Lines Matching +full:0 +full:x0002000
133 #define HAVE_LOG2 0
166 #define SQLITE_OS_OTHER 0
169 #define SQLITE_ENABLE_LOCKING_STYLE 0
173 #define OS_VXWORKS 0
216 ** value of 0 means that compiler is not being used. The
218 ** optimizations, and hence set all compiler macros to 0
230 # define GCC_VERSION 0
235 # define MSVC_VERSION 0
243 # if MSVC_VERSION==0 || MSVC_VERSION>=1800
246 # define SQLITE_HAVE_C99_MATH_FUNCS (0)
359 #if 0
486 ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
487 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
512 ** ^The sqlite3_compileoption_used() function returns 0 or 1
535 # define sqlite3_compileoption_used(X) 0
536 # define sqlite3_compileoption_get(X) ((void*)0)
544 ** [SQLITE_THREADSAFE] compile-time option being set to 0.
549 ** [SQLITE_THREADSAFE] macro is 0,
607 ** between 0 and +18446744073709551615 inclusive.
765 #define SQLITE_OK 0 /* Successful result */
914 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
915 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
916 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
917 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
918 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
919 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
920 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
921 #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
922 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
923 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
924 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
925 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
926 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
927 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
928 #define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */
929 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
930 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
931 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
932 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
933 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
934 #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
935 #define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */
937 /* Reserved: 0x00F00000 */
939 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
982 #define SQLITE_IOCAP_ATOMIC 0x00000001
983 #define SQLITE_IOCAP_ATOMIC512 0x00000002
984 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
985 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
986 #define SQLITE_IOCAP_ATOMIC4K 0x00000010
987 #define SQLITE_IOCAP_ATOMIC8K 0x00000020
988 #define SQLITE_IOCAP_ATOMIC16K 0x00000040
989 #define SQLITE_IOCAP_ATOMIC32K 0x00000080
990 #define SQLITE_IOCAP_ATOMIC64K 0x00000100
991 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
992 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
993 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
994 #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
995 #define SQLITE_IOCAP_IMMUTABLE 0x00002000
996 #define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000
997 #define SQLITE_IOCAP_SUBPAGE_READ 0x00008000
1010 #define SQLITE_LOCK_NONE 0 /* xUnlock() only */
1042 #define SQLITE_SYNC_NORMAL 0x00002
1043 #define SQLITE_SYNC_FULL 0x00003
1044 #define SQLITE_SYNC_DATAONLY 0x00010
1299 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
1309 ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
1529 ** currently has an SQL transaction open on the database. It is set to 0 if
1648 ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
1649 ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
1655 ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
1867 #define SQLITE_ACCESS_EXISTS 0
1902 ** between 0 and this upper bound as its "offset" argument.
2083 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
2136 ** As of SQLite version 3.42.0, the complete set of anytime configuration
2156 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2171 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2187 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2233 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
2298 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2311 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2400 ** fourth parameter. If the fourth parameter is 0, then the database connection
2502 ** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off. If SQLite
2614 ** The first argument is an integer which is 0 to disable FK enforcement,
2617 ** is written 0 or 1 to indicate whether FK enforcement is off or on
2625 ** The first argument is an integer which is 0 to disable triggers,
2628 ** is written 0 or 1 to indicate whether triggers are disabled or enabled
2633 ** SQLite version 3.35.0, TEMP triggers are still allowed even if
2642 ** The first argument is an integer which is 0 to disable views,
2645 ** is written 0 or 1 to indicate whether views are disabled or enabled
2650 ** SQLite version 3.35.0, TEMP views are still allowed even if
2661 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2665 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2678 ** this interface is 0, then both the C-API and the SQL function are disabled.
2682 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2713 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
2714 ** have been disabled - 0 if they are not disabled, 1 if they are.
2726 ** The first argument to this setting is an integer which is 0 to disable
2729 ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
2741 ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
2757 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
2758 ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
2759 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2788 ** The first argument to this setting is an integer which is 0 to disable
2791 ** integer into which is written 0 or 1 to indicate whether the writable_schema
2799 ** behaves as it did prior to [version 3.24.0] (2018-06-04). See the
2850 ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
2852 ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
2854 ** all the way back to version 3.0.0, and so this setting is of little
2857 ** 3.0.0.
2861 ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2874 ** an integer.. The first argument is 1, 0, or -1 to enable, disable, or
2889 ** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
2891 ** then 0 or 1 is written into the integer that the second argument points to
2905 ** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
2907 ** argument is not NULL, then 0 or 1 is written into the integer that the
2924 ** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
2926 ** respectively. If the second argument is not NULL, then 0 or 1 is written
2939 ** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
2941 ** respectively. If the second argument is not NULL, then 0 or 1 is written
2954 ** then the option becomes enabled. If the first integer argument is 0, then the
2957 ** If the second argument is not NULL, then a value of 0 or 1 is written into
3219 ** It returns 1 if an interrupt is currently in effect, or 0 otherwise.
3239 ** ^These routines return 0 if the statement is incomplete. ^If a
3281 ** busy callback returns 0, then no additional attempts are made to
3329 ** the handler returns 0 which causes [sqlite3_step()] to return
3354 ** Passing 0 to this function disables blocking locks altogether. Passing
3368 ** 1 to 0, the last connection takes an exclusive lock on the database,
3380 #define SQLITE_SETLK_BLOCK_ON_CONNECT 0x01
3425 ** azResult[0] = "Name";
3803 #define SQLITE_COPY 0 /* No longer used */
3895 #define SQLITE_TRACE_STMT 0x01
3896 #define SQLITE_TRACE_PROFILE 0x02
3897 #define SQLITE_TRACE_ROW 0x04
3898 #define SQLITE_TRACE_CLOSE 0x08
3973 ** SQLite version 3.41.0, the progress handler callback might also be
4300 ** parameter and returns true (1) or false (0) according to the value
4304 ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
4308 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4318 ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
4328 ** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F
4330 ** in addition to the main database file. Prior to version 3.31.0, these
4641 #define SQLITE_LIMIT_LENGTH 0
4699 #define SQLITE_PREPARE_PERSISTENT 0x01
4700 #define SQLITE_PREPARE_NORMALIZE 0x02
4701 #define SQLITE_PREPARE_NO_VTAB 0x04
4702 #define SQLITE_PREPARE_DONT_LOG 0x10
4956 ** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
4983 ** began with EXPLAIN or EXPLAIN QUERY PLAN, but sqlite3_stmt_explain(S,0)
5038 ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
5192 ** [pointer passing interface] added for SQLite 3.20.0.
5266 ** ^The first host parameter has an index of 1, not 0.
5313 ** [prepared statement]. ^If this routine returns 0, that means the
5334 ** column number. ^The leftmost column is number 0.
5377 ** ^The left-most column is column 0 for these routines.
5424 ** column (i==1), and a NULL pointer for the first result column (i==0).)^
5528 ** interfaces) then sqlite3_data_count(P) returns 0.
5529 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
5530 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
5535 ** pragma returns 0 columns of data.
5579 ** <blockquote><table border=0 cellpadding=0 cellspacing=0>
5605 ** should be returned. ^The leftmost column of the result set has the index 0.
5699 ** <tr><td> NULL <td> INTEGER <td> Result is 0
5895 ** aggregate may take any number of arguments between 0 and the limit
6144 #define SQLITE_DETERMINISTIC 0x000000800
6145 #define SQLITE_DIRECTONLY 0x000080000
6146 #define SQLITE_SUBTYPE 0x000100000
6147 #define SQLITE_INNOCUOUS 0x000200000
6148 #define SQLITE_RESULT_SUBTYPE 0x001000000
6149 #define SQLITE_SELFORDER1 0x002000000
6176 ** <blockquote><table border=0 cellpadding=0 cellspacing=0>
6229 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
6402 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
6564 ** version 3.44.0 ([dateof:3.44.0]) and later.
6586 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
6701 ** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the
6730 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
6960 ** at all. ^In SQLite version 3.42.0 and later, a negative
7016 ** memset(zPathBuf, 0, sizeof(zPathBuf));
7017 ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),
7139 ** out of range. An N value of 0 means the main database file. An N of 1 is
7192 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
7206 ** <li value="0"> SQLITE_TXN_NONE
7244 #define SQLITE_TXN_NONE 0
7457 ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
7558 ** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the
7658 ** not null: 0
7660 ** auto increment: 0
7694 ** ^(zProc may be 0, in which case SQLite will try to come up with an
7702 ** ^If an error occurs and pzErrMsg is not 0, then the
7726 const char *zProc, /* Entry point. Derived from zFile if 0 */
7727 char **pzErrMsg /* Put error message here if not 0 */
7741 ** to turn extension loading on and call it with onoff==0 to turn
7802 ** unregistered and it returns 0 if X was not on the list of initialization
7916 ** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62),
7925 ** about what parameters to pass to xFilter. ^If argvIndex>0 then
7980 ** was added for [version 3.9.0] ([dateof:3.9.0]).
8001 int argvIndex; /* if >0, constraint is part of argv to xFilter */
8011 /* Fields below are only available in SQLite 3.9.0 and later */
8013 /* Fields below are only available in SQLite 3.10.0 and later */
8024 #define SQLITE_INDEX_SCAN_UNIQUE 0x00000001 /* Scan visits at most 1 row */
8025 #define SQLITE_INDEX_SCAN_HEX 0x00000002 /* Display idxNum as hex */
8742 #define SQLITE_MUTEX_FAST 0
8897 ** The sqlite3_keyword_name(N,Z,L) interface finds the 0-based N-th keyword and
8968 ** [sqlite3_str_errcode()], always return 0 for
9062 ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
9171 #define SQLITE_STATUS_MEMORY_USED 0
9249 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
9262 ** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.</dd>
9271 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
9278 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
9284 ** is always 0.
9290 ** is always 0.
9301 ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
9316 ** resolved.)^ ^The highwater mark is always 0.
9320 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
9573 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
9580 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
10041 ** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0.
10109 ** a copy of the third parameter from the previous call, if any, or 0.
10156 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
10232 ** the writer lock retried until either the busy-handler returns 0 or the lock
10234 ** database readers as described above. ^If the busy-handler returns 0 before
10282 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
10464 ** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
10471 ** <ol><li value="0"><p>
10472 ** ^If the sqlite3_vtab_distinct() interface returns 0, that means
10499 ** if the sqlite3_vtab_distinct() interface had returned 0. However if
10515 ** <table border=1 cellspacing=0 cellpadding=10 width="90%">
10521 ** <tr><td>0<td>yes<td>yes<td>no
10584 ** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
10682 ** J being a 0-based index into P->aConstraint[], then this routine
10794 #define SQLITE_SCANSTAT_NLOOP 0
10858 #define SQLITE_SCANSTAT_COMPLEX 0x0001
10967 ** the table row before it is updated. The N parameter must be between 0
10976 ** the table row after it is updated. The N parameter must be between 0
10983 ** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate
11297 #define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */
11332 ** to 0x01 prior to invoking sqlite3_deserialize(D,S,P,N,M,F) to force the
11391 # define SQLITE_THREADSAFE 0
11395 #if 0
11418 #if 0
11507 #define NOT_WITHIN 0 /* Object completely outside of query region */
11512 #if 0
11527 #if 0
11622 ** 0, then the sqlite3session_changeset_size() API is disabled. If it
11623 ** is greater than 0, then the same API is enabled. Or, if the initial
11626 ** enabled following the current call, or 0 otherwise.
11661 ** The return value indicates the final state of the session object: 0 if
11691 ** The return value indicates the final state of the indirect flag: 0 if
11727 ** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
11749 ** Legacy (older than 3.22.0) versions of the sessions module cannot capture
11766 ** If xFilter returns 0, changes are not tracked. Note that once a table is
11894 ** By default, this function always returns 0. For it to return
12096 #define SQLITE_CHANGESETSTART_INVERT 0x0002
12148 ** is an indirect change, or false (0) otherwise. See the documentation for
12179 ** 0x01 if the corresponding column is part of the tables primary key, or
12180 ** 0x00 if it is not.
12208 ** Argument iVal must be greater than or equal to 0, and less than the number
12239 ** Argument iVal must be greater than or equal to 0, and less than the number
12271 ** Argument iVal must be greater than or equal to 0, and less than the number
12390 ** *ppOut = 0;
12391 ** *pnOut = 0;
12610 ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
12859 #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001
12860 #define SQLITE_CHANGESETAPPLY_INVERT 0x0002
12861 #define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004
12862 #define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008
12956 #define SQLITE_CHANGESET_OMIT 0
13312 ** If this value is greater than 0, it is used as the new streaming data
13331 #if 0
13363 #if 0
13425 ** created with the "columnsize=0" option.
13444 ** 0 is returned. Otherwise, this function returns the number of tokens in
13455 ** (i.e. if it is a contentless table), then this API always returns 0.
13561 ** iCol>=0;
13579 ** i.e. all those in column 0, sorted by offset, followed by those in
13595 ** iCol>=0;
13630 ** tables, this includes any embedded 0x00 and trailing data.
13642 ** includes any embedded 0x00 and trailing data.
13671 ** to NULL and 0, respectively. However, if the fts5_locale() function
13804 ** on a columnsize=0 database.
13811 ** which case nLocale is always 0) to indicate that the tokenizer should
13823 ** normally be set to 0. The exception is if the tokenizer supports
13840 ** for the current request. If pLocale and nLocale are both 0, then the
13923 ** xToken(pCtx, 0, "i", 1, 0, 1);
13924 ** xToken(pCtx, 0, "won", 3, 2, 5);
13925 ** xToken(pCtx, 0, "first", 5, 6, 11);
13927 ** xToken(pCtx, 0, "place", 5, 12, 17);
14017 #define FTS5_TOKENIZE_QUERY 0x0001
14018 #define FTS5_TOKENIZE_PREFIX 0x0002
14019 #define FTS5_TOKENIZE_DOCUMENT 0x0004
14020 #define FTS5_TOKENIZE_AUX 0x0008
14024 #define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */
14087 #if 0
14186 ** expression. A value of 0 means that there is no limit.
14197 ** never has more than 3 or 4 terms. Use a value of 0 to disable
14245 ** The maximum number of attached databases. This must be between 0
14317 # define SQLITE_MAX_PAGE_COUNT 0xfffffffe /* 4294967294 */
14332 ** fire any triggers. A value of 0 means that no trigger programs at all
14356 # define __has_extension(x) 0 /* compatibility with non-clang compilers */
14363 # define SQLITE_ATOMIC_INTRINSICS 0
14390 ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
14401 # define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X])
14402 # define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0))
14458 ** disables it using -DSQLITE_DIRECT_OVERFLOW_READ=0
14461 /* Disable if -DSQLITE_DIRECT_OVERFLOW_READ=0 */
14470 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
14471 ** 0 means mutexes are permanently disable and the library is never
14495 ** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option.
14503 ** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in
14539 + defined(SQLITE_MEMDEBUG)==0
14658 # define NEVER(X) (0)
14660 # define ALWAYS(X) ((X)?1:(assert(0),0))
14661 # define NEVER(X) ((X)?(assert(0),1):0)
14669 ** conditionals are replaced with a constant 1 (true) or 0 (false) then
14676 # define OK_IF_ALWAYS_FALSE(X) (0)
14692 # define ONLY_IF_REALLOC_STRESS(X) ((X)?(assert(0),1):0)
14694 # define ONLY_IF_REALLOC_STRESS(X) (0)
14744 #define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0)
15065 int xxn=(N);while(xxn-->0)*(xxd++)=*(xxs++);}
15075 # define fabs(X) ((X)<0?-(X):(X))
15076 # define sqlite3IsOverflow(X) 0
15090 ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
15097 #define OMIT_TEMPDB 0
15116 # define SQLITE_DEFAULT_RECURSIVE_TRIGGERS 0
15132 #if SQLITE_TEMP_STORE==3 || SQLITE_THREADSAFE==0
15134 # define SQLITE_MAX_WORKER_THREADS 0
15140 # define SQLITE_DEFAULT_WORKER_THREADS 0
15164 # define SQLITE_DEFAULT_SORTERREF_SIZE 0x7fffffff
15181 #define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
15277 ** is 0x00000000ffffffff. But because of quirks of some compilers, we
15300 ** 1 -> 0 20 -> 43 10000 -> 132
15381 ** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined
15411 # define SQLITE_BYTEORDER 0
15416 # define SQLITE_LITTLEENDIAN 0
15419 # define SQLITE_BIGENDIAN 0
15428 # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
15438 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
15439 #define LARGEST_UINT64 (0xffffffff|(((u64)0xffffffff)<<32))
15482 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
15484 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
15492 # define SQLITE_MAX_MMAP_SIZE 0
15508 # define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */
15510 # define SQLITE_MAX_MMAP_SIZE 0
15520 # define SQLITE_DEFAULT_MMAP_SIZE 0
15528 ** TREETRACE_ENABLED will be either 1 or 0 depending on whether or not
15544 # define TREETRACE_ENABLED 0
15549 ** 0x00000001 Beginning and end of SELECT processing
15550 ** 0x00000002 WHERE clause processing
15551 ** 0x00000004 Query flattener
15552 ** 0x00000008 Result-set wildcard expansion
15553 ** 0x00000010 Query name resolution
15554 ** 0x00000020 Aggregate analysis
15555 ** 0x00000040 Window functions
15556 ** 0x00000080 Generated column names
15557 ** 0x00000100 Move HAVING terms into WHERE
15558 ** 0x00000200 Count-of-view optimization
15559 ** 0x00000400 Compound SELECT processing
15560 ** 0x00000800 Drop superfluous ORDER BY
15561 ** 0x00001000 LEFT JOIN simplifies to JOIN
15562 ** 0x00002000 Constant propagation
15563 ** 0x00004000 Push-down optimization
15564 ** 0x00008000 After all FROM-clause analysis
15565 ** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
15566 ** 0x00020000 Transform DISTINCT into GROUP BY
15567 ** 0x00040000 SELECT tree dump after all code has been generated
15568 ** 0x00080000 NOT NULL strength reduction
15587 ** 0x-------F High-level debug messages
15588 ** 0x----FFF- More detail
15589 ** 0xFFFF---- Low-level debug messages
15591 ** 0x00000001 Code generation
15592 ** 0x00000002 Solver (Use 0x40000 for less detail)
15593 ** 0x00000004 Solver costs
15594 ** 0x00000008 WhereLoop inserts
15596 ** 0x00000010 Display sqlite3_index_info xBestIndex calls
15597 ** 0x00000020 Range an equality scan metrics
15598 ** 0x00000040 IN operator decisions
15599 ** 0x00000080 WhereLoop cost adjustments
15600 ** 0x00000100
15601 ** 0x00000200 Covering index decisions
15602 ** 0x00000400 OR optimization
15603 ** 0x00000800 Index scanner
15604 ** 0x00001000 More details associated with code generation
15605 ** 0x00002000
15606 ** 0x00004000 Show all WHERE terms at key points
15607 ** 0x00008000 Show the full SELECT statement at key places
15609 ** 0x00010000 Show more detail when printing WHERE terms
15610 ** 0x00020000 Show WHERE terms returned from whereScanNext()
15611 ** 0x00040000 Solver overview messages
15612 ** 0x00080000 Star-query heuristic
15670 #define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0])))
15675 #define IsPowerOfTwo(X) (((X)&((X)-1))==0)
15822 #define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0)
15898 ** will defined to either 1 or 0. One of them will be 1. The others will be 0.
15911 # define SQLITE_OS_UNIX 0
15913 # define SQLITE_OS_WIN 0
15919 # define SQLITE_OS_KV 0
15921 # define SQLITE_OS_UNIX 0
15923 # define SQLITE_OS_WIN 0
15927 # define SQLITE_OS_OTHER 0
15929 # define SQLITE_OS_UNIX 0
15931 # define SQLITE_OS_WIN 0
15937 # define SQLITE_DQS 0
15943 # define SQLITE_OS_KV 0
15945 # define SQLITE_OS_OTHER 0
15947 # define SQLITE_OS_WIN 0
15951 # define SQLITE_OS_KV 0
15953 # define SQLITE_OS_OTHER 0
15955 # define SQLITE_OS_UNIX 0
16033 #define NO_LOCK 0
16095 # define PENDING_BYTE (0x40000000)
16122 #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
16196 ** is called page 1. 0 is used to represent "not a page".
16226 #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
16227 #define PAGER_MEMORY 0x0002 /* In-memory database */
16233 #define PAGER_LOCKINGMODE_NORMAL 0
16244 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
16255 ** Return 0 if it is not open, or non-zero (but not 1) if it is.
16265 #define isOpen(pFd) ((pFd)->pMethods!=0)
16270 #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
16271 #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
16281 #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
16282 #define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
16283 #define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
16284 #define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */
16285 #define PAGER_SYNCHRONOUS_MASK 0x07 /* Mask for four values above */
16286 #define PAGER_FULLFSYNC 0x08 /* PRAGMA fullfsync=ON */
16287 #define PAGER_CKPT_FULLFSYNC 0x10 /* PRAGMA checkpoint_fullfsync=ON */
16288 #define PAGER_CACHESPILL 0x20 /* PRAGMA cache_spill=ON */
16289 #define PAGER_FLAGS_MASK 0x38 /* All above except SYNCHRONOUS */
16462 #define SQLITE_DEFAULT_AUTOVACUUM 0
16465 #define BTREE_AUTOVACUUM_NONE 0 /* Do not do auto-vacuum */
16501 #if SQLITE_MAX_MMAP_SIZE>0
16585 #define BTREE_FREE_PAGE_COUNT 0
16623 #define BTREE_HINT_RANGE 0 /* Range constraints on queries */
16638 #define BTREE_BULKLOAD 0x00000001 /* Used to full index in sorted order */
16639 #define BTREE_SEEK_EQ 0x00000002 /* EQ seeks only - no range seeks */
16662 ** FORDELETE cursor may return a null row: 0x01 0x00.
16664 #define BTREE_WRCSR 0x00000004 /* read-write cursor */
16665 #define BTREE_FORDELETE 0x00000008 /* Cursor is for seek/delete only */
16670 int wrFlag, /* 1 for writing. 0 for read-only */
16702 #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */
16703 #define BTREE_AUXDELETE 0x04 /* not the primary delete operation */
16704 #define BTREE_APPEND 0x08 /* Insert is likely an append */
16705 #define BTREE_PREFORMAT 0x80 /* Inserted data is a preformated cell */
16746 int nData; /* Size of pData. 0 if none. */
16793 # define sqlite3BtreeSeekCount(X) 0
16830 # define sqlite3BtreeSharable(X) 0
16987 #define P4_NOTUSED 0 /* The P4 parameter is not used */
16988 #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
17019 #define COLNAME_NAME 0
17049 #define OP_Savepoint 0
17098 #define OP_FkIfZero 49 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
17099 #define OP_IfPos 50 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
17109 #define OP_IfNotZero 60 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
17110 #define OP_DecrJumpZero 61 /* jump, synopsis: if (--r[P1])==0 goto P2 */
17141 #define OP_ZeroOrNull 92 /* synopsis: r[P2] = 0 OR NULL */
17209 #define OP_OffsetLimit 160 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) …
17229 #define OP_ClrSubtype 180 /* synopsis: r[P1].subtype = 0 */
17244 #define OPFLG_JUMP 0x01 /* jump: P2 holds jmp target */
17245 #define OPFLG_IN1 0x02 /* in1: P1 is an input */
17246 #define OPFLG_IN2 0x04 /* in2: P2 is an input */
17247 #define OPFLG_IN3 0x08 /* in3: P3 is an input */
17248 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
17249 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
17250 #define OPFLG_NCYCLE 0x40 /* ncycle:Cycles count against P1 */
17251 #define OPFLG_JUMP0 0x80 /* jump0: P2 might be zero */
17253 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x41, 0x00,\
17254 /* 8 */ 0x81, 0x01, 0x01, 0x81, 0x83, 0x83, 0x01, 0x01,\
17255 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0xc9, 0xc9, 0xc9,\
17256 /* 24 */ 0xc9, 0x01, 0x49, 0x49, 0x49, 0x49, 0xc9, 0x49,\
17257 /* 32 */ 0xc1, 0x01, 0x41, 0x41, 0xc1, 0x01, 0x41, 0x41,\
17258 /* 40 */ 0x41, 0x41, 0x41, 0x26, 0x26, 0x41, 0x23, 0x0b,\
17259 /* 48 */ 0x81, 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
17260 /* 56 */ 0x0b, 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x41,\
17261 /* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
17262 /* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
17263 /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
17264 /* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x40, 0x00,\
17265 /* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x40, 0x40, 0x26,\
17266 /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
17267 /* 112 */ 0x26, 0x00, 0x40, 0x12, 0x40, 0x40, 0x10, 0x00,\
17268 /* 120 */ 0x00, 0x00, 0x40, 0x00, 0x40, 0x40, 0x10, 0x10,\
17269 /* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x50,\
17270 /* 136 */ 0x00, 0x40, 0x04, 0x04, 0x00, 0x40, 0x50, 0x40,\
17271 /* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
17272 /* 152 */ 0x00, 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04,\
17273 /* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
17274 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x50,\
17275 /* 176 */ 0x40, 0x00, 0x10, 0x10, 0x02, 0x12, 0x12, 0x00,\
17276 /* 184 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}
17292 #define SQLITE_PREPARE_SAVESQL 0x80 /* Preserve SQL text */
17293 #define SQLITE_PREPARE_MASK 0x1f /* Mask of public flags */
17344 # define ExplainQueryPlanParent(P) 0
17494 sqlite3VdbeSetLineNumber(v,__LINE__|0x5000000);
17496 sqlite3VdbeSetLineNumber(v,__LINE__|0x6000000);
17498 sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
17500 if(x)sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
17502 sqlite3VdbeSetLineNumber(v,__LINE__|0x8000000);
17512 # define VDBE_OFFSET_LINENO(x) 0
17589 #define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */
17590 #define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */
17591 #define PGHDR_WRITEABLE 0x004 /* Journaled and ready to modify */
17592 #define PGHDR_NEED_SYNC 0x008 /* Fsync the rollback journal before
17594 #define PGHDR_DONT_WRITE 0x010 /* Do not write content to disk */
17595 #define PGHDR_MMAP 0x020 /* This is an mmap page object */
17597 #define PGHDR_WAL_APPEND 0x040 /* Appended to wal file */
17646 /* Remove all pages with pgno>x. Reset the cache if x==0 */
17824 ** OFF 1 0
17843 ** in the sqlite.aDb[] array. aDb[0] is the main database file and
17891 #define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->schemaFlags&(P))!=0)
17905 #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */
17906 #define DB_UnresetViews 0x0002 /* Some views have defined column names */
17907 #define DB_ResetWanted 0x0008 /* Reset the schema when nSchemaLock==0 */
17935 ** New lookaside allocations are only allowed if bDisable==0. When
17966 u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
17977 void *pTrueEnd; /* True value of pEnd, when db->pnBytesFreed!=0 */
17983 #define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0
17985 db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue
17989 # define LOOKASIDE_SMALL 0
18018 #define SQLITE_TRACE_LEGACY 0x40 /* Use the legacy xTrace */
18019 #define SQLITE_TRACE_XPROFILE 0x80 /* Use the legacy xProfile */
18021 #define SQLITE_TRACE_LEGACY 0
18022 #define SQLITE_TRACE_XPROFILE 0
18024 #define SQLITE_TRACE_NONLEGACY_MASK 0x0f /* Normal flags */
18055 u8 temp_store; /* 1: file 2: memory 0: default */
18059 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
18067 int nextPagesize; /* Pagesize after VACUUM if >0 */
18182 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
18200 #define SQLITE_WriteSchema 0x00000001 /* OK to update SQLITE_SCHEMA */
18201 #define SQLITE_LegacyFileFmt 0x00000002 /* Create new databases in format 1 */
18202 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
18203 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
18204 #define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */
18205 #define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */
18206 #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
18207 #define SQLITE_TrustedSchema 0x00000080 /* Allow unsafe functions and
18209 #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
18211 #define SQLITE_IgnoreChecks 0x00000200 /* Do not enforce check constraints */
18212 #define SQLITE_StmtScanStatus 0x00000400 /* Enable stmt_scanstats() counters */
18213 #define SQLITE_NoCkptOnClose 0x00000800 /* No checkpoint on close()/DETACH */
18214 #define SQLITE_ReverseOrder 0x00001000 /* Reverse unordered SELECTs */
18215 #define SQLITE_RecTriggers 0x00002000 /* Enable recursive triggers */
18216 #define SQLITE_ForeignKeys 0x00004000 /* Enforce foreign key constraints */
18217 #define SQLITE_AutoIndex 0x00008000 /* Enable automatic indexes */
18218 #define SQLITE_LoadExtension 0x00010000 /* Enable load_extension */
18219 #define SQLITE_LoadExtFunc 0x00020000 /* Enable load_extension() SQL func */
18220 #define SQLITE_EnableTrigger 0x00040000 /* True to enable triggers */
18221 #define SQLITE_DeferFKs 0x00080000 /* Defer all FK constraints */
18222 #define SQLITE_QueryOnly 0x00100000 /* Disable database changes */
18223 #define SQLITE_CellSizeCk 0x00200000 /* Check btree cell sizes on load */
18224 #define SQLITE_Fts3Tokenizer 0x00400000 /* Enable fts3_tokenizer(2) */
18225 #define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee*/
18226 #define SQLITE_TriggerEQP 0x01000000 /* Show trigger EXPLAIN QUERY PLAN */
18227 #define SQLITE_ResetDatabase 0x02000000 /* Reset the database */
18228 #define SQLITE_LegacyAlter 0x04000000 /* Legacy ALTER TABLE behaviour */
18229 #define SQLITE_NoSchemaError 0x08000000 /* Do not report schema parse errors*/
18230 #define SQLITE_Defensive 0x10000000 /* Input SQL is likely hostile */
18231 #define SQLITE_DqsDDL 0x20000000 /* dbl-quoted strings allowed in DDL*/
18232 #define SQLITE_DqsDML 0x40000000 /* dbl-quoted strings allowed in DML*/
18233 #define SQLITE_EnableView 0x80000000 /* Enable the use of views */
18234 #define SQLITE_CountRows HI(0x00001) /* Count rows changed by INSERT, */
18237 #define SQLITE_CorruptRdOnly HI(0x00002) /* Prohibit writes due to error */
18238 #define SQLITE_ReadUncommit HI(0x00004) /* READ UNCOMMITTED in shared-cache */
18239 #define SQLITE_FkNoAction HI(0x00008) /* Treat all FK as NO ACTION */
18240 #define SQLITE_AttachCreate HI(0x00010) /* ATTACH allowed to create new dbs */
18241 #define SQLITE_AttachWrite HI(0x00020) /* ATTACH allowed to open for write */
18242 #define SQLITE_Comments HI(0x00040) /* Enable SQL comments */
18246 #define SQLITE_SqlTrace HI(0x0100000) /* Debug print SQL as it executes */
18247 #define SQLITE_VdbeListing HI(0x0200000) /* Debug listings of VDBE progs */
18248 #define SQLITE_VdbeTrace HI(0x0400000) /* True to trace VDBE execution */
18249 #define SQLITE_VdbeAddopTrace HI(0x0800000) /* Trace sqlite3VdbeAddOp() calls */
18250 #define SQLITE_VdbeEQP HI(0x1000000) /* Debug EXPLAIN QUERY PLAN */
18251 #define SQLITE_ParserTrace HI(0x2000000) /* PRAGMA parser_trace=ON */
18257 #define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */
18258 #define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */
18259 #define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */
18260 #define DBFLAG_VacuumInto 0x0008 /* Currently running VACUUM INTO */
18261 #define DBFLAG_SchemaKnownOk 0x0010 /* Schema is known to be valid */
18262 #define DBFLAG_InternalFunc 0x0020 /* Allow use of internal functions */
18263 #define DBFLAG_EncodingFixed 0x0040 /* No longer possible to change enc. */
18270 #define SQLITE_QueryFlattener 0x00000001 /* Query flattening */
18271 #define SQLITE_WindowFunc 0x00000002 /* Use xInverse for window functions */
18272 #define SQLITE_GroupByOrder 0x00000004 /* GROUPBY cover of ORDERBY */
18273 #define SQLITE_FactorOutConst 0x00000008 /* Constant factoring */
18274 #define SQLITE_DistinctOpt 0x00000010 /* DISTINCT using indexes */
18275 #define SQLITE_CoverIdxScan 0x00000020 /* Covering index scans */
18276 #define SQLITE_OrderByIdxJoin 0x00000040 /* ORDER BY of joins via index */
18277 #define SQLITE_Transitive 0x00000080 /* Transitive constraints */
18278 #define SQLITE_OmitNoopJoin 0x00000100 /* Omit unused tables in joins */
18279 #define SQLITE_CountOfView 0x00000200 /* The count-of-view optimization */
18280 #define SQLITE_CursorHints 0x00000400 /* Add OP_CursorHint opcodes */
18281 #define SQLITE_Stat4 0x00000800 /* Use STAT4 data */
18282 /* TH3 expects this value ^^^^^^^^^^ to be 0x0000800. Don't change it */
18283 #define SQLITE_PushDown 0x00001000 /* WHERE-clause push-down opt */
18284 #define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */
18285 #define SQLITE_SkipScan 0x00004000 /* Skip-scans */
18286 #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */
18287 #define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */
18288 #define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */
18289 #define SQLITE_OmitOrderBy 0x00040000 /* Omit pointless ORDER BY */
18290 /* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */
18291 #define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
18292 #define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
18293 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
18294 #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
18295 #define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
18297 #define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
18298 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
18299 #define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
18300 #define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
18301 #define SQLITE_OrderBySubq 0x10000000 /* ORDER BY in subquery helps outer */
18302 #define SQLITE_StarQuery 0x20000000 /* Heurists for star queries */
18303 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
18308 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0)
18309 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0)
18321 #define SQLITE_STATE_OPEN 0x76 /* Database is open */
18322 #define SQLITE_STATE_CLOSED 0xce /* Database is closed */
18323 #define SQLITE_STATE_SICK 0xba /* Error and awaiting close */
18324 #define SQLITE_STATE_BUSY 0x6d /* Database currently in use */
18325 #define SQLITE_STATE_ERROR 0xd5 /* An SQLITE_MISUSE error occurred */
18326 #define SQLITE_STATE_ZOMBIE 0xa7 /* Close with last statement close */
18365 ** count on this object is decremented. When it reaches 0, the destructor
18397 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
18398 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
18399 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
18400 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
18401 #define SQLITE_FUNC_NEEDCOLL 0x0020 /* sqlite3GetFuncCollSeq() might be called*/
18402 #define SQLITE_FUNC_LENGTH 0x0040 /* Built-in length() function */
18403 #define SQLITE_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */
18404 #define SQLITE_FUNC_BYTELEN 0x00c0 /* Built-in octet_length() function */
18405 #define SQLITE_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */
18406 /* 0x0200 -- available for reuse */
18407 #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
18408 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
18409 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
18410 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
18412 #define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */
18413 #define SQLITE_FUNC_RUNONLY 0x8000 /* Cannot be used by valueFromFunction */
18414 #define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
18415 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
18416 #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
18417 /* SQLITE_SUBTYPE 0x00100000 // Consumer of subtypes */
18418 #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
18419 #define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */
18420 #define SQLITE_FUNC_BUILTIN 0x00800000 /* This is a built-in function */
18421 /* SQLITE_RESULT_SUBTYPE 0x01000000 // Generator of subtypes */
18422 #define SQLITE_FUNC_ANYORDER 0x08000000 /* count/min/max aggregate */
18425 #define INLINEFUNC_coalesce 0
18503 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
18506 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
18509 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
18512 xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
18517 SQLITE_INT_TO_PTR(iArg|((bJsonB)*JSON_BLOB)),0,xFunc,0, 0, 0, #zName, {0} }
18521 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
18526 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
18529 0, 0, xFunc, 0, 0, 0, #zName, {0} }
18533 (void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} }
18537 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
18541 pArg, 0, xFunc, 0, 0, 0, #zName, }
18544 (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
18547 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
18551 0, 0, xFunc, 0, 0, 0, #zName, {0} }
18571 #define SAVEPOINT_BEGIN 0
18610 ** a single allocation. Each string is 0x00 terminated. The datatype
18622 u16 iDflt; /* 1-based index of DEFAULT. 0 means "none" */
18633 #define COLTYPE_CUSTOM 0 /* Type appended to zName */
18649 #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */
18650 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
18651 #define COLFLAG_HASTYPE 0x0004 /* Type name follows column name */
18652 #define COLFLAG_UNIQUE 0x0008 /* Column def contains "UNIQUE" or "PK" */
18653 #define COLFLAG_SORTERREF 0x0010 /* Use sorter-refs with this column */
18654 #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
18655 #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
18656 #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
18657 #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
18658 #define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
18659 #define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */
18660 #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
18661 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
18683 #define SQLITE_SO_ASC 0 /* Sort in ascending order */
18694 ** But rather than start with 0 or 1, we begin with 'A'. That way,
18701 #define SQLITE_AFF_NONE 0x40 /* '@' */
18702 #define SQLITE_AFF_BLOB 0x41 /* 'A' */
18703 #define SQLITE_AFF_TEXT 0x42 /* 'B' */
18704 #define SQLITE_AFF_NUMERIC 0x43 /* 'C' */
18705 #define SQLITE_AFF_INTEGER 0x44 /* 'D' */
18706 #define SQLITE_AFF_REAL 0x45 /* 'E' */
18707 #define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
18708 #define SQLITE_AFF_DEFER 0x58 /* 'X' - defer computation until later */
18716 #define SQLITE_AFF_MASK 0x47
18727 #define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */
18728 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */
18729 #define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */
18787 #define SQLITE_VTABRISK_Low 0
18814 u8 eTabType; /* 0: normal, 1: virtual, 2: view */
18827 char **azArg; /* 0: module 1: schema 2: vtab name 3...: args */
18851 #define TF_Readonly 0x00000001 /* Read-only system table */
18852 #define TF_HasHidden 0x00000002 /* Has one or more hidden columns */
18853 #define TF_HasPrimaryKey 0x00000004 /* Table has a primary key */
18854 #define TF_Autoincrement 0x00000008 /* Integer primary key is autoincrement */
18855 #define TF_HasStat1 0x00000010 /* nRowLogEst set from sqlite_stat1 */
18856 #define TF_HasVirtual 0x00000020 /* Has one or more VIRTUAL columns */
18857 #define TF_HasStored 0x00000040 /* Has one or more STORED columns */
18858 #define TF_HasGenerated 0x00000060 /* Combo: HasVirtual + HasStored */
18859 #define TF_WithoutRowid 0x00000080 /* No rowid. PRIMARY KEY is the key */
18860 #define TF_MaybeReanalyze 0x00000100 /* Maybe run ANALYZE on this table */
18861 #define TF_NoVisibleRowid 0x00000200 /* No user-visible "rowid" column */
18862 #define TF_OOOHidden 0x00000400 /* Out-of-Order hidden columns */
18863 #define TF_HasNotNull 0x00000800 /* Contains NOT NULL constraints */
18864 #define TF_Shadow 0x00001000 /* True for a shadow table */
18865 #define TF_HasStat4 0x00002000 /* STAT4 info available for this table */
18866 #define TF_Ephemeral 0x00004000 /* An ephemeral table */
18867 #define TF_Eponymous 0x00008000 /* An eponymous virtual table */
18868 #define TF_Strict 0x00010000 /* STRICT mode */
18873 #define TABTYP_NORM 0 /* Ordinary table */
18890 # define IsVirtual(X) 0
18891 # define ExprIsVtab(X) 0
18901 # define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0)
18902 # define IsOrdinaryHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0)
18904 # define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0)
18905 # define IsOrdinaryHiddenColumn(X) 0
18907 # define IsHiddenColumn(X) 0
18908 # define IsOrdinaryHiddenColumn(X) 0
18913 #define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0)
18914 #define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0)
18920 # define ViewCanHaveRowid 0
18922 # define ViewCanHaveRowid (sqlite3Config.mNoVisibleRowid==0)
19005 #define OE_None 0 /* There is no constraint to check */
19044 #define KEYINFO_ORDER_DESC 0x01 /* DESC sort order */
19045 #define KEYINFO_ORDER_BIGNULL 0x02 /* NULL is larger than any other value */
19069 ** an equals comparison. default_rc can be -1, 0, or +1. If there are
19077 ** When default_rc!=0, the search might end up on the record immediately
19086 char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */
19087 i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */
19089 int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */
19113 ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the
19115 ** The second column to be indexed (c1) has an index of 0 in
19116 ** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
19147 i16 *aiColumn; /* Which columns are used by this index. 1st is 0 */
19162 unsigned idxType:2; /* 0:Normal 1:UNIQUE, 2:PRIMARY KEY, 3:IPK */
19190 #define SQLITE_IDXTYPE_APPDEF 0 /* Created using CREATE INDEX */
19223 #define SQLITE_TOKEN_QUOTED 0x1 /* Token is a quoted identifier. */
19224 #define SQLITE_TOKEN_KEYWORD 0x2 /* Token is a keyword. */
19421 #if SQLITE_MAX_EXPR_DEPTH>0
19426 ** TK_TRIGGER: 1 -> new, 0 -> old
19457 #define EP_OuterON 0x000001 /* Originates in ON/USING clause of outer join */
19458 #define EP_InnerON 0x000002 /* Originates in ON/USING of an inner join */
19459 #define EP_Distinct 0x000004 /* Aggregate function with DISTINCT keyword */
19460 #define EP_HasFunc 0x000008 /* Contains one or more functions of any kind */
19461 #define EP_Agg 0x000010 /* Contains one or more aggregate functions */
19462 #define EP_FixedCol 0x000020 /* TK_Column with a known fixed value */
19463 #define EP_VarSelect 0x000040 /* pSelect is correlated, not constant */
19464 #define EP_DblQuoted 0x000080 /* token.z was originally in "..." */
19465 #define EP_InfixFunc 0x000100 /* True for an infix function: LIKE, GLOB, etc */
19466 #define EP_Collate 0x000200 /* Tree contains a TK_COLLATE operator */
19467 #define EP_Commuted 0x000400 /* Comparison operator has been commuted */
19468 #define EP_IntValue 0x000800 /* Integer value contained in u.iValue */
19469 #define EP_xIsSelect 0x001000 /* x.pSelect is valid (otherwise x.pList is) */
19470 #define EP_Skip 0x002000 /* Operator does not contribute to affinity */
19471 #define EP_Reduced 0x004000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
19472 #define EP_Win 0x008000 /* Contains window functions */
19473 #define EP_TokenOnly 0x010000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
19474 #define EP_FullSize 0x020000 /* Expr structure must remain full sized */
19475 #define EP_IfNullRow 0x040000 /* The TK_IF_NULL_ROW opcode */
19476 #define EP_Unlikely 0x080000 /* unlikely() or likelihood() function */
19477 #define EP_ConstFunc 0x100000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
19478 #define EP_CanBeNull 0x200000 /* Can be null despite NOT NULL constraint */
19479 #define EP_Subquery 0x400000 /* Tree contains a TK_SELECT operator */
19480 #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
19481 #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
19482 #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
19483 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
19484 #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
19485 #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
19486 #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
19487 #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
19488 #define EP_SubtArg 0x80000000 /* Is argument to SQLITE_SUBTYPE function */
19498 #define ExprHasProperty(E,P) (((E)->flags&(u32)(P))!=0)
19504 #define ExprIsFullSize(E) (((E)->flags&(EP_Reduced|EP_TokenOnly))==0)
19509 #define ExprUseUToken(E) (((E)->flags&EP_IntValue)==0)
19510 #define ExprUseUValue(E) (((E)->flags&EP_IntValue)!=0)
19511 #define ExprUseWOfst(E) (((E)->flags&(EP_InnerON|EP_OuterON))==0)
19512 #define ExprUseWJoin(E) (((E)->flags&(EP_InnerON|EP_OuterON))!=0)
19513 #define ExprUseXList(E) (((E)->flags&EP_xIsSelect)==0)
19514 #define ExprUseXSelect(E) (((E)->flags&EP_xIsSelect)!=0)
19515 #define ExprUseYTab(E) (((E)->flags&(EP_WinFunc|EP_Subrtn))==0)
19516 #define ExprUseYWin(E) (((E)->flags&EP_WinFunc)!=0)
19517 #define ExprUseYSub(E) (((E)->flags&EP_Subrtn)!=0)
19521 #define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */
19522 #define EP_Immutable 0x02 /* Do not change this Expr node */
19530 # define ExprHasVVAProperty(E,P) (((E)->vvaFlags&(P))!=0)
19531 # define ExprClearVVAProperties(E) (E)->vvaFlags = 0
19534 # define ExprHasVVAProperty(E,P) 0
19551 #define EXPRDUP_REDUCE 0x0001 /* Used reduced-size Expr nodes */
19558 # define IsWindowFunc(p) 0
19624 #define ENAME_NAME 0 /* The AS clause of a result set */
19642 ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
19658 #define EU4_NONE 0 /* Does not use IdList.a.u4 */
19746 Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */
19789 #define JT_INNER 0x01 /* Any kind of inner or cross join */
19790 #define JT_CROSS 0x02 /* Explicit use of the CROSS keyword */
19791 #define JT_NATURAL 0x04 /* True for a "natural" join */
19792 #define JT_LEFT 0x08 /* Left outer join */
19793 #define JT_RIGHT 0x10 /* Right outer join */
19794 #define JT_OUTER 0x20 /* The "OUTER" keyword is present */
19795 #define JT_LTORJ 0x40 /* One of the LEFT operands of a RIGHT JOIN
19797 #define JT_ERROR 0x80 /* unknown or unsupported join type */
19806 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
19807 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
19808 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
19809 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
19810 #define WHERE_ONEPASS_MULTIROW 0x0008 /* ONEPASS is ok with multiple rows */
19811 #define WHERE_DUPLICATES_OK 0x0010 /* Ok to return a row more than once */
19812 #define WHERE_OR_SUBCLAUSE 0x0020 /* Processing a sub-WHERE as part of
19814 #define WHERE_GROUPBY 0x0040 /* pOrderBy is really a GROUP BY */
19815 #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
19816 #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
19817 #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
19818 #define WHERE_AGG_DISTINCT 0x0400 /* Query is "SELECT agg(DISTINCT ...)" */
19819 #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
19820 #define WHERE_RIGHT_JOIN 0x1000 /* Processing a RIGHT JOIN */
19821 #define WHERE_KEEP_ALL_JOINS 0x2000 /* Do not do the omit-noop-join opt */
19822 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
19823 /* 0x8000 not currently used */
19827 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
19880 #define NC_AllowAgg 0x000001 /* Aggregate functions are allowed here */
19881 #define NC_PartIdx 0x000002 /* True if resolving a partial index WHERE */
19882 #define NC_IsCheck 0x000004 /* True if resolving a CHECK constraint */
19883 #define NC_GenCol 0x000008 /* True for a GENERATED ALWAYS AS clause */
19884 #define NC_HasAgg 0x000010 /* One or more aggregate functions seen */
19885 #define NC_IdxExpr 0x000020 /* True if resolving columns of CREATE INDEX */
19886 #define NC_SelfRef 0x00002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */
19887 #define NC_Subquery 0x000040 /* A subquery has been seen */
19888 #define NC_UEList 0x000080 /* True if uNC.pEList is used */
19889 #define NC_UAggInfo 0x000100 /* True if uNC.pAggInfo is used */
19890 #define NC_UUpsert 0x000200 /* True if uNC.pUpsert is used */
19891 #define NC_UBaseReg 0x000400 /* True if uNC.iBaseReg is used */
19892 #define NC_MinMaxAgg 0x001000 /* min/max aggregates seen. See note above */
19893 /* 0x002000 // available for reuse */
19894 #define NC_AllowWin 0x004000 /* Window functions are allowed here */
19895 #define NC_HasWin 0x008000 /* One or more window functions seen */
19896 #define NC_IsDDL 0x010000 /* Resolving names in a CREATE statement */
19897 #define NC_InAggFunc 0x020000 /* True if analyzing arguments to an agg func */
19898 #define NC_FromDDL 0x040000 /* SQL text comes from sqlite_schema */
19899 #define NC_NoSelect 0x080000 /* Do not descend into sub-selects */
19900 #define NC_Where 0x100000 /* Processing WHERE clause of a SELECT */
19901 #define NC_OrderAgg 0x8000000 /* Has an aggregate other than count/min/max */
19953 ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
19990 #define SF_Distinct 0x0000001 /* Output should be DISTINCT */
19991 #define SF_All 0x0000002 /* Includes the ALL keyword */
19992 #define SF_Resolved 0x0000004 /* Identifiers have been resolved */
19993 #define SF_Aggregate 0x0000008 /* Contains agg functions or a GROUP BY */
19994 #define SF_HasAgg 0x0000010 /* Contains aggregate functions */
19995 #define SF_UsesEphemeral 0x0000020 /* Uses the OpenEphemeral opcode */
19996 #define SF_Expanded 0x0000040 /* sqlite3SelectExpand() called on this */
19997 #define SF_HasTypeInfo 0x0000080 /* FROM subqueries have Table metadata */
19998 #define SF_Compound 0x0000100 /* Part of a compound query */
19999 #define SF_Values 0x0000200 /* Synthesized from VALUES clause */
20000 #define SF_MultiValue 0x0000400 /* Single VALUES term with multiple rows */
20001 #define SF_NestedFrom 0x0000800 /* Part of a parenthesized FROM clause */
20002 #define SF_MinMaxAgg 0x0001000 /* Aggregate containing min() or max() */
20003 #define SF_Recursive 0x0002000 /* The recursive part of a recursive CTE */
20004 #define SF_FixedLimit 0x0004000 /* nSelectRow set by a constant LIMIT */
20005 #define SF_MaybeConvert 0x0008000 /* Need convertCompoundSelectToSubquery() */
20006 #define SF_Converted 0x0010000 /* By convertCompoundSelectToSubquery() */
20007 #define SF_IncludeHidden 0x0020000 /* Include hidden columns in output */
20008 #define SF_ComplexResult 0x0040000 /* Result contains subquery or function */
20009 #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */
20010 #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */
20011 #define SF_View 0x0200000 /* SELECT statement is a view */
20012 #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */
20013 #define SF_UFSrcCheck 0x0800000 /* Check pSrc as required by UPDATE...FROM */
20014 #define SF_PushDown 0x1000000 /* Modified by WHERE-clause push-down opt */
20015 #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */
20016 #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */
20017 #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */
20018 #define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */
20019 #define SF_Correlated 0x20000000 /* True if references the outer context */
20024 ((X)->u4.pSubq->pSelect->selFlags&SF_NestedFrom)!=0)
20092 ** pDest->iSDParm. If (pDest->iSDParm<0), then the temp
20095 ** key. If (pDest->iSDParm>0), then the table is an index
20167 ** The TriggerPrg.aColmask[0] variable is set to a mask of old.* columns
20168 ** accessed (or set to 0 for triggers fired as a result of INSERT
20185 # define DbMaskTest(M,I) (((M)[(I)/8]&(1<<((I)&7)))!=0)
20186 # define DbMaskZero(M) memset((M),0,sizeof(M))
20189 # define DbMaskNonZero(M) (sqlite3DbMaskAllZero(M)==0)
20192 # define DbMaskTest(M,I) (((M)&(((yDbMask)1)<<(I)))!=0)
20193 # define DbMaskZero(M) ((M)=0)
20195 # define DbMaskAllZero(M) ((M)==0)
20196 # define DbMaskNonZero(M) ((M)!=0)
20373 #define PARSE_MODE_NORMAL 0
20391 #define IN_DECLARE_VTAB 0
20397 #define IN_RENAME_OBJECT 0
20403 #define IN_SPECIAL_PARSE 0
20429 #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
20431 #define OPFLAG_NOCHNG 0x01 /* OP_VColumn nochange for UPDATE */
20432 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
20433 #define OPFLAG_LASTROWID 0x20 /* Set to update db->lastRowid */
20434 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
20435 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */
20436 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
20437 #define OPFLAG_ISNOOP 0x40 /* OP_Delete does pre-update-hook only */
20438 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
20439 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
20440 #define OPFLAG_BYTELENARG 0xc0 /* OP_Column only for octet_length() */
20441 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
20442 #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */
20443 #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */
20444 #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */
20445 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
20446 #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */
20447 #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */
20448 #define OPFLAG_NOCHNG_MAGIC 0x6d /* OP_MakeRecord: serialtype 10 is ok */
20449 #define OPFLAG_PREFORMAT 0x80 /* OP_Insert uses preformatted cell */
20573 u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
20578 #define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */
20579 #define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */
20580 #define SQLITE_PRINTF_MALLOCED 0x04 /* True if zText is allocated space */
20582 #define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0)
20614 int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */
20618 Pgno mxPage; /* Maximum page number. 0 for no limit. */
20624 #define INITFLAG_AlterMask 0x0003 /* Types of ALTER */
20625 #define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */
20626 #define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */
20627 #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */
20642 # define Tuning(X) 0
20710 ** feature is disabled. 0 if rowids can
20740 #define CORRUPT_DB (sqlite3Config.neverCorrupt==0)
20811 # define sqlite3SelectPopWith 0
20818 #define WRC_Continue 0 /* Continue down into children */
20837 #define M10d_Yes 0 /* AS MATERIALIZED */
20930 u8 eFrmType; /* TK_RANGE, TK_GROUPS, TK_ROWS, or 0 */
20934 u8 eExclude; /* TK_NO, TK_CURRENT, TK_TIES, TK_GROUP, or 0 */
20988 if( (*(zIn++))>=0xc0 ){ \
20989 while( (*zIn & 0xc0)==0x80 ){ zIn++; } \
21046 # define sqlite3Toupper(x) ((x)&~(sqlite3CtypeMap[(unsigned char)(x)]&0x20))
21047 # define sqlite3Isspace(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x01)
21048 # define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06)
21049 # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
21050 # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
21051 # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
21053 # define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80)
21054 # define sqlite3JsonId1(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x42)
21055 # define sqlite3JsonId2(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x46)
21065 # define sqlite3JsonId1(x) (sqlite3IsIdChar(x)&&(x)<'0')
21075 #define sqlite3Strlen30NN(C) (strlen(C)&0x3fffffff)
21167 # define EXP754 (((u64)0x7ff)<<52)
21169 # define IsNaN(X) (((X)&EXP754)==EXP754 && ((X)&MAN754)!=0)
21174 # define IsNaN(X) 0
21175 # define sqlite3IsNaN(X) 0
21176 # define sqlite3IsOVerflow(X) 0
21358 #define sqlite3CodecQueryParameters(A,B,C) 0
21390 # define sqlite3ViewGetColumnNames(A,B) 0
21462 #define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */
21481 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
21482 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
21483 #define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */
21484 #define SQLITE_ECEL_OMITREF 0x08 /* Omit if ExprList.u.x.iOrderByCol */
21489 #define LOCATE_VIEW 0x01
21490 #define LOCATE_NOERR 0x02
21612 # define sqlite3IsToplevel(p) ((p)->pToplevel==0)
21614 # define sqlite3TriggersExist(B,C,D,E,F) 0
21620 # define sqlite3TriggerList(X, Y) 0
21623 # define sqlite3TriggerColmask(A,B,C,D,E,F,G) 0
21624 # define sqlite3TriggerStepSrc(A,B) 0
21691 (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B)))
21693 B=(u32)*(A);if(B>=0x80)sqlite3GetVarint32((A),(u32*)&(B))
21695 (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\
21729 # define sqlite3IsMemdb(X) 0
21938 # define sqlite3VtabInSync(db) 0
21944 # define sqlite3GetVTable(X,Y) ((VTable*)0)
21965 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
21973 # define sqlite3ShadowTableName(A,B) 0
21974 # define sqlite3IsShadowTableOf(A,B,C) 0
22018 # define sqlite3CteNew(P,T,E,S) ((void*)0)
22020 # define sqlite3CteWithAdd(P,W,C) ((void*)0)
22022 # define sqlite3WithPush(x,y,z) ((void*)0)
22033 #define sqlite3UpsertNew(u,v,w,x,y,z) ((Upsert*)0)
22035 #define sqlite3UpsertDup(x,y) ((Upsert*)0)
22036 #define sqlite3UpsertOfIndex(x,y) ((Upsert*)0)
22037 #define sqlite3UpsertNextIsIPK(x) 0
22060 #define sqlite3FkOldmask(a,b) 0
22061 #define sqlite3FkRequired(a,b,c,d) 0
22062 #define sqlite3FkReferences(a) 0
22075 ** Available fault injectors. Should be numbered beginning with 0.
22077 #define SQLITE_FAULTINJECTOR_MALLOC 0
22104 #define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */
22105 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */
22106 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
22120 #if SQLITE_MAX_EXPR_DEPTH>0
22124 #define sqlite3SelectExprHeight(x) 0
22200 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
22201 #define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */
22202 #define MEMTYPE_PCACHE 0x04 /* Page cache allocations */
22207 #if SQLITE_MAX_WORKER_THREADS>0
22242 # define IS_STMT_SCANSTATUS(db) 0
22294 #define TIMER_ELAPSED ((sqlite_uint64)0)
23151 *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]); in sqlite3CompileOptions()
23184 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
23201 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 0x */
23240 1, 0, 0, 1, 1, 0, /* aLTb[]: Use when compare(A,B) less than zero */
23241 0, 1, 0, 1, 0, 1, /* aEQb[]: Use when compare(A,B) equals zero */
23242 1, 0, 1, 0, 0, 1 /* aGTb[]: Use when compare(A,B) greater than zero*/
23252 ** isspace() 0x01
23253 ** isalpha() 0x02
23254 ** isdigit() 0x04
23255 ** isalnum() 0x06
23256 ** isxdigit() 0x08
23257 ** toupper() 0x20
23258 ** SQLite identifier character 0x40 $, _, or non-ascii
23259 ** Quote character 0x80
23261 ** Bit 0x20 is set if the mapped character requires translation to upper
23264 ** is (x - 0x20). Therefore toupper() can be implemented as:
23266 ** (x & ~(map[x]&0x20))
23271 ** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
23274 ** part of an identifier is 0x46.
23277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
23278 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
23279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
23280 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
23281 0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80, /* 20..27 !"#$%&' */
23282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */
23283 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */
23284 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */
23286 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */
23287 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */
23288 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */
23289 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
23290 0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
23291 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */
23292 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */
23293 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */
23295 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */
23296 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 88..8f ........ */
23297 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 90..97 ........ */
23298 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 98..9f ........ */
23299 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a0..a7 ........ */
23300 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a8..af ........ */
23301 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b0..b7 ........ */
23302 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b8..bf ........ */
23304 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c0..c7 ........ */
23305 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c8..cf ........ */
23306 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d0..d7 ........ */
23307 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d8..df ........ */
23308 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e0..e7 ........ */
23309 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e8..ef ........ */
23310 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
23311 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
23319 ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
23326 # define SQLITE_USE_URI 0
23338 -DSQLITE_ALLOW_COVERING_INDEX_SCAN=0 option is deprecated.\
23352 ** threshold (in bytes). 0 means that statement journals are created and
23354 ** before 3.12.0). -1 means always keep the entire statement journal in
23402 0, /* bSmallMalloc */
23405 0, /* bJsonSelfcheck */
23407 0x7ffffffe, /* mxStrlen */
23408 0, /* neverCorrupt */
23411 {0,0,0,0,0,0,0,0}, /* m */
23412 {0,0,0,0,0,0,0,0,0}, /* mutex */
23413 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
23414 (void*)0, /* pHeap */
23415 0, /* nHeap */
23416 0, 0, /* mnHeap, mxHeap */
23419 (void*)0, /* pPage */
23420 0, /* szPage */
23422 0, /* mxParserStack */
23423 0, /* sharedCacheEnabled */
23426 0, /* isInit */
23427 0, /* inProgress */
23428 0, /* isMutexInit */
23429 0, /* isMallocInit */
23430 0, /* isPCacheInit */
23431 0, /* nRefInitMutex */
23432 0, /* pInitMutex */
23433 0, /* xLog */
23434 0, /* pLogArg */
23436 0, /* xSqllog */
23437 0, /* pSqllogArg */
23440 0, /* xVdbeBranch */
23441 0, /* pVbeBranchArg */
23447 0, /* xTestCallback */
23450 0, /* mNoVisibleRowid. 0 == allow rowid-in-view */
23452 0, /* bLocaltimeFault */
23453 0, /* xAltLocaltime */
23454 0x7ffffffe, /* iOnceResetThreshold */
23456 0, /* iPrngSeed */
23458 {0,0,0,0,0,0}, /* aTune */
23486 SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt = 0;
23490 ** The value of the "pending" byte must be 0x40000000 (1 byte past the
23503 ** 0x40000000 results in an incompatible database file format!
23508 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
23514 SQLITE_PRIVATE u32 sqlite3TreeTrace = 0;
23515 SQLITE_PRIVATE u32 sqlite3WhereTrace = 0;
23618 # define VDBE_DISPLAY_P4 0
23643 #define CURTYPE_BTREE 0
23683 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
23686 int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
23732 ((P)->eCurType==CURTYPE_PSEUDO && (P)->nullRow && (P)->seekResult==0)
23737 #define CACHE_STALE 0
23799 #define SQLITE_FRAME_MAGIC 0x879fb71e
23821 int n; /* Number of characters in string value, excluding '\0' */
23829 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
23871 ** MEM.u.i extra 0x00 bytes at the end.
23889 #define MEM_Undefined 0x0000 /* Value is undefined */
23890 #define MEM_Null 0x0001 /* Value is NULL (or a pointer) */
23891 #define MEM_Str 0x0002 /* Value is a string */
23892 #define MEM_Int 0x0004 /* Value is an integer */
23893 #define MEM_Real 0x0008 /* Value is a real number */
23894 #define MEM_Blob 0x0010 /* Value is a BLOB */
23895 #define MEM_IntReal 0x0020 /* MEM_Int that stringifies like MEM_Real */
23896 #define MEM_AffMask 0x003f /* Mask of affinity bits */
23900 #define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */
23901 /* 0x0080 // Available */
23902 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
23903 #define MEM_Term 0x0200 /* String in Mem.z is zero terminated */
23904 #define MEM_Zero 0x0400 /* Mem.i contains count of 0s appended to blob */
23905 #define MEM_Subtype 0x0800 /* Mem.eSubtype is valid */
23906 #define MEM_TypeMask 0x0dbf /* Mask of type bits */
23911 #define MEM_Dyn 0x1000 /* Need to call Mem.xDel() on Mem.z */
23912 #define MEM_Static 0x2000 /* Mem.z points to a static string */
23913 #define MEM_Ephem 0x4000 /* Mem.z points to an ephemeral string */
23914 #define MEM_Agg 0x8000 /* Mem.z points to an agg function context */
23920 (((X)->flags&(MEM_Agg|MEM_Dyn))!=0)
23933 && (X)->n==0 && (X)->u.nZero==0)
23944 #define memIsValid(M) ((M)->flags & MEM_AffMask)!=0
24005 ** instructions. A start value of 0 indicates an empty range.
24049 int iStatement; /* Statement number (or 0 if has no opened stmt) */
24084 bft explain:2; /* 0: normal, 1: EXPLAIN, 2: EXPLAIN QUERY PLAN */
24114 #define VDBE_INIT_STATE 0 /* Prepared statement under construction */
24140 u8 keyinfoSpace[SZ_KEYINFO(0)]; /* Space to hold pKeyinfo[0] content */
24292 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
24306 # define sqlite3VdbeCheckFk(p,i) 0
24320 #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
24343 } sqlite3Stat = { {0,}, {0,} };
24350 0, /* SQLITE_STATUS_MEMORY_USED */
24353 0, /* SQLITE_STATUS_SCRATCH_USED */
24354 0, /* SQLITE_STATUS_SCRATCH_OVERFLOW */
24355 0, /* SQLITE_STATUS_MALLOC_SIZE */
24356 0, /* SQLITE_STATUS_PARSER_STACK */
24358 0, /* SQLITE_STATUS_SCRATCH_SIZE */
24359 0, /* SQLITE_STATUS_MALLOC_COUNT */
24371 # define wsdStat x[0]
24383 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); in sqlite3StatusValue()
24384 assert( op>=0 && op<ArraySize(statMutex) ); in sqlite3StatusValue()
24403 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); in sqlite3StatusUp()
24404 assert( op>=0 && op<ArraySize(statMutex) ); in sqlite3StatusUp()
24414 assert( N>=0 ); in sqlite3StatusDown()
24415 assert( op>=0 && op<ArraySize(statMutex) ); in sqlite3StatusDown()
24418 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); in sqlite3StatusDown()
24429 assert( X>=0 ); in sqlite3StatusHighwater()
24431 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); in sqlite3StatusHighwater()
24432 assert( op>=0 && op<ArraySize(statMutex) ); in sqlite3StatusHighwater()
24454 if( op<0 || op>=ArraySize(wsdStat.nowValue) ){ in sqlite3_status64()
24458 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; in sqlite3_status64()
24468 (void)pMutex; /* Prevent warning when SQLITE_THREADSAFE=0 */ in sqlite3_status64()
24472 sqlite3_int64 iCur = 0, iHwtr = 0; in sqlite3_status()
24475 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; in sqlite3_status()
24478 if( rc==0 ){ in sqlite3_status()
24489 u32 cnt = 0; in countLookasideSlots()
24524 if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){ in sqlite3_db_status()
24538 db->lookaside.pFree = 0; in sqlite3_db_status()
24546 db->lookaside.pSmallFree = 0; in sqlite3_db_status()
24559 assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 ); in sqlite3_db_status()
24561 *pCurrent = 0; in sqlite3_db_status()
24564 db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0; in sqlite3_db_status()
24576 int totalUsed = 0; in sqlite3_db_status()
24579 for(i=0; i<db->nDb; i++){ in sqlite3_db_status()
24592 *pHighwater = 0; in sqlite3_db_status()
24603 int nByte = 0; /* Used to accumulate return value */ in sqlite3_db_status()
24609 for(i=0; i<db->nDb; i++){ in sqlite3_db_status()
24611 if( ALWAYS(pSchema!=0) ){ in sqlite3_db_status()
24633 db->pnBytesFreed = 0; in sqlite3_db_status()
24637 *pHighwater = 0; in sqlite3_db_status()
24649 int nByte = 0; /* Used to accumulate return value */ in sqlite3_db_status()
24658 db->pnBytesFreed = 0; in sqlite3_db_status()
24660 *pHighwater = 0; /* IMP: R-64479-57858 */ in sqlite3_db_status()
24678 u64 nRet = 0; in sqlite3_db_status()
24682 for(i=0; i<db->nDb; i++){ in sqlite3_db_status()
24688 *pHighwater = 0; /* IMP: R-42420-56072 */ in sqlite3_db_status()
24691 *pCurrent = (int)nRet & 0x7fffffff; in sqlite3_db_status()
24700 *pHighwater = 0; /* IMP: R-11967-56545 */ in sqlite3_db_status()
24701 *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0; in sqlite3_db_status()
24756 ** ISBN 0-943396-61-1
24808 ** B: minimum value. Always "0" or "1".
24831 int cnt = 0; in getDigits()
24835 char N = zFormat[0] - '0'; in getDigits()
24836 char min = zFormat[1] - '0'; in getDigits()
24837 int val = 0; in getDigits()
24843 val = 0; in getDigits()
24848 val = val*10 + *zDate - '0'; in getDigits()
24851 if( val<(int)min || val>(int)max || (nextC!=0 && nextC!=*zDate) ){ in getDigits()
24875 ** of change in p->tz and return 0. If a parser error occurs,
24881 int sgn = 0; in parseTimezone()
24885 p->tz = 0; in parseTimezone()
24893 p->isLocal = 0; in parseTimezone()
24897 return c!=0; in parseTimezone()
24907 return *zDate!=0; in parseTimezone()
24915 ** Return 1 if there is a parsing error and 0 on success.
24934 ms = ms*10.0 + *zDate - '0'; in parseHhMmSs()
24944 s = 0; in parseHhMmSs()
24946 p->validJD = 0; in parseHhMmSs()
24947 p->rawS = 0; in parseHhMmSs()
24953 return 0; in parseHhMmSs()
24960 memset(p, 0, sizeof(*p)); in datetimeError()
25001 p->validYMD = 0; in computeJD()
25002 p->validHMS = 0; in computeJD()
25003 p->tz = 0; in computeJD()
25005 p->isLocal = 0; in computeJD()
25018 assert( p->D>=0 && p->D<=31 ); in computeFloor()
25019 assert( p->M>=0 && p->M<=12 ); in computeFloor()
25021 p->nFloor = 0; in computeFloor()
25022 }else if( (1<<p->M) & 0x15aa ){ in computeFloor()
25023 p->nFloor = 0; in computeFloor()
25026 }else if( p->Y%4!=0 || (p->Y%100==0 && p->Y%400!=0) ){ in computeFloor()
25041 ** Write the result into the DateTime structure and return 0
25048 if( zDate[0]=='-' ){ in parseYyyyMmDd()
25052 neg = 0; in parseYyyyMmDd()
25059 if( parseHhMmSs(zDate, p)==0 ){ in parseYyyyMmDd()
25061 }else if( *zDate==0 ){ in parseYyyyMmDd()
25062 p->validHMS = 0; in parseYyyyMmDd()
25066 p->validJD = 0; in parseYyyyMmDd()
25075 return 0; in parseYyyyMmDd()
25088 if( p->iJD>0 ){ in setDateTimeToCurrent()
25091 p->isLocal = 0; in setDateTimeToCurrent()
25093 return 0; in setDateTimeToCurrent()
25136 if( parseYyyyMmDd(zDate,p)==0 ){ in parseDateOrTime()
25137 return 0; in parseDateOrTime()
25138 }else if( parseHhMmSs(zDate, p)==0 ){ in parseDateOrTime()
25139 return 0; in parseDateOrTime()
25140 }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){ in parseDateOrTime()
25142 }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8)>0 ){ in parseDateOrTime()
25144 return 0; in parseDateOrTime()
25145 }else if( (sqlite3StrICmp(zDate,"subsec")==0 in parseDateOrTime()
25146 || sqlite3StrICmp(zDate,"subsecond")==0) in parseDateOrTime()
25161 #define INT_464269060799999 ((((i64)0x1a640)<<32)|0x1072fdff)
25169 return iJD>=0 && iJD<=INT_464269060799999; in validJulianDay()
25213 p->rawS = 0; in computeHMS()
25229 p->validYMD = 0; in clearYMD_HMS_TZ()
25230 p->validHMS = 0; in clearYMD_HMS_TZ()
25231 p->tz = 0; in clearYMD_HMS_TZ()
25256 ** is available. This routine returns 0 on success and
25272 #if SQLITE_THREADSAFE>0 in osLocaltime()
25279 if( sqlite3GlobalConfig.xAltLocaltime!=0 in osLocaltime()
25280 && 0==sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm) in osLocaltime()
25284 pX = 0; in osLocaltime()
25289 #if SQLITE_THREADSAFE>0 in osLocaltime()
25292 rc = pX==0; in osLocaltime()
25296 if( sqlite3GlobalConfig.xAltLocaltime!=0 ){ in osLocaltime()
25304 rc = localtime_r(t, pTm)==0; in osLocaltime()
25327 memset(&sLocal, 0, sizeof(sLocal)); in toLocaltime()
25342 x.validJD = 0; in toLocaltime()
25346 iYearDiff = 0; in toLocaltime()
25361 p->validJD = 0; in toLocaltime()
25362 p->rawS = 0; in toLocaltime()
25363 p->tz = 0; in toLocaltime()
25364 p->isError = 0; in toLocaltime()
25383 /* 0 */ { 6, "second", 4.6427e+14, 1.0 },
25398 p->rawS = 0; in autoAdjustDate()
25406 p->rawS = 0; in autoAdjustDate()
25435 ** Return 0 on success and 1 if there is any kind of error. If the error
25449 switch(sqlite3UpperToLower[(u8)z[0]] ){ in parseModifier()
25457 if( sqlite3_stricmp(z, "auto")==0 ){ in parseModifier()
25460 rc = 0; in parseModifier()
25472 if( sqlite3_stricmp(z, "ceiling")==0 ){ in parseModifier()
25475 rc = 0; in parseModifier()
25476 p->nFloor = 0; in parseModifier()
25487 if( sqlite3_stricmp(z, "floor")==0 ){ in parseModifier()
25491 rc = 0; in parseModifier()
25502 ** SQLite (0..5373484.5) then the result will be NULL. in parseModifier()
25504 if( sqlite3_stricmp(z, "julianday")==0 ){ in parseModifier()
25507 rc = 0; in parseModifier()
25508 p->rawS = 0; in parseModifier()
25520 if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){ in parseModifier()
25522 p->isUtc = 0; in parseModifier()
25535 if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){ in parseModifier()
25542 p->rawS = 0; in parseModifier()
25543 rc = 0; in parseModifier()
25547 else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){ in parseModifier()
25548 if( p->isUtc==0 ){ in parseModifier()
25551 int cnt = 0; /* Safety to prevent infinite loop */ in parseModifier()
25556 iErr = 0; in parseModifier()
25559 memset(&new, 0, sizeof(new)); in parseModifier()
25568 memset(p, 0, sizeof(*p)); in parseModifier()
25572 p->isLocal = 0; in parseModifier()
25584 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the in parseModifier()
25587 if( sqlite3_strnicmp(z, "weekday ", 8)==0 in parseModifier()
25588 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)>0 in parseModifier()
25592 p->tz = 0; in parseModifier()
25593 p->validJD = 0; in parseModifier()
25599 rc = 0; in parseModifier()
25616 if( sqlite3_strnicmp(z, "start of ", 9)!=0 ){ in parseModifier()
25617 if( sqlite3_stricmp(z, "subsec")==0 in parseModifier()
25618 || sqlite3_stricmp(z, "subsecond")==0 in parseModifier()
25621 rc = 0; in parseModifier()
25629 p->h = p->m = 0; in parseModifier()
25631 p->rawS = 0; in parseModifier()
25632 p->tz = 0; in parseModifier()
25633 p->validJD = 0; in parseModifier()
25634 if( sqlite3_stricmp(z,"month")==0 ){ in parseModifier()
25636 rc = 0; in parseModifier()
25637 }else if( sqlite3_stricmp(z,"year")==0 ){ in parseModifier()
25640 rc = 0; in parseModifier()
25641 }else if( sqlite3_stricmp(z,"day")==0 ){ in parseModifier()
25642 rc = 0; in parseModifier()
25648 case '0': in parseModifier()
25662 char z0 = z[0]; in parseModifier()
25671 if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){ in parseModifier()
25678 ** the range 0-11 and DD is limited to 0-30. in parseModifier()
25688 if( M>=12 ) break; /* M range 0..11 */ in parseModifier()
25689 if( D>=31 ) break; /* D range 0..30 */ in parseModifier()
25691 p->validJD = 0; in parseModifier()
25700 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; in parseModifier()
25705 p->validHMS = 0; in parseModifier()
25706 p->validYMD = 0; in parseModifier()
25708 if( z[11]==0 ){ in parseModifier()
25709 rc = 0; in parseModifier()
25731 memset(&tx, 0, sizeof(tx)); in parseModifier()
25741 rc = 0; in parseModifier()
25754 rRounder = r<0 ? -0.5 : +0.5; in parseModifier()
25755 p->nFloor = 0; in parseModifier()
25756 for(i=0; i<ArraySize(aXformType); i++){ in parseModifier()
25758 && sqlite3_strnicmp(aXformType[i].zName, z, n)==0 in parseModifier()
25763 assert( strcmp(aXformType[4].zName,"month")==0 ); in parseModifier()
25766 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; in parseModifier()
25770 p->validJD = 0; in parseModifier()
25776 assert( strcmp(aXformType[5].zName,"year")==0 ); in parseModifier()
25778 assert( p->M>=0 && p->M<=12 ); in parseModifier()
25781 p->validJD = 0; in parseModifier()
25788 rc = 0; in parseModifier()
25803 ** Process time function arguments. argv[0] is a date-time stamp.
25805 ** the resulting time into the DateTime structure p. Return 0
25808 ** If there are zero parameters (if even argv[0] is undefined)
25809 ** then assume a default value of "now" for argv[0].
25820 memset(p, 0, sizeof(*p)); in isDate()
25821 if( argc==0 ){ in isDate()
25825 if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT in isDate()
25827 setRawDateNumber(p, sqlite3_value_double(argv[0])); in isDate()
25829 z = sqlite3_value_text(argv[0]); in isDate()
25837 if( z==0 || parseModifier(context, (char*)z, n, p, i) ) return 1; in isDate()
25845 p->validYMD = 0; in isDate()
25847 return 0; in isDate()
25867 if( isDate(context, argc, argv, &x)==0 ){ in juliandayFunc()
25885 if( isDate(context, argc, argv, &x)==0 ){ in unixepochFunc()
25906 if( isDate(context, argc, argv, &x)==0 ){ in datetimeFunc()
25911 if( Y<0 ) Y = -Y; in datetimeFunc()
25912 zBuf[1] = '0' + (Y/1000)%10; in datetimeFunc()
25913 zBuf[2] = '0' + (Y/100)%10; in datetimeFunc()
25914 zBuf[3] = '0' + (Y/10)%10; in datetimeFunc()
25915 zBuf[4] = '0' + (Y)%10; in datetimeFunc()
25917 zBuf[6] = '0' + (x.M/10)%10; in datetimeFunc()
25918 zBuf[7] = '0' + (x.M)%10; in datetimeFunc()
25920 zBuf[9] = '0' + (x.D/10)%10; in datetimeFunc()
25921 zBuf[10] = '0' + (x.D)%10; in datetimeFunc()
25923 zBuf[12] = '0' + (x.h/10)%10; in datetimeFunc()
25924 zBuf[13] = '0' + (x.h)%10; in datetimeFunc()
25926 zBuf[15] = '0' + (x.m/10)%10; in datetimeFunc()
25927 zBuf[16] = '0' + (x.m)%10; in datetimeFunc()
25931 zBuf[18] = '0' + (s/10000)%10; in datetimeFunc()
25932 zBuf[19] = '0' + (s/1000)%10; in datetimeFunc()
25934 zBuf[21] = '0' + (s/100)%10; in datetimeFunc()
25935 zBuf[22] = '0' + (s/10)%10; in datetimeFunc()
25936 zBuf[23] = '0' + (s)%10; in datetimeFunc()
25937 zBuf[24] = 0; in datetimeFunc()
25941 zBuf[18] = '0' + (s/10)%10; in datetimeFunc()
25942 zBuf[19] = '0' + (s)%10; in datetimeFunc()
25943 zBuf[20] = 0; in datetimeFunc()
25946 if( x.Y<0 ){ in datetimeFunc()
25947 zBuf[0] = '-'; in datetimeFunc()
25966 if( isDate(context, argc, argv, &x)==0 ){ in timeFunc()
25970 zBuf[0] = '0' + (x.h/10)%10; in timeFunc()
25971 zBuf[1] = '0' + (x.h)%10; in timeFunc()
25973 zBuf[3] = '0' + (x.m/10)%10; in timeFunc()
25974 zBuf[4] = '0' + (x.m)%10; in timeFunc()
25978 zBuf[6] = '0' + (s/10000)%10; in timeFunc()
25979 zBuf[7] = '0' + (s/1000)%10; in timeFunc()
25981 zBuf[9] = '0' + (s/100)%10; in timeFunc()
25982 zBuf[10] = '0' + (s/10)%10; in timeFunc()
25983 zBuf[11] = '0' + (s)%10; in timeFunc()
25984 zBuf[12] = 0; in timeFunc()
25988 zBuf[6] = '0' + (s/10)%10; in timeFunc()
25989 zBuf[7] = '0' + (s)%10; in timeFunc()
25990 zBuf[8] = 0; in timeFunc()
26008 if( isDate(context, argc, argv, &x)==0 ){ in dateFunc()
26013 if( Y<0 ) Y = -Y; in dateFunc()
26014 zBuf[1] = '0' + (Y/1000)%10; in dateFunc()
26015 zBuf[2] = '0' + (Y/100)%10; in dateFunc()
26016 zBuf[3] = '0' + (Y/10)%10; in dateFunc()
26017 zBuf[4] = '0' + (Y)%10; in dateFunc()
26019 zBuf[6] = '0' + (x.M/10)%10; in dateFunc()
26020 zBuf[7] = '0' + (x.M)%10; in dateFunc()
26022 zBuf[9] = '0' + (x.D/10)%10; in dateFunc()
26023 zBuf[10] = '0' + (x.D)%10; in dateFunc()
26024 zBuf[11] = 0; in dateFunc()
26025 if( x.Y<0 ){ in dateFunc()
26026 zBuf[0] = '-'; in dateFunc()
26040 ** Jan01 = 0, Jan02 = 1, ..., Jan31 = 30, Feb01 = 31, ...
26048 jan01.validJD = 0; in daysAfterJan01()
26061 ** 0=Monday, 1=Tuesday, 2=Wednesday, ..., 6=Sunday.
26074 ** 0=Sunday, 1=Monday, 2=Tuesday, ..., 6=Saturday
26093 ** %k hour 0-24 (leading zero converted to space)
26107 ** %w day of week 0-6 Sunday==0, Monday==1
26126 if( argc==0 ) return; in strftimeFunc()
26127 zFmt = (const char*)sqlite3_value_text(argv[0]); in strftimeFunc()
26128 if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return; in strftimeFunc()
26130 sqlite3StrAccumInit(&sRes, 0, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); in strftimeFunc()
26134 for(i=j=0; zFmt[i]; i++){ in strftimeFunc()
26163 y.validYMD = 0; in strftimeFunc()
26181 if( h==0 ) h = 12; in strftimeFunc()
26233 case 'w': { /* Day of week. 0 to 6. Sunday==0, Monday==1 */ in strftimeFunc()
26234 char c = (char)daysAfterSunday(&x) + '0'; in strftimeFunc()
26235 if( c=='0' && cf=='u' ) c = '7'; in strftimeFunc()
26249 y.validYMD = 0; in strftimeFunc()
26288 timeFunc(context, 0, 0); in ctimeFunc()
26302 dateFunc(context, 0, 0); in cdateFunc()
26332 if( isDate(context, 1, &argv[0], &d1) ) return; in timediffFunc()
26341 d2.validJD = 0; in timediffFunc()
26345 if( M<0 ){ in timediffFunc()
26349 if( M!=0 ){ in timediffFunc()
26351 d2.validJD = 0; in timediffFunc()
26356 if( M<0 ){ in timediffFunc()
26365 d2.validJD = 0; in timediffFunc()
26375 d2.validJD = 0; in timediffFunc()
26379 if( M<0 ){ in timediffFunc()
26383 if( M!=0 ){ in timediffFunc()
26385 d2.validJD = 0; in timediffFunc()
26390 if( M<0 ){ in timediffFunc()
26399 d2.validJD = 0; in timediffFunc()
26407 sqlite3StrAccumInit(&sRes, 0, 0, 0, 100); in timediffFunc()
26425 datetimeFunc(context, 0, 0); in ctimestampFunc()
26457 if( iT<=0 ) return; in currentTimeFunc()
26487 if( isDate(context, argc, argv, &x)==0 ){ in datedebugFunc()
26512 PURE_DATE(julianday, -1, 0, 0, juliandayFunc ), in sqlite3RegisterDateTimeFunctions()
26513 PURE_DATE(unixepoch, -1, 0, 0, unixepochFunc ), in sqlite3RegisterDateTimeFunctions()
26514 PURE_DATE(date, -1, 0, 0, dateFunc ), in sqlite3RegisterDateTimeFunctions()
26515 PURE_DATE(time, -1, 0, 0, timeFunc ), in sqlite3RegisterDateTimeFunctions()
26516 PURE_DATE(datetime, -1, 0, 0, datetimeFunc ), in sqlite3RegisterDateTimeFunctions()
26517 PURE_DATE(strftime, -1, 0, 0, strftimeFunc ), in sqlite3RegisterDateTimeFunctions()
26518 PURE_DATE(timediff, 2, 0, 0, timediffFunc ), in sqlite3RegisterDateTimeFunctions()
26520 PURE_DATE(datedebug, -1, 0, 0, datedebugFunc ), in sqlite3RegisterDateTimeFunctions()
26522 DFUNCTION(current_time, 0, 0, 0, ctimeFunc ), in sqlite3RegisterDateTimeFunctions()
26523 DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc), in sqlite3RegisterDateTimeFunctions()
26524 DFUNCTION(current_date, 0, 0, 0, cdateFunc ), in sqlite3RegisterDateTimeFunctions()
26526 STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc), in sqlite3RegisterDateTimeFunctions()
26527 STR_FUNCTION(current_date, 0, "%Y-%m-%d", 0, currentTimeFunc), in sqlite3RegisterDateTimeFunctions()
26528 STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc), in sqlite3RegisterDateTimeFunctions()
26559 SQLITE_API int sqlite3_io_error_hit = 0; /* Total number of I/O Errors */
26560 SQLITE_API int sqlite3_io_error_hardhit = 0; /* Number of non-benign errors */
26561 SQLITE_API int sqlite3_io_error_pending = 0; /* Count down to first I/O error */
26562 SQLITE_API int sqlite3_io_error_persist = 0; /* True if I/O errors persist */
26563 SQLITE_API int sqlite3_io_error_benign = 0; /* True if errors are benign */
26564 SQLITE_API int sqlite3_diskfull_pending = 0;
26565 SQLITE_API int sqlite3_diskfull = 0;
26572 SQLITE_API int sqlite3_open_file_count = 0;
26620 pId->pMethods = 0; in sqlite3OsClose()
26665 if( id->pMethods==0 ) return SQLITE_NOTFOUND; in sqlite3OsFileControl()
26701 if( NEVER(id->pMethods==0) ) return 0; in sqlite3OsDeviceCharacteristics()
26726 #if SQLITE_MAX_MMAP_SIZE>0
26738 *pp = 0; in sqlite3OsFetch()
26758 DO_OS_MALLOC_TEST(0); in sqlite3OsOpen()
26759 /* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed in sqlite3OsOpen()
26764 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut); in sqlite3OsOpen()
26765 assert( rc==SQLITE_OK || pFile->pMethods==0 ); in sqlite3OsOpen()
26769 DO_OS_MALLOC_TEST(0); in sqlite3OsDelete()
26770 assert( dirSync==0 || dirSync==1 ); in sqlite3OsDelete()
26771 return pVfs->xDelete!=0 ? pVfs->xDelete(pVfs, zPath, dirSync) : SQLITE_OK; in sqlite3OsDelete()
26779 DO_OS_MALLOC_TEST(0); in sqlite3OsAccess()
26788 DO_OS_MALLOC_TEST(0); in sqlite3OsFullPathname()
26789 zPathOut[0] = 0; in sqlite3OsFullPathname()
26794 assert( zPath!=0 ); in sqlite3OsDlOpen()
26810 memset(zBufOut, 0, nByte); in sqlite3OsRandomness()
26823 return pVfs->xGetLastError ? pVfs->xGetLastError(pVfs, 0, 0) : 0; in sqlite3OsGetLastError()
26857 *ppFile = 0; in sqlite3OsOpenMalloc()
26862 *ppFile = 0; in sqlite3OsOpenMalloc()
26865 assert( *ppFile!=0 || rc!=SQLITE_OK ); in sqlite3OsOpenMalloc()
26882 if( p==0 ) return SQLITE_NOMEM_BKPT; in sqlite3OsInit()
26890 static sqlite3_vfs * SQLITE_WSD vfsList = 0;
26898 sqlite3_vfs *pVfs = 0; in sqlite3_vfs_find()
26904 if( rc ) return 0; in sqlite3_vfs_find()
26911 if( zVfs==0 ) break; in sqlite3_vfs_find()
26912 if( strcmp(zVfs, pVfs->zName)==0 ) break; in sqlite3_vfs_find()
26923 if( pVfs==0 ){ in vfsUnlink()
26950 if( pVfs==0 ) return SQLITE_MISUSE_BKPT; in sqlite3_vfs_register()
26956 if( makeDflt || vfsList==0 ){ in sqlite3_vfs_register()
27001 ** and returns 0).
27023 } sqlite3Hooks = { 0, 0 };
27034 # define wsdHooks x[0]
27106 static void *sqlite3MemMalloc(int nByte){ return 0; } in sqlite3MemMalloc()
27108 static void *sqlite3MemRealloc(void *pPrior, int nByte){ return 0; } in sqlite3MemRealloc()
27109 static int sqlite3MemSize(void *pPrior){ return 0; } in sqlite3MemSize()
27129 0 in sqlite3MemSetDefault()
27261 ** For this low-level routine, we are guaranteed that nByte>0 because
27262 ** cases of nByte<=0 will be intercepted and dealt with by higher level
27270 if( p==0 ){ in sqlite3MemMalloc()
27271 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3MemMalloc()
27277 assert( nByte>0 ); in sqlite3MemMalloc()
27281 p[0] = nByte; in sqlite3MemMalloc()
27284 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3MemMalloc()
27295 ** For this low-level routine, we already know that pPrior!=0 since
27296 ** cases where pPrior==0 will have been intercepted and dealt with
27304 assert( pPrior!=0 ); in sqlite3MemFree()
27316 assert( pPrior!=0 ); in sqlite3MemSize()
27320 assert( pPrior!=0 ); in sqlite3MemSize()
27323 return (int)p[0]; in sqlite3MemSize()
27331 ** For this low-level interface, we know that pPrior!=0. Cases where
27332 ** pPrior==0 while have been intercepted by higher-level routine and
27333 ** redirected to xMalloc. Similarly, we know that nByte>0 because
27334 ** cases where nByte<=0 will have been intercepted by higher-level
27340 if( p==0 ){ in sqlite3MemRealloc()
27341 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3MemRealloc()
27349 assert( pPrior!=0 && nByte>0 ); in sqlite3MemRealloc()
27354 p[0] = nByte; in sqlite3MemRealloc()
27357 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3MemRealloc()
27385 sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0); in sqlite3MemInit()
27392 _sqliteZone_ = malloc_create_zone(4096, 0); in sqlite3MemInit()
27423 0 in sqlite3MemSetDefault()
27491 u8 nTitle; /* Bytes of title; includes '\0' */
27499 #define FOREGUARD 0x80F5E153
27500 #define REARGUARD 0xE4676B53
27535 int nTitle; /* Bytes of zTitle to save. Includes '\0' and padding */
27565 if( increment>0 ){ in adjustStats()
27573 assert( mem.nCurrent[i]>=0 ); in adjustStats()
27600 while( nReserve-- > p->iSize ) assert( pU8[nReserve]==0x65 ); in sqlite3MemsysGetHeader()
27610 return 0; in sqlite3MemSize()
27621 assert( (sizeof(struct MemBlockHdr)&7) == 0 ); in sqlite3MemInit()
27635 mem.mutex = 0; in sqlite3MemShutdown()
27655 x = (x>>1) ^ (-(int)(x&1) & 0xd0000001); in randomFill()
27662 while( nByte-- > 0 ){ in randomFill()
27663 x = (x>>1) ^ (-(int)(x&1) & 0xd0000001); in randomFill()
27666 *(pBuf++) = r & 0xff; in randomFill()
27678 void *p = 0; in sqlite3MemMalloc()
27682 assert( mem.disallow==0 ); in sqlite3MemMalloc()
27691 pHdr->pNext = 0; in sqlite3MemMalloc()
27707 assert(pBt[0]); in sqlite3MemMalloc()
27712 pHdr->nBacktrace = 0; in sqlite3MemMalloc()
27722 memset(((char*)pInt)+nByte, 0x65, nReserve-nByte); in sqlite3MemMalloc()
27736 assert( sqlite3GlobalConfig.bMemstat || sqlite3GlobalConfig.bCoreMutex==0 in sqlite3MemFree()
27737 || mem.mutex!=0 ); in sqlite3MemFree()
27777 assert( mem.disallow==0 ); in sqlite3MemRealloc()
27778 assert( (nByte & 7)==0 ); /* EV: R-46199-30249 */ in sqlite3MemRealloc()
27804 0 in sqlite3MemSetDefault()
27836 if( (pHdr->eType&eType)==0 ){ in sqlite3MemdebugHasType()
27837 rc = 0; in sqlite3MemdebugHasType()
27858 if( (pHdr->eType&eType)!=0 ){ in sqlite3MemdebugNoType()
27859 rc = 0; in sqlite3MemdebugNoType()
27871 if( depth<0 ){ depth = 0; } in sqlite3MemdebugBacktrace()
27873 depth = (depth+1)&0xfe; in sqlite3MemdebugBacktrace()
27889 mem.zTitle[n] = 0; in sqlite3MemdebugSettitle()
27913 if( out==0 ){ in sqlite3MemdebugDump()
27932 for(i=0; i<NCSIZE-1; i++){ in sqlite3MemdebugDump()
27951 int nTotal = 0; in sqlite3MemdebugMallocCount()
27952 for(i=0; i<NCSIZE; i++){ in sqlite3MemdebugMallocCount()
28030 ** A chunk index of 0 means "no such chunk" and is the equivalent
28088 ** of the current key chunk. iKeyBlk is 0 if there is no key chunk.
28113 if( prev==0 ){ in memsys3UnlinkFromList()
28121 mem3.aPool[i].u.list.next = 0; in memsys3UnlinkFromList()
28122 mem3.aPool[i].u.list.prev = 0; in memsys3UnlinkFromList()
28132 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 ); in memsys3Unlink()
28152 mem3.aPool[i].u.list.prev = 0; in memsys3LinkIntoList()
28167 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 ); in memsys3Link()
28185 if( sqlite3GlobalConfig.bMemstat==0 && mem3.mutex==0 ){ in memsys3Enter()
28204 mem3.alarmBusy = 0; in memsys3OutOfMemory()
28230 ** is not large enough, return 0.
28238 mem3.iKeyBlk = 0; in memsys3FromKeyBlk()
28239 mem3.szKeyBlk = 0; in memsys3FromKeyBlk()
28240 mem3.mnKeyBlk = 0; in memsys3FromKeyBlk()
28281 for(i=*pRoot; i>0; i=iNext){ in memsys3Merge()
28284 assert( (size&1)==0 ); in memsys3Merge()
28285 if( (size&2)==0 ){ in memsys3Merge()
28337 if( i>0 ){ in memsys3MallocUnsafe()
28343 for(i=mem3.aiHash[hash]; i>0; i=mem3.aPool[i].u.list.next){ in memsys3MallocUnsafe()
28371 mem3.iKeyBlk = 0; in memsys3MallocUnsafe()
28372 mem3.szKeyBlk = 0; in memsys3MallocUnsafe()
28374 for(i=0; i<N_HASH; i++){ in memsys3MallocUnsafe()
28377 for(i=0; i<MX_SMALL-1; i++){ in memsys3MallocUnsafe()
28389 return 0; in memsys3MallocUnsafe()
28415 while( (mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x&2)==0 ){ in memsys3FreeUnsafe()
28425 while( (mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x&1)==0 ){ in memsys3FreeUnsafe()
28441 assert( p!=0 ); in memsys3Size()
28443 assert( (pBlock[-1].u.hdr.size4x&1)!=0 ); in memsys3Size()
28463 assert( nBytes>0 ); /* malloc.c filters out 0 byte requests */ in memsys3Malloc()
28486 if( pPrior==0 ){ in memsys3Realloc()
28489 if( nBytes<=0 ){ in memsys3Realloc()
28491 return 0; in memsys3Realloc()
28529 mem3.aPool[0].u.hdr.size4x = (mem3.szKeyBlk<<2) + 2; in memsys3Init()
28541 mem3.mutex = 0; in memsys3Shutdown()
28556 if( zFilename==0 || zFilename[0]==0 ){ in sqlite3Memsys3Dump()
28560 if( out==0 ){ in sqlite3Memsys3Dump()
28572 assert( 0 ); in sqlite3Memsys3Dump()
28575 if( (size&1)==0 && mem3.aPool[i+size/4-1].u.hdr.prevSize!=size/4 ){ in sqlite3Memsys3Dump()
28577 assert( 0 ); in sqlite3Memsys3Dump()
28582 assert( 0 ); in sqlite3Memsys3Dump()
28592 for(i=0; i<MX_SMALL-1; i++){ in sqlite3Memsys3Dump()
28593 if( mem3.aiSmall[i]==0 ) continue; in sqlite3Memsys3Dump()
28595 for(j = mem3.aiSmall[i]; j>0; j=mem3.aPool[j].u.list.next){ in sqlite3Memsys3Dump()
28601 for(i=0; i<N_HASH; i++){ in sqlite3Memsys3Dump()
28602 if( mem3.aiHash[i]==0 ) continue; in sqlite3Memsys3Dump()
28604 for(j = mem3.aiHash[i]; j>0; j=mem3.aPool[j].u.list.next){ in sqlite3Memsys3Dump()
28644 0 in sqlite3MemGetMemsys3()
28735 #define CTRL_LOGSIZE 0x1f /* Log2 Size of this block */
28736 #define CTRL_FREE 0x20 /* True if not checked out */
28772 ** Lists of free blocks. aiFreelist[0] is a list of free blocks of
28803 assert( i>=0 && i<mem5.nBlock ); in memsys5Unlink()
28804 assert( iLogsize>=0 && iLogsize<=LOGMAX ); in memsys5Unlink()
28809 if( prev<0 ){ in memsys5Unlink()
28814 if( next>=0 ){ in memsys5Unlink()
28826 assert( i>=0 && i<mem5.nBlock ); in memsys5Link()
28827 assert( iLogsize>=0 && iLogsize<=LOGMAX ); in memsys5Link()
28832 if( x>=0 ){ in memsys5Link()
28855 assert( p!=0 ); in memsys5Size()
28857 assert( i>=0 && i<mem5.nBlock ); in memsys5Size()
28864 ** Return NULL if unable. Return NULL if nBytes==0.
28879 assert( nByte>0 ); in memsys5MallocUnsafe()
28882 if( nByte > 0x40000000 ) return 0; in memsys5MallocUnsafe()
28894 for(iFullSz=mem5.szAtom,iLogsize=0; iFullSz<nByte; iFullSz*=2,iLogsize++){} in memsys5MallocUnsafe()
28900 for(iBin=iLogsize; iBin<=LOGMAX && mem5.aiFreelist[iBin]<0; iBin++){} in memsys5MallocUnsafe()
28902 testcase( sqlite3GlobalConfig.xLog!=0 ); in memsys5MallocUnsafe()
28904 return 0; in memsys5MallocUnsafe()
28932 memset(&mem5.zPool[i*mem5.szAtom], 0xAA, iFullSz); in memsys5MallocUnsafe()
28952 assert( iBlock>=0 && iBlock<mem5.nBlock ); in memsys5FreeUnsafe()
28953 assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 ); in memsys5FreeUnsafe()
28954 assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 ); in memsys5FreeUnsafe()
28964 assert( mem5.currentCount>0 ); in memsys5FreeUnsafe()
28968 assert( mem5.currentOut>0 || mem5.currentCount==0 ); in memsys5FreeUnsafe()
28969 assert( mem5.currentCount>0 || mem5.currentOut==0 ); in memsys5FreeUnsafe()
28977 assert( iBuddy>=0 ); in memsys5FreeUnsafe()
28987 mem5.aCtrl[iBlock] = 0; in memsys5FreeUnsafe()
28991 mem5.aCtrl[iBuddy] = 0; in memsys5FreeUnsafe()
28997 /* Overwrite freed memory with the 0x55 bit pattern to verify that it is in memsys5FreeUnsafe()
28999 memset(&mem5.zPool[iBlock*mem5.szAtom], 0x55, size); in memsys5FreeUnsafe()
29009 sqlite3_int64 *p = 0; in memsys5Malloc()
29010 if( nBytes>0 ){ in memsys5Malloc()
29022 ** being called with pPrior==0.
29025 assert( pPrior!=0 ); in memsys5Free()
29035 ** being called with pPrior==0.
29039 ** of two. If nBytes==0 that means that an oversize allocation
29040 ** (an allocation larger than 0x40000000) was requested and this
29041 ** routine should return 0 without freeing pPrior.
29046 assert( pPrior!=0 ); in memsys5Realloc()
29047 assert( (nBytes&(nBytes-1))==0 ); /* EV: R-46199-30249 */ in memsys5Realloc()
29048 assert( nBytes>=0 ); in memsys5Realloc()
29049 if( nBytes==0 ){ in memsys5Realloc()
29050 return 0; in memsys5Realloc()
29067 ** return 0.
29070 ** 32-bit signed integer. Hence the largest allocation is 0x40000000
29079 if( n>0x10000000 ){ in memsys5Roundup()
29080 if( n>0x40000000 ) return 0; in memsys5Roundup()
29081 if( n>0x20000000 ) return 0x40000000; in memsys5Roundup()
29082 return 0x20000000; in memsys5Roundup()
29092 ** Examples: memsys5Log(1) -> 0
29101 for(iLog=0; (iLog<(int)((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++); in memsys5Log()
29121 mem5.mutex = 0; in memsys5Init()
29126 assert( (sizeof(Mem5Link)&(sizeof(Mem5Link)-1))==0 ); in memsys5Init()
29130 assert( zByte!=0 ); /* sqlite3_config() does not allow otherwise */ in memsys5Init()
29143 for(ii=0; ii<=LOGMAX; ii++){ in memsys5Init()
29147 iOffset = 0; in memsys5Init()
29148 for(ii=LOGMAX; ii>=0; ii--){ in memsys5Init()
29159 if( sqlite3GlobalConfig.bMemstat==0 ){ in memsys5Init()
29171 mem5.mutex = 0; in memsys5Shutdown()
29185 if( zFilename==0 || zFilename[0]==0 ){ in sqlite3Memsys5Dump()
29189 if( out==0 ){ in sqlite3Memsys5Dump()
29197 for(i=0; i<=LOGMAX && i+nMinLog<32; i++){ in sqlite3Memsys5Dump()
29198 for(n=0, j=mem5.aiFreelist[i]; j>=0; j = MEM5LINK(j)->next, n++){} in sqlite3Memsys5Dump()
29232 0 in sqlite3MemGetMemsys5()
29264 static SQLITE_WSD int mutexIsInit = 0;
29325 pGlobalMutexMethods = 0; in checkMutexEnd()
29334 {2, 0}, {3, 0}, {4, 0}, {5, 0}, in checkMutexAlloc()
29335 {6, 0}, {7, 0}, {8, 0}, {9, 0}, in checkMutexAlloc()
29336 {10, 0}, {11, 0}, {12, 0}, {13, 0} in checkMutexAlloc()
29338 CheckMutex *p = 0; in checkMutexAlloc()
29340 assert( SQLITE_MUTEX_RECURSIVE==1 && SQLITE_MUTEX_FAST==0 ); in checkMutexAlloc()
29343 if( p==0 ) return 0; in checkMutexAlloc()
29349 return 0; in checkMutexAlloc()
29355 if( p->mutex==0 ){ in checkMutexAlloc()
29357 if( p->mutex==0 ){ in checkMutexAlloc()
29361 p = 0; in checkMutexAlloc()
29436 0, in multiThreadedCheckMutex()
29437 0 in multiThreadedCheckMutex()
29512 GLOBAL(int, mutexIsInit) = 0; in sqlite3MutexEnd()
29523 if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; in sqlite3_mutex_alloc()
29524 if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0; in sqlite3_mutex_alloc()
29532 return 0; in sqlite3MutexAlloc()
29597 p = 0; in sqlite3_mutex_held()
29600 assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld ); in sqlite3_mutex_held()
29601 return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p); in sqlite3_mutex_held()
29606 p = 0; in sqlite3_mutex_notheld()
29609 assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld ); in sqlite3_mutex_notheld()
29610 return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); in sqlite3_mutex_notheld()
29679 0, in sqlite3NoopMutex()
29680 0, in sqlite3NoopMutex()
29708 return p==0 || p->cnt>0; in debugMutexHeld()
29712 return p==0 || p->cnt==0; in debugMutexNotheld()
29728 sqlite3_debug_mutex *pNew = 0; in debugMutexAlloc()
29735 pNew->cnt = 0; in debugMutexAlloc()
29741 if( id-2<0 || id-2>=ArraySize(aStatic) ){ in debugMutexAlloc()
29743 return 0; in debugMutexAlloc()
29759 assert( p->cnt==0 ); in debugMutexFree()
29870 # define SQLITE_MUTEX_NREF 0
29889 {PTHREAD_MUTEX_INITIALIZER,id,0,(pthread_t)0,0}
29914 return (p->nRef!=0 && pthread_equal(p->owner, pthread_self())); in pthreadMutexHeld()
29917 return p->nRef==0 || pthread_equal(p->owner, pthread_self())==0; in pthreadMutexNotheld()
30011 pthread_mutex_init(&p->mutex, 0); in pthreadMutexAlloc()
30029 pthread_mutex_init(&p->mutex, 0); in pthreadMutexAlloc()
30038 if( iType-2<0 || iType-2>=ArraySize(staticMutexes) ){ in pthreadMutexAlloc()
30040 return 0; in pthreadMutexAlloc()
30048 assert( p==0 || p->id==iType ); in pthreadMutexAlloc()
30060 assert( p->nRef==0 ); in pthreadMutexFree()
30102 if( p->nRef>0 && pthread_equal(p->owner, self) ){ in pthreadMutexEnter()
30106 assert( p->nRef==0 ); in pthreadMutexEnter()
30116 assert( p->nRef>0 || p->owner==0 ); in pthreadMutexEnter()
30145 if( p->nRef>0 && pthread_equal(p->owner, self) ){ in pthreadMutexTry()
30148 }else if( pthread_mutex_trylock(&p->mutex)==0 ){ in pthreadMutexTry()
30149 assert( p->nRef==0 ); in pthreadMutexTry()
30160 if( pthread_mutex_trylock(&p->mutex)==0 ){ in pthreadMutexTry()
30189 if( p->nRef==0 ) p->owner = 0; in pthreadMutexLeave()
30191 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE ); in pthreadMutexLeave()
30194 if( p->nRef==0 ){ in pthreadMutexLeave()
30221 0, in sqlite3DefaultMutex()
30222 0 in sqlite3DefaultMutex()
30297 ** # define SQLITE_OS_WINNT 0
30303 ** by setting SQLITE_OS_WINNT to 0.
30316 # define SQLITE_OS_WINCE 0
30324 # define SQLITE_OS_WINRT 0
30342 SQLITE_THREADSAFE>0 && !defined(__CYGWIN__)
30345 # define SQLITE_OS_WIN_THREADS 0
30378 #define SQLITE_W32_MUTEX_INITIALIZER { 0 }
30382 0L, (DWORD)0, 0 }
30393 return p->nRef!=0 && p->owner==GetCurrentThreadId(); in winMutexHeld()
30397 return p->nRef==0 || p->owner!=tid; in winMutexNotheld2()
30409 ** compiled without mutexes (SQLITE_THREADSAFE=0).
30441 static int winMutex_isInit = 0;
30442 static int winMutex_isNt = -1; /* <0 means "need to query" */
30448 static LONG SQLITE_WIN32_VOLATILE winMutex_lock = 0;
30455 if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){ in winMutexInit()
30457 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){ in winMutexInit()
30459 InitializeCriticalSectionEx(&winMutex_staticMutexes[i].mutex, 0, 0); in winMutexInit()
30476 /* The first to decrement to 0 does actual shutdown in winMutexEnd()
30478 if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){ in winMutexEnd()
30481 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){ in winMutexEnd()
30484 winMutex_isInit = 0; in winMutexEnd()
30553 InitializeCriticalSectionEx(&p->mutex, 0, 0); in winMutexAlloc()
30562 if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){ in winMutexAlloc()
30564 return 0; in winMutexAlloc()
30570 InterlockedCompareExchange(&p->trace, 1, 0); in winMutexAlloc()
30576 assert( p==0 || p->id==iType ); in winMutexAlloc()
30588 assert( p->nRef==0 && p->owner==0 ); in winMutexFree()
30623 assert( p->nRef>0 || p->owner==0 ); in winMutexEnter()
30651 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400 in winMutexTry()
30654 if( winMutex_isNt<0 ){ in winMutexTry()
30657 assert( winMutex_isNt==0 || winMutex_isNt==1 ); in winMutexTry()
30689 assert( p->nRef>0 ); in winMutexLeave()
30692 if( p->nRef==0 ) p->owner = 0; in winMutexLeave()
30693 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE ); in winMutexLeave()
30718 0, in sqlite3DefaultMutex()
30719 0 in sqlite3DefaultMutex()
30759 return 0; in sqlite3_release_memory()
30764 ** Default value of the hard heap limit. 0 means "no limit".
30767 # define SQLITE_MAX_MEMORY 0
30783 } mem0 = { 0, SQLITE_MAX_MEMORY, SQLITE_MAX_MEMORY, 0 };
30833 if( n<0 ){ in sqlite3_soft_heap_limit64()
30837 if( mem0.hardLimit>0 && (n>mem0.hardLimit || n==0) ){ in sqlite3_soft_heap_limit64()
30842 AtomicStore(&mem0.nearlyFull, n>0 && n<=nUsed); in sqlite3_soft_heap_limit64()
30845 if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff)); in sqlite3_soft_heap_limit64()
30849 if( n<0 ) n = 0; in sqlite3_soft_heap_limit()
30873 if( n>=0 ){ in sqlite3_hard_heap_limit64()
30875 if( n<mem0.alarmThreshold || mem0.alarmThreshold==0 ){ in sqlite3_hard_heap_limit64()
30889 if( sqlite3GlobalConfig.m.xMalloc==0 ){ in sqlite3MallocInit()
30893 if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512 in sqlite3MallocInit()
30894 || sqlite3GlobalConfig.nPage<=0 ){ in sqlite3MallocInit()
30895 sqlite3GlobalConfig.pPage = 0; in sqlite3MallocInit()
30896 sqlite3GlobalConfig.szPage = 0; in sqlite3MallocInit()
30899 if( rc!=SQLITE_OK ) memset(&mem0, 0, sizeof(mem0)); in sqlite3MallocInit()
30919 memset(&mem0, 0, sizeof(mem0)); in sqlite3MallocEnd()
30927 sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, 0); in sqlite3_memory_used()
30946 if( mem0.alarmThreshold<=0 ) return; in sqlite3MallocAlarm()
30960 static u64 nOomFault = 0; in test_oom_breakpoint()
30964 assert( (nOomFault>>32) < 0xffffffff ); in test_oom_breakpoint()
30978 assert( n>0 ); in mallocWithAlarm()
30988 if( mem0.alarmThreshold>0 ){ in mallocWithAlarm()
30997 *pp = 0; in mallocWithAlarm()
31002 AtomicStore(&mem0.nearlyFull, 0); in mallocWithAlarm()
31007 if( p==0 && mem0.alarmThreshold>0 ){ in mallocWithAlarm()
31026 ** The upper bound is slightly less than 2GiB: 0x7ffffeff == 2,147,483,391
31030 ** further for an even larger safety margin. 0x3fffffff or 0x0fffffff
31047 if( n==0 || n>SQLITE_MAX_ALLOCATION_SIZE ){ in sqlite3Malloc()
31048 p = 0; in sqlite3Malloc()
31067 if( sqlite3_initialize() ) return 0; in sqlite3_malloc()
31069 return n<=0 ? 0 : sqlite3Malloc(n); in sqlite3_malloc()
31073 if( sqlite3_initialize() ) return 0; in sqlite3_malloc64()
31086 #define isLookaside(A,B) 0
31105 assert( p!=0 ); in sqlite3DbMallocSize()
31107 if( db==0 ){ in sqlite3DbMallocSize()
31134 return p ? sqlite3GlobalConfig.m.xSize(p) : 0; in sqlite3_msize()
31141 if( p==0 ) return; /* IMP: R-49053-54554 */ in sqlite3_free()
31165 ** connection. Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
31169 assert( db==0 || sqlite3_mutex_held(db->mutex) ); in sqlite3DbFreeNN()
31170 assert( p!=0 ); in sqlite3DbFreeNN()
31176 assert( db->pnBytesFreed==0 ); in sqlite3DbFreeNN()
31178 memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */ in sqlite3DbFreeNN()
31187 assert( db->pnBytesFreed==0 ); in sqlite3DbFreeNN()
31189 memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */ in sqlite3DbFreeNN()
31203 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); in sqlite3DbFreeNN()
31208 assert( db!=0 ); in sqlite3DbNNFreeNN()
31210 assert( p!=0 ); in sqlite3DbNNFreeNN()
31215 assert( db->pnBytesFreed==0 ); in sqlite3DbNNFreeNN()
31217 memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */ in sqlite3DbNNFreeNN()
31226 assert( db->pnBytesFreed==0 ); in sqlite3DbNNFreeNN()
31228 memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */ in sqlite3DbNNFreeNN()
31245 assert( db==0 || sqlite3_mutex_held(db->mutex) ); in sqlite3DbFree()
31257 if( pOld==0 ){ in sqlite3Realloc()
31260 if( nBytes==0 ){ in sqlite3Realloc()
31262 return 0; in sqlite3Realloc()
31264 if( nBytes>=0x7fffff00 ){ in sqlite3Realloc()
31265 /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */ in sqlite3Realloc()
31266 return 0; in sqlite3Realloc()
31280 if( nDiff>0 && (nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)) >= in sqlite3Realloc()
31283 if( mem0.hardLimit>0 && nUsed >= mem0.hardLimit - nDiff ){ in sqlite3Realloc()
31286 return 0; in sqlite3Realloc()
31291 if( pNew==0 && mem0.alarmThreshold>0 ){ in sqlite3Realloc()
31314 if( sqlite3_initialize() ) return 0; in sqlite3_realloc()
31316 if( n<0 ) n = 0; /* IMP: R-26507-47431 */ in sqlite3_realloc()
31321 if( sqlite3_initialize() ) return 0; in sqlite3_realloc64()
31333 memset(p, 0, (size_t)n); in sqlite3MallocZero()
31344 testcase( db==0 ); in sqlite3DbMallocZero()
31346 if( p ) memset(p, 0, (size_t)n); in sqlite3DbMallocZero()
31356 assert( db!=0 ); in dbMallocRawFinish()
31360 (db->lookaside.bDisable==0) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP); in dbMallocRawFinish()
31369 ** If db!=0 and db->mallocFailed is true (indicating a prior malloc
31370 ** failure on the same database connection) then always return 0.
31396 assert( db!=0 ); in sqlite3DbMallocRawNN()
31398 assert( db->pnBytesFreed==0 ); in sqlite3DbMallocRawNN()
31403 return 0; in sqlite3DbMallocRawNN()
31409 if( (pBuf = db->lookaside.pSmallFree)!=0 ){ in sqlite3DbMallocRawNN()
31411 db->lookaside.anStat[0]++; in sqlite3DbMallocRawNN()
31413 }else if( (pBuf = db->lookaside.pSmallInit)!=0 ){ in sqlite3DbMallocRawNN()
31415 db->lookaside.anStat[0]++; in sqlite3DbMallocRawNN()
31420 if( (pBuf = db->lookaside.pFree)!=0 ){ in sqlite3DbMallocRawNN()
31422 db->lookaside.anStat[0]++; in sqlite3DbMallocRawNN()
31424 }else if( (pBuf = db->lookaside.pInit)!=0 ){ in sqlite3DbMallocRawNN()
31426 db->lookaside.anStat[0]++; in sqlite3DbMallocRawNN()
31432 assert( db!=0 ); in sqlite3DbMallocRawNN()
31434 assert( db->pnBytesFreed==0 ); in sqlite3DbMallocRawNN()
31436 return 0; in sqlite3DbMallocRawNN()
31450 assert( db!=0 ); in sqlite3DbRealloc()
31451 if( p==0 ) return sqlite3DbMallocRawNN(db, n); in sqlite3DbRealloc()
31466 void *pNew = 0; in dbReallocFinish()
31467 assert( db!=0 ); in dbReallocFinish()
31468 assert( p!=0 ); in dbReallocFinish()
31469 if( db->mallocFailed==0 ){ in dbReallocFinish()
31485 (db->lookaside.bDisable==0 ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP)); in dbReallocFinish()
31514 if( z==0 ){ in sqlite3DbStrDup()
31515 return 0; in sqlite3DbStrDup()
31526 assert( db!=0 ); in sqlite3DbStrNDup()
31527 assert( z!=0 || n==0 ); in sqlite3DbStrNDup()
31528 assert( (n&0x7fffffff)==n ); in sqlite3DbStrNDup()
31529 zNew = z ? sqlite3DbMallocRawNN(db, n+1) : 0; in sqlite3DbStrNDup()
31532 zNew[n] = 0; in sqlite3DbStrNDup()
31547 for(n=0; sqlite3Isspace(zStart[n]); n++){ assert( &zStart[n]<zEnd ); } in sqlite3DbSpanDup()
31549 while( sqlite3Isspace(zStart[0]) ) zStart++; in sqlite3DbSpanDup()
31578 if( db->mallocFailed==0 && db->bBenignMalloc==0 ){ in sqlite3OomFault()
31580 if( db->nVdbeExec>0 ){ in sqlite3OomFault()
31594 return 0; in sqlite3OomFault()
31605 if( db->mallocFailed && db->nVdbeExec==0 ){ in sqlite3OomClear()
31606 db->mallocFailed = 0; in sqlite3OomClear()
31607 AtomicStore(&db->u1.isInterrupted, 0); in sqlite3OomClear()
31608 assert( db->lookaside.bDisable>0 ); in sqlite3OomClear()
31642 assert( db!=0 ); in sqlite3ApiExit()
31647 return 0; in sqlite3ApiExit()
31669 #define etRADIX 0 /* non-decimal integer types. %x %o */
31724 { 'd', 10, 1, etDECIMAL, 0, 0 },
31725 { 's', 0, 4, etSTRING, 0, 0 },
31726 { 'g', 0, 1, etGENERIC, 30, 0 },
31727 { 'z', 0, 4, etDYNSTRING, 0, 0 },
31728 { 'q', 0, 4, etESCAPE_q, 0, 0 },
31729 { 'Q', 0, 4, etESCAPE_Q, 0, 0 },
31730 { 'w', 0, 4, etESCAPE_w, 0, 0 },
31731 { 'c', 0, 0, etCHARX, 0, 0 },
31732 { 'o', 8, 0, etRADIX, 0, 2 },
31733 { 'u', 10, 0, etDECIMAL, 0, 0 },
31734 { 'x', 16, 0, etRADIX, 16, 1 },
31735 { 'X', 16, 0, etRADIX, 0, 4 },
31737 { 'f', 0, 1, etFLOAT, 0, 0 },
31738 { 'e', 0, 1, etEXP, 30, 0 },
31739 { 'E', 0, 1, etEXP, 14, 0 },
31740 { 'G', 0, 1, etGENERIC, 14, 0 },
31742 { 'i', 10, 1, etDECIMAL, 0, 0 },
31743 { 'n', 0, 0, etSIZE, 0, 0 },
31744 { '%', 0, 0, etPERCENT, 0, 0 },
31745 { 'p', 16, 0, etPOINTER, 0, 1 },
31748 { 'T', 0, 0, etTOKEN, 0, 0 },
31749 { 'S', 0, 0, etSRCITEM, 0, 0 },
31750 { 'r', 10, 1, etORDINAL, 0, 0 },
31773 if( p->nArg<=p->nUsed ) return 0; in getIntArg()
31781 if( p->nArg<=p->nUsed ) return 0; in getTextArg()
31796 if( pAccum->accError ) return 0; in printfTempBuf()
31799 return 0; in printfTempBuf()
31802 if( z==0 ){ in printfTempBuf()
31839 etByte flag_prefix; /* '+' or ' ' or 0 for prefix */ in sqlite3_str_vappendf()
31843 etByte flag_long; /* 1 for the "l" flag, 2 for "ll", 0 by default */ in sqlite3_str_vappendf()
31848 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ in sqlite3_str_vappendf()
31854 char *zExtra = 0; /* Malloced memory used by some conversion */ in sqlite3_str_vappendf()
31859 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ in sqlite3_str_vappendf()
31865 assert( pAccum->nChar>0 || (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 ); in sqlite3_str_vappendf()
31867 bufpt = 0; in sqlite3_str_vappendf()
31868 if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){ in sqlite3_str_vappendf()
31872 bArgList = 0; in sqlite3_str_vappendf()
31874 for(; (c=(*fmt))!=0; ++fmt){ in sqlite3_str_vappendf()
31883 if( *fmt==0 ) break; in sqlite3_str_vappendf()
31885 if( (c=(*++fmt))==0 ){ in sqlite3_str_vappendf()
31891 flag_alternateform = flag_altform2 = flag_zeropad = 0; in sqlite3_str_vappendf()
31892 done = 0; in sqlite3_str_vappendf()
31893 width = 0; in sqlite3_str_vappendf()
31894 flag_long = 0; in sqlite3_str_vappendf()
31903 case '0': flag_zeropad = 1; break; in sqlite3_str_vappendf()
31918 unsigned wx = c - '0'; in sqlite3_str_vappendf()
31919 while( (c = *++fmt)>='0' && c<='9' ){ in sqlite3_str_vappendf()
31920 wx = wx*10 + c - '0'; in sqlite3_str_vappendf()
31922 testcase( wx>0x7fffffff ); in sqlite3_str_vappendf()
31923 width = wx & 0x7fffffff; in sqlite3_str_vappendf()
31942 if( width<0 ){ in sqlite3_str_vappendf()
31944 width = width >= -2147483647 ? -width : 0; in sqlite3_str_vappendf()
31965 if( precision<0 ){ in sqlite3_str_vappendf()
31970 unsigned px = 0; in sqlite3_str_vappendf()
31971 while( c>='0' && c<='9' ){ in sqlite3_str_vappendf()
31972 px = px*10 + c - '0'; in sqlite3_str_vappendf()
31975 testcase( px>0x7fffffff ); in sqlite3_str_vappendf()
31976 precision = px & 0x7fffffff; in sqlite3_str_vappendf()
31991 }while( !done && (c=(*++fmt))!=0 ); in sqlite3_str_vappendf()
31994 infop = &fmtinfo[0]; in sqlite3_str_vappendf()
31996 for(idx=0; idx<ArraySize(fmtinfo); idx++){ in sqlite3_str_vappendf()
32012 ** flag_zeropad TRUE if the width began with 0. in sqlite3_str_vappendf()
32021 assert( width>=0 ); in sqlite3_str_vappendf()
32026 sizeof(char*)==sizeof(long int) ? 1 : 0; in sqlite3_str_vappendf()
32030 cThousand = 0; in sqlite3_str_vappendf()
32046 if( v<0 ){ in sqlite3_str_vappendf()
32068 prefix = 0; in sqlite3_str_vappendf()
32070 if( longvalue==0 ) flag_alternateform = 0; in sqlite3_str_vappendf()
32071 if( flag_zeropad && precision<width-(prefix!=0) ){ in sqlite3_str_vappendf()
32072 precision = width-(prefix!=0); in sqlite3_str_vappendf()
32082 if( zOut==0 ) return; in sqlite3_str_vappendf()
32090 x = 0; in sqlite3_str_vappendf()
32101 }while( longvalue>0 ); in sqlite3_str_vappendf()
32105 *(--bufpt) = '0'; /* Zero pad */ in sqlite3_str_vappendf()
32112 for(idx=0; nn>0; idx++){ in sqlite3_str_vappendf()
32115 if( ix==0 ){ in sqlite3_str_vappendf()
32123 if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */ in sqlite3_str_vappendf()
32127 for(; (x=(*pre))!=0; pre++) *(--bufpt) = x; in sqlite3_str_vappendf()
32143 if( precision<0 ) precision = 6; /* Set default precision */ in sqlite3_str_vappendf()
32152 if( precision==0 ) precision = 1; in sqlite3_str_vappendf()
32164 s.z[0] = '9'; in sqlite3_str_vappendf()
32173 buf[0] = flag_prefix; in sqlite3_str_vappendf()
32194 assert( precision>0 ); in sqlite3_str_vappendf()
32207 e2 = 0; in sqlite3_str_vappendf()
32214 szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15; in sqlite3_str_vappendf()
32215 if( cThousand && e2>0 ) szBufNeeded += (e2+2)/3; in sqlite3_str_vappendf()
32218 if( bufpt==0 ) return; in sqlite3_str_vappendf()
32222 flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2; in sqlite3_str_vappendf()
32228 j = 0; in sqlite3_str_vappendf()
32229 if( e2<0 ){ in sqlite3_str_vappendf()
32230 *(bufpt++) = '0'; in sqlite3_str_vappendf()
32232 for(; e2>=0; e2--){ in sqlite3_str_vappendf()
32233 *(bufpt++) = j<s.n ? s.z[j++] : '0'; in sqlite3_str_vappendf()
32234 if( cThousand && (e2%3)==0 && e2>1 ) *(bufpt++) = ','; in sqlite3_str_vappendf()
32241 /* "0" digits after the decimal point but before the first in sqlite3_str_vappendf()
32243 for(e2++; e2<0 && precision>0; precision--, e2++){ in sqlite3_str_vappendf()
32244 *(bufpt++) = '0'; in sqlite3_str_vappendf()
32247 while( (precision--)>0 ){ in sqlite3_str_vappendf()
32248 *(bufpt++) = j<s.n ? s.z[j++] : '0'; in sqlite3_str_vappendf()
32252 while( bufpt[-1]=='0' ) *(--bufpt) = 0; in sqlite3_str_vappendf()
32256 *(bufpt++) = '0'; in sqlite3_str_vappendf()
32258 *(--bufpt) = 0; in sqlite3_str_vappendf()
32266 if( exp<0 ){ in sqlite3_str_vappendf()
32272 *(bufpt++) = (char)((exp/100)+'0'); /* 100's digit */ in sqlite3_str_vappendf()
32275 *(bufpt++) = (char)(exp/10+'0'); /* 10's digit */ in sqlite3_str_vappendf()
32276 *(bufpt++) = (char)(exp%10+'0'); /* 1's digit */ in sqlite3_str_vappendf()
32278 *bufpt = 0; in sqlite3_str_vappendf()
32294 i = prefix!=0; in sqlite3_str_vappendf()
32295 while( nPad-- ) bufpt[i++] = '0'; in sqlite3_str_vappendf()
32304 length = width = 0; in sqlite3_str_vappendf()
32307 buf[0] = '%'; in sqlite3_str_vappendf()
32316 buf[0] = c = *(bufpt++); in sqlite3_str_vappendf()
32317 if( (c&0xc0)==0xc0 ){ in sqlite3_str_vappendf()
32318 while( length<4 && (bufpt[0]&0xc0)==0x80 ){ in sqlite3_str_vappendf()
32323 buf[0] = 0; in sqlite3_str_vappendf()
32334 width = 0; in sqlite3_str_vappendf()
32363 if( bufpt==0 ){ in sqlite3_str_vappendf()
32366 if( pAccum->nChar==0 in sqlite3_str_vappendf()
32368 && width==0 in sqlite3_str_vappendf()
32369 && precision<0 in sqlite3_str_vappendf()
32370 && pAccum->accError==0 in sqlite3_str_vappendf()
32375 assert( (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 ); in sqlite3_str_vappendf()
32378 pAccum->nChar = 0x7fffffff & (int)strlen(bufpt); in sqlite3_str_vappendf()
32380 length = 0; in sqlite3_str_vappendf()
32385 if( precision>=0 ){ in sqlite3_str_vappendf()
32390 while( precision-- > 0 && z[0] ){ in sqlite3_str_vappendf()
32395 for(length=0; length<precision && bufpt[length]; length++){} in sqlite3_str_vappendf()
32398 length = 0x7fffffff & (int)strlen(bufpt); in sqlite3_str_vappendf()
32401 if( flag_altform2 && width>0 ){ in sqlite3_str_vappendf()
32404 while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++; in sqlite3_str_vappendf()
32411 int needQuote = 0; in sqlite3_str_vappendf()
32421 if( escarg==0 ){ in sqlite3_str_vappendf()
32428 flag_alternateform = 0; in sqlite3_str_vappendf()
32438 for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){ in sqlite3_str_vappendf()
32440 if( flag_altform2 && (ch&0xc0)==0xc0 ){ in sqlite3_str_vappendf()
32441 while( (escarg[i+1]&0xc0)==0x80 ){ i++; } in sqlite3_str_vappendf()
32449 u32 nBack = 0; in sqlite3_str_vappendf()
32450 u32 nCtrl = 0; in sqlite3_str_vappendf()
32451 for(k=0; k<i; k++){ in sqlite3_str_vappendf()
32454 }else if( ((u8*)escarg)[k]<=0x1f ){ in sqlite3_str_vappendf()
32465 flag_alternateform = 0; in sqlite3_str_vappendf()
32471 if( bufpt==0 ) return; in sqlite3_str_vappendf()
32475 j = 0; in sqlite3_str_vappendf()
32486 for(i=0; i<k; i++){ in sqlite3_str_vappendf()
32492 }else if( ((unsigned char)ch)<=0x1f ){ in sqlite3_str_vappendf()
32495 bufpt[j++] = '0'; in sqlite3_str_vappendf()
32496 bufpt[j++] = '0'; in sqlite3_str_vappendf()
32497 bufpt[j++] = ch>=0x10 ? '1' : '0'; in sqlite3_str_vappendf()
32498 bufpt[j++] = "0123456789abcdef"[ch&0xf]; in sqlite3_str_vappendf()
32502 for(i=0; i<k; i++){ in sqlite3_str_vappendf()
32511 bufpt[j] = 0; in sqlite3_str_vappendf()
32516 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; in sqlite3_str_vappendf()
32527 assert( bArgList==0 ); in sqlite3_str_vappendf()
32533 length = width = 0; in sqlite3_str_vappendf()
32538 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; in sqlite3_str_vappendf()
32540 assert( bArgList==0 ); in sqlite3_str_vappendf()
32544 if( pItem->fg.fixedSchema==0 in sqlite3_str_vappendf()
32545 && pItem->fg.isSubquery==0 in sqlite3_str_vappendf()
32546 && pItem->u4.zDatabase!=0 in sqlite3_str_vappendf()
32556 assert( pSel!=0 ); in sqlite3_str_vappendf()
32567 length = width = 0; in sqlite3_str_vappendf()
32584 if( width>0 ){ in sqlite3_str_vappendf()
32594 zExtra = 0; in sqlite3_str_vappendf()
32610 assert( z!=0 ); in sqlite3RecordErrorByteOffset()
32611 if( NEVER(db==0) ) return; in sqlite3RecordErrorByteOffset()
32614 if( NEVER(pParse==0) ) return; in sqlite3RecordErrorByteOffset()
32616 if( NEVER(zText==0) ) return; in sqlite3RecordErrorByteOffset()
32629 && (ExprHasProperty(pExpr,EP_OuterON|EP_InnerON) || pExpr->w.iOfst<=0) in sqlite3RecordErrorOffsetOfExpr()
32633 if( pExpr==0 ) return; in sqlite3RecordErrorOffsetOfExpr()
32651 return 0; in sqlite3StrAccumEnlarge()
32653 if( p->mxAlloc==0 ){ in sqlite3StrAccumEnlarge()
32657 char *zOld = isMalloced(p) ? p->zText : 0; in sqlite3StrAccumEnlarge()
32667 return 0; in sqlite3StrAccumEnlarge()
32677 assert( p->zText!=0 || p->nChar==0 ); in sqlite3StrAccumEnlarge()
32678 if( !isMalloced(p) && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); in sqlite3StrAccumEnlarge()
32685 return 0; in sqlite3StrAccumEnlarge()
32688 assert( N>=0 && N<=0x7fffffff ); in sqlite3StrAccumEnlarge()
32696 testcase( p->nChar + (i64)N > 0x7fffffff ); in sqlite3_str_appendchar()
32697 if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){ in sqlite3_str_appendchar()
32700 while( (N--)>0 ) p->zText[p->nChar++] = c; in sqlite3_str_appendchar()
32713 if( N>0 ){ in enlargeAndAppend()
32724 assert( z!=0 || N==0 ); in sqlite3_str_append()
32725 assert( p->zText!=0 || p->nChar==0 || p->accError ); in sqlite3_str_append()
32726 assert( N>=0 ); in sqlite3_str_append()
32727 assert( p->accError==0 || p->nAlloc==0 || p->mxAlloc==0 ); in sqlite3_str_append()
32752 assert( p->mxAlloc>0 && !isMalloced(p) ); in strAccumFinishRealloc()
32765 p->zText[p->nChar] = 0; in sqlite3StrAccumFinish()
32766 if( p->mxAlloc>0 && !isMalloced(p) ){ in sqlite3StrAccumFinish()
32784 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC); in sqlite3ResultStrAccum()
32796 0, 0, 0, 0, 0, SQLITE_NOMEM, 0
32803 if( p!=0 && p!=&sqlite3OomStr ){ in sqlite3_str_finish()
32807 z = 0; in sqlite3_str_finish()
32819 return p ? p->nChar : 0; in sqlite3_str_length()
32824 if( p==0 || p->nChar==0 ) return 0; in sqlite3_str_value()
32825 p->zText[p->nChar] = 0; in sqlite3_str_value()
32837 p->nAlloc = 0; in sqlite3_str_reset()
32838 p->nChar = 0; in sqlite3_str_reset()
32839 p->zText = 0; in sqlite3_str_reset()
32853 ** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
32861 p->nChar = 0; in sqlite3StrAccumInit()
32862 p->accError = 0; in sqlite3StrAccumInit()
32863 p->printfFlags = 0; in sqlite3StrAccumInit()
32870 sqlite3StrAccumInit(p, 0, 0, 0, in sqlite3_str_new()
32886 assert( db!=0 ); in sqlite3VMPrintf()
32921 if( zFormat==0 ){ in sqlite3_vmprintf()
32923 return 0; in sqlite3_vmprintf()
32927 if( sqlite3_initialize() ) return 0; in sqlite3_vmprintf()
32929 sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); in sqlite3_vmprintf()
32943 if( sqlite3_initialize() ) return 0; in sqlite3_mprintf()
32966 if( n<=0 ) return zBuf; in sqlite3_vsnprintf()
32968 if( zBuf==0 || zFormat==0 ) { in sqlite3_vsnprintf()
32970 if( zBuf ) zBuf[0] = 0; in sqlite3_vsnprintf()
32974 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); in sqlite3_vsnprintf()
32976 zBuf[acc.nChar] = 0; in sqlite3_vsnprintf()
32982 if( n<=0 ) return zBuf; in sqlite3_snprintf()
32984 if( zBuf==0 || zFormat==0 ) { in sqlite3_snprintf()
32986 if( zBuf ) zBuf[0] = 0; in sqlite3_snprintf()
32990 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); in sqlite3_snprintf()
32994 zBuf[acc.nChar] = 0; in sqlite3_snprintf()
33025 sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0); in renderLogMsg()
33053 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); in sqlite3DebugPrintf()
33094 assert( p!=0 ); in sqlite3RCStrRef()
33106 assert( p!=0 ); in sqlite3RCStrUnref()
33108 assert( p->nRCRef>0 ); in sqlite3RCStrUnref()
33123 ** This routine returns 0 on an OOM.
33127 if( p==0 ) return 0; in sqlite3RCStrNew()
33139 assert( p!=0 ); in sqlite3RCStrResize()
33143 if( pNew==0 ){ in sqlite3RCStrResize()
33145 return 0; in sqlite3RCStrResize()
33181 if( p==0 ){ in sqlite3TreeViewPush()
33183 if( p==0 ) return; in sqlite3TreeViewPush()
33184 memset(p, 0, sizeof(*p)); in sqlite3TreeViewPush()
33188 assert( moreToFollow==0 || moreToFollow==1 ); in sqlite3TreeViewPush()
33197 if( p==0 ) return; in sqlite3TreeViewPop()
33199 if( p->iLevel<0 ){ in sqlite3TreeViewPop()
33201 *pp = 0; in sqlite3TreeViewPop()
33214 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); in sqlite3TreeViewLine()
33216 for(i=0; i<p->iLevel && i<(int)sizeof(p->bLine)-1; i++){ in sqlite3TreeViewLine()
33221 if( zFormat!=0 ){ in sqlite3TreeViewLine()
33225 assert( acc.nChar>0 || acc.accError ); in sqlite3TreeViewLine()
33253 for(i=0; i<nCol; i++){ in sqlite3TreeViewColumnList()
33257 sqlite3TreeViewLine(pView, 0); in sqlite3TreeViewColumnList()
33293 if( pWith==0 ) return; in sqlite3TreeViewWith()
33294 if( pWith->nCte==0 ) return; in sqlite3TreeViewWith()
33296 sqlite3TreeViewLine(pView, "WITH (0x%p, pOuter=0x%p)",pWith,pWith->pOuter); in sqlite3TreeViewWith()
33298 sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith); in sqlite3TreeViewWith()
33300 if( pWith->nCte>0 ){ in sqlite3TreeViewWith()
33302 for(i=0; i<pWith->nCte; i++){ in sqlite3TreeViewWith()
33306 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); in sqlite3TreeViewWith()
33308 if( pCte->pCols && pCte->pCols->nExpr>0 ){ in sqlite3TreeViewWith()
33311 for(j=0; j<pCte->pCols->nExpr; j++){ in sqlite3TreeViewWith()
33322 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse, in sqlite3TreeViewWith()
33327 sqlite3TreeViewSelect(pView, pCte->pSelect, 0); in sqlite3TreeViewWith()
33339 if( pSrc==0 ) return; in sqlite3TreeViewSrcList()
33340 for(i=0; i<pSrc->nSrc; i++){ in sqlite3TreeViewSrcList()
33343 int n = 0; in sqlite3TreeViewSrcList()
33345 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); in sqlite3TreeViewSrcList()
33375 if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){ in sqlite3TreeViewSrcList()
33390 n = 0; in sqlite3TreeViewSrcList()
33395 sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING"); in sqlite3TreeViewSrcList()
33404 sqlite3TreeViewSelect(pView, pItem->u4.pSubq->pSelect, 0); in sqlite3TreeViewSrcList()
33407 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); in sqlite3TreeViewSrcList()
33417 int n = 0; in sqlite3TreeViewSelect()
33418 int cnt = 0; in sqlite3TreeViewSelect()
33419 if( p==0 ){ in sqlite3TreeViewSelect()
33434 "SELECT%s%s (%u/%p) selFlags=0x%x nSelectRow=%d", in sqlite3TreeViewSelect()
33445 n = 0; in sqlite3TreeViewSelect()
33458 sqlite3TreeViewExprList(pView, p->pEList, n>0, "result-set"); in sqlite3TreeViewSelect()
33464 sqlite3TreeViewPush(&pView, (n--)>0); in sqlite3TreeViewSelect()
33467 sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0); in sqlite3TreeViewSelect()
33473 sqlite3TreeViewPush(&pView, (n--)>0); in sqlite3TreeViewSelect()
33479 sqlite3TreeViewItem(pView, "WHERE", (n--)>0); in sqlite3TreeViewSelect()
33480 sqlite3TreeViewExpr(pView, p->pWhere, 0); in sqlite3TreeViewSelect()
33484 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY"); in sqlite3TreeViewSelect()
33487 sqlite3TreeViewItem(pView, "HAVING", (n--)>0); in sqlite3TreeViewSelect()
33488 sqlite3TreeViewExpr(pView, p->pHaving, 0); in sqlite3TreeViewSelect()
33494 sqlite3TreeViewItem(pView, "WINDOW", (n--)>0); in sqlite3TreeViewSelect()
33496 sqlite3TreeViewWindow(pView, pX, pX->pNextWin!=0); in sqlite3TreeViewSelect()
33502 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY"); in sqlite3TreeViewSelect()
33505 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0); in sqlite3TreeViewSelect()
33506 sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0); in sqlite3TreeViewSelect()
33508 sqlite3TreeViewItem(pView, "OFFSET", 0); in sqlite3TreeViewSelect()
33509 sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0); in sqlite3TreeViewSelect()
33524 }while( p!=0 ); in sqlite3TreeViewSelect()
33551 sqlite3TreeViewExpr(pView, pExpr, 0); in sqlite3TreeViewBound()
33557 sqlite3TreeViewExpr(pView, pExpr, 0); in sqlite3TreeViewBound()
33570 int nElement = 0; in sqlite3TreeViewWindow()
33571 if( pWin==0 ) return; in sqlite3TreeViewWindow()
33574 sqlite3TreeViewExpr(pView, pWin->pFilter, 0); in sqlite3TreeViewWindow()
33586 if( pWin->eFrmType!=0 && pWin->eFrmType!=TK_FILTER ) nElement++; in sqlite3TreeViewWindow()
33589 sqlite3TreeViewPush(&pView, (--nElement)>0); in sqlite3TreeViewWindow()
33594 sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY"); in sqlite3TreeViewWindow()
33597 sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY"); in sqlite3TreeViewWindow()
33599 if( pWin->eFrmType!=0 && pWin->eFrmType!=TK_FILTER ){ in sqlite3TreeViewWindow()
33606 sqlite3TreeViewItem(pView, zBuf, (--nElement)>0); in sqlite3TreeViewWindow()
33608 sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0); in sqlite3TreeViewWindow()
33624 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewWindow()
33637 if( pWin==0 ) return; in sqlite3TreeViewWinFunc()
33641 sqlite3TreeViewWindow(pView, pWin, 0); in sqlite3TreeViewWinFunc()
33650 const char *zBinOp = 0; /* Binary operator */ in sqlite3TreeViewExpr()
33651 const char *zUniOp = 0; /* Unary operator */ in sqlite3TreeViewExpr()
33654 if( pExpr==0 ){ in sqlite3TreeViewExpr()
33661 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); in sqlite3TreeViewExpr()
33676 if( pExpr->pAggInfo!=0 ){ in sqlite3TreeViewExpr()
33681 zFlgs[0] = 0; in sqlite3TreeViewExpr()
33690 if( pExpr->iTable<0 ){ in sqlite3TreeViewExpr()
33694 sqlite3_snprintf(sizeof(zOp2),zOp2," op2=0x%02x",pExpr->op2); in sqlite3TreeViewExpr()
33696 zOp2[0] = 0; in sqlite3TreeViewExpr()
33707 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33767 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33818 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33832 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33841 pFarg = 0; in sqlite3TreeViewExpr()
33842 pWin = 0; in sqlite3TreeViewExpr()
33847 pWin = IsWindowFunc(pExpr) ? pExpr->y.pWin : 0; in sqlite3TreeViewExpr()
33849 pWin = 0; in sqlite3TreeViewExpr()
33856 pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0, in sqlite3TreeViewExpr()
33858 }else if( pExpr->op2!=0 ){ in sqlite3TreeViewExpr()
33861 sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2); in sqlite3TreeViewExpr()
33873 sqlite3TreeViewExprList(pView, pFarg, pWin!=0 || pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33878 sqlite3TreeViewExprList(pView, pOB->x.pList, pWin!=0, "ORDERBY"); in sqlite3TreeViewExpr()
33883 sqlite3TreeViewWindow(pView, pWin, 0); in sqlite3TreeViewExpr()
33889 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, "ORDERBY"); in sqlite3TreeViewExpr()
33895 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags); in sqlite3TreeViewExpr()
33896 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); in sqlite3TreeViewExpr()
33901 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags); in sqlite3TreeViewExpr()
33902 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); in sqlite3TreeViewExpr()
33906 sqlite3_str *pStr = sqlite3_str_new(0); in sqlite3TreeViewExpr()
33908 sqlite3_str_appendf(pStr, "IN flags=0x%x", pExpr->flags); in sqlite3TreeViewExpr()
33919 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); in sqlite3TreeViewExpr()
33921 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); in sqlite3TreeViewExpr()
33935 ** Y is stored in pExpr->pList->a[0].pExpr. in sqlite3TreeViewExpr()
33943 pY = pExpr->x.pList->a[0].pExpr; in sqlite3TreeViewExpr()
33948 sqlite3TreeViewExpr(pView, pZ, 0); in sqlite3TreeViewExpr()
33955 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn in sqlite3TreeViewExpr()
33967 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); in sqlite3TreeViewExpr()
33981 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33988 sqlite3TreeViewExpr(pView, pExpr->pRight, 0); in sqlite3TreeViewExpr()
33999 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s", in sqlite3TreeViewExpr()
34003 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0); in sqlite3TreeViewExpr()
34008 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
34016 sqlite3TreeViewExpr(pView, &tmp, 0); in sqlite3TreeViewExpr()
34020 if( pExpr->iColumn<=0 ){ in sqlite3TreeViewExpr()
34036 sqlite3TreeViewExpr(pView, pExpr->pRight, 0); in sqlite3TreeViewExpr()
34039 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
34053 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; in sqlite3TreeViewBareExprList()
34054 if( pList==0 ){ in sqlite3TreeViewBareExprList()
34059 for(i=0; i<pList->nExpr; i++){ in sqlite3TreeViewBareExprList()
34066 moreToFollow = 0; in sqlite3TreeViewBareExprList()
34067 sqlite3TreeViewLine(pView, 0); in sqlite3TreeViewBareExprList()
34121 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; in sqlite3TreeViewBareIdList()
34122 if( pList==0 ){ in sqlite3TreeViewBareIdList()
34127 for(i=0; i<pList->nId; i++){ in sqlite3TreeViewBareIdList()
34130 if( zName==0 ) zName = "(null)"; in sqlite3TreeViewBareIdList()
34132 sqlite3TreeViewLine(pView, 0); in sqlite3TreeViewBareIdList()
34157 if( pUpsert==0 ) return; in sqlite3TreeViewUpsert()
34161 sqlite3TreeViewPush(&pView, pUpsert->pNextUpsert!=0 || moreToFollow); in sqlite3TreeViewUpsert()
34164 n = (pUpsert->pUpsertSet!=0) + (pUpsert->pUpsertWhere!=0); in sqlite3TreeViewUpsert()
34165 sqlite3TreeViewExprList(pView, pUpsert->pUpsertTarget, (n--)>0, "TARGET"); in sqlite3TreeViewUpsert()
34166 sqlite3TreeViewExprList(pView, pUpsert->pUpsertSet, (n--)>0, "SET"); in sqlite3TreeViewUpsert()
34168 sqlite3TreeViewItem(pView, "WHERE", (n--)>0); in sqlite3TreeViewUpsert()
34169 sqlite3TreeViewExpr(pView, pUpsert->pUpsertWhere, 0); in sqlite3TreeViewUpsert()
34191 int n = 0; in sqlite3TreeViewDelete()
34192 TreeView *pView = 0; in sqlite3TreeViewDelete()
34193 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewDelete()
34202 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewDelete()
34203 sqlite3TreeViewWith(pView, pWith, 0); in sqlite3TreeViewDelete()
34207 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewDelete()
34213 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewDelete()
34215 sqlite3TreeViewExpr(pView, pWhere, 0); in sqlite3TreeViewDelete()
34219 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); in sqlite3TreeViewDelete()
34222 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewDelete()
34224 sqlite3TreeViewExpr(pView, pLimit, 0); in sqlite3TreeViewDelete()
34228 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); in sqlite3TreeViewDelete()
34249 TreeView *pView = 0; in sqlite3TreeViewInsert()
34250 int n = 0; in sqlite3TreeViewInsert()
34259 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewInsert()
34269 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewInsert()
34270 sqlite3TreeViewWith(pView, pWith, 0); in sqlite3TreeViewInsert()
34274 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewInsert()
34280 sqlite3TreeViewIdList(pView, pColumnList, (--n)>0, "COLUMNS"); in sqlite3TreeViewInsert()
34283 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewInsert()
34285 sqlite3TreeViewSelect(pView, pSelect, 0); in sqlite3TreeViewInsert()
34289 sqlite3TreeViewExprList(pView, pExprList, (--n)>0, "VALUES"); in sqlite3TreeViewInsert()
34292 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewInsert()
34294 sqlite3TreeViewUpsert(pView, pUpsert, 0); in sqlite3TreeViewInsert()
34298 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); in sqlite3TreeViewInsert()
34320 int n = 0; in sqlite3TreeViewUpdate()
34321 TreeView *pView = 0; in sqlite3TreeViewUpdate()
34330 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewUpdate()
34341 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
34342 sqlite3TreeViewWith(pView, pWith, 0); in sqlite3TreeViewUpdate()
34346 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
34352 sqlite3TreeViewExprList(pView, pChanges, (--n)>0, "SET"); in sqlite3TreeViewUpdate()
34355 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
34357 sqlite3TreeViewExpr(pView, pWhere, 0); in sqlite3TreeViewUpdate()
34361 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); in sqlite3TreeViewUpdate()
34364 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
34366 sqlite3TreeViewExpr(pView, pLimit, 0); in sqlite3TreeViewUpdate()
34370 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
34372 sqlite3TreeViewUpsert(pView, pUpsert, 0); in sqlite3TreeViewUpdate()
34376 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); in sqlite3TreeViewUpdate()
34392 int cnt = 0; in sqlite3TreeViewTriggerStep()
34393 if( pStep==0 ) return; in sqlite3TreeViewTriggerStep()
34395 moreToFollow || (showFullList && pStep->pNext!=0)); in sqlite3TreeViewTriggerStep()
34397 if( cnt++ && pStep->pNext==0 ){ in sqlite3TreeViewTriggerStep()
34399 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewTriggerStep()
34402 }while( showFullList && (pStep = pStep->pNext)!=0 ); in sqlite3TreeViewTriggerStep()
34415 int cnt = 0; in sqlite3TreeViewTrigger()
34416 if( pTrigger==0 ) return; in sqlite3TreeViewTrigger()
34418 moreToFollow || (showFullList && pTrigger->pNext!=0)); in sqlite3TreeViewTrigger()
34420 if( cnt++ && pTrigger->pNext==0 ){ in sqlite3TreeViewTrigger()
34422 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewTrigger()
34425 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewTrigger()
34426 sqlite3TreeViewTriggerStep(pView, pTrigger->step_list, 0, 1); in sqlite3TreeViewTrigger()
34428 }while( showFullList && (pTrigger = pTrigger->pNext)!=0 ); in sqlite3TreeViewTrigger()
34448 SQLITE_PRIVATE void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); } in sqlite3ShowExpr()
34449 SQLITE_PRIVATE void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);} in sqlite3ShowExprList()
34450 SQLITE_PRIVATE void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); } in sqlite3ShowIdList()
34451 SQLITE_PRIVATE void sqlite3ShowSrcList(const SrcList *p){ sqlite3TreeViewSrcList(0,p); } in sqlite3ShowSrcList()
34452 SQLITE_PRIVATE void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); } in sqlite3ShowSelect()
34453 SQLITE_PRIVATE void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); } in sqlite3ShowWith()
34454 SQLITE_PRIVATE void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); } in sqlite3ShowUpsert()
34457 sqlite3TreeViewTriggerStep(0,p,0,0); in sqlite3ShowTriggerStep()
34460 sqlite3TreeViewTriggerStep(0,p,0,1); in sqlite3ShowTriggerStepList()
34462 SQLITE_PRIVATE void sqlite3ShowTrigger(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,0); } in sqlite3ShowTrigger()
34463 SQLITE_PRIVATE void sqlite3ShowTriggerList(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,1);} in sqlite3ShowTriggerList()
34466 SQLITE_PRIVATE void sqlite3ShowWindow(const Window *p){ sqlite3TreeViewWindow(0,p,0); } in sqlite3ShowWindow()
34467 SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window *p){ sqlite3TreeViewWinFunc(0,p,0); } in sqlite3ShowWinFunc()
34516 for(i=0; i<10; i++){ in chacha_block()
34517 QR(x[0], x[4], x[ 8], x[12]); in chacha_block()
34521 QR(x[0], x[5], x[10], x[15]); in chacha_block()
34526 for(i=0; i<16; i++) out[i] = x[i]+in[i]; in chacha_block()
34543 # define wsdPrng p[0] in sqlite3_randomness()
34561 if( N<=0 || pBuf==0 ){ in sqlite3_randomness()
34562 wsdPrng.s[0] = 0; in sqlite3_randomness()
34570 if( wsdPrng.s[0]==0 ){ in sqlite3_randomness()
34571 sqlite3_vfs *pVfs = sqlite3_vfs_find(0); in sqlite3_randomness()
34573 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 in sqlite3_randomness()
34575 memcpy(&wsdPrng.s[0], chacha20_init, 16); in sqlite3_randomness()
34576 if( NEVER(pVfs==0) ){ in sqlite3_randomness()
34577 memset(&wsdPrng.s[4], 0, 44); in sqlite3_randomness()
34582 wsdPrng.s[12] = 0; in sqlite3_randomness()
34583 wsdPrng.n = 0; in sqlite3_randomness()
34586 assert( N>0 ); in sqlite3_randomness()
34593 if( wsdPrng.n>0 ){ in sqlite3_randomness()
34666 #if SQLITE_MAX_WORKER_THREADS>0
34669 #if SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) && SQLITE_THREADSAFE>0
34692 assert( ppThread!=0 ); in sqlite3ThreadCreate()
34693 assert( xTask!=0 ); in sqlite3ThreadCreate()
34695 assert( sqlite3GlobalConfig.bCoreMutex!=0 ); in sqlite3ThreadCreate()
34697 *ppThread = 0; in sqlite3ThreadCreate()
34699 if( p==0 ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadCreate()
34700 memset(p, 0, sizeof(*p)); in sqlite3ThreadCreate()
34710 rc = pthread_create(&p->tid, 0, xTask, pIn); in sqlite3ThreadCreate()
34724 assert( ppOut!=0 ); in sqlite3ThreadJoin()
34725 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadJoin()
34761 assert( p!=0 ); in sqlite3ThreadProc()
34762 #if 0 in sqlite3ThreadProc()
34771 assert( p->xTask!=0 ); in sqlite3ThreadProc()
34774 _endthreadex(0); in sqlite3ThreadProc()
34775 return 0; /* NOT REACHED */ in sqlite3ThreadProc()
34786 assert( ppThread!=0 ); in sqlite3ThreadCreate()
34787 assert( xTask!=0 ); in sqlite3ThreadCreate()
34788 *ppThread = 0; in sqlite3ThreadCreate()
34790 if( p==0 ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadCreate()
34796 if( sqlite3GlobalConfig.bCoreMutex==0 || sqlite3FaultSim(200) ){ in sqlite3ThreadCreate()
34797 memset(p, 0, sizeof(*p)); in sqlite3ThreadCreate()
34801 p->tid = (void*)_beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id); in sqlite3ThreadCreate()
34802 if( p->tid==0 ){ in sqlite3ThreadCreate()
34803 memset(p, 0, sizeof(*p)); in sqlite3ThreadCreate()
34806 if( p->xTask==0 ){ in sqlite3ThreadCreate()
34821 assert( ppOut!=0 ); in sqlite3ThreadJoin()
34822 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadJoin()
34823 if( p->xTask==0 ){ in sqlite3ThreadJoin()
34826 assert( p->tid==0 ); in sqlite3ThreadJoin()
34828 assert( p->id!=0 && p->id!=GetCurrentThreadId() ); in sqlite3ThreadJoin()
34866 assert( ppThread!=0 ); in sqlite3ThreadCreate()
34867 assert( xTask!=0 ); in sqlite3ThreadCreate()
34868 *ppThread = 0; in sqlite3ThreadCreate()
34870 if( p==0 ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadCreate()
34875 p->xTask = 0; in sqlite3ThreadCreate()
34885 assert( ppOut!=0 ); in sqlite3ThreadJoin()
34886 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadJoin()
34907 #endif /* SQLITE_MAX_WORKER_THREADS>0 */
34927 ** Byte-0 Byte-1 Byte-2 Byte-3 Value
34928 ** 0xxxxxxx 00000000 00000000 0xxxxxxx
34936 ** Word-0 Word-1 Value
34942 ** 0xff 0xfe little-endian utf-16 follows
34943 ** 0xfe 0xff big-endian utf-16 follows
34950 #if !defined(SQLITE_AMALGAMATION) && SQLITE_BYTEORDER==0
34956 #endif /* SQLITE_AMALGAMATION && SQLITE_BYTEORDER==0 */
34963 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
34964 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
34965 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
34966 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
34967 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
34968 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
34969 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
34970 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
34975 if( c<0x00080 ){ \
34976 *zOut++ = (u8)(c&0xFF); \
34978 else if( c<0x00800 ){ \
34979 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \
34980 *zOut++ = 0x80 + (u8)(c & 0x3F); \
34982 else if( c<0x10000 ){ \
34983 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \
34984 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
34985 *zOut++ = 0x80 + (u8)(c & 0x3F); \
34987 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07); \
34988 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \
34989 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
34990 *zOut++ = 0x80 + (u8)(c & 0x3F); \
34995 if( c<=0xFFFF ){ \
34996 *zOut++ = (u8)(c&0x00FF); \
34997 *zOut++ = (u8)((c>>8)&0x00FF); \
34999 *zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
35000 *zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03)); \
35001 *zOut++ = (u8)(c&0x00FF); \
35002 *zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); \
35007 if( c<=0xFFFF ){ \
35008 *zOut++ = (u8)((c>>8)&0x00FF); \
35009 *zOut++ = (u8)(c&0x00FF); \
35011 *zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03)); \
35012 *zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
35013 *zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); \
35014 *zOut++ = (u8)(c&0x00FF); \
35025 if( v<0x00080 ){ in sqlite3AppendOneUtf8Character()
35026 zOut[0] = (u8)(v & 0xff); in sqlite3AppendOneUtf8Character()
35029 if( v<0x00800 ){ in sqlite3AppendOneUtf8Character()
35030 zOut[0] = 0xc0 + (u8)((v>>6) & 0x1f); in sqlite3AppendOneUtf8Character()
35031 zOut[1] = 0x80 + (u8)(v & 0x3f); in sqlite3AppendOneUtf8Character()
35034 if( v<0x10000 ){ in sqlite3AppendOneUtf8Character()
35035 zOut[0] = 0xe0 + (u8)((v>>12) & 0x0f); in sqlite3AppendOneUtf8Character()
35036 zOut[1] = 0x80 + (u8)((v>>6) & 0x3f); in sqlite3AppendOneUtf8Character()
35037 zOut[2] = 0x80 + (u8)(v & 0x3f); in sqlite3AppendOneUtf8Character()
35040 zOut[0] = 0xf0 + (u8)((v>>18) & 0x07); in sqlite3AppendOneUtf8Character()
35041 zOut[1] = 0x80 + (u8)((v>>12) & 0x3f); in sqlite3AppendOneUtf8Character()
35042 zOut[2] = 0x80 + (u8)((v>>6) & 0x3f); in sqlite3AppendOneUtf8Character()
35043 zOut[3] = 0x80 + (u8)(v & 0x3f); in sqlite3AppendOneUtf8Character()
35051 ** is a 0x00.
35057 ** * This routine never allows a 7-bit character (0x00 through 0x7f) to
35059 ** attempts to encode a value between 0x00 and 0x7f is rendered as 0xfffd.
35063 ** 0xd800 and 0xe000 then it is rendered as 0xfffd.
35065 ** * Bytes in the range of 0x80 through 0xbf which occur as the first
35071 ** for unicode values 0x80 and greater. It does not change over-length
35072 ** encodings to 0xfffd as some systems recommend.
35076 if( c>=0xc0 ){ \
35077 c = sqlite3Utf8Trans1[c-0xc0]; \
35078 while( zIn<zTerm && (*zIn & 0xc0)==0x80 ){ \
35079 c = (c<<6) + (0x3f & *(zIn++)); \
35081 if( c<0x80 \
35082 || (c&0xFFFFF800)==0xD800 \
35083 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
35094 if( c>=0xc0 ){ in sqlite3Utf8Read()
35095 c = sqlite3Utf8Trans1[c-0xc0]; in sqlite3Utf8Read()
35096 while( (*(*pz) & 0xc0)==0x80 ){ in sqlite3Utf8Read()
35097 c = (c<<6) + (0x3f & *((*pz)++)); in sqlite3Utf8Read()
35099 if( c<0x80 in sqlite3Utf8Read()
35100 || (c&0xFFFFF800)==0xD800 in sqlite3Utf8Read()
35101 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } in sqlite3Utf8Read()
35125 assert( n>0 ); in sqlite3Utf8ReadLimited()
35126 c = z[0]; in sqlite3Utf8ReadLimited()
35127 if( c>=0xc0 ){ in sqlite3Utf8ReadLimited()
35128 c = sqlite3Utf8Trans1[c-0xc0]; in sqlite3Utf8ReadLimited()
35130 while( i<n && (z[i] & 0xc0)==0x80 ){ in sqlite3Utf8ReadLimited()
35131 c = (c<<6) + (0x3f & z[i]); in sqlite3Utf8ReadLimited()
35160 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); in sqlite3VdbeMemTranslate()
35163 assert( pMem->enc!=0 ); in sqlite3VdbeMemTranslate()
35164 assert( pMem->n>=0 ); in sqlite3VdbeMemTranslate()
35170 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); in sqlite3VdbeMemTranslate()
35248 *z++ = 0; in sqlite3VdbeMemTranslate()
35256 if( c>=0xd800 && c<0xe000 ){ in sqlite3VdbeMemTranslate()
35258 if( c>=0xdc00 || zIn>=zTerm ){ in sqlite3VdbeMemTranslate()
35259 c = 0xfffd; in sqlite3VdbeMemTranslate()
35263 if( c2<0xdc00 || c2>=0xe000 ){ in sqlite3VdbeMemTranslate()
35265 c = 0xfffd; in sqlite3VdbeMemTranslate()
35267 c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; in sqlite3VdbeMemTranslate()
35274 c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); in sqlite3VdbeMemTranslate()
35285 if( c>=0xd800 && c<0xe000 ){ in sqlite3VdbeMemTranslate()
35287 if( c>=0xdc00 || zIn>=zTerm ){ in sqlite3VdbeMemTranslate()
35288 c = 0xfffd; in sqlite3VdbeMemTranslate()
35292 if( c2<0xdc00 || c2>=0xe000 ){ in sqlite3VdbeMemTranslate()
35294 c = 0xfffd; in sqlite3VdbeMemTranslate()
35296 c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; in sqlite3VdbeMemTranslate()
35303 c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); in sqlite3VdbeMemTranslate()
35312 *z = 0; in sqlite3VdbeMemTranslate()
35328 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); in sqlite3VdbeMemTranslate()
35349 u8 bom = 0; in sqlite3VdbeMemHandleBom()
35351 assert( pMem->n>=0 ); in sqlite3VdbeMemHandleBom()
35355 if( b1==0xFE && b2==0xFF ){ in sqlite3VdbeMemHandleBom()
35358 if( b1==0xFF && b2==0xFE ){ in sqlite3VdbeMemHandleBom()
35368 pMem->z[pMem->n] = '\0'; in sqlite3VdbeMemHandleBom()
35369 pMem->z[pMem->n+1] = '\0'; in sqlite3VdbeMemHandleBom()
35381 ** the first 0x00 byte. If nByte is not less than zero, return the
35383 ** the first 0x00, whichever comes first).
35386 int r = 0; in sqlite3Utf8CharLen()
35389 if( nByte>=0 ){ in sqlite3Utf8CharLen()
35395 while( *z!=0 && z<zTerm ){ in sqlite3Utf8CharLen()
35420 while( zIn[0] && zOut<=zIn ){ in sqlite3Utf8To8()
35422 if( c!=0xfffd ){ in sqlite3Utf8To8()
35426 *zOut = 0; in sqlite3Utf8To8()
35441 memset(&m, 0, sizeof(m)); in sqlite3Utf16to8()
35447 m.z = 0; in sqlite3Utf16to8()
35449 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed ); in sqlite3Utf16to8()
35450 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed ); in sqlite3Utf16to8()
35465 int n = 0; in sqlite3Utf16ByteLen()
35469 c = z[0]; in sqlite3Utf16ByteLen()
35471 if( c>=0xd8 && c<0xdc && z<=zEnd && z[0]>=0xdc && z[0]<0xe0 ) z += 2; in sqlite3Utf16ByteLen()
35491 for(i=0; i<0x00110000; i++){ in sqlite3UtfSelfTest()
35495 assert( n>0 && n<=4 ); in sqlite3UtfSelfTest()
35496 z[0] = 0; in sqlite3UtfSelfTest()
35500 if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD; in sqlite3UtfSelfTest()
35501 if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD; in sqlite3UtfSelfTest()
35539 ** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0). The
35603 if( z==0 ) return 0; in sqlite3Strlen30()
35604 return 0x3fffffff & (int)strlen(z); in sqlite3Strlen30()
35641 assert( db!=0 ); in sqlite3Error()
35655 assert( db!=0 ); in sqlite3ErrorClear()
35672 for(ii=0; ii<db->nDb; ii++){ in sqlite3SystemError()
35684 rc &= 0xff; in sqlite3SystemError()
35703 assert( db!=0 ); in sqlite3ErrorWithMsg()
35706 if( zFormat==0 ){ in sqlite3ErrorWithMsg()
35708 }else if( db->pErr || (db->pErr = sqlite3ValueNew(db))!=0 ){ in sqlite3ErrorWithMsg()
35730 p->nProgressSteps = 0; in sqlite3ProgressCheck()
35736 p->nProgressSteps = 0; in sqlite3ProgressCheck()
35756 assert( db!=0 ); in sqlite3ErrorMsg()
35774 pParse->pWith = 0; in sqlite3ErrorMsg()
35785 if( db==0 || (pParse = db->pParse)==0 ) return errCode; in sqlite3ErrorToParser()
35811 if( z==0 ) return; in sqlite3Dequote()
35812 quote = z[0]; in sqlite3Dequote()
35815 for(i=1, j=0;; i++){ in sqlite3Dequote()
35828 z[j] = 0; in sqlite3Dequote()
35832 assert( sqlite3Isquote(p->u.zToken[0]) ); in sqlite3DequoteExpr()
35833 p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted; in sqlite3DequoteExpr()
35843 assert( p!=0 || pParse->db->mallocFailed ); in sqlite3DequoteNumber()
35847 int bHex = (pIn[0]=='0' && (pIn[1]=='x' || pIn[1]=='X')); in sqlite3DequoteNumber()
35856 if( (bHex==0 && (!sqlite3Isdigit(pIn[-1]) || !sqlite3Isdigit(pIn[1]))) in sqlite3DequoteNumber()
35889 if( !sqlite3Isquote(p->z[0]) ) return; in sqlite3DequoteToken()
35919 if( zLeft==0 ){ in sqlite3_stricmp()
35920 return zRight ? -1 : 0; in sqlite3_stricmp()
35921 }else if( zRight==0 ){ in sqlite3_stricmp()
35935 if( c==0 ) break; in sqlite3StrICmp()
35947 if( zLeft==0 ){ in sqlite3_strnicmp()
35948 return zRight ? -1 : 0; in sqlite3_strnicmp()
35949 }else if( zRight==0 ){ in sqlite3_strnicmp()
35954 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } in sqlite3_strnicmp()
35955 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; in sqlite3_strnicmp()
35962 u8 h = 0; in sqlite3StrIHash()
35963 if( z==0 ) return 0; in sqlite3StrIHash()
35964 while( z[0] ){ in sqlite3StrIHash()
35965 h += UpperToLower[(unsigned char)z[0]]; in sqlite3StrIHash()
35971 /* Double-Double multiplication. (x[0],x[1]) *= (y,yy)
35989 memcpy(&m, (void*)&x[0], 8); in dekkerMul2()
35990 m &= 0xfffffffffc000000LL; in dekkerMul2()
35992 tx = x[0] - hx; in dekkerMul2()
35994 m &= 0xfffffffffc000000LL; in dekkerMul2()
36001 cc = x[0]*yy + x[1]*y + cc; in dekkerMul2()
36002 x[0] = c + cc; in dekkerMul2()
36003 x[1] = c - x[0]; in dekkerMul2()
36019 ** 0 or less => The input string is not a valid number
36045 u64 s = 0; /* significand */ in sqlite3AtoF()
36046 int d = 0; /* adjust exponent for shifting decimal point */ in sqlite3AtoF()
36048 int e = 0; /* exponent */ in sqlite3AtoF()
36050 int nDigit = 0; /* Number of digits processed */ in sqlite3AtoF()
36057 if( length==0 ) return 0; in sqlite3AtoF()
36069 for(i=3-enc; i<length && z[i]==0; i+=2){} in sqlite3AtoF()
36077 if( z>=zEnd ) return 0; in sqlite3AtoF()
36089 s = s*10 + (*z - '0'); in sqlite3AtoF()
36107 s = s*10 + (*z - '0'); in sqlite3AtoF()
36119 eValid = 0; in sqlite3AtoF()
36136 e = e<10000 ? (e*10 + (*z - '0')) : 10000; in sqlite3AtoF()
36147 if( s==0 ){ in sqlite3AtoF()
36148 *pResult = sign<0 ? -0.0 : +0.0; in sqlite3AtoF()
36156 while( e>0 && s<((LARGEST_UINT64-0x7ff)/10) ){ in sqlite3AtoF()
36160 while( e<0 && (s%10)==0 ){ in sqlite3AtoF()
36165 rr[0] = (double)s; in sqlite3AtoF()
36166 assert( sizeof(s2)==sizeof(rr[0]) ); in sqlite3AtoF()
36170 assert( s2==0x43efffffffffffffLL ); in sqlite3AtoF()
36174 if( rr[0]<=18446744073709549568.0 ){ in sqlite3AtoF()
36175 s2 = (u64)rr[0]; in sqlite3AtoF()
36180 assert( rr[1]<=1.0e-10*rr[0] ); /* Equal only when rr[0]==0.0 */ in sqlite3AtoF()
36182 if( e>0 ){ in sqlite3AtoF()
36209 *pResult = rr[0]+rr[1]; in sqlite3AtoF()
36211 if( sign<0 ) *pResult = -*pResult; in sqlite3AtoF()
36216 if( z==zEnd && nDigit>0 && eValid && eType>0 ){ in sqlite3AtoF()
36218 }else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){ in sqlite3AtoF()
36221 return 0; in sqlite3AtoF()
36243 if( v<0 ){ in sqlite3Int64ToText()
36249 zTemp[sizeof(zTemp)-1] = 0; in sqlite3Int64ToText()
36251 zTemp[i] = (x%10) + '0'; in sqlite3Int64ToText()
36253 if( x==0 ) break; in sqlite3Int64ToText()
36256 if( v<0 ) zTemp[--i] = '-'; in sqlite3Int64ToText()
36276 int c = 0; in compare2pow63()
36280 for(i=0; c==0 && i<18; i++){ in compare2pow63()
36283 if( c==0 ){ in compare2pow63()
36286 testcase( c==0 ); in compare2pow63()
36299 ** 0 Successful transformation. Fits in a 64-bit signed integer.
36310 u64 u = 0; in sqlite3Atoi64()
36311 int neg = 0; /* assume positive */ in sqlite3Atoi64()
36313 int c = 0; in sqlite3Atoi64()
36314 int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */ in sqlite3Atoi64()
36325 for(i=3-enc; i<length && zNum[i]==0; i+=2){} in sqlite3Atoi64()
36340 while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */ in sqlite3Atoi64()
36341 for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){ in sqlite3Atoi64()
36342 u = u*10 + c - '0'; in sqlite3Atoi64()
36358 rc = 0; in sqlite3Atoi64()
36359 if( i==0 && zStart==zNum ){ /* No digits */ in sqlite3Atoi64()
36380 if( c<0 ){ in sqlite3Atoi64()
36386 if( c>0 ){ in sqlite3Atoi64()
36406 ** 0 Successful transformation. Fits in a 64-bit signed integer.
36413 if( z[0]=='0' in sqlite3DecOrHexToI64()
36416 u64 u = 0; in sqlite3DecOrHexToI64()
36418 for(i=2; z[i]=='0'; i++){} in sqlite3DecOrHexToI64()
36424 if( z[k]!=0 ) return 1; in sqlite3DecOrHexToI64()
36425 return 0; in sqlite3DecOrHexToI64()
36429 int n = (int)(0x3fffffff&strspn(z,"+- \n\t0123456789")); in sqlite3DecOrHexToI64()
36446 sqlite_int64 v = 0; in sqlite3GetInt32()
36448 int neg = 0; in sqlite3GetInt32()
36449 if( zNum[0]=='-' ){ in sqlite3GetInt32()
36452 }else if( zNum[0]=='+' ){ in sqlite3GetInt32()
36456 else if( zNum[0]=='0' in sqlite3GetInt32()
36460 u32 u = 0; in sqlite3GetInt32()
36462 while( zNum[0]=='0' ) zNum++; in sqlite3GetInt32()
36463 for(i=0; i<8 && sqlite3Isxdigit(zNum[i]); i++){ in sqlite3GetInt32()
36466 if( (u&0x80000000)==0 && sqlite3Isxdigit(zNum[i])==0 ){ in sqlite3GetInt32()
36470 return 0; in sqlite3GetInt32()
36474 if( !sqlite3Isdigit(zNum[0]) ) return 0; in sqlite3GetInt32()
36475 while( zNum[0]=='0' ) zNum++; in sqlite3GetInt32()
36476 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){ in sqlite3GetInt32()
36487 return 0; in sqlite3GetInt32()
36491 return 0; in sqlite3GetInt32()
36502 ** string is not an integer, just return 0.
36505 int x = 0; in sqlite3Atoi()
36514 ** If iRound<=0 then round to -iRound significant digits to the
36518 ** If iRound>0 round to min(iRound,mxRound) significant digits total.
36530 int e, exp = 0; in sqlite3FpDecode()
36533 p->isSpecial = 0; in sqlite3FpDecode()
36535 assert( mxRound>0 ); in sqlite3FpDecode()
36546 p->z = "0"; in sqlite3FpDecode()
36553 if( (e&0x7ff)==0x7ff ){ in sqlite3FpDecode()
36554 p->isSpecial = 1 + (v!=0x7ff0000000000000LL); in sqlite3FpDecode()
36555 p->n = 0; in sqlite3FpDecode()
36556 p->iDP = 0; in sqlite3FpDecode()
36571 rr[0] = r; in sqlite3FpDecode()
36573 if( rr[0]>9.223372036854774784e+18 ){ in sqlite3FpDecode()
36574 while( rr[0]>9.223372036854774784e+118 ){ in sqlite3FpDecode()
36578 while( rr[0]>9.223372036854774784e+28 ){ in sqlite3FpDecode()
36582 while( rr[0]>9.223372036854774784e+18 ){ in sqlite3FpDecode()
36587 while( rr[0]<9.223372036854774784e-83 ){ in sqlite3FpDecode()
36591 while( rr[0]<9.223372036854774784e+07 ){ in sqlite3FpDecode()
36595 while( rr[0]<9.22337203685477478e+17 ){ in sqlite3FpDecode()
36600 v = rr[1]<0.0 ? (u64)rr[0]-(u64)(-rr[1]) : (u64)rr[0]+(u64)rr[1]; in sqlite3FpDecode()
36604 assert( v>0 ); in sqlite3FpDecode()
36605 while( v ){ p->zBuf[i--] = (v%10) + '0'; v /= 10; } in sqlite3FpDecode()
36606 assert( i>=0 && i<sizeof(p->zBuf)-1 ); in sqlite3FpDecode()
36608 assert( p->n>0 ); in sqlite3FpDecode()
36611 if( iRound<=0 ){ in sqlite3FpDecode()
36613 if( iRound==0 && p->zBuf[i+1]>='5' ){ in sqlite3FpDecode()
36615 p->zBuf[i--] = '0'; in sqlite3FpDecode()
36620 if( iRound>0 && (iRound<p->n || p->n>mxRound) ){ in sqlite3FpDecode()
36629 z[j] = '0'; in sqlite3FpDecode()
36630 if( j==0 ){ in sqlite3FpDecode()
36643 assert( p->n>0 ); in sqlite3FpDecode()
36644 while( p->z[p->n-1]=='0' ){ in sqlite3FpDecode()
36646 assert( p->n>0 ); in sqlite3FpDecode()
36657 u64 v = 0; in sqlite3GetUInt32()
36659 for(i=0; sqlite3Isdigit(z[i]); i++){ in sqlite3GetUInt32()
36660 v = v*10 + z[i] - '0'; in sqlite3GetUInt32()
36661 if( v>4294967296LL ){ *pI = 0; return 0; } in sqlite3GetUInt32()
36663 if( i==0 || z[i]!=0 ){ *pI = 0; return 0; } in sqlite3GetUInt32()
36672 ** A = 0xxxxxxx 7 bits of data and one flag bit
36688 ** Write a 64-bit variable-length integer to memory starting at p[0].
36700 if( v & (((u64)0xff000000)<<32) ){ in putVarint64()
36703 for(i=7; i>=0; i--){ in putVarint64()
36704 p[i] = (u8)((v & 0x7f) | 0x80); in putVarint64()
36709 n = 0; in putVarint64()
36711 buf[n++] = (u8)((v & 0x7f) | 0x80); in putVarint64()
36713 }while( v!=0 ); in putVarint64()
36714 buf[0] &= 0x7f; in putVarint64()
36716 for(i=0, j=n-1; j>=0; j--, i++){ in putVarint64()
36722 if( v<=0x7f ){ in sqlite3PutVarint()
36723 p[0] = v&0x7f; in sqlite3PutVarint()
36726 if( v<=0x3fff ){ in sqlite3PutVarint()
36727 p[0] = ((v>>7)&0x7f)|0x80; in sqlite3PutVarint()
36728 p[1] = v&0x7f; in sqlite3PutVarint()
36739 ** SLOT_2_0 A mask for (0x7f<<14) | 0x7f
36741 ** SLOT_4_2_0 A mask for (0x7f<<28) | SLOT_2_0
36743 #define SLOT_2_0 0x001fc07f
36744 #define SLOT_4_2_0 0xf01fc07f
36748 ** Read a 64-bit variable-length integer from memory starting at p[0].
36754 if( ((signed char*)p)[0]>=0 ){ in sqlite3GetVarint()
36758 if( ((signed char*)p)[1]>=0 ){ in sqlite3GetVarint()
36759 *v = ((u32)(p[0]&0x7f)<<7) | p[1]; in sqlite3GetVarint()
36764 assert( SLOT_2_0 == ((0x7f<<14) | (0x7f)) ); in sqlite3GetVarint()
36765 assert( SLOT_4_2_0 == ((0xfU<<28) | (0x7f<<14) | (0x7f)) ); in sqlite3GetVarint()
36767 a = ((u32)p[0])<<14; in sqlite3GetVarint()
36772 if (!(a&0x80)) in sqlite3GetVarint()
36775 b &= 0x7f; in sqlite3GetVarint()
36788 if (!(b&0x80)) in sqlite3GetVarint()
36792 /* a &= (0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36803 /* a &= (0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36812 if (!(a&0x80)) in sqlite3GetVarint()
36816 /* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36817 /* b &= (0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36834 if (!(b&0x80)) in sqlite3GetVarint()
36837 /* b &= (0x7f<<28)|(0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36850 if (!(a&0x80)) in sqlite3GetVarint()
36867 if (!(b&0x80)) in sqlite3GetVarint()
36871 /* a &= (0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36885 /* a &= (0x7f<<29)|(0x7f<<15)|(0xff); */ in sqlite3GetVarint()
36892 b &= 0x7f; in sqlite3GetVarint()
36902 ** Read a 32-bit variable-length integer from memory starting at p[0].
36905 ** If the varint stored in p[0] is larger than can fit in a 32-bit unsigned
36906 ** integer, then set *v to 0xffffffff.
36918 assert( (p[0] & 0x80)!=0 ); in sqlite3GetVarint32()
36920 if( (p[1] & 0x80)==0 ){ in sqlite3GetVarint32()
36922 *v = ((p[0]&0x7f)<<7) | p[1]; in sqlite3GetVarint32()
36925 if( (p[2] & 0x80)==0 ){ in sqlite3GetVarint32()
36927 *v = ((p[0]&0x7f)<<14) | ((p[1]&0x7f)<<7) | p[2]; in sqlite3GetVarint32()
36934 *v = 0xffffffff; in sqlite3GetVarint32()
36947 for(i=1; (v >>= 7)!=0; i++){ assert( i<10 ); } in sqlite3VarintLen()
36969 testcase( p[0]&0x80 ); in sqlite3Get4byte()
36970 return ((unsigned)p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]; in sqlite3Get4byte()
36983 p[0] = (u8)(v>>24); in sqlite3Put4byte()
36995 ** character: 0..9a..fA..F
36998 assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') ); in sqlite3HexToInt()
37005 return (u8)(h & 0xf); in sqlite3HexToInt()
37022 for(i=0; i<n; i+=2){ in sqlite3HexToBlob()
37025 zBlob[i/2] = 0; in sqlite3HexToBlob()
37048 ** 1 it means that the db pointer is valid and 0 if it should not be
37059 if( db==0 ){ in sqlite3SafetyCheckOk()
37061 return 0; in sqlite3SafetyCheckOk()
37066 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3SafetyCheckOk()
37069 return 0; in sqlite3SafetyCheckOk()
37080 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3SafetyCheckSickOrOk()
37082 return 0; in sqlite3SafetyCheckSickOrOk()
37091 ** Return 0 on success. Or if the operation would have resulted in an
37099 testcase( iA==0 ); testcase( iA==1 ); in sqlite3AddInt64()
37100 testcase( iB==-1 ); testcase( iB==0 ); in sqlite3AddInt64()
37101 if( iB>=0 ){ in sqlite3AddInt64()
37102 testcase( iA>0 && LARGEST_INT64 - iA == iB ); in sqlite3AddInt64()
37103 testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 ); in sqlite3AddInt64()
37104 if( iA>0 && LARGEST_INT64 - iA < iB ) return 1; in sqlite3AddInt64()
37106 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 ); in sqlite3AddInt64()
37107 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 ); in sqlite3AddInt64()
37108 if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1; in sqlite3AddInt64()
37111 return 0; in sqlite3AddInt64()
37120 testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); in sqlite3SubInt64()
37121 if( (*pA)>=0 ) return 1; in sqlite3SubInt64()
37123 return 0; in sqlite3SubInt64()
37134 if( iB>0 ){ in sqlite3MulInt64()
37137 }else if( iB<0 ){ in sqlite3MulInt64()
37138 if( iA>0 ){ in sqlite3MulInt64()
37140 }else if( iA<0 ){ in sqlite3MulInt64()
37147 return 0; in sqlite3MulInt64()
37156 if( x>=0 ) return x; in sqlite3AbsInt32()
37157 if( x==(int)0x80000000 ) return 0x7fffffff; in sqlite3AbsInt32()
37181 if( sqlite3_uri_boolean(zBaseFilename, "8_3_names", 0) ) in sqlite3FileSuffix3()
37186 for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){} in sqlite3FileSuffix3()
37200 10, 10, /* 0,1 */ in sqlite3LogEstAdd()
37226 static LogEst a[] = { 0, 2, 3, 5, 6, 7, 8, 9 }; in sqlite3LogEst()
37229 if( x<2 ) return 0; in sqlite3LogEst()
37252 if( x<=1 ) return 0; in sqlite3LogEstFromDouble()
37300 ** } a[0];
37320 assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */ in sqlite3VListAdd()
37321 if( pIn==0 || pIn[1]+nInt > pIn[0] ){ in sqlite3VListAdd()
37323 sqlite3_int64 nAlloc = (pIn ? 2*(sqlite3_int64)pIn[0] : 10) + nInt; in sqlite3VListAdd()
37325 if( pOut==0 ) return pIn; in sqlite3VListAdd()
37326 if( pIn==0 ) pOut[1] = 2; in sqlite3VListAdd()
37328 pIn[0] = nAlloc; in sqlite3VListAdd()
37335 assert( pIn[1]<=pIn[0] ); in sqlite3VListAdd()
37337 z[nName] = 0; in sqlite3VListAdd()
37348 if( pIn==0 ) return 0; in sqlite3VListNumToName()
37355 return 0; in sqlite3VListNumToName()
37360 ** or return 0 if there is no such variable.
37364 if( pIn==0 ) return 0; in sqlite3VListNameToNum()
37369 if( strncmp(z,zName,nName)==0 && z[nName]==0 ) return pIn[i]; in sqlite3VListNameToNum()
37372 return 0; in sqlite3VListNameToNum()
37400 assert( pNew!=0 ); in sqlite3HashInit()
37401 pNew->first = 0; in sqlite3HashInit()
37402 pNew->count = 0; in sqlite3HashInit()
37403 pNew->htsize = 0; in sqlite3HashInit()
37404 pNew->ht = 0; in sqlite3HashInit()
37414 assert( pH!=0 ); in sqlite3HashClear()
37416 pH->first = 0; in sqlite3HashClear()
37418 pH->ht = 0; in sqlite3HashClear()
37419 pH->htsize = 0; in sqlite3HashClear()
37425 pH->count = 0; in sqlite3HashClear()
37432 unsigned int h = 0; in strHash()
37433 while( z[0] ){ /*OPTIMIZATION-IF-TRUE*/ in strHash()
37435 ** 0x9e3779b1 is 2654435761 which is the closest prime number to in strHash()
37438 ** Only bits 0xdf for ASCII and bits 0xbf for EBCDIC each octet are in strHash()
37442 h += 0xbf & (unsigned char)*(z++); in strHash()
37444 h += 0xdf & (unsigned char)*(z++); in strHash()
37446 h *= 0x9e3779b1; in strHash()
37452 /* Link pNew element into the hash table pH. If pEntry!=0 then also
37462 pHead = pEntry->count ? pEntry->chain : 0; in insertElement()
37466 pHead = 0; in insertElement()
37477 pNew->prev = 0; in insertElement()
37493 #if SQLITE_MALLOC_SOFT_LIMIT>0 in rehash()
37497 if( new_size==pH->htsize ) return 0; in rehash()
37502 ** allocation as a benign. Use sqlite3Malloc()/memset(0) instead of in rehash()
37512 if( new_ht==0 ) return 0; in rehash()
37516 memset(new_ht, 0, new_size*sizeof(struct _ht)); in rehash()
37517 for(elem=pH->first, pH->first=0; elem; elem = next_elem){ in rehash()
37526 ** a pointer to a static null element with HashElem.data==0 is returned.
37537 static HashElem nullElement = { 0, 0, 0, 0, 0 }; in findElementWithHash()
37551 assert( elem!=0 ); in findElementWithHash()
37552 if( h==elem->h && sqlite3StrICmp(elem->pKey,pKey)==0 ){ in findElementWithHash()
37582 assert( pEntry->count>0 ); in removeElement()
37587 if( pH->count==0 ){ in removeElement()
37588 assert( pH->first==0 ); in removeElement()
37589 assert( pH->count==0 ); in removeElement()
37599 assert( pH!=0 ); in sqlite3HashFind()
37600 assert( pKey!=0 ); in sqlite3HashFind()
37601 return findElementWithHash(pH, pKey, 0)->data; in sqlite3HashFind()
37623 assert( pH!=0 ); in sqlite3HashInsert()
37624 assert( pKey!=0 ); in sqlite3HashInsert()
37628 if( data==0 ){ in sqlite3HashInsert()
37636 if( data==0 ) return 0; in sqlite3HashInsert()
37638 if( new_elem==0 ) return data; in sqlite3HashInsert()
37646 insertElement(pH, pH->ht ? &pH->ht[new_elem->h % pH->htsize] : 0, new_elem); in sqlite3HashInsert()
37647 return 0; in sqlite3HashInsert()
37658 # define OpHelp(X) "\0" X
37664 /* 0 */ "Savepoint" OpHelp(""), in sqlite3OpcodeName()
37713 /* 49 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), in sqlite3OpcodeName()
37714 /* 50 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"), in sqlite3OpcodeName()
37724 /* 60 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"), in sqlite3OpcodeName()
37725 /* 61 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), in sqlite3OpcodeName()
37756 /* 92 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"), in sqlite3OpcodeName()
37824 /* 160 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), in sqlite3OpcodeName()
37844 /* 180 */ "ClrSubtype" OpHelp("r[P1].subtype = 0"), in sqlite3OpcodeName()
37885 #if 0
37892 #if 0
37958 0, /* pNext */
37960 0, /* pAppData */
37966 0, /* xDlError */
37967 0, /* xDlSym */
37968 0, /* xDlClose */
37972 0, /* xGetLastError */
37992 0, /* xShmMap */
37993 0, /* xShmLock */
37994 0, /* xShmBarrier */
37995 0, /* xShmUnmap */
37996 0, /* xFetch */
37997 0 /* xUnfetch */
38016 0, /* xShmMap */
38017 0, /* xShmLock */
38018 0, /* xShmBarrier */
38019 0, /* xShmUnmap */
38020 0, /* xFetch */
38021 0 /* xUnfetch */
38070 return 0; in kvstorageWrite()
38085 return 0; in kvstorageDelete()
38098 ** If nBuf<=0 then this routine simply returns the size of the data without
38111 if( access(zXKey, R_OK)!=0 in kvstorageRead()
38112 || stat(zXKey, &buf)!=0 in kvstorageRead()
38118 if( nBuf<=0 ){ in kvstorageRead()
38121 zBuf[0] = 0; in kvstorageRead()
38130 if( fd==0 ){ in kvstorageRead()
38136 zBuf[n] = 0; in kvstorageRead()
38199 ** base-26 number using a..z. "a" means 0. "b" means 1,
38209 for(i=j=0; i<nData; i++){ in kvvfsEncode()
38211 if( c!=0 ){ in kvvfsEncode()
38213 aOut[j++] = "0123456789ABCDEF"[c&0xf]; in kvvfsEncode()
38221 for(k=1; i+k<nData && a[i+k]==0; k++){} in kvvfsEncode()
38223 while( k>0 ){ in kvvfsEncode()
38229 aOut[j] = 0; in kvvfsEncode()
38237 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
38263 i = 0; in kvvfsDecode()
38264 j = 0; in kvvfsDecode()
38267 if( c<0 ){ in kvvfsDecode()
38268 int n = 0; in kvvfsDecode()
38271 if( c==0 ) break; in kvvfsDecode()
38278 memset(&aOut[j], 0, n); in kvvfsDecode()
38280 if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */ in kvvfsDecode()
38284 if( c<0 ) break; in kvvfsDecode()
38308 unsigned int n = 0; in kvvfsDecodeJournal()
38310 i = 0; in kvvfsDecodeJournal()
38318 if( pFile->aJrnl==0 ){ in kvvfsDecodeJournal()
38319 pFile->nJrnl = 0; in kvvfsDecodeJournal()
38326 pFile->aJrnl = 0; in kvvfsDecodeJournal()
38327 pFile->nJrnl = 0; in kvvfsDecodeJournal()
38336 zData[0] = 0; in kvvfsReadFileSize()
38338 return strtoll(zData, 0, 0); in kvvfsReadFileSize()
38373 if( pFile->aJrnl==0 ){ in kvvfsReadJrnl()
38374 int szTxt = kvstorageRead(pFile->zClass, "jrnl", 0, 0); in kvvfsReadJrnl()
38380 if( aTxt==0 ) return SQLITE_NOMEM; in kvvfsReadJrnl()
38384 if( pFile->aJrnl==0 ) return SQLITE_IOERR; in kvvfsReadJrnl()
38407 assert( iOfst>=0 ); in kvvfsReadDb()
38408 assert( iAmt>=0 ); in kvvfsReadDb()
38411 if( (iOfst % iAmt)!=0 ){ in kvvfsReadDb()
38414 if( (iAmt & (iAmt-1))!=0 || iAmt<512 || iAmt>65536 ){ in kvvfsReadDb()
38425 if( got<0 ){ in kvvfsReadDb()
38426 n = 0; in kvvfsReadDb()
38428 aData[got] = 0; in kvvfsReadDb()
38431 aData[k*2] = 0; in kvvfsReadDb()
38437 n = 0; in kvvfsReadDb()
38444 memset(zBuf+n, 0, iAmt-n); in kvvfsReadDb()
38463 if( iEnd>=0x10000000 ) return SQLITE_FULL; in kvvfsWriteJrnl()
38464 if( pFile->aJrnl==0 || pFile->nJrnl<iEnd ){ in kvvfsWriteJrnl()
38466 if( aNew==0 ){ in kvvfsWriteJrnl()
38471 memset(pFile->aJrnl+pFile->nJrnl, 0, iOfst-pFile->nJrnl); in kvvfsWriteJrnl()
38494 assert( (iAmt & (iAmt-1))==0 ); in kvvfsWriteDb()
38495 assert( pFile->szPage<0 || pFile->szPage==iAmt ); in kvvfsWriteDb()
38515 assert( size==0 ); in kvvfsTruncateJrnl()
38518 pFile->aJrnl = 0; in kvvfsTruncateJrnl()
38519 pFile->nJrnl = 0; in kvvfsTruncateJrnl()
38525 && pFile->szPage>0 in kvvfsTruncateDb()
38526 && (size % pFile->szPage)==0 in kvvfsTruncateDb()
38552 if( pFile->nJrnl<=0 ){ in kvvfsSyncJrnl()
38553 return kvvfsTruncateJrnl(pProtoFile, 0); in kvvfsSyncJrnl()
38556 if( zOut==0 ){ in kvvfsSyncJrnl()
38560 i = 0; in kvvfsSyncJrnl()
38564 }while( n>0 ); in kvvfsSyncJrnl()
38587 if( pFile->szDb>=0 ){ in kvvfsFileSizeDb()
38627 *pResOut = 0; in kvvfsCheckReservedLock()
38644 if( pFile->szDb>0 && 0!=kvvfsWriteFileSize(pFile, pFile->szDb) ){ in kvvfsFileControlDb()
38663 return 0; in kvvfsDeviceCharacteristics()
38679 if( zName==0 ) zName = ""; in kvvfsOpen()
38681 if( strcmp(zName, "local")==0 in kvvfsOpen()
38682 || strcmp(zName, "session")==0 in kvvfsOpen()
38684 pFile->isJournal = 0; in kvvfsOpen()
38687 if( strcmp(zName, "local-journal")==0 in kvvfsOpen()
38688 || strcmp(zName, "session-journal")==0 in kvvfsOpen()
38695 if( zName[0]=='s' ){ in kvvfsOpen()
38701 if( pFile->aData==0 ){ in kvvfsOpen()
38704 pFile->aJrnl = 0; in kvvfsOpen()
38705 pFile->nJrnl = 0; in kvvfsOpen()
38717 if( strcmp(zPath, "local-journal")==0 ){ in kvvfsDelete()
38720 if( strcmp(zPath, "session-journal")==0 ){ in kvvfsDelete()
38737 if( strcmp(zPath, "local-journal")==0 ){ in kvvfsAccess()
38738 *pResOut = sqlite3KvvfsMethods.xRead("local", "jrnl", 0, 0)>0; in kvvfsAccess()
38740 if( strcmp(zPath, "session-journal")==0 ){ in kvvfsAccess()
38741 *pResOut = sqlite3KvvfsMethods.xRead("session", "jrnl", 0, 0)>0; in kvvfsAccess()
38743 if( strcmp(zPath, "local")==0 ){ in kvvfsAccess()
38744 *pResOut = sqlite3KvvfsMethods.xRead("local", "sz", 0, 0)>0; in kvvfsAccess()
38746 if( strcmp(zPath, "session")==0 ){ in kvvfsAccess()
38747 *pResOut = sqlite3KvvfsMethods.xRead("session", "sz", 0, 0)>0; in kvvfsAccess()
38750 *pResOut = 0; in kvvfsAccess()
38775 zOut[nPath] = 0; in kvvfsFullPathname()
38783 return 0; in kvvfsDlOpen()
38791 memset(zBufOut, 0, nByte); in kvvfsRandomness()
38807 sqlite3_int64 i = 0; in kvvfsCurrentTime()
38809 rc = kvvfsCurrentTimeInt64(0, &i); in kvvfsCurrentTime()
38817 (void)gettimeofday(&sNow, 0); /* Cannot fail given valid arguments */ in kvvfsCurrentTimeInt64()
38837 return sqlite3_vfs_register(&sqlite3OsKvvfsObject, 0); in sqlite3KvvfsInit()
38912 # define SQLITE_ENABLE_LOCKING_STYLE 0
38940 #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
38957 ** -DHAVE_GETHOSTUUID=0
38964 # define HAVE_GETHOSTUUID 0
38967 # if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
38968 && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))\
38969 && (!defined(TARGET_OS_MACCATALYST) || (TARGET_OS_MACCATALYST==0))
38996 #define SQLITE_FSFLAGS_IS_MSDOS 0x1
39037 # define HAVE_MREMAP 0
39043 # define F_RDLCK 0
39046 # if __LONG_MAX == 0x7fffffffL
39112 #if SQLITE_MAX_MMAP_SIZE>0
39160 static pid_t randomnessPid = 0;
39165 #define UNIXFILE_EXCL 0x01 /* Connections from one process only */
39166 #define UNIXFILE_RDONLY 0x02 /* Connection is read only */
39167 #define UNIXFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */
39169 # define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */
39171 # define UNIXFILE_DIRSYNC 0x00
39173 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
39174 #define UNIXFILE_DELETE 0x20 /* Delete on close */
39175 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */
39176 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
39187 # define O_LARGEFILE 0
39191 # define O_LARGEFILE 0
39194 # define O_NOFOLLOW 0
39197 # define O_BINARY 0
39201 ** The threadid macro resolves to the thread-id or to 0. Used for
39207 #define threadid 0
39217 # define HAVE_MREMAP 0
39233 #define F2FS_IOCTL_MAGIC 0xf5
39239 #define F2FS_FEATURE_ATOMIC_WRITE 0x0004
39270 { "open", (sqlite3_syscall_ptr)posixOpen, 0 },
39271 #define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent)
39273 { "close", (sqlite3_syscall_ptr)close, 0 },
39276 { "access", (sqlite3_syscall_ptr)access, 0 },
39279 { "getcwd", (sqlite3_syscall_ptr)getcwd, 0 },
39282 { "stat", (sqlite3_syscall_ptr)stat, 0 },
39292 { "fstat", 0, 0 },
39293 #define osFstat(a,b,c) 0
39295 { "fstat", (sqlite3_syscall_ptr)fstat, 0 },
39299 { "ftruncate", (sqlite3_syscall_ptr)ftruncate, 0 },
39302 { "fcntl", (sqlite3_syscall_ptr)fcntl, 0 },
39305 { "read", (sqlite3_syscall_ptr)read, 0 },
39309 { "pread", (sqlite3_syscall_ptr)pread, 0 },
39311 { "pread", (sqlite3_syscall_ptr)0, 0 },
39316 { "pread64", (sqlite3_syscall_ptr)pread64, 0 },
39318 { "pread64", (sqlite3_syscall_ptr)0, 0 },
39322 { "write", (sqlite3_syscall_ptr)write, 0 },
39326 { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 },
39328 { "pwrite", (sqlite3_syscall_ptr)0, 0 },
39334 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 },
39336 { "pwrite64", (sqlite3_syscall_ptr)0, 0 },
39342 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
39344 { "fchmod", (sqlite3_syscall_ptr)0, 0 },
39349 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
39351 { "fallocate", (sqlite3_syscall_ptr)0, 0 },
39355 { "unlink", (sqlite3_syscall_ptr)unlink, 0 },
39358 { "openDirectory", (sqlite3_syscall_ptr)openDirectory, 0 },
39361 { "mkdir", (sqlite3_syscall_ptr)mkdir, 0 },
39364 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 },
39368 { "fchown", (sqlite3_syscall_ptr)fchown, 0 },
39370 { "fchown", (sqlite3_syscall_ptr)0, 0 },
39375 { "geteuid", (sqlite3_syscall_ptr)geteuid, 0 },
39377 { "geteuid", (sqlite3_syscall_ptr)0, 0 },
39381 #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
39383 { "mmap", (sqlite3_syscall_ptr)mmap, 0 },
39385 { "mmap", (sqlite3_syscall_ptr)0, 0 },
39389 #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
39391 { "munmap", (sqlite3_syscall_ptr)munmap, 0 },
39393 { "munmap", (sqlite3_syscall_ptr)0, 0 },
39397 #if HAVE_MREMAP && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
39398 { "mremap", (sqlite3_syscall_ptr)mremap, 0 },
39400 { "mremap", (sqlite3_syscall_ptr)0, 0 },
39404 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
39405 { "getpagesize", (sqlite3_syscall_ptr)unixGetpagesize, 0 },
39407 { "getpagesize", (sqlite3_syscall_ptr)0, 0 },
39412 { "readlink", (sqlite3_syscall_ptr)readlink, 0 },
39414 { "readlink", (sqlite3_syscall_ptr)0, 0 },
39419 { "lstat", (sqlite3_syscall_ptr)lstat, 0 },
39421 { "lstat", (sqlite3_syscall_ptr)0, 0 },
39427 { "ioctl", (sqlite3_syscall_ptr)(int(*)(int, int, ...))ioctl, 0 },
39430 { "ioctl", (sqlite3_syscall_ptr)ioctl, 0 },
39434 { "ioctl", (sqlite3_syscall_ptr)0, 0 },
39447 return osGeteuid() ? 0 : osFchown(fd,uid,gid); in robustFchown()
39449 return 0; in robustFchown()
39468 if( zName==0 ){ in unixSetSystemCall()
39473 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ in unixSetSystemCall()
39482 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ in unixSetSystemCall()
39483 if( strcmp(zName, aSyscall[i].zName)==0 ){ in unixSetSystemCall()
39484 if( aSyscall[i].pDefault==0 ){ in unixSetSystemCall()
39488 if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault; in unixSetSystemCall()
39509 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ in unixGetSystemCall()
39510 if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent; in unixGetSystemCall()
39512 return 0; in unixGetSystemCall()
39526 for(i=0; i<ArraySize(aSyscall)-1; i++){ in unixNextSystemCall()
39527 if( strcmp(zName, aSyscall[i].zName)==0 ) break; in unixNextSystemCall()
39531 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName; in unixNextSystemCall()
39533 return 0; in unixNextSystemCall()
39549 ** If the file creation mode "m" is 0 then set it to the default for
39551 ** 0644) as modified by the system umask. If m is not 0, then
39571 if( fd<0 ){ in robust_open()
39583 if( osOpen("/dev/null", O_RDONLY, m)<0 ) break; in robust_open()
39585 if( fd>=0 ){ in robust_open()
39586 if( m!=0 ){ in robust_open()
39588 if( osFstat(fd, &statbuf)==0 in robust_open()
39589 && statbuf.st_size==0 in robust_open()
39595 #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) in robust_open()
39596 osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); in robust_open()
39627 static sqlite3_mutex *unixBigLock = 0;
39690 assert( 0 ); in lockTrace()
39709 assert( 0 ); in lockTrace()
39735 if( sz>(sqlite3_int64)0x7FFFFFFF ){ in robust_ftruncate()
39739 do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR ); in robust_ftruncate()
39807 static struct vxworksFileId *vxworksFileList = 0;
39819 ** The original filename is in z[0..n-1]. Return the number of
39825 for(i=j=0; i<n; i++){ in vxworksSimplifyName()
39833 while( j>0 && z[j-1]!='/' ){ j--; } in vxworksSimplifyName()
39834 if( j>0 ){ j--; } in vxworksSimplifyName()
39841 z[j] = 0; in vxworksSimplifyName()
39861 assert( zAbsoluteName[0]=='/' ); in vxworksFindFileId()
39864 if( pNew==0 ) return 0; in vxworksFindFileId()
39876 && memcmp(pCandidate->zCanonicalName, pNew->zCanonicalName, n)==0 in vxworksFindFileId()
39900 assert( pId->nRef>0 ); in vxworksReleaseFileId()
39902 if( pId->nRef==0 ){ in vxworksReleaseFileId()
39963 ** field that tells us its internal lock status. cnt==0 means the
39965 ** cnt>0 means there are cnt shared locks on the file.
40000 ** was dropped beginning with version 3.7.0. SQLite will still work with
40040 ** (2) When nRef>0, then the following fields are unchanging and can
40077 static unixInodeInfo *inodeList = 0; /* All unixInodeInfo objects */
40121 /* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use in unixLogErrorAtLine()
40127 memset(aErr, 0, sizeof(aErr)); in unixLogErrorAtLine()
40159 if( zPath==0 ) zPath = ""; in unixLogErrorAtLine()
40184 pFile ? pFile->zPath : 0, lineno); in robust_close()
40209 pInode->pUnused = 0; in closePendingFds()
40224 if( pInode->nRef==0 ){ in releaseInodeInfo()
40225 assert( pInode->pShmNode==0 ); in releaseInodeInfo()
40263 unixInodeInfo *pInode = 0; /* Candidate unixInodeInfo object */ in findInodeInfo()
40272 if( rc!=0 ){ in findInodeInfo()
40291 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){ in findInodeInfo()
40292 do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR ); in findInodeInfo()
40298 if( rc!=0 ){ in findInodeInfo()
40305 memset(&fileId, 0, sizeof(fileId)); in findInodeInfo()
40317 if( pInode==0 ){ in findInodeInfo()
40319 if( pInode==0 ){ in findInodeInfo()
40322 memset(pInode, 0, sizeof(*pInode)); in findInodeInfo()
40326 if( pInode->pLockMutex==0 ){ in findInodeInfo()
40334 pInode->pPrev = 0; in findInodeInfo()
40349 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId; in fileHasMoved()
40352 return pFile->pInode!=0 && in fileHasMoved()
40353 (osStat(pFile->zPath, &buf)!=0 in fileHasMoved()
40376 if( rc!=0 ){ in verifyDbFile()
40380 if( buf.st_nlink==0 ){ in verifyDbFile()
40403 int reserved = 0; in unixCheckReservedLock()
40468 while( rc<0 && tm>0 ){ in osSetPosixAdvisoryLock()
40474 unixSleep(0,1000); in osSetPosixAdvisoryLock()
40505 assert( pInode!=0 ); in unixFileLock()
40508 if( pInode->bProcessLock==0 ){ in unixFileLock()
40510 /* assert( pInode->nLock==0 ); <-- Not true if unix-excl READONLY used */ in unixFileLock()
40516 if( rc<0 ) return rc; in unixFileLock()
40520 rc = 0; in unixFileLock()
40604 int tErrno = 0; in unixLock()
40610 osGetpid(0))); in unixLock()
40653 assert( pFile->eFileLock==0 ); in unixLock()
40654 assert( pInode->nShared>0 ); in unixLock()
40691 assert( pInode->nShared==0 ); in unixLock()
40692 assert( pInode->eFileLock==0 ); in unixLock()
40732 assert( 0!=pFile->eFileLock ); in unixLock()
40764 pFile->transCntrChng = 0; in unixLock()
40765 pFile->dbUpdate = 0; in unixLock()
40793 pFile->pPreallocatedUnused = 0; in setPendingFd()
40818 osGetpid(0))); in posixUnlock()
40826 assert( pInode->nShared!=0 ); in posixUnlock()
40839 pFile->inNormalWrite = 0; in posixUnlock()
40854 assert( handleNFSUnlock==0 ); in posixUnlock()
40917 if( unixFileLock(pFile, &lock)==0 ){ in posixUnlock()
40931 if( pInode->nShared==0 ){ in posixUnlock()
40934 lock.l_start = lock.l_len = 0L; in posixUnlock()
40935 if( unixFileLock(pFile, &lock)==0 ){ in posixUnlock()
40950 assert( pInode->nLock>=0 ); in posixUnlock()
40951 if( pInode->nLock==0 ) closePendingFds(pFile); in posixUnlock()
40970 #if SQLITE_MAX_MMAP_SIZE>0 in unixUnlock()
40971 assert( eFileLock==SHARED_LOCK || ((unixFile *)id)->nFetchOut==0 ); in unixUnlock()
40973 return posixUnlock(id, eFileLock, 0); in unixUnlock()
40976 #if SQLITE_MAX_MMAP_SIZE>0
40985 ** structure to 0.
40993 #if SQLITE_MAX_MMAP_SIZE>0 in closeUnixFile()
40996 if( pFile->h>=0 ){ in closeUnixFile()
41006 pFile->pId = 0; in closeUnixFile()
41013 pFile->zPath = 0; in closeUnixFile()
41019 memset(pFile, 0, sizeof(unixFile)); in closeUnixFile()
41031 assert( pInode!=0 ); in unixClose()
41040 assert( pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 ); in unixClose()
41052 assert( pFile->pShm==0 ); in unixClose()
41080 *pResOut = 0; in nolockCheckReservedLock()
41142 *pResOut = 0; in dotlockCheckReservedLock()
41144 *pResOut = osAccess((const char*)pFile->lockingContext, 0)==0; in dotlockCheckReservedLock()
41146 OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, 0, *pResOut)); in dotlockCheckReservedLock()
41199 if( rc<0 ){ in dotlockLock()
41234 pFile->eFileLock, osGetpid(0))); in dotlockUnlock()
41253 if( rc<0 ){ in dotlockUnlock()
41272 assert( id!=0 ); in dotlockClose()
41302 do{ rc = flock(fd,op); }while( rc<0 && errno==EINTR ); in robust_flock()
41330 ** connection may be holding a RESERVED lock. So set *pResOut to 0 in flockCheckReservedLock()
41334 ** 0 as well. The caller will then attempt to take an EXCLUSIVE lock on the in flockCheckReservedLock()
41341 *pResOut = 0; in flockCheckReservedLock()
41404 if( (rc & 0xff) == SQLITE_IOERR ){ in flockLock()
41424 pFile->eFileLock, osGetpid(0))); in flockUnlock()
41454 assert( id!=0 ); in flockClose()
41484 int reserved = 0; in semXCheckReservedLock()
41589 pFile->eFileLock, osGetpid(0))); in semXUnlock()
41666 unsigned char unLockFlag; /* 1 = unlock, 0 = lock */
41667 unsigned char startEndFlag; /* 1=rel to end of fork, 0=rel to start */
41689 pb.unLockFlag = setLockFlag ? 0 : 1; in afpSetLock()
41690 pb.startEndFlag = 0; in afpSetLock()
41698 err = fsctl(path, afpfsByteRangeLock2FSCTL, &pb, 0); in afpSetLock()
41727 int reserved = 0; in afpCheckReservedLock()
41753 lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0); in afpCheckReservedLock()
41803 azFileLock(pInode->eFileLock), pInode->nShared , osGetpid(0))); in afpLock()
41846 assert( pFile->eFileLock==0 ); in afpLock()
41847 assert( pInode->nShared>0 ); in afpLock()
41873 int lrc1, lrc2, lrc1Errno = 0; in afpLock()
41876 assert( pInode->nShared==0 ); in afpLock()
41877 assert( pInode->eFileLock==0 ); in afpLock()
41879 mask = (sizeof(long)==8) ? LARGEST_INT64 : 0x7fffffff; in afpLock()
41890 lrc2 = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0); in afpLock()
41915 int failed = 0; in afpLock()
41916 assert( 0!=pFile->eFileLock ); in afpLock()
41931 pInode->sharedByte, 1, 0)) ){ in afpLock()
41941 rc = ((failed & 0xff) == SQLITE_IOERR) ? failed2 : in afpLock()
41981 int skipShared = 0; in afpUnlock()
41986 osGetpid(0))); in afpUnlock()
41994 assert( pInode->nShared!=0 ); in afpUnlock()
42007 assert( pFile->inNormalWrite==0 in afpUnlock()
42008 || pFile->dbUpdate==0 in afpUnlock()
42010 pFile->inNormalWrite = 0; in afpUnlock()
42014 rc = afpSetLock(context->dbPath, pFile, SHARED_FIRST, SHARED_SIZE, 0); in afpUnlock()
42024 rc = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0); in afpUnlock()
42027 rc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0); in afpUnlock()
42029 context->reserved = 0; in afpUnlock()
42044 if( pInode->nShared==0 ){ in afpUnlock()
42046 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 0); in afpUnlock()
42055 assert( pInode->nLock>=0 ); in afpUnlock()
42056 if( pInode->nLock==0 ) closePendingFds(pFile); in afpUnlock()
42073 assert( id!=0 ); in afpClose()
42150 int prior = 0; in seekAndRead()
42155 assert( cnt==(cnt&0x1ffff) ); in seekAndRead()
42167 if( newOffset<0 ){ in seekAndRead()
42174 if( got<0 ){ in seekAndRead()
42176 prior = 0; in seekAndRead()
42179 }else if( got>0 ){ in seekAndRead()
42185 }while( got>0 ); in seekAndRead()
42206 assert( offset>=0 ); in unixRead()
42207 assert( amt>0 ); in unixRead()
42211 #if 0 in unixRead()
42212 assert( pFile->pPreallocatedUnused==0 in unixRead()
42218 #if SQLITE_MAX_MMAP_SIZE>0 in unixRead()
42238 }else if( got<0 ){ in unixRead()
42259 storeLastErrno(pFile, 0); /* not a system error */ in unixRead()
42261 memset(&((char*)pBuf)[got], 0, amt-got); in unixRead()
42280 int rc = 0; /* Value returned by system call */ in seekAndWriteFd()
42282 assert( nBuf==(nBuf&0x1ffff) ); in seekAndWriteFd()
42284 assert( piErrno!=0 ); in seekAndWriteFd()
42285 nBuf &= 0x1ffff; in seekAndWriteFd()
42289 do{ rc = (int)osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR ); in seekAndWriteFd()
42291 do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR); in seekAndWriteFd()
42296 if( iSeek<0 ){ in seekAndWriteFd()
42301 }while( rc<0 && errno==EINTR ); in seekAndWriteFd()
42307 if( rc<0 ) *piErrno = errno; in seekAndWriteFd()
42335 int wrote = 0; in unixWrite()
42337 assert( amt>0 ); in unixWrite()
42341 #if 0 in unixWrite()
42342 assert( pFile->pPreallocatedUnused==0 in unixWrite()
42362 SimulateIOErrorBenign(0); in unixWrite()
42363 if( rc!=4 || memcmp(oldCntr, &((char*)pBuf)[24-offset], 4)!=0 ){ in unixWrite()
42370 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 in unixWrite()
42387 while( (wrote = seekAndWrite(pFile, offset, pBuf, amt))<amt && wrote>0 ){ in unixWrite()
42393 SimulateDiskfullError(( wrote=0, amt=1 )); in unixWrite()
42396 if( wrote<0 && pFile->lastErrno!=ENOSPC ){ in unixWrite()
42400 storeLastErrno(pFile, 0); /* not a system error */ in unixWrite()
42413 SQLITE_API int sqlite3_sync_count = 0;
42414 SQLITE_API int sqlite3_fullsync_count = 0;
42428 ** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not
42435 # define HAVE_FULLFSYNC 0
42502 rc = osFcntl(fd, F_FULLFSYNC, 0); in full_fsync()
42531 rc = 0; in full_fsync()
42565 for(ii=(int)strlen(zDirname); ii>0 && zDirname[ii]!='/'; ii--); in openDirectory()
42566 if( ii>0 ){ in openDirectory()
42567 zDirname[ii] = '\0'; in openDirectory()
42569 if( zDirname[0]!='/' ) zDirname[0] = '.'; in openDirectory()
42570 zDirname[1] = 0; in openDirectory()
42572 fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0); in openDirectory()
42573 if( fd>=0 ){ in openDirectory()
42577 if( fd>=0 ) return SQLITE_OK; in openDirectory()
42584 ** If dataOnly==0 then both the file itself and its metadata (file
42585 ** size, access time, etc) are synced. If dataOnly!=0 then only the
42601 int isFullsync = (flags&0x0F)==SQLITE_SYNC_FULL; in unixSync()
42604 assert((flags&0x0F)==SQLITE_SYNC_NORMAL in unixSync()
42605 || (flags&0x0F)==SQLITE_SYNC_FULL in unixSync()
42632 full_fsync(dirfd, 0, 0); in unixSync()
42657 if( pFile->szChunk>0 ){ in unixTruncate()
42674 if( pFile->inNormalWrite && nByte==0 ){ in unixTruncate()
42679 #if SQLITE_MAX_MMAP_SIZE>0 in unixTruncate()
42702 if( rc!=0 ){ in unixFileSize()
42714 if( *pSize==1 ) *pSize = 0; in unixFileSize()
42735 if( pFile->szChunk>0 ){ in fcntlSizeHint()
42764 int nWrite = 0; /* Number of bytes written by seekAndWrite */ in fcntlSizeHint()
42769 assert( ((iWrite+1)%nBlk)==0 ); in fcntlSizeHint()
42779 #if SQLITE_MAX_MMAP_SIZE>0 in fcntlSizeHint()
42780 if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){ in fcntlSizeHint()
42782 if( pFile->szChunk<=0 ){ in fcntlSizeHint()
42799 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
42801 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
42804 if( *pArg<0 ){ in unixModeBit()
42805 *pArg = (pFile->ctrlFlags & mask)!=0; in unixModeBit()
42806 }else if( (*pArg)==0 ){ in unixModeBit()
42861 SimulateIOErrorBenign(0); in unixFileControl()
42893 pFile->iBusyTimeout = iNew<0 ? 0x7FFFFFFF : (unsigned)iNew; in unixFileControl()
42908 #if SQLITE_MAX_MMAP_SIZE>0 in unixFileControl()
42919 if( newLimit>0 && sizeof(size_t)<8 ){ in unixFileControl()
42920 newLimit = (newLimit & 0x7FFFFFFF); in unixFileControl()
42924 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){ in unixFileControl()
42926 if( pFile->mmapSize>0 ){ in unixFileControl()
42941 ((unixFile*)id)->dbUpdate = 0; in unixFileControl()
42956 *(int*)pArg = 0; in unixFileControl()
42975 assert( pFd->deviceCharacteristics==0 || pFd->sectorSize!=0 ); in setDeviceCharacteristics()
42976 if( pFd->sectorSize==0 ){ in setDeviceCharacteristics()
42979 u32 f = 0; in setDeviceCharacteristics()
42983 if( res==0 && (f & F2FS_FEATURE_ATOMIC_WRITE) ){ in setDeviceCharacteristics()
43001 if( pFile->sectorSize == 0 ){ in setDeviceCharacteristics()
43006 pFile->deviceCharacteristics = 0; in setDeviceCharacteristics()
43019 0; in setDeviceCharacteristics()
43029 0; in setDeviceCharacteristics()
43038 0; in setDeviceCharacteristics()
43046 0; in setDeviceCharacteristics()
43054 0; in setDeviceCharacteristics()
43060 0; in setDeviceCharacteristics()
43065 if( pFile->sectorSize % 512 != 0 ){ in setDeviceCharacteristics()
43066 pFile->deviceCharacteristics = 0; in setDeviceCharacteristics()
43107 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
43125 #endif /* !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 */
43154 ** Either unixShmNode.pShmMutex must be held or unixShmNode.nRef==0 and
43160 ** SQLITE_SHM_NLOCK slots. If the aLock[] entry is set to 0, then no
43230 ** such transactions, or 0 otherwise. If an error occurs, return an
43236 *piOut = 0; in unixFcntlExternalReader()
43241 memset(&f, 0, sizeof(f)); in unixFcntlExternalReader()
43248 if( osFcntl(pShmNode->hShm, F_GETLK, &f)<0 ){ in unixFcntlExternalReader()
43280 assert( pShmNode->nRef>=0 ); in unixShmSystemLock()
43285 assert( pShmNode->nRef>0 || unixMutexHeld() ); in unixShmSystemLock()
43286 assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->pShmMutex) ); in unixShmSystemLock()
43295 assert( pShmNode->nRef>0 ); in unixShmSystemLock()
43306 if( pShmNode->hShm>=0 ){ in unixShmSystemLock()
43362 assert( ((pgsz-1)&pgsz)==0 ); /* Page size must be a power of 2 */ in unixShmRegionPerMap()
43368 ** Purge the unixShmNodeList list of all entries with unixShmNode.nRef==0.
43376 if( p && ALWAYS(p->nRef==0) ){ in unixShmPurge()
43382 for(i=0; i<SQLITE_SHM_NLOCK; i++){ in unixShmPurge()
43386 for(i=0; i<p->nRegion; i+=nShmPerMap){ in unixShmPurge()
43387 if( p->hShm>=0 ){ in unixShmPurge()
43394 if( p->hShm>=0 ){ in unixShmPurge()
43398 p->pInode->pShmNode = 0; in unixShmPurge()
43438 if( osFcntl(pShmNode->hShm, F_GETLK, &lock)!=0 ) { in unixLockSharedMemory()
43453 pDbFd->iBusyTimeout = 0; in unixLockSharedMemory()
43461 ** -shm header size) rather than 0 as a system debugging aid, to in unixLockSharedMemory()
43515 struct unixShm *p = 0; /* The connection to be opened */ in unixOpenSharedMemory()
43524 if( p==0 ) return SQLITE_NOMEM_BKPT; in unixOpenSharedMemory()
43525 memset(p, 0, sizeof(*p)); in unixOpenSharedMemory()
43526 assert( pDbFd->pShm==0 ); in unixOpenSharedMemory()
43535 if( pShmNode==0 ){ in unixOpenSharedMemory()
43556 if( pShmNode==0 ){ in unixOpenSharedMemory()
43560 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename); in unixOpenSharedMemory()
43575 if( pShmNode->pShmMutex==0 ){ in unixOpenSharedMemory()
43582 for(ii=0; ii<SQLITE_SHM_NLOCK; ii++){ in unixOpenSharedMemory()
43584 if( pShmNode->aMutex[ii]==0 ){ in unixOpenSharedMemory()
43593 if( pInode->bProcessLock==0 ){ in unixOpenSharedMemory()
43594 if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){ in unixOpenSharedMemory()
43598 if( pShmNode->hShm<0 ){ in unixOpenSharedMemory()
43601 if( pShmNode->hShm<0 ){ in unixOpenSharedMemory()
43657 ** Otherwise, if the bExtend parameter is 0 and the requested shared-memory
43683 if( pDbFd->pShm==0 ){ in unixShmMap()
43694 pShmNode->isUnlocked = 0; in unixShmMap()
43696 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 ); in unixShmMap()
43698 assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 ); in unixShmMap()
43699 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 ); in unixShmMap()
43711 if( pShmNode->hShm>=0 ){ in unixShmMap()
43741 assert( (nByte % pgsz)==0 ); in unixShmMap()
43743 int x = 0; in unixShmMap()
43767 if( pShmNode->hShm>=0 ){ in unixShmMap()
43768 pMem = osMmap(0, nMap, in unixShmMap()
43778 if( pMem==0 ){ in unixShmMap()
43782 memset(pMem, 0, nMap); in unixShmMap()
43785 for(i=0; i<nShmPerMap; i++){ in unixShmMap()
43796 *pp = 0; in unixShmMap()
43818 memset(aLock, 0, sizeof(aLock)); in assertLockingArrayOk()
43821 for(i=0; i<SQLITE_SHM_NLOCK; i++){ in assertLockingArrayOk()
43823 assert( aLock[i]==0 ); in assertLockingArrayOk()
43826 assert( aLock[i]>=0 ); in assertLockingArrayOk()
43832 assert( 0==memcmp(pShmNode->aLock, aLock, sizeof(aLock)) ); in assertLockingArrayOk()
43833 return (memcmp(pShmNode->aLock, aLock, sizeof(aLock))==0); in assertLockingArrayOk()
43860 if( p==0 ) return SQLITE_IOERR_SHMLOCK; in unixShmLock()
43862 if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK; in unixShmLock()
43867 assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK ); in unixShmLock()
43873 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 ); in unixShmLock()
43874 assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 ); in unixShmLock()
43875 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 ); in unixShmLock()
43882 ** 3. Write lock (ofst==0). in unixShmLock()
43892 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || ( in unixShmLock()
43893 (ofst!=2 || lockMask==0) in unixShmLock()
43894 && (ofst!=1 || lockMask==0 || lockMask==2) in unixShmLock()
43895 && (ofst!=0 || lockMask<3) in unixShmLock()
43911 || 0==(p->exclMask & mask) in unixShmLock()
43914 || (flags==(SQLITE_SHM_SHARED|SQLITE_SHM_LOCK) && 0==(p->sharedMask & mask)) in unixShmLock()
43951 assert( (p->exclMask & p->sharedMask)==0 ); in unixShmLock()
43957 ** this case, set bUnlock to 0 so that the posix lock is not removed in unixShmLock()
43963 bUnlock = 0; in unixShmLock()
43972 memset(&aLock[ofst], 0, sizeof(int)*n); in unixShmLock()
43980 if( aLock[ofst]<0 ){ in unixShmLock()
43983 }else if( aLock[ofst]==0 ){ in unixShmLock()
43997 assert( (p->sharedMask & mask)==0 ); in unixShmLock()
43998 assert( (p->exclMask & mask)==0 ); in unixShmLock()
44036 p->id, osGetpid(0), p->sharedMask, p->exclMask)); in unixShmLock()
44076 if( p==0 ) return SQLITE_OK; in unixShmUnmap()
44090 pDbFd->pShm = 0; in unixShmUnmap()
44093 /* If pShmNode->nRef has reached 0, then close the underlying in unixShmUnmap()
44097 assert( pShmNode->nRef>0 ); in unixShmUnmap()
44099 if( pShmNode->nRef==0 ){ in unixShmUnmap()
44100 if( deleteFlag && pShmNode->hShm>=0 ){ in unixShmUnmap()
44112 # define unixShmMap 0
44113 # define unixShmLock 0
44114 # define unixShmBarrier 0
44115 # define unixShmUnmap 0
44118 #if SQLITE_MAX_MMAP_SIZE>0
44123 assert( pFd->nFetchOut==0 ); in unixUnmapfile()
44126 pFd->pMapRegion = 0; in unixUnmapfile()
44127 pFd->mmapSize = 0; in unixUnmapfile()
44128 pFd->mmapSizeActual = 0; in unixUnmapfile()
44155 u8 *pNew = 0; /* Location of new mapping */ in unixRemapfile()
44158 assert( pFd->nFetchOut==0 ); in unixRemapfile()
44161 assert( nNew>0 ); in unixRemapfile()
44163 assert( MAP_FAILED!=0 ); in unixRemapfile()
44166 if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE; in unixRemapfile()
44191 pNew = 0; in unixRemapfile()
44199 if( pNew==MAP_FAILED || pNew==0 ){ in unixRemapfile()
44205 if( pNew==0 ){ in unixRemapfile()
44206 pNew = osMmap(0, nNew, flags, MAP_SHARED, h, 0); in unixRemapfile()
44210 pNew = 0; in unixRemapfile()
44211 nNew = 0; in unixRemapfile()
44217 pFd->mmapSizeMax = 0; in unixRemapfile()
44240 assert( nMap>=0 || pFd->nFetchOut==0 ); in unixMapfile()
44241 assert( nMap>0 || (pFd->mmapSize==0 && pFd->pMapRegion==0) ); in unixMapfile()
44242 if( pFd->nFetchOut>0 ) return SQLITE_OK; in unixMapfile()
44244 if( nMap<0 ){ in unixMapfile()
44255 assert( nMap>0 || (pFd->mmapSize==0 && pFd->pMapRegion==0) ); in unixMapfile()
44262 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
44269 ** Or, if one cannot but no error occurs, set *pp to 0 and return SQLITE_OK.
44277 #if SQLITE_MAX_MMAP_SIZE>0 in unixFetch()
44280 *pp = 0; in unixFetch()
44282 #if SQLITE_MAX_MMAP_SIZE>0 in unixFetch()
44283 if( pFd->mmapSizeMax>0 ){ in unixFetch()
44289 if( pFd->pMapRegion==0 ){ in unixFetch()
44313 #if SQLITE_MAX_MMAP_SIZE>0 in unixUnfetch()
44317 /* If p==0 (unmap the entire file) then there must be no outstanding in unixUnfetch()
44318 ** xFetch references. Or, if p!=0 (meaning it is an xFetch reference), in unixUnfetch()
44320 assert( (p==0)==(pFd->nFetchOut==0) ); in unixUnfetch()
44322 /* If p!=0, it must match the iOff value. */ in unixUnfetch()
44323 assert( p==0 || p==&((u8 *)pFd->pMapRegion)[iOff] ); in unixUnfetch()
44331 assert( pFd->nFetchOut>=0 ); in unixUnfetch()
44432 0 /* xShmMap method */
44442 0 /* xShmMap method */
44454 0 /* xShmMap method */
44467 0 /* xShmMap method */
44480 0 /* xShmMap method */
44506 0 /* xShmMap method */
44520 0 /* xShmMap method */
44545 { 0, 0 } in autolockIoFinderImpl()
44560 for(i=0; aMap[i].zFilesystem; i++){ in autolockIoFinderImpl()
44561 if( strcmp(fsInfo.f_fstypename, aMap[i].zFilesystem)==0 ){ in autolockIoFinderImpl()
44572 lockInfo.l_start = 0; in autolockIoFinderImpl()
44576 if( strcmp(fsInfo.f_fstypename, "nfs")==0 ){ in autolockIoFinderImpl()
44612 lockInfo.l_start = 0; in vxworksIoFinderImpl()
44656 assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 ); in fillInUnixFile()
44663 #if SQLITE_MAX_MMAP_SIZE>0 in fillInUnixFile()
44666 if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0), in fillInUnixFile()
44670 if( strcmp(pVfs->zName,"unix-excl")==0 ){ in fillInUnixFile()
44676 if( pNew->pId==0 ){ in fillInUnixFile()
44733 if( pCtx==0 ){ in fillInUnixFile()
44740 pCtx->reserved = 0; in fillInUnixFile()
44760 assert( zFilename!=0 ); in fillInUnixFile()
44763 if( zLockFile==0 ){ in fillInUnixFile()
44788 pNew->pInode->aSemName[0] = '\0'; in fillInUnixFile()
44795 storeLastErrno(pNew, 0); in fillInUnixFile()
44798 if( h>=0 ) robust_close(pNew, h, __LINE__); in fillInUnixFile()
44805 if( h>=0 ) robust_close(pNew, h, __LINE__); in fillInUnixFile()
44818 0,
44819 0,
44830 azTempDirs[0] = getenv("SQLITE_TMPDIR"); in unixTempFileInit()
44839 unsigned int i = 0; in unixTempFileDir()
44844 if( zDir!=0 in unixTempFileDir()
44845 && osStat(zDir, &buf)==0 in unixTempFileDir()
44847 && osAccess(zDir, 03)==0 in unixTempFileDir()
44851 if( i>=sizeof(azTempDirs)/sizeof(azTempDirs[0]) ) break; in unixTempFileDir()
44854 return 0; in unixTempFileDir()
44864 int iLimit = 0; in unixGetTempname()
44871 zBuf[0] = 0; in unixGetTempname()
44876 if( zDir==0 ){ in unixGetTempname()
44883 zBuf[nBuf-2] = 0; in unixGetTempname()
44885 zDir, r, 0); in unixGetTempname()
44886 if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ){ in unixGetTempname()
44890 }while( osAccess(zBuf,0)==0 ); in unixGetTempname()
44922 UnixUnusedFd *pUnused = 0; in findReusableFd()
44942 if( inodeList!=0 && 0==osStat(zPath, &sStat) ){ in findReusableFd()
44979 if( 0==osStat(zFile, &sStat) ){ in getFileMode()
44996 ** In most cases, this routine sets *pMode to 0, which will become
45018 *pMode = 0; in findCreateFileMode()
45019 *pUid = 0; in findCreateFileMode()
45020 *pGid = 0; in findCreateFileMode()
45041 ** the filename. In that case, just return SQLITE_OK with *pMode==0. in findCreateFileMode()
45044 while( nDb>0 && zPath[nDb]!='.' ){ in findCreateFileMode()
45047 zDb[nDb] = '\0'; in findCreateFileMode()
45099 int openFlags = 0; /* Flags to pass to open() */ in unixOpen()
45100 int eType = flags&0x0FFF00; /* Type of file to open */ in unixOpen()
45103 int ctrlFlags = 0; /* UNIXFILE_* flags */ in unixOpen()
45140 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly)); in unixOpen()
45141 assert(isCreate==0 || isReadWrite); in unixOpen()
45142 assert(isExclusive==0 || isCreate); in unixOpen()
45143 assert(isDelete==0 || isCreate); in unixOpen()
45164 if( randomnessPid!=osGetpid(0) ){ in unixOpen()
45165 randomnessPid = osGetpid(0); in unixOpen()
45166 sqlite3_randomness(0,0); in unixOpen()
45168 memset(p, 0, sizeof(unixFile)); in unixOpen()
45172 assert( zName==0 ); in unixOpen()
45191 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 ); in unixOpen()
45204 assert( zName[strlen(zName)+1]==0 ); in unixOpen()
45217 if( fd<0 ){ in unixOpen()
45228 OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags)); in unixOpen()
45229 assert( !isExclusive || (openFlags & O_CREAT)!=0 ); in unixOpen()
45230 if( fd<0 ){ in unixOpen()
45237 UnixUnusedFd *pReadonly = 0; in unixOpen()
45252 if( fd<0 ){ in unixOpen()
45266 ** If openMode==0, then that means uid and gid are not set correctly in unixOpen()
45270 if( openMode && (flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL))!=0 ){ in unixOpen()
45274 assert( fd>=0 ); in unixOpen()
45290 if( zPath==0 ){ in unixOpen()
45310 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) { in unixOpen()
45313 if (0 == strncmp("exfat", fsInfo.f_fstypename, 5)) { in unixOpen()
45332 int useProxy = 0; in unixOpen()
45334 /* SQLITE_FORCE_PROXY_LOCKING==1 means force always use proxy, 0 means in unixOpen()
45337 useProxy = atoi(envforce)>0; in unixOpen()
45359 assert( zPath==0 || zPath[0]=='/' in unixOpen()
45387 || osAccess(zPath,0)!=0 in unixDelete()
45397 if( (dirSync & 1)!=0 ){ in unixDelete()
45401 if( full_fsync(fd,0,0) ){ in unixDelete()
45404 robust_close(0, fd, __LINE__); in unixDelete()
45422 ** Otherwise return 0.
45432 assert( pResOut!=0 ); in unixAccess()
45440 *pResOut = 0==osStat(zPath, &buf) && in unixAccess()
45441 (!S_ISREG(buf.st_mode) || buf.st_size>0); in unixAccess()
45443 *pResOut = osAccess(zPath, W_OK|R_OK)==0; in unixAccess()
45471 assert( nName>0 ); in appendOnePathElement()
45472 assert( zName!=0 ); in appendOnePathElement()
45473 if( zName[0]=='.' ){ in appendOnePathElement()
45477 assert( pPath->zOut[0]=='/' ); in appendOnePathElement()
45494 pPath->zOut[pPath->nUsed] = 0; in appendOnePathElement()
45496 if( osLstat(zIn, &buf)!=0 ){ in appendOnePathElement()
45508 if( got<=0 || got>=(ssize_t)sizeof(zLnk)-2 ){ in appendOnePathElement()
45512 zLnk[got] = 0; in appendOnePathElement()
45513 if( zLnk[0]=='/' ){ in appendOnePathElement()
45514 pPath->nUsed = 0; in appendOnePathElement()
45531 int i = 0; in appendAllPathElements()
45532 int j = 0; in appendAllPathElements()
45559 path.rc = 0; in unixFullPathname()
45560 path.nUsed = 0; in unixFullPathname()
45561 path.nSymlink = 0; in unixFullPathname()
45564 if( zPath[0]!='/' ){ in unixFullPathname()
45566 if( osGetcwd(zPwd, sizeof(zPwd)-2)==0 ){ in unixFullPathname()
45572 zOut[path.nUsed] = 0; in unixFullPathname()
45634 #define unixDlOpen 0
45635 #define unixDlError 0
45636 #define unixDlSym 0
45637 #define unixDlClose 0
45659 memset(zBuf, 0, nBuf); in unixRandomness()
45660 randomnessPid = osGetpid(0); in unixRandomness()
45664 fd = robust_open("/dev/urandom", O_RDONLY, 0); in unixRandomness()
45665 if( fd<0 ){ in unixRandomness()
45673 do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR ); in unixRandomness()
45674 robust_close(0, fd, __LINE__); in unixRandomness()
45691 #if !defined(HAVE_NANOSLEEP) || HAVE_NANOSLEEP+0 in unixSleep()
45698 ** -DHAVE_NANOSLEEP=0 (perhaps in conjunction with -DHAVE_USLEEP if in unixSleep()
45723 SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
45749 (void)gettimeofday(&sNow, 0); /* Cannot fail given valid arguments */ in unixCurrentTimeInt64()
45766 ** return 0. Return 1 if the time and date cannot be found.
45769 sqlite3_int64 i = 0; in unixCurrentTime()
45772 rc = unixCurrentTimeInt64(0, &i); in unixCurrentTime()
45777 # define unixCurrentTime 0
45822 ** PENDING_BYTE 0x40000000
45823 ** RESERVED_BYTE 0x40000001
45824 ** SHARED_RANGE 0x40000002 -> 0x40000200
45942 ** force proxy locking to be used for every database file opened, and 0
45987 lPath, errno, osGetpid(0))); in proxyGetLockPath()
46003 for( i=0; i<dbLen && (i+len+7)<(int)maxLen; i++){ in proxyGetLockPath()
46007 lPath[i+len]='\0'; in proxyGetLockPath()
46009 OSTRACE(("GETLOCKPATH proxy lock path=%s pid=%d\n", lPath, osGetpid(0))); in proxyGetLockPath()
46019 int start = 0; in proxyCreateLockPath()
46024 buf[0] = lockPath[0]; in proxyCreateLockPath()
46026 if( lockPath[i] == '/' && (i - start > 0) ){ in proxyCreateLockPath()
46030 buf[i]='\0'; in proxyCreateLockPath()
46036 buf, strerror(err), lockPath, osGetpid(0))); in proxyCreateLockPath()
46045 OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n",lockPath,osGetpid(0))); in proxyCreateLockPath()
46046 return 0; in proxyCreateLockPath()
46066 int terrno = 0; in proxyCreateUnixFile()
46084 if( fd<0 ){ in proxyCreateUnixFile()
46085 fd = robust_open(path, openFlags, 0); in proxyCreateUnixFile()
46087 if( fd<0 && errno==ENOENT && islockfile ){ in proxyCreateUnixFile()
46089 fd = robust_open(path, openFlags, 0); in proxyCreateUnixFile()
46093 if( fd<0 ){ in proxyCreateUnixFile()
46095 fd = robust_open(path, openFlags, 0); in proxyCreateUnixFile()
46098 if( fd<0 ){ in proxyCreateUnixFile()
46117 memset(pNew, 0, sizeof(unixFile)); in proxyCreateUnixFile()
46119 memset(&dummyVfs, 0, sizeof(dummyVfs)); in proxyCreateUnixFile()
46126 rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0); in proxyCreateUnixFile()
46140 SQLITE_API int sqlite3_hostid_num = 0;
46155 memset(pHostID, 0, PROXY_HOSTIDLEN); in proxyGetHostID()
46158 struct timespec timeout = {1, 0}; /* 1 sec timeout */ in proxyGetHostID()
46172 if( sqlite3_hostid_num != 0){ in proxyGetHostID()
46173 pHostID[0] = (char)(pHostID[0] + (char)(sqlite3_hostid_num & 0xFF)); in proxyGetHostID()
46199 size_t readLen = 0; in proxyBreakConchLock()
46200 size_t pathLen = 0; in proxyBreakConchLock()
46214 readLen = osPread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0); in proxyBreakConchLock()
46220 fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW), 0); in proxyBreakConchLock()
46221 if( fd<0 ){ in proxyBreakConchLock()
46225 if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){ in proxyBreakConchLock()
46233 rc = 0; in proxyBreakConchLock()
46241 if( fd>=0 ){ in proxyBreakConchLock()
46257 int nTries = 0; in proxyConchLock()
46260 memset(&conchModTime, 0, sizeof(conchModTime)); in proxyConchLock()
46279 unixSleep(0,500000); /* wait 0.5 sec and try the lock again*/ in proxyConchLock()
46291 int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0); in proxyConchLock()
46292 if( len<0 ){ in proxyConchLock()
46296 if( len>PROXY_PATHINDEX && tBuf[0]==(char)PROXY_CONCHVERSION){ in proxyConchLock()
46298 if( 0!=memcmp(&tBuf[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN) ){ in proxyConchLock()
46305 unixSleep(0,10000000); /* wait 10 sec and try the lock again */ in proxyConchLock()
46310 if( 0==proxyBreakConchLock(pFile, myHostID) ){ in proxyConchLock()
46334 if( pCtx->conchHeld!=0 ){ in proxyTakeConch()
46339 int pError = 0; in proxyTakeConch()
46344 int createConch = 0; in proxyTakeConch()
46345 int hostIdMatch = 0; in proxyTakeConch()
46346 int readLen = 0; in proxyTakeConch()
46347 int tryOldLockPath = 0; in proxyTakeConch()
46348 int forceNewLockPath = 0; in proxyTakeConch()
46352 osGetpid(0))); in proxyTakeConch()
46355 if( (rc&0xff)==SQLITE_IOERR ){ in proxyTakeConch()
46364 readLen = seekAndRead((unixFile*)conchFile, 0, readBuf, PROXY_MAXCONCHLEN); in proxyTakeConch()
46365 if( readLen<0 ){ in proxyTakeConch()
46371 readBuf[0]!=(char)PROXY_CONCHVERSION ){ in proxyTakeConch()
46398 lockPath[pathLen] = 0; in proxyTakeConch()
46414 if( (conchFile->openFlags&O_RDWR) == 0 ){ in proxyTakeConch()
46444 int writeSize = 0; in proxyTakeConch()
46446 writeBuffer[0] = (char)PROXY_CONCHVERSION; in proxyTakeConch()
46456 rc = unixWrite((sqlite3_file *)conchFile, writeBuffer, writeSize, 0); in proxyTakeConch()
46457 full_fsync(conchFile->h,0,0); in proxyTakeConch()
46464 if( err==0 ){ in proxyTakeConch()
46474 if( rc!=0 ){ in proxyTakeConch()
46495 if( pFile->h>=0 ){ in proxyTakeConch()
46499 fd = robust_open(pCtx->dbPath, pFile->openFlags, 0); in proxyTakeConch()
46501 if( fd>=0 ){ in proxyTakeConch()
46516 tryOldLockPath = 0; in proxyTakeConch()
46525 pCtx->lockProxyPath = sqlite3DbStrDup(0, tempLockPath); in proxyTakeConch()
46562 osGetpid(0))); in proxyReleaseConch()
46563 if( pCtx->conchHeld>0 ){ in proxyReleaseConch()
46566 pCtx->conchHeld = 0; in proxyReleaseConch()
46591 if( conchPath==0 ){ in proxyCreateConchPathname()
46597 for( i=(len-1); i>=0; i-- ){ in proxyCreateConchPathname()
46630 if( !path || path[0]=='\0' || !strcmp(path, ":auto:") || in switchLockProxyPath()
46636 pCtx->conchHeld = 0; in switchLockProxyPath()
46643 pCtx->lockProxyPath = sqlite3DbStrDup(0, path); in switchLockProxyPath()
46697 if( !path || path[0]=='\0' || !strcmp(path, ":auto:") ){ in proxyTransformUnixFile()
46704 (lockPath ? lockPath : ":auto:"), osGetpid(0))); in proxyTransformUnixFile()
46707 if( pCtx==0 ){ in proxyTransformUnixFile()
46710 memset(pCtx, 0, sizeof(*pCtx)); in proxyTransformUnixFile()
46714 rc = proxyCreateUnixFile(pCtx->conchFilePath, &pCtx->conchFile, 0); in proxyTransformUnixFile()
46715 if( rc==SQLITE_CANTOPEN && ((pFile->openFlags&O_RDWR) == 0) ){ in proxyTransformUnixFile()
46718 ** Ugh, since O_RDONLY==0x0000 we test for !O_RDWR since unixOpen asserts in proxyTransformUnixFile()
46723 int goLockless = 0; in proxyTransformUnixFile()
46738 pCtx->lockProxyPath = sqlite3DbStrDup(0, lockPath); in proxyTransformUnixFile()
46742 pCtx->dbPath = sqlite3DbStrDup(0, dbPath); in proxyTransformUnixFile()
46760 sqlite3DbFree(0, pCtx->lockProxyPath); in proxyTransformUnixFile()
46795 if( pArg==NULL || (const char *)pArg==0 ){ in proxyFileControl()
46827 assert( 0 ); /* The call assures that only valid opcodes are sent */ in proxyFileControl()
46830 /*NOTREACHED*/ assert(0); in proxyFileControl()
46852 if( pCtx->conchHeld>0 ){ in proxyCheckReservedLock()
46855 }else{ /* conchHeld < 0 is lockless */ in proxyCheckReservedLock()
46856 pResOut=0; in proxyCheckReservedLock()
46891 if( pCtx->conchHeld>0 ){ in proxyLock()
46896 /* conchHeld < 0 is lockless */ in proxyLock()
46915 if( pCtx->conchHeld>0 ){ in proxyUnlock()
46920 /* conchHeld < 0 is lockless */ in proxyUnlock()
46943 pCtx->lockProxy = 0; in proxyClose()
46954 sqlite3DbFree(0, pCtx->lockProxyPath); in proxyClose()
46956 sqlite3DbFree(0, pCtx->dbPath); in proxyClose()
47016 0, /* pNext */ \ in sqlite3_os_init()
47077 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ in sqlite3_os_init()
47080 0==strcmp(aVfs[i].zName,SQLITE_DEFAULT_UNIX_VFS)); in sqlite3_os_init()
47082 sqlite3_vfs_register(&aVfs[i], i==0); in sqlite3_os_init()
47098 ** READ-0 UNIX_SHM_BASE+3 123 in sqlite3_os_init()
47122 unixBigLock = 0; in sqlite3_os_end()
47166 #if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0
47168 compile with SQLITE_MAX_MMAP_SIZE=0."
47201 # define NTDDI_WIN8 0x06020000
47205 # define NTDDI_WINBLUE 0x06030000
47209 # define NTDDI_WINTHRESHOLD 0x06040000
47218 # define SQLITE_WIN32_GETVERSIONEX 0 /* GetVersionEx() is deprecated */
47231 # define SQLITE_WIN32_CREATEFILEMAPPINGA 0
47321 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
47361 # define FILE_FLAG_MASK (0xFF3C0000)
47365 # define FILE_ATTRIBUTE_MASK (0x0003FFF7)
47412 #if SQLITE_MAX_MMAP_SIZE>0
47428 # define winFileBusyTimeout(pDbFd) 0
47445 #define WINFILE_RDONLY 0x02 /* Connection is read only */
47446 #define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */
47447 #define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
47512 # if SQLITE_DEFAULT_CACHE_SIZE>=0
47542 # define SQLITE_WIN32_HEAP_MAX_SIZE (0)
47550 # define SQLITE_WIN32_HEAP_FLAGS (0)
47571 #define WINMEM_MAGIC1 0x42b2830b
47572 #define WINMEM_MAGIC2 0xbd4d7cf4
47613 ** 0: Operating system unknown.
47621 SQLITE_API LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0;
47623 static LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0;
47650 { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 },
47652 { "AreFileApisANSI", (SYSCALL)0, 0 },
47656 #define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent)
47660 { "CharLowerW", (SYSCALL)CharLowerW, 0 },
47662 { "CharLowerW", (SYSCALL)0, 0 },
47668 { "CharUpperW", (SYSCALL)CharUpperW, 0 },
47670 { "CharUpperW", (SYSCALL)0, 0 },
47675 { "CloseHandle", (SYSCALL)CloseHandle, 0 },
47680 { "CreateFileA", (SYSCALL)CreateFileA, 0 },
47682 { "CreateFileA", (SYSCALL)0, 0 },
47689 { "CreateFileW", (SYSCALL)CreateFileW, 0 },
47691 { "CreateFileW", (SYSCALL)0, 0 },
47698 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) && \
47700 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
47702 { "CreateFileMappingA", (SYSCALL)0, 0 },
47709 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
47710 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
47712 { "CreateFileMappingW", (SYSCALL)0, 0 },
47719 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 },
47721 { "CreateMutexW", (SYSCALL)0, 0 },
47728 { "DeleteFileA", (SYSCALL)DeleteFileA, 0 },
47730 { "DeleteFileA", (SYSCALL)0, 0 },
47736 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
47738 { "DeleteFileW", (SYSCALL)0, 0 },
47744 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
47746 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
47753 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
47755 { "FileTimeToSystemTime", (SYSCALL)0, 0 },
47761 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
47766 { "FormatMessageA", (SYSCALL)FormatMessageA, 0 },
47768 { "FormatMessageA", (SYSCALL)0, 0 },
47775 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
47777 { "FormatMessageW", (SYSCALL)0, 0 },
47784 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
47786 { "FreeLibrary", (SYSCALL)0, 0 },
47791 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
47796 { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 },
47798 { "GetDiskFreeSpaceA", (SYSCALL)0, 0 },
47805 { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 },
47807 { "GetDiskFreeSpaceW", (SYSCALL)0, 0 },
47814 { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 },
47816 { "GetFileAttributesA", (SYSCALL)0, 0 },
47822 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
47824 { "GetFileAttributesW", (SYSCALL)0, 0 },
47830 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
47832 { "GetFileAttributesExW", (SYSCALL)0, 0 },
47839 { "GetFileSize", (SYSCALL)GetFileSize, 0 },
47841 { "GetFileSize", (SYSCALL)0, 0 },
47847 { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 },
47849 { "GetFullPathNameA", (SYSCALL)0, 0 },
47856 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
47858 { "GetFullPathNameW", (SYSCALL)0, 0 },
47870 { "GetLastError", (SYSCALL)GetLastError, 0 },
47877 { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 },
47881 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
47884 { "GetProcAddressA", (SYSCALL)0, 0 },
47891 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
47893 { "GetSystemInfo", (SYSCALL)0, 0 },
47898 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
47903 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
47905 { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 },
47912 { "GetTempPathA", (SYSCALL)GetTempPathA, 0 },
47914 { "GetTempPathA", (SYSCALL)0, 0 },
47920 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
47922 { "GetTempPathW", (SYSCALL)0, 0 },
47928 { "GetTickCount", (SYSCALL)GetTickCount, 0 },
47930 { "GetTickCount", (SYSCALL)0, 0 },
47936 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
47938 { "GetVersionExA", (SYSCALL)0, 0 },
47946 { "GetVersionExW", (SYSCALL)GetVersionExW, 0 },
47948 { "GetVersionExW", (SYSCALL)0, 0 },
47954 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
47960 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
47962 { "HeapCreate", (SYSCALL)0, 0 },
47969 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
47971 { "HeapDestroy", (SYSCALL)0, 0 },
47976 { "HeapFree", (SYSCALL)HeapFree, 0 },
47980 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
47985 { "HeapSize", (SYSCALL)HeapSize, 0 },
47991 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
47993 { "HeapValidate", (SYSCALL)0, 0 },
48000 { "HeapCompact", (SYSCALL)HeapCompact, 0 },
48002 { "HeapCompact", (SYSCALL)0, 0 },
48008 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
48010 { "LoadLibraryA", (SYSCALL)0, 0 },
48017 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
48019 { "LoadLibraryW", (SYSCALL)0, 0 },
48025 { "LocalFree", (SYSCALL)LocalFree, 0 },
48027 { "LocalFree", (SYSCALL)0, 0 },
48033 { "LockFile", (SYSCALL)LockFile, 0 },
48035 { "LockFile", (SYSCALL)0, 0 },
48044 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
48046 { "LockFileEx", (SYSCALL)0, 0 },
48055 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
48056 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
48058 { "MapViewOfFile", (SYSCALL)0, 0 },
48064 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
48069 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
48074 { "ReadFile", (SYSCALL)ReadFile, 0 },
48079 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
48084 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
48086 { "SetFilePointer", (SYSCALL)0, 0 },
48093 { "Sleep", (SYSCALL)Sleep, 0 },
48095 { "Sleep", (SYSCALL)0, 0 },
48100 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
48106 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
48108 { "UnlockFile", (SYSCALL)0, 0 },
48117 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
48119 { "UnlockFileEx", (SYSCALL)0, 0 },
48125 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
48126 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
48128 { "UnmapViewOfFile", (SYSCALL)0, 0 },
48133 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
48138 { "WriteFile", (SYSCALL)WriteFile, 0 },
48144 { "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
48146 { "CreateEventExW", (SYSCALL)0, 0 },
48158 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
48164 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
48166 { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
48173 { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
48175 { "SetFilePointerEx", (SYSCALL)0, 0 },
48182 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
48184 { "GetFileInformationByHandleEx", (SYSCALL)0, 0 },
48190 #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
48191 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
48193 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
48200 { "CreateFile2", (SYSCALL)CreateFile2, 0 },
48202 { "CreateFile2", (SYSCALL)0, 0 },
48209 { "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
48211 { "LoadPackagedLibrary", (SYSCALL)0, 0 },
48218 { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
48220 { "GetTickCount64", (SYSCALL)0, 0 },
48226 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
48228 { "GetNativeSystemInfo", (SYSCALL)0, 0 },
48235 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
48237 { "OutputDebugStringA", (SYSCALL)0, 0 },
48243 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
48245 { "OutputDebugStringW", (SYSCALL)0, 0 },
48250 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
48254 #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
48255 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
48257 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
48269 { "InterlockedCompareExchange", (SYSCALL)0, 0 },
48273 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
48280 { "UuidCreate", (SYSCALL)UuidCreate, 0 },
48282 { "UuidCreate", (SYSCALL)0, 0 },
48288 { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
48290 { "UuidCreateSequential", (SYSCALL)0, 0 },
48296 #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
48297 { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
48299 { "FlushViewOfFile", (SYSCALL)0, 0 },
48313 { "CreateEvent", (SYSCALL)CreateEvent, 0 },
48315 { "CreateEvent", (SYSCALL)0, 0 },
48332 { "CancelIo", (SYSCALL)CancelIo, 0 },
48334 { "CancelIo", (SYSCALL)0, 0 },
48340 { "GetModuleHandleW", (SYSCALL)GetModuleHandleW, 0 },
48342 { "GetModuleHandleW", (SYSCALL)0, 0 },
48348 { "getenv", (SYSCALL)getenv, 0 },
48350 { "getenv", (SYSCALL)0, 0 },
48356 { "getcwd", (SYSCALL)getcwd, 0 },
48358 { "getcwd", (SYSCALL)0, 0 },
48364 { "readlink", (SYSCALL)readlink, 0 },
48366 { "readlink", (SYSCALL)0, 0 },
48372 { "lstat", (SYSCALL)lstat, 0 },
48374 { "lstat", (SYSCALL)0, 0 },
48380 { "__errno", (SYSCALL)__errno, 0 },
48382 { "__errno", (SYSCALL)0, 0 },
48388 { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
48390 { "cygwin_conv_path", (SYSCALL)0, 0 },
48413 if( zName==0 ){ in winSetSystemCall()
48418 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ in winSetSystemCall()
48427 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ in winSetSystemCall()
48428 if( strcmp(zName, aSyscall[i].zName)==0 ){ in winSetSystemCall()
48429 if( aSyscall[i].pDefault==0 ){ in winSetSystemCall()
48433 if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault; in winSetSystemCall()
48454 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ in winGetSystemCall()
48455 if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent; in winGetSystemCall()
48457 return 0; in winGetSystemCall()
48471 for(i=0; i<ArraySize(aSyscall)-1; i++){ in winNextSystemCall()
48472 if( strcmp(zName, aSyscall[i].zName)==0 ) break; in winNextSystemCall()
48476 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName; in winNextSystemCall()
48478 return 0; in winNextSystemCall()
48491 UINT nLargest = 0; in sqlite3_win32_compact_heap()
48496 assert( hHeap!=0 ); in sqlite3_win32_compact_heap()
48502 if( (nLargest=osHeapCompact(hHeap, SQLITE_WIN32_HEAP_FLAGS))==0 ){ in sqlite3_win32_compact_heap()
48538 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){ in sqlite3_win32_reset_heap()
48548 assert( sqlite3_memory_used()==0 ); in sqlite3_win32_reset_heap()
48552 assert( sqlite3_memory_used()==0 ); in sqlite3_win32_reset_heap()
48556 assert( rc!=SQLITE_OK || sqlite3_memory_used()==0 ); in sqlite3_win32_reset_heap()
48579 assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE ); in sqlite3_win32_write_debug()
48587 if( nMin>0 ){ in sqlite3_win32_write_debug()
48588 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); in sqlite3_win32_write_debug()
48595 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); in sqlite3_win32_write_debug()
48597 osAreFileApisANSI() ? CP_ACP : CP_OEMCP, 0, zBuf, in sqlite3_win32_write_debug()
48598 nMin, (LPWSTR)zDbgBuf, SQLITE_WIN32_DBG_BUF_SIZE/sizeof(WCHAR))<=0 ){ in sqlite3_win32_write_debug()
48603 if( nMin>0 ){ in sqlite3_win32_write_debug()
48604 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); in sqlite3_win32_write_debug()
48635 #if SQLITE_MAX_WORKER_THREADS>0 && !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
48636 SQLITE_THREADSAFE>0
48662 # define osIsNT() (0)
48679 if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){ in sqlite3_win32_is_nt()
48685 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0); in sqlite3_win32_is_nt()
48691 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0); in sqlite3_win32_is_nt()
48697 || osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 in sqlite3_win32_is_nt()
48718 assert( hHeap!=0 ); in winMemMalloc()
48723 assert( nBytes>=0 ); in winMemMalloc()
48740 assert( hHeap!=0 ); in winMemFree()
48761 assert( hHeap!=0 ); in winMemRealloc()
48766 assert( nBytes>=0 ); in winMemRealloc()
48789 assert( hHeap!=0 ); in winMemSize()
48794 if( !p ) return 0; in winMemSize()
48799 return 0; in winMemSize()
48825 if( dwMaximumSize==0 ){ in winMemInit()
48852 assert( pWinMemData->hHeap!=0 ); in winMemInit()
48923 nChar = osMultiByteToWideChar(CP_UTF8, 0, zText, -1, NULL, 0); in winUtf8ToUnicode()
48924 if( nChar==0 ){ in winUtf8ToUnicode()
48925 return 0; in winUtf8ToUnicode()
48928 if( zWideText==0 ){ in winUtf8ToUnicode()
48929 return 0; in winUtf8ToUnicode()
48931 nChar = osMultiByteToWideChar(CP_UTF8, 0, zText, -1, zWideText, in winUtf8ToUnicode()
48933 if( nChar==0 ){ in winUtf8ToUnicode()
48935 zWideText = 0; in winUtf8ToUnicode()
48950 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideText, -1, 0, 0, 0, 0); in winUnicodeToUtf8()
48951 if( nByte == 0 ){ in winUnicodeToUtf8()
48952 return 0; in winUnicodeToUtf8()
48955 if( zText==0 ){ in winUnicodeToUtf8()
48956 return 0; in winUnicodeToUtf8()
48958 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideText, -1, zText, nByte, in winUnicodeToUtf8()
48959 0, 0); in winUnicodeToUtf8()
48960 if( nByte == 0 ){ in winUnicodeToUtf8()
48962 zText = 0; in winUnicodeToUtf8()
48978 nWideChar = osMultiByteToWideChar(codepage, 0, zText, -1, NULL, in winMbcsToUnicode()
48979 0); in winMbcsToUnicode()
48980 if( nWideChar==0 ){ in winMbcsToUnicode()
48981 return 0; in winMbcsToUnicode()
48984 if( zMbcsText==0 ){ in winMbcsToUnicode()
48985 return 0; in winMbcsToUnicode()
48987 nWideChar = osMultiByteToWideChar(codepage, 0, zText, -1, zMbcsText, in winMbcsToUnicode()
48989 if( nWideChar==0 ){ in winMbcsToUnicode()
48991 zMbcsText = 0; in winMbcsToUnicode()
49008 nByte = osWideCharToMultiByte(codepage, 0, zWideText, -1, 0, 0, 0, 0); in winUnicodeToMbcs()
49009 if( nByte == 0 ){ in winUnicodeToMbcs()
49010 return 0; in winUnicodeToMbcs()
49013 if( zText==0 ){ in winUnicodeToMbcs()
49014 return 0; in winUnicodeToMbcs()
49016 nByte = osWideCharToMultiByte(codepage, 0, zWideText, -1, zText, in winUnicodeToMbcs()
49017 nByte, 0, 0); in winUnicodeToMbcs()
49018 if( nByte == 0 ){ in winUnicodeToMbcs()
49020 zText = 0; in winUnicodeToMbcs()
49036 if( zTmpWide==0 ){ in winMbcsToUtf8()
49037 return 0; in winMbcsToUtf8()
49055 if( zTmpWide==0 ){ in winUtf8ToMbcs()
49056 return 0; in winUtf8ToMbcs()
49070 return 0; in sqlite3_win32_utf8_to_unicode()
49074 if( sqlite3_initialize() ) return 0; in sqlite3_win32_utf8_to_unicode()
49086 return 0; in sqlite3_win32_unicode_to_utf8()
49090 if( sqlite3_initialize() ) return 0; in sqlite3_win32_unicode_to_utf8()
49103 return 0; in sqlite3_win32_mbcs_to_utf8()
49107 if( sqlite3_initialize() ) return 0; in sqlite3_win32_mbcs_to_utf8()
49120 return 0; in sqlite3_win32_mbcs_to_utf8_v2()
49124 if( sqlite3_initialize() ) return 0; in sqlite3_win32_mbcs_to_utf8_v2()
49136 return 0; in sqlite3_win32_utf8_to_mbcs()
49140 if( sqlite3_initialize() ) return 0; in sqlite3_win32_utf8_to_mbcs()
49152 return 0; in sqlite3_win32_utf8_to_mbcs_v2()
49156 if( sqlite3_initialize() ) return 0; in sqlite3_win32_utf8_to_mbcs_v2()
49169 char **ppDirectory = 0; in sqlite3_win32_set_directory8()
49186 char *zCopy = 0; in sqlite3_win32_set_directory8()
49187 if( zValue && zValue[0] ){ in sqlite3_win32_set_directory8()
49189 if ( zCopy==0 ){ in sqlite3_win32_set_directory8()
49214 char *zUtf8 = 0; in sqlite3_win32_set_directory16()
49217 if( zUtf8==0 ) return SQLITE_NOMEM_BKPT; in sqlite3_win32_set_directory16()
49245 /* FormatMessage returns 0 on failure. Otherwise it in winGetLastErrorMsg()
49249 DWORD dwLen = 0; in winGetLastErrorMsg()
49250 char *zOut = 0; in winGetLastErrorMsg()
49259 0, in winGetLastErrorMsg()
49262 0); in winGetLastErrorMsg()
49270 0, in winGetLastErrorMsg()
49272 0, in winGetLastErrorMsg()
49273 0); in winGetLastErrorMsg()
49275 if( dwLen > 0 ){ in winGetLastErrorMsg()
49294 0, in winGetLastErrorMsg()
49296 0, in winGetLastErrorMsg()
49297 0); in winGetLastErrorMsg()
49298 if( dwLen > 0 ){ in winGetLastErrorMsg()
49308 if( 0 == dwLen ){ in winGetLastErrorMsg()
49309 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%lx (%lu)", lastErrno, lastErrno); in winGetLastErrorMsg()
49316 return 0; in winGetLastErrorMsg()
49345 zMsg[0] = 0; in winLogErrorAtLine()
49348 if( zPath==0 ) zPath = ""; in winLogErrorAtLine()
49349 for(i=0; zMsg[i] && zMsg[i]!='\r' && zMsg[i]!='\n'; i++){} in winLogErrorAtLine()
49350 zMsg[i] = 0; in winLogErrorAtLine()
49411 return 0; in winRetryIoerr()
49428 return 0; in winRetryIoerr()
49462 uTm.dwLowDateTime = (DWORD)(t64 & 0xFFFFFFFF); in localtime()
49509 if( zName==0 ){ in winceCreateLock()
49515 memset(&pFile->local, 0, sizeof(pFile->local)); in winceCreateLock()
49542 PAGE_READWRITE, 0, sizeof(winceLock), in winceCreateLock()
49557 FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock)); in winceCreateLock()
49585 memset(pFile->shared, 0, sizeof(winceLock)); in winceCreateLock()
49648 if (pFile->shared->nReaders == 0 && pFile->shared->bExclusive == 0){ in winceLockFile()
49658 if (pFile->shared->bExclusive == 0){ in winceLockFile()
49671 if (pFile->shared->bPending == 0) { in winceLockFile()
49681 if (pFile->shared->bReserved == 0) { in winceLockFile()
49726 if (pFile->local.nReaders == 0) in winceUnlockFile()
49782 memset(&ovlp, 0, sizeof(OVERLAPPED)); in winLockFile()
49785 return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp); in winLockFile()
49802 ** some other process holds the lock, SQLITE_BUSY is returned if nMs==0, or
49812 DWORD flags = LOCKFILE_FAIL_IMMEDIATELY | (bExcl?LOCKFILE_EXCLUSIVE_LOCK:0); in winHandleLockTimeout()
49817 ret = winLockFile(&hFile, flags, offset, 0, nByte, 0); in winHandleLockTimeout()
49820 memset(&ovlp, 0, sizeof(OVERLAPPED)); in winHandleLockTimeout()
49824 if( nMs!=0 ){ in winHandleLockTimeout()
49833 ret = osLockFileEx(hFile, flags, 0, nByte, 0, &ovlp); in winHandleLockTimeout()
49841 ** If nMs is 0, then LOCKFILE_FAIL_IMMEDIATELY was set in the flags in winHandleLockTimeout()
49849 DWORD nDelay = (nMs==0 ? INFINITE : nMs); in winHandleLockTimeout()
49898 memset(&ovlp, 0, sizeof(OVERLAPPED)); in winUnlockFile()
49901 return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp); in winUnlockFile()
49915 BOOL ret = winUnlockFile(&h, iOff, 0, nByte, 0); in winHandleUnlock()
49945 upperBits = (LONG)((iOffset>>32) & 0x7fffffff); in winHandleSeek()
49946 lowerBits = (LONG)(iOffset & 0xffffffff); in winHandleSeek()
49968 bRet = osSetFilePointerEx(h, x, 0, FILE_BEGIN); in winHandleSeek()
49981 ** argument to offset iOffset within the file. If successful, return 0.
49996 #if SQLITE_MAX_MMAP_SIZE>0
50014 int rc, cnt = 0; in winClose()
50017 assert( id!=0 ); in winClose()
50019 assert( pFile->pShm==0 ); in winClose()
50025 #if SQLITE_MAX_MMAP_SIZE>0 in winClose()
50031 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ in winClose()
50032 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) ); in winClose()
50042 int cnt = 0; in winClose()
50044 osDeleteFileW(pFile->zDeleteOnClose)==0 in winClose()
50045 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff in winClose()
50080 int nRetry = 0; /* Number of retrys */
50082 assert( id!=0 );
50083 assert( amt>0 );
50084 assert( offset>=0 );
50090 #if SQLITE_MAX_MMAP_SIZE>0
50115 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
50117 memset(&overlapped, 0, sizeof(OVERLAPPED));
50118 overlapped.Offset = (LONG)(offset & 0xffffffff);
50119 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
50134 memset(&((char*)pBuf)[nRead], 0, amt-nRead);
50155 int rc = 0; /* True if error has occurred, else false */
50157 int nRetry = 0; /* Number of retries */
50159 assert( amt>0 );
50168 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0
50189 if( rc==0 ){
50202 memset(&overlapped, 0, sizeof(OVERLAPPED));
50203 overlapped.Offset = (LONG)(offset & 0xffffffff);
50204 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
50207 while( nRem>0 ){
50209 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
50216 assert( nWrite==0 || nWrite<=(DWORD)nRem );
50217 if( nWrite==0 || nWrite>(DWORD)nRem ){
50223 overlapped.Offset = (LONG)(offset & 0xffffffff);
50224 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
50229 if( nRem>0 ){
50262 if( 0==osSetEndOfFile(h) ){
50286 DWORD upperBits = 0;
50287 DWORD lowerBits = 0;
50316 #if SQLITE_MAX_MMAP_SIZE>0
50318 if( pFile->nFetchOut>0 ){
50350 if( pFile->szChunk>0 ){
50354 #if SQLITE_MAX_MMAP_SIZE>0
50358 oldMmapSize = 0;
50367 }else if( 0==osSetEndOfFile(pFile->h) &&
50374 #if SQLITE_MAX_MMAP_SIZE>0
50375 if( rc==SQLITE_OK && oldMmapSize>0 ){
50394 SQLITE_API int sqlite3_sync_count = 0;
50395 SQLITE_API int sqlite3_fullsync_count = 0;
50421 assert((flags&0x0F)==SQLITE_SYNC_NORMAL
50422 || (flags&0x0F)==SQLITE_SYNC_FULL
50437 if( (flags&0x0F)==SQLITE_SYNC_FULL ){
50451 #if SQLITE_MAX_MMAP_SIZE>0
50453 if( osFlushViewOfFile(pFile->pMapRegion, 0) ){
50490 assert( id!=0 );
50491 assert( pSize!=0 );
50566 DWORD mask = ~(bBlock ? LOCKFILE_FAIL_IMMEDIATELY : 0);
50574 res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
50576 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS&mask, SHARED_FIRST, 0,
50577 SHARED_SIZE, 0);
50584 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
50586 SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
50589 if( res == 0 ){
50605 res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
50609 res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
50612 if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
50643 ** erases all locks at once and returns us immediately to locking level 0.
50645 ** must go straight to locking level 0.
50651 int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */
50655 assert( id!=0 );
50670 if( (pFile->ctrlFlags & WINFILE_RDONLY)!=0 && locktype>=RESERVED_LOCK ){
50697 while( cnt>0 ){
50704 res = winLockFile(&pFile->h, flags, PENDING_BYTE, 0, 1, 0);
50722 if( cnt>0 ) sqlite3_win32_sleep(1);
50734 res = winGetReadLock(pFile, 0);
50747 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
50759 gotPendingLock = 0;
50767 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
50768 SHARED_SIZE, 0);
50773 winGetReadLock(pFile, 0);
50781 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
50813 assert( id!=0 );
50818 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0);
50820 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
50846 assert( pFile!=0 );
50852 winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
50853 if( locktype==SHARED_LOCK && !winGetReadLock(pFile, 0) ){
50861 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
50867 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
50915 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
50917 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
50920 if( *pArg<0 ){
50921 *pArg = (pFile->ctrlFlags & mask)!=0;
50922 }else if( (*pArg)==0 ){
50958 if( pFile->szChunk>0 ){
50966 SimulateIOErrorBenign(0);
50992 if( a[0]>0 ){
50993 winIoerrRetry = a[0];
50995 a[0] = winIoerrRetry;
50997 if( a[1]>0 ){
51028 char *zTFile = 0;
51036 #if SQLITE_MAX_MMAP_SIZE>0
51047 if( newLimit>0 && sizeof(SIZE_T)<8 ){
51048 newLimit = (newLimit & 0x7FFFFFFF);
51052 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
51054 if( pFile->mmapSize>0 ){
51069 pFile->iBusyTimeout = (iNew < 0) ? INFINITE : (DWORD)iNew;
51111 ((p->ctrlFlags & WINFILE_PSOW)?SQLITE_IOCAP_POWERSAFE_OVERWRITE:0);
51137 static sqlite3_mutex *winBigLock = 0;
51167 ** Either winShmNode.mutex must be held or winShmNode.nRef==0 and
51205 static winShmNode *winShmNodeList = 0;
51234 ** Purge the winShmNodeList list of all entries with winShmNode.nRef==0.
51246 while( (p = *pp)!=0 ){
51247 if( p->nRef==0 ){
51250 for(i=0; i<p->nRegion; i++){
51264 winDelete(pVfs, p->zFilename, 0);
51266 SimulateIOErrorBenign(0);
51287 rc = winHandleLockTimeout(h, WIN_SHM_DMS, 1, 1, 0);
51295 rc = winHandleTruncate(h, 0);
51299 winUnlockFile(&h, WIN_SHM_DMS, 0, 1, 0);
51300 }else if( (rc & 0xFF)==SQLITE_BUSY ){
51306 rc = winHandleLockTimeout(h, WIN_SHM_DMS, 1, 0, nMs);
51308 pShmNode->isUnlocked = 0;
51336 void *zConverted = 0;
51348 zFilename, 0, 0);
51349 if( nByte>0 ){
51351 if ( zConverted==0 ){
51358 zWideFilename+4, nByte)==0 ){
51374 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
51375 if( nChar==0 ){
51376 return 0;
51379 if( zWideFilename==0 ){
51380 return 0;
51382 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1,
51384 if( nChar==0 ){
51386 zWideFilename = 0;
51394 && winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1])
51425 void *zConverted = 0;
51432 const DWORD flag_overlapped = 0;
51437 if( zConverted==0 ){
51456 memset(&extendedParameters, 0, sizeof(extendedParameters));
51462 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)),/* dwDesiredAccess */
51469 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
51482 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
51493 if( bReadonly==0 ){
51514 winShmNode *pShmNode = 0; /* The underlying mmapped file */
51519 assert( pDbFd->pShm==0 ); /* Not previously opened */
51524 if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT;
51527 if( pNew==0 ){
51540 p->bReadonly = sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0);
51549 if( sqlite3StrICmp(pShmNode->zFilename, pNew->zFilename)==0 ) break;
51551 if( pShmNode==0 ){
51557 if( pShmNode->mutex==0 ) rc = SQLITE_IOERR_NOMEM_BKPT;
51573 pNew = 0;
51596 assert( rc!=SQLITE_OK || pShmNode->isUnlocked==0 || pShmNode->nRegion==0 );
51616 if( p==0 ) return SQLITE_OK;
51624 /* If pShmNode->nRef has reached 0, then close the underlying
51626 assert( pShmNode->nRef>0 );
51628 if( pShmNode->nRef==0 ){
51635 pDbFd->pShm = 0;
51654 if( p==0 ) return SQLITE_IOERR_SHMLOCK;
51656 if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
51658 assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
51664 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
51671 ** 3. Write lock (ofst==0).
51681 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
51682 (ofst!=2 || lockMask==0)
51683 && (ofst!=1 || lockMask==0 || lockMask==2)
51684 && (ofst!=0 || lockMask<3)
51699 || 0==(p->exclMask & mask)
51702 || (flags==(SQLITE_SHM_SHARED|SQLITE_SHM_LOCK) && 0==(p->sharedMask & mask))
51709 assert( (p->exclMask & p->sharedMask)==0 );
51721 int bExcl = ((flags & SQLITE_SHM_EXCLUSIVE) ? 1 : 0);
51767 ** Otherwise, if the isWrite parameter is 0 and the requested shared-memory
51796 assert( pShm!=0 );
51803 assert( pShmNode->nRegion==0 );
51808 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
51843 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
51858 void *pMap = 0; /* Mapped memory region */
51863 hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL);
51865 hMap = osCreateFileMappingA(hShared, NULL, protect, 0, nByte, NULL);
51880 0, iOffset - iOffsetShift, szRegion + iOffsetShift
51908 *pp = 0;
51918 # define winShmMap 0
51919 # define winShmLock 0
51920 # define winShmBarrier 0
51921 # define winShmUnmap 0
51927 #if SQLITE_MAX_MMAP_SIZE>0
51929 assert( pFile!=0 );
51943 pFile->pMapRegion = 0;
51944 pFile->mmapSize = 0;
51981 assert( nMap>=0 || pFd->nFetchOut==0 );
51985 if( pFd->nFetchOut>0 ) return SQLITE_OK;
51987 if( nMap<0 ){
52000 if( nMap==0 && pFd->mmapSize>0 ){
52004 void *pNew = 0;
52010 if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){
52019 (DWORD)((nMap>>32) & 0xffffffff),
52020 (DWORD)(nMap & 0xffffffff), NULL);
52023 (DWORD)((nMap>>32) & 0xffffffff),
52024 (DWORD)(nMap & 0xffffffff), NULL);
52035 assert( (nMap % winSysInfo.dwPageSize)==0 );
52036 assert( sizeof(SIZE_T)==sizeof(sqlite3_int64) || nMap<=0xffffffff );
52038 pNew = osMapViewOfFileFromApp(pFd->hMap, flags, 0, (SIZE_T)nMap);
52040 pNew = osMapViewOfFile(pFd->hMap, flags, 0, 0, (SIZE_T)nMap);
52061 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
52068 ** Or, if one cannot but no error occurs, set *pp to 0 and return SQLITE_OK.
52076 #if SQLITE_MAX_MMAP_SIZE>0
52079 *pp = 0;
52084 #if SQLITE_MAX_MMAP_SIZE>0
52085 if( pFd->mmapSizeMax>0 ){
52091 if( pFd->pMapRegion==0 ){
52100 assert( pFd->pMapRegion!=0 );
52123 #if SQLITE_MAX_MMAP_SIZE>0
52126 /* If p==0 (unmap the entire file) then there must be no outstanding
52127 ** xFetch references. Or, if p!=0 (meaning it is an xFetch reference),
52129 assert( (p==0)==(pFd->nFetchOut==0) );
52131 /* If p!=0, it must match the iOff value. */
52132 assert( p==0 || p==&((u8 *)pFd->pMapRegion)[iOff] );
52147 assert( pFd->nFetchOut>=0 );
52215 0, /* pAppData */
52216 0 /* bNoLock */
52221 0, /* pAppData */
52240 if( nLen>0 ){
52252 zBuf[nLen+1] = '\0';
52257 return 0;
52268 if( sqlite3_temp_directory!=0 ) return 1;
52270 return 0;
52310 assert( nDir>0 );
52313 if( nDirLen>0 ){
52321 return winLogError(SQLITE_ERROR, 0, "winGetTempname1", 0);
52331 0, /* getenv("SQLITE_TMPDIR") */
52332 0, /* getenv("TMPDIR") */
52333 0, /* getenv("TMP") */
52334 0, /* getenv("TEMP") */
52335 0, /* getenv("USERPROFILE") */
52340 0 /* List terminator */
52343 const char *zDir = 0;
52345 if( !azDirs[0] ) azDirs[0] = osGetenv("SQLITE_TMPDIR");
52350 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
52352 if( zDir==0 ) continue;
52385 if( osGetTempPathW(nMax, zWidePath)==0 ){
52390 "winGetTempname2", 0);
52413 if( osGetTempPathA(nMax, zMbcsPath)==0 ){
52417 "winGetTempname3", 0);
52440 return winLogError(SQLITE_ERROR, 0, "winGetTempname4", 0);
52447 ** "<temporary_directory>/etilqs_XXXXXXXXXXXXXXX\0\0"
52458 return winLogError(SQLITE_ERROR, 0, "winGetTempname5", 0);
52466 for(i=0; i<15; i++, j++){
52467 zBuf[j] += pid & 0xff;
52471 zBuf[j] = 0;
52472 zBuf[j+1] = 0;
52486 int rc = 0;
52490 int cnt = 0;
52492 memset(&sAttrData, 0, sizeof(sAttrData));
52497 return 0; /* Invalid name? */
52500 #if SQLITE_OS_WINCE==0 && defined(SQLITE_WIN32_HAS_ANSI)
52520 #define NORETRY 0x4000
52533 DWORD lastErrno = 0;
52537 DWORD dwFlagsAndAttributes = 0;
52539 int isTemp = 0;
52545 int cnt = 0;
52546 int isRO = 0; /* file is known to be accessible readonly */
52551 char *zTmpname = 0; /* For temporary filename, if necessary. */
52555 int eType = flags&0x0FFF00; /* Type of file to open */
52582 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
52583 assert(isCreate==0 || isReadWrite);
52584 assert(isExclusive==0 || isCreate);
52585 assert(isDelete==0 || isCreate);
52601 assert( pFile!=0 );
52602 memset(pFile, 0, sizeof(winFile));
52630 zUtf8Name[sqlite3Strlen30(zUtf8Name)+1]==0 );
52634 if( zConverted==0 ){
52669 if( 0==sqlite3_uri_boolean(zName, "exclusive", 0) ){
52672 dwShareMode = 0;
52787 *pOutFlags : 0, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
52826 #if SQLITE_MAX_MMAP_SIZE>0
52828 pFile->pMapRegion = 0;
52829 pFile->mmapSize = 0;
52854 int cnt = 0;
52857 DWORD lastErrno = 0;
52866 if( zConverted==0 ){
52874 memset(&sAttrData, 0, sizeof(sAttrData));
52964 int rc = 0;
52965 DWORD lastErrno = 0;
52967 int noRetry = 0; /* Do not use winRetryIoerr() */
52970 if( (flags & NORETRY)!=0 ){
52979 if( zFilename==0 ){
52980 *pResOut = 0;
52987 if( zConverted==0 ){
52992 int cnt = 0;
52994 memset(&sAttrData, 0, sizeof(sAttrData));
53006 && sAttrData.nFileSizeHigh==0
53007 && sAttrData.nFileSizeLow==0 ){
53036 (attr & FILE_ATTRIBUTE_READONLY)==0;
53054 return ( zPathname[0]=='\\' && zPathname[1]=='\\'
53065 return ( sqlite3Isalpha(zPathname[0]) && zPathname[1]==':' );
53085 if ( winIsDirSep(zPathname[0]) ){
53118 ** The original filename is in z[0..]. If the path is shortened,
53119 ** no-longer used bytes will be written by '\0'.
53123 for(i=j=0; z[i]; ++i){
53132 if( !z[i+1] || (winIsDirSep(z[i+1]) && (i!=0)) ){
53140 while(j<i) z[j++] = '\0';
53151 int iOff = 0;
53152 if( zPath[0]!='/' ){
53153 if( osGetcwd(zOut, nOut-2)==0 ){
53162 zOut[iOff] = '\0';
53190 if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1)
53199 zFull[nFull-1] = '\0';
53204 char *zDel = 0;
53212 int bLink = 0;
53214 if( osLstat(zIn, &buf)!=0 ){
53224 if( zDel==0 ){
53226 if( zDel==0 ) rc = SQLITE_NOMEM;
53236 if( zDel[0]!='/' ){
53238 for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
53247 zDel[nByte] = '\0';
53255 assert( rc!=SQLITE_OK || zIn!=zFull || zIn[0]=='/' );
53259 if( bLink==0 ) break;
53310 if( zConverted==0 ){
53315 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0);
53316 if( nByte==0 ){
53322 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
53323 if( zTemp==0 ){
53327 nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
53328 if( nByte==0 ){
53341 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0);
53342 if( nByte==0 ){
53347 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) );
53348 if( zTemp==0 ){
53352 nByte = osGetFullPathNameA((char*)zConverted, nByte+3, zTemp, 0);
53353 if( nByte==0 ){
53416 if( zConverted==0 ){
53417 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
53418 return 0;
53422 h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0);
53454 #define winDlOpen 0
53455 #define winDlError 0
53456 #define winDlSym 0
53457 #define winDlClose 0
53473 for(j=0, k=p->i; j<sz; j++){
53475 if( k>=p->na ) k = 0;
53488 memset(zBuf, 0, nBuf);
53493 memset(zBuf, 0, nBuf);
53496 e.nXor = 0;
53497 e.i = 0;
53526 memset(&id, 0, sizeof(UUID));
53529 memset(&id, 0, sizeof(UUID));
53554 SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
53608 ** return 0. Return 1 if the time and date cannot be found.
53642 ** assert(zBuf[0]=='\0');
53643 ** return 0;
53653 if( nBuf>0 ) winGetLastErrorMsg(e, nBuf, zBuf);
53665 0, /* pNext */
53690 0, /* pNext */
53715 0, /* pNext */
53740 0, /* pNext */
53767 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
53773 assert( winSysInfo.dwAllocationGranularity>0 );
53774 assert( winSysInfo.dwPageSize>0 );
53779 sqlite3_vfs_register(&winLongPathVfs, 0);
53782 sqlite3_vfs_register(&winNolockVfs, 0);
53785 sqlite3_vfs_register(&winLongPathNolockVfs, 0);
53804 winBigLock = 0;
53855 ** Shared memdb objects have .zFName!=0 and .pMutex!=0. They are created
53892 int nWrLock; /* Number of writers. (Always 0 or 1) */
53952 0, /* szOsFile (set when registered) */
53954 0, /* pNext */
53956 0, /* pAppData (set when registered) */
53958 0, /* memdbDelete, */ /* xDelete */
53967 0, /* memdbCurrentTime, */ /* xCurrentTime */
53970 0, /* xSetSystemCall */
53971 0, /* xGetSystemCall */
53972 0, /* xNextSystemCall */
53985 0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */
53987 0, /* memdbSectorSize,*/ /* xSectorSize */
53989 0, /* xShmMap */
53990 0, /* xShmLock */
53991 0, /* xShmBarrier */
53992 0, /* xShmUnmap */
54000 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE==0
54031 for(i=0; ALWAYS(i<memdb_g.nMemStore); i++){
54036 if( memdb_g.nMemStore==0 ){
54038 memdb_g.apMemStore = 0;
54049 if( p->nRef<=0 ){
54074 memset(zBuf, 0, iAmt);
54089 if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || NEVER(p->nMmap>0) ){
54098 if( pNew==0 ) return SQLITE_IOERR_NOMEM;
54129 if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz);
54188 assert( p->nWrLock==0 || p->nWrLock==1 );
54198 if( p->nWrLock>0 ){
54210 if( p->nWrLock>0 ){
54262 #if 0
54268 *pResOut = 0;
54288 if( iLimit<0 ){
54302 #if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */
54331 if( iOfst+iAmt>p->sz || (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)!=0 ){
54332 *pp = 0;
54363 MemStore *p = 0;
54367 memset(pFile, 0, sizeof(*pFile));
54369 if( szName>1 && (zName[0]=='/' || zName[0]=='\\') ){
54375 for(i=0; i<memdb_g.nMemStore; i++){
54376 if( strcmp(memdb_g.apMemStore[i]->zFName,zName)==0 ){
54381 if( p==0 ){
54384 if( p==0 ){
54389 sizeof(apNew[0])*(1+(i64)memdb_g.nMemStore) );
54390 if( apNew==0 ){
54397 memset(p, 0, sizeof(*p));
54403 if( p->pMutex==0 ){
54418 if( p==0 ){
54421 memset(p, 0, sizeof(*p));
54426 if( pOutFlags!=0 ){
54434 #if 0 /* Only used to delete rollback journals, super-journals, and WAL
54461 *pResOut = 0;
54527 #if 0 /* Never used. Modern cores only call xCurrentTimeInt64() */
54548 MemFile *p = 0;
54551 if( rc ) return 0;
54552 if( p->base.pMethods!=&memdb_io_methods ) return 0;
54555 if( pStore->zFName!=0 ) p = 0;
54573 int szPage = 0;
54574 sqlite3_stmt *pStmt = 0;
54582 return 0;
54586 if( zSchema==0 ) zSchema = db->aDb[0].zDbSName;
54590 if( iDb<0 ) return 0;
54593 assert( pStore->pMutex==0 );
54604 if( pBt==0 ) return 0;
54607 rc = zSql ? sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) : SQLITE_NOMEM;
54609 if( rc ) return 0;
54612 pOut = 0;
54614 sz = sqlite3_column_int64(pStmt, 0)*szPage;
54615 if( sz==0 ){
54617 sqlite3_exec(db, "BEGIN IMMEDIATE; COMMIT;", 0, 0, 0);
54620 sz = sqlite3_column_int64(pStmt, 0)*szPage;
54625 pOut = 0;
54629 int nPage = sqlite3_column_int(pStmt, 0);
54633 DbPage *pPage = 0;
54635 rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pPage, 0);
54639 memset(pTo, 0, szPage);
54662 sqlite3_stmt *pStmt = 0;
54670 if( szDb<0 ) return SQLITE_MISUSE_BKPT;
54671 if( szBuf<0 ) return SQLITE_MISUSE_BKPT;
54675 if( zSchema==0 ) zSchema = db->aDb[0].zDbSName;
54678 if( iDb<2 && iDb!=0 ){
54683 if( zSql==0 ){
54686 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
54693 db->init.reopenMemdb = 0;
54699 if( p==0 ){
54704 pData = 0;
54717 if( pData && (mFlags & SQLITE_DESERIALIZE_FREEONCLOSE)!=0 ){
54736 sqlite3_vfs *pLower = sqlite3_vfs_find(0);
54738 if( NEVER(pLower==0) ) return SQLITE_ERROR;
54742 ** Windows x86 and SQLITE_MAX_MMAP_SIZE=0. We always leave
54747 return sqlite3_vfs_register(&memdb_vfs, 0);
54835 ** If iSize>BITVEC_NBIT and iDivisor==0 then Bitvec.u.aHash[] is
54840 ** handles up to iDivisor separate values of i. apSub[0] holds
54852 /* Should >=0 for apSub element. */
54863 ** Create a new bitmap object able to handle bits between 0 and iSize,
54883 assert( p!=0 );
54885 if( i>=p->iSize ) return 0;
54891 return 0;
54895 return (p->u.aBitmap[i/BITVEC_SZELEM] & (1<<(i&(BITVEC_SZELEM-1))))!=0;
54902 return 0;
54906 return p!=0 && sqlite3BitvecTestNotNull(p,i);
54910 ** Set the i-th bit. Return 0 on success and an error code if
54923 if( p==0 ) return SQLITE_OK;
54924 assert( i>0 );
54930 if( p->u.apSub[bin]==0 ){
54932 if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM_BKPT;
54956 if( h>=BITVEC_NINT ) h = 0;
54965 u32 *aiValues = sqlite3StackAllocRaw(0, sizeof(p->u.aHash));
54966 if( aiValues==0 ){
54970 memset(p->u.apSub, 0, sizeof(p->u.apSub));
54972 if( (p->iSize%BITVEC_NPTR)!=0 ) p->iDivisor++;
54975 for(j=0; j<BITVEC_NINT; j++){
54978 sqlite3StackFree(0, aiValues);
54995 if( p==0 ) return;
54996 assert( i>0 );
55012 memset(p->u.aHash, 0, sizeof(p->u.aHash));
55013 p->nSet = 0;
55014 for(j=0; j<BITVEC_NINT; j++){
55020 if( h>=BITVEC_NINT ) h = 0;
55032 if( p==0 ) return;
55035 for(i=0; i<BITVEC_NPTR; i++){
55053 ** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
55059 #define TESTBIT(V,I) (V[I>>3]&(1<<(I&7)))!=0
55066 ** by 0, 1, or 3 operands, depending on the opcode. Another
55069 ** There are 6 opcodes numbered from 0 through 5. 0 is the
55072 ** 0 Halt and return the number of errors
55092 Bitvec *pBitvec = 0;
55093 unsigned char *pV = 0;
55103 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
55106 sqlite3BitvecSet(0, 1);
55107 sqlite3BitvecClear(0, 1, pTmpSpace);
55110 pc = i = 0;
55111 while( (op = aOp[pc])!=0 ){
55129 if( (--aOp[pc+1]) > 0 ) nx = 0;
55131 i = (i & 0x7fffffff)%sz;
55132 if( (op & 1)!=0 ){
55145 ** match (rc==0). Change rc to non-zero if a discrepancy
55148 rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1)
55149 + sqlite3BitvecTest(pBitvec, 0)
55226 ** Debug tracing macros. Enable by by changing the "0" to "1" and
55233 #if defined(SQLITE_DEBUG) && 0
55234 int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
55241 if( pLower==0 ){
55247 for(j=0; j<12; j++) printf("%02x", a[j]);
55257 if( pCache->pCache==0 ) return;
55261 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
55263 if( pLower && ((PgHdr*)pLower)->pPage==0 ){
55264 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
55275 ** Return 1 if pPg is on the dirty list for pCache. Return 0 if not.
55284 return 0;
55289 if( p==pPg ) return 0;
55310 assert( pPg!=0 );
55311 assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
55313 assert( pCache!=0 ); /* Every page has an associated PCache */
55315 assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
55318 assert( (pPg->flags & PGHDR_DIRTY)!=0 );/* If not CLEAN must be DIRTY */
55319 assert( pPg->pDirtyNext==0 || pPg->pDirtyNext->pDirtyPrev==pPg );
55320 assert( pPg->pDirtyPrev==0 || pPg->pDirtyPrev->pDirtyNext==pPg );
55321 assert( pPg->pDirtyPrev!=0 || pCache->pDirty==pPg );
55359 ** argument determines what operation to do. The 0x01 bit means first
55360 ** remove pPage from the dirty list. The 0x02 means add pPage back to
55394 if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/
55395 assert( p->bPurgeable==0 || p->eCreate==1 );
55401 pPage->pDirtyPrev = 0;
55404 assert( pPage->pDirtyNext->pDirtyPrev==0 );
55421 && 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
55436 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
55446 if( p->szCache>=0 ){
55468 if( sqlite3GlobalConfig.pcache2.xInit==0 ){
55473 assert( sqlite3GlobalConfig.pcache2.xInit!=0 );
55509 memset(p, 0, sizeof(PCache));
55528 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
55535 if( pNew==0 ) return SQLITE_NOMEM_BKPT;
55555 ** The createFlags should be 0 to check for existing pages and should
55558 ** If the createFlag is 0, then NULL is always returned if the page
55579 assert( pCache!=0 );
55580 assert( pCache->pCache!=0 );
55581 assert( createFlag==3 || createFlag==0 );
55585 ** 0 Do not allocate a new page. (createFlag==0)
55592 assert( eCreate==0 || eCreate==1 || eCreate==2 );
55593 assert( createFlag==0 || pCache->eCreate==eCreate );
55594 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
55619 if( pCache->eCreate==2 ) return 0;
55657 return *ppPage==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
55675 assert( pPage!=0 );
55677 assert( pPgHdr->pPage==0 );
55678 memset(&pPgHdr->pDirty, 0, sizeof(PgHdr) - offsetof(PgHdr,pDirty));
55682 memset(pPgHdr->pExtra, 0, 8);
55703 assert( pPage!=0 );
55717 ** reference count drops to 0, then it is made eligible for recycling.
55720 assert( p->nRef>0 );
55722 if( (--p->nRef)==0 ){
55736 assert(p->nRef>0);
55762 assert( p->nRef>0 );
55783 assert( (p->flags & PGHDR_DIRTY)!=0 );
55784 assert( (p->flags & PGHDR_CLEAN)==0 );
55790 if( p->nRef==0 ){
55801 while( (p = pCache->pDirty)!=0 ){
55835 assert( p->nRef>0 );
55836 assert( newPgno>0 );
55839 pOther = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, newPgno, 0);
55842 assert( pXPage->nRef==0 );
55861 ** function is 0, then the data area associated with page 1 is zeroed, but
55873 ** it must be that pgno==0.
55875 assert( p->pgno>0 );
55881 if( pgno==0 && pCache->nRefSum ){
55883 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
55885 ** pCache->nRefSum>0 */
55886 memset(pPage1->pBuf, 0, pCache->szPage);
55898 assert( pCache->pCache!=0 );
55907 sqlite3PcacheTruncate(pCache, 0);
55917 assert( pA!=0 && pB!=0 );
55923 if( pA==0 ){
55931 if( pB==0 ){
55954 memset(a, 0, sizeof(a));
55958 p->pDirty = 0;
55959 for(i=0; ALWAYS(i<N_SORT_BUCKET-1); i++){
55960 if( a[i]==0 ){
55965 a[i] = 0;
55975 p = a[0];
55977 if( a[i]==0 ) continue;
56015 assert( pCache->pCache!=0 );
56032 assert( pCache->pCache!=0 );
56045 assert( p->pCache!=0 );
56047 if( mxPage<0 ){
56061 assert( pCache->pCache!=0 );
56077 int nDirty = 0;
56080 return nCache ? (int)(((i64)nDirty * 100) / nCache) : 0;
56088 return (pCache->pDirty!=0);
56176 ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, N).
56233 /* NB: pLruPrev is only valid if pLruNext!=0 */
56240 #define PAGE_IS_PINNED(p) ((p)->pLruNext==0)
56241 #define PAGE_IS_UNPINNED(p) ((p)->pLruNext!=0)
56355 #if !defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || SQLITE_THREADSAFE==0
56356 # define pcache1EnterMutex(X) assert((X)->mutex==0)
56357 # define pcache1LeaveMutex(X) assert((X)->mutex==0)
56358 # define PCACHE1_MIGHT_USE_GROUP_MUTEX 0
56381 if( pBuf==0 ) sz = n = 0;
56382 if( n==0 ) sz = 0;
56388 pcache1.pFree = 0;
56389 AtomicStore(&pcache1.bUnderPressure,0);
56407 if( pcache1.nInitPage==0 ) return 0;
56409 if( pCache->nMax<3 ) return 0;
56411 if( pcache1.nInitPage>0 ){
56429 pX->isAnchor = 0;
56431 pX->pLruPrev = 0; /* Initializing this saves a valgrind error */
56436 return pCache->pFree!=0;
56449 void *p = 0;
56458 assert( pcache1.nFreeSlot>=0 );
56464 if( p==0 ){
56487 if( p==0 ) return;
56504 int nFreed = 0;
56537 PgHdr1 *p = 0;
56541 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
56542 assert( pCache->pFree!=0 );
56545 p->pNext = 0;
56551 assert( pcache1.separateCache==0 );
56561 if( pPg==0 ) return 0;
56566 p->isBulkLocal = 0;
56567 p->isAnchor = 0;
56568 p->pLruPrev = 0; /* Initializing this saves a valgrind error */
56579 assert( p!=0 );
56660 for(i=0; i<p->nHash; i++){
56663 while( (pPage = pNext)!=0 ){
56684 assert( pPage!=0 );
56691 pPage->pLruNext = 0;
56692 /* pPage->pLruPrev = 0;
56693 ** No need to clear pLruPrev as it is never accessed if pLruNext is 0 */
56694 assert( pPage->isAnchor==0 );
56731 && (p=pGroup->lru.pLruPrev)->isAnchor==0
56738 if( pCache->nPage==0 && pCache->pBulk ){
56740 pCache->pBulk = pCache->pFree = 0;
56755 TESTONLY( int nPage = 0; ) /* To assert pCache->nPage is correct */
56759 assert( pCache->nHash > 0 );
56779 while( (pPage = *pp)!=0 ){
56787 TESTONLY( if( nPage>=0 ) nPage++; )
56793 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
56804 assert( pcache1.isInit==0 );
56805 memset(&pcache1, 0, sizeof(pcache1));
56823 pcache1.separateCache = 0;
56825 pcache1.separateCache = sqlite3GlobalConfig.pPage==0
56826 || sqlite3GlobalConfig.bCoreMutex>0;
56828 pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
56838 && sqlite3GlobalConfig.nPage!=0
56839 && sqlite3GlobalConfig.pPage==0
56843 pcache1.nInitPage = 0;
56857 assert( pcache1.isInit!=0 );
56858 memset(&pcache1, 0, sizeof(pcache1));
56874 assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
56887 if( pGroup->lru.isAnchor==0 ){
56895 pCache->bPurgeable = (bPurgeable ? 1 : 0);
56906 if( pCache->nHash==0 ){
56908 pCache = 0;
56922 assert( nMax>=0 );
56927 if( n > 0x7fff0000 - pGroup->nMaxPage + pCache->nMax ){
56928 n = 0x7fff0000 - pGroup->nMaxPage + pCache->nMax;
56951 pGroup->nMaxPage = 0;
56986 PgHdr1 *pPage = 0;
56998 return 0;
57002 assert( pCache->nHash>0 && pCache->apHash );
57012 pcache1RemoveFromHash(pPage, 0);
57017 pPage = 0;
57036 pPage->pLruNext = 0;
57037 /* pPage->pLruPrev = 0;
57038 ** No need to clear pLruPrev since it is not accessed when pLruNext==0 */
57039 *(void **)pPage->page.pExtra = 0;
57054 ** the value of the createFlag argument. 0 means do not allocate a new
57064 ** depending on the value of parameter createFlag (which may be 0, 1 or 2).
57069 ** 2. If createFlag==0 and the page is not already in the cache, NULL is
57113 PgHdr1 *pPage = 0;
57120 ** If the page was not in the hash table and createFlag is 0, abort.
57121 ** Otherwise (page not in hash and createFlag!=0) continue with
57133 return 0;
57147 assert( pPage==0 || pCache->iMaxKey>=iKey );
57161 assert( offsetof(PgHdr1,page)==0 );
57163 assert( pCache->bPurgeable || pCache->nMin==0 );
57164 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
57165 assert( pCache->nMin==0 || pCache->bPurgeable );
57166 assert( pCache->nHash>0 );
57198 assert( pPage->pLruNext==0 );
57234 assert( pcache1FetchNoMutex(p, iOld, 0)==pPage ); /* pPg really is iOld */
57242 assert( pcache1FetchNoMutex(p, iNew, 0)==0 ); /* iNew not in cache */
57279 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
57281 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0);
57302 0, /* pArg */
57342 int nFree = 0;
57345 if( sqlite3GlobalConfig.pPage==0 ){
57348 while( (nReq<0 || nFree<nReq)
57349 && (p=pcache1.grp.lru.pLruPrev)!=0
57350 && p->isAnchor==0
57375 int nRecyclable = 0;
57511 #define ROWSET_SORTED 0x01 /* True if RowSet.pEntry is sorted */
57512 #define ROWSET_NEXT 0x02 /* True if sqlite3RowSetNext() has been called */
57522 p->pChunk = 0;
57524 p->pEntry = 0;
57525 p->pLast = 0;
57526 p->pForest = 0;
57530 p->iBatch = 0;
57547 p->pChunk = 0;
57548 p->nFresh = 0;
57549 p->pEntry = 0;
57550 p->pLast = 0;
57551 p->pForest = 0;
57574 assert( p!=0 );
57575 if( p->nFresh==0 ){ /*OPTIMIZATION-IF-FALSE*/
57580 if( pNew==0 ){
57581 return 0;
57603 assert( p!=0 && (p->rsFlags & ROWSET_NEXT)==0 );
57606 if( pEntry==0 ) return;
57608 pEntry->pRight = 0;
57637 assert( pA!=0 && pB!=0 );
57639 assert( pA->pRight==0 || pA->v<=pA->pRight->v );
57640 assert( pB->pRight==0 || pB->v<=pB->pRight->v );
57644 if( pA==0 ){
57651 if( pB==0 ){
57668 memset(aBucket, 0, sizeof(aBucket));
57671 pIn->pRight = 0;
57672 for(i=0; aBucket[i]; i++){
57674 aBucket[i] = 0;
57679 pIn = aBucket[0];
57680 for(i=1; i<sizeof(aBucket)/sizeof(aBucket[0]); i++){
57681 if( aBucket[i]==0 ) continue;
57698 assert( pIn!=0 );
57711 assert( (*ppLast)->pRight==0 );
57734 if( *ppList==0 ){ /*OPTIMIZATION-IF-TRUE*/
57736 return 0;
57744 if( p==0 ){ /*OPTIMIZATION-IF-FALSE*/
57755 p->pLeft = p->pRight = 0;
57769 assert( pList!=0 );
57772 p->pLeft = p->pRight = 0;
57786 ** 0 if the RowSet is already empty.
57797 assert( p!=0 );
57798 assert( p->pForest==0 ); /* Cannot be used with sqlite3RowSetText() */
57801 if( (p->rsFlags & ROWSET_NEXT)==0 ){ /*OPTIMIZATION-IF-FALSE*/
57802 if( (p->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
57812 if( p->pEntry==0 ){ /*OPTIMIZATION-IF-TRUE*/
57818 return 0;
57824 ** part of any insert batch prior to iBatch. Return 1 or 0.
57834 assert( pRowSet!=0 && (pRowSet->rsFlags & ROWSET_NEXT)==0 );
57843 if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
57849 if( pTree->pLeft==0 ){
57855 pTree->pLeft = 0;
57859 if( pTree==0 ){
57862 pTree->v = 0;
57863 pTree->pRight = 0;
57867 pRowSet->pEntry = 0;
57868 pRowSet->pLast = 0;
57875 ** Return 1 if it does and 0 if not.
57889 return 0;
57942 #define WAL_SYNC_FLAGS(X) ((X)&0x03)
57943 #define CKPT_SYNC_FLAGS(X) (((X)>>2)&0x03)
57946 # define sqlite3WalOpen(x,y,z) 0
57948 # define sqlite3WalClose(v,w,x,y,z) 0
57949 # define sqlite3WalBeginReadTransaction(y,z) 0
57951 # define sqlite3WalDbsize(y) 0
57952 # define sqlite3WalBeginWriteTransaction(y) 0
57953 # define sqlite3WalEndWriteTransaction(x) 0
57954 # define sqlite3WalUndo(x,y,z) 0
57956 # define sqlite3WalSavepointUndo(y,z) 0
57957 # define sqlite3WalFrames(u,v,w,x,y,z) 0
57958 # define sqlite3WalCheckpoint(q,r,s,t,u,v,w,x,y,z) 0
57959 # define sqlite3WalCallback(z) 0
57960 # define sqlite3WalExclusiveMode(y,z) 0
57961 # define sqlite3WalHeapMemory(z) 0
57962 # define sqlite3WalFramesize(z) 0
57963 # define sqlite3WalFindFrame(x,y,z) 0
57964 # define sqlite3WalFile(x) 0
58024 int sync_flags, /* Flags to sync db file with (or 0) */
58034 ** the last call, then return 0.
58172 #if 0
58408 #define PAGER_OPEN 0
58472 #define MAX_SECTOR_SIZE 0x10000
58482 ** set to 0. If a journal-header is written into the main journal while
58504 #define SPILLFLAG_OFF 0x01 /* Never spill cache. Set via pragma */
58505 #define SPILLFLAG_ROLLBACK 0x02 /* Current rolling back, so do not spill */
58506 #define SPILLFLAG_NOSYNC 0x04 /* Spill is ok, but do not sync */
58614 ** Except, any file that is greater than 0 bytes in size is considered
58666 ** syncFlags is either SQLITE_SYNC_NORMAL (0x02) or SQLITE_SYNC_FULL (0x03).
58670 ** file in bits 0x04 and 0x08. In other words, to get the correct sync flags
58671 ** for checkpoint operations, use (walSyncFlags&0x03) and to get the correct
58672 ** sync flags for transaction commit, use ((walSyncFlags>>2)&0x03). Note
58674 ** meaning that the 0x04 and 0x08 bits are both zero.
58770 #define PAGER_STAT_HIT 0
58781 SQLITE_API int sqlite3_pager_readdb_count = 0; /* Number of full pages read from DB */
58782 SQLITE_API int sqlite3_pager_writedb_count = 0; /* Number of full pages written to DB */
58783 SQLITE_API int sqlite3_pager_writej_count = 0; /* Number of pages written to journal */
58795 ** Since version 2.8.0, the journal format contains additional sanity
58815 0xd9, 0xd5, 0x05, 0xf9, 0x20, 0xa1, 0x63, 0xd7,
58837 # define MEMDB 0
58846 #if SQLITE_MAX_MMAP_SIZE>0
58849 # define USEFETCH(x) 0
58863 assert( pPager!=0 );
58864 assert( pPager->fd!=0 );
58865 if( pPager->fd->pMethods==0 ) return 0; /* Case (1) */
58866 if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0; /* Failed (3) */
58869 u32 iRead = 0;
58871 if( iRead ) return 0; /* Case (4) */
58874 assert( pPager->fd->pMethods->xDeviceCharacteristics!=0 );
58876 & SQLITE_IOCAP_SUBPAGE_READ)==0 ){
58877 return 0; /* Case (2) */
58884 # define pagerUseWal(x) ((x)->pWal!=0)
58886 # define pagerUseWal(x) 0
58887 # define pagerRollbackWal(x) 0
58888 # define pagerWalFrames(v,w,x,y) 0
58919 assert( p->tempFile==0 || p->eLock==EXCLUSIVE_LOCK );
58920 assert( p->tempFile==0 || pPager->changeCountDone );
58943 assert( pagerUseWal(p)==0 );
58949 assert( pPager->changeCountDone==0 || pPager->eLock>=RESERVED_LOCK );
58956 assert( sqlite3PcacheRefCount(pPager->pPCache)==0 || pPager->tempFile );
58974 assert( pPager->setSuper==0 );
59026 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 || pPager->tempFile );
59092 #if SQLITE_MAX_MMAP_SIZE>0
59103 #if SQLITE_MAX_MMAP_SIZE>0
59106 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
59126 for(i=0; i<pPager->nSavepoint; i++){
59128 if( p->nOrig>=pgno && 0==sqlite3BitvecTestNotNull(p->pInSavepoint, pgno) ){
59130 pPager->aSavepoint[i].bTruncateOnRelease = 0;
59135 return 0;
59193 assert( eLock!=NO_LOCK || pagerUseWal(pPager)==0 );
59247 ** If neither optimization can be used, 0 is returned.
59263 if( pPager->dbSize>0 && (dc&SQLITE_IOCAP_BATCH_ATOMIC) ){
59275 if( 0==(dc&(SQLITE_IOCAP_ATOMIC|(szPage>>8)) || nSector>szPage) ){
59276 return 0;
59283 return 0;
59296 u32 hash = 0;
59298 for(i=0; i<nByte; i++){
59323 #define pager_datahash(X,Y) 0
59324 #define pager_pagehash(X) 0
59349 ** zSuper[0] is set to 0 and SQLITE_OK returned.
59361 zSuper[0] = '\0';
59368 || len==0
59378 for(u=0; u<len; u++){
59387 len = 0;
59389 zSuper[len] = '\0';
59390 zSuper[len+1] = '\0';
59404 ** 0 0
59411 i64 offset = 0;
59416 assert( offset%JOURNAL_HDR_SZ(pPager)==0 );
59426 ** within the current transaction (i.e. if Pager.journalOff==0).
59429 ** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
59451 if( doTruncate || iLimit==0 ){
59452 rc = sqlite3OsTruncate(pPager->jfd, 0);
59454 static const char zeroHdr[28] = {0};
59455 rc = sqlite3OsWrite(pPager->jfd, zeroHdr, sizeof(zeroHdr), 0);
59467 if( rc==SQLITE_OK && iLimit>0 ){
59510 for(ii=0; ii<pPager->nSavepoint; ii++){
59511 if( pPager->aSavepoint[ii].iHdrOffset==0 ){
59525 ** A faster alternative is to write 0xFFFFFFFF to the nRec field. When
59543 put32bits(&zHeader[sizeof(aJournalMagic)], 0xffffffff);
59545 memset(zHeader, 0, sizeof(aJournalMagic)+4);
59562 ** case the journal file is always 0 bytes in size at this point.
59565 i64 sz = 0;
59567 assert( sz==0 );
59587 memset(&zHeader[sizeof(aJournalMagic)+20], 0,
59607 for(nWrite=0; rc==SQLITE_OK&&nWrite<JOURNAL_HDR_SZ(pPager); nWrite+=nHeader){
59667 if( memcmp(aMagic, aJournalMagic, sizeof(aMagic))!=0 ){
59683 if( pPager->journalOff==0 ){
59698 if( iPageSize==0 ){
59709 || ((iPageSize-1)&iPageSize)!=0 || ((iSectorSize-1)&iSectorSize)!=0
59764 u32 cksum = 0; /* Checksum of string zSuper */
59766 assert( pPager->setSuper==0 );
59779 for(nSuper=0; zSuper[nSuper]; nSuper++){
59795 if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_SJ_PGNO(pPager))))
59796 || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4)))
59797 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper)))
59798 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum)))
59799 || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8,
59847 for(ii=0; ii<pPager->nSavepoint; ii++){
59854 pPager->aSavepoint = 0;
59855 pPager->nSavepoint = 0;
59856 pPager->nSubRec = 0;
59868 for(ii=0; ii<pPager->nSavepoint; ii++){
59904 pPager->pInJournal = 0;
59922 int iDc = isOpen(pPager->fd)?sqlite3OsDeviceCharacteristics(pPager->fd):0;
59935 if( 0==(iDc & SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN)
59966 if( pPager->tempFile==0 ){
59968 pPager->changeCountDone = 0;
59973 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
59978 pPager->journalOff = 0;
59979 pPager->journalHdr = 0;
59980 pPager->setSuper = 0;
60003 int rc2 = rc & 0xff;
60008 (pPager->errCode & 0xff)==SQLITE_IOERR
60022 ** or rolled back (bCommit==0).
60037 if( pPager->tempFile==0 ) return 1;
60038 if( !bCommit ) return 0;
60039 if( !isOpen(pPager->fd) ) return 0;
60120 assert( isOpen(pPager->jfd) || pPager->pInJournal==0
60131 if( pPager->journalOff==0 ){
60134 rc = sqlite3OsTruncate(pPager->jfd, 0);
60144 pPager->journalOff = 0;
60149 pPager->journalOff = 0;
60157 assert( sqlite3JournalIsInMemory(pPager->jfd)==0 );
60171 if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){
60174 p->pageHash = 0;
60181 pPager->pInJournal = 0;
60182 pPager->nRec = 0;
60211 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_COMMIT_PHASETWO, 0);
60216 && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
60221 pPager->setSuper = 0;
60255 pager_end_transaction(pPager, 0, 0);
60298 while( i>0 ){
60307 ** from the sub-journal (if isMainJrnl==0) and playback that page.
60332 ** * If the record page-number is illegal (0 or PAGER_SJ_PGNO), or
60346 int isMainJrnl, /* 1 -> main journal. 0 -> sub-journal. */
60357 assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */
60358 assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */
60360 assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */
60364 assert( pagerUseWal(pPager)==0 || (!isMainJrnl && isSavepnt) );
60392 if( pgno==0 || pgno==PAGER_SJ_PGNO(pPager) ){
60449 ** the page is marked as needSync==0.
60456 pPg = 0;
60461 assert( pPager->eState!=PAGER_OPEN || pPg==0 || pPager->tempFile );
60469 isSynced = (pPg==0 || 0==(pPg->flags & PGHDR_NEED_SYNC));
60476 testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
60493 }else if( !isMainJrnl && pPg==0 ){
60511 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)==0 );
60514 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 );
60558 ** nul-terminator byte (0x00). i.e. the entire contents of a super-journal
60594 char *zSuperJournal = 0; /* Contents of super-journal file */
60598 char *zFree = 0; /* Free this buffer */
60607 pJournal = 0;
60610 rc = sqlite3OsOpen(pVfs, zSuper, pSuper, flags, 0);
60623 assert( nSuperJournal>=0 && nSuperPtr>0 );
60629 assert( nSuperJournal<=0x7fffffff );
60631 zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0;
60634 rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
60636 zSuperJournal[nSuperJournal] = 0;
60637 zSuperJournal[nSuperJournal+1] = 0;
60656 rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
60667 c = zSuperPtr[0]!=0 && strcmp(zSuperPtr, zSuper)==0;
60677 rc = sqlite3OsDelete(pVfs, zSuper, 0);
60731 memset(pTmp, 0, szPage);
60788 SQLITE_IOCAP_POWERSAFE_OVERWRITE)!=0
60807 ** in the journal. If this value is 0xffffffff, then compute the
60834 ** If the nRec value is 0xffffffff it means that nRec should be computed
60861 Pgno mxPg = 0; /* Size of the original file in pages */
60864 char *zSuper = 0; /* Name of super-journal file if any */
60866 int nPlayback = 0; /* Total number of pages restored from journal */
60891 if( rc==SQLITE_OK && zSuper[0] ){
60894 zSuper = 0;
60898 pPager->journalOff = 0;
60919 /* If nRec is 0xffffffff, then this journal was created by a process
60924 if( nRec==0xffffffff ){
60929 /* If nRec is 0 and this rollback is of a transaction created by this
60936 ** When rolling back a hot journal, nRec==0 always means that the next
60938 ** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
60943 if( nRec==0 && !isHot &&
60965 for(u=0; u<nRec; u++){
60968 needPagerReset = 0;
60970 rc = pager_playback_one_page(pPager,&pPager->journalOff,0,1,0);
60997 assert( 0 );
61009 sqlite3OsFileControlHint(pPager->fd,SQLITE_FCNTL_DB_UNCHANGED,0);
61026 ** which case it requires 4 0x00 bytes in memory immediately before
61035 rc = sqlite3PagerSync(pPager, 0);
61038 rc = pager_end_transaction(pPager, zSuper[0]!='\0', 0);
61041 if( rc==SQLITE_OK && zSuper[0] && res ){
61046 memset(pPager->pTmpSpace, 0, 4);
61081 u32 iFrame = 0; /* Frame of WAL containing pgno */
61108 ** should be page numbers which are never 0xffffffff. So filling
61109 ** pPager->dbFileVers[] with all 0xff bytes should suffice.
61113 ** white noise equaling 16 bytes of 0xff is vanishingly small so
61116 memset(pPager->dbFileVers, 0xff, sizeof(pPager->dbFileVers));
61141 if( NEVER(pPg==0) ) return;
61210 ** + Discard the cached page (if refcount==0), or
61211 ** + Reload page content from the database (if refcount>0).
61253 assert( pList->pDirty==0 || isCommit );
61260 nList = 0;
61261 for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
61303 int changed = 0; /* True if cache must be reset */
61318 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
61338 ** function returns zero if the WAL is not open (i.e. Pager.pWal==0), or
61346 assert( pPager->tempFile==0 );
61354 if( nPage==0 && ALWAYS(isOpen(pPager->fd)) ){
61355 i64 n = 0; /* Size of db file in bytes */
61410 if( nPage==0 ){
61411 rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0);
61413 testcase( sqlite3PcachePagecount(pPager->pPCache)==0 );
61414 rc = sqlite3PagerOpenWal(pPager, 0);
61465 Bitvec *pDone = 0; /* Bitvec to ensure pages played back only once */
61494 assert( pagerUseWal(pPager)==0 || szJ==0 );
61511 pPager->journalOff = 0;
61521 u32 nJRec = 0; /* Number of Journal Records */
61523 rc = readJournalHdr(pPager, 0, szJ, &nJRec, &dummy);
61531 if( nJRec==0
61536 for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
61556 rc = pager_playback_one_page(pPager, &offset, pDone, 0, 1);
61589 #if SQLITE_MAX_MMAP_SIZE>0
61594 pPager->bUseFetch = (sz>0);
61674 pPager->fullSync = 0;
61675 pPager->extraSync = 0;
61677 pPager->noSync = level==PAGER_SYNCHRONOUS_OFF ?1:0;
61678 pPager->fullSync = level>=PAGER_SYNCHRONOUS_FULL ?1:0;
61679 pPager->extraSync = level==PAGER_SYNCHRONOUS_EXTRA ?1:0;
61682 pPager->syncFlags = 0;
61708 SQLITE_API int sqlite3_opentemp_count = 0;
61739 rc = sqlite3OsOpen(pPager->pVfs, 0, pFile, vfsFlags, 0);
61774 assert( ((int(*)(void *))(ap[0]))==xBusyHandler );
61823 assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) );
61824 if( (pPager->memDb==0 || pPager->dbSize==0)
61825 && sqlite3PcacheRefCount(pPager->pPCache)==0
61829 i64 nByte = 0;
61841 memset(pNew+pageSize, 0, 8);
61862 if( nReserve<0 ) nReserve = pPager->nReserve;
61863 assert( nReserve>=0 && nReserve<1000 );
61890 if( mxPage>0 ){
61941 memset(pDest, 0, N);
61951 IOTRACE(("DBHDR %p 0 %d\n", pPager, N))
61952 rc = sqlite3OsRead(pPager->fd, pDest, N, 0);
62035 for(i=0; i<pPg->pPager->nSavepoint; i++){
62070 ** Pager object may still have open savepoints (Pager.nSavepoint!=0),
62101 #if SQLITE_MAX_MMAP_SIZE>0
62123 p->pDirty = 0;
62125 memset(p->pExtra, 0, 8);
62128 if( p==0 ){
62140 assert( p->pPage==0 );
62185 int bHasMoved = 0;
62189 if( pPager->dbSize==0 ) return SQLITE_OK;
62190 assert( pPager->zFilename && pPager->zFilename[0] );
62220 assert( db || pagerUseWal(pPager)==0 );
62225 /* pPager->errCode = 0; */
62226 pPager->exclusiveMode = 0;
62229 u8 *a = 0;
62230 assert( db || pPager->pWal==0 );
62231 if( db && 0==(db->flags & SQLITE_NoCkptOnClose)
62237 pPager->pWal = 0;
62344 if( 0==(iDc&SQLITE_IOCAP_SAFE_APPEND) ){
62359 ** a valid header following Pager.journalOff, then write a 0x00
62376 if( rc==SQLITE_OK && 0==memcmp(aMagic, aJournalMagic, 8) ){
62377 static const u8 zerobyte = 0;
62392 ** is populated with 0xFFFFFFFF when the journal header is written
62395 if( pPager->fullSync && 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
62407 if( 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
62411 (pPager->syncFlags==SQLITE_SYNC_FULL?SQLITE_SYNC_DATAONLY:0)
62417 if( newHdr && 0==(iDc&SQLITE_IOCAP_SAFE_APPEND) ){
62418 pPager->nRec = 0;
62476 assert( isOpen(pPager->fd) || pList->pDirty==0 );
62511 if( pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
62515 assert( (pList->flags&PGHDR_NEED_SYNC)==0 );
62570 rc = sqlite3JournalOpen(pPager->pVfs, 0, pPager->sjfd, flags, nStmtSpill);
62594 assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 );
62617 assert( pPager->nSavepoint>0 );
62677 && ((pPager->doNotSpill & (SPILLFLAG_ROLLBACK|SPILLFLAG_OFF))!=0
62678 || (pPg->flags & PGHDR_NEED_SYNC)!=0)
62684 pPg->pDirty = 0;
62689 rc = pagerWalFrames(pPager, pPg, 0, 0);
62694 if( pPager->tempFile==0 ){
62709 assert( (pPg->flags&PGHDR_NEED_SYNC)==0 );
62733 if( pList->nRef==0 ){
62785 Pager *pPager = 0; /* Pager object to allocate and return */
62787 int tempFile = 0; /* True for temp files (incl. in-memory files) */
62788 int memDb = 0; /* True if this is an in-memory file */
62789 int memJM = 0; /* Memory journal mode */
62790 int readOnly = 0; /* True if this is a read-only file */
62792 char *zPathname = 0; /* Full path to database file */
62793 int nPathname = 0; /* Number of bytes in zPathname */
62794 int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
62797 const char *zUri = 0; /* URI args to copy */
62806 *ppPager = 0;
62811 if( zFilename && zFilename[0] ){
62812 zPathname = sqlite3DbStrDup(0, zFilename);
62813 if( zPathname==0 ) return SQLITE_NOMEM_BKPT;
62815 zFilename = 0;
62822 ** leave both nPathname and zPathname set to 0.
62824 if( zFilename && zFilename[0] ){
62827 zPathname = sqlite3DbMallocRaw(0, 2*(i64)nPathname);
62828 if( zPathname==0 ){
62831 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
62860 sqlite3DbFree(0, zPathname);
62875 ** \0\0\0\0 database prefix (4 bytes)
62880 ** \0\0\0 terminator (3 bytes)
62883 ** the specific order of the filenames and the \0 separators between them
62892 ** - \0
62895 ** - \0
62897 ** - \0
62898 ** - \0
62900 ** - \0
62902 ** - \0
62927 sqlite3DbFree(0, zPathname);
62941 if( nPathname>0 ){
62952 if( nPathname>0 ){
62961 pPager->zJournal = 0;
62966 if( nPathname>0 ){
62975 pPager->zWal = 0;
62980 if( nPathname ) sqlite3DbFree(0, zPathname);
62986 if( zFilename && zFilename[0] ){
62987 int fout = 0; /* VFS flags returned by xOpen() */
62990 pPager->memVfs = memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
62991 readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
63027 pPager->noLock = sqlite3_uri_boolean(pPager->zFilename, "nolock", 0);
63028 if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
63029 || sqlite3_uri_boolean(pPager->zFilename, "immutable", 0) ){
63057 assert( pPager->memDb==0 );
63067 !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
63083 /* pPager->stmtOpen = 0; */
63084 /* pPager->stmtInUse = 0; */
63085 /* pPager->nRef = 0; */
63086 /* pPager->stmtSize = 0; */
63087 /* pPager->stmtJSize = 0; */
63088 /* pPager->nPage = 0; */
63091 /* pPager->errMask = 0; */
63102 /* pPager->pFirst = 0; */
63103 /* pPager->pFirstSynced = 0; */
63104 /* pPager->pLast = 0; */
63114 /* pPager->xBusyHandler = 0; */
63115 /* pPager->pBusyHandlerArg = 0; */
63118 /* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
63133 while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){
63152 ** * The database file itself is greater than 0 bytes in size, and
63153 ** * The first byte of the journal file exists and is not 0x00.
63155 ** If the current size of the database file is 0 but a journal file
63158 ** just deleted using OsDelete, *pExists is set to 0 and SQLITE_OK
63170 ** set to 0 and SQLITE_OK returned. If an IO error occurs while trying
63184 assert( jrnlOpen==0 || ( sqlite3OsDeviceCharacteristics(pPager->jfd) &
63188 *pExists = 0;
63193 int locked = 0; /* True if some process holds a RESERVED lock */
63207 assert( pPager->tempFile==0 );
63218 if( nPage==0 && !jrnlOpen ){
63221 sqlite3OsDelete(pVfs, pPager->zJournal, 0);
63237 u8 first = 0;
63238 rc = sqlite3OsRead(pPager->jfd, (void *)&first, 1, 0);
63245 *pExists = (first!=0);
63301 assert( sqlite3PcacheRefCount(pPager->pPCache)==0 );
63310 assert( pPager->tempFile==0 || pPager->eLock==EXCLUSIVE_LOCK );
63372 int fout = 0;
63455 memset(dbFileVers, 0, sizeof(dbFileVers));
63458 if( memcmp(pPager->dbFileVers, dbFileVers, sizeof(dbFileVers))!=0 ){
63468 sqlite3OsUnfetch(pPager->fd, 0, 0);
63478 assert( pPager->pWal==0 || rc==SQLITE_OK );
63487 if( pPager->tempFile==0 && pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){
63512 if( sqlite3PcacheRefCount(pPager->pPCache)==0 ){
63513 assert( pPager->nMmapOut==0 ); /* because page1 is never memory mapped */
63570 ** just returns 0. This routine acquires a read-lock the first time it
63591 if( pgno==0 ) return SQLITE_CORRUPT_BKPT;
63593 if( pBase==0 ){
63594 pPg = 0;
63597 if( pBase==0 ){
63605 assert( pPg->pPager==pPager || pPg->pPager==0 );
63607 noContent = (flags & PAGER_GET_NOCONTENT)!=0;
63635 pPg = 0;
63655 memset(pPg->pData, 0, pPager->pageSize);
63675 *ppPage = 0;
63679 #if SQLITE_MAX_MMAP_SIZE>0
63688 PgHdr *pPg = 0;
63689 u32 iFrame = 0; /* Frame to read from WAL file */
63701 /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here
63703 ** test in the previous statement, and avoid testing pgno==0 in the
63705 if( pgno<=1 && pgno==0 ){
63716 *ppPage = 0;
63720 if( bMmapOk && iFrame==0 ){
63721 void *pData = 0;
63729 if( pPg==0 ){
63741 *ppPage = 0;
63747 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
63759 *ppPage = 0;
63772 #if 0 /* Trace page fetch by setting to 1 */
63778 printf("PAGE %u failed with 0x%02x\n", pgno, rc);
63791 ** or 0 if the page is not in cache.
63801 assert( pPager!=0 );
63802 assert( pgno!=0 );
63803 assert( pPager->pPCache!=0 );
63804 pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
63805 assert( pPage==0 || pPager->hasHeldSharedLock );
63806 if( pPage==0 ) return 0;
63826 assert( pPg!=0 );
63834 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 ); /* tag-20230419-2 */
63841 assert( pPg!=0 );
63843 assert( (pPg->flags & PGHDR_MMAP)==0 ); /* Page1 is never memory mapped */
63877 assert( pPager->pInJournal==0 );
63886 if( pPager->pInJournal==0 ){
63925 pPager->nRec = 0;
63926 pPager->journalOff = 0;
63927 pPager->setSuper = 0;
63928 pPager->journalHdr = 0;
63935 pPager->pInJournal = 0;
63936 pPager->journalOff = 0;
63970 assert( pPager->pInJournal==0 );
64016 pPager->journalOff = 0;
64068 ((pPg->flags&PGHDR_NEED_SYNC)?1:0), pager_pagehash(pPg)));
64072 assert( pPager->pInJournal!=0 );
64101 assert( pPager->errCode==0 );
64102 assert( pPager->readOnly==0 );
64128 assert( (pPager->pInJournal!=0) == isOpen(pPager->jfd) );
64129 if( pPager->pInJournal!=0
64130 && sqlite3BitvecTestNotNull(pPager->pInJournal, pPg->pgno)==0
64132 assert( pagerUseWal(pPager)==0 );
64144 ((pPg->flags&PGHDR_NEED_SYNC)?1:0)));
64158 if( pPager->nSavepoint>0 ){
64184 int nPage = 0; /* Number of pages starting at pg1 to journal */
64186 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
64195 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)==0 );
64212 assert(nPage>0);
64216 for(ii=0; ii<nPage && rc==SQLITE_OK; ii++){
64221 rc = sqlite3PagerGet(pPager, pg, &pPage, 0);
64230 }else if( (pPage = sqlite3PagerLookup(pPager, pg))!=0 ){
64246 for(ii=0; ii<nPage; ii++){
64255 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
64276 assert( (pPg->flags & PGHDR_MMAP)==0 );
64279 if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
64285 assert( pPager->tempFile==0 );
64325 if( !pPager->tempFile && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
64376 # define DIRECT_MODE 0
64377 assert( isDirectMode==0 );
64383 if( !pPager->changeCountDone && pPager->dbSize>0 ){
64389 rc = sqlite3PagerGet(pPager, 1, &pPgHdr, 0);
64390 assert( pPgHdr==0 || rc==SQLITE_OK );
64408 assert( pPager->dbFileSize>0 );
64411 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
64472 if( 0==pagerUseWal(pPager) ){
64531 assert( MEMDB==0 || pPager->tempFile );
64533 if( 0==pagerFlushOnCommit(pPager, 1) ){
64541 PgHdr *pPageOne = 0;
64543 if( pList==0 ){
64546 rc = sqlite3PagerGet(pPager, 1, &pPageOne, 0);
64548 pList->pDirty = 0;
64565 int bBatch = zSuper==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
64570 # define bBatch 0
64597 if( bBatch==0 ){
64606 && (!(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
64618 rc = pager_incr_changecounter(pPager, 0);
64627 assert( bBatch==0 );
64630 rc = pager_incr_changecounter(pPager, 0);
64652 rc = syncJournal(pPager, 0);
64658 rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, 0);
64664 memset(pTmp, 0, szPage);
64669 rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, 0);
64672 sqlite3OsFileControlHint(fd, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 0);
64676 if( (rc&0xFF)==SQLITE_IOERR && rc!=SQLITE_IOERR_NOMEM ){
64682 bBatch = 0;
64689 if( bBatch==0 ){
64762 ** header with the nRec field set to 0. If such a journal is used as
64763 ** a hot-journal during hot-journal rollback, 0 changes will be made
64823 rc2 = pager_end_transaction(pPager, pPager->setSuper, 0);
64827 rc = pager_end_transaction(pPager, 0, 0);
64839 rc = pager_playback(pPager, 0);
64844 || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR
64896 a[0] = sqlite3PcacheRefCount(pPager->pPCache);
64902 a[6] = (int)pPager->aStat[PAGER_STAT_HIT] & 0x7fffffff;
64903 a[7] = (int)pPager->aStat[PAGER_STAT_MISS] & 0x7fffffff;
64904 a[8] = 0; /* Used to be pPager->nOvfl */
64906 a[10] = (int)pPager->aStat[PAGER_STAT_WRITE] & 0x7fffffff;
64932 assert( PAGER_STAT_HIT==0 && PAGER_STAT_MISS==1
64938 pPager->aStat[eStat] = 0;
64979 memset(&aNew[nCurrent], 0, (nSavepoint-nCurrent) * sizeof(PagerSavepoint));
64985 if( isOpen(pPager->jfd) && pPager->journalOff>0 ){
65028 ** iSavepoint. A value of 0 means to operate on the outermost savepoint
65055 assert( iSavepoint>=0 || op==SAVEPOINT_ROLLBACK );
65065 nNew = iSavepoint + (( op==SAVEPOINT_RELEASE ) ? 0 : 1);
65091 PagerSavepoint *pSavepoint = (nNew==0)?0:&pPager->aSavepoint[nNew-1];
65122 ** shared cache, it uses nullIfMemDb==0 so that in-memory databases can
65129 static const char zFake[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
65200 Pgno needSyncPgno = 0; /* Old value of pPg->pgno, if sync is required */
65204 assert( pPg->nRef>0 );
65237 if( (pPg->flags & PGHDR_DIRTY)!=0
65244 PAGERID(pPager), pPg->pgno, (pPg->flags&PGHDR_NEED_SYNC)?1:0, pgno));
65313 rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr, 0);
65316 assert( pPager->pTmpSpace!=0 );
65346 assert( pPg->nRef>0 || pPg->pPager->memDb );
65372 assert( PAGER_LOCKINGMODE_QUERY<0 );
65373 assert( PAGER_LOCKINGMODE_NORMAL>=0 && PAGER_LOCKINGMODE_EXCLUSIVE>=0 );
65374 assert( pPager->exclusiveMode || 0==sqlite3WalHeapMemory(pPager->pWal) );
65375 if( eMode>=0 && !pPager->tempFile && !sqlite3WalHeapMemory(pPager->pWal) ){
65405 assert( eMode==PAGER_JOURNALMODE_DELETE /* 0 */
65416 assert( pPager->tempFile==0 || eMode!=PAGER_JOURNALMODE_WAL );
65440 assert( (PAGER_JOURNALMODE_DELETE & 5)==0 );
65442 assert( (PAGER_JOURNALMODE_OFF & 5)==0 );
65446 if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){
65457 sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
65470 sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
65502 if( pPager->eState>=PAGER_WRITER_CACHEMOD ) return 0;
65503 if( NEVER(isOpen(pPager->jfd) && pPager->journalOff>0) ) return 0;
65536 assert( MEMDB==0 || pPager->tempFile );
65537 if( pPager->tempFile==0 ) pager_reset(pPager);
65558 if( pPager->pWal==0 && pPager->journalMode==PAGER_JOURNALMODE_WAL ){
65568 sqlite3_exec(db, "PRAGMA table_list",0,0,0);
65572 (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
65591 if( pPager->noLock ) return 0;
65624 assert( pPager->pWal==0 && pPager->tempFile==0 );
65680 assert( pbOpen==0 || *pbOpen==0 );
65681 assert( pbOpen!=0 || (!pPager->tempFile && !pPager->pWal) );
65720 int logexists = 0;
65740 pPager->pWal = 0;
65757 if( pagerUseWal(pPager) && pPager->exclusiveMode==0 ){
65860 ** is empty, return 0.
65914 ** 0: Magic number. 0x377f0682 or 0x377f0683
65928 ** 0: Page number.
65948 ** magic number in the first 4 bytes of the WAL is 0x377f0683 and it
65949 ** is computed using little-endian if the magic number is 0x377f0682.
65953 ** an even number of unsigned 32-bit integers: x[0] through x[N]. The
65956 ** for i from 0 to n-1 step 2:
66079 ** contain a value of 0.
66135 SQLITE_PRIVATE int sqlite3WalTrace = 0;
66171 #define WAL_WRITE_LOCK 0
66190 ** For all versions of SQLite through 3.10.0 and probably beyond,
66237 ** the mxFrame for that reader. The value READMARK_NOT_USED (0xffffffff)
66238 ** for any aReadMark[] means that entry is unused. aReadMark[0] is
66241 ** WAL_READ_LOCK(0) always ignore the entire WAL and read all content
66257 ** will choose aReadMark[0] which has value 0 and hence such reader will
66264 ** (in other words, if there are no WAL_READ_LOCK(i) where i>0) then
66278 #define READMARK_NOT_USED 0xffffffff
66285 ** 0: | iVersion | \
66360 ** significant bit also set (WAL_MAGIC | 0x00000001) is stored in 32-bit
66368 #define WAL_MAGIC 0x377f0682
66392 u32 iCallback; /* Value to pass to log callback (or 0) */
66436 #define WAL_NORMAL_MODE 0
66443 #define WAL_RDWR 0 /* Normal read/write connection */
66476 int iZero; /* Frame number associated with aPgno[0] */
66524 assert( walAssertLockmask(pWal) && pWal->nSehTry==0 ); \
66530 assert( pWal->nSehTry==0 ); \
66547 ** ExceptionInformation[] array is a read-write flag - 0 if the exception
66566 assert( pWal->nSehTry>0 );
66569 if( res!=0 ){
66571 aArg[0] = 0;
66572 aArg[1] = 0;
66574 RaiseException(EXCEPTION_IN_PAGE_ERROR, 0, 3, (const ULONG_PTR*)aArg);
66582 ** SEH_FREE_ON_ERROR(0, pPtr);
66586 ** SEH_FREE_ON_ERROR(pPtr, 0);
66592 assert( (X==0 || Y==0) && pWal->pFree==X ); pWal->pFree = Y
66602 ** SEH_SET_ON_ERROR(0, 0);
66608 # define SEH_EXCEPT(X) VVA_ONLY(pWal->nSehTry--); assert( pWal->nSehTry==0 );
66609 # define SEH_INJECT_FAULT assert( pWal->nSehTry>0 );
66629 ** (3) rc==SQLITE_OK and *ppPage==NULL // only if iPage==0
66631 ** Scenario (3) can only occur when pWal->writeLock is false and iPage==0
66646 *ppPage = 0;
66649 memset((void*)&apNew[pWal->nWiData], 0,
66656 assert( pWal->apWiData[iPage]==0 );
66664 assert( pWal->apWiData[iPage]!=0
66666 || (pWal->writeLock==0 && iPage==0) );
66667 testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK );
66669 if( iPage>0 && sqlite3FaultSim(600) ) rc = SQLITE_NOMEM;
66670 }else if( (rc&0xff)==SQLITE_READONLY ){
66679 assert( iPage==0 || *ppPage || rc!=SQLITE_OK );
66688 if( pWal->nWiData<=iPage || (*ppPage = pWal->apWiData[iPage])==0 ){
66698 assert( pWal->nWiData>0 && pWal->apWiData[0] );
66700 return (volatile WalCkptInfo*)&(pWal->apWiData[0][sizeof(WalIndexHdr)/2]);
66707 assert( pWal->nWiData>0 && pWal->apWiData[0] );
66709 return (volatile WalIndexHdr*)pWal->apWiData[0];
66720 (((x)&0x000000FF)<<24) + (((x)&0x0000FF00)<<8) \
66721 + (((x)&0x00FF0000)>>8) + (((x)&0xFF000000)>>24) \
66726 ** array aByte[] and the initial values of aIn[0] and aIn[1] (or
66727 ** initial values of 0 and 0 if aIn==NULL).
66745 s1 = aIn[0];
66748 s1 = s2 = 0;
66752 assert( nByte>=8 && (nByte&7)==0 && nByte<=65536 );
66756 s1 += BYTESWAP32(aData[0]) + s2;
66760 }else if( nByte%64==0 ){
66787 aOut[0] = s1;
66826 walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum);
66830 memcpy((void*)&aHdr[0], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
66838 ** 0: Page number.
66849 u32 nTruncate, /* New db size (or 0 for non-commit frames) */
66856 sqlite3Put4byte(&aFrame[0], iPage);
66858 if( pWal->iReCksum==0 ){
66865 sqlite3Put4byte(&aFrame[16], aCksum[0]);
66868 memset(&aFrame[8], 0, 16);
66880 u32 *pnTruncate, /* OUT: New db size (or 0 if not commit) */
66892 if( memcmp(&pWal->hdr.aSalt, &aFrame[8], 8)!=0 ){
66893 return 0;
66898 pgno = sqlite3Get4byte(&aFrame[0]);
66899 if( pgno==0 ){
66900 return 0;
66911 if( aCksum[0]!=sqlite3Get4byte(&aFrame[16])
66915 return 0;
66942 lockIdx-WAL_READ_LOCK(0));
66963 VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && (rc&0xFF)!=SQLITE_BUSY); )
66985 VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && (rc&0xFF)!=SQLITE_BUSY); )
67006 ** between 0 and (HASHTABLE_NSLOT-1). The walHashNext() function advances
67010 assert( iPage>0 );
67011 assert( (HASHTABLE_NSLOT & (HASHTABLE_NSLOT-1))==0 );
67033 ** numbered starting from 0.
67041 ** Finally, set pLoc->aPgno so that pLoc->aPgno[0] is the page number of the
67052 assert( rc==SQLITE_OK || iHash>0 );
67056 if( iHash==0 ){
67058 pLoc->iZero = 0;
67072 ** are numbered starting from 0.
67076 assert( (iHash==0 || iFrame>HASHTABLE_NPAGE_ONE)
67082 assert( iHash>=0 );
67092 if( iHash==0 ){
67093 return pWal->apWiData[0][WALINDEX_HDR_SIZE/sizeof(u32) + iFrame - 1];
67112 int iLimit = 0; /* Zero values greater than this */
67121 if( pWal->hdr.mxFrame==0 ) return;
67136 assert( iLimit>0 );
67137 for(i=0; i<HASHTABLE_NSLOT; i++){
67139 sLoc.aHash[i] = 0;
67147 assert( nByte>=0 );
67148 memset((void *)&sLoc.aPgno[iLimit], 0, nByte);
67157 for(j=0; j<iLimit; j++){
67194 assert( nByte>=0 );
67195 memset((void*)sLoc.aPgno, 0, nByte);
67212 if( (nCollide--)==0 ) return SQLITE_CORRUPT_BKPT;
67223 int nEntry = 0; /* Number of entries in the hash table */
67224 for(i=0; i<HASHTABLE_NSLOT; i++){ if( sLoc.aHash[i] ) nEntry++; }
67233 if( (idx&0x3ff)==0 ){
67235 for(i=0; i<idx; i++){
67264 u32 aFrameCksum[2] = {0, 0};
67273 assert( pWal->ckptLock==1 || pWal->ckptLock==0 );
67278 rc = walLockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
67285 memset(&pWal->hdr, 0, sizeof(WalIndexHdr));
67294 u32 *aPrivate = 0; /* Heap copy of *-shm hash being populated */
67295 u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */
67306 rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0);
67316 magic = sqlite3Get4byte(&aBuf[0]);
67318 if( (magic&0xFFFFFFFE)!=WAL_MAGIC
67325 pWal->hdr.bigEndCksum = (u8)(magic&0x00000001);
67332 aBuf, WAL_HDRSIZE-2*4, 0, pWal->hdr.aFrameCksum
67334 if( pWal->hdr.aFrameCksum[0]!=sqlite3Get4byte(&aBuf[24])
67351 SEH_FREE_ON_ERROR(0, aFrame);
67361 for(iPg=0; iPg<=(u32)walFramePage(iLastFrame); iPg++){
67365 u32 iFirst = 1 + (iPg==0?0:HASHTABLE_NPAGE_ONE+(iPg-1)*HASHTABLE_NPAGE);
67368 assert( aShare!=0 || rc!=SQLITE_OK );
67369 if( aShare==0 ) break;
67390 pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16));
67393 aFrameCksum[0] = pWal->hdr.aFrameCksum[0];
67398 SEH_SET_ON_ERROR(0,0);
67399 nHdr = (iPg==0 ? WALINDEX_HDR_SIZE : 0);
67433 SEH_FREE_ON_ERROR(aFrame, 0);
67441 pWal->hdr.aFrameCksum[0] = aFrameCksum[0];
67450 pInfo->nBackfill = 0;
67452 pInfo->aReadMark[0] = 0;
67483 walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
67493 for(i=0; i<pWal->nWiData; i++){
67495 pWal->apWiData[i] = 0;
67530 assert( zWalName && zWalName[0] );
67558 assert( 123 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(0) );
67579 *ppWal = 0;
67603 walIndexClose(pRet, 0);
67608 if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; }
67610 pRet->padToSectorBoundary = 0;
67632 ** Return 0 on success. If there are no pages in the WAL with a page
67641 u32 iRet = 0xFFFFFFFF; /* 0xffffffff is never a valid page number */
67645 assert( iMin<0xffffffff );
67646 for(i=p->nSegment-1; i>=0; i--){
67662 return (iRet==0xFFFFFFFF);
67696 int iLeft = 0; /* Current index in aLeft */
67697 int iRight = 0; /* Current index in aRight */
67698 int iOut = 0; /* Current index in output buffer */
67702 assert( nLeft>0 && nRight>0 );
67725 memcpy(aLeft, aTmp, sizeof(aTmp[0])*iOut);
67757 int nMerge = 0; /* Number of elements in list aMerge */
67758 ht_slot *aMerge = 0; /* List to be merged */
67760 u32 iSub = 0; /* Index into aSub array */
67763 memset(aSub, 0, sizeof(aSub));
67764 assert( nList<=HASHTABLE_NPAGE && nList>0 );
67767 for(iList=0; iList<nList; iList++){
67770 for(iSub=0; iList & (1<<iSub); iSub++){
67835 ** it only runs if there is actually content in the log (mxFrame>0).
67837 assert( pWal->ckptLock && pWal->hdr.mxFrame>0 );
67850 memset(p, 0, nByte);
67853 SEH_FREE_ON_ERROR(0, p);
67871 for(j=0; j<nEntry; j++){
67882 SEH_FREE_ON_ERROR(p, 0);
67884 p = 0;
67895 ** blocking locks are successfully enabled, or 0 otherwise.
67908 ** or 0 otherwise.
67911 int res = 0;
67925 int tmout = 0;
67940 assert( pWal->readLock<0 || bLock==0 );
67952 pWal->writeLock = 0;
67965 # define walEnableBlocking(x) 0
67967 # define walEnableBlockingMs(pWal, ms) 0
67976 ** lock is successfully obtained or the busy-handler returns 0.
68003 return (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
68028 pWal->hdr.mxFrame = 0;
68029 sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
68032 AtomicStore(&pInfo->nBackfill, 0);
68033 pInfo->nBackfillAttempted = 0;
68034 pInfo->aReadMark[1] = 0;
68036 assert( pInfo->aReadMark[0]==0 );
68076 int sync_flags, /* Flags for OsSync() (or 0) */
68081 WalIterator *pIter = 0; /* Wal iterator context */
68082 u32 iDbpage = 0; /* Next database page to write */
68083 u32 iFrame = 0; /* Wal frame containing data for iDbpage */
68097 assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
68117 xBusy = 0;
68127 assert( rc==SQLITE_OK || pIter==0 );
68131 && (rc = walBusyLock(pWal,xBusy,pBusyArg,WAL_READ_LOCK(0),1))==SQLITE_OK
68145 sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_START, 0);
68162 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
68182 sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_DONE, 0);
68200 walUnlockExclusive(pWal, WAL_READ_LOCK(0), 1);
68241 rc = sqlite3OsTruncate(pWal->pWalFd, 0);
68249 SEH_FREE_ON_ERROR(pIter, 0);
68295 if( pWal->exclusiveMode==0 ){
68300 if( pWal->writeLock==2 ) pWal->writeLock = 0;
68302 (pWal->readLock<0 ? 0 : (S << WAL_READ_LOCK(pWal->readLock)))
68303 | (pWal->writeLock ? (E << WAL_WRITE_LOCK) : 0)
68304 | (pWal->ckptLock ? (E << WAL_CKPT_LOCK) : 0)
68306 for(ii=0; ii<SQLITE_SHM_NLOCK; ii++){
68312 pWal->pFree = 0;
68315 pWal->pWiValue = 0;
68328 if( pWal->exclusiveMode==0 ){
68332 (pWal->readLock<0 ? 0 : (S << WAL_READ_LOCK(pWal->readLock)))
68333 | (pWal->writeLock ? (E << WAL_WRITE_LOCK) : 0)
68334 | (pWal->ckptLock ? (E << WAL_CKPT_LOCK) : 0)
68336 | (pWal->pSnapshot ? (pWal->lockMask & (1 << WAL_CKPT_LOCK)) : 0)
68349 int iRet = 0;
68352 pWal->iSysErrno = 0;
68367 int sync_flags, /* Flags to pass to OsSync() (or 0) */
68373 int isDelete = 0; /* True to unlink wal and wal-index files */
68385 if( zBuf!=0
68392 SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0
68404 }else if( pWal->mxWalSize>=0 ){
68408 ** non-negative value (pWal->mxWalSize>=0). Note that we truncate
68411 walLimitSize(pWal, 0);
68420 sqlite3OsDelete(pWal->pVfs, pWal->zWalName, 0);
68431 ** Try to read the wal-index header. Return 0 on success and 1 if
68453 assert( pWal->nWiData>0 && pWal->apWiData[0] );
68462 ** When reading, read [0] first then [1]. Writes are in the reverse order.
68472 memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */
68476 if( memcmp(&h1, &h2, sizeof(h1))!=0 ){
68479 if( h1.isInit==0 ){
68482 walChecksumBytes(1, (u8*)&h1, sizeof(h1)-sizeof(h1.aCksum), 0, aCksum);
68483 if( aCksum[0]!=h1.aCksum[0] || aCksum[1]!=h1.aCksum[1] ){
68490 pWal->szPage = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
68496 return 0;
68512 ** to 0.
68522 /* Ensure that page 0 of the wal-index (the page that contains the
68526 rc = walIndexPage(pWal, 0, &page0);
68536 assert( page0==0 );
68537 assert( pWal->writeLock==0 );
68548 testcase( page0!=0 );
68550 assert( page0!=0 || pWal->writeLock==0 );
68563 if( pWal->bShmUnreliable==0 && (pWal->readOnly & WAL_SHM_RDONLY) ){
68579 if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
68591 if( bWriteLock==0 ){
68592 pWal->writeLock = 0;
68603 if( badHdr==0 && pWal->hdr.iVersion!=WALINDEX_MAX_VERSION ){
68608 walIndexClose(pWal, 0);
68609 pWal->bShmUnreliable = 0;
68610 assert( pWal->nWiData>0 && pWal->apWiData[0]==0 );
68653 u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */
68662 assert( pWal->nWiData>0 && pWal->apWiData[0] );
68664 /* Take WAL_READ_LOCK(0). This has the effect of preventing any
68667 rc = walLockShared(pWal, WAL_READ_LOCK(0));
68672 pWal->readLock = 0;
68684 ** the WAL_READ_LOCK(0) which prevents a checkpoint, a writer might
68696 rc = sqlite3OsShmMap(pWal->pDbFd, 0, WALINDEX_PGSZ, 0, &pDummy);
68718 ** wal-index header has mxFrame==0, then it must be safe to proceed
68724 rc = (pWal->hdr.mxFrame==0 ? SQLITE_OK : WAL_RETRY);
68729 rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0);
68742 assert( (pWal->szPage & (pWal->szPage-1))==0 );
68746 if( aFrame==0 ){
68756 aSaveCksum[0] = pWal->hdr.aFrameCksum[0];
68778 pWal->hdr.aFrameCksum[0] = aSaveCksum[0];
68785 for(i=0; i<pWal->nWiData; i++){
68787 pWal->apWiData[i] = 0;
68789 pWal->bShmUnreliable = 0;
68800 ** int cnt = 0;
68822 # define WAL_RETRY_BLOCKED_MASK 0x10000000
68824 # define WAL_RETRY_BLOCKED_MASK 0
68838 ** checkpointed. If useWal==0 then this routine calls walIndexReadHdr()
68858 ** in the range 0 <= pWal->readLock < WAL_NREADER. If pWal->readLock==(-1)
68862 ** use WAL frames up to and including pWal->hdr.mxFrame if pWal->readLock>0
68863 ** Or if pWal->readLock==0, then the reader will ignore the WAL
68866 ** this routine will always set pWal->readLock>0 on success.
68881 int nBlockTmout = 0;
68884 assert( pWal->readLock<0 ); /* Not currently locked */
68887 assert( (pWal->readOnly & WAL_SHM_RDONLY)==0 || useWal==0 );
68938 if( pWal->bShmUnreliable==0 ){
68957 if( pWal->apWiData[0]==0 ){
68982 assert( pWal->nWiData>0 );
68983 assert( pWal->apWiData[0]!=0 );
68993 && ((pWal->bGetSnapshot==0 && pWal->pSnapshot==0) || pWal->hdr.mxFrame==0)
68999 rc = walLockShared(pWal, WAL_READ_LOCK(0));
69004 ** may have been appended to the log before READ_LOCK(0) was obtained.
69005 ** When holding READ_LOCK(0), the reader ignores the entire log file,
69007 ** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from
69011 ** is wrapped and written for that matter) before the READ_LOCK(0)
69016 walUnlockShared(pWal, WAL_READ_LOCK(0));
69019 pWal->readLock = 0;
69031 mxReadMark = 0;
69032 mxI = 0;
69047 if( (pWal->readOnly & WAL_SHM_RDONLY)==0
69048 && (mxReadMark<mxFrame || mxI==0)
69063 if( mxI==0 ){
69064 assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 );
69079 assert((rc&0xFF)!=SQLITE_BUSY||rc==SQLITE_BUSY||rc==SQLITE_BUSY_TIMEOUT);
69080 return (rc&0xFF)==SQLITE_BUSY ? WAL_RETRY : rc;
69156 assert( i - sLoc.iZero - 1 >=0 );
69168 if( rc!=SQLITE_OK || 0==memcmp(pBuf1, pBuf2, szPage) ){
69202 assert( pWal->readLock>=0 );
69207 if( pBuf1==0 || pBuf2==0 ){
69215 pWal->ckptLock = 0;
69233 int cnt = 0; /* Number of TryBeginRead attempts */
69235 int ckptLock = 0;
69236 int bChanged = 0;
69240 assert( pWal->ckptLock==0 );
69241 assert( pWal->nSehTry>0 );
69245 if( memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
69269 rc = walTryBeginRead(pWal, pChanged, 0, &cnt);
69271 testcase( (rc&0xff)==SQLITE_BUSY );
69272 testcase( (rc&0xff)==SQLITE_IOERR );
69278 if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
69294 assert( pWal->readLock>0 || pWal->hdr.mxFrame==0 );
69306 assert( pWal->readLock>0 );
69365 assert( pWal->writeLock==0 || pWal->readLock<0 );
69367 if( pWal->readLock>=0 ){
69387 u32 iRead = 0; /* If !=0, WAL frame to return data from */
69393 assert( pWal->readLock>=0 || pWal->lockError );
69395 /* If the "last page" field of the wal-index header snapshot is 0, then
69397 ** in this case as an optimization. Likewise, if pWal->readLock==0,
69401 if( iLast==0 || (pWal->readLock==0 && pWal->bShmUnreliable==0) ){
69402 *piRead = 0;
69446 while( (iH = AtomicLoad(&sLoc.aHash[iKey]))!=0 ){
69452 if( (nCollide--)==0 ){
69453 *piRead = 0;
69466 u32 iRead2 = 0;
69468 assert( pWal->bShmUnreliable || pWal->minFrame>0 );
69469 for(iTest=iLast; iTest>=pWal->minFrame && iTest>0; iTest--){
69521 sz = (sz&0xfe00) + ((sz&0x0001)<<16);
69533 if( pWal && ALWAYS(pWal->readLock>=0) ){
69536 return 0;
69561 assert( !memcmp(&pWal->hdr,(void*)pWal->apWiData[0],sizeof(WalIndexHdr)) );
69568 assert( pWal->readLock>=0 );
69569 assert( pWal->writeLock==0 && pWal->iReCksum==0 );
69589 if( memcmp(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr))!=0 ){
69597 pWal->writeLock = 0;
69609 pWal->writeLock = 0;
69610 pWal->iReCksum = 0;
69611 pWal->truncateOnCommit = 0;
69661 pWal->iReCksum = 0;
69674 aWalData[0] = pWal->hdr.mxFrame;
69675 aWalData[1] = pWal->hdr.aFrameCksum[0];
69690 assert( aWalData[3]!=pWal->nCkpt || aWalData[0]<=pWal->hdr.mxFrame );
69697 aWalData[0] = 0;
69701 if( aWalData[0]<pWal->hdr.mxFrame ){
69702 pWal->hdr.mxFrame = aWalData[0];
69703 pWal->hdr.aFrameCksum[0] = aWalData[1];
69710 pWal->iReCksum = 0;
69722 ** it sets pWal->hdr.mxFrame to 0. Otherwise, pWal->hdr.mxFrame is left
69733 if( pWal->readLock==0 ){
69736 if( pInfo->nBackfill>0 ){
69741 /* If all readers are using WAL_READ_LOCK(0) (in other words if no
69756 walUnlockShared(pWal, WAL_READ_LOCK(0));
69758 cnt = 0;
69763 assert( (rc&0xff)!=SQLITE_BUSY ); /* BUSY not possible when useWal==1 */
69764 testcase( (rc&0xff)==SQLITE_IOERR );
69806 assert( WAL_SYNC_FLAGS(p->syncFlags)!=0 );
69808 if( iAmt==0 || rc ) return rc;
69820 int nTruncate, /* The commit flag. Usually 0. >0 for commit */
69852 if( aBuf==0 ) return SQLITE_NOMEM_BKPT;
69859 assert( pWal->iReCksum>0 );
69866 pWal->hdr.aFrameCksum[0] = sqlite3Get4byte(aBuf);
69870 pWal->iReCksum = 0;
69898 int sync_flags /* Flags to pass to OsSync() (or 0) */
69903 PgHdr *pLast = 0; /* Last frame in list */
69904 int nExtra = 0; /* Number of extra copies of last page */
69908 u32 iFirst = 0; /* First frame that may be overwritten */
69914 /* If this frame set completes a transaction, then nTruncate>0. If
69915 ** nTruncate==0 then this frame set does not complete the transaction. */
69916 assert( (isCommit!=0)==(nTruncate!=0) );
69919 { int cnt; for(cnt=0, p=pList; p; p=p->pDirty, cnt++){}
69926 if( memcmp(&pWal->hdr, (void *)pLive, sizeof(WalIndexHdr))!=0 ){
69942 if( iFrame==0 ){
69946 sqlite3Put4byte(&aWalHdr[0], (WAL_MAGIC | SQLITE_BIGENDIAN));
69950 if( pWal->nCkpt==0 ) sqlite3_randomness(8, pWal->hdr.aSalt);
69952 walChecksumBytes(1, aWalHdr, WAL_HDRSIZE-2*4, 0, aCksum);
69953 sqlite3Put4byte(&aWalHdr[24], aCksum[0]);
69958 pWal->hdr.aFrameCksum[0] = aCksum[0];
69962 rc = sqlite3OsWrite(pWal->pWalFd, aWalHdr, sizeof(aWalHdr), 0);
69987 w.iSyncPoint = 0;
69995 int nDbSize; /* 0 normally. Positive == commit flag */
70001 if( iFirst && (p->pDirty || isCommit==0) ){
70002 u32 iWrite = 0;
70004 assert( rc==SQLITE_OK || iWrite==0 );
70008 if( pWal->iReCksum==0 || iWrite<pWal->iReCksum ){
70021 nDbSize = (isCommit && p->pDirty==0) ? nTruncate : 0;
70049 if( isCommit && WAL_SYNC_FLAGS(sync_flags)!=0 ){
70061 assert( pLast!=0 );
70074 if( isCommit && pWal->truncateOnCommit && pWal->mxWalSize>=0 ){
70080 pWal->truncateOnCommit = 0;
70090 if( (p->flags & PGHDR_WAL_APPEND)==0 ) continue;
70094 assert( pLast!=0 || nExtra==0 );
70095 while( rc==SQLITE_OK && nExtra>0 ){
70103 pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16));
70135 int sync_flags /* Flags to pass to OsSync() (or 0) */
70161 int sync_flags, /* Flags to sync db file with (or 0) */
70168 int isChanged = 0; /* True if a new wal-index header is loaded */
70172 assert( pWal->ckptLock==0 );
70173 assert( pWal->writeLock==0 );
70177 assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
70196 testcase( rc!=SQLITE_OK && xBusy2!=0 );
70206 ** writer lock retried until either the busy-handler returns 0 or the
70215 xBusy2 = 0;
70234 sqlite3OsUnfetch(pWal->pDbFd, 0, 0);
70263 memset(&pWal->hdr, 0, sizeof(WalIndexHdr));
70267 sqlite3WalDb(pWal, 0);
70273 pWal->ckptLock = 0;
70285 ** the last call, then return 0.
70288 u32 ret = 0;
70291 pWal->iCallback = 0;
70303 ** or if the acquisition of the lock fails, then return 0. If the
70310 ** be released. Return 1 if the transition is made and 0 if the
70322 assert( pWal->writeLock==0 );
70332 assert( pWal->readLock>=0 || pWal->lockError );
70334 assert( pWal->readLock>=0 || (op<=0 && pWal->exclusiveMode==0) );
70336 if( op==0 ){
70345 rc = 0;
70347 }else if( op>0 ){
70349 assert( pWal->readLock>=0 );
70376 static const u32 aZero[4] = { 0, 0, 0, 0 };
70378 assert( pWal->readLock>=0 && pWal->writeLock==0 );
70380 if( memcmp(&pWal->hdr.aFrameCksum[0],aZero,16)==0 ){
70381 *ppSnapshot = 0;
70385 if( pRet==0 ){
70401 if( pSnapshot && ((WalIndexHdr*)pSnapshot)->iVersion==0 ){
70402 /* iVersion==0 means that this is a call to sqlite3_snapshot_get(). In
70405 ** file, it does not take read-lock 0 if the wal file has been completely
70406 ** checkpointed. Taking read-lock 0 would work, but then it would be
70409 ** to user expectations, so we avoid it by not taking read-lock 0. */
70413 pWal->bGetSnapshot = 0;
70425 /* aSalt[0] is a copy of the value stored in the wal file header. It
70427 if( pHdr1->aSalt[0]<pHdr2->aSalt[0] ) return -1;
70428 if( pHdr1->aSalt[0]>pHdr2->aSalt[0] ) return +1;
70431 return 0;
70482 assert( pWal==0 || pWal->readLock>=0 );
70483 return (pWal ? pWal->szPage : 0);
70538 ** | Ptr(0) | Key(0) | Ptr(1) | Key(1) | ... | Key(N-1) | Ptr(N) |
70541 ** All of the keys on the page that Ptr(0) points to have values less
70542 ** than Key(0). All of the keys on page Ptr(1) and its subpages have
70543 ** values greater than Key(0) and less than Key(1). All of the keys
70573 ** 0 16 Header string: "SQLite format 3\000"
70644 ** 0 1 Flags. 1: intkey, 2: zerodata, 4: leafdata, 8: leaf
70693 ** 0x00 becomes 0x00000000
70694 ** 0x7f becomes 0x0000007f
70695 ** 0x81 0x00 becomes 0x00000080
70696 ** 0x82 0x00 becomes 0x00000100
70697 ** 0x80 0x7f becomes 0x0000007f
70698 ** 0x81 0x91 0xd1 0xac 0x78 becomes 0x12345678
70699 ** 0x81 0x81 0x81 0x81 0x01 becomes 0x10204081
70771 #define PTF_INTKEY 0x01
70772 #define PTF_ZERODATA 0x02
70773 #define PTF_LEAFDATA 0x04
70774 #define PTF_LEAF 0x08
70796 u8 hdrOffset; /* 100 for page 1. 0 otherwise */
70797 u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
70890 #define TRANS_NONE 0
70918 ** may not be modified once it is initially set as long as nRef>0.
70920 ** thereafter is unchanged as long as nRef>0.
70980 #define BTS_READ_ONLY 0x0001 /* Underlying file is readonly */
70981 #define BTS_PAGESIZE_FIXED 0x0002 /* Page size can no longer be changed */
70982 #define BTS_SECURE_DELETE 0x0004 /* PRAGMA secure_delete is enabled */
70983 #define BTS_OVERWRITE 0x0008 /* Overwrite deleted content with zeros */
70984 #define BTS_FAST_SECURE 0x000c /* Combination of the previous two */
70985 #define BTS_INITIALLY_EMPTY 0x0010 /* Database was empty at trans start */
70986 #define BTS_NO_WAL 0x0020 /* Do not open write-ahead-log files */
70987 #define BTS_EXCLUSIVE 0x0040 /* pWriter has an exclusive lock */
70988 #define BTS_PENDING 0x0080 /* Waiting for read-locks to clear */
71040 ** SKIPNEXT sqlite3BtreeNext() is a no-op if skipNext>0 and
71041 ** sqlite3BtreePrevious() is no-op if skipNext<0.
71043 ** eState=SKIPNEXT if skipNext!=0
71066 u8 curIntKey; /* Value of apPage[0]->intKey */
71077 #define BTCF_WriteFlag 0x01 /* True if a write cursor */
71078 #define BTCF_ValidNKey 0x02 /* True if info.nKey is valid */
71079 #define BTCF_ValidOvfl 0x04 /* True if aOverflow is valid */
71080 #define BTCF_AtLast 0x08 /* Cursor is pointing to the last entry */
71081 #define BTCF_Incrblob 0x10 /* True if an incremental I/O handle */
71082 #define BTCF_Multiple 0x20 /* Maybe another cursor on the same btree */
71083 #define BTCF_Pinned 0x40 /* Cursor is busy and cannot be moved */
71115 #define CURSOR_VALID 0
71149 ** 0 or 1 parent pages. (In this context 'database page' refers
71186 assert( p->pBt->inTransaction!=TRANS_NONE || p->pBt->nTransaction==0 ); \
71200 #define ISAUTOVACUUM(pBt) 0
71219 Pgno nCkPage; /* Pages in the database. 0 for partial check */
71237 #define get2byte(x) ((x)[0]<<8 | (x)[1])
71238 #define put2byte(p,v) ((p)[0] = (u8)((v)>>8), (p)[1] = (u8)(v))
71254 # define get2byteAligned(x) ((x)[0]<<8 | (x)[1])
71268 assert( p->locked==0 );
71289 p->locked = 0;
71316 assert( p->pNext==0 || p->pNext->pBt>p->pBt );
71317 assert( p->pPrev==0 || p->pPrev->pBt<p->pBt );
71318 assert( p->pNext==0 || p->pNext->db==p->db );
71319 assert( p->pPrev==0 || p->pPrev->db==p->db );
71320 assert( p->sharable || (p->pNext==0 && p->pPrev==0) );
71323 assert( !p->locked || p->wantToLock>0 );
71324 assert( p->sharable || p->wantToLock==0 );
71331 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );
71365 assert( pLater->pNext==0 || pLater->pNext->pBt>pLater->pBt );
71366 assert( !pLater->locked || pLater->wantToLock>0 );
71386 assert( p->wantToLock>0 );
71388 if( p->wantToLock==0 ){
71402 assert( p->sharable==0 || p->locked==0 || p->wantToLock>0 );
71403 assert( p->sharable==0 || p->locked==0 || p->db==p->pBt->db );
71404 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->pBt->mutex) );
71405 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->db->mutex) );
71407 return (p->sharable==0 || p->locked);
71431 for(i=0; i<db->nDb; i++){
71435 skipOk = 0;
71441 if( db->noSharedCache==0 ) btreeEnterAll(db);
71447 for(i=0; i<db->nDb; i++){
71453 if( db->noSharedCache==0 ) btreeLeaveAll(db);
71466 return 0;
71468 for(i=0; i<db->nDb; i++){
71472 (p->wantToLock==0 || !sqlite3_mutex_held(p->pBt->mutex)) ){
71473 return 0;
71494 assert( db!=0 );
71495 if( db->pVfs==0 && db->nDb==0 ) return 1;
71497 assert( iDb>=0 && iDb<db->nDb );
71498 if( !sqlite3_mutex_held(db->mutex) ) return 0;
71501 assert( p!=0 );
71502 return p->sharable==0 || p->locked==1;
71506 #else /* SQLITE_THREADSAFE>0 above. SQLITE_THREADSAFE==0 below */
71522 for(i=0; i<db->nDb; i++){
71580 #if 0
71596 #define get2byteNotZero(X) (((((int)get2byte(X))-1)&0xffff)+1)
71601 #define BTALLOC_ANY 0 /* Allocate any page */
71607 ** defined, or 0 if it is. For example:
71614 #define IfNotOmitAV(expr) 0
71627 SQLITE_PRIVATE BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
71629 static BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
71664 #define hasReadConflicts(a, b) 0
71673 pBt->nSeek = 0;
71692 p->pgno, sqlite3PagerFilename(p->pBt->pPager, 0)
71714 #if 0
71727 if( iRoot>0 ){
71752 ** table with root page iRoot. Return 1 if it does and 0 if not.
71757 ** assert( hasSharedCacheTableLock(pBtree, iRoot, 0, WRITE_LOCK) );
71777 Pgno iTab = 0;
71784 if( (pBtree->sharable==0)
71795 if( isIndex && (!pSchema || (pSchema->schemaFlags&DB_SchemaLoaded)==0) ){
71805 int bSeen = 0;
71838 return 0;
71866 && 0==(p->pBtree->db->flags & SQLITE_ReadUncommit)
71871 return 0;
71887 assert( p->db!=0 );
71905 if( pBt->pWriter!=p && (pBt->btsFlags & BTS_EXCLUSIVE)!=0 ){
71955 BtLock *pLock = 0;
71962 assert( p->db!=0 );
71968 assert( 0==(p->db->flags&SQLITE_ReadUncommit) || eLock==WRITE_LOCK );
72024 assert( p->sharable || 0==*ppIter );
72025 assert( p->inTrans>0 );
72027 SHARED_LOCK_TRACE(pBt, "clearAllLocks", 0, 0);
72031 assert( (pBt->btsFlags & BTS_EXCLUSIVE)==0 || pBt->pWriter==pLock->pBtree );
72044 assert( (pBt->btsFlags & BTS_PENDING)==0 || pBt->pWriter );
72046 pBt->pWriter = 0;
72053 ** set the BTS_PENDING flag to 0.
72068 SHARED_LOCK_TRACE(pBt, "downgradeLocks", 0, 0);
72072 pBt->pWriter = 0;
72152 pBtree->hasIncrblobCur = 0;
72154 if( (p->curFlags & BTCF_Incrblob)!=0 ){
72236 pBt->pHasContent = 0;
72244 if( pCur->iPage>=0 ){
72245 for(i=0; i<pCur->iPage; i++){
72269 assert( 0==pCur->pKey );
72286 rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey);
72288 memset(((u8*)pKey)+pCur->nKey, 0, 9+8);
72312 assert( 0==pCur->pKey );
72321 pCur->skipNext = 0;
72361 assert( pExcept==0 || pExcept->pBt==pBt );
72363 if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ) break;
72381 if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){
72388 testcase( p->iPage>=0 );
72403 pCur->pKey = 0;
72426 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
72428 if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
72435 pIdxKey = 0;
72450 int skipNext = 0;
72460 rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
72464 pCur->pKey = 0;
72494 assert( offsetof(BtCursor, eState)==0 );
72506 assert( offsetof(BtCursor, eState)==0 );
72526 assert( pCur!=0 );
72536 *pDifferentRow = 0;
72554 memset(&w, 0, sizeof(w));
72560 assert( pExpr!=0 );
72561 assert( w.u.aMem!=0 );
72573 assert( x==BTREE_SEEK_EQ || x==BTREE_BULKLOAD || x==0 );
72584 ** Return 0 (not a valid page) for pgno==1 since there is
72592 if( pgno<2 ) return 0;
72623 assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) );
72626 if( key==0 ){
72631 rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage, 0);
72636 if( ((char*)sqlite3PagerGetExtra(pDbPage))[0]!=0 ){
72644 if( offset<0 ){
72681 rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage, 0);
72682 if( rc!=0 ){
72688 if( offset<0 ){
72693 assert( pEType!=0 );
72709 ** Given a btree page and a cell index (0 means the first cell on
72768 assert( nPayload>=0 );
72800 assert( pPage->leaf==0 );
72806 pInfo->nPayload = 0;
72807 pInfo->nLocal = 0;
72808 pInfo->pPayload = 0;
72821 assert( pPage->leaf==0 || pPage->leaf==1 );
72823 assert( pPage->childPtrSize==0 );
72833 if( nPayload>=0x80 ){
72835 nPayload &= 0x7f;
72837 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
72838 }while( (*pIter)>=0x80 && pIter<pEnd );
72850 if( iKey>=0x80 ){
72853 if( x>=0x80 ){
72855 if( x>=0x80 ){
72856 iKey = (iKey<<7) ^ 0x10204000 ^ (x = *++pIter);
72857 if( x>=0x80 ){
72858 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++pIter);
72859 if( x>=0x80 ){
72860 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++pIter);
72861 if( x>=0x80 ){
72862 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++pIter);
72863 if( x>=0x80 ){
72864 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++pIter);
72865 if( x>=0x80 ){
72866 iKey = (iKey<<8) ^ 0x8000 ^ (*++pIter);
72873 iKey ^= 0x204000;
72876 iKey ^= 0x4000;
72886 assert( nPayload>=0 );
72908 assert( pPage->leaf==0 || pPage->leaf==1 );
72909 assert( pPage->intKeyLeaf==0 );
72912 if( nPayload>=0x80 ){
72914 nPayload &= 0x7f;
72916 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
72917 }while( *(pIter)>=0x80 && pIter<pEnd );
72925 assert( nPayload>=0 );
72940 int iCell, /* The cell index. First cell is 0 */
72976 if( nSize>=0x80 ){
72978 nSize &= 0x7f;
72980 nSize = (nSize<<7) | (*++pIter & 0x7f);
72981 }while( *(pIter)>=0x80 && pIter<pEnd );
73016 assert( pPage->childPtrSize==0 );
73018 if( nSize>=0x80 ){
73020 nSize &= 0x7f;
73022 nSize = (nSize<<7) | (*++pIter & 0x7f);
73023 }while( *(pIter)>=0x80 && pIter<pEnd );
73061 while( (*pIter++)&0x80 && pIter<pEnd );
73080 if( nSize>=0x80 ){
73082 nSize &= 0x7f;
73084 nSize = (nSize<<7) | (*++pIter & 0x7f);
73085 }while( *(pIter)>=0x80 && pIter<pEnd );
73091 if( (*pIter++)&0x80
73092 && (*pIter++)&0x80
73093 && (*pIter++)&0x80
73094 && (*pIter++)&0x80
73095 && (*pIter++)&0x80
73096 && (*pIter++)&0x80
73097 && (*pIter++)&0x80
73098 && (*pIter++)&0x80 ){ pIter++; }
73137 assert( pCell!=0 );
73182 assert( pPage->pBt!=0 );
73184 assert( pPage->nOverflow==0 );
73205 if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){
73208 int sz2 = 0;
73240 if( nCell>0 ){
73244 for(i=0; i<nCell; i++){
73256 assert( pc>=0 && pc<=iCellLast );
73269 data[hdr+7] = 0;
73272 assert( pPage->nFree>=0 );
73278 data[hdr+1] = 0;
73279 data[hdr+2] = 0;
73280 memset(&data[iCellFirst], 0, cbrk-iCellFirst);
73309 assert( pc>0 );
73316 if( (x = size - nByte)>=0 ){
73322 if( aData[hdr+7]>57 ) return 0;
73332 return 0;
73348 return 0;
73355 return 0;
73382 assert( nByte>=0 ); /* Minimum cell size is 4 */
73384 assert( pPage->nOverflow==0 );
73394 ** integer, so a value of 0 is used in its place. */
73398 if( top==0 && pPage->pBt->usableSize==65536 ){
73435 assert( pPage->nCell>0 || CORRUPT_DB );
73436 assert( pPage->nFree>=0 );
73473 u8 hdr; /* Page header size. 0 or 100 */
73474 int nFrag = 0; /* Reduction in fragmentation */
73481 assert( pPage->pBt!=0 );
73494 if( data[iPtr+1]==0 && data[iPtr]==0 ){
73495 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
73499 if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
73507 assert( iFreeBlk>iPtr || iFreeBlk==0 || CORRUPT_DB );
73547 memset(&data[iStart], 0, iSize);
73561 assert( iSize>=0 && iSize<=0xffff );
73575 ** PTF_ZERODATA (0x02, 2)
73576 ** PTF_LEAFDATA | PTF_INTKEY (0x05, 5)
73577 ** PTF_ZERODATA | PTF_LEAF (0x0a, 10)
73578 ** PTF_LEAFDATA | PTF_INTKEY | PTF_LEAF (0x0d, 13)
73583 assert( pPage->hdrOffset==(pPage->pgno==1 ? 100 : 0) );
73588 pPage->childPtrSize = 0;
73598 pPage->intKey = 0;
73599 pPage->intKeyLeaf = 0;
73605 pPage->intKey = 0;
73606 pPage->intKeyLeaf = 0;
73613 pPage->leaf = 0;
73615 pPage->intKey = 0;
73616 pPage->intKeyLeaf = 0;
73622 pPage->intKeyLeaf = 0;
73629 pPage->intKey = 0;
73630 pPage->intKeyLeaf = 0;
73653 assert( pPage->pBt!=0 );
73654 assert( pPage->pBt->db!=0 );
73660 assert( pPage->nFree<0 );
73678 if( pc>0 ){
73697 if( next>0 ){
73741 for(i=0; i<pPage->nCell; i++){
73770 assert( pPage->pBt!=0 );
73771 assert( pPage->pBt->db!=0 );
73776 assert( pPage->isInit==0 );
73780 /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
73782 if( decodeFlags(pPage, data[0]) ){
73787 pPage->nOverflow = 0;
73804 assert( pPage->nCell>0
73831 memset(&data[hdr], 0, pBt->usableSize - hdr);
73834 first = hdr + ((flags&PTF_LEAF)==0 ? 12 : 8);
73835 memset(&data[hdr+1], 0, 4);
73836 data[hdr+7] = 0;
73844 pPage->nOverflow = 0;
73847 pPage->nCell = 0;
73863 pPage->hdrOffset = pgno==1 ? 100 : 0;
73889 assert( flags==0 || flags==PAGER_GET_NOCONTENT || flags==PAGER_GET_READONLY );
73909 return 0;
73939 *ppPage = 0;
73944 *ppPage = 0;
73948 if( pPage->isInit==0 ){
73953 *ppPage = 0;
73972 assert( pPage->pDbPage!=0 );
73982 assert( pPage!=0 );
73985 assert( pPage->pDbPage!=0 );
74011 *ppPage = 0;
74014 (*ppPage)->isInit = 0;
74016 *ppPage = 0;
74033 assert( sqlite3PagerPageRefcount(pData)>0 );
74036 pPage->isInit = 0;
74088 BtShared *pBt = 0; /* Shared part of btree structure */
74090 sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */
74096 const int isTempDb = zFilename==0 || zFilename[0]==0;
74102 const int isMemdb = 0;
74104 const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
74106 || (vfsFlags & SQLITE_OPEN_MEMORY)!=0;
74109 assert( db!=0 );
74110 assert( pVfs!=0 );
74112 assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
74115 assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 );
74118 assert( (flags & BTREE_SINGLE)==0 || isTempDb );
74123 if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){
74142 if( isTempDb==0 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=0) ){
74176 assert( pBt->nRef>0 );
74177 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0))
74180 for(iDb=db->nDb-1; iDb>=0; iDb--){
74210 if( pBt==0 ){
74223 memset(&zDbHeader[16], 0, 8);
74226 if( pBt==0 ){
74244 pBt->pCursor = 0;
74245 pBt->pPage1 = 0;
74257 || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
74258 pBt->pageSize = 0;
74261 ** leave the autoVacuum mode at 0 (do not auto-vacuum), even if
74267 pBt->autoVacuum = (SQLITE_DEFAULT_AUTOVACUUM ? 1 : 0);
74268 pBt->incrVacuum = (SQLITE_DEFAULT_AUTOVACUUM==2 ? 1 : 0);
74271 nReserve = 0;
74279 pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
74280 pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
74286 assert( (pBt->pageSize & 7)==0 ); /* 8-byte alignment of pageSize */
74297 if( pBt->mutex==0 ){
74318 for(i=0; i<db->nDb; i++){
74319 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
74323 p->pPrev = 0;
74346 sqlite3PagerClose(pBt->pPager, 0);
74350 *ppBtree = 0;
74358 if( sqlite3BtreeSchema(p, 0, 0)==0 ){
74371 assert( rc!=SQLITE_OK || sqlite3BtreeConnectionCount(*ppBtree)>0 );
74385 int removed = 0;
74391 if( pBt->nRef<=0 ){
74421 assert( pBt!=0 );
74422 assert( pBt->pTmpSpace==0 );
74425 assert( pBt->pCursor!=0 && (pBt->pCursor->curFlags & BTCF_WriteFlag)!=0 );
74427 if( pBt->pTmpSpace==0 ){
74430 memset(pCur, 0, sizeof(*pCur));
74449 memset(pBt->pTmpSpace, 0, 8);
74461 pBt->pTmpSpace = 0;
74492 sqlite3BtreeRollback(p, SQLITE_OK, 0);
74499 assert( p->wantToLock==0 && p->locked==0 );
74511 sqlite3DbFree(0, pBt->pSchema);
74517 assert( p->wantToLock==0 );
74518 assert( p->locked==0 );
74551 ** using mxPage of 0 is a way to query the current spill size.
74563 #if SQLITE_MAX_MMAP_SIZE>0
74576 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
74611 ** the first byte past the 1GB boundary, 0x40000000) needs to occur
74617 ** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size
74624 assert( nReserve>=0 && nReserve<=255 );
74633 assert( nReserve>=0 && nReserve<=255 );
74635 ((pageSize-1)&pageSize)==0 ){
74636 assert( (pageSize & 7)==0 );
74695 ** No changes are made if mxPage is 0 or negative.
74709 ** newFlag==0 Both BTS_SECURE_DELETE and BTS_OVERWRITE are cleared
74726 if( p==0 ) return 0;
74730 if( newFlag>=0 ){
74754 if( (pBt->btsFlags & BTS_PAGESIZE_FIXED)!=0 && (av ?1:0)!=pBt->autoVacuum ){
74757 pBt->autoVacuum = av ?1:0;
74758 pBt->incrVacuum = av==2 ?1:0;
74767 ** enabled 1 is returned. Otherwise 0.
74796 if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){
74797 while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; }
74798 if( pDb->bSyncSet==0
74829 u32 nPageFile = 0; /* Number of pages in the database file */
74832 assert( pBt->pPage1==0 );
74835 rc = btreeGetPage(pBt, 1, &pPage1, 0);
74843 if( nPage==0 || memcmp(24+(u8*)pPage1->aData, 92+(u8*)pPage1->aData,4)!=0 ){
74846 if( (pBt->db->flags & SQLITE_ResetDatabase)!=0 ){
74847 nPage = 0;
74849 if( nPage>0 ){
74857 if( memcmp(page1, zMagicHeader, 16)!=0 ){
74884 if( page1[19]==2 && (pBt->btsFlags & BTS_NO_WAL)==0 ){
74885 int isOpen = 0;
74891 if( isOpen==0 ){
74906 ** version 3.6.0, we require them to be fixed.
74908 if( memcmp(&page1[21], "\100\040\040",3)!=0 ){
74917 if( ((pageSize-1)&pageSize)!=0
74923 assert( (pageSize & 7)==0 );
74949 if( sqlite3WritableSchema(pBt->db)==0 ){
74966 pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0);
74967 pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0);
74981 ** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow
75000 pBt->pPage1 = 0;
75019 int r = 0;
75021 if( (wrOnly==0 || (pCur->curFlags & BTCF_WriteFlag)!=0)
75038 assert( countValidCursors(pBt,0)==0 || pBt->inTransaction>TRANS_NONE );
75039 if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){
75043 pBt->pPage1 = 0;
75059 if( pBt->nPage>0 ){
75063 assert( pP1!=0 );
75069 data[16] = (u8)((pBt->pageSize>>8)&0xff);
75070 data[17] = (u8)((pBt->pageSize>>16)&0xff);
75078 memset(&data[24], 0, 100-24);
75082 assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
75083 assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
75100 p->pBt->nPage = 0;
75160 assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 );
75163 && sqlite3PagerIsreadonly(pPager)==0
75169 if( (pBt->btsFlags & BTS_READ_ONLY)!=0 && wrflag ){
75176 sqlite3 *pBlock = 0;
75182 || (pBt->btsFlags & BTS_PENDING)!=0
75209 if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY;
75216 if( pBt->pPage1==0 && wrflag ){
75225 ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
75230 while( pBt->pPage1==0 && SQLITE_OK==(rc = lockBtree(pBt)) );
75233 if( (pBt->btsFlags & BTS_READ_ONLY)!=0 ){
75249 (void)sqlite3PagerWalWriteLock(pPager, 0);
75259 }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
75261 sqlite3PagerWalDb(pPager, 0);
75313 ** open savepoints. If the second parameter is greater than 0 and
75328 || (p->inTrans==TRANS_READ && wrflag!=0)
75338 ** open savepoints. If the second parameter is greater than 0 and
75366 for(i=0; i<nCell; i++){
75417 for(i=0; i<nCell; i++){
75506 if( nextOvfl!=0 ){
75519 rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0);
75569 if( nFreeList==0 ){
75582 if( bCommit==0 ){
75601 Pgno iNear = 0; /* nearby parameter for allocateBtreePage() */
75603 rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0);
75615 if( bCommit==0 ){
75643 if( bCommit==0 ){
75699 }else if( nFree>0 ){
75700 rc = saveAllCursors(pBt, 0, 0);
75703 rc = incrVacuumStep(pBt, nFin, nOrig, 0);
75728 assert( p!=0 );
75756 for(iDb=0; ALWAYS(iDb<db->nDb); iDb++){
75769 if( nVac==0 ){
75778 rc = saveAllCursors(pBt, 0, 0);
75783 if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
75786 put4byte(&pBt->pPage1->aData[32], 0);
75787 put4byte(&pBt->pPage1->aData[36], 0);
75849 rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zSuperJrnl, 0);
75865 pBt->bDoTruncate = 0;
75876 ** reaches 0, set the shared state to TRANS_NONE. The unlockBtreeIfUnused()
75881 if( 0==pBt->nTransaction ){
75934 assert( pBt->nTransaction>0 );
75936 if( rc!=SQLITE_OK && bCleanup==0 ){
75956 rc = sqlite3BtreeCommitPhaseOne(p, 0);
75958 rc = sqlite3BtreeCommitPhaseTwo(p, 0);
75994 assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
75998 if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){
76002 (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0);
76024 testcase( nPage==0 );
76025 if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
76046 assert( writeOnly==1 || writeOnly==0 );
76050 rc = tripCode = saveAllCursors(pBt, 0, 0);
76051 if( rc ) writeOnly = 0;
76057 assert( rc==SQLITE_OK || (writeOnly==0 && rc2==SQLITE_OK) );
76074 if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
76078 assert( countValidCursors(pBt, 1)==0 );
76111 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
76112 assert( iStatement>0 );
76142 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
76145 rc = saveAllCursors(pBt, 0, 0);
76151 if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){
76152 pBt->nPage = 0;
76159 assert( CORRUPT_DB || pBt->nPage>0 );
76183 ** cursors open with wrFlag==0 on the same table. Otherwise
76199 ** return a null row (2-bytes: 0x01 0x00).
76211 int wrFlag, /* 1 to write. 0 read-only */
76219 assert( wrFlag==0
76228 assert( hasSharedCacheTableLock(p, iTable, pKeyInfo!=0, (wrFlag?2:1))
76230 assert( wrFlag==0 || !hasReadConflicts(p, iTable) );
76234 assert( wrFlag==0 || p->inTrans==TRANS_WRITE );
76236 assert( wrFlag==0 || (pBt->btsFlags & BTS_READ_ONLY)==0 );
76241 }else if( btreePagecount(pBt)==0 ){
76242 assert( wrFlag==0 );
76243 iTable = 0;
76254 pCur->curFlags = 0;
76268 pCur->curPagerFlags = 0;
76269 if( pBt->pTmpSpace==0 ) return allocateTempSpace(pBt);
76278 int wrFlag, /* 1 to write. 0 read-only */
76291 int wrFlag, /* 1 to write. 0 read-only */
76325 if( (pBt->openFlags & BTREE_SINGLE)==0 ) return 0;
76326 if( pBt->pCursor!=pCur ) return 0;
76327 if( pCur->pNext!=0 ) return 0;
76328 if( pCur->pBtree!=pBtree ) return 0;
76342 memset(p, 0, offsetof(BtCursor, BTCURSOR_FIRST_UNINIT));
76354 assert( pBt->pCursor!=0 );
76371 if( (pBt->openFlags & BTREE_SINGLE) && pBt->pCursor==0 ){
76374 assert( pBtree->sharable==0 );
76379 pCur->pBtree = 0;
76394 if( a->nKey!=b->nKey ) return 0;
76395 if( a->pPayload!=b->pPayload ) return 0;
76396 if( a->nPayload!=b->nPayload ) return 0;
76397 if( a->nLocal!=b->nLocal ) return 0;
76398 if( a->nSize!=b->nSize ) return 0;
76403 memset(&info, 0, sizeof(info));
76411 if( pCur->info.nSize==0 ){
76430 assert( pCur!=0 );
76452 assert( (pCur->curFlags & BTCF_Pinned)==0 );
76456 assert( (pCur->curFlags & BTCF_Pinned)!=0 );
76532 Pgno next = 0;
76533 MemPage *pPage = 0;
76565 assert( next==0 || rc==SQLITE_DONE );
76567 rc = btreeGetPage(pBt, ovfl, &pPage, (ppPage==0) ? PAGER_GET_READONLY : 0);
76568 assert( rc==SQLITE_OK || pPage==0 );
76598 int eOp, /* 0 -> copy from page, 1 -> copy to page */
76620 ** 0: The operation is a read. Populate the overflow cache.
76653 int iIdx = 0;
76661 assert( eOp==0 || eOp==1 );
76689 offset = 0;
76697 if( rc==SQLITE_OK && amt>0 ){
76707 ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
76710 if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){
76712 if( pCur->aOverflow==0
76717 aNew = 0;
76721 if( aNew==0 ){
76727 memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
76731 assert( pCur->aOverflow[0]==nextPage
76732 || pCur->aOverflow[0]==0
76734 assert( pCur->aOverflow[0]!=0 || pCur->aOverflow[offset/ovflSize]==0 );
76747 assert( rc==SQLITE_OK && amt>0 );
76751 assert( pCur->aOverflow[iIdx]==0
76768 rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
76773 ** range of data that is being read (eOp==0) or written (eOp!=0).
76794 if( eOp==0 /* (1) */
76795 && offset==0 /* (2) */
76813 (eOp==0 ? PAGER_GET_READONLY : 0)
76820 offset = 0;
76824 if( amt==0 ) return rc;
76832 if( rc==SQLITE_OK && amt>0 ){
76859 assert( pCur->iPage>=0 && pCur->pPage );
76860 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
76881 return rc ? rc : accessPayload(pCur, offset, amt, pBuf, 0);
76886 return accessPayload(pCur, offset, amt, pBuf, 0);
76896 ** the key if index btrees (pPage->intKey==0) and is the data for
76898 ** key/data is written into *pAmt. If *pAmt==0, then the value
76917 assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
76922 assert( pCur->info.nSize>0 );
76930 amt = MAX(0, (int)(pCur->pPage->aDataEnd - pCur->info.pPayload));
76970 assert( pCur->iPage>=0 );
76974 pCur->info.nSize = 0;
76978 pCur->ix = 0;
76981 assert( pCur->pPage!=0 || rc!=SQLITE_OK );
77028 assert( pCur->iPage>0 );
77036 pCur->info.nSize = 0;
77060 ** specify a KeyInfo structure the flags byte is set to 0x05 or 0x0D,
77062 ** structure the flags byte is set to 0x02 or 0x0A, indicating an index
77073 assert( pCur->eState < CURSOR_REQUIRESEEK || pCur->iPage<0 );
77074 assert( pCur->pgnoRoot>0 || pCur->iPage<0 );
77076 if( pCur->iPage>=0 ){
77082 pRoot = pCur->pPage = pCur->apPage[0];
77085 }else if( pCur->pgnoRoot==0 ){
77103 pCur->iPage = 0;
77116 ** if pCur->iPage>=0). But this is not so if the database is corrupted
77119 assert( pRoot->intKey==1 || pRoot->intKey==0 );
77120 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
77125 pCur->ix = 0;
77126 pCur->info.nSize = 0;
77129 if( pRoot->nCell>0 ){
77179 MemPage *pPage = 0;
77190 assert( pCur->info.nSize==0 );
77191 assert( (pCur->curFlags & BTCF_ValidNKey)==0 );
77196 ** on success. Set *pRes to 0 if the cursor actually points to something
77206 assert( pCur->pPage->nCell>0 );
77207 *pRes = 0;
77210 assert( pCur->pgnoRoot==0 || (pCur->pPage!=0 && pCur->pPage->nCell==0) );
77227 for(ii=0; ii<pCur->iPage; ii++){
77228 if( pCur->aiIdx[ii]!=pCur->apPage[ii]->nCell ) return 0;
77230 return pCur->ix==pCur->pPage->nCell-1 && pCur->pPage->leaf!=0;
77235 ** on success. Set *pRes to 0 if the cursor actually points to something
77242 *pRes = 0;
77250 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
77261 if( CURSOR_VALID==pCur->eState && (pCur->curFlags & BTCF_AtLast)!=0 ){
77263 *pRes = 0;
77282 ** *pRes<0 The cursor is left pointing at an entry that
77286 ** *pRes==0 The cursor is left pointing at an entry that
77289 ** *pRes>0 The cursor is left pointing at an entry that
77303 assert( pCur->pKeyInfo==0 );
77304 assert( pCur->eState!=CURSOR_VALID || pCur->curIntKey!=0 );
77308 if( pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0 ){
77310 *pRes = 0;
77314 if( (pCur->curFlags & BTCF_AtLast)!=0 ){
77324 *pRes = 0;
77325 rc = sqlite3BtreeNext(pCur, 0);
77345 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
77354 assert( pCur->pPage->nCell > 0 );
77355 assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey );
77370 assert( pPage->nCell>0 );
77372 lwr = 0;
77374 assert( biasRight==0 || biasRight==1 );
77380 while( 0x80 <= *(pCell++) ){
77402 pCur->info.nSize = 0;
77403 *pRes = 0;
77407 assert( lwr+upr>=0 );
77430 pCur->info.nSize = 0;
77431 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
77462 nCell = pCell[0];
77469 }else if( !(pCell[1] & 0x80)
77470 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
77491 for(i=0; i<pCur->iPage; i++){
77493 if( pCur->aiIdx[i]<pPage->nCell ) return 0;
77511 ** *pRes<0 The cursor is left pointing at an entry that
77515 ** *pRes==0 The cursor is left pointing at an entry that
77518 ** *pRes>0 The cursor is left pointing at an entry that
77535 assert( pCur->pKeyInfo!=0 );
77542 pIdxKey->errCode = 0;
77544 || pIdxKey->default_rc==0
77566 && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0
77572 if( pCur->iPage>0
77573 && indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0
77588 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
77599 assert( pCur->pPage->nCell > 0 );
77600 assert( pCur->curIntKey==0 );
77601 assert( pIdxKey!=0 );
77614 assert( pPage->nCell>0 );
77615 assert( pPage->intKey==0 );
77616 lwr = 0;
77631 nCell = pCell[0];
77638 }else if( !(pCell[1] & 0x80)
77639 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
77660 testcase( nCell<0 ); /* True if key size is 2^32 or more */
77661 testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
77662 testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
77669 if( pCellKey==0 ){
77674 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
77675 memset(((u8*)pCellKey)+nCell,0,nOverrun); /* Fix uninit warnings */
77685 (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
77688 if( c<0 ){
77690 }else if( c>0 ){
77693 assert( c==0 );
77694 *pRes = 0;
77701 assert( lwr+upr>=0 );
77725 pCur->info.nSize = 0;
77732 pCur->ix = 0;
77749 pCur->info.nSize = 0;
77750 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
77785 if( pCur->eState!=CURSOR_VALID ) return 0;
77786 if( NEVER(pCur->pPage->leaf==0) ) return -1;
77789 for(i=0; i<pCur->iPage; i++){
77809 ** If bit 0x01 of the F argument in sqlite3BtreeNext(C,F) is 1, then the
77822 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
77832 if( pCur->skipNext>0 ) return SQLITE_OK;
77838 if( sqlite3FaultSim(412) ) pPage->isInit = 0;
77850 if( pCur->iPage==0 ){
77858 return sqlite3BtreeNext(pCur, 0);
77873 assert( flags==0 || flags==1 );
77874 pCur->info.nSize = 0;
77903 ** If bit 0x01 of the F argument to sqlite3BtreePrevious(C,F) is 1, then
77914 assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
77915 assert( pCur->info.nSize==0 );
77926 if( pCur->skipNext<0 ) return SQLITE_OK;
77931 if( sqlite3FaultSim(412) ) pPage->isInit = 0;
77941 while( pCur->ix==0 ){
77942 if( pCur->iPage==0 ){
77948 assert( pCur->info.nSize==0 );
77949 assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
77954 rc = sqlite3BtreePrevious(pCur, 0);
77963 assert( flags==0 || flags==1 );
77966 pCur->info.nSize = 0;
77968 || pCur->ix==0
77969 || pCur->pPage->leaf==0
77988 ** If the "nearby" parameter is not 0, then an effort is made to
78010 MemPage *pTrunk = 0;
78011 MemPage *pPrevTrunk = 0;
78015 assert( eMode==BTALLOC_ANY || (nearby>0 && IfNotOmitAV(pBt->autoVacuum)) );
78025 if( n>0 ){
78028 u8 searchList = 0; /* If the free-list must be searched for 'nearby' */
78029 u32 nSearch = 0; /* Count of the number of search attempts */
78039 assert( nearby>0 );
78041 rc = ptrmapGet(pBt, nearby, &eType, 0);
78070 iTrunk = get4byte(&pPrevTrunk->aData[0]);
78081 rc = btreeGetUnusedPage(pBt, iTrunk, &pTrunk, 0);
78084 pTrunk = 0;
78087 assert( pTrunk!=0 );
78088 assert( pTrunk->aData!=0 );
78092 if( k==0 && !searchList ){
78096 assert( pPrevTrunk==0 );
78102 memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
78104 pTrunk = 0;
78119 searchList = 0;
78124 if( k==0 ){
78126 memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
78132 memcpy(&pPrevTrunk->aData[0], &pTrunk->aData[0], 4);
78146 rc = btreeGetUnusedPage(pBt, iNewTrunk, &pNewTrunk, 0);
78155 memcpy(&pNewTrunk->aData[0], &pTrunk->aData[0], 4);
78167 put4byte(&pPrevTrunk->aData[0], iNewTrunk);
78170 pTrunk = 0;
78173 }else if( k>0 ){
78178 if( nearby>0 ){
78180 closest = 0;
78182 for(i=0; i<k; i++){
78201 closest = 0;
78225 noContent = !btreeGetHasContent(pBt, *pPgno)? PAGER_GET_NOCONTENT : 0;
78231 *ppPage = 0;
78234 searchList = 0;
78238 pPrevTrunk = 0;
78259 int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate))? PAGER_GET_NOCONTENT:0;
78272 MemPage *pPg = 0;
78294 *ppPage = 0;
78305 assert( rc!=SQLITE_OK || (*ppPage)->isInit==0 );
78322 MemPage *pTrunk = 0; /* Free-list trunk page */
78323 Pgno iTrunk = 0; /* Page number of free-list trunk page */
78353 if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
78354 || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0)
78358 memset(pPage->aData, 0, pPage->pBt->pageSize);
78365 ptrmapPut(pBt, iPage, PTRMAP_FREEPAGE, 0, &rc);
78376 if( nFree!=0 ){
78384 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
78402 ** 3.6.0, databases with freelist trunk pages holding more than
78407 ** to 3.6.0 or later) we should consider fixing the conditional above
78419 if( pPage && (pBt->btsFlags & BTS_SECURE_DELETE)==0 ){
78435 if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0)) ){
78443 put4byte(&pPage->aData[4], 0);
78449 pPage->isInit = 0;
78488 assert( nOvfl>0 ||
78492 Pgno iNext = 0;
78493 MemPage *pOvfl = 0;
78495 /* 0 is not a legal page number and page 1 cannot be an
78505 if( ( pOvfl || ((pOvfl = btreePageLookup(pBt, ovflPgno))!=0) )
78593 assert( pX->nKey<=0x7fffffff && pX->pKey!=0 );
78609 pPayload[nPayload] = 0;
78615 memset(pPayload+nSrc, 0, nPayload-nSrc);
78630 pToRelease = 0;
78631 pgnoOvfl = 0;
78664 assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );
78673 }else if( nSrc>0 ){
78677 memset(pPayload, 0, n);
78680 if( nPayload<=0 ) break;
78685 if( spaceLeft==0 ){
78686 MemPage *pOvfl = 0;
78697 rc = allocateBtreePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, 0);
78724 assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );
78735 put4byte(pPrior, 0);
78757 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
78760 assert( idx>=0 );
78765 assert( pPage->nFree>=0 );
78783 if( pPage->nCell==0 ){
78784 memset(&data[hdr+1], 0, 4);
78785 data[hdr+7] = 0;
78824 int idx = 0; /* Where to write new cell content in data[] */
78829 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
78836 assert( pPage->nFree>=0 );
78837 assert( iChild>0 );
78857 assert( j==0 || pPage->aiOvfl[j-1]<(u16)i ); /* Overflows in sorted order */
78858 assert( j==0 || i==pPage->aiOvfl[j-1]+1 ); /* Overflows are sequential */
78871 assert( idx >= 0 );
78887 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
78919 int idx = 0; /* Where to write new cell content in data[] */
78924 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
78931 assert( pPage->nFree>=0 );
78932 assert( pPage->nOverflow==0 );
78947 assert( j==0 || pPage->aiOvfl[j-1]<(u16)i ); /* Overflows in sorted order */
78948 assert( j==0 || i==pPage->aiOvfl[j-1]+1 ); /* Overflows are sequential */
78961 assert( idx >= 0 );
78971 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
79052 ** ixNx[0] = Number of cells in Child-1.
79058 ** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
79061 ** ixNx[0] = Number of cells in Child-1.
79087 assert( idx>=0 && idx+N<=p->nCell );
79088 while( N>0 ){
79089 assert( p->apCell[idx]!=0 );
79090 if( szCell[idx]==0 ){
79105 assert( N>=0 && N<p->nCell );
79106 assert( p->szCell[N]==0 );
79111 assert( N>=0 && N<p->nCell );
79148 assert( nCell>0 );
79151 if( j>(u32)usableSize ){ j = 0; }
79155 for(k=0; pCArray->ixNx[k]<=i; k++){}
79162 assert( sz>0 );
79189 pPg->nOverflow = 0;
79191 put2byte(&aData[hdr+1], 0);
79194 aData[hdr+7] = 0x00;
79206 ** (part of page pPg) to populate. After cell apCell[0] is written to the
79237 assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
79238 if( iEnd<=iFirst ) return 0;
79240 for(k=0; pCArray->ixNx[k]<=i ; k++){}
79245 assert( pCArray->szCell[i]!=0 );
79247 if( (aData[1]==0 && aData[2]==0) || (pSlot = pageFindSlot(pPg,sz,&rc))==0 ){
79276 return 0;
79297 int nRet = 0;
79300 int nFree = 0;
79313 sz = pCArray->szCell[i]; assert( sz>0 );
79316 for(j=0; j<nFree; j++){
79326 if( nFree>=(int)(sizeof(aOfst)/sizeof(aOfst[0])) ){
79327 for(j=0; j<nFree; j++){
79330 nFree = 0;
79334 if( &aData[iAfter]>pEnd ) return 0;
79340 for(j=0; j<nFree; j++){
79381 assert( nCell>=0 );
79401 assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
79402 assert( nAdd>=0 );
79413 for(i=0; i<pPg->nOverflow; i++){
79415 if( iCell>=0 && iCell<nNew ){
79430 assert( nCell>=0 );
79442 pPg->nOverflow = 0;
79448 for(i=0; i<nNew && !CORRUPT_DB; i++){
79454 assert( 0==memcmp(pCell, &aData[iOff],
79502 if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT; /* dbfuzz001.test */
79503 assert( pPage->nFree>=0 );
79504 assert( pParent->nFree>=0 );
79510 rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
79515 u8 *pCell = pPage->apOvfl[0];
79521 assert( CORRUPT_DB || pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
79527 b.apEnd[0] = pPage->aDataEnd;
79528 b.ixNx[0] = 2;
79529 b.ixNx[NB*2-1] = 0x7fffffff;
79530 rc = rebuildPage(&b, 0, 1, pNew);
79568 while( (*(pCell++)&0x80) && pCell<pStop );
79570 while( ((*(pOut++) = *(pCell++))&0x80) && pCell<pStop );
79575 0, pPage->pgno);
79589 #if 0
79597 for(i=0; i<nPage; i++){
79604 for(j=0; j<pPage->nCell; j++){
79654 int const iToHdr = ((pTo->pgno==1) ? 100 : 0);
79673 pTo->isInit = 0;
79738 int nMaxCells = 0; /* Allocated size of apCell, szCell, aFrom. */
79739 int nNew = 0; /* Number of pages in apNew[] */
79744 u16 leafCorrection; /* 4 if pPage is a leaf. 0 if not */
79747 int pageFlags; /* Value of pPage->aData[0] */
79748 int iSpace1 = 0; /* First unused byte of aSpace1[] */
79749 int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */
79764 memset(abDone, 0, sizeof(abDone));
79766 memset(&b, 0, sizeof(b)-sizeof(b.ixNx[0]));
79767 b.ixNx[NB*2-1] = 0x7fffffff;
79777 assert( pParent->nOverflow==0 || pParent->nOverflow==1 );
79778 assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );
79783 assert( pParent->nFree>=0 );
79798 nxDiv = 0;
79800 assert( bBulk==0 || bBulk==1 );
79801 if( iParentIdx==0 ){
79802 nxDiv = 0;
79819 rc = getAndInitPage(pBt, pgno, &apOld[i], 0);
79822 memset(apOld, 0, (i+1)*sizeof(MemPage*));
79825 if( apOld[i]->nFree<0 ){
79828 memset(apOld, 0, (i)*sizeof(MemPage*));
79833 if( (i--)==0 ) break;
79835 if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
79836 apDiv[i] = pParent->apOvfl[0];
79839 pParent->nOverflow = 0;
79885 b.apCell = sqlite3StackAllocRaw(0, szScratch );
79886 if( b.apCell==0 ){
79907 ** leafCorrection: 4 if pPage is a leaf. 0 if pPage is not a leaf.
79910 b.pRef = apOld[0];
79913 for(i=0; i<nOld; i++){
79925 if( pOld->aData[0]!=apOld[0]->aData[0] ){
79947 memset(&b.szCell[b.nCell], 0, sizeof(b.szCell[0])*(limit+pOld->nOverflow));
79948 if( pOld->nOverflow>0 ){
79949 if( NEVER(limit<pOld->aiOvfl[0]) ){
79953 limit = pOld->aiOvfl[0];
79954 for(j=0; j<limit; j++){
79959 for(k=0; k<pOld->nOverflow; k++){
79960 assert( k==0 || pOld->aiOvfl[k-1]+1==pOld->aiOvfl[k] );/* NOTE 1 */
79986 assert( leafCorrection==0 || leafCorrection==4 );
79989 assert( leafCorrection==0 );
79990 assert( pOld->hdrOffset==0 || CORRUPT_DB );
79998 ** does exist, pad it with 0x00 bytes. */
80001 aSpace1[iSpace1++] = 0x00;
80026 for(i=k=0; i<nOld; i++, k++){
80038 assert( p->nFree>=0 );
80040 for(j=0; j<p->nOverflow; j++){
80046 for(i=0; i<k; i++){
80052 szNew[k-1] = 0;
80061 sz = 0;
80076 sz = 0;
80083 }else if( cntNew[i] <= (i>0 ? cntNew[i-1] : 0) ){
80100 for(i=k-1; i>0; i--){
80115 if( szRight!=0
80116 && (bBulk || szRight+szD+2 > szLeft-(szR+(i==k-1?0:2)))){
80124 }while( r>=0 );
80127 if( cntNew[i-1] <= (i>1 ? cntNew[i-2] : 0) ){
80135 ** (1) We found one or more cells (cntNew[0])>0), or
80140 assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) || CORRUPT_DB);
80142 apOld[0]->pgno, apOld[0]->nCell,
80143 nOld>=2 ? apOld[1]->pgno : 0, nOld>=2 ? apOld[1]->nCell : 0,
80144 nOld>=3 ? apOld[2]->pgno : 0, nOld>=3 ? apOld[2]->nCell : 0
80150 pageFlags = apOld[0]->aData[0];
80151 for(i=0; i<k; i++){
80155 apOld[i] = 0;
80165 assert( i>0 );
80166 rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0);
80195 for(i=0; i<nNew; i++){
80200 for(i=0; i<nNew-1; i++){
80227 apNew[0]->pgno, szNew[0], cntNew[0],
80228 nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0,
80229 nNew>=2 ? cntNew[1] - cntNew[0] - !leafData : 0,
80230 nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0,
80231 nNew>=3 ? cntNew[2] - cntNew[1] - !leafData : 0,
80232 nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0,
80233 nNew>=4 ? cntNew[3] - cntNew[2] - !leafData : 0,
80234 nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0,
80235 nNew>=5 ? cntNew[4] - cntNew[3] - !leafData : 0
80240 assert( apNew[nNew-1]!=0 );
80246 if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){
80269 MemPage *pNew = pOld = apNew[0];
80271 int iNew = 0;
80272 int iOld = 0;
80274 for(i=0; i<b.nCell; i++){
80279 assert( iOld>=0 && iOld<NB );
80310 for(i=0; i<nNew-1; i++){
80319 assert( b.apCell[j]!=0 );
80336 pTemp = 0;
80359 for(k=0; b.ixNx[k]<=j; k++){}
80385 ** to 0, then back up to nNew-1 again, thus making two passes over
80393 int iPg = i<0 ? -i : i;
80394 assert( iPg>=0 && iPg<nNew );
80395 assert( iPg>=1 || i>=0 );
80398 if( i>=0 /* On the upwards pass, or... */
80407 assert( iPg==0 || cntOld[iPg-1]>=cntNew[iPg-1] || abDone[iPg-1] );
80413 if( iPg==0 ){
80414 iNew = iOld = 0;
80415 nNewCell = cntNew[0];
80426 assert( apNew[iPg]->nOverflow==0 );
80432 assert( memcmp(abDone, "\01\01\01\01\01", nNew)==0 );
80434 assert( nOld>0 );
80435 assert( nNew>0 );
80437 if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){
80454 rc = defragmentPage(apNew[0], -1);
80456 assert( apNew[0]->nFree ==
80457 (get2byteNotZero(&apNew[0]->aData[5]) - apNew[0]->cellOffset
80458 - apNew[0]->nCell*2)
80461 copyNodeContent(apNew[0], pParent, &rc);
80462 freePage(apNew[0], &rc);
80467 for(i=0; i<nNew; i++){
80483 #if 0
80484 if( ISAUTOVACUUM(pBt) && rc==SQLITE_OK && apNew[0]->isInit ){
80498 sqlite3StackFree(0, b.apCell);
80499 for(i=0; i<nOld; i++){
80502 for(i=0; i<nNew; i++){
80527 ** an error code is returned and *ppChild is set to 0.
80531 MemPage *pChild = 0; /* Pointer to a new child page */
80532 Pgno pgnoChild = 0; /* Page number of the new child page */
80535 assert( pRoot->nOverflow>0 );
80544 rc = allocateBtreePage(pBt,&pChild,&pgnoChild,pRoot->pgno,0);
80551 *ppChild = 0;
80563 pRoot->nOverflow*sizeof(pRoot->aiOvfl[0]));
80565 pRoot->nOverflow*sizeof(pRoot->apOvfl[0]));
80569 zeroPage(pRoot, pChild->aData[0] & ~PTF_LEAF);
80613 u8 *pFree = 0;
80615 VVA_ONLY( int balance_quick_called = 0 );
80616 VVA_ONLY( int balance_deeper_called = 0 );
80622 if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
80623 if( pPage->nOverflow==0 && pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
80629 }else if( (iPage = pCur->iPage)==0 ){
80636 assert( balance_deeper_called==0 );
80641 pCur->ix = 0;
80642 pCur->aiIdx[0] = 0;
80643 pCur->apPage[0] = pPage;
80660 if( rc==SQLITE_OK && pParent->nFree<0 ){
80667 && pPage->aiOvfl[0]==pPage->nCell
80684 assert( balance_quick_called==0 );
80725 pPage->nOverflow = 0;
80730 assert( pCur->iPage>=0 );
80752 if( nData<=0 ){
80755 for(i=0; i<iAmt && pDest[i]==0; i++){}
80759 memset(pDest + i, 0, iAmt - i);
80770 if( memcmp(pDest, ((u8*)pX->pData) + iOffset, iAmt)!=0 ){
80804 0, pCur->info.nLocal);
80809 assert( nTotal>=0 );
80810 assert( iOffset>=0 );
80815 rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
80851 0, pCur->info.nLocal);
80876 ** been performed. In other words, if seekResult!=0 then the cursor
80878 ** to be inserted. If seekResult<0 then pCur points to a cell that is
80879 ** smaller then (pKey,nKey). If seekResult>0 then pCur points to a cell
80882 ** If seekResult==0, that means pCur is pointing at some unknown location.
80897 int szNew = 0;
80902 unsigned char *newCell = 0;
80905 assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 );
80921 if( loc && pCur->iPage<0 ){
80942 assert( (pCur->curFlags & BTCF_WriteFlag)!=0
80944 && (p->pBt->btsFlags & BTS_READ_ONLY)==0 );
80945 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
80952 assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
80954 if( pCur->pKeyInfo==0 ){
80955 assert( pX->pKey==0 );
80959 invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
80969 assert( loc==0 );
80973 /* On the other hand, BTREE_SAVEPOSITION==0 does not imply
80977 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
80980 assert( pX->nData>=0 && pX->nZero>=0 );
80981 if( pCur->info.nSize!=0
80987 assert( loc==0 );
80988 }else if( loc==0 ){
80994 (flags & BTREE_APPEND)!=0, &loc);
81003 assert( (flags & BTREE_SAVEPOSITION)==0 || loc==0 );
81010 if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
81016 r.default_rc = 0;
81017 r.eqSeen = 0;
81021 (flags & BTREE_APPEND)!=0, &loc);
81030 if( loc==0 ){
81035 x2.nData = (int)pX->nKey; assert( pX->nKey<=0x7fffffff );
81036 x2.nZero = 0;
81045 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
81047 if( pPage->nFree<0 ){
81059 loc==0 ? "overwrite" : "new entry"));
81062 assert( newCell!=0 );
81069 newCell[3] = 0;
81087 pCur->info.nSize = 0;
81088 if( loc==0 ){
81090 assert( idx>=0 );
81129 }else if( loc<0 && pPage->nCell>0 ){
81137 assert( pPage->nOverflow==0 || rc==SQLITE_OK );
81138 assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
81169 pCur->pPage->nOverflow = 0;
81174 assert( pCur->pKey==0 );
81176 if( pCur->pKey==0 ){
81186 assert( pCur->iPage<0 || pCur->pPage->nOverflow==0 );
81215 if( pSrc->info.nPayload<0x80 ){
81220 if( pDest->pKeyInfo==0 ) aOut += putVarint(aOut, iKey);
81234 u8 *pPgnoOut = 0;
81235 Pgno ovflIn = 0;
81236 DbPage *pPageIn = 0;
81237 MemPage *pPageOut = 0;
81257 assert( nOut>0 );
81258 if( nIn>0 ){
81266 if( nOut>0 ){
81268 pPageIn = 0;
81277 }while( rc==SQLITE_OK && nOut>0 );
81279 if( rc==SQLITE_OK && nRem>0 && ALWAYS(pPgnoOut) ){
81281 MemPage *pNew = 0;
81282 rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
81291 put4byte(pPgnoOut, 0);
81296 }while( nRem>0 && rc==SQLITE_OK );
81334 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
81336 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
81338 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
81357 if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){
81376 ** bPreserve==0 Not necessary to save the cursor position
81380 bPreserve = (flags & BTREE_SAVEPOSITION)!=0;
81404 rc = sqlite3BtreePrevious(pCur, 0);
81418 if( pCur->pKeyInfo==0 && p->hasIncrblobCur ){
81419 invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0);
81442 if( pLeaf->nFree<0 ){
81456 assert( pTmp!=0 );
81480 assert( pCur->pPage->nOverflow==0 );
81481 assert( pCur->pPage->nFree>=0 );
81503 assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
81543 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
81546 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
81597 u8 eType = 0;
81598 Pgno iPtrPage = 0;
81603 rc = saveAllCursors(pBt, 0, 0);
81610 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
81624 rc = relocatePage(pBt, pRoot, eType, iPtrPage, pgnoMove, 0);
81631 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
81645 ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
81663 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
81675 assert( (pBt->openFlags & BTREE_SINGLE)==0 || pgnoRoot==2 );
81708 rc = getAndInitPage(pBt, pgno, &pPage, 0);
81710 if( (pBt->openFlags & BTREE_SINGLE)==0
81717 for(i=0; i<pPage->nCell; i++){
81729 if( pPage->intKey ) pnChange = 0;
81737 }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
81764 rc = saveAllCursors(pBt, (Pgno)iTable, 0);
81771 invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
81773 rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
81785 return sqlite3BtreeClearTable(pCur->pBtree, pCur->pgnoRoot, 0);
81804 ** the move. If no page gets moved, *piMoved is set to 0.
81810 MemPage *pPage = 0;
81820 rc = sqlite3BtreeClearTable(p, iTable, 0);
81822 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
81828 *piMoved = 0;
81854 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
81858 rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0);
81863 pMove = 0;
81864 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
81906 ** Read the meta-information out of a database file. Meta[0]
81908 ** through meta[15] are available for use by higher layers. Meta[0]
81913 ** free pages is not visible. So Cookie[0] is the same as Meta[1].
81929 assert( idx>=0 && idx<=15 );
81940 if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
81949 ** Write meta-information back into the database. Meta[0] is
81959 assert( pBt->pPage1!=0 );
81966 assert( pBt->autoVacuum || iMeta==0 );
81967 assert( iMeta==0 || iMeta==1 );
81985 i64 nEntry = 0; /* Value to return in *pnEntry */
81990 *pnEntry = 0;
82022 if( pCur->iPage==0 ){
82063 pCheck->mxErr = 0; /* Causes integrity_check processing to stop */
82064 if( pCheck->nErr==0 ) pCheck->nErr++;
82076 pCheck->mxErr = 0;
82080 assert( db->nProgressOps>0 );
82082 if( (pCheck->nStep % db->nProgressOps)==0
82087 pCheck->mxErr = 0;
82129 assert( pCheck->aPgRef!=0 );
82130 assert( iPg<=pCheck->nCkPage && sizeof(pCheck->aPgRef[0])==1 );
82131 return (pCheck->aPgRef[iPg/8] & (1 << (iPg & 0x07)));
82138 assert( pCheck->aPgRef!=0 );
82139 assert( iPg<=pCheck->nCkPage && sizeof(pCheck->aPgRef[0])==1 );
82140 pCheck->aPgRef[iPg/8] |= (1 << (iPg & 0x07));
82147 ** Return 1 if there are 2 or more references to the page and 0 if
82153 if( iPage>pCheck->nCkPage || iPage==0 ){
82162 return 0;
82209 while( iPage!=0 && pCheck->mxErr ){
82214 if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage, 0) ){
82223 checkPtrmap(pCheck, iPage, PTRMAP_FREEPAGE, 0);
82231 for(i=0; i<(int)n; i++){
82235 checkPtrmap(pCheck, iFreePage, PTRMAP_FREEPAGE, 0);
82249 if( pCheck->pBt->autoVacuum && N>0 ){
82270 ** aHeap[0] is the number of elements on the heap. aHeap[1] is the
82291 assert( aHeap!=0 );
82292 i = ++aHeap[0];
82294 while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){
82303 if( (x = aHeap[0])==0 ) return 0;
82306 aHeap[x] = 0xffffffff;
82307 aHeap[0]--;
82309 while( (j = i*2)<=aHeap[0] ){
82323 ** the tree depth. Root pages return 0. Parents of root pages
82341 MemPage *pPage = 0; /* The page being analyzed */
82360 u32 *heap = 0; /* Min-heap used for checking cell coverage */
82361 u32 x, prev = 0; /* Next and previous entry on the min-heap */
82365 u8 savedIsInit = 0;
82370 if( pCheck->mxErr==0 ) goto end_of_check;
82373 if( iPage==0 ) return 0;
82374 if( checkRef(pCheck, iPage) ) return 0;
82377 if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
82387 pPage->isInit = 0;
82388 if( (rc = btreeInitPage(pPage))!=0 ){
82394 if( (rc = btreeComputeFreeSpace(pPage))!=0 ){
82411 if( pPage->leaf || pPage->intKey==0 ){
82431 keyCanBeEqual = 0;
82436 heap[0] = 0;
82441 for(i=nCell-1; i>=0 && pCheck->mxErr; i--){
82452 doCoverageCheck = 0;
82459 doCoverageCheck = 0;
82469 keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
82484 checkList(pCheck, 0, pgnoOvfl, nPage);
82496 keyCanBeEqual = 0;
82510 pCheck->zPfx = 0;
82511 if( doCoverageCheck && pCheck->mxErr>0 ){
82517 heap[0] = 0;
82518 for(i=nCell-1; i>=0; i--){
82525 assert( heap!=0 );
82533 while( i>0 ){
82546 assert( j==0 || j>i+size ); /* Enforced by btreeComputeFreeSpace() */
82563 nFrag = 0;
82566 if( (prev&0xffff)>=(x>>16) ){
82571 nFrag += (x>>16) - (prev&0xffff) - 1;
82575 nFrag += usableSize - (prev&0xffff) - 1;
82581 if( heap[0]==0 && nFrag!=data[hdr+7] ){
82609 ** malloc is returned if *pnErr is non-zero. If *pnErr==0 then NULL is
82612 ** If the first entry in aRoot[] is 0, that indicates that the list of
82636 int bPartial = 0; /* True if not checking all btrees */
82640 assert( nRoot>0 );
82641 assert( aCnt!=0 );
82643 /* aRoot[0]==0 means this is a partial check */
82644 if( aRoot[0]==0 ){
82647 if( aRoot[1]!=1 ) bCkFreelist = 0;
82653 assert( nRef>=0 );
82654 memset(&sCheck, 0, sizeof(sCheck));
82660 sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
82662 if( sCheck.nCkPage==0 ){
82672 if( sCheck.heap==0 ){
82686 sCheck.zPfx = 0;
82694 Pgno mx = 0;
82696 for(i=0; (int)i<nRoot; i++) if( mx<aRoot[i] ) mx = aRoot[i];
82704 }else if( get4byte(&pBt->pPage1->aData[64])!=0 ){
82713 for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
82714 sCheck.nRow = 0;
82719 checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
82734 if( getPageReferenced(&sCheck, i)==0 ){
82741 if( getPageReferenced(&sCheck, i)==0 &&
82745 if( getPageReferenced(&sCheck, i)!=0 &&
82759 if( sCheck.nErr==0 ){
82761 *pzOut = 0;
82780 assert( p->pBt->pPager!=0 );
82793 assert( p->pBt->pPager!=0 );
82802 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
82803 return p ? p->inTrans : 0;
82837 return p->nBackup!=0;
82851 ** If the nBytes parameter is 0 and the blob of memory has not yet been
82862 assert( nBytes==0 || nBytes==sizeof(Schema) );
82865 pBt->pSchema = sqlite3DbMallocZero(0, nBytes);
82900 assert( isWriteLock==0 || isWriteLock==1 );
82957 if( (pCsr->curFlags & BTCF_WriteFlag)==0 ){
82960 assert( (pCsr->pBt->btsFlags & BTS_READ_ONLY)==0
82962 assert( hasSharedCacheTableLock(pCsr->pBtree, pCsr->pgnoRoot, 0, 2) );
82995 rc = sqlite3BtreeBeginTrans(pBtree, 0, 0);
82999 rc = sqlite3BtreeBeginTrans(pBtree, 2, 0);
83019 return (pCsr->hints & mask)!=0;
83026 return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
83144 ** function. If an error occurs while doing so, return 0 and write an
83152 int rc = 0;
83161 return 0;
83165 if( i<0 ){
83167 return 0;
83179 rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),0,0);
83216 return 0;
83235 p = 0;
83254 p->isAttached = 0;
83256 if( 0==p->pSrc || 0==p->pDest
83265 p = 0;
83305 assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
83310 assert( nSrcPgsz==nDestPgsz || sqlite3PagerIsMemdb(pDestPager)==0 );
83317 DbPage *pDestPg = 0;
83320 if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg, 0))
83335 ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0;
83336 if( iOff==0 && bUpdate==0 ){
83382 int pgszSrc = 0; /* Source page size */
83383 int pgszDest = 0; /* Destination page size */
83386 if( p==0 ) return SQLITE_MISUSE_BKPT;
83400 int bCloseTrans = 0; /* True if src db requires unlocking */
83416 rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0);
83426 if( p->bDestLocked==0 && rc==SQLITE_OK && setDestPgsz(p)==SQLITE_NOMEM ){
83431 if( SQLITE_OK==rc && p->bDestLocked==0
83454 assert( nSrcPage>=0 );
83455 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
83461 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
83483 if( nSrcPage==0 ){
83523 assert( nDestTruncate>0 );
83543 assert( nDestTruncate==0
83559 rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0);
83567 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1);
83577 PgHdr *pSrcPg = 0;
83579 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg, 0);
83592 rc = sqlite3PagerSync(pDestPager, 0);
83596 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
83601 && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0))
83615 TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0);
83616 TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0);
83642 if( p==0 ) return SQLITE_OK;
83656 assert( pp!=0 );
83659 assert( pp!=0 );
83665 sqlite3BtreeRollback(p->pDest, SQLITE_OK, 0);
83692 if( p==0 ){
83694 return 0;
83706 if( p==0 ){
83708 return 0;
83731 assert( p!=0 );
83749 }while( (p = p->pNext)!=0 );
83800 ** to 0. This is used by the implementations of sqlite3_backup_step()
83804 memset(&b, 0, sizeof(b));
83810 /* 0x7FFFFFFF is the hard limit for the number of pages in a database
83816 sqlite3_backup_step(&b, 0x7FFFFFFF);
83856 /* True if X is a power of two. 0 is considered a power of two here.
83859 #define ISPOWEROF2(X) (((X)&((X)-1))==0)
83869 /* If MEM_Dyn is set then Mem.xDel!=0.
83872 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
83874 /* MEM_Dyn may only be set if Mem.szMalloc==0. In this way we
83875 ** ensure that if Mem.szMalloc>0 then it is safe to do
83878 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
83885 assert( (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob|MEM_Agg))==0 );
83895 assert( ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
83896 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
83897 ((p->flags&MEM_Static)!=0 ? 1 : 0) <= 1 );
83901 |MEM_Dyn|MEM_Ephem|MEM_Static))==0 );
83908 assert( (p->flags & MEM_Cleared)==0 );
83912 assert( p->szMalloc==0
83925 if( (p->flags & (MEM_Str|MEM_Blob)) && p->n>0 ){
83927 ((p->szMalloc>0 && p->z==p->zMalloc)? 1 : 0) +
83928 ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
83929 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
83930 ((p->flags&MEM_Static)!=0 ? 1 : 0) == 1
83957 sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0);
83959 (p->flags & MEM_IntReal)!=0 ? (double)p->u.i : p->u.r);
83960 assert( acc.zText==zBuf && acc.mxAlloc<=0 );
83961 zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
83994 if( (p->flags & MEM_Str)==0 ) return 1;
83999 if( p->szMalloc>0 && p->z==p->zMalloc ){
84003 assert( p->z[p->n]==0 );
84004 assert( p->enc==SQLITE_UTF8 || p->z[(p->n+1)&~1]==0 );
84005 assert( p->enc==SQLITE_UTF8 || p->z[((p->n+1)&~1)+1]==0 );
84007 if( (p->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 ) return 1;
84011 i = j = 0;
84018 if( zBuf[j++]!=z[i] ) return 0;
84042 assert( pMem!=0 );
84053 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84080 testcase( pMem->db==0 );
84084 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
84085 testcase( bPreserve && pMem->z==0 );
84087 assert( pMem->szMalloc==0
84091 if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
84096 if( pMem->zMalloc==0 ) sqlite3_free(pMem->z);
84099 bPreserve = 0;
84101 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
84104 if( pMem->zMalloc==0 ){
84106 pMem->z = 0;
84107 pMem->szMalloc = 0;
84117 if( (pMem->flags&MEM_Dyn)!=0 ){
84118 assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
84141 assert( CORRUPT_DB || szNew>0 );
84142 assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
84144 return sqlite3VdbeMemGrow(pMem, szNew, 0);
84146 assert( (pMem->flags & MEM_Dyn)==0 );
84165 assert( pMem->z!=0 );
84170 pMem->z[pMem->n] = 0;
84180 pMem->z[pMem->n] = 0;
84199 pMem->z[pMem->n] = 0;
84200 pMem->z[pMem->n+1] = 0;
84201 pMem->z[pMem->n+2] = 0;
84213 assert( pMem!=0 );
84214 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84216 if( (pMem->flags & (MEM_Str|MEM_Blob))!=0 ){
84218 if( pMem->szMalloc==0 || pMem->z!=pMem->zMalloc ){
84225 pMem->pScopyFrom = 0;
84238 assert( pMem!=0 );
84240 assert( (pMem->flags&MEM_Blob)!=0 || MemNullNochng(pMem) );
84243 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84247 if( nByte<=0 ){
84248 if( (pMem->flags & MEM_Blob)==0 ) return SQLITE_OK;
84254 assert( pMem->z!=0 );
84257 memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
84268 assert( pMem!=0 );
84269 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84271 testcase( (pMem->flags & (MEM_Term|MEM_Str))==0 );
84296 assert( pMem!=0 );
84297 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84306 pMem->enc = 0;
84311 assert( pMem->z!=0 );
84331 assert( pFunc!=0 );
84332 assert( pMem!=0 );
84333 assert( pMem->db!=0 );
84334 assert( pFunc->xFinalize!=0 );
84335 assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef );
84337 memset(&ctx, 0, sizeof(ctx));
84338 memset(&t, 0, sizeof(t));
84346 assert( (pMem->flags & MEM_Dyn)==0 );
84347 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
84363 assert( pFunc!=0 );
84364 assert( pFunc->xValue!=0 );
84365 assert( (pAccum->flags & MEM_Null)!=0 || pFunc==pAccum->u.pDef );
84366 assert( pAccum->db!=0 );
84368 memset(&ctx, 0, sizeof(ctx));
84389 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
84393 assert( (p->flags & MEM_Agg)==0 );
84397 assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 );
84417 p->szMalloc = 0;
84419 p->z = 0;
84454 ** an SQL-NULL value, return 0.
84459 i64 value = 0;
84465 assert( pMem!=0 );
84466 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84474 }else if( (flags & (MEM_Str|MEM_Blob))!=0 && pMem->z!=0 ){
84477 return 0;
84488 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
84489 double val = (double)0;
84494 assert( pMem!=0 );
84495 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84505 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
84506 return (double)0;
84511 ** Return 1 if pMem represents true, and return 0 if pMem represents false.
84516 if( pMem->flags & (MEM_Int|MEM_IntReal) ) return pMem->u.i!=0;
84526 assert( pMem!=0 );
84529 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84558 assert( pMem!=0 );
84559 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84573 assert( pMem!=0 );
84574 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84594 || (memcmp(&r1, &r2, sizeof(r1))==0
84617 assert( pMem!=0 );
84622 if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){
84625 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
84626 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84628 if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
84637 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))!=0 );
84653 if( (pMem->flags & MEM_Blob)==0 ){
84697 assert( (flags & ~MEM_TypeMask)==0 );
84700 pMem->szMalloc = 0;
84735 pMem->n = 0;
84736 if( n<0 ) n = 0;
84739 pMem->z = 0;
84743 int nByte = n>0?n:1;
84744 if( sqlite3VdbeMemGrow(pMem, nByte, 0) ){
84747 assert( pMem->z!=0 );
84749 memset(pMem->z, 0, nByte);
84750 pMem->n = n>0?n:0;
84845 assert( db!=0 );
84849 if( p==0 ) return SQLITE_NOMEM;
84861 assert( p->db!=0 );
84869 return 0;
84899 assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
84904 pX->pScopyFrom = 0;
84907 pMem->bScopy = 0;
84909 pMem->pScopyFrom = 0;
84929 if( (pFrom->flags&MEM_Static)==0 ){
84948 if( 0==(pFrom->flags&MEM_Static) ){
84964 assert( pFrom->db==0 || sqlite3_mutex_held(pFrom->db->mutex) );
84965 assert( pTo->db==0 || sqlite3_mutex_held(pTo->db->mutex) );
84966 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
84971 pFrom->szMalloc = 0;
85000 u8 enc, /* Encoding of z. 0 for BLOBs */
85007 assert( pMem!=0 );
85008 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
85010 assert( enc!=0 || n>=0 );
85023 if( nByte<0 ){
85024 assert( enc!=0 );
85028 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
85031 }else if( enc==0 ){
85058 testcase( nAlloc==0 );
85077 pMem->n = (int)(nByte & 0x7fffffff);
85120 pMem->z[amt] = 0; /* Overrun area used when reading malformed records */
85134 u32 available = 0; /* Number of bytes available on the local btree page */
85144 assert( pMem->z!=0 );
85150 rc = sqlite3VdbeMemFromBtree(pCur, 0, amt, pMem);
85162 assert( pVal!=0 );
85163 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
85166 assert( (pVal->flags & (MEM_Null))==0 );
85168 if( ExpandBlob(pVal) ) return 0;
85173 if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&SQLITE_PTR_TO_INT(pVal->z)) ){
85174 assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 );
85176 return 0;
85181 sqlite3VdbeMemStringify(pVal, enc, 0);
85182 assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) );
85184 assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
85190 return 0;
85205 if( !pVal ) return 0;
85206 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
85214 return 0;
85226 if( ALWAYS(pVal!=0)
85227 && ALWAYS((pVal->flags & (MEM_Str|MEM_Blob))!=0)
85228 && (pVal->flags & MEM_Dyn)!=0
85233 return 0;
85274 UnpackedRecord *pRec = p->ppRec[0];
85276 if( pRec==0 ){
85290 for(i=0; i<nCol; i++){
85296 pRec = 0;
85299 if( pRec==0 ) return 0;
85300 p->ppRec[0] = pRec;
85343 sqlite3_value **apVal = 0; /* Function arguments */
85344 int nVal = 0; /* Number of function arguments */
85345 FuncDef *pFunc = 0; /* Function definition */
85346 sqlite3_value *pVal = 0; /* New value */
85348 ExprList *pList = 0; /* Function arguments */
85351 assert( pCtx!=0 );
85352 assert( (p->flags & EP_TokenOnly)==0 );
85357 pFunc = sqlite3FindFunction(db, p->u.zToken, nVal, enc, 0);
85359 if( pFunc==0 ) return SQLITE_OK;
85362 if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
85363 || (pFunc->funcFlags & (SQLITE_FUNC_NEEDCOLL|SQLITE_FUNC_RUNONLY))!=0
85369 apVal = (sqlite3_value**)sqlite3DbMallocZero(db, sizeof(apVal[0]) * nVal);
85370 if( apVal==0 ){
85374 for(i=0; i<nVal; i++){
85377 if( apVal[i]==0 || rc!=SQLITE_OK ) goto value_from_function_out;
85382 if( pVal==0 ){
85387 memset(&ctx, 0, sizeof(ctx));
85407 pVal = 0;
85411 for(i=0; i<nVal; i++){
85443 char *zVal = 0;
85444 sqlite3_value *pVal = 0;
85449 assert( pExpr!=0 );
85454 ** on a table column definition, and hence only when pCtx==0. This
85457 assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );
85462 aff = sqlite3AffinityType(pExpr->u.zToken,0);
85471 assert( (ppVal[0][0].flags & MEM_Zero)==0 );
85486 || pLeft->u.zToken[0]!='0' || (pLeft->u.zToken[1] & ~0x20)!='X'
85498 if( pVal==0 ) goto no_mem;
85503 if( op==TK_INTEGER && 0==sqlite3DecOrHexToI64(pExpr->u.zToken, &iVal) ){
85507 if( zVal==0 ) goto no_mem;
85525 assert( (pVal->flags & MEM_IntReal)==0 );
85537 && pVal!=0
85556 if( pVal==0 ) goto no_mem;
85563 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
85571 0, SQLITE_DYNAMIC);
85575 else if( op==TK_FUNCTION && pCtx!=0 ){
85584 pVal->u.i = pExpr->u.zToken[4]==0;
85594 if( pCtx==0 || NEVER(pCtx->pParse->nErr==0) )
85598 assert( *ppVal==0 );
85600 if( pCtx==0 ) sqlite3ValueFree(pVal);
85602 assert( pCtx==0 ); sqlite3ValueFree(pVal);
85624 return pExpr ? valueFromExpr(db, pExpr, enc, affinity, ppVal, 0) : 0;
85637 ** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
85654 sqlite3_value *pVal = 0;
85660 assert( pExpr==0 || pExpr->op!=TK_REGISTER || pExpr->op2!=TK_VARIABLE );
85666 }else if( pExpr->op==TK_VARIABLE && (db->flags & SQLITE_EnableQPSG)==0 ){
85670 if( (v = pParse->pReprepare)!=0 ){
85682 assert( pVal==0 || pVal->db==db );
85694 ** right starting with 0). A single field is populated if:
85696 ** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
85731 int nExtract = 0;
85733 if( pExpr==0 || pExpr->op!=TK_SELECT ){
85741 for(i=0; i<nElem; i++){
85742 sqlite3_value *pVal = 0;
85743 Expr *pElem = (pExpr ? sqlite3VectorFieldSubexpr(pExpr, i) : 0);
85772 return stat4ValueFromExpr(pParse, pExpr, affinity, 0, ppVal);
85790 u32 t = 0; /* a column type code */
85794 u32 szField = 0; /* Size of the current data field */
85799 assert( iCol>0 );
85803 for(i=0; i<=iCol; i++){
85814 if( pMem==0 ){
85816 if( pMem==0 ) return SQLITE_NOMEM_BKPT;
85833 sqlite3 *db = aMem[0].db;
85834 for(i=0; i<nCol; i++){
85871 return valueToText(pVal, enc)!=0 ? pVal->n : 0;
85875 assert( (p->flags & MEM_Null)==0 || (p->flags & (MEM_Str|MEM_Blob))==0 );
85876 if( (p->flags & MEM_Str)!=0 && pVal->enc==enc ){
85879 if( (p->flags & MEM_Str)!=0 && enc!=SQLITE_UTF8 && pVal->enc!=SQLITE_UTF8 ){
85882 if( (p->flags & MEM_Blob)!=0 ){
85889 if( p->flags & MEM_Null ) return 0;
85923 if( p==0 ) return 0;
85924 memset(&p->aOp, 0, sizeof(Vdbe)-offsetof(Vdbe,aOp));
85935 assert( pParse->aLabel==0 );
85936 assert( pParse->nLabel==0 );
85937 assert( p->nOpAlloc==0 );
85938 assert( pParse->szOpAlloc==0 );
85939 sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
85965 if( p==0 ) return;
85967 if( (prepFlags & SQLITE_PREPARE_SAVESQL)==0 ){
85968 p->expmask = 0;
85970 assert( p->zSql==0 );
86002 assert( zId!=0 );
86003 if( pVdbe->pDblStr==0 ) return 0;
86005 if( strcmp(zId, pStr->z)==0 ) return 1;
86007 return 0;
86108 static u64 n = 0;
86136 if( p->db->mallocFailed==0 ){
86158 return sqlite3VdbeAddOp3(p, op, 0, 0, 0);
86161 return sqlite3VdbeAddOp3(p, op, p1, 0, 0);
86164 return sqlite3VdbeAddOp3(p, op, p1, p2, 0);
86172 assert( op>=0 && op<0xff );
86176 assert( p->aOp!=0 );
86179 assert( pOp!=0 );
86181 pOp->p5 = 0;
86185 pOp->p4.p = 0;
86191 pOp->zComment = 0;
86194 pOp->nExec = 0;
86195 pOp->nCycle = 0;
86199 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
86204 pOp->iSrcLine = 0;
86228 assert( pOp!=0 );
86230 pOp->p5 = 0;
86240 pOp->zComment = 0;
86243 pOp->nExec = 0;
86244 pOp->nCycle = 0;
86248 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
86253 pOp->iSrcLine = 0;
86264 return sqlite3VdbeAddOp3(p, OP_Goto, 0, iDest, 0);
86271 return sqlite3VdbeAddOp4(p, OP_String8, 0, iDest, 0, zStr, 0);
86290 for(i=0; (c = zTypes[i])!=0; i++){
86293 sqlite3VdbeAddOp4(p, z==0 ? OP_Null : OP_String8, 0, iDest+i, 0, z, 0);
86326 ** that describes the calling context of the function. 0 means a general
86330 ** while computing a generated column value. 0 is the usual case.
86346 if( pCtx==0 ){
86349 return 0;
86351 pCtx->pOut = 0;
86353 pCtx->pVdbe = 0;
86354 pCtx->isError = 0;
86385 ** 0 means "none".
86389 if( pParse->addrExplain==0 ) return 0;
86412 int addr = 0;
86428 addr = sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
86434 sqlite3VdbeScanStatus(v, iThis, -1, -1, 0, 0);
86443 sqlite3ExplainBreakpoint("POP", 0);
86458 sqlite3VdbeAddOp4(p, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC);
86460 for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
86475 v->pParse->nTempReg = 0;
86476 v->pParse->nRangeReg = 0;
86516 nNewSize*sizeof(p->aLabel[0]));
86517 if( p->aLabel==0 ){
86518 p->nLabelAlloc = 0;
86536 assert( j>=0 );
86542 if( p->nLabelAlloc + p->nLabel < 0 ){
86580 ** memset(&sIter, 0, sizeof(sIter));
86594 int iSub; /* 0 = main program, 1 = first sub-program etc. */
86598 Op *pRet = 0;
86604 if( p->iSub==0 ){
86617 p->iAddr = 0;
86623 for(j=0; j<p->nSub; j++){
86629 pRet = 0;
86652 ** * OP_FkCounter with P2==0 (immediate foreign key constraint)
86664 int hasAbort = 0;
86665 int hasFkCounter = 0;
86666 int hasCreateTable = 0;
86667 int hasCreateIndex = 0;
86668 int hasInitCoroutine = 0;
86672 if( v==0 ) return 0;
86673 memset(&sIter, 0, sizeof(sIter));
86676 while( (pOp = opIterNext(&sIter))!=0 ){
86700 if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
86724 if( pC==0
86740 assert( p->nWrite==0 || p->usesStmtJournal );
86771 assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
86773 p->bIsReader = 0;
86775 assert( p->aOp[0].opcode==OP_Init );
86788 if( pOp->p2!=0 ) p->readOnly = 0;
86801 p->readOnly = 0;
86806 assert( pOp->p2>=0 );
86829 if( pOp->p2<0 ){
86833 assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 );
86835 assert( aLabel!=0 ); /* True because of tag-20230419-1 */
86839 /* OPFLG_JUMP opcodes never have P2==0, though OPFLG_JUMP0 opcodes
86841 assert( pOp->p2>0
86842 || (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP0)!=0 );
86846 || (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)==0 );
86853 assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
86861 pParse->aLabel = 0;
86863 pParse->nLabel = 0;
86865 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
86898 sqlite3_str *pErr = 0;
86899 assert( v!=0 );
86901 assert( pParse!=0 );
86907 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 ){
86909 if( iDest==0 ) continue;
86915 if( iDest<0 ){
86917 assert( j>=0 );
86918 if( j>=-pParse->nLabel || pParse->aLabel[j]<0 ){
86933 if( pErr==0 ){
86934 pErr = sqlite3_str_new(0);
86949 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_INTERNAL, OE_Abort, 0, zErr, 0);
86988 for(i=0; i<p->nOp; i++){
87025 p->aOp = 0;
87044 assert( nOp>0 );
87047 return 0;
87050 for(i=0; i<nOp; i++, aOp++, pOut++){
87054 assert( aOp->p2>=0 );
87055 if( (sqlite3OpcodeProperty[aOp->opcode] & OPFLG_JUMP)!=0 && aOp->p2>0 ){
87060 pOut->p4.p = 0;
87061 pOut->p5 = 0;
87063 pOut->zComment = 0;
87072 sqlite3VdbePrintOp(0, i+p->nOp, &p->aOp[i+p->nOp]);
87086 int addrExplain, /* Address of OP_Explain (or 0) */
87098 memset(pNew, 0, sizeof(ScanStatus));
87123 ScanStatus *pScan = 0;
87125 for(ii=p->nScan-1; ii>=0; ii--){
87128 pScan = 0;
87131 if( addrEnd<0 ) addrEnd = sqlite3VdbeCurrentAddr(p)-1;
87132 for(ii=0; ii<ArraySize(pScan->aAddrRange); ii+=2){
87133 if( pScan->aAddrRange[ii]==0 ){
87155 ScanStatus *pScan = 0;
87157 for(ii=p->nScan-1; ii>=0; ii--){
87160 pScan = 0;
87163 if( addrLoop>0 ) pScan->addrLoop = addrLoop;
87164 if( addrVisit>0 ) pScan->addrVisit = addrVisit;
87176 assert( addr>=0 );
87180 assert( addr>=0 );
87184 assert( addr>=0 || p->db->mallocFailed );
87188 assert( addr>=0 );
87192 assert( p->nOp>0 || p->db->mallocFailed );
87193 if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5;
87229 ** 7 Once 0 8 0
87237 assert( p->aOp[addr].p4type==0 );
87239 sqlite3VdbeGetLastOp(p)->iSrcLine = 0; /* Erase VdbeCoverage() macros */
87253 assert( db!=0 );
87254 if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
87267 assert( db!=0 );
87286 if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4);
87300 if( db->pnBytesFreed==0 ){
87308 if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
87312 if( db->pnBytesFreed==0 ) sqlite3DeleteTable(db, (Table*)p4);
87330 assert( nOp>=0 );
87331 assert( db!=0 );
87360 return pVdbe->pProgram!=0;
87368 if( p->db->mallocFailed ) return 0;
87369 assert( addr>=0 && addr<p->nOp );
87373 pOp->p4.z = 0;
87383 if( p->nOp>0 && p->aOp[p->nOp-1].opcode==op ){
87386 return 0;
87402 if( N==0 || OptimizationDisabled(pParse->db, SQLITE_ReleaseReg) ) return;
87406 if( N<=31 && mask!=0 ){
87407 while( N>0 && (mask&1)!=0 ){
87412 while( N>0 && N<=32 && (mask & MASKBIT32(N-1))!=0 ){
87417 if( N>0 ){
87430 ** If n>=0 then the P4 operand is dynamic, meaning that a copy of
87432 ** A value of n==0 means copy bytes of zP4 up to and including the
87433 ** first null byte. If n>0 then copy n+1 bytes of zP4.
87439 ** If addr<0 then change P4 on the most recently inserted instruction.
87449 pOp->p4type = 0;
87450 pOp->p4.p = 0;
87452 if( n<0 ){
87455 if( n==0 ) n = sqlite3Strlen30(zP4);
87463 assert( p!=0 );
87466 assert( p->aOp!=0 || db->mallocFailed );
87471 assert( p->nOp>0 );
87473 if( addr<0 ){
87477 if( n>=0 || pOp->p4type ){
87486 }else if( zP4!=0 ){
87487 assert( n<0 );
87506 assert( n<=0 );
87510 assert( pP4!=0 || n==P4_DYNAMIC );
87511 assert( p->nOp>0 );
87526 assert( v!=0 );
87527 assert( pIdx!=0 );
87540 assert( p->nOp>0 || p->aOp==0 );
87541 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->pParse->nErr>0 );
87585 ** this routine is a valid pointer. But because the dummy.opcode is 0,
87594 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
87630 ** "PX@PY" -> "r[X..X+Y-1]" or "r[x]" if y is 0 or 1
87631 ** "PX@PY+1" -> "r[X..X+Y]" or "r[x]" if y is 0
87646 sqlite3StrAccumInit(&x, 0, 0, 0, SQLITE_MAX_LENGTH);
87650 int seenCom = 0;
87653 if( strncmp(zSynopsis,"IF ",3)==0 ){
87657 for(ii=0; (c = zSynopsis[ii])!=0; ii++){
87663 if( pOp->zComment && pOp->zComment[0] ){
87671 if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
87674 if( strncmp(zSynopsis+ii+1,"+1",2)==0 ){
87683 }else if( strncmp(zSynopsis+ii+1, "@NP", 3)==0 ){
87689 }else if( x.accError==0 ){
87697 if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){
87712 if( (x.accError & SQLITE_NOMEM)!=0 && db!=0 ){
87725 const char *zOp = 0;
87742 if( pExpr->iColumn<0 ){
87800 char *zP4 = 0;
87803 sqlite3StrAccumInit(&x, 0, 0, 0, SQLITE_MAX_LENGTH);
87808 assert( pKeyInfo->aSortFlags!=0 );
87810 for(j=0; j<pKeyInfo->nKeyField; j++){
87813 if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
87884 u32 n = ai[0]; /* The first element of an INTARRAY is always the
87910 if( (x.accError & SQLITE_NOMEM)!=0 ){
87926 assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
87965 for(i=0; i<nDb; i++){
87966 if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
87973 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
87985 for(i=0; i<nDb; i++){
87986 if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
88006 if( pOut==0 ) pOut = stdout;
88011 zCom = sqlite3VdbeDisplayComment(0, pOp, zP4);
88013 zCom = 0;
88040 ** Mem.szMalloc = 0
88046 assert( db!=0 );
88047 if( N>0 ){
88051 p->szMalloc = 0;
88053 p->pScopyFrom = 0;
88054 p->bScopy = 0;
88057 }while( (--N)>0 );
88073 assert( db!=0 );
88081 assert( (&p[1])==pEnd || p[0].db==p[1].db );
88099 testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel );
88104 p->szMalloc = 0;
88124 if( pFrame->iFrameMagic!=SQLITE_FRAME_MAGIC ) return 0;
88155 int eMode, /* 0: normal. 1: EQP. 2: TablesUsed */
88161 int nSub = 0; /* Number of sub-vdbes seen so far */
88162 SubProgram **apSub = 0; /* Array of sub-vdbes */
88165 Op *aOp = 0; /* Opcode array */
88176 if( pSub!=0 ){
88183 for(i=0; i<nSub; i++){
88204 assert( apSub!=0 );
88205 assert( nSub>0 );
88206 for(j=0; i>=apSub[j]->nOp; j++){
88218 if( pSub!=0 && aOp[i].p4type==P4_SUBPROGRAM ){
88221 for(j=0; j<nSub; j++){
88225 p->rc = sqlite3VdbeMemGrow(pSub, nByte, nSub!=0);
88237 if( eMode==0 ) break;
88242 if( pOp->opcode==OP_OpenWrite && (pOp->p5 & OPFLAG_P2ISREG)==0 ) break;
88269 for(i=0; i<p->nChildCsr; i++){
88273 sqlite3VdbeDeleteAuxData(p->v->db, &p->pAuxData, -1, 0);
88299 Mem *pSub = 0; /* Memory cell hold array of subprogs */
88304 int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0);
88333 pSub = 0;
88354 sqlite3VdbeMemSetInt64(pMem+0, i);
88392 const char *z = 0;
88396 const VdbeOp *pOp = &p->aOp[0];
88397 if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
88413 if( sqlite3IoTrace==0 ) return;
88415 pOp = &p->aOp[0];
88416 if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
88420 for(i=0; sqlite3Isspace(z[i]); i++){}
88421 for(j=0; z[i]; i++){
88430 z[j] = 0;
88466 if( pBuf==0 ){
88487 assert( p!=0 );
88494 assert( p->nOp>0 );
88499 for(i=0; i<p->nMem; i++){
88506 p->nChange = 0;
88509 p->iStatement = 0;
88510 p->nFkConstraint = 0;
88512 for(i=0; i<p->nOp; i++){
88513 p->aOp[i].nExec = 0;
88514 p->aOp[i].nCycle = 0;
88549 assert( p!=0 );
88550 assert( p->nOp>0 );
88551 assert( pParse!=0 );
88556 pParse->pVList = 0;
88558 assert( db->mallocFailed==0 );
88564 /* Each cursor uses a memory cell. The first cursor (cursor 0) can
88565 ** use aMem[0] which is not otherwise used by the VDBE program. Allocate
88570 if( nCursor==0 && nMem>0 ) nMem++; /* Space for aMem[0] even if not used */
88580 assert( x.nFree>=0 );
88590 p->expired = 0;
88602 x.nNeeded = 0;
88603 p->aMem = allocSpace(&x, 0, nMem*sizeof(Mem));
88604 p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
88605 p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
88606 p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
88622 p->nVar = 0;
88623 p->nCursor = 0;
88624 p->nMem = 0;
88631 memset(p->apCsr, 0, nCursor*sizeof(VdbeCursor*));
88646 pCx->colCache = 0;
88647 pCx->pCache = 0;
88650 pCache->pCValue = 0;
88666 assert( pCx->uc.pCursor!=0 );
88674 assert( pVCur->pVtab->nRef>0 );
88688 for(i=0; i<p->nCursor; i++){
88692 p->apCsr[i] = 0;
88714 sqlite3VdbeDeleteAuxData(v->db, &v->pAuxData, -1, 0);
88716 pFrame->pAuxData = 0;
88733 p->pFrame = 0;
88734 p->nFrame = 0;
88736 assert( p->nFrame==0 );
88746 if( p->pAuxData ) sqlite3VdbeDeleteAuxData(p->db, &p->pAuxData, -1, 0);
88747 assert( p->pAuxData==0 );
88767 if( p->aColName==0 ) return;
88796 assert( p->aColName!=0 );
88799 assert( rc!=0 || !zName || (pColName->flags&MEM_Term)!=0 );
88811 int nTrans = 0; /* Number of databases with an active write-transaction
88815 int needXcommit = 0;
88838 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
88847 /* OFF */ 0,
88849 /* MEMORY */ 0,
88850 /* WAL */ 0
88858 && sqlite3PagerIsMemdb(pPager)==0
88888 if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
88891 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
88894 rc = sqlite3BtreeCommitPhaseOne(pBt, 0);
88903 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
88906 rc = sqlite3BtreeCommitPhaseTwo(pBt, 0);
88921 char *zSuper = 0; /* File-name for the super-journal */
88922 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
88923 sqlite3_file *pSuperJrnl = 0;
88924 i64 offset = 0;
88926 int retryCount = 0;
88931 zSuper = sqlite3MPrintf(db, "%.4c%s%.16c", 0,zMainFile,0);
88932 if( zSuper==0 ) return SQLITE_NOMEM_BKPT;
88939 sqlite3OsDelete(pVfs, zSuper, 0);
88948 (iRandom>>8)&0xffffff, iRandom&0xff);
88959 SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_SUPER_JOURNAL, 0
88973 for(i=0; i<db->nDb; i++){
88977 if( zFile==0 ){
88980 assert( zFile[0]!=0 );
88985 sqlite3OsDelete(pVfs, zSuper, 0);
88995 if( 0==(sqlite3OsDeviceCharacteristics(pSuperJrnl)&SQLITE_IOCAP_SEQUENTIAL)
88999 sqlite3OsDelete(pVfs, zSuper, 0);
89014 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
89033 zSuper = 0;
89047 for(i=0; i<db->nDb; i++){
89075 int cnt = 0;
89076 int nWrite = 0;
89077 int nRead = 0;
89082 if( p->readOnly==0 ) nWrite++;
89112 assert( db->nStatement>0 );
89115 for(i=0; i<db->nDb; i++){
89131 p->iStatement = 0;
89172 if( (deferred && (db->nDeferredCons+db->nDeferredImmCons)>0)
89173 || (!deferred && p->nFkConstraint>0)
89178 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)==0 ) return SQLITE_ERROR;
89229 int eStatementOp = 0;
89237 mrc = p->rc & 0xff;
89243 mrc = isSpecialError = 0;
89268 p->nChange = 0;
89275 (void)sqlite3VdbeCheckFk(p, 0);
89286 && db->nVdbeWrite==(p->readOnly==0)
89313 p->nChange = 0;
89315 db->nDeferredCons = 0;
89316 db->nDeferredImmCons = 0;
89321 p->nChange = 0;
89324 p->nChange = 0;
89326 db->nStatement = 0;
89327 }else if( eStatementOp==0 ){
89336 p->nChange = 0;
89349 if( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ){
89352 p->zErrMsg = 0;
89357 p->nChange = 0;
89368 sqlite3VdbeSetChanges(db, 0);
89370 p->nChange = 0;
89383 assert( db->nVdbeWrite>=0 );
89398 assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 );
89425 if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db);
89443 if( sqlite3GlobalConfig.xSqllog && v->rc==SQLITE_OK && v->zSql && v->pc>=0 ){
89445 assert( v->db->init.busy==0 );
89488 if( p->pc>=0 ){
89502 if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
89504 for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
89509 p->zErrMsg = 0;
89511 p->pResultRow = 0;
89513 p->nWrite = 0;
89523 for(i=0; i<p->nOp; i++){
89528 char c, pc = 0;
89530 for(i=0; (c = p->zSql[i])!=0; i++){
89537 for(i=0; i<p->nOp; i++){
89544 cnt>0 ? cycles/cnt : 0
89587 ** function parameter corresponds to bit 0 etc.).
89592 if( (iOp<0)
89594 && pAux->iAuxArg>=0
89619 assert( db!=0 );
89620 assert( p->db==0 || p->db==db );
89650 for(i=0; i<p->nScan; i++){
89664 assert( p!=0 );
89666 assert( db!=0 );
89669 if( db->pnBytesFreed==0 ){
89670 assert( p->ppVPrev!=0 );
89692 rc = sqlite3BtreeTableMoveto(p->uc.pCursor, p->movetoTarget, 0, &res);
89694 if( res!=0 ) return SQLITE_CORRUPT_BKPT;
89698 p->deferredMoveto = 0;
89713 assert( p->uc.pCursor!=0 );
89757 ** 0 0 NULL
89765 ** 8 0 Integer constant 0
89766 ** 9 0 Integer constant 1
89771 ** The 8 and 9 types were added in 3.3.0, file format 4. Prior versions
89775 #if 0 /* Inlined into the OP_MakeRecord opcode */
89791 assert( pLen!=0 );
89793 *pLen = 0;
89794 return 0;
89798 # define MAX_6BYTE ((((i64)0x00008000)<<32)-1)
89803 if( i<0 ){
89810 *pLen = 0;
89838 assert( pMem->n>=0 );
89844 return ((n*2) + 12 + ((flags&MEM_Str)!=0));
89852 /* 0 1 2 3 4 5 6 7 8 9 */
89853 /* 0 */ 0, 1, 2, 3, 4, 6, 8, 8, 0, 0,
89854 /* 10 */ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
89928 t = u.i[0];
89929 u.i[0] = u.i[1];
89939 #define ONE_BYTE_INT(x) ((i8)(x)[0])
89940 #define TWO_BYTE_INT(x) (256*(i8)((x)[0])|(x)[1])
89941 #define THREE_BYTE_INT(x) (65536*(i8)((x)[0])|((x)[1]<<8)|(x)[2])
89942 #define FOUR_BYTE_UINT(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
89943 #define FOUR_BYTE_INT(x) (16777216*(i8)((x)[0])|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
89967 testcase( pMem->u.i<0 );
89977 static const u64 t1 = ((u64)0x3ff00000)<<32;
89981 assert( sizeof(r1)==sizeof(t2) && memcmp(&r1, &t2, sizeof(r1))==0 );
90004 return 0;
90015 pMem->n = 0;
90016 pMem->u.nZero = 0;
90020 case 0: { /* Null */
90030 testcase( pMem->u.i<0 );
90038 testcase( pMem->u.i<0 );
90046 testcase( pMem->u.i<0 );
90055 if( buf[0]&0x80 ) pMem->u.i |= 0xffffffff80000000LL;
90058 testcase( pMem->u.i<0 );
90066 testcase( pMem->u.i<0 );
90076 case 8: /* Integer 0 */
90078 /* EVIDENCE-OF: R-12976-22893 Value is the integer 0. */
90117 assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff );
90120 if( !p ) return 0;
90122 assert( pKeyInfo->aSortFlags!=0 );
90146 p->default_rc = 0;
90150 u = 0;
90157 /* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
90158 pMem->szMalloc = 0;
90159 pMem->z = 0;
90196 int i = 0;
90197 int rc = 0;
90203 if( pKeyInfo->db==0 ) return 1;
90206 /* mem1.flags = 0; // Will be initialized by sqlite3VdbeSerialGet() */
90207 VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
90216 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
90222 assert( pKeyInfo->aSortFlags!=0 );
90223 assert( pKeyInfo->nKeyField>0 );
90260 pKeyInfo->nAllField>i ? pKeyInfo->aColl[i] : 0);
90261 if( rc!=0 ){
90262 assert( mem1.szMalloc==0 ); /* See comment below */
90280 assert( mem1.szMalloc==0 );
90282 /* rc==0 here means that one of the keys ran out of fields and
90288 if( desiredResult==0 && rc==0 ) return 1;
90289 if( desiredResult<0 && rc<0 ) return 1;
90290 if( desiredResult>0 && rc>0 ) return 1;
90293 return 0;
90313 int nField = 0;
90321 assert( nKey>=0 );
90360 if( (v1==0 || v2==0) ){
90362 rc = 0;
90378 for(i=0; i<n; i++){
90379 if( z[i] ) return 0;
90398 assert( (pB1->flags & MEM_Zero)==0 || n1==0 );
90399 assert( (pB2->flags & MEM_Zero)==0 || n2==0 );
90470 ** are NULL, return 0.
90482 if( (f1 & f2 & (MEM_Int|MEM_IntReal))!=0 ){
90487 return 0;
90489 if( (f1 & f2 & MEM_Real)!=0 ){
90492 return 0;
90494 if( (f1&(MEM_Int|MEM_IntReal))!=0 ){
90497 if( (f2&MEM_Real)!=0 ){
90499 }else if( (f2&(MEM_Int|MEM_IntReal))!=0 ){
90502 return 0;
90507 if( (f1&MEM_Real)!=0 ){
90508 if( (f2&(MEM_Int|MEM_IntReal))!=0 ){
90523 if( (f1 & MEM_Str)==0 ){
90526 if( (f2 & MEM_Str)==0 ){
90541 return vdbeCompareMemString(pMem1, pMem2, pColl, 0);
90563 case 0:
90565 testcase( aKey[0]&0x80 );
90568 testcase( aKey[0]&0x80 );
90571 testcase( aKey[0]&0x80 );
90574 testcase( aKey[0]&0x80 );
90579 testcase( aKey[0]&0x80 );
90584 testcase( aKey[0]&0x80 );
90610 ** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
90623 int rc = 0; /* Return value */
90634 if( s1<0x80 ){
90639 szHdr1 = aKey1[0];
90644 if( (szHdr1 = aKey1[0])<0x80 ){
90650 i = 0;
90654 return 0; /* Corruption */
90657 VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
90660 assert( pPKey2->pKeyInfo->aSortFlags!=0 );
90661 assert( pPKey2->pKeyInfo->nKeyField>0 );
90674 }else if( serial_type==0 ){
90699 }else if( serial_type==0 ){
90710 assert( rc==0 );
90725 }else if( !(serial_type & 0x01) ){
90735 return 0; /* Corruption */
90747 if( rc==0 ) rc = mem1.n - pRhs->n;
90754 assert( (pRhs->flags & MEM_Zero)==0 || pRhs->n==0 );
90757 if( serial_type<12 || (serial_type & 0x01) ){
90765 return 0; /* Corruption */
90775 if( rc==0 ) rc = nStr - pRhs->n;
90783 if( serial_type==0
90785 || (serial_type==7 && serialGet7(&aKey1[d1], &mem1)!=0)
90787 assert( rc==0 );
90793 if( rc!=0 ){
90796 if( (sortFlags & KEYINFO_ORDER_BIGNULL)==0
90798 !=(serial_type==0 || (pRhs->flags&MEM_Null)))
90804 assert( mem1.szMalloc==0 ); /* See comment below */
90816 return 0; /* Corrupt index */
90823 assert( mem1.szMalloc==0 );
90825 /* rc==0 here means that one or both of the keys ran out of fields and
90839 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
90856 const u8 *aKey = &((const u8*)pKey1)[*(const u8*)pKey1 & 0x3F];
90865 assert( (*(u8*)pKey1)<=0x3F || CORRUPT_DB );
90869 testcase( lhs<0 );
90874 testcase( lhs<0 );
90879 testcase( lhs<0 );
90885 testcase( lhs<0 );
90890 testcase( lhs<0 );
90897 testcase( lhs<0 );
90901 lhs = 0;
90913 case 0: case 7:
90920 assert( pPKey2->u.i == pPKey2->aMem[0].u.i );
90955 assert( pPKey2->aMem[0].flags & MEM_Str );
90956 assert( pPKey2->aMem[0].n == pPKey2->n );
90957 assert( pPKey2->aMem[0].z == pPKey2->u.z );
90963 if( serial_type<0 ){
90969 }else if( !(serial_type & 0x01) ){
90974 int szHdr = aKey1[0];
90979 return 0; /* Corruption */
90984 if( res>0 ){
90986 }else if( res<0 ){
90990 if( res==0 ){
90997 }else if( res>0 ){
91032 int flags = p->aMem[0].flags;
91033 if( p->pKeyInfo->aSortFlags[0] ){
91034 if( p->pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL ){
91044 p->u.i = p->aMem[0].u.i;
91050 if( (flags & (MEM_Real|MEM_IntReal|MEM_Null|MEM_Blob))==0
91051 && p->pKeyInfo->aColl[0]==0
91054 p->u.z = p->aMem[0].z;
91055 p->n = p->aMem[0].n;
91072 i64 nCellKey = 0;
91089 sqlite3VdbeMemInit(&m, db, 0);
91099 testcase( szHdr>0x7fffffff );
91100 assert( m.n>=0 );
91134 testcase( m.szMalloc!=0 );
91156 i64 nCellKey = 0;
91165 /* nCellKey will always be between 0 and 0xffffffff because of the way
91167 if( nCellKey<=0 || nCellKey>0x7fffffff ){
91168 *res = 0;
91171 sqlite3VdbeMemInit(&m, db, 0);
91176 *res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, pUnpacked, 0);
91241 ** 0 instead. Unless it is NULL, apply affinity aff (one of the SQLITE_AFF_*
91247 assert( iVar>0 );
91250 assert( (v->db->flags & SQLITE_EnableQPSG)==0
91251 || (v->db->mDbFlags & DBFLAG_InternalFunc)!=0 );
91252 if( 0==(pMem->flags & MEM_Null) ){
91261 return 0;
91270 assert( iVar>0 );
91271 assert( (v->db->flags & SQLITE_EnableQPSG)==0
91272 || (v->db->mDbFlags & DBFLAG_InternalFunc)!=0 );
91274 v->expmask |= 0x80000000;
91292 if( pCtx->pVdbe==0 ) return 1;
91309 return 0;
91322 assert( (pWalker->u.aMem[pExpr->iTable].flags & MEM_Undefined)==0 );
91340 pVtab->zErrMsg = 0;
91356 assert( db!=0 );
91359 for(i=0; i<nField; i++){
91389 static const u8 fakeSortOrder = 0;
91401 assert( db->pPreUpdate==0 );
91402 memset(&preupdate, 0, sizeof(PreUpdate));
91403 if( HasRowid(pTab)==0 ){
91404 iKey1 = iKey2 = 0;
91414 assert( pCsr!=0 );
91436 db->pPreUpdate = 0;
91443 for(i=0; i<pCsr->nField; i++){
91450 for(i=0; i<pTab->nCol; i++){
91490 return p==0 || p->expired;
91500 if( p->db==0 ){
91504 return 0;
91508 if( p==0 ){
91524 assert( p->startTime>0 );
91525 assert( db->init.busy==0 );
91526 assert( p->zSql!=0 );
91537 p->startTime = 0;
91544 if( ((P)->startTime)>0 ){ invokeProfileCallback(DB,P); }
91560 if( pStmt==0 ){
91589 if( pStmt==0 ){
91616 if( pStmt==0 ){
91624 for(i=0; i<p->nVar; i++){
91628 assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || p->expmask==0 );
91645 assert( p->flags==MEM_Null && p->z==0 );
91646 return 0;
91649 return p->n ? p->z : 0;
91671 return ((pMem->flags & MEM_Subtype) ? pMem->eSubtype : 0);
91677 && zPType!=0
91679 && strcmp(p->u.zPType, zPType)==0
91683 return 0;
91706 SQLITE_BLOB, /* 0x00 (not possible) */
91707 SQLITE_NULL, /* 0x01 NULL */
91708 SQLITE_TEXT, /* 0x02 TEXT */
91709 SQLITE_NULL, /* 0x03 (not possible) */
91710 SQLITE_INTEGER, /* 0x04 INTEGER */
91711 SQLITE_NULL, /* 0x05 (not possible) */
91712 SQLITE_INTEGER, /* 0x06 INTEGER + TEXT */
91713 SQLITE_NULL, /* 0x07 (not possible) */
91714 SQLITE_FLOAT, /* 0x08 FLOAT */
91715 SQLITE_NULL, /* 0x09 (not possible) */
91716 SQLITE_FLOAT, /* 0x0a FLOAT + TEXT */
91717 SQLITE_NULL, /* 0x0b (not possible) */
91718 SQLITE_INTEGER, /* 0x0c (not possible) */
91719 SQLITE_NULL, /* 0x0d (not possible) */
91720 SQLITE_INTEGER, /* 0x0e (not possible) */
91721 SQLITE_NULL, /* 0x0f (not possible) */
91722 SQLITE_BLOB, /* 0x10 BLOB */
91723 SQLITE_NULL, /* 0x11 (not possible) */
91724 SQLITE_TEXT, /* 0x12 (not possible) */
91725 SQLITE_NULL, /* 0x13 (not possible) */
91726 SQLITE_INTEGER, /* 0x14 INTEGER + BLOB */
91727 SQLITE_NULL, /* 0x15 (not possible) */
91728 SQLITE_INTEGER, /* 0x16 (not possible) */
91729 SQLITE_NULL, /* 0x17 (not possible) */
91730 SQLITE_FLOAT, /* 0x18 FLOAT + BLOB */
91731 SQLITE_NULL, /* 0x19 (not possible) */
91732 SQLITE_FLOAT, /* 0x1a (not possible) */
91733 SQLITE_NULL, /* 0x1b (not possible) */
91734 SQLITE_INTEGER, /* 0x1c (not possible) */
91735 SQLITE_NULL, /* 0x1d (not possible) */
91736 SQLITE_INTEGER, /* 0x1e (not possible) */
91737 SQLITE_NULL, /* 0x1f (not possible) */
91738 SQLITE_FLOAT, /* 0x20 INTREAL */
91739 SQLITE_NULL, /* 0x21 (not possible) */
91740 SQLITE_FLOAT, /* 0x22 INTREAL + TEXT */
91741 SQLITE_NULL, /* 0x23 (not possible) */
91742 SQLITE_FLOAT, /* 0x24 (not possible) */
91743 SQLITE_NULL, /* 0x25 (not possible) */
91744 SQLITE_FLOAT, /* 0x26 (not possible) */
91745 SQLITE_NULL, /* 0x27 (not possible) */
91746 SQLITE_FLOAT, /* 0x28 (not possible) */
91747 SQLITE_NULL, /* 0x29 (not possible) */
91748 SQLITE_FLOAT, /* 0x2a (not possible) */
91749 SQLITE_NULL, /* 0x2b (not possible) */
91750 SQLITE_FLOAT, /* 0x2c (not possible) */
91751 SQLITE_NULL, /* 0x2d (not possible) */
91752 SQLITE_FLOAT, /* 0x2e (not possible) */
91753 SQLITE_NULL, /* 0x2f (not possible) */
91754 SQLITE_BLOB, /* 0x30 (not possible) */
91755 SQLITE_NULL, /* 0x31 (not possible) */
91756 SQLITE_TEXT, /* 0x32 (not possible) */
91757 SQLITE_NULL, /* 0x33 (not possible) */
91758 SQLITE_FLOAT, /* 0x34 (not possible) */
91759 SQLITE_NULL, /* 0x35 (not possible) */
91760 SQLITE_FLOAT, /* 0x36 (not possible) */
91761 SQLITE_NULL, /* 0x37 (not possible) */
91762 SQLITE_FLOAT, /* 0x38 (not possible) */
91763 SQLITE_NULL, /* 0x39 (not possible) */
91764 SQLITE_FLOAT, /* 0x3a (not possible) */
91765 SQLITE_NULL, /* 0x3b (not possible) */
91766 SQLITE_FLOAT, /* 0x3c (not possible) */
91767 SQLITE_NULL, /* 0x3d (not possible) */
91768 SQLITE_FLOAT, /* 0x3e (not possible) */
91769 SQLITE_NULL, /* 0x3f (not possible) */
91799 return (pVal->flags&MEM_FromBind)!=0;
91806 if( pOrig==0 ) return 0;
91808 if( pNew==0 ) return 0;
91809 memset(pNew, 0, sizeof(*pNew));
91812 pNew->db = 0;
91818 pNew = 0;
91850 u8 enc, /* Encoding of z. 0 for BLOBs */
91877 if( xDel==0 ){
91885 if( pCtx!=0 ){
91889 assert( pCtx!=0 );
91901 if( pCtx==0 || n<0 ){
91906 assert( n>=0 );
91908 setResultStrOrError(pCtx, z, n, 0, xDel);
91918 if( pCtx==0 ){
91919 invokeValueDestructor(z, xDel, 0);
91924 if( n>0x7fffffff ){
91927 setResultStrOrError(pCtx, z, (int)n, 0, xDel);
91932 if( pCtx==0 ) return;
91939 if( pCtx==0 ) return;
91948 if( pCtx==0 ) return;
91957 if( pCtx==0 ) return;
91964 if( pCtx==0 ) return;
91971 if( pCtx==0 ) return;
91984 if( pCtx==0 ){
91985 invokeValueDestructor(pPtr, xDestructor, 0);
91998 if( pCtx==0 ) return;
92000 #if defined(SQLITE_STRICT_SUBTYPE) && SQLITE_STRICT_SUBTYPE+0!=0
92001 if( pCtx->pFunc!=0
92002 && (pCtx->pFunc->funcFlags & SQLITE_RESULT_SUBTYPE)==0
92014 pOut->eSubtype = eSubtype & 0xff;
92024 if( pCtx==0 ){
92025 invokeValueDestructor(z, xDel, 0);
92040 if( pCtx==0 ){
92041 invokeValueDestructor(z, xDel, 0);
92051 if( n>0x7fffffff ){
92091 if( pCtx==0 ) return;
92092 if( pValue==0 ){
92106 sqlite3_result_zeroblob64(pCtx, n>0 ? n : 0);
92112 if( pCtx==0 ) return SQLITE_MISUSE_BKPT;
92129 if( pCtx==0 ) return;
92144 if( pCtx==0 ) return;
92155 if( pCtx==0 ) return;
92186 for(i=0; i<db->nDb; i++){
92193 if( nEntry>0 && db->xWalCallback && rc==SQLITE_OK ){
92224 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
92239 if( db->nVdbeActive==0 ){
92240 AtomicStore(&db->u1.isInterrupted, 0);
92243 assert( db->nVdbeWrite>0 || db->autoCommit==0
92244 || ((db->nDeferredCons + db->nDeferredImmCons)==0)
92248 if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
92252 assert( p->startTime==0 );
92257 if( p->readOnly==0 ) db->nVdbeWrite++;
92259 p->pc = 0;
92266 ** with version 3.7.0, we changed this so that sqlite3_reset() would
92281 if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
92310 assert( db->mallocFailed==0 );
92318 p->pResultRow = 0;
92325 }else if( rc!=SQLITE_DONE && (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
92337 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ) rc = p->rc;
92342 assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0
92344 || (rc&0xff)==SQLITE_BUSY || rc==SQLITE_MISUSE
92357 int cnt = 0; /* Counter to prevent infinite loop of reprepares */
92374 ** program counter to 0 to ensure that when the statement is
92384 v->zErrMsg = 0;
92390 if( savedPc>=0 ){
92397 assert( v->expired==0 );
92410 if( p==0 ) return 0;
92428 if( p==0 ) return 0;
92451 if( p==0 ) return 0;
92470 ** Implementation of sqlite3_vtab_in_first() (if bNext==0) and
92471 ** sqlite3_vtab_in_next() (if bNext!=0).
92476 int bNext /* 1 for _next(). 0 for _first() */
92481 *ppOut = 0;
92482 if( pVal==0 ) return SQLITE_MISUSE_BKPT;
92483 if( (pVal->flags & MEM_Dyn)==0 || pVal->xDel!=sqlite3VdbeValueListFree ){
92489 assert( pVal->u.zPType!=0 && strcmp(pVal->u.zPType,"ValueList")==0 );
92493 rc = sqlite3BtreeNext(pRhs->pCsr, 0);
92495 int dummy = 0;
92503 memset(&sMem, 0, sizeof(sMem));
92513 if( (pOut->flags & MEM_Ephem)!=0 && sqlite3VdbeMemMakeWriteable(pOut) ){
92529 return valueFromValueList(pVal, ppOut, 0);
92551 assert( p->pVdbe!=0 );
92553 sqlite3_int64 iTime = 0;
92554 sqlite3_int64 *piTime = p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime;
92556 if( *piTime==0 ){
92558 if( rc ) *piTime = 0;
92569 assert( (pMem->flags & MEM_Agg)==0 );
92570 if( nByte<=0 ){
92572 pMem->z = 0;
92578 memset(pMem->z, 0, nByte);
92592 testcase( nByte<0 );
92593 if( (p->pMem->flags & MEM_Agg)==0 ){
92604 ** The left-most argument is 0.
92614 if( pCtx==0 ) return 0;
92618 if( pCtx->pVdbe==0 ) return 0;
92620 assert( pCtx->pVdbe!=0 );
92623 if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
92627 return 0;
92635 ** The left-most argument is 0.
92651 if( pCtx==0 ) return;
92656 if( pVdbe==0 ) goto failed;
92658 assert( pVdbe!=0 );
92662 if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
92666 if( pAuxData==0 ){
92673 if( pCtx->isError==0 ) pCtx->isError = -1;
92709 if( pVm==0 ) return 0;
92719 if( pVm==0 || pVm->pResultRow==0 ) return 0;
92741 /* .u = */ {0},
92742 /* .z = */ (char*)0,
92743 /* .n = */ (int)0,
92745 /* .enc = */ (u8)0,
92746 /* .eSubtype = */ (u8)0,
92747 /* .db = */ (sqlite3*)0,
92748 /* .szMalloc = */ (int)0,
92749 /* .uTemp = */ (u32)0,
92750 /* .zMalloc = */ (char*)0,
92751 /* .xDel = */ (void(*)(void*))0,
92753 /* .pScopyFrom = */ (Mem*)0,
92754 /* .mScopyFlags= */ 0,
92755 /* .bScopy = */ 0,
92772 if( pVm==0 ) return (Mem*)columnNullValue();
92775 if( pVm->pResultRow!=0 && i<pVm->nResColumn && i>=0 ){
92811 assert( p->db!=0 );
92892 /* 0 */ 'a', 'd', 'd', 'r', 0,
92893 /* 5 */ 'o', 'p', 'c', 'o', 'd', 'e', 0,
92894 /* 12 */ 'p', '1', 0,
92895 /* 15 */ 'p', '2', 0,
92896 /* 18 */ 'p', '3', 0,
92897 /* 21 */ 'p', '4', 0,
92898 /* 24 */ 'p', '5', 0,
92899 /* 27 */ 'c', 'o', 'm', 'm', 'e', 'n', 't', 0,
92900 /* 35 */ 'i', 'd', 0,
92901 /* 38 */ 'p', 'a', 'r', 'e', 'n', 't', 0,
92902 /* 45 */ 'n', 'o', 't', 'u', 's', 'e', 'd', 0,
92903 /* 53 */ 'd', 'e', 't', 'a', 'i', 'l', 0
92906 0, 5, 12, 15, 18, 21, 24, 27,
92912 ** xFunc() then return that string. If N is out of range, return 0.
92917 ** 0 The column name as it should be displayed for output
92937 if( pStmt==0 ){
92939 return 0;
92942 if( N<0 ) return 0;
92943 ret = 0;
92946 assert( db!=0 );
92950 if( useType>0 ) goto columnName_end;
92976 assert( db->mallocFailed==0 || db->mallocFailed==1 );
92979 ret = 0;
92992 return columnName(pStmt, N, 0, COLNAME_NAME);
93015 return columnName(pStmt, N, 0, COLNAME_DECLTYPE);
93031 return columnName(pStmt, N, 0, COLNAME_DATABASE);
93045 return columnName(pStmt, N, 0, COLNAME_TABLE);
93059 return columnName(pStmt, N, 0, COLNAME_COLUMN);
93087 ** p!=0
93088 ** p->pVar!=0
93089 ** i>0
93127 assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || p->expmask==0 );
93128 if( p->expmask!=0 && (p->expmask & (i>=31 ? 0x80000000 : (u32)1<<i))!=0 ){
93151 assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
93152 if( zData!=0 ){
93155 if( rc==SQLITE_OK && encoding!=0 ){
93182 if( nData<0 ) return SQLITE_MISUSE_BKPT;
93184 return bindText(pStmt, i, zData, nData, xDel, 0);
93194 return bindText(pStmt, i, zData, nData, xDel, 0);
93201 assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
93215 assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
93226 assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
93242 assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
93324 assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
93338 if( p==0 ) return SQLITE_MISUSE_BKPT;
93344 assert( (n & 0x7FFFFFFF)==n );
93358 return p ? p->nVar : 0;
93369 if( p==0 ) return 0;
93376 ** return 0.
93379 if( p==0 || zName==0 ) return 0;
93396 for(i=0; i<pFrom->nVar; i++){
93422 assert( (pTo->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || pTo->expmask==0 );
93426 assert( (pFrom->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || pFrom->expmask==0 );
93441 return pStmt ? ((Vdbe*)pStmt)->db : 0;
93457 return pStmt ? ((Vdbe*)pStmt)->explain : 0;
93467 if( pStmt==0 ) return SQLITE_MISUSE_BKPT;
93472 }else if( eMode<0 || eMode>2 ){
93474 }else if( (v->prepFlags & SQLITE_PREPARE_SAVESQL)==0 ){
93501 return v!=0 && v->eVdbeState==VDBE_RUN_STATE;
93515 return 0;
93519 if( pStmt==0 ){
93536 || (op!=SQLITE_STMTSTATUS_MEMUSED && (op<0||op>=ArraySize(pVdbe->aCounter)))
93539 return 0;
93545 v = 0;
93550 db->pnBytesFreed = 0;
93555 if( resetFlag ) pVdbe->aCounter[op] = 0;
93565 return p ? p->zSql : 0;
93579 return 0;
93581 char *z = 0;
93599 if( p==0 ) return 0;
93600 if( p->zNormSql==0 && ALWAYS(p->zSql!=0) ){
93624 memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1));
93638 int iStore = 0;
93641 if( db==0 || ppValue==0 ){
93657 if( iStore>=p->pCsr->nField || iStore<0 ){
93668 if( p->pUnpacked==0 ){
93676 rc = sqlite3BtreePayload(p->pCsr->uc.pCursor, 0, nRec, aRec);
93693 if( pCol->iDflt>0 ){
93694 if( p->apDflt==0 ){
93696 assert( sizeof(sqlite3_value*)*UMXV(p->pTab->nCol) < 0x7fffffff );
93699 if( p->apDflt==0 ) goto preupdate_old_out;
93701 if( p->apDflt[iIdx]==0 ){
93702 sqlite3_value *pVal = 0;
93704 assert( p->pTab!=0 && IsOrdinaryTable(p->pTab) );
93707 if( rc==SQLITE_OK && pVal==0 ){
93739 p = db!=0 ? db->pPreUpdate : 0;
93743 return (p ? p->pKeyinfo->nKeyField : 0);
93762 p = db!=0 ? db->pPreUpdate : 0;
93766 return (p ? p->v->nFrame : 0);
93778 p = db!=0 ? db->pPreUpdate : 0;
93795 int iStore = 0;
93798 if( db==0 || ppValue==0 ){
93813 if( iStore>=p->pCsr->nField || iStore<0 ){
93847 assert( sizeof(Mem)*UMXV(p->pCsr->nField) < 0x7fffffff );
93854 assert( iStore>=0 && iStore<p->pCsr->nField );
93856 if( pMem->flags==0 ){
93887 ScanStatus *pScan = 0;
93891 if( p==0 || pOut==0
93906 if( iScan<0 ){
93909 i64 res = 0;
93910 for(ii=0; ii<nOp; ii++){
93914 return 0;
93922 ** ScanStatus structures with ScanStatus.addrLoop set to 0. */
93923 for(idx=0; idx<p->nScan; idx++){
93927 if( iScan<0 ) break;
93932 assert( pScan==0 || pScan==&p->aScan[idx] );
93937 if( pScan->addrLoop>0 ){
93945 if( pScan->addrVisit>0 ){
93970 *(const char**)pOut = 0;
93991 i64 res = 0;
93992 if( pScan->aAddrRange[0]==0 ){
93996 for(ii=0; ii<ArraySize(pScan->aAddrRange); ii+=2){
93999 if( iIns==0 ) break;
94000 if( iIns>0 ){
94007 for(iOp=0; iOp<nOp; iOp++){
94010 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_NCYCLE)==0 ){
94025 return 0;
94037 return sqlite3_stmt_scanstatus_v2(pStmt, iScan, iScanStatusOp, 0, pOut);
94046 for(ii=0; p!=0 && ii<p->nOp; ii++){
94048 pOp->nExec = 0;
94049 pOp->nCycle = 0;
94086 int nTotal = 0;
94089 *pnToken = 0;
94090 while( zSql[0] ){
94092 assert( n>0 && tokenType!=TK_ILLEGAL );
94132 int idx = 0; /* Index of a host parameter */
94144 sqlite3StrAccumInit(&out, 0, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
94150 assert( (zRawSql - zStart) > 0 );
94153 }else if( p->nVar==0 ){
94156 while( zRawSql[0] ){
94158 assert( n>0 );
94161 assert( zRawSql[0] || nToken==0 );
94162 if( nToken==0 ) break;
94163 if( zRawSql[0]=='?' ){
94171 assert( zRawSql[0]==':' || zRawSql[0]=='$' ||
94172 zRawSql[0]=='@' || zRawSql[0]=='#' );
94173 testcase( zRawSql[0]==':' );
94174 testcase( zRawSql[0]=='$' );
94175 testcase( zRawSql[0]=='@' );
94176 testcase( zRawSql[0]=='#' );
94178 assert( idx>0 );
94182 assert( idx>0 && idx<=p->nVar );
94195 memset(&utf8, 0, sizeof(utf8));
94200 out.nAlloc = 0;
94209 while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
94231 for(i=0; i<nOut; i++){
94232 sqlite3_str_appendf(&out, "%02x", pVar->z[i]&0xff);
94345 mftbu %0\n\
94346 cmpw %0,%1\n\
94362 SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
94395 SQLITE_API int sqlite3_search_count = 0;
94407 SQLITE_API int sqlite3_interrupt_count = 0;
94418 SQLITE_API int sqlite3_sort_count = 0;
94429 SQLITE_API int sqlite3_max_blobsize = 0;
94431 if( (p->flags & (MEM_Str|MEM_Blob))!=0 && p->n>sqlite3_max_blobsize ){
94455 SQLITE_API int sqlite3_found_count = 0;
94483 static u64 n = 0;
94500 ** M: 2 - two-way branch (I=0: fall-thru 1: jump )
94501 ** 3 - two-way + NULL (I=0: fall-thru 1: jump 2: NULL )
94502 ** 4 - OP_Jump (I=0: jump p1 1: jump p2 2: jump p3)
94504 ** In other words, if M is 2, then I is either 0 (for fall-through) or
94505 ** 1 (for when the branch is taken). If M is 3, the I is 0 for an
94509 ** When M is 4, that means that an OP_Jump is being run. I is 0, 1, or 2
94517 ** always taken, the flags should be 0x05 since the fall-through and
94519 ** flags should be 0x06 since only the fall-through approach is allowed.
94521 ** Bit 0x08 of the flags indicates an OP_Jump opcode that is only
94522 ** interested in equal or not-equal. In other words, I==0 and I==2
94535 assert( I<=2 ); /* 0: fall through, 1: taken, 2: alternate taken */
94538 /* Transform I from a integer [0,1,2] into a bitmask of [1,2,4] */
94545 assert( (I & mNever)==0 );
94546 if( sqlite3GlobalConfig.xVdbeBranch==0 ) return; /*NO_TEST*/
94550 ** I - Mask of bits 0x07 indicating which cases are are
94551 ** fulfilled by this instance of the jump. 0x01 means
94552 ** fall-thru, 0x02 means taken, 0x04 means NULL. Any
94560 if( M==2 ) I |= 0x04;
94562 I |= 0x08;
94563 if( (mNever&0x08)!=0 && (I&0x05)!=0) I |= 0x05; /*NO_TEST*/
94566 iSrcLine&0xffffff, I, M);
94582 if( ((P)->flags&MEM_Ephem)!=0 \
94612 ** The memory cell for cursor 0 is aMem[0]. The rest are allocated from
94616 Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem;
94619 VdbeCursor *pCx = 0;
94624 assert( iCur>=0 && iCur<p->nCursor );
94627 p->apCsr[iCur] = 0;
94635 assert( (pMem->flags & MEM_Dyn)==0 );
94636 assert( pMem->szMalloc==0 || pMem->z==pMem->zMalloc );
94638 if( pMem->szMalloc>0 ){
94642 if( pMem->zMalloc==0 ){
94643 pMem->szMalloc = 0;
94644 return 0;
94650 memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
94675 return 0==sqlite3Atoi64(pRec->z, piValue, pRec->n, pRec->enc);
94699 if( rc<=0 ) return;
94745 if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
94746 if( (pRec->flags & (MEM_Real|MEM_IntReal))==0 ){
94758 if( 0==(pRec->flags&MEM_Str) ){ /*OPTIMIZATION-IF-FALSE*/
94780 applyNumericAffinity(pMem, 0);
94807 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 );
94808 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
94810 pMem->u.i = 0;
94814 if( rc<=0 ){
94815 if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
94821 }else if( rc==1 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)==0 ){
94836 assert( (pMem->flags & MEM_Null)==0
94837 || pMem->db==0 || pMem->db->mallocFailed );
94848 return 0;
94864 assert( (f & (MEM_Static|MEM_Ephem))==0 );
94867 assert( (f & (MEM_Dyn|MEM_Ephem))==0 );
94870 assert( (f & (MEM_Static|MEM_Dyn))==0 );
94875 for(i=0; i<25 && i<pMem->n; i++){
94876 sqlite3_str_appendf(pStr, "%02X", ((int)pMem->z[i] & 0xFF));
94879 for(i=0; i<25 && i<pMem->n; i++){
94892 assert( (f & (MEM_Static|MEM_Ephem))==0 );
94895 assert( (f & (MEM_Dyn|MEM_Ephem))==0 );
94898 assert( (f & (MEM_Static|MEM_Dyn))==0 );
94903 for(j=0; j<25 && j<pMem->n; j++){
94905 sqlite3_str_appendchar(pStr, 1, (c>=0x20&&c<=0x7f) ? c : '.');
94909 sqlite3_str_appendf(pStr, "(0-term)");
94926 }else if( (p->flags & (MEM_IntReal))!=0 ){
94939 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
94943 if( p->flags & MEM_Subtype ) printf(" subtype=0x%02x", p->eSubtype);
94992 int n = 0;
95011 assert( pOp->p2>0 );
95029 u64 h = 0;
95071 if( len > 4000 && pC->pKeyInfo==0 ){
95084 if( pC->colCache==0 ){
95086 if( pC->pCache==0 ) return SQLITE_NOMEM;
95090 if( pCache->pCValue==0
95098 if( pBuf==0 ) return SQLITE_NOMEM;
95101 pBuf[len] = 0;
95102 pBuf[len+1] = 0;
95103 pBuf[len+2] = 0;
95118 rc = sqlite3VdbeMemSetStr(pDest, pBuf, len, 0,
95125 if( (t&1)!=0 && encoding==SQLITE_UTF8 ){
95126 pDest->z[len] = 0;
95160 int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */
95161 u8 iCompareIsInit = 0; /* iCompare is initialized */
95165 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
95167 int iCompare = 0; /* Result of last comparison */
95168 u64 nVmStep = 0; /* Number of virtual machine steps */
95173 Mem *pIn1 = 0; /* 1st input operand */
95174 Mem *pIn2 = 0; /* 2nd input operand */
95175 Mem *pIn3 = 0; /* 3rd input operand */
95176 Mem *pOut = 0; /* Output operand */
95177 u32 colCacheCtr = 0; /* Column cache counter */
95179 u64 *pnCycle = 0;
95180 int bStmtScanStatus = IS_STMT_SCANSTATUS(db)!=0;
95191 assert( 0 < db->nProgressOps );
95202 assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
95205 assert( p->bIsReader || p->readOnly!=0 );
95206 p->iCurrentTime = 0;
95207 assert( p->explain==0 );
95208 db->busyHandler.nBusy = 0;
95213 if( p->pc==0
95214 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
95221 for(i=0; i<p->nOp; i++){
95226 for(i=0; i<p->nOp; i++){
95230 once = 0;
95249 if( sqlite3NProfileCnt==0 ) *pnCycle -= sqlite3Hwtime();
95272 if( sqlite3_interrupt_count>0 ){
95274 if( sqlite3_interrupt_count==0 ){
95284 if( (opProperty & OPFLG_IN1)!=0 ){
95285 assert( pOp->p1>0 );
95291 if( (opProperty & OPFLG_IN2)!=0 ){
95292 assert( pOp->p2>0 );
95298 if( (opProperty & OPFLG_IN3)!=0 ){
95299 assert( pOp->p3>0 );
95305 if( (opProperty & OPFLG_OUT2)!=0 ){
95306 assert( pOp->p2>0 );
95310 if( (opProperty & OPFLG_OUT3)!=0 ){
95311 assert( pOp->p3>0 );
95366 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell
95407 while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
95408 assert( db->nProgressOps!=0 );
95427 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
95429 assert( VdbeMemDynamic(pIn1)==0 );
95444 ** OP_Return becomes a no-op. If P3 is 0, then register P1 must hold an
95446 ** this opcode is used in combination with OP_BeginSubrtn, and set to 0
95465 VdbeBranchTaken(0, 2);
95475 ** If P2!=0 then the coroutine implementation immediately follows
95482 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
95483 assert( pOp->p2>=0 && pOp->p2<p->nOp );
95484 assert( pOp->p3>=0 && pOp->p3<p->nOp );
95489 if( pOp->p2==0 ) break;
95494 assert( pOp->p2>0 ); /* There are never any jumps to instruction 0 */
95514 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
95517 assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
95539 assert( VdbeMemDynamic(pIn1)==0 );
95561 if( (pIn3->flags & MEM_Null)==0 ) break;
95572 ** or sqlite3_finalize(). For a normal halt, this should be SQLITE_OK (0).
95573 ** For errors, it can be some other value. If P1!=0 then P2 will determine
95596 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
95640 if( pOp->p3>0 && pOp->p4type==P4_NOTUSED ){
95667 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
95668 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
95693 assert( pOp->p4.pI64!=0 );
95723 assert( pOp->p4.z!=0 );
95733 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
95734 assert( VdbeMemDynamic(pOut)==0 );
95735 pOut->szMalloc = 0;
95764 ** if( P3!=0 and reg[P3]==P5 ) reg[P2] := CAST(reg[P2] as BLOB)
95767 assert( pOp->p4.z!=0 );
95775 if( pOp->p3>0 ){
95827 pOut->n = 0;
95829 pOut->uTemp = 0;
95831 while( cnt>0 ){
95836 pOut->n = 0;
95851 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
95867 if( pOp->p4.z==0 ){
95871 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
95886 assert( pOp->p1>0 && pOp->p1<=p->nVar );
95917 assert( n>0 && p1>0 && p2>0 );
95929 pIn1->pScopyFrom = 0;
95952 ** If the 0x0002 bit of P5 is set then also clear the MEM_Subtype flag in the
95953 ** destination. The 0x0001 bit of P5 indicates that this Copy opcode cannot
95954 ** be merged. The 0x0001 bit is used by the query planner and does not
95971 if( (pOut->flags & MEM_Subtype)!=0 && (pOp->p5 & 0x0002)!=0 ){
95975 pOut->pScopyFrom = 0;
95978 if( (n--)==0 ) break;
96021 assert( (pIn1->flags & MEM_Int)!=0 );
96039 if( (rc = sqlite3VdbeCheckFk(p,0))!=SQLITE_OK ){
96056 assert( pOp->p1>0 || CORRUPT_DB );
96065 for(i=0; i<pOp->p2; i++){
96073 pMem[i].pScopyFrom = 0;
96079 db->trace.xV2(SQLITE_TRACE_ROW, db->pTraceArg, p, 0);
96116 if( (flags1 & (MEM_Str|MEM_Blob))==0 ){
96117 if( sqlite3VdbeMemStringify(pIn1,encoding,0) ) goto no_mem;
96119 }else if( (flags1 & MEM_Zero)!=0 ){
96124 if( (flags2 & (MEM_Str|MEM_Blob))==0 ){
96125 if( sqlite3VdbeMemStringify(pIn2,encoding,0) ) goto no_mem;
96127 }else if( (flags2 & MEM_Zero)!=0 ){
96148 pOut->z[nByte]=0;
96149 pOut->z[nByte+1] = 0;
96212 if( (type1 & type2 & MEM_Int)!=0 ){
96221 if( iA==0 ) goto arithmetic_result_is_null;
96227 if( iA==0 ) goto arithmetic_result_is_null;
96235 }else if( ((type1 | type2) & MEM_Null)!=0 ){
96240 if( (type1 & type2 & MEM_Int)!=0 ) goto int_math;
96249 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
96250 if( rA==(double)0 ) goto arithmetic_result_is_null;
96257 if( iA==0 ) goto arithmetic_result_is_null;
96290 ** maximum. The P1 register is initialized to 0 by this instruction.
96299 sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
96357 }else if( iB!=0 ){
96361 if( iB<0 ){
96368 iA = (iA>=0 || op==OP_ShiftLeft) ? 0 : -1;
96376 if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB);
96392 ** To force any register to be an integer, just add 0.
96406 ** without data loss, then jump immediately to P2, or if P2==0
96411 if( (pIn1->flags & MEM_Int)==0 ){
96413 if( (pIn1->flags & MEM_Int)==0 ){
96415 if( pOp->p2==0 ){
96423 VdbeBranchTaken(0, 2);
96494 ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
96538 ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
96592 if( (flags1 & flags3 & MEM_Int)!=0 ){
96613 iCompare = 0;
96616 VdbeBranchTaken(0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
96626 assert( (flags1 & MEM_Cleared)==0 );
96627 assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 || CORRUPT_DB );
96628 testcase( (pOp->p5 & SQLITE_JUMPIFNULL)!=0 );
96629 if( (flags1&flags3&MEM_Null)!=0
96630 && (flags3&MEM_Cleared)==0
96632 res = 0; /* Operands are equal */
96656 applyNumericAffinity(pIn1,0);
96661 applyNumericAffinity(pIn3,0);
96664 }else if( affinity==SQLITE_AFF_TEXT && ((flags1 | flags3) & MEM_Str)!=0 ){
96665 if( (flags1 & MEM_Str)!=0 ){
96667 }else if( (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
96676 if( (flags3 & MEM_Str)!=0 ){
96678 }else if( (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
96687 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
96699 if( res<0 ){
96701 }else if( res==0 ){
96715 VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
96740 for(iAddr = (int)(pOp - aOp) - 1; ALWAYS(iAddr>=0); iAddr--){
96747 VdbeBranchTaken(iCompare==0, 2);
96748 if( iCompare==0 ) goto jump_to_p2;
96805 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ){
96806 aPermute = 0;
96812 assert( aPermute!=0 );
96816 assert( n>0 );
96817 assert( pKeyInfo!=0 );
96822 int k, mx = 0;
96823 for(k=0; k<n; k++) if( aPermute[k]>(u32)mx ) mx = aPermute[k];
96824 assert( p1>0 && p1+mx<=(p->nMem+1 - p->nCursor)+1 );
96825 assert( p2>0 && p2+mx<=(p->nMem+1 - p->nCursor)+1 );
96827 assert( p1>0 && p1+n<=(p->nMem+1 - p->nCursor)+1 );
96828 assert( p2>0 && p2+n<=(p->nMem+1 - p->nCursor)+1 );
96831 for(i=0; i<n; i++){
96867 if( iCompare<0 ){
96868 VdbeBranchTaken(0,4); pOp = &aOp[pOp->p1 - 1];
96869 }else if( iCompare==0 ){
96883 ** If either P1 or P2 is 0 (false) then the result is 0 even if
96899 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
96900 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
96905 static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
96908 static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
96928 ** boolean (a 0 or 1) in register P2. Or if the value in register P1 is
96935 ** <li> If P3==0 and P4==0 then r[P2] := r[P1] IS TRUE
96937 ** <li> If P3==0 and P4==1 then r[P2] := r[P1] IS NOT TRUE
96938 ** <li> If P3==1 and P4==0 then r[P2] := r[P1] IS NOT FALSE
96943 assert( pOp->p4.i==0 || pOp->p4.i==1 );
96944 assert( pOp->p3==0 || pOp->p3==1 );
96960 if( (pIn1->flags & MEM_Null)==0 ){
96961 sqlite3VdbeMemSetInt64(pOut, !sqlite3VdbeBooleanValue(pIn1,0));
96979 if( (pIn1->flags & MEM_Null)==0 ){
97011 assert( p->aOp[0].opcode==OP_Init );
97014 if( (p->pFrame->aOnce[iAddr/8] & (1<<(iAddr & 7)))!=0 ){
97020 if( p->aOp[0].p1==pOp->p1 ){
97025 VdbeBranchTaken(0, 2);
97026 pOp->p1 = p->aOp[0].p1;
97039 VdbeBranchTaken(c!=0, 2);
97053 VdbeBranchTaken(c!=0, 2);
97065 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
97066 if( (pIn1->flags & MEM_Null)!=0 ){
97089 ** (0x01) bit. SQLITE_FLOAT is the 0x02 bit. SQLITE_TEXT is 0x04.
97090 ** SQLITE_BLOB is 0x08. SQLITE_NULL is 0x10.
97093 ** when P1>=0. If the database contains a NaN value, this opcode will think
97094 ** that the datatype is REAL when it should be NULL. When P1<0 and the value
97096 ** distinguish between NULL and REAL. The problem only arises then P1>=0.
97109 assert( pOp->p1>=0 || (pOp->p3>=0 && pOp->p3<=(p->nMem+1 - p->nCursor)) );
97110 if( pOp->p1>=0 ){
97112 assert( pC!=0 );
97113 assert( pOp->p3>=0 );
97118 typeMask = 0x04; /* SQLITE_TEXT */
97120 typeMask = 0x08; /* SQLITE_BLOB */
97124 0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x2,
97125 0x01, 0x01, 0x10, 0x10
97127 testcase( serialType==0 );
97143 testcase( typeMask==0x01 );
97144 testcase( typeMask==0x02 );
97145 testcase( typeMask==0x04 );
97146 testcase( typeMask==0x08 );
97147 testcase( typeMask==0x10 );
97152 testcase( typeMask==0x01 );
97153 testcase( typeMask==0x02 );
97154 testcase( typeMask==0x04 );
97155 testcase( typeMask==0x08 );
97156 testcase( typeMask==0x10 );
97158 VdbeBranchTaken( (typeMask & pOp->p5)!=0, 2);
97166 ** Synopsis: r[P2] = 0 OR NULL
97173 if( (aMem[pOp->p1].flags & MEM_Null)!=0
97174 || (aMem[pOp->p3].flags & MEM_Null)!=0
97178 sqlite3VdbeMemSetInt64(aMem + pOp->p2, 0);
97190 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
97191 if( (pIn1->flags & MEM_Null)==0 ){
97209 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
97236 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
97239 if( pC==0 || pC->eCurType!=CURTYPE_BTREE ){
97294 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
97295 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
97300 assert( pC!=0 );
97302 || (pC->eCurType==CURTYPE_PSEUDO && pC->seekResult==0) );
97311 if( pC->eCurType==CURTYPE_PSEUDO && pC->seekResult>0 ){
97330 if( pC->ub.aAltMap && (iMap = pC->ub.aAltMap[1+p2])>0 ){
97351 if( (aOffset[0] = pC->aRow[0])<0x80 ){
97356 pC->nHdrParsed = 0;
97358 if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/
97363 pC->aRow = 0;
97364 pC->szRow = 0;
97375 if( aOffset[0] > 98307 || aOffset[0] > pC->payloadSize ){
97383 ** This branch is taken even if aOffset[0]==0. Such a record is never
97385 ** accept it for historical reasons. When aOffset[0]==0, the code this
97394 testcase( aOffset[0]==0 );
97410 if( pC->iHdrOffset<aOffset[0] ){
97412 if( pC->aRow==0 ){
97413 memset(&sMem, 0, sizeof(sMem));
97414 rc = sqlite3VdbeMemFromBtreeZeroOffset(pC->uc.pCursor,aOffset[0],&sMem);
97426 zEndHdr = zData + aOffset[0];
97429 if( (pC->aType[i] = t = zHdr[0])<0x80 ){
97437 aOffset[++i] = (u32)(offset64 & 0xffffffff);
97448 if( aOffset[0]==0 ){
97449 i = 0;
97452 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
97459 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
97461 t = 0;
97512 if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem;
97517 pDest->z[len] = 0;
97518 pDest->z[len+1] = 0;
97526 if( ((p5 = (pOp->p5 & OPFLAG_BYTELENARG))!=0
97528 || (t>=12 && ((t&1)==0 || p5==OPFLAG_BYTELENARG))
97531 || sqlite3VdbeSerialTypeLen(t)==0
97564 if( aOp[0].p3>0 ){
97565 pOp = &aOp[aOp[0].p3-1];
97610 for(i=0; i<pTab->nCol; i++){
97617 if( (pIn1->flags & MEM_Null)==0 ){
97620 if( (pIn1->flags & MEM_Blob)==0 ) goto vdbe_type_error;
97625 if( (pIn1->flags & MEM_Int)==0 ) goto vdbe_type_error;
97629 if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error;
97634 assert( (pIn1->flags & MEM_IntReal)==0 );
97652 }else if( (pIn1->flags & (MEM_Real|MEM_IntReal))==0 ){
97690 assert( zAffinity!=0 );
97691 assert( pOp->p2>0 );
97692 assert( zAffinity[pOp->p2]==0 );
97696 assert( zAffinity[0]==SQLITE_AFF_NONE || memIsValid(pIn1) );
97697 applyAffinity(pIn1, zAffinity[0], encoding);
97698 if( zAffinity[0]==SQLITE_AFF_REAL && (pIn1->flags & MEM_Int)!=0 ){
97718 if( zAffinity[0]==0 ) break;
97771 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
97774 ** Data(0) is taken from register P1. Data(1) comes from register P1+1
97782 nData = 0; /* Number of bytes of data space */
97783 nHdr = 0; /* Number of bytes of header space */
97784 nZero = 0; /* Number of zero bytes at the end of the record */
97787 assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem+1 - p->nCursor)+1 );
97803 applyAffinity(pRec, zAffinity[0], encoding);
97804 if( zAffinity[0]==SQLITE_AFF_REAL && (pRec->flags & MEM_Int) ){
97811 assert( zAffinity[0]==0 || pRec<=pLast );
97812 }while( zAffinity[0] );
97819 ** at least one field. If P5>0 then it will be one more than the
97822 while( (pLast->flags & MEM_Null)!=0 && nField>pOp->p5 ){
97836 ** 0 NULL
97844 ** 8 Integer constant 0
97871 pRec->uTemp = 0;
97880 if( i<0 ){
97930 assert( pRec->n>=0 );
97932 serial_type = (len*2) + 12 + ((pRec->flags & MEM_Str)!=0);
97997 if( nHdr<0x80 ){
98012 if( serial_type==0 ){
98026 default: zPayload[7] = (u8)(v&0xff); v >>= 8;
98027 zPayload[6] = (u8)(v&0xff); v >>= 8;
98029 case 6: zPayload[5] = (u8)(v&0xff); v >>= 8;
98030 zPayload[4] = (u8)(v&0xff); v >>= 8;
98032 case 4: zPayload[3] = (u8)(v&0xff); v >>= 8;
98034 case 3: zPayload[2] = (u8)(v&0xff); v >>= 8;
98036 case 2: zPayload[1] = (u8)(v&0xff); v >>= 8;
98038 case 1: zPayload[0] = (u8)(v&0xff);
98042 }else if( serial_type<0x80 ){
98044 if( serial_type>=14 && pRec->n>0 ){
98045 assert( pRec->z!=0 );
98052 assert( pRec->z!=0 );
98064 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
98075 ** If P3==0, then an exact count is obtained, which involves visiting
98089 nEntry = 0; /* Not needed. Only used to silence a warning. */
98101 ** on the value of P1. To open a new savepoint set P1==0 (SAVEPOINT_BEGIN).
98121 assert( db->pSavepoint==0 || db->autoCommit==0 );
98123 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
98128 if( db->nVdbeWrite>0 ){
98142 assert( db->autoCommit==0 || db->nVTrans==0 );
98157 db->autoCommit = 0;
98172 iSavepoint = 0;
98186 }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){
98199 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
98207 db->autoCommit = 0;
98213 db->autoCommit = 0;
98215 db->isTransactionSavepoint = 0;
98221 isSchemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0;
98222 for(ii=0; ii<db->nDb; ii++){
98225 isSchemaChange==0);
98230 isSchemaChange = 0;
98232 for(ii=0; ii<db->nDb; ii++){
98239 sqlite3ExpirePreparedStatements(db, 0);
98288 ** Set the database auto-commit flag to P1 (1 or 0). If P2 is true, roll
98301 assert( desiredAutoCommit==1 || desiredAutoCommit==0 );
98302 assert( desiredAutoCommit==1 || iRollback==0 );
98303 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
98311 }else if( desiredAutoCommit && db->nVdbeWrite>0 ){
98346 /*NOTREACHED*/ assert(0);
98359 ** started. Index 0 is the main database file and index 1 is the
98373 ** If P5!=0 then this opcode also checks the schema cookie against P3
98387 int iMeta = 0;
98390 assert( p->readOnly==0 || pOp->p2==0 );
98391 assert( pOp->p2>=0 && pOp->p2<=2 );
98392 assert( pOp->p1>=0 && pOp->p1<db->nDb );
98395 if( pOp->p2 && (db->flags & (SQLITE_QueryOnly|SQLITE_CorruptRdOnly))!=0 ){
98414 if( (rc&0xff)==SQLITE_BUSY ){
98424 && (db->autoCommit==0 || db->nVdbeRead>1)
98427 if( p->iStatement==0 ){
98428 assert( db->nStatement>=0 && db->nSavepoint>=0 );
98445 assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
98476 /* Set changeCntOn to 0 to prevent the value returned by sqlite3_changes()
98479 p->changeCntOn = 0;
98489 ** P3==3 is the recommended pager cache size, and so forth. P1==0 is
98506 assert( iDb>=0 && iDb<db->nDb );
98507 assert( db->aDb[iDb].pBt!=0 );
98521 ** size, and so forth. P1==0 is the main database file and P1==1 is the
98534 sqlite3VdbeIncrWriteCounter(p, 0);
98536 assert( pOp->p1>=0 && pOp->p1<db->nDb );
98538 assert( p->readOnly==0 );
98540 assert( pDb->pBt!=0 );
98541 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
98556 sqlite3ExpirePreparedStatements(db, 0);
98557 p->expired = 0;
98568 ** P3==0 means the main database, P3==1 means the database used for
98576 ** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
98599 ** The ReopenIdx opcode may only be used with P5==0 or P5==OPFLAG_SEEKEQ
98606 ** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
98630 ** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
98633 ** <li> <b>0x08 OPFLAG_FORDELETE</b>: This cursor is used only to seek
98638 ** <li> <b>0x10 OPFLAG_P2ISREG</b>: Use the content of register P2
98657 assert( pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
98671 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
98674 || p->readOnly==0 );
98681 nField = 0;
98682 pKeyInfo = 0;
98685 assert( iDb>=0 && iDb<db->nDb );
98689 assert( pX!=0 );
98693 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
98698 assert( p2>0 );
98702 assert( (pIn2->flags & MEM_Int)!=0 );
98712 wrFlag = 0;
98713 assert( (pOp->p5 & OPFLAG_P2ISREG)==0 );
98723 assert( pOp->p1>=0 );
98724 assert( nField>=0 );
98725 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
98727 if( pCur==0 ) goto no_mem;
98771 if( pCx==0 ) goto no_mem;
98803 ** The cursor points to a BTree table if P4==0 and to a BTree index
98804 ** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
98835 assert( pOp->p1>=0 );
98836 assert( pOp->p2>=0 );
98837 if( pOp->p3>0 ){
98840 assert( pOp->p2==0 ); /* Only used when number of columns is zero */
98843 aMem[pOp->p3].n = 0;
98852 pCx->seqCount = 0;
98854 rc = sqlite3BtreeClearTable(pCx->ub.pBtx, pCx->pgnoRoot, 0);
98857 if( pCx==0 ) goto no_mem;
98859 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->ub.pBtx,
98863 rc = sqlite3BtreeBeginTrans(pCx->ub.pBtx, 1, 0);
98870 if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
98881 pCx->isTable = 0;
98885 0, pCx->uc.pCursor);
98894 p->apCsr[pOp->p1] = 0; /* Not required; helps with static analysis */
98918 assert( pOp->p1>=0 );
98919 assert( pOp->p2>=0 );
98921 if( pCx==0 ) goto no_mem;
98939 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98942 if( (pC->seqCount++)==0 ){
98962 ** the pseudo-table. If P2 is 0 or negative then the pseudo-cursor
98968 assert( pOp->p1>=0 );
98969 assert( pOp->p3>=0 );
98971 if( pCx==0 ) goto no_mem;
98980 assert( pOp->p5==0 );
98990 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98992 p->apCsr[pOp->p1] = 0;
99118 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99119 assert( pOp->p2!=0 );
99121 assert( pC!=0 );
99127 assert( pC->uc.pCursor!=0 );
99129 eqOnly = 0;
99130 pC->nullRow = 0;
99135 pC->deferredMoveto = 0;
99140 assert( sqlite3BtreeCursorHasHint(pC->uc.pCursor, BTREE_SEEK_EQ)==0
99149 applyNumericAffinity(pIn3, 0);
99157 if( (newType & (MEM_Int|MEM_IntReal))==0 ){
99159 if( (newType & MEM_Real)==0 ){
99178 if( c>0 ){
99181 assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) );
99182 if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--;
99187 else if( c<0 ){
99190 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
99191 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
99194 rc = sqlite3BtreeTableMoveto(pC->uc.pCursor, (u64)iKey, 0, &res);
99211 assert( pOp[1].p1==pOp[0].p1 );
99212 assert( pOp[1].p2==pOp[0].p2 );
99213 assert( pOp[1].p3==pOp[0].p3 );
99214 assert( pOp[1].p4.i==pOp[0].p4.i );
99219 assert( nField>0 );
99240 for(i=0; i<r.nField; i++){
99242 if( i>0 ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
99246 r.eqSeen = 0;
99251 if( eqOnly && r.eqSeen==0 ){
99252 assert( res!=0 );
99260 if( res<0 || (res==0 && oc==OP_SeekGT) ){
99261 res = 0;
99262 rc = sqlite3BtreeNext(pC->uc.pCursor, 0);
99272 res = 0;
99276 if( res>0 || (res==0 && oc==OP_SeekLT) ){
99277 res = 0;
99278 rc = sqlite3BtreePrevious(pC->uc.pCursor, 0);
99295 assert( pOp->p2>0 );
99296 VdbeBranchTaken(res!=0,2);
99342 ** row. If This.P5 is false (0) then a jump is made to SeekGE.P2. If
99343 ** This.P5 is true (non-zero) then a jump is made to This.P2. The P5==0
99345 ** the IN constraint. The jump to SeekGE.P2 ends the loop. The P5!=0 case
99372 ** jump to SeekOP.P2 if This.P5==0 or to This.P2 if This.P5>0.
99388 if( pOp->p5==0 ){
99403 assert( pOp->p1>0 );
99405 assert( pC!=0 );
99420 r.default_rc = 0;
99425 for(i=0; i<r.nField; i++){
99431 res = 0; /* Not needed. Only used to silence a warning. */
99435 if( res>0 && pOp->p5==0 ){
99447 if( res>=0 ){
99458 if( nStep<=0 ){
99464 VdbeBranchTaken(0,3);
99469 rc = sqlite3BtreeNext(pC->uc.pCursor, 0);
99500 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99502 assert( pC!=0 );
99531 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99533 VdbeBranchTaken(pCur==0 || pCur->nullRow, 2);
99534 if( pCur==0 || pCur->nullRow ){
99543 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
99544 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
99560 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
99561 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
99610 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
99611 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
99632 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99634 assert( pC!=0 );
99657 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99660 assert( pC!=0 );
99666 assert( pC->uc.pCursor!=0 );
99667 assert( pC->isTable==0 );
99669 if( r.nField>0 ){
99672 r.default_rc = 0;
99675 for(ii=0; ii<r.nField; ii++){
99677 assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
99690 if( pIdxKey==0 ) goto no_mem;
99692 pIdxKey->default_rc = 0;
99699 alreadyExists = (pC->seekResult==0);
99701 pC->deferredMoveto = 0;
99704 VdbeBranchTaken(alreadyExists!=0,2);
99715 for(ii=0; ii<r.nField; ii++){
99722 VdbeBranchTaken(0,2);
99736 ** Or, if P2 is 0, raise an SQLITE_CORRUPT error. If P1 does contain
99759 ** rowid P3 then jump immediately to P2. Or, if P2 is 0, raise an
99788 if( (pIn3->flags & (MEM_Int|MEM_IntReal))==0 ){
99794 Mem x = pIn3[0];
99796 if( (x.flags & MEM_Int)==0 ) goto jump_to_p2;
99804 assert( (pIn3->flags & MEM_Int)!=0 || pOp->opcode==OP_SeekRowid );
99805 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99809 assert( pC!=0 );
99816 assert( pCrsr!=0 );
99817 res = 0;
99818 rc = sqlite3BtreeTableMoveto(pCrsr, iKey, 0, &res);
99819 assert( rc==SQLITE_OK || res==0 );
99821 pC->nullRow = 0;
99823 pC->deferredMoveto = 0;
99824 VdbeBranchTaken(res!=0,2);
99826 if( res!=0 ){
99828 if( pOp->p2==0 ){
99847 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99848 assert( p->apCsr[pOp->p1]!=0 );
99864 ** If P3>0 then P3 is a register in the root frame of this VDBE that holds
99881 v = 0;
99882 res = 0;
99884 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99886 assert( pC!=0 );
99889 assert( pC->uc.pCursor!=0 );
99907 # define MAX_ROWID 0x7fffffff
99909 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
99910 ** Others complain about 0x7ffffffffffffffffLL. The following macro seems
99913 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
99937 assert( pOp->p3>0 );
99953 assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
99969 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
99971 cnt = 0;
99976 0, &res))==SQLITE_OK)
99977 && (res==0)
99980 if( res==0 ){
99984 assert( v>0 ); /* EV: R-40812-03570 */
99986 pC->deferredMoveto = 0;
100034 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
100040 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100043 assert( pC!=0 );
100045 assert( pC->deferredMoveto==0 );
100046 assert( pC->uc.pCursor!=0 );
100059 assert( pC->iDb>=0 );
100064 pTab = 0;
100065 zDb = 0;
100074 if( db->xUpdateCallback==0 || pTab->aCol==0 ){
100076 pTab = 0;
100082 assert( (pOp->p5 & OPFLAG_LASTROWID)==0 || (pOp->p5 & OPFLAG_NCHANGE)!=0 );
100087 assert( (pData->flags & (MEM_Blob|MEM_Str))!=0 || pData->n==0 );
100090 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
100094 x.nZero = 0;
100096 x.pKey = 0;
100102 pC->deferredMoveto = 0;
100109 assert( db->xUpdateCallback!=0 );
100110 assert( pTab->aCol!=0 );
100134 assert( pOp[1].opcode==OP_Insert || pOp->p3==0 );
100135 assert( pOp[1].opcode==OP_IdxInsert || pOp->p3>0 );
100139 iKey = pOp->p3 ? aMem[pOp->p3].u.i : 0;
100163 ** If the OPFLAG_NCHANGE (0x01) flag of P2 (NB: P2 not P5) is set, then
100166 ** If the OPFLAG_ISNOOP (0x40) flag of P2 (not P5!) is set, then the
100192 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100194 assert( pC!=0 );
100196 assert( pC->uc.pCursor!=0 );
100197 assert( pC->deferredMoveto==0 );
100203 && pOp->p5==0
100220 assert( pC->iDb>=0 );
100221 assert( pOp->p4.pTab!=0 );
100224 if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){
100228 zDb = 0;
100229 pTab = 0;
100234 assert( db->xPreUpdateCallback==0 || pTab==pOp->p4.pTab );
100237 || HasRowid(pTab)==0
100250 assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_AUXDELETE))==0 );
100255 if( p->pFrame==0 ){
100256 if( pC->isEphemeral==0
100257 && (pOp->p5 & OPFLAG_AUXDELETE)==0
100258 && (pC->wrFlag & OPFLAG_FORDELETE)==0
100271 pC->seekResult = 0;
100277 if( db->xUpdateCallback && ALWAYS(pTab!=0) && HasRowid(pTab) ){
100280 assert( pC->iDb>=0 );
100290 ** Then the VMs internal change counter resets to 0.
100295 p->nChange = 0;
100324 res = 0;
100326 VdbeBranchTaken(res!=0,2);
100352 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100373 ** If P3!=0 then this opcode is allowed to make an ephemeral pointer
100377 ** position in order that they can write to the same table. If P3==0
100378 ** then a copy of the data is made into memory. P3!=0 is faster, but
100379 ** P3==0 is safer.
100381 ** If P3!=0 then the content of the P2 register is unsuitable for use
100393 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100395 assert( pC!=0 );
100397 assert( isSorter(pC)==0 );
100398 assert( pC->nullRow==0 );
100399 assert( pC->uc.pCursor!=0 );
100410 assert( pC->deferredMoveto==0 );
100417 testcase( n==0 );
100443 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100445 assert( pC!=0 );
100454 assert( pC->uc.pVCur!=0 );
100464 assert( pC->uc.pCursor!=0 );
100489 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100491 if( pC==0 ){
100495 if( pC==0 ) goto no_mem;
100496 pC->seekResult = 0;
100504 assert( pC->uc.pCursor!=0 );
100508 if( pC->seekOp==0 ) pC->seekOp = OP_NullRow;
100527 ** If the table or index is empty and P2>0, then jump immediately to P2.
100528 ** If P2 is 0 or if the table or index is not empty, fall through
100541 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100543 assert( pC!=0 );
100546 res = 0;
100547 assert( pCrsr!=0 );
100552 assert( pOp->p2==0 );
100560 pC->deferredMoveto = 0;
100563 if( pOp->p2>0 ){
100564 VdbeBranchTaken(res!=0,2);
100584 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100589 assert( pC!=0 );
100594 if( res!=0 ){
100598 assert( sz>0 );
100602 VdbeBranchTaken(res!=0,2);
100659 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100660 assert( pOp->p5==0 );
100661 assert( pOp->p2>=0 && pOp->p2<p->nOp );
100664 assert( pC!=0 );
100677 pC->deferredMoveto = 0;
100682 if( pOp->p2>0 ){
100683 VdbeBranchTaken(res!=0,2);
100705 ** omitted if that index had been unique. P3 is usually 0. P3 is
100706 ** always either 0 or 1.
100730 ** omitted if that index had been unique. P3 is usually 0. P3 is
100731 ** always either 0 or 1.
100752 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100753 assert( pOp->p5==0
100757 assert( pC!=0 );
100758 assert( pC->deferredMoveto==0 );
100767 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100768 assert( pOp->p5==0
100772 assert( pC!=0 );
100773 assert( pC->deferredMoveto==0 );
100785 pC->nullRow = 0;
100830 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100833 assert( pC!=0 );
100839 assert( pC->isTable==0 );
100848 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
100850 assert( pC->deferredMoveto==0 );
100866 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100869 assert( pC!=0 );
100873 assert( pC->isTable==0 );
100902 assert( pOp->p3>0 );
100903 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem+1 - p->nCursor)+1 );
100904 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100906 assert( pC!=0 );
100910 assert( pCrsr!=0 );
100913 r.default_rc = 0;
100917 if( res==0 ){
100924 assert( pC->deferredMoveto==0 );
100926 pC->seekResult = 0;
100964 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100966 assert( pC!=0 );
100968 assert( pC->uc.pCursor!=0 );
100969 assert( pC->isTable==0 || IsNullCursor(pC) );
100970 assert( pC->deferredMoveto==0 );
100983 rowid = 0; /* Not needed. Only used to silence a warning. */
100989 assert( pOp->p3>=0 && pOp->p3<p->nCursor );
100991 assert( pTabCur!=0 );
100993 assert( pTabCur->uc.pCursor!=0 );
100995 pTabCur->nullRow = 0;
100999 assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 );
101024 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
101085 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
101087 assert( pC!=0 );
101090 assert( pC->uc.pCursor!=0);
101091 assert( pC->deferredMoveto==0 );
101100 r.default_rc = 0;
101106 for(i=0; i<r.nField; i++){
101115 i64 nCellKey = 0;
101123 /* nCellKey will always be between 0 and 0xffffffff because of the way
101125 if( nCellKey<=0 || nCellKey>0x7fffffff ){
101129 sqlite3VdbeMemInit(&m, db, 0);
101132 res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, &r, 0);
101145 VdbeBranchTaken(res>0,2);
101147 if( res>0 ) goto jump_to_p2;
101156 ** The table being destroyed is in the main database file if P3==0. If
101182 sqlite3VdbeIncrWriteCounter(p, 0);
101183 assert( p->readOnly==0 );
101194 iMoved = 0; /* Not needed. Only to silence a warning. */
101200 if( iMoved!=0 ){
101203 assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 );
101217 ** The table being cleared is in the main database file if P2==0. If
101231 sqlite3VdbeIncrWriteCounter(p, 0);
101232 nChange = 0;
101233 assert( p->readOnly==0 );
101238 if( pOp->p3>0 ){
101259 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
101261 assert( pC!=0 );
101276 ** Allocate a new b-tree in the main database file if P1==0 or in the
101286 sqlite3VdbeIncrWriteCounter(p, 0);
101288 pgno = 0;
101290 assert( pOp->p1>=0 && pOp->p1<db->nDb );
101292 assert( p->readOnly==0 );
101294 assert( pDb->pBt!=0 );
101307 ** 0x0001 Disable Auth and Trace callbacks while the statements
101310 ** 0x0002 Set db->nAnalysisLimit to P2 while the statements in
101322 sqlite3VdbeIncrWriteCounter(p, 0);
101324 zErr = 0;
101330 if( pOp->p1 & 0x0001 ){
101332 db->xAuth = 0;
101334 db->mTrace = 0;
101336 if( pOp->p1 & 0x0002 ){
101339 rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
101375 for(iDb=0; iDb<db->nDb; iDb++){
101381 assert( iDb>=0 && iDb<db->nDb );
101384 || (CORRUPT_DB && (db->flags & SQLITE_NoSchemaError)!=0) );
101387 if( pOp->p4.z==0 ){
101392 p->expired = 0;
101400 initData.mInitFlags = 0;
101405 if( zSql==0 ){
101408 assert( db->init.busy==0 );
101411 initData.nInitRow = 0;
101413 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
101415 if( rc==SQLITE_OK && initData.nInitRow==0 ){
101422 db->init.busy = 0;
101443 assert( pOp->p1>=0 && pOp->p1<db->nDb );
101459 sqlite3VdbeIncrWriteCounter(p, 0);
101473 sqlite3VdbeIncrWriteCounter(p, 0);
101487 sqlite3VdbeIncrWriteCounter(p, 0);
101524 assert( nRoot>0 );
101525 assert( aRoot!=0 );
101526 assert( aRoot[0]==(Pgno)nRoot );
101527 assert( pOp->p1>0 && (pOp->p1+1)<=(p->nMem+1 - p->nCursor) );
101529 assert( (pnErr->flags & MEM_Int)!=0 );
101530 assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
101537 if( nErr==0 ){
101538 assert( z==0 );
101563 assert( (pIn2->flags & MEM_Int)!=0 );
101564 if( (pIn1->flags & MEM_Blob)==0 ){
101584 assert( (pIn1->flags & MEM_Blob)==0 || sqlite3VdbeMemIsRowSet(pIn1) );
101585 if( (pIn1->flags & MEM_Blob)==0
101586 || sqlite3RowSetNext((RowSet*)pIn1->z, &val)==0
101594 VdbeBranchTaken(0,2);
101612 ** must have P4==0, the final set must have P4==-1, and for all other sets
101613 ** must have P4>0.
101615 ** This allows optimizations: (a) when P4==0 there is no need to test
101635 if( (pIn1->flags & MEM_Blob)==0 ){
101640 assert( iSet==-1 || iSet>=0 );
101643 VdbeBranchTaken(exists!=0,2);
101646 if( iSet>=0 ){
101684 assert( pProgram->nOp>0 );
101713 if( (pRt->flags&MEM_Blob)==0 ){
101720 assert( nMem>0 );
101721 if( pProgram->nCsr==0 ) nMem++;
101760 || (pProgram->nCsr==0 && pProgram->nMem+1==pFrame->nChildMem) );
101770 assert( pFrame->pAuxData==0 );
101772 p->pAuxData = 0;
101773 p->nChange = 0;
101780 memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
101788 for(i=0; i<p->nMem; i++){
101789 aMem[i].pScopyFrom = 0; /* Prevent false-positive AboutToChange() errs */
101845 ** Synopsis: if fkctr[P1]==0 goto P2
101858 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
101859 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
101861 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
101862 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
101900 ** Synopsis: if r[P1]>0 then r[P1]-=P3, goto P2
101912 VdbeBranchTaken( pIn1->u.i>0, 2);
101913 if( pIn1->u.i>0 ){
101921 ** Synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)
101946 if( x<=0 || sqlite3AddInt64(&x, pIn3->u.i>0?pIn3->u.i:0) ){
101962 ** Synopsis: if r[P1]!=0 then r[P1]--, goto P2
101972 VdbeBranchTaken(pIn1->u.i<0, 2);
101974 if( pIn1->u.i>0 ) pIn1->u.i--;
101981 ** Synopsis: if (--r[P1])==0 goto P2
101990 VdbeBranchTaken(pIn1->u.i==0, 2);
101991 if( pIn1->u.i==0 ) goto jump_to_p2;
102021 ** Execute the xStep (if P1==0) or xInverse (if P1!=0) function for an
102043 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
102044 assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) );
102056 if( pCtx==0 ) goto no_mem;
102061 pCtx->pMem = 0;
102065 pCtx->skipFlag = 0;
102066 pCtx->isError = 0;
102072 /* OP_AggInverse must have P1==1 and OP_AggStep must have P1==0 */
102092 assert( pMem->uTemp==0x1122e0e3 );
102095 pMem->uTemp = 0x1122e0e3;
102105 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
102109 for(i=0; i<pCtx->argc; i++){
102117 assert( pCtx->isError==0 );
102118 assert( pCtx->skipFlag==0 );
102127 if( pCtx->isError>0 ){
102135 pCtx->skipFlag = 0;
102139 pCtx->isError = 0;
102143 assert( pCtx->skipFlag==0 );
102176 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
102177 assert( pOp->p3==0 || pOp->opcode==OP_AggValue );
102179 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
102206 ** RESTART, or TRUNCATE. Write 1 or 0 into mem[P3] if the checkpoint returns
102218 assert( p->readOnly==0 );
102219 aRes[0] = 0;
102230 aRes[0] = 1;
102232 for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){
102270 assert( pOp->p1>=0 && pOp->p1<db->nDb );
102271 assert( p->readOnly==0 );
102287 && (sqlite3Strlen30(zFilename)==0 /* Temp file */
102348 ** Vacuum the entire database P1. P1 is 0 for "main", and 2 or more
102356 assert( p->readOnly==0 );
102358 pOp->p2 ? &aMem[pOp->p2] : 0);
102374 assert( pOp->p1>=0 && pOp->p1<db->nDb );
102376 assert( p->readOnly==0 );
102396 ** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
102399 ** If P2 is 0, then SQL statements are expired immediately. If P2 is 1,
102406 assert( pOp->p2==0 || pOp->p2==1 );
102422 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
102424 assert( pC!=0 );
102437 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
102439 assert( pC!=0 );
102453 ** on which the lock is acquired. A readlock is obtained if P3==0 or
102463 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommit) ){
102465 assert( p1>=0 && p1<db->nDb );
102467 assert( isWriteLock==0 || isWriteLock==1 );
102470 if( (rc&0xFF)==SQLITE_LOCKED ){
102511 memset(&sMem, 0, sizeof(sMem));
102515 assert( (aMem[pOp->p2].flags & MEM_Str)!=0 );
102516 assert( (aMem[pOp->p2].flags & MEM_Static)!=0 );
102560 pCur = 0;
102561 pVCur = 0;
102563 if( pVtab==0 || NEVER(pVtab->pModule==0) ){
102576 pCur = allocateCursor(p, pOp->p1, 0, CURTYPE_VTAB);
102603 char *zErr = 0;
102609 assert( pTab!=0 );
102610 assert( pTab->nTabRef>0 );
102612 if( pTab->u.vtab.p==0 ) break;
102614 assert( pVtab!=0 );
102616 assert( pModule!=0 );
102618 assert( pModule->xIntegrity!=0 );
102620 assert( pOp->p1>=0 && pOp->p1<db->nDb );
102652 if( pRhs==0 ) goto no_mem;
102679 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
102701 assert( pCur!=0 );
102708 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
102715 for(i = 0; i<nArg; i++){
102722 pCur->nullRow = 0;
102723 VdbeBranchTaken(res!=0,2);
102752 assert( pCur!=0 );
102753 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
102764 memset(&sContext, 0, sizeof(sContext));
102767 nullFunc.pUserData = 0;
102770 assert( pOp->p5==OPFLAG_NOCHNG || pOp->p5==0 );
102774 pDest->u.nZero = 0;
102780 if( sContext.isError>0 ){
102807 assert( pCur!=0 );
102853 assert( p->readOnly==0 );
102862 if( isLegacy==0 ) db->flags &= ~(u64)SQLITE_LegacyAlter;
102864 p->expired = 0;
102881 ** The argv[0] element (which corresponds to memory cell P3)
102882 ** is the rowid of a row to delete. If argv[0] is NULL then no
102888 ** If P2==1 then no insert is performed. argv[0] is the rowid of
102903 sqlite_int64 rowid = 0;
102910 assert( p->readOnly==0 );
102912 sqlite3VdbeIncrWriteCounter(p, 0);
102914 if( pVtab==0 || NEVER(pVtab->pModule==0) ){
102926 for(i=0; i<nArg; i++){
102937 assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
102940 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
102973 ** do not change the maximum page count value if P3==0.
102983 newMax = 0;
103005 ** argument was constant then bit 0 of P1 is set. This is used to determine
103024 ** argument was constant then bit 0 of P1 is set. This is used to determine
103056 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
103062 for(i=0; i<pCtx->argc; i++){
103068 assert( pCtx->isError==0 );
103073 if( pCtx->isError>0 ){
103078 pCtx->isError = 0;
103082 assert( (pOut->flags&MEM_Str)==0
103093 ** Synopsis: r[P1].subtype = 0
103134 pOut->eSubtype = (u8)(pIn1->u.i & 0xff);
103148 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
103151 assert( pIn1->n>0 );
103184 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
103186 assert( (pIn1->flags & MEM_Blob)!=0 );
103199 if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){
103205 VdbeBranchTaken(0, 2);
103215 ** Operand P1 must be 0x7fffffff and P2 must positive.
103251 assert( pOp->p4.z==0 || strncmp(pOp->p4.z, "-" "- ", 3)==0 );
103253 /* OP_Init is always instruction 0 */
103257 if( (db->mTrace & (SQLITE_TRACE_STMT|SQLITE_TRACE_LEGACY))!=0
103259 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
103280 for(j=0; j<db->nDb; j++){
103281 if( DbMaskTest(p->btreeMask, j)==0 ) continue;
103287 if( (db->flags & SQLITE_SqlTrace)!=0
103288 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
103294 assert( pOp->p2>0 );
103298 if( p->aOp[i].opcode==OP_Once ) p->aOp[i].p1 = 0;
103300 pOp->p1 = 0;
103318 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
103381 assert( pOp->p1>0 );
103385 for(i=0; i<pOp->p2; i++, pMem++){
103386 if( i>=32 || (constMask & MASKBIT32(i))==0 ){
103387 pMem->pScopyFrom = 0;
103437 pnCycle = 0;
103441 pnCycle = 0;
103456 if( rc!=0 ) printf("rc=%d\n",rc);
103463 if( opProperty==0xff ){
103487 if( zTrace==0 ){
103488 if( aOp[0].opcode==OP_Trace ){
103489 zTrace = aOp[0].p4.z;
103491 if( zTrace==0 ) zTrace = "???";
103496 if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){
103501 testcase( sqlite3GlobalConfig.xLog!=0 );
103506 if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){
103510 if( resetSchemaOnFault>0 ){
103521 pnCycle = 0;
103526 pnCycle = 0;
103531 while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
103544 assert( rc!=SQLITE_OK || nExtraDelete==0
103545 || sqlite3_strlike("DELETE%",p->zSql,0)!=0
103632 char *zErr = 0; /* Error message */
103652 VdbeCursor *pC = v->apCsr[0];
103654 assert( pC!=0 );
103656 type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0;
103661 type==0?"null": type==7?"real": "integer"
103665 p->pStmt = 0;
103678 p->pStmt = 0;
103687 assert( rc!=SQLITE_OK || zErr==0 );
103706 int nAttempt = 0;
103709 char *zErr = 0;
103711 Incrblob *pBlob = 0;
103716 if( ppBlob==0 ){
103720 *ppBlob = 0;
103722 if( !sqlite3SafetyCheckOk(db) || zTable==0 || zColumn==0 ){
103726 wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
103735 zErr = 0;
103738 pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
103740 pTab = 0;
103744 pTab = 0;
103747 if( pTab && (pTab->tabFlags&TF_HasGenerated)!=0 ){
103748 pTab = 0;
103754 pTab = 0;
103758 if( pTab==0
103765 sParse.zErrMsg = 0;
103776 if( iCol<0 ){
103788 const char *zFault = 0;
103800 for(j=0; j<pFKey->nCol; j++){
103810 for(j=0; j<pIdx->nKeyCol; j++){
103847 {OP_TableLock, 0, 0, 0}, /* 0: Acquire a read or write lock */
103848 {OP_OpenRead, 0, 0, 0}, /* 1: Open a cursor */
103850 {OP_NotExists, 0, 5, 1}, /* 2: Seek the cursor to rowid=r[1] */
103851 {OP_Column, 0, 0, 1}, /* 3 */
103852 {OP_ResultRow, 1, 0, 0}, /* 4 */
103853 {OP_Halt, 0, 0, 0}, /* 5 */
103868 if( db->mallocFailed==0 ){
103869 assert( aOp!=0 );
103872 aOp[0].opcode = OP_Noop;
103874 aOp[0].p1 = iDb;
103875 aOp[0].p2 = pTab->tnum;
103876 aOp[0].p3 = wrFlag;
103879 if( db->mallocFailed==0 ){
103899 sParse.nVar = 0;
103918 if( rc==SQLITE_OK && db->mallocFailed==0 ){
103924 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : (char*)0), zErr);
103969 if( p==0 ) return SQLITE_MISUSE_BKPT;
103974 if( n<0 || iOffset<0 || ((sqlite3_int64)iOffset+n)>p->nByte ){
103977 }else if( v==0 ){
104006 assert( v->apCsr[0]!=0 );
104007 assert( v->apCsr[0]->eCurType==CURTYPE_BTREE );
104009 v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1, p->iCol
104018 p->pStmt = 0;
104051 return (p && p->pStmt) ? p->nByte : 0;
104069 if( p==0 ) return SQLITE_MISUSE_BKPT;
104073 if( p->pStmt==0 ){
104083 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : (char*)0), zErr);
104090 assert( rc==SQLITE_OK || p->pStmt==0 );
104179 ** A PMA created at this point is known as a "level-0 PMA". Higher levels
104181 ** merging two or more level-0 PMAs together creates a level-1 PMA.
104201 ** "PRAGMA threads=N" with some value of N greater than 0.
104244 #if 0
104250 ** to a level 0 PMA. The purpose of this limit is to prevent various integer
104279 ** If aMemory==0 then each object is allocated separately and the objects
104280 ** are connected using SorterRecord.u.pNext. If aMemory!=0 then all objects
104319 ** currently points to the smallest key value. aTree[0] is unused.
104323 ** aReadr[0] -> Banana
104332 ** aTree[] = { X, 5 0, 5 0, 3, 5, 6 }
104345 ** 5, so aTree[3] is set to 6. Key 0 is smaller than key 6 (Banana<Durian),
104346 ** so the value written into element 1 of the array is 0. As follows:
104348 ** aTree[] = { X, 0 0, 6 0, 3, 5, 6 }
104375 ** Before a background thread is launched, variable bDone is set to 0. Then,
104379 ** 1. When flushing the contents of memory to a level-0 PMA on disk, to
104388 ** In both cases, the effects of the main thread seeing (bDone==0) even
104401 SorterFile file; /* Temp file for level-0 PMAs */
104417 int mxPmaSize; /* Maximum PMA size, in bytes. 0==no limit */
104421 MergeEngine *pMerger; /* Or here, if bUseThreads==0 */
104439 #define SORTER_TYPE_INTEGER 0x01
104440 #define SORTER_TYPE_TEXT 0x02
104449 ** pFd==0 at EOF.
104471 ** There are two types of IncrMerger object - single (bUseThread==0) and
104474 ** A multi-threaded IncrMerger object uses two temporary files - aFile[0]
104477 ** pMerger to populate aFile[0]. It then sets variables within the
104482 ** When the PmaReader reaches the end of aFile[0], it blocks until the
104484 ** the contents of the aFile[0] and aFile[1] variables within this structure,
104485 ** sets the PmaReader fields to read from the new aFile[0] and kicks off
104504 SorterFile aFile[2]; /* aFile[0] for reading, [1] for writing */
104531 ** (VdbeSorter.list.aMemory==0), then the list is always connected using the
104534 ** Or, if using the single large allocation method (VdbeSorter.list.aMemory!=0),
104573 if( pReadr->aMap ) sqlite3OsUnfetch(pReadr->pFd, 0, pReadr->aMap);
104575 memset(pReadr, 0, sizeof(PmaReader));
104607 if( iBuf==0 ){
104617 assert( nRead>0 );
104657 while( nRem>0 ){
104660 u8 *aNext = 0; /* Pointer to buffer to copy data from */
104667 assert( aNext!=0 );
104693 int i = 0, rc;
104697 aVarint[(i++)&0xf] = a[0];
104698 }while( (a[0]&0x80)!=0 );
104720 rc = sqlite3OsFetch(pFd, 0, (int)pFile->iEof, (void**)pp);
104740 assert( pReadr->pIncr==0 || pReadr->pIncr->bEof==0 );
104744 sqlite3OsUnfetch(pReadr->pFd, 0, pReadr->aMap);
104745 pReadr->aMap = 0;
104752 if( rc==SQLITE_OK && pReadr->aMap==0 ){
104755 if( pReadr->aBuffer==0 ){
104757 if( pReadr->aBuffer==0 ) rc = SQLITE_NOMEM_BKPT;
104781 u64 nRec = 0; /* Size of record in bytes */
104789 if( rc==SQLITE_OK && pIncr->bEof==0 ){
104791 pIncr->pTask, pReadr, &pIncr->aFile[0], pIncr->iStartOff
104793 bEof = 0;
104836 assert( pReadr->aAlloc==0 && pReadr->nAlloc==0 );
104837 assert( pReadr->aBuffer==0 );
104838 assert( pReadr->aMap==0 );
104842 u64 nByte = 0; /* Size of PMA in bytes */
104866 if( *pbKey2Cached==0 ){
104913 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
104914 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
104923 if( res==0 ){
104927 if( res==0 ){
104934 assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
104935 if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
104957 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
104958 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
104961 assert( (s1>0 && s1<7) || s1==8 || s1==9 );
104962 assert( (s2>0 && s2<7) || s2==8 || s2==9 );
104966 static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8, 0, 0, 0 };
104969 res = 0;
104970 for(i=0; i<n; i++){
104971 if( (res = v1[i] - v2[i])!=0 ){
104972 if( ((v1[0] ^ v2[0]) & 0x80)!=0 ){
104973 res = v1[0] & 0x80 ? -1 : +1;
104988 assert( res!=0 );
104990 if( res>0 ){
104991 if( *v1 & 0x80 ) res = -1;
104993 if( *v2 & 0x80 ) res = +1;
104997 if( res==0 ){
105003 }else if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
105004 assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
105038 KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
105042 #if SQLITE_MAX_WORKER_THREADS==0
105043 # define nWorker 0
105049 #if SQLITE_MAX_WORKER_THREADS>0
105050 if( sqlite3TempInMemory(db) || sqlite3GlobalConfig.bCoreMutex==0 ){
105051 nWorker = 0;
105069 < 0x7fffffff );
105075 if( pSorter==0 ){
105078 Btree *pBt = db->aDb[0].pBt;
105081 pKeyInfo->db = 0;
105082 if( nField && nWorker==0 ){
105092 for(i=0; i<pSorter->nTask; i++){
105102 mxCache = db->aDb[0].pSchema->cache_size;
105103 if( mxCache<0 ){
105115 if( sqlite3GlobalConfig.bSmallMalloc==0 ){
105116 assert( pSorter->iMemory==0 );
105124 && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
105125 && (pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL)==0
105153 #if SQLITE_MAX_WORKER_THREADS>0
105155 ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
105161 assert( pTask->list.aMemory==0 );
105162 vdbeSorterRecordFree(0, pTask->list.pList);
105170 memset(pTask, 0, sizeof(SortSubtask));
105181 i64 t = 0;
105182 sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
105213 #if SQLITE_MAX_WORKER_THREADS>0
105229 pTask->bDone = 0;
105230 pTask->pThread = 0;
105243 assert( pTask->pThread==0 && pTask->bDone==0 );
105249 ** level-0 PMAs.
105262 for(i=pSorter->nTask-1; i>=0; i--){
105291 pNew = sqlite3FaultSim(100) ? 0 : (MergeEngine*)sqlite3MallocZero(nByte);
105294 pNew->pTask = 0;
105307 for(i=0; i<pMerger->nTree; i++){
105320 #if SQLITE_MAX_WORKER_THREADS>0
105323 if( pIncr->aFile[0].pFd ) sqlite3OsCloseFree(pIncr->aFile[0].pFd);
105338 assert( pSorter->bUseThreads || pSorter->pReader==0 );
105339 #if SQLITE_MAX_WORKER_THREADS>0
105343 pSorter->pReader = 0;
105347 pSorter->pMerger = 0;
105348 for(i=0; i<pSorter->nTask; i++){
105353 if( pSorter->list.aMemory==0 ){
105354 vdbeSorterRecordFree(0, pSorter->list.pList);
105356 pSorter->list.pList = 0;
105357 pSorter->list.szPMA = 0;
105358 pSorter->bUsePMA = 0;
105359 pSorter->iMemory = 0;
105360 pSorter->mxKeysize = 0;
105362 pSorter->pUnpacked = 0;
105376 pCsr->uc.pSorter = 0;
105380 #if SQLITE_MAX_MMAP_SIZE>0
105392 void *p = 0;
105396 sqlite3OsFetch(pFd, 0, (int)nByte, &p);
105397 if( p ) sqlite3OsUnfetch(pFd, 0, p);
105407 ** Otherwise, set *ppFd to 0 and return an SQLite error code.
105416 rc = sqlite3OsOpenMalloc(db->pVfs, 0, ppFd,
105424 if( nExtend>0 ){
105437 if( pTask->pUnpacked==0 ){
105439 if( pTask->pUnpacked==0 ) return SQLITE_NOMEM_BKPT;
105441 pTask->pUnpacked->errCode = 0;
105455 SorterRecord *pFinal = 0;
105457 int bCached = 0;
105459 assert( p1!=0 && p2!=0 );
105466 if( res<=0 ){
105470 if( p1==0 ){
105478 bCached = 0;
105479 if( p2==0 ){
105517 memset(aSlot, 0, sizeof(aSlot));
105523 pNext = 0;
105532 p->u.pNext = 0;
105533 for(i=0; aSlot[i]; i++){
105539 aSlot[i] = 0;
105545 p = 0;
105546 for(i=0; i<ArraySize(aSlot); i++){
105547 if( aSlot[i]==0 ) continue;
105567 memset(p, 0, sizeof(PmaWriter));
105585 while( nRem>0 && p->eFWErr==0 ){
105598 p->iBufStart = p->iBufEnd = 0;
105618 if( p->eFWErr==0 && ALWAYS(p->aBuffer) && p->iBufEnd>p->iBufStart ){
105627 memset(p, 0, sizeof(PmaWriter));
105643 ** Write the current contents of in-memory linked-list pList to a level-0
105668 memset(&writer, 0, sizeof(PmaWriter));
105669 assert( pList->szPMA>0 );
105672 if( pTask->file.pFd==0 ){
105673 rc = vdbeSorterOpenTempFile(db, 0, &pTask->file.pFd);
105675 assert( pTask->file.iEof==0 );
105676 assert( pTask->nPMA==0 );
105691 SorterRecord *pNext = 0;
105701 if( pList->aMemory==0 ) sqlite3_free(p);
105708 assert( rc!=SQLITE_OK || pList->pList==0 );
105736 int bCached = 0;
105740 pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
105741 pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
105743 for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
105746 if( pReadr1->pFd==0 ){
105748 }else if( pReadr2->pFd==0 ){
105771 if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
105773 pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
105774 bCached = 0;
105776 if( pReadr1->pFd ) bCached = 0;
105778 pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
105781 *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
105787 #if SQLITE_MAX_WORKER_THREADS>0
105789 ** The main routine for background threads that write level-0 PMAs.
105794 assert( pTask->bDone==0 );
105799 #endif /* SQLITE_MAX_WORKER_THREADS>0 */
105806 #if SQLITE_MAX_WORKER_THREADS==0
105808 return vdbeSorterListToPMA(&pSorter->aTask[0], &pSorter->list);
105812 SortSubtask *pTask = 0; /* Thread context used to create new PMA */
105827 for(i=0; i<nWorker; i++){
105833 if( rc!=SQLITE_OK || pTask->pThread==0 ) break;
105845 assert( pTask!=0 );
105846 assert( pTask->pThread==0 && pTask->bDone==0 );
105847 assert( pTask->list.pList==0 );
105848 assert( pTask->list.aMemory==0 || pSorter->list.aMemory!=0 );
105854 pSorter->list.pList = 0;
105855 pSorter->list.szPMA = 0;
105869 #endif /* SQLITE_MAX_WORKER_THREADS!=0 */
105890 if( t>0 && t<10 && t!=7 ){
105892 }else if( t>10 && (t & 0x01) ){
105895 pSorter->typeMask = 0;
105903 ** If using the single large allocation mode (pSorter->aMemory!=0), then
105929 pSorter->list.szPMA = 0;
105930 pSorter->iMemory = 0;
105931 assert( rc!=SQLITE_OK || pSorter->list.pList==0 );
105955 if( iListOff>=0 ){
105969 if( pNew==0 ){
105995 assert( pIncr->bEof==0 );
106008 if( pReader->pFd==0 ) break;
106024 #if SQLITE_MAX_WORKER_THREADS>0
106048 ** finished reading the contents of aFile[0]. Its purpose is to "refill"
106049 ** aFile[0] such that the PmaReader should start rereading it from the
106053 ** keys from pIncr->pMerger and repopulating aFile[0].
106057 ** aFile[0] and aFile[1] in place. If the contents of pMerger have not
106066 #if SQLITE_MAX_WORKER_THREADS>0
106071 SorterFile f0 = pIncr->aFile[0];
106072 pIncr->aFile[0] = pIncr->aFile[1];
106077 if( pIncr->aFile[0].iEof==pIncr->iStartOff ){
106087 pIncr->aFile[0] = pIncr->aFile[1];
106088 if( pIncr->aFile[0].iEof==pIncr->iStartOff ){
106109 (sqlite3FaultSim(100) ? 0 : sqlite3MallocZero(sizeof(*pIncr)));
106119 assert( *ppOut!=0 || rc!=SQLITE_OK );
106123 #if SQLITE_MAX_WORKER_THREADS>0
106131 #endif /* SQLITE_MAX_WORKER_THREADS>0 */
106150 assert( iOut<pMerger->nTree && iOut>0 );
106163 if( p1->pFd==0 ){
106165 }else if( p2->pFd==0 ){
106169 int bCached = 0;
106171 assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
106175 if( res<=0 ){
106190 ** SQLITE_MAX_WORKER_THREADS==0). The other values are only used
106193 #define INCRINIT_NORMAL 0
106211 ** already been populated, but that they have not yet populated aFile[0] and
106233 assert( pMerger!=0 );
106236 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
106239 assert( pMerger->pTask==0 );
106243 for(i=0; i<nTree; i++){
106244 if( SQLITE_MAX_WORKER_THREADS>0 && eMode==INCRINIT_ROOT ){
106259 for(i=pMerger->nTree-1; i>0; i--){
106267 ** incremental-reader (pReadr->pIncr!=0). This function serves to open
106305 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
106314 #if SQLITE_MAX_WORKER_THREADS>0
106316 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
106323 if( pTask->file2.pFd==0 ){
106324 assert( pTask->file2.iEof>0 );
106326 pTask->file2.iEof = 0;
106336 #if SQLITE_MAX_WORKER_THREADS>0
106353 if( rc==SQLITE_OK && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) ){
106360 #if SQLITE_MAX_WORKER_THREADS>0
106377 ** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes
106390 #if SQLITE_MAX_WORKER_THREADS>0
106391 assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK );
106405 ** Allocate a new MergeEngine object to merge the contents of nPMA level-0
106428 if( pNew==0 ) rc = SQLITE_NOMEM_BKPT;
106430 for(i=0; i<nPMA && rc==SQLITE_OK; i++){
106431 i64 nDummy = 0;
106439 *ppOut = 0;
106451 ** nPMA<=16 -> TreeDepth() == 0
106456 int nDepth = 0;
106496 if( pReadr->pIncr==0 ){
106498 if( pNew==0 ){
106520 ** that has already written two or more level-0 PMAs to one or more temp
106533 MergeEngine *pMain = 0;
106537 #if SQLITE_MAX_WORKER_THREADS>0
106544 if( pMain==0 ) rc = SQLITE_NOMEM_BKPT;
106548 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
106550 assert( pTask->nPMA>0 || SQLITE_MAX_WORKER_THREADS>0 );
106551 if( SQLITE_MAX_WORKER_THREADS==0 || pTask->nPMA ){
106552 MergeEngine *pRoot = 0; /* Root node of tree for this task */
106554 i64 iReadOff = 0;
106560 int iSeq = 0;
106562 if( pRoot==0 ) rc = SQLITE_NOMEM_BKPT;
106563 for(i=0; i<pTask->nPMA && rc==SQLITE_OK; i += SORTER_MAX_MERGE_COUNT){
106564 MergeEngine *pMerger = 0; /* New level-0 PMA merger */
106565 int nReader; /* Number of level-0 PMAs to merge */
106576 #if SQLITE_MAX_WORKER_THREADS>0
106577 if( pMain!=0 ){
106582 assert( pMain==0 );
106593 pMain = 0;
106610 SortSubtask *pTask0 = &pSorter->aTask[0];
106611 MergeEngine *pMain = 0;
106616 for(i=0; i<pSorter->nTask; i++){
106624 assert( pSorter->bUseThreads==0 || pSorter->nTask>1 );
106627 PmaReader *pReadr = 0;
106633 if( pReadr==0 ) rc = SQLITE_NOMEM_BKPT;
106639 for(iTask=0; iTask<(pSorter->nTask-1); iTask++){
106646 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
106657 assert( p->pIncr==0 || (
106659 && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */
106664 pMain = 0;
106674 pMain = 0;
106701 if( pSorter->bUsePMA==0 ){
106703 *pbEof = 0;
106704 rc = vdbeSorterSort(&pSorter->aTask[0], &pSorter->list);
106725 assert( pSorter->pReader==0 );
106728 *pbEof = 0;
106748 assert( pSorter->bUsePMA || (pSorter->pReader==0 && pSorter->pMerger==0) );
106750 assert( pSorter->pReader==0 || pSorter->pMerger==0 );
106751 assert( pSorter->bUseThreads==0 || pSorter->pReader );
106753 #if SQLITE_MAX_WORKER_THREADS>0
106756 if( rc==SQLITE_OK && pSorter->pReader->pFd==0 ) rc = SQLITE_DONE;
106760 int res = 0;
106761 assert( pSorter->pMerger!=0 );
106762 assert( pSorter->pMerger->pTask==(&pSorter->aTask[0]) );
106769 pFree->u.pNext = 0;
106770 if( pSorter->list.aMemory==0 ) vdbeSorterRecordFree(db, pFree);
106787 #if SQLITE_MAX_WORKER_THREADS>0
106856 if( r2==0 ){
106858 if( r2==0 ) return SQLITE_NOMEM_BKPT;
106865 for(i=0; i<nKeyCol; i++){
106903 int bTablesUsed; /* 2 for tables_used(). 0 for bytecode(). */
106936 int isTabUsed = pAux!=0;
106972 if( pNew==0 ) return SQLITE_NOMEM;
106973 memset(pNew, 0, sizeof(*pNew));
106996 if( pCur==0 ) return SQLITE_NOMEM;
106997 memset(pCur, 0, sizeof(*pCur));
107008 pCur->zP4 = 0;
107014 pCur->pStmt = 0;
107015 pCur->needFinalize = 0;
107016 pCur->zType = 0;
107017 pCur->zSchema = 0;
107018 pCur->zName = 0;
107041 pCur->zP4 = 0;
107044 pCur->zName = 0;
107045 pCur->zType = 0;
107046 pCur->zSchema = 0;
107050 pCur->showSubprograms ? &pCur->sub : 0,
107057 pCur->aOp = 0;
107068 return pCur->aOp==0;
107087 if( i<=2 && pCur->zType==0 ){
107103 if( pCur->zName==0 ){
107117 case 0: /* addr */
107135 if( pCur->zP4==0 ){
107152 assert( aOp[0].opcode==OP_Init );
107153 assert( aOp[0].p4.z==0 || strncmp(aOp[0].p4.z,"-" "- ",3)==0 );
107156 }else if( aOp[0].p4.z!=0 ){
107157 sqlite3_result_text(ctx, aOp[0].p4.z+3, -1, SQLITE_STATIC);
107174 sqlite3_result_int(ctx, 0);
107207 ** idxNum==0 means show all subprograms
107221 pCur->iRowid = 0;
107222 pCur->iAddr = 0;
107223 pCur->showSubprograms = idxNum==0;
107225 if( sqlite3_value_type(argv[0])==SQLITE_TEXT ){
107226 const char *zSql = (const char*)sqlite3_value_text(argv[0]);
107227 if( zSql==0 ){
107230 rc = sqlite3_prepare_v2(pVTab->db, zSql, -1, &pCur->pStmt, 0);
107234 pCur->pStmt = (sqlite3_stmt*)sqlite3_value_pointer(argv[0],"stmt-pointer");
107236 if( pCur->pStmt==0 ){
107264 pIdxInfo->idxNum = 0;
107265 for(i=0, p=pIdxInfo->aConstraint; i<pIdxInfo->nConstraint; i++, p++){
107266 if( p->usable==0 ) continue;
107285 /* iVersion */ 0,
107286 /* xCreate */ 0,
107290 /* xDestroy */ 0,
107298 /* xUpdate */ 0,
107299 /* xBegin */ 0,
107300 /* xSync */ 0,
107301 /* xCommit */ 0,
107302 /* xRollback */ 0,
107303 /* xFindMethod */ 0,
107304 /* xRename */ 0,
107305 /* xSavepoint */ 0,
107306 /* xRelease */ 0,
107307 /* xRollbackTo */ 0,
107308 /* xShadowName */ 0,
107309 /* xIntegrity */ 0
107315 rc = sqlite3_create_module(db, "bytecode", &bytecodevtabModule, 0);
107427 assert( p->readpoint.iOffset==0 || p->readpoint.pChunk!=0 );
107428 if( p->readpoint.iOffset!=iOfst || iOfst==0 ){
107429 sqlite3_int64 iOff = 0;
107438 assert( pChunk!=0 );
107448 iChunkOffset = 0;
107449 } while( nRead>=0 && (pChunk=pChunk->pNext)!=0 && nRead>0 );
107450 p->readpoint.iOffset = pChunk ? iOfst+iAmt : 0;
107476 memset(p, 0, sizeof(MemJournal));
107477 rc = sqlite3OsOpen(copy.pVfs, copy.zJournal, pReal, copy.flags, 0);
107480 i64 iOff = 0;
107525 if( p->nSpill>0 && (iAmt+iOfst)>p->nSpill ){
107541 if( iOfst>0 && iOfst!=p->endpoint.iOffset ){
107544 if( iOfst==0 && p->pFirst ){
107548 while( nWrite>0 ){
107553 assert( pChunk!=0 || iChunkOffset==0 );
107554 if( iChunkOffset==0 ){
107560 pNew->pNext = 0;
107571 assert( pChunk!=0 );
107588 assert( p->endpoint.pChunk==0 || p->endpoint.pChunk->pNext==0 );
107590 FileChunk *pIter = 0;
107591 if( size==0 ){
107593 p->pFirst = 0;
107601 pIter->pNext = 0;
107607 p->readpoint.pChunk = 0;
107608 p->readpoint.iOffset = 0;
107653 0, /* xLock */
107654 0, /* xUnlock */
107655 0, /* xCheckReservedLock */
107656 0, /* xFileControl */
107657 0, /* xSectorSize */
107658 0, /* xDeviceCharacteristics */
107659 0, /* xShmMap */
107660 0, /* xShmLock */
107661 0, /* xShmBarrier */
107662 0, /* xShmUnmap */
107663 0, /* xFetch */
107664 0 /* xUnfetch */
107671 ** nSpill. If nSpill is 0, then the journal file is always create and
107688 assert( zName || nSpill<0 || (flags & SQLITE_OPEN_EXCLUSIVE) );
107694 memset(p, 0, sizeof(MemJournal));
107695 if( nSpill==0 ){
107696 return sqlite3OsOpen(pVfs, zName, pJfd, flags, 0);
107699 if( nSpill>0 ){
107718 sqlite3JournalOpen(0, 0, pJfd, 0, -1);
107734 p->nSpill>0
107739 NEVER(p->nSpill>0)
107841 assert( pExpr->x.pList==0 || pExpr->pRight==0 );
107879 for(i=p->nExpr, pItem=p->a; i>0; i--, pItem++){
107913 || ((pParse = pWalker->pParse)!=0 && IN_RENAME_OBJECT)
107920 int rc = walkWindowList(pWalker, p->pWinDefn, 0);
107942 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
107977 if( p==0 ) return WRC_Continue;
107978 if( pWalker->xSelectCallback==0 ) return WRC_Continue;
107991 }while( p!=0 );
108073 if( N>0 ){
108075 memset(&w, 0, sizeof(w));
108104 int iCol, /* A column in the result set. 0..pEList->nExpr-1 */
108112 assert( iCol>=0 && iCol<pEList->nExpr );
108114 assert( pOrig!=0 );
108118 pDup = sqlite3ExprDup(db, pOrig, 0);
108121 pDup = 0;
108133 if( ALWAYS(pExpr->y.pWin!=0) ){
108168 if( eEName!=ENAME_TAB && (eEName!=ENAME_ROWID || NEVER(pbRowid==0)) ){
108169 return 0;
108171 assert( pbRowid==0 || *pbRowid==0 );
108173 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
108174 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
108175 return 0;
108178 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
108179 if( zTab && (sqlite3StrNICmp(zSpan, zTab, n)!=0 || zTab[n]!=0) ){
108180 return 0;
108184 if( eEName==ENAME_TAB && sqlite3StrICmp(zSpan, zCol)!=0 ) return 0;
108185 if( eEName==ENAME_ROWID && sqlite3IsRowid(zCol)==0 ) return 0;
108198 if( sqlite3WritableSchema(db) && (db->flags & SQLITE_DqsDML)!=0 ){
108201 return (db->flags & SQLITE_DqsDDL)!=0;
108204 return (db->flags & SQLITE_DqsDML)!=0;
108219 assert( pExTab!=0 );
108221 if( (pExTab->tabFlags & TF_HasGenerated)!=0
108222 && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
108247 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
108252 assert( (pMatch->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 );
108267 assert( pTab!=0 );
108269 if( sqlite3StrNICmp(zTab, "sqlite_", 7)!=0 ) return 0;
108271 if( strcmp(zLegacy+7, &LEGACY_TEMP_SCHEMA_TABLE[7])==0 ){
108272 if( sqlite3StrICmp(zTab+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 ){
108275 if( zDb==0 ) return 0;
108276 if( sqlite3StrICmp(zTab+7, &LEGACY_SCHEMA_TABLE[7])==0 ) return 1;
108277 if( sqlite3StrICmp(zTab+7, &PREFERRED_SCHEMA_TABLE[7])==0 ) return 1;
108279 if( sqlite3StrICmp(zTab+7, &PREFERRED_SCHEMA_TABLE[7])==0 ) return 1;
108281 return 0;
108320 int cnt = 0; /* Number of matching column names */
108321 int cntTab = 0; /* Number of potential "rowid" matches */
108322 int nSubquery = 0; /* How many levels of subquery */
108325 SrcItem *pMatch = 0; /* The matching pSrcList item */
108327 Schema *pSchema = 0; /* Schema of the expression */
108329 Table *pTab = 0; /* Table holding the row */
108330 ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */
108335 assert( zDb==0 || zTab!=0 );
108349 if( (pNC->ncFlags & (NC_PartIdx|NC_IsCheck))!=0 ){
108354 zDb = 0;
108356 for(i=0; i<db->nDb; i++){
108358 if( sqlite3StrICmp(db->aDb[i].zDbSName,zDb)==0 ){
108363 if( i==db->nDb && sqlite3StrICmp("main", zDb)==0 ){
108366 pSchema = db->aDb[0].pSchema;
108367 zDb = db->aDb[0].zDbSName;
108373 assert( pNC && cnt==0 );
108379 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
108381 assert( pTab!=0 && pTab->zName!=0 );
108382 assert( pTab->nCol>0 || pParse->nErr );
108391 int hit = 0;
108394 assert( pItem->u4.pSubq!=0 );
108396 assert( pSel!=0 );
108398 assert( pEList!=0 );
108400 for(j=0; j<pEList->nExpr; j++){
108401 int bRowid = 0; /* True if possible rowid match */
108405 if( bRowid==0 ){
108406 if( cnt>0 ){
108407 if( pItem->fg.isUsing==0
108408 || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
108414 pFJMatch = 0;
108416 if( (pItem->fg.jointype & JT_RIGHT)==0 ){
108420 if( (pItem->fg.jointype & JT_LEFT)==0 ){
108422 cnt = 0;
108424 pFJMatch = 0;
108432 }else if( cnt>0 ){
108443 assert( bRowid==0 || pEList->a[j].fg.bUsingTerm==0 );
108446 if( hit || zTab==0 ) continue;
108448 assert( zDb==0 || zTab!=0 );
108452 if( pSchema==0 && strcmp(zDb,"*")!=0 ) continue;
108454 if( pItem->zAlias!=0 ){
108455 if( sqlite3StrICmp(zTab, pItem->zAlias)!=0 ){
108458 }else if( sqlite3StrICmp(zTab, pTab->zName)!=0 ){
108464 sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
108468 if( j>=0 ){
108469 if( cnt>0 ){
108470 if( pItem->fg.isUsing==0
108471 || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
108477 pFJMatch = 0;
108479 if( (pItem->fg.jointype & JT_RIGHT)==0 ){
108483 if( (pItem->fg.jointype & JT_LEFT)==0 ){
108485 cnt = 0;
108487 pFJMatch = 0;
108501 if( 0==cnt && VisibleRowid(pTab) ){
108513 if( cntTab==0
108515 && pMatch!=0
108516 && ALWAYS(pMatch->pSTab!=0)
108517 && (pMatch->pSTab->tabFlags & TF_Ephemeral)!=0
108518 && (pTab->tabFlags & TF_Ephemeral)==0)
108539 if( (pMatch->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 ){
108552 if( cnt==0 && zDb==0 ){
108553 pTab = 0;
108555 if( pParse->pTriggerTab!=0 ){
108559 if( (pNC->ncFlags & NC_UBaseReg)!=0
108560 && ALWAYS(zTab==0
108561 || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0
108562 || isValidSchemaTableName(zTab, pParse->pTriggerTab, 0))
108567 }else if( op!=TK_DELETE && zTab && sqlite3StrICmp("new",zTab) == 0 ){
108570 }else if( op!=TK_INSERT && zTab && sqlite3StrICmp("old",zTab)==0 ){
108571 pExpr->iTable = 0;
108577 if( (pNC->ncFlags & NC_UUpsert)!=0 && zTab!=0 ){
108579 if( pUpsert && sqlite3StrICmp("excluded",zTab)==0 ){
108580 pTab = pUpsert->pUpsertSrc->a[0].pSTab;
108591 if( iCol>=0 ){
108602 pMatch = 0;
108631 if( iCol<0 ){
108633 }else if( pExpr->iTable==0 ){
108636 pParse->oldmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
108640 pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
108653 if( cnt==0
108656 && (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0
108661 #if SQLITE_ALLOW_ROWID_IN_VIEW+0==2
108662 if( pMatch->pSTab!=0 && IsView(pMatch->pSTab) ){
108666 if( pMatch->fg.isNestedFrom==0 ) pExpr->iColumn = -1;
108688 if( cnt==0
108689 && (pNC->ncFlags & NC_UEList)!=0
108690 && zTab==0
108693 assert( pEList!=0 );
108694 for(j=0; j<pEList->nExpr; j++){
108697 && sqlite3_stricmp(zAs, zCol)==0
108700 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
108701 assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
108702 assert( ExprUseXSelect(pExpr)==0 || pExpr->x.pSelect==0 );
108704 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
108709 && ((pNC->ncFlags&NC_AllowWin)==0 || pNC!=pTopNC )
108720 pMatch = 0;
108721 assert( zTab==0 && zDb==0 );
108723 sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr);
108731 ** we have a match (cnt>0) or when we run out of name contexts.
108749 if( cnt==0 && zTab==0 ){
108774 memset(&pExpr->y, 0, sizeof(pExpr->y));
108783 ** cnt==0 means there was not match.
108786 ** cnt==0 is always an error. cnt>1 is often an error, but might
108789 assert( pFJMatch==0 || cnt>0 );
108799 pExpr->pLeft = 0;
108801 pExpr->pRight = 0;
108811 pFJMatch = 0;
108814 zErr = cnt==0 ? "no such column" : "ambiguous column name";
108819 }else if( cnt==0 && ExprHasProperty(pRight,EP_DblQuoted) ){
108831 assert( pFJMatch==0 );
108836 pExpr->pLeft = 0;
108838 pExpr->pRight = 0;
108843 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
108844 ** bit 0 to be set. Column 1 sets bit 1. And so forth. Bit 63 is
108857 if( pExpr->iColumn>=0 ){
108867 assert( pNC!=0 );
108878 assert( pTopNC!=0 );
108894 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
108905 if( (pTab->tabFlags & TF_HasGenerated)!=0
108906 && (pTab->aCol[iCol].colFlags & COLFLAG_GENERATED)!=0
108957 assert( ((X)&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 ); \
108958 if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E,R);
108979 ** node in the expression tree. Return 0 to continue the search down
108991 assert( pNC!=0 );
108996 if( pNC->pSrcList && pNC->pSrcList->nAlloc>0 ){
108999 for(i=0; i<pNC->pSrcList->nSrc; i++){
109000 assert( pSrcList->a[i].iCursor>=0 && pSrcList->a[i].iCursor<pParse->nTab);
109057 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
109067 for(i=0, p=pNC; p; p=p->pNext, i++){
109068 if( (p->ncFlags & NC_Where)==0 ){
109075 if( sqlite3TreeTrace & 0x80000 ){
109086 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
109090 pExpr->pLeft = 0;
109109 zDb = 0;
109110 zTable = 0;
109118 NC_IdxExpr|NC_GenCol, 0, pExpr);
109121 zDb = 0;
109145 int no_such_func = 0; /* True if no such function exists */
109146 int wrong_num_args = 0; /* True if wrong number of arguments */
109147 int is_agg = 0; /* True if is an aggregate function */
109153 Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
109156 assert( pExpr->pLeft==0 || pExpr->pLeft->op==TK_ORDER );
109158 n = pList ? pList->nExpr : 0;
109160 pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
109161 if( pDef==0 ){
109162 pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
109163 if( pDef==0 ){
109169 is_agg = pDef->xFinalize!=0;
109174 if( pExpr->iTable<0 ){
109190 pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120;
109195 int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0);
109220 for(ii=0; ii<n; ii++){
109232 if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
109240 NC_IdxExpr|NC_PartIdx|NC_GenCol, 0, pExpr);
109242 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
109245 if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
109246 && pParse->nested==0
109247 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
109254 pDef = 0;
109256 if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
109264 if( 0==IN_RENAME_OBJECT ){
109266 assert( is_agg==0 || (pDef->funcFlags & SQLITE_FUNC_MINMAX)
109267 || (pDef->xValue==0 && pDef->xInverse==0)
109270 if( pDef && pDef->xValue==0 && pWin ){
109276 (is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
109278 || (is_agg && pWin && (pNC->ncFlags & NC_AllowWin)==0)
109288 is_agg = 0;
109291 if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){
109294 is_agg = 0;
109297 else if( no_such_func && pParse->db->init.busy==0
109299 && pParse->explain==0
109310 else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
109318 else if( is_agg==0 && pExpr->pLeft ){
109327 pNC->ncFlags &= ~(NC_AllowWin | (!pWin ? NC_AllowAgg : 0));
109344 if( pWin && pParse->nErr==0 ){
109347 if( IN_RENAME_OBJECT==0 ){
109348 sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
109361 pExpr->op2 = 0;
109369 && sqlite3ReferencesSrcList(pParse, pExpr, pNC2->pSrcList)==0
109374 assert( pDef!=0 || IN_RENAME_OBJECT );
109379 testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 );
109380 testcase( (pDef->funcFlags & SQLITE_FUNC_ANYORDER)!=0 );
109455 assert( pExpr->pLeft!=0 );
109459 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
109464 assert( pExpr->pRight!=0 );
109483 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
109495 ** return 0.
109512 for(i=0; i<pEList->nExpr; i++){
109514 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
109520 return 0;
109539 ** If there is no match, return 0. Return -1 if an error occurs.
109553 assert( sqlite3ExprIsInteger(pE, &i, 0)==0 );
109558 memset(&nc, 0, sizeof(nc));
109563 nc.nNcErr = 0;
109569 if( rc ) return 0;
109575 for(i=0; i<pEList->nExpr; i++){
109576 if( sqlite3ExprCompare(0, pEList->a[i].pExpr, pE, -1)<2 ){
109581 /* If no match, return 0. */
109582 return 0;
109627 if( pOrderBy==0 ) return 0;
109633 for(i=0; i<pOrderBy->nExpr; i++){
109634 pOrderBy->a[i].fg.done = 0;
109636 pSelect->pNext = 0;
109643 moreToDo = 0;
109645 assert( pEList!=0 );
109646 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
109651 if( NEVER(pE==0) ) continue;
109652 if( sqlite3ExprIsInteger(pE, &iCol, 0) ){
109653 if( iCol<=0 || iCol>pEList->nExpr ){
109659 if( iCol==0 ){
109671 pDup = sqlite3ExprDup(db, pE, 0);
109675 if( IN_RENAME_OBJECT && iCol>0 ){
109682 if( iCol>0 ){
109686 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
109687 if( pNew==0 ) return 1;
109709 for(i=0; i<pOrderBy->nExpr; i++){
109710 if( pOrderBy->a[i].fg.done==0 ){
109716 return 0;
109740 if( pOrderBy==0 || pParse->db->mallocFailed || IN_RENAME_OBJECT ) return 0;
109746 assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
109747 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
109750 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr, 0);
109753 resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,0);
109756 return 0;
109779 memset(&sWalker, 0, sizeof(Walker));
109819 assert( pOrderBy!=0 );
109822 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
109825 if( NEVER(pE2==0) ) continue;
109826 if( zType[0]!='G' ){
109828 if( iCol>0 ){
109837 if( sqlite3ExprIsInteger(pE2, &iCol, 0) ){
109841 if( iCol<1 || iCol>0xffff ){
109850 pItem->u.x.iOrderByCol = 0;
109854 for(j=0; j<pSelect->pEList->nExpr; j++){
109855 if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
109882 assert( p!=0 );
109898 if( (p->selFlags & SF_Expanded)==0 ){
109903 isCompound = p->pPrior!=0;
109904 nCompound = 0;
109907 assert( (p->selFlags & SF_Expanded)!=0 );
109908 assert( (p->selFlags & SF_Resolved)==0 );
109914 memset(&sNC, 0, sizeof(sNC));
109929 assert( p->pSrc->a[0].fg.isSubquery );
109930 assert( p->pSrc->a[0].u4.pSubq!=0 );
109931 pSub = p->pSrc->a[0].u4.pSubq->pSelect;
109932 assert( pSub!=0 );
109934 assert( pSub->pPrior && pSub->pOrderBy==0 );
109936 p->pOrderBy = 0;
109942 for(i=0; i<p->pSrc->nSrc; i++){
109944 assert( pItem->zName!=0
109947 && (pItem->u4.pSubq->pSelect->selFlags & SF_Resolved)==0
109949 int nRef = pOuterNC ? pOuterNC->nRef : 0;
109956 assert( db->mallocFailed==0 );
109965 assert( pItem->fg.isCorrelated==0 && pOuterNC->nRef>=nRef );
109970 if( pOuterNC && ALWAYS(pOuterNC->nNestedSelect>0) ){
109988 assert( (p->selFlags & SF_Aggregate)==0 );
109990 if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
110006 assert( (sNC.ncFlags & (NC_UAggInfo|NC_UUpsert|NC_UBaseReg))==0 );
110010 if( (p->selFlags & SF_Aggregate)==0 ){
110021 for(i=0; i<p->pSrc->nSrc; i++){
110046 sNC.pNext = 0;
110056 assert( p->pSrc->a[0].fg.isSubquery );
110057 pSub = p->pSrc->a[0].u4.pSubq->pSelect;
110058 assert( pSub!=0 );
110060 pSub->pOrderBy = 0;
110073 if( p->pOrderBy!=0
110093 for(i=0, pItem=pGroupBy->a; i<pGroupBy->nExpr; i++, pItem++){
110180 if( pExpr==0 ) return SQLITE_OK;
110185 w.xSelectCallback = (pNC->ncFlags & NC_NoSelect) ? 0 : resolveSelectStep;
110186 w.xSelectCallback2 = 0;
110188 #if SQLITE_MAX_EXPR_DEPTH>0
110194 assert( pExpr!=0 );
110196 #if SQLITE_MAX_EXPR_DEPTH>0
110205 return pNC->nNcErr>0 || w.pParse->nErr>0;
110213 ** The return value is SQLITE_OK (0) for success or SQLITE_ERROR (1) for a
110221 int savedHasAgg = 0;
110223 if( pList==0 ) return SQLITE_OK;
110227 w.xSelectCallback2 = 0;
110231 for(i=0; i<pList->nExpr; i++){
110233 if( pExpr==0 ) continue;
110234 #if SQLITE_MAX_EXPR_DEPTH>0
110241 #if SQLITE_MAX_EXPR_DEPTH>0
110254 if( w.pParse->nErr>0 ) return SQLITE_ERROR;
110279 assert( p!=0 );
110282 w.xSelectCallback2 = 0;
110297 ** (4) Expression arguments to VACUUM INTO. 0
110309 int type, /* NC_IsCheck, NC_PartIdx, NC_IdxExpr, NC_GenCol, or 0 */
110318 assert( type==0 || pTab!=0 );
110320 || type==NC_GenCol || pTab==0 );
110321 memset(&sNC, 0, sizeof(sNC));
110323 memset(pSrc, 0, SZ_SRCLIST_1);
110326 pSrc->a[0].zName = pTab->zName;
110327 pSrc->a[0].pSTab = pTab;
110328 pSrc->a[0].iCursor = -1;
110369 if( iCol<0 || NEVER(iCol>=pTab->nCol) ) return SQLITE_AFF_INTEGER;
110378 ** affinity of that column is returned. Otherwise, 0x00 is returned,
110393 if( op==TK_COLUMN || (op==TK_AGG_COLUMN && pExpr->y.pTab!=0) ){
110395 assert( pExpr->y.pTab!=0 );
110400 assert( pExpr->x.pSelect!=0 );
110401 assert( pExpr->x.pSelect->pEList!=0 );
110402 assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
110403 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
110408 return sqlite3AffinityType(pExpr->u.zToken, 0);
110412 assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
110414 assert( pExpr->iColumn >= 0 );
110424 return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
110445 ** 0x01 Numeric
110446 ** 0x02 Text
110447 ** 0x04 Blob
110449 ** If the expression must return NULL, then 0x00 is returned.
110461 pExpr = 0;
110465 return 0x02;
110468 return 0x04;
110471 return 0x06;
110476 return 0x07;
110485 if( aff>=SQLITE_AFF_NUMERIC ) return 0x05;
110486 if( aff==SQLITE_AFF_TEXT ) return 0x06;
110487 return 0x07;
110490 int res = 0;
110493 assert( ExprUseXList(pExpr) && pList!=0 );
110494 assert( pList->nExpr > 0);
110504 return 0x01;
110508 return 0x00;
110525 if( pCollName->n>0 ){
110541 assert( zC!=0 );
110543 return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0);
110566 assert( pExpr->x.pList->nExpr>0 );
110568 pExpr = pExpr->x.pList->a[0].pExpr;
110594 CollSeq *pColl = 0;
110599 if( (op==TK_AGG_COLUMN && p->y.pTab!=0)
110604 assert( p->y.pTab!=0 );
110605 if( (j = p->iColumn)>=0 ){
110607 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
110619 p = p->x.pList->a[0].pExpr;
110624 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
110628 if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){
110633 assert( !ExprUseXList(p) || p->x.pList==0 || p->pRight==0 );
110634 if( ExprUseXList(p) && p->x.pList!=0 && !db->mallocFailed ){
110636 for(i=0; i<p->x.pList->nExpr; i++){
110650 pColl = 0;
110667 if( p==0 ) p = pParse->db->pDfltColl;
110668 assert( p!=0 );
110678 return sqlite3StrICmp(pColl1->zName, pColl2->zName)==0;
110718 aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
110719 }else if( aff==0 ){
110777 }else if( pRight && (pRight->flags & EP_Collate)!=0 ){
110821 if( pParse->nErr ) return 0;
110869 ** column of the vector (numbered starting with 0). The caller must
110885 assert( pVector->op2==0 || pVector->op==TK_REGISTER );
110902 ** It is ok for pVector to be a scalar (as long as iField==0).
110932 ** iTable: 0 or the number of columns on the LHS of an assignment
110933 ** pLeft->iTable: First in an array of register holding result, or 0
110943 pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0);
110958 *ppVector = 0;
110962 pRet = sqlite3ExprDup(pParse->db, pVector, 0);
110973 ** If pExpr is not a TK_SELECT expression, return 0.
110976 int reg = 0;
111027 return 0;
111032 ** the result of the comparison (1, 0, or NULL) and write that
111039 ** otherwise: op==pExpr->op and p5==0
111053 int regLeft = 0;
111054 int regRight = 0;
111056 int addrCmp = 0;
111073 assert( p5==0 || pExpr->op!=op );
111084 for(i=0; 1 /*Loop exits by "break"*/; i++){
111085 int regFree1 = 0, regFree2 = 0;
111086 Expr *pL = 0, *pR = 0;
111088 assert( i>=0 && i<nLeft );
111108 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest);
111119 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
111130 #if SQLITE_MAX_EXPR_DEPTH>0
111167 for(i=0; i<p->nExpr; i++){
111195 int nHeight = p->pLeft ? p->pLeft->nHeight : 0;
111227 int nHeight = 0;
111243 #endif /* SQLITE_MAX_EXPR_DEPTH>0 */
111249 if( pExpr==0 ) return;
111282 int nExtra = 0;
111283 int iValue = 0;
111285 assert( db!=0 );
111287 if( op!=TK_INTEGER || pToken->z==0
111288 || sqlite3GetInt32(pToken->z, &iValue)==0 ){
111290 assert( iValue>=0 );
111295 memset(pNew, 0, sizeof(Expr));
111299 if( nExtra==0 ){
111304 assert( pToken->z!=0 || pToken->n==0 );
111306 pNew->u.zToken[pToken->n] = 0;
111307 if( dequote && sqlite3Isquote(pNew->u.zToken[0]) ){
111312 #if SQLITE_MAX_EXPR_DEPTH>0
111331 return sqlite3ExprAlloc(db, op, &x, 0);
111346 if( pRoot==0 ){
111352 assert( pRoot->x.pSelect==0 );
111356 #if SQLITE_MAX_EXPR_DEPTH>0
111365 #if SQLITE_MAX_EXPR_DEPTH>0
111390 memset(p, 0, sizeof(Expr));
111391 p->op = op & 0xff;
111438 Select *pRet = 0;
111440 for(ii=0; ii<pEList->nExpr; ii++){
111457 pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0);
111458 pExpr->x.pList = 0;
111485 if( pLeft==0 ){
111487 }else if( pRight==0 ){
111496 return sqlite3Expr(db, TK_INTEGER, "0");
111511 int eDistinct /* SF_Distinct or SF_ALL or 0 */
111517 if( pNew==0 ){
111519 return 0;
111564 if( NEVER(pOrderBy==0) ){
111568 if( pExpr==0 ){
111574 assert( pExpr->pLeft==0 );
111576 if( pExpr->x.pList==0 || NEVER(pExpr->x.pList->nExpr==0) ){
111587 pOB = sqlite3ExprAlloc(db, TK_ORDER, 0, 0);
111588 if( pOB==0 ){
111615 assert( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 );
111617 if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0
111618 || (pParse->db->flags & SQLITE_TrustedSchema)==0
111653 if( pExpr==0 ) return;
111656 assert( z!=0 );
111657 assert( z[0]!=0 );
111659 if( z[1]==0 ){
111661 assert( z[0]=='?' );
111664 int doAdd = 0;
111665 if( z[0]=='?' ){
111671 i = z[1]-'0'; /* The common case of ?N for a single digit N */
111674 bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
111676 testcase( i==0 );
111680 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
111690 }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
111699 if( x==0 ){
111719 assert( p!=0 );
111720 assert( db!=0 );
111722 assert( !ExprUseUValue(p) || p->u.iValue>=0 );
111724 assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed );
111728 assert( p->pLeft==0 );
111729 assert( p->pRight==0 );
111730 assert( !ExprUseXSelect(p) || p->x.pSelect==0 );
111731 assert( !ExprUseXList(p) || p->x.pList==0 );
111736 assert( (ExprUseXList(p) && p->x.pList==0) || p->pRight==0 );
111780 if( p==0 ){
111796 ** Return 0 if the delete was successfully deferred. Return non-zero
111800 return 0==sqlite3ParserAddCleanup(pParse, sqlite3ExprDeleteGeneric, pExpr);
111847 ** of this routine with 0xfff. The flags can be found by masking the
111862 assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
111863 assert( EXPR_FULLSIZE<=0xfff );
111864 assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
111865 if( 0==flags || ExprHasProperty(p, EP_FullSize) ){
111874 assert( p->pRight==0 );
111887 int nByte = dupedExprStructSize(p, flags) & 0xfff;
111907 assert( p!=0 );
111940 int dupFlags, /* EXPRDUP_REDUCE for compression. 0 if not */
111948 assert( db!=0 );
111950 assert( dupFlags==0 || dupFlags==EXPRDUP_REDUCE );
111951 assert( pEdupBuf==0 || dupFlags==EXPRDUP_REDUCE );
111960 assert( sEdupBuf.zAlloc!=0 );
111970 nToken = 0;
111976 sEdupBuf.zEnd = sEdupBuf.zAlloc ? sEdupBuf.zAlloc+nAlloc : 0;
111979 staticFlag = 0;
111991 int nNewSize = nStructSize & 0xfff;
111992 if( nToken<0 ){
111996 nToken = 0;
112001 assert( ExprHasProperty(p, EP_Reduced)==0 );
112009 memset(&sEdupBuf.zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
112024 assert( nToken>=0 );
112025 if( nToken>0 ){
112032 if( ((p->flags|pNew->flags)&(EP_TokenOnly|EP_Leaf))==0 ){
112039 p->op!=TK_ORDER ? dupFlags : 0);
112053 assert( p->pRight==0
112058 exprDup(db, p->pLeft, EXPRDUP_REDUCE, &sEdupBuf) : 0;
112061 exprDup(db, p->pRight, EXPRDUP_REDUCE, &sEdupBuf) : 0;
112065 assert( p->pRight==0
112069 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
112071 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
112087 With *pRet = 0;
112094 for(i=0; i<p->nCte; i++){
112095 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
112096 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
112105 # define sqlite3WithDup(x,y) 0
112121 assert( pWin->ppThis==0 );
112133 w.xSelectCallback2 = 0;
112134 w.pParse = 0;
112159 assert( flags==0 || flags==EXPRDUP_REDUCE );
112160 return p ? exprDup(db, p, flags, 0) : 0;
112167 Expr *pPriorSelectColOld = 0;
112168 Expr *pPriorSelectColNew = 0;
112169 assert( db!=0 );
112170 if( p==0 ) return 0;
112172 if( pNew==0 ) return 0;
112177 for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
112183 && (pNewExpr = pItem->pExpr)!=0
112216 assert( db!=0 );
112217 if( p==0 ) return 0;
112219 if( pNew==0 ) return 0;
112221 for(i=0; i<p->nSrc; i++){
112228 if( pNewSubq==0 ){
112230 pNewItem->fg.isSubquery = 0;
112234 if( pNewSubq->pSelect==0 ){
112236 pNewSubq = 0;
112237 pNewItem->fg.isSubquery = 0;
112278 assert( db!=0 );
112279 if( p==0 ) return 0;
112281 if( pNew==0 ) return 0;
112283 for(i=0; i<p->nId; i++){
112291 Select *pRet = 0;
112292 Select *pNext = 0;
112296 assert( db!=0 );
112299 if( pNew==0 ) break;
112308 pNew->pPrior = 0;
112310 pNew->iLimit = 0;
112311 pNew->iOffset = 0;
112313 pNew->addrOpenEphm[0] = -1;
112318 pNew->pWin = 0;
112320 if( p->pWin && db->mallocFailed==0 ) gatherSelectWindows(pNew);
112327 pNew->pNext = 0;
112339 assert( p==0 );
112340 return 0;
112356 static const struct ExprList_item zeroItem = {0};
112365 if( pList==0 ){
112367 return 0;
112371 pItem = &pList->a[0];
112385 if( pNew==0 ){
112388 return 0;
112403 if( pList==0 ){
112435 int iFirst = pList ? pList->nExpr : 0;
112438 if( NEVER(pColumns==0) ) goto vector_append_error;
112439 if( pExpr==0 ) goto vector_append_error;
112452 for(i=0; i<pColumns->nId; i++){
112454 assert( pSubExpr!=0 || db->mallocFailed );
112455 if( pSubExpr==0 ) continue;
112460 pColumns->a[i].zName = 0;
112464 if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){
112466 assert( pFirst!=0 );
112472 pExpr = 0;
112490 if( p==0 ) return;
112491 assert( p->nExpr>0 );
112493 assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC==0 && SQLITE_SO_DESC>0 );
112504 assert( pItem->fg.bNulls==0 );
112532 assert( pList!=0 || pParse->db->mallocFailed!=0 );
112533 assert( pParse->eParseMode!=PARSE_MODE_UNMAP || dequote==0 );
112536 assert( pList->nExpr>0 );
112538 assert( pItem->zEName==0 );
112542 /* If dequote==0, then pName->z does not point to part of a DDL
112568 assert( pList!=0 || db->mallocFailed!=0 );
112571 assert( pList->nExpr>0 );
112572 if( pItem->zEName==0 ){
112602 assert( pList->nExpr>0 );
112603 assert( db!=0 );
112608 }while( --i>0 );
112624 u32 m = 0;
112625 assert( pList!=0 );
112626 for(i=0; i<pList->nExpr; i++){
112628 assert( pExpr!=0 );
112643 pWalker->eCode = 0;
112653 ** anything else 0
112656 if( sqlite3StrICmp(zIn, "true")==0 ) return EP_IsTrue;
112657 if( sqlite3StrICmp(zIn, "false")==0 ) return EP_IsFalse;
112658 return 0;
112671 && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0
112677 return 0;
112682 ** and 0 if it is FALSE.
112688 assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
112689 || sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
112690 return pExpr->u.zToken[4]==0;
112707 assert( pExpr!=0 );
112730 ** This routine sets pWalker->eCode to 0 if pExpr is not a constant.
112747 || (pList = pExpr->x.pList)==0
112749 n = 0;
112753 if( pWalker->eCode==0 ) return WRC_Abort;
112756 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
112757 if( pDef==0
112758 || pDef->xFinalize!=0
112759 || (pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
112762 pWalker->eCode = 0;
112782 ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
112796 assert( pWalker->eCode>0 );
112802 pWalker->eCode = 0;
112819 pWalker->eCode = 0;
112851 pWalker->eCode = 0;
112862 pWalker->eCode = 0;
112887 ** and 0 if it involves variables or function calls.
112927 assert( pSelect!=0 );
112928 assert( pWalker->eCode==3 || pWalker->eCode==0 );
112929 if( (pSelect->selFlags & SF_Correlated)!=0 ){
112930 pWalker->eCode = 0;
112948 w.pParse = 0;
112972 ** doubt, return 0.
113015 return 0; /* rule (3) */
113018 if( !ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (4a) */
113019 if( pExpr->w.iJoin!=pSrc->iCursor ) return 0; /* rule (4b) */
113021 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (5) */
113024 && (pSrcList->a[0].fg.jointype & JT_LTORJ)!=0 /* Fast pre-test of (6b) */
113027 for(jj=0; jj<iSrc; jj++){
113029 if( (pSrcList->a[jj].fg.jointype & JT_LTORJ)!=0 ){
113030 return 0; /* restriction (6) */
113050 for(i=0; i<pGroupBy->nExpr; i++){
113052 if( sqlite3ExprCompare(0, pExpr, p, -1)<2 ){
113062 pWalker->eCode = 0;
113092 w.xSelectCallback = 0;
113104 ** Return and 0 if there are any variables.
113121 assert( isInit==0 || isInit==1 );
113122 return exprIsConst(0, p, 4+isInit);
113128 ** subquery of some kind. Return 0 if there are no subqueries.
113139 return w.eCode==0;
113147 ** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged.
113154 int rc = 0;
113155 if( NEVER(p==0) ) return 0; /* Used to only happen following on OOM */
113159 assert( p->op!=TK_INTEGER || (p->flags & EP_IntValue)!=0
113160 || sqlite3GetInt32(p->u.zToken, &rc)==0 );
113168 rc = sqlite3ExprIsInteger(p->pLeft, pValue, 0);
113172 int v = 0;
113173 if( sqlite3ExprIsInteger(p->pLeft, &v, 0) ){
113174 assert( ((unsigned int)v)!=0x80000000 );
113182 if( pParse==0 ) break;
113183 if( NEVER(pParse->pVdbe==0) ) break;
113184 if( (pParse->db->flags & SQLITE_EnableQPSG)!=0 ) break;
113191 if( vv == (vv & 0x7fffffff) ){ /* non-negative numbers only */
113221 assert( p!=0 );
113224 assert( p!=0 );
113233 return 0;
113237 || NEVER(p->y.pTab==0) /* Reference to column of index on expr */
113241 || (p->iColumn>=0
113242 && p->y.pTab->aCol!=0 /* Possible due to prior error */
113244 && p->y.pTab->aCol[p->iColumn].notNull==0);
113262 int unaryMinus = 0;
113284 assert( p->iTable>=0 ); /* p cannot be part of a CHECK constraint */
113285 return aff>=SQLITE_AFF_NUMERIC && p->iColumn<0;
113288 return 0;
113297 if( sqlite3StrICmp(z, "_ROWID_")==0 ) return 1;
113298 if( sqlite3StrICmp(z, "ROWID")==0 ) return 1;
113299 if( sqlite3StrICmp(z, "OID")==0 ) return 1;
113300 return 0;
113312 for(ii=0; ii<ArraySize(azOpt); ii++){
113313 if( sqlite3ColumnIndex(pTab, azOpt[ii])<0 ) return azOpt[ii];
113315 return 0;
113332 if( !ExprUseXSelect(pX) ) return 0; /* Not a subquery */
113333 if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */
113335 if( p->pPrior ) return 0; /* Not a compound SELECT */
113339 return 0; /* No DISTINCT keyword and no aggregate functions */
113341 assert( p->pGroupBy==0 ); /* Has no GROUP BY clause */
113342 if( p->pLimit ) return 0; /* Has no LIMIT clause */
113343 if( p->pWhere ) return 0; /* Has no WHERE clause */
113345 assert( pSrc!=0 );
113346 if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
113347 if( pSrc->a[0].fg.isSubquery) return 0;/* FROM is not a subquery or view */
113348 pTab = pSrc->a[0].pSTab;
113349 assert( pTab!=0 );
113351 if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
113353 assert( pEList!=0 );
113355 for(i=0; i<pEList->nExpr; i++){
113357 if( pRes->op!=TK_COLUMN ) return 0;
113358 assert( pRes->iTable==pSrc->a[0].iCursor ); /* Not a correlated subquery */
113373 sqlite3VdbeAddOp2(v, OP_Integer, 0, regHasNull);
113375 sqlite3VdbeAddOp3(v, OP_Column, iCur, 0, regHasNull);
113393 pIn->pLeft = 0;
113481 ** then aiMap[] is populated with {2, 0, 1}.
113493 int eType = 0; /* Type of RHS table. IN_INDEX_* */
113499 mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
113506 ** set prRhsHasNull to 0 before continuing. */
113510 for(i=0; i<pEList->nExpr; i++){
113514 prRhsHasNull = 0;
113521 if( pParse->nErr==0 && (p = isCandidateForInOpt(pX))!=0 ){
113528 assert( p->pEList!=0 ); /* Because of isCandidateForInOpt(p) */
113529 assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */
113530 assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
113531 pTab = p->pSrc->a[0].pSTab;
113535 assert( iDb>=0 && iDb<SQLITE_MAX_DB );
113537 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
113540 if( nExpr==1 && pEList->a[0].pExpr->iColumn<0 ){
113547 ExplainQueryPlan((pParse, 0,
113559 for(i=0; i<nExpr && affinity_ok; i++){
113583 for(pIdx=pTab->pIndex; pIdx && eType==0; pIdx=pIdx->pNext){
113587 if( pIdx->pPartIdxWhere!=0 ) continue;
113601 colUsed = 0; /* Columns of index used so far */
113602 for(i=0; i<nExpr; i++){
113608 for(j=0; j<nExpr; j++){
113611 if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){
113623 assert( nExpr>0 && nExpr<BMS );
113628 ExplainQueryPlan((pParse, 0,
113634 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
113640 iTab, 0, 0, (u8*)&mask, P4_INT64);
113661 if( eType==0
113671 if( eType==0 ){
113676 int rMayHaveNull = 0;
113679 pParse->nQueryLoop = 0;
113694 for(i=0; i<n; i++) aiMap[i] = i;
113713 Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0;
113720 for(i=0; i<nVal; i++){
113729 zRet[nVal] = '\0';
113743 if( pParse->nErr==0 ){
113787 if( pNewSig==0 ) return 0;
113788 if( (pParse->mSubrtnSig & (1<<(pNewSig->selId&7)))==0 ) return 0;
113792 assert( pExpr->x.pSelect!=0 );
113793 assert( (pExpr->x.pSelect->selFlags & SF_All)==0 );
113795 assert( v!=0 );
113802 assert( pSig!=0 );
113805 if( strcmp(pNewSig->zAff,pSig->zAff)!=0 ) continue;
113812 return 0;
113844 int addrOnce = 0; /* Address of the OP_Once instruction at top */
113847 KeyInfo *pKeyInfo = 0; /* Key information */
113850 SubrtnSig *pSig = 0; /* Signature for this subroutine */
113853 assert( v!=0 );
113865 if( !ExprHasProperty(pExpr, EP_VarSelect) && pParse->iSelfTab==0 ){
113871 assert( !ExprUseXSelect(pExpr) || pExpr->x.pSelect!=0 );
113872 if( ExprUseXSelect(pExpr) && (pExpr->x.pSelect->selFlags & SF_All)==0 ){
113873 pSig = sqlite3DbMallocRawNN(pParse->db, sizeof(pSig[0]));
113889 ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d",
113911 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1;
113913 pSig->bComplete = 0;
113960 int addrBloom = 0;
113963 pSelect->iLimit = 0;
113971 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
113972 pCopy = sqlite3SelectDup(pParse->db, pSelect, 0);
113980 if( dest.iSDParm2==0 ){
113989 assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
113990 assert( pEList!=0 );
113991 assert( pEList->nExpr>0 );
113993 for(i=0; i<nVal; i++){
114000 }else if( ALWAYS(pExpr->x.pList!=0) ){
114021 pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
114027 for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
114039 addrOnce = 0;
114081 ** Return 0 if an error occurs.
114085 int addrOnce = 0; /* Address of OP_Once at top of subroutine */
114086 int rReg = 0; /* Register storing resulting */
114096 assert( v!=0 );
114097 if( pParse->nErr ) return 0;
114107 ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
114120 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1;
114140 ** If this is an EXISTS, write an integer 0 (not exists) or 1 (exists)
114150 sqlite3SelectDestInit(&dest, 0, pParse->nMem+1);
114156 sqlite3VdbeAddOp3(v, OP_Null, 0, dest.iSDParm, dest.iSDParm+nReg-1);
114160 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
114165 ** then make the new limit X<>0 so that the new limit is either 1 or 0 */
114167 pLimit = sqlite3Expr(db, TK_INTEGER, "0");
114171 sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit);
114178 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
114180 pSel->iLimit = 0;
114184 return 0;
114223 return 0;
114259 int rRhsHasNull = 0; /* Register that is true if RHS contains NULL values */
114264 int *aiMap = 0; /* Map from vector field to index column */
114265 char *zAff = 0; /* Affinity string for comparisons */
114271 int destStep6 = 0; /* Start of code for Step 6 */
114275 int iTab = 0; /* Index to use */
114291 assert( v!=0 ); /* OOM detected prior to this routine */
114295 destIfFalse==destIfNull ? 0 : &rRhsHasNull,
114302 /* Confirm that aiMap[] contains nVector integer values between 0 and
114304 for(i=0; i<nVector; i++){
114306 for(cnt=j=0; j<nVector; j++) if( aiMap[j]==i ) cnt++;
114324 pParse->okConstFactor = 0;
114327 for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */
114334 for(i=0; i<nVector; i++){
114335 sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0);
114350 int regCkNull = 0;
114359 for(ii=0; ii<pList->nExpr; ii++){
114373 sqlite3VdbeChangeP5(v, zAff[0]);
114381 sqlite3VdbeChangeP5(v, zAff[0] | SQLITE_JUMPIFNULL);
114402 for(i=0; i<nVector; i++){
114423 sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
114429 if( pOp->opcode==OP_Once && pOp->p3>0 ){ /* tag-202407032019 */
114440 addrTruthOp = sqlite3VdbeAddOp4Int(v, OP_Found, iTab, 0,
114474 for(i=0; i<nVector; i++){
114486 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
114494 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
114512 ** value described by z[0..n-1] into register iMem.
114519 if( ALWAYS(z!=0) ){
114524 sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
114532 ** text z[0..n-1] into register iMem.
114540 assert( i>=0 );
114547 assert( z!=0 );
114554 if( sqlite3_strnicmp(z,"0x",2)==0 ){
114565 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64);
114587 pParse->iSelfTab = 0;
114608 assert( v!=0 );
114609 assert( pParse->iSelfTab!=0 );
114610 if( pParse->iSelfTab>0 ){
114611 iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
114613 iAddr = 0;
114617 sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
114635 assert( v!=0 );
114636 assert( pTab!=0 );
114638 if( iCol<0 || iCol==pTab->iPKey ){
114682 ** is called. If iColumn<0 then code is generated that extracts the rowid.
114692 assert( pParse->pVdbe!=0 );
114694 assert( IsVirtual(pTab) || (p5 & OPFLAG_NOCHNG)==0 );
114719 if( NEVER(p==0) ) return;
114738 ** to 0.
114746 *piFreeable = 0;
114749 iResult = 0;
114758 for(i=0; i<nResult; i++){
114788 assert( v!=0 );
114789 assert( pFarg!=0 );
114791 assert( nFarg>0 ); /* All in-line functions have at least one argument */
114801 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
114813 memset(&caseExpr, 0, sizeof(caseExpr));
114820 Expr *pArg = pFarg->a[0].pExpr;
114821 if( pArg->op==TK_COLUMN && pArg->iTable>=0 ){
114824 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
114834 target = sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target);
114847 sqlite3ExprCompare(0,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
114856 sqlite3ExprImpliesExpr(pParse,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
114868 sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable,1),
114871 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
114885 aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
114923 n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0;
114924 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
114925 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
114942 memset(&w, 0, sizeof(w));
114966 if( iDataCur<0 ) continue;
114971 if( sqlite3ExprCompare(0, pExpr, p->pExpr, iDataCur)!=0 ) continue;
114994 assert( v!=0 );
115004 sqlite3VdbeGoto(v, 0);
115006 pParse->pIdxEpr = 0;
115035 int addr = 0;
115042 sqlite3VdbeAddOp4(pParse->pVdbe, OP_Affinity, ret, 1, 0,
115051 return 0;
115070 int regFree1 = 0; /* If non-zero free this temporary register */
115071 int regFree2 = 0; /* If non-zero free this temporary register */
115074 int p5 = 0;
115076 assert( target>0 && target<=pParse->nMem );
115077 assert( v!=0 );
115080 if( pExpr==0 ){
115082 }else if( pParse->pIdxEpr!=0
115084 && (r1 = sqlite3IndexedExprLookup(pParse, pExpr, target))>=0
115096 assert( pAggInfo!=0 );
115097 assert( pExpr->iAgg>=0 );
115101 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
115117 if( pTab==0 ){
115119 }else if( pCol->iColumn<0 ){
115129 }else if( pExpr->y.pTab==0 ){
115151 assert( pExpr->y.pTab!=0 );
115157 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0,
115162 if( iTab<0 ){
115163 if( pParse->iSelfTab<0 ){
115167 ** 0-(pParse->iSelfTab). The rowid (if any) is in a register
115176 assert( pTab!=0 );
115179 if( iCol<0 ){
115190 return 0;
115214 && 0!=(r1 = exprPartidxExprLookup(pParse, pExpr, target))
115219 assert( pExpr->y.pTab!=0 );
115226 codeInteger(pParse, pExpr, 0, target);
115236 codeReal(v, pExpr->u.zToken, 0, target);
115251 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
115260 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
115266 sqlite3VdbeAddOp4(v, OP_Blob, n/2, target, 0, zBlob, P4_DYNAMIC);
115272 assert( pExpr->u.zToken!=0 );
115273 assert( pExpr->u.zToken[0]!=0 );
115287 sqlite3AffinityType(pExpr->u.zToken, 0));
115319 sqlite3VdbeAddOp2(v, OP_Integer, 0, inReg);
115323 testcase( regFree1==0 );
115324 testcase( regFree2==0 );
115354 testcase( regFree1==0 );
115355 testcase( regFree2==0 );
115373 tempX.u.iValue = 0;
115378 testcase( regFree2==0 );
115387 testcase( regFree1==0 );
115395 testcase( regFree1==0 );
115410 testcase( regFree1==0 );
115414 sqlite3VdbeAddOp2(v, OP_Integer, 0, target);
115420 if( pInfo==0
115421 || NEVER(pExpr->iAgg<0)
115436 u32 constMask = 0; /* Mask of function arguments that are constant */
115440 CollSeq *pColl = 0; /* A collating sequence */
115458 nFarg = pFarg ? pFarg->nExpr : 0;
115461 pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0);
115463 if( pDef==0 && pParse->explain ){
115464 pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0);
115467 if( pDef==0 || pDef->xFinalize!=0 ){
115471 if( (pDef->funcFlags & SQLITE_FUNC_INLINE)!=0 && ALWAYS(pFarg!=0) ){
115472 assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 );
115473 assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 );
115480 for(i=0; i<nFarg; i++){
115485 if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
115502 if( (pDef->funcFlags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
115505 assert( pFarg->a[0].pExpr!=0 );
115506 exprOp = pFarg->a[0].pExpr->op;
115515 pFarg->a[0].pExpr->op2 = pDef->funcFlags & OPFLAG_BYTELENARG;
115519 sqlite3ExprCodeExprList(pParse, pFarg, r1, 0, SQLITE_ECEL_FACTOR);
115521 r1 = 0;
115538 }else if( nFarg>0 ){
115539 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
115544 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
115549 if( constMask==0 ){
115564 return 0;
115578 if( pLeft->iTable==0 || pParse->withinRJSubrtn > pLeft->op2 ){
115593 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
115597 sqlite3VdbeAddOp2(v, OP_AddImm, target, 0);
115612 ** Y is stored in pExpr->pList->a[0].pExpr.
115616 exprCodeBetween(pParse, pExpr, target, 0, 0);
115646 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
115651 ** parameter is set to 0 for an old.rowid reference, or to (i+1)
115664 ** p1==0 -> old.rowid p1==3 -> new.rowid
115678 assert( pExpr->iTable==0 || pExpr->iTable==1 );
115680 assert( pTab->iPKey<0 || iCol!=pTab->iPKey );
115681 assert( p1>=0 && p1<(pTab->nCol*2+2) );
115686 (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[iCol].zCnName)
115695 if( iCol>=0 && pTab->aCol[iCol].affinity==SQLITE_AFF_REAL ){
115718 assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
115731 addrINR = sqlite3VdbeAddOp3(v, OP_IfNullRow, pExpr->iTable, 0, target);
115739 pParse->okConstFactor = 0; /* note (1) above */
115777 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
115778 Expr *pDel = 0;
115781 assert( ExprUseXList(pExpr) && pExpr->x.pList!=0 );
115782 assert(pExpr->x.pList->nExpr > 0);
115787 if( (pX = pExpr->pLeft)!=0 ){
115788 pDel = sqlite3ExprDup(db, pX, 0);
115795 testcase( regFree1==0 );
115796 memset(&opCompare, 0, sizeof(opCompare));
115804 regFree1 = 0;
115806 for(i=0; i<nExpr-1; i=i+2){
115808 assert( pTest!=0 );
115821 if( (nExpr&1)!=0 ){
115824 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
115841 return 0;
115874 ** If regDest>0 then the result is always stored in that register and the
115875 ** result is not reusable. If regDest<0 then this routine is free to
115877 ** is stored is returned. When regDest<0, two identical expressions might
115889 assert( regDest!=0 );
115891 if( regDest<0 && p ){
115894 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
115896 && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0
115902 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
115903 if( pExpr!=0 && ExprHasProperty(pExpr, EP_HasFunc) ){
115908 pParse->okConstFactor = 0;
115910 if( regDest<0 ) regDest = ++pParse->nMem;
115920 pItem->fg.reusable = regDest<0;
115921 if( regDest<0 ) regDest = ++pParse->nMem;
115946 && ALWAYS(pExpr!=0)
115950 *pReg = 0;
115959 *pReg = 0;
115973 assert( pExpr==0 || !ExprHasVVAProperty(pExpr,EP_Immutable) );
115974 assert( target>0 && target<=pParse->nMem );
115975 assert( pParse->pVdbe!=0 || pParse->db->mallocFailed );
115976 if( pParse->pVdbe==0 ) return;
116000 pExpr = sqlite3ExprDup(db, pExpr, 0);
116034 ** ExprList.a[].u.x.iOrderByCol>0 have already been evaluated and stored
116036 ** If SQLITE_ECEL_OMITREF is also set, then the values with u.x.iOrderByCol>0
116050 assert( pList!=0 );
116051 assert( target>0 );
116052 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
116055 for(pItem=pList->a, i=0; i<n; i++, pItem++){
116063 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
116070 }else if( (flags & SQLITE_ECEL_FACTOR)!=0
116082 && pOp->p5==0 /* The do-not-merge flag must be clear */
116124 int regFree1 = 0; /* Temporary use register */
116125 Expr *pDel = 0;
116128 memset(&compLeft, 0, sizeof(Expr));
116129 memset(&compRight, 0, sizeof(Expr));
116130 memset(&exprAnd, 0, sizeof(Expr));
116133 pDel = sqlite3ExprDup(db, pExpr->pLeft, 0);
116134 if( db->mallocFailed==0 ){
116140 compLeft.pRight = pExpr->x.pList->a[0].pExpr;
116161 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull==0 && regFree1==0 );
116162 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull==0 && regFree1!=0 );
116163 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull!=0 && regFree1==0 );
116164 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull!=0 && regFree1!=0 );
116165 testcase( xJump==sqlite3ExprIfFalse && jumpIfNull==0 && regFree1==0 );
116166 testcase( xJump==sqlite3ExprIfFalse && jumpIfNull==0 && regFree1!=0 );
116167 testcase( xJump==sqlite3ExprIfFalse && jumpIfNull!=0 && regFree1==0 );
116168 testcase( xJump==sqlite3ExprIfFalse && jumpIfNull!=0 && regFree1!=0 );
116169 testcase( xJump==0 );
116188 int op = 0;
116189 int regFree1 = 0;
116190 int regFree2 = 0;
116193 assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
116194 if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
116195 if( NEVER(pExpr==0) ) return; /* No way this can happen */
116206 testcase( jumpIfNull==0 );
116212 testcase( jumpIfNull==0 );
116219 testcase( jumpIfNull==0 );
116226 testcase( jumpIfNull==0 );
116233 isNot ? SQLITE_JUMPIFNULL : 0);
116236 isNot ? SQLITE_JUMPIFNULL : 0);
116254 testcase( jumpIfNull==0 );
116269 testcase( regFree1==0 );
116270 testcase( regFree2==0 );
116278 assert( regFree1==0 || regFree1==r1 );
116286 testcase( jumpIfNull==0 );
116308 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
116310 testcase( regFree1==0 );
116311 testcase( jumpIfNull==0 );
116327 ** is 0.
116331 int op = 0;
116332 int regFree1 = 0;
116333 int regFree2 = 0;
116336 assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
116337 if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
116338 if( pExpr==0 ) return;
116379 testcase( jumpIfNull==0 );
116384 testcase( jumpIfNull==0 );
116393 testcase( jumpIfNull==0 );
116400 testcase( jumpIfNull==0 );
116408 isNot ? 0 : SQLITE_JUMPIFNULL);
116413 isNot ? 0 : SQLITE_JUMPIFNULL);
116431 testcase( jumpIfNull==0 );
116446 testcase( regFree1==0 );
116447 testcase( regFree2==0 );
116453 assert( regFree1==0 || regFree1==r1 );
116461 testcase( jumpIfNull==0 );
116485 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
116487 testcase( regFree1==0 );
116488 testcase( jumpIfNull==0 );
116504 Expr *pCopy = sqlite3ExprDup(db, pExpr, 0);
116505 if( db->mallocFailed==0 ){
116534 sqlite3_value *pL, *pR = 0;
116537 return 0;
116539 if( (pParse->db->flags & SQLITE_EnableQPSG)!=0 ) return 2;
116549 res = sqlite3MemCompare(pL, pR, 0) ? 2 : 0;
116558 ** Do a deep comparison of two expression trees. Return 0 if the two
116567 ** not using TK_REGISTER but is otherwise equivalent, then still return 0.
116573 ** expressions are the same. But if you get a 0 or 1 return, then you
116577 ** an incorrect 0 or 1 could lead to a malfunction.
116591 if( pA==0 || pB==0 ){
116592 return pB==pA ? 0 : 2;
116599 if( (pA->flags&pB->flags&EP_IntValue)!=0 && pA->u.iValue==pB->u.iValue ){
116600 return 0;
116612 && pB->iTable<0 && pA->iTable==iTab
116623 if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
116630 if( sqlite3WindowCompare(pParse, pA->y.pWin, pB->y.pWin, 1)!=0 ){
116636 return 0;
116638 if( sqlite3_stricmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
116640 if( pB->u.zToken!=0
116643 && strcmp(pA->u.zToken,pB->u.zToken)!=0
116650 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
116652 if( (combinedFlags & EP_FixedCol)==0
116658 && ALWAYS((combinedFlags & EP_Reduced)==0)
116667 return 0;
116671 ** Compare two ExprList objects. Return 0 if they are identical, 1
116680 ** must never return 0 if the two ExprList objects are different, or
116688 if( pA==0 && pB==0 ) return 0;
116689 if( pA==0 || pB==0 ) return 1;
116691 for(i=0; i<pA->nExpr; i++){
116696 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
116698 return 0;
116706 return sqlite3ExprCompare(0,
116727 if( sqlite3ExprCompare(pParse, p, pNN, iTab)==0 ){
116732 if( seenNot && ExprHasProperty(p, EP_xIsSelect) ) return 0;
116733 assert( ExprUseXSelect(p) || (p->x.pList!=0 && p->x.pList->nExpr>0) );
116740 assert( pList!=0 );
116742 if( seenNot ) return 0;
116743 if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, 1)
116778 if( seenNot ) return 0;
116779 if( p->op2!=TK_IS ) return 0;
116787 return 0;
116797 if( pExpr->op==TK_TRUEFALSE && sqlite3ExprTruthValue(pExpr)==0 ) return 1;
116799 if( sqlite3ExprIsInteger(pExpr, &v, 0) && v==0 ) return 1;
116800 return 0;
116818 if( (z[0]!='i' && z[0]!='I') ) return 0;
116819 if( pExpr->x.pList==0 ) return 0;
116820 pDef = sqlite3FindFunction(db, z, pExpr->x.pList->nExpr, ENC(db), 0);
116822 if( pDef==0 ) return 0;
116824 if( NEVER(pDef==0) ) return 0;
116826 if( (pDef->funcFlags & SQLITE_FUNC_INLINE)==0 ) return 0;
116827 if( SQLITE_PTR_TO_INT(pDef->pUserData)!=INLINEFUNC_iif ) return 0;
116829 if( pExpr->pLeft!=0 ) return 0;
116831 return 0;
116834 assert( pList!=0 );
116837 return 0;
116846 ** pE1: x>0 pE2: x==5 Result: false
116853 ** PE1: iif(x,y,0) pE2: x Result: true
116856 ** Expr.iTable<0 then assume a table number given by iTab.
116873 if( sqlite3ExprCompare(pParse, pE1, pE2, iTab)==0 ){
116883 && exprImpliesNotNull(pParse, pE1, pE2->pLeft, iTab, 0)
116888 return sqlite3ExprImpliesExpr(pParse,pE1->x.pList->a[0].pExpr,pE2,iTab);
116890 return 0;
116898 if( pWalker->eCode==0 ){
116901 pWalker->eCode = 0;
116977 if( ExprUseXList(pExpr) && ALWAYS(pExpr->x.pList->nExpr>0) ){
116988 bothImplyNotNullRow(pWalker, pExpr->x.pList->a[0].pExpr,
117009 /* The y.pTab=0 assignment in wherecode.c always happens after the
117014 && ALWAYS(pLeft->y.pTab!=0)
117017 && ALWAYS(pRight->y.pTab!=0)
117054 if( p==0 ) return 0;
117064 w.xSelectCallback = 0;
117065 w.xSelectCallback2 = 0;
117066 w.eCode = 0;
117067 w.mWFlags = isRJ!=0;
117093 && sqlite3TableColumnToIndex(pWalker->u.pIdxCover->pIdx, pExpr->iColumn)<0
117118 memset(&w, 0, sizeof(w));
117151 if( pSrc->nSrc==0 ) return WRC_Continue;
117155 if( piNew==0 ){
117156 p->nExclude = 0;
117161 for(i=0; i<pSrc->nSrc; i++, j++){
117177 ** Set the 0x01 bit of pWalker->eCode if there is a reference to any
117180 ** Set the 0x02 bit of pWalker->eCode if there is a reference to a
117190 int nSrc = pSrc ? pSrc->nSrc : 0;
117191 for(i=0; i<nSrc; i++){
117197 for(i=0; i<p->nExclude && p->aiExclude[i]!=pExpr->iTable; i++){}
117211 ** 0 pExpr references some table that is not defined in either
117223 assert( pParse->db!=0 );
117224 memset(&w, 0, sizeof(w));
117225 memset(&x, 0, sizeof(x));
117238 assert( pExpr->pLeft->x.pList!=0 );
117247 if( w.eCode & 0x01 ){
117250 return 0;
117269 && pExpr->pAggInfo!=0
117275 assert( iAgg>=0 );
117280 pExpr = sqlite3ExprDup(db, pExpr, 0);
117290 pExpr = sqlite3ExprDup(db, pExpr, 0);
117305 memset(pWalker, 0, sizeof(*pWalker));
117320 sizeof(pInfo->aCol[0]),
117336 sizeof(pInfo->aFunc[0]),
117360 assert( pAggInfo->iFirstReg==0 );
117362 for(k=0; k<pAggInfo->nColumn; k++, pCol++){
117372 if( k<0 ){
117393 for(j=0; j<n; j++, pTerm++){
117404 if( pCol->iSorterColumn<0 ){
117409 assert( pExpr->pAggInfo==0 || pExpr->pAggInfo==pAggInfo );
117431 assert( pAggInfo->iFirstReg==0 );
117436 assert( pParse->iSelfTab==0 );
117437 if( (pNC->ncFlags & NC_InAggFunc)==0 ) break;
117438 if( pParse->pIdxEpr==0 ) break;
117441 if( iDataCur<0 ) continue;
117442 if( sqlite3ExprCompare(0, pExpr, pIEpr->pExpr, iDataCur)==0 ) break;
117444 if( pIEpr==0 ) break;
117446 for(i=0; i<pSrcList->nSrc; i++){
117447 if( pSrcList->a[0].iCursor==pIEpr->iDataCur ) break;
117450 if( NEVER(pExpr->pAggInfo!=0) ) break; /* Resolved by outer context */
117457 memset(&tmp, 0, sizeof(tmp));
117463 assert( pAggInfo->aCol!=0 );
117478 if( ALWAYS(pSrcList!=0) ){
117480 for(i=0; i<pSrcList->nSrc; i++, pItem++){
117491 if( (pNC->ncFlags & NC_InAggFunc)==0
117493 && pExpr->pAggInfo==0
117501 for(i=0; i<pAggInfo->nFunc; i++, pItem++){
117503 if( sqlite3ExprCompare(0, pItem->pFExpr, pExpr, -1)==0 ){
117516 if( i>=0 ){
117522 nArg = pExpr->x.pList ? pExpr->x.pList->nExpr : 0;
117524 pExpr->u.zToken, nArg, enc, 0);
117525 assert( pItem->bOBUnique==0 );
117527 && (pItem->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)==0
117532 assert( nArg>0 );
117537 assert( pOBList->nExpr>0 );
117538 assert( pItem->bOBUnique==0 );
117541 && sqlite3ExprCompare(0,pOBList->a[0].pExpr,
117542 pExpr->x.pList->a[0].pExpr,0)==0
117544 pItem->bOBPayload = 0;
117550 (pItem->pFunc->funcFlags & SQLITE_SUBTYPE)!=0;
117591 w.walkerDepth = 0;
117593 w.pParse = 0;
117594 assert( pNC->pSrcList!=0 );
117608 for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
117618 if( pParse->nTempReg==0 ){
117630 sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0, 0);
117659 sqlite3VdbeReleaseRegisters(pParse, iReg, nReg, 0, 0);
117675 pParse->nTempReg = 0;
117676 pParse->nRangeReg = 0;
117698 for(i=0; i<pList->nExpr; i++){
117704 pParse->nTempReg = 0;
117705 pParse->nRangeReg = 0;
117718 if( pParse->nRangeReg>0
117722 return 0;
117724 for(i=0; i<pParse->nTempReg; i++){
117726 return 0;
117731 for(i=0; i<pList->nExpr; i++){
117733 if( iReg==0 ) continue;
117734 if( iReg>=iFirst && iReg<=iLast ) return 0;
117774 if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)
117776 || (pTab->tabFlags & TF_Eponymous)!=0
117777 || ( (pTab->tabFlags & TF_Shadow)!=0
117785 return 0;
117813 if( bTemp==0 ){
117839 if( bTemp==0 ){
117857 sqlite3VdbeAddParseSchemaOp(pParse->pVdbe, iDb, 0, p5);
117858 if( iDb!=1 ) sqlite3VdbeAddParseSchemaOp(pParse->pVdbe, 1, 0, p5);
117874 char *zName = 0; /* NULL-terminated version of pName */
117879 VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */
117885 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
117925 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
117936 if( pVTab->pVtab->pModule->xRename==0 ){
117937 pVTab = 0;
117947 if( v==0 ){
118004 " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename', 0) "
118019 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
118024 renameTestSchema(pParse, zDb, iDb==1, "after rename", 0);
118071 assert( db->mallocFailed==0 );
118086 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
118105 if( (pCol->colFlags & COLFLAG_GENERATED)==0 ){
118107 ** literal NULL, then set pDflt to 0. This simplifies checking
118110 assert( pDflt==0 || pDflt->op==TK_SPAN );
118112 pDflt = 0;
118129 sqlite3_value *pVal = 0;
118153 *zEnd-- = '\0';
118189 if( pNew->pCheck!=0
118190 || (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0)
118191 || (pTab->tabFlags & TF_Strict)!=0
118234 assert( pParse->pNewTable==0 );
118237 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
118258 assert( pTab->u.tab.addColOffset>0 );
118273 assert( pNew->nCol>0 );
118275 assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
118283 for(i=0; i<pNew->nCol; i++){
118289 pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0);
118309 const char *zType = 0;
118327 return 0;
118330 # define isRealTable(x,y,z) (0)
118347 char *zOld = 0; /* Old column name */
118348 char *zNew = 0; /* New column name */
118354 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
118359 if( SQLITE_OK!=isRealTable(pParse, pTab, 0) ) goto exit_rename_column;
118363 assert( iSchema>=0 );
118368 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
118378 if( iCol<0 ){
118384 renameTestSchema(pParse, zDb, iSchema==1, "", 0);
118394 assert( pNew->n>0 );
118395 bQuote = sqlite3Isquote(pNew->z[0]);
118486 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
118487 if( pParse->nErr==0 ){
118496 assert( i>0 );
118557 sqlite3RenameTokenRemap(pParse, 0, (const void*)pExpr);
118559 sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab);
118573 With *pCopy = 0;
118574 assert( pWith->nCte>0 );
118575 if( (pWith->a[0].pSelect->selFlags & SF_Expanded)==0 ){
118584 for(i=0; i<pWith->nCte; i++){
118587 memset(&sNC, 0, sizeof(sNC));
118608 assert( pIdList!=0 );
118609 for(ii=0; ii<pIdList->nId; ii++){
118610 sqlite3RenameTokenRemap(pParse, 0, (const void*)pIdList->a[ii].zName);
118628 for(i=0; i<pList->nExpr; i++){
118630 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
118636 for(i=0; i<pSrc->nSrc; i++){
118637 sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
118638 if( pSrc->a[i].fg.isUsing==0 ){
118656 memset(&sWalker, 0, sizeof(Walker));
118673 memset(&sWalker, 0, sizeof(Walker));
118677 for(i=0; i<pEList->nExpr; i++){
118679 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
118712 if( NEVER(pPtr==0) ){
118713 return 0;
118727 return 0;
118813 zT, zN, (zWhen[0] ? " " : ""), zWhen,
118834 for(i=0; i<pEList->nExpr; i++){
118837 && ALWAYS(zName!=0)
118838 && 0==sqlite3_stricmp(zName, zOld)
118859 for(i=0; i<pIdList->nId; i++){
118861 if( 0==sqlite3_stricmp(zName, zOld) ){
118884 if( zSql==0 ){
118887 if( sqlite3StrNICmp(zSql,"CREATE ",7)!=0 ){
118894 assert( iDb>=0 && iDb<=0xff );
118901 testcase( (db->flags & SQLITE_Comments)==0 && strstr(zSql," /* ")!=0 );
118907 && NEVER(p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0)
118924 db->init.iDb = 0;
118948 char *zQuot = 0;
118950 i64 nQuot = 0;
118951 char *zBuf1 = 0;
118952 char *zBuf2 = 0;
118961 if( zQuot==0 ){
118967 assert( nQuot>=nNew && nSql>=0 && nNew>=0 );
118970 assert( nSql>0 );
118984 assert( nSql>0 );
118993 if( bQuote==0 && sqlite3IsIdChar(*(u8*)pBest->t.z) ){
119009 zBuf1[pBest->t.n] = 0;
119011 assert( nSql < 0x15555554 /* otherwise malloc would have failed */ );
119025 zOut[nOut] = '\0';
119048 for(i=0; i<pEList->nExpr; i++){
119050 pEList->a[i].fg.eEName = val&0x3;
119068 memset(&sNC, 0, sizeof(sNC));
119078 rc = sqlite3ViewGetColumnNames(pParse, pParse->pTriggerTab)!=0;
119095 pParse, pStep->pExprList, pSrc, 0, 0, 0, 0, 0, 0
119097 if( pSel==0 ){
119098 pStep->pExprList = 0;
119099 pSrc = 0;
119111 sqlite3SelectPrep(pParse, pSel, 0);
119114 assert( pStep->pExprList==0 || pStep->pExprList==pSel->pEList );
119116 if( pStep->pExprList ) pSel->pEList = 0;
119117 pSel->pSrc = 0;
119122 for(i=0; i<pStep->pFrom->nSrc && rc==SQLITE_OK; i++){
119125 assert( p->u4.pSubq!=0 );
119126 sqlite3SelectPrep(pParse, p->u4.pSubq->pSelect, 0);
119158 sNC.ncFlags = 0;
119160 sNC.pSrcList = 0;
119195 for(i=0; i<pFrom->nSrc; i++){
119197 assert( pFrom->a[i].u4.pSubq!=0 );
119216 while( (pIdx = pParse->pNewIndex)!=0 ){
119231 ** 0. zSql: SQL statement to rewrite
119242 ** The iCol-th column (left-most is 0) of table zTable is renamed from zCol
119257 const char *zSql = (const char*)sqlite3_value_text(argv[0]);
119276 if( zSql==0 ) return;
119277 if( zTable==0 ) return;
119278 if( zNew==0 ) return;
119279 if( iCol<0 ) return;
119282 if( pTab==0 || iCol>=pTab->nCol ){
119287 memset(&sCtx, 0, sizeof(sCtx));
119291 db->xAuth = 0;
119296 memset(&sWalker, 0, sizeof(Walker));
119309 sqlite3SelectPrep(&sParse, pSelect, 0);
119320 if( bFKOnly==0 ){
119326 if( sCtx.iCol<0 ){
119337 for(i=0; i<sParse.pNewTable->nCol; i++){
119347 for(i=0; i<pFKey->nCol; i++){
119348 if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
119351 if( 0==sqlite3_stricmp(pFKey->zTo, zTable)
119352 && 0==sqlite3_stricmp(pFKey->aCol[i].zCol, zOld)
119370 Table *pTarget = sqlite3LocateTable(&sParse, 0, pStep->zTarget, zDb);
119398 sqlite3_result_value(context, argv[0]);
119440 if( NEVER(pSrc==0) ){
119444 for(i=0; i<pSrc->nSrc; i++){
119462 ** 0: The database containing the table being renamed.
119472 ** sqlite_rename_table('main', 'CREATE TABLE t1(a REFERENCES t2)','t2','t3',0)
119481 const char *zDb = (const char*)sqlite3_value_text(argv[0]);
119497 db->xAuth = 0;
119502 memset(&sCtx, 0, sizeof(RenameCtx));
119504 memset(&sWalker, 0, sizeof(Walker));
119518 if( isLegacy==0 ){
119521 memset(&sNC, 0, sizeof(sNC));
119536 if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys))
119542 if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
119552 if( sqlite3_stricmp(zOld, pTab->zName)==0 ){
119554 if( isLegacy==0 ){
119564 if( isLegacy==0 ){
119573 if( 0==sqlite3_stricmp(sParse.pNewTrigger->table, zOld)
119579 if( isLegacy==0 ){
119584 if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){
119589 for(i=0; i<pStep->pFrom->nSrc; i++){
119591 if( 0==sqlite3_stricmp(pItem->zName, zOld) ){
119641 ** 0: Database name ("main", "temp" etc.).
119667 char const *zDb = (const char*)sqlite3_value_text(argv[0]);
119672 db->xAuth = 0;
119681 rc = renameParseSql(&sParse, zDb, db, zInput, 0);
119688 memset(&sCtx, 0, sizeof(RenameCtx));
119689 memset(&sWalker, 0, sizeof(Walker));
119700 sqlite3SelectPrep(&sParse, pSelect, 0);
119709 for(i=0; i<sParse.pNewTable->nCol; i++){
119729 rc = renameEditSql(context, &sCtx, zInput, 0, 0);
119758 ** 0: Database name ("main", "temp" etc.).
119780 char const *zDb = (const char*)sqlite3_value_text(argv[0]);
119789 db->xAuth = 0;
119802 if( isLegacy==0 && sParse.pNewTable && IsView(sParse.pNewTable) ){
119804 memset(&sNC, 0, sizeof(sNC));
119811 if( isLegacy==0 ){
119842 ** argv[0]: An integer - the index of the schema containing the table
119855 int iSchema = sqlite3_value_int(argv[0]);
119864 char *zNew = 0;
119868 db->xAuth = 0;
119875 if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
119881 pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zCnName);
119884 pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName);
119889 while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
119919 char *zCol = 0; /* Name of column to drop */
119923 assert( pParse->pNewTable==0 );
119926 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
119936 if( zCol==0 ){
119941 if( iCol<0 ){
119964 assert( iDb>=0 );
119972 renameTestSchema(pParse, zDb, iDb==1, "", 0);
119986 if( pParse->nErr==0 && (pTab->aCol[iCol].colFlags & COLFLAG_VIRTUAL)==0 ){
119991 Index *pPk = 0;
119992 int nField = 0; /* Number of non-virtual columns after drop */
120005 for(i=0; i<pPk->nKeyCol; i++){
120011 for(i=0; i<pTab->nCol; i++){
120012 if( i!=iCol && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
120023 sqlite3VdbeAddOp2(v, OP_Null, 0, regOut);
120035 if( nField==0 ){
120038 sqlite3VdbeAddOp2(v, OP_Null, 0, reg+1);
120104 ** created and used by SQLite versions 3.7.9 through 3.29.0 when
120151 ** The sqlite_stat2 entries for an index that have sampleno between 0 and 9
120159 ** For i between 0 and S-1. Conceptually, the index space is divided into
120222 # define IsStat4 0
120238 ** If zWhere==0, then code is generated to delete all stat table entries.
120255 { "sqlite_stat4", 0 },
120257 { "sqlite_stat3", 0 },
120271 if( v==0 ) return;
120279 for(i=0; i<ArraySize(aTable); i++){
120282 aCreateTbl[i] = 0;
120283 if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){
120319 for(i=0; i<nToOpen; i++){
120372 int nMaxEqZero; /* Max leading 0 in anEq[] for any a[] entry */
120382 assert( db!=0 );
120385 p->nRowid = 0;
120394 assert( db!=0 );
120401 p->nRowid = 0;
120410 assert( db!=0 );
120412 p->nRowid = 0;
120445 for(i=0; i<p->nCol; i++) sampleClear(p->db, p->aBest+i);
120446 for(i=0; i<p->mxSample; i++) sampleClear(p->db, p->a+i);
120459 ** L: A limit on the number of rows to scan, or 0 for no-limit
120487 /* Maximum number of samples. 0 if STAT4 data is not collected */
120488 int mxSample = OptimizationEnabled(db,SQLITE_Stat4) ?SQLITE_STAT4_SAMPLES :0;
120493 nCol = sqlite3_value_int(argv[0]);
120494 assert( nCol>0 );
120498 assert( nKeyCol>0 );
120512 if( p==0 ){
120519 p->nRow = 0;
120523 p->nSkipAhead = 0;
120528 p->mxSample = p->nLimit==0 ? mxSample : 0;
120536 p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]);
120542 for(i=0; i<(mxSample+nCol); i++){
120549 for(i=0; i<nCol; i++){
120564 0, /* pUserData */
120565 0, /* pNext */
120567 0, /* xFinalize */
120568 0, 0, /* xValue, xInverse */
120570 {0}
120595 if( pNew->anEq[i]<pOld->anEq[i] ) return 0;
120598 return 0;
120617 assert( pOld->isPSample==0 && pNew->isPSample==0 );
120618 assert( IsStat4 || (pNew->iCol==0 && pOld->iCol==0) );
120625 return 0;
120633 StatSample *pSample = 0;
120636 assert( IsStat4 || nEqZero==0 );
120638 /* StatAccum.nMaxEqZero is set to the maximum number of leading 0
120641 ** are no samples with StatSample.anEq[m]==0 for (m>=n). */
120645 if( pNew->isPSample==0 ){
120646 StatSample *pUpgrade = 0;
120647 assert( pNew->anEq[pNew->iCol]>0 );
120654 for(i=p->nSample-1; i>=0; i--){
120656 if( pOld->anEq[pNew->iCol]==0 ){
120660 if( pUpgrade==0 || sampleIsBetter(p, pOld, pUpgrade) ){
120679 memmove(pMin, &pMin[1], sizeof(p->a[0])*(p->nSample-p->iMin-1));
120681 pSample->nRowid = 0;
120691 assert( p->nSample==0
120700 memset(pSample->anEq, 0, sizeof(tRowcnt)*nEqZero);
120705 for(i=0; i<p->mxSample; i++){
120707 if( iMin<0 || sampleIsBetter(p, &p->a[iMin], &p->a[i]) ){
120711 assert( iMin>=0 );
120739 for(i=p->nSample-1; i>=0; i--){
120741 for(j=p->nMaxEqZero; j<p->nCol; j++) assert( p->a[i].anEq[j]>0 );
120746 for(i=p->nSample-1; i>=0; i--){
120749 if( p->a[i].anEq[j]==0 ) p->a[i].anEq[j] = p->current.anEq[j];
120784 StatAccum *p = (StatAccum*)sqlite3_value_blob(argv[0]);
120789 assert( p->nCol>0 );
120792 if( p->nRow==0 ){
120795 for(i=0; i<p->nCol; i++) p->current.anEq[i] = 1;
120806 for(i=0; i<iChng; i++){
120835 p->current.iCol = 0;
120837 p->current.isPSample = 0;
120841 for(i=0; i<(p->nCol-1); i++){
120851 sqlite3_result_int(context, p->current.anDLt[0]>0);
120858 0, /* pUserData */
120859 0, /* pNext */
120861 0, /* xFinalize */
120862 0, 0, /* xValue, xInverse */
120864 {0}
120867 #define STAT_GET_STAT1 0 /* "stat" column of stat1 table */
120897 StatAccum *p = (StatAccum*)sqlite3_value_blob(argv[0]);
120941 sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
120944 for(i=0; i<p->nKeyCol; i++){
120950 assert( p->current.anEq[i] || p->nRow==0 );
120957 if( p->iGet<0 ){
120958 samplePushPrevious(p, 0);
120959 p->iGet = 0;
120963 if( pS->nRowid==0 ){
120971 tRowcnt *aCnt = 0;
120985 sqlite3StrAccumInit(&sStat, 0, 0, 0, p->nCol*100);
120986 for(i=0; i<p->nCol; i++){
121000 0, /* pUserData */
121001 0, /* pNext */
121003 0, /* xFinalize */
121004 0, 0, /* xValue, xInverse */
121006 {0}
121018 sqlite3VdbeAddFunctionCall(pParse, 0, regStat, regOut, 1+IsStat4,
121019 &statGetFuncdef, 0);
121032 assert( k>=0 && k<pIdx->nColumn );
121082 Table *pStat1 = 0;
121088 if( v==0 || NEVER(pTab==0) ){
121095 if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){
121101 assert( iDb>=0 );
121102 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
121104 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
121113 if( pStat1==0 ) return;
121118 sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNAMIC);
121126 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
121141 if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0;
121159 ** regChng = 0
121162 ** stat_init() with count = 0;
121170 ** regChng = 0
121171 ** if( idx(0) != regPrev(0) ) goto chng_addr_0
121179 ** regPrev(0) = idx(0)
121207 ** regChng = 0
121210 ** stat_init() with count = 0;
121230 sqlite3VdbeAddFunctionCall(pParse, 0, regStat+1, regStat, 4,
121231 &statInitFuncdef, 0);
121235 sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
121238 if( nColTest>0 ){
121242 if( aGotoChng==0 ) continue;
121246 ** regChng = 0
121247 ** if( idx(0) != regPrev(0) ) goto chng_addr_0
121263 for(i=0; i<nColTest; i++){
121269 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
121279 ** regPrev(0) = idx(0)
121285 for(i=0; i<nColTest; i++){
121310 for(j=0; j<pPk->nKeyCol; j++){
121312 assert( k>=0 && k<pIdx->nColumn );
121324 &statPushFuncdef, 0);
121329 j3 = sqlite3VdbeAddOp4Int(v, OP_SeekGT, iIdxCur, 0, regPrev, 1);
121345 addrGotoEnd = 0;
121348 assert( "BBB"[0]==SQLITE_AFF_TEXT );
121349 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
121359 if( OptimizationEnabled(db, SQLITE_Stat4) && db->nAnalysisLimit==0 ){
121371 if( addrGotoEnd==0 ){
121394 doOnce = 0;
121414 sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
121416 for(i=0; i<nCol; i++){
121436 if( pOnlyIdx==0 && needTableCnt ){
121440 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
121441 assert( "BBB"[0]==SQLITE_AFF_TEXT );
121442 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
121476 sqlite3BeginWriteOperation(pParse, 0, iDb);
121479 openStatTable(pParse, iDb, iStatCur, 0, 0);
121482 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
121485 analyzeOneTable(pParse, pTab, 0, iStatCur, iMem, iTab);
121504 assert( pTab!=0 );
121507 sqlite3BeginWriteOperation(pParse, 0, iDb);
121548 assert( pName2!=0 || pName1==0 );
121549 if( pName1==0 ){
121551 for(i=0; i<db->nDb; i++){
121555 }else if( pName2->n==0 && (iDb = sqlite3FindDb(db, pName1))>=0 ){
121561 if( iDb>=0 ){
121562 zDb = pName2->n ? db->aDb[iDb].zDbSName : 0;
121565 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
121567 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
121568 analyzeTable(pParse, pTab, 0);
121574 if( db->nSqlExec==0 && (v = sqlite3GetVdbe(pParse))!=0 ){
121598 LogEst *aLog, /* Or, if aOut==0, here */
121607 if( z==0 ) z = "";
121609 assert( z!=0 );
121611 for(i=0; *z && i<nOut; i++){
121612 v = 0;
121613 while( (c=z[0])>='0' && c<='9' ){
121614 v = v*10 + c - '0';
121621 assert( aOut==0 );
121623 assert( aLog!=0 );
121629 assert( pIndex!=0 ); {
121633 pIndex->bUnordered = 0;
121634 pIndex->noSkipScan = 0;
121635 while( z[0] ){
121636 if( sqlite3_strglob("unordered*", z)==0 ){
121638 }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
121642 }else if( sqlite3_strglob("noskipscan*", z)==0 ){
121646 else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){
121650 while( z[0]!=0 && z[0]!=' ' ) z++;
121651 while( z[0]==' ' ) z++;
121660 ** argv[0] = name of the table
121676 if( argv==0 || argv[0]==0 || argv[2]==0 ){
121677 return 0;
121679 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
121680 if( pTable==0 ){
121681 return 0;
121683 if( argv[1]==0 ){
121684 pIndex = 0;
121685 }else if( sqlite3_stricmp(argv[0],argv[1])==0 ){
121693 tRowcnt *aiRowEst = 0;
121699 if( pIndex->aiRowEst==0 ){
121701 if( pIndex->aiRowEst==0 ) sqlite3OomFault(pInfo->db);
121705 pIndex->bUnordered = 0;
121708 if( pIndex->pPartIdxWhere==0 ){
121709 pTable->nRowLogEst = pIndex->aiRowLogEst[0];
121718 decodeIntArray((char*)z, 1, 0, &pTable->nRowLogEst, &fakeIdx);
121723 return 0;
121731 assert( db!=0 );
121732 assert( pIdx!=0 );
121736 for(j=0; j<pIdx->nSample; j++){
121742 if( db->pnBytesFreed==0 ){
121743 pIdx->nSample = 0;
121744 pIdx->aSample = 0;
121771 for(iCol=0; iCol<nCol; iCol++){
121774 tRowcnt sumEq = 0; /* Sum of the nEq values */
121775 tRowcnt avgEq = 0;
121777 i64 nSum100 = 0; /* Number of terms contributing to sumEq */
121780 if( !pIdx->aiRowEst || iCol>=pIdx->nKeyCol || pIdx->aiRowEst[iCol+1]==0 ){
121785 nRow = pIdx->aiRowEst[0];
121786 nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
121794 for(i=0; i<nSample; i++){
121806 if( avgEq==0 ) avgEq = 1;
121822 if( pIdx==0 ){
121848 sqlite3_stmt *pStmt = 0; /* An SQL statement being run */
121850 Index *pPrevIdx = 0; /* Previous index in the loop */
121858 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
121873 zIndex = (char *)sqlite3_column_text(pStmt, 0);
121874 if( zIndex==0 ) continue;
121877 assert( pIdx==0 || pIdx->nSample==0 );
121878 if( pIdx==0 ) continue;
121879 if( pIdx->aSample!=0 ){
121896 if( pIdx->aSample==0 ){
121901 pPtr += ROUND8(nSample*sizeof(pIdx->aSample[0]));
121906 for(i=0; i<nSample; i++){
121920 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
121929 zIndex = (char *)sqlite3_column_text(pStmt, 0);
121930 if( zIndex==0 ) continue;
121932 if( pIdx==0 ) continue;
121946 decodeIntArray((char*)sqlite3_column_text(pStmt,1),nCol,pSample->anEq,0,0);
121947 decodeIntArray((char*)sqlite3_column_text(pStmt,2),nCol,pSample->anLt,0,0);
121948 decodeIntArray((char*)sqlite3_column_text(pStmt,3),nCol,pSample->anDLt,0,0);
121950 /* Take a copy of the sample. Add 8 extra 0x00 bytes the end of the buffer.
121955 ** buffer. In any case, eight 0x00 bytes prevents this from causing
121959 if( pSample->p==0 ){
121983 && (pStat4 = sqlite3FindTable(db, "sqlite_stat4", zDb))!=0
122024 assert( iDb>=0 && iDb<db->nDb );
122025 assert( db->aDb[iDb].pBt!=0 );
122028 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
122035 pIdx->hasStat1 = 0;
122038 pIdx->aSample = 0;
122050 if( zSql==0 ){
122053 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
122059 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
122075 pIdx->aiRowEst = 0;
122143 sqlite3StrICmp(db->aDb[iDb].zDbSName, zName)==0
122144 || (iDb==0 && sqlite3StrICmp("main", zName)==0)
122169 int rc = 0;
122173 char *zPath = 0;
122174 char *zErr = 0;
122177 Db *pNew = 0; /* Db object for the newly attached database */
122178 char *zErrDyn = 0;
122182 zFile = (const char *)sqlite3_value_text(argv[0]);
122184 if( zFile==0 ) zFile = "";
122185 if( zName==0 ) zName = "";
122190 # define REOPEN_AS_MEMDB(db) (0)
122197 Btree *pNewBt = 0;
122199 if( pVfs==0 ) return;
122200 rc = sqlite3BtreeOpen(pVfs, "x\0", db, &pNewBt, 0, SQLITE_OPEN_MAIN_DB);
122232 for(i=0; i<db->nDb; i++){
122244 aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 );
122245 if( aNew==0 ) return;
122246 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
122248 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(1+(i64)db->nDb));
122249 if( aNew==0 ) return;
122253 memset(pNew, 0, sizeof(*pNew));
122267 if( (db->flags & SQLITE_AttachWrite)==0 ){
122270 }else if( (db->flags & SQLITE_AttachCreate)==0 ){
122275 rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags);
122279 db->noSharedCache = 0;
122297 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
122305 if( rc==SQLITE_OK && pNew->zDbSName==0 ){
122317 db->init.iDb = 0;
122330 assert( zErrDyn==0 || rc!=SQLITE_OK );
122338 db->aDb[iDb].pBt = 0;
122339 db->aDb[iDb].pSchema = 0;
122347 }else if( zErrDyn==0 ){
122378 const char *zName = (const char *)sqlite3_value_text(argv[0]);
122381 Db *pDb = 0;
122387 if( zName==0 ) zName = "";
122388 for(i=0; i<db->nDb; i++){
122390 if( pDb->pBt==0 ) continue;
122422 pDb->pBt = 0;
122423 pDb->pSchema = 0;
122453 memset(&sName, 0, sizeof(NameContext));
122471 zAuthArg = 0;
122473 rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
122489 sqlite3VdbeAddFunctionCall(pParse, 0, regArgs+3-pFunc->nArg, regArgs+3,
122490 pFunc->nArg, pFunc, 0);
122513 0, /* pUserData */
122514 0, /* pNext */
122516 0, /* xFinalize */
122517 0, 0, /* xValue, xInverse */
122519 {0}
122521 codeAttach(pParse, SQLITE_DETACH, &detach_func, pDbname, 0, 0, pDbname);
122533 0, /* pUserData */
122534 0, /* pNext */
122536 0, /* xFinalize */
122537 0, 0, /* xValue, xInverse */
122539 {0}
122573 if( NEVER(pList==0) ) return WRC_Continue;
122574 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
122575 if( pFix->bTemp==0 && pItem->fg.isSubquery==0 ){
122576 if( pItem->fg.fixedSchema==0 && pItem->u4.zDatabase!=0 ){
122592 if( pList->a[i].fg.isUsing==0
122600 for(i=0; i<pSelect->pWith->nCte; i++){
122632 pFix->w.walkerDepth = 0;
122633 pFix->w.eCode = 0;
122649 ** checks out, these routines return 0.
122655 int res = 0;
122658 memset(&s, 0, sizeof(s));
122709 return 0;
122832 if( db->nDb>2 || iDb!=0 ) z = sqlite3_mprintf("%s.%z", zDb, z);
122856 Table *pTab = 0; /* The table being read */
122864 assert( pParse->db->xAuth!=0 );
122866 if( iDb<0 ){
122876 for(iSrc=0; iSrc<pTabList->nSrc; iSrc++){
122884 if( pTab==0 ) return;
122886 if( iCol>=0 ){
122889 }else if( pTab->iPKey>=0 ){
122895 assert( iDb>=0 && iDb<pParse->db->nDb );
122920 assert( !IN_RENAME_OBJECT || db->xAuth==0 );
122921 if( db->xAuth==0 || db->init.busy || IN_SPECIAL_PARSE ){
122931 testcase( zArg1==0 );
122932 testcase( zArg2==0 );
122933 testcase( zArg3==0 );
122934 testcase( pParse->zAuthContext==0 );
122950 ** popped. Or if pParse==0, this routine is a no-op.
122970 pContext->pParse = 0;
123037 assert( iDb>=0 );
123040 for(i=0; i<pToplevel->nTableLock; i++){
123048 assert( pToplevel->nTableLock < 0x7fff0000 );
123059 pToplevel->nTableLock = 0;
123082 assert( pVdbe!=0 );
123084 for(i=0; i<pParse->nTableLock; i++){
123103 for(i=0; i<sizeof(yDbMask); i++) if( m[i] ) return 0;
123123 assert( pParse->pToplevel==0 );
123131 assert( db->mallocFailed==0 );
123137 if( v==0 ){
123143 if( v==0 ) pParse->rc = SQLITE_ERROR;
123161 for(i=0; i<pReturning->nRetCol; i++){
123173 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
123178 assert( pParse->nErr>0 || sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
123179 sqlite3VdbeJumpHere(v, 0);
123180 assert( db->nDb>0 );
123181 iDb = 0;
123184 if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
123194 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
123199 for(i=0; i<pParse->nVtabLock; i++){
123201 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
123203 pParse->nVtabLock = 0;
123222 pParse->okConstFactor = 0;
123223 for(i=0; i<pEL->nExpr; i++){
123224 assert( pEL->a[i].u.iConstExprReg>0 );
123244 assert( v!=0 || pParse->nErr );
123245 assert( db->mallocFailed==0 || pParse->nErr );
123246 if( pParse->nErr==0 ){
123249 assert( pParse->pAinc==0 || pParse->nTab>0 );
123283 if( zSql==0 ){
123293 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
123307 ** If zDatabase is 0, all databases are searched for the table and the
123315 Table *p = 0;
123319 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
123321 for(i=0; i<db->nDb; i++){
123322 if( sqlite3StrICmp(zDatabase, db->aDb[i].zDbSName)==0 ) break;
123326 ** to schema 0 as a legacy fallback. */
123327 if( sqlite3StrICmp(zDatabase,"main")==0 ){
123328 i = 0;
123330 return 0;
123334 if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
123336 if( sqlite3StrICmp(zName+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0
123337 || sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0
123338 || sqlite3StrICmp(zName+7, &LEGACY_SCHEMA_TABLE[7])==0
123344 if( sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0 ){
123355 p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, zName);
123359 assert( sqlite3SchemaMutexHeld(db, i, 0) );
123363 if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
123364 if( sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0 ){
123365 p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, LEGACY_SCHEMA_TABLE);
123366 }else if( sqlite3StrICmp(zName+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 ){
123396 if( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0
123399 return 0;
123403 if( p==0 ){
123408 if( (pParse->prepFlags & SQLITE_PREPARE_NO_VTAB)==0 && db->init.busy==0 ){
123410 if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
123414 testcase( pMod->pEpoTab==0 );
123419 if( flags & LOCATE_NOERR ) return 0;
123421 }else if( IsVirtual(p) && (pParse->prepFlags & SQLITE_PREPARE_NO_VTAB)!=0 ){
123422 p = 0;
123425 if( p==0 ){
123433 assert( HasRowid(p) || p->iPKey<0 );
123469 if( sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
123470 if( sqlite3StrICmp(zName+7, &LEGACY_SCHEMA_TABLE[7])==0 ){
123473 if( sqlite3StrICmp(zName+7, &LEGACY_TEMP_SCHEMA_TABLE[7])==0 ){
123486 ** If zDatabase is 0, all databases are searched for the
123493 Index *p = 0;
123496 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
123501 if( zDb && sqlite3DbIsNamed(db, j, zDb)==0 ) continue;
123502 assert( sqlite3SchemaMutexHeld(db, j, 0) );
123536 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
123538 pIndex = sqlite3HashInsert(pHash, zIdxName, 0);
123562 ** Entry 0 (the "main" database) and entry 1 (the "temp" database)
123569 if( pDb->pBt==0 ){
123571 pDb->zDbSName = 0;
123581 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
123590 ** Deferred resets may be run by calling with iDb<0.
123596 if( iDb>=0 ){
123597 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
123603 if( db->nSchemaLock==0 ){
123604 for(i=0; i<db->nDb; i++){
123619 for(i=0; i<db->nDb; i++){
123622 if( db->nSchemaLock==0 ){
123632 if( db->nSchemaLock==0 ){
123658 if( pCol->iDflt==0
123659 || NEVER(pList==0)
123662 pCol->iDflt = pList==0 ? 1 : pList->nExpr+1;
123676 if( pCol->iDflt==0 ) return 0;
123677 if( !IsOrdinaryTable(pTab) ) return 0;
123678 if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
123679 if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
123694 assert( zColl!=0 );
123713 if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0;
123729 assert( pTable!=0 );
123730 assert( db!=0 );
123731 if( (pCol = pTable->aCol)!=0 ){
123732 for(i=0; i<pTable->nCol; i++, pCol++){
123733 assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
123740 if( db->pnBytesFreed==0 ){
123741 pTable->aCol = 0;
123742 pTable->nCol = 0;
123744 pTable->u.tab.pDfltList = 0;
123776 int nLookaside = 0;
123777 assert( db!=0 );
123778 if( !db->mallocFailed && (pTable->tabFlags & TF_Ephemeral)==0 ){
123779 nLookaside = sqlite3LookasideUsed(db, 0);
123788 if( db->pnBytesFreed==0 && !IsVirtual(pTable) ){
123791 &pIndex->pSchema->idxHash, zName, 0
123793 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
123794 assert( pOld==pIndex || pOld==0 );
123821 assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) );
123825 assert( db!=0 );
123827 if( db->pnBytesFreed==0 && (--pTable->nTabRef)>0 ) return;
123843 assert( db!=0 );
123844 assert( iDb>=0 && iDb<db->nDb );
123846 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
123847 testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
123849 p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, 0);
123873 zName = 0;
123880 ** writing. The table is opened using cursor 0.
123885 sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, SCHEMA_ROOT, iDb, 5);
123886 if( p->nTab==0 ){
123901 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
123902 if( 0==sqlite3_stricmp(pDb->zDbSName, zName) ) break;
123905 if( i==0 && 0==sqlite3_stricmp("main", zName) ) break;
123951 assert( pName2!=0 );
123952 if( pName2->n>0 ){
123959 if( iDb<0 ){
123964 assert( db->init.iDb==0 || db->init.busy || IN_SPECIAL_PARSE
123965 || (db->mDbFlags & DBFLAG_Vacuum)!=0);
123976 testcase( (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))==0 );
124012 if( sqlite3_stricmp(zType, db->init.azInit[0])
124020 if( (pParse->nested==0 && 0==sqlite3StrNICmp(zName, "sqlite_", 7))
124053 for(i=0; i<pIdx->nColumn; i++){
124064 ** The storage column number (0,1,2,....) is the index of the value
124066 ** is the index (0,1,2,...) of the column in the CREATE TABLE statement.
124076 for(i=0; i<=iCol; i++){
124087 ** The storage column number (0,1,2,....) is the index of the value
124092 ** The true column number is the index (0,1,2,...) of the column in
124106 ** -- 0 1 2 3 4 5 6 7 8
124110 ** INPUTS: 0 1 2 3 4 5 6 7 8
124111 ** OUTPUTS: 0 1 6 2 3 7 4 5 8
124125 if( (pTab->tabFlags & TF_HasVirtual)==0 || iCol<0 ) return iCol;
124126 for(i=0, n=0; i<iCol; i++){
124127 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) n++;
124151 sqlite3VdbeAddOp3(v, OP_JournalMode, 0, iReg, PAGER_JOURNALMODE_QUERY);
124152 sqlite3VdbeUsesBtree(v, 0);
124182 char *zName = 0; /* The name of the new table */
124196 if( iDb<0 ) return;
124197 if( !OMIT_TEMPDB && isTemp && pName2->n>0 && iDb!=1 ){
124210 if( zName==0 ) return;
124216 assert( isTemp==0 || isTemp==1 );
124217 assert( isView==0 || isView==1 );
124226 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
124230 zName, 0, zDb) ){
124260 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
124267 if( pTable==0 ){
124282 assert( pParse->pNewTable==0 );
124293 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
124298 static const char nullRow[] = { 6, 0, 0, 0, 0, 0 };
124317 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
124334 sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
124343 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
124344 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
124345 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
124365 if( sqlite3_strnicmp(pCol->zCnName, "__hidden__", 10)==0 ){
124381 sqlite3HashInsert(pHash, pRet->zName, 0);
124409 assert( pParse->bReturning==0 || pParse->ifNotExists );
124413 if( pRet==0 ){
124437 assert( sqlite3HashFind(pHash, pRet->zName)==0
124465 if( (p = pParse->pNewTable)==0 ) return;
124477 && sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0
124480 while( ALWAYS(sType.n>0) && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--;
124482 && sqlite3_strnicmp(sType.z+(sType.n-9),"generated",9)==0
124485 while( sType.n>0 && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--;
124494 for(i=0; i<SQLITE_N_STDTYPE; i++){
124496 && sqlite3_strnicmp(sType.z, sqlite3StdType[i], sType.n)==0
124498 sType.n = 0;
124507 z = sqlite3DbMallocRaw(db, (i64)sName.n + 1 + (i64)sType.n + (sType.n>0) );
124508 if( z==0 ) return;
124511 z[sName.n] = 0;
124513 if( p->nCol && sqlite3ColumnIndex(p, z)>=0 ){
124518 aNew = sqlite3DbRealloc(db,p->aCol,((i64)p->nCol+1)*sizeof(p->aCol[0]));
124519 if( aNew==0 ){
124525 memset(pCol, 0, sizeof(p->aCol[0]));
124530 if( sType.n==0 ){
124546 zType[sType.n] = 0;
124551 if( p->nCol<=0xff ){
124558 pParse->u1.cr.constraintName.n = 0;
124571 if( p==0 || NEVER(p->nCol<1) ) return;
124582 if( pIdx->aiColumn[0]==p->nCol-1 ){
124615 u32 h = 0;
124617 const char *zChar = 0;
124619 assert( zIn!=0 );
124620 while( zIn[0] ){
124634 if( zIn[0]=='(' ) zChar = zIn;
124646 }else if( (h&0x00FFFFFF)==(('i'<<16)+('n'<<8)+'t') ){ /* INT */
124655 int v = 0; /* default size is approx 4 bytes */
124658 while( zChar[0] ){
124659 if( sqlite3Isdigit(zChar[0]) ){
124702 if( p!=0 ){
124719 memset(&x, 0, sizeof(x));
124800 Column *pCol = 0;
124803 if( pTab==0 ) goto primary_key_exit;
124810 if( pList==0 ){
124817 for(i=0; i<nTerm; i++){
124819 assert( pCExpr!=0 );
124824 if( iCol>=0 ){
124837 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
124842 assert( autoInc==0 || autoInc==1 );
124844 if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags;
124852 sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
124853 0, sortOrder, 0, SQLITE_IDXTYPE_PRIMARYKEY);
124854 pList = 0;
124884 for(zStart++; sqlite3Isspace(zStart[0]); zStart++){}
124907 if( (p = pParse->pNewTable)==0 || IN_RENAME_OBJECT ) return;
124923 if( pIdx->aiColumn[0]==i ){
124924 pIdx->azColl[0] = sqlite3ColumnColl(&p->aCol[i]);
124939 if( pTab==0 ){
124948 if( pCol->iDflt>0 ) goto generated_error;
124950 if( pType->n==7 && sqlite3StrNICmp("virtual",pType->z,7)==0 ){
124952 }else if( pType->n==6 && sqlite3StrNICmp("stored",pType->z,6)==0 ){
124971 pExpr = sqlite3PExpr(pParse, TK_UPLUS, pExpr, 0);
124975 pExpr = 0;
125013 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
125028 for(n=0; *z; n++, z++){
125052 for(j=0; zIdent[j]; j++){
125055 needQuote = sqlite3Isdigit(zIdent[0])
125057 || zIdent[j]!=0
125058 || j==0;
125061 for(j=0; zIdent[j]; j++){
125066 z[i] = 0;
125081 n = 0;
125082 for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){
125096 zStmt = sqlite3DbMallocRaw(0, n);
125097 if( zStmt==0 ){
125099 return 0;
125101 assert( n>14 && n<=0x7fffffff );
125106 for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
125124 assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 );
125137 || pCol->affinity==sqlite3AffinityType(zType, 0) );
125159 assert( N>0 );
125162 assert( pIdx->isResized==0 );
125165 if( zExtra==0 ) return SQLITE_NOMEM_BKPT;
125186 unsigned wTable = 0;
125189 for(i=pTab->nCol, pTabCol=pTab->aCol; i>0; i--, pTabCol++){
125192 if( pTab->iPKey<0 ) wTable++;
125200 unsigned wIndex = 0;
125203 for(i=0; i<pIdx->nColumn; i++){
125206 wIndex += x<0 ? 1 : aCol[x].szEst;
125216 while( nCol-- > 0 ){
125221 return 0;
125247 for(i=0; i<nKey; i++){
125248 assert( pIdx->aiColumn[i]>=0 || j>=0 );
125250 && sqlite3StrICmp(pIdx->azColl[i], pPk->azColl[iCol])==0
125255 return 0;
125260 ** colNotIdxed is a bitmask that has a 0 bit representing each indexed
125278 Bitmask m = 0;
125281 for(j=pIdx->nColumn-1; j>=0; j--){
125283 if( x>=0 && (pTab->aCol[x].colFlags & COLFLAG_VIRTUAL)==0 ){
125329 for(i=0; i<pTab->nCol; i++){
125330 if( (pTab->aCol[i].colFlags & COLFLAG_PRIMKEY)!=0
125351 if( pTab->iPKey>=0 ){
125355 pList = sqlite3ExprListAppend(pParse, 0,
125356 sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
125357 if( pList==0 ){
125362 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
125364 pList->a[0].fg.sortFlags = pParse->iPkSortOrder;
125367 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
125373 assert( db->mallocFailed==0 );
125378 assert( pPk!=0 );
125397 assert( pPk!=0 );
125406 if( v && pPk->tnum>0 ){
125407 assert( db->init.busy==0 );
125420 for(i=n=0; i<nPk; i++){
125426 if( n==0 ){
125432 for(i=0, j=pIdx->nKeyCol; i<nPk; i++){
125450 nExtra = 0;
125451 for(i=0; i<pTab->nCol; i++){
125453 && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) nExtra++;
125456 for(i=0, j=nPk; i<pTab->nCol; i++){
125458 && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0
125481 if( !IsVirtual(pTab) ) return 0;
125483 if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0;
125484 if( zName[nName]!='_' ) return 0;
125485 pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]);
125486 if( pMod==0 ) return 0;
125487 if( pMod->pModule->iVersion<3 ) return 0;
125488 if( pMod->pModule->xShadowName==0 ) return 0;
125506 pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]);
125507 if( pMod==0 ) return;
125508 if( NEVER(pMod->pModule==0) ) return;
125510 if( pMod->pModule->xShadowName==0 ) return;
125511 assert( pTab->zName!=0 );
125515 assert( pOther->zName!=0 );
125518 if( sqlite3StrNICmp(pOther->zName, pTab->zName, nName)==0
125540 if( zTail==0 ) return 0;
125541 *zTail = 0;
125542 pTab = sqlite3FindTable(db, zName, 0);
125544 if( pTab==0 ) return 0;
125545 if( !IsVirtual(pTab) ) return 0;
125566 memset(&w, 0, sizeof(w));
125569 w.xSelectCallback2 = 0;
125602 u32 tabOpts, /* Extra table options. Usually 0. */
125610 if( pEnd==0 && pSelect==0 ){
125614 if( p==0 ) return;
125616 if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){
125650 for(ii=0; ii<p->nCol; ii++){
125666 if( (pCol->colFlags & COLFLAG_PRIMKEY)!=0
125676 assert( (p->tabFlags & TF_HasPrimaryKey)==0
125677 || p->iPKey>=0 || sqlite3PrimaryKeyIndex(p)!=0 );
125678 assert( (p->tabFlags & TF_HasPrimaryKey)!=0
125679 || (p->iPKey<0 && sqlite3PrimaryKeyIndex(p)==0) );
125688 if( (p->tabFlags & TF_HasPrimaryKey)==0 ){
125701 sqlite3ResolveSelfReference(pParse, p, NC_IsCheck, 0, p->pCheck);
125706 p->pCheck = 0;
125714 int ii, nNG = 0;
125717 for(ii=0; ii<p->nCol; ii++){
125719 if( (colFlags & COLFLAG_GENERATED)!=0 ){
125723 if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){
125731 sqlite3ExprAlloc(db, TK_NULL, 0, 0));
125737 if( nNG==0 ){
125764 if( NEVER(v==0) ) return;
125766 sqlite3VdbeAddOp1(v, OP_Close, 0);
125820 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
125823 if( pSelTab==0 ) return;
125824 assert( p->aCol==0 );
125827 pSelTab->nCol = 0;
125828 pSelTab->aCol = 0;
125838 sqlite3TableAffinity(v, p, 0);
125852 if( pEnd2->z[0]!=';' ) n += pEnd2->n;
125882 if( (p->tabFlags & TF_Autoincrement)!=0 && !IN_SPECIAL_PARSE ){
125884 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
125885 if( pDb->pSchema->pSeqTab==0 ){
125896 sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName),0);
125901 sqlite3VdbeAddOp4(v, OP_SqlExec, 0x0001, 0, 0,
125912 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
125913 assert( HasRowid(p) || p->iPKey<0 );
125920 pParse->pNewTable = 0;
125928 if( strcmp(p->zName, "sqlite_sequence")==0 ){
125929 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
125938 if( pCons->z==0 ){
125965 Token *pName = 0;
125969 if( pParse->nVar>0 ){
125973 sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
125975 if( p==0 || pParse->nErr ) goto create_view_fail;
126002 pSelect = 0;
126014 assert( sEnd.z[0]!=0 || sEnd.n==0 );
126015 if( sEnd.z[0]!=';' ){
126018 sEnd.n = 0;
126020 assert( n>0 );
126027 sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
126049 int nErr = 0; /* Number of errors encountered */
126074 assert( pTable->nCol<=0 );
126091 if( pTable->nCol<0 ){
126095 assert( pTable->nCol>=0 );
126105 pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
126116 db->xAuth = 0;
126124 if( pSelTab==0 ){
126125 pTable->nCol = 0;
126136 if( pParse->nErr==0
126139 assert( db->mallocFailed==0 );
126146 assert( pTable->aCol==0 );
126150 pSelTab->nCol = 0;
126151 pSelTab->aCol = 0;
126152 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
126170 assert( pTable!=0 );
126171 if( !IsVirtual(pTable) && pTable->nCol>0 ) return 0;
126182 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
126219 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
126282 ** OP_Destroy 4 0
126284 ** OP_Destroy 5 0
126288 ** "OP_Destroy 4 0" opcode. The subsequent "OP_Destroy 5 0" would hit
126292 Pgno iDestroyed = 0;
126296 Pgno iLargest = 0;
126298 if( iDestroyed==0 || iTab<iDestroyed ){
126304 if( (iDestroyed==0 || (iIdx<iDestroyed)) && iIdx>iLargest ){
126308 if( iLargest==0 ){
126312 assert( iDb>=0 && iDb<pParse->db->nDb );
126353 assert( v!=0 );
126407 sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
126410 sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
126421 if( (db->flags & SQLITE_Defensive)!=0
126422 && db->pVtabCtx==0
126423 && db->nVdbeExec==0
126429 return 0;
126436 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
126437 if( sqlite3StrNICmp(pTab->zName+7, "stat", 4)==0 ) return 0;
126438 if( sqlite3StrNICmp(pTab->zName+7, "parameters", 10)==0 ) return 0;
126441 if( (pTab->tabFlags & TF_Shadow)!=0 && sqlite3ReadOnlyShadowTables(db) ){
126447 return 0;
126463 assert( pParse->nErr==0 );
126465 assert( pName->a[0].fg.fixedSchema==0 );
126466 assert( pName->a[0].fg.isSubquery==0 );
126469 assert( isView==0 || isView==LOCATE_VIEW );
126470 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
126473 if( pTab==0 ){
126475 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].u4.zDatabase);
126481 assert( iDb>=0 && iDb<db->nDb );
126494 const char *zArg2 = 0;
126495 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
126519 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
126563 ** in the current table point to the foreign key. If pFromCol==0 then
126585 FKey *pFKey = 0;
126593 assert( pTo!=0 );
126594 if( p==0 || IN_DECLARE_VTAB ) goto fk_end;
126595 if( pFromCol==0 ){
126597 if( NEVER(iCol<0) ) goto fk_end;
126615 for(i=0; i<pToCol->nExpr; i++){
126620 if( pFKey==0 ){
126632 z[pTo->n] = 0;
126636 if( pFromCol==0 ){
126637 pFKey->aCol[0].iFrom = p->nCol-1;
126639 for(i=0; i<nCol; i++){
126641 for(j=0; j<p->nCol; j++){
126642 if( sqlite3StrICmp(p->aCol[j].zCnName, pFromCol->a[i].zEName)==0 ){
126659 for(i=0; i<nCol; i++){
126666 z[n] = 0;
126670 pFKey->isDeferred = 0;
126671 pFKey->aAction[0] = (u8)(flags & 0xff); /* ON DELETE action */
126672 pFKey->aAction[1] = (u8)((flags >> 8 ) & 0xff); /* ON UPDATE action */
126674 assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
126683 assert( pNextTo->pPrevTo==0 );
126692 pFKey = 0;
126704 ** parameter is 1 for INITIALLY DEFERRED and 0 for INITIALLY IMMEDIATE.
126712 if( (pTab = pParse->pNewTable)==0 ) return;
126714 if( (pFKey = pTab->u.tab.pFKey)==0 ) return;
126715 assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */
126747 if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
126757 if( v==0 ) return;
126758 if( memRootPage>=0 ){
126764 assert( pKey!=0 || pParse->nErr );
126768 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*)
126774 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); VdbeCoverage(v);
126778 sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0);
126783 if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
126786 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
126788 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
126859 assert( nCol>0 );
126875 for(i=0; i<pList->nExpr; i++){
126879 (sf==0 || sf==3) ? "FIRST" : "LAST"
126885 return 0;
126904 SrcList *pTblName, /* Table to index. Use pParse->pNewTable if 0 */
126913 Table *pTab = 0; /* Table to be indexed */
126914 Index *pIndex = 0; /* The index to be created */
126915 char *zName = 0; /* Name of the index */
126919 int sortOrderMask; /* 1 to honor DESC in index. 0 to ignore. */
126923 Token *pName = 0; /* Unqualified name of the index to create */
126925 int nExtra = 0; /* Space allocated for zExtra[] */
126927 char *zExtra = 0; /* Extra space after the Index object */
126928 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
126934 assert( db->mallocFailed==0 );
126948 if( pTblName!=0 ){
126956 if( iDb<0 ) goto exit_create_index;
126966 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
126976 assert(0);
126978 pTab = sqlite3LocateTableItem(pParse, 0, &pTblName->a[0]);
126979 assert( db->mallocFailed==0 || pTab==0 );
126980 if( pTab==0 ) goto exit_create_index;
126989 assert( pName==0 );
126990 assert( pStart==0 );
126997 assert( pTab!=0 );
126998 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
126999 && db->init.busy==0
127000 && pTblName!=0
127027 ** If pName==0 it means that we are
127033 if( zName==0 ) goto exit_create_index;
127034 assert( pName->z!=0 );
127040 if( sqlite3FindTable(db, zName, pDb->zDbSName)!=0 ){
127045 if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
127061 if( zName==0 ){
127078 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
127089 /* If pList==0, it means this routine was called to make a primary
127093 if( pList==0 ){
127098 pList = sqlite3ExprListAppend(pParse, 0,
127099 sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
127100 if( pList==0 ) goto exit_create_index;
127111 for(i=0; i<pList->nExpr; i++){
127113 assert( pExpr!=0 );
127143 sqlite3ResolveSelfReference(pParse, pTab, NC_PartIdx, pPIWhere, 0);
127145 pPIWhere = 0;
127147 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
127154 sortOrderMask = 0; /* Ignore DESC */
127169 pList = 0;
127171 for(i=0; i<pIndex->nKeyCol; i++, pListItem++){
127177 sqlite3ResolveSelfReference(pParse, pTab, NC_IdxExpr, pListItem->pExpr, 0);
127186 if( pIndex->aColExpr==0 ){
127188 pList = 0;
127192 pIndex->uniqNotNull = 0;
127196 assert( j<=0x7fff );
127197 if( j<0 ){
127201 if( pTab->aCol[j].notNull==0 ){
127202 pIndex->uniqNotNull = 0;
127211 zColl = 0;
127222 }else if( j>=0 ){
127235 ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
127236 ** normal tables (when pPk==0) this will be the rowid.
127239 for(j=0; j<pPk->nKeyCol; j++){
127241 assert( x>=0 );
127258 if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex);
127263 || pTab->iPKey<0 || sqlite3TableColumnToIndex(pIndex, pTab->iPKey)>=0 );
127265 if( pTblName!=0 && pIndex->nColumn>=pTab->nCol ){
127267 for(j=0; j<pTab->nCol; j++){
127269 if( sqlite3TableColumnToIndex(pIndex,j)>=0 ) continue;
127270 pIndex->isCovering = 0;
127305 for(k=0; k<pIdx->nKeyCol; k++){
127308 assert( pIdx->aiColumn[k]>=0 );
127325 "conflicting ON CONFLICT clauses specified", 0);
127335 pIndex = 0;
127347 assert( pParse->nErr==0 );
127351 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
127352 if( pTblName!=0 ){
127378 ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
127383 else if( HasRowid(pTab) || pTblName!=0 ){
127389 if( v==0 ) goto exit_create_index;
127405 assert( pName!=0 || pStart==0 );
127415 zStmt = 0;
127437 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName), 0);
127438 sqlite3VdbeAddOp2(v, OP_Expire, 0, 1);
127444 if( db->init.busy || pTblName==0 ){
127447 pIndex = 0;
127450 assert( pParse->pNewIndex==0 );
127452 pIndex = 0;
127465 for(ppFrom=&pTab->pIndex; (pThis = *ppFrom)!=0; ppFrom=&pThis->pNext){
127468 while( (pNext = pThis->pNext)!=0 && pNext->onError!=OE_Replace ){
127482 || pThis->pNext==0
127497 ** aiRowEst[0] is supposed to contain the number of elements in the index.
127537 if( pIdx->pPartIdxWhere!=0 ){ x -= 10; assert( 10==sqlite3LogEst(2) ); }
127538 a[0] = x;
127547 assert( 0==sqlite3LogEst(1) );
127548 if( IsUniqueIndex(pIdx) ) a[pIdx->nKeyCol] = 0;
127564 assert( pParse->nErr==0 ); /* Never called with prior non-OOM errors */
127566 assert( pName->a[0].fg.fixedSchema==0 );
127567 assert( pName->a[0].fg.isSubquery==0 );
127571 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].u4.zDatabase);
127572 if( pIndex==0 ){
127576 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].u4.zDatabase);
127584 "or PRIMARY KEY constraint cannot be dropped", 0);
127594 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
127615 sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
127648 if( (n & (n-1))==0 ){
127649 sqlite3_int64 sz = (n==0) ? 1 : 2*n;
127651 if( pNew==0 ){
127658 memset(&z[n * szEntry], 0, szEntry);
127672 if( pList==0 ){
127674 if( pList==0 ) return 0;
127678 if( pNew==0 ){
127680 return 0;
127697 assert( db!=0 );
127698 if( pList==0 ) return;
127699 for(i=0; i<pList->nId; i++){
127711 assert( pList!=0 );
127712 for(i=0; i<pList->nId; i++){
127713 if( sqlite3StrICmp(pList->a[i].zName, zName)==0 ) return i;
127743 ** the iStart value would be 0. The result then would
127759 assert( iStart>=0 );
127761 assert( pSrc!=0 );
127773 return 0;
127777 if( pNew==0 ){
127779 return 0;
127793 memset(&pSrc->a[iStart], 0, sizeof(pSrc->a[0])*nExtra);
127823 ** sqlite3SrcListAppend(D,A,B,0);
127833 ** sqlite3SrcListAppend(D,A,0,C);
127846 assert( pDatabase==0 || pTable!=0 ); /* Cannot have C without B */
127847 assert( pParse!=0 );
127848 assert( pParse->db!=0 );
127850 if( pList==0 ){
127852 if( pList==0 ) return 0;
127855 memset(&pList->a[0], 0, sizeof(pList->a[0]));
127856 pList->a[0].iCursor = -1;
127859 if( pNew==0 ){
127861 return 0;
127867 if( pDatabase && pDatabase->z==0 ){
127868 pDatabase = 0;
127870 assert( pItem->fg.fixedSchema==0 );
127871 assert( pItem->fg.isSubquery==0 );
127877 pItem->u4.zDatabase = 0;
127890 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
127891 if( pItem->iCursor>=0 ) continue;
127894 assert( pItem->u4.pSubq!=0 );
127895 assert( pItem->u4.pSubq->pSelect!=0 );
127896 assert( pItem->u4.pSubq->pSelect->pSrc!=0 );
127907 assert( pSubq!=0 && pSubq->pSelect!=0 );
127918 assert( pItem!=0 );
127922 pItem->u4.pSubq = 0;
127923 pItem->fg.isSubquery = 0;
127933 assert( db!=0 );
127934 if( pList==0 ) return;
127935 for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
127941 assert( !pItem->fg.isSubquery || (pItem->u4.pSubq!=0 &&
127942 pItem->u4.pSubq->pSelect!=0) );
127948 }else if( pItem->fg.fixedSchema==0 && pItem->u4.zDatabase!=0 ){
127985 assert( pSelect!=0 );
127986 assert( pItem->fg.isSubquery==0 );
127988 pItem->u4.pSchema = 0;
127989 pItem->fg.fixedSchema = 0;
127990 }else if( pItem->u4.zDatabase!=0 ){
127992 pItem->u4.zDatabase = 0;
127995 pSelect = sqlite3SelectDup(pParse->db, pSelect, 0);
127996 if( pSelect==0 ) return 0;
127999 if( p==0 ){
128001 return 0;
128005 assert( offsetof(Subquery, pSelect)==0 );
128006 memset(((char*)p)+sizeof(p->pSelect), 0, sizeof(*p)-sizeof(p->pSelect));
128038 if( !p && pOnUsing!=0 && (pOnUsing->pOn || pOnUsing->pUsing) ){
128045 if( p==0 ){
128048 assert( p->nSrc>0 );
128050 assert( (pTable==0)==(pDatabase==0) );
128051 assert( pItem->zName==0 || pDatabase!=0 );
128056 assert( pAlias!=0 );
128060 assert( pSubquery==0 || pDatabase==0 );
128062 if( sqlite3SrcItemAttachSubquery(pParse, pItem, pSubquery, 0) ){
128068 assert( pOnUsing==0 || pOnUsing->pOn==0 || pOnUsing->pUsing==0 );
128069 assert( pItem->fg.isUsing==0 );
128070 if( pOnUsing==0 ){
128071 pItem->u3.pOn = 0;
128081 assert( p==0 );
128084 return 0;
128092 assert( pIndexedBy!=0 );
128093 if( p && pIndexedBy->n>0 ){
128095 assert( p->nSrc>0 );
128097 assert( pItem->fg.notIndexed==0 );
128098 assert( pItem->fg.isIndexedBy==0 );
128099 assert( pItem->fg.isTabFunc==0 );
128107 assert( pItem->fg.isCte==0 ); /* No collision on union u2 */
128121 if( pNew==0 ){
128127 p1->a[0].fg.jointype |= (JT_LTORJ & p1->a[1].fg.jointype);
128140 assert( pItem->fg.notIndexed==0 );
128141 assert( pItem->fg.isIndexedBy==0 );
128142 assert( pItem->fg.isTabFunc==0 );
128162 ** in p->a[0] and p->a[1], respectively. The parser initially stores the
128176 u8 allFlags = 0;
128179 }while( (--i)>0 );
128180 p->a[0].fg.jointype = 0;
128185 for(i=p->nSrc-1; ALWAYS(i>0) && (p->a[i].fg.jointype&JT_RIGHT)==0; i--){}
128187 assert( i>=0 );
128190 }while( (--i)>=0 );
128203 assert( pParse!=0 );
128205 assert( db!=0 );
128206 if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "BEGIN", 0, 0) ){
128212 for(i=0; i<db->nDb; i++){
128216 eTxnType = 0; /* Read txn */
128238 assert( pParse!=0 );
128239 assert( pParse->db!=0 );
128243 isRollback ? "ROLLBACK" : "COMMIT", 0, 0) ){
128264 if( !v || sqlite3AuthCheck(pParse, SQLITE_SAVEPOINT, az[op], zName, 0) ){
128268 sqlite3VdbeAddOp4(v, OP_Savepoint, op, 0, 0, zName, P4_DYNAMIC);
128278 if( db->aDb[1].pBt==0 && !pParse->explain ){
128288 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
128297 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, 0, 0) ){
128302 return 0;
128312 assert( iDb>=0 && iDb<pToplevel->db->nDb );
128313 assert( pToplevel->db->aDb[iDb].pBt!=0 || iDb==1 );
128315 assert( sqlite3SchemaMutexHeld(pToplevel->db, iDb, 0) );
128316 if( DbMaskTest(pToplevel->cookieMask, iDb)==0 ){
128335 for(i=0; i<db->nDb; i++){
128337 if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zDbSName)) ){
128410 assert( pParse->pVdbe!=0 );
128412 assert( (errCode&0xff)==SQLITE_CONSTRAINT || pParse->nested );
128416 sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type);
128433 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0,
128438 for(j=0; j<pIdx->nKeyCol; j++){
128440 assert( pIdx->aiColumn[j]>=0 );
128466 if( pTab->iPKey>=0 ){
128485 assert( zColl!=0 );
128486 for(i=0; i<pIndex->nColumn; i++){
128488 assert( z!=0 || pIndex->aiColumn[i]<0 );
128489 if( pIndex->aiColumn[i]>=0 && 0==sqlite3StrICmp(z, zColl) ){
128493 return 0;
128499 ** If pColl==0 then recompute all indices of pTab.
128507 if( zColl==0 || collationMatch(zColl, pIndex) ){
128509 sqlite3BeginWriteOperation(pParse, 0, iDb);
128519 ** indices use the collating sequence pColl. If pColl==0 then recompute
128531 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
128532 assert( pDb!=0 );
128571 if( pName1==0 ){
128572 reindexDatabases(pParse, 0);
128574 }else if( NEVER(pName2==0) || pName2->z==0 ){
128579 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
128588 if( iDb<0 ) return;
128590 if( z==0 ) return;
128591 zDb = pName2->n ? db->aDb[iDb].zDbSName : 0;
128594 reindexTable(pParse, pTab, 0);
128602 sqlite3BeginWriteOperation(pParse, 0, iDb);
128621 if( pParse->nErr ) return 0;
128625 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
128629 for(i=0; i<nCol; i++){
128631 pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
128634 assert( 0==(pKey->aSortFlags[i] & KEYINFO_ORDER_BIGNULL) );
128638 if( pIdx->bNoQuery==0 ){
128650 pKey = 0;
128671 assert( pNew!=0 || db->mallocFailed );
128690 assert( pCte!=0 );
128700 assert( pCte!=0 );
128720 if( pCte==0 ){
128729 for(i=0; i<pWith->nCte; i++){
128730 if( sqlite3StrICmp(zName, pWith->a[i].zName)==0 ){
128741 assert( (pNew!=0 && zName!=0) || db->mallocFailed );
128760 for(i=0; i<pWith->nCte; i++){
128829 for(i=0; i<3; i++){
128830 pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, 0);
128831 if( pColl2->xCmp!=0 ){
128833 pColl->xDel = 0; /* Do not copy the destructor */
128852 if( pColl && pColl->xCmp==0 ){
128887 if( 0==pColl && create ){
128891 CollSeq *pDel = 0;
128892 pColl[0].zName = (char*)&pColl[3];
128893 pColl[0].enc = SQLITE_UTF8;
128898 memcpy(pColl[0].zName, zName, nName);
128899 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, pColl);
128905 assert( pDel==0 || pDel==pColl );
128906 if( pDel!=0 ){
128909 pColl = 0;
128959 db->pDfltColl = sqlite3FindCollSeq(db, enc, sqlite3StrBINARY, 0);
128988 p = sqlite3FindCollSeq(db, enc, zName, 0);
128995 p = sqlite3FindCollSeq(db, enc, zName, 0);
128998 p = 0;
129001 if( p==0 ){
129056 ** The returned value is always between 0 and 6, as follows:
129058 ** 0: Not a match.
129082 if( nArg==(-2) ) return p->xSFunc==0 ? 0 : FUNC_PERFECT_MATCH;
129083 if( p->nArg>=0 ) return 0;
129088 if( p->nArg<(-2) && nArg<(-2-p->nArg) ) return 0;
129102 }else if( (enc & p->funcFlags & 2)!=0 ){
129111 ** a pointer to the matching FuncDef if found, or 0 if there is no match.
129120 if( sqlite3StrICmp(p->zName, zFunc)==0 ){
129124 return 0;
129135 for(i=0; i<nDef; i++){
129139 int h = SQLITE_FUNC_HASH(zName[0], nName);
129147 aDef[i].pNext = 0;
129169 ** of arguments. If nArg is -2, then createFlag must be 0.
129183 FuncDef *pBest = 0; /* Best match found so far */
129184 int bestScore = 0; /* Score of best match */
129189 assert( nArg>=(-1) || createFlag==0 );
129216 if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){
129217 bestScore = 0;
129218 h = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zName[0]], nName);
129235 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
129247 return 0;
129256 return 0;
129274 memset(&xdb, 0, sizeof(xdb));
129290 pSchema->pSeqTab = 0;
129306 p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema));
129310 }else if ( 0==p->file_format ){
129348 ** pSrc->a[0].spTab Pointer to the Table object
129349 ** pSrc->a[0].u2.pIBIndex Pointer to the INDEXED BY index, if there is one
129356 pTab = sqlite3LocateTableItem(pParse, 0, pItem);
129363 pTab = 0;
129376 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zColName, SQLITE_STATIC);
129400 if( sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 ){
129410 if( pParse->pToplevel!=0
129412 ((pParse->db->flags & SQLITE_TrustedSchema)!=0)
129417 return 0;
129424 if( (pTab->tabFlags & (TF_Readonly|TF_Shadow))==0 ) return 0;
129426 if( (pTab->tabFlags & TF_Readonly)!=0 ){
129427 return sqlite3WritableSchema(db)==0 && pParse->nested==0;
129438 ** If pTab is writable and no prior errors -> return 0;
129447 && (pTrigger==0 || (pTrigger->bReturning && pTrigger->pNext==0))
129453 return 0;
129476 pWhere = sqlite3ExprDup(db, pWhere, 0);
129477 pFrom = sqlite3SrcListAppend(pParse, 0, 0, 0);
129480 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
129481 assert( pFrom->a[0].fg.fixedSchema==0 && pFrom->a[0].fg.isSubquery==0 );
129482 pFrom->a[0].u4.zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
129483 assert( pFrom->a[0].fg.isUsing==0 );
129484 assert( pFrom->a[0].u3.pOn==0 );
129486 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy,
129521 if( pOrderBy && pLimit==0 ) {
129525 return 0;
129531 if( pLimit == 0 ) {
129544 pTab = pSrc->a[0].pSTab;
129546 pLhs = sqlite3PExpr(pParse, TK_ROW, 0, 0);
129548 pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0)
129552 assert( pPk!=0 );
129556 assert( pPk->aiColumn[0]>=0 && pPk->aiColumn[0]<pTab->nCol );
129557 zName = pTab->aCol[pPk->aiColumn[0]].zCnName;
129559 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName));
129562 for(i=0; i<pPk->nKeyCol; i++){
129564 assert( pPk->aiColumn[i]>=0 && pPk->aiColumn[i]<pTab->nCol );
129568 pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
129570 pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0);
129577 pSrc->a[0].pSTab = 0;
129578 pSelectSrc = sqlite3SrcListDup(db, pSrc, 0);
129579 pSrc->a[0].pSTab = pTab;
129580 if( pSrc->a[0].fg.isIndexedBy ){
129581 assert( pSrc->a[0].fg.isCte==0 );
129582 pSrc->a[0].u2.pIBIndex = 0;
129583 pSrc->a[0].fg.isIndexedBy = 0;
129584 sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy);
129585 }else if( pSrc->a[0].fg.isCte ){
129586 pSrc->a[0].u2.pCteUse->nUse++;
129590 pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
129591 pOrderBy,0,pLimit
129595 pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0);
129622 int iDataCur = 0; /* VDBE cursor for the canonical data source */
129623 int iIdxCur = 0; /* Cursor number of the first index */
129629 int memCnt = 0; /* Memory cell used for change counting */
129633 u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */
129635 int iPk = 0; /* First of nPk registers holding PRIMARY KEY value */
129639 int iEphCur = 0; /* Ephemeral table holding all primary key values */
129640 int iRowSet = 0; /* Register for rowset of rows to delete */
129641 int addrBypass = 0; /* Address of jump over the delete logic */
129642 int addrLoop = 0; /* Top of the delete loop */
129643 int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
129652 memset(&sContext, 0, sizeof(sContext));
129658 assert( db->mallocFailed==0 );
129667 if( pTab==0 ) goto delete_from_cleanup;
129673 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
129676 # define pTrigger 0
129677 # define isView 0
129679 bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
129682 # define isView 0
129686 if( sqlite3TreeTrace & 0x10000 ){
129687 sqlite3TreeViewLine(0, "In sqlite3Delete() at %s:%d", __FILE__, __LINE__);
129698 pOrderBy = 0;
129699 pLimit = 0;
129714 rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0,
129725 iTabCur = pTabList->a[0].iCursor = pParse->nTab++;
129726 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
129739 if( v==0 ){
129742 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
129754 pOrderBy = 0;
129755 pLimit = 0;
129761 memset(&sNC, 0, sizeof(sNC));
129771 if( (db->flags & SQLITE_CountRows)!=0
129777 sqlite3VdbeAddOp2(v, OP_Integer, 0, memCnt);
129793 && pWhere==0
129797 && db->xPreUpdateCallback==0
129819 wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
129822 pPk = 0;
129825 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
129830 assert( pPk!=0 );
129847 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,0,wcf,iTabCur+1);
129848 if( pWInfo==0 ) goto delete_from_cleanup;
129850 assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI );
129865 for(i=0; i<nPk; i++){
129866 assert( pPk->aiColumn[i]>=0 );
129882 if( aToOpen==0 ){
129887 aToOpen[nIdx+1] = 0;
129888 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
129889 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
129896 nKey = 0; /* Zero tells OP_Found to use a composite key */
129914 int iAddrOnce = 0;
129934 assert( pPk!=0 || IsView(pTab) );
129941 sqlite3VdbeAddOp3(v, OP_Column, iEphCur, 0, iKey);
129945 assert( nKey==0 ); /* OP_Found will use a composite key */
129947 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
129962 pParse->isMultiWrite = 0;
129965 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iKey, pVTab, P4_VTAB);
129970 int count = (pParse->nested==0); /* True to count changes */
129992 if( pParse->nested==0 && pParse->pTriggerTab==0 ){
130041 ** sequence of nPk memory cells starting at iPk. If nPk==0 that means
130046 ** Parameter eMode may be passed either ONEPASS_OFF (0), ONEPASS_SINGLE, or
130054 ** iIdxNoSeek is a valid cursor number (>=0) and is not the same as
130060 ** If iIdxNoSeek is a valid cursor number (>=0) not equal to iDataCur,
130080 int iOld = 0; /* First register in OLD.* array */
130102 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
130110 pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf
130119 for(iCol=0; iCol<pTab->nCol; iCol++){
130120 testcase( mask!=0xffffffff && iCol==31 );
130121 testcase( mask!=0xffffffff && iCol==32 );
130122 if( mask==0xffffffff || (iCol<=31 && (mask & MASKBIT32(iCol))!=0) ){
130131 TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
130146 testcase( iIdxNoSeek>=0 );
130153 sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
130167 u8 p5 = 0;
130168 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
130169 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
130170 if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){
130176 if( iIdxNoSeek>=0 && iIdxNoSeek!=iDataCur ){
130186 sqlite3FkActions(pParse, pTab, 0, iOld, 0, 0);
130191 TK_DELETE, 0, TRIGGER_AFTER, pTab, iOld, onconf, iLabel
130215 ** index is the 0-th index.)
130225 int *aRegIdx, /* Only delete if aRegIdx!=0 && aRegIdx[i]>0 */
130232 Index *pPrior = 0; /* Prior index */
130237 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
130238 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
130240 if( aRegIdx!=0 && aRegIdx[i]==0 ) continue;
130244 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1,
130289 int regOut, /* Put the new key into this register if not 0 */
130306 pParse->iSelfTab = 0;
130307 pPrior = 0; /* Ticket a9efb42811fa41ee 2019-11-02;
130310 *piPartIdxLabel = 0;
130315 if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;
130316 for(j=0; j<nCol; j++){
130325 if( pIdx->aiColumn[j]>=0 ){
130383 assert( context->pVdbe!=0 );
130395 assert( context->isError<=0 );
130409 int mask; /* 0 for min() or 0xffffffff for max() */
130414 mask = sqlite3_user_data(context)==0 ? 0 : -1;
130417 assert( mask==-1 || mask==0 );
130418 iBest = 0;
130419 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
130422 if( (sqlite3MemCompare(argv[iBest], argv[i], pColl)^mask)>=0 ){
130423 testcase( mask==0 );
130439 int i = sqlite3_value_type(argv[0]) - 1;
130441 assert( i>=0 && i<ArraySize(azType) );
130464 sqlite3_result_int(context, sqlite3_value_subtype(argv[0]));
130477 switch( sqlite3_value_type(argv[0]) ){
130481 sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
130485 const unsigned char *z = sqlite3_value_text(argv[0]);
130488 if( z==0 ) return;
130490 while( (c = *z)!=0 ){
130492 if( c>=0xc0 ){
130493 while( (*z & 0xc0)==0x80 ){ z++; z0++; }
130516 switch( sqlite3_value_type(argv[0]) ){
130518 sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
130524 sqlite3_result_int64(context, sqlite3_value_bytes(argv[0])*m);
130528 if( sqlite3_value_encoding(argv[0])<=SQLITE_UTF8 ){
130529 sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
130531 sqlite3_result_int(context, sqlite3_value_bytes16(argv[0]));
130551 switch( sqlite3_value_type(argv[0]) ){
130553 i64 iVal = sqlite3_value_int64(argv[0]);
130554 if( iVal<0 ){
130578 double rVal = sqlite3_value_double(argv[0]);
130579 if( rVal<0 ) rVal = -rVal;
130591 ** or 0 if needle does not occur within haystack.
130595 ** or 0 if needle never occurs in haystack.
130610 sqlite3_value *pC1 = 0;
130611 sqlite3_value *pC2 = 0;
130614 typeHaystack = sqlite3_value_type(argv[0]);
130617 nHaystack = sqlite3_value_bytes(argv[0]);
130619 if( nNeedle>0 ){
130621 zHaystack = sqlite3_value_blob(argv[0]);
130623 isText = 0;
130625 zHaystack = sqlite3_value_text(argv[0]);
130629 pC1 = sqlite3_value_dup(argv[0]);
130631 if( zHaystack==0 ) goto endInstrOOM;
130635 if( zNeedle==0 ) goto endInstrOOM;
130639 if( zNeedle==0 || (nHaystack && zHaystack==0) ) goto endInstrOOM;
130640 firstChar = zNeedle[0];
130642 && (zHaystack[0]!=firstChar || memcmp(zHaystack, zNeedle, nNeedle)!=0)
130648 }while( isText && (zHaystack[0]&0xc0)==0x80 );
130650 if( nNeedle>nHaystack ) N = 0;
130676 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
130678 x.nUsed = 0;
130680 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
130713 p0type = sqlite3_value_type(argv[0]);
130716 len = sqlite3_value_bytes(argv[0]);
130717 z = sqlite3_value_blob(argv[0]);
130718 if( z==0 ) return;
130719 assert( len==sqlite3_value_bytes(argv[0]) );
130721 z = sqlite3_value_text(argv[0]);
130722 if( z==0 ) return;
130723 len = 0;
130724 if( p1<0 ){
130732 if( p2==0 && sqlite3_value_type(argv[2])==SQLITE_NULL ) return;
130736 if( p1==0 ){
130738 /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
130747 if( p1<0 ){
130749 if( p1<0 ){
130750 if( p2<0 ){
130751 p2 = 0;
130755 p1 = 0;
130757 }else if( p1>0 ){
130759 }else if( p2>0 ){
130762 if( p2<0 ){
130770 assert( p1>=0 && p2>=0 );
130783 p1 = p2 = 0;
130786 assert( p2>0 );
130797 i64 n = 0;
130805 if( n<0 ) n = 0;
130807 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
130808 r = sqlite3_value_double(argv[0]);
130809 /* If Y==0 and X will fit in a 64-bit int,
130815 }else if( n==0 ){
130816 r = (double)((sqlite_int64)(r+(r<0?-0.5:+0.5)));
130819 if( zBuf==0 ){
130840 assert( nByte>0 );
130845 z = 0;
130863 z2 = (char*)sqlite3_value_text(argv[0]);
130864 n = sqlite3_value_bytes(argv[0]);
130866 assert( z2==(char*)sqlite3_value_text(argv[0]) );
130870 for(i=0; i<n; i++){
130882 z2 = (char*)sqlite3_value_text(argv[0]);
130883 n = sqlite3_value_bytes(argv[0]);
130885 assert( z2==(char*)sqlite3_value_text(argv[0]) );
130889 for(i=0; i<n; i++){
130918 if( r<0 ){
130919 /* We need to prevent a random number of 0x8000000000000000
130945 n = sqlite3_value_int64(argv[0]);
131012 u8 matchSet; /* "[" or 0 */
131026 # define Utf8Read(A) (A[0]<0x80?*(A++):sqlite3Utf8Read(&A))
131029 static const struct compareInfo globInfo = { '*', '?', '[', 0 };
131032 static const struct compareInfo likeInfoNorm = { '%', '_', 0, 1 };
131035 static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
131040 #define SQLITE_MATCH 0
131092 const u8 *zEscaped = 0; /* One past the last escaped input char */
131094 while( (c = Utf8Read(zPattern))!=0 ){
131100 || (c == matchOne && matchOne!=0) ){
131101 if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
131105 if( c==0 ){
131108 if( pInfo->matchSet==0 ){
131110 if( c==0 ) return SQLITE_NOWILDCARDMATCH;
131114 assert( matchOther<0x80 ); /* '[' is a single-byte character */
131133 if( c<0x80 ){
131137 zStop[0] = sqlite3Toupper(c);
131139 zStop[2] = 0;
131141 zStop[0] = c;
131142 zStop[1] = 0;
131146 if( zString[0]==0 ) break;
131153 while( (c2 = Utf8Read(zString))!=0 ){
131162 if( pInfo->matchSet==0 ){
131164 if( c==0 ) return SQLITE_NOMATCH;
131167 u32 prior_c = 0;
131168 int seen = 0;
131169 int invert = 0;
131171 if( c==0 ) return SQLITE_NOMATCH;
131182 if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
131185 prior_c = 0;
131194 if( c2==0 || (seen ^ invert)==0 ){
131202 if( noCase && sqlite3Tolower(c)==sqlite3Tolower(c2) && c<0x80 && c2<0x80 ){
131205 if( c==matchOne && zPattern!=zEscaped && c2!=0 ) continue;
131208 return *zString==0 ? SQLITE_MATCH : SQLITE_NOMATCH;
131212 ** The sqlite3_strglob() interface. Return 0 on a match (like strcmp()) and
131216 if( zString==0 ){
131217 return zGlobPattern!=0;
131218 }else if( zGlobPattern==0 ){
131226 ** The sqlite3_strlike() interface. Return 0 on a match and non-zero for
131230 if( zStr==0 ){
131231 return zPattern!=0;
131232 }else if( zPattern==0 ){
131245 SQLITE_API int sqlite3_like_count = 0;
131274 if( sqlite3_value_type(argv[0])==SQLITE_BLOB
131280 sqlite3_result_int(context, 0);
131288 nPat = sqlite3_value_bytes(argv[0]);
131300 if( zEsc==0 ) return;
131310 if( escape==pInfo->matchAll ) pInfo->matchAll = 0;
131311 if( escape==pInfo->matchOne ) pInfo->matchOne = 0;
131316 zB = sqlite3_value_text(argv[0]);
131339 if( sqlite3MemCompare(argv[0], argv[1], pColl)!=0 ){
131340 sqlite3_result_value(context, argv[0]);
131387 sqlite3_log(sqlite3_value_int(argv[0]), "%s", sqlite3_value_text(argv[1]));
131408 if( (zOptName = (const char*)sqlite3_value_text(argv[0]))!=0 ){
131431 n = sqlite3_value_int(argv[0]);
131439 '0', '1', '2', '3', '4', '5', '6', '7',
131451 assert( pStr!=0 && pStr->nChar==0 );
131478 if( pStr->accError==0 ){
131481 for(i=0; i<nBlob; i++){
131482 zText[(i*2)+2] = hexdigits[(zBlob[i]>>4)&0x0F];
131483 zText[(i*2)+3] = hexdigits[(zBlob[i])&0x0F];
131486 zText[(nBlob*2)+3] = '\0';
131487 zText[0] = 'X';
131513 int v = 0;
131514 for(i=0; i<N; i++){
131515 if( !sqlite3Isxdigit(z[i]) ) return 0;
131548 zIn = (const char*)sqlite3_value_text(argv[0]);
131549 if( zIn==0 ) return;
131550 nIn = sqlite3_value_bytes(argv[0]);
131552 if( zOut==0 ){
131556 i = j = 0;
131559 if( z==0 ){
131566 if( n>0 ){
131594 zOut[j] = 0;
131624 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
131625 sqlite3QuoteValue(&str,argv[0],SQLITE_PTR_TO_INT(sqlite3_user_data(context)));
131643 const unsigned char *z = sqlite3_value_text(argv[0]);
131645 if( z && z[0] ) sqlite3_result_int(context, sqlite3Utf8Read(&z));
131661 if( z==0 ){
131665 for(i=0; i<argc; i++){
131669 if( x<0 || x>0x10ffff ) x = 0xfffd;
131670 c = (unsigned)(x & 0x1fffff);
131671 if( c<0x00080 ){
131672 *zOut++ = (u8)(c&0xFF);
131673 }else if( c<0x00800 ){
131674 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F);
131675 *zOut++ = 0x80 + (u8)(c & 0x3F);
131676 }else if( c<0x10000 ){
131677 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F);
131678 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F);
131679 *zOut++ = 0x80 + (u8)(c & 0x3F);
131681 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07);
131682 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F);
131683 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F);
131684 *zOut++ = 0x80 + (u8)(c & 0x3F);
131687 *zOut = 0;
131705 pBlob = sqlite3_value_blob(argv[0]);
131706 n = sqlite3_value_bytes(argv[0]);
131707 assert( pBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
131710 for(i=0; i<n; i++, pBlob++){
131712 *(z++) = hexdigits[(c>>4)&0xf];
131713 *(z++) = hexdigits[c&0xf];
131715 *z = 0;
131723 ** contains character ch, or 0 if it does not.
131732 return 0;
131763 int nPass = 0;
131764 const u8 *zHex = sqlite3_value_text(argv[0]);
131765 int nHex = sqlite3_value_bytes(argv[0]);
131767 const u8 *zEnd = zHex ? &zHex[nHex] : 0;
131769 u8 *pBlob = 0;
131770 u8 *p = 0;
131784 while( (c = *zHex)!=0x00 ){
131790 if( c==0x00 ) goto unhex_done;
131793 assert( *zEnd==0x00 );
131823 n = sqlite3_value_int64(argv[0]);
131824 if( n<0 ) n = 0;
131857 zStr = sqlite3_value_text(argv[0]);
131858 if( zStr==0 ) return;
131859 nStr = sqlite3_value_bytes(argv[0]);
131860 assert( zStr==sqlite3_value_text(argv[0]) ); /* No encoding change */
131862 if( zPattern==0 ){
131867 if( zPattern[0]==0 ){
131875 if( zRep==0 ) return;
131881 if( zOut==0 ){
131885 cntExpand = 0;
131886 for(i=j=0; i<=loopLimit; i++){
131887 if( zStr[i]!=zPattern[0] || memcmp(&zStr[i], zPattern, nPattern) ){
131900 if( (cntExpand&(cntExpand-1))==0 ){
131906 if( zOut==0 ){
131922 zOut[j] = 0;
131928 ** The userdata is 0x1 for left trim, 0x2 for right trim, 0x3 for both.
131940 unsigned int *aLen = 0; /* Length of each character in zCharSet */
131941 unsigned char **azChar = 0; /* Individual characters in zCharSet */
131944 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
131947 zIn = sqlite3_value_text(argv[0]);
131948 if( zIn==0 ) return;
131949 nIn = (unsigned)sqlite3_value_bytes(argv[0]);
131950 assert( zIn==sqlite3_value_text(argv[0]) );
131957 zCharSet = 0;
131958 }else if( (zCharSet = sqlite3_value_text(argv[1]))==0 ){
131962 for(z=zCharSet, nChar=0; *z; nChar++){
131965 if( nChar>0 ){
131968 if( azChar==0 ){
131972 for(z=zCharSet, nChar=0; *z; nChar++){
131979 if( nChar>0 ){
131982 while( nIn>0 ){
131983 unsigned int len = 0;
131984 for(i=0; i<nChar; i++){
131986 if( len<=nIn && memcmp(zIn, azChar[i], len)==0 ) break;
131994 while( nIn>0 ){
131995 unsigned int len = 0;
131996 for(i=0; i<nChar; i++){
131998 if( len<=nIn && memcmp(&zIn[nIn-len],azChar[i],len)==0 ) break;
132024 i64 j, n = 0;
132027 for(i=0; i<argc; i++){
132032 if( z==0 ){
132036 j = 0;
132037 for(i=0; i<argc; i++){
132041 if( v!=0 ){
132042 if( j>0 && nSep>0 ){
132051 z[j] = 0;
132065 concatFuncCore(context, argc, argv, 0, "");
132080 int nSep = sqlite3_value_bytes(argv[0]);
132081 const char *zSep = (const char*)sqlite3_value_text(argv[0]);
132082 if( zSep==0 ) return;
132130 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132131 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132132 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132133 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132134 0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
132135 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
132136 0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
132137 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
132140 zIn = (u8*)sqlite3_value_text(argv[0]);
132141 if( zIn==0 ) zIn = (u8*)"";
132142 for(i=0; zIn[i] && !sqlite3Isalpha(zIn[i]); i++){}
132144 u8 prevcode = iCode[zIn[i]&0x7f];
132145 zResult[0] = sqlite3Toupper(zIn[i]);
132147 int code = iCode[zIn[i]&0x7f];
132148 if( code>0 ){
132151 zResult[j++] = code + '0';
132154 prevcode = 0;
132158 zResult[j++] = '0';
132160 zResult[j] = 0;
132175 const char *zFile = (const char *)sqlite3_value_text(argv[0]);
132178 char *zErrMsg = 0;
132183 if( (db->flags & SQLITE_LoadExtFunc)==0 ){
132191 zProc = 0;
132285 type = sqlite3_value_numeric_type(argv[0]);
132288 if( p->approx==0 ){
132292 kahanBabuskaNeumaierStep(p, sqlite3_value_double(argv[0]));
132295 if( sqlite3AddInt64(&x, sqlite3_value_int64(argv[0]))==0 ){
132301 kahanBabuskaNeumaierStepInt64(p, sqlite3_value_int64(argv[0]));
132306 kahanBabuskaNeumaierStepInt64(p, sqlite3_value_int64(argv[0]));
132308 p->ovrfl = 0;
132309 kahanBabuskaNeumaierStep(p, sqlite3_value_double(argv[0]));
132321 type = sqlite3_value_numeric_type(argv[0]);
132325 assert( p->cnt>0 );
132328 if( sqlite3SubInt64(&p->iSum, sqlite3_value_int64(argv[0])) ){
132333 i64 iVal = sqlite3_value_int64(argv[0]);
132341 kahanBabuskaNeumaierStep(p, -sqlite3_value_double(argv[0]));
132346 # define sumInverse 0
132350 p = sqlite3_aggregate_context(context, 0);
132351 if( p && p->cnt>0 ){
132367 p = sqlite3_aggregate_context(context, 0);
132368 if( p && p->cnt>0 ){
132382 p = sqlite3_aggregate_context(context, 0);
132412 if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && p ){
132421 assert( argc==1 || p==0 || p->n>0x7fffffff || p->bInverse
132427 p = sqlite3_aggregate_context(context, 0);
132428 sqlite3_result_int64(context, p ? p->n : 0);
132435 if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && ALWAYS(p) ){
132443 # define countInverse 0
132454 Mem *pArg = (Mem *)argv[0];
132473 ** aggregate, or 0 for min().
132475 max = sqlite3_user_data(context)!=0;
132477 if( (max && cmp<0) || (!max && cmp>0) ){
132489 pRes = (sqlite3_value *)sqlite3_aggregate_context(context, 0);
132494 if( bValue==0 ) sqlite3VdbeMemRelease(pRes);
132502 # define minMaxValue 0
132505 minMaxValueFinalize(context, 0);
132527 /* If pnSepLengths!=0, refs an array of inter-string separator lengths,
132530 ** If pnSepLengths==0, nFirstSepLength is the length used throughout.
132546 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
132550 int firstTerm = pGCC->str.mxAlloc==0;
132569 nSep = 0;
132571 if( nSep != pGCC->nFirstSepLength || pGCC->pnSepLengths != 0 ){
132573 if( pnsl == 0 ){
132576 if( pnsl!=0 ){
132577 int i = 0, nA = pGCC->nAccum-1;
132583 if( pnsl!=0 ){
132584 if( ALWAYS(pGCC->nAccum>0) ){
132600 zVal = (char*)sqlite3_value_text(argv[0]);
132601 nVal = sqlite3_value_bytes(argv[0]);
132615 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
132623 (void)sqlite3_value_text(argv[0]);
132624 nVS = sqlite3_value_bytes(argv[0]);
132626 if( pGCC->pnSepLengths!=0 ){
132627 assert(pGCC->nAccum >= 0);
132628 if( pGCC->nAccum>0 ){
132638 pGCC->str.nChar = 0;
132643 if( pGCC->str.nChar==0 ){
132644 pGCC->str.mxAlloc = 0;
132646 pGCC->pnSepLengths = 0;
132651 # define groupConcatInverse 0
132655 = (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
132666 = (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
132673 }else if( pGCC->nAccum>0 && pAccum->nChar==0 ){
132682 # define groupConcatValue 0
132717 0, 0, 0, 0, 0);
132718 pDef = sqlite3FindFunction(db, "like", nArg, SQLITE_UTF8, 0);
132727 ** then set aWc[0] through aWc[2] to the wildcard characters and the
132744 assert( pExpr!=0 );
132748 return 0;
132752 pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0);
132754 if( pDef==0 ) return 0;
132756 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
132757 return 0;
132770 aWc[3] = 0;
132774 if( pEscape->op!=TK_STRING ) return 0;
132777 if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
132778 if( zEscape[0]==aWc[0] ) return 0;
132779 if( zEscape[0]==aWc[1] ) return 0;
132780 aWc[3] = zEscape[0];
132783 *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0;
132818 switch( sqlite3_value_numeric_type(argv[0]) ){
132820 sqlite3_result_int64(context, sqlite3_value_int64(argv[0]));
132825 sqlite3_result_double(context, x(sqlite3_value_double(argv[0])));
132846 #if defined(HAVE_LOG10) && HAVE_LOG10==0
132849 #if defined(HAVE_LOG2) && HAVE_LOG2==0
132869 switch( sqlite3_value_numeric_type(argv[0]) ){
132872 x = sqlite3_value_double(argv[0]);
132879 switch( sqlite3_value_numeric_type(argv[0]) ){
132927 type0 = sqlite3_value_numeric_type(argv[0]);
132929 v0 = sqlite3_value_double(argv[0]);
132949 type0 = sqlite3_value_numeric_type(argv[0]);
132953 v0 = sqlite3_value_double(argv[0]);
132961 ** Implementation of 0-argument pi() function.
132968 assert( argc==0 );
132987 type0 = sqlite3_value_numeric_type(argv[0]);
132989 x = sqlite3_value_double(argv[0]);
132990 sqlite3_result_int(context, x<0.0 ? -1 : x>0.0 ? +1 : 0);
133017 x = sqlite3_value_double(argv[0]);
133020 if( z<=0 ) z = 1;
133060 sqlite3_vfs *pVfs = 0;
133061 char *zFile = 0;
133062 char *zErr = 0;
133065 pVfs = sqlite3_vfs_find(0);
133068 zUri = (const char*)sqlite3_value_text(argv[0]);
133069 if( zUri==0 ) return;
133072 pResult = sqlite3_str_new(0);
133076 sqlite3_str_appendf(pResult, ", flags=0x%x", flgs);
133077 sqlite3_str_appendf(pResult, ", vfs=%Q", pVfs ? pVfs->zName: 0);
133083 while( z[0] ){
133092 }else if( (zArg = (const char*)sqlite3_value_text(argv[i]))!=0 ){
133128 TEST_FUNC(implies_nonnull_row, 2, INLINEFUNC_implies_nonnull_row, 0),
133129 TEST_FUNC(expr_compare, 2, INLINEFUNC_expr_compare, 0),
133130 TEST_FUNC(expr_implies_expr, 2, INLINEFUNC_expr_implies_expr, 0),
133131 TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0),
133135 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
133138 SFUNCTION(load_extension, 1, 0, 0, loadExt ),
133139 SFUNCTION(load_extension, 2, 0, 0, loadExt ),
133142 DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
133143 DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
133149 INLINE_FUNC(sqlite_offset, 1, INLINEFUNC_sqlite_offset, 0 ),
133151 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
133152 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
133153 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
133154 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
133155 FUNCTION(trim, 1, 3, 0, trimFunc ),
133156 FUNCTION(trim, 2, 3, 0, trimFunc ),
133157 FUNCTION(min, -3, 0, 1, minmaxFunc ),
133158 WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
133161 WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
133163 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
133164 FUNCTION2(subtype, 1, 0, 0, subtypeFunc,
133166 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
133167 FUNCTION2(octet_length, 1, 0, 0, bytelengthFunc,SQLITE_FUNC_BYTELEN),
133168 FUNCTION(instr, 2, 0, 0, instrFunc ),
133169 FUNCTION(printf, -1, 0, 0, printfFunc ),
133170 FUNCTION(format, -1, 0, 0, printfFunc ),
133171 FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
133172 FUNCTION(char, -1, 0, 0, charFunc ),
133173 FUNCTION(abs, 1, 0, 0, absFunc ),
133175 FUNCTION(fpdecode, 3, 0, 0, fpdecodeFunc ),
133176 FUNCTION(parseuri, -1, 0, 0, parseuriFunc ),
133179 FUNCTION(round, 1, 0, 0, roundFunc ),
133180 FUNCTION(round, 2, 0, 0, roundFunc ),
133182 FUNCTION(upper, 1, 0, 0, upperFunc ),
133183 FUNCTION(lower, 1, 0, 0, lowerFunc ),
133184 FUNCTION(hex, 1, 0, 0, hexFunc ),
133185 FUNCTION(unhex, 1, 0, 0, unhexFunc ),
133186 FUNCTION(unhex, 2, 0, 0, unhexFunc ),
133187 FUNCTION(concat, -3, 0, 0, concatFunc ),
133188 FUNCTION(concat_ws, -4, 0, 0, concatwsFunc ),
133189 INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, 0 ),
133190 VFUNCTION(random, 0, 0, 0, randomFunc ),
133191 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
133192 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
133193 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
133194 DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
133195 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
133196 FUNCTION(unistr, 1, 0, 0, unistrFunc ),
133197 FUNCTION(quote, 1, 0, 0, quoteFunc ),
133198 FUNCTION(unistr_quote, 1, 1, 0, quoteFunc ),
133199 VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
133200 VFUNCTION(changes, 0, 0, 0, changes ),
133201 VFUNCTION(total_changes, 0, 0, 0, total_changes ),
133202 FUNCTION(replace, 3, 0, 0, replaceFunc ),
133203 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
133204 FUNCTION(substr, 2, 0, 0, substrFunc ),
133205 FUNCTION(substr, 3, 0, 0, substrFunc ),
133206 FUNCTION(substring, 2, 0, 0, substrFunc ),
133207 FUNCTION(substring, 3, 0, 0, substrFunc ),
133208 WAGGREGATE(sum, 1,0,0, sumStep, sumFinalize, sumFinalize, sumInverse, 0),
133209 WAGGREGATE(total, 1,0,0, sumStep,totalFinalize,totalFinalize,sumInverse, 0),
133210 WAGGREGATE(avg, 1,0,0, sumStep, avgFinalize, avgFinalize, sumInverse, 0),
133211 WAGGREGATE(count, 0,0,0, countStep,
133214 WAGGREGATE(count, 1,0,0, countStep,
133216 WAGGREGATE(group_concat, 1, 0, 0, groupConcatStep,
133217 groupConcatFinalize, groupConcatValue, groupConcatInverse, 0),
133218 WAGGREGATE(group_concat, 2, 0, 0, groupConcatStep,
133219 groupConcatFinalize, groupConcatValue, groupConcatInverse, 0),
133220 WAGGREGATE(string_agg, 2, 0, 0, groupConcatStep,
133221 groupConcatFinalize, groupConcatValue, groupConcatInverse, 0),
133232 FUNCTION(unknown, -1, 0, 0, unknownFunc ),
133241 FUNCTION(ln, 1, 0, 0, logFunc ),
133242 FUNCTION(log, 1, 1, 0, logFunc ),
133243 FUNCTION(log10, 1, 1, 0, logFunc ),
133244 FUNCTION(log2, 1, 2, 0, logFunc ),
133245 FUNCTION(log, 2, 0, 0, logFunc ),
133268 MFUNCTION(pi, 0, 0, piFunc ),
133270 FUNCTION(sign, 1, 0, 0, signFunc ),
133271 INLINE_FUNC(coalesce, -4, INLINEFUNC_coalesce, 0 ),
133272 INLINE_FUNC(iif, -4, INLINEFUNC_iif, 0 ),
133273 INLINE_FUNC(if, -4, INLINEFUNC_iif, 0 ),
133283 #if 0 /* Enable to print out how the built-in functions are hashed */
133287 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
133291 int h = p->zName[0] + n;
133492 Index *pIdx = 0; /* Value to return via *ppIdx */
133493 int *aiCol = 0; /* Value to return via *paiCol */
133495 char *zKey = pFKey->aCol[0].zCol; /* Name of left-most parent key column */
133498 assert( ppIdx && *ppIdx==0 );
133499 assert( !paiCol || *paiCol==0 );
133518 if( pParent->iPKey>=0 ){
133519 if( !zKey ) return 0;
133521 return 0;
133532 if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) && pIdx->pPartIdxWhere==0 ){
133537 if( zKey==0 ){
133544 for(i=0; i<nCol; i++) aiCol[i] = pFKey->aCol[i].iFrom;
133554 for(i=0; i<nCol; i++){
133559 if( iCol<0 ) break; /* No foreign keys against expression indexes */
133569 for(j=0; j<nCol; j++){
133570 if( sqlite3StrICmp(pFKey->aCol[j].zCol, zIdxCol)==0 ){
133593 return 0;
133651 if( nIncr<0 ){
133655 for(i=0; i<pFKey->nCol; i++){
133660 if( isIgnore==0 ){
133661 if( pIdx==0 ){
133673 sqlite3TableColumnToStorage(pFKey->pFrom,aiCol[0])+1+regData, regTemp);
133674 iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
133687 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
133698 for(i=0; i<nCol; i++){
133716 for(i=0; i<nCol; i++){
133722 assert( pIdx->aiColumn[i]>=0 );
133734 sqlite3VdbeAddOp4(v, OP_Affinity, regTemp, nCol, 0,
133752 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
133754 if( nIncr>0 && pFKey->isDeferred==0 ){
133784 pExpr = sqlite3Expr(db, TK_REGISTER, 0);
133786 if( iCol>=0 && iCol!=pTab->iPKey ){
133791 if( zColl==0 ) zColl = db->pDfltColl->zName;
133811 Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
133861 Expr *pWhere = 0; /* WHERE clause to scan with */
133864 int iFkIfZero = 0; /* Address of OP_FkIfZero */
133867 assert( pIdx==0 || pIdx->pTable==pTab );
133868 assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
133869 assert( pIdx!=0 || pFKey->nCol==1 );
133870 assert( pIdx!=0 || HasRowid(pTab) );
133872 if( nIncr<0 ){
133873 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
133885 for(i=0; i<pFKey->nCol; i++){
133894 iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
133895 assert( iCol>=0 );
133916 if( pTab==pFKey->pFrom && nIncr>0 ){
133922 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
133925 Expr *pEq, *pAll = 0;
133926 assert( pIdx!=0 );
133927 for(i=0; i<pIdx->nKeyCol; i++){
133929 assert( iCol>=0 );
133935 pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
133941 memset(&sNameContext, 0, sizeof(NameContext));
133949 if( pParse->nErr==0 ){
133950 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0, 0);
134014 fkTriggerDelete(db, pFKey->apTrigger[0]); pFKey->apTrigger[0] = 0;
134015 fkTriggerDelete(db, pFKey->apTrigger[1]); pFKey->apTrigger[1] = 0;
134040 int iSkip = 0;
134045 if( sqlite3FkReferences(pTab)==0 ){
134061 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0);
134062 pParse->disableTriggers = 0;
134073 if( (db->flags & SQLITE_DeferFKs)==0 ){
134075 sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
134078 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
134107 for(i=0; i<p->nCol; i++){
134109 if( aChange[iChildKey]>=0 ) return 1;
134112 return 0;
134134 for(i=0; i<p->nCol; i++){
134137 for(iKey=0; iKey<pTab->nCol; iKey++){
134138 if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){
134141 if( 0==sqlite3StrICmp(pCol->zCnName, zKey) ) return 1;
134148 return 0;
134160 if( (p==pFKey->apTrigger[0] && pFKey->aAction[0]==OE_SetNull)
134163 assert( (pTop->db->flags & SQLITE_FkNoAction)==0 );
134167 return 0;
134195 int *aChange, /* Array indicating UPDATEd columns (or 0) */
134205 assert( (regOld==0)!=(regNew==0) );
134208 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
134218 Index *pIdx = 0; /* Index on key columns in pTo */
134219 int *aiFree = 0;
134223 int bIgnore = 0;
134226 && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
134227 && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
134239 pTo = sqlite3LocateTable(pParse, 0, pFKey->zTo, zDb);
134242 assert( isIgnoreErrors==0 || (regOld!=0 && regNew==0) );
134244 if( pTo==0 ){
134254 for(i=0; i<pFKey->nCol; i++){
134269 iCol = pFKey->aCol[0].iFrom;
134272 for(i=0; i<pFKey->nCol; i++){
134276 assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
134293 sqlite3TableLock(pParse, iDb, pTo->tnum, 0, pTo->zName);
134296 if( regOld!=0 ){
134302 if( regNew!=0 && !isSetNullAction(pParse, pFKey) ){
134320 Index *pIdx = 0; /* Foreign key index for pFKey */
134322 int *aiCol = 0;
134324 if( aChange && fkParentIsModified(pTab, pFKey, aChange, bChngRowid)==0 ){
134331 assert( regOld==0 && regNew!=0 );
134345 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
134353 if( regNew!=0 ){
134356 if( regOld!=0 ){
134357 int eAction = pFKey->aAction[aChange!=0];
134382 pItem->zName = 0;
134389 #define COLUMN_MASK(x) (((x)>31) ? 0xffffffff : ((u32)1<<(x)))
134399 u32 mask = 0;
134404 for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
134407 Index *pIdx = 0;
134408 sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0);
134410 for(i=0; i<pIdx->nKeyCol; i++){
134411 assert( pIdx->aiColumn[i]>=0 );
134428 ** the value is 0 or greater. Parameter chngRowid is set to true if the
134452 int bHaveFK = 0; /* If FK processing is required */
134467 if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) eRet = 2;
134475 if( (pParse->db->flags & SQLITE_FkNoAction)==0
134485 return bHaveFK ? eRet : 0;
134526 int iAction = (pChanges!=0); /* 1 for UPDATE, 0 for DELETE */
134531 return 0;
134538 Index *pIdx = 0; /* Parent key index for this FK */
134539 int *aiCol = 0; /* child table cols -> parent key cols */
134540 TriggerStep *pStep = 0; /* First (only) step of trigger program */
134541 Expr *pWhere = 0; /* WHERE clause of trigger step */
134542 ExprList *pList = 0; /* Changes list if ON UPDATE CASCADE */
134543 Select *pSelect = 0; /* If RESTRICT, "SELECT RAISE(...)" */
134545 Expr *pWhen = 0; /* WHEN clause for the trigger */
134547 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ) return 0;
134550 for(i=0; i<pFKey->nCol; i++){
134558 iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
134559 assert( iFromCol>=0 );
134560 assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
134561 assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
134572 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
134573 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
134574 sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
134586 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
134587 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
134589 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
134590 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0))
134599 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
134600 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0));
134607 pDflt = 0;
134612 pNew = sqlite3ExprDup(db, pDflt, 0);
134614 pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
134617 pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
134620 sqlite3ExprListSetName(pParse, pList, &tFromCol, 0);
134634 pRaise = sqlite3PExpr(pParse, TK_RAISE, pRaise, 0);
134638 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
134641 pSrc->a[0].zName = sqlite3DbStrDup(db, zFrom);
134642 assert( pSrc->a[0].fg.fixedSchema==0 && pSrc->a[0].fg.isSubquery==0 );
134643 pSrc->a[0].u4.zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
134646 sqlite3ExprListAppend(pParse, 0, pRaise),
134649 0, 0, 0, 0, 0
134651 pWhere = 0;
134671 pWhen = sqlite3PExpr(pParse, TK_NOT, pWhen, 0);
134685 return 0;
134687 assert( pStep!=0 );
134688 assert( pTrigger!=0 );
134722 int *aChange, /* Array indicating UPDATEd columns (or 0) */
134732 if( aChange==0 || fkParentIsModified(pTab, pFKey, aChange, bChngRowid) ){
134735 sqlite3CodeRowTriggerDirect(pParse, pAct, pTab, regOld, OE_Abort, 0);
134754 assert( db!=0 );
134756 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
134759 if( db->pnBytesFreed==0 ){
134774 assert( pFKey->isDeferred==0 || pFKey->isDeferred==1 );
134778 fkTriggerDelete(db, pFKey->apTrigger[0]);
134824 assert( pParse->pVdbe!=0 );
134829 (opcode==OP_OpenWrite)?1:0, pTab->zName);
134836 assert( pPk!=0 );
134875 pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
134878 return 0;
134880 for(n=0; n<pIdx->nColumn; n++){
134883 if( x>=0 ){
134890 assert( pIdx->aColExpr!=0 );
134897 pIdx->zColAff[n] = 0;
134916 for(i=j=0; i<pTab->nCol; i++){
134917 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
134922 zColAff[j--] = 0;
134923 }while( j>=0 && zColAff[j]<=SQLITE_AFF_BLOB );
134941 ** Otherwise if iReg>0 then code an OP_Affinity opcode that will set the
134942 ** affinities for register iReg and following. Or if iReg==0,
134960 ** datatypes against the column definitions in pTab. If iReg==0, that
134964 ** register set as the OP_MakeRecord. If iReg>0 then register iReg is
134972 if( iReg==0 ){
134979 assert( pPrev!=0 );
134991 if( zColAff==0 ){
134992 zColAff = sqlite3TableAffinityStr(0, pTab);
134999 assert( zColAff!=0 );
135003 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i);
135023 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
135028 assert( pOp!=0 );
135043 assert( pOp->p4.pVtab!=0 );
135049 return 0;
135056 if( pExpr->op==TK_COLUMN && pExpr->iColumn>=0 ){
135090 if( (pTab->tabFlags & TF_HasStored)!=0 ){
135098 assert( zP4!=0 );
135100 for(ii=jj=0; zP4[jj]; ii++){
135121 for(i=0; i<pTab->nCol; i++){
135131 w.xSelectCallback = 0;
135132 w.xSelectCallback2 = 0;
135141 eProgress = 0;
135142 pRedo = 0;
135143 for(i=0; i<pTab->nCol; i++){
135145 if( (pCol->colFlags & COLFLAG_NOTAVAIL)!=0 ){
135148 w.eCode = 0;
135166 pParse->iSelfTab = 0;
135200 int memId = 0; /* Register holding maximum rowid */
135201 assert( pParse->db->aDb[iDb].pSchema!=0 );
135202 if( (pTab->tabFlags & TF_Autoincrement)!=0
135203 && (pParse->db->mDbFlags & DBFLAG_Vacuum)==0
135212 if( pSeqTab==0
135219 return 0;
135224 if( pInfo==0 ){
135228 if( pParse->db->mallocFailed ) return 0;
135255 assert( pParse->pTriggerTab==0 );
135262 /* 0 */ {OP_Null, 0, 0, 0},
135263 /* 1 */ {OP_Rewind, 0, 10, 0},
135264 /* 2 */ {OP_Column, 0, 0, 0},
135265 /* 3 */ {OP_Ne, 0, 9, 0},
135266 /* 4 */ {OP_Rowid, 0, 0, 0},
135267 /* 5 */ {OP_Column, 0, 1, 0},
135268 /* 6 */ {OP_AddImm, 0, 0, 0},
135269 /* 7 */ {OP_Copy, 0, 0, 0},
135270 /* 8 */ {OP_Goto, 0, 11, 0},
135271 /* 9 */ {OP_Next, 0, 2, 0},
135272 /* 10 */ {OP_Integer, 0, 0, 0},
135273 /* 11 */ {OP_Close, 0, 0, 0}
135278 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
135279 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
135282 if( aOp==0 ) break;
135283 aOp[0].p2 = memId;
135284 aOp[0].p3 = memId+2;
135295 if( pParse->nTab==0 ) pParse->nTab = 1;
135308 if( memId>0 ){
135329 /* 0 */ {OP_NotNull, 0, 2, 0},
135330 /* 1 */ {OP_NewRowid, 0, 0, 0},
135331 /* 2 */ {OP_MakeRecord, 0, 2, 0},
135332 /* 3 */ {OP_Insert, 0, 0, 0},
135333 /* 4 */ {OP_Close, 0, 0, 0}
135341 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
135344 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
135346 if( aOp==0 ) break;
135347 aOp[0].p1 = memId+1;
135365 # define autoIncBegin(A,B,C) (0)
135375 if( ALWAYS(pVal) && pVal->pSrc->nSrc>0 ){
135376 SrcItem *pItem = &pVal->pSrc->a[0];
135377 assert( (pItem->fg.isSubquery && pItem->u4.pSubq!=0) || pParse->nErr );
135391 for(ii=0; ii<pRow->nExpr; ii++){
135392 if( 0==sqlite3ExprIsConstant(pParse, pRow->a[ii].pExpr) ) return 0;
135403 if( exprListIsConstant(pParse,pRow)==0 ) return 0;
135404 for(ii=0; ii<pRow->nExpr; ii++){
135407 assert( pExpr->affExpr==0 );
135408 if( 0!=sqlite3ExprAffinity(pExpr) ) return 0;
135469 || exprListIsConstant(pParse,pRow)==0 /* condition (c) above */
135470 || (pLeft->pSrc->nSrc==0 &&
135471 exprListIsNoAffinity(pParse,pLeft->pEList)==0) /* condition (d) above */
135475 Select *pSelect = 0;
135484 pSelect = sqlite3SelectNew(pParse, pRow, 0, 0, 0, 0, 0, f, 0);
135492 SrcItem *p = 0; /* SrcItem that reads from co-routine */
135494 if( pLeft->pSrc->nSrc==0 ){
135499 Select *pRet = sqlite3SelectNew(pParse, 0, 0, 0, 0, 0, 0, 0, 0);
135503 if( (pParse->db->mDbFlags & DBFLAG_SchemaKnownOk)==0 ){
135514 pLeft->pPrior = 0;
135516 assert( pLeft->pNext==0 );
135517 assert( pRet->pNext==0 );
135518 p = &pRet->pSrc->a[0];
135523 if( sqlite3SrcItemAttachSubquery(pParse, p, pLeft, 0) ){
135528 pSubq->regReturn, 0, pSubq->addrFillSub);
135543 assert( pParse->nErr || dest.iSdst>0 );
135548 p = &pLeft->pSrc->a[0];
135553 if( pParse->nErr==0 ){
135555 assert( p!=0 );
135558 assert( pSubq!=0 );
135559 assert( pSubq->pSelect!=0 );
135560 assert( pSubq->pSelect->pEList!=0 );
135564 sqlite3ExprCodeExprList(pParse, pRow, pSubq->regResult, 0, 0);
135694 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
135695 int iDataCur = 0; /* VDBE cursor that is the main data repository */
135696 int iIdxCur = 0; /* First index cursor */
135699 int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
135700 int addrInsTop = 0; /* Jump to label "D" */
135701 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
135704 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
135705 u8 appendFlag = 0; /* True if the insert is likely to be an append */
135706 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
135708 ExprList *pList = 0; /* List of VALUES() to be inserted */
135712 int regFromSelect = 0;/* Base register for data coming from SELECT */
135713 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
135714 int regRowCount = 0; /* Memory cell used for the row counter */
135718 int *aRegIdx = 0; /* One register allocated to each index */
135719 int *aTabColMap = 0; /* Mapping from pTab columns to pCol entries */
135732 assert( db->mallocFailed==0 );
135733 dest.iSDParm = 0; /* Suppress a harmless compiler warning */
135739 if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
135741 pSelect->pEList = 0;
135743 pSelect = 0;
135750 if( pTab==0 ){
135755 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0,
135765 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0, &tmask);
135768 # define pTrigger 0
135769 # define tmask 0
135770 # define isView 0
135774 # define isView 0
135776 assert( (pTrigger && tmask) || (pTrigger==0 && tmask==0) );
135779 if( sqlite3TreeTrace & 0x10000 ){
135780 sqlite3TreeViewLine(0, "In sqlite3Insert() at %s:%d", __FILE__, __LINE__);
135802 if( v==0 ) goto insert_cleanup;
135803 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
135816 if( pColumn==0
135817 && pSelect!=0
135818 && pTrigger==0
135822 assert( pList==0 );
135862 bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
135865 if( aTabColMap==0 ) goto insert_cleanup;
135866 for(i=0; i<pColumn->nId; i++){
135868 if( j>=0 ){
135869 if( aTabColMap[j]==0 ) aTabColMap[j] = i+1;
135870 if( i!=j ) bIdListInOrder = 0;
135885 bIdListInOrder = 0;
135907 && pSelect->pSrc->a[0].fg.viaCoroutine
135908 && pSelect->pPrior==0
135910 SrcItem *pItem = &pSelect->pSrc->a[0];
135916 assert( pSubq->pSelect!=0 );
135917 assert( pSubq->pSelect->pEList!=0 );
135919 ExplainQueryPlan((pParse, 0, "SCAN %S", pItem));
135923 regIns = regRowid - (IsVirtual(pTab) ? 1 : 0);
135929 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
135931 dest.iSdst = bIdListInOrder ? regData : 0;
135937 assert( db->mallocFailed==0 );
135990 memset(&sNC, 0, sizeof(sNC));
135993 assert( useTempTable==0 );
136000 nColumn = 0;
136008 if( pColumn==0 && nColumn>0 ){
136011 if( ipkColumn>=0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
136014 for(i=ipkColumn-1; i>=0; i--){
136030 if( (pTab->tabFlags & (TF_HasGenerated|TF_HasHidden))!=0 ){
136031 for(i=0; i<pTab->nCol; i++){
136042 if( pColumn!=0 && nColumn!=pColumn->nId ){
136049 if( (db->flags & SQLITE_CountRows)!=0
136055 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
136061 nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, -1, 0,
136064 if( aRegIdx==0 ){
136067 for(i=0, pIdx=pTab->pIndex; i<nIdx; pIdx=pIdx->pNext, i++){
136089 pTabList->a[0].iCursor = iDataCur;
136102 }while( pNx!=0 );
136129 sqlite3VdbeReleaseRegisters(pParse, regData, pTab->nCol, 0, 0);
136132 if( ipkColumn>=0 ){
136147 nHidden = 0;
136149 for(i=0; i<pTab->nCol; i++, iRegStore++){
136161 if( ((colFlags = pTab->aCol[i].colFlags) & COLFLAG_NOINSERT)!=0 ){
136163 if( (colFlags & COLFLAG_VIRTUAL)!=0 ){
136169 }else if( (colFlags & COLFLAG_STORED)!=0 ){
136178 }else if( pColumn==0 ){
136189 assert( j>=0 && j<=pColumn->nId );
136190 if( j==0 ){
136199 }else if( nColumn==0 ){
136238 if( ipkColumn<0 ){
136246 assert( pSelect==0 ); /* Otherwise useTempTable is true */
136256 assert( pTab->nNVCol>0 || pParse->nErr>0 );
136281 sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE,
136290 sqlite3VdbeAddOp2(v, OP_Null, 0, regIns);
136292 if( ipkColumn>=0 ){
136323 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
136353 int isReplace = 0;/* Set to true if constraints may cause a replace */
136356 regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert
136359 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
136370 bUseSeek = (isReplace==0 || !sqlite3VdbeHasSubProgram(v));
136372 regIns, aRegIdx, 0, appendFlag, bUseSeek
136392 sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_AFTER,
136425 if( pParse->nested==0 && pParse->pTriggerTab==0 ){
136467 #define CKCNSTRNT_COLUMN 0x01 /* CHECK constraint uses a changing column */
136468 #define CKCNSTRNT_ROWID 0x02 /* CHECK constraint references the ROWID */
136471 * Set bit 0x01 of pWalker->eCode if pWalker->eCode to 0 and if this
136477 assert( pExpr->iColumn>=0 || pExpr->iColumn==-1 );
136478 if( pExpr->iColumn>=0 ){
136479 if( pWalker->u.aiCol[pExpr->iColumn]>=0 ){
136492 ** aiChng[i]>=0, and also the ROWID is modified if chngRowid is true.
136506 int *aiChng, /* aiChng[x]>=0 if column x changed by the UPDATE */
136510 memset(&w, 0, sizeof(w));
136511 w.eCode = 0;
136516 testcase( (w.eCode & CKCNSTRNT_ROWID)!=0 );
136519 testcase( w.eCode==0 );
136523 return w.eCode!=0;
136540 int eType; /* 0 for Index.pNext list. 1 for an array of IndexListTerm */
136543 struct { /* Use this object for eType==0: A Index.pNext list */
136563 assert( pIter->i==0 );
136565 *pIx = pIter->u.ax.aIdx[0].ix;
136566 return pIter->u.ax.aIdx[0].p;
136568 *pIx = 0;
136579 return 0;
136621 ** indices where aRegIdx[i]==0. The order of indices in aRegIdx[] is
136684 int *aRegIdx, /* Use register aRegIdx[i] for index i. 0 for unused */
136688 int regOldData, /* Previous content. 0 for INSERTs */
136693 int *aiChng, /* column i is unchanged if aiChng[i]<0 */
136698 Index *pPk = 0; /* The PRIMARY KEY index for WITHOUT ROWID tables */
136704 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
136706 Upsert *pUpsertClause = 0; /* The specific ON CONFLICT clause for pIdx */
136708 u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
136709 int upsertIpkReturn = 0; /* Address of Goto at end of IPK uniqueness check */
136710 int upsertIpkDelay = 0; /* Address of Goto to bypass initial IPK check */
136711 int ipkTop = 0; /* Top of the IPK uniqueness check */
136712 int ipkBottom = 0; /* OP_Goto at the end of the IPK uniqueness check */
136716 int addrRecheck = 0; /* Jump here to recheck all uniqueness constraints */
136717 int lblRecheckOk = 0; /* Each recheck jumps to this label if it passes */
136719 int nReplaceTrig = 0; /* Number of replace triggers coded */
136722 isUpdate = regOldData!=0;
136725 assert( v!=0 );
136734 pPk = 0;
136748 int b2ndPass = 0; /* True if currently running 2nd pass */
136749 int nSeenReplace = 0; /* Number of ON CONFLICT REPLACE operations */
136750 int nGenerated = 0; /* Number of generated columns with NOT NULL */
136752 for(i=0; i<nCol; i++){
136766 if( aiChng && aiChng[i]<0 && !isGenerated ){
136777 || pCol->iDflt==0 /* REPLACE is ABORT if no DEFAULT value */
136797 assert( (pCol->colFlags & COLFLAG_GENERATED)==0 );
136811 testcase( zMsg==0 && db->mallocFailed==0 );
136827 if( nGenerated==0 && nSeenReplace==0 ){
136836 if( nSeenReplace>0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
136850 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
136854 for(i=0; i<pCheck->nExpr; i++){
136865 if( bAffinityDone==0 ){
136871 pCopy = sqlite3ExprDup(db, pExpr, 0);
136880 assert( zName!=0 || pParse->db->mallocFailed );
136888 pParse->iSelfTab = 0;
136920 sIdxIter.eType = 0;
136921 sIdxIter.i = 0;
136922 sIdxIter.u.ax.aIdx = 0; /* Silence harmless compiler warning */
136925 if( pUpsert->pUpsertTarget==0 ){
136927 assert( pUpsert->pNextUpsert==0 );
136928 if( pUpsert->isDoUpdate==0 ){
136932 pUpsert = 0;
136937 }else if( pTab->pIndex!=0 ){
136945 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
136946 assert( aRegIdx[nIdx]>0 );
136952 if( sIdxIter.u.ax.aIdx==0 ) return; /* OOM */
136955 for(i=0, pTerm=pUpsert; pTerm; pTerm=pTerm->pNextUpsert){
136956 if( pTerm->pUpsertTarget==0 ) break;
136957 if( pTerm->pUpsertIdx==0 ) continue; /* Skip ON CONFLICT for the IPK */
136958 jj = 0;
136960 while( ALWAYS(pIdx!=0) && pIdx!=pTerm->pUpsertIdx ){
136970 for(jj=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, jj++){
137000 if( (db->flags & (SQLITE_RecTriggers|SQLITE_ForeignKeys))==0 ){
137003 pTrigger = 0;
137004 regTrigCnt = 0;
137007 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
137008 regTrigCnt = pTrigger!=0 || sqlite3FkRequired(pParse, pTab, 0, 0);
137010 pTrigger = 0;
137011 regTrigCnt = sqlite3FkRequired(pParse, pTab, 0, 0);
137017 sqlite3VdbeAddOp2(v, OP_Integer, 0, regTrigCnt);
137027 if( pkChng && pPk==0 ){
137040 pUpsertClause = sqlite3UpsertOfIndex(pUpsert,0);
137041 if( pUpsertClause!=0 ){
137042 if( pUpsertClause->isDoUpdate==0 ){
137071 /* pkChng!=0 does not mean that the rowid has changed, only that
137126 regNewData, 1, 0, OE_Replace, 1, -1);
137141 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,-1);
137149 sqlite3UpsertDoUpdate(pParse, pUpsert, pTab, 0, iDataCur);
137185 if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
137193 if( bAffinityDone==0 ){
137203 sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[ix]);
137207 pParse->iSelfTab = 0;
137214 for(i=0; i<pIdx->nColumn; i++){
137220 pParse->iSelfTab = 0;
137240 sqlite3VdbeReleaseRegisters(pParse, regIdx, pIdx->nColumn, 0, 0);
137246 if( isUpdate && pPk==pIdx && pkChng==0 ){
137265 if( pUpsertClause->isDoUpdate==0 ){
137284 if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
137287 && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
137288 0==sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0))
137289 && ( 0==(db->flags&SQLITE_ForeignKeys) || /* Condition 5 */
137290 (0==pTab->u.tab.pFKey && 0==sqlite3FkReferences(pTab)))
137320 for(i=0; i<pPk->nKeyCol; i++){
137321 assert( pPk->aiColumn[i]>=0 );
137340 for(i=0; i<pPk->nKeyCol; i++){
137343 assert( x>=0 );
137389 assert( nConflictCk>0 || db->mallocFailed );
137390 testcase( nConflictCk<=0 );
137400 regR, nPkField, 0, OE_Replace,
137426 while( nConflictCk>0 ){
137465 upsertIpkReturn = 0;
137473 assert( ipkBottom>0 );
137478 testcase( regTrigCnt!=0 && nReplaceTrig==0 );
137479 assert( regTrigCnt!=0 || nReplaceTrig==0 );
137503 sqlite3TableAffinity(v, pTab, 0);
137525 for(i=pTab->nCol-1; i>0; i--){
137526 if( pTab->aCol[i].iDflt!=0 ) break;
137549 assert( 0==(pParse->db->mDbFlags & DBFLAG_Vacuum) || CORRUPT_DB );
137550 sqlite3VdbeAddOp2(v, OP_Integer, 0, r);
137574 int *aRegIdx, /* Register used by each index. 0 for unused indices */
137584 assert( update_flags==0
137590 assert( v!=0 );
137592 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
137595 || pIdx->pNext==0
137597 if( aRegIdx[i]==0 ) continue;
137602 pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
137606 if( update_flags==0 ){
137617 pik_flags = 0;
137673 assert( op==OP_OpenWrite || p5==0 );
137674 assert( piDataCur!=0 );
137675 assert( piIdxCur!=0 );
137681 return 0;
137685 assert( v!=0 );
137686 if( iBase<0 ) iBase = pParse->nTab;
137689 if( HasRowid(pTab) && (aToOpen==0 || aToOpen[0]) ){
137691 }else if( pParse->db->noSharedCache==0 ){
137695 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
137700 p5 = 0;
137702 if( aToOpen==0 || aToOpen[i+1] ){
137742 return 0; /* Different number of columns */
137745 return 0; /* Different conflict resolution strategies */
137747 for(i=0; i<pSrc->nKeyCol; i++){
137749 return 0; /* Different columns indexed */
137752 assert( pSrc->aColExpr!=0 && pDest->aColExpr!=0 );
137753 if( sqlite3ExprCompare(0, pSrc->aColExpr->a[i].pExpr,
137754 pDest->aColExpr->a[i].pExpr, -1)!=0 ){
137755 return 0; /* Different expressions in the index */
137759 return 0; /* Different sort orders */
137761 if( sqlite3_stricmp(pSrc->azColl[i],pDest->azColl[i])!=0 ){
137762 return 0; /* Different collating sequences */
137765 if( sqlite3ExprCompare(0, pSrc->pPartIdxWhere, pDest->pPartIdxWhere, -1) ){
137766 return 0; /* Different WHERE clauses */
137814 int emptyDestTest = 0; /* Address of test for empty pDest */
137815 int emptySrcTest = 0; /* Address of test for empty pSrc */
137818 int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */
137821 assert( pSelect!=0 );
137826 return 0;
137830 return 0; /* tab1 must not be a virtual table */
137834 if( pDest->iPKey>=0 ) onError = pDest->keyConf;
137839 return 0; /* FROM clause must have exactly one term */
137841 if( pSelect->pSrc->a[0].fg.isSubquery ){
137842 return 0; /* FROM clause cannot contain a subquery */
137845 return 0; /* SELECT may not have a WHERE clause */
137848 return 0; /* SELECT may not have an ORDER BY clause */
137853 return 0; /* SELECT may not have a GROUP BY clause */
137856 return 0; /* SELECT may not have a LIMIT clause */
137859 return 0; /* SELECT may not be a compound query */
137862 return 0; /* SELECT may not be DISTINCT */
137865 assert( pEList!=0 );
137867 return 0; /* The result set must have exactly one column */
137869 assert( pEList->a[0].pExpr );
137870 if( pEList->a[0].pExpr->op!=TK_ASTERISK ){
137871 return 0; /* The result set must be the special operator "*" */
137879 pSrc = sqlite3LocateTableItem(pParse, 0, pItem);
137880 if( pSrc==0 ){
137881 return 0; /* FROM clause does not contain a real table */
137885 return 0; /* tab1 and tab2 may not be the same table */
137888 return 0; /* source and destination must both be WITHOUT ROWID or not */
137891 return 0; /* tab2 may not be a view or virtual table */
137894 return 0; /* Number of columns must be the same in tab1 and tab2 */
137897 return 0; /* Both tables must have the same INTEGER PRIMARY KEY */
137899 if( (pDest->tabFlags & TF_Strict)!=0 && (pSrc->tabFlags & TF_Strict)==0 ){
137900 return 0; /* Cannot feed from a non-strict into a strict table */
137902 for(i=0; i<pDest->nCol; i++){
137906 if( (db->mDbFlags & DBFLAG_Vacuum)==0
137909 return 0; /* Neither table may have __hidden__ columns */
137931 return 0; /* Both columns have the same generated-column type */
137937 if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){
137938 if( sqlite3ExprCompare(0,
137940 sqlite3ColumnExpr(pDest, pDestCol), -1)!=0 ){
137943 return 0; /* Different generator expressions */
137948 return 0; /* Affinity must be the same on all columns */
137951 sqlite3ColumnColl(pSrcCol))!=0 ){
137952 return 0; /* Collating sequence must be the same on all columns */
137955 return 0; /* tab2 must be NOT NULL if tab1 is */
137958 if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
137961 assert( pDestExpr==0 || pDestExpr->op==TK_SPAN );
137962 assert( pDestExpr==0 || !ExprHasProperty(pDestExpr, EP_IntValue) );
137963 assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN );
137964 assert( pSrcExpr==0 || !ExprHasProperty(pSrcExpr, EP_IntValue) );
137965 if( (pDestExpr==0)!=(pSrcExpr==0)
137966 || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken,
137967 pSrcExpr->u.zToken)!=0)
137969 return 0; /* Default values must be the same for all columns */
137980 if( pSrcIdx==0 ){
137981 return 0; /* pDestIdx has no corresponding index in pSrc */
137988 return 0; /* Corrupt schema - two indexes on the same btree */
137993 && (db->mDbFlags & DBFLAG_Vacuum)==0
137996 return 0; /* Tables have different CHECK constraints. Ticket #2252 */
138008 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){
138009 return 0;
138012 if( (db->flags & SQLITE_CountRows)!=0 ){
138013 return 0; /* xfer opt does not play well with PRAGMA count_changes */
138030 sqlite3VdbeAddOp2(v, OP_Null, 0, regData);
138034 if( (db->mDbFlags & DBFLAG_Vacuum)==0 && (
138035 (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
138056 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
138063 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
138064 if( pDest->iPKey>=0 ){
138066 if( (db->mDbFlags & DBFLAG_Vacuum)==0 ){
138068 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
138074 }else if( pDest->pIndex==0 && !(db->mDbFlags & DBFLAG_VacuumInto) ){
138078 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
138088 if( (db->mDbFlags & DBFLAG_Vacuum)==0 ){
138097 if( (db->mDbFlags & DBFLAG_Vacuum)==0 ){
138103 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
138104 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
138107 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
138110 u8 idxInsFlags = 0;
138122 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
138138 for(i=0; i<pSrcIdx->nColumn; i++){
138152 if( (db->mDbFlags & DBFLAG_Vacuum)==0
138163 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
138164 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
138171 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0);
138173 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
138174 return 0;
138221 sqlite3_stmt *pStmt = 0; /* The current SQL statement */
138222 char **azCols = 0; /* Names of result columns */
138226 if( zSql==0 ) zSql = "";
138230 while( rc==SQLITE_OK && zSql[0] ){
138231 int nCol = 0;
138232 char **azVals = 0;
138234 pStmt = 0;
138236 assert( rc==SQLITE_OK || pStmt==0 );
138245 callbackIsInit = 0;
138258 if( azCols==0 ){
138261 for(i=0; i<nCol; i++){
138265 assert( azCols[i]!=0 );
138271 for(i=0; i<nCol; i++){
138278 azVals[i] = 0;
138286 pStmt = 0;
138294 pStmt = 0;
138296 while( sqlite3Isspace(zSql[0]) ) zSql++;
138302 azCols = 0;
138311 *pzErrMsg = sqlite3DbStrDup(0, sqlite3_errmsg(db));
138312 if( *pzErrMsg==0 ){
138317 *pzErrMsg = 0;
138516 /* Added by 3.5.0 */
138619 /* Version 3.9.0 and later */
138622 /* Version 3.10.0 and later */
138626 /* Version 3.12.0 and later */
138628 /* Version 3.14.0 and later */
138631 /* Version 3.18.0 and later */
138633 /* Version 3.20.0 and later */
138644 /* Version 3.24.0 and later */
138659 /* Version 3.25.0 and later */
138666 /* Version 3.26.0 and later */
138668 /* Version 3.28.0 and later */
138671 /* Version 3.30.0 and later */
138673 /* Version 3.31.0 and later */
138679 /* Version 3.32.0 and later */
138684 /* Version 3.34.0 and later */
138689 /* Version 3.37.0 and later */
138693 /* Version 3.38.0 and later */
138700 /* Version 3.39.0 and later */
138706 /* Version 3.40.0 and later */
138708 /* Version 3.41.0 and later */
138710 /* Version 3.43.0 and later */
138712 /* Version 3.44.0 and later */
138715 /* Version 3.50.0 and later */
138963 /* Version 3.9.0 and later */
138966 /* Version 3.10.0 and later */
138970 /* Version 3.12.0 and later */
138972 /* Version 3.14.0 and later */
138975 /* Version 3.18.0 and later */
138977 /* Version 3.20.0 and later */
138983 /* Version 3.22.0 and later */
138987 /* Version 3.24.0 and later */
139002 /* Version 3.25.0 and later */
139004 /* Version 3.26.0 and later */
139006 /* Version 3.28.0 and later */
139009 /* Version 3.30.0 and later */
139011 /* Version 3.31.0 and later */
139017 /* Version 3.32.0 and later */
139021 /* Version 3.34.0 and later */
139026 /* Version 3.37.0 and later */
139028 /* Version 3.38.0 and later */
139035 /* Version 3.39.0 and later */
139041 /* Version 3.40.0 and later */
139043 /* Version 3.41.0 and later */
139045 /* Version 3.43.0 and later */
139047 /* Version 3.44.0 and later */
139050 /* Version 3.50.0 and later */
139057 # define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
139082 # define sqlite3_column_database_name 0
139083 # define sqlite3_column_database_name16 0
139084 # define sqlite3_column_table_name 0
139085 # define sqlite3_column_table_name16 0
139086 # define sqlite3_column_origin_name 0
139087 # define sqlite3_column_origin_name16 0
139091 # define sqlite3_set_authorizer 0
139095 # define sqlite3_bind_text16 0
139096 # define sqlite3_collation_needed16 0
139097 # define sqlite3_column_decltype16 0
139098 # define sqlite3_column_name16 0
139099 # define sqlite3_column_text16 0
139100 # define sqlite3_complete16 0
139101 # define sqlite3_create_collation16 0
139102 # define sqlite3_create_function16 0
139103 # define sqlite3_errmsg16 0
139104 # define sqlite3_open16 0
139105 # define sqlite3_prepare16 0
139106 # define sqlite3_prepare16_v2 0
139107 # define sqlite3_prepare16_v3 0
139108 # define sqlite3_result_error16 0
139109 # define sqlite3_result_text16 0
139110 # define sqlite3_result_text16be 0
139111 # define sqlite3_result_text16le 0
139112 # define sqlite3_value_text16 0
139113 # define sqlite3_value_text16be 0
139114 # define sqlite3_value_text16le 0
139115 # define sqlite3_column_database_name16 0
139116 # define sqlite3_column_table_name16 0
139117 # define sqlite3_column_origin_name16 0
139121 # define sqlite3_complete 0
139122 # define sqlite3_complete16 0
139126 # define sqlite3_column_decltype16 0
139127 # define sqlite3_column_decltype 0
139131 # define sqlite3_progress_handler 0
139135 # define sqlite3_create_module 0
139136 # define sqlite3_create_module_v2 0
139137 # define sqlite3_declare_vtab 0
139138 # define sqlite3_vtab_config 0
139139 # define sqlite3_vtab_on_conflict 0
139140 # define sqlite3_vtab_collation 0
139144 # define sqlite3_enable_shared_cache 0
139148 # define sqlite3_profile 0
139149 # define sqlite3_trace 0
139153 # define sqlite3_free_table 0
139154 # define sqlite3_get_table 0
139158 #define sqlite3_bind_zeroblob 0
139159 #define sqlite3_blob_bytes 0
139160 #define sqlite3_blob_close 0
139161 #define sqlite3_blob_open 0
139162 #define sqlite3_blob_read 0
139163 #define sqlite3_blob_write 0
139164 #define sqlite3_blob_reopen 0
139168 # define sqlite3_trace_v2 0
139191 0,
139250 0,
139258 0, /* Was sqlite3_global_recover(), but that function is deprecated */
139294 0,
139301 0,
139341 ** Added for 3.5.0
139354 0,
139355 0,
139356 0,
139357 0,
139358 0,
139387 ** Added for 3.6.0
139407 0,
139408 0,
139423 0,
139430 0,
139431 0,
139432 0,
139468 /* Version 3.9.0 and later */
139471 /* Version 3.10.0 and later */
139475 /* Version 3.12.0 and later */
139477 /* Version 3.14.0 and later */
139480 /* Version 3.18.0 and later */
139482 /* Version 3.20.0 and later */
139488 /* Version 3.22.0 and later */
139492 /* Version 3.24.0 and later */
139507 /* Version 3.25.0 and later */
139509 /* Version 3.26.0 and later */
139513 0,
139515 /* Version 3.28.0 and later */
139518 /* Version 3.30.0 and later */
139522 0,
139524 /* Version 3.31.0 and later */
139530 /* Version 3.32.0 and later */
139534 /* Version 3.34.0 and later */
139539 /* Version 3.37.0 and later */
139541 /* Version 3.38.0 and later */
139550 0,
139551 0,
139552 0,
139553 0,
139554 0,
139556 /* Version 3.39.0 and later */
139561 0,
139562 0,
139565 /* Version 3.40.0 and later */
139567 /* Version 3.41.0 and later */
139569 /* Version 3.43.0 and later */
139571 /* Version 3.44.0 and later */
139574 /* Version 3.50.0 and later */
139588 ** zFile. The entry point is zProc. zProc may be 0 in which case a
139594 ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
139601 const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
139602 char **pzErrMsg /* Put error message here if not 0 */
139607 char *zErrmsg = 0;
139609 char *zAltEntry = 0;
139627 if( pzErrMsg ) *pzErrMsg = 0;
139633 ** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0)
139636 if( (db->flags & SQLITE_LoadExtension)==0 ){
139657 if( nMsg==0 ) goto extension_not_found;
139661 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
139663 if( zAltFile==0 ) return SQLITE_NOMEM_BKPT;
139670 if( handle==0 ) goto extension_not_found;
139684 if( xInit==0 && zProc==0 ){
139688 if( zAltEntry==0 ){
139693 for(iFile=ncFile-1; iFile>=0 && !DirSep(zFile[iFile]); iFile--){}
139695 if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
139696 for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
139705 if( xInit==0 ){
139710 assert( nMsg<0x7fffffff ); /* zErrmsg would be NULL if not so */
139734 if( aHandle==0 ){
139737 if( db->nExtension>0 ){
139751 assert( nMsg<0x7fffffff ); /* zErrmsg would be NULL if not so */
139762 const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
139763 char **pzErrMsg /* Put error message here if not 0 */
139780 for(i=0; i<db->nExtension; i++){
139817 } sqlite3Autoext = { 0, 0 };
139828 # define wsdAutoext x[0]
139844 if( xInit==0 ) return SQLITE_MISUSE_BKPT;
139859 for(i=0; i<wsdAutoext.nExt; i++){
139863 u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
139866 if( aNew==0 ){
139875 assert( (rc&0xff)==rc );
139886 ** Return 1 if xInit was found on the list and removed. Return 0 if xInit
139896 int n = 0;
139899 if( xInit==0 ) return 0;
139902 for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
139928 wsdAutoext.aExt = 0;
139929 wsdAutoext.nExt = 0;
139946 if( wsdAutoext.nExt==0 ){
139950 for(i=0; go; i++){
139956 const sqlite3_api_routines *pThunk = 0;
139962 xInit = 0;
139963 go = 0;
139968 zErrmsg = 0;
139969 if( xInit && (rc = xInit(db, &zErrmsg, pThunk))!=0 ){
139972 go = 0;
139999 # define SQLITE_ENABLE_LOCKING_STYLE 0
140019 #define PragTyp_ACTIVATE_EXTENSIONS 0
140067 #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
140068 #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
140069 #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
140070 #define PragFlg_ReadOnly 0x08 /* Read-only HEADER_VALUE */
140071 #define PragFlg_Result0 0x10 /* Acts as query when no argument */
140072 #define PragFlg_Result1 0x20 /* Acts as query when has one argument */
140073 #define PragFlg_SchemaOpt 0x40 /* Schema restricts name search if present */
140074 #define PragFlg_SchemaReq 0x80 /* Schema required - "main" is default */
140081 /* 0 */ "id", /* Used by: foreign_key_list */
140150 u8 nPragCName; /* Num of col names. 0 means use pragma name */
140157 /* ePragFlg: */ 0,
140158 /* ColNames: */ 0, 0,
140159 /* iArg: */ 0 },
140164 /* ColNames: */ 0, 0,
140165 /* iArg: */ 0 },
140170 /* ColNames: */ 0, 0,
140177 /* ColNames: */ 0, 0,
140178 /* iArg: */ 0 },
140185 /* ColNames: */ 0, 0,
140193 /* iArg: */ 0 },
140198 /* ColNames: */ 0, 0,
140199 /* iArg: */ 0 },
140205 /* ColNames: */ 0, 0,
140206 /* iArg: */ 0 },
140212 /* ColNames: */ 0, 0,
140213 /* iArg: */ 0 },
140218 /* ColNames: */ 0, 0,
140224 /* ColNames: */ 0, 0,
140232 /* iArg: */ 0 },
140238 /* ColNames: */ 0, 0,
140239 /* iArg: */ 0 },
140245 /* ColNames: */ 0, 0,
140252 /* ColNames: */ 0, 0,
140253 /* iArg: */ 0 },
140259 /* ColNames: */ 0, 0,
140267 /* iArg: */ 0 },
140274 /* iArg: */ 0 },
140281 /* ColNames: */ 0, 0,
140289 /* ColNames: */ 0, 0,
140296 /* ColNames: */ 0, 0,
140297 /* iArg: */ 0 },
140304 /* iArg: */ 0 },
140310 /* ColNames: */ 0, 8,
140311 /* iArg: */ 0 },
140318 /* ColNames: */ 0, 0,
140326 /* ColNames: */ 0, 0,
140333 /* ColNames: */ 0, 0,
140338 /* ColNames: */ 0, 0,
140347 /* iArg: */ 0 },
140353 /* ColNames: */ 0, 0,
140354 /* iArg: */ 0 },
140360 /* ColNames: */ 0, 0,
140368 /* ColNames: */ 0, 0,
140369 /* iArg: */ 0 },
140376 /* iArg: */ 0 },
140381 /* iArg: */ 0 },
140392 /* ColNames: */ 0, 0,
140393 /* iArg: */ 0 },
140399 /* ColNames: */ 0, 0,
140400 /* iArg: */ 0 },
140404 /* ColNames: */ 0, 0,
140405 /* iArg: */ 0 },
140411 /* ColNames: */ 0, 0,
140418 /* ColNames: */ 0, 0,
140419 /* iArg: */ 0 },
140426 /* iArg: */ 0 },
140432 /* ColNames: */ 0, 0,
140433 /* iArg: */ 0 },
140437 /* ColNames: */ 0, 0,
140438 /* iArg: */ 0 },
140441 /* ePragFlg: */ 0,
140442 /* ColNames: */ 0, 0,
140443 /* iArg: */ 0 },
140452 /* iArg: */ 0 },
140459 /* ColNames: */ 0, 0,
140460 /* iArg: */ 0 },
140465 /* ColNames: */ 0, 0,
140466 /* iArg: */ 0 },
140470 /* ColNames: */ 0, 0,
140471 /* iArg: */ 0 },
140478 /* ColNames: */ 0, 0,
140487 /* iArg: */ 0 },
140493 /* ColNames: */ 0, 0,
140500 /* ColNames: */ 0, 0,
140501 /* iArg: */ 0 },
140507 /* ColNames: */ 0, 0,
140512 /* ColNames: */ 0, 0,
140517 /* ColNames: */ 0, 0,
140524 /* ColNames: */ 0, 0,
140531 /* ColNames: */ 0, 0,
140532 /* iArg: */ 0 },
140538 /* ColNames: */ 0, 0,
140544 /* ColNames: */ 0, 0,
140545 /* iArg: */ 0 },
140549 /* ColNames: */ 0, 0,
140550 /* iArg: */ 0 },
140556 /* ColNames: */ 0, 0,
140565 /* iArg: */ 0 },
140571 /* ColNames: */ 0, 0,
140572 /* iArg: */ 0 },
140579 /* iArg: */ 0 },
140584 /* iArg: */ 0 },
140595 /* ColNames: */ 0, 0,
140596 /* iArg: */ 0 },
140600 /* ColNames: */ 0, 0,
140601 /* iArg: */ 0 },
140606 /* ColNames: */ 0, 0,
140607 /* iArg: */ 0 },
140612 /* ColNames: */ 0, 0,
140619 /* ColNames: */ 0, 0,
140627 /* ColNames: */ 0, 0,
140632 /* ColNames: */ 0, 0,
140637 /* ColNames: */ 0, 0,
140642 /* ColNames: */ 0, 0,
140647 /* ColNames: */ 0, 0,
140654 /* ePragFlg: */ 0,
140655 /* ColNames: */ 0, 0,
140656 /* iArg: */ 0 },
140661 /* iArg: */ 0 },
140667 /* ColNames: */ 0, 0,
140677 ** When the 0x10 bit of PRAGMA optimize is set, any ANALYZE commands
140689 ** has not been previously run and the 0x10000 flag is included so that
140693 ** optimize on a PI-4 is more like 1 millisecond or less with the 0x10000
140694 ** flag or less than 100 microseconds without the 0x10000 flag.
140705 ** Interpret the given string as a safety level. Return 0 for OFF,
140713 ** and older scripts may have used numbers 0 for OFF and 1 for ON.
140718 static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 15, 20};
140720 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 3, 2};
140727 for(i=0; i<ArraySize(iLength); i++){
140728 if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0
140741 return getSafetyLevel(z,1,dflt)!=0;
140755 if( 0==sqlite3StrICmp(z, "exclusive") ) return PAGER_LOCKINGMODE_EXCLUSIVE;
140756 if( 0==sqlite3StrICmp(z, "normal") ) return PAGER_LOCKINGMODE_NORMAL;
140766 ** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
140770 if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE;
140771 if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL;
140772 if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR;
140774 return (u8)((i>=0&&i<=2)?i:0);
140782 ** and 0 to use the compile-time default.
140785 if( z[0]>='0' && z[0]<='2' ){
140786 return z[0] - '0';
140787 }else if( sqlite3StrICmp(z, "file")==0 ){
140789 }else if( sqlite3StrICmp(z, "memory")==0 ){
140792 return 0;
140804 if( db->aDb[1].pBt!=0 ){
140813 db->aDb[1].pBt = 0;
140846 sqlite3VdbeSetNumCols(v, n==0 ? 1 : n);
140847 if( n==0 ){
140848 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, pPragma->zName, SQLITE_STATIC);
140851 for(i=0, j=pPragma->iPragCName; i<n; i++, j++){
140861 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
140880 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
140894 while( (n--) > 0 ){
140939 assert( PAGER_JOURNALMODE_DELETE==0 );
140945 assert( eMode>=0 && eMode<=ArraySize(azModeName) );
140947 if( eMode==ArraySize(azModeName) ) return 0;
140955 int upr, lwr, mid = 0, rc;
140956 lwr = 0;
140961 if( rc==0 ) break;
140962 if( rc<0 ){
140968 return lwr>upr ? 0 : &aPragmaName[mid];
140988 if( showInternFuncs ) mask = 0xffffffff;
140991 static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" };
140993 assert( SQLITE_FUNC_ENCMASK==0x3 );
140994 assert( strcmp(azEnc[SQLITE_UTF8],"utf8")==0 );
140995 assert( strcmp(azEnc[SQLITE_UTF16LE],"utf16le")==0 );
140996 assert( strcmp(azEnc[SQLITE_UTF16BE],"utf16be")==0 );
140998 if( p->xSFunc==0 ) continue;
140999 if( (p->funcFlags & SQLITE_FUNC_INTERNAL)!=0
141000 && showInternFuncs==0
141004 if( p->xValue!=0 ){
141006 }else if( p->xFinalize!=0 ){
141059 char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */
141060 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
141061 const char *zDb = 0; /* The database name */
141071 if( v==0 ) return;
141078 if( iDb<0 ) return;
141097 zDb = pId2->n>0 ? pDb->zDbSName : 0;
141117 aFcntl[0] = 0;
141120 aFcntl[3] = 0;
141121 db->busyHandler.nBusy = 0;
141125 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, aFcntl[0], SQLITE_TRANSIENT);
141126 returnSingleText(v, aFcntl[0]);
141127 sqlite3_free(aFcntl[0]);
141131 if( aFcntl[0] ){
141132 sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
141133 sqlite3_free(aFcntl[0]);
141142 if( pPragma==0 ){
141149 if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){
141154 if( (pPragma->mPragFlg & PragFlg_NoColumns)==0
141155 && ((pPragma->mPragFlg & PragFlg_NoColumns1)==0 || zRight==0)
141183 { OP_Transaction, 0, 0, 0}, /* 0 */
141184 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
141185 { OP_IfPos, 1, 8, 0},
141186 { OP_Integer, 0, 2, 0},
141188 { OP_IfPos, 1, 8, 0},
141189 { OP_Integer, 0, 1, 0}, /* 6 */
141190 { OP_Noop, 0, 0, 0},
141191 { OP_ResultRow, 1, 1, 0},
141199 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
141200 aOp[0].p1 = iDb;
141205 sqlite3BeginWriteOperation(pParse, 0, iDb);
141207 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
141227 assert( pBt!=0 );
141229 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
141236 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,0,0) ){
141254 assert( pBt!=0 );
141256 if( sqlite3_stricmp(zRight, "fast")==0 ){
141259 b = sqlite3GetBoolean(zRight, 0);
141262 if( pId2->n==0 && b>=0 ){
141264 for(ii=0; ii<db->nDb; ii++){
141292 i64 x = 0;
141295 if( sqlite3Tolower(zLeft[0])=='p' ){
141298 if( zRight && sqlite3DecOrHexToI64(zRight,&x)==0 ){
141299 if( x<0 ) x = 0;
141300 else if( x>0xfffffffe ) x = 0xfffffffe;
141302 x = 0;
141318 if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
141326 if( pId2->n==0 ){
141336 assert(pDb==&db->aDb[0]);
141365 if( zRight==0 ){
141372 for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){
141373 if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
141380 if( eMode==PAGER_JOURNALMODE_OFF && (db->flags & SQLITE_Defensive)!=0 ){
141386 if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){
141388 iDb = 0;
141391 for(ii=db->nDb-1; ii>=0; ii--){
141392 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
141426 ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
141431 assert( pBt!=0 );
141436 assert( eAuto>=0 && eAuto<=2 );
141452 { OP_Transaction, 0, 1, 0}, /* 0 */
141453 { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE},
141454 { OP_If, 1, 0, 0}, /* 2 */
141455 { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
141456 { OP_SetCookie, 0, BTREE_INCR_VACUUM, 0}, /* 4 */
141462 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
141463 aOp[0].p1 = iDb;
141482 int iLimit = 0, addr;
141483 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
141484 iLimit = 0x7fffffff;
141486 sqlite3BeginWriteOperation(pParse, 0, iDb);
141510 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
141544 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
141547 (db->flags & SQLITE_CacheSpill)==0 ? 0 :
141548 sqlite3BtreeSetSpillSize(pDb->pBt,0));
141554 if( sqlite3GetBoolean(zRight, size!=0) ){
141575 ** as little or as much as it wants. Except, if N is set to 0 then the
141580 #if SQLITE_MAX_MMAP_SIZE>0
141581 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
141585 if( sz<0 ) sz = sqlite3GlobalConfig.szMmap;
141586 if( pId2->n==0 ) db->szMmap = sz;
141587 for(ii=db->nDb-1; ii>=0; ii--){
141588 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
141596 sz = 0;
141644 if( zRight[0] ){
141647 if( rc!=SQLITE_OK || res==0 ){
141653 if( SQLITE_TEMP_STORE==0
141660 if( zRight[0] ){
141663 sqlite3_temp_directory = 0;
141691 if( zRight[0] ){
141694 if( rc!=SQLITE_OK || res==0 ){
141701 if( zRight[0] ){
141704 sqlite3_data_directory = 0;
141734 if( zRight[0] ){
141767 int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
141768 if( iLevel==0 ) iLevel = 1;
141780 if( zRight==0 ){
141782 returnSingleInt(v, (db->flags & pPragma->iArg)!=0 );
141785 if( db->autoCommit==0 ){
141791 if( sqlite3GetBoolean(zRight, 0) ){
141792 if( (mask & SQLITE_WriteSchema)==0
141793 || (db->flags & SQLITE_Defensive)==0
141800 db->nDeferredImmCons = 0;
141801 db->nDeferredCons = 0;
141803 if( (mask & SQLITE_WriteSchema)!=0
141804 && sqlite3_stricmp(zRight, "reset")==0
141831 ** cid: Column id (numbered from left to right, starting at 0)
141844 int nHidden = 0;
141849 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
141850 int isHidden = 0;
141853 if( pPragma->iArg==0 ){
141865 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
141866 k = 0;
141867 }else if( pPk==0 ){
141873 assert( pColExpr==0 || pColExpr->op==TK_SPAN || isHidden>=2 );
141874 assert( pColExpr==0 || !ExprHasProperty(pColExpr, EP_IntValue)
141880 pCol->notNull ? 1 : 0,
141881 (isHidden>=2 || pColExpr==0) ? 0 : pColExpr->u.zToken,
141906 for(ii=0; ii<db->nDb; ii++){
141910 if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue;
141922 if( k==0 ){ initNCol = 0; break; }
141924 if( pTab->nCol==0 ){
141927 sqlite3_stmt *pDummy = 0;
141929 &pDummy, 0);
141946 if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue;
141961 (pTab->tabFlags & TF_WithoutRowid)!=0,
141962 (pTab->tabFlags & TF_Strict)!=0
141979 0,
141987 pIdx->aiRowLogEst[0],
142000 if( pIdx==0 ){
142025 for(i=0; i<mx; i++){
142028 cnum<0 ? 0 : pTab->aCol[cnum].zCnName);
142050 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
142057 pIdx->pPartIdxWhere!=0);
142066 for(i=0; i<db->nDb; i++){
142067 if( db->aDb[i].pBt==0 ) continue;
142068 assert( db->aDb[i].zDbSName!=0 );
142078 int i = 0;
142093 int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0;
142095 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
142103 assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
142104 pragmaFunclistLine(v, p, 0, showInternFunc);
142123 for(i=0; i<ArraySize(aPragmaName); i++){
142141 int i = 0;
142146 for(j=0; j<pFK->nCol; j++){
142154 actionName(pFK->aAction[0]), /* ON DELETE */
142189 pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
142190 k = 0;
142195 if( pTab==0 || !IsOrdinaryTable(pTab) || pTab->u.tab.pFKey==0 ) continue;
142199 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
142201 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
142206 if( pParent==0 ) continue;
142207 pIdx = 0;
142208 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
142209 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
142210 if( x==0 ){
142211 if( pIdx==0 ){
142218 k = 0;
142222 assert( pParse->nErr>0 || pFK==0 );
142225 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
142229 pIdx = 0;
142230 aiCols = 0;
142233 assert( x==0 || db->mallocFailed );
142242 for(j=0; j<pFK->nCol; j++){
142244 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
142251 sqlite3VdbeAddOp4(v, OP_Affinity, regRow, pFK->nCol, 0,
142264 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
142266 sqlite3VdbeAddOp2(v, OP_Null, 0, regResult+1);
142273 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
142287 sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
142324 Table *pObjTab = 0; /* Check only this one table, if not NULL */
142326 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
142334 ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb
142337 assert( iDb>=0 );
142338 assert( iDb==0 || pId2->z );
142339 if( pId2->z==0 ) iDb = -1;
142348 if( mxErr<=0 ){
142352 pObjTab = sqlite3LocateTable(pParse, 0, zRight,
142353 iDb>=0 ? db->aDb[iDb].zDbSName : 0);
142359 for(i=0; i<db->nDb; i++){
142363 int cnt = 0; /* Number of entries in aRoot[] */
142366 if( iDb>=0 && i!=iDb ) continue;
142369 pParse->okConstFactor = 0; /* tag-20230327-1 */
142376 assert( sqlite3SchemaMutexHeld(db, i, 0) );
142378 for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
142384 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
142386 if( cnt==0 ) continue;
142389 if( aRoot==0 ) break;
142390 cnt = 0;
142391 if( pObjTab ) aRoot[++cnt] = 0;
142401 aRoot[0] = cnt;
142405 sqlite3VdbeAddOp3(v, OP_Null, 0, 8, 8+cnt);
142412 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
142420 cnt = pObjTab ? 1 : 0;
142423 int iTab = 0;
142437 if( pIdx->pPartIdxWhere==0 ){
142438 addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+cnt, 0, 8+iTab);
142454 Index *pPrior = 0; /* Previous index */
142465 pPk = 0;
142466 r2 = 0;
142472 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
142473 1, 0, &iDataCur, &iIdxCur);
142477 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
142478 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
142479 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
142483 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
142494 for(j=0; j<pTab->nCol; j++){
142495 if( (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)==0 ) mxCol++;
142504 if( mxCol>=0 ){
142514 a1 = sqlite3VdbeAddOp4Int(v, OP_IdxGT, iDataCur, 0,r2,pPk->nKeyCol);
142520 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
142524 for(j=0; j<pPk->nKeyCol; j++){
142538 bStrict = (pTab->tabFlags & TF_Strict)!=0;
142539 for(j=0; j<pTab->nCol; j++){
142553 if( pCol->notNull==0 && !doTypeCheck ) continue;
142563 sqlite3_value *pDfltValue = 0;
142588 if( p1<0 ){
142589 sqlite3VdbeChangeP5(v, 0x0f); /* INT, REAL, TEXT, or BLOB */
142592 sqlite3VdbeChangeP5(v, 0x0d); /* INT, TEXT, or BLOB */
142604 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
142616 0x1f, /* ANY */
142617 0x18, /* BLOB */
142618 0x11, /* INT */
142619 0x11, /* INTEGER */
142620 0x13, /* REAL */
142621 0x14 /* TEXT */
142630 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
142635 sqlite3VdbeChangeP5(v, 0x1c); /* NULL, TEXT, or BLOB */
142639 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
142644 sqlite3VdbeChangeP5(v, 0x1b); /* NULL, INT, FLOAT, or BLOB */
142646 if( p1>=0 ){
142649 sqlite3VdbeAddOp4(v, OP_Affinity, 3, 1, 0, "C", P4_STATIC);
142651 sqlite3VdbeChangeP5(v, 0x1c); /* NULL, TEXT, or BLOB */
142655 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
142662 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
142663 ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
142664 if( db->mallocFailed==0 ){
142670 for(k=pCheck->nExpr-1; k>0; k--){
142671 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
142673 sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
142676 pParse->iSelfTab = 0;
142679 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
142687 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
142692 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
142715 jmp7 = sqlite3VdbeAddOp3(v, OP_Eq, 3, 0, r1+pIdx->nColumn-1);
142727 label6 = 0;
142728 for(kk=0; kk<pIdx->nKeyCol; kk++){
142730 if( label6==0 ) label6 = sqlite3VdbeMakeLabel(pParse);
142750 for(kk=0; kk<pIdx->nKeyCol; kk++){
142753 if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
142789 if( pTab->nCol<=0 ){
142790 const char *zMod = pTab->u.vtab.azArg[0];
142791 if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue;
142794 if( pTab->u.vtab.p==0 ) continue;
142796 if( NEVER(pVTab==0) ) continue;
142797 if( NEVER(pVTab->pModule==0) ) continue;
142799 if( pVTab->pModule->xIntegrity==0 ) continue;
142813 { OP_AddImm, 1, 0, 0}, /* 0 */
142814 { OP_IfNotZero, 1, 4, 0}, /* 1 */
142815 { OP_String8, 0, 3, 0}, /* 2 */
142816 { OP_ResultRow, 3, 1, 0}, /* 3 */
142817 { OP_Halt, 0, 0, 0}, /* 4 */
142818 { OP_String8, 0, 3, 0}, /* 5 */
142819 { OP_Goto, 0, 3, 0}, /* 6 */
142825 aOp[0].p2 = 1-mxErr;
142831 sqlite3VdbeChangeP3(v, 0, sqlite3VdbeCurrentAddr(v)-2);
142871 { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
142872 { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
142873 { 0, 0 }
142888 if( (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){
142889 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
142890 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
142942 if( zRight && (pPragma->mPragFlg & PragFlg_ReadOnly)==0 ){
142945 { OP_Transaction, 0, 1, 0}, /* 0 */
142946 { OP_SetCookie, 0, 0, 0}, /* 1 */
142950 aOp = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
142951 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
142952 aOp[0].p1 = iDb;
142957 if( iCookie==BTREE_SCHEMA_VERSION && (db->flags & SQLITE_Defensive)!=0 ){
142965 { OP_Transaction, 0, 0, 0}, /* 0 */
142966 { OP_ReadCookie, 0, 1, 0}, /* 1 */
142967 { OP_ResultRow, 1, 1, 0}
142971 aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0);
142972 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
142973 aOp[0].p1 = iDb;
142990 int i = 0;
142993 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
143012 if( sqlite3StrICmp(zRight, "full")==0 ){
143014 }else if( sqlite3StrICmp(zRight, "restart")==0 ){
143016 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
143040 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
143072 ** 0x00001 Debugging mode. Do not actually perform any optimizations
143076 ** 0x00002 Run ANALYZE on tables that might benefit. On by default.
143079 ** 0x00010 Run all ANALYZE operations using an analysis_limit that
143088 ** 0x10000 Look at tables to see if they need to be reanalyzed
143092 ** The default MASK is and always shall be 0x0fffe. In the current
143093 ** implementation, the default mask only covers the 0x00002 optimization,
143094 ** though additional optimizations that are covered by 0x0fffe might be
143096 ** be explicitly requested have masks of 0x10000 or greater.
143103 ** (1) MASK bit 0x00002 is set.
143110 ** (4a) The 0x10000 MASK bit is set.
143141 int nCheck = 0; /* Number of tables to be optimized */
143142 int nBtree = 0; /* Number of btrees to scan */
143147 if( (opMask & 0x02)==0 ) break;
143149 opMask = 0xfffe;
143151 if( (opMask & 0x10)==0 ){
143152 nLimit = 0;
143153 }else if( db->nAnalysisLimit>0
143155 nLimit = 0;
143171 if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ) continue;
143178 nIndex = 0;
143188 ** unless the 0x10000 MASK bit is set. */
143189 if( (pTab->tabFlags & TF_MaybeReanalyze)!=0 ){
143191 }else if( opMask & 0x10000 ){
143192 /* Check for size change if 0x10000 is set */
143193 }else if( pTab->pIndex!=0 && szThreshold<0 ){
143204 sqlite3BeginWriteOperation(pParse, 0, iDb);
143212 if( szThreshold>=0 ){
143226 if( opMask & 0x01 ){
143228 sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC);
143231 sqlite3VdbeAddOp4(v, OP_SqlExec, nLimit ? 0x02 : 00, nLimit, 0,
143241 if( !db->mallocFailed && nLimit>0 && nBtree>100 ){
143246 aOp = sqlite3VdbeGetOp(v, 0);
143248 for(iAddr=0; iAddr<iEnd; iAddr++){
143261 ** then 0 is returned. Setting the busy_timeout to 0 or negative
143308 if( N>0 && (iPrior==0 || iPrior>N) ) sqlite3_hard_heap_limit64(N);
143325 && N>=0
143327 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
143344 && N>=0
143346 db->nAnalysisLimit = (int)(N&0x7fffffff);
143362 for(i=0; i<db->nDb; i++){
143366 if( db->aDb[i].zDbSName==0 ) continue;
143368 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
143370 }else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0,
143382 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
143436 PragmaVtab *pTab = 0;
143445 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
143447 for(i=0, j=pPragma->iPragCName; i<pPragma->nPragCName; i++, j++){
143451 if( i==0 ){
143455 j = 0;
143470 if( pTab==0 ){
143473 memset(pTab, 0, sizeof(PragmaVtab));
143510 if( pTab->nHidden==0 ){ return SQLITE_OK; }
143512 seen[0] = 0;
143513 seen[1] = 0;
143514 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
143517 if( pConstraint->usable==0 ) return SQLITE_CONSTRAINT;
143522 if( seen[0]==0 ){
143527 j = seen[0]-1;
143544 if( pCsr==0 ) return SQLITE_NOMEM;
143545 memset(pCsr, 0, sizeof(PragmaVtabCursor));
143555 pCsr->pPragma = 0;
143556 pCsr->iRowid = 0;
143557 for(i=0; i<ArraySize(pCsr->azArg); i++){
143559 pCsr->azArg[i] = 0;
143581 pCsr->pPragma = 0;
143605 j = (pTab->pName->mPragFlg & PragFlg_Result1)!=0 ? 0 : 1;
143606 for(i=0; i<argc; i++, j++){
143609 assert( pCsr->azArg[j]==0 );
143612 if( pCsr->azArg[j]==0 ){
143617 sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]);
143623 if( pCsr->azArg[0] ){
143624 sqlite3_str_appendf(&acc, "=%Q", pCsr->azArg[0]);
143627 if( zSql==0 ) return SQLITE_NOMEM;
143628 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pPragma, 0);
143642 return (pCsr->pPragma==0);
143674 0, /* iVersion */
143675 0, /* xCreate - create a table */
143679 0, /* xDestroy - Drop a table */
143687 0, /* xUpdate - write data */
143688 0, /* xBegin - begin transaction */
143689 0, /* xSync - sync transaction */
143690 0, /* xCommit - commit transaction */
143691 0, /* xRollback - rollback transaction */
143692 0, /* xFindFunction - function overloading */
143693 0, /* xRename - rename the table */
143694 0, /* xSavepoint */
143695 0, /* xRelease */
143696 0, /* xRollbackTo */
143697 0, /* xShadowName */
143698 0 /* xIntegrity */
143708 assert( sqlite3_strnicmp(zName, "pragma_", 7)==0 );
143710 if( pName==0 ) return 0;
143711 if( (pName->mPragFlg & (PragFlg_Result0|PragFlg_Result1))==0 ) return 0;
143712 assert( sqlite3HashFind(&db->aModule, zName)==0 );
143713 return sqlite3VtabCreateModule(db, zName, &pragmaVtabModule, (void*)pName, 0);
143751 }else if( pData->pzErrMsg[0]!=0 ){
143760 "error in %s %s after %s: %s", azObj[0], azObj[1],
143771 if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra);
143787 return 0;
143809 ** argv[0] = type of object: "table", "index", "trigger", or "view".
143812 ** argv[3] = root page number for table or index. 0 for trigger or view.
143825 if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
143828 corruptSchema(pData, argv, 0);
143832 assert( iDb>=0 && iDb<db->nDb );
143833 if( argv[3]==0 ){
143834 corruptSchema(pData, argv, 0);
143836 && 'c'==sqlite3UpperToLower[(unsigned char)argv[4][0]]
143855 if( sqlite3GetUInt32(argv[3], &db->init.newTnum)==0
143856 || (db->init.newTnum>pData->mxPage && pData->mxPage>0)
143862 db->init.orphanTrigger = 0;
143864 pStmt = 0;
143865 TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, 0);
143867 assert( (rc&0xFF)==(rcp&0xFF) );
143869 /* assert( saved_iDb==0 || (db->mDbFlags & DBFLAG_Vacuum)!=0 ); */
143877 }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){
143884 }else if( argv[1]==0 || (argv[4]!=0 && argv[4][0]!=0) ){
143885 corruptSchema(pData, argv, 0);
143895 if( pIndex==0 ){
143898 if( sqlite3GetUInt32(argv[3],&pIndex->tnum)==0
143908 return 0;
143914 ** database file is given by iDb. iDb==0 is used for the main
143930 int openedTransaction = 0;
143933 assert( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0 );
143934 assert( iDb>=0 && iDb<db->nDb );
143946 azArg[0] = "table";
143952 azArg[5] = 0;
143958 initData.nInitRow = 0;
143959 initData.mxPage = 0;
143960 sqlite3InitCallback(&initData, 5, (char **)azArg, 0);
143970 if( pDb->pBt==0 ){
143982 rc = sqlite3BtreeBeginTrans(pDb->pBt, 0, 0);
143993 ** meta[0] Schema cookie. Changes with each schema change.
144007 for(i=0; i<ArraySize(meta); i++){
144010 if( (db->flags & SQLITE_ResetDatabase)!=0 ){
144011 memset(meta, 0, sizeof(meta));
144021 if( iDb==0 && (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){
144026 if( encoding==0 ) encoding = SQLITE_UTF8;
144043 if( pDb->pSchema->cache_size==0 ){
144046 if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; }
144055 ** file_format==1 Version 3.0.0.
144058 ** file_format==4 Version 3.3.0. // DESC indices. Boolean constants
144061 if( pDb->pSchema->file_format==0 ){
144075 if( iDb==0 && meta[BTREE_FILE_FORMAT-1]>=4 ){
144092 db->xAuth = 0;
144094 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
144145 db->init.busy = 0;
144163 assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
144164 assert( db->init.busy==0 );
144166 assert( db->nDb>0 );
144168 if( !DbHasProperty(db, 0, DB_SchemaLoaded) ){
144169 rc = sqlite3InitOne(db, 0, pzErrMsg, 0);
144173 for(i=db->nDb-1; i>0; i--){
144176 rc = sqlite3InitOne(db, i, pzErrMsg, 0);
144220 for(iDb=0; iDb<db->nDb; iDb++){
144221 int openedTransaction = 0; /* True if a transaction is opened */
144223 if( pBt==0 ) continue;
144229 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
144242 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
144278 for(i=0; 1; i++){
144284 assert( i>=0 && i<db->nDb );
144294 assert( db!=0 );
144296 assert( pParse->nested==0 );
144312 db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
144352 pCleanup = 0;
144364 pPtr = 0;
144382 memset(PARSE_HDR(pParse), 0, PARSE_HDR_SZ);
144383 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
144416 memset(PARSE_HDR(&sParse), 0, PARSE_HDR_SZ);
144417 memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ);
144425 assert( sParse.pReprepare==0 );
144427 assert( ppStmt && *ppStmt==0 );
144442 sParse.prepFlags = prepFlags & 0xff;
144468 for(i=0; i<db->nDb; i++) {
144487 if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
144508 assert( 0==sParse.nQueryLoop );
144514 if( db->init.busy==0 ){
144519 sParse.checkSchema = 0;
144522 if( sParse.checkSchema && db->init.busy==0 ){
144528 assert( 0==(*ppStmt) );
144537 assert( sParse.zErrMsg==0 );
144566 int cnt = 0;
144569 if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
144571 *ppStmt = 0;
144572 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
144582 assert( rc==SQLITE_OK || *ppStmt==0 );
144585 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
144589 db->busyHandler.nBusy = 0;
144591 assert( rc==SQLITE_OK || (*ppStmt)==0 );
144613 assert( zSql!=0 ); /* Reprepare only called for prepare_v2() statements */
144617 rc = sqlite3LockAndPrepare(db, zSql, -1, prepFlags, p, &pNew, 0);
144622 assert( pNew==0 );
144625 assert( pNew!=0 );
144651 rc = sqlite3LockAndPrepare(db,zSql,nBytes,0,0,ppStmt,pzTail);
144652 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
144667 ** Proof in that the 5th parameter to sqlite3LockAndPrepare is 0 */
144668 rc = sqlite3LockAndPrepare(db,zSql,nBytes,SQLITE_PREPARE_SAVESQL,0,
144670 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 );
144691 0,ppStmt,pzTail);
144692 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 );
144714 const char *zTail8 = 0;
144718 if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
144720 *ppStmt = 0;
144721 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
144730 if( nBytes>=0 ){
144733 for(sz=0; sz<nBytes && (z[sz]!=0 || z[sz+1]!=0); sz += 2){}
144738 for(sz=0; z[sz]!=0 || z[sz+1]!=0; sz += 2){}
144745 rc = sqlite3LockAndPrepare(db, zSql8, -1, prepFlags, 0, ppStmt, &zTail8);
144779 rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
144780 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
144792 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
144807 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
144838 u8 isTnct; /* 0: Not distinct. 1: DISTICT 2: DISTINCT and ORDER BY */
144887 #define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
144894 ** If bFree==0, Leave the first Select object unfreed
144897 assert( db!=0 );
144929 pDest->iSDParm2 = 0;
144930 pDest->zAffSdst = 0;
144931 pDest->iSdst = 0;
144932 pDest->nSdst = 0;
144954 if( pNew==0 ){
144958 if( pEList==0 ){
144959 pEList = sqlite3ExprListAppend(pParse, 0,
144960 sqlite3Expr(pParse->db,TK_ASTERISK,0));
144965 pNew->iLimit = 0;
144966 pNew->iOffset = 0;
144968 pNew->addrOpenEphm[0] = -1;
144970 pNew->nSelectRow = 0;
144971 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(pParse->db, SZ_SRCLIST_1);
144977 pNew->pPrior = 0;
144978 pNew->pNext = 0;
144980 pNew->pWith = 0;
144982 pNew->pWin = 0;
144983 pNew->pWinDefn = 0;
144987 pAllocated = 0;
144989 assert( pNew->pSrc!=0 || pParse->nErr>0 );
145077 int jointype = 0;
145087 /* (0) natural */ { 0, 7, JT_NATURAL },
145096 apAll[0] = pA;
145099 for(i=0; i<3 && apAll[i]; i++){
145101 for(j=0; j<ArraySize(aKeyword); j++){
145103 && sqlite3StrNICmp((char*)p->z, &zKeyText[aKeyword[j].i], p->n)==0 ){
145108 testcase( j==0 || j==1 || j==2 || j==3 || j==4 || j==5 || j==6 );
145116 (jointype & JT_ERROR)!=0 ||
145121 if( pB==0 ){ zSp1++; }
145122 if( pC==0 ){ zSp2++; }
145148 && sqlite3StrICmp(aCol[i].zCnName, zCol)==0
145154 i = 0;
145157 && sqlite3StrICmp(aCol[i].zCnName, zCol)==0
145171 assert( pItem!=0 );
145176 assert( pItem->u4.pSubq!=0 );
145177 assert( pItem->u4.pSubq->pSelect!=0 );
145179 assert( pResults!=0 );
145180 assert( iCol>=0 && iCol<pResults->nExpr );
145208 assert( iStart>=0 );
145209 assert( (piTab==0)==(piCol==0) ); /* Both or neither are NULL */
145213 if( iCol>=0
145214 && (bIgnoreHidden==0 || IsHiddenColumn(&pSrc->a[i].pSTab->aCol[iCol])==0)
145224 return 0;
145264 for(i=0; i<p->x.pList->nExpr; i++){
145279 ** an ordinary term that omits the EP_OuterON mark. Or if iTable<0, then
145290 if( iTable<0 || (ExprHasProperty(p, EP_OuterON) && p->w.iJoin==iTable) ){
145292 if( iTable>=0 ) ExprSetProperty(p, EP_InnerON);
145299 assert( p->pLeft==0 );
145302 for(i=0; i<p->x.pList->nExpr; i++){
145328 ** entries 0 and 1. Any ON or USING clauses associated with the join are
145340 pLeft = &pSrc->a[0];
145342 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
145346 if( NEVER(pLeft->pSTab==0 || pRightTab==0) ) continue;
145347 joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_OuterON : EP_InnerON;
145353 IdList *pUsing = 0;
145356 "an ON or USING clause", 0);
145359 for(j=0; j<pRightTab->nCol; j++){
145364 if( tableAndColumnIndex(pSrc, 0, i, zName, 0, 0, 1) ){
145365 pUsing = sqlite3IdListAppend(pParse, pUsing, 0);
145367 assert( pUsing->nId>0 );
145368 assert( pUsing->a[pUsing->nId-1].zName==0 );
145391 assert( pList!=0 );
145392 for(j=0; j<pList->nId; j++){
145403 if( iRightCol<0
145404 || tableAndColumnIndex(pSrc, 0, i, zName, &iLeft, &iLeftCol,
145405 pRight->fg.isSynthUsing)==0
145413 if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 && pParse->nErr==0 ){
145427 ExprList *pFuncArgs = 0; /* Arguments to the coalesce() */
145429 assert( pE1!=0 );
145432 pRight->fg.isSynthUsing)!=0 ){
145433 if( pSrc->a[iLeft].fg.isUsing==0
145434 || sqlite3IdListIndex(pSrc->a[iLeft].u3.pUsing, zName)<0
145446 pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0);
145451 }else if( (pSrc->a[i+1].fg.jointype & JT_LEFT)!=0 && pParse->nErr==0 ){
145452 assert( pE1!=0 );
145458 assert( pE2!=0 || pEq==0 );
145475 pRight->u3.pOn = 0;
145479 return 0;
145506 0, pInfo->ecelFlags);
145509 sqlite3ExprCodeExprList(pParse, pInfo->pExtra, pInfo->regExtraResult, 0, 0);
145552 int bSeq = ((pSort->sortFlags & SORTFLAG_UseSorter)==0);
145556 int regRecord = 0; /* Assembled sorter record */
145560 int iSkip = 0; /* End of the sorter insert loop */
145562 assert( bSeq==0 || bSeq==1 );
145574 ** regOrigData is 0 to prevent this routine from trying to copy
145577 assert( nData==1 || regData==regOrigData || regOrigData==0 );
145590 assert( pSelect->iOffset==0 || pSelect->iLimit!=0 );
145594 SQLITE_ECEL_DUP | (regOrigData? SQLITE_ECEL_REF : 0));
145598 if( nPrefixReg==0 && nData>0 ){
145601 if( nOBSat>0 ){
145624 memset(pKI->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */
145629 pOp = 0; /* Ensure pOp not used after sqlite3VdbeAddOp3() */
145631 sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
145663 sqlite3VdbeAddOp2(v, OP_Last, iCsr, 0);
145665 iCsr, 0, regBase+nOBSat, nExpr-nOBSat);
145669 if( regRecord==0 ){
145696 if( iOffset>0 ){
145753 int iRet = 0;
145768 for(i=0; i<nResultCol; i++){
145835 if( pParse->nErr==0
145888 int nDefer = 0;
145889 ExprList *pExtra = 0;
145890 for(i=0; i<pEList->nExpr; i++){
145892 if( pItem->u.x.iOrderByCol==0 ){
145896 && pExpr->iColumn>=0
145898 && (pTab = pExpr->y.pTab)!=0
145900 && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)!=0
145903 for(j=0; j<nDefer; j++){
145912 Index *pPk = 0;
145917 for(k=0; k<nKey; k++){
145918 Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0);
145967 int nPrefixReg = 0; /* Number of extra registers before regResult */
145976 int regOrig; /* Start of memory holding full result (or 0) */
145979 assert( p->pEList!=0 );
145981 if( pSort && pSort->pOrderBy==0 ) pSort = 0;
145982 if( pSort==0 && !hasDistinct ){
145983 assert( iContinue!=0 );
145991 if( pDest->iSdst==0 ){
146009 if( srcTab>=0 ){
146010 for(i=0; i<nResultCol; i++){
146016 ExprList *pExtra = 0;
146026 ecelFlags = 0;
146028 if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab && eDest!=SRT_Table ){
146039 if( (j = pSort->pOrderBy->a[i].u.x.iOrderByCol)>0 ){
146045 if( pExtra && pParse->db->mallocFailed==0 ){
146061 for(i=0; i<pEList->nExpr; i++){
146062 if( pEList->a[i].u.x.iOrderByCol>0
146068 regOrig = 0;
146089 && (ecelFlags & SQLITE_ECEL_OMITREF)!=0
146090 && nPrefixReg>0
146092 assert( pSort!=0 );
146093 assert( hasDistinct==0 );
146095 regOrig = 0;
146111 if( pSort==0 ){
146170 sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
146173 assert( pSort==0 );
146204 regResult+(i2<0), nResultCol-(i2<0), r1);
146205 if( i2<0 ){
146227 pDest->iSDParm2 = 0; /* Signal that any Bloom filter is unpopulated */
146235 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
146237 ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
146297 int addrTest = 0;
146309 addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0,
146318 for(i=0; i<nKey; i++){
146352 if( pSort==0 && p->iLimit ){
146363 KeyInfo *p = sqlite3DbMallocRawNN(db, SZ_KEYINFO(0) + nExtra);
146371 memset(p->aColl, 0, nExtra);
146383 assert( p->db!=0 );
146384 assert( p->nRef>0 );
146386 if( p->nRef==0 ) sqlite3DbNNFreeNN(p->db, p);
146395 assert( p->nRef>0 );
146475 ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s", zUsage));
146511 int addrOnce = 0;
146523 int nRefKey = 0;
146530 if( pSort->nOBSat==0 || nKey==1 ){
146531 ExplainQueryPlan2(addrExplain, (pParse, 0,
146535 ExplainQueryPlan2(addrExplain, (pParse, 0,
146543 assert( addrBreak<0 );
146552 for(i=0; i<pSort->nDefer; i++){
146563 sqlite3VdbeAddOp2(v, OP_Null, 0, pDest->iSdst);
146565 regRowid = 0;
146571 nColumn = 0;
146587 assert( p->iLimit==0 && p->iOffset==0 );
146589 bSeq = 0;
146595 if( p->iOffset>0 ){
146599 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
146603 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
146610 for(i=0; i<pSort->nDefer; i++){
146624 for(k=0; k<nKey; k++){
146636 for(i=nColumn-1; i>=0; i--){
146679 sqlite3VdbeAddOp3(v, OP_MakeRecord,regRow+(i2<0),nColumn-(i2<0),r1);
146680 if( i2<0 ){
146757 char const *zType = 0;
146760 char const *zOrigDb = 0;
146761 char const *zOrigTab = 0;
146762 char const *zOrigCol = 0;
146765 assert( pExpr!=0 );
146766 assert( pNC->pSrcList!=0 );
146773 Table *pTab = 0; /* Table structure column is extracted from */
146774 Select *pS = 0; /* Select the column is extracted from */
146778 for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
146784 pS = 0;
146791 if( pTab==0 ){
146819 && (!ViewCanHaveRowid || iCol>=0)
146836 if( iCol<0 ) iCol = pTab->iPKey;
146837 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
146838 if( iCol<0 ){
146843 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
146851 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
146852 if( iCol<0 ){
146855 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
146872 p = pS->pEList->a[0].pExpr;
146908 sNC.pNext = 0;
146909 for(i=0; i<pEList->nExpr; i++){
146913 const char *zOrigDb = 0;
146914 const char *zOrigTab = 0;
146915 const char *zOrigCol = 0;
146926 zType = columnType(&sNC, p, 0, 0, 0);
146980 TREETRACE(0x80,pParse,pSelect,("generating column names\n"));
146983 assert( v!=0 );
146984 assert( pTabList!=0 );
146986 fullName = (db->flags & SQLITE_FullColNames)!=0;
146987 srcName = (db->flags & SQLITE_ShortColNames)!=0 || fullName;
146989 for(i=0; i<pEList->nExpr; i++){
146992 assert( p!=0 );
146995 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
147004 assert( pTab!=0 );
147005 if( iCol<0 ) iCol = pTab->iPKey;
147006 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
147007 if( iCol<0 ){
147013 char *zName = 0;
147021 z = z==0 ? sqlite3MPrintf(db, "column%d", i+1) : sqlite3DbStrDup(db, z);
147039 ** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
147069 aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
147070 testcase( aCol==0 );
147073 nCol = 0;
147074 aCol = 0;
147080 for(i=0, pCol=aCol; i<nCol && !pParse->nErr; i++, pCol++){
147085 if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
147089 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
147091 assert( pColExpr!=0 );
147095 && ALWAYS( pColExpr->y.pTab!=0 )
147100 if( iCol<0 ) iCol = pTab->iPKey;
147101 zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
147119 cnt = 0;
147120 while( zName && (pCollide = sqlite3HashFind(&ht, zName))!=0 ){
147125 if( nName>0 ){
147126 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
147140 sqlite3ColumnPropertiesFromName(0, pCol);
147147 for(j=0; j<i; j++){
147151 *paCol = 0;
147152 *pnCol = 0;
147183 assert( pSelect!=0 );
147184 assert( (pSelect->selFlags & SF_Resolved)!=0 );
147185 assert( pTab->nCol==pSelect->pEList->nExpr || pParse->nErr>0 );
147190 memset(&sNC, 0, sizeof(sNC));
147192 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
147195 int m = 0;
147201 while( pCol->affinity<=SQLITE_AFF_NONE && pS2->pNext!=0 ){
147213 if( pCol->affinity==SQLITE_AFF_TEXT && (m&0x01)!=0 ){
147216 if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
147223 zType = columnType(&sNC, p, 0, 0, 0);
147224 if( zType==0 || pCol->affinity!=sqlite3AffinityType(zType, 0) ){
147230 zType = 0;
147251 assert( pTab->pIndex==0 );
147270 sqlite3SelectPrep(pParse, pSelect, 0);
147272 if( pParse->nErr ) return 0;
147275 if( pTab==0 ){
147276 return 0;
147279 pTab->zName = 0;
147286 return 0;
147299 if( pParse->pToplevel==0
147326 ** Only if pLimit->pLeft!=0 do the limit registers get
147332 Vdbe *v = 0;
147333 int iLimit = 0;
147343 ** The current implementation interprets "LIMIT 0" to mean
147348 assert( pLimit->pLeft!=0 );
147351 assert( v!=0 );
147355 if( n==0 ){
147357 }else if( n>=0 && p->nSelectRow>sqlite3LogEst((u64)n) ){
147393 pRet = 0;
147395 assert( iCol>=0 );
147399 if( pRet==0 && ALWAYS(iCol<p->pEList->nExpr) ){
147416 int nOrderBy = ALWAYS(pOrderBy!=0) ? pOrderBy->nExpr : 0;
147421 for(i=0; i<nOrderBy; i++){
147430 if( pColl==0 ) pColl = db->pDfltColl;
147492 int iCurrent = 0; /* The Current table */
147495 int iDistinct = 0; /* To ensure unique results if UNION */
147512 if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
147521 p->pLimit = 0;
147522 p->iLimit = p->iOffset = 0;
147526 for(i=0; ALWAYS(i<pSrc->nSrc); i++){
147550 sqlite3VdbeAddOp4(v, OP_OpenEphemeral, iQueue, pOrderBy->nExpr+2, 0,
147558 p->addrOpenEphm[0] = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iDistinct, 0);
147563 p->pOrderBy = 0;
147572 for(pFirstRec=p; ALWAYS(pFirstRec!=0); pFirstRec=pFirstRec->pPrior){
147578 if( (pFirstRec->pPrior->selFlags & SF_Recursive)==0 ) break;
147583 pSetup->pNext = 0;
147605 0, 0, pDest, addrCont, addrBreak);
147615 pFirstRec->pPrior = 0;
147618 assert( pFirstRec->pPrior==0 );
147662 int rc = 0;
147663 int bShowAll = p->pLimit==0;
147667 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
147668 assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
147672 if( p->pPrior==0 ) break;
147677 ExplainQueryPlan((pParse, 0, "SCAN %d CONSTANT ROW%s", nRow,
147680 selectInnerLoop(pParse, p, -1, 0, 0, pDest, 1, 1);
147694 while( p && (p->selFlags & SF_Recursive)!=0 ){ p = p->pPrior; }
147695 return p!=0;
147738 Select *pDelete = 0; /* Chain of simple selects to delete */
147745 assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
147750 assert( pPrior->pOrderBy==0 );
147751 assert( pPrior->pLimit==0 );
147754 assert( v!=0 ); /* The VDBE already created by calling function */
147768 if( rc>=0 ) goto multi_select_end;
147779 if( (p->selFlags & SF_Recursive)!=0 && hasAnchor(p) ){
147791 if( pPrior->pPrior==0 ){
147801 int addr = 0;
147802 int nLimit = 0; /* Initialize to suppress harmless compiler warning */
147807 TREETRACE(0x200, pParse, p, ("multiSelect UNION ALL left...\n"));
147809 pPrior->pLimit = 0;
147813 p->pPrior = 0;
147825 TREETRACE(0x200, pParse, p, ("multiSelect UNION ALL right...\n"));
147833 && nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit)
147845 u8 op = 0; /* One of the SRT_ operations to apply to self */
147858 assert( p->pLimit==0 ); /* Not allowed on leftward elements */
147865 assert( p->pOrderBy==0 );
147866 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, unionTab, 0);
147867 assert( p->addrOpenEphm[0] == -1 );
147868 p->addrOpenEphm[0] = addr;
147878 TREETRACE(0x200, pParse, p, ("multiSelect EXCEPT/UNION left...\n"));
147892 p->pPrior = 0;
147894 p->pLimit = 0;
147898 TREETRACE(0x200, pParse, p, ("multiSelect EXCEPT/UNION right...\n"));
147901 assert( p->pOrderBy==0 );
147904 p->pOrderBy = 0;
147910 p->iLimit = 0;
147911 p->iOffset = 0;
147918 if( dest.eDest!=priorOp && db->mallocFailed==0 ){
147926 0, 0, &dest, iCont, iBreak);
147930 sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
147948 assert( p->pOrderBy==0 );
147950 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0);
147951 assert( p->addrOpenEphm[0] == -1 );
147952 p->addrOpenEphm[0] = addr;
147959 TREETRACE(0x400, pParse, p, ("multiSelect INTERSECT left...\n"));
147967 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab2, 0);
147970 p->pPrior = 0;
147972 p->pLimit = 0;
147976 TREETRACE(0x400, pParse, p, ("multiSelect INTERSECT right...\n"));
147998 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
148002 0, 0, &dest, iCont, iBreak);
148006 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
148007 sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
148013 if( p->pNext==0 ){
148036 assert( p->pNext==0 );
148037 assert( p->pEList!=0 );
148044 for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
148046 if( 0==*apColl ){
148052 for(i=0; i<2; i++){
148054 if( addr<0 ){
148055 /* If [0] is unused then [1] is also unused. So we can
148057 assert( pLoop->addrOpenEphm[1]<0 );
148105 ** If regPrev>0 then it is the first register in a vector that
148107 ** if there has been no previous output. If regPrev>0 then code is
148120 int regPrev, /* Previous result register. No uniqueness if 0 */
148143 if( pParse->db->mallocFailed ) return 0;
148177 if( pDest->iSDParm2>0 ){
148178 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
148180 ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
148203 if( pDest->iSdst==0 ){
148346 int addrOutB = 0; /* Address of the output-B subroutine */
148362 KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */
148369 assert( p->pOrderBy!=0 );
148370 assert( pKeyDup==0 ); /* "Managed" code needs this. Ticket #3382. */
148373 assert( v!=0 ); /* Already thrown the error if VDBE alloc failed */
148381 assert( p->pPrior->pOrderBy==0 );
148391 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
148393 for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){
148394 assert( pItem!=0 );
148395 assert( pItem->u.x.iOrderByCol>0 );
148399 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
148400 if( pNew==0 ) return SQLITE_NOMEM_BKPT;
148419 aPermute[0] = nOrderBy;
148421 assert( pItem!=0 );
148422 assert( pItem->u.x.iOrderByCol>0 );
148428 pKeyMerge = 0;
148436 regPrev = 0;
148442 sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
148446 for(i=0; i<nExpr; i++){
148448 pKeyDup->aSortFlags[i] = 0;
148459 for(pSplit=p; pSplit->pPrior!=0 && pSplit->op==op; pSplit=pSplit->pPrior){
148471 assert( pPrior!=0 );
148472 pSplit->pPrior = 0;
148473 pPrior->pNext = 0;
148475 assert( pOrderBy!=0 || db->mallocFailed );
148476 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
148489 regLimitA = regLimitB = 0;
148492 p->pLimit = 0;
148507 addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrA, 0, addrSelectA);
148519 addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrB, 0, addrSelectB);
148524 p->iOffset = 0;
148617 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
148635 pPrior->pOrderBy = 0;
148640 return pParse->nErr!=0;
148710 if( pExpr==0 ) return 0;
148722 if( pExpr->iColumn<0 ){
148732 assert( iColumn>=0 );
148733 assert( pSubst->pEList!=0 && iColumn<pSubst->pEList->nExpr );
148734 assert( pExpr->pRight==0 );
148743 memset(&ifNullRow, 0, sizeof(ifNullRow));
148752 pNew = sqlite3ExprDup(db, pCopy, 0);
148815 if( pList==0 ) return;
148816 for(i=0; i<pList->nExpr; i++){
148836 assert( pSrc!=0 );
148837 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
148845 }while( doPrior && (p = p->pPrior)!=0 );
148862 if( pExpr->iColumn<0 ) return WRC_Continue;
148871 if( NEVER(pSrcItem->pSTab==0) ) return;
148872 memset(&w, 0, sizeof(w));
148876 pSrcItem->colUsed = 0;
148890 ** existing cursor numbers in pSrc. aCsrMap[0] is the array size.
148903 for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
148906 assert( pItem->iCursor < aCsrMap[0] );
148907 if( !pItem->fg.isRecursive || aCsrMap[pItem->iCursor+1]==0 ){
148926 if( iCsr < aCsrMap[0] && aCsrMap[iCsr+1]>0 ){
148972 memset(&w, 0, sizeof(w));
148999 assert( p!=0 );
149000 assert( p->pEList!=0 );
149001 assert( p->pPrior!=0 );
149003 for(ii=0; ii<pList->nExpr; ii++){
149006 assert( pList->a[ii].pExpr!=0 );
149009 assert( pSub1->pEList!=0 );
149011 assert( pSub1->pEList->a[ii].pExpr!=0 );
149017 return 0;
149023 ** This routine returns 1 if it makes changes and 0 if no flattening occurs.
149188 ** If flattening is not attempted, this routine is a no-op and returns 0.
149208 int isOuterJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
149214 int *aCsrMap = 0;
149216 /* Check to see if flattening is permitted. Return 0 if not.
149218 assert( p!=0 );
149219 assert( p->pPrior==0 );
149220 if( OptimizationDisabled(db, SQLITE_QueryFlattener) ) return 0;
149222 assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
149227 assert( pSub!=0 );
149230 if( p->pWin || pSub->pWin ) return 0; /* Restriction (25) */
149240 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
149241 if( pSub->pLimit && pSub->pLimit->pRight ) return 0; /* Restriction (14) */
149242 if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){
149243 return 0; /* Restriction (15) */
149245 if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
149246 if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (4) */
149248 return 0; /* Restrictions (8)(9) */
149251 return 0; /* Restriction (11) */
149253 if( isAgg && pSub->pOrderBy ) return 0; /* Restriction (16) */
149254 if( pSub->pLimit && p->pWhere ) return 0; /* Restriction (19) */
149255 if( pSub->pLimit && (p->selFlags & SF_Distinct)!=0 ){
149256 return 0; /* Restriction (21) */
149259 return 0; /* Restrictions (22) */
149277 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
149279 /**** || IsVirtual(pSubSrc->a[0].pSTab) (3b)-omitted */
149280 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
149281 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
149283 return 0;
149288 assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
149289 if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
149290 return 0; /* Restriction (27a) */
149304 return 0; /* Restriction (20) */
149306 if( isAgg || (p->selFlags & SF_Distinct)!=0 || isOuterJoin>0 ){
149307 return 0; /* (17d1), (17d2), or (17f) */
149312 assert( pSub->pSrc!=0 );
149313 assert( (pSub->selFlags & SF_Recursive)==0 );
149315 if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 /* (17b) */
149322 return 0;
149324 if( iFrom>0 && (pSub1->pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
149328 return 0; /* Restrictions (17g), (27b) */
149335 for(ii=0; ii<p->pOrderBy->nExpr; ii++){
149336 if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
149341 if( (p->selFlags & SF_Recursive) ) return 0;
149344 if( compoundHasDifferentAffinities(pSub) ) return 0;
149347 if( pParse->nSelect>500 ) return 0;
149348 if( OptimizationDisabled(db, SQLITE_FlttnUnionAll) ) return 0;
149350 if( aCsrMap ) aCsrMap[0] = pParse->nTab;
149355 TREETRACE(0x4,pParse,p,("flatten %u.%p from term %d\n",
149360 TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
149369 pSub1 = 0;
149371 assert( pSubitem->fg.isSubquery==0 );
149372 assert( pSubitem->fg.fixedSchema==0 );
149375 pSubitem->zName = 0;
149376 pSubitem->zAlias = 0;
149377 assert( pSubitem->fg.isUsing!=0 || pSubitem->u3.pOn==0 );
149418 pSubitem->pSTab = 0;
149419 p->pOrderBy = 0;
149420 p->pPrior = 0;
149421 p->pLimit = 0;
149422 pNew = sqlite3SelectDup(db, p, 0);
149427 if( pNew==0 ){
149431 if( aCsrMap && ALWAYS(db->mallocFailed==0) ){
149438 TREETRACE(0x4,pParse,p,("compound-subquery flattener"
149441 assert( pSubitem->fg.isSubquery==0 );
149445 assert( pSubitem->fg.fixedSchema==0 );
149446 assert( pSubitem->fg.isSubquery==0 );
149447 assert( pSubitem->u4.zDatabase==0 );
149448 sqlite3SrcItemAttachSubquery(pParse, pSubitem, pSub1, 0);
149459 if( ALWAYS(pSubitem->pSTab!=0) ){
149468 pSubitem->pSTab = 0;
149487 u8 jointype = 0;
149489 assert( pSub!=0 );
149515 if( pSrc==0 ) break;
149522 iNewParent = pSubSrc->a[0].iCursor;
149523 for(i=0; i<nSubSrc; i++){
149525 assert( pItem->fg.isTabFunc==0 );
149528 || pItem->u4.zDatabase==0 );
149532 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
149549 if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){
149561 for(i=0; i<pOrderBy->nExpr; i++){
149562 pOrderBy->a[i].u.x.iOrderByCol = 0;
149564 assert( pParent->pOrderBy==0 );
149566 pSub->pOrderBy = 0;
149569 pSub->pWhere = 0;
149570 if( isOuterJoin>0 ){
149581 if( db->mallocFailed==0 ){
149589 substSelect(&x, pParent, 0);
149595 assert( (pSub->selFlags & SF_Distinct)==0 ); /* restriction (17b) */
149605 pSub->pLimit = 0;
149610 for(i=0; i<nSubSrc; i++){
149622 if( sqlite3TreeTrace & 0x4 ){
149623 TREETRACE(0x4,pParse,p,("After flattening:\n"));
149624 sqlite3TreeViewSelect(0, p, 0);
149667 if( sqlite3ExprAffinity(pValue)!=0 ) return;
149674 for(i=0; i<pConst->nConst; i++){
149691 if( pConst->apExpr==0 ){
149692 pConst->nConst = 0;
149707 if( NEVER(pExpr==0) ) return;
149721 assert( pRight!=0 );
149722 assert( pLeft!=0 );
149746 if( pConst->pOomFault[0] ) return WRC_Prune;
149754 for(i=0; i<pConst->nConst; i++){
149767 assert( pExpr->pLeft==0 );
149768 pExpr->pLeft = sqlite3ExprDup(pConst->pParse->db, pConst->apExpr[i*2+1], 0);
149801 propagateConstantExprRewriteOne(pConst, pExpr->pLeft, 0);
149802 if( pConst->pOomFault[0] ) return WRC_Prune;
149804 propagateConstantExprRewriteOne(pConst, pExpr->pRight, 0);
149868 int nChng = 0;
149872 x.nConst = 0;
149873 x.nChng = 0;
149874 x.apExpr = 0;
149875 x.bHasAffBlob = 0;
149876 if( ALWAYS(p->pSrc!=0)
149877 && p->pSrc->nSrc>0
149878 && (p->pSrc->a[0].fg.jointype & JT_LTORJ)!=0
149889 memset(&w, 0, sizeof(w));
149893 w.xSelectCallback2 = 0;
149894 w.walkerDepth = 0;
149910 ** if it is safe and the expression should be pushed down, or 0
149926 assert( (pSubq->selFlags & SF_MultiPart)==0 );
149927 assert( pSubq->pPrior==0 );
150039 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
150051 int nChng = 0;
150053 if( pWhere==0 ) return 0;
150055 return 0; /* restrictions (2) and (11) */
150058 return 0; /* restrictions (10) */
150063 int notUnionAll = 0;
150072 if( pSel->pWin ) return 0; /* restriction (6b) */
150082 assert( pList!=0 );
150083 for(ii=0; ii<pList->nExpr; ii++){
150086 return 0; /* Restriction (8) */
150093 if( pSubq->pWin && pSubq->pWin->pPartition==0 ) return 0;
150105 assert( (pX->selFlags & (SF_Recursive))==0 );
150110 if( pSubq->pLimit!=0 ){
150111 return 0; /* restriction (3) */
150118 #if 0 /* These checks now done by sqlite3ExprIsSingleTableConstraint() */
150120 && (pSrcList->a[0].fg.jointype & JT_LTORJ)!=0 /* Fast pre-test of (9c) */
150123 for(jj=0; jj<iSrc; jj++){
150129 if( (pSrcList->a[jj].fg.jointype & JT_RIGHT)!=0 ){
150130 return 0; /* restriction (9) */
150137 && (ExprHasProperty(pWhere,EP_OuterON)==0
150140 return 0; /* restriction (4) */
150145 return 0; /* restriction (5) */
150154 && pLeft->iColumn < 0
150156 return 0; /* Restriction (12) */
150166 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
150171 x.isOuterJoin = 0;
150176 if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
150208 int nChng = 0; /* Number of columns converted to NULL */
150211 assert( pItem!=0 );
150213 return 0;
150215 assert( pItem->pSTab!=0 );
150221 if( (pX->selFlags & (SF_Distinct|SF_Aggregate))!=0 ){
150224 return 0;
150229 return 0;
150235 return 0;
150242 for(j=0; j<pList->nExpr; j++){
150244 if( iCol>0 ){
150251 for(j=0; j<nCol; j++){
150253 if( (m & colUsed)!=0 ) continue;
150288 u8 sortFlags = 0;
150290 assert( *ppMinMax==0 );
150295 if( pEList==0
150304 if( sqlite3StrICmp(zFunc, "min")==0 ){
150306 if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){
150309 }else if( sqlite3StrICmp(zFunc, "max")==0 ){
150315 *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
150316 assert( pOrderBy!=0 || db->mallocFailed );
150317 if( pOrderBy ) pOrderBy->a[0].fg.sortFlags = sortFlags;
150347 || p->pSrc->a[0].fg.isSubquery
150351 return 0;
150353 pTab = p->pSrc->a[0].pSTab;
150354 assert( pTab!=0 );
150356 if( !IsOrdinaryTable(pTab) ) return 0;
150357 pExpr = p->pEList->a[0].pExpr;
150358 assert( pExpr!=0 );
150359 if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
150360 if( pExpr->pAggInfo!=pAggInfo ) return 0;
150361 if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0;
150362 assert( pAggInfo->aFunc[0].pFExpr==pExpr );
150365 if( ExprHasProperty(pExpr, EP_Distinct|EP_WinFunc) ) return 0;
150381 assert( pTab!=0 );
150382 assert( pFrom->fg.isIndexedBy!=0 );
150389 sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
150393 assert( pFrom->fg.isCte==0 );
150429 if( p->pPrior==0 ) return WRC_Continue;
150430 if( p->pOrderBy==0 ) return WRC_Continue;
150432 if( pX==0 ) return WRC_Continue;
150440 if( a[0].u.x.iOrderByCol ) return WRC_Continue;
150442 for(i=p->pOrderBy->nExpr-1; i>=0; i--){
150445 if( i<0 ) return WRC_Continue;
150452 if( pNew==0 ) return WRC_Abort;
150453 memset(&dummy, 0, sizeof(dummy));
150454 pNewSrc = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&dummy,pNew,0);
150455 assert( pNewSrc!=0 || pParse->nErr );
150462 p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ASTERISK, 0));
150464 p->pWhere = 0;
150465 pNew->pGroupBy = 0;
150466 pNew->pHaving = 0;
150467 pNew->pOrderBy = 0;
150468 p->pPrior = 0;
150469 p->pNext = 0;
150470 p->pWith = 0;
150472 p->pWinDefn = 0;
150475 assert( (p->selFlags & SF_Converted)==0 );
150477 assert( pNew->pPrior!=0 );
150479 pNew->pLimit = 0;
150493 return 0;
150514 assert( pItem->fg.fixedSchema || pItem->u4.zDatabase==0 );
150515 assert( zName!=0 );
150518 for(i=0; i<p->nCte; i++){
150519 if( sqlite3StrICmp(zName, p->a[i].zName)==0 ){
150526 return 0;
150536 ** bFree==0, the With object will be freed along with the SELECT
150551 if( pWith==0 ) return 0;
150553 if( pParse->nErr==0 ){
150572 ** Return 0 if no match is found.
150584 assert( pFrom->pSTab==0 );
150585 if( pParse->pWith==0 ){
150587 return 0;
150592 return 0;
150594 assert( pFrom->fg.hadSchema==0 || pFrom->fg.notCte!=0 );
150595 if( pFrom->fg.fixedSchema==0 && pFrom->u4.zDatabase!=0 ){
150598 return 0;
150606 return 0;
150631 assert( pFrom->pSTab==0 );
150633 if( pTab==0 ) return 2;
150635 if( pCteUse==0 ){
150636 pCte->pUse = pCteUse = sqlite3DbMallocZero(db, sizeof(pCteUse[0]));
150637 if( pCteUse==0
150638 || sqlite3ParserAddCleanup(pParse,sqlite3DbFree,pCteUse)==0
150655 assert( pSel!=0 );
150672 assert( pRecTerm->pPrior!=0 );
150673 for(i=0; i<pSrc->nSrc; i++){
150675 if( pItem->zName!=0
150678 && (pItem->fg.fixedSchema || pItem->u4.zDatabase==0)
150679 && 0==sqlite3StrICmp(pItem->zName, pCte->zName)
150691 if( iRecTab<0 ) iRecTab = pParse->nTab++;
150695 if( (pRecTerm->selFlags & SF_Recursive)==0 ) break;
150704 assert( pRecTerm!=0 );
150705 assert( (pRecTerm->selFlags & SF_Recursive)==0 );
150706 assert( pRecTerm->pNext!=0 );
150707 assert( (pRecTerm->pNext->selFlags & SF_Recursive)!=0 );
150708 assert( pRecTerm->pWith==0 );
150711 pRecTerm->pWith = 0;
150746 pCte->zCteErr = 0;
150750 return 0; /* No match */
150765 if( OK_IF_ALWAYS_TRUE(pParse->pWith) && p->pPrior==0 ){
150767 if( pWith!=0 ){
150787 assert( pFrom->u4.pSubq!=0 );
150791 if( pTab==0 ) return SQLITE_NOMEM;
150828 while( N>0 ){
150831 if( pBase->fg.isUsing==0 ) continue;
150832 if( NEVER(pBase->u3.pUsing==0) ) continue;
150833 if( sqlite3IdListIndex(pBase->u3.pUsing, zName)>=0 ) return 1;
150835 return 0;
150872 u32 elistFlags = 0;
150878 assert( p->pSrc!=0 );
150879 if( (selFlags & SF_Expanded)!=0 ){
150889 if( p->pWith==0 ){
150891 if( p->pWith==0 ){
150897 sqlite3WithPush(pParse, p->pWith, 0);
150908 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
150910 assert( pFrom->fg.isRecursive==0 || pFrom->pSTab!=0 );
150912 assert( pFrom->fg.isRecursive==0 );
150913 if( pFrom->zName==0 ){
150916 assert( pFrom->fg.isSubquery && pFrom->u4.pSubq!=0 );
150919 assert( pSel!=0 );
150920 assert( pFrom->pSTab==0 );
150925 }else if( (rc = resolveFromTermToCte(pParse, pWalker, pFrom))!=0 ){
150928 assert( pTab!=0 );
150932 assert( pFrom->pSTab==0 );
150933 pFrom->pSTab = pTab = sqlite3LocateTableItem(pParse, 0, pFrom);
150934 if( pTab==0 ) return WRC_Abort;
150935 if( pTab->nTabRef>=0xffff ){
150938 pFrom->pSTab = 0;
150950 assert( pFrom->fg.isSubquery==0 );
150952 if( (db->flags & SQLITE_EnableView)==0
150963 && ALWAYS(pTab->u.vtab.p!=0)
150964 && pTab->u.vtab.p->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
150991 assert( db->mallocFailed==0 || pParse->nErr!=0 );
151007 for(k=0; k<pEList->nExpr; k++){
151010 assert( pE->op!=TK_DOT || pE->pRight!=0 );
151011 assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) );
151022 ExprList *pNew = 0;
151024 int longNames = (flags & SQLITE_FullColNames)!=0
151025 && (flags & SQLITE_ShortColNames)==0;
151027 for(k=0; k<pEList->nExpr; k++){
151031 assert( pE->op!=TK_DOT || pRight!=0 );
151041 a[k].zEName = 0;
151043 a[k].pExpr = 0;
151047 int tableSeen = 0; /* Set to 1 when TABLE matches */
151048 char *zTName = 0; /* text of name of TABLE */
151051 assert( (selFlags & SF_NestedFrom)==0 );
151052 assert( pE->pLeft!=0 );
151061 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
151066 const char *zSchemaName = 0; /* Schema name for this data source */
151070 if( (zTabName = pFrom->zAlias)==0 ){
151077 assert( pFrom->u4.pSubq->pSelect!=0 );
151079 assert( pNestedFrom!=0 );
151081 assert( VisibleRowid(pTab)==0 || ViewCanHaveRowid );
151083 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
151086 pNestedFrom = 0;
151088 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
151092 && (selFlags & SF_NestedFrom)!=0
151096 for(ii=0; ii<pUsing->nId; ii++){
151103 assert( pX->zEName==0 );
151110 pUsing = 0;
151114 if( VisibleRowid(pTab) && (selFlags & SF_NestedFrom)!=0 ) nAdd++;
151115 for(j=0; j<nAdd; j++){
151121 if( zName==0 ) continue;
151133 && sqlite3MatchEName(&pNestedFrom->a[j], 0, zTName, 0, 0)==0
151142 if( (p->selFlags & SF_IncludeHidden)==0
151147 if( (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
151148 && zTName==0
151149 && (selFlags & (SF_NestedFrom))==0
151157 if( i>0 && zTName==0 && (selFlags & SF_NestedFrom)==0 ){
151159 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
151168 && ( (pFrom->fg.jointype & JT_LTORJ)==0
151169 || (selFlags & SF_NestedFrom)!=0
151190 if( pNew==0 ){
151194 assert( pX->zEName==0 );
151195 if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
151199 testcase( pX->zEName==0 );
151203 testcase( pX->zEName==0 );
151207 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0)
151208 || (pUsing && sqlite3IdListIndex(pUsing, zName)>=0)
151239 if( (elistFlags & (EP_HasFunc|EP_Subquery))!=0 ){
151244 if( sqlite3TreeTrace & 0x8 ){
151245 TREETRACE(0x8,pParse,p,("After result-set wildcard expansion:\n"));
151246 sqlite3TreeViewSelect(0, p, 0);
151259 assert( 0 );
151281 w.xSelectCallback2 = 0;
151286 w.eCode = 0;
151316 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
151318 assert( pTab!=0 );
151319 if( (pTab->tabFlags & TF_Ephemeral)!=0 && pFrom->fg.isSubquery ){
151365 assert( p!=0 || pParse->db->mallocFailed );
151384 for(ii=0; ii<pAggInfo->nColumn; ii++){
151393 sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0);
151395 for(ii=0; ii<pAggInfo->nFunc; ii++){
151398 sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pFExpr, 0);
151425 assert( pAggInfo!=0 );
151426 assert( pAggInfo->iFirstReg==0 );
151428 for(i=0; i<pAggInfo->nFunc; i++){
151461 assert( pAggInfo->iFirstReg==0 );
151462 assert( pSelect!=0 );
151463 assert( pSelect->pGroupBy!=0 );
151465 if( ALWAYS(pAggInfo->nSortingColumn>0) ){
151468 for(j=0; j<pAggInfo->nColumn; j++){
151476 if( sqlite3TreeTrace & 0x20 ){
151478 TREETRACE(0x20, pParse, pSelect,
151480 sqlite3TreeViewSelect(0, pSelect, 0);
151484 sqlite3TreeViewExpr(0, pIEpr->pExpr, 0);
151501 if( pExpr->pAggInfo==0 ) return WRC_Continue;
151507 assert( pExpr->iAgg>=0 );
151524 memset(&w, 0, sizeof(w));
151526 for(i=0; i<pAggInfo->nFunc; i++){
151550 assert( pAggInfo!=0 );
151551 assert( pAggInfo->iFirstReg==0 );
151569 assert( pAggInfo->iFirstReg>0 );
151571 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
151572 if( nReg==0 ) return;
151574 sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->iFirstReg,
151576 for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
151577 if( pFunc->iDistinct>=0 ){
151580 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
151585 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pE->x.pList,0,0);
151587 pFunc->iDistinct, 0, 0, (char*)pKeyInfo, P4_KEYINFO);
151588 ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s(DISTINCT)",
151592 if( pFunc->iOBTab>=0 ){
151595 int nExtra = 0;
151596 assert( pFunc->pFExpr->pLeft!=0 );
151599 assert( pFunc->pFunc!=0 );
151612 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOBList, 0, nExtra);
151613 if( !pFunc->bOBUnique && pParse->nErr==0 ){
151617 pFunc->iOBTab, pOBList->nExpr+nExtra, 0,
151619 ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s(ORDER BY)",
151633 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
151638 if( pF->iOBTab>=0 ){
151649 assert( pF->pFunc!=0 );
151653 if( pF->bOBPayload==0 ){
151654 nKey = 0;
151656 assert( pF->pFExpr->pLeft!=0 );
151658 assert( pF->pFExpr->pLeft->x.pList!=0 );
151663 for(j=nArg-1; j>=0; j--){
151668 int iBaseCol = nKey + nArg + (pF->bOBPayload==0 && pF->bOBUnique==0);
151669 for(j=nArg-1; j>=0; j--){
151675 sqlite3VdbeAddOp3(v, OP_AggStep, 0, regAgg, AggInfoFuncReg(pAggInfo,i));
151683 pList ? pList->nExpr : 0);
151694 ** registers if register regAcc contains 0. The caller will take care
151712 int regHit = 0;
151713 int addrHitTest = 0;
151717 assert( pAggInfo->iFirstReg>0 );
151720 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
151722 int addrNext = 0;
151724 int regAggSz = 0;
151725 int regDistinct = 0;
151729 assert( pF->pFunc!=0 );
151737 /* If regAcc==0, there there exists some min() or max() function
151740 if( regHit==0 ) regHit = ++pParse->nMem;
151741 /* If this is the first row of the group (regAcc contains 0), clear the
151753 if( pF->iOBTab>=0 ){
151758 assert( pList!=0 );
151760 assert( nArg>0 );
151761 assert( pF->pFExpr->pLeft!=0 );
151765 assert( pOBList!=0 );
151766 assert( pOBList->nExpr>0 );
151780 sqlite3ExprCodeExprList(pParse, pOBList, regAgg, 0, SQLITE_ECEL_DUP);
151788 sqlite3ExprCodeExprList(pParse, pList, regDistinct, 0, SQLITE_ECEL_DUP);
151794 for(kk=0; kk<nArg; kk++, jj++){
151802 sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
151804 nArg = 0;
151805 regAgg = 0;
151807 if( pF->iDistinct>=0 && pList ){
151808 if( addrNext==0 ){
151814 if( pF->iOBTab>=0 ){
151824 CollSeq *pColl = 0;
151827 assert( pList!=0 ); /* pList!=0 if pF->pFunc has NEEDCOLL */
151828 for(j=0, pItem=pList->a; !pColl && j<nArg; j++, pItem++){
151834 if( regHit==0 && pAggInfo->nAccumulator ) regHit = ++pParse->nMem;
151835 sqlite3VdbeAddOp4(v, OP_CollSeq, regHit, 0, 0,
151838 sqlite3VdbeAddOp3(v, OP_AggStep, 0, regAgg, AggInfoFuncReg(pAggInfo,i));
151848 if( regHit==0 && pAggInfo->nAccumulator ){
151854 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
151859 pAggInfo->directMode = 0;
151876 int bCover = (pIdx!=0 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pIdx)));
151877 sqlite3VdbeExplain(pParse, 0, "SCAN %s%s%s",
151910 && ExprAlwaysFalse(pExpr)==0
151911 && pExpr->pAggInfo==0
151945 memset(&sWalker, 0, sizeof(sWalker));
151951 if( sWalker.eCode && (sqlite3TreeTrace & 0x100)!=0 ){
151952 TREETRACE(0x100,pParse,p,("Move HAVING terms into WHERE:\n"));
151953 sqlite3TreeViewSelect(0, p, 0);
151964 ** instance of that view found. If pThis is not a self-join then return 0.
151975 assert( pSel!=0 );
151976 if( pSel->selFlags & SF_PushDown ) return 0;
151982 if( pItem->zName==0 ) continue;
151983 assert( pItem->pSTab!=0 );
151984 assert( pThis->pSTab!=0 );
151986 if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
151988 if( pItem->pSTab->pSchema==0 && pSel->selId!=pS1->selId ){
152000 return 0;
152039 if( (p->selFlags & SF_Aggregate)==0 ) return 0; /* This is an aggregate */
152040 if( p->pEList->nExpr!=1 ) return 0; /* Single result column */
152041 if( p->pWhere ) return 0;
152042 if( p->pHaving ) return 0;
152043 if( p->pGroupBy ) return 0;
152044 if( p->pOrderBy ) return 0;
152045 pExpr = p->pEList->a[0].pExpr;
152046 if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */
152048 if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */
152050 if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */
152051 if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */
152052 if( ExprHasProperty(pExpr, EP_WinFunc) ) return 0;/* Not a window function */
152054 if( pFrom->fg.isSubquery==0 ) return 0; /* FROM is a subquery */
152056 if( pSub->pPrior==0 ) return 0; /* Must be a compound */
152057 if( pSub->selFlags & SF_CopyCte ) return 0; /* Not a CTE */
152059 if( pSub->op!=TK_ALL && pSub->pPrior ) return 0; /* Must be UNION ALL */
152060 if( pSub->pWhere ) return 0; /* No WHERE clause */
152061 if( pSub->pLimit ) return 0; /* No LIMIT clause */
152065 return 0; /* Not an aggregate nor DISTINCT */
152067 assert( pSub->pHaving==0 ); /* Due to the previous */
152075 pExpr = 0;
152082 pSub->pPrior = 0;
152083 pSub->pNext = 0;
152086 pSub->nSelectRow = 0;
152088 pTerm = pPrior ? sqlite3ExprDup(db, pCount, 0) : pCount;
152089 pSub->pEList = sqlite3ExprListAppend(pParse, 0, pTerm);
152090 pTerm = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
152092 if( pExpr==0 ){
152099 p->pEList->a[0].pExpr = pExpr;
152103 if( sqlite3TreeTrace & 0x200 ){
152104 TREETRACE(0x200,pParse,p,("After count-of-view optimization:\n"));
152105 sqlite3TreeViewSelect(0, p, 0);
152118 for(i=0; i<pSrc->nSrc; i++){
152121 if( p0->pSTab==p1->pSTab && 0==sqlite3_stricmp(p0->zAlias, p1->zAlias) ){
152125 && (p1->u4.pSubq->pSelect->selFlags & SF_NestedFrom)!=0
152131 return 0;
152171 if( pCteUse->eM10d==M10d_Yes ) return 0; /* (2a) */
152172 if( pCteUse->nUse>=2 && pCteUse->eM10d!=M10d_No ) return 0; /* (2b) */
152174 if( pTabList->a[0].fg.jointype & JT_LTORJ ) return 0; /* (3) */
152175 if( OptimizationDisabled(pParse->db, SQLITE_Coroutines) ) return 0; /* (4) */
152176 if( isSelfJoinView(pTabList, pItem, i+1, pTabList->nSrc)!=0 ){
152177 return 0; /* (5) */
152179 if( i==0 ){
152182 if( selFlags & SF_UpdateFrom ) return 0; /* (1c-iii) */
152185 if( selFlags & SF_UpdateFrom ) return 0; /* (1c-iii) */
152187 if( pItem->fg.jointype & (JT_OUTER|JT_CROSS) ) return 0; /* (1c-ii) */
152188 if( i==0 ) break;
152191 if( pItem->fg.isSubquery ) return 0; /* (1c-i) */
152252 ExprList *pEList = 0; /* List of columns to extract. */
152257 AggInfo *pAggInfo = 0; /* Aggregate information */
152263 ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
152269 if( p==0 || pParse->nErr ){
152272 assert( db->mallocFailed==0 );
152273 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
152275 TREETRACE(0x1,pParse,p, ("begin processing:\n", pParse->addrExplain));
152276 if( sqlite3TreeTrace & 0x10000 ){
152277 if( (sqlite3TreeTrace & 0x10001)==0x10000 ){
152278 sqlite3TreeViewLine(0, "In sqlite3Select() at %s:%d",
152286 assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistFifo );
152287 assert( p->pOrderBy==0 || pDest->eDest!=SRT_Fifo );
152288 assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistQueue );
152289 assert( p->pOrderBy==0 || pDest->eDest!=SRT_Queue );
152297 TREETRACE(0x800,pParse,p, ("dropping superfluous ORDER BY:\n"));
152298 if( sqlite3TreeTrace & 0x800 ){
152299 sqlite3TreeViewExprList(0, p->pOrderBy, 0, "ORDERBY");
152305 p->pOrderBy = 0;
152310 sqlite3SelectPrep(pParse, p, 0);
152314 assert( db->mallocFailed==0 );
152315 assert( p->pEList!=0 );
152317 if( sqlite3TreeTrace & 0x10 ){
152318 TREETRACE(0x10,pParse,p, ("after name resolution:\n"));
152319 sqlite3TreeViewSelect(0, p, 0);
152325 ** In this case, it is an error if the target object (pSrc->a[0]) name
152333 SrcItem *p0 = &p->pSrc->a[0];
152359 if( p->pWin && (sqlite3TreeTrace & 0x40)!=0 ){
152360 TREETRACE(0x40,pParse,p, ("after window rewrite:\n"));
152361 sqlite3TreeViewSelect(0, p, 0);
152366 isAgg = (p->selFlags & SF_Aggregate)!=0;
152367 memset(&sSort, 0, sizeof(sSort));
152375 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
152377 Select *pSub = pItem->fg.isSubquery ? pItem->u4.pSubq->pSelect : 0;
152383 assert( pTab!=0 );
152397 if( (pItem->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
152404 TREETRACE(0x1000,pParse,p,
152408 TREETRACE(0x1000,pParse,p,
152411 unsetJoinExpr(p->pWhere, pItem->iCursor, 0);
152419 TREETRACE(0x1000,pParse,p,
152423 TREETRACE(0x1000,pParse,p,
152430 for(j=pTabList->nSrc-1; j>=0; j--){
152438 if( pSub==0 ) continue;
152463 if( (pSub->selFlags & SF_Aggregate)!=0 ) continue;
152464 assert( pSub->pGroupBy==0 );
152492 if( pSub->pOrderBy!=0
152493 && (p->pOrderBy!=0 || pTabList->nSrc>1) /* Condition (5) */
152494 && pSub->pLimit==0 /* Condition (1) */
152495 && (pSub->selFlags & (SF_OrderByReqd|SF_Recursive))==0 /* (2) and (6) */
152496 && (p->selFlags & SF_OrderByReqd)==0 /* Condition (3) and (4) */
152499 TREETRACE(0x800,pParse,p,
152503 pSub->pOrderBy = 0;
152524 if( pSub->pOrderBy!=0
152525 && i==0
152526 && (p->selFlags & SF_ComplexResult)!=0
152528 || (pTabList->a[1].fg.jointype&(JT_OUTER|JT_CROSS))!=0)
152554 TREETRACE(0x400,pParse,p,("end compound-select processing\n"));
152555 if( (sqlite3TreeTrace & 0x400)!=0 && ExplainQueryPlanParent(pParse)==0 ){
152556 sqlite3TreeViewSelect(0, p, 0);
152559 if( p->pNext==0 ) ExplainQueryPlanPop(pParse);
152569 if( p->pWhere!=0
152575 if( sqlite3TreeTrace & 0x2000 ){
152576 TREETRACE(0x2000,pParse,p,("After constant propagation:\n"));
152577 sqlite3TreeViewSelect(0, p, 0);
152581 TREETRACE(0x2000,pParse,p,("Constant propagation not helpful\n"));
152599 for(i=0; i<pTabList->nSrc; i++){
152627 if( pItem->colUsed==0 && pItem->zName!=0 ){
152633 zDb = 0;
152643 if( pItem->fg.isSubquery==0 ) continue;
152645 assert( pSubq!=0 );
152649 if( pSubq->addrFillSub!=0 ) continue;
152665 && (pItem->fg.isCte==0
152670 if( sqlite3TreeTrace & 0x4000 ){
152671 TREETRACE(0x4000,pParse,p,
152673 sqlite3TreeViewSelect(0, p, 0);
152676 assert( pSubq->pSelect && (pSub->selFlags & SF_PushDown)!=0 );
152678 TREETRACE(0x4000,pParse,p,("WHERE-clause push-down not possible\n"));
152689 if( sqlite3TreeTrace & 0x4000 ){
152690 TREETRACE(0x4000,pParse,p,
152693 sqlite3TreeViewSelect(0, p, 0);
152710 sqlite3VdbeAddOp3(v, OP_InitCoroutine, pSubq->regReturn, 0, addrTop);
152723 }else if( pItem->fg.isCte && pItem->u2.pCteUse->addrM9e>0 ){
152735 }else if( (pPrior = isSelfJoinView(pTabList, pItem, 0, i))!=0 ){
152741 assert( pPriorSubq!=0 );
152753 int onceAddr = 0;
152762 if( pItem->fg.isCorrelated==0 ){
152782 if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
152802 sDistinct.isTnct = (p->selFlags & SF_Distinct)!=0;
152805 if( sqlite3TreeTrace & 0x8000 ){
152806 TREETRACE(0x8000,pParse,p,("After all FROM-clause analysis:\n"));
152807 sqlite3TreeViewSelect(0, p, 0);
152829 && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
152832 && p->pWin==0
152836 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
152838 for(i=0; i<pGroupBy->nExpr; i++){
152850 if( sqlite3TreeTrace & 0x20000 ){
152851 TREETRACE(0x20000,pParse,p,("Transform DISTINCT into GROUP BY:\n"));
152852 sqlite3TreeViewSelect(0, p, 0);
152868 pParse, sSort.pOrderBy, 0, pEList->nExpr);
152872 sSort.iECursor, sSort.pOrderBy->nExpr+1+pEList->nExpr, 0,
152887 for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].fg.bUsed==0; ii--){
152892 for(ii=0; ii<pEList->nExpr; ii++){
152893 if( pEList->a[ii].fg.bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
152901 if( (p->selFlags & SF_FixedLimit)==0 ){
152905 if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
152915 sDistinct.tabTnct, 0, 0,
152916 (char*)sqlite3KeyInfoFromExprList(pParse, p->pEList,0,0),
152924 if( !isAgg && pGroupBy==0 ){
152926 u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0)
152938 TREETRACE(0x2,pParse,p,("WhereBegin\n"));
152941 if( pWInfo==0 ) goto select_end;
152958 sSort.pOrderBy = 0;
152961 TREETRACE(0x2,pParse,p,("WhereBegin returns\n"));
152967 if( sSort.addrSortIndex>=0 && sSort.pOrderBy==0 ){
152981 sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
152984 sSort.labelOBLopt = 0;
153000 TREETRACE(0x2,pParse,p,("WhereEnd\n"));
153015 int sortPTab = 0; /* Pseudotable used to decode sorting results */
153016 int sortOut = 0; /* Output register from the sorter */
153017 int orderByGrp = 0; /* True if the GROUP BY and ORDER BY are the same */
153026 for(k=p->pEList->nExpr, pItem=p->pEList->a; k>0; k--, pItem++){
153027 pItem->u.x.iAlias = 0;
153029 for(k=pGroupBy->nExpr, pItem=pGroupBy->a; k>0; k--, pItem++){
153030 pItem->u.x.iAlias = 0;
153050 for(ii=0; ii<pGroupBy->nExpr; ii++){
153055 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
153060 assert( 0==sqlite3LogEst(1) );
153061 p->nSelectRow = 0;
153083 memset(&sNC, 0, sizeof(sNC));
153088 pAggInfo->nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
153103 if( p->pGroupBy==0 && p->pHaving==0 && pAggInfo->nFunc==1 ){
153104 minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pFExpr, &pMinMaxOrderBy);
153111 if( sqlite3TreeTrace & 0x20 ){
153112 TREETRACE(0x20,pParse,p,("After aggregate analysis %p:\n", pAggInfo));
153113 sqlite3TreeViewSelect(0, p, 0);
153115 sqlite3DebugPrintf("MIN/MAX Optimization (0x%02x) adds:\n", minMaxFlag);
153116 sqlite3TreeViewExprList(0, pMinMaxOrderBy, 0, "ORDERBY");
153136 ExprList *pDistinct = 0;
153137 u16 distFlag = 0;
153141 && pAggInfo->aFunc[0].iDistinct>=0
153142 && ALWAYS(pAggInfo->aFunc[0].pFExpr!=0)
153143 && ALWAYS(ExprUseXList(pAggInfo->aFunc[0].pFExpr))
153144 && pAggInfo->aFunc[0].pFExpr->x.pList!=0
153146 Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr;
153147 pExpr = sqlite3ExprDup(db, pExpr, 0);
153148 pDistinct = sqlite3ExprListDup(db, pGroupBy, 0);
153150 distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
153160 0, pAggInfo->nColumn);
153163 0, (char*)pKeyInfo, P4_KEYINFO);
153177 sqlite3VdbeAddOp2(v, OP_Integer, 0, iAbortFlag);
153179 sqlite3VdbeAddOp3(v, OP_Null, 0, iAMem, iAMem+pGroupBy->nExpr-1);
153187 TREETRACE(0x2,pParse,p,("WhereBegin\n"));
153190 | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
153192 if( pWInfo==0 ){
153201 TREETRACE(0x2,pParse,p,("WhereBegin returns\n"));
153207 groupBySort = 0;
153222 ExplainQueryPlan2(addrExp, (pParse, 0, "USE TEMP B-TREE FOR %s",
153223 (sDistinct.isTnct && (p->selFlags&SF_Distinct)==0) ?
153231 for(i=0; i<pAggInfo->nColumn; i++){
153238 sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
153241 for(i=0; i<pAggInfo->nColumn; i++){
153248 pAggInfo->directMode = 0;
153250 sqlite3VdbeScanStatusCounters(v, addrExp, 0, sqlite3VdbeCurrentAddr(v));
153256 TREETRACE(0x2,pParse,p,("WhereEnd\n"));
153260 sqlite3VdbeScanStatusCounters(v, addrExp, sqlite3VdbeCurrentAddr(v), 0);
153277 if( sqlite3TreeTrace & 0x20 ){
153278 TREETRACE(0x20, pParse, p,
153280 sqlite3TreeViewSelect(0, p, 0);
153296 sSort.pOrderBy = 0;
153301 ** (b0 is memory location iBMem+0, b1 is iBMem+1, and so forth)
153310 for(j=0; j<pGroupBy->nExpr; j++){
153323 while( ALWAYS(pBase!=0) && pBase->op==TK_IF_NULL_ROW ){
153327 if( ALWAYS(pBase!=0)
153338 sqlite3VdbeAddOp3(v, OP_Jump, addr1+1, 0, addr1+1); VdbeCoverage(v);
153371 TREETRACE(0x2,pParse,p,("WhereEnd\n"));
153415 sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
153419 if( distFlag!=0 && eDist!=WHERE_DISTINCT_NOOP ){
153420 struct AggInfo_func *pF = &pAggInfo->aFunc[0];
153427 if( (pTab = isSimpleCount(p, pAggInfo))!=0 ){
153446 KeyInfo *pKeyInfo = 0; /* Keyinfo for scanned index */
153447 Index *pBest = 0; /* Best index found so far */
153451 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
153463 if( !p->pSrc->a[0].fg.notIndexed ){
153465 if( pIdx->bUnordered==0
153467 && pIdx->pPartIdxWhere==0
153485 sqlite3VdbeAddOp2(v, OP_Count, iCsr, AggInfoFuncReg(pAggInfo,0));
153491 int regAcc = 0; /* "populate accumulators" flag */
153492 ExprList *pDistinct = 0;
153493 u16 distFlag = 0;
153498 ** will contain 0 the first time the inner loop runs, and 1 thereafter.
153506 for(i=0; i<pAggInfo->nFunc; i++){
153516 sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
153518 }else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){
153519 assert( ExprUseXList(pAggInfo->aFunc[0].pFExpr) );
153520 pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList;
153521 distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
153529 assert( p->pGroupBy==0 );
153537 assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
153538 assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
153540 TREETRACE(0x2,pParse,p,("WhereBegin\n"));
153542 pDistinct, p, minMaxFlag|distFlag, 0);
153543 if( pWInfo==0 ){
153546 TREETRACE(0x2,pParse,p,("WhereBegin returns\n"));
153560 TREETRACE(0x2,pParse,p,("WhereEnd\n"));
153565 sSort.pOrderBy = 0;
153567 selectInnerLoop(pParse, p, -1, 0, 0,
153591 ** set the return code to 1. Otherwise 0. */
153592 rc = (pParse->nErr>0);
153598 assert( db->mallocFailed==0 || db->mallocFailed==1 );
153599 assert( db->mallocFailed==0 || pParse->nErr!=0 );
153605 if( sqlite3TreeTrace & 0x20 ){
153606 TREETRACE(0x20,pParse,p,("Finished with AggInfo\n"));
153610 for(i=0; i<pAggInfo->nColumn; i++){
153612 if( pExpr==0 ) continue;
153616 for(i=0; i<pAggInfo->nFunc; i++){
153618 assert( pExpr!=0 );
153626 TREETRACE(0x1,pParse,p,("end processing\n"));
153627 if( (sqlite3TreeTrace & 0x40000)!=0 && ExplainQueryPlanParent(pParse)==0 ){
153628 sqlite3TreeViewSelect(0, p, 0);
153687 if( p->nRow==0 && argv!=0 ){
153696 if( azNew==0 ) goto malloc_failed;
153703 if( p->nRow==0 ){
153705 for(i=0; i<nCol; i++){
153707 if( z==0 ) goto malloc_failed;
153721 if( argv!=0 ){
153722 for(i=0; i<nCol; i++){
153723 if( argv[i]==0 ){
153724 z = 0;
153728 if( z==0 ) goto malloc_failed;
153735 return 0;
153764 if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT;
153766 *pazResult = 0;
153767 if( pnColumn ) *pnColumn = 0;
153768 if( pnRow ) *pnRow = 0;
153769 if( pzErrMsg ) *pzErrMsg = 0;
153770 res.zErrMsg = 0;
153771 res.nRow = 0;
153772 res.nColumn = 0;
153777 if( res.azResult==0 ){
153781 res.azResult[0] = 0;
153783 assert( sizeof(res.azResult[0])>= sizeof(res.nData) );
153784 res.azResult[0] = SQLITE_INT_TO_PTR(res.nData);
153785 if( (rc&0xff)==SQLITE_ABORT ){
153805 if( azNew==0 ){
153827 assert( azResult!=0 );
153828 n = SQLITE_PTR_TO_INT(azResult[0]);
153892 assert( pParse->disableTriggers==0 );
153900 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
153907 assert( pParse->db->pVtabCtx==0 );
153919 #if 0
153953 Trigger *pTrigger = 0; /* The new trigger */
153955 char *zName = 0; /* Name of the trigger */
153961 assert( pName1!=0 ); /* pName1->z might be NULL, but not pName1 itself */
153962 assert( pName2!=0 );
153964 assert( op>0 && op<0xff );
153967 if( pName2->n>0 ){
153976 if( iDb<0 ){
153993 assert( pTableName->a[0].fg.fixedSchema==0 );
153994 assert( pTableName->a[0].fg.isSubquery==0 );
153995 sqlite3DbFree(db, pTableName->a[0].u4.zDatabase);
153996 pTableName->a[0].u4.zDatabase = 0;
154001 ** If sqlite3SrcListLookup() returns 0, indicating the table does not
154005 if( db->init.busy==0 && pName2->n==0 && pTab
154026 if( (pTab->tabFlags & TF_Shadow)!=0 && sqlite3ReadOnlyShadowTables(db) ){
154034 if( zName==0 ){
154041 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
154056 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
154085 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
154102 if( pTrigger==0 ) goto trigger_cleanup;
154104 zName = 0;
154105 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
154111 sqlite3RenameTokenRemap(pParse, pTrigger->table, pTableName->a[0].zName);
154113 pWhen = 0;
154118 pColumns = 0;
154119 assert( pParse->pNewTrigger==0 );
154167 pParse->pNewTrigger = 0;
154188 pTrig = 0;
154205 if( pStep->zTarget!=0
154218 if( v==0 ) goto triggerfinish_cleanup;
154219 sqlite3BeginWriteOperation(pParse, 0, iDb);
154221 testcase( z==0 );
154224 " VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
154230 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName), 0);
154236 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
154237 assert( pLink!=0 );
154244 assert( pTab!=0 );
154263 if( z ) for(i=0; z[i]; i++) if( sqlite3Isspace(z[i]) ) z[i] = ' ';
154281 if( pTriggerStep==0 ) {
154283 return 0;
154308 if( pParse->nErr ) return 0;
154344 assert(pSelect != 0 || db->mallocFailed);
154350 pSelect = 0;
154395 pEList = 0;
154396 pWhere = 0;
154397 pFrom = 0;
154430 pWhere = 0;
154444 if( pTrigger==0 || pTrigger->bReturning ) return;
154462 Trigger *pTrigger = 0;
154474 assert( pName->a[0].fg.fixedSchema==0 && pName->a[0].fg.isSubquery==0 );
154475 zDb = pName->a[0].u4.zDatabase;
154476 zName = pName->a[0].zName;
154477 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
154480 if( zDb && sqlite3DbIsNamed(db, j, zDb)==0 ) continue;
154481 assert( sqlite3SchemaMutexHeld(db, j, 0) );
154519 assert( iDb>=0 && iDb<db->nDb );
154529 sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
154537 if( (v = sqlite3GetVdbe(pParse))!=0 ){
154543 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
154554 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
154556 pTrigger = sqlite3HashInsert(pHash, zName, 0);
154586 if( pIdList==0 || NEVER(pEList==0) ) return 1;
154587 for(e=0; e<pEList->nExpr; e++){
154588 if( sqlite3IdListIndex(pIdList, pEList->a[e].zEName)>=0 ) return 1;
154590 return 0;
154597 if( NEVER(db->aDb[1].pSchema==0) ) return 0;
154598 if( sqliteHashFirst(&db->aDb[1].pSchema->trigHash)==0 ) return 0;
154615 int mask = 0;
154616 Trigger *pList = 0;
154620 assert( pList==0 || IsVirtual(pTab)==0
154621 || (pList->bReturning && pList->pNext==0) );
154622 if( pList!=0 ){
154624 if( (pParse->db->flags & SQLITE_EnableTrigger)==0
154625 && pTab->pTrigger!=0
154631 pList = 0;
154635 p->pNext = 0;
154669 return (mask ? pList : 0);
154678 assert( pTab!=0 );
154679 if( (pTab->pTrigger==0 && !tempTriggersExist(pParse->db))
154682 if( pMask ) *pMask = 0;
154683 return 0;
154705 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
154706 assert( pSrc==0 || pSrc->nSrc==1 );
154707 assert( zName || pSrc==0 );
154710 pSrc->a[0].zName = zName;
154712 assert( pSrc->a[0].fg.fixedSchema || pSrc->a[0].u4.zDatabase==0 );
154713 pSrc->a[0].u4.pSchema = pSchema;
154714 pSrc->a[0].fg.fixedSchema = 1;
154717 SrcList *pDup = sqlite3SrcListDup(db, pStep->pFrom, 0);
154721 pSubquery = sqlite3SelectNew(pParse,0,pDup,0,0,0,0,SF_NestedFrom,0);
154722 as.n = 0;
154723 as.z = 0;
154724 pDup = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
154743 assert( pTerm!=0 );
154745 if( pTerm->op!=TK_DOT ) return 0;
154746 assert( pTerm->pRight!=0 );
154747 assert( pTerm->pLeft!=0 );
154748 if( pTerm->pRight->op!=TK_ASTERISK ) return 0;
154764 ExprList *pNew = 0;
154768 for(i=0; i<pList->nExpr; i++){
154770 if( NEVER(pOldExpr==0) ) continue;
154773 for(jj=0; jj<pTab->nCol; jj++){
154785 Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
154787 if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
154804 && (pExpr->x.pSelect->selFlags & SF_Correlated)!=0
154823 assert( pSelect!=0 );
154825 assert( pSrc!=0 );
154826 for(i=0; i<pSrc->nSrc; i++){
154851 memset(&w, 0, sizeof(w));
154882 assert( v!=0 );
154895 memset(&sSelect, 0, sizeof(sSelect));
154897 memset(pFrom, 0, SZ_SRCLIST_1);
154898 sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
154901 pFrom->a[0].pSTab = pTab;
154902 pFrom->a[0].zName = pTab->zName; /* tag-20240424-1 */
154903 pFrom->a[0].iCursor = -1;
154904 sqlite3SelectPrep(pParse, &sSelect, 0);
154905 if( pParse->nErr==0 ){
154906 assert( db->mallocFailed==0 );
154911 if( pParse->nErr==0 ){
154913 memset(&sNC, 0, sizeof(sNC));
154914 if( pReturning->nRetCol==0 ){
154932 for(i=0; i<nCol; i++){
154934 assert( pCol!=0 ); /* Due to !db->mallocFailed ~9 lines above */
154946 pParse->eTriggerOp = 0;
154947 pParse->pTriggerTab = 0;
154967 assert( v!=0 );
154983 assert( pParse->okConstFactor==0 );
154987 sqlite3VdbeAddOp4(v, OP_Trace, 0x7fffffff, 1, 0,
154997 sqlite3ExprListDup(db, pStep->pExprList, 0),
154998 sqlite3ExprDup(db, pStep->pWhere, 0),
154999 pParse->eOrconf, 0, 0, 0
155007 sqlite3SelectDup(db, pStep->pSelect, 0),
155018 sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0
155025 Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
155026 sqlite3SelectDestInit(&sDest, SRT_Discard, 0);
155034 return 0;
155061 assert( pFrom->zErrMsg==0 || pFrom->nErr );
155062 assert( pTo->zErrMsg==0 || pTo->nErr );
155063 if( pTo->nErr==0 ){
155085 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
155088 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
155089 int iEndTrigger = 0; /* Label to jump to if WHEN is false */
155092 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
155099 if( !pPrg ) return 0;
155103 if( !pProgram ) return 0;
155107 pPrg->aColmask[0] = 0xffffffff;
155108 pPrg->aColmask[1] = 0xffffffff;
155113 memset(&sNC, 0, sizeof(sNC));
155121 sSubParse.oldmask = 0;
155122 sSubParse.newmask = 0;
155146 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
155147 if( db->mallocFailed==0
155167 if( pParse->nErr==0 ){
155168 assert( db->mallocFailed==0 );
155174 pPrg->aColmask[0] = sSubParse.oldmask;
155201 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
155243 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
155276 ** reg+0 OLD.rowid
155314 assert( (op==TK_UPDATE)==(pChanges!=0) );
155321 assert( p->pSchema!=0 );
155322 assert( p->pTabSchema!=0 );
155351 ** Bit 0 of the returned mask is set if the left-most column of the
155355 ** with an index greater than 32 may be accessed, 0xffffffff is returned.
155360 ** Parameter isNew must be either 1 or 0. If it is 0, then the mask returned
155373 int isNew, /* 1 for new.* ref mask, 0 for old.* ref mask */
155379 u32 mask = 0;
155382 assert( isNew==1 || isNew==0 );
155384 return 0xffffffff;
155392 mask = 0xffffffff;
155472 assert( pTab!=0 );
155476 sqlite3_value *pValue = 0;
155509 int *aXRef, /* aXRef[j]>=0 if column j is being updated */
155514 if( iIdxCol>=0 ){
155515 return aXRef[iIdxCol]>=0;
155518 assert( pIdx->aColExpr!=0 );
155519 assert( pIdx->aColExpr->a[iCol].pExpr!=0 );
155538 int *aXRef, /* aXRef[j]>=0 if column j is being updated */
155541 if( pIdx->pPartIdxWhere==0 ) return 0;
155550 ** table in the source-list (pSrc->a[0]).
155553 Expr *pRet = sqlite3PExpr(pParse, TK_ROW, 0, 0);
155579 ** of table pTabList->a[0].pTab.
155599 Index *pPk, /* PK if table 0 is WITHOUT ROWID */
155608 Select *pSelect = 0;
155609 ExprList *pList = 0;
155610 ExprList *pGrp = 0;
155611 Expr *pLimit2 = 0;
155612 ExprList *pOrderBy2 = 0;
155614 Table *pTab = pTabList->a[0].pSTab;
155620 if( pOrderBy && pLimit==0 ) {
155624 pOrderBy2 = sqlite3ExprListDup(db, pOrderBy, 0);
155625 pLimit2 = sqlite3ExprDup(db, pLimit, 0);
155631 pSrc = sqlite3SrcListDup(db, pTabList, 0);
155632 pWhere2 = sqlite3ExprDup(db, pWhere, 0);
155636 assert( pSrc->a[0].fg.notCte );
155637 pSrc->a[0].iCursor = -1;
155638 pSrc->a[0].pSTab->nTabRef--;
155639 pSrc->a[0].pSTab = 0;
155642 for(i=0; i<pPk->nKeyCol; i++){
155646 pGrp = sqlite3ExprListAppend(pParse, pGrp, sqlite3ExprDup(db, pNew, 0));
155653 for(i=0; i<pTab->nCol; i++){
155659 pList = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
155662 pGrp = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
155666 assert( pChanges!=0 || pParse->db->mallocFailed );
155668 for(i=0; i<pChanges->nExpr; i++){
155670 sqlite3ExprDup(db, pChanges->a[i].pExpr, 0)
155675 pSrc, pWhere2, pGrp, 0, pOrderBy2,
155706 int addrTop = 0; /* VDBE instruction address of the start of the loop */
155707 WhereInfo *pWInfo = 0; /* Information about the WHERE clause */
155717 int *aRegIdx = 0; /* Registers for to each index and the main table */
155718 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
155725 Expr *pRowidExpr = 0; /* Expression defining the new record number */
155742 int iEph = 0; /* Ephemeral table holding all primary key values */
155743 int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */
155745 int addrOpen = 0; /* Address of OP_OpenEphemeral */
155746 int iPk = 0; /* First of nPk cells holding PRIMARY KEY value */
155747 i16 nPk = 0; /* Number of components of the PRIMARY KEY */
155748 int bReplace = 0; /* True if REPLACE conflict resolution might happen */
155750 int nChangeFrom = 0; /* If there is a FROM, pChanges->nExpr, else 0 */
155753 int regRowCount = 0; /* A count of rows changed */
155754 int regOldRowid = 0; /* The old rowid */
155755 int regNewRowid = 0; /* The new rowid */
155756 int regNew = 0; /* Content of the NEW.* table in triggers */
155757 int regOld = 0; /* Content of OLD.* table in triggers */
155758 int regRowSet = 0; /* Rowset of rows to be updated */
155759 int regKey = 0; /* composite PRIMARY KEY value */
155761 memset(&sContext, 0, sizeof(sContext));
155767 assert( db->mallocFailed==0 );
155772 if( pTab==0 ) goto update_cleanup;
155781 assert( pTrigger || tmask==0 );
155783 # define pTrigger 0
155784 # define isView 0
155785 # define tmask 0
155789 # define isView 0
155793 if( sqlite3TreeTrace & 0x10000 ){
155794 sqlite3TreeViewLine(0, "In sqlite3Update() at %s:%d", __FILE__, __LINE__);
155801 ** in the change-list. Otherwise, set it to 0. There cannot be a FROM
155804 nChangeFrom = (pTabList->nSrc>1) ? pChanges->nExpr : 0;
155805 assert( nChangeFrom==0 || pUpsert==0 );
155808 if( !isView && nChangeFrom==0 ){
155812 pOrderBy = 0;
155813 pLimit = 0;
155831 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
155832 testcase( pPk!=0 && pPk!=pTab->pIndex );
155833 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
155845 pTabList->a[0].iCursor = iDataCur;
155851 if( aXRef==0 ) goto update_cleanup;
155855 aToOpen[nIdx+1] = 0;
155856 for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
155859 memset(&sNC, 0, sizeof(sNC));
155867 if( v==0 ) goto update_cleanup;
155875 chngRowid = chngPk = 0;
155876 for(i=0; i<pChanges->nExpr; i++){
155879 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
155883 if( j>=0 ){
155888 }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
155903 if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){
155918 j<0 ? "ROWID" : pTab->aCol[j].zCnName,
155928 assert( (chngRowid & chngPk)==0 );
155929 assert( chngRowid==0 || chngRowid==1 );
155930 assert( chngPk==0 || chngPk==1 );
155946 bProgress = 0;
155947 for(i=0; i<pTab->nCol; i++){
155948 if( aXRef[i]>=0 ) continue;
155949 if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ) continue;
155967 pTabList->a[0].colUsed = IsVirtual(pTab) ? ALLBITS : 0;
155976 for(nAllIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nAllIdx++){
155984 reg = 0;
155985 for(i=0; i<pIdx->nKeyCol; i++){
155996 if( reg==0 ) aToOpen[nAllIdx+1] = 0;
156006 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
156039 if( nChangeFrom==0 && isView ){
156043 pOrderBy = 0;
156044 pLimit = 0;
156051 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pWhere) ){
156069 if( (db->flags&SQLITE_CountRows)!=0
156073 && pUpsert==0
156076 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
156079 if( nChangeFrom==0 && HasRowid(pTab) ){
156080 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
156082 addrOpen = sqlite3VdbeAddOp3(v, OP_OpenEphemeral, iEph, 0, regRowSet);
156084 assert( pPk!=0 || HasRowid(pTab) );
156085 nPk = pPk ? pPk->nKeyCol : 0;
156090 if( pUpsert==0 ){
156091 int nEphCol = nPk + nChangeFrom + (isView ? pTab->nCol : 0);
156093 if( pPk ) sqlite3VdbeAddOp3(v, OP_Null, 0, iPk, iPk+nPk-1);
156125 pWInfo = 0;
156128 bFinishSeek = 0;
156147 && (pWhere==0 || !ExprHasProperty(pWhere, EP_Subquery))
156151 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0,0,0,flags,iIdxCur);
156152 if( pWInfo==0 ) goto update_cleanup;
156170 if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){
156195 for(i=0; i<nPk; i++){
156196 assert( pPk->aiColumn[i]>=0 );
156212 if( pUpsert==0 ){
156213 if( nChangeFrom==0 && eOnePass!=ONEPASS_MULTI ){
156218 int addrOnce = 0;
156219 int iNotUsed1 = 0;
156220 int iNotUsed2 = 0;
156224 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0;
156225 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0;
156228 if( eOnePass==ONEPASS_MULTI && (nIdx-(aiCurOnePass[1]>=0))>0 ){
156231 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur,
156240 if( aiCurOnePass[0]!=iDataCur
156254 VdbeCoverageIf(v, pPk==0);
156255 VdbeCoverageIf(v, pPk!=0);
156263 for(i=0; i<nPk; i++){
156278 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey,0);
156297 assert( iRowidExpr>=0 );
156298 if( nChangeFrom==0 ){
156309 u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);
156311 pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError
156313 for(i=0; i<pTab->nCol; i++){
156316 if( oldmask==0xffffffff
156317 || (i<32 && (oldmask & MASKBIT32(i))!=0)
156318 || (colFlags & COLFLAG_PRIMKEY)!=0
156320 testcase( oldmask!=0xffffffff && i==31 );
156323 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
156326 if( chngRowid==0 && pPk==0 ){
156328 if( isView ) sqlite3VdbeAddOp2(v, OP_Null, 0, regOldRowid);
156350 for(i=0, k=regNew; i<pTab->nCol; i++, k++){
156352 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
156353 }else if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)!=0 ){
156357 if( j>=0 ){
156365 }else if( 0==(tmask&TRIGGER_BEFORE) || i>31 || (newmask & MASKBIT32(i)) ){
156374 bFinishSeek = 0;
156376 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
156420 for(i=0, k=regNew; i<pTab->nCol; i++, k++){
156423 }else if( aXRef[i]<0 && i!=pTab->iPKey ){
156439 assert( regOldRowid>0 );
156442 aXRef, 0);
156458 sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
156485 OPFLAG_ISUPDATE | ((hasFK>1 || chngKey) ? 0 : OPFLAG_ISNOOP),
156489 assert( hasFK==0 && chngKey==0 );
156497 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
156502 sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey);
156508 OPFLAG_ISUPDATE | (eOnePass==ONEPASS_MULTI ? OPFLAG_SAVEPOSITION : 0),
156509 0, 0
156549 if( pParse->nested==0 && pParse->pTriggerTab==0 && pUpsert==0 ){
156620 WhereInfo *pWInfo = 0;
156625 int iCsr = pSrc->a[0].iCursor; /* Cursor used for virtual table scan */
156639 Index *pPk = 0;
156644 pRow = sqlite3ExprDup(db, pRowid, 0);
156646 pRow = sqlite3PExpr(pParse, TK_ROW, 0, 0);
156651 assert( pPk!=0 );
156653 iPk = pPk->aiColumn[0];
156654 if( aXRef[iPk]>=0 ){
156655 pRow = sqlite3ExprDup(db, pChanges->a[aXRef[iPk]].pExpr, 0);
156660 pList = sqlite3ExprListAppend(pParse, 0, pRow);
156662 for(i=0; i<pTab->nCol; i++){
156663 if( aXRef[i]>=0 ){
156665 sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0)
156674 updateFromSelect(pParse, ephemTab, pPk, pList, pSrc, pWhere, 0, 0);
156683 pParse, pSrc, pWhere, 0, 0, 0, WHERE_ONEPASS_DESIRED, 0
156685 if( pWInfo==0 ) return;
156688 for(i=0; i<pTab->nCol; i++){
156689 assert( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 );
156690 if( aXRef[i]>=0 ){
156708 assert( pPk!=0 );
156710 iPk = pPk->aiColumn[0];
156752 for(i=0; i<nArg; i++){
156757 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, nArg, regArg, pVTab, P4_VTAB);
156766 sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
156816 if( p==0 ) return 0;
156818 sqlite3ExprListDup(db, p->pUpsertTarget, 0),
156819 sqlite3ExprDup(db, p->pUpsertTargetWhere, 0),
156820 sqlite3ExprListDup(db, p->pUpsertSet, 0),
156821 sqlite3ExprDup(db, p->pUpsertWhere, 0),
156839 if( pNew==0 ){
156845 return 0;
156851 pNew->isDoUpdate = pSet!=0;
156878 int nClause = 0; /* Counter of ON CONFLICT clauses */
156881 assert( pTabList->a[0].pSTab!=0 );
156882 assert( pUpsert!=0 );
156883 assert( pUpsert->pUpsertTarget!=0 );
156889 memset(&sNC, 0, sizeof(sNC));
156900 pTab = pTabList->a[0].pSTab;
156902 iCursor = pTabList->a[0].iCursor;
156905 && (pTerm = pTarget->a[0].pExpr)->op==TK_COLUMN
156909 assert( pUpsert->pUpsertIdx==0 );
156913 /* Initialize sCol[0..1] to be an expression parse tree for a
156914 ** single column of an index. The sCol[0] node will be the TK_COLLATE
156919 memset(sCol, 0, sizeof(sCol));
156920 sCol[0].op = TK_COLLATE;
156921 sCol[0].pLeft = &sCol[1];
156923 sCol[1].iTable = pTabList->a[0].iCursor;
156931 if( pUpsert->pUpsertTargetWhere==0 ) continue;
156933 pIdx->pPartIdxWhere, iCursor)!=0 ){
156938 for(ii=0; ii<nn; ii++){
156940 sCol[0].u.zToken = (char*)pIdx->azColl[ii];
156942 assert( pIdx->aColExpr!=0 );
156947 sCol[0].pLeft = pExpr;
156948 pExpr = &sCol[0];
156951 sCol[0].pLeft = &sCol[1];
156953 pExpr = &sCol[0];
156955 for(jj=0; jj<nn; jj++){
156956 if( sqlite3ExprCompare(0,pTarget->a[jj].pExpr,pExpr,iCursor)<2 ){
156981 if( pUpsert->pUpsertIdx==0 ){
156983 if( nClause==0 && pUpsert->pNextUpsert==0 ){
156984 zWhich[0] = 0;
157003 if( NEVER(pUpsert==0) ) return 0;
157006 if( pNext==0 ) return 1;
157007 if( pNext->pUpsertTarget==0 ) return 1;
157008 if( pNext->pUpsertIdx==0 ) return 1;
157009 if( !pNext->isDup ) return 0;
157012 return 0;
157024 && pUpsert->pUpsertTarget!=0
157055 assert( v!=0 );
157056 assert( pUpsert!=0 );
157064 sqlite3VdbeAddOp3(v, OP_SeekRowid, iDataCur, 0, regRowid);
157072 for(i=0; i<nPk; i++){
157074 assert( pPk->aiColumn[i]>=0 );
157081 i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk);
157083 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0,
157091 pSrc = sqlite3SrcListDup(db, pTop->pUpsertSrc, 0);
157093 for(i=0; i<pTab->nCol; i++){
157098 sqlite3Update(pParse, pSrc, sqlite3ExprListDup(db,pUpsert->pUpsertSet,0),
157099 sqlite3ExprDup(db,pUpsert->pUpsertWhere,0), OE_Abort, 0, 0, pUpsert);
157143 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
157146 const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0);
157147 assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 );
157154 && (strncmp(zSubSql,"CRE",3)==0 || strncmp(zSubSql,"INS",3)==0)
157175 if( z==0 ) return SQLITE_NOMEM;
157213 int iDb = 0;
157214 if( v==0 ) goto build_vacuum_end;
157221 if( iDb<0 ) goto build_vacuum_end;
157229 if( iDb<0 ) iDb = 0;
157233 int iIntoReg = 0;
157234 if( pInto && sqlite3ResolveSelfReference(pParse,0,0,pInto,0)==0 ){
157264 Db *pDb = 0; /* Database to detach at end of vacuum */
157308 db->mTrace = 0;
157336 assert( strcmp(pDb->zDbSName,zDbVacuum)==0 );
157340 i64 sz = 0;
157341 if( id->pMethods!=0 && (sqlite3OsFileSize(id, &sz)!=SQLITE_OK || sz>0) ){
157356 sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
157365 rc = sqlite3BtreeBeginTrans(pMain, pOut==0 ? 2 : 0, 0);
157371 && pOut==0
157373 db->nextPagesize = 0;
157376 if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0)
157377 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
157385 sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
157396 " AND coalesce(rootpage,1)>0",
157406 db->init.iDb = 0;
157416 "WHERE type='table'AND coalesce(rootpage,1)>0",
157419 assert( (db->mDbFlags & DBFLAG_Vacuum)!=0 );
157432 " OR(type='table'AND rootpage=0)",
157455 BTREE_DEFAULT_CACHE_SIZE, 0, /* Preserve the default page cache size */
157456 BTREE_TEXT_ENCODING, 0, /* Preserve the text encoding */
157457 BTREE_USER_VERSION, 0, /* Preserve the user version */
157458 BTREE_APPLICATION_ID, 0, /* Preserve the application id */
157462 assert( pOut!=0 || SQLITE_TXN_WRITE==sqlite3BtreeTxnState(pMain) );
157465 for(i=0; i<ArraySize(aCopy); i+=2){
157473 if( pOut==0 ){
157480 if( pOut==0 ){
157487 if( pOut==0 ){
157494 db->init.iDb = 0;
157500 sqlite3BtreeSetPageSize(pMain, -1, 0, 1);
157513 pDb->pBt = 0;
157514 pDb->pSchema = 0;
157564 ** If pModule==0, then delete the module zName if it exists.
157576 if( pModule==0 ){
157578 pMod = 0;
157582 if( pMod==0 ){
157584 return 0;
157592 pMod->pEpoTab = 0;
157600 pMod = 0;
157642 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
157644 return createModule(db, zName, pModule, pAux, 0);
157658 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
157677 for(ii=0; azNames[ii]!=0 && strcmp(azNames[ii],pMod->zName)!=0; ii++){}
157678 if( azNames[ii]!=0 ) continue;
157680 createModule(db, pMod->zName, 0, 0, 0);
157690 assert( pMod->nRefModule>0 );
157692 if( pMod->nRefModule==0 ){
157696 assert( pMod->pEpoTab==0 );
157734 assert( pVTab->nRef>0 );
157739 if( pVTab->nRef==0 ){
157757 VTable *pRet = 0;
157762 p->u.vtab.p = 0;
157770 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
157779 pRet->pNext = 0;
157844 db->pDisconnect = 0;
157869 assert( db!=0 );
157870 if( db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
157873 for(i=0; i<p->u.vtab.nArg; i++){
157897 if( azModuleArg==0 ){
157902 azModuleArg[i+1] = 0;
157922 sqlite3StartTable(pParse, pName1, pName2, 0, 0, 1, ifNotExists);
157924 if( pTable==0 ) return;
157925 assert( 0==pTable->pIndex );
157930 assert( pTable->u.vtab.nArg==0 );
157932 addModuleArgument(pParse, pTable, 0);
157934 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
157935 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
157949 assert( iDb>=0 ); /* The database the table is being created in */
157951 pTable->u.vtab.azArg[0], pParse->db->aDb[iDb].zDbSName);
157978 if( pTab==0 ) return;
157981 pParse->sArg.z = 0;
158017 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
158030 sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere, 0);
158042 assert( zName!=0 );
158050 pParse->pNewTable = 0;
158060 pParse->sArg.z = 0;
158061 pParse->sArg.n = 0;
158070 if( pArg->z==0 ){
158096 char *zErr = 0;
158138 sCtx.bDeclared = 0;
158142 assert( pTab!=0 );
158150 if( zErr==0 ){
158160 memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
158164 if( sCtx.bDeclared==0 ){
158171 u16 oooHidden = 0;
158180 for(iCol=0; iCol<pTab->nCol; iCol++){
158183 int i = 0;
158185 for(i=0; i<nType; i++){
158186 if( 0==sqlite3StrNICmp("hidden", &zType[i], 6)
158187 && (i==0 || zType[i-1]==' ')
158188 && (zType[i+6]=='\0' || zType[i+6]==' ')
158195 int nDel = 6 + (zType[i+6] ? 1 : 0);
158199 if( zType[i]=='\0' && i>0 ){
158201 zType[i-1] = '\0';
158237 zMod = pTab->u.vtab.azArg[0];
158241 const char *zModule = pTab->u.vtab.azArg[0];
158245 char *zErr = 0;
158264 if( (db->nVTrans%ARRAY_INCR)==0 ){
158272 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
158307 zMod = pTab->u.vtab.azArg[0];
158314 if( pMod==0 || pMod->pModule->xCreate==0 || pMod->pModule->xDestroy==0 ){
158346 static const u8 aKeyword[] = { TK_CREATE, TK_TABLE, 0 };
158349 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
158359 for(i=0; aKeyword[i]; i++){
158360 int tokenType = 0;
158387 assert( db->init.busy==0 );
158389 db->init.busy = 0;
158392 assert( sParse.pNewTable!=0 );
158395 assert( sParse.zErrMsg==0 );
158404 pNew->nCol = 0;
158405 pNew->aCol = 0;
158406 assert( pTab->pIndex==0 );
158407 assert( HasRowid(pNew) || sqlite3PrimaryKeyIndex(pNew)!=0 );
158409 && pCtx->pVTable->pMod->pModule->xUpdate!=0
158412 /* WITHOUT ROWID virtual tables must either be read-only (xUpdate==0)
158418 assert( pIdx->pNext==0 );
158420 pNew->pIndex = 0;
158427 (sParse.zErrMsg ? "%s" : 0), sParse.zErrMsg);
158440 assert( (rc&0xff)==rc );
158458 if( ALWAYS(pTab!=0)
158460 && ALWAYS(pTab->u.vtab.p!=0)
158466 if( p->pVtab->nRef>0 ){
158472 if( xDestroy==0 ) xDestroy = p->pMod->pModule->xDisconnect;
158473 assert( xDestroy!=0 );
158478 assert( pTab->u.vtab.p==p && p->pNext==0 );
158479 p->pVtab = 0;
158480 pTab->u.vtab.p = 0;
158501 db->aVTrans = 0;
158502 for(i=0; i<db->nVTrans; i++){
158510 pVTab->iSavepoint = 0;
158514 db->nVTrans = 0;
158530 db->aVTrans = 0;
158531 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
158534 if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
158590 for(i=0; i<db->nVTrans; i++){
158636 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
158689 void (*xSFunc)(sqlite3_context*,int,sqlite3_value**) = 0;
158690 void *pArg = 0;
158692 int rc = 0;
158695 if( NEVER(pExpr==0) ) return pDef;
158699 if( NEVER(pTab==0) ) return pDef;
158702 assert( pVtab!=0 );
158703 assert( pVtab->pModule!=0 );
158705 if( pMod->xFindFunction==0 ) return pDef;
158717 for(i=0; pDef->zName[i]; i++){
158724 if( rc==0 ){
158732 if( pNew==0 ){
158756 for(i=0; i<pToplevel->nVtabLock; i++){
158759 n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
158787 char *zErr = 0;
158791 if( pModule->xCreate!=0 && pModule->xCreate!=pModule->xConnect ) return 0;
158793 if( pTab==0 ) return 0;
158795 if( pTab->zName==0 ){
158797 return 0;
158802 pTab->pSchema = db->aDb[0].pSchema;
158803 assert( pTab->u.vtab.nArg==0 );
158807 addModuleArgument(pParse, pTab, 0);
158824 if( pTab!=0 ){
158830 pMod->pEpoTab = 0;
158872 assert( p->pTab==0 || IsVirtual(p->pTab) );
158999 ** the loop nested order, with WhereInfo.a[0] being the outer loop and
159064 u8 iSortIdx; /* Sorting index number. 0==None */
159182 ** categories, then eOperator==0. The WhereTerm.pExpr field is still set
159186 ** When eOperator!=0, prereqRight and prereqAll record sets of cursor numbers,
159194 ** beginning with 0 in order to make the best possible use of the available
159196 ** would be mapped into integers 0 through 7.
159217 WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */
159218 WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */
159227 #define TERM_DYNAMIC 0x0001 /* Need to call sqlite3ExprDelete(db, pExpr) */
159228 #define TERM_VIRTUAL 0x0002 /* Added by the optimizer. Do not code */
159229 #define TERM_CODED 0x0004 /* This term is already coded */
159230 #define TERM_COPIED 0x0008 /* Has a child */
159231 #define TERM_ORINFO 0x0010 /* Need to free the WhereTerm.u.pOrInfo object */
159232 #define TERM_ANDINFO 0x0020 /* Need to free the WhereTerm.u.pAndInfo obj */
159233 #define TERM_OK 0x0040 /* Used during OR-clause processing */
159234 #define TERM_VNULL 0x0080 /* Manufactured x>NULL or x<=NULL term */
159235 #define TERM_LIKEOPT 0x0100 /* Virtual terms from the LIKE optimization */
159236 #define TERM_LIKECOND 0x0200 /* Conditionally this LIKE operator term */
159237 #define TERM_LIKE 0x0400 /* The original LIKE operator */
159238 #define TERM_IS 0x0800 /* Term.pExpr is an IS operator */
159239 #define TERM_VARSELECT 0x1000 /* Term.pExpr contains a correlated sub-query */
159240 #define TERM_HEURTRUTH 0x2000 /* Heuristic truthProb used */
159242 # define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */
159244 # define TERM_HIGHTRUTH 0 /* Only used with STAT4 */
159246 #define TERM_SLICE 0x8000 /* One slice of a row-value/vector comparison */
159317 ** clause, the cursor numbers might not begin with 0 and they might
159321 ** with 0.
159328 ** would map those cursor numbers into bits 0 through 5.
159331 ** above, the mapping might go like this: 4->3, 5->1, 8->2, 29->0,
159334 ** numbers all get mapped into bit numbers that begin with 0 and contain
159362 #define SQLITE_BLDF1_INDEXED 0x0001 /* An index is used */
159363 #define SQLITE_BLDF1_UNIQUE 0x0002 /* All keys of a UNIQUE index used */
159365 #define SQLITE_BLDF2_2NDPASS 0x0004 /* Second builder pass needed */
159484 # define sqlite3WhereExplainOneScan(u,v,w,x) 0
159485 # define sqlite3WhereExplainBloomFilter(u,v,w) 0
159493 int addrExplain /* Address of OP_Explain (or 0) */
159540 #define WO_IN 0x0001
159541 #define WO_EQ 0x0002
159546 #define WO_AUX 0x0040 /* Op useful to virtual tables only */
159547 #define WO_IS 0x0080
159548 #define WO_ISNULL 0x0100
159549 #define WO_OR 0x0200 /* Two or more OR-connected terms */
159550 #define WO_AND 0x0400 /* Two or more AND-connected terms */
159551 #define WO_EQUIV 0x0800 /* Of the form A==B, both columns */
159552 #define WO_NOOP 0x1000 /* This term does not restrict search space */
159553 #define WO_ROWVAL 0x2000 /* A row-value term */
159555 #define WO_ALL 0x3fff /* Mask of all possible WO_* values */
159556 #define WO_SINGLE 0x01ff /* Mask of all non-compound WO_* values */
159563 #define WHERE_COLUMN_EQ 0x00000001 /* x=EXPR */
159564 #define WHERE_COLUMN_RANGE 0x00000002 /* x<EXPR and/or x>EXPR */
159565 #define WHERE_COLUMN_IN 0x00000004 /* x IN (...) */
159566 #define WHERE_COLUMN_NULL 0x00000008 /* x IS NULL */
159567 #define WHERE_CONSTRAINT 0x0000000f /* Any of the WHERE_COLUMN_xxx values */
159568 #define WHERE_TOP_LIMIT 0x00000010 /* x<EXPR or x<=EXPR constraint */
159569 #define WHERE_BTM_LIMIT 0x00000020 /* x>EXPR or x>=EXPR constraint */
159570 #define WHERE_BOTH_LIMIT 0x00000030 /* Both x>EXPR and x<EXPR */
159571 #define WHERE_IDX_ONLY 0x00000040 /* Use index only - omit table */
159572 #define WHERE_IPK 0x00000100 /* x is the INTEGER PRIMARY KEY */
159573 #define WHERE_INDEXED 0x00000200 /* WhereLoop.u.btree.pIndex is valid */
159574 #define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
159575 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
159576 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
159577 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
159578 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
159579 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
159580 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
159581 #define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */
159582 #define WHERE_IN_EARLYOUT 0x00040000 /* Perhaps quit IN loops early */
159583 #define WHERE_BIGNULL_SORT 0x00080000 /* Column nEq of index is BIGNULL */
159584 #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
159585 #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
159586 #define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */
159587 #define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */
159588 #define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */
159589 #define WHERE_COROUTINE 0x02000000 /* Implemented by co-routine.
159591 #define WHERE_EXPRIDX 0x04000000 /* Uses an index-on-expressions */
159632 for(i=0; i<nTerm; i++){
159641 for(i=0; i<nTerm; i++){
159668 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
159670 for(i=0; i<nEq; i++){
159721 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
159722 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
159728 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
159729 const char *zFmt = 0;
159732 assert( pLoop->u.btree.pIndex!=0 );
159753 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
159755 #if 0 /* Better output, but breaks many tests */
159757 const char *zRowid = pTab->iPKey>=0 ? pTab->aCol[pTab->iPKey].zCnName:
159777 else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
159780 pLoop->u.vtab.bIdxNumHex ? "0x%x:%s" : "%d:%s",
159801 assert( pOp->p4type==P4_DYNAMIC || pOp->p4.z==0 );
159824 int ret = 0;
159829 if( (pLevel->pWLoop->wsFlags & WHERE_MULTI_OR)==0
159830 && (wctrlFlags & WHERE_OR_SUBCLAUSE)==0
159858 int ret = 0;
159874 if( pTab->iPKey>=0 ){
159889 pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
159891 sqlite3VdbeScanStatus(v, sqlite3VdbeCurrentAddr(v)-1, 0, 0, 0, 0);
159903 ** If argument addrExplain is not 0, it must be the address of an
159910 int addrExplain /* Address of OP_Explain (or 0) */
159913 const char *zObj = 0;
159916 int viaCoroutine = 0;
159918 if( (wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){
159928 if( viaCoroutine==0 ){
159929 if( (wsFlags & (WHERE_MULTI_OR|WHERE_AUTO_INDEX))==0 ){
159993 int nLoop = 0;
159994 assert( pTerm!=0 );
159995 while( (pTerm->wtFlags & TERM_CODED)==0
159996 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_OuterON))
159997 && (pLevel->notReady & pTerm->prereqAll)==0
159999 if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
160005 if( (sqlite3WhereTrace & 0x4001)==0x4001 ){
160010 if( pTerm->iParent<0 ) break;
160012 assert( pTerm!=0 );
160014 if( pTerm->nChild!=0 ) break;
160032 if( zAff==0 ){
160036 assert( v!=0 );
160042 while( n>0 && zAff[0]<=SQLITE_AFF_BLOB ){
160052 if( n>0 ){
160053 sqlite3VdbeAddOp4(v, OP_Affinity, base, n, 0, zAff, n);
160073 for(i=0; i<n; i++){
160100 if( pOrderBy==0 ) return;
160101 for(i=0; i<pOrderBy->nExpr; i++){
160103 if( t==0 ) continue;
160104 for(j=0; j<pEList->nExpr; j++){
160111 pOrderBy->a[i].u.x.iOrderByCol = 0;
160155 pNew = sqlite3ExprDup(db, pX, 0);
160156 if( db->mallocFailed==0 ){
160159 ExprList *pOrigLhs = 0; /* Original unmodified LHS */
160160 ExprList *pRhs = 0; /* New RHS after modifications */
160161 ExprList *pLhs = 0; /* New LHS after mods */
160166 assert( pNew->pLeft!=0 );
160174 assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 );
160176 if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */
160178 pOrigRhs->a[iField].pExpr = 0;
160181 assert( pOrigLhs->a[iField].pExpr!=0 );
160183 pOrigLhs->a[iField].pExpr = 0;
160198 Expr *p = pLhs->a[0].pExpr;
160199 pLhs->a[0].pExpr = 0;
160208 assert( pRhs!=0 || db->mallocFailed );
160212 for(i=0; i<pRhs->nExpr; i++) pRhs->a[i].u.x.iOrderByCol = 0;
160215 #if 0
160217 sqlite3TreeViewExpr(0, pX, 0);
160219 sqlite3TreeViewExpr(0, pNew, 0);
160254 int nEq = 0;
160255 int *aiMap = 0;
160257 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0
160258 && pLoop->u.btree.pIndex!=0
160261 testcase( iEq==0 );
160267 for(i=0; i<iEq; i++){
160274 assert( pLoop->aLTerm[i]!=0 );
160278 iTab = 0;
160280 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
160283 if( pExpr->iTable==0 || !ExprHasProperty(pExpr, EP_Subrtn) ){
160288 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab);
160295 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
160304 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
160308 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
160310 if( pLevel->u.in.nIn==0 ){
160313 if( iEq>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0 ){
160322 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
160325 int iMap = 0; /* Index in aiMap[] */
160333 int iCol = aiMap ? aiMap[iMap++] : 0;
160340 if( iEq>0 ){
160344 pIn->nPrefix = 0;
160352 testcase( iEq>0
160353 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0
160354 && (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 );
160355 if( iEq>0
160356 && (pLoop->wsFlags & (WHERE_IN_SEEKSCAN|WHERE_VIRTUALTABLE))==0
160358 sqlite3VdbeAddOp3(v, OP_SeekHit, pLevel->iIdxCur, 0, iEq);
160361 pLevel->u.in.nIn = 0;
160395 assert( iTarget>0 );
160400 sqlite3VdbeAddOp2(pParse->pVdbe, OP_Null, 0, iReg);
160418 if( (pLevel->pWLoop->wsFlags & WHERE_TRANSCONS)==0
160419 || (pTerm->eOperator & WO_EQUIV)==0
160440 ** of nEq including 0. If nEq==0, this routine is nearly a no-op.
160444 ** The nExtraReg parameter is 0 or 1. It is 0 if all WHERE clause constraints
160492 assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
160496 assert( pIdx!=0 );
160505 assert( zAff!=0 || pParse->db->mallocFailed );
160509 sqlite3VdbeAddOp3(v, OP_Null, 0, regBase, regBase+nSkip-1);
160511 VdbeCoverageIf(v, bRev==0);
160512 VdbeCoverageIf(v, bRev!=0);
160515 assert( pLevel->addrSkip==0 );
160517 iIdxCur, 0, regBase, nSkip);
160518 VdbeCoverageIf(v, bRev==0);
160519 VdbeCoverageIf(v, bRev!=0);
160521 for(j=0; j<nSkip; j++){
160530 assert( zAff==0 || (int)strlen(zAff)>=nEq );
160534 assert( pTerm!=0 );
160536 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
160537 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
160556 }else if( (pTerm->eOperator & WO_ISNULL)==0 ){
160558 if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
160562 if( pParse->nErr==0 ){
160563 assert( pParse->db->mallocFailed==0 );
160602 assert( pLevel->iLikeRepCntr>0 );
160604 assert( pOp!=0 );
160623 int iIdxCur; /* Cursor for the index, if pIdx!=0. Unused otherwise */
160635 assert( pHint->pIdx!=0 );
160638 && sqlite3TableColumnToIndex(pHint->pIdx, pExpr->iColumn)<0
160658 ** CASE WHEN col THEN 0 ELSE 1 END
160669 if( 0==sqlite3IsLikeFunction(pWalker->pParse->db, pExpr, &d1, d2) ){
160692 ** know because CCurHint.pIdx!=0) then transform the TK_COLUMN into
160705 }else if( pHint->pIdx!=0 ){
160708 assert( pExpr->iColumn>=0 );
160735 Expr *pExpr = 0;
160750 memset(&sWalker, 0, sizeof(sWalker));
160754 for(i=0; i<pWC->nBase; i++){
160786 sWalker.eCode = 0;
160798 if( pLoop->u.btree.nEq==0 && pTerm!=pEndRange ){
160799 for(j=0; j<pLoop->nLTerm && pLoop->aLTerm[j]!=pTerm; j++){}
160808 if( sHint.pIdx!=0 ){
160809 sWalker.eCode = 0;
160816 pExpr = sqlite3ExprAnd(pParse, pExpr, sqlite3ExprDup(db, pTerm->pExpr, 0));
160818 if( pExpr!=0 ){
160820 if( pParse->nErr==0 ) sqlite3WalkExpr(&sWalker, pExpr);
160822 (sHint.pIdx ? sHint.iIdxCur : sHint.iTabCur), 0, 0,
160851 ** to 0. The OP_Column opcode can check this array to see if the column it
160865 assert( iIdxCur>0 );
160869 sqlite3VdbeAddOp3(v, OP_DeferredSeek, iIdxCur, 0, iCur);
160877 ai[0] = pTab->nCol;
160878 for(i=0; i<pIdx->nColumn-1; i++){
160884 if( x1>=0 ) ai[x2+1] = i+1;
160901 assert( nReg>0 );
160918 for(i=0; i<nReg; i++){
160946 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
160950 if( sqlite3ExprCompare(0, pExpr, pTruth, iTabCur)==0 ){
160981 if( pLevel->regFilter==0 ) continue;
160986 assert( pLevel->addrBrk==0 );
160989 WhereTerm *pTerm = pLoop->aLTerm[0];
160991 assert( pTerm!=0 );
160992 assert( pTerm->pExpr!=0 );
160995 regRowid = codeEqualityTerm(pParse, pTerm, pLevel, 0, 0, regRowid);
161007 assert( (pLoop->wsFlags & WHERE_COLUMN_IN)==0 );
161008 r1 = codeAllEqualityTerms(pParse,pLevel,0,0,&zStartAff);
161015 pLevel->regFilter = 0;
161016 pLevel->addrBrk = 0;
161027 && pLoop->nSkip==0
161031 for(ii=0; ii<pLoop->u.btree.nEq; ii++){
161033 return 0;
161038 return 0;
161065 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
161066 int iReleaseReg = 0; /* Temp register to free before returning */
161067 Index *pIdx = 0; /* Index used by loop (if any) */
161079 #if WHERETRACE_ENABLED /* 0x4001 */
161080 if( sqlite3WhereTrace & 0x1 ){
161083 if( sqlite3WhereTrace & 0x1000 ){
161087 if( (sqlite3WhereTrace & 0x4001)==0x4001 ){
161088 if( iLevel==0 ){
161090 sqlite3TreeViewExpr(0, pWInfo->pWhere, 0);
161115 || pLevel->iFrom>0 || (pTabItem[0].fg.jointype & JT_LEFT)==0
161117 if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
161119 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
161125 for(j=iLevel; j>0; j--){
161135 assert( pTabItem->fg.isSubquery && pTabItem->u4.pSubq!=0 );
161138 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pSubq->addrFillSub);
161146 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
161156 for(j=0; j<nConstraint; j++){
161159 if( NEVER(pTerm==0) ) continue;
161177 assert( pWInfo->pSelect!=0 );
161178 assert( pWInfo->pSelect->iOffset>0 );
161179 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWInfo->pSelect->iOffset);
161193 pLoop->u.vtab.needFree = 0;
161196 if( db->mallocFailed ) pLoop->u.vtab.idxStr = 0;
161200 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
161202 for(j=0; j<nConstraint; j++){
161208 if( (pTerm->eOperator & WO_IN)!=0
161209 && (SMASKBIT32(j) & pLoop->u.vtab.mHandleIn)==0
161222 for(iIn=0; ALWAYS(iIn<pLevel->u.in.nIn); iIn++){
161236 pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0);
161240 assert( pLeft!=0 );
161241 if( iFld>0 ){
161249 pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0);
161256 pCompare->pLeft = 0;
161264 ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems
161272 if( (pLoop->wsFlags & WHERE_IPK)!=0
161273 && (pLoop->wsFlags & (WHERE_COLUMN_IN|WHERE_COLUMN_EQ))!=0
161281 pTerm = pLoop->aLTerm[0];
161282 assert( pTerm!=0 );
161283 assert( pTerm->pExpr!=0 );
161286 iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
161300 }else if( (pLoop->wsFlags & WHERE_IPK)!=0
161301 && (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0
161307 int memEndValue = 0;
161310 j = 0;
161311 pStart = pEnd = 0;
161314 assert( pStart!=0 || pEnd!=0 );
161339 assert( (pStart->wtFlags & TERM_VNULL)==0 );
161342 assert( pX!=0 );
161351 op = aMoveOp[((pX->op - TK_GT - 1) & 0x3) | 0x1];
161370 VdbeCoverageIf(v, bRev==0);
161371 VdbeCoverageIf(v, bRev!=0);
161376 assert( pX!=0 );
161377 assert( (pEnd->wtFlags & TERM_VNULL)==0 );
161382 if( 0==sqlite3ExprIsVector(pX->pRight)
161389 if( 0==sqlite3ExprIsVector(pX->pRight) ){
161397 assert( pLevel->p5==0 );
161441 0,
161442 0,
161451 OP_IdxGE, /* 0: (end_constraints && !bRev && !endEq) */
161460 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
161461 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
161467 int nExtraReg = 0; /* Number of extra registers needed */
161470 char *zEndAff = 0; /* Affinity for end of range constraint */
161471 u8 bSeekPastNull = 0; /* True to seek past initial nulls */
161472 u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
161474 int regBignull = 0; /* big-null flag register */
161475 int addrSeekScan = 0; /* Opcode of the OP_SeekScan, if any */
161489 assert( (pRangeStart->wtFlags & TERM_LIKEOPT)==0 ||
161490 (pLoop->wsFlags & WHERE_TOP_LIMIT)!=0 );
161496 if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
161497 assert( pRangeStart!=0 ); /* LIKE opt constraints */
161507 assert( (bRev & ~1)==0 );
161512 if( pRangeStart==0 ){
161514 if( (j>=0 && pIdx->pTable->aCol[j].notNull==0) || j==XN_EXPR ){
161519 assert( pRangeEnd==0 || (pRangeEnd->wtFlags & TERM_VNULL)==0 );
161528 if( (pLoop->wsFlags & (WHERE_TOP_LIMIT|WHERE_BTM_LIMIT))==0
161529 && (pLoop->wsFlags & WHERE_BIGNULL_SORT)!=0
161531 assert( bSeekPastNull==0 && nExtraReg==0 && nBtm==0 && nTop==0 );
161532 assert( pRangeEnd==0 && pRangeStart==0 );
161533 testcase( pLoop->nSkip>0 );
161538 sqlite3VdbeAddOp2(v, OP_Integer, 0, regBignull);
161553 if( iLevel>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)!=0 ){
161565 assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
161571 testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
161572 testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
161573 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
161574 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_GE)!=0 );
161577 start_constraints = pRangeStart || nEq>0;
161585 if( (pRangeStart->wtFlags & TERM_VNULL)==0
161596 if( sqlite3ExprIsVector(pRight)==0 ){
161601 bSeekPastNull = 0;
161603 startEq = 0;
161604 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
161608 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
161613 if( pLoop->nSkip>0 && nConstraint==pLoop->nSkip ){
161630 assert( op!=0 );
161631 if( (pLoop->wsFlags & WHERE_IN_SEEKSCAN)!=0 && op==OP_SeekGE ){
161632 assert( regBignull==0 );
161642 (pIdx->aiRowLogEst[0]+9)/10);
161646 addrSeekScan = 0;
161659 assert( bSeekPastNull==0 || bStopAtNull==0 );
161664 sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
161681 assert( pLevel->p2==0 );
161684 assert( addrSeekScan==0 );
161687 if( (pRangeEnd->wtFlags & TERM_VNULL)==0
161702 if( sqlite3ExprIsVector(pRight)==0 ){
161708 if( regBignull==0 ){
161709 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
161710 endEq = 0;
161741 assert( nConstraint+bSeekPastNull>0 );
161754 if( (pLoop->wsFlags & WHERE_IN_EARLYOUT)!=0 ){
161759 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
161760 && (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))==0;
161768 for(j=0; j<pPk->nKeyCol; j++){
161776 if( pLevel->iLeftJoin==0 ){
161785 if( pIdx->pPartIdxWhere && pLevel->pRJ==0 ){
161793 assert( (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))==0 );
161798 || (pLevel->u.in.nIn && regBignull==0 && whereLoopIsOneRow(pLoop))
161807 pLevel->p3 = (pLoop->wsFlags&WHERE_UNQ_WANTED)!=0 ? 1:0;
161808 if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
161811 assert( pLevel->p5==0 );
161813 if( omitTable ) pIdx = 0;
161863 Index *pCov = 0; /* Potential covering index (or NULL) */
161867 int regRowset = 0; /* Register for RowSet object */
161868 int regRowid = 0; /* Register holding rowid */
161871 int untestedTerms = 0; /* Some terms not completely tested */
161873 Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
161876 pTerm = pLoop->aLTerm[0];
161877 assert( pTerm!=0 );
161879 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
161885 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
161893 if( pOrTab==0 ) return notReady;
161917 if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
161920 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowset);
161929 iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
161961 for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
161967 if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){
161970 if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
161972 pExpr = sqlite3ExprDup(db, pExpr, 0);
161976 /* The extra 0x10000 bit on the opcode is masked off and does not
161981 pAndExpr = sqlite3PExpr(pParse, TK_AND|0x10000, 0, pAndExpr);
161990 for(ii=0; ii<pOrWc->nTerm; ii++){
161992 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
161996 int jmp1 = 0; /* Address of jump operation */
161997 testcase( (pTabItem[0].fg.jointype & JT_LEFT)!=0
162000 pDelete = pOrExpr = sqlite3ExprDup(db, pOrExpr, 0);
162011 WHERETRACE(0xffffffff, ("Subplan for OR-clause:\n"));
162012 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, 0,
162018 pParse, pOrTab, &pSubWInfo->a[0], 0
162020 sqlite3WhereAddScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain);
162027 if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
162031 jmp1 = sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset, 0,
162042 for(iPk=0; iPk<nPk; iPk++){
162059 jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, regRowset, 0, r, nPk);
162062 if( iSet>=0 ){
162100 pSubLoop = pSubWInfo->a[0].pWLoop;
162101 assert( (pSubLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
162102 if( (pSubLoop->wsFlags & WHERE_INDEXED)!=0
162103 && (ii==0 || pSubLoop->u.btree.pIndex==pCov)
162106 assert( pSubWInfo->a[0].iIdxCur==iCovCur );
162109 pCov = 0;
162124 assert( (pLoop->wsFlags & WHERE_MULTI_OR)!=0 );
162125 assert( (pLoop->wsFlags & WHERE_IN_ABLE)==0 );
162129 pAndExpr->pLeft = 0;
162155 assert( bRev==0 || bRev==1 );
162161 codeCursorHint(pTabItem, pWInfo, pLevel, 0);
162165 VdbeCoverageIf(v, bRev==0);
162166 VdbeCoverageIf(v, bRev!=0);
162197 int iNext = 0; /* Next value for iLoop */
162198 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
162200 int skipLikeAddr = 0;
162204 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
162205 testcase( pWInfo->untestedTerms==0
162206 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
162211 assert( pE!=0 );
162233 if( iNext==0 ) iNext = 3;
162237 if( (pTerm->wtFlags & TERM_LIKECOND)!=0 ){
162247 if( x>0 ){
162250 VdbeCoverageIf(v, (x&1)==0);
162254 #ifdef WHERETRACE_ENABLED /* 0xffffffff */
162259 if( sqlite3WhereTrace & 0x4000 ){
162269 }while( iLoop>0 );
162279 for(pTerm=pWC->a, j=pWC->nBase; j>0; j--, pTerm++){
162283 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue;
162284 if( (pTerm->eOperator & WO_EQUIV)==0 ) continue;
162288 #ifdef WHERETRACE_ENABLED /* 0x4001 */
162289 if( (sqlite3WhereTrace & 0x4001)==0x4001 ){
162295 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
162296 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
162298 WO_EQ|WO_IN|WO_IS, 0);
162299 if( pAlt==0 ) continue;
162324 int jmp1 = 0;
162342 for(iPk=0; iPk<nPk; iPk++){
162347 jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, 0, r+1, nPk);
162352 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pRJ->regBloom, 0, r+1, nPk);
162365 if( pLevel->pRJ==0 ){
162378 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pRJ->regReturn);
162389 for(pTerm=pWC->a, j=0; j<pWC->nBase; j++, pTerm++){
162393 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
162404 #if WHERETRACE_ENABLED /* 0x4001 */
162405 if( sqlite3WhereTrace & 0x4000 ){
162410 if( sqlite3WhereTrace & 0x1 ){
162430 Expr *pSubWhere = 0;
162437 Bitmask mAll = 0;
162443 for(k=0; k<iLevel; k++){
162451 assert( pRight->fg.isSubquery && pRight->u4.pSubq!=0 );
162453 assert( pSubq->pSelect!=0 && pSubq->pSelect->pEList!=0 );
162455 v, OP_Null, 0, pSubq->regResult,
162465 if( (pTabItem->fg.jointype & JT_LTORJ)==0 ){
162467 for(k=0; k<pWC->nTerm; k++){
162469 if( (pTerm->wtFlags & (TERM_VIRTUAL|TERM_SLICE))!=0
162477 sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
162483 memcpy(&pFrom->a[0], pTabItem, sizeof(SrcItem));
162484 pFrom->a[0].fg.jointype = 0;
162487 pSubWInfo = sqlite3WhereBegin(pParse, pFrom, pSubWhere, 0, 0, 0,
162488 WHERE_RIGHT_JOIN, 0);
162504 for(iPk=0; iPk<nPk; iPk++){
162509 jmp = sqlite3VdbeAddOp4Int(v, OP_Filter, pRJ->regBloom, 0, r, nPk);
162519 assert( pParse->withinRJSubrtn>0 );
162569 ** 0 is returned if the new WhereTerm could not be added due to a memory
162591 pWC->a = sqlite3WhereMalloc(pWC->pWInfo, sizeof(pWC->a[0])*pWC->nSlot*2 );
162592 if( pWC->a==0 ){
162597 return 0;
162599 memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm);
162603 if( (wtFlags & TERM_VIRTUAL)==0 ) pWC->nBase = pWC->nTerm;
162613 memset(&pTerm->eOperator, 0,
162631 if( op>TK_GE ) return 0;
162657 return 0;
162667 assert( (WO_EQ<<(op-TK_EQ)) < 0x7fff );
162709 const u8 *z = 0; /* String on RHS of LIKE operator */
162716 sqlite3_value *pVal = 0;
162721 return 0;
162724 if( *pnoCase ) return 0;
162730 pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
162732 if( op==TK_VARIABLE && (db->flags & SQLITE_EnableQPSG)==0 ){
162752 cnt = 0;
162753 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
162755 if( c==wc[3] && z[cnt]>0 && z[cnt]<0x80 ){
162757 }else if( c>=0x80 ){
162759 if( c==0xff || sqlite3Utf8Read(&z2)==0xfffd /* bad utf-8 */
162772 ** an (illegal 0xff) character, or (3) the pattern does not consist of
162778 if( (cnt>1 || (cnt>0 && z[0]!=wc[3])) && ALWAYS(255!=(u8)z[cnt-1]) ){
162782 *pisComplete = c==wc[0] && z[cnt+1]==0 && ENC(db)!=SQLITE_UTF16LE;
162791 zNew[cnt] = 0;
162792 for(iFrom=iTo=0; iFrom<cnt; iFrom++){
162796 zNew[iTo] = 0;
162797 assert( iTo>0 );
162810 ** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
162821 if( isNum<=0 ){
162822 if( iTo==1 && zNew[0]=='-' ){
162830 if( isNum>0 ){
162833 return 0;
162854 sqlite3VdbeChangeP3(v, sqlite3VdbeCurrentAddr(v)-1, 0);
162859 z = 0;
162863 rc = (z!=0);
162895 ** If the expression matches none of the patterns above, return 0.
162900 unsigned char *peOp2, /* OUT: 0 for MATCH, or else an op2 value */
162920 if( pList==0 || pList->nExpr!=2 ){
162921 return 0;
162932 assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) );
162934 for(i=0; i<ArraySize(aOp); i++){
162936 if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
162938 *ppRight = pList->a[0].pExpr;
162955 pCol = pList->a[0].pExpr;
162957 assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) );
162964 assert( pVtab!=0 );
162965 assert( pVtab->pModule!=0 );
162968 if( pMod->xFindFunction!=0 ){
162984 return 0;
162986 int res = 0;
162989 assert( pLeft->op!=TK_COLUMN || (ExprUseYTab(pLeft) && pLeft->y.pTab!=0) );
162993 assert( pRight==0 || pRight->op!=TK_COLUMN
162994 || (ExprUseYTab(pRight) && pRight->y.pTab!=0) );
163006 return 0;
163032 ** a conjunction, then return just pTerm when N==0. If N is exceeds
163037 return N==0 ? pTerm : 0;
163042 return 0;
163078 if( (pOne->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
163079 if( (pTwo->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
163082 assert( pOne->pExpr->pLeft!=0 && pOne->pExpr->pRight!=0 );
163083 assert( pTwo->pExpr->pLeft!=0 && pTwo->pExpr->pRight!=0 );
163084 if( sqlite3ExprCompare(0,pOne->pExpr->pLeft, pTwo->pExpr->pLeft, -1) ) return;
163085 if( sqlite3ExprCompare(0,pOne->pExpr->pRight, pTwo->pExpr->pRight,-1) )return;
163087 if( (eOp & (eOp-1))!=0 ){
163096 pNew = sqlite3ExprDup(db, pOne->pExpr, 0);
163097 if( pNew==0 ) return;
163214 assert( (pTerm->wtFlags & (TERM_DYNAMIC|TERM_ORINFO|TERM_ANDINFO))==0 );
163217 if( pOrInfo==0 ) return;
163220 memset(pOrWc->aStatic, 0, sizeof(pOrWc->aStatic));
163230 indexable = ~(Bitmask)0;
163231 chngToIN = ~(Bitmask)0;
163232 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0 && indexable; i--, pOrTerm++){
163233 if( (pOrTerm->eOperator & WO_SINGLE)==0 ){
163235 assert( (pOrTerm->wtFlags & (TERM_ANDINFO|TERM_ORINFO))==0 );
163236 chngToIN = 0;
163242 Bitmask b = 0;
163248 memset(pAndWC->aStatic, 0, sizeof(pAndWC->aStatic));
163254 for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){
163276 if( (pOrTerm->eOperator & WO_EQ)==0 ){
163277 chngToIN = 0;
163298 int iOne = 0;
163300 while( (pOne = whereNthSubterm(&pOrWc->a[0],iOne++))!=0 ){
163301 int iTwo = 0;
163303 while( (pTwo = whereNthSubterm(&pOrWc->a[1],iTwo++))!=0 ){
163314 ** chngToIN will hold either 0, 1, or 2 bits. The 0-bit case means
163331 int okToChngToIN = 0; /* True if the conversion to IN is valid */
163334 int j = 0; /* Loop counter */
163342 for(j=0; j<2 && !okToChngToIN; j++){
163343 Expr *pLeft = 0;
163345 for(i=pOrWc->nTerm-1; i>=0; i--, pOrTerm++){
163355 pOrTerm->leftCursor))==0 ){
163365 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
163371 if( i<0 ){
163384 for(; i>=0 && okToChngToIN; i--, pOrTerm++){
163386 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
163392 okToChngToIN = 0;
163401 if( affRight!=0 && affRight!=affLeft ){
163402 okToChngToIN = 0;
163416 ExprList *pList = 0; /* The RHS of the IN operator */
163417 Expr *pLeft = 0; /* The LHS of the IN operator */
163420 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
163421 if( (pOrTerm->wtFlags & TERM_OK)==0 ) continue;
163423 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
163426 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
163430 assert( pLeft!=0 );
163431 pDup = sqlite3ExprDup(db, pLeft, 0);
163432 pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
163439 testcase( idxNew==0 );
163464 ** This is an optimization. No harm comes from returning 0. But if 1 is
163470 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */
163471 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */
163472 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* (3) */
163473 assert( pSrc!=0 );
163476 && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0
163478 return 0; /* (4) */
163485 return 0; /* (5) */
163491 return 0; /* (6) */
163502 Bitmask mask = 0;
163510 if( ALWAYS(pSrc!=0) ){
163512 for(i=0; i<pSrc->nSrc; i++){
163516 if( pSrc->a[i].fg.isUsing==0 ){
163533 ** FALSE (0) if not. If TRUE is returned, also set aiCurCol[0] to the cursor
163554 if( pIdx->aColExpr==0 ) continue;
163555 for(i=0; i<pIdx->nKeyCol; i++){
163558 if( sqlite3ExprCompareSkip(pExpr,pIdx->aColExpr->a[i].pExpr,iCur)==0
163559 && !sqlite3ExprIsConstant(0,pIdx->aColExpr->a[i].pExpr)
163561 aiCurCol[0] = iCur;
163568 return 0;
163586 pExpr = pExpr->x.pList->a[0].pExpr;
163590 aiCurCol[0] = pExpr->iTable;
163595 for(i=0; i<pFrom->nSrc; i++){
163603 return 0;
163636 Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */
163637 Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */
163638 int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */
163639 int noCase = 0; /* uppercase equivalent to lowercase */
163643 unsigned char eOp2 = 0; /* op2 value for LIKE/REGEXP/GLOB */
163653 assert( pExpr!=0 ); /* Because malloc() has not failed */
163655 pMaskSet->bVarSelect = 0;
163659 assert( pExpr->pRight==0 );
163669 if( pExpr->pLeft==0
163671 || pExpr->x.pList!=0
163683 sqlite3TreeViewExpr(0,pExpr,0);
163684 assert( 0 );
163705 if( ALWAYS(pSrc->nSrc>0) && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
163715 pTerm->eOperator = 0;
163720 u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
163722 if( pTerm->u.x.iField>0 ){
163730 pTerm->leftCursor = aiCurCol[0];
163731 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
163742 u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
163743 assert( pTerm->u.x.iField==0 );
163744 if( pTerm->leftCursor>=0 ){
163746 pDup = sqlite3ExprDup(db, pExpr, 0);
163752 if( idxNew==0 ) return;
163758 assert( pWInfo->pTabList!=0 );
163768 pNew->leftCursor = aiCurCol[0];
163769 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
163778 && 0==sqlite3ExprCanBeNull(pLeft)
163784 pTerm->prereqAll = 0;
163785 pTerm->eOperator = 0;
163811 assert( pList!=0 );
163813 for(i=0; i<2; i++){
163817 sqlite3ExprDup(db, pExpr->pLeft, 0),
163818 sqlite3ExprDup(db, pList->a[i].pExpr, 0));
163821 testcase( idxNew==0 );
163847 && pExpr->pLeft->iColumn>=0
163856 sqlite3ExprDup(db, pLeft, 0),
163857 sqlite3ExprAlloc(db, TK_NULL, 0, 0));
163863 pNewTerm->prereqRight = 0;
163905 pStr2 = sqlite3ExprDup(db, pStr1, 0);
163906 assert( pStr1==0 || !ExprHasProperty(pStr1, EP_IntValue) );
163907 assert( pStr2==0 || !ExprHasProperty(pStr2, EP_IntValue) );
163918 for(i=0; (c = pStr1->u.zToken[i])!=0; i++){
163934 if( *pC=='A'-1 ) isComplete = 0;
163939 while( *pC==0xBF && pC>(u8*)pStr2->u.zToken ){
163940 *pC = 0x80;
163943 assert( *pC!=0xFF ); /* isLikeOrGlob() guarantees this */
163947 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
163953 testcase( idxNew1==0 );
163954 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
163960 testcase( idxNew2==0 );
163984 && ( (pExpr->pLeft->flags & EP_xIsSelect)==0
163985 || (pExpr->pRight->flags & EP_xIsSelect)==0)
163989 for(i=0; i<nLeft; i++){
164015 && pTerm->u.x.iField==0
164018 && (pExpr->x.pSelect->pPrior==0 || (pExpr->x.pSelect->selFlags & SF_Values))
164020 && pExpr->x.pSelect->pWin==0
164025 for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){
164045 Expr *pRight = 0, *pLeft = 0;
164047 while( res-- > 0 ){
164054 if( (prereqExpr & prereqColumn)==0 ){
164057 0, sqlite3ExprDup(db, pRight, 0));
164063 testcase( idxNew==0 );
164101 ** slot[0] slot[1] slot[2]
164113 assert( pE2!=0 || pExpr==0 );
164114 if( pE2==0 ) return;
164116 whereClauseInsert(pWC, pExpr, 0);
164144 int iVal = 0;
164146 if( sqlite3ExprIsInteger(pExpr, &iVal, pParse) && iVal>=0 ){
164147 Expr *pVal = sqlite3Expr(db, TK_INTEGER, 0);
164148 if( pVal==0 ) return;
164151 pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal);
164153 Expr *pVal = sqlite3Expr(db, TK_REGISTER, 0);
164154 if( pVal==0 ) return;
164156 pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal);
164188 assert( p!=0 && p->pLimit!=0 ); /* 1 -- checked by caller */
164189 if( p->pGroupBy==0
164190 && (p->selFlags & (SF_Distinct|SF_Aggregate))==0 /* 2 */
164191 && (p->pSrc->nSrc==1 && IsVirtual(p->pSrc->a[0].pSTab)) /* 3 */
164194 int iCsr = p->pSrc->a[0].iCursor;
164198 for(ii=0; ii<pWC->nTerm; ii++){
164214 if( pWC->a[ii].prereqRight!=0 ) return;
164219 for(ii=0; ii<pOrderBy->nExpr; ii++){
164229 if( p->iOffset!=0 && (p->selFlags & SF_Compound)==0 ){
164233 if( p->iOffset==0 || (p->selFlags & SF_Compound)==0 ){
164248 pWC->hasOr = 0;
164249 pWC->pOuter = 0;
164250 pWC->nTerm = 0;
164251 pWC->nBase = 0;
164264 if( pWC->nTerm>0 ){
164271 assert( (pWC->a[i].wtFlags & TERM_VIRTUAL)!=0 );
164275 assert( a->eMatchOp==0 || a->eOperator==WO_AUX );
164281 assert( (a->wtFlags & TERM_ANDINFO)==0 );
164284 assert( (a->wtFlags & TERM_ANDINFO)!=0 );
164303 ** be NULL, in which case 0 is returned.
164314 ** case 0 is returned.
164331 mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0;
164335 assert( p->x.pList==0 );
164344 assert( p->y.pWin!=0 );
164357 return 0;
164362 return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
164366 Bitmask mask = 0;
164368 for(i=0; i<pList->nExpr; i++){
164389 for(i=pWC->nTerm-1; i>=0; i--){
164411 if( pItem->fg.isTabFunc==0 ) return;
164413 assert( pTab!=0 );
164415 if( pArgs==0 ) return;
164416 for(j=k=0; j<pArgs->nExpr; j++){
164419 while( k<pTab->nCol && (pTab->aCol[k].colFlags & COLFLAG_HIDDEN)==0 ){k++;}
164425 pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
164426 if( pColRef==0 ) return;
164433 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
164517 ** WHERE clause. A return of 0 means that the output must be
164524 return pWInfo->nOBSat<0 ? 0 : pWInfo->nOBSat;
164558 assert( pInner->addrNxt!=0 );
164577 if( pWInfo->nOBSat==0 ) return;
164578 for(i=pWInfo->nLevel-1; i>=0; i--){
164580 if( (pInner->pWLoop->wsFlags & WHERE_COLUMN_IN)!=0 ){
164593 assert( pWInfo->iContinue!=0 );
164606 ** Return ONEPASS_OFF (0) if an UPDATE or DELETE statement is unable to
164614 ** into aiCur[0] and aiCur[1]. iaCur[0] gets the cursor of the data
164619 ** aiCur[0] and aiCur[1] both get -1 if the where-clause logic is
164628 aiCur[0], aiCur[1]);
164647 memcpy(pDest->a, pSrc->a, pDest->n*sizeof(pDest->a[0]));
164665 for(i=pSet->n, p=pSet->a; i>0; i--, p++){
164670 return 0;
164681 if( p->rRun<=rRun ) return 0;
164691 ** Return the bitmask for the given cursor number. Return 0 if
164697 assert( pMaskSet->n>0 || pMaskSet->ix[0]<0 );
164699 if( pMaskSet->ix[0]==iCursor ){
164707 return 0;
164753 if( ALWAYS(p!=0) && p->op==TK_COLUMN && !ExprHasProperty(p, EP_FixedCol) ){
164756 return 0;
164780 inexpr.flags = 0;
164792 return 0;
164813 assert( pWC!=0 );
164814 assert( iCur>=0 );
164817 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 || pTerm->leftCursor<0 );
164822 pScan->pIdxExpr,iCur)==0)
164825 if( (pTerm->eOperator & WO_EQUIV)!=0
164827 && (pX = whereRightSubexprIsColumn(pTerm->pExpr))!=0
164830 for(j=0; j<pScan->nEquiv; j++){
164842 if( (pTerm->eOperator & pScan->opMask)!=0 ){
164844 if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){
164866 if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0
164867 && (pX = pTerm->pExpr->pRight, ALWAYS(pX!=0))
164869 && pX->iTable==pScan->aiCur[0]
164870 && pX->iColumn==pScan->aiColumn[0]
164878 if( sqlite3WhereTrace & 0x20000 ){
164882 for(ii=0; ii<pScan->nEquiv; ii++){
164894 k = 0;
164895 }while( pWC!=0 );
164898 k = 0;
164901 return 0;
164921 ** iCur. Or if pIdx!=0 then X is column iColumn of index pIdx. pIdx
164944 pScan->pIdxExpr = 0;
164945 pScan->idxaff = 0;
164946 pScan->zCollName = 0;
164948 pScan->k = 0;
164949 pScan->aiCur[0] = iCur;
164957 }else if( iColumn>=0 ){
164963 pScan->aiColumn[0] = XN_EXPR;
164967 return 0;
164969 pScan->aiColumn[0] = iColumn;
164976 ** if pIdx!=0 and <op> is one of the WO_xx operator codes specified by
164977 ** the op parameter. Return a pointer to the term. Return 0 if not found.
164979 ** If pIdx!=0 then it must be one of the indexes of table iCur.
165006 WhereTerm *pResult = 0;
165013 if( (p->prereqRight & notReady)==0 ){
165014 if( p->prereqRight==0 && (p->eOperator&op)!=0 ){
165018 if( pResult==0 ) pResult = p;
165042 for(i=0; i<pList->nExpr; i++){
165044 if( ALWAYS(p!=0)
165050 if( 0==sqlite3StrICmp(pColl->zName, zColl) ){
165064 assert( pIdx!=0 );
165065 assert( iCol>=0 && iCol<pIdx->nColumn );
165067 if( j>=0 ){
165073 return 0; /* Assume an indexed expression can always yield a NULL */
165099 if( pTabList->nSrc!=1 ) return 0;
165100 iBase = pTabList->a[0].iCursor;
165101 pTab = pTabList->a[0].pSTab;
165107 for(i=0; i<pDistinct->nExpr; i++){
165109 if( NEVER(p==0) ) continue;
165111 if( p->iTable==iBase && p->iColumn<0 ) return 1;
165130 for(i=0; i<pIdx->nKeyCol; i++){
165131 if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
165132 if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
165133 if( indexColumnNotNull(pIdx, i)==0 ) break;
165142 return 0;
165150 return N<=10 ? 0 : sqlite3LogEst(N) - 33;
165193 pOp->p3 = 0;
165204 if( iAutoidxCur==0 ){
165206 pOp->p3 = 0;
165225 if( (sqlite3WhereTrace & 0x10)==0 ) return;
165227 for(i=0; i<p->nConstraint; i++){
165237 for(i=0; i<p->nOrderBy; i++){
165249 if( (sqlite3WhereTrace & 0x10)==0 ) return;
165251 for(i=0; i<p->nConstraint; i++){
165285 assert( (pSrc->fg.jointype&(JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ); /* By caller */
165293 return 0;
165295 if( (pSrc->fg.jointype & (JT_LEFT|JT_RIGHT))!=0
165298 return 0;
165328 for(pIdx = pTab->pIndex; pIdx!=0; pIdx=pIdx->pNext){
165330 for(j=0; j<pIdx->nKeyCol; j++){
165332 if( j==0 ) return 0;
165333 if( pIdx->hasStat1 && pIdx->aiRowLogEst[j+1]>20 ) return 0;
165358 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
165359 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
165360 assert( (pSrc->fg.jointype & JT_RIGHT)==0 );
165361 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0
165364 return 0; /* See https://sqlite.org/forum/forumpost/51e6959f61 */
165366 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
165367 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
165369 if( leftCol<0 ) return 0;
165371 if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
165401 char *zText = 0;
165402 int ii = 0;
165407 for(ii=0; ii<(pIdx->nColumn-1); ii++){
165408 const char *zName = 0;
165416 if( zText==0 ){
165420 pParse, 0, "%s)%s", zText, (bPartial ? " WHERE <expr>" : "")
165458 u8 sentWarning = 0; /* True if a warning has been issued */
165459 u8 useBloomFilter = 0; /* True to also add a Bloom filter */
165460 Expr *pPartial = 0; /* Partial Index Expression */
165461 int iContinue = 0; /* Jump here to skip excluded rows */
165464 int addrCounter = 0; /* Address where integer counter is initialized */
165467 int addrExp = 0; /* Address of OP_Explain */
165473 assert( v!=0 );
165478 nKeyCol = 0;
165484 idxCols = 0;
165490 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
165491 && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, pLevel->iFrom, 0)
165494 sqlite3ExprDup(pParse->db, pExpr, 0));
165499 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
165510 if( (idxCols & cMask)==0 ){
165519 assert( nKeyCol>0 || pParse->db->mallocFailed );
165540 for(i=0; i<pTable->nCol; i++){
165541 if( (pTable->aCol[i].colFlags & COLFLAG_PRIMKEY)==0 ) continue;
165553 for(i=0; i<mxBitCol; i++){
165561 assert( nKeyCol <= pTable->nCol + MAX(0, pTable->nCol - BMS + 1) );
165564 0, &zNotUsed);
165565 if( pIdx==0 ) goto end_auto_index_create;
165569 n = 0;
165570 idxCols = 0;
165575 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
165580 if( (idxCols & cMask)==0 ){
165585 assert( pColl!=0 || pParse->nErr>0 ); /* TH3 collate01.800 */
165588 if( ALWAYS(pX->pLeft!=0)
165605 for(i=0; i<mxBitCol; i++){
165626 explainAutomaticIndex(pParse, pIdx, pPartial!=0, &addrExp);
165627 assert( pLevel->iIdxCur>=0 );
165645 assert( pSubq!=0 );
165647 addrCounter = sqlite3VdbeAddOp2(v, OP_Integer, 0, 0);
165648 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pSubq->addrFillSub);
165662 pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0
165665 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0,
165673 assert( pSrc->fg.isSubquery && pSrc->u4.pSubq!=0 );
165676 assert( pLevel->iIdxCur>0 );
165680 pSrc->fg.viaCoroutine = 0;
165737 pParse->pIdxEpr = 0;
165738 pParse->pIdxPartExpr = 0;
165740 assert( pLoop!=0 );
165741 assert( v!=0 );
165743 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 );
165768 assert( pItem!=0 );
165770 assert( pTab!=0 );
165783 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
165784 && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, iSrc, 0)
165792 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, 1);
165799 for(jj=0; jj<n; jj++){
165803 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, n);
165818 if( NEVER(pLoop==0) ) continue;
165840 ** are numbered from 0 upwards, starting with the terms in pWC->a[], then
165849 return 0;
165874 u16 mNoOmit = 0;
165876 int eDistinct = 0;
165880 assert( pSrc!=0 );
165882 assert( pTab!=0 );
165889 for(p=pWC, nTerm=0; p; p=p->pOuter){
165890 for(i=0, pTerm=p->a; i<p->nTerm; i++, pTerm++){
165899 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
165902 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
165905 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0
165919 nOrderBy = 0;
165922 for(i=0; i<n; i++){
165927 if( sqlite3ExprIsConstant(0, pExpr) ){
165948 assert( pExpr->u.zToken!=0 );
165951 if( pE2->iColumn<0 ) continue; /* Collseq does not matter for rowid */
165953 if( zColl==0 ) zColl = sqlite3StrBINARY;
165954 if( sqlite3_stricmp(pExpr->u.zToken, zColl)==0 ) continue;
165963 eDistinct = 2 + ((pWInfo->wctrlFlags & WHERE_SORTBYGROUP)!=0);
165976 if( pIdxInfo==0 ){
165978 return 0;
165988 if( HasRowid(pTab)==0 ){
165992 assert( pPk!=0 );
165993 for(i=0; i<pPk->nKeyCol; i++){
165995 assert( iCol>=0 );
166003 pHidden->mIn = 0;
166004 for(p=pWC, i=j=0; p; p=p->pOuter){
166008 if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
166013 if( (pTerm->wtFlags & TERM_SLICE)==0 ){
166053 for(i=j=0; i<nOrderBy; i++){
166055 if( sqlite3ExprIsConstant(0, pExpr) ) continue;
166075 pIdxInfo->idxStr = 0;
166076 pIdxInfo->needToFreeIdxStr = 0;
166087 assert( pIdxInfo!=0 );
166089 assert( pHidden->pParse!=0 );
166091 for(i=0; i<pIdxInfo->nConstraint; i++){
166093 pHidden->aRhs[i] = 0;
166140 pVtab->zErrMsg = 0;
166150 ** aStat[0] Est. number of rows less than pRec
166170 int iMin = 0; /* Smallest sample not yet tested */
166174 tRowcnt iLower = 0; /* anLt[] + anEq[] of largest sample pRec is > */
166179 assert( pRec!=0 );
166180 assert( pIdx->nSample>0 );
166181 assert( pRec->nField>0 );
166194 ** aSample[0] = (a, 5)
166204 ** 0: (a)
166216 ** effective sample array. In the above, samples 0 and 1 are based on
166217 ** sample aSample[0]. Samples 2 and 3 on aSample[1] etc.
166234 iCol = 0;
166242 if( iSamp>0 ){
166255 if( res<0 ){
166258 }else if( res==0 && n<nField ){
166273 if( pParse->db->mallocFailed==0 ){
166274 if( res==0 ){
166275 /* If (res==0) is true, then pRec must be equal to sample i. */
166279 assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
166286 assert( i<=pIdx->nSample && i>=0 );
166289 || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
166292 /* if i==0 and iCol==0, then record pRec is smaller than all samples
166293 ** in the aSample[] array. Otherwise, if (iCol>0) then pRec must
166295 ** If (i>0), then pRec must also be greater than sample (i-1). */
166296 if( iCol>0 ){
166298 assert( sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)<=0
166301 if( i>0 ){
166303 assert( sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
166310 if( res==0 ){
166313 aStat[0] = aSample[i].anLt[iCol];
166327 iGap = 0;
166336 aStat[0] = iLower + iGap;
166360 if( pTerm->truthProb<=0 ){
166362 }else if( (pTerm->wtFlags & TERM_VNULL)==0 ){
166375 assert( iCol>=0 && iCol<pIdx->nColumn );
166377 if( sqlite3IndexAffinityStr(db, pIdx)==0 ) return SQLITE_AFF_BLOB;
166379 assert( pIdx->zColAff[iCol]!=0 );
166437 sqlite3_value *p1 = 0; /* Value extracted from pLower */
166438 sqlite3_value *p2 = 0; /* Value extracted from pUpper */
166439 sqlite3_value *pVal = 0; /* Value extracted from record */
166444 nLower = 0;
166448 nUpper = p2 ? 0 : p->nSample;
166454 for(i=0; rc==SQLITE_OK && i<p->nSample; i++){
166458 if( res>=0 ) nLower++;
166462 if( res>=0 ) nUpper++;
166466 if( nDiff<=0 ) nDiff = 1;
166473 if( nDiff!=1 || pUpper==0 || pLower==0 ){
166477 WHERETRACE(0x20, ("range skip-scan regions: %u..%u adjust=%d est=%d\n",
166482 assert( *pbDone==0 );
166520 ** then nEq is set to 0.
166524 ** considering the range constraints. If nEq is 0, then *pnOut is the number of
166548 if( p->nSample>0 && ALWAYS(nEq<p->nSampleCol)
166586 if( nEq==0 ){
166587 iLower = 0;
166592 whereKeyStats(pParse, p, pRec, 0, a);
166593 iLower = a[0];
166594 iUpper = a[0] + a[1];
166597 assert( pLower==0 || (pLower->eOperator & (WO_GT|WO_GE))!=0 );
166598 assert( pUpper==0 || (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
166599 assert( p->aSortOrder!=0 );
166615 iLwrIdx = whereKeyStats(pParse, p, pRec, 0, a);
166616 iNew = a[0] + ((pLower->eOperator & mask) ? a[1] : 0);
166619 pLower = 0;
166633 iNew = a[0] + ((pUpper->eOperator & mask) ? a[1] : 0);
166636 pUpper = 0;
166656 WHERETRACE(0x20, ("STAT4 range scan: %u..%u est=%d\n",
166660 int bDone = 0;
166670 assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 || pParse->nErr>0 );
166680 if( pLower && pLower->truthProb>0 && pUpper && pUpper->truthProb>0 ){
166684 nOut -= (pLower!=0) + (pUpper!=0);
166689 WHERETRACE(0x20,("Range scan lowers nOut from %d to %d\n",
166730 assert( p->aSample!=0 );
166731 assert( p->nSample>0 );
166750 if( bOk==0 ) return SQLITE_NOTFOUND;
166753 whereKeyStats(pParse, p, pRec, 0, a);
166754 WHERETRACE(0x20,("equality scan regions %s(%d): %d\n",
166786 i64 nRow0 = sqlite3LogEstToInt(p->aiRowLogEst[0]);
166790 tRowcnt nRowEst = 0; /* New estimate of the number of rows */
166793 assert( p->aSample!=0 );
166794 for(i=0; rc==SQLITE_OK && i<pList->nExpr; i++){
166804 WHERETRACE(0x20,("IN row estimate: est=%d\n", nRowEst));
166817 if( pTerm==0 ){
166823 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
166828 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
166831 }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){
166832 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
166840 /* The 0x10000 .wheretrace flag causes extra information to be
166842 if( sqlite3WhereTrace & 0x10000 ){
166846 if( (pTerm->eOperator & (WO_OR|WO_AND))==0 && pTerm->u.x.iField ){
166849 if( pTerm->iParent>=0 ){
166853 sqlite3TreeViewExpr(0, pTerm->pExpr, 0);
166857 sqlite3WhereTermPrint(pTerm, 0);
166867 for(i=0; i<pWC->nTerm; i++){
166887 ** 1.002.001 t2.t2xy 2 f 010241 N 2 cost 0,56,31
166897 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
166902 pWInfo = 0;
166904 p->cId, p->iTab, p->maskSelf, p->prereq & 0xfff, p->cId, p->iTab);
166906 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
166908 if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
166909 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
166934 if( pWInfo && pWInfo->bStarUsed && p->rStarDelta!=0 ){
166940 if( p->nLTerm && (sqlite3WhereTrace & 0x4000)!=0 ){
166942 for(i=0; i<p->nLTerm; i++){
166948 if( p ) sqlite3WhereLoopPrint(p, 0);
166964 p->nLTerm = 0;
166966 p->wsFlags = 0;
166974 if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 && p->u.vtab.needFree ){
166976 p->u.vtab.needFree = 0;
166977 p->u.vtab.idxStr = 0;
166978 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
166981 p->u.btree.pIndex = 0;
166997 p->nLTerm = 0;
166998 p->wsFlags = 0;
167008 paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);
167009 if( paNew==0 ) return SQLITE_NOMEM_BKPT;
167010 memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0])*p->nLSlot);
167025 memset(pTo, 0, WHERE_LOOP_XFER_SZ);
167029 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
167031 pFrom->u.vtab.needFree = 0;
167032 }else if( (pFrom->wsFlags & WHERE_AUTO_INDEX)!=0 ){
167033 pFrom->u.btree.pIndex = 0;
167042 assert( db!=0 );
167051 assert( pWInfo!=0 );
167052 assert( db!=0 );
167097 if( pX->rRun>pY->rRun && pX->nOut>pY->nOut ) return 0; /* (1d) and (2a) */
167098 assert( (pX->wsFlags & WHERE_VIRTUALTABLE)==0 );
167099 assert( (pY->wsFlags & WHERE_VIRTUALTABLE)==0 );
167102 && pX->nSkip==0 && pY->nSkip==0 /* (1c) */
167107 return 0; /* (2b) */
167109 if( pY->nSkip > pX->nSkip ) return 0; /* (2d) */
167110 for(i=pX->nLTerm-1; i>=0; i--){
167111 if( pX->aLTerm[i]==0 ) continue;
167112 for(j=pY->nLTerm-1; j>=0; j--){
167115 if( j<0 ) return 0; /* (2c) */
167117 if( (pX->wsFlags&WHERE_IDX_ONLY)!=0
167118 && (pY->wsFlags&WHERE_IDX_ONLY)==0 ){
167119 return 0; /* (2e) */
167139 if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return;
167142 if( (p->wsFlags & WHERE_INDEXED)==0 ) continue;
167146 WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
167155 WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
167194 assert( p->rSetup==0 || pTemplate->rSetup==0
167205 if( (p->wsFlags & WHERE_AUTO_INDEX)!=0
167206 && (pTemplate->nSkip)==0
167207 && (pTemplate->wsFlags & WHERE_INDEXED)!=0
167208 && (pTemplate->wsFlags & WHERE_COLUMN_EQ)!=0
167224 return 0; /* Discard pTemplate */
167274 if( pBuilder->iPlanLimit==0 ){
167275 WHERETRACE(0xffffffff,("=== query planner search limit reached ===\n"));
167276 if( pBuilder->pOrSet ) pBuilder->pOrSet->n = 0;
167286 if( pBuilder->pOrSet!=0 ){
167294 #if WHERETRACE_ENABLED /* 0x8 */
167295 if( sqlite3WhereTrace & 0x8 ){
167308 if( ppPrev==0 ){
167311 #if WHERETRACE_ENABLED /* 0x8 */
167312 if( sqlite3WhereTrace & 0x8 ){
167326 #if WHERETRACE_ENABLED /* 0x8 */
167327 if( sqlite3WhereTrace & 0x8 ){
167328 if( p!=0 ){
167338 if( p==0 ){
167341 if( p==0 ) return SQLITE_NOMEM_BKPT;
167343 p->pNextLoop = 0;
167352 if( ppTail==0 ) break;
167354 if( pToDel==0 ) break;
167356 #if WHERETRACE_ENABLED /* 0x8 */
167357 if( sqlite3WhereTrace & 0x8 ){
167366 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
167369 p->u.btree.pIndex = 0;
167396 ** form "x==EXPR" and EXPR is not a constant 0 or 1, then make sure the
167399 ** out at least 3 out of 4 rows. If EXPR is -1 or 0 or 1, then maybe the
167400 ** "x" column is boolean or else -1 or 0 or 1 is a common default value
167412 LogEst iReduce = 0; /* pLoop->nOut should not exceed nRow-iReduce */
167414 assert( (pLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
167415 for(i=pWC->nBase, pTerm=pWC->a; i>0; i--, pTerm++){
167416 assert( pTerm!=0 );
167417 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
167418 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
167419 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) continue;
167420 for(j=pLoop->nLTerm-1; j>=0; j--){
167422 if( pX==0 ) continue;
167424 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
167426 if( j<0 ){
167438 if( (pTerm->eOperator & 0x3f)!=0
167440 & (JT_LEFT|JT_LTORJ))==0
167445 if( pTerm->truthProb<=0 ){
167453 if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0
167454 && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */
167457 int k = 0;
167459 if( sqlite3ExprIsInteger(pRight, &k, 0) && k>=(-1) && k<=1 ){
167509 char idxaff = 0; /* Indexed columns affinity */
167540 if( pColl==0 ) break;
167592 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
167595 assert( db->mallocFailed==0 || pParse->nErr>0 );
167599 WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d, rRun=%d\n",
167603 assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
167604 assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
167608 assert( pNew->u.btree.nBtm==0 );
167629 pNew->rSetup = 0;
167630 rSize = pProbe->aiRowLogEst[0];
167632 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
167636 int nIn = 0;
167640 if( (eOp==WO_ISNULL || (pTerm->wtFlags&TERM_VNULL)!=0)
167651 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0
167674 assert( nInMul==0
167675 || (pNew->wsFlags & WHERE_COLUMN_NULL)!=0
167676 || (pNew->wsFlags & WHERE_COLUMN_IN)!=0
167677 || (pNew->wsFlags & WHERE_SKIPSCAN)!=0
167691 ** first such term in use, and sets nIn back to 0 if it is not. */
167692 for(i=0; i<pNew->nLTerm-1; i++){
167693 if( pNew->aLTerm[i] && pNew->aLTerm[i]->pExpr==pExpr ) nIn = 0;
167725 if( x>=0 ){
167726 WHERETRACE(0x40,
167731 WHERETRACE(0x40,
167737 WHERETRACE(0x40,
167750 || (iCol>=0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1)
167773 pTop = 0;
167793 pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
167794 pNew->aLTerm[pNew->nLTerm-2] : 0;
167813 if( pTerm->truthProb<=0 && pProbe->aiColumn[saved_nEq]>=0 ){
167814 assert( (eOp & WO_IN) || nIn==0 );
167820 tRowcnt nOut = 0;
167821 if( nInMul==0
167824 && ((eOp & WO_IN)==0 || ExprUseXList(pTerm->pExpr))
167828 if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){
167844 && pNew->nOut+10 > pProbe->aiRowLogEst[0]
167846 #if WHERETRACE_ENABLED /* 0x01 */
167847 if( sqlite3WhereTrace & 0x20 ){
167865 if( nOut==0 )
167886 assert( pSrc->pSTab->szTabRow>0 );
167905 if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK|WHERE_EXPRIDX))==0 ){
167922 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
167960 && pProbe->noSkipScan==0
167961 && pProbe->hasStat1!=0
167969 pNew->aLTerm[pNew->nLTerm++] = 0;
167983 WHERETRACE(0x800, ("END %s.addBtreeIdx(%s), nEq=%d, rc=%d\n",
168005 if( pIndex->bUnordered ) return 0;
168006 if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
168007 for(ii=0; ii<pOB->nExpr; ii++){
168009 if( NEVER(pExpr==0) ) continue;
168013 if( pExpr->iColumn<0 ) return 1;
168014 for(jj=0; jj<pIndex->nKeyCol; jj++){
168017 }else if( (aColExpr = pIndex->aColExpr)!=0 ){
168018 for(jj=0; jj<pIndex->nKeyCol; jj++){
168020 if( sqlite3ExprCompareSkip(pExpr,aColExpr->a[jj].pExpr,iCursor)==0 ){
168026 return 0;
168042 if( jointype & JT_LTORJ ) return 0;
168045 if( !whereUsablePartialIndex(iTab,jointype,pWC,pWhere->pLeft) ) return 0;
168048 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
168052 && ((jointype & JT_OUTER)==0 || ExprHasProperty(pExpr, EP_OuterON))
168055 && (pTerm->wtFlags & TERM_VNULL)==0
168060 return 0;
168073 for(i=0; i<pIdx->nColumn; i++){
168075 && sqlite3ExprCompare(0, pExpr, pIdx->aColExpr->a[i].pExpr, iTabCur)==0
168080 return 0;
168121 /* if( pExpr->iColumn<(BMS-1) && pIdx->bHasExpr==0 ) return WRC_Continue;*/
168126 for(i=0; i<nColumn; i++){
168142 ** pWInfo->pSelect (columns from 0 through 62) or an index that has
168149 ** 0 The index is definitely not a covering index
168171 if( pWInfo->pSelect==0 ){
168174 return 0;
168176 if( pIdx->bHasExpr==0 ){
168177 for(i=0; i<pIdx->nColumn; i++){
168184 return 0;
168189 ck.bExpr = 0;
168190 ck.bUnidx = 0;
168191 memset(&w, 0, sizeof(w));
168197 rc = 0;
168212 while( *pp!=0 ){
168255 assert( pItem==0 || (pItem->fg.jointype & JT_RIGHT)==0 );
168256 assert( (pItem==0 || pMask==0) && (pMask!=0 || pItem!=0) );
168269 if( !sqlite3ExprIsConstant(0, pRight) ) return;
168271 if( pLeft->iColumn<0 ) return;
168278 int bNullRow = (pItem->fg.jointype&(JT_LEFT|JT_LTORJ))!=0;
168279 p->pExpr = sqlite3ExprDup(db, pRight, 0);
168287 if( p->pIENext==0 ){
168364 assert( pSrc->fg.isCte==0 );
168375 memset(&sPk, 0, sizeof(Index));
168384 aiRowEstPk[0] = pTab->nRowLogEst;
168385 aiRowEstPk[1] = 0;
168387 if( pSrc->fg.notIndexed==0 ){
168399 && (pWInfo->wctrlFlags & (WHERE_RIGHT_JOIN|WHERE_OR_SUBCLAUSE))==0
168400 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
168405 && (pSrc->fg.jointype & JT_RIGHT)==0 /* Not the right tab of a RIGHT JOIN */
168414 if( termCanDriveIndex(pTerm, pSrc, 0) ){
168416 pNew->nSkip = 0;
168417 pNew->u.btree.pIndex = 0;
168419 pNew->aLTerm[0] = pTerm;
168429 if( !IsView(pTab) && (pTab->tabFlags & TF_Ephemeral)==0 ){
168436 if( pNew->rSetup<0 ) pNew->rSetup = 0;
168454 pProbe=(pSrc->fg.isIndexedBy ? 0 : pProbe->pNext), iSortIdx++
168456 if( pProbe->pPartIdxWhere!=0
168464 rSize = pProbe->aiRowLogEst[0];
168465 pNew->u.btree.nEq = 0;
168466 pNew->u.btree.nBtm = 0;
168467 pNew->u.btree.nTop = 0;
168468 pNew->nSkip = 0;
168469 pNew->nLTerm = 0;
168470 pNew->iSortIdx = 0;
168471 pNew->rSetup = 0;
168475 pNew->u.btree.pOrderBy = 0;
168479 assert( (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || b==0 );
168485 pNew->iSortIdx = b ? iSortIdx : 0;
168499 pNew->rRun = rSize + 16 - 2*((pTab->tabFlags & TF_HasStat4)!=0);
168515 m = 0;
168521 pWInfo->pParse, pProbe, pProbe->pPartIdxWhere, &m, 0, 0
168525 if( m==TOPBIT || (pProbe->bHasExpr && !pProbe->bHasVCol && m!=0) ){
168527 if( isCov==0 ){
168528 WHERETRACE(0x200,
168531 assert( m!=0 );
168533 m = 0;
168536 WHERETRACE(0x200,
168541 WHERETRACE(0x200,
168546 }else if( m==0
168547 && (HasRowid(pTab) || pWInfo->pSelect!=0 || sqlite3FaultSim(700))
168549 WHERETRACE(0x200,
168551 pProbe->zName, m==0 ? "is" : "is not"));
168559 || pProbe->pPartIdxWhere!=0
168561 || ( m==0
168562 && pProbe->bUnordered==0
168564 && (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
168569 pNew->iSortIdx = b ? iSortIdx : 0;
168575 if( m!=0 ){
168585 for(ii=0; ii<pWC2->nTerm; ii++){
168592 if( pTerm->truthProb<=0 ){
168604 if( (pSrc->fg.jointype & JT_RIGHT)!=0 && pProbe->aColExpr ){
168617 pBuilder->bldFlags1 = 0;
168618 rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0);
168628 pBuilder->nRecValid = 0;
168629 pBuilder->pRec = 0;
168641 assert( pTerm->eOperator==WO_AUX || pTerm->eMatchOp==0 );
168648 ** marked as in-use (have argvIndex>0). False otherwise.
168655 for(ii=0; ii<nCons; ii++){
168656 if( aUsage[ii].argvIndex<=0 ) return 0;
168672 ** as the fourth argument (which in practice is either WO_IN or 0).
168704 *pbIn = 0;
168710 for(i=0; i<nConstraint; i++, pIdxCons++){
168712 pIdxCons->usable = 0;
168714 && (pTerm->eOperator & mExclude)==0
168722 memset(pUsage, 0, sizeof(pUsage[0])*nConstraint);
168723 assert( pIdxInfo->needToFreeIdxStr==0 );
168724 pIdxInfo->idxStr = 0;
168725 pIdxInfo->idxNum = 0;
168726 pIdxInfo->orderByConsumed = 0;
168729 pIdxInfo->idxFlags = 0;
168730 pHidden->mHandleIn = 0;
168740 WHERETRACE(0xffffffff, (" ^^^^--- non-viable plan rejected!\n"));
168749 memset(pNew->aLTerm, 0, sizeof(pNew->aLTerm[0])*nConstraint );
168750 memset(&pNew->u.vtab, 0, sizeof(pNew->u.vtab));
168752 for(i=0; i<nConstraint; i++, pIdxCons++){
168754 if( (iTerm = pUsage[i].argvIndex - 1)>=0 ){
168758 || j<0
168759 || (pTerm = termFromWhereClause(pWC, j))==0
168760 || pNew->aLTerm[iTerm]!=0
168761 || pIdxCons->usable==0
168768 testcase( j==0 );
168777 if( i<16 && ((1<<i)&mNoOmit)==0 ){
168789 }else if( (pTerm->eOperator & WO_IN)!=0 ){
168795 pIdxInfo->orderByConsumed = 0;
168797 *pbIn = 1; assert( (mExclude & WO_IN)==0 );
168822 for(i=0; i<=mxTerm; i++){
168823 if( pNew->aLTerm[i]==0 ){
168834 pIdxInfo->needToFreeIdxStr = 0;
168837 pIdxInfo->nOrderBy : 0);
168838 pNew->u.vtab.bIdxNumHex = (pIdxInfo->idxFlags&SQLITE_INDEX_SCAN_HEX)!=0;
168839 pNew->rSetup = 0;
168853 pNew->u.vtab.needFree = 0;
168855 WHERETRACE(0xffffffff, (" bIn=%d prereqIn=%04llx prereqOut=%04llx\n",
168879 const char *zRet = 0;
168880 if( iCons>=0 && iCons<pIdxInfo->nConstraint ){
168881 CollSeq *pC = 0;
168894 ** false otherwise. If iCons is an IN(...) constraint, set (if bHandle!=0)
168895 ** or clear (if bHandle==0) the flag to handle it using an iterator.
168901 if( bHandle==0 ){
168903 }else if( bHandle>0 ){
168908 return 0;
168923 sqlite3_value *pVal = 0;
168925 if( iCons<0 || iCons>=pIdxInfo->nConstraint ){
168928 if( pH->aRhs[iCons]==0 ){
168942 if( rc==SQLITE_OK && pVal==0 ){ /* IMP: R-19933-32160 */
168954 assert( pHidden->eDistinct>=0 && pHidden->eDistinct<=3 );
168970 for(i=0; i<nDb; i++){
168974 for(i=0; i<nDb; i++){
168975 sqlite3BeginWriteOperation(pParse, 0, i);
168985 ** mUnusable are set to 0. Otherwise, mPrereq is a mask of all FROM clause
169021 int bRetry = 0; /* True to retry with LIMIT/OFFSET disabled */
169023 assert( (mPrereq & mUnusable)==0 );
169031 if( p==0 ) return SQLITE_NOMEM_BKPT;
169032 pNew->rSetup = 0;
169034 pNew->nLTerm = 0;
169035 pNew->u.vtab.needFree = 0;
169043 WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pSTab->zName));
169044 WHERETRACE(0x800, (" VirtualOne: all usable\n"));
169046 pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, &bRetry
169051 pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, 0
169056 ** that does not require any source tables (IOW: a plan with mBest==0)
169060 if( rc==SQLITE_OK && ((mBest = (pNew->prereq & ~mPrereq))!=0 || bIn) ){
169061 int seenZero = 0; /* True if a plan with no prereqs seen */
169062 int seenZeroNoIN = 0; /* Plan with no prereqs and no IN(...) seen */
169063 Bitmask mPrev = 0;
169064 Bitmask mBestNoIn = 0;
169069 WHERETRACE(0x800, (" VirtualOne: all usable w/o IN\n"));
169071 pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn, 0);
169072 assert( bIn==0 );
169074 if( mBestNoIn==0 ){
169085 assert( mNext>0 );
169086 for(i=0; i<nConstraint; i++){
169094 WHERETRACE(0x800, (" VirtualOne: mPrev=%04llx mNext=%04llx\n",
169097 pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn, 0);
169100 if( bIn==0 ) seenZeroNoIN = 1;
169107 if( rc==SQLITE_OK && seenZero==0 ){
169108 WHERETRACE(0x800, (" VirtualOne: all disabled\n"));
169110 pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn, 0);
169111 if( bIn==0 ) seenZeroNoIN = 1;
169117 if( rc==SQLITE_OK && seenZeroNoIN==0 ){
169118 WHERETRACE(0x800, (" VirtualOne: all disabled and w/o IN\n"));
169120 pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn, 0);
169125 WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pSTab->zName, rc));
169153 memset(&sSum, 0, sizeof(sSum));
169161 if( (pTerm->eOperator & WO_OR)!=0
169162 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
169173 WHERETRACE(0x400, ("Begin processing OR-clause %p\n", pTerm));
169175 if( (pOrTerm->eOperator & WO_AND)!=0 ){
169188 sCur.n = 0;
169190 WHERETRACE(0x400, ("OR-term %d of %p has %d subterms:\n",
169192 if( sqlite3WhereTrace & 0x20000 ){
169207 testcase( rc==SQLITE_NOMEM && sCur.n>0 );
169209 if( sCur.n==0 ){
169210 sSum.n = 0;
169214 once = 0;
169218 sSum.n = 0;
169219 for(i=0; i<sPrev.n; i++){
169220 for(j=0; j<sCur.n; j++){
169229 pNew->aLTerm[0] = pTerm;
169231 pNew->rSetup = 0;
169232 pNew->iSortIdx = 0;
169233 memset(&pNew->u, 0, sizeof(pNew->u));
169234 for(i=0; rc==SQLITE_OK && i<sSum.n; i++){
169252 WHERETRACE(0x400, ("End processing OR-clause %p\n", pTerm));
169263 Bitmask mPrereq = 0;
169264 Bitmask mPrior = 0;
169271 int bFirstPastRJ = 0;
169272 int hasRightJoin = 0;
169280 assert( pNew->nLTerm==0 );
169281 assert( pNew->wsFlags==0 );
169283 assert( pNew->aLTerm!=0 );
169286 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
169287 Bitmask mUnusable = 0;
169292 || (pItem->fg.jointype & (JT_OUTER|JT_CROSS|JT_LTORJ))!=0
169306 bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
169308 mPrereq = 0;
169385 int iLoop, /* Which level of the nested loop. 0==outermost */
169393 u8 rev = 0; /* True if iOB and jSub sort in opposite directions */
169394 u8 revIdx = 0; /* Sort direction for jSub */
169399 assert( pSubOB!=0 );
169400 for(iOB=0; (MASKBIT(iOB) & *pOBSat)!=0; iOB++){}
169401 for(jSub=0; jSub<pSubOB->nExpr && iOB<pOrderBy->nExpr; jSub++, iOB++){
169402 if( pSubOB->a[jSub].u.x.iOrderByCol==0 ) break;
169407 if( (pWInfo->wctrlFlags & WHERE_GROUPBY)==0 ){
169414 if( jSub>0 ){
169421 if( (pLoop->wsFlags & WHERE_COROUTINE)!=0 ){
169431 return jSub>0;
169439 ** N>0: N terms of the ORDER BY clause are satisfied
169440 ** N==0: No terms of the ORDER BY clause are satisfied
169441 ** N<0: Unknown yet how many terms of ORDER BY might be satisfied.
169474 WhereLoop *pLoop = 0; /* Current WhereLoop being processed. */
169480 Bitmask obSat = 0; /* Mask of ORDER BY terms satisfied so far */
169507 assert( pOrderBy!=0 );
169508 if( nLoop && OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ) return 0;
169512 if( nOrderBy>BMS-1 ) return 0; /* Cannot optimize overly large ORDER BYs */
169515 orderDistinctMask = 0;
169516 ready = 0;
169521 for(iLoop=0; isOrderDistinct && obSat<obDone && iLoop<=nLoop; iLoop++){
169522 if( iLoop>0 ) ready |= pLoop->maskSelf;
169537 pLoop->u.btree.nDistinctCol = 0;
169546 for(i=0; i<nOrderBy; i++){
169549 if( NEVER(pOBExpr==0) ) continue;
169553 ~ready, eqOpMask, 0);
169554 if( pTerm==0 ) continue;
169561 for(j=0; j<pLoop->nLTerm && pTerm!=pLoop->aLTerm[j]; j++){}
169564 if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 && pOBExpr->iColumn>=0 ){
169569 if( pColl2==0 || sqlite3StrICmp(pColl1->zName, pColl2->zName) ){
169577 if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
169584 nColumn = 0;
169585 isOrderDistinct = 0;
169589 pIndex = 0;
169590 nKeyCol = 0;
169591 }else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
169592 return 0;
169604 && (pLoop->wsFlags & WHERE_SKIPSCAN)==0;
169610 rev = revSet = 0;
169611 distinctColumns = 0;
169612 for(j=0; j<nColumn; j++){
169616 || (pLoop->aLTerm[j]==0)==(j<pLoop->nSkip)
169633 if( (eOp & eqOpMask)!=0 ){
169638 isOrderDistinct = 0;
169650 bOnce = 0;
169666 revIdx = 0;
169673 if( iColumn>=0
169675 && pIndex->pTable->aCol[iColumn].notNull==0
169677 isOrderDistinct = 0;
169680 isOrderDistinct = 0;
169687 isMatch = 0;
169688 for(i=0; bOnce && i<nOrderBy; i++){
169693 if( NEVER(pOBExpr==0) ) continue;
169694 if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0;
169707 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
169715 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
169722 isMatch = 0;
169734 isMatch = 0;
169739 testcase( distinctColumns==0 );
169745 if( j==0 || j<nKeyCol ){
169746 testcase( isOrderDistinct!=0 );
169747 isOrderDistinct = 0;
169753 testcase( isOrderDistinct==0 );
169761 for(i=0; i<nOrderBy; i++){
169767 if( mTerm==0 && !sqlite3ExprIsConstant(0,p) ) continue;
169768 if( (mTerm&~orderDistinctMask)==0 ){
169776 for(i=nOrderBy-1; i>0; i--){
169777 Bitmask m = ALWAYS(i<BMS) ? MASKBIT(i) - 1 : 0;
169780 return 0;
169807 ** SELECT * FROM t1 GROUP BY y,x ORDER BY y,x; -- IsSorted()==0
169820 for(i=0; i<nLoop; i++){ zName[i] = pPath->aLoop[i]->cId; }
169822 zName[i] = 0;
169860 assert( pWInfo->pSelect!=0 );
169861 assert( pWInfo->pSelect->pEList!=0 );
169865 if( nSorted>0 ){
169875 if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 ){
169877 if( nSorted!=0 ){
169960 assert( pWLoop->pNextLoop==0 || pWLoop->iTab<=pWLoop->pNextLoop->iTab );
169971 Bitmask mSelfJoin = 0; /* Tables that cannot be dimension tables */
169983 for(iFromIdx=0, m=1; iFromIdx<nLoop; iFromIdx++, m<<=1){
169984 int nDep = 0; /* Number of dimension tables */
169986 Bitmask mSeen = 0; /* Mask of dimension tables */
169990 if( (pFactTab->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
170000 if( (aFromTabs[pWLoop->iTab].fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
170006 if( (pWLoop->prereq & m)!=0 /* pWInfo depends on iFromIdx */
170007 && (pWLoop->maskSelf & mSeen)==0 /* pWInfo not already a dependency */
170008 && (pWLoop->maskSelf & mSelfJoin)==0 /* Not a self-join */
170028 pWLoop->rStarDelta = 0;
170047 if( (pWLoop->maskSelf & mSeen)==0 ) continue;
170050 #ifdef WHERETRACE_ENABLED /* 0x80000 */
170051 if( sqlite3WhereTrace & 0x80000 ){
170066 #ifdef WHERETRACE_ENABLED /* 0x80000 */
170067 if( (sqlite3WhereTrace & 0x80000)!=0 && pWInfo->bStarUsed ){
170095 if( (pCandidate->wsFlags & WHERE_INDEXED)==0 ) return 1;
170096 if( (pBaseline->wsFlags & WHERE_INDEXED)==0 ) return 1;
170098 pBaseline->u.btree.pIndex->szIdxRow ) return 0;
170109 ** costs if nRowEst==0.
170120 int mxI = 0; /* Index of next entry to replace */
170122 LogEst mxCost = 0; /* Maximum cost of a set of paths */
170123 LogEst mxUnsort = 0; /* Maximum unsorted cost of a set of path */
170131 LogEst *aSortCost = 0; /* Sorting and partial sorting costs */
170137 WHERETRACE(0x002, ("---- begin solver. (nRowEst=%d, nQueryLoop=%d)\n",
170164 if( pWInfo->pOrderBy==0 || nRowEst==0 ){
170165 nOrderBy = 0;
170174 if( pSpace==0 ) return SQLITE_NOMEM_BKPT;
170177 memset(aFrom, 0, sizeof(aFrom[0]));
170179 for(ii=mxChoice*2, pFrom=aTo; ii>0; ii--, pFrom++, pX += nLoop){
170190 memset(aSortCost, 0, sizeof(LogEst) * nOrderBy);
170192 assert( aSortCost==0 || &pSpace[nSpace]==(char*)&aSortCost[nOrderBy] );
170193 assert( aSortCost!=0 || &pSpace[nSpace]==(char*)pX );
170200 aFrom[0].nRow = MIN(pParse->nQueryLoop, 48); assert( 48==sqlite3LogEst(28) );
170202 assert( aFrom[0].isOrdered==0 );
170210 aFrom[0].isOrdered = nLoop>0 ? -1 : nOrderBy;
170216 for(iLoop=0; iLoop<nLoop; iLoop++){
170217 nTo = 0;
170218 for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
170227 if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
170228 if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
170229 if( (pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 && pFrom->nRow<3 ){
170248 if( isOrdered<0 ){
170249 revMask = 0;
170256 if( isOrdered>=0 && isOrdered<nOrderBy ){
170257 if( aSortCost[isOrdered]==0 ){
170268 WHERETRACE(0x002,
170284 ** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent
170288 testcase( nTo==0 );
170289 for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
170291 && ((pTo->isOrdered^isOrdered)&0x80)==0
170305 #ifdef WHERETRACE_ENABLED /* 0x4 */
170306 if( sqlite3WhereTrace&0x4 ){
170309 isOrdered>=0 ? isOrdered+'0' : '?');
170324 #ifdef WHERETRACE_ENABLED /* 0x4 */
170325 if( sqlite3WhereTrace&0x4 ){
170328 isOrdered>=0 ? isOrdered+'0' : '?');
170346 #ifdef WHERETRACE_ENABLED /* 0x4 */
170347 if( sqlite3WhereTrace&0x4 ){
170351 isOrdered>=0 ? isOrdered+'0' : '?');
170353 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
170354 pTo->rUnsort, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
170364 #ifdef WHERETRACE_ENABLED /* 0x4 */
170365 if( sqlite3WhereTrace&0x4 ){
170369 isOrdered>=0 ? isOrdered+'0' : '?');
170371 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
170372 pTo->rUnsort, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
170386 mxI = 0;
170387 mxCost = aTo[0].rCost;
170388 mxUnsort = aTo[0].nRow;
170403 if( sqlite3WhereTrace & 0x02 ){
170404 LogEst rMin, rFloor = 0;
170405 int nDone = 0;
170409 nProgress = 0;
170410 rMin = 0x7fff;
170411 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
170414 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
170417 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
170418 pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?');
170419 if( pTo->isOrdered>0 ){
170420 sqlite3DebugPrintf(" rev=0x%llx\n", pTo->revLoop);
170429 }while( nDone<nTo && nProgress>0 );
170440 if( nFrom==0 ){
170453 for(iLoop=0; iLoop<nLoop; iLoop++){
170459 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0
170460 && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
170471 pWInfo->bOrderedInnerLoop = 0;
170479 assert( pWInfo->pSelect->pOrderBy==0
170483 if( pWInfo->nOBSat<=0 ){
170484 pWInfo->nOBSat = 0;
170485 if( nLoop>0 ){
170487 if( (wsFlags & WHERE_ONEROW)==0
170490 Bitmask m = 0;
170503 && (pWInfo->wctrlFlags & (WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX))!=0
170509 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0
170511 Bitmask revMask = 0;
170513 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
170515 assert( pWInfo->sorted==0 );
170578 int once = 0;
170580 for(i=0; i<pWInfo->nLevel; i++){
170582 if( p==0 ) break;
170583 if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 ) continue;
170584 if( (p->wsFlags & (WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0 ){
170589 if( (pLoop->wsFlags & (WHERE_CONSTRAINT|WHERE_AUTO_INDEX))!=0 ){
170594 if( sqlite3WhereTrace & 0x80 ){
170595 if( once==0 ){
170634 if( pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE ) return 0;
170638 if( IsVirtual(pTab) ) return 0;
170642 return 0;
170647 pLoop->wsFlags = 0;
170648 pLoop->nSkip = 0;
170649 pTerm = whereScanInit(&scan, pWC, iCur, -1, WO_EQ|WO_IS, 0);
170654 pLoop->aLTerm[0] = pTerm;
170664 || pIdx->pPartIdxWhere!=0
170668 for(j=0; j<pIdx->nKeyCol; j++){
170671 if( pTerm==0 ) break;
170677 if( pIdx->isCovering || (pItem->colUsed & pIdx->colNotIdxed)==0 ){
170690 pWInfo->a[0].pWLoop = pLoop;
170691 assert( pWInfo->sMaskSet.n==1 && iCur==pWInfo->sMaskSet.ix[0] );
170693 pWInfo->a[0].iTabCur = iCur;
170701 pLoop->cId = '0';
170704 if( sqlite3WhereTrace & 0x02 ){
170710 return 0;
170717 if( pExpr->op==TK_FUNCTION && ExprHasProperty(pExpr, EP_ConstFunc)==0 ){
170718 pWalker->eCode = 0;
170731 memset(&w, 0, sizeof(w));
170750 for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
170815 assert( pWInfo->pResultSet!=0 );
170816 assert( 0==(pWInfo->wctrlFlags & WHERE_AGG_DISTINCT) );
170822 hasRightJoin = (pWInfo->pTabList->a[0].fg.jointype & JT_LTORJ)!=0;
170831 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)==0
170832 && (pLoop->wsFlags & WHERE_ONEROW)==0
170836 if( (tabUsed & pLoop->maskSelf)!=0 ) continue;
170839 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
170854 WHERETRACE(0xffffffff,("-> omit unused FROM-clause term %c\n",pLoop->cId));
170856 testcase( ((pWInfo->revMask>>1) & ~m1)!=0 );
170860 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
170869 assert( pWInfo->nLevel>0 );
170896 LogEst nSearch = 0;
170900 for(i=0; i<pWInfo->nLevel; i++){
170905 if( (pTab->tabFlags & TF_HasStat1)==0 ) break;
170910 && ALWAYS((pLoop->wsFlags & (WHERE_IPK|WHERE_INDEXED))!=0)
170916 WHERETRACE(0xffffffff, (
170949 for(i=0; i<pIdx->nColumn; i++){
170954 }else if( j>=0 && (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)!=0 ){
170959 if( sqlite3ExprIsConstant(0,pExpr) ) continue;
170961 if( p==0 ) break;
170964 if( sqlite3WhereTrace & 0x200 ){
170966 if( sqlite3WhereTrace & 0x5000 ) sqlite3ShowExpr(pExpr);
170969 p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
170973 p->bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0;
170981 if( p->pIENext==0 ){
170998 for(ii=0; ii<pWInfo->pTabList->nSrc; ii++){
171002 || NEVER(pItem->fg.isSubquery==0)
171003 || pItem->u4.pSubq->pSelect->pOrderBy==0
171043 ** number pTabList->a[0].iCursor. t2 uses the cursor pTabList->a[1].iCursor.
171071 ** flag = 0
171077 ** if flag==0 then
171121 u8 bFordelete = 0; /* OPFLAG_FORDELETE or zero, as appropriate */
171123 assert( (wctrlFlags & WHERE_ONEPASS_MULTIROW)==0 || (
171124 (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0
171125 && (wctrlFlags & WHERE_OR_SUBCLAUSE)==0
171129 assert( (wctrlFlags & WHERE_OR_SUBCLAUSE)==0
171130 || (wctrlFlags & WHERE_USE_LIMIT)==0 );
171134 memset(&sWLB, 0, sizeof(sWLB));
171139 pOrderBy = 0;
171150 return 0;
171171 pWInfo = 0;
171181 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
171188 memset(&pWInfo->nOBSat, 0,
171190 memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel));
171193 pMaskSet->n = 0;
171194 pMaskSet->ix[0] = -99; /* Initialize ix[0] to a value that can never be
171196 ** test for pMaskSet->n==0 in sqlite3WhereGetMask() */
171214 if( nTabList==0 ){
171216 if( (wctrlFlags & WHERE_WANT_DISTINCT)!=0
171222 && (pWInfo->pSelect->selFlags & SF_MultiValue)==0
171224 ExplainQueryPlan((pParse, 0, "SCAN CONSTANT ROW"));
171241 ii = 0;
171248 Bitmask mx = 0;
171249 for(ii=0; ii<pTabList->nSrc; ii++){
171282 ** WHERE random()>0; -- eval random() once per row
171283 ** WHERE (SELECT random())>0; -- eval random() just once overall
171291 for(ii=0; ii<sWLB.pWC->nBase; ii++){
171296 assert( pX!=0 );
171297 assert( pT->prereqAll!=0 || !ExprHasProperty(pX, EP_OuterON) );
171298 if( pT->prereqAll==0 /* Conditions (1) and (2) */
171299 && (nTabList==0 || exprIsDeterministic(pX)) /* Condition (4) */
171301 && (pTabList->a[0].fg.jointype & JT_LTORJ)!=0 )
171317 }else if( pOrderBy==0 ){
171326 if( sqlite3WhereTrace & 0xffffffff ){
171327 sqlite3DebugPrintf("*** Optimizer Start *** (wctrlFlags: 0x%x",wctrlFlags);
171332 if( sqlite3WhereTrace & 0x8000 ){
171334 memset(&sSelect, 0, sizeof(sSelect));
171340 sqlite3TreeViewSelect(0, &sSelect, 0);
171342 if( sqlite3WhereTrace & 0x4000 ){ /* Display all WHERE clause terms */
171349 if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
171361 WHERETRACE(0xffffffff,
171375 wherePathSolver(pWInfo, 0);
171379 wherePathSolver(pWInfo, pWInfo->nRowOut<0 ? 1 : pWInfo->nRowOut+1);
171387 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
171388 WHERETRACE(0x0080,("nRowOut reduced from %d to %d due to DISTINCT\n",
171394 assert( pWInfo->pTabList!=0 );
171395 if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
171401 assert( db->mallocFailed==0 );
171406 if( pWInfo->nOBSat>0 ){
171407 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
171424 for(ii=0; ii<pWInfo->nLevel; ii++){
171440 notReady = ~(Bitmask)0;
171442 && pResultSet!=0 /* Condition (1) */
171443 && 0==(wctrlFlags & (WHERE_AGG_DISTINCT|WHERE_KEEP_ALL_JOINS)) /* (1),(6) */
171448 assert( nTabList>0 );
171461 if( sqlite3WhereTrace & 0x4000 ){ /* Display all terms of the WHERE clause */
171465 WHERETRACE(0xffffffff,("*** Optimizer Finished ***\n"));
171488 assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 );
171489 if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 ){
171490 int wsFlags = pWInfo->a[0].pWLoop->wsFlags;
171491 int bOnerow = (wsFlags & WHERE_ONEROW)!=0;
171492 assert( !(wsFlags&WHERE_VIRTUALTABLE) || IsVirtual(pTabList->a[0].pSTab) );
171494 0!=(wctrlFlags & WHERE_ONEPASS_MULTIROW)
171495 && !IsVirtual(pTabList->a[0].pSTab)
171496 && (0==(wsFlags & WHERE_MULTI_OR) || (wctrlFlags & WHERE_DUPLICATES_OK))
171500 if( HasRowid(pTabList->a[0].pSTab) && (wsFlags & WHERE_IDX_ONLY) ){
171504 pWInfo->a[0].pWLoop->wsFlags = (wsFlags & ~WHERE_IDX_ONLY);
171512 for(ii=0, pLevel=pWInfo->a; ii<nTabList; ii++, pLevel++){
171521 if( (pTab->tabFlags & TF_Ephemeral)!=0 || IsView(pTab) ){
171525 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
171528 sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
171533 if( ((pLoop->wsFlags & WHERE_IDX_ONLY)==0
171534 && (wctrlFlags & WHERE_OR_SUBCLAUSE)==0)
171535 || (pTabItem->fg.jointype & (JT_LTORJ|JT_RIGHT))!=0
171540 pWInfo->aiCurOnePass[0] = pTabItem->iCursor;
171548 && (pTab->tabFlags & (TF_HasGenerated|TF_WithoutRowid))==0
171549 && (pLoop->wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))==0
171555 int n = 0;
171561 if( pLoop->u.btree.pIndex!=0 && (pTab->tabFlags & TF_WithoutRowid)==0 ){
171569 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, pTabItem->iCursor, 0, 0,
171573 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
171580 assert( iAuxArg!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
171582 && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0
171587 op = 0;
171598 }else if( iAuxArg && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 ){
171606 if( pIx->pPartIdxWhere && (pTabItem->fg.jointype & JT_RIGHT)==0 ){
171608 pParse, pIx, pIx->pPartIdxWhere, 0, iIndexCur, pTabItem
171613 assert( pIx!=0 );
171615 assert( iIndexCur>=0 );
171619 if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
171620 && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
171621 && (pLoop->wsFlags & WHERE_BIGNULL_SORT)==0
171622 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0
171623 && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
171631 u64 colUsed = 0;
171633 for(ii=0; ii<pIx->nColumn; ii++){
171635 if( jj<0 ) continue;
171637 if( (pTabItem->colUsed & MASKBIT(jj))==0 ) continue;
171640 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, iIndexCur, 0, 0,
171646 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
171647 if( (pTabItem->fg.jointype & JT_RIGHT)!=0
171648 && (pLevel->pRJ = sqlite3WhereMalloc(pWInfo, sizeof(WhereRightJoin)))!=0
171655 sqlite3VdbeAddOp2(v, OP_Null, 0, pRJ->regReturn);
171660 pInfo = sqlite3KeyInfoAlloc(pParse->db, 1, 0);
171662 pInfo->aColl[0] = 0;
171663 pInfo->aSortFlags[0] = 0;
171675 pWInfo->nOBSat = 0;
171686 for(ii=0; ii<nTabList; ii++){
171696 int iOnce = 0;
171699 if( pSrc->fg.isCorrelated==0 ){
171702 iOnce = 0;
171709 if( (wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))!=0 ){
171710 if( (wsFlags & WHERE_AUTO_INDEX)!=0 ){
171725 if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_OR_SUBCLAUSE)==0 ){
171744 sqlite3ShowWhereLoopList(0);
171746 return 0;
171764 if( (db->flags & SQLITE_VdbeAddopTrace)==0 ) return;
171765 sqlite3VdbePrintOp(0, pc, pOp);
171766 sqlite3ShowWhereTerm(0); /* So compiler won't complain about unused func */
171783 int nRJ = 0;
171788 for(i=pWInfo->nLevel-1; i>=0; i--){
171796 pLevel->addrCont = 0;
171805 int addrSeek = 0;
171810 && (pLoop->wsFlags & WHERE_INDEXED)!=0
171812 && (n = pLoop->u.btree.nDistinctCol)>0
171817 for(j=0; j<n; j++){
171822 addrSeek = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
171847 if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
171851 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
171858 (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0
171859 && (pLoop->wsFlags & WHERE_IN_EARLYOUT)!=0;
171895 sqlite3VdbeAddOp3(v, OP_Return, pLevel->pRJ->regReturn, 0, 1);
171914 assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 );
171915 if( (ws & WHERE_IDX_ONLY)==0 ){
171922 assert( pSrc->pSTab!=0 );
171924 sqlite3VdbeAddOp3(v, OP_Null, 0, n, n+m-1);
171951 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
171954 Index *pIdx = 0;
171957 assert( pTab!=0 );
171976 assert( pTabItem->u4.pSubq->regResult>=0 );
171978 pTabItem->u4.pSubq->regResult, 0);
172011 if( sqlite3WhereTrace & 0x200 ){
172014 if( sqlite3WhereTrace & 0x5000 ) sqlite3ShowExpr(p->pExpr);
172056 assert( x>=0 );
172062 if( x>=0 ){
172281 sqlite3_result_int64(pCtx, (p ? *p : 0));
172317 p->nStep = 0;
172354 if( iVal<=0 ) goto error_out;
172358 p->pValue = sqlite3_value_dup(apArg[0]);
172375 p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, 0);
172379 p->pValue = 0;
172392 if( p && p->pValue==0 ){
172393 p->pValue = sqlite3_value_dup(apArg[0]);
172407 p->pValue = 0;
172428 if( p->nValue==0 ){
172440 p->nValue = 0;
172456 UNUSED_PARAMETER(nArg); assert( nArg==0 );
172469 UNUSED_PARAMETER(nArg); assert( nArg==0 );
172501 UNUSED_PARAMETER(nArg); assert( nArg==0 );
172514 UNUSED_PARAMETER(nArg); assert( nArg==0 );
172521 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, 0);
172553 if( p->nTotal==0 ){
172554 p->nParam = sqlite3_value_int64(apArg[0]);
172555 if( p->nParam<=0 ){
172578 if( p && p->nParam>0 ){
172580 if( nSize==0 ){
172620 p->pVal = sqlite3_value_dup(apArg[0]);
172621 if( p->pVal==0 ){
172639 if( p->nVal==0 ){
172641 p->pVal = 0;
172647 p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, 0);
172658 p->pVal = 0;
172699 assert(0); /*NO_TEST*/
172706 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
172708 name ## InvFunc, name ## Name, {0} \
172714 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
172716 noopStepFunc, name ## Name, {0} \
172723 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
172725 noopStepFunc, name ## Name, {0} \
172734 WINDOWFUNCX(row_number, 0, 0),
172735 WINDOWFUNCX(dense_rank, 0, 0),
172736 WINDOWFUNCX(rank, 0, 0),
172737 WINDOWFUNCALL(percent_rank, 0, 0),
172738 WINDOWFUNCALL(cume_dist, 0, 0),
172739 WINDOWFUNCALL(ntile, 1, 0),
172740 WINDOWFUNCALL(last_value, 1, 0),
172741 WINDOWFUNCALL(nth_value, 2, 0),
172742 WINDOWFUNCALL(first_value, 1, 0),
172743 WINDOWFUNCNOOP(lead, 1, 0),
172744 WINDOWFUNCNOOP(lead, 2, 0),
172745 WINDOWFUNCNOOP(lead, 3, 0),
172746 WINDOWFUNCNOOP(lag, 1, 0),
172747 WINDOWFUNCNOOP(lag, 2, 0),
172748 WINDOWFUNCNOOP(lag, 3, 0),
172756 if( sqlite3StrICmp(p->zName, zName)==0 ) break;
172758 if( p==0 ){
172787 if( pWin->zName && pWin->eFrmType==0 ){
172789 if( p==0 ) return;
172790 pWin->pPartition = sqlite3ExprListDup(pParse->db, p->pPartition, 0);
172791 pWin->pOrderBy = sqlite3ExprListDup(pParse->db, p->pOrderBy, 0);
172792 pWin->pStart = sqlite3ExprDup(pParse->db, p->pStart, 0);
172793 pWin->pEnd = sqlite3ExprDup(pParse->db, p->pEnd, 0);
172803 && (pWin->pOrderBy==0 || pWin->pOrderBy->nExpr!=1)
172832 for(i=0; i<ArraySize(aUp); i++){
172836 pWin->pEnd = pWin->pStart = 0;
172840 pWin->eExclude = 0;
172873 assert( p!=0 );
172874 assert( p->pWin!=0 );
172887 for(i=0; i<nSrc; i++){
172917 for(i=0; i<p->pSub->nExpr; i++){
172918 if( 0==sqlite3ExprCompare(0, p->pSub->a[i].pExpr, pExpr, -1) ){
172924 if( iCol<0 ){
172925 Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0);
172931 assert( ExprHasProperty(pExpr, EP_Static)==0 );
172935 memset(pExpr, 0, sizeof(Expr));
172938 pExpr->iColumn = (iCol<0 ? p->pSub->nExpr-1: iCol);
172991 assert( pWin!=0 );
172992 memset(&sWalker, 0, sizeof(Walker));
172993 memset(&sRewrite, 0, sizeof(WindowRewrite));
173022 int nInit = pList ? pList->nExpr : 0;
173023 for(i=0; i<pAppend->nExpr; i++){
173025 Expr *pDup = sqlite3ExprDup(db, pAppend->a[i].pExpr, 0);
173034 if( sqlite3ExprIsInteger(pSub, &iDummy, 0) ){
173037 pSub->u.zToken = 0;
173065 if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){
173083 && p->pPrior==0
173084 && ALWAYS((p->selFlags & SF_WinRewrite)==0)
173089 Select *pSub = 0; /* The subquery */
173094 ExprList *pSort = 0;
173096 ExprList *pSublist = 0; /* Expression list for sub-query */
173105 if( pTab==0 ){
173110 if( (p->selFlags & SF_Aggregate)==0 ){
173112 w.xSelectCallback = 0;
173116 p->pSrc = 0;
173117 p->pWhere = 0;
173118 p->pGroupBy = 0;
173119 p->pHaving = 0;
173126 pSort = exprListAppendList(pParse, 0, pMWin->pPartition, 1);
173131 if( sqlite3ExprListCompare(pSort, p->pOrderBy, -1)==0 ){
173133 p->pOrderBy = 0;
173146 pMWin->nBufferCol = (pSublist ? pSublist->nExpr : 0);
173151 pSublist = exprListAppendList(pParse, pSublist, pMWin->pPartition, 0);
173152 pSublist = exprListAppendList(pParse, pSublist, pMWin->pOrderBy, 0);
173161 assert( pWin->pWFunc!=0 );
173165 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
173168 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
173169 pSublist = exprListAppendList(pParse, pSublist, pArgs, 0);
173172 Expr *pFilter = sqlite3ExprDup(db, pWin->pFilter, 0);
173177 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
173186 if( pSublist==0 ){
173187 pSublist = sqlite3ExprListAppend(pParse, 0,
173188 sqlite3Expr(db, TK_INTEGER, "0")
173193 pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
173195 TREETRACE(0x40,pParse,pSub,
173198 p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
173199 assert( pSub!=0 || p->pSrc==0 ); /* Due to db->mallocFailed test inside
173202 if( p->pSrc==0 ){
173204 }else if( sqlite3SrcItemAttachSubquery(pParse, &p->pSrc->a[0], pSub, 0) ){
173206 p->pSrc->a[0].fg.isCorrelated = 1;
173211 if( pTab2==0 ){
173219 p->pSrc->a[0].pSTab = pTab;
173221 memset(&w, 0, sizeof(w));
173236 assert( rc==SQLITE_OK || pParse->nErr!=0 );
173248 p->ppThis = 0;
173288 if( 0==sqlite3ExprIsConstant(0,pExpr) ){
173291 pExpr = sqlite3ExprAlloc(pParse->db, TK_NULL, 0, 0);
173301 int eType, /* Frame type. TK_RANGE, TK_ROWS, TK_GROUPS, or 0 */
173308 Window *pWin = 0;
173309 int bImplicitFrame = 0;
173312 assert( eType==0 || eType==TK_RANGE || eType==TK_ROWS || eType==TK_GROUPS );
173317 assert( (eStart==TK_PRECEDING || eStart==TK_FOLLOWING)==(pStart!=0) );
173318 assert( (eEnd==TK_FOLLOWING || eEnd==TK_PRECEDING)==(pEnd!=0) );
173320 if( eType==0 ){
173347 if( pWin==0 ) goto windowAllocErr;
173351 if( eExclude==0 && OptimizationDisabled(pParse->db, SQLITE_WindowFunc) ){
173363 return 0;
173403 const char *zErr = 0;
173409 }else if( pExist->bImplicitFrame==0 ){
173417 pWin->pPartition = sqlite3ExprListDup(db, pExist->pPartition, 0);
173419 assert( pWin->pOrderBy==0 );
173420 pWin->pOrderBy = sqlite3ExprListDup(db, pExist->pOrderBy, 0);
173423 pWin->zBase = 0;
173458 if( 0==pSel->pWin || 0==sqlite3WindowCompare(0, pSel->pWin, pWin, 0) ){
173474 ** Return 0 if the two window objects are identical, 1 if they are
173485 if( NEVER(p1==0) || NEVER(p2==0) ) return 1;
173503 return 0;
173518 assert( pSelect->pSrc->a[0].fg.isSubquery );
173519 nEphExpr = pSelect->pSrc->a[0].u4.pSubq->pSelect->pEList->nExpr;
173534 sqlite3VdbeAddOp3(v, OP_Null, 0, pMWin->regPart, pMWin->regPart+nExpr-1);
173545 sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
173556 ** regApp+0: slot to copy min()/max() argument to for MakeRecord
173564 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
173569 assert( pKeyInfo->aSortFlags[0]==0 );
173570 pKeyInfo->aSortFlags[0] = KEYINFO_ORDER_DESC;
173574 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
173591 #define WINDOW_STARTING_INT 0
173598 ** A "PRECEDING <expr>" (eCond==0) or "FOLLOWING <expr>" (eCond==1) or the
173615 assert( eCond>=0 && eCond<ArraySize(azErr) );
173616 sqlite3VdbeAddOp2(v, OP_Integer, 0, regZero);
173619 sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
173629 assert( eCond==0 || eCond==1 || eCond==2 );
173630 VdbeCoverageIf(v, eCond==0);
173636 VdbeCoverageNeverNullIf(v, eCond==0); /* NULL case captured by */
173655 return (pList ? pList->nExpr : 0);
173722 ** 0.
173753 int iColOff = pMWin->nBufferCol + (pPart ? pPart->nExpr : 0);
173755 for(i=0; i<pOrderBy->nExpr; i++){
173762 ** Generate VM code to invoke either xStep() (if bInverse is 0) or
173768 ** If argument csr is greater than or equal to 0, then argument reg is
173793 int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin);
173795 int addrIf = 0;
173797 assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );
173801 assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)!=1 );
173803 for(i=0; i<nArg; i++){
173816 assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
173819 addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
173824 if( pMWin->regStartRowid==0
173830 if( bInverse==0 ){
173836 sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
173843 assert( pWin->pFilter==0 );
173847 assert( bInverse==0 || bInverse==1 );
173857 sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
173868 assert( nArg>0 );
173870 pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
173871 sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
173894 ** Generate VM code to invoke either xValue() (bFin==0) or xFinalize()
173906 if( pMWin->regStartRowid==0
173910 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
173913 sqlite3VdbeAddOp3(v, OP_Column, pWin->csrApp, 0, pWin->regResult);
173916 assert( pMWin->regStartRowid==0 );
173923 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
173944 int regCRowid = 0; /* Current rowid value */
173945 int regCPeer = 0; /* Current peer values */
173946 int regRowid = 0; /* AggStep rowid value */
173947 int regPeer = 0; /* AggStep peer values */
173957 assert( pMWin!=0 );
173959 nPeer = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
173975 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
173990 int addrEq = 0;
173991 KeyInfo *pKeyInfo = 0;
173994 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pMWin->pOrderBy, 0, 0);
173997 addrEq = sqlite3VdbeAddOp3(v, OP_Eq, regCRowid, 0, regRowid);
174008 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblNext);
174013 windowAggStep(p, pMWin, csr, 0, p->regArg);
174063 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
174074 sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, 0, tmpReg);
174088 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
174124 int nArg = 0;
174129 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
174131 if( pMWin->regStartRowid==0 ){
174133 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp);
174134 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
174140 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
174166 return 0;
174189 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
174198 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
174250 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_DESC ){
174283 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_BIGNULL ){
174288 sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
174300 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
174322 sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
174323 addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
174335 pColl = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[0].pExpr);
174366 int ret = 0;
174368 int addrContinue = 0;
174372 int addrNextRange = 0;
174377 assert( regCountdown==0 && jumpOnEof==0 );
174378 return 0;
174381 if( regCountdown>0 ){
174406 if( op==WINDOW_RETURN_ROW && pMWin->regStartRowid==0 ){
174407 windowAggFinal(p, 0);
174463 windowAggStep(p, pMWin, csr, 0, p->regArg);
174481 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblDone);
174486 int nReg = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
174487 int regTmp = (nReg ? sqlite3GetTempRange(pParse, nReg) : 0);
174494 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNextRange);
174507 Window *pNew = 0;
174513 pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0);
174515 pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0);
174516 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0);
174526 pNew->pStart = sqlite3ExprDup(db, p->pStart, 0);
174527 pNew->pEnd = sqlite3ExprDup(db, p->pEnd, 0);
174541 Window *pRet = 0;
174545 *pp = sqlite3WindowDup(db, 0, pWin);
174546 if( *pp==0 ) break;
174562 int ret = 0;
174564 sqlite3_value *pVal = 0;
174566 if( pVal && sqlite3_value_int(pVal)>0 ){
174607 ** if( (regEnd--)<=0 ){
174609 ** if( (regStart--)<=0 ){
174620 ** if( (regStart--)<=0 ){
174660 ** if( (regEnd--)<=0 ){
174664 ** if( (regStart--)<=0 ){
174670 ** if( (regEnd--)<=0 ){
174689 ** if( (regEnd--)<=0 ){
174692 ** if( (regStart--)<=0 ){
174700 ** if( (regEnd--)<=0 ){
174704 ** if( (regStart--)<=0 ){
174715 ** CURRENT ROW by assuming that it is equivalent to "0 PRECEDING/FOLLOWING".
174737 ** if( (regStart--)<=0 ){
174919 int csrInput = p->pSrc->a[0].iCursor; /* Cursor of sub-select */
174920 int nInput = p->pSrc->a[0].pSTab->nCol; /* Number of cols returned by sub */
174923 int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */
174924 int addrInteger = 0; /* Address of OP_Integer */
174928 int regNewPeer = 0; /* Peer values for new row (part of regNew) */
174929 int regPeer = 0; /* Peer values for current row */
174930 int regFlushPart = 0; /* Register for "Gosub flush_partition" */
174933 int regStart = 0; /* Value of <expr> PRECEDING */
174934 int regEnd = 0; /* Value of <expr> FOLLOWING */
174942 assert( pMWin->eExclude==0 || pMWin->eExclude==TK_CURRENT
174950 memset(&s, 0, sizeof(WindowCodeArg));
174962 ** are four options - they may never be deleted (eDelete==0), they may
174976 if( windowCacheFrame(pMWin)==0 ){
175015 int nPeer = (pOrderBy ? pOrderBy->nExpr : 0);
175027 for(iInput=0; iInput<nInput; iInput++){
175042 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
175057 addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, s.regRowid);
175065 windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE?3:0));
175069 windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE?3:0));
175074 int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
175077 windowAggFinal(&s, 0);
175081 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
175101 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
175110 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
175116 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175117 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
175118 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
175121 windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 0);
175122 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175128 windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
175129 if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175130 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
175131 if( !bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175133 int addr = 0;
175134 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
175137 int lbl = 0;
175143 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
175144 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175146 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
175151 addr = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0, 1);
175154 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
175155 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175167 addrInteger = sqlite3VdbeAddOp2(v, OP_Integer, 0, regFlushPart);
175171 s.regRowid = 0;
175176 windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
175177 if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175178 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
175184 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
175188 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
175193 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, 0, 1);
175200 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
175203 addrBreak3 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
175204 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
175210 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
175212 addrBreak = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
175213 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175214 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
175223 sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
175331 memset(&pParse->u1.cr, 0, sizeof(pParse->u1.cr));
175363 assert( p!=0 );
175365 Select *pNext = 0, *pLoop = p;
175372 if( pLoop==0 ) break;
175376 pLoop->pOrderBy!=0 ? "ORDER BY" : "LIMIT",
175381 if( (p->selFlags & (SF_MultiValue|SF_Values))==0
175382 && (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
175408 return sqlite3FaultSim(700) ? 0 : sqlite3_realloc(pOld, newSize);
175416 /* memset(p, 0, sizeof(Expr)); */
175418 p->affExpr = 0;
175422 p->pLeft = p->pRight = 0;
175423 p->pAggInfo = 0;
175424 memset(&p->x, 0, sizeof(p->x));
175425 memset(&p->y, 0, sizeof(p->y));
175426 p->op2 = 0;
175427 p->iTable = 0;
175428 p->iColumn = 0;
175431 p->u.zToken[t.n] = 0;
175433 if( sqlite3Isquote(p->u.zToken[0]) ){
175436 #if SQLITE_MAX_EXPR_DEPTH>0
175454 pA->pRight = 0;
175470 ExprList *p = sqlite3ExprListAppend(pParse, pPrior, 0);
175472 && pParse->db->init.busy==0
175796 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
175813 #if YYSTACKDEPTH<=0 || YYDYNSTACK
175816 # define YYGROWABLESTACK 0
175821 #if YYSTACKDEPTH<=0
175835 ** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
175879 /* 0 */ 130, 127, 234, 282, 282, 1328, 576, 1307, 460, 289,
176102 /* 0 */ 277, 278, 279, 241, 242, 225, 195, 227, 195, 241,
176282 /* 1800 */ 158, 0, 1, 2, 247, 227, 5, 221, 221, 221,
176344 #define YY_SHIFT_MIN (0)
176347 /* 0 */ 2029, 1801, 2043, 1380, 1380, 318, 271, 1496, 1569, 1642,
176348 /* 10 */ 702, 702, 702, 740, 318, 318, 318, 318, 318, 0,
176349 /* 20 */ 0, 216, 1177, 702, 702, 702, 702, 702, 702, 702,
176411 /* 0 */ -67, 1252, -64, -178, -181, 160, 1071, 143, -184, 137,
176455 /* 0 */ 1663, 1663, 1663, 1491, 1254, 1367, 1254, 1254, 1254, 1254,
176533 0, /* $ => nothing */
176534 0, /* SEMI => nothing */
176539 0, /* TRANSACTION => nothing */
176543 0, /* COMMIT => nothing */
176548 0, /* TO => nothing */
176549 0, /* TABLE => nothing */
176550 0, /* CREATE => nothing */
176552 0, /* NOT => nothing */
176553 0, /* EXISTS => nothing */
176555 0, /* LP => nothing */
176556 0, /* RP => nothing */
176557 0, /* AS => nothing */
176558 0, /* COMMA => nothing */
176576 0, /* OR => nothing */
176577 0, /* AND => nothing */
176578 0, /* IS => nothing */
176579 0, /* ISNOT => nothing */
176582 0, /* BETWEEN => nothing */
176583 0, /* IN => nothing */
176584 0, /* ISNULL => nothing */
176585 0, /* NOTNULL => nothing */
176586 0, /* NE => nothing */
176587 0, /* EQ => nothing */
176588 0, /* GT => nothing */
176589 0, /* LE => nothing */
176590 0, /* LT => nothing */
176591 0, /* GE => nothing */
176592 0, /* ESCAPE => nothing */
176593 0, /* ID => nothing */
176635 0, /* ANY => nothing */
176636 0, /* BITAND => nothing */
176637 0, /* BITOR => nothing */
176638 0, /* LSHIFT => nothing */
176639 0, /* RSHIFT => nothing */
176640 0, /* PLUS => nothing */
176641 0, /* MINUS => nothing */
176642 0, /* STAR => nothing */
176643 0, /* SLASH => nothing */
176644 0, /* REM => nothing */
176645 0, /* CONCAT => nothing */
176646 0, /* PTR => nothing */
176647 0, /* COLLATE => nothing */
176648 0, /* BITNOT => nothing */
176649 0, /* ON => nothing */
176650 0, /* INDEXED => nothing */
176651 0, /* STRING => nothing */
176652 0, /* JOIN_KW => nothing */
176653 0, /* CONSTRAINT => nothing */
176654 0, /* DEFAULT => nothing */
176655 0, /* NULL => nothing */
176656 0, /* PRIMARY => nothing */
176657 0, /* UNIQUE => nothing */
176658 0, /* CHECK => nothing */
176659 0, /* REFERENCES => nothing */
176660 0, /* AUTOINCR => nothing */
176661 0, /* INSERT => nothing */
176662 0, /* DELETE => nothing */
176663 0, /* UPDATE => nothing */
176664 0, /* SET => nothing */
176665 0, /* DEFERRABLE => nothing */
176666 0, /* FOREIGN => nothing */
176667 0, /* DROP => nothing */
176668 0, /* UNION => nothing */
176669 0, /* ALL => nothing */
176670 0, /* EXCEPT => nothing */
176671 0, /* INTERSECT => nothing */
176672 0, /* SELECT => nothing */
176673 0, /* VALUES => nothing */
176674 0, /* DISTINCT => nothing */
176675 0, /* DOT => nothing */
176676 0, /* FROM => nothing */
176677 0, /* JOIN => nothing */
176678 0, /* USING => nothing */
176679 0, /* ORDER => nothing */
176680 0, /* GROUP => nothing */
176681 0, /* HAVING => nothing */
176682 0, /* LIMIT => nothing */
176683 0, /* WHERE => nothing */
176684 0, /* RETURNING => nothing */
176685 0, /* INTO => nothing */
176686 0, /* NOTHING => nothing */
176687 0, /* FLOAT => nothing */
176688 0, /* BLOB => nothing */
176689 0, /* INTEGER => nothing */
176690 0, /* VARIABLE => nothing */
176691 0, /* CASE => nothing */
176692 0, /* WHEN => nothing */
176693 0, /* THEN => nothing */
176694 0, /* ELSE => nothing */
176695 0, /* INDEX => nothing */
176696 0, /* ALTER => nothing */
176697 0, /* ADD => nothing */
176698 0, /* WINDOW => nothing */
176699 0, /* OVER => nothing */
176700 0, /* FILTER => nothing */
176701 0, /* COLUMN => nothing */
176702 0, /* AGG_FUNCTION => nothing */
176703 0, /* AGG_COLUMN => nothing */
176704 0, /* TRUEFALSE => nothing */
176705 0, /* FUNCTION => nothing */
176706 0, /* UPLUS => nothing */
176707 0, /* UMINUS => nothing */
176708 0, /* TRUTH => nothing */
176709 0, /* REGISTER => nothing */
176710 0, /* VECTOR => nothing */
176711 0, /* SELECT_COLUMN => nothing */
176712 0, /* IF_NULL_ROW => nothing */
176713 0, /* ASTERISK => nothing */
176714 0, /* SPAN => nothing */
176715 0, /* ERROR => nothing */
176716 0, /* QNUMBER => nothing */
176717 0, /* SPACE => nothing */
176718 0, /* COMMENT => nothing */
176719 0, /* ILLEGAL => nothing */
176769 static FILE *yyTraceFILE = 0;
176770 static char *yyTracePrompt = 0;
176794 if( yyTraceFILE==0 ) yyTracePrompt = 0;
176795 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
176803 /* 0 */ "$",
177133 /* 0 */ "explain ::= EXPLAIN",
177549 ** of errors. Return 0 on success.
177560 pNew = YYREALLOC(0, newSize*sizeof(pNew[0]));
177561 if( pNew==0 ) return 1;
177562 memcpy(pNew, p->yystack, oldSize*sizeof(pNew[0]));
177564 pNew = YYREALLOC(p->yystack, newSize*sizeof(pNew[0]));
177565 if( pNew==0 ) return 1;
177576 return 0;
177602 yypParser->yyhwm = 0;
177610 yypParser->yystack[0].stateno = 0;
177611 yypParser->yystack[0].major = 0;
177772 assert( pParser->yytos!=0 );
177827 if( p==0 ) return;
177864 int nMissed = 0;
177865 for(stateno=0; stateno<YYNSTATE; stateno++){
177867 for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
177869 if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
177898 assert( i>=0 );
177908 assert( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) );
177910 if( iFallback!=0 ){
177917 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
177925 assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) );
177926 if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){
177940 assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) );
177966 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
177970 assert( i>=0 && i<YY_ACTTAB_COUNT );
178058 191, /* (0) explain ::= EXPLAIN */
178472 -1, /* (0) explain ::= EXPLAIN */
178476 0, /* (4) transtype ::= */
178487 0, /* (15) ifnotexists ::= */
178490 0, /* (18) temp ::= */
178493 0, /* (21) table_option_set ::= */
178498 0, /* (26) typetoken ::= */
178502 0, /* (30) scanpt ::= */
178503 0, /* (31) scantok ::= */
178519 0, /* (47) autoinc ::= */
178521 0, /* (49) refargs ::= */
178534 0, /* (62) init_deferred_pred_opt ::= */
178537 0, /* (65) conslist_opt ::= */
178544 0, /* (72) defer_subclause_opt ::= */
178545 0, /* (73) onconf ::= */
178547 0, /* (75) orconf ::= */
178553 0, /* (81) ifexists ::= */
178572 0, /* (100) distinct ::= */
178573 0, /* (101) sclp ::= */
178578 0, /* (106) as ::= */
178579 0, /* (107) from ::= */
178582 0, /* (110) stl_prefix ::= */
178588 0, /* (116) dbnm ::= */
178602 0, /* (130) on_using ::= */
178603 0, /* (131) indexed_opt ::= */
178606 0, /* (134) orderby_opt ::= */
178612 0, /* (140) sortorder ::= */
178615 0, /* (143) nulls ::= */
178616 0, /* (144) groupby_opt ::= */
178618 0, /* (146) having_opt ::= */
178620 0, /* (148) limit_opt ::= */
178625 0, /* (153) where_opt ::= */
178627 0, /* (155) where_opt_ret ::= */
178638 0, /* (166) upsert ::= */
178647 0, /* (175) idlist_opt ::= */
178704 0, /* (232) case_else ::= */
178705 0, /* (233) case_operand ::= */
178706 0, /* (234) exprlist ::= */
178709 0, /* (237) paren_exprlist ::= */
178713 0, /* (241) uniqueflag ::= */
178714 0, /* (242) eidlist_opt ::= */
178718 0, /* (246) collate ::= */
178724 0, /* (252) vinto ::= */
178736 0, /* (264) trigger_time ::= */
178740 0, /* (268) when_clause ::= */
178759 0, /* (287) key_opt ::= */
178773 0, /* (301) vtabarg ::= */
178793 0, /* (321) frame_opt ::= */
178803 0, /* (331) frame_exclude_opt ::= */
178822 0, /* (350) trans_opt ::= */
178826 0, /* (354) savepoint_opt ::= */
178838 0, /* (366) carglist ::= */
178845 0, /* (373) tconscomma ::= */
178853 0, /* (381) returning ::= */
178864 0, /* (392) foreach_clause ::= */
178867 0, /* (395) tridxby ::= */
178869 0, /* (397) database_kw_opt ::= */
178870 0, /* (398) kwcolumn_opt ::= */
178875 0, /* (403) anylist ::= */
178878 0, /* (406) with ::= */
178914 ** case 0:
178922 case 0: /* explain ::= EXPLAIN */
178923 { if( pParse->pReprepare==0 ) pParse->explain = 1; }
178926 { if( pParse->pReprepare==0 ) pParse->explain = 2; }
178941 {yymsp[0].minor.yy502 = yymsp[0].major; /*A-overwrites-X*/}
178949 sqlite3Savepoint(pParse, SAVEPOINT_BEGIN, &yymsp[0].minor.yy0);
178954 sqlite3Savepoint(pParse, SAVEPOINT_RELEASE, &yymsp[0].minor.yy0);
178959 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
178964 …sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy502,0,0,yymsp[…
178980 {yymsp[1].minor.yy502 = 0;}
178986 {yymsp[0].minor.yy502 = pParse->db->init.busy==0;}
178990 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy9,0);
178995 sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy637);
178996 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy637);
179000 {yymsp[1].minor.yy9 = 0;}
179003 {yylhsminor.yy9 = yymsp[-2].minor.yy9|yymsp[0].minor.yy9;}
179008 if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
179011 yymsp[-1].minor.yy9 = 0;
179012 … sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
179018 if( yymsp[0].minor.yy0.n==6 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"strict",6)==0 ){
179021 yylhsminor.yy9 = 0;
179022 … sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
179025 yymsp[0].minor.yy9 = yylhsminor.yy9;
179028 {sqlite3AddColumn(pParse,yymsp[-1].minor.yy0,yymsp[0].minor.yy0);}
179033 {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;}
179037 …yymsp[-3].minor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
179042 …yymsp[-5].minor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
179046 {yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
179062 {ASSERT_IS_CREATE; pParse->u1.cr.constraintName = yymsp[0].minor.yy0;}
179065 {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy590,yymsp[-1].minor.yy0.z,&yymsp[-1].minor.yy0.z[yy…
179068 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy590,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);}
179071 {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy590,yymsp[-2].minor.yy0.z,&yymsp[-1].minor.yy0.z[yy…
179075 Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy590, 0);
179081 Expr *p = tokenExpr(pParse, TK_STRING, yymsp[0].minor.yy0);
179086 sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n);
179090 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy502);}
179093 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy502,yymsp[0].minor.yy502,yymsp[-2].minor.yy502);}
179096 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy502,0,0,0,0,
179100 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy590,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy0.z)…
179103 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy402,yymsp[0].minor.yy502);}
179106 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy502);}
179109 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
179112 {sqlite3AddGenerated(pParse,yymsp[-1].minor.yy590,0);}
179115 {sqlite3AddGenerated(pParse,yymsp[-2].minor.yy590,&yymsp[0].minor.yy0);}
179118 {yymsp[0].minor.yy502 = 1;}
179121 { yymsp[1].minor.yy502 = OE_None*0x0101; /* EV: R-19803-45884 */}
179124 { yymsp[-1].minor.yy502 = (yymsp[-1].minor.yy502 & ~yymsp[0].minor.yy481.mask) | yymsp[0].minor.yy4…
179127 { yymsp[-1].minor.yy481.value = 0; yymsp[-1].minor.yy481.mask = 0x000000; }
179130 { yymsp[-2].minor.yy481.value = 0; yymsp[-2].minor.yy481.mask = 0x000000; }
179133 { yymsp[-2].minor.yy481.value = yymsp[0].minor.yy502; yymsp[-2].minor.yy481.mask = 0x0000ff; }
179136 { yymsp[-2].minor.yy481.value = yymsp[0].minor.yy502<<8; yymsp[-2].minor.yy481.mask = 0x00ff00; }
179145 { yymsp[0].minor.yy502 = OE_Cascade; /* EV: R-33326-45252 */}
179148 { yymsp[0].minor.yy502 = OE_Restrict; /* EV: R-33326-45252 */}
179154 {yymsp[-2].minor.yy502 = 0;}
179159 {yymsp[-1].minor.yy502 = yymsp[0].minor.yy502;}
179169 {yymsp[-1].minor.yy502 = 0;}
179172 {ASSERT_IS_CREATE; pParse->u1.cr.constraintName.n = 0;}
179175 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy402,yymsp[0].minor.yy502,yymsp[-2].minor.yy502,0);}
179178 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy402,yymsp[0].minor.yy502,0,0,0,0,
179187 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy502);
179195 {yymsp[-2].minor.yy502 = yymsp[0].minor.yy502;}
179198 {yymsp[0].minor.yy502 = OE_Ignore;}
179202 {yymsp[0].minor.yy502 = OE_Replace;}
179206 sqlite3DropTable(pParse, yymsp[0].minor.yy563, 0, yymsp[-1].minor.yy502);
179211 …0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy402, yymsp[0].minor.yy637, yymsp[…
179216 sqlite3DropTable(pParse, yymsp[0].minor.yy563, 1, yymsp[-1].minor.yy502);
179221 SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0, 0};
179222 if( (pParse->db->mDbFlags & DBFLAG_EncodingFixed)!=0
179225 sqlite3Select(pParse, yymsp[0].minor.yy637, &dest);
179227 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy637);
179231 {yymsp[-2].minor.yy637 = attachWithToSelect(pParse,yymsp[0].minor.yy637,yymsp[-1].minor.yy125);}
179234 {yymsp[-3].minor.yy637 = attachWithToSelect(pParse,yymsp[0].minor.yy637,yymsp[-1].minor.yy125);}
179238 Select *p = yymsp[0].minor.yy637;
179246 Select *pRhs = yymsp[0].minor.yy637;
179251 x.n = 0;
179253 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0);
179254 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
179270 {yymsp[0].minor.yy502 = yymsp[0].major; /*A-overwrites-OP*/}
179277 …inor.yy402,yymsp[-2].minor.yy590,yymsp[-1].minor.yy402,yymsp[-7].minor.yy502,yymsp[0].minor.yy590);
179282 …inor.yy402,yymsp[-3].minor.yy590,yymsp[-1].minor.yy402,yymsp[-8].minor.yy502,yymsp[0].minor.yy590);
179292 yymsp[-3].minor.yy637 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy402,0,0,0,0,0,SF_Values,0);
179297 sqlite3MultiValuesEnd(pParse, yymsp[0].minor.yy637);
179307 {yymsp[0].minor.yy502 = SF_Distinct;}
179310 {yymsp[0].minor.yy502 = SF_All;}
179318 {yymsp[1].minor.yy402 = 0;}
179323 …if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy402, &yymsp[0].minor…
179329 Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
179330 sqlite3ExprSetErrorOffset(p, (int)(yymsp[0].minor.yy0.z - pParse->zTail));
179337 pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
179338 sqlite3ExprSetErrorOffset(pRight, (int)(yymsp[0].minor.yy0.z - pParse->zTail));
179348 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
179352 {yymsp[1].minor.yy563 = 0;}
179356 yymsp[-1].minor.yy563 = yymsp[0].minor.yy563;
179362 …3 && yymsp[-1].minor.yy563->nSrc>0) ) yymsp[-1].minor.yy563->a[yymsp[-1].minor.yy563->nSrc-1].fg.j…
179367 …inor.yy563,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0,&yymsp[0].minor.yy421);
179372 …inor.yy563,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,0,&yymsp[0].minor.yy421);
179378 …inor.yy563,&yymsp[-6].minor.yy0,&yymsp[-5].minor.yy0,&yymsp[-1].minor.yy0,0,&yymsp[0].minor.yy421);
179384 …cListAppendFromTerm(pParse,yymsp[-5].minor.yy563,0,0,&yymsp[-1].minor.yy0,yymsp[-3].minor.yy637,&y…
179389 …if( yymsp[-5].minor.yy563==0 && yymsp[-1].minor.yy0.n==0 && yymsp[0].minor.yy421.pOn==0 && yymsp[0…
179391 }else if( ALWAYS(yymsp[-3].minor.yy563!=0) && yymsp[-3].minor.yy563->nSrc==1 ){
179392 … sqlite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy563,0,0,&yymsp[-1].minor.yy0,0,&yymsp[0].mi…
179396 assert( pOld->fg.fixedSchema==0 );
179398 assert( pOld->fg.fixedSchema==0 );
179402 pOld->u4.pSubq = 0;
179403 pOld->fg.isSubquery = 0;
179404 assert( pNew->u4.pSubq!=0 && pNew->u4.pSubq->pSelect!=0 );
179405 if( (pNew->u4.pSubq->pSelect->selFlags & SF_NestedFrom)!=0 ){
179410 pOld->u4.zDatabase = 0;
179414 pOld->u1.pFuncArg = 0;
179415 pOld->fg.isTabFunc = 0;
179418 pOld->zName = 0;
179424 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-3].minor.yy563,0,0,0,0,SF_NestedFrom,0);
179425 …ite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy563,0,0,&yymsp[-1].minor.yy0,pSubquery,&yymsp[0…
179431 {yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;}
179435 yylhsminor.yy563 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0);
179436 …ylhsminor.yy563 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy563->a[0].zName, &yymsp[0].minor.yy0);
179438 yymsp[0].minor.yy563 = yylhsminor.yy563;
179442 yylhsminor.yy563 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
179443 …ylhsminor.yy563 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy563->a[0].zName, &yymsp[0].minor.yy0);
179448 {yymsp[0].minor.yy563 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/}
179451 {yymsp[-2].minor.yy563 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /…
179455 …yymsp[-4].minor.yy563 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); …
179456 … yymsp[-4].minor.yy563 ) yymsp[-4].minor.yy563->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yy…
179461 yymsp[-2].minor.yy563 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/
179462 … yymsp[-2].minor.yy563 ) yymsp[-2].minor.yy563->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yy…
179466 { yymsp[0].minor.yy502 = JT_INNER; }
179469 {yymsp[-1].minor.yy502 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
179472 {yymsp[-2].minor.yy502 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-o…
179478 {yymsp[-1].minor.yy421.pOn = yymsp[0].minor.yy590; yymsp[-1].minor.yy421.pUsing = 0;}
179481 {yymsp[-3].minor.yy421.pOn = 0; yymsp[-3].minor.yy421.pUsing = yymsp[-1].minor.yy204;}
179484 {yymsp[1].minor.yy421.pOn = 0; yymsp[1].minor.yy421.pUsing = 0;}
179487 {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
179490 {yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;}
179494 {yymsp[-2].minor.yy402 = yymsp[0].minor.yy402;}
179499 sqlite3ExprListSetSortOrder(yymsp[-4].minor.yy402,yymsp[-1].minor.yy502,yymsp[0].minor.yy502);
179504 yymsp[-2].minor.yy402 = sqlite3ExprListAppend(pParse,0,yymsp[-2].minor.yy590); /*A-overwrites-Y*/
179505 sqlite3ExprListSetSortOrder(yymsp[-2].minor.yy402,yymsp[-1].minor.yy502,yymsp[0].minor.yy502);
179509 {yymsp[0].minor.yy502 = SQLITE_SO_ASC;}
179512 {yymsp[0].minor.yy502 = SQLITE_SO_DESC;}
179531 {yymsp[1].minor.yy590 = 0;}
179538 {yymsp[-1].minor.yy590 = yymsp[0].minor.yy590;}
179541 {yymsp[-1].minor.yy590 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy590,0);}
179544 {yymsp[-3].minor.yy590 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy590,yymsp[0].minor.yy590);}
179547 {yymsp[-3].minor.yy590 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy590,yymsp[-2].minor.yy590);}
179552 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy563,yymsp[0].minor.yy590,0,0);
179556 {sqlite3AddReturning(pParse,yymsp[0].minor.yy402); yymsp[-1].minor.yy590 = 0;}
179559 {sqlite3AddReturning(pParse,yymsp[0].minor.yy402); yymsp[-3].minor.yy590 = yymsp[-2].minor.yy590;}
179570 pSubquery = sqlite3SelectNew(pParse,0,pFromClause,0,0,0,0,SF_NestedFrom,0);
179571 as.n = 0;
179572 as.z = 0;
179573 pFromClause = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
179577 …arse,yymsp[-5].minor.yy563,yymsp[-2].minor.yy402,yymsp[0].minor.yy590,yymsp[-6].minor.yy502,0,0,0);
179582 …yymsp[-4].minor.yy402 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy402, yymsp[0].minor.yy590);
179588 …e3ExprListAppendVector(pParse, yymsp[-6].minor.yy402, yymsp[-3].minor.yy204, yymsp[0].minor.yy590);
179593 yylhsminor.yy402 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy590);
179600 …yymsp[-4].minor.yy402 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy204, yymsp[0].min…
179605 ….yy563, yymsp[-1].minor.yy637, yymsp[-2].minor.yy204, yymsp[-5].minor.yy502, yymsp[0].minor.yy403);
179610 sqlite3Insert(pParse, yymsp[-4].minor.yy563, 0, yymsp[-3].minor.yy204, yymsp[-6].minor.yy502, 0);
179614 { yymsp[1].minor.yy403 = 0; }
179617 { yymsp[-1].minor.yy403 = 0; sqlite3AddReturning(pParse,yymsp[0].minor.yy402); }
179620 …nor.yy402,yymsp[-6].minor.yy590,yymsp[-2].minor.yy402,yymsp[-1].minor.yy590,yymsp[0].minor.yy403);}
179623 …qlite3UpsertNew(pParse->db,yymsp[-5].minor.yy402,yymsp[-3].minor.yy590,0,0,yymsp[0].minor.yy403); }
179626 { yymsp[-4].minor.yy403 = sqlite3UpsertNew(pParse->db,0,0,0,0,0); }
179629 …yymsp[-7].minor.yy403 = sqlite3UpsertNew(pParse->db,0,0,yymsp[-2].minor.yy402,yymsp[-1].minor.yy59…
179632 {sqlite3AddReturning(pParse,yymsp[0].minor.yy402);}
179635 {yymsp[1].minor.yy204 = 0;}
179641 {yymsp[-2].minor.yy204 = sqlite3IdListAppend(pParse,yymsp[-2].minor.yy204,&yymsp[0].minor.yy0);}
179644 {yymsp[0].minor.yy204 = sqlite3IdListAppend(pParse,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
179650 {yymsp[0].minor.yy590=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
179655 Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
179664 Expr *temp3 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
179667 sqlite3RenameTokenRemap(pParse, 0, temp1);
179675 {yymsp[0].minor.yy590=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
179679 yylhsminor.yy590 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
179680 if( yylhsminor.yy590 ) yylhsminor.yy590->w.iOfst = (int)(yymsp[0].minor.yy0.z - pParse->zTail);
179682 yymsp[0].minor.yy590 = yylhsminor.yy590;
179686 if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
179687 u32 n = yymsp[0].minor.yy0.n;
179688 yymsp[0].minor.yy590 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0);
179689 sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy590, n);
179694 Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
179696 if( pParse->nested==0 ){
179698 yymsp[0].minor.yy590 = 0;
179700 yymsp[0].minor.yy590 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
179701 if( yymsp[0].minor.yy590 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy590->iTable);
179708 …yymsp[-2].minor.yy590 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy590, &yymsp[0].minor.…
179714 sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy590, yymsp[-3].minor.yy590, 0);
179732 yylhsminor.yy590 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0, 0);
179739 sqlite3WindowAttach(pParse, yylhsminor.yy590, yymsp[0].minor.yy483);
179746 sqlite3WindowAttach(pParse, yylhsminor.yy590, yymsp[0].minor.yy483);
179753 yylhsminor.yy590 = sqlite3ExprFunction(pParse, 0, &yymsp[-4].minor.yy0, 0);
179754 sqlite3WindowAttach(pParse, yylhsminor.yy590, yymsp[0].minor.yy483);
179760 yylhsminor.yy590 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0, 0);
179762 yymsp[0].minor.yy590 = yylhsminor.yy590;
179767 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
179771 yymsp[-4].minor.yy590->flags |= pList->a[0].pExpr->flags & EP_Propagate;
179779 {yymsp[-2].minor.yy590=sqlite3ExprAnd(pParse,yymsp[-2].minor.yy590,yymsp[0].minor.yy590);}
179788 {yymsp[-2].minor.yy590=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy590,yymsp[0].minor.yy5…
179791 {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-o…
179796 int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
179797 yymsp[-1].minor.yy0.n &= 0x7fffffff;
179798 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy590);
179800 yymsp[-2].minor.yy590 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
179801 if( bNot ) yymsp[-2].minor.yy590 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy590, 0);
179808 int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
179809 yymsp[-3].minor.yy0.n &= 0x7fffffff;
179810 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy590);
179812 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy590);
179813 yymsp[-4].minor.yy590 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0, 0);
179814 if( bNot ) yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy590, 0);
179819 {yymsp[-1].minor.yy590 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy590,0);}
179822 {yymsp[-2].minor.yy590 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy590,0);}
179826 yymsp[-2].minor.yy590 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy590,yymsp[0].minor.yy590);
179827 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy590, yymsp[-2].minor.yy590, TK_ISNULL);
179832 yymsp[-3].minor.yy590 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy590,yymsp[0].minor.yy590);
179833 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy590, yymsp[-3].minor.yy590, TK_NOTNULL);
179838 yymsp[-5].minor.yy590 = sqlite3PExpr(pParse,TK_IS,yymsp[-5].minor.yy590,yymsp[0].minor.yy590);
179839 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy590, yymsp[-5].minor.yy590, TK_ISNULL);
179844 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-4].minor.yy590,yymsp[0].minor.yy590);
179845 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy590, yymsp[-4].minor.yy590, TK_NOTNULL);
179850 {yymsp[-1].minor.yy590 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy590, 0);/*A-overwri…
179854 Expr *p = yymsp[0].minor.yy590;
179862 yymsp[-1].minor.yy590 = sqlite3PExpr(pParse, op, p, 0);
179869 ExprList *pList = sqlite3ExprListAppend(pParse, 0, yymsp[-2].minor.yy590);
179870 pList = sqlite3ExprListAppend(pParse, pList, yymsp[0].minor.yy590);
179871 yylhsminor.yy590 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
179877 {yymsp[0].minor.yy502 = 0;}
179881 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy590);
179882 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy590);
179883 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy590, 0);
179889 …p[-3].minor.yy502 ) yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy590, 0);
179894 if( yymsp[-1].minor.yy402==0 ){
179900 ** simplify to constants 0 (false) and 1 (true), respectively,
179907 Expr *pRHS = yymsp[-1].minor.yy402->a[0].pExpr;
179909 yymsp[-1].minor.yy402->a[0].pExpr = 0;
179911 pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0);
179914 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy590, 0);
179916 pRHS->x.pSelect = 0;
179919 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy590, 0);
179920 if( yymsp[-4].minor.yy590==0 ){
179934 …p[-3].minor.yy502 ) yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy590, 0);
179940 yymsp[-2].minor.yy590 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
179946 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy590, 0);
179948 …p[-3].minor.yy502 ) yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy590, 0);
179953 SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
179954 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
179955 …if( yymsp[0].minor.yy402 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy40…
179956 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy590, 0);
179958 …p[-3].minor.yy502 ) yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy590, 0);
179964 p = yymsp[-3].minor.yy590 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
179970 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy590, 0);
179983 yymsp[-4].minor.yy402 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy402, yymsp[0].minor.yy590);
179988 yymsp[-3].minor.yy402 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy590);
179989 yymsp[-3].minor.yy402 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy402, yymsp[0].minor.yy590);
179993 {yymsp[-2].minor.yy402 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy402,yymsp[0].minor.yy590);}
179996 {yymsp[0].minor.yy402 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy590); /*A-overwrites-Y*/}
180005 …sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy402, yymsp[-10].minor.yy5…
180006 …&yymsp[-11].minor.yy0, yymsp[0].minor.yy590, SQLITE_SO_ASC, yymsp[-8].minor.yy502, SQLITE_IDXTYPE_…
180014 {yymsp[0].minor.yy502 = OE_Abort;}
180021 …(pParse, yymsp[-4].minor.yy402, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy502, yymsp[0].minor.yy502);
180026 …2].minor.yy402 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy502, y…
180030 {sqlite3DropIndex(pParse, yymsp[0].minor.yy563, yymsp[-1].minor.yy502);}
180033 {sqlite3Vacuum(pParse,0,yymsp[0].minor.yy590);}
180036 {sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy590);}
180039 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
180042 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
180045 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
180048 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
180057 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
180063 …ymsp[-4].minor.yy28.a, yymsp[-4].minor.yy28.b, yymsp[-2].minor.yy563, yymsp[0].minor.yy590, yymsp[…
180064 …yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-ove…
180067 pParse->isCreate = 0; /* But, should not be set for CREATE TRIGGER */
180072 { yymsp[0].minor.yy502 = yymsp[0].major; /*A-overwrites-X*/ }
180082 {yymsp[0].minor.yy28.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy28.b = 0;}
180085 {yymsp[-2].minor.yy28.a = TK_UPDATE; yymsp[-2].minor.yy28.b = yymsp[0].minor.yy204;}
180089 { yymsp[1].minor.yy590 = 0; }
180093 { yymsp[-1].minor.yy590 = yymsp[0].minor.yy590; }
180097 assert( yymsp[-2].minor.yy319!=0 );
180104 assert( yymsp[-1].minor.yy319!=0 );
180110 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
180131 …yy402, yymsp[-1].minor.yy590, yymsp[-7].minor.yy502, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy342);}
180136 …637,yymsp[-6].minor.yy502,yymsp[-1].minor.yy403,yymsp[-7].minor.yy342,yymsp[0].minor.yy342);/*yylh…
180141 …pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy590, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy342);}
180145 …rSelectStep(pParse->db, yymsp[-1].minor.yy637, yymsp[-2].minor.yy342, yymsp[0].minor.yy342); /*yyl…
180150 yymsp[-3].minor.yy590 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
180158 yymsp[-5].minor.yy590 = sqlite3PExpr(pParse, TK_RAISE, yymsp[-1].minor.yy590, 0);
180165 {yymsp[0].minor.yy502 = OE_Rollback;}
180168 {yymsp[0].minor.yy502 = OE_Fail;}
180172 sqlite3DropTrigger(pParse,yymsp[0].minor.yy563,yymsp[-1].minor.yy502);
180177 sqlite3Attach(pParse, yymsp[-3].minor.yy590, yymsp[-1].minor.yy590, yymsp[0].minor.yy590);
180182 sqlite3Detach(pParse, yymsp[0].minor.yy590);
180186 {sqlite3Reindex(pParse, 0, 0);}
180189 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
180192 {sqlite3Analyze(pParse, 0, 0);}
180195 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
180199 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy563,&yymsp[0].minor.yy0);
180210 sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy563, &yymsp[0].minor.yy0);
180216 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy563);
180221 …sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy563, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
180225 {sqlite3VtabFinishParse(pParse,0);}
180228 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
180232 …sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yym…
180241 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
180245 { sqlite3WithPush(pParse, yymsp[0].minor.yy125, 1); }
180248 {yymsp[0].minor.yy444 = M10d_Any;}
180266 yymsp[0].minor.yy125 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy361); /*A-overwrites-X*/
180271 yymsp[-2].minor.yy125 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy125, yymsp[0].minor.yy361);
180276 assert( yymsp[0].minor.yy483!=0 );
180277 sqlite3WindowChain(pParse, yymsp[0].minor.yy483, yymsp[-2].minor.yy483);
180278 yymsp[0].minor.yy483->pNextWin = yymsp[-2].minor.yy483;
180279 yylhsminor.yy483 = yymsp[0].minor.yy483;
180294 ….yy483 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy483, yymsp[-2].minor.yy402, yymsp[-1].mino…
180299 …yylhsminor.yy483 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy483, yymsp[-2].minor.yy402, yyms…
180305 …[-3].minor.yy483 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy483, 0, yymsp[-1].minor.yy402, 0…
180310 …yylhsminor.yy483 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy483, 0, yymsp[-1].minor.yy402, &…
180316 …yylhsminor.yy483 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy483, 0, 0, &yymsp[-1].minor.yy0);
180322 yymsp[1].minor.yy483 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
180327 …02, yymsp[-1].minor.yy205.eType, yymsp[-1].minor.yy205.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy444);
180333 …minor.yy205.pExpr, yymsp[-1].minor.yy205.eType, yymsp[-1].minor.yy205.pExpr, yymsp[0].minor.yy444);
180339 {yylhsminor.yy205 = yymsp[0].minor.yy205;}
180340 yymsp[0].minor.yy205 = yylhsminor.yy205;
180345 {yylhsminor.yy205.eType = yymsp[-1].major; yylhsminor.yy205.pExpr = 0;}
180349 {yylhsminor.yy205.eType = yymsp[0].major; yylhsminor.yy205.pExpr = yymsp[-1].minor.yy590;}
180353 {yymsp[1].minor.yy444 = 0;}
180356 {yymsp[-1].minor.yy444 = yymsp[0].minor.yy444;}
180363 {yymsp[0].minor.yy444 = yymsp[0].major; /*A-overwrites-X*/}
180366 { yymsp[-1].minor.yy483 = yymsp[0].minor.yy483; }
180370 if( yymsp[0].minor.yy483 ){
180371 yymsp[0].minor.yy483->pFilter = yymsp[-1].minor.yy590;
180375 yylhsminor.yy483 = yymsp[0].minor.yy483;
180381 yylhsminor.yy483 = yymsp[0].minor.yy483;
180383 yymsp[0].minor.yy483 = yylhsminor.yy483;
180390 yylhsminor.yy483->pFilter = yymsp[0].minor.yy590;
180392 sqlite3ExprDelete(pParse->db, yymsp[0].minor.yy590);
180395 yymsp[0].minor.yy483 = yylhsminor.yy483;
180400 assert( yymsp[-3].minor.yy483!=0 );
180407 …yymsp[-1].minor.yy483->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.y…
180416 yylhsminor.yy590=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0);
180419 yymsp[0].minor.yy590 = yylhsminor.yy590;
180490 assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
180548 if( TOKEN.z[0] ){
180614 int yyerrorhit = 0; /* True if yymajor has invoked an error */
180620 assert( yypParser->yytos!=0 );
180622 yyendofinput = (yymajor==0);
180645 assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) );
180665 if( yyRuleInfoNRhs[yyruleno]==0 ){
180722 if( yypParser->yyerrcnt<0 ){
180742 if( yypParser->yytos <= yypParser->yystack || yymajor==0 ){
180778 if( yypParser->yyerrcnt<=0 ){
180810 ** 0 if iToken has no fallback.
180814 assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) );
180818 return 0;
180852 #define CC_X 0 /* The letter 'x', or start of BLOB literal */
180881 #define CC_NUL 29 /* 0x00 */
180882 #define CC_BOM 30 /* First byte of UTF8 BOM: 0xEF 0xBB 0xBF */
180887 /* 0x */ 29, 28, 28, 28, 28, 28, 28, 28, 28, 7, 7, 28, 7, 7, 28, 28,
180892 /* 5x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 9, 28, 28, 28, 2,
180894 /* 7x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 28, 10, 28, 25, 28,
180906 /* 0x */ 29, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 7, 7, 28, 28,
180916 /* Ax */ 28, 25, 1, 1, 1, 1, 1, 0, 2, 2, 28, 28, 28, 28, 28, 28,
180920 /* Ex */ 28, 28, 1, 1, 1, 1, 1, 0, 2, 2, 28, 28, 28, 28, 28, 28,
180940 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
180941 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
180942 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
180943 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
180944 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3x */
180945 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 4x */
180946 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 5x */
180947 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 95, 0, 0, /* 6x */
180948 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 7x */
180949 0, 97, 98, 99,100,101,102,103,104,105, 0, 0, 0, 0, 0, 0, /* 8x */
180950 0,106,107,108,109,110,111,112,113,114, 0, 0, 0, 0, 0, 0, /* 9x */
180951 0, 0,115,116,117,118,119,120,121,122, 0, 0, 0, 0, 0, 0, /* Ax */
180952 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */
180953 0, 97, 98, 99,100,101,102,103,104,105, 0, 0, 0, 0, 0, 0, /* Cx */
180954 0,106,107,108,109,110,111,112,113,114, 0, 0, 0, 0, 0, 0, /* Dx */
180955 0, 0,115,116,117,118,119,120,121,122, 0, 0, 0, 0, 0, 0, /* Ex */
180956 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Fx */
181041 84, 92, 134, 82, 105, 29, 0, 0, 94, 0, 85, 72, 0,
181042 53, 35, 86, 15, 0, 42, 97, 54, 89, 135, 19, 0, 0,
181043 140, 0, 40, 129, 0, 22, 107, 0, 9, 0, 0, 123, 80,
181044 0, 78, 6, 0, 65, 103, 147, 0, 136, 115, 0, 0, 48,
181045 0, 90, 24, 0, 17, 0, 27, 70, 23, 26, 5, 60, 142,
181046 110, 122, 0, 73, 91, 71, 145, 61, 120, 74, 0, 49, 0,
181047 11, 41, 0, 113, 0, 0, 0, 109, 10, 111, 116, 125, 14,
181048 50, 124, 0, 100, 0, 18, 121, 144, 56, 130, 139, 88, 83,
181049 37, 30, 126, 0, 0, 108, 51, 131, 128, 0, 34, 0, 0,
181050 132, 0, 98, 38, 39, 0, 20, 45, 117, 93,
181052 /* aKWNext[] forms the hash collision chain. If aKWHash[i]==0
181055 static const unsigned char aKWNext[148] = {0,
181056 0, 0, 0, 0, 4, 0, 43, 0, 0, 106, 114, 0, 0,
181057 0, 2, 0, 0, 143, 0, 0, 0, 13, 0, 0, 0, 0,
181058 141, 0, 0, 119, 52, 0, 0, 137, 12, 0, 0, 62, 0,
181059 138, 0, 133, 0, 0, 36, 0, 0, 28, 77, 0, 0, 0,
181060 0, 59, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0,
181061 0, 69, 0, 0, 0, 0, 0, 146, 3, 0, 58, 0, 1,
181062 75, 0, 0, 0, 31, 0, 0, 0, 0, 0, 127, 0, 104,
181063 0, 64, 66, 63, 0, 0, 0, 0, 0, 46, 0, 16, 8,
181064 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 81, 101, 0,
181065 112, 21, 7, 67, 0, 79, 96, 118, 0, 0, 68, 0, 0,
181066 99, 44, 0, 55, 0, 76, 0, 95, 32, 33, 57, 25, 0,
181067 102, 0, 0, 87,
181070 static const unsigned char aKWLen[148] = {0,
181086 static const unsigned short int aKWOffset[148] = {0,
181087 0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
181101 static const unsigned char aKWCode[148] = {0,
181134 ** 0: INSERT
181262 /* Check to see if z[0..n-1] is a keyword. If it is, write the
181269 i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n*1) % 127;
181270 for(i=(int)aKWHash[i]; i>0; i=aKWNext[i]){
181274 if( (z[0]&~0x20)!=zKW[0] ) continue;
181275 if( (z[1]&~0x20)!=zKW[1] ) continue;
181277 while( j<n && (z[j]&~0x20)==zKW[j] ){ j++; }
181280 if( toupper(z[0])!=zKW[0] ) continue;
181445 if( i<0 || i>=SQLITE_N_KEYWORD ) return SQLITE_ERROR;
181477 #define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
181482 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 4x */
181483 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, /* 5x */
181484 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, /* 6x */
181485 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, /* 7x */
181486 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, /* 8x */
181487 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, /* 9x */
181488 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, /* Ax */
181489 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */
181490 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Cx */
181491 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Dx */
181492 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Ex */
181493 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* Fx */
181495 #define IdChar(C) (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))
181579 ** Return the length (in bytes) of the token that begins at z[0].
181588 testcase( z[0]==' ' );
181589 testcase( z[0]=='\t' );
181590 testcase( z[0]=='\n' );
181591 testcase( z[0]=='\f' );
181592 testcase( z[0]=='\r' );
181599 for(i=2; (c=z[i])!=0 && c!='\n'; i++){}
181630 if( z[1]!='*' || z[2]==0 ){
181634 for(i=3, c=z[2]; (c!='*' || z[i]!='/') && (c=z[i])!=0; i++){}
181705 int delim = z[0];
181709 for(i=1; (c=z[i])!=0; i++){
181721 }else if( c!=0 ){
181742 testcase( z[0]=='0' ); testcase( z[0]=='1' ); testcase( z[0]=='2' );
181743 testcase( z[0]=='3' ); testcase( z[0]=='4' ); testcase( z[0]=='5' );
181744 testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' );
181745 testcase( z[0]=='9' ); testcase( z[0]=='.' );
181748 if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){
181750 if( sqlite3Isxdigit(z[i])==0 ){
181761 for(i=0; 1; i++){
181762 if( sqlite3Isdigit(z[i])==0 ){
181774 if( sqlite3Isdigit(z[i])==0 ){
181790 if( sqlite3Isdigit(z[i])==0 ){
181808 for(i=1, c=z[0]; c!=']' && (c=z[i])!=0; i++){}
181819 int n = 0;
181820 testcase( z[0]=='$' ); testcase( z[0]=='@' );
181821 testcase( z[0]==':' ); testcase( z[0]=='#' );
181823 for(i=1; (c=z[i])!=0; i++){
181827 }else if( c=='(' && n>0 ){
181830 }while( (c=z[i])!=0 && !sqlite3Isspace(c) && c!=')' );
181844 if( n==0 ) *tokenType = TK_ILLEGAL;
181862 testcase( z[0]=='x' ); testcase( z[0]=='X' );
181884 if( z[1]==0xbb && z[2]==0xbf ){
181893 return 0;
181909 int nErr = 0; /* Number of errors encountered */
181911 int n = 0; /* Length of the next token token */
181916 Parse *pParentParse = 0; /* Outer parse context, if any */
181922 assert( zSql!=0 );
181924 if( db->nVdbeActive==0 ){
181925 AtomicStore(&db->u1.isInterrupted, 0);
181934 sqlite3ParserTrace(0, 0);
181942 if( pEngine==0 ){
181947 assert( pParse->pNewTable==0 );
181948 assert( pParse->pNewTrigger==0 );
181949 assert( pParse->nVar==0 );
181950 assert( pParse->pVList==0 );
181956 if( mxSqlLen<0 ){
181982 if( zSql[0]==0 ){
181984 ** with tokens TK_SEMI and 0, in that order. */
181986 tokenType = 0;
181987 }else if( lastTokenParsed==0 ){
181992 n = 0;
182005 && (db->init.busy || (db->flags & SQLITE_Comments)!=0)
182024 assert( db->mallocFailed==0 || pParse->rc!=SQLITE_OK || startedWithOom );
182027 assert( nErr==0 );
182044 if( pParse->zErrMsg==0 ){
182047 if( (pParse->prepFlags & SQLITE_PREPARE_DONT_LOG)==0 ){
182069 assert( nErr==0 || pParse->rc!=SQLITE_OK );
182086 ** Compute a normalization of the SQL given by zSql[0..nSql-1]. Return
182098 int prevType = 0; /* Previous non-whitespace token */
182107 nParen = iStartIN = nParenAtIN = 0;
182109 assert( pStr!=0 ); /* sqlite3_str_new() never returns NULL */
182110 for(i=0; zSql[i] && pStr->accError==0; i+=n){
182115 if( NEVER(n<=0) ) break;
182146 if( iStartIN>0 && nParen==nParenAtIN ){
182150 iStartIN = 0;
182157 iStartIN = 0;
182162 int eType = 0;
182163 if( zId==0 ) break;
182189 iStartIN = 0;
182237 #define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
182241 #define IdChar(C) (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))
182250 #define tkSEMI 0
182270 ** (0) INVALID We have not yet seen a non-whitespace character.
182273 ** returns 1 if it ends in the START state and 0 if it ends
182298 ** (0) tkSEMI A semicolon.
182315 u8 state = 0; /* Current state, using numbers defined in header comment */
182325 /* 0 INVALID: */ { 1, 0, 2, 3, 4, 2, 2, 2, },
182341 /* 0 INVALID: */ { 1, 0, 2, },
182348 if( zSql==0 ){
182350 return 0;
182374 while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
182375 if( zSql[0]==0 ) return 0;
182386 if( *zSql==0 ) return state==1;
182393 if( *zSql==0 ) return 0;
182403 if( *zSql==0 ) return 0;
182420 if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
182428 if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
182430 }else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
182432 }else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
182440 if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
182444 if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
182488 pVal = sqlite3ValueNew(0);
182497 return rc & 0xff;
182542 #if 0
182548 #if 0
182579 #if 0
182585 #if 0
182612 #if 0
182618 #if 0
182715 ** the SQLITE_THREADSAFE compile-time option being set to 0.
182726 # define SQLITE_DEBUG_OS_TRACE 0
182738 SQLITE_API void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...) = 0;
182748 SQLITE_API char *sqlite3_temp_directory = 0;
182757 SQLITE_API char *sqlite3_data_directory = 0;
182794 int bRunExtraInit = 0; /* Extra initialization needed */
182878 if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){
182886 memset(&sqlite3BuiltinFunctions, 0, sizeof(sqlite3BuiltinFunctions));
182888 if( sqlite3GlobalConfig.isPCacheInit==0 ){
182906 rc = SQLITE_EXTRA_INIT_MUTEXED(0);
182917 sqlite3GlobalConfig.inProgress = 0;
182926 if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
182927 assert( sqlite3GlobalConfig.nRefInitMutex==0 );
182929 sqlite3GlobalConfig.pInitMutex = 0;
182958 rc = SQLITE_EXTRA_INIT(0);
182987 sqlite3GlobalConfig.isInit = 0;
182991 sqlite3GlobalConfig.isPCacheInit = 0;
182995 sqlite3GlobalConfig.isMallocInit = 0;
183005 sqlite3_data_directory = 0;
183006 sqlite3_temp_directory = 0;
183011 sqlite3GlobalConfig.isMutexInit = 0;
183035 static const u64 mAnytimeConfigOption = 0
183039 if( op<0 || op>63 || (MASKBIT64(op) & mAnytimeConfigOption)==0 ){
183052 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
183056 sqlite3GlobalConfig.bCoreMutex = 0; /* Disable mutex on core */
183057 sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
183061 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
183066 sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
183070 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
183079 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
183086 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */
183108 if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
183169 if( sqlite3GlobalConfig.pcache2.xInit==0 ){
183196 if( sqlite3GlobalConfig.pHeap==0 ){
183205 memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
183247 ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
183292 if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
183295 if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
183325 if( iVal<0 ){
183343 if( 0==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = TF_NoVisibleRowid;
183344 if( 1==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = 0;
183345 *pVal = (sqlite3GlobalConfig.mNoVisibleRowid==0);
183347 *pVal = 0;
183384 if( sqlite3LookasideUsed(db,0)>0 ){
183398 if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;
183401 ** more than 0x7fff0000 total bytes for lookaside. */
183402 if( cnt<1 ) cnt = 0;
183403 if( sz>0 && cnt>(0x7fff0000/sz) ) cnt = 0x7fff0000/sz;
183405 if( szAlloc==0 ){
183406 sz = 0;
183407 pStart = 0;
183408 }else if( pBuf==0 ){
183425 if( sz>0 ){
183427 nSm = 0;
183429 nBig = nSm = 0;
183432 db->lookaside.pInit = 0;
183433 db->lookaside.pFree = 0;
183441 for(i=0; i<nBig; i++){
183447 db->lookaside.pSmallInit = 0;
183448 db->lookaside.pSmallFree = 0;
183450 for(i=0; i<nSm; i++){
183458 db->lookaside.bDisable = 0;
183459 db->lookaside.bMalloced = pBuf==0 ?1:0;
183462 db->lookaside.pStart = 0;
183464 db->lookaside.pSmallInit = 0;
183465 db->lookaside.pSmallFree = 0;
183466 db->lookaside.pMiddle = 0;
183468 db->lookaside.pEnd = 0;
183470 db->lookaside.sz = 0;
183471 db->lookaside.bMalloced = 0;
183472 db->lookaside.nSlot = 0;
183475 assert( sqlite3LookasideUsed(db,0)==0 );
183487 return 0;
183505 for(i=0; i<db->nDb; i++){
183524 int bSeenBusy = 0;
183531 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
183563 db->aDb[0].zDbSName = va_arg(ap,char*);
183604 for(i=0; i<ArraySize(aFlagOp); i++){
183609 if( onoff>0 ){
183611 }else if( onoff==0 ){
183615 sqlite3ExpirePreparedStatements(db, 0);
183618 *pRes = (db->flags & aFlagOp[i].mask)!=0;
183649 if( rc==0 ){
183675 assert( p==0 || p->xCmp!=binCollFunc || strcmp(p->zName,"BINARY")==0 );
183676 return p==0 || p->xCmp==binCollFunc;
183696 if( 0==r ){
183709 return 0;
183737 return 0;
183753 return 0;
183773 db->nSavepoint = 0;
183774 db->nStatement = 0;
183775 db->isTransactionSavepoint = 0;
183786 assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
183790 if( pDestructor->nRef==0 ){
183806 for(i=0; i<db->nDb; i++){
183836 for(j=0; j<db->nDb; j++){
183840 return 0;
183857 db->trace.xV2(SQLITE_TRACE_CLOSE, db->pTraceArg, db, 0);
183885 sqlite3GlobalConfig.xSqllog(sqlite3GlobalConfig.pSqllogArg, db, 0, 2);
183892 assert( p->pData!=0 );
183920 if( iDb<0 ) nDb--;
183922 iDb = 0;
183927 int x = pBt!=0 ? sqlite3BtreeTxnState(pBt) : SQLITE_TXN_NONE;
183943 SQLITE_API int sqlite3_close(sqlite3 *db){ return sqlite3Close(db,0); }
183984 for(j=0; j<db->nDb; j++){
183988 pDb->pBt = 0;
183990 pDb->pSchema = 0;
184024 for(j=0; j<3; j++){
184060 assert( sqlite3LookasideUsed(db,0)==0 );
184076 int inTrans = 0;
184088 schemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0 && db->init.busy==0;
184090 for(i=0; i<db->nDb; i++){
184103 sqlite3ExpirePreparedStatements(db, 0);
184109 db->nDeferredCons = 0;
184110 db->nDeferredImmCons = 0;
184125 const char *zName = 0;
184127 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
184223 if( zName==0 ){
184240 /* SQLITE_INTERNAL */ 0,
184254 /* SQLITE_EMPTY */ 0,
184263 /* SQLITE_NOLFS */ 0,
184266 /* SQLITE_FORMAT */ 0,
184287 rc &= 0xff;
184288 if( ALWAYS(rc>=0) && rc<ArraySize(aMsg) && aMsg[rc]!=0 ){
184316 { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
184322 assert( count>=0 );
184332 if( delay<=0 ) return 0;
184342 return 0;
184356 ** returns 0, the operation aborts with an SQLITE_BUSY error.
184360 if( p->xBusyHandler==0 || p->nBusy<0 ) return 0;
184362 if( rc==0 ){
184385 db->busyHandler.nBusy = 0;
184386 db->busyTimeout = 0;
184388 db->setlkTimeout = 0;
184413 if( nOps>0 ){
184418 db->xProgress = 0;
184419 db->nProgressOps = 0;
184420 db->pProgressArg = 0;
184429 ** specified number of milliseconds before returning 0.
184435 if( ms>0 ){
184443 sqlite3_busy_handler(db, 0, 0);
184454 int bBOC = ((flags & SQLITE_SETLK_BLOCK_ON_CONNECT) ? 1 : 0);
184465 for(iDb=0; iDb<db->nDb; iDb++){
184488 && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE)
184504 && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE)
184507 return 0;
184510 return AtomicLoad(&db->u1.isInterrupted)!=0;
184536 assert( xValue==0 || xSFunc==0 );
184537 if( zFunctionName==0 /* Must have a valid name */
184538 || (xSFunc!=0 && xFinal!=0) /* Not both xSFunc and xFinal */
184539 || ((xFinal==0)!=(xStep==0)) /* Both or neither of xFinal and xStep */
184540 || ((xValue==0)!=(xInverse==0)) /* Both or neither of xValue, xInverse */
184605 p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 0);
184613 sqlite3ExpirePreparedStatements(db, 0);
184615 }else if( xSFunc==0 && xFinal==0 ){
184668 FuncDestructor *pArg = 0;
184683 pArg->nRef = 0;
184690 if( pArg && pArg->nRef==0 ){
184691 assert( rc!=SQLITE_OK || (xStep==0 && xFinal==0) );
184716 xFinal, 0, 0, 0);
184730 xFinal, 0, 0, xDestroy);
184744 return createFunctionApi(db, zFunc, nArg, enc, p, 0, xStep,
184763 if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT;
184768 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xSFunc,xStep,xFinal,0,0,0);
184820 if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){
184825 rc = sqlite3FindFunction(db, zName, nArg, SQLITE_UTF8, 0)!=0;
184829 if( zCopy==0 ) return SQLITE_NOMEM;
184831 zCopy, sqlite3InvalidFunction, 0, 0, sqlite3_free);
184850 return 0;
184855 db->mTrace = xTrace ? SQLITE_TRACE_LEGACY : 0;
184877 if( mTrace==0 ) xTrace = 0;
184878 if( xTrace==0 ) mTrace = 0;
184905 return 0;
184935 return 0;
184960 return 0;
184985 return 0;
185010 if( db==0 ){
185011 return 0;
185092 if( nFrame>0 ){
185095 sqlite3_wal_hook(db, 0, 0);
185115 return 0;
185125 return 0;
185153 assert( SQLITE_CHECKPOINT_PASSIVE==0 );
185164 if( zDb && zDb[0] ){
185169 if( iDb<0 ){
185173 db->busyHandler.nBusy = 0;
185181 if( db->nVdbeActive==0 ){
185182 AtomicStore(&db->u1.isInterrupted, 0);
185198 ** sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). */
185199 return sqlite3_wal_checkpoint_v2(db,zDb,SQLITE_CHECKPOINT_PASSIVE,0,0);
185226 int bBusy = 0; /* True if SQLITE_BUSY has been encountered */
185234 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
185237 pnLog = 0;
185238 pnCkpt = 0;
185260 ** 0 any file (return 0)
185261 ** 1 1 file (return 0)
185263 ** 1 0 file (return 0)
185264 ** 2 1 file (return 0)
185266 ** 2 0 memory (return 1)
185282 return 0;
185302 testcase( db->pErr==0 );
185303 z = db->errCode ? (char*)sqlite3_value_text(db->pErr) : 0;
185305 if( z==0 ){
185333 'o', 'u', 't', ' ', 'o', 'f', ' ', 'm', 'e', 'm', 'o', 'r', 'y', 0
185338 'm', 'i', 's', 'u', 's', 'e', 0
185353 if( z==0 ){
185392 return db ? db->iSysErrno : 0;
185439 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
185446 sqlite3ExpirePreparedStatements(db, 0);
185457 for(j=0; j<3; j++){
185463 p->xCmp = 0;
185470 if( pColl==0 ) return SQLITE_NOMEM_BKPT;
185518 #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>32767
185519 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 32767
185521 #if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>125
185522 # error SQLITE_MAX_ATTACHED must be between 0 and 125
185533 #if SQLITE_MAX_WORKER_THREADS<0 || SQLITE_MAX_WORKER_THREADS>50
185534 # error SQLITE_MAX_WORKER_THREADS must be between 0 and 50
185579 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
185583 if( newLimit>=0 ){ /* IMP: R-52476-28732 */
185635 assert( *pzErrMsg==0 );
185639 && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
185644 int iOut = 0; /* Output character index */
185651 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
185655 memset(zFile, 0, 4); /* 4-byte of 0x00 is the start of DB name marker */
185660 if( strncmp(zUri+5, "///", 3)==0 ){
185667 if( strncmp(zUri+7, "///", 3)==0 ){ iIn++; }
185668 }else if( strncmp(zUri+5, "//localhost/", 12)==0 ){
185688 ** Within this loop, variable eState may be set to 0, 1 or 2, depending
185691 ** 0: Parsing file-name.
185695 eState = 0;
185696 while( (c = zUri[iIn])!=0 && c!='#' ){
185705 assert( octet>=0 && octet<256 );
185706 if( octet==0 ){
185712 while( (c = zUri[iIn])!=0 && c!='#'
185713 && (eState!=0 || c!='?')
185729 if( zFile[iOut-1]==0 ){
185735 zFile[iOut++] = '\0';
185739 c = 0;
185740 }else if( (eState==0 && c=='?') || (eState==2 && c=='&') ){
185741 c = 0;
185746 if( eState==1 ) zFile[iOut++] = '\0';
185747 memset(zFile+iOut, 0, 4); /* end-of-options + empty journal filenames */
185754 while( zOpt[0] ){
185759 if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
185765 } *aMode = 0;
185766 char *zModeType = 0;
185767 int mask = 0;
185768 int limit = 0;
185770 if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
185774 { 0, 0 }
185782 if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
185788 { 0, 0 }
185800 int mode = 0;
185801 for(i=0; aMode[i].z; i++){
185803 if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){
185808 if( mode==0 ){
185829 memset(zFile, 0, 4);
185834 memset(zFile+nUri, 0, 4);
185839 if( *ppVfs==0 ){
185846 zFile = 0;
185859 while( ALWAYS(zFilename!=0) && zFilename[0] ){
185862 if( x==0 ) return zFilename;
185865 return 0;
185884 char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
185885 char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
185889 if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
185891 *ppDb = 0;
185897 if( sqlite3GlobalConfig.bCoreMutex==0 ){
185898 isThreadsafe = 0;
185900 isThreadsafe = 0;
185938 if( db==0 ) goto opendb_out;
185945 if( db->mutex==0 ){
185947 db = 0;
185950 if( isThreadsafe==0 ){
185955 db->errMask = (flags & SQLITE_OPEN_EXRESCODE)!=0 ? 0xffffffff : 0xff;
185960 db->lookaside.sz = 0;
185968 db->nextPagesize = 0;
185971 /* Beginning with version 3.37.0, using the VFS xFetch() API to memory-map
185976 db->nMaxSorterMmap = 0x7FFFFFFF;
185985 #if !defined(SQLITE_TRUSTED_SCHEMA) || SQLITE_TRUSTED_SCHEMA+0!=0
185997 ** 0 off off
186001 ** -DSQLITE_DQS=0 (best) or -DSQLITE_DQS=1 (second choice) if possible.
186065 createCollation(db, sqlite3StrBINARY, SQLITE_UTF8, 0, binCollFunc, 0);
186066 createCollation(db, sqlite3StrBINARY, SQLITE_UTF16BE, 0, binCollFunc, 0);
186067 createCollation(db, sqlite3StrBINARY, SQLITE_UTF16LE, 0, binCollFunc, 0);
186068 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
186069 createCollation(db, "RTRIM", SQLITE_UTF8, 0, rtrimCollFunc, 0);
186076 if( zFilename && zFilename[0]==':' ){
186077 if( strcmp(zFilename, ":localStorage:")==0 ){
186080 }else if( strcmp(zFilename, ":sessionStorage:")==0 ){
186100 assert( SQLITE_OPEN_READONLY == 0x01 );
186101 assert( SQLITE_OPEN_READWRITE == 0x02 );
186102 assert( SQLITE_OPEN_CREATE == 0x04 );
186103 testcase( (1<<(flags&7))==0x02 ); /* READONLY */
186104 testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
186105 testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
186106 if( ((1<<(flags&7)) & 0x46)==0 ){
186109 if( zFilename==0 ) zFilename = ":memory:";
186114 sqlite3ErrorWithMsg(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
186118 assert( db->pVfs!=0 );
186120 if( sqlite3_stricmp(db->pVfs->zName, "kvvfs")==0 ){
186126 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
186135 sqlite3BtreeEnter(db->aDb[0].pBt);
186136 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
186140 sqlite3BtreeLeave(db->aDb[0].pBt);
186141 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
186146 db->aDb[0].zDbSName = "main";
186147 db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
186166 for(i=0; rc==SQLITE_OK && i<ArraySize(sqlite3BuiltinExtensions); i++){
186189 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
186194 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
186201 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
186208 assert( db->mutex!=0 || isThreadsafe==0
186209 || sqlite3GlobalConfig.bFullMutex==0 );
186213 assert( db!=0 || (rc&0xff)==SQLITE_NOMEM );
186214 if( (rc&0xff)==SQLITE_NOMEM ){
186216 db = 0;
186223 /* Opening a db handle. Fourth parameter is passed 0. */
186225 sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
186241 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
186265 if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
186267 *ppDb = 0;
186272 if( zFilename==0 ) zFilename = "\000\000";
186273 pVal = sqlite3ValueNew(0);
186278 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
186280 if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
186288 return rc & 0xff;
186302 return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0);
186319 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
186344 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
186350 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
186373 db->xCollNeeded16 = 0;
186393 db->xCollNeeded = 0;
186408 if( strcmp(p->zName, zName)==0 ){
186415 return 0;
186434 assert( p->pData!=0 );
186436 if( pData==0 ){
186442 }else if( pData==0 ){
186448 if( p==0 ){
186484 return 0;
186507 testcase( sqlite3GlobalConfig.xLog!=0 );
186511 testcase( sqlite3GlobalConfig.xLog!=0 );
186515 testcase( sqlite3GlobalConfig.xLog!=0 );
186522 testcase( sqlite3GlobalConfig.xLog!=0 );
186528 testcase( sqlite3GlobalConfig.xLog!=0 );
186532 testcase( sqlite3GlobalConfig.xLog!=0 );
186565 char *zErrMsg = 0;
186566 Table *pTab = 0;
186567 Column *pCol = 0;
186568 int iCol = 0;
186569 char const *zDataType = 0;
186570 char const *zCollSeq = 0;
186571 int notnull = 0;
186572 int primarykey = 0;
186573 int autoinc = 0;
186577 if( !sqlite3SafetyCheckOk(db) || zTableName==0 ){
186593 pTab = 0;
186598 if( zColumnName==0 ){
186602 if( iCol>=0 ){
186607 pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
186609 pTab = 0;
186626 zDataType = sqlite3ColumnType(pCol,0);
186628 notnull = pCol->notNull!=0;
186629 primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
186630 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
186658 sqlite3ErrorWithMsg(db, rc, (zErrMsg?"%s":0), zErrMsg);
186671 pVfs = sqlite3_vfs_find(0);
186672 if( pVfs==0 ) return 0;
186677 rc = (sqlite3OsSleep(pVfs, ms<0 ? 0 : 1000*ms)/1000);
186689 db->errMask = onoff ? 0xffffffff : 0xff;
186711 assert( pPager!=0 );
186713 assert( fd!=0 );
186729 if( iNew>=0 && iNew<=255 ){
186730 sqlite3BtreeSetPageSize(pBtree, 0, iNew, 0);
186751 int rc = 0;
186782 ** x!=0 && db!=0 Seed the PRNG to the current value of the
186789 ** x!=0 && db==0 Seed the PRNG to the value of x.
186791 ** x==0 && db==0 Revert to default behavior of using the
186802 assert( db==0 || db->aDb[0].pSchema!=0 );
186803 if( db && (y = db->aDb[0].pSchema->schema_cookie)!=0 ){ x = y; }
186805 sqlite3_randomness(0,0);
186837 ** memory allocation error, 0 on success, or non-zero for an error.
186853 ** As a test of the fault simulator mechanism itself, sqlite3FaultSim(0)
186855 ** value from sqlite3FaultSim(0) becomes the return from
186869 rc = sqlite3FaultSim(0);
186892 ** Set the PENDING byte to the value in the argument, if X>0.
186893 ** Make no changes if X==0. Return the value of the pending byte
186896 ** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
186924 volatile int x = 0;
186925 assert( /*side-effects-ok*/ (x = va_arg(ap,int))!=0 );
186931 sqlite3ShowExpr(0);
186932 sqlite3ShowExprList(0);
186933 sqlite3ShowIdList(0);
186934 sqlite3ShowSrcList(0);
186935 sqlite3ShowWith(0);
186936 sqlite3ShowUpsert(0);
186938 sqlite3ShowTriggerStep(0);
186939 sqlite3ShowTriggerStepList(0);
186940 sqlite3ShowTrigger(0);
186941 sqlite3ShowTriggerList(0);
186944 sqlite3ShowWindow(0);
186945 sqlite3ShowWinFunc(0);
186947 sqlite3ShowSelect(0);
186960 ** The return value is ALWAYS(X) if X is true, or 0 if X is false.
186978 ** // ALWAYS(x) is a constant 1. NEVER(x) is a constant 0.
186983 rc = x ? ALWAYS(x) : 0;
187007 ** operation N should be 0. The idea is that a test program (like the
187033 ** If 2, then invoke xAlt() instead of localtime(). If 0, normal
187049 sqlite3GlobalConfig.xAltLocaltime = 0;
187096 ** By default this is 0x7ffffffe (over 2 billion), but that value is
187133 if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
187149 ** If onOff==0 and tnum>0 then reset the schema for all databases, causing
187158 if( iDb>=0 ){
187162 if( db->init.busy==0 && db->init.newTnum>0 ){
187223 ** op==0 Store the current sqlite3TreeTrace in *ptr
187232 case 0: *ptr = sqlite3TreeTrace; break;
187280 if( id>0 && id<=SQLITE_NTUNE ){
187282 }else if( id<0 && id>=-SQLITE_NTUNE ){
187304 if( *pOnOff<0 ){
187307 sqlite3Config.bJsonSelfcheck = (u8)((*pOnOff)&0xff);
187327 while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){
187363 for(i=0; i<nParam*2; i++){
187367 if( p==0 ) return 0;
187368 memset(p, 0, 4);
187371 for(i=0; i<nParam*2; i++){
187374 *(p++) = 0;
187377 *(p++) = 0;
187378 *(p++) = 0;
187389 if( p==0 ) return;
187407 if( zFilename==0 || zParam==0 ) return 0;
187416 if( zFilename==0 || N<0 ) return 0;
187419 while( ALWAYS(zFilename) && zFilename[0] && (N--)>0 ){
187423 return zFilename[0] ? zFilename : 0;
187431 bDflt = bDflt!=0;
187445 if( z && sqlite3DecOrHexToI64(z, &v)==0 ){
187462 if( zFilename==0 ) return 0;
187466 if( zFilename==0 ) return 0;
187469 while( ALWAYS(zFilename) && zFilename[0] ){
187477 return 0;
187489 int iDb = zDbName ? sqlite3FindDbName(db, zDbName) : 0;
187490 return iDb<0 ? 0 : db->aDb[iDb].pBt;
187501 return 0;
187504 if( N<0 || N>=db->nDb ){
187505 return 0;
187520 return 0;
187524 return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
187528 ** Return 1 if database is read-only or 0 if read/write. Return -1 if
187563 if( db->autoCommit==0 ){
187565 if( iDb==0 || iDb>1 ){
187569 i64 dummy = 0;
187571 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
187572 sqlite3PagerSnapshotOpen(pPager, 0);
187602 if( db->autoCommit==0 ){
187605 if( iDb==0 || iDb>1 ){
187609 int bUnlock = 0;
187611 if( db->nVdbeActive==0 ){
187625 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
187626 sqlite3PagerSnapshotOpen(pPager, 0);
187657 if( iDb==0 || iDb>1 ){
187660 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
187694 if( zOptName==0 ){
187696 return 0;
187702 if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
187707 for(i=0; i<nOpt; i++){
187708 if( sqlite3StrNICmp(zOptName, azCompileOpt[i], n)==0
187709 && sqlite3IsIdChar((unsigned char)azCompileOpt[i][n])==0
187714 return 0;
187725 if( N>=0 && N<nOpt ){
187728 return 0;
187773 static sqlite3 *SQLITE_WSD sqlite3BlockedList = 0;
187793 int seen = 0;
187803 assert( db==0 || p->pUnlockConnection!=db );
187804 assert( db==0 || p->pBlockingConnection!=db );
187848 checkListProperties(0);
187856 checkListProperties(0);
187878 ** on the same "db". If xNotify==0 then any prior callbacks are immediately
187894 if( xNotify==0 ){
187896 db->pBlockingConnection = 0;
187897 db->pUnlockConnection = 0;
187898 db->xUnlockNotify = 0;
187899 db->pUnlockArg = 0;
187900 }else if( 0==db->pBlockingConnection ){
187923 sqlite3ErrorWithMsg(db, rc, (rc?"database is deadlocked":0));
187936 if( db->pBlockingConnection==0 && db->pUnlockConnection==0 ){
187952 ** set to db, then set pBlockingConnection=0.
187956 ** set pUnlockConnection=0.
187958 ** 3) If the two steps above mean that pBlockingConnection==0 and
187959 ** pUnlockConnection==0, remove the entry from the blocked connections
187963 void (*xUnlockNotify)(void **, int) = 0; /* Unlock-notify cb to invoke */
187964 int nArg = 0; /* Number of entries in aArg[] */
187967 void **aDyn = 0; /* Dynamically allocated space for aArg[] */
187979 p->pBlockingConnection = 0;
187985 if( p->xUnlockNotify!=xUnlockNotify && nArg!=0 ){
187987 nArg = 0;
187991 assert( aArg==aDyn || (aDyn==0 && aArg==aStatic) );
188028 nArg = 0;
188035 p->pUnlockConnection = 0;
188036 p->xUnlockNotify = 0;
188037 p->pUnlockArg = 0;
188041 if( p->pBlockingConnection==0 && p->pUnlockConnection==0 ){
188044 p->pNextBlocked = 0;
188050 if( nArg!=0 ){
188111 ** A = 0xxxxxxx 7 bits of data and one flag bit
188126 ** 1: 0x01
188127 ** 127: 0x7f
188128 ** 128: 0x81 0x00
188136 ** word of the document has a position of 0.
188145 ** array { (position list for column 0)
188162 ** ending a position list array. POS_END is 0. POS_COLUMN is 1.
188168 ** value: 123 5 9 1 1 14 35 0 234 72 0
188174 ** (14-2 and 35-2+12). The 0 at H indicate the end-of-document. The
188176 ** (72-2) and then terminates with the 0 at K.
188194 ** varint iHeight; (height from leaf level, always 0)
188240 ** varint iHeight; (height from leaf level, always >0)
188298 ** leaves_end_block, and end_block are all 0.
188307 ** written individually (using LeafWriter) to a level 0 segment, with
188309 ** level 0 segments are merged into a single level 1 segment. Level 1
188310 ** is populated like level 0, and eventually MERGE_COUNT level 1
188471 ** Structure version. Should always be set to 0 or 1.
188486 ** This method should return either SQLITE_OK (0), or an SQLite error
188733 #define SizeofArray(X) ((int)(sizeof(X)/sizeof(X[0])))
188759 ** level values between 0 and 1023 (inclusive) belong to index 0, all levels
188781 #define POS_END (0) /* Position-list terminator */
188810 # define NEVER(X) (0)
188812 # define ALWAYS(X) ((X)?1:(assert(0),0))
188813 # define NEVER(X) ((X)?(assert(0),1):0)
188851 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
188860 # define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
188941 ** there is an entry in the aIndex[] array. Index 0 is an index of all the
188953 int nPrefix; /* Prefix length (0 for main terms index) */
189019 #define FTS3_EVAL_FILTER 0
189033 ** Fts3Cursor.eSearch will be set to FTS3_FULLTEXT_SEARCH+1. (+0 for a,
189038 #define FTS3_FULLSCAN_SEARCH 0 /* Linear scan of %_content table */
189048 #define FTS3_HAVE_LANGID 0x00010000 /* languageid=? */
189049 #define FTS3_HAVE_DOCID_GE 0x00020000 /* docid>=? */
189050 #define FTS3_HAVE_DOCID_LE 0x00040000 /* docid<=? */
189057 sqlite3_int64 iDocid; /* Current docid (if pList!=0) */
189073 int bFirst; /* True if token must appear at position 0 */
189119 ** aMI[iCol*3 + 0] = Undefined
189208 #define FTS3_SEGMENT_REQUIRE_POS 0x00000001
189209 #define FTS3_SEGMENT_IGNORE_EMPTY 0x00000002
189210 #define FTS3_SEGMENT_COLUMN_FILTER 0x00000004
189211 #define FTS3_SEGMENT_PREFIX 0x00000008
189212 #define FTS3_SEGMENT_SCAN 0x00000010
189213 #define FTS3_SEGMENT_FIRST 0x00000020
189232 int iColFilter; /* If >=0, filter for this column */
189249 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
189367 ** Write a 64-bit variable-length integer to memory starting at p[0].
189375 *q++ = (unsigned char) ((vu & 0x7f) | 0x80);
189377 }while( vu!=0 );
189378 q[-1] &= 0x7f; /* turn off high bit in final byte */
189385 if( (v & mask2)==0 ){ var = v; return ret; }
189388 if( (v & mask2)==0 ){ var = v; return ret; }
189397 GETVARINT_INIT(a, p, 0, 0x00, 0x80, *v, 1);
189398 GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *v, 2);
189399 GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *v, 3);
189400 GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *v, 4);
189401 b = (a & 0x0FFFFFFF );
189405 b += (c&0x7F) << shift;
189406 if( (c & 0x80)==0 ) break;
189413 ** Read a 64-bit variable-length integer from memory starting at p[0].
189414 ** Return the number of bytes read, or 0 on error.
189422 ** Read a 64-bit variable-length integer from memory starting at p[0] and
189424 ** Return the number of bytes read, or 0 on error.
189435 u64 b = 0;
189437 for(shift=0; shift<=63; shift+=7){
189438 u64 c = p<pX ? *p : 0;
189440 b += (c&0x7F) << shift;
189441 if( (c & 0x80)==0 ) break;
189456 GETVARINT_INIT(a, ptr, 0, 0x00, 0x80, *pi, 1);
189459 assert( a & 0x80 );
189462 GETVARINT_STEP(a, ptr, 7, 0x7F, 0x4000, *pi, 2);
189463 GETVARINT_STEP(a, ptr, 14, 0x3FFF, 0x200000, *pi, 3);
189464 GETVARINT_STEP(a, ptr, 21, 0x1FFFFF, 0x10000000, *pi, 4);
189465 a = (a & 0x0FFFFFFF );
189466 *pi = (int)(a | ((u32)(*ptr & 0x07) << 28));
189467 assert( 0==(a & 0x80000000) );
189468 assert( *pi>=0 );
189476 int i = 0;
189480 }while( v!=0 );
189501 quote = z[0];
189504 int iOut = 0; /* Index of next byte to write to output */
189518 z[iOut] = '\0';
189551 ** interested in. So, unless the doclist is corrupt, the 0x80 bit is
189553 for(p = (*pp)-2; p>=pStart && *p&0x80; p--);
189568 assert( p->nPendingData==0 );
189569 assert( p->pSegments==0 );
189573 for(i=0; i<SizeofArray(p->aStmt); i++){
189619 if( zSql==0 ){
189622 *pRc = sqlite3_exec(db, zSql, 0, 0, 0);
189680 zCols = sqlite3_mprintf("%Q, ", p->azColumn[0]);
189728 if( p->zContentTbl==0 ){
189734 for(i=0; zContentCols && i<p->nColumn; i++){
189741 if( zContentCols==0 ) rc = SQLITE_NOMEM;
189798 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
189801 p->nPgsz = sqlite3_column_int(pStmt, 0);
189808 assert( p->nPgsz>0 || rc!=SQLITE_OK );
189831 if( *zCsr=='\0' ) return 0;
189864 if( z==0 ) *pRc = SQLITE_NOMEM;
189889 for(i=0; zInput[i]; i++){
189894 *(z++) = '\0';
189923 char *zRet = 0;
189924 char *zFree = 0;
189928 if( p->zContentTbl==0 ){
189935 for(i=0; i<p->nColumn; i++){
189944 for(i=0; i<p->nColumn; i++){
189980 char *zRet = 0;
189981 char *zFree = 0;
189991 for(i=0; i<p->nColumn; i++){
190007 u64 iVal = 0;
190009 for(i=0; z[i]>='0' && z[i]<='9'; i++){
190010 iVal = iVal*10 + (z[i] - '0');
190011 if( iVal>0x7FFFFFFF ) return -1;
190023 ** Only decimal digits ('0'..'9') may be part of an integer value.
190032 int nInt = 0; /* Output value */
190036 nInt = 0;
190038 if( nByte==0 ){
190071 if( zParam && zParam[0] ){
190085 memset(aIndex, 0, sizeof(struct Fts3Index) * nIndex);
190090 int nPrefix = 0;
190092 assert( nPrefix>=0 );
190093 if( nPrefix==0 ){
190143 sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */
190149 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
190158 sqlite3_int64 nStr = 0; /* Size of all column names (incl. 0x00) */
190166 for(i=0; i<nCol; i++){
190173 if( azCol==0 ){
190177 for(i=0; i<nCol; i++){
190202 ** argv[0] -> module name ("fts3" or "fts4")
190217 Fts3Table *p = 0; /* Pointer to allocated vtab */
190222 int nString = 0; /* Bytes required to hold all column names */
190223 int nCol = 0; /* Number of columns in the FTS table */
190227 int isFts4 = (argv[0][3]=='4'); /* True for FTS4, false for FTS3 */
190229 sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */
190231 int nIndex = 0; /* Size of aIndex[] array */
190232 struct Fts3Index *aIndex = 0; /* Array of indexes for this table */
190235 int bNoDocsize = 0; /* True to omit %_docsize table */
190236 int bDescIdx = 0; /* True to store descending indexes */
190237 char *zPrefix = 0; /* Prefix parameter value (or NULL) */
190238 char *zCompress = 0; /* compress=? parameter (or NULL) */
190239 char *zUncompress = 0; /* uncompress=? parameter (or NULL) */
190240 char *zContent = 0; /* content=? parameter (or NULL) */
190241 char *zLanguageid = 0; /* languageid=? parameter (or NULL) */
190242 char **azNotindexed = 0; /* The set of notindexed= columns */
190243 int nNotindexed = 0; /* Size of azNotindexed[] array */
190245 assert( strlen(argv[0])==4 );
190246 assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
190247 || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
190256 memset((void*)aCol, 0, nByte);
190260 memset(azNotindexed, 0, nByte);
190286 && 0==sqlite3_strnicmp(z, "tokenize", 8)
190287 && 0==sqlite3Fts3IsIdChar(z[8])
190298 { "matchinfo", 9 }, /* 0 -> MATCHINFO */
190312 for(iOpt=0; iOpt<SizeofArray(aFts4Opt); iOpt++){
190319 case 0: /* MATCHINFO */
190330 zVal = 0;
190336 zVal = 0;
190342 zVal = 0;
190352 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
190358 zVal = 0;
190365 zVal = 0;
190370 zVal = 0;
190400 zCompress = 0;
190401 zUncompress = 0;
190402 if( nCol==0 ){
190404 aCol = 0;
190411 for(j=0; j<nCol; j++){
190412 if( sqlite3_stricmp(zLanguageid, aCol[j])==0 ){
190424 if( nCol==0 ){
190425 assert( nString==0 );
190426 aCol[0] = "content";
190431 if( pTokenizer==0 ){
190453 if( p==0 ){
190457 memset(p, 0, nByte);
190460 p->nPendingData = 0;
190464 p->bHasDocsize = (isFts4 && bNoDocsize==0);
190468 p->nAutoincrmerge = 0xff; /* 0xff means setting unknown */
190471 zContent = 0;
190472 zLanguageid = 0;
190479 for(i=0; i<nIndex; i++){
190494 for(iCol=0; iCol<nCol; iCol++){
190496 int n = 0;
190498 if( n>0 ){
190501 zCsr[n] = '\0';
190509 for(iCol=0; iCol<nCol; iCol++){
190511 for(i=0; i<nNotindexed; i++){
190514 && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n)
190518 azNotindexed[i] = 0;
190522 for(i=0; i<nNotindexed; i++){
190529 if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
190530 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
190571 for(i=0; i<nNotindexed; i++) sqlite3_free(azNotindexed[i]);
190581 assert( p->pSegments==0 );
190599 return fts3InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
190666 for(i=0; i<pInfo->nConstraint; i++){
190669 if( pCons->usable==0 ){
190684 bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1);
190687 if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){
190703 && pCons->iColumn>=0 && pCons->iColumn<=p->nColumn
190736 if( iCons>=0 ){
190740 if( iLangidCons>=0 ){
190744 if( iDocidGe>=0 ){
190748 if( iDocidLe>=0 ){
190757 struct sqlite3_index_orderby *pOrder = &pInfo->aOrderBy[0];
190758 if( pOrder->iColumn<0 || pOrder->iColumn==p->nColumn+1 ){
190768 assert( p->pSegments==0 );
190788 memset(pCsr, 0, sizeof(Fts3Cursor));
190802 if( p->pSeekStmt==0 ){
190805 pCsr->pStmt = 0;
190807 pCsr->bSeekStmt = 0;
190822 memset(&(&pCsr->base)[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
190831 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
190833 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
190839 ** If pCsr->pStmt has not been prepared (i.e. if pCsr->pStmt==0), then
190849 if( pCsr->pStmt==0 ){
190854 p->pSeekStmt = 0;
190860 p->db, zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
190883 pCsr->isRequireSeek = 0;
190890 if( rc==SQLITE_OK && ((Fts3Table *)pCsr->base.pVtab)->zContentTbl==0 ){
190933 char *zBuffer = 0; /* Buffer to load terms into */
190934 i64 nAlloc = 0; /* Size of allocated buffer */
190937 int nBuffer = 0; /* Total term size */
190961 int nPrefix = 0; /* Size of term prefix */
190972 isFirstTerm = 0;
190975 assert( nPrefix>=0 && nSuffix>=0 );
190976 if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){
191005 if( piFirst && (cmp<0 || (cmp==0 && nBuffer>nTerm)) ){
191007 piFirst = 0;
191010 if( piLast && cmp<0 ){
191012 piLast = 0;
191067 char *zBlob = 0; /* Blob read from %_segments table */
191068 int nBlob = 0; /* Size of zBlob in bytes */
191071 rc = sqlite3Fts3ReadBlock(p, *piLeaf, &zBlob, &nBlob, 0);
191073 rc = fts3SelectLeaf(p, zTerm, nTerm, zBlob, nBlob, piLeaf, 0);
191076 piLeaf = 0;
191077 zBlob = 0;
191081 rc = sqlite3Fts3ReadBlock(p, piLeaf?*piLeaf:*piLeaf2, &zBlob, &nBlob, 0);
191084 int iNewHeight = 0;
191107 assert_fts3_nc( iVal-*piPrev > 0 || (*piPrev==0 && iVal==0) );
191128 char c = 0;
191131 ** varint. A single POS_END (0) byte. Except, if the 0 byte is preceded by
191132 ** a byte with the 0x80 bit set, then it is not a varint 0, but the tail
191136 ** immediately preceded by a byte with the 0x80 bit set. Then increments
191141 c = *pEnd++ & 0x80;
191142 testcase( c!=0 && (*pEnd)==0 );
191165 ** a POS_END varint (0). This routine leaves *ppPoslist pointing to
191175 char c = 0;
191177 /* A column-list is terminated by either a 0x01 or 0x00 byte that is
191180 while( 0xFE & (*pEnd | c) ){
191181 c = *pEnd++ & 0x80;
191182 testcase( c!=0 && ((*pEnd)&0xfe)==0 );
191205 ** (in which case **pp will be a terminator bytes POS_END (0) or
191223 if( (**pp)&0xFE ){
191234 ** If parameter iCol is not 0, write an POS_COLUMN (1) byte followed by
191239 ** returning (do not modify it if iCol==0). Return the total number of bytes
191240 ** written (0 if iCol==0).
191243 int n = 0; /* Number of bytes written */
191247 *p = 0x01;
191275 if( iCol1==0 ) return FTS_CORRUPT_VTAB;
191277 else if( *p1==POS_END ) iCol1 = 0x7fffffff;
191278 else iCol1 = 0;
191282 if( iCol2==0 ) return FTS_CORRUPT_VTAB;
191284 else if( *p2==POS_END ) iCol2 = 0x7fffffff;
191285 else iCol2 = 0;
191288 sqlite3_int64 i1 = 0; /* Last position from pp1 */
191289 sqlite3_int64 i2 = 0; /* Last position from pp2 */
191290 sqlite3_int64 iPrev = 0;
191299 ** POS_END (0) or POS_COLUMN (1). The following block merges the two lists
191347 ** 0x02 0x01 0x02 0x03 0x03 0x00
191350 ** byte following the 0x00 terminator of their respective position lists.
191352 ** If isSaveLeft is 0, an entry is added to the output position list for
191371 int iCol1 = 0;
191372 int iCol2 = 0;
191375 assert( isSaveLeft==0 || isExact==0 );
191377 assert_fts3_nc( p!=0 && *p1!=0 && *p2!=0 );
191381 /* iCol1==0 indicates corruption. Column 0 does not have a POS_COLUMN
191383 if( iCol1==0 ) return 0;
191388 /* As above, iCol2==0 indicates corruption. */
191389 if( iCol2==0 ) return 0;
191395 sqlite3_int64 iPrev = 0;
191396 sqlite3_int64 iPos1 = 0;
191397 sqlite3_int64 iPos2 = 0;
191406 if( iPos1<0 || iPos2<0 ) break;
191410 || (isExact==0 && iPos2>iPos1 && iPos2<=iPos1+nToken)
191415 pSave = 0;
191419 if( (*p2&0xFE)==0 ) break;
191422 if( (*p1&0xFE)==0 ) break;
191432 fts3ColumnlistCopy(0, &p1);
191433 fts3ColumnlistCopy(0, &p2);
191434 assert( (*p1&0xFE)==0 && (*p2&0xFE)==0 );
191435 if( 0==*p1 || 0==*p2 ) break;
191444 ** iCol1 and iCol2) so that it points to either the 0x00 that marks the
191445 ** end of the position list, or the 0x01 that precedes the next
191449 fts3ColumnlistCopy(0, &p1);
191450 if( 0==*p1 ) break;
191454 fts3ColumnlistCopy(0, &p2);
191455 if( 0==*p2 ) break;
191461 fts3PoslistCopy(0, &p2);
191462 fts3PoslistCopy(0, &p1);
191466 return 0;
191468 *p++ = 0x00;
191504 fts3PoslistPhraseMerge(&pTmp1, nRight, 0, 0, pp1, pp2);
191508 fts3PoslistPhraseMerge(&pTmp2, nLeft, 1, 0, pp2, pp1);
191516 res = 0;
191537 ** has been reached. In this case *pp is set to 0 and the function returns.
191553 *pp = 0;
191588 if( bDescIdx==0 || *pbFirst==0 ){
191589 assert_fts3_nc( *pbFirst==0 || iVal>=*piPrev );
191595 assert( *pbFirst || *piPrev==0 );
191596 assert_fts3_nc( *pbFirst==0 || iWrite>0 );
191606 ** bDescDoclist is 0 when this macro is invoked, then it returns (i1-i2).
191613 #define DOCID_CMP(i1, i2) ((bDescDoclist?-1:1) * (i1>i2?1:((i1==i2)?0:-1)))
191636 sqlite3_int64 i1 = 0;
191637 sqlite3_int64 i2 = 0;
191638 sqlite3_int64 iPrev = 0;
191645 int bFirstOut = 0;
191647 *paOut = 0;
191648 *pnOut = 0;
191651 ** are delta encoded. If they are in ascending order (bDescDoclist==0),
191683 fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
191684 fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
191688 if( p2 && p1 && iDiff==0 ){
191694 }else if( !p2 || (p1 && iDiff<0) ){
191709 p = aOut = 0;
191712 memset(&aOut[(p-aOut)], 0, FTS3_BUFFER_PADDING);
191737 sqlite3_int64 i1 = 0;
191738 sqlite3_int64 i2 = 0;
191739 sqlite3_int64 iPrev = 0;
191746 int bFirstOut = 0;
191749 assert( nDist>0 );
191752 if( aOut==0 ) return SQLITE_NOMEM;
191758 fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
191759 fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
191763 if( iDiff==0 ){
191769 if( 0==fts3PoslistPhraseMerge(&p, nDist, 0, 1, &p1, &p2) ){
191776 }else if( iDiff<0 ){
191777 fts3PoslistCopy(0, &p1);
191780 fts3PoslistCopy(0, &p2);
191797 ** a token in position 0 (of any column). If so, it writes argument iDelta
191799 ** of the entries from pList at position 0, and terminated by an 0x00 byte.
191804 char *pList, /* Position list (no 0x00 term) */
191808 int nOut = 0;
191809 int bWritten = 0; /* True once iDelta has been written */
191813 if( *p!=0x01 ){
191814 if( *p==0x02 ){
191816 pOut[nOut++] = 0x02;
191819 fts3ColumnlistCopy(0, &p);
191826 if( *p==0x02 ){
191827 if( bWritten==0 ){
191831 pOut[nOut++] = 0x01;
191833 pOut[nOut++] = 0x02;
191835 fts3ColumnlistCopy(0, &p);
191838 pOut[nOut++] = 0x00;
191847 ** doclist stored in TermSelect.aaOutput[0]. If successful, delete all
191848 ** other doclists (except the aaOutput[0] one) and return SQLITE_OK.
191855 char *aOut = 0;
191856 int nOut = 0;
191862 for(i=0; i<SizeofArray(pTS->aaOutput); i++){
191867 pTS->aaOutput[i] = 0;
191882 pTS->aaOutput[i] = 0;
191889 pTS->aaOutput[0] = aOut;
191890 pTS->anOutput[0] = nOut;
191914 if( pTS->aaOutput[0]==0 ){
191931 pTS->aaOutput[0] = sqlite3_malloc64((i64)nDoclist + FTS3_VARINT_MAX + 1);
191932 pTS->anOutput[0] = nDoclist;
191933 if( pTS->aaOutput[0] ){
191934 memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
191935 memset(&pTS->aaOutput[0][nDoclist], 0, FTS3_VARINT_MAX);
191944 for(iOut=0; iOut<SizeofArray(pTS->aaOutput); iOut++){
191945 if( pTS->aaOutput[iOut]==0 ){
191946 assert( iOut>0 );
191964 pTS->aaOutput[iOut] = 0;
191985 if( (pCsr->nSegment%16)==0 ){
192009 int iIndex, /* Index to search (from 0 to p->nIndex-1) */
192018 sqlite3_stmt *pStmt = 0; /* Statement to iterate through segments */
192021 /* If iLevel is less than 0 and this is not a scan, include a seg-reader
192027 if( iLevel<0 && p->aIndex && p->iPrevLangid==iLangid ){
192028 Fts3SegReader *pSeg = 0;
192041 Fts3SegReader *pSeg = 0;
192053 sqlite3_int64 *pi = (isPrefix ? &iLeavesEndBlock : 0);
192056 if( isPrefix==0 && isScan==0 ) iLeavesEndBlock = iStartBlock;
192060 (isPrefix==0 && isScan==0),
192083 int iIndex, /* Index to search (from 0 to p->nIndex-1) */
192091 assert( iIndex>=0 && iIndex<p->nIndex );
192094 || iLevel>=0
192097 assert( FTS3_SEGCURSOR_ALL<0 && FTS3_SEGCURSOR_PENDING<0 );
192098 assert( isPrefix==0 || isScan==0 );
192100 memset(pCsr, 0, sizeof(Fts3MultiSegReader));
192120 iLangid, 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0,pCsr
192135 ** Output parameter *ppSegcsr is set to 0 if an error occurs.
192150 int bFound = 0; /* True once an index has been found */
192154 for(i=1; bFound==0 && i<p->nIndex; i++){
192158 i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0, pSegcsr
192164 for(i=1; bFound==0 && i<p->nIndex; i++){
192168 i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 1, 0, pSegcsr
192179 if( bFound==0 ){
192181 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, isPrefix, 0, pSegcsr
192216 memset(&tsc, 0, sizeof(TermSelect));
192219 | (pTok->isPrefix ? FTS3_SEGMENT_PREFIX : 0)
192220 | (pTok->bFirst ? FTS3_SEGMENT_FIRST : 0)
192221 | (iColumn<p->nColumn ? FTS3_SEGMENT_COLUMN_FILTER : 0);
192237 *ppOut = tsc.aaOutput[0];
192238 *pnOut = tsc.anOutput[0];
192241 for(i=0; i<SizeofArray(tsc.aaOutput); i++){
192247 pTok->pSegcsr = 0;
192261 int nDoc = 0; /* Return value */
192267 while( (*p++)&0x80 ); /* Skip docid varint */
192268 fts3PoslistCopy(0, &p); /* Skip over position list */
192296 pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0);
192303 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
192335 ** number idxNum-FTS3_FULLTEXT_SEARCH, 0 indexed. argv[0] is the right-hand
192351 sqlite3_value *pCons = 0; /* The MATCH or rowid constraint, if any */
192352 sqlite3_value *pLangid = 0; /* The "langid = ?" constraint, if any */
192353 sqlite3_value *pDocidGe = 0; /* The "docid >= ?" constraint, if any */
192354 sqlite3_value *pDocidLe = 0; /* The "docid <= ?" constraint, if any */
192364 eSearch = (idxNum & 0x0000FFFF);
192365 assert( eSearch>=0 && eSearch<=(FTS3_FULLTEXT_SEARCH+p->nColumn) );
192366 assert( p->pSegments==0 );
192369 iIdx = 0;
192384 pCsr->bDesc = (idxStr[0]=='D');
192394 if( zQuery==0 && sqlite3_value_type(pCons)!=SQLITE_NULL ){
192398 pCsr->iLangid = 0;
192401 assert( p->base.zErrMsg==0 );
192414 pCsr->iPrevId = 0;
192437 p->db,zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
192501 assert( iCol>=0 && iCol<=p->nColumn+2 );
192504 case 0:
192506 sqlite3_result_pointer(pCtx, pCsr, "fts3cursor", 0);
192518 }else if( p->zLanguageid==0 ){
192519 sqlite3_result_int(pCtx, 0);
192529 rc = fts3CursorSeek(0, pCsr);
192536 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
192568 ** small - often between 0 and 2. So the overhead of the incremental
192588 && p->nAutoincrmerge && p->nAutoincrmerge!=0xff
192590 int mxLevel = 0; /* Maximum relative level value in db */
192594 assert( rc==SQLITE_OK || mxLevel==0 );
192607 ** to 0 or 1). Return SQLITE_OK if successful, or an SQLite error code
192615 int res = sqlite3_table_column_metadata(p->db, p->zDb, zTbl, 0,0,0,0,0,0);
192632 assert( p->pSegments==0 );
192633 assert( p->nPendingData==0 );
192635 p->nLeafAdd = 0;
192654 assert( p->nPendingData==0 );
192655 assert( p->inTransaction!=0 );
192656 assert( p->pSegments==0 );
192657 TESTONLY( p->inTransaction = 0 );
192669 assert( p->inTransaction!=0 );
192670 TESTONLY( p->inTransaction = 0 );
192683 char c = 0;
192685 /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */
192686 while( p>pStart && (c=*p--)==0 );
192689 ** poslist). This is an 0x00 byte preceded by some byte that does not
192690 ** have the 0x80 bit set. */
192691 while( p>pStart && (*p & 0x80) | c ){
192694 assert( p==pStart || c==0 );
192696 /* At this point p points to that preceding byte without the 0x80 bit
192702 ** The second part of the if condition (c==0 && *ppPoslist>&p[2])
192707 ** 0x0A 0x00 <next docid delta varint>
192709 if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; }
192710 while( *p++&0x80 );
192727 sqlite3_value *pVal, /* argv[0] passed to function */
192732 if( (*ppCsr)!=0 ){
192751 Fts3Cursor *pCsr; /* Cursor handle passed through apVal[0] */
192768 if( fts3FunctionArg(pContext, "snippet", apVal[0], &pCsr) ) return;
192783 }else if( nToken==0 ){
192798 Fts3Cursor *pCsr; /* Cursor handle passed through apVal[0] */
192803 if( fts3FunctionArg(pContext, "offsets", apVal[0], &pCsr) ) return;
192826 Fts3Cursor *pCursor; /* Cursor handle passed through apVal[0] */
192831 if( fts3FunctionArg(pContext, "optimize", apVal[0], &pCursor) ) return;
192858 Fts3Cursor *pCsr; /* Cursor handle passed through apVal[0] */
192860 if( SQLITE_OK==fts3FunctionArg(pContext, "matchinfo", apVal[0], &pCsr) ){
192861 const char *zArg = 0;
192895 for(i=0; i<SizeofArray(aOverload); i++){
192896 if( strcmp(zName, aOverload[i].zName)==0 ){
192902 /* No function of the specified name was found. Return 0. */
192903 return 0;
192927 assert( p->nPendingData==0 );
192934 if( p->zContentTbl==0 ){
192962 p->bIgnoreSavepoint = 0;
192978 if( pTab->bIgnoreSavepoint==0 ){
192979 if( fts3HashCount(&pTab->aIndex[0].hPending)>0 ){
192985 rc = sqlite3_exec(pTab->db, zSql, 0, 0, 0);
192986 pTab->bIgnoreSavepoint = 0;
193038 for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
193039 if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
193041 return 0;
193057 int bOk = 0;
193062 if( rc==SQLITE_ERROR || (rc&0xFF)==SQLITE_CORRUPT ){
193067 }else if( rc==SQLITE_OK && bOk==0 ){
193070 if( *pzErr==0 ) rc = SQLITE_NOMEM;
193114 if( pHash->nRef<=0 ){
193147 Fts3HashWrapper *pHash = 0;
193148 const sqlite3_tokenizer_module *pSimple = 0;
193149 const sqlite3_tokenizer_module *pPorter = 0;
193151 const sqlite3_tokenizer_module *pUnicode = 0;
193155 const sqlite3_tokenizer_module *pIcu = 0;
193180 pHash->nRef = 0;
193271 for(i=0; i<nToken; i++){
193281 assert( pExpr->pPhrase->iDoclistToken==0 );
193311 if( pList==0 ){
193313 p->doclist.aAll = 0;
193314 p->doclist.nAll = 0;
193317 else if( p->iDoclistToken<0 ){
193322 else if( p->doclist.aAll==0 ){
193373 for(iToken=0; rc==SQLITE_OK && iToken<p->nToken; iToken++){
193375 assert( pToken->pDeferred==0 || pToken->pSegcsr==0 );
193378 int nThis = 0;
193379 char *pThis = 0;
193385 assert( pToken->pSegcsr==0 );
193404 char *aPoslist = 0; /* Position list for deferred tokens */
193405 int nPoslist = 0; /* Number of bytes in aPoslist */
193407 char *aFree = (pPhrase->doclist.bFreeList ? pPhrase->doclist.pList : 0);
193409 for(iToken=0; iToken<pPhrase->nToken; iToken++){
193419 if( pList==0 ){
193422 pPhrase->doclist.pList = 0;
193423 pPhrase->doclist.nList = 0;
193426 }else if( aPoslist==0 ){
193435 assert( iPrev>=0 );
193436 fts3PoslistPhraseMerge(&aOut, iToken-iPrev, 0, 1, &p1, &p2);
193440 if( nPoslist==0 ){
193443 pPhrase->doclist.pList = 0;
193444 pPhrase->doclist.nList = 0;
193452 if( iPrev>=0 ){
193454 if( nMaxUndeferred<0 ){
193483 if( fts3PoslistPhraseMerge(&aOut, nDistance, 0, 1, &p1, &p2) ){
193488 pPhrase->doclist.pList = 0;
193489 pPhrase->doclist.nList = 0;
193528 int bHaveIncr = 0;
193531 && p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0
193533 && pTab->bNoIncrDoclist==0
193536 for(i=0; bIncrOk==1 && i<p->nToken; i++){
193538 if( pToken->bFirst || (pToken->pSegcsr!=0 && !pToken->pSegcsr->bLookup) ){
193539 bIncrOk = 0;
193547 for(i=0; rc==SQLITE_OK && i<p->nToken; i++){
193558 p->bIncr = 0;
193561 assert( rc!=SQLITE_OK || p->nToken<1 || p->aToken[0].pSegcsr==0 || p->bIncr );
193571 ** The doclist may be sorted in ascending (parameter bDescIdx==0) or
193586 assert( nDoclist>0 );
193587 assert( *pbEof==0 );
193588 assert_fts3_nc( p || *piDocid==0 );
193591 if( p==0 ){
193592 sqlite3_int64 iDocid = 0;
193593 char *pNext = 0;
193603 fts3PoslistCopy(0, &pDocid);
193604 while( pDocid<pEnd && *pDocid==0 ) pDocid++;
193641 assert( nDoclist>0 );
193642 assert( *pbEof==0 );
193643 assert_fts3_nc( p || *piDocid==0 );
193646 if( p==0 ){
193650 fts3PoslistCopy(0, &p);
193651 while( p<&aDoclist[nDoclist] && *p==0 ) p++;
193678 assert( pDL->aAll!=0 || pIter==0 );
193683 if( pIter==0 || pIter>=(pEnd = pDL->aAll + pDL->nAll) ){
193689 if( pTab->bDescIdx==0 || pDL->pNextDocid==0 ){
193695 fts3PoslistCopy(0, &pIter);
193698 /* pIter now points just past the 0x00 that terminates the position-
193704 while( pIter<pEnd && *pIter==0 ) pIter++;
193708 *pbEof = 0;
193742 assert( p->bIgnore==0 );
193743 assert( pPhrase->aToken[iToken].pSegcsr==0 );
193750 assert( pToken->pDeferred==0 );
193751 assert( pToken->pSegcsr || pPhrase->iDoclistToken>=0 );
193753 assert( p->bIgnore==0 );
193757 if( p->pList==0 ) *pbEof = 1;
193779 ** successfully advanced, *pbEof is set to 0.
193792 u8 bEof = 0;
193799 rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr,
193802 if( pDL->pList==0 ) bEof = 1;
193807 memset(a, 0, sizeof(a));
193811 while( bEof==0 ){
193812 int bMaxSet = 0;
193813 sqlite3_int64 iMax = 0; /* Largest docid for all iterators */
193817 for(i=0; rc==SQLITE_OK && i<p->nToken && bEof==0; i++){
193819 if( a[i].bIgnore==0 && (bMaxSet==0 || DOCID_CMP(iMax, a[i].iDocid)<0) ){
193824 assert( rc!=SQLITE_OK || (p->nToken>=1 && a[p->nToken-1].bIgnore==0) );
193828 for(i=0; i<p->nToken; i++){
193829 while( rc==SQLITE_OK && bEof==0
193830 && a[i].bIgnore==0 && DOCID_CMP(a[i].iDocid, iMax)<0
193833 if( DOCID_CMP(a[i].iDocid, iMax)>0 ){
193835 i = 0;
193841 if( bEof==0 ){
193842 int nList = 0;
193847 memset(&aDoclist[nByte], 0, FTS3_BUFFER_PADDING);
193849 for(i=0; i<(p->nToken-1); i++){
193850 if( a[i].bIgnore==0 ){
193855 int res = fts3PoslistPhraseMerge(&pOut, nDist, 0, 1, &pL, &pR);
193856 if( res==0 ) break;
193883 ** successfully advanced, *pbEof is set to 0.
193934 for(i=0; i<nToken; i++){
193935 if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
193989 for(i=0; *pRc==SQLITE_OK && i<pPhrase->nToken; i++){
194033 if( pCsr->nRowAvg==0 ){
194038 ** Entry 0 of the %_stat table is a blob containing (nCol+1) FTS3
194047 sqlite3_int64 nDoc = 0;
194048 sqlite3_int64 nByte = 0;
194054 a = sqlite3_column_blob(pStmt, 0);
194055 testcase( a==0 ); /* If %_stat.value set to X'' */
194057 pEnd = &a[sqlite3_column_bytes(pStmt, 0)];
194063 if( nDoc==0 || nByte==0 ){
194070 assert( pCsr->nRowAvg>0 );
194099 int nDocSize = 0; /* Number of pages per doc loaded */
194102 int nOvfl = 0; /* Total overflow pages used by doclists */
194103 int nToken = 0; /* Total number of tokens in cluster */
194105 int nMinEst = 0; /* The minimum count for any phrase so far. */
194120 for(ii=0; ii<nTC; ii++){
194126 if( nOvfl==0 || nToken<2 ) return SQLITE_OK;
194130 assert( rc!=SQLITE_OK || nDocSize>0 );
194155 for(ii=0; ii<nToken && rc==SQLITE_OK; ii++){
194157 Fts3TokenAndCost *pTC = 0; /* Set to cheapest remaining token. */
194160 for(iTC=0; iTC<nTC; iTC++){
194177 pToken->pSegcsr = 0;
194184 if( ii==0 || (pTC->pPhrase->nToken>1 && ii!=nToken-1) ){
194189 int nList = 0;
194190 char *pList = 0;
194192 assert( rc==SQLITE_OK || pList==0 );
194203 if( ii==0 || nCount<nMinEst ) nMinEst = nCount;
194207 pTC->pToken = 0;
194228 int nToken = 0;
194229 int nOr = 0;
194251 fts3EvalTokenCosts(pCsr, 0, pCsr->pExpr, &pTC, &ppOr, &rc);
194256 rc = fts3EvalSelectDeferred(pCsr, 0, aTC, nToken);
194257 for(ii=0; rc==SQLITE_OK && ii<nOr; ii++){
194278 pPhrase->doclist.pList = 0;
194279 pPhrase->doclist.nList = 0;
194280 pPhrase->doclist.bFreeList = 0;
194299 ** leaves 0 positions, zero is returned. Otherwise, non-zero.
194327 assert_fts3_nc( nNew<=pPhrase->doclist.nList && nNew>0 );
194328 if( nNew>=0 && nNew<=pPhrase->doclist.nList ){
194329 assert( pPhrase->doclist.pList[nNew]=='\0' );
194330 memset(&pPhrase->doclist.pList[nNew], 0, pPhrase->doclist.nList - nNew);
194351 ** Fts3Expr.iDocid (valid if bEof==0. The docid of the next row)
194386 if( *pRc==SQLITE_OK && pExpr->bEof==0 ){
194415 if( iDiff==0 ) break;
194416 if( iDiff<0 ){
194428 while( *pRc==SQLITE_OK && pRight->bEof==0 ){
194429 memset(pDl->pList, 0, pDl->nList);
194435 while( *pRc==SQLITE_OK && pLeft->bEof==0 ){
194436 memset(pDl->pList, 0, pDl->nList);
194454 if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
194456 }else if( pLeft->bEof || iCmp>0 ){
194465 if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
194478 if( pRight->bStart==0 ){
194484 if( pLeft->bEof==0 ){
194487 && DOCID_CMP(pLeft->iDocid, pRight->iDocid)>0
194520 ** match the current row, 0 is returned. The position lists may or may not
194521 ** be edited if 0 is returned.
194548 && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
194551 sqlite3_int64 nTmp = 0; /* Bytes of temp space */
194556 assert( p->pRight->pPhrase->doclist.nList>0 );
194563 res = 0;
194636 if( bHit==0
194638 && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
194641 for(p=pExpr; p->pPhrase==0; p=p->pLeft){
194677 bHit = (pPhrase->doclist.pList!=0);
194683 pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId
194684 && pExpr->pPhrase->doclist.nList>0
194706 ** returns 0. Otherwise, it tests whether or not after considering NEAR
194716 ** query, return 0.
194720 int bMiss = 0;
194730 rc = fts3CursorSeek(0, pCsr);
194735 bMiss = (0==fts3EvalTestExpr(pCsr, pCsr->pExpr, &rc));
194751 assert( pCsr->isEof==0 );
194752 if( pExpr==0 ){
194756 if( pCsr->isRequireSeek==0 ){
194759 assert( sqlite3_data_count(pCsr->pStmt)==0 );
194765 }while( pCsr->isEof==0 && sqlite3Fts3EvalTestDeferred(pCsr, &rc) );
194771 (pCsr->bDesc==0 && pCsr->iPrevId>pCsr->iMaxDocid)
194772 || (pCsr->bDesc!=0 && pCsr->iPrevId<pCsr->iMinDocid)
194801 for(i=0; i<pPhrase->nToken; i++){
194803 assert( pToken->pDeferred==0 );
194808 *pRc = fts3EvalPhraseStart(pCsr, 0, pPhrase);
194810 pPhrase->doclist.pNextDocid = 0;
194811 pPhrase->doclist.iDocid = 0;
194812 pPhrase->pOrPoslist = 0;
194815 pExpr->iDocid = 0;
194816 pExpr->bEof = 0;
194817 pExpr->bStart = 0;
194831 if( pExpr->bEof==0 ){
194854 int iCol = 0;
194858 u8 c = 0;
194859 int iCnt = 0;
194860 while( 0xFE & (*p | c) ){
194861 if( (c&0x80)==0 ) iCnt++;
194862 c = *p++ & 0x80;
194869 pExpr->aMI[iCol*3 + 2] += (iCnt>0);
194870 if( *p==0x00 ) break;
194889 if( pExpr->aMI==0 ){
194891 if( pExpr->aMI==0 ) return SQLITE_NOMEM;
194893 memset(pExpr->aMI, 0, pTab->nColumn * 3 * sizeof(u32));
194915 if( pExpr->aMI==0 ){
194939 while( pCsr->isEof==0 && rc==SQLITE_OK ){
194943 if( pCsr->isRequireSeek==0 ) sqlite3_reset(pCsr->pStmt);
194944 assert( sqlite3_data_count(pCsr->pStmt)==0 );
194952 }while( pCsr->isEof==0
194957 if( rc==SQLITE_OK && pCsr->isEof==0 ){
194962 pCsr->isEof = 0;
194977 assert_fts3_nc( pRoot->bEof==0 );
195025 assert( pCsr->nDoc>0 );
195026 for(iCol=0; iCol<pTab->nColumn; iCol++){
195034 for(iCol=0; iCol<pTab->nColumn; iCol++){
195054 ** compression and is terminated by either an 0x01 or 0x00 byte. For example,
195058 ** 0x04 0x05 0x03 0x01 or 0x04 0x05 0x03 0x00
195077 *ppOut = 0;
195078 assert( iCol>=0 && iCol<pTab->nColumn );
195088 int bOr = 0;
195089 u8 bTreeEof = 0;
195106 if( bOr==0 ) return SQLITE_OK;
195121 if( bEofSave==0 && pRun->iDocid==iDocid ) break;
195123 assert( rc!=SQLITE_OK || pPhrase->bIncr==0 );
195137 u8 bEof = 0;
195150 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
195158 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){
195168 if( bEof || iDocid!=pCsr->iPrevId ) bMatch = 0;
195174 pIter = 0;
195177 if( pIter==0 ) return SQLITE_OK;
195179 if( *pIter==0x01 ){
195183 iThis = 0;
195186 fts3ColumnlistCopy(0, &pIter);
195187 if( *pIter==0x00 ) return SQLITE_OK;
195191 if( *pIter==0x00 ){
195192 pIter = 0;
195195 *ppOut = ((iCol==iThis)?pIter:0);
195211 memset(&pPhrase->doclist, 0, sizeof(Fts3Doclist));
195212 for(i=0; i<pPhrase->nToken; i++){
195214 pPhrase->aToken[i].pSegcsr = 0;
195334 if( nDb==4 && 0==sqlite3_strnicmp("temp", zDb, 4) ){
195352 memset(p, 0, nByte);
195383 for(i=0; i<SizeofArray(pFts3->aStmt); i++){
195413 && pInfo->aOrderBy[0].iColumn==0
195414 && pInfo->aOrderBy[0].desc==0
195421 for(i=0; i<pInfo->nConstraint; i++){
195426 if( iCol==0 ){
195439 if( iEq>=0 ){
195444 pInfo->idxNum = 0;
195446 if( iGe>=0 ){
195451 if( iLe>=0 ){
195457 if( iLangid>=0 ){
195475 memset(pCsr, 0, sizeof(Fts3auxCursor));
195503 if( aNew==0 ) return SQLITE_NOMEM;
195504 memset(&aNew[pCsr->nStat], 0,
195525 if( pCsr->aStat[pCsr->iCol].nDoc>0 ) return SQLITE_OK;
195530 int i = 0;
195535 int eState = 0;
195540 if( mc<0 || (mc==0 && pCsr->csr.nTerm>pCsr->nStop) ){
195547 memset(pCsr->aStat, 0, sizeof(struct Fts3auxColstats) * pCsr->nStat);
195548 iCol = 0;
195552 sqlite3_int64 v = 0;
195556 /* State 0. In this state the integer just read was a docid. */
195557 case 0:
195558 pCsr->aStat[0].nDoc++;
195560 iCol = 0;
195565 ** start of a position list for column 0.
195568 ** integer encountered in state 1 is not 0 or 1, then we need to
195569 ** increment the column 0 "nDoc" count for this term.
195572 assert( iCol==0 );
195580 if( v==0 ){ /* 0x00. Next integer will be a docid. */
195581 eState = 0;
195582 }else if( v==1 ){ /* 0x01. Next integer will be a column number. */
195586 pCsr->aStat[0].nOcc++;
195604 pCsr->iCol = 0;
195624 int isScan = 0;
195625 int iLangVal = 0; /* Language id to query */
195631 int iNext = 0;
195636 assert( idxStr==0 );
195637 assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0
195663 memset(&pCsr->csr, 0, ((u8*)&pCsr[1]) - (u8*)&pCsr->csr);
195668 if( iEq>=0 || iGe>=0 ){
195669 const unsigned char *zStr = sqlite3_value_text(apVal[0]);
195670 assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
195673 if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
195678 if( iLe>=0 ){
195680 if( pCsr->zStop==0 ) return SQLITE_NOMEM;
195684 if( iLangid>=0 ){
195692 if( iLangVal<0 ) iLangVal = 0;
195696 rc = sqlite3Fts3SegReaderCursor(pFts3, iLangVal, 0, FTS3_SEGCURSOR_ALL,
195697 pCsr->filter.zTerm, pCsr->filter.nTerm, 0, isScan, &pCsr->csr
195725 assert( p->isEof==0 );
195727 case 0: /* term */
195774 0, /* iVersion */
195787 0, /* xUpdate */
195788 0, /* xBegin */
195789 0, /* xSync */
195790 0, /* xCommit */
195791 0, /* xRollback */
195792 0, /* xFindFunction */
195793 0, /* xRename */
195794 0, /* xSavepoint */
195795 0, /* xRelease */
195796 0, /* xRollbackTo */
195797 0, /* xShadowName */
195798 0 /* xIntegrity */
195802 rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
195876 SQLITE_API int sqlite3_fts3_enable_parentheses = 0;
195881 # define sqlite3_fts3_enable_parentheses 0
195921 ** is defined to accept an argument of type char, and always returns 0 for
195936 if( pRet ) memset(pRet, 0, nByte);
195948 sqlite3_tokenizer_cursor *pCsr = 0;
195952 assert( rc==SQLITE_OK || pCsr==0 );
195959 pCsr = 0;
195980 for(ii=0; ii<n; ii++){
196013 Fts3Expr *pRet = 0;
196019 int nToken = 0, iStart = 0, iEnd = 0, iPosition = 0;
196030 if( iBarred>=0 ){
196044 pRet->pPhrase->aToken[0].n = nToken;
196045 pRet->pPhrase->aToken[0].z = (char*)&pRet->pPhrase->aToken[1];
196046 memcpy(pRet->pPhrase->aToken[0].z, zToken, nToken);
196049 pRet->pPhrase->aToken[0].isPrefix = 1;
196055 && iStart>0 && z[iStart-1]=='-'
196059 }else if( pParse->bFts4 && iStart>0 && z[iStart-1]=='^' ){
196060 pRet->pPhrase->aToken[0].bFirst = 1;
196071 if( iBarred>=0 ){
196107 ** to 0.
196117 Fts3Expr *p = 0;
196118 sqlite3_tokenizer_cursor *pCursor = 0;
196119 char *zTemp = 0;
196120 i64 nTemp = 0;
196123 int nToken = 0;
196148 for(ii=0; rc==SQLITE_OK; ii++){
196150 int nByte = 0, iBegin = 0, iEnd = 0, iPos = 0;
196164 memset(pToken, 0, sizeof(Fts3PhraseToken));
196171 pToken->bFirst = (iBegin>0 && zInput[iBegin-1]=='^');
196179 char *zBuf = 0;
196186 memset(p, 0, (char *)&(((Fts3Phrase *)&p[1])->aToken[0])-(char *)p);
196193 assert( nTemp==0 || zTemp );
196198 for(jj=0; jj<p->pPhrase->nToken; jj++){
196212 p = 0;
196220 ** structure, or set to 0 if the end of the input buffer is reached.
196238 { "OR" , 2, 0, FTSQUERY_OR },
196241 { "NEAR", 4, 0, FTSQUERY_NEAR }
196247 Fts3Expr *pRet = 0;
196252 pParse->isNot = 0;
196257 while( nInput>0 && fts3isspace(*zInput) ){
196261 if( nInput==0 ){
196266 for(ii=0; ii<(int)(sizeof(aKeyword)/sizeof(struct Fts3Keyword)); ii++){
196269 if( (pKey->parenOnly & ~sqlite3_fts3_enable_parentheses)!=0 ){
196273 if( nInput>=pKey->n && 0==memcmp(zInput, pKey->z, pKey->n) ){
196281 if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){
196292 || cNext=='"' || cNext=='(' || cNext==')' || cNext==0
196327 int nConsumed = 0;
196331 #elif SQLITE_MAX_EXPR_DEPTH>0
196340 *ppExpr = 0;
196357 iColLen = 0;
196358 for(ii=0; ii<pParse->nCol; ii++){
196362 && sqlite3_strnicmp(zStr, zInput, nStr)==0
196442 ** bytes read from buffer z. Otherwise, *ppExpr is set to 0 and SQLITE_NOMEM
196451 Fts3Expr *pRet = 0;
196452 Fts3Expr *pPrev = 0;
196453 Fts3Expr *pNotBranch = 0; /* Only used in legacy parse mode */
196460 Fts3Expr *p = 0;
196461 int nByte = 0;
196464 assert( nByte>0 || (rc!=SQLITE_OK && p==0) );
196538 assert( pPrev && pPrev->pLeft && pPrev->pRight==0 );
196551 assert( nByte>0 );
196553 assert( rc!=SQLITE_OK || (nByte>0 && nByte<=nIn) );
196584 pRet = 0;
196597 if( nMaxDepth<0 ){
196623 Fts3Expr *pFree = 0; /* List of free nodes. Linked by pParent. */
196626 if( nMaxDepth==0 ){
196634 if( 0==apLeaf ){
196637 memset(apLeaf, 0, sizeof(Fts3Expr *) * nMaxDepth);
196646 assert( p->pParent==0 || p->pParent->pLeft==p );
196655 assert( pParent==0 || pParent->pLeft==p );
196656 p->pParent = 0;
196658 pParent->pLeft = 0;
196660 pRoot = 0;
196665 for(iLvl=0; p && iLvl<nMaxDepth; iLvl++){
196666 if( apLeaf[iLvl]==0 ){
196668 p = 0;
196678 p->pParent = 0;
196679 apLeaf[iLvl] = 0;
196689 if( pParent==0 ) break;
196695 assert( pParent->pParent==0 || pParent->pParent->pLeft==pParent );
196711 p = 0;
196712 for(i=0; i<nMaxDepth; i++){
196714 if( p==0 ){
196716 p->pParent = 0;
196718 assert( pFree!=0 );
196726 p->pParent = 0;
196736 for(i=0; i<nMaxDepth; i++){
196739 while( (pDel=pFree)!=0 ){
196745 assert( pFree==0 );
196752 pRoot->pLeft = 0;
196753 pRoot->pRight = 0;
196754 pLeft->pParent = 0;
196755 pRight->pParent = 0;
196777 pRoot = 0;
196808 memset(&sParse, 0, sizeof(ParseContext));
196815 if( z==0 ){
196816 *ppExpr = 0;
196819 if( n<0 ){
196823 assert( rc==SQLITE_OK || *ppExpr==0 );
196840 ** error) is returned and *ppExpr is set to 0.
196883 *ppExpr = 0;
196902 assert( p->eType==FTSQUERY_PHRASE || p->pPhrase==0 );
196917 assert( pDel==0 || pDel->pParent==0 );
196919 assert( p->pParent==0 || p==p->pParent->pRight || p==p->pParent->pLeft );
196956 if( pExpr==0 ){
196964 "%zPHRASE %d 0", zBuf, pPhrase->iColumn);
196965 for(i=0; zBuf && i<pPhrase->nToken; i++){
197018 sqlite3_tokenizer *pTokenizer = 0;
197020 char **azCol = 0;
197026 char *zBuf = 0;
197028 const char *zTokenizer = 0;
197029 char *zErr = 0;
197038 zTokenizer = (const char*)sqlite3_value_text(argv[0]);
197058 for(ii=0; ii<nCol; ii++){
197063 char *zDummy = 0;
197065 pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr, &zDummy
197067 assert( rc==SQLITE_OK || pExpr==0 );
197071 pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr
197077 }else if( rc==SQLITE_NOMEM || !(zBuf = exprToString(pExpr, 0)) ){
197098 fts3ExprTestCommon(0, context, argc, argv);
197114 db, "fts3_exprtest", -1, SQLITE_UTF8, (void*)pHash, fts3ExprTest, 0, 0
197118 -1, SQLITE_UTF8, (void*)pHash, fts3ExprTestRebalance, 0, 0
197169 memset(p, 0, n);
197188 assert( pNew!=0 );
197192 pNew->first = 0;
197193 pNew->count = 0;
197194 pNew->htsize = 0;
197195 pNew->ht = 0;
197205 assert( pH!=0 );
197207 pH->first = 0;
197209 pH->ht = 0;
197210 pH->htsize = 0;
197219 pH->count = 0;
197227 unsigned h = 0;
197228 if( nKey<=0 ) nKey = (int) strlen(z);
197229 while( nKey > 0 ){
197233 return (int)(h & 0x7fffffff);
197244 int h = 0;
197246 while( nKey-- > 0 ){
197249 return h & 0x7fffffff;
197310 pNew->prev = 0;
197329 assert( (new_size & (new_size-1))==0 );
197331 if( new_ht==0 ) return 1;
197336 for(elem=pH->first, pH->first=0; elem; elem = next_elem){
197341 return 0;
197364 if( (*xCompare)(elem->pKey,elem->nKey,pKey,nKey)==0 ){
197370 return 0;
197395 if( pEntry->count<=0 ){
197396 pEntry->chain = 0;
197403 if( pH->count<=0 ){
197404 assert( pH->first==0 );
197405 assert( pH->count==0 );
197418 if( pH==0 || pH->ht==0 ) return 0;
197420 assert( xHash!=0 );
197422 assert( (pH->htsize & (pH->htsize-1))==0 );
197435 return pElem ? pElem->data : 0;
197465 assert( pH!=0 );
197467 assert( xHash!=0 );
197469 assert( (pH->htsize & (pH->htsize-1))==0 );
197474 if( data==0 ){
197481 if( data==0 ) return 0;
197482 if( (pH->htsize==0 && fts3Rehash(pH,8))
197485 pH->count = 0;
197488 assert( pH->htsize>0 );
197490 if( new_elem==0 ) return data;
197491 if( pH->copyKey && pKey!=0 ){
197493 if( new_elem->pKey==0 ){
197503 assert( pH->htsize>0 );
197504 assert( (pH->htsize & (pH->htsize-1))==0 );
197508 return 0;
197584 memset(t, 0, sizeof(*t));
197599 ** string to be tokenized is zInput[0..nInput-1]. A cursor
197616 if( zInput==0 ){
197617 c->nInput = 0;
197618 }else if( nInput<0 ){
197623 c->iOffset = 0; /* start tokenizing at the beginning */
197624 c->iToken = 0;
197626 c->nAllocated = 0;
197646 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0,
197667 if( x==0 ) return 0;
197671 return z[1]==0 || isVowel(z + 1);
197676 if( x==0 ) return 0;
197704 if( *z==0 ) return 0;
197706 return *z!=0;
197714 if( *z==0 ) return 0;
197716 if( *z==0 ) return 0;
197718 if( *z==0 ) return 1;
197720 return *z==0;
197724 ** or m>0
197728 if( *z==0 ) return 0;
197730 if( *z==0 ) return 0;
197732 if( *z==0 ) return 0;
197734 return *z!=0;
197738 ** Return TRUE if there is a vowel anywhere within z[0..n-1]
197742 return *z!=0;
197752 return isConsonant(z) && z[0]==z[1];
197766 z[0]!='w' && z[0]!='x' && z[0]!='y' &&
197791 if( *zFrom!=0 ) return 0;
197810 int hasDigit = 0;
197811 for(i=0; i<nIn; i++){
197816 if( c>='0' && c<='9' ) hasDigit = 1;
197827 zOut[i] = 0;
197833 ** Stem the input word zIn[0..nIn-1]. Store the output in zOut.
197835 ** size of the output word (exclusive of the '\0' terminator) into *pnOut.
197865 for(i=0, j=sizeof(zReverse)-6; i<nIn; i++, j--){
197878 memset(&zReverse[sizeof(zReverse)-5], 0, 5);
197883 if( z[0]=='s' ){
197885 !stem(&z, "sess", "ss", 0) &&
197886 !stem(&z, "sei", "i", 0) &&
197887 !stem(&z, "ss", "ss", 0)
197901 if( stem(&z, "ta", "ate", 0) ||
197902 stem(&z, "lb", "ble", 0) ||
197903 stem(&z, "zi", "ize", 0) ){
197913 if( z[0]=='y' && hasVowel(z+1) ){
197914 z[0] = 'i';
197969 switch( z[0] ){
197993 if( z[0]=='l' && m_gt_1(z+2) ){
197998 if( z[0]=='e' && z[2]=='n' && (z[3]=='a' || z[3]=='e') && m_gt_1(z+4) ){
198003 if( z[0]=='r' && m_gt_1(z+2) ){
198008 if( z[0]=='c' && m_gt_1(z+2) ){
198013 if( z[0]=='e' && z[2]=='b' && (z[3]=='a' || z[3]=='i') && m_gt_1(z+4) ){
198018 if( z[0]=='t' ){
198033 if( z[0]=='u' ){
198042 if( z[0]=='m' && z[2]=='i' && m_gt_1(z+3) ){
198052 if( z[0]=='s' && z[2]=='o' && m_gt_1(z+3) ){
198058 if( z[0]=='e' && z[2]=='i' && m_gt_1(z+3) ){
198065 if( z[0]=='e' ){
198074 if( m_gt_1(z) && z[0]=='l' && z[1]=='l' ){
198082 zOut[i] = 0;
198090 ** whose value is greater than 0x80 (any UTF character) can be
198092 ** values of 0x7f or lower.
198096 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
198097 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
198098 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */
198099 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
198100 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
198102 #define isDelim(C) (((ch=C)&0x80)==0 && (ch<0x30 || !porterIdChar[ch-0x30]))
198157 0,
198163 0
198214 ** SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, 1, 0);
198218 int isEnabled = 0;
198249 void *pPtr = 0;
198257 zName = sqlite3_value_text(argv[0]);
198258 nName = sqlite3_value_bytes(argv[0])+1;
198264 if( zName==0 || n!=sizeof(pPtr) ){
198288 if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[0]) ){
198295 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
198296 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
198297 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
198298 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
198299 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
198300 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */
198301 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
198302 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
198304 return (c&0x80 || isFtsIdChar[(int)(c)]);
198309 const char *z2 = 0;
198313 while( z2==0 ){
198316 case '\0': return 0; /* No more tokens here */
198326 while( *z2 && z2[0]!=']' ) z2++;
198352 int n = 0;
198362 if( z==0 ){
198363 assert( n==0 );
198366 z[n] = '\0';
198374 char const **aArg = 0;
198375 int iArg = 0;
198387 z[n] = '\0';
198433 ** "{0 i I 1 dont don't 2 see see 3 how how}"
198443 sqlite3_tokenizer *pTokenizer = 0;
198444 sqlite3_tokenizer_cursor *pCsr = 0;
198446 const char *zErr = 0;
198456 int nToken = 0;
198457 int iStart = 0;
198458 int iEnd = 0;
198459 int iPos = 0;
198469 nName = sqlite3_value_bytes(argv[0]);
198470 zName = (const char *)sqlite3_value_text(argv[0]);
198496 if( sqlite3Fts3OpenTokenizer(pTokenizer, 0, zInput, nInput, &pCsr) ){
198502 Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(iPos));
198503 Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zToken, nToken));
198506 Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zToken, nToken));
198537 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
198560 *pp = 0;
198561 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
198568 if( sqlite3_column_type(pStmt, 0)==SQLITE_BLOB
198569 && sqlite3_column_bytes(pStmt, 0)==sizeof(*pp)
198571 memcpy((void *)pp, sqlite3_column_blob(pStmt, 0), sizeof(*pp));
198618 assert( p2==0 );
198619 assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") );
198662 char *zTest = 0;
198663 char *zTest2 = 0;
198673 rc = sqlite3_create_function(db, zName, 1, any, p, fts3TokenizerFunc, 0, 0);
198676 rc = sqlite3_create_function(db, zName, 2, any, p, fts3TokenizerFunc, 0, 0);
198680 rc = sqlite3_create_function(db, zTest, -1, any, p, testFunc, 0, 0);
198683 rc = sqlite3_create_function(db, zTest2, 0, any, pdb, intTestFunc, 0, 0);
198750 return c<0x80 && t->delim[c];
198753 return (x>='0' && x<='9') || (x>='A' && x<='Z') || (x>='a' && x<='z');
198767 memset(t, 0, sizeof(*t));
198776 for(i=0; i<n; i++){
198779 if( ch>=0x80 ){
198788 for(i=1; i<0x80; i++){
198789 t->delim[i] = !fts3_isalnum(i) ? -1 : 0;
198807 ** string to be tokenized is pInput[0..nBytes-1]. A cursor
198824 if( pInput==0 ){
198825 c->nBytes = 0;
198826 }else if( nBytes<0 ){
198831 c->iOffset = 0; /* start tokenizing at the beginning */
198832 c->iToken = 0;
198834 c->nTokenAllocated = 0;
198890 for(i=0; i<n; i++){
198913 0,
198919 0,
199049 if( argc==0 ){
199050 *pazDequote = 0;
199053 int nByte = 0;
199056 for(i=0; i<argc; i++){
199061 if( azDequote==0 ){
199065 for(i=0; i<argc; i++){
199088 ** argv[0]: module name
199101 Fts3tokTable *pTab = 0;
199102 const sqlite3_tokenizer_module *pMod = 0;
199103 sqlite3_tokenizer *pTok = 0;
199105 char **azDequote = 0;
199119 zModule = azDequote[0];
199124 assert( (rc==SQLITE_OK)==(pMod!=0) );
199126 const char * const *azArg = 0;
199128 rc = pMod->xCreate((nDequote>1 ? nDequote-1 : 0), azArg, &pTok);
199133 if( pTab==0 ){
199139 memset(pTab, 0, sizeof(Fts3tokTable));
199176 for(i=0; i<pInfo->nConstraint; i++){
199178 && pInfo->aConstraint[i].iColumn==0
199189 pInfo->idxNum = 0;
199203 if( pCsr==0 ){
199206 memset(pCsr, 0, sizeof(Fts3tokCursor));
199220 pCsr->pCsr = 0;
199223 pCsr->zInput = 0;
199224 pCsr->zToken = 0;
199225 pCsr->nToken = 0;
199226 pCsr->iStart = 0;
199227 pCsr->iEnd = 0;
199228 pCsr->iPos = 0;
199229 pCsr->iRowid = 0;
199283 const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
199284 sqlite3_int64 nByte = sqlite3_value_bytes(apVal[0]);
199286 if( pCsr->zInput==0 ){
199289 if( nByte>0 ) memcpy(pCsr->zInput, zByte, nByte);
199290 pCsr->zInput[nByte] = 0;
199307 return (pCsr->zToken==0);
199322 case 0:
199360 0, /* iVersion */
199373 0, /* xUpdate */
199374 0, /* xBegin */
199375 0, /* xSync */
199376 0, /* xCommit */
199377 0, /* xRollback */
199378 0, /* xFindFunction */
199379 0, /* xRename */
199380 0, /* xSavepoint */
199381 0, /* xRelease */
199382 0, /* xRollbackTo */
199383 0, /* xShadowName */
199384 0 /* xIntegrity */
199470 #define FTS_STAT_DOCTOTAL 0
199535 int iIdx; /* Index within level, or 0x7FFFFFFF for PT */
199541 sqlite3_int64 iEndBlock; /* Rowid of final block in segment (or 0) */
199542 sqlite3_int64 iCurrentBlock; /* Current leaf block (or 0) */
199545 int nNode; /* Size of buffer at aNode (or 0) */
199546 int nPopulate; /* If >0, bytes of buffer aNode[] loaded */
199570 #define fts3SegReaderIsPending(p) ((p)->ppNextElem!=0)
199571 #define fts3SegReaderIsRootOnly(p) ((p)->rootOnly!=0)
199630 #define SQL_DELETE_CONTENT 0
199677 ** Otherwise, an SQLite error code is returned and *pp is set to 0.
199691 /* 0 */ "DELETE FROM %Q.'%q_content' WHERE rowid = ?",
199794 assert( eStmt<SizeofArray(azSql) && eStmt>=0 );
199813 assert( rc==SQLITE_OK || pStmt==0 );
199820 for(i=0; rc==SQLITE_OK && i<nParam; i++){
199834 sqlite3_stmt *pStmt = 0; /* Statement requested from fts3SqlStmt() */
199837 rc = fts3SqlStmt(pTab, SQL_SELECT_DOCSIZE, &pStmt, 0);
199841 if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){
199844 pStmt = 0;
199858 sqlite3_stmt *pStmt = 0;
199860 rc = fts3SqlStmt(pTab, SQL_SELECT_STAT, &pStmt, 0);
199864 || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB
199868 pStmt = 0;
199926 if( p->nPendingData==0 ){
199928 rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_LEVEL, &pStmt, 0);
199954 ** for language-id 0 is allocate values 0-1023. The first prefix index
199955 ** (if any) for language-id 0 is allocated values 1024-2047. And so on.
199956 ** Language 1 indexes are allocated immediately following language 0.
199969 assert_fts3_nc( iLangid>=0 );
199970 assert( p->nIndex>0 );
199971 assert( iIndex>=0 && iIndex<p->nIndex );
199988 ** 0: idx
200002 sqlite3_stmt *pStmt = 0;
200004 assert( iLevel==FTS3_SEGCURSOR_ALL || iLevel>=0 );
200006 assert( iIndex>=0 && iIndex<p->nIndex );
200008 if( iLevel<0 ){
200010 rc = fts3SqlStmt(p, SQL_SELECT_LEVEL_RANGE, &pStmt, 0);
200012 sqlite3_bind_int64(pStmt, 1, getAbsoluteLevel(p, iLangid, iIndex, 0));
200019 rc = fts3SqlStmt(p, SQL_SELECT_LEVEL, &pStmt, 0);
200037 ** PendingList *p = 0;
200055 p->nData = 0;
200062 *pp = 0;
200071 p->aData[p->nData] = '\0';
200098 u64 iDelta = (u64)iDocid - (u64)(p ? p->iLastDocid : 0);
200101 assert( p->aData[p->nData]==0 );
200108 p->iLastPos = 0;
200111 if( iCol>0 && p->iLastCol!=iCol ){
200118 p->iLastPos = 0;
200120 if( iCol>=0 ){
200121 assert( iPos>p->iLastPos || (iPos==0 && p->iLastPos==0) );
200134 return 0;
200167 assert( 0==fts3HashFind(pHash, zToken, nToken) );
200193 int iStart = 0;
200194 int iEnd = 0;
200195 int iPos = 0;
200196 int nWord = 0;
200199 int nToken = 0;
200210 ** zText==0. In this case, add zero token entries to the hash table and
200212 if( zText==0 ){
200213 *pnWord = 0;
200232 if( iPos<0 || !zToken || nToken<=0 ){
200239 p, iCol, iPos, &p->aIndex[0].hPending, zToken, nToken
200269 assert( iLangid>=0 );
200270 assert( bDelete==1 || bDelete==0 );
200279 || (iDocid==p->iPrevDocid && p->bPrevDelete==0)
200297 for(i=0; i<p->nIndex; i++){
200306 p->nPendingData = 0;
200326 if( p->abNotindexed[iCol]==0 ){
200343 ** apVal[0] Not used for INSERT.
200400 if( SQLITE_NULL==sqlite3_value_type(apVal[0])
200434 assert( p->zContentTbl==0 || bContent==0 );
200435 if( bContent ) fts3SqlExec(&rc, p, SQL_DELETE_ALL_CONTENT, 0);
200436 fts3SqlExec(&rc, p, SQL_DELETE_ALL_SEGMENTS, 0);
200437 fts3SqlExec(&rc, p, SQL_DELETE_ALL_SEGDIR, 0);
200439 fts3SqlExec(&rc, p, SQL_DELETE_ALL_DOCSIZE, 0);
200442 fts3SqlExec(&rc, p, SQL_DELETE_ALL_STAT, 0);
200451 int iLangid = 0;
200471 assert( *pbFound==0 );
200478 i64 iDocid = sqlite3_column_int64(pSelect, 0);
200482 if( p->abNotindexed[iCol]==0 ){
200511 ** with 0, so the allocated index is one greater than the value returned
200518 ** allocated index is 0.
200532 int iNext = 0; /* Result of query pNextIdx */
200534 assert( iLangid>=0 );
200538 rc = fts3SqlStmt(p, SQL_NEXT_SEGMENT_INDEX, &pNextIdx, 0);
200544 iNext = sqlite3_column_int(pNextIdx, 0);
200552 ** segment and allocate (newly freed) index 0 at level iLevel. Otherwise,
200558 *piIdx = 0;
200609 if( 0==p->zSegmentsTbl ){
200611 if( 0==p->zSegmentsTbl ) return SQLITE_NOMEM;
200614 p->db, p->zDb, p->zSegmentsTbl, "block", iBlockid, 0, &p->pSegments
200630 rc = sqlite3_blob_read(p->pSegments, aByte, nByte, 0);
200631 memset(&aByte[nByte], 0, FTS3_NODE_PADDING);
200634 aByte = 0;
200652 p->pSegments = 0;
200669 memset(&pReader->aNode[pReader->nPopulate], 0, FTS3_NODE_PADDING);
200672 pReader->pBlob = 0;
200673 pReader->nPopulate = 0;
200699 pSeg->pBlob = 0;
200701 pSeg->aNode = 0;
200730 pReader->aNode = 0;
200744 pReader->zTerm[nTerm] = '\0';
200771 (bIncr ? &pReader->nPopulate : 0)
200774 assert( pReader->pBlob==0 );
200777 p->pSegments = 0;
200791 if( nSuffix<=0
200799 ** between 0 and 0x7FFFFFFF. But the sum of the two may cause integer
200819 pReader->pOffsetList = 0;
200822 ** b-tree node. And that the final byte of the doclist is 0x00. If either
200826 || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1])
200827 || pReader->nDoclist==0
200843 u8 bEof = 0;
200844 pReader->iDocid = 0;
200845 pReader->nOffsetList = 0;
200846 sqlite3Fts3DoclistPrev(0,
200878 char c = 0;
200886 u8 bEof = 0;
200891 sqlite3Fts3DoclistPrev(0,
200896 pReader->pOffsetList = 0;
200914 while( *p | c ) c = *p++ & 0x80;
200915 assert( *p==0 );
200917 if( pReader->pBlob==0 || p<&pReader->aNode[pReader->nPopulate] ) break;
200932 while( p<pEnd && *p==0 ) p++;
200940 pReader->pOffsetList = 0;
200965 int nOvfl = 0;
200971 assert( pgsz>0 );
200973 for(ii=0; rc==SQLITE_OK && ii<pMsr->nSegment; ii++){
200981 rc = sqlite3Fts3ReadBlock(p, jj, 0, &nBlob, 0);
201022 int nExtra = 0; /* Bytes to allocate segment root node */
201024 assert( zRoot!=0 || nRoot==0 );
201026 assert( zRoot!=0 || CORRUPT_DB );
201029 if( iStartLeaf==0 ){
201030 if( iEndLeaf!=0 ) return FTS_CORRUPT_VTAB;
201038 memset(pReader, 0, sizeof(Fts3SegReader));
201040 pReader->bLookup = bLookup!=0;
201051 memset(&pReader->aNode[nRoot], 0, FTS3_NODE_PADDING);
201075 if( c==0 ){
201108 Fts3SegReader *pReader = 0; /* Fts3SegReader object to return */
201110 Fts3HashElem **aElem = 0; /* Array of term hash entries to scan */
201111 int nElem = 0; /* Size of array at aElem */
201117 int nAlloc = 0; /* Size of allocated array at aElem */
201122 if( nTerm==0 || (nKey>=nTerm && 0==memcmp(zKey, zTerm, nTerm)) ){
201131 nElem = 0;
201164 if( nElem>0 ){
201171 memset(pReader, 0, nByte);
201172 pReader->iIdx = 0x7FFFFFFF;
201201 if( rc2<0 ){
201206 if( rc==0 ){
201210 rc = (pLhs->aNode==0) - (pRhs->aNode==0);
201212 if( rc==0 ){
201215 assert_fts3_nc( rc!=0 );
201231 int rc = (pLhs->pOffsetList==0)-(pRhs->pOffsetList==0);
201232 if( rc==0 ){
201243 int rc = (pLhs->pOffsetList==0)-(pRhs->pOffsetList==0);
201244 if( rc==0 ){
201259 ** If the pSeg iterator is already at EOF, return 0. Otherwise, return
201260 ** -ve if the pSeg term is less than zTerm/nTerm, 0 if the two terms are
201268 int res = 0;
201275 if( res==0 ){
201299 for(i=nSuspect-1; i>=0; i--){
201303 if( xCmp(apSegment[j], apSegment[j+1])<0 ) break;
201312 for(i=0; i<(nSuspect-1); i++){
201313 assert( xCmp(apSegment[i], apSegment[i+1])<0 );
201328 int rc = fts3SqlStmt(p, SQL_INSERT_SEGMENTS, &pStmt, 0);
201346 int mxLevel = 0;
201347 sqlite3_stmt *pStmt = 0;
201349 rc = fts3SqlStmt(p, SQL_SELECT_MXLEVEL, &pStmt, 0);
201352 mxLevel = sqlite3_column_int(pStmt, 0);
201375 int rc = fts3SqlStmt(p, SQL_INSERT_SEGDIR, &pStmt, 0);
201381 if( nLeafData==0 ){
201402 ** fts3PrefixCompress("abX", 3, "Xbcdef", 6) // returns 0
201411 for(n=0; n<nPrev && n<nNext && zPrev[n]==zNext[n]; n++);
201446 if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
201508 memset(pNew, 0, sizeof(SegmentNode));
201515 if( pTree->pParent==0 ){
201523 pTree->zMalloc = 0;
201615 assert( pRight==0 || p->zMalloc==0 );
201653 memset(pWriter, 0, sizeof(SegmentWriter));
201662 rc = fts3SqlStmt(p, SQL_NEXT_SEGMENTS_ID, &pStmt, 0);
201665 pWriter->iFree = sqlite3_column_int64(pStmt, 0);
201679 if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
201688 if( nData>0 && nData+nReq>p->nNodeSize ){
201713 nData = 0;
201714 pWriter->nTerm = 0;
201716 nPrefix = 0;
201742 assert( nSuffix>0 );
201746 assert( nDoclist>0 );
201766 assert( nTerm>0 );
201790 sqlite3_int64 iLast = 0; /* Largest block id written to database */
201793 int nRoot = 0; /* Size of buffer zRoot */
201808 0, 0, 0, pWriter->nLeafData, pWriter->aData, pWriter->nData);
201842 *pisEmpty = 0;
201848 *pisEmpty = sqlite3_column_int(pStmt, 0);
201872 assert( iIndex>=0 && iIndex<p->nIndex );
201880 rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR_MAX_LEVEL, &pStmt, 0);
201882 sqlite3_bind_int64(pStmt, 1, getAbsoluteLevel(p, iLangid, iIndex, 0));
201887 *pnMax = sqlite3_column_int64(pStmt, 0);
201896 ** iAbsLevel is indeed the largest level, or 0 otherwise, and SQLITE_OK
201909 int rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR_MAX_LEVEL, &pStmt, 0);
201916 *pbMax = 0;
201918 *pbMax = sqlite3_column_type(pStmt, 0)==SQLITE_NULL;
201935 rc = fts3SqlStmt(p, SQL_DELETE_SEGMENTS_RANGE, &pDelete, 0);
201956 ** entries regardless of level if (iLevel<0).
201970 sqlite3_stmt *pDelete = 0; /* SQL statement to delete rows */
201972 for(i=0; rc==SQLITE_OK && i<nReader; i++){
201979 assert( iLevel>=0 || iLevel==FTS3_SEGCURSOR_ALL );
201981 rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_RANGE, &pDelete, 0);
201983 sqlite3_bind_int64(pDelete, 1, getAbsoluteLevel(p, iLangid, iIndex, 0));
201989 rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_LEVEL, &pDelete, 0);
202026 int iCurrent = 0;
202029 assert( iCol>=0 );
202031 char c = 0;
202032 while( p<pEnd && (c | *p)&0xFE ) c = *p++ & 0x80;
202041 if( nList<=0 ){
202048 if( bZero && (pEnd - &pList[nList])>0){
202049 memset(&pList[nList], 0, pEnd - &pList[nList]);
202076 assert( nList>0 );
202078 memset(&pMsr->aBuffer[nList], 0, FTS3_NODE_PADDING);
202095 if( nMerge==0 ){
202096 *paPoslist = 0;
202102 pSeg = pMsr->apSegment[0];
202104 if( pSeg->pOffsetList==0 ){
202105 *paPoslist = 0;
202112 sqlite3_int64 iDocid = apSegment[0]->iDocid;
202114 rc = fts3SegReaderNextDocid(p, apSegment[0], &pList, &nList);
202121 rc = fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
202127 if( nList>0 && fts3SegReaderIsPending(apSegment[0]) ){
202130 assert( (pMsr->aBuffer[nList] & 0xFE)==0x00 );
202134 if( pMsr->iColFilter>=0 ){
202138 if( nList>0 ){
202165 for(i=0; pCsr->bRestart==0 && i<pCsr->nSegment; i++){
202166 int res = 0;
202169 int rc = fts3SegReaderNext(p, pSeg, 0);
202171 }while( zTerm && (res = fts3SegReaderTermCmp(pSeg, zTerm, nTerm))<0 );
202173 if( pSeg->bLookup && res!=0 ){
202205 assert( pCsr->pFilter==0 );
202206 assert( zTerm && nTerm>0 );
202213 for(i=0; i<nSegment; i++){
202222 for(i=0; i<pCsr->nAdvance; i++){
202228 assert( iCol<0 || iCol<p->nColumn );
202249 assert( pCsr->zTerm==0 );
202250 assert( pCsr->nTerm==0 );
202251 assert( pCsr->aDoclist==0 );
202252 assert( pCsr->nDoclist==0 );
202254 pCsr->nAdvance = 0;
202256 for(i=0; i<pCsr->nSegment; i++){
202257 pCsr->apSegment[i]->pOffsetList = 0;
202258 pCsr->apSegment[i]->nOffsetList = 0;
202259 pCsr->apSegment[i]->iDocid = 0;
202299 if( pCsr->nSegment==0 ) return SQLITE_OK;
202308 for(i=0; i<pCsr->nAdvance; i++){
202313 rc = fts3SegReaderNext(p, pSeg, 0);
202318 pCsr->nAdvance = 0;
202322 if( apSegment[0]->aNode==0 ) break;
202324 pCsr->nTerm = apSegment[0]->nTerm;
202325 pCsr->zTerm = apSegment[0]->zTerm;
202327 /* If this is a prefix-search, and if the term that apSegment[0] points
202332 ** of segment apSegment[0] is not a match, exit early.
202347 && 0==memcmp(pCsr->zTerm, apSegment[nMerge]->zTerm, pCsr->nTerm)
202356 && (p->bDescIdx==0 || fts3SegReaderIsPending(apSegment[0])==0)
202358 pCsr->nDoclist = apSegment[0]->nDoclist;
202359 if( fts3SegReaderIsPending(apSegment[0]) ){
202360 rc = fts3MsrBufferData(pCsr, apSegment[0]->aDoclist,
202364 pCsr->aDoclist = apSegment[0]->aDoclist;
202368 int nDoclist = 0; /* Size of doclist */
202369 sqlite3_int64 iPrev = 0; /* Previous docid stored in doclist */
202375 for(i=0; i<nMerge; i++){
202379 while( apSegment[0]->pOffsetList ){
202381 char *pList = 0;
202382 int nList = 0;
202384 sqlite3_int64 iDocid = apSegment[0]->iDocid;
202385 fts3SegReaderNextDocid(p, apSegment[0], &pList, &nList);
202391 fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
202396 fts3ColumnFilter(pFilter->iCol, 0, &pList, &nList);
202399 if( !isIgnoreEmpty || nList>0 ){
202404 if( p->bDescIdx && nDoclist>0 ){
202408 if( nDoclist>0 && iPrev>=iDocid ) return FTS_CORRUPT_VTAB;
202412 nByte = sqlite3Fts3VarintLen(iDelta) + (isRequirePos?nList+1:0);
202433 pCsr->aBuffer[nDoclist++] = '\0';
202440 if( nDoclist>0 ){
202443 memset(&pCsr->aBuffer[nDoclist], 0, FTS3_NODE_PADDING);
202461 for(i=0; i<pCsr->nSegment; i++){
202467 pCsr->nSegment = 0;
202468 pCsr->apSegment = 0;
202469 pCsr->aBuffer = 0;
202479 ** by one or more space (0x20) characters. In the first case, set *piEndBlock
202493 u64 iVal = 0;
202494 for(i=0; zText[i]>='0' && zText[i]<='9'; i++){
202495 iVal = iVal*10 + (zText[i] - '0');
202499 iVal = 0;
202504 for(/* no-op */; zText[i]>='0' && zText[i]<='9'; i++){
202505 iVal = iVal*10 + (zText[i] - '0');
202524 rc = fts3SqlStmt(p, SQL_SELECT_LEVEL_RANGE2, &pRange, 0);
202527 int bOk = 0;
202539 i64 nSize = 0, dummy;
202541 if( nSize<=0 || nSize>nLimit ){
202542 /* If nSize==0, then the %_segdir.end_block field does not not
202547 bOk = 0;
202555 int iIdx = 0;
202556 sqlite3_stmt *pUpdate1 = 0;
202557 sqlite3_stmt *pUpdate2 = 0;
202560 rc = fts3SqlStmt(p, SQL_UPDATE_LEVEL_IDX, &pUpdate1, 0);
202563 rc = fts3SqlStmt(p, SQL_UPDATE_LEVEL, &pUpdate2, 0);
202570 ** updated it to set (level = -1) and (idx = N), where N is 0 for the
202580 sqlite3_bind_int(pUpdate1, 2, sqlite3_column_int(pRange, 0));
202609 ** iLevel+1 segment. Or, if iLevel<0, merge all segments into a
202613 ** If this function is called with iLevel<0, but there is only one
202625 int iIdx = 0; /* Index of new segment */
202626 sqlite3_int64 iNewLevel = 0; /* Level/index to create new segment at */
202627 SegmentWriter *pWriter = 0; /* Used to write the new, merged, segment */
202630 int bIgnoreEmpty = 0; /* True to ignore empty segments */
202631 i64 iMaxLevel = 0; /* Max level number for this index/langid */
202635 || iLevel>=0
202638 assert( iIndex>=0 && iIndex<p->nIndex );
202640 rc = sqlite3Fts3SegReaderCursor(p, iLangid, iIndex, iLevel, 0, 0, 1, 0, &csr);
202641 if( rc!=SQLITE_OK || csr.nSegment==0 ) goto finished;
202652 ** index. The idx of the new segment is always 0. */
202653 if( csr.nSegment==1 && 0==fts3SegReaderIsPending(csr.apSegment[0]) ){
202672 assert( csr.nSegment>0 );
202673 assert_fts3_nc( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
202678 memset(&filter, 0, sizeof(Fts3SegFilter));
202680 filter.flags |= (bIgnoreEmpty ? FTS3_SEGMENT_IGNORE_EMPTY : 0);
202715 ** Flush the contents of pendingTerms to level 0 segments.
202721 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
202730 && p->nAutoincrmerge==0xff && p->nLeafAdd>0
202732 sqlite3_stmt *pStmt = 0;
202733 rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pStmt, 0);
202738 p->nAutoincrmerge = sqlite3_column_int(pStmt, 0);
202741 p->nAutoincrmerge = 0;
202763 for(i=j=0; i<N; i++){
202778 int i = 0;
202779 if( nBuf && (zBuf[nBuf-1]&0x80)==0 ){
202781 for(i=j=0; i<N && j<nBuf; i++){
202784 a[i] = (u32)(x & 0xffffffff);
202787 while( i<N ) a[i++] = 0;
202807 if( pBlob==0 ){
202812 rc = fts3SqlStmt(p, SQL_REPLACE_DOCSIZE, &pStmt, 0);
202825 ** Record 0 of the %_stat table contains a blob consisting of N varints,
202830 ** Varint 0: Total number of rows in the table.
202857 if( a==0 ){
202862 rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pStmt, 0);
202871 sqlite3_column_blob(pStmt, 0),
202872 sqlite3_column_bytes(pStmt, 0));
202874 memset(a, 0, sizeof(u32)*(nStat) );
202882 if( nChng<0 && a[0]<(u32)(-nChng) ){
202883 a[0] = 0;
202885 a[0] += nChng;
202887 for(i=0; i<p->nColumn+1; i++){
202890 x = 0;
202897 rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0);
202916 int bSeenDone = 0;
202918 sqlite3_stmt *pAllLangid = 0;
202922 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
202930 int iLangid = sqlite3_column_int(pAllLangid, 0);
202931 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
202961 rc = fts3DeleteAll(p, 0);
202963 u32 *aSz = 0;
202964 u32 *aSzIns = 0;
202965 u32 *aSzDel = 0;
202966 sqlite3_stmt *pStmt = 0;
202967 int nEntry = 0;
202974 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
202981 if( aSz==0 ){
202984 memset(aSz, 0, nByte);
202993 rc = fts3PendingTermsDocid(p, 0, iLangid, sqlite3_column_int64(pStmt, 0));
202994 memset(aSz, 0, sizeof(aSz[0]) * (p->nColumn+1));
202995 for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
202996 if( p->abNotindexed[iCol]==0 ){
203007 pStmt = 0;
203010 for(iCol=0; iCol<=p->nColumn; iCol++){
203035 ** the oldest nSeg segments (idx=0 through idx=(nSeg-1)) in absolute
203045 sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */
203049 memset(pCsr, 0, sizeof(*pCsr));
203053 if( pCsr->apSegment==0 ){
203056 memset(pCsr->apSegment, 0, nByte);
203057 rc = fts3SqlStmt(p, SQL_SELECT_LEVEL, &pStmt, 0);
203063 assert( pCsr->nSegment==0 );
203064 for(i=0; rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW && i<nSeg; i++){
203065 rc = sqlite3Fts3SegReaderNew(i, 0,
203121 u8 bNoLeafData; /* If true, store 0 for segment size */
203178 int bFirst = (p->term.n==0); /* True for first term on the node */
203179 int nPrefix = 0; /* Bytes to copy from previous term */
203180 int nSuffix = 0; /* Bytes to append to the prefix */
203184 if( p->iChild && bFirst==0 ) p->iChild++;
203187 p->aNode = 0;
203189 if( bFirst==0 ){
203194 if( nPrefix>p->term.n || nSuffix>p->nNode-p->iOff || nSuffix==0 ){
203198 if( rc==SQLITE_OK && ALWAYS(p->term.a!=0) ){
203202 if( p->iChild==0 ){
203232 memset(p, 0, sizeof(NodeReader));
203237 if( aNode && aNode[0] ){
203255 ** (pWriter->aNodeWriter[0].iBlock) when this function is called.
203263 sqlite3_int64 iPtr = pWriter->aNodeWriter[0].iBlock;
203266 assert( nTerm>0 );
203268 sqlite3_int64 iNextPtr = 0;
203281 if(nSuffix<=0 ) return FTS_CORRUPT_VTAB;
203285 if( pNode->key.n==0 || (pNode->block.n + nSpace)<=p->nNodeSize ){
203291 if( pBlk->n==0 ){
203294 pBlk->a[0] = (char)iLayer;
203307 assert( nPrefix>=0 );
203321 pNode->block.a[0] = (char)iLayer;
203326 pNode->key.n = 0;
203329 if( rc!=SQLITE_OK || iNextPtr==0 ) return rc;
203333 assert( 0 );
203334 return 0;
203342 ** A node header is a single 0x00 byte for a leaf node, or a height varint
203347 ** node, both aDoclist and nDoclist must be passed 0.
203370 int bFirst = (pPrev->n==0); /* True if this is the first term written */
203376 assert( pNode->n>0 );
203377 assert_fts3_nc( (pNode->a[0]=='\0')==(aDoclist!=0) );
203381 assert( pPrev!=0 );
203382 assert( pPrev->a!=0 );
203386 if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
203390 if( bFirst==0 ){
203429 pLeaf = &pWriter->aNodeWriter[0];
203432 if(nSuffix<=0 ) return FTS_CORRUPT_VTAB;
203442 if( pLeaf->block.n>0
203467 pLeaf->key.n = 0;
203468 pLeaf->block.n = 0;
203479 if( pLeaf->block.n==0 ){
203481 pLeaf->block.a[0] = '\0';
203516 ** will be set to 0. If the root node is the parent of the leaves, iRoot
203518 for(iRoot=FTS_MAX_APPENDABLE_HEIGHT-1; iRoot>=0; iRoot--){
203520 if( pNode->block.n>0 ) break;
203521 assert( *pRc || pNode->block.nAlloc==0 );
203522 assert( *pRc || pNode->key.nAlloc==0 );
203528 if( iRoot<0 ) return;
203536 ** segments that fit entirely on the root node with start_block!=0.
203545 if( iRoot==0 ){
203549 pBlock->a[0] = 0x01;
203551 &pBlock->a[1], pWriter->aNodeWriter[0].iBlock
203559 for(i=0; i<iRoot; i++){
203561 if( pNode->block.n>0 && rc==SQLITE_OK ){
203574 pWriter->aNodeWriter[0].iBlock, /* leaves_end_block */
203576 (pWriter->bNoLeafData==0 ? pWriter->nLeafData : 0), /* end_block */
203591 ** Return -ve if zLhs is smaller than zRhs, 0 if it is equal, or +ve
203604 res = 0;
203606 if( res==0 ) res = nLhs - nRhs;
203615 ** returning. Otherwise, set *pbRes to 0.
203625 int bRes = 0; /* Result to set *pbRes to */
203626 sqlite3_stmt *pCheck = 0; /* Statement to query database with */
203629 rc = fts3SqlStmt(p, SQL_SEGMENT_IS_APPENDABLE, &pCheck, 0);
203664 sqlite3_stmt *pSelect = 0; /* SELECT to read %_segdir entry */
203666 rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR, &pSelect, 0);
203668 sqlite3_int64 iStart = 0; /* Value of %_segdir.start_block */
203669 sqlite3_int64 iLeafEnd = 0; /* Value of %_segdir.leaves_end_block */
203670 sqlite3_int64 iEnd = 0; /* Value of %_segdir.end_block */
203671 const char *aRoot = 0; /* Pointer to %_segdir.root buffer */
203672 int nRoot = 0; /* Size of aRoot[] in bytes */
203674 int bAppendable = 0; /* Set to true if segment is appendable */
203683 if( pWriter->nLeafData<0 ){
203686 pWriter->bNoLeafData = (pWriter->nLeafData==0);
203689 if( aRoot==0 ){
203702 char *aLeaf = 0;
203703 int nLeaf = 0;
203705 rc = sqlite3Fts3ReadBlock(p, iLeafEnd, &aLeaf, &nLeaf, 0);
203714 if( fts3TermCmp(zKey, nKey, reader.term.a, reader.term.n)<=0 ){
203715 bAppendable = 0;
203726 int nHeight = (int)aRoot[0];
203751 memset(&pNode->block.a[nRoot], 0, FTS3_NODE_PADDING);
203754 for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){
203756 memset(&reader, 0, sizeof(reader));
203764 assert_fts3_nc( reader.term.n>0 || reader.aNode==0 );
203765 if( reader.term.n>0 ){
203769 if( i>0 ){
203770 char *aBlock = 0;
203771 int nBlock = 0;
203774 rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock,0);
203781 memset(&pNode->block.a[nBlock], 0, FTS3_NODE_PADDING);
203813 sqlite3_stmt *pOutputIdx = 0; /* SQL used to find output index */
203815 rc = fts3SqlStmt(p, SQL_NEXT_SEGMENT_INDEX, &pOutputIdx, 0);
203819 *piIdx = sqlite3_column_int(pOutputIdx, 0);
203861 int nLeafEst = 0; /* Blocks allocated for leaf nodes */
203862 sqlite3_stmt *pLeafEst = 0; /* SQL used to determine nLeafEst */
203863 sqlite3_stmt *pFirstBlock = 0; /* SQL used to determine first block */
203866 rc = fts3SqlStmt(p, SQL_MAX_LEAF_NODE_ESTIMATE, &pLeafEst, 0);
203871 nLeafEst = sqlite3_column_int(pLeafEst, 0);
203878 rc = fts3SqlStmt(p, SQL_NEXT_SEGMENTS_ID, &pFirstBlock, 0);
203881 pWriter->iStart = sqlite3_column_int64(pFirstBlock, 0);
203892 rc = fts3WriteSegment(p, pWriter->iEnd, 0, 0);
203900 for(i=0; i<FTS_MAX_APPENDABLE_HEIGHT; i++){
203923 sqlite3_stmt *pDelete = 0; /* DELETE statement */
203925 rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_ENTRY, &pDelete, 0);
203939 ** the idx values are a contiguous sequence starting from 0.
203946 int *aIdx = 0; /* Array of remaining idx values */
203947 int nIdx = 0; /* Valid entries in aIdx[] */
203948 int nAlloc = 0; /* Allocated size of aIdx[] */
203950 sqlite3_stmt *pSelect = 0; /* Select statement to read idx values */
203951 sqlite3_stmt *pUpdate = 0; /* Update statement to modify idx values */
203953 rc = fts3SqlStmt(p, SQL_SELECT_INDEXES, &pSelect, 0);
203968 aIdx[nIdx++] = sqlite3_column_int(pSelect, 0);
203975 rc = fts3SqlStmt(p, SQL_SHIFT_SEGDIR_ENTRY, &pUpdate, 0);
203981 assert( p->bIgnoreSavepoint==0 );
203983 for(i=0; rc==SQLITE_OK && i<nIdx; i++){
203991 p->bIgnoreSavepoint = 0;
203998 pNode->a[0] = (char)iHeight;
204025 Blob prev = {0, 0, 0}; /* Previous term written to new node */
204030 bLeaf = aNode[0]=='\0';
204035 pNew->n = 0;
204042 if( pNew->n==0 ){
204044 if( res<0 || (bLeaf==0 && res==0) ) continue;
204045 fts3StartNode(pNew, (int)aNode[0], reader.iChild);
204054 if( pNew->n==0 ){
204055 fts3StartNode(pNew, (int)aNode[0], reader.iChild);
204082 Blob root = {0,0,0}; /* New root page image */
204083 Blob block = {0,0,0}; /* Buffer used for any other block */
204084 sqlite3_int64 iBlock = 0; /* Block id */
204085 sqlite3_int64 iNewStart = 0; /* New value for iStartBlock */
204086 sqlite3_int64 iOldStart = 0; /* Old value for iStartBlock */
204087 sqlite3_stmt *pFetch = 0; /* Statement used to fetch segdir */
204089 rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR, &pFetch, 0);
204105 char *aBlock = 0;
204106 int nBlock = 0;
204109 rc = sqlite3Fts3ReadBlock(p, iBlock, &aBlock, &nBlock, 0);
204121 sqlite3_stmt *pDel = 0;
204122 rc = fts3SqlStmt(p, SQL_DELETE_SEGMENTS_RANGE, &pDel, 0);
204132 sqlite3_stmt *pChomp = 0;
204133 rc = fts3SqlStmt(p, SQL_CHOMP_SEGDIR, &pChomp, 0);
204167 int nRem = 0;
204170 for(i=pCsr->nSegment-1; i>=0 && rc==SQLITE_OK; i--){
204171 Fts3SegReader *pSeg = 0;
204176 for(j=0; ALWAYS(j<pCsr->nSegment); j++){
204182 if( pSeg->aNode==0 ){
204188 *pnRem = 0;
204212 sqlite3_stmt *pReplace = 0;
204215 rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pReplace, 0);
204236 sqlite3_stmt *pSelect = 0;
204239 pHint->n = 0;
204240 rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pSelect, 0);
204245 const char *aHint = sqlite3_column_blob(pSelect, 0);
204246 int nHint = sqlite3_column_bytes(pSelect, 0);
204250 if( ALWAYS(pHint->a!=0) ) memcpy(pHint->a, aHint, nHint);
204297 if( (pHint->a[i] & 0x80) ) return FTS_CORRUPT_VTAB;
204298 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
204299 if( i==0 ) return FTS_CORRUPT_VTAB;
204301 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
204328 int nSeg = 0; /* Number of input segments */
204329 sqlite3_int64 iAbsLevel = 0; /* Absolute level number to work on */
204330 Blob hint = {0, 0, 0}; /* Hint read from %_stat table */
204331 int bDirtyHint = 0; /* True if blob 'hint' has been modified */
204341 while( rc==SQLITE_OK && nRem>0 ){
204343 sqlite3_stmt *pFindLevel = 0; /* SQL used to determine iAbsLevel */
204344 int bUseHint = 0; /* True if attempting to append */
204345 int iIdx = 0; /* Largest idx in level (iAbsLevel+1) */
204353 rc = fts3SqlStmt(p, SQL_FIND_MERGE_LEVEL, &pFindLevel, 0);
204356 iAbsLevel = sqlite3_column_int64(pFindLevel, 0);
204371 sqlite3_int64 iHintAbsLevel = 0; /* Hint level */
204372 int nHintSeg = 0; /* Hint number of segments */
204375 if( nSeg<0 || (iAbsLevel % nMod) >= (iHintAbsLevel % nMod) ){
204396 if( nSeg<=0 ) break;
204398 assert( nMod<=0x7FFFFFFF );
204399 if( iAbsLevel<0 || iAbsLevel>(nMod<<32) ){
204410 memset(pWriter, 0, nAlloc);
204415 assert( bUseHint==1 || bUseHint==0 );
204416 if( iIdx==0 || (bUseHint && iIdx==1) ){
204417 int bIgnore = 0;
204431 int bEmpty = 0;
204439 if( bUseHint && iIdx>0 ){
204449 if( bEmpty==0 ){
204461 if( nSeg!=0 ){
204468 if( nSeg!=0 ){
204472 if( nSeg==0 && pWriter->bNoLeafData==0 ){
204500 int i = 0;
204501 while( (*z)>='0' && (*z)<='9' && i<214748363 ) i = 10*i + *(z++) - '0';
204521 int nMerge = 0;
204529 if( z[0]==',' && z[1]!='\0' ){
204534 if( z[0]!='\0' || nMin<2 ){
204539 assert( p->bFts4==0 );
204555 ** where X is an integer. X==0 means to turn automerge off. X!=0 means
204563 sqlite3_stmt *pStmt = 0;
204569 assert( p->bFts4==0 );
204573 rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0);
204590 int iIndex, /* Index (0..Fts3Table.nIndex-1) */
204602 for(i=0; i<nTerm; i++) ret += (ret<<3) + zTerm[i];
204619 int iIndex, /* Index to cksum (0..p->nIndex-1) */
204625 u64 cksum = 0;
204627 if( *pRc ) return 0;
204629 memset(&filter, 0, sizeof(filter));
204630 memset(&csr, 0, sizeof(csr));
204635 p, iLangid, iIndex, FTS3_SEGCURSOR_ALL, 0, 0, 0, 1,&csr
204646 i64 iDocid = 0;
204647 i64 iCol = 0;
204648 u64 iPos = 0;
204652 u64 iVal = 0;
204655 if( iVal==0 || iVal==1 ){
204656 iCol = 0;
204657 iPos = 0;
204696 u64 cksum1 = 0; /* Checksum based on FTS index contents */
204697 u64 cksum2 = 0; /* Checksum based on %_content contents */
204698 sqlite3_stmt *pAllLangid = 0; /* Statement to return all language-ids */
204701 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
204707 int iLangid = sqlite3_column_int(pAllLangid, 0);
204709 for(i=0; i<p->nIndex; i++){
204720 sqlite3_stmt *pStmt = 0;
204727 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
204732 i64 iDocid = sqlite3_column_int64(pStmt, 0);
204736 for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
204737 if( p->abNotindexed[iCol]==0 ){
204739 sqlite3_tokenizer_cursor *pT = 0;
204744 int nToken = 0; /* Number of bytes in token */
204745 int iDum1 = 0, iDum2 = 0; /* Dummy variables */
204746 int iPos = 0; /* Position of token in zText */
204752 zToken, nToken, iLang, 0, iDocid, iCol, iPos
204774 *pbOk = 0;
204793 ** + The index number (0 for the main index, 1 for the first prefix
204816 int bOk = 0;
204818 if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB;
204837 }else if( nVal==8 && 0==sqlite3_strnicmp(zVal, "optimize", 8) ){
204838 rc = fts3DoOptimize(p, 0);
204839 }else if( nVal==7 && 0==sqlite3_strnicmp(zVal, "rebuild", 7) ){
204841 }else if( nVal==15 && 0==sqlite3_strnicmp(zVal, "integrity-check", 15) ){
204843 }else if( nVal>6 && 0==sqlite3_strnicmp(zVal, "merge=", 6) ){
204845 }else if( nVal>10 && 0==sqlite3_strnicmp(zVal, "automerge=", 10) ){
204847 }else if( nVal==5 && 0==sqlite3_strnicmp(zVal, "flush", 5) ){
204853 if( nVal>9 && 0==sqlite3_strnicmp(zVal, "nodesize=", 9) ){
204857 }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 9) ){
204861 }else if( nVal>21 && 0==sqlite3_strnicmp(zVal,"test-no-incr-doclist=",21) ){
204864 }else if( nVal>11 && 0==sqlite3_strnicmp(zVal,"mergecount=",11) ){
204866 if( v>=4 && v<=FTS3_MERGE_COUNT && (v&1)==0 ) p->nMergeCount = v;
204883 pDef->pList = 0;
204899 pCsr->pDeferred = 0;
204921 assert( pCsr->isRequireSeek==0 );
204922 iDocid = sqlite3_column_int64(pCsr->pStmt, 0);
204924 for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){
204925 if( p->abNotindexed[i]==0 ){
204927 sqlite3_tokenizer_cursor *pTC = 0;
204932 int nToken = 0; /* Number of bytes in token */
204933 int iDum1 = 0, iDum2 = 0; /* Dummy variables */
204934 int iPos = 0; /* Position of token in zText */
204940 && (pPT->bFirst==0 || iPos==0)
204942 && (0==memcmp(zToken, pPT->z, pPT->n))
204955 rc = fts3PendingListAppendVarint(&pDef->pList, 0);
204972 *ppData = 0;
204973 *pnData = 0;
204975 if( p->pList==0 ){
205003 memset(pDeferred, 0, sizeof(*pDeferred));
205009 assert( pToken->pDeferred==0 );
205028 int bFound = 0; /* True if *pRowid really is in the table */
205032 int isEmpty = 0; /* Deleting *pRowid leaves the table empty */
205040 *pnChng = 0;
205041 memset(aSzDel, 0, sizeof(u32) * (p->nColumn+1) * 2);
205044 if( p->zContentTbl==0 ){
205078 u32 *aSzIns = 0; /* Sizes of inserted documents */
205079 u32 *aSzDel = 0; /* Sizes of deleted documents */
205080 int nChng = 0; /* Net change in number of documents */
205081 int bInsertDone = 0;
205085 assert( p->bHasStat==0 || p->bHasStat==1 );
205087 assert( p->pSegments==0 );
205098 && sqlite3_value_type(apVal[0])==SQLITE_NULL
205105 if( nArg>1 && sqlite3_value_int(apVal[2 + p->nColumn + 2])<0 ){
205111 aSzDel = sqlite3_malloc64(sizeof(aSzDel[0])*((sqlite3_int64)p->nColumn+1)*2);
205112 if( aSzDel==0 ){
205117 memset(aSzDel, 0, sizeof(aSzDel[0])*(p->nColumn+1)*2);
205131 if( nArg>1 && p->zContentTbl==0 ){
205139 sqlite3_value_type(apVal[0])==SQLITE_NULL
205140 || sqlite3_value_int64(apVal[0])!=sqlite3_value_int64(pNewRowid)
205172 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
205173 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER );
205174 rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel);
205180 if( bInsertDone==0 ){
205182 if( rc==SQLITE_CONSTRAINT && p->zContentTbl==0 ){
205187 rc = fts3PendingTermsDocid(p, 0, iLangid, *pRowid);
205216 rc = sqlite3_exec(p->db, "SAVEPOINT fts3", 0, 0, 0);
205220 int rc2 = sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
205223 sqlite3_exec(p->db, "ROLLBACK TO fts3", 0, 0, 0);
205224 sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
205381 pRet->aMI[0] = (u8*)(&pRet->aMI[1]) - (u8*)pRet;
205382 pRet->aMI[1+nElem] = pRet->aMI[0]
205387 pRet->aRef[0] = 1;
205400 pBuf->aRef[1] = 0;
205402 pBuf->aRef[2] = 0;
205405 if( pBuf->aRef[0]==0 && pBuf->aRef[1]==0 && pBuf->aRef[2]==0 ){
205411 void (*xRet)(void*) = 0;
205412 u32 *aOut = 0;
205414 if( p->aRef[1]==0 ){
205419 else if( p->aRef[2]==0 ){
205445 assert( p->aRef[0]==1 );
205446 p->aRef[0] = 0;
205447 if( p->aRef[0]==0 && p->aRef[1]==0 && p->aRef[2]==0 ){
205524 int iPhrase = 0; /* Variable used as the phrase counter */
205562 LoadDoclistCtx sCtx = {0,0,0}; /* Context for sqlite3Fts3ExprIterate() */
205576 int nPhrase = 0;
205592 if( 0==(*pIter & 0xFE) ){
205594 pIter = 0;
205611 if( pIter->iCurrent<0 ){
205613 ** candidate always starts at offset 0 (even if this candidate has a
205616 pIter->iCurrent = 0;
205621 for(i=0; i<pIter->nPhrase; i++){
205627 int iEnd = 0x7FFFFFFF;
205629 for(i=0; i<pIter->nPhrase; i++){
205635 if( iEnd==0x7FFFFFFF ){
205639 assert( pIter->nSnippet>=0 );
205641 for(i=0; i<pIter->nPhrase; i++){
205648 return 0;
205664 int iScore = 0; /* Score of this snippet */
205666 u64 mCover = 0; /* Mask of phrases covered by this snippet */
205667 u64 mHighlight = 0; /* Mask of tokens to highlight in snippet */
205669 for(i=0; i<pIter->nPhrase; i++){
205680 assert( i>=0 );
205688 for(j=0; j<pPhrase->nToken && j<pIter->nSnippet; j++){
205692 if( 0==(*pCsr & 0x0FE) ) break;
205718 assert( rc==SQLITE_OK || pCsr==0 );
205720 i64 iFirst = 0;
205723 if( iFirst<0 ){
205733 pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0
205771 memset(&sIter, 0, sizeof(sIter));
205776 rc = fts3ExprLoadDoclists(pCsr, &nList, 0);
205804 for(i=0; i<nList; i++){
205820 assert( iScore>=0 );
205847 if( nAppend<0 ){
205864 assert( pStr->z!=0 && (pStr->nAlloc >= pStr->n+nAppend+1) );
205869 pStr->z[pStr->n] = '\0';
205910 for(nLeft=0; !(hlmask & ((u64)1 << nLeft)); nLeft++);
205911 for(nRight=0; !(hlmask & ((u64)1 << (nSnippet-1-nRight))); nRight++);
205912 assert( (nSnippet-1-nRight)<=63 && (nSnippet-1-nRight)>=0 );
205922 if( nDesired>0 ){
205924 int iCurrent = 0; /* Token counter */
205938 const char *ZDUMMY; int DUMMY1 = 0, DUMMY2 = 0, DUMMY3 = 0;
205946 if( nShift>0 ){
205974 int iCurrent = 0; /* Current token number of document */
205975 int iEnd = 0; /* Byte offset of end of current token */
205976 int isShiftDone = 0; /* True after snippet is shifted */
205984 if( zDoc==0 ){
206002 int iBegin = 0; /* Offset in zDoc of start of token */
206003 int iFin = 0; /* Offset in zDoc of end of token */
206004 int isHighlight = 0; /* True for highlighted terms */
206039 ** or (b) this fragment does not begin at position 0 of its column.
206042 if( iPos>0 || iFragment>0 ){
206059 isHighlight = (hlmask & ((u64)1 << (iCurrent-iPos)))!=0;
206081 ** the last varint in the column-list (either the 0x00 signifying the end
206082 ** of the position-list, or the 0x01 that precedes the column number of
206089 char c = 0;
206090 int nEntry = 0;
206092 /* A column-list is terminated by either a 0x01 or 0x00. */
206093 while( 0xFE & (*pEnd | c) ){
206094 c = *pEnd++ & 0x80;
206113 int iCol = 0;
206128 p->aMatchinfo[iStart + (iCol+1)/32] |= (1 << (iCol&0x1F));
206131 assert( *pIter==0x00 || *pIter==0x01 );
206132 if( *pIter!=0x01 ) break;
206148 assert( (pExpr->pLeft==0)==(pExpr->pRight==0) );
206149 if( pExpr->bEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
206172 ** for(iCol=0; iCol<nCol; iCol++){
206213 for(i=0; i<p->nCol && rc==SQLITE_OK; i++){
206219 p->aMatchinfo[iStart+i*3] = 0;
206301 n = sqlite3_column_bytes(pStmt, 0);
206302 a = sqlite3_column_blob(pStmt, 0);
206303 if( a==0 ){
206308 if( nDoc<=0 || a>pEnd ){
206336 #define LCS_ITERATOR_FINISHED 0x7FFFFFFF;
206356 int rc = 0;
206358 if( NEVER(pIter==0) ) return 1;
206361 if( iRead==0 || iRead==1 ){
206362 pRead = 0;
206387 int nToken = 0;
206397 for(i=0; i<pInfo->nPhrase; i++){
206403 for(iCol=0; iCol<pInfo->nCol; iCol++){
206404 int nLcs = 0; /* LCS value for this column */
206405 int nLive = 0; /* Number of iterators in aIter not at EOF */
206407 for(i=0; i<pInfo->nPhrase; i++){
206414 if( pIt->pRead==0 ){
206422 while( nLive>0 ){
206423 LcsIterator *pAdv = 0; /* The iterator to advance by one position */
206424 int nThisLcs = 0; /* LCS for the current iterator positions */
206426 for(i=0; i<pInfo->nPhrase; i++){
206428 if( pIter->pRead==0 ){
206430 nThisLcs = 0;
206432 if( pAdv==0 || pIter->iPos<pAdv->iPos ){
206435 if( nThisLcs==0 || pIter->iPos==pIter[-1].iPos ){
206480 sqlite3_stmt *pSelect = 0;
206482 for(i=0; rc==SQLITE_OK && zArg[i]; i++){
206486 if( bGlobal ) pInfo->aMatchinfo[0] = pInfo->nPhrase;
206490 if( bGlobal ) pInfo->aMatchinfo[0] = pInfo->nCol;
206495 sqlite3_int64 nDoc = 0;
206496 rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &nDoc, 0, 0);
206497 pInfo->aMatchinfo[0] = (u32)nDoc;
206510 for(iCol=0; iCol<pInfo->nCol; iCol++){
206518 iVal = (u32)(((u32)(nToken&0xffffffff)+nDoc/2)/nDoc);
206526 sqlite3_stmt *pSelectDocsize = 0;
206530 const char *a = sqlite3_column_blob(pSelectDocsize, 0);
206531 const char *pEnd = a + sqlite3_column_bytes(pSelectDocsize, 0);
206532 for(iCol=0; iCol<pInfo->nCol; iCol++){
206547 rc = fts3ExprLoadDoclists(pCsr, 0, 0);
206556 memset(pInfo->aMatchinfo, 0, nZero);
206565 rc = fts3ExprLoadDoclists(pCsr, 0, 0);
206569 rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &pInfo->nDoc,0,0);
206601 int bGlobal = 0; /* Collect 'global' stats as well as local */
206603 u32 *aOut = 0;
206604 void (*xDestroyOut)(void*) = 0;
206606 memset(&sInfo, 0, sizeof(MatchInfo));
206615 pCsr->pMIBuffer = 0;
206623 if( pCsr->pMIBuffer==0 ){
206624 size_t nMatchinfo = 0; /* Number of u32 elements in match-info */
206632 for(i=0; zArg[i]; i++){
206633 char *zErr = 0;
206652 if( xDestroyOut==0 ){
206690 StrBuffer res = {0, 0, 0};
206700 int nSnippet = 0; /* Number of fragments in this snippet */
206705 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
206715 int iSnip; /* Loop counter 0..nSnippet-1 */
206716 u64 mCovered = 0; /* Bitmask of phrases covered by snippet */
206717 u64 mSeen = 0; /* Bitmask of phrases seen by BestSnippet() */
206719 if( nToken>=0 ){
206725 for(iSnip=0; iSnip<nSnippet; iSnip++){
206730 memset(pFragment, 0, sizeof(*pFragment));
206736 for(iRead=0; iRead<pTab->nColumn; iRead++){
206737 SnippetFragment sF = {0, 0, 0, 0};
206738 int iS = 0;
206739 if( iCol>=0 && iRead!=iCol ) continue;
206762 assert( nFToken>0 );
206764 for(i=0; i<nSnippet && rc==SQLITE_OK; i++){
206806 i64 iPos = 0; /* First position in position-list */
206814 assert_fts3_nc( iPos>=0 );
206817 for(iTerm=0; iTerm<nTerm; iTerm++){
206838 pExpr->pPhrase->bIncr = 0;
206855 StrBuffer res = {0, 0, 0}; /* Result string */
206859 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
206863 memset(&sCtx, 0, sizeof(sCtx));
206864 assert( pCsr->isRequireSeek==0 );
206867 rc = fts3ExprLoadDoclists(pCsr, 0, &nToken);
206872 if( 0==sCtx.aTerm ){
206888 for(iCol=0; iCol<pTab->nColumn; iCol++){
206891 int NDUMMY = 0; /* Dummy argument used with xNext() */
206892 int iStart = 0;
206893 int iEnd = 0;
206894 int iCurrent = 0;
206902 sCtx.iTerm = 0;
206916 if( zDoc==0 ){
206933 int iMinPos = 0x7FFFFFFF; /* Position of next token */
206934 TermOffset *pTerm = 0; /* TermOffset associated with next token */
206936 for(i=0; i<nToken; i++){
206949 if( 0==(0xFE&*pTerm->pList) ){
206950 pTerm->pList = 0;
206963 }else if( rc==SQLITE_DONE && pTab->zContentTbl==0 ){
207007 sqlite3_result_blob(pContext, "", 0, SQLITE_STATIC);
207055 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
207056 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
207057 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
207058 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
207059 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
207060 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
207061 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
207062 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
207067 if( c>=0xc0 ){ \
207068 c = sqlite3Utf8Trans1[c-0xc0]; \
207069 while( zIn!=zTerm && (*zIn & 0xc0)==0x80 ){ \
207070 c = (c<<6) + (0x3f & *(zIn++)); \
207072 if( c<0x80 \
207073 || (c&0xFFFFF800)==0xD800 \
207074 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
207078 if( c<0x00080 ){ \
207079 *zOut++ = (u8)(c&0xFF); \
207081 else if( c<0x00800 ){ \
207082 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \
207083 *zOut++ = 0x80 + (u8)(c & 0x3F); \
207085 else if( c<0x10000 ){ \
207086 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \
207087 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
207088 *zOut++ = 0x80 + (u8)(c & 0x3F); \
207090 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07); \
207091 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \
207092 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
207093 *zOut++ = 0x80 + (u8)(c & 0x3F); \
207135 ** all characters in string zIn/nIn to be separators (if bAlnum==0) or
207159 int nEntry = 0;
207161 assert( bAlnum==0 || bAlnum==1 );
207165 assert( (sqlite3FtsUnicodeIsalnum((int)iCode) & 0xFFFFFFFE)==0 );
207167 && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
207178 if( aNew==0 ) return SQLITE_NOMEM;
207185 && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
207188 for(i=0; i<nNew && aNew[i]<(int)iCode; i++);
207205 if( p->nException>0 ){
207207 int iLo = 0;
207222 return 0;
207230 assert( (sqlite3FtsUnicodeIsalnum(iCode) & 0xFFFFFFFE)==0 );
207248 memset(pNew, 0, sizeof(unicode_tokenizer));
207251 for(i=0; rc==SQLITE_OK && i<nArg; i++){
207255 if( n==19 && memcmp("remove_diacritics=1", z, 19)==0 ){
207258 else if( n==19 && memcmp("remove_diacritics=0", z, 19)==0 ){
207259 pNew->eRemoveDiacritic = 0;
207261 else if( n==19 && memcmp("remove_diacritics=2", z, 19)==0 ){
207264 else if( n>=11 && memcmp("tokenchars=", z, 11)==0 ){
207267 else if( n>=11 && memcmp("separators=", z, 11)==0 ){
207268 rc = unicodeAddExceptions(pNew, 0, &z[11], n-11);
207278 pNew = 0;
207286 ** string to be tokenized is pInput[0..nBytes-1]. A cursor
207299 if( pCsr==0 ){
207302 memset(pCsr, 0, sizeof(unicode_cursor));
207305 if( aInput==0 ){
207306 pCsr->nInput = 0;
207308 }else if( nInput<0 ){
207344 unsigned int iCode = 0;
207404 0,
207410 0,
207452 ** codepoints for which this function should return 0).
207462 0x00000030, 0x0000E807, 0x00016C06, 0x0001EC2F, 0x0002AC07,
207463 0x0002D001, 0x0002D803, 0x0002EC01, 0x0002FC01, 0x00035C01,
207464 0x0003DC01, 0x000B0804, 0x000B480E, 0x000B9407, 0x000BB401,
207465 0x000BBC81, 0x000DD401, 0x000DF801, 0x000E1002, 0x000E1C01,
207466 0x000FD801, 0x00120808, 0x00156806, 0x00162402, 0x00163C01,
207467 0x00164437, 0x0017CC02, 0x00180005, 0x00181816, 0x00187802,
207468 0x00192C15, 0x0019A804, 0x0019C001, 0x001B5001, 0x001B580F,
207469 0x001B9C07, 0x001BF402, 0x001C000E, 0x001C3C01, 0x001C4401,
207470 0x001CC01B, 0x001E980B, 0x001FAC09, 0x001FD804, 0x00205804,
207471 0x00206C09, 0x00209403, 0x0020A405, 0x0020C00F, 0x00216403,
207472 0x00217801, 0x0023901B, 0x00240004, 0x0024E803, 0x0024F812,
207473 0x00254407, 0x00258804, 0x0025C001, 0x00260403, 0x0026F001,
207474 0x0026F807, 0x00271C02, 0x00272C03, 0x00275C01, 0x00278802,
207475 0x0027C802, 0x0027E802, 0x00280403, 0x0028F001, 0x0028F805,
207476 0x00291C02, 0x00292C03, 0x00294401, 0x0029C002, 0x0029D401,
207477 0x002A0403, 0x002AF001, 0x002AF808, 0x002B1C03, 0x002B2C03,
207478 0x002B8802, 0x002BC002, 0x002C0403, 0x002CF001, 0x002CF807,
207479 0x002D1C02, 0x002D2C03, 0x002D5802, 0x002D8802, 0x002DC001,
207480 0x002E0801, 0x002EF805, 0x002F1803, 0x002F2804, 0x002F5C01,
207481 0x002FCC08, 0x00300403, 0x0030F807, 0x00311803, 0x00312804,
207482 0x00315402, 0x00318802, 0x0031FC01, 0x00320802, 0x0032F001,
207483 0x0032F807, 0x00331803, 0x00332804, 0x00335402, 0x00338802,
207484 0x00340802, 0x0034F807, 0x00351803, 0x00352804, 0x00355C01,
207485 0x00358802, 0x0035E401, 0x00360802, 0x00372801, 0x00373C06,
207486 0x00375801, 0x00376008, 0x0037C803, 0x0038C401, 0x0038D007,
207487 0x0038FC01, 0x00391C09, 0x00396802, 0x003AC401, 0x003AD006,
207488 0x003AEC02, 0x003B2006, 0x003C041F, 0x003CD00C, 0x003DC417,
207489 0x003E340B, 0x003E6424, 0x003EF80F, 0x003F380D, 0x0040AC14,
207490 0x00412806, 0x00415804, 0x00417803, 0x00418803, 0x00419C07,
207491 0x0041C404, 0x0042080C, 0x00423C01, 0x00426806, 0x0043EC01,
207492 0x004D740C, 0x004E400A, 0x00500001, 0x0059B402, 0x005A0001,
207493 0x005A6C02, 0x005BAC03, 0x005C4803, 0x005CC805, 0x005D4802,
207494 0x005DC802, 0x005ED023, 0x005F6004, 0x005F7401, 0x0060000F,
207495 0x0062A401, 0x0064800C, 0x0064C00C, 0x00650001, 0x00651002,
207496 0x0066C011, 0x00672002, 0x00677822, 0x00685C05, 0x00687802,
207497 0x0069540A, 0x0069801D, 0x0069FC01, 0x006A8007, 0x006AA006,
207498 0x006C0005, 0x006CD011, 0x006D6823, 0x006E0003, 0x006E840D,
207499 0x006F980E, 0x006FF004, 0x00709014, 0x0070EC05, 0x0071F802,
207500 0x00730008, 0x00734019, 0x0073B401, 0x0073C803, 0x00770027,
207501 0x0077F004, 0x007EF401, 0x007EFC03, 0x007F3403, 0x007F7403,
207502 0x007FB403, 0x007FF402, 0x00800065, 0x0081A806, 0x0081E805,
207503 0x00822805, 0x0082801A, 0x00834021, 0x00840002, 0x00840C04,
207504 0x00842002, 0x00845001, 0x00845803, 0x00847806, 0x00849401,
207505 0x00849C01, 0x0084A401, 0x0084B801, 0x0084E802, 0x00850005,
207506 0x00852804, 0x00853C01, 0x00864264, 0x00900027, 0x0091000B,
207507 0x0092704E, 0x00940200, 0x009C0475, 0x009E53B9, 0x00AD400A,
207508 0x00B39406, 0x00B3BC03, 0x00B3E404, 0x00B3F802, 0x00B5C001,
207509 0x00B5FC01, 0x00B7804F, 0x00B8C00C, 0x00BA001A, 0x00BA6C59,
207510 0x00BC00D6, 0x00BFC00C, 0x00C00005, 0x00C02019, 0x00C0A807,
207511 0x00C0D802, 0x00C0F403, 0x00C26404, 0x00C28001, 0x00C3EC01,
207512 0x00C64002, 0x00C6580A, 0x00C70024, 0x00C8001F, 0x00C8A81E,
207513 0x00C94001, 0x00C98020, 0x00CA2827, 0x00CB003F, 0x00CC0100,
207514 0x01370040, 0x02924037, 0x0293F802, 0x02983403, 0x0299BC10,
207515 0x029A7C01, 0x029BC008, 0x029C0017, 0x029C8002, 0x029E2402,
207516 0x02A00801, 0x02A01801, 0x02A02C01, 0x02A08C09, 0x02A0D804,
207517 0x02A1D004, 0x02A20002, 0x02A2D011, 0x02A33802, 0x02A38012,
207518 0x02A3E003, 0x02A4980A, 0x02A51C0D, 0x02A57C01, 0x02A60004,
207519 0x02A6CC1B, 0x02A77802, 0x02A8A40E, 0x02A90C01, 0x02A93002,
207520 0x02A97004, 0x02A9DC03, 0x02A9EC01, 0x02AAC001, 0x02AAC803,
207521 0x02AADC02, 0x02AAF802, 0x02AB0401, 0x02AB7802, 0x02ABAC07,
207522 0x02ABD402, 0x02AF8C0B, 0x03600001, 0x036DFC02, 0x036FFC02,
207523 0x037FFC01, 0x03EC7801, 0x03ECA401, 0x03EEC810, 0x03F4F802,
207524 0x03F7F002, 0x03F8001A, 0x03F88007, 0x03F8C023, 0x03F95013,
207525 0x03F9A004, 0x03FBFC01, 0x03FC040F, 0x03FC6807, 0x03FCEC06,
207526 0x03FD6C0B, 0x03FF8007, 0x03FFA007, 0x03FFE405, 0x04040003,
207527 0x0404DC09, 0x0405E411, 0x0406400C, 0x0407402E, 0x040E7C01,
207528 0x040F4001, 0x04215C01, 0x04247C01, 0x0424FC01, 0x04280403,
207529 0x04281402, 0x04283004, 0x0428E003, 0x0428FC01, 0x04294009,
207530 0x0429FC01, 0x042CE407, 0x04400003, 0x0440E016, 0x04420003,
207531 0x0442C012, 0x04440003, 0x04449C0E, 0x04450004, 0x04460003,
207532 0x0446CC0E, 0x04471404, 0x045AAC0D, 0x0491C004, 0x05BD442E,
207533 0x05BE3C04, 0x074000F6, 0x07440027, 0x0744A4B5, 0x07480046,
207534 0x074C0057, 0x075B0401, 0x075B6C01, 0x075BEC01, 0x075C5401,
207535 0x075CD401, 0x075D3C01, 0x075DBC01, 0x075E2401, 0x075EA401,
207536 0x075F0C01, 0x07BBC002, 0x07C0002C, 0x07C0C064, 0x07C2800F,
207537 0x07C2C40E, 0x07C3040F, 0x07C3440F, 0x07C4401F, 0x07C4C03C,
207538 0x07C5C02B, 0x07C7981D, 0x07C8402B, 0x07C90009, 0x07C94002,
207539 0x07CC0021, 0x07CCC006, 0x07CCDC46, 0x07CE0014, 0x07CE8025,
207540 0x07CF1805, 0x07CF8011, 0x07D0003F, 0x07D10001, 0x07D108B6,
207541 0x07D3E404, 0x07D4003E, 0x07D50004, 0x07D54018, 0x07D7EC46,
207542 0x07D9140B, 0x07DA0046, 0x07DC0074, 0x38000401, 0x38008060,
207543 0x380400F0,
207546 0xFFFFFFFF, 0xFC00FFFF, 0xF8000001, 0xF8000001,
207550 return ( (aAscii[c >> 5] & ((unsigned int)1 << (c & 0x001F)))==0 );
207552 unsigned int key = (((unsigned int)c)<<10) | 0x000003FF;
207553 int iRes = 0;
207554 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
207555 int iLo = 0;
207565 assert( aEntry[0]<key );
207567 return (((unsigned int)c) >= ((aEntry[iRes]>>10) + (aEntry[iRes]&0x3FF)));
207583 0, 1797, 1848, 1859, 1891, 1928, 1940, 1995,
207600 #define HIBIT ((unsigned char)0x80)
207602 '\0', 'a', 'c', 'e', 'i', 'n',
207612 'o'|HIBIT, 'y', '\0', '\0', '\0', '\0',
207613 '\0', '\0', '\0', '\0', 'a', 'b',
207625 unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
207626 int iRes = 0;
207627 int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
207628 int iLo = 0;
207639 if( bComplex==0 && (aChar[iRes] & 0x80) ) return c;
207640 return (c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : ((int)aChar[iRes] & 0x7F);
207649 unsigned int mask0 = 0x08029FDF;
207650 unsigned int mask1 = 0x000361F8;
207651 if( c<768 || c>817 ) return 0;
207679 ** case equivalent is ((C + aiOff[flags>>1]) & 0xFFFF).
207694 {386, 1, 4}, {390, 44, 1}, {391, 0, 1},
207695 {393, 42, 2}, {395, 0, 1}, {398, 32, 1},
207696 {399, 38, 1}, {400, 40, 1}, {401, 0, 1},
207698 {407, 48, 1}, {408, 0, 1}, {412, 52, 1},
207700 {422, 60, 1}, {423, 0, 1}, {425, 60, 1},
207701 {428, 0, 1}, {430, 60, 1}, {431, 0, 1},
207703 {440, 0, 1}, {444, 0, 1}, {452, 2, 1},
207704 {453, 0, 1}, {455, 2, 1}, {456, 0, 1},
207708 {546, 1, 18}, {570, 70, 1}, {571, 0, 1},
207709 {573, 108, 1}, {574, 68, 1}, {577, 0, 1},
207712 {886, 0, 1}, {902, 18, 1}, {904, 16, 3},
207714 {931, 14, 9}, {962, 0, 1}, {975, 4, 1},
207718 {1015, 0, 1}, {1017, 152, 1}, {1018, 0, 1},
207734 {8579, 0, 1}, {9398, 10, 26}, {11264, 22, 47},
207735 {11360, 0, 1}, {11362, 88, 1}, {11363, 102, 1},
207738 {11378, 0, 1}, {11381, 0, 1}, {11390, 78, 2},
207739 {11392, 1, 100}, {11499, 1, 4}, {11506, 0, 1},
207742 {42878, 1, 10}, {42891, 0, 1}, {42893, 74, 1},
207767 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
207768 int iLo = 0;
207771 assert( c>aEntry[0].iCode );
207775 if( cmp>=0 ){
207783 assert( iRes>=0 && c>=aEntry[iRes].iCode );
207785 if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
207786 ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
207787 assert( ret>0 );
207824 ** Support for JSON-5 extensions was added with version 3.42.0 (2023-05-16).
207828 ** Beginning with version 3.45.0 (circa 2024-01-01), these routines also
207854 ** 0: NULL
207873 ** of the element and if X>>4 is between 0 and 11, then the payload
207882 ** 12 1 byte (0-255) 2
207883 ** 13 2 byte (0-65535) 3
207884 ** 14 4 byte (0-4294967295) 5
207885 ** 15 8 byte (0-1.8e19) 9
207889 ** ways: (1) (X>>4)==10, (2) (X>>4)==12 following by one 0x0a byte,
207890 ** (3) (X>>4)==13 followed by 0x00 and 0x0a, (4) (X>>4)==14 followed by
207891 ** 0x00 0x00 0x00 0x0a, or (5) (X>>4)==15 followed by 7 bytes of 0x00 and
207892 ** a single byte of 0x0a. The shorter forms are preferred, of course, but
207916 ** code is between 0 and 12 and that the total size of the element
207930 #define JSONB_NULL 0 /* "null" */
207934 #define JSONB_INT5 4 /* integer in 0x000 notation */
207960 /*0 1 2 3 4 5 6 7 8 9 a b c d e f */
207961 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, /* 0 */
207962 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */
207963 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2 */
207964 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3 */
207965 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 4 */
207966 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 5 */
207967 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 6 */
207968 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 7 */
207970 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 8 */
207971 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 9 */
207972 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* a */
207973 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* b */
207974 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* c */
207975 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* d */
207976 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* e */
207977 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* f */
207980 /*0 1 2 3 4 5 6 7 8 9 a b c d e f */
207981 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, /* 0 */
207982 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */
207983 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2 */
207984 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3 */
207985 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 4 */
207986 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 5 */
207987 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 6 */
207988 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 7 */
207990 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 8 */
207991 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 9 */
207992 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* a */
207993 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* b */
207994 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* c */
207995 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* d */
207996 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* e */
207997 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* f */
208023 /*0 1 2 3 4 5 6 7 8 9 a b c d e f */
208024 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0 */
208025 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */
208026 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, /* 2 */
208029 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, /* 5 */
208043 /*0 1 2 3 4 5 6 7 8 9 a b c d e f */
208044 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0 */
208045 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */
208046 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2 */
208047 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, /* 3 */
208051 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, /* 7 */
208059 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* e */
208079 #define JSON_INVALID_CHAR 0x99999
208119 #define JSTRING_OOM 0x01 /* Out of memory */
208120 #define JSTRING_MALFORMED 0x02 /* Malformed JSONB */
208121 #define JSTRING_ERR 0x04 /* Error already sent to sqlite3_result */
208132 #define JSON_JSON 0x01 /* Result is always JSON */
208133 #define JSON_SQL 0x02 /* Result is always SQL */
208134 #define JSON_ABPATH 0x03 /* Allow abbreviated JSON path specs */
208135 #define JSON_ISSET 0x04 /* json_set(), not json_insert() */
208136 #define JSON_BLOB 0x08 /* Use the BLOB output format */
208157 u32 nBlobAlloc; /* Bytes allocated to aBlob[]. 0 if aBlob is external */
208188 ** should go. Historical note: This limit was 2000 prior to version 3.42.0
208199 #define JSON_EDITABLE 0x01 /* Generate a writable JsonParse object */
208200 #define JSON_KEEPERROR 0x02 /* Return non-NULL even if there is an error */
208223 for(i=0; i<p->nUsed; i++){
208245 assert( pParse->zJson!=0 );
208247 assert( pParse->delta==0 );
208249 if( p==0 ){
208252 if( p==0 ) return SQLITE_NOMEM;
208256 if( p==0 ) return SQLITE_NOMEM;
208259 jsonParseFree(p->a[0]);
208260 memmove(p->a, &p->a[1], (JSON_CACHE_SIZE-1)*sizeof(p->a[0]));
208263 assert( pParse->nBlobAlloc>0 );
208264 pParse->eEdit = 0;
208293 return 0;
208296 if( zJson==0 ) return 0;
208300 if( p==0 ){
208301 return 0;
208303 for(i=0; i<p->nUsed; i++){
208307 for(i=0; i<p->nUsed; i++){
208309 if( memcmp(p->a[i]->zJson, zJson, nJson)==0 ) break;
208320 assert( p->a[i]->delta==0 );
208323 return 0;
208337 p->nUsed = 0;
208345 p->eErr = 0;
208374 if( zNew==0 ){
208380 p->bStatic = 0;
208383 if( p->zBuf==0 ){
208400 assert( N>0 );
208406 if( N==0 ) return;
208415 assert( N>0 );
208452 if( p->eErr==0 ){
208453 assert( p->nUsed>0 );
208465 jsonAppendChar(p, 0);
208467 return p->eErr==0;
208475 if( p->nUsed==0 ) return;
208489 0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0,
208490 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
208498 assert( c>=0 && c<sizeof(aSpecial) );
208507 p->zBuf[p->nUsed+2] = '0';
208508 p->zBuf[p->nUsed+3] = '0';
208510 p->zBuf[p->nUsed+5] = "0123456789abcdef"[c&0xf];
208527 if( z==0 ) return;
208528 if( (N+p->nUsed+2 >= p->nAlloc) && jsonStringGrow(p,N+2)!=0 ) return;
208531 k = 0;
208560 if( k>0 ){
208566 if( k>0 ){
208572 c = z[0];
208574 if( (p->nUsed+N+3 > p->nAlloc) && jsonStringGrow(p,N+3)!=0 ) return;
208580 if( (p->nUsed+N+7 > p->nAlloc) && jsonStringGrow(p,N+7)!=0 ) return;
208625 memset(&px, 0, sizeof(px));
208627 jsonTranslateBlobToText(&px, 0, p);
208628 }else if( p->eErr==0 ){
208652 assert( (pParse!=0)==(ctx!=0) );
208653 assert( ctx==0 || ctx==p->pCtx );
208654 if( p->eErr==0 ){
208662 if( pParse && pParse->bJsonIsRCStr==0 && pParse->nBlobAlloc>0 ){
208700 pParse->zJson = 0;
208701 pParse->nJson = 0;
208702 pParse->bJsonIsRCStr = 0;
208706 pParse->aBlob = 0;
208707 pParse->nBlob = 0;
208708 pParse->nBlobAlloc = 0;
208734 ** character: 0..9a..fA..F. But unlike sqlite3HexToInt(), it does not
208744 return (u8)(h & 0xf);
208752 v = (jsonHexToInt(z[0])<<12)
208763 return sqlite3Isxdigit(z[0]) && sqlite3Isxdigit(z[1]);
208781 ** U+000a 0a line feed
208782 ** U+000b 0b vertical tab
208783 ** U+000c 0c form feed
208784 ** U+000d 0d carriage return
208810 int n = 0;
208814 case 0x09:
208815 case 0x0a:
208816 case 0x0b:
208817 case 0x0c:
208818 case 0x0d:
208819 case 0x20: {
208824 if( z[n+1]=='*' && z[n+2]!=0 ){
208827 if( z[j]==0 ) goto whitespace_done;
208834 for(j=n+2; (c = z[j])!=0; j++){
208836 if( 0xe2==(u8)c && 0x80==(u8)z[j+1]
208837 && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2])
208849 case 0xc2: {
208850 if( z[n+1]==0xa0 ){
208856 case 0xe1: {
208857 if( z[n+1]==0x9a && z[n+2]==0x80 ){
208863 case 0xe2: {
208864 if( z[n+1]==0x80 ){
208866 if( c<0x80 ) goto whitespace_done;
208867 if( c<=0x8a || c==0xa8 || c==0xa9 || c==0xaf ){
208871 }else if( z[n+1]==0x81 && z[n+2]==0x9f ){
208877 case 0xe3: {
208878 if( z[n+1]==0x80 && z[n+2]==0x80 ){
208884 case 0xef: {
208885 if( z[n+1]==0xbb && z[n+2]==0xbf ){
208947 if( pParse->nBlobAlloc==0 ){
208954 if( aNew==0 ){ pParse->oom = 1; return 1; }
208955 assert( t<0x7fffffff );
208958 return 0;
208964 ** pParse->nBlobAlloc==0 and pParse->nBlob>0) then make it editable
208973 if( pParse->oom ) return 0;
208974 if( pParse->nBlobAlloc>0 ) return 1;
208977 pParse->aBlob = 0;
208979 return 0;
208993 if( pParse->oom==0 ){
209044 assert( pParse->aBlob!=0 );
209047 a[0] = eType | (szPayload<<4);
209049 }else if( szPayload<=0xff ){
209050 a[0] = eType | 0xc0;
209051 a[1] = szPayload & 0xff;
209053 }else if( szPayload<=0xffff ){
209054 a[0] = eType | 0xd0;
209055 a[1] = (szPayload >> 8) & 0xff;
209056 a[2] = szPayload & 0xff;
209059 a[0] = eType | 0xe0;
209060 a[1] = (szPayload >> 24) & 0xff;
209061 a[2] = (szPayload >> 16) & 0xff;
209062 a[3] = (szPayload >> 8) & 0xff;
209063 a[4] = szPayload & 0xff;
209084 if( pParse->oom ) return 0;
209086 szType = a[0]>>4;
209088 nExtra = 0;
209099 nNeeded = 0;
209100 }else if( szPayload<=0xff ){
209102 }else if( szPayload<=0xffff ){
209110 if( delta>0 ){
209112 return 0; /* OOM error. Error state recorded in pParse->oom. */
209121 if( nNeeded==0 ){
209122 a[0] = (a[0] & 0x0f) | (szPayload<<4);
209124 a[0] = (a[0] & 0x0f) | 0xc0;
209125 a[1] = szPayload & 0xff;
209127 a[0] = (a[0] & 0x0f) | 0xd0;
209128 a[1] = (szPayload >> 8) & 0xff;
209129 a[2] = szPayload & 0xff;
209131 a[0] = (a[0] & 0x0f) | 0xe0;
209132 a[1] = (szPayload >> 24) & 0xff;
209133 a[2] = (szPayload >> 16) & 0xff;
209134 a[3] = (szPayload >> 8) & 0xff;
209135 a[4] = szPayload & 0xff;
209141 ** If z[0] is 'u' and is followed by exactly 4 hexadecimal character,
209146 if( z[0]!='u' ) return 0;
209147 if( !jsonIs4Hex(&z[1]) ) return 0;
209158 ** Return 0 if everything is correct. Return the 1-based byte offset of the
209160 ** 0, return 1).
209172 sz = 0;
209174 if( NEVER(n==0) ) return i+1; /* Checked by caller */
209177 x = z[i] & 0x0f;
209182 return n+sz==1 ? 0 : i+1;
209199 return 0;
209208 if( z[j]!='0' ) return i+1;
209219 return 0;
209223 u8 seen = 0; /* 0: initial. 1: '.' seen 2: 'e' seen */
209236 }else if( z[j]=='0' && x==JSONB_FLOAT ){
209244 if( seen>0 ) return j+1;
209263 if( seen==0 ) return i+1;
209264 return 0;
209273 return 0;
209283 }else if( z[j]<=0x1f ){
209288 }else if( strchr("\"\\/bfnrt",z[j+1])!=0 ){
209297 u32 c = 0;
209305 return 0;
209308 return 0;
209315 sz = 0;
209317 if( n==0 ) return j+1;
209324 return 0;
209327 u32 cnt = 0;
209332 sz = 0;
209334 if( n==0 ) return j+1;
209336 if( (cnt & 1)==0 ){
209337 x = z[j] & 0x0f;
209346 if( (cnt & 1)!=0 ) return j+1;
209347 return 0;
209364 ** 0 End of input
209383 jsonBlobAppendNode(pParse, JSONB_OBJECT, pParse->nJson-i, 0);
209392 if( x<=0 ){
209405 while( (sqlite3JsonId2(z[k]) && json5Whitespace(&z[k])==0)
209420 t = pParse->aBlob[iBlob] & 0x0f;
209446 if( x<=0 ){
209485 jsonBlobAppendNode(pParse, JSONB_ARRAY, pParse->nJson - i, 0);
209494 if( x<=0 ){
209568 || (c=='0') /* Legacy bug compatible */
209570 || (c=='0' && !sqlite3Isdigit(z[j+1])) /* Correct implementation */
209572 || (0xe2==(u8)c && 0x80==(u8)z[j+1]
209573 && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2]))
209585 }else if( c<=0x1f ){
209586 if( c==0 ){
209603 if( strncmp(z+i,"true",4)==0 && !sqlite3Isalnum(z[i+4]) ){
209611 if( strncmp(z+i,"false",5)==0 && !sqlite3Isalnum(z[i+5]) ){
209621 t = 0x00; /* Bit 0x01: JSON5. Bit 0x02: FLOAT */
209626 t = 0x03; /* Bit 0x01: JSON5. Bit 0x02: FLOAT */
209627 seenE = 0;
209633 case '0':
209644 t = 0x00; /* Bit 0x01: JSON5. Bit 0x02: FLOAT */
209646 seenE = 0;
209647 assert( '-' < '0' );
209648 assert( '+' < '0' );
209649 assert( '.' < '0' );
209652 if( c<='0' ){
209653 if( c=='0' ){
209655 assert( t==0x00 );
209657 t = 0x01;
209670 && sqlite3StrNICmp(&z[i+1], "inf",3)==0
209678 return i + (sqlite3StrNICmp(&z[i+4],"inity",5)==0 ? 9 : 4);
209682 t |= 0x01;
209688 if( z[i+1]=='0' ){
209694 t |= 0x01;
209707 if( (t & 0x02)!=0 ){
209711 t |= 0x02;
209715 if( z[j-1]<'0' ){
209718 t |= 0x01;
209728 t |= 0x02;
209735 if( c<'0' || c>'9' ){
209743 if( z[j-1]<'0' ){
209746 t |= 0x01;
209753 assert( JSONB_INT+0x01==JSONB_INT5 );
209754 assert( JSONB_FLOAT+0x01==JSONB_FLOAT5 );
209755 assert( JSONB_INT+0x02==JSONB_FLOAT );
209776 case 0: {
209777 return 0; /* End of file */
209779 case 0x09:
209780 case 0x0a:
209781 case 0x0d:
209782 case 0x20: {
209786 case 0x0b:
209787 case 0x0c:
209789 case 0xc2:
209790 case 0xe1:
209791 case 0xe2:
209792 case 0xe3:
209793 case 0xef: {
209795 if( j>0 ){
209804 if( strncmp(z+i,"null",4)==0 && !sqlite3Isalnum(z[i+4]) ){
209815 for(k=0; k<sizeof(aNanInfName)/sizeof(aNanInfName[0]); k++){
209818 if( sqlite3StrNICmp(&z[i], aNanInfName[k].zMatch, nn)!=0 ){
209838 ** Parse a complete JSON string. Return 0 on success or non-zero if there
209851 i = jsonTranslateTextToBlob(pParse, 0);
209853 if( i>0 ){
209855 assert( pParse->iDepth==0 );
209857 assert( jsonbValidityCheck(pParse, 0, pParse->nBlob, 0)==0 );
209871 if( i<=0 ){
209872 if( pCtx!=0 ){
209882 return 0;
209892 memset(&px, 0, sizeof(px));
209901 (void)jsonTranslateTextToBlob(&px, 0);
209906 assert( px.nBlobAlloc>0 );
209915 ** beginning of the payload. Return 0 on error.
209928 *pSz = 0;
209929 return 0;
209935 *pSz = 0;
209936 return 0;
209942 *pSz = 0;
209943 return 0;
209950 || pParse->aBlob[i+1]!=0
209951 || pParse->aBlob[i+2]!=0
209952 || pParse->aBlob[i+3]!=0
209953 || pParse->aBlob[i+4]!=0
209955 *pSz = 0;
209956 return 0;
209965 *pSz = 0;
209966 return 0;
209994 if( n==0 ){
209998 switch( pParse->aBlob[i] & 0x0f ){
210013 if( sz==0 ) goto malformed_jsonb;
210019 sqlite3_uint64 u = 0;
210021 int bOverflow = 0;
210022 if( sz==0 ) goto malformed_jsonb;
210023 if( zIn[0]=='-' ){
210026 }else if( zIn[0]=='+' ){
210033 }else if( (u>>60)!=0 ){
210043 u32 k = 0;
210045 if( sz==0 ) goto malformed_jsonb;
210046 if( zIn[0]=='-' ){
210051 jsonAppendChar(pOut, '0');
210056 jsonAppendChar(pOut, '0');
210063 if( pOut->nUsed+sz+2<=pOut->nAlloc || jsonStringGrow(pOut, sz+2)==0 ){
210077 while( sz2>0 ){
210078 for(k=0; k<sz2 && (jsonIsOk[(u8)zIn[k]] || zIn[k]=='\''); k++){}
210079 if( k>0 ){
210087 if( zIn[0]=='"' ){
210093 if( zIn[0]<=0x1f ){
210095 jsonAppendControlChar(pOut, zIn[0]);
210100 assert( zIn[0]=='\\' );
210124 case '0':
210135 case 0xe2:
210137 ** whitespace. Not that in UTF8, U+2028 is 0xe2 0x80 0x29.
210140 || 0x80!=(u8)zIn[2]
210141 || (0xa8!=(u8)zIn[3] && 0xa9!=(u8)zIn[3])
210169 while( j<iEnd && pOut->eErr==0 ){
210174 if( sz>0 ) jsonStringTrimOneChar(pOut);
210179 int x = 0;
210183 while( j<iEnd && pOut->eErr==0 ){
210187 if( (x & 1)!=0 || j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
210188 if( sz>0 ) jsonStringTrimOneChar(pOut);
210216 for(jj=0; jj<pPretty->nIndent; jj++){
210246 if( n==0 ){
210250 switch( pParse->aBlob[i] & 0x0f ){
210258 while( pOut->eErr==0 ){
210279 while( pOut->eErr==0 ){
210313 u32 k = 0;
210316 for(i=iRoot+n; n>0 && i<iEnd; i+=sz+n, k++){
210327 u32 sz = 0;
210329 assert( pParse->delta!=0 );
210340 ** If the JSONB at aIns[0..nIns-1] can be expanded (by denormalizing the
210369 static const u8 aType[] = { 0xc0, 0xd0, 0, 0xe0, 0, 0, 0, 0xf0 };
210371 if( (aIns[0]&0x0f)<=2 ) return 0; /* Cannot enlarge NULL, true, false */
210372 switch( aIns[0]>>4 ){
210374 if( ((1<<d)&0x116)==0 ) return 0; /* d must be 1, 2, 4, or 8 */
210380 if( ((1<<d)&0x8a)==0) return 0; /* d must be 1, 3, or 7 */
210386 if( d!=2 && d!=6 ) return 0; /* d must be 2 or 6 */
210392 if( d!=4 ) return 0; /* d must be 4 */
210398 return 0; /* No solution */
210401 assert( i>=2 && i<=9 && aType[i-2]!=0 );
210402 aOut[0] = (aIns[0] & 0x0f) | aType[i-2];
210407 aOut[i] = szPayload & 0xff;
210411 assert( (szPayload>>8)==0 );
210436 if( d<0 && d>=(-8) && aIns!=0
210441 if( d!=0 ){
210461 ** 0x5c 0x0a
210462 ** 0x5c 0x0d
210463 ** 0x5c 0x0d 0x0a
210464 ** 0x5c 0xe2 0x80 0xa8
210465 ** 0x5c 0xe2 0x80 0xa9
210468 u32 i = 0;
210483 if( 0xe2==(u8)z[i+1]
210485 && 0x80==(u8)z[i+2]
210486 && (0xa8==(u8)z[i+3] || 0xa9==(u8)z[i+3])
210497 ** Input z[0..n] defines JSON escape sequence including the leading '\\'.
210506 assert( n>0 );
210507 assert( z[0]=='\\' );
210520 if( (v & 0xfc00)==0xd800
210524 && ((vlo = jsonHexToInt4(&z[8]))&0xfc00)==0xdc00
210526 *piOut = ((v&0x3ff)<<10) + (vlo&0x3ff) + 0x10000;
210539 case '0': {
210540 /* JSON5 requires that the \0 escape not be followed by a digit.
210541 ** But SQLite did not enforce this restriction in versions 3.42.0
210547 *piOut = 0;
210550 *piOut = (n>2 && sqlite3Isdigit(z[2])) ? JSON_INVALID_CHAR : 0;
210566 case 0xe2:
210570 if( nSkip==0 ){
210574 *piOut = 0;
210593 ** 0 if they differ.
210607 assert( rawLeft==0 || rawRight==0 );
210609 if( nLeft==0 ){
210610 cLeft = 0;
210611 }else if( rawLeft || zLeft[0]!='\\' ){
210612 cLeft = ((u8*)zLeft)[0];
210613 if( cLeft>=0xc0 ){
210627 if( nRight==0 ){
210628 cRight = 0;
210629 }else if( rawRight || zRight[0]!='\\' ){
210630 cRight = ((u8*)zRight)[0];
210631 if( cRight>=0xc0 ){
210645 if( cLeft!=cRight ) return 0;
210646 if( cLeft==0 ) return 1;
210652 ** 0 if they differ. Return -1 if an OOM occurs.
210665 if( nLeft!=nRight ) return 0;
210666 return memcmp(zLeft, zRight, nLeft)==0;
210676 #define JSON_LOOKUP_ERROR 0xffffffff
210677 #define JSON_LOOKUP_NOTFOUND 0xfffffffe
210678 #define JSON_LOOKUP_PATHERROR 0xfffffffd
210711 memset(pIns, 0, sizeof(*pIns));
210713 if( zTail[0]==0 ){
210717 rc = 0;
210721 pIns->aBlob = (u8*)&emptyObject[zTail[0]=='.'];
210725 rc = jsonLookupStep(pIns, 0, zTail, 0);
210758 if( zPath[0]==0 ){
210763 if( iLabel>0 ){
210767 jsonBlobEdit(pParse, iRoot, sz, 0, 0);
210778 if( zPath[0]=='.' ){
210782 if( zPath[0]=='"' ){
210785 if( zPath[i]=='\\' && zPath[i+1]!=0 ) i++;
210793 testcase( nKey==0 );
210794 rawKey = memchr(zKey, '\\', nKey)==0;
210797 for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){}
210799 if( nKey==0 ){
210803 if( (x & 0x0f)!=JSONB_OBJECT ) return JSON_LOOKUP_NOTFOUND;
210810 x = pParse->aBlob[j] & 0x0f;
210813 if( n==0 ) return JSON_LOOKUP_ERROR;
210820 if( ((pParse->aBlob[v])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
210822 if( n==0 || v+n+sz>iEnd ) return JSON_LOOKUP_ERROR;
210823 assert( j>0 );
210829 if( ((pParse->aBlob[j])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
210831 if( n==0 ) return JSON_LOOKUP_ERROR;
210841 memset(&ix, 0, sizeof(ix));
210843 jsonBlobAppendNode(&ix, rawKey?JSONB_TEXTRAW:JSONB_TEXT5, nKey, 0);
210851 jsonBlobEdit(pParse, j, 0, 0, nIns);
210853 assert( pParse->aBlob!=0 ); /* Because pParse->oom!=0 */
210854 assert( ix.aBlob!=0 ); /* Because pPasre->oom!=0 */
210867 }else if( zPath[0]=='[' ){
210868 x = pParse->aBlob[iRoot] & 0x0f;
210871 k = 0;
210874 k = k*10 + zPath[i] - '0';
210882 unsigned int nn = 0;
210885 nn = nn*10 + zPath[i] - '0';
210901 if( k==0 ){
210902 rc = jsonLookupStep(pParse, j, &zPath[i+1], 0);
210908 if( n==0 ) return JSON_LOOKUP_ERROR;
210912 if( k>0 ) return JSON_LOOKUP_NOTFOUND;
210922 jsonBlobEdit(pParse, j, 0, v.aBlob, v.nBlob);
210946 if( NEVER(aBlob==0) ) return;
210947 memset(&x, 0, sizeof(x));
210951 jsonTranslateBlobToText(&x, 0, &s);
210952 jsonReturnString(&s, 0, 0);
210975 if( n==0 ){
210979 switch( pParse->aBlob[i] & 0x0f ){
210992 sqlite3_result_int(pCtx, 0);
210997 sqlite3_int64 iRes = 0;
210999 int bNeg = 0;
211001 if( sz==0 ) goto returnfromblob_malformed;
211010 if( z==0 ) goto returnfromblob_oom;
211013 if( rc==0 ){
211029 if( sz==0 ) goto returnfromblob_malformed;
211032 if( z==0 ) goto returnfromblob_oom;
211035 if( rc<=0 ) goto returnfromblob_malformed;
211054 if( zOut==0 ) goto returnfromblob_oom;
211055 for(iIn=iOut=0; iIn<sz; iIn++){
211060 if( v<=0x7f ){
211062 }else if( v<=0x7ff ){
211064 zOut[iOut++] = (char)(0xc0 | (v>>6));
211065 zOut[iOut++] = 0x80 | (v&0x3f);
211066 }else if( v<0x10000 ){
211068 zOut[iOut++] = 0xe0 | (v>>12);
211069 zOut[iOut++] = 0x80 | ((v>>6)&0x3f);
211070 zOut[iOut++] = 0x80 | (v&0x3f);
211075 zOut[iOut++] = 0xf0 | (v>>18);
211076 zOut[iOut++] = 0x80 | ((v>>12)&0x3f);
211077 zOut[iOut++] = 0x80 | ((v>>6)&0x3f);
211078 zOut[iOut++] = 0x80 | (v&0x3f);
211086 zOut[iOut] = 0;
211092 int flags = textOnly ? 0 : SQLITE_PTR_TO_INT(sqlite3_user_data(pCtx));
211138 static u8 aNull[] = { 0x00 };
211139 memset(pParse, 0, sizeof(pParse[0]));
211145 return 0;
211157 if( zJson==0 ) return 1;
211164 memset(pParse, 0, sizeof(pParse[0]));
211175 jsonBlobAppendNode(pParse, JSONB_NULL, 0, 0);
211179 if( z==0 ) return 1;
211180 if( z[0]=='I' ){
211182 }else if( z[0]=='-' && z[1]=='I' ){
211193 if( z==0 ) return 1;
211202 return 0;
211217 if( ctx==0 ) return zMsg;
211224 return 0;
211227 /* argv[0] is a BLOB that seems likely to be a JSONB. Subsequent
211242 u32 rc = 0;
211243 const char *zPath = 0;
211249 flgs = argc==1 ? 0 : JSON_EDITABLE;
211250 p = jsonParseFuncArg(ctx, argv[0], flgs);
211251 if( p==0 ) return;
211255 if( zPath==0 ){
211260 if( zPath[0]!='$' ) goto jsonInsertIntoBlob_patherror;
211266 if( zPath[1]==0 ){
211268 jsonBlobEdit(p, 0, p->nBlob, ax.aBlob, ax.nBlob);
211270 rc = 0;
211275 p->delta = 0;
211276 rc = jsonLookupStep(p, 0, zPath+1, 0);
211317 ** '\r', '\t', '-', or a digit '0' through '9'. Of these, only a subset
211325 u32 n, sz = 0;
211327 if( sqlite3_value_type(pArg)!=SQLITE_BLOB ) return 0;
211330 if( p->nBlob>0
211331 && ALWAYS(p->aBlob!=0)
211332 && ((c = p->aBlob[0]) & 0x0f)<=JSONB_OBJECT
211333 && (n = jsonbPayloadSize(p, 0, &sz))>0
211335 && ((c & 0x0f)>JSONB_FALSE || sz==0)
211337 || (c!=0x7b && c!=0x5b && !sqlite3Isdigit(c))
211338 || jsonbValidityCheck(p, 0, p->nBlob, 1)==0)
211342 p->aBlob = 0;
211343 p->nBlob = 0;
211344 return 0;
211369 JsonParse *p = 0; /* Value to be returned */
211370 JsonParse *pFromCache = 0; /* Value taken from cache */
211373 assert( ctx!=0 );
211376 return 0;
211381 if( (flgs & JSON_EDITABLE)==0 ){
211388 if( p==0 ) goto json_pfa_oom;
211389 memset(p, 0, sizeof(*p));
211392 if( pFromCache!=0 ){
211395 if( p->aBlob==0 ) goto json_pfa_oom;
211404 if( (flgs & JSON_EDITABLE)!=0 && jsonBlobMakeEditable(p, 0)==0 ){
211425 if( p->nJson==0 ) goto json_pfa_malformed;
211426 assert( p->zJson!=0 );
211427 if( jsonConvertTextToBlob(p, (flgs & JSON_KEEPERROR) ? 0 : ctx) ){
211433 return 0;
211440 if( zNew==0 ) goto json_pfa_oom;
211443 p->zJson[p->nJson] = 0;
211452 p = 0;
211465 return 0;
211472 return 0;
211491 if( p->nBlobAlloc>0 && !p->bReadOnly ){
211493 p->nBlobAlloc = 0;
211500 p->delta = 0;
211501 jsonTranslateBlobToText(p, 0, &s);
211525 u32 i, n, nn, sz = 0;
211527 u8 x = pParse->aBlob[iStart] & 0x0f;
211534 if( nn==0 ) nn = 1;
211535 if( sz>0 && x<JSONB_ARRAY ){
211538 for(i=0; i<nn; i++){
211541 if( n==0 ){
211543 iStart = n==0 ? iStart+1 : iEnd;
211550 if( pParse->nBlobAlloc>0 && iEnd>pParse->nBlobAlloc ){
211573 showContent = 0;
211579 showContent = 0;
211584 showContent = 0;
211589 if( sz==0 && x<=JSONB_FALSE ){
211596 if( c<0x20 || c>=0x7f ) c = '.';
211608 if( pParse==0 ){
211615 if( pParse->nBlob==0 ) return;
211616 printf("content (bytes 0..%u):\n", pParse->nBlob-1);
211618 sqlite3StrAccumInit(&out, 0, zBuf, sizeof(zBuf), 1000000);
211619 jsonDebugPrintBlob(pParse, 0, pParse->nBlob, 0, &out);
211641 sqlite3StrAccumInit(&out, 0, 0, 0, 1000000);
211642 p = jsonParseFuncArg(ctx, argv[0], 0);
211643 if( p==0 ) return;
211645 jsonDebugPrintBlob(p, 0, p->nBlob, 0, &out);
211674 jsonAppendSqlValue(&jx, argv[0]);
211675 jsonReturnString(&jx, 0, 0);
211694 for(i=0; i<argc; i++){
211699 jsonReturnString(&jx, 0, 0);
211708 ** Return 0 if the input is not a well-formed JSON array.
211716 sqlite3_int64 cnt = 0;
211718 u8 eErr = 0;
211720 p = jsonParseFuncArg(ctx, argv[0], 0);
211721 if( p==0 ) return;
211724 if( zPath==0 ){
211728 i = jsonLookupStep(p, 0, zPath[0]=='$' ? zPath+1 : "@", 0);
211738 i = 0;
211741 i = 0;
211743 if( (p->aBlob[i] & 0x0f)==JSONB_ARRAY ){
211753 for(i=0; i<n && (sqlite3Isalnum(z[i]) || z[i]=='_'); i++){}
211782 JsonParse *p = 0; /* The parse */
211788 p = jsonParseFuncArg(ctx, argv[0], 0);
211789 if( p==0 ) return;
211800 if( zPath==0 ) goto json_extract_error;
211802 if( zPath[0]=='$' ){
211803 j = jsonLookupStep(p, 0, zPath+1, 0);
211821 if( zPath[0]=='-' ) jsonAppendRawNZ(&jx,"#",1);
211827 }else if( zPath[0]=='[' && nPath>=3 && zPath[nPath-1]==']' ){
211835 j = jsonLookupStep(p, 0, jx.zBuf, 0);
211846 jsonReturnString(&jx, 0, 0);
211848 assert( (flags & JSON_BLOB)==0 );
211851 jsonReturnFromBlob(p, j, ctx, 0);
211852 if( (flags & (JSON_SQL|JSON_BLOB))==0
211853 && (p->aBlob[j]&0x0f)>=JSONB_ARRAY
211879 jsonReturnString(&jx, 0, 0);
211880 if( (flags & JSON_BLOB)==0 ){
211893 #define JSON_MERGE_OK 0 /* Success */
211951 u32 n, sz=0; /* Return values from jsonbPayloadSize() */
211957 u32 iTLabel = 0; /* Index of the label */
211958 u32 nTLabel = 0; /* Header size in bytes for the target label */
211959 u32 szTLabel = 0; /* Size of the target label payload */
211960 u32 iTValue = 0; /* Index of the target value */
211961 u32 nTValue = 0; /* Header size of the target value */
211962 u32 szTValue = 0; /* Payload size for the target value */
211974 assert( iTarget>=0 && iTarget<pTarget->nBlob );
211975 assert( iPatch>=0 && iPatch<pPatch->nBlob );
211976 x = pPatch->aBlob[iPatch] & 0x0f;
211982 sz = 0;
211988 x = pTarget->aBlob[iTarget] & 0x0f;
211991 jsonBlobEdit(pTarget, iTarget+n, sz, 0, 0);
211993 pTarget->aBlob[iTarget] = (x & 0xf0) | JSONB_OBJECT;
211996 if( NEVER(n==0) ) return JSON_MERGE_BADPATCH;
212000 if( NEVER(n==0) ) return JSON_MERGE_BADTARGET;
212006 ePLabel = pPatch->aBlob[iPCursor] & 0x0f;
212011 if( nPLabel==0 ) return JSON_MERGE_BADPATCH;
212015 if( nPValue==0 ) return JSON_MERGE_BADPATCH;
212024 eTLabel = pTarget->aBlob[iTCursor] & 0x0f;
212029 if( nTLabel==0 ) return JSON_MERGE_BADTARGET;
212033 if( nTValue==0 ) return JSON_MERGE_BADTARGET;
212045 x = pPatch->aBlob[iPValue] & 0x0f;
212048 if( x==0 ){
212050 jsonBlobEdit(pTarget, iTLabel, nTLabel+szTLabel+nTValue+szTValue, 0,0);
212056 pTarget->delta = 0;
212061 }else if( x>0 ){ /* Algorithm line 13 */
212064 if( (pPatch->aBlob[iPValue] & 0x0f)!=JSONB_OBJECT ){ /* Line 14 */
212065 jsonBlobEdit(pTarget, iTEnd, 0, 0, szPValue+nPValue+szNew);
212072 jsonBlobEdit(pTarget, iTEnd, 0, 0, szNew+1);
212075 pTarget->aBlob[iTEnd+szNew] = 0x00;
212077 pTarget->delta = 0;
212105 pTarget = jsonParseFuncArg(ctx, argv[0], JSON_EDITABLE);
212106 if( pTarget==0 ) return;
212107 pPatch = jsonParseFuncArg(ctx, argv[1], 0);
212109 rc = jsonMergePatch(pTarget, 0, pPatch, 0);
212145 for(i=0; i<argc; i+=2){
212159 jsonReturnString(&jx, 0, 0);
212176 const char *zPath = 0; /* Path of element to be removed */
212181 p = jsonParseFuncArg(ctx, argv[0], argc>1 ? JSON_EDITABLE : 0);
212182 if( p==0 ) return;
212185 if( zPath==0 ){
212188 if( zPath[0]!='$' ){
212191 if( zPath[1]==0 ){
212196 p->delta = 0;
212197 rc = jsonLookupStep(p, 0, zPath+1, 0);
212233 if( (argc&1)==0 ) {
212260 int bIsSet = (flags&JSON_ISSET)!=0;
212263 if( (argc&1)==0 ) {
212283 const char *zPath = 0;
212286 p = jsonParseFuncArg(ctx, argv[0], 0);
212287 if( p==0 ) return;
212290 if( zPath==0 ) goto json_type_done;
212291 if( zPath[0]!='$' ){
212295 i = jsonLookupStep(p, 0, zPath+1, 0);
212307 i = 0;
212309 sqlite3_result_text(ctx, jsonbType[p->aBlob[i]&0x0f], -1, SQLITE_STATIC);
212332 memset(&x, 0, sizeof(x));
212333 x.pParse = jsonParseFuncArg(ctx, argv[0], 0);
212334 if( x.pParse==0 ) return;
212337 if( argc==1 || (x.zIndent = (const char*)sqlite3_value_text(argv[1]))==0 ){
212343 jsonTranslateBlobToPrettyText(&x, 0);
212344 jsonReturnString(&s, 0, 0);
212355 ** 0x01 Canonical RFC-8259 JSON text
212356 ** 0x02 JSON text with optional JSON-5 extensions
212357 ** 0x04 Superficially appears to be JSONB
212358 ** 0x08 Strictly well-formed JSONB
212403 ** * Return 0 if the input is not well-formed.
212412 u8 res = 0;
212420 flags = f & 0x0f;
212422 switch( sqlite3_value_type(argv[0]) ){
212426 sqlite3_result_int(ctx, 0);
212432 memset(&py, 0, sizeof(py));
212433 if( jsonArgIsJsonb(argv[0], &py) ){
212434 if( flags & 0x04 ){
212438 }else if( flags & 0x08 ){
212441 res = 0==jsonbValidityCheck(&py, 0, py.nBlob, 1);
212451 if( (flags & 0x3)==0 ) break;
212452 memset(&px, 0, sizeof(px));
212454 p = jsonParseFuncArg(ctx, argv[0], JSON_KEEPERROR);
212460 }else if( (flags & 0x02)!=0 || p->hasNonstd==0 ){
212484 ** that the input was not valid JSON, or return 0 if the input text looks
212492 i64 iErrPos = 0; /* Error position to be returned */
212497 memset(&s, 0, sizeof(s));
212499 if( jsonArgIsJsonb(argv[0], &s) ){
212500 iErrPos = (i64)jsonbValidityCheck(&s, 0, s.nBlob, 1);
212502 s.zJson = (char*)sqlite3_value_text(argv[0]);
212503 if( s.zJson==0 ) return; /* NULL input or OOM */
212504 s.nJson = sqlite3_value_bytes(argv[0]);
212505 if( jsonConvertTextToBlob(&s,0) ){
212511 assert( s.zJson!=0 ); /* Because s.oom is false */
212512 for(k=0; k<s.iErr && ALWAYS(s.zJson[k]); k++){
212513 if( (s.zJson[k] & 0xc0)!=0x80 ) iErrPos++;
212520 if( iErrPos<0 ){
212544 if( pStr->zBuf==0 ){
212551 jsonAppendSqlValue(pStr, argv[0]);
212556 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
212563 jsonReturnString(pStr, 0, 0);
212588 jsonArrayCompute(ctx, 0);
212607 int inStr = 0;
212608 int nNest = 0;
212614 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
212634 z[pStr->nUsed] = 0;
212640 # define jsonGroupInverse 0
212660 z = (const char*)sqlite3_value_text(argv[0]);
212662 if( pStr->zBuf==0 ){
212665 }else if( pStr->nUsed>1 && z!=0 ){
212669 if( z!=0 ){
212678 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
212685 jsonReturnString(pStr, 0, 0);
212710 jsonObjectCompute(ctx, 0);
212766 #define JEACH_KEY 0
212790 if( pNew==0 ) return SQLITE_NOMEM;
212811 if( pCur==0 ) return SQLITE_NOMEM;
212834 p->iRowid = 0;
212835 p->i = 0;
212836 p->aParent = 0;
212837 p->nParent = 0;
212838 p->nParentAlloc = 0;
212839 p->iEnd = 0;
212840 p->eType = 0;
212866 u32 sz = 0;
212878 assert( p->nParent>0 );
212883 u32 n, sz = 0, k, i;
212885 int needQuote = 0;
212889 if( sz==0 || !sqlite3Isalpha(z[0]) ){
212892 for(i=0; i<sz; i++){
212913 u8 levelChange = 0;
212914 u32 n, sz = 0;
212916 x = p->sParse.aBlob[i] & 0x0f;
212925 if( pNew==0 ) return SQLITE_NOMEM;
212945 while( p->nParent>0 && p->i >= p->aParent[p->nParent-1].iEnd ){
212951 if( p->nParent>0 ){
212954 p->eType = p->sParse.aBlob[iVal] & 0x0f;
212956 p->eType = 0;
212960 u32 n, sz = 0;
212972 /* Length of the path for rowid==0 in bRecursive mode.
212977 if( p->iRowid==0 && p->bRecursive && n>=2 ){
212981 u32 x, sz = 0;
212983 z[n] = 0;
212984 assert( p->sParse.eEdit==0 );
212985 x = jsonLookupStep(&p->sParse, 0, z+1, 0);
213004 if( p->nParent==0 ){
213009 if( n==0 ){
213033 if( (p->sParse.aBlob[i] & 0x0f)>=JSONB_ARRAY ){
213040 u8 eType = p->sParse.aBlob[i] & 0x0f;
213046 if( (p->sParse.aBlob[i] & 0x0f)<JSONB_ARRAY ){
213056 if( p->nParent>0 && p->bRecursive ){
213080 if( p->sParse.zJson==0 ){
213102 ** and 0 otherwise.
213110 int unusableMask = 0; /* Mask of unusable JSON and ROOT constraints */
213111 int idxMask = 0; /* Mask of usable == constraints JSON and ROOT */
213118 aIdx[0] = aIdx[1] = -1;
213120 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
213125 assert( iCol==0 || iCol==1 );
213126 testcase( iCol==0 );
213128 if( pConstraint->usable==0 ){
213135 if( pIdxInfo->nOrderBy>0
213136 && pIdxInfo->aOrderBy[0].iColumn<0
213137 && pIdxInfo->aOrderBy[0].desc==0
213142 if( (unusableMask & ~idxMask)!=0 ){
213147 if( aIdx[0]<0 ){
213151 pIdxInfo->idxNum = 0;
213154 i = aIdx[0];
213157 if( aIdx[1]<0 ){
213176 const char *zRoot = 0;
213182 if( idxNum==0 ) return SQLITE_OK;
213183 memset(&p->sParse, 0, sizeof(p->sParse));
213186 if( jsonArgIsJsonb(argv[0], &p->sParse) ){
213189 p->sParse.zJson = (char*)sqlite3_value_text(argv[0]);
213190 p->sParse.nJson = sqlite3_value_bytes(argv[0]);
213191 if( p->sParse.zJson==0 ){
213192 p->i = p->iEnd = 0;
213195 if( jsonConvertTextToBlob(&p->sParse, 0) ){
213204 if( zRoot==0 ) return SQLITE_OK;
213205 if( zRoot[0]!='$' ){
213207 cur->pVtab->zErrMsg = jsonBadPathError(0, zRoot);
213212 if( zRoot[1]==0 ){
213213 i = p->i = 0;
213214 p->eType = 0;
213216 i = jsonLookupStep(&p->sParse, 0, zRoot+1, 0);
213219 p->i = 0;
213220 p->eType = 0;
213221 p->iEnd = 0;
213225 cur->pVtab->zErrMsg = jsonBadPathError(0, zRoot);
213239 i = p->i = 0;
213240 p->eType = 0;
213244 p->nParent = 0;
213247 if( (p->sParse.aBlob[i] & 0x0f)>=JSONB_ARRAY && !p->bRecursive ){
213249 p->eType = p->sParse.aBlob[i] & 0x0f;
213251 if( p->aParent==0 ) return SQLITE_NOMEM;
213254 p->aParent[0].iKey = 0;
213255 p->aParent[0].iEnd = p->iEnd;
213256 p->aParent[0].iHead = p->i;
213257 p->aParent[0].iValue = i;
213270 0, /* iVersion */
213271 0, /* xCreate */
213275 0, /* xDestroy */
213283 0, /* xUpdate */
213284 0, /* xBegin */
213285 0, /* xSync */
213286 0, /* xCommit */
213287 0, /* xRollback */
213288 0, /* xFindMethod */
213289 0, /* xRename */
213290 0, /* xSavepoint */
213291 0, /* xRelease */
213292 0, /* xRollbackTo */
213293 0, /* xShadowName */
213294 0 /* xIntegrity */
213299 0, /* iVersion */
213300 0, /* xCreate */
213304 0, /* xDestroy */
213312 0, /* xUpdate */
213313 0, /* xBegin */
213314 0, /* xSync */
213315 0, /* xCommit */
213316 0, /* xRollback */
213317 0, /* xFindMethod */
213318 0, /* xRename */
213319 0, /* xSavepoint */
213320 0, /* xRelease */
213321 0, /* xRollbackTo */
213322 0, /* xShadowName */
213323 0 /* xIntegrity */
213340 JFUNCTION(json, 1,1,1, 0,0,0, jsonRemoveFunc),
213341 JFUNCTION(jsonb, 1,1,0, 0,1,0, jsonRemoveFunc),
213342 JFUNCTION(json_array, -1,0,1, 1,0,0, jsonArrayFunc),
213343 JFUNCTION(jsonb_array, -1,0,1, 1,1,0, jsonArrayFunc),
213344 JFUNCTION(json_array_length, 1,1,0, 0,0,0, jsonArrayLengthFunc),
213345 JFUNCTION(json_array_length, 2,1,0, 0,0,0, jsonArrayLengthFunc),
213346 JFUNCTION(json_error_position,1,1,0, 0,0,0, jsonErrorFunc),
213347 JFUNCTION(json_extract, -1,1,1, 0,0,0, jsonExtractFunc),
213348 JFUNCTION(jsonb_extract, -1,1,0, 0,1,0, jsonExtractFunc),
213349 JFUNCTION(->, 2,1,1, 0,0,JSON_JSON, jsonExtractFunc),
213350 JFUNCTION(->>, 2,1,0, 0,0,JSON_SQL, jsonExtractFunc),
213351 JFUNCTION(json_insert, -1,1,1, 1,0,0, jsonSetFunc),
213352 JFUNCTION(jsonb_insert, -1,1,0, 1,1,0, jsonSetFunc),
213353 JFUNCTION(json_object, -1,0,1, 1,0,0, jsonObjectFunc),
213354 JFUNCTION(jsonb_object, -1,0,1, 1,1,0, jsonObjectFunc),
213355 JFUNCTION(json_patch, 2,1,1, 0,0,0, jsonPatchFunc),
213356 JFUNCTION(jsonb_patch, 2,1,0, 0,1,0, jsonPatchFunc),
213357 JFUNCTION(json_pretty, 1,1,0, 0,0,0, jsonPrettyFunc),
213358 JFUNCTION(json_pretty, 2,1,0, 0,0,0, jsonPrettyFunc),
213359 JFUNCTION(json_quote, 1,0,1, 1,0,0, jsonQuoteFunc),
213360 JFUNCTION(json_remove, -1,1,1, 0,0,0, jsonRemoveFunc),
213361 JFUNCTION(jsonb_remove, -1,1,0, 0,1,0, jsonRemoveFunc),
213362 JFUNCTION(json_replace, -1,1,1, 1,0,0, jsonReplaceFunc),
213363 JFUNCTION(jsonb_replace, -1,1,0, 1,1,0, jsonReplaceFunc),
213364 JFUNCTION(json_set, -1,1,1, 1,0,JSON_ISSET, jsonSetFunc),
213365 JFUNCTION(jsonb_set, -1,1,0, 1,1,JSON_ISSET, jsonSetFunc),
213366 JFUNCTION(json_type, 1,1,0, 0,0,0, jsonTypeFunc),
213367 JFUNCTION(json_type, 2,1,0, 0,0,0, jsonTypeFunc),
213368 JFUNCTION(json_valid, 1,1,0, 0,0,0, jsonValidFunc),
213369 JFUNCTION(json_valid, 2,1,0, 0,0,0, jsonValidFunc),
213371 JFUNCTION(json_parse, 1,1,0, 0,0,0, jsonParseFunc),
213373 WAGGREGATE(json_group_array, 1, 0, 0,
213377 WAGGREGATE(jsonb_group_array, 1, JSON_BLOB, 0,
213380 WAGGREGATE(json_group_object, 2, 0, 0,
213383 WAGGREGATE(jsonb_group_object,2, JSON_BLOB, 0,
213406 for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
213407 rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
213505 # define NEVER(X) (0)
213507 # define ALWAYS(X) ((X)?1:(assert(0),0))
213508 # define NEVER(X) ((X)?(assert(0),1):0)
213514 #define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
213525 # define FOUR_BYTE_ALIGNED(X) ((((char*)(X) - (char*)0) & 3)==0)
213603 ** headed by the node (leaf nodes have RtreeNode.iNode==0).
213631 #define RTREE_COORD_REAL32 0
213642 # define RTREE_ZERO 0
213663 ** the node that the RtreeSearchPoint represents. When iLevel==0, however,
213670 u8 iLevel; /* 0=entries. 1=leaf node. 2+ for higher */
213770 #define RTREE_EQ 0x41 /* A */
213771 #define RTREE_LE 0x42 /* B */
213772 #define RTREE_LT 0x43 /* C */
213773 #define RTREE_GE 0x44 /* D */
213774 #define RTREE_GT 0x45 /* E */
213775 #define RTREE_MATCH 0x46 /* F: Old-style sqlite3_rtree_geometry_callback() */
213776 #define RTREE_QUERY 0x47 /* G: New-style sqlite3_rtree_query_callback() */
213782 #define RTREE_TRUE 0x3f /* ? */
213783 #define RTREE_FALSE 0x40 /* @ */
213855 /* What version of GCC is being used. 0 means GCC is not being used .
213864 # define GCC_VERSION 0
213873 unsigned int sqlite3RtreeTestcase = 0;
213921 # define SQLITE_BYTEORDER 0
213926 /* What version of MSVC is being used. 0 means MSVC is not being used */
213931 # define MSVC_VERSION 0
213940 return (p[0]<<8) + p[1];
213952 (((u32)p[0]) << 24) +
213955 (((u32)p[3]) << 0)
213974 (((u64)p[0]) << 56) +
213981 (((u64)p[7]) << 0)
213992 p[0] = (i>> 8)&0xFF;
213993 p[1] = (i>> 0)&0xFF;
214011 p[0] = (i>>24)&0xFF;
214012 p[1] = (i>>16)&0xFF;
214013 p[2] = (i>> 8)&0xFF;
214014 p[3] = (i>> 0)&0xFF;
214028 p[0] = (i>>56)&0xFF;
214029 p[1] = (i>>48)&0xFF;
214030 p[2] = (i>>40)&0xFF;
214031 p[3] = (i>>32)&0xFF;
214032 p[4] = (i>>24)&0xFF;
214033 p[5] = (i>>16)&0xFF;
214034 p[6] = (i>> 8)&0xFF;
214035 p[7] = (i>> 0)&0xFF;
214045 assert( p->nRef>0 );
214051 ** Clear the content of node p (set all bytes to 0x00).
214054 memset(&p->zData[2], 0, pRtree->iNodeSize-2);
214068 ** to it. Otherwise, return 0.
214081 assert( pNode->pNext==0 );
214092 if( pNode->iNode!=0 ){
214096 pNode->pNext = 0;
214101 ** Allocate and return new r-tree node. Initially, (RtreeNode.iNode==0),
214110 memset(pNode, 0, sizeof(RtreeNode) + pRtree->iNodeSize);
214126 pRtree->pNodeBlob = 0;
214140 RtreeNode *pNode = 0;
214145 if( (pNode = nodeHashLookup(pRtree, iNode))!=0 ){
214157 pRtree->pNodeBlob = 0;
214165 if( pRtree->pNodeBlob==0 ){
214167 "data", iNode, 0,
214171 *ppNode = 0;
214188 pNode->isDirty = 0;
214189 pNode->pNext = 0;
214191 pRtree->iNodeSize, 0);
214221 if( pNode!=0 ){
214235 *ppNode = 0;
214253 for(ii=0; ii<pRtree->nDim2; ii++){
214312 pNode->isDirty = 0;
214315 if( pNode->iNode==0 && rc==SQLITE_OK ){
214330 assert( pNode->nRef>0 );
214331 assert( pRtree->nNodeRef>0 );
214333 if( pNode->nRef==0 ){
214391 int ii = 0;
214434 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
214450 if( pRtree->nBusy==0 ){
214451 pRtree->inWrTrans = 0;
214452 assert( pRtree->nCursor==0 );
214454 assert( pRtree->nNodeRef==0 || pRtree->bCorrupt );
214495 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
214515 memset(pCsr, 0, sizeof(RtreeCursor));
214535 for(i=0; i<pCsr->nConstraint; i++){
214543 pCsr->aConstraint = 0;
214545 for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
214548 memset(pCsr, 0, sizeof(RtreeCursor));
214560 assert( pRtree->nCursor>0 );
214565 if( pRtree->nCursor==0 && pRtree->inWrTrans==0 ){
214609 c.u = ((c.u>>24)&0xff)|((c.u>>8)&0xff00)| \
214610 ((c.u&0xff)<<24)|((c.u&0xff00)<<8); \
214622 c.u = ((u32)a[0]<<24) + ((u32)a[1]<<16) \
214654 if( eInt==0 ){
214665 readCoord(pCellData, &c); aCoord[0] = c.f;
214680 readCoord(pCellData, &c); aCoord[0] = c.i;
214684 int eWithin = 0;
214687 if( eWithin==0 ) *peWithin = NOT_WITHIN;
214719 pCellData += 8 + 4*(p->iCoord&0xfe);
214804 for(ii=0; ii<nCell; ii++){
214846 return 0;
214861 p->aNode[i] = 0;
214874 return pCur->bPoint ? &pCur->sPoint : pCur->nPoint ? pCur->aPoint : 0;
214883 assert( ii==0 || ii==1 );
214885 if( pCur->aNode[ii]==0 ){
214886 assert( pRC!=0 );
214887 id = ii ? pCur->aPoint[0].id : pCur->sPoint.id;
214888 *pRC = nodeAcquire(RTREE_OF_CURSOR(pCur), id, 0, &pCur->aNode[ii]);
214905 pNew = sqlite3_realloc64(pCur->aPoint, nNew*sizeof(pCur->aPoint[0]));
214906 if( pNew==0 ) return 0;
214915 while( i>0 ){
214919 if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break;
214939 if( pFirst==0
214946 if( pNew==0 ) return 0;
214950 assert( pCur->aNode[ii]==0 );
214951 pCur->aNode[ii] = pCur->aNode[0];
214953 nodeRelease(RTREE_OF_CURSOR(pCur), pCur->aNode[0]);
214955 pCur->aNode[0] = 0;
214967 #if 0
214970 if( idx<0 ){ printf(" s"); }else{ printf("%2d", idx); }
214987 for(ii=0; ii<pCur->nPoint; ii++){
214988 if( ii>0 || pCur->bPoint ) printf(" ");
215002 assert( i==0 || i==1 );
215005 p->aNode[i] = 0;
215009 p->bPoint = 0;
215011 p->anQueue[p->aPoint[0].iLevel]--;
215013 p->aPoint[0] = p->aPoint[n];
215016 p->aNode[n+1] = 0;
215018 i = 0;
215021 if( k<n && rtreeSearchPointCompare(&p->aPoint[k], &p->aPoint[j])<0 ){
215022 if( rtreeSearchPointCompare(&p->aPoint[k], &p->aPoint[i])<0 ){
215029 if( rtreeSearchPointCompare(&p->aPoint[j], &p->aPoint[i])<0 ){
215060 while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){
215070 for(ii=0; ii<nConstraint; ii++){
215092 for(ii=0; ii<pCur->nPoint; ii++){
215098 x.iCell = 0;
215109 if( p==0 ) return SQLITE_NOMEM;
215121 pCur->atEOF = p==0;
215135 pCsr->bAuxValid = 0;
215173 if( NEVER(p==0) ) return SQLITE_OK;
215175 if( i==0 ){
215190 if( pCsr->pReadAux==0 ){
215191 rc = sqlite3_prepare_v3(pRtree->db, pRtree->zReadAuxSql, -1, 0,
215192 &pCsr->pReadAux, 0);
215216 ** *ppLeaf to 0 and return SQLITE_OK. If an error occurs, set *ppLeaf
215226 *ppLeaf = 0;
215229 i64 iNode = sqlite3_column_int64(pRtree->pReadRowid, 0);
215231 rc = nodeAcquire(pRtree, iNode, 0, ppLeaf);
215250 if( pSrc==0 ) return SQLITE_ERROR;
215254 memset(pInfo, 0, sizeof(*pInfo));
215284 RtreeNode *pRoot = 0;
215287 int iCell = 0;
215299 i64 iRowid = sqlite3_value_int64(argv[0]);
215300 i64 iNode = 0;
215301 int eType = sqlite3_value_numeric_type(argv[0]);
215304 && 0==sqlite3IntFloatCompare(iRowid,sqlite3_value_double(argv[0])))
215309 pLeaf = 0;
215311 if( rc==SQLITE_OK && pLeaf!=0 ){
215312 p = rtreeSearchPointNew(pCsr, RTREE_ZERO, 0);
215313 assert( p!=0 ); /* Always returns pCsr->sPoint */
215314 pCsr->aNode[0] = pLeaf;
215327 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
215328 if( rc==SQLITE_OK && argc>0 ){
215334 memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc);
215335 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
215336 assert( (idxStr==0 && argc==0)
215338 for(ii=0; ii<argc; ii++){
215342 p->iCoord = idxStr[ii*2+1]-'0';
215389 assert( pCsr->bPoint==0 ); /* Due to the resetCursor() call above */
215391 if( NEVER(pNew==0) ){ /* Because pCsr->bPoint was FALSE */
215395 pNew->iCell = 0;
215398 pCsr->aNode[0] = pRoot;
215399 pRoot = 0;
215432 ** = 0x41 ('A')
215433 ** <= 0x42 ('B')
215434 ** < 0x43 ('C')
215435 ** >= 0x44 ('D')
215436 ** > 0x45 ('E')
215437 ** MATCH 0x46 ('F')
215448 int bMatch = 0; /* True if there exists a MATCH constraint */
215451 int iIdx = 0;
215453 memset(zIdxStr, 0, sizeof(zIdxStr));
215459 for(ii=0; ii<pIdxInfo->nConstraint; ii++){
215465 assert( pIdxInfo->idxStr==0 );
215466 for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
215469 if( bMatch==0 && p->usable
215470 && p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ
215474 for(jj=0; jj<ii; jj++){
215475 pIdxInfo->aConstraintUsage[jj].argvIndex = 0;
215476 pIdxInfo->aConstraintUsage[jj].omit = 0;
215495 && ((p->iColumn>0 && p->iColumn<=pRtree->nDim2)
215501 case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; doOmit = 0; break;
215502 case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; doOmit = 0; break;
215504 case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; doOmit = 0; break;
215507 default: op = 0; break;
215511 zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0');
215520 if( iIdx>0 ){
215522 if( pIdxInfo->idxStr==0 ){
215548 default: area *= p->aCoord[1].f - p->aCoord[0].f;
215558 default: area *= (i64)p->aCoord[1].i - (i64)p->aCoord[0].i;
215569 RtreeDValue margin = 0;
215574 }while( ii>=0 );
215582 int ii = 0;
215605 for(ii=0; ii<pRtree->nDim2; ii+=2){
215608 if( a2[0].i<a1[0].i || a2[1].i>a1[1].i ) return 0;
215611 for(ii=0; ii<pRtree->nDim2; ii+=2){
215614 if( a2[0].f<a1[0].f || a2[1].f>a1[1].f ) return 0;
215628 for(ii=0; ii<nCell; ii++){
215631 for(jj=0; jj<pRtree->nDim2; jj+=2){
215636 o = (RtreeDValue)0;
215660 RtreeNode *pNode = 0;
215661 rc = nodeAcquire(pRtree, 1, 0, &pNode);
215663 for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){
215665 sqlite3_int64 iBest = 0;
215666 int bFound = 0;
215670 RtreeNode *pChild = 0;
215676 for(iCell=0; iCell<nCell; iCell++){
215681 if( bFound==0 || area<fMinArea ){
215693 for(iCell=0; iCell<nCell; iCell++){
215701 if( iCell==0
215732 int cnt = 0;
215787 ** nIdx. The aIdx array contains the set of integers from 0 to
215806 int iLeft = 0;
215807 int iRight = 0;
215836 #if 0
215868 int iBestDim = 0;
215869 int iBestSplit = 0;
215880 memset(aaSorted, 0, nByte);
215881 for(ii=0; ii<pRtree->nDim; ii++){
215884 for(jj=0; jj<nCell; jj++){
215890 for(ii=0; ii<pRtree->nDim; ii++){
215894 int iBestLeft = 0;
215908 memcpy(&left, &aCell[aaSorted[ii][0]], sizeof(RtreeCell));
215931 if( ii==0 || margin<fBestMargin ){
215938 memcpy(pBboxLeft, &aCell[aaSorted[iBestDim][0]], sizeof(RtreeCell));
215940 for(ii=0; ii<nCell; ii++){
215960 xSetMapping = ((iHeight==0)?rowidWrite:parentWrite);
215961 if( iHeight>0 ){
215973 if( NEVER(pNode==0) ) return SQLITE_ERROR;
215984 int newCellIsRight = 0;
215991 RtreeNode *pLeft = 0;
215992 RtreeNode *pRight = 0;
216006 memset(aiUsed, 0, sizeof(int)*(nCell+1));
216007 for(i=0; i<nCell; i++){
216031 memset(pLeft->zData, 0, pRtree->iNodeSize);
216032 memset(pRight->zData, 0, pRtree->iNodeSize);
216046 || (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft)))
216076 for(i=0; i<NCELL(pRight); i++){
216087 for(i=0; i<NCELL(pLeft); i++){
216094 }else if( newCellIsRight==0 ){
216100 pRight = 0;
216104 pLeft = 0;
216128 while( rc==SQLITE_OK && pChild->iNode!=1 && pChild->pParent==0 ){
216141 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
216143 if( pTest==0 ){
216144 rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
216163 RtreeNode *pParent = 0;
216172 pNode->pParent = 0;
216217 nodeGetCell(pRtree, pNode, 0, &box);
216270 ** subtree iHeight high (leaf nodes have iHeight==0).
216279 if( iHeight>0 ){
216292 if( iHeight==0 ){
216307 for(ii=0; rc==SQLITE_OK && ii<nCell; ii++){
216346 RtreeNode *pLeaf = 0; /* Leaf node containing record iDelete */
216348 RtreeNode *pRoot = 0; /* Root node of rtree structure */
216352 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
216358 rc = findLeafNode(pRtree, iDelete, &pLeaf, 0);
216362 assert( pLeaf!=0 || rc!=SQLITE_OK || CORRUPT_DB );
216370 rc = deleteCell(pRtree, pLeaf, iCell, 0);
216393 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
216395 RtreeNode *pChild = 0;
216396 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
216445 f = (float)(d*(d<0 ? RNDAWAY : RNDTOWARDS));
216453 f = (float)(d*(d<0 ? RNDTOWARDS : RNDAWAY));
216466 ** constraint failure. If it is 0, then the constraint that failed is
216473 sqlite3_stmt *pStmt = 0;
216477 assert( iCol==0 || iCol%2 );
216480 rc = sqlite3_prepare_v2(pRtree->db, zSql, -1, &pStmt, 0);
216487 if( iCol==0 ){
216488 const char *zCol = sqlite3_column_name(pStmt, 0);
216519 int bHaveRowid = 0; /* Set to 1 after new rowid is determined */
216530 memset(&cell, 0, sizeof(cell));
216559 for(ii=0; ii<nn; ii+=2){
216570 for(ii=0; ii<nn; ii+=2){
216584 if( sqlite3_value_type(aData[0])==SQLITE_NULL
216585 || sqlite3_value_int64(aData[0])!=cell.iRowid
216595 rc = rtreeConstraintError(pRtree, 0);
216604 /* If aData[0] is not an SQL NULL value, it is the rowid of a
216608 if( sqlite3_value_type(aData[0])!=SQLITE_NULL ){
216609 rc = rtreeDeleteRowid(pRtree, sqlite3_value_int64(aData[0]));
216618 RtreeNode *pLeaf = 0;
216621 if( bHaveRowid==0 ){
216627 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
216631 rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
216641 for(jj=0; jj<pRtree->nAux; jj++){
216659 assert( pRtree->inWrTrans==0 );
216670 pRtree->inWrTrans = 0;
216694 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
216718 pRtree->inWrTrans = 0;
216737 db, pRtree->zDb, "sqlite_stat1",0,0,0,0,0,0
216744 if( zSql==0 ){
216747 rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
216749 if( sqlite3_step(p)==SQLITE_ROW ) nRow = sqlite3_column_int64(p, 0);
216768 for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
216769 if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
216771 return 0;
216796 0, /* xFindFunction - function overloading */
216799 0, /* xRelease */
216800 0, /* xRollbackTo */
216843 for(ii=0; ii<pRtree->nAux; ii++){
216859 rc = sqlite3_exec(db, zCreate, 0, 0, 0);
216866 appStmt[0] = &pRtree->pWriteNode;
216876 for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){
216879 if( i!=3 || pRtree->nAux==0 ){
216889 rc = sqlite3_prepare_v3(db, zSql, -1, f, appStmt[i], 0);
216899 if( pRtree->zReadAuxSql==0 ){
216906 for(ii=0; ii<pRtree->nAux; ii++){
216919 if( zSql==0 ){
216922 rc = sqlite3_prepare_v3(db, zSql, -1, f, &pRtree->pWriteAux, 0);
216941 sqlite3_stmt *pStmt = 0;
216942 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
216945 *piVal = sqlite3_column_int(pStmt, 0);
216977 int iPageSize = 0;
217012 int dummy = 0;
217020 ** argv[0] -> module name
217044 0, /* 0 */
217068 memset(pRtree, 0, sizeof(Rtree)+nDb+nName*2+8);
217090 if( zArg[0]=='+' ){
217093 }else if( pRtree->nAux>0 ){
217122 iErr = 0;
217144 assert( *ppVtab==0 );
217176 memset(&node, 0, sizeof(RtreeNode));
217177 memset(&tree, 0, sizeof(Rtree));
217178 tree.nDim = (u8)sqlite3_value_int(apArg[0]);
217183 if( node.zData==0 ) return;
217188 pOut = sqlite3_str_new(0);
217189 for(ii=0; ii<NCELL(&node); ii++){
217194 if( ii>0 ) sqlite3_str_append(pOut, " ", 1);
217196 for(jj=0; jj<tree.nDim2; jj++){
217215 ** The depth value is 0 for all nodes other than the root node, and the root
217221 if( sqlite3_value_type(apArg[0])!=SQLITE_BLOB
217222 || sqlite3_value_bytes(apArg[0])<2
217227 u8 *zBlob = (u8 *)sqlite3_value_blob(apArg[0]);
217281 sqlite3_stmt *pRet = 0;
217287 if( z==0 ){
217290 pCheck->rc = sqlite3_prepare_v2(pCheck->db, z, -1, &pRet, 0);
217309 if( z==0 ){
217315 if( pCheck->zReport==0 ){
217339 u8 *pRet = 0; /* Return value */
217341 if( pCheck->rc==SQLITE_OK && pCheck->pGetNode==0 ){
217351 int nNode = sqlite3_column_bytes(pCheck->pGetNode, 0);
217352 const u8 *pNode = (const u8*)sqlite3_column_blob(pCheck->pGetNode, 0);
217354 if( pRet==0 ){
217362 if( pCheck->rc==SQLITE_OK && pRet==0 ){
217371 ** This function is used to check that the %_parent (if bLeaf==0) or %_rowid
217395 assert( bLeaf==0 || bLeaf==1 );
217396 if( pCheck->aCheckMapping[bLeaf]==0 ){
217411 i64 ii = sqlite3_column_int64(pStmt, 0);
217445 for(i=0; i<pCheck->nDim; i++){
217482 int iDepth, /* Depth of iNode (0==leaf) */
217486 u8 *aNode = 0;
217487 int nNode = 0;
217489 assert( iNode==1 || aParent!=0 );
217490 assert( pCheck->nDim>0 );
217501 if( aParent==0 ){
217516 for(i=0; i<nCell; i++){
217521 if( iDepth>0 ){
217522 rtreeCheckMapping(pCheck, 0, iVal, iNode);
217551 i64 nActual = sqlite3_column_int64(pCount, 0);
217574 sqlite3_stmt *pStmt = 0; /* Used to find column count of rtree table */
217575 int nAux = 0; /* Number of extra columns. */
217578 memset(&check, 0, sizeof(check));
217610 rtreeCheckNode(&check, 0, 0, 1);
217618 sqlite3_finalize(check.aCheckMapping[0]);
217637 assert( pzErr!=0 && *pzErr==0 );
217645 if( (*pzErr)==0 ) rc = SQLITE_NOMEM;
217694 char *zReport = 0;
217695 const char *zDb = (const char*)sqlite3_value_text(apArg[0]);
217739 static int geo_debug = 0;
217766 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
217767 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217768 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217769 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217770 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217771 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217772 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217773 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217774 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217775 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217776 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217777 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217778 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217779 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217780 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217781 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217791 # define GCC_VERSION 0
217798 # define MSVC_VERSION 0
217820 ** encoding (1 byte) 0=big-endian, 1=little-endian
217862 unsigned char t = a[0];
217863 a[0] = a[3];
217872 while( fast_isspace(p->z[0]) ) p->z++;
217873 return p->z[0];
217876 /* Parse out a number. Write the value into *pVal if pVal!=0.
217882 int j = 0;
217883 int seenDP = 0;
217884 int seenE = 0;
217889 if( c=='0' && z[j+1]>='0' && z[j+1]<='9' ) return 0;
217894 if( z[j-1]=='-' ) return 0;
217895 if( seenDP ) return 0;
217900 if( z[j-1]<'0' ) return 0;
217908 if( c<'0' || c>'9' ) return 0;
217913 if( z[j-1]<'0' ) return 0;
217940 memset(&s, 0, sizeof(s));
217945 int ii = 0;
217952 if( aNew==0 ){
217959 while( geopolyParseNumber(&s, ii<=1 ? &s.a[s.nVertex*2+ii] : 0) ){
217978 && s.a[0]==s.a[s.nVertex*2-2]
217980 && (s.z++, geopolySkipSpace(&s)==0)
217987 if( pOut==0 ) goto parse_json_err;
217990 pOut->hdr[0] = *(unsigned char*)&x;
217991 pOut->hdr[1] = (s.nVertex>>16)&0xff;
217992 pOut->hdr[2] = (s.nVertex>>8)&0xff;
217993 pOut->hdr[3] = s.nVertex&0xff;
218005 return 0;
218019 GeoPoly *p = 0;
218021 testcase( pCtx==0 );
218027 if( a==0 ){
218029 return 0;
218032 if( (a[0]==0 || a[0]==1)
218036 if( p==0 ){
218043 if( a[0] != *(unsigned char*)&x ){
218045 for(ii=0; ii<nVertex; ii++){
218049 p->hdr[0] ^= 1;
218057 if( zJson==0 ){
218059 return 0;
218064 return 0;
218080 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
218100 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
218107 for(i=0; i<p->nVertex; i++){
218110 sqlite3_str_appendf(x, "[%!g,%!g]]", GeoX(p,0), GeoY(p,0));
218129 p = geopolyFuncParam(context, argv[0], 0);
218136 for(i=0; i<p->nVertex; i++){
218140 sqlite3_str_appendf(x, " %g,%g'", GeoX(p,0), GeoY(p,0));
218143 if( z && z[0] ){
218163 ** geopoly_xform(poly, 1, 0, 0, 1, x-offset, y-offset)
218165 ** Rotate by R around the point (0,0):
218167 ** geopoly_xform(poly, cos(R), sin(R), -sin(R), cos(R), 0, 0)
218174 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
218185 for(ii=0; ii<p->nVertex; ii++){
218209 for(ii=0; ii<p->nVertex-1; ii++){
218214 rArea += (GeoX(p,ii) - GeoX(p,0)) /* (xN - x0) */
218215 * (GeoY(p,ii) + GeoY(p,0)) /* (yN + y0) */
218233 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
218259 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
218309 double x = sqlite3_value_double(argv[0]);
218320 if( p==0 ){
218325 p->hdr[0] = *(unsigned char*)&i;
218326 p->hdr[1] = 0;
218327 p->hdr[2] = (n>>8)&0xff;
218328 p->hdr[3] = n&0xff;
218329 for(i=0; i<n; i++){
218341 ** (1) if aCoord!=0 store the bounding box in aCoord, returning NULL
218354 GeoPoly *pOut = 0;
218357 if( pPoly==0 && aCoord!=0 ){
218358 p = 0;
218359 mnX = aCoord[0].f;
218369 mnX = mxX = GeoX(p,0);
218370 mnY = mxY = GeoY(p,0);
218380 if( aCoord==0 ){
218383 if( pOut==0 ){
218387 return 0;
218391 pOut->hdr[0] = *(unsigned char*)ⅈ
218392 pOut->hdr[1] = 0;
218393 pOut->hdr[2] = 0;
218395 GeoX(pOut,0) = mnX;
218396 GeoY(pOut,0) = mnY;
218405 aCoord[0].f = mnX;
218411 memset(aCoord, 0, sizeof(RtreeCoord)*4);
218424 GeoPoly *p = geopolyBBox(context, argv[0], 0, 0);
218454 (void)geopolyBBox(context, argv[0], a, &rc);
218458 if( pBBox==0 ) return;
218459 if( pBBox->isInit==0 ){
218463 if( a[0].f < pBBox->a[0].f ) pBBox->a[0] = a[0];
218475 pBBox = (GeoBBox*)sqlite3_aggregate_context(context, 0);
218476 if( pBBox==0 ) return;
218477 p = geopolyBBox(context, 0, pBBox->a, 0);
218494 ** 0 x0,y0 is not on or beneath the line segment or the line segment
218508 if( x0<=x1 || x0>x2 ) return 0;
218510 if( x0<=x2 || x0>x1 ) return 0;
218513 if( x0!=x1 ) return 0;
218514 if( y0<y1 && y0<y2 ) return 0;
218515 if( y0>y1 && y0>y2 ) return 0;
218521 return 0;
218529 ** Return 0 if point X,Y is outside the polygon
218536 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
218539 int v = 0;
218540 int cnt = 0;
218544 if( p1==0 ) return;
218545 for(ii=0; ii<p1->nVertex-1; ii++){
218553 GeoX(p1,0), GeoY(p1,0));
218557 }else if( ((v+cnt)&1)==0 ){
218558 sqlite3_result_int(context, 0);
218573 ** Return 0 if any part of P2 is on the outside of P1
218581 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
218582 GeoPoly *p2 = geopolyFuncParam(context, argv[1], 0);
218586 if( x<0 ){
218589 sqlite3_result_int(context, x==2 ? 1 : x==4 ? 2 : 0);
218602 int eType; /* 0 for ADD, 1 for REMOVE */
218654 pEvent->eType = 0;
218675 for(i=0; i<(unsigned)pPoly->nVertex-1; i++){
218677 geopolyAddOneSegment(p, x[0], x[1], x[2], x[3], side, i);
218680 geopolyAddOneSegment(p, x[0], x[1], pPoly->a[0], pPoly->a[1], side, i);
218688 head.pNext = 0;
218709 int mx = 0;
218713 for(i=0; i<nEvent; i++){
218715 p->pNext = 0;
218716 for(j=0; j<mx && a[j]; j++){
218718 a[j] = 0;
218723 p = 0;
218724 for(i=0; i<mx; i++){
218735 head.pNext = 0;
218759 int mx = 0;
218766 p->pNext = 0;
218767 for(i=0; i<mx && a[i]; i++){
218769 a[i] = 0;
218774 p = 0;
218775 for(i=0; i<mx; i++){
218790 int rc = 0;
218791 int needSort = 0;
218792 GeoSegment *pActive = 0;
218800 if( p==0 ) return -1;
218803 p->nEvent = p->nSegment = 0;
218808 memset(aOverlap, 0, sizeof(aOverlap));
218811 GeoSegment *pPrev = 0;
218812 int iMask = 0;
218818 needSort = 0;
218830 pPrev = 0;
218856 if( pThisEvent->eType==0 ){
218866 pActive = ALWAYS(pActive) ? pActive->pNext : 0;
218870 pSeg->pNext = ALWAYS(pSeg->pNext) ? pSeg->pNext->pNext : 0;
218878 if( aOverlap[3]==0 ){
218879 rc = 0;
218880 }else if( aOverlap[1]!=0 && aOverlap[2]==0 ){
218882 }else if( aOverlap[1]==0 && aOverlap[2]!=0 ){
218884 }else if( aOverlap[1]==0 && aOverlap[2]==0 ){
218900 ** 0 The two polygons are disjoint
218912 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
218913 GeoPoly *p2 = geopolyFuncParam(context, argv[1], 0);
218917 if( x<0 ){
218938 geo_debug = sqlite3_value_int(argv[0]);
218948 ** argv[0] -> module name
218980 memset(pRtree, 0, sizeof(Rtree)+nDb+nName*2+8);
219032 assert( *ppVtab==0 );
219062 return geopolyInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
219073 ** that contains polygon argv[0]
219075 ** that contains polygon argv[0]
219086 RtreeNode *pRoot = 0;
219088 int iCell = 0;
219101 i64 iRowid = sqlite3_value_int64(argv[0]);
219102 i64 iNode = 0;
219104 if( rc==SQLITE_OK && pLeaf!=0 ){
219105 p = rtreeSearchPointNew(pCsr, RTREE_ZERO, 0);
219106 assert( p!=0 ); /* Always returns pCsr->sPoint */
219107 pCsr->aNode[0] = pLeaf;
219120 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
219125 assert( argv[0]!=0 );
219126 geopolyBBox(0, argv[0], bbox, &rc);
219132 if( p==0 ){
219135 memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*4);
219136 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
219140 p->iCoord = 0;
219145 p->u.rValue = bbox[0].f;
219157 p->iCoord = 0;
219158 p->u.rValue = bbox[0].f;
219177 if( pNew==0 ){
219182 pNew->iCell = 0;
219185 pCsr->aNode[0] = pRoot;
219186 pRoot = 0;
219215 int idxNum = 0;
219218 for(ii=0; ii<pIdxInfo->nConstraint; ii++){
219221 if( p->iColumn<0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
219225 if( p->iColumn==0 && p->op>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
219234 if( iRowidTerm>=0 ){
219244 if( iFuncTerm>=0 ){
219248 pIdxInfo->aConstraintUsage[iFuncTerm].omit = 0;
219272 if( p==0 ) return SQLITE_OK;
219273 if( i==0 && sqlite3_vtab_nochange(ctx) ) return SQLITE_OK;
219276 if( pCsr->pReadAux==0 ){
219277 rc = sqlite3_prepare_v3(pRtree->db, pRtree->zReadAuxSql, -1, 0,
219278 &pCsr->pReadAux, 0);
219303 ** argv[0] = the rowid to be deleted
219307 ** argv[0] = SQL NULL
219314 ** argv[0] = rowid to modify. Never NULL
219332 int coordChange = 0; /* Change in coordinates */
219343 oldRowidValid = sqlite3_value_type(aData[0])!=SQLITE_NULL;;
219344 oldRowid = oldRowidValid ? sqlite3_value_int64(aData[0]) : 0;
219346 newRowid = newRowidValid ? sqlite3_value_int64(aData[1]) : 0;
219354 assert( aData[2]!=0 );
219355 geopolyBBox(0, aData[2], cell.aCoord, &rc);
219376 rc = rtreeConstraintError(pRtree, 0);
219382 /* If aData[0] is not an SQL NULL value, it is the rowid of a
219396 RtreeNode *pLeaf = 0;
219402 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
219406 rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
219418 int nChange = 0;
219424 GeoPoly *p = 0;
219426 && (p = geopolyFuncParam(0, aData[2], &rc))!=0
219464 if( sqlite3_stricmp(zName, "geopoly_overlap")==0 ){
219466 *ppArg = 0;
219469 if( sqlite3_stricmp(zName, "geopoly_within")==0 ){
219471 *ppArg = 0;
219474 return 0;
219500 0, /* xRelease */
219501 0, /* xRollbackTo */
219521 { geopolyDebugFunc, 1, 0, "geopoly_debug" },
219535 for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
219543 enc, 0,
219544 aFunc[i].xFunc, 0, 0);
219546 for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){
219548 SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS, 0,
219549 0, aAgg[i].xStep, aAgg[i].xFinal);
219552 rc = sqlite3_create_module_v2(db, "geopoly", &geopolyModule, 0, 0);
219570 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
219572 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
219575 rc = sqlite3_create_function(db, "rtreecheck", -1, utf8, 0,rtreecheck, 0,0);
219583 rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);
219587 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
219617 for(i=0; i<p->nParam; i++){
219641 int memErr = 0;
219650 pBlob->cb = pGeomCtx[0];
219653 for(i=0; i<nArg; i++){
219655 if( pBlob->apSqlParam[i]==0 ) memErr = 1;
219686 pGeomCtx->xQueryFunc = 0;
219687 pGeomCtx->xDestructor = 0;
219690 (void *)pGeomCtx, geomCallback, 0, 0, rtreeFreeCallback
219713 pGeomCtx->xGeom = 0;
219718 (void *)pGeomCtx, geomCallback, 0, 0, rtreeFreeCallback
219803 zBuf[127] = '\0';
219830 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
219831 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
219832 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
219833 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
219834 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
219835 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
219836 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
219837 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
219842 if( c>=0xc0 ){ \
219843 c = icuUtf8Trans1[c-0xc0]; \
219844 while( (*zIn & 0xc0)==0x80 ){ \
219845 c = (c<<6) + (0x3f & *(zIn++)); \
219851 if( *(zIn++)>=0xc0 ){ \
219852 while( (*zIn & 0xc0)==0x80 ){zIn++;} \
219859 ** false (0) if they are different.
219869 int prevEscape = 0; /* True if the previous character was uEsc */
219876 if( uPattern==0 ) break;
219895 if( *zString==0 ) return 0;
219901 if( *zPattern==0 ) return 1;
219909 return 0;
219913 if( *zString==0 ) return 0;
219927 return 0;
219929 prevEscape = 0;
219933 return *zString==0;
219954 const unsigned char *zA = sqlite3_value_text(argv[0]);
219956 UChar32 uEsc = 0;
219961 if( sqlite3_value_bytes(argv[0])>SQLITE_MAX_LIKE_PATTERN_LENGTH ){
219973 int i = 0;
219974 if( zE==0 ) return;
220002 ** is 1 if the string matches the pattern, or 0 otherwise.
220031 pExpr = sqlite3_get_auxdata(p, 0);
220033 const UChar *zPattern = sqlite3_value_text16(apArg[0]);
220037 pExpr = uregex_open(zPattern, -1, 0, 0, &status);
220040 sqlite3_set_auxdata(p, 0, pExpr, icuRegexpDelete);
220041 pExpr = sqlite3_get_auxdata(p, 0);
220057 res = uregex_matches(pExpr, 0, &status);
220068 uregex_setText(pExpr, 0, 0, &status);
220070 /* Return 1 or 0. */
220071 sqlite3_result_int(p, res ? 1 : 0);
220102 UChar *zOutput = 0; /* Pointer to output buffer */
220108 const char *zLocale = 0;
220111 bToUpper = (sqlite3_user_data(p)!=0);
220116 zInput = sqlite3_value_text16(apArg[0]);
220120 nOut = nInput = sqlite3_value_bytes16(apArg[0]);
220121 if( nOut==0 ){
220122 sqlite3_result_text16(p, "", 0, SQLITE_STATIC);
220126 for(cnt=0; cnt<2; cnt++){
220128 if( zNew==0 ){
220144 assert( cnt==0 );
220151 assert( 0 ); /* Unreachable */
220182 case UCOL_EQUAL: return 0;
220185 return 0;
220215 zLocale = (const char *)sqlite3_value_text(apArg[0]);
220242 for(i=0; i<sizeof(aStrength)/sizeof(aStrength[0]); i++){
220243 if( sqlite3_stricmp(zOption,aStrength[i].zName)==0 ){
220248 if( i>=sizeof(aStrength)/sizeof(aStrength[0]) ){
220253 for(i=0; i<sizeof(aStrength)/sizeof(aStrength[0]); i++){
220285 {"regexp", 2, SQLITE_ANY|SQLITEICU_EXTRAFLAGS, 0, icuRegexpFunc},
220286 {"lower", 1, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
220287 {"lower", 2, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
220290 {"lower", 1, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
220291 {"lower", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
220294 {"like", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuLikeFunc},
220295 {"like", 3, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuLikeFunc},
220301 for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){
220305 p->iContext ? (void*)db : (void*)0,
220306 p->xFunc, 0, 0
220388 int n = 0;
220390 if( argc>0 ){
220391 n = strlen(argv[0])+1;
220397 memset(p, 0, sizeof(IcuTokenizer));
220401 memcpy(p->zLocale, argv[0], n);
220420 ** string to be tokenized is pInput[0..nBytes-1]. A cursor
220438 int iInput = 0;
220439 int iOut = 0;
220441 *ppCursor = 0;
220443 if( zInput==0 ){
220444 nInput = 0;
220446 }else if( nInput<0 ){
220458 memset(pCsr, 0, sizeof(IcuCursor));
220464 while( c>0 ){
220465 int isError = 0;
220477 c = 0;
220517 int iStart = 0;
220518 int iEnd = 0;
220519 int nByte = 0;
220573 0, /* iVersion */
220579 0, /* xLanguageid */
220791 ** of zero or more numeric characters (0-9). This can be significant because
220827 ** with the "rbu_control" column set to contain integer value 0. The
220958 #if 0
221169 ** to a value between 0 and 10000 to indicate the permyriadage progress of
221174 ** (*pnTwo) is set to 0 to indicate that stage 2 has not yet started. The
221280 ** sqlite3_multiplex_initialize(0, 0);
221289 ** zipvfs_create_vfs_v3("zipvfs", "rbu", 0, xCompressorAlgorithmDetector);
221315 #if 0
221335 # define RBU_ENABLE_DELTA_CKSUM 0
221442 #define WAL_LOCK_WRITE 0
221508 /* Output variables. zTbl==0 implies EOF. */
221535 ** 0: Table does not exist (error)
221542 #define RBU_PK_NOTABLE 0
221686 rbu_file *pMainRbu; /* List of main db files with pRbu!=0 */
221693 ** If this is a temporary file (pRbu!=0 && flags&DELETE_ON_CLOSE), variable
221715 rbu_file *pMainRbuNext; /* Next MAIN_DB file with pRbu!=0 */
221721 #define rbuIsVacuum(p) ((p)->zTarget==0)
221746 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
221752 unsigned int v = 0;
221756 while( (c = zValue[0x7f&*(z++)])>=0 ){
221771 unsigned sum0 = 0;
221772 unsigned sum1 = 0;
221773 unsigned sum2 = 0;
221774 unsigned sum3 = 0;
221776 sum0 += ((unsigned)z[0] + z[4] + z[8] + z[12]);
221784 sum0 += z[0];
221795 case 1: sum3 += (z[0] << 24);
221830 unsigned int total = 0;
221841 while( *zDelta && lenDelta>0 ){
221844 switch( zDelta[0] ){
221848 if( lenDelta>0 && zDelta[0]!=',' ){
221885 zOut[0] = 0;
221947 nOrig = sqlite3_value_bytes(argv[0]);
221948 aOrig = (const char*)sqlite3_value_blob(argv[0]);
221954 if( nOut<0 ){
221960 if( aOut==0 ){
221990 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
221993 *ppStmt = 0;
222036 assert( *pzErrmsg==0 );
222037 if( zSql==0 ){
222039 *ppStmt = 0;
222053 for(i=0; i<pIter->nTblCol; i++){
222058 pIter->azTblCol = 0;
222059 pIter->azTblType = 0;
222060 pIter->aiSrcOrder = 0;
222061 pIter->abTblPk = 0;
222062 pIter->abNotNull = 0;
222063 pIter->nTblCol = 0;
222064 pIter->eType = 0; /* Invalid value */
222088 pIter->pSelect = 0;
222089 pIter->pInsert = 0;
222090 pIter->pDelete = 0;
222091 pIter->pRbuUpdate = 0;
222092 pIter->pTmpInsert = 0;
222093 pIter->nCol = 0;
222094 pIter->nIdxCol = 0;
222095 pIter->aIdxCol = 0;
222096 pIter->zIdxSql = 0;
222108 memset(pIter, 0, sizeof(RbuObjIter));
222125 if( pIter->zIdx==0 ){
222131 , 0, 0, &p->zErrmsg
222138 pIter->bCleanup = 0;
222142 pIter->zTbl = 0;
222143 pIter->zDataTbl = 0;
222145 pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
222150 if( pIter->zIdx==0 ){
222159 pIter->zIdx = 0;
222161 pIter->zIdx = (const char*)sqlite3_column_text(pIter->pIdxIter, 0);
222183 ** for a view or 0 for a table.
222187 ** data[0-9]_<name>
222198 ** the second argument is either missing or 0 (not a view).
222209 zIn = (const char*)sqlite3_value_text(argv[0]);
222213 if( argc==1 || 0==sqlite3_value_int(argv[1]) ){
222217 if( strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
222219 for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
222238 memset(pIter, 0, sizeof(RbuObjIter));
222247 , rbuIsVacuum(p) ? "AND rootpage!=0 AND rootpage IS NOT NULL" : ""));
222272 char *zSql = 0;
222277 if( zSql==0 ) p->rc = SQLITE_NOMEM;
222280 zSql = 0;
222302 if( zSql==0 ){
222305 p->rc = sqlite3_exec(db, zSql, 0, 0, &p->zErrmsg);
222324 void *pRet = 0;
222326 assert( nByte>0 );
222328 if( pRet==0 ){
222331 memset(pRet, 0, nByte);
222369 char *zRet = 0;
222449 ** 0) SELECT count(*) FROM sqlite_schema where name=%Q AND IsVirtual(%Q)
222454 sqlite3_stmt *aStmt[4] = {0, 0, 0, 0};
222457 *piPk = 0;
222460 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
222468 if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
222472 if( sqlite3_column_int(aStmt[0], 0) ){
222476 *piTnum = sqlite3_column_int(aStmt[0], 1);
222485 if( zOrig && zIdx && zOrig[0]=='p' ){
222492 *piPk = sqlite3_column_int(aStmt[2], 0);
222507 if( sqlite3_column_int(aStmt[3],5)>0 ){
222517 for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){
222528 sqlite3_stmt *pList = 0;
222529 int bIndex = 0;
222538 pIter->nIndex = 0;
222542 sqlite3_stmt *pXInfo = 0;
222543 if( zIdx==0 ) break;
222545 memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
222552 if( iCid>=0 ) pIter->abIndexed[iCid] = 1;
222554 memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
222568 if( bIndex==0 ) pIter->abIndexed = 0;
222582 if( pIter->azTblCol==0 ){
222583 sqlite3_stmt *pStmt = 0;
222584 int nCol = 0;
222586 int bRbuRowid = 0; /* If input table has column "rbu_rowid" */
222587 int iOrder = 0;
222588 int iTnum = 0;
222591 assert( pIter->eType==0 );
222598 if( pIter->zIdx==0 ) pIter->iTnum = iTnum;
222615 for(i=0; p->rc==SQLITE_OK && i<nCol; i++){
222622 else if( 0==sqlite3_stricmp("rbu_rowid", zName) ){
222627 pStmt = 0;
222630 && rbuIsVacuum(p)==0
222650 if( zName==0 ) break; /* An OOM - finalize() below returns S_NOMEM */
222652 if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
222670 assert( iPk>=0 );
222672 pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0);
222679 assert( pIter->eType!=RBU_PK_VTAB || pIter->abIndexed==0 );
222680 assert( pIter->eType!=RBU_PK_VTAB || pIter->nIndex==0 );
222695 char *zList = 0;
222698 for(i=0; i<pIter->nTblCol; i++){
222720 char *zRet = 0;
222724 for(i=0; i<pIter->nTblCol; i++){
222763 sqlite3_stmt *pMax = 0;
222764 char *zRet = 0;
222772 sqlite3_int64 iMax = sqlite3_column_int64(pMax, 0);
222789 const char *zVal = (const char*)sqlite3_column_text(pMax, 0);
222828 char *zOrder = 0;
222829 char *zLhs = 0;
222830 char *zSelect = 0;
222831 char *zVector = 0;
222832 char *zRet = 0;
222833 int bFailed = 0;
222835 int iCol = 0;
222836 sqlite3_stmt *pXInfo = 0;
222850 if( iCid<0 ){
222853 for(i=0; pIter->abTblPk[i]==0; i++);
222879 sqlite3_stmt *pSel = 0;
222888 for(iCol=0; iCol<pIter->nCol; iCol++){
222890 if( zQuoted==0 ){
222892 }else if( zQuoted[0]=='N' ){
222949 char *zRet = 0; /* String to return */
222950 char *zImpCols = 0; /* String to return via *pzImposterCols */
222951 char *zImpPK = 0; /* String to return via *pzImposterPK */
222952 char *zWhere = 0; /* String to return via *pzWhere */
222953 int nBind = 0; /* Value to return via *pnBind */
222956 sqlite3_stmt *pXInfo = 0; /* PRAGMA index_xinfo = ? */
222959 assert( p->zErrmsg==0 );
222969 const char *zCol = 0;
222973 int iSeq = sqlite3_column_int(pXInfo, 0);
222979 if( iCid<0 ){
222984 for(i=0; pIter->abTblPk[i]==0; i++);
223000 if( pIter->bUnique==0 || sqlite3_column_int(pXInfo, 5) ){
223012 if( zRet==0 || zImpPK==0 || zImpCols==0 || zWhere==0 ) rc = SQLITE_NOMEM;
223026 zRet = 0;
223027 zImpCols = 0;
223028 zImpPK = 0;
223029 zWhere = 0;
223056 char *zList = 0;
223060 for(i=0; i<pIter->nTblCol; i++){
223068 if( zList==0 ){
223096 char *zList = 0;
223102 for(i=0; i<pIter->nTblCol; i++){
223115 for(i=0; i<pIter->nTblCol; i++){
223161 char *zList = 0;
223169 for(i=0; i<pIter->nTblCol; i++){
223211 char *zRet = 0;
223217 for(i=0; i<nBind; i++){
223219 zRet[i*2+1] = (i+1==nBind) ? '\0' : ',';
223238 char *z = 0;
223239 assert( pIter->zIdx==0 );
223242 sqlite3_stmt *pXList = 0; /* PRAGMA index_list = (pIter->zTbl) */
223243 sqlite3_stmt *pXInfo = 0; /* PRAGMA index_xinfo = <pk-index> */
223250 if( zOrig && strcmp(zOrig, "pk")==0 ){
223264 /* int iCid = sqlite3_column_int(pXInfo, 0); */
223299 sqlite3_stmt *pQuery = 0; /* SELECT name ... WHERE rootpage = $tnum */
223300 const char *zIdx = 0; /* Name of PK index */
223301 sqlite3_stmt *pXInfo = 0; /* PRAGMA main.index_xinfo = $zIdx */
223303 char *zCols = 0; /* Used to build up list of table cols */
223304 char *zPk = 0; /* Used to build up table PK declaration */
223315 zIdx = (const char*)sqlite3_column_text(pQuery, 0);
223346 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
223374 char *zSql = 0;
223376 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
223378 for(iCol=0; p->rc==SQLITE_OK && iCol<pIter->nTblCol; iCol++){
223381 const char *zColl = 0;
223384 p->dbMain, "main", pIter->zTbl, zCol, 0, &zColl, 0, 0, 0
223411 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
223435 assert( pIter->pTmpInsert==0 );
223453 assert( sqlite3_value_int(apVal[0])!=0
223457 if( sqlite3_value_int(apVal[0])!=0 ){
223461 for(i=0; rc==SQLITE_OK && i<nVal; i++){
223475 sqlite3_stmt *pStmt = 0;
223477 char *zRet = 0;
223479 assert( pIter->zIdxSql==0 && pIter->nIdxCol==0 && pIter->aIdxCol==0 );
223490 char *zSql = (char*)sqlite3_column_text(pStmt, 0);
223495 int nParen = 0; /* Number of open parenthesis */
223497 int iIdxCol = 0;
223498 int nIdxAlloc = 0;
223499 for(i=0; zSql[i]; i++){
223507 if( aIdxCol==0 ){
223516 if( nParen==0 ){
223517 assert( iIdxCol==0 );
223518 pIter->aIdxCol[0].zSpan = &zSql[i+1];
223524 if( nParen==0 ){
223547 if( zSql[i]=='\0' ) break;
223550 if( zSql[i]=='\0' ) break;
223579 assert( pIter->bCleanup==0 );
223580 if( pIter->pSelect==0 && rbuObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){
223582 char *zCollist = 0; /* List of indexed columns */
223585 char *zLimit = 0;
223594 char *zImposterCols = 0; /* Columns for imposter table */
223595 char *zImposterPK = 0; /* Primary key declaration for imposter */
223596 char *zWhere = 0; /* WHERE clause on PK columns */
223597 char *zBind = 0;
223598 char *zPart = 0;
223599 int nBind = 0;
223609 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
223615 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
223627 if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
223638 char *zStart = 0;
223643 zLimit = 0;
223648 "SELECT %s, 0 AS rbu_control FROM '%q' %s %s %s ORDER BY %s%s",
223723 if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
223731 if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
223740 "SELECT *%s FROM '%q' WHERE 0;"
223742 , (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
223770 " SELECT rbu_tmp_insert(0, %s);"
223782 char *zStart = 0;
223783 char *zOrder = 0;
223793 zLimit = 0;
223808 (rbuIsVacuum(p) ? "0 AS " : ""),
223848 RbuUpdateStmt *pUp = 0;
223849 int nUp = 0;
223852 *ppStmt = 0;
223860 if( strcmp(pUp->zMask, zMask)==0 ){
223869 assert( pUp==0 || pUp->pNext==0 );
223873 *pp = 0;
223875 pUp->pUpdate = 0;
223883 char *zUpdate = 0;
223914 sqlite3 *db = 0;
223917 p->rc = sqlite3_open_v2(zName, &db, flags, bUseVfs ? p->zVfsName : 0);
223921 db = 0;
223949 RbuState *pRet = 0;
223950 sqlite3_stmt *pStmt = 0;
223955 if( pRet==0 ) return 0;
223961 switch( sqlite3_column_int(pStmt, 0) ){
224030 assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
224031 assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
224032 assert( dbMain==0 || rbuIsVacuum(p)==0 );
224040 if( p->zState==0 ){
224055 #if 0
224057 p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, 0);
224064 #if 0
224068 int bOk = 0;
224069 sqlite3_stmt *pCnt = 0;
224075 && 1==sqlite3_column_int(pCnt, 0)
224082 if( p->rc==SQLITE_OK && bOk==0 ){
224088 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
224095 int bOpen = 0;
224097 p->nRbu = 0;
224098 p->pRbuFd = 0;
224113 p->eStage = 0;
224114 if( p->rc==SQLITE_OK && p->dbMain==0 ){
224119 p->pRbuFd->bNolock = 0;
224122 p->dbMain = 0;
224123 p->dbRbu = 0;
224131 char *zExtra = 0;
224132 if( strlen(p->zRbu)>=5 && 0==memcmp("file:", p->zRbu, 5) ){
224137 if( *zExtra=='\0' ) zExtra = 0;
224142 (zExtra==0 ? "" : "&"), (zExtra==0 ? "" : zExtra)
224145 if( zTarget==0 ){
224156 "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
224162 "rbu_fossil_delta", 2, SQLITE_UTF8, 0, rbuFossilDeltaFunc, 0, 0
224168 "rbu_target_name", -1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
224213 if( sqlite3_uri_boolean(zBase, "8_3_names", 0) )
224217 sz = (int)strlen(z)&0xffffff;
224218 for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){}
224234 i64 iRet = 0;
224238 p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, (void volatile**)&ptr);
224267 if( pState==0 ){
224268 p->eStage = 0;
224270 p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_schema", 0, 0, 0);
224305 rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
224309 if( p->rc==SQLITE_OK && p->nFrame>0 ){
224311 p->nStep = (pState ? pState->nRow : 0);
224317 if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){
224324 assert( p->nPagePerSector==0 );
224360 if( aNew==0 ) return SQLITE_NOMEM;
224368 pRbu->aFrame[pRbu->nFrame].iDbPage = 0;
224414 sqlite3_file *fd = 0;
224443 const char *zUri = sqlite3_db_filename(db, 0);
224444 return sqlite3_uri_boolean(zUri, RBU_EXCLUSIVE_CHECKPOINT, 0);
224452 nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
224453 if( nChar==0 ){
224454 return 0;
224456 zWideFilename = sqlite3_malloc64( nChar*sizeof(zWideFilename[0]) );
224457 if( zWideFilename==0 ){
224458 return 0;
224460 memset(zWideFilename, 0, nChar*sizeof(zWideFilename[0]));
224461 nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename,
224463 if( nChar==0 ){
224465 zWideFilename = 0;
224491 assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
224492 if( zWal==0 || zOal==0 ){
224502 sqlite3 *dbMain = 0;
224510 p->dbMain = 0;
224511 p->dbRbu = 0;
224525 || rbuExclusiveCheckpoint(dbMain)==0
224528 dbMain = 0;
224532 rbuOpenDatabase(p, dbMain, 0);
224533 rbuSetupCheckpoint(p, 0);
224560 int res = 0; /* Return value */
224566 case 0: res = RBU_INSERT; break;
224577 if( z==0 ){
224591 if( res==0 ){
224603 assert( 0==sqlite3_stricmp(zName, zCol) );
224621 assert( eType!=RBU_DELETE || pIter->zIdx==0 );
224640 for(i=0; i<pIter->nCol; i++){
224645 && pIter->zIdx==0 && pIter->eType==RBU_PK_IPK && pIter->abTblPk[i]
224653 if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){
224661 if( pIter->zIdx==0 ){
224699 const char *zMask = 0;
224707 assert( eType!=RBU_UPDATE || pIter->zIdx==0 );
224709 if( pIter->zIdx==0 && (eType==RBU_IDX_DELETE || eType==RBU_IDX_INSERT) ){
224713 if( pIter->zIdx==0 ){
224724 sqlite3_stmt *pUpdate = 0;
224730 for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
224778 iCookie = sqlite3_column_int(pStmt, 0);
224795 sqlite3_stmt *pInsert = 0;
224799 assert( p->zErrmsg==0 );
224826 assert( pInsert==0 || rc==SQLITE_OK );
224856 sqlite3_stmt *pPragma = 0;
224862 zPragma, sqlite3_column_int(pPragma, 0)
224875 sqlite3_stmt *pSql = 0;
224876 sqlite3_stmt *pInsert = 0;
224879 p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
224882 "SELECT sql FROM sqlite_schema WHERE sql!='' AND rootpage!=0"
224889 const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
224890 p->rc = sqlite3_exec(p->dbMain, zSql, 0, 0, &p->zErrmsg);
224897 "SELECT * FROM sqlite_schema WHERE rootpage=0 OR rootpage IS NULL"
224909 for(i=0; i<5; i++){
224916 p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=0",0,0,&p->zErrmsg);
224934 if( rbuIsVacuum(p) && p->nProgress==0 && p->rc==SQLITE_OK ){
224946 if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
224952 rbuObjIterPrepareAll(p, pIter, 0);
224963 p->nStep = 0;
224971 assert( pIter->zTbl==0 );
224975 p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
224978 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
225004 p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, &ptr);
225051 ** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
225056 if( z1==0 && z2==0 ) return 0;
225057 if( z1==0 || z2==0 ) return 1;
225058 return (sqlite3_stricmp(z1, z2)!=0);
225079 || (pState->zDataTbl==0 && rbuStrCompare(pIter->zTbl, pState->zTbl))
225107 sqlite3_vfs *pVfs = 0;
225109 assert( pVfs && p->rc==SQLITE_OK && p->zErrmsg==0 );
225110 pVfs->xDelete(pVfs, zOal, 0);
225128 p->rc = sqlite3rbu_create_vfs(zRnd, 0);
225144 p->zVfsName = 0;
225159 sqlite3_stmt *pStmt = 0;
225160 char *zErrmsg = 0;
225169 "WHERE type='index' AND tbl_name = %Q", sqlite3_value_text(apVal[0]))
225174 int nIndex = 0;
225176 nIndex = sqlite3_column_int(pStmt, 0);
225206 sqlite3_stmt *pStmt = 0;
225207 int bExists = 0; /* True if rbu_count exists */
225212 "rbu_index_cnt", 1, SQLITE_UTF8, (void*)p, rbuIndexCntFunc, 0, 0
225236 p->nPhaseOneStep = sqlite3_column_int64(pStmt, 0);
225251 size_t nTarget = zTarget ? strlen(zTarget) : 0;
225257 RbuState *pState = 0;
225260 memset(p, 0, sizeof(sqlite3rbu));
225261 sqlite3rbu_rename_handler(p, 0, 0);
225267 int bRetry = 0;
225287 rbuOpenDatabase(p, 0, &bRetry);
225289 rbuOpenDatabase(p, 0, 0);
225298 if( pState->eStage==0 ){
225310 assert( p->rc!=SQLITE_OK || p->eStage!=0 );
225318 p->nStep = 0;
225324 && pState->eStage!=0
225342 p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, &p->zErrmsg);
225351 if( p->rc==SQLITE_OK && p->objiter.zTbl==0 ){
225355 if( p->rc==SQLITE_OK && pState->eStage==0 && rbuIsVacuum(p) ){
225363 p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
225370 int frc = sqlite3_file_control(db, "main", SQLITE_FCNTL_ZIPVFS, 0);
225373 db, "PRAGMA journal_mode=off",0,0,&p->zErrmsg);
225414 memset(pRet, 0, sizeof(sqlite3rbu));
225428 if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); }
225439 if( zTarget==0 ){ return rbuMisuseError(); }
225442 if( n>=7 && 0==memcmp("-vactmp", &zState[n-7], 7) ){
225447 return openRbuHandle(0, zTarget, zState);
225454 sqlite3 *db = 0;
225465 ** the pattern "rbu_imp_[0-9]*".
225471 for(i=0; i<(nErrmsg-8); i++){
225472 if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
225474 while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
225491 p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
225503 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
225515 int rc2 = sqlite3_exec(p->dbRbu, "DELETE FROM stat.rbu_state", 0, 0, 0);
225522 assert( p->szTemp==0 );
225538 *pzErrmsg = 0;
225560 if( p->nPhaseOneStep>0 ){
225565 *pnTwo = 0;
225570 *pnTwo = 0;
225584 assert( 0 );
225593 0, SQLITE_RBU_STATE_OAL, SQLITE_RBU_STATE_MOVE,
225594 0, SQLITE_RBU_STATE_CHECKPOINT, SQLITE_RBU_STATE_DONE
225626 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, 0);
225641 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
225644 rc = sqlite3_exec(p->dbRbu, zBegin, 0, 0, 0);
225646 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0,0);
225698 pRbu->pRenameArg = 0;
225766 for(i=0; i<SQLITE_SHM_NLOCK;i++){
225771 p->pRbu->mLock = 0;
225782 assert( pRbu->szTemp>=0 );
225791 ** for all file descriptors with rbu_file.pDb!=0. If the argument has
225792 ** rbu_file.pDb!=0, then it is assumed to already be present on the
225793 ** main list and is only added to the pDb!=0 list.
225800 if( p->pRbu==0 ){
225806 if( pIter==0 ){
225822 p->pMainNext = 0;
225825 p->pMainRbuNext = 0;
225836 ** rbu_file.pDb!=0.
225859 for(i=0; i<p->nShm; i++){
225863 p->apShm = 0;
225871 pMeth->xShmUnmap(p->pReal, 0);
225875 rbuUpdateTempSize(p, 0);
225877 assert( p->pMainNext==0 && p->pRbuVfs->pMain!=p );
225890 return ((u32)aBuf[0] << 24)
225901 aBuf[0] = (iVal >> 24) & 0xFF;
225902 aBuf[1] = (iVal >> 16) & 0xFF;
225903 aBuf[2] = (iVal >> 8) & 0xFF;
225904 aBuf[3] = (iVal >> 0) & 0xFF;
225908 aBuf[0] = (iVal >> 8) & 0xFF;
225909 aBuf[1] = (iVal >> 0) & 0xFF;
225934 memset(zBuf, 0, iAmt);
225943 && rc==SQLITE_IOERR_SHORT_READ && iOfst==0
225951 u32 iRoot = rbuGetU32(&aBuf[52]) ? 1 : 0;
225953 rbuPutU32(&aBuf[36], 0); /* number of free pages */
225954 rbuPutU32(&aBuf[32], 0); /* first page on free list trunk */
225959 memset(&aBuf[100], 0, iAmt-100);
225960 rbuPutU16(&aBuf[105], iAmt & 0xFFFF);
225961 aBuf[100] = 0x0D;
225967 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
226010 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
226059 if( rc==SQLITE_OK && *pSize==0
226128 void *dummy = 0;
226156 if( zOut==0 ) rc = SQLITE_NOMEM;
226201 int bCapture = 0;
226205 if( bCapture==0 || 0==(flags & SQLITE_SHM_UNLOCK) ){
226228 int eStage = (p->pRbu ? p->pRbu->eStage : 0);
226243 if( apNew==0 ){
226246 memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm));
226253 if( pNew==0 ){
226256 memset(pNew, 0, szRegion);
226264 *pp = 0;
226267 assert( p->apShm==0 );
226288 int eStage = (p->pRbu ? p->pRbu->eStage : 0);
226329 0, 0 /* xFetch, xUnfetch */
226345 0, 0, 0, 0, 0, 0
226357 memset(pFd, 0, sizeof(rbu_file));
226371 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName, 0);
226392 && sqlite3_uri_boolean(zName, "rbu_memory", 0)
226397 zOpen = 0;
226408 if( pMeth->iVersion<2 || pMeth->xShmLock==0 ){
226468 sqlite3_int64 sz = 0;
226470 *pResOut = (sz>0);
226566 return 0;
226592 0, /* szOsFile */
226593 0, /* mxPathname */
226594 0, /* pNext */
226595 0, /* zName */
226596 0, /* pAppData */
226608 0, 0, 0, 0,
226615 0, /* xCurrentTimeInt64 (version 2) */
226616 0, 0, 0 /* Unimplemented version 3 methods */
226619 rbu_vfs *pNew = 0; /* Newly allocated VFS */
226627 if( pNew==0 ){
226631 memset(pNew, 0, nByte);
226633 if( pParent==0 ){
226646 if( pNew->mutex==0 ){
226649 rc = sqlite3_vfs_register(&pNew->base, 0);
226666 if( n>=0 ){
226752 " name TEXT," /* 0 Name of table or index */
226756 " ncell INTEGER," /* 4 Cells on page (0 for overflow) */
226776 u32 iChildPg; /* Child node (or 0 if this is a leaf) */
226795 u32 iRightChildPg; /* Right-child page number (or 0) */
226832 # define get2byte(x) ((x)[0]<<8 | (x)[1])
226845 StatTable *pTab = 0;
226854 if( iDb<0 ){
226859 iDb = 0;
226865 if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
226868 assert( rc==SQLITE_OK || pTab==0 );
226870 memset(pTab, 0, sizeof(StatTable));
226892 ** 0x01 There is a schema=? term in the WHERE clause
226893 ** 0x02 There is a name=? term in the WHERE clause
226894 ** 0x04 There is an aggregate=? term in the WHERE clause
226895 ** 0x08 Output should be ordered by name and path
226909 for(i=0; i<pIdxInfo->nConstraint; i++){
226911 if( pIdxInfo->aConstraint[i].usable==0 ){
226916 case 0: { /* name */
226930 i = 0;
226931 if( iSchema>=0 ){
226934 pIdxInfo->idxNum |= 0x01;
226936 if( iName>=0 ){
226938 pIdxInfo->idxNum |= 0x02;
226940 if( iAgg>=0 ){
226942 pIdxInfo->idxNum |= 0x04;
226951 && pIdxInfo->aOrderBy[0].iColumn==0
226952 && pIdxInfo->aOrderBy[0].desc==0
226955 && pIdxInfo->aOrderBy[0].iColumn==0
226956 && pIdxInfo->aOrderBy[0].desc==0
226958 && pIdxInfo->aOrderBy[1].desc==0
226962 pIdxInfo->idxNum |= 0x08;
226977 if( pCsr==0 ){
226980 memset(pCsr, 0, sizeof(StatCursor));
226992 for(i=0; i<p->nCell; i++){
226997 p->nCell = 0;
226998 p->aCell = 0;
227005 memset(p, 0, sizeof(StatPage));
227015 for(i=0; i<ArraySize(pCsr->aPage); i++){
227018 pCsr->aPage[i].aPg = 0;
227021 pCsr->iPage = 0;
227023 pCsr->zPath = 0;
227024 pCsr->isEof = 0;
227029 pCsr->nCell = 0;
227030 pCsr->nMxPayload = 0;
227031 pCsr->nUnused = 0;
227032 pCsr->nPayload = 0;
227033 pCsr->szPage = 0;
227034 pCsr->nPage = 0;
227062 if( flags==0x0D ){ /* Table leaf node */
227086 u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0];
227088 p->flags = aHdr[0];
227089 if( p->flags==0x0A || p->flags==0x0D ){
227092 }else if( p->flags==0x05 || p->flags==0x02 ){
227093 isLeaf = 0;
227100 p->nMxPayload = 0;
227111 if( iNext<iOff+4 && iNext>0 ) goto statPageIsCorrupt;
227115 p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]);
227125 if( p->aCell==0 ) return SQLITE_NOMEM_BKPT;
227126 memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell));
227128 for(i=0; i<p->nCell; i++){
227137 if( p->flags==0x05 ){
227138 /* A table interior node. nPayload==0. */
227143 if( p->flags==0x0D ){
227149 if( nLocal<0 ) goto statPageIsCorrupt;
227156 if( iOff+nLocal+4>nUsable || nPayload>0x7fffffff ){
227162 if( pCell->aOvfl==0 ) return SQLITE_NOMEM_BKPT;
227163 pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]);
227167 DbPage *pPg = 0;
227168 rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg, 0);
227170 assert( pPg==0 );
227184 p->flags = 0;
227204 x[0] = pCsr->iPageno;
227206 pCsr->iOffset = x[0];
227226 DbPage *pDbPage = 0;
227229 if( pPg->aPg==0 ){
227231 if( pPg->aPg==0 ){
227234 memset(&pPg->aPg[pgsz], 0, DBSTAT_PAGE_PADDING_BYTES);
227237 rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPg, &pDbPage, 0);
227249 ** entry will be the next page, but in aggregated mode (pCsr->isAgg!=0),
227262 pCsr->zPath = 0;
227265 if( pCsr->iPage<0 ){
227273 if( nPage==0 ){
227277 rc = statGetPage(pBt, iRoot, &pCsr->aPage[0]);
227278 pCsr->aPage[0].iPgno = iRoot;
227279 pCsr->aPage[0].iCell = 0;
227281 pCsr->aPage[0].zPath = z = sqlite3_mprintf("/");
227282 if( z==0 ) rc = SQLITE_NOMEM_BKPT;
227284 pCsr->iPage = 0;
227313 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
227319 return z==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
227329 if( pCsr->isAgg && pCsr->iPage<0 ){
227350 p[1].iCell = 0;
227353 if( z==0 ) rc = SQLITE_NOMEM_BKPT;
227365 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
227373 case 0x05: /* table internal */
227374 case 0x02: /* index internal */
227377 case 0x0D: /* table leaf */
227378 case 0x0A: /* index leaf */
227390 if( z==0 ) rc = SQLITE_NOMEM_BKPT;
227392 nPayload = 0;
227393 for(i=0; i<p->nCell; i++){
227414 ** arguments in argv[0]. See statBestIndex() for a description of the
227426 int iArg = 0; /* Count of argv[] parameters used so far */
227428 const char *zName = 0; /* Only provide analysis of this table */
227434 pCsr->pStmt = 0;
227435 if( idxNum & 0x01 ){
227439 if( pCsr->iDb<0 ){
227440 pCsr->iDb = 0;
227447 if( idxNum & 0x02 ){
227451 if( idxNum & 0x04 ){
227455 pCsr->isAgg = 0;
227463 " FROM \"%w\".sqlite_schema WHERE rootpage!=0)",
227468 if( idxNum & 0x08 ){
227472 if( zSql==0 ){
227475 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
227493 case 0: /* name */
227558 0, /* iVersion */
227571 0, /* xUpdate */
227572 0, /* xBegin */
227573 0, /* xSync */
227574 0, /* xCommit */
227575 0, /* xRollback */
227576 0, /* xFindMethod */
227577 0, /* xRename */
227578 0, /* xSavepoint */
227579 0, /* xRelease */
227580 0, /* xRollbackTo */
227581 0, /* xShadowName */
227582 0 /* xIntegrity */
227584 return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
227656 #define DBPAGE_COLUMN_PGNO 0
227671 DbpageTable *pTab = 0;
227684 if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
227687 assert( rc==SQLITE_OK || pTab==0 );
227689 memset(pTab, 0, sizeof(DbpageTable));
227708 ** 0 schema=main, full table scan
227715 int iPlan = 0;
227722 for(i=0; i<pIdxInfo->nConstraint; i++){
227743 for(i=0; i<pIdxInfo->nConstraint; i++){
227745 if( p->usable && p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
227758 && pIdxInfo->aOrderBy[0].iColumn<=0
227759 && pIdxInfo->aOrderBy[0].desc==0
227773 if( pCsr==0 ){
227776 memset(pCsr, 0, sizeof(DbpageCursor));
227813 ** 0 schema=main, full table scan
227835 pCsr->mxPgno = 0;
227840 zSchema = (const char*)sqlite3_value_text(argv[0]);
227842 if( pCsr->iDb<0 ) return SQLITE_OK;
227844 pCsr->iDb = 0;
227847 if( NEVER(pBt==0) ) return SQLITE_OK;
227856 pCsr->mxPgno = 0;
227864 rc = sqlite3PagerGet(pCsr->pPager, 1, &pCsr->pPage1, 0);
227876 case 0: { /* pgno */
227881 DbPage *pDbPage = 0;
227887 rc = sqlite3PagerGet(pCsr->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0);
227922 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
227924 if( pBt ) rc = sqlite3BtreeBeginTrans(pBt, 1, 0);
227937 DbPage *pDbPage = 0;
227939 char *zErr = 0;
227955 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
227959 pgno = sqlite3_value_int(argv[0]);
227964 isInsert = 0;
227967 iDb = 0;
227971 if( iDb<0 ){
227977 if( pgno<1 || NEVER(pBt==0) ){
228003 rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pDbPage, 0);
228009 pTab->pgnoTrunc = 0;
228012 pTab->pgnoTrunc = 0;
228018 pTab->pgnoTrunc = 0;
228026 pTab->pgnoTrunc = 0;
228034 if( pTab->pgnoTrunc>0 ){
228043 pTab->pgnoTrunc = 0;
228051 pTab->pgnoTrunc = 0;
228077 0, /* xCommit */
228078 0, /* xRollback */
228079 0, /* xFindMethod */
228080 0, /* xRename */
228081 0, /* xSavepoint */
228082 0, /* xRelease */
228084 0, /* xShadowName */
228085 0 /* xIntegrity */
228087 return sqlite3_create_module(db, "sqlite_dbpage", &dbpage_module, 0);
228261 ** 0x00: Undefined value.
228262 ** 0x01: Integer value.
228263 ** 0x02: Real value.
228264 ** 0x03: Text value.
228265 ** 0x04: Blob value.
228266 ** 0x05: SQL NULL value.
228300 ** 1 byte: Constant 0x54 (capital 'T')
228302 ** nCol bytes: 0x01 for PK columns, 0x00 otherwise.
228307 ** 1 byte: Either SQLITE_INSERT (0x12), UPDATE (0x17) or DELETE (0x09).
228322 ** of INSERT or DELETE changes never contain any undefined (type byte 0x00)
228342 ** 1 byte: Constant 0x50 (capital 'P')
228344 ** nCol bytes: 0x01 for PK columns, 0x00 otherwise.
228349 ** 1 byte: Either SQLITE_INSERT (0x12), UPDATE (0x17) or DELETE (0x09).
228385 ** 1 byte: Constant 0x54 (capital 'T')
228387 ** nCol bytes: 0x01 for PK columns, 0x00 otherwise.
228392 ** 1 byte: Either SQLITE_INSERT (0x12), DELETE (0x09).
228393 ** 1 byte: Flag. 0x01 for REPLACE, 0x00 for OMIT.
228398 ** it was a DELETE. The second field is set to 0x01 if the conflict
228399 ** resolution strategy was REPLACE, or 0x00 if it was OMIT.
228447 #define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
228464 aBuf[0] = (i>>56) & 0xFF;
228465 aBuf[1] = (i>>48) & 0xFF;
228466 aBuf[2] = (i>>40) & 0xFF;
228467 aBuf[3] = (i>>32) & 0xFF;
228468 aBuf[4] = (i>>24) & 0xFF;
228469 aBuf[5] = (i>>16) & 0xFF;
228470 aBuf[6] = (i>> 8) & 0xFF;
228471 aBuf[7] = (i>> 0) & 0xFF;
228498 if( aBuf ) aBuf[0] = eType;
228537 if( z==0 && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
228542 if( n>0 ) memcpy(&aBuf[nVarint + 1], z, n);
228551 if( aBuf ) aBuf[0] = '\0';
228587 ** hash_key_value = HASH_APPEND(0, <value 1>);
228601 h = HASH_APPEND(h, i & 0xFFFFFFFF);
228602 return HASH_APPEND(h, (i>>32)&0xFFFFFFFF);
228611 for(i=0; i<n; i++) h = HASH_APPEND(h, z[i]);
228642 unsigned int h = 0; /* Hash value to return */
228649 assert( *pbNullPK==0 );
228650 for(i=0; i<pTab->nCol; i++){
228685 if( !z && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
228689 assert( pTab->bStat1==0 || i!=1 );
228708 assert( a!=0 );
228710 if( e==0 || e==0xFF ) return 1;
228731 unsigned int h = 0; /* Value to return */
228735 for(i=0; i<pTab->nCol; i++){
228738 if( bPkOnly && isPK==0 ) continue;
228745 || eType==SQLITE_NULL || eType==0
228747 assert( !isPK || (eType!=0 && eType!=SQLITE_NULL) );
228785 for(iCol=0; iCol<pTab->nCol; iCol++){
228791 return 0;
228796 if( bLeftPkOnly==0 ) a1 += sessionSerialLen(a1);
228797 if( bRightPkOnly==0 ) a2 += sessionSerialLen(a2);
228826 int iCol; /* Used to iterate from 0 to nCol */
228828 for(iCol=0; iCol<nCol; iCol++){
228853 ** *paTwo[0] is not 0x00 - the "no value" placeholder), a copy of the *paTwo
228870 u8 *pRet = 0;
228884 if( pRet==0 ){
228914 if( bPatchset==0 ){
228915 int bRequired = 0;
228920 for(i=0; i<pTab->nCol; i++){
228929 if( pTab->abPK[i]==0 ) bRequired = 1;
228933 *(aOut++) = '\0';
228937 if( !bRequired ) return 0;
228945 for(i=0; i<pTab->nCol; i++){
228953 if( bPatchset==0
228954 && (pTab->abPK[i] || (nOld==nNew && 0==memcmp(aOld, aNew, nNew)))
228956 *(aOut++) = '\0';
228985 if( a[0]!=SQLITE_INTEGER ) return 0;
228990 for(iCol=0; iCol<pTab->nCol; iCol++){
229013 if( sqlite3_value_type(pVal)!=eType ) return 0;
229024 if( sqlite3_value_int64(pVal)!=iVal ) return 0;
229029 if( sqlite3_value_double(pVal)!=rVal ) return 0;
229035 if( sqlite3_value_bytes(pVal)!=n ) return 0;
229041 if( n>0 && memcmp(a, z, n) ) return 0;
229066 if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){
229074 if( apNew==0 ){
229075 if( pTab->nChange==0 ){
229080 memset(apNew, 0, sizeof(SessionChange *) * nNew);
229082 for(i=0; i<pTab->nChange; i++){
229123 ** *pabPK = {1, 0, 0, 1}
229146 int nDbCol = 0;
229149 u8 *pAlloc = 0;
229150 char **azCol = 0;
229151 char **azDflt = 0;
229152 u8 *abPK = 0;
229153 int *aiIdx = 0;
229154 int bRowid = 0; /* Set to true to use rowid as PK */
229158 *pazCol = 0;
229159 *pabPK = 0;
229160 *pnCol = 0;
229161 if( pnTotalCol ) *pnTotalCol = 0;
229162 if( paiIdx ) *paiIdx = 0;
229163 if( pzTab ) *pzTab = 0;
229164 if( pazDflt ) *pazDflt = 0;
229167 if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){
229168 rc = sqlite3_table_column_metadata(db, zDb, zThis, 0, 0, 0, 0, 0, 0);
229172 "SELECT 0, 'tbl', '', 0, '', 1, 0 UNION ALL "
229173 "SELECT 1, 'idx', '', 0, '', 2, 0 UNION ALL "
229174 "SELECT 2, 'stat', '', 0, '', 0, 0"
229188 rc = sqlite3_prepare_v2(db, zPragma, -1, &pStmt, 0);
229195 bRowid = (pbRowid!=0);
229199 if( sqlite3_column_int(pStmt, 6)==0 ){ /* !hidden */
229202 if( sqlite3_column_int(pStmt, 5) ) bRowid = 0; /* pk */
229204 if( nDbCol==0 ) bRowid = 0;
229212 if( pAlloc==0 ){
229215 memset(pAlloc, 0, nByte);
229230 i = 0;
229241 if( sqlite3_column_int(pStmt, 6)==0 ){ /* !hidden */
229247 if( zName==0 ) break;
229256 azDflt[i] = 0;
229259 aiIdx[i] = sqlite3_column_int(pStmt, 0);
229303 if( pTab->nCol==0 ){
229305 assert( pTab->azCol==0 || pTab->abPK==0 );
229307 pTab->abPK = 0;
229309 pTab->zName, &pTab->nCol, &pTab->nTotalCol, 0, &pTab->azCol,
229311 ((pSession==0 || pSession->bImplicitPK) ? &pTab->bRowid : 0)
229315 for(i=0; i<pTab->nCol; i++){
229321 if( 0==sqlite3_stricmp("sqlite_stat1", pTab->zName) ){
229335 return (rc || pTab->abPK==0);
229344 int nCol = 0;
229345 int nTotalCol = 0;
229346 const char **azCol = 0;
229347 const char **azDflt = 0;
229348 int *aiIdx = 0;
229349 u8 *abPK = 0;
229350 int bRowid = 0;
229355 pTab->zName, &nCol, &nTotalCol, 0, &azCol, &azDflt, &aiIdx, &abPK,
229356 (pSession->bImplicitPK ? &bRowid : 0)
229364 for(ii=0; ii<nCol; ii++){
229411 SessionChange *pNew = 0;
229412 int nByte = 0;
229413 int nIncr = 0;
229434 if( pNew==0 ){
229452 i64 iVal = 0;
229501 #define SESSION_MAX_BUFFER_SZ (0x7FFFFF00 - 1)
229525 if( 0==aNew ){
229550 if( 0==sessionBufferGrow(p, nStr+1, pRc) ){
229553 p->aBuf[p->nBuf] = 0x00;
229568 char *zApp = 0;
229572 if( zApp==0 ){
229598 SessionBuffer sql = {0,0,0};
229601 int ii = 0;
229603 *ppStmt = 0;
229605 for(ii=0; ii<pTab->nCol; ii++){
229611 rc = sqlite3_prepare_v2(db, (const char*)sql.aBuf, -1, ppStmt, 0);
229624 sqlite3_stmt *pStmt = 0;
229629 int ii = 0;
229630 SessionChange **pp = 0;
229631 for(ii=0; ii<pTab->nChange; ii++){
229659 sqlite3_value *pVal = 0;
229669 sqlite3_value *pVal = 0;
229697 for(ii=0; ii<pTab->nCol; ii++){
229698 sqlite3_value *p = 0;
229700 sessionSerializeValue(0, p, &nNew);
229705 if( sqlite3_preupdate_blobwrite(pSession->db)>=0 ){
229717 int nOld = 0;
229720 sqlite3_value *p = 0;
229722 if( p==0 ){
229757 && (nByte==0 || 0==memcmp(pCsr, sqlite3_value_blob(p), nByte))
229759 bChanged = 0;
229773 sessionSerializeValue(0, p, &nNew);
229805 int bNull = 0;
229807 int nExpect = 0;
229808 SessionStat1Ctx stat1 = {{0,0,0,0,0},0};
229828 if( sessionGrowHash(pSession, 0, pTab) ){
229841 if( pSession->pZeroBlob==0 ){
229842 sqlite3_value *p = sqlite3ValueNew(0);
229843 if( p==0 ){
229847 sqlite3ValueSetStr(p, 0, "", 0, SQLITE_STATIC);
229860 if( bNull==0 ){
229867 if( pC==0 ){
229881 sqlite3_value *p = 0;
229894 rc = sessionSerializeValue(0, p, &nByte);
229908 memset(pC, 0, sizeof(SessionChange));
229916 nByte = 0;
229918 pC->aRecord[0] = SQLITE_INTEGER;
229923 sqlite3_value *p = 0;
229946 if( pSession->hook.xDepth(pSession->hook.pCtx)==0
229947 && pSession->bIndirect==0
229949 pC->bIndirect = 0;
229981 if( 0==sqlite3_strnicmp(pRet->zName, zName, nName+1) ) break;
229984 if( pRet==0 && pSession->bAutoAttach ){
229985 /* If there is a table-filter configured, invoke it. If it returns 0,
229987 if( pSession->xTableFilter==0
229996 assert( pRet!=0 );
229997 assert( 0==sqlite3_strnicmp(pRet->zName, zName, nName+1) );
230002 assert( rc==SQLITE_OK || pRet==0 );
230032 if( pSession->bEnable==0 ) continue;
230104 return 0;
230130 char *zRet = 0;
230132 for(i=0; i<nCol; i++){
230138 if( zRet==0 ) break;
230153 char *zRet = 0;
230154 int bHave = 0;
230156 for(i=0; i<nCol; i++){
230157 if( abPK[i]==0 ){
230164 if( zRet==0 ) break;
230168 if( bHave==0 ){
230169 assert( zRet==0 );
230170 zRet = sqlite3_mprintf("0");
230206 if( zStmt==0 ){
230210 rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
230214 pDiffCtx->nOldOff = 0;
230217 i64 iRowid = (pTab->bRowid ? sqlite3_column_int64(pStmt, 0) : 0);
230239 char *zRet = 0;
230240 for(ii=0; ii<pTab->nCol; ii++){
230260 if( zExpr2==0 ){
230269 if( zStmt==0 || z1==0 || z2==0 ){
230273 rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
230280 i64 iRowid = (pTab->bRowid ? sqlite3_column_int64(pStmt, 0) : 0);
230304 memset(&d, 0, sizeof(d));
230308 if( pzErrMsg ) *pzErrMsg = 0;
230310 char *zExpr = 0;
230318 if( pTo==0 ) goto diff_out;
230326 int bHasPk = 0;
230327 int bMismatch = 0;
230328 int nCol = 0; /* Columns in zFrom.zTbl */
230329 int bRowid = 0;
230330 u8 *abPK = 0;
230331 const char **azCol = 0;
230332 char *zDbExists = 0;
230336 if( zDbExists==0 ){
230339 sqlite3_stmt *pDbExists = 0;
230340 rc = sqlite3_prepare_v2(db, zDbExists, -1, &pDbExists, 0);
230349 if( rc==SQLITE_OK && nCol==0 ){
230350 rc = sessionTableInfo(0, db, zFrom, zTbl,
230351 &nCol, 0, 0, &azCol, 0, 0, &abPK,
230352 pSession->bImplicitPK ? &bRowid : 0
230357 if( nCol<=0 ){
230367 for(i=0; i<nCol; i++){
230381 if( bHasPk==0 ){
230431 *ppSession = 0;
230436 memset(pNew, 0, sizeof(sqlite3_session));
230466 for(i=0; i<pTab->nChange; i++){
230492 pHead = (sqlite3_session*)sqlite3_preupdate_hook(db, 0, 0);
230493 for(pp=&pHead; ALWAYS((*pp)!=0); pp=&((*pp)->pNext)){
230549 if( 0==sqlite3_strnicmp(pTab->zName, zName, nName+1) ) break;
230565 memset(pTab, 0, sizeof(SessionTable));
230589 sqlite3_int64 nByte = 0;
230590 rc = sessionSerializeValue(0, pVal, &nByte);
230593 rc = sessionSerializeValue(&p->aBuf[p->nBuf], pVal, 0);
230609 if( 0==sessionBufferGrow(p, 1, pRc) ){
230622 if( 0==sessionBufferGrow(p, 9, pRc) ){
230640 if( nBlob>0 && 0==sessionBufferGrow(p, nBlob, pRc) ){
230679 if( 0==sessionBufferGrow(p, nStr, pRc) ){
230683 if( zIn!=0 ){
230691 p->aBuf[p->nBuf] = 0x00;
230731 if( z || (eType==SQLITE_BLOB && nByte==0) ){
230747 ** 1 byte: SQLITE_UPDATE (0x17)
230765 int bPatchset, /* True for "patchset", 0 for "changeset" */
230771 SessionBuffer buf2 = {0,0,0}; /* Buffer to accumulate new.* record in */
230777 assert( abPK!=0 );
230780 for(i=0; i<sqlite3_column_count(pStmt); i++){
230781 int bChanged = 0;
230816 && (n==0 || 0==memcmp(&pCsr[nHdr], sqlite3_column_blob(pStmt, i), n))
230825 if( bChanged ) bNoop = 0;
230829 if( bPatchset==0 ){
230833 sessionAppendByte(pBuf, 0, &rc);
230842 sessionAppendByte(&buf2, 0, &rc);
230865 int bPatchset, /* True for "patchset", 0 for "changeset" */
230875 if( bPatchset==0 ){
230880 for(i=0; i<nCol; i++){
230885 case 0:
230887 assert( abPK[i]==0 );
230936 char *zSql = 0;
230941 SessionBuffer cols = {0, 0, 0};
230942 SessionBuffer nooptest = {0, 0, 0};
230943 SessionBuffer pkfield = {0, 0, 0};
230944 SessionBuffer pkvar = {0, 0, 0};
230948 if( 0==sqlite3_stricmp("sqlite_stat1", zTab) ){
230956 #if 0
230961 for(i=0; i<nCol; i++){
230984 if( zSql==0 ) rc = SQLITE_NOMEM;
230987 #if 0
230988 if( 0==sqlite3_stricmp("sqlite_stat1", zTab) ){
230993 if( zSql==0 ) rc = SQLITE_NOMEM;
230996 SessionBuffer buf = {0, 0, 0};
231003 for(i=0; i<nCol; i++){
231018 rc = sqlite3_prepare_v2(db, zSql, nSql, ppStmt, 0);
231046 for(i=0; i<nCol && rc==SQLITE_OK; i++){
231050 case 0:
231052 assert( abPK[i]==0 );
231128 ** to 0.
231140 SessionBuffer buf = {0,0,0}; /* Buffer in which to accumulate changeset */
231143 assert( xOutput==0 || (pnChangeset==0 && ppChangeset==0) );
231144 assert( xOutput!=0 || (pnChangeset!=0 && ppChangeset!=0) );
231149 if( xOutput==0 ){
231150 assert( pnChangeset!=0 && ppChangeset!=0 );
231151 *pnChangeset = 0;
231152 *ppChangeset = 0;
231156 rc = sqlite3_exec(pSession->db, "SAVEPOINT changeset", 0, 0, 0);
231165 sqlite3_stmt *pSel = 0; /* SELECT statement to query table pTab */
231181 rc = sessionSelectStmt(db, 0, pSession->zDb,
231187 for(i=0; i<pTab->nChange && rc==SQLITE_OK; i++){
231198 for(iCol=0; iCol<pTab->nCol; iCol++){
231202 assert( pTab->abPK!=0 );
231221 buf.nBuf = 0;
231235 if( xOutput==0 ){
231238 buf.aBuf = 0;
231239 }else if( buf.nBuf>0 ){
231245 sqlite3_exec(db, "RELEASE changeset", 0, 0, 0);
231264 if( pnChangeset==0 || ppChangeset==0 ) return SQLITE_MISUSE;
231265 rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset, ppChangeset);
231266 assert( rc || pnChangeset==0
231267 || pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize
231280 if( xOutput==0 ) return SQLITE_MISUSE;
231281 return sessionGenerateChangeset(pSession, 0, xOutput, pOut, 0, 0);
231292 if( xOutput==0 ) return SQLITE_MISUSE;
231293 return sessionGenerateChangeset(pSession, 1, xOutput, pOut, 0, 0);
231308 if( pnPatchset==0 || ppPatchset==0 ) return SQLITE_MISUSE;
231309 return sessionGenerateChangeset(pSession, 1, 0, 0, pnPatchset, ppPatchset);
231318 if( bEnable>=0 ){
231332 if( bIndirect>=0 ){
231345 int ret = 0;
231349 for(pTab=pSession->pTable; pTab && ret==0; pTab=pTab->pNext){
231350 ret = (pTab->nEntry>0);
231354 return (ret==0);
231372 if( iArg>=0 ){
231376 pSession->bEnableSize = (iArg!=0);
231385 if( iArg>=0 ){
231389 pSession->bImplicitPK = (iArg!=0);
231425 assert( xInput==0 || (pChangeset==0 && nChangeset==0) );
231428 *pp = 0;
231434 memset(pRet, 0, sizeof(sqlite3_changeset_iter));
231439 pRet->in.bEof = (xInput ? 0 : 1);
231456 return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset, 0, 0);
231465 return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset, bInvert, 0);
231476 return sessionChangesetStart(pp, xInput, pIn, 0, 0, 0, 0);
231485 return sessionChangesetStart(pp, xInput, pIn, 0, 0, bInvert, 0);
231495 assert( nMove>=0 );
231496 if( nMove>0 ){
231501 pIn->iCurrent = 0;
231519 if( pIn->bNoDiscard==0 ) sessionDiscardData(pIn);
231522 if( nNew==0 ){
231547 for(i=0; i<nCol; i++){
231571 u8 enc /* String encoding (0 for blobs) */
231578 if( aCopy==0 ) return SQLITE_NOMEM;
231618 assert( pbEmpty==0 || *pbEmpty==0 );
231620 for(i=0; i<nCol && rc==SQLITE_OK; i++){
231621 int eType = 0; /* Type of value (SQLITE_NULL, TEXT etc.) */
231622 if( abPK && abPK[i]==0 ) continue;
231629 assert( apOut[i]==0 );
231631 if( pbEmpty ) *pbEmpty = 0;
231632 apOut[i] = sqlite3ValueNew(0);
231645 if( nByte<0 || nByte>pIn->nData-pIn->iNext ){
231648 u8 enc = (eType==SQLITE_TEXT ? SQLITE_UTF8 : 0);
231690 int nCol = 0;
231691 int nRead = 0;
231703 if( nCol<0 || nCol>65536 ){
231737 int nByte = 0;
231739 for(i=0; rc==SQLITE_OK && i<nCol; i++){
231785 if( p->nCol>0 ){
231789 p->tblhdr.nBuf = 0;
231798 memset(p->tblhdr.aBuf, 0, iPK);
231804 if( p->apValue==0 ){
231805 p->abPK = 0;
231806 p->zTab = 0;
231809 p->zTab = p->abPK ? (char*)&p->abPK[p->nCol] : 0;
231834 assert( (paRec==0 && pnRec==0) || (paRec && pnRec) );
231835 assert( pbEmpty==0 || *pbEmpty==0 );
231842 for(i=0; i<p->nCol*2; i++){
231845 memset(p->apValue, 0, sizeof(sqlite3_value*)*p->nCol*2);
231874 if( p->zTab==0 || (p->bPatchset && p->bInvert) ){
231889 if( p->bPatchset==0 && op==SQLITE_UPDATE ){
231892 nVal = 0;
231893 for(i=0; i<p->nCol; i++) if( p->abPK[i] ) nVal++;
231906 if( p->op!=SQLITE_INSERT && (p->bPatchset==0 || p->op==SQLITE_DELETE) ){
231907 u8 *abPK = p->bPatchset ? p->abPK : 0;
231908 p->rc = sessionReadRecord(&p->in, p->nCol, abPK, apOld, 0);
231914 p->rc = sessionReadRecord(&p->in, p->nCol, 0, apNew, pbEmpty);
231923 for(i=0; i<p->nCol; i++){
231924 assert( p->bPatchset==0 || p->apValue[i]==0 );
231926 assert( p->apValue[i]==0 );
231928 if( p->apValue[i]==0 ) return (p->rc = SQLITE_CORRUPT_BKPT);
231929 p->apValue[i+p->nCol] = 0;
231944 if( p->bPatchset==0 && p->op==SQLITE_UPDATE){
231945 for(i=0; i<p->nCol; i++){
231946 if( p->abPK[i]==0 && p->apValue[i+p->nCol]==0 ){
231948 p->apValue[i] = 0;
231982 bEmpty = 0;
231997 return sessionChangesetNext(p, 0, 0, 0);
232056 if( iVal<0 || iVal>=pIter->nCol ){
232084 if( iVal<0 || iVal>=pIter->nCol ){
232118 if( iVal<0 || iVal>=pIter->nCol ){
232157 for(i=0; i<p->nCol*2; i++) sqlite3ValueFree(p->apValue[i]);
232175 int nCol = 0; /* Number of cols in current table */
232176 u8 *abPK = 0; /* PK array for current table */
232177 sqlite3_value **apVal = 0; /* Space for values for UPDATE inversion */
232178 SessionBuffer sPK = {0, 0, 0}; /* PK array for current table */
232181 memset(&sOut, 0, sizeof(SessionBuffer));
232185 *ppInverted = 0;
232186 *pnInverted = 0;
232213 sPK.nBuf = 0;
232221 apVal = 0;
232245 if( 0==apVal ){
232246 apVal = (sqlite3_value **)sqlite3_malloc64(sizeof(apVal[0])*nCol*2);
232247 if( 0==apVal ){
232251 memset(apVal, 0, sizeof(apVal[0])*nCol*2);
232260 rc = sessionReadRecord(pInput, nCol, 0, &apVal[0], 0);
232262 rc = sessionReadRecord(pInput, nCol, 0, &apVal[nCol], 0);
232268 for(iCol=0; iCol<nCol; iCol++){
232269 sqlite3_value *pVal = apVal[iCol + (abPK[iCol] ? 0 : nCol)];
232276 for(iCol=0; iCol<nCol; iCol++){
232277 sqlite3_value *pVal = (abPK[iCol] ? 0 : apVal[iCol]);
232281 for(iCol=0; iCol<nCol*2; iCol++){
232284 memset(apVal, 0, sizeof(apVal[0])*nCol*2);
232300 sOut.nBuf = 0;
232309 sOut.aBuf = 0;
232310 }else if( sOut.nBuf>0 && ALWAYS(xOutput!=0) ){
232334 memset(&sInput, 0, sizeof(SessionInput));
232338 return sessionChangesetInvert(&sInput, 0, 0, pnInverted, ppInverted);
232354 memset(&sInput, 0, sizeof(SessionInput));
232358 rc = sessionChangesetInvert(&sInput, xOutput, pOut, 0, 0);
232409 SessionUpdate *pUp = 0;
232414 if( p->aUpdateMask==0 ){
232416 if( p->aUpdateMask==0 ){
232422 memset(p->aUpdateMask, 0, nU32*sizeof(u32));
232424 for(ii=0; ii<pIter->nCol; ii++){
232436 int nUp = 0;
232440 if( 0==memcmp(p->aUpdateMask, (*pp)->aMask, nU32*sizeof(u32)) ){
232454 *pp = 0;
232461 if( pUp==0 ){
232463 int bStat1 = (sqlite3_stricmp(pIter->zTab, "sqlite_stat1")==0);
232465 if( pUp==0 ){
232471 memset(&buf, 0, sizeof(buf));
232480 for(ii=0; ii<pIter->nCol; ii++){
232481 if( p->abPK[ii]==0 && sessionChangesetNew(pIter, ii) ){
232493 for(ii=0; ii<pIter->nCol; ii++){
232494 if( p->abPK[ii] || (bPatchset==0 && sessionChangesetOld(pIter, ii)) ){
232497 assert( sqlite3_stricmp(p->azCol[ii], "idx")==0 );
232500 "WHEN length(?4)=0 AND typeof(?4)='blob' THEN NULL "
232514 rc = sqlite3_prepare_v2(p->db, zSql, buf.nBuf, &pUp->pStmt, 0);
232519 pUp = 0;
232529 assert( (rc==SQLITE_OK)==(pUp!=0) );
232533 *ppStmt = 0;
232549 p->pUp = 0;
232551 p->aUpdateMask = 0;
232564 ** Variable :5 (nCol+1) is a boolean. It should be set to 0 if we require
232579 SessionBuffer buf = {0, 0, 0};
232580 int nPk = 0;
232586 for(i=0; i<p->nCol; i++){
232603 for(i=0; i<p->nCol; i++){
232616 rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pDelete, 0);
232663 SessionBuffer buf = {0, 0, 0};
232668 for(i=0; i<p->nCol; i++){
232669 if( i!=0 ) sessionAppendStr(&buf, ", ", &rc);
232680 rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pInsert, 0);
232687 return sqlite3_prepare_v2(db, zSql, -1, pp, 0);
232701 "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, "
232708 "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END "
232725 /* COVERAGE: The (pVal->z==0) branch is never true using current versions
232729 if( (eType==SQLITE_TEXT || eType==SQLITE_BLOB) && pVal->z==0 ){
232744 ** statement pStmt. If parameter abPK is NULL, all values from 0 to (nCol-1)
232768 for(i=0; rc==SQLITE_OK && i<nCol; i++){
232770 sqlite3_value *pVal = 0;
232772 if( pVal==0 ){
232812 sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
232820 for(ii=0; rc==SQLITE_OK && ii<nCol; ii++){
232821 if( p->abPK[ii]==0 ){
232822 sqlite3_value *pVal = 0;
232824 sqlite3_bind_int(pSelect, ii+1+nCol, (pVal==0));
232857 if( p->bRebaseStarted==0 ){
232874 for(i=0; i<p->nCol; i++){
232875 sqlite3_value *pVal = 0;
232930 int res = 0; /* Value returned by conflict handler */
232936 sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
232958 pIter->pConflict = 0;
233041 assert( !pbReplace || *pbReplace==0 );
233043 sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
233054 ** * (pbRetry==0), or
233058 u8 *abPK = (pIter->bPatchset ? p->abPK : 0);
233061 rc = sqlite3_bind_int(p->pDelete, nCol+1, (pbRetry==0 || abPK));
233067 if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 && p->bIgnoreNoop==0 ){
233071 }else if( (rc&0xff)==SQLITE_CONSTRAINT ){
233073 SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, 0
233079 sqlite3_stmt *pUp = 0;
233080 int bPatchset = (pbRetry==0 || pIter->bPatchset);
233085 for(i=0; rc==SQLITE_OK && i<nCol; i++){
233088 if( p->abPK[i] || (bPatchset==0 && pOld) ){
233098 ** the result will be SQLITE_OK with 0 rows modified. */
233102 if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 ){
233111 }else if( (rc&0xff)==SQLITE_CONSTRAINT ){
233114 SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, 0
233132 rc = sessionBindRow(pIter, sqlite3changeset_new, nCol, 0, p->pInsert);
233139 if( (rc&0xff)==SQLITE_CONSTRAINT ){
233166 int bReplace = 0;
233167 int bRetry = 0;
233181 rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, 0, 0);
233191 rc = sqlite3_exec(db, "SAVEPOINT replace_op", 0, 0, 0);
233202 rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, 0, 0);
233205 rc = sqlite3_exec(db, "RELEASE replace_op", 0, 0, 0);
233227 sqlite3_changeset_iter *pIter2 = 0;
233229 memset(&pApply->constraints, 0, sizeof(SessionBuffer));
233232 &pIter2, 0, 0, cons.nBuf, cons.aBuf, pApply->bInvertConstraints, 1
233243 if( rc==SQLITE_OK ) memset(pIter2->apValue, 0, nByte);
233252 assert( pApply->bDeferConstraints || pApply->constraints.nBuf==0 );
233258 pApply->bDeferConstraints = 0;
233288 int schemaMismatch = 0;
233290 const char *zTab = 0; /* Name of current table */
233291 int nTab = 0; /* Result of sqlite3Strlen30(zTab) */
233296 assert( xConflict!=0 );
233301 db->aDb[0].pSchema->schema_cookie -= 32;
233305 memset(&sApply, 0, sizeof(sApply));
233309 if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
233310 rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0);
233313 rc = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 1", 0, 0, 0);
233320 sqlite3changeset_op(pIter, &zNew, &nCol, &op, 0);
233322 if( zTab==0 || sqlite3_strnicmp(zNew, zTab, nTab+1) ){
233336 sApply.pDelete = 0;
233337 sApply.pInsert = 0;
233338 sApply.pSelect = 0;
233339 sApply.nCol = 0;
233340 sApply.azCol = 0;
233341 sApply.abPK = 0;
233342 sApply.bStat1 = 0;
233344 sApply.bRebaseStarted = 0;
233345 sApply.bRowid = 0;
233346 memset(&sApply.constraints, 0, sizeof(SessionBuffer));
233351 schemaMismatch = (xFilter && (0==xFilter(pCtx, zNew)));
233354 if( zTab==0 ){
233361 int nMinCol = 0;
233364 sqlite3changeset_pk(pIter, &abPK, 0);
233365 rc = sessionTableInfo(0, db, "main", zNew,
233366 &sApply.nCol, 0, &zTab, &sApply.azCol, 0, 0,
233370 for(i=0; i<sApply.nCol; i++){
233374 if( sApply.nCol==0 ){
233388 else if( nCol<nMinCol || memcmp(sApply.abPK, abPK, nCol)!=0 ){
233396 if( 0==sqlite3_stricmp(zTab, "sqlite_stat1") ){
233408 sApply.bStat1 = 0;
233435 sqlite3_db_status(db, SQLITE_DBSTATUS_DEFERRED_FKS, &nFk, ¬Used, 0);
233436 if( nFk!=0 ){
233439 memset(&sIter, 0, sizeof(sIter));
233449 int rc2 = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 0", 0, 0, 0);
233453 if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
233455 rc = sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
233458 sqlite3_exec(db, "ROLLBACK TO changeset_apply", 0, 0, 0);
233459 sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
233463 assert( sApply.bRebase || sApply.rebase.nBuf==0 );
233464 if( rc==SQLITE_OK && bPatchset==0 && sApply.bRebase ){
233467 sApply.rebase.aBuf = 0;
233477 if( (flags & SQLITE_CHANGESETAPPLY_FKNOACTION) && savedFlag==0 ){
233480 db->aDb[0].pSchema->schema_cookie -= 32;
233509 int rc = sessionChangesetStart(&pIter, 0, 0, nChangeset, pChangeset, bInv, 1);
233541 db, nChangeset, pChangeset, xFilter, xConflict, pCtx, 0, 0, 0
233569 int rc = sessionChangesetStart(&pIter, xInput, pIn, 0, 0, bInverse, 1);
233593 db, xInput, pIn, xFilter, xConflict, pCtx, 0, 0, 0
233626 SessionChange *pNew = 0;
233628 assert( aRec!=0 );
233635 memset(pNew, 0, sizeof(SessionChange));
233639 if( bIndirect==0 || bRebase==0 ){
233646 for(i=0; i<pTab->nCol; i++){
233648 if( *pIn==0 ){
233649 *pOut++ = 0;
233650 }else if( pTab->abPK[i]==0 ){
233651 *pOut++ = 0xFF;
233666 if( pNew==0 ){
233674 memset(pNew, 0, nByte);
233679 for(i=0; i<pTab->nCol; i++){
233682 if( *a1==0xFF || (pTab->abPK[i]==0 && bIndirect) ){
233683 *pOut++ = 0xFF;
233684 }else if( *a2==0 ){
233722 assert( pNew==0 );
233737 memset(pNew, 0, sizeof(SessionChange));
233745 if( bPatchset==0 ) sessionSkipRecord(&a1, pTab->nCol);
233754 if( 0==sessionMergeUpdate(&aCsr, pTab, bPatchset, aExist, 0,aRec,0) ){
233756 pNew = 0;
233763 if( bPatchset==0 ){
233768 if( 0==sessionMergeUpdate(&aCsr, pTab, bPatchset, aRec, aExist,a1,a2) ){
233770 pNew = 0;
233798 ** return 0.
233807 for(ii=0; ii<pTab->nCol; ii++){
233808 u8 bPK = (ii < nCol) ? abPK[ii] : 0;
233809 if( pTab->abPK[ii]!=bPK ) return 0;
233813 return (pTab->nCol==nCol && 0==memcmp(abPK, pTab->abPK, nCol));
233826 int ii = 0;
233831 pOut->nBuf = 0;
233832 if( op==SQLITE_INSERT || (op==SQLITE_DELETE && pGrp->bPatch==0) ){
233835 if( rc==SQLITE_OK && pTab->pDfltStmt==0 ){
233883 int iOff = 0;
233884 if( pGrp->bPatch==0 ){
233885 for(ii=0; ii<nCol; ii++){
233889 for(ii=0; ii<(pTab->nCol-nCol); ii++){
233890 sessionAppendByte(pOut, 0x00, &rc);
233895 for(ii=0; ii<(pTab->nCol-nCol); ii++){
233896 sessionAppendByte(pOut, 0x00, &rc);
233920 SessionTable *pTab = 0;
233922 u8 *abPK = 0;
233923 int nCol = 0;
233925 *ppTab = 0;
233930 if( 0==sqlite3_strnicmp(pTab->zName, zTab, nTab+1) ) break;
233941 memset(pTab, 0, sizeof(SessionTable));
233949 pTab->nCol = 0;
233950 rc = sessionInitTable(0, pTab, pGrp->db, pGrp->zDb);
233952 assert( pTab->azCol==0 );
233985 int nCol = 0;
233986 int op = 0;
233987 int iHash = 0;
233988 int bIndirect = 0;
233989 SessionChange *pChange = 0;
233990 SessionChange *pExist = 0;
233991 SessionChange **pp = 0;
233992 SessionTable *pTab = 0;
233996 assert( nRec>0 );
234001 if( pGrp->pList==0 ){
234008 const char *zTab = 0;
234021 if( rc==SQLITE_OK && sessionGrowHash(0, pIter->bPatchset, pTab) ){
234032 int bPkOnly1 = 0;
234033 int bPkOnly2 = 0;
234076 while( SQLITE_ROW==(sessionChangesetNext(pIter, &aRec, &nRec, 0)) ){
234101 ** are both set to 0 before returning.
234111 SessionBuffer buf = {0, 0, 0};
234113 assert( xOutput==0 || (ppOut==0 && pnOut==0) );
234120 if( pTab->nEntry==0 ) continue;
234123 for(i=0; i<pTab->nChange; i++){
234131 buf.nBuf = 0;
234139 if( buf.nBuf>0 ) rc = xOutput(pOut, buf.aBuf, buf.nBuf);
234143 buf.aBuf = 0;
234158 if( p==0 ){
234161 memset(p, 0, sizeof(sqlite3_changegroup));
234183 if( pGrp->zDb==0 ){
234202 rc = sessionChangesetToHash(pIter, pGrp, 0);
234225 rc = sessionOneChangeToHash(pGrp, pIter, 0);
234239 return sessionChangegroupOutput(pGrp, 0, 0, pnData, ppData);
234255 rc = sessionChangesetToHash(pIter, pGrp, 0);
234269 return sessionChangegroupOutput(pGrp, xOutput, pOut, 0, 0);
234278 sessionDeleteTable(0, pGrp->pList);
234366 for(i=0; i<nCol; i++){
234369 if( *a1==0 || *a1==0xFF ){
234395 ** in the rebase buffer is set to "replaced" (type 0xFF). If this
234400 ** corresponding field in the rebase buffer is not "undefined" (0x00)
234401 ** or "replaced" (0xFF), the old.* value is replaced by the value
234413 int bData = 0;
234421 for(i=0; i<pIter->nCol; i++){
234424 if( pIter->abPK[i] || a2[0]==0 ){
234425 if( !pIter->abPK[i] && a1[0] ) bData = 1;
234428 }else if( a2[0]!=0xFF && a1[0] ){
234433 *pOut++ = '\0';
234440 for(i=0; i<pIter->nCol; i++){
234443 if( pIter->abPK[i] || a2[0]!=0xFF ){
234447 *pOut++ = '\0';
234469 ** pnOut are not NULL, then the two output parameters are set to 0 before
234481 u8 *aRec = 0;
234482 int nRec = 0;
234483 int bNew = 0;
234484 SessionTable *pTab = 0;
234485 SessionBuffer sOut = {0,0,0};
234488 SessionChange *pChange = 0;
234489 int bDone = 0;
234494 if( 0==sqlite3_stricmp(pTab->zName, zTab) ) break;
234496 bNew = 0;
234511 int iHash = sessionChangeHash(pTab, 0, aRec, pTab->nChange);
234514 if( sessionChangeEqual(pTab, 0, aRec, 0, pChange->aRecord) ){
234526 if( pChange->bIndirect==0 ){
234538 if( pChange->bIndirect==0 ){
234569 if( bDone==0 ){
234576 sOut.nBuf = 0;
234583 memset(&sOut, 0, sizeof(sOut));
234588 if( sOut.nBuf>0 ){
234594 sOut.aBuf = 0;
234609 if( pNew==0 ){
234612 memset(pNew, 0, sizeof(sqlite3_rebaser));
234625 sqlite3_changeset_iter *pIter = 0; /* Iterator opened on pData/nData */
234643 sqlite3_changeset_iter *pIter = 0; /* Iterator to skip through input */
234647 rc = sessionRebase(p, pIter, 0, 0, pnOut, ppOut);
234664 sqlite3_changeset_iter *pIter = 0; /* Iterator to skip through input */
234668 rc = sessionRebase(p, pIter, xOutput, pOut, 0, 0);
234680 sessionDeleteTable(0, p->grp.pList);
234694 if( *pInt>0 ){
234773 #if 0
234835 ** created with the "columnsize=0" option.
234854 ** 0 is returned. Otherwise, this function returns the number of tokens in
234865 ** (i.e. if it is a contentless table), then this API always returns 0.
234971 ** iCol>=0;
234989 ** i.e. all those in column 0, sorted by offset, followed by those in
235005 ** iCol>=0;
235040 ** tables, this includes any embedded 0x00 and trailing data.
235052 ** includes any embedded 0x00 and trailing data.
235081 ** to NULL and 0, respectively. However, if the fts5_locale() function
235214 ** on a columnsize=0 database.
235221 ** which case nLocale is always 0) to indicate that the tokenizer should
235233 ** normally be set to 0. The exception is if the tokenizer supports
235250 ** for the current request. If pLocale and nLocale are both 0, then the
235333 ** xToken(pCtx, 0, "i", 1, 0, 1);
235334 ** xToken(pCtx, 0, "won", 3, 2, 5);
235335 ** xToken(pCtx, 0, "first", 5, 6, 11);
235337 ** xToken(pCtx, 0, "place", 5, 12, 17);
235427 #define FTS5_TOKENIZE_QUERY 0x0001
235428 #define FTS5_TOKENIZE_PREFIX 0x0002
235429 #define FTS5_TOKENIZE_DOCUMENT 0x0004
235430 #define FTS5_TOKENIZE_AUX 0x0008
235434 #define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */
235497 #if 0
235537 # define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0])))
235547 # define NEVER(X) (0)
235549 # define ALWAYS(X) ((X)?1:(assert(0),0))
235550 # define NEVER(X) ((X)?(assert(0),1):0)
235562 # define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
235576 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
235578 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
235585 # define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
235642 #define fts5Memcmp(s1, s2, n) ((n)<=0 ? 0 : memcmp((s1), (s2), (n)))
235742 int bContentlessDelete; /* "contentless_delete=" option (dflt==0) */
235743 int bContentlessUnindexed; /* "contentless_unindexed=" option (dflt=0) */
235747 int bTokendata; /* "tokendata=" option value (dflt==0) */
235748 int bLocale; /* "locale=" option value (dflt==0) */
235783 #define FTS5_CONTENT_NORMAL 0
235788 #define FTS5_DETAIL_FULL 0
235792 #define FTS5_PATTERN_NONE 0
235859 (u32)((pBuf)->n) + (u32)(nn) <= (u32)((pBuf)->nSpace) ? 0 : \
235867 #define FTS5_POS2COLUMN(iPos) (int)((iPos >> 32) & 0x7FFFFFFF)
235868 #define FTS5_POS2OFFSET(iPos) (int)(iPos & 0x7FFFFFFF)
235910 /* Bucket of terms object used by the integrity-check in offsets=0 mode. */
235940 #define FTS5INDEX_QUERY_PREFIX 0x0001 /* Prefix query */
235941 #define FTS5INDEX_QUERY_DESC 0x0002 /* Docs in descending rowid order */
235942 #define FTS5INDEX_QUERY_TEST_NOIDX 0x0004 /* Do not use prefix index */
235943 #define FTS5INDEX_QUERY_SCAN 0x0008 /* Scan query (fts5vocab) */
235948 #define FTS5INDEX_QUERY_SKIPEMPTY 0x0010
235949 #define FTS5INDEX_QUERY_NOOUTPUT 0x0020
235950 #define FTS5INDEX_QUERY_SKIPHASH 0x0040
235951 #define FTS5INDEX_QUERY_NOTOKENDATA 0x0080
235952 #define FTS5INDEX_QUERY_SCANONETERM 0x0100
235975 ** buffer, or 0 if there are less than nChar characters in total.
236133 if( nVal & 0x80 ){ \
236239 #define FTS5_STMT_SCAN_ASC 0 /* SELECT rowid, * FROM ... ORDER BY 1 ASC */
236320 ** rc==SQLITE_OK && 0==sqlite3Fts5ExprEof(pExpr);
236640 #define fts5YYDYNSTACK 0
236661 #define fts5YY_NLOOKAHEAD ((int)(sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0])))
236678 #if fts5YYSTACKDEPTH<=0 || fts5YYDYNSTACK
236681 # define fts5YYGROWABLESTACK 0
236686 #if fts5YYSTACKDEPTH<=0
236700 ** 0 <= N <= fts5YY_MAX_SHIFT Shift N. That is, push the lookahead
236744 /* 0 */ 81, 20, 96, 6, 28, 99, 98, 26, 26, 18,
236757 /* 0 */ 16, 17, 18, 19, 20, 22, 22, 24, 24, 17,
236764 /* 70 */ 24, 3, 1, 2, 3, 1, 2, 3, 0, 1,
236772 #define fts5YY_SHIFT_MIN (0)
236775 /* 0 */ 44, 44, 44, 44, 44, 44, 51, 77, 43, 12,
236784 /* 0 */ -16, -8, 0, 9, 17, 25, 46, -17, -17, 37,
236788 /* 0 */ 80, 80, 80, 80, 80, 80, 95, 80, 80, 105,
236860 static FILE *fts5yyTraceFILE = 0;
236861 static char *fts5yyTracePrompt = 0;
236885 if( fts5yyTraceFILE==0 ) fts5yyTracePrompt = 0;
236886 else if( fts5yyTracePrompt==0 ) fts5yyTraceFILE = 0;
236894 /* 0 */ "$",
236928 /* 0 */ "input ::= expr",
236963 ** of errors. Return 0 on success.
236974 pNew = fts5YYREALLOC(0, newSize*sizeof(pNew[0]));
236975 if( pNew==0 ) return 1;
236976 memcpy(pNew, p->fts5yystack, oldSize*sizeof(pNew[0]));
236978 pNew = fts5YYREALLOC(p->fts5yystack, newSize*sizeof(pNew[0]));
236979 if( pNew==0 ) return 1;
236990 return 0;
237016 fts5yypParser->fts5yyhwm = 0;
237024 fts5yypParser->fts5yystack[0].stateno = 0;
237025 fts5yypParser->fts5yystack[0].major = 0;
237121 assert( pParser->fts5yytos!=0 );
237176 if( p==0 ) return;
237213 int nMissed = 0;
237214 for(stateno=0; stateno<fts5YYNSTATE; stateno++){
237216 for(iLookAhead=0; iLookAhead<fts5YYNFTS5TOKEN; iLookAhead++){
237218 if( fts5yycoverage[stateno][iLookAhead]==0 ) nMissed++;
237247 assert( i>=0 );
237257 assert( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0]) );
237259 if( iFallback!=0 ){
237266 assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
237274 assert( j<(int)(sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0])) );
237275 if( fts5yy_lookahead[j]==fts5YYWILDCARD && iLookAhead>0 ){
237289 assert( i>=0 && i<(int)(sizeof(fts5yy_action)/sizeof(fts5yy_action[0])) );
237315 if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
237319 assert( i>=0 && i<fts5YY_ACTTAB_COUNT );
237407 16, /* (0) input ::= expr */
237440 -1, /* (0) input ::= expr */
237462 0, /* (22) neardist_opt ::= */
237467 0, /* (27) star_opt ::= */
237501 ** case 0:
237509 case 0: /* input ::= expr */
237510 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
237522 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
237524 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
237528 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
237534 …yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
237539 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
237541 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
237545 …lite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
237551 …qlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
237557 …lite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
237573 {fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
237574 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
237578 …4 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
237584 …fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5y…
237586 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
237590 …fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5y…
237596 { fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
237597 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
237601 sqlite3Fts5ParseSetCaret(fts5yymsp[0].minor.fts5yy53);
237602 fts5yymsp[-1].minor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
237615 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
237617 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
237621 …5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
237626 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
237629 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
237633 …rm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
237639 …ts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0…
237644 { fts5yymsp[0].minor.fts5yy4 = 1; }
237647 { fts5yymsp[1].minor.fts5yy4 = 0; }
237653 assert( fts5yyruleno<sizeof(fts5yyRuleInfoLhs)/sizeof(fts5yyRuleInfoLhs[0]) );
237775 int fts5yyerrorhit = 0; /* True if fts5yymajor has invoked an error */
237781 assert( fts5yypParser->fts5yytos!=0 );
237783 fts5yyendofinput = (fts5yymajor==0);
237806 assert( fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) );
237826 if( fts5yyRuleInfoNRhs[fts5yyruleno]==0 ){
237883 if( fts5yypParser->fts5yyerrcnt<0 ){
237903 if( fts5yypParser->fts5yytos <= fts5yypParser->fts5yystack || fts5yymajor==0 ){
237939 if( fts5yypParser->fts5yyerrcnt<=0 ){
237971 ** 0 if iToken has no fallback.
237975 assert( iToken<(int)(sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])) );
237979 return 0;
238012 ** (rc==SQLITE_OK && 0==fts5CInstIterEof(&iter);
238047 if( pIter->iStart<0 ){
238075 memset(pIter, 0, sizeof(CInstIter));
238114 ** negative, everything up until the first '\0' is appended to the output.
238126 if( n<0 ) n = (int)strlen(z);
238128 if( p->zOut==0 ) *pRc = SQLITE_NOMEM;
238152 if( p->iRangeEnd>=0 ){
238162 && (iPos<=p->iter.iStart || p->iter.iStart<0)
238166 p->bOpen = 0;
238174 if( iPos==p->iter.iStart && p->bOpen==0 ){
238182 if( p->bOpen==0 ){
238183 assert( p->iRangeEnd>=0 );
238197 if( p->iter.iStart>=0 && iPos>=p->iter.iStart ){
238202 p->bOpen = 0;
238232 iCol = sqlite3_value_int(apVal[0]);
238233 memset(&ctx, 0, sizeof(HighlightContext));
238242 const char *pLoc = 0; /* Locale of column iCol */
238243 int nLoc = 0; /* Size of pLoc in bytes */
238297 if( aNew==0 ) return SQLITE_NOMEM;
238323 if( (tflags & FTS5_TOKEN_COLOCATED)==0 ){
238325 if( p->iPos>0 ){
238327 char c = 0;
238328 for(i=iStartOff-1; i>=0; i--){
238336 rc = fts5SentenceFinderAdd(p, 0);
238356 int ip = 0;
238357 int ic = 0;
238358 int iOff = 0;
238361 int nScore = 0;
238362 int iLast = 0;
238366 for(i=0; i<nInst && rc==SQLITE_OK; i++){
238371 if( iFirst<0 ) iFirst = iOff;
238380 if( iAdj<0 ) iAdj = 0;
238412 int nInst = 0; /* Number of instance matches this row */
238417 int iBestStart = 0; /* First token of best snippet */
238418 int nBestScore = 0; /* Score of best snippet */
238419 int nColSize = 0; /* Total size of iBestCol in tokens */
238430 memset(&ctx, 0, sizeof(HighlightContext));
238431 iCol = sqlite3_value_int(apVal[0]);
238438 iBestCol = (iCol>=0 ? iCol : 0);
238441 if( aSeen==0 ){
238448 memset(&sFinder, 0, sizeof(Fts5SFinder));
238449 for(i=0; i<nCol; i++){
238450 if( iCol<0 || iCol==i ){
238451 const char *pLoc = 0; /* Locale of column iCol */
238452 int nLoc = 0; /* Size of pLoc in bytes */
238456 sFinder.iPos = 0;
238457 sFinder.nFirst = 0;
238469 for(ii=0; rc==SQLITE_OK && ii<nInst; ii++){
238479 memset(aSeen, 0, nPhrase);
238491 for(jj=0; jj<(sFinder.nFirst-1); jj++){
238496 memset(aSeen, 0, nPhrase);
238498 sFinder.aFirst[jj], nToken, &nScore, 0
238501 nScore += (sFinder.aFirst[jj]==0 ? 120 : 100);
238517 if( rc==SQLITE_OK && nColSize==0 ){
238521 const char *pLoc = 0; /* Locale of column iBestCol */
238522 int nLoc = 0; /* Bytes in pLoc */
238531 if( iBestStart>0 ){
238537 while( ctx.iter.iStart>=0 && ctx.iter.iStart<iBestStart && rc==SQLITE_OK ){
238610 p = (Fts5Bm25Data*)pApi->xGetAuxdata(pFts, 0);
238611 if( p==0 ){
238613 sqlite3_int64 nRow = 0; /* Number of rows in table */
238614 sqlite3_int64 nToken = 0; /* Number of tokens in table */
238622 if( p==0 ){
238625 memset(p, 0, (size_t)nByte);
238633 assert( rc!=SQLITE_OK || nRow>0 );
238638 for(i=0; rc==SQLITE_OK && i<nPhrase; i++){
238639 sqlite3_int64 nHit = 0;
238666 if( rc!=SQLITE_OK ) p = 0;
238688 int nInst = 0; /* Value returned by xInstCount() */
238690 double *aFreq = 0; /* Array of phrase freq. for current row */
238697 memset(aFreq, 0, sizeof(double) * pData->nPhrase);
238700 for(i=0; rc==SQLITE_OK && i<nInst; i++){
238719 for(i=0; i<pData->nPhrase; i++){
238741 int iCol = 0;
238742 int eType = 0;
238744 const char *zLocale = 0;
238745 int nLocale = 0;
238756 eType = sqlite3_value_numeric_type(apVal[0]);
238763 iCol = sqlite3_value_int(apVal[0]);
238764 if( iCol<0 || iCol>=pApi->xColumnCount(pFts) ){
238785 { "snippet", 0, fts5SnippetFunction, 0 },
238786 { "highlight", 0, fts5HighlightFunction, 0 },
238787 { "bm25", 0, fts5Bm25Function, 0 },
238788 { "fts5_get_locale", 0, fts5GetLocaleFunction, 0 },
238793 for(i=0; rc==SQLITE_OK && i<ArraySize(aBuiltin); i++){
238830 if( pNew==0 ){
238838 return 0;
238852 aBuf[0] = (iVal>>24) & 0x00FF;
238853 aBuf[1] = (iVal>>16) & 0x00FF;
238854 aBuf[2] = (iVal>> 8) & 0x00FF;
238855 aBuf[3] = (iVal>> 0) & 0x00FF;
238859 return (int)((((u32)aBuf[0])<<24) + (aBuf[1]<<16) + (aBuf[2]<<8) + aBuf[3]);
238875 assert( pBuf->p!=0 );
238883 ** ensures that the byte following the buffer data is set to 0x00, even
238901 ** following the buffer data is set to 0x00, even though this byte is not
238916 if( zTmp==0 ){
238926 char *zRet = 0;
238932 if( zRet==0 ){
238945 memset(pBuf, 0, sizeof(Fts5Buffer));
238953 pBuf->n = 0;
238967 pBuf->n = 0;
238977 assert( a!=0 || i==0 );
238985 assert( a!=0 );
238988 if( iVal==0 ){
238990 return 0;
238994 assert( iOff>=0 );
239001 *piOff = iOff + ((iVal-2) & 0x7FFFFFFF);
239003 *piOff = (iOff & (i64)0x7FFFFFFF<<32)+((iOff + (iVal-2)) & 0x7FFFFFFF);
239007 return 0;
239027 memset(pIter, 0, sizeof(*pIter));
239046 static const i64 colmask = ((i64)(0x7FFFFFFF)) << 32;
239062 int rc = 0; /* Initialized only to suppress erroneous warning from Clang */
239069 void *pRet = 0;
239072 if( pRet==0 ){
239073 if( nByte>0 ) *pRc = SQLITE_NOMEM;
239075 memset(pRet, 0, (size_t)nByte);
239090 char *zRet = 0;
239092 if( nIn<0 ){
239098 zRet[nIn] = '\0';
239114 ** * The underscore character "_" (0x5F).
239115 ** * The unicode "substitute" character (0x1A).
239119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 .. 0x0F */
239120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* 0x10 .. 0x1F */
239121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 .. 0x2F */
239122 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0x30 .. 0x3F */
239123 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 .. 0x4F */
239124 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x50 .. 0x5F */
239125 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 .. 0x6F */
239126 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70 .. 0x7F */
239129 return (t & 0x80) || aBareword[(int)t];
239160 *pbPresent = 0;
239170 for(i=nTerm-1; i>=0; i--){
239179 && memcmp(pEntry->pTerm, pTerm, nTerm)==0
239186 if( pEntry==0 ){
239205 for(i=0; i<ArraySize(p->apHash); i++){
239275 if( p==pIn ) p = 0;
239280 return (a>='0' && a<='9');
239289 if( sqlite3_strnicmp("null", p, 4)==0 ){
239292 p = 0;
239302 || (*p>='0' && *p<='9')
239306 if( *p=='\'' && 0==((p-pIn)%2) ){
239309 p = 0;
239312 p = 0;
239324 if( *p==0 ) p = 0;
239340 if( p==pIn ) p = 0;
239364 int iOut = 0;
239365 q = z[0];
239389 z[iOut] = '\0';
239409 assert( 0==fts5_iswhitespace(z[0]) );
239410 quote = z[0];
239432 for(i=0; aEnum[i].zName; i++){
239433 if( sqlite3_strnicmp(aEnum[i].zName, zEnum, nEnum)==0 ){
239434 if( iVal>=0 ) return SQLITE_ERROR;
239440 return iVal<0 ? SQLITE_ERROR : SQLITE_OK;
239461 if( sqlite3_strnicmp("prefix", zCmd, nCmd)==0 ){
239465 if( pConfig->aPrefix==0 ){
239472 int nPre = 0;
239474 while( p[0]==' ' ) p++;
239475 if( bFirst==0 && p[0]==',' ){
239477 while( p[0]==' ' ) p++;
239478 }else if( p[0]=='\0' ){
239481 if( p[0]<'0' || p[0]>'9' ){
239495 while( p[0]>='0' && p[0]<='9' && nPre<1000 ){
239496 nPre = nPre*10 + (p[0] - '0');
239500 if( nPre<=0 || nPre>=1000 ){
239508 bFirst = 0;
239514 if( sqlite3_strnicmp("tokenize", zCmd, nCmd)==0 ){
239525 for(nArg=0; p && *p; nArg++){
239540 if( p==0 ){
239546 azArg = 0;
239555 if( sqlite3_strnicmp("content", zCmd, nCmd)==0 ){
239560 if( zArg[0] ){
239570 if( sqlite3_strnicmp("contentless_delete", zCmd, nCmd)==0 ){
239571 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
239575 pConfig->bContentlessDelete = (zArg[0]=='1');
239580 if( sqlite3_strnicmp("contentless_unindexed", zCmd, nCmd)==0 ){
239581 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
239585 pConfig->bContentlessUnindexed = (zArg[0]=='1');
239590 if( sqlite3_strnicmp("content_rowid", zCmd, nCmd)==0 ){
239600 if( sqlite3_strnicmp("columnsize", zCmd, nCmd)==0 ){
239601 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
239605 pConfig->bColumnsize = (zArg[0]=='1');
239610 if( sqlite3_strnicmp("locale", zCmd, nCmd)==0 ){
239611 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
239615 pConfig->bLocale = (zArg[0]=='1');
239620 if( sqlite3_strnicmp("detail", zCmd, nCmd)==0 ){
239625 { 0, 0 }
239634 if( sqlite3_strnicmp("tokendata", zCmd, nCmd)==0 ){
239635 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
239639 pConfig->bTokendata = (zArg[0]=='1');
239669 const char *zRet = 0;
239675 *pbQuoted = 0;
239676 *pzOut = 0;
239678 if( zOut==0 ){
239682 if( fts5_isopenquote(zOut[0]) ){
239689 zOut[zRet-zIn] = '\0';
239694 if( zRet==0 ){
239711 if( 0==sqlite3_stricmp(zCol, FTS5_RANK_NAME)
239712 || 0==sqlite3_stricmp(zCol, FTS5_ROWID_NAME)
239717 if( 0==sqlite3_stricmp(zArg, "unindexed") ){
239736 Fts5Buffer buf = {0, 0, 0};
239744 for(i=0; i<p->nCol; i++){
239755 for(i=0; i<p->nCol; i++){
239756 if( p->abUnindexed[i]==0 ){
239764 assert( p->zContentExprlist==0 );
239793 int bUnindexed = 0; /* True if there are one or more UNINDEXED */
239796 if( pRet==0 ) return SQLITE_NOMEM;
239797 memset(pRet, 0, sizeof(Fts5Config));
239804 pRet->abUnindexed = pRet->azCol ? (u8*)&pRet->azCol[nArg] : 0;
239812 if( rc==SQLITE_OK && sqlite3_stricmp(pRet->zName, FTS5_RANK_NAME)==0 ){
239821 char *zOne = 0;
239822 char *zTwo = 0;
239823 int bOption = 0;
239824 int bMustBeCol = 0;
239830 assert( zOne!=0 );
239832 if( bMustBeCol ) z = 0;
239835 if( z && z[0] ){
239838 if( z && z[0] ) z = 0;
239842 if( z==0 ){
239854 zOne = 0;
239874 /* We only allow contentless_delete=1 if columnsize=0 is not present.
239878 if( rc==SQLITE_OK && pRet->bContentlessDelete && pRet->bColumnsize==0 ){
239880 "contentless_delete=1 is incompatible with columnsize=0"
239899 if( rc==SQLITE_OK && pRet->zContent==0 ){
239900 const char *zTail = 0;
239920 if( rc==SQLITE_OK && pRet->zContentRowid==0 ){
239931 *ppOut = 0;
239952 for(i=0; i<pConfig->nCol; i++){
239977 for(i=0; zSql && i<pConfig->nCol; i++){
239978 const char *zSep = (i==0?"":", ");
240005 ** int iPos // Position of token in input (first token is 0)
240026 if( pConfig->t.pTok==0 ){
240057 if( p==0 || *p==')' ) break;
240059 p = 0;
240084 char *zRank = 0;
240085 char *zRankArgs = 0;
240088 *pzRank = 0;
240089 *pzRankArgs = 0;
240091 if( p==0 ){
240116 if( p==0 ){
240128 assert( zRankArgs==0 );
240144 if( 0==sqlite3_stricmp(zKey, "pgsz") ){
240145 int pgsz = 0;
240156 else if( 0==sqlite3_stricmp(zKey, "hashsize") ){
240161 if( nHashSize<=0 ){
240168 else if( 0==sqlite3_stricmp(zKey, "automerge") ){
240173 if( nAutomerge<0 || nAutomerge>64 ){
240181 else if( 0==sqlite3_stricmp(zKey, "usermerge") ){
240193 else if( 0==sqlite3_stricmp(zKey, "crisismerge") ){
240198 if( nCrisisMerge<0 ){
240207 else if( 0==sqlite3_stricmp(zKey, "deletemerge") ){
240214 if( nVal<0 ) nVal = FTS5_DEFAULT_DELETE_AUTOMERGE;
240215 if( nVal>100 ) nVal = 0;
240219 else if( 0==sqlite3_stricmp(zKey, "rank") ){
240235 else if( 0==sqlite3_stricmp(zKey, "secure-delete") ){
240240 if( bVal<0 ){
240243 pConfig->bSecureDelete = (bVal ? 1 : 0);
240247 else if( 0==sqlite3_stricmp(zKey, "insttoken") ){
240252 if( bVal<0 ){
240255 pConfig->bPrefixInsttoken = (bVal ? 1 : 0);
240270 sqlite3_stmt *p = 0;
240272 int iVersion = 0;
240284 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &p, 0);
240288 assert( rc==SQLITE_OK || p==0 );
240291 const char *zK = (const char*)sqlite3_column_text(p, 0);
240293 if( 0==sqlite3_stricmp(zK, "version") ){
240296 int bDummy = 0;
240329 char *zMsg = 0;
240334 assert( *pConfig->pzErrmsg==0 );
240369 ** All token types in the generated fts5parse.h file are greater than 0.
240371 #define FTS5_EOF 0
240373 #define FTS5_LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
240409 ** An expression node with eType==0 may also exist. It always matches zero
240414 ** Distance from this node to furthest leaf. This is always 0 for nodes
240512 if( p->eType==FTS5_TERM || p->eType==FTS5_STRING || p->eType==0 ){
240513 assert( p->iHeight==0 );
240516 int iMaxChild = 0;
240517 for(ii=0; ii<p->nChild; ii++){
240534 assert( pParse->zErr==0 );
240572 case '\0': tok = FTS5_EOF; break;
240579 if( z2[0]=='"' ){
240581 if( z2[0]!='"' ) break;
240583 if( z2[0]=='\0' ){
240594 if( sqlite3Fts5IsBareword(z[0])==0 ){
240601 if( pToken->n==2 && memcmp(pToken->p, "OR", 2)==0 ) tok = FTS5_OR;
240602 if( pToken->n==3 && memcmp(pToken->p, "NOT", 3)==0 ) tok = FTS5_NOT;
240603 if( pToken->n==3 && memcmp(pToken->p, "AND", 3)==0 ) tok = FTS5_AND;
240630 *ppNew = 0;
240631 *pzErr = 0;
240632 memset(&sParse, 0, sizeof(sParse));
240635 if( pEngine==0 ){ return SQLITE_NOMEM; }
240654 pColset->aiCol[0] = iCol;
240659 assert( sParse.rc!=SQLITE_OK || sParse.zErr==0 );
240662 if( pNew==0 ){
240667 pNew->pIndex = 0;
240671 pNew->bDesc = 0;
240672 sParse.apPhrase = 0;
240679 if( 0==*pzErr ){
240692 int nRet = 0;
240694 for(ii=0; ii<nByte; ii++){
240695 if( (z[ii] & 0xC0)!=0x80 ) nRet++;
240715 if( zExpr==0 ){
240719 int iOut = 0;
240720 int i = 0;
240721 int iFirst = 0;
240723 if( bGlob==0 ){
240724 aSpec[0] = '_';
240726 aSpec[2] = 0;
240728 aSpec[0] = '*';
240735 || zText[i]==aSpec[0] || zText[i]==aSpec[1] || zText[i]==aSpec[2]
240757 if( iOut>0 ){
240758 int bAnd = 0;
240765 zExpr[iOut] = '\0';
240768 *pp = 0;
240782 for(i=0; i<p->nChild; i++){
240803 memset(&sParse, 0, sizeof(sParse));
240809 p1->pRoot = sqlite3Fts5ParseNode(&sParse, FTS5_AND, p1->pRoot, p2->pRoot,0);
240810 p2->pRoot = 0;
240816 if( ap==0 ){
240821 for(i=0; i<p2->nPhrase; i++){
240842 i64 iRet = 0;
240843 int bRetValid = 0;
240848 assert( bDesc==0 || bDesc==1 );
240850 if( 0==sqlite3Fts5IterEof(p->pIter) ){
240852 if( bRetValid==0 || (bDesc!=(iRowid<iRet)) ){
240859 if( pbEof && bRetValid==0 ) *pbEof = 1;
240874 int nIter = 0;
240882 if( sqlite3Fts5IterEof(pIter)==0 && pIter->iRowid==iRowid ){
240883 if( pIter->nData==0 ) continue;
240887 if( aNew==0 ){
240897 assert( aIter[nIter].bEof==0 );
240903 *pa = (u8*)aIter[0].a;
240904 *pn = aIter[0].n;
240906 Fts5PoslistWriter writer = {0};
240912 for(i=0; i<nIter; i++){
240913 if( aIter[i].bEof==0 ){
240954 Fts5PoslistWriter writer = {0};
240959 int bFirst = pPhrase->aTerm[0].bFirst;
240970 memset(aIter, 0, sizeof(Fts5PoslistReader) * pPhrase->nTerm);
240973 for(i=0; i<pPhrase->nTerm; i++){
240975 int n = 0;
240976 int bFlag = 0;
240977 u8 *a = 0;
240979 Fts5Buffer buf = {0, 0, 0};
240997 i64 iPos = aIter[0].iPos;
241000 for(i=0; i<pPhrase->nTerm; i++){
241004 bMatch = 0;
241011 }while( bMatch==0 );
241014 if( bFirst==0 || FTS5_POS2OFFSET(iPos)==0 ){
241019 for(i=0; i<pPhrase->nTerm; i++){
241025 *pbMatch = (pPhrase->poslist.n>0);
241026 for(i=0; i<pPhrase->nTerm; i++){
241056 memset(p, 0, sizeof(Fts5LookaheadReader));
241104 memset(aStatic, 0, sizeof(aStatic));
241108 return 0;
241119 for(i=0; i<pNear->nPhrase; i++){
241122 pPoslist->n = 0;
241133 iMax = a[0].reader.iPos;
241136 for(i=0; i<pNear->nPhrase; i++){
241140 bMatch = 0;
241147 }while( bMatch==0 );
241150 for(i=0; i<pNear->nPhrase; i++){
241153 if( a[i].pOut->n==0 || iPos!=pWriter->iPrev ){
241158 iAdv = 0;
241159 iMin = a[0].reader.iLookahead;
241160 for(i=0; i<pNear->nPhrase; i++){
241170 int bRet = a[0].pOut->n>0;
241197 if( (bDesc==0 && iLast>iRowid) || (bDesc && iLast<iRowid) ){
241205 assert( (bDesc==0 && iRowid>=iLast) || (bDesc==1 && iRowid<=iLast) );
241209 return 0;
241221 int bEof = 0;
241224 if( sqlite3Fts5IterEof(p->pIter)==0 ){
241226 if( (bDesc==0 && iLast>iRowid) || (bDesc && iLast<iRowid) ){
241252 Fts5ExprPhrase *pPhrase = pNear->apPhrase[0];
241253 pPhrase->poslist.n = 0;
241254 for(pTerm=&pPhrase->aTerm[0]; pTerm; pTerm=pTerm->pSynonym){
241256 if( sqlite3Fts5IterEof(pIter)==0 ){
241257 if( pIter->iRowid==pNode->iRowid && pIter->nData>0 ){
241269 for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){
241271 if( pPhrase->nTerm>1 || pPhrase->aTerm[0].pSynonym
241272 || pNear->pColset || pPhrase->aTerm[0].bFirst
241274 int bMatch = 0;
241276 if( bMatch==0 ) break;
241278 Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
241287 return 0;
241308 assert( pNode->bNomatch==0 );
241309 for(i=0; i<pNear->nPhrase; i++){
241311 if( pPhrase->nTerm==0 ){
241316 for(j=0; j<pPhrase->nTerm; j++){
241319 int bHit = 0;
241325 p->pIter = 0;
241329 (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) |
241330 (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0),
241334 assert( (rc==SQLITE_OK)==(p->pIter!=0) );
241336 if( 0==sqlite3Fts5IterEof(p->pIter) ){
241341 if( bHit==0 ){
241349 pNode->bEof = 0;
241368 assert( pExpr->bDesc==0 || pExpr->bDesc==1 );
241369 if( pExpr->bDesc==0 ){
241381 pNode->bNomatch = 0;
241382 for(i=0; i<pNode->nChild; i++){
241391 for(i=0; i<pNear->nPhrase; i++){
241393 pPhrase->poslist.n = 0;
241397 for(i=0; i<pNode->nChild; i++){
241443 Fts5ExprPhrase *pLeft = pNear->apPhrase[0];
241452 || pNear->apPhrase[0]->nTerm>1
241453 || pNear->apPhrase[0]->aTerm[0].pSynonym
241454 || pNear->apPhrase[0]->aTerm[0].bFirst
241461 if( pLeft->aTerm[0].pSynonym ){
241462 iLast = fts5ExprSynonymRowid(&pLeft->aTerm[0], bDesc, 0);
241464 iLast = pLeft->aTerm[0].pIter->iRowid;
241469 for(i=0; i<pNear->nPhrase; i++){
241471 for(j=0; j<pPhrase->nTerm; j++){
241474 i64 iRowid = fts5ExprSynonymRowid(pTerm, bDesc, 0);
241476 bMatch = 0;
241478 pNode->bNomatch = 0;
241485 bMatch = 0;
241492 }while( bMatch==0 );
241495 pNode->bNomatch = ((0==fts5ExprNearTest(&rc, pExpr, pNode)) && rc==SQLITE_OK);
241496 assert( pNode->bEof==0 || pNode->bNomatch==0 );
241514 Fts5ExprTerm *pTerm = &pNode->pNear->apPhrase[0]->aTerm[0];
241517 pNode->bNomatch = 0;
241523 i64 iRowid = fts5ExprSynonymRowid(pTerm, pExpr->bDesc, 0);
241528 if( sqlite3Fts5IterEof(p->pIter)==0 ){
241539 if( sqlite3Fts5IterEof(p->pIter)==0 ){
241540 bEof = 0;
241543 bEof = 0;
241564 if( pNode->bEof==0 ){
241582 Fts5ExprPhrase *pPhrase = pNode->pNear->apPhrase[0];
241583 Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
241587 assert( pPhrase->aTerm[0].pSynonym==0 );
241594 pNode->bNomatch = (pPhrase->poslist.n==0);
241608 Fts5IndexIter *pIter = pNode->pNear->apPhrase[0]->aTerm[0].pIter;
241610 assert( pNode->bEof==0 );
241616 if( rc==SQLITE_OK && sqlite3Fts5IterEof(pIter)==0 ){
241620 pNode->bNomatch = 0;
241629 Fts5ExprNode *pNext = pNode->apChild[0];
241635 if( cmp>0 || (cmp==0 && pChild->bNomatch==0) ){
241653 for(i=0; i<pNode->nChild; i++){
241655 assert( p1->bEof || fts5RowidCmp(pExpr, p1->iRowid, iLast)>=0 );
241656 if( p1->bEof==0 ){
241658 || (bFromValid && fts5RowidCmp(pExpr, p1->iRowid, iFrom)<0)
241662 pNode->bNomatch = 0;
241685 assert( pAnd->bEof==0 );
241687 pAnd->bNomatch = 0;
241689 for(iChild=0; iChild<pAnd->nChild; iChild++){
241692 if( cmp>0 ){
241696 pAnd->bNomatch = 0;
241705 assert( pChild->bEof || fts5RowidCmp(pExpr, iLast, pChild->iRowid)<=0 );
241711 bMatch = 0;
241719 }while( bMatch==0 );
241734 int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom);
241738 pNode->bNomatch = 0;
241748 Fts5ExprNode *p1 = pNode->apChild[0];
241752 while( rc==SQLITE_OK && p1->bEof==0 ){
241754 if( cmp>0 ){
241758 assert( rc!=SQLITE_OK || cmp<=0 );
241760 rc = fts5ExprNodeNext(pExpr, p1, 0, 0);
241777 int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom);
241782 pNode->bNomatch = 0;
241797 if( pNode->bEof==0 ){
241839 pNode->bEof = 0;
241840 pNode->bNomatch = 0;
241845 }else if( pNode->xNext==0 ){
241849 int nEof = 0;
241850 for(i=0; i<pNode->nChild && rc==SQLITE_OK; i++){
241853 assert( pChild->bEof==0 || pChild->bEof==1 );
241856 pNode->iRowid = pNode->apChild[0]->iRowid;
241860 if( nEof>0 ) fts5ExprSetEof(pNode);
241869 pNode->bEof = pNode->apChild[0]->bEof;
241887 ** If iterating in ascending rowid order (bDesc==0), the first document
241907 && 0==pRoot->bEof
241908 && fts5RowidCmp(p, pRoot->iRowid, iFirst)<0
241915 assert( pRoot->bEof==0 );
241916 rc = fts5ExprNodeNext(p, pRoot, 0, 0);
241930 assert( pRoot->bEof==0 && pRoot->bNomatch==0 );
241932 rc = fts5ExprNodeNext(p, pRoot, 0, 0);
241933 assert( pRoot->bNomatch==0 || (rc==SQLITE_OK && pRoot->bEof==0) );
241935 if( fts5RowidCmp(p, pRoot->iRowid, iLast)>0 ){
241961 for(i=0; i<pPhrase->nTerm; i++){
241974 if( pPhrase->poslist.nSpace>0 ) fts5BufferFree(&pPhrase->poslist);
241985 pPhrase->aTerm[0].bFirst = 1;
242003 Fts5ExprNearset *pRet = 0;
242006 if( pNear==0 ){
242010 if( pRet==0 ){
242013 memset(pRet, 0, (size_t)nByte);
242015 }else if( (pNear->nPhrase % SZALLOC)==0 ){
242021 if( pRet==0 ){
242029 if( pRet==0 ){
242034 if( pRet->nPhrase>0 ){
242036 assert( pParse!=0 );
242037 assert( pParse->apPhrase!=0 );
242040 if( pPhrase->nTerm==0 ){
242045 }else if( pLast->nTerm==0 ){
242086 if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){
242090 if( pSyn==0 ){
242093 memset(pSyn, 0, (size_t)nByte);
242105 if( pPhrase==0 || (pPhrase->nTerm % SZALLOC)==0 ){
242107 int nNew = SZALLOC + (pPhrase ? pPhrase->nTerm : 0);
242112 if( pNew==0 ){
242115 if( pPhrase==0 ) memset(pNew, 0, SZ_FTS5EXPRPHRASE(1));
242123 memset(pTerm, 0, sizeof(Fts5ExprTerm));
242150 for(i=0; i<pNear->nPhrase; i++){
242159 assert( pParse->pExpr==0 );
242164 if( (pParse->nPhrase % 8)==0 ){
242168 if( apNew==0 ){
242191 char *z = 0;
242193 memset(&sCtx, 0, sizeof(TokenCtx));
242199 int flags = FTS5_TOKENIZE_QUERY | (bPrefix ? FTS5_TOKENIZE_PREFIX : 0);
242209 sCtx.pPhrase = 0;
242212 if( pAppend==0 ){
242215 return 0;
242220 if( sCtx.pPhrase==0 ){
242227 assert( pParse->apPhrase!=0 );
242244 Fts5ExprPhrase *pOrig = 0; /* The phrase extracted from pExpr */
242245 Fts5Expr *pNew = 0; /* Expression to return via *ppNew */
242246 TokenCtx sCtx = {0,0,0}; /* Context object for fts5ParseTokenize */
242247 if( !pExpr || iPhrase<0 || iPhrase>=pExpr->nPhrase ){
242264 if( rc==SQLITE_OK && ALWAYS(pOrig!=0) ){
242282 for(i=0; rc==SQLITE_OK && i<pOrig->nTerm; i++){
242283 int tflags = 0;
242286 rc = fts5ParseTokenize((void*)&sCtx,tflags,p->pTerm,p->nFullTerm,0,0);
242306 pNew->apExprPhrase[0] = sCtx.pPhrase;
242307 pNew->pRoot->pNear->apPhrase[0] = sCtx.pPhrase;
242312 && pOrig->aTerm[0].pSynonym==0
242313 && pOrig->aTerm[0].bFirst==0
242324 pNew = 0;
242351 int nNear = 0;
242354 for(i=0; i<p->n; i++){
242356 if( c<'0' || c>'9' ){
242362 if( nNear<214748363 ) nNear = nNear * 10 + (p->p[i] - '0');
242386 int nCol = p ? p->nCol : 0; /* Num. columns already in colset object */
242390 assert( iCol>=0 && iCol<pParse->pConfig->nCol );
242393 if( pNew==0 ){
242398 for(i=0; i<nCol; i++){
242431 int iOld = 0;
242432 for(i=0; i<nCol; i++){
242450 Fts5Colset *pRet = 0;
242458 for(iCol=0; iCol<pConfig->nCol; iCol++){
242459 if( 0==sqlite3_stricmp(pConfig->azCol[iCol], z) ) break;
242469 if( pRet==0 ){
242494 pRet = 0;
242503 int iIn = 0; /* Next input in pColset */
242504 int iMerge = 0; /* Next input in pMerge */
242505 int iOut = 0; /* Next output slot in pColset */
242509 if( iDiff==0 ){
242513 }else if( iDiff>0 ){
242543 if( pNear->pColset->nCol==0 ){
242545 pNode->xNext = 0;
242549 *ppFree = 0;
242555 assert( pNode->eType!=FTS5_EOF || pNode->nChild==0 );
242556 for(i=0; i<pNode->nChild; i++){
242586 if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1
242587 && pNear->apPhrase[0]->aTerm[0].pSynonym==0
242588 && pNear->apPhrase[0]->aTerm[0].bFirst==0
242648 int nTerm = pNear->apPhrase[0]->nTerm;
242664 for(ii=0; ii<nTerm; ii++){
242672 Fts5ExprTerm *p = &pNear->apPhrase[0]->aTerm[ii];
242673 Fts5ExprTerm *pTo = &pPhrase->aTerm[0];
242680 0, 0, sqlite3Fts5ParseNearset(pParse, 0, pPhrase)
242688 pRet = 0;
242708 Fts5ExprNode *pRet = 0;
242711 int nChild = 0; /* Number of children of returned node */
242717 if( eType==FTS5_STRING && pNear==0 ) return 0;
242718 if( eType!=FTS5_STRING && pLeft==0 ) return pRight;
242719 if( eType!=FTS5_STRING && pRight==0 ) return pLeft;
242723 && pNear->apPhrase[0]->nTerm>1
242744 for(iPhrase=0; iPhrase<pNear->nPhrase; iPhrase++){
242746 if( pNear->apPhrase[iPhrase]->nTerm==0 ){
242747 pRet->xNext = 0;
242753 Fts5ExprPhrase *pPhrase = pNear->apPhrase[0];
242756 || (pPhrase->nTerm>0 && pPhrase->aTerm[0].bFirst)
242763 pRet = 0;
242764 pNear = 0;
242765 assert( pLeft==0 && pRight==0 );
242769 assert( pNear==0 );
242772 pLeft = pRight = 0;
242779 pRet = 0;
242786 if( pRet==0 ){
242800 Fts5ExprNode *pRet = 0;
242830 assert( pParse->apPhrase!=0 );
242831 assert( pParse->nPhrase>0 );
242832 assert( pParse->apPhrase[pParse->nPhrase-1]==pRight->pNear->apPhrase[0] );
242848 assert( ap[0]==pPrev->pNear->apPhrase[0] );
242855 pRet = sqlite3Fts5ParseNode(pParse, FTS5_AND, pLeft, pRight, 0);
242864 sqlite3_int64 nByte = 0;
242875 int i = 0;
242891 zQuoted[i++] = '\0';
242922 char *zRet = 0;
242929 if( zRet==0 ) return 0;
242934 zRet = fts5PrintfAppend(zRet, "-col %d ", aiCol[0]);
242936 zRet = fts5PrintfAppend(zRet, "-col {%d", aiCol[0]);
242942 if( zRet==0 ) return 0;
242947 if( zRet==0 ) return 0;
242951 if( zRet==0 ) return 0;
242953 for(i=0; i<pNear->nPhrase; i++){
242957 for(iTerm=0; zRet && iTerm<pPhrase->nTerm; iTerm++){
242959 zRet = fts5PrintfAppend(zRet, "%s%.*s", iTerm==0?"":" ",
242968 if( zRet==0 ) return 0;
242971 }else if( pExpr->eType==0 ){
242974 char const *zOp = 0;
242986 for(i=0; zRet && i<pExpr->nChild; i++){
242990 zRet = 0;
243001 char *zRet = 0;
243002 if( pExpr->eType==0 ){
243014 for(ii=0; ii<pColset->nCol; ii++){
243022 if( zRet==0 ) return 0;
243027 if( zRet==0 ) return 0;
243030 for(i=0; i<pNear->nPhrase; i++){
243032 if( i!=0 ){
243034 if( zRet==0 ) return 0;
243036 for(iTerm=0; iTerm<pPhrase->nTerm; iTerm++){
243039 zRet = fts5PrintfAppend(zRet, "%s%s", iTerm==0?"":" + ", zTerm);
243042 if( zTerm==0 || zRet==0 ){
243044 return 0;
243051 if( zRet==0 ) return 0;
243055 char const *zOp = 0;
243067 for(i=0; i<pExpr->nChild; i++){
243069 if( z==0 ){
243071 zRet = 0;
243076 (i==0 ? "" : zOp),
243080 if( zRet==0 ) break;
243088 ** The implementation of user-defined scalar functions fts5_expr() (bTcl==0)
243089 ** and fts5_expr_tcl() (bTcl!=0).
243099 const char *zExpr = 0;
243100 char *zErr = 0;
243101 Fts5Expr *pExpr = 0;
243108 Fts5Config *pConfig = 0;
243127 if( azConfig==0 ){
243131 azConfig[0] = 0;
243139 zExpr = (const char*)sqlite3_value_text(apVal[0]);
243140 if( zExpr==0 ) zExpr = "";
243144 rc = sqlite3Fts5ExprNew(pConfig, 0, pConfig->nCol, zExpr, &pExpr, &zErr);
243148 if( pExpr->pRoot->xNext==0 ){
243155 if( zText==0 ){
243181 fts5ExprFunction(pCtx, nArg, apVal, 0);
243194 ** unicode code point, 1 is returned. Otherwise 0.
243209 memset(aArr, 0, sizeof(aArr));
243213 iCode = sqlite3_value_int(apVal[0]);
243228 int bRemoveDiacritics = 0;
243229 iCode = sqlite3_value_int(apVal[0]);
243255 for(i=0; rc==SQLITE_OK && i<ArraySize(aFunc); i++){
243257 rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0);
243278 return (pExpr ? pExpr->nPhrase : 0);
243285 if( iPhrase<0 || iPhrase>=pExpr->nPhrase ) return 0;
243297 if( pNode->bEof==0 && pNode->iRowid==pExpr->pRoot->iRowid ){
243301 *pa = 0;
243302 nRet = 0;
243327 memset(pRet, 0, sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
243328 for(i=0; i<pExpr->nPhrase; i++){
243333 (pBuf->n==0 || pNode->iRowid!=pExpr->pRoot->iRowid || pNode->bEof)
243337 pBuf->n = 0;
243356 for(i=0; i<pColset->nCol; i++){
243359 return 0;
243364 ** an embedded 0x00 byte. If it does, return the number of bytes in
243365 ** the buffer before the 0x00. If it does not, return nToken.
243369 for(ii=0; ii<nToken && pToken[ii]; ii++){}
243393 if( (tflags & FTS5_TOKEN_COLOCATED)==0 ) p->iOff++;
243394 for(i=0; i<pExpr->nPhrase; i++){
243396 if( p->aPopulator[i].bOk==0 ) continue;
243397 for(pT=&pExpr->apExprPhrase[i]->aTerm[0]; pT; pT=pT->pSynonym){
243399 && memcmp(pT->pTerm, pToken, pT->nQueryTerm)==0
243406 int iTokOff = p->iOff & 0x7FFFFFFF;
243432 for(i=0; i<pExpr->nPhrase; i++){
243435 if( (pColset && 0==fts5ExprColsetTest(pColset, iCol))
243438 aPopulator[i].bOk = 0;
243451 pNode->pNear->apPhrase[0]->poslist.n = 0;
243454 for(i=0; i<pNode->nChild; i++){
243462 pNode->bEof = 0;
243464 case 0:
243467 return (pNode->pNear->apPhrase[0]->poslist.n>0);
243471 for(i=0; i<pNode->nChild; i++){
243472 if( fts5ExprCheckPoslists(pNode->apChild[i], iRowid)==0 ){
243474 return 0;
243482 int bRet = 0;
243483 for(i=0; i<pNode->nChild; i++){
243493 if( 0==fts5ExprCheckPoslists(pNode->apChild[0], iRowid)
243494 || 0!=fts5ExprCheckPoslists(pNode->apChild[1], iRowid)
243497 return 0;
243522 assert( iPhrase>=0 && iPhrase<pExpr->nPhrase );
243525 if( pNode->bEof==0
243527 && pPhrase->poslist.n>0
243529 Fts5ExprTerm *pTerm = &pPhrase->aTerm[0];
243536 *ppCollist = pPhrase->aTerm[0].pIter->pData;
243537 *pnCollist = pPhrase->aTerm[0].pIter->nData;
243540 *ppCollist = 0;
243541 *pnCollist = 0;
243557 Fts5ExprPhrase *pPhrase = 0;
243559 if( iPhrase<0 || iPhrase>=pExpr->nPhrase ){
243563 if( iToken<0 || iToken>=pPhrase->nTerm ){
243585 Fts5ExprPhrase *pPhrase = 0;
243586 Fts5ExprTerm *pTerm = 0;
243589 if( iPhrase<0 || iPhrase>=pExpr->nPhrase ){
243593 if( iToken<0 || iToken>=pPhrase->nTerm ){
243615 for(ii=0; ii<pExpr->nPhrase; ii++){
243617 for(pT=&pExpr->apExprPhrase[ii]->aTerm[0]; pT; pT=pT->pSynonym){
243645 ** to accumulate "term -> doclist" content before it is flushed to a level-0
243668 ** followed by the term data. For example: "0token". There is no
243675 ** * Position list, without 0x00 terminator.
243717 if( pNew==0 ){
243721 memset(pNew, 0, sizeof(Fts5Hash));
243728 if( pNew->aSlot==0 ){
243730 *ppNew = 0;
243733 memset(pNew->aSlot, 0, (size_t)nByte);
243755 for(i=0; i<pHash->nSlot; i++){
243763 memset(pHash->aSlot, 0, pHash->nSlot * sizeof(Fts5HashEntry*));
243764 pHash->nEntry = 0;
243770 for(i=n-1; i>=0; i--){
243779 for(i=n-1; i>=0; i--){
243797 memset(apNew, 0, nNew*sizeof(Fts5HashEntry*));
243799 for(i=0; i<pHash->nSlot; i++){
243821 int nRet = 0;
243828 pPtr[nData++] = 0x00;
243830 pPtr[nData++] = 0x00;
243837 assert( p->bDel==0 || p->bDel==1 );
243849 if( p2==0 ){
243850 p->iSzPoslist = 0;
243851 p->bDel = 0;
243852 p->bContent = 0;
243878 int nIncr = 0; /* Amount to increment (*pHash->pnByte) by */
243887 if( zKey[0]==bByte
243889 && memcmp(&zKey[1], pToken, nToken)==0
243896 if( p==0 ){
243912 memset(p, 0, sizeof(Fts5HashEntry));
243915 zKey[0] = bByte;
243919 zKey[nToken+1] = '\0';
243932 p->iCol = (pHash->eDetail==FTS5_DETAIL_FULL ? 0 : -1);
243952 if( pNew==0 ) return SQLITE_NOMEM;
243968 fts5HashAddPoslistSize(pHash, p, 0);
243975 p->iCol = (pHash->eDetail==FTS5_DETAIL_FULL ? 0 : -1);
243976 p->iPos = 0;
243980 if( iCol>=0 ){
243988 pPtr[p->nData++] = 0x01;
243991 p->iPos = 0;
244026 Fts5HashEntry *pRet = 0;
244030 if( p1==0 ){
244032 p2 = 0;
244033 }else if( p2==0 ){
244035 p1 = 0;
244042 if( cmp==0 ){
244045 assert( cmp!=0 );
244047 if( cmp>0 ){
244058 *ppOut = 0;
244080 *ppSorted = 0;
244083 memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
244085 for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
244088 if( pTerm==0
244089 || (pIter->nKey>=nTerm && 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm))
244092 pEntry->pScanNext = 0;
244093 for(i=0; ap[i]; i++){
244095 ap[i] = 0;
244102 pList = 0;
244103 for(i=0; i<nMergeSlot; i++){
244123 char *zKey = 0;
244128 if( nTerm==p->nKey && memcmp(zKey, pTerm, nTerm)==0 ) break;
244141 *pnDoclist = 0;
244145 *ppOut = 0;
244146 *pnDoclist = 0;
244161 int nEntry = 0;
244163 for(ii=0; ii<pHash->nSlot; ii++){
244164 Fts5HashEntry *p = 0;
244178 return pHash->nEntry==0;
244187 return (p->pScan==0);
244201 fts5HashAddPoslistSize(pHash, p, 0);
244207 *pzTerm = 0;
244208 *pnTerm = 0;
244209 *ppDoclist = 0;
244210 *pnDoclist = 0;
244264 #define FTS5_MAIN_PREFIX '0'
244282 ** 4 bytes [0xff 0x00 0x00 0x01]. This is unambiguous as the value of a
244283 ** varint has to be at least 16256 to begin with "0xFF". And the default
244309 ** followed by the following 4 bytes: [0xFF 0x00 0x00 0x01].
244317 ** Then, for each level from 0 to nMax:
244322 ** + segment id (always > 0)
244323 ** + first leaf page number (often 1, always greater than 0)
244362 ** varint: rowid delta (always > 0)
244370 ** collist: collist for column 0
244372 ** 0x01 byte
244390 ** and occurs before the first term (otherwise 0).
244393 ** footer is 0 bytes in size, then this field is the same as the
244425 ** 0x01: Clear if leaf is also the root page, otherwise set.
244433 ** or an 0x00 byte otherwise.
244438 ** 0x01: Clear for root page, otherwise set.
244467 ** 1-byte: rowid-0-tombstone flag. This flag is only valid on the
244468 ** first tombstone hash page for each segment (iPg=0). If set,
244469 ** the hash table contains rowid 0. If clear, it does not.
244470 ** Rowid 0 is handled specially.
244510 #define FTS5_SEGMENT_ROWID(segid, pgno) fts5_dri(segid, 0, 0, pgno)
244512 #define FTS5_TOMBSTONE_ROWID(segid,ipg) fts5_dri(segid+(1<<16), 0, 0, ipg)
244598 /* Output variables. aPoslist==0 at EOF */
244630 Fts5StructureSegment *aSeg; /* Array of segments. aSeg[0] is oldest. */
244634 u64 nWriteCounter; /* Total leaves written to level 0 */
244667 /* TODO1: Can use (writer.pgidx.n==0) instead of bFirstTermInPage */
244791 #define FTS5_SEGITER_ONETERM 0x01
244792 #define FTS5_SEGITER_REVERSE 0x02
244822 ** the smallest key overall. aFirst[0] is unused.
244891 aOut[0] = (iVal>>8);
244892 aOut[1] = (iVal&0xFF);
244896 return ((u16)aIn[0] << 8) + aIn[1];
244905 return ((u64)a[0] << 56)
244912 + ((u64)a[7] << 0);
244921 return ((u32)a[0] << 24)
244924 + ((u32)a[3] << 0);
244932 a[0] = ((iVal >> 56) & 0xFF);
244933 a[1] = ((iVal >> 48) & 0xFF);
244934 a[2] = ((iVal >> 40) & 0xFF);
244935 a[3] = ((iVal >> 32) & 0xFF);
244936 a[4] = ((iVal >> 24) & 0xFF);
244937 a[5] = ((iVal >> 16) & 0xFF);
244938 a[6] = ((iVal >> 8) & 0xFF);
244939 a[7] = ((iVal >> 0) & 0xFF);
244947 a[0] = ((iVal >> 24) & 0xFF);
244948 a[1] = ((iVal >> 16) & 0xFF);
244949 a[2] = ((iVal >> 8) & 0xFF);
244950 a[3] = ((iVal >> 0) & 0xFF);
244966 ** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
244978 return (res==0 ? (pLeft->n - nRight) : res);
244986 ** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
244994 assert( nCmp<=0 || pLeft->p!=0 );
244995 assert( nCmp<=0 || pRight->p!=0 );
244997 return (res==0 ? (pLeft->n - pRight->n) : res);
245013 p->pReader = 0;
245026 Fts5Data *pRet = 0;
245035 p->pReader = 0;
245037 assert( p->pReader==0 );
245047 if( p->pReader==0 && rc==SQLITE_OK ){
245050 pConfig->zDb, p->zDataTbl, "block", iRowid, 0, &p->pReader
245062 u8 *aOut = 0; /* Read blob data into this buffer */
245075 rc = sqlite3_blob_read(p->pReader, aOut, nByte, 0);
245079 pRet = 0;
245082 pRet->p[nByte] = 0x00;
245083 pRet->p[nByte+1] = 0x00;
245091 assert( (pRet==0)==(p->rc!=SQLITE_OK) );
245092 assert( pRet==0 || EIGHT_BYTE_ALIGNMENT( pRet->p ) );
245111 pRet = 0;
245126 ppStmt, 0);
245146 if( p->pWriter==0 ){
245170 if( p->pDeleter==0 ){
245190 i64 iFirst = FTS5_SEGMENT_ROWID(iSegid, 0);
245191 i64 iLast = FTS5_SEGMENT_ROWID(iSegid+1, 0)-1;
245195 i64 iTomb1 = FTS5_TOMBSTONE_ROWID(iSegid, 0);
245199 if( p->pIdxDeleter==0 ){
245218 if( pStruct && 0>=(--pStruct->nRef) ){
245220 assert( pStruct->nRef==0 );
245221 for(i=0; i<pStruct->nLevel; i++){
245263 for(i=0; i<p->nLevel; i++) pNew->aLevel[i].aSeg = 0;
245264 for(i=0; i<p->nLevel; i++){
245268 if( pLvl->aSeg==0 ){
245269 for(i=0; i<p->nLevel; i++){
245303 int i = 0;
245305 int nLevel = 0;
245306 int nSegment = 0;
245308 Fts5Structure *pRet = 0; /* Structure object to return */
245309 int bStructureV2 = 0; /* True for FTS5_STRUCTURE_V2 */
245310 u64 nOriginCntr = 0; /* Largest origin value seen so far */
245317 if( 0==memcmp(&pData[i], FTS5_STRUCTURE_V2, 4) ){
245326 if( nLevel>FTS5_MAX_SEGMENT || nLevel<0
245327 || nSegment>FTS5_MAX_SEGMENT || nSegment<0
245340 for(iLvl=0; rc==SQLITE_OK && iLvl<nLevel; iLvl++){
245342 int nTotal = 0;
245359 for(iSeg=0; iSeg<nTotal; iSeg++){
245365 assert( pSeg!=0 );
245382 if( iLvl>0 && pLvl[-1].nMerge && nTotal==0 ) rc = FTS5_CORRUPT;
245386 if( nSegment!=0 && rc==SQLITE_OK ) rc = FTS5_CORRUPT;
245393 pRet = 0;
245407 assert( (ppStruct!=0 && (*ppStruct)!=0) || (*pRc)!=SQLITE_OK );
245415 memset(&pStruct->aLevel[nLevel], 0, sizeof(Fts5StructureLevel));
245443 if( bInsert==0 ){
245444 memset(&aNew[pLvl->nSeg], 0, sizeof(Fts5StructureSegment) * nExtra);
245448 memset(aNew, 0, sizeof(Fts5StructureSegment) * nExtra);
245458 Fts5Structure *pRet = 0;
245466 memset(&pData->p[pData->nn], 0, FTS5_DATA_PADDING);
245468 if( p->rc==SQLITE_OK && (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
245474 pRet = 0;
245482 i64 iVersion = 0;
245485 if( p->pDataVersion==0 ){
245489 if( p->rc ) return 0;
245493 iVersion = sqlite3_column_int64(p->pDataVersion, 0);
245514 if( p->pStruct==0 ){
245521 #if 0
245528 for(i=0; i<pTest->nLevel; i++){
245531 for(j=0; j<pTest->aLevel[i].nSeg; j++){
245544 if( p->rc!=SQLITE_OK ) return 0;
245545 assert( p->iStructVersion!=0 );
245546 assert( p->pStruct!=0 );
245554 p->pStruct = 0;
245564 int nSegment = 0; /* Total number of segments */
245567 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
245599 int nHdr = (pStruct->nOriginCntr>0 ? (4+4+9+9+9) : (4+9+9));
245602 memset(&buf, 0, sizeof(Fts5Buffer));
245606 if( iCookie<0 ) iCookie = 0;
245608 if( 0==sqlite3Fts5BufferSize(&p->rc, &buf, nHdr) ){
245611 if( pStruct->nOriginCntr>0 ){
245619 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
245626 for(iSeg=0; iSeg<pLvl->nSeg; iSeg++){
245631 if( pStruct->nOriginCntr>0 ){
245646 #if 0
245651 memset(&buf, 0, sizeof(buf));
245679 if( pOut->nMerge==0 ){
245683 for(is=pLvl->nSeg-1; is>=0; is--){
245721 int szPromote = 0; /* Promote anything this size or smaller */
245726 if( nSeg==0 ) return;
245731 for(iTst=iLvl-1; iTst>=0 && pStruct->aLevel[iTst].nSeg==0; iTst--);
245732 if( iTst>=0 ){
245734 int szMax = 0;
245736 assert( pTst->nMerge==0 );
245737 for(i=0; i<pTst->nSeg; i++){
245751 if( iPromote<0 ){
245767 if( pLvl->iOff==0 ){
245768 assert( pLvl->bEof==0 );
245803 if( pLvl[1].bEof==0 ){
245805 memset(pLvl, 0, sizeof(Fts5DlidxLvl));
245814 return pIter->aLvl[0].bEof;
245817 return fts5DlidxIterNextR(p, pIter, 0);
245833 for(i=0; i<pIter->nLvl; i++){
245836 return pIter->aLvl[0].bEof;
245841 return p->rc!=SQLITE_OK || pIter->aLvl[0].bEof;
245848 for(i=pIter->nLvl-1; p->rc==SQLITE_OK && i>=0; i--){
245850 while( fts5DlidxLvlNext(pLvl)==0 );
245851 pLvl->bEof = 0;
245853 if( i>0 ){
245856 memset(pChild, 0, sizeof(Fts5DlidxLvl));
245870 assert( pLvl->bEof==0 );
245876 pLvl->iOff = 0;
245879 int nZero = 0;
245881 u64 delta = 0;
245883 while( a[ii]==0 ){
245906 if( pLvl[1].bEof==0 ){
245908 memset(pLvl, 0, sizeof(Fts5DlidxLvl));
245913 while( fts5DlidxLvlNext(pLvl)==0 );
245914 pLvl->bEof = 0;
245920 return pIter->aLvl[0].bEof;
245923 return fts5DlidxIterPrevR(p, pIter, 0);
245932 for(i=0; i<pIter->nLvl; i++){
245945 Fts5DlidxIter *pIter = 0;
245947 int bDone = 0;
245949 for(i=0; p->rc==SQLITE_OK && bDone==0; i++){
245954 if( pNew==0 ){
245960 memset(pLvl, 0, sizeof(Fts5DlidxLvl));
245962 if( pLvl->pData && (pLvl->pData->p[0] & 0x0001)==0 ){
245971 if( bRev==0 ){
245980 pIter = 0;
245987 return pIter->aLvl[0].iRowid;
245990 return pIter->aLvl[0].iLeafPgno;
246006 pIter->pNextLeaf = 0;
246012 pIter->pLeaf = 0;
246036 int n = 0;
246038 assert_nc( nSz>=0 );
246040 *pbDel = nSz & 0x0001;
246061 pIter->bDel = 0;
246063 if( iOff<iEod && pIter->pLeaf->p[iOff]==0 ){
246066 if( iOff<iEod && pIter->pLeaf->p[iOff]==0 ){
246070 pIter->nPos = 0;
246076 pIter->bDel = (nSz & 0x0001);
246078 assert_nc( pIter->nPos>=0 );
246091 if( pIter->pLeaf==0 ){
246105 ** of the "nPrefix" field (if there was one - it is passed 0 if this is
246123 if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
246167 if( nTomb>0 ){
246192 if( pSeg->pgnoFirst==0 ){
246196 ** The caller will see the (pIter->pLeaf==0) and assume the iterator is
246198 assert( pIter->pLeaf==0 );
246203 memset(pIter, 0, sizeof(*pIter));
246214 assert( pIter->pLeaf!=0 );
246218 fts5SegIterLoadTerm(p, pIter, 0);
246244 int iRowidOffset = 0;
246252 u64 iDelta = 0;
246256 if( i<n && a[i]==0 ){
246258 if( i<n && a[i]==0 ) i++;
246274 if( aNew==0 ){
246297 pIter->pLeaf = 0;
246307 ** In this case leave pIter->pLeaf==0, this iterator is at EOF. */
246309 assert( pIter->pLeaf==0 );
246345 ** points to a delete marker. A delete marker is an entry with a 0 byte
246350 return (p->rc==SQLITE_OK && pSeg->pLeaf && pSeg->nPos==0);
246364 assert( pIter->pNextLeaf==0 );
246367 if( pIter->iRowidOffset>0 ){
246400 assert( (pIter->flags & FTS5_SEGITER_REVERSE)==0 );
246409 if( p->rc || pIter->pLeaf==0 ) return;
246410 pIter->iRowid = 0;
246420 }else if( (pIter->flags & FTS5_SEGITER_ONETERM)==0 ){
246422 int nKeep = 0;
246429 const u8 *pList = 0;
246430 const char *zTerm = 0;
246431 int nTerm = 0;
246435 if( pList==0 ) goto next_none_eof;
246454 pIter->pLeaf = 0;
246472 int bNewTerm = 0;
246473 int nKeep = 0;
246477 assert( pbNewTerm==0 || *pbNewTerm==0 );
246499 assert_nc( iDelta>0 );
246503 }else if( pIter->pSeg==0 ){
246504 const u8 *pList = 0;
246505 const char *zTerm = 0;
246506 int nTerm = 0;
246507 int nList = 0;
246509 if( 0==(pIter->flags & FTS5_SEGITER_ONETERM) ){
246513 if( pList==0 ){
246515 pIter->pLeaf = 0;
246526 iOff = 0;
246528 while( iOff==0 ){
246531 if( pLeaf==0 ) break;
246564 pIter->pLeaf = 0;
246577 pIter->bDel = (nSz & 0x0001);
246579 assert_nc( pIter->nPos>=0 );
246588 while( (a[iOff++] & 0x80) && iOff<iEnd ); \
246598 Fts5Data *pLast = 0;
246599 int pgnoLast = 0;
246641 if( bTermless==0 ) break;
246691 assert( pIter->pDlidx==0 );
246729 u32 nMatch = 0;
246730 u32 nKeep = 0;
246731 u32 nNew = 0;
246734 int bEndOfPage = 0;
246759 for(i=0; i<nCmp; i++){
246794 if( bGe==0 ){
246796 pIter->pLeaf = 0;
246801 if( pIter->pLeaf==0 ) return;
246803 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
246810 nKeep = 0;
246846 if( p->pIdxSelect==0 ){
246873 int bDlidx = 0; /* True if there is a doclist-index */
246874 sqlite3_stmt *pIdxSelect = 0;
246876 assert( bGe==0 || (flags & FTS5INDEX_QUERY_DESC)==0 );
246878 memset(pIter, 0, sizeof(*pIter));
246888 i64 val = sqlite3_column_int(pIdxSelect, 0);
246890 bDlidx = (val & 0x0001);
246897 bDlidx = 0;
246907 if( p->rc==SQLITE_OK && (bGe==0 || (flags & FTS5INDEX_QUERY_SCANONETERM)) ){
246923 if( 0==(flags & FTS5INDEX_QUERY_SCANONETERM) ){
246936 || pIter->pLeaf==0 /* 2 */
246937 || fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)==0 /* 3 */
246938 || (bGe && fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)>0) /* 4 */
246947 if( p->pIdxNextSelect==0 ){
246971 int bDlidx = 0;
246972 sqlite3_stmt *pSel = 0; /* SELECT to find iPg */
246981 i64 val = sqlite3_column_int64(pSel, 0);
246983 bDlidx = (val & 0x0001);
246990 memset(pIter, 0, sizeof(*pIter));
246993 if( iPg>=0 ){
247000 int iTermOff = 0;
247005 fts5SegIterLoadTerm(p, pIter, 0);
247010 fts5BufferCompareBlob(&pIter->term, (const u8*)pTerm, nTerm)>0
247029 int nList = 0;
247030 const u8 *z = 0;
247031 int n = 0;
247032 Fts5Data *pLeaf = 0;
247037 if( pTerm==0 || (flags & FTS5INDEX_QUERY_SCAN) ){
247038 const u8 *pList = 0;
247055 p->bDelete = 0;
247093 for(ii=0; ii<n; ii++){
247102 ** reaches 0, free it and its contents.
247107 if( p->nRef<=0 ){
247109 for(ii=0; ii<p->nTombstone; ii++){
247127 memset(pIter, 0, sizeof(Fts5SegIter));
247148 if( p1->pLeaf==0 ){
247150 }else if( p2->pLeaf==0 ){
247155 if( res==0 ) res = p1->term.n - p2->term.n;
247157 if( res==0 ){
247162 assert( pRes->bTermEq==0 );
247165 if( res<0 ){
247185 assert( (pFirst->pLeaf==0)==pIter->base.bEof );
247188 for(i=0; i<pIter->nSeg; i++){
247191 || p1->pLeaf==0
247198 for(i=0; i<pIter->nSeg; i+=2){
247233 assert( iOut<pIter->nSeg && iOut>0 );
247234 assert( pIter->bRev==0 || pIter->bRev==1 );
247246 pRes->bTermEq = 0;
247247 if( p1->pLeaf==0 ){ /* If p1 is at EOF */
247249 }else if( p2->pLeaf==0 ){ /* If p2 is at EOF */
247253 if( res==0 ){
247255 assert_nc( i2!=0 );
247262 assert( res!=0 );
247263 if( res<0 ){
247271 return 0;
247290 pIter->pNextLeaf = 0;
247296 if( pIter->pLeaf==0 ) break;
247298 if( iOff>0 ){
247333 if( bRev==0 ){
247341 bMove = 0;
247344 assert( pIter->pNextLeaf==0 );
247356 bMove = 0;
247361 if( bMove && p->rc==SQLITE_OK ) pIter->xNext(p, pIter, 0);
247362 if( pIter->pLeaf==0 ) break;
247363 if( bRev==0 && pIter->iRowid>=iMatch ) break;
247364 if( bRev!=0 && pIter->iRowid<=iMatch ) break;
247375 for(i=0; i<pIter->nSeg; i++){
247395 pSeg->xNext(p, pSeg, 0);
247405 ** If it does so successfully, 0 is returned. Otherwise 1.
247422 Fts5SegIter *pOther = &pIter->aSeg[iChanged ^ 0x0001];
247428 assert( pRes->bTermEq==0 || pOther->pLeaf );
247443 pOther = &pIter->aSeg[ pIter->aFirst[i ^ 0x0001].iFirst ];
247448 return 0;
247456 pIter->base.bEof = pSeg->pLeaf==0;
247464 #define TOMBSTONE_KEYSIZE(pPg) (pPg->p[0]==4 ? 4 : 8)
247484 if( iRowid==0 ){
247490 if( nCollide--==0 ) break;
247497 if( nCollide--==0 ) break;
247502 return 0;
247518 assert( iPg>=0 );
247522 if( pArray->apTombstone[iPg]==0 ){
247526 if( pArray->apTombstone[iPg]==0 ) return 0;
247536 return 0;
247553 assert( pIter->base.bEof==0 );
247556 int bNewTerm = 0;
247565 if( pSeg->pLeaf==0 || bNewTerm
247571 if( pSeg->pLeaf==0 ) return;
247576 if( (pIter->bSkipEmpty==0 || pSeg->nPos)
247577 && 0==fts5MultiIterIsDeleted(pIter)
247582 bUseFrom = 0;
247593 *pbNewTerm = 0;
247597 int bNewTerm = 0;
247601 if( pSeg->pLeaf==0 || bNewTerm
247647 assert_nc( nChunk>=0 );
247648 if( nChunk>0 ){
247673 for(i=0; i<pColset->nCol; i++){
247676 return 0;
247686 assert_nc( nChunk>=0 );
247687 if( nChunk>0 ){
247688 int i = 0;
247709 assert_nc( nChunk>=0 );
247710 if( nChunk>0 ){
247713 int i = 0;
247714 int iStart = 0;
247723 pCtx->eState = 0;
247728 while( i<nChunk && pChunk[i]!=0x01 ){
247729 while( pChunk[i] & 0x80 ) i++;
247761 Fts5Data *pData = 0;
247765 int pgnoSave = 0;
247770 if( (pSeg->flags & FTS5_SEGITER_REVERSE)==0 ){
247778 if( nRem<=0 ){
247780 }else if( pSeg->pSeg==0 ){
247786 if( pData==0 ) break;
247790 assert( pSeg->pNextLeaf==0 );
247792 pData = 0;
247810 assert( pBuf!=0 );
247811 assert( pSeg!=0 );
247812 if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+FTS5_DATA_ZERO_PADDING) ){
247813 assert( pBuf->p!=0 );
247815 memset(&pBuf->p[pBuf->n+pSeg->nPos], 0, FTS5_DATA_ZERO_PADDING);
247816 if( pColset==0 ){
247823 sCtx.eState = fts5IndexColsetTest(pColset, 0);
247824 assert( sCtx.eState==0 || sCtx.eState==1 );
247828 memset(&sCtx, 0, sizeof(sCtx));
247859 int i = 0;
247860 int iCurrent = 0;
247876 /* Advance pointer p until it points to pEnd or an 0x01 byte that is
247878 while( p<pEnd && *p!=0x01 ){
247879 while( *p++ & 0x80 );
247897 if( iCurrent & 0x80 ){
247924 assert( pIter->pColset==0 );
247935 fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist);
247941 ** xSetOutputs callback used when the Fts5Colset object has nCol==0 (match
247946 pIter->base.nData = 0;
247982 int iPrev = 0;
247987 int iPrevOut = 0;
247992 iPrev += (int)a++[0] - 2;
248038 assert( pIter!=0 || (*pRc)!=SQLITE_OK );
248045 else if( pIter->pColset==0 ){
248049 else if( pIter->pColset->nCol==0 ){
248075 for(iIter=pIter->nSeg-1; iIter>0; iIter--){
248079 if( p->rc==SQLITE_OK ) pSeg->xNext(p, pSeg, 0);
248089 fts5MultiIterNext(p, pIter, 0, 0);
248090 }else if( pIter->base.bEof==0 ){
248112 const u8 *pTerm, int nTerm, /* Term to seek to (or NULL/0) */
248114 int nSegment, /* Number of segments to merge (iLevel>=0) */
248117 int nSeg = 0; /* Number of segment-iters in use */
248118 int iIter = 0; /* */
248123 assert( (pTerm==0 && nTerm==0) || iLevel<0 );
248127 if( iLevel<0 ){
248130 nSeg += (p->pHash && 0==(flags & FTS5INDEX_QUERY_SKIPHASH));
248136 if( pNew==0 ){
248140 pNew->bRev = (0!=(flags & FTS5INDEX_QUERY_DESC));
248141 pNew->bSkipEmpty = (0!=(flags & FTS5INDEX_QUERY_SKIPEMPTY));
248143 if( (flags & FTS5INDEX_QUERY_NOOUTPUT)==0 ){
248149 if( iLevel<0 ){
248151 if( p->pHash && 0==(flags & FTS5INDEX_QUERY_SKIPHASH) ){
248156 for(pLvl=&pStruct->aLevel[0]; pLvl<pEnd; pLvl++){
248157 for(iSeg=pLvl->nSeg-1; iSeg>=0; iSeg--){
248160 if( pTerm==0 ){
248169 for(iSeg=nSeg-1; iSeg>=0; iSeg--){
248184 *ppOut = 0;
248188 assert( (*ppOut)!=0 || p->rc!=SQLITE_OK );
248207 if( pData->szLeaf>0 ){
248219 pData = 0;
248236 assert( pIter!=0 || p->rc!=SQLITE_OK );
248238 || (pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf==0)==pIter->base.bEof
248266 if( pIter->bRev==0 && iRowid>=iMatch ) break;
248267 if( pIter->bRev!=0 && iRowid<=iMatch ) break;
248287 ** If an error has already occurred, this function is a no-op. 0 is
248291 int iSegid = 0;
248303 memset(aUsed, 0, sizeof(aUsed));
248304 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
248305 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
248307 if( iId<=FTS5_MAX_SEGMENT && iId>0 ){
248313 for(i=0; aUsed[i]==0xFFFFFFFF; i++);
248315 for(iSegid=0; mask & ((u32)1 << iSegid); iSegid++);
248319 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
248320 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
248324 assert_nc( iSegid>0 && iSegid<=FTS5_MAX_SEGMENT );
248329 u8 aBlob[2] = {0xff, 0xff};
248348 assert( p->pHash || p->nPendingData==0 );
248351 p->nPendingData = 0;
248352 p->nPendingRow = 0;
248355 p->nContentlessDelete = 0;
248367 for(i=0; i<nOld; i++){
248379 assert( bFlush==0 || (pWriter->nDlidx>0 && pWriter->aDlidx[0].buf.n>0) );
248380 for(i=0; i<pWriter->nDlidx; i++){
248382 if( pDlidx->buf.n==0 ) break;
248384 assert( pDlidx->pgno!=0 );
248391 pDlidx->bPrevValid = 0;
248408 if( aDlidx==0 ){
248412 memset(&aDlidx[pWriter->nDlidx], 0, nByte);
248426 int bFlag = 0;
248430 if( pWriter->aDlidx[0].buf.n>0 && pWriter->nEmpty>=FTS5_MIN_DLIDX_SIZE ){
248434 pWriter->nEmpty = 0;
248452 assert( pWriter->iBtPage || pWriter->nEmpty==0 );
248453 if( pWriter->iBtPage==0 ) return;
248457 const char *z = (pWriter->btterm.n>0?(const char*)pWriter->btterm.p:"");
248466 pWriter->iBtPage = 0;
248499 ** has already been started, append an 0x00 byte to it. */
248500 if( pWriter->bFirstRowidInPage && pWriter->aDlidx[0].buf.n>0 ){
248501 Fts5DlidxWriter *pDlidx = &pWriter->aDlidx[0];
248503 sqlite3Fts5BufferAppendVarint(&p->rc, &pDlidx->buf, 0);
248530 int bDone = 0;
248532 for(i=0; p->rc==SQLITE_OK && bDone==0; i++){
248542 pDlidx->buf.p[0] = 0x01; /* Not the root node */
248549 if( p->rc==SQLITE_OK && pDlidx[1].buf.n==0 ){
248554 sqlite3Fts5BufferAppendVarint(&p->rc, &pDlidx[1].buf, 0);
248562 pDlidx->bPrevValid = 0;
248571 i64 iPgno = (i==0 ? pWriter->writer.pgno : pDlidx[-1].pgno);
248572 assert( pDlidx->buf.n==0 );
248585 static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
248589 assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
248592 assert( 0==fts5GetU16(&pPage->buf.p[2]) );
248597 assert( pPage->pgidx.n==0 );
248612 pPage->iPrevPgidx = 0;
248658 #if 0
248664 nPrefix = 0;
248699 pWriter->bFirstTermInPage = 0;
248701 pWriter->bFirstRowidInPage = 0;
248704 assert( p->rc || (pWriter->nDlidx>0 && pWriter->aDlidx[0].buf.n==0) );
248705 pWriter->aDlidx[0].pgno = pPage->pgno;
248741 pWriter->bFirstRowidInDoclist = 0;
248742 pWriter->bFirstRowidInPage = 0;
248756 assert( p->pConfig->pgsz>0 || p->rc!=SQLITE_OK );
248761 int nCopy = 0;
248771 if( n>0 ){
248802 for(i=0; i<pWriter->nDlidx; i++){
248815 memset(pWriter, 0, sizeof(Fts5SegWriter));
248823 assert( pWriter->writer.buf.n==0 );
248824 assert( pWriter->writer.pgidx.n==0 );
248830 if( p->pIdxWriter==0 ){
248839 /* Initialize the 4-byte leaf-page header to 0x00. */
248840 memset(pWriter->writer.buf.p, 0, 4);
248858 memset(&buf, 0, sizeof(Fts5Buffer));
248859 for(i=0; i<pIter->nSeg && p->rc==SQLITE_OK; i++){
248861 if( pSeg->pSeg==0 ){
248863 }else if( pSeg->pLeaf==0 ){
248865 ** Set both the first and last page-numbers to 0 to indicate that the
248867 pSeg->pSeg->pgnoLast = 0;
248868 pSeg->pSeg->pgnoFirst = 0;
248874 u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
248942 Fts5Iter *pIter = 0; /* Iterator to read input data */
248943 int nRem = pnRem ? *pnRem : 0; /* Output leaf pages left to write */
248951 int bTermWritten = 0; /* True if current term already output */
248956 memset(&writer, 0, sizeof(Fts5SegWriter));
248957 memset(&term, 0, sizeof(Fts5Buffer));
248960 assert( pLvlOut->nSeg>0 );
248966 writer.iBtPage = 0;
248976 fts5StructureExtendLevel(&p->rc, pStruct, iLvl+1, 1, 0);
248994 if( pStruct->nOriginCntr>0 ){
248995 pSeg->iOrigin1 = pLvl->aSeg[0].iOrigin1;
249001 assert( iLvl>=0 );
249002 for(fts5MultiIterNew(p, pStruct, flags, 0, 0, 0, iLvl, nInput, &pIter);
249003 fts5MultiIterEof(p, pIter)==0;
249004 fts5MultiIterNext(p, pIter, 0, 0)
249017 bTermWritten =0;
249021 if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue;
249023 if( p->rc==SQLITE_OK && bTermWritten==0 ){
249035 fts5BufferAppendVarint(&p->rc, &writer.writer.buf, 0);
249036 if( pSegIter->nPos>0 ){
249037 fts5BufferAppendVarint(&p->rc, &writer.writer.buf, 0);
249052 assert( pIter!=0 || p->rc!=SQLITE_OK );
249057 assert( pSeg->nEntry==0 );
249058 for(i=0; i<nInput; i++){
249071 pLvl->nMerge = 0;
249072 if( pSeg->pgnoLast==0 ){
249077 assert( pSeg->pgnoLast>0 );
249089 ** configuration option is set to 0, then this function always returns -1.
249098 if( pConfig->bContentlessDelete && pConfig->nDeleteMerge>0 ){
249100 int nBest = 0;
249102 for(ii=0; ii<pStruct->nLevel; ii++){
249104 i64 nEntry = 0;
249105 i64 nTomb = 0;
249107 for(iSeg=0; iSeg<pLvl->nSeg; iSeg++){
249111 assert_nc( nEntry>0 || pLvl->nSeg==0 );
249112 if( nEntry>0 ){
249141 int bRet = 0;
249143 while( nRem>0 && p->rc==SQLITE_OK ){
249145 int iBestLvl = 0; /* Level offering the most input segments */
249146 int nBest = 0; /* Number of input segments on best level */
249150 assert( pStruct->nLevel>0 );
249151 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
249169 if( iBestLvl<0 ) break;
249172 if( p->rc==SQLITE_OK && pStruct->aLevel[iBestLvl].nMerge==0 ){
249183 ** A total of nLeaf leaf pages of data has just been flushed to a level-0
249195 if( p->rc==SQLITE_OK && p->pConfig->nAutomerge>0 && ALWAYS((*ppStruct)!=0) ){
249217 if( pStruct && pStruct->nLevel>0 ){
249218 int iLvl = 0;
249220 fts5IndexMergeLevel(p, &pStruct, iLvl, 0);
249286 if( p->pDeleteFromIdx==0 ){
249319 Fts5Data *pLeaf = 0;
249325 int iNext = 0;
249326 u8 *aPg = 0;
249329 if( pLeaf==0 ) break;
249332 iNext = fts5GetU16(&aPg[0]);
249333 if( iNext!=0 ){
249334 *pbLastInDoclist = 0;
249336 if( iNext==0 && pLeaf->szLeaf!=pLeaf->nn ){
249340 if( iNext==0 ){
249343 const u8 aEmpty[] = {0x00, 0x00, 0x00, 0x04};
249344 assert_nc( bDetailNone==0 || pLeaf->nn==4 );
249345 if( bDetailNone==0 ) fts5DataWrite(p, iRowid, aEmpty, sizeof(aEmpty));
249347 pLeaf = 0;
249357 int nIdx = 0;
249358 u8 *aIdx = 0;
249360 /* Unless the current page footer is 0 bytes in size (in which case
249365 int iFirst = 0;
249367 int i2 = 0;
249375 if( aIdx==0 ) break;
249389 if( fts5GetU16(&aPg[0]) ) fts5PutU16(&aPg[0], 4);
249390 if( nIdx>0 ){
249397 assert( nPg>4 || fts5GetU16(aPg)==0 );
249419 u64 iDelta = 0;
249420 int iNextOff = 0;
249421 int iOff = 0;
249422 int nIdx = 0;
249423 u8 *aIdx = 0;
249424 int bLastInDoclist = 0;
249425 int iIdx = 0;
249426 int iStart = 0;
249427 int iDelKeyOff = 0; /* Offset of deleted key, if any */
249469 iStart = fts5GetU16(&aPg[0]);
249477 if( aPg[iSOP]==0x00 ) iSOP++;
249478 if( aPg[iSOP]==0x00 ) iSOP++;
249484 if( iNextOff<pSeg->iEndofDoclist && aPg[iNextOff]==0x00 ) iNextOff++;
249485 if( iNextOff<pSeg->iEndofDoclist && aPg[iNextOff]==0x00 ) iNextOff++;
249488 int nPos = 0;
249514 if( pSeg->bDel==0 ){
249520 int iKeyOff = 0;
249521 for(iIdx=0; iIdx<nIdx; /* no-op */){
249522 u32 iVal = 0;
249533 ** of the header to 0. */
249534 if( fts5GetU16(&aPg[0])==iStart && (bLastInDoclist || iNextOff==iPgIdx) ){
249535 fts5PutU16(&aPg[0], 0);
249541 aPg[iOff++] = 0x01;
249542 }else if( bLastInDoclist==0 ){
249544 u64 iNextDelta = 0;
249554 int iKey = 0;
249555 int iKeyOff = 0;
249559 for(iIdx=0; iIdx<nIdx; iKey++){
249560 u32 iVal = 0;
249576 int nPrefix = 0;
249577 int nSuffix = 0;
249578 int nPrefix2 = 0;
249579 int nSuffix2 = 0;
249621 if( bEmpty==0 ) break;
249630 int iTermIdx = 0;
249631 int iTermOff = 0;
249634 u32 iVal = 0;
249646 if( nTermIdx==0 ){
249667 int iPrevKeyOut = 0;
249668 int iKeyIn = 0;
249675 for(iIdx=0; iIdx<nIdx; /* no-op */){
249676 u32 iVal = 0;
249680 int iKeyOut = (iKeyIn - (iKeyIn>iOff ? nShift : 0));
249686 if( iPgIdx==nPg && nIdx>0 && pSeg->iLeafPgno!=1 ){
249690 assert_nc( nPg>4 || fts5GetU16(aPg)==0 );
249712 Fts5Iter *pIter = 0; /* Used to find term instance */
249717 sqlite3_stmt *pStmt = 0;
249732 fts5MultiIterNew(p, pStruct, f, 0, (const u8*)zTerm, nTerm, -1, 0, &pIter);
249733 if( fts5MultiIterEof(p, pIter)==0 ){
249740 && fts5MultiIterEof(p, pIter)==0
249754 ** Flush the contents of in-memory hash table iHash to a new level-0
249764 int pgnoLast = 0; /* Last leaf page number in segment */
249767 ** for the new level-0 segment. */
249771 if( sqlite3Fts5HashIsEmpty(pHash)==0 ){
249795 p->rc = sqlite3Fts5HashScanInit(pHash, 0, 0);
249797 while( p->rc==SQLITE_OK && 0==sqlite3Fts5HashScanEof(pHash) ){
249805 if( bSecureDelete==0 ){
249808 assert( writer.bFirstRowidInPage==0 );
249816 i64 iRowid = 0;
249817 i64 iPrev = 0;
249818 int iOff = 0;
249824 u64 iDelta = 0;
249833 if( iOff<nDoclist && pDoclist[iOff]==0x00
249837 if( iOff<nDoclist && pDoclist[iOff]==0x00 ){
249839 nDoclist = 0;
249844 }else if( (pDoclist[iOff] & 0x01)
249847 if( p->rc!=SQLITE_OK || pDoclist[iOff]==0x01 ){
249854 if( p->rc==SQLITE_OK && bTermWritten==0 ){
249857 assert( p->rc!=SQLITE_OK || writer.bFirstRowidInPage==0 );
249861 fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
249863 writer.bFirstRowidInPage = 0;
249874 if( iOff<nDoclist && pDoclist[iOff]==0 ){
249875 pBuf->p[pBuf->n++] = 0;
249877 if( iOff<nDoclist && pDoclist[iOff]==0 ){
249878 pBuf->p[pBuf->n++] = 0;
249886 int bDel = 0;
249887 int nPos = 0;
249905 int iPos = 0;
249908 int n = 0;
249914 assert( n>0 );
249929 /* pBuf->p[pBuf->n++] = '\0'; */
249935 assert( p->rc!=SQLITE_OK || bSecureDelete || pgnoLast>0 );
249936 if( pgnoLast>0 ){
249939 if( pStruct->nLevel==0 ){
249942 fts5StructureExtendLevel(&p->rc, pStruct, 0, 1, 0);
249944 pSeg = &pStruct->aLevel[0].aSeg[ pStruct->aLevel[0].nSeg++ ];
249948 if( pStruct->nOriginCntr>0 ){
249956 fts5StructurePromote(p, 0, pStruct);
249981 p->nPendingData = 0;
249982 p->nPendingRow = 0;
249983 p->nContentlessDelete = 0;
249994 Fts5Structure *pNew = 0;
250010 if( nSeg==0 ) return 0;
250011 for(i=0; i<pStruct->nLevel; i++){
250014 if( nThis>0 && (nThis==nSeg || (nThis==nSeg-1 && nMerge==nThis)) ){
250015 if( nSeg==1 && nThis==1 && pStruct->aLevel[i].aSeg[0].nPgTombstone==0 ){
250016 return 0;
250039 int iSegOut = 0;
250041 ** the new Fts5Level object so that pLvl->aSeg[0] is the oldest
250043 for(iLvl=pStruct->nLevel-1; iLvl>=0; iLvl--){
250044 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
250052 pNew = 0;
250061 Fts5Structure *pNew = 0;
250065 assert( p->rc!=SQLITE_OK || p->nContentlessDelete==0 );
250067 assert( p->rc!=SQLITE_OK || pStruct!=0 );
250075 assert( pNew==0 || pNew->nSegment>0 );
250078 for(iLvl=0; pNew->aLevel[iLvl].nSeg==0; iLvl++){}
250079 while( p->rc==SQLITE_OK && pNew->aLevel[iLvl].nSeg>0 ){
250096 Fts5Structure *pStruct = 0;
250103 if( nMerge<0 ){
250138 assert( nData>0 );
250139 if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nByte) ){
250143 memset(&pBuf->p[pBuf->n], 0, FTS5_DATA_ZERO_PADDING);
250151 assert( pIter->aPoslist || (p==0 && pIter->aPoslist==0) );
250153 pIter->aPoslist = 0;
250161 if( p[0] & 0x80 ){
250166 pIter->nPoslist = ((int)(p[0])) >> 1;
250172 pIter->aPoslist = 0;
250181 memset(pIter, 0, sizeof(*pIter));
250182 if( pBuf->n>0 ){
250189 #if 0
250201 assert( pBuf->n!=0 || (*piLastRowid)==0 );
250208 assert( (pBuf)->n!=0 || (iLastRowid)==0 ); \
250243 int i1 = 0;
250244 int i2 = 0;
250245 i64 iRowid1 = 0;
250246 i64 iRowid2 = 0;
250247 i64 iOut = 0;
250248 Fts5Buffer *p2 = &aBuf[0];
250252 memset(&out, 0, sizeof(out));
250259 while( i1>=0 || i2>=0 ){
250260 if( i1>=0 && (i2<0 || iRowid1<iRowid2) ){
250261 assert( iOut==0 || iRowid1>iOut );
250266 assert( iOut==0 || iRowid2>iOut );
250269 if( i1>=0 && iRowid1==iRowid2 ){
250307 if( p->iPos>=0 ){
250332 PrefixMerger *pHead = 0;
250334 int nOut = 0;
250335 Fts5Buffer out = {0, 0, 0};
250336 Fts5Buffer tmp = {0, 0, 0};
250337 i64 iLastRowid = 0;
250342 assert( nBuf+1<=(int)(sizeof(aMerger)/sizeof(aMerger[0])) );
250343 memset(aMerger, 0, sizeof(PrefixMerger)*(nBuf+1));
250346 for(i=0; i<nBuf; i++){
250351 if( nOut==0 ) return;
250373 i64 iPrev = 0;
250375 int nMerge = 0;
250377 PrefixMerger *pThis = 0;
250378 int nTail = 0;
250380 pHead = 0;
250383 pSave->iOff = 0;
250384 pSave->iPos = 0;
250393 if( pHead==0 || pHead->pNext==0 ){
250436 if( nTail>0 ){
250441 for(i=0; i<nBuf+1; i++){
250462 memset(&out.p[out.n], 0, FTS5_DATA_ZERO_PADDING);
250491 ** are passed 0.
250505 const int flags = (bPrefix ? FTS5INDEX_QUERY_SCAN : 0)
250508 Fts5Iter *p1 = 0; /* Iterator used to gather data from index */
250512 fts5MultiIterNew(p, pStruct, flags, pColset, pToken, nToken, -1, 0, &p1);
250515 fts5MultiIterEof(p, p1)==0;
250519 int nNew = 0;
250520 const u8 *pNew = 0;
250560 ** actually an iterator (i.e. with nIter>0, not just a container for
250566 ** (nIter==0), then iIter is an index into the term.p[] buffer where
250578 int nByte; /* Length of token in bytes (or 0) */
250622 int i1 = 0;
250623 int i2 = 0;
250625 assert( n1>=0 && n2>=0 );
250660 if( aNew==0 ){
250684 Fts5TokenDataMap *aTmp = 0;
250695 for(i1=0; i1<pT->nMap; i1+=(nHalf*2)){
250729 for(ii=0; ii<pSet->nIter; ii++){
250765 int iPosOff = 0;
250766 i64 iPos = 0;
250774 while( 0==sqlite3Fts5PoslistNext64(
250812 if( p1->base.nData>0 ){
250813 if( p1->base.iRowid<=pSetup->iLastRowid && pSetup->doclist.n>0 ){
250815 for(i=0; p->rc==SQLITE_OK && pSetup->doclist.n; i++){
250820 if( pSetup->aBuf[iStore].n==0 ){
250833 pSetup->iLastRowid = 0;
250860 memset(&s, 0, sizeof(s));
250861 memset(&s2, 0, sizeof(s2));
250864 s.iLastRowid = 0;
250866 if( iIdx==0
250898 if( iIdx!=0 ){
250899 pToken[0] = FTS5_MAIN_PREFIX;
250900 fts5VisitEntries(p, pColset, pToken, nToken, 0, prefixIterSetupCb, pCtx);
250903 pToken[0] = FTS5_MAIN_PREFIX + iIdx;
250906 assert( (s.nBuf%s.nMerge)==0 );
250907 for(i=0; i<s.nBuf; i+=s.nMerge){
250919 assert( pData!=0 || p->rc!=SQLITE_OK );
250927 assert( (*ppIter)!=0 || p->rc!=SQLITE_OK );
250931 s2.pT = 0;
250950 if( p->pHash==0 ){
250956 || (iRowid==p->iWriteRowid && p->bDelete==0)
250964 if( bDelete==0 ){
251004 memset(pTmp, 0, SZ_FTS5STRUCTURE(1));
251008 fts5DataWrite(p, FTS5_AVERAGES_ROWID, (const u8*)"", 0);
251036 pConfig, "data", "id INTEGER PRIMARY KEY, block BLOB", 0, pzErr
251053 *pp = 0;
251064 assert( p->pReader==0 );
251084 ** buffer, or 0 if there are less than nChar characters in total.
251091 int n = 0;
251093 for(i=0; i<nChar; i++){
251094 if( n>=nByte ) return 0; /* Input contains fewer than nChar chars */
251095 if( (unsigned char)p[n++]>=0xc0 ){
251096 if( n>=nByte ) return 0;
251097 while( (p[n] & 0xc0)==0x80 ){
251101 return 0;
251114 int nChar = 0;
251115 int i = 0;
251117 if( (unsigned char)pIn[i++]>=0xc0 ){
251118 while( i<nIn && (pIn[i] & 0xc0)==0x80 ) i++;
251146 assert( (iCol<0)==p->bDelete );
251153 for(i=0; i<pConfig->nPrefix && rc==SQLITE_OK; i++){
251180 && 0==memcmp(pBuf->p, pToken, nToken)
251181 && (pBuf->n==nToken || pBuf->p[nToken]==0x00)
251190 pSeg->pLeaf = 0;
251215 if( pIn==0 || pIn->nIter==pIn->nIterAlloc ){
251220 if( pNew==0 ){
251223 if( pIn==0 ) memset(pNew, 0, nByte);
251234 assert( pRet==0 || pRet->nIter<=pRet->nIterAlloc );
251241 ** (pIter->pTokenDataIter!=0). This function sets the iterator output
251247 int nHit = 0;
251249 int iMin = 0;
251253 pIter->base.nData = 0;
251254 pIter->base.pData = 0;
251256 for(ii=0; ii<pT->nIter; ii++){
251258 if( p->base.bEof==0 ){
251259 if( nHit==0 || p->base.iRowid<iRowid ){
251271 if( nHit==0 ){
251275 pIter->base.bEof = 0;
251279 fts5TokendataIterAppendMap(pIter->pIndex, pT, iMin, 0, iRowid, -1);
251282 int nReader = 0;
251283 int nByte = 0;
251284 i64 iPrev = 0;
251287 if( pT->aPoslistReader==0 ){
251292 if( pT->aPoslistReader==0 ) return;
251297 for(ii=0; ii<pT->nIter; ii++){
251319 if( aNew==0 ){
251327 pIter->poslist.n = 0;
251333 iMin = 0;
251334 for(ii=0; ii<nReader; ii++){
251336 if( pReader->bEof==0 ){
251366 ** (pIter->pTokenDataIter!=0). This function advances the iterator. If
251376 for(ii=0; ii<pT->nIter; ii++){
251378 if( p->base.bEof==0
251382 while( bFrom && p->base.bEof==0
251386 fts5MultiIterNext(pIndex, p, 0, 0);
251401 if( pIter && pIter->aSeg[0].pLeaf==0 ){
251402 fts5BufferSet(&pIter->pIndex->rc, &pIter->aSeg[0].term, pTerm->n, pTerm->p);
251416 Fts5Iter *pRet = 0;
251417 Fts5TokenDataIter *pSet = 0;
251418 Fts5Structure *pStruct = 0;
251421 Fts5Buffer bSeek = {0, 0, 0};
251422 Fts5Buffer *pSmall = 0;
251428 Fts5Iter *pPrev = pSet ? pSet->apIter[pSet->nIter-1] : 0;
251429 Fts5Iter *pNew = 0;
251430 Fts5SegIter *pNewIter = 0;
251431 Fts5SegIter *pPrevIter = 0;
251438 fts5BufferAppendBlob(&p->rc, &bSeek, 1, (const u8*)"\0");
251447 pNewIter = &pNew->aSeg[0];
251448 pPrevIter = (pPrev ? &pPrev->aSeg[0] : 0);
251449 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
251450 for(iSeg=pStruct->aLevel[iLvl].nSeg-1; iSeg>=0; iSeg--){
251452 int bDone = 0;
251457 memset(pPrevIter, 0, sizeof(Fts5SegIter));
251465 if( bDone==0 ){
251493 pSmall = 0;
251494 for(ii=0; ii<pNew->nSeg; ii++){
251496 if( 0==fts5IsTokendataPrefix(&pII->term, pToken, nToken) ){
251499 if( pII->pLeaf && (!pSmall || fts5BufferCompare(pSmall, &pII->term)>0) ){
251507 if( pSmall==0 ){
251518 for(ii=0; ii<pSet->nIter; ii++){
251521 for(iSeg=0; iSeg<pIter->nSeg; iSeg++){
251529 pRet = fts5MultiIterAlloc(p, 0);
251532 pRet->nSeg = 0;
251560 Fts5Iter *pRet = 0;
251561 Fts5Buffer buf = {0, 0, 0};
251564 assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
251566 if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
251567 int iIdx = 0; /* Index to search */
251568 int iPrefixIdx = 0; /* +1 prefix index */
251570 assert( buf.p!=0 );
251571 if( nToken>0 ) memcpy(&buf.p[1], pToken, nToken);
251579 bTokendata = 0;
251593 if( pConfig->bPrefixIndex==0 || (flags & FTS5INDEX_QUERY_TEST_NOIDX) ){
251607 if( bTokendata && iIdx==0 ){
251608 buf.p[0] = FTS5_MAIN_PREFIX;
251613 buf.p[0] = (u8)(FTS5_MAIN_PREFIX + iIdx);
251616 pColset, buf.p, nToken+1, -1, 0, &pRet
251622 int bDesc = (flags & FTS5INDEX_QUERY_DESC)!=0;
251624 if( pRet==0 ){
251627 assert( pRet->pColset==0 );
251638 pRet = 0;
251657 if( pIter->nSeg==0 ){
251659 fts5TokendataIterNext(pIter, 0, 0);
251661 fts5MultiIterNext(pIter->pIndex, pIter, 0, 0);
251675 fts5MultiIterNext(p, pIter, 0, 0);
251678 if( pSeg->pLeaf && pSeg->term.p[0]!=FTS5_MAIN_PREFIX ){
251680 pSeg->pLeaf = 0;
251695 if( pIter->nSeg==0 ){
251712 return (z ? &z[1] : 0);
251726 Fts5Buffer token = {0, 0, 0};
251729 memset(&ctx, 0, sizeof(ctx));
251732 assert( token.p!=0 || p->rc!=SQLITE_OK );
251739 token.p[0] = FTS5_MAIN_PREFIX;
251744 p, 0, token.p, token.n, 1, prefixIterSetupTokendataCb, (void*)&ctx
251764 ** iterator (pIter->pTokenDataIter!=0).
251779 Fts5TokenDataMap *aMap = 0;
251780 int i1 = 0;
251781 int i2 = 0;
251782 int iTest = 0;
251784 assert( pT || (pToken && pIter->nSeg>0) );
251785 if( pT==0 ){
251803 if( aMap[iTest].iPos<0 ){
251816 if( pIter->nSeg==0 ){
251818 *ppOut = (const char*)pMap->aSeg[0].term.p+1;
251819 *pnOut = pMap->aSeg[0].term.n-1;
251837 && (pIter->nSeg==0 || pIter->pIndex->pConfig->eDetail!=FTS5_DETAIL_FULL)
251839 pIter->pTokenDataIter->nMap = 0;
251861 assert( pIter->pTokenDataIter || pIter->nSeg>0 );
251862 if( pIter->nSeg>0 ){
251864 if( pT==0 ){
251875 for(ii=0; ii<pT->nIter; ii++){
251876 Fts5Buffer *pTerm = &pT->apIter[ii]->aSeg[0].term;
251877 if( nToken==pTerm->n-1 && memcmp(pToken, pTerm->p+1, nToken)==0 ) break;
251880 fts5TokendataIterAppendMap(p, pT, ii, 0, iRowid, iPos);
251907 *pnRow = 0;
251908 memset(anSize, 0, sizeof(i64) * nCol);
251911 int i = 0;
251914 for(iCol=0; i<pData->nn && iCol<nCol; iCol++){
251952 sqlite3_blob *pBlob = 0;
251961 sqlite3_blob_write(pBlob, aCookie, 4, 0);
252015 if( szKey==4 && iRowid>0xFFFFFFFF ) return 2;
252016 if( iRowid==0 ){
252017 pPg->p[1] = 0x01;
252018 return 0;
252021 if( bForce==0 && nElem>=(nSlot/2) ){
252030 if( nCollide--==0 ) return 0;
252037 if( nCollide--==0 ) return 0;
252042 return 0;
252051 ** Return 0 if the hash is successfully rebuilt into the nOut pages.
252067 int res = 0;
252070 for(ii=0; ii<nOut; ii++){
252071 apOut[ii]->p[0] = szKey;
252072 fts5PutU32(&apOut[ii]->p[4], 0);
252076 for(ii=0; res==0 && ii<pSeg->nPgTombstone; ii++){
252077 Fts5Data *pData = 0; /* Page ii of the current hash table */
252078 Fts5Data *pFree = 0; /* Free this at the end of the loop */
252090 for(iIn=0; iIn<nSlotIn; iIn++){
252091 u64 iVal = 0;
252102 /* If iVal is not 0 at this point, insert it into the new hash table */
252105 res = fts5IndexTombstoneAddToPage(pPg, 0, nOut, iVal);
252110 /* If this is page 0 of the old hash, copy the rowid-0-flag from the
252112 if( ii==0 ){
252113 apOut[0]->p[1] = pData->p[1];
252134 ** both output parameters set to 0 before returning.
252147 int nSlot = 0; /* Number of slots in each output page */
252148 int nOut = 0;
252167 if( pSeg->nPgTombstone==0 ){
252174 assert( pData1 && iPg1==0 );
252177 if( nSlot>nSlotPerPage ) nOut = 0;
252179 if( nOut==0 ){
252187 int res = 0;
252188 int ii = 0;
252189 int szPage = 0;
252190 Fts5Data **apOut = 0;
252196 for(ii=0; ii<nOut; ii++){
252211 if( res==0 ){
252214 apOut = 0;
252215 nOut = 0;
252240 Fts5Data *pPg = 0;
252242 int szKey = 0;
252243 int nHash = 0;
252244 Fts5Data **apHash = 0;
252248 if( pSeg->nPgTombstone>0 ){
252251 if( pPg==0 ){
252256 if( 0==fts5IndexTombstoneAddToPage(pPg, 0, pSeg->nPgTombstone, iRowid) ){
252265 if( iRowid>0xFFFFFFFF ) szKey = 8;
252269 assert( p->rc==SQLITE_OK || (nHash==0 && apHash==0) );
252274 int ii = 0;
252276 for(ii=0; ii<nHash; ii++){
252297 int bFound = 0; /* True after pSeg->nEntryTombstone incr. */
252299 for(iLvl=pStruct->nLevel-1; iLvl>=0; iLvl--){
252301 for(iSeg=pStruct->aLevel[iLvl].nSeg-1; iSeg>=0; iSeg--){
252304 if( bFound==0 ){
252338 if( iIdx>=0 ) ret += (ret<<3) + (FTS5_MAIN_PREFIX + iIdx);
252339 for(i=0; i<nTerm; i++) ret += (ret<<3) + pTerm[i];
252357 Fts5DlidxIter *pDlidx = 0;
252361 for(pDlidx=fts5DlidxIterInit(p, 0, iSegid, iLeaf);
252362 fts5DlidxIterEof(p, pDlidx)==0;
252371 pDlidx = 0;
252374 fts5DlidxIterEof(p, pDlidx)==0;
252383 pDlidx = 0;
252398 Fts5IndexIter *pIter = 0;
252400 p, z, n, (flags | FTS5INDEX_QUERY_NOTOKENDATA), 0, &pIter
252403 while( rc==SQLITE_OK && ALWAYS(pIter!=0) && 0==sqlite3Fts5IterEof(pIter) ){
252407 cksum ^= sqlite3Fts5IndexEntryCksum(rowid, 0, 0, iIdx, z, n);
252411 sReader.bEof==0;
252431 ** encoded codepoints. If so, return 0. Otherwise, if the buffer does not
252435 int i = 0;
252436 assert_nc( n>0 );
252438 if( (z[i] & 0x80)==0x00 ){
252441 if( (z[i] & 0xE0)==0xC0 ){
252442 if( i+1>=n || (z[i+1] & 0xC0)!=0x80 ) return 1;
252445 if( (z[i] & 0xF0)==0xE0 ){
252446 if( i+2>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
252449 if( (z[i] & 0xF8)==0xF0 ){
252450 if( i+3>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
252451 if( (z[i+2] & 0xC0)!=0x80 ) return 1;
252458 return 0;
252473 if( pPrev->n==0 ){
252480 int iIdx = (pPrev->p[0] - FTS5_MAIN_PREFIX);
252481 int flags = (iIdx==0 ? 0 : FTS5INDEX_QUERY_PREFIX);
252482 u64 ck1 = 0;
252483 u64 ck2 = 0;
252507 if( p->nPendingData==0 && 0==fts5TestUtf8(zTerm, nTerm) ){
252508 if( iIdx>0 && rc==SQLITE_OK ){
252510 ck2 = 0;
252514 if( iIdx>0 && rc==SQLITE_OK ){
252516 ck2 = 0;
252561 if( i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf) ) p->rc = FTS5_CORRUPT;
252568 i64 iTermOff = 0;
252571 Fts5Buffer buf1 = {0,0,0};
252572 Fts5Buffer buf2 = {0,0,0};
252607 if( res<=0 ) p->rc = FTS5_CORRUPT;
252623 sqlite3_stmt *pStmt = 0;
252628 if( pSeg->pgnoFirst==0 ) return;
252651 if( pLeaf==0 ) break;
252659 if( nIdxTerm==0
252684 if( res==0 ) res = nTerm - nIdxTerm;
252685 if( res<0 ) p->rc = FTS5_CORRUPT;
252702 Fts5DlidxIter *pDlidx = 0; /* For iterating through doclist index */
252705 int iPg = 0;
252708 for(pDlidx=fts5DlidxIterInit(p, 0, iSegid, iIdxLeaf);
252709 fts5DlidxIterEof(p, pDlidx)==0;
252718 if( fts5LeafFirstRowidOff(pLeaf)!=0 ) p->rc = FTS5_CORRUPT;
252734 }else if( bSecureDelete==0 || iRowidOff>0 ){
252737 if( iRowid<iDlRowid || (bSecureDelete==0 && iRowid!=iDlRowid) ){
252760 #if 0
252780 u64 cksum2 = 0; /* Checksum based on contents of indexes */
252781 Fts5Buffer poslist = {0,0,0}; /* Buffer used to hold a poslist */
252788 u64 cksum3 = 0; /* Checksum based on contents of indexes */
252789 Fts5Buffer term = {0,0,0}; /* Buffer used to hold most recent term */
252795 if( pStruct==0 ){
252801 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
252802 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
252821 for(fts5MultiIterNew(p, pStruct, flags, 0, 0, 0, -1, 0, &pIter);
252822 fts5MultiIterEof(p, pIter)==0;
252823 fts5MultiIterNext(p, pIter, 0, 0)
252826 i64 iPos = 0; /* Position read from poslist */
252827 int iOff = 0; /* Offset within poslist */
252836 if( 0==fts5MultiIterIsEmpty(p, pIter) ){
252837 cksum2 ^= sqlite3Fts5IndexEntryCksum(iRowid, 0, 0, -1, z, n);
252840 poslist.n = 0;
252841 fts5SegiterPoslist(p, &pIter->aSeg[pIter->aFirst[1].iFirst], 0, &poslist);
252842 fts5BufferAppendBlob(&p->rc, &poslist, 4, (const u8*)"\0\0\0\0");
252843 while( 0==sqlite3Fts5PoslistNext64(poslist.p, poslist.n, &iOff, &iPos) ){
252850 fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3);
252888 *pbDlidx = (int)(iRowid & 0x0001);
252894 *pbTombstone = (int)(iRowid & 0x0001);
252903 if( iSegid==0 ){
252928 for(iLvl=0; iLvl<p->nLevel; iLvl++){
252933 for(iSeg=0; iSeg<pLvl->nSeg; iSeg++){
252938 if( pSeg->iOrigin1>0 ){
252964 Fts5Structure *p = 0; /* Decoded structure object */
252966 rc = fts5StructureDecode(pBlob, nBlob, 0, &p);
252990 int i = 0;
253006 ** after either the input buffer is exhausted or a 0 value is read.
253011 int iOff = 0;
253031 i64 iDocid = 0;
253032 int iOff = 0;
253034 if( n>0 ){
253075 int i = 0;
253076 i64 iRowid = 0;
253084 if( i<nData && pData[i]==0x00 ){
253086 if( i<nData && pData[i]==0x00 ){
253104 for(ii=0; ii<pTerm->n; ii++){
253105 if( pTerm->p[ii]==0x00 ){
253107 pBuf->p[pBuf->n++] = '0';
253112 pBuf->p[pBuf->n] = 0x00;
253130 u8 *a = 0;
253133 sqlite3_int64 nSpace = 0;
253134 int eDetailNone = (sqlite3_user_data(pCtx)!=0);
253138 memset(&s, 0, sizeof(Fts5Buffer));
253139 iRowid = sqlite3_value_int64(apVal[0]);
253142 ** copy is followed by FTS5_DATA_ZERO_PADDING 0x00 bytes, which prevents
253148 if( a==0 ) goto decode_out;
253149 if( n>0 ) memcpy(a, aBlob, n);
253161 memset(&lvl, 0, sizeof(Fts5DlidxLvl));
253165 for(fts5DlidxLvlNext(&lvl); lvl.bEof==0; fts5DlidxLvlNext(&lvl)){
253172 int szKey = (aBlob[0]==4 || aBlob[0]==8) ? aBlob[0] : 8;
253177 sqlite3Fts5BufferAppendPrintf(&rc, &s, " 0");
253179 for(ii=0; ii<nSlot; ii++){
253180 u64 iVal = 0;
253188 if( iVal!=0 ){
253192 }else if( iSegid==0 ){
253203 int nKeep = 0;
253206 memset(&term, 0, sizeof(Fts5Buffer));
253252 int iPgidxPrev = 0; /* Previous value read from pgidx */
253253 int iTermOff = 0;
253254 int iRowidOff = 0;
253258 memset(&term, 0, sizeof(Fts5Buffer));
253264 iRowidOff = fts5GetU16(&a[0]);
253275 if( iRowidOff!=0 ){
253277 }else if( iTermOff!=0 ){
253317 if( bFirst==0 ){
253362 if( nArg==0 ){
253365 zArg = (const char*)sqlite3_value_text(apVal[0]);
253366 if( 0==sqlite3_stricmp(zArg, "segment") ){
253414 Fts5StructVtab *pNew = 0;
253444 pIdxInfo->idxNum = 0;
253445 for(i=0, p=pIdxInfo->aConstraint; i<pIdxInfo->nConstraint; i++, p++){
253446 if( p->usable==0 ) continue;
253471 Fts5StructVcsr *pNew = 0;
253502 pCsr->iSeg = 0;
253506 pCsr->pStruct = 0;
253517 return pCsr->pStruct==0;
253543 case 0: /* level */
253583 ** idxNum==0 means show all subprograms
253594 const u8 *aBlob = 0;
253595 int nBlob = 0;
253599 pCsr->pStruct = 0;
253601 nBlob = sqlite3_value_bytes(argv[0]);
253602 aBlob = (const u8*)sqlite3_value_blob(argv[0]);
253603 rc = fts5StructureDecode(aBlob, nBlob, 0, &pCsr->pStruct);
253605 pCsr->iLevel = 0;
253606 pCsr->iRowid = 0;
253627 db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0
253633 SQLITE_UTF8, (void*)db, fts5DecodeFunction, 0, 0
253639 db, "fts5_rowid", -1, SQLITE_UTF8, 0, fts5RowidFunction, 0, 0
253645 0, /* iVersion */
253646 0, /* xCreate */
253650 0, /* xDestroy */
253658 0, /* xUpdate */
253659 0, /* xBegin */
253660 0, /* xSync */
253661 0, /* xCommit */
253662 0, /* xRollback */
253663 0, /* xFindFunction */
253664 0, /* xRename */
253665 0, /* xSavepoint */
253666 0, /* xRelease */
253667 0, /* xRollbackTo */
253668 0, /* xShadowName */
253669 0 /* xIntegrity */
253671 rc = sqlite3_create_module(db, "fts5_structure", &fts5structure_module, 0);
253682 assert( p->pStruct==0 || p->iStructVersion!=0 );
253757 int eState; /* 0==closed, 1==open, 2==synced */
253758 int iSavepoint; /* Number of open savepoints (0 -> none) */
253781 #define FTS5_LOCALE_HDR_SIZE ((int)sizeof( ((Fts5Global*)0)->aLocaleHdr ))
253926 #define FTS5_BI_MATCH 0x0001 /* <tbl> MATCH ? */
253927 #define FTS5_BI_RANK 0x0002 /* rank MATCH ? */
253928 #define FTS5_BI_ROWID_EQ 0x0004 /* rowid == ? */
253929 #define FTS5_BI_ROWID_LE 0x0008 /* rowid <= ? */
253930 #define FTS5_BI_ROWID_GE 0x0010 /* rowid >= ? */
253932 #define FTS5_BI_ORDER_RANK 0x0020
253933 #define FTS5_BI_ORDER_ROWID 0x0040
253934 #define FTS5_BI_ORDER_DESC 0x0080
253939 #define FTS5CSR_EOF 0x01
253940 #define FTS5CSR_REQUIRE_CONTENT 0x02
253941 #define FTS5CSR_REQUIRE_DOCSIZE 0x04
253942 #define FTS5CSR_REQUIRE_INST 0x08
253943 #define FTS5CSR_FREE_ZRANK 0x10
253944 #define FTS5CSR_REQUIRE_RESEEK 0x20
253945 #define FTS5CSR_REQUIRE_POSLIST 0x40
253948 #define BitFlagTest(x,y) (((x) & (y))!=0)
253976 assert( p->ts.eState==0 );
253988 p->ts.eState = 0;
253992 assert( p->ts.eState==1 || p->ts.eState==2 || p->ts.eState==0 );
253993 p->ts.eState = 0;
253998 assert( iSavepoint>=0 );
254005 assert( iSavepoint>=0 );
254076 ** argv[0] -> module name ("fts5")
254093 Fts5Config *pConfig = 0; /* Results of parsing argc/argv */
254094 Fts5FullTable *pTab = 0; /* New virtual table object */
254100 assert( (rc==SQLITE_OK && *pzErr==0) || pConfig==0 );
254140 if( pConfig ) pConfig->pzErrmsg = 0;
254143 pTab = 0;
254145 fts5CheckTransactionState(pTab, FTS5_BEGIN, 0);
254163 return fts5InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
254216 return 0;
254284 int idxFlags = 0; /* Parameter passed through to xFilter() */
254288 int iIdxStr = 0;
254289 int iCons = 0;
254291 int bSeenEq = 0;
254292 int bSeenGt = 0;
254293 int bSeenLt = 0;
254294 int nSeenMatch = 0;
254295 int bSeenRank = 0;
254312 if( idxStr==0 ) return SQLITE_NOMEM;
254316 for(i=0; i<pInfo->nConstraint; i++){
254323 if( p->usable==0 || iCol<0 ){
254326 idxStr[iIdxStr] = 0;
254338 assert( idxStr[iIdxStr]=='\0' );
254344 if( iCol>=0 && iCol<nCol && fts5UsePatternMatch(pConfig, p) ){
254350 assert( idxStr[iIdxStr]=='\0' );
254352 }else if( bSeenEq==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ && iCol<0 ){
254360 if( bSeenEq==0 ){
254361 for(i=0; i<pInfo->nConstraint; i++){
254363 if( p->iColumn<0 && p->usable ){
254380 idxStr[iIdxStr] = '\0';
254387 int iSort = pInfo->aOrderBy[0].iColumn;
254388 if( iSort==(pConfig->nCol+1) && nSeenMatch>0 ){
254390 }else if( iSort==-1 && (!pInfo->aOrderBy[0].desc || !pConfig->bTokendata) ){
254395 if( pInfo->aOrderBy[0].desc ){
254404 if( nSeenMatch==0 ) fts5SetUniqueFlag(pInfo);
254434 Fts5Cursor *pCsr = 0; /* New cursor object */
254444 memset(pCsr, 0, (size_t)nByte);
254514 memset(&pCsr->ePlan, 0, sizeof(Fts5Cursor) - ((u8*)&pCsr->ePlan - (u8*)pCsr));
254551 int iOff = 0;
254554 pSorter->iRowid = sqlite3_column_int64(pSorter->pStmt, 0);
254558 /* nBlob==0 in detail=none mode. */
254559 if( nBlob>0 ){
254560 for(i=0; i<(pSorter->nIdx-1); i++){
254606 assert( *pbSkip==0 );
254656 int bSkip = 0;
254706 sqlite3_stmt *pRet = 0;
254713 if( zSql==0 ){
254717 SQLITE_PREPARE_PERSISTENT, &pRet, 0);
254745 if( pSorter==0 ) return SQLITE_NOMEM;
254746 memset(pSorter, 0, (size_t)nByte);
254766 assert( pTab->pSortCsr==0 );
254769 pTab->pSortCsr = 0;
254775 pCsr->pSorter = 0;
254807 while( z[0]==' ' ) z++;
254808 for(n=0; z[n] && z[n]!=' '; n++);
254810 assert( pTab->p.base.zErrMsg==0 );
254813 if( n==5 && 0==sqlite3_strnicmp("reads", z, n) ){
254816 else if( n==2 && 0==sqlite3_strnicmp("id", z, n) ){
254837 if( sqlite3_stricmp(zName, pAux->zFunc)==0 ) return pAux;
254840 /* No function of the specified name was found. Return 0. */
254841 return 0;
254849 Fts5Auxiliary *pAux = 0;
254856 sqlite3_stmt *pStmt = 0;
254858 SQLITE_PREPARE_PERSISTENT, &pStmt, 0);
254860 assert( rc==SQLITE_OK || pCsr->pRankArgStmt==0 );
254869 for(i=0; i<pCsr->nRankArg; i++){
254884 if( pAux==0 ){
254885 assert( pTab->p.base.zErrMsg==0 );
254904 char *zRank = 0;
254905 char *zRankArgs = 0;
254907 if( z==0 ){
254927 pCsr->zRankArgs = 0;
254974 sqlite3Fts5SetLocale(pConfig, 0, 0);
254982 int ret = 0;
254987 ** by both value_blob() and value_bytes() will be 0. If value_bytes() were
254993 && 0==memcmp(pBlob, FTS5_LOCALE_HDR(pConfig), FTS5_LOCALE_HDR_SIZE)
255023 int nLoc = 0;
255063 const char *pText = 0;
255064 int nText = 0;
255065 const char *pLoc = 0;
255066 int nLoc = 0;
255075 *pbFreeAndReset = 0;
255106 sqlite3_value *pRank = 0; /* rank MATCH ? expression (or NULL) */
255107 sqlite3_value *pRowidEq = 0; /* rowid = ? expression (or NULL) */
255108 sqlite3_value *pRowidLe = 0; /* rowid <= ? expression (or NULL) */
255109 sqlite3_value *pRowidGe = 0; /* rowid >= ? expression (or NULL) */
255114 int iIdxStr = 0;
255115 Fts5Expr *pExpr = 0;
255117 assert( pConfig->bLock==0 );
255120 memset(&pCsr->ePlan, 0, sizeof(Fts5Cursor) - ((u8*)&pCsr->ePlan-(u8*)pCsr));
255123 assert( pCsr->pStmt==0 );
255124 assert( pCsr->pExpr==0 );
255125 assert( pCsr->csrflags==0 );
255126 assert( pCsr->pRank==0 );
255127 assert( pCsr->zRank==0 );
255128 assert( pCsr->zRankArgs==0 );
255129 assert( pTab->pSortCsr==0 || nVal==0 );
255131 assert( pzErrmsg==0 || pzErrmsg==&pTab->p.base.zErrMsg );
255135 for(i=0; i<nVal; i++){
255141 char *zText = 0;
255142 int bFreeAndReset = 0;
255143 int bInternal = 0;
255147 if( zText==0 ) zText = "";
255152 iCol = 0;
255154 iCol = iCol*10 + (idxStr[iIdxStr]-'0');
255156 }while( idxStr[iIdxStr]>='0' && idxStr[iIdxStr]<='9' );
255158 if( zText[0]=='*' ){
255166 rc = sqlite3Fts5ExprNew(pConfig, 0, iCol, zText, &pExpr, pzErr);
255169 pExpr = 0;
255186 iCol = 0;
255188 iCol = iCol*10 + (idxStr[iIdxStr]-'0');
255190 }while( idxStr[iIdxStr]>='0' && idxStr[iIdxStr]<='9' );
255196 pExpr = 0;
255212 bOrderByRank = ((idxNum & FTS5_BI_ORDER_RANK) ? 1 : 0);
255213 pCsr->bDesc = bDesc = ((idxNum & FTS5_BI_ORDER_DESC) ? 1 : 0);
255240 assert( pRowidEq==0 && pRowidLe==0 && pRowidGe==0 && pRank==0 );
255241 assert( nVal==0 && bOrderByRank==0 && bDesc==0 );
255266 }else if( pConfig->zContent==0 ){
255277 if( pRowidEq!=0 ){
255301 return (CsrFlagTest(pCsr, FTS5CSR_EOF) ? 1 : 0);
255317 return sqlite3_column_int64(pCsr->pStmt, 0);
255333 assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
255335 *pRowid = 0;
255355 if( pCsr->pStmt==0 ){
255359 pTab->pStorage, eStmt, &pCsr->pStmt, (bErrormsg?&pTab->p.base.zErrMsg:0)
255361 assert( rc!=SQLITE_OK || pTab->p.base.zErrMsg==0 );
255417 int bError = 0;
255418 int bLoadConfig = 0;
255420 if( 0==sqlite3_stricmp("delete-all", zCmd) ){
255431 }else if( 0==sqlite3_stricmp("rebuild", zCmd) ){
255441 }else if( 0==sqlite3_stricmp("optimize", zCmd) ){
255443 }else if( 0==sqlite3_stricmp("merge", zCmd) ){
255446 }else if( 0==sqlite3_stricmp("integrity-check", zCmd) ){
255450 }else if( 0==sqlite3_stricmp("prefix-index", zCmd) ){
255453 }else if( 0==sqlite3_stricmp("flush", zCmd) ){
255467 rc = sqlite3Fts5StorageConfigValue(pTab->pStorage, zCmd, pVal, 0);
255488 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, &apVal[2], 0);
255501 rc = sqlite3Fts5StorageContentInsert(pTab->pStorage, 0, apVal, piRowid);
255539 int bSeenIndex = 0; /* Have seen modified indexed column */
255540 int bSeenIndexNC = 0; /* Have seen unmodified indexed column */
255543 for(ii=0; ii<pConfig->nCol; ii++){
255544 if( pConfig->abUnindexed[ii]==0 ){
255553 if( bSeenIndex==0 && bRowidModified==0 ){
255556 if( bSeenIndexNC || pConfig->bContentlessDelete==0 ){
255592 int eType0; /* value_type() of apVal[0] */
255598 assert( pVtab->zErrMsg==0 );
255600 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER
255601 || sqlite3_value_type(apVal[0])==SQLITE_NULL
255603 assert( pTab->p.pConfig->pzErrmsg==0 );
255604 if( pConfig->pgsz==0 ){
255614 eType0 = sqlite3_value_type(apVal[0]);
255621 && 0==sqlite3_stricmp("delete", z)
255658 if( fts5IsContentless(pTab, 1) && pConfig->bContentlessDelete==0 ){
255664 i64 iDel = sqlite3_value_int64(apVal[0]); /* Rowid to delete */
255665 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0, 0);
255675 if( pConfig->bLocale==0 ){
255677 for(ii=0; ii<pConfig->nCol; ii++){
255692 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0, 0);
255700 i64 iOld = sqlite3_value_int64(apVal[0]); /* Old rowid */
255702 int bContent = 0; /* Content only update */
255714 assert( bContent==0 );
255716 rc = sqlite3Fts5StorageDelete(pStorage, iOld, 0, 1);
255718 rc = sqlite3Fts5StorageDelete(pStorage, iNew, 0, 0);
255724 rc = sqlite3Fts5StorageContentInsert(pStorage, 0, apVal, pRowid);
255727 rc = sqlite3Fts5StorageDelete(pStorage, iOld, 0, 0);
255735 ** UNINDEXED columns. This is a no-op for contentless_unindexed=0
255743 rc = sqlite3Fts5StorageDelete(pStorage, iOld, 0, 1);
255752 pTab->p.pConfig->pzErrmsg = 0;
255762 fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
255765 pTab->p.pConfig->pzErrmsg = 0;
255775 fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_BEGIN, 0);
255787 fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_COMMIT, 0);
255798 fts5CheckTransactionState(pTab, FTS5_ROLLBACK, 0);
255800 pTab->p.pConfig->pgsz = 0;
255850 sqlite3Fts5SetLocale(pTab->pConfig, 0, 0);
255856 ** Implementation of xTokenize() API. This is just xTokenize_v2() with NULL/0
255865 return fts5ApiTokenize_v2(pCtx, pText, nText, 0, 0, pUserData, xToken);
255900 const char *pLoc = 0;
255901 int nLoc = 0;
255932 if( iCol<0 || iCol>=pTab->pConfig->nCol ){
255934 }else if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab), 0) ){
255935 *pz = 0;
255936 *pn = 0;
255938 rc = fts5SeekCursor(pCsr, 0);
255962 int bLive = (pCsr->pSorter==0);
255964 if( iPhrase<0 || iPhrase>=sqlite3Fts5ExprPhraseCount(pCsr->pExpr) ){
255969 *pa = 0;
255970 *pn = 0;
255978 if( aPopulator==0 ) rc = SQLITE_NOMEM;
255980 rc = fts5SeekCursor(pCsr, 0);
255982 for(i=0; i<pConfig->nCol && rc==SQLITE_OK; i++){
255983 const char *z = 0;
255984 int n = 0;
256005 int i1 = (iPhrase==0 ? 0 : pSorter->aIdx[iPhrase-1]);
256012 *pa = 0;
256013 *pn = 0;
256031 if( pCsr->aInstIter==0 ){
256038 int nInst = 0; /* Number instances seen so far */
256042 for(i=0; i<nIter && rc==SQLITE_OK; i++){
256055 for(i=0; i<nIter; i++){
256056 if( (aIter[i].bEof==0)
256057 && (iBest<0 || aIter[i].iPos<aIter[iBest].iPos)
256062 if( iBest<0 ) break;
256081 aInst[0] = iBest;
256084 assert( aInst[1]>=0 );
256102 if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_INST)==0
256118 if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_INST)==0
256121 if( iIdx<0 || iIdx>=pCsr->nInstCount ){
256147 if( (tflags & FTS5_TOKEN_COLOCATED)==0 ){
256165 for(i=0; i<pConfig->nCol; i++){
256166 if( pConfig->abUnindexed[i]==0 ){
256172 rc = fts5SeekCursor(pCsr, 0);
256173 for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
256174 if( pConfig->abUnindexed[i]==0 ){
256175 const char *z = 0;
256176 int n = 0;
256177 pCsr->aColumnSize[i] = 0;
256190 if( iCol<0 ){
256192 *pnToken = 0;
256193 for(i=0; i<pConfig->nCol; i++){
256199 *pnToken = 0;
256229 if( pData==0 ){
256246 void *pRet = 0;
256255 pData->pPtr = 0;
256256 pData->xDelete = 0;
256281 *piOff = 0;
256298 assert( pIter->a || n==0 );
256299 pIter->b = (pIter->a ? &pIter->a[n] : 0);
256300 *piCol = 0;
256301 *piOff = 0;
256320 pIter->a += fts5GetVarint32(&pIter->a[0], iIncr);
256330 if( pIter->a[0]==0x01 ) break;
256351 int i1 = (iPhrase==0 ? 0 : pSorter->aIdx[iPhrase-1]);
256358 assert( pIter->a || n==0 );
256359 pIter->b = (pIter->a ? &pIter->a[n] : 0);
256360 *piCol = 0;
256367 assert( pIter->a || n==0 );
256368 pIter->b = (pIter->a ? &pIter->a[n] : 0);
256369 if( n<=0 ){
256371 }else if( pIter->a[0]==0x01 ){
256374 *piCol = 0;
256407 if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_INST)==0
256410 if( iIdx<0 || iIdx>=pCsr->nInstCount ){
256443 *pzLocale = 0;
256444 *pnLocale = 0;
256447 if( iCol<0 || iCol>=pConfig->nCol ){
256450 pConfig->abUnindexed[iCol]==0
256451 && 0==fts5IsContentless((Fts5FullTable*)pCsr->base.pVtab, 1)
256454 rc = fts5SeekCursor(pCsr, 0);
256456 const char *zDummy = 0;
256457 int nDummy = 0;
256509 Fts5Cursor *pNew = 0;
256521 for(rc = fts5CursorFirst(pTab, pNew, 0);
256522 rc==SQLITE_OK && CsrFlagTest(pNew, FTS5CSR_EOF)==0;
256544 assert( pCsr->pAux==0 );
256548 pCsr->pAux = 0;
256565 char *zErr = 0;
256586 iCsrId = sqlite3_value_int64(argv[0]);
256589 if( pCsr==0 || (pCsr->ePlan==0 || pCsr->ePlan==FTS5_PLAN_SPECIAL) ){
256595 pTab->zErrMsg = 0;
256613 return 0;
256627 ** for phrase 0. The second (same disclaimer) contains the size of position
256637 memset(&val, 0, sizeof(Fts5Buffer));
256642 for(i=0; i<(nPhrase-1); i++){
256649 for(i=0; i<nPhrase; i++){
256660 for(i=0; rc==SQLITE_OK && i<(nPhrase-1); i++){
256668 for(i=0; rc==SQLITE_OK && i<nPhrase; i++){
256698 assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
256735 const char *z = 0;
256736 int n = 0;
256747 pConfig->pzErrmsg = 0;
256777 /* No function of the specified name was found. Return 0. */
256778 return 0;
256845 pTab->p.pConfig->pgsz = 0;
256865 sqlite3_int64 nName; /* Size of zName in bytes, including \0 */
256872 memset(pAux, 0, (size_t)nByte);
256913 sqlite3_int64 nName; /* Size of zName and its \0 terminator */
256926 if( pNew->pNext==0 ){
256959 Fts5VtoVTokenizer *pNew = 0;
256974 pNew = 0;
257010 return p->x2.xTokenize(p->pReal, pCtx, flags, pText, nText, 0, 0, xToken);
257025 assert( p->bV2Native==0 );
257047 Fts5TokenizerModule *pNew = 0;
257071 Fts5TokenizerModule *pNew = 0;
257095 Fts5TokenizerModule *pMod = 0;
257097 if( zName==0 ){
257101 if( sqlite3_stricmp(zName, pMod->zName)==0 ) break;
257130 *ppTokenizer = 0;
257131 *ppUserData = 0;
257153 if( pMod->bV2Native==0 ){
257160 memset(pTokenizer, 0, sizeof(*pTokenizer));
257161 *ppUserData = 0;
257174 Fts5TokenizerModule *pMod = 0;
257177 pMod = fts5LocateTokenizer(pConfig->pGlobal, nArg==0 ? 0 : azArg[0]);
257178 if( pMod==0 ){
257179 assert( nArg>0 );
257181 sqlite3Fts5ConfigErrmsg(pConfig, "no such tokenizer: %s", azArg[0]);
257183 int (*xCreate)(void*, const char**, int, Fts5Tokenizer**) = 0;
257193 (azArg?&azArg[1]:0), (nArg?nArg-1:0), &pConfig->t.pTok
257200 }else if( pMod->bV2Native==0 ){
257208 pConfig->t.pApi1 = 0;
257209 pConfig->t.pApi2 = 0;
257210 pConfig->t.pTok = 0;
257255 ppApi = (fts5_api**)sqlite3_value_pointer(apArg[0], "fts5_api_ptr");
257267 assert( nArg==0 );
257279 ** * The 4 bytes 0x00, 0xE0, 0xB2, 0xEb (FTS5_LOCALE_HEADER).
257281 ** * 0x00, followed by
257291 const char *zLocale = 0;
257292 int nLocale = 0;
257293 const char *zText = 0;
257294 int nText = 0;
257299 zLocale = (const char*)sqlite3_value_text(apArg[0]);
257300 nLocale = sqlite3_value_bytes(apArg[0]);
257305 if( zLocale==0 || zLocale[0]=='\0' ){
257309 u8 *pBlob = 0;
257310 u8 *pCsr = 0;
257311 int nBlob = 0;
257315 if( pBlob==0 ){
257325 (*pCsr++) = 0x00;
257343 sqlite3_result_value(pCtx, apArg[0]);
257356 for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
257357 if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
257359 return 0;
257377 assert( pzErr!=0 && *pzErr==0 );
257379 assert( pTab->p.pConfig->pzErrmsg==0 );
257381 rc = sqlite3Fts5StorageIntegrity(pTab->pStorage, 0);
257382 if( *pzErr==0 && rc!=SQLITE_OK ){
257383 if( (rc&0xff)==SQLITE_CORRUPT ){
257395 pTab->p.pConfig->pzErrmsg = 0;
257430 Fts5Global *pGlobal = 0;
257433 if( pGlobal==0 ){
257437 memset(pGlobal, 0, sizeof(Fts5Global));
257449 pGlobal->aLocaleHdr[0] ^= 0xF924976D;
257450 pGlobal->aLocaleHdr[1] ^= 0x16596E13;
257451 pGlobal->aLocaleHdr[2] ^= 0x7C80BEAA;
257452 pGlobal->aLocaleHdr[3] ^= 0x9B03A67F;
257463 db, "fts5", 1, SQLITE_UTF8, p, fts5Fts5Func, 0, 0
257468 db, "fts5_source_id", 0,
257470 p, fts5SourceIdFunc, 0, 0
257477 p, fts5LocaleFunc, 0, 0
257484 p, fts5InsttokenFunc, 0, 0
257598 #if FTS5_STMT_SCAN_ASC!=0
257640 assert( eStmt>=0 && eStmt<ArraySize(p->aStmt) );
257641 if( p->aStmt[eStmt]==0 ){
257660 char *zSql = 0;
257688 char *zBind = 0;
257699 for(i=0; rc==SQLITE_OK && i<(pC->nCol+1); i++){
257708 for(i=0; rc==SQLITE_OK && i<pC->nCol; i++){
257709 if( pC->abUnindexed[i]==0 ){
257738 if( zSql==0 ){
257744 rc = sqlite3_prepare_v3(pC->db, zSql, -1, f, &p->aStmt[eStmt], 0);
257777 if( zSql==0 ){
257780 rc = sqlite3_exec(db, zSql, 0, 0, pzErr);
257793 int rc = fts5ExecPrintf(pConfig->db, 0,
257802 rc = fts5ExecPrintf(pConfig->db, 0,
257808 rc = fts5ExecPrintf(pConfig->db, 0,
257823 *pRc = fts5ExecPrintf(pConfig->db, 0,
257858 char *zErr = 0;
257901 memset(p, 0, (size_t)nByte);
257912 if( zDefn==0 ){
257919 for(i=0; i<pConfig->nCol; i++){
257928 for(i=0; i<pConfig->nCol; i++){
257929 if( pConfig->abUnindexed[i]==0 ){
257935 rc = sqlite3Fts5CreateTable(pConfig, "content", zDefn, 0, pzErr);
257945 rc = sqlite3Fts5CreateTable(pConfig, "docsize", zCols, 0, pzErr);
257953 rc = sqlite3Fts5StorageConfigValue(p, "version", 0, FTS5_CURRENT_VERSION);
257959 *pp = 0;
257973 for(i=0; i<ArraySize(p->aStmt); i++){
258004 if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
258022 sqlite3_stmt *pSeek = 0;
258024 assert( p->pSavedRow==0 );
258025 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP+1, &pSeek, 0);
258055 sqlite3_stmt *pSeek = 0; /* SELECT to read row iDel from %_data */
258061 assert( bSaveRow==0 || apVal==0 );
258062 assert( bSaveRow==0 || bSaveRow==1 );
258065 if( apVal==0 ){
258068 p->pSavedRow = 0;
258070 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP+bSaveRow, &pSeek, 0);
258082 if( pConfig->abUnindexed[iCol-1]==0 ){
258083 sqlite3_value *pVal = 0;
258084 sqlite3_value *pFree = 0;
258085 const char *pText = 0;
258086 int nText = 0;
258087 const char *pLoc = 0;
258088 int nLoc = 0;
258090 assert( pSeek==0 || apVal==0 );
258091 assert( pSeek!=0 || apVal!=0 );
258106 if( pVal==0 ){
258122 ctx.szCol = 0;
258127 if( rc==SQLITE_OK && p->aTotalSize[iCol-1]<0 ){
258142 assert( p->pSavedRow==0 );
258157 assert( pStorage->pSavedRow==0
258161 pStorage->pSavedRow = 0;
258171 i64 iOrigin = 0;
258172 sqlite3_stmt *pLookup = 0;
258182 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
258191 if( rc==SQLITE_OK && iOrigin!=0 ){
258203 ** If there is no %_docsize table (as happens if the columnsize=0 option
258213 sqlite3_stmt *pReplace = 0;
258214 rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
258218 i64 iOrigin = 0;
258245 if( p->bTotalsValid==0 ){
258264 memset(&buf, 0, sizeof(buf));
258267 for(i=0; i<nCol; i++){
258289 sqlite3_stmt *pDel = 0;
258291 assert( pConfig->eContent!=FTS5_CONTENT_NORMAL || apVal==0 );
258315 rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_DOCSIZE, &pDel, 0);
258328 rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_CONTENT, &pDel, 0);
258347 p->bTotalsValid = 0;
258350 rc = fts5ExecPrintf(pConfig->db, 0,
258357 rc = fts5ExecPrintf(pConfig->db, 0,
258363 rc = fts5ExecPrintf(pConfig->db, 0,
258374 rc = sqlite3Fts5StorageConfigValue(p, "version", 0, FTS5_CURRENT_VERSION);
258380 Fts5Buffer buf = {0,0,0};
258382 sqlite3_stmt *pScan = 0;
258386 memset(&ctx, 0, sizeof(Fts5InsertCtx));
258398 i64 iRowid = sqlite3_column_int64(pScan, 0);
258401 rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
258402 for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
258403 ctx.szCol = 0;
258404 if( pConfig->abUnindexed[ctx.iCol]==0 ){
258405 int nText = 0; /* Size of pText in bytes */
258406 const char *pText = 0; /* Pointer to buffer containing text value */
258407 int nLoc = 0; /* Size of pLoc in bytes */
258408 const char *pLoc = 0; /* Pointer to buffer containing text value */
258480 sqlite3_stmt *pReplace = 0;
258481 rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
258517 sqlite3_stmt *pInsert = 0; /* Statement to write %_content table */
258521 assert( bReplace==0 || bReplace==1 );
258522 rc = fts5StorageGetStmt(p, FTS5_STMT_INSERT_CONTENT+bReplace, &pInsert, 0);
258539 if( pConfig->bLocale && bUnindexed==0 ){
258545 const char *pText = 0;
258546 const char *pLoc = 0;
258547 int nText = 0;
258548 int nLoc = 0;
258554 if( bUnindexed==0 ){
258589 memset(&buf, 0, sizeof(Fts5Buffer));
258594 rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
258596 for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
258597 ctx.szCol = 0;
258598 if( pConfig->abUnindexed[ctx.iCol]==0 ){
258599 int nText = 0; /* Size of pText in bytes */
258600 const char *pText = 0; /* Pointer to buffer containing text value */
258601 int nLoc = 0; /* Size of pText in bytes */
258602 const char *pLoc = 0; /* Pointer to buffer containing text value */
258654 if( zSql==0 ){
258657 sqlite3_stmt *pCnt = 0;
258658 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pCnt, 0);
258661 *pnRow = sqlite3_column_int64(pCnt, 0);
258707 if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
258719 iCol = 0;
258724 iPos = 0;
258725 iCol = 0;
258729 rc = sqlite3Fts5TermsetAdd(pTermset, 0, pToken, nToken, &bPresent);
258730 if( rc==SQLITE_OK && bPresent==0 ){
258732 pCtx->iRowid, iCol, iPos, 0, pToken, nToken
258736 for(ii=0; rc==SQLITE_OK && ii<pCtx->pConfig->nPrefix; ii++){
258741 if( bPresent==0 ){
258767 memset(&ctx, 0, sizeof(Fts5IntegrityCtx));
258772 memset(aTotalSize, 0, sizeof(i64) * pConfig->nCol);
258780 rc = fts5StorageGetStmt(p, FTS5_STMT_SCAN, &pScan, 0);
258785 ctx.iRowid = sqlite3_column_int64(pScan, 0);
258786 ctx.szCol = 0;
258793 for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
258794 if( pConfig->abUnindexed[i]==0 ){
258795 const char *pText = 0;
258796 int nText = 0;
258797 const char *pLoc = 0;
258798 int nLoc = 0;
258818 ctx.szCol = 0;
258835 /* If this is not a columnsize=0 database, check that the number
258847 ctx.pTermset = 0;
258852 ctx.pTermset = 0;
258863 rc = fts5StorageLoadTotals(p, 0);
258864 for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
258872 i64 nRow = 0;
258877 i64 nRow = 0;
258912 p->aStmt[eStmt] = 0;
258931 if( p->aStmt[eStmt]==0 ){
258944 int iOff = 0;
258945 for(i=0; i<nCol; i++){
258962 sqlite3_stmt *pLookup = 0; /* Statement to query %_docsize */
258966 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
258972 const u8 *aBlob = sqlite3_column_blob(pLookup, 0);
258973 int nBlob = sqlite3_column_bytes(pLookup, 0);
258974 if( 0==fts5StorageDecodeSizeArray(aCol, nCol, aBlob, nBlob) ){
258975 bCorrupt = 0;
258990 int rc = fts5StorageLoadTotals(p, 0);
258992 *pnToken = 0;
258993 if( iCol<0 ){
258995 for(i=0; i<p->pConfig->nCol; i++){
259008 int rc = fts5StorageLoadTotals(p, 0);
259016 if( p->nTotalRow<=0 ) rc = FTS5_CORRUPT;
259030 p->bTotalsValid = 0;
259041 p->bTotalsValid = 0;
259051 sqlite3_stmt *pReplace = 0;
259052 int rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_CONFIG, &pReplace, 0);
259099 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00..0x0F */
259100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10..0x1F */
259101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20..0x2F */
259102 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0x30..0x3F */
259103 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40..0x4F */
259104 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 0x50..0x5F */
259105 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60..0x6F */
259106 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 0x70..0x7F */
259120 for(i=0; zArg[i]; i++){
259121 if( (zArg[i] & 0x80)==0 ){
259143 AsciiTokenizer *p = 0;
259149 if( p==0 ){
259153 memset(p, 0, sizeof(AsciiTokenizer));
259155 for(i=0; rc==SQLITE_OK && i<nArg; i+=2){
259157 if( 0==sqlite3_stricmp(azArg[i], "tokenchars") ){
259160 if( 0==sqlite3_stricmp(azArg[i], "separators") ){
259161 fts5AsciiAddExceptions(p, zArg, 0);
259168 p = 0;
259180 for(i=0; i<nByte; i++){
259200 int is = 0;
259213 while( is<nText && ((pText[is]&0x80)==0 && a[(int)pText[is]]==0) ){
259220 while( ie<nText && ((pText[ie]&0x80) || a[(int)pText[ie]] ) ){
259229 if( pFold==0 ){
259238 rc = xToken(pCtx, 0, pFold, nByte, is, ie);
259260 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
259261 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
259262 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
259263 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
259264 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
259265 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
259266 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
259267 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
259272 if( c>=0xc0 ){ \
259273 c = sqlite3Utf8Trans1[c-0xc0]; \
259274 while( zIn<zTerm && (*zIn & 0xc0)==0x80 ){ \
259275 c = (c<<6) + (0x3f & *(zIn++)); \
259277 if( c<0x80 \
259278 || (c&0xFFFFF800)==0xD800 \
259279 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
259284 if( c<0x00080 ){ \
259285 *zOut++ = (unsigned char)(c&0xFF); \
259287 else if( c<0x00800 ){ \
259288 *zOut++ = 0xC0 + (unsigned char)((c>>6)&0x1F); \
259289 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
259291 else if( c<0x10000 ){ \
259292 *zOut++ = 0xE0 + (unsigned char)((c>>12)&0x0F); \
259293 *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
259294 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
259296 *zOut++ = 0xF0 + (unsigned char)((c>>18) & 0x07); \
259297 *zOut++ = 0x80 + (unsigned char)((c>>12) & 0x3F); \
259298 *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
259299 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
259306 if( ((unsigned char)(*(zIn++)))>=0xc0 ){ \
259307 while( (((unsigned char)*zIn) & 0xc0)==0x80 ){ zIn++; } \
259324 #define FTS5_REMOVE_DIACRITICS_NONE 0
259331 int bTokenChars /* 1 for 'tokenchars', 0 for 'separators' */
259337 if( n>0 ){
259352 assert( (bToken==0 || bToken==1) );
259353 assert( (bTokenChars==0 || bTokenChars==1) );
259354 if( bToken!=bTokenChars && sqlite3Fts5UnicodeIsdiacritic(iCode)==0 ){
259356 for(i=0; i<nNew; i++){
259379 if( p->nException>0 ){
259381 int iLo = 0;
259396 return 0;
259420 while( *z!=' ' && *z!='\t' && *z!='\0' ) z++;
259436 Unicode61Tokenizer *p = 0; /* New tokenizer object */
259447 memset(p, 0, sizeof(Unicode61Tokenizer));
259452 if( p->aFold==0 ){
259457 for(i=0; rc==SQLITE_OK && i<nArg; i+=2){
259458 if( 0==sqlite3_stricmp(azArg[i], "categories") ){
259466 for(i=0; rc==SQLITE_OK && i<nArg; i+=2){
259468 if( 0==sqlite3_stricmp(azArg[i], "remove_diacritics") ){
259469 if( (zArg[0]!='0' && zArg[0]!='1' && zArg[0]!='2') || zArg[1] ){
259472 p->eRemoveDiacritic = (zArg[0] - '0');
259479 if( 0==sqlite3_stricmp(azArg[i], "tokenchars") ){
259482 if( 0==sqlite3_stricmp(azArg[i], "separators") ){
259483 rc = fts5UnicodeAddExceptions(p, zArg, 0);
259485 if( 0==sqlite3_stricmp(azArg[i], "categories") ){
259496 p = 0;
259547 if( *zCsr & 0x80 ) {
259572 if( aFold==0 ){
259584 if( *zCsr & 0x80 ){
259595 }else if( a[*zCsr]==0 ){
259611 rc = xToken(pCtx, 0, aFold, zOut-aFold, is, ie);
259658 void *pUserdata = 0;
259660 fts5_tokenizer_v2 *pV2 = 0;
259662 if( nArg>0 ){
259663 zBase = azArg[0];
259668 memset(pRet, 0, sizeof(PorterTokenizer));
259674 int nArg2 = (nArg>0 ? nArg-1 : 0);
259675 const char **az2 = (nArg2 ? &azArg[1] : 0);
259682 pRet = 0;
259704 #if 0
259714 if( 0==memcmp(&aBuf[nBuf - p->nSuffix], p->zSuffix, p->nSuffix) ) break;
259719 if( p->xCond==0 || p->xCond(aBuf, nStem) ){
259741 for(i=0; i<nStem; i++){
259742 if( 0==(bCons = !fts5PorterIsVowel(zStem[i], bCons)) ) break;
259749 return 0;
259752 /* porter rule condition: (m > 0) */
259754 return !!fts5PorterGobbleVC(zStem, nStem, 0);
259760 n = fts5PorterGobbleVC(zStem, nStem, 0);
259764 return 0;
259770 n = fts5PorterGobbleVC(zStem, nStem, 0);
259771 if( n && 0==fts5PorterGobbleVC(&zStem[n], nStem-n, 1) ){
259774 return 0;
259780 return 0;
259783 int mask = 0;
259784 int bCons = 0;
259785 for(i=0; i<nStem; i++){
259787 assert( bCons==0 || bCons==1 );
259790 return ((mask & 0x0007)==0x0005);
259796 assert( nStem>0 );
259804 for(i=0; i<nStem; i++){
259805 if( fts5PorterIsVowel(zStem[i], i>0) ){
259809 return 0;
259819 int ret = 0;
259824 if( nBuf>2 && 0==memcmp("al", &aBuf[nBuf-2], 2) ){
259832 if( nBuf>4 && 0==memcmp("ance", &aBuf[nBuf-4], 4) ){
259836 }else if( nBuf>4 && 0==memcmp("ence", &aBuf[nBuf-4], 4) ){
259844 if( nBuf>2 && 0==memcmp("er", &aBuf[nBuf-2], 2) ){
259852 if( nBuf>2 && 0==memcmp("ic", &aBuf[nBuf-2], 2) ){
259860 if( nBuf>4 && 0==memcmp("able", &aBuf[nBuf-4], 4) ){
259864 }else if( nBuf>4 && 0==memcmp("ible", &aBuf[nBuf-4], 4) ){
259872 if( nBuf>3 && 0==memcmp("ant", &aBuf[nBuf-3], 3) ){
259876 }else if( nBuf>5 && 0==memcmp("ement", &aBuf[nBuf-5], 5) ){
259880 }else if( nBuf>4 && 0==memcmp("ment", &aBuf[nBuf-4], 4) ){
259884 }else if( nBuf>3 && 0==memcmp("ent", &aBuf[nBuf-3], 3) ){
259892 if( nBuf>3 && 0==memcmp("ion", &aBuf[nBuf-3], 3) ){
259896 }else if( nBuf>2 && 0==memcmp("ou", &aBuf[nBuf-2], 2) ){
259904 if( nBuf>3 && 0==memcmp("ism", &aBuf[nBuf-3], 3) ){
259912 if( nBuf>3 && 0==memcmp("ate", &aBuf[nBuf-3], 3) ){
259916 }else if( nBuf>3 && 0==memcmp("iti", &aBuf[nBuf-3], 3) ){
259924 if( nBuf>3 && 0==memcmp("ous", &aBuf[nBuf-3], 3) ){
259932 if( nBuf>3 && 0==memcmp("ive", &aBuf[nBuf-3], 3) ){
259940 if( nBuf>3 && 0==memcmp("ize", &aBuf[nBuf-3], 3) ){
259953 int ret = 0;
259958 if( nBuf>2 && 0==memcmp("at", &aBuf[nBuf-2], 2) ){
259966 if( nBuf>2 && 0==memcmp("bl", &aBuf[nBuf-2], 2) ){
259974 if( nBuf>2 && 0==memcmp("iz", &aBuf[nBuf-2], 2) ){
259987 int ret = 0;
259992 if( nBuf>7 && 0==memcmp("ational", &aBuf[nBuf-7], 7) ){
259997 }else if( nBuf>6 && 0==memcmp("tional", &aBuf[nBuf-6], 6) ){
260006 if( nBuf>4 && 0==memcmp("enci", &aBuf[nBuf-4], 4) ){
260011 }else if( nBuf>4 && 0==memcmp("anci", &aBuf[nBuf-4], 4) ){
260020 if( nBuf>4 && 0==memcmp("izer", &aBuf[nBuf-4], 4) ){
260029 if( nBuf>4 && 0==memcmp("logi", &aBuf[nBuf-4], 4) ){
260038 if( nBuf>3 && 0==memcmp("bli", &aBuf[nBuf-3], 3) ){
260043 }else if( nBuf>4 && 0==memcmp("alli", &aBuf[nBuf-4], 4) ){
260048 }else if( nBuf>5 && 0==memcmp("entli", &aBuf[nBuf-5], 5) ){
260053 }else if( nBuf>3 && 0==memcmp("eli", &aBuf[nBuf-3], 3) ){
260058 }else if( nBuf>5 && 0==memcmp("ousli", &aBuf[nBuf-5], 5) ){
260067 if( nBuf>7 && 0==memcmp("ization", &aBuf[nBuf-7], 7) ){
260072 }else if( nBuf>5 && 0==memcmp("ation", &aBuf[nBuf-5], 5) ){
260077 }else if( nBuf>4 && 0==memcmp("ator", &aBuf[nBuf-4], 4) ){
260086 if( nBuf>5 && 0==memcmp("alism", &aBuf[nBuf-5], 5) ){
260091 }else if( nBuf>7 && 0==memcmp("iveness", &aBuf[nBuf-7], 7) ){
260096 }else if( nBuf>7 && 0==memcmp("fulness", &aBuf[nBuf-7], 7) ){
260101 }else if( nBuf>7 && 0==memcmp("ousness", &aBuf[nBuf-7], 7) ){
260110 if( nBuf>5 && 0==memcmp("aliti", &aBuf[nBuf-5], 5) ){
260115 }else if( nBuf>5 && 0==memcmp("iviti", &aBuf[nBuf-5], 5) ){
260120 }else if( nBuf>6 && 0==memcmp("biliti", &aBuf[nBuf-6], 6) ){
260134 int ret = 0;
260139 if( nBuf>4 && 0==memcmp("ical", &aBuf[nBuf-4], 4) ){
260148 if( nBuf>4 && 0==memcmp("ness", &aBuf[nBuf-4], 4) ){
260156 if( nBuf>5 && 0==memcmp("icate", &aBuf[nBuf-5], 5) ){
260161 }else if( nBuf>5 && 0==memcmp("iciti", &aBuf[nBuf-5], 5) ){
260170 if( nBuf>3 && 0==memcmp("ful", &aBuf[nBuf-3], 3) ){
260178 if( nBuf>5 && 0==memcmp("ative", &aBuf[nBuf-5], 5) ){
260186 if( nBuf>5 && 0==memcmp("alize", &aBuf[nBuf-5], 5) ){
260200 int ret = 0;
260205 if( nBuf>3 && 0==memcmp("eed", &aBuf[nBuf-3], 3) ){
260210 }else if( nBuf>2 && 0==memcmp("ed", &aBuf[nBuf-2], 2) ){
260219 if( nBuf>3 && 0==memcmp("ing", &aBuf[nBuf-3], 3) ){
260275 if( fts5PorterStep1B2(aBuf, &nBuf)==0 ){
260277 if( fts5PorterIsVowel(c, 0)==0
260298 assert( nBuf>0 );
260367 TrigramTokenizer *pNew = 0;
260374 if( pNew==0 ){
260378 pNew->iFoldParam = 0;
260380 for(i=0; rc==SQLITE_OK && i<nArg; i+=2){
260382 if( 0==sqlite3_stricmp(azArg[i], "case_sensitive") ){
260383 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1] ){
260386 pNew->bFold = (zArg[0]=='0');
260388 }else if( 0==sqlite3_stricmp(azArg[i], "remove_diacritics") ){
260389 if( (zArg[0]!='0' && zArg[0]!='1' && zArg[0]!='2') || zArg[1] ){
260392 pNew->iFoldParam = (zArg[0]!='0') ? 2 : 0;
260399 if( pNew->iFoldParam!=0 && pNew->bFold==0 ){
260405 pNew = 0;
260429 const unsigned char *zEof = (zIn ? &zIn[nText] : 0);
260430 u32 iCode = 0;
260436 for(ii=0; ii<3; ii++){
260442 }while( iCode==0 );
260462 iCode = 0;
260467 }while( iCode==0 );
260470 rc = xToken(pCtx, 0, aBuf, zOut-aBuf, aStart[0], iNext);
260471 if( iCode==0 || rc!=SQLITE_OK ) break;
260482 aStart[0] = aStart[1];
260498 ** "trigram" tokenizer, case_sensitive=0 (the default) - FTS5_PATTERN_LIKE
260507 if( p->iFoldParam==0 ){
260520 return (p->nArg>=1 && 0==sqlite3_stricmp(p->azArg[0], "trigram"));
260540 for(i=0; rc==SQLITE_OK && i<ArraySize(aBuiltin); i++){
260545 0
260559 0
260597 0, 1797, 1848, 1859, 1891, 1928, 1940, 1995,
260614 #define HIBIT ((unsigned char)0x80)
260616 '\0', 'a', 'c', 'e', 'i', 'n',
260626 'o'|HIBIT, 'y', '\0', '\0', '\0', '\0',
260627 '\0', '\0', '\0', '\0', 'a', 'b',
260639 unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
260640 int iRes = 0;
260641 int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
260642 int iLo = 0;
260653 if( bComplex==0 && (aChar[iRes] & 0x80) ) return c;
260654 return (c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : ((int)aChar[iRes] & 0x7F);
260663 unsigned int mask0 = 0x08029FDF;
260664 unsigned int mask1 = 0x000361F8;
260665 if( c<768 || c>817 ) return 0;
260693 ** case equivalent is ((C + aiOff[flags>>1]) & 0xFFFF).
260708 {386, 1, 4}, {390, 44, 1}, {391, 0, 1},
260709 {393, 42, 2}, {395, 0, 1}, {398, 32, 1},
260710 {399, 38, 1}, {400, 40, 1}, {401, 0, 1},
260712 {407, 48, 1}, {408, 0, 1}, {412, 52, 1},
260714 {422, 60, 1}, {423, 0, 1}, {425, 60, 1},
260715 {428, 0, 1}, {430, 60, 1}, {431, 0, 1},
260717 {440, 0, 1}, {444, 0, 1}, {452, 2, 1},
260718 {453, 0, 1}, {455, 2, 1}, {456, 0, 1},
260722 {546, 1, 18}, {570, 70, 1}, {571, 0, 1},
260723 {573, 108, 1}, {574, 68, 1}, {577, 0, 1},
260726 {886, 0, 1}, {902, 18, 1}, {904, 16, 3},
260728 {931, 14, 9}, {962, 0, 1}, {975, 4, 1},
260732 {1015, 0, 1}, {1017, 152, 1}, {1018, 0, 1},
260748 {8579, 0, 1}, {9398, 10, 26}, {11264, 22, 47},
260749 {11360, 0, 1}, {11362, 88, 1}, {11363, 102, 1},
260752 {11378, 0, 1}, {11381, 0, 1}, {11390, 78, 2},
260753 {11392, 1, 100}, {11499, 1, 4}, {11506, 0, 1},
260756 {42878, 1, 10}, {42891, 0, 1}, {42893, 74, 1},
260781 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
260782 int iLo = 0;
260785 assert( c>aEntry[0].iCode );
260789 if( cmp>=0 ){
260797 assert( iRes>=0 && c>=aEntry[iRes].iCode );
260799 if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
260800 ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
260801 assert( ret>0 );
260818 aArray[0] = 1;
260819 switch( zCat[0] ){
260935 return 0;
260939 0, 1471, 1753, 1760, 1760, 1760, 1760, 1760, 1760, 1760,
260943 0, 32, 33, 36, 37, 40, 41, 42, 43, 44,
261090 65532, 0, 13, 40, 60, 63, 80, 128, 256, 263,
261118 63045, 63104, 63232, 0, 42710, 42752, 46900, 46912, 47133, 63488,
261119 1, 32, 256, 0, 65533,
261309 return 0;
261313 iKey = (iCode & 0xFFFF);
261325 if( iRes<0 ) return 0;
261326 if( iKey>=(aFts5UnicodeMap[iRes]+(aFts5UnicodeData[iRes]>>5)) ) return 0;
261327 ret = aFts5UnicodeData[iRes] & 0x1F;
261329 return ((iKey - aFts5UnicodeMap[iRes]) & 0x01) ? 5 : 9;
261333 int i = 0;
261334 int iTbl = 0;
261336 int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
261343 aAscii[0] = 0; /* 0x00 is never a token character */
261375 if (!(a&0x80))
261377 /* Values between 0 and 127 */
261386 if (!(b&0x80))
261389 a &= 0x7f;
261400 if (!(a&0x80))
261403 a &= (0x7f<<14)|(0x7f);
261404 b &= 0x7f;
261424 *v = ((u32)v64) & 0x7FFFFFFF;
261436 ** SLOT_2_0 A mask for (0x7f<<14) | 0x7f
261438 ** SLOT_4_2_0 A mask for (0x7f<<28) | SLOT_2_0
261440 #define SLOT_2_0 0x001fc07f
261441 #define SLOT_4_2_0 0xf01fc07f
261444 ** Read a 64-bit variable-length integer from memory starting at p[0].
261452 if (!(a&0x80))
261461 if (!(b&0x80))
261463 a &= 0x7f;
261471 assert( SLOT_2_0 == ((0x7f<<14) | (0x7f)) );
261472 assert( SLOT_4_2_0 == ((0xfU<<28) | (0x7f<<14) | (0x7f)) );
261478 if (!(a&0x80))
261481 b &= 0x7f;
261494 if (!(b&0x80))
261498 /* a &= (0x7f<<14)|(0x7f); */
261509 /* a &= (0x7f<<14)|(0x7f); */
261518 if (!(a&0x80))
261521 /* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
261522 /* b &= (0x7f<<14)|(0x7f); */
261539 if (!(b&0x80))
261542 /* b &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
261555 if (!(a&0x80))
261572 if (!(b&0x80))
261576 /* a &= (0x7f<<14)|(0x7f); */
261590 /* a &= (0x7f<<29)|(0x7f<<15)|(0xff); */
261597 b &= 0x7f;
261610 ** A = 0xxxxxxx 7 bits of data and one flag bit
261632 ** Write a 64-bit variable-length integer to memory starting at p[0].
261644 if( v & (((u64)0xff000000)<<32) ){
261647 for(i=7; i>=0; i--){
261648 p[i] = (u8)((v & 0x7f) | 0x80);
261653 n = 0;
261655 buf[n++] = (u8)((v & 0x7f) | 0x80);
261657 }while( v!=0 );
261658 buf[0] &= 0x7f;
261660 for(i=0, j=n-1; j>=0; j--, i++){
261667 if( v<=0x7f ){
261668 p[0] = v&0x7f;
261671 if( v<=0x3fff ){
261672 p[0] = ((v>>7)&0x7f)|0x80;
261673 p[1] = v&0x7f;
261681 #if 0
261773 #define FTS5_VOCAB_COL 0
261784 #define FTS5_VOCAB_TERM_EQ 0x0100
261785 #define FTS5_VOCAB_TERM_GE 0x0200
261786 #define FTS5_VOCAB_TERM_LE 0x0400
261788 #define FTS5_VOCAB_COLUSED_MASK 0xFF
261802 if( sqlite3_stricmp(zCopy, "col")==0 ){
261806 if( sqlite3_stricmp(zCopy, "row")==0 ){
261809 if( sqlite3_stricmp(zCopy, "instance")==0 ){
261847 ** argv[0] -> module name ("fts5vocab")
261876 Fts5VocabTable *pRet = 0;
261880 bDb = (argc==6 && strlen(argv[1])==4 && memcmp("temp", argv[1], 4)==0);
261882 if( argc!=5 && bDb==0 ){
261892 int eType = 0;
261896 assert( eType>=0 && eType<ArraySize(azSchema) );
261966 int nArg = 0;
261972 for(i=0; i<pInfo->nConstraint; i++){
261974 if( p->usable==0 ) continue;
261975 if( p->iColumn==0 ){ /* term column */
261984 if( iTermEq>=0 ){
261990 if( iTermGe>=0 ){
261995 if( iTermLe>=0 ){
262003 ** the "term" column (column 0). So if the user has requested this
262008 && pInfo->aOrderBy[0].iColumn==0
262009 && pInfo->aOrderBy[0].desc==0
262026 Fts5Table *pFts5 = 0;
262027 Fts5VocabCursor *pCsr = 0;
262029 sqlite3_stmt *pStmt = 0;
262030 char *zSql = 0;
262043 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pStmt, 0);
262046 assert( rc==SQLITE_OK || pStmt==0 );
262051 i64 iId = sqlite3_column_int64(pStmt, 0);
262054 pTab->bBusy = 0;
262057 if( pFts5==0 ){
262059 pStmt = 0;
262090 pCsr->rowid = 0;
262093 pCsr->pStruct = 0;
262094 pCsr->pIter = 0;
262097 pCsr->zLeTerm = 0;
262098 pCsr->bEof = 0;
262123 if( pCsr->nLeTerm>=0 ){
262126 if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
262143 assert( sqlite3Fts5IterEof(pIter)==0 );
262144 assert( pCsr->bEof==0 );
262148 pCsr->iInstPos = 0;
262149 pCsr->iInstOff = 0;
262196 assert( nTerm>=0 );
262197 if( pCsr->nLeTerm>=0 ){
262200 if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
262207 memset(pCsr->aCnt, 0, nCol * sizeof(i64));
262208 memset(pCsr->aDoc, 0, nCol * sizeof(i64));
262209 pCsr->iCol = 0;
262215 i64 iPos = 0; /* 64-bit position read from poslist */
262216 int iOff = 0; /* Current offset within position list */
262225 if( eDetail==FTS5_DETAIL_FULL && (pCsr->colUsed & 0x04) ){
262234 pCsr->aCnt[0]++;
262238 pCsr->aDoc[0]++;
262244 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){
262257 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff,&iPos) ){
262258 assert_nc( iPos>=0 && iPos<nCol );
262267 pCsr->aDoc[0]++;
262284 || (nTerm>0 && memcmp(zTerm, pCsr->term.p, nTerm))
262294 if( rc==SQLITE_OK && pCsr->bEof==0 && pTab->eType==FTS5_VOCAB_COL ){
262295 for(/* noop */; pCsr->iCol<nCol && pCsr->aDoc[pCsr->iCol]==0; pCsr->iCol++);
262318 int iVal = 0;
262320 const char *zTerm = 0;
262321 int nTerm = 0;
262323 sqlite3_value *pEq = 0;
262324 sqlite3_value *pGe = 0;
262325 sqlite3_value *pLe = 0;
262346 if( zCopy==0 ) zCopy = "";
262349 if( pCsr->zLeTerm==0 ){
262359 rc = sqlite3Fts5IndexQuery(pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
262394 i64 iVal = 0;
262396 if( iCol==0 ){
262415 iVal = pCsr->aDoc[0];
262417 iVal = pCsr->aCnt[0];
262432 if( ii>=0 && ii<pCsr->pFts5->pConfig->nCol ){
262449 if( iVal>0 ) sqlite3_result_int64(pCtx, iVal);
262482 /* xUpdate */ 0,
262483 /* xBegin */ 0,
262484 /* xSync */ 0,
262485 /* xCommit */ 0,
262486 /* xRollback */ 0,
262487 /* xFindFunction */ 0,
262488 /* xRename */ 0,
262489 /* xSavepoint */ 0,
262490 /* xRelease */ 0,
262491 /* xRollbackTo */ 0,
262492 /* xShadowName */ 0,
262493 /* xIntegrity */ 0
262497 return sqlite3_create_module_v2(db, "fts5vocab", &fts5Vocab, p, 0);
262592 #define STMT_COLUMN_SQL 0 /* SQL for the statement */
262615 if( pNew==0 ) return SQLITE_NOMEM;
262616 memset(pNew, 0, sizeof(*pNew));
262636 if( pCur==0 ) return SQLITE_NOMEM;
262637 memset(pCur, 0, sizeof(*pCur));
262644 StmtRow *pRow = 0;
262645 StmtRow *pNext = 0;
262650 pCur->pRow = 0;
262709 return pCur->pRow==0;
262724 sqlite3_stmt *p = 0;
262726 StmtRow **ppRow = 0;
262734 for(p=sqlite3_next_stmt(pCur->db, 0); p; p=sqlite3_next_stmt(pCur->db, p)){
262736 sqlite3_int64 nSql = zSql ? strlen(zSql)+1 : 0;
262739 if( pNew==0 ) return SQLITE_NOMEM;
262740 memset(pNew, 0, sizeof(StmtRow));
262749 p, SQLITE_STMTSTATUS_FULLSCAN_STEP, 0
262752 p, SQLITE_STMTSTATUS_SORT, 0
262755 p, SQLITE_STMTSTATUS_AUTOINDEX, 0
262758 p, SQLITE_STMTSTATUS_VM_STEP, 0
262761 p, SQLITE_STMTSTATUS_REPREPARE, 0
262764 p, SQLITE_STMTSTATUS_RUN, 0
262767 p, SQLITE_STMTSTATUS_MEMUSED, 0
262798 0, /* iVersion */
262799 0, /* xCreate */
262803 0, /* xDestroy */
262811 0, /* xUpdate */
262812 0, /* xBegin */
262813 0, /* xSync */
262814 0, /* xCommit */
262815 0, /* xRollback */
262816 0, /* xFindMethod */
262817 0, /* xRename */
262818 0, /* xSavepoint */
262819 0, /* xRelease */
262820 0, /* xRollbackTo */
262821 0, /* xShadowName */
262822 0 /* xIntegrity */
262830 rc = sqlite3_create_module(db, "sqlite_stmt", &stmtModule, 0);