Lines Matching +full:0 +full:x6000000
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 */
19189 #define SQLITE_IDXTYPE_APPDEF 0 /* Created using CREATE INDEX */
19222 #define SQLITE_TOKEN_QUOTED 0x1 /* Token is a quoted identifier. */
19223 #define SQLITE_TOKEN_KEYWORD 0x2 /* Token is a keyword. */
19420 #if SQLITE_MAX_EXPR_DEPTH>0
19425 ** 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 */
21482 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
21483 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
21484 #define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */
21485 #define SQLITE_ECEL_OMITREF 0x08 /* Omit if ExprList.u.x.iOrderByCol */
21490 #define LOCATE_VIEW 0x01
21491 #define LOCATE_NOERR 0x02
21613 # define sqlite3IsToplevel(p) ((p)->pToplevel==0)
21615 # define sqlite3TriggersExist(B,C,D,E,F) 0
21621 # define sqlite3TriggerList(X, Y) 0
21624 # define sqlite3TriggerColmask(A,B,C,D,E,F,G) 0
21625 # define sqlite3TriggerStepSrc(A,B) 0
21692 (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B)))
21694 B=(u32)*(A);if(B>=0x80)sqlite3GetVarint32((A),(u32*)&(B))
21696 (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\
21730 # define sqlite3IsMemdb(X) 0
21939 # define sqlite3VtabInSync(db) 0
21945 # define sqlite3GetVTable(X,Y) ((VTable*)0)
21966 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
21974 # define sqlite3ShadowTableName(A,B) 0
21975 # define sqlite3IsShadowTableOf(A,B,C) 0
22019 # define sqlite3CteNew(P,T,E,S) ((void*)0)
22021 # define sqlite3CteWithAdd(P,W,C) ((void*)0)
22023 # define sqlite3WithPush(x,y,z) ((void*)0)
22034 #define sqlite3UpsertNew(u,v,w,x,y,z) ((Upsert*)0)
22036 #define sqlite3UpsertDup(x,y) ((Upsert*)0)
22037 #define sqlite3UpsertOfIndex(x,y) ((Upsert*)0)
22038 #define sqlite3UpsertNextIsIPK(x) 0
22061 #define sqlite3FkOldmask(a,b) 0
22062 #define sqlite3FkRequired(a,b,c,d) 0
22063 #define sqlite3FkReferences(a) 0
22076 ** Available fault injectors. Should be numbered beginning with 0.
22078 #define SQLITE_FAULTINJECTOR_MALLOC 0
22105 #define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */
22106 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */
22107 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
22121 #if SQLITE_MAX_EXPR_DEPTH>0
22125 #define sqlite3SelectExprHeight(x) 0
22201 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
22202 #define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */
22203 #define MEMTYPE_PCACHE 0x04 /* Page cache allocations */
22208 #if SQLITE_MAX_WORKER_THREADS>0
22243 # define IS_STMT_SCANSTATUS(db) 0
22295 #define TIMER_ELAPSED ((sqlite_uint64)0)
23152 *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]); in sqlite3CompileOptions()
23185 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
23202 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 0x */
23241 1, 0, 0, 1, 1, 0, /* aLTb[]: Use when compare(A,B) less than zero */
23242 0, 1, 0, 1, 0, 1, /* aEQb[]: Use when compare(A,B) equals zero */
23243 1, 0, 1, 0, 0, 1 /* aGTb[]: Use when compare(A,B) greater than zero*/
23253 ** isspace() 0x01
23254 ** isalpha() 0x02
23255 ** isdigit() 0x04
23256 ** isalnum() 0x06
23257 ** isxdigit() 0x08
23258 ** toupper() 0x20
23259 ** SQLite identifier character 0x40 $, _, or non-ascii
23260 ** Quote character 0x80
23262 ** Bit 0x20 is set if the mapped character requires translation to upper
23265 ** is (x - 0x20). Therefore toupper() can be implemented as:
23267 ** (x & ~(map[x]&0x20))
23272 ** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
23275 ** part of an identifier is 0x46.
23278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
23279 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
23280 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
23281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
23282 0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80, /* 20..27 !"#$%&' */
23283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */
23284 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */
23285 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */
23287 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */
23288 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */
23289 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */
23290 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
23291 0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
23292 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */
23293 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */
23294 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */
23296 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */
23297 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 88..8f ........ */
23298 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 90..97 ........ */
23299 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 98..9f ........ */
23300 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a0..a7 ........ */
23301 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a8..af ........ */
23302 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b0..b7 ........ */
23303 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b8..bf ........ */
23305 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c0..c7 ........ */
23306 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c8..cf ........ */
23307 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d0..d7 ........ */
23308 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d8..df ........ */
23309 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e0..e7 ........ */
23310 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e8..ef ........ */
23311 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
23312 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
23320 ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
23327 # define SQLITE_USE_URI 0
23339 -DSQLITE_ALLOW_COVERING_INDEX_SCAN=0 option is deprecated.\
23353 ** threshold (in bytes). 0 means that statement journals are created and
23355 ** before 3.12.0). -1 means always keep the entire statement journal in
23403 0, /* bSmallMalloc */
23406 0, /* bJsonSelfcheck */
23408 0x7ffffffe, /* mxStrlen */
23409 0, /* neverCorrupt */
23412 {0,0,0,0,0,0,0,0}, /* m */
23413 {0,0,0,0,0,0,0,0,0}, /* mutex */
23414 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
23415 (void*)0, /* pHeap */
23416 0, /* nHeap */
23417 0, 0, /* mnHeap, mxHeap */
23420 (void*)0, /* pPage */
23421 0, /* szPage */
23423 0, /* mxParserStack */
23424 0, /* sharedCacheEnabled */
23427 0, /* isInit */
23428 0, /* inProgress */
23429 0, /* isMutexInit */
23430 0, /* isMallocInit */
23431 0, /* isPCacheInit */
23432 0, /* nRefInitMutex */
23433 0, /* pInitMutex */
23434 0, /* xLog */
23435 0, /* pLogArg */
23437 0, /* xSqllog */
23438 0, /* pSqllogArg */
23441 0, /* xVdbeBranch */
23442 0, /* pVbeBranchArg */
23448 0, /* xTestCallback */
23451 0, /* mNoVisibleRowid. 0 == allow rowid-in-view */
23453 0, /* bLocaltimeFault */
23454 0, /* xAltLocaltime */
23455 0x7ffffffe, /* iOnceResetThreshold */
23457 0, /* iPrngSeed */
23459 {0,0,0,0,0,0}, /* aTune */
23487 SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt = 0;
23491 ** The value of the "pending" byte must be 0x40000000 (1 byte past the
23504 ** 0x40000000 results in an incompatible database file format!
23509 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
23515 SQLITE_PRIVATE u32 sqlite3TreeTrace = 0;
23516 SQLITE_PRIVATE u32 sqlite3WhereTrace = 0;
23619 # define VDBE_DISPLAY_P4 0
23644 #define CURTYPE_BTREE 0
23684 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
23687 int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
23733 ((P)->eCurType==CURTYPE_PSEUDO && (P)->nullRow && (P)->seekResult==0)
23738 #define CACHE_STALE 0
23800 #define SQLITE_FRAME_MAGIC 0x879fb71e
23822 int n; /* Number of characters in string value, excluding '\0' */
23830 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
23872 ** MEM.u.i extra 0x00 bytes at the end.
23890 #define MEM_Undefined 0x0000 /* Value is undefined */
23891 #define MEM_Null 0x0001 /* Value is NULL (or a pointer) */
23892 #define MEM_Str 0x0002 /* Value is a string */
23893 #define MEM_Int 0x0004 /* Value is an integer */
23894 #define MEM_Real 0x0008 /* Value is a real number */
23895 #define MEM_Blob 0x0010 /* Value is a BLOB */
23896 #define MEM_IntReal 0x0020 /* MEM_Int that stringifies like MEM_Real */
23897 #define MEM_AffMask 0x003f /* Mask of affinity bits */
23901 #define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */
23902 /* 0x0080 // Available */
23903 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
23904 #define MEM_Term 0x0200 /* String in Mem.z is zero terminated */
23905 #define MEM_Zero 0x0400 /* Mem.i contains count of 0s appended to blob */
23906 #define MEM_Subtype 0x0800 /* Mem.eSubtype is valid */
23907 #define MEM_TypeMask 0x0dbf /* Mask of type bits */
23912 #define MEM_Dyn 0x1000 /* Need to call Mem.xDel() on Mem.z */
23913 #define MEM_Static 0x2000 /* Mem.z points to a static string */
23914 #define MEM_Ephem 0x4000 /* Mem.z points to an ephemeral string */
23915 #define MEM_Agg 0x8000 /* Mem.z points to an agg function context */
23921 (((X)->flags&(MEM_Agg|MEM_Dyn))!=0)
23934 && (X)->n==0 && (X)->u.nZero==0)
23945 #define memIsValid(M) ((M)->flags & MEM_AffMask)!=0
24006 ** instructions. A start value of 0 indicates an empty range.
24050 int iStatement; /* Statement number (or 0 if has no opened stmt) */
24085 bft explain:2; /* 0: normal, 1: EXPLAIN, 2: EXPLAIN QUERY PLAN */
24115 #define VDBE_INIT_STATE 0 /* Prepared statement under construction */
24141 u8 keyinfoSpace[SZ_KEYINFO(0)]; /* Space to hold pKeyinfo[0] content */
24293 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
24307 # define sqlite3VdbeCheckFk(p,i) 0
24321 #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
24344 } sqlite3Stat = { {0,}, {0,} };
24351 0, /* SQLITE_STATUS_MEMORY_USED */
24354 0, /* SQLITE_STATUS_SCRATCH_USED */
24355 0, /* SQLITE_STATUS_SCRATCH_OVERFLOW */
24356 0, /* SQLITE_STATUS_MALLOC_SIZE */
24357 0, /* SQLITE_STATUS_PARSER_STACK */
24359 0, /* SQLITE_STATUS_SCRATCH_SIZE */
24360 0, /* SQLITE_STATUS_MALLOC_COUNT */
24372 # define wsdStat x[0]
24384 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); in sqlite3StatusValue()
24385 assert( op>=0 && op<ArraySize(statMutex) ); in sqlite3StatusValue()
24404 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); in sqlite3StatusUp()
24405 assert( op>=0 && op<ArraySize(statMutex) ); in sqlite3StatusUp()
24415 assert( N>=0 ); in sqlite3StatusDown()
24416 assert( op>=0 && op<ArraySize(statMutex) ); in sqlite3StatusDown()
24419 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); in sqlite3StatusDown()
24430 assert( X>=0 ); in sqlite3StatusHighwater()
24432 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); in sqlite3StatusHighwater()
24433 assert( op>=0 && op<ArraySize(statMutex) ); in sqlite3StatusHighwater()
24455 if( op<0 || op>=ArraySize(wsdStat.nowValue) ){ in sqlite3_status64()
24459 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; in sqlite3_status64()
24469 (void)pMutex; /* Prevent warning when SQLITE_THREADSAFE=0 */ in sqlite3_status64()
24473 sqlite3_int64 iCur = 0, iHwtr = 0; in sqlite3_status()
24476 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; in sqlite3_status()
24479 if( rc==0 ){ in sqlite3_status()
24490 u32 cnt = 0; in countLookasideSlots()
24525 if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){ in sqlite3_db_status()
24539 db->lookaside.pFree = 0; in sqlite3_db_status()
24547 db->lookaside.pSmallFree = 0; in sqlite3_db_status()
24560 assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 ); in sqlite3_db_status()
24562 *pCurrent = 0; in sqlite3_db_status()
24565 db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0; in sqlite3_db_status()
24577 int totalUsed = 0; in sqlite3_db_status()
24580 for(i=0; i<db->nDb; i++){ in sqlite3_db_status()
24593 *pHighwater = 0; in sqlite3_db_status()
24604 int nByte = 0; /* Used to accumulate return value */ in sqlite3_db_status()
24610 for(i=0; i<db->nDb; i++){ in sqlite3_db_status()
24612 if( ALWAYS(pSchema!=0) ){ in sqlite3_db_status()
24634 db->pnBytesFreed = 0; in sqlite3_db_status()
24638 *pHighwater = 0; in sqlite3_db_status()
24650 int nByte = 0; /* Used to accumulate return value */ in sqlite3_db_status()
24659 db->pnBytesFreed = 0; in sqlite3_db_status()
24661 *pHighwater = 0; /* IMP: R-64479-57858 */ in sqlite3_db_status()
24679 u64 nRet = 0; in sqlite3_db_status()
24683 for(i=0; i<db->nDb; i++){ in sqlite3_db_status()
24689 *pHighwater = 0; /* IMP: R-42420-56072 */ in sqlite3_db_status()
24692 *pCurrent = (int)nRet & 0x7fffffff; in sqlite3_db_status()
24701 *pHighwater = 0; /* IMP: R-11967-56545 */ in sqlite3_db_status()
24702 *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0; in sqlite3_db_status()
24757 ** ISBN 0-943396-61-1
24809 ** B: minimum value. Always "0" or "1".
24832 int cnt = 0; in getDigits()
24836 char N = zFormat[0] - '0'; in getDigits()
24837 char min = zFormat[1] - '0'; in getDigits()
24838 int val = 0; in getDigits()
24844 val = 0; in getDigits()
24849 val = val*10 + *zDate - '0'; in getDigits()
24852 if( val<(int)min || val>(int)max || (nextC!=0 && nextC!=*zDate) ){ in getDigits()
24876 ** of change in p->tz and return 0. If a parser error occurs,
24882 int sgn = 0; in parseTimezone()
24886 p->tz = 0; in parseTimezone()
24894 p->isLocal = 0; in parseTimezone()
24898 return c!=0; in parseTimezone()
24908 return *zDate!=0; in parseTimezone()
24916 ** Return 1 if there is a parsing error and 0 on success.
24935 ms = ms*10.0 + *zDate - '0'; in parseHhMmSs()
24945 s = 0; in parseHhMmSs()
24947 p->validJD = 0; in parseHhMmSs()
24948 p->rawS = 0; in parseHhMmSs()
24954 return 0; in parseHhMmSs()
24961 memset(p, 0, sizeof(*p)); in datetimeError()
25002 p->validYMD = 0; in computeJD()
25003 p->validHMS = 0; in computeJD()
25004 p->tz = 0; in computeJD()
25006 p->isLocal = 0; in computeJD()
25019 assert( p->D>=0 && p->D<=31 ); in computeFloor()
25020 assert( p->M>=0 && p->M<=12 ); in computeFloor()
25022 p->nFloor = 0; in computeFloor()
25023 }else if( (1<<p->M) & 0x15aa ){ in computeFloor()
25024 p->nFloor = 0; in computeFloor()
25027 }else if( p->Y%4!=0 || (p->Y%100==0 && p->Y%400!=0) ){ in computeFloor()
25042 ** Write the result into the DateTime structure and return 0
25049 if( zDate[0]=='-' ){ in parseYyyyMmDd()
25053 neg = 0; in parseYyyyMmDd()
25060 if( parseHhMmSs(zDate, p)==0 ){ in parseYyyyMmDd()
25062 }else if( *zDate==0 ){ in parseYyyyMmDd()
25063 p->validHMS = 0; in parseYyyyMmDd()
25067 p->validJD = 0; in parseYyyyMmDd()
25076 return 0; in parseYyyyMmDd()
25089 if( p->iJD>0 ){ in setDateTimeToCurrent()
25092 p->isLocal = 0; in setDateTimeToCurrent()
25094 return 0; in setDateTimeToCurrent()
25137 if( parseYyyyMmDd(zDate,p)==0 ){ in parseDateOrTime()
25138 return 0; in parseDateOrTime()
25139 }else if( parseHhMmSs(zDate, p)==0 ){ in parseDateOrTime()
25140 return 0; in parseDateOrTime()
25141 }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){ in parseDateOrTime()
25143 }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8)>0 ){ in parseDateOrTime()
25145 return 0; in parseDateOrTime()
25146 }else if( (sqlite3StrICmp(zDate,"subsec")==0 in parseDateOrTime()
25147 || sqlite3StrICmp(zDate,"subsecond")==0) in parseDateOrTime()
25162 #define INT_464269060799999 ((((i64)0x1a640)<<32)|0x1072fdff)
25170 return iJD>=0 && iJD<=INT_464269060799999; in validJulianDay()
25214 p->rawS = 0; in computeHMS()
25230 p->validYMD = 0; in clearYMD_HMS_TZ()
25231 p->validHMS = 0; in clearYMD_HMS_TZ()
25232 p->tz = 0; in clearYMD_HMS_TZ()
25257 ** is available. This routine returns 0 on success and
25273 #if SQLITE_THREADSAFE>0 in osLocaltime()
25280 if( sqlite3GlobalConfig.xAltLocaltime!=0 in osLocaltime()
25281 && 0==sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm) in osLocaltime()
25285 pX = 0; in osLocaltime()
25290 #if SQLITE_THREADSAFE>0 in osLocaltime()
25293 rc = pX==0; in osLocaltime()
25297 if( sqlite3GlobalConfig.xAltLocaltime!=0 ){ in osLocaltime()
25305 rc = localtime_r(t, pTm)==0; in osLocaltime()
25328 memset(&sLocal, 0, sizeof(sLocal)); in toLocaltime()
25343 x.validJD = 0; in toLocaltime()
25347 iYearDiff = 0; in toLocaltime()
25362 p->validJD = 0; in toLocaltime()
25363 p->rawS = 0; in toLocaltime()
25364 p->tz = 0; in toLocaltime()
25365 p->isError = 0; in toLocaltime()
25384 /* 0 */ { 6, "second", 4.6427e+14, 1.0 },
25399 p->rawS = 0; in autoAdjustDate()
25407 p->rawS = 0; in autoAdjustDate()
25436 ** Return 0 on success and 1 if there is any kind of error. If the error
25450 switch(sqlite3UpperToLower[(u8)z[0]] ){ in parseModifier()
25458 if( sqlite3_stricmp(z, "auto")==0 ){ in parseModifier()
25461 rc = 0; in parseModifier()
25473 if( sqlite3_stricmp(z, "ceiling")==0 ){ in parseModifier()
25476 rc = 0; in parseModifier()
25477 p->nFloor = 0; in parseModifier()
25488 if( sqlite3_stricmp(z, "floor")==0 ){ in parseModifier()
25492 rc = 0; in parseModifier()
25503 ** SQLite (0..5373484.5) then the result will be NULL. in parseModifier()
25505 if( sqlite3_stricmp(z, "julianday")==0 ){ in parseModifier()
25508 rc = 0; in parseModifier()
25509 p->rawS = 0; in parseModifier()
25521 if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){ in parseModifier()
25523 p->isUtc = 0; in parseModifier()
25536 if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){ in parseModifier()
25543 p->rawS = 0; in parseModifier()
25544 rc = 0; in parseModifier()
25548 else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){ in parseModifier()
25549 if( p->isUtc==0 ){ in parseModifier()
25552 int cnt = 0; /* Safety to prevent infinite loop */ in parseModifier()
25557 iErr = 0; in parseModifier()
25560 memset(&new, 0, sizeof(new)); in parseModifier()
25569 memset(p, 0, sizeof(*p)); in parseModifier()
25573 p->isLocal = 0; in parseModifier()
25585 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the in parseModifier()
25588 if( sqlite3_strnicmp(z, "weekday ", 8)==0 in parseModifier()
25589 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)>0 in parseModifier()
25593 p->tz = 0; in parseModifier()
25594 p->validJD = 0; in parseModifier()
25600 rc = 0; in parseModifier()
25617 if( sqlite3_strnicmp(z, "start of ", 9)!=0 ){ in parseModifier()
25618 if( sqlite3_stricmp(z, "subsec")==0 in parseModifier()
25619 || sqlite3_stricmp(z, "subsecond")==0 in parseModifier()
25622 rc = 0; in parseModifier()
25630 p->h = p->m = 0; in parseModifier()
25632 p->rawS = 0; in parseModifier()
25633 p->tz = 0; in parseModifier()
25634 p->validJD = 0; in parseModifier()
25635 if( sqlite3_stricmp(z,"month")==0 ){ in parseModifier()
25637 rc = 0; in parseModifier()
25638 }else if( sqlite3_stricmp(z,"year")==0 ){ in parseModifier()
25641 rc = 0; in parseModifier()
25642 }else if( sqlite3_stricmp(z,"day")==0 ){ in parseModifier()
25643 rc = 0; in parseModifier()
25649 case '0': in parseModifier()
25663 char z0 = z[0]; in parseModifier()
25672 if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){ in parseModifier()
25679 ** the range 0-11 and DD is limited to 0-30. in parseModifier()
25689 if( M>=12 ) break; /* M range 0..11 */ in parseModifier()
25690 if( D>=31 ) break; /* D range 0..30 */ in parseModifier()
25692 p->validJD = 0; in parseModifier()
25701 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; in parseModifier()
25706 p->validHMS = 0; in parseModifier()
25707 p->validYMD = 0; in parseModifier()
25709 if( z[11]==0 ){ in parseModifier()
25710 rc = 0; in parseModifier()
25732 memset(&tx, 0, sizeof(tx)); in parseModifier()
25742 rc = 0; in parseModifier()
25755 rRounder = r<0 ? -0.5 : +0.5; in parseModifier()
25756 p->nFloor = 0; in parseModifier()
25757 for(i=0; i<ArraySize(aXformType); i++){ in parseModifier()
25759 && sqlite3_strnicmp(aXformType[i].zName, z, n)==0 in parseModifier()
25764 assert( strcmp(aXformType[4].zName,"month")==0 ); in parseModifier()
25767 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; in parseModifier()
25771 p->validJD = 0; in parseModifier()
25777 assert( strcmp(aXformType[5].zName,"year")==0 ); in parseModifier()
25779 assert( p->M>=0 && p->M<=12 ); in parseModifier()
25782 p->validJD = 0; in parseModifier()
25789 rc = 0; in parseModifier()
25804 ** Process time function arguments. argv[0] is a date-time stamp.
25806 ** the resulting time into the DateTime structure p. Return 0
25809 ** If there are zero parameters (if even argv[0] is undefined)
25810 ** then assume a default value of "now" for argv[0].
25821 memset(p, 0, sizeof(*p)); in isDate()
25822 if( argc==0 ){ in isDate()
25826 if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT in isDate()
25828 setRawDateNumber(p, sqlite3_value_double(argv[0])); in isDate()
25830 z = sqlite3_value_text(argv[0]); in isDate()
25838 if( z==0 || parseModifier(context, (char*)z, n, p, i) ) return 1; in isDate()
25846 p->validYMD = 0; in isDate()
25848 return 0; in isDate()
25868 if( isDate(context, argc, argv, &x)==0 ){ in juliandayFunc()
25886 if( isDate(context, argc, argv, &x)==0 ){ in unixepochFunc()
25907 if( isDate(context, argc, argv, &x)==0 ){ in datetimeFunc()
25912 if( Y<0 ) Y = -Y; in datetimeFunc()
25913 zBuf[1] = '0' + (Y/1000)%10; in datetimeFunc()
25914 zBuf[2] = '0' + (Y/100)%10; in datetimeFunc()
25915 zBuf[3] = '0' + (Y/10)%10; in datetimeFunc()
25916 zBuf[4] = '0' + (Y)%10; in datetimeFunc()
25918 zBuf[6] = '0' + (x.M/10)%10; in datetimeFunc()
25919 zBuf[7] = '0' + (x.M)%10; in datetimeFunc()
25921 zBuf[9] = '0' + (x.D/10)%10; in datetimeFunc()
25922 zBuf[10] = '0' + (x.D)%10; in datetimeFunc()
25924 zBuf[12] = '0' + (x.h/10)%10; in datetimeFunc()
25925 zBuf[13] = '0' + (x.h)%10; in datetimeFunc()
25927 zBuf[15] = '0' + (x.m/10)%10; in datetimeFunc()
25928 zBuf[16] = '0' + (x.m)%10; in datetimeFunc()
25932 zBuf[18] = '0' + (s/10000)%10; in datetimeFunc()
25933 zBuf[19] = '0' + (s/1000)%10; in datetimeFunc()
25935 zBuf[21] = '0' + (s/100)%10; in datetimeFunc()
25936 zBuf[22] = '0' + (s/10)%10; in datetimeFunc()
25937 zBuf[23] = '0' + (s)%10; in datetimeFunc()
25938 zBuf[24] = 0; in datetimeFunc()
25942 zBuf[18] = '0' + (s/10)%10; in datetimeFunc()
25943 zBuf[19] = '0' + (s)%10; in datetimeFunc()
25944 zBuf[20] = 0; in datetimeFunc()
25947 if( x.Y<0 ){ in datetimeFunc()
25948 zBuf[0] = '-'; in datetimeFunc()
25967 if( isDate(context, argc, argv, &x)==0 ){ in timeFunc()
25971 zBuf[0] = '0' + (x.h/10)%10; in timeFunc()
25972 zBuf[1] = '0' + (x.h)%10; in timeFunc()
25974 zBuf[3] = '0' + (x.m/10)%10; in timeFunc()
25975 zBuf[4] = '0' + (x.m)%10; in timeFunc()
25979 zBuf[6] = '0' + (s/10000)%10; in timeFunc()
25980 zBuf[7] = '0' + (s/1000)%10; in timeFunc()
25982 zBuf[9] = '0' + (s/100)%10; in timeFunc()
25983 zBuf[10] = '0' + (s/10)%10; in timeFunc()
25984 zBuf[11] = '0' + (s)%10; in timeFunc()
25985 zBuf[12] = 0; in timeFunc()
25989 zBuf[6] = '0' + (s/10)%10; in timeFunc()
25990 zBuf[7] = '0' + (s)%10; in timeFunc()
25991 zBuf[8] = 0; in timeFunc()
26009 if( isDate(context, argc, argv, &x)==0 ){ in dateFunc()
26014 if( Y<0 ) Y = -Y; in dateFunc()
26015 zBuf[1] = '0' + (Y/1000)%10; in dateFunc()
26016 zBuf[2] = '0' + (Y/100)%10; in dateFunc()
26017 zBuf[3] = '0' + (Y/10)%10; in dateFunc()
26018 zBuf[4] = '0' + (Y)%10; in dateFunc()
26020 zBuf[6] = '0' + (x.M/10)%10; in dateFunc()
26021 zBuf[7] = '0' + (x.M)%10; in dateFunc()
26023 zBuf[9] = '0' + (x.D/10)%10; in dateFunc()
26024 zBuf[10] = '0' + (x.D)%10; in dateFunc()
26025 zBuf[11] = 0; in dateFunc()
26026 if( x.Y<0 ){ in dateFunc()
26027 zBuf[0] = '-'; in dateFunc()
26041 ** Jan01 = 0, Jan02 = 1, ..., Jan31 = 30, Feb01 = 31, ...
26049 jan01.validJD = 0; in daysAfterJan01()
26062 ** 0=Monday, 1=Tuesday, 2=Wednesday, ..., 6=Sunday.
26075 ** 0=Sunday, 1=Monday, 2=Tuesday, ..., 6=Saturday
26094 ** %k hour 0-24 (leading zero converted to space)
26108 ** %w day of week 0-6 Sunday==0, Monday==1
26127 if( argc==0 ) return; in strftimeFunc()
26128 zFmt = (const char*)sqlite3_value_text(argv[0]); in strftimeFunc()
26129 if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return; in strftimeFunc()
26131 sqlite3StrAccumInit(&sRes, 0, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); in strftimeFunc()
26135 for(i=j=0; zFmt[i]; i++){ in strftimeFunc()
26164 y.validYMD = 0; in strftimeFunc()
26182 if( h==0 ) h = 12; in strftimeFunc()
26234 case 'w': { /* Day of week. 0 to 6. Sunday==0, Monday==1 */ in strftimeFunc()
26235 char c = (char)daysAfterSunday(&x) + '0'; in strftimeFunc()
26236 if( c=='0' && cf=='u' ) c = '7'; in strftimeFunc()
26250 y.validYMD = 0; in strftimeFunc()
26289 timeFunc(context, 0, 0); in ctimeFunc()
26303 dateFunc(context, 0, 0); in cdateFunc()
26333 if( isDate(context, 1, &argv[0], &d1) ) return; in timediffFunc()
26342 d2.validJD = 0; in timediffFunc()
26346 if( M<0 ){ in timediffFunc()
26350 if( M!=0 ){ in timediffFunc()
26352 d2.validJD = 0; in timediffFunc()
26357 if( M<0 ){ in timediffFunc()
26366 d2.validJD = 0; in timediffFunc()
26376 d2.validJD = 0; in timediffFunc()
26380 if( M<0 ){ in timediffFunc()
26384 if( M!=0 ){ in timediffFunc()
26386 d2.validJD = 0; in timediffFunc()
26391 if( M<0 ){ in timediffFunc()
26400 d2.validJD = 0; in timediffFunc()
26408 sqlite3StrAccumInit(&sRes, 0, 0, 0, 100); in timediffFunc()
26426 datetimeFunc(context, 0, 0); in ctimestampFunc()
26458 if( iT<=0 ) return; in currentTimeFunc()
26488 if( isDate(context, argc, argv, &x)==0 ){ in datedebugFunc()
26513 PURE_DATE(julianday, -1, 0, 0, juliandayFunc ), in sqlite3RegisterDateTimeFunctions()
26514 PURE_DATE(unixepoch, -1, 0, 0, unixepochFunc ), in sqlite3RegisterDateTimeFunctions()
26515 PURE_DATE(date, -1, 0, 0, dateFunc ), in sqlite3RegisterDateTimeFunctions()
26516 PURE_DATE(time, -1, 0, 0, timeFunc ), in sqlite3RegisterDateTimeFunctions()
26517 PURE_DATE(datetime, -1, 0, 0, datetimeFunc ), in sqlite3RegisterDateTimeFunctions()
26518 PURE_DATE(strftime, -1, 0, 0, strftimeFunc ), in sqlite3RegisterDateTimeFunctions()
26519 PURE_DATE(timediff, 2, 0, 0, timediffFunc ), in sqlite3RegisterDateTimeFunctions()
26521 PURE_DATE(datedebug, -1, 0, 0, datedebugFunc ), in sqlite3RegisterDateTimeFunctions()
26523 DFUNCTION(current_time, 0, 0, 0, ctimeFunc ), in sqlite3RegisterDateTimeFunctions()
26524 DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc), in sqlite3RegisterDateTimeFunctions()
26525 DFUNCTION(current_date, 0, 0, 0, cdateFunc ), in sqlite3RegisterDateTimeFunctions()
26527 STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc), in sqlite3RegisterDateTimeFunctions()
26528 STR_FUNCTION(current_date, 0, "%Y-%m-%d", 0, currentTimeFunc), in sqlite3RegisterDateTimeFunctions()
26529 STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc), in sqlite3RegisterDateTimeFunctions()
26560 SQLITE_API int sqlite3_io_error_hit = 0; /* Total number of I/O Errors */
26561 SQLITE_API int sqlite3_io_error_hardhit = 0; /* Number of non-benign errors */
26562 SQLITE_API int sqlite3_io_error_pending = 0; /* Count down to first I/O error */
26563 SQLITE_API int sqlite3_io_error_persist = 0; /* True if I/O errors persist */
26564 SQLITE_API int sqlite3_io_error_benign = 0; /* True if errors are benign */
26565 SQLITE_API int sqlite3_diskfull_pending = 0;
26566 SQLITE_API int sqlite3_diskfull = 0;
26573 SQLITE_API int sqlite3_open_file_count = 0;
26621 pId->pMethods = 0; in sqlite3OsClose()
26666 if( id->pMethods==0 ) return SQLITE_NOTFOUND; in sqlite3OsFileControl()
26702 if( NEVER(id->pMethods==0) ) return 0; in sqlite3OsDeviceCharacteristics()
26727 #if SQLITE_MAX_MMAP_SIZE>0
26739 *pp = 0; in sqlite3OsFetch()
26759 DO_OS_MALLOC_TEST(0); in sqlite3OsOpen()
26760 /* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed in sqlite3OsOpen()
26765 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut); in sqlite3OsOpen()
26766 assert( rc==SQLITE_OK || pFile->pMethods==0 ); in sqlite3OsOpen()
26770 DO_OS_MALLOC_TEST(0); in sqlite3OsDelete()
26771 assert( dirSync==0 || dirSync==1 ); in sqlite3OsDelete()
26772 return pVfs->xDelete!=0 ? pVfs->xDelete(pVfs, zPath, dirSync) : SQLITE_OK; in sqlite3OsDelete()
26780 DO_OS_MALLOC_TEST(0); in sqlite3OsAccess()
26789 DO_OS_MALLOC_TEST(0); in sqlite3OsFullPathname()
26790 zPathOut[0] = 0; in sqlite3OsFullPathname()
26795 assert( zPath!=0 ); in sqlite3OsDlOpen()
26811 memset(zBufOut, 0, nByte); in sqlite3OsRandomness()
26824 return pVfs->xGetLastError ? pVfs->xGetLastError(pVfs, 0, 0) : 0; in sqlite3OsGetLastError()
26858 *ppFile = 0; in sqlite3OsOpenMalloc()
26863 *ppFile = 0; in sqlite3OsOpenMalloc()
26866 assert( *ppFile!=0 || rc!=SQLITE_OK ); in sqlite3OsOpenMalloc()
26883 if( p==0 ) return SQLITE_NOMEM_BKPT; in sqlite3OsInit()
26891 static sqlite3_vfs * SQLITE_WSD vfsList = 0;
26899 sqlite3_vfs *pVfs = 0; in sqlite3_vfs_find()
26905 if( rc ) return 0; in sqlite3_vfs_find()
26912 if( zVfs==0 ) break; in sqlite3_vfs_find()
26913 if( strcmp(zVfs, pVfs->zName)==0 ) break; in sqlite3_vfs_find()
26924 if( pVfs==0 ){ in vfsUnlink()
26951 if( pVfs==0 ) return SQLITE_MISUSE_BKPT; in sqlite3_vfs_register()
26957 if( makeDflt || vfsList==0 ){ in sqlite3_vfs_register()
27002 ** and returns 0).
27024 } sqlite3Hooks = { 0, 0 };
27035 # define wsdHooks x[0]
27107 static void *sqlite3MemMalloc(int nByte){ return 0; } in sqlite3MemMalloc()
27109 static void *sqlite3MemRealloc(void *pPrior, int nByte){ return 0; } in sqlite3MemRealloc()
27110 static int sqlite3MemSize(void *pPrior){ return 0; } in sqlite3MemSize()
27130 0 in sqlite3MemSetDefault()
27262 ** For this low-level routine, we are guaranteed that nByte>0 because
27263 ** cases of nByte<=0 will be intercepted and dealt with by higher level
27271 if( p==0 ){ in sqlite3MemMalloc()
27272 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3MemMalloc()
27278 assert( nByte>0 ); in sqlite3MemMalloc()
27282 p[0] = nByte; in sqlite3MemMalloc()
27285 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3MemMalloc()
27296 ** For this low-level routine, we already know that pPrior!=0 since
27297 ** cases where pPrior==0 will have been intercepted and dealt with
27305 assert( pPrior!=0 ); in sqlite3MemFree()
27317 assert( pPrior!=0 ); in sqlite3MemSize()
27321 assert( pPrior!=0 ); in sqlite3MemSize()
27324 return (int)p[0]; in sqlite3MemSize()
27332 ** For this low-level interface, we know that pPrior!=0. Cases where
27333 ** pPrior==0 while have been intercepted by higher-level routine and
27334 ** redirected to xMalloc. Similarly, we know that nByte>0 because
27335 ** cases where nByte<=0 will have been intercepted by higher-level
27341 if( p==0 ){ in sqlite3MemRealloc()
27342 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3MemRealloc()
27350 assert( pPrior!=0 && nByte>0 ); in sqlite3MemRealloc()
27355 p[0] = nByte; in sqlite3MemRealloc()
27358 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3MemRealloc()
27386 sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0); in sqlite3MemInit()
27393 _sqliteZone_ = malloc_create_zone(4096, 0); in sqlite3MemInit()
27424 0 in sqlite3MemSetDefault()
27492 u8 nTitle; /* Bytes of title; includes '\0' */
27500 #define FOREGUARD 0x80F5E153
27501 #define REARGUARD 0xE4676B53
27536 int nTitle; /* Bytes of zTitle to save. Includes '\0' and padding */
27566 if( increment>0 ){ in adjustStats()
27574 assert( mem.nCurrent[i]>=0 ); in adjustStats()
27601 while( nReserve-- > p->iSize ) assert( pU8[nReserve]==0x65 ); in sqlite3MemsysGetHeader()
27611 return 0; in sqlite3MemSize()
27622 assert( (sizeof(struct MemBlockHdr)&7) == 0 ); in sqlite3MemInit()
27636 mem.mutex = 0; in sqlite3MemShutdown()
27656 x = (x>>1) ^ (-(int)(x&1) & 0xd0000001); in randomFill()
27663 while( nByte-- > 0 ){ in randomFill()
27664 x = (x>>1) ^ (-(int)(x&1) & 0xd0000001); in randomFill()
27667 *(pBuf++) = r & 0xff; in randomFill()
27679 void *p = 0; in sqlite3MemMalloc()
27683 assert( mem.disallow==0 ); in sqlite3MemMalloc()
27692 pHdr->pNext = 0; in sqlite3MemMalloc()
27708 assert(pBt[0]); in sqlite3MemMalloc()
27713 pHdr->nBacktrace = 0; in sqlite3MemMalloc()
27723 memset(((char*)pInt)+nByte, 0x65, nReserve-nByte); in sqlite3MemMalloc()
27737 assert( sqlite3GlobalConfig.bMemstat || sqlite3GlobalConfig.bCoreMutex==0 in sqlite3MemFree()
27738 || mem.mutex!=0 ); in sqlite3MemFree()
27778 assert( mem.disallow==0 ); in sqlite3MemRealloc()
27779 assert( (nByte & 7)==0 ); /* EV: R-46199-30249 */ in sqlite3MemRealloc()
27805 0 in sqlite3MemSetDefault()
27837 if( (pHdr->eType&eType)==0 ){ in sqlite3MemdebugHasType()
27838 rc = 0; in sqlite3MemdebugHasType()
27859 if( (pHdr->eType&eType)!=0 ){ in sqlite3MemdebugNoType()
27860 rc = 0; in sqlite3MemdebugNoType()
27872 if( depth<0 ){ depth = 0; } in sqlite3MemdebugBacktrace()
27874 depth = (depth+1)&0xfe; in sqlite3MemdebugBacktrace()
27890 mem.zTitle[n] = 0; in sqlite3MemdebugSettitle()
27914 if( out==0 ){ in sqlite3MemdebugDump()
27933 for(i=0; i<NCSIZE-1; i++){ in sqlite3MemdebugDump()
27952 int nTotal = 0; in sqlite3MemdebugMallocCount()
27953 for(i=0; i<NCSIZE; i++){ in sqlite3MemdebugMallocCount()
28031 ** A chunk index of 0 means "no such chunk" and is the equivalent
28089 ** of the current key chunk. iKeyBlk is 0 if there is no key chunk.
28114 if( prev==0 ){ in memsys3UnlinkFromList()
28122 mem3.aPool[i].u.list.next = 0; in memsys3UnlinkFromList()
28123 mem3.aPool[i].u.list.prev = 0; in memsys3UnlinkFromList()
28133 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 ); in memsys3Unlink()
28153 mem3.aPool[i].u.list.prev = 0; in memsys3LinkIntoList()
28168 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 ); in memsys3Link()
28186 if( sqlite3GlobalConfig.bMemstat==0 && mem3.mutex==0 ){ in memsys3Enter()
28205 mem3.alarmBusy = 0; in memsys3OutOfMemory()
28231 ** is not large enough, return 0.
28239 mem3.iKeyBlk = 0; in memsys3FromKeyBlk()
28240 mem3.szKeyBlk = 0; in memsys3FromKeyBlk()
28241 mem3.mnKeyBlk = 0; in memsys3FromKeyBlk()
28282 for(i=*pRoot; i>0; i=iNext){ in memsys3Merge()
28285 assert( (size&1)==0 ); in memsys3Merge()
28286 if( (size&2)==0 ){ in memsys3Merge()
28338 if( i>0 ){ in memsys3MallocUnsafe()
28344 for(i=mem3.aiHash[hash]; i>0; i=mem3.aPool[i].u.list.next){ in memsys3MallocUnsafe()
28372 mem3.iKeyBlk = 0; in memsys3MallocUnsafe()
28373 mem3.szKeyBlk = 0; in memsys3MallocUnsafe()
28375 for(i=0; i<N_HASH; i++){ in memsys3MallocUnsafe()
28378 for(i=0; i<MX_SMALL-1; i++){ in memsys3MallocUnsafe()
28390 return 0; in memsys3MallocUnsafe()
28416 while( (mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x&2)==0 ){ in memsys3FreeUnsafe()
28426 while( (mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x&1)==0 ){ in memsys3FreeUnsafe()
28442 assert( p!=0 ); in memsys3Size()
28444 assert( (pBlock[-1].u.hdr.size4x&1)!=0 ); in memsys3Size()
28464 assert( nBytes>0 ); /* malloc.c filters out 0 byte requests */ in memsys3Malloc()
28487 if( pPrior==0 ){ in memsys3Realloc()
28490 if( nBytes<=0 ){ in memsys3Realloc()
28492 return 0; in memsys3Realloc()
28530 mem3.aPool[0].u.hdr.size4x = (mem3.szKeyBlk<<2) + 2; in memsys3Init()
28542 mem3.mutex = 0; in memsys3Shutdown()
28557 if( zFilename==0 || zFilename[0]==0 ){ in sqlite3Memsys3Dump()
28561 if( out==0 ){ in sqlite3Memsys3Dump()
28573 assert( 0 ); in sqlite3Memsys3Dump()
28576 if( (size&1)==0 && mem3.aPool[i+size/4-1].u.hdr.prevSize!=size/4 ){ in sqlite3Memsys3Dump()
28578 assert( 0 ); in sqlite3Memsys3Dump()
28583 assert( 0 ); in sqlite3Memsys3Dump()
28593 for(i=0; i<MX_SMALL-1; i++){ in sqlite3Memsys3Dump()
28594 if( mem3.aiSmall[i]==0 ) continue; in sqlite3Memsys3Dump()
28596 for(j = mem3.aiSmall[i]; j>0; j=mem3.aPool[j].u.list.next){ in sqlite3Memsys3Dump()
28602 for(i=0; i<N_HASH; i++){ in sqlite3Memsys3Dump()
28603 if( mem3.aiHash[i]==0 ) continue; in sqlite3Memsys3Dump()
28605 for(j = mem3.aiHash[i]; j>0; j=mem3.aPool[j].u.list.next){ in sqlite3Memsys3Dump()
28645 0 in sqlite3MemGetMemsys3()
28736 #define CTRL_LOGSIZE 0x1f /* Log2 Size of this block */
28737 #define CTRL_FREE 0x20 /* True if not checked out */
28773 ** Lists of free blocks. aiFreelist[0] is a list of free blocks of
28804 assert( i>=0 && i<mem5.nBlock ); in memsys5Unlink()
28805 assert( iLogsize>=0 && iLogsize<=LOGMAX ); in memsys5Unlink()
28810 if( prev<0 ){ in memsys5Unlink()
28815 if( next>=0 ){ in memsys5Unlink()
28827 assert( i>=0 && i<mem5.nBlock ); in memsys5Link()
28828 assert( iLogsize>=0 && iLogsize<=LOGMAX ); in memsys5Link()
28833 if( x>=0 ){ in memsys5Link()
28856 assert( p!=0 ); in memsys5Size()
28858 assert( i>=0 && i<mem5.nBlock ); in memsys5Size()
28865 ** Return NULL if unable. Return NULL if nBytes==0.
28880 assert( nByte>0 ); in memsys5MallocUnsafe()
28883 if( nByte > 0x40000000 ) return 0; in memsys5MallocUnsafe()
28895 for(iFullSz=mem5.szAtom,iLogsize=0; iFullSz<nByte; iFullSz*=2,iLogsize++){} in memsys5MallocUnsafe()
28901 for(iBin=iLogsize; iBin<=LOGMAX && mem5.aiFreelist[iBin]<0; iBin++){} in memsys5MallocUnsafe()
28903 testcase( sqlite3GlobalConfig.xLog!=0 ); in memsys5MallocUnsafe()
28905 return 0; in memsys5MallocUnsafe()
28933 memset(&mem5.zPool[i*mem5.szAtom], 0xAA, iFullSz); in memsys5MallocUnsafe()
28953 assert( iBlock>=0 && iBlock<mem5.nBlock ); in memsys5FreeUnsafe()
28954 assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 ); in memsys5FreeUnsafe()
28955 assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 ); in memsys5FreeUnsafe()
28965 assert( mem5.currentCount>0 ); in memsys5FreeUnsafe()
28969 assert( mem5.currentOut>0 || mem5.currentCount==0 ); in memsys5FreeUnsafe()
28970 assert( mem5.currentCount>0 || mem5.currentOut==0 ); in memsys5FreeUnsafe()
28978 assert( iBuddy>=0 ); in memsys5FreeUnsafe()
28988 mem5.aCtrl[iBlock] = 0; in memsys5FreeUnsafe()
28992 mem5.aCtrl[iBuddy] = 0; in memsys5FreeUnsafe()
28998 /* Overwrite freed memory with the 0x55 bit pattern to verify that it is in memsys5FreeUnsafe()
29000 memset(&mem5.zPool[iBlock*mem5.szAtom], 0x55, size); in memsys5FreeUnsafe()
29010 sqlite3_int64 *p = 0; in memsys5Malloc()
29011 if( nBytes>0 ){ in memsys5Malloc()
29023 ** being called with pPrior==0.
29026 assert( pPrior!=0 ); in memsys5Free()
29036 ** being called with pPrior==0.
29040 ** of two. If nBytes==0 that means that an oversize allocation
29041 ** (an allocation larger than 0x40000000) was requested and this
29042 ** routine should return 0 without freeing pPrior.
29047 assert( pPrior!=0 ); in memsys5Realloc()
29048 assert( (nBytes&(nBytes-1))==0 ); /* EV: R-46199-30249 */ in memsys5Realloc()
29049 assert( nBytes>=0 ); in memsys5Realloc()
29050 if( nBytes==0 ){ in memsys5Realloc()
29051 return 0; in memsys5Realloc()
29068 ** return 0.
29071 ** 32-bit signed integer. Hence the largest allocation is 0x40000000
29080 if( n>0x10000000 ){ in memsys5Roundup()
29081 if( n>0x40000000 ) return 0; in memsys5Roundup()
29082 if( n>0x20000000 ) return 0x40000000; in memsys5Roundup()
29083 return 0x20000000; in memsys5Roundup()
29093 ** Examples: memsys5Log(1) -> 0
29102 for(iLog=0; (iLog<(int)((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++); in memsys5Log()
29122 mem5.mutex = 0; in memsys5Init()
29127 assert( (sizeof(Mem5Link)&(sizeof(Mem5Link)-1))==0 ); in memsys5Init()
29131 assert( zByte!=0 ); /* sqlite3_config() does not allow otherwise */ in memsys5Init()
29144 for(ii=0; ii<=LOGMAX; ii++){ in memsys5Init()
29148 iOffset = 0; in memsys5Init()
29149 for(ii=LOGMAX; ii>=0; ii--){ in memsys5Init()
29160 if( sqlite3GlobalConfig.bMemstat==0 ){ in memsys5Init()
29172 mem5.mutex = 0; in memsys5Shutdown()
29186 if( zFilename==0 || zFilename[0]==0 ){ in sqlite3Memsys5Dump()
29190 if( out==0 ){ in sqlite3Memsys5Dump()
29198 for(i=0; i<=LOGMAX && i+nMinLog<32; i++){ in sqlite3Memsys5Dump()
29199 for(n=0, j=mem5.aiFreelist[i]; j>=0; j = MEM5LINK(j)->next, n++){} in sqlite3Memsys5Dump()
29233 0 in sqlite3MemGetMemsys5()
29265 static SQLITE_WSD int mutexIsInit = 0;
29326 pGlobalMutexMethods = 0; in checkMutexEnd()
29335 {2, 0}, {3, 0}, {4, 0}, {5, 0}, in checkMutexAlloc()
29336 {6, 0}, {7, 0}, {8, 0}, {9, 0}, in checkMutexAlloc()
29337 {10, 0}, {11, 0}, {12, 0}, {13, 0} in checkMutexAlloc()
29339 CheckMutex *p = 0; in checkMutexAlloc()
29341 assert( SQLITE_MUTEX_RECURSIVE==1 && SQLITE_MUTEX_FAST==0 ); in checkMutexAlloc()
29344 if( p==0 ) return 0; in checkMutexAlloc()
29350 return 0; in checkMutexAlloc()
29356 if( p->mutex==0 ){ in checkMutexAlloc()
29358 if( p->mutex==0 ){ in checkMutexAlloc()
29362 p = 0; in checkMutexAlloc()
29437 0, in multiThreadedCheckMutex()
29438 0 in multiThreadedCheckMutex()
29513 GLOBAL(int, mutexIsInit) = 0; in sqlite3MutexEnd()
29524 if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; in sqlite3_mutex_alloc()
29525 if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0; in sqlite3_mutex_alloc()
29533 return 0; in sqlite3MutexAlloc()
29598 p = 0; in sqlite3_mutex_held()
29601 assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld ); in sqlite3_mutex_held()
29602 return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p); in sqlite3_mutex_held()
29607 p = 0; in sqlite3_mutex_notheld()
29610 assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld ); in sqlite3_mutex_notheld()
29611 return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); in sqlite3_mutex_notheld()
29680 0, in sqlite3NoopMutex()
29681 0, in sqlite3NoopMutex()
29709 return p==0 || p->cnt>0; in debugMutexHeld()
29713 return p==0 || p->cnt==0; in debugMutexNotheld()
29729 sqlite3_debug_mutex *pNew = 0; in debugMutexAlloc()
29736 pNew->cnt = 0; in debugMutexAlloc()
29742 if( id-2<0 || id-2>=ArraySize(aStatic) ){ in debugMutexAlloc()
29744 return 0; in debugMutexAlloc()
29760 assert( p->cnt==0 ); in debugMutexFree()
29871 # define SQLITE_MUTEX_NREF 0
29890 {PTHREAD_MUTEX_INITIALIZER,id,0,(pthread_t)0,0}
29915 return (p->nRef!=0 && pthread_equal(p->owner, pthread_self())); in pthreadMutexHeld()
29918 return p->nRef==0 || pthread_equal(p->owner, pthread_self())==0; in pthreadMutexNotheld()
30012 pthread_mutex_init(&p->mutex, 0); in pthreadMutexAlloc()
30030 pthread_mutex_init(&p->mutex, 0); in pthreadMutexAlloc()
30039 if( iType-2<0 || iType-2>=ArraySize(staticMutexes) ){ in pthreadMutexAlloc()
30041 return 0; in pthreadMutexAlloc()
30049 assert( p==0 || p->id==iType ); in pthreadMutexAlloc()
30061 assert( p->nRef==0 ); in pthreadMutexFree()
30103 if( p->nRef>0 && pthread_equal(p->owner, self) ){ in pthreadMutexEnter()
30107 assert( p->nRef==0 ); in pthreadMutexEnter()
30117 assert( p->nRef>0 || p->owner==0 ); in pthreadMutexEnter()
30146 if( p->nRef>0 && pthread_equal(p->owner, self) ){ in pthreadMutexTry()
30149 }else if( pthread_mutex_trylock(&p->mutex)==0 ){ in pthreadMutexTry()
30150 assert( p->nRef==0 ); in pthreadMutexTry()
30161 if( pthread_mutex_trylock(&p->mutex)==0 ){ in pthreadMutexTry()
30190 if( p->nRef==0 ) p->owner = 0; in pthreadMutexLeave()
30192 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE ); in pthreadMutexLeave()
30195 if( p->nRef==0 ){ in pthreadMutexLeave()
30222 0, in sqlite3DefaultMutex()
30223 0 in sqlite3DefaultMutex()
30298 ** # define SQLITE_OS_WINNT 0
30304 ** by setting SQLITE_OS_WINNT to 0.
30317 # define SQLITE_OS_WINCE 0
30325 # define SQLITE_OS_WINRT 0
30343 SQLITE_THREADSAFE>0 && !defined(__CYGWIN__)
30346 # define SQLITE_OS_WIN_THREADS 0
30379 #define SQLITE_W32_MUTEX_INITIALIZER { 0 }
30383 0L, (DWORD)0, 0 }
30394 return p->nRef!=0 && p->owner==GetCurrentThreadId(); in winMutexHeld()
30398 return p->nRef==0 || p->owner!=tid; in winMutexNotheld2()
30410 ** compiled without mutexes (SQLITE_THREADSAFE=0).
30442 static int winMutex_isInit = 0;
30443 static int winMutex_isNt = -1; /* <0 means "need to query" */
30449 static LONG SQLITE_WIN32_VOLATILE winMutex_lock = 0;
30456 if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){ in winMutexInit()
30458 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){ in winMutexInit()
30460 InitializeCriticalSectionEx(&winMutex_staticMutexes[i].mutex, 0, 0); in winMutexInit()
30477 /* The first to decrement to 0 does actual shutdown in winMutexEnd()
30479 if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){ in winMutexEnd()
30482 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){ in winMutexEnd()
30485 winMutex_isInit = 0; in winMutexEnd()
30554 InitializeCriticalSectionEx(&p->mutex, 0, 0); in winMutexAlloc()
30563 if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){ in winMutexAlloc()
30565 return 0; in winMutexAlloc()
30571 InterlockedCompareExchange(&p->trace, 1, 0); in winMutexAlloc()
30577 assert( p==0 || p->id==iType ); in winMutexAlloc()
30589 assert( p->nRef==0 && p->owner==0 ); in winMutexFree()
30624 assert( p->nRef>0 || p->owner==0 ); in winMutexEnter()
30652 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400 in winMutexTry()
30655 if( winMutex_isNt<0 ){ in winMutexTry()
30658 assert( winMutex_isNt==0 || winMutex_isNt==1 ); in winMutexTry()
30690 assert( p->nRef>0 ); in winMutexLeave()
30693 if( p->nRef==0 ) p->owner = 0; in winMutexLeave()
30694 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE ); in winMutexLeave()
30719 0, in sqlite3DefaultMutex()
30720 0 in sqlite3DefaultMutex()
30760 return 0; in sqlite3_release_memory()
30765 ** Default value of the hard heap limit. 0 means "no limit".
30768 # define SQLITE_MAX_MEMORY 0
30784 } mem0 = { 0, SQLITE_MAX_MEMORY, SQLITE_MAX_MEMORY, 0 };
30834 if( n<0 ){ in sqlite3_soft_heap_limit64()
30838 if( mem0.hardLimit>0 && (n>mem0.hardLimit || n==0) ){ in sqlite3_soft_heap_limit64()
30843 AtomicStore(&mem0.nearlyFull, n>0 && n<=nUsed); in sqlite3_soft_heap_limit64()
30846 if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff)); in sqlite3_soft_heap_limit64()
30850 if( n<0 ) n = 0; in sqlite3_soft_heap_limit()
30874 if( n>=0 ){ in sqlite3_hard_heap_limit64()
30876 if( n<mem0.alarmThreshold || mem0.alarmThreshold==0 ){ in sqlite3_hard_heap_limit64()
30890 if( sqlite3GlobalConfig.m.xMalloc==0 ){ in sqlite3MallocInit()
30894 if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512 in sqlite3MallocInit()
30895 || sqlite3GlobalConfig.nPage<=0 ){ in sqlite3MallocInit()
30896 sqlite3GlobalConfig.pPage = 0; in sqlite3MallocInit()
30897 sqlite3GlobalConfig.szPage = 0; in sqlite3MallocInit()
30900 if( rc!=SQLITE_OK ) memset(&mem0, 0, sizeof(mem0)); in sqlite3MallocInit()
30920 memset(&mem0, 0, sizeof(mem0)); in sqlite3MallocEnd()
30928 sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, 0); in sqlite3_memory_used()
30947 if( mem0.alarmThreshold<=0 ) return; in sqlite3MallocAlarm()
30961 static u64 nOomFault = 0; in test_oom_breakpoint()
30965 assert( (nOomFault>>32) < 0xffffffff ); in test_oom_breakpoint()
30979 assert( n>0 ); in mallocWithAlarm()
30989 if( mem0.alarmThreshold>0 ){ in mallocWithAlarm()
30998 *pp = 0; in mallocWithAlarm()
31003 AtomicStore(&mem0.nearlyFull, 0); in mallocWithAlarm()
31008 if( p==0 && mem0.alarmThreshold>0 ){ in mallocWithAlarm()
31027 ** The upper bound is slightly less than 2GiB: 0x7ffffeff == 2,147,483,391
31031 ** further for an even larger safety margin. 0x3fffffff or 0x0fffffff
31048 if( n==0 || n>SQLITE_MAX_ALLOCATION_SIZE ){ in sqlite3Malloc()
31049 p = 0; in sqlite3Malloc()
31068 if( sqlite3_initialize() ) return 0; in sqlite3_malloc()
31070 return n<=0 ? 0 : sqlite3Malloc(n); in sqlite3_malloc()
31074 if( sqlite3_initialize() ) return 0; in sqlite3_malloc64()
31087 #define isLookaside(A,B) 0
31106 assert( p!=0 ); in sqlite3DbMallocSize()
31108 if( db==0 ){ in sqlite3DbMallocSize()
31135 return p ? sqlite3GlobalConfig.m.xSize(p) : 0; in sqlite3_msize()
31142 if( p==0 ) return; /* IMP: R-49053-54554 */ in sqlite3_free()
31166 ** connection. Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
31170 assert( db==0 || sqlite3_mutex_held(db->mutex) ); in sqlite3DbFreeNN()
31171 assert( p!=0 ); in sqlite3DbFreeNN()
31177 assert( db->pnBytesFreed==0 ); in sqlite3DbFreeNN()
31179 memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */ in sqlite3DbFreeNN()
31188 assert( db->pnBytesFreed==0 ); in sqlite3DbFreeNN()
31190 memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */ in sqlite3DbFreeNN()
31204 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); in sqlite3DbFreeNN()
31209 assert( db!=0 ); in sqlite3DbNNFreeNN()
31211 assert( p!=0 ); in sqlite3DbNNFreeNN()
31216 assert( db->pnBytesFreed==0 ); in sqlite3DbNNFreeNN()
31218 memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */ in sqlite3DbNNFreeNN()
31227 assert( db->pnBytesFreed==0 ); in sqlite3DbNNFreeNN()
31229 memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */ in sqlite3DbNNFreeNN()
31246 assert( db==0 || sqlite3_mutex_held(db->mutex) ); in sqlite3DbFree()
31258 if( pOld==0 ){ in sqlite3Realloc()
31261 if( nBytes==0 ){ in sqlite3Realloc()
31263 return 0; in sqlite3Realloc()
31265 if( nBytes>=0x7fffff00 ){ in sqlite3Realloc()
31266 /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */ in sqlite3Realloc()
31267 return 0; in sqlite3Realloc()
31281 if( nDiff>0 && (nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)) >= in sqlite3Realloc()
31284 if( mem0.hardLimit>0 && nUsed >= mem0.hardLimit - nDiff ){ in sqlite3Realloc()
31287 return 0; in sqlite3Realloc()
31292 if( pNew==0 && mem0.alarmThreshold>0 ){ in sqlite3Realloc()
31315 if( sqlite3_initialize() ) return 0; in sqlite3_realloc()
31317 if( n<0 ) n = 0; /* IMP: R-26507-47431 */ in sqlite3_realloc()
31322 if( sqlite3_initialize() ) return 0; in sqlite3_realloc64()
31334 memset(p, 0, (size_t)n); in sqlite3MallocZero()
31345 testcase( db==0 ); in sqlite3DbMallocZero()
31347 if( p ) memset(p, 0, (size_t)n); in sqlite3DbMallocZero()
31357 assert( db!=0 ); in dbMallocRawFinish()
31361 (db->lookaside.bDisable==0) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP); in dbMallocRawFinish()
31370 ** If db!=0 and db->mallocFailed is true (indicating a prior malloc
31371 ** failure on the same database connection) then always return 0.
31397 assert( db!=0 ); in sqlite3DbMallocRawNN()
31399 assert( db->pnBytesFreed==0 ); in sqlite3DbMallocRawNN()
31404 return 0; in sqlite3DbMallocRawNN()
31410 if( (pBuf = db->lookaside.pSmallFree)!=0 ){ in sqlite3DbMallocRawNN()
31412 db->lookaside.anStat[0]++; in sqlite3DbMallocRawNN()
31414 }else if( (pBuf = db->lookaside.pSmallInit)!=0 ){ in sqlite3DbMallocRawNN()
31416 db->lookaside.anStat[0]++; in sqlite3DbMallocRawNN()
31421 if( (pBuf = db->lookaside.pFree)!=0 ){ in sqlite3DbMallocRawNN()
31423 db->lookaside.anStat[0]++; in sqlite3DbMallocRawNN()
31425 }else if( (pBuf = db->lookaside.pInit)!=0 ){ in sqlite3DbMallocRawNN()
31427 db->lookaside.anStat[0]++; in sqlite3DbMallocRawNN()
31433 assert( db!=0 ); in sqlite3DbMallocRawNN()
31435 assert( db->pnBytesFreed==0 ); in sqlite3DbMallocRawNN()
31437 return 0; in sqlite3DbMallocRawNN()
31451 assert( db!=0 ); in sqlite3DbRealloc()
31452 if( p==0 ) return sqlite3DbMallocRawNN(db, n); in sqlite3DbRealloc()
31467 void *pNew = 0; in dbReallocFinish()
31468 assert( db!=0 ); in dbReallocFinish()
31469 assert( p!=0 ); in dbReallocFinish()
31470 if( db->mallocFailed==0 ){ in dbReallocFinish()
31486 (db->lookaside.bDisable==0 ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP)); in dbReallocFinish()
31515 if( z==0 ){ in sqlite3DbStrDup()
31516 return 0; in sqlite3DbStrDup()
31527 assert( db!=0 ); in sqlite3DbStrNDup()
31528 assert( z!=0 || n==0 ); in sqlite3DbStrNDup()
31529 assert( (n&0x7fffffff)==n ); in sqlite3DbStrNDup()
31530 zNew = z ? sqlite3DbMallocRawNN(db, n+1) : 0; in sqlite3DbStrNDup()
31533 zNew[n] = 0; in sqlite3DbStrNDup()
31548 for(n=0; sqlite3Isspace(zStart[n]); n++){ assert( &zStart[n]<zEnd ); } in sqlite3DbSpanDup()
31550 while( sqlite3Isspace(zStart[0]) ) zStart++; in sqlite3DbSpanDup()
31579 if( db->mallocFailed==0 && db->bBenignMalloc==0 ){ in sqlite3OomFault()
31581 if( db->nVdbeExec>0 ){ in sqlite3OomFault()
31595 return 0; in sqlite3OomFault()
31606 if( db->mallocFailed && db->nVdbeExec==0 ){ in sqlite3OomClear()
31607 db->mallocFailed = 0; in sqlite3OomClear()
31608 AtomicStore(&db->u1.isInterrupted, 0); in sqlite3OomClear()
31609 assert( db->lookaside.bDisable>0 ); in sqlite3OomClear()
31643 assert( db!=0 ); in sqlite3ApiExit()
31648 return 0; in sqlite3ApiExit()
31670 #define etRADIX 0 /* non-decimal integer types. %x %o */
31725 { 'd', 10, 1, etDECIMAL, 0, 0 },
31726 { 's', 0, 4, etSTRING, 0, 0 },
31727 { 'g', 0, 1, etGENERIC, 30, 0 },
31728 { 'z', 0, 4, etDYNSTRING, 0, 0 },
31729 { 'q', 0, 4, etESCAPE_q, 0, 0 },
31730 { 'Q', 0, 4, etESCAPE_Q, 0, 0 },
31731 { 'w', 0, 4, etESCAPE_w, 0, 0 },
31732 { 'c', 0, 0, etCHARX, 0, 0 },
31733 { 'o', 8, 0, etRADIX, 0, 2 },
31734 { 'u', 10, 0, etDECIMAL, 0, 0 },
31735 { 'x', 16, 0, etRADIX, 16, 1 },
31736 { 'X', 16, 0, etRADIX, 0, 4 },
31738 { 'f', 0, 1, etFLOAT, 0, 0 },
31739 { 'e', 0, 1, etEXP, 30, 0 },
31740 { 'E', 0, 1, etEXP, 14, 0 },
31741 { 'G', 0, 1, etGENERIC, 14, 0 },
31743 { 'i', 10, 1, etDECIMAL, 0, 0 },
31744 { 'n', 0, 0, etSIZE, 0, 0 },
31745 { '%', 0, 0, etPERCENT, 0, 0 },
31746 { 'p', 16, 0, etPOINTER, 0, 1 },
31749 { 'T', 0, 0, etTOKEN, 0, 0 },
31750 { 'S', 0, 0, etSRCITEM, 0, 0 },
31751 { 'r', 10, 1, etORDINAL, 0, 0 },
31774 if( p->nArg<=p->nUsed ) return 0; in getIntArg()
31782 if( p->nArg<=p->nUsed ) return 0; in getTextArg()
31797 if( pAccum->accError ) return 0; in printfTempBuf()
31800 return 0; in printfTempBuf()
31803 if( z==0 ){ in printfTempBuf()
31840 etByte flag_prefix; /* '+' or ' ' or 0 for prefix */ in sqlite3_str_vappendf()
31844 etByte flag_long; /* 1 for the "l" flag, 2 for "ll", 0 by default */ in sqlite3_str_vappendf()
31849 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ in sqlite3_str_vappendf()
31855 char *zExtra = 0; /* Malloced memory used by some conversion */ in sqlite3_str_vappendf()
31860 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ in sqlite3_str_vappendf()
31866 assert( pAccum->nChar>0 || (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 ); in sqlite3_str_vappendf()
31868 bufpt = 0; in sqlite3_str_vappendf()
31869 if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){ in sqlite3_str_vappendf()
31873 bArgList = 0; in sqlite3_str_vappendf()
31875 for(; (c=(*fmt))!=0; ++fmt){ in sqlite3_str_vappendf()
31884 if( *fmt==0 ) break; in sqlite3_str_vappendf()
31886 if( (c=(*++fmt))==0 ){ in sqlite3_str_vappendf()
31892 flag_alternateform = flag_altform2 = flag_zeropad = 0; in sqlite3_str_vappendf()
31893 done = 0; in sqlite3_str_vappendf()
31894 width = 0; in sqlite3_str_vappendf()
31895 flag_long = 0; in sqlite3_str_vappendf()
31904 case '0': flag_zeropad = 1; break; in sqlite3_str_vappendf()
31919 unsigned wx = c - '0'; in sqlite3_str_vappendf()
31920 while( (c = *++fmt)>='0' && c<='9' ){ in sqlite3_str_vappendf()
31921 wx = wx*10 + c - '0'; in sqlite3_str_vappendf()
31923 testcase( wx>0x7fffffff ); in sqlite3_str_vappendf()
31924 width = wx & 0x7fffffff; in sqlite3_str_vappendf()
31943 if( width<0 ){ in sqlite3_str_vappendf()
31945 width = width >= -2147483647 ? -width : 0; in sqlite3_str_vappendf()
31966 if( precision<0 ){ in sqlite3_str_vappendf()
31971 unsigned px = 0; in sqlite3_str_vappendf()
31972 while( c>='0' && c<='9' ){ in sqlite3_str_vappendf()
31973 px = px*10 + c - '0'; in sqlite3_str_vappendf()
31976 testcase( px>0x7fffffff ); in sqlite3_str_vappendf()
31977 precision = px & 0x7fffffff; in sqlite3_str_vappendf()
31992 }while( !done && (c=(*++fmt))!=0 ); in sqlite3_str_vappendf()
31995 infop = &fmtinfo[0]; in sqlite3_str_vappendf()
31997 for(idx=0; idx<ArraySize(fmtinfo); idx++){ in sqlite3_str_vappendf()
32013 ** flag_zeropad TRUE if the width began with 0. in sqlite3_str_vappendf()
32022 assert( width>=0 ); in sqlite3_str_vappendf()
32027 sizeof(char*)==sizeof(long int) ? 1 : 0; in sqlite3_str_vappendf()
32031 cThousand = 0; in sqlite3_str_vappendf()
32047 if( v<0 ){ in sqlite3_str_vappendf()
32069 prefix = 0; in sqlite3_str_vappendf()
32071 if( longvalue==0 ) flag_alternateform = 0; in sqlite3_str_vappendf()
32072 if( flag_zeropad && precision<width-(prefix!=0) ){ in sqlite3_str_vappendf()
32073 precision = width-(prefix!=0); in sqlite3_str_vappendf()
32083 if( zOut==0 ) return; in sqlite3_str_vappendf()
32091 x = 0; in sqlite3_str_vappendf()
32102 }while( longvalue>0 ); in sqlite3_str_vappendf()
32106 *(--bufpt) = '0'; /* Zero pad */ in sqlite3_str_vappendf()
32113 for(idx=0; nn>0; idx++){ in sqlite3_str_vappendf()
32116 if( ix==0 ){ in sqlite3_str_vappendf()
32124 if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */ in sqlite3_str_vappendf()
32128 for(; (x=(*pre))!=0; pre++) *(--bufpt) = x; in sqlite3_str_vappendf()
32144 if( precision<0 ) precision = 6; /* Set default precision */ in sqlite3_str_vappendf()
32153 if( precision==0 ) precision = 1; in sqlite3_str_vappendf()
32165 s.z[0] = '9'; in sqlite3_str_vappendf()
32174 buf[0] = flag_prefix; in sqlite3_str_vappendf()
32195 assert( precision>0 ); in sqlite3_str_vappendf()
32208 e2 = 0; in sqlite3_str_vappendf()
32215 szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15; in sqlite3_str_vappendf()
32216 if( cThousand && e2>0 ) szBufNeeded += (e2+2)/3; in sqlite3_str_vappendf()
32219 if( bufpt==0 ) return; in sqlite3_str_vappendf()
32223 flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2; in sqlite3_str_vappendf()
32229 j = 0; in sqlite3_str_vappendf()
32230 if( e2<0 ){ in sqlite3_str_vappendf()
32231 *(bufpt++) = '0'; in sqlite3_str_vappendf()
32233 for(; e2>=0; e2--){ in sqlite3_str_vappendf()
32234 *(bufpt++) = j<s.n ? s.z[j++] : '0'; in sqlite3_str_vappendf()
32235 if( cThousand && (e2%3)==0 && e2>1 ) *(bufpt++) = ','; in sqlite3_str_vappendf()
32242 /* "0" digits after the decimal point but before the first in sqlite3_str_vappendf()
32244 for(e2++; e2<0 && precision>0; precision--, e2++){ in sqlite3_str_vappendf()
32245 *(bufpt++) = '0'; in sqlite3_str_vappendf()
32248 while( (precision--)>0 ){ in sqlite3_str_vappendf()
32249 *(bufpt++) = j<s.n ? s.z[j++] : '0'; in sqlite3_str_vappendf()
32253 while( bufpt[-1]=='0' ) *(--bufpt) = 0; in sqlite3_str_vappendf()
32257 *(bufpt++) = '0'; in sqlite3_str_vappendf()
32259 *(--bufpt) = 0; in sqlite3_str_vappendf()
32267 if( exp<0 ){ in sqlite3_str_vappendf()
32273 *(bufpt++) = (char)((exp/100)+'0'); /* 100's digit */ in sqlite3_str_vappendf()
32276 *(bufpt++) = (char)(exp/10+'0'); /* 10's digit */ in sqlite3_str_vappendf()
32277 *(bufpt++) = (char)(exp%10+'0'); /* 1's digit */ in sqlite3_str_vappendf()
32279 *bufpt = 0; in sqlite3_str_vappendf()
32295 i = prefix!=0; in sqlite3_str_vappendf()
32296 while( nPad-- ) bufpt[i++] = '0'; in sqlite3_str_vappendf()
32305 length = width = 0; in sqlite3_str_vappendf()
32308 buf[0] = '%'; in sqlite3_str_vappendf()
32317 buf[0] = c = *(bufpt++); in sqlite3_str_vappendf()
32318 if( (c&0xc0)==0xc0 ){ in sqlite3_str_vappendf()
32319 while( length<4 && (bufpt[0]&0xc0)==0x80 ){ in sqlite3_str_vappendf()
32324 buf[0] = 0; in sqlite3_str_vappendf()
32335 width = 0; in sqlite3_str_vappendf()
32364 if( bufpt==0 ){ in sqlite3_str_vappendf()
32367 if( pAccum->nChar==0 in sqlite3_str_vappendf()
32369 && width==0 in sqlite3_str_vappendf()
32370 && precision<0 in sqlite3_str_vappendf()
32371 && pAccum->accError==0 in sqlite3_str_vappendf()
32376 assert( (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 ); in sqlite3_str_vappendf()
32379 pAccum->nChar = 0x7fffffff & (int)strlen(bufpt); in sqlite3_str_vappendf()
32381 length = 0; in sqlite3_str_vappendf()
32386 if( precision>=0 ){ in sqlite3_str_vappendf()
32391 while( precision-- > 0 && z[0] ){ in sqlite3_str_vappendf()
32396 for(length=0; length<precision && bufpt[length]; length++){} in sqlite3_str_vappendf()
32399 length = 0x7fffffff & (int)strlen(bufpt); in sqlite3_str_vappendf()
32402 if( flag_altform2 && width>0 ){ in sqlite3_str_vappendf()
32405 while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++; in sqlite3_str_vappendf()
32412 int needQuote = 0; in sqlite3_str_vappendf()
32422 if( escarg==0 ){ in sqlite3_str_vappendf()
32429 flag_alternateform = 0; in sqlite3_str_vappendf()
32439 for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){ in sqlite3_str_vappendf()
32441 if( flag_altform2 && (ch&0xc0)==0xc0 ){ in sqlite3_str_vappendf()
32442 while( (escarg[i+1]&0xc0)==0x80 ){ i++; } in sqlite3_str_vappendf()
32450 u32 nBack = 0; in sqlite3_str_vappendf()
32451 u32 nCtrl = 0; in sqlite3_str_vappendf()
32452 for(k=0; k<i; k++){ in sqlite3_str_vappendf()
32455 }else if( ((u8*)escarg)[k]<=0x1f ){ in sqlite3_str_vappendf()
32466 flag_alternateform = 0; in sqlite3_str_vappendf()
32472 if( bufpt==0 ) return; in sqlite3_str_vappendf()
32476 j = 0; in sqlite3_str_vappendf()
32487 for(i=0; i<k; i++){ in sqlite3_str_vappendf()
32493 }else if( ((unsigned char)ch)<=0x1f ){ in sqlite3_str_vappendf()
32496 bufpt[j++] = '0'; in sqlite3_str_vappendf()
32497 bufpt[j++] = '0'; in sqlite3_str_vappendf()
32498 bufpt[j++] = ch>=0x10 ? '1' : '0'; in sqlite3_str_vappendf()
32499 bufpt[j++] = "0123456789abcdef"[ch&0xf]; in sqlite3_str_vappendf()
32503 for(i=0; i<k; i++){ in sqlite3_str_vappendf()
32512 bufpt[j] = 0; in sqlite3_str_vappendf()
32517 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; in sqlite3_str_vappendf()
32528 assert( bArgList==0 ); in sqlite3_str_vappendf()
32534 length = width = 0; in sqlite3_str_vappendf()
32539 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; in sqlite3_str_vappendf()
32541 assert( bArgList==0 ); in sqlite3_str_vappendf()
32545 if( pItem->fg.fixedSchema==0 in sqlite3_str_vappendf()
32546 && pItem->fg.isSubquery==0 in sqlite3_str_vappendf()
32547 && pItem->u4.zDatabase!=0 in sqlite3_str_vappendf()
32557 assert( pSel!=0 ); in sqlite3_str_vappendf()
32568 length = width = 0; in sqlite3_str_vappendf()
32585 if( width>0 ){ in sqlite3_str_vappendf()
32595 zExtra = 0; in sqlite3_str_vappendf()
32611 assert( z!=0 ); in sqlite3RecordErrorByteOffset()
32612 if( NEVER(db==0) ) return; in sqlite3RecordErrorByteOffset()
32615 if( NEVER(pParse==0) ) return; in sqlite3RecordErrorByteOffset()
32617 if( NEVER(zText==0) ) return; in sqlite3RecordErrorByteOffset()
32630 && (ExprHasProperty(pExpr,EP_OuterON|EP_InnerON) || pExpr->w.iOfst<=0) in sqlite3RecordErrorOffsetOfExpr()
32634 if( pExpr==0 ) return; in sqlite3RecordErrorOffsetOfExpr()
32652 return 0; in sqlite3StrAccumEnlarge()
32654 if( p->mxAlloc==0 ){ in sqlite3StrAccumEnlarge()
32658 char *zOld = isMalloced(p) ? p->zText : 0; in sqlite3StrAccumEnlarge()
32668 return 0; in sqlite3StrAccumEnlarge()
32678 assert( p->zText!=0 || p->nChar==0 ); in sqlite3StrAccumEnlarge()
32679 if( !isMalloced(p) && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); in sqlite3StrAccumEnlarge()
32686 return 0; in sqlite3StrAccumEnlarge()
32689 assert( N>=0 && N<=0x7fffffff ); in sqlite3StrAccumEnlarge()
32697 testcase( p->nChar + (i64)N > 0x7fffffff ); in sqlite3_str_appendchar()
32698 if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){ in sqlite3_str_appendchar()
32701 while( (N--)>0 ) p->zText[p->nChar++] = c; in sqlite3_str_appendchar()
32714 if( N>0 ){ in enlargeAndAppend()
32725 assert( z!=0 || N==0 ); in sqlite3_str_append()
32726 assert( p->zText!=0 || p->nChar==0 || p->accError ); in sqlite3_str_append()
32727 assert( N>=0 ); in sqlite3_str_append()
32728 assert( p->accError==0 || p->nAlloc==0 || p->mxAlloc==0 ); in sqlite3_str_append()
32753 assert( p->mxAlloc>0 && !isMalloced(p) ); in strAccumFinishRealloc()
32766 p->zText[p->nChar] = 0; in sqlite3StrAccumFinish()
32767 if( p->mxAlloc>0 && !isMalloced(p) ){ in sqlite3StrAccumFinish()
32785 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC); in sqlite3ResultStrAccum()
32797 0, 0, 0, 0, 0, SQLITE_NOMEM, 0
32804 if( p!=0 && p!=&sqlite3OomStr ){ in sqlite3_str_finish()
32808 z = 0; in sqlite3_str_finish()
32820 return p ? p->nChar : 0; in sqlite3_str_length()
32825 if( p==0 || p->nChar==0 ) return 0; in sqlite3_str_value()
32826 p->zText[p->nChar] = 0; in sqlite3_str_value()
32838 p->nAlloc = 0; in sqlite3_str_reset()
32839 p->nChar = 0; in sqlite3_str_reset()
32840 p->zText = 0; in sqlite3_str_reset()
32854 ** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
32862 p->nChar = 0; in sqlite3StrAccumInit()
32863 p->accError = 0; in sqlite3StrAccumInit()
32864 p->printfFlags = 0; in sqlite3StrAccumInit()
32871 sqlite3StrAccumInit(p, 0, 0, 0, in sqlite3_str_new()
32887 assert( db!=0 ); in sqlite3VMPrintf()
32922 if( zFormat==0 ){ in sqlite3_vmprintf()
32924 return 0; in sqlite3_vmprintf()
32928 if( sqlite3_initialize() ) return 0; in sqlite3_vmprintf()
32930 sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); in sqlite3_vmprintf()
32944 if( sqlite3_initialize() ) return 0; in sqlite3_mprintf()
32967 if( n<=0 ) return zBuf; in sqlite3_vsnprintf()
32969 if( zBuf==0 || zFormat==0 ) { in sqlite3_vsnprintf()
32971 if( zBuf ) zBuf[0] = 0; in sqlite3_vsnprintf()
32975 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); in sqlite3_vsnprintf()
32977 zBuf[acc.nChar] = 0; in sqlite3_vsnprintf()
32983 if( n<=0 ) return zBuf; in sqlite3_snprintf()
32985 if( zBuf==0 || zFormat==0 ) { in sqlite3_snprintf()
32987 if( zBuf ) zBuf[0] = 0; in sqlite3_snprintf()
32991 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); in sqlite3_snprintf()
32995 zBuf[acc.nChar] = 0; in sqlite3_snprintf()
33026 sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0); in renderLogMsg()
33054 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); in sqlite3DebugPrintf()
33095 assert( p!=0 ); in sqlite3RCStrRef()
33107 assert( p!=0 ); in sqlite3RCStrUnref()
33109 assert( p->nRCRef>0 ); in sqlite3RCStrUnref()
33124 ** This routine returns 0 on an OOM.
33128 if( p==0 ) return 0; in sqlite3RCStrNew()
33140 assert( p!=0 ); in sqlite3RCStrResize()
33144 if( pNew==0 ){ in sqlite3RCStrResize()
33146 return 0; in sqlite3RCStrResize()
33182 if( p==0 ){ in sqlite3TreeViewPush()
33184 if( p==0 ) return; in sqlite3TreeViewPush()
33185 memset(p, 0, sizeof(*p)); in sqlite3TreeViewPush()
33189 assert( moreToFollow==0 || moreToFollow==1 ); in sqlite3TreeViewPush()
33198 if( p==0 ) return; in sqlite3TreeViewPop()
33200 if( p->iLevel<0 ){ in sqlite3TreeViewPop()
33202 *pp = 0; in sqlite3TreeViewPop()
33215 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); in sqlite3TreeViewLine()
33217 for(i=0; i<p->iLevel && i<(int)sizeof(p->bLine)-1; i++){ in sqlite3TreeViewLine()
33222 if( zFormat!=0 ){ in sqlite3TreeViewLine()
33226 assert( acc.nChar>0 || acc.accError ); in sqlite3TreeViewLine()
33254 for(i=0; i<nCol; i++){ in sqlite3TreeViewColumnList()
33258 sqlite3TreeViewLine(pView, 0); in sqlite3TreeViewColumnList()
33294 if( pWith==0 ) return; in sqlite3TreeViewWith()
33295 if( pWith->nCte==0 ) return; in sqlite3TreeViewWith()
33297 sqlite3TreeViewLine(pView, "WITH (0x%p, pOuter=0x%p)",pWith,pWith->pOuter); in sqlite3TreeViewWith()
33299 sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith); in sqlite3TreeViewWith()
33301 if( pWith->nCte>0 ){ in sqlite3TreeViewWith()
33303 for(i=0; i<pWith->nCte; i++){ in sqlite3TreeViewWith()
33307 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); in sqlite3TreeViewWith()
33309 if( pCte->pCols && pCte->pCols->nExpr>0 ){ in sqlite3TreeViewWith()
33312 for(j=0; j<pCte->pCols->nExpr; j++){ in sqlite3TreeViewWith()
33323 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse, in sqlite3TreeViewWith()
33328 sqlite3TreeViewSelect(pView, pCte->pSelect, 0); in sqlite3TreeViewWith()
33340 if( pSrc==0 ) return; in sqlite3TreeViewSrcList()
33341 for(i=0; i<pSrc->nSrc; i++){ in sqlite3TreeViewSrcList()
33344 int n = 0; in sqlite3TreeViewSrcList()
33346 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); in sqlite3TreeViewSrcList()
33376 if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){ in sqlite3TreeViewSrcList()
33391 n = 0; in sqlite3TreeViewSrcList()
33396 sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING"); in sqlite3TreeViewSrcList()
33405 sqlite3TreeViewSelect(pView, pItem->u4.pSubq->pSelect, 0); in sqlite3TreeViewSrcList()
33408 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); in sqlite3TreeViewSrcList()
33418 int n = 0; in sqlite3TreeViewSelect()
33419 int cnt = 0; in sqlite3TreeViewSelect()
33420 if( p==0 ){ in sqlite3TreeViewSelect()
33435 "SELECT%s%s (%u/%p) selFlags=0x%x nSelectRow=%d", in sqlite3TreeViewSelect()
33446 n = 0; in sqlite3TreeViewSelect()
33459 sqlite3TreeViewExprList(pView, p->pEList, n>0, "result-set"); in sqlite3TreeViewSelect()
33465 sqlite3TreeViewPush(&pView, (n--)>0); in sqlite3TreeViewSelect()
33468 sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0); in sqlite3TreeViewSelect()
33474 sqlite3TreeViewPush(&pView, (n--)>0); in sqlite3TreeViewSelect()
33480 sqlite3TreeViewItem(pView, "WHERE", (n--)>0); in sqlite3TreeViewSelect()
33481 sqlite3TreeViewExpr(pView, p->pWhere, 0); in sqlite3TreeViewSelect()
33485 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY"); in sqlite3TreeViewSelect()
33488 sqlite3TreeViewItem(pView, "HAVING", (n--)>0); in sqlite3TreeViewSelect()
33489 sqlite3TreeViewExpr(pView, p->pHaving, 0); in sqlite3TreeViewSelect()
33495 sqlite3TreeViewItem(pView, "WINDOW", (n--)>0); in sqlite3TreeViewSelect()
33497 sqlite3TreeViewWindow(pView, pX, pX->pNextWin!=0); in sqlite3TreeViewSelect()
33503 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY"); in sqlite3TreeViewSelect()
33506 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0); in sqlite3TreeViewSelect()
33507 sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0); in sqlite3TreeViewSelect()
33509 sqlite3TreeViewItem(pView, "OFFSET", 0); in sqlite3TreeViewSelect()
33510 sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0); in sqlite3TreeViewSelect()
33525 }while( p!=0 ); in sqlite3TreeViewSelect()
33552 sqlite3TreeViewExpr(pView, pExpr, 0); in sqlite3TreeViewBound()
33558 sqlite3TreeViewExpr(pView, pExpr, 0); in sqlite3TreeViewBound()
33571 int nElement = 0; in sqlite3TreeViewWindow()
33572 if( pWin==0 ) return; in sqlite3TreeViewWindow()
33575 sqlite3TreeViewExpr(pView, pWin->pFilter, 0); in sqlite3TreeViewWindow()
33587 if( pWin->eFrmType!=0 && pWin->eFrmType!=TK_FILTER ) nElement++; in sqlite3TreeViewWindow()
33590 sqlite3TreeViewPush(&pView, (--nElement)>0); in sqlite3TreeViewWindow()
33595 sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY"); in sqlite3TreeViewWindow()
33598 sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY"); in sqlite3TreeViewWindow()
33600 if( pWin->eFrmType!=0 && pWin->eFrmType!=TK_FILTER ){ in sqlite3TreeViewWindow()
33607 sqlite3TreeViewItem(pView, zBuf, (--nElement)>0); in sqlite3TreeViewWindow()
33609 sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0); in sqlite3TreeViewWindow()
33625 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewWindow()
33638 if( pWin==0 ) return; in sqlite3TreeViewWinFunc()
33642 sqlite3TreeViewWindow(pView, pWin, 0); in sqlite3TreeViewWinFunc()
33651 const char *zBinOp = 0; /* Binary operator */ in sqlite3TreeViewExpr()
33652 const char *zUniOp = 0; /* Unary operator */ in sqlite3TreeViewExpr()
33655 if( pExpr==0 ){ in sqlite3TreeViewExpr()
33662 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); in sqlite3TreeViewExpr()
33677 if( pExpr->pAggInfo!=0 ){ in sqlite3TreeViewExpr()
33682 zFlgs[0] = 0; in sqlite3TreeViewExpr()
33691 if( pExpr->iTable<0 ){ in sqlite3TreeViewExpr()
33695 sqlite3_snprintf(sizeof(zOp2),zOp2," op2=0x%02x",pExpr->op2); in sqlite3TreeViewExpr()
33697 zOp2[0] = 0; in sqlite3TreeViewExpr()
33708 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33768 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33819 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33833 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33842 pFarg = 0; in sqlite3TreeViewExpr()
33843 pWin = 0; in sqlite3TreeViewExpr()
33848 pWin = IsWindowFunc(pExpr) ? pExpr->y.pWin : 0; in sqlite3TreeViewExpr()
33850 pWin = 0; in sqlite3TreeViewExpr()
33857 pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0, in sqlite3TreeViewExpr()
33859 }else if( pExpr->op2!=0 ){ in sqlite3TreeViewExpr()
33862 sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2); in sqlite3TreeViewExpr()
33874 sqlite3TreeViewExprList(pView, pFarg, pWin!=0 || pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33879 sqlite3TreeViewExprList(pView, pOB->x.pList, pWin!=0, "ORDERBY"); in sqlite3TreeViewExpr()
33884 sqlite3TreeViewWindow(pView, pWin, 0); in sqlite3TreeViewExpr()
33890 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, "ORDERBY"); in sqlite3TreeViewExpr()
33896 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags); in sqlite3TreeViewExpr()
33897 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); in sqlite3TreeViewExpr()
33902 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags); in sqlite3TreeViewExpr()
33903 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); in sqlite3TreeViewExpr()
33907 sqlite3_str *pStr = sqlite3_str_new(0); in sqlite3TreeViewExpr()
33909 sqlite3_str_appendf(pStr, "IN flags=0x%x", pExpr->flags); in sqlite3TreeViewExpr()
33920 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); in sqlite3TreeViewExpr()
33922 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); in sqlite3TreeViewExpr()
33936 ** Y is stored in pExpr->pList->a[0].pExpr. in sqlite3TreeViewExpr()
33944 pY = pExpr->x.pList->a[0].pExpr; in sqlite3TreeViewExpr()
33949 sqlite3TreeViewExpr(pView, pZ, 0); in sqlite3TreeViewExpr()
33956 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn in sqlite3TreeViewExpr()
33968 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); in sqlite3TreeViewExpr()
33982 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33989 sqlite3TreeViewExpr(pView, pExpr->pRight, 0); in sqlite3TreeViewExpr()
34000 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s", in sqlite3TreeViewExpr()
34004 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0); in sqlite3TreeViewExpr()
34009 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
34017 sqlite3TreeViewExpr(pView, &tmp, 0); in sqlite3TreeViewExpr()
34021 if( pExpr->iColumn<=0 ){ in sqlite3TreeViewExpr()
34037 sqlite3TreeViewExpr(pView, pExpr->pRight, 0); in sqlite3TreeViewExpr()
34040 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
34054 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; in sqlite3TreeViewBareExprList()
34055 if( pList==0 ){ in sqlite3TreeViewBareExprList()
34060 for(i=0; i<pList->nExpr; i++){ in sqlite3TreeViewBareExprList()
34067 moreToFollow = 0; in sqlite3TreeViewBareExprList()
34068 sqlite3TreeViewLine(pView, 0); in sqlite3TreeViewBareExprList()
34122 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; in sqlite3TreeViewBareIdList()
34123 if( pList==0 ){ in sqlite3TreeViewBareIdList()
34128 for(i=0; i<pList->nId; i++){ in sqlite3TreeViewBareIdList()
34131 if( zName==0 ) zName = "(null)"; in sqlite3TreeViewBareIdList()
34133 sqlite3TreeViewLine(pView, 0); in sqlite3TreeViewBareIdList()
34158 if( pUpsert==0 ) return; in sqlite3TreeViewUpsert()
34162 sqlite3TreeViewPush(&pView, pUpsert->pNextUpsert!=0 || moreToFollow); in sqlite3TreeViewUpsert()
34165 n = (pUpsert->pUpsertSet!=0) + (pUpsert->pUpsertWhere!=0); in sqlite3TreeViewUpsert()
34166 sqlite3TreeViewExprList(pView, pUpsert->pUpsertTarget, (n--)>0, "TARGET"); in sqlite3TreeViewUpsert()
34167 sqlite3TreeViewExprList(pView, pUpsert->pUpsertSet, (n--)>0, "SET"); in sqlite3TreeViewUpsert()
34169 sqlite3TreeViewItem(pView, "WHERE", (n--)>0); in sqlite3TreeViewUpsert()
34170 sqlite3TreeViewExpr(pView, pUpsert->pUpsertWhere, 0); in sqlite3TreeViewUpsert()
34192 int n = 0; in sqlite3TreeViewDelete()
34193 TreeView *pView = 0; in sqlite3TreeViewDelete()
34194 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewDelete()
34203 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewDelete()
34204 sqlite3TreeViewWith(pView, pWith, 0); in sqlite3TreeViewDelete()
34208 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewDelete()
34214 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewDelete()
34216 sqlite3TreeViewExpr(pView, pWhere, 0); in sqlite3TreeViewDelete()
34220 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); in sqlite3TreeViewDelete()
34223 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewDelete()
34225 sqlite3TreeViewExpr(pView, pLimit, 0); in sqlite3TreeViewDelete()
34229 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); in sqlite3TreeViewDelete()
34250 TreeView *pView = 0; in sqlite3TreeViewInsert()
34251 int n = 0; in sqlite3TreeViewInsert()
34260 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewInsert()
34270 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewInsert()
34271 sqlite3TreeViewWith(pView, pWith, 0); in sqlite3TreeViewInsert()
34275 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewInsert()
34281 sqlite3TreeViewIdList(pView, pColumnList, (--n)>0, "COLUMNS"); in sqlite3TreeViewInsert()
34284 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewInsert()
34286 sqlite3TreeViewSelect(pView, pSelect, 0); in sqlite3TreeViewInsert()
34290 sqlite3TreeViewExprList(pView, pExprList, (--n)>0, "VALUES"); in sqlite3TreeViewInsert()
34293 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewInsert()
34295 sqlite3TreeViewUpsert(pView, pUpsert, 0); in sqlite3TreeViewInsert()
34299 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); in sqlite3TreeViewInsert()
34321 int n = 0; in sqlite3TreeViewUpdate()
34322 TreeView *pView = 0; in sqlite3TreeViewUpdate()
34331 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewUpdate()
34342 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
34343 sqlite3TreeViewWith(pView, pWith, 0); in sqlite3TreeViewUpdate()
34347 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
34353 sqlite3TreeViewExprList(pView, pChanges, (--n)>0, "SET"); in sqlite3TreeViewUpdate()
34356 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
34358 sqlite3TreeViewExpr(pView, pWhere, 0); in sqlite3TreeViewUpdate()
34362 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); in sqlite3TreeViewUpdate()
34365 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
34367 sqlite3TreeViewExpr(pView, pLimit, 0); in sqlite3TreeViewUpdate()
34371 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
34373 sqlite3TreeViewUpsert(pView, pUpsert, 0); in sqlite3TreeViewUpdate()
34377 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); in sqlite3TreeViewUpdate()
34393 int cnt = 0; in sqlite3TreeViewTriggerStep()
34394 if( pStep==0 ) return; in sqlite3TreeViewTriggerStep()
34396 moreToFollow || (showFullList && pStep->pNext!=0)); in sqlite3TreeViewTriggerStep()
34398 if( cnt++ && pStep->pNext==0 ){ in sqlite3TreeViewTriggerStep()
34400 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewTriggerStep()
34403 }while( showFullList && (pStep = pStep->pNext)!=0 ); in sqlite3TreeViewTriggerStep()
34416 int cnt = 0; in sqlite3TreeViewTrigger()
34417 if( pTrigger==0 ) return; in sqlite3TreeViewTrigger()
34419 moreToFollow || (showFullList && pTrigger->pNext!=0)); in sqlite3TreeViewTrigger()
34421 if( cnt++ && pTrigger->pNext==0 ){ in sqlite3TreeViewTrigger()
34423 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewTrigger()
34426 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewTrigger()
34427 sqlite3TreeViewTriggerStep(pView, pTrigger->step_list, 0, 1); in sqlite3TreeViewTrigger()
34429 }while( showFullList && (pTrigger = pTrigger->pNext)!=0 ); in sqlite3TreeViewTrigger()
34449 SQLITE_PRIVATE void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); } in sqlite3ShowExpr()
34450 SQLITE_PRIVATE void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);} in sqlite3ShowExprList()
34451 SQLITE_PRIVATE void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); } in sqlite3ShowIdList()
34452 SQLITE_PRIVATE void sqlite3ShowSrcList(const SrcList *p){ sqlite3TreeViewSrcList(0,p); } in sqlite3ShowSrcList()
34453 SQLITE_PRIVATE void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); } in sqlite3ShowSelect()
34454 SQLITE_PRIVATE void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); } in sqlite3ShowWith()
34455 SQLITE_PRIVATE void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); } in sqlite3ShowUpsert()
34458 sqlite3TreeViewTriggerStep(0,p,0,0); in sqlite3ShowTriggerStep()
34461 sqlite3TreeViewTriggerStep(0,p,0,1); in sqlite3ShowTriggerStepList()
34463 SQLITE_PRIVATE void sqlite3ShowTrigger(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,0); } in sqlite3ShowTrigger()
34464 SQLITE_PRIVATE void sqlite3ShowTriggerList(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,1);} in sqlite3ShowTriggerList()
34467 SQLITE_PRIVATE void sqlite3ShowWindow(const Window *p){ sqlite3TreeViewWindow(0,p,0); } in sqlite3ShowWindow()
34468 SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window *p){ sqlite3TreeViewWinFunc(0,p,0); } in sqlite3ShowWinFunc()
34517 for(i=0; i<10; i++){ in chacha_block()
34518 QR(x[0], x[4], x[ 8], x[12]); in chacha_block()
34522 QR(x[0], x[5], x[10], x[15]); in chacha_block()
34527 for(i=0; i<16; i++) out[i] = x[i]+in[i]; in chacha_block()
34544 # define wsdPrng p[0] in sqlite3_randomness()
34562 if( N<=0 || pBuf==0 ){ in sqlite3_randomness()
34563 wsdPrng.s[0] = 0; in sqlite3_randomness()
34571 if( wsdPrng.s[0]==0 ){ in sqlite3_randomness()
34572 sqlite3_vfs *pVfs = sqlite3_vfs_find(0); in sqlite3_randomness()
34574 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 in sqlite3_randomness()
34576 memcpy(&wsdPrng.s[0], chacha20_init, 16); in sqlite3_randomness()
34577 if( NEVER(pVfs==0) ){ in sqlite3_randomness()
34578 memset(&wsdPrng.s[4], 0, 44); in sqlite3_randomness()
34583 wsdPrng.s[12] = 0; in sqlite3_randomness()
34584 wsdPrng.n = 0; in sqlite3_randomness()
34587 assert( N>0 ); in sqlite3_randomness()
34594 if( wsdPrng.n>0 ){ in sqlite3_randomness()
34667 #if SQLITE_MAX_WORKER_THREADS>0
34670 #if SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) && SQLITE_THREADSAFE>0
34693 assert( ppThread!=0 ); in sqlite3ThreadCreate()
34694 assert( xTask!=0 ); in sqlite3ThreadCreate()
34696 assert( sqlite3GlobalConfig.bCoreMutex!=0 ); in sqlite3ThreadCreate()
34698 *ppThread = 0; in sqlite3ThreadCreate()
34700 if( p==0 ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadCreate()
34701 memset(p, 0, sizeof(*p)); in sqlite3ThreadCreate()
34711 rc = pthread_create(&p->tid, 0, xTask, pIn); in sqlite3ThreadCreate()
34725 assert( ppOut!=0 ); in sqlite3ThreadJoin()
34726 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadJoin()
34762 assert( p!=0 ); in sqlite3ThreadProc()
34763 #if 0 in sqlite3ThreadProc()
34772 assert( p->xTask!=0 ); in sqlite3ThreadProc()
34775 _endthreadex(0); in sqlite3ThreadProc()
34776 return 0; /* NOT REACHED */ in sqlite3ThreadProc()
34787 assert( ppThread!=0 ); in sqlite3ThreadCreate()
34788 assert( xTask!=0 ); in sqlite3ThreadCreate()
34789 *ppThread = 0; in sqlite3ThreadCreate()
34791 if( p==0 ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadCreate()
34797 if( sqlite3GlobalConfig.bCoreMutex==0 || sqlite3FaultSim(200) ){ in sqlite3ThreadCreate()
34798 memset(p, 0, sizeof(*p)); in sqlite3ThreadCreate()
34802 p->tid = (void*)_beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id); in sqlite3ThreadCreate()
34803 if( p->tid==0 ){ in sqlite3ThreadCreate()
34804 memset(p, 0, sizeof(*p)); in sqlite3ThreadCreate()
34807 if( p->xTask==0 ){ in sqlite3ThreadCreate()
34822 assert( ppOut!=0 ); in sqlite3ThreadJoin()
34823 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadJoin()
34824 if( p->xTask==0 ){ in sqlite3ThreadJoin()
34827 assert( p->tid==0 ); in sqlite3ThreadJoin()
34829 assert( p->id!=0 && p->id!=GetCurrentThreadId() ); in sqlite3ThreadJoin()
34867 assert( ppThread!=0 ); in sqlite3ThreadCreate()
34868 assert( xTask!=0 ); in sqlite3ThreadCreate()
34869 *ppThread = 0; in sqlite3ThreadCreate()
34871 if( p==0 ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadCreate()
34876 p->xTask = 0; in sqlite3ThreadCreate()
34886 assert( ppOut!=0 ); in sqlite3ThreadJoin()
34887 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadJoin()
34908 #endif /* SQLITE_MAX_WORKER_THREADS>0 */
34928 ** Byte-0 Byte-1 Byte-2 Byte-3 Value
34929 ** 0xxxxxxx 00000000 00000000 0xxxxxxx
34937 ** Word-0 Word-1 Value
34943 ** 0xff 0xfe little-endian utf-16 follows
34944 ** 0xfe 0xff big-endian utf-16 follows
34951 #if !defined(SQLITE_AMALGAMATION) && SQLITE_BYTEORDER==0
34957 #endif /* SQLITE_AMALGAMATION && SQLITE_BYTEORDER==0 */
34964 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
34965 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
34966 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
34967 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
34968 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
34969 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
34970 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
34971 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
34976 if( c<0x00080 ){ \
34977 *zOut++ = (u8)(c&0xFF); \
34979 else if( c<0x00800 ){ \
34980 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \
34981 *zOut++ = 0x80 + (u8)(c & 0x3F); \
34983 else if( c<0x10000 ){ \
34984 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \
34985 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
34986 *zOut++ = 0x80 + (u8)(c & 0x3F); \
34988 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07); \
34989 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \
34990 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
34991 *zOut++ = 0x80 + (u8)(c & 0x3F); \
34996 if( c<=0xFFFF ){ \
34997 *zOut++ = (u8)(c&0x00FF); \
34998 *zOut++ = (u8)((c>>8)&0x00FF); \
35000 *zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
35001 *zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03)); \
35002 *zOut++ = (u8)(c&0x00FF); \
35003 *zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); \
35008 if( c<=0xFFFF ){ \
35009 *zOut++ = (u8)((c>>8)&0x00FF); \
35010 *zOut++ = (u8)(c&0x00FF); \
35012 *zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03)); \
35013 *zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
35014 *zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); \
35015 *zOut++ = (u8)(c&0x00FF); \
35026 if( v<0x00080 ){ in sqlite3AppendOneUtf8Character()
35027 zOut[0] = (u8)(v & 0xff); in sqlite3AppendOneUtf8Character()
35030 if( v<0x00800 ){ in sqlite3AppendOneUtf8Character()
35031 zOut[0] = 0xc0 + (u8)((v>>6) & 0x1f); in sqlite3AppendOneUtf8Character()
35032 zOut[1] = 0x80 + (u8)(v & 0x3f); in sqlite3AppendOneUtf8Character()
35035 if( v<0x10000 ){ in sqlite3AppendOneUtf8Character()
35036 zOut[0] = 0xe0 + (u8)((v>>12) & 0x0f); in sqlite3AppendOneUtf8Character()
35037 zOut[1] = 0x80 + (u8)((v>>6) & 0x3f); in sqlite3AppendOneUtf8Character()
35038 zOut[2] = 0x80 + (u8)(v & 0x3f); in sqlite3AppendOneUtf8Character()
35041 zOut[0] = 0xf0 + (u8)((v>>18) & 0x07); in sqlite3AppendOneUtf8Character()
35042 zOut[1] = 0x80 + (u8)((v>>12) & 0x3f); in sqlite3AppendOneUtf8Character()
35043 zOut[2] = 0x80 + (u8)((v>>6) & 0x3f); in sqlite3AppendOneUtf8Character()
35044 zOut[3] = 0x80 + (u8)(v & 0x3f); in sqlite3AppendOneUtf8Character()
35052 ** is a 0x00.
35058 ** * This routine never allows a 7-bit character (0x00 through 0x7f) to
35060 ** attempts to encode a value between 0x00 and 0x7f is rendered as 0xfffd.
35064 ** 0xd800 and 0xe000 then it is rendered as 0xfffd.
35066 ** * Bytes in the range of 0x80 through 0xbf which occur as the first
35072 ** for unicode values 0x80 and greater. It does not change over-length
35073 ** encodings to 0xfffd as some systems recommend.
35077 if( c>=0xc0 ){ \
35078 c = sqlite3Utf8Trans1[c-0xc0]; \
35079 while( zIn<zTerm && (*zIn & 0xc0)==0x80 ){ \
35080 c = (c<<6) + (0x3f & *(zIn++)); \
35082 if( c<0x80 \
35083 || (c&0xFFFFF800)==0xD800 \
35084 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
35095 if( c>=0xc0 ){ in sqlite3Utf8Read()
35096 c = sqlite3Utf8Trans1[c-0xc0]; in sqlite3Utf8Read()
35097 while( (*(*pz) & 0xc0)==0x80 ){ in sqlite3Utf8Read()
35098 c = (c<<6) + (0x3f & *((*pz)++)); in sqlite3Utf8Read()
35100 if( c<0x80 in sqlite3Utf8Read()
35101 || (c&0xFFFFF800)==0xD800 in sqlite3Utf8Read()
35102 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } in sqlite3Utf8Read()
35126 assert( n>0 ); in sqlite3Utf8ReadLimited()
35127 c = z[0]; in sqlite3Utf8ReadLimited()
35128 if( c>=0xc0 ){ in sqlite3Utf8ReadLimited()
35129 c = sqlite3Utf8Trans1[c-0xc0]; in sqlite3Utf8ReadLimited()
35131 while( i<n && (z[i] & 0xc0)==0x80 ){ in sqlite3Utf8ReadLimited()
35132 c = (c<<6) + (0x3f & z[i]); in sqlite3Utf8ReadLimited()
35161 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); in sqlite3VdbeMemTranslate()
35164 assert( pMem->enc!=0 ); in sqlite3VdbeMemTranslate()
35165 assert( pMem->n>=0 ); in sqlite3VdbeMemTranslate()
35171 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); in sqlite3VdbeMemTranslate()
35249 *z++ = 0; in sqlite3VdbeMemTranslate()
35257 if( c>=0xd800 && c<0xe000 ){ in sqlite3VdbeMemTranslate()
35259 if( c>=0xdc00 || zIn>=zTerm ){ in sqlite3VdbeMemTranslate()
35260 c = 0xfffd; in sqlite3VdbeMemTranslate()
35264 if( c2<0xdc00 || c2>=0xe000 ){ in sqlite3VdbeMemTranslate()
35266 c = 0xfffd; in sqlite3VdbeMemTranslate()
35268 c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; in sqlite3VdbeMemTranslate()
35275 c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); in sqlite3VdbeMemTranslate()
35286 if( c>=0xd800 && c<0xe000 ){ in sqlite3VdbeMemTranslate()
35288 if( c>=0xdc00 || zIn>=zTerm ){ in sqlite3VdbeMemTranslate()
35289 c = 0xfffd; in sqlite3VdbeMemTranslate()
35293 if( c2<0xdc00 || c2>=0xe000 ){ in sqlite3VdbeMemTranslate()
35295 c = 0xfffd; in sqlite3VdbeMemTranslate()
35297 c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; in sqlite3VdbeMemTranslate()
35304 c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); in sqlite3VdbeMemTranslate()
35313 *z = 0; in sqlite3VdbeMemTranslate()
35329 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); in sqlite3VdbeMemTranslate()
35350 u8 bom = 0; in sqlite3VdbeMemHandleBom()
35352 assert( pMem->n>=0 ); in sqlite3VdbeMemHandleBom()
35356 if( b1==0xFE && b2==0xFF ){ in sqlite3VdbeMemHandleBom()
35359 if( b1==0xFF && b2==0xFE ){ in sqlite3VdbeMemHandleBom()
35369 pMem->z[pMem->n] = '\0'; in sqlite3VdbeMemHandleBom()
35370 pMem->z[pMem->n+1] = '\0'; in sqlite3VdbeMemHandleBom()
35382 ** the first 0x00 byte. If nByte is not less than zero, return the
35384 ** the first 0x00, whichever comes first).
35387 int r = 0; in sqlite3Utf8CharLen()
35390 if( nByte>=0 ){ in sqlite3Utf8CharLen()
35396 while( *z!=0 && z<zTerm ){ in sqlite3Utf8CharLen()
35421 while( zIn[0] && zOut<=zIn ){ in sqlite3Utf8To8()
35423 if( c!=0xfffd ){ in sqlite3Utf8To8()
35427 *zOut = 0; in sqlite3Utf8To8()
35442 memset(&m, 0, sizeof(m)); in sqlite3Utf16to8()
35448 m.z = 0; in sqlite3Utf16to8()
35450 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed ); in sqlite3Utf16to8()
35451 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed ); in sqlite3Utf16to8()
35466 int n = 0; in sqlite3Utf16ByteLen()
35470 c = z[0]; in sqlite3Utf16ByteLen()
35472 if( c>=0xd8 && c<0xdc && z<=zEnd && z[0]>=0xdc && z[0]<0xe0 ) z += 2; in sqlite3Utf16ByteLen()
35492 for(i=0; i<0x00110000; i++){ in sqlite3UtfSelfTest()
35496 assert( n>0 && n<=4 ); in sqlite3UtfSelfTest()
35497 z[0] = 0; in sqlite3UtfSelfTest()
35501 if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD; in sqlite3UtfSelfTest()
35502 if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD; in sqlite3UtfSelfTest()
35540 ** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0). The
35604 if( z==0 ) return 0; in sqlite3Strlen30()
35605 return 0x3fffffff & (int)strlen(z); in sqlite3Strlen30()
35642 assert( db!=0 ); in sqlite3Error()
35656 assert( db!=0 ); in sqlite3ErrorClear()
35673 for(ii=0; ii<db->nDb; ii++){ in sqlite3SystemError()
35685 rc &= 0xff; in sqlite3SystemError()
35704 assert( db!=0 ); in sqlite3ErrorWithMsg()
35707 if( zFormat==0 ){ in sqlite3ErrorWithMsg()
35709 }else if( db->pErr || (db->pErr = sqlite3ValueNew(db))!=0 ){ in sqlite3ErrorWithMsg()
35731 p->nProgressSteps = 0; in sqlite3ProgressCheck()
35737 p->nProgressSteps = 0; in sqlite3ProgressCheck()
35757 assert( db!=0 ); in sqlite3ErrorMsg()
35775 pParse->pWith = 0; in sqlite3ErrorMsg()
35786 if( db==0 || (pParse = db->pParse)==0 ) return errCode; in sqlite3ErrorToParser()
35812 if( z==0 ) return; in sqlite3Dequote()
35813 quote = z[0]; in sqlite3Dequote()
35816 for(i=1, j=0;; i++){ in sqlite3Dequote()
35829 z[j] = 0; in sqlite3Dequote()
35833 assert( sqlite3Isquote(p->u.zToken[0]) ); in sqlite3DequoteExpr()
35834 p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted; in sqlite3DequoteExpr()
35844 assert( p!=0 || pParse->db->mallocFailed ); in sqlite3DequoteNumber()
35848 int bHex = (pIn[0]=='0' && (pIn[1]=='x' || pIn[1]=='X')); in sqlite3DequoteNumber()
35857 if( (bHex==0 && (!sqlite3Isdigit(pIn[-1]) || !sqlite3Isdigit(pIn[1]))) in sqlite3DequoteNumber()
35890 if( !sqlite3Isquote(p->z[0]) ) return; in sqlite3DequoteToken()
35920 if( zLeft==0 ){ in sqlite3_stricmp()
35921 return zRight ? -1 : 0; in sqlite3_stricmp()
35922 }else if( zRight==0 ){ in sqlite3_stricmp()
35936 if( c==0 ) break; in sqlite3StrICmp()
35948 if( zLeft==0 ){ in sqlite3_strnicmp()
35949 return zRight ? -1 : 0; in sqlite3_strnicmp()
35950 }else if( zRight==0 ){ in sqlite3_strnicmp()
35955 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } in sqlite3_strnicmp()
35956 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; in sqlite3_strnicmp()
35963 u8 h = 0; in sqlite3StrIHash()
35964 if( z==0 ) return 0; in sqlite3StrIHash()
35965 while( z[0] ){ in sqlite3StrIHash()
35966 h += UpperToLower[(unsigned char)z[0]]; in sqlite3StrIHash()
35972 /* Double-Double multiplication. (x[0],x[1]) *= (y,yy)
35990 memcpy(&m, (void*)&x[0], 8); in dekkerMul2()
35991 m &= 0xfffffffffc000000LL; in dekkerMul2()
35993 tx = x[0] - hx; in dekkerMul2()
35995 m &= 0xfffffffffc000000LL; in dekkerMul2()
36002 cc = x[0]*yy + x[1]*y + cc; in dekkerMul2()
36003 x[0] = c + cc; in dekkerMul2()
36004 x[1] = c - x[0]; in dekkerMul2()
36020 ** 0 or less => The input string is not a valid number
36046 u64 s = 0; /* significand */ in sqlite3AtoF()
36047 int d = 0; /* adjust exponent for shifting decimal point */ in sqlite3AtoF()
36049 int e = 0; /* exponent */ in sqlite3AtoF()
36051 int nDigit = 0; /* Number of digits processed */ in sqlite3AtoF()
36058 if( length==0 ) return 0; in sqlite3AtoF()
36070 for(i=3-enc; i<length && z[i]==0; i+=2){} in sqlite3AtoF()
36078 if( z>=zEnd ) return 0; in sqlite3AtoF()
36090 s = s*10 + (*z - '0'); in sqlite3AtoF()
36108 s = s*10 + (*z - '0'); in sqlite3AtoF()
36120 eValid = 0; in sqlite3AtoF()
36137 e = e<10000 ? (e*10 + (*z - '0')) : 10000; in sqlite3AtoF()
36148 if( s==0 ){ in sqlite3AtoF()
36149 *pResult = sign<0 ? -0.0 : +0.0; in sqlite3AtoF()
36157 while( e>0 && s<((LARGEST_UINT64-0x7ff)/10) ){ in sqlite3AtoF()
36161 while( e<0 && (s%10)==0 ){ in sqlite3AtoF()
36166 rr[0] = (double)s; in sqlite3AtoF()
36167 assert( sizeof(s2)==sizeof(rr[0]) ); in sqlite3AtoF()
36171 assert( s2==0x43efffffffffffffLL ); in sqlite3AtoF()
36175 if( rr[0]<=18446744073709549568.0 ){ in sqlite3AtoF()
36176 s2 = (u64)rr[0]; in sqlite3AtoF()
36181 assert( rr[1]<=1.0e-10*rr[0] ); /* Equal only when rr[0]==0.0 */ in sqlite3AtoF()
36183 if( e>0 ){ in sqlite3AtoF()
36210 *pResult = rr[0]+rr[1]; in sqlite3AtoF()
36212 if( sign<0 ) *pResult = -*pResult; in sqlite3AtoF()
36217 if( z==zEnd && nDigit>0 && eValid && eType>0 ){ in sqlite3AtoF()
36219 }else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){ in sqlite3AtoF()
36222 return 0; in sqlite3AtoF()
36244 if( v<0 ){ in sqlite3Int64ToText()
36250 zTemp[sizeof(zTemp)-1] = 0; in sqlite3Int64ToText()
36252 zTemp[i] = (x%10) + '0'; in sqlite3Int64ToText()
36254 if( x==0 ) break; in sqlite3Int64ToText()
36257 if( v<0 ) zTemp[--i] = '-'; in sqlite3Int64ToText()
36277 int c = 0; in compare2pow63()
36281 for(i=0; c==0 && i<18; i++){ in compare2pow63()
36284 if( c==0 ){ in compare2pow63()
36287 testcase( c==0 ); in compare2pow63()
36300 ** 0 Successful transformation. Fits in a 64-bit signed integer.
36311 u64 u = 0; in sqlite3Atoi64()
36312 int neg = 0; /* assume positive */ in sqlite3Atoi64()
36314 int c = 0; in sqlite3Atoi64()
36315 int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */ in sqlite3Atoi64()
36326 for(i=3-enc; i<length && zNum[i]==0; i+=2){} in sqlite3Atoi64()
36341 while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */ in sqlite3Atoi64()
36342 for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){ in sqlite3Atoi64()
36343 u = u*10 + c - '0'; in sqlite3Atoi64()
36359 rc = 0; in sqlite3Atoi64()
36360 if( i==0 && zStart==zNum ){ /* No digits */ in sqlite3Atoi64()
36381 if( c<0 ){ in sqlite3Atoi64()
36387 if( c>0 ){ in sqlite3Atoi64()
36407 ** 0 Successful transformation. Fits in a 64-bit signed integer.
36414 if( z[0]=='0' in sqlite3DecOrHexToI64()
36417 u64 u = 0; in sqlite3DecOrHexToI64()
36419 for(i=2; z[i]=='0'; i++){} in sqlite3DecOrHexToI64()
36425 if( z[k]!=0 ) return 1; in sqlite3DecOrHexToI64()
36426 return 0; in sqlite3DecOrHexToI64()
36430 int n = (int)(0x3fffffff&strspn(z,"+- \n\t0123456789")); in sqlite3DecOrHexToI64()
36447 sqlite_int64 v = 0; in sqlite3GetInt32()
36449 int neg = 0; in sqlite3GetInt32()
36450 if( zNum[0]=='-' ){ in sqlite3GetInt32()
36453 }else if( zNum[0]=='+' ){ in sqlite3GetInt32()
36457 else if( zNum[0]=='0' in sqlite3GetInt32()
36461 u32 u = 0; in sqlite3GetInt32()
36463 while( zNum[0]=='0' ) zNum++; in sqlite3GetInt32()
36464 for(i=0; i<8 && sqlite3Isxdigit(zNum[i]); i++){ in sqlite3GetInt32()
36467 if( (u&0x80000000)==0 && sqlite3Isxdigit(zNum[i])==0 ){ in sqlite3GetInt32()
36471 return 0; in sqlite3GetInt32()
36475 if( !sqlite3Isdigit(zNum[0]) ) return 0; in sqlite3GetInt32()
36476 while( zNum[0]=='0' ) zNum++; in sqlite3GetInt32()
36477 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){ in sqlite3GetInt32()
36488 return 0; in sqlite3GetInt32()
36492 return 0; in sqlite3GetInt32()
36503 ** string is not an integer, just return 0.
36506 int x = 0; in sqlite3Atoi()
36515 ** If iRound<=0 then round to -iRound significant digits to the
36519 ** If iRound>0 round to min(iRound,mxRound) significant digits total.
36531 int e, exp = 0; in sqlite3FpDecode()
36534 p->isSpecial = 0; in sqlite3FpDecode()
36536 assert( mxRound>0 ); in sqlite3FpDecode()
36547 p->z = "0"; in sqlite3FpDecode()
36554 if( (e&0x7ff)==0x7ff ){ in sqlite3FpDecode()
36555 p->isSpecial = 1 + (v!=0x7ff0000000000000LL); in sqlite3FpDecode()
36556 p->n = 0; in sqlite3FpDecode()
36557 p->iDP = 0; in sqlite3FpDecode()
36572 rr[0] = r; in sqlite3FpDecode()
36574 if( rr[0]>9.223372036854774784e+18 ){ in sqlite3FpDecode()
36575 while( rr[0]>9.223372036854774784e+118 ){ in sqlite3FpDecode()
36579 while( rr[0]>9.223372036854774784e+28 ){ in sqlite3FpDecode()
36583 while( rr[0]>9.223372036854774784e+18 ){ in sqlite3FpDecode()
36588 while( rr[0]<9.223372036854774784e-83 ){ in sqlite3FpDecode()
36592 while( rr[0]<9.223372036854774784e+07 ){ in sqlite3FpDecode()
36596 while( rr[0]<9.22337203685477478e+17 ){ in sqlite3FpDecode()
36601 v = rr[1]<0.0 ? (u64)rr[0]-(u64)(-rr[1]) : (u64)rr[0]+(u64)rr[1]; in sqlite3FpDecode()
36605 assert( v>0 ); in sqlite3FpDecode()
36606 while( v ){ p->zBuf[i--] = (v%10) + '0'; v /= 10; } in sqlite3FpDecode()
36607 assert( i>=0 && i<sizeof(p->zBuf)-1 ); in sqlite3FpDecode()
36609 assert( p->n>0 ); in sqlite3FpDecode()
36612 if( iRound<=0 ){ in sqlite3FpDecode()
36614 if( iRound==0 && p->zBuf[i+1]>='5' ){ in sqlite3FpDecode()
36616 p->zBuf[i--] = '0'; in sqlite3FpDecode()
36621 if( iRound>0 && (iRound<p->n || p->n>mxRound) ){ in sqlite3FpDecode()
36630 z[j] = '0'; in sqlite3FpDecode()
36631 if( j==0 ){ in sqlite3FpDecode()
36644 assert( p->n>0 ); in sqlite3FpDecode()
36645 while( p->z[p->n-1]=='0' ){ in sqlite3FpDecode()
36647 assert( p->n>0 ); in sqlite3FpDecode()
36658 u64 v = 0; in sqlite3GetUInt32()
36660 for(i=0; sqlite3Isdigit(z[i]); i++){ in sqlite3GetUInt32()
36661 v = v*10 + z[i] - '0'; in sqlite3GetUInt32()
36662 if( v>4294967296LL ){ *pI = 0; return 0; } in sqlite3GetUInt32()
36664 if( i==0 || z[i]!=0 ){ *pI = 0; return 0; } in sqlite3GetUInt32()
36673 ** A = 0xxxxxxx 7 bits of data and one flag bit
36689 ** Write a 64-bit variable-length integer to memory starting at p[0].
36701 if( v & (((u64)0xff000000)<<32) ){ in putVarint64()
36704 for(i=7; i>=0; i--){ in putVarint64()
36705 p[i] = (u8)((v & 0x7f) | 0x80); in putVarint64()
36710 n = 0; in putVarint64()
36712 buf[n++] = (u8)((v & 0x7f) | 0x80); in putVarint64()
36714 }while( v!=0 ); in putVarint64()
36715 buf[0] &= 0x7f; in putVarint64()
36717 for(i=0, j=n-1; j>=0; j--, i++){ in putVarint64()
36723 if( v<=0x7f ){ in sqlite3PutVarint()
36724 p[0] = v&0x7f; in sqlite3PutVarint()
36727 if( v<=0x3fff ){ in sqlite3PutVarint()
36728 p[0] = ((v>>7)&0x7f)|0x80; in sqlite3PutVarint()
36729 p[1] = v&0x7f; in sqlite3PutVarint()
36740 ** SLOT_2_0 A mask for (0x7f<<14) | 0x7f
36742 ** SLOT_4_2_0 A mask for (0x7f<<28) | SLOT_2_0
36744 #define SLOT_2_0 0x001fc07f
36745 #define SLOT_4_2_0 0xf01fc07f
36749 ** Read a 64-bit variable-length integer from memory starting at p[0].
36755 if( ((signed char*)p)[0]>=0 ){ in sqlite3GetVarint()
36759 if( ((signed char*)p)[1]>=0 ){ in sqlite3GetVarint()
36760 *v = ((u32)(p[0]&0x7f)<<7) | p[1]; in sqlite3GetVarint()
36765 assert( SLOT_2_0 == ((0x7f<<14) | (0x7f)) ); in sqlite3GetVarint()
36766 assert( SLOT_4_2_0 == ((0xfU<<28) | (0x7f<<14) | (0x7f)) ); in sqlite3GetVarint()
36768 a = ((u32)p[0])<<14; in sqlite3GetVarint()
36773 if (!(a&0x80)) in sqlite3GetVarint()
36776 b &= 0x7f; in sqlite3GetVarint()
36789 if (!(b&0x80)) in sqlite3GetVarint()
36793 /* a &= (0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36804 /* a &= (0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36813 if (!(a&0x80)) in sqlite3GetVarint()
36817 /* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36818 /* b &= (0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36835 if (!(b&0x80)) in sqlite3GetVarint()
36838 /* b &= (0x7f<<28)|(0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36851 if (!(a&0x80)) in sqlite3GetVarint()
36868 if (!(b&0x80)) in sqlite3GetVarint()
36872 /* a &= (0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36886 /* a &= (0x7f<<29)|(0x7f<<15)|(0xff); */ in sqlite3GetVarint()
36893 b &= 0x7f; in sqlite3GetVarint()
36903 ** Read a 32-bit variable-length integer from memory starting at p[0].
36906 ** If the varint stored in p[0] is larger than can fit in a 32-bit unsigned
36907 ** integer, then set *v to 0xffffffff.
36919 assert( (p[0] & 0x80)!=0 ); in sqlite3GetVarint32()
36921 if( (p[1] & 0x80)==0 ){ in sqlite3GetVarint32()
36923 *v = ((p[0]&0x7f)<<7) | p[1]; in sqlite3GetVarint32()
36926 if( (p[2] & 0x80)==0 ){ in sqlite3GetVarint32()
36928 *v = ((p[0]&0x7f)<<14) | ((p[1]&0x7f)<<7) | p[2]; in sqlite3GetVarint32()
36935 *v = 0xffffffff; in sqlite3GetVarint32()
36948 for(i=1; (v >>= 7)!=0; i++){ assert( i<10 ); } in sqlite3VarintLen()
36970 testcase( p[0]&0x80 ); in sqlite3Get4byte()
36971 return ((unsigned)p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]; in sqlite3Get4byte()
36984 p[0] = (u8)(v>>24); in sqlite3Put4byte()
36996 ** character: 0..9a..fA..F
36999 assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') ); in sqlite3HexToInt()
37006 return (u8)(h & 0xf); in sqlite3HexToInt()
37023 for(i=0; i<n; i+=2){ in sqlite3HexToBlob()
37026 zBlob[i/2] = 0; in sqlite3HexToBlob()
37049 ** 1 it means that the db pointer is valid and 0 if it should not be
37060 if( db==0 ){ in sqlite3SafetyCheckOk()
37062 return 0; in sqlite3SafetyCheckOk()
37067 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3SafetyCheckOk()
37070 return 0; in sqlite3SafetyCheckOk()
37081 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3SafetyCheckSickOrOk()
37083 return 0; in sqlite3SafetyCheckSickOrOk()
37092 ** Return 0 on success. Or if the operation would have resulted in an
37100 testcase( iA==0 ); testcase( iA==1 ); in sqlite3AddInt64()
37101 testcase( iB==-1 ); testcase( iB==0 ); in sqlite3AddInt64()
37102 if( iB>=0 ){ in sqlite3AddInt64()
37103 testcase( iA>0 && LARGEST_INT64 - iA == iB ); in sqlite3AddInt64()
37104 testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 ); in sqlite3AddInt64()
37105 if( iA>0 && LARGEST_INT64 - iA < iB ) return 1; in sqlite3AddInt64()
37107 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 ); in sqlite3AddInt64()
37108 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 ); in sqlite3AddInt64()
37109 if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1; in sqlite3AddInt64()
37112 return 0; in sqlite3AddInt64()
37121 testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); in sqlite3SubInt64()
37122 if( (*pA)>=0 ) return 1; in sqlite3SubInt64()
37124 return 0; in sqlite3SubInt64()
37135 if( iB>0 ){ in sqlite3MulInt64()
37138 }else if( iB<0 ){ in sqlite3MulInt64()
37139 if( iA>0 ){ in sqlite3MulInt64()
37141 }else if( iA<0 ){ in sqlite3MulInt64()
37148 return 0; in sqlite3MulInt64()
37157 if( x>=0 ) return x; in sqlite3AbsInt32()
37158 if( x==(int)0x80000000 ) return 0x7fffffff; in sqlite3AbsInt32()
37182 if( sqlite3_uri_boolean(zBaseFilename, "8_3_names", 0) ) in sqlite3FileSuffix3()
37187 for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){} in sqlite3FileSuffix3()
37201 10, 10, /* 0,1 */ in sqlite3LogEstAdd()
37227 static LogEst a[] = { 0, 2, 3, 5, 6, 7, 8, 9 }; in sqlite3LogEst()
37230 if( x<2 ) return 0; in sqlite3LogEst()
37253 if( x<=1 ) return 0; in sqlite3LogEstFromDouble()
37301 ** } a[0];
37321 assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */ in sqlite3VListAdd()
37322 if( pIn==0 || pIn[1]+nInt > pIn[0] ){ in sqlite3VListAdd()
37324 sqlite3_int64 nAlloc = (pIn ? 2*(sqlite3_int64)pIn[0] : 10) + nInt; in sqlite3VListAdd()
37326 if( pOut==0 ) return pIn; in sqlite3VListAdd()
37327 if( pIn==0 ) pOut[1] = 2; in sqlite3VListAdd()
37329 pIn[0] = nAlloc; in sqlite3VListAdd()
37336 assert( pIn[1]<=pIn[0] ); in sqlite3VListAdd()
37338 z[nName] = 0; in sqlite3VListAdd()
37349 if( pIn==0 ) return 0; in sqlite3VListNumToName()
37356 return 0; in sqlite3VListNumToName()
37361 ** or return 0 if there is no such variable.
37365 if( pIn==0 ) return 0; in sqlite3VListNameToNum()
37370 if( strncmp(z,zName,nName)==0 && z[nName]==0 ) return pIn[i]; in sqlite3VListNameToNum()
37373 return 0; in sqlite3VListNameToNum()
37401 assert( pNew!=0 ); in sqlite3HashInit()
37402 pNew->first = 0; in sqlite3HashInit()
37403 pNew->count = 0; in sqlite3HashInit()
37404 pNew->htsize = 0; in sqlite3HashInit()
37405 pNew->ht = 0; in sqlite3HashInit()
37415 assert( pH!=0 ); in sqlite3HashClear()
37417 pH->first = 0; in sqlite3HashClear()
37419 pH->ht = 0; in sqlite3HashClear()
37420 pH->htsize = 0; in sqlite3HashClear()
37426 pH->count = 0; in sqlite3HashClear()
37433 unsigned int h = 0; in strHash()
37434 while( z[0] ){ /*OPTIMIZATION-IF-TRUE*/ in strHash()
37436 ** 0x9e3779b1 is 2654435761 which is the closest prime number to in strHash()
37439 ** Only bits 0xdf for ASCII and bits 0xbf for EBCDIC each octet are in strHash()
37443 h += 0xbf & (unsigned char)*(z++); in strHash()
37445 h += 0xdf & (unsigned char)*(z++); in strHash()
37447 h *= 0x9e3779b1; in strHash()
37453 /* Link pNew element into the hash table pH. If pEntry!=0 then also
37463 pHead = pEntry->count ? pEntry->chain : 0; in insertElement()
37467 pHead = 0; in insertElement()
37478 pNew->prev = 0; in insertElement()
37494 #if SQLITE_MALLOC_SOFT_LIMIT>0 in rehash()
37498 if( new_size==pH->htsize ) return 0; in rehash()
37503 ** allocation as a benign. Use sqlite3Malloc()/memset(0) instead of in rehash()
37513 if( new_ht==0 ) return 0; in rehash()
37517 memset(new_ht, 0, new_size*sizeof(struct _ht)); in rehash()
37518 for(elem=pH->first, pH->first=0; elem; elem = next_elem){ in rehash()
37527 ** a pointer to a static null element with HashElem.data==0 is returned.
37538 static HashElem nullElement = { 0, 0, 0, 0, 0 }; in findElementWithHash()
37552 assert( elem!=0 ); in findElementWithHash()
37553 if( h==elem->h && sqlite3StrICmp(elem->pKey,pKey)==0 ){ in findElementWithHash()
37583 assert( pEntry->count>0 ); in removeElement()
37588 if( pH->count==0 ){ in removeElement()
37589 assert( pH->first==0 ); in removeElement()
37590 assert( pH->count==0 ); in removeElement()
37600 assert( pH!=0 ); in sqlite3HashFind()
37601 assert( pKey!=0 ); in sqlite3HashFind()
37602 return findElementWithHash(pH, pKey, 0)->data; in sqlite3HashFind()
37624 assert( pH!=0 ); in sqlite3HashInsert()
37625 assert( pKey!=0 ); in sqlite3HashInsert()
37629 if( data==0 ){ in sqlite3HashInsert()
37637 if( data==0 ) return 0; in sqlite3HashInsert()
37639 if( new_elem==0 ) return data; in sqlite3HashInsert()
37647 insertElement(pH, pH->ht ? &pH->ht[new_elem->h % pH->htsize] : 0, new_elem); in sqlite3HashInsert()
37648 return 0; in sqlite3HashInsert()
37659 # define OpHelp(X) "\0" X
37665 /* 0 */ "Savepoint" OpHelp(""), in sqlite3OpcodeName()
37714 /* 49 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), in sqlite3OpcodeName()
37715 /* 50 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"), in sqlite3OpcodeName()
37725 /* 60 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"), in sqlite3OpcodeName()
37726 /* 61 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), in sqlite3OpcodeName()
37757 /* 92 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"), in sqlite3OpcodeName()
37825 /* 160 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), in sqlite3OpcodeName()
37845 /* 180 */ "ClrSubtype" OpHelp("r[P1].subtype = 0"), in sqlite3OpcodeName()
37886 #if 0
37893 #if 0
37959 0, /* pNext */
37961 0, /* pAppData */
37967 0, /* xDlError */
37968 0, /* xDlSym */
37969 0, /* xDlClose */
37973 0, /* xGetLastError */
37993 0, /* xShmMap */
37994 0, /* xShmLock */
37995 0, /* xShmBarrier */
37996 0, /* xShmUnmap */
37997 0, /* xFetch */
37998 0 /* xUnfetch */
38017 0, /* xShmMap */
38018 0, /* xShmLock */
38019 0, /* xShmBarrier */
38020 0, /* xShmUnmap */
38021 0, /* xFetch */
38022 0 /* xUnfetch */
38071 return 0; in kvstorageWrite()
38086 return 0; in kvstorageDelete()
38099 ** If nBuf<=0 then this routine simply returns the size of the data without
38112 if( access(zXKey, R_OK)!=0 in kvstorageRead()
38113 || stat(zXKey, &buf)!=0 in kvstorageRead()
38119 if( nBuf<=0 ){ in kvstorageRead()
38122 zBuf[0] = 0; in kvstorageRead()
38131 if( fd==0 ){ in kvstorageRead()
38137 zBuf[n] = 0; in kvstorageRead()
38200 ** base-26 number using a..z. "a" means 0. "b" means 1,
38210 for(i=j=0; i<nData; i++){ in kvvfsEncode()
38212 if( c!=0 ){ in kvvfsEncode()
38214 aOut[j++] = "0123456789ABCDEF"[c&0xf]; in kvvfsEncode()
38222 for(k=1; i+k<nData && a[i+k]==0; k++){} in kvvfsEncode()
38224 while( k>0 ){ in kvvfsEncode()
38230 aOut[j] = 0; in kvvfsEncode()
38238 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
38264 i = 0; in kvvfsDecode()
38265 j = 0; in kvvfsDecode()
38268 if( c<0 ){ in kvvfsDecode()
38269 int n = 0; in kvvfsDecode()
38272 if( c==0 ) break; in kvvfsDecode()
38279 memset(&aOut[j], 0, n); in kvvfsDecode()
38281 if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */ in kvvfsDecode()
38285 if( c<0 ) break; in kvvfsDecode()
38309 unsigned int n = 0; in kvvfsDecodeJournal()
38311 i = 0; in kvvfsDecodeJournal()
38319 if( pFile->aJrnl==0 ){ in kvvfsDecodeJournal()
38320 pFile->nJrnl = 0; in kvvfsDecodeJournal()
38327 pFile->aJrnl = 0; in kvvfsDecodeJournal()
38328 pFile->nJrnl = 0; in kvvfsDecodeJournal()
38337 zData[0] = 0; in kvvfsReadFileSize()
38339 return strtoll(zData, 0, 0); in kvvfsReadFileSize()
38374 if( pFile->aJrnl==0 ){ in kvvfsReadJrnl()
38375 int szTxt = kvstorageRead(pFile->zClass, "jrnl", 0, 0); in kvvfsReadJrnl()
38381 if( aTxt==0 ) return SQLITE_NOMEM; in kvvfsReadJrnl()
38385 if( pFile->aJrnl==0 ) return SQLITE_IOERR; in kvvfsReadJrnl()
38408 assert( iOfst>=0 ); in kvvfsReadDb()
38409 assert( iAmt>=0 ); in kvvfsReadDb()
38412 if( (iOfst % iAmt)!=0 ){ in kvvfsReadDb()
38415 if( (iAmt & (iAmt-1))!=0 || iAmt<512 || iAmt>65536 ){ in kvvfsReadDb()
38426 if( got<0 ){ in kvvfsReadDb()
38427 n = 0; in kvvfsReadDb()
38429 aData[got] = 0; in kvvfsReadDb()
38432 aData[k*2] = 0; in kvvfsReadDb()
38438 n = 0; in kvvfsReadDb()
38445 memset(zBuf+n, 0, iAmt-n); in kvvfsReadDb()
38464 if( iEnd>=0x10000000 ) return SQLITE_FULL; in kvvfsWriteJrnl()
38465 if( pFile->aJrnl==0 || pFile->nJrnl<iEnd ){ in kvvfsWriteJrnl()
38467 if( aNew==0 ){ in kvvfsWriteJrnl()
38472 memset(pFile->aJrnl+pFile->nJrnl, 0, iOfst-pFile->nJrnl); in kvvfsWriteJrnl()
38495 assert( (iAmt & (iAmt-1))==0 ); in kvvfsWriteDb()
38496 assert( pFile->szPage<0 || pFile->szPage==iAmt ); in kvvfsWriteDb()
38516 assert( size==0 ); in kvvfsTruncateJrnl()
38519 pFile->aJrnl = 0; in kvvfsTruncateJrnl()
38520 pFile->nJrnl = 0; in kvvfsTruncateJrnl()
38526 && pFile->szPage>0 in kvvfsTruncateDb()
38527 && (size % pFile->szPage)==0 in kvvfsTruncateDb()
38553 if( pFile->nJrnl<=0 ){ in kvvfsSyncJrnl()
38554 return kvvfsTruncateJrnl(pProtoFile, 0); in kvvfsSyncJrnl()
38557 if( zOut==0 ){ in kvvfsSyncJrnl()
38561 i = 0; in kvvfsSyncJrnl()
38565 }while( n>0 ); in kvvfsSyncJrnl()
38588 if( pFile->szDb>=0 ){ in kvvfsFileSizeDb()
38628 *pResOut = 0; in kvvfsCheckReservedLock()
38645 if( pFile->szDb>0 && 0!=kvvfsWriteFileSize(pFile, pFile->szDb) ){ in kvvfsFileControlDb()
38664 return 0; in kvvfsDeviceCharacteristics()
38680 if( zName==0 ) zName = ""; in kvvfsOpen()
38682 if( strcmp(zName, "local")==0 in kvvfsOpen()
38683 || strcmp(zName, "session")==0 in kvvfsOpen()
38685 pFile->isJournal = 0; in kvvfsOpen()
38688 if( strcmp(zName, "local-journal")==0 in kvvfsOpen()
38689 || strcmp(zName, "session-journal")==0 in kvvfsOpen()
38696 if( zName[0]=='s' ){ in kvvfsOpen()
38702 if( pFile->aData==0 ){ in kvvfsOpen()
38705 pFile->aJrnl = 0; in kvvfsOpen()
38706 pFile->nJrnl = 0; in kvvfsOpen()
38718 if( strcmp(zPath, "local-journal")==0 ){ in kvvfsDelete()
38721 if( strcmp(zPath, "session-journal")==0 ){ in kvvfsDelete()
38738 if( strcmp(zPath, "local-journal")==0 ){ in kvvfsAccess()
38739 *pResOut = sqlite3KvvfsMethods.xRead("local", "jrnl", 0, 0)>0; in kvvfsAccess()
38741 if( strcmp(zPath, "session-journal")==0 ){ in kvvfsAccess()
38742 *pResOut = sqlite3KvvfsMethods.xRead("session", "jrnl", 0, 0)>0; in kvvfsAccess()
38744 if( strcmp(zPath, "local")==0 ){ in kvvfsAccess()
38745 *pResOut = sqlite3KvvfsMethods.xRead("local", "sz", 0, 0)>0; in kvvfsAccess()
38747 if( strcmp(zPath, "session")==0 ){ in kvvfsAccess()
38748 *pResOut = sqlite3KvvfsMethods.xRead("session", "sz", 0, 0)>0; in kvvfsAccess()
38751 *pResOut = 0; in kvvfsAccess()
38776 zOut[nPath] = 0; in kvvfsFullPathname()
38784 return 0; in kvvfsDlOpen()
38792 memset(zBufOut, 0, nByte); in kvvfsRandomness()
38808 sqlite3_int64 i = 0; in kvvfsCurrentTime()
38810 rc = kvvfsCurrentTimeInt64(0, &i); in kvvfsCurrentTime()
38818 (void)gettimeofday(&sNow, 0); /* Cannot fail given valid arguments */ in kvvfsCurrentTimeInt64()
38838 return sqlite3_vfs_register(&sqlite3OsKvvfsObject, 0); in sqlite3KvvfsInit()
38913 # define SQLITE_ENABLE_LOCKING_STYLE 0
38941 #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
38958 ** -DHAVE_GETHOSTUUID=0
38965 # define HAVE_GETHOSTUUID 0
38968 # if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
38969 && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))\
38970 && (!defined(TARGET_OS_MACCATALYST) || (TARGET_OS_MACCATALYST==0))
38997 #define SQLITE_FSFLAGS_IS_MSDOS 0x1
39038 # define HAVE_MREMAP 0
39044 # define F_RDLCK 0
39047 # if __LONG_MAX == 0x7fffffffL
39113 #if SQLITE_MAX_MMAP_SIZE>0
39161 static pid_t randomnessPid = 0;
39166 #define UNIXFILE_EXCL 0x01 /* Connections from one process only */
39167 #define UNIXFILE_RDONLY 0x02 /* Connection is read only */
39168 #define UNIXFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */
39170 # define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */
39172 # define UNIXFILE_DIRSYNC 0x00
39174 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
39175 #define UNIXFILE_DELETE 0x20 /* Delete on close */
39176 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */
39177 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
39188 # define O_LARGEFILE 0
39192 # define O_LARGEFILE 0
39195 # define O_NOFOLLOW 0
39198 # define O_BINARY 0
39202 ** The threadid macro resolves to the thread-id or to 0. Used for
39208 #define threadid 0
39218 # define HAVE_MREMAP 0
39234 #define F2FS_IOCTL_MAGIC 0xf5
39240 #define F2FS_FEATURE_ATOMIC_WRITE 0x0004
39271 { "open", (sqlite3_syscall_ptr)posixOpen, 0 },
39272 #define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent)
39274 { "close", (sqlite3_syscall_ptr)close, 0 },
39277 { "access", (sqlite3_syscall_ptr)access, 0 },
39280 { "getcwd", (sqlite3_syscall_ptr)getcwd, 0 },
39283 { "stat", (sqlite3_syscall_ptr)stat, 0 },
39293 { "fstat", 0, 0 },
39294 #define osFstat(a,b,c) 0
39296 { "fstat", (sqlite3_syscall_ptr)fstat, 0 },
39300 { "ftruncate", (sqlite3_syscall_ptr)ftruncate, 0 },
39303 { "fcntl", (sqlite3_syscall_ptr)fcntl, 0 },
39306 { "read", (sqlite3_syscall_ptr)read, 0 },
39310 { "pread", (sqlite3_syscall_ptr)pread, 0 },
39312 { "pread", (sqlite3_syscall_ptr)0, 0 },
39317 { "pread64", (sqlite3_syscall_ptr)pread64, 0 },
39319 { "pread64", (sqlite3_syscall_ptr)0, 0 },
39323 { "write", (sqlite3_syscall_ptr)write, 0 },
39327 { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 },
39329 { "pwrite", (sqlite3_syscall_ptr)0, 0 },
39335 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 },
39337 { "pwrite64", (sqlite3_syscall_ptr)0, 0 },
39343 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
39345 { "fchmod", (sqlite3_syscall_ptr)0, 0 },
39350 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
39352 { "fallocate", (sqlite3_syscall_ptr)0, 0 },
39356 { "unlink", (sqlite3_syscall_ptr)unlink, 0 },
39359 { "openDirectory", (sqlite3_syscall_ptr)openDirectory, 0 },
39362 { "mkdir", (sqlite3_syscall_ptr)mkdir, 0 },
39365 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 },
39369 { "fchown", (sqlite3_syscall_ptr)fchown, 0 },
39371 { "fchown", (sqlite3_syscall_ptr)0, 0 },
39376 { "geteuid", (sqlite3_syscall_ptr)geteuid, 0 },
39378 { "geteuid", (sqlite3_syscall_ptr)0, 0 },
39382 #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
39384 { "mmap", (sqlite3_syscall_ptr)mmap, 0 },
39386 { "mmap", (sqlite3_syscall_ptr)0, 0 },
39390 #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
39392 { "munmap", (sqlite3_syscall_ptr)munmap, 0 },
39394 { "munmap", (sqlite3_syscall_ptr)0, 0 },
39398 #if HAVE_MREMAP && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
39399 { "mremap", (sqlite3_syscall_ptr)mremap, 0 },
39401 { "mremap", (sqlite3_syscall_ptr)0, 0 },
39405 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
39406 { "getpagesize", (sqlite3_syscall_ptr)unixGetpagesize, 0 },
39408 { "getpagesize", (sqlite3_syscall_ptr)0, 0 },
39413 { "readlink", (sqlite3_syscall_ptr)readlink, 0 },
39415 { "readlink", (sqlite3_syscall_ptr)0, 0 },
39420 { "lstat", (sqlite3_syscall_ptr)lstat, 0 },
39422 { "lstat", (sqlite3_syscall_ptr)0, 0 },
39428 { "ioctl", (sqlite3_syscall_ptr)(int(*)(int, int, ...))ioctl, 0 },
39431 { "ioctl", (sqlite3_syscall_ptr)ioctl, 0 },
39435 { "ioctl", (sqlite3_syscall_ptr)0, 0 },
39448 return osGeteuid() ? 0 : osFchown(fd,uid,gid); in robustFchown()
39450 return 0; in robustFchown()
39469 if( zName==0 ){ in unixSetSystemCall()
39474 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ in unixSetSystemCall()
39483 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ in unixSetSystemCall()
39484 if( strcmp(zName, aSyscall[i].zName)==0 ){ in unixSetSystemCall()
39485 if( aSyscall[i].pDefault==0 ){ in unixSetSystemCall()
39489 if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault; in unixSetSystemCall()
39510 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ in unixGetSystemCall()
39511 if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent; in unixGetSystemCall()
39513 return 0; in unixGetSystemCall()
39527 for(i=0; i<ArraySize(aSyscall)-1; i++){ in unixNextSystemCall()
39528 if( strcmp(zName, aSyscall[i].zName)==0 ) break; in unixNextSystemCall()
39532 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName; in unixNextSystemCall()
39534 return 0; in unixNextSystemCall()
39550 ** If the file creation mode "m" is 0 then set it to the default for
39552 ** 0644) as modified by the system umask. If m is not 0, then
39572 if( fd<0 ){ in robust_open()
39584 if( osOpen("/dev/null", O_RDONLY, m)<0 ) break; in robust_open()
39586 if( fd>=0 ){ in robust_open()
39587 if( m!=0 ){ in robust_open()
39589 if( osFstat(fd, &statbuf)==0 in robust_open()
39590 && statbuf.st_size==0 in robust_open()
39596 #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) in robust_open()
39597 osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); in robust_open()
39628 static sqlite3_mutex *unixBigLock = 0;
39691 assert( 0 ); in lockTrace()
39710 assert( 0 ); in lockTrace()
39736 if( sz>(sqlite3_int64)0x7FFFFFFF ){ in robust_ftruncate()
39740 do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR ); in robust_ftruncate()
39808 static struct vxworksFileId *vxworksFileList = 0;
39820 ** The original filename is in z[0..n-1]. Return the number of
39826 for(i=j=0; i<n; i++){ in vxworksSimplifyName()
39834 while( j>0 && z[j-1]!='/' ){ j--; } in vxworksSimplifyName()
39835 if( j>0 ){ j--; } in vxworksSimplifyName()
39842 z[j] = 0; in vxworksSimplifyName()
39862 assert( zAbsoluteName[0]=='/' ); in vxworksFindFileId()
39865 if( pNew==0 ) return 0; in vxworksFindFileId()
39877 && memcmp(pCandidate->zCanonicalName, pNew->zCanonicalName, n)==0 in vxworksFindFileId()
39901 assert( pId->nRef>0 ); in vxworksReleaseFileId()
39903 if( pId->nRef==0 ){ in vxworksReleaseFileId()
39964 ** field that tells us its internal lock status. cnt==0 means the
39966 ** cnt>0 means there are cnt shared locks on the file.
40001 ** was dropped beginning with version 3.7.0. SQLite will still work with
40041 ** (2) When nRef>0, then the following fields are unchanging and can
40078 static unixInodeInfo *inodeList = 0; /* All unixInodeInfo objects */
40122 /* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use in unixLogErrorAtLine()
40128 memset(aErr, 0, sizeof(aErr)); in unixLogErrorAtLine()
40160 if( zPath==0 ) zPath = ""; in unixLogErrorAtLine()
40185 pFile ? pFile->zPath : 0, lineno); in robust_close()
40210 pInode->pUnused = 0; in closePendingFds()
40225 if( pInode->nRef==0 ){ in releaseInodeInfo()
40226 assert( pInode->pShmNode==0 ); in releaseInodeInfo()
40264 unixInodeInfo *pInode = 0; /* Candidate unixInodeInfo object */ in findInodeInfo()
40273 if( rc!=0 ){ in findInodeInfo()
40292 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){ in findInodeInfo()
40293 do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR ); in findInodeInfo()
40299 if( rc!=0 ){ in findInodeInfo()
40306 memset(&fileId, 0, sizeof(fileId)); in findInodeInfo()
40318 if( pInode==0 ){ in findInodeInfo()
40320 if( pInode==0 ){ in findInodeInfo()
40323 memset(pInode, 0, sizeof(*pInode)); in findInodeInfo()
40327 if( pInode->pLockMutex==0 ){ in findInodeInfo()
40335 pInode->pPrev = 0; in findInodeInfo()
40350 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId; in fileHasMoved()
40353 return pFile->pInode!=0 && in fileHasMoved()
40354 (osStat(pFile->zPath, &buf)!=0 in fileHasMoved()
40377 if( rc!=0 ){ in verifyDbFile()
40381 if( buf.st_nlink==0 ){ in verifyDbFile()
40404 int reserved = 0; in unixCheckReservedLock()
40469 while( rc<0 && tm>0 ){ in osSetPosixAdvisoryLock()
40475 unixSleep(0,1000); in osSetPosixAdvisoryLock()
40506 assert( pInode!=0 ); in unixFileLock()
40509 if( pInode->bProcessLock==0 ){ in unixFileLock()
40511 /* assert( pInode->nLock==0 ); <-- Not true if unix-excl READONLY used */ in unixFileLock()
40517 if( rc<0 ) return rc; in unixFileLock()
40521 rc = 0; in unixFileLock()
40605 int tErrno = 0; in unixLock()
40611 osGetpid(0))); in unixLock()
40654 assert( pFile->eFileLock==0 ); in unixLock()
40655 assert( pInode->nShared>0 ); in unixLock()
40692 assert( pInode->nShared==0 ); in unixLock()
40693 assert( pInode->eFileLock==0 ); in unixLock()
40733 assert( 0!=pFile->eFileLock ); in unixLock()
40765 pFile->transCntrChng = 0; in unixLock()
40766 pFile->dbUpdate = 0; in unixLock()
40794 pFile->pPreallocatedUnused = 0; in setPendingFd()
40819 osGetpid(0))); in posixUnlock()
40827 assert( pInode->nShared!=0 ); in posixUnlock()
40840 pFile->inNormalWrite = 0; in posixUnlock()
40855 assert( handleNFSUnlock==0 ); in posixUnlock()
40918 if( unixFileLock(pFile, &lock)==0 ){ in posixUnlock()
40932 if( pInode->nShared==0 ){ in posixUnlock()
40935 lock.l_start = lock.l_len = 0L; in posixUnlock()
40936 if( unixFileLock(pFile, &lock)==0 ){ in posixUnlock()
40951 assert( pInode->nLock>=0 ); in posixUnlock()
40952 if( pInode->nLock==0 ) closePendingFds(pFile); in posixUnlock()
40971 #if SQLITE_MAX_MMAP_SIZE>0 in unixUnlock()
40972 assert( eFileLock==SHARED_LOCK || ((unixFile *)id)->nFetchOut==0 ); in unixUnlock()
40974 return posixUnlock(id, eFileLock, 0); in unixUnlock()
40977 #if SQLITE_MAX_MMAP_SIZE>0
40986 ** structure to 0.
40994 #if SQLITE_MAX_MMAP_SIZE>0 in closeUnixFile()
40997 if( pFile->h>=0 ){ in closeUnixFile()
41007 pFile->pId = 0; in closeUnixFile()
41014 pFile->zPath = 0; in closeUnixFile()
41020 memset(pFile, 0, sizeof(unixFile)); in closeUnixFile()
41032 assert( pInode!=0 ); in unixClose()
41041 assert( pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 ); in unixClose()
41053 assert( pFile->pShm==0 ); in unixClose()
41081 *pResOut = 0; in nolockCheckReservedLock()
41143 *pResOut = 0; in dotlockCheckReservedLock()
41145 *pResOut = osAccess((const char*)pFile->lockingContext, 0)==0; in dotlockCheckReservedLock()
41147 OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, 0, *pResOut)); in dotlockCheckReservedLock()
41200 if( rc<0 ){ in dotlockLock()
41235 pFile->eFileLock, osGetpid(0))); in dotlockUnlock()
41254 if( rc<0 ){ in dotlockUnlock()
41273 assert( id!=0 ); in dotlockClose()
41303 do{ rc = flock(fd,op); }while( rc<0 && errno==EINTR ); in robust_flock()
41331 ** connection may be holding a RESERVED lock. So set *pResOut to 0 in flockCheckReservedLock()
41335 ** 0 as well. The caller will then attempt to take an EXCLUSIVE lock on the in flockCheckReservedLock()
41342 *pResOut = 0; in flockCheckReservedLock()
41405 if( (rc & 0xff) == SQLITE_IOERR ){ in flockLock()
41425 pFile->eFileLock, osGetpid(0))); in flockUnlock()
41455 assert( id!=0 ); in flockClose()
41485 int reserved = 0; in semXCheckReservedLock()
41590 pFile->eFileLock, osGetpid(0))); in semXUnlock()
41667 unsigned char unLockFlag; /* 1 = unlock, 0 = lock */
41668 unsigned char startEndFlag; /* 1=rel to end of fork, 0=rel to start */
41690 pb.unLockFlag = setLockFlag ? 0 : 1; in afpSetLock()
41691 pb.startEndFlag = 0; in afpSetLock()
41699 err = fsctl(path, afpfsByteRangeLock2FSCTL, &pb, 0); in afpSetLock()
41728 int reserved = 0; in afpCheckReservedLock()
41754 lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0); in afpCheckReservedLock()
41804 azFileLock(pInode->eFileLock), pInode->nShared , osGetpid(0))); in afpLock()
41847 assert( pFile->eFileLock==0 ); in afpLock()
41848 assert( pInode->nShared>0 ); in afpLock()
41874 int lrc1, lrc2, lrc1Errno = 0; in afpLock()
41877 assert( pInode->nShared==0 ); in afpLock()
41878 assert( pInode->eFileLock==0 ); in afpLock()
41880 mask = (sizeof(long)==8) ? LARGEST_INT64 : 0x7fffffff; in afpLock()
41891 lrc2 = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0); in afpLock()
41916 int failed = 0; in afpLock()
41917 assert( 0!=pFile->eFileLock ); in afpLock()
41932 pInode->sharedByte, 1, 0)) ){ in afpLock()
41942 rc = ((failed & 0xff) == SQLITE_IOERR) ? failed2 : in afpLock()
41982 int skipShared = 0; in afpUnlock()
41987 osGetpid(0))); in afpUnlock()
41995 assert( pInode->nShared!=0 ); in afpUnlock()
42008 assert( pFile->inNormalWrite==0 in afpUnlock()
42009 || pFile->dbUpdate==0 in afpUnlock()
42011 pFile->inNormalWrite = 0; in afpUnlock()
42015 rc = afpSetLock(context->dbPath, pFile, SHARED_FIRST, SHARED_SIZE, 0); in afpUnlock()
42025 rc = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0); in afpUnlock()
42028 rc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0); in afpUnlock()
42030 context->reserved = 0; in afpUnlock()
42045 if( pInode->nShared==0 ){ in afpUnlock()
42047 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 0); in afpUnlock()
42056 assert( pInode->nLock>=0 ); in afpUnlock()
42057 if( pInode->nLock==0 ) closePendingFds(pFile); in afpUnlock()
42074 assert( id!=0 ); in afpClose()
42151 int prior = 0; in seekAndRead()
42156 assert( cnt==(cnt&0x1ffff) ); in seekAndRead()
42168 if( newOffset<0 ){ in seekAndRead()
42175 if( got<0 ){ in seekAndRead()
42177 prior = 0; in seekAndRead()
42180 }else if( got>0 ){ in seekAndRead()
42186 }while( got>0 ); in seekAndRead()
42207 assert( offset>=0 ); in unixRead()
42208 assert( amt>0 ); in unixRead()
42212 #if 0 in unixRead()
42213 assert( pFile->pPreallocatedUnused==0 in unixRead()
42219 #if SQLITE_MAX_MMAP_SIZE>0 in unixRead()
42239 }else if( got<0 ){ in unixRead()
42260 storeLastErrno(pFile, 0); /* not a system error */ in unixRead()
42262 memset(&((char*)pBuf)[got], 0, amt-got); in unixRead()
42281 int rc = 0; /* Value returned by system call */ in seekAndWriteFd()
42283 assert( nBuf==(nBuf&0x1ffff) ); in seekAndWriteFd()
42285 assert( piErrno!=0 ); in seekAndWriteFd()
42286 nBuf &= 0x1ffff; in seekAndWriteFd()
42290 do{ rc = (int)osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR ); in seekAndWriteFd()
42292 do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR); in seekAndWriteFd()
42297 if( iSeek<0 ){ in seekAndWriteFd()
42302 }while( rc<0 && errno==EINTR ); in seekAndWriteFd()
42308 if( rc<0 ) *piErrno = errno; in seekAndWriteFd()
42336 int wrote = 0; in unixWrite()
42338 assert( amt>0 ); in unixWrite()
42342 #if 0 in unixWrite()
42343 assert( pFile->pPreallocatedUnused==0 in unixWrite()
42363 SimulateIOErrorBenign(0); in unixWrite()
42364 if( rc!=4 || memcmp(oldCntr, &((char*)pBuf)[24-offset], 4)!=0 ){ in unixWrite()
42371 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 in unixWrite()
42388 while( (wrote = seekAndWrite(pFile, offset, pBuf, amt))<amt && wrote>0 ){ in unixWrite()
42394 SimulateDiskfullError(( wrote=0, amt=1 )); in unixWrite()
42397 if( wrote<0 && pFile->lastErrno!=ENOSPC ){ in unixWrite()
42401 storeLastErrno(pFile, 0); /* not a system error */ in unixWrite()
42414 SQLITE_API int sqlite3_sync_count = 0;
42415 SQLITE_API int sqlite3_fullsync_count = 0;
42429 ** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not
42436 # define HAVE_FULLFSYNC 0
42503 rc = osFcntl(fd, F_FULLFSYNC, 0); in full_fsync()
42532 rc = 0; in full_fsync()
42566 for(ii=(int)strlen(zDirname); ii>0 && zDirname[ii]!='/'; ii--); in openDirectory()
42567 if( ii>0 ){ in openDirectory()
42568 zDirname[ii] = '\0'; in openDirectory()
42570 if( zDirname[0]!='/' ) zDirname[0] = '.'; in openDirectory()
42571 zDirname[1] = 0; in openDirectory()
42573 fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0); in openDirectory()
42574 if( fd>=0 ){ in openDirectory()
42578 if( fd>=0 ) return SQLITE_OK; in openDirectory()
42585 ** If dataOnly==0 then both the file itself and its metadata (file
42586 ** size, access time, etc) are synced. If dataOnly!=0 then only the
42602 int isFullsync = (flags&0x0F)==SQLITE_SYNC_FULL; in unixSync()
42605 assert((flags&0x0F)==SQLITE_SYNC_NORMAL in unixSync()
42606 || (flags&0x0F)==SQLITE_SYNC_FULL in unixSync()
42633 full_fsync(dirfd, 0, 0); in unixSync()
42658 if( pFile->szChunk>0 ){ in unixTruncate()
42675 if( pFile->inNormalWrite && nByte==0 ){ in unixTruncate()
42680 #if SQLITE_MAX_MMAP_SIZE>0 in unixTruncate()
42703 if( rc!=0 ){ in unixFileSize()
42715 if( *pSize==1 ) *pSize = 0; in unixFileSize()
42736 if( pFile->szChunk>0 ){ in fcntlSizeHint()
42765 int nWrite = 0; /* Number of bytes written by seekAndWrite */ in fcntlSizeHint()
42770 assert( ((iWrite+1)%nBlk)==0 ); in fcntlSizeHint()
42780 #if SQLITE_MAX_MMAP_SIZE>0 in fcntlSizeHint()
42781 if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){ in fcntlSizeHint()
42783 if( pFile->szChunk<=0 ){ in fcntlSizeHint()
42800 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
42802 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
42805 if( *pArg<0 ){ in unixModeBit()
42806 *pArg = (pFile->ctrlFlags & mask)!=0; in unixModeBit()
42807 }else if( (*pArg)==0 ){ in unixModeBit()
42862 SimulateIOErrorBenign(0); in unixFileControl()
42894 pFile->iBusyTimeout = iNew<0 ? 0x7FFFFFFF : (unsigned)iNew; in unixFileControl()
42909 #if SQLITE_MAX_MMAP_SIZE>0 in unixFileControl()
42920 if( newLimit>0 && sizeof(size_t)<8 ){ in unixFileControl()
42921 newLimit = (newLimit & 0x7FFFFFFF); in unixFileControl()
42925 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){ in unixFileControl()
42927 if( pFile->mmapSize>0 ){ in unixFileControl()
42942 ((unixFile*)id)->dbUpdate = 0; in unixFileControl()
42957 *(int*)pArg = 0; in unixFileControl()
42976 assert( pFd->deviceCharacteristics==0 || pFd->sectorSize!=0 ); in setDeviceCharacteristics()
42977 if( pFd->sectorSize==0 ){ in setDeviceCharacteristics()
42980 u32 f = 0; in setDeviceCharacteristics()
42984 if( res==0 && (f & F2FS_FEATURE_ATOMIC_WRITE) ){ in setDeviceCharacteristics()
43002 if( pFile->sectorSize == 0 ){ in setDeviceCharacteristics()
43007 pFile->deviceCharacteristics = 0; in setDeviceCharacteristics()
43020 0; in setDeviceCharacteristics()
43030 0; in setDeviceCharacteristics()
43039 0; in setDeviceCharacteristics()
43047 0; in setDeviceCharacteristics()
43055 0; in setDeviceCharacteristics()
43061 0; in setDeviceCharacteristics()
43066 if( pFile->sectorSize % 512 != 0 ){ in setDeviceCharacteristics()
43067 pFile->deviceCharacteristics = 0; in setDeviceCharacteristics()
43108 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
43126 #endif /* !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 */
43155 ** Either unixShmNode.pShmMutex must be held or unixShmNode.nRef==0 and
43161 ** SQLITE_SHM_NLOCK slots. If the aLock[] entry is set to 0, then no
43231 ** such transactions, or 0 otherwise. If an error occurs, return an
43237 *piOut = 0; in unixFcntlExternalReader()
43242 memset(&f, 0, sizeof(f)); in unixFcntlExternalReader()
43249 if( osFcntl(pShmNode->hShm, F_GETLK, &f)<0 ){ in unixFcntlExternalReader()
43281 assert( pShmNode->nRef>=0 ); in unixShmSystemLock()
43286 assert( pShmNode->nRef>0 || unixMutexHeld() ); in unixShmSystemLock()
43287 assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->pShmMutex) ); in unixShmSystemLock()
43296 assert( pShmNode->nRef>0 ); in unixShmSystemLock()
43307 if( pShmNode->hShm>=0 ){ in unixShmSystemLock()
43363 assert( ((pgsz-1)&pgsz)==0 ); /* Page size must be a power of 2 */ in unixShmRegionPerMap()
43369 ** Purge the unixShmNodeList list of all entries with unixShmNode.nRef==0.
43377 if( p && ALWAYS(p->nRef==0) ){ in unixShmPurge()
43383 for(i=0; i<SQLITE_SHM_NLOCK; i++){ in unixShmPurge()
43387 for(i=0; i<p->nRegion; i+=nShmPerMap){ in unixShmPurge()
43388 if( p->hShm>=0 ){ in unixShmPurge()
43395 if( p->hShm>=0 ){ in unixShmPurge()
43399 p->pInode->pShmNode = 0; in unixShmPurge()
43439 if( osFcntl(pShmNode->hShm, F_GETLK, &lock)!=0 ) { in unixLockSharedMemory()
43454 pDbFd->iBusyTimeout = 0; in unixLockSharedMemory()
43462 ** -shm header size) rather than 0 as a system debugging aid, to in unixLockSharedMemory()
43516 struct unixShm *p = 0; /* The connection to be opened */ in unixOpenSharedMemory()
43525 if( p==0 ) return SQLITE_NOMEM_BKPT; in unixOpenSharedMemory()
43526 memset(p, 0, sizeof(*p)); in unixOpenSharedMemory()
43527 assert( pDbFd->pShm==0 ); in unixOpenSharedMemory()
43536 if( pShmNode==0 ){ in unixOpenSharedMemory()
43557 if( pShmNode==0 ){ in unixOpenSharedMemory()
43561 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename); in unixOpenSharedMemory()
43576 if( pShmNode->pShmMutex==0 ){ in unixOpenSharedMemory()
43583 for(ii=0; ii<SQLITE_SHM_NLOCK; ii++){ in unixOpenSharedMemory()
43585 if( pShmNode->aMutex[ii]==0 ){ in unixOpenSharedMemory()
43594 if( pInode->bProcessLock==0 ){ in unixOpenSharedMemory()
43595 if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){ in unixOpenSharedMemory()
43599 if( pShmNode->hShm<0 ){ in unixOpenSharedMemory()
43602 if( pShmNode->hShm<0 ){ in unixOpenSharedMemory()
43658 ** Otherwise, if the bExtend parameter is 0 and the requested shared-memory
43684 if( pDbFd->pShm==0 ){ in unixShmMap()
43695 pShmNode->isUnlocked = 0; in unixShmMap()
43697 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 ); in unixShmMap()
43699 assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 ); in unixShmMap()
43700 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 ); in unixShmMap()
43712 if( pShmNode->hShm>=0 ){ in unixShmMap()
43742 assert( (nByte % pgsz)==0 ); in unixShmMap()
43744 int x = 0; in unixShmMap()
43768 if( pShmNode->hShm>=0 ){ in unixShmMap()
43769 pMem = osMmap(0, nMap, in unixShmMap()
43779 if( pMem==0 ){ in unixShmMap()
43783 memset(pMem, 0, nMap); in unixShmMap()
43786 for(i=0; i<nShmPerMap; i++){ in unixShmMap()
43797 *pp = 0; in unixShmMap()
43819 memset(aLock, 0, sizeof(aLock)); in assertLockingArrayOk()
43822 for(i=0; i<SQLITE_SHM_NLOCK; i++){ in assertLockingArrayOk()
43824 assert( aLock[i]==0 ); in assertLockingArrayOk()
43827 assert( aLock[i]>=0 ); in assertLockingArrayOk()
43833 assert( 0==memcmp(pShmNode->aLock, aLock, sizeof(aLock)) ); in assertLockingArrayOk()
43834 return (memcmp(pShmNode->aLock, aLock, sizeof(aLock))==0); in assertLockingArrayOk()
43861 if( p==0 ) return SQLITE_IOERR_SHMLOCK; in unixShmLock()
43863 if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK; in unixShmLock()
43868 assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK ); in unixShmLock()
43874 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 ); in unixShmLock()
43875 assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 ); in unixShmLock()
43876 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 ); in unixShmLock()
43883 ** 3. Write lock (ofst==0). in unixShmLock()
43893 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || ( in unixShmLock()
43894 (ofst!=2 || lockMask==0) in unixShmLock()
43895 && (ofst!=1 || lockMask==0 || lockMask==2) in unixShmLock()
43896 && (ofst!=0 || lockMask<3) in unixShmLock()
43912 || 0==(p->exclMask & mask) in unixShmLock()
43915 || (flags==(SQLITE_SHM_SHARED|SQLITE_SHM_LOCK) && 0==(p->sharedMask & mask)) in unixShmLock()
43952 assert( (p->exclMask & p->sharedMask)==0 ); in unixShmLock()
43958 ** this case, set bUnlock to 0 so that the posix lock is not removed in unixShmLock()
43964 bUnlock = 0; in unixShmLock()
43973 memset(&aLock[ofst], 0, sizeof(int)*n); in unixShmLock()
43981 if( aLock[ofst]<0 ){ in unixShmLock()
43984 }else if( aLock[ofst]==0 ){ in unixShmLock()
43998 assert( (p->sharedMask & mask)==0 ); in unixShmLock()
43999 assert( (p->exclMask & mask)==0 ); in unixShmLock()
44037 p->id, osGetpid(0), p->sharedMask, p->exclMask)); in unixShmLock()
44077 if( p==0 ) return SQLITE_OK; in unixShmUnmap()
44091 pDbFd->pShm = 0; in unixShmUnmap()
44094 /* If pShmNode->nRef has reached 0, then close the underlying in unixShmUnmap()
44098 assert( pShmNode->nRef>0 ); in unixShmUnmap()
44100 if( pShmNode->nRef==0 ){ in unixShmUnmap()
44101 if( deleteFlag && pShmNode->hShm>=0 ){ in unixShmUnmap()
44113 # define unixShmMap 0
44114 # define unixShmLock 0
44115 # define unixShmBarrier 0
44116 # define unixShmUnmap 0
44119 #if SQLITE_MAX_MMAP_SIZE>0
44124 assert( pFd->nFetchOut==0 ); in unixUnmapfile()
44127 pFd->pMapRegion = 0; in unixUnmapfile()
44128 pFd->mmapSize = 0; in unixUnmapfile()
44129 pFd->mmapSizeActual = 0; in unixUnmapfile()
44156 u8 *pNew = 0; /* Location of new mapping */ in unixRemapfile()
44159 assert( pFd->nFetchOut==0 ); in unixRemapfile()
44162 assert( nNew>0 ); in unixRemapfile()
44164 assert( MAP_FAILED!=0 ); in unixRemapfile()
44167 if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE; in unixRemapfile()
44192 pNew = 0; in unixRemapfile()
44200 if( pNew==MAP_FAILED || pNew==0 ){ in unixRemapfile()
44206 if( pNew==0 ){ in unixRemapfile()
44207 pNew = osMmap(0, nNew, flags, MAP_SHARED, h, 0); in unixRemapfile()
44211 pNew = 0; in unixRemapfile()
44212 nNew = 0; in unixRemapfile()
44218 pFd->mmapSizeMax = 0; in unixRemapfile()
44241 assert( nMap>=0 || pFd->nFetchOut==0 ); in unixMapfile()
44242 assert( nMap>0 || (pFd->mmapSize==0 && pFd->pMapRegion==0) ); in unixMapfile()
44243 if( pFd->nFetchOut>0 ) return SQLITE_OK; in unixMapfile()
44245 if( nMap<0 ){ in unixMapfile()
44256 assert( nMap>0 || (pFd->mmapSize==0 && pFd->pMapRegion==0) ); in unixMapfile()
44263 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
44270 ** Or, if one cannot but no error occurs, set *pp to 0 and return SQLITE_OK.
44278 #if SQLITE_MAX_MMAP_SIZE>0 in unixFetch()
44281 *pp = 0; in unixFetch()
44283 #if SQLITE_MAX_MMAP_SIZE>0 in unixFetch()
44284 if( pFd->mmapSizeMax>0 ){ in unixFetch()
44290 if( pFd->pMapRegion==0 ){ in unixFetch()
44314 #if SQLITE_MAX_MMAP_SIZE>0 in unixUnfetch()
44318 /* If p==0 (unmap the entire file) then there must be no outstanding in unixUnfetch()
44319 ** xFetch references. Or, if p!=0 (meaning it is an xFetch reference), in unixUnfetch()
44321 assert( (p==0)==(pFd->nFetchOut==0) ); in unixUnfetch()
44323 /* If p!=0, it must match the iOff value. */ in unixUnfetch()
44324 assert( p==0 || p==&((u8 *)pFd->pMapRegion)[iOff] ); in unixUnfetch()
44332 assert( pFd->nFetchOut>=0 ); in unixUnfetch()
44433 0 /* xShmMap method */
44443 0 /* xShmMap method */
44455 0 /* xShmMap method */
44468 0 /* xShmMap method */
44481 0 /* xShmMap method */
44507 0 /* xShmMap method */
44521 0 /* xShmMap method */
44546 { 0, 0 } in autolockIoFinderImpl()
44561 for(i=0; aMap[i].zFilesystem; i++){ in autolockIoFinderImpl()
44562 if( strcmp(fsInfo.f_fstypename, aMap[i].zFilesystem)==0 ){ in autolockIoFinderImpl()
44573 lockInfo.l_start = 0; in autolockIoFinderImpl()
44577 if( strcmp(fsInfo.f_fstypename, "nfs")==0 ){ in autolockIoFinderImpl()
44613 lockInfo.l_start = 0; in vxworksIoFinderImpl()
44657 assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 ); in fillInUnixFile()
44664 #if SQLITE_MAX_MMAP_SIZE>0 in fillInUnixFile()
44667 if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0), in fillInUnixFile()
44671 if( strcmp(pVfs->zName,"unix-excl")==0 ){ in fillInUnixFile()
44677 if( pNew->pId==0 ){ in fillInUnixFile()
44734 if( pCtx==0 ){ in fillInUnixFile()
44741 pCtx->reserved = 0; in fillInUnixFile()
44761 assert( zFilename!=0 ); in fillInUnixFile()
44764 if( zLockFile==0 ){ in fillInUnixFile()
44789 pNew->pInode->aSemName[0] = '\0'; in fillInUnixFile()
44796 storeLastErrno(pNew, 0); in fillInUnixFile()
44799 if( h>=0 ) robust_close(pNew, h, __LINE__); in fillInUnixFile()
44806 if( h>=0 ) robust_close(pNew, h, __LINE__); in fillInUnixFile()
44819 0,
44820 0,
44831 azTempDirs[0] = getenv("SQLITE_TMPDIR"); in unixTempFileInit()
44840 unsigned int i = 0; in unixTempFileDir()
44845 if( zDir!=0 in unixTempFileDir()
44846 && osStat(zDir, &buf)==0 in unixTempFileDir()
44848 && osAccess(zDir, 03)==0 in unixTempFileDir()
44852 if( i>=sizeof(azTempDirs)/sizeof(azTempDirs[0]) ) break; in unixTempFileDir()
44855 return 0; in unixTempFileDir()
44865 int iLimit = 0; in unixGetTempname()
44872 zBuf[0] = 0; in unixGetTempname()
44877 if( zDir==0 ){ in unixGetTempname()
44884 zBuf[nBuf-2] = 0; in unixGetTempname()
44886 zDir, r, 0); in unixGetTempname()
44887 if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ){ in unixGetTempname()
44891 }while( osAccess(zBuf,0)==0 ); in unixGetTempname()
44923 UnixUnusedFd *pUnused = 0; in findReusableFd()
44943 if( inodeList!=0 && 0==osStat(zPath, &sStat) ){ in findReusableFd()
44980 if( 0==osStat(zFile, &sStat) ){ in getFileMode()
44997 ** In most cases, this routine sets *pMode to 0, which will become
45019 *pMode = 0; in findCreateFileMode()
45020 *pUid = 0; in findCreateFileMode()
45021 *pGid = 0; in findCreateFileMode()
45042 ** the filename. In that case, just return SQLITE_OK with *pMode==0. in findCreateFileMode()
45045 while( nDb>0 && zPath[nDb]!='.' ){ in findCreateFileMode()
45048 zDb[nDb] = '\0'; in findCreateFileMode()
45100 int openFlags = 0; /* Flags to pass to open() */ in unixOpen()
45101 int eType = flags&0x0FFF00; /* Type of file to open */ in unixOpen()
45104 int ctrlFlags = 0; /* UNIXFILE_* flags */ in unixOpen()
45141 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly)); in unixOpen()
45142 assert(isCreate==0 || isReadWrite); in unixOpen()
45143 assert(isExclusive==0 || isCreate); in unixOpen()
45144 assert(isDelete==0 || isCreate); in unixOpen()
45165 if( randomnessPid!=osGetpid(0) ){ in unixOpen()
45166 randomnessPid = osGetpid(0); in unixOpen()
45167 sqlite3_randomness(0,0); in unixOpen()
45169 memset(p, 0, sizeof(unixFile)); in unixOpen()
45173 assert( zName==0 ); in unixOpen()
45192 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 ); in unixOpen()
45205 assert( zName[strlen(zName)+1]==0 ); in unixOpen()
45218 if( fd<0 ){ in unixOpen()
45229 OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags)); in unixOpen()
45230 assert( !isExclusive || (openFlags & O_CREAT)!=0 ); in unixOpen()
45231 if( fd<0 ){ in unixOpen()
45238 UnixUnusedFd *pReadonly = 0; in unixOpen()
45253 if( fd<0 ){ in unixOpen()
45267 ** If openMode==0, then that means uid and gid are not set correctly in unixOpen()
45271 if( openMode && (flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL))!=0 ){ in unixOpen()
45275 assert( fd>=0 ); in unixOpen()
45291 if( zPath==0 ){ in unixOpen()
45311 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) { in unixOpen()
45314 if (0 == strncmp("exfat", fsInfo.f_fstypename, 5)) { in unixOpen()
45333 int useProxy = 0; in unixOpen()
45335 /* SQLITE_FORCE_PROXY_LOCKING==1 means force always use proxy, 0 means in unixOpen()
45338 useProxy = atoi(envforce)>0; in unixOpen()
45360 assert( zPath==0 || zPath[0]=='/' in unixOpen()
45388 || osAccess(zPath,0)!=0 in unixDelete()
45398 if( (dirSync & 1)!=0 ){ in unixDelete()
45402 if( full_fsync(fd,0,0) ){ in unixDelete()
45405 robust_close(0, fd, __LINE__); in unixDelete()
45423 ** Otherwise return 0.
45433 assert( pResOut!=0 ); in unixAccess()
45441 *pResOut = 0==osStat(zPath, &buf) && in unixAccess()
45442 (!S_ISREG(buf.st_mode) || buf.st_size>0); in unixAccess()
45444 *pResOut = osAccess(zPath, W_OK|R_OK)==0; in unixAccess()
45472 assert( nName>0 ); in appendOnePathElement()
45473 assert( zName!=0 ); in appendOnePathElement()
45474 if( zName[0]=='.' ){ in appendOnePathElement()
45478 assert( pPath->zOut[0]=='/' ); in appendOnePathElement()
45495 pPath->zOut[pPath->nUsed] = 0; in appendOnePathElement()
45497 if( osLstat(zIn, &buf)!=0 ){ in appendOnePathElement()
45509 if( got<=0 || got>=(ssize_t)sizeof(zLnk)-2 ){ in appendOnePathElement()
45513 zLnk[got] = 0; in appendOnePathElement()
45514 if( zLnk[0]=='/' ){ in appendOnePathElement()
45515 pPath->nUsed = 0; in appendOnePathElement()
45532 int i = 0; in appendAllPathElements()
45533 int j = 0; in appendAllPathElements()
45560 path.rc = 0; in unixFullPathname()
45561 path.nUsed = 0; in unixFullPathname()
45562 path.nSymlink = 0; in unixFullPathname()
45565 if( zPath[0]!='/' ){ in unixFullPathname()
45567 if( osGetcwd(zPwd, sizeof(zPwd)-2)==0 ){ in unixFullPathname()
45573 zOut[path.nUsed] = 0; in unixFullPathname()
45635 #define unixDlOpen 0
45636 #define unixDlError 0
45637 #define unixDlSym 0
45638 #define unixDlClose 0
45660 memset(zBuf, 0, nBuf); in unixRandomness()
45661 randomnessPid = osGetpid(0); in unixRandomness()
45665 fd = robust_open("/dev/urandom", O_RDONLY, 0); in unixRandomness()
45666 if( fd<0 ){ in unixRandomness()
45674 do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR ); in unixRandomness()
45675 robust_close(0, fd, __LINE__); in unixRandomness()
45692 #if !defined(HAVE_NANOSLEEP) || HAVE_NANOSLEEP+0 in unixSleep()
45699 ** -DHAVE_NANOSLEEP=0 (perhaps in conjunction with -DHAVE_USLEEP if in unixSleep()
45724 SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
45750 (void)gettimeofday(&sNow, 0); /* Cannot fail given valid arguments */ in unixCurrentTimeInt64()
45767 ** return 0. Return 1 if the time and date cannot be found.
45770 sqlite3_int64 i = 0; in unixCurrentTime()
45773 rc = unixCurrentTimeInt64(0, &i); in unixCurrentTime()
45778 # define unixCurrentTime 0
45823 ** PENDING_BYTE 0x40000000
45824 ** RESERVED_BYTE 0x40000001
45825 ** SHARED_RANGE 0x40000002 -> 0x40000200
45943 ** force proxy locking to be used for every database file opened, and 0
45988 lPath, errno, osGetpid(0))); in proxyGetLockPath()
46004 for( i=0; i<dbLen && (i+len+7)<(int)maxLen; i++){ in proxyGetLockPath()
46008 lPath[i+len]='\0'; in proxyGetLockPath()
46010 OSTRACE(("GETLOCKPATH proxy lock path=%s pid=%d\n", lPath, osGetpid(0))); in proxyGetLockPath()
46020 int start = 0; in proxyCreateLockPath()
46025 buf[0] = lockPath[0]; in proxyCreateLockPath()
46027 if( lockPath[i] == '/' && (i - start > 0) ){ in proxyCreateLockPath()
46031 buf[i]='\0'; in proxyCreateLockPath()
46037 buf, strerror(err), lockPath, osGetpid(0))); in proxyCreateLockPath()
46046 OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n",lockPath,osGetpid(0))); in proxyCreateLockPath()
46047 return 0; in proxyCreateLockPath()
46067 int terrno = 0; in proxyCreateUnixFile()
46085 if( fd<0 ){ in proxyCreateUnixFile()
46086 fd = robust_open(path, openFlags, 0); in proxyCreateUnixFile()
46088 if( fd<0 && errno==ENOENT && islockfile ){ in proxyCreateUnixFile()
46090 fd = robust_open(path, openFlags, 0); in proxyCreateUnixFile()
46094 if( fd<0 ){ in proxyCreateUnixFile()
46096 fd = robust_open(path, openFlags, 0); in proxyCreateUnixFile()
46099 if( fd<0 ){ in proxyCreateUnixFile()
46118 memset(pNew, 0, sizeof(unixFile)); in proxyCreateUnixFile()
46120 memset(&dummyVfs, 0, sizeof(dummyVfs)); in proxyCreateUnixFile()
46127 rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0); in proxyCreateUnixFile()
46141 SQLITE_API int sqlite3_hostid_num = 0;
46156 memset(pHostID, 0, PROXY_HOSTIDLEN); in proxyGetHostID()
46159 struct timespec timeout = {1, 0}; /* 1 sec timeout */ in proxyGetHostID()
46173 if( sqlite3_hostid_num != 0){ in proxyGetHostID()
46174 pHostID[0] = (char)(pHostID[0] + (char)(sqlite3_hostid_num & 0xFF)); in proxyGetHostID()
46200 size_t readLen = 0; in proxyBreakConchLock()
46201 size_t pathLen = 0; in proxyBreakConchLock()
46215 readLen = osPread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0); in proxyBreakConchLock()
46221 fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW), 0); in proxyBreakConchLock()
46222 if( fd<0 ){ in proxyBreakConchLock()
46226 if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){ in proxyBreakConchLock()
46234 rc = 0; in proxyBreakConchLock()
46242 if( fd>=0 ){ in proxyBreakConchLock()
46258 int nTries = 0; in proxyConchLock()
46261 memset(&conchModTime, 0, sizeof(conchModTime)); in proxyConchLock()
46280 unixSleep(0,500000); /* wait 0.5 sec and try the lock again*/ in proxyConchLock()
46292 int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0); in proxyConchLock()
46293 if( len<0 ){ in proxyConchLock()
46297 if( len>PROXY_PATHINDEX && tBuf[0]==(char)PROXY_CONCHVERSION){ in proxyConchLock()
46299 if( 0!=memcmp(&tBuf[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN) ){ in proxyConchLock()
46306 unixSleep(0,10000000); /* wait 10 sec and try the lock again */ in proxyConchLock()
46311 if( 0==proxyBreakConchLock(pFile, myHostID) ){ in proxyConchLock()
46335 if( pCtx->conchHeld!=0 ){ in proxyTakeConch()
46340 int pError = 0; in proxyTakeConch()
46345 int createConch = 0; in proxyTakeConch()
46346 int hostIdMatch = 0; in proxyTakeConch()
46347 int readLen = 0; in proxyTakeConch()
46348 int tryOldLockPath = 0; in proxyTakeConch()
46349 int forceNewLockPath = 0; in proxyTakeConch()
46353 osGetpid(0))); in proxyTakeConch()
46356 if( (rc&0xff)==SQLITE_IOERR ){ in proxyTakeConch()
46365 readLen = seekAndRead((unixFile*)conchFile, 0, readBuf, PROXY_MAXCONCHLEN); in proxyTakeConch()
46366 if( readLen<0 ){ in proxyTakeConch()
46372 readBuf[0]!=(char)PROXY_CONCHVERSION ){ in proxyTakeConch()
46399 lockPath[pathLen] = 0; in proxyTakeConch()
46415 if( (conchFile->openFlags&O_RDWR) == 0 ){ in proxyTakeConch()
46445 int writeSize = 0; in proxyTakeConch()
46447 writeBuffer[0] = (char)PROXY_CONCHVERSION; in proxyTakeConch()
46457 rc = unixWrite((sqlite3_file *)conchFile, writeBuffer, writeSize, 0); in proxyTakeConch()
46458 full_fsync(conchFile->h,0,0); in proxyTakeConch()
46465 if( err==0 ){ in proxyTakeConch()
46475 if( rc!=0 ){ in proxyTakeConch()
46496 if( pFile->h>=0 ){ in proxyTakeConch()
46500 fd = robust_open(pCtx->dbPath, pFile->openFlags, 0); in proxyTakeConch()
46502 if( fd>=0 ){ in proxyTakeConch()
46517 tryOldLockPath = 0; in proxyTakeConch()
46526 pCtx->lockProxyPath = sqlite3DbStrDup(0, tempLockPath); in proxyTakeConch()
46563 osGetpid(0))); in proxyReleaseConch()
46564 if( pCtx->conchHeld>0 ){ in proxyReleaseConch()
46567 pCtx->conchHeld = 0; in proxyReleaseConch()
46592 if( conchPath==0 ){ in proxyCreateConchPathname()
46598 for( i=(len-1); i>=0; i-- ){ in proxyCreateConchPathname()
46631 if( !path || path[0]=='\0' || !strcmp(path, ":auto:") || in switchLockProxyPath()
46637 pCtx->conchHeld = 0; in switchLockProxyPath()
46644 pCtx->lockProxyPath = sqlite3DbStrDup(0, path); in switchLockProxyPath()
46698 if( !path || path[0]=='\0' || !strcmp(path, ":auto:") ){ in proxyTransformUnixFile()
46705 (lockPath ? lockPath : ":auto:"), osGetpid(0))); in proxyTransformUnixFile()
46708 if( pCtx==0 ){ in proxyTransformUnixFile()
46711 memset(pCtx, 0, sizeof(*pCtx)); in proxyTransformUnixFile()
46715 rc = proxyCreateUnixFile(pCtx->conchFilePath, &pCtx->conchFile, 0); in proxyTransformUnixFile()
46716 if( rc==SQLITE_CANTOPEN && ((pFile->openFlags&O_RDWR) == 0) ){ in proxyTransformUnixFile()
46719 ** Ugh, since O_RDONLY==0x0000 we test for !O_RDWR since unixOpen asserts in proxyTransformUnixFile()
46724 int goLockless = 0; in proxyTransformUnixFile()
46739 pCtx->lockProxyPath = sqlite3DbStrDup(0, lockPath); in proxyTransformUnixFile()
46743 pCtx->dbPath = sqlite3DbStrDup(0, dbPath); in proxyTransformUnixFile()
46761 sqlite3DbFree(0, pCtx->lockProxyPath); in proxyTransformUnixFile()
46796 if( pArg==NULL || (const char *)pArg==0 ){ in proxyFileControl()
46828 assert( 0 ); /* The call assures that only valid opcodes are sent */ in proxyFileControl()
46831 /*NOTREACHED*/ assert(0); in proxyFileControl()
46853 if( pCtx->conchHeld>0 ){ in proxyCheckReservedLock()
46856 }else{ /* conchHeld < 0 is lockless */ in proxyCheckReservedLock()
46857 pResOut=0; in proxyCheckReservedLock()
46892 if( pCtx->conchHeld>0 ){ in proxyLock()
46897 /* conchHeld < 0 is lockless */ in proxyLock()
46916 if( pCtx->conchHeld>0 ){ in proxyUnlock()
46921 /* conchHeld < 0 is lockless */ in proxyUnlock()
46944 pCtx->lockProxy = 0; in proxyClose()
46955 sqlite3DbFree(0, pCtx->lockProxyPath); in proxyClose()
46957 sqlite3DbFree(0, pCtx->dbPath); in proxyClose()
47017 0, /* pNext */ \ in sqlite3_os_init()
47078 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ in sqlite3_os_init()
47081 0==strcmp(aVfs[i].zName,SQLITE_DEFAULT_UNIX_VFS)); in sqlite3_os_init()
47083 sqlite3_vfs_register(&aVfs[i], i==0); in sqlite3_os_init()
47099 ** READ-0 UNIX_SHM_BASE+3 123 in sqlite3_os_init()
47123 unixBigLock = 0; in sqlite3_os_end()
47167 #if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0
47169 compile with SQLITE_MAX_MMAP_SIZE=0."
47202 # define NTDDI_WIN8 0x06020000
47206 # define NTDDI_WINBLUE 0x06030000
47210 # define NTDDI_WINTHRESHOLD 0x06040000
47219 # define SQLITE_WIN32_GETVERSIONEX 0 /* GetVersionEx() is deprecated */
47232 # define SQLITE_WIN32_CREATEFILEMAPPINGA 0
47322 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
47362 # define FILE_FLAG_MASK (0xFF3C0000)
47366 # define FILE_ATTRIBUTE_MASK (0x0003FFF7)
47413 #if SQLITE_MAX_MMAP_SIZE>0
47429 # define winFileBusyTimeout(pDbFd) 0
47446 #define WINFILE_RDONLY 0x02 /* Connection is read only */
47447 #define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */
47448 #define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
47513 # if SQLITE_DEFAULT_CACHE_SIZE>=0
47543 # define SQLITE_WIN32_HEAP_MAX_SIZE (0)
47551 # define SQLITE_WIN32_HEAP_FLAGS (0)
47572 #define WINMEM_MAGIC1 0x42b2830b
47573 #define WINMEM_MAGIC2 0xbd4d7cf4
47614 ** 0: Operating system unknown.
47622 SQLITE_API LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0;
47624 static LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0;
47651 { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 },
47653 { "AreFileApisANSI", (SYSCALL)0, 0 },
47657 #define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent)
47661 { "CharLowerW", (SYSCALL)CharLowerW, 0 },
47663 { "CharLowerW", (SYSCALL)0, 0 },
47669 { "CharUpperW", (SYSCALL)CharUpperW, 0 },
47671 { "CharUpperW", (SYSCALL)0, 0 },
47676 { "CloseHandle", (SYSCALL)CloseHandle, 0 },
47681 { "CreateFileA", (SYSCALL)CreateFileA, 0 },
47683 { "CreateFileA", (SYSCALL)0, 0 },
47690 { "CreateFileW", (SYSCALL)CreateFileW, 0 },
47692 { "CreateFileW", (SYSCALL)0, 0 },
47699 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) && \
47701 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
47703 { "CreateFileMappingA", (SYSCALL)0, 0 },
47710 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
47711 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
47713 { "CreateFileMappingW", (SYSCALL)0, 0 },
47720 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 },
47722 { "CreateMutexW", (SYSCALL)0, 0 },
47729 { "DeleteFileA", (SYSCALL)DeleteFileA, 0 },
47731 { "DeleteFileA", (SYSCALL)0, 0 },
47737 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
47739 { "DeleteFileW", (SYSCALL)0, 0 },
47745 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
47747 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
47754 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
47756 { "FileTimeToSystemTime", (SYSCALL)0, 0 },
47762 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
47767 { "FormatMessageA", (SYSCALL)FormatMessageA, 0 },
47769 { "FormatMessageA", (SYSCALL)0, 0 },
47776 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
47778 { "FormatMessageW", (SYSCALL)0, 0 },
47785 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
47787 { "FreeLibrary", (SYSCALL)0, 0 },
47792 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
47797 { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 },
47799 { "GetDiskFreeSpaceA", (SYSCALL)0, 0 },
47806 { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 },
47808 { "GetDiskFreeSpaceW", (SYSCALL)0, 0 },
47815 { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 },
47817 { "GetFileAttributesA", (SYSCALL)0, 0 },
47823 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
47825 { "GetFileAttributesW", (SYSCALL)0, 0 },
47831 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
47833 { "GetFileAttributesExW", (SYSCALL)0, 0 },
47840 { "GetFileSize", (SYSCALL)GetFileSize, 0 },
47842 { "GetFileSize", (SYSCALL)0, 0 },
47848 { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 },
47850 { "GetFullPathNameA", (SYSCALL)0, 0 },
47857 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
47859 { "GetFullPathNameW", (SYSCALL)0, 0 },
47871 { "GetLastError", (SYSCALL)GetLastError, 0 },
47878 { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 },
47882 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
47885 { "GetProcAddressA", (SYSCALL)0, 0 },
47892 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
47894 { "GetSystemInfo", (SYSCALL)0, 0 },
47899 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
47904 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
47906 { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 },
47913 { "GetTempPathA", (SYSCALL)GetTempPathA, 0 },
47915 { "GetTempPathA", (SYSCALL)0, 0 },
47921 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
47923 { "GetTempPathW", (SYSCALL)0, 0 },
47929 { "GetTickCount", (SYSCALL)GetTickCount, 0 },
47931 { "GetTickCount", (SYSCALL)0, 0 },
47937 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
47939 { "GetVersionExA", (SYSCALL)0, 0 },
47947 { "GetVersionExW", (SYSCALL)GetVersionExW, 0 },
47949 { "GetVersionExW", (SYSCALL)0, 0 },
47955 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
47961 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
47963 { "HeapCreate", (SYSCALL)0, 0 },
47970 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
47972 { "HeapDestroy", (SYSCALL)0, 0 },
47977 { "HeapFree", (SYSCALL)HeapFree, 0 },
47981 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
47986 { "HeapSize", (SYSCALL)HeapSize, 0 },
47992 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
47994 { "HeapValidate", (SYSCALL)0, 0 },
48001 { "HeapCompact", (SYSCALL)HeapCompact, 0 },
48003 { "HeapCompact", (SYSCALL)0, 0 },
48009 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
48011 { "LoadLibraryA", (SYSCALL)0, 0 },
48018 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
48020 { "LoadLibraryW", (SYSCALL)0, 0 },
48026 { "LocalFree", (SYSCALL)LocalFree, 0 },
48028 { "LocalFree", (SYSCALL)0, 0 },
48034 { "LockFile", (SYSCALL)LockFile, 0 },
48036 { "LockFile", (SYSCALL)0, 0 },
48045 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
48047 { "LockFileEx", (SYSCALL)0, 0 },
48056 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
48057 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
48059 { "MapViewOfFile", (SYSCALL)0, 0 },
48065 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
48070 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
48075 { "ReadFile", (SYSCALL)ReadFile, 0 },
48080 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
48085 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
48087 { "SetFilePointer", (SYSCALL)0, 0 },
48094 { "Sleep", (SYSCALL)Sleep, 0 },
48096 { "Sleep", (SYSCALL)0, 0 },
48101 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
48107 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
48109 { "UnlockFile", (SYSCALL)0, 0 },
48118 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
48120 { "UnlockFileEx", (SYSCALL)0, 0 },
48126 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
48127 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
48129 { "UnmapViewOfFile", (SYSCALL)0, 0 },
48134 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
48139 { "WriteFile", (SYSCALL)WriteFile, 0 },
48145 { "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
48147 { "CreateEventExW", (SYSCALL)0, 0 },
48159 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
48165 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
48167 { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
48174 { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
48176 { "SetFilePointerEx", (SYSCALL)0, 0 },
48183 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
48185 { "GetFileInformationByHandleEx", (SYSCALL)0, 0 },
48191 #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
48192 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
48194 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
48201 { "CreateFile2", (SYSCALL)CreateFile2, 0 },
48203 { "CreateFile2", (SYSCALL)0, 0 },
48210 { "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
48212 { "LoadPackagedLibrary", (SYSCALL)0, 0 },
48219 { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
48221 { "GetTickCount64", (SYSCALL)0, 0 },
48227 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
48229 { "GetNativeSystemInfo", (SYSCALL)0, 0 },
48236 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
48238 { "OutputDebugStringA", (SYSCALL)0, 0 },
48244 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
48246 { "OutputDebugStringW", (SYSCALL)0, 0 },
48251 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
48255 #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
48256 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
48258 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
48270 { "InterlockedCompareExchange", (SYSCALL)0, 0 },
48274 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
48281 { "UuidCreate", (SYSCALL)UuidCreate, 0 },
48283 { "UuidCreate", (SYSCALL)0, 0 },
48289 { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
48291 { "UuidCreateSequential", (SYSCALL)0, 0 },
48297 #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
48298 { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
48300 { "FlushViewOfFile", (SYSCALL)0, 0 },
48314 { "CreateEvent", (SYSCALL)CreateEvent, 0 },
48316 { "CreateEvent", (SYSCALL)0, 0 },
48333 { "CancelIo", (SYSCALL)CancelIo, 0 },
48335 { "CancelIo", (SYSCALL)0, 0 },
48341 { "GetModuleHandleW", (SYSCALL)GetModuleHandleW, 0 },
48343 { "GetModuleHandleW", (SYSCALL)0, 0 },
48349 { "getenv", (SYSCALL)getenv, 0 },
48351 { "getenv", (SYSCALL)0, 0 },
48357 { "getcwd", (SYSCALL)getcwd, 0 },
48359 { "getcwd", (SYSCALL)0, 0 },
48365 { "readlink", (SYSCALL)readlink, 0 },
48367 { "readlink", (SYSCALL)0, 0 },
48373 { "lstat", (SYSCALL)lstat, 0 },
48375 { "lstat", (SYSCALL)0, 0 },
48381 { "__errno", (SYSCALL)__errno, 0 },
48383 { "__errno", (SYSCALL)0, 0 },
48389 { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
48391 { "cygwin_conv_path", (SYSCALL)0, 0 },
48414 if( zName==0 ){ in winSetSystemCall()
48419 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ in winSetSystemCall()
48428 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ in winSetSystemCall()
48429 if( strcmp(zName, aSyscall[i].zName)==0 ){ in winSetSystemCall()
48430 if( aSyscall[i].pDefault==0 ){ in winSetSystemCall()
48434 if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault; in winSetSystemCall()
48455 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ in winGetSystemCall()
48456 if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent; in winGetSystemCall()
48458 return 0; in winGetSystemCall()
48472 for(i=0; i<ArraySize(aSyscall)-1; i++){ in winNextSystemCall()
48473 if( strcmp(zName, aSyscall[i].zName)==0 ) break; in winNextSystemCall()
48477 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName; in winNextSystemCall()
48479 return 0; in winNextSystemCall()
48492 UINT nLargest = 0; in sqlite3_win32_compact_heap()
48497 assert( hHeap!=0 ); in sqlite3_win32_compact_heap()
48503 if( (nLargest=osHeapCompact(hHeap, SQLITE_WIN32_HEAP_FLAGS))==0 ){ in sqlite3_win32_compact_heap()
48539 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){ in sqlite3_win32_reset_heap()
48549 assert( sqlite3_memory_used()==0 ); in sqlite3_win32_reset_heap()
48553 assert( sqlite3_memory_used()==0 ); in sqlite3_win32_reset_heap()
48557 assert( rc!=SQLITE_OK || sqlite3_memory_used()==0 ); in sqlite3_win32_reset_heap()
48580 assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE ); in sqlite3_win32_write_debug()
48588 if( nMin>0 ){ in sqlite3_win32_write_debug()
48589 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); in sqlite3_win32_write_debug()
48596 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); in sqlite3_win32_write_debug()
48598 osAreFileApisANSI() ? CP_ACP : CP_OEMCP, 0, zBuf, in sqlite3_win32_write_debug()
48599 nMin, (LPWSTR)zDbgBuf, SQLITE_WIN32_DBG_BUF_SIZE/sizeof(WCHAR))<=0 ){ in sqlite3_win32_write_debug()
48604 if( nMin>0 ){ in sqlite3_win32_write_debug()
48605 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); in sqlite3_win32_write_debug()
48636 #if SQLITE_MAX_WORKER_THREADS>0 && !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
48637 SQLITE_THREADSAFE>0
48663 # define osIsNT() (0)
48680 if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){ in sqlite3_win32_is_nt()
48686 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0); in sqlite3_win32_is_nt()
48692 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0); in sqlite3_win32_is_nt()
48698 || osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 in sqlite3_win32_is_nt()
48719 assert( hHeap!=0 ); in winMemMalloc()
48724 assert( nBytes>=0 ); in winMemMalloc()
48741 assert( hHeap!=0 ); in winMemFree()
48762 assert( hHeap!=0 ); in winMemRealloc()
48767 assert( nBytes>=0 ); in winMemRealloc()
48790 assert( hHeap!=0 ); in winMemSize()
48795 if( !p ) return 0; in winMemSize()
48800 return 0; in winMemSize()
48826 if( dwMaximumSize==0 ){ in winMemInit()
48853 assert( pWinMemData->hHeap!=0 ); in winMemInit()
48924 nChar = osMultiByteToWideChar(CP_UTF8, 0, zText, -1, NULL, 0); in winUtf8ToUnicode()
48925 if( nChar==0 ){ in winUtf8ToUnicode()
48926 return 0; in winUtf8ToUnicode()
48929 if( zWideText==0 ){ in winUtf8ToUnicode()
48930 return 0; in winUtf8ToUnicode()
48932 nChar = osMultiByteToWideChar(CP_UTF8, 0, zText, -1, zWideText, in winUtf8ToUnicode()
48934 if( nChar==0 ){ in winUtf8ToUnicode()
48936 zWideText = 0; in winUtf8ToUnicode()
48951 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideText, -1, 0, 0, 0, 0); in winUnicodeToUtf8()
48952 if( nByte == 0 ){ in winUnicodeToUtf8()
48953 return 0; in winUnicodeToUtf8()
48956 if( zText==0 ){ in winUnicodeToUtf8()
48957 return 0; in winUnicodeToUtf8()
48959 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideText, -1, zText, nByte, in winUnicodeToUtf8()
48960 0, 0); in winUnicodeToUtf8()
48961 if( nByte == 0 ){ in winUnicodeToUtf8()
48963 zText = 0; in winUnicodeToUtf8()
48979 nWideChar = osMultiByteToWideChar(codepage, 0, zText, -1, NULL, in winMbcsToUnicode()
48980 0); in winMbcsToUnicode()
48981 if( nWideChar==0 ){ in winMbcsToUnicode()
48982 return 0; in winMbcsToUnicode()
48985 if( zMbcsText==0 ){ in winMbcsToUnicode()
48986 return 0; in winMbcsToUnicode()
48988 nWideChar = osMultiByteToWideChar(codepage, 0, zText, -1, zMbcsText, in winMbcsToUnicode()
48990 if( nWideChar==0 ){ in winMbcsToUnicode()
48992 zMbcsText = 0; in winMbcsToUnicode()
49009 nByte = osWideCharToMultiByte(codepage, 0, zWideText, -1, 0, 0, 0, 0); in winUnicodeToMbcs()
49010 if( nByte == 0 ){ in winUnicodeToMbcs()
49011 return 0; in winUnicodeToMbcs()
49014 if( zText==0 ){ in winUnicodeToMbcs()
49015 return 0; in winUnicodeToMbcs()
49017 nByte = osWideCharToMultiByte(codepage, 0, zWideText, -1, zText, in winUnicodeToMbcs()
49018 nByte, 0, 0); in winUnicodeToMbcs()
49019 if( nByte == 0 ){ in winUnicodeToMbcs()
49021 zText = 0; in winUnicodeToMbcs()
49037 if( zTmpWide==0 ){ in winMbcsToUtf8()
49038 return 0; in winMbcsToUtf8()
49056 if( zTmpWide==0 ){ in winUtf8ToMbcs()
49057 return 0; in winUtf8ToMbcs()
49071 return 0; in sqlite3_win32_utf8_to_unicode()
49075 if( sqlite3_initialize() ) return 0; in sqlite3_win32_utf8_to_unicode()
49087 return 0; in sqlite3_win32_unicode_to_utf8()
49091 if( sqlite3_initialize() ) return 0; in sqlite3_win32_unicode_to_utf8()
49104 return 0; in sqlite3_win32_mbcs_to_utf8()
49108 if( sqlite3_initialize() ) return 0; in sqlite3_win32_mbcs_to_utf8()
49121 return 0; in sqlite3_win32_mbcs_to_utf8_v2()
49125 if( sqlite3_initialize() ) return 0; in sqlite3_win32_mbcs_to_utf8_v2()
49137 return 0; in sqlite3_win32_utf8_to_mbcs()
49141 if( sqlite3_initialize() ) return 0; in sqlite3_win32_utf8_to_mbcs()
49153 return 0; in sqlite3_win32_utf8_to_mbcs_v2()
49157 if( sqlite3_initialize() ) return 0; in sqlite3_win32_utf8_to_mbcs_v2()
49170 char **ppDirectory = 0; in sqlite3_win32_set_directory8()
49187 char *zCopy = 0; in sqlite3_win32_set_directory8()
49188 if( zValue && zValue[0] ){ in sqlite3_win32_set_directory8()
49190 if ( zCopy==0 ){ in sqlite3_win32_set_directory8()
49215 char *zUtf8 = 0; in sqlite3_win32_set_directory16()
49218 if( zUtf8==0 ) return SQLITE_NOMEM_BKPT; in sqlite3_win32_set_directory16()
49246 /* FormatMessage returns 0 on failure. Otherwise it in winGetLastErrorMsg()
49250 DWORD dwLen = 0; in winGetLastErrorMsg()
49251 char *zOut = 0; in winGetLastErrorMsg()
49260 0, in winGetLastErrorMsg()
49263 0); in winGetLastErrorMsg()
49271 0, in winGetLastErrorMsg()
49273 0, in winGetLastErrorMsg()
49274 0); in winGetLastErrorMsg()
49276 if( dwLen > 0 ){ in winGetLastErrorMsg()
49295 0, in winGetLastErrorMsg()
49297 0, in winGetLastErrorMsg()
49298 0); in winGetLastErrorMsg()
49299 if( dwLen > 0 ){ in winGetLastErrorMsg()
49309 if( 0 == dwLen ){ in winGetLastErrorMsg()
49310 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%lx (%lu)", lastErrno, lastErrno); in winGetLastErrorMsg()
49317 return 0; in winGetLastErrorMsg()
49346 zMsg[0] = 0; in winLogErrorAtLine()
49349 if( zPath==0 ) zPath = ""; in winLogErrorAtLine()
49350 for(i=0; zMsg[i] && zMsg[i]!='\r' && zMsg[i]!='\n'; i++){} in winLogErrorAtLine()
49351 zMsg[i] = 0; in winLogErrorAtLine()
49412 return 0; in winRetryIoerr()
49429 return 0; in winRetryIoerr()
49463 uTm.dwLowDateTime = (DWORD)(t64 & 0xFFFFFFFF); in localtime()
49510 if( zName==0 ){ in winceCreateLock()
49516 memset(&pFile->local, 0, sizeof(pFile->local)); in winceCreateLock()
49543 PAGE_READWRITE, 0, sizeof(winceLock), in winceCreateLock()
49558 FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock)); in winceCreateLock()
49586 memset(pFile->shared, 0, sizeof(winceLock)); in winceCreateLock()
49649 if (pFile->shared->nReaders == 0 && pFile->shared->bExclusive == 0){ in winceLockFile()
49659 if (pFile->shared->bExclusive == 0){ in winceLockFile()
49672 if (pFile->shared->bPending == 0) { in winceLockFile()
49682 if (pFile->shared->bReserved == 0) { in winceLockFile()
49727 if (pFile->local.nReaders == 0) in winceUnlockFile()
49783 memset(&ovlp, 0, sizeof(OVERLAPPED)); in winLockFile()
49786 return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp); in winLockFile()
49803 ** some other process holds the lock, SQLITE_BUSY is returned if nMs==0, or
49813 DWORD flags = LOCKFILE_FAIL_IMMEDIATELY | (bExcl?LOCKFILE_EXCLUSIVE_LOCK:0); in winHandleLockTimeout()
49818 ret = winLockFile(&hFile, flags, offset, 0, nByte, 0); in winHandleLockTimeout()
49821 memset(&ovlp, 0, sizeof(OVERLAPPED)); in winHandleLockTimeout()
49825 if( nMs!=0 ){ in winHandleLockTimeout()
49834 ret = osLockFileEx(hFile, flags, 0, nByte, 0, &ovlp); in winHandleLockTimeout()
49842 ** If nMs is 0, then LOCKFILE_FAIL_IMMEDIATELY was set in the flags in winHandleLockTimeout()
49850 DWORD nDelay = (nMs==0 ? INFINITE : nMs); in winHandleLockTimeout()
49899 memset(&ovlp, 0, sizeof(OVERLAPPED)); in winUnlockFile()
49902 return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp); in winUnlockFile()
49916 BOOL ret = winUnlockFile(&h, iOff, 0, nByte, 0); in winHandleUnlock()
49946 upperBits = (LONG)((iOffset>>32) & 0x7fffffff); in winHandleSeek()
49947 lowerBits = (LONG)(iOffset & 0xffffffff); in winHandleSeek()
49969 bRet = osSetFilePointerEx(h, x, 0, FILE_BEGIN); in winHandleSeek()
49982 ** argument to offset iOffset within the file. If successful, return 0.
49997 #if SQLITE_MAX_MMAP_SIZE>0
50015 int rc, cnt = 0; in winClose()
50018 assert( id!=0 ); in winClose()
50020 assert( pFile->pShm==0 ); in winClose()
50026 #if SQLITE_MAX_MMAP_SIZE>0 in winClose()
50032 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ in winClose()
50033 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) ); in winClose()
50043 int cnt = 0; in winClose()
50045 osDeleteFileW(pFile->zDeleteOnClose)==0 in winClose()
50046 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff in winClose()
50081 int nRetry = 0; /* Number of retrys */
50083 assert( id!=0 );
50084 assert( amt>0 );
50085 assert( offset>=0 );
50091 #if SQLITE_MAX_MMAP_SIZE>0
50116 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
50118 memset(&overlapped, 0, sizeof(OVERLAPPED));
50119 overlapped.Offset = (LONG)(offset & 0xffffffff);
50120 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
50135 memset(&((char*)pBuf)[nRead], 0, amt-nRead);
50156 int rc = 0; /* True if error has occurred, else false */
50158 int nRetry = 0; /* Number of retries */
50160 assert( amt>0 );
50169 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0
50190 if( rc==0 ){
50203 memset(&overlapped, 0, sizeof(OVERLAPPED));
50204 overlapped.Offset = (LONG)(offset & 0xffffffff);
50205 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
50208 while( nRem>0 ){
50210 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
50217 assert( nWrite==0 || nWrite<=(DWORD)nRem );
50218 if( nWrite==0 || nWrite>(DWORD)nRem ){
50224 overlapped.Offset = (LONG)(offset & 0xffffffff);
50225 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
50230 if( nRem>0 ){
50263 if( 0==osSetEndOfFile(h) ){
50287 DWORD upperBits = 0;
50288 DWORD lowerBits = 0;
50317 #if SQLITE_MAX_MMAP_SIZE>0
50319 if( pFile->nFetchOut>0 ){
50351 if( pFile->szChunk>0 ){
50355 #if SQLITE_MAX_MMAP_SIZE>0
50359 oldMmapSize = 0;
50368 }else if( 0==osSetEndOfFile(pFile->h) &&
50375 #if SQLITE_MAX_MMAP_SIZE>0
50376 if( rc==SQLITE_OK && oldMmapSize>0 ){
50395 SQLITE_API int sqlite3_sync_count = 0;
50396 SQLITE_API int sqlite3_fullsync_count = 0;
50422 assert((flags&0x0F)==SQLITE_SYNC_NORMAL
50423 || (flags&0x0F)==SQLITE_SYNC_FULL
50438 if( (flags&0x0F)==SQLITE_SYNC_FULL ){
50452 #if SQLITE_MAX_MMAP_SIZE>0
50454 if( osFlushViewOfFile(pFile->pMapRegion, 0) ){
50491 assert( id!=0 );
50492 assert( pSize!=0 );
50567 DWORD mask = ~(bBlock ? LOCKFILE_FAIL_IMMEDIATELY : 0);
50575 res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
50577 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS&mask, SHARED_FIRST, 0,
50578 SHARED_SIZE, 0);
50585 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
50587 SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
50590 if( res == 0 ){
50606 res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
50610 res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
50613 if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
50644 ** erases all locks at once and returns us immediately to locking level 0.
50646 ** must go straight to locking level 0.
50652 int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */
50656 assert( id!=0 );
50671 if( (pFile->ctrlFlags & WINFILE_RDONLY)!=0 && locktype>=RESERVED_LOCK ){
50698 while( cnt>0 ){
50705 res = winLockFile(&pFile->h, flags, PENDING_BYTE, 0, 1, 0);
50723 if( cnt>0 ) sqlite3_win32_sleep(1);
50735 res = winGetReadLock(pFile, 0);
50748 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
50760 gotPendingLock = 0;
50768 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
50769 SHARED_SIZE, 0);
50774 winGetReadLock(pFile, 0);
50782 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
50814 assert( id!=0 );
50819 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0);
50821 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
50847 assert( pFile!=0 );
50853 winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
50854 if( locktype==SHARED_LOCK && !winGetReadLock(pFile, 0) ){
50862 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
50868 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
50916 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
50918 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
50921 if( *pArg<0 ){
50922 *pArg = (pFile->ctrlFlags & mask)!=0;
50923 }else if( (*pArg)==0 ){
50959 if( pFile->szChunk>0 ){
50967 SimulateIOErrorBenign(0);
50993 if( a[0]>0 ){
50994 winIoerrRetry = a[0];
50996 a[0] = winIoerrRetry;
50998 if( a[1]>0 ){
51029 char *zTFile = 0;
51037 #if SQLITE_MAX_MMAP_SIZE>0
51048 if( newLimit>0 && sizeof(SIZE_T)<8 ){
51049 newLimit = (newLimit & 0x7FFFFFFF);
51053 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
51055 if( pFile->mmapSize>0 ){
51070 pFile->iBusyTimeout = (iNew < 0) ? INFINITE : (DWORD)iNew;
51112 ((p->ctrlFlags & WINFILE_PSOW)?SQLITE_IOCAP_POWERSAFE_OVERWRITE:0);
51138 static sqlite3_mutex *winBigLock = 0;
51168 ** Either winShmNode.mutex must be held or winShmNode.nRef==0 and
51206 static winShmNode *winShmNodeList = 0;
51235 ** Purge the winShmNodeList list of all entries with winShmNode.nRef==0.
51247 while( (p = *pp)!=0 ){
51248 if( p->nRef==0 ){
51251 for(i=0; i<p->nRegion; i++){
51265 winDelete(pVfs, p->zFilename, 0);
51267 SimulateIOErrorBenign(0);
51288 rc = winHandleLockTimeout(h, WIN_SHM_DMS, 1, 1, 0);
51296 rc = winHandleTruncate(h, 0);
51300 winUnlockFile(&h, WIN_SHM_DMS, 0, 1, 0);
51301 }else if( (rc & 0xFF)==SQLITE_BUSY ){
51307 rc = winHandleLockTimeout(h, WIN_SHM_DMS, 1, 0, nMs);
51309 pShmNode->isUnlocked = 0;
51337 void *zConverted = 0;
51349 zFilename, 0, 0);
51350 if( nByte>0 ){
51352 if ( zConverted==0 ){
51359 zWideFilename+4, nByte)==0 ){
51375 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
51376 if( nChar==0 ){
51377 return 0;
51380 if( zWideFilename==0 ){
51381 return 0;
51383 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1,
51385 if( nChar==0 ){
51387 zWideFilename = 0;
51395 && winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1])
51426 void *zConverted = 0;
51433 const DWORD flag_overlapped = 0;
51438 if( zConverted==0 ){
51457 memset(&extendedParameters, 0, sizeof(extendedParameters));
51463 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)),/* dwDesiredAccess */
51470 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
51483 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
51494 if( bReadonly==0 ){
51515 winShmNode *pShmNode = 0; /* The underlying mmapped file */
51520 assert( pDbFd->pShm==0 ); /* Not previously opened */
51525 if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT;
51528 if( pNew==0 ){
51541 p->bReadonly = sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0);
51550 if( sqlite3StrICmp(pShmNode->zFilename, pNew->zFilename)==0 ) break;
51552 if( pShmNode==0 ){
51558 if( pShmNode->mutex==0 ) rc = SQLITE_IOERR_NOMEM_BKPT;
51574 pNew = 0;
51597 assert( rc!=SQLITE_OK || pShmNode->isUnlocked==0 || pShmNode->nRegion==0 );
51617 if( p==0 ) return SQLITE_OK;
51625 /* If pShmNode->nRef has reached 0, then close the underlying
51627 assert( pShmNode->nRef>0 );
51629 if( pShmNode->nRef==0 ){
51636 pDbFd->pShm = 0;
51655 if( p==0 ) return SQLITE_IOERR_SHMLOCK;
51657 if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
51659 assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
51665 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
51672 ** 3. Write lock (ofst==0).
51682 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
51683 (ofst!=2 || lockMask==0)
51684 && (ofst!=1 || lockMask==0 || lockMask==2)
51685 && (ofst!=0 || lockMask<3)
51700 || 0==(p->exclMask & mask)
51703 || (flags==(SQLITE_SHM_SHARED|SQLITE_SHM_LOCK) && 0==(p->sharedMask & mask))
51710 assert( (p->exclMask & p->sharedMask)==0 );
51722 int bExcl = ((flags & SQLITE_SHM_EXCLUSIVE) ? 1 : 0);
51768 ** Otherwise, if the isWrite parameter is 0 and the requested shared-memory
51797 assert( pShm!=0 );
51804 assert( pShmNode->nRegion==0 );
51809 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
51844 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
51859 void *pMap = 0; /* Mapped memory region */
51864 hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL);
51866 hMap = osCreateFileMappingA(hShared, NULL, protect, 0, nByte, NULL);
51881 0, iOffset - iOffsetShift, szRegion + iOffsetShift
51909 *pp = 0;
51919 # define winShmMap 0
51920 # define winShmLock 0
51921 # define winShmBarrier 0
51922 # define winShmUnmap 0
51928 #if SQLITE_MAX_MMAP_SIZE>0
51930 assert( pFile!=0 );
51944 pFile->pMapRegion = 0;
51945 pFile->mmapSize = 0;
51982 assert( nMap>=0 || pFd->nFetchOut==0 );
51986 if( pFd->nFetchOut>0 ) return SQLITE_OK;
51988 if( nMap<0 ){
52001 if( nMap==0 && pFd->mmapSize>0 ){
52005 void *pNew = 0;
52011 if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){
52020 (DWORD)((nMap>>32) & 0xffffffff),
52021 (DWORD)(nMap & 0xffffffff), NULL);
52024 (DWORD)((nMap>>32) & 0xffffffff),
52025 (DWORD)(nMap & 0xffffffff), NULL);
52036 assert( (nMap % winSysInfo.dwPageSize)==0 );
52037 assert( sizeof(SIZE_T)==sizeof(sqlite3_int64) || nMap<=0xffffffff );
52039 pNew = osMapViewOfFileFromApp(pFd->hMap, flags, 0, (SIZE_T)nMap);
52041 pNew = osMapViewOfFile(pFd->hMap, flags, 0, 0, (SIZE_T)nMap);
52062 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
52069 ** Or, if one cannot but no error occurs, set *pp to 0 and return SQLITE_OK.
52077 #if SQLITE_MAX_MMAP_SIZE>0
52080 *pp = 0;
52085 #if SQLITE_MAX_MMAP_SIZE>0
52086 if( pFd->mmapSizeMax>0 ){
52092 if( pFd->pMapRegion==0 ){
52101 assert( pFd->pMapRegion!=0 );
52124 #if SQLITE_MAX_MMAP_SIZE>0
52127 /* If p==0 (unmap the entire file) then there must be no outstanding
52128 ** xFetch references. Or, if p!=0 (meaning it is an xFetch reference),
52130 assert( (p==0)==(pFd->nFetchOut==0) );
52132 /* If p!=0, it must match the iOff value. */
52133 assert( p==0 || p==&((u8 *)pFd->pMapRegion)[iOff] );
52148 assert( pFd->nFetchOut>=0 );
52216 0, /* pAppData */
52217 0 /* bNoLock */
52222 0, /* pAppData */
52241 if( nLen>0 ){
52253 zBuf[nLen+1] = '\0';
52258 return 0;
52269 if( sqlite3_temp_directory!=0 ) return 1;
52271 return 0;
52311 assert( nDir>0 );
52314 if( nDirLen>0 ){
52322 return winLogError(SQLITE_ERROR, 0, "winGetTempname1", 0);
52332 0, /* getenv("SQLITE_TMPDIR") */
52333 0, /* getenv("TMPDIR") */
52334 0, /* getenv("TMP") */
52335 0, /* getenv("TEMP") */
52336 0, /* getenv("USERPROFILE") */
52341 0 /* List terminator */
52344 const char *zDir = 0;
52346 if( !azDirs[0] ) azDirs[0] = osGetenv("SQLITE_TMPDIR");
52351 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
52353 if( zDir==0 ) continue;
52386 if( osGetTempPathW(nMax, zWidePath)==0 ){
52391 "winGetTempname2", 0);
52414 if( osGetTempPathA(nMax, zMbcsPath)==0 ){
52418 "winGetTempname3", 0);
52441 return winLogError(SQLITE_ERROR, 0, "winGetTempname4", 0);
52448 ** "<temporary_directory>/etilqs_XXXXXXXXXXXXXXX\0\0"
52459 return winLogError(SQLITE_ERROR, 0, "winGetTempname5", 0);
52467 for(i=0; i<15; i++, j++){
52468 zBuf[j] += pid & 0xff;
52472 zBuf[j] = 0;
52473 zBuf[j+1] = 0;
52487 int rc = 0;
52491 int cnt = 0;
52493 memset(&sAttrData, 0, sizeof(sAttrData));
52498 return 0; /* Invalid name? */
52501 #if SQLITE_OS_WINCE==0 && defined(SQLITE_WIN32_HAS_ANSI)
52521 #define NORETRY 0x4000
52534 DWORD lastErrno = 0;
52538 DWORD dwFlagsAndAttributes = 0;
52540 int isTemp = 0;
52546 int cnt = 0;
52547 int isRO = 0; /* file is known to be accessible readonly */
52552 char *zTmpname = 0; /* For temporary filename, if necessary. */
52556 int eType = flags&0x0FFF00; /* Type of file to open */
52583 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
52584 assert(isCreate==0 || isReadWrite);
52585 assert(isExclusive==0 || isCreate);
52586 assert(isDelete==0 || isCreate);
52602 assert( pFile!=0 );
52603 memset(pFile, 0, sizeof(winFile));
52631 zUtf8Name[sqlite3Strlen30(zUtf8Name)+1]==0 );
52635 if( zConverted==0 ){
52670 if( 0==sqlite3_uri_boolean(zName, "exclusive", 0) ){
52673 dwShareMode = 0;
52788 *pOutFlags : 0, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
52827 #if SQLITE_MAX_MMAP_SIZE>0
52829 pFile->pMapRegion = 0;
52830 pFile->mmapSize = 0;
52855 int cnt = 0;
52858 DWORD lastErrno = 0;
52867 if( zConverted==0 ){
52875 memset(&sAttrData, 0, sizeof(sAttrData));
52965 int rc = 0;
52966 DWORD lastErrno = 0;
52968 int noRetry = 0; /* Do not use winRetryIoerr() */
52971 if( (flags & NORETRY)!=0 ){
52980 if( zFilename==0 ){
52981 *pResOut = 0;
52988 if( zConverted==0 ){
52993 int cnt = 0;
52995 memset(&sAttrData, 0, sizeof(sAttrData));
53007 && sAttrData.nFileSizeHigh==0
53008 && sAttrData.nFileSizeLow==0 ){
53037 (attr & FILE_ATTRIBUTE_READONLY)==0;
53055 return ( zPathname[0]=='\\' && zPathname[1]=='\\'
53066 return ( sqlite3Isalpha(zPathname[0]) && zPathname[1]==':' );
53086 if ( winIsDirSep(zPathname[0]) ){
53119 ** The original filename is in z[0..]. If the path is shortened,
53120 ** no-longer used bytes will be written by '\0'.
53124 for(i=j=0; z[i]; ++i){
53133 if( !z[i+1] || (winIsDirSep(z[i+1]) && (i!=0)) ){
53141 while(j<i) z[j++] = '\0';
53152 int iOff = 0;
53153 if( zPath[0]!='/' ){
53154 if( osGetcwd(zOut, nOut-2)==0 ){
53163 zOut[iOff] = '\0';
53191 if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1)
53200 zFull[nFull-1] = '\0';
53205 char *zDel = 0;
53213 int bLink = 0;
53215 if( osLstat(zIn, &buf)!=0 ){
53225 if( zDel==0 ){
53227 if( zDel==0 ) rc = SQLITE_NOMEM;
53237 if( zDel[0]!='/' ){
53239 for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
53248 zDel[nByte] = '\0';
53256 assert( rc!=SQLITE_OK || zIn!=zFull || zIn[0]=='/' );
53260 if( bLink==0 ) break;
53311 if( zConverted==0 ){
53316 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0);
53317 if( nByte==0 ){
53323 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
53324 if( zTemp==0 ){
53328 nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
53329 if( nByte==0 ){
53342 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0);
53343 if( nByte==0 ){
53348 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) );
53349 if( zTemp==0 ){
53353 nByte = osGetFullPathNameA((char*)zConverted, nByte+3, zTemp, 0);
53354 if( nByte==0 ){
53417 if( zConverted==0 ){
53418 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
53419 return 0;
53423 h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0);
53455 #define winDlOpen 0
53456 #define winDlError 0
53457 #define winDlSym 0
53458 #define winDlClose 0
53474 for(j=0, k=p->i; j<sz; j++){
53476 if( k>=p->na ) k = 0;
53489 memset(zBuf, 0, nBuf);
53494 memset(zBuf, 0, nBuf);
53497 e.nXor = 0;
53498 e.i = 0;
53527 memset(&id, 0, sizeof(UUID));
53530 memset(&id, 0, sizeof(UUID));
53555 SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
53609 ** return 0. Return 1 if the time and date cannot be found.
53643 ** assert(zBuf[0]=='\0');
53644 ** return 0;
53654 if( nBuf>0 ) winGetLastErrorMsg(e, nBuf, zBuf);
53666 0, /* pNext */
53691 0, /* pNext */
53716 0, /* pNext */
53741 0, /* pNext */
53768 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
53774 assert( winSysInfo.dwAllocationGranularity>0 );
53775 assert( winSysInfo.dwPageSize>0 );
53780 sqlite3_vfs_register(&winLongPathVfs, 0);
53783 sqlite3_vfs_register(&winNolockVfs, 0);
53786 sqlite3_vfs_register(&winLongPathNolockVfs, 0);
53805 winBigLock = 0;
53856 ** Shared memdb objects have .zFName!=0 and .pMutex!=0. They are created
53893 int nWrLock; /* Number of writers. (Always 0 or 1) */
53953 0, /* szOsFile (set when registered) */
53955 0, /* pNext */
53957 0, /* pAppData (set when registered) */
53959 0, /* memdbDelete, */ /* xDelete */
53968 0, /* memdbCurrentTime, */ /* xCurrentTime */
53971 0, /* xSetSystemCall */
53972 0, /* xGetSystemCall */
53973 0, /* xNextSystemCall */
53986 0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */
53988 0, /* memdbSectorSize,*/ /* xSectorSize */
53990 0, /* xShmMap */
53991 0, /* xShmLock */
53992 0, /* xShmBarrier */
53993 0, /* xShmUnmap */
54001 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE==0
54032 for(i=0; ALWAYS(i<memdb_g.nMemStore); i++){
54037 if( memdb_g.nMemStore==0 ){
54039 memdb_g.apMemStore = 0;
54050 if( p->nRef<=0 ){
54075 memset(zBuf, 0, iAmt);
54090 if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || NEVER(p->nMmap>0) ){
54099 if( pNew==0 ) return SQLITE_IOERR_NOMEM;
54130 if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz);
54189 assert( p->nWrLock==0 || p->nWrLock==1 );
54199 if( p->nWrLock>0 ){
54211 if( p->nWrLock>0 ){
54263 #if 0
54269 *pResOut = 0;
54289 if( iLimit<0 ){
54303 #if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */
54332 if( iOfst+iAmt>p->sz || (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)!=0 ){
54333 *pp = 0;
54364 MemStore *p = 0;
54368 memset(pFile, 0, sizeof(*pFile));
54370 if( szName>1 && (zName[0]=='/' || zName[0]=='\\') ){
54376 for(i=0; i<memdb_g.nMemStore; i++){
54377 if( strcmp(memdb_g.apMemStore[i]->zFName,zName)==0 ){
54382 if( p==0 ){
54385 if( p==0 ){
54390 sizeof(apNew[0])*(1+(i64)memdb_g.nMemStore) );
54391 if( apNew==0 ){
54398 memset(p, 0, sizeof(*p));
54404 if( p->pMutex==0 ){
54419 if( p==0 ){
54422 memset(p, 0, sizeof(*p));
54427 if( pOutFlags!=0 ){
54435 #if 0 /* Only used to delete rollback journals, super-journals, and WAL
54462 *pResOut = 0;
54528 #if 0 /* Never used. Modern cores only call xCurrentTimeInt64() */
54549 MemFile *p = 0;
54552 if( rc ) return 0;
54553 if( p->base.pMethods!=&memdb_io_methods ) return 0;
54556 if( pStore->zFName!=0 ) p = 0;
54574 int szPage = 0;
54575 sqlite3_stmt *pStmt = 0;
54583 return 0;
54587 if( zSchema==0 ) zSchema = db->aDb[0].zDbSName;
54591 if( iDb<0 ) return 0;
54594 assert( pStore->pMutex==0 );
54605 if( pBt==0 ) return 0;
54608 rc = zSql ? sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) : SQLITE_NOMEM;
54610 if( rc ) return 0;
54613 pOut = 0;
54615 sz = sqlite3_column_int64(pStmt, 0)*szPage;
54616 if( sz==0 ){
54618 sqlite3_exec(db, "BEGIN IMMEDIATE; COMMIT;", 0, 0, 0);
54621 sz = sqlite3_column_int64(pStmt, 0)*szPage;
54626 pOut = 0;
54630 int nPage = sqlite3_column_int(pStmt, 0);
54634 DbPage *pPage = 0;
54636 rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pPage, 0);
54640 memset(pTo, 0, szPage);
54663 sqlite3_stmt *pStmt = 0;
54671 if( szDb<0 ) return SQLITE_MISUSE_BKPT;
54672 if( szBuf<0 ) return SQLITE_MISUSE_BKPT;
54676 if( zSchema==0 ) zSchema = db->aDb[0].zDbSName;
54679 if( iDb<2 && iDb!=0 ){
54684 if( zSql==0 ){
54687 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
54694 db->init.reopenMemdb = 0;
54700 if( p==0 ){
54705 pData = 0;
54718 if( pData && (mFlags & SQLITE_DESERIALIZE_FREEONCLOSE)!=0 ){
54737 sqlite3_vfs *pLower = sqlite3_vfs_find(0);
54739 if( NEVER(pLower==0) ) return SQLITE_ERROR;
54743 ** Windows x86 and SQLITE_MAX_MMAP_SIZE=0. We always leave
54748 return sqlite3_vfs_register(&memdb_vfs, 0);
54836 ** If iSize>BITVEC_NBIT and iDivisor==0 then Bitvec.u.aHash[] is
54841 ** handles up to iDivisor separate values of i. apSub[0] holds
54853 /* Should >=0 for apSub element. */
54864 ** Create a new bitmap object able to handle bits between 0 and iSize,
54884 assert( p!=0 );
54886 if( i>=p->iSize ) return 0;
54892 return 0;
54896 return (p->u.aBitmap[i/BITVEC_SZELEM] & (1<<(i&(BITVEC_SZELEM-1))))!=0;
54903 return 0;
54907 return p!=0 && sqlite3BitvecTestNotNull(p,i);
54911 ** Set the i-th bit. Return 0 on success and an error code if
54924 if( p==0 ) return SQLITE_OK;
54925 assert( i>0 );
54931 if( p->u.apSub[bin]==0 ){
54933 if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM_BKPT;
54957 if( h>=BITVEC_NINT ) h = 0;
54966 u32 *aiValues = sqlite3StackAllocRaw(0, sizeof(p->u.aHash));
54967 if( aiValues==0 ){
54971 memset(p->u.apSub, 0, sizeof(p->u.apSub));
54973 if( (p->iSize%BITVEC_NPTR)!=0 ) p->iDivisor++;
54976 for(j=0; j<BITVEC_NINT; j++){
54979 sqlite3StackFree(0, aiValues);
54996 if( p==0 ) return;
54997 assert( i>0 );
55013 memset(p->u.aHash, 0, sizeof(p->u.aHash));
55014 p->nSet = 0;
55015 for(j=0; j<BITVEC_NINT; j++){
55021 if( h>=BITVEC_NINT ) h = 0;
55033 if( p==0 ) return;
55036 for(i=0; i<BITVEC_NPTR; i++){
55054 ** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
55060 #define TESTBIT(V,I) (V[I>>3]&(1<<(I&7)))!=0
55067 ** by 0, 1, or 3 operands, depending on the opcode. Another
55070 ** There are 6 opcodes numbered from 0 through 5. 0 is the
55073 ** 0 Halt and return the number of errors
55093 Bitvec *pBitvec = 0;
55094 unsigned char *pV = 0;
55104 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
55107 sqlite3BitvecSet(0, 1);
55108 sqlite3BitvecClear(0, 1, pTmpSpace);
55111 pc = i = 0;
55112 while( (op = aOp[pc])!=0 ){
55130 if( (--aOp[pc+1]) > 0 ) nx = 0;
55132 i = (i & 0x7fffffff)%sz;
55133 if( (op & 1)!=0 ){
55146 ** match (rc==0). Change rc to non-zero if a discrepancy
55149 rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1)
55150 + sqlite3BitvecTest(pBitvec, 0)
55227 ** Debug tracing macros. Enable by by changing the "0" to "1" and
55234 #if defined(SQLITE_DEBUG) && 0
55235 int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
55242 if( pLower==0 ){
55248 for(j=0; j<12; j++) printf("%02x", a[j]);
55258 if( pCache->pCache==0 ) return;
55262 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
55264 if( pLower && ((PgHdr*)pLower)->pPage==0 ){
55265 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
55276 ** Return 1 if pPg is on the dirty list for pCache. Return 0 if not.
55285 return 0;
55290 if( p==pPg ) return 0;
55311 assert( pPg!=0 );
55312 assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
55314 assert( pCache!=0 ); /* Every page has an associated PCache */
55316 assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
55319 assert( (pPg->flags & PGHDR_DIRTY)!=0 );/* If not CLEAN must be DIRTY */
55320 assert( pPg->pDirtyNext==0 || pPg->pDirtyNext->pDirtyPrev==pPg );
55321 assert( pPg->pDirtyPrev==0 || pPg->pDirtyPrev->pDirtyNext==pPg );
55322 assert( pPg->pDirtyPrev!=0 || pCache->pDirty==pPg );
55360 ** argument determines what operation to do. The 0x01 bit means first
55361 ** remove pPage from the dirty list. The 0x02 means add pPage back to
55395 if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/
55396 assert( p->bPurgeable==0 || p->eCreate==1 );
55402 pPage->pDirtyPrev = 0;
55405 assert( pPage->pDirtyNext->pDirtyPrev==0 );
55422 && 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
55437 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
55447 if( p->szCache>=0 ){
55469 if( sqlite3GlobalConfig.pcache2.xInit==0 ){
55474 assert( sqlite3GlobalConfig.pcache2.xInit!=0 );
55510 memset(p, 0, sizeof(PCache));
55529 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
55536 if( pNew==0 ) return SQLITE_NOMEM_BKPT;
55556 ** The createFlags should be 0 to check for existing pages and should
55559 ** If the createFlag is 0, then NULL is always returned if the page
55580 assert( pCache!=0 );
55581 assert( pCache->pCache!=0 );
55582 assert( createFlag==3 || createFlag==0 );
55586 ** 0 Do not allocate a new page. (createFlag==0)
55593 assert( eCreate==0 || eCreate==1 || eCreate==2 );
55594 assert( createFlag==0 || pCache->eCreate==eCreate );
55595 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
55620 if( pCache->eCreate==2 ) return 0;
55658 return *ppPage==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
55676 assert( pPage!=0 );
55678 assert( pPgHdr->pPage==0 );
55679 memset(&pPgHdr->pDirty, 0, sizeof(PgHdr) - offsetof(PgHdr,pDirty));
55683 memset(pPgHdr->pExtra, 0, 8);
55704 assert( pPage!=0 );
55718 ** reference count drops to 0, then it is made eligible for recycling.
55721 assert( p->nRef>0 );
55723 if( (--p->nRef)==0 ){
55737 assert(p->nRef>0);
55763 assert( p->nRef>0 );
55784 assert( (p->flags & PGHDR_DIRTY)!=0 );
55785 assert( (p->flags & PGHDR_CLEAN)==0 );
55791 if( p->nRef==0 ){
55802 while( (p = pCache->pDirty)!=0 ){
55836 assert( p->nRef>0 );
55837 assert( newPgno>0 );
55840 pOther = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, newPgno, 0);
55843 assert( pXPage->nRef==0 );
55862 ** function is 0, then the data area associated with page 1 is zeroed, but
55874 ** it must be that pgno==0.
55876 assert( p->pgno>0 );
55882 if( pgno==0 && pCache->nRefSum ){
55884 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
55886 ** pCache->nRefSum>0 */
55887 memset(pPage1->pBuf, 0, pCache->szPage);
55899 assert( pCache->pCache!=0 );
55908 sqlite3PcacheTruncate(pCache, 0);
55918 assert( pA!=0 && pB!=0 );
55924 if( pA==0 ){
55932 if( pB==0 ){
55955 memset(a, 0, sizeof(a));
55959 p->pDirty = 0;
55960 for(i=0; ALWAYS(i<N_SORT_BUCKET-1); i++){
55961 if( a[i]==0 ){
55966 a[i] = 0;
55976 p = a[0];
55978 if( a[i]==0 ) continue;
56016 assert( pCache->pCache!=0 );
56033 assert( pCache->pCache!=0 );
56046 assert( p->pCache!=0 );
56048 if( mxPage<0 ){
56062 assert( pCache->pCache!=0 );
56078 int nDirty = 0;
56081 return nCache ? (int)(((i64)nDirty * 100) / nCache) : 0;
56089 return (pCache->pDirty!=0);
56177 ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, N).
56234 /* NB: pLruPrev is only valid if pLruNext!=0 */
56241 #define PAGE_IS_PINNED(p) ((p)->pLruNext==0)
56242 #define PAGE_IS_UNPINNED(p) ((p)->pLruNext!=0)
56356 #if !defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || SQLITE_THREADSAFE==0
56357 # define pcache1EnterMutex(X) assert((X)->mutex==0)
56358 # define pcache1LeaveMutex(X) assert((X)->mutex==0)
56359 # define PCACHE1_MIGHT_USE_GROUP_MUTEX 0
56382 if( pBuf==0 ) sz = n = 0;
56383 if( n==0 ) sz = 0;
56389 pcache1.pFree = 0;
56390 AtomicStore(&pcache1.bUnderPressure,0);
56408 if( pcache1.nInitPage==0 ) return 0;
56410 if( pCache->nMax<3 ) return 0;
56412 if( pcache1.nInitPage>0 ){
56430 pX->isAnchor = 0;
56432 pX->pLruPrev = 0; /* Initializing this saves a valgrind error */
56437 return pCache->pFree!=0;
56450 void *p = 0;
56459 assert( pcache1.nFreeSlot>=0 );
56465 if( p==0 ){
56488 if( p==0 ) return;
56505 int nFreed = 0;
56538 PgHdr1 *p = 0;
56542 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
56543 assert( pCache->pFree!=0 );
56546 p->pNext = 0;
56552 assert( pcache1.separateCache==0 );
56562 if( pPg==0 ) return 0;
56567 p->isBulkLocal = 0;
56568 p->isAnchor = 0;
56569 p->pLruPrev = 0; /* Initializing this saves a valgrind error */
56580 assert( p!=0 );
56661 for(i=0; i<p->nHash; i++){
56664 while( (pPage = pNext)!=0 ){
56685 assert( pPage!=0 );
56692 pPage->pLruNext = 0;
56693 /* pPage->pLruPrev = 0;
56694 ** No need to clear pLruPrev as it is never accessed if pLruNext is 0 */
56695 assert( pPage->isAnchor==0 );
56732 && (p=pGroup->lru.pLruPrev)->isAnchor==0
56739 if( pCache->nPage==0 && pCache->pBulk ){
56741 pCache->pBulk = pCache->pFree = 0;
56756 TESTONLY( int nPage = 0; ) /* To assert pCache->nPage is correct */
56760 assert( pCache->nHash > 0 );
56780 while( (pPage = *pp)!=0 ){
56788 TESTONLY( if( nPage>=0 ) nPage++; )
56794 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
56805 assert( pcache1.isInit==0 );
56806 memset(&pcache1, 0, sizeof(pcache1));
56824 pcache1.separateCache = 0;
56826 pcache1.separateCache = sqlite3GlobalConfig.pPage==0
56827 || sqlite3GlobalConfig.bCoreMutex>0;
56829 pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
56839 && sqlite3GlobalConfig.nPage!=0
56840 && sqlite3GlobalConfig.pPage==0
56844 pcache1.nInitPage = 0;
56858 assert( pcache1.isInit!=0 );
56859 memset(&pcache1, 0, sizeof(pcache1));
56875 assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
56888 if( pGroup->lru.isAnchor==0 ){
56896 pCache->bPurgeable = (bPurgeable ? 1 : 0);
56907 if( pCache->nHash==0 ){
56909 pCache = 0;
56923 assert( nMax>=0 );
56928 if( n > 0x7fff0000 - pGroup->nMaxPage + pCache->nMax ){
56929 n = 0x7fff0000 - pGroup->nMaxPage + pCache->nMax;
56952 pGroup->nMaxPage = 0;
56987 PgHdr1 *pPage = 0;
56999 return 0;
57003 assert( pCache->nHash>0 && pCache->apHash );
57013 pcache1RemoveFromHash(pPage, 0);
57018 pPage = 0;
57037 pPage->pLruNext = 0;
57038 /* pPage->pLruPrev = 0;
57039 ** No need to clear pLruPrev since it is not accessed when pLruNext==0 */
57040 *(void **)pPage->page.pExtra = 0;
57055 ** the value of the createFlag argument. 0 means do not allocate a new
57065 ** depending on the value of parameter createFlag (which may be 0, 1 or 2).
57070 ** 2. If createFlag==0 and the page is not already in the cache, NULL is
57114 PgHdr1 *pPage = 0;
57121 ** If the page was not in the hash table and createFlag is 0, abort.
57122 ** Otherwise (page not in hash and createFlag!=0) continue with
57134 return 0;
57148 assert( pPage==0 || pCache->iMaxKey>=iKey );
57162 assert( offsetof(PgHdr1,page)==0 );
57164 assert( pCache->bPurgeable || pCache->nMin==0 );
57165 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
57166 assert( pCache->nMin==0 || pCache->bPurgeable );
57167 assert( pCache->nHash>0 );
57199 assert( pPage->pLruNext==0 );
57235 assert( pcache1FetchNoMutex(p, iOld, 0)==pPage ); /* pPg really is iOld */
57243 assert( pcache1FetchNoMutex(p, iNew, 0)==0 ); /* iNew not in cache */
57280 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
57282 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0);
57303 0, /* pArg */
57343 int nFree = 0;
57346 if( sqlite3GlobalConfig.pPage==0 ){
57349 while( (nReq<0 || nFree<nReq)
57350 && (p=pcache1.grp.lru.pLruPrev)!=0
57351 && p->isAnchor==0
57376 int nRecyclable = 0;
57512 #define ROWSET_SORTED 0x01 /* True if RowSet.pEntry is sorted */
57513 #define ROWSET_NEXT 0x02 /* True if sqlite3RowSetNext() has been called */
57523 p->pChunk = 0;
57525 p->pEntry = 0;
57526 p->pLast = 0;
57527 p->pForest = 0;
57531 p->iBatch = 0;
57548 p->pChunk = 0;
57549 p->nFresh = 0;
57550 p->pEntry = 0;
57551 p->pLast = 0;
57552 p->pForest = 0;
57575 assert( p!=0 );
57576 if( p->nFresh==0 ){ /*OPTIMIZATION-IF-FALSE*/
57581 if( pNew==0 ){
57582 return 0;
57604 assert( p!=0 && (p->rsFlags & ROWSET_NEXT)==0 );
57607 if( pEntry==0 ) return;
57609 pEntry->pRight = 0;
57638 assert( pA!=0 && pB!=0 );
57640 assert( pA->pRight==0 || pA->v<=pA->pRight->v );
57641 assert( pB->pRight==0 || pB->v<=pB->pRight->v );
57645 if( pA==0 ){
57652 if( pB==0 ){
57669 memset(aBucket, 0, sizeof(aBucket));
57672 pIn->pRight = 0;
57673 for(i=0; aBucket[i]; i++){
57675 aBucket[i] = 0;
57680 pIn = aBucket[0];
57681 for(i=1; i<sizeof(aBucket)/sizeof(aBucket[0]); i++){
57682 if( aBucket[i]==0 ) continue;
57699 assert( pIn!=0 );
57712 assert( (*ppLast)->pRight==0 );
57735 if( *ppList==0 ){ /*OPTIMIZATION-IF-TRUE*/
57737 return 0;
57745 if( p==0 ){ /*OPTIMIZATION-IF-FALSE*/
57756 p->pLeft = p->pRight = 0;
57770 assert( pList!=0 );
57773 p->pLeft = p->pRight = 0;
57787 ** 0 if the RowSet is already empty.
57798 assert( p!=0 );
57799 assert( p->pForest==0 ); /* Cannot be used with sqlite3RowSetText() */
57802 if( (p->rsFlags & ROWSET_NEXT)==0 ){ /*OPTIMIZATION-IF-FALSE*/
57803 if( (p->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
57813 if( p->pEntry==0 ){ /*OPTIMIZATION-IF-TRUE*/
57819 return 0;
57825 ** part of any insert batch prior to iBatch. Return 1 or 0.
57835 assert( pRowSet!=0 && (pRowSet->rsFlags & ROWSET_NEXT)==0 );
57844 if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
57850 if( pTree->pLeft==0 ){
57856 pTree->pLeft = 0;
57860 if( pTree==0 ){
57863 pTree->v = 0;
57864 pTree->pRight = 0;
57868 pRowSet->pEntry = 0;
57869 pRowSet->pLast = 0;
57876 ** Return 1 if it does and 0 if not.
57890 return 0;
57943 #define WAL_SYNC_FLAGS(X) ((X)&0x03)
57944 #define CKPT_SYNC_FLAGS(X) (((X)>>2)&0x03)
57947 # define sqlite3WalOpen(x,y,z) 0
57949 # define sqlite3WalClose(v,w,x,y,z) 0
57950 # define sqlite3WalBeginReadTransaction(y,z) 0
57952 # define sqlite3WalDbsize(y) 0
57953 # define sqlite3WalBeginWriteTransaction(y) 0
57954 # define sqlite3WalEndWriteTransaction(x) 0
57955 # define sqlite3WalUndo(x,y,z) 0
57957 # define sqlite3WalSavepointUndo(y,z) 0
57958 # define sqlite3WalFrames(u,v,w,x,y,z) 0
57959 # define sqlite3WalCheckpoint(q,r,s,t,u,v,w,x,y,z) 0
57960 # define sqlite3WalCallback(z) 0
57961 # define sqlite3WalExclusiveMode(y,z) 0
57962 # define sqlite3WalHeapMemory(z) 0
57963 # define sqlite3WalFramesize(z) 0
57964 # define sqlite3WalFindFrame(x,y,z) 0
57965 # define sqlite3WalFile(x) 0
58025 int sync_flags, /* Flags to sync db file with (or 0) */
58035 ** the last call, then return 0.
58173 #if 0
58409 #define PAGER_OPEN 0
58473 #define MAX_SECTOR_SIZE 0x10000
58483 ** set to 0. If a journal-header is written into the main journal while
58505 #define SPILLFLAG_OFF 0x01 /* Never spill cache. Set via pragma */
58506 #define SPILLFLAG_ROLLBACK 0x02 /* Current rolling back, so do not spill */
58507 #define SPILLFLAG_NOSYNC 0x04 /* Spill is ok, but do not sync */
58615 ** Except, any file that is greater than 0 bytes in size is considered
58667 ** syncFlags is either SQLITE_SYNC_NORMAL (0x02) or SQLITE_SYNC_FULL (0x03).
58671 ** file in bits 0x04 and 0x08. In other words, to get the correct sync flags
58672 ** for checkpoint operations, use (walSyncFlags&0x03) and to get the correct
58673 ** sync flags for transaction commit, use ((walSyncFlags>>2)&0x03). Note
58675 ** meaning that the 0x04 and 0x08 bits are both zero.
58771 #define PAGER_STAT_HIT 0
58782 SQLITE_API int sqlite3_pager_readdb_count = 0; /* Number of full pages read from DB */
58783 SQLITE_API int sqlite3_pager_writedb_count = 0; /* Number of full pages written to DB */
58784 SQLITE_API int sqlite3_pager_writej_count = 0; /* Number of pages written to journal */
58796 ** Since version 2.8.0, the journal format contains additional sanity
58816 0xd9, 0xd5, 0x05, 0xf9, 0x20, 0xa1, 0x63, 0xd7,
58838 # define MEMDB 0
58847 #if SQLITE_MAX_MMAP_SIZE>0
58850 # define USEFETCH(x) 0
58864 assert( pPager!=0 );
58865 assert( pPager->fd!=0 );
58866 if( pPager->fd->pMethods==0 ) return 0; /* Case (1) */
58867 if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0; /* Failed (3) */
58870 u32 iRead = 0;
58872 if( iRead ) return 0; /* Case (4) */
58875 assert( pPager->fd->pMethods->xDeviceCharacteristics!=0 );
58877 & SQLITE_IOCAP_SUBPAGE_READ)==0 ){
58878 return 0; /* Case (2) */
58885 # define pagerUseWal(x) ((x)->pWal!=0)
58887 # define pagerUseWal(x) 0
58888 # define pagerRollbackWal(x) 0
58889 # define pagerWalFrames(v,w,x,y) 0
58920 assert( p->tempFile==0 || p->eLock==EXCLUSIVE_LOCK );
58921 assert( p->tempFile==0 || pPager->changeCountDone );
58944 assert( pagerUseWal(p)==0 );
58950 assert( pPager->changeCountDone==0 || pPager->eLock>=RESERVED_LOCK );
58957 assert( sqlite3PcacheRefCount(pPager->pPCache)==0 || pPager->tempFile );
58975 assert( pPager->setSuper==0 );
59027 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 || pPager->tempFile );
59093 #if SQLITE_MAX_MMAP_SIZE>0
59104 #if SQLITE_MAX_MMAP_SIZE>0
59107 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
59127 for(i=0; i<pPager->nSavepoint; i++){
59129 if( p->nOrig>=pgno && 0==sqlite3BitvecTestNotNull(p->pInSavepoint, pgno) ){
59131 pPager->aSavepoint[i].bTruncateOnRelease = 0;
59136 return 0;
59194 assert( eLock!=NO_LOCK || pagerUseWal(pPager)==0 );
59248 ** If neither optimization can be used, 0 is returned.
59264 if( pPager->dbSize>0 && (dc&SQLITE_IOCAP_BATCH_ATOMIC) ){
59276 if( 0==(dc&(SQLITE_IOCAP_ATOMIC|(szPage>>8)) || nSector>szPage) ){
59277 return 0;
59284 return 0;
59297 u32 hash = 0;
59299 for(i=0; i<nByte; i++){
59324 #define pager_datahash(X,Y) 0
59325 #define pager_pagehash(X) 0
59350 ** zSuper[0] is set to 0 and SQLITE_OK returned.
59362 zSuper[0] = '\0';
59369 || len==0
59379 for(u=0; u<len; u++){
59388 len = 0;
59390 zSuper[len] = '\0';
59391 zSuper[len+1] = '\0';
59405 ** 0 0
59412 i64 offset = 0;
59417 assert( offset%JOURNAL_HDR_SZ(pPager)==0 );
59427 ** within the current transaction (i.e. if Pager.journalOff==0).
59430 ** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
59452 if( doTruncate || iLimit==0 ){
59453 rc = sqlite3OsTruncate(pPager->jfd, 0);
59455 static const char zeroHdr[28] = {0};
59456 rc = sqlite3OsWrite(pPager->jfd, zeroHdr, sizeof(zeroHdr), 0);
59468 if( rc==SQLITE_OK && iLimit>0 ){
59511 for(ii=0; ii<pPager->nSavepoint; ii++){
59512 if( pPager->aSavepoint[ii].iHdrOffset==0 ){
59526 ** A faster alternative is to write 0xFFFFFFFF to the nRec field. When
59544 put32bits(&zHeader[sizeof(aJournalMagic)], 0xffffffff);
59546 memset(zHeader, 0, sizeof(aJournalMagic)+4);
59563 ** case the journal file is always 0 bytes in size at this point.
59566 i64 sz = 0;
59568 assert( sz==0 );
59588 memset(&zHeader[sizeof(aJournalMagic)+20], 0,
59608 for(nWrite=0; rc==SQLITE_OK&&nWrite<JOURNAL_HDR_SZ(pPager); nWrite+=nHeader){
59668 if( memcmp(aMagic, aJournalMagic, sizeof(aMagic))!=0 ){
59684 if( pPager->journalOff==0 ){
59699 if( iPageSize==0 ){
59710 || ((iPageSize-1)&iPageSize)!=0 || ((iSectorSize-1)&iSectorSize)!=0
59765 u32 cksum = 0; /* Checksum of string zSuper */
59767 assert( pPager->setSuper==0 );
59780 for(nSuper=0; zSuper[nSuper]; nSuper++){
59796 if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_SJ_PGNO(pPager))))
59797 || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4)))
59798 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper)))
59799 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum)))
59800 || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8,
59848 for(ii=0; ii<pPager->nSavepoint; ii++){
59855 pPager->aSavepoint = 0;
59856 pPager->nSavepoint = 0;
59857 pPager->nSubRec = 0;
59869 for(ii=0; ii<pPager->nSavepoint; ii++){
59905 pPager->pInJournal = 0;
59923 int iDc = isOpen(pPager->fd)?sqlite3OsDeviceCharacteristics(pPager->fd):0;
59936 if( 0==(iDc & SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN)
59967 if( pPager->tempFile==0 ){
59969 pPager->changeCountDone = 0;
59974 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
59979 pPager->journalOff = 0;
59980 pPager->journalHdr = 0;
59981 pPager->setSuper = 0;
60004 int rc2 = rc & 0xff;
60009 (pPager->errCode & 0xff)==SQLITE_IOERR
60023 ** or rolled back (bCommit==0).
60038 if( pPager->tempFile==0 ) return 1;
60039 if( !bCommit ) return 0;
60040 if( !isOpen(pPager->fd) ) return 0;
60121 assert( isOpen(pPager->jfd) || pPager->pInJournal==0
60132 if( pPager->journalOff==0 ){
60135 rc = sqlite3OsTruncate(pPager->jfd, 0);
60145 pPager->journalOff = 0;
60150 pPager->journalOff = 0;
60158 assert( sqlite3JournalIsInMemory(pPager->jfd)==0 );
60172 if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){
60175 p->pageHash = 0;
60182 pPager->pInJournal = 0;
60183 pPager->nRec = 0;
60212 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_COMMIT_PHASETWO, 0);
60217 && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
60222 pPager->setSuper = 0;
60256 pager_end_transaction(pPager, 0, 0);
60299 while( i>0 ){
60308 ** from the sub-journal (if isMainJrnl==0) and playback that page.
60333 ** * If the record page-number is illegal (0 or PAGER_SJ_PGNO), or
60347 int isMainJrnl, /* 1 -> main journal. 0 -> sub-journal. */
60358 assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */
60359 assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */
60361 assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */
60365 assert( pagerUseWal(pPager)==0 || (!isMainJrnl && isSavepnt) );
60393 if( pgno==0 || pgno==PAGER_SJ_PGNO(pPager) ){
60450 ** the page is marked as needSync==0.
60457 pPg = 0;
60462 assert( pPager->eState!=PAGER_OPEN || pPg==0 || pPager->tempFile );
60470 isSynced = (pPg==0 || 0==(pPg->flags & PGHDR_NEED_SYNC));
60477 testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
60494 }else if( !isMainJrnl && pPg==0 ){
60512 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)==0 );
60515 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 );
60559 ** nul-terminator byte (0x00). i.e. the entire contents of a super-journal
60595 char *zSuperJournal = 0; /* Contents of super-journal file */
60599 char *zFree = 0; /* Free this buffer */
60608 pJournal = 0;
60611 rc = sqlite3OsOpen(pVfs, zSuper, pSuper, flags, 0);
60624 assert( nSuperJournal>=0 && nSuperPtr>0 );
60630 assert( nSuperJournal<=0x7fffffff );
60632 zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0;
60635 rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
60637 zSuperJournal[nSuperJournal] = 0;
60638 zSuperJournal[nSuperJournal+1] = 0;
60657 rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
60668 c = zSuperPtr[0]!=0 && strcmp(zSuperPtr, zSuper)==0;
60678 rc = sqlite3OsDelete(pVfs, zSuper, 0);
60732 memset(pTmp, 0, szPage);
60789 SQLITE_IOCAP_POWERSAFE_OVERWRITE)!=0
60808 ** in the journal. If this value is 0xffffffff, then compute the
60835 ** If the nRec value is 0xffffffff it means that nRec should be computed
60862 Pgno mxPg = 0; /* Size of the original file in pages */
60865 char *zSuper = 0; /* Name of super-journal file if any */
60867 int nPlayback = 0; /* Total number of pages restored from journal */
60892 if( rc==SQLITE_OK && zSuper[0] ){
60895 zSuper = 0;
60899 pPager->journalOff = 0;
60920 /* If nRec is 0xffffffff, then this journal was created by a process
60925 if( nRec==0xffffffff ){
60930 /* If nRec is 0 and this rollback is of a transaction created by this
60937 ** When rolling back a hot journal, nRec==0 always means that the next
60939 ** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
60944 if( nRec==0 && !isHot &&
60966 for(u=0; u<nRec; u++){
60969 needPagerReset = 0;
60971 rc = pager_playback_one_page(pPager,&pPager->journalOff,0,1,0);
60998 assert( 0 );
61010 sqlite3OsFileControlHint(pPager->fd,SQLITE_FCNTL_DB_UNCHANGED,0);
61027 ** which case it requires 4 0x00 bytes in memory immediately before
61036 rc = sqlite3PagerSync(pPager, 0);
61039 rc = pager_end_transaction(pPager, zSuper[0]!='\0', 0);
61042 if( rc==SQLITE_OK && zSuper[0] && res ){
61047 memset(pPager->pTmpSpace, 0, 4);
61082 u32 iFrame = 0; /* Frame of WAL containing pgno */
61109 ** should be page numbers which are never 0xffffffff. So filling
61110 ** pPager->dbFileVers[] with all 0xff bytes should suffice.
61114 ** white noise equaling 16 bytes of 0xff is vanishingly small so
61117 memset(pPager->dbFileVers, 0xff, sizeof(pPager->dbFileVers));
61142 if( NEVER(pPg==0) ) return;
61211 ** + Discard the cached page (if refcount==0), or
61212 ** + Reload page content from the database (if refcount>0).
61254 assert( pList->pDirty==0 || isCommit );
61261 nList = 0;
61262 for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
61304 int changed = 0; /* True if cache must be reset */
61319 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
61339 ** function returns zero if the WAL is not open (i.e. Pager.pWal==0), or
61347 assert( pPager->tempFile==0 );
61355 if( nPage==0 && ALWAYS(isOpen(pPager->fd)) ){
61356 i64 n = 0; /* Size of db file in bytes */
61411 if( nPage==0 ){
61412 rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0);
61414 testcase( sqlite3PcachePagecount(pPager->pPCache)==0 );
61415 rc = sqlite3PagerOpenWal(pPager, 0);
61466 Bitvec *pDone = 0; /* Bitvec to ensure pages played back only once */
61495 assert( pagerUseWal(pPager)==0 || szJ==0 );
61512 pPager->journalOff = 0;
61522 u32 nJRec = 0; /* Number of Journal Records */
61524 rc = readJournalHdr(pPager, 0, szJ, &nJRec, &dummy);
61532 if( nJRec==0
61537 for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
61557 rc = pager_playback_one_page(pPager, &offset, pDone, 0, 1);
61590 #if SQLITE_MAX_MMAP_SIZE>0
61595 pPager->bUseFetch = (sz>0);
61675 pPager->fullSync = 0;
61676 pPager->extraSync = 0;
61678 pPager->noSync = level==PAGER_SYNCHRONOUS_OFF ?1:0;
61679 pPager->fullSync = level>=PAGER_SYNCHRONOUS_FULL ?1:0;
61680 pPager->extraSync = level==PAGER_SYNCHRONOUS_EXTRA ?1:0;
61683 pPager->syncFlags = 0;
61709 SQLITE_API int sqlite3_opentemp_count = 0;
61740 rc = sqlite3OsOpen(pPager->pVfs, 0, pFile, vfsFlags, 0);
61775 assert( ((int(*)(void *))(ap[0]))==xBusyHandler );
61824 assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) );
61825 if( (pPager->memDb==0 || pPager->dbSize==0)
61826 && sqlite3PcacheRefCount(pPager->pPCache)==0
61830 i64 nByte = 0;
61842 memset(pNew+pageSize, 0, 8);
61863 if( nReserve<0 ) nReserve = pPager->nReserve;
61864 assert( nReserve>=0 && nReserve<1000 );
61891 if( mxPage>0 ){
61942 memset(pDest, 0, N);
61952 IOTRACE(("DBHDR %p 0 %d\n", pPager, N))
61953 rc = sqlite3OsRead(pPager->fd, pDest, N, 0);
62036 for(i=0; i<pPg->pPager->nSavepoint; i++){
62071 ** Pager object may still have open savepoints (Pager.nSavepoint!=0),
62102 #if SQLITE_MAX_MMAP_SIZE>0
62124 p->pDirty = 0;
62126 memset(p->pExtra, 0, 8);
62129 if( p==0 ){
62141 assert( p->pPage==0 );
62186 int bHasMoved = 0;
62190 if( pPager->dbSize==0 ) return SQLITE_OK;
62191 assert( pPager->zFilename && pPager->zFilename[0] );
62221 assert( db || pagerUseWal(pPager)==0 );
62226 /* pPager->errCode = 0; */
62227 pPager->exclusiveMode = 0;
62230 u8 *a = 0;
62231 assert( db || pPager->pWal==0 );
62232 if( db && 0==(db->flags & SQLITE_NoCkptOnClose)
62238 pPager->pWal = 0;
62345 if( 0==(iDc&SQLITE_IOCAP_SAFE_APPEND) ){
62360 ** a valid header following Pager.journalOff, then write a 0x00
62377 if( rc==SQLITE_OK && 0==memcmp(aMagic, aJournalMagic, 8) ){
62378 static const u8 zerobyte = 0;
62393 ** is populated with 0xFFFFFFFF when the journal header is written
62396 if( pPager->fullSync && 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
62408 if( 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
62412 (pPager->syncFlags==SQLITE_SYNC_FULL?SQLITE_SYNC_DATAONLY:0)
62418 if( newHdr && 0==(iDc&SQLITE_IOCAP_SAFE_APPEND) ){
62419 pPager->nRec = 0;
62477 assert( isOpen(pPager->fd) || pList->pDirty==0 );
62512 if( pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
62516 assert( (pList->flags&PGHDR_NEED_SYNC)==0 );
62571 rc = sqlite3JournalOpen(pPager->pVfs, 0, pPager->sjfd, flags, nStmtSpill);
62595 assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 );
62618 assert( pPager->nSavepoint>0 );
62678 && ((pPager->doNotSpill & (SPILLFLAG_ROLLBACK|SPILLFLAG_OFF))!=0
62679 || (pPg->flags & PGHDR_NEED_SYNC)!=0)
62685 pPg->pDirty = 0;
62690 rc = pagerWalFrames(pPager, pPg, 0, 0);
62695 if( pPager->tempFile==0 ){
62710 assert( (pPg->flags&PGHDR_NEED_SYNC)==0 );
62734 if( pList->nRef==0 ){
62786 Pager *pPager = 0; /* Pager object to allocate and return */
62788 int tempFile = 0; /* True for temp files (incl. in-memory files) */
62789 int memDb = 0; /* True if this is an in-memory file */
62790 int memJM = 0; /* Memory journal mode */
62791 int readOnly = 0; /* True if this is a read-only file */
62793 char *zPathname = 0; /* Full path to database file */
62794 int nPathname = 0; /* Number of bytes in zPathname */
62795 int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
62798 const char *zUri = 0; /* URI args to copy */
62807 *ppPager = 0;
62812 if( zFilename && zFilename[0] ){
62813 zPathname = sqlite3DbStrDup(0, zFilename);
62814 if( zPathname==0 ) return SQLITE_NOMEM_BKPT;
62816 zFilename = 0;
62823 ** leave both nPathname and zPathname set to 0.
62825 if( zFilename && zFilename[0] ){
62828 zPathname = sqlite3DbMallocRaw(0, 2*(i64)nPathname);
62829 if( zPathname==0 ){
62832 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
62861 sqlite3DbFree(0, zPathname);
62876 ** \0\0\0\0 database prefix (4 bytes)
62881 ** \0\0\0 terminator (3 bytes)
62884 ** the specific order of the filenames and the \0 separators between them
62893 ** - \0
62896 ** - \0
62898 ** - \0
62899 ** - \0
62901 ** - \0
62903 ** - \0
62928 sqlite3DbFree(0, zPathname);
62942 if( nPathname>0 ){
62953 if( nPathname>0 ){
62962 pPager->zJournal = 0;
62967 if( nPathname>0 ){
62976 pPager->zWal = 0;
62981 if( nPathname ) sqlite3DbFree(0, zPathname);
62987 if( zFilename && zFilename[0] ){
62988 int fout = 0; /* VFS flags returned by xOpen() */
62991 pPager->memVfs = memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
62992 readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
63028 pPager->noLock = sqlite3_uri_boolean(pPager->zFilename, "nolock", 0);
63029 if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
63030 || sqlite3_uri_boolean(pPager->zFilename, "immutable", 0) ){
63058 assert( pPager->memDb==0 );
63068 !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
63084 /* pPager->stmtOpen = 0; */
63085 /* pPager->stmtInUse = 0; */
63086 /* pPager->nRef = 0; */
63087 /* pPager->stmtSize = 0; */
63088 /* pPager->stmtJSize = 0; */
63089 /* pPager->nPage = 0; */
63092 /* pPager->errMask = 0; */
63103 /* pPager->pFirst = 0; */
63104 /* pPager->pFirstSynced = 0; */
63105 /* pPager->pLast = 0; */
63115 /* pPager->xBusyHandler = 0; */
63116 /* pPager->pBusyHandlerArg = 0; */
63119 /* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
63134 while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){
63153 ** * The database file itself is greater than 0 bytes in size, and
63154 ** * The first byte of the journal file exists and is not 0x00.
63156 ** If the current size of the database file is 0 but a journal file
63159 ** just deleted using OsDelete, *pExists is set to 0 and SQLITE_OK
63171 ** set to 0 and SQLITE_OK returned. If an IO error occurs while trying
63185 assert( jrnlOpen==0 || ( sqlite3OsDeviceCharacteristics(pPager->jfd) &
63189 *pExists = 0;
63194 int locked = 0; /* True if some process holds a RESERVED lock */
63208 assert( pPager->tempFile==0 );
63219 if( nPage==0 && !jrnlOpen ){
63222 sqlite3OsDelete(pVfs, pPager->zJournal, 0);
63238 u8 first = 0;
63239 rc = sqlite3OsRead(pPager->jfd, (void *)&first, 1, 0);
63246 *pExists = (first!=0);
63302 assert( sqlite3PcacheRefCount(pPager->pPCache)==0 );
63311 assert( pPager->tempFile==0 || pPager->eLock==EXCLUSIVE_LOCK );
63373 int fout = 0;
63456 memset(dbFileVers, 0, sizeof(dbFileVers));
63459 if( memcmp(pPager->dbFileVers, dbFileVers, sizeof(dbFileVers))!=0 ){
63469 sqlite3OsUnfetch(pPager->fd, 0, 0);
63479 assert( pPager->pWal==0 || rc==SQLITE_OK );
63488 if( pPager->tempFile==0 && pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){
63513 if( sqlite3PcacheRefCount(pPager->pPCache)==0 ){
63514 assert( pPager->nMmapOut==0 ); /* because page1 is never memory mapped */
63571 ** just returns 0. This routine acquires a read-lock the first time it
63592 if( pgno==0 ) return SQLITE_CORRUPT_BKPT;
63594 if( pBase==0 ){
63595 pPg = 0;
63598 if( pBase==0 ){
63606 assert( pPg->pPager==pPager || pPg->pPager==0 );
63608 noContent = (flags & PAGER_GET_NOCONTENT)!=0;
63636 pPg = 0;
63656 memset(pPg->pData, 0, pPager->pageSize);
63676 *ppPage = 0;
63680 #if SQLITE_MAX_MMAP_SIZE>0
63689 PgHdr *pPg = 0;
63690 u32 iFrame = 0; /* Frame to read from WAL file */
63702 /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here
63704 ** test in the previous statement, and avoid testing pgno==0 in the
63706 if( pgno<=1 && pgno==0 ){
63717 *ppPage = 0;
63721 if( bMmapOk && iFrame==0 ){
63722 void *pData = 0;
63730 if( pPg==0 ){
63742 *ppPage = 0;
63748 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
63760 *ppPage = 0;
63773 #if 0 /* Trace page fetch by setting to 1 */
63779 printf("PAGE %u failed with 0x%02x\n", pgno, rc);
63792 ** or 0 if the page is not in cache.
63802 assert( pPager!=0 );
63803 assert( pgno!=0 );
63804 assert( pPager->pPCache!=0 );
63805 pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
63806 assert( pPage==0 || pPager->hasHeldSharedLock );
63807 if( pPage==0 ) return 0;
63827 assert( pPg!=0 );
63835 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 ); /* tag-20230419-2 */
63842 assert( pPg!=0 );
63844 assert( (pPg->flags & PGHDR_MMAP)==0 ); /* Page1 is never memory mapped */
63878 assert( pPager->pInJournal==0 );
63887 if( pPager->pInJournal==0 ){
63926 pPager->nRec = 0;
63927 pPager->journalOff = 0;
63928 pPager->setSuper = 0;
63929 pPager->journalHdr = 0;
63936 pPager->pInJournal = 0;
63937 pPager->journalOff = 0;
63971 assert( pPager->pInJournal==0 );
64017 pPager->journalOff = 0;
64069 ((pPg->flags&PGHDR_NEED_SYNC)?1:0), pager_pagehash(pPg)));
64073 assert( pPager->pInJournal!=0 );
64102 assert( pPager->errCode==0 );
64103 assert( pPager->readOnly==0 );
64129 assert( (pPager->pInJournal!=0) == isOpen(pPager->jfd) );
64130 if( pPager->pInJournal!=0
64131 && sqlite3BitvecTestNotNull(pPager->pInJournal, pPg->pgno)==0
64133 assert( pagerUseWal(pPager)==0 );
64145 ((pPg->flags&PGHDR_NEED_SYNC)?1:0)));
64159 if( pPager->nSavepoint>0 ){
64185 int nPage = 0; /* Number of pages starting at pg1 to journal */
64187 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
64196 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)==0 );
64213 assert(nPage>0);
64217 for(ii=0; ii<nPage && rc==SQLITE_OK; ii++){
64222 rc = sqlite3PagerGet(pPager, pg, &pPage, 0);
64231 }else if( (pPage = sqlite3PagerLookup(pPager, pg))!=0 ){
64247 for(ii=0; ii<nPage; ii++){
64256 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
64277 assert( (pPg->flags & PGHDR_MMAP)==0 );
64280 if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
64286 assert( pPager->tempFile==0 );
64326 if( !pPager->tempFile && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
64377 # define DIRECT_MODE 0
64378 assert( isDirectMode==0 );
64384 if( !pPager->changeCountDone && pPager->dbSize>0 ){
64390 rc = sqlite3PagerGet(pPager, 1, &pPgHdr, 0);
64391 assert( pPgHdr==0 || rc==SQLITE_OK );
64409 assert( pPager->dbFileSize>0 );
64412 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
64473 if( 0==pagerUseWal(pPager) ){
64532 assert( MEMDB==0 || pPager->tempFile );
64534 if( 0==pagerFlushOnCommit(pPager, 1) ){
64542 PgHdr *pPageOne = 0;
64544 if( pList==0 ){
64547 rc = sqlite3PagerGet(pPager, 1, &pPageOne, 0);
64549 pList->pDirty = 0;
64566 int bBatch = zSuper==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
64571 # define bBatch 0
64598 if( bBatch==0 ){
64607 && (!(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
64619 rc = pager_incr_changecounter(pPager, 0);
64628 assert( bBatch==0 );
64631 rc = pager_incr_changecounter(pPager, 0);
64653 rc = syncJournal(pPager, 0);
64659 rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, 0);
64665 memset(pTmp, 0, szPage);
64670 rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, 0);
64673 sqlite3OsFileControlHint(fd, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 0);
64677 if( (rc&0xFF)==SQLITE_IOERR && rc!=SQLITE_IOERR_NOMEM ){
64683 bBatch = 0;
64690 if( bBatch==0 ){
64763 ** header with the nRec field set to 0. If such a journal is used as
64764 ** a hot-journal during hot-journal rollback, 0 changes will be made
64824 rc2 = pager_end_transaction(pPager, pPager->setSuper, 0);
64828 rc = pager_end_transaction(pPager, 0, 0);
64840 rc = pager_playback(pPager, 0);
64845 || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR
64897 a[0] = sqlite3PcacheRefCount(pPager->pPCache);
64903 a[6] = (int)pPager->aStat[PAGER_STAT_HIT] & 0x7fffffff;
64904 a[7] = (int)pPager->aStat[PAGER_STAT_MISS] & 0x7fffffff;
64905 a[8] = 0; /* Used to be pPager->nOvfl */
64907 a[10] = (int)pPager->aStat[PAGER_STAT_WRITE] & 0x7fffffff;
64933 assert( PAGER_STAT_HIT==0 && PAGER_STAT_MISS==1
64939 pPager->aStat[eStat] = 0;
64980 memset(&aNew[nCurrent], 0, (nSavepoint-nCurrent) * sizeof(PagerSavepoint));
64986 if( isOpen(pPager->jfd) && pPager->journalOff>0 ){
65029 ** iSavepoint. A value of 0 means to operate on the outermost savepoint
65056 assert( iSavepoint>=0 || op==SAVEPOINT_ROLLBACK );
65066 nNew = iSavepoint + (( op==SAVEPOINT_RELEASE ) ? 0 : 1);
65092 PagerSavepoint *pSavepoint = (nNew==0)?0:&pPager->aSavepoint[nNew-1];
65123 ** shared cache, it uses nullIfMemDb==0 so that in-memory databases can
65130 static const char zFake[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
65201 Pgno needSyncPgno = 0; /* Old value of pPg->pgno, if sync is required */
65205 assert( pPg->nRef>0 );
65238 if( (pPg->flags & PGHDR_DIRTY)!=0
65245 PAGERID(pPager), pPg->pgno, (pPg->flags&PGHDR_NEED_SYNC)?1:0, pgno));
65314 rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr, 0);
65317 assert( pPager->pTmpSpace!=0 );
65347 assert( pPg->nRef>0 || pPg->pPager->memDb );
65373 assert( PAGER_LOCKINGMODE_QUERY<0 );
65374 assert( PAGER_LOCKINGMODE_NORMAL>=0 && PAGER_LOCKINGMODE_EXCLUSIVE>=0 );
65375 assert( pPager->exclusiveMode || 0==sqlite3WalHeapMemory(pPager->pWal) );
65376 if( eMode>=0 && !pPager->tempFile && !sqlite3WalHeapMemory(pPager->pWal) ){
65406 assert( eMode==PAGER_JOURNALMODE_DELETE /* 0 */
65417 assert( pPager->tempFile==0 || eMode!=PAGER_JOURNALMODE_WAL );
65441 assert( (PAGER_JOURNALMODE_DELETE & 5)==0 );
65443 assert( (PAGER_JOURNALMODE_OFF & 5)==0 );
65447 if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){
65458 sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
65471 sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
65503 if( pPager->eState>=PAGER_WRITER_CACHEMOD ) return 0;
65504 if( NEVER(isOpen(pPager->jfd) && pPager->journalOff>0) ) return 0;
65537 assert( MEMDB==0 || pPager->tempFile );
65538 if( pPager->tempFile==0 ) pager_reset(pPager);
65559 if( pPager->pWal==0 && pPager->journalMode==PAGER_JOURNALMODE_WAL ){
65569 sqlite3_exec(db, "PRAGMA table_list",0,0,0);
65573 (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
65592 if( pPager->noLock ) return 0;
65625 assert( pPager->pWal==0 && pPager->tempFile==0 );
65681 assert( pbOpen==0 || *pbOpen==0 );
65682 assert( pbOpen!=0 || (!pPager->tempFile && !pPager->pWal) );
65721 int logexists = 0;
65741 pPager->pWal = 0;
65758 if( pagerUseWal(pPager) && pPager->exclusiveMode==0 ){
65861 ** is empty, return 0.
65915 ** 0: Magic number. 0x377f0682 or 0x377f0683
65929 ** 0: Page number.
65949 ** magic number in the first 4 bytes of the WAL is 0x377f0683 and it
65950 ** is computed using little-endian if the magic number is 0x377f0682.
65954 ** an even number of unsigned 32-bit integers: x[0] through x[N]. The
65957 ** for i from 0 to n-1 step 2:
66080 ** contain a value of 0.
66136 SQLITE_PRIVATE int sqlite3WalTrace = 0;
66172 #define WAL_WRITE_LOCK 0
66191 ** For all versions of SQLite through 3.10.0 and probably beyond,
66238 ** the mxFrame for that reader. The value READMARK_NOT_USED (0xffffffff)
66239 ** for any aReadMark[] means that entry is unused. aReadMark[0] is
66242 ** WAL_READ_LOCK(0) always ignore the entire WAL and read all content
66258 ** will choose aReadMark[0] which has value 0 and hence such reader will
66265 ** (in other words, if there are no WAL_READ_LOCK(i) where i>0) then
66279 #define READMARK_NOT_USED 0xffffffff
66286 ** 0: | iVersion | \
66361 ** significant bit also set (WAL_MAGIC | 0x00000001) is stored in 32-bit
66369 #define WAL_MAGIC 0x377f0682
66393 u32 iCallback; /* Value to pass to log callback (or 0) */
66437 #define WAL_NORMAL_MODE 0
66444 #define WAL_RDWR 0 /* Normal read/write connection */
66477 int iZero; /* Frame number associated with aPgno[0] */
66525 assert( walAssertLockmask(pWal) && pWal->nSehTry==0 ); \
66531 assert( pWal->nSehTry==0 ); \
66548 ** ExceptionInformation[] array is a read-write flag - 0 if the exception
66567 assert( pWal->nSehTry>0 );
66570 if( res!=0 ){
66572 aArg[0] = 0;
66573 aArg[1] = 0;
66575 RaiseException(EXCEPTION_IN_PAGE_ERROR, 0, 3, (const ULONG_PTR*)aArg);
66583 ** SEH_FREE_ON_ERROR(0, pPtr);
66587 ** SEH_FREE_ON_ERROR(pPtr, 0);
66593 assert( (X==0 || Y==0) && pWal->pFree==X ); pWal->pFree = Y
66603 ** SEH_SET_ON_ERROR(0, 0);
66609 # define SEH_EXCEPT(X) VVA_ONLY(pWal->nSehTry--); assert( pWal->nSehTry==0 );
66610 # define SEH_INJECT_FAULT assert( pWal->nSehTry>0 );
66630 ** (3) rc==SQLITE_OK and *ppPage==NULL // only if iPage==0
66632 ** Scenario (3) can only occur when pWal->writeLock is false and iPage==0
66647 *ppPage = 0;
66650 memset((void*)&apNew[pWal->nWiData], 0,
66657 assert( pWal->apWiData[iPage]==0 );
66665 assert( pWal->apWiData[iPage]!=0
66667 || (pWal->writeLock==0 && iPage==0) );
66668 testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK );
66670 if( iPage>0 && sqlite3FaultSim(600) ) rc = SQLITE_NOMEM;
66671 }else if( (rc&0xff)==SQLITE_READONLY ){
66680 assert( iPage==0 || *ppPage || rc!=SQLITE_OK );
66689 if( pWal->nWiData<=iPage || (*ppPage = pWal->apWiData[iPage])==0 ){
66699 assert( pWal->nWiData>0 && pWal->apWiData[0] );
66701 return (volatile WalCkptInfo*)&(pWal->apWiData[0][sizeof(WalIndexHdr)/2]);
66708 assert( pWal->nWiData>0 && pWal->apWiData[0] );
66710 return (volatile WalIndexHdr*)pWal->apWiData[0];
66721 (((x)&0x000000FF)<<24) + (((x)&0x0000FF00)<<8) \
66722 + (((x)&0x00FF0000)>>8) + (((x)&0xFF000000)>>24) \
66727 ** array aByte[] and the initial values of aIn[0] and aIn[1] (or
66728 ** initial values of 0 and 0 if aIn==NULL).
66746 s1 = aIn[0];
66749 s1 = s2 = 0;
66753 assert( nByte>=8 && (nByte&7)==0 && nByte<=65536 );
66757 s1 += BYTESWAP32(aData[0]) + s2;
66761 }else if( nByte%64==0 ){
66788 aOut[0] = s1;
66827 walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum);
66831 memcpy((void*)&aHdr[0], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
66839 ** 0: Page number.
66850 u32 nTruncate, /* New db size (or 0 for non-commit frames) */
66857 sqlite3Put4byte(&aFrame[0], iPage);
66859 if( pWal->iReCksum==0 ){
66866 sqlite3Put4byte(&aFrame[16], aCksum[0]);
66869 memset(&aFrame[8], 0, 16);
66881 u32 *pnTruncate, /* OUT: New db size (or 0 if not commit) */
66893 if( memcmp(&pWal->hdr.aSalt, &aFrame[8], 8)!=0 ){
66894 return 0;
66899 pgno = sqlite3Get4byte(&aFrame[0]);
66900 if( pgno==0 ){
66901 return 0;
66912 if( aCksum[0]!=sqlite3Get4byte(&aFrame[16])
66916 return 0;
66943 lockIdx-WAL_READ_LOCK(0));
66964 VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && (rc&0xFF)!=SQLITE_BUSY); )
66986 VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && (rc&0xFF)!=SQLITE_BUSY); )
67007 ** between 0 and (HASHTABLE_NSLOT-1). The walHashNext() function advances
67011 assert( iPage>0 );
67012 assert( (HASHTABLE_NSLOT & (HASHTABLE_NSLOT-1))==0 );
67034 ** numbered starting from 0.
67042 ** Finally, set pLoc->aPgno so that pLoc->aPgno[0] is the page number of the
67053 assert( rc==SQLITE_OK || iHash>0 );
67057 if( iHash==0 ){
67059 pLoc->iZero = 0;
67073 ** are numbered starting from 0.
67077 assert( (iHash==0 || iFrame>HASHTABLE_NPAGE_ONE)
67083 assert( iHash>=0 );
67093 if( iHash==0 ){
67094 return pWal->apWiData[0][WALINDEX_HDR_SIZE/sizeof(u32) + iFrame - 1];
67113 int iLimit = 0; /* Zero values greater than this */
67122 if( pWal->hdr.mxFrame==0 ) return;
67137 assert( iLimit>0 );
67138 for(i=0; i<HASHTABLE_NSLOT; i++){
67140 sLoc.aHash[i] = 0;
67148 assert( nByte>=0 );
67149 memset((void *)&sLoc.aPgno[iLimit], 0, nByte);
67158 for(j=0; j<iLimit; j++){
67195 assert( nByte>=0 );
67196 memset((void*)sLoc.aPgno, 0, nByte);
67213 if( (nCollide--)==0 ) return SQLITE_CORRUPT_BKPT;
67224 int nEntry = 0; /* Number of entries in the hash table */
67225 for(i=0; i<HASHTABLE_NSLOT; i++){ if( sLoc.aHash[i] ) nEntry++; }
67234 if( (idx&0x3ff)==0 ){
67236 for(i=0; i<idx; i++){
67265 u32 aFrameCksum[2] = {0, 0};
67274 assert( pWal->ckptLock==1 || pWal->ckptLock==0 );
67279 rc = walLockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
67286 memset(&pWal->hdr, 0, sizeof(WalIndexHdr));
67295 u32 *aPrivate = 0; /* Heap copy of *-shm hash being populated */
67296 u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */
67307 rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0);
67317 magic = sqlite3Get4byte(&aBuf[0]);
67319 if( (magic&0xFFFFFFFE)!=WAL_MAGIC
67326 pWal->hdr.bigEndCksum = (u8)(magic&0x00000001);
67333 aBuf, WAL_HDRSIZE-2*4, 0, pWal->hdr.aFrameCksum
67335 if( pWal->hdr.aFrameCksum[0]!=sqlite3Get4byte(&aBuf[24])
67352 SEH_FREE_ON_ERROR(0, aFrame);
67362 for(iPg=0; iPg<=(u32)walFramePage(iLastFrame); iPg++){
67366 u32 iFirst = 1 + (iPg==0?0:HASHTABLE_NPAGE_ONE+(iPg-1)*HASHTABLE_NPAGE);
67369 assert( aShare!=0 || rc!=SQLITE_OK );
67370 if( aShare==0 ) break;
67391 pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16));
67394 aFrameCksum[0] = pWal->hdr.aFrameCksum[0];
67399 SEH_SET_ON_ERROR(0,0);
67400 nHdr = (iPg==0 ? WALINDEX_HDR_SIZE : 0);
67434 SEH_FREE_ON_ERROR(aFrame, 0);
67442 pWal->hdr.aFrameCksum[0] = aFrameCksum[0];
67451 pInfo->nBackfill = 0;
67453 pInfo->aReadMark[0] = 0;
67484 walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
67494 for(i=0; i<pWal->nWiData; i++){
67496 pWal->apWiData[i] = 0;
67531 assert( zWalName && zWalName[0] );
67559 assert( 123 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(0) );
67580 *ppWal = 0;
67604 walIndexClose(pRet, 0);
67609 if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; }
67611 pRet->padToSectorBoundary = 0;
67633 ** Return 0 on success. If there are no pages in the WAL with a page
67642 u32 iRet = 0xFFFFFFFF; /* 0xffffffff is never a valid page number */
67646 assert( iMin<0xffffffff );
67647 for(i=p->nSegment-1; i>=0; i--){
67663 return (iRet==0xFFFFFFFF);
67697 int iLeft = 0; /* Current index in aLeft */
67698 int iRight = 0; /* Current index in aRight */
67699 int iOut = 0; /* Current index in output buffer */
67703 assert( nLeft>0 && nRight>0 );
67726 memcpy(aLeft, aTmp, sizeof(aTmp[0])*iOut);
67758 int nMerge = 0; /* Number of elements in list aMerge */
67759 ht_slot *aMerge = 0; /* List to be merged */
67761 u32 iSub = 0; /* Index into aSub array */
67764 memset(aSub, 0, sizeof(aSub));
67765 assert( nList<=HASHTABLE_NPAGE && nList>0 );
67768 for(iList=0; iList<nList; iList++){
67771 for(iSub=0; iList & (1<<iSub); iSub++){
67836 ** it only runs if there is actually content in the log (mxFrame>0).
67838 assert( pWal->ckptLock && pWal->hdr.mxFrame>0 );
67851 memset(p, 0, nByte);
67854 SEH_FREE_ON_ERROR(0, p);
67872 for(j=0; j<nEntry; j++){
67883 SEH_FREE_ON_ERROR(p, 0);
67885 p = 0;
67896 ** blocking locks are successfully enabled, or 0 otherwise.
67909 ** or 0 otherwise.
67912 int res = 0;
67926 int tmout = 0;
67941 assert( pWal->readLock<0 || bLock==0 );
67953 pWal->writeLock = 0;
67966 # define walEnableBlocking(x) 0
67968 # define walEnableBlockingMs(pWal, ms) 0
67977 ** lock is successfully obtained or the busy-handler returns 0.
68004 return (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
68029 pWal->hdr.mxFrame = 0;
68030 sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
68033 AtomicStore(&pInfo->nBackfill, 0);
68034 pInfo->nBackfillAttempted = 0;
68035 pInfo->aReadMark[1] = 0;
68037 assert( pInfo->aReadMark[0]==0 );
68077 int sync_flags, /* Flags for OsSync() (or 0) */
68082 WalIterator *pIter = 0; /* Wal iterator context */
68083 u32 iDbpage = 0; /* Next database page to write */
68084 u32 iFrame = 0; /* Wal frame containing data for iDbpage */
68098 assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
68118 xBusy = 0;
68128 assert( rc==SQLITE_OK || pIter==0 );
68132 && (rc = walBusyLock(pWal,xBusy,pBusyArg,WAL_READ_LOCK(0),1))==SQLITE_OK
68146 sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_START, 0);
68163 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
68183 sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_DONE, 0);
68201 walUnlockExclusive(pWal, WAL_READ_LOCK(0), 1);
68242 rc = sqlite3OsTruncate(pWal->pWalFd, 0);
68250 SEH_FREE_ON_ERROR(pIter, 0);
68296 if( pWal->exclusiveMode==0 ){
68301 if( pWal->writeLock==2 ) pWal->writeLock = 0;
68303 (pWal->readLock<0 ? 0 : (S << WAL_READ_LOCK(pWal->readLock)))
68304 | (pWal->writeLock ? (E << WAL_WRITE_LOCK) : 0)
68305 | (pWal->ckptLock ? (E << WAL_CKPT_LOCK) : 0)
68307 for(ii=0; ii<SQLITE_SHM_NLOCK; ii++){
68313 pWal->pFree = 0;
68316 pWal->pWiValue = 0;
68329 if( pWal->exclusiveMode==0 ){
68333 (pWal->readLock<0 ? 0 : (S << WAL_READ_LOCK(pWal->readLock)))
68334 | (pWal->writeLock ? (E << WAL_WRITE_LOCK) : 0)
68335 | (pWal->ckptLock ? (E << WAL_CKPT_LOCK) : 0)
68337 | (pWal->pSnapshot ? (pWal->lockMask & (1 << WAL_CKPT_LOCK)) : 0)
68350 int iRet = 0;
68353 pWal->iSysErrno = 0;
68368 int sync_flags, /* Flags to pass to OsSync() (or 0) */
68374 int isDelete = 0; /* True to unlink wal and wal-index files */
68386 if( zBuf!=0
68393 SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0
68405 }else if( pWal->mxWalSize>=0 ){
68409 ** non-negative value (pWal->mxWalSize>=0). Note that we truncate
68412 walLimitSize(pWal, 0);
68421 sqlite3OsDelete(pWal->pVfs, pWal->zWalName, 0);
68432 ** Try to read the wal-index header. Return 0 on success and 1 if
68454 assert( pWal->nWiData>0 && pWal->apWiData[0] );
68463 ** When reading, read [0] first then [1]. Writes are in the reverse order.
68473 memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */
68477 if( memcmp(&h1, &h2, sizeof(h1))!=0 ){
68480 if( h1.isInit==0 ){
68483 walChecksumBytes(1, (u8*)&h1, sizeof(h1)-sizeof(h1.aCksum), 0, aCksum);
68484 if( aCksum[0]!=h1.aCksum[0] || aCksum[1]!=h1.aCksum[1] ){
68491 pWal->szPage = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
68497 return 0;
68513 ** to 0.
68523 /* Ensure that page 0 of the wal-index (the page that contains the
68527 rc = walIndexPage(pWal, 0, &page0);
68537 assert( page0==0 );
68538 assert( pWal->writeLock==0 );
68549 testcase( page0!=0 );
68551 assert( page0!=0 || pWal->writeLock==0 );
68564 if( pWal->bShmUnreliable==0 && (pWal->readOnly & WAL_SHM_RDONLY) ){
68580 if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
68592 if( bWriteLock==0 ){
68593 pWal->writeLock = 0;
68604 if( badHdr==0 && pWal->hdr.iVersion!=WALINDEX_MAX_VERSION ){
68609 walIndexClose(pWal, 0);
68610 pWal->bShmUnreliable = 0;
68611 assert( pWal->nWiData>0 && pWal->apWiData[0]==0 );
68654 u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */
68663 assert( pWal->nWiData>0 && pWal->apWiData[0] );
68665 /* Take WAL_READ_LOCK(0). This has the effect of preventing any
68668 rc = walLockShared(pWal, WAL_READ_LOCK(0));
68673 pWal->readLock = 0;
68685 ** the WAL_READ_LOCK(0) which prevents a checkpoint, a writer might
68697 rc = sqlite3OsShmMap(pWal->pDbFd, 0, WALINDEX_PGSZ, 0, &pDummy);
68719 ** wal-index header has mxFrame==0, then it must be safe to proceed
68725 rc = (pWal->hdr.mxFrame==0 ? SQLITE_OK : WAL_RETRY);
68730 rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0);
68743 assert( (pWal->szPage & (pWal->szPage-1))==0 );
68747 if( aFrame==0 ){
68757 aSaveCksum[0] = pWal->hdr.aFrameCksum[0];
68779 pWal->hdr.aFrameCksum[0] = aSaveCksum[0];
68786 for(i=0; i<pWal->nWiData; i++){
68788 pWal->apWiData[i] = 0;
68790 pWal->bShmUnreliable = 0;
68801 ** int cnt = 0;
68823 # define WAL_RETRY_BLOCKED_MASK 0x10000000
68825 # define WAL_RETRY_BLOCKED_MASK 0
68839 ** checkpointed. If useWal==0 then this routine calls walIndexReadHdr()
68859 ** in the range 0 <= pWal->readLock < WAL_NREADER. If pWal->readLock==(-1)
68863 ** use WAL frames up to and including pWal->hdr.mxFrame if pWal->readLock>0
68864 ** Or if pWal->readLock==0, then the reader will ignore the WAL
68867 ** this routine will always set pWal->readLock>0 on success.
68882 int nBlockTmout = 0;
68885 assert( pWal->readLock<0 ); /* Not currently locked */
68888 assert( (pWal->readOnly & WAL_SHM_RDONLY)==0 || useWal==0 );
68939 if( pWal->bShmUnreliable==0 ){
68958 if( pWal->apWiData[0]==0 ){
68983 assert( pWal->nWiData>0 );
68984 assert( pWal->apWiData[0]!=0 );
68994 && ((pWal->bGetSnapshot==0 && pWal->pSnapshot==0) || pWal->hdr.mxFrame==0)
69000 rc = walLockShared(pWal, WAL_READ_LOCK(0));
69005 ** may have been appended to the log before READ_LOCK(0) was obtained.
69006 ** When holding READ_LOCK(0), the reader ignores the entire log file,
69008 ** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from
69012 ** is wrapped and written for that matter) before the READ_LOCK(0)
69017 walUnlockShared(pWal, WAL_READ_LOCK(0));
69020 pWal->readLock = 0;
69032 mxReadMark = 0;
69033 mxI = 0;
69048 if( (pWal->readOnly & WAL_SHM_RDONLY)==0
69049 && (mxReadMark<mxFrame || mxI==0)
69064 if( mxI==0 ){
69065 assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 );
69080 assert((rc&0xFF)!=SQLITE_BUSY||rc==SQLITE_BUSY||rc==SQLITE_BUSY_TIMEOUT);
69081 return (rc&0xFF)==SQLITE_BUSY ? WAL_RETRY : rc;
69157 assert( i - sLoc.iZero - 1 >=0 );
69169 if( rc!=SQLITE_OK || 0==memcmp(pBuf1, pBuf2, szPage) ){
69203 assert( pWal->readLock>=0 );
69208 if( pBuf1==0 || pBuf2==0 ){
69216 pWal->ckptLock = 0;
69234 int cnt = 0; /* Number of TryBeginRead attempts */
69236 int ckptLock = 0;
69237 int bChanged = 0;
69241 assert( pWal->ckptLock==0 );
69242 assert( pWal->nSehTry>0 );
69246 if( memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
69270 rc = walTryBeginRead(pWal, pChanged, 0, &cnt);
69272 testcase( (rc&0xff)==SQLITE_BUSY );
69273 testcase( (rc&0xff)==SQLITE_IOERR );
69279 if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
69295 assert( pWal->readLock>0 || pWal->hdr.mxFrame==0 );
69307 assert( pWal->readLock>0 );
69366 assert( pWal->writeLock==0 || pWal->readLock<0 );
69368 if( pWal->readLock>=0 ){
69388 u32 iRead = 0; /* If !=0, WAL frame to return data from */
69394 assert( pWal->readLock>=0 || pWal->lockError );
69396 /* If the "last page" field of the wal-index header snapshot is 0, then
69398 ** in this case as an optimization. Likewise, if pWal->readLock==0,
69402 if( iLast==0 || (pWal->readLock==0 && pWal->bShmUnreliable==0) ){
69403 *piRead = 0;
69447 while( (iH = AtomicLoad(&sLoc.aHash[iKey]))!=0 ){
69453 if( (nCollide--)==0 ){
69454 *piRead = 0;
69467 u32 iRead2 = 0;
69469 assert( pWal->bShmUnreliable || pWal->minFrame>0 );
69470 for(iTest=iLast; iTest>=pWal->minFrame && iTest>0; iTest--){
69522 sz = (sz&0xfe00) + ((sz&0x0001)<<16);
69534 if( pWal && ALWAYS(pWal->readLock>=0) ){
69537 return 0;
69562 assert( !memcmp(&pWal->hdr,(void*)pWal->apWiData[0],sizeof(WalIndexHdr)) );
69569 assert( pWal->readLock>=0 );
69570 assert( pWal->writeLock==0 && pWal->iReCksum==0 );
69590 if( memcmp(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr))!=0 ){
69598 pWal->writeLock = 0;
69610 pWal->writeLock = 0;
69611 pWal->iReCksum = 0;
69612 pWal->truncateOnCommit = 0;
69662 pWal->iReCksum = 0;
69675 aWalData[0] = pWal->hdr.mxFrame;
69676 aWalData[1] = pWal->hdr.aFrameCksum[0];
69691 assert( aWalData[3]!=pWal->nCkpt || aWalData[0]<=pWal->hdr.mxFrame );
69698 aWalData[0] = 0;
69702 if( aWalData[0]<pWal->hdr.mxFrame ){
69703 pWal->hdr.mxFrame = aWalData[0];
69704 pWal->hdr.aFrameCksum[0] = aWalData[1];
69711 pWal->iReCksum = 0;
69723 ** it sets pWal->hdr.mxFrame to 0. Otherwise, pWal->hdr.mxFrame is left
69734 if( pWal->readLock==0 ){
69737 if( pInfo->nBackfill>0 ){
69742 /* If all readers are using WAL_READ_LOCK(0) (in other words if no
69757 walUnlockShared(pWal, WAL_READ_LOCK(0));
69759 cnt = 0;
69764 assert( (rc&0xff)!=SQLITE_BUSY ); /* BUSY not possible when useWal==1 */
69765 testcase( (rc&0xff)==SQLITE_IOERR );
69807 assert( WAL_SYNC_FLAGS(p->syncFlags)!=0 );
69809 if( iAmt==0 || rc ) return rc;
69821 int nTruncate, /* The commit flag. Usually 0. >0 for commit */
69853 if( aBuf==0 ) return SQLITE_NOMEM_BKPT;
69860 assert( pWal->iReCksum>0 );
69867 pWal->hdr.aFrameCksum[0] = sqlite3Get4byte(aBuf);
69871 pWal->iReCksum = 0;
69899 int sync_flags /* Flags to pass to OsSync() (or 0) */
69904 PgHdr *pLast = 0; /* Last frame in list */
69905 int nExtra = 0; /* Number of extra copies of last page */
69909 u32 iFirst = 0; /* First frame that may be overwritten */
69915 /* If this frame set completes a transaction, then nTruncate>0. If
69916 ** nTruncate==0 then this frame set does not complete the transaction. */
69917 assert( (isCommit!=0)==(nTruncate!=0) );
69920 { int cnt; for(cnt=0, p=pList; p; p=p->pDirty, cnt++){}
69927 if( memcmp(&pWal->hdr, (void *)pLive, sizeof(WalIndexHdr))!=0 ){
69943 if( iFrame==0 ){
69947 sqlite3Put4byte(&aWalHdr[0], (WAL_MAGIC | SQLITE_BIGENDIAN));
69951 if( pWal->nCkpt==0 ) sqlite3_randomness(8, pWal->hdr.aSalt);
69953 walChecksumBytes(1, aWalHdr, WAL_HDRSIZE-2*4, 0, aCksum);
69954 sqlite3Put4byte(&aWalHdr[24], aCksum[0]);
69959 pWal->hdr.aFrameCksum[0] = aCksum[0];
69963 rc = sqlite3OsWrite(pWal->pWalFd, aWalHdr, sizeof(aWalHdr), 0);
69988 w.iSyncPoint = 0;
69996 int nDbSize; /* 0 normally. Positive == commit flag */
70002 if( iFirst && (p->pDirty || isCommit==0) ){
70003 u32 iWrite = 0;
70005 assert( rc==SQLITE_OK || iWrite==0 );
70009 if( pWal->iReCksum==0 || iWrite<pWal->iReCksum ){
70022 nDbSize = (isCommit && p->pDirty==0) ? nTruncate : 0;
70050 if( isCommit && WAL_SYNC_FLAGS(sync_flags)!=0 ){
70062 assert( pLast!=0 );
70075 if( isCommit && pWal->truncateOnCommit && pWal->mxWalSize>=0 ){
70081 pWal->truncateOnCommit = 0;
70091 if( (p->flags & PGHDR_WAL_APPEND)==0 ) continue;
70095 assert( pLast!=0 || nExtra==0 );
70096 while( rc==SQLITE_OK && nExtra>0 ){
70104 pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16));
70136 int sync_flags /* Flags to pass to OsSync() (or 0) */
70162 int sync_flags, /* Flags to sync db file with (or 0) */
70169 int isChanged = 0; /* True if a new wal-index header is loaded */
70173 assert( pWal->ckptLock==0 );
70174 assert( pWal->writeLock==0 );
70178 assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
70197 testcase( rc!=SQLITE_OK && xBusy2!=0 );
70207 ** writer lock retried until either the busy-handler returns 0 or the
70216 xBusy2 = 0;
70235 sqlite3OsUnfetch(pWal->pDbFd, 0, 0);
70264 memset(&pWal->hdr, 0, sizeof(WalIndexHdr));
70268 sqlite3WalDb(pWal, 0);
70274 pWal->ckptLock = 0;
70286 ** the last call, then return 0.
70289 u32 ret = 0;
70292 pWal->iCallback = 0;
70304 ** or if the acquisition of the lock fails, then return 0. If the
70311 ** be released. Return 1 if the transition is made and 0 if the
70323 assert( pWal->writeLock==0 );
70333 assert( pWal->readLock>=0 || pWal->lockError );
70335 assert( pWal->readLock>=0 || (op<=0 && pWal->exclusiveMode==0) );
70337 if( op==0 ){
70346 rc = 0;
70348 }else if( op>0 ){
70350 assert( pWal->readLock>=0 );
70377 static const u32 aZero[4] = { 0, 0, 0, 0 };
70379 assert( pWal->readLock>=0 && pWal->writeLock==0 );
70381 if( memcmp(&pWal->hdr.aFrameCksum[0],aZero,16)==0 ){
70382 *ppSnapshot = 0;
70386 if( pRet==0 ){
70402 if( pSnapshot && ((WalIndexHdr*)pSnapshot)->iVersion==0 ){
70403 /* iVersion==0 means that this is a call to sqlite3_snapshot_get(). In
70406 ** file, it does not take read-lock 0 if the wal file has been completely
70407 ** checkpointed. Taking read-lock 0 would work, but then it would be
70410 ** to user expectations, so we avoid it by not taking read-lock 0. */
70414 pWal->bGetSnapshot = 0;
70426 /* aSalt[0] is a copy of the value stored in the wal file header. It
70428 if( pHdr1->aSalt[0]<pHdr2->aSalt[0] ) return -1;
70429 if( pHdr1->aSalt[0]>pHdr2->aSalt[0] ) return +1;
70432 return 0;
70483 assert( pWal==0 || pWal->readLock>=0 );
70484 return (pWal ? pWal->szPage : 0);
70539 ** | Ptr(0) | Key(0) | Ptr(1) | Key(1) | ... | Key(N-1) | Ptr(N) |
70542 ** All of the keys on the page that Ptr(0) points to have values less
70543 ** than Key(0). All of the keys on page Ptr(1) and its subpages have
70544 ** values greater than Key(0) and less than Key(1). All of the keys
70574 ** 0 16 Header string: "SQLite format 3\000"
70645 ** 0 1 Flags. 1: intkey, 2: zerodata, 4: leafdata, 8: leaf
70694 ** 0x00 becomes 0x00000000
70695 ** 0x7f becomes 0x0000007f
70696 ** 0x81 0x00 becomes 0x00000080
70697 ** 0x82 0x00 becomes 0x00000100
70698 ** 0x80 0x7f becomes 0x0000007f
70699 ** 0x81 0x91 0xd1 0xac 0x78 becomes 0x12345678
70700 ** 0x81 0x81 0x81 0x81 0x01 becomes 0x10204081
70772 #define PTF_INTKEY 0x01
70773 #define PTF_ZERODATA 0x02
70774 #define PTF_LEAFDATA 0x04
70775 #define PTF_LEAF 0x08
70797 u8 hdrOffset; /* 100 for page 1. 0 otherwise */
70798 u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
70891 #define TRANS_NONE 0
70919 ** may not be modified once it is initially set as long as nRef>0.
70921 ** thereafter is unchanged as long as nRef>0.
70981 #define BTS_READ_ONLY 0x0001 /* Underlying file is readonly */
70982 #define BTS_PAGESIZE_FIXED 0x0002 /* Page size can no longer be changed */
70983 #define BTS_SECURE_DELETE 0x0004 /* PRAGMA secure_delete is enabled */
70984 #define BTS_OVERWRITE 0x0008 /* Overwrite deleted content with zeros */
70985 #define BTS_FAST_SECURE 0x000c /* Combination of the previous two */
70986 #define BTS_INITIALLY_EMPTY 0x0010 /* Database was empty at trans start */
70987 #define BTS_NO_WAL 0x0020 /* Do not open write-ahead-log files */
70988 #define BTS_EXCLUSIVE 0x0040 /* pWriter has an exclusive lock */
70989 #define BTS_PENDING 0x0080 /* Waiting for read-locks to clear */
71041 ** SKIPNEXT sqlite3BtreeNext() is a no-op if skipNext>0 and
71042 ** sqlite3BtreePrevious() is no-op if skipNext<0.
71044 ** eState=SKIPNEXT if skipNext!=0
71067 u8 curIntKey; /* Value of apPage[0]->intKey */
71078 #define BTCF_WriteFlag 0x01 /* True if a write cursor */
71079 #define BTCF_ValidNKey 0x02 /* True if info.nKey is valid */
71080 #define BTCF_ValidOvfl 0x04 /* True if aOverflow is valid */
71081 #define BTCF_AtLast 0x08 /* Cursor is pointing to the last entry */
71082 #define BTCF_Incrblob 0x10 /* True if an incremental I/O handle */
71083 #define BTCF_Multiple 0x20 /* Maybe another cursor on the same btree */
71084 #define BTCF_Pinned 0x40 /* Cursor is busy and cannot be moved */
71116 #define CURSOR_VALID 0
71150 ** 0 or 1 parent pages. (In this context 'database page' refers
71187 assert( p->pBt->inTransaction!=TRANS_NONE || p->pBt->nTransaction==0 ); \
71201 #define ISAUTOVACUUM(pBt) 0
71220 Pgno nCkPage; /* Pages in the database. 0 for partial check */
71238 #define get2byte(x) ((x)[0]<<8 | (x)[1])
71239 #define put2byte(p,v) ((p)[0] = (u8)((v)>>8), (p)[1] = (u8)(v))
71255 # define get2byteAligned(x) ((x)[0]<<8 | (x)[1])
71269 assert( p->locked==0 );
71290 p->locked = 0;
71317 assert( p->pNext==0 || p->pNext->pBt>p->pBt );
71318 assert( p->pPrev==0 || p->pPrev->pBt<p->pBt );
71319 assert( p->pNext==0 || p->pNext->db==p->db );
71320 assert( p->pPrev==0 || p->pPrev->db==p->db );
71321 assert( p->sharable || (p->pNext==0 && p->pPrev==0) );
71324 assert( !p->locked || p->wantToLock>0 );
71325 assert( p->sharable || p->wantToLock==0 );
71332 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );
71366 assert( pLater->pNext==0 || pLater->pNext->pBt>pLater->pBt );
71367 assert( !pLater->locked || pLater->wantToLock>0 );
71387 assert( p->wantToLock>0 );
71389 if( p->wantToLock==0 ){
71403 assert( p->sharable==0 || p->locked==0 || p->wantToLock>0 );
71404 assert( p->sharable==0 || p->locked==0 || p->db==p->pBt->db );
71405 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->pBt->mutex) );
71406 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->db->mutex) );
71408 return (p->sharable==0 || p->locked);
71432 for(i=0; i<db->nDb; i++){
71436 skipOk = 0;
71442 if( db->noSharedCache==0 ) btreeEnterAll(db);
71448 for(i=0; i<db->nDb; i++){
71454 if( db->noSharedCache==0 ) btreeLeaveAll(db);
71467 return 0;
71469 for(i=0; i<db->nDb; i++){
71473 (p->wantToLock==0 || !sqlite3_mutex_held(p->pBt->mutex)) ){
71474 return 0;
71495 assert( db!=0 );
71496 if( db->pVfs==0 && db->nDb==0 ) return 1;
71498 assert( iDb>=0 && iDb<db->nDb );
71499 if( !sqlite3_mutex_held(db->mutex) ) return 0;
71502 assert( p!=0 );
71503 return p->sharable==0 || p->locked==1;
71507 #else /* SQLITE_THREADSAFE>0 above. SQLITE_THREADSAFE==0 below */
71523 for(i=0; i<db->nDb; i++){
71581 #if 0
71597 #define get2byteNotZero(X) (((((int)get2byte(X))-1)&0xffff)+1)
71602 #define BTALLOC_ANY 0 /* Allocate any page */
71608 ** defined, or 0 if it is. For example:
71615 #define IfNotOmitAV(expr) 0
71628 SQLITE_PRIVATE BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
71630 static BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
71665 #define hasReadConflicts(a, b) 0
71674 pBt->nSeek = 0;
71693 p->pgno, sqlite3PagerFilename(p->pBt->pPager, 0)
71715 #if 0
71728 if( iRoot>0 ){
71753 ** table with root page iRoot. Return 1 if it does and 0 if not.
71758 ** assert( hasSharedCacheTableLock(pBtree, iRoot, 0, WRITE_LOCK) );
71778 Pgno iTab = 0;
71785 if( (pBtree->sharable==0)
71796 if( isIndex && (!pSchema || (pSchema->schemaFlags&DB_SchemaLoaded)==0) ){
71806 int bSeen = 0;
71839 return 0;
71867 && 0==(p->pBtree->db->flags & SQLITE_ReadUncommit)
71872 return 0;
71888 assert( p->db!=0 );
71906 if( pBt->pWriter!=p && (pBt->btsFlags & BTS_EXCLUSIVE)!=0 ){
71956 BtLock *pLock = 0;
71963 assert( p->db!=0 );
71969 assert( 0==(p->db->flags&SQLITE_ReadUncommit) || eLock==WRITE_LOCK );
72025 assert( p->sharable || 0==*ppIter );
72026 assert( p->inTrans>0 );
72028 SHARED_LOCK_TRACE(pBt, "clearAllLocks", 0, 0);
72032 assert( (pBt->btsFlags & BTS_EXCLUSIVE)==0 || pBt->pWriter==pLock->pBtree );
72045 assert( (pBt->btsFlags & BTS_PENDING)==0 || pBt->pWriter );
72047 pBt->pWriter = 0;
72054 ** set the BTS_PENDING flag to 0.
72069 SHARED_LOCK_TRACE(pBt, "downgradeLocks", 0, 0);
72073 pBt->pWriter = 0;
72153 pBtree->hasIncrblobCur = 0;
72155 if( (p->curFlags & BTCF_Incrblob)!=0 ){
72237 pBt->pHasContent = 0;
72245 if( pCur->iPage>=0 ){
72246 for(i=0; i<pCur->iPage; i++){
72270 assert( 0==pCur->pKey );
72287 rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey);
72289 memset(((u8*)pKey)+pCur->nKey, 0, 9+8);
72313 assert( 0==pCur->pKey );
72322 pCur->skipNext = 0;
72362 assert( pExcept==0 || pExcept->pBt==pBt );
72364 if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ) break;
72382 if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){
72389 testcase( p->iPage>=0 );
72404 pCur->pKey = 0;
72427 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
72429 if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
72436 pIdxKey = 0;
72451 int skipNext = 0;
72461 rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
72465 pCur->pKey = 0;
72495 assert( offsetof(BtCursor, eState)==0 );
72507 assert( offsetof(BtCursor, eState)==0 );
72527 assert( pCur!=0 );
72537 *pDifferentRow = 0;
72555 memset(&w, 0, sizeof(w));
72561 assert( pExpr!=0 );
72562 assert( w.u.aMem!=0 );
72574 assert( x==BTREE_SEEK_EQ || x==BTREE_BULKLOAD || x==0 );
72585 ** Return 0 (not a valid page) for pgno==1 since there is
72593 if( pgno<2 ) return 0;
72624 assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) );
72627 if( key==0 ){
72632 rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage, 0);
72637 if( ((char*)sqlite3PagerGetExtra(pDbPage))[0]!=0 ){
72645 if( offset<0 ){
72682 rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage, 0);
72683 if( rc!=0 ){
72689 if( offset<0 ){
72694 assert( pEType!=0 );
72710 ** Given a btree page and a cell index (0 means the first cell on
72769 assert( nPayload>=0 );
72801 assert( pPage->leaf==0 );
72807 pInfo->nPayload = 0;
72808 pInfo->nLocal = 0;
72809 pInfo->pPayload = 0;
72822 assert( pPage->leaf==0 || pPage->leaf==1 );
72824 assert( pPage->childPtrSize==0 );
72834 if( nPayload>=0x80 ){
72836 nPayload &= 0x7f;
72838 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
72839 }while( (*pIter)>=0x80 && pIter<pEnd );
72851 if( iKey>=0x80 ){
72854 if( x>=0x80 ){
72856 if( x>=0x80 ){
72857 iKey = (iKey<<7) ^ 0x10204000 ^ (x = *++pIter);
72858 if( x>=0x80 ){
72859 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++pIter);
72860 if( x>=0x80 ){
72861 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++pIter);
72862 if( x>=0x80 ){
72863 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++pIter);
72864 if( x>=0x80 ){
72865 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++pIter);
72866 if( x>=0x80 ){
72867 iKey = (iKey<<8) ^ 0x8000 ^ (*++pIter);
72874 iKey ^= 0x204000;
72877 iKey ^= 0x4000;
72887 assert( nPayload>=0 );
72909 assert( pPage->leaf==0 || pPage->leaf==1 );
72910 assert( pPage->intKeyLeaf==0 );
72913 if( nPayload>=0x80 ){
72915 nPayload &= 0x7f;
72917 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
72918 }while( *(pIter)>=0x80 && pIter<pEnd );
72926 assert( nPayload>=0 );
72941 int iCell, /* The cell index. First cell is 0 */
72977 if( nSize>=0x80 ){
72979 nSize &= 0x7f;
72981 nSize = (nSize<<7) | (*++pIter & 0x7f);
72982 }while( *(pIter)>=0x80 && pIter<pEnd );
73017 assert( pPage->childPtrSize==0 );
73019 if( nSize>=0x80 ){
73021 nSize &= 0x7f;
73023 nSize = (nSize<<7) | (*++pIter & 0x7f);
73024 }while( *(pIter)>=0x80 && pIter<pEnd );
73062 while( (*pIter++)&0x80 && pIter<pEnd );
73081 if( nSize>=0x80 ){
73083 nSize &= 0x7f;
73085 nSize = (nSize<<7) | (*++pIter & 0x7f);
73086 }while( *(pIter)>=0x80 && pIter<pEnd );
73092 if( (*pIter++)&0x80
73093 && (*pIter++)&0x80
73094 && (*pIter++)&0x80
73095 && (*pIter++)&0x80
73096 && (*pIter++)&0x80
73097 && (*pIter++)&0x80
73098 && (*pIter++)&0x80
73099 && (*pIter++)&0x80 ){ pIter++; }
73138 assert( pCell!=0 );
73183 assert( pPage->pBt!=0 );
73185 assert( pPage->nOverflow==0 );
73206 if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){
73209 int sz2 = 0;
73241 if( nCell>0 ){
73245 for(i=0; i<nCell; i++){
73257 assert( pc>=0 && pc<=iCellLast );
73270 data[hdr+7] = 0;
73273 assert( pPage->nFree>=0 );
73279 data[hdr+1] = 0;
73280 data[hdr+2] = 0;
73281 memset(&data[iCellFirst], 0, cbrk-iCellFirst);
73310 assert( pc>0 );
73317 if( (x = size - nByte)>=0 ){
73323 if( aData[hdr+7]>57 ) return 0;
73333 return 0;
73349 return 0;
73356 return 0;
73383 assert( nByte>=0 ); /* Minimum cell size is 4 */
73385 assert( pPage->nOverflow==0 );
73395 ** integer, so a value of 0 is used in its place. */
73399 if( top==0 && pPage->pBt->usableSize==65536 ){
73436 assert( pPage->nCell>0 || CORRUPT_DB );
73437 assert( pPage->nFree>=0 );
73474 u8 hdr; /* Page header size. 0 or 100 */
73475 int nFrag = 0; /* Reduction in fragmentation */
73482 assert( pPage->pBt!=0 );
73495 if( data[iPtr+1]==0 && data[iPtr]==0 ){
73496 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
73500 if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
73508 assert( iFreeBlk>iPtr || iFreeBlk==0 || CORRUPT_DB );
73548 memset(&data[iStart], 0, iSize);
73562 assert( iSize>=0 && iSize<=0xffff );
73576 ** PTF_ZERODATA (0x02, 2)
73577 ** PTF_LEAFDATA | PTF_INTKEY (0x05, 5)
73578 ** PTF_ZERODATA | PTF_LEAF (0x0a, 10)
73579 ** PTF_LEAFDATA | PTF_INTKEY | PTF_LEAF (0x0d, 13)
73584 assert( pPage->hdrOffset==(pPage->pgno==1 ? 100 : 0) );
73589 pPage->childPtrSize = 0;
73599 pPage->intKey = 0;
73600 pPage->intKeyLeaf = 0;
73606 pPage->intKey = 0;
73607 pPage->intKeyLeaf = 0;
73614 pPage->leaf = 0;
73616 pPage->intKey = 0;
73617 pPage->intKeyLeaf = 0;
73623 pPage->intKeyLeaf = 0;
73630 pPage->intKey = 0;
73631 pPage->intKeyLeaf = 0;
73654 assert( pPage->pBt!=0 );
73655 assert( pPage->pBt->db!=0 );
73661 assert( pPage->nFree<0 );
73679 if( pc>0 ){
73698 if( next>0 ){
73742 for(i=0; i<pPage->nCell; i++){
73771 assert( pPage->pBt!=0 );
73772 assert( pPage->pBt->db!=0 );
73777 assert( pPage->isInit==0 );
73781 /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
73783 if( decodeFlags(pPage, data[0]) ){
73788 pPage->nOverflow = 0;
73805 assert( pPage->nCell>0
73832 memset(&data[hdr], 0, pBt->usableSize - hdr);
73835 first = hdr + ((flags&PTF_LEAF)==0 ? 12 : 8);
73836 memset(&data[hdr+1], 0, 4);
73837 data[hdr+7] = 0;
73845 pPage->nOverflow = 0;
73848 pPage->nCell = 0;
73864 pPage->hdrOffset = pgno==1 ? 100 : 0;
73890 assert( flags==0 || flags==PAGER_GET_NOCONTENT || flags==PAGER_GET_READONLY );
73910 return 0;
73940 *ppPage = 0;
73945 *ppPage = 0;
73949 if( pPage->isInit==0 ){
73954 *ppPage = 0;
73973 assert( pPage->pDbPage!=0 );
73983 assert( pPage!=0 );
73986 assert( pPage->pDbPage!=0 );
74012 *ppPage = 0;
74015 (*ppPage)->isInit = 0;
74017 *ppPage = 0;
74034 assert( sqlite3PagerPageRefcount(pData)>0 );
74037 pPage->isInit = 0;
74089 BtShared *pBt = 0; /* Shared part of btree structure */
74091 sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */
74097 const int isTempDb = zFilename==0 || zFilename[0]==0;
74103 const int isMemdb = 0;
74105 const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
74107 || (vfsFlags & SQLITE_OPEN_MEMORY)!=0;
74110 assert( db!=0 );
74111 assert( pVfs!=0 );
74113 assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
74116 assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 );
74119 assert( (flags & BTREE_SINGLE)==0 || isTempDb );
74124 if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){
74143 if( isTempDb==0 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=0) ){
74177 assert( pBt->nRef>0 );
74178 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0))
74181 for(iDb=db->nDb-1; iDb>=0; iDb--){
74211 if( pBt==0 ){
74224 memset(&zDbHeader[16], 0, 8);
74227 if( pBt==0 ){
74245 pBt->pCursor = 0;
74246 pBt->pPage1 = 0;
74258 || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
74259 pBt->pageSize = 0;
74262 ** leave the autoVacuum mode at 0 (do not auto-vacuum), even if
74268 pBt->autoVacuum = (SQLITE_DEFAULT_AUTOVACUUM ? 1 : 0);
74269 pBt->incrVacuum = (SQLITE_DEFAULT_AUTOVACUUM==2 ? 1 : 0);
74272 nReserve = 0;
74280 pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
74281 pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
74287 assert( (pBt->pageSize & 7)==0 ); /* 8-byte alignment of pageSize */
74298 if( pBt->mutex==0 ){
74319 for(i=0; i<db->nDb; i++){
74320 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
74324 p->pPrev = 0;
74347 sqlite3PagerClose(pBt->pPager, 0);
74351 *ppBtree = 0;
74359 if( sqlite3BtreeSchema(p, 0, 0)==0 ){
74372 assert( rc!=SQLITE_OK || sqlite3BtreeConnectionCount(*ppBtree)>0 );
74386 int removed = 0;
74392 if( pBt->nRef<=0 ){
74422 assert( pBt!=0 );
74423 assert( pBt->pTmpSpace==0 );
74426 assert( pBt->pCursor!=0 && (pBt->pCursor->curFlags & BTCF_WriteFlag)!=0 );
74428 if( pBt->pTmpSpace==0 ){
74431 memset(pCur, 0, sizeof(*pCur));
74450 memset(pBt->pTmpSpace, 0, 8);
74462 pBt->pTmpSpace = 0;
74493 sqlite3BtreeRollback(p, SQLITE_OK, 0);
74500 assert( p->wantToLock==0 && p->locked==0 );
74512 sqlite3DbFree(0, pBt->pSchema);
74518 assert( p->wantToLock==0 );
74519 assert( p->locked==0 );
74552 ** using mxPage of 0 is a way to query the current spill size.
74564 #if SQLITE_MAX_MMAP_SIZE>0
74577 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
74612 ** the first byte past the 1GB boundary, 0x40000000) needs to occur
74618 ** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size
74625 assert( nReserve>=0 && nReserve<=255 );
74634 assert( nReserve>=0 && nReserve<=255 );
74636 ((pageSize-1)&pageSize)==0 ){
74637 assert( (pageSize & 7)==0 );
74696 ** No changes are made if mxPage is 0 or negative.
74710 ** newFlag==0 Both BTS_SECURE_DELETE and BTS_OVERWRITE are cleared
74727 if( p==0 ) return 0;
74731 if( newFlag>=0 ){
74755 if( (pBt->btsFlags & BTS_PAGESIZE_FIXED)!=0 && (av ?1:0)!=pBt->autoVacuum ){
74758 pBt->autoVacuum = av ?1:0;
74759 pBt->incrVacuum = av==2 ?1:0;
74768 ** enabled 1 is returned. Otherwise 0.
74797 if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){
74798 while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; }
74799 if( pDb->bSyncSet==0
74830 u32 nPageFile = 0; /* Number of pages in the database file */
74833 assert( pBt->pPage1==0 );
74836 rc = btreeGetPage(pBt, 1, &pPage1, 0);
74844 if( nPage==0 || memcmp(24+(u8*)pPage1->aData, 92+(u8*)pPage1->aData,4)!=0 ){
74847 if( (pBt->db->flags & SQLITE_ResetDatabase)!=0 ){
74848 nPage = 0;
74850 if( nPage>0 ){
74858 if( memcmp(page1, zMagicHeader, 16)!=0 ){
74885 if( page1[19]==2 && (pBt->btsFlags & BTS_NO_WAL)==0 ){
74886 int isOpen = 0;
74892 if( isOpen==0 ){
74907 ** version 3.6.0, we require them to be fixed.
74909 if( memcmp(&page1[21], "\100\040\040",3)!=0 ){
74918 if( ((pageSize-1)&pageSize)!=0
74924 assert( (pageSize & 7)==0 );
74950 if( sqlite3WritableSchema(pBt->db)==0 ){
74967 pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0);
74968 pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0);
74982 ** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow
75001 pBt->pPage1 = 0;
75020 int r = 0;
75022 if( (wrOnly==0 || (pCur->curFlags & BTCF_WriteFlag)!=0)
75039 assert( countValidCursors(pBt,0)==0 || pBt->inTransaction>TRANS_NONE );
75040 if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){
75044 pBt->pPage1 = 0;
75060 if( pBt->nPage>0 ){
75064 assert( pP1!=0 );
75070 data[16] = (u8)((pBt->pageSize>>8)&0xff);
75071 data[17] = (u8)((pBt->pageSize>>16)&0xff);
75079 memset(&data[24], 0, 100-24);
75083 assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
75084 assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
75101 p->pBt->nPage = 0;
75161 assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 );
75164 && sqlite3PagerIsreadonly(pPager)==0
75170 if( (pBt->btsFlags & BTS_READ_ONLY)!=0 && wrflag ){
75177 sqlite3 *pBlock = 0;
75183 || (pBt->btsFlags & BTS_PENDING)!=0
75210 if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY;
75217 if( pBt->pPage1==0 && wrflag ){
75226 ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
75231 while( pBt->pPage1==0 && SQLITE_OK==(rc = lockBtree(pBt)) );
75234 if( (pBt->btsFlags & BTS_READ_ONLY)!=0 ){
75250 (void)sqlite3PagerWalWriteLock(pPager, 0);
75260 }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
75262 sqlite3PagerWalDb(pPager, 0);
75314 ** open savepoints. If the second parameter is greater than 0 and
75329 || (p->inTrans==TRANS_READ && wrflag!=0)
75339 ** open savepoints. If the second parameter is greater than 0 and
75367 for(i=0; i<nCell; i++){
75418 for(i=0; i<nCell; i++){
75507 if( nextOvfl!=0 ){
75520 rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0);
75570 if( nFreeList==0 ){
75583 if( bCommit==0 ){
75602 Pgno iNear = 0; /* nearby parameter for allocateBtreePage() */
75604 rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0);
75616 if( bCommit==0 ){
75644 if( bCommit==0 ){
75700 }else if( nFree>0 ){
75701 rc = saveAllCursors(pBt, 0, 0);
75704 rc = incrVacuumStep(pBt, nFin, nOrig, 0);
75729 assert( p!=0 );
75757 for(iDb=0; ALWAYS(iDb<db->nDb); iDb++){
75770 if( nVac==0 ){
75779 rc = saveAllCursors(pBt, 0, 0);
75784 if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
75787 put4byte(&pBt->pPage1->aData[32], 0);
75788 put4byte(&pBt->pPage1->aData[36], 0);
75850 rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zSuperJrnl, 0);
75866 pBt->bDoTruncate = 0;
75877 ** reaches 0, set the shared state to TRANS_NONE. The unlockBtreeIfUnused()
75882 if( 0==pBt->nTransaction ){
75935 assert( pBt->nTransaction>0 );
75937 if( rc!=SQLITE_OK && bCleanup==0 ){
75957 rc = sqlite3BtreeCommitPhaseOne(p, 0);
75959 rc = sqlite3BtreeCommitPhaseTwo(p, 0);
75995 assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
75999 if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){
76003 (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0);
76025 testcase( nPage==0 );
76026 if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
76047 assert( writeOnly==1 || writeOnly==0 );
76051 rc = tripCode = saveAllCursors(pBt, 0, 0);
76052 if( rc ) writeOnly = 0;
76058 assert( rc==SQLITE_OK || (writeOnly==0 && rc2==SQLITE_OK) );
76075 if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
76079 assert( countValidCursors(pBt, 1)==0 );
76112 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
76113 assert( iStatement>0 );
76143 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
76146 rc = saveAllCursors(pBt, 0, 0);
76152 if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){
76153 pBt->nPage = 0;
76160 assert( CORRUPT_DB || pBt->nPage>0 );
76184 ** cursors open with wrFlag==0 on the same table. Otherwise
76200 ** return a null row (2-bytes: 0x01 0x00).
76212 int wrFlag, /* 1 to write. 0 read-only */
76220 assert( wrFlag==0
76229 assert( hasSharedCacheTableLock(p, iTable, pKeyInfo!=0, (wrFlag?2:1))
76231 assert( wrFlag==0 || !hasReadConflicts(p, iTable) );
76235 assert( wrFlag==0 || p->inTrans==TRANS_WRITE );
76237 assert( wrFlag==0 || (pBt->btsFlags & BTS_READ_ONLY)==0 );
76242 }else if( btreePagecount(pBt)==0 ){
76243 assert( wrFlag==0 );
76244 iTable = 0;
76255 pCur->curFlags = 0;
76269 pCur->curPagerFlags = 0;
76270 if( pBt->pTmpSpace==0 ) return allocateTempSpace(pBt);
76279 int wrFlag, /* 1 to write. 0 read-only */
76292 int wrFlag, /* 1 to write. 0 read-only */
76326 if( (pBt->openFlags & BTREE_SINGLE)==0 ) return 0;
76327 if( pBt->pCursor!=pCur ) return 0;
76328 if( pCur->pNext!=0 ) return 0;
76329 if( pCur->pBtree!=pBtree ) return 0;
76343 memset(p, 0, offsetof(BtCursor, BTCURSOR_FIRST_UNINIT));
76355 assert( pBt->pCursor!=0 );
76372 if( (pBt->openFlags & BTREE_SINGLE) && pBt->pCursor==0 ){
76375 assert( pBtree->sharable==0 );
76380 pCur->pBtree = 0;
76395 if( a->nKey!=b->nKey ) return 0;
76396 if( a->pPayload!=b->pPayload ) return 0;
76397 if( a->nPayload!=b->nPayload ) return 0;
76398 if( a->nLocal!=b->nLocal ) return 0;
76399 if( a->nSize!=b->nSize ) return 0;
76404 memset(&info, 0, sizeof(info));
76412 if( pCur->info.nSize==0 ){
76431 assert( pCur!=0 );
76453 assert( (pCur->curFlags & BTCF_Pinned)==0 );
76457 assert( (pCur->curFlags & BTCF_Pinned)!=0 );
76533 Pgno next = 0;
76534 MemPage *pPage = 0;
76566 assert( next==0 || rc==SQLITE_DONE );
76568 rc = btreeGetPage(pBt, ovfl, &pPage, (ppPage==0) ? PAGER_GET_READONLY : 0);
76569 assert( rc==SQLITE_OK || pPage==0 );
76599 int eOp, /* 0 -> copy from page, 1 -> copy to page */
76621 ** 0: The operation is a read. Populate the overflow cache.
76654 int iIdx = 0;
76662 assert( eOp==0 || eOp==1 );
76690 offset = 0;
76698 if( rc==SQLITE_OK && amt>0 ){
76708 ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
76711 if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){
76713 if( pCur->aOverflow==0
76718 aNew = 0;
76722 if( aNew==0 ){
76728 memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
76732 assert( pCur->aOverflow[0]==nextPage
76733 || pCur->aOverflow[0]==0
76735 assert( pCur->aOverflow[0]!=0 || pCur->aOverflow[offset/ovflSize]==0 );
76748 assert( rc==SQLITE_OK && amt>0 );
76752 assert( pCur->aOverflow[iIdx]==0
76769 rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
76774 ** range of data that is being read (eOp==0) or written (eOp!=0).
76795 if( eOp==0 /* (1) */
76796 && offset==0 /* (2) */
76814 (eOp==0 ? PAGER_GET_READONLY : 0)
76821 offset = 0;
76825 if( amt==0 ) return rc;
76833 if( rc==SQLITE_OK && amt>0 ){
76860 assert( pCur->iPage>=0 && pCur->pPage );
76861 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
76882 return rc ? rc : accessPayload(pCur, offset, amt, pBuf, 0);
76887 return accessPayload(pCur, offset, amt, pBuf, 0);
76897 ** the key if index btrees (pPage->intKey==0) and is the data for
76899 ** key/data is written into *pAmt. If *pAmt==0, then the value
76918 assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
76923 assert( pCur->info.nSize>0 );
76931 amt = MAX(0, (int)(pCur->pPage->aDataEnd - pCur->info.pPayload));
76971 assert( pCur->iPage>=0 );
76975 pCur->info.nSize = 0;
76979 pCur->ix = 0;
76982 assert( pCur->pPage!=0 || rc!=SQLITE_OK );
77029 assert( pCur->iPage>0 );
77037 pCur->info.nSize = 0;
77061 ** specify a KeyInfo structure the flags byte is set to 0x05 or 0x0D,
77063 ** structure the flags byte is set to 0x02 or 0x0A, indicating an index
77074 assert( pCur->eState < CURSOR_REQUIRESEEK || pCur->iPage<0 );
77075 assert( pCur->pgnoRoot>0 || pCur->iPage<0 );
77077 if( pCur->iPage>=0 ){
77083 pRoot = pCur->pPage = pCur->apPage[0];
77086 }else if( pCur->pgnoRoot==0 ){
77104 pCur->iPage = 0;
77117 ** if pCur->iPage>=0). But this is not so if the database is corrupted
77120 assert( pRoot->intKey==1 || pRoot->intKey==0 );
77121 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
77126 pCur->ix = 0;
77127 pCur->info.nSize = 0;
77130 if( pRoot->nCell>0 ){
77180 MemPage *pPage = 0;
77191 assert( pCur->info.nSize==0 );
77192 assert( (pCur->curFlags & BTCF_ValidNKey)==0 );
77197 ** on success. Set *pRes to 0 if the cursor actually points to something
77207 assert( pCur->pPage->nCell>0 );
77208 *pRes = 0;
77211 assert( pCur->pgnoRoot==0 || (pCur->pPage!=0 && pCur->pPage->nCell==0) );
77228 for(ii=0; ii<pCur->iPage; ii++){
77229 if( pCur->aiIdx[ii]!=pCur->apPage[ii]->nCell ) return 0;
77231 return pCur->ix==pCur->pPage->nCell-1 && pCur->pPage->leaf!=0;
77236 ** on success. Set *pRes to 0 if the cursor actually points to something
77243 *pRes = 0;
77251 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
77262 if( CURSOR_VALID==pCur->eState && (pCur->curFlags & BTCF_AtLast)!=0 ){
77264 *pRes = 0;
77283 ** *pRes<0 The cursor is left pointing at an entry that
77287 ** *pRes==0 The cursor is left pointing at an entry that
77290 ** *pRes>0 The cursor is left pointing at an entry that
77304 assert( pCur->pKeyInfo==0 );
77305 assert( pCur->eState!=CURSOR_VALID || pCur->curIntKey!=0 );
77309 if( pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0 ){
77311 *pRes = 0;
77315 if( (pCur->curFlags & BTCF_AtLast)!=0 ){
77325 *pRes = 0;
77326 rc = sqlite3BtreeNext(pCur, 0);
77346 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
77355 assert( pCur->pPage->nCell > 0 );
77356 assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey );
77371 assert( pPage->nCell>0 );
77373 lwr = 0;
77375 assert( biasRight==0 || biasRight==1 );
77381 while( 0x80 <= *(pCell++) ){
77403 pCur->info.nSize = 0;
77404 *pRes = 0;
77408 assert( lwr+upr>=0 );
77431 pCur->info.nSize = 0;
77432 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
77463 nCell = pCell[0];
77470 }else if( !(pCell[1] & 0x80)
77471 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
77492 for(i=0; i<pCur->iPage; i++){
77494 if( pCur->aiIdx[i]<pPage->nCell ) return 0;
77512 ** *pRes<0 The cursor is left pointing at an entry that
77516 ** *pRes==0 The cursor is left pointing at an entry that
77519 ** *pRes>0 The cursor is left pointing at an entry that
77536 assert( pCur->pKeyInfo!=0 );
77543 pIdxKey->errCode = 0;
77545 || pIdxKey->default_rc==0
77567 && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0
77573 if( pCur->iPage>0
77574 && indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0
77589 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
77600 assert( pCur->pPage->nCell > 0 );
77601 assert( pCur->curIntKey==0 );
77602 assert( pIdxKey!=0 );
77615 assert( pPage->nCell>0 );
77616 assert( pPage->intKey==0 );
77617 lwr = 0;
77632 nCell = pCell[0];
77639 }else if( !(pCell[1] & 0x80)
77640 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
77661 testcase( nCell<0 ); /* True if key size is 2^32 or more */
77662 testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
77663 testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
77670 if( pCellKey==0 ){
77675 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
77676 memset(((u8*)pCellKey)+nCell,0,nOverrun); /* Fix uninit warnings */
77686 (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
77689 if( c<0 ){
77691 }else if( c>0 ){
77694 assert( c==0 );
77695 *pRes = 0;
77702 assert( lwr+upr>=0 );
77726 pCur->info.nSize = 0;
77733 pCur->ix = 0;
77750 pCur->info.nSize = 0;
77751 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
77786 if( pCur->eState!=CURSOR_VALID ) return 0;
77787 if( NEVER(pCur->pPage->leaf==0) ) return -1;
77790 for(i=0; i<pCur->iPage; i++){
77810 ** If bit 0x01 of the F argument in sqlite3BtreeNext(C,F) is 1, then the
77823 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
77833 if( pCur->skipNext>0 ) return SQLITE_OK;
77839 if( sqlite3FaultSim(412) ) pPage->isInit = 0;
77851 if( pCur->iPage==0 ){
77859 return sqlite3BtreeNext(pCur, 0);
77874 assert( flags==0 || flags==1 );
77875 pCur->info.nSize = 0;
77904 ** If bit 0x01 of the F argument to sqlite3BtreePrevious(C,F) is 1, then
77915 assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
77916 assert( pCur->info.nSize==0 );
77927 if( pCur->skipNext<0 ) return SQLITE_OK;
77932 if( sqlite3FaultSim(412) ) pPage->isInit = 0;
77942 while( pCur->ix==0 ){
77943 if( pCur->iPage==0 ){
77949 assert( pCur->info.nSize==0 );
77950 assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
77955 rc = sqlite3BtreePrevious(pCur, 0);
77964 assert( flags==0 || flags==1 );
77967 pCur->info.nSize = 0;
77969 || pCur->ix==0
77970 || pCur->pPage->leaf==0
77989 ** If the "nearby" parameter is not 0, then an effort is made to
78011 MemPage *pTrunk = 0;
78012 MemPage *pPrevTrunk = 0;
78016 assert( eMode==BTALLOC_ANY || (nearby>0 && IfNotOmitAV(pBt->autoVacuum)) );
78026 if( n>0 ){
78029 u8 searchList = 0; /* If the free-list must be searched for 'nearby' */
78030 u32 nSearch = 0; /* Count of the number of search attempts */
78040 assert( nearby>0 );
78042 rc = ptrmapGet(pBt, nearby, &eType, 0);
78071 iTrunk = get4byte(&pPrevTrunk->aData[0]);
78082 rc = btreeGetUnusedPage(pBt, iTrunk, &pTrunk, 0);
78085 pTrunk = 0;
78088 assert( pTrunk!=0 );
78089 assert( pTrunk->aData!=0 );
78093 if( k==0 && !searchList ){
78097 assert( pPrevTrunk==0 );
78103 memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
78105 pTrunk = 0;
78120 searchList = 0;
78125 if( k==0 ){
78127 memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
78133 memcpy(&pPrevTrunk->aData[0], &pTrunk->aData[0], 4);
78147 rc = btreeGetUnusedPage(pBt, iNewTrunk, &pNewTrunk, 0);
78156 memcpy(&pNewTrunk->aData[0], &pTrunk->aData[0], 4);
78168 put4byte(&pPrevTrunk->aData[0], iNewTrunk);
78171 pTrunk = 0;
78174 }else if( k>0 ){
78179 if( nearby>0 ){
78181 closest = 0;
78183 for(i=0; i<k; i++){
78202 closest = 0;
78226 noContent = !btreeGetHasContent(pBt, *pPgno)? PAGER_GET_NOCONTENT : 0;
78232 *ppPage = 0;
78235 searchList = 0;
78239 pPrevTrunk = 0;
78260 int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate))? PAGER_GET_NOCONTENT:0;
78273 MemPage *pPg = 0;
78295 *ppPage = 0;
78306 assert( rc!=SQLITE_OK || (*ppPage)->isInit==0 );
78323 MemPage *pTrunk = 0; /* Free-list trunk page */
78324 Pgno iTrunk = 0; /* Page number of free-list trunk page */
78354 if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
78355 || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0)
78359 memset(pPage->aData, 0, pPage->pBt->pageSize);
78366 ptrmapPut(pBt, iPage, PTRMAP_FREEPAGE, 0, &rc);
78377 if( nFree!=0 ){
78385 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
78403 ** 3.6.0, databases with freelist trunk pages holding more than
78408 ** to 3.6.0 or later) we should consider fixing the conditional above
78420 if( pPage && (pBt->btsFlags & BTS_SECURE_DELETE)==0 ){
78436 if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0)) ){
78444 put4byte(&pPage->aData[4], 0);
78450 pPage->isInit = 0;
78489 assert( nOvfl>0 ||
78493 Pgno iNext = 0;
78494 MemPage *pOvfl = 0;
78496 /* 0 is not a legal page number and page 1 cannot be an
78506 if( ( pOvfl || ((pOvfl = btreePageLookup(pBt, ovflPgno))!=0) )
78594 assert( pX->nKey<=0x7fffffff && pX->pKey!=0 );
78610 pPayload[nPayload] = 0;
78616 memset(pPayload+nSrc, 0, nPayload-nSrc);
78631 pToRelease = 0;
78632 pgnoOvfl = 0;
78665 assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );
78674 }else if( nSrc>0 ){
78678 memset(pPayload, 0, n);
78681 if( nPayload<=0 ) break;
78686 if( spaceLeft==0 ){
78687 MemPage *pOvfl = 0;
78698 rc = allocateBtreePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, 0);
78725 assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );
78736 put4byte(pPrior, 0);
78758 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
78761 assert( idx>=0 );
78766 assert( pPage->nFree>=0 );
78784 if( pPage->nCell==0 ){
78785 memset(&data[hdr+1], 0, 4);
78786 data[hdr+7] = 0;
78825 int idx = 0; /* Where to write new cell content in data[] */
78830 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
78837 assert( pPage->nFree>=0 );
78838 assert( iChild>0 );
78858 assert( j==0 || pPage->aiOvfl[j-1]<(u16)i ); /* Overflows in sorted order */
78859 assert( j==0 || i==pPage->aiOvfl[j-1]+1 ); /* Overflows are sequential */
78872 assert( idx >= 0 );
78888 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
78920 int idx = 0; /* Where to write new cell content in data[] */
78925 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
78932 assert( pPage->nFree>=0 );
78933 assert( pPage->nOverflow==0 );
78948 assert( j==0 || pPage->aiOvfl[j-1]<(u16)i ); /* Overflows in sorted order */
78949 assert( j==0 || i==pPage->aiOvfl[j-1]+1 ); /* Overflows are sequential */
78962 assert( idx >= 0 );
78972 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
79053 ** ixNx[0] = Number of cells in Child-1.
79059 ** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
79062 ** ixNx[0] = Number of cells in Child-1.
79088 assert( idx>=0 && idx+N<=p->nCell );
79089 while( N>0 ){
79090 assert( p->apCell[idx]!=0 );
79091 if( szCell[idx]==0 ){
79106 assert( N>=0 && N<p->nCell );
79107 assert( p->szCell[N]==0 );
79112 assert( N>=0 && N<p->nCell );
79149 assert( nCell>0 );
79152 if( j>(u32)usableSize ){ j = 0; }
79156 for(k=0; pCArray->ixNx[k]<=i; k++){}
79163 assert( sz>0 );
79190 pPg->nOverflow = 0;
79192 put2byte(&aData[hdr+1], 0);
79195 aData[hdr+7] = 0x00;
79207 ** (part of page pPg) to populate. After cell apCell[0] is written to the
79238 assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
79239 if( iEnd<=iFirst ) return 0;
79241 for(k=0; pCArray->ixNx[k]<=i ; k++){}
79246 assert( pCArray->szCell[i]!=0 );
79248 if( (aData[1]==0 && aData[2]==0) || (pSlot = pageFindSlot(pPg,sz,&rc))==0 ){
79277 return 0;
79298 int nRet = 0;
79301 int nFree = 0;
79314 sz = pCArray->szCell[i]; assert( sz>0 );
79317 for(j=0; j<nFree; j++){
79327 if( nFree>=(int)(sizeof(aOfst)/sizeof(aOfst[0])) ){
79328 for(j=0; j<nFree; j++){
79331 nFree = 0;
79335 if( &aData[iAfter]>pEnd ) return 0;
79341 for(j=0; j<nFree; j++){
79382 assert( nCell>=0 );
79402 assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
79403 assert( nAdd>=0 );
79414 for(i=0; i<pPg->nOverflow; i++){
79416 if( iCell>=0 && iCell<nNew ){
79431 assert( nCell>=0 );
79443 pPg->nOverflow = 0;
79449 for(i=0; i<nNew && !CORRUPT_DB; i++){
79455 assert( 0==memcmp(pCell, &aData[iOff],
79503 if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT; /* dbfuzz001.test */
79504 assert( pPage->nFree>=0 );
79505 assert( pParent->nFree>=0 );
79511 rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
79516 u8 *pCell = pPage->apOvfl[0];
79522 assert( CORRUPT_DB || pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
79528 b.apEnd[0] = pPage->aDataEnd;
79529 b.ixNx[0] = 2;
79530 b.ixNx[NB*2-1] = 0x7fffffff;
79531 rc = rebuildPage(&b, 0, 1, pNew);
79569 while( (*(pCell++)&0x80) && pCell<pStop );
79571 while( ((*(pOut++) = *(pCell++))&0x80) && pCell<pStop );
79576 0, pPage->pgno);
79590 #if 0
79598 for(i=0; i<nPage; i++){
79605 for(j=0; j<pPage->nCell; j++){
79655 int const iToHdr = ((pTo->pgno==1) ? 100 : 0);
79674 pTo->isInit = 0;
79739 int nMaxCells = 0; /* Allocated size of apCell, szCell, aFrom. */
79740 int nNew = 0; /* Number of pages in apNew[] */
79745 u16 leafCorrection; /* 4 if pPage is a leaf. 0 if not */
79748 int pageFlags; /* Value of pPage->aData[0] */
79749 int iSpace1 = 0; /* First unused byte of aSpace1[] */
79750 int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */
79765 memset(abDone, 0, sizeof(abDone));
79767 memset(&b, 0, sizeof(b)-sizeof(b.ixNx[0]));
79768 b.ixNx[NB*2-1] = 0x7fffffff;
79778 assert( pParent->nOverflow==0 || pParent->nOverflow==1 );
79779 assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );
79784 assert( pParent->nFree>=0 );
79799 nxDiv = 0;
79801 assert( bBulk==0 || bBulk==1 );
79802 if( iParentIdx==0 ){
79803 nxDiv = 0;
79820 rc = getAndInitPage(pBt, pgno, &apOld[i], 0);
79823 memset(apOld, 0, (i+1)*sizeof(MemPage*));
79826 if( apOld[i]->nFree<0 ){
79829 memset(apOld, 0, (i)*sizeof(MemPage*));
79834 if( (i--)==0 ) break;
79836 if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
79837 apDiv[i] = pParent->apOvfl[0];
79840 pParent->nOverflow = 0;
79886 b.apCell = sqlite3StackAllocRaw(0, szScratch );
79887 if( b.apCell==0 ){
79908 ** leafCorrection: 4 if pPage is a leaf. 0 if pPage is not a leaf.
79911 b.pRef = apOld[0];
79914 for(i=0; i<nOld; i++){
79926 if( pOld->aData[0]!=apOld[0]->aData[0] ){
79948 memset(&b.szCell[b.nCell], 0, sizeof(b.szCell[0])*(limit+pOld->nOverflow));
79949 if( pOld->nOverflow>0 ){
79950 if( NEVER(limit<pOld->aiOvfl[0]) ){
79954 limit = pOld->aiOvfl[0];
79955 for(j=0; j<limit; j++){
79960 for(k=0; k<pOld->nOverflow; k++){
79961 assert( k==0 || pOld->aiOvfl[k-1]+1==pOld->aiOvfl[k] );/* NOTE 1 */
79987 assert( leafCorrection==0 || leafCorrection==4 );
79990 assert( leafCorrection==0 );
79991 assert( pOld->hdrOffset==0 || CORRUPT_DB );
79999 ** does exist, pad it with 0x00 bytes. */
80002 aSpace1[iSpace1++] = 0x00;
80027 for(i=k=0; i<nOld; i++, k++){
80039 assert( p->nFree>=0 );
80041 for(j=0; j<p->nOverflow; j++){
80047 for(i=0; i<k; i++){
80053 szNew[k-1] = 0;
80062 sz = 0;
80077 sz = 0;
80084 }else if( cntNew[i] <= (i>0 ? cntNew[i-1] : 0) ){
80101 for(i=k-1; i>0; i--){
80116 if( szRight!=0
80117 && (bBulk || szRight+szD+2 > szLeft-(szR+(i==k-1?0:2)))){
80125 }while( r>=0 );
80128 if( cntNew[i-1] <= (i>1 ? cntNew[i-2] : 0) ){
80136 ** (1) We found one or more cells (cntNew[0])>0), or
80141 assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) || CORRUPT_DB);
80143 apOld[0]->pgno, apOld[0]->nCell,
80144 nOld>=2 ? apOld[1]->pgno : 0, nOld>=2 ? apOld[1]->nCell : 0,
80145 nOld>=3 ? apOld[2]->pgno : 0, nOld>=3 ? apOld[2]->nCell : 0
80151 pageFlags = apOld[0]->aData[0];
80152 for(i=0; i<k; i++){
80156 apOld[i] = 0;
80166 assert( i>0 );
80167 rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0);
80196 for(i=0; i<nNew; i++){
80201 for(i=0; i<nNew-1; i++){
80228 apNew[0]->pgno, szNew[0], cntNew[0],
80229 nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0,
80230 nNew>=2 ? cntNew[1] - cntNew[0] - !leafData : 0,
80231 nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0,
80232 nNew>=3 ? cntNew[2] - cntNew[1] - !leafData : 0,
80233 nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0,
80234 nNew>=4 ? cntNew[3] - cntNew[2] - !leafData : 0,
80235 nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0,
80236 nNew>=5 ? cntNew[4] - cntNew[3] - !leafData : 0
80241 assert( apNew[nNew-1]!=0 );
80247 if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){
80270 MemPage *pNew = pOld = apNew[0];
80272 int iNew = 0;
80273 int iOld = 0;
80275 for(i=0; i<b.nCell; i++){
80280 assert( iOld>=0 && iOld<NB );
80311 for(i=0; i<nNew-1; i++){
80320 assert( b.apCell[j]!=0 );
80337 pTemp = 0;
80360 for(k=0; b.ixNx[k]<=j; k++){}
80386 ** to 0, then back up to nNew-1 again, thus making two passes over
80394 int iPg = i<0 ? -i : i;
80395 assert( iPg>=0 && iPg<nNew );
80396 assert( iPg>=1 || i>=0 );
80399 if( i>=0 /* On the upwards pass, or... */
80408 assert( iPg==0 || cntOld[iPg-1]>=cntNew[iPg-1] || abDone[iPg-1] );
80414 if( iPg==0 ){
80415 iNew = iOld = 0;
80416 nNewCell = cntNew[0];
80427 assert( apNew[iPg]->nOverflow==0 );
80433 assert( memcmp(abDone, "\01\01\01\01\01", nNew)==0 );
80435 assert( nOld>0 );
80436 assert( nNew>0 );
80438 if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){
80455 rc = defragmentPage(apNew[0], -1);
80457 assert( apNew[0]->nFree ==
80458 (get2byteNotZero(&apNew[0]->aData[5]) - apNew[0]->cellOffset
80459 - apNew[0]->nCell*2)
80462 copyNodeContent(apNew[0], pParent, &rc);
80463 freePage(apNew[0], &rc);
80468 for(i=0; i<nNew; i++){
80484 #if 0
80485 if( ISAUTOVACUUM(pBt) && rc==SQLITE_OK && apNew[0]->isInit ){
80499 sqlite3StackFree(0, b.apCell);
80500 for(i=0; i<nOld; i++){
80503 for(i=0; i<nNew; i++){
80528 ** an error code is returned and *ppChild is set to 0.
80532 MemPage *pChild = 0; /* Pointer to a new child page */
80533 Pgno pgnoChild = 0; /* Page number of the new child page */
80536 assert( pRoot->nOverflow>0 );
80545 rc = allocateBtreePage(pBt,&pChild,&pgnoChild,pRoot->pgno,0);
80552 *ppChild = 0;
80564 pRoot->nOverflow*sizeof(pRoot->aiOvfl[0]));
80566 pRoot->nOverflow*sizeof(pRoot->apOvfl[0]));
80570 zeroPage(pRoot, pChild->aData[0] & ~PTF_LEAF);
80614 u8 *pFree = 0;
80616 VVA_ONLY( int balance_quick_called = 0 );
80617 VVA_ONLY( int balance_deeper_called = 0 );
80623 if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
80624 if( pPage->nOverflow==0 && pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
80630 }else if( (iPage = pCur->iPage)==0 ){
80637 assert( balance_deeper_called==0 );
80642 pCur->ix = 0;
80643 pCur->aiIdx[0] = 0;
80644 pCur->apPage[0] = pPage;
80661 if( rc==SQLITE_OK && pParent->nFree<0 ){
80668 && pPage->aiOvfl[0]==pPage->nCell
80685 assert( balance_quick_called==0 );
80726 pPage->nOverflow = 0;
80731 assert( pCur->iPage>=0 );
80753 if( nData<=0 ){
80756 for(i=0; i<iAmt && pDest[i]==0; i++){}
80760 memset(pDest + i, 0, iAmt - i);
80771 if( memcmp(pDest, ((u8*)pX->pData) + iOffset, iAmt)!=0 ){
80805 0, pCur->info.nLocal);
80810 assert( nTotal>=0 );
80811 assert( iOffset>=0 );
80816 rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
80852 0, pCur->info.nLocal);
80877 ** been performed. In other words, if seekResult!=0 then the cursor
80879 ** to be inserted. If seekResult<0 then pCur points to a cell that is
80880 ** smaller then (pKey,nKey). If seekResult>0 then pCur points to a cell
80883 ** If seekResult==0, that means pCur is pointing at some unknown location.
80898 int szNew = 0;
80903 unsigned char *newCell = 0;
80906 assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 );
80922 if( loc && pCur->iPage<0 ){
80943 assert( (pCur->curFlags & BTCF_WriteFlag)!=0
80945 && (p->pBt->btsFlags & BTS_READ_ONLY)==0 );
80946 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
80953 assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
80955 if( pCur->pKeyInfo==0 ){
80956 assert( pX->pKey==0 );
80960 invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
80970 assert( loc==0 );
80974 /* On the other hand, BTREE_SAVEPOSITION==0 does not imply
80978 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
80981 assert( pX->nData>=0 && pX->nZero>=0 );
80982 if( pCur->info.nSize!=0
80988 assert( loc==0 );
80989 }else if( loc==0 ){
80995 (flags & BTREE_APPEND)!=0, &loc);
81004 assert( (flags & BTREE_SAVEPOSITION)==0 || loc==0 );
81011 if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
81017 r.default_rc = 0;
81018 r.eqSeen = 0;
81022 (flags & BTREE_APPEND)!=0, &loc);
81031 if( loc==0 ){
81036 x2.nData = (int)pX->nKey; assert( pX->nKey<=0x7fffffff );
81037 x2.nZero = 0;
81046 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
81048 if( pPage->nFree<0 ){
81060 loc==0 ? "overwrite" : "new entry"));
81063 assert( newCell!=0 );
81070 newCell[3] = 0;
81088 pCur->info.nSize = 0;
81089 if( loc==0 ){
81091 assert( idx>=0 );
81130 }else if( loc<0 && pPage->nCell>0 ){
81138 assert( pPage->nOverflow==0 || rc==SQLITE_OK );
81139 assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
81170 pCur->pPage->nOverflow = 0;
81175 assert( pCur->pKey==0 );
81177 if( pCur->pKey==0 ){
81187 assert( pCur->iPage<0 || pCur->pPage->nOverflow==0 );
81216 if( pSrc->info.nPayload<0x80 ){
81221 if( pDest->pKeyInfo==0 ) aOut += putVarint(aOut, iKey);
81235 u8 *pPgnoOut = 0;
81236 Pgno ovflIn = 0;
81237 DbPage *pPageIn = 0;
81238 MemPage *pPageOut = 0;
81258 assert( nOut>0 );
81259 if( nIn>0 ){
81267 if( nOut>0 ){
81269 pPageIn = 0;
81278 }while( rc==SQLITE_OK && nOut>0 );
81280 if( rc==SQLITE_OK && nRem>0 && ALWAYS(pPgnoOut) ){
81282 MemPage *pNew = 0;
81283 rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
81292 put4byte(pPgnoOut, 0);
81297 }while( nRem>0 && rc==SQLITE_OK );
81335 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
81337 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
81339 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
81358 if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){
81377 ** bPreserve==0 Not necessary to save the cursor position
81381 bPreserve = (flags & BTREE_SAVEPOSITION)!=0;
81405 rc = sqlite3BtreePrevious(pCur, 0);
81419 if( pCur->pKeyInfo==0 && p->hasIncrblobCur ){
81420 invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0);
81443 if( pLeaf->nFree<0 ){
81457 assert( pTmp!=0 );
81481 assert( pCur->pPage->nOverflow==0 );
81482 assert( pCur->pPage->nFree>=0 );
81504 assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
81544 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
81547 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
81598 u8 eType = 0;
81599 Pgno iPtrPage = 0;
81604 rc = saveAllCursors(pBt, 0, 0);
81611 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
81625 rc = relocatePage(pBt, pRoot, eType, iPtrPage, pgnoMove, 0);
81632 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
81646 ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
81664 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
81676 assert( (pBt->openFlags & BTREE_SINGLE)==0 || pgnoRoot==2 );
81709 rc = getAndInitPage(pBt, pgno, &pPage, 0);
81711 if( (pBt->openFlags & BTREE_SINGLE)==0
81718 for(i=0; i<pPage->nCell; i++){
81730 if( pPage->intKey ) pnChange = 0;
81738 }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
81765 rc = saveAllCursors(pBt, (Pgno)iTable, 0);
81772 invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
81774 rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
81786 return sqlite3BtreeClearTable(pCur->pBtree, pCur->pgnoRoot, 0);
81805 ** the move. If no page gets moved, *piMoved is set to 0.
81811 MemPage *pPage = 0;
81821 rc = sqlite3BtreeClearTable(p, iTable, 0);
81823 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
81829 *piMoved = 0;
81855 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
81859 rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0);
81864 pMove = 0;
81865 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
81907 ** Read the meta-information out of a database file. Meta[0]
81909 ** through meta[15] are available for use by higher layers. Meta[0]
81914 ** free pages is not visible. So Cookie[0] is the same as Meta[1].
81930 assert( idx>=0 && idx<=15 );
81941 if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
81950 ** Write meta-information back into the database. Meta[0] is
81960 assert( pBt->pPage1!=0 );
81967 assert( pBt->autoVacuum || iMeta==0 );
81968 assert( iMeta==0 || iMeta==1 );
81986 i64 nEntry = 0; /* Value to return in *pnEntry */
81991 *pnEntry = 0;
82023 if( pCur->iPage==0 ){
82064 pCheck->mxErr = 0; /* Causes integrity_check processing to stop */
82065 if( pCheck->nErr==0 ) pCheck->nErr++;
82077 pCheck->mxErr = 0;
82081 assert( db->nProgressOps>0 );
82083 if( (pCheck->nStep % db->nProgressOps)==0
82088 pCheck->mxErr = 0;
82130 assert( pCheck->aPgRef!=0 );
82131 assert( iPg<=pCheck->nCkPage && sizeof(pCheck->aPgRef[0])==1 );
82132 return (pCheck->aPgRef[iPg/8] & (1 << (iPg & 0x07)));
82139 assert( pCheck->aPgRef!=0 );
82140 assert( iPg<=pCheck->nCkPage && sizeof(pCheck->aPgRef[0])==1 );
82141 pCheck->aPgRef[iPg/8] |= (1 << (iPg & 0x07));
82148 ** Return 1 if there are 2 or more references to the page and 0 if
82154 if( iPage>pCheck->nCkPage || iPage==0 ){
82163 return 0;
82210 while( iPage!=0 && pCheck->mxErr ){
82215 if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage, 0) ){
82224 checkPtrmap(pCheck, iPage, PTRMAP_FREEPAGE, 0);
82232 for(i=0; i<(int)n; i++){
82236 checkPtrmap(pCheck, iFreePage, PTRMAP_FREEPAGE, 0);
82250 if( pCheck->pBt->autoVacuum && N>0 ){
82271 ** aHeap[0] is the number of elements on the heap. aHeap[1] is the
82292 assert( aHeap!=0 );
82293 i = ++aHeap[0];
82295 while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){
82304 if( (x = aHeap[0])==0 ) return 0;
82307 aHeap[x] = 0xffffffff;
82308 aHeap[0]--;
82310 while( (j = i*2)<=aHeap[0] ){
82324 ** the tree depth. Root pages return 0. Parents of root pages
82342 MemPage *pPage = 0; /* The page being analyzed */
82361 u32 *heap = 0; /* Min-heap used for checking cell coverage */
82362 u32 x, prev = 0; /* Next and previous entry on the min-heap */
82366 u8 savedIsInit = 0;
82371 if( pCheck->mxErr==0 ) goto end_of_check;
82374 if( iPage==0 ) return 0;
82375 if( checkRef(pCheck, iPage) ) return 0;
82378 if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
82388 pPage->isInit = 0;
82389 if( (rc = btreeInitPage(pPage))!=0 ){
82395 if( (rc = btreeComputeFreeSpace(pPage))!=0 ){
82412 if( pPage->leaf || pPage->intKey==0 ){
82432 keyCanBeEqual = 0;
82437 heap[0] = 0;
82442 for(i=nCell-1; i>=0 && pCheck->mxErr; i--){
82453 doCoverageCheck = 0;
82460 doCoverageCheck = 0;
82470 keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
82485 checkList(pCheck, 0, pgnoOvfl, nPage);
82497 keyCanBeEqual = 0;
82511 pCheck->zPfx = 0;
82512 if( doCoverageCheck && pCheck->mxErr>0 ){
82518 heap[0] = 0;
82519 for(i=nCell-1; i>=0; i--){
82526 assert( heap!=0 );
82534 while( i>0 ){
82547 assert( j==0 || j>i+size ); /* Enforced by btreeComputeFreeSpace() */
82564 nFrag = 0;
82567 if( (prev&0xffff)>=(x>>16) ){
82572 nFrag += (x>>16) - (prev&0xffff) - 1;
82576 nFrag += usableSize - (prev&0xffff) - 1;
82582 if( heap[0]==0 && nFrag!=data[hdr+7] ){
82610 ** malloc is returned if *pnErr is non-zero. If *pnErr==0 then NULL is
82613 ** If the first entry in aRoot[] is 0, that indicates that the list of
82637 int bPartial = 0; /* True if not checking all btrees */
82641 assert( nRoot>0 );
82642 assert( aCnt!=0 );
82644 /* aRoot[0]==0 means this is a partial check */
82645 if( aRoot[0]==0 ){
82648 if( aRoot[1]!=1 ) bCkFreelist = 0;
82654 assert( nRef>=0 );
82655 memset(&sCheck, 0, sizeof(sCheck));
82661 sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
82663 if( sCheck.nCkPage==0 ){
82673 if( sCheck.heap==0 ){
82687 sCheck.zPfx = 0;
82695 Pgno mx = 0;
82697 for(i=0; (int)i<nRoot; i++) if( mx<aRoot[i] ) mx = aRoot[i];
82705 }else if( get4byte(&pBt->pPage1->aData[64])!=0 ){
82714 for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
82715 sCheck.nRow = 0;
82720 checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
82735 if( getPageReferenced(&sCheck, i)==0 ){
82742 if( getPageReferenced(&sCheck, i)==0 &&
82746 if( getPageReferenced(&sCheck, i)!=0 &&
82760 if( sCheck.nErr==0 ){
82762 *pzOut = 0;
82781 assert( p->pBt->pPager!=0 );
82794 assert( p->pBt->pPager!=0 );
82803 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
82804 return p ? p->inTrans : 0;
82838 return p->nBackup!=0;
82852 ** If the nBytes parameter is 0 and the blob of memory has not yet been
82863 assert( nBytes==0 || nBytes==sizeof(Schema) );
82866 pBt->pSchema = sqlite3DbMallocZero(0, nBytes);
82901 assert( isWriteLock==0 || isWriteLock==1 );
82958 if( (pCsr->curFlags & BTCF_WriteFlag)==0 ){
82961 assert( (pCsr->pBt->btsFlags & BTS_READ_ONLY)==0
82963 assert( hasSharedCacheTableLock(pCsr->pBtree, pCsr->pgnoRoot, 0, 2) );
82996 rc = sqlite3BtreeBeginTrans(pBtree, 0, 0);
83000 rc = sqlite3BtreeBeginTrans(pBtree, 2, 0);
83020 return (pCsr->hints & mask)!=0;
83027 return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
83145 ** function. If an error occurs while doing so, return 0 and write an
83153 int rc = 0;
83162 return 0;
83166 if( i<0 ){
83168 return 0;
83180 rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),0,0);
83217 return 0;
83236 p = 0;
83255 p->isAttached = 0;
83257 if( 0==p->pSrc || 0==p->pDest
83266 p = 0;
83306 assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
83311 assert( nSrcPgsz==nDestPgsz || sqlite3PagerIsMemdb(pDestPager)==0 );
83318 DbPage *pDestPg = 0;
83321 if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg, 0))
83336 ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0;
83337 if( iOff==0 && bUpdate==0 ){
83383 int pgszSrc = 0; /* Source page size */
83384 int pgszDest = 0; /* Destination page size */
83387 if( p==0 ) return SQLITE_MISUSE_BKPT;
83401 int bCloseTrans = 0; /* True if src db requires unlocking */
83417 rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0);
83427 if( p->bDestLocked==0 && rc==SQLITE_OK && setDestPgsz(p)==SQLITE_NOMEM ){
83432 if( SQLITE_OK==rc && p->bDestLocked==0
83455 assert( nSrcPage>=0 );
83456 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
83462 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
83484 if( nSrcPage==0 ){
83524 assert( nDestTruncate>0 );
83544 assert( nDestTruncate==0
83560 rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0);
83568 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1);
83578 PgHdr *pSrcPg = 0;
83580 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg, 0);
83593 rc = sqlite3PagerSync(pDestPager, 0);
83597 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
83602 && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0))
83616 TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0);
83617 TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0);
83643 if( p==0 ) return SQLITE_OK;
83657 assert( pp!=0 );
83660 assert( pp!=0 );
83666 sqlite3BtreeRollback(p->pDest, SQLITE_OK, 0);
83693 if( p==0 ){
83695 return 0;
83707 if( p==0 ){
83709 return 0;
83732 assert( p!=0 );
83750 }while( (p = p->pNext)!=0 );
83801 ** to 0. This is used by the implementations of sqlite3_backup_step()
83805 memset(&b, 0, sizeof(b));
83811 /* 0x7FFFFFFF is the hard limit for the number of pages in a database
83817 sqlite3_backup_step(&b, 0x7FFFFFFF);
83857 /* True if X is a power of two. 0 is considered a power of two here.
83860 #define ISPOWEROF2(X) (((X)&((X)-1))==0)
83870 /* If MEM_Dyn is set then Mem.xDel!=0.
83873 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
83875 /* MEM_Dyn may only be set if Mem.szMalloc==0. In this way we
83876 ** ensure that if Mem.szMalloc>0 then it is safe to do
83879 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
83886 assert( (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob|MEM_Agg))==0 );
83896 assert( ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
83897 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
83898 ((p->flags&MEM_Static)!=0 ? 1 : 0) <= 1 );
83902 |MEM_Dyn|MEM_Ephem|MEM_Static))==0 );
83909 assert( (p->flags & MEM_Cleared)==0 );
83913 assert( p->szMalloc==0
83926 if( (p->flags & (MEM_Str|MEM_Blob)) && p->n>0 ){
83928 ((p->szMalloc>0 && p->z==p->zMalloc)? 1 : 0) +
83929 ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
83930 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
83931 ((p->flags&MEM_Static)!=0 ? 1 : 0) == 1
83958 sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0);
83960 (p->flags & MEM_IntReal)!=0 ? (double)p->u.i : p->u.r);
83961 assert( acc.zText==zBuf && acc.mxAlloc<=0 );
83962 zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
83995 if( (p->flags & MEM_Str)==0 ) return 1;
84000 if( p->szMalloc>0 && p->z==p->zMalloc ){
84004 assert( p->z[p->n]==0 );
84005 assert( p->enc==SQLITE_UTF8 || p->z[(p->n+1)&~1]==0 );
84006 assert( p->enc==SQLITE_UTF8 || p->z[((p->n+1)&~1)+1]==0 );
84008 if( (p->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 ) return 1;
84012 i = j = 0;
84019 if( zBuf[j++]!=z[i] ) return 0;
84043 assert( pMem!=0 );
84054 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84081 testcase( pMem->db==0 );
84085 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
84086 testcase( bPreserve && pMem->z==0 );
84088 assert( pMem->szMalloc==0
84092 if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
84097 if( pMem->zMalloc==0 ) sqlite3_free(pMem->z);
84100 bPreserve = 0;
84102 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
84105 if( pMem->zMalloc==0 ){
84107 pMem->z = 0;
84108 pMem->szMalloc = 0;
84118 if( (pMem->flags&MEM_Dyn)!=0 ){
84119 assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
84142 assert( CORRUPT_DB || szNew>0 );
84143 assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
84145 return sqlite3VdbeMemGrow(pMem, szNew, 0);
84147 assert( (pMem->flags & MEM_Dyn)==0 );
84166 assert( pMem->z!=0 );
84171 pMem->z[pMem->n] = 0;
84181 pMem->z[pMem->n] = 0;
84200 pMem->z[pMem->n] = 0;
84201 pMem->z[pMem->n+1] = 0;
84202 pMem->z[pMem->n+2] = 0;
84214 assert( pMem!=0 );
84215 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84217 if( (pMem->flags & (MEM_Str|MEM_Blob))!=0 ){
84219 if( pMem->szMalloc==0 || pMem->z!=pMem->zMalloc ){
84226 pMem->pScopyFrom = 0;
84239 assert( pMem!=0 );
84241 assert( (pMem->flags&MEM_Blob)!=0 || MemNullNochng(pMem) );
84244 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84248 if( nByte<=0 ){
84249 if( (pMem->flags & MEM_Blob)==0 ) return SQLITE_OK;
84255 assert( pMem->z!=0 );
84258 memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
84269 assert( pMem!=0 );
84270 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84272 testcase( (pMem->flags & (MEM_Term|MEM_Str))==0 );
84297 assert( pMem!=0 );
84298 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84307 pMem->enc = 0;
84312 assert( pMem->z!=0 );
84332 assert( pFunc!=0 );
84333 assert( pMem!=0 );
84334 assert( pMem->db!=0 );
84335 assert( pFunc->xFinalize!=0 );
84336 assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef );
84338 memset(&ctx, 0, sizeof(ctx));
84339 memset(&t, 0, sizeof(t));
84347 assert( (pMem->flags & MEM_Dyn)==0 );
84348 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
84364 assert( pFunc!=0 );
84365 assert( pFunc->xValue!=0 );
84366 assert( (pAccum->flags & MEM_Null)!=0 || pFunc==pAccum->u.pDef );
84367 assert( pAccum->db!=0 );
84369 memset(&ctx, 0, sizeof(ctx));
84390 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
84394 assert( (p->flags & MEM_Agg)==0 );
84398 assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 );
84418 p->szMalloc = 0;
84420 p->z = 0;
84455 ** an SQL-NULL value, return 0.
84460 i64 value = 0;
84466 assert( pMem!=0 );
84467 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84475 }else if( (flags & (MEM_Str|MEM_Blob))!=0 && pMem->z!=0 ){
84478 return 0;
84489 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
84490 double val = (double)0;
84495 assert( pMem!=0 );
84496 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84506 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
84507 return (double)0;
84512 ** Return 1 if pMem represents true, and return 0 if pMem represents false.
84517 if( pMem->flags & (MEM_Int|MEM_IntReal) ) return pMem->u.i!=0;
84527 assert( pMem!=0 );
84530 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84559 assert( pMem!=0 );
84560 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84574 assert( pMem!=0 );
84575 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84595 || (memcmp(&r1, &r2, sizeof(r1))==0
84618 assert( pMem!=0 );
84623 if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){
84626 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
84627 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
84629 if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
84638 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))!=0 );
84654 if( (pMem->flags & MEM_Blob)==0 ){
84698 assert( (flags & ~MEM_TypeMask)==0 );
84701 pMem->szMalloc = 0;
84736 pMem->n = 0;
84737 if( n<0 ) n = 0;
84740 pMem->z = 0;
84744 int nByte = n>0?n:1;
84745 if( sqlite3VdbeMemGrow(pMem, nByte, 0) ){
84748 assert( pMem->z!=0 );
84750 memset(pMem->z, 0, nByte);
84751 pMem->n = n>0?n:0;
84846 assert( db!=0 );
84850 if( p==0 ) return SQLITE_NOMEM;
84862 assert( p->db!=0 );
84870 return 0;
84900 assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
84905 pX->pScopyFrom = 0;
84908 pMem->bScopy = 0;
84910 pMem->pScopyFrom = 0;
84930 if( (pFrom->flags&MEM_Static)==0 ){
84949 if( 0==(pFrom->flags&MEM_Static) ){
84965 assert( pFrom->db==0 || sqlite3_mutex_held(pFrom->db->mutex) );
84966 assert( pTo->db==0 || sqlite3_mutex_held(pTo->db->mutex) );
84967 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
84972 pFrom->szMalloc = 0;
85001 u8 enc, /* Encoding of z. 0 for BLOBs */
85008 assert( pMem!=0 );
85009 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
85011 assert( enc!=0 || n>=0 );
85024 if( nByte<0 ){
85025 assert( enc!=0 );
85029 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
85032 }else if( enc==0 ){
85059 testcase( nAlloc==0 );
85078 pMem->n = (int)(nByte & 0x7fffffff);
85121 pMem->z[amt] = 0; /* Overrun area used when reading malformed records */
85135 u32 available = 0; /* Number of bytes available on the local btree page */
85145 assert( pMem->z!=0 );
85151 rc = sqlite3VdbeMemFromBtree(pCur, 0, amt, pMem);
85163 assert( pVal!=0 );
85164 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
85167 assert( (pVal->flags & (MEM_Null))==0 );
85169 if( ExpandBlob(pVal) ) return 0;
85174 if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&SQLITE_PTR_TO_INT(pVal->z)) ){
85175 assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 );
85177 return 0;
85182 sqlite3VdbeMemStringify(pVal, enc, 0);
85183 assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) );
85185 assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
85191 return 0;
85206 if( !pVal ) return 0;
85207 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
85215 return 0;
85227 if( ALWAYS(pVal!=0)
85228 && ALWAYS((pVal->flags & (MEM_Str|MEM_Blob))!=0)
85229 && (pVal->flags & MEM_Dyn)!=0
85234 return 0;
85275 UnpackedRecord *pRec = p->ppRec[0];
85277 if( pRec==0 ){
85291 for(i=0; i<nCol; i++){
85297 pRec = 0;
85300 if( pRec==0 ) return 0;
85301 p->ppRec[0] = pRec;
85344 sqlite3_value **apVal = 0; /* Function arguments */
85345 int nVal = 0; /* Number of function arguments */
85346 FuncDef *pFunc = 0; /* Function definition */
85347 sqlite3_value *pVal = 0; /* New value */
85349 ExprList *pList = 0; /* Function arguments */
85352 assert( pCtx!=0 );
85353 assert( (p->flags & EP_TokenOnly)==0 );
85358 pFunc = sqlite3FindFunction(db, p->u.zToken, nVal, enc, 0);
85360 if( pFunc==0 ) return SQLITE_OK;
85363 if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
85364 || (pFunc->funcFlags & (SQLITE_FUNC_NEEDCOLL|SQLITE_FUNC_RUNONLY))!=0
85370 apVal = (sqlite3_value**)sqlite3DbMallocZero(db, sizeof(apVal[0]) * nVal);
85371 if( apVal==0 ){
85375 for(i=0; i<nVal; i++){
85378 if( apVal[i]==0 || rc!=SQLITE_OK ) goto value_from_function_out;
85383 if( pVal==0 ){
85388 memset(&ctx, 0, sizeof(ctx));
85408 pVal = 0;
85412 for(i=0; i<nVal; i++){
85444 char *zVal = 0;
85445 sqlite3_value *pVal = 0;
85450 assert( pExpr!=0 );
85455 ** on a table column definition, and hence only when pCtx==0. This
85458 assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );
85463 aff = sqlite3AffinityType(pExpr->u.zToken,0);
85472 assert( (ppVal[0][0].flags & MEM_Zero)==0 );
85487 || pLeft->u.zToken[0]!='0' || (pLeft->u.zToken[1] & ~0x20)!='X'
85499 if( pVal==0 ) goto no_mem;
85504 if( op==TK_INTEGER && 0==sqlite3DecOrHexToI64(pExpr->u.zToken, &iVal) ){
85508 if( zVal==0 ) goto no_mem;
85526 assert( (pVal->flags & MEM_IntReal)==0 );
85538 && pVal!=0
85557 if( pVal==0 ) goto no_mem;
85564 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
85572 0, SQLITE_DYNAMIC);
85576 else if( op==TK_FUNCTION && pCtx!=0 ){
85585 pVal->u.i = pExpr->u.zToken[4]==0;
85595 if( pCtx==0 || NEVER(pCtx->pParse->nErr==0) )
85599 assert( *ppVal==0 );
85601 if( pCtx==0 ) sqlite3ValueFree(pVal);
85603 assert( pCtx==0 ); sqlite3ValueFree(pVal);
85625 return pExpr ? valueFromExpr(db, pExpr, enc, affinity, ppVal, 0) : 0;
85638 ** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
85655 sqlite3_value *pVal = 0;
85661 assert( pExpr==0 || pExpr->op!=TK_REGISTER || pExpr->op2!=TK_VARIABLE );
85667 }else if( pExpr->op==TK_VARIABLE && (db->flags & SQLITE_EnableQPSG)==0 ){
85671 if( (v = pParse->pReprepare)!=0 ){
85683 assert( pVal==0 || pVal->db==db );
85695 ** right starting with 0). A single field is populated if:
85697 ** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
85732 int nExtract = 0;
85734 if( pExpr==0 || pExpr->op!=TK_SELECT ){
85742 for(i=0; i<nElem; i++){
85743 sqlite3_value *pVal = 0;
85744 Expr *pElem = (pExpr ? sqlite3VectorFieldSubexpr(pExpr, i) : 0);
85773 return stat4ValueFromExpr(pParse, pExpr, affinity, 0, ppVal);
85791 u32 t = 0; /* a column type code */
85795 u32 szField = 0; /* Size of the current data field */
85800 assert( iCol>0 );
85804 for(i=0; i<=iCol; i++){
85815 if( pMem==0 ){
85817 if( pMem==0 ) return SQLITE_NOMEM_BKPT;
85834 sqlite3 *db = aMem[0].db;
85835 for(i=0; i<nCol; i++){
85872 return valueToText(pVal, enc)!=0 ? pVal->n : 0;
85876 assert( (p->flags & MEM_Null)==0 || (p->flags & (MEM_Str|MEM_Blob))==0 );
85877 if( (p->flags & MEM_Str)!=0 && pVal->enc==enc ){
85880 if( (p->flags & MEM_Str)!=0 && enc!=SQLITE_UTF8 && pVal->enc!=SQLITE_UTF8 ){
85883 if( (p->flags & MEM_Blob)!=0 ){
85890 if( p->flags & MEM_Null ) return 0;
85924 if( p==0 ) return 0;
85925 memset(&p->aOp, 0, sizeof(Vdbe)-offsetof(Vdbe,aOp));
85936 assert( pParse->aLabel==0 );
85937 assert( pParse->nLabel==0 );
85938 assert( p->nOpAlloc==0 );
85939 assert( pParse->szOpAlloc==0 );
85940 sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
85966 if( p==0 ) return;
85968 if( (prepFlags & SQLITE_PREPARE_SAVESQL)==0 ){
85969 p->expmask = 0;
85971 assert( p->zSql==0 );
86003 assert( zId!=0 );
86004 if( pVdbe->pDblStr==0 ) return 0;
86006 if( strcmp(zId, pStr->z)==0 ) return 1;
86008 return 0;
86109 static u64 n = 0;
86137 if( p->db->mallocFailed==0 ){
86159 return sqlite3VdbeAddOp3(p, op, 0, 0, 0);
86162 return sqlite3VdbeAddOp3(p, op, p1, 0, 0);
86165 return sqlite3VdbeAddOp3(p, op, p1, p2, 0);
86173 assert( op>=0 && op<0xff );
86177 assert( p->aOp!=0 );
86180 assert( pOp!=0 );
86182 pOp->p5 = 0;
86186 pOp->p4.p = 0;
86192 pOp->zComment = 0;
86195 pOp->nExec = 0;
86196 pOp->nCycle = 0;
86200 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
86205 pOp->iSrcLine = 0;
86229 assert( pOp!=0 );
86231 pOp->p5 = 0;
86241 pOp->zComment = 0;
86244 pOp->nExec = 0;
86245 pOp->nCycle = 0;
86249 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
86254 pOp->iSrcLine = 0;
86265 return sqlite3VdbeAddOp3(p, OP_Goto, 0, iDest, 0);
86272 return sqlite3VdbeAddOp4(p, OP_String8, 0, iDest, 0, zStr, 0);
86291 for(i=0; (c = zTypes[i])!=0; i++){
86294 sqlite3VdbeAddOp4(p, z==0 ? OP_Null : OP_String8, 0, iDest+i, 0, z, 0);
86327 ** that describes the calling context of the function. 0 means a general
86331 ** while computing a generated column value. 0 is the usual case.
86347 if( pCtx==0 ){
86350 return 0;
86352 pCtx->pOut = 0;
86354 pCtx->pVdbe = 0;
86355 pCtx->isError = 0;
86386 ** 0 means "none".
86390 if( pParse->addrExplain==0 ) return 0;
86413 int addr = 0;
86429 addr = sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
86435 sqlite3VdbeScanStatus(v, iThis, -1, -1, 0, 0);
86444 sqlite3ExplainBreakpoint("POP", 0);
86459 sqlite3VdbeAddOp4(p, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC);
86461 for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
86476 v->pParse->nTempReg = 0;
86477 v->pParse->nRangeReg = 0;
86517 nNewSize*sizeof(p->aLabel[0]));
86518 if( p->aLabel==0 ){
86519 p->nLabelAlloc = 0;
86537 assert( j>=0 );
86543 if( p->nLabelAlloc + p->nLabel < 0 ){
86581 ** memset(&sIter, 0, sizeof(sIter));
86595 int iSub; /* 0 = main program, 1 = first sub-program etc. */
86599 Op *pRet = 0;
86605 if( p->iSub==0 ){
86618 p->iAddr = 0;
86624 for(j=0; j<p->nSub; j++){
86630 pRet = 0;
86653 ** * OP_FkCounter with P2==0 (immediate foreign key constraint)
86665 int hasAbort = 0;
86666 int hasFkCounter = 0;
86667 int hasCreateTable = 0;
86668 int hasCreateIndex = 0;
86669 int hasInitCoroutine = 0;
86673 if( v==0 ) return 0;
86674 memset(&sIter, 0, sizeof(sIter));
86677 while( (pOp = opIterNext(&sIter))!=0 ){
86701 if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
86725 if( pC==0
86741 assert( p->nWrite==0 || p->usesStmtJournal );
86772 assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
86774 p->bIsReader = 0;
86776 assert( p->aOp[0].opcode==OP_Init );
86789 if( pOp->p2!=0 ) p->readOnly = 0;
86802 p->readOnly = 0;
86807 assert( pOp->p2>=0 );
86830 if( pOp->p2<0 ){
86834 assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 );
86836 assert( aLabel!=0 ); /* True because of tag-20230419-1 */
86840 /* OPFLG_JUMP opcodes never have P2==0, though OPFLG_JUMP0 opcodes
86842 assert( pOp->p2>0
86843 || (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP0)!=0 );
86847 || (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)==0 );
86854 assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
86862 pParse->aLabel = 0;
86864 pParse->nLabel = 0;
86866 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
86899 sqlite3_str *pErr = 0;
86900 assert( v!=0 );
86902 assert( pParse!=0 );
86908 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 ){
86910 if( iDest==0 ) continue;
86916 if( iDest<0 ){
86918 assert( j>=0 );
86919 if( j>=-pParse->nLabel || pParse->aLabel[j]<0 ){
86934 if( pErr==0 ){
86935 pErr = sqlite3_str_new(0);
86950 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_INTERNAL, OE_Abort, 0, zErr, 0);
86989 for(i=0; i<p->nOp; i++){
87026 p->aOp = 0;
87045 assert( nOp>0 );
87048 return 0;
87051 for(i=0; i<nOp; i++, aOp++, pOut++){
87055 assert( aOp->p2>=0 );
87056 if( (sqlite3OpcodeProperty[aOp->opcode] & OPFLG_JUMP)!=0 && aOp->p2>0 ){
87061 pOut->p4.p = 0;
87062 pOut->p5 = 0;
87064 pOut->zComment = 0;
87073 sqlite3VdbePrintOp(0, i+p->nOp, &p->aOp[i+p->nOp]);
87087 int addrExplain, /* Address of OP_Explain (or 0) */
87099 memset(pNew, 0, sizeof(ScanStatus));
87124 ScanStatus *pScan = 0;
87126 for(ii=p->nScan-1; ii>=0; ii--){
87129 pScan = 0;
87132 if( addrEnd<0 ) addrEnd = sqlite3VdbeCurrentAddr(p)-1;
87133 for(ii=0; ii<ArraySize(pScan->aAddrRange); ii+=2){
87134 if( pScan->aAddrRange[ii]==0 ){
87156 ScanStatus *pScan = 0;
87158 for(ii=p->nScan-1; ii>=0; ii--){
87161 pScan = 0;
87164 if( addrLoop>0 ) pScan->addrLoop = addrLoop;
87165 if( addrVisit>0 ) pScan->addrVisit = addrVisit;
87177 assert( addr>=0 );
87181 assert( addr>=0 );
87185 assert( addr>=0 || p->db->mallocFailed );
87189 assert( addr>=0 );
87193 assert( p->nOp>0 || p->db->mallocFailed );
87194 if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5;
87230 ** 7 Once 0 8 0
87238 assert( p->aOp[addr].p4type==0 );
87240 sqlite3VdbeGetLastOp(p)->iSrcLine = 0; /* Erase VdbeCoverage() macros */
87254 assert( db!=0 );
87255 if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
87268 assert( db!=0 );
87287 if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4);
87301 if( db->pnBytesFreed==0 ){
87309 if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
87313 if( db->pnBytesFreed==0 ) sqlite3DeleteTable(db, (Table*)p4);
87331 assert( nOp>=0 );
87332 assert( db!=0 );
87361 return pVdbe->pProgram!=0;
87369 if( p->db->mallocFailed ) return 0;
87370 assert( addr>=0 && addr<p->nOp );
87374 pOp->p4.z = 0;
87384 if( p->nOp>0 && p->aOp[p->nOp-1].opcode==op ){
87387 return 0;
87403 if( N==0 || OptimizationDisabled(pParse->db, SQLITE_ReleaseReg) ) return;
87407 if( N<=31 && mask!=0 ){
87408 while( N>0 && (mask&1)!=0 ){
87413 while( N>0 && N<=32 && (mask & MASKBIT32(N-1))!=0 ){
87418 if( N>0 ){
87431 ** If n>=0 then the P4 operand is dynamic, meaning that a copy of
87433 ** A value of n==0 means copy bytes of zP4 up to and including the
87434 ** first null byte. If n>0 then copy n+1 bytes of zP4.
87440 ** If addr<0 then change P4 on the most recently inserted instruction.
87450 pOp->p4type = 0;
87451 pOp->p4.p = 0;
87453 if( n<0 ){
87456 if( n==0 ) n = sqlite3Strlen30(zP4);
87464 assert( p!=0 );
87467 assert( p->aOp!=0 || db->mallocFailed );
87472 assert( p->nOp>0 );
87474 if( addr<0 ){
87478 if( n>=0 || pOp->p4type ){
87487 }else if( zP4!=0 ){
87488 assert( n<0 );
87507 assert( n<=0 );
87511 assert( pP4!=0 || n==P4_DYNAMIC );
87512 assert( p->nOp>0 );
87527 assert( v!=0 );
87528 assert( pIdx!=0 );
87541 assert( p->nOp>0 || p->aOp==0 );
87542 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->pParse->nErr>0 );
87586 ** this routine is a valid pointer. But because the dummy.opcode is 0,
87595 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
87631 ** "PX@PY" -> "r[X..X+Y-1]" or "r[x]" if y is 0 or 1
87632 ** "PX@PY+1" -> "r[X..X+Y]" or "r[x]" if y is 0
87647 sqlite3StrAccumInit(&x, 0, 0, 0, SQLITE_MAX_LENGTH);
87651 int seenCom = 0;
87654 if( strncmp(zSynopsis,"IF ",3)==0 ){
87658 for(ii=0; (c = zSynopsis[ii])!=0; ii++){
87664 if( pOp->zComment && pOp->zComment[0] ){
87672 if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
87675 if( strncmp(zSynopsis+ii+1,"+1",2)==0 ){
87684 }else if( strncmp(zSynopsis+ii+1, "@NP", 3)==0 ){
87690 }else if( x.accError==0 ){
87698 if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){
87713 if( (x.accError & SQLITE_NOMEM)!=0 && db!=0 ){
87726 const char *zOp = 0;
87743 if( pExpr->iColumn<0 ){
87801 char *zP4 = 0;
87804 sqlite3StrAccumInit(&x, 0, 0, 0, SQLITE_MAX_LENGTH);
87809 assert( pKeyInfo->aSortFlags!=0 );
87811 for(j=0; j<pKeyInfo->nKeyField; j++){
87814 if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
87885 u32 n = ai[0]; /* The first element of an INTARRAY is always the
87911 if( (x.accError & SQLITE_NOMEM)!=0 ){
87927 assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
87966 for(i=0; i<nDb; i++){
87967 if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
87974 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
87986 for(i=0; i<nDb; i++){
87987 if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
88007 if( pOut==0 ) pOut = stdout;
88012 zCom = sqlite3VdbeDisplayComment(0, pOp, zP4);
88014 zCom = 0;
88041 ** Mem.szMalloc = 0
88047 assert( db!=0 );
88048 if( N>0 ){
88052 p->szMalloc = 0;
88054 p->pScopyFrom = 0;
88055 p->bScopy = 0;
88058 }while( (--N)>0 );
88074 assert( db!=0 );
88082 assert( (&p[1])==pEnd || p[0].db==p[1].db );
88100 testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel );
88105 p->szMalloc = 0;
88125 if( pFrame->iFrameMagic!=SQLITE_FRAME_MAGIC ) return 0;
88156 int eMode, /* 0: normal. 1: EQP. 2: TablesUsed */
88162 int nSub = 0; /* Number of sub-vdbes seen so far */
88163 SubProgram **apSub = 0; /* Array of sub-vdbes */
88166 Op *aOp = 0; /* Opcode array */
88177 if( pSub!=0 ){
88184 for(i=0; i<nSub; i++){
88205 assert( apSub!=0 );
88206 assert( nSub>0 );
88207 for(j=0; i>=apSub[j]->nOp; j++){
88219 if( pSub!=0 && aOp[i].p4type==P4_SUBPROGRAM ){
88222 for(j=0; j<nSub; j++){
88226 p->rc = sqlite3VdbeMemGrow(pSub, nByte, nSub!=0);
88238 if( eMode==0 ) break;
88243 if( pOp->opcode==OP_OpenWrite && (pOp->p5 & OPFLAG_P2ISREG)==0 ) break;
88270 for(i=0; i<p->nChildCsr; i++){
88274 sqlite3VdbeDeleteAuxData(p->v->db, &p->pAuxData, -1, 0);
88300 Mem *pSub = 0; /* Memory cell hold array of subprogs */
88305 int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0);
88334 pSub = 0;
88355 sqlite3VdbeMemSetInt64(pMem+0, i);
88393 const char *z = 0;
88397 const VdbeOp *pOp = &p->aOp[0];
88398 if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
88414 if( sqlite3IoTrace==0 ) return;
88416 pOp = &p->aOp[0];
88417 if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
88421 for(i=0; sqlite3Isspace(z[i]); i++){}
88422 for(j=0; z[i]; i++){
88431 z[j] = 0;
88467 if( pBuf==0 ){
88488 assert( p!=0 );
88495 assert( p->nOp>0 );
88500 for(i=0; i<p->nMem; i++){
88507 p->nChange = 0;
88510 p->iStatement = 0;
88511 p->nFkConstraint = 0;
88513 for(i=0; i<p->nOp; i++){
88514 p->aOp[i].nExec = 0;
88515 p->aOp[i].nCycle = 0;
88550 assert( p!=0 );
88551 assert( p->nOp>0 );
88552 assert( pParse!=0 );
88557 pParse->pVList = 0;
88559 assert( db->mallocFailed==0 );
88565 /* Each cursor uses a memory cell. The first cursor (cursor 0) can
88566 ** use aMem[0] which is not otherwise used by the VDBE program. Allocate
88571 if( nCursor==0 && nMem>0 ) nMem++; /* Space for aMem[0] even if not used */
88581 assert( x.nFree>=0 );
88591 p->expired = 0;
88603 x.nNeeded = 0;
88604 p->aMem = allocSpace(&x, 0, nMem*sizeof(Mem));
88605 p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
88606 p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
88607 p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
88623 p->nVar = 0;
88624 p->nCursor = 0;
88625 p->nMem = 0;
88632 memset(p->apCsr, 0, nCursor*sizeof(VdbeCursor*));
88647 pCx->colCache = 0;
88648 pCx->pCache = 0;
88651 pCache->pCValue = 0;
88667 assert( pCx->uc.pCursor!=0 );
88675 assert( pVCur->pVtab->nRef>0 );
88689 for(i=0; i<p->nCursor; i++){
88693 p->apCsr[i] = 0;
88715 sqlite3VdbeDeleteAuxData(v->db, &v->pAuxData, -1, 0);
88717 pFrame->pAuxData = 0;
88734 p->pFrame = 0;
88735 p->nFrame = 0;
88737 assert( p->nFrame==0 );
88747 if( p->pAuxData ) sqlite3VdbeDeleteAuxData(p->db, &p->pAuxData, -1, 0);
88748 assert( p->pAuxData==0 );
88768 if( p->aColName==0 ) return;
88797 assert( p->aColName!=0 );
88800 assert( rc!=0 || !zName || (pColName->flags&MEM_Term)!=0 );
88812 int nTrans = 0; /* Number of databases with an active write-transaction
88816 int needXcommit = 0;
88839 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
88848 /* OFF */ 0,
88850 /* MEMORY */ 0,
88851 /* WAL */ 0
88859 && sqlite3PagerIsMemdb(pPager)==0
88889 if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
88892 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
88895 rc = sqlite3BtreeCommitPhaseOne(pBt, 0);
88904 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
88907 rc = sqlite3BtreeCommitPhaseTwo(pBt, 0);
88922 char *zSuper = 0; /* File-name for the super-journal */
88923 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
88924 sqlite3_file *pSuperJrnl = 0;
88925 i64 offset = 0;
88927 int retryCount = 0;
88932 zSuper = sqlite3MPrintf(db, "%.4c%s%.16c", 0,zMainFile,0);
88933 if( zSuper==0 ) return SQLITE_NOMEM_BKPT;
88940 sqlite3OsDelete(pVfs, zSuper, 0);
88949 (iRandom>>8)&0xffffff, iRandom&0xff);
88960 SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_SUPER_JOURNAL, 0
88974 for(i=0; i<db->nDb; i++){
88978 if( zFile==0 ){
88981 assert( zFile[0]!=0 );
88986 sqlite3OsDelete(pVfs, zSuper, 0);
88996 if( 0==(sqlite3OsDeviceCharacteristics(pSuperJrnl)&SQLITE_IOCAP_SEQUENTIAL)
89000 sqlite3OsDelete(pVfs, zSuper, 0);
89015 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
89034 zSuper = 0;
89048 for(i=0; i<db->nDb; i++){
89076 int cnt = 0;
89077 int nWrite = 0;
89078 int nRead = 0;
89083 if( p->readOnly==0 ) nWrite++;
89113 assert( db->nStatement>0 );
89116 for(i=0; i<db->nDb; i++){
89132 p->iStatement = 0;
89173 if( (deferred && (db->nDeferredCons+db->nDeferredImmCons)>0)
89174 || (!deferred && p->nFkConstraint>0)
89179 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)==0 ) return SQLITE_ERROR;
89230 int eStatementOp = 0;
89238 mrc = p->rc & 0xff;
89244 mrc = isSpecialError = 0;
89269 p->nChange = 0;
89276 (void)sqlite3VdbeCheckFk(p, 0);
89287 && db->nVdbeWrite==(p->readOnly==0)
89314 p->nChange = 0;
89316 db->nDeferredCons = 0;
89317 db->nDeferredImmCons = 0;
89322 p->nChange = 0;
89325 p->nChange = 0;
89327 db->nStatement = 0;
89328 }else if( eStatementOp==0 ){
89337 p->nChange = 0;
89350 if( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ){
89353 p->zErrMsg = 0;
89358 p->nChange = 0;
89369 sqlite3VdbeSetChanges(db, 0);
89371 p->nChange = 0;
89384 assert( db->nVdbeWrite>=0 );
89399 assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 );
89426 if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db);
89444 if( sqlite3GlobalConfig.xSqllog && v->rc==SQLITE_OK && v->zSql && v->pc>=0 ){
89446 assert( v->db->init.busy==0 );
89489 if( p->pc>=0 ){
89503 if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
89505 for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
89510 p->zErrMsg = 0;
89512 p->pResultRow = 0;
89514 p->nWrite = 0;
89524 for(i=0; i<p->nOp; i++){
89529 char c, pc = 0;
89531 for(i=0; (c = p->zSql[i])!=0; i++){
89538 for(i=0; i<p->nOp; i++){
89545 cnt>0 ? cycles/cnt : 0
89588 ** function parameter corresponds to bit 0 etc.).
89593 if( (iOp<0)
89595 && pAux->iAuxArg>=0
89620 assert( db!=0 );
89621 assert( p->db==0 || p->db==db );
89651 for(i=0; i<p->nScan; i++){
89665 assert( p!=0 );
89667 assert( db!=0 );
89670 if( db->pnBytesFreed==0 ){
89671 assert( p->ppVPrev!=0 );
89693 rc = sqlite3BtreeTableMoveto(p->uc.pCursor, p->movetoTarget, 0, &res);
89695 if( res!=0 ) return SQLITE_CORRUPT_BKPT;
89699 p->deferredMoveto = 0;
89714 assert( p->uc.pCursor!=0 );
89758 ** 0 0 NULL
89766 ** 8 0 Integer constant 0
89767 ** 9 0 Integer constant 1
89772 ** The 8 and 9 types were added in 3.3.0, file format 4. Prior versions
89776 #if 0 /* Inlined into the OP_MakeRecord opcode */
89792 assert( pLen!=0 );
89794 *pLen = 0;
89795 return 0;
89799 # define MAX_6BYTE ((((i64)0x00008000)<<32)-1)
89804 if( i<0 ){
89811 *pLen = 0;
89839 assert( pMem->n>=0 );
89845 return ((n*2) + 12 + ((flags&MEM_Str)!=0));
89853 /* 0 1 2 3 4 5 6 7 8 9 */
89854 /* 0 */ 0, 1, 2, 3, 4, 6, 8, 8, 0, 0,
89855 /* 10 */ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
89929 t = u.i[0];
89930 u.i[0] = u.i[1];
89940 #define ONE_BYTE_INT(x) ((i8)(x)[0])
89941 #define TWO_BYTE_INT(x) (256*(i8)((x)[0])|(x)[1])
89942 #define THREE_BYTE_INT(x) (65536*(i8)((x)[0])|((x)[1]<<8)|(x)[2])
89943 #define FOUR_BYTE_UINT(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
89944 #define FOUR_BYTE_INT(x) (16777216*(i8)((x)[0])|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
89968 testcase( pMem->u.i<0 );
89978 static const u64 t1 = ((u64)0x3ff00000)<<32;
89982 assert( sizeof(r1)==sizeof(t2) && memcmp(&r1, &t2, sizeof(r1))==0 );
90005 return 0;
90016 pMem->n = 0;
90017 pMem->u.nZero = 0;
90021 case 0: { /* Null */
90031 testcase( pMem->u.i<0 );
90039 testcase( pMem->u.i<0 );
90047 testcase( pMem->u.i<0 );
90056 if( buf[0]&0x80 ) pMem->u.i |= 0xffffffff80000000LL;
90059 testcase( pMem->u.i<0 );
90067 testcase( pMem->u.i<0 );
90077 case 8: /* Integer 0 */
90079 /* EVIDENCE-OF: R-12976-22893 Value is the integer 0. */
90118 assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff );
90121 if( !p ) return 0;
90123 assert( pKeyInfo->aSortFlags!=0 );
90147 p->default_rc = 0;
90151 u = 0;
90158 /* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
90159 pMem->szMalloc = 0;
90160 pMem->z = 0;
90197 int i = 0;
90198 int rc = 0;
90204 if( pKeyInfo->db==0 ) return 1;
90207 /* mem1.flags = 0; // Will be initialized by sqlite3VdbeSerialGet() */
90208 VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
90217 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
90223 assert( pKeyInfo->aSortFlags!=0 );
90224 assert( pKeyInfo->nKeyField>0 );
90261 pKeyInfo->nAllField>i ? pKeyInfo->aColl[i] : 0);
90262 if( rc!=0 ){
90263 assert( mem1.szMalloc==0 ); /* See comment below */
90281 assert( mem1.szMalloc==0 );
90283 /* rc==0 here means that one of the keys ran out of fields and
90289 if( desiredResult==0 && rc==0 ) return 1;
90290 if( desiredResult<0 && rc<0 ) return 1;
90291 if( desiredResult>0 && rc>0 ) return 1;
90294 return 0;
90314 int nField = 0;
90322 assert( nKey>=0 );
90361 if( (v1==0 || v2==0) ){
90363 rc = 0;
90379 for(i=0; i<n; i++){
90380 if( z[i] ) return 0;
90399 assert( (pB1->flags & MEM_Zero)==0 || n1==0 );
90400 assert( (pB2->flags & MEM_Zero)==0 || n2==0 );
90471 ** are NULL, return 0.
90483 if( (f1 & f2 & (MEM_Int|MEM_IntReal))!=0 ){
90488 return 0;
90490 if( (f1 & f2 & MEM_Real)!=0 ){
90493 return 0;
90495 if( (f1&(MEM_Int|MEM_IntReal))!=0 ){
90498 if( (f2&MEM_Real)!=0 ){
90500 }else if( (f2&(MEM_Int|MEM_IntReal))!=0 ){
90503 return 0;
90508 if( (f1&MEM_Real)!=0 ){
90509 if( (f2&(MEM_Int|MEM_IntReal))!=0 ){
90524 if( (f1 & MEM_Str)==0 ){
90527 if( (f2 & MEM_Str)==0 ){
90542 return vdbeCompareMemString(pMem1, pMem2, pColl, 0);
90564 case 0:
90566 testcase( aKey[0]&0x80 );
90569 testcase( aKey[0]&0x80 );
90572 testcase( aKey[0]&0x80 );
90575 testcase( aKey[0]&0x80 );
90580 testcase( aKey[0]&0x80 );
90585 testcase( aKey[0]&0x80 );
90611 ** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
90624 int rc = 0; /* Return value */
90635 if( s1<0x80 ){
90640 szHdr1 = aKey1[0];
90645 if( (szHdr1 = aKey1[0])<0x80 ){
90651 i = 0;
90655 return 0; /* Corruption */
90658 VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
90661 assert( pPKey2->pKeyInfo->aSortFlags!=0 );
90662 assert( pPKey2->pKeyInfo->nKeyField>0 );
90675 }else if( serial_type==0 ){
90700 }else if( serial_type==0 ){
90711 assert( rc==0 );
90726 }else if( !(serial_type & 0x01) ){
90736 return 0; /* Corruption */
90748 if( rc==0 ) rc = mem1.n - pRhs->n;
90755 assert( (pRhs->flags & MEM_Zero)==0 || pRhs->n==0 );
90758 if( serial_type<12 || (serial_type & 0x01) ){
90766 return 0; /* Corruption */
90776 if( rc==0 ) rc = nStr - pRhs->n;
90784 if( serial_type==0
90786 || (serial_type==7 && serialGet7(&aKey1[d1], &mem1)!=0)
90788 assert( rc==0 );
90794 if( rc!=0 ){
90797 if( (sortFlags & KEYINFO_ORDER_BIGNULL)==0
90799 !=(serial_type==0 || (pRhs->flags&MEM_Null)))
90805 assert( mem1.szMalloc==0 ); /* See comment below */
90817 return 0; /* Corrupt index */
90824 assert( mem1.szMalloc==0 );
90826 /* rc==0 here means that one or both of the keys ran out of fields and
90840 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
90857 const u8 *aKey = &((const u8*)pKey1)[*(const u8*)pKey1 & 0x3F];
90866 assert( (*(u8*)pKey1)<=0x3F || CORRUPT_DB );
90870 testcase( lhs<0 );
90875 testcase( lhs<0 );
90880 testcase( lhs<0 );
90886 testcase( lhs<0 );
90891 testcase( lhs<0 );
90898 testcase( lhs<0 );
90902 lhs = 0;
90914 case 0: case 7:
90921 assert( pPKey2->u.i == pPKey2->aMem[0].u.i );
90956 assert( pPKey2->aMem[0].flags & MEM_Str );
90957 assert( pPKey2->aMem[0].n == pPKey2->n );
90958 assert( pPKey2->aMem[0].z == pPKey2->u.z );
90964 if( serial_type<0 ){
90970 }else if( !(serial_type & 0x01) ){
90975 int szHdr = aKey1[0];
90980 return 0; /* Corruption */
90985 if( res>0 ){
90987 }else if( res<0 ){
90991 if( res==0 ){
90998 }else if( res>0 ){
91033 int flags = p->aMem[0].flags;
91034 if( p->pKeyInfo->aSortFlags[0] ){
91035 if( p->pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL ){
91045 p->u.i = p->aMem[0].u.i;
91051 if( (flags & (MEM_Real|MEM_IntReal|MEM_Null|MEM_Blob))==0
91052 && p->pKeyInfo->aColl[0]==0
91055 p->u.z = p->aMem[0].z;
91056 p->n = p->aMem[0].n;
91073 i64 nCellKey = 0;
91090 sqlite3VdbeMemInit(&m, db, 0);
91100 testcase( szHdr>0x7fffffff );
91101 assert( m.n>=0 );
91135 testcase( m.szMalloc!=0 );
91157 i64 nCellKey = 0;
91166 /* nCellKey will always be between 0 and 0xffffffff because of the way
91168 if( nCellKey<=0 || nCellKey>0x7fffffff ){
91169 *res = 0;
91172 sqlite3VdbeMemInit(&m, db, 0);
91177 *res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, pUnpacked, 0);
91242 ** 0 instead. Unless it is NULL, apply affinity aff (one of the SQLITE_AFF_*
91248 assert( iVar>0 );
91251 assert( (v->db->flags & SQLITE_EnableQPSG)==0
91252 || (v->db->mDbFlags & DBFLAG_InternalFunc)!=0 );
91253 if( 0==(pMem->flags & MEM_Null) ){
91262 return 0;
91271 assert( iVar>0 );
91272 assert( (v->db->flags & SQLITE_EnableQPSG)==0
91273 || (v->db->mDbFlags & DBFLAG_InternalFunc)!=0 );
91275 v->expmask |= 0x80000000;
91293 if( pCtx->pVdbe==0 ) return 1;
91310 return 0;
91323 assert( (pWalker->u.aMem[pExpr->iTable].flags & MEM_Undefined)==0 );
91341 pVtab->zErrMsg = 0;
91357 assert( db!=0 );
91360 for(i=0; i<nField; i++){
91390 static const u8 fakeSortOrder = 0;
91402 assert( db->pPreUpdate==0 );
91403 memset(&preupdate, 0, sizeof(PreUpdate));
91404 if( HasRowid(pTab)==0 ){
91405 iKey1 = iKey2 = 0;
91415 assert( pCsr!=0 );
91437 db->pPreUpdate = 0;
91444 for(i=0; i<pCsr->nField; i++){
91451 for(i=0; i<pTab->nCol; i++){
91491 return p==0 || p->expired;
91501 if( p->db==0 ){
91505 return 0;
91509 if( p==0 ){
91525 assert( p->startTime>0 );
91526 assert( db->init.busy==0 );
91527 assert( p->zSql!=0 );
91538 p->startTime = 0;
91545 if( ((P)->startTime)>0 ){ invokeProfileCallback(DB,P); }
91561 if( pStmt==0 ){
91590 if( pStmt==0 ){
91617 if( pStmt==0 ){
91625 for(i=0; i<p->nVar; i++){
91629 assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || p->expmask==0 );
91646 assert( p->flags==MEM_Null && p->z==0 );
91647 return 0;
91650 return p->n ? p->z : 0;
91672 return ((pMem->flags & MEM_Subtype) ? pMem->eSubtype : 0);
91678 && zPType!=0
91680 && strcmp(p->u.zPType, zPType)==0
91684 return 0;
91707 SQLITE_BLOB, /* 0x00 (not possible) */
91708 SQLITE_NULL, /* 0x01 NULL */
91709 SQLITE_TEXT, /* 0x02 TEXT */
91710 SQLITE_NULL, /* 0x03 (not possible) */
91711 SQLITE_INTEGER, /* 0x04 INTEGER */
91712 SQLITE_NULL, /* 0x05 (not possible) */
91713 SQLITE_INTEGER, /* 0x06 INTEGER + TEXT */
91714 SQLITE_NULL, /* 0x07 (not possible) */
91715 SQLITE_FLOAT, /* 0x08 FLOAT */
91716 SQLITE_NULL, /* 0x09 (not possible) */
91717 SQLITE_FLOAT, /* 0x0a FLOAT + TEXT */
91718 SQLITE_NULL, /* 0x0b (not possible) */
91719 SQLITE_INTEGER, /* 0x0c (not possible) */
91720 SQLITE_NULL, /* 0x0d (not possible) */
91721 SQLITE_INTEGER, /* 0x0e (not possible) */
91722 SQLITE_NULL, /* 0x0f (not possible) */
91723 SQLITE_BLOB, /* 0x10 BLOB */
91724 SQLITE_NULL, /* 0x11 (not possible) */
91725 SQLITE_TEXT, /* 0x12 (not possible) */
91726 SQLITE_NULL, /* 0x13 (not possible) */
91727 SQLITE_INTEGER, /* 0x14 INTEGER + BLOB */
91728 SQLITE_NULL, /* 0x15 (not possible) */
91729 SQLITE_INTEGER, /* 0x16 (not possible) */
91730 SQLITE_NULL, /* 0x17 (not possible) */
91731 SQLITE_FLOAT, /* 0x18 FLOAT + BLOB */
91732 SQLITE_NULL, /* 0x19 (not possible) */
91733 SQLITE_FLOAT, /* 0x1a (not possible) */
91734 SQLITE_NULL, /* 0x1b (not possible) */
91735 SQLITE_INTEGER, /* 0x1c (not possible) */
91736 SQLITE_NULL, /* 0x1d (not possible) */
91737 SQLITE_INTEGER, /* 0x1e (not possible) */
91738 SQLITE_NULL, /* 0x1f (not possible) */
91739 SQLITE_FLOAT, /* 0x20 INTREAL */
91740 SQLITE_NULL, /* 0x21 (not possible) */
91741 SQLITE_FLOAT, /* 0x22 INTREAL + TEXT */
91742 SQLITE_NULL, /* 0x23 (not possible) */
91743 SQLITE_FLOAT, /* 0x24 (not possible) */
91744 SQLITE_NULL, /* 0x25 (not possible) */
91745 SQLITE_FLOAT, /* 0x26 (not possible) */
91746 SQLITE_NULL, /* 0x27 (not possible) */
91747 SQLITE_FLOAT, /* 0x28 (not possible) */
91748 SQLITE_NULL, /* 0x29 (not possible) */
91749 SQLITE_FLOAT, /* 0x2a (not possible) */
91750 SQLITE_NULL, /* 0x2b (not possible) */
91751 SQLITE_FLOAT, /* 0x2c (not possible) */
91752 SQLITE_NULL, /* 0x2d (not possible) */
91753 SQLITE_FLOAT, /* 0x2e (not possible) */
91754 SQLITE_NULL, /* 0x2f (not possible) */
91755 SQLITE_BLOB, /* 0x30 (not possible) */
91756 SQLITE_NULL, /* 0x31 (not possible) */
91757 SQLITE_TEXT, /* 0x32 (not possible) */
91758 SQLITE_NULL, /* 0x33 (not possible) */
91759 SQLITE_FLOAT, /* 0x34 (not possible) */
91760 SQLITE_NULL, /* 0x35 (not possible) */
91761 SQLITE_FLOAT, /* 0x36 (not possible) */
91762 SQLITE_NULL, /* 0x37 (not possible) */
91763 SQLITE_FLOAT, /* 0x38 (not possible) */
91764 SQLITE_NULL, /* 0x39 (not possible) */
91765 SQLITE_FLOAT, /* 0x3a (not possible) */
91766 SQLITE_NULL, /* 0x3b (not possible) */
91767 SQLITE_FLOAT, /* 0x3c (not possible) */
91768 SQLITE_NULL, /* 0x3d (not possible) */
91769 SQLITE_FLOAT, /* 0x3e (not possible) */
91770 SQLITE_NULL, /* 0x3f (not possible) */
91800 return (pVal->flags&MEM_FromBind)!=0;
91807 if( pOrig==0 ) return 0;
91809 if( pNew==0 ) return 0;
91810 memset(pNew, 0, sizeof(*pNew));
91813 pNew->db = 0;
91819 pNew = 0;
91851 u8 enc, /* Encoding of z. 0 for BLOBs */
91878 if( xDel==0 ){
91886 if( pCtx!=0 ){
91890 assert( pCtx!=0 );
91902 if( pCtx==0 || n<0 ){
91907 assert( n>=0 );
91909 setResultStrOrError(pCtx, z, n, 0, xDel);
91919 if( pCtx==0 ){
91920 invokeValueDestructor(z, xDel, 0);
91925 if( n>0x7fffffff ){
91928 setResultStrOrError(pCtx, z, (int)n, 0, xDel);
91933 if( pCtx==0 ) return;
91940 if( pCtx==0 ) return;
91949 if( pCtx==0 ) return;
91958 if( pCtx==0 ) return;
91965 if( pCtx==0 ) return;
91972 if( pCtx==0 ) return;
91985 if( pCtx==0 ){
91986 invokeValueDestructor(pPtr, xDestructor, 0);
91999 if( pCtx==0 ) return;
92001 #if defined(SQLITE_STRICT_SUBTYPE) && SQLITE_STRICT_SUBTYPE+0!=0
92002 if( pCtx->pFunc!=0
92003 && (pCtx->pFunc->funcFlags & SQLITE_RESULT_SUBTYPE)==0
92015 pOut->eSubtype = eSubtype & 0xff;
92025 if( pCtx==0 ){
92026 invokeValueDestructor(z, xDel, 0);
92041 if( pCtx==0 ){
92042 invokeValueDestructor(z, xDel, 0);
92052 if( n>0x7fffffff ){
92092 if( pCtx==0 ) return;
92093 if( pValue==0 ){
92107 sqlite3_result_zeroblob64(pCtx, n>0 ? n : 0);
92113 if( pCtx==0 ) return SQLITE_MISUSE_BKPT;
92130 if( pCtx==0 ) return;
92145 if( pCtx==0 ) return;
92156 if( pCtx==0 ) return;
92187 for(i=0; i<db->nDb; i++){
92194 if( nEntry>0 && db->xWalCallback && rc==SQLITE_OK ){
92225 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
92240 if( db->nVdbeActive==0 ){
92241 AtomicStore(&db->u1.isInterrupted, 0);
92244 assert( db->nVdbeWrite>0 || db->autoCommit==0
92245 || ((db->nDeferredCons + db->nDeferredImmCons)==0)
92249 if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
92253 assert( p->startTime==0 );
92258 if( p->readOnly==0 ) db->nVdbeWrite++;
92260 p->pc = 0;
92267 ** with version 3.7.0, we changed this so that sqlite3_reset() would
92282 if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
92311 assert( db->mallocFailed==0 );
92319 p->pResultRow = 0;
92326 }else if( rc!=SQLITE_DONE && (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
92338 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ) rc = p->rc;
92343 assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0
92345 || (rc&0xff)==SQLITE_BUSY || rc==SQLITE_MISUSE
92358 int cnt = 0; /* Counter to prevent infinite loop of reprepares */
92375 ** program counter to 0 to ensure that when the statement is
92385 v->zErrMsg = 0;
92391 if( savedPc>=0 ){
92398 assert( v->expired==0 );
92411 if( p==0 ) return 0;
92429 if( p==0 ) return 0;
92452 if( p==0 ) return 0;
92471 ** Implementation of sqlite3_vtab_in_first() (if bNext==0) and
92472 ** sqlite3_vtab_in_next() (if bNext!=0).
92477 int bNext /* 1 for _next(). 0 for _first() */
92482 *ppOut = 0;
92483 if( pVal==0 ) return SQLITE_MISUSE_BKPT;
92484 if( (pVal->flags & MEM_Dyn)==0 || pVal->xDel!=sqlite3VdbeValueListFree ){
92490 assert( pVal->u.zPType!=0 && strcmp(pVal->u.zPType,"ValueList")==0 );
92494 rc = sqlite3BtreeNext(pRhs->pCsr, 0);
92496 int dummy = 0;
92504 memset(&sMem, 0, sizeof(sMem));
92514 if( (pOut->flags & MEM_Ephem)!=0 && sqlite3VdbeMemMakeWriteable(pOut) ){
92530 return valueFromValueList(pVal, ppOut, 0);
92552 assert( p->pVdbe!=0 );
92554 sqlite3_int64 iTime = 0;
92555 sqlite3_int64 *piTime = p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime;
92557 if( *piTime==0 ){
92559 if( rc ) *piTime = 0;
92570 assert( (pMem->flags & MEM_Agg)==0 );
92571 if( nByte<=0 ){
92573 pMem->z = 0;
92579 memset(pMem->z, 0, nByte);
92593 testcase( nByte<0 );
92594 if( (p->pMem->flags & MEM_Agg)==0 ){
92605 ** The left-most argument is 0.
92615 if( pCtx==0 ) return 0;
92619 if( pCtx->pVdbe==0 ) return 0;
92621 assert( pCtx->pVdbe!=0 );
92624 if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
92628 return 0;
92636 ** The left-most argument is 0.
92652 if( pCtx==0 ) return;
92657 if( pVdbe==0 ) goto failed;
92659 assert( pVdbe!=0 );
92663 if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
92667 if( pAuxData==0 ){
92674 if( pCtx->isError==0 ) pCtx->isError = -1;
92710 if( pVm==0 ) return 0;
92720 if( pVm==0 || pVm->pResultRow==0 ) return 0;
92742 /* .u = */ {0},
92743 /* .z = */ (char*)0,
92744 /* .n = */ (int)0,
92746 /* .enc = */ (u8)0,
92747 /* .eSubtype = */ (u8)0,
92748 /* .db = */ (sqlite3*)0,
92749 /* .szMalloc = */ (int)0,
92750 /* .uTemp = */ (u32)0,
92751 /* .zMalloc = */ (char*)0,
92752 /* .xDel = */ (void(*)(void*))0,
92754 /* .pScopyFrom = */ (Mem*)0,
92755 /* .mScopyFlags= */ 0,
92756 /* .bScopy = */ 0,
92773 if( pVm==0 ) return (Mem*)columnNullValue();
92776 if( pVm->pResultRow!=0 && i<pVm->nResColumn && i>=0 ){
92812 assert( p->db!=0 );
92893 /* 0 */ 'a', 'd', 'd', 'r', 0,
92894 /* 5 */ 'o', 'p', 'c', 'o', 'd', 'e', 0,
92895 /* 12 */ 'p', '1', 0,
92896 /* 15 */ 'p', '2', 0,
92897 /* 18 */ 'p', '3', 0,
92898 /* 21 */ 'p', '4', 0,
92899 /* 24 */ 'p', '5', 0,
92900 /* 27 */ 'c', 'o', 'm', 'm', 'e', 'n', 't', 0,
92901 /* 35 */ 'i', 'd', 0,
92902 /* 38 */ 'p', 'a', 'r', 'e', 'n', 't', 0,
92903 /* 45 */ 'n', 'o', 't', 'u', 's', 'e', 'd', 0,
92904 /* 53 */ 'd', 'e', 't', 'a', 'i', 'l', 0
92907 0, 5, 12, 15, 18, 21, 24, 27,
92913 ** xFunc() then return that string. If N is out of range, return 0.
92918 ** 0 The column name as it should be displayed for output
92938 if( pStmt==0 ){
92940 return 0;
92943 if( N<0 ) return 0;
92944 ret = 0;
92947 assert( db!=0 );
92951 if( useType>0 ) goto columnName_end;
92977 assert( db->mallocFailed==0 || db->mallocFailed==1 );
92980 ret = 0;
92993 return columnName(pStmt, N, 0, COLNAME_NAME);
93016 return columnName(pStmt, N, 0, COLNAME_DECLTYPE);
93032 return columnName(pStmt, N, 0, COLNAME_DATABASE);
93046 return columnName(pStmt, N, 0, COLNAME_TABLE);
93060 return columnName(pStmt, N, 0, COLNAME_COLUMN);
93088 ** p!=0
93089 ** p->pVar!=0
93090 ** i>0
93128 assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || p->expmask==0 );
93129 if( p->expmask!=0 && (p->expmask & (i>=31 ? 0x80000000 : (u32)1<<i))!=0 ){
93152 assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
93153 if( zData!=0 ){
93156 if( rc==SQLITE_OK && encoding!=0 ){
93183 if( nData<0 ) return SQLITE_MISUSE_BKPT;
93185 return bindText(pStmt, i, zData, nData, xDel, 0);
93195 return bindText(pStmt, i, zData, nData, xDel, 0);
93202 assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
93216 assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
93227 assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
93243 assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
93325 assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
93339 if( p==0 ) return SQLITE_MISUSE_BKPT;
93345 assert( (n & 0x7FFFFFFF)==n );
93359 return p ? p->nVar : 0;
93370 if( p==0 ) return 0;
93377 ** return 0.
93380 if( p==0 || zName==0 ) return 0;
93397 for(i=0; i<pFrom->nVar; i++){
93423 assert( (pTo->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || pTo->expmask==0 );
93427 assert( (pFrom->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || pFrom->expmask==0 );
93442 return pStmt ? ((Vdbe*)pStmt)->db : 0;
93458 return pStmt ? ((Vdbe*)pStmt)->explain : 0;
93468 if( pStmt==0 ) return SQLITE_MISUSE_BKPT;
93473 }else if( eMode<0 || eMode>2 ){
93475 }else if( (v->prepFlags & SQLITE_PREPARE_SAVESQL)==0 ){
93502 return v!=0 && v->eVdbeState==VDBE_RUN_STATE;
93516 return 0;
93520 if( pStmt==0 ){
93537 || (op!=SQLITE_STMTSTATUS_MEMUSED && (op<0||op>=ArraySize(pVdbe->aCounter)))
93540 return 0;
93546 v = 0;
93551 db->pnBytesFreed = 0;
93556 if( resetFlag ) pVdbe->aCounter[op] = 0;
93566 return p ? p->zSql : 0;
93580 return 0;
93582 char *z = 0;
93600 if( p==0 ) return 0;
93601 if( p->zNormSql==0 && ALWAYS(p->zSql!=0) ){
93625 memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1));
93639 int iStore = 0;
93642 if( db==0 || ppValue==0 ){
93658 if( iStore>=p->pCsr->nField || iStore<0 ){
93669 if( p->pUnpacked==0 ){
93677 rc = sqlite3BtreePayload(p->pCsr->uc.pCursor, 0, nRec, aRec);
93694 if( pCol->iDflt>0 ){
93695 if( p->apDflt==0 ){
93697 assert( sizeof(sqlite3_value*)*UMXV(p->pTab->nCol) < 0x7fffffff );
93700 if( p->apDflt==0 ) goto preupdate_old_out;
93702 if( p->apDflt[iIdx]==0 ){
93703 sqlite3_value *pVal = 0;
93705 assert( p->pTab!=0 && IsOrdinaryTable(p->pTab) );
93708 if( rc==SQLITE_OK && pVal==0 ){
93740 p = db!=0 ? db->pPreUpdate : 0;
93744 return (p ? p->pKeyinfo->nKeyField : 0);
93763 p = db!=0 ? db->pPreUpdate : 0;
93767 return (p ? p->v->nFrame : 0);
93779 p = db!=0 ? db->pPreUpdate : 0;
93796 int iStore = 0;
93799 if( db==0 || ppValue==0 ){
93814 if( iStore>=p->pCsr->nField || iStore<0 ){
93848 assert( sizeof(Mem)*UMXV(p->pCsr->nField) < 0x7fffffff );
93855 assert( iStore>=0 && iStore<p->pCsr->nField );
93857 if( pMem->flags==0 ){
93888 ScanStatus *pScan = 0;
93892 if( p==0 || pOut==0
93907 if( iScan<0 ){
93910 i64 res = 0;
93911 for(ii=0; ii<nOp; ii++){
93915 return 0;
93923 ** ScanStatus structures with ScanStatus.addrLoop set to 0. */
93924 for(idx=0; idx<p->nScan; idx++){
93928 if( iScan<0 ) break;
93933 assert( pScan==0 || pScan==&p->aScan[idx] );
93938 if( pScan->addrLoop>0 ){
93946 if( pScan->addrVisit>0 ){
93971 *(const char**)pOut = 0;
93992 i64 res = 0;
93993 if( pScan->aAddrRange[0]==0 ){
93997 for(ii=0; ii<ArraySize(pScan->aAddrRange); ii+=2){
94000 if( iIns==0 ) break;
94001 if( iIns>0 ){
94008 for(iOp=0; iOp<nOp; iOp++){
94011 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_NCYCLE)==0 ){
94026 return 0;
94038 return sqlite3_stmt_scanstatus_v2(pStmt, iScan, iScanStatusOp, 0, pOut);
94047 for(ii=0; p!=0 && ii<p->nOp; ii++){
94049 pOp->nExec = 0;
94050 pOp->nCycle = 0;
94087 int nTotal = 0;
94090 *pnToken = 0;
94091 while( zSql[0] ){
94093 assert( n>0 && tokenType!=TK_ILLEGAL );
94133 int idx = 0; /* Index of a host parameter */
94145 sqlite3StrAccumInit(&out, 0, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
94151 assert( (zRawSql - zStart) > 0 );
94154 }else if( p->nVar==0 ){
94157 while( zRawSql[0] ){
94159 assert( n>0 );
94162 assert( zRawSql[0] || nToken==0 );
94163 if( nToken==0 ) break;
94164 if( zRawSql[0]=='?' ){
94172 assert( zRawSql[0]==':' || zRawSql[0]=='$' ||
94173 zRawSql[0]=='@' || zRawSql[0]=='#' );
94174 testcase( zRawSql[0]==':' );
94175 testcase( zRawSql[0]=='$' );
94176 testcase( zRawSql[0]=='@' );
94177 testcase( zRawSql[0]=='#' );
94179 assert( idx>0 );
94183 assert( idx>0 && idx<=p->nVar );
94196 memset(&utf8, 0, sizeof(utf8));
94201 out.nAlloc = 0;
94210 while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
94232 for(i=0; i<nOut; i++){
94233 sqlite3_str_appendf(&out, "%02x", pVar->z[i]&0xff);
94346 mftbu %0\n\
94347 cmpw %0,%1\n\
94363 SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
94396 SQLITE_API int sqlite3_search_count = 0;
94408 SQLITE_API int sqlite3_interrupt_count = 0;
94419 SQLITE_API int sqlite3_sort_count = 0;
94430 SQLITE_API int sqlite3_max_blobsize = 0;
94432 if( (p->flags & (MEM_Str|MEM_Blob))!=0 && p->n>sqlite3_max_blobsize ){
94456 SQLITE_API int sqlite3_found_count = 0;
94484 static u64 n = 0;
94501 ** M: 2 - two-way branch (I=0: fall-thru 1: jump )
94502 ** 3 - two-way + NULL (I=0: fall-thru 1: jump 2: NULL )
94503 ** 4 - OP_Jump (I=0: jump p1 1: jump p2 2: jump p3)
94505 ** In other words, if M is 2, then I is either 0 (for fall-through) or
94506 ** 1 (for when the branch is taken). If M is 3, the I is 0 for an
94510 ** When M is 4, that means that an OP_Jump is being run. I is 0, 1, or 2
94518 ** always taken, the flags should be 0x05 since the fall-through and
94520 ** flags should be 0x06 since only the fall-through approach is allowed.
94522 ** Bit 0x08 of the flags indicates an OP_Jump opcode that is only
94523 ** interested in equal or not-equal. In other words, I==0 and I==2
94536 assert( I<=2 ); /* 0: fall through, 1: taken, 2: alternate taken */
94539 /* Transform I from a integer [0,1,2] into a bitmask of [1,2,4] */
94546 assert( (I & mNever)==0 );
94547 if( sqlite3GlobalConfig.xVdbeBranch==0 ) return; /*NO_TEST*/
94551 ** I - Mask of bits 0x07 indicating which cases are are
94552 ** fulfilled by this instance of the jump. 0x01 means
94553 ** fall-thru, 0x02 means taken, 0x04 means NULL. Any
94561 if( M==2 ) I |= 0x04;
94563 I |= 0x08;
94564 if( (mNever&0x08)!=0 && (I&0x05)!=0) I |= 0x05; /*NO_TEST*/
94567 iSrcLine&0xffffff, I, M);
94583 if( ((P)->flags&MEM_Ephem)!=0 \
94613 ** The memory cell for cursor 0 is aMem[0]. The rest are allocated from
94617 Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem;
94620 VdbeCursor *pCx = 0;
94625 assert( iCur>=0 && iCur<p->nCursor );
94628 p->apCsr[iCur] = 0;
94636 assert( (pMem->flags & MEM_Dyn)==0 );
94637 assert( pMem->szMalloc==0 || pMem->z==pMem->zMalloc );
94639 if( pMem->szMalloc>0 ){
94643 if( pMem->zMalloc==0 ){
94644 pMem->szMalloc = 0;
94645 return 0;
94651 memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
94676 return 0==sqlite3Atoi64(pRec->z, piValue, pRec->n, pRec->enc);
94700 if( rc<=0 ) return;
94746 if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
94747 if( (pRec->flags & (MEM_Real|MEM_IntReal))==0 ){
94759 if( 0==(pRec->flags&MEM_Str) ){ /*OPTIMIZATION-IF-FALSE*/
94781 applyNumericAffinity(pMem, 0);
94808 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 );
94809 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
94811 pMem->u.i = 0;
94815 if( rc<=0 ){
94816 if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
94822 }else if( rc==1 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)==0 ){
94837 assert( (pMem->flags & MEM_Null)==0
94838 || pMem->db==0 || pMem->db->mallocFailed );
94849 return 0;
94865 assert( (f & (MEM_Static|MEM_Ephem))==0 );
94868 assert( (f & (MEM_Dyn|MEM_Ephem))==0 );
94871 assert( (f & (MEM_Static|MEM_Dyn))==0 );
94876 for(i=0; i<25 && i<pMem->n; i++){
94877 sqlite3_str_appendf(pStr, "%02X", ((int)pMem->z[i] & 0xFF));
94880 for(i=0; i<25 && i<pMem->n; i++){
94893 assert( (f & (MEM_Static|MEM_Ephem))==0 );
94896 assert( (f & (MEM_Dyn|MEM_Ephem))==0 );
94899 assert( (f & (MEM_Static|MEM_Dyn))==0 );
94904 for(j=0; j<25 && j<pMem->n; j++){
94906 sqlite3_str_appendchar(pStr, 1, (c>=0x20&&c<=0x7f) ? c : '.');
94910 sqlite3_str_appendf(pStr, "(0-term)");
94927 }else if( (p->flags & (MEM_IntReal))!=0 ){
94940 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
94944 if( p->flags & MEM_Subtype ) printf(" subtype=0x%02x", p->eSubtype);
94993 int n = 0;
95012 assert( pOp->p2>0 );
95030 u64 h = 0;
95072 if( len > 4000 && pC->pKeyInfo==0 ){
95085 if( pC->colCache==0 ){
95087 if( pC->pCache==0 ) return SQLITE_NOMEM;
95091 if( pCache->pCValue==0
95099 if( pBuf==0 ) return SQLITE_NOMEM;
95102 pBuf[len] = 0;
95103 pBuf[len+1] = 0;
95104 pBuf[len+2] = 0;
95119 rc = sqlite3VdbeMemSetStr(pDest, pBuf, len, 0,
95126 if( (t&1)!=0 && encoding==SQLITE_UTF8 ){
95127 pDest->z[len] = 0;
95161 int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */
95162 u8 iCompareIsInit = 0; /* iCompare is initialized */
95166 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
95168 int iCompare = 0; /* Result of last comparison */
95169 u64 nVmStep = 0; /* Number of virtual machine steps */
95174 Mem *pIn1 = 0; /* 1st input operand */
95175 Mem *pIn2 = 0; /* 2nd input operand */
95176 Mem *pIn3 = 0; /* 3rd input operand */
95177 Mem *pOut = 0; /* Output operand */
95178 u32 colCacheCtr = 0; /* Column cache counter */
95180 u64 *pnCycle = 0;
95181 int bStmtScanStatus = IS_STMT_SCANSTATUS(db)!=0;
95192 assert( 0 < db->nProgressOps );
95203 assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
95206 assert( p->bIsReader || p->readOnly!=0 );
95207 p->iCurrentTime = 0;
95208 assert( p->explain==0 );
95209 db->busyHandler.nBusy = 0;
95214 if( p->pc==0
95215 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
95222 for(i=0; i<p->nOp; i++){
95227 for(i=0; i<p->nOp; i++){
95231 once = 0;
95250 if( sqlite3NProfileCnt==0 ) *pnCycle -= sqlite3Hwtime();
95273 if( sqlite3_interrupt_count>0 ){
95275 if( sqlite3_interrupt_count==0 ){
95285 if( (opProperty & OPFLG_IN1)!=0 ){
95286 assert( pOp->p1>0 );
95292 if( (opProperty & OPFLG_IN2)!=0 ){
95293 assert( pOp->p2>0 );
95299 if( (opProperty & OPFLG_IN3)!=0 ){
95300 assert( pOp->p3>0 );
95306 if( (opProperty & OPFLG_OUT2)!=0 ){
95307 assert( pOp->p2>0 );
95311 if( (opProperty & OPFLG_OUT3)!=0 ){
95312 assert( pOp->p3>0 );
95367 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell
95408 while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
95409 assert( db->nProgressOps!=0 );
95428 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
95430 assert( VdbeMemDynamic(pIn1)==0 );
95445 ** OP_Return becomes a no-op. If P3 is 0, then register P1 must hold an
95447 ** this opcode is used in combination with OP_BeginSubrtn, and set to 0
95466 VdbeBranchTaken(0, 2);
95476 ** If P2!=0 then the coroutine implementation immediately follows
95483 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
95484 assert( pOp->p2>=0 && pOp->p2<p->nOp );
95485 assert( pOp->p3>=0 && pOp->p3<p->nOp );
95490 if( pOp->p2==0 ) break;
95495 assert( pOp->p2>0 ); /* There are never any jumps to instruction 0 */
95515 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
95518 assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
95540 assert( VdbeMemDynamic(pIn1)==0 );
95562 if( (pIn3->flags & MEM_Null)==0 ) break;
95573 ** or sqlite3_finalize(). For a normal halt, this should be SQLITE_OK (0).
95574 ** For errors, it can be some other value. If P1!=0 then P2 will determine
95597 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
95641 if( pOp->p3>0 && pOp->p4type==P4_NOTUSED ){
95668 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
95669 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
95694 assert( pOp->p4.pI64!=0 );
95724 assert( pOp->p4.z!=0 );
95734 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
95735 assert( VdbeMemDynamic(pOut)==0 );
95736 pOut->szMalloc = 0;
95765 ** if( P3!=0 and reg[P3]==P5 ) reg[P2] := CAST(reg[P2] as BLOB)
95768 assert( pOp->p4.z!=0 );
95776 if( pOp->p3>0 ){
95828 pOut->n = 0;
95830 pOut->uTemp = 0;
95832 while( cnt>0 ){
95837 pOut->n = 0;
95852 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
95868 if( pOp->p4.z==0 ){
95872 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
95887 assert( pOp->p1>0 && pOp->p1<=p->nVar );
95918 assert( n>0 && p1>0 && p2>0 );
95930 pIn1->pScopyFrom = 0;
95953 ** If the 0x0002 bit of P5 is set then also clear the MEM_Subtype flag in the
95954 ** destination. The 0x0001 bit of P5 indicates that this Copy opcode cannot
95955 ** be merged. The 0x0001 bit is used by the query planner and does not
95972 if( (pOut->flags & MEM_Subtype)!=0 && (pOp->p5 & 0x0002)!=0 ){
95976 pOut->pScopyFrom = 0;
95979 if( (n--)==0 ) break;
96022 assert( (pIn1->flags & MEM_Int)!=0 );
96040 if( (rc = sqlite3VdbeCheckFk(p,0))!=SQLITE_OK ){
96057 assert( pOp->p1>0 || CORRUPT_DB );
96066 for(i=0; i<pOp->p2; i++){
96074 pMem[i].pScopyFrom = 0;
96080 db->trace.xV2(SQLITE_TRACE_ROW, db->pTraceArg, p, 0);
96117 if( (flags1 & (MEM_Str|MEM_Blob))==0 ){
96118 if( sqlite3VdbeMemStringify(pIn1,encoding,0) ) goto no_mem;
96120 }else if( (flags1 & MEM_Zero)!=0 ){
96125 if( (flags2 & (MEM_Str|MEM_Blob))==0 ){
96126 if( sqlite3VdbeMemStringify(pIn2,encoding,0) ) goto no_mem;
96128 }else if( (flags2 & MEM_Zero)!=0 ){
96149 pOut->z[nByte]=0;
96150 pOut->z[nByte+1] = 0;
96213 if( (type1 & type2 & MEM_Int)!=0 ){
96222 if( iA==0 ) goto arithmetic_result_is_null;
96228 if( iA==0 ) goto arithmetic_result_is_null;
96236 }else if( ((type1 | type2) & MEM_Null)!=0 ){
96241 if( (type1 & type2 & MEM_Int)!=0 ) goto int_math;
96250 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
96251 if( rA==(double)0 ) goto arithmetic_result_is_null;
96258 if( iA==0 ) goto arithmetic_result_is_null;
96291 ** maximum. The P1 register is initialized to 0 by this instruction.
96300 sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
96358 }else if( iB!=0 ){
96362 if( iB<0 ){
96369 iA = (iA>=0 || op==OP_ShiftLeft) ? 0 : -1;
96377 if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB);
96393 ** To force any register to be an integer, just add 0.
96407 ** without data loss, then jump immediately to P2, or if P2==0
96412 if( (pIn1->flags & MEM_Int)==0 ){
96414 if( (pIn1->flags & MEM_Int)==0 ){
96416 if( pOp->p2==0 ){
96424 VdbeBranchTaken(0, 2);
96495 ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
96539 ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
96593 if( (flags1 & flags3 & MEM_Int)!=0 ){
96614 iCompare = 0;
96617 VdbeBranchTaken(0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
96627 assert( (flags1 & MEM_Cleared)==0 );
96628 assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 || CORRUPT_DB );
96629 testcase( (pOp->p5 & SQLITE_JUMPIFNULL)!=0 );
96630 if( (flags1&flags3&MEM_Null)!=0
96631 && (flags3&MEM_Cleared)==0
96633 res = 0; /* Operands are equal */
96657 applyNumericAffinity(pIn1,0);
96662 applyNumericAffinity(pIn3,0);
96665 }else if( affinity==SQLITE_AFF_TEXT && ((flags1 | flags3) & MEM_Str)!=0 ){
96666 if( (flags1 & MEM_Str)!=0 ){
96668 }else if( (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
96677 if( (flags3 & MEM_Str)!=0 ){
96679 }else if( (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
96688 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
96700 if( res<0 ){
96702 }else if( res==0 ){
96716 VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
96741 for(iAddr = (int)(pOp - aOp) - 1; ALWAYS(iAddr>=0); iAddr--){
96748 VdbeBranchTaken(iCompare==0, 2);
96749 if( iCompare==0 ) goto jump_to_p2;
96806 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ){
96807 aPermute = 0;
96813 assert( aPermute!=0 );
96817 assert( n>0 );
96818 assert( pKeyInfo!=0 );
96823 int k, mx = 0;
96824 for(k=0; k<n; k++) if( aPermute[k]>(u32)mx ) mx = aPermute[k];
96825 assert( p1>0 && p1+mx<=(p->nMem+1 - p->nCursor)+1 );
96826 assert( p2>0 && p2+mx<=(p->nMem+1 - p->nCursor)+1 );
96828 assert( p1>0 && p1+n<=(p->nMem+1 - p->nCursor)+1 );
96829 assert( p2>0 && p2+n<=(p->nMem+1 - p->nCursor)+1 );
96832 for(i=0; i<n; i++){
96868 if( iCompare<0 ){
96869 VdbeBranchTaken(0,4); pOp = &aOp[pOp->p1 - 1];
96870 }else if( iCompare==0 ){
96884 ** If either P1 or P2 is 0 (false) then the result is 0 even if
96900 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
96901 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
96906 static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
96909 static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
96929 ** boolean (a 0 or 1) in register P2. Or if the value in register P1 is
96936 ** <li> If P3==0 and P4==0 then r[P2] := r[P1] IS TRUE
96938 ** <li> If P3==0 and P4==1 then r[P2] := r[P1] IS NOT TRUE
96939 ** <li> If P3==1 and P4==0 then r[P2] := r[P1] IS NOT FALSE
96944 assert( pOp->p4.i==0 || pOp->p4.i==1 );
96945 assert( pOp->p3==0 || pOp->p3==1 );
96961 if( (pIn1->flags & MEM_Null)==0 ){
96962 sqlite3VdbeMemSetInt64(pOut, !sqlite3VdbeBooleanValue(pIn1,0));
96980 if( (pIn1->flags & MEM_Null)==0 ){
97012 assert( p->aOp[0].opcode==OP_Init );
97015 if( (p->pFrame->aOnce[iAddr/8] & (1<<(iAddr & 7)))!=0 ){
97021 if( p->aOp[0].p1==pOp->p1 ){
97026 VdbeBranchTaken(0, 2);
97027 pOp->p1 = p->aOp[0].p1;
97040 VdbeBranchTaken(c!=0, 2);
97054 VdbeBranchTaken(c!=0, 2);
97066 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
97067 if( (pIn1->flags & MEM_Null)!=0 ){
97090 ** (0x01) bit. SQLITE_FLOAT is the 0x02 bit. SQLITE_TEXT is 0x04.
97091 ** SQLITE_BLOB is 0x08. SQLITE_NULL is 0x10.
97094 ** when P1>=0. If the database contains a NaN value, this opcode will think
97095 ** that the datatype is REAL when it should be NULL. When P1<0 and the value
97097 ** distinguish between NULL and REAL. The problem only arises then P1>=0.
97110 assert( pOp->p1>=0 || (pOp->p3>=0 && pOp->p3<=(p->nMem+1 - p->nCursor)) );
97111 if( pOp->p1>=0 ){
97113 assert( pC!=0 );
97114 assert( pOp->p3>=0 );
97119 typeMask = 0x04; /* SQLITE_TEXT */
97121 typeMask = 0x08; /* SQLITE_BLOB */
97125 0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x2,
97126 0x01, 0x01, 0x10, 0x10
97128 testcase( serialType==0 );
97144 testcase( typeMask==0x01 );
97145 testcase( typeMask==0x02 );
97146 testcase( typeMask==0x04 );
97147 testcase( typeMask==0x08 );
97148 testcase( typeMask==0x10 );
97153 testcase( typeMask==0x01 );
97154 testcase( typeMask==0x02 );
97155 testcase( typeMask==0x04 );
97156 testcase( typeMask==0x08 );
97157 testcase( typeMask==0x10 );
97159 VdbeBranchTaken( (typeMask & pOp->p5)!=0, 2);
97167 ** Synopsis: r[P2] = 0 OR NULL
97174 if( (aMem[pOp->p1].flags & MEM_Null)!=0
97175 || (aMem[pOp->p3].flags & MEM_Null)!=0
97179 sqlite3VdbeMemSetInt64(aMem + pOp->p2, 0);
97191 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
97192 if( (pIn1->flags & MEM_Null)==0 ){
97210 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
97237 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
97240 if( pC==0 || pC->eCurType!=CURTYPE_BTREE ){
97295 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
97296 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
97301 assert( pC!=0 );
97303 || (pC->eCurType==CURTYPE_PSEUDO && pC->seekResult==0) );
97312 if( pC->eCurType==CURTYPE_PSEUDO && pC->seekResult>0 ){
97331 if( pC->ub.aAltMap && (iMap = pC->ub.aAltMap[1+p2])>0 ){
97352 if( (aOffset[0] = pC->aRow[0])<0x80 ){
97357 pC->nHdrParsed = 0;
97359 if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/
97364 pC->aRow = 0;
97365 pC->szRow = 0;
97376 if( aOffset[0] > 98307 || aOffset[0] > pC->payloadSize ){
97384 ** This branch is taken even if aOffset[0]==0. Such a record is never
97386 ** accept it for historical reasons. When aOffset[0]==0, the code this
97395 testcase( aOffset[0]==0 );
97411 if( pC->iHdrOffset<aOffset[0] ){
97413 if( pC->aRow==0 ){
97414 memset(&sMem, 0, sizeof(sMem));
97415 rc = sqlite3VdbeMemFromBtreeZeroOffset(pC->uc.pCursor,aOffset[0],&sMem);
97427 zEndHdr = zData + aOffset[0];
97430 if( (pC->aType[i] = t = zHdr[0])<0x80 ){
97438 aOffset[++i] = (u32)(offset64 & 0xffffffff);
97449 if( aOffset[0]==0 ){
97450 i = 0;
97453 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
97460 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
97462 t = 0;
97513 if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem;
97518 pDest->z[len] = 0;
97519 pDest->z[len+1] = 0;
97527 if( ((p5 = (pOp->p5 & OPFLAG_BYTELENARG))!=0
97529 || (t>=12 && ((t&1)==0 || p5==OPFLAG_BYTELENARG))
97532 || sqlite3VdbeSerialTypeLen(t)==0
97565 if( aOp[0].p3>0 ){
97566 pOp = &aOp[aOp[0].p3-1];
97611 for(i=0; i<pTab->nCol; i++){
97618 if( (pIn1->flags & MEM_Null)==0 ){
97621 if( (pIn1->flags & MEM_Blob)==0 ) goto vdbe_type_error;
97626 if( (pIn1->flags & MEM_Int)==0 ) goto vdbe_type_error;
97630 if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error;
97635 assert( (pIn1->flags & MEM_IntReal)==0 );
97653 }else if( (pIn1->flags & (MEM_Real|MEM_IntReal))==0 ){
97691 assert( zAffinity!=0 );
97692 assert( pOp->p2>0 );
97693 assert( zAffinity[pOp->p2]==0 );
97697 assert( zAffinity[0]==SQLITE_AFF_NONE || memIsValid(pIn1) );
97698 applyAffinity(pIn1, zAffinity[0], encoding);
97699 if( zAffinity[0]==SQLITE_AFF_REAL && (pIn1->flags & MEM_Int)!=0 ){
97719 if( zAffinity[0]==0 ) break;
97772 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
97775 ** Data(0) is taken from register P1. Data(1) comes from register P1+1
97783 nData = 0; /* Number of bytes of data space */
97784 nHdr = 0; /* Number of bytes of header space */
97785 nZero = 0; /* Number of zero bytes at the end of the record */
97788 assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem+1 - p->nCursor)+1 );
97804 applyAffinity(pRec, zAffinity[0], encoding);
97805 if( zAffinity[0]==SQLITE_AFF_REAL && (pRec->flags & MEM_Int) ){
97812 assert( zAffinity[0]==0 || pRec<=pLast );
97813 }while( zAffinity[0] );
97820 ** at least one field. If P5>0 then it will be one more than the
97823 while( (pLast->flags & MEM_Null)!=0 && nField>pOp->p5 ){
97837 ** 0 NULL
97845 ** 8 Integer constant 0
97872 pRec->uTemp = 0;
97881 if( i<0 ){
97931 assert( pRec->n>=0 );
97933 serial_type = (len*2) + 12 + ((pRec->flags & MEM_Str)!=0);
97998 if( nHdr<0x80 ){
98013 if( serial_type==0 ){
98027 default: zPayload[7] = (u8)(v&0xff); v >>= 8;
98028 zPayload[6] = (u8)(v&0xff); v >>= 8;
98030 case 6: zPayload[5] = (u8)(v&0xff); v >>= 8;
98031 zPayload[4] = (u8)(v&0xff); v >>= 8;
98033 case 4: zPayload[3] = (u8)(v&0xff); v >>= 8;
98035 case 3: zPayload[2] = (u8)(v&0xff); v >>= 8;
98037 case 2: zPayload[1] = (u8)(v&0xff); v >>= 8;
98039 case 1: zPayload[0] = (u8)(v&0xff);
98043 }else if( serial_type<0x80 ){
98045 if( serial_type>=14 && pRec->n>0 ){
98046 assert( pRec->z!=0 );
98053 assert( pRec->z!=0 );
98065 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
98076 ** If P3==0, then an exact count is obtained, which involves visiting
98090 nEntry = 0; /* Not needed. Only used to silence a warning. */
98102 ** on the value of P1. To open a new savepoint set P1==0 (SAVEPOINT_BEGIN).
98122 assert( db->pSavepoint==0 || db->autoCommit==0 );
98124 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
98129 if( db->nVdbeWrite>0 ){
98143 assert( db->autoCommit==0 || db->nVTrans==0 );
98158 db->autoCommit = 0;
98173 iSavepoint = 0;
98187 }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){
98200 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
98208 db->autoCommit = 0;
98214 db->autoCommit = 0;
98216 db->isTransactionSavepoint = 0;
98222 isSchemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0;
98223 for(ii=0; ii<db->nDb; ii++){
98226 isSchemaChange==0);
98231 isSchemaChange = 0;
98233 for(ii=0; ii<db->nDb; ii++){
98240 sqlite3ExpirePreparedStatements(db, 0);
98289 ** Set the database auto-commit flag to P1 (1 or 0). If P2 is true, roll
98302 assert( desiredAutoCommit==1 || desiredAutoCommit==0 );
98303 assert( desiredAutoCommit==1 || iRollback==0 );
98304 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
98312 }else if( desiredAutoCommit && db->nVdbeWrite>0 ){
98347 /*NOTREACHED*/ assert(0);
98360 ** started. Index 0 is the main database file and index 1 is the
98374 ** If P5!=0 then this opcode also checks the schema cookie against P3
98388 int iMeta = 0;
98391 assert( p->readOnly==0 || pOp->p2==0 );
98392 assert( pOp->p2>=0 && pOp->p2<=2 );
98393 assert( pOp->p1>=0 && pOp->p1<db->nDb );
98396 if( pOp->p2 && (db->flags & (SQLITE_QueryOnly|SQLITE_CorruptRdOnly))!=0 ){
98415 if( (rc&0xff)==SQLITE_BUSY ){
98425 && (db->autoCommit==0 || db->nVdbeRead>1)
98428 if( p->iStatement==0 ){
98429 assert( db->nStatement>=0 && db->nSavepoint>=0 );
98446 assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
98477 /* Set changeCntOn to 0 to prevent the value returned by sqlite3_changes()
98480 p->changeCntOn = 0;
98490 ** P3==3 is the recommended pager cache size, and so forth. P1==0 is
98507 assert( iDb>=0 && iDb<db->nDb );
98508 assert( db->aDb[iDb].pBt!=0 );
98522 ** size, and so forth. P1==0 is the main database file and P1==1 is the
98535 sqlite3VdbeIncrWriteCounter(p, 0);
98537 assert( pOp->p1>=0 && pOp->p1<db->nDb );
98539 assert( p->readOnly==0 );
98541 assert( pDb->pBt!=0 );
98542 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
98557 sqlite3ExpirePreparedStatements(db, 0);
98558 p->expired = 0;
98569 ** P3==0 means the main database, P3==1 means the database used for
98577 ** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
98600 ** The ReopenIdx opcode may only be used with P5==0 or P5==OPFLAG_SEEKEQ
98607 ** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
98631 ** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
98634 ** <li> <b>0x08 OPFLAG_FORDELETE</b>: This cursor is used only to seek
98639 ** <li> <b>0x10 OPFLAG_P2ISREG</b>: Use the content of register P2
98658 assert( pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
98672 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
98675 || p->readOnly==0 );
98682 nField = 0;
98683 pKeyInfo = 0;
98686 assert( iDb>=0 && iDb<db->nDb );
98690 assert( pX!=0 );
98694 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
98699 assert( p2>0 );
98703 assert( (pIn2->flags & MEM_Int)!=0 );
98713 wrFlag = 0;
98714 assert( (pOp->p5 & OPFLAG_P2ISREG)==0 );
98724 assert( pOp->p1>=0 );
98725 assert( nField>=0 );
98726 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
98728 if( pCur==0 ) goto no_mem;
98772 if( pCx==0 ) goto no_mem;
98804 ** The cursor points to a BTree table if P4==0 and to a BTree index
98805 ** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
98836 assert( pOp->p1>=0 );
98837 assert( pOp->p2>=0 );
98838 if( pOp->p3>0 ){
98841 assert( pOp->p2==0 ); /* Only used when number of columns is zero */
98844 aMem[pOp->p3].n = 0;
98853 pCx->seqCount = 0;
98855 rc = sqlite3BtreeClearTable(pCx->ub.pBtx, pCx->pgnoRoot, 0);
98858 if( pCx==0 ) goto no_mem;
98860 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->ub.pBtx,
98864 rc = sqlite3BtreeBeginTrans(pCx->ub.pBtx, 1, 0);
98871 if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
98882 pCx->isTable = 0;
98886 0, pCx->uc.pCursor);
98895 p->apCsr[pOp->p1] = 0; /* Not required; helps with static analysis */
98919 assert( pOp->p1>=0 );
98920 assert( pOp->p2>=0 );
98922 if( pCx==0 ) goto no_mem;
98940 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98943 if( (pC->seqCount++)==0 ){
98963 ** the pseudo-table. If P2 is 0 or negative then the pseudo-cursor
98969 assert( pOp->p1>=0 );
98970 assert( pOp->p3>=0 );
98972 if( pCx==0 ) goto no_mem;
98981 assert( pOp->p5==0 );
98991 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98993 p->apCsr[pOp->p1] = 0;
99119 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99120 assert( pOp->p2!=0 );
99122 assert( pC!=0 );
99128 assert( pC->uc.pCursor!=0 );
99130 eqOnly = 0;
99131 pC->nullRow = 0;
99136 pC->deferredMoveto = 0;
99141 assert( sqlite3BtreeCursorHasHint(pC->uc.pCursor, BTREE_SEEK_EQ)==0
99150 applyNumericAffinity(pIn3, 0);
99158 if( (newType & (MEM_Int|MEM_IntReal))==0 ){
99160 if( (newType & MEM_Real)==0 ){
99179 if( c>0 ){
99182 assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) );
99183 if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--;
99188 else if( c<0 ){
99191 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
99192 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
99195 rc = sqlite3BtreeTableMoveto(pC->uc.pCursor, (u64)iKey, 0, &res);
99212 assert( pOp[1].p1==pOp[0].p1 );
99213 assert( pOp[1].p2==pOp[0].p2 );
99214 assert( pOp[1].p3==pOp[0].p3 );
99215 assert( pOp[1].p4.i==pOp[0].p4.i );
99220 assert( nField>0 );
99241 for(i=0; i<r.nField; i++){
99243 if( i>0 ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
99247 r.eqSeen = 0;
99252 if( eqOnly && r.eqSeen==0 ){
99253 assert( res!=0 );
99261 if( res<0 || (res==0 && oc==OP_SeekGT) ){
99262 res = 0;
99263 rc = sqlite3BtreeNext(pC->uc.pCursor, 0);
99273 res = 0;
99277 if( res>0 || (res==0 && oc==OP_SeekLT) ){
99278 res = 0;
99279 rc = sqlite3BtreePrevious(pC->uc.pCursor, 0);
99296 assert( pOp->p2>0 );
99297 VdbeBranchTaken(res!=0,2);
99343 ** row. If This.P5 is false (0) then a jump is made to SeekGE.P2. If
99344 ** This.P5 is true (non-zero) then a jump is made to This.P2. The P5==0
99346 ** the IN constraint. The jump to SeekGE.P2 ends the loop. The P5!=0 case
99373 ** jump to SeekOP.P2 if This.P5==0 or to This.P2 if This.P5>0.
99389 if( pOp->p5==0 ){
99404 assert( pOp->p1>0 );
99406 assert( pC!=0 );
99421 r.default_rc = 0;
99426 for(i=0; i<r.nField; i++){
99432 res = 0; /* Not needed. Only used to silence a warning. */
99436 if( res>0 && pOp->p5==0 ){
99448 if( res>=0 ){
99459 if( nStep<=0 ){
99465 VdbeBranchTaken(0,3);
99470 rc = sqlite3BtreeNext(pC->uc.pCursor, 0);
99501 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99503 assert( pC!=0 );
99532 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99534 VdbeBranchTaken(pCur==0 || pCur->nullRow, 2);
99535 if( pCur==0 || pCur->nullRow ){
99544 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
99545 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
99561 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
99562 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
99611 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
99612 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
99633 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99635 assert( pC!=0 );
99658 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99661 assert( pC!=0 );
99667 assert( pC->uc.pCursor!=0 );
99668 assert( pC->isTable==0 );
99670 if( r.nField>0 ){
99673 r.default_rc = 0;
99676 for(ii=0; ii<r.nField; ii++){
99678 assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
99691 if( pIdxKey==0 ) goto no_mem;
99693 pIdxKey->default_rc = 0;
99700 alreadyExists = (pC->seekResult==0);
99702 pC->deferredMoveto = 0;
99705 VdbeBranchTaken(alreadyExists!=0,2);
99716 for(ii=0; ii<r.nField; ii++){
99723 VdbeBranchTaken(0,2);
99737 ** Or, if P2 is 0, raise an SQLITE_CORRUPT error. If P1 does contain
99760 ** rowid P3 then jump immediately to P2. Or, if P2 is 0, raise an
99789 if( (pIn3->flags & (MEM_Int|MEM_IntReal))==0 ){
99795 Mem x = pIn3[0];
99797 if( (x.flags & MEM_Int)==0 ) goto jump_to_p2;
99805 assert( (pIn3->flags & MEM_Int)!=0 || pOp->opcode==OP_SeekRowid );
99806 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99810 assert( pC!=0 );
99817 assert( pCrsr!=0 );
99818 res = 0;
99819 rc = sqlite3BtreeTableMoveto(pCrsr, iKey, 0, &res);
99820 assert( rc==SQLITE_OK || res==0 );
99822 pC->nullRow = 0;
99824 pC->deferredMoveto = 0;
99825 VdbeBranchTaken(res!=0,2);
99827 if( res!=0 ){
99829 if( pOp->p2==0 ){
99848 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99849 assert( p->apCsr[pOp->p1]!=0 );
99865 ** If P3>0 then P3 is a register in the root frame of this VDBE that holds
99882 v = 0;
99883 res = 0;
99885 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99887 assert( pC!=0 );
99890 assert( pC->uc.pCursor!=0 );
99908 # define MAX_ROWID 0x7fffffff
99910 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
99911 ** Others complain about 0x7ffffffffffffffffLL. The following macro seems
99914 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
99938 assert( pOp->p3>0 );
99954 assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
99970 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
99972 cnt = 0;
99977 0, &res))==SQLITE_OK)
99978 && (res==0)
99981 if( res==0 ){
99985 assert( v>0 ); /* EV: R-40812-03570 */
99987 pC->deferredMoveto = 0;
100035 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
100041 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100044 assert( pC!=0 );
100046 assert( pC->deferredMoveto==0 );
100047 assert( pC->uc.pCursor!=0 );
100060 assert( pC->iDb>=0 );
100065 pTab = 0;
100066 zDb = 0;
100075 if( db->xUpdateCallback==0 || pTab->aCol==0 ){
100077 pTab = 0;
100083 assert( (pOp->p5 & OPFLAG_LASTROWID)==0 || (pOp->p5 & OPFLAG_NCHANGE)!=0 );
100088 assert( (pData->flags & (MEM_Blob|MEM_Str))!=0 || pData->n==0 );
100091 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
100095 x.nZero = 0;
100097 x.pKey = 0;
100103 pC->deferredMoveto = 0;
100110 assert( db->xUpdateCallback!=0 );
100111 assert( pTab->aCol!=0 );
100135 assert( pOp[1].opcode==OP_Insert || pOp->p3==0 );
100136 assert( pOp[1].opcode==OP_IdxInsert || pOp->p3>0 );
100140 iKey = pOp->p3 ? aMem[pOp->p3].u.i : 0;
100164 ** If the OPFLAG_NCHANGE (0x01) flag of P2 (NB: P2 not P5) is set, then
100167 ** If the OPFLAG_ISNOOP (0x40) flag of P2 (not P5!) is set, then the
100193 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100195 assert( pC!=0 );
100197 assert( pC->uc.pCursor!=0 );
100198 assert( pC->deferredMoveto==0 );
100204 && pOp->p5==0
100221 assert( pC->iDb>=0 );
100222 assert( pOp->p4.pTab!=0 );
100225 if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){
100229 zDb = 0;
100230 pTab = 0;
100235 assert( db->xPreUpdateCallback==0 || pTab==pOp->p4.pTab );
100238 || HasRowid(pTab)==0
100251 assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_AUXDELETE))==0 );
100256 if( p->pFrame==0 ){
100257 if( pC->isEphemeral==0
100258 && (pOp->p5 & OPFLAG_AUXDELETE)==0
100259 && (pC->wrFlag & OPFLAG_FORDELETE)==0
100272 pC->seekResult = 0;
100278 if( db->xUpdateCallback && ALWAYS(pTab!=0) && HasRowid(pTab) ){
100281 assert( pC->iDb>=0 );
100291 ** Then the VMs internal change counter resets to 0.
100296 p->nChange = 0;
100325 res = 0;
100327 VdbeBranchTaken(res!=0,2);
100353 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100374 ** If P3!=0 then this opcode is allowed to make an ephemeral pointer
100378 ** position in order that they can write to the same table. If P3==0
100379 ** then a copy of the data is made into memory. P3!=0 is faster, but
100380 ** P3==0 is safer.
100382 ** If P3!=0 then the content of the P2 register is unsuitable for use
100394 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100396 assert( pC!=0 );
100398 assert( isSorter(pC)==0 );
100399 assert( pC->nullRow==0 );
100400 assert( pC->uc.pCursor!=0 );
100411 assert( pC->deferredMoveto==0 );
100418 testcase( n==0 );
100444 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100446 assert( pC!=0 );
100455 assert( pC->uc.pVCur!=0 );
100465 assert( pC->uc.pCursor!=0 );
100490 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100492 if( pC==0 ){
100496 if( pC==0 ) goto no_mem;
100497 pC->seekResult = 0;
100505 assert( pC->uc.pCursor!=0 );
100509 if( pC->seekOp==0 ) pC->seekOp = OP_NullRow;
100528 ** If the table or index is empty and P2>0, then jump immediately to P2.
100529 ** If P2 is 0 or if the table or index is not empty, fall through
100542 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100544 assert( pC!=0 );
100547 res = 0;
100548 assert( pCrsr!=0 );
100553 assert( pOp->p2==0 );
100561 pC->deferredMoveto = 0;
100564 if( pOp->p2>0 ){
100565 VdbeBranchTaken(res!=0,2);
100585 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100590 assert( pC!=0 );
100595 if( res!=0 ){
100599 assert( sz>0 );
100603 VdbeBranchTaken(res!=0,2);
100660 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100661 assert( pOp->p5==0 );
100662 assert( pOp->p2>=0 && pOp->p2<p->nOp );
100665 assert( pC!=0 );
100678 pC->deferredMoveto = 0;
100683 if( pOp->p2>0 ){
100684 VdbeBranchTaken(res!=0,2);
100706 ** omitted if that index had been unique. P3 is usually 0. P3 is
100707 ** always either 0 or 1.
100731 ** omitted if that index had been unique. P3 is usually 0. P3 is
100732 ** always either 0 or 1.
100753 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100754 assert( pOp->p5==0
100758 assert( pC!=0 );
100759 assert( pC->deferredMoveto==0 );
100768 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100769 assert( pOp->p5==0
100773 assert( pC!=0 );
100774 assert( pC->deferredMoveto==0 );
100786 pC->nullRow = 0;
100831 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100834 assert( pC!=0 );
100840 assert( pC->isTable==0 );
100849 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
100851 assert( pC->deferredMoveto==0 );
100867 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100870 assert( pC!=0 );
100874 assert( pC->isTable==0 );
100903 assert( pOp->p3>0 );
100904 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem+1 - p->nCursor)+1 );
100905 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100907 assert( pC!=0 );
100911 assert( pCrsr!=0 );
100914 r.default_rc = 0;
100918 if( res==0 ){
100925 assert( pC->deferredMoveto==0 );
100927 pC->seekResult = 0;
100965 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100967 assert( pC!=0 );
100969 assert( pC->uc.pCursor!=0 );
100970 assert( pC->isTable==0 || IsNullCursor(pC) );
100971 assert( pC->deferredMoveto==0 );
100984 rowid = 0; /* Not needed. Only used to silence a warning. */
100990 assert( pOp->p3>=0 && pOp->p3<p->nCursor );
100992 assert( pTabCur!=0 );
100994 assert( pTabCur->uc.pCursor!=0 );
100996 pTabCur->nullRow = 0;
101000 assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 );
101025 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
101086 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
101088 assert( pC!=0 );
101091 assert( pC->uc.pCursor!=0);
101092 assert( pC->deferredMoveto==0 );
101101 r.default_rc = 0;
101107 for(i=0; i<r.nField; i++){
101116 i64 nCellKey = 0;
101124 /* nCellKey will always be between 0 and 0xffffffff because of the way
101126 if( nCellKey<=0 || nCellKey>0x7fffffff ){
101130 sqlite3VdbeMemInit(&m, db, 0);
101133 res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, &r, 0);
101146 VdbeBranchTaken(res>0,2);
101148 if( res>0 ) goto jump_to_p2;
101157 ** The table being destroyed is in the main database file if P3==0. If
101183 sqlite3VdbeIncrWriteCounter(p, 0);
101184 assert( p->readOnly==0 );
101195 iMoved = 0; /* Not needed. Only to silence a warning. */
101201 if( iMoved!=0 ){
101204 assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 );
101218 ** The table being cleared is in the main database file if P2==0. If
101232 sqlite3VdbeIncrWriteCounter(p, 0);
101233 nChange = 0;
101234 assert( p->readOnly==0 );
101239 if( pOp->p3>0 ){
101260 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
101262 assert( pC!=0 );
101277 ** Allocate a new b-tree in the main database file if P1==0 or in the
101287 sqlite3VdbeIncrWriteCounter(p, 0);
101289 pgno = 0;
101291 assert( pOp->p1>=0 && pOp->p1<db->nDb );
101293 assert( p->readOnly==0 );
101295 assert( pDb->pBt!=0 );
101308 ** 0x0001 Disable Auth and Trace callbacks while the statements
101311 ** 0x0002 Set db->nAnalysisLimit to P2 while the statements in
101323 sqlite3VdbeIncrWriteCounter(p, 0);
101325 zErr = 0;
101331 if( pOp->p1 & 0x0001 ){
101333 db->xAuth = 0;
101335 db->mTrace = 0;
101337 if( pOp->p1 & 0x0002 ){
101340 rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
101376 for(iDb=0; iDb<db->nDb; iDb++){
101382 assert( iDb>=0 && iDb<db->nDb );
101385 || (CORRUPT_DB && (db->flags & SQLITE_NoSchemaError)!=0) );
101388 if( pOp->p4.z==0 ){
101393 p->expired = 0;
101401 initData.mInitFlags = 0;
101406 if( zSql==0 ){
101409 assert( db->init.busy==0 );
101412 initData.nInitRow = 0;
101414 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
101416 if( rc==SQLITE_OK && initData.nInitRow==0 ){
101423 db->init.busy = 0;
101444 assert( pOp->p1>=0 && pOp->p1<db->nDb );
101460 sqlite3VdbeIncrWriteCounter(p, 0);
101474 sqlite3VdbeIncrWriteCounter(p, 0);
101488 sqlite3VdbeIncrWriteCounter(p, 0);
101525 assert( nRoot>0 );
101526 assert( aRoot!=0 );
101527 assert( aRoot[0]==(Pgno)nRoot );
101528 assert( pOp->p1>0 && (pOp->p1+1)<=(p->nMem+1 - p->nCursor) );
101530 assert( (pnErr->flags & MEM_Int)!=0 );
101531 assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
101538 if( nErr==0 ){
101539 assert( z==0 );
101564 assert( (pIn2->flags & MEM_Int)!=0 );
101565 if( (pIn1->flags & MEM_Blob)==0 ){
101585 assert( (pIn1->flags & MEM_Blob)==0 || sqlite3VdbeMemIsRowSet(pIn1) );
101586 if( (pIn1->flags & MEM_Blob)==0
101587 || sqlite3RowSetNext((RowSet*)pIn1->z, &val)==0
101595 VdbeBranchTaken(0,2);
101613 ** must have P4==0, the final set must have P4==-1, and for all other sets
101614 ** must have P4>0.
101616 ** This allows optimizations: (a) when P4==0 there is no need to test
101636 if( (pIn1->flags & MEM_Blob)==0 ){
101641 assert( iSet==-1 || iSet>=0 );
101644 VdbeBranchTaken(exists!=0,2);
101647 if( iSet>=0 ){
101685 assert( pProgram->nOp>0 );
101714 if( (pRt->flags&MEM_Blob)==0 ){
101721 assert( nMem>0 );
101722 if( pProgram->nCsr==0 ) nMem++;
101761 || (pProgram->nCsr==0 && pProgram->nMem+1==pFrame->nChildMem) );
101771 assert( pFrame->pAuxData==0 );
101773 p->pAuxData = 0;
101774 p->nChange = 0;
101781 memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
101789 for(i=0; i<p->nMem; i++){
101790 aMem[i].pScopyFrom = 0; /* Prevent false-positive AboutToChange() errs */
101846 ** Synopsis: if fkctr[P1]==0 goto P2
101859 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
101860 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
101862 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
101863 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
101901 ** Synopsis: if r[P1]>0 then r[P1]-=P3, goto P2
101913 VdbeBranchTaken( pIn1->u.i>0, 2);
101914 if( pIn1->u.i>0 ){
101922 ** Synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)
101947 if( x<=0 || sqlite3AddInt64(&x, pIn3->u.i>0?pIn3->u.i:0) ){
101963 ** Synopsis: if r[P1]!=0 then r[P1]--, goto P2
101973 VdbeBranchTaken(pIn1->u.i<0, 2);
101975 if( pIn1->u.i>0 ) pIn1->u.i--;
101982 ** Synopsis: if (--r[P1])==0 goto P2
101991 VdbeBranchTaken(pIn1->u.i==0, 2);
101992 if( pIn1->u.i==0 ) goto jump_to_p2;
102022 ** Execute the xStep (if P1==0) or xInverse (if P1!=0) function for an
102044 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
102045 assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) );
102057 if( pCtx==0 ) goto no_mem;
102062 pCtx->pMem = 0;
102066 pCtx->skipFlag = 0;
102067 pCtx->isError = 0;
102073 /* OP_AggInverse must have P1==1 and OP_AggStep must have P1==0 */
102093 assert( pMem->uTemp==0x1122e0e3 );
102096 pMem->uTemp = 0x1122e0e3;
102106 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
102110 for(i=0; i<pCtx->argc; i++){
102118 assert( pCtx->isError==0 );
102119 assert( pCtx->skipFlag==0 );
102128 if( pCtx->isError>0 ){
102136 pCtx->skipFlag = 0;
102140 pCtx->isError = 0;
102144 assert( pCtx->skipFlag==0 );
102177 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
102178 assert( pOp->p3==0 || pOp->opcode==OP_AggValue );
102180 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
102207 ** RESTART, or TRUNCATE. Write 1 or 0 into mem[P3] if the checkpoint returns
102219 assert( p->readOnly==0 );
102220 aRes[0] = 0;
102231 aRes[0] = 1;
102233 for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){
102271 assert( pOp->p1>=0 && pOp->p1<db->nDb );
102272 assert( p->readOnly==0 );
102288 && (sqlite3Strlen30(zFilename)==0 /* Temp file */
102349 ** Vacuum the entire database P1. P1 is 0 for "main", and 2 or more
102357 assert( p->readOnly==0 );
102359 pOp->p2 ? &aMem[pOp->p2] : 0);
102375 assert( pOp->p1>=0 && pOp->p1<db->nDb );
102377 assert( p->readOnly==0 );
102397 ** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
102400 ** If P2 is 0, then SQL statements are expired immediately. If P2 is 1,
102407 assert( pOp->p2==0 || pOp->p2==1 );
102423 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
102425 assert( pC!=0 );
102438 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
102440 assert( pC!=0 );
102454 ** on which the lock is acquired. A readlock is obtained if P3==0 or
102464 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommit) ){
102466 assert( p1>=0 && p1<db->nDb );
102468 assert( isWriteLock==0 || isWriteLock==1 );
102471 if( (rc&0xFF)==SQLITE_LOCKED ){
102512 memset(&sMem, 0, sizeof(sMem));
102516 assert( (aMem[pOp->p2].flags & MEM_Str)!=0 );
102517 assert( (aMem[pOp->p2].flags & MEM_Static)!=0 );
102561 pCur = 0;
102562 pVCur = 0;
102564 if( pVtab==0 || NEVER(pVtab->pModule==0) ){
102577 pCur = allocateCursor(p, pOp->p1, 0, CURTYPE_VTAB);
102604 char *zErr = 0;
102610 assert( pTab!=0 );
102611 assert( pTab->nTabRef>0 );
102613 if( pTab->u.vtab.p==0 ) break;
102615 assert( pVtab!=0 );
102617 assert( pModule!=0 );
102619 assert( pModule->xIntegrity!=0 );
102621 assert( pOp->p1>=0 && pOp->p1<db->nDb );
102653 if( pRhs==0 ) goto no_mem;
102680 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
102702 assert( pCur!=0 );
102709 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
102716 for(i = 0; i<nArg; i++){
102723 pCur->nullRow = 0;
102724 VdbeBranchTaken(res!=0,2);
102753 assert( pCur!=0 );
102754 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
102765 memset(&sContext, 0, sizeof(sContext));
102768 nullFunc.pUserData = 0;
102771 assert( pOp->p5==OPFLAG_NOCHNG || pOp->p5==0 );
102775 pDest->u.nZero = 0;
102781 if( sContext.isError>0 ){
102808 assert( pCur!=0 );
102854 assert( p->readOnly==0 );
102863 if( isLegacy==0 ) db->flags &= ~(u64)SQLITE_LegacyAlter;
102865 p->expired = 0;
102882 ** The argv[0] element (which corresponds to memory cell P3)
102883 ** is the rowid of a row to delete. If argv[0] is NULL then no
102889 ** If P2==1 then no insert is performed. argv[0] is the rowid of
102904 sqlite_int64 rowid = 0;
102911 assert( p->readOnly==0 );
102913 sqlite3VdbeIncrWriteCounter(p, 0);
102915 if( pVtab==0 || NEVER(pVtab->pModule==0) ){
102927 for(i=0; i<nArg; i++){
102938 assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
102941 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
102974 ** do not change the maximum page count value if P3==0.
102984 newMax = 0;
103006 ** argument was constant then bit 0 of P1 is set. This is used to determine
103025 ** argument was constant then bit 0 of P1 is set. This is used to determine
103057 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
103063 for(i=0; i<pCtx->argc; i++){
103069 assert( pCtx->isError==0 );
103074 if( pCtx->isError>0 ){
103079 pCtx->isError = 0;
103083 assert( (pOut->flags&MEM_Str)==0
103094 ** Synopsis: r[P1].subtype = 0
103135 pOut->eSubtype = (u8)(pIn1->u.i & 0xff);
103149 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
103152 assert( pIn1->n>0 );
103185 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
103187 assert( (pIn1->flags & MEM_Blob)!=0 );
103200 if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){
103206 VdbeBranchTaken(0, 2);
103216 ** Operand P1 must be 0x7fffffff and P2 must positive.
103252 assert( pOp->p4.z==0 || strncmp(pOp->p4.z, "-" "- ", 3)==0 );
103254 /* OP_Init is always instruction 0 */
103258 if( (db->mTrace & (SQLITE_TRACE_STMT|SQLITE_TRACE_LEGACY))!=0
103260 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
103281 for(j=0; j<db->nDb; j++){
103282 if( DbMaskTest(p->btreeMask, j)==0 ) continue;
103288 if( (db->flags & SQLITE_SqlTrace)!=0
103289 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
103295 assert( pOp->p2>0 );
103299 if( p->aOp[i].opcode==OP_Once ) p->aOp[i].p1 = 0;
103301 pOp->p1 = 0;
103319 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
103382 assert( pOp->p1>0 );
103386 for(i=0; i<pOp->p2; i++, pMem++){
103387 if( i>=32 || (constMask & MASKBIT32(i))==0 ){
103388 pMem->pScopyFrom = 0;
103438 pnCycle = 0;
103442 pnCycle = 0;
103457 if( rc!=0 ) printf("rc=%d\n",rc);
103464 if( opProperty==0xff ){
103488 if( zTrace==0 ){
103489 if( aOp[0].opcode==OP_Trace ){
103490 zTrace = aOp[0].p4.z;
103492 if( zTrace==0 ) zTrace = "???";
103497 if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){
103502 testcase( sqlite3GlobalConfig.xLog!=0 );
103507 if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){
103511 if( resetSchemaOnFault>0 ){
103522 pnCycle = 0;
103527 pnCycle = 0;
103532 while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
103545 assert( rc!=SQLITE_OK || nExtraDelete==0
103546 || sqlite3_strlike("DELETE%",p->zSql,0)!=0
103633 char *zErr = 0; /* Error message */
103653 VdbeCursor *pC = v->apCsr[0];
103655 assert( pC!=0 );
103657 type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0;
103662 type==0?"null": type==7?"real": "integer"
103666 p->pStmt = 0;
103679 p->pStmt = 0;
103688 assert( rc!=SQLITE_OK || zErr==0 );
103707 int nAttempt = 0;
103710 char *zErr = 0;
103712 Incrblob *pBlob = 0;
103717 if( ppBlob==0 ){
103721 *ppBlob = 0;
103723 if( !sqlite3SafetyCheckOk(db) || zTable==0 || zColumn==0 ){
103727 wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
103736 zErr = 0;
103739 pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
103741 pTab = 0;
103745 pTab = 0;
103748 if( pTab && (pTab->tabFlags&TF_HasGenerated)!=0 ){
103749 pTab = 0;
103755 pTab = 0;
103759 if( pTab==0
103766 sParse.zErrMsg = 0;
103777 if( iCol<0 ){
103789 const char *zFault = 0;
103801 for(j=0; j<pFKey->nCol; j++){
103811 for(j=0; j<pIdx->nKeyCol; j++){
103848 {OP_TableLock, 0, 0, 0}, /* 0: Acquire a read or write lock */
103849 {OP_OpenRead, 0, 0, 0}, /* 1: Open a cursor */
103851 {OP_NotExists, 0, 5, 1}, /* 2: Seek the cursor to rowid=r[1] */
103852 {OP_Column, 0, 0, 1}, /* 3 */
103853 {OP_ResultRow, 1, 0, 0}, /* 4 */
103854 {OP_Halt, 0, 0, 0}, /* 5 */
103869 if( db->mallocFailed==0 ){
103870 assert( aOp!=0 );
103873 aOp[0].opcode = OP_Noop;
103875 aOp[0].p1 = iDb;
103876 aOp[0].p2 = pTab->tnum;
103877 aOp[0].p3 = wrFlag;
103880 if( db->mallocFailed==0 ){
103900 sParse.nVar = 0;
103919 if( rc==SQLITE_OK && db->mallocFailed==0 ){
103925 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : (char*)0), zErr);
103970 if( p==0 ) return SQLITE_MISUSE_BKPT;
103975 if( n<0 || iOffset<0 || ((sqlite3_int64)iOffset+n)>p->nByte ){
103978 }else if( v==0 ){
104007 assert( v->apCsr[0]!=0 );
104008 assert( v->apCsr[0]->eCurType==CURTYPE_BTREE );
104010 v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1, p->iCol
104019 p->pStmt = 0;
104052 return (p && p->pStmt) ? p->nByte : 0;
104070 if( p==0 ) return SQLITE_MISUSE_BKPT;
104074 if( p->pStmt==0 ){
104084 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : (char*)0), zErr);
104091 assert( rc==SQLITE_OK || p->pStmt==0 );
104180 ** A PMA created at this point is known as a "level-0 PMA". Higher levels
104182 ** merging two or more level-0 PMAs together creates a level-1 PMA.
104202 ** "PRAGMA threads=N" with some value of N greater than 0.
104245 #if 0
104251 ** to a level 0 PMA. The purpose of this limit is to prevent various integer
104280 ** If aMemory==0 then each object is allocated separately and the objects
104281 ** are connected using SorterRecord.u.pNext. If aMemory!=0 then all objects
104320 ** currently points to the smallest key value. aTree[0] is unused.
104324 ** aReadr[0] -> Banana
104333 ** aTree[] = { X, 5 0, 5 0, 3, 5, 6 }
104346 ** 5, so aTree[3] is set to 6. Key 0 is smaller than key 6 (Banana<Durian),
104347 ** so the value written into element 1 of the array is 0. As follows:
104349 ** aTree[] = { X, 0 0, 6 0, 3, 5, 6 }
104376 ** Before a background thread is launched, variable bDone is set to 0. Then,
104380 ** 1. When flushing the contents of memory to a level-0 PMA on disk, to
104389 ** In both cases, the effects of the main thread seeing (bDone==0) even
104402 SorterFile file; /* Temp file for level-0 PMAs */
104418 int mxPmaSize; /* Maximum PMA size, in bytes. 0==no limit */
104422 MergeEngine *pMerger; /* Or here, if bUseThreads==0 */
104440 #define SORTER_TYPE_INTEGER 0x01
104441 #define SORTER_TYPE_TEXT 0x02
104450 ** pFd==0 at EOF.
104472 ** There are two types of IncrMerger object - single (bUseThread==0) and
104475 ** A multi-threaded IncrMerger object uses two temporary files - aFile[0]
104478 ** pMerger to populate aFile[0]. It then sets variables within the
104483 ** When the PmaReader reaches the end of aFile[0], it blocks until the
104485 ** the contents of the aFile[0] and aFile[1] variables within this structure,
104486 ** sets the PmaReader fields to read from the new aFile[0] and kicks off
104505 SorterFile aFile[2]; /* aFile[0] for reading, [1] for writing */
104532 ** (VdbeSorter.list.aMemory==0), then the list is always connected using the
104535 ** Or, if using the single large allocation method (VdbeSorter.list.aMemory!=0),
104574 if( pReadr->aMap ) sqlite3OsUnfetch(pReadr->pFd, 0, pReadr->aMap);
104576 memset(pReadr, 0, sizeof(PmaReader));
104608 if( iBuf==0 ){
104618 assert( nRead>0 );
104658 while( nRem>0 ){
104661 u8 *aNext = 0; /* Pointer to buffer to copy data from */
104668 assert( aNext!=0 );
104694 int i = 0, rc;
104698 aVarint[(i++)&0xf] = a[0];
104699 }while( (a[0]&0x80)!=0 );
104721 rc = sqlite3OsFetch(pFd, 0, (int)pFile->iEof, (void**)pp);
104741 assert( pReadr->pIncr==0 || pReadr->pIncr->bEof==0 );
104745 sqlite3OsUnfetch(pReadr->pFd, 0, pReadr->aMap);
104746 pReadr->aMap = 0;
104753 if( rc==SQLITE_OK && pReadr->aMap==0 ){
104756 if( pReadr->aBuffer==0 ){
104758 if( pReadr->aBuffer==0 ) rc = SQLITE_NOMEM_BKPT;
104782 u64 nRec = 0; /* Size of record in bytes */
104790 if( rc==SQLITE_OK && pIncr->bEof==0 ){
104792 pIncr->pTask, pReadr, &pIncr->aFile[0], pIncr->iStartOff
104794 bEof = 0;
104837 assert( pReadr->aAlloc==0 && pReadr->nAlloc==0 );
104838 assert( pReadr->aBuffer==0 );
104839 assert( pReadr->aMap==0 );
104843 u64 nByte = 0; /* Size of PMA in bytes */
104867 if( *pbKey2Cached==0 ){
104914 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
104915 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
104924 if( res==0 ){
104928 if( res==0 ){
104935 assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
104936 if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
104958 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
104959 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
104962 assert( (s1>0 && s1<7) || s1==8 || s1==9 );
104963 assert( (s2>0 && s2<7) || s2==8 || s2==9 );
104967 static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8, 0, 0, 0 };
104970 res = 0;
104971 for(i=0; i<n; i++){
104972 if( (res = v1[i] - v2[i])!=0 ){
104973 if( ((v1[0] ^ v2[0]) & 0x80)!=0 ){
104974 res = v1[0] & 0x80 ? -1 : +1;
104989 assert( res!=0 );
104991 if( res>0 ){
104992 if( *v1 & 0x80 ) res = -1;
104994 if( *v2 & 0x80 ) res = +1;
104998 if( res==0 ){
105004 }else if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
105005 assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
105039 KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
105043 #if SQLITE_MAX_WORKER_THREADS==0
105044 # define nWorker 0
105050 #if SQLITE_MAX_WORKER_THREADS>0
105051 if( sqlite3TempInMemory(db) || sqlite3GlobalConfig.bCoreMutex==0 ){
105052 nWorker = 0;
105070 < 0x7fffffff );
105076 if( pSorter==0 ){
105079 Btree *pBt = db->aDb[0].pBt;
105082 pKeyInfo->db = 0;
105083 if( nField && nWorker==0 ){
105093 for(i=0; i<pSorter->nTask; i++){
105103 mxCache = db->aDb[0].pSchema->cache_size;
105104 if( mxCache<0 ){
105116 if( sqlite3GlobalConfig.bSmallMalloc==0 ){
105117 assert( pSorter->iMemory==0 );
105125 && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
105126 && (pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL)==0
105154 #if SQLITE_MAX_WORKER_THREADS>0
105156 ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
105162 assert( pTask->list.aMemory==0 );
105163 vdbeSorterRecordFree(0, pTask->list.pList);
105171 memset(pTask, 0, sizeof(SortSubtask));
105182 i64 t = 0;
105183 sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
105214 #if SQLITE_MAX_WORKER_THREADS>0
105230 pTask->bDone = 0;
105231 pTask->pThread = 0;
105244 assert( pTask->pThread==0 && pTask->bDone==0 );
105250 ** level-0 PMAs.
105263 for(i=pSorter->nTask-1; i>=0; i--){
105292 pNew = sqlite3FaultSim(100) ? 0 : (MergeEngine*)sqlite3MallocZero(nByte);
105295 pNew->pTask = 0;
105308 for(i=0; i<pMerger->nTree; i++){
105321 #if SQLITE_MAX_WORKER_THREADS>0
105324 if( pIncr->aFile[0].pFd ) sqlite3OsCloseFree(pIncr->aFile[0].pFd);
105339 assert( pSorter->bUseThreads || pSorter->pReader==0 );
105340 #if SQLITE_MAX_WORKER_THREADS>0
105344 pSorter->pReader = 0;
105348 pSorter->pMerger = 0;
105349 for(i=0; i<pSorter->nTask; i++){
105354 if( pSorter->list.aMemory==0 ){
105355 vdbeSorterRecordFree(0, pSorter->list.pList);
105357 pSorter->list.pList = 0;
105358 pSorter->list.szPMA = 0;
105359 pSorter->bUsePMA = 0;
105360 pSorter->iMemory = 0;
105361 pSorter->mxKeysize = 0;
105363 pSorter->pUnpacked = 0;
105377 pCsr->uc.pSorter = 0;
105381 #if SQLITE_MAX_MMAP_SIZE>0
105393 void *p = 0;
105397 sqlite3OsFetch(pFd, 0, (int)nByte, &p);
105398 if( p ) sqlite3OsUnfetch(pFd, 0, p);
105408 ** Otherwise, set *ppFd to 0 and return an SQLite error code.
105417 rc = sqlite3OsOpenMalloc(db->pVfs, 0, ppFd,
105425 if( nExtend>0 ){
105438 if( pTask->pUnpacked==0 ){
105440 if( pTask->pUnpacked==0 ) return SQLITE_NOMEM_BKPT;
105442 pTask->pUnpacked->errCode = 0;
105456 SorterRecord *pFinal = 0;
105458 int bCached = 0;
105460 assert( p1!=0 && p2!=0 );
105467 if( res<=0 ){
105471 if( p1==0 ){
105479 bCached = 0;
105480 if( p2==0 ){
105518 memset(aSlot, 0, sizeof(aSlot));
105524 pNext = 0;
105533 p->u.pNext = 0;
105534 for(i=0; aSlot[i]; i++){
105540 aSlot[i] = 0;
105546 p = 0;
105547 for(i=0; i<ArraySize(aSlot); i++){
105548 if( aSlot[i]==0 ) continue;
105568 memset(p, 0, sizeof(PmaWriter));
105586 while( nRem>0 && p->eFWErr==0 ){
105599 p->iBufStart = p->iBufEnd = 0;
105619 if( p->eFWErr==0 && ALWAYS(p->aBuffer) && p->iBufEnd>p->iBufStart ){
105628 memset(p, 0, sizeof(PmaWriter));
105644 ** Write the current contents of in-memory linked-list pList to a level-0
105669 memset(&writer, 0, sizeof(PmaWriter));
105670 assert( pList->szPMA>0 );
105673 if( pTask->file.pFd==0 ){
105674 rc = vdbeSorterOpenTempFile(db, 0, &pTask->file.pFd);
105676 assert( pTask->file.iEof==0 );
105677 assert( pTask->nPMA==0 );
105692 SorterRecord *pNext = 0;
105702 if( pList->aMemory==0 ) sqlite3_free(p);
105709 assert( rc!=SQLITE_OK || pList->pList==0 );
105737 int bCached = 0;
105741 pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
105742 pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
105744 for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
105747 if( pReadr1->pFd==0 ){
105749 }else if( pReadr2->pFd==0 ){
105772 if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
105774 pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
105775 bCached = 0;
105777 if( pReadr1->pFd ) bCached = 0;
105779 pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
105782 *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
105788 #if SQLITE_MAX_WORKER_THREADS>0
105790 ** The main routine for background threads that write level-0 PMAs.
105795 assert( pTask->bDone==0 );
105800 #endif /* SQLITE_MAX_WORKER_THREADS>0 */
105807 #if SQLITE_MAX_WORKER_THREADS==0
105809 return vdbeSorterListToPMA(&pSorter->aTask[0], &pSorter->list);
105813 SortSubtask *pTask = 0; /* Thread context used to create new PMA */
105828 for(i=0; i<nWorker; i++){
105834 if( rc!=SQLITE_OK || pTask->pThread==0 ) break;
105846 assert( pTask!=0 );
105847 assert( pTask->pThread==0 && pTask->bDone==0 );
105848 assert( pTask->list.pList==0 );
105849 assert( pTask->list.aMemory==0 || pSorter->list.aMemory!=0 );
105855 pSorter->list.pList = 0;
105856 pSorter->list.szPMA = 0;
105870 #endif /* SQLITE_MAX_WORKER_THREADS!=0 */
105891 if( t>0 && t<10 && t!=7 ){
105893 }else if( t>10 && (t & 0x01) ){
105896 pSorter->typeMask = 0;
105904 ** If using the single large allocation mode (pSorter->aMemory!=0), then
105930 pSorter->list.szPMA = 0;
105931 pSorter->iMemory = 0;
105932 assert( rc!=SQLITE_OK || pSorter->list.pList==0 );
105956 if( iListOff>=0 ){
105970 if( pNew==0 ){
105996 assert( pIncr->bEof==0 );
106009 if( pReader->pFd==0 ) break;
106025 #if SQLITE_MAX_WORKER_THREADS>0
106049 ** finished reading the contents of aFile[0]. Its purpose is to "refill"
106050 ** aFile[0] such that the PmaReader should start rereading it from the
106054 ** keys from pIncr->pMerger and repopulating aFile[0].
106058 ** aFile[0] and aFile[1] in place. If the contents of pMerger have not
106067 #if SQLITE_MAX_WORKER_THREADS>0
106072 SorterFile f0 = pIncr->aFile[0];
106073 pIncr->aFile[0] = pIncr->aFile[1];
106078 if( pIncr->aFile[0].iEof==pIncr->iStartOff ){
106088 pIncr->aFile[0] = pIncr->aFile[1];
106089 if( pIncr->aFile[0].iEof==pIncr->iStartOff ){
106110 (sqlite3FaultSim(100) ? 0 : sqlite3MallocZero(sizeof(*pIncr)));
106120 assert( *ppOut!=0 || rc!=SQLITE_OK );
106124 #if SQLITE_MAX_WORKER_THREADS>0
106132 #endif /* SQLITE_MAX_WORKER_THREADS>0 */
106151 assert( iOut<pMerger->nTree && iOut>0 );
106164 if( p1->pFd==0 ){
106166 }else if( p2->pFd==0 ){
106170 int bCached = 0;
106172 assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
106176 if( res<=0 ){
106191 ** SQLITE_MAX_WORKER_THREADS==0). The other values are only used
106194 #define INCRINIT_NORMAL 0
106212 ** already been populated, but that they have not yet populated aFile[0] and
106234 assert( pMerger!=0 );
106237 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
106240 assert( pMerger->pTask==0 );
106244 for(i=0; i<nTree; i++){
106245 if( SQLITE_MAX_WORKER_THREADS>0 && eMode==INCRINIT_ROOT ){
106260 for(i=pMerger->nTree-1; i>0; i--){
106268 ** incremental-reader (pReadr->pIncr!=0). This function serves to open
106306 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
106315 #if SQLITE_MAX_WORKER_THREADS>0
106317 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
106324 if( pTask->file2.pFd==0 ){
106325 assert( pTask->file2.iEof>0 );
106327 pTask->file2.iEof = 0;
106337 #if SQLITE_MAX_WORKER_THREADS>0
106354 if( rc==SQLITE_OK && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) ){
106361 #if SQLITE_MAX_WORKER_THREADS>0
106378 ** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes
106391 #if SQLITE_MAX_WORKER_THREADS>0
106392 assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK );
106406 ** Allocate a new MergeEngine object to merge the contents of nPMA level-0
106429 if( pNew==0 ) rc = SQLITE_NOMEM_BKPT;
106431 for(i=0; i<nPMA && rc==SQLITE_OK; i++){
106432 i64 nDummy = 0;
106440 *ppOut = 0;
106452 ** nPMA<=16 -> TreeDepth() == 0
106457 int nDepth = 0;
106497 if( pReadr->pIncr==0 ){
106499 if( pNew==0 ){
106521 ** that has already written two or more level-0 PMAs to one or more temp
106534 MergeEngine *pMain = 0;
106538 #if SQLITE_MAX_WORKER_THREADS>0
106545 if( pMain==0 ) rc = SQLITE_NOMEM_BKPT;
106549 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
106551 assert( pTask->nPMA>0 || SQLITE_MAX_WORKER_THREADS>0 );
106552 if( SQLITE_MAX_WORKER_THREADS==0 || pTask->nPMA ){
106553 MergeEngine *pRoot = 0; /* Root node of tree for this task */
106555 i64 iReadOff = 0;
106561 int iSeq = 0;
106563 if( pRoot==0 ) rc = SQLITE_NOMEM_BKPT;
106564 for(i=0; i<pTask->nPMA && rc==SQLITE_OK; i += SORTER_MAX_MERGE_COUNT){
106565 MergeEngine *pMerger = 0; /* New level-0 PMA merger */
106566 int nReader; /* Number of level-0 PMAs to merge */
106577 #if SQLITE_MAX_WORKER_THREADS>0
106578 if( pMain!=0 ){
106583 assert( pMain==0 );
106594 pMain = 0;
106611 SortSubtask *pTask0 = &pSorter->aTask[0];
106612 MergeEngine *pMain = 0;
106617 for(i=0; i<pSorter->nTask; i++){
106625 assert( pSorter->bUseThreads==0 || pSorter->nTask>1 );
106628 PmaReader *pReadr = 0;
106634 if( pReadr==0 ) rc = SQLITE_NOMEM_BKPT;
106640 for(iTask=0; iTask<(pSorter->nTask-1); iTask++){
106647 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
106658 assert( p->pIncr==0 || (
106660 && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */
106665 pMain = 0;
106675 pMain = 0;
106702 if( pSorter->bUsePMA==0 ){
106704 *pbEof = 0;
106705 rc = vdbeSorterSort(&pSorter->aTask[0], &pSorter->list);
106726 assert( pSorter->pReader==0 );
106729 *pbEof = 0;
106749 assert( pSorter->bUsePMA || (pSorter->pReader==0 && pSorter->pMerger==0) );
106751 assert( pSorter->pReader==0 || pSorter->pMerger==0 );
106752 assert( pSorter->bUseThreads==0 || pSorter->pReader );
106754 #if SQLITE_MAX_WORKER_THREADS>0
106757 if( rc==SQLITE_OK && pSorter->pReader->pFd==0 ) rc = SQLITE_DONE;
106761 int res = 0;
106762 assert( pSorter->pMerger!=0 );
106763 assert( pSorter->pMerger->pTask==(&pSorter->aTask[0]) );
106770 pFree->u.pNext = 0;
106771 if( pSorter->list.aMemory==0 ) vdbeSorterRecordFree(db, pFree);
106788 #if SQLITE_MAX_WORKER_THREADS>0
106857 if( r2==0 ){
106859 if( r2==0 ) return SQLITE_NOMEM_BKPT;
106866 for(i=0; i<nKeyCol; i++){
106904 int bTablesUsed; /* 2 for tables_used(). 0 for bytecode(). */
106937 int isTabUsed = pAux!=0;
106973 if( pNew==0 ) return SQLITE_NOMEM;
106974 memset(pNew, 0, sizeof(*pNew));
106997 if( pCur==0 ) return SQLITE_NOMEM;
106998 memset(pCur, 0, sizeof(*pCur));
107009 pCur->zP4 = 0;
107015 pCur->pStmt = 0;
107016 pCur->needFinalize = 0;
107017 pCur->zType = 0;
107018 pCur->zSchema = 0;
107019 pCur->zName = 0;
107042 pCur->zP4 = 0;
107045 pCur->zName = 0;
107046 pCur->zType = 0;
107047 pCur->zSchema = 0;
107051 pCur->showSubprograms ? &pCur->sub : 0,
107058 pCur->aOp = 0;
107069 return pCur->aOp==0;
107088 if( i<=2 && pCur->zType==0 ){
107104 if( pCur->zName==0 ){
107118 case 0: /* addr */
107136 if( pCur->zP4==0 ){
107153 assert( aOp[0].opcode==OP_Init );
107154 assert( aOp[0].p4.z==0 || strncmp(aOp[0].p4.z,"-" "- ",3)==0 );
107157 }else if( aOp[0].p4.z!=0 ){
107158 sqlite3_result_text(ctx, aOp[0].p4.z+3, -1, SQLITE_STATIC);
107175 sqlite3_result_int(ctx, 0);
107208 ** idxNum==0 means show all subprograms
107222 pCur->iRowid = 0;
107223 pCur->iAddr = 0;
107224 pCur->showSubprograms = idxNum==0;
107226 if( sqlite3_value_type(argv[0])==SQLITE_TEXT ){
107227 const char *zSql = (const char*)sqlite3_value_text(argv[0]);
107228 if( zSql==0 ){
107231 rc = sqlite3_prepare_v2(pVTab->db, zSql, -1, &pCur->pStmt, 0);
107235 pCur->pStmt = (sqlite3_stmt*)sqlite3_value_pointer(argv[0],"stmt-pointer");
107237 if( pCur->pStmt==0 ){
107265 pIdxInfo->idxNum = 0;
107266 for(i=0, p=pIdxInfo->aConstraint; i<pIdxInfo->nConstraint; i++, p++){
107267 if( p->usable==0 ) continue;
107286 /* iVersion */ 0,
107287 /* xCreate */ 0,
107291 /* xDestroy */ 0,
107299 /* xUpdate */ 0,
107300 /* xBegin */ 0,
107301 /* xSync */ 0,
107302 /* xCommit */ 0,
107303 /* xRollback */ 0,
107304 /* xFindMethod */ 0,
107305 /* xRename */ 0,
107306 /* xSavepoint */ 0,
107307 /* xRelease */ 0,
107308 /* xRollbackTo */ 0,
107309 /* xShadowName */ 0,
107310 /* xIntegrity */ 0
107316 rc = sqlite3_create_module(db, "bytecode", &bytecodevtabModule, 0);
107428 assert( p->readpoint.iOffset==0 || p->readpoint.pChunk!=0 );
107429 if( p->readpoint.iOffset!=iOfst || iOfst==0 ){
107430 sqlite3_int64 iOff = 0;
107439 assert( pChunk!=0 );
107449 iChunkOffset = 0;
107450 } while( nRead>=0 && (pChunk=pChunk->pNext)!=0 && nRead>0 );
107451 p->readpoint.iOffset = pChunk ? iOfst+iAmt : 0;
107477 memset(p, 0, sizeof(MemJournal));
107478 rc = sqlite3OsOpen(copy.pVfs, copy.zJournal, pReal, copy.flags, 0);
107481 i64 iOff = 0;
107526 if( p->nSpill>0 && (iAmt+iOfst)>p->nSpill ){
107542 if( iOfst>0 && iOfst!=p->endpoint.iOffset ){
107545 if( iOfst==0 && p->pFirst ){
107549 while( nWrite>0 ){
107554 assert( pChunk!=0 || iChunkOffset==0 );
107555 if( iChunkOffset==0 ){
107561 pNew->pNext = 0;
107572 assert( pChunk!=0 );
107589 assert( p->endpoint.pChunk==0 || p->endpoint.pChunk->pNext==0 );
107591 FileChunk *pIter = 0;
107592 if( size==0 ){
107594 p->pFirst = 0;
107602 pIter->pNext = 0;
107608 p->readpoint.pChunk = 0;
107609 p->readpoint.iOffset = 0;
107654 0, /* xLock */
107655 0, /* xUnlock */
107656 0, /* xCheckReservedLock */
107657 0, /* xFileControl */
107658 0, /* xSectorSize */
107659 0, /* xDeviceCharacteristics */
107660 0, /* xShmMap */
107661 0, /* xShmLock */
107662 0, /* xShmBarrier */
107663 0, /* xShmUnmap */
107664 0, /* xFetch */
107665 0 /* xUnfetch */
107672 ** nSpill. If nSpill is 0, then the journal file is always create and
107689 assert( zName || nSpill<0 || (flags & SQLITE_OPEN_EXCLUSIVE) );
107695 memset(p, 0, sizeof(MemJournal));
107696 if( nSpill==0 ){
107697 return sqlite3OsOpen(pVfs, zName, pJfd, flags, 0);
107700 if( nSpill>0 ){
107719 sqlite3JournalOpen(0, 0, pJfd, 0, -1);
107735 p->nSpill>0
107740 NEVER(p->nSpill>0)
107842 assert( pExpr->x.pList==0 || pExpr->pRight==0 );
107880 for(i=p->nExpr, pItem=p->a; i>0; i--, pItem++){
107914 || ((pParse = pWalker->pParse)!=0 && IN_RENAME_OBJECT)
107921 int rc = walkWindowList(pWalker, p->pWinDefn, 0);
107943 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
107978 if( p==0 ) return WRC_Continue;
107979 if( pWalker->xSelectCallback==0 ) return WRC_Continue;
107992 }while( p!=0 );
108074 if( N>0 ){
108076 memset(&w, 0, sizeof(w));
108105 int iCol, /* A column in the result set. 0..pEList->nExpr-1 */
108113 assert( iCol>=0 && iCol<pEList->nExpr );
108115 assert( pOrig!=0 );
108119 pDup = sqlite3ExprDup(db, pOrig, 0);
108122 pDup = 0;
108134 if( ALWAYS(pExpr->y.pWin!=0) ){
108169 if( eEName!=ENAME_TAB && (eEName!=ENAME_ROWID || NEVER(pbRowid==0)) ){
108170 return 0;
108172 assert( pbRowid==0 || *pbRowid==0 );
108174 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
108175 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
108176 return 0;
108179 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
108180 if( zTab && (sqlite3StrNICmp(zSpan, zTab, n)!=0 || zTab[n]!=0) ){
108181 return 0;
108185 if( eEName==ENAME_TAB && sqlite3StrICmp(zSpan, zCol)!=0 ) return 0;
108186 if( eEName==ENAME_ROWID && sqlite3IsRowid(zCol)==0 ) return 0;
108199 if( sqlite3WritableSchema(db) && (db->flags & SQLITE_DqsDML)!=0 ){
108202 return (db->flags & SQLITE_DqsDDL)!=0;
108205 return (db->flags & SQLITE_DqsDML)!=0;
108220 assert( pExTab!=0 );
108222 if( (pExTab->tabFlags & TF_HasGenerated)!=0
108223 && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
108248 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
108253 assert( (pMatch->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 );
108268 assert( pTab!=0 );
108270 if( sqlite3StrNICmp(zTab, "sqlite_", 7)!=0 ) return 0;
108272 if( strcmp(zLegacy+7, &LEGACY_TEMP_SCHEMA_TABLE[7])==0 ){
108273 if( sqlite3StrICmp(zTab+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 ){
108276 if( zDb==0 ) return 0;
108277 if( sqlite3StrICmp(zTab+7, &LEGACY_SCHEMA_TABLE[7])==0 ) return 1;
108278 if( sqlite3StrICmp(zTab+7, &PREFERRED_SCHEMA_TABLE[7])==0 ) return 1;
108280 if( sqlite3StrICmp(zTab+7, &PREFERRED_SCHEMA_TABLE[7])==0 ) return 1;
108282 return 0;
108321 int cnt = 0; /* Number of matching column names */
108322 int cntTab = 0; /* Number of potential "rowid" matches */
108323 int nSubquery = 0; /* How many levels of subquery */
108326 SrcItem *pMatch = 0; /* The matching pSrcList item */
108328 Schema *pSchema = 0; /* Schema of the expression */
108330 Table *pTab = 0; /* Table holding the row */
108331 ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */
108336 assert( zDb==0 || zTab!=0 );
108350 if( (pNC->ncFlags & (NC_PartIdx|NC_IsCheck))!=0 ){
108355 zDb = 0;
108357 for(i=0; i<db->nDb; i++){
108359 if( sqlite3StrICmp(db->aDb[i].zDbSName,zDb)==0 ){
108364 if( i==db->nDb && sqlite3StrICmp("main", zDb)==0 ){
108367 pSchema = db->aDb[0].pSchema;
108368 zDb = db->aDb[0].zDbSName;
108374 assert( pNC && cnt==0 );
108380 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
108382 assert( pTab!=0 && pTab->zName!=0 );
108383 assert( pTab->nCol>0 || pParse->nErr );
108392 int hit = 0;
108395 assert( pItem->u4.pSubq!=0 );
108397 assert( pSel!=0 );
108399 assert( pEList!=0 );
108401 for(j=0; j<pEList->nExpr; j++){
108402 int bRowid = 0; /* True if possible rowid match */
108406 if( bRowid==0 ){
108407 if( cnt>0 ){
108408 if( pItem->fg.isUsing==0
108409 || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
108415 pFJMatch = 0;
108417 if( (pItem->fg.jointype & JT_RIGHT)==0 ){
108421 if( (pItem->fg.jointype & JT_LEFT)==0 ){
108423 cnt = 0;
108425 pFJMatch = 0;
108433 }else if( cnt>0 ){
108444 assert( bRowid==0 || pEList->a[j].fg.bUsingTerm==0 );
108447 if( hit || zTab==0 ) continue;
108449 assert( zDb==0 || zTab!=0 );
108453 if( pSchema==0 && strcmp(zDb,"*")!=0 ) continue;
108455 if( pItem->zAlias!=0 ){
108456 if( sqlite3StrICmp(zTab, pItem->zAlias)!=0 ){
108459 }else if( sqlite3StrICmp(zTab, pTab->zName)!=0 ){
108465 sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
108469 if( j>=0 ){
108470 if( cnt>0 ){
108471 if( pItem->fg.isUsing==0
108472 || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
108478 pFJMatch = 0;
108480 if( (pItem->fg.jointype & JT_RIGHT)==0 ){
108484 if( (pItem->fg.jointype & JT_LEFT)==0 ){
108486 cnt = 0;
108488 pFJMatch = 0;
108502 if( 0==cnt && VisibleRowid(pTab) ){
108514 if( cntTab==0
108516 && pMatch!=0
108517 && ALWAYS(pMatch->pSTab!=0)
108518 && (pMatch->pSTab->tabFlags & TF_Ephemeral)!=0
108519 && (pTab->tabFlags & TF_Ephemeral)==0)
108540 if( (pMatch->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 ){
108553 if( cnt==0 && zDb==0 ){
108554 pTab = 0;
108556 if( pParse->pTriggerTab!=0 ){
108560 if( (pNC->ncFlags & NC_UBaseReg)!=0
108561 && ALWAYS(zTab==0
108562 || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0
108563 || isValidSchemaTableName(zTab, pParse->pTriggerTab, 0))
108568 }else if( op!=TK_DELETE && zTab && sqlite3StrICmp("new",zTab) == 0 ){
108571 }else if( op!=TK_INSERT && zTab && sqlite3StrICmp("old",zTab)==0 ){
108572 pExpr->iTable = 0;
108578 if( (pNC->ncFlags & NC_UUpsert)!=0 && zTab!=0 ){
108580 if( pUpsert && sqlite3StrICmp("excluded",zTab)==0 ){
108581 pTab = pUpsert->pUpsertSrc->a[0].pSTab;
108592 if( iCol>=0 ){
108603 pMatch = 0;
108632 if( iCol<0 ){
108634 }else if( pExpr->iTable==0 ){
108637 pParse->oldmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
108641 pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
108654 if( cnt==0
108657 && (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0
108662 #if SQLITE_ALLOW_ROWID_IN_VIEW+0==2
108663 if( pMatch->pSTab!=0 && IsView(pMatch->pSTab) ){
108667 if( pMatch->fg.isNestedFrom==0 ) pExpr->iColumn = -1;
108689 if( cnt==0
108690 && (pNC->ncFlags & NC_UEList)!=0
108691 && zTab==0
108694 assert( pEList!=0 );
108695 for(j=0; j<pEList->nExpr; j++){
108698 && sqlite3_stricmp(zAs, zCol)==0
108701 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
108702 assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
108703 assert( ExprUseXSelect(pExpr)==0 || pExpr->x.pSelect==0 );
108705 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
108710 && ((pNC->ncFlags&NC_AllowWin)==0 || pNC!=pTopNC )
108721 pMatch = 0;
108722 assert( zTab==0 && zDb==0 );
108724 sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr);
108732 ** we have a match (cnt>0) or when we run out of name contexts.
108750 if( cnt==0 && zTab==0 ){
108775 memset(&pExpr->y, 0, sizeof(pExpr->y));
108784 ** cnt==0 means there was not match.
108787 ** cnt==0 is always an error. cnt>1 is often an error, but might
108790 assert( pFJMatch==0 || cnt>0 );
108800 pExpr->pLeft = 0;
108802 pExpr->pRight = 0;
108812 pFJMatch = 0;
108815 zErr = cnt==0 ? "no such column" : "ambiguous column name";
108820 }else if( cnt==0 && ExprHasProperty(pRight,EP_DblQuoted) ){
108832 assert( pFJMatch==0 );
108837 pExpr->pLeft = 0;
108839 pExpr->pRight = 0;
108844 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
108845 ** bit 0 to be set. Column 1 sets bit 1. And so forth. Bit 63 is
108858 if( pExpr->iColumn>=0 ){
108868 assert( pNC!=0 );
108879 assert( pTopNC!=0 );
108895 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
108906 if( (pTab->tabFlags & TF_HasGenerated)!=0
108907 && (pTab->aCol[iCol].colFlags & COLFLAG_GENERATED)!=0
108958 assert( ((X)&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 ); \
108959 if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E,R);
108980 ** node in the expression tree. Return 0 to continue the search down
108992 assert( pNC!=0 );
108997 if( pNC->pSrcList && pNC->pSrcList->nAlloc>0 ){
109000 for(i=0; i<pNC->pSrcList->nSrc; i++){
109001 assert( pSrcList->a[i].iCursor>=0 && pSrcList->a[i].iCursor<pParse->nTab);
109058 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
109068 for(i=0, p=pNC; p; p=p->pNext, i++){
109069 if( (p->ncFlags & NC_Where)==0 ){
109076 if( sqlite3TreeTrace & 0x80000 ){
109087 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
109091 pExpr->pLeft = 0;
109110 zDb = 0;
109111 zTable = 0;
109119 NC_IdxExpr|NC_GenCol, 0, pExpr);
109122 zDb = 0;
109146 int no_such_func = 0; /* True if no such function exists */
109147 int wrong_num_args = 0; /* True if wrong number of arguments */
109148 int is_agg = 0; /* True if is an aggregate function */
109154 Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
109157 assert( pExpr->pLeft==0 || pExpr->pLeft->op==TK_ORDER );
109159 n = pList ? pList->nExpr : 0;
109161 pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
109162 if( pDef==0 ){
109163 pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
109164 if( pDef==0 ){
109170 is_agg = pDef->xFinalize!=0;
109175 if( pExpr->iTable<0 ){
109191 pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120;
109196 int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0);
109221 for(ii=0; ii<n; ii++){
109233 if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
109241 NC_IdxExpr|NC_PartIdx|NC_GenCol, 0, pExpr);
109243 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
109246 if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
109247 && pParse->nested==0
109248 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
109255 pDef = 0;
109257 if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
109265 if( 0==IN_RENAME_OBJECT ){
109267 assert( is_agg==0 || (pDef->funcFlags & SQLITE_FUNC_MINMAX)
109268 || (pDef->xValue==0 && pDef->xInverse==0)
109271 if( pDef && pDef->xValue==0 && pWin ){
109277 (is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
109279 || (is_agg && pWin && (pNC->ncFlags & NC_AllowWin)==0)
109289 is_agg = 0;
109292 if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){
109295 is_agg = 0;
109298 else if( no_such_func && pParse->db->init.busy==0
109300 && pParse->explain==0
109311 else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
109319 else if( is_agg==0 && pExpr->pLeft ){
109328 pNC->ncFlags &= ~(NC_AllowWin | (!pWin ? NC_AllowAgg : 0));
109345 if( pWin && pParse->nErr==0 ){
109348 if( IN_RENAME_OBJECT==0 ){
109349 sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
109362 pExpr->op2 = 0;
109370 && sqlite3ReferencesSrcList(pParse, pExpr, pNC2->pSrcList)==0
109375 assert( pDef!=0 || IN_RENAME_OBJECT );
109380 testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 );
109381 testcase( (pDef->funcFlags & SQLITE_FUNC_ANYORDER)!=0 );
109456 assert( pExpr->pLeft!=0 );
109460 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
109465 assert( pExpr->pRight!=0 );
109484 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
109496 ** return 0.
109513 for(i=0; i<pEList->nExpr; i++){
109515 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
109521 return 0;
109540 ** If there is no match, return 0. Return -1 if an error occurs.
109554 assert( sqlite3ExprIsInteger(pE, &i, 0)==0 );
109559 memset(&nc, 0, sizeof(nc));
109564 nc.nNcErr = 0;
109570 if( rc ) return 0;
109576 for(i=0; i<pEList->nExpr; i++){
109577 if( sqlite3ExprCompare(0, pEList->a[i].pExpr, pE, -1)<2 ){
109582 /* If no match, return 0. */
109583 return 0;
109628 if( pOrderBy==0 ) return 0;
109634 for(i=0; i<pOrderBy->nExpr; i++){
109635 pOrderBy->a[i].fg.done = 0;
109637 pSelect->pNext = 0;
109644 moreToDo = 0;
109646 assert( pEList!=0 );
109647 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
109652 if( NEVER(pE==0) ) continue;
109653 if( sqlite3ExprIsInteger(pE, &iCol, 0) ){
109654 if( iCol<=0 || iCol>pEList->nExpr ){
109660 if( iCol==0 ){
109672 pDup = sqlite3ExprDup(db, pE, 0);
109676 if( IN_RENAME_OBJECT && iCol>0 ){
109683 if( iCol>0 ){
109687 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
109688 if( pNew==0 ) return 1;
109710 for(i=0; i<pOrderBy->nExpr; i++){
109711 if( pOrderBy->a[i].fg.done==0 ){
109717 return 0;
109741 if( pOrderBy==0 || pParse->db->mallocFailed || IN_RENAME_OBJECT ) return 0;
109747 assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
109748 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
109751 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr, 0);
109754 resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,0);
109757 return 0;
109780 memset(&sWalker, 0, sizeof(Walker));
109820 assert( pOrderBy!=0 );
109823 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
109826 if( NEVER(pE2==0) ) continue;
109827 if( zType[0]!='G' ){
109829 if( iCol>0 ){
109838 if( sqlite3ExprIsInteger(pE2, &iCol, 0) ){
109842 if( iCol<1 || iCol>0xffff ){
109851 pItem->u.x.iOrderByCol = 0;
109855 for(j=0; j<pSelect->pEList->nExpr; j++){
109856 if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
109883 assert( p!=0 );
109899 if( (p->selFlags & SF_Expanded)==0 ){
109904 isCompound = p->pPrior!=0;
109905 nCompound = 0;
109908 assert( (p->selFlags & SF_Expanded)!=0 );
109909 assert( (p->selFlags & SF_Resolved)==0 );
109915 memset(&sNC, 0, sizeof(sNC));
109930 assert( p->pSrc->a[0].fg.isSubquery );
109931 assert( p->pSrc->a[0].u4.pSubq!=0 );
109932 pSub = p->pSrc->a[0].u4.pSubq->pSelect;
109933 assert( pSub!=0 );
109935 assert( pSub->pPrior && pSub->pOrderBy==0 );
109937 p->pOrderBy = 0;
109943 for(i=0; i<p->pSrc->nSrc; i++){
109945 assert( pItem->zName!=0
109948 && (pItem->u4.pSubq->pSelect->selFlags & SF_Resolved)==0
109950 int nRef = pOuterNC ? pOuterNC->nRef : 0;
109957 assert( db->mallocFailed==0 );
109966 assert( pItem->fg.isCorrelated==0 && pOuterNC->nRef>=nRef );
109971 if( pOuterNC && ALWAYS(pOuterNC->nNestedSelect>0) ){
109989 assert( (p->selFlags & SF_Aggregate)==0 );
109991 if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
110007 assert( (sNC.ncFlags & (NC_UAggInfo|NC_UUpsert|NC_UBaseReg))==0 );
110011 if( (p->selFlags & SF_Aggregate)==0 ){
110022 for(i=0; i<p->pSrc->nSrc; i++){
110047 sNC.pNext = 0;
110057 assert( p->pSrc->a[0].fg.isSubquery );
110058 pSub = p->pSrc->a[0].u4.pSubq->pSelect;
110059 assert( pSub!=0 );
110061 pSub->pOrderBy = 0;
110074 if( p->pOrderBy!=0
110094 for(i=0, pItem=pGroupBy->a; i<pGroupBy->nExpr; i++, pItem++){
110181 if( pExpr==0 ) return SQLITE_OK;
110186 w.xSelectCallback = (pNC->ncFlags & NC_NoSelect) ? 0 : resolveSelectStep;
110187 w.xSelectCallback2 = 0;
110189 #if SQLITE_MAX_EXPR_DEPTH>0
110195 assert( pExpr!=0 );
110197 #if SQLITE_MAX_EXPR_DEPTH>0
110206 return pNC->nNcErr>0 || w.pParse->nErr>0;
110214 ** The return value is SQLITE_OK (0) for success or SQLITE_ERROR (1) for a
110222 int savedHasAgg = 0;
110224 if( pList==0 ) return SQLITE_OK;
110228 w.xSelectCallback2 = 0;
110232 for(i=0; i<pList->nExpr; i++){
110234 if( pExpr==0 ) continue;
110235 #if SQLITE_MAX_EXPR_DEPTH>0
110242 #if SQLITE_MAX_EXPR_DEPTH>0
110255 if( w.pParse->nErr>0 ) return SQLITE_ERROR;
110280 assert( p!=0 );
110283 w.xSelectCallback2 = 0;
110298 ** (4) Expression arguments to VACUUM INTO. 0
110310 int type, /* NC_IsCheck, NC_PartIdx, NC_IdxExpr, NC_GenCol, or 0 */
110319 assert( type==0 || pTab!=0 );
110321 || type==NC_GenCol || pTab==0 );
110322 memset(&sNC, 0, sizeof(sNC));
110324 memset(pSrc, 0, SZ_SRCLIST_1);
110327 pSrc->a[0].zName = pTab->zName;
110328 pSrc->a[0].pSTab = pTab;
110329 pSrc->a[0].iCursor = -1;
110370 if( iCol<0 || NEVER(iCol>=pTab->nCol) ) return SQLITE_AFF_INTEGER;
110379 ** affinity of that column is returned. Otherwise, 0x00 is returned,
110394 if( op==TK_COLUMN || (op==TK_AGG_COLUMN && pExpr->y.pTab!=0) ){
110396 assert( pExpr->y.pTab!=0 );
110401 assert( pExpr->x.pSelect!=0 );
110402 assert( pExpr->x.pSelect->pEList!=0 );
110403 assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
110404 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
110409 return sqlite3AffinityType(pExpr->u.zToken, 0);
110413 assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
110415 assert( pExpr->iColumn >= 0 );
110425 return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
110446 ** 0x01 Numeric
110447 ** 0x02 Text
110448 ** 0x04 Blob
110450 ** If the expression must return NULL, then 0x00 is returned.
110462 pExpr = 0;
110466 return 0x02;
110469 return 0x04;
110472 return 0x06;
110477 return 0x07;
110486 if( aff>=SQLITE_AFF_NUMERIC ) return 0x05;
110487 if( aff==SQLITE_AFF_TEXT ) return 0x06;
110488 return 0x07;
110491 int res = 0;
110494 assert( ExprUseXList(pExpr) && pList!=0 );
110495 assert( pList->nExpr > 0);
110505 return 0x01;
110509 return 0x00;
110526 if( pCollName->n>0 ){
110542 assert( zC!=0 );
110544 return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0);
110567 assert( pExpr->x.pList->nExpr>0 );
110569 pExpr = pExpr->x.pList->a[0].pExpr;
110595 CollSeq *pColl = 0;
110600 if( (op==TK_AGG_COLUMN && p->y.pTab!=0)
110605 assert( p->y.pTab!=0 );
110606 if( (j = p->iColumn)>=0 ){
110608 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
110620 p = p->x.pList->a[0].pExpr;
110625 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
110629 if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){
110634 assert( !ExprUseXList(p) || p->x.pList==0 || p->pRight==0 );
110635 if( ExprUseXList(p) && p->x.pList!=0 && !db->mallocFailed ){
110637 for(i=0; i<p->x.pList->nExpr; i++){
110651 pColl = 0;
110668 if( p==0 ) p = pParse->db->pDfltColl;
110669 assert( p!=0 );
110679 return sqlite3StrICmp(pColl1->zName, pColl2->zName)==0;
110719 aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
110720 }else if( aff==0 ){
110778 }else if( pRight && (pRight->flags & EP_Collate)!=0 ){
110822 if( pParse->nErr ) return 0;
110870 ** column of the vector (numbered starting with 0). The caller must
110886 assert( pVector->op2==0 || pVector->op==TK_REGISTER );
110903 ** It is ok for pVector to be a scalar (as long as iField==0).
110933 ** iTable: 0 or the number of columns on the LHS of an assignment
110934 ** pLeft->iTable: First in an array of register holding result, or 0
110944 pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0);
110959 *ppVector = 0;
110963 pRet = sqlite3ExprDup(pParse->db, pVector, 0);
110974 ** If pExpr is not a TK_SELECT expression, return 0.
110977 int reg = 0;
111028 return 0;
111033 ** the result of the comparison (1, 0, or NULL) and write that
111040 ** otherwise: op==pExpr->op and p5==0
111054 int regLeft = 0;
111055 int regRight = 0;
111057 int addrCmp = 0;
111074 assert( p5==0 || pExpr->op!=op );
111085 for(i=0; 1 /*Loop exits by "break"*/; i++){
111086 int regFree1 = 0, regFree2 = 0;
111087 Expr *pL = 0, *pR = 0;
111089 assert( i>=0 && i<nLeft );
111109 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest);
111120 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
111131 #if SQLITE_MAX_EXPR_DEPTH>0
111168 for(i=0; i<p->nExpr; i++){
111196 int nHeight = p->pLeft ? p->pLeft->nHeight : 0;
111228 int nHeight = 0;
111244 #endif /* SQLITE_MAX_EXPR_DEPTH>0 */
111250 if( pExpr==0 ) return;
111283 int nExtra = 0;
111284 int iValue = 0;
111286 assert( db!=0 );
111288 if( op!=TK_INTEGER || pToken->z==0
111289 || sqlite3GetInt32(pToken->z, &iValue)==0 ){
111291 assert( iValue>=0 );
111296 memset(pNew, 0, sizeof(Expr));
111300 if( nExtra==0 ){
111305 assert( pToken->z!=0 || pToken->n==0 );
111307 pNew->u.zToken[pToken->n] = 0;
111308 if( dequote && sqlite3Isquote(pNew->u.zToken[0]) ){
111313 #if SQLITE_MAX_EXPR_DEPTH>0
111332 return sqlite3ExprAlloc(db, op, &x, 0);
111347 if( pRoot==0 ){
111353 assert( pRoot->x.pSelect==0 );
111357 #if SQLITE_MAX_EXPR_DEPTH>0
111366 #if SQLITE_MAX_EXPR_DEPTH>0
111391 memset(p, 0, sizeof(Expr));
111392 p->op = op & 0xff;
111439 Select *pRet = 0;
111441 for(ii=0; ii<pEList->nExpr; ii++){
111458 pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0);
111459 pExpr->x.pList = 0;
111486 if( pLeft==0 ){
111488 }else if( pRight==0 ){
111497 return sqlite3Expr(db, TK_INTEGER, "0");
111512 int eDistinct /* SF_Distinct or SF_ALL or 0 */
111518 if( pNew==0 ){
111520 return 0;
111565 if( NEVER(pOrderBy==0) ){
111569 if( pExpr==0 ){
111575 assert( pExpr->pLeft==0 );
111577 if( pExpr->x.pList==0 || NEVER(pExpr->x.pList->nExpr==0) ){
111588 pOB = sqlite3ExprAlloc(db, TK_ORDER, 0, 0);
111589 if( pOB==0 ){
111616 assert( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 );
111618 if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0
111619 || (pParse->db->flags & SQLITE_TrustedSchema)==0
111654 if( pExpr==0 ) return;
111657 assert( z!=0 );
111658 assert( z[0]!=0 );
111660 if( z[1]==0 ){
111662 assert( z[0]=='?' );
111665 int doAdd = 0;
111666 if( z[0]=='?' ){
111672 i = z[1]-'0'; /* The common case of ?N for a single digit N */
111675 bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
111677 testcase( i==0 );
111681 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
111691 }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
111700 if( x==0 ){
111720 assert( p!=0 );
111721 assert( db!=0 );
111723 assert( !ExprUseUValue(p) || p->u.iValue>=0 );
111725 assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed );
111729 assert( p->pLeft==0 );
111730 assert( p->pRight==0 );
111731 assert( !ExprUseXSelect(p) || p->x.pSelect==0 );
111732 assert( !ExprUseXList(p) || p->x.pList==0 );
111737 assert( (ExprUseXList(p) && p->x.pList==0) || p->pRight==0 );
111781 if( p==0 ){
111797 ** Return 0 if the delete was successfully deferred. Return non-zero
111801 return 0==sqlite3ParserAddCleanup(pParse, sqlite3ExprDeleteGeneric, pExpr);
111848 ** of this routine with 0xfff. The flags can be found by masking the
111863 assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
111864 assert( EXPR_FULLSIZE<=0xfff );
111865 assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
111866 if( 0==flags || ExprHasProperty(p, EP_FullSize) ){
111875 assert( p->pRight==0 );
111888 int nByte = dupedExprStructSize(p, flags) & 0xfff;
111908 assert( p!=0 );
111941 int dupFlags, /* EXPRDUP_REDUCE for compression. 0 if not */
111949 assert( db!=0 );
111951 assert( dupFlags==0 || dupFlags==EXPRDUP_REDUCE );
111952 assert( pEdupBuf==0 || dupFlags==EXPRDUP_REDUCE );
111961 assert( sEdupBuf.zAlloc!=0 );
111971 nToken = 0;
111977 sEdupBuf.zEnd = sEdupBuf.zAlloc ? sEdupBuf.zAlloc+nAlloc : 0;
111980 staticFlag = 0;
111992 int nNewSize = nStructSize & 0xfff;
111993 if( nToken<0 ){
111997 nToken = 0;
112002 assert( ExprHasProperty(p, EP_Reduced)==0 );
112010 memset(&sEdupBuf.zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
112025 assert( nToken>=0 );
112026 if( nToken>0 ){
112033 if( ((p->flags|pNew->flags)&(EP_TokenOnly|EP_Leaf))==0 ){
112040 p->op!=TK_ORDER ? dupFlags : 0);
112054 assert( p->pRight==0
112059 exprDup(db, p->pLeft, EXPRDUP_REDUCE, &sEdupBuf) : 0;
112062 exprDup(db, p->pRight, EXPRDUP_REDUCE, &sEdupBuf) : 0;
112066 assert( p->pRight==0
112070 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
112072 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
112088 With *pRet = 0;
112095 for(i=0; i<p->nCte; i++){
112096 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
112097 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
112106 # define sqlite3WithDup(x,y) 0
112122 assert( pWin->ppThis==0 );
112134 w.xSelectCallback2 = 0;
112135 w.pParse = 0;
112160 assert( flags==0 || flags==EXPRDUP_REDUCE );
112161 return p ? exprDup(db, p, flags, 0) : 0;
112168 Expr *pPriorSelectColOld = 0;
112169 Expr *pPriorSelectColNew = 0;
112170 assert( db!=0 );
112171 if( p==0 ) return 0;
112173 if( pNew==0 ) return 0;
112178 for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
112184 && (pNewExpr = pItem->pExpr)!=0
112217 assert( db!=0 );
112218 if( p==0 ) return 0;
112220 if( pNew==0 ) return 0;
112222 for(i=0; i<p->nSrc; i++){
112229 if( pNewSubq==0 ){
112231 pNewItem->fg.isSubquery = 0;
112235 if( pNewSubq->pSelect==0 ){
112237 pNewSubq = 0;
112238 pNewItem->fg.isSubquery = 0;
112279 assert( db!=0 );
112280 if( p==0 ) return 0;
112282 if( pNew==0 ) return 0;
112284 for(i=0; i<p->nId; i++){
112292 Select *pRet = 0;
112293 Select *pNext = 0;
112297 assert( db!=0 );
112300 if( pNew==0 ) break;
112309 pNew->pPrior = 0;
112311 pNew->iLimit = 0;
112312 pNew->iOffset = 0;
112314 pNew->addrOpenEphm[0] = -1;
112319 pNew->pWin = 0;
112321 if( p->pWin && db->mallocFailed==0 ) gatherSelectWindows(pNew);
112328 pNew->pNext = 0;
112340 assert( p==0 );
112341 return 0;
112357 static const struct ExprList_item zeroItem = {0};
112366 if( pList==0 ){
112368 return 0;
112372 pItem = &pList->a[0];
112386 if( pNew==0 ){
112389 return 0;
112404 if( pList==0 ){
112436 int iFirst = pList ? pList->nExpr : 0;
112439 if( NEVER(pColumns==0) ) goto vector_append_error;
112440 if( pExpr==0 ) goto vector_append_error;
112453 for(i=0; i<pColumns->nId; i++){
112455 assert( pSubExpr!=0 || db->mallocFailed );
112456 if( pSubExpr==0 ) continue;
112461 pColumns->a[i].zName = 0;
112465 if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){
112467 assert( pFirst!=0 );
112473 pExpr = 0;
112491 if( p==0 ) return;
112492 assert( p->nExpr>0 );
112494 assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC==0 && SQLITE_SO_DESC>0 );
112505 assert( pItem->fg.bNulls==0 );
112533 assert( pList!=0 || pParse->db->mallocFailed!=0 );
112534 assert( pParse->eParseMode!=PARSE_MODE_UNMAP || dequote==0 );
112537 assert( pList->nExpr>0 );
112539 assert( pItem->zEName==0 );
112543 /* If dequote==0, then pName->z does not point to part of a DDL
112569 assert( pList!=0 || db->mallocFailed!=0 );
112572 assert( pList->nExpr>0 );
112573 if( pItem->zEName==0 ){
112603 assert( pList->nExpr>0 );
112604 assert( db!=0 );
112609 }while( --i>0 );
112625 u32 m = 0;
112626 assert( pList!=0 );
112627 for(i=0; i<pList->nExpr; i++){
112629 assert( pExpr!=0 );
112644 pWalker->eCode = 0;
112654 ** anything else 0
112657 if( sqlite3StrICmp(zIn, "true")==0 ) return EP_IsTrue;
112658 if( sqlite3StrICmp(zIn, "false")==0 ) return EP_IsFalse;
112659 return 0;
112672 && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0
112678 return 0;
112683 ** and 0 if it is FALSE.
112689 assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
112690 || sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
112691 return pExpr->u.zToken[4]==0;
112708 assert( pExpr!=0 );
112731 ** This routine sets pWalker->eCode to 0 if pExpr is not a constant.
112748 || (pList = pExpr->x.pList)==0
112750 n = 0;
112754 if( pWalker->eCode==0 ) return WRC_Abort;
112757 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
112758 if( pDef==0
112759 || pDef->xFinalize!=0
112760 || (pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
112763 pWalker->eCode = 0;
112783 ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
112797 assert( pWalker->eCode>0 );
112803 pWalker->eCode = 0;
112820 pWalker->eCode = 0;
112852 pWalker->eCode = 0;
112863 pWalker->eCode = 0;
112888 ** and 0 if it involves variables or function calls.
112928 assert( pSelect!=0 );
112929 assert( pWalker->eCode==3 || pWalker->eCode==0 );
112930 if( (pSelect->selFlags & SF_Correlated)!=0 ){
112931 pWalker->eCode = 0;
112949 w.pParse = 0;
112973 ** doubt, return 0.
113016 return 0; /* rule (3) */
113019 if( !ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (4a) */
113020 if( pExpr->w.iJoin!=pSrc->iCursor ) return 0; /* rule (4b) */
113022 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (5) */
113025 && (pSrcList->a[0].fg.jointype & JT_LTORJ)!=0 /* Fast pre-test of (6b) */
113028 for(jj=0; jj<iSrc; jj++){
113030 if( (pSrcList->a[jj].fg.jointype & JT_LTORJ)!=0 ){
113031 return 0; /* restriction (6) */
113051 for(i=0; i<pGroupBy->nExpr; i++){
113053 if( sqlite3ExprCompare(0, pExpr, p, -1)<2 ){
113063 pWalker->eCode = 0;
113093 w.xSelectCallback = 0;
113105 ** Return and 0 if there are any variables.
113122 assert( isInit==0 || isInit==1 );
113123 return exprIsConst(0, p, 4+isInit);
113129 ** subquery of some kind. Return 0 if there are no subqueries.
113140 return w.eCode==0;
113148 ** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged.
113155 int rc = 0;
113156 if( NEVER(p==0) ) return 0; /* Used to only happen following on OOM */
113160 assert( p->op!=TK_INTEGER || (p->flags & EP_IntValue)!=0
113161 || sqlite3GetInt32(p->u.zToken, &rc)==0 );
113169 rc = sqlite3ExprIsInteger(p->pLeft, pValue, 0);
113173 int v = 0;
113174 if( sqlite3ExprIsInteger(p->pLeft, &v, 0) ){
113175 assert( ((unsigned int)v)!=0x80000000 );
113183 if( pParse==0 ) break;
113184 if( NEVER(pParse->pVdbe==0) ) break;
113185 if( (pParse->db->flags & SQLITE_EnableQPSG)!=0 ) break;
113192 if( vv == (vv & 0x7fffffff) ){ /* non-negative numbers only */
113222 assert( p!=0 );
113225 assert( p!=0 );
113234 return 0;
113238 || NEVER(p->y.pTab==0) /* Reference to column of index on expr */
113242 || (p->iColumn>=0
113243 && p->y.pTab->aCol!=0 /* Possible due to prior error */
113245 && p->y.pTab->aCol[p->iColumn].notNull==0);
113263 int unaryMinus = 0;
113285 assert( p->iTable>=0 ); /* p cannot be part of a CHECK constraint */
113286 return aff>=SQLITE_AFF_NUMERIC && p->iColumn<0;
113289 return 0;
113298 if( sqlite3StrICmp(z, "_ROWID_")==0 ) return 1;
113299 if( sqlite3StrICmp(z, "ROWID")==0 ) return 1;
113300 if( sqlite3StrICmp(z, "OID")==0 ) return 1;
113301 return 0;
113313 for(ii=0; ii<ArraySize(azOpt); ii++){
113314 if( sqlite3ColumnIndex(pTab, azOpt[ii])<0 ) return azOpt[ii];
113316 return 0;
113333 if( !ExprUseXSelect(pX) ) return 0; /* Not a subquery */
113334 if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */
113336 if( p->pPrior ) return 0; /* Not a compound SELECT */
113340 return 0; /* No DISTINCT keyword and no aggregate functions */
113342 assert( p->pGroupBy==0 ); /* Has no GROUP BY clause */
113343 if( p->pLimit ) return 0; /* Has no LIMIT clause */
113344 if( p->pWhere ) return 0; /* Has no WHERE clause */
113346 assert( pSrc!=0 );
113347 if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
113348 if( pSrc->a[0].fg.isSubquery) return 0;/* FROM is not a subquery or view */
113349 pTab = pSrc->a[0].pSTab;
113350 assert( pTab!=0 );
113352 if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
113354 assert( pEList!=0 );
113356 for(i=0; i<pEList->nExpr; i++){
113358 if( pRes->op!=TK_COLUMN ) return 0;
113359 assert( pRes->iTable==pSrc->a[0].iCursor ); /* Not a correlated subquery */
113374 sqlite3VdbeAddOp2(v, OP_Integer, 0, regHasNull);
113376 sqlite3VdbeAddOp3(v, OP_Column, iCur, 0, regHasNull);
113394 pIn->pLeft = 0;
113482 ** then aiMap[] is populated with {2, 0, 1}.
113494 int eType = 0; /* Type of RHS table. IN_INDEX_* */
113500 mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
113507 ** set prRhsHasNull to 0 before continuing. */
113511 for(i=0; i<pEList->nExpr; i++){
113515 prRhsHasNull = 0;
113522 if( pParse->nErr==0 && (p = isCandidateForInOpt(pX))!=0 ){
113529 assert( p->pEList!=0 ); /* Because of isCandidateForInOpt(p) */
113530 assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */
113531 assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
113532 pTab = p->pSrc->a[0].pSTab;
113536 assert( iDb>=0 && iDb<SQLITE_MAX_DB );
113538 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
113541 if( nExpr==1 && pEList->a[0].pExpr->iColumn<0 ){
113548 ExplainQueryPlan((pParse, 0,
113560 for(i=0; i<nExpr && affinity_ok; i++){
113584 for(pIdx=pTab->pIndex; pIdx && eType==0; pIdx=pIdx->pNext){
113588 if( pIdx->pPartIdxWhere!=0 ) continue;
113602 colUsed = 0; /* Columns of index used so far */
113603 for(i=0; i<nExpr; i++){
113609 for(j=0; j<nExpr; j++){
113612 if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){
113624 assert( nExpr>0 && nExpr<BMS );
113629 ExplainQueryPlan((pParse, 0,
113635 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
113641 iTab, 0, 0, (u8*)&mask, P4_INT64);
113662 if( eType==0
113672 if( eType==0 ){
113677 int rMayHaveNull = 0;
113680 pParse->nQueryLoop = 0;
113695 for(i=0; i<n; i++) aiMap[i] = i;
113714 Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0;
113721 for(i=0; i<nVal; i++){
113730 zRet[nVal] = '\0';
113744 if( pParse->nErr==0 ){
113788 if( pNewSig==0 ) return 0;
113789 if( (pParse->mSubrtnSig & (1<<(pNewSig->selId&7)))==0 ) return 0;
113793 assert( pExpr->x.pSelect!=0 );
113794 assert( (pExpr->x.pSelect->selFlags & SF_All)==0 );
113796 assert( v!=0 );
113803 assert( pSig!=0 );
113806 if( strcmp(pNewSig->zAff,pSig->zAff)!=0 ) continue;
113813 return 0;
113845 int addrOnce = 0; /* Address of the OP_Once instruction at top */
113848 KeyInfo *pKeyInfo = 0; /* Key information */
113851 SubrtnSig *pSig = 0; /* Signature for this subroutine */
113854 assert( v!=0 );
113866 if( !ExprHasProperty(pExpr, EP_VarSelect) && pParse->iSelfTab==0 ){
113872 assert( !ExprUseXSelect(pExpr) || pExpr->x.pSelect!=0 );
113873 if( ExprUseXSelect(pExpr) && (pExpr->x.pSelect->selFlags & SF_All)==0 ){
113874 pSig = sqlite3DbMallocRawNN(pParse->db, sizeof(pSig[0]));
113890 ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d",
113912 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1;
113914 pSig->bComplete = 0;
113961 int addrBloom = 0;
113964 pSelect->iLimit = 0;
113972 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
113973 pCopy = sqlite3SelectDup(pParse->db, pSelect, 0);
113981 if( dest.iSDParm2==0 ){
113990 assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
113991 assert( pEList!=0 );
113992 assert( pEList->nExpr>0 );
113994 for(i=0; i<nVal; i++){
114001 }else if( ALWAYS(pExpr->x.pList!=0) ){
114022 pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
114028 for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
114040 addrOnce = 0;
114082 ** Return 0 if an error occurs.
114086 int addrOnce = 0; /* Address of OP_Once at top of subroutine */
114087 int rReg = 0; /* Register storing resulting */
114097 assert( v!=0 );
114098 if( pParse->nErr ) return 0;
114108 ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
114121 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1;
114141 ** If this is an EXISTS, write an integer 0 (not exists) or 1 (exists)
114151 sqlite3SelectDestInit(&dest, 0, pParse->nMem+1);
114157 sqlite3VdbeAddOp3(v, OP_Null, 0, dest.iSDParm, dest.iSDParm+nReg-1);
114161 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
114166 ** then make the new limit X<>0 so that the new limit is either 1 or 0 */
114168 pLimit = sqlite3Expr(db, TK_INTEGER, "0");
114172 sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit);
114179 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
114181 pSel->iLimit = 0;
114185 return 0;
114224 return 0;
114260 int rRhsHasNull = 0; /* Register that is true if RHS contains NULL values */
114265 int *aiMap = 0; /* Map from vector field to index column */
114266 char *zAff = 0; /* Affinity string for comparisons */
114272 int destStep6 = 0; /* Start of code for Step 6 */
114276 int iTab = 0; /* Index to use */
114292 assert( v!=0 ); /* OOM detected prior to this routine */
114296 destIfFalse==destIfNull ? 0 : &rRhsHasNull,
114303 /* Confirm that aiMap[] contains nVector integer values between 0 and
114305 for(i=0; i<nVector; i++){
114307 for(cnt=j=0; j<nVector; j++) if( aiMap[j]==i ) cnt++;
114325 pParse->okConstFactor = 0;
114328 for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */
114335 for(i=0; i<nVector; i++){
114336 sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0);
114351 int regCkNull = 0;
114360 for(ii=0; ii<pList->nExpr; ii++){
114374 sqlite3VdbeChangeP5(v, zAff[0]);
114382 sqlite3VdbeChangeP5(v, zAff[0] | SQLITE_JUMPIFNULL);
114403 for(i=0; i<nVector; i++){
114424 sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
114430 if( pOp->opcode==OP_Once && pOp->p3>0 ){ /* tag-202407032019 */
114441 addrTruthOp = sqlite3VdbeAddOp4Int(v, OP_Found, iTab, 0,
114475 for(i=0; i<nVector; i++){
114487 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
114495 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
114513 ** value described by z[0..n-1] into register iMem.
114520 if( ALWAYS(z!=0) ){
114525 sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
114533 ** text z[0..n-1] into register iMem.
114541 assert( i>=0 );
114548 assert( z!=0 );
114555 if( sqlite3_strnicmp(z,"0x",2)==0 ){
114566 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64);
114588 pParse->iSelfTab = 0;
114609 assert( v!=0 );
114610 assert( pParse->iSelfTab!=0 );
114611 if( pParse->iSelfTab>0 ){
114612 iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
114614 iAddr = 0;
114618 sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
114636 assert( v!=0 );
114637 assert( pTab!=0 );
114639 if( iCol<0 || iCol==pTab->iPKey ){
114683 ** is called. If iColumn<0 then code is generated that extracts the rowid.
114693 assert( pParse->pVdbe!=0 );
114695 assert( IsVirtual(pTab) || (p5 & OPFLAG_NOCHNG)==0 );
114720 if( NEVER(p==0) ) return;
114739 ** to 0.
114747 *piFreeable = 0;
114750 iResult = 0;
114759 for(i=0; i<nResult; i++){
114789 assert( v!=0 );
114790 assert( pFarg!=0 );
114792 assert( nFarg>0 ); /* All in-line functions have at least one argument */
114802 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
114814 memset(&caseExpr, 0, sizeof(caseExpr));
114821 Expr *pArg = pFarg->a[0].pExpr;
114822 if( pArg->op==TK_COLUMN && pArg->iTable>=0 ){
114825 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
114835 target = sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target);
114848 sqlite3ExprCompare(0,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
114857 sqlite3ExprImpliesExpr(pParse,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
114869 sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable,1),
114872 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
114886 aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
114924 n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0;
114925 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
114926 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
114943 memset(&w, 0, sizeof(w));
114967 if( iDataCur<0 ) continue;
114972 if( sqlite3ExprCompare(0, pExpr, p->pExpr, iDataCur)!=0 ) continue;
114995 assert( v!=0 );
115005 sqlite3VdbeGoto(v, 0);
115007 pParse->pIdxEpr = 0;
115036 int addr = 0;
115043 sqlite3VdbeAddOp4(pParse->pVdbe, OP_Affinity, ret, 1, 0,
115052 return 0;
115071 int regFree1 = 0; /* If non-zero free this temporary register */
115072 int regFree2 = 0; /* If non-zero free this temporary register */
115075 int p5 = 0;
115077 assert( target>0 && target<=pParse->nMem );
115078 assert( v!=0 );
115081 if( pExpr==0 ){
115083 }else if( pParse->pIdxEpr!=0
115085 && (r1 = sqlite3IndexedExprLookup(pParse, pExpr, target))>=0
115097 assert( pAggInfo!=0 );
115098 assert( pExpr->iAgg>=0 );
115102 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
115118 if( pTab==0 ){
115120 }else if( pCol->iColumn<0 ){
115130 }else if( pExpr->y.pTab==0 ){
115152 assert( pExpr->y.pTab!=0 );
115158 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0,
115163 if( iTab<0 ){
115164 if( pParse->iSelfTab<0 ){
115168 ** 0-(pParse->iSelfTab). The rowid (if any) is in a register
115177 assert( pTab!=0 );
115180 if( iCol<0 ){
115191 return 0;
115215 && 0!=(r1 = exprPartidxExprLookup(pParse, pExpr, target))
115220 assert( pExpr->y.pTab!=0 );
115227 codeInteger(pParse, pExpr, 0, target);
115237 codeReal(v, pExpr->u.zToken, 0, target);
115249 sqlite3VdbeAddOp3(v, OP_Null, 0, target, target + pExpr->y.nReg - 1);
115258 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
115267 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
115273 sqlite3VdbeAddOp4(v, OP_Blob, n/2, target, 0, zBlob, P4_DYNAMIC);
115279 assert( pExpr->u.zToken!=0 );
115280 assert( pExpr->u.zToken[0]!=0 );
115294 sqlite3AffinityType(pExpr->u.zToken, 0));
115326 sqlite3VdbeAddOp2(v, OP_Integer, 0, inReg);
115330 testcase( regFree1==0 );
115331 testcase( regFree2==0 );
115361 testcase( regFree1==0 );
115362 testcase( regFree2==0 );
115380 tempX.u.iValue = 0;
115385 testcase( regFree2==0 );
115394 testcase( regFree1==0 );
115402 testcase( regFree1==0 );
115417 testcase( regFree1==0 );
115421 sqlite3VdbeAddOp2(v, OP_Integer, 0, target);
115427 if( pInfo==0
115428 || NEVER(pExpr->iAgg<0)
115443 u32 constMask = 0; /* Mask of function arguments that are constant */
115447 CollSeq *pColl = 0; /* A collating sequence */
115465 nFarg = pFarg ? pFarg->nExpr : 0;
115468 pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0);
115470 if( pDef==0 && pParse->explain ){
115471 pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0);
115474 if( pDef==0 || pDef->xFinalize!=0 ){
115478 if( (pDef->funcFlags & SQLITE_FUNC_INLINE)!=0 && ALWAYS(pFarg!=0) ){
115479 assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 );
115480 assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 );
115487 for(i=0; i<nFarg; i++){
115492 if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
115509 if( (pDef->funcFlags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
115512 assert( pFarg->a[0].pExpr!=0 );
115513 exprOp = pFarg->a[0].pExpr->op;
115522 pFarg->a[0].pExpr->op2 = pDef->funcFlags & OPFLAG_BYTELENARG;
115526 sqlite3ExprCodeExprList(pParse, pFarg, r1, 0, SQLITE_ECEL_FACTOR);
115528 r1 = 0;
115545 }else if( nFarg>0 ){
115546 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
115551 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
115556 if( constMask==0 ){
115571 return 0;
115585 if( pLeft->iTable==0 || pParse->withinRJSubrtn > pLeft->op2 ){
115600 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
115604 sqlite3VdbeAddOp2(v, OP_AddImm, target, 0);
115619 ** Y is stored in pExpr->pList->a[0].pExpr.
115623 exprCodeBetween(pParse, pExpr, target, 0, 0);
115653 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
115658 ** parameter is set to 0 for an old.rowid reference, or to (i+1)
115671 ** p1==0 -> old.rowid p1==3 -> new.rowid
115685 assert( pExpr->iTable==0 || pExpr->iTable==1 );
115687 assert( pTab->iPKey<0 || iCol!=pTab->iPKey );
115688 assert( p1>=0 && p1<(pTab->nCol*2+2) );
115693 (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[iCol].zCnName)
115702 if( iCol>=0 && pTab->aCol[iCol].affinity==SQLITE_AFF_REAL ){
115725 assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
115738 addrINR = sqlite3VdbeAddOp3(v, OP_IfNullRow, pExpr->iTable, 0, target);
115746 pParse->okConstFactor = 0; /* note (1) above */
115784 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
115785 Expr *pDel = 0;
115788 assert( ExprUseXList(pExpr) && pExpr->x.pList!=0 );
115789 assert(pExpr->x.pList->nExpr > 0);
115794 if( (pX = pExpr->pLeft)!=0 ){
115795 pDel = sqlite3ExprDup(db, pX, 0);
115802 testcase( regFree1==0 );
115803 memset(&opCompare, 0, sizeof(opCompare));
115811 regFree1 = 0;
115813 for(i=0; i<nExpr-1; i=i+2){
115815 assert( pTest!=0 );
115828 if( (nExpr&1)!=0 ){
115831 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
115848 return 0;
115881 ** If regDest>0 then the result is always stored in that register and the
115882 ** result is not reusable. If regDest<0 then this routine is free to
115884 ** is stored is returned. When regDest<0, two identical expressions might
115896 assert( regDest!=0 );
115898 if( regDest<0 && p ){
115901 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
115903 && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0
115909 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
115910 if( pExpr!=0 && ExprHasProperty(pExpr, EP_HasFunc) ){
115915 pParse->okConstFactor = 0;
115917 if( regDest<0 ) regDest = ++pParse->nMem;
115927 pItem->fg.reusable = regDest<0;
115928 if( regDest<0 ) regDest = ++pParse->nMem;
115947 memset(&t, 0, sizeof(t));
115972 && ALWAYS(pExpr!=0)
115976 *pReg = 0;
115985 *pReg = 0;
115999 assert( pExpr==0 || !ExprHasVVAProperty(pExpr,EP_Immutable) );
116000 assert( target>0 && target<=pParse->nMem );
116001 assert( pParse->pVdbe!=0 || pParse->db->mallocFailed );
116002 if( pParse->pVdbe==0 ) return;
116026 pExpr = sqlite3ExprDup(db, pExpr, 0);
116060 ** ExprList.a[].u.x.iOrderByCol>0 have already been evaluated and stored
116062 ** If SQLITE_ECEL_OMITREF is also set, then the values with u.x.iOrderByCol>0
116076 assert( pList!=0 );
116077 assert( target>0 );
116078 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
116081 for(pItem=pList->a, i=0; i<n; i++, pItem++){
116089 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
116096 }else if( (flags & SQLITE_ECEL_FACTOR)!=0
116108 && pOp->p5==0 /* The do-not-merge flag must be clear */
116150 int regFree1 = 0; /* Temporary use register */
116151 Expr *pDel = 0;
116154 memset(&compLeft, 0, sizeof(Expr));
116155 memset(&compRight, 0, sizeof(Expr));
116156 memset(&exprAnd, 0, sizeof(Expr));
116159 pDel = sqlite3ExprDup(db, pExpr->pLeft, 0);
116160 if( db->mallocFailed==0 ){
116166 compLeft.pRight = pExpr->x.pList->a[0].pExpr;
116187 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull==0 && regFree1==0 );
116188 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull==0 && regFree1!=0 );
116189 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull!=0 && regFree1==0 );
116190 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull!=0 && regFree1!=0 );
116191 testcase( xJump==sqlite3ExprIfFalse && jumpIfNull==0 && regFree1==0 );
116192 testcase( xJump==sqlite3ExprIfFalse && jumpIfNull==0 && regFree1!=0 );
116193 testcase( xJump==sqlite3ExprIfFalse && jumpIfNull!=0 && regFree1==0 );
116194 testcase( xJump==sqlite3ExprIfFalse && jumpIfNull!=0 && regFree1!=0 );
116195 testcase( xJump==0 );
116214 int op = 0;
116215 int regFree1 = 0;
116216 int regFree2 = 0;
116219 assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
116220 if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
116221 if( NEVER(pExpr==0) ) return; /* No way this can happen */
116232 testcase( jumpIfNull==0 );
116238 testcase( jumpIfNull==0 );
116245 testcase( jumpIfNull==0 );
116252 testcase( jumpIfNull==0 );
116259 isNot ? SQLITE_JUMPIFNULL : 0);
116262 isNot ? SQLITE_JUMPIFNULL : 0);
116280 testcase( jumpIfNull==0 );
116295 testcase( regFree1==0 );
116296 testcase( regFree2==0 );
116304 assert( regFree1==0 || regFree1==r1 );
116312 testcase( jumpIfNull==0 );
116334 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
116336 testcase( regFree1==0 );
116337 testcase( jumpIfNull==0 );
116353 ** is 0.
116357 int op = 0;
116358 int regFree1 = 0;
116359 int regFree2 = 0;
116362 assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
116363 if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
116364 if( pExpr==0 ) return;
116405 testcase( jumpIfNull==0 );
116410 testcase( jumpIfNull==0 );
116419 testcase( jumpIfNull==0 );
116426 testcase( jumpIfNull==0 );
116434 isNot ? 0 : SQLITE_JUMPIFNULL);
116439 isNot ? 0 : SQLITE_JUMPIFNULL);
116457 testcase( jumpIfNull==0 );
116472 testcase( regFree1==0 );
116473 testcase( regFree2==0 );
116479 assert( regFree1==0 || regFree1==r1 );
116487 testcase( jumpIfNull==0 );
116511 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
116513 testcase( regFree1==0 );
116514 testcase( jumpIfNull==0 );
116530 Expr *pCopy = sqlite3ExprDup(db, pExpr, 0);
116531 if( db->mallocFailed==0 ){
116560 sqlite3_value *pL, *pR = 0;
116563 return 0;
116565 if( (pParse->db->flags & SQLITE_EnableQPSG)!=0 ) return 2;
116575 res = sqlite3MemCompare(pL, pR, 0) ? 2 : 0;
116584 ** Do a deep comparison of two expression trees. Return 0 if the two
116593 ** not using TK_REGISTER but is otherwise equivalent, then still return 0.
116599 ** expressions are the same. But if you get a 0 or 1 return, then you
116603 ** an incorrect 0 or 1 could lead to a malfunction.
116617 if( pA==0 || pB==0 ){
116618 return pB==pA ? 0 : 2;
116625 if( (pA->flags&pB->flags&EP_IntValue)!=0 && pA->u.iValue==pB->u.iValue ){
116626 return 0;
116638 && pB->iTable<0 && pA->iTable==iTab
116649 if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
116656 if( sqlite3WindowCompare(pParse, pA->y.pWin, pB->y.pWin, 1)!=0 ){
116662 return 0;
116664 if( sqlite3_stricmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
116666 if( pB->u.zToken!=0
116669 && strcmp(pA->u.zToken,pB->u.zToken)!=0
116676 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
116678 if( (combinedFlags & EP_FixedCol)==0
116684 && ALWAYS((combinedFlags & EP_Reduced)==0)
116693 return 0;
116697 ** Compare two ExprList objects. Return 0 if they are identical, 1
116706 ** must never return 0 if the two ExprList objects are different, or
116714 if( pA==0 && pB==0 ) return 0;
116715 if( pA==0 || pB==0 ) return 1;
116717 for(i=0; i<pA->nExpr; i++){
116722 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
116724 return 0;
116732 return sqlite3ExprCompare(0,
116753 if( sqlite3ExprCompare(pParse, p, pNN, iTab)==0 ){
116758 if( seenNot && ExprHasProperty(p, EP_xIsSelect) ) return 0;
116759 assert( ExprUseXSelect(p) || (p->x.pList!=0 && p->x.pList->nExpr>0) );
116766 assert( pList!=0 );
116768 if( seenNot ) return 0;
116769 if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, 1)
116804 if( seenNot ) return 0;
116805 if( p->op2!=TK_IS ) return 0;
116813 return 0;
116823 if( pExpr->op==TK_TRUEFALSE && sqlite3ExprTruthValue(pExpr)==0 ) return 1;
116825 if( sqlite3ExprIsInteger(pExpr, &v, 0) && v==0 ) return 1;
116826 return 0;
116844 if( (z[0]!='i' && z[0]!='I') ) return 0;
116845 if( pExpr->x.pList==0 ) return 0;
116846 pDef = sqlite3FindFunction(db, z, pExpr->x.pList->nExpr, ENC(db), 0);
116848 if( pDef==0 ) return 0;
116850 if( NEVER(pDef==0) ) return 0;
116852 if( (pDef->funcFlags & SQLITE_FUNC_INLINE)==0 ) return 0;
116853 if( SQLITE_PTR_TO_INT(pDef->pUserData)!=INLINEFUNC_iif ) return 0;
116855 if( pExpr->pLeft!=0 ) return 0;
116857 return 0;
116860 assert( pList!=0 );
116863 return 0;
116872 ** pE1: x>0 pE2: x==5 Result: false
116879 ** PE1: iif(x,y,0) pE2: x Result: true
116882 ** Expr.iTable<0 then assume a table number given by iTab.
116899 if( sqlite3ExprCompare(pParse, pE1, pE2, iTab)==0 ){
116909 && exprImpliesNotNull(pParse, pE1, pE2->pLeft, iTab, 0)
116914 return sqlite3ExprImpliesExpr(pParse,pE1->x.pList->a[0].pExpr,pE2,iTab);
116916 return 0;
116924 if( pWalker->eCode==0 ){
116927 pWalker->eCode = 0;
117003 if( ExprUseXList(pExpr) && ALWAYS(pExpr->x.pList->nExpr>0) ){
117014 bothImplyNotNullRow(pWalker, pExpr->x.pList->a[0].pExpr,
117035 /* The y.pTab=0 assignment in wherecode.c always happens after the
117040 && ALWAYS(pLeft->y.pTab!=0)
117043 && ALWAYS(pRight->y.pTab!=0)
117080 if( p==0 ) return 0;
117090 w.xSelectCallback = 0;
117091 w.xSelectCallback2 = 0;
117092 w.eCode = 0;
117093 w.mWFlags = isRJ!=0;
117119 && sqlite3TableColumnToIndex(pWalker->u.pIdxCover->pIdx, pExpr->iColumn)<0
117144 memset(&w, 0, sizeof(w));
117177 if( pSrc->nSrc==0 ) return WRC_Continue;
117181 if( piNew==0 ){
117182 p->nExclude = 0;
117187 for(i=0; i<pSrc->nSrc; i++, j++){
117203 ** Set the 0x01 bit of pWalker->eCode if there is a reference to any
117206 ** Set the 0x02 bit of pWalker->eCode if there is a reference to a
117216 int nSrc = pSrc ? pSrc->nSrc : 0;
117217 for(i=0; i<nSrc; i++){
117223 for(i=0; i<p->nExclude && p->aiExclude[i]!=pExpr->iTable; i++){}
117237 ** 0 pExpr references some table that is not defined in either
117249 assert( pParse->db!=0 );
117250 memset(&w, 0, sizeof(w));
117251 memset(&x, 0, sizeof(x));
117264 assert( pExpr->pLeft->x.pList!=0 );
117273 if( w.eCode & 0x01 ){
117276 return 0;
117295 && pExpr->pAggInfo!=0
117301 assert( iAgg>=0 );
117306 pExpr = sqlite3ExprDup(db, pExpr, 0);
117316 pExpr = sqlite3ExprDup(db, pExpr, 0);
117331 memset(pWalker, 0, sizeof(*pWalker));
117346 sizeof(pInfo->aCol[0]),
117362 sizeof(pInfo->aFunc[0]),
117386 assert( pAggInfo->iFirstReg==0 );
117388 for(k=0; k<pAggInfo->nColumn; k++, pCol++){
117398 if( k<0 ){
117419 for(j=0; j<n; j++, pTerm++){
117430 if( pCol->iSorterColumn<0 ){
117435 assert( pExpr->pAggInfo==0 || pExpr->pAggInfo==pAggInfo );
117457 assert( pAggInfo->iFirstReg==0 );
117462 assert( pParse->iSelfTab==0 );
117463 if( (pNC->ncFlags & NC_InAggFunc)==0 ) break;
117464 if( pParse->pIdxEpr==0 ) break;
117467 if( iDataCur<0 ) continue;
117468 if( sqlite3ExprCompare(0, pExpr, pIEpr->pExpr, iDataCur)==0 ) break;
117470 if( pIEpr==0 ) break;
117472 for(i=0; i<pSrcList->nSrc; i++){
117473 if( pSrcList->a[0].iCursor==pIEpr->iDataCur ) break;
117476 if( NEVER(pExpr->pAggInfo!=0) ) break; /* Resolved by outer context */
117483 memset(&tmp, 0, sizeof(tmp));
117489 assert( pAggInfo->aCol!=0 );
117504 if( ALWAYS(pSrcList!=0) ){
117506 for(i=0; i<pSrcList->nSrc; i++, pItem++){
117517 if( (pNC->ncFlags & NC_InAggFunc)==0
117519 && pExpr->pAggInfo==0
117527 for(i=0; i<pAggInfo->nFunc; i++, pItem++){
117529 if( sqlite3ExprCompare(0, pItem->pFExpr, pExpr, -1)==0 ){
117542 if( i>=0 ){
117548 nArg = pExpr->x.pList ? pExpr->x.pList->nExpr : 0;
117550 pExpr->u.zToken, nArg, enc, 0);
117551 assert( pItem->bOBUnique==0 );
117553 && (pItem->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)==0
117558 assert( nArg>0 );
117563 assert( pOBList->nExpr>0 );
117564 assert( pItem->bOBUnique==0 );
117567 && sqlite3ExprCompare(0,pOBList->a[0].pExpr,
117568 pExpr->x.pList->a[0].pExpr,0)==0
117570 pItem->bOBPayload = 0;
117576 (pItem->pFunc->funcFlags & SQLITE_SUBTYPE)!=0;
117617 w.walkerDepth = 0;
117619 w.pParse = 0;
117620 assert( pNC->pSrcList!=0 );
117634 for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
117644 if( pParse->nTempReg==0 ){
117656 sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0, 0);
117685 sqlite3VdbeReleaseRegisters(pParse, iReg, nReg, 0, 0);
117701 pParse->nTempReg = 0;
117702 pParse->nRangeReg = 0;
117724 for(i=0; i<pList->nExpr; i++){
117730 pParse->nTempReg = 0;
117731 pParse->nRangeReg = 0;
117744 if( pParse->nRangeReg>0
117748 return 0;
117750 for(i=0; i<pParse->nTempReg; i++){
117752 return 0;
117757 for(i=0; i<pList->nExpr; i++){
117759 if( iReg==0 ) continue;
117760 if( iReg>=iFirst && iReg<=iLast ) return 0;
117800 if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)
117802 || (pTab->tabFlags & TF_Eponymous)!=0
117803 || ( (pTab->tabFlags & TF_Shadow)!=0
117811 return 0;
117839 if( bTemp==0 ){
117865 if( bTemp==0 ){
117883 sqlite3VdbeAddParseSchemaOp(pParse->pVdbe, iDb, 0, p5);
117884 if( iDb!=1 ) sqlite3VdbeAddParseSchemaOp(pParse->pVdbe, 1, 0, p5);
117900 char *zName = 0; /* NULL-terminated version of pName */
117905 VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */
117911 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
117951 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
117962 if( pVTab->pVtab->pModule->xRename==0 ){
117963 pVTab = 0;
117973 if( v==0 ){
118030 " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename', 0) "
118045 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
118050 renameTestSchema(pParse, zDb, iDb==1, "after rename", 0);
118097 assert( db->mallocFailed==0 );
118112 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
118131 if( (pCol->colFlags & COLFLAG_GENERATED)==0 ){
118133 ** literal NULL, then set pDflt to 0. This simplifies checking
118136 assert( pDflt==0 || pDflt->op==TK_SPAN );
118138 pDflt = 0;
118155 sqlite3_value *pVal = 0;
118179 *zEnd-- = '\0';
118215 if( pNew->pCheck!=0
118216 || (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0)
118217 || (pTab->tabFlags & TF_Strict)!=0
118260 assert( pParse->pNewTable==0 );
118263 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
118284 assert( pTab->u.tab.addColOffset>0 );
118299 assert( pNew->nCol>0 );
118301 assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
118309 for(i=0; i<pNew->nCol; i++){
118315 pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0);
118335 const char *zType = 0;
118353 return 0;
118356 # define isRealTable(x,y,z) (0)
118373 char *zOld = 0; /* Old column name */
118374 char *zNew = 0; /* New column name */
118380 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
118385 if( SQLITE_OK!=isRealTable(pParse, pTab, 0) ) goto exit_rename_column;
118389 assert( iSchema>=0 );
118394 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
118404 if( iCol<0 ){
118410 renameTestSchema(pParse, zDb, iSchema==1, "", 0);
118420 assert( pNew->n>0 );
118421 bQuote = sqlite3Isquote(pNew->z[0]);
118512 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
118513 if( pParse->nErr==0 ){
118522 assert( i>0 );
118583 sqlite3RenameTokenRemap(pParse, 0, (const void*)pExpr);
118585 sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab);
118599 With *pCopy = 0;
118600 assert( pWith->nCte>0 );
118601 if( (pWith->a[0].pSelect->selFlags & SF_Expanded)==0 ){
118610 for(i=0; i<pWith->nCte; i++){
118613 memset(&sNC, 0, sizeof(sNC));
118634 assert( pIdList!=0 );
118635 for(ii=0; ii<pIdList->nId; ii++){
118636 sqlite3RenameTokenRemap(pParse, 0, (const void*)pIdList->a[ii].zName);
118654 for(i=0; i<pList->nExpr; i++){
118656 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
118662 for(i=0; i<pSrc->nSrc; i++){
118663 sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
118664 if( pSrc->a[i].fg.isUsing==0 ){
118682 memset(&sWalker, 0, sizeof(Walker));
118699 memset(&sWalker, 0, sizeof(Walker));
118703 for(i=0; i<pEList->nExpr; i++){
118705 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
118738 if( NEVER(pPtr==0) ){
118739 return 0;
118753 return 0;
118839 zT, zN, (zWhen[0] ? " " : ""), zWhen,
118860 for(i=0; i<pEList->nExpr; i++){
118863 && ALWAYS(zName!=0)
118864 && 0==sqlite3_stricmp(zName, zOld)
118885 for(i=0; i<pIdList->nId; i++){
118887 if( 0==sqlite3_stricmp(zName, zOld) ){
118910 if( zSql==0 ){
118913 if( sqlite3StrNICmp(zSql,"CREATE ",7)!=0 ){
118920 assert( iDb>=0 && iDb<=0xff );
118927 testcase( (db->flags & SQLITE_Comments)==0 && strstr(zSql," /* ")!=0 );
118933 && NEVER(p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0)
118950 db->init.iDb = 0;
118974 char *zQuot = 0;
118976 i64 nQuot = 0;
118977 char *zBuf1 = 0;
118978 char *zBuf2 = 0;
118987 if( zQuot==0 ){
118993 assert( nQuot>=nNew && nSql>=0 && nNew>=0 );
118996 assert( nSql>0 );
119010 assert( nSql>0 );
119019 if( bQuote==0 && sqlite3IsIdChar(*(u8*)pBest->t.z) ){
119035 zBuf1[pBest->t.n] = 0;
119037 assert( nSql < 0x15555554 /* otherwise malloc would have failed */ );
119051 zOut[nOut] = '\0';
119074 for(i=0; i<pEList->nExpr; i++){
119076 pEList->a[i].fg.eEName = val&0x3;
119094 memset(&sNC, 0, sizeof(sNC));
119104 rc = sqlite3ViewGetColumnNames(pParse, pParse->pTriggerTab)!=0;
119121 pParse, pStep->pExprList, pSrc, 0, 0, 0, 0, 0, 0
119123 if( pSel==0 ){
119124 pStep->pExprList = 0;
119125 pSrc = 0;
119137 sqlite3SelectPrep(pParse, pSel, 0);
119140 assert( pStep->pExprList==0 || pStep->pExprList==pSel->pEList );
119142 if( pStep->pExprList ) pSel->pEList = 0;
119143 pSel->pSrc = 0;
119148 for(i=0; i<pStep->pFrom->nSrc && rc==SQLITE_OK; i++){
119151 assert( p->u4.pSubq!=0 );
119152 sqlite3SelectPrep(pParse, p->u4.pSubq->pSelect, 0);
119184 sNC.ncFlags = 0;
119186 sNC.pSrcList = 0;
119221 for(i=0; i<pFrom->nSrc; i++){
119223 assert( pFrom->a[i].u4.pSubq!=0 );
119242 while( (pIdx = pParse->pNewIndex)!=0 ){
119257 ** 0. zSql: SQL statement to rewrite
119268 ** The iCol-th column (left-most is 0) of table zTable is renamed from zCol
119283 const char *zSql = (const char*)sqlite3_value_text(argv[0]);
119302 if( zSql==0 ) return;
119303 if( zTable==0 ) return;
119304 if( zNew==0 ) return;
119305 if( iCol<0 ) return;
119308 if( pTab==0 || iCol>=pTab->nCol ){
119313 memset(&sCtx, 0, sizeof(sCtx));
119317 db->xAuth = 0;
119322 memset(&sWalker, 0, sizeof(Walker));
119335 sqlite3SelectPrep(&sParse, pSelect, 0);
119346 if( bFKOnly==0 ){
119352 if( sCtx.iCol<0 ){
119363 for(i=0; i<sParse.pNewTable->nCol; i++){
119373 for(i=0; i<pFKey->nCol; i++){
119374 if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
119377 if( 0==sqlite3_stricmp(pFKey->zTo, zTable)
119378 && 0==sqlite3_stricmp(pFKey->aCol[i].zCol, zOld)
119396 Table *pTarget = sqlite3LocateTable(&sParse, 0, pStep->zTarget, zDb);
119424 sqlite3_result_value(context, argv[0]);
119466 if( NEVER(pSrc==0) ){
119470 for(i=0; i<pSrc->nSrc; i++){
119488 ** 0: The database containing the table being renamed.
119498 ** sqlite_rename_table('main', 'CREATE TABLE t1(a REFERENCES t2)','t2','t3',0)
119507 const char *zDb = (const char*)sqlite3_value_text(argv[0]);
119523 db->xAuth = 0;
119528 memset(&sCtx, 0, sizeof(RenameCtx));
119530 memset(&sWalker, 0, sizeof(Walker));
119544 if( isLegacy==0 ){
119547 memset(&sNC, 0, sizeof(sNC));
119562 if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys))
119568 if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
119578 if( sqlite3_stricmp(zOld, pTab->zName)==0 ){
119580 if( isLegacy==0 ){
119590 if( isLegacy==0 ){
119599 if( 0==sqlite3_stricmp(sParse.pNewTrigger->table, zOld)
119605 if( isLegacy==0 ){
119610 if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){
119615 for(i=0; i<pStep->pFrom->nSrc; i++){
119617 if( 0==sqlite3_stricmp(pItem->zName, zOld) ){
119667 ** 0: Database name ("main", "temp" etc.).
119693 char const *zDb = (const char*)sqlite3_value_text(argv[0]);
119698 db->xAuth = 0;
119707 rc = renameParseSql(&sParse, zDb, db, zInput, 0);
119714 memset(&sCtx, 0, sizeof(RenameCtx));
119715 memset(&sWalker, 0, sizeof(Walker));
119726 sqlite3SelectPrep(&sParse, pSelect, 0);
119735 for(i=0; i<sParse.pNewTable->nCol; i++){
119755 rc = renameEditSql(context, &sCtx, zInput, 0, 0);
119784 ** 0: Database name ("main", "temp" etc.).
119806 char const *zDb = (const char*)sqlite3_value_text(argv[0]);
119815 db->xAuth = 0;
119828 if( isLegacy==0 && sParse.pNewTable && IsView(sParse.pNewTable) ){
119830 memset(&sNC, 0, sizeof(sNC));
119837 if( isLegacy==0 ){
119868 ** argv[0]: An integer - the index of the schema containing the table
119881 int iSchema = sqlite3_value_int(argv[0]);
119890 char *zNew = 0;
119894 db->xAuth = 0;
119901 if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
119907 pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zCnName);
119910 pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName);
119915 while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
119945 char *zCol = 0; /* Name of column to drop */
119949 assert( pParse->pNewTable==0 );
119952 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
119962 if( zCol==0 ){
119967 if( iCol<0 ){
119990 assert( iDb>=0 );
119998 renameTestSchema(pParse, zDb, iDb==1, "", 0);
120012 if( pParse->nErr==0 && (pTab->aCol[iCol].colFlags & COLFLAG_VIRTUAL)==0 ){
120017 Index *pPk = 0;
120018 int nField = 0; /* Number of non-virtual columns after drop */
120031 for(i=0; i<pPk->nKeyCol; i++){
120037 for(i=0; i<pTab->nCol; i++){
120038 if( i!=iCol && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
120049 sqlite3VdbeAddOp2(v, OP_Null, 0, regOut);
120061 if( nField==0 ){
120064 sqlite3VdbeAddOp2(v, OP_Null, 0, reg+1);
120130 ** created and used by SQLite versions 3.7.9 through 3.29.0 when
120177 ** The sqlite_stat2 entries for an index that have sampleno between 0 and 9
120185 ** For i between 0 and S-1. Conceptually, the index space is divided into
120248 # define IsStat4 0
120264 ** If zWhere==0, then code is generated to delete all stat table entries.
120281 { "sqlite_stat4", 0 },
120283 { "sqlite_stat3", 0 },
120297 if( v==0 ) return;
120305 for(i=0; i<ArraySize(aTable); i++){
120308 aCreateTbl[i] = 0;
120309 if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){
120345 for(i=0; i<nToOpen; i++){
120398 int nMaxEqZero; /* Max leading 0 in anEq[] for any a[] entry */
120408 assert( db!=0 );
120411 p->nRowid = 0;
120420 assert( db!=0 );
120427 p->nRowid = 0;
120436 assert( db!=0 );
120438 p->nRowid = 0;
120471 for(i=0; i<p->nCol; i++) sampleClear(p->db, p->aBest+i);
120472 for(i=0; i<p->mxSample; i++) sampleClear(p->db, p->a+i);
120485 ** L: A limit on the number of rows to scan, or 0 for no-limit
120513 /* Maximum number of samples. 0 if STAT4 data is not collected */
120514 int mxSample = OptimizationEnabled(db,SQLITE_Stat4) ?SQLITE_STAT4_SAMPLES :0;
120519 nCol = sqlite3_value_int(argv[0]);
120520 assert( nCol>0 );
120524 assert( nKeyCol>0 );
120538 if( p==0 ){
120545 p->nRow = 0;
120549 p->nSkipAhead = 0;
120554 p->mxSample = p->nLimit==0 ? mxSample : 0;
120562 p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]);
120568 for(i=0; i<(mxSample+nCol); i++){
120575 for(i=0; i<nCol; i++){
120590 0, /* pUserData */
120591 0, /* pNext */
120593 0, /* xFinalize */
120594 0, 0, /* xValue, xInverse */
120596 {0}
120621 if( pNew->anEq[i]<pOld->anEq[i] ) return 0;
120624 return 0;
120643 assert( pOld->isPSample==0 && pNew->isPSample==0 );
120644 assert( IsStat4 || (pNew->iCol==0 && pOld->iCol==0) );
120651 return 0;
120659 StatSample *pSample = 0;
120662 assert( IsStat4 || nEqZero==0 );
120664 /* StatAccum.nMaxEqZero is set to the maximum number of leading 0
120667 ** are no samples with StatSample.anEq[m]==0 for (m>=n). */
120671 if( pNew->isPSample==0 ){
120672 StatSample *pUpgrade = 0;
120673 assert( pNew->anEq[pNew->iCol]>0 );
120680 for(i=p->nSample-1; i>=0; i--){
120682 if( pOld->anEq[pNew->iCol]==0 ){
120686 if( pUpgrade==0 || sampleIsBetter(p, pOld, pUpgrade) ){
120705 memmove(pMin, &pMin[1], sizeof(p->a[0])*(p->nSample-p->iMin-1));
120707 pSample->nRowid = 0;
120717 assert( p->nSample==0
120726 memset(pSample->anEq, 0, sizeof(tRowcnt)*nEqZero);
120731 for(i=0; i<p->mxSample; i++){
120733 if( iMin<0 || sampleIsBetter(p, &p->a[iMin], &p->a[i]) ){
120737 assert( iMin>=0 );
120765 for(i=p->nSample-1; i>=0; i--){
120767 for(j=p->nMaxEqZero; j<p->nCol; j++) assert( p->a[i].anEq[j]>0 );
120772 for(i=p->nSample-1; i>=0; i--){
120775 if( p->a[i].anEq[j]==0 ) p->a[i].anEq[j] = p->current.anEq[j];
120810 StatAccum *p = (StatAccum*)sqlite3_value_blob(argv[0]);
120815 assert( p->nCol>0 );
120818 if( p->nRow==0 ){
120821 for(i=0; i<p->nCol; i++) p->current.anEq[i] = 1;
120832 for(i=0; i<iChng; i++){
120861 p->current.iCol = 0;
120863 p->current.isPSample = 0;
120867 for(i=0; i<(p->nCol-1); i++){
120877 sqlite3_result_int(context, p->current.anDLt[0]>0);
120884 0, /* pUserData */
120885 0, /* pNext */
120887 0, /* xFinalize */
120888 0, 0, /* xValue, xInverse */
120890 {0}
120893 #define STAT_GET_STAT1 0 /* "stat" column of stat1 table */
120923 StatAccum *p = (StatAccum*)sqlite3_value_blob(argv[0]);
120967 sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
120970 for(i=0; i<p->nKeyCol; i++){
120976 assert( p->current.anEq[i] || p->nRow==0 );
120983 if( p->iGet<0 ){
120984 samplePushPrevious(p, 0);
120985 p->iGet = 0;
120989 if( pS->nRowid==0 ){
120997 tRowcnt *aCnt = 0;
121011 sqlite3StrAccumInit(&sStat, 0, 0, 0, p->nCol*100);
121012 for(i=0; i<p->nCol; i++){
121026 0, /* pUserData */
121027 0, /* pNext */
121029 0, /* xFinalize */
121030 0, 0, /* xValue, xInverse */
121032 {0}
121044 sqlite3VdbeAddFunctionCall(pParse, 0, regStat, regOut, 1+IsStat4,
121045 &statGetFuncdef, 0);
121058 assert( k>=0 && k<pIdx->nColumn );
121108 Table *pStat1 = 0;
121114 if( v==0 || NEVER(pTab==0) ){
121121 if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){
121127 assert( iDb>=0 );
121128 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
121130 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
121139 if( pStat1==0 ) return;
121144 sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNAMIC);
121152 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
121167 if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0;
121185 ** regChng = 0
121188 ** stat_init() with count = 0;
121196 ** regChng = 0
121197 ** if( idx(0) != regPrev(0) ) goto chng_addr_0
121205 ** regPrev(0) = idx(0)
121233 ** regChng = 0
121236 ** stat_init() with count = 0;
121256 sqlite3VdbeAddFunctionCall(pParse, 0, regStat+1, regStat, 4,
121257 &statInitFuncdef, 0);
121261 sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
121264 if( nColTest>0 ){
121268 if( aGotoChng==0 ) continue;
121272 ** regChng = 0
121273 ** if( idx(0) != regPrev(0) ) goto chng_addr_0
121289 for(i=0; i<nColTest; i++){
121295 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
121305 ** regPrev(0) = idx(0)
121311 for(i=0; i<nColTest; i++){
121336 for(j=0; j<pPk->nKeyCol; j++){
121338 assert( k>=0 && k<pIdx->nColumn );
121350 &statPushFuncdef, 0);
121355 j3 = sqlite3VdbeAddOp4Int(v, OP_SeekGT, iIdxCur, 0, regPrev, 1);
121371 addrGotoEnd = 0;
121374 assert( "BBB"[0]==SQLITE_AFF_TEXT );
121375 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
121385 if( OptimizationEnabled(db, SQLITE_Stat4) && db->nAnalysisLimit==0 ){
121397 if( addrGotoEnd==0 ){
121420 doOnce = 0;
121440 sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
121442 for(i=0; i<nCol; i++){
121462 if( pOnlyIdx==0 && needTableCnt ){
121466 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
121467 assert( "BBB"[0]==SQLITE_AFF_TEXT );
121468 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
121502 sqlite3BeginWriteOperation(pParse, 0, iDb);
121505 openStatTable(pParse, iDb, iStatCur, 0, 0);
121508 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
121511 analyzeOneTable(pParse, pTab, 0, iStatCur, iMem, iTab);
121530 assert( pTab!=0 );
121533 sqlite3BeginWriteOperation(pParse, 0, iDb);
121574 assert( pName2!=0 || pName1==0 );
121575 if( pName1==0 ){
121577 for(i=0; i<db->nDb; i++){
121581 }else if( pName2->n==0 && (iDb = sqlite3FindDb(db, pName1))>=0 ){
121587 if( iDb>=0 ){
121588 zDb = pName2->n ? db->aDb[iDb].zDbSName : 0;
121591 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
121593 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
121594 analyzeTable(pParse, pTab, 0);
121600 if( db->nSqlExec==0 && (v = sqlite3GetVdbe(pParse))!=0 ){
121624 LogEst *aLog, /* Or, if aOut==0, here */
121633 if( z==0 ) z = "";
121635 assert( z!=0 );
121637 for(i=0; *z && i<nOut; i++){
121638 v = 0;
121639 while( (c=z[0])>='0' && c<='9' ){
121640 v = v*10 + c - '0';
121647 assert( aOut==0 );
121649 assert( aLog!=0 );
121655 assert( pIndex!=0 ); {
121659 pIndex->bUnordered = 0;
121660 pIndex->noSkipScan = 0;
121661 while( z[0] ){
121662 if( sqlite3_strglob("unordered*", z)==0 ){
121664 }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
121668 }else if( sqlite3_strglob("noskipscan*", z)==0 ){
121672 else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){
121676 while( z[0]!=0 && z[0]!=' ' ) z++;
121677 while( z[0]==' ' ) z++;
121686 ** argv[0] = name of the table
121702 if( argv==0 || argv[0]==0 || argv[2]==0 ){
121703 return 0;
121705 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
121706 if( pTable==0 ){
121707 return 0;
121709 if( argv[1]==0 ){
121710 pIndex = 0;
121711 }else if( sqlite3_stricmp(argv[0],argv[1])==0 ){
121719 tRowcnt *aiRowEst = 0;
121725 if( pIndex->aiRowEst==0 ){
121727 if( pIndex->aiRowEst==0 ) sqlite3OomFault(pInfo->db);
121731 pIndex->bUnordered = 0;
121734 if( pIndex->pPartIdxWhere==0 ){
121735 pTable->nRowLogEst = pIndex->aiRowLogEst[0];
121744 decodeIntArray((char*)z, 1, 0, &pTable->nRowLogEst, &fakeIdx);
121749 return 0;
121757 assert( db!=0 );
121758 assert( pIdx!=0 );
121762 for(j=0; j<pIdx->nSample; j++){
121768 if( db->pnBytesFreed==0 ){
121769 pIdx->nSample = 0;
121770 pIdx->aSample = 0;
121797 for(iCol=0; iCol<nCol; iCol++){
121800 tRowcnt sumEq = 0; /* Sum of the nEq values */
121801 tRowcnt avgEq = 0;
121803 i64 nSum100 = 0; /* Number of terms contributing to sumEq */
121806 if( !pIdx->aiRowEst || iCol>=pIdx->nKeyCol || pIdx->aiRowEst[iCol+1]==0 ){
121811 nRow = pIdx->aiRowEst[0];
121812 nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
121820 for(i=0; i<nSample; i++){
121832 if( avgEq==0 ) avgEq = 1;
121848 if( pIdx==0 ){
121874 sqlite3_stmt *pStmt = 0; /* An SQL statement being run */
121876 Index *pPrevIdx = 0; /* Previous index in the loop */
121884 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
121899 zIndex = (char *)sqlite3_column_text(pStmt, 0);
121900 if( zIndex==0 ) continue;
121903 assert( pIdx==0 || pIdx->nSample==0 );
121904 if( pIdx==0 ) continue;
121905 if( pIdx->aSample!=0 ){
121922 if( pIdx->aSample==0 ){
121927 pPtr += ROUND8(nSample*sizeof(pIdx->aSample[0]));
121932 for(i=0; i<nSample; i++){
121946 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
121955 zIndex = (char *)sqlite3_column_text(pStmt, 0);
121956 if( zIndex==0 ) continue;
121958 if( pIdx==0 ) continue;
121972 decodeIntArray((char*)sqlite3_column_text(pStmt,1),nCol,pSample->anEq,0,0);
121973 decodeIntArray((char*)sqlite3_column_text(pStmt,2),nCol,pSample->anLt,0,0);
121974 decodeIntArray((char*)sqlite3_column_text(pStmt,3),nCol,pSample->anDLt,0,0);
121976 /* Take a copy of the sample. Add 8 extra 0x00 bytes the end of the buffer.
121981 ** buffer. In any case, eight 0x00 bytes prevents this from causing
121985 if( pSample->p==0 ){
122009 && (pStat4 = sqlite3FindTable(db, "sqlite_stat4", zDb))!=0
122050 assert( iDb>=0 && iDb<db->nDb );
122051 assert( db->aDb[iDb].pBt!=0 );
122054 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
122061 pIdx->hasStat1 = 0;
122064 pIdx->aSample = 0;
122076 if( zSql==0 ){
122079 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
122085 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
122101 pIdx->aiRowEst = 0;
122169 sqlite3StrICmp(db->aDb[iDb].zDbSName, zName)==0
122170 || (iDb==0 && sqlite3StrICmp("main", zName)==0)
122195 int rc = 0;
122199 char *zPath = 0;
122200 char *zErr = 0;
122203 Db *pNew = 0; /* Db object for the newly attached database */
122204 char *zErrDyn = 0;
122208 zFile = (const char *)sqlite3_value_text(argv[0]);
122210 if( zFile==0 ) zFile = "";
122211 if( zName==0 ) zName = "";
122216 # define REOPEN_AS_MEMDB(db) (0)
122223 Btree *pNewBt = 0;
122225 if( pVfs==0 ) return;
122226 rc = sqlite3BtreeOpen(pVfs, "x\0", db, &pNewBt, 0, SQLITE_OPEN_MAIN_DB);
122258 for(i=0; i<db->nDb; i++){
122270 aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 );
122271 if( aNew==0 ) return;
122272 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
122274 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(1+(i64)db->nDb));
122275 if( aNew==0 ) return;
122279 memset(pNew, 0, sizeof(*pNew));
122293 if( (db->flags & SQLITE_AttachWrite)==0 ){
122296 }else if( (db->flags & SQLITE_AttachCreate)==0 ){
122301 rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags);
122305 db->noSharedCache = 0;
122323 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
122331 if( rc==SQLITE_OK && pNew->zDbSName==0 ){
122343 db->init.iDb = 0;
122356 assert( zErrDyn==0 || rc!=SQLITE_OK );
122364 db->aDb[iDb].pBt = 0;
122365 db->aDb[iDb].pSchema = 0;
122373 }else if( zErrDyn==0 ){
122404 const char *zName = (const char *)sqlite3_value_text(argv[0]);
122407 Db *pDb = 0;
122413 if( zName==0 ) zName = "";
122414 for(i=0; i<db->nDb; i++){
122416 if( pDb->pBt==0 ) continue;
122448 pDb->pBt = 0;
122449 pDb->pSchema = 0;
122479 memset(&sName, 0, sizeof(NameContext));
122497 zAuthArg = 0;
122499 rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
122515 sqlite3VdbeAddFunctionCall(pParse, 0, regArgs+3-pFunc->nArg, regArgs+3,
122516 pFunc->nArg, pFunc, 0);
122539 0, /* pUserData */
122540 0, /* pNext */
122542 0, /* xFinalize */
122543 0, 0, /* xValue, xInverse */
122545 {0}
122547 codeAttach(pParse, SQLITE_DETACH, &detach_func, pDbname, 0, 0, pDbname);
122559 0, /* pUserData */
122560 0, /* pNext */
122562 0, /* xFinalize */
122563 0, 0, /* xValue, xInverse */
122565 {0}
122599 if( NEVER(pList==0) ) return WRC_Continue;
122600 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
122601 if( pFix->bTemp==0 && pItem->fg.isSubquery==0 ){
122602 if( pItem->fg.fixedSchema==0 && pItem->u4.zDatabase!=0 ){
122618 if( pList->a[i].fg.isUsing==0
122626 for(i=0; i<pSelect->pWith->nCte; i++){
122658 pFix->w.walkerDepth = 0;
122659 pFix->w.eCode = 0;
122675 ** checks out, these routines return 0.
122681 int res = 0;
122684 memset(&s, 0, sizeof(s));
122735 return 0;
122858 if( db->nDb>2 || iDb!=0 ) z = sqlite3_mprintf("%s.%z", zDb, z);
122882 Table *pTab = 0; /* The table being read */
122890 assert( pParse->db->xAuth!=0 );
122892 if( iDb<0 ){
122902 for(iSrc=0; iSrc<pTabList->nSrc; iSrc++){
122910 if( pTab==0 ) return;
122912 if( iCol>=0 ){
122915 }else if( pTab->iPKey>=0 ){
122921 assert( iDb>=0 && iDb<pParse->db->nDb );
122946 assert( !IN_RENAME_OBJECT || db->xAuth==0 );
122947 if( db->xAuth==0 || db->init.busy || IN_SPECIAL_PARSE ){
122957 testcase( zArg1==0 );
122958 testcase( zArg2==0 );
122959 testcase( zArg3==0 );
122960 testcase( pParse->zAuthContext==0 );
122976 ** popped. Or if pParse==0, this routine is a no-op.
122996 pContext->pParse = 0;
123063 assert( iDb>=0 );
123066 for(i=0; i<pToplevel->nTableLock; i++){
123074 assert( pToplevel->nTableLock < 0x7fff0000 );
123085 pToplevel->nTableLock = 0;
123108 assert( pVdbe!=0 );
123110 for(i=0; i<pParse->nTableLock; i++){
123129 for(i=0; i<sizeof(yDbMask); i++) if( m[i] ) return 0;
123149 assert( pParse->pToplevel==0 );
123157 assert( db->mallocFailed==0 );
123163 if( v==0 ){
123169 if( v==0 ) pParse->rc = SQLITE_ERROR;
123187 for(i=0; i<pReturning->nRetCol; i++){
123199 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
123204 assert( pParse->nErr>0 || sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
123205 sqlite3VdbeJumpHere(v, 0);
123206 assert( db->nDb>0 );
123207 iDb = 0;
123210 if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
123220 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
123225 for(i=0; i<pParse->nVtabLock; i++){
123227 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
123229 pParse->nVtabLock = 0;
123248 pParse->okConstFactor = 0;
123249 for(i=0; i<pEL->nExpr; i++){
123250 assert( pEL->a[i].u.iConstExprReg>0 );
123270 assert( v!=0 || pParse->nErr );
123271 assert( db->mallocFailed==0 || pParse->nErr );
123272 if( pParse->nErr==0 ){
123275 assert( pParse->pAinc==0 || pParse->nTab>0 );
123309 if( zSql==0 ){
123319 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
123333 ** If zDatabase is 0, all databases are searched for the table and the
123341 Table *p = 0;
123345 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
123347 for(i=0; i<db->nDb; i++){
123348 if( sqlite3StrICmp(zDatabase, db->aDb[i].zDbSName)==0 ) break;
123352 ** to schema 0 as a legacy fallback. */
123353 if( sqlite3StrICmp(zDatabase,"main")==0 ){
123354 i = 0;
123356 return 0;
123360 if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
123362 if( sqlite3StrICmp(zName+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0
123363 || sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0
123364 || sqlite3StrICmp(zName+7, &LEGACY_SCHEMA_TABLE[7])==0
123370 if( sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0 ){
123381 p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, zName);
123385 assert( sqlite3SchemaMutexHeld(db, i, 0) );
123389 if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
123390 if( sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0 ){
123391 p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, LEGACY_SCHEMA_TABLE);
123392 }else if( sqlite3StrICmp(zName+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 ){
123422 if( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0
123425 return 0;
123429 if( p==0 ){
123434 if( (pParse->prepFlags & SQLITE_PREPARE_NO_VTAB)==0 && db->init.busy==0 ){
123436 if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
123440 testcase( pMod->pEpoTab==0 );
123445 if( flags & LOCATE_NOERR ) return 0;
123447 }else if( IsVirtual(p) && (pParse->prepFlags & SQLITE_PREPARE_NO_VTAB)!=0 ){
123448 p = 0;
123451 if( p==0 ){
123459 assert( HasRowid(p) || p->iPKey<0 );
123495 if( sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
123496 if( sqlite3StrICmp(zName+7, &LEGACY_SCHEMA_TABLE[7])==0 ){
123499 if( sqlite3StrICmp(zName+7, &LEGACY_TEMP_SCHEMA_TABLE[7])==0 ){
123512 ** If zDatabase is 0, all databases are searched for the
123519 Index *p = 0;
123522 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
123527 if( zDb && sqlite3DbIsNamed(db, j, zDb)==0 ) continue;
123528 assert( sqlite3SchemaMutexHeld(db, j, 0) );
123562 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
123564 pIndex = sqlite3HashInsert(pHash, zIdxName, 0);
123588 ** Entry 0 (the "main" database) and entry 1 (the "temp" database)
123595 if( pDb->pBt==0 ){
123597 pDb->zDbSName = 0;
123607 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
123616 ** Deferred resets may be run by calling with iDb<0.
123622 if( iDb>=0 ){
123623 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
123629 if( db->nSchemaLock==0 ){
123630 for(i=0; i<db->nDb; i++){
123645 for(i=0; i<db->nDb; i++){
123648 if( db->nSchemaLock==0 ){
123658 if( db->nSchemaLock==0 ){
123684 if( pCol->iDflt==0
123685 || NEVER(pList==0)
123688 pCol->iDflt = pList==0 ? 1 : pList->nExpr+1;
123702 if( pCol->iDflt==0 ) return 0;
123703 if( !IsOrdinaryTable(pTab) ) return 0;
123704 if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
123705 if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
123720 assert( zColl!=0 );
123739 if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0;
123755 assert( pTable!=0 );
123756 assert( db!=0 );
123757 if( (pCol = pTable->aCol)!=0 ){
123758 for(i=0; i<pTable->nCol; i++, pCol++){
123759 assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
123766 if( db->pnBytesFreed==0 ){
123767 pTable->aCol = 0;
123768 pTable->nCol = 0;
123770 pTable->u.tab.pDfltList = 0;
123802 int nLookaside = 0;
123803 assert( db!=0 );
123804 if( !db->mallocFailed && (pTable->tabFlags & TF_Ephemeral)==0 ){
123805 nLookaside = sqlite3LookasideUsed(db, 0);
123814 if( db->pnBytesFreed==0 && !IsVirtual(pTable) ){
123817 &pIndex->pSchema->idxHash, zName, 0
123819 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
123820 assert( pOld==pIndex || pOld==0 );
123847 assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) );
123851 assert( db!=0 );
123853 if( db->pnBytesFreed==0 && (--pTable->nTabRef)>0 ) return;
123869 assert( db!=0 );
123870 assert( iDb>=0 && iDb<db->nDb );
123872 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
123873 testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
123875 p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, 0);
123899 zName = 0;
123906 ** writing. The table is opened using cursor 0.
123911 sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, SCHEMA_ROOT, iDb, 5);
123912 if( p->nTab==0 ){
123927 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
123928 if( 0==sqlite3_stricmp(pDb->zDbSName, zName) ) break;
123931 if( i==0 && 0==sqlite3_stricmp("main", zName) ) break;
123977 assert( pName2!=0 );
123978 if( pName2->n>0 ){
123985 if( iDb<0 ){
123990 assert( db->init.iDb==0 || db->init.busy || IN_SPECIAL_PARSE
123991 || (db->mDbFlags & DBFLAG_Vacuum)!=0);
124002 testcase( (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))==0 );
124038 if( sqlite3_stricmp(zType, db->init.azInit[0])
124046 if( (pParse->nested==0 && 0==sqlite3StrNICmp(zName, "sqlite_", 7))
124079 for(i=0; i<pIdx->nColumn; i++){
124090 ** The storage column number (0,1,2,....) is the index of the value
124092 ** is the index (0,1,2,...) of the column in the CREATE TABLE statement.
124102 for(i=0; i<=iCol; i++){
124113 ** The storage column number (0,1,2,....) is the index of the value
124118 ** The true column number is the index (0,1,2,...) of the column in
124132 ** -- 0 1 2 3 4 5 6 7 8
124136 ** INPUTS: 0 1 2 3 4 5 6 7 8
124137 ** OUTPUTS: 0 1 6 2 3 7 4 5 8
124151 if( (pTab->tabFlags & TF_HasVirtual)==0 || iCol<0 ) return iCol;
124152 for(i=0, n=0; i<iCol; i++){
124153 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) n++;
124177 sqlite3VdbeAddOp3(v, OP_JournalMode, 0, iReg, PAGER_JOURNALMODE_QUERY);
124178 sqlite3VdbeUsesBtree(v, 0);
124208 char *zName = 0; /* The name of the new table */
124222 if( iDb<0 ) return;
124223 if( !OMIT_TEMPDB && isTemp && pName2->n>0 && iDb!=1 ){
124236 if( zName==0 ) return;
124242 assert( isTemp==0 || isTemp==1 );
124243 assert( isView==0 || isView==1 );
124252 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
124256 zName, 0, zDb) ){
124286 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
124293 if( pTable==0 ){
124308 assert( pParse->pNewTable==0 );
124319 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
124324 static const char nullRow[] = { 6, 0, 0, 0, 0, 0 };
124343 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
124360 sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
124369 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
124370 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
124371 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
124391 if( sqlite3_strnicmp(pCol->zCnName, "__hidden__", 10)==0 ){
124407 sqlite3HashInsert(pHash, pRet->zName, 0);
124435 assert( pParse->bReturning==0 || pParse->ifNotExists );
124439 if( pRet==0 ){
124463 assert( sqlite3HashFind(pHash, pRet->zName)==0
124491 if( (p = pParse->pNewTable)==0 ) return;
124503 && sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0
124506 while( ALWAYS(sType.n>0) && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--;
124508 && sqlite3_strnicmp(sType.z+(sType.n-9),"generated",9)==0
124511 while( sType.n>0 && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--;
124520 for(i=0; i<SQLITE_N_STDTYPE; i++){
124522 && sqlite3_strnicmp(sType.z, sqlite3StdType[i], sType.n)==0
124524 sType.n = 0;
124533 z = sqlite3DbMallocRaw(db, (i64)sName.n + 1 + (i64)sType.n + (sType.n>0) );
124534 if( z==0 ) return;
124537 z[sName.n] = 0;
124539 if( p->nCol && sqlite3ColumnIndex(p, z)>=0 ){
124544 aNew = sqlite3DbRealloc(db,p->aCol,((i64)p->nCol+1)*sizeof(p->aCol[0]));
124545 if( aNew==0 ){
124551 memset(pCol, 0, sizeof(p->aCol[0]));
124556 if( sType.n==0 ){
124572 zType[sType.n] = 0;
124577 if( p->nCol<=0xff ){
124584 pParse->u1.cr.constraintName.n = 0;
124597 if( p==0 || NEVER(p->nCol<1) ) return;
124608 if( pIdx->aiColumn[0]==p->nCol-1 ){
124641 u32 h = 0;
124643 const char *zChar = 0;
124645 assert( zIn!=0 );
124646 while( zIn[0] ){
124660 if( zIn[0]=='(' ) zChar = zIn;
124672 }else if( (h&0x00FFFFFF)==(('i'<<16)+('n'<<8)+'t') ){ /* INT */
124681 int v = 0; /* default size is approx 4 bytes */
124684 while( zChar[0] ){
124685 if( sqlite3Isdigit(zChar[0]) ){
124728 if( p!=0 ){
124745 memset(&x, 0, sizeof(x));
124826 Column *pCol = 0;
124829 if( pTab==0 ) goto primary_key_exit;
124836 if( pList==0 ){
124843 for(i=0; i<nTerm; i++){
124845 assert( pCExpr!=0 );
124850 if( iCol>=0 ){
124863 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
124868 assert( autoInc==0 || autoInc==1 );
124870 if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags;
124878 sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
124879 0, sortOrder, 0, SQLITE_IDXTYPE_PRIMARYKEY);
124880 pList = 0;
124910 for(zStart++; sqlite3Isspace(zStart[0]); zStart++){}
124933 if( (p = pParse->pNewTable)==0 || IN_RENAME_OBJECT ) return;
124949 if( pIdx->aiColumn[0]==i ){
124950 pIdx->azColl[0] = sqlite3ColumnColl(&p->aCol[i]);
124965 if( pTab==0 ){
124974 if( pCol->iDflt>0 ) goto generated_error;
124976 if( pType->n==7 && sqlite3StrNICmp("virtual",pType->z,7)==0 ){
124978 }else if( pType->n==6 && sqlite3StrNICmp("stored",pType->z,6)==0 ){
124997 pExpr = sqlite3PExpr(pParse, TK_UPLUS, pExpr, 0);
125001 pExpr = 0;
125039 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
125054 for(n=0; *z; n++, z++){
125078 for(j=0; zIdent[j]; j++){
125081 needQuote = sqlite3Isdigit(zIdent[0])
125083 || zIdent[j]!=0
125084 || j==0;
125087 for(j=0; zIdent[j]; j++){
125092 z[i] = 0;
125107 n = 0;
125108 for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){
125122 zStmt = sqlite3DbMallocRaw(0, n);
125123 if( zStmt==0 ){
125125 return 0;
125127 assert( n>14 && n<=0x7fffffff );
125132 for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
125150 assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 );
125163 || pCol->affinity==sqlite3AffinityType(zType, 0) );
125185 assert( N>0 );
125188 assert( pIdx->isResized==0 );
125191 if( zExtra==0 ) return SQLITE_NOMEM_BKPT;
125212 unsigned wTable = 0;
125215 for(i=pTab->nCol, pTabCol=pTab->aCol; i>0; i--, pTabCol++){
125218 if( pTab->iPKey<0 ) wTable++;
125226 unsigned wIndex = 0;
125229 for(i=0; i<pIdx->nColumn; i++){
125232 wIndex += x<0 ? 1 : aCol[x].szEst;
125242 while( nCol-- > 0 ){
125247 return 0;
125273 for(i=0; i<nKey; i++){
125274 assert( pIdx->aiColumn[i]>=0 || j>=0 );
125276 && sqlite3StrICmp(pIdx->azColl[i], pPk->azColl[iCol])==0
125281 return 0;
125286 ** colNotIdxed is a bitmask that has a 0 bit representing each indexed
125304 Bitmask m = 0;
125307 for(j=pIdx->nColumn-1; j>=0; j--){
125309 if( x>=0 && (pTab->aCol[x].colFlags & COLFLAG_VIRTUAL)==0 ){
125355 for(i=0; i<pTab->nCol; i++){
125356 if( (pTab->aCol[i].colFlags & COLFLAG_PRIMKEY)!=0
125377 if( pTab->iPKey>=0 ){
125381 pList = sqlite3ExprListAppend(pParse, 0,
125382 sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
125383 if( pList==0 ){
125388 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
125390 pList->a[0].fg.sortFlags = pParse->iPkSortOrder;
125393 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
125399 assert( db->mallocFailed==0 );
125404 assert( pPk!=0 );
125423 assert( pPk!=0 );
125432 if( v && pPk->tnum>0 ){
125433 assert( db->init.busy==0 );
125446 for(i=n=0; i<nPk; i++){
125452 if( n==0 ){
125458 for(i=0, j=pIdx->nKeyCol; i<nPk; i++){
125476 nExtra = 0;
125477 for(i=0; i<pTab->nCol; i++){
125479 && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) nExtra++;
125482 for(i=0, j=nPk; i<pTab->nCol; i++){
125484 && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0
125507 if( !IsVirtual(pTab) ) return 0;
125509 if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0;
125510 if( zName[nName]!='_' ) return 0;
125511 pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]);
125512 if( pMod==0 ) return 0;
125513 if( pMod->pModule->iVersion<3 ) return 0;
125514 if( pMod->pModule->xShadowName==0 ) return 0;
125532 pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]);
125533 if( pMod==0 ) return;
125534 if( NEVER(pMod->pModule==0) ) return;
125536 if( pMod->pModule->xShadowName==0 ) return;
125537 assert( pTab->zName!=0 );
125541 assert( pOther->zName!=0 );
125544 if( sqlite3StrNICmp(pOther->zName, pTab->zName, nName)==0
125566 if( zTail==0 ) return 0;
125567 *zTail = 0;
125568 pTab = sqlite3FindTable(db, zName, 0);
125570 if( pTab==0 ) return 0;
125571 if( !IsVirtual(pTab) ) return 0;
125592 memset(&w, 0, sizeof(w));
125595 w.xSelectCallback2 = 0;
125628 u32 tabOpts, /* Extra table options. Usually 0. */
125636 if( pEnd==0 && pSelect==0 ){
125640 if( p==0 ) return;
125642 if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){
125676 for(ii=0; ii<p->nCol; ii++){
125692 if( (pCol->colFlags & COLFLAG_PRIMKEY)!=0
125702 assert( (p->tabFlags & TF_HasPrimaryKey)==0
125703 || p->iPKey>=0 || sqlite3PrimaryKeyIndex(p)!=0 );
125704 assert( (p->tabFlags & TF_HasPrimaryKey)!=0
125705 || (p->iPKey<0 && sqlite3PrimaryKeyIndex(p)==0) );
125714 if( (p->tabFlags & TF_HasPrimaryKey)==0 ){
125727 sqlite3ResolveSelfReference(pParse, p, NC_IsCheck, 0, p->pCheck);
125732 p->pCheck = 0;
125740 int ii, nNG = 0;
125743 for(ii=0; ii<p->nCol; ii++){
125745 if( (colFlags & COLFLAG_GENERATED)!=0 ){
125749 if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){
125757 sqlite3ExprAlloc(db, TK_NULL, 0, 0));
125763 if( nNG==0 ){
125790 if( NEVER(v==0) ) return;
125792 sqlite3VdbeAddOp1(v, OP_Close, 0);
125846 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
125849 if( pSelTab==0 ) return;
125850 assert( p->aCol==0 );
125853 pSelTab->nCol = 0;
125854 pSelTab->aCol = 0;
125864 sqlite3TableAffinity(v, p, 0);
125878 if( pEnd2->z[0]!=';' ) n += pEnd2->n;
125908 if( (p->tabFlags & TF_Autoincrement)!=0 && !IN_SPECIAL_PARSE ){
125910 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
125911 if( pDb->pSchema->pSeqTab==0 ){
125922 sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName),0);
125927 sqlite3VdbeAddOp4(v, OP_SqlExec, 0x0001, 0, 0,
125938 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
125939 assert( HasRowid(p) || p->iPKey<0 );
125946 pParse->pNewTable = 0;
125954 if( strcmp(p->zName, "sqlite_sequence")==0 ){
125955 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
125964 if( pCons->z==0 ){
125991 Token *pName = 0;
125995 if( pParse->nVar>0 ){
125999 sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
126001 if( p==0 || pParse->nErr ) goto create_view_fail;
126028 pSelect = 0;
126040 assert( sEnd.z[0]!=0 || sEnd.n==0 );
126041 if( sEnd.z[0]!=';' ){
126044 sEnd.n = 0;
126046 assert( n>0 );
126053 sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
126075 int nErr = 0; /* Number of errors encountered */
126100 assert( pTable->nCol<=0 );
126117 if( pTable->nCol<0 ){
126121 assert( pTable->nCol>=0 );
126131 pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
126142 db->xAuth = 0;
126150 if( pSelTab==0 ){
126151 pTable->nCol = 0;
126162 if( pParse->nErr==0
126165 assert( db->mallocFailed==0 );
126172 assert( pTable->aCol==0 );
126176 pSelTab->nCol = 0;
126177 pSelTab->aCol = 0;
126178 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
126196 assert( pTable!=0 );
126197 if( !IsVirtual(pTable) && pTable->nCol>0 ) return 0;
126208 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
126245 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
126308 ** OP_Destroy 4 0
126310 ** OP_Destroy 5 0
126314 ** "OP_Destroy 4 0" opcode. The subsequent "OP_Destroy 5 0" would hit
126318 Pgno iDestroyed = 0;
126322 Pgno iLargest = 0;
126324 if( iDestroyed==0 || iTab<iDestroyed ){
126330 if( (iDestroyed==0 || (iIdx<iDestroyed)) && iIdx>iLargest ){
126334 if( iLargest==0 ){
126338 assert( iDb>=0 && iDb<pParse->db->nDb );
126379 assert( v!=0 );
126433 sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
126436 sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
126447 if( (db->flags & SQLITE_Defensive)!=0
126448 && db->pVtabCtx==0
126449 && db->nVdbeExec==0
126455 return 0;
126462 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
126463 if( sqlite3StrNICmp(pTab->zName+7, "stat", 4)==0 ) return 0;
126464 if( sqlite3StrNICmp(pTab->zName+7, "parameters", 10)==0 ) return 0;
126467 if( (pTab->tabFlags & TF_Shadow)!=0 && sqlite3ReadOnlyShadowTables(db) ){
126473 return 0;
126489 assert( pParse->nErr==0 );
126491 assert( pName->a[0].fg.fixedSchema==0 );
126492 assert( pName->a[0].fg.isSubquery==0 );
126495 assert( isView==0 || isView==LOCATE_VIEW );
126496 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
126499 if( pTab==0 ){
126501 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].u4.zDatabase);
126507 assert( iDb>=0 && iDb<db->nDb );
126520 const char *zArg2 = 0;
126521 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
126545 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
126589 ** in the current table point to the foreign key. If pFromCol==0 then
126611 FKey *pFKey = 0;
126619 assert( pTo!=0 );
126620 if( p==0 || IN_DECLARE_VTAB ) goto fk_end;
126621 if( pFromCol==0 ){
126623 if( NEVER(iCol<0) ) goto fk_end;
126641 for(i=0; i<pToCol->nExpr; i++){
126646 if( pFKey==0 ){
126658 z[pTo->n] = 0;
126662 if( pFromCol==0 ){
126663 pFKey->aCol[0].iFrom = p->nCol-1;
126665 for(i=0; i<nCol; i++){
126667 for(j=0; j<p->nCol; j++){
126668 if( sqlite3StrICmp(p->aCol[j].zCnName, pFromCol->a[i].zEName)==0 ){
126685 for(i=0; i<nCol; i++){
126692 z[n] = 0;
126696 pFKey->isDeferred = 0;
126697 pFKey->aAction[0] = (u8)(flags & 0xff); /* ON DELETE action */
126698 pFKey->aAction[1] = (u8)((flags >> 8 ) & 0xff); /* ON UPDATE action */
126700 assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
126709 assert( pNextTo->pPrevTo==0 );
126718 pFKey = 0;
126730 ** parameter is 1 for INITIALLY DEFERRED and 0 for INITIALLY IMMEDIATE.
126738 if( (pTab = pParse->pNewTable)==0 ) return;
126740 if( (pFKey = pTab->u.tab.pFKey)==0 ) return;
126741 assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */
126773 if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
126783 if( v==0 ) return;
126784 if( memRootPage>=0 ){
126790 assert( pKey!=0 || pParse->nErr );
126794 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*)
126800 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); VdbeCoverage(v);
126804 sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0);
126809 if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
126812 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
126814 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
126885 assert( nCol>0 );
126901 for(i=0; i<pList->nExpr; i++){
126905 (sf==0 || sf==3) ? "FIRST" : "LAST"
126911 return 0;
126930 SrcList *pTblName, /* Table to index. Use pParse->pNewTable if 0 */
126939 Table *pTab = 0; /* Table to be indexed */
126940 Index *pIndex = 0; /* The index to be created */
126941 char *zName = 0; /* Name of the index */
126945 int sortOrderMask; /* 1 to honor DESC in index. 0 to ignore. */
126949 Token *pName = 0; /* Unqualified name of the index to create */
126951 int nExtra = 0; /* Space allocated for zExtra[] */
126953 char *zExtra = 0; /* Extra space after the Index object */
126954 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
126960 assert( db->mallocFailed==0 );
126974 if( pTblName!=0 ){
126982 if( iDb<0 ) goto exit_create_index;
126992 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
127002 assert(0);
127004 pTab = sqlite3LocateTableItem(pParse, 0, &pTblName->a[0]);
127005 assert( db->mallocFailed==0 || pTab==0 );
127006 if( pTab==0 ) goto exit_create_index;
127015 assert( pName==0 );
127016 assert( pStart==0 );
127023 assert( pTab!=0 );
127024 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
127025 && db->init.busy==0
127026 && pTblName!=0
127053 ** If pName==0 it means that we are
127059 if( zName==0 ) goto exit_create_index;
127060 assert( pName->z!=0 );
127066 if( sqlite3FindTable(db, zName, pDb->zDbSName)!=0 ){
127071 if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
127087 if( zName==0 ){
127104 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
127115 /* If pList==0, it means this routine was called to make a primary
127119 if( pList==0 ){
127124 pList = sqlite3ExprListAppend(pParse, 0,
127125 sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
127126 if( pList==0 ) goto exit_create_index;
127137 for(i=0; i<pList->nExpr; i++){
127139 assert( pExpr!=0 );
127169 sqlite3ResolveSelfReference(pParse, pTab, NC_PartIdx, pPIWhere, 0);
127171 pPIWhere = 0;
127173 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
127180 sortOrderMask = 0; /* Ignore DESC */
127195 pList = 0;
127197 for(i=0; i<pIndex->nKeyCol; i++, pListItem++){
127203 sqlite3ResolveSelfReference(pParse, pTab, NC_IdxExpr, pListItem->pExpr, 0);
127212 if( pIndex->aColExpr==0 ){
127214 pList = 0;
127218 pIndex->uniqNotNull = 0;
127222 assert( j<=0x7fff );
127223 if( j<0 ){
127226 if( pTab->aCol[j].notNull==0 ){
127227 pIndex->uniqNotNull = 0;
127236 zColl = 0;
127247 }else if( j>=0 ){
127260 ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
127261 ** normal tables (when pPk==0) this will be the rowid.
127264 for(j=0; j<pPk->nKeyCol; j++){
127266 assert( x>=0 );
127283 if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex);
127288 || pTab->iPKey<0 || sqlite3TableColumnToIndex(pIndex, pTab->iPKey)>=0 );
127290 if( pTblName!=0 && pIndex->nColumn>=pTab->nCol ){
127292 for(j=0; j<pTab->nCol; j++){
127294 if( sqlite3TableColumnToIndex(pIndex,j)>=0 ) continue;
127295 pIndex->isCovering = 0;
127330 for(k=0; k<pIdx->nKeyCol; k++){
127333 assert( pIdx->aiColumn[k]>=0 );
127350 "conflicting ON CONFLICT clauses specified", 0);
127360 pIndex = 0;
127372 assert( pParse->nErr==0 );
127376 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
127377 if( pTblName!=0 ){
127403 ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
127408 else if( HasRowid(pTab) || pTblName!=0 ){
127414 if( v==0 ) goto exit_create_index;
127430 assert( pName!=0 || pStart==0 );
127440 zStmt = 0;
127462 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName), 0);
127463 sqlite3VdbeAddOp2(v, OP_Expire, 0, 1);
127469 if( db->init.busy || pTblName==0 ){
127472 pIndex = 0;
127475 assert( pParse->pNewIndex==0 );
127477 pIndex = 0;
127490 for(ppFrom=&pTab->pIndex; (pThis = *ppFrom)!=0; ppFrom=&pThis->pNext){
127493 while( (pNext = pThis->pNext)!=0 && pNext->onError!=OE_Replace ){
127507 || pThis->pNext==0
127522 ** aiRowEst[0] is supposed to contain the number of elements in the index.
127562 if( pIdx->pPartIdxWhere!=0 ){ x -= 10; assert( 10==sqlite3LogEst(2) ); }
127563 a[0] = x;
127572 assert( 0==sqlite3LogEst(1) );
127573 if( IsUniqueIndex(pIdx) ) a[pIdx->nKeyCol] = 0;
127589 assert( pParse->nErr==0 ); /* Never called with prior non-OOM errors */
127591 assert( pName->a[0].fg.fixedSchema==0 );
127592 assert( pName->a[0].fg.isSubquery==0 );
127596 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].u4.zDatabase);
127597 if( pIndex==0 ){
127601 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].u4.zDatabase);
127609 "or PRIMARY KEY constraint cannot be dropped", 0);
127619 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
127640 sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
127673 if( (n & (n-1))==0 ){
127674 sqlite3_int64 sz = (n==0) ? 1 : 2*n;
127676 if( pNew==0 ){
127683 memset(&z[n * szEntry], 0, szEntry);
127697 if( pList==0 ){
127699 if( pList==0 ) return 0;
127703 if( pNew==0 ){
127705 return 0;
127722 assert( db!=0 );
127723 if( pList==0 ) return;
127724 for(i=0; i<pList->nId; i++){
127736 assert( pList!=0 );
127737 for(i=0; i<pList->nId; i++){
127738 if( sqlite3StrICmp(pList->a[i].zName, zName)==0 ) return i;
127768 ** the iStart value would be 0. The result then would
127784 assert( iStart>=0 );
127786 assert( pSrc!=0 );
127798 return 0;
127802 if( pNew==0 ){
127804 return 0;
127818 memset(&pSrc->a[iStart], 0, sizeof(pSrc->a[0])*nExtra);
127848 ** sqlite3SrcListAppend(D,A,B,0);
127858 ** sqlite3SrcListAppend(D,A,0,C);
127871 assert( pDatabase==0 || pTable!=0 ); /* Cannot have C without B */
127872 assert( pParse!=0 );
127873 assert( pParse->db!=0 );
127875 if( pList==0 ){
127877 if( pList==0 ) return 0;
127880 memset(&pList->a[0], 0, sizeof(pList->a[0]));
127881 pList->a[0].iCursor = -1;
127884 if( pNew==0 ){
127886 return 0;
127892 if( pDatabase && pDatabase->z==0 ){
127893 pDatabase = 0;
127895 assert( pItem->fg.fixedSchema==0 );
127896 assert( pItem->fg.isSubquery==0 );
127902 pItem->u4.zDatabase = 0;
127915 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
127916 if( pItem->iCursor>=0 ) continue;
127919 assert( pItem->u4.pSubq!=0 );
127920 assert( pItem->u4.pSubq->pSelect!=0 );
127921 assert( pItem->u4.pSubq->pSelect->pSrc!=0 );
127932 assert( pSubq!=0 && pSubq->pSelect!=0 );
127943 assert( pItem!=0 );
127947 pItem->u4.pSubq = 0;
127948 pItem->fg.isSubquery = 0;
127958 assert( db!=0 );
127959 if( pList==0 ) return;
127960 for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
127966 assert( !pItem->fg.isSubquery || (pItem->u4.pSubq!=0 &&
127967 pItem->u4.pSubq->pSelect!=0) );
127973 }else if( pItem->fg.fixedSchema==0 && pItem->u4.zDatabase!=0 ){
128010 assert( pSelect!=0 );
128011 assert( pItem->fg.isSubquery==0 );
128013 pItem->u4.pSchema = 0;
128014 pItem->fg.fixedSchema = 0;
128015 }else if( pItem->u4.zDatabase!=0 ){
128017 pItem->u4.zDatabase = 0;
128020 pSelect = sqlite3SelectDup(pParse->db, pSelect, 0);
128021 if( pSelect==0 ) return 0;
128024 if( p==0 ){
128026 return 0;
128030 assert( offsetof(Subquery, pSelect)==0 );
128031 memset(((char*)p)+sizeof(p->pSelect), 0, sizeof(*p)-sizeof(p->pSelect));
128063 if( !p && pOnUsing!=0 && (pOnUsing->pOn || pOnUsing->pUsing) ){
128070 if( p==0 ){
128073 assert( p->nSrc>0 );
128075 assert( (pTable==0)==(pDatabase==0) );
128076 assert( pItem->zName==0 || pDatabase!=0 );
128081 assert( pAlias!=0 );
128085 assert( pSubquery==0 || pDatabase==0 );
128087 if( sqlite3SrcItemAttachSubquery(pParse, pItem, pSubquery, 0) ){
128093 assert( pOnUsing==0 || pOnUsing->pOn==0 || pOnUsing->pUsing==0 );
128094 assert( pItem->fg.isUsing==0 );
128095 if( pOnUsing==0 ){
128096 pItem->u3.pOn = 0;
128106 assert( p==0 );
128109 return 0;
128117 assert( pIndexedBy!=0 );
128118 if( p && pIndexedBy->n>0 ){
128120 assert( p->nSrc>0 );
128122 assert( pItem->fg.notIndexed==0 );
128123 assert( pItem->fg.isIndexedBy==0 );
128124 assert( pItem->fg.isTabFunc==0 );
128132 assert( pItem->fg.isCte==0 ); /* No collision on union u2 */
128146 if( pNew==0 ){
128152 p1->a[0].fg.jointype |= (JT_LTORJ & p1->a[1].fg.jointype);
128165 assert( pItem->fg.notIndexed==0 );
128166 assert( pItem->fg.isIndexedBy==0 );
128167 assert( pItem->fg.isTabFunc==0 );
128187 ** in p->a[0] and p->a[1], respectively. The parser initially stores the
128201 u8 allFlags = 0;
128204 }while( (--i)>0 );
128205 p->a[0].fg.jointype = 0;
128210 for(i=p->nSrc-1; ALWAYS(i>0) && (p->a[i].fg.jointype&JT_RIGHT)==0; i--){}
128212 assert( i>=0 );
128215 }while( (--i)>=0 );
128228 assert( pParse!=0 );
128230 assert( db!=0 );
128231 if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "BEGIN", 0, 0) ){
128237 for(i=0; i<db->nDb; i++){
128241 eTxnType = 0; /* Read txn */
128263 assert( pParse!=0 );
128264 assert( pParse->db!=0 );
128268 isRollback ? "ROLLBACK" : "COMMIT", 0, 0) ){
128289 if( !v || sqlite3AuthCheck(pParse, SQLITE_SAVEPOINT, az[op], zName, 0) ){
128293 sqlite3VdbeAddOp4(v, OP_Savepoint, op, 0, 0, zName, P4_DYNAMIC);
128303 if( db->aDb[1].pBt==0 && !pParse->explain ){
128313 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
128322 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, 0, 0) ){
128327 return 0;
128337 assert( iDb>=0 && iDb<pToplevel->db->nDb );
128338 assert( pToplevel->db->aDb[iDb].pBt!=0 || iDb==1 );
128340 assert( sqlite3SchemaMutexHeld(pToplevel->db, iDb, 0) );
128341 if( DbMaskTest(pToplevel->cookieMask, iDb)==0 ){
128360 for(i=0; i<db->nDb; i++){
128362 if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zDbSName)) ){
128435 assert( pParse->pVdbe!=0 );
128437 assert( (errCode&0xff)==SQLITE_CONSTRAINT || pParse->nested );
128441 sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type);
128458 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0,
128463 for(j=0; j<pIdx->nKeyCol; j++){
128465 assert( pIdx->aiColumn[j]>=0 );
128491 if( pTab->iPKey>=0 ){
128510 assert( zColl!=0 );
128511 for(i=0; i<pIndex->nColumn; i++){
128513 assert( z!=0 || pIndex->aiColumn[i]<0 );
128514 if( pIndex->aiColumn[i]>=0 && 0==sqlite3StrICmp(z, zColl) ){
128518 return 0;
128524 ** If pColl==0 then recompute all indices of pTab.
128532 if( zColl==0 || collationMatch(zColl, pIndex) ){
128534 sqlite3BeginWriteOperation(pParse, 0, iDb);
128544 ** indices use the collating sequence pColl. If pColl==0 then recompute
128556 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
128557 assert( pDb!=0 );
128596 if( pName1==0 ){
128597 reindexDatabases(pParse, 0);
128599 }else if( NEVER(pName2==0) || pName2->z==0 ){
128604 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
128613 if( iDb<0 ) return;
128615 if( z==0 ) return;
128616 zDb = pName2->n ? db->aDb[iDb].zDbSName : 0;
128619 reindexTable(pParse, pTab, 0);
128627 sqlite3BeginWriteOperation(pParse, 0, iDb);
128646 if( pParse->nErr ) return 0;
128650 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
128654 for(i=0; i<nCol; i++){
128656 pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
128659 assert( 0==(pKey->aSortFlags[i] & KEYINFO_ORDER_BIGNULL) );
128663 if( pIdx->bNoQuery==0 ){
128675 pKey = 0;
128696 assert( pNew!=0 || db->mallocFailed );
128715 assert( pCte!=0 );
128725 assert( pCte!=0 );
128745 if( pCte==0 ){
128754 for(i=0; i<pWith->nCte; i++){
128755 if( sqlite3StrICmp(zName, pWith->a[i].zName)==0 ){
128766 assert( (pNew!=0 && zName!=0) || db->mallocFailed );
128785 for(i=0; i<pWith->nCte; i++){
128854 for(i=0; i<3; i++){
128855 pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, 0);
128856 if( pColl2->xCmp!=0 ){
128858 pColl->xDel = 0; /* Do not copy the destructor */
128877 if( pColl && pColl->xCmp==0 ){
128912 if( 0==pColl && create ){
128916 CollSeq *pDel = 0;
128917 pColl[0].zName = (char*)&pColl[3];
128918 pColl[0].enc = SQLITE_UTF8;
128923 memcpy(pColl[0].zName, zName, nName);
128924 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, pColl);
128930 assert( pDel==0 || pDel==pColl );
128931 if( pDel!=0 ){
128934 pColl = 0;
128984 db->pDfltColl = sqlite3FindCollSeq(db, enc, sqlite3StrBINARY, 0);
129013 p = sqlite3FindCollSeq(db, enc, zName, 0);
129020 p = sqlite3FindCollSeq(db, enc, zName, 0);
129023 p = 0;
129026 if( p==0 ){
129081 ** The returned value is always between 0 and 6, as follows:
129083 ** 0: Not a match.
129107 if( nArg==(-2) ) return p->xSFunc==0 ? 0 : FUNC_PERFECT_MATCH;
129108 if( p->nArg>=0 ) return 0;
129113 if( p->nArg<(-2) && nArg<(-2-p->nArg) ) return 0;
129127 }else if( (enc & p->funcFlags & 2)!=0 ){
129136 ** a pointer to the matching FuncDef if found, or 0 if there is no match.
129145 if( sqlite3StrICmp(p->zName, zFunc)==0 ){
129149 return 0;
129160 for(i=0; i<nDef; i++){
129164 int h = SQLITE_FUNC_HASH(zName[0], nName);
129172 aDef[i].pNext = 0;
129194 ** of arguments. If nArg is -2, then createFlag must be 0.
129208 FuncDef *pBest = 0; /* Best match found so far */
129209 int bestScore = 0; /* Score of best match */
129214 assert( nArg>=(-1) || createFlag==0 );
129241 if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){
129242 bestScore = 0;
129243 h = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zName[0]], nName);
129260 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
129272 return 0;
129281 return 0;
129299 memset(&xdb, 0, sizeof(xdb));
129315 pSchema->pSeqTab = 0;
129331 p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema));
129335 }else if ( 0==p->file_format ){
129373 ** pSrc->a[0].spTab Pointer to the Table object
129374 ** pSrc->a[0].u2.pIBIndex Pointer to the INDEXED BY index, if there is one
129381 pTab = sqlite3LocateTableItem(pParse, 0, pItem);
129388 pTab = 0;
129401 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zColName, SQLITE_STATIC);
129425 if( sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 ){
129435 if( pParse->pToplevel!=0
129437 ((pParse->db->flags & SQLITE_TrustedSchema)!=0)
129442 return 0;
129449 if( (pTab->tabFlags & (TF_Readonly|TF_Shadow))==0 ) return 0;
129451 if( (pTab->tabFlags & TF_Readonly)!=0 ){
129452 return sqlite3WritableSchema(db)==0 && pParse->nested==0;
129463 ** If pTab is writable and no prior errors -> return 0;
129472 && (pTrigger==0 || (pTrigger->bReturning && pTrigger->pNext==0))
129478 return 0;
129501 pWhere = sqlite3ExprDup(db, pWhere, 0);
129502 pFrom = sqlite3SrcListAppend(pParse, 0, 0, 0);
129505 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
129506 assert( pFrom->a[0].fg.fixedSchema==0 && pFrom->a[0].fg.isSubquery==0 );
129507 pFrom->a[0].u4.zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
129508 assert( pFrom->a[0].fg.isUsing==0 );
129509 assert( pFrom->a[0].u3.pOn==0 );
129511 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy,
129546 if( pOrderBy && pLimit==0 ) {
129550 return 0;
129556 if( pLimit == 0 ) {
129569 pTab = pSrc->a[0].pSTab;
129571 pLhs = sqlite3PExpr(pParse, TK_ROW, 0, 0);
129573 pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0)
129577 assert( pPk!=0 );
129581 assert( pPk->aiColumn[0]>=0 && pPk->aiColumn[0]<pTab->nCol );
129582 zName = pTab->aCol[pPk->aiColumn[0]].zCnName;
129584 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName));
129587 for(i=0; i<pPk->nKeyCol; i++){
129589 assert( pPk->aiColumn[i]>=0 && pPk->aiColumn[i]<pTab->nCol );
129593 pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
129595 pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0);
129602 pSrc->a[0].pSTab = 0;
129603 pSelectSrc = sqlite3SrcListDup(db, pSrc, 0);
129604 pSrc->a[0].pSTab = pTab;
129605 if( pSrc->a[0].fg.isIndexedBy ){
129606 assert( pSrc->a[0].fg.isCte==0 );
129607 pSrc->a[0].u2.pIBIndex = 0;
129608 pSrc->a[0].fg.isIndexedBy = 0;
129609 sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy);
129610 }else if( pSrc->a[0].fg.isCte ){
129611 pSrc->a[0].u2.pCteUse->nUse++;
129615 pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
129616 pOrderBy,0,pLimit
129620 pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0);
129647 int iDataCur = 0; /* VDBE cursor for the canonical data source */
129648 int iIdxCur = 0; /* Cursor number of the first index */
129654 int memCnt = 0; /* Memory cell used for change counting */
129658 u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */
129660 int iPk = 0; /* First of nPk registers holding PRIMARY KEY value */
129664 int iEphCur = 0; /* Ephemeral table holding all primary key values */
129665 int iRowSet = 0; /* Register for rowset of rows to delete */
129666 int addrBypass = 0; /* Address of jump over the delete logic */
129667 int addrLoop = 0; /* Top of the delete loop */
129668 int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
129677 memset(&sContext, 0, sizeof(sContext));
129683 assert( db->mallocFailed==0 );
129692 if( pTab==0 ) goto delete_from_cleanup;
129698 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
129701 # define pTrigger 0
129702 # define isView 0
129704 bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
129707 # define isView 0
129711 if( sqlite3TreeTrace & 0x10000 ){
129712 sqlite3TreeViewLine(0, "In sqlite3Delete() at %s:%d", __FILE__, __LINE__);
129723 pOrderBy = 0;
129724 pLimit = 0;
129739 rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0,
129750 iTabCur = pTabList->a[0].iCursor = pParse->nTab++;
129751 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
129764 if( v==0 ){
129767 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
129779 pOrderBy = 0;
129780 pLimit = 0;
129786 memset(&sNC, 0, sizeof(sNC));
129796 if( (db->flags & SQLITE_CountRows)!=0
129802 sqlite3VdbeAddOp2(v, OP_Integer, 0, memCnt);
129818 && pWhere==0
129822 && db->xPreUpdateCallback==0
129844 wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
129847 pPk = 0;
129850 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
129855 assert( pPk!=0 );
129872 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,0,wcf,iTabCur+1);
129873 if( pWInfo==0 ) goto delete_from_cleanup;
129875 assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI );
129890 for(i=0; i<nPk; i++){
129891 assert( pPk->aiColumn[i]>=0 );
129907 if( aToOpen==0 ){
129912 aToOpen[nIdx+1] = 0;
129913 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
129914 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
129921 nKey = 0; /* Zero tells OP_Found to use a composite key */
129939 int iAddrOnce = 0;
129959 assert( pPk!=0 || IsView(pTab) );
129966 sqlite3VdbeAddOp3(v, OP_Column, iEphCur, 0, iKey);
129970 assert( nKey==0 ); /* OP_Found will use a composite key */
129972 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
129987 pParse->isMultiWrite = 0;
129990 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iKey, pVTab, P4_VTAB);
129995 int count = (pParse->nested==0); /* True to count changes */
130017 if( pParse->nested==0 && pParse->pTriggerTab==0 ){
130066 ** sequence of nPk memory cells starting at iPk. If nPk==0 that means
130071 ** Parameter eMode may be passed either ONEPASS_OFF (0), ONEPASS_SINGLE, or
130079 ** iIdxNoSeek is a valid cursor number (>=0) and is not the same as
130085 ** If iIdxNoSeek is a valid cursor number (>=0) not equal to iDataCur,
130105 int iOld = 0; /* First register in OLD.* array */
130127 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
130135 pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf
130144 for(iCol=0; iCol<pTab->nCol; iCol++){
130145 testcase( mask!=0xffffffff && iCol==31 );
130146 testcase( mask!=0xffffffff && iCol==32 );
130147 if( mask==0xffffffff || (iCol<=31 && (mask & MASKBIT32(iCol))!=0) ){
130156 TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
130171 testcase( iIdxNoSeek>=0 );
130178 sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
130192 u8 p5 = 0;
130193 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
130194 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
130195 if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){
130201 if( iIdxNoSeek>=0 && iIdxNoSeek!=iDataCur ){
130211 sqlite3FkActions(pParse, pTab, 0, iOld, 0, 0);
130216 TK_DELETE, 0, TRIGGER_AFTER, pTab, iOld, onconf, iLabel
130240 ** index is the 0-th index.)
130250 int *aRegIdx, /* Only delete if aRegIdx!=0 && aRegIdx[i]>0 */
130257 Index *pPrior = 0; /* Prior index */
130262 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
130263 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
130265 if( aRegIdx!=0 && aRegIdx[i]==0 ) continue;
130269 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1,
130314 int regOut, /* Put the new key into this register if not 0 */
130331 pParse->iSelfTab = 0;
130332 pPrior = 0; /* Ticket a9efb42811fa41ee 2019-11-02;
130335 *piPartIdxLabel = 0;
130340 if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;
130341 for(j=0; j<nCol; j++){
130350 if( pIdx->aiColumn[j]>=0 ){
130408 assert( context->pVdbe!=0 );
130420 assert( context->isError<=0 );
130434 int mask; /* 0 for min() or 0xffffffff for max() */
130439 mask = sqlite3_user_data(context)==0 ? 0 : -1;
130442 assert( mask==-1 || mask==0 );
130443 iBest = 0;
130444 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
130447 if( (sqlite3MemCompare(argv[iBest], argv[i], pColl)^mask)>=0 ){
130448 testcase( mask==0 );
130464 int i = sqlite3_value_type(argv[0]) - 1;
130466 assert( i>=0 && i<ArraySize(azType) );
130489 sqlite3_result_int(context, sqlite3_value_subtype(argv[0]));
130502 switch( sqlite3_value_type(argv[0]) ){
130506 sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
130510 const unsigned char *z = sqlite3_value_text(argv[0]);
130513 if( z==0 ) return;
130515 while( (c = *z)!=0 ){
130517 if( c>=0xc0 ){
130518 while( (*z & 0xc0)==0x80 ){ z++; z0++; }
130541 switch( sqlite3_value_type(argv[0]) ){
130543 sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
130549 sqlite3_result_int64(context, sqlite3_value_bytes(argv[0])*m);
130553 if( sqlite3_value_encoding(argv[0])<=SQLITE_UTF8 ){
130554 sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
130556 sqlite3_result_int(context, sqlite3_value_bytes16(argv[0]));
130576 switch( sqlite3_value_type(argv[0]) ){
130578 i64 iVal = sqlite3_value_int64(argv[0]);
130579 if( iVal<0 ){
130603 double rVal = sqlite3_value_double(argv[0]);
130604 if( rVal<0 ) rVal = -rVal;
130616 ** or 0 if needle does not occur within haystack.
130620 ** or 0 if needle never occurs in haystack.
130635 sqlite3_value *pC1 = 0;
130636 sqlite3_value *pC2 = 0;
130639 typeHaystack = sqlite3_value_type(argv[0]);
130642 nHaystack = sqlite3_value_bytes(argv[0]);
130644 if( nNeedle>0 ){
130646 zHaystack = sqlite3_value_blob(argv[0]);
130648 isText = 0;
130650 zHaystack = sqlite3_value_text(argv[0]);
130654 pC1 = sqlite3_value_dup(argv[0]);
130656 if( zHaystack==0 ) goto endInstrOOM;
130660 if( zNeedle==0 ) goto endInstrOOM;
130664 if( zNeedle==0 || (nHaystack && zHaystack==0) ) goto endInstrOOM;
130665 firstChar = zNeedle[0];
130667 && (zHaystack[0]!=firstChar || memcmp(zHaystack, zNeedle, nNeedle)!=0)
130673 }while( isText && (zHaystack[0]&0xc0)==0x80 );
130675 if( nNeedle>nHaystack ) N = 0;
130701 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
130703 x.nUsed = 0;
130705 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
130738 p0type = sqlite3_value_type(argv[0]);
130741 len = sqlite3_value_bytes(argv[0]);
130742 z = sqlite3_value_blob(argv[0]);
130743 if( z==0 ) return;
130744 assert( len==sqlite3_value_bytes(argv[0]) );
130746 z = sqlite3_value_text(argv[0]);
130747 if( z==0 ) return;
130748 len = 0;
130749 if( p1<0 ){
130757 if( p2==0 && sqlite3_value_type(argv[2])==SQLITE_NULL ) return;
130761 if( p1==0 ){
130763 /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
130772 if( p1<0 ){
130774 if( p1<0 ){
130775 if( p2<0 ){
130776 p2 = 0;
130780 p1 = 0;
130782 }else if( p1>0 ){
130784 }else if( p2>0 ){
130787 if( p2<0 ){
130795 assert( p1>=0 && p2>=0 );
130808 p1 = p2 = 0;
130811 assert( p2>0 );
130822 i64 n = 0;
130830 if( n<0 ) n = 0;
130832 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
130833 r = sqlite3_value_double(argv[0]);
130834 /* If Y==0 and X will fit in a 64-bit int,
130840 }else if( n==0 ){
130841 r = (double)((sqlite_int64)(r+(r<0?-0.5:+0.5)));
130844 if( zBuf==0 ){
130865 assert( nByte>0 );
130870 z = 0;
130888 z2 = (char*)sqlite3_value_text(argv[0]);
130889 n = sqlite3_value_bytes(argv[0]);
130891 assert( z2==(char*)sqlite3_value_text(argv[0]) );
130895 for(i=0; i<n; i++){
130907 z2 = (char*)sqlite3_value_text(argv[0]);
130908 n = sqlite3_value_bytes(argv[0]);
130910 assert( z2==(char*)sqlite3_value_text(argv[0]) );
130914 for(i=0; i<n; i++){
130943 if( r<0 ){
130944 /* We need to prevent a random number of 0x8000000000000000
130970 n = sqlite3_value_int64(argv[0]);
131037 u8 matchSet; /* "[" or 0 */
131051 # define Utf8Read(A) (A[0]<0x80?*(A++):sqlite3Utf8Read(&A))
131054 static const struct compareInfo globInfo = { '*', '?', '[', 0 };
131057 static const struct compareInfo likeInfoNorm = { '%', '_', 0, 1 };
131060 static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
131065 #define SQLITE_MATCH 0
131117 const u8 *zEscaped = 0; /* One past the last escaped input char */
131119 while( (c = Utf8Read(zPattern))!=0 ){
131125 || (c == matchOne && matchOne!=0) ){
131126 if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
131130 if( c==0 ){
131133 if( pInfo->matchSet==0 ){
131135 if( c==0 ) return SQLITE_NOWILDCARDMATCH;
131139 assert( matchOther<0x80 ); /* '[' is a single-byte character */
131158 if( c<0x80 ){
131162 zStop[0] = sqlite3Toupper(c);
131164 zStop[2] = 0;
131166 zStop[0] = c;
131167 zStop[1] = 0;
131171 if( zString[0]==0 ) break;
131178 while( (c2 = Utf8Read(zString))!=0 ){
131187 if( pInfo->matchSet==0 ){
131189 if( c==0 ) return SQLITE_NOMATCH;
131192 u32 prior_c = 0;
131193 int seen = 0;
131194 int invert = 0;
131196 if( c==0 ) return SQLITE_NOMATCH;
131207 if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
131210 prior_c = 0;
131219 if( c2==0 || (seen ^ invert)==0 ){
131227 if( noCase && sqlite3Tolower(c)==sqlite3Tolower(c2) && c<0x80 && c2<0x80 ){
131230 if( c==matchOne && zPattern!=zEscaped && c2!=0 ) continue;
131233 return *zString==0 ? SQLITE_MATCH : SQLITE_NOMATCH;
131237 ** The sqlite3_strglob() interface. Return 0 on a match (like strcmp()) and
131241 if( zString==0 ){
131242 return zGlobPattern!=0;
131243 }else if( zGlobPattern==0 ){
131251 ** The sqlite3_strlike() interface. Return 0 on a match and non-zero for
131255 if( zStr==0 ){
131256 return zPattern!=0;
131257 }else if( zPattern==0 ){
131270 SQLITE_API int sqlite3_like_count = 0;
131299 if( sqlite3_value_type(argv[0])==SQLITE_BLOB
131305 sqlite3_result_int(context, 0);
131313 nPat = sqlite3_value_bytes(argv[0]);
131325 if( zEsc==0 ) return;
131335 if( escape==pInfo->matchAll ) pInfo->matchAll = 0;
131336 if( escape==pInfo->matchOne ) pInfo->matchOne = 0;
131341 zB = sqlite3_value_text(argv[0]);
131364 if( sqlite3MemCompare(argv[0], argv[1], pColl)!=0 ){
131365 sqlite3_result_value(context, argv[0]);
131412 sqlite3_log(sqlite3_value_int(argv[0]), "%s", sqlite3_value_text(argv[1]));
131433 if( (zOptName = (const char*)sqlite3_value_text(argv[0]))!=0 ){
131456 n = sqlite3_value_int(argv[0]);
131464 '0', '1', '2', '3', '4', '5', '6', '7',
131476 assert( pStr!=0 && pStr->nChar==0 );
131503 if( pStr->accError==0 ){
131506 for(i=0; i<nBlob; i++){
131507 zText[(i*2)+2] = hexdigits[(zBlob[i]>>4)&0x0F];
131508 zText[(i*2)+3] = hexdigits[(zBlob[i])&0x0F];
131511 zText[(nBlob*2)+3] = '\0';
131512 zText[0] = 'X';
131538 int v = 0;
131539 for(i=0; i<N; i++){
131540 if( !sqlite3Isxdigit(z[i]) ) return 0;
131573 zIn = (const char*)sqlite3_value_text(argv[0]);
131574 if( zIn==0 ) return;
131575 nIn = sqlite3_value_bytes(argv[0]);
131577 if( zOut==0 ){
131581 i = j = 0;
131584 if( z==0 ){
131591 if( n>0 ){
131619 zOut[j] = 0;
131649 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
131650 sqlite3QuoteValue(&str,argv[0],SQLITE_PTR_TO_INT(sqlite3_user_data(context)));
131668 const unsigned char *z = sqlite3_value_text(argv[0]);
131670 if( z && z[0] ) sqlite3_result_int(context, sqlite3Utf8Read(&z));
131686 if( z==0 ){
131690 for(i=0; i<argc; i++){
131694 if( x<0 || x>0x10ffff ) x = 0xfffd;
131695 c = (unsigned)(x & 0x1fffff);
131696 if( c<0x00080 ){
131697 *zOut++ = (u8)(c&0xFF);
131698 }else if( c<0x00800 ){
131699 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F);
131700 *zOut++ = 0x80 + (u8)(c & 0x3F);
131701 }else if( c<0x10000 ){
131702 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F);
131703 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F);
131704 *zOut++ = 0x80 + (u8)(c & 0x3F);
131706 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07);
131707 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F);
131708 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F);
131709 *zOut++ = 0x80 + (u8)(c & 0x3F);
131712 *zOut = 0;
131730 pBlob = sqlite3_value_blob(argv[0]);
131731 n = sqlite3_value_bytes(argv[0]);
131732 assert( pBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
131735 for(i=0; i<n; i++, pBlob++){
131737 *(z++) = hexdigits[(c>>4)&0xf];
131738 *(z++) = hexdigits[c&0xf];
131740 *z = 0;
131748 ** contains character ch, or 0 if it does not.
131757 return 0;
131788 int nPass = 0;
131789 const u8 *zHex = sqlite3_value_text(argv[0]);
131790 int nHex = sqlite3_value_bytes(argv[0]);
131792 const u8 *zEnd = zHex ? &zHex[nHex] : 0;
131794 u8 *pBlob = 0;
131795 u8 *p = 0;
131809 while( (c = *zHex)!=0x00 ){
131815 if( c==0x00 ) goto unhex_done;
131818 assert( *zEnd==0x00 );
131848 n = sqlite3_value_int64(argv[0]);
131849 if( n<0 ) n = 0;
131882 zStr = sqlite3_value_text(argv[0]);
131883 if( zStr==0 ) return;
131884 nStr = sqlite3_value_bytes(argv[0]);
131885 assert( zStr==sqlite3_value_text(argv[0]) ); /* No encoding change */
131887 if( zPattern==0 ){
131892 if( zPattern[0]==0 ){
131900 if( zRep==0 ) return;
131906 if( zOut==0 ){
131910 cntExpand = 0;
131911 for(i=j=0; i<=loopLimit; i++){
131912 if( zStr[i]!=zPattern[0] || memcmp(&zStr[i], zPattern, nPattern) ){
131925 if( (cntExpand&(cntExpand-1))==0 ){
131931 if( zOut==0 ){
131947 zOut[j] = 0;
131953 ** The userdata is 0x1 for left trim, 0x2 for right trim, 0x3 for both.
131965 unsigned int *aLen = 0; /* Length of each character in zCharSet */
131966 unsigned char **azChar = 0; /* Individual characters in zCharSet */
131969 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
131972 zIn = sqlite3_value_text(argv[0]);
131973 if( zIn==0 ) return;
131974 nIn = (unsigned)sqlite3_value_bytes(argv[0]);
131975 assert( zIn==sqlite3_value_text(argv[0]) );
131982 zCharSet = 0;
131983 }else if( (zCharSet = sqlite3_value_text(argv[1]))==0 ){
131987 for(z=zCharSet, nChar=0; *z; nChar++){
131990 if( nChar>0 ){
131993 if( azChar==0 ){
131997 for(z=zCharSet, nChar=0; *z; nChar++){
132004 if( nChar>0 ){
132007 while( nIn>0 ){
132008 unsigned int len = 0;
132009 for(i=0; i<nChar; i++){
132011 if( len<=nIn && memcmp(zIn, azChar[i], len)==0 ) break;
132019 while( nIn>0 ){
132020 unsigned int len = 0;
132021 for(i=0; i<nChar; i++){
132023 if( len<=nIn && memcmp(&zIn[nIn-len],azChar[i],len)==0 ) break;
132049 i64 j, n = 0;
132052 for(i=0; i<argc; i++){
132057 if( z==0 ){
132061 j = 0;
132062 for(i=0; i<argc; i++){
132066 if( v!=0 ){
132067 if( j>0 && nSep>0 ){
132076 z[j] = 0;
132090 concatFuncCore(context, argc, argv, 0, "");
132105 int nSep = sqlite3_value_bytes(argv[0]);
132106 const char *zSep = (const char*)sqlite3_value_text(argv[0]);
132107 if( zSep==0 ) return;
132155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132156 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132157 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132158 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132159 0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
132160 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
132161 0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
132162 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
132165 zIn = (u8*)sqlite3_value_text(argv[0]);
132166 if( zIn==0 ) zIn = (u8*)"";
132167 for(i=0; zIn[i] && !sqlite3Isalpha(zIn[i]); i++){}
132169 u8 prevcode = iCode[zIn[i]&0x7f];
132170 zResult[0] = sqlite3Toupper(zIn[i]);
132172 int code = iCode[zIn[i]&0x7f];
132173 if( code>0 ){
132176 zResult[j++] = code + '0';
132179 prevcode = 0;
132183 zResult[j++] = '0';
132185 zResult[j] = 0;
132200 const char *zFile = (const char *)sqlite3_value_text(argv[0]);
132203 char *zErrMsg = 0;
132208 if( (db->flags & SQLITE_LoadExtFunc)==0 ){
132216 zProc = 0;
132310 type = sqlite3_value_numeric_type(argv[0]);
132313 if( p->approx==0 ){
132317 kahanBabuskaNeumaierStep(p, sqlite3_value_double(argv[0]));
132320 if( sqlite3AddInt64(&x, sqlite3_value_int64(argv[0]))==0 ){
132326 kahanBabuskaNeumaierStepInt64(p, sqlite3_value_int64(argv[0]));
132331 kahanBabuskaNeumaierStepInt64(p, sqlite3_value_int64(argv[0]));
132333 p->ovrfl = 0;
132334 kahanBabuskaNeumaierStep(p, sqlite3_value_double(argv[0]));
132346 type = sqlite3_value_numeric_type(argv[0]);
132350 assert( p->cnt>0 );
132353 if( sqlite3SubInt64(&p->iSum, sqlite3_value_int64(argv[0])) ){
132358 i64 iVal = sqlite3_value_int64(argv[0]);
132366 kahanBabuskaNeumaierStep(p, -sqlite3_value_double(argv[0]));
132371 # define sumInverse 0
132375 p = sqlite3_aggregate_context(context, 0);
132376 if( p && p->cnt>0 ){
132392 p = sqlite3_aggregate_context(context, 0);
132393 if( p && p->cnt>0 ){
132407 p = sqlite3_aggregate_context(context, 0);
132437 if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && p ){
132446 assert( argc==1 || p==0 || p->n>0x7fffffff || p->bInverse
132452 p = sqlite3_aggregate_context(context, 0);
132453 sqlite3_result_int64(context, p ? p->n : 0);
132460 if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && ALWAYS(p) ){
132468 # define countInverse 0
132479 Mem *pArg = (Mem *)argv[0];
132498 ** aggregate, or 0 for min().
132500 max = sqlite3_user_data(context)!=0;
132502 if( (max && cmp<0) || (!max && cmp>0) ){
132514 pRes = (sqlite3_value *)sqlite3_aggregate_context(context, 0);
132519 if( bValue==0 ) sqlite3VdbeMemRelease(pRes);
132527 # define minMaxValue 0
132530 minMaxValueFinalize(context, 0);
132552 /* If pnSepLengths!=0, refs an array of inter-string separator lengths,
132555 ** If pnSepLengths==0, nFirstSepLength is the length used throughout.
132571 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
132575 int firstTerm = pGCC->str.mxAlloc==0;
132594 nSep = 0;
132596 if( nSep != pGCC->nFirstSepLength || pGCC->pnSepLengths != 0 ){
132598 if( pnsl == 0 ){
132601 if( pnsl!=0 ){
132602 int i = 0, nA = pGCC->nAccum-1;
132608 if( pnsl!=0 ){
132609 if( ALWAYS(pGCC->nAccum>0) ){
132625 zVal = (char*)sqlite3_value_text(argv[0]);
132626 nVal = sqlite3_value_bytes(argv[0]);
132640 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
132648 (void)sqlite3_value_text(argv[0]);
132649 nVS = sqlite3_value_bytes(argv[0]);
132651 if( pGCC->pnSepLengths!=0 ){
132652 assert(pGCC->nAccum >= 0);
132653 if( pGCC->nAccum>0 ){
132663 pGCC->str.nChar = 0;
132668 if( pGCC->str.nChar==0 ){
132669 pGCC->str.mxAlloc = 0;
132671 pGCC->pnSepLengths = 0;
132676 # define groupConcatInverse 0
132680 = (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
132691 = (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
132698 }else if( pGCC->nAccum>0 && pAccum->nChar==0 ){
132707 # define groupConcatValue 0
132742 0, 0, 0, 0, 0);
132743 pDef = sqlite3FindFunction(db, "like", nArg, SQLITE_UTF8, 0);
132752 ** then set aWc[0] through aWc[2] to the wildcard characters and the
132769 assert( pExpr!=0 );
132773 return 0;
132777 pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0);
132779 if( pDef==0 ) return 0;
132781 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
132782 return 0;
132795 aWc[3] = 0;
132799 if( pEscape->op!=TK_STRING ) return 0;
132802 if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
132803 if( zEscape[0]==aWc[0] ) return 0;
132804 if( zEscape[0]==aWc[1] ) return 0;
132805 aWc[3] = zEscape[0];
132808 *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0;
132843 switch( sqlite3_value_numeric_type(argv[0]) ){
132845 sqlite3_result_int64(context, sqlite3_value_int64(argv[0]));
132850 sqlite3_result_double(context, x(sqlite3_value_double(argv[0])));
132871 #if defined(HAVE_LOG10) && HAVE_LOG10==0
132874 #if defined(HAVE_LOG2) && HAVE_LOG2==0
132894 switch( sqlite3_value_numeric_type(argv[0]) ){
132897 x = sqlite3_value_double(argv[0]);
132904 switch( sqlite3_value_numeric_type(argv[0]) ){
132952 type0 = sqlite3_value_numeric_type(argv[0]);
132954 v0 = sqlite3_value_double(argv[0]);
132974 type0 = sqlite3_value_numeric_type(argv[0]);
132978 v0 = sqlite3_value_double(argv[0]);
132986 ** Implementation of 0-argument pi() function.
132993 assert( argc==0 );
133012 type0 = sqlite3_value_numeric_type(argv[0]);
133014 x = sqlite3_value_double(argv[0]);
133015 sqlite3_result_int(context, x<0.0 ? -1 : x>0.0 ? +1 : 0);
133042 x = sqlite3_value_double(argv[0]);
133045 if( z<=0 ) z = 1;
133085 sqlite3_vfs *pVfs = 0;
133086 char *zFile = 0;
133087 char *zErr = 0;
133090 pVfs = sqlite3_vfs_find(0);
133093 zUri = (const char*)sqlite3_value_text(argv[0]);
133094 if( zUri==0 ) return;
133097 pResult = sqlite3_str_new(0);
133101 sqlite3_str_appendf(pResult, ", flags=0x%x", flgs);
133102 sqlite3_str_appendf(pResult, ", vfs=%Q", pVfs ? pVfs->zName: 0);
133108 while( z[0] ){
133117 }else if( (zArg = (const char*)sqlite3_value_text(argv[i]))!=0 ){
133153 TEST_FUNC(implies_nonnull_row, 2, INLINEFUNC_implies_nonnull_row, 0),
133154 TEST_FUNC(expr_compare, 2, INLINEFUNC_expr_compare, 0),
133155 TEST_FUNC(expr_implies_expr, 2, INLINEFUNC_expr_implies_expr, 0),
133156 TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0),
133160 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
133163 SFUNCTION(load_extension, 1, 0, 0, loadExt ),
133164 SFUNCTION(load_extension, 2, 0, 0, loadExt ),
133167 DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
133168 DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
133174 INLINE_FUNC(sqlite_offset, 1, INLINEFUNC_sqlite_offset, 0 ),
133176 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
133177 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
133178 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
133179 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
133180 FUNCTION(trim, 1, 3, 0, trimFunc ),
133181 FUNCTION(trim, 2, 3, 0, trimFunc ),
133182 FUNCTION(min, -3, 0, 1, minmaxFunc ),
133183 WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
133186 WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
133188 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
133189 FUNCTION2(subtype, 1, 0, 0, subtypeFunc,
133191 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
133192 FUNCTION2(octet_length, 1, 0, 0, bytelengthFunc,SQLITE_FUNC_BYTELEN),
133193 FUNCTION(instr, 2, 0, 0, instrFunc ),
133194 FUNCTION(printf, -1, 0, 0, printfFunc ),
133195 FUNCTION(format, -1, 0, 0, printfFunc ),
133196 FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
133197 FUNCTION(char, -1, 0, 0, charFunc ),
133198 FUNCTION(abs, 1, 0, 0, absFunc ),
133200 FUNCTION(fpdecode, 3, 0, 0, fpdecodeFunc ),
133201 FUNCTION(parseuri, -1, 0, 0, parseuriFunc ),
133204 FUNCTION(round, 1, 0, 0, roundFunc ),
133205 FUNCTION(round, 2, 0, 0, roundFunc ),
133207 FUNCTION(upper, 1, 0, 0, upperFunc ),
133208 FUNCTION(lower, 1, 0, 0, lowerFunc ),
133209 FUNCTION(hex, 1, 0, 0, hexFunc ),
133210 FUNCTION(unhex, 1, 0, 0, unhexFunc ),
133211 FUNCTION(unhex, 2, 0, 0, unhexFunc ),
133212 FUNCTION(concat, -3, 0, 0, concatFunc ),
133213 FUNCTION(concat_ws, -4, 0, 0, concatwsFunc ),
133214 INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, 0 ),
133215 VFUNCTION(random, 0, 0, 0, randomFunc ),
133216 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
133217 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
133218 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
133219 DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
133220 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
133221 FUNCTION(unistr, 1, 0, 0, unistrFunc ),
133222 FUNCTION(quote, 1, 0, 0, quoteFunc ),
133223 FUNCTION(unistr_quote, 1, 1, 0, quoteFunc ),
133224 VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
133225 VFUNCTION(changes, 0, 0, 0, changes ),
133226 VFUNCTION(total_changes, 0, 0, 0, total_changes ),
133227 FUNCTION(replace, 3, 0, 0, replaceFunc ),
133228 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
133229 FUNCTION(substr, 2, 0, 0, substrFunc ),
133230 FUNCTION(substr, 3, 0, 0, substrFunc ),
133231 FUNCTION(substring, 2, 0, 0, substrFunc ),
133232 FUNCTION(substring, 3, 0, 0, substrFunc ),
133233 WAGGREGATE(sum, 1,0,0, sumStep, sumFinalize, sumFinalize, sumInverse, 0),
133234 WAGGREGATE(total, 1,0,0, sumStep,totalFinalize,totalFinalize,sumInverse, 0),
133235 WAGGREGATE(avg, 1,0,0, sumStep, avgFinalize, avgFinalize, sumInverse, 0),
133236 WAGGREGATE(count, 0,0,0, countStep,
133239 WAGGREGATE(count, 1,0,0, countStep,
133241 WAGGREGATE(group_concat, 1, 0, 0, groupConcatStep,
133242 groupConcatFinalize, groupConcatValue, groupConcatInverse, 0),
133243 WAGGREGATE(group_concat, 2, 0, 0, groupConcatStep,
133244 groupConcatFinalize, groupConcatValue, groupConcatInverse, 0),
133245 WAGGREGATE(string_agg, 2, 0, 0, groupConcatStep,
133246 groupConcatFinalize, groupConcatValue, groupConcatInverse, 0),
133257 FUNCTION(unknown, -1, 0, 0, unknownFunc ),
133266 FUNCTION(ln, 1, 0, 0, logFunc ),
133267 FUNCTION(log, 1, 1, 0, logFunc ),
133268 FUNCTION(log10, 1, 1, 0, logFunc ),
133269 FUNCTION(log2, 1, 2, 0, logFunc ),
133270 FUNCTION(log, 2, 0, 0, logFunc ),
133293 MFUNCTION(pi, 0, 0, piFunc ),
133295 FUNCTION(sign, 1, 0, 0, signFunc ),
133296 INLINE_FUNC(coalesce, -4, INLINEFUNC_coalesce, 0 ),
133297 INLINE_FUNC(iif, -4, INLINEFUNC_iif, 0 ),
133298 INLINE_FUNC(if, -4, INLINEFUNC_iif, 0 ),
133308 #if 0 /* Enable to print out how the built-in functions are hashed */
133312 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
133316 int h = p->zName[0] + n;
133517 Index *pIdx = 0; /* Value to return via *ppIdx */
133518 int *aiCol = 0; /* Value to return via *paiCol */
133520 char *zKey = pFKey->aCol[0].zCol; /* Name of left-most parent key column */
133523 assert( ppIdx && *ppIdx==0 );
133524 assert( !paiCol || *paiCol==0 );
133543 if( pParent->iPKey>=0 ){
133544 if( !zKey ) return 0;
133546 return 0;
133557 if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) && pIdx->pPartIdxWhere==0 ){
133562 if( zKey==0 ){
133569 for(i=0; i<nCol; i++) aiCol[i] = pFKey->aCol[i].iFrom;
133579 for(i=0; i<nCol; i++){
133584 if( iCol<0 ) break; /* No foreign keys against expression indexes */
133594 for(j=0; j<nCol; j++){
133595 if( sqlite3StrICmp(pFKey->aCol[j].zCol, zIdxCol)==0 ){
133618 return 0;
133676 if( nIncr<0 ){
133680 for(i=0; i<pFKey->nCol; i++){
133685 if( isIgnore==0 ){
133686 if( pIdx==0 ){
133698 sqlite3TableColumnToStorage(pFKey->pFrom,aiCol[0])+1+regData, regTemp);
133699 iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
133712 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
133723 for(i=0; i<nCol; i++){
133741 for(i=0; i<nCol; i++){
133747 assert( pIdx->aiColumn[i]>=0 );
133759 sqlite3VdbeAddOp4(v, OP_Affinity, regTemp, nCol, 0,
133777 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
133779 if( nIncr>0 && pFKey->isDeferred==0 ){
133809 pExpr = sqlite3Expr(db, TK_REGISTER, 0);
133811 if( iCol>=0 && iCol!=pTab->iPKey ){
133816 if( zColl==0 ) zColl = db->pDfltColl->zName;
133836 Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
133886 Expr *pWhere = 0; /* WHERE clause to scan with */
133889 int iFkIfZero = 0; /* Address of OP_FkIfZero */
133892 assert( pIdx==0 || pIdx->pTable==pTab );
133893 assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
133894 assert( pIdx!=0 || pFKey->nCol==1 );
133895 assert( pIdx!=0 || HasRowid(pTab) );
133897 if( nIncr<0 ){
133898 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
133910 for(i=0; i<pFKey->nCol; i++){
133919 iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
133920 assert( iCol>=0 );
133941 if( pTab==pFKey->pFrom && nIncr>0 ){
133947 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
133950 Expr *pEq, *pAll = 0;
133951 assert( pIdx!=0 );
133952 for(i=0; i<pIdx->nKeyCol; i++){
133954 assert( iCol>=0 );
133960 pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
133966 memset(&sNameContext, 0, sizeof(NameContext));
133974 if( pParse->nErr==0 ){
133975 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0, 0);
134039 fkTriggerDelete(db, pFKey->apTrigger[0]); pFKey->apTrigger[0] = 0;
134040 fkTriggerDelete(db, pFKey->apTrigger[1]); pFKey->apTrigger[1] = 0;
134065 int iSkip = 0;
134070 if( sqlite3FkReferences(pTab)==0 ){
134086 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0);
134087 pParse->disableTriggers = 0;
134098 if( (db->flags & SQLITE_DeferFKs)==0 ){
134100 sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
134103 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
134132 for(i=0; i<p->nCol; i++){
134134 if( aChange[iChildKey]>=0 ) return 1;
134137 return 0;
134159 for(i=0; i<p->nCol; i++){
134162 for(iKey=0; iKey<pTab->nCol; iKey++){
134163 if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){
134166 if( 0==sqlite3StrICmp(pCol->zCnName, zKey) ) return 1;
134173 return 0;
134185 if( (p==pFKey->apTrigger[0] && pFKey->aAction[0]==OE_SetNull)
134188 assert( (pTop->db->flags & SQLITE_FkNoAction)==0 );
134192 return 0;
134220 int *aChange, /* Array indicating UPDATEd columns (or 0) */
134230 assert( (regOld==0)!=(regNew==0) );
134233 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
134243 Index *pIdx = 0; /* Index on key columns in pTo */
134244 int *aiFree = 0;
134248 int bIgnore = 0;
134251 && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
134252 && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
134264 pTo = sqlite3LocateTable(pParse, 0, pFKey->zTo, zDb);
134267 assert( isIgnoreErrors==0 || (regOld!=0 && regNew==0) );
134269 if( pTo==0 ){
134279 for(i=0; i<pFKey->nCol; i++){
134294 iCol = pFKey->aCol[0].iFrom;
134297 for(i=0; i<pFKey->nCol; i++){
134301 assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
134318 sqlite3TableLock(pParse, iDb, pTo->tnum, 0, pTo->zName);
134321 if( regOld!=0 ){
134327 if( regNew!=0 && !isSetNullAction(pParse, pFKey) ){
134345 Index *pIdx = 0; /* Foreign key index for pFKey */
134347 int *aiCol = 0;
134349 if( aChange && fkParentIsModified(pTab, pFKey, aChange, bChngRowid)==0 ){
134356 assert( regOld==0 && regNew!=0 );
134370 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
134378 if( regNew!=0 ){
134381 if( regOld!=0 ){
134382 int eAction = pFKey->aAction[aChange!=0];
134407 pItem->zName = 0;
134414 #define COLUMN_MASK(x) (((x)>31) ? 0xffffffff : ((u32)1<<(x)))
134424 u32 mask = 0;
134429 for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
134432 Index *pIdx = 0;
134433 sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0);
134435 for(i=0; i<pIdx->nKeyCol; i++){
134436 assert( pIdx->aiColumn[i]>=0 );
134453 ** the value is 0 or greater. Parameter chngRowid is set to true if the
134477 int bHaveFK = 0; /* If FK processing is required */
134492 if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) eRet = 2;
134500 if( (pParse->db->flags & SQLITE_FkNoAction)==0
134510 return bHaveFK ? eRet : 0;
134551 int iAction = (pChanges!=0); /* 1 for UPDATE, 0 for DELETE */
134556 return 0;
134563 Index *pIdx = 0; /* Parent key index for this FK */
134564 int *aiCol = 0; /* child table cols -> parent key cols */
134565 TriggerStep *pStep = 0; /* First (only) step of trigger program */
134566 Expr *pWhere = 0; /* WHERE clause of trigger step */
134567 ExprList *pList = 0; /* Changes list if ON UPDATE CASCADE */
134568 Select *pSelect = 0; /* If RESTRICT, "SELECT RAISE(...)" */
134570 Expr *pWhen = 0; /* WHEN clause for the trigger */
134572 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ) return 0;
134575 for(i=0; i<pFKey->nCol; i++){
134583 iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
134584 assert( iFromCol>=0 );
134585 assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
134586 assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
134597 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
134598 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
134599 sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
134611 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
134612 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
134614 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
134615 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0))
134624 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
134625 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0));
134632 pDflt = 0;
134637 pNew = sqlite3ExprDup(db, pDflt, 0);
134639 pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
134642 pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
134645 sqlite3ExprListSetName(pParse, pList, &tFromCol, 0);
134659 pRaise = sqlite3PExpr(pParse, TK_RAISE, pRaise, 0);
134663 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
134666 pSrc->a[0].zName = sqlite3DbStrDup(db, zFrom);
134667 assert( pSrc->a[0].fg.fixedSchema==0 && pSrc->a[0].fg.isSubquery==0 );
134668 pSrc->a[0].u4.zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
134671 sqlite3ExprListAppend(pParse, 0, pRaise),
134674 0, 0, 0, 0, 0
134676 pWhere = 0;
134696 pWhen = sqlite3PExpr(pParse, TK_NOT, pWhen, 0);
134710 return 0;
134712 assert( pStep!=0 );
134713 assert( pTrigger!=0 );
134747 int *aChange, /* Array indicating UPDATEd columns (or 0) */
134757 if( aChange==0 || fkParentIsModified(pTab, pFKey, aChange, bChngRowid) ){
134760 sqlite3CodeRowTriggerDirect(pParse, pAct, pTab, regOld, OE_Abort, 0);
134779 assert( db!=0 );
134781 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
134784 if( db->pnBytesFreed==0 ){
134799 assert( pFKey->isDeferred==0 || pFKey->isDeferred==1 );
134803 fkTriggerDelete(db, pFKey->apTrigger[0]);
134849 assert( pParse->pVdbe!=0 );
134854 (opcode==OP_OpenWrite)?1:0, pTab->zName);
134861 assert( pPk!=0 );
134900 pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
134903 return 0;
134905 for(n=0; n<pIdx->nColumn; n++){
134908 if( x>=0 ){
134915 assert( pIdx->aColExpr!=0 );
134922 pIdx->zColAff[n] = 0;
134941 for(i=j=0; i<pTab->nCol; i++){
134942 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
134947 zColAff[j--] = 0;
134948 }while( j>=0 && zColAff[j]<=SQLITE_AFF_BLOB );
134966 ** Otherwise if iReg>0 then code an OP_Affinity opcode that will set the
134967 ** affinities for register iReg and following. Or if iReg==0,
134985 ** datatypes against the column definitions in pTab. If iReg==0, that
134989 ** register set as the OP_MakeRecord. If iReg>0 then register iReg is
134997 if( iReg==0 ){
135004 assert( pPrev!=0 );
135016 if( zColAff==0 ){
135017 zColAff = sqlite3TableAffinityStr(0, pTab);
135024 assert( zColAff!=0 );
135028 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i);
135048 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
135053 assert( pOp!=0 );
135068 assert( pOp->p4.pVtab!=0 );
135074 return 0;
135081 if( pExpr->op==TK_COLUMN && pExpr->iColumn>=0 ){
135115 if( (pTab->tabFlags & TF_HasStored)!=0 ){
135123 assert( zP4!=0 );
135125 for(ii=jj=0; zP4[jj]; ii++){
135146 for(i=0; i<pTab->nCol; i++){
135156 w.xSelectCallback = 0;
135157 w.xSelectCallback2 = 0;
135166 eProgress = 0;
135167 pRedo = 0;
135168 for(i=0; i<pTab->nCol; i++){
135170 if( (pCol->colFlags & COLFLAG_NOTAVAIL)!=0 ){
135173 w.eCode = 0;
135191 pParse->iSelfTab = 0;
135225 int memId = 0; /* Register holding maximum rowid */
135226 assert( pParse->db->aDb[iDb].pSchema!=0 );
135227 if( (pTab->tabFlags & TF_Autoincrement)!=0
135228 && (pParse->db->mDbFlags & DBFLAG_Vacuum)==0
135237 if( pSeqTab==0
135244 return 0;
135249 if( pInfo==0 ){
135253 if( pParse->db->mallocFailed ) return 0;
135280 assert( pParse->pTriggerTab==0 );
135287 /* 0 */ {OP_Null, 0, 0, 0},
135288 /* 1 */ {OP_Rewind, 0, 10, 0},
135289 /* 2 */ {OP_Column, 0, 0, 0},
135290 /* 3 */ {OP_Ne, 0, 9, 0},
135291 /* 4 */ {OP_Rowid, 0, 0, 0},
135292 /* 5 */ {OP_Column, 0, 1, 0},
135293 /* 6 */ {OP_AddImm, 0, 0, 0},
135294 /* 7 */ {OP_Copy, 0, 0, 0},
135295 /* 8 */ {OP_Goto, 0, 11, 0},
135296 /* 9 */ {OP_Next, 0, 2, 0},
135297 /* 10 */ {OP_Integer, 0, 0, 0},
135298 /* 11 */ {OP_Close, 0, 0, 0}
135303 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
135304 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
135307 if( aOp==0 ) break;
135308 aOp[0].p2 = memId;
135309 aOp[0].p3 = memId+2;
135320 if( pParse->nTab==0 ) pParse->nTab = 1;
135333 if( memId>0 ){
135354 /* 0 */ {OP_NotNull, 0, 2, 0},
135355 /* 1 */ {OP_NewRowid, 0, 0, 0},
135356 /* 2 */ {OP_MakeRecord, 0, 2, 0},
135357 /* 3 */ {OP_Insert, 0, 0, 0},
135358 /* 4 */ {OP_Close, 0, 0, 0}
135366 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
135369 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
135371 if( aOp==0 ) break;
135372 aOp[0].p1 = memId+1;
135390 # define autoIncBegin(A,B,C) (0)
135400 if( ALWAYS(pVal) && pVal->pSrc->nSrc>0 ){
135401 SrcItem *pItem = &pVal->pSrc->a[0];
135402 assert( (pItem->fg.isSubquery && pItem->u4.pSubq!=0) || pParse->nErr );
135416 for(ii=0; ii<pRow->nExpr; ii++){
135417 if( 0==sqlite3ExprIsConstant(pParse, pRow->a[ii].pExpr) ) return 0;
135428 if( exprListIsConstant(pParse,pRow)==0 ) return 0;
135429 for(ii=0; ii<pRow->nExpr; ii++){
135432 assert( pExpr->affExpr==0 );
135433 if( 0!=sqlite3ExprAffinity(pExpr) ) return 0;
135494 || exprListIsConstant(pParse,pRow)==0 /* condition (c) above */
135495 || (pLeft->pSrc->nSrc==0 &&
135496 exprListIsNoAffinity(pParse,pLeft->pEList)==0) /* condition (d) above */
135500 Select *pSelect = 0;
135509 pSelect = sqlite3SelectNew(pParse, pRow, 0, 0, 0, 0, 0, f, 0);
135517 SrcItem *p = 0; /* SrcItem that reads from co-routine */
135519 if( pLeft->pSrc->nSrc==0 ){
135524 Select *pRet = sqlite3SelectNew(pParse, 0, 0, 0, 0, 0, 0, 0, 0);
135528 if( (pParse->db->mDbFlags & DBFLAG_SchemaKnownOk)==0 ){
135539 pLeft->pPrior = 0;
135541 assert( pLeft->pNext==0 );
135542 assert( pRet->pNext==0 );
135543 p = &pRet->pSrc->a[0];
135548 if( sqlite3SrcItemAttachSubquery(pParse, p, pLeft, 0) ){
135553 pSubq->regReturn, 0, pSubq->addrFillSub);
135568 assert( pParse->nErr || dest.iSdst>0 );
135573 p = &pLeft->pSrc->a[0];
135578 if( pParse->nErr==0 ){
135580 assert( p!=0 );
135583 assert( pSubq!=0 );
135584 assert( pSubq->pSelect!=0 );
135585 assert( pSubq->pSelect->pEList!=0 );
135589 sqlite3ExprCodeExprList(pParse, pRow, pSubq->regResult, 0, 0);
135719 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
135720 int iDataCur = 0; /* VDBE cursor that is the main data repository */
135721 int iIdxCur = 0; /* First index cursor */
135724 int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
135725 int addrInsTop = 0; /* Jump to label "D" */
135726 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
135729 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
135730 u8 appendFlag = 0; /* True if the insert is likely to be an append */
135731 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
135733 ExprList *pList = 0; /* List of VALUES() to be inserted */
135737 int regFromSelect = 0;/* Base register for data coming from SELECT */
135738 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
135739 int regRowCount = 0; /* Memory cell used for the row counter */
135743 int *aRegIdx = 0; /* One register allocated to each index */
135744 int *aTabColMap = 0; /* Mapping from pTab columns to pCol entries */
135757 assert( db->mallocFailed==0 );
135758 dest.iSDParm = 0; /* Suppress a harmless compiler warning */
135764 if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
135766 pSelect->pEList = 0;
135768 pSelect = 0;
135775 if( pTab==0 ){
135780 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0,
135790 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0, &tmask);
135793 # define pTrigger 0
135794 # define tmask 0
135795 # define isView 0
135799 # define isView 0
135801 assert( (pTrigger && tmask) || (pTrigger==0 && tmask==0) );
135804 if( sqlite3TreeTrace & 0x10000 ){
135805 sqlite3TreeViewLine(0, "In sqlite3Insert() at %s:%d", __FILE__, __LINE__);
135827 if( v==0 ) goto insert_cleanup;
135828 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
135841 if( pColumn==0
135842 && pSelect!=0
135843 && pTrigger==0
135847 assert( pList==0 );
135887 bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
135890 if( aTabColMap==0 ) goto insert_cleanup;
135891 for(i=0; i<pColumn->nId; i++){
135893 if( j>=0 ){
135894 if( aTabColMap[j]==0 ) aTabColMap[j] = i+1;
135895 if( i!=j ) bIdListInOrder = 0;
135910 bIdListInOrder = 0;
135932 && pSelect->pSrc->a[0].fg.viaCoroutine
135933 && pSelect->pPrior==0
135935 SrcItem *pItem = &pSelect->pSrc->a[0];
135941 assert( pSubq->pSelect!=0 );
135942 assert( pSubq->pSelect->pEList!=0 );
135944 ExplainQueryPlan((pParse, 0, "SCAN %S", pItem));
135948 regIns = regRowid - (IsVirtual(pTab) ? 1 : 0);
135954 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
135956 dest.iSdst = bIdListInOrder ? regData : 0;
135962 assert( db->mallocFailed==0 );
136015 memset(&sNC, 0, sizeof(sNC));
136018 assert( useTempTable==0 );
136025 nColumn = 0;
136033 if( pColumn==0 && nColumn>0 ){
136036 if( ipkColumn>=0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
136039 for(i=ipkColumn-1; i>=0; i--){
136055 if( (pTab->tabFlags & (TF_HasGenerated|TF_HasHidden))!=0 ){
136056 for(i=0; i<pTab->nCol; i++){
136067 if( pColumn!=0 && nColumn!=pColumn->nId ){
136074 if( (db->flags & SQLITE_CountRows)!=0
136080 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
136086 nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, -1, 0,
136089 if( aRegIdx==0 ){
136092 for(i=0, pIdx=pTab->pIndex; i<nIdx; pIdx=pIdx->pNext, i++){
136114 pTabList->a[0].iCursor = iDataCur;
136127 }while( pNx!=0 );
136154 sqlite3VdbeReleaseRegisters(pParse, regData, pTab->nCol, 0, 0);
136157 if( ipkColumn>=0 ){
136172 nHidden = 0;
136174 for(i=0; i<pTab->nCol; i++, iRegStore++){
136186 if( ((colFlags = pTab->aCol[i].colFlags) & COLFLAG_NOINSERT)!=0 ){
136188 if( (colFlags & COLFLAG_VIRTUAL)!=0 ){
136194 }else if( (colFlags & COLFLAG_STORED)!=0 ){
136203 }else if( pColumn==0 ){
136214 assert( j>=0 && j<=pColumn->nId );
136215 if( j==0 ){
136224 }else if( nColumn==0 ){
136263 if( ipkColumn<0 ){
136271 assert( pSelect==0 ); /* Otherwise useTempTable is true */
136281 assert( pTab->nNVCol>0 || pParse->nErr>0 );
136306 sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE,
136315 sqlite3VdbeAddOp2(v, OP_Null, 0, regIns);
136317 if( ipkColumn>=0 ){
136348 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
136378 int isReplace = 0;/* Set to true if constraints may cause a replace */
136381 regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert
136384 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
136395 bUseSeek = (isReplace==0 || !sqlite3VdbeHasSubProgram(v));
136397 regIns, aRegIdx, 0, appendFlag, bUseSeek
136417 sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_AFTER,
136450 if( pParse->nested==0 && pParse->pTriggerTab==0 ){
136492 #define CKCNSTRNT_COLUMN 0x01 /* CHECK constraint uses a changing column */
136493 #define CKCNSTRNT_ROWID 0x02 /* CHECK constraint references the ROWID */
136496 * Set bit 0x01 of pWalker->eCode if pWalker->eCode to 0 and if this
136502 assert( pExpr->iColumn>=0 || pExpr->iColumn==-1 );
136503 if( pExpr->iColumn>=0 ){
136504 if( pWalker->u.aiCol[pExpr->iColumn]>=0 ){
136517 ** aiChng[i]>=0, and also the ROWID is modified if chngRowid is true.
136531 int *aiChng, /* aiChng[x]>=0 if column x changed by the UPDATE */
136535 memset(&w, 0, sizeof(w));
136536 w.eCode = 0;
136541 testcase( (w.eCode & CKCNSTRNT_ROWID)!=0 );
136544 testcase( w.eCode==0 );
136548 return w.eCode!=0;
136565 int eType; /* 0 for Index.pNext list. 1 for an array of IndexListTerm */
136568 struct { /* Use this object for eType==0: A Index.pNext list */
136588 assert( pIter->i==0 );
136590 *pIx = pIter->u.ax.aIdx[0].ix;
136591 return pIter->u.ax.aIdx[0].p;
136593 *pIx = 0;
136604 return 0;
136646 ** indices where aRegIdx[i]==0. The order of indices in aRegIdx[] is
136709 int *aRegIdx, /* Use register aRegIdx[i] for index i. 0 for unused */
136713 int regOldData, /* Previous content. 0 for INSERTs */
136718 int *aiChng, /* column i is unchanged if aiChng[i]<0 */
136723 Index *pPk = 0; /* The PRIMARY KEY index for WITHOUT ROWID tables */
136729 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
136731 Upsert *pUpsertClause = 0; /* The specific ON CONFLICT clause for pIdx */
136733 u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
136734 int upsertIpkReturn = 0; /* Address of Goto at end of IPK uniqueness check */
136735 int upsertIpkDelay = 0; /* Address of Goto to bypass initial IPK check */
136736 int ipkTop = 0; /* Top of the IPK uniqueness check */
136737 int ipkBottom = 0; /* OP_Goto at the end of the IPK uniqueness check */
136741 int addrRecheck = 0; /* Jump here to recheck all uniqueness constraints */
136742 int lblRecheckOk = 0; /* Each recheck jumps to this label if it passes */
136744 int nReplaceTrig = 0; /* Number of replace triggers coded */
136747 isUpdate = regOldData!=0;
136750 assert( v!=0 );
136759 pPk = 0;
136773 int b2ndPass = 0; /* True if currently running 2nd pass */
136774 int nSeenReplace = 0; /* Number of ON CONFLICT REPLACE operations */
136775 int nGenerated = 0; /* Number of generated columns with NOT NULL */
136777 for(i=0; i<nCol; i++){
136791 if( aiChng && aiChng[i]<0 && !isGenerated ){
136802 || pCol->iDflt==0 /* REPLACE is ABORT if no DEFAULT value */
136822 assert( (pCol->colFlags & COLFLAG_GENERATED)==0 );
136836 testcase( zMsg==0 && db->mallocFailed==0 );
136852 if( nGenerated==0 && nSeenReplace==0 ){
136861 if( nSeenReplace>0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
136875 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
136879 for(i=0; i<pCheck->nExpr; i++){
136890 if( bAffinityDone==0 ){
136896 pCopy = sqlite3ExprDup(db, pExpr, 0);
136905 assert( zName!=0 || pParse->db->mallocFailed );
136913 pParse->iSelfTab = 0;
136945 sIdxIter.eType = 0;
136946 sIdxIter.i = 0;
136947 sIdxIter.u.ax.aIdx = 0; /* Silence harmless compiler warning */
136950 if( pUpsert->pUpsertTarget==0 ){
136952 assert( pUpsert->pNextUpsert==0 );
136953 if( pUpsert->isDoUpdate==0 ){
136957 pUpsert = 0;
136962 }else if( pTab->pIndex!=0 ){
136970 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
136971 assert( aRegIdx[nIdx]>0 );
136977 if( sIdxIter.u.ax.aIdx==0 ) return; /* OOM */
136980 for(i=0, pTerm=pUpsert; pTerm; pTerm=pTerm->pNextUpsert){
136981 if( pTerm->pUpsertTarget==0 ) break;
136982 if( pTerm->pUpsertIdx==0 ) continue; /* Skip ON CONFLICT for the IPK */
136983 jj = 0;
136985 while( ALWAYS(pIdx!=0) && pIdx!=pTerm->pUpsertIdx ){
136995 for(jj=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, jj++){
137025 if( (db->flags & (SQLITE_RecTriggers|SQLITE_ForeignKeys))==0 ){
137028 pTrigger = 0;
137029 regTrigCnt = 0;
137032 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
137033 regTrigCnt = pTrigger!=0 || sqlite3FkRequired(pParse, pTab, 0, 0);
137035 pTrigger = 0;
137036 regTrigCnt = sqlite3FkRequired(pParse, pTab, 0, 0);
137042 sqlite3VdbeAddOp2(v, OP_Integer, 0, regTrigCnt);
137052 if( pkChng && pPk==0 ){
137065 pUpsertClause = sqlite3UpsertOfIndex(pUpsert,0);
137066 if( pUpsertClause!=0 ){
137067 if( pUpsertClause->isDoUpdate==0 ){
137096 /* pkChng!=0 does not mean that the rowid has changed, only that
137151 regNewData, 1, 0, OE_Replace, 1, -1);
137166 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,-1);
137174 sqlite3UpsertDoUpdate(pParse, pUpsert, pTab, 0, iDataCur);
137210 if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
137218 if( bAffinityDone==0 ){
137228 sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[ix]);
137232 pParse->iSelfTab = 0;
137239 for(i=0; i<pIdx->nColumn; i++){
137245 pParse->iSelfTab = 0;
137265 sqlite3VdbeReleaseRegisters(pParse, regIdx, pIdx->nColumn, 0, 0);
137271 if( isUpdate && pPk==pIdx && pkChng==0 ){
137290 if( pUpsertClause->isDoUpdate==0 ){
137309 if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
137312 && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
137313 0==sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0))
137314 && ( 0==(db->flags&SQLITE_ForeignKeys) || /* Condition 5 */
137315 (0==pTab->u.tab.pFKey && 0==sqlite3FkReferences(pTab)))
137345 for(i=0; i<pPk->nKeyCol; i++){
137346 assert( pPk->aiColumn[i]>=0 );
137365 for(i=0; i<pPk->nKeyCol; i++){
137368 assert( x>=0 );
137414 assert( nConflictCk>0 || db->mallocFailed );
137415 testcase( nConflictCk<=0 );
137425 regR, nPkField, 0, OE_Replace,
137451 while( nConflictCk>0 ){
137490 upsertIpkReturn = 0;
137498 assert( ipkBottom>0 );
137503 testcase( regTrigCnt!=0 && nReplaceTrig==0 );
137504 assert( regTrigCnt!=0 || nReplaceTrig==0 );
137528 sqlite3TableAffinity(v, pTab, 0);
137550 for(i=pTab->nCol-1; i>0; i--){
137551 if( pTab->aCol[i].iDflt!=0 ) break;
137574 assert( 0==(pParse->db->mDbFlags & DBFLAG_Vacuum) || CORRUPT_DB );
137575 sqlite3VdbeAddOp2(v, OP_Integer, 0, r);
137599 int *aRegIdx, /* Register used by each index. 0 for unused indices */
137609 assert( update_flags==0
137615 assert( v!=0 );
137617 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
137620 || pIdx->pNext==0
137622 if( aRegIdx[i]==0 ) continue;
137627 pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
137631 if( update_flags==0 ){
137642 pik_flags = 0;
137698 assert( op==OP_OpenWrite || p5==0 );
137699 assert( piDataCur!=0 );
137700 assert( piIdxCur!=0 );
137706 return 0;
137710 assert( v!=0 );
137711 if( iBase<0 ) iBase = pParse->nTab;
137714 if( HasRowid(pTab) && (aToOpen==0 || aToOpen[0]) ){
137716 }else if( pParse->db->noSharedCache==0 ){
137720 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
137725 p5 = 0;
137727 if( aToOpen==0 || aToOpen[i+1] ){
137767 return 0; /* Different number of columns */
137770 return 0; /* Different conflict resolution strategies */
137772 for(i=0; i<pSrc->nKeyCol; i++){
137774 return 0; /* Different columns indexed */
137777 assert( pSrc->aColExpr!=0 && pDest->aColExpr!=0 );
137778 if( sqlite3ExprCompare(0, pSrc->aColExpr->a[i].pExpr,
137779 pDest->aColExpr->a[i].pExpr, -1)!=0 ){
137780 return 0; /* Different expressions in the index */
137784 return 0; /* Different sort orders */
137786 if( sqlite3_stricmp(pSrc->azColl[i],pDest->azColl[i])!=0 ){
137787 return 0; /* Different collating sequences */
137790 if( sqlite3ExprCompare(0, pSrc->pPartIdxWhere, pDest->pPartIdxWhere, -1) ){
137791 return 0; /* Different WHERE clauses */
137839 int emptyDestTest = 0; /* Address of test for empty pDest */
137840 int emptySrcTest = 0; /* Address of test for empty pSrc */
137843 int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */
137846 assert( pSelect!=0 );
137851 return 0;
137855 return 0; /* tab1 must not be a virtual table */
137859 if( pDest->iPKey>=0 ) onError = pDest->keyConf;
137864 return 0; /* FROM clause must have exactly one term */
137866 if( pSelect->pSrc->a[0].fg.isSubquery ){
137867 return 0; /* FROM clause cannot contain a subquery */
137870 return 0; /* SELECT may not have a WHERE clause */
137873 return 0; /* SELECT may not have an ORDER BY clause */
137878 return 0; /* SELECT may not have a GROUP BY clause */
137881 return 0; /* SELECT may not have a LIMIT clause */
137884 return 0; /* SELECT may not be a compound query */
137887 return 0; /* SELECT may not be DISTINCT */
137890 assert( pEList!=0 );
137892 return 0; /* The result set must have exactly one column */
137894 assert( pEList->a[0].pExpr );
137895 if( pEList->a[0].pExpr->op!=TK_ASTERISK ){
137896 return 0; /* The result set must be the special operator "*" */
137904 pSrc = sqlite3LocateTableItem(pParse, 0, pItem);
137905 if( pSrc==0 ){
137906 return 0; /* FROM clause does not contain a real table */
137910 return 0; /* tab1 and tab2 may not be the same table */
137913 return 0; /* source and destination must both be WITHOUT ROWID or not */
137916 return 0; /* tab2 may not be a view or virtual table */
137919 return 0; /* Number of columns must be the same in tab1 and tab2 */
137922 return 0; /* Both tables must have the same INTEGER PRIMARY KEY */
137924 if( (pDest->tabFlags & TF_Strict)!=0 && (pSrc->tabFlags & TF_Strict)==0 ){
137925 return 0; /* Cannot feed from a non-strict into a strict table */
137927 for(i=0; i<pDest->nCol; i++){
137931 if( (db->mDbFlags & DBFLAG_Vacuum)==0
137934 return 0; /* Neither table may have __hidden__ columns */
137956 return 0; /* Both columns have the same generated-column type */
137962 if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){
137963 if( sqlite3ExprCompare(0,
137965 sqlite3ColumnExpr(pDest, pDestCol), -1)!=0 ){
137968 return 0; /* Different generator expressions */
137973 return 0; /* Affinity must be the same on all columns */
137976 sqlite3ColumnColl(pSrcCol))!=0 ){
137977 return 0; /* Collating sequence must be the same on all columns */
137980 return 0; /* tab2 must be NOT NULL if tab1 is */
137983 if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
137986 assert( pDestExpr==0 || pDestExpr->op==TK_SPAN );
137987 assert( pDestExpr==0 || !ExprHasProperty(pDestExpr, EP_IntValue) );
137988 assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN );
137989 assert( pSrcExpr==0 || !ExprHasProperty(pSrcExpr, EP_IntValue) );
137990 if( (pDestExpr==0)!=(pSrcExpr==0)
137991 || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken,
137992 pSrcExpr->u.zToken)!=0)
137994 return 0; /* Default values must be the same for all columns */
138005 if( pSrcIdx==0 ){
138006 return 0; /* pDestIdx has no corresponding index in pSrc */
138013 return 0; /* Corrupt schema - two indexes on the same btree */
138018 && (db->mDbFlags & DBFLAG_Vacuum)==0
138021 return 0; /* Tables have different CHECK constraints. Ticket #2252 */
138033 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){
138034 return 0;
138037 if( (db->flags & SQLITE_CountRows)!=0 ){
138038 return 0; /* xfer opt does not play well with PRAGMA count_changes */
138055 sqlite3VdbeAddOp2(v, OP_Null, 0, regData);
138059 if( (db->mDbFlags & DBFLAG_Vacuum)==0 && (
138060 (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
138081 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
138088 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
138089 if( pDest->iPKey>=0 ){
138091 if( (db->mDbFlags & DBFLAG_Vacuum)==0 ){
138093 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
138099 }else if( pDest->pIndex==0 && !(db->mDbFlags & DBFLAG_VacuumInto) ){
138103 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
138113 if( (db->mDbFlags & DBFLAG_Vacuum)==0 ){
138122 if( (db->mDbFlags & DBFLAG_Vacuum)==0 ){
138128 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
138129 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
138132 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
138135 u8 idxInsFlags = 0;
138147 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
138163 for(i=0; i<pSrcIdx->nColumn; i++){
138177 if( (db->mDbFlags & DBFLAG_Vacuum)==0
138188 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
138189 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
138196 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0);
138198 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
138199 return 0;
138246 sqlite3_stmt *pStmt = 0; /* The current SQL statement */
138247 char **azCols = 0; /* Names of result columns */
138251 if( zSql==0 ) zSql = "";
138255 while( rc==SQLITE_OK && zSql[0] ){
138256 int nCol = 0;
138257 char **azVals = 0;
138259 pStmt = 0;
138261 assert( rc==SQLITE_OK || pStmt==0 );
138270 callbackIsInit = 0;
138283 if( azCols==0 ){
138286 for(i=0; i<nCol; i++){
138290 assert( azCols[i]!=0 );
138296 for(i=0; i<nCol; i++){
138303 azVals[i] = 0;
138311 pStmt = 0;
138319 pStmt = 0;
138321 while( sqlite3Isspace(zSql[0]) ) zSql++;
138327 azCols = 0;
138336 *pzErrMsg = sqlite3DbStrDup(0, sqlite3_errmsg(db));
138337 if( *pzErrMsg==0 ){
138342 *pzErrMsg = 0;
138541 /* Added by 3.5.0 */
138644 /* Version 3.9.0 and later */
138647 /* Version 3.10.0 and later */
138651 /* Version 3.12.0 and later */
138653 /* Version 3.14.0 and later */
138656 /* Version 3.18.0 and later */
138658 /* Version 3.20.0 and later */
138669 /* Version 3.24.0 and later */
138684 /* Version 3.25.0 and later */
138691 /* Version 3.26.0 and later */
138693 /* Version 3.28.0 and later */
138696 /* Version 3.30.0 and later */
138698 /* Version 3.31.0 and later */
138704 /* Version 3.32.0 and later */
138709 /* Version 3.34.0 and later */
138714 /* Version 3.37.0 and later */
138718 /* Version 3.38.0 and later */
138725 /* Version 3.39.0 and later */
138731 /* Version 3.40.0 and later */
138733 /* Version 3.41.0 and later */
138735 /* Version 3.43.0 and later */
138737 /* Version 3.44.0 and later */
138740 /* Version 3.50.0 and later */
138988 /* Version 3.9.0 and later */
138991 /* Version 3.10.0 and later */
138995 /* Version 3.12.0 and later */
138997 /* Version 3.14.0 and later */
139000 /* Version 3.18.0 and later */
139002 /* Version 3.20.0 and later */
139008 /* Version 3.22.0 and later */
139012 /* Version 3.24.0 and later */
139027 /* Version 3.25.0 and later */
139029 /* Version 3.26.0 and later */
139031 /* Version 3.28.0 and later */
139034 /* Version 3.30.0 and later */
139036 /* Version 3.31.0 and later */
139042 /* Version 3.32.0 and later */
139046 /* Version 3.34.0 and later */
139051 /* Version 3.37.0 and later */
139053 /* Version 3.38.0 and later */
139060 /* Version 3.39.0 and later */
139066 /* Version 3.40.0 and later */
139068 /* Version 3.41.0 and later */
139070 /* Version 3.43.0 and later */
139072 /* Version 3.44.0 and later */
139075 /* Version 3.50.0 and later */
139082 # define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
139107 # define sqlite3_column_database_name 0
139108 # define sqlite3_column_database_name16 0
139109 # define sqlite3_column_table_name 0
139110 # define sqlite3_column_table_name16 0
139111 # define sqlite3_column_origin_name 0
139112 # define sqlite3_column_origin_name16 0
139116 # define sqlite3_set_authorizer 0
139120 # define sqlite3_bind_text16 0
139121 # define sqlite3_collation_needed16 0
139122 # define sqlite3_column_decltype16 0
139123 # define sqlite3_column_name16 0
139124 # define sqlite3_column_text16 0
139125 # define sqlite3_complete16 0
139126 # define sqlite3_create_collation16 0
139127 # define sqlite3_create_function16 0
139128 # define sqlite3_errmsg16 0
139129 # define sqlite3_open16 0
139130 # define sqlite3_prepare16 0
139131 # define sqlite3_prepare16_v2 0
139132 # define sqlite3_prepare16_v3 0
139133 # define sqlite3_result_error16 0
139134 # define sqlite3_result_text16 0
139135 # define sqlite3_result_text16be 0
139136 # define sqlite3_result_text16le 0
139137 # define sqlite3_value_text16 0
139138 # define sqlite3_value_text16be 0
139139 # define sqlite3_value_text16le 0
139140 # define sqlite3_column_database_name16 0
139141 # define sqlite3_column_table_name16 0
139142 # define sqlite3_column_origin_name16 0
139146 # define sqlite3_complete 0
139147 # define sqlite3_complete16 0
139151 # define sqlite3_column_decltype16 0
139152 # define sqlite3_column_decltype 0
139156 # define sqlite3_progress_handler 0
139160 # define sqlite3_create_module 0
139161 # define sqlite3_create_module_v2 0
139162 # define sqlite3_declare_vtab 0
139163 # define sqlite3_vtab_config 0
139164 # define sqlite3_vtab_on_conflict 0
139165 # define sqlite3_vtab_collation 0
139169 # define sqlite3_enable_shared_cache 0
139173 # define sqlite3_profile 0
139174 # define sqlite3_trace 0
139178 # define sqlite3_free_table 0
139179 # define sqlite3_get_table 0
139183 #define sqlite3_bind_zeroblob 0
139184 #define sqlite3_blob_bytes 0
139185 #define sqlite3_blob_close 0
139186 #define sqlite3_blob_open 0
139187 #define sqlite3_blob_read 0
139188 #define sqlite3_blob_write 0
139189 #define sqlite3_blob_reopen 0
139193 # define sqlite3_trace_v2 0
139216 0,
139275 0,
139283 0, /* Was sqlite3_global_recover(), but that function is deprecated */
139319 0,
139326 0,
139366 ** Added for 3.5.0
139379 0,
139380 0,
139381 0,
139382 0,
139383 0,
139412 ** Added for 3.6.0
139432 0,
139433 0,
139448 0,
139455 0,
139456 0,
139457 0,
139493 /* Version 3.9.0 and later */
139496 /* Version 3.10.0 and later */
139500 /* Version 3.12.0 and later */
139502 /* Version 3.14.0 and later */
139505 /* Version 3.18.0 and later */
139507 /* Version 3.20.0 and later */
139513 /* Version 3.22.0 and later */
139517 /* Version 3.24.0 and later */
139532 /* Version 3.25.0 and later */
139534 /* Version 3.26.0 and later */
139538 0,
139540 /* Version 3.28.0 and later */
139543 /* Version 3.30.0 and later */
139547 0,
139549 /* Version 3.31.0 and later */
139555 /* Version 3.32.0 and later */
139559 /* Version 3.34.0 and later */
139564 /* Version 3.37.0 and later */
139566 /* Version 3.38.0 and later */
139575 0,
139576 0,
139577 0,
139578 0,
139579 0,
139581 /* Version 3.39.0 and later */
139586 0,
139587 0,
139590 /* Version 3.40.0 and later */
139592 /* Version 3.41.0 and later */
139594 /* Version 3.43.0 and later */
139596 /* Version 3.44.0 and later */
139599 /* Version 3.50.0 and later */
139613 ** zFile. The entry point is zProc. zProc may be 0 in which case a
139619 ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
139626 const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
139627 char **pzErrMsg /* Put error message here if not 0 */
139632 char *zErrmsg = 0;
139634 char *zAltEntry = 0;
139652 if( pzErrMsg ) *pzErrMsg = 0;
139658 ** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0)
139661 if( (db->flags & SQLITE_LoadExtension)==0 ){
139682 if( nMsg==0 ) goto extension_not_found;
139686 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
139688 if( zAltFile==0 ) return SQLITE_NOMEM_BKPT;
139695 if( handle==0 ) goto extension_not_found;
139709 if( xInit==0 && zProc==0 ){
139713 if( zAltEntry==0 ){
139718 for(iFile=ncFile-1; iFile>=0 && !DirSep(zFile[iFile]); iFile--){}
139720 if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
139721 for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
139730 if( xInit==0 ){
139735 assert( nMsg<0x7fffffff ); /* zErrmsg would be NULL if not so */
139759 if( aHandle==0 ){
139762 if( db->nExtension>0 ){
139776 assert( nMsg<0x7fffffff ); /* zErrmsg would be NULL if not so */
139787 const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
139788 char **pzErrMsg /* Put error message here if not 0 */
139805 for(i=0; i<db->nExtension; i++){
139842 } sqlite3Autoext = { 0, 0 };
139853 # define wsdAutoext x[0]
139869 if( xInit==0 ) return SQLITE_MISUSE_BKPT;
139884 for(i=0; i<wsdAutoext.nExt; i++){
139888 u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
139891 if( aNew==0 ){
139900 assert( (rc&0xff)==rc );
139911 ** Return 1 if xInit was found on the list and removed. Return 0 if xInit
139921 int n = 0;
139924 if( xInit==0 ) return 0;
139927 for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
139953 wsdAutoext.aExt = 0;
139954 wsdAutoext.nExt = 0;
139971 if( wsdAutoext.nExt==0 ){
139975 for(i=0; go; i++){
139981 const sqlite3_api_routines *pThunk = 0;
139987 xInit = 0;
139988 go = 0;
139993 zErrmsg = 0;
139994 if( xInit && (rc = xInit(db, &zErrmsg, pThunk))!=0 ){
139997 go = 0;
140024 # define SQLITE_ENABLE_LOCKING_STYLE 0
140044 #define PragTyp_ACTIVATE_EXTENSIONS 0
140092 #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
140093 #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
140094 #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
140095 #define PragFlg_ReadOnly 0x08 /* Read-only HEADER_VALUE */
140096 #define PragFlg_Result0 0x10 /* Acts as query when no argument */
140097 #define PragFlg_Result1 0x20 /* Acts as query when has one argument */
140098 #define PragFlg_SchemaOpt 0x40 /* Schema restricts name search if present */
140099 #define PragFlg_SchemaReq 0x80 /* Schema required - "main" is default */
140106 /* 0 */ "id", /* Used by: foreign_key_list */
140175 u8 nPragCName; /* Num of col names. 0 means use pragma name */
140182 /* ePragFlg: */ 0,
140183 /* ColNames: */ 0, 0,
140184 /* iArg: */ 0 },
140189 /* ColNames: */ 0, 0,
140190 /* iArg: */ 0 },
140195 /* ColNames: */ 0, 0,
140202 /* ColNames: */ 0, 0,
140203 /* iArg: */ 0 },
140210 /* ColNames: */ 0, 0,
140218 /* iArg: */ 0 },
140223 /* ColNames: */ 0, 0,
140224 /* iArg: */ 0 },
140230 /* ColNames: */ 0, 0,
140231 /* iArg: */ 0 },
140237 /* ColNames: */ 0, 0,
140238 /* iArg: */ 0 },
140243 /* ColNames: */ 0, 0,
140249 /* ColNames: */ 0, 0,
140257 /* iArg: */ 0 },
140263 /* ColNames: */ 0, 0,
140264 /* iArg: */ 0 },
140270 /* ColNames: */ 0, 0,
140277 /* ColNames: */ 0, 0,
140278 /* iArg: */ 0 },
140284 /* ColNames: */ 0, 0,
140292 /* iArg: */ 0 },
140299 /* iArg: */ 0 },
140306 /* ColNames: */ 0, 0,
140314 /* ColNames: */ 0, 0,
140321 /* ColNames: */ 0, 0,
140322 /* iArg: */ 0 },
140329 /* iArg: */ 0 },
140335 /* ColNames: */ 0, 8,
140336 /* iArg: */ 0 },
140343 /* ColNames: */ 0, 0,
140351 /* ColNames: */ 0, 0,
140358 /* ColNames: */ 0, 0,
140363 /* ColNames: */ 0, 0,
140372 /* iArg: */ 0 },
140378 /* ColNames: */ 0, 0,
140379 /* iArg: */ 0 },
140385 /* ColNames: */ 0, 0,
140393 /* ColNames: */ 0, 0,
140394 /* iArg: */ 0 },
140401 /* iArg: */ 0 },
140406 /* iArg: */ 0 },
140417 /* ColNames: */ 0, 0,
140418 /* iArg: */ 0 },
140424 /* ColNames: */ 0, 0,
140425 /* iArg: */ 0 },
140429 /* ColNames: */ 0, 0,
140430 /* iArg: */ 0 },
140436 /* ColNames: */ 0, 0,
140443 /* ColNames: */ 0, 0,
140444 /* iArg: */ 0 },
140451 /* iArg: */ 0 },
140457 /* ColNames: */ 0, 0,
140458 /* iArg: */ 0 },
140462 /* ColNames: */ 0, 0,
140463 /* iArg: */ 0 },
140466 /* ePragFlg: */ 0,
140467 /* ColNames: */ 0, 0,
140468 /* iArg: */ 0 },
140477 /* iArg: */ 0 },
140484 /* ColNames: */ 0, 0,
140485 /* iArg: */ 0 },
140490 /* ColNames: */ 0, 0,
140491 /* iArg: */ 0 },
140495 /* ColNames: */ 0, 0,
140496 /* iArg: */ 0 },
140503 /* ColNames: */ 0, 0,
140512 /* iArg: */ 0 },
140518 /* ColNames: */ 0, 0,
140525 /* ColNames: */ 0, 0,
140526 /* iArg: */ 0 },
140532 /* ColNames: */ 0, 0,
140537 /* ColNames: */ 0, 0,
140542 /* ColNames: */ 0, 0,
140549 /* ColNames: */ 0, 0,
140556 /* ColNames: */ 0, 0,
140557 /* iArg: */ 0 },
140563 /* ColNames: */ 0, 0,
140569 /* ColNames: */ 0, 0,
140570 /* iArg: */ 0 },
140574 /* ColNames: */ 0, 0,
140575 /* iArg: */ 0 },
140581 /* ColNames: */ 0, 0,
140590 /* iArg: */ 0 },
140596 /* ColNames: */ 0, 0,
140597 /* iArg: */ 0 },
140604 /* iArg: */ 0 },
140609 /* iArg: */ 0 },
140620 /* ColNames: */ 0, 0,
140621 /* iArg: */ 0 },
140625 /* ColNames: */ 0, 0,
140626 /* iArg: */ 0 },
140631 /* ColNames: */ 0, 0,
140632 /* iArg: */ 0 },
140637 /* ColNames: */ 0, 0,
140644 /* ColNames: */ 0, 0,
140652 /* ColNames: */ 0, 0,
140657 /* ColNames: */ 0, 0,
140662 /* ColNames: */ 0, 0,
140667 /* ColNames: */ 0, 0,
140672 /* ColNames: */ 0, 0,
140679 /* ePragFlg: */ 0,
140680 /* ColNames: */ 0, 0,
140681 /* iArg: */ 0 },
140686 /* iArg: */ 0 },
140692 /* ColNames: */ 0, 0,
140702 ** When the 0x10 bit of PRAGMA optimize is set, any ANALYZE commands
140714 ** has not been previously run and the 0x10000 flag is included so that
140718 ** optimize on a PI-4 is more like 1 millisecond or less with the 0x10000
140719 ** flag or less than 100 microseconds without the 0x10000 flag.
140730 ** Interpret the given string as a safety level. Return 0 for OFF,
140738 ** and older scripts may have used numbers 0 for OFF and 1 for ON.
140743 static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 15, 20};
140745 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 3, 2};
140752 for(i=0; i<ArraySize(iLength); i++){
140753 if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0
140766 return getSafetyLevel(z,1,dflt)!=0;
140780 if( 0==sqlite3StrICmp(z, "exclusive") ) return PAGER_LOCKINGMODE_EXCLUSIVE;
140781 if( 0==sqlite3StrICmp(z, "normal") ) return PAGER_LOCKINGMODE_NORMAL;
140791 ** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
140795 if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE;
140796 if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL;
140797 if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR;
140799 return (u8)((i>=0&&i<=2)?i:0);
140807 ** and 0 to use the compile-time default.
140810 if( z[0]>='0' && z[0]<='2' ){
140811 return z[0] - '0';
140812 }else if( sqlite3StrICmp(z, "file")==0 ){
140814 }else if( sqlite3StrICmp(z, "memory")==0 ){
140817 return 0;
140829 if( db->aDb[1].pBt!=0 ){
140838 db->aDb[1].pBt = 0;
140871 sqlite3VdbeSetNumCols(v, n==0 ? 1 : n);
140872 if( n==0 ){
140873 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, pPragma->zName, SQLITE_STATIC);
140876 for(i=0, j=pPragma->iPragCName; i<n; i++, j++){
140886 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
140905 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
140919 while( (n--) > 0 ){
140964 assert( PAGER_JOURNALMODE_DELETE==0 );
140970 assert( eMode>=0 && eMode<=ArraySize(azModeName) );
140972 if( eMode==ArraySize(azModeName) ) return 0;
140980 int upr, lwr, mid = 0, rc;
140981 lwr = 0;
140986 if( rc==0 ) break;
140987 if( rc<0 ){
140993 return lwr>upr ? 0 : &aPragmaName[mid];
141013 if( showInternFuncs ) mask = 0xffffffff;
141016 static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" };
141018 assert( SQLITE_FUNC_ENCMASK==0x3 );
141019 assert( strcmp(azEnc[SQLITE_UTF8],"utf8")==0 );
141020 assert( strcmp(azEnc[SQLITE_UTF16LE],"utf16le")==0 );
141021 assert( strcmp(azEnc[SQLITE_UTF16BE],"utf16be")==0 );
141023 if( p->xSFunc==0 ) continue;
141024 if( (p->funcFlags & SQLITE_FUNC_INTERNAL)!=0
141025 && showInternFuncs==0
141029 if( p->xValue!=0 ){
141031 }else if( p->xFinalize!=0 ){
141084 char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */
141085 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
141086 const char *zDb = 0; /* The database name */
141096 if( v==0 ) return;
141103 if( iDb<0 ) return;
141122 zDb = pId2->n>0 ? pDb->zDbSName : 0;
141142 aFcntl[0] = 0;
141145 aFcntl[3] = 0;
141146 db->busyHandler.nBusy = 0;
141150 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, aFcntl[0], SQLITE_TRANSIENT);
141151 returnSingleText(v, aFcntl[0]);
141152 sqlite3_free(aFcntl[0]);
141156 if( aFcntl[0] ){
141157 sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
141158 sqlite3_free(aFcntl[0]);
141167 if( pPragma==0 ){
141174 if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){
141179 if( (pPragma->mPragFlg & PragFlg_NoColumns)==0
141180 && ((pPragma->mPragFlg & PragFlg_NoColumns1)==0 || zRight==0)
141208 { OP_Transaction, 0, 0, 0}, /* 0 */
141209 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
141210 { OP_IfPos, 1, 8, 0},
141211 { OP_Integer, 0, 2, 0},
141213 { OP_IfPos, 1, 8, 0},
141214 { OP_Integer, 0, 1, 0}, /* 6 */
141215 { OP_Noop, 0, 0, 0},
141216 { OP_ResultRow, 1, 1, 0},
141224 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
141225 aOp[0].p1 = iDb;
141230 sqlite3BeginWriteOperation(pParse, 0, iDb);
141232 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
141252 assert( pBt!=0 );
141254 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
141261 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,0,0) ){
141279 assert( pBt!=0 );
141281 if( sqlite3_stricmp(zRight, "fast")==0 ){
141284 b = sqlite3GetBoolean(zRight, 0);
141287 if( pId2->n==0 && b>=0 ){
141289 for(ii=0; ii<db->nDb; ii++){
141317 i64 x = 0;
141320 if( sqlite3Tolower(zLeft[0])=='p' ){
141323 if( zRight && sqlite3DecOrHexToI64(zRight,&x)==0 ){
141324 if( x<0 ) x = 0;
141325 else if( x>0xfffffffe ) x = 0xfffffffe;
141327 x = 0;
141343 if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
141351 if( pId2->n==0 ){
141361 assert(pDb==&db->aDb[0]);
141390 if( zRight==0 ){
141397 for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){
141398 if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
141405 if( eMode==PAGER_JOURNALMODE_OFF && (db->flags & SQLITE_Defensive)!=0 ){
141411 if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){
141413 iDb = 0;
141416 for(ii=db->nDb-1; ii>=0; ii--){
141417 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
141451 ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
141456 assert( pBt!=0 );
141461 assert( eAuto>=0 && eAuto<=2 );
141477 { OP_Transaction, 0, 1, 0}, /* 0 */
141478 { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE},
141479 { OP_If, 1, 0, 0}, /* 2 */
141480 { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
141481 { OP_SetCookie, 0, BTREE_INCR_VACUUM, 0}, /* 4 */
141487 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
141488 aOp[0].p1 = iDb;
141507 int iLimit = 0, addr;
141508 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
141509 iLimit = 0x7fffffff;
141511 sqlite3BeginWriteOperation(pParse, 0, iDb);
141535 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
141569 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
141572 (db->flags & SQLITE_CacheSpill)==0 ? 0 :
141573 sqlite3BtreeSetSpillSize(pDb->pBt,0));
141579 if( sqlite3GetBoolean(zRight, size!=0) ){
141600 ** as little or as much as it wants. Except, if N is set to 0 then the
141605 #if SQLITE_MAX_MMAP_SIZE>0
141606 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
141610 if( sz<0 ) sz = sqlite3GlobalConfig.szMmap;
141611 if( pId2->n==0 ) db->szMmap = sz;
141612 for(ii=db->nDb-1; ii>=0; ii--){
141613 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
141621 sz = 0;
141669 if( zRight[0] ){
141672 if( rc!=SQLITE_OK || res==0 ){
141678 if( SQLITE_TEMP_STORE==0
141685 if( zRight[0] ){
141688 sqlite3_temp_directory = 0;
141716 if( zRight[0] ){
141719 if( rc!=SQLITE_OK || res==0 ){
141726 if( zRight[0] ){
141729 sqlite3_data_directory = 0;
141759 if( zRight[0] ){
141792 int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
141793 if( iLevel==0 ) iLevel = 1;
141805 if( zRight==0 ){
141807 returnSingleInt(v, (db->flags & pPragma->iArg)!=0 );
141810 if( db->autoCommit==0 ){
141816 if( sqlite3GetBoolean(zRight, 0) ){
141817 if( (mask & SQLITE_WriteSchema)==0
141818 || (db->flags & SQLITE_Defensive)==0
141825 db->nDeferredImmCons = 0;
141826 db->nDeferredCons = 0;
141828 if( (mask & SQLITE_WriteSchema)!=0
141829 && sqlite3_stricmp(zRight, "reset")==0
141856 ** cid: Column id (numbered from left to right, starting at 0)
141869 int nHidden = 0;
141874 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
141875 int isHidden = 0;
141878 if( pPragma->iArg==0 ){
141890 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
141891 k = 0;
141892 }else if( pPk==0 ){
141898 assert( pColExpr==0 || pColExpr->op==TK_SPAN || isHidden>=2 );
141899 assert( pColExpr==0 || !ExprHasProperty(pColExpr, EP_IntValue)
141905 pCol->notNull ? 1 : 0,
141906 (isHidden>=2 || pColExpr==0) ? 0 : pColExpr->u.zToken,
141931 for(ii=0; ii<db->nDb; ii++){
141935 if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue;
141947 if( k==0 ){ initNCol = 0; break; }
141949 if( pTab->nCol==0 ){
141952 sqlite3_stmt *pDummy = 0;
141954 &pDummy, 0);
141971 if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue;
141986 (pTab->tabFlags & TF_WithoutRowid)!=0,
141987 (pTab->tabFlags & TF_Strict)!=0
142004 0,
142012 pIdx->aiRowLogEst[0],
142025 if( pIdx==0 ){
142050 for(i=0; i<mx; i++){
142053 cnum<0 ? 0 : pTab->aCol[cnum].zCnName);
142075 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
142082 pIdx->pPartIdxWhere!=0);
142091 for(i=0; i<db->nDb; i++){
142092 if( db->aDb[i].pBt==0 ) continue;
142093 assert( db->aDb[i].zDbSName!=0 );
142103 int i = 0;
142118 int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0;
142120 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
142128 assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
142129 pragmaFunclistLine(v, p, 0, showInternFunc);
142148 for(i=0; i<ArraySize(aPragmaName); i++){
142166 int i = 0;
142171 for(j=0; j<pFK->nCol; j++){
142179 actionName(pFK->aAction[0]), /* ON DELETE */
142214 pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
142215 k = 0;
142220 if( pTab==0 || !IsOrdinaryTable(pTab) || pTab->u.tab.pFKey==0 ) continue;
142224 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
142226 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
142231 if( pParent==0 ) continue;
142232 pIdx = 0;
142233 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
142234 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
142235 if( x==0 ){
142236 if( pIdx==0 ){
142243 k = 0;
142247 assert( pParse->nErr>0 || pFK==0 );
142250 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
142254 pIdx = 0;
142255 aiCols = 0;
142258 assert( x==0 || db->mallocFailed );
142267 for(j=0; j<pFK->nCol; j++){
142269 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
142276 sqlite3VdbeAddOp4(v, OP_Affinity, regRow, pFK->nCol, 0,
142289 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
142291 sqlite3VdbeAddOp2(v, OP_Null, 0, regResult+1);
142298 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
142312 sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
142349 Table *pObjTab = 0; /* Check only this one table, if not NULL */
142351 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
142359 ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb
142362 assert( iDb>=0 );
142363 assert( iDb==0 || pId2->z );
142364 if( pId2->z==0 ) iDb = -1;
142373 if( mxErr<=0 ){
142377 pObjTab = sqlite3LocateTable(pParse, 0, zRight,
142378 iDb>=0 ? db->aDb[iDb].zDbSName : 0);
142384 for(i=0; i<db->nDb; i++){
142388 int cnt = 0; /* Number of entries in aRoot[] */
142391 if( iDb>=0 && i!=iDb ) continue;
142394 pParse->okConstFactor = 0; /* tag-20230327-1 */
142401 assert( sqlite3SchemaMutexHeld(db, i, 0) );
142403 for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
142409 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
142411 if( cnt==0 ) continue;
142414 if( aRoot==0 ) break;
142415 cnt = 0;
142416 if( pObjTab ) aRoot[++cnt] = 0;
142426 aRoot[0] = cnt;
142430 sqlite3VdbeAddOp3(v, OP_Null, 0, 8, 8+cnt);
142437 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
142445 cnt = pObjTab ? 1 : 0;
142448 int iTab = 0;
142462 if( pIdx->pPartIdxWhere==0 ){
142463 addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+cnt, 0, 8+iTab);
142479 Index *pPrior = 0; /* Previous index */
142490 pPk = 0;
142491 r2 = 0;
142497 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
142498 1, 0, &iDataCur, &iIdxCur);
142502 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
142503 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
142504 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
142508 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
142519 for(j=0; j<pTab->nCol; j++){
142520 if( (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)==0 ) mxCol++;
142529 if( mxCol>=0 ){
142539 a1 = sqlite3VdbeAddOp4Int(v, OP_IdxGT, iDataCur, 0,r2,pPk->nKeyCol);
142545 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
142549 for(j=0; j<pPk->nKeyCol; j++){
142563 bStrict = (pTab->tabFlags & TF_Strict)!=0;
142564 for(j=0; j<pTab->nCol; j++){
142578 if( pCol->notNull==0 && !doTypeCheck ) continue;
142588 sqlite3_value *pDfltValue = 0;
142613 if( p1<0 ){
142614 sqlite3VdbeChangeP5(v, 0x0f); /* INT, REAL, TEXT, or BLOB */
142617 sqlite3VdbeChangeP5(v, 0x0d); /* INT, TEXT, or BLOB */
142629 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
142641 0x1f, /* ANY */
142642 0x18, /* BLOB */
142643 0x11, /* INT */
142644 0x11, /* INTEGER */
142645 0x13, /* REAL */
142646 0x14 /* TEXT */
142655 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
142660 sqlite3VdbeChangeP5(v, 0x1c); /* NULL, TEXT, or BLOB */
142664 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
142669 sqlite3VdbeChangeP5(v, 0x1b); /* NULL, INT, FLOAT, or BLOB */
142671 if( p1>=0 ){
142674 sqlite3VdbeAddOp4(v, OP_Affinity, 3, 1, 0, "C", P4_STATIC);
142676 sqlite3VdbeChangeP5(v, 0x1c); /* NULL, TEXT, or BLOB */
142680 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
142687 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
142688 ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
142689 if( db->mallocFailed==0 ){
142695 for(k=pCheck->nExpr-1; k>0; k--){
142696 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
142698 sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
142701 pParse->iSelfTab = 0;
142704 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
142712 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
142717 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
142740 jmp7 = sqlite3VdbeAddOp3(v, OP_Eq, 3, 0, r1+pIdx->nColumn-1);
142752 label6 = 0;
142753 for(kk=0; kk<pIdx->nKeyCol; kk++){
142755 if( label6==0 ) label6 = sqlite3VdbeMakeLabel(pParse);
142775 for(kk=0; kk<pIdx->nKeyCol; kk++){
142778 if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
142814 if( pTab->nCol<=0 ){
142815 const char *zMod = pTab->u.vtab.azArg[0];
142816 if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue;
142819 if( pTab->u.vtab.p==0 ) continue;
142821 if( NEVER(pVTab==0) ) continue;
142822 if( NEVER(pVTab->pModule==0) ) continue;
142824 if( pVTab->pModule->xIntegrity==0 ) continue;
142838 { OP_AddImm, 1, 0, 0}, /* 0 */
142839 { OP_IfNotZero, 1, 4, 0}, /* 1 */
142840 { OP_String8, 0, 3, 0}, /* 2 */
142841 { OP_ResultRow, 3, 1, 0}, /* 3 */
142842 { OP_Halt, 0, 0, 0}, /* 4 */
142843 { OP_String8, 0, 3, 0}, /* 5 */
142844 { OP_Goto, 0, 3, 0}, /* 6 */
142850 aOp[0].p2 = 1-mxErr;
142856 sqlite3VdbeChangeP3(v, 0, sqlite3VdbeCurrentAddr(v)-2);
142896 { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
142897 { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
142898 { 0, 0 }
142913 if( (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){
142914 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
142915 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
142967 if( zRight && (pPragma->mPragFlg & PragFlg_ReadOnly)==0 ){
142970 { OP_Transaction, 0, 1, 0}, /* 0 */
142971 { OP_SetCookie, 0, 0, 0}, /* 1 */
142975 aOp = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
142976 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
142977 aOp[0].p1 = iDb;
142982 if( iCookie==BTREE_SCHEMA_VERSION && (db->flags & SQLITE_Defensive)!=0 ){
142990 { OP_Transaction, 0, 0, 0}, /* 0 */
142991 { OP_ReadCookie, 0, 1, 0}, /* 1 */
142992 { OP_ResultRow, 1, 1, 0}
142996 aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0);
142997 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
142998 aOp[0].p1 = iDb;
143015 int i = 0;
143018 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
143037 if( sqlite3StrICmp(zRight, "full")==0 ){
143039 }else if( sqlite3StrICmp(zRight, "restart")==0 ){
143041 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
143065 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
143097 ** 0x00001 Debugging mode. Do not actually perform any optimizations
143101 ** 0x00002 Run ANALYZE on tables that might benefit. On by default.
143104 ** 0x00010 Run all ANALYZE operations using an analysis_limit that
143113 ** 0x10000 Look at tables to see if they need to be reanalyzed
143117 ** The default MASK is and always shall be 0x0fffe. In the current
143118 ** implementation, the default mask only covers the 0x00002 optimization,
143119 ** though additional optimizations that are covered by 0x0fffe might be
143121 ** be explicitly requested have masks of 0x10000 or greater.
143128 ** (1) MASK bit 0x00002 is set.
143135 ** (4a) The 0x10000 MASK bit is set.
143166 int nCheck = 0; /* Number of tables to be optimized */
143167 int nBtree = 0; /* Number of btrees to scan */
143172 if( (opMask & 0x02)==0 ) break;
143174 opMask = 0xfffe;
143176 if( (opMask & 0x10)==0 ){
143177 nLimit = 0;
143178 }else if( db->nAnalysisLimit>0
143180 nLimit = 0;
143196 if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ) continue;
143203 nIndex = 0;
143213 ** unless the 0x10000 MASK bit is set. */
143214 if( (pTab->tabFlags & TF_MaybeReanalyze)!=0 ){
143216 }else if( opMask & 0x10000 ){
143217 /* Check for size change if 0x10000 is set */
143218 }else if( pTab->pIndex!=0 && szThreshold<0 ){
143229 sqlite3BeginWriteOperation(pParse, 0, iDb);
143237 if( szThreshold>=0 ){
143251 if( opMask & 0x01 ){
143253 sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC);
143256 sqlite3VdbeAddOp4(v, OP_SqlExec, nLimit ? 0x02 : 00, nLimit, 0,
143266 if( !db->mallocFailed && nLimit>0 && nBtree>100 ){
143271 aOp = sqlite3VdbeGetOp(v, 0);
143273 for(iAddr=0; iAddr<iEnd; iAddr++){
143286 ** then 0 is returned. Setting the busy_timeout to 0 or negative
143333 if( N>0 && (iPrior==0 || iPrior>N) ) sqlite3_hard_heap_limit64(N);
143350 && N>=0
143352 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
143369 && N>=0
143371 db->nAnalysisLimit = (int)(N&0x7fffffff);
143387 for(i=0; i<db->nDb; i++){
143391 if( db->aDb[i].zDbSName==0 ) continue;
143393 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
143395 }else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0,
143407 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
143461 PragmaVtab *pTab = 0;
143470 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
143472 for(i=0, j=pPragma->iPragCName; i<pPragma->nPragCName; i++, j++){
143476 if( i==0 ){
143480 j = 0;
143495 if( pTab==0 ){
143498 memset(pTab, 0, sizeof(PragmaVtab));
143535 if( pTab->nHidden==0 ){ return SQLITE_OK; }
143537 seen[0] = 0;
143538 seen[1] = 0;
143539 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
143542 if( pConstraint->usable==0 ) return SQLITE_CONSTRAINT;
143547 if( seen[0]==0 ){
143552 j = seen[0]-1;
143569 if( pCsr==0 ) return SQLITE_NOMEM;
143570 memset(pCsr, 0, sizeof(PragmaVtabCursor));
143580 pCsr->pPragma = 0;
143581 pCsr->iRowid = 0;
143582 for(i=0; i<ArraySize(pCsr->azArg); i++){
143584 pCsr->azArg[i] = 0;
143606 pCsr->pPragma = 0;
143630 j = (pTab->pName->mPragFlg & PragFlg_Result1)!=0 ? 0 : 1;
143631 for(i=0; i<argc; i++, j++){
143634 assert( pCsr->azArg[j]==0 );
143637 if( pCsr->azArg[j]==0 ){
143642 sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]);
143648 if( pCsr->azArg[0] ){
143649 sqlite3_str_appendf(&acc, "=%Q", pCsr->azArg[0]);
143652 if( zSql==0 ) return SQLITE_NOMEM;
143653 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pPragma, 0);
143667 return (pCsr->pPragma==0);
143699 0, /* iVersion */
143700 0, /* xCreate - create a table */
143704 0, /* xDestroy - Drop a table */
143712 0, /* xUpdate - write data */
143713 0, /* xBegin - begin transaction */
143714 0, /* xSync - sync transaction */
143715 0, /* xCommit - commit transaction */
143716 0, /* xRollback - rollback transaction */
143717 0, /* xFindFunction - function overloading */
143718 0, /* xRename - rename the table */
143719 0, /* xSavepoint */
143720 0, /* xRelease */
143721 0, /* xRollbackTo */
143722 0, /* xShadowName */
143723 0 /* xIntegrity */
143733 assert( sqlite3_strnicmp(zName, "pragma_", 7)==0 );
143735 if( pName==0 ) return 0;
143736 if( (pName->mPragFlg & (PragFlg_Result0|PragFlg_Result1))==0 ) return 0;
143737 assert( sqlite3HashFind(&db->aModule, zName)==0 );
143738 return sqlite3VtabCreateModule(db, zName, &pragmaVtabModule, (void*)pName, 0);
143776 }else if( pData->pzErrMsg[0]!=0 ){
143785 "error in %s %s after %s: %s", azObj[0], azObj[1],
143796 if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra);
143812 return 0;
143834 ** argv[0] = type of object: "table", "index", "trigger", or "view".
143837 ** argv[3] = root page number for table or index. 0 for trigger or view.
143850 if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
143853 corruptSchema(pData, argv, 0);
143857 assert( iDb>=0 && iDb<db->nDb );
143858 if( argv[3]==0 ){
143859 corruptSchema(pData, argv, 0);
143861 && 'c'==sqlite3UpperToLower[(unsigned char)argv[4][0]]
143880 if( sqlite3GetUInt32(argv[3], &db->init.newTnum)==0
143881 || (db->init.newTnum>pData->mxPage && pData->mxPage>0)
143887 db->init.orphanTrigger = 0;
143889 pStmt = 0;
143890 TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, 0);
143892 assert( (rc&0xFF)==(rcp&0xFF) );
143894 /* assert( saved_iDb==0 || (db->mDbFlags & DBFLAG_Vacuum)!=0 ); */
143902 }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){
143909 }else if( argv[1]==0 || (argv[4]!=0 && argv[4][0]!=0) ){
143910 corruptSchema(pData, argv, 0);
143920 if( pIndex==0 ){
143923 if( sqlite3GetUInt32(argv[3],&pIndex->tnum)==0
143933 return 0;
143939 ** database file is given by iDb. iDb==0 is used for the main
143955 int openedTransaction = 0;
143958 assert( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0 );
143959 assert( iDb>=0 && iDb<db->nDb );
143971 azArg[0] = "table";
143977 azArg[5] = 0;
143983 initData.nInitRow = 0;
143984 initData.mxPage = 0;
143985 sqlite3InitCallback(&initData, 5, (char **)azArg, 0);
143995 if( pDb->pBt==0 ){
144007 rc = sqlite3BtreeBeginTrans(pDb->pBt, 0, 0);
144018 ** meta[0] Schema cookie. Changes with each schema change.
144032 for(i=0; i<ArraySize(meta); i++){
144035 if( (db->flags & SQLITE_ResetDatabase)!=0 ){
144036 memset(meta, 0, sizeof(meta));
144046 if( iDb==0 && (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){
144051 if( encoding==0 ) encoding = SQLITE_UTF8;
144068 if( pDb->pSchema->cache_size==0 ){
144071 if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; }
144080 ** file_format==1 Version 3.0.0.
144083 ** file_format==4 Version 3.3.0. // DESC indices. Boolean constants
144086 if( pDb->pSchema->file_format==0 ){
144100 if( iDb==0 && meta[BTREE_FILE_FORMAT-1]>=4 ){
144117 db->xAuth = 0;
144119 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
144170 db->init.busy = 0;
144188 assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
144189 assert( db->init.busy==0 );
144191 assert( db->nDb>0 );
144193 if( !DbHasProperty(db, 0, DB_SchemaLoaded) ){
144194 rc = sqlite3InitOne(db, 0, pzErrMsg, 0);
144198 for(i=db->nDb-1; i>0; i--){
144201 rc = sqlite3InitOne(db, i, pzErrMsg, 0);
144245 for(iDb=0; iDb<db->nDb; iDb++){
144246 int openedTransaction = 0; /* True if a transaction is opened */
144248 if( pBt==0 ) continue;
144254 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
144267 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
144303 for(i=0; 1; i++){
144309 assert( i>=0 && i<db->nDb );
144319 assert( db!=0 );
144321 assert( pParse->nested==0 );
144337 db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
144377 pCleanup = 0;
144389 pPtr = 0;
144407 memset(PARSE_HDR(pParse), 0, PARSE_HDR_SZ);
144408 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
144441 memset(PARSE_HDR(&sParse), 0, PARSE_HDR_SZ);
144442 memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ);
144450 assert( sParse.pReprepare==0 );
144452 assert( ppStmt && *ppStmt==0 );
144467 sParse.prepFlags = prepFlags & 0xff;
144493 for(i=0; i<db->nDb; i++) {
144512 if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
144533 assert( 0==sParse.nQueryLoop );
144539 if( db->init.busy==0 ){
144544 sParse.checkSchema = 0;
144547 if( sParse.checkSchema && db->init.busy==0 ){
144553 assert( 0==(*ppStmt) );
144562 assert( sParse.zErrMsg==0 );
144591 int cnt = 0;
144594 if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
144596 *ppStmt = 0;
144597 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
144607 assert( rc==SQLITE_OK || *ppStmt==0 );
144610 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
144614 db->busyHandler.nBusy = 0;
144616 assert( rc==SQLITE_OK || (*ppStmt)==0 );
144638 assert( zSql!=0 ); /* Reprepare only called for prepare_v2() statements */
144642 rc = sqlite3LockAndPrepare(db, zSql, -1, prepFlags, p, &pNew, 0);
144647 assert( pNew==0 );
144650 assert( pNew!=0 );
144676 rc = sqlite3LockAndPrepare(db,zSql,nBytes,0,0,ppStmt,pzTail);
144677 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
144692 ** Proof in that the 5th parameter to sqlite3LockAndPrepare is 0 */
144693 rc = sqlite3LockAndPrepare(db,zSql,nBytes,SQLITE_PREPARE_SAVESQL,0,
144695 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 );
144716 0,ppStmt,pzTail);
144717 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 );
144739 const char *zTail8 = 0;
144743 if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
144745 *ppStmt = 0;
144746 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
144755 if( nBytes>=0 ){
144758 for(sz=0; sz<nBytes && (z[sz]!=0 || z[sz+1]!=0); sz += 2){}
144763 for(sz=0; z[sz]!=0 || z[sz+1]!=0; sz += 2){}
144770 rc = sqlite3LockAndPrepare(db, zSql8, -1, prepFlags, 0, ppStmt, &zTail8);
144804 rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
144805 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
144817 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
144832 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
144863 u8 isTnct; /* 0: Not distinct. 1: DISTICT 2: DISTINCT and ORDER BY */
144912 #define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
144919 ** If bFree==0, Leave the first Select object unfreed
144922 assert( db!=0 );
144954 pDest->iSDParm2 = 0;
144955 pDest->zAffSdst = 0;
144956 pDest->iSdst = 0;
144957 pDest->nSdst = 0;
144979 if( pNew==0 ){
144983 if( pEList==0 ){
144984 pEList = sqlite3ExprListAppend(pParse, 0,
144985 sqlite3Expr(pParse->db,TK_ASTERISK,0));
144990 pNew->iLimit = 0;
144991 pNew->iOffset = 0;
144993 pNew->addrOpenEphm[0] = -1;
144995 pNew->nSelectRow = 0;
144996 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(pParse->db, SZ_SRCLIST_1);
145002 pNew->pPrior = 0;
145003 pNew->pNext = 0;
145005 pNew->pWith = 0;
145007 pNew->pWin = 0;
145008 pNew->pWinDefn = 0;
145012 pAllocated = 0;
145014 assert( pNew->pSrc!=0 || pParse->nErr>0 );
145102 int jointype = 0;
145112 /* (0) natural */ { 0, 7, JT_NATURAL },
145121 apAll[0] = pA;
145124 for(i=0; i<3 && apAll[i]; i++){
145126 for(j=0; j<ArraySize(aKeyword); j++){
145128 && sqlite3StrNICmp((char*)p->z, &zKeyText[aKeyword[j].i], p->n)==0 ){
145133 testcase( j==0 || j==1 || j==2 || j==3 || j==4 || j==5 || j==6 );
145141 (jointype & JT_ERROR)!=0 ||
145146 if( pB==0 ){ zSp1++; }
145147 if( pC==0 ){ zSp2++; }
145173 && sqlite3StrICmp(aCol[i].zCnName, zCol)==0
145179 i = 0;
145182 && sqlite3StrICmp(aCol[i].zCnName, zCol)==0
145196 assert( pItem!=0 );
145201 assert( pItem->u4.pSubq!=0 );
145202 assert( pItem->u4.pSubq->pSelect!=0 );
145204 assert( pResults!=0 );
145205 assert( iCol>=0 && iCol<pResults->nExpr );
145233 assert( iStart>=0 );
145234 assert( (piTab==0)==(piCol==0) ); /* Both or neither are NULL */
145238 if( iCol>=0
145239 && (bIgnoreHidden==0 || IsHiddenColumn(&pSrc->a[i].pSTab->aCol[iCol])==0)
145249 return 0;
145289 for(i=0; i<p->x.pList->nExpr; i++){
145304 ** an ordinary term that omits the EP_OuterON mark. Or if iTable<0, then
145315 if( iTable<0 || (ExprHasProperty(p, EP_OuterON) && p->w.iJoin==iTable) ){
145317 if( iTable>=0 ) ExprSetProperty(p, EP_InnerON);
145324 assert( p->pLeft==0 );
145327 for(i=0; i<p->x.pList->nExpr; i++){
145353 ** entries 0 and 1. Any ON or USING clauses associated with the join are
145365 pLeft = &pSrc->a[0];
145367 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
145371 if( NEVER(pLeft->pSTab==0 || pRightTab==0) ) continue;
145372 joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_OuterON : EP_InnerON;
145378 IdList *pUsing = 0;
145381 "an ON or USING clause", 0);
145384 for(j=0; j<pRightTab->nCol; j++){
145389 if( tableAndColumnIndex(pSrc, 0, i, zName, 0, 0, 1) ){
145390 pUsing = sqlite3IdListAppend(pParse, pUsing, 0);
145392 assert( pUsing->nId>0 );
145393 assert( pUsing->a[pUsing->nId-1].zName==0 );
145416 assert( pList!=0 );
145417 for(j=0; j<pList->nId; j++){
145428 if( iRightCol<0
145429 || tableAndColumnIndex(pSrc, 0, i, zName, &iLeft, &iLeftCol,
145430 pRight->fg.isSynthUsing)==0
145438 if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 && pParse->nErr==0 ){
145452 ExprList *pFuncArgs = 0; /* Arguments to the coalesce() */
145454 assert( pE1!=0 );
145457 pRight->fg.isSynthUsing)!=0 ){
145458 if( pSrc->a[iLeft].fg.isUsing==0
145459 || sqlite3IdListIndex(pSrc->a[iLeft].u3.pUsing, zName)<0
145471 pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0);
145476 }else if( (pSrc->a[i+1].fg.jointype & JT_LEFT)!=0 && pParse->nErr==0 ){
145477 assert( pE1!=0 );
145483 assert( pE2!=0 || pEq==0 );
145500 pRight->u3.pOn = 0;
145504 return 0;
145531 0, pInfo->ecelFlags);
145534 sqlite3ExprCodeExprList(pParse, pInfo->pExtra, pInfo->regExtraResult, 0, 0);
145577 int bSeq = ((pSort->sortFlags & SORTFLAG_UseSorter)==0);
145581 int regRecord = 0; /* Assembled sorter record */
145585 int iSkip = 0; /* End of the sorter insert loop */
145587 assert( bSeq==0 || bSeq==1 );
145599 ** regOrigData is 0 to prevent this routine from trying to copy
145602 assert( nData==1 || regData==regOrigData || regOrigData==0 );
145615 assert( pSelect->iOffset==0 || pSelect->iLimit!=0 );
145619 SQLITE_ECEL_DUP | (regOrigData? SQLITE_ECEL_REF : 0));
145623 if( nPrefixReg==0 && nData>0 ){
145626 if( nOBSat>0 ){
145649 memset(pKI->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */
145654 pOp = 0; /* Ensure pOp not used after sqlite3VdbeAddOp3() */
145656 sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
145688 sqlite3VdbeAddOp2(v, OP_Last, iCsr, 0);
145690 iCsr, 0, regBase+nOBSat, nExpr-nOBSat);
145694 if( regRecord==0 ){
145721 if( iOffset>0 ){
145778 int iRet = 0;
145793 for(i=0; i<nResultCol; i++){
145860 if( pParse->nErr==0
145913 int nDefer = 0;
145914 ExprList *pExtra = 0;
145915 for(i=0; i<pEList->nExpr; i++){
145917 if( pItem->u.x.iOrderByCol==0 ){
145921 && pExpr->iColumn>=0
145923 && (pTab = pExpr->y.pTab)!=0
145925 && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)!=0
145928 for(j=0; j<nDefer; j++){
145937 Index *pPk = 0;
145942 for(k=0; k<nKey; k++){
145943 Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0);
145992 int nPrefixReg = 0; /* Number of extra registers before regResult */
146001 int regOrig; /* Start of memory holding full result (or 0) */
146004 assert( p->pEList!=0 );
146006 if( pSort && pSort->pOrderBy==0 ) pSort = 0;
146007 if( pSort==0 && !hasDistinct ){
146008 assert( iContinue!=0 );
146016 if( pDest->iSdst==0 ){
146034 if( srcTab>=0 ){
146035 for(i=0; i<nResultCol; i++){
146041 ExprList *pExtra = 0;
146051 ecelFlags = 0;
146053 if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab && eDest!=SRT_Table ){
146064 if( (j = pSort->pOrderBy->a[i].u.x.iOrderByCol)>0 ){
146070 if( pExtra && pParse->db->mallocFailed==0 ){
146086 for(i=0; i<pEList->nExpr; i++){
146087 if( pEList->a[i].u.x.iOrderByCol>0
146093 regOrig = 0;
146114 && (ecelFlags & SQLITE_ECEL_OMITREF)!=0
146115 && nPrefixReg>0
146117 assert( pSort!=0 );
146118 assert( hasDistinct==0 );
146120 regOrig = 0;
146136 if( pSort==0 ){
146195 sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
146198 assert( pSort==0 );
146229 regResult+(i2<0), nResultCol-(i2<0), r1);
146230 if( i2<0 ){
146252 pDest->iSDParm2 = 0; /* Signal that any Bloom filter is unpopulated */
146260 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
146262 ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
146322 int addrTest = 0;
146334 addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0,
146343 for(i=0; i<nKey; i++){
146377 if( pSort==0 && p->iLimit ){
146388 KeyInfo *p = sqlite3DbMallocRawNN(db, SZ_KEYINFO(0) + nExtra);
146396 memset(p->aColl, 0, nExtra);
146408 assert( p->db!=0 );
146409 assert( p->nRef>0 );
146411 if( p->nRef==0 ) sqlite3DbNNFreeNN(p->db, p);
146420 assert( p->nRef>0 );
146500 ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s", zUsage));
146536 int addrOnce = 0;
146548 int nRefKey = 0;
146555 if( pSort->nOBSat==0 || nKey==1 ){
146556 ExplainQueryPlan2(addrExplain, (pParse, 0,
146560 ExplainQueryPlan2(addrExplain, (pParse, 0,
146568 assert( addrBreak<0 );
146577 for(i=0; i<pSort->nDefer; i++){
146588 sqlite3VdbeAddOp2(v, OP_Null, 0, pDest->iSdst);
146590 regRowid = 0;
146596 nColumn = 0;
146612 assert( p->iLimit==0 && p->iOffset==0 );
146614 bSeq = 0;
146620 if( p->iOffset>0 ){
146624 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
146628 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
146635 for(i=0; i<pSort->nDefer; i++){
146649 for(k=0; k<nKey; k++){
146661 for(i=nColumn-1; i>=0; i--){
146704 sqlite3VdbeAddOp3(v, OP_MakeRecord,regRow+(i2<0),nColumn-(i2<0),r1);
146705 if( i2<0 ){
146782 char const *zType = 0;
146785 char const *zOrigDb = 0;
146786 char const *zOrigTab = 0;
146787 char const *zOrigCol = 0;
146790 assert( pExpr!=0 );
146791 assert( pNC->pSrcList!=0 );
146798 Table *pTab = 0; /* Table structure column is extracted from */
146799 Select *pS = 0; /* Select the column is extracted from */
146803 for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
146809 pS = 0;
146816 if( pTab==0 ){
146844 && (!ViewCanHaveRowid || iCol>=0)
146861 if( iCol<0 ) iCol = pTab->iPKey;
146862 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
146863 if( iCol<0 ){
146868 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
146876 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
146877 if( iCol<0 ){
146880 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
146897 p = pS->pEList->a[0].pExpr;
146933 sNC.pNext = 0;
146934 for(i=0; i<pEList->nExpr; i++){
146938 const char *zOrigDb = 0;
146939 const char *zOrigTab = 0;
146940 const char *zOrigCol = 0;
146951 zType = columnType(&sNC, p, 0, 0, 0);
147005 TREETRACE(0x80,pParse,pSelect,("generating column names\n"));
147008 assert( v!=0 );
147009 assert( pTabList!=0 );
147011 fullName = (db->flags & SQLITE_FullColNames)!=0;
147012 srcName = (db->flags & SQLITE_ShortColNames)!=0 || fullName;
147014 for(i=0; i<pEList->nExpr; i++){
147017 assert( p!=0 );
147020 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
147029 assert( pTab!=0 );
147030 if( iCol<0 ) iCol = pTab->iPKey;
147031 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
147032 if( iCol<0 ){
147038 char *zName = 0;
147046 z = z==0 ? sqlite3MPrintf(db, "column%d", i+1) : sqlite3DbStrDup(db, z);
147064 ** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
147094 aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
147095 testcase( aCol==0 );
147098 nCol = 0;
147099 aCol = 0;
147105 for(i=0, pCol=aCol; i<nCol && !pParse->nErr; i++, pCol++){
147110 if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
147114 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
147116 assert( pColExpr!=0 );
147120 && ALWAYS( pColExpr->y.pTab!=0 )
147125 if( iCol<0 ) iCol = pTab->iPKey;
147126 zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
147144 cnt = 0;
147145 while( zName && (pCollide = sqlite3HashFind(&ht, zName))!=0 ){
147150 if( nName>0 ){
147151 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
147165 sqlite3ColumnPropertiesFromName(0, pCol);
147172 for(j=0; j<i; j++){
147176 *paCol = 0;
147177 *pnCol = 0;
147208 assert( pSelect!=0 );
147209 assert( (pSelect->selFlags & SF_Resolved)!=0 );
147210 assert( pTab->nCol==pSelect->pEList->nExpr || pParse->nErr>0 );
147215 memset(&sNC, 0, sizeof(sNC));
147217 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
147220 int m = 0;
147226 while( pCol->affinity<=SQLITE_AFF_NONE && pS2->pNext!=0 ){
147238 if( pCol->affinity==SQLITE_AFF_TEXT && (m&0x01)!=0 ){
147241 if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
147248 zType = columnType(&sNC, p, 0, 0, 0);
147249 if( zType==0 || pCol->affinity!=sqlite3AffinityType(zType, 0) ){
147255 zType = 0;
147276 assert( pTab->pIndex==0 );
147295 sqlite3SelectPrep(pParse, pSelect, 0);
147297 if( pParse->nErr ) return 0;
147300 if( pTab==0 ){
147301 return 0;
147304 pTab->zName = 0;
147311 return 0;
147324 if( pParse->pToplevel==0
147351 ** Only if pLimit->pLeft!=0 do the limit registers get
147357 Vdbe *v = 0;
147358 int iLimit = 0;
147368 ** The current implementation interprets "LIMIT 0" to mean
147373 assert( pLimit->pLeft!=0 );
147376 assert( v!=0 );
147380 if( n==0 ){
147382 }else if( n>=0 && p->nSelectRow>sqlite3LogEst((u64)n) ){
147418 pRet = 0;
147420 assert( iCol>=0 );
147424 if( pRet==0 && ALWAYS(iCol<p->pEList->nExpr) ){
147441 int nOrderBy = ALWAYS(pOrderBy!=0) ? pOrderBy->nExpr : 0;
147446 for(i=0; i<nOrderBy; i++){
147455 if( pColl==0 ) pColl = db->pDfltColl;
147517 int iCurrent = 0; /* The Current table */
147520 int iDistinct = 0; /* To ensure unique results if UNION */
147537 if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
147546 p->pLimit = 0;
147547 p->iLimit = p->iOffset = 0;
147551 for(i=0; ALWAYS(i<pSrc->nSrc); i++){
147575 sqlite3VdbeAddOp4(v, OP_OpenEphemeral, iQueue, pOrderBy->nExpr+2, 0,
147583 p->addrOpenEphm[0] = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iDistinct, 0);
147588 p->pOrderBy = 0;
147597 for(pFirstRec=p; ALWAYS(pFirstRec!=0); pFirstRec=pFirstRec->pPrior){
147603 if( (pFirstRec->pPrior->selFlags & SF_Recursive)==0 ) break;
147608 pSetup->pNext = 0;
147630 0, 0, pDest, addrCont, addrBreak);
147640 pFirstRec->pPrior = 0;
147643 assert( pFirstRec->pPrior==0 );
147687 int rc = 0;
147688 int bShowAll = p->pLimit==0;
147692 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
147693 assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
147697 if( p->pPrior==0 ) break;
147702 ExplainQueryPlan((pParse, 0, "SCAN %d CONSTANT ROW%s", nRow,
147705 selectInnerLoop(pParse, p, -1, 0, 0, pDest, 1, 1);
147719 while( p && (p->selFlags & SF_Recursive)!=0 ){ p = p->pPrior; }
147720 return p!=0;
147763 Select *pDelete = 0; /* Chain of simple selects to delete */
147770 assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
147775 assert( pPrior->pOrderBy==0 );
147776 assert( pPrior->pLimit==0 );
147779 assert( v!=0 ); /* The VDBE already created by calling function */
147793 if( rc>=0 ) goto multi_select_end;
147804 if( (p->selFlags & SF_Recursive)!=0 && hasAnchor(p) ){
147816 if( pPrior->pPrior==0 ){
147826 int addr = 0;
147827 int nLimit = 0; /* Initialize to suppress harmless compiler warning */
147832 TREETRACE(0x200, pParse, p, ("multiSelect UNION ALL left...\n"));
147834 pPrior->pLimit = 0;
147838 p->pPrior = 0;
147850 TREETRACE(0x200, pParse, p, ("multiSelect UNION ALL right...\n"));
147858 && nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit)
147870 u8 op = 0; /* One of the SRT_ operations to apply to self */
147883 assert( p->pLimit==0 ); /* Not allowed on leftward elements */
147890 assert( p->pOrderBy==0 );
147891 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, unionTab, 0);
147892 assert( p->addrOpenEphm[0] == -1 );
147893 p->addrOpenEphm[0] = addr;
147903 TREETRACE(0x200, pParse, p, ("multiSelect EXCEPT/UNION left...\n"));
147917 p->pPrior = 0;
147919 p->pLimit = 0;
147923 TREETRACE(0x200, pParse, p, ("multiSelect EXCEPT/UNION right...\n"));
147926 assert( p->pOrderBy==0 );
147929 p->pOrderBy = 0;
147935 p->iLimit = 0;
147936 p->iOffset = 0;
147943 if( dest.eDest!=priorOp && db->mallocFailed==0 ){
147951 0, 0, &dest, iCont, iBreak);
147955 sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
147973 assert( p->pOrderBy==0 );
147975 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0);
147976 assert( p->addrOpenEphm[0] == -1 );
147977 p->addrOpenEphm[0] = addr;
147984 TREETRACE(0x400, pParse, p, ("multiSelect INTERSECT left...\n"));
147992 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab2, 0);
147995 p->pPrior = 0;
147997 p->pLimit = 0;
148001 TREETRACE(0x400, pParse, p, ("multiSelect INTERSECT right...\n"));
148023 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
148027 0, 0, &dest, iCont, iBreak);
148031 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
148032 sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
148038 if( p->pNext==0 ){
148061 assert( p->pNext==0 );
148062 assert( p->pEList!=0 );
148069 for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
148071 if( 0==*apColl ){
148077 for(i=0; i<2; i++){
148079 if( addr<0 ){
148080 /* If [0] is unused then [1] is also unused. So we can
148082 assert( pLoop->addrOpenEphm[1]<0 );
148130 ** If regPrev>0 then it is the first register in a vector that
148132 ** if there has been no previous output. If regPrev>0 then code is
148145 int regPrev, /* Previous result register. No uniqueness if 0 */
148168 if( pParse->db->mallocFailed ) return 0;
148202 if( pDest->iSDParm2>0 ){
148203 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
148205 ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
148228 if( pDest->iSdst==0 ){
148371 int addrOutB = 0; /* Address of the output-B subroutine */
148387 KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */
148394 assert( p->pOrderBy!=0 );
148395 assert( pKeyDup==0 ); /* "Managed" code needs this. Ticket #3382. */
148398 assert( v!=0 ); /* Already thrown the error if VDBE alloc failed */
148406 assert( p->pPrior->pOrderBy==0 );
148416 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
148418 for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){
148419 assert( pItem!=0 );
148420 assert( pItem->u.x.iOrderByCol>0 );
148424 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
148425 if( pNew==0 ) return SQLITE_NOMEM_BKPT;
148444 aPermute[0] = nOrderBy;
148446 assert( pItem!=0 );
148447 assert( pItem->u.x.iOrderByCol>0 );
148453 pKeyMerge = 0;
148461 regPrev = 0;
148467 sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
148471 for(i=0; i<nExpr; i++){
148473 pKeyDup->aSortFlags[i] = 0;
148484 for(pSplit=p; pSplit->pPrior!=0 && pSplit->op==op; pSplit=pSplit->pPrior){
148496 assert( pPrior!=0 );
148497 pSplit->pPrior = 0;
148498 pPrior->pNext = 0;
148500 assert( pOrderBy!=0 || db->mallocFailed );
148501 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
148514 regLimitA = regLimitB = 0;
148517 p->pLimit = 0;
148532 addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrA, 0, addrSelectA);
148544 addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrB, 0, addrSelectB);
148549 p->iOffset = 0;
148642 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
148660 pPrior->pOrderBy = 0;
148665 return pParse->nErr!=0;
148735 if( pExpr==0 ) return 0;
148747 if( pExpr->iColumn<0 ){
148757 assert( iColumn>=0 );
148758 assert( pSubst->pEList!=0 && iColumn<pSubst->pEList->nExpr );
148759 assert( pExpr->pRight==0 );
148768 memset(&ifNullRow, 0, sizeof(ifNullRow));
148777 pNew = sqlite3ExprDup(db, pCopy, 0);
148840 if( pList==0 ) return;
148841 for(i=0; i<pList->nExpr; i++){
148861 assert( pSrc!=0 );
148862 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
148870 }while( doPrior && (p = p->pPrior)!=0 );
148887 if( pExpr->iColumn<0 ) return WRC_Continue;
148896 if( NEVER(pSrcItem->pSTab==0) ) return;
148897 memset(&w, 0, sizeof(w));
148901 pSrcItem->colUsed = 0;
148915 ** existing cursor numbers in pSrc. aCsrMap[0] is the array size.
148928 for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
148931 assert( pItem->iCursor < aCsrMap[0] );
148932 if( !pItem->fg.isRecursive || aCsrMap[pItem->iCursor+1]==0 ){
148951 if( iCsr < aCsrMap[0] && aCsrMap[iCsr+1]>0 ){
148997 memset(&w, 0, sizeof(w));
149024 assert( p!=0 );
149025 assert( p->pEList!=0 );
149026 assert( p->pPrior!=0 );
149028 for(ii=0; ii<pList->nExpr; ii++){
149031 assert( pList->a[ii].pExpr!=0 );
149034 assert( pSub1->pEList!=0 );
149036 assert( pSub1->pEList->a[ii].pExpr!=0 );
149042 return 0;
149048 ** This routine returns 1 if it makes changes and 0 if no flattening occurs.
149213 ** If flattening is not attempted, this routine is a no-op and returns 0.
149233 int isOuterJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
149239 int *aCsrMap = 0;
149241 /* Check to see if flattening is permitted. Return 0 if not.
149243 assert( p!=0 );
149244 assert( p->pPrior==0 );
149245 if( OptimizationDisabled(db, SQLITE_QueryFlattener) ) return 0;
149247 assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
149252 assert( pSub!=0 );
149255 if( p->pWin || pSub->pWin ) return 0; /* Restriction (25) */
149265 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
149266 if( pSub->pLimit && pSub->pLimit->pRight ) return 0; /* Restriction (14) */
149267 if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){
149268 return 0; /* Restriction (15) */
149270 if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
149271 if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (4) */
149273 return 0; /* Restrictions (8)(9) */
149276 return 0; /* Restriction (11) */
149278 if( isAgg && pSub->pOrderBy ) return 0; /* Restriction (16) */
149279 if( pSub->pLimit && p->pWhere ) return 0; /* Restriction (19) */
149280 if( pSub->pLimit && (p->selFlags & SF_Distinct)!=0 ){
149281 return 0; /* Restriction (21) */
149284 return 0; /* Restrictions (22) */
149302 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
149304 /**** || IsVirtual(pSubSrc->a[0].pSTab) (3b)-omitted */
149305 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
149306 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
149308 return 0;
149313 assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
149314 if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
149315 return 0; /* Restriction (27a) */
149329 return 0; /* Restriction (20) */
149331 if( isAgg || (p->selFlags & SF_Distinct)!=0 || isOuterJoin>0 ){
149332 return 0; /* (17d1), (17d2), or (17f) */
149337 assert( pSub->pSrc!=0 );
149338 assert( (pSub->selFlags & SF_Recursive)==0 );
149340 if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 /* (17b) */
149347 return 0;
149349 if( iFrom>0 && (pSub1->pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
149353 return 0; /* Restrictions (17g), (27b) */
149360 for(ii=0; ii<p->pOrderBy->nExpr; ii++){
149361 if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
149366 if( (p->selFlags & SF_Recursive) ) return 0;
149369 if( compoundHasDifferentAffinities(pSub) ) return 0;
149372 if( pParse->nSelect>500 ) return 0;
149373 if( OptimizationDisabled(db, SQLITE_FlttnUnionAll) ) return 0;
149375 if( aCsrMap ) aCsrMap[0] = pParse->nTab;
149380 TREETRACE(0x4,pParse,p,("flatten %u.%p from term %d\n",
149385 TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
149394 pSub1 = 0;
149396 assert( pSubitem->fg.isSubquery==0 );
149397 assert( pSubitem->fg.fixedSchema==0 );
149400 pSubitem->zName = 0;
149401 pSubitem->zAlias = 0;
149402 assert( pSubitem->fg.isUsing!=0 || pSubitem->u3.pOn==0 );
149443 pSubitem->pSTab = 0;
149444 p->pOrderBy = 0;
149445 p->pPrior = 0;
149446 p->pLimit = 0;
149447 pNew = sqlite3SelectDup(db, p, 0);
149452 if( pNew==0 ){
149456 if( aCsrMap && ALWAYS(db->mallocFailed==0) ){
149463 TREETRACE(0x4,pParse,p,("compound-subquery flattener"
149466 assert( pSubitem->fg.isSubquery==0 );
149470 assert( pSubitem->fg.fixedSchema==0 );
149471 assert( pSubitem->fg.isSubquery==0 );
149472 assert( pSubitem->u4.zDatabase==0 );
149473 sqlite3SrcItemAttachSubquery(pParse, pSubitem, pSub1, 0);
149484 if( ALWAYS(pSubitem->pSTab!=0) ){
149493 pSubitem->pSTab = 0;
149512 u8 jointype = 0;
149514 assert( pSub!=0 );
149540 if( pSrc==0 ) break;
149547 iNewParent = pSubSrc->a[0].iCursor;
149548 for(i=0; i<nSubSrc; i++){
149550 assert( pItem->fg.isTabFunc==0 );
149553 || pItem->u4.zDatabase==0 );
149557 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
149574 if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){
149586 for(i=0; i<pOrderBy->nExpr; i++){
149587 pOrderBy->a[i].u.x.iOrderByCol = 0;
149589 assert( pParent->pOrderBy==0 );
149591 pSub->pOrderBy = 0;
149594 pSub->pWhere = 0;
149595 if( isOuterJoin>0 ){
149606 if( db->mallocFailed==0 ){
149614 substSelect(&x, pParent, 0);
149620 assert( (pSub->selFlags & SF_Distinct)==0 ); /* restriction (17b) */
149630 pSub->pLimit = 0;
149635 for(i=0; i<nSubSrc; i++){
149647 if( sqlite3TreeTrace & 0x4 ){
149648 TREETRACE(0x4,pParse,p,("After flattening:\n"));
149649 sqlite3TreeViewSelect(0, p, 0);
149692 if( sqlite3ExprAffinity(pValue)!=0 ) return;
149699 for(i=0; i<pConst->nConst; i++){
149716 if( pConst->apExpr==0 ){
149717 pConst->nConst = 0;
149732 if( NEVER(pExpr==0) ) return;
149746 assert( pRight!=0 );
149747 assert( pLeft!=0 );
149771 if( pConst->pOomFault[0] ) return WRC_Prune;
149779 for(i=0; i<pConst->nConst; i++){
149792 assert( pExpr->pLeft==0 );
149793 pExpr->pLeft = sqlite3ExprDup(pConst->pParse->db, pConst->apExpr[i*2+1], 0);
149826 propagateConstantExprRewriteOne(pConst, pExpr->pLeft, 0);
149827 if( pConst->pOomFault[0] ) return WRC_Prune;
149829 propagateConstantExprRewriteOne(pConst, pExpr->pRight, 0);
149893 int nChng = 0;
149897 x.nConst = 0;
149898 x.nChng = 0;
149899 x.apExpr = 0;
149900 x.bHasAffBlob = 0;
149901 if( ALWAYS(p->pSrc!=0)
149902 && p->pSrc->nSrc>0
149903 && (p->pSrc->a[0].fg.jointype & JT_LTORJ)!=0
149914 memset(&w, 0, sizeof(w));
149918 w.xSelectCallback2 = 0;
149919 w.walkerDepth = 0;
149935 ** if it is safe and the expression should be pushed down, or 0
149951 assert( (pSubq->selFlags & SF_MultiPart)==0 );
149952 assert( pSubq->pPrior==0 );
150064 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
150076 int nChng = 0;
150078 if( pWhere==0 ) return 0;
150080 return 0; /* restrictions (2) and (11) */
150083 return 0; /* restrictions (10) */
150088 int notUnionAll = 0;
150097 if( pSel->pWin ) return 0; /* restriction (6b) */
150107 assert( pList!=0 );
150108 for(ii=0; ii<pList->nExpr; ii++){
150111 return 0; /* Restriction (8) */
150118 if( pSubq->pWin && pSubq->pWin->pPartition==0 ) return 0;
150130 assert( (pX->selFlags & (SF_Recursive))==0 );
150135 if( pSubq->pLimit!=0 ){
150136 return 0; /* restriction (3) */
150143 #if 0 /* These checks now done by sqlite3ExprIsSingleTableConstraint() */
150145 && (pSrcList->a[0].fg.jointype & JT_LTORJ)!=0 /* Fast pre-test of (9c) */
150148 for(jj=0; jj<iSrc; jj++){
150154 if( (pSrcList->a[jj].fg.jointype & JT_RIGHT)!=0 ){
150155 return 0; /* restriction (9) */
150162 && (ExprHasProperty(pWhere,EP_OuterON)==0
150165 return 0; /* restriction (4) */
150170 return 0; /* restriction (5) */
150179 && pLeft->iColumn < 0
150181 return 0; /* Restriction (12) */
150191 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
150196 x.isOuterJoin = 0;
150201 if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
150233 int nChng = 0; /* Number of columns converted to NULL */
150236 assert( pItem!=0 );
150238 return 0;
150240 assert( pItem->pSTab!=0 );
150246 if( (pX->selFlags & (SF_Distinct|SF_Aggregate))!=0 ){
150249 return 0;
150254 return 0;
150260 return 0;
150267 for(j=0; j<pList->nExpr; j++){
150269 if( iCol>0 ){
150276 for(j=0; j<nCol; j++){
150278 if( (m & colUsed)!=0 ) continue;
150313 u8 sortFlags = 0;
150315 assert( *ppMinMax==0 );
150320 if( pEList==0
150329 if( sqlite3StrICmp(zFunc, "min")==0 ){
150331 if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){
150334 }else if( sqlite3StrICmp(zFunc, "max")==0 ){
150340 *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
150341 assert( pOrderBy!=0 || db->mallocFailed );
150342 if( pOrderBy ) pOrderBy->a[0].fg.sortFlags = sortFlags;
150372 || p->pSrc->a[0].fg.isSubquery
150376 return 0;
150378 pTab = p->pSrc->a[0].pSTab;
150379 assert( pTab!=0 );
150381 if( !IsOrdinaryTable(pTab) ) return 0;
150382 pExpr = p->pEList->a[0].pExpr;
150383 assert( pExpr!=0 );
150384 if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
150385 if( pExpr->pAggInfo!=pAggInfo ) return 0;
150386 if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0;
150387 assert( pAggInfo->aFunc[0].pFExpr==pExpr );
150390 if( ExprHasProperty(pExpr, EP_Distinct|EP_WinFunc) ) return 0;
150406 assert( pTab!=0 );
150407 assert( pFrom->fg.isIndexedBy!=0 );
150414 sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
150418 assert( pFrom->fg.isCte==0 );
150454 if( p->pPrior==0 ) return WRC_Continue;
150455 if( p->pOrderBy==0 ) return WRC_Continue;
150457 if( pX==0 ) return WRC_Continue;
150465 if( a[0].u.x.iOrderByCol ) return WRC_Continue;
150467 for(i=p->pOrderBy->nExpr-1; i>=0; i--){
150470 if( i<0 ) return WRC_Continue;
150477 if( pNew==0 ) return WRC_Abort;
150478 memset(&dummy, 0, sizeof(dummy));
150479 pNewSrc = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&dummy,pNew,0);
150480 assert( pNewSrc!=0 || pParse->nErr );
150487 p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ASTERISK, 0));
150489 p->pWhere = 0;
150490 pNew->pGroupBy = 0;
150491 pNew->pHaving = 0;
150492 pNew->pOrderBy = 0;
150493 p->pPrior = 0;
150494 p->pNext = 0;
150495 p->pWith = 0;
150497 p->pWinDefn = 0;
150500 assert( (p->selFlags & SF_Converted)==0 );
150502 assert( pNew->pPrior!=0 );
150504 pNew->pLimit = 0;
150518 return 0;
150539 assert( pItem->fg.fixedSchema || pItem->u4.zDatabase==0 );
150540 assert( zName!=0 );
150543 for(i=0; i<p->nCte; i++){
150544 if( sqlite3StrICmp(zName, p->a[i].zName)==0 ){
150551 return 0;
150561 ** bFree==0, the With object will be freed along with the SELECT
150576 if( pWith==0 ) return 0;
150578 if( pParse->nErr==0 ){
150597 ** Return 0 if no match is found.
150609 assert( pFrom->pSTab==0 );
150610 if( pParse->pWith==0 ){
150612 return 0;
150617 return 0;
150619 assert( pFrom->fg.hadSchema==0 || pFrom->fg.notCte!=0 );
150620 if( pFrom->fg.fixedSchema==0 && pFrom->u4.zDatabase!=0 ){
150623 return 0;
150631 return 0;
150656 assert( pFrom->pSTab==0 );
150658 if( pTab==0 ) return 2;
150660 if( pCteUse==0 ){
150661 pCte->pUse = pCteUse = sqlite3DbMallocZero(db, sizeof(pCteUse[0]));
150662 if( pCteUse==0
150663 || sqlite3ParserAddCleanup(pParse,sqlite3DbFree,pCteUse)==0
150680 assert( pSel!=0 );
150697 assert( pRecTerm->pPrior!=0 );
150698 for(i=0; i<pSrc->nSrc; i++){
150700 if( pItem->zName!=0
150703 && (pItem->fg.fixedSchema || pItem->u4.zDatabase==0)
150704 && 0==sqlite3StrICmp(pItem->zName, pCte->zName)
150716 if( iRecTab<0 ) iRecTab = pParse->nTab++;
150720 if( (pRecTerm->selFlags & SF_Recursive)==0 ) break;
150729 assert( pRecTerm!=0 );
150730 assert( (pRecTerm->selFlags & SF_Recursive)==0 );
150731 assert( pRecTerm->pNext!=0 );
150732 assert( (pRecTerm->pNext->selFlags & SF_Recursive)!=0 );
150733 assert( pRecTerm->pWith==0 );
150736 pRecTerm->pWith = 0;
150771 pCte->zCteErr = 0;
150775 return 0; /* No match */
150790 if( OK_IF_ALWAYS_TRUE(pParse->pWith) && p->pPrior==0 ){
150792 if( pWith!=0 ){
150812 assert( pFrom->u4.pSubq!=0 );
150816 if( pTab==0 ) return SQLITE_NOMEM;
150853 while( N>0 ){
150856 if( pBase->fg.isUsing==0 ) continue;
150857 if( NEVER(pBase->u3.pUsing==0) ) continue;
150858 if( sqlite3IdListIndex(pBase->u3.pUsing, zName)>=0 ) return 1;
150860 return 0;
150897 u32 elistFlags = 0;
150903 assert( p->pSrc!=0 );
150904 if( (selFlags & SF_Expanded)!=0 ){
150914 if( p->pWith==0 ){
150916 if( p->pWith==0 ){
150922 sqlite3WithPush(pParse, p->pWith, 0);
150933 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
150935 assert( pFrom->fg.isRecursive==0 || pFrom->pSTab!=0 );
150937 assert( pFrom->fg.isRecursive==0 );
150938 if( pFrom->zName==0 ){
150941 assert( pFrom->fg.isSubquery && pFrom->u4.pSubq!=0 );
150944 assert( pSel!=0 );
150945 assert( pFrom->pSTab==0 );
150950 }else if( (rc = resolveFromTermToCte(pParse, pWalker, pFrom))!=0 ){
150953 assert( pTab!=0 );
150957 assert( pFrom->pSTab==0 );
150958 pFrom->pSTab = pTab = sqlite3LocateTableItem(pParse, 0, pFrom);
150959 if( pTab==0 ) return WRC_Abort;
150960 if( pTab->nTabRef>=0xffff ){
150963 pFrom->pSTab = 0;
150975 assert( pFrom->fg.isSubquery==0 );
150977 if( (db->flags & SQLITE_EnableView)==0
150988 && ALWAYS(pTab->u.vtab.p!=0)
150989 && pTab->u.vtab.p->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
151016 assert( db->mallocFailed==0 || pParse->nErr!=0 );
151032 for(k=0; k<pEList->nExpr; k++){
151035 assert( pE->op!=TK_DOT || pE->pRight!=0 );
151036 assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) );
151047 ExprList *pNew = 0;
151049 int longNames = (flags & SQLITE_FullColNames)!=0
151050 && (flags & SQLITE_ShortColNames)==0;
151052 for(k=0; k<pEList->nExpr; k++){
151056 assert( pE->op!=TK_DOT || pRight!=0 );
151066 a[k].zEName = 0;
151068 a[k].pExpr = 0;
151072 int tableSeen = 0; /* Set to 1 when TABLE matches */
151073 char *zTName = 0; /* text of name of TABLE */
151076 assert( (selFlags & SF_NestedFrom)==0 );
151077 assert( pE->pLeft!=0 );
151086 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
151091 const char *zSchemaName = 0; /* Schema name for this data source */
151095 if( (zTabName = pFrom->zAlias)==0 ){
151102 assert( pFrom->u4.pSubq->pSelect!=0 );
151104 assert( pNestedFrom!=0 );
151106 assert( VisibleRowid(pTab)==0 || ViewCanHaveRowid );
151108 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
151111 pNestedFrom = 0;
151113 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
151117 && (selFlags & SF_NestedFrom)!=0
151121 for(ii=0; ii<pUsing->nId; ii++){
151128 assert( pX->zEName==0 );
151135 pUsing = 0;
151139 if( VisibleRowid(pTab) && (selFlags & SF_NestedFrom)!=0 ) nAdd++;
151140 for(j=0; j<nAdd; j++){
151146 if( zName==0 ) continue;
151158 && sqlite3MatchEName(&pNestedFrom->a[j], 0, zTName, 0, 0)==0
151167 if( (p->selFlags & SF_IncludeHidden)==0
151172 if( (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
151173 && zTName==0
151174 && (selFlags & (SF_NestedFrom))==0
151182 if( i>0 && zTName==0 && (selFlags & SF_NestedFrom)==0 ){
151184 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
151193 && ( (pFrom->fg.jointype & JT_LTORJ)==0
151194 || (selFlags & SF_NestedFrom)!=0
151215 if( pNew==0 ){
151219 assert( pX->zEName==0 );
151220 if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
151224 testcase( pX->zEName==0 );
151228 testcase( pX->zEName==0 );
151232 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0)
151233 || (pUsing && sqlite3IdListIndex(pUsing, zName)>=0)
151264 if( (elistFlags & (EP_HasFunc|EP_Subquery))!=0 ){
151269 if( sqlite3TreeTrace & 0x8 ){
151270 TREETRACE(0x8,pParse,p,("After result-set wildcard expansion:\n"));
151271 sqlite3TreeViewSelect(0, p, 0);
151284 assert( 0 );
151306 w.xSelectCallback2 = 0;
151311 w.eCode = 0;
151341 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
151343 assert( pTab!=0 );
151344 if( (pTab->tabFlags & TF_Ephemeral)!=0 && pFrom->fg.isSubquery ){
151390 assert( p!=0 || pParse->db->mallocFailed );
151409 for(ii=0; ii<pAggInfo->nColumn; ii++){
151418 sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0);
151420 for(ii=0; ii<pAggInfo->nFunc; ii++){
151423 sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pFExpr, 0);
151450 assert( pAggInfo!=0 );
151451 assert( pAggInfo->iFirstReg==0 );
151453 for(i=0; i<pAggInfo->nFunc; i++){
151486 assert( pAggInfo->iFirstReg==0 );
151487 assert( pSelect!=0 );
151488 assert( pSelect->pGroupBy!=0 );
151490 if( ALWAYS(pAggInfo->nSortingColumn>0) ){
151493 for(j=0; j<pAggInfo->nColumn; j++){
151501 if( sqlite3TreeTrace & 0x20 ){
151503 TREETRACE(0x20, pParse, pSelect,
151505 sqlite3TreeViewSelect(0, pSelect, 0);
151509 sqlite3TreeViewExpr(0, pIEpr->pExpr, 0);
151526 if( pExpr->pAggInfo==0 ) return WRC_Continue;
151532 assert( pExpr->iAgg>=0 );
151549 memset(&w, 0, sizeof(w));
151551 for(i=0; i<pAggInfo->nFunc; i++){
151575 assert( pAggInfo!=0 );
151576 assert( pAggInfo->iFirstReg==0 );
151594 assert( pAggInfo->iFirstReg>0 );
151596 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
151597 if( nReg==0 ) return;
151599 sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->iFirstReg,
151601 for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
151602 if( pFunc->iDistinct>=0 ){
151605 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
151610 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pE->x.pList,0,0);
151612 pFunc->iDistinct, 0, 0, (char*)pKeyInfo, P4_KEYINFO);
151613 ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s(DISTINCT)",
151617 if( pFunc->iOBTab>=0 ){
151620 int nExtra = 0;
151621 assert( pFunc->pFExpr->pLeft!=0 );
151624 assert( pFunc->pFunc!=0 );
151637 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOBList, 0, nExtra);
151638 if( !pFunc->bOBUnique && pParse->nErr==0 ){
151642 pFunc->iOBTab, pOBList->nExpr+nExtra, 0,
151644 ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s(ORDER BY)",
151658 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
151663 if( pF->iOBTab>=0 ){
151674 assert( pF->pFunc!=0 );
151678 if( pF->bOBPayload==0 ){
151679 nKey = 0;
151681 assert( pF->pFExpr->pLeft!=0 );
151683 assert( pF->pFExpr->pLeft->x.pList!=0 );
151688 for(j=nArg-1; j>=0; j--){
151693 int iBaseCol = nKey + nArg + (pF->bOBPayload==0 && pF->bOBUnique==0);
151694 for(j=nArg-1; j>=0; j--){
151700 sqlite3VdbeAddOp3(v, OP_AggStep, 0, regAgg, AggInfoFuncReg(pAggInfo,i));
151708 pList ? pList->nExpr : 0);
151719 ** registers if register regAcc contains 0. The caller will take care
151737 int regHit = 0;
151738 int addrHitTest = 0;
151742 assert( pAggInfo->iFirstReg>0 );
151745 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
151747 int addrNext = 0;
151749 int regAggSz = 0;
151750 int regDistinct = 0;
151754 assert( pF->pFunc!=0 );
151762 /* If regAcc==0, there there exists some min() or max() function
151765 if( regHit==0 ) regHit = ++pParse->nMem;
151766 /* If this is the first row of the group (regAcc contains 0), clear the
151778 if( pF->iOBTab>=0 ){
151783 assert( pList!=0 );
151785 assert( nArg>0 );
151786 assert( pF->pFExpr->pLeft!=0 );
151790 assert( pOBList!=0 );
151791 assert( pOBList->nExpr>0 );
151805 sqlite3ExprCodeExprList(pParse, pOBList, regAgg, 0, SQLITE_ECEL_DUP);
151813 sqlite3ExprCodeExprList(pParse, pList, regDistinct, 0, SQLITE_ECEL_DUP);
151819 for(kk=0; kk<nArg; kk++, jj++){
151827 sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
151829 nArg = 0;
151830 regAgg = 0;
151832 if( pF->iDistinct>=0 && pList ){
151833 if( addrNext==0 ){
151839 if( pF->iOBTab>=0 ){
151849 CollSeq *pColl = 0;
151852 assert( pList!=0 ); /* pList!=0 if pF->pFunc has NEEDCOLL */
151853 for(j=0, pItem=pList->a; !pColl && j<nArg; j++, pItem++){
151859 if( regHit==0 && pAggInfo->nAccumulator ) regHit = ++pParse->nMem;
151860 sqlite3VdbeAddOp4(v, OP_CollSeq, regHit, 0, 0,
151863 sqlite3VdbeAddOp3(v, OP_AggStep, 0, regAgg, AggInfoFuncReg(pAggInfo,i));
151873 if( regHit==0 && pAggInfo->nAccumulator ){
151879 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
151884 pAggInfo->directMode = 0;
151901 int bCover = (pIdx!=0 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pIdx)));
151902 sqlite3VdbeExplain(pParse, 0, "SCAN %s%s%s",
151935 && ExprAlwaysFalse(pExpr)==0
151936 && pExpr->pAggInfo==0
151970 memset(&sWalker, 0, sizeof(sWalker));
151976 if( sWalker.eCode && (sqlite3TreeTrace & 0x100)!=0 ){
151977 TREETRACE(0x100,pParse,p,("Move HAVING terms into WHERE:\n"));
151978 sqlite3TreeViewSelect(0, p, 0);
151989 ** instance of that view found. If pThis is not a self-join then return 0.
152000 assert( pSel!=0 );
152001 if( pSel->selFlags & SF_PushDown ) return 0;
152007 if( pItem->zName==0 ) continue;
152008 assert( pItem->pSTab!=0 );
152009 assert( pThis->pSTab!=0 );
152011 if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
152013 if( pItem->pSTab->pSchema==0 && pSel->selId!=pS1->selId ){
152025 return 0;
152064 if( (p->selFlags & SF_Aggregate)==0 ) return 0; /* This is an aggregate */
152065 if( p->pEList->nExpr!=1 ) return 0; /* Single result column */
152066 if( p->pWhere ) return 0;
152067 if( p->pHaving ) return 0;
152068 if( p->pGroupBy ) return 0;
152069 if( p->pOrderBy ) return 0;
152070 pExpr = p->pEList->a[0].pExpr;
152071 if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */
152073 if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */
152075 if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */
152076 if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */
152077 if( ExprHasProperty(pExpr, EP_WinFunc) ) return 0;/* Not a window function */
152079 if( pFrom->fg.isSubquery==0 ) return 0; /* FROM is a subquery */
152081 if( pSub->pPrior==0 ) return 0; /* Must be a compound */
152082 if( pSub->selFlags & SF_CopyCte ) return 0; /* Not a CTE */
152084 if( pSub->op!=TK_ALL && pSub->pPrior ) return 0; /* Must be UNION ALL */
152085 if( pSub->pWhere ) return 0; /* No WHERE clause */
152086 if( pSub->pLimit ) return 0; /* No LIMIT clause */
152090 return 0; /* Not an aggregate nor DISTINCT */
152092 assert( pSub->pHaving==0 ); /* Due to the previous */
152100 pExpr = 0;
152107 pSub->pPrior = 0;
152108 pSub->pNext = 0;
152111 pSub->nSelectRow = 0;
152113 pTerm = pPrior ? sqlite3ExprDup(db, pCount, 0) : pCount;
152114 pSub->pEList = sqlite3ExprListAppend(pParse, 0, pTerm);
152115 pTerm = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
152117 if( pExpr==0 ){
152124 p->pEList->a[0].pExpr = pExpr;
152128 if( sqlite3TreeTrace & 0x200 ){
152129 TREETRACE(0x200,pParse,p,("After count-of-view optimization:\n"));
152130 sqlite3TreeViewSelect(0, p, 0);
152143 for(i=0; i<pSrc->nSrc; i++){
152146 if( p0->pSTab==p1->pSTab && 0==sqlite3_stricmp(p0->zAlias, p1->zAlias) ){
152150 && (p1->u4.pSubq->pSelect->selFlags & SF_NestedFrom)!=0
152156 return 0;
152196 if( pCteUse->eM10d==M10d_Yes ) return 0; /* (2a) */
152197 if( pCteUse->nUse>=2 && pCteUse->eM10d!=M10d_No ) return 0; /* (2b) */
152199 if( pTabList->a[0].fg.jointype & JT_LTORJ ) return 0; /* (3) */
152200 if( OptimizationDisabled(pParse->db, SQLITE_Coroutines) ) return 0; /* (4) */
152201 if( isSelfJoinView(pTabList, pItem, i+1, pTabList->nSrc)!=0 ){
152202 return 0; /* (5) */
152204 if( i==0 ){
152207 if( selFlags & SF_UpdateFrom ) return 0; /* (1c-iii) */
152210 if( selFlags & SF_UpdateFrom ) return 0; /* (1c-iii) */
152212 if( pItem->fg.jointype & (JT_OUTER|JT_CROSS) ) return 0; /* (1c-ii) */
152213 if( i==0 ) break;
152216 if( pItem->fg.isSubquery ) return 0; /* (1c-i) */
152277 ExprList *pEList = 0; /* List of columns to extract. */
152282 AggInfo *pAggInfo = 0; /* Aggregate information */
152288 ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
152294 if( p==0 || pParse->nErr ){
152297 assert( db->mallocFailed==0 );
152298 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
152300 TREETRACE(0x1,pParse,p, ("begin processing:\n", pParse->addrExplain));
152301 if( sqlite3TreeTrace & 0x10000 ){
152302 if( (sqlite3TreeTrace & 0x10001)==0x10000 ){
152303 sqlite3TreeViewLine(0, "In sqlite3Select() at %s:%d",
152311 assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistFifo );
152312 assert( p->pOrderBy==0 || pDest->eDest!=SRT_Fifo );
152313 assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistQueue );
152314 assert( p->pOrderBy==0 || pDest->eDest!=SRT_Queue );
152322 TREETRACE(0x800,pParse,p, ("dropping superfluous ORDER BY:\n"));
152323 if( sqlite3TreeTrace & 0x800 ){
152324 sqlite3TreeViewExprList(0, p->pOrderBy, 0, "ORDERBY");
152330 p->pOrderBy = 0;
152335 sqlite3SelectPrep(pParse, p, 0);
152339 assert( db->mallocFailed==0 );
152340 assert( p->pEList!=0 );
152342 if( sqlite3TreeTrace & 0x10 ){
152343 TREETRACE(0x10,pParse,p, ("after name resolution:\n"));
152344 sqlite3TreeViewSelect(0, p, 0);
152350 ** In this case, it is an error if the target object (pSrc->a[0]) name
152358 SrcItem *p0 = &p->pSrc->a[0];
152384 if( p->pWin && (sqlite3TreeTrace & 0x40)!=0 ){
152385 TREETRACE(0x40,pParse,p, ("after window rewrite:\n"));
152386 sqlite3TreeViewSelect(0, p, 0);
152391 isAgg = (p->selFlags & SF_Aggregate)!=0;
152392 memset(&sSort, 0, sizeof(sSort));
152400 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
152402 Select *pSub = pItem->fg.isSubquery ? pItem->u4.pSubq->pSelect : 0;
152408 assert( pTab!=0 );
152422 if( (pItem->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
152429 TREETRACE(0x1000,pParse,p,
152433 TREETRACE(0x1000,pParse,p,
152436 unsetJoinExpr(p->pWhere, pItem->iCursor, 0);
152444 TREETRACE(0x1000,pParse,p,
152448 TREETRACE(0x1000,pParse,p,
152455 for(j=pTabList->nSrc-1; j>=0; j--){
152463 if( pSub==0 ) continue;
152488 if( (pSub->selFlags & SF_Aggregate)!=0 ) continue;
152489 assert( pSub->pGroupBy==0 );
152517 if( pSub->pOrderBy!=0
152518 && (p->pOrderBy!=0 || pTabList->nSrc>1) /* Condition (5) */
152519 && pSub->pLimit==0 /* Condition (1) */
152520 && (pSub->selFlags & (SF_OrderByReqd|SF_Recursive))==0 /* (2) and (6) */
152521 && (p->selFlags & SF_OrderByReqd)==0 /* Condition (3) and (4) */
152524 TREETRACE(0x800,pParse,p,
152528 pSub->pOrderBy = 0;
152549 if( pSub->pOrderBy!=0
152550 && i==0
152551 && (p->selFlags & SF_ComplexResult)!=0
152553 || (pTabList->a[1].fg.jointype&(JT_OUTER|JT_CROSS))!=0)
152579 TREETRACE(0x400,pParse,p,("end compound-select processing\n"));
152580 if( (sqlite3TreeTrace & 0x400)!=0 && ExplainQueryPlanParent(pParse)==0 ){
152581 sqlite3TreeViewSelect(0, p, 0);
152584 if( p->pNext==0 ) ExplainQueryPlanPop(pParse);
152594 if( p->pWhere!=0
152600 if( sqlite3TreeTrace & 0x2000 ){
152601 TREETRACE(0x2000,pParse,p,("After constant propagation:\n"));
152602 sqlite3TreeViewSelect(0, p, 0);
152606 TREETRACE(0x2000,pParse,p,("Constant propagation not helpful\n"));
152624 for(i=0; i<pTabList->nSrc; i++){
152652 if( pItem->colUsed==0 && pItem->zName!=0 ){
152658 zDb = 0;
152668 if( pItem->fg.isSubquery==0 ) continue;
152670 assert( pSubq!=0 );
152674 if( pSubq->addrFillSub!=0 ) continue;
152690 && (pItem->fg.isCte==0
152695 if( sqlite3TreeTrace & 0x4000 ){
152696 TREETRACE(0x4000,pParse,p,
152698 sqlite3TreeViewSelect(0, p, 0);
152701 assert( pSubq->pSelect && (pSub->selFlags & SF_PushDown)!=0 );
152703 TREETRACE(0x4000,pParse,p,("WHERE-clause push-down not possible\n"));
152714 if( sqlite3TreeTrace & 0x4000 ){
152715 TREETRACE(0x4000,pParse,p,
152718 sqlite3TreeViewSelect(0, p, 0);
152735 sqlite3VdbeAddOp3(v, OP_InitCoroutine, pSubq->regReturn, 0, addrTop);
152748 }else if( pItem->fg.isCte && pItem->u2.pCteUse->addrM9e>0 ){
152760 }else if( (pPrior = isSelfJoinView(pTabList, pItem, 0, i))!=0 ){
152766 assert( pPriorSubq!=0 );
152778 int onceAddr = 0;
152787 if( pItem->fg.isCorrelated==0 ){
152807 if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
152827 sDistinct.isTnct = (p->selFlags & SF_Distinct)!=0;
152830 if( sqlite3TreeTrace & 0x8000 ){
152831 TREETRACE(0x8000,pParse,p,("After all FROM-clause analysis:\n"));
152832 sqlite3TreeViewSelect(0, p, 0);
152854 && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
152857 && p->pWin==0
152861 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
152863 for(i=0; i<pGroupBy->nExpr; i++){
152875 if( sqlite3TreeTrace & 0x20000 ){
152876 TREETRACE(0x20000,pParse,p,("Transform DISTINCT into GROUP BY:\n"));
152877 sqlite3TreeViewSelect(0, p, 0);
152893 pParse, sSort.pOrderBy, 0, pEList->nExpr);
152897 sSort.iECursor, sSort.pOrderBy->nExpr+1+pEList->nExpr, 0,
152912 for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].fg.bUsed==0; ii--){
152917 for(ii=0; ii<pEList->nExpr; ii++){
152918 if( pEList->a[ii].fg.bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
152926 if( (p->selFlags & SF_FixedLimit)==0 ){
152930 if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
152940 sDistinct.tabTnct, 0, 0,
152941 (char*)sqlite3KeyInfoFromExprList(pParse, p->pEList,0,0),
152949 if( !isAgg && pGroupBy==0 ){
152951 u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0)
152963 TREETRACE(0x2,pParse,p,("WhereBegin\n"));
152966 if( pWInfo==0 ) goto select_end;
152983 sSort.pOrderBy = 0;
152986 TREETRACE(0x2,pParse,p,("WhereBegin returns\n"));
152992 if( sSort.addrSortIndex>=0 && sSort.pOrderBy==0 ){
153006 sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
153009 sSort.labelOBLopt = 0;
153025 TREETRACE(0x2,pParse,p,("WhereEnd\n"));
153040 int sortPTab = 0; /* Pseudotable used to decode sorting results */
153041 int sortOut = 0; /* Output register from the sorter */
153042 int orderByGrp = 0; /* True if the GROUP BY and ORDER BY are the same */
153051 for(k=p->pEList->nExpr, pItem=p->pEList->a; k>0; k--, pItem++){
153052 pItem->u.x.iAlias = 0;
153054 for(k=pGroupBy->nExpr, pItem=pGroupBy->a; k>0; k--, pItem++){
153055 pItem->u.x.iAlias = 0;
153075 for(ii=0; ii<pGroupBy->nExpr; ii++){
153080 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
153085 assert( 0==sqlite3LogEst(1) );
153086 p->nSelectRow = 0;
153108 memset(&sNC, 0, sizeof(sNC));
153113 pAggInfo->nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
153128 if( p->pGroupBy==0 && p->pHaving==0 && pAggInfo->nFunc==1 ){
153129 minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pFExpr, &pMinMaxOrderBy);
153136 if( sqlite3TreeTrace & 0x20 ){
153137 TREETRACE(0x20,pParse,p,("After aggregate analysis %p:\n", pAggInfo));
153138 sqlite3TreeViewSelect(0, p, 0);
153140 sqlite3DebugPrintf("MIN/MAX Optimization (0x%02x) adds:\n", minMaxFlag);
153141 sqlite3TreeViewExprList(0, pMinMaxOrderBy, 0, "ORDERBY");
153161 ExprList *pDistinct = 0;
153162 u16 distFlag = 0;
153166 && pAggInfo->aFunc[0].iDistinct>=0
153167 && ALWAYS(pAggInfo->aFunc[0].pFExpr!=0)
153168 && ALWAYS(ExprUseXList(pAggInfo->aFunc[0].pFExpr))
153169 && pAggInfo->aFunc[0].pFExpr->x.pList!=0
153171 Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr;
153172 pExpr = sqlite3ExprDup(db, pExpr, 0);
153173 pDistinct = sqlite3ExprListDup(db, pGroupBy, 0);
153175 distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
153185 0, pAggInfo->nColumn);
153188 0, (char*)pKeyInfo, P4_KEYINFO);
153202 sqlite3VdbeAddOp2(v, OP_Integer, 0, iAbortFlag);
153204 sqlite3VdbeAddOp3(v, OP_Null, 0, iAMem, iAMem+pGroupBy->nExpr-1);
153213 TREETRACE(0x2,pParse,p,("WhereBegin\n"));
153216 | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
153218 if( pWInfo==0 ){
153227 TREETRACE(0x2,pParse,p,("WhereBegin returns\n"));
153233 groupBySort = 0;
153248 ExplainQueryPlan2(addrExp, (pParse, 0, "USE TEMP B-TREE FOR %s",
153249 (sDistinct.isTnct && (p->selFlags&SF_Distinct)==0) ?
153257 for(i=0; i<pAggInfo->nColumn; i++){
153264 sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
153267 for(i=0; i<pAggInfo->nColumn; i++){
153274 pAggInfo->directMode = 0;
153276 sqlite3VdbeScanStatusCounters(v, addrExp, 0, sqlite3VdbeCurrentAddr(v));
153282 TREETRACE(0x2,pParse,p,("WhereEnd\n"));
153286 sqlite3VdbeScanStatusCounters(v, addrExp, sqlite3VdbeCurrentAddr(v), 0);
153303 if( sqlite3TreeTrace & 0x20 ){
153304 TREETRACE(0x20, pParse, p,
153306 sqlite3TreeViewSelect(0, p, 0);
153322 sSort.pOrderBy = 0;
153327 ** (b0 is memory location iBMem+0, b1 is iBMem+1, and so forth)
153336 for(j=0; j<pGroupBy->nExpr; j++){
153349 while( ALWAYS(pBase!=0) && pBase->op==TK_IF_NULL_ROW ){
153353 if( ALWAYS(pBase!=0)
153364 sqlite3VdbeAddOp3(v, OP_Jump, addr1+1, 0, addr1+1); VdbeCoverage(v);
153397 TREETRACE(0x2,pParse,p,("WhereEnd\n"));
153441 sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
153445 if( distFlag!=0 && eDist!=WHERE_DISTINCT_NOOP ){
153446 struct AggInfo_func *pF = &pAggInfo->aFunc[0];
153453 if( (pTab = isSimpleCount(p, pAggInfo))!=0 ){
153472 KeyInfo *pKeyInfo = 0; /* Keyinfo for scanned index */
153473 Index *pBest = 0; /* Best index found so far */
153477 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
153489 if( !p->pSrc->a[0].fg.notIndexed ){
153491 if( pIdx->bUnordered==0
153493 && pIdx->pPartIdxWhere==0
153511 sqlite3VdbeAddOp2(v, OP_Count, iCsr, AggInfoFuncReg(pAggInfo,0));
153517 int regAcc = 0; /* "populate accumulators" flag */
153518 ExprList *pDistinct = 0;
153519 u16 distFlag = 0;
153524 ** will contain 0 the first time the inner loop runs, and 1 thereafter.
153532 for(i=0; i<pAggInfo->nFunc; i++){
153542 sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
153544 }else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){
153545 assert( ExprUseXList(pAggInfo->aFunc[0].pFExpr) );
153546 pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList;
153547 distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
153555 assert( p->pGroupBy==0 );
153563 assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
153564 assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
153566 TREETRACE(0x2,pParse,p,("WhereBegin\n"));
153568 pDistinct, p, minMaxFlag|distFlag, 0);
153569 if( pWInfo==0 ){
153572 TREETRACE(0x2,pParse,p,("WhereBegin returns\n"));
153586 TREETRACE(0x2,pParse,p,("WhereEnd\n"));
153591 sSort.pOrderBy = 0;
153593 selectInnerLoop(pParse, p, -1, 0, 0,
153617 ** set the return code to 1. Otherwise 0. */
153618 rc = (pParse->nErr>0);
153624 assert( db->mallocFailed==0 || db->mallocFailed==1 );
153625 assert( db->mallocFailed==0 || pParse->nErr!=0 );
153631 if( sqlite3TreeTrace & 0x20 ){
153632 TREETRACE(0x20,pParse,p,("Finished with AggInfo\n"));
153636 for(i=0; i<pAggInfo->nColumn; i++){
153638 if( pExpr==0 ) continue;
153642 for(i=0; i<pAggInfo->nFunc; i++){
153644 assert( pExpr!=0 );
153652 TREETRACE(0x1,pParse,p,("end processing\n"));
153653 if( (sqlite3TreeTrace & 0x40000)!=0 && ExplainQueryPlanParent(pParse)==0 ){
153654 sqlite3TreeViewSelect(0, p, 0);
153713 if( p->nRow==0 && argv!=0 ){
153722 if( azNew==0 ) goto malloc_failed;
153729 if( p->nRow==0 ){
153731 for(i=0; i<nCol; i++){
153733 if( z==0 ) goto malloc_failed;
153747 if( argv!=0 ){
153748 for(i=0; i<nCol; i++){
153749 if( argv[i]==0 ){
153750 z = 0;
153754 if( z==0 ) goto malloc_failed;
153761 return 0;
153790 if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT;
153792 *pazResult = 0;
153793 if( pnColumn ) *pnColumn = 0;
153794 if( pnRow ) *pnRow = 0;
153795 if( pzErrMsg ) *pzErrMsg = 0;
153796 res.zErrMsg = 0;
153797 res.nRow = 0;
153798 res.nColumn = 0;
153803 if( res.azResult==0 ){
153807 res.azResult[0] = 0;
153809 assert( sizeof(res.azResult[0])>= sizeof(res.nData) );
153810 res.azResult[0] = SQLITE_INT_TO_PTR(res.nData);
153811 if( (rc&0xff)==SQLITE_ABORT ){
153831 if( azNew==0 ){
153853 assert( azResult!=0 );
153854 n = SQLITE_PTR_TO_INT(azResult[0]);
153918 assert( pParse->disableTriggers==0 );
153926 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
153933 assert( pParse->db->pVtabCtx==0 );
153945 #if 0
153979 Trigger *pTrigger = 0; /* The new trigger */
153981 char *zName = 0; /* Name of the trigger */
153987 assert( pName1!=0 ); /* pName1->z might be NULL, but not pName1 itself */
153988 assert( pName2!=0 );
153990 assert( op>0 && op<0xff );
153993 if( pName2->n>0 ){
154002 if( iDb<0 ){
154019 assert( pTableName->a[0].fg.fixedSchema==0 );
154020 assert( pTableName->a[0].fg.isSubquery==0 );
154021 sqlite3DbFree(db, pTableName->a[0].u4.zDatabase);
154022 pTableName->a[0].u4.zDatabase = 0;
154027 ** If sqlite3SrcListLookup() returns 0, indicating the table does not
154031 if( db->init.busy==0 && pName2->n==0 && pTab
154052 if( (pTab->tabFlags & TF_Shadow)!=0 && sqlite3ReadOnlyShadowTables(db) ){
154060 if( zName==0 ){
154067 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
154082 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
154111 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
154128 if( pTrigger==0 ) goto trigger_cleanup;
154130 zName = 0;
154131 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
154137 sqlite3RenameTokenRemap(pParse, pTrigger->table, pTableName->a[0].zName);
154139 pWhen = 0;
154144 pColumns = 0;
154145 assert( pParse->pNewTrigger==0 );
154193 pParse->pNewTrigger = 0;
154214 pTrig = 0;
154231 if( pStep->zTarget!=0
154244 if( v==0 ) goto triggerfinish_cleanup;
154245 sqlite3BeginWriteOperation(pParse, 0, iDb);
154247 testcase( z==0 );
154250 " VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
154256 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName), 0);
154262 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
154263 assert( pLink!=0 );
154270 assert( pTab!=0 );
154289 if( z ) for(i=0; z[i]; i++) if( sqlite3Isspace(z[i]) ) z[i] = ' ';
154307 if( pTriggerStep==0 ) {
154309 return 0;
154334 if( pParse->nErr ) return 0;
154370 assert(pSelect != 0 || db->mallocFailed);
154376 pSelect = 0;
154421 pEList = 0;
154422 pWhere = 0;
154423 pFrom = 0;
154456 pWhere = 0;
154470 if( pTrigger==0 || pTrigger->bReturning ) return;
154488 Trigger *pTrigger = 0;
154500 assert( pName->a[0].fg.fixedSchema==0 && pName->a[0].fg.isSubquery==0 );
154501 zDb = pName->a[0].u4.zDatabase;
154502 zName = pName->a[0].zName;
154503 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
154506 if( zDb && sqlite3DbIsNamed(db, j, zDb)==0 ) continue;
154507 assert( sqlite3SchemaMutexHeld(db, j, 0) );
154545 assert( iDb>=0 && iDb<db->nDb );
154555 sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
154563 if( (v = sqlite3GetVdbe(pParse))!=0 ){
154569 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
154580 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
154582 pTrigger = sqlite3HashInsert(pHash, zName, 0);
154612 if( pIdList==0 || NEVER(pEList==0) ) return 1;
154613 for(e=0; e<pEList->nExpr; e++){
154614 if( sqlite3IdListIndex(pIdList, pEList->a[e].zEName)>=0 ) return 1;
154616 return 0;
154623 if( NEVER(db->aDb[1].pSchema==0) ) return 0;
154624 if( sqliteHashFirst(&db->aDb[1].pSchema->trigHash)==0 ) return 0;
154641 int mask = 0;
154642 Trigger *pList = 0;
154646 assert( pList==0 || IsVirtual(pTab)==0
154647 || (pList->bReturning && pList->pNext==0) );
154648 if( pList!=0 ){
154650 if( (pParse->db->flags & SQLITE_EnableTrigger)==0
154651 && pTab->pTrigger!=0
154657 pList = 0;
154661 p->pNext = 0;
154695 return (mask ? pList : 0);
154704 assert( pTab!=0 );
154705 if( (pTab->pTrigger==0 && !tempTriggersExist(pParse->db))
154708 if( pMask ) *pMask = 0;
154709 return 0;
154731 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
154732 assert( pSrc==0 || pSrc->nSrc==1 );
154733 assert( zName || pSrc==0 );
154736 pSrc->a[0].zName = zName;
154738 assert( pSrc->a[0].fg.fixedSchema || pSrc->a[0].u4.zDatabase==0 );
154739 pSrc->a[0].u4.pSchema = pSchema;
154740 pSrc->a[0].fg.fixedSchema = 1;
154743 SrcList *pDup = sqlite3SrcListDup(db, pStep->pFrom, 0);
154747 pSubquery = sqlite3SelectNew(pParse,0,pDup,0,0,0,0,SF_NestedFrom,0);
154748 as.n = 0;
154749 as.z = 0;
154750 pDup = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
154769 assert( pTerm!=0 );
154771 if( pTerm->op!=TK_DOT ) return 0;
154772 assert( pTerm->pRight!=0 );
154773 assert( pTerm->pLeft!=0 );
154774 if( pTerm->pRight->op!=TK_ASTERISK ) return 0;
154790 ExprList *pNew = 0;
154794 for(i=0; i<pList->nExpr; i++){
154796 if( NEVER(pOldExpr==0) ) continue;
154799 for(jj=0; jj<pTab->nCol; jj++){
154811 Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
154813 if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
154830 && (pExpr->x.pSelect->selFlags & SF_Correlated)!=0
154849 assert( pSelect!=0 );
154851 assert( pSrc!=0 );
154852 for(i=0; i<pSrc->nSrc; i++){
154877 memset(&w, 0, sizeof(w));
154908 assert( v!=0 );
154921 memset(&sSelect, 0, sizeof(sSelect));
154923 memset(pFrom, 0, SZ_SRCLIST_1);
154924 sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
154927 pFrom->a[0].pSTab = pTab;
154928 pFrom->a[0].zName = pTab->zName; /* tag-20240424-1 */
154929 pFrom->a[0].iCursor = -1;
154930 sqlite3SelectPrep(pParse, &sSelect, 0);
154931 if( pParse->nErr==0 ){
154932 assert( db->mallocFailed==0 );
154937 if( pParse->nErr==0 ){
154939 memset(&sNC, 0, sizeof(sNC));
154940 if( pReturning->nRetCol==0 ){
154958 for(i=0; i<nCol; i++){
154960 assert( pCol!=0 ); /* Due to !db->mallocFailed ~9 lines above */
154972 pParse->eTriggerOp = 0;
154973 pParse->pTriggerTab = 0;
154993 assert( v!=0 );
155009 assert( pParse->okConstFactor==0 );
155013 sqlite3VdbeAddOp4(v, OP_Trace, 0x7fffffff, 1, 0,
155023 sqlite3ExprListDup(db, pStep->pExprList, 0),
155024 sqlite3ExprDup(db, pStep->pWhere, 0),
155025 pParse->eOrconf, 0, 0, 0
155033 sqlite3SelectDup(db, pStep->pSelect, 0),
155044 sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0
155051 Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
155052 sqlite3SelectDestInit(&sDest, SRT_Discard, 0);
155060 return 0;
155087 assert( pFrom->zErrMsg==0 || pFrom->nErr );
155088 assert( pTo->zErrMsg==0 || pTo->nErr );
155089 if( pTo->nErr==0 ){
155111 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
155114 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
155115 int iEndTrigger = 0; /* Label to jump to if WHEN is false */
155118 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
155125 if( !pPrg ) return 0;
155129 if( !pProgram ) return 0;
155133 pPrg->aColmask[0] = 0xffffffff;
155134 pPrg->aColmask[1] = 0xffffffff;
155139 memset(&sNC, 0, sizeof(sNC));
155147 sSubParse.oldmask = 0;
155148 sSubParse.newmask = 0;
155172 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
155173 if( db->mallocFailed==0
155193 if( pParse->nErr==0 ){
155194 assert( db->mallocFailed==0 );
155200 pPrg->aColmask[0] = sSubParse.oldmask;
155227 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
155269 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
155302 ** reg+0 OLD.rowid
155340 assert( (op==TK_UPDATE)==(pChanges!=0) );
155347 assert( p->pSchema!=0 );
155348 assert( p->pTabSchema!=0 );
155377 ** Bit 0 of the returned mask is set if the left-most column of the
155381 ** with an index greater than 32 may be accessed, 0xffffffff is returned.
155386 ** Parameter isNew must be either 1 or 0. If it is 0, then the mask returned
155399 int isNew, /* 1 for new.* ref mask, 0 for old.* ref mask */
155405 u32 mask = 0;
155408 assert( isNew==1 || isNew==0 );
155410 return 0xffffffff;
155418 mask = 0xffffffff;
155498 assert( pTab!=0 );
155502 sqlite3_value *pValue = 0;
155535 int *aXRef, /* aXRef[j]>=0 if column j is being updated */
155540 if( iIdxCol>=0 ){
155541 return aXRef[iIdxCol]>=0;
155544 assert( pIdx->aColExpr!=0 );
155545 assert( pIdx->aColExpr->a[iCol].pExpr!=0 );
155564 int *aXRef, /* aXRef[j]>=0 if column j is being updated */
155567 if( pIdx->pPartIdxWhere==0 ) return 0;
155576 ** table in the source-list (pSrc->a[0]).
155579 Expr *pRet = sqlite3PExpr(pParse, TK_ROW, 0, 0);
155605 ** of table pTabList->a[0].pTab.
155625 Index *pPk, /* PK if table 0 is WITHOUT ROWID */
155634 Select *pSelect = 0;
155635 ExprList *pList = 0;
155636 ExprList *pGrp = 0;
155637 Expr *pLimit2 = 0;
155638 ExprList *pOrderBy2 = 0;
155640 Table *pTab = pTabList->a[0].pSTab;
155646 if( pOrderBy && pLimit==0 ) {
155650 pOrderBy2 = sqlite3ExprListDup(db, pOrderBy, 0);
155651 pLimit2 = sqlite3ExprDup(db, pLimit, 0);
155657 pSrc = sqlite3SrcListDup(db, pTabList, 0);
155658 pWhere2 = sqlite3ExprDup(db, pWhere, 0);
155662 assert( pSrc->a[0].fg.notCte );
155663 pSrc->a[0].iCursor = -1;
155664 pSrc->a[0].pSTab->nTabRef--;
155665 pSrc->a[0].pSTab = 0;
155668 for(i=0; i<pPk->nKeyCol; i++){
155672 pGrp = sqlite3ExprListAppend(pParse, pGrp, sqlite3ExprDup(db, pNew, 0));
155679 for(i=0; i<pTab->nCol; i++){
155685 pList = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
155688 pGrp = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
155692 assert( pChanges!=0 || pParse->db->mallocFailed );
155694 for(i=0; i<pChanges->nExpr; i++){
155696 sqlite3ExprDup(db, pChanges->a[i].pExpr, 0)
155701 pSrc, pWhere2, pGrp, 0, pOrderBy2,
155732 int addrTop = 0; /* VDBE instruction address of the start of the loop */
155733 WhereInfo *pWInfo = 0; /* Information about the WHERE clause */
155743 int *aRegIdx = 0; /* Registers for to each index and the main table */
155744 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
155751 Expr *pRowidExpr = 0; /* Expression defining the new record number */
155768 int iEph = 0; /* Ephemeral table holding all primary key values */
155769 int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */
155771 int addrOpen = 0; /* Address of OP_OpenEphemeral */
155772 int iPk = 0; /* First of nPk cells holding PRIMARY KEY value */
155773 i16 nPk = 0; /* Number of components of the PRIMARY KEY */
155774 int bReplace = 0; /* True if REPLACE conflict resolution might happen */
155776 int nChangeFrom = 0; /* If there is a FROM, pChanges->nExpr, else 0 */
155779 int regRowCount = 0; /* A count of rows changed */
155780 int regOldRowid = 0; /* The old rowid */
155781 int regNewRowid = 0; /* The new rowid */
155782 int regNew = 0; /* Content of the NEW.* table in triggers */
155783 int regOld = 0; /* Content of OLD.* table in triggers */
155784 int regRowSet = 0; /* Rowset of rows to be updated */
155785 int regKey = 0; /* composite PRIMARY KEY value */
155787 memset(&sContext, 0, sizeof(sContext));
155793 assert( db->mallocFailed==0 );
155798 if( pTab==0 ) goto update_cleanup;
155807 assert( pTrigger || tmask==0 );
155809 # define pTrigger 0
155810 # define isView 0
155811 # define tmask 0
155815 # define isView 0
155819 if( sqlite3TreeTrace & 0x10000 ){
155820 sqlite3TreeViewLine(0, "In sqlite3Update() at %s:%d", __FILE__, __LINE__);
155827 ** in the change-list. Otherwise, set it to 0. There cannot be a FROM
155830 nChangeFrom = (pTabList->nSrc>1) ? pChanges->nExpr : 0;
155831 assert( nChangeFrom==0 || pUpsert==0 );
155834 if( !isView && nChangeFrom==0 ){
155838 pOrderBy = 0;
155839 pLimit = 0;
155857 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
155858 testcase( pPk!=0 && pPk!=pTab->pIndex );
155859 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
155871 pTabList->a[0].iCursor = iDataCur;
155877 if( aXRef==0 ) goto update_cleanup;
155881 aToOpen[nIdx+1] = 0;
155882 for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
155885 memset(&sNC, 0, sizeof(sNC));
155893 if( v==0 ) goto update_cleanup;
155901 chngRowid = chngPk = 0;
155902 for(i=0; i<pChanges->nExpr; i++){
155905 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
155909 if( j>=0 ){
155914 }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
155929 if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){
155944 j<0 ? "ROWID" : pTab->aCol[j].zCnName,
155954 assert( (chngRowid & chngPk)==0 );
155955 assert( chngRowid==0 || chngRowid==1 );
155956 assert( chngPk==0 || chngPk==1 );
155972 bProgress = 0;
155973 for(i=0; i<pTab->nCol; i++){
155974 if( aXRef[i]>=0 ) continue;
155975 if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ) continue;
155993 pTabList->a[0].colUsed = IsVirtual(pTab) ? ALLBITS : 0;
156002 for(nAllIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nAllIdx++){
156010 reg = 0;
156011 for(i=0; i<pIdx->nKeyCol; i++){
156022 if( reg==0 ) aToOpen[nAllIdx+1] = 0;
156032 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
156065 if( nChangeFrom==0 && isView ){
156069 pOrderBy = 0;
156070 pLimit = 0;
156077 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pWhere) ){
156095 if( (db->flags&SQLITE_CountRows)!=0
156099 && pUpsert==0
156102 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
156105 if( nChangeFrom==0 && HasRowid(pTab) ){
156106 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
156108 addrOpen = sqlite3VdbeAddOp3(v, OP_OpenEphemeral, iEph, 0, regRowSet);
156110 assert( pPk!=0 || HasRowid(pTab) );
156111 nPk = pPk ? pPk->nKeyCol : 0;
156116 if( pUpsert==0 ){
156117 int nEphCol = nPk + nChangeFrom + (isView ? pTab->nCol : 0);
156119 if( pPk ) sqlite3VdbeAddOp3(v, OP_Null, 0, iPk, iPk+nPk-1);
156151 pWInfo = 0;
156154 bFinishSeek = 0;
156173 && (pWhere==0 || !ExprHasProperty(pWhere, EP_Subquery))
156177 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0,0,0,flags,iIdxCur);
156178 if( pWInfo==0 ) goto update_cleanup;
156196 if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){
156221 for(i=0; i<nPk; i++){
156222 assert( pPk->aiColumn[i]>=0 );
156238 if( pUpsert==0 ){
156239 if( nChangeFrom==0 && eOnePass!=ONEPASS_MULTI ){
156244 int addrOnce = 0;
156245 int iNotUsed1 = 0;
156246 int iNotUsed2 = 0;
156250 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0;
156251 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0;
156254 if( eOnePass==ONEPASS_MULTI && (nIdx-(aiCurOnePass[1]>=0))>0 ){
156257 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur,
156266 if( aiCurOnePass[0]!=iDataCur
156280 VdbeCoverageIf(v, pPk==0);
156281 VdbeCoverageIf(v, pPk!=0);
156289 for(i=0; i<nPk; i++){
156304 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey,0);
156323 assert( iRowidExpr>=0 );
156324 if( nChangeFrom==0 ){
156335 u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);
156337 pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError
156339 for(i=0; i<pTab->nCol; i++){
156342 if( oldmask==0xffffffff
156343 || (i<32 && (oldmask & MASKBIT32(i))!=0)
156344 || (colFlags & COLFLAG_PRIMKEY)!=0
156346 testcase( oldmask!=0xffffffff && i==31 );
156349 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
156352 if( chngRowid==0 && pPk==0 ){
156354 if( isView ) sqlite3VdbeAddOp2(v, OP_Null, 0, regOldRowid);
156376 for(i=0, k=regNew; i<pTab->nCol; i++, k++){
156378 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
156379 }else if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)!=0 ){
156383 if( j>=0 ){
156391 }else if( 0==(tmask&TRIGGER_BEFORE) || i>31 || (newmask & MASKBIT32(i)) ){
156400 bFinishSeek = 0;
156402 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
156446 for(i=0, k=regNew; i<pTab->nCol; i++, k++){
156449 }else if( aXRef[i]<0 && i!=pTab->iPKey ){
156465 assert( regOldRowid>0 );
156468 aXRef, 0);
156484 sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
156511 OPFLAG_ISUPDATE | ((hasFK>1 || chngKey) ? 0 : OPFLAG_ISNOOP),
156515 assert( hasFK==0 && chngKey==0 );
156523 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
156528 sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey);
156534 OPFLAG_ISUPDATE | (eOnePass==ONEPASS_MULTI ? OPFLAG_SAVEPOSITION : 0),
156535 0, 0
156575 if( pParse->nested==0 && pParse->pTriggerTab==0 && pUpsert==0 ){
156646 WhereInfo *pWInfo = 0;
156651 int iCsr = pSrc->a[0].iCursor; /* Cursor used for virtual table scan */
156665 Index *pPk = 0;
156670 pRow = sqlite3ExprDup(db, pRowid, 0);
156672 pRow = sqlite3PExpr(pParse, TK_ROW, 0, 0);
156677 assert( pPk!=0 );
156679 iPk = pPk->aiColumn[0];
156680 if( aXRef[iPk]>=0 ){
156681 pRow = sqlite3ExprDup(db, pChanges->a[aXRef[iPk]].pExpr, 0);
156686 pList = sqlite3ExprListAppend(pParse, 0, pRow);
156688 for(i=0; i<pTab->nCol; i++){
156689 if( aXRef[i]>=0 ){
156691 sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0)
156700 updateFromSelect(pParse, ephemTab, pPk, pList, pSrc, pWhere, 0, 0);
156709 pParse, pSrc, pWhere, 0, 0, 0, WHERE_ONEPASS_DESIRED, 0
156711 if( pWInfo==0 ) return;
156714 for(i=0; i<pTab->nCol; i++){
156715 assert( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 );
156716 if( aXRef[i]>=0 ){
156734 assert( pPk!=0 );
156736 iPk = pPk->aiColumn[0];
156778 for(i=0; i<nArg; i++){
156783 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, nArg, regArg, pVTab, P4_VTAB);
156792 sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
156842 if( p==0 ) return 0;
156844 sqlite3ExprListDup(db, p->pUpsertTarget, 0),
156845 sqlite3ExprDup(db, p->pUpsertTargetWhere, 0),
156846 sqlite3ExprListDup(db, p->pUpsertSet, 0),
156847 sqlite3ExprDup(db, p->pUpsertWhere, 0),
156865 if( pNew==0 ){
156871 return 0;
156877 pNew->isDoUpdate = pSet!=0;
156904 int nClause = 0; /* Counter of ON CONFLICT clauses */
156907 assert( pTabList->a[0].pSTab!=0 );
156908 assert( pUpsert!=0 );
156909 assert( pUpsert->pUpsertTarget!=0 );
156915 memset(&sNC, 0, sizeof(sNC));
156926 pTab = pTabList->a[0].pSTab;
156928 iCursor = pTabList->a[0].iCursor;
156931 && (pTerm = pTarget->a[0].pExpr)->op==TK_COLUMN
156935 assert( pUpsert->pUpsertIdx==0 );
156939 /* Initialize sCol[0..1] to be an expression parse tree for a
156940 ** single column of an index. The sCol[0] node will be the TK_COLLATE
156945 memset(sCol, 0, sizeof(sCol));
156946 sCol[0].op = TK_COLLATE;
156947 sCol[0].pLeft = &sCol[1];
156949 sCol[1].iTable = pTabList->a[0].iCursor;
156957 if( pUpsert->pUpsertTargetWhere==0 ) continue;
156959 pIdx->pPartIdxWhere, iCursor)!=0 ){
156964 for(ii=0; ii<nn; ii++){
156966 sCol[0].u.zToken = (char*)pIdx->azColl[ii];
156968 assert( pIdx->aColExpr!=0 );
156973 sCol[0].pLeft = pExpr;
156974 pExpr = &sCol[0];
156977 sCol[0].pLeft = &sCol[1];
156979 pExpr = &sCol[0];
156981 for(jj=0; jj<nn; jj++){
156982 if( sqlite3ExprCompare(0,pTarget->a[jj].pExpr,pExpr,iCursor)<2 ){
157007 if( pUpsert->pUpsertIdx==0 ){
157009 if( nClause==0 && pUpsert->pNextUpsert==0 ){
157010 zWhich[0] = 0;
157029 if( NEVER(pUpsert==0) ) return 0;
157032 if( pNext==0 ) return 1;
157033 if( pNext->pUpsertTarget==0 ) return 1;
157034 if( pNext->pUpsertIdx==0 ) return 1;
157035 if( !pNext->isDup ) return 0;
157038 return 0;
157050 && pUpsert->pUpsertTarget!=0
157081 assert( v!=0 );
157082 assert( pUpsert!=0 );
157090 sqlite3VdbeAddOp3(v, OP_SeekRowid, iDataCur, 0, regRowid);
157098 for(i=0; i<nPk; i++){
157100 assert( pPk->aiColumn[i]>=0 );
157107 i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk);
157109 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0,
157117 pSrc = sqlite3SrcListDup(db, pTop->pUpsertSrc, 0);
157119 for(i=0; i<pTab->nCol; i++){
157124 sqlite3Update(pParse, pSrc, sqlite3ExprListDup(db,pUpsert->pUpsertSet,0),
157125 sqlite3ExprDup(db,pUpsert->pUpsertWhere,0), OE_Abort, 0, 0, pUpsert);
157169 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
157172 const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0);
157173 assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 );
157180 && (strncmp(zSubSql,"CRE",3)==0 || strncmp(zSubSql,"INS",3)==0)
157201 if( z==0 ) return SQLITE_NOMEM;
157239 int iDb = 0;
157240 if( v==0 ) goto build_vacuum_end;
157247 if( iDb<0 ) goto build_vacuum_end;
157255 if( iDb<0 ) iDb = 0;
157259 int iIntoReg = 0;
157260 if( pInto && sqlite3ResolveSelfReference(pParse,0,0,pInto,0)==0 ){
157290 Db *pDb = 0; /* Database to detach at end of vacuum */
157334 db->mTrace = 0;
157362 assert( strcmp(pDb->zDbSName,zDbVacuum)==0 );
157366 i64 sz = 0;
157367 if( id->pMethods!=0 && (sqlite3OsFileSize(id, &sz)!=SQLITE_OK || sz>0) ){
157382 sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
157391 rc = sqlite3BtreeBeginTrans(pMain, pOut==0 ? 2 : 0, 0);
157397 && pOut==0
157399 db->nextPagesize = 0;
157402 if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0)
157403 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
157411 sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
157422 " AND coalesce(rootpage,1)>0",
157432 db->init.iDb = 0;
157442 "WHERE type='table'AND coalesce(rootpage,1)>0",
157445 assert( (db->mDbFlags & DBFLAG_Vacuum)!=0 );
157458 " OR(type='table'AND rootpage=0)",
157481 BTREE_DEFAULT_CACHE_SIZE, 0, /* Preserve the default page cache size */
157482 BTREE_TEXT_ENCODING, 0, /* Preserve the text encoding */
157483 BTREE_USER_VERSION, 0, /* Preserve the user version */
157484 BTREE_APPLICATION_ID, 0, /* Preserve the application id */
157488 assert( pOut!=0 || SQLITE_TXN_WRITE==sqlite3BtreeTxnState(pMain) );
157491 for(i=0; i<ArraySize(aCopy); i+=2){
157499 if( pOut==0 ){
157506 if( pOut==0 ){
157513 if( pOut==0 ){
157520 db->init.iDb = 0;
157526 sqlite3BtreeSetPageSize(pMain, -1, 0, 1);
157539 pDb->pBt = 0;
157540 pDb->pSchema = 0;
157590 ** If pModule==0, then delete the module zName if it exists.
157602 if( pModule==0 ){
157604 pMod = 0;
157608 if( pMod==0 ){
157610 return 0;
157618 pMod->pEpoTab = 0;
157626 pMod = 0;
157668 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
157670 return createModule(db, zName, pModule, pAux, 0);
157684 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
157703 for(ii=0; azNames[ii]!=0 && strcmp(azNames[ii],pMod->zName)!=0; ii++){}
157704 if( azNames[ii]!=0 ) continue;
157706 createModule(db, pMod->zName, 0, 0, 0);
157716 assert( pMod->nRefModule>0 );
157718 if( pMod->nRefModule==0 ){
157722 assert( pMod->pEpoTab==0 );
157760 assert( pVTab->nRef>0 );
157765 if( pVTab->nRef==0 ){
157783 VTable *pRet = 0;
157788 p->u.vtab.p = 0;
157796 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
157805 pRet->pNext = 0;
157870 db->pDisconnect = 0;
157895 assert( db!=0 );
157896 if( db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
157899 for(i=0; i<p->u.vtab.nArg; i++){
157923 if( azModuleArg==0 ){
157928 azModuleArg[i+1] = 0;
157948 sqlite3StartTable(pParse, pName1, pName2, 0, 0, 1, ifNotExists);
157950 if( pTable==0 ) return;
157951 assert( 0==pTable->pIndex );
157956 assert( pTable->u.vtab.nArg==0 );
157958 addModuleArgument(pParse, pTable, 0);
157960 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
157961 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
157975 assert( iDb>=0 ); /* The database the table is being created in */
157977 pTable->u.vtab.azArg[0], pParse->db->aDb[iDb].zDbSName);
158004 if( pTab==0 ) return;
158007 pParse->sArg.z = 0;
158043 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
158056 sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere, 0);
158068 assert( zName!=0 );
158076 pParse->pNewTable = 0;
158086 pParse->sArg.z = 0;
158087 pParse->sArg.n = 0;
158096 if( pArg->z==0 ){
158122 char *zErr = 0;
158164 sCtx.bDeclared = 0;
158168 assert( pTab!=0 );
158176 if( zErr==0 ){
158186 memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
158190 if( sCtx.bDeclared==0 ){
158197 u16 oooHidden = 0;
158206 for(iCol=0; iCol<pTab->nCol; iCol++){
158209 int i = 0;
158211 for(i=0; i<nType; i++){
158212 if( 0==sqlite3StrNICmp("hidden", &zType[i], 6)
158213 && (i==0 || zType[i-1]==' ')
158214 && (zType[i+6]=='\0' || zType[i+6]==' ')
158221 int nDel = 6 + (zType[i+6] ? 1 : 0);
158225 if( zType[i]=='\0' && i>0 ){
158227 zType[i-1] = '\0';
158263 zMod = pTab->u.vtab.azArg[0];
158267 const char *zModule = pTab->u.vtab.azArg[0];
158271 char *zErr = 0;
158290 if( (db->nVTrans%ARRAY_INCR)==0 ){
158298 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
158333 zMod = pTab->u.vtab.azArg[0];
158340 if( pMod==0 || pMod->pModule->xCreate==0 || pMod->pModule->xDestroy==0 ){
158372 static const u8 aKeyword[] = { TK_CREATE, TK_TABLE, 0 };
158375 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
158385 for(i=0; aKeyword[i]; i++){
158386 int tokenType = 0;
158413 assert( db->init.busy==0 );
158415 db->init.busy = 0;
158418 assert( sParse.pNewTable!=0 );
158421 assert( sParse.zErrMsg==0 );
158430 pNew->nCol = 0;
158431 pNew->aCol = 0;
158432 assert( pTab->pIndex==0 );
158433 assert( HasRowid(pNew) || sqlite3PrimaryKeyIndex(pNew)!=0 );
158435 && pCtx->pVTable->pMod->pModule->xUpdate!=0
158438 /* WITHOUT ROWID virtual tables must either be read-only (xUpdate==0)
158444 assert( pIdx->pNext==0 );
158446 pNew->pIndex = 0;
158453 (sParse.zErrMsg ? "%s" : 0), sParse.zErrMsg);
158466 assert( (rc&0xff)==rc );
158484 if( ALWAYS(pTab!=0)
158486 && ALWAYS(pTab->u.vtab.p!=0)
158492 if( p->pVtab->nRef>0 ){
158498 if( xDestroy==0 ) xDestroy = p->pMod->pModule->xDisconnect;
158499 assert( xDestroy!=0 );
158504 assert( pTab->u.vtab.p==p && p->pNext==0 );
158505 p->pVtab = 0;
158506 pTab->u.vtab.p = 0;
158527 db->aVTrans = 0;
158528 for(i=0; i<db->nVTrans; i++){
158536 pVTab->iSavepoint = 0;
158540 db->nVTrans = 0;
158556 db->aVTrans = 0;
158557 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
158560 if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
158616 for(i=0; i<db->nVTrans; i++){
158662 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
158715 void (*xSFunc)(sqlite3_context*,int,sqlite3_value**) = 0;
158716 void *pArg = 0;
158718 int rc = 0;
158721 if( NEVER(pExpr==0) ) return pDef;
158725 if( NEVER(pTab==0) ) return pDef;
158728 assert( pVtab!=0 );
158729 assert( pVtab->pModule!=0 );
158731 if( pMod->xFindFunction==0 ) return pDef;
158743 for(i=0; pDef->zName[i]; i++){
158750 if( rc==0 ){
158758 if( pNew==0 ){
158782 for(i=0; i<pToplevel->nVtabLock; i++){
158785 n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
158813 char *zErr = 0;
158817 if( pModule->xCreate!=0 && pModule->xCreate!=pModule->xConnect ) return 0;
158819 if( pTab==0 ) return 0;
158821 if( pTab->zName==0 ){
158823 return 0;
158828 pTab->pSchema = db->aDb[0].pSchema;
158829 assert( pTab->u.vtab.nArg==0 );
158833 addModuleArgument(pParse, pTab, 0);
158850 if( pTab!=0 ){
158856 pMod->pEpoTab = 0;
158898 assert( p->pTab==0 || IsVirtual(p->pTab) );
159025 ** the loop nested order, with WhereInfo.a[0] being the outer loop and
159090 u8 iSortIdx; /* Sorting index number. 0==None */
159208 ** categories, then eOperator==0. The WhereTerm.pExpr field is still set
159212 ** When eOperator!=0, prereqRight and prereqAll record sets of cursor numbers,
159220 ** beginning with 0 in order to make the best possible use of the available
159222 ** would be mapped into integers 0 through 7.
159243 WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */
159244 WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */
159253 #define TERM_DYNAMIC 0x0001 /* Need to call sqlite3ExprDelete(db, pExpr) */
159254 #define TERM_VIRTUAL 0x0002 /* Added by the optimizer. Do not code */
159255 #define TERM_CODED 0x0004 /* This term is already coded */
159256 #define TERM_COPIED 0x0008 /* Has a child */
159257 #define TERM_ORINFO 0x0010 /* Need to free the WhereTerm.u.pOrInfo object */
159258 #define TERM_ANDINFO 0x0020 /* Need to free the WhereTerm.u.pAndInfo obj */
159259 #define TERM_OK 0x0040 /* Used during OR-clause processing */
159260 #define TERM_VNULL 0x0080 /* Manufactured x>NULL or x<=NULL term */
159261 #define TERM_LIKEOPT 0x0100 /* Virtual terms from the LIKE optimization */
159262 #define TERM_LIKECOND 0x0200 /* Conditionally this LIKE operator term */
159263 #define TERM_LIKE 0x0400 /* The original LIKE operator */
159264 #define TERM_IS 0x0800 /* Term.pExpr is an IS operator */
159265 #define TERM_VARSELECT 0x1000 /* Term.pExpr contains a correlated sub-query */
159266 #define TERM_HEURTRUTH 0x2000 /* Heuristic truthProb used */
159268 # define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */
159270 # define TERM_HIGHTRUTH 0 /* Only used with STAT4 */
159272 #define TERM_SLICE 0x8000 /* One slice of a row-value/vector comparison */
159343 ** clause, the cursor numbers might not begin with 0 and they might
159347 ** with 0.
159354 ** would map those cursor numbers into bits 0 through 5.
159357 ** above, the mapping might go like this: 4->3, 5->1, 8->2, 29->0,
159360 ** numbers all get mapped into bit numbers that begin with 0 and contain
159388 #define SQLITE_BLDF1_INDEXED 0x0001 /* An index is used */
159389 #define SQLITE_BLDF1_UNIQUE 0x0002 /* All keys of a UNIQUE index used */
159391 #define SQLITE_BLDF2_2NDPASS 0x0004 /* Second builder pass needed */
159510 # define sqlite3WhereExplainOneScan(u,v,w,x) 0
159511 # define sqlite3WhereExplainBloomFilter(u,v,w) 0
159519 int addrExplain /* Address of OP_Explain (or 0) */
159566 #define WO_IN 0x0001
159567 #define WO_EQ 0x0002
159572 #define WO_AUX 0x0040 /* Op useful to virtual tables only */
159573 #define WO_IS 0x0080
159574 #define WO_ISNULL 0x0100
159575 #define WO_OR 0x0200 /* Two or more OR-connected terms */
159576 #define WO_AND 0x0400 /* Two or more AND-connected terms */
159577 #define WO_EQUIV 0x0800 /* Of the form A==B, both columns */
159578 #define WO_NOOP 0x1000 /* This term does not restrict search space */
159579 #define WO_ROWVAL 0x2000 /* A row-value term */
159581 #define WO_ALL 0x3fff /* Mask of all possible WO_* values */
159582 #define WO_SINGLE 0x01ff /* Mask of all non-compound WO_* values */
159589 #define WHERE_COLUMN_EQ 0x00000001 /* x=EXPR */
159590 #define WHERE_COLUMN_RANGE 0x00000002 /* x<EXPR and/or x>EXPR */
159591 #define WHERE_COLUMN_IN 0x00000004 /* x IN (...) */
159592 #define WHERE_COLUMN_NULL 0x00000008 /* x IS NULL */
159593 #define WHERE_CONSTRAINT 0x0000000f /* Any of the WHERE_COLUMN_xxx values */
159594 #define WHERE_TOP_LIMIT 0x00000010 /* x<EXPR or x<=EXPR constraint */
159595 #define WHERE_BTM_LIMIT 0x00000020 /* x>EXPR or x>=EXPR constraint */
159596 #define WHERE_BOTH_LIMIT 0x00000030 /* Both x>EXPR and x<EXPR */
159597 #define WHERE_IDX_ONLY 0x00000040 /* Use index only - omit table */
159598 #define WHERE_IPK 0x00000100 /* x is the INTEGER PRIMARY KEY */
159599 #define WHERE_INDEXED 0x00000200 /* WhereLoop.u.btree.pIndex is valid */
159600 #define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
159601 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
159602 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
159603 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
159604 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
159605 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
159606 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
159607 #define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */
159608 #define WHERE_IN_EARLYOUT 0x00040000 /* Perhaps quit IN loops early */
159609 #define WHERE_BIGNULL_SORT 0x00080000 /* Column nEq of index is BIGNULL */
159610 #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
159611 #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
159612 #define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */
159613 #define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */
159614 #define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */
159615 #define WHERE_COROUTINE 0x02000000 /* Implemented by co-routine.
159617 #define WHERE_EXPRIDX 0x04000000 /* Uses an index-on-expressions */
159658 for(i=0; i<nTerm; i++){
159667 for(i=0; i<nTerm; i++){
159694 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
159696 for(i=0; i<nEq; i++){
159747 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
159748 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
159754 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
159755 const char *zFmt = 0;
159758 assert( pLoop->u.btree.pIndex!=0 );
159779 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
159781 #if 0 /* Better output, but breaks many tests */
159783 const char *zRowid = pTab->iPKey>=0 ? pTab->aCol[pTab->iPKey].zCnName:
159803 else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
159806 pLoop->u.vtab.bIdxNumHex ? "0x%x:%s" : "%d:%s",
159827 assert( pOp->p4type==P4_DYNAMIC || pOp->p4.z==0 );
159850 int ret = 0;
159855 if( (pLevel->pWLoop->wsFlags & WHERE_MULTI_OR)==0
159856 && (wctrlFlags & WHERE_OR_SUBCLAUSE)==0
159884 int ret = 0;
159900 if( pTab->iPKey>=0 ){
159915 pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
159917 sqlite3VdbeScanStatus(v, sqlite3VdbeCurrentAddr(v)-1, 0, 0, 0, 0);
159929 ** If argument addrExplain is not 0, it must be the address of an
159936 int addrExplain /* Address of OP_Explain (or 0) */
159939 const char *zObj = 0;
159942 int viaCoroutine = 0;
159944 if( (wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){
159954 if( viaCoroutine==0 ){
159955 if( (wsFlags & (WHERE_MULTI_OR|WHERE_AUTO_INDEX))==0 ){
160019 int nLoop = 0;
160020 assert( pTerm!=0 );
160021 while( (pTerm->wtFlags & TERM_CODED)==0
160022 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_OuterON))
160023 && (pLevel->notReady & pTerm->prereqAll)==0
160025 if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
160031 if( (sqlite3WhereTrace & 0x4001)==0x4001 ){
160036 if( pTerm->iParent<0 ) break;
160038 assert( pTerm!=0 );
160040 if( pTerm->nChild!=0 ) break;
160058 if( zAff==0 ){
160062 assert( v!=0 );
160068 while( n>0 && zAff[0]<=SQLITE_AFF_BLOB ){
160078 if( n>0 ){
160079 sqlite3VdbeAddOp4(v, OP_Affinity, base, n, 0, zAff, n);
160099 for(i=0; i<n; i++){
160126 if( pOrderBy==0 ) return;
160127 for(i=0; i<pOrderBy->nExpr; i++){
160129 if( t==0 ) continue;
160130 for(j=0; j<pEList->nExpr; j++){
160137 pOrderBy->a[i].u.x.iOrderByCol = 0;
160181 pNew = sqlite3ExprDup(db, pX, 0);
160182 if( db->mallocFailed==0 ){
160185 ExprList *pOrigLhs = 0; /* Original unmodified LHS */
160186 ExprList *pRhs = 0; /* New RHS after modifications */
160187 ExprList *pLhs = 0; /* New LHS after mods */
160192 assert( pNew->pLeft!=0 );
160200 assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 );
160202 if( NEVER(pOrigRhs->a[iField].pExpr==0) ){
160206 pOrigRhs->a[iField].pExpr = 0;
160209 assert( pOrigLhs->a[iField].pExpr!=0 );
160211 pOrigLhs->a[iField].pExpr = 0;
160226 Expr *p = pLhs->a[0].pExpr;
160227 pLhs->a[0].pExpr = 0;
160236 assert( pRhs!=0 || db->mallocFailed );
160240 for(i=0; i<pRhs->nExpr; i++) pRhs->a[i].u.x.iOrderByCol = 0;
160243 #if 0
160245 sqlite3TreeViewExpr(0, pX, 0);
160247 sqlite3TreeViewExpr(0, pNew, 0);
160282 int nEq = 0;
160283 int *aiMap = 0;
160285 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0
160286 && pLoop->u.btree.pIndex!=0
160289 testcase( iEq==0 );
160295 for(i=0; i<iEq; i++){
160302 assert( pLoop->aLTerm[i]!=0 );
160306 iTab = 0;
160308 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
160314 eType = sqlite3FindInIndex(pParse, pXMod, IN_INDEX_LOOP, 0, aiMap, &iTab);
160323 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
160327 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
160329 if( pLevel->u.in.nIn==0 ){
160332 if( iEq>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0 ){
160341 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
160344 int iMap = 0; /* Index in aiMap[] */
160352 int iCol = aiMap ? aiMap[iMap++] : 0;
160359 if( iEq>0 ){
160363 pIn->nPrefix = 0;
160371 testcase( iEq>0
160372 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0
160373 && (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 );
160374 if( iEq>0
160375 && (pLoop->wsFlags & (WHERE_IN_SEEKSCAN|WHERE_VIRTUALTABLE))==0
160377 sqlite3VdbeAddOp3(v, OP_SeekHit, pLevel->iIdxCur, 0, iEq);
160380 pLevel->u.in.nIn = 0;
160414 assert( iTarget>0 );
160419 sqlite3VdbeAddOp2(pParse->pVdbe, OP_Null, 0, iReg);
160437 if( (pLevel->pWLoop->wsFlags & WHERE_TRANSCONS)==0
160438 || (pTerm->eOperator & WO_EQUIV)==0
160459 ** of nEq including 0. If nEq==0, this routine is nearly a no-op.
160463 ** The nExtraReg parameter is 0 or 1. It is 0 if all WHERE clause constraints
160511 assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
160515 assert( pIdx!=0 );
160524 assert( zAff!=0 || pParse->db->mallocFailed );
160528 sqlite3VdbeAddOp3(v, OP_Null, 0, regBase, regBase+nSkip-1);
160530 VdbeCoverageIf(v, bRev==0);
160531 VdbeCoverageIf(v, bRev!=0);
160534 assert( pLevel->addrSkip==0 );
160536 iIdxCur, 0, regBase, nSkip);
160537 VdbeCoverageIf(v, bRev==0);
160538 VdbeCoverageIf(v, bRev!=0);
160540 for(j=0; j<nSkip; j++){
160549 assert( zAff==0 || (int)strlen(zAff)>=nEq );
160553 assert( pTerm!=0 );
160555 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
160556 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
160575 }else if( (pTerm->eOperator & WO_ISNULL)==0 ){
160577 if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
160581 if( pParse->nErr==0 ){
160582 assert( pParse->db->mallocFailed==0 );
160621 assert( pLevel->iLikeRepCntr>0 );
160623 assert( pOp!=0 );
160642 int iIdxCur; /* Cursor for the index, if pIdx!=0. Unused otherwise */
160654 assert( pHint->pIdx!=0 );
160657 && sqlite3TableColumnToIndex(pHint->pIdx, pExpr->iColumn)<0
160677 ** CASE WHEN col THEN 0 ELSE 1 END
160688 if( 0==sqlite3IsLikeFunction(pWalker->pParse->db, pExpr, &d1, d2) ){
160711 ** know because CCurHint.pIdx!=0) then transform the TK_COLUMN into
160724 }else if( pHint->pIdx!=0 ){
160727 assert( pExpr->iColumn>=0 );
160754 Expr *pExpr = 0;
160769 memset(&sWalker, 0, sizeof(sWalker));
160773 for(i=0; i<pWC->nBase; i++){
160805 sWalker.eCode = 0;
160817 if( pLoop->u.btree.nEq==0 && pTerm!=pEndRange ){
160818 for(j=0; j<pLoop->nLTerm && pLoop->aLTerm[j]!=pTerm; j++){}
160827 if( sHint.pIdx!=0 ){
160828 sWalker.eCode = 0;
160835 pExpr = sqlite3ExprAnd(pParse, pExpr, sqlite3ExprDup(db, pTerm->pExpr, 0));
160837 if( pExpr!=0 ){
160839 if( pParse->nErr==0 ) sqlite3WalkExpr(&sWalker, pExpr);
160841 (sHint.pIdx ? sHint.iIdxCur : sHint.iTabCur), 0, 0,
160870 ** to 0. The OP_Column opcode can check this array to see if the column it
160884 assert( iIdxCur>0 );
160888 sqlite3VdbeAddOp3(v, OP_DeferredSeek, iIdxCur, 0, iCur);
160896 ai[0] = pTab->nCol;
160897 for(i=0; i<pIdx->nColumn-1; i++){
160903 if( x1>=0 ) ai[x2+1] = i+1;
160920 assert( nReg>0 );
160937 for(i=0; i<nReg; i++){
160965 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
160969 if( sqlite3ExprCompare(0, pExpr, pTruth, iTabCur)==0 ){
161000 if( pLevel->regFilter==0 ) continue;
161005 assert( pLevel->addrBrk==0 );
161008 WhereTerm *pTerm = pLoop->aLTerm[0];
161010 assert( pTerm!=0 );
161011 assert( pTerm->pExpr!=0 );
161014 regRowid = codeEqualityTerm(pParse, pTerm, pLevel, 0, 0, regRowid);
161026 assert( (pLoop->wsFlags & WHERE_COLUMN_IN)==0 );
161027 r1 = codeAllEqualityTerms(pParse,pLevel,0,0,&zStartAff);
161034 pLevel->regFilter = 0;
161035 pLevel->addrBrk = 0;
161046 && pLoop->nSkip==0
161050 for(ii=0; ii<pLoop->u.btree.nEq; ii++){
161052 return 0;
161057 return 0;
161084 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
161085 int iReleaseReg = 0; /* Temp register to free before returning */
161086 Index *pIdx = 0; /* Index used by loop (if any) */
161098 #if WHERETRACE_ENABLED /* 0x4001 */
161099 if( sqlite3WhereTrace & 0x1 ){
161102 if( sqlite3WhereTrace & 0x1000 ){
161106 if( (sqlite3WhereTrace & 0x4001)==0x4001 ){
161107 if( iLevel==0 ){
161109 sqlite3TreeViewExpr(0, pWInfo->pWhere, 0);
161134 || pLevel->iFrom>0 || (pTabItem[0].fg.jointype & JT_LEFT)==0
161136 if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
161138 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
161144 for(j=iLevel; j>0; j--){
161154 assert( pTabItem->fg.isSubquery && pTabItem->u4.pSubq!=0 );
161157 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pSubq->addrFillSub);
161165 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
161175 for(j=0; j<nConstraint; j++){
161178 if( NEVER(pTerm==0) ) continue;
161196 assert( pWInfo->pSelect!=0 );
161197 assert( pWInfo->pSelect->iOffset>0 );
161198 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWInfo->pSelect->iOffset);
161212 pLoop->u.vtab.needFree = 0;
161215 if( db->mallocFailed ) pLoop->u.vtab.idxStr = 0;
161219 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
161221 for(j=0; j<nConstraint; j++){
161227 if( (pTerm->eOperator & WO_IN)!=0
161228 && (SMASKBIT32(j) & pLoop->u.vtab.mHandleIn)==0
161241 for(iIn=0; ALWAYS(iIn<pLevel->u.in.nIn); iIn++){
161255 pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0);
161259 assert( pLeft!=0 );
161260 if( iFld>0 ){
161268 pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0);
161275 pCompare->pLeft = 0;
161283 ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems
161291 if( (pLoop->wsFlags & WHERE_IPK)!=0
161292 && (pLoop->wsFlags & (WHERE_COLUMN_IN|WHERE_COLUMN_EQ))!=0
161300 pTerm = pLoop->aLTerm[0];
161301 assert( pTerm!=0 );
161302 assert( pTerm->pExpr!=0 );
161305 iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
161319 }else if( (pLoop->wsFlags & WHERE_IPK)!=0
161320 && (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0
161326 int memEndValue = 0;
161329 j = 0;
161330 pStart = pEnd = 0;
161333 assert( pStart!=0 || pEnd!=0 );
161358 assert( (pStart->wtFlags & TERM_VNULL)==0 );
161361 assert( pX!=0 );
161370 op = aMoveOp[((pX->op - TK_GT - 1) & 0x3) | 0x1];
161389 VdbeCoverageIf(v, bRev==0);
161390 VdbeCoverageIf(v, bRev!=0);
161395 assert( pX!=0 );
161396 assert( (pEnd->wtFlags & TERM_VNULL)==0 );
161401 if( 0==sqlite3ExprIsVector(pX->pRight)
161408 if( 0==sqlite3ExprIsVector(pX->pRight) ){
161416 assert( pLevel->p5==0 );
161460 0,
161461 0,
161470 OP_IdxGE, /* 0: (end_constraints && !bRev && !endEq) */
161479 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
161480 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
161486 int nExtraReg = 0; /* Number of extra registers needed */
161489 char *zEndAff = 0; /* Affinity for end of range constraint */
161490 u8 bSeekPastNull = 0; /* True to seek past initial nulls */
161491 u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
161493 int regBignull = 0; /* big-null flag register */
161494 int addrSeekScan = 0; /* Opcode of the OP_SeekScan, if any */
161508 assert( (pRangeStart->wtFlags & TERM_LIKEOPT)==0 ||
161509 (pLoop->wsFlags & WHERE_TOP_LIMIT)!=0 );
161515 if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
161516 assert( pRangeStart!=0 ); /* LIKE opt constraints */
161526 assert( (bRev & ~1)==0 );
161531 if( pRangeStart==0 ){
161533 if( (j>=0 && pIdx->pTable->aCol[j].notNull==0) || j==XN_EXPR ){
161538 assert( pRangeEnd==0 || (pRangeEnd->wtFlags & TERM_VNULL)==0 );
161547 if( (pLoop->wsFlags & (WHERE_TOP_LIMIT|WHERE_BTM_LIMIT))==0
161548 && (pLoop->wsFlags & WHERE_BIGNULL_SORT)!=0
161550 assert( bSeekPastNull==0 && nExtraReg==0 && nBtm==0 && nTop==0 );
161551 assert( pRangeEnd==0 && pRangeStart==0 );
161552 testcase( pLoop->nSkip>0 );
161557 sqlite3VdbeAddOp2(v, OP_Integer, 0, regBignull);
161572 if( iLevel>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)!=0 ){
161584 assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
161590 testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
161591 testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
161592 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
161593 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_GE)!=0 );
161596 start_constraints = pRangeStart || nEq>0;
161604 if( (pRangeStart->wtFlags & TERM_VNULL)==0
161615 if( sqlite3ExprIsVector(pRight)==0 ){
161620 bSeekPastNull = 0;
161622 startEq = 0;
161623 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
161627 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
161632 if( pLoop->nSkip>0 && nConstraint==pLoop->nSkip ){
161649 assert( op!=0 );
161650 if( (pLoop->wsFlags & WHERE_IN_SEEKSCAN)!=0 && op==OP_SeekGE ){
161651 assert( regBignull==0 );
161661 (pIdx->aiRowLogEst[0]+9)/10);
161665 addrSeekScan = 0;
161678 assert( bSeekPastNull==0 || bStopAtNull==0 );
161683 sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
161700 assert( pLevel->p2==0 );
161703 assert( addrSeekScan==0 );
161706 if( (pRangeEnd->wtFlags & TERM_VNULL)==0
161721 if( sqlite3ExprIsVector(pRight)==0 ){
161727 if( regBignull==0 ){
161728 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
161729 endEq = 0;
161760 assert( nConstraint+bSeekPastNull>0 );
161773 if( (pLoop->wsFlags & WHERE_IN_EARLYOUT)!=0 ){
161778 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
161779 && (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))==0;
161787 for(j=0; j<pPk->nKeyCol; j++){
161795 if( pLevel->iLeftJoin==0 ){
161804 if( pIdx->pPartIdxWhere && pLevel->pRJ==0 ){
161812 assert( (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))==0 );
161817 || (pLevel->u.in.nIn && regBignull==0 && whereLoopIsOneRow(pLoop))
161826 pLevel->p3 = (pLoop->wsFlags&WHERE_UNQ_WANTED)!=0 ? 1:0;
161827 if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
161830 assert( pLevel->p5==0 );
161832 if( omitTable ) pIdx = 0;
161882 Index *pCov = 0; /* Potential covering index (or NULL) */
161886 int regRowset = 0; /* Register for RowSet object */
161887 int regRowid = 0; /* Register holding rowid */
161890 int untestedTerms = 0; /* Some terms not completely tested */
161892 Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
161895 pTerm = pLoop->aLTerm[0];
161896 assert( pTerm!=0 );
161898 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
161904 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
161912 if( pOrTab==0 ) return notReady;
161936 if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
161939 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowset);
161948 iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
161980 for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
161986 if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){
161989 if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
161991 pExpr = sqlite3ExprDup(db, pExpr, 0);
161995 /* The extra 0x10000 bit on the opcode is masked off and does not
162000 pAndExpr = sqlite3PExpr(pParse, TK_AND|0x10000, 0, pAndExpr);
162009 for(ii=0; ii<pOrWc->nTerm; ii++){
162011 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
162015 int jmp1 = 0; /* Address of jump operation */
162016 testcase( (pTabItem[0].fg.jointype & JT_LEFT)!=0
162019 pDelete = pOrExpr = sqlite3ExprDup(db, pOrExpr, 0);
162030 WHERETRACE(0xffffffff, ("Subplan for OR-clause:\n"));
162031 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, 0,
162037 pParse, pOrTab, &pSubWInfo->a[0], 0
162039 sqlite3WhereAddScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain);
162046 if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
162050 jmp1 = sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset, 0,
162061 for(iPk=0; iPk<nPk; iPk++){
162078 jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, regRowset, 0, r, nPk);
162081 if( iSet>=0 ){
162119 pSubLoop = pSubWInfo->a[0].pWLoop;
162120 assert( (pSubLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
162121 if( (pSubLoop->wsFlags & WHERE_INDEXED)!=0
162122 && (ii==0 || pSubLoop->u.btree.pIndex==pCov)
162125 assert( pSubWInfo->a[0].iIdxCur==iCovCur );
162128 pCov = 0;
162143 assert( (pLoop->wsFlags & WHERE_MULTI_OR)!=0 );
162144 assert( (pLoop->wsFlags & WHERE_IN_ABLE)==0 );
162148 pAndExpr->pLeft = 0;
162174 assert( bRev==0 || bRev==1 );
162180 codeCursorHint(pTabItem, pWInfo, pLevel, 0);
162184 VdbeCoverageIf(v, bRev==0);
162185 VdbeCoverageIf(v, bRev!=0);
162216 int iNext = 0; /* Next value for iLoop */
162217 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
162219 int skipLikeAddr = 0;
162223 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
162224 testcase( pWInfo->untestedTerms==0
162225 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
162230 assert( pE!=0 );
162252 if( iNext==0 ) iNext = 3;
162256 if( (pTerm->wtFlags & TERM_LIKECOND)!=0 ){
162266 if( x>0 ){
162269 VdbeCoverageIf(v, (x&1)==0);
162273 #ifdef WHERETRACE_ENABLED /* 0xffffffff */
162278 if( sqlite3WhereTrace & 0x4000 ){
162288 }while( iLoop>0 );
162298 for(pTerm=pWC->a, j=pWC->nBase; j>0; j--, pTerm++){
162302 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue;
162303 if( (pTerm->eOperator & WO_EQUIV)==0 ) continue;
162307 #ifdef WHERETRACE_ENABLED /* 0x4001 */
162308 if( (sqlite3WhereTrace & 0x4001)==0x4001 ){
162314 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
162315 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
162317 WO_EQ|WO_IN|WO_IS, 0);
162318 if( pAlt==0 ) continue;
162343 int jmp1 = 0;
162361 for(iPk=0; iPk<nPk; iPk++){
162366 jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, 0, r+1, nPk);
162371 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pRJ->regBloom, 0, r+1, nPk);
162384 if( pLevel->pRJ==0 ){
162397 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pRJ->regReturn);
162408 for(pTerm=pWC->a, j=0; j<pWC->nBase; j++, pTerm++){
162412 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
162423 #if WHERETRACE_ENABLED /* 0x4001 */
162424 if( sqlite3WhereTrace & 0x4000 ){
162429 if( sqlite3WhereTrace & 0x1 ){
162449 Expr *pSubWhere = 0;
162456 Bitmask mAll = 0;
162462 for(k=0; k<iLevel; k++){
162470 assert( pRight->fg.isSubquery && pRight->u4.pSubq!=0 );
162472 assert( pSubq->pSelect!=0 && pSubq->pSelect->pEList!=0 );
162474 v, OP_Null, 0, pSubq->regResult,
162484 if( (pTabItem->fg.jointype & JT_LTORJ)==0 ){
162486 for(k=0; k<pWC->nTerm; k++){
162488 if( (pTerm->wtFlags & (TERM_VIRTUAL|TERM_SLICE))!=0
162496 sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
162502 memcpy(&pFrom->a[0], pTabItem, sizeof(SrcItem));
162503 pFrom->a[0].fg.jointype = 0;
162506 pSubWInfo = sqlite3WhereBegin(pParse, pFrom, pSubWhere, 0, 0, 0,
162507 WHERE_RIGHT_JOIN, 0);
162523 for(iPk=0; iPk<nPk; iPk++){
162528 jmp = sqlite3VdbeAddOp4Int(v, OP_Filter, pRJ->regBloom, 0, r, nPk);
162538 assert( pParse->withinRJSubrtn>0 );
162588 ** 0 is returned if the new WhereTerm could not be added due to a memory
162610 pWC->a = sqlite3WhereMalloc(pWC->pWInfo, sizeof(pWC->a[0])*pWC->nSlot*2 );
162611 if( pWC->a==0 ){
162616 return 0;
162618 memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm);
162622 if( (wtFlags & TERM_VIRTUAL)==0 ) pWC->nBase = pWC->nTerm;
162632 memset(&pTerm->eOperator, 0,
162650 if( op>TK_GE ) return 0;
162676 return 0;
162686 assert( (WO_EQ<<(op-TK_EQ)) < 0x7fff );
162728 const u8 *z = 0; /* String on RHS of LIKE operator */
162735 sqlite3_value *pVal = 0;
162740 return 0;
162743 if( *pnoCase ) return 0;
162749 pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
162751 if( op==TK_VARIABLE && (db->flags & SQLITE_EnableQPSG)==0 ){
162771 cnt = 0;
162772 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
162774 if( c==wc[3] && z[cnt]>0 && z[cnt]<0x80 ){
162776 }else if( c>=0x80 ){
162778 if( c==0xff || sqlite3Utf8Read(&z2)==0xfffd /* bad utf-8 */
162791 ** an (illegal 0xff) character, or (3) the pattern does not consist of
162797 if( (cnt>1 || (cnt>0 && z[0]!=wc[3])) && ALWAYS(255!=(u8)z[cnt-1]) ){
162801 *pisComplete = c==wc[0] && z[cnt+1]==0 && ENC(db)!=SQLITE_UTF16LE;
162810 zNew[cnt] = 0;
162811 for(iFrom=iTo=0; iFrom<cnt; iFrom++){
162815 zNew[iTo] = 0;
162816 assert( iTo>0 );
162829 ** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
162840 if( isNum<=0 ){
162841 if( iTo==1 && zNew[0]=='-' ){
162849 if( isNum>0 ){
162852 return 0;
162873 sqlite3VdbeChangeP3(v, sqlite3VdbeCurrentAddr(v)-1, 0);
162878 z = 0;
162882 rc = (z!=0);
162914 ** If the expression matches none of the patterns above, return 0.
162919 unsigned char *peOp2, /* OUT: 0 for MATCH, or else an op2 value */
162939 if( pList==0 || pList->nExpr!=2 ){
162940 return 0;
162951 assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) );
162953 for(i=0; i<ArraySize(aOp); i++){
162955 if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
162957 *ppRight = pList->a[0].pExpr;
162974 pCol = pList->a[0].pExpr;
162976 assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) );
162983 assert( pVtab!=0 );
162984 assert( pVtab->pModule!=0 );
162987 if( pMod->xFindFunction!=0 ){
163003 return 0;
163005 int res = 0;
163008 assert( pLeft->op!=TK_COLUMN || (ExprUseYTab(pLeft) && pLeft->y.pTab!=0) );
163012 assert( pRight==0 || pRight->op!=TK_COLUMN
163013 || (ExprUseYTab(pRight) && pRight->y.pTab!=0) );
163025 return 0;
163051 ** a conjunction, then return just pTerm when N==0. If N is exceeds
163056 return N==0 ? pTerm : 0;
163061 return 0;
163097 if( (pOne->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
163098 if( (pTwo->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
163101 assert( pOne->pExpr->pLeft!=0 && pOne->pExpr->pRight!=0 );
163102 assert( pTwo->pExpr->pLeft!=0 && pTwo->pExpr->pRight!=0 );
163103 if( sqlite3ExprCompare(0,pOne->pExpr->pLeft, pTwo->pExpr->pLeft, -1) ) return;
163104 if( sqlite3ExprCompare(0,pOne->pExpr->pRight, pTwo->pExpr->pRight,-1) )return;
163106 if( (eOp & (eOp-1))!=0 ){
163115 pNew = sqlite3ExprDup(db, pOne->pExpr, 0);
163116 if( pNew==0 ) return;
163233 assert( (pTerm->wtFlags & (TERM_DYNAMIC|TERM_ORINFO|TERM_ANDINFO))==0 );
163236 if( pOrInfo==0 ) return;
163239 memset(pOrWc->aStatic, 0, sizeof(pOrWc->aStatic));
163249 indexable = ~(Bitmask)0;
163250 chngToIN = ~(Bitmask)0;
163251 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0 && indexable; i--, pOrTerm++){
163252 if( (pOrTerm->eOperator & WO_SINGLE)==0 ){
163254 assert( (pOrTerm->wtFlags & (TERM_ANDINFO|TERM_ORINFO))==0 );
163255 chngToIN = 0;
163261 Bitmask b = 0;
163267 memset(pAndWC->aStatic, 0, sizeof(pAndWC->aStatic));
163273 for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){
163295 if( (pOrTerm->eOperator & WO_EQ)==0 ){
163296 chngToIN = 0;
163317 int iOne = 0;
163319 while( (pOne = whereNthSubterm(&pOrWc->a[0],iOne++))!=0 ){
163320 int iTwo = 0;
163322 while( (pTwo = whereNthSubterm(&pOrWc->a[1],iTwo++))!=0 ){
163333 ** chngToIN will hold either 0, 1, or 2 bits. The 0-bit case means
163350 int okToChngToIN = 0; /* True if the conversion to IN is valid */
163353 int j = 0; /* Loop counter */
163361 for(j=0; j<2 && !okToChngToIN; j++){
163362 Expr *pLeft = 0;
163364 for(i=pOrWc->nTerm-1; i>=0; i--, pOrTerm++){
163374 pOrTerm->leftCursor))==0 ){
163384 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
163390 if( i<0 ){
163403 for(; i>=0 && okToChngToIN; i--, pOrTerm++){
163405 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
163411 okToChngToIN = 0;
163420 if( affRight!=0 && affRight!=affLeft ){
163421 okToChngToIN = 0;
163435 ExprList *pList = 0; /* The RHS of the IN operator */
163436 Expr *pLeft = 0; /* The LHS of the IN operator */
163439 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
163440 if( (pOrTerm->wtFlags & TERM_OK)==0 ) continue;
163442 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
163445 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
163449 assert( pLeft!=0 );
163450 pDup = sqlite3ExprDup(db, pLeft, 0);
163451 pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
163458 testcase( idxNew==0 );
163483 ** This is an optimization. No harm comes from returning 0. But if 1 is
163489 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */
163490 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */
163491 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* (3) */
163492 assert( pSrc!=0 );
163495 && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0
163497 return 0; /* (4) */
163504 return 0; /* (5) */
163510 return 0; /* (6) */
163521 Bitmask mask = 0;
163529 if( ALWAYS(pSrc!=0) ){
163531 for(i=0; i<pSrc->nSrc; i++){
163535 if( pSrc->a[i].fg.isUsing==0 ){
163552 ** FALSE (0) if not. If TRUE is returned, also set aiCurCol[0] to the cursor
163573 if( pIdx->aColExpr==0 ) continue;
163574 for(i=0; i<pIdx->nKeyCol; i++){
163577 if( sqlite3ExprCompareSkip(pExpr,pIdx->aColExpr->a[i].pExpr,iCur)==0
163578 && !sqlite3ExprIsConstant(0,pIdx->aColExpr->a[i].pExpr)
163580 aiCurCol[0] = iCur;
163587 return 0;
163605 pExpr = pExpr->x.pList->a[0].pExpr;
163609 aiCurCol[0] = pExpr->iTable;
163614 for(i=0; i<pFrom->nSrc; i++){
163622 return 0;
163655 Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */
163656 Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */
163657 int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */
163658 int noCase = 0; /* uppercase equivalent to lowercase */
163662 unsigned char eOp2 = 0; /* op2 value for LIKE/REGEXP/GLOB */
163672 assert( pExpr!=0 ); /* Because malloc() has not failed */
163674 pMaskSet->bVarSelect = 0;
163678 assert( pExpr->pRight==0 );
163688 if( pExpr->pLeft==0
163690 || pExpr->x.pList!=0
163702 sqlite3TreeViewExpr(0,pExpr,0);
163703 assert( 0 );
163724 if( ALWAYS(pSrc->nSrc>0) && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
163734 pTerm->eOperator = 0;
163739 u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
163741 if( pTerm->u.x.iField>0 ){
163749 pTerm->leftCursor = aiCurCol[0];
163750 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
163761 u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
163762 assert( pTerm->u.x.iField==0 );
163763 if( pTerm->leftCursor>=0 ){
163765 pDup = sqlite3ExprDup(db, pExpr, 0);
163771 if( idxNew==0 ) return;
163777 assert( pWInfo->pTabList!=0 );
163787 pNew->leftCursor = aiCurCol[0];
163788 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
163797 && 0==sqlite3ExprCanBeNull(pLeft)
163803 pTerm->prereqAll = 0;
163804 pTerm->eOperator = 0;
163830 assert( pList!=0 );
163832 for(i=0; i<2; i++){
163836 sqlite3ExprDup(db, pExpr->pLeft, 0),
163837 sqlite3ExprDup(db, pList->a[i].pExpr, 0));
163840 testcase( idxNew==0 );
163866 && pExpr->pLeft->iColumn>=0
163875 sqlite3ExprDup(db, pLeft, 0),
163876 sqlite3ExprAlloc(db, TK_NULL, 0, 0));
163882 pNewTerm->prereqRight = 0;
163924 pStr2 = sqlite3ExprDup(db, pStr1, 0);
163925 assert( pStr1==0 || !ExprHasProperty(pStr1, EP_IntValue) );
163926 assert( pStr2==0 || !ExprHasProperty(pStr2, EP_IntValue) );
163937 for(i=0; (c = pStr1->u.zToken[i])!=0; i++){
163953 if( *pC=='A'-1 ) isComplete = 0;
163958 while( *pC==0xBF && pC>(u8*)pStr2->u.zToken ){
163959 *pC = 0x80;
163962 assert( *pC!=0xFF ); /* isLikeOrGlob() guarantees this */
163966 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
163972 testcase( idxNew1==0 );
163973 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
163979 testcase( idxNew2==0 );
164003 && ( (pExpr->pLeft->flags & EP_xIsSelect)==0
164004 || (pExpr->pRight->flags & EP_xIsSelect)==0)
164008 for(i=0; i<nLeft; i++){
164034 && pTerm->u.x.iField==0
164037 && (pExpr->x.pSelect->pPrior==0 || (pExpr->x.pSelect->selFlags & SF_Values))
164039 && pExpr->x.pSelect->pWin==0
164044 for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){
164064 Expr *pRight = 0, *pLeft = 0;
164066 while( res-- > 0 ){
164073 if( (prereqExpr & prereqColumn)==0 ){
164076 0, sqlite3ExprDup(db, pRight, 0));
164082 testcase( idxNew==0 );
164120 ** slot[0] slot[1] slot[2]
164132 assert( pE2!=0 || pExpr==0 );
164133 if( pE2==0 ) return;
164135 whereClauseInsert(pWC, pExpr, 0);
164163 int iVal = 0;
164165 if( sqlite3ExprIsInteger(pExpr, &iVal, pParse) && iVal>=0 ){
164166 Expr *pVal = sqlite3Expr(db, TK_INTEGER, 0);
164167 if( pVal==0 ) return;
164170 pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal);
164172 Expr *pVal = sqlite3Expr(db, TK_REGISTER, 0);
164173 if( pVal==0 ) return;
164175 pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal);
164207 assert( p!=0 && p->pLimit!=0 ); /* 1 -- checked by caller */
164208 if( p->pGroupBy==0
164209 && (p->selFlags & (SF_Distinct|SF_Aggregate))==0 /* 2 */
164210 && (p->pSrc->nSrc==1 && IsVirtual(p->pSrc->a[0].pSTab)) /* 3 */
164213 int iCsr = p->pSrc->a[0].iCursor;
164217 for(ii=0; ii<pWC->nTerm; ii++){
164233 if( pWC->a[ii].prereqRight!=0 ) return;
164238 for(ii=0; ii<pOrderBy->nExpr; ii++){
164248 if( p->iOffset!=0 && (p->selFlags & SF_Compound)==0 ){
164252 if( p->iOffset==0 || (p->selFlags & SF_Compound)==0 ){
164267 pWC->hasOr = 0;
164268 pWC->pOuter = 0;
164269 pWC->nTerm = 0;
164270 pWC->nBase = 0;
164283 if( pWC->nTerm>0 ){
164290 assert( (pWC->a[i].wtFlags & TERM_VIRTUAL)!=0 );
164294 assert( a->eMatchOp==0 || a->eOperator==WO_AUX );
164300 assert( (a->wtFlags & TERM_ANDINFO)==0 );
164303 assert( (a->wtFlags & TERM_ANDINFO)!=0 );
164322 ** be NULL, in which case 0 is returned.
164333 ** case 0 is returned.
164350 mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0;
164354 assert( p->x.pList==0 );
164363 assert( p->y.pWin!=0 );
164376 return 0;
164381 return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
164385 Bitmask mask = 0;
164387 for(i=0; i<pList->nExpr; i++){
164408 for(i=pWC->nTerm-1; i>=0; i--){
164430 if( pItem->fg.isTabFunc==0 ) return;
164432 assert( pTab!=0 );
164434 if( pArgs==0 ) return;
164435 for(j=k=0; j<pArgs->nExpr; j++){
164438 while( k<pTab->nCol && (pTab->aCol[k].colFlags & COLFLAG_HIDDEN)==0 ){k++;}
164444 pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
164445 if( pColRef==0 ) return;
164452 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
164536 ** WHERE clause. A return of 0 means that the output must be
164543 return pWInfo->nOBSat<0 ? 0 : pWInfo->nOBSat;
164577 assert( pInner->addrNxt!=0 );
164596 if( pWInfo->nOBSat==0 ) return;
164597 for(i=pWInfo->nLevel-1; i>=0; i--){
164599 if( (pInner->pWLoop->wsFlags & WHERE_COLUMN_IN)!=0 ){
164612 assert( pWInfo->iContinue!=0 );
164625 ** Return ONEPASS_OFF (0) if an UPDATE or DELETE statement is unable to
164633 ** into aiCur[0] and aiCur[1]. iaCur[0] gets the cursor of the data
164638 ** aiCur[0] and aiCur[1] both get -1 if the where-clause logic is
164647 aiCur[0], aiCur[1]);
164666 memcpy(pDest->a, pSrc->a, pDest->n*sizeof(pDest->a[0]));
164684 for(i=pSet->n, p=pSet->a; i>0; i--, p++){
164689 return 0;
164700 if( p->rRun<=rRun ) return 0;
164710 ** Return the bitmask for the given cursor number. Return 0 if
164716 assert( pMaskSet->n>0 || pMaskSet->ix[0]<0 );
164718 if( pMaskSet->ix[0]==iCursor ){
164726 return 0;
164772 if( ALWAYS(p!=0) && p->op==TK_COLUMN && !ExprHasProperty(p, EP_FixedCol) ){
164775 return 0;
164799 inexpr.flags = 0;
164811 return 0;
164832 assert( pWC!=0 );
164833 assert( iCur>=0 );
164836 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 || pTerm->leftCursor<0 );
164841 pScan->pIdxExpr,iCur)==0)
164844 if( (pTerm->eOperator & WO_EQUIV)!=0
164846 && (pX = whereRightSubexprIsColumn(pTerm->pExpr))!=0
164849 for(j=0; j<pScan->nEquiv; j++){
164861 if( (pTerm->eOperator & pScan->opMask)!=0 ){
164863 if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){
164885 if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0
164886 && (pX = pTerm->pExpr->pRight, ALWAYS(pX!=0))
164888 && pX->iTable==pScan->aiCur[0]
164889 && pX->iColumn==pScan->aiColumn[0]
164897 if( sqlite3WhereTrace & 0x20000 ){
164901 for(ii=0; ii<pScan->nEquiv; ii++){
164913 k = 0;
164914 }while( pWC!=0 );
164917 k = 0;
164920 return 0;
164940 ** iCur. Or if pIdx!=0 then X is column iColumn of index pIdx. pIdx
164963 pScan->pIdxExpr = 0;
164964 pScan->idxaff = 0;
164965 pScan->zCollName = 0;
164967 pScan->k = 0;
164968 pScan->aiCur[0] = iCur;
164976 }else if( iColumn>=0 ){
164982 pScan->aiColumn[0] = XN_EXPR;
164986 return 0;
164988 pScan->aiColumn[0] = iColumn;
164995 ** if pIdx!=0 and <op> is one of the WO_xx operator codes specified by
164996 ** the op parameter. Return a pointer to the term. Return 0 if not found.
164998 ** If pIdx!=0 then it must be one of the indexes of table iCur.
165025 WhereTerm *pResult = 0;
165032 if( (p->prereqRight & notReady)==0 ){
165033 if( p->prereqRight==0 && (p->eOperator&op)!=0 ){
165037 if( pResult==0 ) pResult = p;
165061 for(i=0; i<pList->nExpr; i++){
165063 if( ALWAYS(p!=0)
165069 if( 0==sqlite3StrICmp(pColl->zName, zColl) ){
165083 assert( pIdx!=0 );
165084 assert( iCol>=0 && iCol<pIdx->nColumn );
165086 if( j>=0 ){
165092 return 0; /* Assume an indexed expression can always yield a NULL */
165118 if( pTabList->nSrc!=1 ) return 0;
165119 iBase = pTabList->a[0].iCursor;
165120 pTab = pTabList->a[0].pSTab;
165126 for(i=0; i<pDistinct->nExpr; i++){
165128 if( NEVER(p==0) ) continue;
165130 if( p->iTable==iBase && p->iColumn<0 ) return 1;
165149 for(i=0; i<pIdx->nKeyCol; i++){
165150 if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
165151 if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
165152 if( indexColumnNotNull(pIdx, i)==0 ) break;
165161 return 0;
165169 return N<=10 ? 0 : sqlite3LogEst(N) - 33;
165212 pOp->p3 = 0;
165223 if( iAutoidxCur==0 ){
165225 pOp->p3 = 0;
165244 if( (sqlite3WhereTrace & 0x10)==0 ) return;
165246 for(i=0; i<p->nConstraint; i++){
165256 for(i=0; i<p->nOrderBy; i++){
165268 if( (sqlite3WhereTrace & 0x10)==0 ) return;
165270 for(i=0; i<p->nConstraint; i++){
165304 assert( (pSrc->fg.jointype&(JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ); /* By caller */
165312 return 0;
165314 if( (pSrc->fg.jointype & (JT_LEFT|JT_RIGHT))!=0
165317 return 0;
165347 for(pIdx = pTab->pIndex; pIdx!=0; pIdx=pIdx->pNext){
165349 for(j=0; j<pIdx->nKeyCol; j++){
165351 if( j==0 ) return 0;
165352 if( pIdx->hasStat1 && pIdx->aiRowLogEst[j+1]>20 ) return 0;
165377 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
165378 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
165379 assert( (pSrc->fg.jointype & JT_RIGHT)==0 );
165380 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0
165383 return 0; /* See https://sqlite.org/forum/forumpost/51e6959f61 */
165385 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
165386 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
165388 if( leftCol<0 ) return 0;
165390 if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
165420 char *zText = 0;
165421 int ii = 0;
165426 for(ii=0; ii<(pIdx->nColumn-1); ii++){
165427 const char *zName = 0;
165435 if( zText==0 ){
165439 pParse, 0, "%s)%s", zText, (bPartial ? " WHERE <expr>" : "")
165477 u8 sentWarning = 0; /* True if a warning has been issued */
165478 u8 useBloomFilter = 0; /* True to also add a Bloom filter */
165479 Expr *pPartial = 0; /* Partial Index Expression */
165480 int iContinue = 0; /* Jump here to skip excluded rows */
165483 int addrCounter = 0; /* Address where integer counter is initialized */
165486 int addrExp = 0; /* Address of OP_Explain */
165492 assert( v!=0 );
165497 nKeyCol = 0;
165503 idxCols = 0;
165509 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
165510 && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, pLevel->iFrom, 0)
165513 sqlite3ExprDup(pParse->db, pExpr, 0));
165518 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
165529 if( (idxCols & cMask)==0 ){
165538 assert( nKeyCol>0 || pParse->db->mallocFailed );
165559 for(i=0; i<pTable->nCol; i++){
165560 if( (pTable->aCol[i].colFlags & COLFLAG_PRIMKEY)==0 ) continue;
165572 for(i=0; i<mxBitCol; i++){
165580 assert( nKeyCol <= pTable->nCol + MAX(0, pTable->nCol - BMS + 1) );
165583 0, &zNotUsed);
165584 if( pIdx==0 ) goto end_auto_index_create;
165588 n = 0;
165589 idxCols = 0;
165594 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
165599 if( (idxCols & cMask)==0 ){
165604 assert( pColl!=0 || pParse->nErr>0 ); /* TH3 collate01.800 */
165607 if( ALWAYS(pX->pLeft!=0)
165624 for(i=0; i<mxBitCol; i++){
165645 explainAutomaticIndex(pParse, pIdx, pPartial!=0, &addrExp);
165646 assert( pLevel->iIdxCur>=0 );
165664 assert( pSubq!=0 );
165666 addrCounter = sqlite3VdbeAddOp2(v, OP_Integer, 0, 0);
165667 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pSubq->addrFillSub);
165681 pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0
165684 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0,
165692 assert( pSrc->fg.isSubquery && pSrc->u4.pSubq!=0 );
165695 assert( pLevel->iIdxCur>0 );
165699 pSrc->fg.viaCoroutine = 0;
165756 pParse->pIdxEpr = 0;
165757 pParse->pIdxPartExpr = 0;
165759 assert( pLoop!=0 );
165760 assert( v!=0 );
165762 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 );
165787 assert( pItem!=0 );
165789 assert( pTab!=0 );
165802 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
165803 && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, iSrc, 0)
165811 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, 1);
165818 for(jj=0; jj<n; jj++){
165822 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, n);
165837 if( NEVER(pLoop==0) ) continue;
165859 ** are numbered from 0 upwards, starting with the terms in pWC->a[], then
165868 return 0;
165893 u16 mNoOmit = 0;
165895 int eDistinct = 0;
165899 assert( pSrc!=0 );
165901 assert( pTab!=0 );
165908 for(p=pWC, nTerm=0; p; p=p->pOuter){
165909 for(i=0, pTerm=p->a; i<p->nTerm; i++, pTerm++){
165918 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
165921 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
165924 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0
165938 nOrderBy = 0;
165941 for(i=0; i<n; i++){
165946 if( sqlite3ExprIsConstant(0, pExpr) ){
165967 assert( pExpr->u.zToken!=0 );
165970 if( pE2->iColumn<0 ) continue; /* Collseq does not matter for rowid */
165972 if( zColl==0 ) zColl = sqlite3StrBINARY;
165973 if( sqlite3_stricmp(pExpr->u.zToken, zColl)==0 ) continue;
165982 eDistinct = 2 + ((pWInfo->wctrlFlags & WHERE_SORTBYGROUP)!=0);
165995 if( pIdxInfo==0 ){
165997 return 0;
166007 if( HasRowid(pTab)==0 ){
166011 assert( pPk!=0 );
166012 for(i=0; i<pPk->nKeyCol; i++){
166014 assert( iCol>=0 );
166022 pHidden->mIn = 0;
166023 for(p=pWC, i=j=0; p; p=p->pOuter){
166027 if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
166032 if( (pTerm->wtFlags & TERM_SLICE)==0 ){
166072 for(i=j=0; i<nOrderBy; i++){
166074 if( sqlite3ExprIsConstant(0, pExpr) ) continue;
166094 pIdxInfo->idxStr = 0;
166095 pIdxInfo->needToFreeIdxStr = 0;
166106 assert( pIdxInfo!=0 );
166108 assert( pHidden->pParse!=0 );
166110 for(i=0; i<pIdxInfo->nConstraint; i++){
166112 pHidden->aRhs[i] = 0;
166159 pVtab->zErrMsg = 0;
166169 ** aStat[0] Est. number of rows less than pRec
166189 int iMin = 0; /* Smallest sample not yet tested */
166193 tRowcnt iLower = 0; /* anLt[] + anEq[] of largest sample pRec is > */
166198 assert( pRec!=0 );
166199 assert( pIdx->nSample>0 );
166200 assert( pRec->nField>0 );
166213 ** aSample[0] = (a, 5)
166223 ** 0: (a)
166235 ** effective sample array. In the above, samples 0 and 1 are based on
166236 ** sample aSample[0]. Samples 2 and 3 on aSample[1] etc.
166253 iCol = 0;
166261 if( iSamp>0 ){
166274 if( res<0 ){
166277 }else if( res==0 && n<nField ){
166292 if( pParse->db->mallocFailed==0 ){
166293 if( res==0 ){
166294 /* If (res==0) is true, then pRec must be equal to sample i. */
166298 assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
166305 assert( i<=pIdx->nSample && i>=0 );
166308 || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
166311 /* if i==0 and iCol==0, then record pRec is smaller than all samples
166312 ** in the aSample[] array. Otherwise, if (iCol>0) then pRec must
166314 ** If (i>0), then pRec must also be greater than sample (i-1). */
166315 if( iCol>0 ){
166317 assert( sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)<=0
166320 if( i>0 ){
166322 assert( sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
166329 if( res==0 ){
166332 aStat[0] = aSample[i].anLt[iCol];
166346 iGap = 0;
166355 aStat[0] = iLower + iGap;
166379 if( pTerm->truthProb<=0 ){
166381 }else if( (pTerm->wtFlags & TERM_VNULL)==0 ){
166394 assert( iCol>=0 && iCol<pIdx->nColumn );
166396 if( sqlite3IndexAffinityStr(db, pIdx)==0 ) return SQLITE_AFF_BLOB;
166398 assert( pIdx->zColAff[iCol]!=0 );
166456 sqlite3_value *p1 = 0; /* Value extracted from pLower */
166457 sqlite3_value *p2 = 0; /* Value extracted from pUpper */
166458 sqlite3_value *pVal = 0; /* Value extracted from record */
166463 nLower = 0;
166467 nUpper = p2 ? 0 : p->nSample;
166473 for(i=0; rc==SQLITE_OK && i<p->nSample; i++){
166477 if( res>=0 ) nLower++;
166481 if( res>=0 ) nUpper++;
166485 if( nDiff<=0 ) nDiff = 1;
166492 if( nDiff!=1 || pUpper==0 || pLower==0 ){
166496 WHERETRACE(0x20, ("range skip-scan regions: %u..%u adjust=%d est=%d\n",
166501 assert( *pbDone==0 );
166539 ** then nEq is set to 0.
166543 ** considering the range constraints. If nEq is 0, then *pnOut is the number of
166567 if( p->nSample>0 && ALWAYS(nEq<p->nSampleCol)
166605 if( nEq==0 ){
166606 iLower = 0;
166611 whereKeyStats(pParse, p, pRec, 0, a);
166612 iLower = a[0];
166613 iUpper = a[0] + a[1];
166616 assert( pLower==0 || (pLower->eOperator & (WO_GT|WO_GE))!=0 );
166617 assert( pUpper==0 || (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
166618 assert( p->aSortOrder!=0 );
166634 iLwrIdx = whereKeyStats(pParse, p, pRec, 0, a);
166635 iNew = a[0] + ((pLower->eOperator & mask) ? a[1] : 0);
166638 pLower = 0;
166652 iNew = a[0] + ((pUpper->eOperator & mask) ? a[1] : 0);
166655 pUpper = 0;
166675 WHERETRACE(0x20, ("STAT4 range scan: %u..%u est=%d\n",
166679 int bDone = 0;
166689 assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 || pParse->nErr>0 );
166699 if( pLower && pLower->truthProb>0 && pUpper && pUpper->truthProb>0 ){
166703 nOut -= (pLower!=0) + (pUpper!=0);
166708 WHERETRACE(0x20,("Range scan lowers nOut from %d to %d\n",
166749 assert( p->aSample!=0 );
166750 assert( p->nSample>0 );
166769 if( bOk==0 ) return SQLITE_NOTFOUND;
166772 whereKeyStats(pParse, p, pRec, 0, a);
166773 WHERETRACE(0x20,("equality scan regions %s(%d): %d\n",
166805 i64 nRow0 = sqlite3LogEstToInt(p->aiRowLogEst[0]);
166809 tRowcnt nRowEst = 0; /* New estimate of the number of rows */
166812 assert( p->aSample!=0 );
166813 for(i=0; rc==SQLITE_OK && i<pList->nExpr; i++){
166823 WHERETRACE(0x20,("IN row estimate: est=%d\n", nRowEst));
166836 if( pTerm==0 ){
166842 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
166847 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
166850 }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){
166851 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
166859 /* The 0x10000 .wheretrace flag causes extra information to be
166861 if( sqlite3WhereTrace & 0x10000 ){
166865 if( (pTerm->eOperator & (WO_OR|WO_AND))==0 && pTerm->u.x.iField ){
166868 if( pTerm->iParent>=0 ){
166872 sqlite3TreeViewExpr(0, pTerm->pExpr, 0);
166876 sqlite3WhereTermPrint(pTerm, 0);
166886 for(i=0; i<pWC->nTerm; i++){
166906 ** 1.002.001 t2.t2xy 2 f 010241 N 2 cost 0,56,31
166916 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
166921 pWInfo = 0;
166923 p->cId, p->iTab, p->maskSelf, p->prereq & 0xfff, p->cId, p->iTab);
166925 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
166927 if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
166928 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
166953 if( pWInfo && pWInfo->bStarUsed && p->rStarDelta!=0 ){
166959 if( p->nLTerm && (sqlite3WhereTrace & 0x4000)!=0 ){
166961 for(i=0; i<p->nLTerm; i++){
166967 if( p ) sqlite3WhereLoopPrint(p, 0);
166983 p->nLTerm = 0;
166985 p->wsFlags = 0;
166993 if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 && p->u.vtab.needFree ){
166995 p->u.vtab.needFree = 0;
166996 p->u.vtab.idxStr = 0;
166997 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
167000 p->u.btree.pIndex = 0;
167016 p->nLTerm = 0;
167017 p->wsFlags = 0;
167027 paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);
167028 if( paNew==0 ) return SQLITE_NOMEM_BKPT;
167029 memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0])*p->nLSlot);
167044 memset(pTo, 0, WHERE_LOOP_XFER_SZ);
167048 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
167050 pFrom->u.vtab.needFree = 0;
167051 }else if( (pFrom->wsFlags & WHERE_AUTO_INDEX)!=0 ){
167052 pFrom->u.btree.pIndex = 0;
167061 assert( db!=0 );
167070 assert( pWInfo!=0 );
167071 assert( db!=0 );
167116 if( pX->rRun>pY->rRun && pX->nOut>pY->nOut ) return 0; /* (1d) and (2a) */
167117 assert( (pX->wsFlags & WHERE_VIRTUALTABLE)==0 );
167118 assert( (pY->wsFlags & WHERE_VIRTUALTABLE)==0 );
167121 && pX->nSkip==0 && pY->nSkip==0 /* (1c) */
167126 return 0; /* (2b) */
167128 if( pY->nSkip > pX->nSkip ) return 0; /* (2d) */
167129 for(i=pX->nLTerm-1; i>=0; i--){
167130 if( pX->aLTerm[i]==0 ) continue;
167131 for(j=pY->nLTerm-1; j>=0; j--){
167134 if( j<0 ) return 0; /* (2c) */
167136 if( (pX->wsFlags&WHERE_IDX_ONLY)!=0
167137 && (pY->wsFlags&WHERE_IDX_ONLY)==0 ){
167138 return 0; /* (2e) */
167158 if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return;
167161 if( (p->wsFlags & WHERE_INDEXED)==0 ) continue;
167165 WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
167174 WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
167213 assert( p->rSetup==0 || pTemplate->rSetup==0
167224 if( (p->wsFlags & WHERE_AUTO_INDEX)!=0
167225 && (pTemplate->nSkip)==0
167226 && (pTemplate->wsFlags & WHERE_INDEXED)!=0
167227 && (pTemplate->wsFlags & WHERE_COLUMN_EQ)!=0
167243 return 0; /* Discard pTemplate */
167293 if( pBuilder->iPlanLimit==0 ){
167294 WHERETRACE(0xffffffff,("=== query planner search limit reached ===\n"));
167295 if( pBuilder->pOrSet ) pBuilder->pOrSet->n = 0;
167305 if( pBuilder->pOrSet!=0 ){
167313 #if WHERETRACE_ENABLED /* 0x8 */
167314 if( sqlite3WhereTrace & 0x8 ){
167327 if( ppPrev==0 ){
167330 #if WHERETRACE_ENABLED /* 0x8 */
167331 if( sqlite3WhereTrace & 0x8 ){
167345 #if WHERETRACE_ENABLED /* 0x8 */
167346 if( sqlite3WhereTrace & 0x8 ){
167347 if( p!=0 ){
167357 if( p==0 ){
167360 if( p==0 ) return SQLITE_NOMEM_BKPT;
167362 p->pNextLoop = 0;
167371 if( ppTail==0 ) break;
167373 if( pToDel==0 ) break;
167375 #if WHERETRACE_ENABLED /* 0x8 */
167376 if( sqlite3WhereTrace & 0x8 ){
167385 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
167388 p->u.btree.pIndex = 0;
167415 ** form "x==EXPR" and EXPR is not a constant 0 or 1, then make sure the
167418 ** out at least 3 out of 4 rows. If EXPR is -1 or 0 or 1, then maybe the
167419 ** "x" column is boolean or else -1 or 0 or 1 is a common default value
167431 LogEst iReduce = 0; /* pLoop->nOut should not exceed nRow-iReduce */
167433 assert( (pLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
167434 for(i=pWC->nBase, pTerm=pWC->a; i>0; i--, pTerm++){
167435 assert( pTerm!=0 );
167436 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
167437 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
167438 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) continue;
167439 for(j=pLoop->nLTerm-1; j>=0; j--){
167441 if( pX==0 ) continue;
167443 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
167445 if( j<0 ){
167457 if( (pTerm->eOperator & 0x3f)!=0
167459 & (JT_LEFT|JT_LTORJ))==0
167464 if( pTerm->truthProb<=0 ){
167472 if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0
167473 && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */
167476 int k = 0;
167478 if( sqlite3ExprIsInteger(pRight, &k, 0) && k>=(-1) && k<=1 ){
167528 char idxaff = 0; /* Indexed columns affinity */
167559 if( pColl==0 ) break;
167611 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
167614 assert( db->mallocFailed==0 || pParse->nErr>0 );
167618 WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d, rRun=%d\n",
167622 assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
167623 assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
167627 assert( pNew->u.btree.nBtm==0 );
167648 pNew->rSetup = 0;
167649 rSize = pProbe->aiRowLogEst[0];
167651 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
167655 int nIn = 0;
167659 if( (eOp==WO_ISNULL || (pTerm->wtFlags&TERM_VNULL)!=0)
167670 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0
167693 assert( nInMul==0
167694 || (pNew->wsFlags & WHERE_COLUMN_NULL)!=0
167695 || (pNew->wsFlags & WHERE_COLUMN_IN)!=0
167696 || (pNew->wsFlags & WHERE_SKIPSCAN)!=0
167704 int bRedundant = 0;
167711 ** first such term in use, and sets nIn back to 0 if it is not. */
167712 for(i=0; i<pNew->nLTerm-1; i++){
167714 nIn = 0;
167758 if( x>=0 ){
167759 WHERETRACE(0x40,
167764 WHERETRACE(0x40,
167770 WHERETRACE(0x40,
167783 || (iCol>=0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1)
167806 pTop = 0;
167826 pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
167827 pNew->aLTerm[pNew->nLTerm-2] : 0;
167846 if( pTerm->truthProb<=0 && pProbe->aiColumn[saved_nEq]>=0 ){
167847 assert( (eOp & WO_IN) || nIn==0 );
167853 tRowcnt nOut = 0;
167854 if( nInMul==0
167857 && ((eOp & WO_IN)==0 || ExprUseXList(pTerm->pExpr))
167861 if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){
167877 && pNew->nOut+10 > pProbe->aiRowLogEst[0]
167879 #if WHERETRACE_ENABLED /* 0x01 */
167880 if( sqlite3WhereTrace & 0x20 ){
167898 if( nOut==0 )
167919 assert( pSrc->pSTab->szTabRow>0 );
167938 if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK|WHERE_EXPRIDX))==0 ){
167955 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
167993 && pProbe->noSkipScan==0
167994 && pProbe->hasStat1!=0
168002 pNew->aLTerm[pNew->nLTerm++] = 0;
168016 WHERETRACE(0x800, ("END %s.addBtreeIdx(%s), nEq=%d, rc=%d\n",
168038 if( pIndex->bUnordered ) return 0;
168039 if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
168040 for(ii=0; ii<pOB->nExpr; ii++){
168042 if( NEVER(pExpr==0) ) continue;
168046 if( pExpr->iColumn<0 ) return 1;
168047 for(jj=0; jj<pIndex->nKeyCol; jj++){
168050 }else if( (aColExpr = pIndex->aColExpr)!=0 ){
168051 for(jj=0; jj<pIndex->nKeyCol; jj++){
168053 if( sqlite3ExprCompareSkip(pExpr,aColExpr->a[jj].pExpr,iCursor)==0 ){
168059 return 0;
168075 if( jointype & JT_LTORJ ) return 0;
168078 if( !whereUsablePartialIndex(iTab,jointype,pWC,pWhere->pLeft) ) return 0;
168081 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
168085 && ((jointype & JT_OUTER)==0 || ExprHasProperty(pExpr, EP_OuterON))
168088 && (pTerm->wtFlags & TERM_VNULL)==0
168093 return 0;
168106 for(i=0; i<pIdx->nColumn; i++){
168108 && sqlite3ExprCompare(0, pExpr, pIdx->aColExpr->a[i].pExpr, iTabCur)==0
168113 return 0;
168154 /* if( pExpr->iColumn<(BMS-1) && pIdx->bHasExpr==0 ) return WRC_Continue;*/
168159 for(i=0; i<nColumn; i++){
168175 ** pWInfo->pSelect (columns from 0 through 62) or an index that has
168182 ** 0 The index is definitely not a covering index
168204 if( pWInfo->pSelect==0 ){
168207 return 0;
168209 if( pIdx->bHasExpr==0 ){
168210 for(i=0; i<pIdx->nColumn; i++){
168217 return 0;
168222 ck.bExpr = 0;
168223 ck.bUnidx = 0;
168224 memset(&w, 0, sizeof(w));
168230 rc = 0;
168245 while( *pp!=0 ){
168288 assert( pItem==0 || (pItem->fg.jointype & JT_RIGHT)==0 );
168289 assert( (pItem==0 || pMask==0) && (pMask!=0 || pItem!=0) );
168302 if( !sqlite3ExprIsConstant(0, pRight) ) return;
168304 if( pLeft->iColumn<0 ) return;
168311 int bNullRow = (pItem->fg.jointype&(JT_LEFT|JT_LTORJ))!=0;
168312 p->pExpr = sqlite3ExprDup(db, pRight, 0);
168320 if( p->pIENext==0 ){
168397 assert( pSrc->fg.isCte==0 );
168408 memset(&sPk, 0, sizeof(Index));
168417 aiRowEstPk[0] = pTab->nRowLogEst;
168418 aiRowEstPk[1] = 0;
168420 if( pSrc->fg.notIndexed==0 ){
168432 && (pWInfo->wctrlFlags & (WHERE_RIGHT_JOIN|WHERE_OR_SUBCLAUSE))==0
168433 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
168438 && (pSrc->fg.jointype & JT_RIGHT)==0 /* Not the right tab of a RIGHT JOIN */
168447 if( termCanDriveIndex(pTerm, pSrc, 0) ){
168449 pNew->nSkip = 0;
168450 pNew->u.btree.pIndex = 0;
168452 pNew->aLTerm[0] = pTerm;
168462 if( !IsView(pTab) && (pTab->tabFlags & TF_Ephemeral)==0 ){
168469 if( pNew->rSetup<0 ) pNew->rSetup = 0;
168487 pProbe=(pSrc->fg.isIndexedBy ? 0 : pProbe->pNext), iSortIdx++
168489 if( pProbe->pPartIdxWhere!=0
168497 rSize = pProbe->aiRowLogEst[0];
168498 pNew->u.btree.nEq = 0;
168499 pNew->u.btree.nBtm = 0;
168500 pNew->u.btree.nTop = 0;
168501 pNew->u.btree.nDistinctCol = 0;
168502 pNew->nSkip = 0;
168503 pNew->nLTerm = 0;
168504 pNew->iSortIdx = 0;
168505 pNew->rSetup = 0;
168509 pNew->u.btree.pOrderBy = 0;
168513 assert( (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || b==0 );
168519 pNew->iSortIdx = b ? iSortIdx : 0;
168533 pNew->rRun = rSize + 16 - 2*((pTab->tabFlags & TF_HasStat4)!=0);
168549 m = 0;
168555 pWInfo->pParse, pProbe, pProbe->pPartIdxWhere, &m, 0, 0
168559 if( m==TOPBIT || (pProbe->bHasExpr && !pProbe->bHasVCol && m!=0) ){
168561 if( isCov==0 ){
168562 WHERETRACE(0x200,
168565 assert( m!=0 );
168567 m = 0;
168570 WHERETRACE(0x200,
168575 WHERETRACE(0x200,
168580 }else if( m==0
168581 && (HasRowid(pTab) || pWInfo->pSelect!=0 || sqlite3FaultSim(700))
168583 WHERETRACE(0x200,
168585 pProbe->zName, m==0 ? "is" : "is not"));
168593 || pProbe->pPartIdxWhere!=0
168595 || ( m==0
168596 && pProbe->bUnordered==0
168598 && (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
168603 pNew->iSortIdx = b ? iSortIdx : 0;
168609 if( m!=0 ){
168619 for(ii=0; ii<pWC2->nTerm; ii++){
168626 if( pTerm->truthProb<=0 ){
168638 if( (pSrc->fg.jointype & JT_RIGHT)!=0 && pProbe->aColExpr ){
168651 pBuilder->bldFlags1 = 0;
168652 rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0);
168662 pBuilder->nRecValid = 0;
168663 pBuilder->pRec = 0;
168675 assert( pTerm->eOperator==WO_AUX || pTerm->eMatchOp==0 );
168682 ** marked as in-use (have argvIndex>0). False otherwise.
168689 for(ii=0; ii<nCons; ii++){
168690 if( aUsage[ii].argvIndex<=0 ) return 0;
168706 ** as the fourth argument (which in practice is either WO_IN or 0).
168738 *pbIn = 0;
168744 for(i=0; i<nConstraint; i++, pIdxCons++){
168746 pIdxCons->usable = 0;
168748 && (pTerm->eOperator & mExclude)==0
168756 memset(pUsage, 0, sizeof(pUsage[0])*nConstraint);
168757 assert( pIdxInfo->needToFreeIdxStr==0 );
168758 pIdxInfo->idxStr = 0;
168759 pIdxInfo->idxNum = 0;
168760 pIdxInfo->orderByConsumed = 0;
168763 pIdxInfo->idxFlags = 0;
168764 pHidden->mHandleIn = 0;
168774 WHERETRACE(0xffffffff, (" ^^^^--- non-viable plan rejected!\n"));
168783 memset(pNew->aLTerm, 0, sizeof(pNew->aLTerm[0])*nConstraint );
168784 memset(&pNew->u.vtab, 0, sizeof(pNew->u.vtab));
168786 for(i=0; i<nConstraint; i++, pIdxCons++){
168788 if( (iTerm = pUsage[i].argvIndex - 1)>=0 ){
168792 || j<0
168793 || (pTerm = termFromWhereClause(pWC, j))==0
168794 || pNew->aLTerm[iTerm]!=0
168795 || pIdxCons->usable==0
168802 testcase( j==0 );
168811 if( i<16 && ((1<<i)&mNoOmit)==0 ){
168823 }else if( (pTerm->eOperator & WO_IN)!=0 ){
168829 pIdxInfo->orderByConsumed = 0;
168831 *pbIn = 1; assert( (mExclude & WO_IN)==0 );
168856 for(i=0; i<=mxTerm; i++){
168857 if( pNew->aLTerm[i]==0 ){
168868 pIdxInfo->needToFreeIdxStr = 0;
168871 pIdxInfo->nOrderBy : 0);
168872 pNew->u.vtab.bIdxNumHex = (pIdxInfo->idxFlags&SQLITE_INDEX_SCAN_HEX)!=0;
168873 pNew->rSetup = 0;
168887 pNew->u.vtab.needFree = 0;
168889 WHERETRACE(0xffffffff, (" bIn=%d prereqIn=%04llx prereqOut=%04llx\n",
168913 const char *zRet = 0;
168914 if( iCons>=0 && iCons<pIdxInfo->nConstraint ){
168915 CollSeq *pC = 0;
168928 ** false otherwise. If iCons is an IN(...) constraint, set (if bHandle!=0)
168929 ** or clear (if bHandle==0) the flag to handle it using an iterator.
168935 if( bHandle==0 ){
168937 }else if( bHandle>0 ){
168942 return 0;
168957 sqlite3_value *pVal = 0;
168959 if( iCons<0 || iCons>=pIdxInfo->nConstraint ){
168962 if( pH->aRhs[iCons]==0 ){
168976 if( rc==SQLITE_OK && pVal==0 ){ /* IMP: R-19933-32160 */
168988 assert( pHidden->eDistinct>=0 && pHidden->eDistinct<=3 );
169004 for(i=0; i<nDb; i++){
169008 for(i=0; i<nDb; i++){
169009 sqlite3BeginWriteOperation(pParse, 0, i);
169019 ** mUnusable are set to 0. Otherwise, mPrereq is a mask of all FROM clause
169055 int bRetry = 0; /* True to retry with LIMIT/OFFSET disabled */
169057 assert( (mPrereq & mUnusable)==0 );
169065 if( p==0 ) return SQLITE_NOMEM_BKPT;
169066 pNew->rSetup = 0;
169068 pNew->nLTerm = 0;
169069 pNew->u.vtab.needFree = 0;
169077 WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pSTab->zName));
169078 WHERETRACE(0x800, (" VirtualOne: all usable\n"));
169080 pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, &bRetry
169085 pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, 0
169090 ** that does not require any source tables (IOW: a plan with mBest==0)
169094 if( rc==SQLITE_OK && ((mBest = (pNew->prereq & ~mPrereq))!=0 || bIn) ){
169095 int seenZero = 0; /* True if a plan with no prereqs seen */
169096 int seenZeroNoIN = 0; /* Plan with no prereqs and no IN(...) seen */
169097 Bitmask mPrev = 0;
169098 Bitmask mBestNoIn = 0;
169103 WHERETRACE(0x800, (" VirtualOne: all usable w/o IN\n"));
169105 pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn, 0);
169106 assert( bIn==0 );
169108 if( mBestNoIn==0 ){
169119 assert( mNext>0 );
169120 for(i=0; i<nConstraint; i++){
169128 WHERETRACE(0x800, (" VirtualOne: mPrev=%04llx mNext=%04llx\n",
169131 pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn, 0);
169134 if( bIn==0 ) seenZeroNoIN = 1;
169141 if( rc==SQLITE_OK && seenZero==0 ){
169142 WHERETRACE(0x800, (" VirtualOne: all disabled\n"));
169144 pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn, 0);
169145 if( bIn==0 ) seenZeroNoIN = 1;
169151 if( rc==SQLITE_OK && seenZeroNoIN==0 ){
169152 WHERETRACE(0x800, (" VirtualOne: all disabled and w/o IN\n"));
169154 pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn, 0);
169159 WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pSTab->zName, rc));
169187 memset(&sSum, 0, sizeof(sSum));
169195 if( (pTerm->eOperator & WO_OR)!=0
169196 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
169207 WHERETRACE(0x400, ("Begin processing OR-clause %p\n", pTerm));
169209 if( (pOrTerm->eOperator & WO_AND)!=0 ){
169222 sCur.n = 0;
169224 WHERETRACE(0x400, ("OR-term %d of %p has %d subterms:\n",
169226 if( sqlite3WhereTrace & 0x20000 ){
169241 testcase( rc==SQLITE_NOMEM && sCur.n>0 );
169243 if( sCur.n==0 ){
169244 sSum.n = 0;
169248 once = 0;
169252 sSum.n = 0;
169253 for(i=0; i<sPrev.n; i++){
169254 for(j=0; j<sCur.n; j++){
169263 pNew->aLTerm[0] = pTerm;
169265 pNew->rSetup = 0;
169266 pNew->iSortIdx = 0;
169267 memset(&pNew->u, 0, sizeof(pNew->u));
169268 for(i=0; rc==SQLITE_OK && i<sSum.n; i++){
169286 WHERETRACE(0x400, ("End processing OR-clause %p\n", pTerm));
169297 Bitmask mPrereq = 0;
169298 Bitmask mPrior = 0;
169305 int bFirstPastRJ = 0;
169306 int hasRightJoin = 0;
169314 assert( pNew->nLTerm==0 );
169315 assert( pNew->wsFlags==0 );
169317 assert( pNew->aLTerm!=0 );
169320 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
169321 Bitmask mUnusable = 0;
169326 || (pItem->fg.jointype & (JT_OUTER|JT_CROSS|JT_LTORJ))!=0
169340 bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
169342 mPrereq = 0;
169419 int iLoop, /* Which level of the nested loop. 0==outermost */
169427 u8 rev = 0; /* True if iOB and jSub sort in opposite directions */
169428 u8 revIdx = 0; /* Sort direction for jSub */
169433 assert( pSubOB!=0 );
169434 for(iOB=0; (MASKBIT(iOB) & *pOBSat)!=0; iOB++){}
169435 for(jSub=0; jSub<pSubOB->nExpr && iOB<pOrderBy->nExpr; jSub++, iOB++){
169436 if( pSubOB->a[jSub].u.x.iOrderByCol==0 ) break;
169441 if( (pWInfo->wctrlFlags & WHERE_GROUPBY)==0 ){
169448 if( jSub>0 ){
169455 if( (pLoop->wsFlags & WHERE_COROUTINE)!=0 ){
169465 return jSub>0;
169473 ** N>0: N terms of the ORDER BY clause are satisfied
169474 ** N==0: No terms of the ORDER BY clause are satisfied
169475 ** N<0: Unknown yet how many terms of ORDER BY might be satisfied.
169508 WhereLoop *pLoop = 0; /* Current WhereLoop being processed. */
169514 Bitmask obSat = 0; /* Mask of ORDER BY terms satisfied so far */
169541 assert( pOrderBy!=0 );
169542 if( nLoop && OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ) return 0;
169546 if( nOrderBy>BMS-1 ) return 0; /* Cannot optimize overly large ORDER BYs */
169549 orderDistinctMask = 0;
169550 ready = 0;
169555 for(iLoop=0; isOrderDistinct && obSat<obDone && iLoop<=nLoop; iLoop++){
169556 if( iLoop>0 ) ready |= pLoop->maskSelf;
169578 for(i=0; i<nOrderBy; i++){
169581 if( NEVER(pOBExpr==0) ) continue;
169585 ~ready, eqOpMask, 0);
169586 if( pTerm==0 ) continue;
169593 for(j=0; j<pLoop->nLTerm && pTerm!=pLoop->aLTerm[j]; j++){}
169596 if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 && pOBExpr->iColumn>=0 ){
169601 if( pColl2==0 || sqlite3StrICmp(pColl1->zName, pColl2->zName) ){
169609 if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
169616 nColumn = 0;
169617 isOrderDistinct = 0;
169621 pIndex = 0;
169622 nKeyCol = 0;
169623 }else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
169624 return 0;
169636 && (pLoop->wsFlags & WHERE_SKIPSCAN)==0;
169642 rev = revSet = 0;
169643 distinctColumns = 0;
169644 for(j=0; j<nColumn; j++){
169648 || (pLoop->aLTerm[j]==0)==(j<pLoop->nSkip)
169665 if( (eOp & eqOpMask)!=0 ){
169670 isOrderDistinct = 0;
169682 bOnce = 0;
169698 revIdx = 0;
169705 if( iColumn>=0
169707 && pIndex->pTable->aCol[iColumn].notNull==0
169709 isOrderDistinct = 0;
169712 isOrderDistinct = 0;
169719 isMatch = 0;
169720 for(i=0; bOnce && i<nOrderBy; i++){
169725 if( NEVER(pOBExpr==0) ) continue;
169726 if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0;
169739 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
169747 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
169754 isMatch = 0;
169766 isMatch = 0;
169771 testcase( distinctColumns==0 );
169777 if( j==0 || j<nKeyCol ){
169778 testcase( isOrderDistinct!=0 );
169779 isOrderDistinct = 0;
169785 testcase( isOrderDistinct==0 );
169793 for(i=0; i<nOrderBy; i++){
169799 if( mTerm==0 && !sqlite3ExprIsConstant(0,p) ) continue;
169800 if( (mTerm&~orderDistinctMask)==0 ){
169808 for(i=nOrderBy-1; i>0; i--){
169809 Bitmask m = ALWAYS(i<BMS) ? MASKBIT(i) - 1 : 0;
169812 return 0;
169839 ** SELECT * FROM t1 GROUP BY y,x ORDER BY y,x; -- IsSorted()==0
169852 for(i=0; i<nLoop; i++){ zName[i] = pPath->aLoop[i]->cId; }
169854 zName[i] = 0;
169892 assert( pWInfo->pSelect!=0 );
169893 assert( pWInfo->pSelect->pEList!=0 );
169897 if( nSorted>0 ){
169907 if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 ){
169909 if( nSorted!=0 ){
169992 assert( pWLoop->pNextLoop==0 || pWLoop->iTab<=pWLoop->pNextLoop->iTab );
170003 Bitmask mSelfJoin = 0; /* Tables that cannot be dimension tables */
170015 for(iFromIdx=0, m=1; iFromIdx<nLoop; iFromIdx++, m<<=1){
170016 int nDep = 0; /* Number of dimension tables */
170018 Bitmask mSeen = 0; /* Mask of dimension tables */
170022 if( (pFactTab->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
170032 if( (aFromTabs[pWLoop->iTab].fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
170038 if( (pWLoop->prereq & m)!=0 /* pWInfo depends on iFromIdx */
170039 && (pWLoop->maskSelf & mSeen)==0 /* pWInfo not already a dependency */
170040 && (pWLoop->maskSelf & mSelfJoin)==0 /* Not a self-join */
170060 pWLoop->rStarDelta = 0;
170079 if( (pWLoop->maskSelf & mSeen)==0 ) continue;
170082 #ifdef WHERETRACE_ENABLED /* 0x80000 */
170083 if( sqlite3WhereTrace & 0x80000 ){
170098 #ifdef WHERETRACE_ENABLED /* 0x80000 */
170099 if( (sqlite3WhereTrace & 0x80000)!=0 && pWInfo->bStarUsed ){
170127 if( (pCandidate->wsFlags & WHERE_INDEXED)==0 ) return 1;
170128 if( (pBaseline->wsFlags & WHERE_INDEXED)==0 ) return 1;
170130 pBaseline->u.btree.pIndex->szIdxRow ) return 0;
170141 ** costs if nRowEst==0.
170152 int mxI = 0; /* Index of next entry to replace */
170154 LogEst mxCost = 0; /* Maximum cost of a set of paths */
170155 LogEst mxUnsort = 0; /* Maximum unsorted cost of a set of path */
170163 LogEst *aSortCost = 0; /* Sorting and partial sorting costs */
170169 WHERETRACE(0x002, ("---- begin solver. (nRowEst=%d, nQueryLoop=%d)\n",
170196 if( pWInfo->pOrderBy==0 || nRowEst==0 ){
170197 nOrderBy = 0;
170206 if( pSpace==0 ) return SQLITE_NOMEM_BKPT;
170209 memset(aFrom, 0, sizeof(aFrom[0]));
170211 for(ii=mxChoice*2, pFrom=aTo; ii>0; ii--, pFrom++, pX += nLoop){
170222 memset(aSortCost, 0, sizeof(LogEst) * nOrderBy);
170224 assert( aSortCost==0 || &pSpace[nSpace]==(char*)&aSortCost[nOrderBy] );
170225 assert( aSortCost!=0 || &pSpace[nSpace]==(char*)pX );
170232 aFrom[0].nRow = MIN(pParse->nQueryLoop, 48); assert( 48==sqlite3LogEst(28) );
170234 assert( aFrom[0].isOrdered==0 );
170242 aFrom[0].isOrdered = nLoop>0 ? -1 : nOrderBy;
170248 for(iLoop=0; iLoop<nLoop; iLoop++){
170249 nTo = 0;
170250 for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
170259 if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
170260 if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
170261 if( (pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 && pFrom->nRow<3 ){
170280 if( isOrdered<0 ){
170281 revMask = 0;
170288 if( isOrdered>=0 && isOrdered<nOrderBy ){
170289 if( aSortCost[isOrdered]==0 ){
170300 WHERETRACE(0x002,
170316 ** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent
170320 testcase( nTo==0 );
170321 for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
170323 && ((pTo->isOrdered^isOrdered)&0x80)==0
170337 #ifdef WHERETRACE_ENABLED /* 0x4 */
170338 if( sqlite3WhereTrace&0x4 ){
170341 isOrdered>=0 ? isOrdered+'0' : '?');
170356 #ifdef WHERETRACE_ENABLED /* 0x4 */
170357 if( sqlite3WhereTrace&0x4 ){
170360 isOrdered>=0 ? isOrdered+'0' : '?');
170378 #ifdef WHERETRACE_ENABLED /* 0x4 */
170379 if( sqlite3WhereTrace&0x4 ){
170383 isOrdered>=0 ? isOrdered+'0' : '?');
170385 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
170386 pTo->rUnsort, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
170396 #ifdef WHERETRACE_ENABLED /* 0x4 */
170397 if( sqlite3WhereTrace&0x4 ){
170401 isOrdered>=0 ? isOrdered+'0' : '?');
170403 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
170404 pTo->rUnsort, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
170418 mxI = 0;
170419 mxCost = aTo[0].rCost;
170420 mxUnsort = aTo[0].nRow;
170435 if( sqlite3WhereTrace & 0x02 ){
170436 LogEst rMin, rFloor = 0;
170437 int nDone = 0;
170441 nProgress = 0;
170442 rMin = 0x7fff;
170443 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
170446 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
170449 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
170450 pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?');
170451 if( pTo->isOrdered>0 ){
170452 sqlite3DebugPrintf(" rev=0x%llx\n", pTo->revLoop);
170461 }while( nDone<nTo && nProgress>0 );
170472 if( nFrom==0 ){
170485 for(iLoop=0; iLoop<nLoop; iLoop++){
170491 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0
170492 && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
170503 pWInfo->bOrderedInnerLoop = 0;
170511 assert( pWInfo->pSelect->pOrderBy==0
170515 if( pWInfo->nOBSat<=0 ){
170516 pWInfo->nOBSat = 0;
170517 if( nLoop>0 ){
170519 if( (wsFlags & WHERE_ONEROW)==0
170522 Bitmask m = 0;
170535 && (pWInfo->wctrlFlags & (WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX))!=0
170541 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0
170543 Bitmask revMask = 0;
170545 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
170547 assert( pWInfo->sorted==0 );
170610 int once = 0;
170612 for(i=0; i<pWInfo->nLevel; i++){
170614 if( p==0 ) break;
170615 if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 ) continue;
170616 if( (p->wsFlags & (WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0 ){
170621 if( (pLoop->wsFlags & (WHERE_CONSTRAINT|WHERE_AUTO_INDEX))!=0 ){
170626 if( sqlite3WhereTrace & 0x80 ){
170627 if( once==0 ){
170666 if( pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE ) return 0;
170670 if( IsVirtual(pTab) ) return 0;
170674 return 0;
170679 pLoop->wsFlags = 0;
170680 pLoop->nSkip = 0;
170681 pTerm = whereScanInit(&scan, pWC, iCur, -1, WO_EQ|WO_IS, 0);
170686 pLoop->aLTerm[0] = pTerm;
170696 || pIdx->pPartIdxWhere!=0
170700 for(j=0; j<pIdx->nKeyCol; j++){
170703 if( pTerm==0 ) break;
170709 if( pIdx->isCovering || (pItem->colUsed & pIdx->colNotIdxed)==0 ){
170722 pWInfo->a[0].pWLoop = pLoop;
170723 assert( pWInfo->sMaskSet.n==1 && iCur==pWInfo->sMaskSet.ix[0] );
170725 pWInfo->a[0].iTabCur = iCur;
170733 pLoop->cId = '0';
170736 if( sqlite3WhereTrace & 0x02 ){
170742 return 0;
170749 if( pExpr->op==TK_FUNCTION && ExprHasProperty(pExpr, EP_ConstFunc)==0 ){
170750 pWalker->eCode = 0;
170763 memset(&w, 0, sizeof(w));
170782 for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
170847 assert( pWInfo->pResultSet!=0 );
170848 assert( 0==(pWInfo->wctrlFlags & WHERE_AGG_DISTINCT) );
170854 hasRightJoin = (pWInfo->pTabList->a[0].fg.jointype & JT_LTORJ)!=0;
170863 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)==0
170864 && (pLoop->wsFlags & WHERE_ONEROW)==0
170868 if( (tabUsed & pLoop->maskSelf)!=0 ) continue;
170871 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
170886 WHERETRACE(0xffffffff,("-> omit unused FROM-clause term %c\n",pLoop->cId));
170888 testcase( ((pWInfo->revMask>>1) & ~m1)!=0 );
170892 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
170901 assert( pWInfo->nLevel>0 );
170928 LogEst nSearch = 0;
170932 for(i=0; i<pWInfo->nLevel; i++){
170937 if( (pTab->tabFlags & TF_HasStat1)==0 ) break;
170942 && ALWAYS((pLoop->wsFlags & (WHERE_IPK|WHERE_INDEXED))!=0)
170948 WHERETRACE(0xffffffff, (
170981 for(i=0; i<pIdx->nColumn; i++){
170986 }else if( j>=0 && (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)!=0 ){
170991 if( sqlite3ExprIsConstant(0,pExpr) ) continue;
170993 if( p==0 ) break;
170996 if( sqlite3WhereTrace & 0x200 ){
170998 if( sqlite3WhereTrace & 0x5000 ) sqlite3ShowExpr(pExpr);
171001 p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
171005 p->bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0;
171013 if( p->pIENext==0 ){
171030 for(ii=0; ii<pWInfo->pTabList->nSrc; ii++){
171034 || NEVER(pItem->fg.isSubquery==0)
171035 || pItem->u4.pSubq->pSelect->pOrderBy==0
171075 ** number pTabList->a[0].iCursor. t2 uses the cursor pTabList->a[1].iCursor.
171103 ** flag = 0
171109 ** if flag==0 then
171153 u8 bFordelete = 0; /* OPFLAG_FORDELETE or zero, as appropriate */
171155 assert( (wctrlFlags & WHERE_ONEPASS_MULTIROW)==0 || (
171156 (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0
171157 && (wctrlFlags & WHERE_OR_SUBCLAUSE)==0
171161 assert( (wctrlFlags & WHERE_OR_SUBCLAUSE)==0
171162 || (wctrlFlags & WHERE_USE_LIMIT)==0 );
171166 memset(&sWLB, 0, sizeof(sWLB));
171171 pOrderBy = 0;
171182 return 0;
171203 pWInfo = 0;
171213 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
171220 memset(&pWInfo->nOBSat, 0,
171222 memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel));
171225 pMaskSet->n = 0;
171226 pMaskSet->ix[0] = -99; /* Initialize ix[0] to a value that can never be
171228 ** test for pMaskSet->n==0 in sqlite3WhereGetMask() */
171246 if( nTabList==0 ){
171248 if( (wctrlFlags & WHERE_WANT_DISTINCT)!=0
171254 && (pWInfo->pSelect->selFlags & SF_MultiValue)==0
171256 ExplainQueryPlan((pParse, 0, "SCAN CONSTANT ROW"));
171273 ii = 0;
171280 Bitmask mx = 0;
171281 for(ii=0; ii<pTabList->nSrc; ii++){
171314 ** WHERE random()>0; -- eval random() once per row
171315 ** WHERE (SELECT random())>0; -- eval random() just once overall
171323 for(ii=0; ii<sWLB.pWC->nBase; ii++){
171328 assert( pX!=0 );
171329 assert( pT->prereqAll!=0 || !ExprHasProperty(pX, EP_OuterON) );
171330 if( pT->prereqAll==0 /* Conditions (1) and (2) */
171331 && (nTabList==0 || exprIsDeterministic(pX)) /* Condition (4) */
171333 && (pTabList->a[0].fg.jointype & JT_LTORJ)!=0 )
171349 }else if( pOrderBy==0 ){
171358 if( sqlite3WhereTrace & 0xffffffff ){
171359 sqlite3DebugPrintf("*** Optimizer Start *** (wctrlFlags: 0x%x",wctrlFlags);
171364 if( sqlite3WhereTrace & 0x8000 ){
171366 memset(&sSelect, 0, sizeof(sSelect));
171372 sqlite3TreeViewSelect(0, &sSelect, 0);
171374 if( sqlite3WhereTrace & 0x4000 ){ /* Display all WHERE clause terms */
171381 if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
171393 WHERETRACE(0xffffffff,
171407 wherePathSolver(pWInfo, 0);
171411 wherePathSolver(pWInfo, pWInfo->nRowOut<0 ? 1 : pWInfo->nRowOut+1);
171419 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
171420 WHERETRACE(0x0080,("nRowOut reduced from %d to %d due to DISTINCT\n",
171426 assert( pWInfo->pTabList!=0 );
171427 if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
171433 assert( db->mallocFailed==0 );
171438 if( pWInfo->nOBSat>0 ){
171439 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
171456 for(ii=0; ii<pWInfo->nLevel; ii++){
171472 notReady = ~(Bitmask)0;
171474 && pResultSet!=0 /* Condition (1) */
171475 && 0==(wctrlFlags & (WHERE_AGG_DISTINCT|WHERE_KEEP_ALL_JOINS)) /* (1),(6) */
171480 assert( nTabList>0 );
171493 if( sqlite3WhereTrace & 0x4000 ){ /* Display all terms of the WHERE clause */
171497 WHERETRACE(0xffffffff,("*** Optimizer Finished ***\n"));
171520 assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 );
171521 if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 ){
171522 int wsFlags = pWInfo->a[0].pWLoop->wsFlags;
171523 int bOnerow = (wsFlags & WHERE_ONEROW)!=0;
171524 assert( !(wsFlags&WHERE_VIRTUALTABLE) || IsVirtual(pTabList->a[0].pSTab) );
171526 0!=(wctrlFlags & WHERE_ONEPASS_MULTIROW)
171527 && !IsVirtual(pTabList->a[0].pSTab)
171528 && (0==(wsFlags & WHERE_MULTI_OR) || (wctrlFlags & WHERE_DUPLICATES_OK))
171532 if( HasRowid(pTabList->a[0].pSTab) && (wsFlags & WHERE_IDX_ONLY) ){
171536 pWInfo->a[0].pWLoop->wsFlags = (wsFlags & ~WHERE_IDX_ONLY);
171544 for(ii=0, pLevel=pWInfo->a; ii<nTabList; ii++, pLevel++){
171553 if( (pTab->tabFlags & TF_Ephemeral)!=0 || IsView(pTab) ){
171557 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
171560 sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
171565 if( ((pLoop->wsFlags & WHERE_IDX_ONLY)==0
171566 && (wctrlFlags & WHERE_OR_SUBCLAUSE)==0)
171567 || (pTabItem->fg.jointype & (JT_LTORJ|JT_RIGHT))!=0
171572 pWInfo->aiCurOnePass[0] = pTabItem->iCursor;
171580 && (pTab->tabFlags & (TF_HasGenerated|TF_WithoutRowid))==0
171581 && (pLoop->wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))==0
171587 int n = 0;
171593 if( pLoop->u.btree.pIndex!=0 && (pTab->tabFlags & TF_WithoutRowid)==0 ){
171601 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, pTabItem->iCursor, 0, 0,
171605 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
171612 assert( iAuxArg!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
171614 && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0
171619 op = 0;
171630 }else if( iAuxArg && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 ){
171638 if( pIx->pPartIdxWhere && (pTabItem->fg.jointype & JT_RIGHT)==0 ){
171640 pParse, pIx, pIx->pPartIdxWhere, 0, iIndexCur, pTabItem
171645 assert( pIx!=0 );
171647 assert( iIndexCur>=0 );
171651 if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
171652 && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
171653 && (pLoop->wsFlags & WHERE_BIGNULL_SORT)==0
171654 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0
171655 && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
171663 u64 colUsed = 0;
171665 for(ii=0; ii<pIx->nColumn; ii++){
171667 if( jj<0 ) continue;
171669 if( (pTabItem->colUsed & MASKBIT(jj))==0 ) continue;
171672 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, iIndexCur, 0, 0,
171678 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
171679 if( (pTabItem->fg.jointype & JT_RIGHT)!=0
171680 && (pLevel->pRJ = sqlite3WhereMalloc(pWInfo, sizeof(WhereRightJoin)))!=0
171687 sqlite3VdbeAddOp2(v, OP_Null, 0, pRJ->regReturn);
171692 pInfo = sqlite3KeyInfoAlloc(pParse->db, 1, 0);
171694 pInfo->aColl[0] = 0;
171695 pInfo->aSortFlags[0] = 0;
171707 pWInfo->nOBSat = 0;
171718 for(ii=0; ii<nTabList; ii++){
171728 int iOnce = 0;
171731 if( pSrc->fg.isCorrelated==0 ){
171734 iOnce = 0;
171741 if( (wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))!=0 ){
171742 if( (wsFlags & WHERE_AUTO_INDEX)!=0 ){
171757 if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_OR_SUBCLAUSE)==0 ){
171776 sqlite3ShowWhereLoopList(0);
171778 return 0;
171796 if( (db->flags & SQLITE_VdbeAddopTrace)==0 ) return;
171797 sqlite3VdbePrintOp(0, pc, pOp);
171798 sqlite3ShowWhereTerm(0); /* So compiler won't complain about unused func */
171815 int nRJ = 0;
171820 for(i=pWInfo->nLevel-1; i>=0; i--){
171828 pLevel->addrCont = 0;
171837 int addrSeek = 0;
171842 && (pLoop->wsFlags & WHERE_INDEXED)!=0
171844 && (n = pLoop->u.btree.nDistinctCol)>0
171849 for(j=0; j<n; j++){
171854 addrSeek = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
171879 if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
171883 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
171890 (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0
171891 && (pLoop->wsFlags & WHERE_IN_EARLYOUT)!=0;
171927 sqlite3VdbeAddOp3(v, OP_Return, pLevel->pRJ->regReturn, 0, 1);
171946 assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 );
171947 if( (ws & WHERE_IDX_ONLY)==0 ){
171954 assert( pSrc->pSTab!=0 );
171956 sqlite3VdbeAddOp3(v, OP_Null, 0, n, n+m-1);
171983 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
171986 Index *pIdx = 0;
171989 assert( pTab!=0 );
172008 assert( pTabItem->u4.pSubq->regResult>=0 );
172010 pTabItem->u4.pSubq->regResult, 0);
172043 if( sqlite3WhereTrace & 0x200 ){
172046 if( sqlite3WhereTrace & 0x5000 ) sqlite3ShowExpr(p->pExpr);
172088 assert( x>=0 );
172094 if( x>=0 ){
172313 sqlite3_result_int64(pCtx, (p ? *p : 0));
172349 p->nStep = 0;
172386 if( iVal<=0 ) goto error_out;
172390 p->pValue = sqlite3_value_dup(apArg[0]);
172407 p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, 0);
172411 p->pValue = 0;
172424 if( p && p->pValue==0 ){
172425 p->pValue = sqlite3_value_dup(apArg[0]);
172439 p->pValue = 0;
172460 if( p->nValue==0 ){
172472 p->nValue = 0;
172488 UNUSED_PARAMETER(nArg); assert( nArg==0 );
172501 UNUSED_PARAMETER(nArg); assert( nArg==0 );
172533 UNUSED_PARAMETER(nArg); assert( nArg==0 );
172546 UNUSED_PARAMETER(nArg); assert( nArg==0 );
172553 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, 0);
172585 if( p->nTotal==0 ){
172586 p->nParam = sqlite3_value_int64(apArg[0]);
172587 if( p->nParam<=0 ){
172610 if( p && p->nParam>0 ){
172612 if( nSize==0 ){
172652 p->pVal = sqlite3_value_dup(apArg[0]);
172653 if( p->pVal==0 ){
172671 if( p->nVal==0 ){
172673 p->pVal = 0;
172679 p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, 0);
172690 p->pVal = 0;
172731 assert(0); /*NO_TEST*/
172738 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
172740 name ## InvFunc, name ## Name, {0} \
172746 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
172748 noopStepFunc, name ## Name, {0} \
172755 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
172757 noopStepFunc, name ## Name, {0} \
172766 WINDOWFUNCX(row_number, 0, 0),
172767 WINDOWFUNCX(dense_rank, 0, 0),
172768 WINDOWFUNCX(rank, 0, 0),
172769 WINDOWFUNCALL(percent_rank, 0, 0),
172770 WINDOWFUNCALL(cume_dist, 0, 0),
172771 WINDOWFUNCALL(ntile, 1, 0),
172772 WINDOWFUNCALL(last_value, 1, 0),
172773 WINDOWFUNCALL(nth_value, 2, 0),
172774 WINDOWFUNCALL(first_value, 1, 0),
172775 WINDOWFUNCNOOP(lead, 1, 0),
172776 WINDOWFUNCNOOP(lead, 2, 0),
172777 WINDOWFUNCNOOP(lead, 3, 0),
172778 WINDOWFUNCNOOP(lag, 1, 0),
172779 WINDOWFUNCNOOP(lag, 2, 0),
172780 WINDOWFUNCNOOP(lag, 3, 0),
172788 if( sqlite3StrICmp(p->zName, zName)==0 ) break;
172790 if( p==0 ){
172819 if( pWin->zName && pWin->eFrmType==0 ){
172821 if( p==0 ) return;
172822 pWin->pPartition = sqlite3ExprListDup(pParse->db, p->pPartition, 0);
172823 pWin->pOrderBy = sqlite3ExprListDup(pParse->db, p->pOrderBy, 0);
172824 pWin->pStart = sqlite3ExprDup(pParse->db, p->pStart, 0);
172825 pWin->pEnd = sqlite3ExprDup(pParse->db, p->pEnd, 0);
172835 && (pWin->pOrderBy==0 || pWin->pOrderBy->nExpr!=1)
172864 for(i=0; i<ArraySize(aUp); i++){
172868 pWin->pEnd = pWin->pStart = 0;
172872 pWin->eExclude = 0;
172905 assert( p!=0 );
172906 assert( p->pWin!=0 );
172919 for(i=0; i<nSrc; i++){
172949 for(i=0; i<p->pSub->nExpr; i++){
172950 if( 0==sqlite3ExprCompare(0, p->pSub->a[i].pExpr, pExpr, -1) ){
172956 if( iCol<0 ){
172957 Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0);
172963 assert( ExprHasProperty(pExpr, EP_Static)==0 );
172967 memset(pExpr, 0, sizeof(Expr));
172970 pExpr->iColumn = (iCol<0 ? p->pSub->nExpr-1: iCol);
173023 assert( pWin!=0 );
173024 memset(&sWalker, 0, sizeof(Walker));
173025 memset(&sRewrite, 0, sizeof(WindowRewrite));
173054 int nInit = pList ? pList->nExpr : 0;
173055 for(i=0; i<pAppend->nExpr; i++){
173057 Expr *pDup = sqlite3ExprDup(db, pAppend->a[i].pExpr, 0);
173066 if( sqlite3ExprIsInteger(pSub, &iDummy, 0) ){
173069 pSub->u.zToken = 0;
173097 if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){
173115 && p->pPrior==0
173116 && ALWAYS((p->selFlags & SF_WinRewrite)==0)
173121 Select *pSub = 0; /* The subquery */
173126 ExprList *pSort = 0;
173128 ExprList *pSublist = 0; /* Expression list for sub-query */
173137 if( pTab==0 ){
173142 if( (p->selFlags & SF_Aggregate)==0 ){
173144 w.xSelectCallback = 0;
173148 p->pSrc = 0;
173149 p->pWhere = 0;
173150 p->pGroupBy = 0;
173151 p->pHaving = 0;
173158 pSort = exprListAppendList(pParse, 0, pMWin->pPartition, 1);
173163 if( sqlite3ExprListCompare(pSort, p->pOrderBy, -1)==0 ){
173165 p->pOrderBy = 0;
173178 pMWin->nBufferCol = (pSublist ? pSublist->nExpr : 0);
173183 pSublist = exprListAppendList(pParse, pSublist, pMWin->pPartition, 0);
173184 pSublist = exprListAppendList(pParse, pSublist, pMWin->pOrderBy, 0);
173193 assert( pWin->pWFunc!=0 );
173197 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
173200 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
173201 pSublist = exprListAppendList(pParse, pSublist, pArgs, 0);
173204 Expr *pFilter = sqlite3ExprDup(db, pWin->pFilter, 0);
173209 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
173218 if( pSublist==0 ){
173219 pSublist = sqlite3ExprListAppend(pParse, 0,
173220 sqlite3Expr(db, TK_INTEGER, "0")
173225 pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
173227 TREETRACE(0x40,pParse,pSub,
173230 p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
173231 assert( pSub!=0 || p->pSrc==0 ); /* Due to db->mallocFailed test inside
173234 if( p->pSrc==0 ){
173236 }else if( sqlite3SrcItemAttachSubquery(pParse, &p->pSrc->a[0], pSub, 0) ){
173238 p->pSrc->a[0].fg.isCorrelated = 1;
173243 if( pTab2==0 ){
173251 p->pSrc->a[0].pSTab = pTab;
173253 memset(&w, 0, sizeof(w));
173268 assert( rc==SQLITE_OK || pParse->nErr!=0 );
173280 p->ppThis = 0;
173320 if( 0==sqlite3ExprIsConstant(0,pExpr) ){
173323 pExpr = sqlite3ExprAlloc(pParse->db, TK_NULL, 0, 0);
173333 int eType, /* Frame type. TK_RANGE, TK_ROWS, TK_GROUPS, or 0 */
173340 Window *pWin = 0;
173341 int bImplicitFrame = 0;
173344 assert( eType==0 || eType==TK_RANGE || eType==TK_ROWS || eType==TK_GROUPS );
173349 assert( (eStart==TK_PRECEDING || eStart==TK_FOLLOWING)==(pStart!=0) );
173350 assert( (eEnd==TK_FOLLOWING || eEnd==TK_PRECEDING)==(pEnd!=0) );
173352 if( eType==0 ){
173379 if( pWin==0 ) goto windowAllocErr;
173383 if( eExclude==0 && OptimizationDisabled(pParse->db, SQLITE_WindowFunc) ){
173395 return 0;
173435 const char *zErr = 0;
173441 }else if( pExist->bImplicitFrame==0 ){
173449 pWin->pPartition = sqlite3ExprListDup(db, pExist->pPartition, 0);
173451 assert( pWin->pOrderBy==0 );
173452 pWin->pOrderBy = sqlite3ExprListDup(db, pExist->pOrderBy, 0);
173455 pWin->zBase = 0;
173490 if( 0==pSel->pWin || 0==sqlite3WindowCompare(0, pSel->pWin, pWin, 0) ){
173506 ** Return 0 if the two window objects are identical, 1 if they are
173517 if( NEVER(p1==0) || NEVER(p2==0) ) return 1;
173535 return 0;
173550 assert( pSelect->pSrc->a[0].fg.isSubquery );
173551 nEphExpr = pSelect->pSrc->a[0].u4.pSubq->pSelect->pEList->nExpr;
173566 sqlite3VdbeAddOp3(v, OP_Null, 0, pMWin->regPart, pMWin->regPart+nExpr-1);
173577 sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
173588 ** regApp+0: slot to copy min()/max() argument to for MakeRecord
173596 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
173601 assert( pKeyInfo->aSortFlags[0]==0 );
173602 pKeyInfo->aSortFlags[0] = KEYINFO_ORDER_DESC;
173606 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
173623 #define WINDOW_STARTING_INT 0
173630 ** A "PRECEDING <expr>" (eCond==0) or "FOLLOWING <expr>" (eCond==1) or the
173647 assert( eCond>=0 && eCond<ArraySize(azErr) );
173648 sqlite3VdbeAddOp2(v, OP_Integer, 0, regZero);
173651 sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
173661 assert( eCond==0 || eCond==1 || eCond==2 );
173662 VdbeCoverageIf(v, eCond==0);
173668 VdbeCoverageNeverNullIf(v, eCond==0); /* NULL case captured by */
173687 return (pList ? pList->nExpr : 0);
173754 ** 0.
173785 int iColOff = pMWin->nBufferCol + (pPart ? pPart->nExpr : 0);
173787 for(i=0; i<pOrderBy->nExpr; i++){
173794 ** Generate VM code to invoke either xStep() (if bInverse is 0) or
173800 ** If argument csr is greater than or equal to 0, then argument reg is
173825 int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin);
173827 int addrIf = 0;
173829 assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );
173833 assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)!=1 );
173835 for(i=0; i<nArg; i++){
173848 assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
173851 addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
173856 if( pMWin->regStartRowid==0
173862 if( bInverse==0 ){
173868 sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
173875 assert( pWin->pFilter==0 );
173879 assert( bInverse==0 || bInverse==1 );
173889 sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
173900 assert( nArg>0 );
173902 pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
173903 sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
173926 ** Generate VM code to invoke either xValue() (bFin==0) or xFinalize()
173938 if( pMWin->regStartRowid==0
173942 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
173945 sqlite3VdbeAddOp3(v, OP_Column, pWin->csrApp, 0, pWin->regResult);
173948 assert( pMWin->regStartRowid==0 );
173955 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
173976 int regCRowid = 0; /* Current rowid value */
173977 int regCPeer = 0; /* Current peer values */
173978 int regRowid = 0; /* AggStep rowid value */
173979 int regPeer = 0; /* AggStep peer values */
173989 assert( pMWin!=0 );
173991 nPeer = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
174007 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
174022 int addrEq = 0;
174023 KeyInfo *pKeyInfo = 0;
174026 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pMWin->pOrderBy, 0, 0);
174029 addrEq = sqlite3VdbeAddOp3(v, OP_Eq, regCRowid, 0, regRowid);
174040 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblNext);
174045 windowAggStep(p, pMWin, csr, 0, p->regArg);
174095 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
174106 sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, 0, tmpReg);
174120 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
174156 int nArg = 0;
174161 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
174163 if( pMWin->regStartRowid==0 ){
174165 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp);
174166 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
174172 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
174198 return 0;
174221 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
174230 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
174282 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_DESC ){
174315 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_BIGNULL ){
174320 sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
174332 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
174354 sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
174355 addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
174367 pColl = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[0].pExpr);
174398 int ret = 0;
174400 int addrContinue = 0;
174404 int addrNextRange = 0;
174409 assert( regCountdown==0 && jumpOnEof==0 );
174410 return 0;
174413 if( regCountdown>0 ){
174438 if( op==WINDOW_RETURN_ROW && pMWin->regStartRowid==0 ){
174439 windowAggFinal(p, 0);
174495 windowAggStep(p, pMWin, csr, 0, p->regArg);
174513 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblDone);
174518 int nReg = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
174519 int regTmp = (nReg ? sqlite3GetTempRange(pParse, nReg) : 0);
174526 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNextRange);
174539 Window *pNew = 0;
174545 pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0);
174547 pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0);
174548 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0);
174558 pNew->pStart = sqlite3ExprDup(db, p->pStart, 0);
174559 pNew->pEnd = sqlite3ExprDup(db, p->pEnd, 0);
174573 Window *pRet = 0;
174577 *pp = sqlite3WindowDup(db, 0, pWin);
174578 if( *pp==0 ) break;
174594 int ret = 0;
174596 sqlite3_value *pVal = 0;
174598 if( pVal && sqlite3_value_int(pVal)>0 ){
174639 ** if( (regEnd--)<=0 ){
174641 ** if( (regStart--)<=0 ){
174652 ** if( (regStart--)<=0 ){
174692 ** if( (regEnd--)<=0 ){
174696 ** if( (regStart--)<=0 ){
174702 ** if( (regEnd--)<=0 ){
174721 ** if( (regEnd--)<=0 ){
174724 ** if( (regStart--)<=0 ){
174732 ** if( (regEnd--)<=0 ){
174736 ** if( (regStart--)<=0 ){
174747 ** CURRENT ROW by assuming that it is equivalent to "0 PRECEDING/FOLLOWING".
174769 ** if( (regStart--)<=0 ){
174951 int csrInput = p->pSrc->a[0].iCursor; /* Cursor of sub-select */
174952 int nInput = p->pSrc->a[0].pSTab->nCol; /* Number of cols returned by sub */
174955 int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */
174956 int addrInteger = 0; /* Address of OP_Integer */
174960 int regNewPeer = 0; /* Peer values for new row (part of regNew) */
174961 int regPeer = 0; /* Peer values for current row */
174962 int regFlushPart = 0; /* Register for "Gosub flush_partition" */
174965 int regStart = 0; /* Value of <expr> PRECEDING */
174966 int regEnd = 0; /* Value of <expr> FOLLOWING */
174974 assert( pMWin->eExclude==0 || pMWin->eExclude==TK_CURRENT
174982 memset(&s, 0, sizeof(WindowCodeArg));
174994 ** are four options - they may never be deleted (eDelete==0), they may
175008 if( windowCacheFrame(pMWin)==0 ){
175047 int nPeer = (pOrderBy ? pOrderBy->nExpr : 0);
175059 for(iInput=0; iInput<nInput; iInput++){
175074 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
175089 addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, s.regRowid);
175097 windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE?3:0));
175101 windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE?3:0));
175106 int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
175109 windowAggFinal(&s, 0);
175113 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
175133 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
175142 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
175148 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175149 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
175150 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
175153 windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 0);
175154 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175160 windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
175161 if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175162 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
175163 if( !bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175165 int addr = 0;
175166 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
175169 int lbl = 0;
175175 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
175176 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175178 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
175183 addr = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0, 1);
175186 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
175187 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175199 addrInteger = sqlite3VdbeAddOp2(v, OP_Integer, 0, regFlushPart);
175203 s.regRowid = 0;
175208 windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
175209 if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175210 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
175216 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
175220 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
175225 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, 0, 1);
175232 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
175235 addrBreak3 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
175236 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
175242 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
175244 addrBreak = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
175245 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
175246 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
175255 sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
175363 memset(&pParse->u1.cr, 0, sizeof(pParse->u1.cr));
175395 assert( p!=0 );
175397 Select *pNext = 0, *pLoop = p;
175404 if( pLoop==0 ) break;
175408 pLoop->pOrderBy!=0 ? "ORDER BY" : "LIMIT",
175413 if( (p->selFlags & (SF_MultiValue|SF_Values))==0
175414 && (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
175440 return sqlite3FaultSim(700) ? 0 : sqlite3_realloc(pOld, newSize);
175448 /* memset(p, 0, sizeof(Expr)); */
175450 p->affExpr = 0;
175454 p->pLeft = p->pRight = 0;
175455 p->pAggInfo = 0;
175456 memset(&p->x, 0, sizeof(p->x));
175457 memset(&p->y, 0, sizeof(p->y));
175458 p->op2 = 0;
175459 p->iTable = 0;
175460 p->iColumn = 0;
175463 p->u.zToken[t.n] = 0;
175465 if( sqlite3Isquote(p->u.zToken[0]) ){
175468 #if SQLITE_MAX_EXPR_DEPTH>0
175486 pA->pRight = 0;
175502 ExprList *p = sqlite3ExprListAppend(pParse, pPrior, 0);
175504 && pParse->db->init.busy==0
175828 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
175845 #if YYSTACKDEPTH<=0 || YYDYNSTACK
175848 # define YYGROWABLESTACK 0
175853 #if YYSTACKDEPTH<=0
175867 ** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
175911 /* 0 */ 130, 127, 234, 282, 282, 1328, 576, 1307, 460, 289,
176134 /* 0 */ 277, 278, 279, 241, 242, 225, 195, 227, 195, 241,
176314 /* 1800 */ 158, 0, 1, 2, 247, 227, 5, 221, 221, 221,
176376 #define YY_SHIFT_MIN (0)
176379 /* 0 */ 2029, 1801, 2043, 1380, 1380, 318, 271, 1496, 1569, 1642,
176380 /* 10 */ 702, 702, 702, 740, 318, 318, 318, 318, 318, 0,
176381 /* 20 */ 0, 216, 1177, 702, 702, 702, 702, 702, 702, 702,
176443 /* 0 */ -67, 1252, -64, -178, -181, 160, 1071, 143, -184, 137,
176487 /* 0 */ 1663, 1663, 1663, 1491, 1254, 1367, 1254, 1254, 1254, 1254,
176565 0, /* $ => nothing */
176566 0, /* SEMI => nothing */
176571 0, /* TRANSACTION => nothing */
176575 0, /* COMMIT => nothing */
176580 0, /* TO => nothing */
176581 0, /* TABLE => nothing */
176582 0, /* CREATE => nothing */
176584 0, /* NOT => nothing */
176585 0, /* EXISTS => nothing */
176587 0, /* LP => nothing */
176588 0, /* RP => nothing */
176589 0, /* AS => nothing */
176590 0, /* COMMA => nothing */
176608 0, /* OR => nothing */
176609 0, /* AND => nothing */
176610 0, /* IS => nothing */
176611 0, /* ISNOT => nothing */
176614 0, /* BETWEEN => nothing */
176615 0, /* IN => nothing */
176616 0, /* ISNULL => nothing */
176617 0, /* NOTNULL => nothing */
176618 0, /* NE => nothing */
176619 0, /* EQ => nothing */
176620 0, /* GT => nothing */
176621 0, /* LE => nothing */
176622 0, /* LT => nothing */
176623 0, /* GE => nothing */
176624 0, /* ESCAPE => nothing */
176625 0, /* ID => nothing */
176667 0, /* ANY => nothing */
176668 0, /* BITAND => nothing */
176669 0, /* BITOR => nothing */
176670 0, /* LSHIFT => nothing */
176671 0, /* RSHIFT => nothing */
176672 0, /* PLUS => nothing */
176673 0, /* MINUS => nothing */
176674 0, /* STAR => nothing */
176675 0, /* SLASH => nothing */
176676 0, /* REM => nothing */
176677 0, /* CONCAT => nothing */
176678 0, /* PTR => nothing */
176679 0, /* COLLATE => nothing */
176680 0, /* BITNOT => nothing */
176681 0, /* ON => nothing */
176682 0, /* INDEXED => nothing */
176683 0, /* STRING => nothing */
176684 0, /* JOIN_KW => nothing */
176685 0, /* CONSTRAINT => nothing */
176686 0, /* DEFAULT => nothing */
176687 0, /* NULL => nothing */
176688 0, /* PRIMARY => nothing */
176689 0, /* UNIQUE => nothing */
176690 0, /* CHECK => nothing */
176691 0, /* REFERENCES => nothing */
176692 0, /* AUTOINCR => nothing */
176693 0, /* INSERT => nothing */
176694 0, /* DELETE => nothing */
176695 0, /* UPDATE => nothing */
176696 0, /* SET => nothing */
176697 0, /* DEFERRABLE => nothing */
176698 0, /* FOREIGN => nothing */
176699 0, /* DROP => nothing */
176700 0, /* UNION => nothing */
176701 0, /* ALL => nothing */
176702 0, /* EXCEPT => nothing */
176703 0, /* INTERSECT => nothing */
176704 0, /* SELECT => nothing */
176705 0, /* VALUES => nothing */
176706 0, /* DISTINCT => nothing */
176707 0, /* DOT => nothing */
176708 0, /* FROM => nothing */
176709 0, /* JOIN => nothing */
176710 0, /* USING => nothing */
176711 0, /* ORDER => nothing */
176712 0, /* GROUP => nothing */
176713 0, /* HAVING => nothing */
176714 0, /* LIMIT => nothing */
176715 0, /* WHERE => nothing */
176716 0, /* RETURNING => nothing */
176717 0, /* INTO => nothing */
176718 0, /* NOTHING => nothing */
176719 0, /* FLOAT => nothing */
176720 0, /* BLOB => nothing */
176721 0, /* INTEGER => nothing */
176722 0, /* VARIABLE => nothing */
176723 0, /* CASE => nothing */
176724 0, /* WHEN => nothing */
176725 0, /* THEN => nothing */
176726 0, /* ELSE => nothing */
176727 0, /* INDEX => nothing */
176728 0, /* ALTER => nothing */
176729 0, /* ADD => nothing */
176730 0, /* WINDOW => nothing */
176731 0, /* OVER => nothing */
176732 0, /* FILTER => nothing */
176733 0, /* COLUMN => nothing */
176734 0, /* AGG_FUNCTION => nothing */
176735 0, /* AGG_COLUMN => nothing */
176736 0, /* TRUEFALSE => nothing */
176737 0, /* FUNCTION => nothing */
176738 0, /* UPLUS => nothing */
176739 0, /* UMINUS => nothing */
176740 0, /* TRUTH => nothing */
176741 0, /* REGISTER => nothing */
176742 0, /* VECTOR => nothing */
176743 0, /* SELECT_COLUMN => nothing */
176744 0, /* IF_NULL_ROW => nothing */
176745 0, /* ASTERISK => nothing */
176746 0, /* SPAN => nothing */
176747 0, /* ERROR => nothing */
176748 0, /* QNUMBER => nothing */
176749 0, /* SPACE => nothing */
176750 0, /* COMMENT => nothing */
176751 0, /* ILLEGAL => nothing */
176801 static FILE *yyTraceFILE = 0;
176802 static char *yyTracePrompt = 0;
176826 if( yyTraceFILE==0 ) yyTracePrompt = 0;
176827 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
176835 /* 0 */ "$",
177165 /* 0 */ "explain ::= EXPLAIN",
177581 ** of errors. Return 0 on success.
177592 pNew = YYREALLOC(0, newSize*sizeof(pNew[0]));
177593 if( pNew==0 ) return 1;
177594 memcpy(pNew, p->yystack, oldSize*sizeof(pNew[0]));
177596 pNew = YYREALLOC(p->yystack, newSize*sizeof(pNew[0]));
177597 if( pNew==0 ) return 1;
177608 return 0;
177634 yypParser->yyhwm = 0;
177642 yypParser->yystack[0].stateno = 0;
177643 yypParser->yystack[0].major = 0;
177804 assert( pParser->yytos!=0 );
177859 if( p==0 ) return;
177896 int nMissed = 0;
177897 for(stateno=0; stateno<YYNSTATE; stateno++){
177899 for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
177901 if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
177930 assert( i>=0 );
177940 assert( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) );
177942 if( iFallback!=0 ){
177949 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
177957 assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) );
177958 if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){
177972 assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) );
177998 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
178002 assert( i>=0 && i<YY_ACTTAB_COUNT );
178090 191, /* (0) explain ::= EXPLAIN */
178504 -1, /* (0) explain ::= EXPLAIN */
178508 0, /* (4) transtype ::= */
178519 0, /* (15) ifnotexists ::= */
178522 0, /* (18) temp ::= */
178525 0, /* (21) table_option_set ::= */
178530 0, /* (26) typetoken ::= */
178534 0, /* (30) scanpt ::= */
178535 0, /* (31) scantok ::= */
178551 0, /* (47) autoinc ::= */
178553 0, /* (49) refargs ::= */
178566 0, /* (62) init_deferred_pred_opt ::= */
178569 0, /* (65) conslist_opt ::= */
178576 0, /* (72) defer_subclause_opt ::= */
178577 0, /* (73) onconf ::= */
178579 0, /* (75) orconf ::= */
178585 0, /* (81) ifexists ::= */
178604 0, /* (100) distinct ::= */
178605 0, /* (101) sclp ::= */
178610 0, /* (106) as ::= */
178611 0, /* (107) from ::= */
178614 0, /* (110) stl_prefix ::= */
178620 0, /* (116) dbnm ::= */
178634 0, /* (130) on_using ::= */
178635 0, /* (131) indexed_opt ::= */
178638 0, /* (134) orderby_opt ::= */
178644 0, /* (140) sortorder ::= */
178647 0, /* (143) nulls ::= */
178648 0, /* (144) groupby_opt ::= */
178650 0, /* (146) having_opt ::= */
178652 0, /* (148) limit_opt ::= */
178657 0, /* (153) where_opt ::= */
178659 0, /* (155) where_opt_ret ::= */
178670 0, /* (166) upsert ::= */
178679 0, /* (175) idlist_opt ::= */
178736 0, /* (232) case_else ::= */
178737 0, /* (233) case_operand ::= */
178738 0, /* (234) exprlist ::= */
178741 0, /* (237) paren_exprlist ::= */
178745 0, /* (241) uniqueflag ::= */
178746 0, /* (242) eidlist_opt ::= */
178750 0, /* (246) collate ::= */
178756 0, /* (252) vinto ::= */
178768 0, /* (264) trigger_time ::= */
178772 0, /* (268) when_clause ::= */
178791 0, /* (287) key_opt ::= */
178805 0, /* (301) vtabarg ::= */
178825 0, /* (321) frame_opt ::= */
178835 0, /* (331) frame_exclude_opt ::= */
178854 0, /* (350) trans_opt ::= */
178858 0, /* (354) savepoint_opt ::= */
178870 0, /* (366) carglist ::= */
178877 0, /* (373) tconscomma ::= */
178885 0, /* (381) returning ::= */
178896 0, /* (392) foreach_clause ::= */
178899 0, /* (395) tridxby ::= */
178901 0, /* (397) database_kw_opt ::= */
178902 0, /* (398) kwcolumn_opt ::= */
178907 0, /* (403) anylist ::= */
178910 0, /* (406) with ::= */
178946 ** case 0:
178954 case 0: /* explain ::= EXPLAIN */
178955 { if( pParse->pReprepare==0 ) pParse->explain = 1; }
178958 { if( pParse->pReprepare==0 ) pParse->explain = 2; }
178973 {yymsp[0].minor.yy502 = yymsp[0].major; /*A-overwrites-X*/}
178981 sqlite3Savepoint(pParse, SAVEPOINT_BEGIN, &yymsp[0].minor.yy0);
178986 sqlite3Savepoint(pParse, SAVEPOINT_RELEASE, &yymsp[0].minor.yy0);
178991 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
178996 …sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy502,0,0,yymsp[…
179012 {yymsp[1].minor.yy502 = 0;}
179018 {yymsp[0].minor.yy502 = pParse->db->init.busy==0;}
179022 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy9,0);
179027 sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy637);
179028 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy637);
179032 {yymsp[1].minor.yy9 = 0;}
179035 {yylhsminor.yy9 = yymsp[-2].minor.yy9|yymsp[0].minor.yy9;}
179040 if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
179043 yymsp[-1].minor.yy9 = 0;
179044 … sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
179050 if( yymsp[0].minor.yy0.n==6 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"strict",6)==0 ){
179053 yylhsminor.yy9 = 0;
179054 … sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
179057 yymsp[0].minor.yy9 = yylhsminor.yy9;
179060 {sqlite3AddColumn(pParse,yymsp[-1].minor.yy0,yymsp[0].minor.yy0);}
179065 {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;}
179069 …yymsp[-3].minor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
179074 …yymsp[-5].minor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
179078 {yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
179094 {ASSERT_IS_CREATE; pParse->u1.cr.constraintName = yymsp[0].minor.yy0;}
179097 {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy590,yymsp[-1].minor.yy0.z,&yymsp[-1].minor.yy0.z[yy…
179100 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy590,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);}
179103 {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy590,yymsp[-2].minor.yy0.z,&yymsp[-1].minor.yy0.z[yy…
179107 Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy590, 0);
179113 Expr *p = tokenExpr(pParse, TK_STRING, yymsp[0].minor.yy0);
179118 sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n);
179122 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy502);}
179125 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy502,yymsp[0].minor.yy502,yymsp[-2].minor.yy502);}
179128 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy502,0,0,0,0,
179132 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy590,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy0.z)…
179135 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy402,yymsp[0].minor.yy502);}
179138 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy502);}
179141 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
179144 {sqlite3AddGenerated(pParse,yymsp[-1].minor.yy590,0);}
179147 {sqlite3AddGenerated(pParse,yymsp[-2].minor.yy590,&yymsp[0].minor.yy0);}
179150 {yymsp[0].minor.yy502 = 1;}
179153 { yymsp[1].minor.yy502 = OE_None*0x0101; /* EV: R-19803-45884 */}
179156 { yymsp[-1].minor.yy502 = (yymsp[-1].minor.yy502 & ~yymsp[0].minor.yy481.mask) | yymsp[0].minor.yy4…
179159 { yymsp[-1].minor.yy481.value = 0; yymsp[-1].minor.yy481.mask = 0x000000; }
179162 { yymsp[-2].minor.yy481.value = 0; yymsp[-2].minor.yy481.mask = 0x000000; }
179165 { yymsp[-2].minor.yy481.value = yymsp[0].minor.yy502; yymsp[-2].minor.yy481.mask = 0x0000ff; }
179168 { yymsp[-2].minor.yy481.value = yymsp[0].minor.yy502<<8; yymsp[-2].minor.yy481.mask = 0x00ff00; }
179177 { yymsp[0].minor.yy502 = OE_Cascade; /* EV: R-33326-45252 */}
179180 { yymsp[0].minor.yy502 = OE_Restrict; /* EV: R-33326-45252 */}
179186 {yymsp[-2].minor.yy502 = 0;}
179191 {yymsp[-1].minor.yy502 = yymsp[0].minor.yy502;}
179201 {yymsp[-1].minor.yy502 = 0;}
179204 {ASSERT_IS_CREATE; pParse->u1.cr.constraintName.n = 0;}
179207 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy402,yymsp[0].minor.yy502,yymsp[-2].minor.yy502,0);}
179210 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy402,yymsp[0].minor.yy502,0,0,0,0,
179219 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy502);
179227 {yymsp[-2].minor.yy502 = yymsp[0].minor.yy502;}
179230 {yymsp[0].minor.yy502 = OE_Ignore;}
179234 {yymsp[0].minor.yy502 = OE_Replace;}
179238 sqlite3DropTable(pParse, yymsp[0].minor.yy563, 0, yymsp[-1].minor.yy502);
179243 …0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy402, yymsp[0].minor.yy637, yymsp[…
179248 sqlite3DropTable(pParse, yymsp[0].minor.yy563, 1, yymsp[-1].minor.yy502);
179253 SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0, 0};
179254 if( (pParse->db->mDbFlags & DBFLAG_EncodingFixed)!=0
179257 sqlite3Select(pParse, yymsp[0].minor.yy637, &dest);
179259 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy637);
179263 {yymsp[-2].minor.yy637 = attachWithToSelect(pParse,yymsp[0].minor.yy637,yymsp[-1].minor.yy125);}
179266 {yymsp[-3].minor.yy637 = attachWithToSelect(pParse,yymsp[0].minor.yy637,yymsp[-1].minor.yy125);}
179270 Select *p = yymsp[0].minor.yy637;
179278 Select *pRhs = yymsp[0].minor.yy637;
179283 x.n = 0;
179285 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0);
179286 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
179302 {yymsp[0].minor.yy502 = yymsp[0].major; /*A-overwrites-OP*/}
179309 …inor.yy402,yymsp[-2].minor.yy590,yymsp[-1].minor.yy402,yymsp[-7].minor.yy502,yymsp[0].minor.yy590);
179314 …inor.yy402,yymsp[-3].minor.yy590,yymsp[-1].minor.yy402,yymsp[-8].minor.yy502,yymsp[0].minor.yy590);
179324 yymsp[-3].minor.yy637 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy402,0,0,0,0,0,SF_Values,0);
179329 sqlite3MultiValuesEnd(pParse, yymsp[0].minor.yy637);
179339 {yymsp[0].minor.yy502 = SF_Distinct;}
179342 {yymsp[0].minor.yy502 = SF_All;}
179350 {yymsp[1].minor.yy402 = 0;}
179355 …if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy402, &yymsp[0].minor…
179361 Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
179362 sqlite3ExprSetErrorOffset(p, (int)(yymsp[0].minor.yy0.z - pParse->zTail));
179369 pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
179370 sqlite3ExprSetErrorOffset(pRight, (int)(yymsp[0].minor.yy0.z - pParse->zTail));
179380 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
179384 {yymsp[1].minor.yy563 = 0;}
179388 yymsp[-1].minor.yy563 = yymsp[0].minor.yy563;
179394 …3 && yymsp[-1].minor.yy563->nSrc>0) ) yymsp[-1].minor.yy563->a[yymsp[-1].minor.yy563->nSrc-1].fg.j…
179399 …inor.yy563,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0,&yymsp[0].minor.yy421);
179404 …inor.yy563,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,0,&yymsp[0].minor.yy421);
179410 …inor.yy563,&yymsp[-6].minor.yy0,&yymsp[-5].minor.yy0,&yymsp[-1].minor.yy0,0,&yymsp[0].minor.yy421);
179416 …cListAppendFromTerm(pParse,yymsp[-5].minor.yy563,0,0,&yymsp[-1].minor.yy0,yymsp[-3].minor.yy637,&y…
179421 …if( yymsp[-5].minor.yy563==0 && yymsp[-1].minor.yy0.n==0 && yymsp[0].minor.yy421.pOn==0 && yymsp[0…
179423 }else if( ALWAYS(yymsp[-3].minor.yy563!=0) && yymsp[-3].minor.yy563->nSrc==1 ){
179424 … sqlite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy563,0,0,&yymsp[-1].minor.yy0,0,&yymsp[0].mi…
179428 assert( pOld->fg.fixedSchema==0 );
179430 assert( pOld->fg.fixedSchema==0 );
179434 pOld->u4.pSubq = 0;
179435 pOld->fg.isSubquery = 0;
179436 assert( pNew->u4.pSubq!=0 && pNew->u4.pSubq->pSelect!=0 );
179437 if( (pNew->u4.pSubq->pSelect->selFlags & SF_NestedFrom)!=0 ){
179442 pOld->u4.zDatabase = 0;
179446 pOld->u1.pFuncArg = 0;
179447 pOld->fg.isTabFunc = 0;
179450 pOld->zName = 0;
179456 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-3].minor.yy563,0,0,0,0,SF_NestedFrom,0);
179457 …ite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy563,0,0,&yymsp[-1].minor.yy0,pSubquery,&yymsp[0…
179463 {yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;}
179467 yylhsminor.yy563 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0);
179468 …ylhsminor.yy563 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy563->a[0].zName, &yymsp[0].minor.yy0);
179470 yymsp[0].minor.yy563 = yylhsminor.yy563;
179474 yylhsminor.yy563 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
179475 …ylhsminor.yy563 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy563->a[0].zName, &yymsp[0].minor.yy0);
179480 {yymsp[0].minor.yy563 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/}
179483 {yymsp[-2].minor.yy563 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /…
179487 …yymsp[-4].minor.yy563 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); …
179488 … yymsp[-4].minor.yy563 ) yymsp[-4].minor.yy563->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yy…
179493 yymsp[-2].minor.yy563 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/
179494 … yymsp[-2].minor.yy563 ) yymsp[-2].minor.yy563->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yy…
179498 { yymsp[0].minor.yy502 = JT_INNER; }
179501 {yymsp[-1].minor.yy502 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
179504 {yymsp[-2].minor.yy502 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-o…
179510 {yymsp[-1].minor.yy421.pOn = yymsp[0].minor.yy590; yymsp[-1].minor.yy421.pUsing = 0;}
179513 {yymsp[-3].minor.yy421.pOn = 0; yymsp[-3].minor.yy421.pUsing = yymsp[-1].minor.yy204;}
179516 {yymsp[1].minor.yy421.pOn = 0; yymsp[1].minor.yy421.pUsing = 0;}
179519 {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
179522 {yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;}
179526 {yymsp[-2].minor.yy402 = yymsp[0].minor.yy402;}
179531 sqlite3ExprListSetSortOrder(yymsp[-4].minor.yy402,yymsp[-1].minor.yy502,yymsp[0].minor.yy502);
179536 yymsp[-2].minor.yy402 = sqlite3ExprListAppend(pParse,0,yymsp[-2].minor.yy590); /*A-overwrites-Y*/
179537 sqlite3ExprListSetSortOrder(yymsp[-2].minor.yy402,yymsp[-1].minor.yy502,yymsp[0].minor.yy502);
179541 {yymsp[0].minor.yy502 = SQLITE_SO_ASC;}
179544 {yymsp[0].minor.yy502 = SQLITE_SO_DESC;}
179563 {yymsp[1].minor.yy590 = 0;}
179570 {yymsp[-1].minor.yy590 = yymsp[0].minor.yy590;}
179573 {yymsp[-1].minor.yy590 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy590,0);}
179576 {yymsp[-3].minor.yy590 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy590,yymsp[0].minor.yy590);}
179579 {yymsp[-3].minor.yy590 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy590,yymsp[-2].minor.yy590);}
179584 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy563,yymsp[0].minor.yy590,0,0);
179588 {sqlite3AddReturning(pParse,yymsp[0].minor.yy402); yymsp[-1].minor.yy590 = 0;}
179591 {sqlite3AddReturning(pParse,yymsp[0].minor.yy402); yymsp[-3].minor.yy590 = yymsp[-2].minor.yy590;}
179602 pSubquery = sqlite3SelectNew(pParse,0,pFromClause,0,0,0,0,SF_NestedFrom,0);
179603 as.n = 0;
179604 as.z = 0;
179605 pFromClause = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
179609 …arse,yymsp[-5].minor.yy563,yymsp[-2].minor.yy402,yymsp[0].minor.yy590,yymsp[-6].minor.yy502,0,0,0);
179614 …yymsp[-4].minor.yy402 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy402, yymsp[0].minor.yy590);
179620 …e3ExprListAppendVector(pParse, yymsp[-6].minor.yy402, yymsp[-3].minor.yy204, yymsp[0].minor.yy590);
179625 yylhsminor.yy402 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy590);
179632 …yymsp[-4].minor.yy402 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy204, yymsp[0].min…
179637 ….yy563, yymsp[-1].minor.yy637, yymsp[-2].minor.yy204, yymsp[-5].minor.yy502, yymsp[0].minor.yy403);
179642 sqlite3Insert(pParse, yymsp[-4].minor.yy563, 0, yymsp[-3].minor.yy204, yymsp[-6].minor.yy502, 0);
179646 { yymsp[1].minor.yy403 = 0; }
179649 { yymsp[-1].minor.yy403 = 0; sqlite3AddReturning(pParse,yymsp[0].minor.yy402); }
179652 …nor.yy402,yymsp[-6].minor.yy590,yymsp[-2].minor.yy402,yymsp[-1].minor.yy590,yymsp[0].minor.yy403);}
179655 …qlite3UpsertNew(pParse->db,yymsp[-5].minor.yy402,yymsp[-3].minor.yy590,0,0,yymsp[0].minor.yy403); }
179658 { yymsp[-4].minor.yy403 = sqlite3UpsertNew(pParse->db,0,0,0,0,0); }
179661 …yymsp[-7].minor.yy403 = sqlite3UpsertNew(pParse->db,0,0,yymsp[-2].minor.yy402,yymsp[-1].minor.yy59…
179664 {sqlite3AddReturning(pParse,yymsp[0].minor.yy402);}
179667 {yymsp[1].minor.yy204 = 0;}
179673 {yymsp[-2].minor.yy204 = sqlite3IdListAppend(pParse,yymsp[-2].minor.yy204,&yymsp[0].minor.yy0);}
179676 {yymsp[0].minor.yy204 = sqlite3IdListAppend(pParse,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
179682 {yymsp[0].minor.yy590=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
179687 Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
179696 Expr *temp3 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
179699 sqlite3RenameTokenRemap(pParse, 0, temp1);
179707 {yymsp[0].minor.yy590=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
179711 yylhsminor.yy590 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
179712 if( yylhsminor.yy590 ) yylhsminor.yy590->w.iOfst = (int)(yymsp[0].minor.yy0.z - pParse->zTail);
179714 yymsp[0].minor.yy590 = yylhsminor.yy590;
179718 if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
179719 u32 n = yymsp[0].minor.yy0.n;
179720 yymsp[0].minor.yy590 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0);
179721 sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy590, n);
179726 Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
179728 if( pParse->nested==0 ){
179730 yymsp[0].minor.yy590 = 0;
179732 yymsp[0].minor.yy590 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
179733 if( yymsp[0].minor.yy590 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy590->iTable);
179740 …yymsp[-2].minor.yy590 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy590, &yymsp[0].minor.…
179746 sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy590, yymsp[-3].minor.yy590, 0);
179764 yylhsminor.yy590 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0, 0);
179771 sqlite3WindowAttach(pParse, yylhsminor.yy590, yymsp[0].minor.yy483);
179778 sqlite3WindowAttach(pParse, yylhsminor.yy590, yymsp[0].minor.yy483);
179785 yylhsminor.yy590 = sqlite3ExprFunction(pParse, 0, &yymsp[-4].minor.yy0, 0);
179786 sqlite3WindowAttach(pParse, yylhsminor.yy590, yymsp[0].minor.yy483);
179792 yylhsminor.yy590 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0, 0);
179794 yymsp[0].minor.yy590 = yylhsminor.yy590;
179799 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
179803 yymsp[-4].minor.yy590->flags |= pList->a[0].pExpr->flags & EP_Propagate;
179811 {yymsp[-2].minor.yy590=sqlite3ExprAnd(pParse,yymsp[-2].minor.yy590,yymsp[0].minor.yy590);}
179820 {yymsp[-2].minor.yy590=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy590,yymsp[0].minor.yy5…
179823 {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-o…
179828 int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
179829 yymsp[-1].minor.yy0.n &= 0x7fffffff;
179830 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy590);
179832 yymsp[-2].minor.yy590 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
179833 if( bNot ) yymsp[-2].minor.yy590 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy590, 0);
179840 int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
179841 yymsp[-3].minor.yy0.n &= 0x7fffffff;
179842 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy590);
179844 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy590);
179845 yymsp[-4].minor.yy590 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0, 0);
179846 if( bNot ) yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy590, 0);
179851 {yymsp[-1].minor.yy590 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy590,0);}
179854 {yymsp[-2].minor.yy590 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy590,0);}
179858 yymsp[-2].minor.yy590 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy590,yymsp[0].minor.yy590);
179859 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy590, yymsp[-2].minor.yy590, TK_ISNULL);
179864 yymsp[-3].minor.yy590 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy590,yymsp[0].minor.yy590);
179865 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy590, yymsp[-3].minor.yy590, TK_NOTNULL);
179870 yymsp[-5].minor.yy590 = sqlite3PExpr(pParse,TK_IS,yymsp[-5].minor.yy590,yymsp[0].minor.yy590);
179871 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy590, yymsp[-5].minor.yy590, TK_ISNULL);
179876 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-4].minor.yy590,yymsp[0].minor.yy590);
179877 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy590, yymsp[-4].minor.yy590, TK_NOTNULL);
179882 {yymsp[-1].minor.yy590 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy590, 0);/*A-overwri…
179886 Expr *p = yymsp[0].minor.yy590;
179894 yymsp[-1].minor.yy590 = sqlite3PExpr(pParse, op, p, 0);
179901 ExprList *pList = sqlite3ExprListAppend(pParse, 0, yymsp[-2].minor.yy590);
179902 pList = sqlite3ExprListAppend(pParse, pList, yymsp[0].minor.yy590);
179903 yylhsminor.yy590 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
179909 {yymsp[0].minor.yy502 = 0;}
179913 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy590);
179914 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy590);
179915 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy590, 0);
179921 …p[-3].minor.yy502 ) yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy590, 0);
179926 if( yymsp[-1].minor.yy402==0 ){
179932 ** simplify to constants 0 (false) and 1 (true), respectively.
179948 Expr *pRHS = yymsp[-1].minor.yy402->a[0].pExpr;
179950 yymsp[-1].minor.yy402->a[0].pExpr = 0;
179952 pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0);
179955 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy590, 0);
179957 pRHS->x.pSelect = 0;
179960 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy590, 0);
179961 if( yymsp[-4].minor.yy590==0 ){
179975 …p[-3].minor.yy502 ) yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy590, 0);
179981 yymsp[-2].minor.yy590 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
179987 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy590, 0);
179989 …p[-3].minor.yy502 ) yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy590, 0);
179994 SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
179995 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
179996 …if( yymsp[0].minor.yy402 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy40…
179997 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy590, 0);
179999 …p[-3].minor.yy502 ) yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy590, 0);
180005 p = yymsp[-3].minor.yy590 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
180011 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy590, 0);
180024 yymsp[-4].minor.yy402 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy402, yymsp[0].minor.yy590);
180029 yymsp[-3].minor.yy402 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy590);
180030 yymsp[-3].minor.yy402 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy402, yymsp[0].minor.yy590);
180034 {yymsp[-2].minor.yy402 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy402,yymsp[0].minor.yy590);}
180037 {yymsp[0].minor.yy402 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy590); /*A-overwrites-Y*/}
180046 …sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy402, yymsp[-10].minor.yy5…
180047 …&yymsp[-11].minor.yy0, yymsp[0].minor.yy590, SQLITE_SO_ASC, yymsp[-8].minor.yy502, SQLITE_IDXTYPE_…
180055 {yymsp[0].minor.yy502 = OE_Abort;}
180062 …(pParse, yymsp[-4].minor.yy402, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy502, yymsp[0].minor.yy502);
180067 …2].minor.yy402 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy502, y…
180071 {sqlite3DropIndex(pParse, yymsp[0].minor.yy563, yymsp[-1].minor.yy502);}
180074 {sqlite3Vacuum(pParse,0,yymsp[0].minor.yy590);}
180077 {sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy590);}
180080 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
180083 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
180086 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
180089 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
180098 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
180104 …ymsp[-4].minor.yy28.a, yymsp[-4].minor.yy28.b, yymsp[-2].minor.yy563, yymsp[0].minor.yy590, yymsp[…
180105 …yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-ove…
180108 pParse->isCreate = 0; /* But, should not be set for CREATE TRIGGER */
180113 { yymsp[0].minor.yy502 = yymsp[0].major; /*A-overwrites-X*/ }
180123 {yymsp[0].minor.yy28.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy28.b = 0;}
180126 {yymsp[-2].minor.yy28.a = TK_UPDATE; yymsp[-2].minor.yy28.b = yymsp[0].minor.yy204;}
180130 { yymsp[1].minor.yy590 = 0; }
180134 { yymsp[-1].minor.yy590 = yymsp[0].minor.yy590; }
180138 assert( yymsp[-2].minor.yy319!=0 );
180145 assert( yymsp[-1].minor.yy319!=0 );
180151 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
180172 …yy402, yymsp[-1].minor.yy590, yymsp[-7].minor.yy502, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy342);}
180177 …637,yymsp[-6].minor.yy502,yymsp[-1].minor.yy403,yymsp[-7].minor.yy342,yymsp[0].minor.yy342);/*yylh…
180182 …pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy590, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy342);}
180186 …rSelectStep(pParse->db, yymsp[-1].minor.yy637, yymsp[-2].minor.yy342, yymsp[0].minor.yy342); /*yyl…
180191 yymsp[-3].minor.yy590 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
180199 yymsp[-5].minor.yy590 = sqlite3PExpr(pParse, TK_RAISE, yymsp[-1].minor.yy590, 0);
180206 {yymsp[0].minor.yy502 = OE_Rollback;}
180209 {yymsp[0].minor.yy502 = OE_Fail;}
180213 sqlite3DropTrigger(pParse,yymsp[0].minor.yy563,yymsp[-1].minor.yy502);
180218 sqlite3Attach(pParse, yymsp[-3].minor.yy590, yymsp[-1].minor.yy590, yymsp[0].minor.yy590);
180223 sqlite3Detach(pParse, yymsp[0].minor.yy590);
180227 {sqlite3Reindex(pParse, 0, 0);}
180230 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
180233 {sqlite3Analyze(pParse, 0, 0);}
180236 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
180240 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy563,&yymsp[0].minor.yy0);
180251 sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy563, &yymsp[0].minor.yy0);
180257 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy563);
180262 …sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy563, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
180266 {sqlite3VtabFinishParse(pParse,0);}
180269 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
180273 …sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yym…
180282 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
180286 { sqlite3WithPush(pParse, yymsp[0].minor.yy125, 1); }
180289 {yymsp[0].minor.yy444 = M10d_Any;}
180307 yymsp[0].minor.yy125 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy361); /*A-overwrites-X*/
180312 yymsp[-2].minor.yy125 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy125, yymsp[0].minor.yy361);
180317 assert( yymsp[0].minor.yy483!=0 );
180318 sqlite3WindowChain(pParse, yymsp[0].minor.yy483, yymsp[-2].minor.yy483);
180319 yymsp[0].minor.yy483->pNextWin = yymsp[-2].minor.yy483;
180320 yylhsminor.yy483 = yymsp[0].minor.yy483;
180335 ….yy483 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy483, yymsp[-2].minor.yy402, yymsp[-1].mino…
180340 …yylhsminor.yy483 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy483, yymsp[-2].minor.yy402, yyms…
180346 …[-3].minor.yy483 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy483, 0, yymsp[-1].minor.yy402, 0…
180351 …yylhsminor.yy483 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy483, 0, yymsp[-1].minor.yy402, &…
180357 …yylhsminor.yy483 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy483, 0, 0, &yymsp[-1].minor.yy0);
180363 yymsp[1].minor.yy483 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
180368 …02, yymsp[-1].minor.yy205.eType, yymsp[-1].minor.yy205.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy444);
180374 …minor.yy205.pExpr, yymsp[-1].minor.yy205.eType, yymsp[-1].minor.yy205.pExpr, yymsp[0].minor.yy444);
180380 {yylhsminor.yy205 = yymsp[0].minor.yy205;}
180381 yymsp[0].minor.yy205 = yylhsminor.yy205;
180386 {yylhsminor.yy205.eType = yymsp[-1].major; yylhsminor.yy205.pExpr = 0;}
180390 {yylhsminor.yy205.eType = yymsp[0].major; yylhsminor.yy205.pExpr = yymsp[-1].minor.yy590;}
180394 {yymsp[1].minor.yy444 = 0;}
180397 {yymsp[-1].minor.yy444 = yymsp[0].minor.yy444;}
180404 {yymsp[0].minor.yy444 = yymsp[0].major; /*A-overwrites-X*/}
180407 { yymsp[-1].minor.yy483 = yymsp[0].minor.yy483; }
180411 if( yymsp[0].minor.yy483 ){
180412 yymsp[0].minor.yy483->pFilter = yymsp[-1].minor.yy590;
180416 yylhsminor.yy483 = yymsp[0].minor.yy483;
180422 yylhsminor.yy483 = yymsp[0].minor.yy483;
180424 yymsp[0].minor.yy483 = yylhsminor.yy483;
180431 yylhsminor.yy483->pFilter = yymsp[0].minor.yy590;
180433 sqlite3ExprDelete(pParse->db, yymsp[0].minor.yy590);
180436 yymsp[0].minor.yy483 = yylhsminor.yy483;
180441 assert( yymsp[-3].minor.yy483!=0 );
180448 …yymsp[-1].minor.yy483->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.y…
180457 yylhsminor.yy590=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0);
180460 yymsp[0].minor.yy590 = yylhsminor.yy590;
180531 assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
180589 if( TOKEN.z[0] ){
180655 int yyerrorhit = 0; /* True if yymajor has invoked an error */
180661 assert( yypParser->yytos!=0 );
180663 yyendofinput = (yymajor==0);
180686 assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) );
180706 if( yyRuleInfoNRhs[yyruleno]==0 ){
180763 if( yypParser->yyerrcnt<0 ){
180783 if( yypParser->yytos <= yypParser->yystack || yymajor==0 ){
180819 if( yypParser->yyerrcnt<=0 ){
180851 ** 0 if iToken has no fallback.
180855 assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) );
180859 return 0;
180893 #define CC_X 0 /* The letter 'x', or start of BLOB literal */
180922 #define CC_NUL 29 /* 0x00 */
180923 #define CC_BOM 30 /* First byte of UTF8 BOM: 0xEF 0xBB 0xBF */
180928 /* 0x */ 29, 28, 28, 28, 28, 28, 28, 28, 28, 7, 7, 28, 7, 7, 28, 28,
180933 /* 5x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 9, 28, 28, 28, 2,
180935 /* 7x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 28, 10, 28, 25, 28,
180947 /* 0x */ 29, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 7, 7, 28, 28,
180957 /* Ax */ 28, 25, 1, 1, 1, 1, 1, 0, 2, 2, 28, 28, 28, 28, 28, 28,
180961 /* Ex */ 28, 28, 1, 1, 1, 1, 1, 0, 2, 2, 28, 28, 28, 28, 28, 28,
180981 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
180982 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
180983 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
180984 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
180985 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3x */
180986 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 4x */
180987 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 5x */
180988 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 95, 0, 0, /* 6x */
180989 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 7x */
180990 0, 97, 98, 99,100,101,102,103,104,105, 0, 0, 0, 0, 0, 0, /* 8x */
180991 0,106,107,108,109,110,111,112,113,114, 0, 0, 0, 0, 0, 0, /* 9x */
180992 0, 0,115,116,117,118,119,120,121,122, 0, 0, 0, 0, 0, 0, /* Ax */
180993 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */
180994 0, 97, 98, 99,100,101,102,103,104,105, 0, 0, 0, 0, 0, 0, /* Cx */
180995 0,106,107,108,109,110,111,112,113,114, 0, 0, 0, 0, 0, 0, /* Dx */
180996 0, 0,115,116,117,118,119,120,121,122, 0, 0, 0, 0, 0, 0, /* Ex */
180997 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Fx */
181082 84, 92, 134, 82, 105, 29, 0, 0, 94, 0, 85, 72, 0,
181083 53, 35, 86, 15, 0, 42, 97, 54, 89, 135, 19, 0, 0,
181084 140, 0, 40, 129, 0, 22, 107, 0, 9, 0, 0, 123, 80,
181085 0, 78, 6, 0, 65, 103, 147, 0, 136, 115, 0, 0, 48,
181086 0, 90, 24, 0, 17, 0, 27, 70, 23, 26, 5, 60, 142,
181087 110, 122, 0, 73, 91, 71, 145, 61, 120, 74, 0, 49, 0,
181088 11, 41, 0, 113, 0, 0, 0, 109, 10, 111, 116, 125, 14,
181089 50, 124, 0, 100, 0, 18, 121, 144, 56, 130, 139, 88, 83,
181090 37, 30, 126, 0, 0, 108, 51, 131, 128, 0, 34, 0, 0,
181091 132, 0, 98, 38, 39, 0, 20, 45, 117, 93,
181093 /* aKWNext[] forms the hash collision chain. If aKWHash[i]==0
181096 static const unsigned char aKWNext[148] = {0,
181097 0, 0, 0, 0, 4, 0, 43, 0, 0, 106, 114, 0, 0,
181098 0, 2, 0, 0, 143, 0, 0, 0, 13, 0, 0, 0, 0,
181099 141, 0, 0, 119, 52, 0, 0, 137, 12, 0, 0, 62, 0,
181100 138, 0, 133, 0, 0, 36, 0, 0, 28, 77, 0, 0, 0,
181101 0, 59, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0,
181102 0, 69, 0, 0, 0, 0, 0, 146, 3, 0, 58, 0, 1,
181103 75, 0, 0, 0, 31, 0, 0, 0, 0, 0, 127, 0, 104,
181104 0, 64, 66, 63, 0, 0, 0, 0, 0, 46, 0, 16, 8,
181105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 81, 101, 0,
181106 112, 21, 7, 67, 0, 79, 96, 118, 0, 0, 68, 0, 0,
181107 99, 44, 0, 55, 0, 76, 0, 95, 32, 33, 57, 25, 0,
181108 102, 0, 0, 87,
181111 static const unsigned char aKWLen[148] = {0,
181127 static const unsigned short int aKWOffset[148] = {0,
181128 0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
181142 static const unsigned char aKWCode[148] = {0,
181175 ** 0: INSERT
181303 /* Check to see if z[0..n-1] is a keyword. If it is, write the
181310 i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n*1) % 127;
181311 for(i=(int)aKWHash[i]; i>0; i=aKWNext[i]){
181315 if( (z[0]&~0x20)!=zKW[0] ) continue;
181316 if( (z[1]&~0x20)!=zKW[1] ) continue;
181318 while( j<n && (z[j]&~0x20)==zKW[j] ){ j++; }
181321 if( toupper(z[0])!=zKW[0] ) continue;
181486 if( i<0 || i>=SQLITE_N_KEYWORD ) return SQLITE_ERROR;
181518 #define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
181523 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 4x */
181524 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, /* 5x */
181525 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, /* 6x */
181526 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, /* 7x */
181527 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, /* 8x */
181528 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, /* 9x */
181529 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, /* Ax */
181530 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */
181531 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Cx */
181532 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Dx */
181533 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Ex */
181534 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* Fx */
181536 #define IdChar(C) (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))
181620 ** Return the length (in bytes) of the token that begins at z[0].
181629 testcase( z[0]==' ' );
181630 testcase( z[0]=='\t' );
181631 testcase( z[0]=='\n' );
181632 testcase( z[0]=='\f' );
181633 testcase( z[0]=='\r' );
181640 for(i=2; (c=z[i])!=0 && c!='\n'; i++){}
181671 if( z[1]!='*' || z[2]==0 ){
181675 for(i=3, c=z[2]; (c!='*' || z[i]!='/') && (c=z[i])!=0; i++){}
181746 int delim = z[0];
181750 for(i=1; (c=z[i])!=0; i++){
181762 }else if( c!=0 ){
181783 testcase( z[0]=='0' ); testcase( z[0]=='1' ); testcase( z[0]=='2' );
181784 testcase( z[0]=='3' ); testcase( z[0]=='4' ); testcase( z[0]=='5' );
181785 testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' );
181786 testcase( z[0]=='9' ); testcase( z[0]=='.' );
181789 if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){
181791 if( sqlite3Isxdigit(z[i])==0 ){
181802 for(i=0; 1; i++){
181803 if( sqlite3Isdigit(z[i])==0 ){
181815 if( sqlite3Isdigit(z[i])==0 ){
181831 if( sqlite3Isdigit(z[i])==0 ){
181849 for(i=1, c=z[0]; c!=']' && (c=z[i])!=0; i++){}
181860 int n = 0;
181861 testcase( z[0]=='$' ); testcase( z[0]=='@' );
181862 testcase( z[0]==':' ); testcase( z[0]=='#' );
181864 for(i=1; (c=z[i])!=0; i++){
181868 }else if( c=='(' && n>0 ){
181871 }while( (c=z[i])!=0 && !sqlite3Isspace(c) && c!=')' );
181885 if( n==0 ) *tokenType = TK_ILLEGAL;
181903 testcase( z[0]=='x' ); testcase( z[0]=='X' );
181925 if( z[1]==0xbb && z[2]==0xbf ){
181934 return 0;
181950 int nErr = 0; /* Number of errors encountered */
181952 int n = 0; /* Length of the next token token */
181957 Parse *pParentParse = 0; /* Outer parse context, if any */
181963 assert( zSql!=0 );
181965 if( db->nVdbeActive==0 ){
181966 AtomicStore(&db->u1.isInterrupted, 0);
181975 sqlite3ParserTrace(0, 0);
181983 if( pEngine==0 ){
181988 assert( pParse->pNewTable==0 );
181989 assert( pParse->pNewTrigger==0 );
181990 assert( pParse->nVar==0 );
181991 assert( pParse->pVList==0 );
181997 if( mxSqlLen<0 ){
182023 if( zSql[0]==0 ){
182025 ** with tokens TK_SEMI and 0, in that order. */
182027 tokenType = 0;
182028 }else if( lastTokenParsed==0 ){
182033 n = 0;
182046 && (db->init.busy || (db->flags & SQLITE_Comments)!=0)
182065 assert( db->mallocFailed==0 || pParse->rc!=SQLITE_OK || startedWithOom );
182068 assert( nErr==0 );
182085 if( pParse->zErrMsg==0 ){
182088 if( (pParse->prepFlags & SQLITE_PREPARE_DONT_LOG)==0 ){
182110 assert( nErr==0 || pParse->rc!=SQLITE_OK );
182127 ** Compute a normalization of the SQL given by zSql[0..nSql-1]. Return
182139 int prevType = 0; /* Previous non-whitespace token */
182148 nParen = iStartIN = nParenAtIN = 0;
182150 assert( pStr!=0 ); /* sqlite3_str_new() never returns NULL */
182151 for(i=0; zSql[i] && pStr->accError==0; i+=n){
182156 if( NEVER(n<=0) ) break;
182187 if( iStartIN>0 && nParen==nParenAtIN ){
182191 iStartIN = 0;
182198 iStartIN = 0;
182203 int eType = 0;
182204 if( zId==0 ) break;
182230 iStartIN = 0;
182278 #define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
182282 #define IdChar(C) (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))
182291 #define tkSEMI 0
182311 ** (0) INVALID We have not yet seen a non-whitespace character.
182314 ** returns 1 if it ends in the START state and 0 if it ends
182339 ** (0) tkSEMI A semicolon.
182356 u8 state = 0; /* Current state, using numbers defined in header comment */
182366 /* 0 INVALID: */ { 1, 0, 2, 3, 4, 2, 2, 2, },
182382 /* 0 INVALID: */ { 1, 0, 2, },
182389 if( zSql==0 ){
182391 return 0;
182415 while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
182416 if( zSql[0]==0 ) return 0;
182427 if( *zSql==0 ) return state==1;
182434 if( *zSql==0 ) return 0;
182444 if( *zSql==0 ) return 0;
182461 if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
182469 if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
182471 }else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
182473 }else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
182481 if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
182485 if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
182529 pVal = sqlite3ValueNew(0);
182538 return rc & 0xff;
182583 #if 0
182589 #if 0
182620 #if 0
182626 #if 0
182653 #if 0
182659 #if 0
182756 ** the SQLITE_THREADSAFE compile-time option being set to 0.
182767 # define SQLITE_DEBUG_OS_TRACE 0
182779 SQLITE_API void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...) = 0;
182789 SQLITE_API char *sqlite3_temp_directory = 0;
182798 SQLITE_API char *sqlite3_data_directory = 0;
182835 int bRunExtraInit = 0; /* Extra initialization needed */
182919 if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){
182927 memset(&sqlite3BuiltinFunctions, 0, sizeof(sqlite3BuiltinFunctions));
182929 if( sqlite3GlobalConfig.isPCacheInit==0 ){
182947 rc = SQLITE_EXTRA_INIT_MUTEXED(0);
182958 sqlite3GlobalConfig.inProgress = 0;
182967 if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
182968 assert( sqlite3GlobalConfig.nRefInitMutex==0 );
182970 sqlite3GlobalConfig.pInitMutex = 0;
182999 rc = SQLITE_EXTRA_INIT(0);
183028 sqlite3GlobalConfig.isInit = 0;
183032 sqlite3GlobalConfig.isPCacheInit = 0;
183036 sqlite3GlobalConfig.isMallocInit = 0;
183046 sqlite3_data_directory = 0;
183047 sqlite3_temp_directory = 0;
183052 sqlite3GlobalConfig.isMutexInit = 0;
183076 static const u64 mAnytimeConfigOption = 0
183080 if( op<0 || op>63 || (MASKBIT64(op) & mAnytimeConfigOption)==0 ){
183093 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
183097 sqlite3GlobalConfig.bCoreMutex = 0; /* Disable mutex on core */
183098 sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
183102 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
183107 sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
183111 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
183120 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
183127 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */
183149 if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
183210 if( sqlite3GlobalConfig.pcache2.xInit==0 ){
183237 if( sqlite3GlobalConfig.pHeap==0 ){
183246 memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
183288 ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
183333 if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
183336 if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
183366 if( iVal<0 ){
183384 if( 0==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = TF_NoVisibleRowid;
183385 if( 1==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = 0;
183386 *pVal = (sqlite3GlobalConfig.mNoVisibleRowid==0);
183388 *pVal = 0;
183425 if( sqlite3LookasideUsed(db,0)>0 ){
183439 if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;
183442 ** more than 0x7fff0000 total bytes for lookaside. */
183443 if( cnt<1 ) cnt = 0;
183444 if( sz>0 && cnt>(0x7fff0000/sz) ) cnt = 0x7fff0000/sz;
183446 if( szAlloc==0 ){
183447 sz = 0;
183448 pStart = 0;
183449 }else if( pBuf==0 ){
183466 if( sz>0 ){
183468 nSm = 0;
183470 nBig = nSm = 0;
183473 db->lookaside.pInit = 0;
183474 db->lookaside.pFree = 0;
183482 for(i=0; i<nBig; i++){
183488 db->lookaside.pSmallInit = 0;
183489 db->lookaside.pSmallFree = 0;
183491 for(i=0; i<nSm; i++){
183499 db->lookaside.bDisable = 0;
183500 db->lookaside.bMalloced = pBuf==0 ?1:0;
183503 db->lookaside.pStart = 0;
183505 db->lookaside.pSmallInit = 0;
183506 db->lookaside.pSmallFree = 0;
183507 db->lookaside.pMiddle = 0;
183509 db->lookaside.pEnd = 0;
183511 db->lookaside.sz = 0;
183512 db->lookaside.bMalloced = 0;
183513 db->lookaside.nSlot = 0;
183516 assert( sqlite3LookasideUsed(db,0)==0 );
183528 return 0;
183546 for(i=0; i<db->nDb; i++){
183565 int bSeenBusy = 0;
183572 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
183604 db->aDb[0].zDbSName = va_arg(ap,char*);
183645 for(i=0; i<ArraySize(aFlagOp); i++){
183650 if( onoff>0 ){
183652 }else if( onoff==0 ){
183656 sqlite3ExpirePreparedStatements(db, 0);
183659 *pRes = (db->flags & aFlagOp[i].mask)!=0;
183690 if( rc==0 ){
183716 assert( p==0 || p->xCmp!=binCollFunc || strcmp(p->zName,"BINARY")==0 );
183717 return p==0 || p->xCmp==binCollFunc;
183737 if( 0==r ){
183750 return 0;
183778 return 0;
183794 return 0;
183814 db->nSavepoint = 0;
183815 db->nStatement = 0;
183816 db->isTransactionSavepoint = 0;
183827 assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
183831 if( pDestructor->nRef==0 ){
183847 for(i=0; i<db->nDb; i++){
183877 for(j=0; j<db->nDb; j++){
183881 return 0;
183898 db->trace.xV2(SQLITE_TRACE_CLOSE, db->pTraceArg, db, 0);
183926 sqlite3GlobalConfig.xSqllog(sqlite3GlobalConfig.pSqllogArg, db, 0, 2);
183933 assert( p->pData!=0 );
183961 if( iDb<0 ) nDb--;
183963 iDb = 0;
183968 int x = pBt!=0 ? sqlite3BtreeTxnState(pBt) : SQLITE_TXN_NONE;
183984 SQLITE_API int sqlite3_close(sqlite3 *db){ return sqlite3Close(db,0); }
184025 for(j=0; j<db->nDb; j++){
184029 pDb->pBt = 0;
184031 pDb->pSchema = 0;
184065 for(j=0; j<3; j++){
184101 assert( sqlite3LookasideUsed(db,0)==0 );
184117 int inTrans = 0;
184129 schemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0 && db->init.busy==0;
184131 for(i=0; i<db->nDb; i++){
184144 sqlite3ExpirePreparedStatements(db, 0);
184150 db->nDeferredCons = 0;
184151 db->nDeferredImmCons = 0;
184166 const char *zName = 0;
184168 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
184264 if( zName==0 ){
184281 /* SQLITE_INTERNAL */ 0,
184295 /* SQLITE_EMPTY */ 0,
184304 /* SQLITE_NOLFS */ 0,
184307 /* SQLITE_FORMAT */ 0,
184328 rc &= 0xff;
184329 if( ALWAYS(rc>=0) && rc<ArraySize(aMsg) && aMsg[rc]!=0 ){
184357 { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
184363 assert( count>=0 );
184373 if( delay<=0 ) return 0;
184383 return 0;
184397 ** returns 0, the operation aborts with an SQLITE_BUSY error.
184401 if( p->xBusyHandler==0 || p->nBusy<0 ) return 0;
184403 if( rc==0 ){
184426 db->busyHandler.nBusy = 0;
184427 db->busyTimeout = 0;
184429 db->setlkTimeout = 0;
184454 if( nOps>0 ){
184459 db->xProgress = 0;
184460 db->nProgressOps = 0;
184461 db->pProgressArg = 0;
184470 ** specified number of milliseconds before returning 0.
184476 if( ms>0 ){
184484 sqlite3_busy_handler(db, 0, 0);
184495 int bBOC = ((flags & SQLITE_SETLK_BLOCK_ON_CONNECT) ? 1 : 0);
184506 for(iDb=0; iDb<db->nDb; iDb++){
184529 && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE)
184545 && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE)
184548 return 0;
184551 return AtomicLoad(&db->u1.isInterrupted)!=0;
184577 assert( xValue==0 || xSFunc==0 );
184578 if( zFunctionName==0 /* Must have a valid name */
184579 || (xSFunc!=0 && xFinal!=0) /* Not both xSFunc and xFinal */
184580 || ((xFinal==0)!=(xStep==0)) /* Both or neither of xFinal and xStep */
184581 || ((xValue==0)!=(xInverse==0)) /* Both or neither of xValue, xInverse */
184646 p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 0);
184654 sqlite3ExpirePreparedStatements(db, 0);
184656 }else if( xSFunc==0 && xFinal==0 ){
184709 FuncDestructor *pArg = 0;
184724 pArg->nRef = 0;
184731 if( pArg && pArg->nRef==0 ){
184732 assert( rc!=SQLITE_OK || (xStep==0 && xFinal==0) );
184757 xFinal, 0, 0, 0);
184771 xFinal, 0, 0, xDestroy);
184785 return createFunctionApi(db, zFunc, nArg, enc, p, 0, xStep,
184804 if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT;
184809 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xSFunc,xStep,xFinal,0,0,0);
184861 if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){
184866 rc = sqlite3FindFunction(db, zName, nArg, SQLITE_UTF8, 0)!=0;
184870 if( zCopy==0 ) return SQLITE_NOMEM;
184872 zCopy, sqlite3InvalidFunction, 0, 0, sqlite3_free);
184891 return 0;
184896 db->mTrace = xTrace ? SQLITE_TRACE_LEGACY : 0;
184918 if( mTrace==0 ) xTrace = 0;
184919 if( xTrace==0 ) mTrace = 0;
184946 return 0;
184976 return 0;
185001 return 0;
185026 return 0;
185051 if( db==0 ){
185052 return 0;
185133 if( nFrame>0 ){
185136 sqlite3_wal_hook(db, 0, 0);
185156 return 0;
185166 return 0;
185194 assert( SQLITE_CHECKPOINT_PASSIVE==0 );
185205 if( zDb && zDb[0] ){
185210 if( iDb<0 ){
185214 db->busyHandler.nBusy = 0;
185222 if( db->nVdbeActive==0 ){
185223 AtomicStore(&db->u1.isInterrupted, 0);
185239 ** sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). */
185240 return sqlite3_wal_checkpoint_v2(db,zDb,SQLITE_CHECKPOINT_PASSIVE,0,0);
185267 int bBusy = 0; /* True if SQLITE_BUSY has been encountered */
185275 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
185278 pnLog = 0;
185279 pnCkpt = 0;
185301 ** 0 any file (return 0)
185302 ** 1 1 file (return 0)
185304 ** 1 0 file (return 0)
185305 ** 2 1 file (return 0)
185307 ** 2 0 memory (return 1)
185323 return 0;
185343 testcase( db->pErr==0 );
185344 z = db->errCode ? (char*)sqlite3_value_text(db->pErr) : 0;
185346 if( z==0 ){
185374 'o', 'u', 't', ' ', 'o', 'f', ' ', 'm', 'e', 'm', 'o', 'r', 'y', 0
185379 'm', 'i', 's', 'u', 's', 'e', 0
185394 if( z==0 ){
185433 return db ? db->iSysErrno : 0;
185480 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
185487 sqlite3ExpirePreparedStatements(db, 0);
185498 for(j=0; j<3; j++){
185504 p->xCmp = 0;
185511 if( pColl==0 ) return SQLITE_NOMEM_BKPT;
185559 #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>32767
185560 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 32767
185562 #if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>125
185563 # error SQLITE_MAX_ATTACHED must be between 0 and 125
185574 #if SQLITE_MAX_WORKER_THREADS<0 || SQLITE_MAX_WORKER_THREADS>50
185575 # error SQLITE_MAX_WORKER_THREADS must be between 0 and 50
185620 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
185624 if( newLimit>=0 ){ /* IMP: R-52476-28732 */
185676 assert( *pzErrMsg==0 );
185680 && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
185685 int iOut = 0; /* Output character index */
185692 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
185696 memset(zFile, 0, 4); /* 4-byte of 0x00 is the start of DB name marker */
185701 if( strncmp(zUri+5, "///", 3)==0 ){
185708 if( strncmp(zUri+7, "///", 3)==0 ){ iIn++; }
185709 }else if( strncmp(zUri+5, "//localhost/", 12)==0 ){
185729 ** Within this loop, variable eState may be set to 0, 1 or 2, depending
185732 ** 0: Parsing file-name.
185736 eState = 0;
185737 while( (c = zUri[iIn])!=0 && c!='#' ){
185746 assert( octet>=0 && octet<256 );
185747 if( octet==0 ){
185753 while( (c = zUri[iIn])!=0 && c!='#'
185754 && (eState!=0 || c!='?')
185770 if( zFile[iOut-1]==0 ){
185776 zFile[iOut++] = '\0';
185780 c = 0;
185781 }else if( (eState==0 && c=='?') || (eState==2 && c=='&') ){
185782 c = 0;
185787 if( eState==1 ) zFile[iOut++] = '\0';
185788 memset(zFile+iOut, 0, 4); /* end-of-options + empty journal filenames */
185795 while( zOpt[0] ){
185800 if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
185806 } *aMode = 0;
185807 char *zModeType = 0;
185808 int mask = 0;
185809 int limit = 0;
185811 if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
185815 { 0, 0 }
185823 if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
185829 { 0, 0 }
185841 int mode = 0;
185842 for(i=0; aMode[i].z; i++){
185844 if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){
185849 if( mode==0 ){
185870 memset(zFile, 0, 4);
185875 memset(zFile+nUri, 0, 4);
185880 if( *ppVfs==0 ){
185887 zFile = 0;
185900 while( ALWAYS(zFilename!=0) && zFilename[0] ){
185903 if( x==0 ) return zFilename;
185906 return 0;
185925 char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
185926 char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
185930 if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
185932 *ppDb = 0;
185938 if( sqlite3GlobalConfig.bCoreMutex==0 ){
185939 isThreadsafe = 0;
185941 isThreadsafe = 0;
185979 if( db==0 ) goto opendb_out;
185986 if( db->mutex==0 ){
185988 db = 0;
185991 if( isThreadsafe==0 ){
185996 db->errMask = (flags & SQLITE_OPEN_EXRESCODE)!=0 ? 0xffffffff : 0xff;
186001 db->lookaside.sz = 0;
186009 db->nextPagesize = 0;
186012 /* Beginning with version 3.37.0, using the VFS xFetch() API to memory-map
186017 db->nMaxSorterMmap = 0x7FFFFFFF;
186026 #if !defined(SQLITE_TRUSTED_SCHEMA) || SQLITE_TRUSTED_SCHEMA+0!=0
186038 ** 0 off off
186042 ** -DSQLITE_DQS=0 (best) or -DSQLITE_DQS=1 (second choice) if possible.
186106 createCollation(db, sqlite3StrBINARY, SQLITE_UTF8, 0, binCollFunc, 0);
186107 createCollation(db, sqlite3StrBINARY, SQLITE_UTF16BE, 0, binCollFunc, 0);
186108 createCollation(db, sqlite3StrBINARY, SQLITE_UTF16LE, 0, binCollFunc, 0);
186109 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
186110 createCollation(db, "RTRIM", SQLITE_UTF8, 0, rtrimCollFunc, 0);
186117 if( zFilename && zFilename[0]==':' ){
186118 if( strcmp(zFilename, ":localStorage:")==0 ){
186121 }else if( strcmp(zFilename, ":sessionStorage:")==0 ){
186141 assert( SQLITE_OPEN_READONLY == 0x01 );
186142 assert( SQLITE_OPEN_READWRITE == 0x02 );
186143 assert( SQLITE_OPEN_CREATE == 0x04 );
186144 testcase( (1<<(flags&7))==0x02 ); /* READONLY */
186145 testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
186146 testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
186147 if( ((1<<(flags&7)) & 0x46)==0 ){
186150 if( zFilename==0 ) zFilename = ":memory:";
186155 sqlite3ErrorWithMsg(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
186159 assert( db->pVfs!=0 );
186161 if( sqlite3_stricmp(db->pVfs->zName, "kvvfs")==0 ){
186167 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
186176 sqlite3BtreeEnter(db->aDb[0].pBt);
186177 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
186181 sqlite3BtreeLeave(db->aDb[0].pBt);
186182 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
186187 db->aDb[0].zDbSName = "main";
186188 db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
186207 for(i=0; rc==SQLITE_OK && i<ArraySize(sqlite3BuiltinExtensions); i++){
186230 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
186235 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
186242 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
186249 assert( db->mutex!=0 || isThreadsafe==0
186250 || sqlite3GlobalConfig.bFullMutex==0 );
186254 assert( db!=0 || (rc&0xff)==SQLITE_NOMEM );
186255 if( (rc&0xff)==SQLITE_NOMEM ){
186257 db = 0;
186264 /* Opening a db handle. Fourth parameter is passed 0. */
186266 sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
186282 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
186306 if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
186308 *ppDb = 0;
186313 if( zFilename==0 ) zFilename = "\000\000";
186314 pVal = sqlite3ValueNew(0);
186319 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
186321 if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
186329 return rc & 0xff;
186343 return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0);
186360 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
186385 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
186391 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
186414 db->xCollNeeded16 = 0;
186434 db->xCollNeeded = 0;
186449 if( strcmp(p->zName, zName)==0 ){
186456 return 0;
186475 assert( p->pData!=0 );
186477 if( pData==0 ){
186483 }else if( pData==0 ){
186489 if( p==0 ){
186525 return 0;
186548 testcase( sqlite3GlobalConfig.xLog!=0 );
186552 testcase( sqlite3GlobalConfig.xLog!=0 );
186556 testcase( sqlite3GlobalConfig.xLog!=0 );
186563 testcase( sqlite3GlobalConfig.xLog!=0 );
186569 testcase( sqlite3GlobalConfig.xLog!=0 );
186573 testcase( sqlite3GlobalConfig.xLog!=0 );
186606 char *zErrMsg = 0;
186607 Table *pTab = 0;
186608 Column *pCol = 0;
186609 int iCol = 0;
186610 char const *zDataType = 0;
186611 char const *zCollSeq = 0;
186612 int notnull = 0;
186613 int primarykey = 0;
186614 int autoinc = 0;
186618 if( !sqlite3SafetyCheckOk(db) || zTableName==0 ){
186634 pTab = 0;
186639 if( zColumnName==0 ){
186643 if( iCol>=0 ){
186648 pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
186650 pTab = 0;
186667 zDataType = sqlite3ColumnType(pCol,0);
186669 notnull = pCol->notNull!=0;
186670 primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
186671 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
186699 sqlite3ErrorWithMsg(db, rc, (zErrMsg?"%s":0), zErrMsg);
186712 pVfs = sqlite3_vfs_find(0);
186713 if( pVfs==0 ) return 0;
186718 rc = (sqlite3OsSleep(pVfs, ms<0 ? 0 : 1000*ms)/1000);
186730 db->errMask = onoff ? 0xffffffff : 0xff;
186752 assert( pPager!=0 );
186754 assert( fd!=0 );
186770 if( iNew>=0 && iNew<=255 ){
186771 sqlite3BtreeSetPageSize(pBtree, 0, iNew, 0);
186792 int rc = 0;
186823 ** x!=0 && db!=0 Seed the PRNG to the current value of the
186830 ** x!=0 && db==0 Seed the PRNG to the value of x.
186832 ** x==0 && db==0 Revert to default behavior of using the
186843 assert( db==0 || db->aDb[0].pSchema!=0 );
186844 if( db && (y = db->aDb[0].pSchema->schema_cookie)!=0 ){ x = y; }
186846 sqlite3_randomness(0,0);
186878 ** memory allocation error, 0 on success, or non-zero for an error.
186894 ** As a test of the fault simulator mechanism itself, sqlite3FaultSim(0)
186896 ** value from sqlite3FaultSim(0) becomes the return from
186910 rc = sqlite3FaultSim(0);
186933 ** Set the PENDING byte to the value in the argument, if X>0.
186934 ** Make no changes if X==0. Return the value of the pending byte
186937 ** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
186965 volatile int x = 0;
186966 assert( /*side-effects-ok*/ (x = va_arg(ap,int))!=0 );
186972 sqlite3ShowExpr(0);
186973 sqlite3ShowExprList(0);
186974 sqlite3ShowIdList(0);
186975 sqlite3ShowSrcList(0);
186976 sqlite3ShowWith(0);
186977 sqlite3ShowUpsert(0);
186979 sqlite3ShowTriggerStep(0);
186980 sqlite3ShowTriggerStepList(0);
186981 sqlite3ShowTrigger(0);
186982 sqlite3ShowTriggerList(0);
186985 sqlite3ShowWindow(0);
186986 sqlite3ShowWinFunc(0);
186988 sqlite3ShowSelect(0);
187001 ** The return value is ALWAYS(X) if X is true, or 0 if X is false.
187019 ** // ALWAYS(x) is a constant 1. NEVER(x) is a constant 0.
187024 rc = x ? ALWAYS(x) : 0;
187048 ** operation N should be 0. The idea is that a test program (like the
187074 ** If 2, then invoke xAlt() instead of localtime(). If 0, normal
187090 sqlite3GlobalConfig.xAltLocaltime = 0;
187137 ** By default this is 0x7ffffffe (over 2 billion), but that value is
187174 if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
187190 ** If onOff==0 and tnum>0 then reset the schema for all databases, causing
187199 if( iDb>=0 ){
187203 if( db->init.busy==0 && db->init.newTnum>0 ){
187264 ** op==0 Store the current sqlite3TreeTrace in *ptr
187273 case 0: *ptr = sqlite3TreeTrace; break;
187321 if( id>0 && id<=SQLITE_NTUNE ){
187323 }else if( id<0 && id>=-SQLITE_NTUNE ){
187345 if( *pOnOff<0 ){
187348 sqlite3Config.bJsonSelfcheck = (u8)((*pOnOff)&0xff);
187368 while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){
187404 for(i=0; i<nParam*2; i++){
187408 if( p==0 ) return 0;
187409 memset(p, 0, 4);
187412 for(i=0; i<nParam*2; i++){
187415 *(p++) = 0;
187418 *(p++) = 0;
187419 *(p++) = 0;
187430 if( p==0 ) return;
187448 if( zFilename==0 || zParam==0 ) return 0;
187457 if( zFilename==0 || N<0 ) return 0;
187460 while( ALWAYS(zFilename) && zFilename[0] && (N--)>0 ){
187464 return zFilename[0] ? zFilename : 0;
187472 bDflt = bDflt!=0;
187486 if( z && sqlite3DecOrHexToI64(z, &v)==0 ){
187503 if( zFilename==0 ) return 0;
187507 if( zFilename==0 ) return 0;
187510 while( ALWAYS(zFilename) && zFilename[0] ){
187518 return 0;
187530 int iDb = zDbName ? sqlite3FindDbName(db, zDbName) : 0;
187531 return iDb<0 ? 0 : db->aDb[iDb].pBt;
187542 return 0;
187545 if( N<0 || N>=db->nDb ){
187546 return 0;
187561 return 0;
187565 return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
187569 ** Return 1 if database is read-only or 0 if read/write. Return -1 if
187604 if( db->autoCommit==0 ){
187606 if( iDb==0 || iDb>1 ){
187610 i64 dummy = 0;
187612 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
187613 sqlite3PagerSnapshotOpen(pPager, 0);
187643 if( db->autoCommit==0 ){
187646 if( iDb==0 || iDb>1 ){
187650 int bUnlock = 0;
187652 if( db->nVdbeActive==0 ){
187666 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
187667 sqlite3PagerSnapshotOpen(pPager, 0);
187698 if( iDb==0 || iDb>1 ){
187701 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
187735 if( zOptName==0 ){
187737 return 0;
187743 if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
187748 for(i=0; i<nOpt; i++){
187749 if( sqlite3StrNICmp(zOptName, azCompileOpt[i], n)==0
187750 && sqlite3IsIdChar((unsigned char)azCompileOpt[i][n])==0
187755 return 0;
187766 if( N>=0 && N<nOpt ){
187769 return 0;
187814 static sqlite3 *SQLITE_WSD sqlite3BlockedList = 0;
187834 int seen = 0;
187844 assert( db==0 || p->pUnlockConnection!=db );
187845 assert( db==0 || p->pBlockingConnection!=db );
187889 checkListProperties(0);
187897 checkListProperties(0);
187919 ** on the same "db". If xNotify==0 then any prior callbacks are immediately
187935 if( xNotify==0 ){
187937 db->pBlockingConnection = 0;
187938 db->pUnlockConnection = 0;
187939 db->xUnlockNotify = 0;
187940 db->pUnlockArg = 0;
187941 }else if( 0==db->pBlockingConnection ){
187964 sqlite3ErrorWithMsg(db, rc, (rc?"database is deadlocked":0));
187977 if( db->pBlockingConnection==0 && db->pUnlockConnection==0 ){
187993 ** set to db, then set pBlockingConnection=0.
187997 ** set pUnlockConnection=0.
187999 ** 3) If the two steps above mean that pBlockingConnection==0 and
188000 ** pUnlockConnection==0, remove the entry from the blocked connections
188004 void (*xUnlockNotify)(void **, int) = 0; /* Unlock-notify cb to invoke */
188005 int nArg = 0; /* Number of entries in aArg[] */
188008 void **aDyn = 0; /* Dynamically allocated space for aArg[] */
188020 p->pBlockingConnection = 0;
188026 if( p->xUnlockNotify!=xUnlockNotify && nArg!=0 ){
188028 nArg = 0;
188032 assert( aArg==aDyn || (aDyn==0 && aArg==aStatic) );
188069 nArg = 0;
188076 p->pUnlockConnection = 0;
188077 p->xUnlockNotify = 0;
188078 p->pUnlockArg = 0;
188082 if( p->pBlockingConnection==0 && p->pUnlockConnection==0 ){
188085 p->pNextBlocked = 0;
188091 if( nArg!=0 ){
188152 ** A = 0xxxxxxx 7 bits of data and one flag bit
188167 ** 1: 0x01
188168 ** 127: 0x7f
188169 ** 128: 0x81 0x00
188177 ** word of the document has a position of 0.
188186 ** array { (position list for column 0)
188203 ** ending a position list array. POS_END is 0. POS_COLUMN is 1.
188209 ** value: 123 5 9 1 1 14 35 0 234 72 0
188215 ** (14-2 and 35-2+12). The 0 at H indicate the end-of-document. The
188217 ** (72-2) and then terminates with the 0 at K.
188235 ** varint iHeight; (height from leaf level, always 0)
188281 ** varint iHeight; (height from leaf level, always >0)
188339 ** leaves_end_block, and end_block are all 0.
188348 ** written individually (using LeafWriter) to a level 0 segment, with
188350 ** level 0 segments are merged into a single level 1 segment. Level 1
188351 ** is populated like level 0, and eventually MERGE_COUNT level 1
188512 ** Structure version. Should always be set to 0 or 1.
188527 ** This method should return either SQLITE_OK (0), or an SQLite error
188774 #define SizeofArray(X) ((int)(sizeof(X)/sizeof(X[0])))
188800 ** level values between 0 and 1023 (inclusive) belong to index 0, all levels
188822 #define POS_END (0) /* Position-list terminator */
188851 # define NEVER(X) (0)
188853 # define ALWAYS(X) ((X)?1:(assert(0),0))
188854 # define NEVER(X) ((X)?(assert(0),1):0)
188892 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
188901 # define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
188982 ** there is an entry in the aIndex[] array. Index 0 is an index of all the
188994 int nPrefix; /* Prefix length (0 for main terms index) */
189060 #define FTS3_EVAL_FILTER 0
189074 ** Fts3Cursor.eSearch will be set to FTS3_FULLTEXT_SEARCH+1. (+0 for a,
189079 #define FTS3_FULLSCAN_SEARCH 0 /* Linear scan of %_content table */
189089 #define FTS3_HAVE_LANGID 0x00010000 /* languageid=? */
189090 #define FTS3_HAVE_DOCID_GE 0x00020000 /* docid>=? */
189091 #define FTS3_HAVE_DOCID_LE 0x00040000 /* docid<=? */
189098 sqlite3_int64 iDocid; /* Current docid (if pList!=0) */
189114 int bFirst; /* True if token must appear at position 0 */
189160 ** aMI[iCol*3 + 0] = Undefined
189249 #define FTS3_SEGMENT_REQUIRE_POS 0x00000001
189250 #define FTS3_SEGMENT_IGNORE_EMPTY 0x00000002
189251 #define FTS3_SEGMENT_COLUMN_FILTER 0x00000004
189252 #define FTS3_SEGMENT_PREFIX 0x00000008
189253 #define FTS3_SEGMENT_SCAN 0x00000010
189254 #define FTS3_SEGMENT_FIRST 0x00000020
189273 int iColFilter; /* If >=0, filter for this column */
189290 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
189408 ** Write a 64-bit variable-length integer to memory starting at p[0].
189416 *q++ = (unsigned char) ((vu & 0x7f) | 0x80);
189418 }while( vu!=0 );
189419 q[-1] &= 0x7f; /* turn off high bit in final byte */
189426 if( (v & mask2)==0 ){ var = v; return ret; }
189429 if( (v & mask2)==0 ){ var = v; return ret; }
189438 GETVARINT_INIT(a, p, 0, 0x00, 0x80, *v, 1);
189439 GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *v, 2);
189440 GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *v, 3);
189441 GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *v, 4);
189442 b = (a & 0x0FFFFFFF );
189446 b += (c&0x7F) << shift;
189447 if( (c & 0x80)==0 ) break;
189454 ** Read a 64-bit variable-length integer from memory starting at p[0].
189455 ** Return the number of bytes read, or 0 on error.
189463 ** Read a 64-bit variable-length integer from memory starting at p[0] and
189465 ** Return the number of bytes read, or 0 on error.
189476 u64 b = 0;
189478 for(shift=0; shift<=63; shift+=7){
189479 u64 c = p<pX ? *p : 0;
189481 b += (c&0x7F) << shift;
189482 if( (c & 0x80)==0 ) break;
189497 GETVARINT_INIT(a, ptr, 0, 0x00, 0x80, *pi, 1);
189500 assert( a & 0x80 );
189503 GETVARINT_STEP(a, ptr, 7, 0x7F, 0x4000, *pi, 2);
189504 GETVARINT_STEP(a, ptr, 14, 0x3FFF, 0x200000, *pi, 3);
189505 GETVARINT_STEP(a, ptr, 21, 0x1FFFFF, 0x10000000, *pi, 4);
189506 a = (a & 0x0FFFFFFF );
189507 *pi = (int)(a | ((u32)(*ptr & 0x07) << 28));
189508 assert( 0==(a & 0x80000000) );
189509 assert( *pi>=0 );
189517 int i = 0;
189521 }while( v!=0 );
189542 quote = z[0];
189545 int iOut = 0; /* Index of next byte to write to output */
189559 z[iOut] = '\0';
189592 ** interested in. So, unless the doclist is corrupt, the 0x80 bit is
189594 for(p = (*pp)-2; p>=pStart && *p&0x80; p--);
189609 assert( p->nPendingData==0 );
189610 assert( p->pSegments==0 );
189614 for(i=0; i<SizeofArray(p->aStmt); i++){
189660 if( zSql==0 ){
189663 *pRc = sqlite3_exec(db, zSql, 0, 0, 0);
189721 zCols = sqlite3_mprintf("%Q, ", p->azColumn[0]);
189769 if( p->zContentTbl==0 ){
189775 for(i=0; zContentCols && i<p->nColumn; i++){
189782 if( zContentCols==0 ) rc = SQLITE_NOMEM;
189839 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
189842 p->nPgsz = sqlite3_column_int(pStmt, 0);
189849 assert( p->nPgsz>0 || rc!=SQLITE_OK );
189872 if( *zCsr=='\0' ) return 0;
189905 if( z==0 ) *pRc = SQLITE_NOMEM;
189930 for(i=0; zInput[i]; i++){
189935 *(z++) = '\0';
189964 char *zRet = 0;
189965 char *zFree = 0;
189969 if( p->zContentTbl==0 ){
189976 for(i=0; i<p->nColumn; i++){
189985 for(i=0; i<p->nColumn; i++){
190021 char *zRet = 0;
190022 char *zFree = 0;
190032 for(i=0; i<p->nColumn; i++){
190048 u64 iVal = 0;
190050 for(i=0; z[i]>='0' && z[i]<='9'; i++){
190051 iVal = iVal*10 + (z[i] - '0');
190052 if( iVal>0x7FFFFFFF ) return -1;
190064 ** Only decimal digits ('0'..'9') may be part of an integer value.
190073 int nInt = 0; /* Output value */
190077 nInt = 0;
190079 if( nByte==0 ){
190112 if( zParam && zParam[0] ){
190126 memset(aIndex, 0, sizeof(struct Fts3Index) * nIndex);
190131 int nPrefix = 0;
190133 assert( nPrefix>=0 );
190134 if( nPrefix==0 ){
190184 sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */
190190 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
190199 sqlite3_int64 nStr = 0; /* Size of all column names (incl. 0x00) */
190207 for(i=0; i<nCol; i++){
190214 if( azCol==0 ){
190218 for(i=0; i<nCol; i++){
190243 ** argv[0] -> module name ("fts3" or "fts4")
190258 Fts3Table *p = 0; /* Pointer to allocated vtab */
190263 int nString = 0; /* Bytes required to hold all column names */
190264 int nCol = 0; /* Number of columns in the FTS table */
190268 int isFts4 = (argv[0][3]=='4'); /* True for FTS4, false for FTS3 */
190270 sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */
190272 int nIndex = 0; /* Size of aIndex[] array */
190273 struct Fts3Index *aIndex = 0; /* Array of indexes for this table */
190276 int bNoDocsize = 0; /* True to omit %_docsize table */
190277 int bDescIdx = 0; /* True to store descending indexes */
190278 char *zPrefix = 0; /* Prefix parameter value (or NULL) */
190279 char *zCompress = 0; /* compress=? parameter (or NULL) */
190280 char *zUncompress = 0; /* uncompress=? parameter (or NULL) */
190281 char *zContent = 0; /* content=? parameter (or NULL) */
190282 char *zLanguageid = 0; /* languageid=? parameter (or NULL) */
190283 char **azNotindexed = 0; /* The set of notindexed= columns */
190284 int nNotindexed = 0; /* Size of azNotindexed[] array */
190286 assert( strlen(argv[0])==4 );
190287 assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
190288 || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
190297 memset((void*)aCol, 0, nByte);
190301 memset(azNotindexed, 0, nByte);
190327 && 0==sqlite3_strnicmp(z, "tokenize", 8)
190328 && 0==sqlite3Fts3IsIdChar(z[8])
190339 { "matchinfo", 9 }, /* 0 -> MATCHINFO */
190353 for(iOpt=0; iOpt<SizeofArray(aFts4Opt); iOpt++){
190360 case 0: /* MATCHINFO */
190371 zVal = 0;
190377 zVal = 0;
190383 zVal = 0;
190393 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
190399 zVal = 0;
190406 zVal = 0;
190411 zVal = 0;
190441 zCompress = 0;
190442 zUncompress = 0;
190443 if( nCol==0 ){
190445 aCol = 0;
190452 for(j=0; j<nCol; j++){
190453 if( sqlite3_stricmp(zLanguageid, aCol[j])==0 ){
190465 if( nCol==0 ){
190466 assert( nString==0 );
190467 aCol[0] = "content";
190472 if( pTokenizer==0 ){
190494 if( p==0 ){
190498 memset(p, 0, nByte);
190501 p->nPendingData = 0;
190505 p->bHasDocsize = (isFts4 && bNoDocsize==0);
190509 p->nAutoincrmerge = 0xff; /* 0xff means setting unknown */
190512 zContent = 0;
190513 zLanguageid = 0;
190520 for(i=0; i<nIndex; i++){
190535 for(iCol=0; iCol<nCol; iCol++){
190537 int n = 0;
190539 if( n>0 ){
190542 zCsr[n] = '\0';
190550 for(iCol=0; iCol<nCol; iCol++){
190552 for(i=0; i<nNotindexed; i++){
190555 && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n)
190559 azNotindexed[i] = 0;
190563 for(i=0; i<nNotindexed; i++){
190570 if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
190571 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
190612 for(i=0; i<nNotindexed; i++) sqlite3_free(azNotindexed[i]);
190622 assert( p->pSegments==0 );
190640 return fts3InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
190707 for(i=0; i<pInfo->nConstraint; i++){
190710 if( pCons->usable==0 ){
190725 bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1);
190728 if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){
190744 && pCons->iColumn>=0 && pCons->iColumn<=p->nColumn
190777 if( iCons>=0 ){
190781 if( iLangidCons>=0 ){
190785 if( iDocidGe>=0 ){
190789 if( iDocidLe>=0 ){
190798 struct sqlite3_index_orderby *pOrder = &pInfo->aOrderBy[0];
190799 if( pOrder->iColumn<0 || pOrder->iColumn==p->nColumn+1 ){
190809 assert( p->pSegments==0 );
190829 memset(pCsr, 0, sizeof(Fts3Cursor));
190843 if( p->pSeekStmt==0 ){
190846 pCsr->pStmt = 0;
190848 pCsr->bSeekStmt = 0;
190863 memset(&(&pCsr->base)[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
190872 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
190874 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
190880 ** If pCsr->pStmt has not been prepared (i.e. if pCsr->pStmt==0), then
190890 if( pCsr->pStmt==0 ){
190895 p->pSeekStmt = 0;
190901 p->db, zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
190924 pCsr->isRequireSeek = 0;
190931 if( rc==SQLITE_OK && ((Fts3Table *)pCsr->base.pVtab)->zContentTbl==0 ){
190974 char *zBuffer = 0; /* Buffer to load terms into */
190975 i64 nAlloc = 0; /* Size of allocated buffer */
190978 int nBuffer = 0; /* Total term size */
191002 int nPrefix = 0; /* Size of term prefix */
191013 isFirstTerm = 0;
191016 assert( nPrefix>=0 && nSuffix>=0 );
191017 if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){
191046 if( piFirst && (cmp<0 || (cmp==0 && nBuffer>nTerm)) ){
191048 piFirst = 0;
191051 if( piLast && cmp<0 ){
191053 piLast = 0;
191108 char *zBlob = 0; /* Blob read from %_segments table */
191109 int nBlob = 0; /* Size of zBlob in bytes */
191112 rc = sqlite3Fts3ReadBlock(p, *piLeaf, &zBlob, &nBlob, 0);
191114 rc = fts3SelectLeaf(p, zTerm, nTerm, zBlob, nBlob, piLeaf, 0);
191117 piLeaf = 0;
191118 zBlob = 0;
191122 rc = sqlite3Fts3ReadBlock(p, piLeaf?*piLeaf:*piLeaf2, &zBlob, &nBlob, 0);
191125 int iNewHeight = 0;
191148 assert_fts3_nc( iVal-*piPrev > 0 || (*piPrev==0 && iVal==0) );
191169 char c = 0;
191172 ** varint. A single POS_END (0) byte. Except, if the 0 byte is preceded by
191173 ** a byte with the 0x80 bit set, then it is not a varint 0, but the tail
191177 ** immediately preceded by a byte with the 0x80 bit set. Then increments
191182 c = *pEnd++ & 0x80;
191183 testcase( c!=0 && (*pEnd)==0 );
191206 ** a POS_END varint (0). This routine leaves *ppPoslist pointing to
191216 char c = 0;
191218 /* A column-list is terminated by either a 0x01 or 0x00 byte that is
191221 while( 0xFE & (*pEnd | c) ){
191222 c = *pEnd++ & 0x80;
191223 testcase( c!=0 && ((*pEnd)&0xfe)==0 );
191246 ** (in which case **pp will be a terminator bytes POS_END (0) or
191264 if( (**pp)&0xFE ){
191275 ** If parameter iCol is not 0, write an POS_COLUMN (1) byte followed by
191280 ** returning (do not modify it if iCol==0). Return the total number of bytes
191281 ** written (0 if iCol==0).
191284 int n = 0; /* Number of bytes written */
191288 *p = 0x01;
191316 if( iCol1==0 ) return FTS_CORRUPT_VTAB;
191318 else if( *p1==POS_END ) iCol1 = 0x7fffffff;
191319 else iCol1 = 0;
191323 if( iCol2==0 ) return FTS_CORRUPT_VTAB;
191325 else if( *p2==POS_END ) iCol2 = 0x7fffffff;
191326 else iCol2 = 0;
191329 sqlite3_int64 i1 = 0; /* Last position from pp1 */
191330 sqlite3_int64 i2 = 0; /* Last position from pp2 */
191331 sqlite3_int64 iPrev = 0;
191340 ** POS_END (0) or POS_COLUMN (1). The following block merges the two lists
191388 ** 0x02 0x01 0x02 0x03 0x03 0x00
191391 ** byte following the 0x00 terminator of their respective position lists.
191393 ** If isSaveLeft is 0, an entry is added to the output position list for
191412 int iCol1 = 0;
191413 int iCol2 = 0;
191416 assert( isSaveLeft==0 || isExact==0 );
191418 assert_fts3_nc( p!=0 && *p1!=0 && *p2!=0 );
191422 /* iCol1==0 indicates corruption. Column 0 does not have a POS_COLUMN
191424 if( iCol1==0 ) return 0;
191429 /* As above, iCol2==0 indicates corruption. */
191430 if( iCol2==0 ) return 0;
191436 sqlite3_int64 iPrev = 0;
191437 sqlite3_int64 iPos1 = 0;
191438 sqlite3_int64 iPos2 = 0;
191447 if( iPos1<0 || iPos2<0 ) break;
191451 || (isExact==0 && iPos2>iPos1 && iPos2<=iPos1+nToken)
191456 pSave = 0;
191460 if( (*p2&0xFE)==0 ) break;
191463 if( (*p1&0xFE)==0 ) break;
191473 fts3ColumnlistCopy(0, &p1);
191474 fts3ColumnlistCopy(0, &p2);
191475 assert( (*p1&0xFE)==0 && (*p2&0xFE)==0 );
191476 if( 0==*p1 || 0==*p2 ) break;
191485 ** iCol1 and iCol2) so that it points to either the 0x00 that marks the
191486 ** end of the position list, or the 0x01 that precedes the next
191490 fts3ColumnlistCopy(0, &p1);
191491 if( 0==*p1 ) break;
191495 fts3ColumnlistCopy(0, &p2);
191496 if( 0==*p2 ) break;
191502 fts3PoslistCopy(0, &p2);
191503 fts3PoslistCopy(0, &p1);
191507 return 0;
191509 *p++ = 0x00;
191545 fts3PoslistPhraseMerge(&pTmp1, nRight, 0, 0, pp1, pp2);
191549 fts3PoslistPhraseMerge(&pTmp2, nLeft, 1, 0, pp2, pp1);
191557 res = 0;
191578 ** has been reached. In this case *pp is set to 0 and the function returns.
191594 *pp = 0;
191629 if( bDescIdx==0 || *pbFirst==0 ){
191630 assert_fts3_nc( *pbFirst==0 || iVal>=*piPrev );
191636 assert( *pbFirst || *piPrev==0 );
191637 assert_fts3_nc( *pbFirst==0 || iWrite>0 );
191647 ** bDescDoclist is 0 when this macro is invoked, then it returns (i1-i2).
191654 #define DOCID_CMP(i1, i2) ((bDescDoclist?-1:1) * (i1>i2?1:((i1==i2)?0:-1)))
191677 sqlite3_int64 i1 = 0;
191678 sqlite3_int64 i2 = 0;
191679 sqlite3_int64 iPrev = 0;
191686 int bFirstOut = 0;
191688 *paOut = 0;
191689 *pnOut = 0;
191692 ** are delta encoded. If they are in ascending order (bDescDoclist==0),
191724 fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
191725 fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
191729 if( p2 && p1 && iDiff==0 ){
191735 }else if( !p2 || (p1 && iDiff<0) ){
191750 p = aOut = 0;
191753 memset(&aOut[(p-aOut)], 0, FTS3_BUFFER_PADDING);
191778 sqlite3_int64 i1 = 0;
191779 sqlite3_int64 i2 = 0;
191780 sqlite3_int64 iPrev = 0;
191787 int bFirstOut = 0;
191790 assert( nDist>0 );
191793 if( aOut==0 ) return SQLITE_NOMEM;
191799 fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
191800 fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
191804 if( iDiff==0 ){
191810 if( 0==fts3PoslistPhraseMerge(&p, nDist, 0, 1, &p1, &p2) ){
191817 }else if( iDiff<0 ){
191818 fts3PoslistCopy(0, &p1);
191821 fts3PoslistCopy(0, &p2);
191838 ** a token in position 0 (of any column). If so, it writes argument iDelta
191840 ** of the entries from pList at position 0, and terminated by an 0x00 byte.
191845 char *pList, /* Position list (no 0x00 term) */
191849 int nOut = 0;
191850 int bWritten = 0; /* True once iDelta has been written */
191854 if( *p!=0x01 ){
191855 if( *p==0x02 ){
191857 pOut[nOut++] = 0x02;
191860 fts3ColumnlistCopy(0, &p);
191867 if( *p==0x02 ){
191868 if( bWritten==0 ){
191872 pOut[nOut++] = 0x01;
191874 pOut[nOut++] = 0x02;
191876 fts3ColumnlistCopy(0, &p);
191879 pOut[nOut++] = 0x00;
191888 ** doclist stored in TermSelect.aaOutput[0]. If successful, delete all
191889 ** other doclists (except the aaOutput[0] one) and return SQLITE_OK.
191896 char *aOut = 0;
191897 int nOut = 0;
191903 for(i=0; i<SizeofArray(pTS->aaOutput); i++){
191908 pTS->aaOutput[i] = 0;
191923 pTS->aaOutput[i] = 0;
191930 pTS->aaOutput[0] = aOut;
191931 pTS->anOutput[0] = nOut;
191955 if( pTS->aaOutput[0]==0 ){
191972 pTS->aaOutput[0] = sqlite3_malloc64((i64)nDoclist + FTS3_VARINT_MAX + 1);
191973 pTS->anOutput[0] = nDoclist;
191974 if( pTS->aaOutput[0] ){
191975 memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
191976 memset(&pTS->aaOutput[0][nDoclist], 0, FTS3_VARINT_MAX);
191985 for(iOut=0; iOut<SizeofArray(pTS->aaOutput); iOut++){
191986 if( pTS->aaOutput[iOut]==0 ){
191987 assert( iOut>0 );
192005 pTS->aaOutput[iOut] = 0;
192026 if( (pCsr->nSegment%16)==0 ){
192050 int iIndex, /* Index to search (from 0 to p->nIndex-1) */
192059 sqlite3_stmt *pStmt = 0; /* Statement to iterate through segments */
192062 /* If iLevel is less than 0 and this is not a scan, include a seg-reader
192068 if( iLevel<0 && p->aIndex && p->iPrevLangid==iLangid ){
192069 Fts3SegReader *pSeg = 0;
192082 Fts3SegReader *pSeg = 0;
192094 sqlite3_int64 *pi = (isPrefix ? &iLeavesEndBlock : 0);
192097 if( isPrefix==0 && isScan==0 ) iLeavesEndBlock = iStartBlock;
192101 (isPrefix==0 && isScan==0),
192124 int iIndex, /* Index to search (from 0 to p->nIndex-1) */
192132 assert( iIndex>=0 && iIndex<p->nIndex );
192135 || iLevel>=0
192138 assert( FTS3_SEGCURSOR_ALL<0 && FTS3_SEGCURSOR_PENDING<0 );
192139 assert( isPrefix==0 || isScan==0 );
192141 memset(pCsr, 0, sizeof(Fts3MultiSegReader));
192161 iLangid, 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0,pCsr
192176 ** Output parameter *ppSegcsr is set to 0 if an error occurs.
192191 int bFound = 0; /* True once an index has been found */
192195 for(i=1; bFound==0 && i<p->nIndex; i++){
192199 i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0, pSegcsr
192205 for(i=1; bFound==0 && i<p->nIndex; i++){
192209 i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 1, 0, pSegcsr
192220 if( bFound==0 ){
192222 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, isPrefix, 0, pSegcsr
192257 memset(&tsc, 0, sizeof(TermSelect));
192260 | (pTok->isPrefix ? FTS3_SEGMENT_PREFIX : 0)
192261 | (pTok->bFirst ? FTS3_SEGMENT_FIRST : 0)
192262 | (iColumn<p->nColumn ? FTS3_SEGMENT_COLUMN_FILTER : 0);
192278 *ppOut = tsc.aaOutput[0];
192279 *pnOut = tsc.anOutput[0];
192282 for(i=0; i<SizeofArray(tsc.aaOutput); i++){
192288 pTok->pSegcsr = 0;
192302 int nDoc = 0; /* Return value */
192308 while( (*p++)&0x80 ); /* Skip docid varint */
192309 fts3PoslistCopy(0, &p); /* Skip over position list */
192337 pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0);
192344 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
192376 ** number idxNum-FTS3_FULLTEXT_SEARCH, 0 indexed. argv[0] is the right-hand
192392 sqlite3_value *pCons = 0; /* The MATCH or rowid constraint, if any */
192393 sqlite3_value *pLangid = 0; /* The "langid = ?" constraint, if any */
192394 sqlite3_value *pDocidGe = 0; /* The "docid >= ?" constraint, if any */
192395 sqlite3_value *pDocidLe = 0; /* The "docid <= ?" constraint, if any */
192405 eSearch = (idxNum & 0x0000FFFF);
192406 assert( eSearch>=0 && eSearch<=(FTS3_FULLTEXT_SEARCH+p->nColumn) );
192407 assert( p->pSegments==0 );
192410 iIdx = 0;
192425 pCsr->bDesc = (idxStr[0]=='D');
192435 if( zQuery==0 && sqlite3_value_type(pCons)!=SQLITE_NULL ){
192439 pCsr->iLangid = 0;
192442 assert( p->base.zErrMsg==0 );
192455 pCsr->iPrevId = 0;
192478 p->db,zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
192542 assert( iCol>=0 && iCol<=p->nColumn+2 );
192545 case 0:
192547 sqlite3_result_pointer(pCtx, pCsr, "fts3cursor", 0);
192559 }else if( p->zLanguageid==0 ){
192560 sqlite3_result_int(pCtx, 0);
192570 rc = fts3CursorSeek(0, pCsr);
192577 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
192609 ** small - often between 0 and 2. So the overhead of the incremental
192629 && p->nAutoincrmerge && p->nAutoincrmerge!=0xff
192631 int mxLevel = 0; /* Maximum relative level value in db */
192635 assert( rc==SQLITE_OK || mxLevel==0 );
192648 ** to 0 or 1). Return SQLITE_OK if successful, or an SQLite error code
192656 int res = sqlite3_table_column_metadata(p->db, p->zDb, zTbl, 0,0,0,0,0,0);
192673 assert( p->pSegments==0 );
192674 assert( p->nPendingData==0 );
192676 p->nLeafAdd = 0;
192695 assert( p->nPendingData==0 );
192696 assert( p->inTransaction!=0 );
192697 assert( p->pSegments==0 );
192698 TESTONLY( p->inTransaction = 0 );
192710 assert( p->inTransaction!=0 );
192711 TESTONLY( p->inTransaction = 0 );
192724 char c = 0;
192726 /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */
192727 while( p>pStart && (c=*p--)==0 );
192730 ** poslist). This is an 0x00 byte preceded by some byte that does not
192731 ** have the 0x80 bit set. */
192732 while( p>pStart && (*p & 0x80) | c ){
192735 assert( p==pStart || c==0 );
192737 /* At this point p points to that preceding byte without the 0x80 bit
192743 ** The second part of the if condition (c==0 && *ppPoslist>&p[2])
192748 ** 0x0A 0x00 <next docid delta varint>
192750 if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; }
192751 while( *p++&0x80 );
192768 sqlite3_value *pVal, /* argv[0] passed to function */
192773 if( (*ppCsr)!=0 ){
192792 Fts3Cursor *pCsr; /* Cursor handle passed through apVal[0] */
192809 if( fts3FunctionArg(pContext, "snippet", apVal[0], &pCsr) ) return;
192824 }else if( nToken==0 ){
192839 Fts3Cursor *pCsr; /* Cursor handle passed through apVal[0] */
192844 if( fts3FunctionArg(pContext, "offsets", apVal[0], &pCsr) ) return;
192867 Fts3Cursor *pCursor; /* Cursor handle passed through apVal[0] */
192872 if( fts3FunctionArg(pContext, "optimize", apVal[0], &pCursor) ) return;
192899 Fts3Cursor *pCsr; /* Cursor handle passed through apVal[0] */
192901 if( SQLITE_OK==fts3FunctionArg(pContext, "matchinfo", apVal[0], &pCsr) ){
192902 const char *zArg = 0;
192936 for(i=0; i<SizeofArray(aOverload); i++){
192937 if( strcmp(zName, aOverload[i].zName)==0 ){
192943 /* No function of the specified name was found. Return 0. */
192944 return 0;
192968 assert( p->nPendingData==0 );
192975 if( p->zContentTbl==0 ){
193003 p->bIgnoreSavepoint = 0;
193019 if( pTab->bIgnoreSavepoint==0 ){
193020 if( fts3HashCount(&pTab->aIndex[0].hPending)>0 ){
193026 rc = sqlite3_exec(pTab->db, zSql, 0, 0, 0);
193027 pTab->bIgnoreSavepoint = 0;
193079 for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
193080 if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
193082 return 0;
193098 int bOk = 0;
193103 if( rc==SQLITE_ERROR || (rc&0xFF)==SQLITE_CORRUPT ){
193108 }else if( rc==SQLITE_OK && bOk==0 ){
193111 if( *pzErr==0 ) rc = SQLITE_NOMEM;
193155 if( pHash->nRef<=0 ){
193188 Fts3HashWrapper *pHash = 0;
193189 const sqlite3_tokenizer_module *pSimple = 0;
193190 const sqlite3_tokenizer_module *pPorter = 0;
193192 const sqlite3_tokenizer_module *pUnicode = 0;
193196 const sqlite3_tokenizer_module *pIcu = 0;
193221 pHash->nRef = 0;
193312 for(i=0; i<nToken; i++){
193322 assert( pExpr->pPhrase->iDoclistToken==0 );
193352 if( pList==0 ){
193354 p->doclist.aAll = 0;
193355 p->doclist.nAll = 0;
193358 else if( p->iDoclistToken<0 ){
193363 else if( p->doclist.aAll==0 ){
193414 for(iToken=0; rc==SQLITE_OK && iToken<p->nToken; iToken++){
193416 assert( pToken->pDeferred==0 || pToken->pSegcsr==0 );
193419 int nThis = 0;
193420 char *pThis = 0;
193426 assert( pToken->pSegcsr==0 );
193445 char *aPoslist = 0; /* Position list for deferred tokens */
193446 int nPoslist = 0; /* Number of bytes in aPoslist */
193448 char *aFree = (pPhrase->doclist.bFreeList ? pPhrase->doclist.pList : 0);
193450 for(iToken=0; iToken<pPhrase->nToken; iToken++){
193460 if( pList==0 ){
193463 pPhrase->doclist.pList = 0;
193464 pPhrase->doclist.nList = 0;
193467 }else if( aPoslist==0 ){
193476 assert( iPrev>=0 );
193477 fts3PoslistPhraseMerge(&aOut, iToken-iPrev, 0, 1, &p1, &p2);
193481 if( nPoslist==0 ){
193484 pPhrase->doclist.pList = 0;
193485 pPhrase->doclist.nList = 0;
193493 if( iPrev>=0 ){
193495 if( nMaxUndeferred<0 ){
193524 if( fts3PoslistPhraseMerge(&aOut, nDistance, 0, 1, &p1, &p2) ){
193529 pPhrase->doclist.pList = 0;
193530 pPhrase->doclist.nList = 0;
193569 int bHaveIncr = 0;
193572 && p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0
193574 && pTab->bNoIncrDoclist==0
193577 for(i=0; bIncrOk==1 && i<p->nToken; i++){
193579 if( pToken->bFirst || (pToken->pSegcsr!=0 && !pToken->pSegcsr->bLookup) ){
193580 bIncrOk = 0;
193588 for(i=0; rc==SQLITE_OK && i<p->nToken; i++){
193599 p->bIncr = 0;
193602 assert( rc!=SQLITE_OK || p->nToken<1 || p->aToken[0].pSegcsr==0 || p->bIncr );
193612 ** The doclist may be sorted in ascending (parameter bDescIdx==0) or
193627 assert( nDoclist>0 );
193628 assert( *pbEof==0 );
193629 assert_fts3_nc( p || *piDocid==0 );
193632 if( p==0 ){
193633 sqlite3_int64 iDocid = 0;
193634 char *pNext = 0;
193644 fts3PoslistCopy(0, &pDocid);
193645 while( pDocid<pEnd && *pDocid==0 ) pDocid++;
193682 assert( nDoclist>0 );
193683 assert( *pbEof==0 );
193684 assert_fts3_nc( p || *piDocid==0 );
193687 if( p==0 ){
193691 fts3PoslistCopy(0, &p);
193692 while( p<&aDoclist[nDoclist] && *p==0 ) p++;
193719 assert( pDL->aAll!=0 || pIter==0 );
193724 if( pIter==0 || pIter>=(pEnd = pDL->aAll + pDL->nAll) ){
193730 if( pTab->bDescIdx==0 || pDL->pNextDocid==0 ){
193736 fts3PoslistCopy(0, &pIter);
193739 /* pIter now points just past the 0x00 that terminates the position-
193745 while( pIter<pEnd && *pIter==0 ) pIter++;
193749 *pbEof = 0;
193783 assert( p->bIgnore==0 );
193784 assert( pPhrase->aToken[iToken].pSegcsr==0 );
193791 assert( pToken->pDeferred==0 );
193792 assert( pToken->pSegcsr || pPhrase->iDoclistToken>=0 );
193794 assert( p->bIgnore==0 );
193798 if( p->pList==0 ) *pbEof = 1;
193820 ** successfully advanced, *pbEof is set to 0.
193833 u8 bEof = 0;
193840 rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr,
193843 if( pDL->pList==0 ) bEof = 1;
193848 memset(a, 0, sizeof(a));
193852 while( bEof==0 ){
193853 int bMaxSet = 0;
193854 sqlite3_int64 iMax = 0; /* Largest docid for all iterators */
193858 for(i=0; rc==SQLITE_OK && i<p->nToken && bEof==0; i++){
193860 if( a[i].bIgnore==0 && (bMaxSet==0 || DOCID_CMP(iMax, a[i].iDocid)<0) ){
193865 assert( rc!=SQLITE_OK || (p->nToken>=1 && a[p->nToken-1].bIgnore==0) );
193869 for(i=0; i<p->nToken; i++){
193870 while( rc==SQLITE_OK && bEof==0
193871 && a[i].bIgnore==0 && DOCID_CMP(a[i].iDocid, iMax)<0
193874 if( DOCID_CMP(a[i].iDocid, iMax)>0 ){
193876 i = 0;
193882 if( bEof==0 ){
193883 int nList = 0;
193888 memset(&aDoclist[nByte], 0, FTS3_BUFFER_PADDING);
193890 for(i=0; i<(p->nToken-1); i++){
193891 if( a[i].bIgnore==0 ){
193896 int res = fts3PoslistPhraseMerge(&pOut, nDist, 0, 1, &pL, &pR);
193897 if( res==0 ) break;
193924 ** successfully advanced, *pbEof is set to 0.
193975 for(i=0; i<nToken; i++){
193976 if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
194030 for(i=0; *pRc==SQLITE_OK && i<pPhrase->nToken; i++){
194074 if( pCsr->nRowAvg==0 ){
194079 ** Entry 0 of the %_stat table is a blob containing (nCol+1) FTS3
194088 sqlite3_int64 nDoc = 0;
194089 sqlite3_int64 nByte = 0;
194095 a = sqlite3_column_blob(pStmt, 0);
194096 testcase( a==0 ); /* If %_stat.value set to X'' */
194098 pEnd = &a[sqlite3_column_bytes(pStmt, 0)];
194104 if( nDoc==0 || nByte==0 ){
194111 assert( pCsr->nRowAvg>0 );
194140 int nDocSize = 0; /* Number of pages per doc loaded */
194143 int nOvfl = 0; /* Total overflow pages used by doclists */
194144 int nToken = 0; /* Total number of tokens in cluster */
194146 int nMinEst = 0; /* The minimum count for any phrase so far. */
194161 for(ii=0; ii<nTC; ii++){
194167 if( nOvfl==0 || nToken<2 ) return SQLITE_OK;
194171 assert( rc!=SQLITE_OK || nDocSize>0 );
194196 for(ii=0; ii<nToken && rc==SQLITE_OK; ii++){
194198 Fts3TokenAndCost *pTC = 0; /* Set to cheapest remaining token. */
194201 for(iTC=0; iTC<nTC; iTC++){
194218 pToken->pSegcsr = 0;
194225 if( ii==0 || (pTC->pPhrase->nToken>1 && ii!=nToken-1) ){
194230 int nList = 0;
194231 char *pList = 0;
194233 assert( rc==SQLITE_OK || pList==0 );
194244 if( ii==0 || nCount<nMinEst ) nMinEst = nCount;
194248 pTC->pToken = 0;
194269 int nToken = 0;
194270 int nOr = 0;
194292 fts3EvalTokenCosts(pCsr, 0, pCsr->pExpr, &pTC, &ppOr, &rc);
194297 rc = fts3EvalSelectDeferred(pCsr, 0, aTC, nToken);
194298 for(ii=0; rc==SQLITE_OK && ii<nOr; ii++){
194319 pPhrase->doclist.pList = 0;
194320 pPhrase->doclist.nList = 0;
194321 pPhrase->doclist.bFreeList = 0;
194340 ** leaves 0 positions, zero is returned. Otherwise, non-zero.
194368 assert_fts3_nc( nNew<=pPhrase->doclist.nList && nNew>0 );
194369 if( nNew>=0 && nNew<=pPhrase->doclist.nList ){
194370 assert( pPhrase->doclist.pList[nNew]=='\0' );
194371 memset(&pPhrase->doclist.pList[nNew], 0, pPhrase->doclist.nList - nNew);
194392 ** Fts3Expr.iDocid (valid if bEof==0. The docid of the next row)
194427 if( *pRc==SQLITE_OK && pExpr->bEof==0 ){
194456 if( iDiff==0 ) break;
194457 if( iDiff<0 ){
194469 while( *pRc==SQLITE_OK && pRight->bEof==0 ){
194470 memset(pDl->pList, 0, pDl->nList);
194476 while( *pRc==SQLITE_OK && pLeft->bEof==0 ){
194477 memset(pDl->pList, 0, pDl->nList);
194495 if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
194497 }else if( pLeft->bEof || iCmp>0 ){
194506 if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
194519 if( pRight->bStart==0 ){
194525 if( pLeft->bEof==0 ){
194528 && DOCID_CMP(pLeft->iDocid, pRight->iDocid)>0
194561 ** match the current row, 0 is returned. The position lists may or may not
194562 ** be edited if 0 is returned.
194589 && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
194592 sqlite3_int64 nTmp = 0; /* Bytes of temp space */
194597 assert( p->pRight->pPhrase->doclist.nList>0 );
194604 res = 0;
194677 if( bHit==0
194679 && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
194682 for(p=pExpr; p->pPhrase==0; p=p->pLeft){
194718 bHit = (pPhrase->doclist.pList!=0);
194724 pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId
194725 && pExpr->pPhrase->doclist.nList>0
194747 ** returns 0. Otherwise, it tests whether or not after considering NEAR
194757 ** query, return 0.
194761 int bMiss = 0;
194771 rc = fts3CursorSeek(0, pCsr);
194776 bMiss = (0==fts3EvalTestExpr(pCsr, pCsr->pExpr, &rc));
194792 assert( pCsr->isEof==0 );
194793 if( pExpr==0 ){
194797 if( pCsr->isRequireSeek==0 ){
194800 assert( sqlite3_data_count(pCsr->pStmt)==0 );
194806 }while( pCsr->isEof==0 && sqlite3Fts3EvalTestDeferred(pCsr, &rc) );
194812 (pCsr->bDesc==0 && pCsr->iPrevId>pCsr->iMaxDocid)
194813 || (pCsr->bDesc!=0 && pCsr->iPrevId<pCsr->iMinDocid)
194842 for(i=0; i<pPhrase->nToken; i++){
194844 assert( pToken->pDeferred==0 );
194849 *pRc = fts3EvalPhraseStart(pCsr, 0, pPhrase);
194851 pPhrase->doclist.pNextDocid = 0;
194852 pPhrase->doclist.iDocid = 0;
194853 pPhrase->pOrPoslist = 0;
194856 pExpr->iDocid = 0;
194857 pExpr->bEof = 0;
194858 pExpr->bStart = 0;
194872 if( pExpr->bEof==0 ){
194895 int iCol = 0;
194899 u8 c = 0;
194900 int iCnt = 0;
194901 while( 0xFE & (*p | c) ){
194902 if( (c&0x80)==0 ) iCnt++;
194903 c = *p++ & 0x80;
194910 pExpr->aMI[iCol*3 + 2] += (iCnt>0);
194911 if( *p==0x00 ) break;
194930 if( pExpr->aMI==0 ){
194932 if( pExpr->aMI==0 ) return SQLITE_NOMEM;
194934 memset(pExpr->aMI, 0, pTab->nColumn * 3 * sizeof(u32));
194956 if( pExpr->aMI==0 ){
194980 while( pCsr->isEof==0 && rc==SQLITE_OK ){
194984 if( pCsr->isRequireSeek==0 ) sqlite3_reset(pCsr->pStmt);
194985 assert( sqlite3_data_count(pCsr->pStmt)==0 );
194993 }while( pCsr->isEof==0
194998 if( rc==SQLITE_OK && pCsr->isEof==0 ){
195003 pCsr->isEof = 0;
195018 assert_fts3_nc( pRoot->bEof==0 );
195066 assert( pCsr->nDoc>0 );
195067 for(iCol=0; iCol<pTab->nColumn; iCol++){
195075 for(iCol=0; iCol<pTab->nColumn; iCol++){
195095 ** compression and is terminated by either an 0x01 or 0x00 byte. For example,
195099 ** 0x04 0x05 0x03 0x01 or 0x04 0x05 0x03 0x00
195118 *ppOut = 0;
195119 assert( iCol>=0 && iCol<pTab->nColumn );
195129 int bOr = 0;
195130 u8 bTreeEof = 0;
195147 if( bOr==0 ) return SQLITE_OK;
195162 if( bEofSave==0 && pRun->iDocid==iDocid ) break;
195164 assert( rc!=SQLITE_OK || pPhrase->bIncr==0 );
195178 u8 bEof = 0;
195191 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
195199 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){
195209 if( bEof || iDocid!=pCsr->iPrevId ) bMatch = 0;
195215 pIter = 0;
195218 if( pIter==0 ) return SQLITE_OK;
195220 if( *pIter==0x01 ){
195224 iThis = 0;
195227 fts3ColumnlistCopy(0, &pIter);
195228 if( *pIter==0x00 ) return SQLITE_OK;
195232 if( *pIter==0x00 ){
195233 pIter = 0;
195236 *ppOut = ((iCol==iThis)?pIter:0);
195252 memset(&pPhrase->doclist, 0, sizeof(Fts3Doclist));
195253 for(i=0; i<pPhrase->nToken; i++){
195255 pPhrase->aToken[i].pSegcsr = 0;
195375 if( nDb==4 && 0==sqlite3_strnicmp("temp", zDb, 4) ){
195393 memset(p, 0, nByte);
195424 for(i=0; i<SizeofArray(pFts3->aStmt); i++){
195454 && pInfo->aOrderBy[0].iColumn==0
195455 && pInfo->aOrderBy[0].desc==0
195462 for(i=0; i<pInfo->nConstraint; i++){
195467 if( iCol==0 ){
195480 if( iEq>=0 ){
195485 pInfo->idxNum = 0;
195487 if( iGe>=0 ){
195492 if( iLe>=0 ){
195498 if( iLangid>=0 ){
195516 memset(pCsr, 0, sizeof(Fts3auxCursor));
195544 if( aNew==0 ) return SQLITE_NOMEM;
195545 memset(&aNew[pCsr->nStat], 0,
195566 if( pCsr->aStat[pCsr->iCol].nDoc>0 ) return SQLITE_OK;
195571 int i = 0;
195576 int eState = 0;
195581 if( mc<0 || (mc==0 && pCsr->csr.nTerm>pCsr->nStop) ){
195588 memset(pCsr->aStat, 0, sizeof(struct Fts3auxColstats) * pCsr->nStat);
195589 iCol = 0;
195593 sqlite3_int64 v = 0;
195597 /* State 0. In this state the integer just read was a docid. */
195598 case 0:
195599 pCsr->aStat[0].nDoc++;
195601 iCol = 0;
195606 ** start of a position list for column 0.
195609 ** integer encountered in state 1 is not 0 or 1, then we need to
195610 ** increment the column 0 "nDoc" count for this term.
195613 assert( iCol==0 );
195621 if( v==0 ){ /* 0x00. Next integer will be a docid. */
195622 eState = 0;
195623 }else if( v==1 ){ /* 0x01. Next integer will be a column number. */
195627 pCsr->aStat[0].nOcc++;
195645 pCsr->iCol = 0;
195665 int isScan = 0;
195666 int iLangVal = 0; /* Language id to query */
195672 int iNext = 0;
195677 assert( idxStr==0 );
195678 assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0
195704 memset(&pCsr->csr, 0, ((u8*)&pCsr[1]) - (u8*)&pCsr->csr);
195709 if( iEq>=0 || iGe>=0 ){
195710 const unsigned char *zStr = sqlite3_value_text(apVal[0]);
195711 assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
195714 if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
195719 if( iLe>=0 ){
195721 if( pCsr->zStop==0 ) return SQLITE_NOMEM;
195725 if( iLangid>=0 ){
195733 if( iLangVal<0 ) iLangVal = 0;
195737 rc = sqlite3Fts3SegReaderCursor(pFts3, iLangVal, 0, FTS3_SEGCURSOR_ALL,
195738 pCsr->filter.zTerm, pCsr->filter.nTerm, 0, isScan, &pCsr->csr
195766 assert( p->isEof==0 );
195768 case 0: /* term */
195815 0, /* iVersion */
195828 0, /* xUpdate */
195829 0, /* xBegin */
195830 0, /* xSync */
195831 0, /* xCommit */
195832 0, /* xRollback */
195833 0, /* xFindFunction */
195834 0, /* xRename */
195835 0, /* xSavepoint */
195836 0, /* xRelease */
195837 0, /* xRollbackTo */
195838 0, /* xShadowName */
195839 0 /* xIntegrity */
195843 rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
195917 SQLITE_API int sqlite3_fts3_enable_parentheses = 0;
195922 # define sqlite3_fts3_enable_parentheses 0
195962 ** is defined to accept an argument of type char, and always returns 0 for
195977 if( pRet ) memset(pRet, 0, nByte);
195989 sqlite3_tokenizer_cursor *pCsr = 0;
195993 assert( rc==SQLITE_OK || pCsr==0 );
196000 pCsr = 0;
196021 for(ii=0; ii<n; ii++){
196054 Fts3Expr *pRet = 0;
196060 int nToken = 0, iStart = 0, iEnd = 0, iPosition = 0;
196071 if( iBarred>=0 ){
196085 pRet->pPhrase->aToken[0].n = nToken;
196086 pRet->pPhrase->aToken[0].z = (char*)&pRet->pPhrase->aToken[1];
196087 memcpy(pRet->pPhrase->aToken[0].z, zToken, nToken);
196090 pRet->pPhrase->aToken[0].isPrefix = 1;
196096 && iStart>0 && z[iStart-1]=='-'
196100 }else if( pParse->bFts4 && iStart>0 && z[iStart-1]=='^' ){
196101 pRet->pPhrase->aToken[0].bFirst = 1;
196112 if( iBarred>=0 ){
196148 ** to 0.
196158 Fts3Expr *p = 0;
196159 sqlite3_tokenizer_cursor *pCursor = 0;
196160 char *zTemp = 0;
196161 i64 nTemp = 0;
196164 int nToken = 0;
196189 for(ii=0; rc==SQLITE_OK; ii++){
196191 int nByte = 0, iBegin = 0, iEnd = 0, iPos = 0;
196205 memset(pToken, 0, sizeof(Fts3PhraseToken));
196212 pToken->bFirst = (iBegin>0 && zInput[iBegin-1]=='^');
196220 char *zBuf = 0;
196227 memset(p, 0, (char *)&(((Fts3Phrase *)&p[1])->aToken[0])-(char *)p);
196234 assert( nTemp==0 || zTemp );
196239 for(jj=0; jj<p->pPhrase->nToken; jj++){
196253 p = 0;
196261 ** structure, or set to 0 if the end of the input buffer is reached.
196279 { "OR" , 2, 0, FTSQUERY_OR },
196282 { "NEAR", 4, 0, FTSQUERY_NEAR }
196288 Fts3Expr *pRet = 0;
196293 pParse->isNot = 0;
196298 while( nInput>0 && fts3isspace(*zInput) ){
196302 if( nInput==0 ){
196307 for(ii=0; ii<(int)(sizeof(aKeyword)/sizeof(struct Fts3Keyword)); ii++){
196310 if( (pKey->parenOnly & ~sqlite3_fts3_enable_parentheses)!=0 ){
196314 if( nInput>=pKey->n && 0==memcmp(zInput, pKey->z, pKey->n) ){
196322 if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){
196333 || cNext=='"' || cNext=='(' || cNext==')' || cNext==0
196368 int nConsumed = 0;
196372 #elif SQLITE_MAX_EXPR_DEPTH>0
196381 *ppExpr = 0;
196398 iColLen = 0;
196399 for(ii=0; ii<pParse->nCol; ii++){
196403 && sqlite3_strnicmp(zStr, zInput, nStr)==0
196483 ** bytes read from buffer z. Otherwise, *ppExpr is set to 0 and SQLITE_NOMEM
196492 Fts3Expr *pRet = 0;
196493 Fts3Expr *pPrev = 0;
196494 Fts3Expr *pNotBranch = 0; /* Only used in legacy parse mode */
196501 Fts3Expr *p = 0;
196502 int nByte = 0;
196505 assert( nByte>0 || (rc!=SQLITE_OK && p==0) );
196579 assert( pPrev && pPrev->pLeft && pPrev->pRight==0 );
196592 assert( nByte>0 );
196594 assert( rc!=SQLITE_OK || (nByte>0 && nByte<=nIn) );
196625 pRet = 0;
196638 if( nMaxDepth<0 ){
196664 Fts3Expr *pFree = 0; /* List of free nodes. Linked by pParent. */
196667 if( nMaxDepth==0 ){
196675 if( 0==apLeaf ){
196678 memset(apLeaf, 0, sizeof(Fts3Expr *) * nMaxDepth);
196687 assert( p->pParent==0 || p->pParent->pLeft==p );
196696 assert( pParent==0 || pParent->pLeft==p );
196697 p->pParent = 0;
196699 pParent->pLeft = 0;
196701 pRoot = 0;
196706 for(iLvl=0; p && iLvl<nMaxDepth; iLvl++){
196707 if( apLeaf[iLvl]==0 ){
196709 p = 0;
196719 p->pParent = 0;
196720 apLeaf[iLvl] = 0;
196730 if( pParent==0 ) break;
196736 assert( pParent->pParent==0 || pParent->pParent->pLeft==pParent );
196752 p = 0;
196753 for(i=0; i<nMaxDepth; i++){
196755 if( p==0 ){
196757 p->pParent = 0;
196759 assert( pFree!=0 );
196767 p->pParent = 0;
196777 for(i=0; i<nMaxDepth; i++){
196780 while( (pDel=pFree)!=0 ){
196786 assert( pFree==0 );
196793 pRoot->pLeft = 0;
196794 pRoot->pRight = 0;
196795 pLeft->pParent = 0;
196796 pRight->pParent = 0;
196818 pRoot = 0;
196849 memset(&sParse, 0, sizeof(ParseContext));
196856 if( z==0 ){
196857 *ppExpr = 0;
196860 if( n<0 ){
196864 assert( rc==SQLITE_OK || *ppExpr==0 );
196881 ** error) is returned and *ppExpr is set to 0.
196924 *ppExpr = 0;
196943 assert( p->eType==FTSQUERY_PHRASE || p->pPhrase==0 );
196958 assert( pDel==0 || pDel->pParent==0 );
196960 assert( p->pParent==0 || p==p->pParent->pRight || p==p->pParent->pLeft );
196997 if( pExpr==0 ){
197005 "%zPHRASE %d 0", zBuf, pPhrase->iColumn);
197006 for(i=0; zBuf && i<pPhrase->nToken; i++){
197059 sqlite3_tokenizer *pTokenizer = 0;
197061 char **azCol = 0;
197067 char *zBuf = 0;
197069 const char *zTokenizer = 0;
197070 char *zErr = 0;
197079 zTokenizer = (const char*)sqlite3_value_text(argv[0]);
197099 for(ii=0; ii<nCol; ii++){
197104 char *zDummy = 0;
197106 pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr, &zDummy
197108 assert( rc==SQLITE_OK || pExpr==0 );
197112 pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr
197118 }else if( rc==SQLITE_NOMEM || !(zBuf = exprToString(pExpr, 0)) ){
197139 fts3ExprTestCommon(0, context, argc, argv);
197155 db, "fts3_exprtest", -1, SQLITE_UTF8, (void*)pHash, fts3ExprTest, 0, 0
197159 -1, SQLITE_UTF8, (void*)pHash, fts3ExprTestRebalance, 0, 0
197210 memset(p, 0, n);
197229 assert( pNew!=0 );
197233 pNew->first = 0;
197234 pNew->count = 0;
197235 pNew->htsize = 0;
197236 pNew->ht = 0;
197246 assert( pH!=0 );
197248 pH->first = 0;
197250 pH->ht = 0;
197251 pH->htsize = 0;
197260 pH->count = 0;
197268 unsigned h = 0;
197269 if( nKey<=0 ) nKey = (int) strlen(z);
197270 while( nKey > 0 ){
197274 return (int)(h & 0x7fffffff);
197285 int h = 0;
197287 while( nKey-- > 0 ){
197290 return h & 0x7fffffff;
197351 pNew->prev = 0;
197370 assert( (new_size & (new_size-1))==0 );
197372 if( new_ht==0 ) return 1;
197377 for(elem=pH->first, pH->first=0; elem; elem = next_elem){
197382 return 0;
197405 if( (*xCompare)(elem->pKey,elem->nKey,pKey,nKey)==0 ){
197411 return 0;
197436 if( pEntry->count<=0 ){
197437 pEntry->chain = 0;
197444 if( pH->count<=0 ){
197445 assert( pH->first==0 );
197446 assert( pH->count==0 );
197459 if( pH==0 || pH->ht==0 ) return 0;
197461 assert( xHash!=0 );
197463 assert( (pH->htsize & (pH->htsize-1))==0 );
197476 return pElem ? pElem->data : 0;
197506 assert( pH!=0 );
197508 assert( xHash!=0 );
197510 assert( (pH->htsize & (pH->htsize-1))==0 );
197515 if( data==0 ){
197522 if( data==0 ) return 0;
197523 if( (pH->htsize==0 && fts3Rehash(pH,8))
197526 pH->count = 0;
197529 assert( pH->htsize>0 );
197531 if( new_elem==0 ) return data;
197532 if( pH->copyKey && pKey!=0 ){
197534 if( new_elem->pKey==0 ){
197544 assert( pH->htsize>0 );
197545 assert( (pH->htsize & (pH->htsize-1))==0 );
197549 return 0;
197625 memset(t, 0, sizeof(*t));
197640 ** string to be tokenized is zInput[0..nInput-1]. A cursor
197657 if( zInput==0 ){
197658 c->nInput = 0;
197659 }else if( nInput<0 ){
197664 c->iOffset = 0; /* start tokenizing at the beginning */
197665 c->iToken = 0;
197667 c->nAllocated = 0;
197687 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0,
197708 if( x==0 ) return 0;
197712 return z[1]==0 || isVowel(z + 1);
197717 if( x==0 ) return 0;
197745 if( *z==0 ) return 0;
197747 return *z!=0;
197755 if( *z==0 ) return 0;
197757 if( *z==0 ) return 0;
197759 if( *z==0 ) return 1;
197761 return *z==0;
197765 ** or m>0
197769 if( *z==0 ) return 0;
197771 if( *z==0 ) return 0;
197773 if( *z==0 ) return 0;
197775 return *z!=0;
197779 ** Return TRUE if there is a vowel anywhere within z[0..n-1]
197783 return *z!=0;
197793 return isConsonant(z) && z[0]==z[1];
197807 z[0]!='w' && z[0]!='x' && z[0]!='y' &&
197832 if( *zFrom!=0 ) return 0;
197851 int hasDigit = 0;
197852 for(i=0; i<nIn; i++){
197857 if( c>='0' && c<='9' ) hasDigit = 1;
197868 zOut[i] = 0;
197874 ** Stem the input word zIn[0..nIn-1]. Store the output in zOut.
197876 ** size of the output word (exclusive of the '\0' terminator) into *pnOut.
197906 for(i=0, j=sizeof(zReverse)-6; i<nIn; i++, j--){
197919 memset(&zReverse[sizeof(zReverse)-5], 0, 5);
197924 if( z[0]=='s' ){
197926 !stem(&z, "sess", "ss", 0) &&
197927 !stem(&z, "sei", "i", 0) &&
197928 !stem(&z, "ss", "ss", 0)
197942 if( stem(&z, "ta", "ate", 0) ||
197943 stem(&z, "lb", "ble", 0) ||
197944 stem(&z, "zi", "ize", 0) ){
197954 if( z[0]=='y' && hasVowel(z+1) ){
197955 z[0] = 'i';
198010 switch( z[0] ){
198034 if( z[0]=='l' && m_gt_1(z+2) ){
198039 if( z[0]=='e' && z[2]=='n' && (z[3]=='a' || z[3]=='e') && m_gt_1(z+4) ){
198044 if( z[0]=='r' && m_gt_1(z+2) ){
198049 if( z[0]=='c' && m_gt_1(z+2) ){
198054 if( z[0]=='e' && z[2]=='b' && (z[3]=='a' || z[3]=='i') && m_gt_1(z+4) ){
198059 if( z[0]=='t' ){
198074 if( z[0]=='u' ){
198083 if( z[0]=='m' && z[2]=='i' && m_gt_1(z+3) ){
198093 if( z[0]=='s' && z[2]=='o' && m_gt_1(z+3) ){
198099 if( z[0]=='e' && z[2]=='i' && m_gt_1(z+3) ){
198106 if( z[0]=='e' ){
198115 if( m_gt_1(z) && z[0]=='l' && z[1]=='l' ){
198123 zOut[i] = 0;
198131 ** whose value is greater than 0x80 (any UTF character) can be
198133 ** values of 0x7f or lower.
198137 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
198138 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
198139 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */
198140 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
198141 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
198143 #define isDelim(C) (((ch=C)&0x80)==0 && (ch<0x30 || !porterIdChar[ch-0x30]))
198198 0,
198204 0
198255 ** SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, 1, 0);
198259 int isEnabled = 0;
198290 void *pPtr = 0;
198298 zName = sqlite3_value_text(argv[0]);
198299 nName = sqlite3_value_bytes(argv[0])+1;
198305 if( zName==0 || n!=sizeof(pPtr) ){
198329 if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[0]) ){
198336 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
198337 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
198338 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
198339 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
198340 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
198341 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */
198342 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
198343 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
198345 return (c&0x80 || isFtsIdChar[(int)(c)]);
198350 const char *z2 = 0;
198354 while( z2==0 ){
198357 case '\0': return 0; /* No more tokens here */
198367 while( *z2 && z2[0]!=']' ) z2++;
198393 int n = 0;
198403 if( z==0 ){
198404 assert( n==0 );
198407 z[n] = '\0';
198415 char const **aArg = 0;
198416 int iArg = 0;
198428 z[n] = '\0';
198474 ** "{0 i I 1 dont don't 2 see see 3 how how}"
198484 sqlite3_tokenizer *pTokenizer = 0;
198485 sqlite3_tokenizer_cursor *pCsr = 0;
198487 const char *zErr = 0;
198497 int nToken = 0;
198498 int iStart = 0;
198499 int iEnd = 0;
198500 int iPos = 0;
198510 nName = sqlite3_value_bytes(argv[0]);
198511 zName = (const char *)sqlite3_value_text(argv[0]);
198537 if( sqlite3Fts3OpenTokenizer(pTokenizer, 0, zInput, nInput, &pCsr) ){
198543 Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(iPos));
198544 Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zToken, nToken));
198547 Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zToken, nToken));
198578 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
198601 *pp = 0;
198602 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
198609 if( sqlite3_column_type(pStmt, 0)==SQLITE_BLOB
198610 && sqlite3_column_bytes(pStmt, 0)==sizeof(*pp)
198612 memcpy((void *)pp, sqlite3_column_blob(pStmt, 0), sizeof(*pp));
198659 assert( p2==0 );
198660 assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") );
198703 char *zTest = 0;
198704 char *zTest2 = 0;
198714 rc = sqlite3_create_function(db, zName, 1, any, p, fts3TokenizerFunc, 0, 0);
198717 rc = sqlite3_create_function(db, zName, 2, any, p, fts3TokenizerFunc, 0, 0);
198721 rc = sqlite3_create_function(db, zTest, -1, any, p, testFunc, 0, 0);
198724 rc = sqlite3_create_function(db, zTest2, 0, any, pdb, intTestFunc, 0, 0);
198791 return c<0x80 && t->delim[c];
198794 return (x>='0' && x<='9') || (x>='A' && x<='Z') || (x>='a' && x<='z');
198808 memset(t, 0, sizeof(*t));
198817 for(i=0; i<n; i++){
198820 if( ch>=0x80 ){
198829 for(i=1; i<0x80; i++){
198830 t->delim[i] = !fts3_isalnum(i) ? -1 : 0;
198848 ** string to be tokenized is pInput[0..nBytes-1]. A cursor
198865 if( pInput==0 ){
198866 c->nBytes = 0;
198867 }else if( nBytes<0 ){
198872 c->iOffset = 0; /* start tokenizing at the beginning */
198873 c->iToken = 0;
198875 c->nTokenAllocated = 0;
198931 for(i=0; i<n; i++){
198954 0,
198960 0,
199090 if( argc==0 ){
199091 *pazDequote = 0;
199094 int nByte = 0;
199097 for(i=0; i<argc; i++){
199102 if( azDequote==0 ){
199106 for(i=0; i<argc; i++){
199129 ** argv[0]: module name
199142 Fts3tokTable *pTab = 0;
199143 const sqlite3_tokenizer_module *pMod = 0;
199144 sqlite3_tokenizer *pTok = 0;
199146 char **azDequote = 0;
199160 zModule = azDequote[0];
199165 assert( (rc==SQLITE_OK)==(pMod!=0) );
199167 const char * const *azArg = 0;
199169 rc = pMod->xCreate((nDequote>1 ? nDequote-1 : 0), azArg, &pTok);
199174 if( pTab==0 ){
199180 memset(pTab, 0, sizeof(Fts3tokTable));
199217 for(i=0; i<pInfo->nConstraint; i++){
199219 && pInfo->aConstraint[i].iColumn==0
199230 pInfo->idxNum = 0;
199244 if( pCsr==0 ){
199247 memset(pCsr, 0, sizeof(Fts3tokCursor));
199261 pCsr->pCsr = 0;
199264 pCsr->zInput = 0;
199265 pCsr->zToken = 0;
199266 pCsr->nToken = 0;
199267 pCsr->iStart = 0;
199268 pCsr->iEnd = 0;
199269 pCsr->iPos = 0;
199270 pCsr->iRowid = 0;
199324 const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
199325 sqlite3_int64 nByte = sqlite3_value_bytes(apVal[0]);
199327 if( pCsr->zInput==0 ){
199330 if( nByte>0 ) memcpy(pCsr->zInput, zByte, nByte);
199331 pCsr->zInput[nByte] = 0;
199348 return (pCsr->zToken==0);
199363 case 0:
199401 0, /* iVersion */
199414 0, /* xUpdate */
199415 0, /* xBegin */
199416 0, /* xSync */
199417 0, /* xCommit */
199418 0, /* xRollback */
199419 0, /* xFindFunction */
199420 0, /* xRename */
199421 0, /* xSavepoint */
199422 0, /* xRelease */
199423 0, /* xRollbackTo */
199424 0, /* xShadowName */
199425 0 /* xIntegrity */
199511 #define FTS_STAT_DOCTOTAL 0
199576 int iIdx; /* Index within level, or 0x7FFFFFFF for PT */
199582 sqlite3_int64 iEndBlock; /* Rowid of final block in segment (or 0) */
199583 sqlite3_int64 iCurrentBlock; /* Current leaf block (or 0) */
199586 int nNode; /* Size of buffer at aNode (or 0) */
199587 int nPopulate; /* If >0, bytes of buffer aNode[] loaded */
199611 #define fts3SegReaderIsPending(p) ((p)->ppNextElem!=0)
199612 #define fts3SegReaderIsRootOnly(p) ((p)->rootOnly!=0)
199671 #define SQL_DELETE_CONTENT 0
199718 ** Otherwise, an SQLite error code is returned and *pp is set to 0.
199732 /* 0 */ "DELETE FROM %Q.'%q_content' WHERE rowid = ?",
199835 assert( eStmt<SizeofArray(azSql) && eStmt>=0 );
199854 assert( rc==SQLITE_OK || pStmt==0 );
199861 for(i=0; rc==SQLITE_OK && i<nParam; i++){
199875 sqlite3_stmt *pStmt = 0; /* Statement requested from fts3SqlStmt() */
199878 rc = fts3SqlStmt(pTab, SQL_SELECT_DOCSIZE, &pStmt, 0);
199882 if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){
199885 pStmt = 0;
199899 sqlite3_stmt *pStmt = 0;
199901 rc = fts3SqlStmt(pTab, SQL_SELECT_STAT, &pStmt, 0);
199905 || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB
199909 pStmt = 0;
199967 if( p->nPendingData==0 ){
199969 rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_LEVEL, &pStmt, 0);
199995 ** for language-id 0 is allocate values 0-1023. The first prefix index
199996 ** (if any) for language-id 0 is allocated values 1024-2047. And so on.
199997 ** Language 1 indexes are allocated immediately following language 0.
200010 assert_fts3_nc( iLangid>=0 );
200011 assert( p->nIndex>0 );
200012 assert( iIndex>=0 && iIndex<p->nIndex );
200029 ** 0: idx
200043 sqlite3_stmt *pStmt = 0;
200045 assert( iLevel==FTS3_SEGCURSOR_ALL || iLevel>=0 );
200047 assert( iIndex>=0 && iIndex<p->nIndex );
200049 if( iLevel<0 ){
200051 rc = fts3SqlStmt(p, SQL_SELECT_LEVEL_RANGE, &pStmt, 0);
200053 sqlite3_bind_int64(pStmt, 1, getAbsoluteLevel(p, iLangid, iIndex, 0));
200060 rc = fts3SqlStmt(p, SQL_SELECT_LEVEL, &pStmt, 0);
200078 ** PendingList *p = 0;
200096 p->nData = 0;
200103 *pp = 0;
200112 p->aData[p->nData] = '\0';
200139 u64 iDelta = (u64)iDocid - (u64)(p ? p->iLastDocid : 0);
200142 assert( p->aData[p->nData]==0 );
200149 p->iLastPos = 0;
200152 if( iCol>0 && p->iLastCol!=iCol ){
200159 p->iLastPos = 0;
200161 if( iCol>=0 ){
200162 assert( iPos>p->iLastPos || (iPos==0 && p->iLastPos==0) );
200175 return 0;
200208 assert( 0==fts3HashFind(pHash, zToken, nToken) );
200234 int iStart = 0;
200235 int iEnd = 0;
200236 int iPos = 0;
200237 int nWord = 0;
200240 int nToken = 0;
200251 ** zText==0. In this case, add zero token entries to the hash table and
200253 if( zText==0 ){
200254 *pnWord = 0;
200273 if( iPos<0 || !zToken || nToken<=0 ){
200280 p, iCol, iPos, &p->aIndex[0].hPending, zToken, nToken
200310 assert( iLangid>=0 );
200311 assert( bDelete==1 || bDelete==0 );
200320 || (iDocid==p->iPrevDocid && p->bPrevDelete==0)
200338 for(i=0; i<p->nIndex; i++){
200347 p->nPendingData = 0;
200367 if( p->abNotindexed[iCol]==0 ){
200384 ** apVal[0] Not used for INSERT.
200441 if( SQLITE_NULL==sqlite3_value_type(apVal[0])
200475 assert( p->zContentTbl==0 || bContent==0 );
200476 if( bContent ) fts3SqlExec(&rc, p, SQL_DELETE_ALL_CONTENT, 0);
200477 fts3SqlExec(&rc, p, SQL_DELETE_ALL_SEGMENTS, 0);
200478 fts3SqlExec(&rc, p, SQL_DELETE_ALL_SEGDIR, 0);
200480 fts3SqlExec(&rc, p, SQL_DELETE_ALL_DOCSIZE, 0);
200483 fts3SqlExec(&rc, p, SQL_DELETE_ALL_STAT, 0);
200492 int iLangid = 0;
200512 assert( *pbFound==0 );
200519 i64 iDocid = sqlite3_column_int64(pSelect, 0);
200523 if( p->abNotindexed[iCol]==0 ){
200552 ** with 0, so the allocated index is one greater than the value returned
200559 ** allocated index is 0.
200573 int iNext = 0; /* Result of query pNextIdx */
200575 assert( iLangid>=0 );
200579 rc = fts3SqlStmt(p, SQL_NEXT_SEGMENT_INDEX, &pNextIdx, 0);
200585 iNext = sqlite3_column_int(pNextIdx, 0);
200593 ** segment and allocate (newly freed) index 0 at level iLevel. Otherwise,
200599 *piIdx = 0;
200650 if( 0==p->zSegmentsTbl ){
200652 if( 0==p->zSegmentsTbl ) return SQLITE_NOMEM;
200655 p->db, p->zDb, p->zSegmentsTbl, "block", iBlockid, 0, &p->pSegments
200671 rc = sqlite3_blob_read(p->pSegments, aByte, nByte, 0);
200672 memset(&aByte[nByte], 0, FTS3_NODE_PADDING);
200675 aByte = 0;
200693 p->pSegments = 0;
200710 memset(&pReader->aNode[pReader->nPopulate], 0, FTS3_NODE_PADDING);
200713 pReader->pBlob = 0;
200714 pReader->nPopulate = 0;
200740 pSeg->pBlob = 0;
200742 pSeg->aNode = 0;
200771 pReader->aNode = 0;
200785 pReader->zTerm[nTerm] = '\0';
200812 (bIncr ? &pReader->nPopulate : 0)
200815 assert( pReader->pBlob==0 );
200818 p->pSegments = 0;
200832 if( nSuffix<=0
200840 ** between 0 and 0x7FFFFFFF. But the sum of the two may cause integer
200860 pReader->pOffsetList = 0;
200863 ** b-tree node. And that the final byte of the doclist is 0x00. If either
200867 || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1])
200868 || pReader->nDoclist==0
200884 u8 bEof = 0;
200885 pReader->iDocid = 0;
200886 pReader->nOffsetList = 0;
200887 sqlite3Fts3DoclistPrev(0,
200919 char c = 0;
200927 u8 bEof = 0;
200932 sqlite3Fts3DoclistPrev(0,
200937 pReader->pOffsetList = 0;
200955 while( *p | c ) c = *p++ & 0x80;
200956 assert( *p==0 );
200958 if( pReader->pBlob==0 || p<&pReader->aNode[pReader->nPopulate] ) break;
200973 while( p<pEnd && *p==0 ) p++;
200981 pReader->pOffsetList = 0;
201006 int nOvfl = 0;
201012 assert( pgsz>0 );
201014 for(ii=0; rc==SQLITE_OK && ii<pMsr->nSegment; ii++){
201022 rc = sqlite3Fts3ReadBlock(p, jj, 0, &nBlob, 0);
201063 int nExtra = 0; /* Bytes to allocate segment root node */
201065 assert( zRoot!=0 || nRoot==0 );
201067 assert( zRoot!=0 || CORRUPT_DB );
201070 if( iStartLeaf==0 ){
201071 if( iEndLeaf!=0 ) return FTS_CORRUPT_VTAB;
201079 memset(pReader, 0, sizeof(Fts3SegReader));
201081 pReader->bLookup = bLookup!=0;
201092 memset(&pReader->aNode[nRoot], 0, FTS3_NODE_PADDING);
201116 if( c==0 ){
201149 Fts3SegReader *pReader = 0; /* Fts3SegReader object to return */
201151 Fts3HashElem **aElem = 0; /* Array of term hash entries to scan */
201152 int nElem = 0; /* Size of array at aElem */
201158 int nAlloc = 0; /* Size of allocated array at aElem */
201163 if( nTerm==0 || (nKey>=nTerm && 0==memcmp(zKey, zTerm, nTerm)) ){
201172 nElem = 0;
201205 if( nElem>0 ){
201212 memset(pReader, 0, nByte);
201213 pReader->iIdx = 0x7FFFFFFF;
201242 if( rc2<0 ){
201247 if( rc==0 ){
201251 rc = (pLhs->aNode==0) - (pRhs->aNode==0);
201253 if( rc==0 ){
201256 assert_fts3_nc( rc!=0 );
201272 int rc = (pLhs->pOffsetList==0)-(pRhs->pOffsetList==0);
201273 if( rc==0 ){
201284 int rc = (pLhs->pOffsetList==0)-(pRhs->pOffsetList==0);
201285 if( rc==0 ){
201300 ** If the pSeg iterator is already at EOF, return 0. Otherwise, return
201301 ** -ve if the pSeg term is less than zTerm/nTerm, 0 if the two terms are
201309 int res = 0;
201316 if( res==0 ){
201340 for(i=nSuspect-1; i>=0; i--){
201344 if( xCmp(apSegment[j], apSegment[j+1])<0 ) break;
201353 for(i=0; i<(nSuspect-1); i++){
201354 assert( xCmp(apSegment[i], apSegment[i+1])<0 );
201369 int rc = fts3SqlStmt(p, SQL_INSERT_SEGMENTS, &pStmt, 0);
201387 int mxLevel = 0;
201388 sqlite3_stmt *pStmt = 0;
201390 rc = fts3SqlStmt(p, SQL_SELECT_MXLEVEL, &pStmt, 0);
201393 mxLevel = sqlite3_column_int(pStmt, 0);
201416 int rc = fts3SqlStmt(p, SQL_INSERT_SEGDIR, &pStmt, 0);
201422 if( nLeafData==0 ){
201443 ** fts3PrefixCompress("abX", 3, "Xbcdef", 6) // returns 0
201452 for(n=0; n<nPrev && n<nNext && zPrev[n]==zNext[n]; n++);
201487 if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
201549 memset(pNew, 0, sizeof(SegmentNode));
201556 if( pTree->pParent==0 ){
201564 pTree->zMalloc = 0;
201656 assert( pRight==0 || p->zMalloc==0 );
201694 memset(pWriter, 0, sizeof(SegmentWriter));
201703 rc = fts3SqlStmt(p, SQL_NEXT_SEGMENTS_ID, &pStmt, 0);
201706 pWriter->iFree = sqlite3_column_int64(pStmt, 0);
201720 if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
201729 if( nData>0 && nData+nReq>p->nNodeSize ){
201754 nData = 0;
201755 pWriter->nTerm = 0;
201757 nPrefix = 0;
201783 assert( nSuffix>0 );
201787 assert( nDoclist>0 );
201807 assert( nTerm>0 );
201831 sqlite3_int64 iLast = 0; /* Largest block id written to database */
201834 int nRoot = 0; /* Size of buffer zRoot */
201849 0, 0, 0, pWriter->nLeafData, pWriter->aData, pWriter->nData);
201883 *pisEmpty = 0;
201889 *pisEmpty = sqlite3_column_int(pStmt, 0);
201913 assert( iIndex>=0 && iIndex<p->nIndex );
201921 rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR_MAX_LEVEL, &pStmt, 0);
201923 sqlite3_bind_int64(pStmt, 1, getAbsoluteLevel(p, iLangid, iIndex, 0));
201928 *pnMax = sqlite3_column_int64(pStmt, 0);
201937 ** iAbsLevel is indeed the largest level, or 0 otherwise, and SQLITE_OK
201950 int rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR_MAX_LEVEL, &pStmt, 0);
201957 *pbMax = 0;
201959 *pbMax = sqlite3_column_type(pStmt, 0)==SQLITE_NULL;
201976 rc = fts3SqlStmt(p, SQL_DELETE_SEGMENTS_RANGE, &pDelete, 0);
201997 ** entries regardless of level if (iLevel<0).
202011 sqlite3_stmt *pDelete = 0; /* SQL statement to delete rows */
202013 for(i=0; rc==SQLITE_OK && i<nReader; i++){
202020 assert( iLevel>=0 || iLevel==FTS3_SEGCURSOR_ALL );
202022 rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_RANGE, &pDelete, 0);
202024 sqlite3_bind_int64(pDelete, 1, getAbsoluteLevel(p, iLangid, iIndex, 0));
202030 rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_LEVEL, &pDelete, 0);
202067 int iCurrent = 0;
202070 assert( iCol>=0 );
202072 char c = 0;
202073 while( p<pEnd && (c | *p)&0xFE ) c = *p++ & 0x80;
202082 if( nList<=0 ){
202089 if( bZero && (pEnd - &pList[nList])>0){
202090 memset(&pList[nList], 0, pEnd - &pList[nList]);
202117 assert( nList>0 );
202119 memset(&pMsr->aBuffer[nList], 0, FTS3_NODE_PADDING);
202136 if( nMerge==0 ){
202137 *paPoslist = 0;
202143 pSeg = pMsr->apSegment[0];
202145 if( pSeg->pOffsetList==0 ){
202146 *paPoslist = 0;
202153 sqlite3_int64 iDocid = apSegment[0]->iDocid;
202155 rc = fts3SegReaderNextDocid(p, apSegment[0], &pList, &nList);
202162 rc = fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
202168 if( nList>0 && fts3SegReaderIsPending(apSegment[0]) ){
202171 assert( (pMsr->aBuffer[nList] & 0xFE)==0x00 );
202175 if( pMsr->iColFilter>=0 ){
202179 if( nList>0 ){
202206 for(i=0; pCsr->bRestart==0 && i<pCsr->nSegment; i++){
202207 int res = 0;
202210 int rc = fts3SegReaderNext(p, pSeg, 0);
202212 }while( zTerm && (res = fts3SegReaderTermCmp(pSeg, zTerm, nTerm))<0 );
202214 if( pSeg->bLookup && res!=0 ){
202246 assert( pCsr->pFilter==0 );
202247 assert( zTerm && nTerm>0 );
202254 for(i=0; i<nSegment; i++){
202263 for(i=0; i<pCsr->nAdvance; i++){
202269 assert( iCol<0 || iCol<p->nColumn );
202290 assert( pCsr->zTerm==0 );
202291 assert( pCsr->nTerm==0 );
202292 assert( pCsr->aDoclist==0 );
202293 assert( pCsr->nDoclist==0 );
202295 pCsr->nAdvance = 0;
202297 for(i=0; i<pCsr->nSegment; i++){
202298 pCsr->apSegment[i]->pOffsetList = 0;
202299 pCsr->apSegment[i]->nOffsetList = 0;
202300 pCsr->apSegment[i]->iDocid = 0;
202340 if( pCsr->nSegment==0 ) return SQLITE_OK;
202349 for(i=0; i<pCsr->nAdvance; i++){
202354 rc = fts3SegReaderNext(p, pSeg, 0);
202359 pCsr->nAdvance = 0;
202363 if( apSegment[0]->aNode==0 ) break;
202365 pCsr->nTerm = apSegment[0]->nTerm;
202366 pCsr->zTerm = apSegment[0]->zTerm;
202368 /* If this is a prefix-search, and if the term that apSegment[0] points
202373 ** of segment apSegment[0] is not a match, exit early.
202388 && 0==memcmp(pCsr->zTerm, apSegment[nMerge]->zTerm, pCsr->nTerm)
202397 && (p->bDescIdx==0 || fts3SegReaderIsPending(apSegment[0])==0)
202399 pCsr->nDoclist = apSegment[0]->nDoclist;
202400 if( fts3SegReaderIsPending(apSegment[0]) ){
202401 rc = fts3MsrBufferData(pCsr, apSegment[0]->aDoclist,
202405 pCsr->aDoclist = apSegment[0]->aDoclist;
202409 int nDoclist = 0; /* Size of doclist */
202410 sqlite3_int64 iPrev = 0; /* Previous docid stored in doclist */
202416 for(i=0; i<nMerge; i++){
202420 while( apSegment[0]->pOffsetList ){
202422 char *pList = 0;
202423 int nList = 0;
202425 sqlite3_int64 iDocid = apSegment[0]->iDocid;
202426 fts3SegReaderNextDocid(p, apSegment[0], &pList, &nList);
202432 fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
202437 fts3ColumnFilter(pFilter->iCol, 0, &pList, &nList);
202440 if( !isIgnoreEmpty || nList>0 ){
202445 if( p->bDescIdx && nDoclist>0 ){
202449 if( nDoclist>0 && iPrev>=iDocid ) return FTS_CORRUPT_VTAB;
202453 nByte = sqlite3Fts3VarintLen(iDelta) + (isRequirePos?nList+1:0);
202474 pCsr->aBuffer[nDoclist++] = '\0';
202481 if( nDoclist>0 ){
202484 memset(&pCsr->aBuffer[nDoclist], 0, FTS3_NODE_PADDING);
202502 for(i=0; i<pCsr->nSegment; i++){
202508 pCsr->nSegment = 0;
202509 pCsr->apSegment = 0;
202510 pCsr->aBuffer = 0;
202520 ** by one or more space (0x20) characters. In the first case, set *piEndBlock
202534 u64 iVal = 0;
202535 for(i=0; zText[i]>='0' && zText[i]<='9'; i++){
202536 iVal = iVal*10 + (zText[i] - '0');
202540 iVal = 0;
202545 for(/* no-op */; zText[i]>='0' && zText[i]<='9'; i++){
202546 iVal = iVal*10 + (zText[i] - '0');
202565 rc = fts3SqlStmt(p, SQL_SELECT_LEVEL_RANGE2, &pRange, 0);
202568 int bOk = 0;
202580 i64 nSize = 0, dummy;
202582 if( nSize<=0 || nSize>nLimit ){
202583 /* If nSize==0, then the %_segdir.end_block field does not not
202588 bOk = 0;
202596 int iIdx = 0;
202597 sqlite3_stmt *pUpdate1 = 0;
202598 sqlite3_stmt *pUpdate2 = 0;
202601 rc = fts3SqlStmt(p, SQL_UPDATE_LEVEL_IDX, &pUpdate1, 0);
202604 rc = fts3SqlStmt(p, SQL_UPDATE_LEVEL, &pUpdate2, 0);
202611 ** updated it to set (level = -1) and (idx = N), where N is 0 for the
202621 sqlite3_bind_int(pUpdate1, 2, sqlite3_column_int(pRange, 0));
202650 ** iLevel+1 segment. Or, if iLevel<0, merge all segments into a
202654 ** If this function is called with iLevel<0, but there is only one
202666 int iIdx = 0; /* Index of new segment */
202667 sqlite3_int64 iNewLevel = 0; /* Level/index to create new segment at */
202668 SegmentWriter *pWriter = 0; /* Used to write the new, merged, segment */
202671 int bIgnoreEmpty = 0; /* True to ignore empty segments */
202672 i64 iMaxLevel = 0; /* Max level number for this index/langid */
202676 || iLevel>=0
202679 assert( iIndex>=0 && iIndex<p->nIndex );
202681 rc = sqlite3Fts3SegReaderCursor(p, iLangid, iIndex, iLevel, 0, 0, 1, 0, &csr);
202682 if( rc!=SQLITE_OK || csr.nSegment==0 ) goto finished;
202693 ** index. The idx of the new segment is always 0. */
202694 if( csr.nSegment==1 && 0==fts3SegReaderIsPending(csr.apSegment[0]) ){
202713 assert( csr.nSegment>0 );
202714 assert_fts3_nc( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
202719 memset(&filter, 0, sizeof(Fts3SegFilter));
202721 filter.flags |= (bIgnoreEmpty ? FTS3_SEGMENT_IGNORE_EMPTY : 0);
202756 ** Flush the contents of pendingTerms to level 0 segments.
202762 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
202771 && p->nAutoincrmerge==0xff && p->nLeafAdd>0
202773 sqlite3_stmt *pStmt = 0;
202774 rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pStmt, 0);
202779 p->nAutoincrmerge = sqlite3_column_int(pStmt, 0);
202782 p->nAutoincrmerge = 0;
202804 for(i=j=0; i<N; i++){
202819 int i = 0;
202820 if( nBuf && (zBuf[nBuf-1]&0x80)==0 ){
202822 for(i=j=0; i<N && j<nBuf; i++){
202825 a[i] = (u32)(x & 0xffffffff);
202828 while( i<N ) a[i++] = 0;
202848 if( pBlob==0 ){
202853 rc = fts3SqlStmt(p, SQL_REPLACE_DOCSIZE, &pStmt, 0);
202866 ** Record 0 of the %_stat table contains a blob consisting of N varints,
202871 ** Varint 0: Total number of rows in the table.
202898 if( a==0 ){
202903 rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pStmt, 0);
202912 sqlite3_column_blob(pStmt, 0),
202913 sqlite3_column_bytes(pStmt, 0));
202915 memset(a, 0, sizeof(u32)*(nStat) );
202923 if( nChng<0 && a[0]<(u32)(-nChng) ){
202924 a[0] = 0;
202926 a[0] += nChng;
202928 for(i=0; i<p->nColumn+1; i++){
202931 x = 0;
202938 rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0);
202957 int bSeenDone = 0;
202959 sqlite3_stmt *pAllLangid = 0;
202963 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
202971 int iLangid = sqlite3_column_int(pAllLangid, 0);
202972 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
203002 rc = fts3DeleteAll(p, 0);
203004 u32 *aSz = 0;
203005 u32 *aSzIns = 0;
203006 u32 *aSzDel = 0;
203007 sqlite3_stmt *pStmt = 0;
203008 int nEntry = 0;
203015 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
203022 if( aSz==0 ){
203025 memset(aSz, 0, nByte);
203034 rc = fts3PendingTermsDocid(p, 0, iLangid, sqlite3_column_int64(pStmt, 0));
203035 memset(aSz, 0, sizeof(aSz[0]) * (p->nColumn+1));
203036 for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
203037 if( p->abNotindexed[iCol]==0 ){
203048 pStmt = 0;
203051 for(iCol=0; iCol<=p->nColumn; iCol++){
203076 ** the oldest nSeg segments (idx=0 through idx=(nSeg-1)) in absolute
203086 sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */
203090 memset(pCsr, 0, sizeof(*pCsr));
203094 if( pCsr->apSegment==0 ){
203097 memset(pCsr->apSegment, 0, nByte);
203098 rc = fts3SqlStmt(p, SQL_SELECT_LEVEL, &pStmt, 0);
203104 assert( pCsr->nSegment==0 );
203105 for(i=0; rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW && i<nSeg; i++){
203106 rc = sqlite3Fts3SegReaderNew(i, 0,
203162 u8 bNoLeafData; /* If true, store 0 for segment size */
203219 int bFirst = (p->term.n==0); /* True for first term on the node */
203220 int nPrefix = 0; /* Bytes to copy from previous term */
203221 int nSuffix = 0; /* Bytes to append to the prefix */
203225 if( p->iChild && bFirst==0 ) p->iChild++;
203228 p->aNode = 0;
203230 if( bFirst==0 ){
203235 if( nPrefix>p->term.n || nSuffix>p->nNode-p->iOff || nSuffix==0 ){
203239 if( rc==SQLITE_OK && ALWAYS(p->term.a!=0) ){
203243 if( p->iChild==0 ){
203273 memset(p, 0, sizeof(NodeReader));
203278 if( aNode && aNode[0] ){
203296 ** (pWriter->aNodeWriter[0].iBlock) when this function is called.
203304 sqlite3_int64 iPtr = pWriter->aNodeWriter[0].iBlock;
203307 assert( nTerm>0 );
203309 sqlite3_int64 iNextPtr = 0;
203322 if(nSuffix<=0 ) return FTS_CORRUPT_VTAB;
203326 if( pNode->key.n==0 || (pNode->block.n + nSpace)<=p->nNodeSize ){
203332 if( pBlk->n==0 ){
203335 pBlk->a[0] = (char)iLayer;
203348 assert( nPrefix>=0 );
203362 pNode->block.a[0] = (char)iLayer;
203367 pNode->key.n = 0;
203370 if( rc!=SQLITE_OK || iNextPtr==0 ) return rc;
203374 assert( 0 );
203375 return 0;
203383 ** A node header is a single 0x00 byte for a leaf node, or a height varint
203388 ** node, both aDoclist and nDoclist must be passed 0.
203411 int bFirst = (pPrev->n==0); /* True if this is the first term written */
203417 assert( pNode->n>0 );
203418 assert_fts3_nc( (pNode->a[0]=='\0')==(aDoclist!=0) );
203422 assert( pPrev!=0 );
203423 assert( pPrev->a!=0 );
203427 if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
203431 if( bFirst==0 ){
203470 pLeaf = &pWriter->aNodeWriter[0];
203473 if(nSuffix<=0 ) return FTS_CORRUPT_VTAB;
203483 if( pLeaf->block.n>0
203508 pLeaf->key.n = 0;
203509 pLeaf->block.n = 0;
203520 if( pLeaf->block.n==0 ){
203522 pLeaf->block.a[0] = '\0';
203557 ** will be set to 0. If the root node is the parent of the leaves, iRoot
203559 for(iRoot=FTS_MAX_APPENDABLE_HEIGHT-1; iRoot>=0; iRoot--){
203561 if( pNode->block.n>0 ) break;
203562 assert( *pRc || pNode->block.nAlloc==0 );
203563 assert( *pRc || pNode->key.nAlloc==0 );
203569 if( iRoot<0 ) return;
203577 ** segments that fit entirely on the root node with start_block!=0.
203586 if( iRoot==0 ){
203590 pBlock->a[0] = 0x01;
203592 &pBlock->a[1], pWriter->aNodeWriter[0].iBlock
203600 for(i=0; i<iRoot; i++){
203602 if( pNode->block.n>0 && rc==SQLITE_OK ){
203615 pWriter->aNodeWriter[0].iBlock, /* leaves_end_block */
203617 (pWriter->bNoLeafData==0 ? pWriter->nLeafData : 0), /* end_block */
203632 ** Return -ve if zLhs is smaller than zRhs, 0 if it is equal, or +ve
203645 res = 0;
203647 if( res==0 ) res = nLhs - nRhs;
203656 ** returning. Otherwise, set *pbRes to 0.
203666 int bRes = 0; /* Result to set *pbRes to */
203667 sqlite3_stmt *pCheck = 0; /* Statement to query database with */
203670 rc = fts3SqlStmt(p, SQL_SEGMENT_IS_APPENDABLE, &pCheck, 0);
203705 sqlite3_stmt *pSelect = 0; /* SELECT to read %_segdir entry */
203707 rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR, &pSelect, 0);
203709 sqlite3_int64 iStart = 0; /* Value of %_segdir.start_block */
203710 sqlite3_int64 iLeafEnd = 0; /* Value of %_segdir.leaves_end_block */
203711 sqlite3_int64 iEnd = 0; /* Value of %_segdir.end_block */
203712 const char *aRoot = 0; /* Pointer to %_segdir.root buffer */
203713 int nRoot = 0; /* Size of aRoot[] in bytes */
203715 int bAppendable = 0; /* Set to true if segment is appendable */
203724 if( pWriter->nLeafData<0 ){
203727 pWriter->bNoLeafData = (pWriter->nLeafData==0);
203730 if( aRoot==0 ){
203743 char *aLeaf = 0;
203744 int nLeaf = 0;
203746 rc = sqlite3Fts3ReadBlock(p, iLeafEnd, &aLeaf, &nLeaf, 0);
203755 if( fts3TermCmp(zKey, nKey, reader.term.a, reader.term.n)<=0 ){
203756 bAppendable = 0;
203767 int nHeight = (int)aRoot[0];
203792 memset(&pNode->block.a[nRoot], 0, FTS3_NODE_PADDING);
203795 for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){
203797 memset(&reader, 0, sizeof(reader));
203805 assert_fts3_nc( reader.term.n>0 || reader.aNode==0 );
203806 if( reader.term.n>0 ){
203810 if( i>0 ){
203811 char *aBlock = 0;
203812 int nBlock = 0;
203815 rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock,0);
203822 memset(&pNode->block.a[nBlock], 0, FTS3_NODE_PADDING);
203854 sqlite3_stmt *pOutputIdx = 0; /* SQL used to find output index */
203856 rc = fts3SqlStmt(p, SQL_NEXT_SEGMENT_INDEX, &pOutputIdx, 0);
203860 *piIdx = sqlite3_column_int(pOutputIdx, 0);
203902 int nLeafEst = 0; /* Blocks allocated for leaf nodes */
203903 sqlite3_stmt *pLeafEst = 0; /* SQL used to determine nLeafEst */
203904 sqlite3_stmt *pFirstBlock = 0; /* SQL used to determine first block */
203907 rc = fts3SqlStmt(p, SQL_MAX_LEAF_NODE_ESTIMATE, &pLeafEst, 0);
203912 nLeafEst = sqlite3_column_int(pLeafEst, 0);
203919 rc = fts3SqlStmt(p, SQL_NEXT_SEGMENTS_ID, &pFirstBlock, 0);
203922 pWriter->iStart = sqlite3_column_int64(pFirstBlock, 0);
203933 rc = fts3WriteSegment(p, pWriter->iEnd, 0, 0);
203941 for(i=0; i<FTS_MAX_APPENDABLE_HEIGHT; i++){
203964 sqlite3_stmt *pDelete = 0; /* DELETE statement */
203966 rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_ENTRY, &pDelete, 0);
203980 ** the idx values are a contiguous sequence starting from 0.
203987 int *aIdx = 0; /* Array of remaining idx values */
203988 int nIdx = 0; /* Valid entries in aIdx[] */
203989 int nAlloc = 0; /* Allocated size of aIdx[] */
203991 sqlite3_stmt *pSelect = 0; /* Select statement to read idx values */
203992 sqlite3_stmt *pUpdate = 0; /* Update statement to modify idx values */
203994 rc = fts3SqlStmt(p, SQL_SELECT_INDEXES, &pSelect, 0);
204009 aIdx[nIdx++] = sqlite3_column_int(pSelect, 0);
204016 rc = fts3SqlStmt(p, SQL_SHIFT_SEGDIR_ENTRY, &pUpdate, 0);
204022 assert( p->bIgnoreSavepoint==0 );
204024 for(i=0; rc==SQLITE_OK && i<nIdx; i++){
204032 p->bIgnoreSavepoint = 0;
204039 pNode->a[0] = (char)iHeight;
204066 Blob prev = {0, 0, 0}; /* Previous term written to new node */
204071 bLeaf = aNode[0]=='\0';
204076 pNew->n = 0;
204083 if( pNew->n==0 ){
204085 if( res<0 || (bLeaf==0 && res==0) ) continue;
204086 fts3StartNode(pNew, (int)aNode[0], reader.iChild);
204095 if( pNew->n==0 ){
204096 fts3StartNode(pNew, (int)aNode[0], reader.iChild);
204123 Blob root = {0,0,0}; /* New root page image */
204124 Blob block = {0,0,0}; /* Buffer used for any other block */
204125 sqlite3_int64 iBlock = 0; /* Block id */
204126 sqlite3_int64 iNewStart = 0; /* New value for iStartBlock */
204127 sqlite3_int64 iOldStart = 0; /* Old value for iStartBlock */
204128 sqlite3_stmt *pFetch = 0; /* Statement used to fetch segdir */
204130 rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR, &pFetch, 0);
204146 char *aBlock = 0;
204147 int nBlock = 0;
204150 rc = sqlite3Fts3ReadBlock(p, iBlock, &aBlock, &nBlock, 0);
204162 sqlite3_stmt *pDel = 0;
204163 rc = fts3SqlStmt(p, SQL_DELETE_SEGMENTS_RANGE, &pDel, 0);
204173 sqlite3_stmt *pChomp = 0;
204174 rc = fts3SqlStmt(p, SQL_CHOMP_SEGDIR, &pChomp, 0);
204208 int nRem = 0;
204211 for(i=pCsr->nSegment-1; i>=0 && rc==SQLITE_OK; i--){
204212 Fts3SegReader *pSeg = 0;
204217 for(j=0; ALWAYS(j<pCsr->nSegment); j++){
204223 if( pSeg->aNode==0 ){
204229 *pnRem = 0;
204253 sqlite3_stmt *pReplace = 0;
204256 rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pReplace, 0);
204277 sqlite3_stmt *pSelect = 0;
204280 pHint->n = 0;
204281 rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pSelect, 0);
204286 const char *aHint = sqlite3_column_blob(pSelect, 0);
204287 int nHint = sqlite3_column_bytes(pSelect, 0);
204291 if( ALWAYS(pHint->a!=0) ) memcpy(pHint->a, aHint, nHint);
204338 if( (pHint->a[i] & 0x80) ) return FTS_CORRUPT_VTAB;
204339 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
204340 if( i==0 ) return FTS_CORRUPT_VTAB;
204342 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
204369 int nSeg = 0; /* Number of input segments */
204370 sqlite3_int64 iAbsLevel = 0; /* Absolute level number to work on */
204371 Blob hint = {0, 0, 0}; /* Hint read from %_stat table */
204372 int bDirtyHint = 0; /* True if blob 'hint' has been modified */
204382 while( rc==SQLITE_OK && nRem>0 ){
204384 sqlite3_stmt *pFindLevel = 0; /* SQL used to determine iAbsLevel */
204385 int bUseHint = 0; /* True if attempting to append */
204386 int iIdx = 0; /* Largest idx in level (iAbsLevel+1) */
204394 rc = fts3SqlStmt(p, SQL_FIND_MERGE_LEVEL, &pFindLevel, 0);
204397 iAbsLevel = sqlite3_column_int64(pFindLevel, 0);
204412 sqlite3_int64 iHintAbsLevel = 0; /* Hint level */
204413 int nHintSeg = 0; /* Hint number of segments */
204416 if( nSeg<0 || (iAbsLevel % nMod) >= (iHintAbsLevel % nMod) ){
204437 if( nSeg<=0 ) break;
204439 assert( nMod<=0x7FFFFFFF );
204440 if( iAbsLevel<0 || iAbsLevel>(nMod<<32) ){
204451 memset(pWriter, 0, nAlloc);
204456 assert( bUseHint==1 || bUseHint==0 );
204457 if( iIdx==0 || (bUseHint && iIdx==1) ){
204458 int bIgnore = 0;
204472 int bEmpty = 0;
204480 if( bUseHint && iIdx>0 ){
204490 if( bEmpty==0 ){
204502 if( nSeg!=0 ){
204509 if( nSeg!=0 ){
204513 if( nSeg==0 && pWriter->bNoLeafData==0 ){
204541 int i = 0;
204542 while( (*z)>='0' && (*z)<='9' && i<214748363 ) i = 10*i + *(z++) - '0';
204562 int nMerge = 0;
204570 if( z[0]==',' && z[1]!='\0' ){
204575 if( z[0]!='\0' || nMin<2 ){
204580 assert( p->bFts4==0 );
204596 ** where X is an integer. X==0 means to turn automerge off. X!=0 means
204604 sqlite3_stmt *pStmt = 0;
204610 assert( p->bFts4==0 );
204614 rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0);
204631 int iIndex, /* Index (0..Fts3Table.nIndex-1) */
204643 for(i=0; i<nTerm; i++) ret += (ret<<3) + zTerm[i];
204660 int iIndex, /* Index to cksum (0..p->nIndex-1) */
204666 u64 cksum = 0;
204668 if( *pRc ) return 0;
204670 memset(&filter, 0, sizeof(filter));
204671 memset(&csr, 0, sizeof(csr));
204676 p, iLangid, iIndex, FTS3_SEGCURSOR_ALL, 0, 0, 0, 1,&csr
204687 i64 iDocid = 0;
204688 i64 iCol = 0;
204689 u64 iPos = 0;
204693 u64 iVal = 0;
204696 if( iVal==0 || iVal==1 ){
204697 iCol = 0;
204698 iPos = 0;
204737 u64 cksum1 = 0; /* Checksum based on FTS index contents */
204738 u64 cksum2 = 0; /* Checksum based on %_content contents */
204739 sqlite3_stmt *pAllLangid = 0; /* Statement to return all language-ids */
204742 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
204748 int iLangid = sqlite3_column_int(pAllLangid, 0);
204750 for(i=0; i<p->nIndex; i++){
204761 sqlite3_stmt *pStmt = 0;
204768 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
204773 i64 iDocid = sqlite3_column_int64(pStmt, 0);
204777 for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
204778 if( p->abNotindexed[iCol]==0 ){
204780 sqlite3_tokenizer_cursor *pT = 0;
204785 int nToken = 0; /* Number of bytes in token */
204786 int iDum1 = 0, iDum2 = 0; /* Dummy variables */
204787 int iPos = 0; /* Position of token in zText */
204793 zToken, nToken, iLang, 0, iDocid, iCol, iPos
204815 *pbOk = 0;
204834 ** + The index number (0 for the main index, 1 for the first prefix
204857 int bOk = 0;
204859 if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB;
204878 }else if( nVal==8 && 0==sqlite3_strnicmp(zVal, "optimize", 8) ){
204879 rc = fts3DoOptimize(p, 0);
204880 }else if( nVal==7 && 0==sqlite3_strnicmp(zVal, "rebuild", 7) ){
204882 }else if( nVal==15 && 0==sqlite3_strnicmp(zVal, "integrity-check", 15) ){
204884 }else if( nVal>6 && 0==sqlite3_strnicmp(zVal, "merge=", 6) ){
204886 }else if( nVal>10 && 0==sqlite3_strnicmp(zVal, "automerge=", 10) ){
204888 }else if( nVal==5 && 0==sqlite3_strnicmp(zVal, "flush", 5) ){
204894 if( nVal>9 && 0==sqlite3_strnicmp(zVal, "nodesize=", 9) ){
204898 }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 9) ){
204902 }else if( nVal>21 && 0==sqlite3_strnicmp(zVal,"test-no-incr-doclist=",21) ){
204905 }else if( nVal>11 && 0==sqlite3_strnicmp(zVal,"mergecount=",11) ){
204907 if( v>=4 && v<=FTS3_MERGE_COUNT && (v&1)==0 ) p->nMergeCount = v;
204924 pDef->pList = 0;
204940 pCsr->pDeferred = 0;
204962 assert( pCsr->isRequireSeek==0 );
204963 iDocid = sqlite3_column_int64(pCsr->pStmt, 0);
204965 for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){
204966 if( p->abNotindexed[i]==0 ){
204968 sqlite3_tokenizer_cursor *pTC = 0;
204973 int nToken = 0; /* Number of bytes in token */
204974 int iDum1 = 0, iDum2 = 0; /* Dummy variables */
204975 int iPos = 0; /* Position of token in zText */
204981 && (pPT->bFirst==0 || iPos==0)
204983 && (0==memcmp(zToken, pPT->z, pPT->n))
204996 rc = fts3PendingListAppendVarint(&pDef->pList, 0);
205013 *ppData = 0;
205014 *pnData = 0;
205016 if( p->pList==0 ){
205044 memset(pDeferred, 0, sizeof(*pDeferred));
205050 assert( pToken->pDeferred==0 );
205069 int bFound = 0; /* True if *pRowid really is in the table */
205073 int isEmpty = 0; /* Deleting *pRowid leaves the table empty */
205081 *pnChng = 0;
205082 memset(aSzDel, 0, sizeof(u32) * (p->nColumn+1) * 2);
205085 if( p->zContentTbl==0 ){
205119 u32 *aSzIns = 0; /* Sizes of inserted documents */
205120 u32 *aSzDel = 0; /* Sizes of deleted documents */
205121 int nChng = 0; /* Net change in number of documents */
205122 int bInsertDone = 0;
205126 assert( p->bHasStat==0 || p->bHasStat==1 );
205128 assert( p->pSegments==0 );
205139 && sqlite3_value_type(apVal[0])==SQLITE_NULL
205146 if( nArg>1 && sqlite3_value_int(apVal[2 + p->nColumn + 2])<0 ){
205152 aSzDel = sqlite3_malloc64(sizeof(aSzDel[0])*((sqlite3_int64)p->nColumn+1)*2);
205153 if( aSzDel==0 ){
205158 memset(aSzDel, 0, sizeof(aSzDel[0])*(p->nColumn+1)*2);
205172 if( nArg>1 && p->zContentTbl==0 ){
205180 sqlite3_value_type(apVal[0])==SQLITE_NULL
205181 || sqlite3_value_int64(apVal[0])!=sqlite3_value_int64(pNewRowid)
205213 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
205214 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER );
205215 rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel);
205221 if( bInsertDone==0 ){
205223 if( rc==SQLITE_CONSTRAINT && p->zContentTbl==0 ){
205228 rc = fts3PendingTermsDocid(p, 0, iLangid, *pRowid);
205257 rc = sqlite3_exec(p->db, "SAVEPOINT fts3", 0, 0, 0);
205261 int rc2 = sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
205264 sqlite3_exec(p->db, "ROLLBACK TO fts3", 0, 0, 0);
205265 sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
205422 pRet->aMI[0] = (u8*)(&pRet->aMI[1]) - (u8*)pRet;
205423 pRet->aMI[1+nElem] = pRet->aMI[0]
205428 pRet->aRef[0] = 1;
205441 pBuf->aRef[1] = 0;
205443 pBuf->aRef[2] = 0;
205446 if( pBuf->aRef[0]==0 && pBuf->aRef[1]==0 && pBuf->aRef[2]==0 ){
205452 void (*xRet)(void*) = 0;
205453 u32 *aOut = 0;
205455 if( p->aRef[1]==0 ){
205460 else if( p->aRef[2]==0 ){
205486 assert( p->aRef[0]==1 );
205487 p->aRef[0] = 0;
205488 if( p->aRef[0]==0 && p->aRef[1]==0 && p->aRef[2]==0 ){
205565 int iPhrase = 0; /* Variable used as the phrase counter */
205603 LoadDoclistCtx sCtx = {0,0,0}; /* Context for sqlite3Fts3ExprIterate() */
205617 int nPhrase = 0;
205633 if( 0==(*pIter & 0xFE) ){
205635 pIter = 0;
205652 if( pIter->iCurrent<0 ){
205654 ** candidate always starts at offset 0 (even if this candidate has a
205657 pIter->iCurrent = 0;
205662 for(i=0; i<pIter->nPhrase; i++){
205668 int iEnd = 0x7FFFFFFF;
205670 for(i=0; i<pIter->nPhrase; i++){
205676 if( iEnd==0x7FFFFFFF ){
205680 assert( pIter->nSnippet>=0 );
205682 for(i=0; i<pIter->nPhrase; i++){
205689 return 0;
205705 int iScore = 0; /* Score of this snippet */
205707 u64 mCover = 0; /* Mask of phrases covered by this snippet */
205708 u64 mHighlight = 0; /* Mask of tokens to highlight in snippet */
205710 for(i=0; i<pIter->nPhrase; i++){
205721 assert( i>=0 );
205729 for(j=0; j<pPhrase->nToken && j<pIter->nSnippet; j++){
205733 if( 0==(*pCsr & 0x0FE) ) break;
205759 assert( rc==SQLITE_OK || pCsr==0 );
205761 i64 iFirst = 0;
205764 if( iFirst<0 ){
205774 pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0
205812 memset(&sIter, 0, sizeof(sIter));
205817 rc = fts3ExprLoadDoclists(pCsr, &nList, 0);
205845 for(i=0; i<nList; i++){
205861 assert( iScore>=0 );
205888 if( nAppend<0 ){
205905 assert( pStr->z!=0 && (pStr->nAlloc >= pStr->n+nAppend+1) );
205910 pStr->z[pStr->n] = '\0';
205951 for(nLeft=0; !(hlmask & ((u64)1 << nLeft)); nLeft++);
205952 for(nRight=0; !(hlmask & ((u64)1 << (nSnippet-1-nRight))); nRight++);
205953 assert( (nSnippet-1-nRight)<=63 && (nSnippet-1-nRight)>=0 );
205963 if( nDesired>0 ){
205965 int iCurrent = 0; /* Token counter */
205979 const char *ZDUMMY; int DUMMY1 = 0, DUMMY2 = 0, DUMMY3 = 0;
205987 if( nShift>0 ){
206015 int iCurrent = 0; /* Current token number of document */
206016 int iEnd = 0; /* Byte offset of end of current token */
206017 int isShiftDone = 0; /* True after snippet is shifted */
206025 if( zDoc==0 ){
206043 int iBegin = 0; /* Offset in zDoc of start of token */
206044 int iFin = 0; /* Offset in zDoc of end of token */
206045 int isHighlight = 0; /* True for highlighted terms */
206080 ** or (b) this fragment does not begin at position 0 of its column.
206083 if( iPos>0 || iFragment>0 ){
206100 isHighlight = (hlmask & ((u64)1 << (iCurrent-iPos)))!=0;
206122 ** the last varint in the column-list (either the 0x00 signifying the end
206123 ** of the position-list, or the 0x01 that precedes the column number of
206130 char c = 0;
206131 int nEntry = 0;
206133 /* A column-list is terminated by either a 0x01 or 0x00. */
206134 while( 0xFE & (*pEnd | c) ){
206135 c = *pEnd++ & 0x80;
206154 int iCol = 0;
206169 p->aMatchinfo[iStart + (iCol+1)/32] |= (1 << (iCol&0x1F));
206172 assert( *pIter==0x00 || *pIter==0x01 );
206173 if( *pIter!=0x01 ) break;
206189 assert( (pExpr->pLeft==0)==(pExpr->pRight==0) );
206190 if( pExpr->bEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
206213 ** for(iCol=0; iCol<nCol; iCol++){
206254 for(i=0; i<p->nCol && rc==SQLITE_OK; i++){
206260 p->aMatchinfo[iStart+i*3] = 0;
206342 n = sqlite3_column_bytes(pStmt, 0);
206343 a = sqlite3_column_blob(pStmt, 0);
206344 if( a==0 ){
206349 if( nDoc<=0 || a>pEnd ){
206377 #define LCS_ITERATOR_FINISHED 0x7FFFFFFF;
206397 int rc = 0;
206399 if( NEVER(pIter==0) ) return 1;
206402 if( iRead==0 || iRead==1 ){
206403 pRead = 0;
206428 int nToken = 0;
206438 for(i=0; i<pInfo->nPhrase; i++){
206444 for(iCol=0; iCol<pInfo->nCol; iCol++){
206445 int nLcs = 0; /* LCS value for this column */
206446 int nLive = 0; /* Number of iterators in aIter not at EOF */
206448 for(i=0; i<pInfo->nPhrase; i++){
206455 if( pIt->pRead==0 ){
206463 while( nLive>0 ){
206464 LcsIterator *pAdv = 0; /* The iterator to advance by one position */
206465 int nThisLcs = 0; /* LCS for the current iterator positions */
206467 for(i=0; i<pInfo->nPhrase; i++){
206469 if( pIter->pRead==0 ){
206471 nThisLcs = 0;
206473 if( pAdv==0 || pIter->iPos<pAdv->iPos ){
206476 if( nThisLcs==0 || pIter->iPos==pIter[-1].iPos ){
206521 sqlite3_stmt *pSelect = 0;
206523 for(i=0; rc==SQLITE_OK && zArg[i]; i++){
206527 if( bGlobal ) pInfo->aMatchinfo[0] = pInfo->nPhrase;
206531 if( bGlobal ) pInfo->aMatchinfo[0] = pInfo->nCol;
206536 sqlite3_int64 nDoc = 0;
206537 rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &nDoc, 0, 0);
206538 pInfo->aMatchinfo[0] = (u32)nDoc;
206551 for(iCol=0; iCol<pInfo->nCol; iCol++){
206559 iVal = (u32)(((u32)(nToken&0xffffffff)+nDoc/2)/nDoc);
206567 sqlite3_stmt *pSelectDocsize = 0;
206571 const char *a = sqlite3_column_blob(pSelectDocsize, 0);
206572 const char *pEnd = a + sqlite3_column_bytes(pSelectDocsize, 0);
206573 for(iCol=0; iCol<pInfo->nCol; iCol++){
206588 rc = fts3ExprLoadDoclists(pCsr, 0, 0);
206597 memset(pInfo->aMatchinfo, 0, nZero);
206606 rc = fts3ExprLoadDoclists(pCsr, 0, 0);
206610 rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &pInfo->nDoc,0,0);
206642 int bGlobal = 0; /* Collect 'global' stats as well as local */
206644 u32 *aOut = 0;
206645 void (*xDestroyOut)(void*) = 0;
206647 memset(&sInfo, 0, sizeof(MatchInfo));
206656 pCsr->pMIBuffer = 0;
206664 if( pCsr->pMIBuffer==0 ){
206665 size_t nMatchinfo = 0; /* Number of u32 elements in match-info */
206673 for(i=0; zArg[i]; i++){
206674 char *zErr = 0;
206693 if( xDestroyOut==0 ){
206731 StrBuffer res = {0, 0, 0};
206741 int nSnippet = 0; /* Number of fragments in this snippet */
206746 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
206756 int iSnip; /* Loop counter 0..nSnippet-1 */
206757 u64 mCovered = 0; /* Bitmask of phrases covered by snippet */
206758 u64 mSeen = 0; /* Bitmask of phrases seen by BestSnippet() */
206760 if( nToken>=0 ){
206766 for(iSnip=0; iSnip<nSnippet; iSnip++){
206771 memset(pFragment, 0, sizeof(*pFragment));
206777 for(iRead=0; iRead<pTab->nColumn; iRead++){
206778 SnippetFragment sF = {0, 0, 0, 0};
206779 int iS = 0;
206780 if( iCol>=0 && iRead!=iCol ) continue;
206803 assert( nFToken>0 );
206805 for(i=0; i<nSnippet && rc==SQLITE_OK; i++){
206847 i64 iPos = 0; /* First position in position-list */
206855 assert_fts3_nc( iPos>=0 );
206858 for(iTerm=0; iTerm<nTerm; iTerm++){
206879 pExpr->pPhrase->bIncr = 0;
206896 StrBuffer res = {0, 0, 0}; /* Result string */
206900 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
206904 memset(&sCtx, 0, sizeof(sCtx));
206905 assert( pCsr->isRequireSeek==0 );
206908 rc = fts3ExprLoadDoclists(pCsr, 0, &nToken);
206913 if( 0==sCtx.aTerm ){
206929 for(iCol=0; iCol<pTab->nColumn; iCol++){
206932 int NDUMMY = 0; /* Dummy argument used with xNext() */
206933 int iStart = 0;
206934 int iEnd = 0;
206935 int iCurrent = 0;
206943 sCtx.iTerm = 0;
206957 if( zDoc==0 ){
206974 int iMinPos = 0x7FFFFFFF; /* Position of next token */
206975 TermOffset *pTerm = 0; /* TermOffset associated with next token */
206977 for(i=0; i<nToken; i++){
206990 if( 0==(0xFE&*pTerm->pList) ){
206991 pTerm->pList = 0;
207004 }else if( rc==SQLITE_DONE && pTab->zContentTbl==0 ){
207048 sqlite3_result_blob(pContext, "", 0, SQLITE_STATIC);
207096 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
207097 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
207098 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
207099 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
207100 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
207101 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
207102 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
207103 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
207108 if( c>=0xc0 ){ \
207109 c = sqlite3Utf8Trans1[c-0xc0]; \
207110 while( zIn!=zTerm && (*zIn & 0xc0)==0x80 ){ \
207111 c = (c<<6) + (0x3f & *(zIn++)); \
207113 if( c<0x80 \
207114 || (c&0xFFFFF800)==0xD800 \
207115 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
207119 if( c<0x00080 ){ \
207120 *zOut++ = (u8)(c&0xFF); \
207122 else if( c<0x00800 ){ \
207123 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \
207124 *zOut++ = 0x80 + (u8)(c & 0x3F); \
207126 else if( c<0x10000 ){ \
207127 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \
207128 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
207129 *zOut++ = 0x80 + (u8)(c & 0x3F); \
207131 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07); \
207132 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \
207133 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
207134 *zOut++ = 0x80 + (u8)(c & 0x3F); \
207176 ** all characters in string zIn/nIn to be separators (if bAlnum==0) or
207200 int nEntry = 0;
207202 assert( bAlnum==0 || bAlnum==1 );
207206 assert( (sqlite3FtsUnicodeIsalnum((int)iCode) & 0xFFFFFFFE)==0 );
207208 && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
207219 if( aNew==0 ) return SQLITE_NOMEM;
207226 && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
207229 for(i=0; i<nNew && aNew[i]<(int)iCode; i++);
207246 if( p->nException>0 ){
207248 int iLo = 0;
207263 return 0;
207271 assert( (sqlite3FtsUnicodeIsalnum(iCode) & 0xFFFFFFFE)==0 );
207289 memset(pNew, 0, sizeof(unicode_tokenizer));
207292 for(i=0; rc==SQLITE_OK && i<nArg; i++){
207296 if( n==19 && memcmp("remove_diacritics=1", z, 19)==0 ){
207299 else if( n==19 && memcmp("remove_diacritics=0", z, 19)==0 ){
207300 pNew->eRemoveDiacritic = 0;
207302 else if( n==19 && memcmp("remove_diacritics=2", z, 19)==0 ){
207305 else if( n>=11 && memcmp("tokenchars=", z, 11)==0 ){
207308 else if( n>=11 && memcmp("separators=", z, 11)==0 ){
207309 rc = unicodeAddExceptions(pNew, 0, &z[11], n-11);
207319 pNew = 0;
207327 ** string to be tokenized is pInput[0..nBytes-1]. A cursor
207340 if( pCsr==0 ){
207343 memset(pCsr, 0, sizeof(unicode_cursor));
207346 if( aInput==0 ){
207347 pCsr->nInput = 0;
207349 }else if( nInput<0 ){
207385 unsigned int iCode = 0;
207445 0,
207451 0,
207493 ** codepoints for which this function should return 0).
207503 0x00000030, 0x0000E807, 0x00016C06, 0x0001EC2F, 0x0002AC07,
207504 0x0002D001, 0x0002D803, 0x0002EC01, 0x0002FC01, 0x00035C01,
207505 0x0003DC01, 0x000B0804, 0x000B480E, 0x000B9407, 0x000BB401,
207506 0x000BBC81, 0x000DD401, 0x000DF801, 0x000E1002, 0x000E1C01,
207507 0x000FD801, 0x00120808, 0x00156806, 0x00162402, 0x00163C01,
207508 0x00164437, 0x0017CC02, 0x00180005, 0x00181816, 0x00187802,
207509 0x00192C15, 0x0019A804, 0x0019C001, 0x001B5001, 0x001B580F,
207510 0x001B9C07, 0x001BF402, 0x001C000E, 0x001C3C01, 0x001C4401,
207511 0x001CC01B, 0x001E980B, 0x001FAC09, 0x001FD804, 0x00205804,
207512 0x00206C09, 0x00209403, 0x0020A405, 0x0020C00F, 0x00216403,
207513 0x00217801, 0x0023901B, 0x00240004, 0x0024E803, 0x0024F812,
207514 0x00254407, 0x00258804, 0x0025C001, 0x00260403, 0x0026F001,
207515 0x0026F807, 0x00271C02, 0x00272C03, 0x00275C01, 0x00278802,
207516 0x0027C802, 0x0027E802, 0x00280403, 0x0028F001, 0x0028F805,
207517 0x00291C02, 0x00292C03, 0x00294401, 0x0029C002, 0x0029D401,
207518 0x002A0403, 0x002AF001, 0x002AF808, 0x002B1C03, 0x002B2C03,
207519 0x002B8802, 0x002BC002, 0x002C0403, 0x002CF001, 0x002CF807,
207520 0x002D1C02, 0x002D2C03, 0x002D5802, 0x002D8802, 0x002DC001,
207521 0x002E0801, 0x002EF805, 0x002F1803, 0x002F2804, 0x002F5C01,
207522 0x002FCC08, 0x00300403, 0x0030F807, 0x00311803, 0x00312804,
207523 0x00315402, 0x00318802, 0x0031FC01, 0x00320802, 0x0032F001,
207524 0x0032F807, 0x00331803, 0x00332804, 0x00335402, 0x00338802,
207525 0x00340802, 0x0034F807, 0x00351803, 0x00352804, 0x00355C01,
207526 0x00358802, 0x0035E401, 0x00360802, 0x00372801, 0x00373C06,
207527 0x00375801, 0x00376008, 0x0037C803, 0x0038C401, 0x0038D007,
207528 0x0038FC01, 0x00391C09, 0x00396802, 0x003AC401, 0x003AD006,
207529 0x003AEC02, 0x003B2006, 0x003C041F, 0x003CD00C, 0x003DC417,
207530 0x003E340B, 0x003E6424, 0x003EF80F, 0x003F380D, 0x0040AC14,
207531 0x00412806, 0x00415804, 0x00417803, 0x00418803, 0x00419C07,
207532 0x0041C404, 0x0042080C, 0x00423C01, 0x00426806, 0x0043EC01,
207533 0x004D740C, 0x004E400A, 0x00500001, 0x0059B402, 0x005A0001,
207534 0x005A6C02, 0x005BAC03, 0x005C4803, 0x005CC805, 0x005D4802,
207535 0x005DC802, 0x005ED023, 0x005F6004, 0x005F7401, 0x0060000F,
207536 0x0062A401, 0x0064800C, 0x0064C00C, 0x00650001, 0x00651002,
207537 0x0066C011, 0x00672002, 0x00677822, 0x00685C05, 0x00687802,
207538 0x0069540A, 0x0069801D, 0x0069FC01, 0x006A8007, 0x006AA006,
207539 0x006C0005, 0x006CD011, 0x006D6823, 0x006E0003, 0x006E840D,
207540 0x006F980E, 0x006FF004, 0x00709014, 0x0070EC05, 0x0071F802,
207541 0x00730008, 0x00734019, 0x0073B401, 0x0073C803, 0x00770027,
207542 0x0077F004, 0x007EF401, 0x007EFC03, 0x007F3403, 0x007F7403,
207543 0x007FB403, 0x007FF402, 0x00800065, 0x0081A806, 0x0081E805,
207544 0x00822805, 0x0082801A, 0x00834021, 0x00840002, 0x00840C04,
207545 0x00842002, 0x00845001, 0x00845803, 0x00847806, 0x00849401,
207546 0x00849C01, 0x0084A401, 0x0084B801, 0x0084E802, 0x00850005,
207547 0x00852804, 0x00853C01, 0x00864264, 0x00900027, 0x0091000B,
207548 0x0092704E, 0x00940200, 0x009C0475, 0x009E53B9, 0x00AD400A,
207549 0x00B39406, 0x00B3BC03, 0x00B3E404, 0x00B3F802, 0x00B5C001,
207550 0x00B5FC01, 0x00B7804F, 0x00B8C00C, 0x00BA001A, 0x00BA6C59,
207551 0x00BC00D6, 0x00BFC00C, 0x00C00005, 0x00C02019, 0x00C0A807,
207552 0x00C0D802, 0x00C0F403, 0x00C26404, 0x00C28001, 0x00C3EC01,
207553 0x00C64002, 0x00C6580A, 0x00C70024, 0x00C8001F, 0x00C8A81E,
207554 0x00C94001, 0x00C98020, 0x00CA2827, 0x00CB003F, 0x00CC0100,
207555 0x01370040, 0x02924037, 0x0293F802, 0x02983403, 0x0299BC10,
207556 0x029A7C01, 0x029BC008, 0x029C0017, 0x029C8002, 0x029E2402,
207557 0x02A00801, 0x02A01801, 0x02A02C01, 0x02A08C09, 0x02A0D804,
207558 0x02A1D004, 0x02A20002, 0x02A2D011, 0x02A33802, 0x02A38012,
207559 0x02A3E003, 0x02A4980A, 0x02A51C0D, 0x02A57C01, 0x02A60004,
207560 0x02A6CC1B, 0x02A77802, 0x02A8A40E, 0x02A90C01, 0x02A93002,
207561 0x02A97004, 0x02A9DC03, 0x02A9EC01, 0x02AAC001, 0x02AAC803,
207562 0x02AADC02, 0x02AAF802, 0x02AB0401, 0x02AB7802, 0x02ABAC07,
207563 0x02ABD402, 0x02AF8C0B, 0x03600001, 0x036DFC02, 0x036FFC02,
207564 0x037FFC01, 0x03EC7801, 0x03ECA401, 0x03EEC810, 0x03F4F802,
207565 0x03F7F002, 0x03F8001A, 0x03F88007, 0x03F8C023, 0x03F95013,
207566 0x03F9A004, 0x03FBFC01, 0x03FC040F, 0x03FC6807, 0x03FCEC06,
207567 0x03FD6C0B, 0x03FF8007, 0x03FFA007, 0x03FFE405, 0x04040003,
207568 0x0404DC09, 0x0405E411, 0x0406400C, 0x0407402E, 0x040E7C01,
207569 0x040F4001, 0x04215C01, 0x04247C01, 0x0424FC01, 0x04280403,
207570 0x04281402, 0x04283004, 0x0428E003, 0x0428FC01, 0x04294009,
207571 0x0429FC01, 0x042CE407, 0x04400003, 0x0440E016, 0x04420003,
207572 0x0442C012, 0x04440003, 0x04449C0E, 0x04450004, 0x04460003,
207573 0x0446CC0E, 0x04471404, 0x045AAC0D, 0x0491C004, 0x05BD442E,
207574 0x05BE3C04, 0x074000F6, 0x07440027, 0x0744A4B5, 0x07480046,
207575 0x074C0057, 0x075B0401, 0x075B6C01, 0x075BEC01, 0x075C5401,
207576 0x075CD401, 0x075D3C01, 0x075DBC01, 0x075E2401, 0x075EA401,
207577 0x075F0C01, 0x07BBC002, 0x07C0002C, 0x07C0C064, 0x07C2800F,
207578 0x07C2C40E, 0x07C3040F, 0x07C3440F, 0x07C4401F, 0x07C4C03C,
207579 0x07C5C02B, 0x07C7981D, 0x07C8402B, 0x07C90009, 0x07C94002,
207580 0x07CC0021, 0x07CCC006, 0x07CCDC46, 0x07CE0014, 0x07CE8025,
207581 0x07CF1805, 0x07CF8011, 0x07D0003F, 0x07D10001, 0x07D108B6,
207582 0x07D3E404, 0x07D4003E, 0x07D50004, 0x07D54018, 0x07D7EC46,
207583 0x07D9140B, 0x07DA0046, 0x07DC0074, 0x38000401, 0x38008060,
207584 0x380400F0,
207587 0xFFFFFFFF, 0xFC00FFFF, 0xF8000001, 0xF8000001,
207591 return ( (aAscii[c >> 5] & ((unsigned int)1 << (c & 0x001F)))==0 );
207593 unsigned int key = (((unsigned int)c)<<10) | 0x000003FF;
207594 int iRes = 0;
207595 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
207596 int iLo = 0;
207606 assert( aEntry[0]<key );
207608 return (((unsigned int)c) >= ((aEntry[iRes]>>10) + (aEntry[iRes]&0x3FF)));
207624 0, 1797, 1848, 1859, 1891, 1928, 1940, 1995,
207641 #define HIBIT ((unsigned char)0x80)
207643 '\0', 'a', 'c', 'e', 'i', 'n',
207653 'o'|HIBIT, 'y', '\0', '\0', '\0', '\0',
207654 '\0', '\0', '\0', '\0', 'a', 'b',
207666 unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
207667 int iRes = 0;
207668 int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
207669 int iLo = 0;
207680 if( bComplex==0 && (aChar[iRes] & 0x80) ) return c;
207681 return (c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : ((int)aChar[iRes] & 0x7F);
207690 unsigned int mask0 = 0x08029FDF;
207691 unsigned int mask1 = 0x000361F8;
207692 if( c<768 || c>817 ) return 0;
207720 ** case equivalent is ((C + aiOff[flags>>1]) & 0xFFFF).
207735 {386, 1, 4}, {390, 44, 1}, {391, 0, 1},
207736 {393, 42, 2}, {395, 0, 1}, {398, 32, 1},
207737 {399, 38, 1}, {400, 40, 1}, {401, 0, 1},
207739 {407, 48, 1}, {408, 0, 1}, {412, 52, 1},
207741 {422, 60, 1}, {423, 0, 1}, {425, 60, 1},
207742 {428, 0, 1}, {430, 60, 1}, {431, 0, 1},
207744 {440, 0, 1}, {444, 0, 1}, {452, 2, 1},
207745 {453, 0, 1}, {455, 2, 1}, {456, 0, 1},
207749 {546, 1, 18}, {570, 70, 1}, {571, 0, 1},
207750 {573, 108, 1}, {574, 68, 1}, {577, 0, 1},
207753 {886, 0, 1}, {902, 18, 1}, {904, 16, 3},
207755 {931, 14, 9}, {962, 0, 1}, {975, 4, 1},
207759 {1015, 0, 1}, {1017, 152, 1}, {1018, 0, 1},
207775 {8579, 0, 1}, {9398, 10, 26}, {11264, 22, 47},
207776 {11360, 0, 1}, {11362, 88, 1}, {11363, 102, 1},
207779 {11378, 0, 1}, {11381, 0, 1}, {11390, 78, 2},
207780 {11392, 1, 100}, {11499, 1, 4}, {11506, 0, 1},
207783 {42878, 1, 10}, {42891, 0, 1}, {42893, 74, 1},
207808 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
207809 int iLo = 0;
207812 assert( c>aEntry[0].iCode );
207816 if( cmp>=0 ){
207824 assert( iRes>=0 && c>=aEntry[iRes].iCode );
207826 if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
207827 ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
207828 assert( ret>0 );
207865 ** Support for JSON-5 extensions was added with version 3.42.0 (2023-05-16).
207869 ** Beginning with version 3.45.0 (circa 2024-01-01), these routines also
207895 ** 0: NULL
207914 ** of the element and if X>>4 is between 0 and 11, then the payload
207923 ** 12 1 byte (0-255) 2
207924 ** 13 2 byte (0-65535) 3
207925 ** 14 4 byte (0-4294967295) 5
207926 ** 15 8 byte (0-1.8e19) 9
207930 ** ways: (1) (X>>4)==10, (2) (X>>4)==12 following by one 0x0a byte,
207931 ** (3) (X>>4)==13 followed by 0x00 and 0x0a, (4) (X>>4)==14 followed by
207932 ** 0x00 0x00 0x00 0x0a, or (5) (X>>4)==15 followed by 7 bytes of 0x00 and
207933 ** a single byte of 0x0a. The shorter forms are preferred, of course, but
207957 ** code is between 0 and 12 and that the total size of the element
207971 #define JSONB_NULL 0 /* "null" */
207975 #define JSONB_INT5 4 /* integer in 0x000 notation */
208001 /*0 1 2 3 4 5 6 7 8 9 a b c d e f */
208002 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, /* 0 */
208003 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */
208004 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2 */
208005 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3 */
208006 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 4 */
208007 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 5 */
208008 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 6 */
208009 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 7 */
208011 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 8 */
208012 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 9 */
208013 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* a */
208014 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* b */
208015 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* c */
208016 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* d */
208017 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* e */
208018 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* f */
208021 /*0 1 2 3 4 5 6 7 8 9 a b c d e f */
208022 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, /* 0 */
208023 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */
208024 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2 */
208025 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3 */
208026 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 4 */
208027 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 5 */
208028 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 6 */
208029 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 7 */
208031 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 8 */
208032 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 9 */
208033 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* a */
208034 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* b */
208035 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* c */
208036 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* d */
208037 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* e */
208038 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* f */
208064 /*0 1 2 3 4 5 6 7 8 9 a b c d e f */
208065 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0 */
208066 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */
208067 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, /* 2 */
208070 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, /* 5 */
208084 /*0 1 2 3 4 5 6 7 8 9 a b c d e f */
208085 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0 */
208086 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */
208087 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2 */
208088 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, /* 3 */
208092 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, /* 7 */
208100 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* e */
208120 #define JSON_INVALID_CHAR 0x99999
208160 #define JSTRING_OOM 0x01 /* Out of memory */
208161 #define JSTRING_MALFORMED 0x02 /* Malformed JSONB */
208162 #define JSTRING_ERR 0x04 /* Error already sent to sqlite3_result */
208173 #define JSON_JSON 0x01 /* Result is always JSON */
208174 #define JSON_SQL 0x02 /* Result is always SQL */
208175 #define JSON_ABPATH 0x03 /* Allow abbreviated JSON path specs */
208176 #define JSON_ISSET 0x04 /* json_set(), not json_insert() */
208177 #define JSON_BLOB 0x08 /* Use the BLOB output format */
208198 u32 nBlobAlloc; /* Bytes allocated to aBlob[]. 0 if aBlob is external */
208229 ** should go. Historical note: This limit was 2000 prior to version 3.42.0
208240 #define JSON_EDITABLE 0x01 /* Generate a writable JsonParse object */
208241 #define JSON_KEEPERROR 0x02 /* Return non-NULL even if there is an error */
208264 for(i=0; i<p->nUsed; i++){
208286 assert( pParse->zJson!=0 );
208288 assert( pParse->delta==0 );
208290 if( p==0 ){
208293 if( p==0 ) return SQLITE_NOMEM;
208297 if( p==0 ) return SQLITE_NOMEM;
208300 jsonParseFree(p->a[0]);
208301 memmove(p->a, &p->a[1], (JSON_CACHE_SIZE-1)*sizeof(p->a[0]));
208304 assert( pParse->nBlobAlloc>0 );
208305 pParse->eEdit = 0;
208334 return 0;
208337 if( zJson==0 ) return 0;
208341 if( p==0 ){
208342 return 0;
208344 for(i=0; i<p->nUsed; i++){
208348 for(i=0; i<p->nUsed; i++){
208350 if( memcmp(p->a[i]->zJson, zJson, nJson)==0 ) break;
208361 assert( p->a[i]->delta==0 );
208364 return 0;
208378 p->nUsed = 0;
208386 p->eErr = 0;
208415 if( zNew==0 ){
208421 p->bStatic = 0;
208424 if( p->zBuf==0 ){
208441 assert( N>0 );
208447 if( N==0 ) return;
208456 assert( N>0 );
208493 if( p->eErr==0 ){
208494 assert( p->nUsed>0 );
208506 jsonAppendChar(p, 0);
208508 return p->eErr==0;
208516 if( p->nUsed==0 ) return;
208530 0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0,
208531 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
208539 assert( c>=0 && c<sizeof(aSpecial) );
208548 p->zBuf[p->nUsed+2] = '0';
208549 p->zBuf[p->nUsed+3] = '0';
208551 p->zBuf[p->nUsed+5] = "0123456789abcdef"[c&0xf];
208568 if( z==0 ) return;
208569 if( (N+p->nUsed+2 >= p->nAlloc) && jsonStringGrow(p,N+2)!=0 ) return;
208572 k = 0;
208601 if( k>0 ){
208607 if( k>0 ){
208613 c = z[0];
208615 if( (p->nUsed+N+3 > p->nAlloc) && jsonStringGrow(p,N+3)!=0 ) return;
208621 if( (p->nUsed+N+7 > p->nAlloc) && jsonStringGrow(p,N+7)!=0 ) return;
208666 memset(&px, 0, sizeof(px));
208668 jsonTranslateBlobToText(&px, 0, p);
208669 }else if( p->eErr==0 ){
208693 assert( (pParse!=0)==(ctx!=0) );
208694 assert( ctx==0 || ctx==p->pCtx );
208695 if( p->eErr==0 ){
208703 if( pParse && pParse->bJsonIsRCStr==0 && pParse->nBlobAlloc>0 ){
208741 pParse->zJson = 0;
208742 pParse->nJson = 0;
208743 pParse->bJsonIsRCStr = 0;
208747 pParse->aBlob = 0;
208748 pParse->nBlob = 0;
208749 pParse->nBlobAlloc = 0;
208775 ** character: 0..9a..fA..F. But unlike sqlite3HexToInt(), it does not
208785 return (u8)(h & 0xf);
208793 v = (jsonHexToInt(z[0])<<12)
208804 return sqlite3Isxdigit(z[0]) && sqlite3Isxdigit(z[1]);
208822 ** U+000a 0a line feed
208823 ** U+000b 0b vertical tab
208824 ** U+000c 0c form feed
208825 ** U+000d 0d carriage return
208851 int n = 0;
208855 case 0x09:
208856 case 0x0a:
208857 case 0x0b:
208858 case 0x0c:
208859 case 0x0d:
208860 case 0x20: {
208865 if( z[n+1]=='*' && z[n+2]!=0 ){
208868 if( z[j]==0 ) goto whitespace_done;
208875 for(j=n+2; (c = z[j])!=0; j++){
208877 if( 0xe2==(u8)c && 0x80==(u8)z[j+1]
208878 && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2])
208890 case 0xc2: {
208891 if( z[n+1]==0xa0 ){
208897 case 0xe1: {
208898 if( z[n+1]==0x9a && z[n+2]==0x80 ){
208904 case 0xe2: {
208905 if( z[n+1]==0x80 ){
208907 if( c<0x80 ) goto whitespace_done;
208908 if( c<=0x8a || c==0xa8 || c==0xa9 || c==0xaf ){
208912 }else if( z[n+1]==0x81 && z[n+2]==0x9f ){
208918 case 0xe3: {
208919 if( z[n+1]==0x80 && z[n+2]==0x80 ){
208925 case 0xef: {
208926 if( z[n+1]==0xbb && z[n+2]==0xbf ){
208988 if( pParse->nBlobAlloc==0 ){
208995 if( aNew==0 ){ pParse->oom = 1; return 1; }
208996 assert( t<0x7fffffff );
208999 return 0;
209005 ** pParse->nBlobAlloc==0 and pParse->nBlob>0) then make it editable
209014 if( pParse->oom ) return 0;
209015 if( pParse->nBlobAlloc>0 ) return 1;
209018 pParse->aBlob = 0;
209020 return 0;
209034 if( pParse->oom==0 ){
209085 assert( pParse->aBlob!=0 );
209088 a[0] = eType | (szPayload<<4);
209090 }else if( szPayload<=0xff ){
209091 a[0] = eType | 0xc0;
209092 a[1] = szPayload & 0xff;
209094 }else if( szPayload<=0xffff ){
209095 a[0] = eType | 0xd0;
209096 a[1] = (szPayload >> 8) & 0xff;
209097 a[2] = szPayload & 0xff;
209100 a[0] = eType | 0xe0;
209101 a[1] = (szPayload >> 24) & 0xff;
209102 a[2] = (szPayload >> 16) & 0xff;
209103 a[3] = (szPayload >> 8) & 0xff;
209104 a[4] = szPayload & 0xff;
209125 if( pParse->oom ) return 0;
209127 szType = a[0]>>4;
209129 nExtra = 0;
209140 nNeeded = 0;
209141 }else if( szPayload<=0xff ){
209143 }else if( szPayload<=0xffff ){
209151 if( delta>0 ){
209153 return 0; /* OOM error. Error state recorded in pParse->oom. */
209162 if( nNeeded==0 ){
209163 a[0] = (a[0] & 0x0f) | (szPayload<<4);
209165 a[0] = (a[0] & 0x0f) | 0xc0;
209166 a[1] = szPayload & 0xff;
209168 a[0] = (a[0] & 0x0f) | 0xd0;
209169 a[1] = (szPayload >> 8) & 0xff;
209170 a[2] = szPayload & 0xff;
209172 a[0] = (a[0] & 0x0f) | 0xe0;
209173 a[1] = (szPayload >> 24) & 0xff;
209174 a[2] = (szPayload >> 16) & 0xff;
209175 a[3] = (szPayload >> 8) & 0xff;
209176 a[4] = szPayload & 0xff;
209182 ** If z[0] is 'u' and is followed by exactly 4 hexadecimal character,
209187 if( z[0]!='u' ) return 0;
209188 if( !jsonIs4Hex(&z[1]) ) return 0;
209199 ** Return 0 if everything is correct. Return the 1-based byte offset of the
209201 ** 0, return 1).
209213 sz = 0;
209215 if( NEVER(n==0) ) return i+1; /* Checked by caller */
209218 x = z[i] & 0x0f;
209223 return n+sz==1 ? 0 : i+1;
209240 return 0;
209249 if( z[j]!='0' ) return i+1;
209260 return 0;
209264 u8 seen = 0; /* 0: initial. 1: '.' seen 2: 'e' seen */
209277 }else if( z[j]=='0' && x==JSONB_FLOAT ){
209285 if( seen>0 ) return j+1;
209304 if( seen==0 ) return i+1;
209305 return 0;
209314 return 0;
209324 }else if( z[j]<=0x1f ){
209329 }else if( strchr("\"\\/bfnrt",z[j+1])!=0 ){
209338 u32 c = 0;
209346 return 0;
209349 return 0;
209356 sz = 0;
209358 if( n==0 ) return j+1;
209365 return 0;
209368 u32 cnt = 0;
209373 sz = 0;
209375 if( n==0 ) return j+1;
209377 if( (cnt & 1)==0 ){
209378 x = z[j] & 0x0f;
209387 if( (cnt & 1)!=0 ) return j+1;
209388 return 0;
209405 ** 0 End of input
209424 jsonBlobAppendNode(pParse, JSONB_OBJECT, pParse->nJson-i, 0);
209433 if( x<=0 ){
209446 while( (sqlite3JsonId2(z[k]) && json5Whitespace(&z[k])==0)
209461 t = pParse->aBlob[iBlob] & 0x0f;
209487 if( x<=0 ){
209526 jsonBlobAppendNode(pParse, JSONB_ARRAY, pParse->nJson - i, 0);
209535 if( x<=0 ){
209609 || (c=='0') /* Legacy bug compatible */
209611 || (c=='0' && !sqlite3Isdigit(z[j+1])) /* Correct implementation */
209613 || (0xe2==(u8)c && 0x80==(u8)z[j+1]
209614 && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2]))
209626 }else if( c<=0x1f ){
209627 if( c==0 ){
209644 if( strncmp(z+i,"true",4)==0 && !sqlite3Isalnum(z[i+4]) ){
209652 if( strncmp(z+i,"false",5)==0 && !sqlite3Isalnum(z[i+5]) ){
209662 t = 0x00; /* Bit 0x01: JSON5. Bit 0x02: FLOAT */
209667 t = 0x03; /* Bit 0x01: JSON5. Bit 0x02: FLOAT */
209668 seenE = 0;
209674 case '0':
209685 t = 0x00; /* Bit 0x01: JSON5. Bit 0x02: FLOAT */
209687 seenE = 0;
209688 assert( '-' < '0' );
209689 assert( '+' < '0' );
209690 assert( '.' < '0' );
209693 if( c<='0' ){
209694 if( c=='0' ){
209696 assert( t==0x00 );
209698 t = 0x01;
209711 && sqlite3StrNICmp(&z[i+1], "inf",3)==0
209719 return i + (sqlite3StrNICmp(&z[i+4],"inity",5)==0 ? 9 : 4);
209723 t |= 0x01;
209729 if( z[i+1]=='0' ){
209735 t |= 0x01;
209748 if( (t & 0x02)!=0 ){
209752 t |= 0x02;
209756 if( z[j-1]<'0' ){
209759 t |= 0x01;
209769 t |= 0x02;
209776 if( c<'0' || c>'9' ){
209784 if( z[j-1]<'0' ){
209787 t |= 0x01;
209794 assert( JSONB_INT+0x01==JSONB_INT5 );
209795 assert( JSONB_FLOAT+0x01==JSONB_FLOAT5 );
209796 assert( JSONB_INT+0x02==JSONB_FLOAT );
209817 case 0: {
209818 return 0; /* End of file */
209820 case 0x09:
209821 case 0x0a:
209822 case 0x0d:
209823 case 0x20: {
209827 case 0x0b:
209828 case 0x0c:
209830 case 0xc2:
209831 case 0xe1:
209832 case 0xe2:
209833 case 0xe3:
209834 case 0xef: {
209836 if( j>0 ){
209845 if( strncmp(z+i,"null",4)==0 && !sqlite3Isalnum(z[i+4]) ){
209856 for(k=0; k<sizeof(aNanInfName)/sizeof(aNanInfName[0]); k++){
209859 if( sqlite3StrNICmp(&z[i], aNanInfName[k].zMatch, nn)!=0 ){
209879 ** Parse a complete JSON string. Return 0 on success or non-zero if there
209892 i = jsonTranslateTextToBlob(pParse, 0);
209894 if( i>0 ){
209896 assert( pParse->iDepth==0 );
209898 assert( jsonbValidityCheck(pParse, 0, pParse->nBlob, 0)==0 );
209912 if( i<=0 ){
209913 if( pCtx!=0 ){
209923 return 0;
209933 memset(&px, 0, sizeof(px));
209942 (void)jsonTranslateTextToBlob(&px, 0);
209947 assert( px.nBlobAlloc>0 );
209956 ** beginning of the payload. Return 0 on error.
209969 *pSz = 0;
209970 return 0;
209976 *pSz = 0;
209977 return 0;
209983 *pSz = 0;
209984 return 0;
209991 || pParse->aBlob[i+1]!=0
209992 || pParse->aBlob[i+2]!=0
209993 || pParse->aBlob[i+3]!=0
209994 || pParse->aBlob[i+4]!=0
209996 *pSz = 0;
209997 return 0;
210006 *pSz = 0;
210007 return 0;
210035 if( n==0 ){
210039 switch( pParse->aBlob[i] & 0x0f ){
210054 if( sz==0 ) goto malformed_jsonb;
210060 sqlite3_uint64 u = 0;
210062 int bOverflow = 0;
210063 if( sz==0 ) goto malformed_jsonb;
210064 if( zIn[0]=='-' ){
210067 }else if( zIn[0]=='+' ){
210074 }else if( (u>>60)!=0 ){
210084 u32 k = 0;
210086 if( sz==0 ) goto malformed_jsonb;
210087 if( zIn[0]=='-' ){
210092 jsonAppendChar(pOut, '0');
210097 jsonAppendChar(pOut, '0');
210104 if( pOut->nUsed+sz+2<=pOut->nAlloc || jsonStringGrow(pOut, sz+2)==0 ){
210118 while( sz2>0 ){
210119 for(k=0; k<sz2 && (jsonIsOk[(u8)zIn[k]] || zIn[k]=='\''); k++){}
210120 if( k>0 ){
210128 if( zIn[0]=='"' ){
210134 if( zIn[0]<=0x1f ){
210136 jsonAppendControlChar(pOut, zIn[0]);
210141 assert( zIn[0]=='\\' );
210165 case '0':
210176 case 0xe2:
210178 ** whitespace. Not that in UTF8, U+2028 is 0xe2 0x80 0x29.
210181 || 0x80!=(u8)zIn[2]
210182 || (0xa8!=(u8)zIn[3] && 0xa9!=(u8)zIn[3])
210210 while( j<iEnd && pOut->eErr==0 ){
210215 if( sz>0 ) jsonStringTrimOneChar(pOut);
210220 int x = 0;
210224 while( j<iEnd && pOut->eErr==0 ){
210228 if( (x & 1)!=0 || j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
210229 if( sz>0 ) jsonStringTrimOneChar(pOut);
210257 for(jj=0; jj<pPretty->nIndent; jj++){
210287 if( n==0 ){
210291 switch( pParse->aBlob[i] & 0x0f ){
210299 while( pOut->eErr==0 ){
210320 while( pOut->eErr==0 ){
210354 u32 k = 0;
210357 for(i=iRoot+n; n>0 && i<iEnd; i+=sz+n, k++){
210368 u32 sz = 0;
210370 assert( pParse->delta!=0 );
210381 ** If the JSONB at aIns[0..nIns-1] can be expanded (by denormalizing the
210410 static const u8 aType[] = { 0xc0, 0xd0, 0, 0xe0, 0, 0, 0, 0xf0 };
210412 if( (aIns[0]&0x0f)<=2 ) return 0; /* Cannot enlarge NULL, true, false */
210413 switch( aIns[0]>>4 ){
210415 if( ((1<<d)&0x116)==0 ) return 0; /* d must be 1, 2, 4, or 8 */
210421 if( ((1<<d)&0x8a)==0) return 0; /* d must be 1, 3, or 7 */
210427 if( d!=2 && d!=6 ) return 0; /* d must be 2 or 6 */
210433 if( d!=4 ) return 0; /* d must be 4 */
210439 return 0; /* No solution */
210442 assert( i>=2 && i<=9 && aType[i-2]!=0 );
210443 aOut[0] = (aIns[0] & 0x0f) | aType[i-2];
210448 aOut[i] = szPayload & 0xff;
210452 assert( (szPayload>>8)==0 );
210477 if( d<0 && d>=(-8) && aIns!=0
210482 if( d!=0 ){
210502 ** 0x5c 0x0a
210503 ** 0x5c 0x0d
210504 ** 0x5c 0x0d 0x0a
210505 ** 0x5c 0xe2 0x80 0xa8
210506 ** 0x5c 0xe2 0x80 0xa9
210509 u32 i = 0;
210524 if( 0xe2==(u8)z[i+1]
210526 && 0x80==(u8)z[i+2]
210527 && (0xa8==(u8)z[i+3] || 0xa9==(u8)z[i+3])
210538 ** Input z[0..n] defines JSON escape sequence including the leading '\\'.
210547 assert( n>0 );
210548 assert( z[0]=='\\' );
210561 if( (v & 0xfc00)==0xd800
210565 && ((vlo = jsonHexToInt4(&z[8]))&0xfc00)==0xdc00
210567 *piOut = ((v&0x3ff)<<10) + (vlo&0x3ff) + 0x10000;
210580 case '0': {
210581 /* JSON5 requires that the \0 escape not be followed by a digit.
210582 ** But SQLite did not enforce this restriction in versions 3.42.0
210588 *piOut = 0;
210591 *piOut = (n>2 && sqlite3Isdigit(z[2])) ? JSON_INVALID_CHAR : 0;
210607 case 0xe2:
210611 if( nSkip==0 ){
210615 *piOut = 0;
210634 ** 0 if they differ.
210648 assert( rawLeft==0 || rawRight==0 );
210650 if( nLeft==0 ){
210651 cLeft = 0;
210652 }else if( rawLeft || zLeft[0]!='\\' ){
210653 cLeft = ((u8*)zLeft)[0];
210654 if( cLeft>=0xc0 ){
210668 if( nRight==0 ){
210669 cRight = 0;
210670 }else if( rawRight || zRight[0]!='\\' ){
210671 cRight = ((u8*)zRight)[0];
210672 if( cRight>=0xc0 ){
210686 if( cLeft!=cRight ) return 0;
210687 if( cLeft==0 ) return 1;
210693 ** 0 if they differ. Return -1 if an OOM occurs.
210706 if( nLeft!=nRight ) return 0;
210707 return memcmp(zLeft, zRight, nLeft)==0;
210717 #define JSON_LOOKUP_ERROR 0xffffffff
210718 #define JSON_LOOKUP_NOTFOUND 0xfffffffe
210719 #define JSON_LOOKUP_PATHERROR 0xfffffffd
210752 memset(pIns, 0, sizeof(*pIns));
210754 if( zTail[0]==0 ){
210758 rc = 0;
210762 pIns->aBlob = (u8*)&emptyObject[zTail[0]=='.'];
210766 rc = jsonLookupStep(pIns, 0, zTail, 0);
210799 if( zPath[0]==0 ){
210804 if( iLabel>0 ){
210808 jsonBlobEdit(pParse, iRoot, sz, 0, 0);
210819 if( zPath[0]=='.' ){
210823 if( zPath[0]=='"' ){
210826 if( zPath[i]=='\\' && zPath[i+1]!=0 ) i++;
210834 testcase( nKey==0 );
210835 rawKey = memchr(zKey, '\\', nKey)==0;
210838 for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){}
210840 if( nKey==0 ){
210844 if( (x & 0x0f)!=JSONB_OBJECT ) return JSON_LOOKUP_NOTFOUND;
210851 x = pParse->aBlob[j] & 0x0f;
210854 if( n==0 ) return JSON_LOOKUP_ERROR;
210861 if( ((pParse->aBlob[v])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
210863 if( n==0 || v+n+sz>iEnd ) return JSON_LOOKUP_ERROR;
210864 assert( j>0 );
210870 if( ((pParse->aBlob[j])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
210872 if( n==0 ) return JSON_LOOKUP_ERROR;
210882 memset(&ix, 0, sizeof(ix));
210884 jsonBlobAppendNode(&ix, rawKey?JSONB_TEXTRAW:JSONB_TEXT5, nKey, 0);
210892 jsonBlobEdit(pParse, j, 0, 0, nIns);
210894 assert( pParse->aBlob!=0 ); /* Because pParse->oom!=0 */
210895 assert( ix.aBlob!=0 ); /* Because pPasre->oom!=0 */
210908 }else if( zPath[0]=='[' ){
210909 x = pParse->aBlob[iRoot] & 0x0f;
210912 k = 0;
210915 k = k*10 + zPath[i] - '0';
210923 unsigned int nn = 0;
210926 nn = nn*10 + zPath[i] - '0';
210942 if( k==0 ){
210943 rc = jsonLookupStep(pParse, j, &zPath[i+1], 0);
210949 if( n==0 ) return JSON_LOOKUP_ERROR;
210953 if( k>0 ) return JSON_LOOKUP_NOTFOUND;
210963 jsonBlobEdit(pParse, j, 0, v.aBlob, v.nBlob);
210987 if( NEVER(aBlob==0) ) return;
210988 memset(&x, 0, sizeof(x));
210992 jsonTranslateBlobToText(&x, 0, &s);
210993 jsonReturnString(&s, 0, 0);
211016 if( n==0 ){
211020 switch( pParse->aBlob[i] & 0x0f ){
211033 sqlite3_result_int(pCtx, 0);
211038 sqlite3_int64 iRes = 0;
211040 int bNeg = 0;
211042 if( sz==0 ) goto returnfromblob_malformed;
211051 if( z==0 ) goto returnfromblob_oom;
211054 if( rc==0 ){
211070 if( sz==0 ) goto returnfromblob_malformed;
211073 if( z==0 ) goto returnfromblob_oom;
211076 if( rc<=0 ) goto returnfromblob_malformed;
211095 if( zOut==0 ) goto returnfromblob_oom;
211096 for(iIn=iOut=0; iIn<sz; iIn++){
211101 if( v<=0x7f ){
211103 }else if( v<=0x7ff ){
211105 zOut[iOut++] = (char)(0xc0 | (v>>6));
211106 zOut[iOut++] = 0x80 | (v&0x3f);
211107 }else if( v<0x10000 ){
211109 zOut[iOut++] = 0xe0 | (v>>12);
211110 zOut[iOut++] = 0x80 | ((v>>6)&0x3f);
211111 zOut[iOut++] = 0x80 | (v&0x3f);
211116 zOut[iOut++] = 0xf0 | (v>>18);
211117 zOut[iOut++] = 0x80 | ((v>>12)&0x3f);
211118 zOut[iOut++] = 0x80 | ((v>>6)&0x3f);
211119 zOut[iOut++] = 0x80 | (v&0x3f);
211127 zOut[iOut] = 0;
211133 int flags = textOnly ? 0 : SQLITE_PTR_TO_INT(sqlite3_user_data(pCtx));
211179 static u8 aNull[] = { 0x00 };
211180 memset(pParse, 0, sizeof(pParse[0]));
211186 return 0;
211198 if( zJson==0 ) return 1;
211205 memset(pParse, 0, sizeof(pParse[0]));
211216 jsonBlobAppendNode(pParse, JSONB_NULL, 0, 0);
211220 if( z==0 ) return 1;
211221 if( z[0]=='I' ){
211223 }else if( z[0]=='-' && z[1]=='I' ){
211234 if( z==0 ) return 1;
211243 return 0;
211258 if( ctx==0 ) return zMsg;
211265 return 0;
211268 /* argv[0] is a BLOB that seems likely to be a JSONB. Subsequent
211283 u32 rc = 0;
211284 const char *zPath = 0;
211290 flgs = argc==1 ? 0 : JSON_EDITABLE;
211291 p = jsonParseFuncArg(ctx, argv[0], flgs);
211292 if( p==0 ) return;
211296 if( zPath==0 ){
211301 if( zPath[0]!='$' ) goto jsonInsertIntoBlob_patherror;
211307 if( zPath[1]==0 ){
211309 jsonBlobEdit(p, 0, p->nBlob, ax.aBlob, ax.nBlob);
211311 rc = 0;
211316 p->delta = 0;
211317 rc = jsonLookupStep(p, 0, zPath+1, 0);
211358 ** '\r', '\t', '-', or a digit '0' through '9'. Of these, only a subset
211366 u32 n, sz = 0;
211368 if( sqlite3_value_type(pArg)!=SQLITE_BLOB ) return 0;
211371 if( p->nBlob>0
211372 && ALWAYS(p->aBlob!=0)
211373 && ((c = p->aBlob[0]) & 0x0f)<=JSONB_OBJECT
211374 && (n = jsonbPayloadSize(p, 0, &sz))>0
211376 && ((c & 0x0f)>JSONB_FALSE || sz==0)
211378 || (c!=0x7b && c!=0x5b && !sqlite3Isdigit(c))
211379 || jsonbValidityCheck(p, 0, p->nBlob, 1)==0)
211383 p->aBlob = 0;
211384 p->nBlob = 0;
211385 return 0;
211410 JsonParse *p = 0; /* Value to be returned */
211411 JsonParse *pFromCache = 0; /* Value taken from cache */
211414 assert( ctx!=0 );
211417 return 0;
211422 if( (flgs & JSON_EDITABLE)==0 ){
211429 if( p==0 ) goto json_pfa_oom;
211430 memset(p, 0, sizeof(*p));
211433 if( pFromCache!=0 ){
211436 if( p->aBlob==0 ) goto json_pfa_oom;
211445 if( (flgs & JSON_EDITABLE)!=0 && jsonBlobMakeEditable(p, 0)==0 ){
211466 if( p->nJson==0 ) goto json_pfa_malformed;
211467 assert( p->zJson!=0 );
211468 if( jsonConvertTextToBlob(p, (flgs & JSON_KEEPERROR) ? 0 : ctx) ){
211474 return 0;
211481 if( zNew==0 ) goto json_pfa_oom;
211484 p->zJson[p->nJson] = 0;
211493 p = 0;
211506 return 0;
211513 return 0;
211532 if( p->nBlobAlloc>0 && !p->bReadOnly ){
211534 p->nBlobAlloc = 0;
211541 p->delta = 0;
211542 jsonTranslateBlobToText(p, 0, &s);
211566 u32 i, n, nn, sz = 0;
211568 u8 x = pParse->aBlob[iStart] & 0x0f;
211575 if( nn==0 ) nn = 1;
211576 if( sz>0 && x<JSONB_ARRAY ){
211579 for(i=0; i<nn; i++){
211582 if( n==0 ){
211584 iStart = n==0 ? iStart+1 : iEnd;
211591 if( pParse->nBlobAlloc>0 && iEnd>pParse->nBlobAlloc ){
211614 showContent = 0;
211620 showContent = 0;
211625 showContent = 0;
211630 if( sz==0 && x<=JSONB_FALSE ){
211637 if( c<0x20 || c>=0x7f ) c = '.';
211649 if( pParse==0 ){
211656 if( pParse->nBlob==0 ) return;
211657 printf("content (bytes 0..%u):\n", pParse->nBlob-1);
211659 sqlite3StrAccumInit(&out, 0, zBuf, sizeof(zBuf), 1000000);
211660 jsonDebugPrintBlob(pParse, 0, pParse->nBlob, 0, &out);
211682 sqlite3StrAccumInit(&out, 0, 0, 0, 1000000);
211683 p = jsonParseFuncArg(ctx, argv[0], 0);
211684 if( p==0 ) return;
211686 jsonDebugPrintBlob(p, 0, p->nBlob, 0, &out);
211715 jsonAppendSqlValue(&jx, argv[0]);
211716 jsonReturnString(&jx, 0, 0);
211735 for(i=0; i<argc; i++){
211740 jsonReturnString(&jx, 0, 0);
211749 ** Return 0 if the input is not a well-formed JSON array.
211757 sqlite3_int64 cnt = 0;
211759 u8 eErr = 0;
211761 p = jsonParseFuncArg(ctx, argv[0], 0);
211762 if( p==0 ) return;
211765 if( zPath==0 ){
211769 i = jsonLookupStep(p, 0, zPath[0]=='$' ? zPath+1 : "@", 0);
211779 i = 0;
211782 i = 0;
211784 if( (p->aBlob[i] & 0x0f)==JSONB_ARRAY ){
211794 for(i=0; i<n && (sqlite3Isalnum(z[i]) || z[i]=='_'); i++){}
211823 JsonParse *p = 0; /* The parse */
211829 p = jsonParseFuncArg(ctx, argv[0], 0);
211830 if( p==0 ) return;
211841 if( zPath==0 ) goto json_extract_error;
211843 if( zPath[0]=='$' ){
211844 j = jsonLookupStep(p, 0, zPath+1, 0);
211862 if( zPath[0]=='-' ) jsonAppendRawNZ(&jx,"#",1);
211868 }else if( zPath[0]=='[' && nPath>=3 && zPath[nPath-1]==']' ){
211876 j = jsonLookupStep(p, 0, jx.zBuf, 0);
211887 jsonReturnString(&jx, 0, 0);
211889 assert( (flags & JSON_BLOB)==0 );
211892 jsonReturnFromBlob(p, j, ctx, 0);
211893 if( (flags & (JSON_SQL|JSON_BLOB))==0
211894 && (p->aBlob[j]&0x0f)>=JSONB_ARRAY
211920 jsonReturnString(&jx, 0, 0);
211921 if( (flags & JSON_BLOB)==0 ){
211934 #define JSON_MERGE_OK 0 /* Success */
211992 u32 n, sz=0; /* Return values from jsonbPayloadSize() */
211998 u32 iTLabel = 0; /* Index of the label */
211999 u32 nTLabel = 0; /* Header size in bytes for the target label */
212000 u32 szTLabel = 0; /* Size of the target label payload */
212001 u32 iTValue = 0; /* Index of the target value */
212002 u32 nTValue = 0; /* Header size of the target value */
212003 u32 szTValue = 0; /* Payload size for the target value */
212015 assert( iTarget>=0 && iTarget<pTarget->nBlob );
212016 assert( iPatch>=0 && iPatch<pPatch->nBlob );
212017 x = pPatch->aBlob[iPatch] & 0x0f;
212023 sz = 0;
212029 x = pTarget->aBlob[iTarget] & 0x0f;
212032 jsonBlobEdit(pTarget, iTarget+n, sz, 0, 0);
212034 pTarget->aBlob[iTarget] = (x & 0xf0) | JSONB_OBJECT;
212037 if( NEVER(n==0) ) return JSON_MERGE_BADPATCH;
212041 if( NEVER(n==0) ) return JSON_MERGE_BADTARGET;
212047 ePLabel = pPatch->aBlob[iPCursor] & 0x0f;
212052 if( nPLabel==0 ) return JSON_MERGE_BADPATCH;
212056 if( nPValue==0 ) return JSON_MERGE_BADPATCH;
212065 eTLabel = pTarget->aBlob[iTCursor] & 0x0f;
212070 if( nTLabel==0 ) return JSON_MERGE_BADTARGET;
212074 if( nTValue==0 ) return JSON_MERGE_BADTARGET;
212086 x = pPatch->aBlob[iPValue] & 0x0f;
212089 if( x==0 ){
212091 jsonBlobEdit(pTarget, iTLabel, nTLabel+szTLabel+nTValue+szTValue, 0,0);
212097 pTarget->delta = 0;
212102 }else if( x>0 ){ /* Algorithm line 13 */
212105 if( (pPatch->aBlob[iPValue] & 0x0f)!=JSONB_OBJECT ){ /* Line 14 */
212106 jsonBlobEdit(pTarget, iTEnd, 0, 0, szPValue+nPValue+szNew);
212113 jsonBlobEdit(pTarget, iTEnd, 0, 0, szNew+1);
212116 pTarget->aBlob[iTEnd+szNew] = 0x00;
212118 pTarget->delta = 0;
212146 pTarget = jsonParseFuncArg(ctx, argv[0], JSON_EDITABLE);
212147 if( pTarget==0 ) return;
212148 pPatch = jsonParseFuncArg(ctx, argv[1], 0);
212150 rc = jsonMergePatch(pTarget, 0, pPatch, 0);
212186 for(i=0; i<argc; i+=2){
212200 jsonReturnString(&jx, 0, 0);
212217 const char *zPath = 0; /* Path of element to be removed */
212222 p = jsonParseFuncArg(ctx, argv[0], argc>1 ? JSON_EDITABLE : 0);
212223 if( p==0 ) return;
212226 if( zPath==0 ){
212229 if( zPath[0]!='$' ){
212232 if( zPath[1]==0 ){
212237 p->delta = 0;
212238 rc = jsonLookupStep(p, 0, zPath+1, 0);
212274 if( (argc&1)==0 ) {
212301 int bIsSet = (flags&JSON_ISSET)!=0;
212304 if( (argc&1)==0 ) {
212324 const char *zPath = 0;
212327 p = jsonParseFuncArg(ctx, argv[0], 0);
212328 if( p==0 ) return;
212331 if( zPath==0 ) goto json_type_done;
212332 if( zPath[0]!='$' ){
212336 i = jsonLookupStep(p, 0, zPath+1, 0);
212348 i = 0;
212350 sqlite3_result_text(ctx, jsonbType[p->aBlob[i]&0x0f], -1, SQLITE_STATIC);
212373 memset(&x, 0, sizeof(x));
212374 x.pParse = jsonParseFuncArg(ctx, argv[0], 0);
212375 if( x.pParse==0 ) return;
212378 if( argc==1 || (x.zIndent = (const char*)sqlite3_value_text(argv[1]))==0 ){
212384 jsonTranslateBlobToPrettyText(&x, 0);
212385 jsonReturnString(&s, 0, 0);
212396 ** 0x01 Canonical RFC-8259 JSON text
212397 ** 0x02 JSON text with optional JSON-5 extensions
212398 ** 0x04 Superficially appears to be JSONB
212399 ** 0x08 Strictly well-formed JSONB
212444 ** * Return 0 if the input is not well-formed.
212453 u8 res = 0;
212461 flags = f & 0x0f;
212463 switch( sqlite3_value_type(argv[0]) ){
212467 sqlite3_result_int(ctx, 0);
212473 memset(&py, 0, sizeof(py));
212474 if( jsonArgIsJsonb(argv[0], &py) ){
212475 if( flags & 0x04 ){
212479 }else if( flags & 0x08 ){
212482 res = 0==jsonbValidityCheck(&py, 0, py.nBlob, 1);
212492 if( (flags & 0x3)==0 ) break;
212493 memset(&px, 0, sizeof(px));
212495 p = jsonParseFuncArg(ctx, argv[0], JSON_KEEPERROR);
212501 }else if( (flags & 0x02)!=0 || p->hasNonstd==0 ){
212525 ** that the input was not valid JSON, or return 0 if the input text looks
212533 i64 iErrPos = 0; /* Error position to be returned */
212538 memset(&s, 0, sizeof(s));
212540 if( jsonArgIsJsonb(argv[0], &s) ){
212541 iErrPos = (i64)jsonbValidityCheck(&s, 0, s.nBlob, 1);
212543 s.zJson = (char*)sqlite3_value_text(argv[0]);
212544 if( s.zJson==0 ) return; /* NULL input or OOM */
212545 s.nJson = sqlite3_value_bytes(argv[0]);
212546 if( jsonConvertTextToBlob(&s,0) ){
212552 assert( s.zJson!=0 ); /* Because s.oom is false */
212553 for(k=0; k<s.iErr && ALWAYS(s.zJson[k]); k++){
212554 if( (s.zJson[k] & 0xc0)!=0x80 ) iErrPos++;
212561 if( iErrPos<0 ){
212585 if( pStr->zBuf==0 ){
212592 jsonAppendSqlValue(pStr, argv[0]);
212597 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
212604 jsonReturnString(pStr, 0, 0);
212629 jsonArrayCompute(ctx, 0);
212648 int inStr = 0;
212649 int nNest = 0;
212655 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
212675 z[pStr->nUsed] = 0;
212681 # define jsonGroupInverse 0
212701 z = (const char*)sqlite3_value_text(argv[0]);
212703 if( pStr->zBuf==0 ){
212706 }else if( pStr->nUsed>1 && z!=0 ){
212710 if( z!=0 ){
212719 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
212726 jsonReturnString(pStr, 0, 0);
212751 jsonObjectCompute(ctx, 0);
212807 #define JEACH_KEY 0
212831 if( pNew==0 ) return SQLITE_NOMEM;
212852 if( pCur==0 ) return SQLITE_NOMEM;
212875 p->iRowid = 0;
212876 p->i = 0;
212877 p->aParent = 0;
212878 p->nParent = 0;
212879 p->nParentAlloc = 0;
212880 p->iEnd = 0;
212881 p->eType = 0;
212907 u32 sz = 0;
212919 assert( p->nParent>0 );
212924 u32 n, sz = 0, k, i;
212926 int needQuote = 0;
212930 if( sz==0 || !sqlite3Isalpha(z[0]) ){
212933 for(i=0; i<sz; i++){
212954 u8 levelChange = 0;
212955 u32 n, sz = 0;
212957 x = p->sParse.aBlob[i] & 0x0f;
212966 if( pNew==0 ) return SQLITE_NOMEM;
212986 while( p->nParent>0 && p->i >= p->aParent[p->nParent-1].iEnd ){
212992 if( p->nParent>0 ){
212995 p->eType = p->sParse.aBlob[iVal] & 0x0f;
212997 p->eType = 0;
213001 u32 n, sz = 0;
213013 /* Length of the path for rowid==0 in bRecursive mode.
213018 if( p->iRowid==0 && p->bRecursive && n>=2 ){
213022 u32 x, sz = 0;
213024 z[n] = 0;
213025 assert( p->sParse.eEdit==0 );
213026 x = jsonLookupStep(&p->sParse, 0, z+1, 0);
213045 if( p->nParent==0 ){
213050 if( n==0 ){
213074 if( (p->sParse.aBlob[i] & 0x0f)>=JSONB_ARRAY ){
213081 u8 eType = p->sParse.aBlob[i] & 0x0f;
213087 if( (p->sParse.aBlob[i] & 0x0f)<JSONB_ARRAY ){
213097 if( p->nParent>0 && p->bRecursive ){
213121 if( p->sParse.zJson==0 ){
213143 ** and 0 otherwise.
213151 int unusableMask = 0; /* Mask of unusable JSON and ROOT constraints */
213152 int idxMask = 0; /* Mask of usable == constraints JSON and ROOT */
213159 aIdx[0] = aIdx[1] = -1;
213161 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
213166 assert( iCol==0 || iCol==1 );
213167 testcase( iCol==0 );
213169 if( pConstraint->usable==0 ){
213176 if( pIdxInfo->nOrderBy>0
213177 && pIdxInfo->aOrderBy[0].iColumn<0
213178 && pIdxInfo->aOrderBy[0].desc==0
213183 if( (unusableMask & ~idxMask)!=0 ){
213188 if( aIdx[0]<0 ){
213192 pIdxInfo->idxNum = 0;
213195 i = aIdx[0];
213198 if( aIdx[1]<0 ){
213217 const char *zRoot = 0;
213223 if( idxNum==0 ) return SQLITE_OK;
213224 memset(&p->sParse, 0, sizeof(p->sParse));
213227 if( jsonArgIsJsonb(argv[0], &p->sParse) ){
213230 p->sParse.zJson = (char*)sqlite3_value_text(argv[0]);
213231 p->sParse.nJson = sqlite3_value_bytes(argv[0]);
213232 if( p->sParse.zJson==0 ){
213233 p->i = p->iEnd = 0;
213236 if( jsonConvertTextToBlob(&p->sParse, 0) ){
213245 if( zRoot==0 ) return SQLITE_OK;
213246 if( zRoot[0]!='$' ){
213248 cur->pVtab->zErrMsg = jsonBadPathError(0, zRoot);
213253 if( zRoot[1]==0 ){
213254 i = p->i = 0;
213255 p->eType = 0;
213257 i = jsonLookupStep(&p->sParse, 0, zRoot+1, 0);
213260 p->i = 0;
213261 p->eType = 0;
213262 p->iEnd = 0;
213266 cur->pVtab->zErrMsg = jsonBadPathError(0, zRoot);
213280 i = p->i = 0;
213281 p->eType = 0;
213285 p->nParent = 0;
213288 if( (p->sParse.aBlob[i] & 0x0f)>=JSONB_ARRAY && !p->bRecursive ){
213290 p->eType = p->sParse.aBlob[i] & 0x0f;
213292 if( p->aParent==0 ) return SQLITE_NOMEM;
213295 p->aParent[0].iKey = 0;
213296 p->aParent[0].iEnd = p->iEnd;
213297 p->aParent[0].iHead = p->i;
213298 p->aParent[0].iValue = i;
213311 0, /* iVersion */
213312 0, /* xCreate */
213316 0, /* xDestroy */
213324 0, /* xUpdate */
213325 0, /* xBegin */
213326 0, /* xSync */
213327 0, /* xCommit */
213328 0, /* xRollback */
213329 0, /* xFindMethod */
213330 0, /* xRename */
213331 0, /* xSavepoint */
213332 0, /* xRelease */
213333 0, /* xRollbackTo */
213334 0, /* xShadowName */
213335 0 /* xIntegrity */
213340 0, /* iVersion */
213341 0, /* xCreate */
213345 0, /* xDestroy */
213353 0, /* xUpdate */
213354 0, /* xBegin */
213355 0, /* xSync */
213356 0, /* xCommit */
213357 0, /* xRollback */
213358 0, /* xFindMethod */
213359 0, /* xRename */
213360 0, /* xSavepoint */
213361 0, /* xRelease */
213362 0, /* xRollbackTo */
213363 0, /* xShadowName */
213364 0 /* xIntegrity */
213381 JFUNCTION(json, 1,1,1, 0,0,0, jsonRemoveFunc),
213382 JFUNCTION(jsonb, 1,1,0, 0,1,0, jsonRemoveFunc),
213383 JFUNCTION(json_array, -1,0,1, 1,0,0, jsonArrayFunc),
213384 JFUNCTION(jsonb_array, -1,0,1, 1,1,0, jsonArrayFunc),
213385 JFUNCTION(json_array_length, 1,1,0, 0,0,0, jsonArrayLengthFunc),
213386 JFUNCTION(json_array_length, 2,1,0, 0,0,0, jsonArrayLengthFunc),
213387 JFUNCTION(json_error_position,1,1,0, 0,0,0, jsonErrorFunc),
213388 JFUNCTION(json_extract, -1,1,1, 0,0,0, jsonExtractFunc),
213389 JFUNCTION(jsonb_extract, -1,1,0, 0,1,0, jsonExtractFunc),
213390 JFUNCTION(->, 2,1,1, 0,0,JSON_JSON, jsonExtractFunc),
213391 JFUNCTION(->>, 2,1,0, 0,0,JSON_SQL, jsonExtractFunc),
213392 JFUNCTION(json_insert, -1,1,1, 1,0,0, jsonSetFunc),
213393 JFUNCTION(jsonb_insert, -1,1,0, 1,1,0, jsonSetFunc),
213394 JFUNCTION(json_object, -1,0,1, 1,0,0, jsonObjectFunc),
213395 JFUNCTION(jsonb_object, -1,0,1, 1,1,0, jsonObjectFunc),
213396 JFUNCTION(json_patch, 2,1,1, 0,0,0, jsonPatchFunc),
213397 JFUNCTION(jsonb_patch, 2,1,0, 0,1,0, jsonPatchFunc),
213398 JFUNCTION(json_pretty, 1,1,0, 0,0,0, jsonPrettyFunc),
213399 JFUNCTION(json_pretty, 2,1,0, 0,0,0, jsonPrettyFunc),
213400 JFUNCTION(json_quote, 1,0,1, 1,0,0, jsonQuoteFunc),
213401 JFUNCTION(json_remove, -1,1,1, 0,0,0, jsonRemoveFunc),
213402 JFUNCTION(jsonb_remove, -1,1,0, 0,1,0, jsonRemoveFunc),
213403 JFUNCTION(json_replace, -1,1,1, 1,0,0, jsonReplaceFunc),
213404 JFUNCTION(jsonb_replace, -1,1,0, 1,1,0, jsonReplaceFunc),
213405 JFUNCTION(json_set, -1,1,1, 1,0,JSON_ISSET, jsonSetFunc),
213406 JFUNCTION(jsonb_set, -1,1,0, 1,1,JSON_ISSET, jsonSetFunc),
213407 JFUNCTION(json_type, 1,1,0, 0,0,0, jsonTypeFunc),
213408 JFUNCTION(json_type, 2,1,0, 0,0,0, jsonTypeFunc),
213409 JFUNCTION(json_valid, 1,1,0, 0,0,0, jsonValidFunc),
213410 JFUNCTION(json_valid, 2,1,0, 0,0,0, jsonValidFunc),
213412 JFUNCTION(json_parse, 1,1,0, 0,0,0, jsonParseFunc),
213414 WAGGREGATE(json_group_array, 1, 0, 0,
213418 WAGGREGATE(jsonb_group_array, 1, JSON_BLOB, 0,
213421 WAGGREGATE(json_group_object, 2, 0, 0,
213424 WAGGREGATE(jsonb_group_object,2, JSON_BLOB, 0,
213447 for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
213448 rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
213546 # define NEVER(X) (0)
213548 # define ALWAYS(X) ((X)?1:(assert(0),0))
213549 # define NEVER(X) ((X)?(assert(0),1):0)
213555 #define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
213566 # define FOUR_BYTE_ALIGNED(X) ((((char*)(X) - (char*)0) & 3)==0)
213644 ** headed by the node (leaf nodes have RtreeNode.iNode==0).
213672 #define RTREE_COORD_REAL32 0
213683 # define RTREE_ZERO 0
213704 ** the node that the RtreeSearchPoint represents. When iLevel==0, however,
213711 u8 iLevel; /* 0=entries. 1=leaf node. 2+ for higher */
213811 #define RTREE_EQ 0x41 /* A */
213812 #define RTREE_LE 0x42 /* B */
213813 #define RTREE_LT 0x43 /* C */
213814 #define RTREE_GE 0x44 /* D */
213815 #define RTREE_GT 0x45 /* E */
213816 #define RTREE_MATCH 0x46 /* F: Old-style sqlite3_rtree_geometry_callback() */
213817 #define RTREE_QUERY 0x47 /* G: New-style sqlite3_rtree_query_callback() */
213823 #define RTREE_TRUE 0x3f /* ? */
213824 #define RTREE_FALSE 0x40 /* @ */
213896 /* What version of GCC is being used. 0 means GCC is not being used .
213905 # define GCC_VERSION 0
213914 unsigned int sqlite3RtreeTestcase = 0;
213962 # define SQLITE_BYTEORDER 0
213967 /* What version of MSVC is being used. 0 means MSVC is not being used */
213972 # define MSVC_VERSION 0
213981 return (p[0]<<8) + p[1];
213993 (((u32)p[0]) << 24) +
213996 (((u32)p[3]) << 0)
214015 (((u64)p[0]) << 56) +
214022 (((u64)p[7]) << 0)
214033 p[0] = (i>> 8)&0xFF;
214034 p[1] = (i>> 0)&0xFF;
214052 p[0] = (i>>24)&0xFF;
214053 p[1] = (i>>16)&0xFF;
214054 p[2] = (i>> 8)&0xFF;
214055 p[3] = (i>> 0)&0xFF;
214069 p[0] = (i>>56)&0xFF;
214070 p[1] = (i>>48)&0xFF;
214071 p[2] = (i>>40)&0xFF;
214072 p[3] = (i>>32)&0xFF;
214073 p[4] = (i>>24)&0xFF;
214074 p[5] = (i>>16)&0xFF;
214075 p[6] = (i>> 8)&0xFF;
214076 p[7] = (i>> 0)&0xFF;
214086 assert( p->nRef>0 );
214092 ** Clear the content of node p (set all bytes to 0x00).
214095 memset(&p->zData[2], 0, pRtree->iNodeSize-2);
214109 ** to it. Otherwise, return 0.
214122 assert( pNode->pNext==0 );
214133 if( pNode->iNode!=0 ){
214137 pNode->pNext = 0;
214142 ** Allocate and return new r-tree node. Initially, (RtreeNode.iNode==0),
214151 memset(pNode, 0, sizeof(RtreeNode) + pRtree->iNodeSize);
214167 pRtree->pNodeBlob = 0;
214181 RtreeNode *pNode = 0;
214186 if( (pNode = nodeHashLookup(pRtree, iNode))!=0 ){
214198 pRtree->pNodeBlob = 0;
214206 if( pRtree->pNodeBlob==0 ){
214208 "data", iNode, 0,
214212 *ppNode = 0;
214229 pNode->isDirty = 0;
214230 pNode->pNext = 0;
214232 pRtree->iNodeSize, 0);
214262 if( pNode!=0 ){
214276 *ppNode = 0;
214294 for(ii=0; ii<pRtree->nDim2; ii++){
214353 pNode->isDirty = 0;
214356 if( pNode->iNode==0 && rc==SQLITE_OK ){
214371 assert( pNode->nRef>0 );
214372 assert( pRtree->nNodeRef>0 );
214374 if( pNode->nRef==0 ){
214432 int ii = 0;
214475 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
214491 if( pRtree->nBusy==0 ){
214492 pRtree->inWrTrans = 0;
214493 assert( pRtree->nCursor==0 );
214495 assert( pRtree->nNodeRef==0 || pRtree->bCorrupt );
214536 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
214556 memset(pCsr, 0, sizeof(RtreeCursor));
214576 for(i=0; i<pCsr->nConstraint; i++){
214584 pCsr->aConstraint = 0;
214586 for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
214589 memset(pCsr, 0, sizeof(RtreeCursor));
214601 assert( pRtree->nCursor>0 );
214606 if( pRtree->nCursor==0 && pRtree->inWrTrans==0 ){
214650 c.u = ((c.u>>24)&0xff)|((c.u>>8)&0xff00)| \
214651 ((c.u&0xff)<<24)|((c.u&0xff00)<<8); \
214663 c.u = ((u32)a[0]<<24) + ((u32)a[1]<<16) \
214695 if( eInt==0 ){
214706 readCoord(pCellData, &c); aCoord[0] = c.f;
214721 readCoord(pCellData, &c); aCoord[0] = c.i;
214725 int eWithin = 0;
214728 if( eWithin==0 ) *peWithin = NOT_WITHIN;
214760 pCellData += 8 + 4*(p->iCoord&0xfe);
214845 for(ii=0; ii<nCell; ii++){
214887 return 0;
214902 p->aNode[i] = 0;
214915 return pCur->bPoint ? &pCur->sPoint : pCur->nPoint ? pCur->aPoint : 0;
214924 assert( ii==0 || ii==1 );
214926 if( pCur->aNode[ii]==0 ){
214927 assert( pRC!=0 );
214928 id = ii ? pCur->aPoint[0].id : pCur->sPoint.id;
214929 *pRC = nodeAcquire(RTREE_OF_CURSOR(pCur), id, 0, &pCur->aNode[ii]);
214946 pNew = sqlite3_realloc64(pCur->aPoint, nNew*sizeof(pCur->aPoint[0]));
214947 if( pNew==0 ) return 0;
214956 while( i>0 ){
214960 if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break;
214980 if( pFirst==0
214987 if( pNew==0 ) return 0;
214991 assert( pCur->aNode[ii]==0 );
214992 pCur->aNode[ii] = pCur->aNode[0];
214994 nodeRelease(RTREE_OF_CURSOR(pCur), pCur->aNode[0]);
214996 pCur->aNode[0] = 0;
215008 #if 0
215011 if( idx<0 ){ printf(" s"); }else{ printf("%2d", idx); }
215028 for(ii=0; ii<pCur->nPoint; ii++){
215029 if( ii>0 || pCur->bPoint ) printf(" ");
215043 assert( i==0 || i==1 );
215046 p->aNode[i] = 0;
215050 p->bPoint = 0;
215052 p->anQueue[p->aPoint[0].iLevel]--;
215054 p->aPoint[0] = p->aPoint[n];
215057 p->aNode[n+1] = 0;
215059 i = 0;
215062 if( k<n && rtreeSearchPointCompare(&p->aPoint[k], &p->aPoint[j])<0 ){
215063 if( rtreeSearchPointCompare(&p->aPoint[k], &p->aPoint[i])<0 ){
215070 if( rtreeSearchPointCompare(&p->aPoint[j], &p->aPoint[i])<0 ){
215101 while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){
215111 for(ii=0; ii<nConstraint; ii++){
215133 for(ii=0; ii<pCur->nPoint; ii++){
215139 x.iCell = 0;
215150 if( p==0 ) return SQLITE_NOMEM;
215162 pCur->atEOF = p==0;
215176 pCsr->bAuxValid = 0;
215214 if( NEVER(p==0) ) return SQLITE_OK;
215216 if( i==0 ){
215231 if( pCsr->pReadAux==0 ){
215232 rc = sqlite3_prepare_v3(pRtree->db, pRtree->zReadAuxSql, -1, 0,
215233 &pCsr->pReadAux, 0);
215257 ** *ppLeaf to 0 and return SQLITE_OK. If an error occurs, set *ppLeaf
215267 *ppLeaf = 0;
215270 i64 iNode = sqlite3_column_int64(pRtree->pReadRowid, 0);
215272 rc = nodeAcquire(pRtree, iNode, 0, ppLeaf);
215291 if( pSrc==0 ) return SQLITE_ERROR;
215295 memset(pInfo, 0, sizeof(*pInfo));
215325 RtreeNode *pRoot = 0;
215328 int iCell = 0;
215340 i64 iRowid = sqlite3_value_int64(argv[0]);
215341 i64 iNode = 0;
215342 int eType = sqlite3_value_numeric_type(argv[0]);
215345 && 0==sqlite3IntFloatCompare(iRowid,sqlite3_value_double(argv[0])))
215350 pLeaf = 0;
215352 if( rc==SQLITE_OK && pLeaf!=0 ){
215353 p = rtreeSearchPointNew(pCsr, RTREE_ZERO, 0);
215354 assert( p!=0 ); /* Always returns pCsr->sPoint */
215355 pCsr->aNode[0] = pLeaf;
215368 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
215369 if( rc==SQLITE_OK && argc>0 ){
215375 memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc);
215376 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
215377 assert( (idxStr==0 && argc==0)
215379 for(ii=0; ii<argc; ii++){
215383 p->iCoord = idxStr[ii*2+1]-'0';
215430 assert( pCsr->bPoint==0 ); /* Due to the resetCursor() call above */
215432 if( NEVER(pNew==0) ){ /* Because pCsr->bPoint was FALSE */
215436 pNew->iCell = 0;
215439 pCsr->aNode[0] = pRoot;
215440 pRoot = 0;
215473 ** = 0x41 ('A')
215474 ** <= 0x42 ('B')
215475 ** < 0x43 ('C')
215476 ** >= 0x44 ('D')
215477 ** > 0x45 ('E')
215478 ** MATCH 0x46 ('F')
215489 int bMatch = 0; /* True if there exists a MATCH constraint */
215492 int iIdx = 0;
215494 memset(zIdxStr, 0, sizeof(zIdxStr));
215500 for(ii=0; ii<pIdxInfo->nConstraint; ii++){
215506 assert( pIdxInfo->idxStr==0 );
215507 for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
215510 if( bMatch==0 && p->usable
215511 && p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ
215515 for(jj=0; jj<ii; jj++){
215516 pIdxInfo->aConstraintUsage[jj].argvIndex = 0;
215517 pIdxInfo->aConstraintUsage[jj].omit = 0;
215536 && ((p->iColumn>0 && p->iColumn<=pRtree->nDim2)
215542 case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; doOmit = 0; break;
215543 case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; doOmit = 0; break;
215545 case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; doOmit = 0; break;
215548 default: op = 0; break;
215552 zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0');
215561 if( iIdx>0 ){
215563 if( pIdxInfo->idxStr==0 ){
215589 default: area *= p->aCoord[1].f - p->aCoord[0].f;
215599 default: area *= (i64)p->aCoord[1].i - (i64)p->aCoord[0].i;
215610 RtreeDValue margin = 0;
215615 }while( ii>=0 );
215623 int ii = 0;
215646 for(ii=0; ii<pRtree->nDim2; ii+=2){
215649 if( a2[0].i<a1[0].i || a2[1].i>a1[1].i ) return 0;
215652 for(ii=0; ii<pRtree->nDim2; ii+=2){
215655 if( a2[0].f<a1[0].f || a2[1].f>a1[1].f ) return 0;
215669 for(ii=0; ii<nCell; ii++){
215672 for(jj=0; jj<pRtree->nDim2; jj+=2){
215677 o = (RtreeDValue)0;
215701 RtreeNode *pNode = 0;
215702 rc = nodeAcquire(pRtree, 1, 0, &pNode);
215704 for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){
215706 sqlite3_int64 iBest = 0;
215707 int bFound = 0;
215711 RtreeNode *pChild = 0;
215717 for(iCell=0; iCell<nCell; iCell++){
215722 if( bFound==0 || area<fMinArea ){
215734 for(iCell=0; iCell<nCell; iCell++){
215742 if( iCell==0
215773 int cnt = 0;
215828 ** nIdx. The aIdx array contains the set of integers from 0 to
215847 int iLeft = 0;
215848 int iRight = 0;
215877 #if 0
215909 int iBestDim = 0;
215910 int iBestSplit = 0;
215921 memset(aaSorted, 0, nByte);
215922 for(ii=0; ii<pRtree->nDim; ii++){
215925 for(jj=0; jj<nCell; jj++){
215931 for(ii=0; ii<pRtree->nDim; ii++){
215935 int iBestLeft = 0;
215949 memcpy(&left, &aCell[aaSorted[ii][0]], sizeof(RtreeCell));
215972 if( ii==0 || margin<fBestMargin ){
215979 memcpy(pBboxLeft, &aCell[aaSorted[iBestDim][0]], sizeof(RtreeCell));
215981 for(ii=0; ii<nCell; ii++){
216001 xSetMapping = ((iHeight==0)?rowidWrite:parentWrite);
216002 if( iHeight>0 ){
216014 if( NEVER(pNode==0) ) return SQLITE_ERROR;
216025 int newCellIsRight = 0;
216032 RtreeNode *pLeft = 0;
216033 RtreeNode *pRight = 0;
216047 memset(aiUsed, 0, sizeof(int)*(nCell+1));
216048 for(i=0; i<nCell; i++){
216072 memset(pLeft->zData, 0, pRtree->iNodeSize);
216073 memset(pRight->zData, 0, pRtree->iNodeSize);
216087 || (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft)))
216117 for(i=0; i<NCELL(pRight); i++){
216128 for(i=0; i<NCELL(pLeft); i++){
216135 }else if( newCellIsRight==0 ){
216141 pRight = 0;
216145 pLeft = 0;
216169 while( rc==SQLITE_OK && pChild->iNode!=1 && pChild->pParent==0 ){
216182 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
216184 if( pTest==0 ){
216185 rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
216204 RtreeNode *pParent = 0;
216213 pNode->pParent = 0;
216258 nodeGetCell(pRtree, pNode, 0, &box);
216311 ** subtree iHeight high (leaf nodes have iHeight==0).
216320 if( iHeight>0 ){
216333 if( iHeight==0 ){
216348 for(ii=0; rc==SQLITE_OK && ii<nCell; ii++){
216387 RtreeNode *pLeaf = 0; /* Leaf node containing record iDelete */
216389 RtreeNode *pRoot = 0; /* Root node of rtree structure */
216393 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
216399 rc = findLeafNode(pRtree, iDelete, &pLeaf, 0);
216403 assert( pLeaf!=0 || rc!=SQLITE_OK || CORRUPT_DB );
216411 rc = deleteCell(pRtree, pLeaf, iCell, 0);
216434 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
216436 RtreeNode *pChild = 0;
216437 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
216486 f = (float)(d*(d<0 ? RNDAWAY : RNDTOWARDS));
216494 f = (float)(d*(d<0 ? RNDTOWARDS : RNDAWAY));
216507 ** constraint failure. If it is 0, then the constraint that failed is
216514 sqlite3_stmt *pStmt = 0;
216518 assert( iCol==0 || iCol%2 );
216521 rc = sqlite3_prepare_v2(pRtree->db, zSql, -1, &pStmt, 0);
216528 if( iCol==0 ){
216529 const char *zCol = sqlite3_column_name(pStmt, 0);
216560 int bHaveRowid = 0; /* Set to 1 after new rowid is determined */
216571 memset(&cell, 0, sizeof(cell));
216600 for(ii=0; ii<nn; ii+=2){
216611 for(ii=0; ii<nn; ii+=2){
216625 if( sqlite3_value_type(aData[0])==SQLITE_NULL
216626 || sqlite3_value_int64(aData[0])!=cell.iRowid
216636 rc = rtreeConstraintError(pRtree, 0);
216645 /* If aData[0] is not an SQL NULL value, it is the rowid of a
216649 if( sqlite3_value_type(aData[0])!=SQLITE_NULL ){
216650 rc = rtreeDeleteRowid(pRtree, sqlite3_value_int64(aData[0]));
216659 RtreeNode *pLeaf = 0;
216662 if( bHaveRowid==0 ){
216668 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
216672 rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
216682 for(jj=0; jj<pRtree->nAux; jj++){
216700 assert( pRtree->inWrTrans==0 );
216711 pRtree->inWrTrans = 0;
216735 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
216759 pRtree->inWrTrans = 0;
216778 db, pRtree->zDb, "sqlite_stat1",0,0,0,0,0,0
216785 if( zSql==0 ){
216788 rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
216790 if( sqlite3_step(p)==SQLITE_ROW ) nRow = sqlite3_column_int64(p, 0);
216809 for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
216810 if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
216812 return 0;
216837 0, /* xFindFunction - function overloading */
216840 0, /* xRelease */
216841 0, /* xRollbackTo */
216884 for(ii=0; ii<pRtree->nAux; ii++){
216900 rc = sqlite3_exec(db, zCreate, 0, 0, 0);
216907 appStmt[0] = &pRtree->pWriteNode;
216917 for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){
216920 if( i!=3 || pRtree->nAux==0 ){
216930 rc = sqlite3_prepare_v3(db, zSql, -1, f, appStmt[i], 0);
216940 if( pRtree->zReadAuxSql==0 ){
216947 for(ii=0; ii<pRtree->nAux; ii++){
216960 if( zSql==0 ){
216963 rc = sqlite3_prepare_v3(db, zSql, -1, f, &pRtree->pWriteAux, 0);
216982 sqlite3_stmt *pStmt = 0;
216983 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
216986 *piVal = sqlite3_column_int(pStmt, 0);
217018 int iPageSize = 0;
217053 int dummy = 0;
217061 ** argv[0] -> module name
217085 0, /* 0 */
217109 memset(pRtree, 0, sizeof(Rtree)+nDb+nName*2+8);
217131 if( zArg[0]=='+' ){
217134 }else if( pRtree->nAux>0 ){
217163 iErr = 0;
217185 assert( *ppVtab==0 );
217217 memset(&node, 0, sizeof(RtreeNode));
217218 memset(&tree, 0, sizeof(Rtree));
217219 tree.nDim = (u8)sqlite3_value_int(apArg[0]);
217224 if( node.zData==0 ) return;
217229 pOut = sqlite3_str_new(0);
217230 for(ii=0; ii<NCELL(&node); ii++){
217235 if( ii>0 ) sqlite3_str_append(pOut, " ", 1);
217237 for(jj=0; jj<tree.nDim2; jj++){
217256 ** The depth value is 0 for all nodes other than the root node, and the root
217262 if( sqlite3_value_type(apArg[0])!=SQLITE_BLOB
217263 || sqlite3_value_bytes(apArg[0])<2
217268 u8 *zBlob = (u8 *)sqlite3_value_blob(apArg[0]);
217322 sqlite3_stmt *pRet = 0;
217328 if( z==0 ){
217331 pCheck->rc = sqlite3_prepare_v2(pCheck->db, z, -1, &pRet, 0);
217350 if( z==0 ){
217356 if( pCheck->zReport==0 ){
217380 u8 *pRet = 0; /* Return value */
217382 if( pCheck->rc==SQLITE_OK && pCheck->pGetNode==0 ){
217392 int nNode = sqlite3_column_bytes(pCheck->pGetNode, 0);
217393 const u8 *pNode = (const u8*)sqlite3_column_blob(pCheck->pGetNode, 0);
217395 if( pRet==0 ){
217403 if( pCheck->rc==SQLITE_OK && pRet==0 ){
217412 ** This function is used to check that the %_parent (if bLeaf==0) or %_rowid
217436 assert( bLeaf==0 || bLeaf==1 );
217437 if( pCheck->aCheckMapping[bLeaf]==0 ){
217452 i64 ii = sqlite3_column_int64(pStmt, 0);
217486 for(i=0; i<pCheck->nDim; i++){
217523 int iDepth, /* Depth of iNode (0==leaf) */
217527 u8 *aNode = 0;
217528 int nNode = 0;
217530 assert( iNode==1 || aParent!=0 );
217531 assert( pCheck->nDim>0 );
217542 if( aParent==0 ){
217557 for(i=0; i<nCell; i++){
217562 if( iDepth>0 ){
217563 rtreeCheckMapping(pCheck, 0, iVal, iNode);
217592 i64 nActual = sqlite3_column_int64(pCount, 0);
217615 sqlite3_stmt *pStmt = 0; /* Used to find column count of rtree table */
217616 int nAux = 0; /* Number of extra columns. */
217619 memset(&check, 0, sizeof(check));
217651 rtreeCheckNode(&check, 0, 0, 1);
217659 sqlite3_finalize(check.aCheckMapping[0]);
217678 assert( pzErr!=0 && *pzErr==0 );
217686 if( (*pzErr)==0 ) rc = SQLITE_NOMEM;
217735 char *zReport = 0;
217736 const char *zDb = (const char*)sqlite3_value_text(apArg[0]);
217780 static int geo_debug = 0;
217807 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
217808 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217809 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217810 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217811 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217812 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217813 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217814 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217815 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217816 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217817 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217818 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217819 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217820 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217821 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217822 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217832 # define GCC_VERSION 0
217839 # define MSVC_VERSION 0
217861 ** encoding (1 byte) 0=big-endian, 1=little-endian
217903 unsigned char t = a[0];
217904 a[0] = a[3];
217913 while( fast_isspace(p->z[0]) ) p->z++;
217914 return p->z[0];
217917 /* Parse out a number. Write the value into *pVal if pVal!=0.
217923 int j = 0;
217924 int seenDP = 0;
217925 int seenE = 0;
217930 if( c=='0' && z[j+1]>='0' && z[j+1]<='9' ) return 0;
217935 if( z[j-1]=='-' ) return 0;
217936 if( seenDP ) return 0;
217941 if( z[j-1]<'0' ) return 0;
217949 if( c<'0' || c>'9' ) return 0;
217954 if( z[j-1]<'0' ) return 0;
217981 memset(&s, 0, sizeof(s));
217986 int ii = 0;
217993 if( aNew==0 ){
218000 while( geopolyParseNumber(&s, ii<=1 ? &s.a[s.nVertex*2+ii] : 0) ){
218019 && s.a[0]==s.a[s.nVertex*2-2]
218021 && (s.z++, geopolySkipSpace(&s)==0)
218028 if( pOut==0 ) goto parse_json_err;
218031 pOut->hdr[0] = *(unsigned char*)&x;
218032 pOut->hdr[1] = (s.nVertex>>16)&0xff;
218033 pOut->hdr[2] = (s.nVertex>>8)&0xff;
218034 pOut->hdr[3] = s.nVertex&0xff;
218046 return 0;
218060 GeoPoly *p = 0;
218062 testcase( pCtx==0 );
218068 if( a==0 ){
218070 return 0;
218073 if( (a[0]==0 || a[0]==1)
218077 if( p==0 ){
218084 if( a[0] != *(unsigned char*)&x ){
218086 for(ii=0; ii<nVertex; ii++){
218090 p->hdr[0] ^= 1;
218098 if( zJson==0 ){
218100 return 0;
218105 return 0;
218121 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
218141 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
218148 for(i=0; i<p->nVertex; i++){
218151 sqlite3_str_appendf(x, "[%!g,%!g]]", GeoX(p,0), GeoY(p,0));
218170 p = geopolyFuncParam(context, argv[0], 0);
218177 for(i=0; i<p->nVertex; i++){
218181 sqlite3_str_appendf(x, " %g,%g'", GeoX(p,0), GeoY(p,0));
218184 if( z && z[0] ){
218204 ** geopoly_xform(poly, 1, 0, 0, 1, x-offset, y-offset)
218206 ** Rotate by R around the point (0,0):
218208 ** geopoly_xform(poly, cos(R), sin(R), -sin(R), cos(R), 0, 0)
218215 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
218226 for(ii=0; ii<p->nVertex; ii++){
218250 for(ii=0; ii<p->nVertex-1; ii++){
218255 rArea += (GeoX(p,ii) - GeoX(p,0)) /* (xN - x0) */
218256 * (GeoY(p,ii) + GeoY(p,0)) /* (yN + y0) */
218274 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
218300 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
218350 double x = sqlite3_value_double(argv[0]);
218361 if( p==0 ){
218366 p->hdr[0] = *(unsigned char*)&i;
218367 p->hdr[1] = 0;
218368 p->hdr[2] = (n>>8)&0xff;
218369 p->hdr[3] = n&0xff;
218370 for(i=0; i<n; i++){
218382 ** (1) if aCoord!=0 store the bounding box in aCoord, returning NULL
218395 GeoPoly *pOut = 0;
218398 if( pPoly==0 && aCoord!=0 ){
218399 p = 0;
218400 mnX = aCoord[0].f;
218410 mnX = mxX = GeoX(p,0);
218411 mnY = mxY = GeoY(p,0);
218421 if( aCoord==0 ){
218424 if( pOut==0 ){
218428 return 0;
218432 pOut->hdr[0] = *(unsigned char*)ⅈ
218433 pOut->hdr[1] = 0;
218434 pOut->hdr[2] = 0;
218436 GeoX(pOut,0) = mnX;
218437 GeoY(pOut,0) = mnY;
218446 aCoord[0].f = mnX;
218452 memset(aCoord, 0, sizeof(RtreeCoord)*4);
218465 GeoPoly *p = geopolyBBox(context, argv[0], 0, 0);
218495 (void)geopolyBBox(context, argv[0], a, &rc);
218499 if( pBBox==0 ) return;
218500 if( pBBox->isInit==0 ){
218504 if( a[0].f < pBBox->a[0].f ) pBBox->a[0] = a[0];
218516 pBBox = (GeoBBox*)sqlite3_aggregate_context(context, 0);
218517 if( pBBox==0 ) return;
218518 p = geopolyBBox(context, 0, pBBox->a, 0);
218535 ** 0 x0,y0 is not on or beneath the line segment or the line segment
218549 if( x0<=x1 || x0>x2 ) return 0;
218551 if( x0<=x2 || x0>x1 ) return 0;
218554 if( x0!=x1 ) return 0;
218555 if( y0<y1 && y0<y2 ) return 0;
218556 if( y0>y1 && y0>y2 ) return 0;
218562 return 0;
218570 ** Return 0 if point X,Y is outside the polygon
218577 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
218580 int v = 0;
218581 int cnt = 0;
218585 if( p1==0 ) return;
218586 for(ii=0; ii<p1->nVertex-1; ii++){
218594 GeoX(p1,0), GeoY(p1,0));
218598 }else if( ((v+cnt)&1)==0 ){
218599 sqlite3_result_int(context, 0);
218614 ** Return 0 if any part of P2 is on the outside of P1
218622 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
218623 GeoPoly *p2 = geopolyFuncParam(context, argv[1], 0);
218627 if( x<0 ){
218630 sqlite3_result_int(context, x==2 ? 1 : x==4 ? 2 : 0);
218643 int eType; /* 0 for ADD, 1 for REMOVE */
218695 pEvent->eType = 0;
218716 for(i=0; i<(unsigned)pPoly->nVertex-1; i++){
218718 geopolyAddOneSegment(p, x[0], x[1], x[2], x[3], side, i);
218721 geopolyAddOneSegment(p, x[0], x[1], pPoly->a[0], pPoly->a[1], side, i);
218729 head.pNext = 0;
218750 int mx = 0;
218754 for(i=0; i<nEvent; i++){
218756 p->pNext = 0;
218757 for(j=0; j<mx && a[j]; j++){
218759 a[j] = 0;
218764 p = 0;
218765 for(i=0; i<mx; i++){
218776 head.pNext = 0;
218800 int mx = 0;
218807 p->pNext = 0;
218808 for(i=0; i<mx && a[i]; i++){
218810 a[i] = 0;
218815 p = 0;
218816 for(i=0; i<mx; i++){
218831 int rc = 0;
218832 int needSort = 0;
218833 GeoSegment *pActive = 0;
218841 if( p==0 ) return -1;
218844 p->nEvent = p->nSegment = 0;
218849 memset(aOverlap, 0, sizeof(aOverlap));
218852 GeoSegment *pPrev = 0;
218853 int iMask = 0;
218859 needSort = 0;
218871 pPrev = 0;
218897 if( pThisEvent->eType==0 ){
218907 pActive = ALWAYS(pActive) ? pActive->pNext : 0;
218911 pSeg->pNext = ALWAYS(pSeg->pNext) ? pSeg->pNext->pNext : 0;
218919 if( aOverlap[3]==0 ){
218920 rc = 0;
218921 }else if( aOverlap[1]!=0 && aOverlap[2]==0 ){
218923 }else if( aOverlap[1]==0 && aOverlap[2]!=0 ){
218925 }else if( aOverlap[1]==0 && aOverlap[2]==0 ){
218941 ** 0 The two polygons are disjoint
218953 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
218954 GeoPoly *p2 = geopolyFuncParam(context, argv[1], 0);
218958 if( x<0 ){
218979 geo_debug = sqlite3_value_int(argv[0]);
218989 ** argv[0] -> module name
219021 memset(pRtree, 0, sizeof(Rtree)+nDb+nName*2+8);
219073 assert( *ppVtab==0 );
219103 return geopolyInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
219114 ** that contains polygon argv[0]
219116 ** that contains polygon argv[0]
219127 RtreeNode *pRoot = 0;
219129 int iCell = 0;
219142 i64 iRowid = sqlite3_value_int64(argv[0]);
219143 i64 iNode = 0;
219145 if( rc==SQLITE_OK && pLeaf!=0 ){
219146 p = rtreeSearchPointNew(pCsr, RTREE_ZERO, 0);
219147 assert( p!=0 ); /* Always returns pCsr->sPoint */
219148 pCsr->aNode[0] = pLeaf;
219161 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
219166 assert( argv[0]!=0 );
219167 geopolyBBox(0, argv[0], bbox, &rc);
219173 if( p==0 ){
219176 memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*4);
219177 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
219181 p->iCoord = 0;
219186 p->u.rValue = bbox[0].f;
219198 p->iCoord = 0;
219199 p->u.rValue = bbox[0].f;
219218 if( pNew==0 ){
219223 pNew->iCell = 0;
219226 pCsr->aNode[0] = pRoot;
219227 pRoot = 0;
219256 int idxNum = 0;
219259 for(ii=0; ii<pIdxInfo->nConstraint; ii++){
219262 if( p->iColumn<0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
219266 if( p->iColumn==0 && p->op>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
219275 if( iRowidTerm>=0 ){
219285 if( iFuncTerm>=0 ){
219289 pIdxInfo->aConstraintUsage[iFuncTerm].omit = 0;
219313 if( p==0 ) return SQLITE_OK;
219314 if( i==0 && sqlite3_vtab_nochange(ctx) ) return SQLITE_OK;
219317 if( pCsr->pReadAux==0 ){
219318 rc = sqlite3_prepare_v3(pRtree->db, pRtree->zReadAuxSql, -1, 0,
219319 &pCsr->pReadAux, 0);
219344 ** argv[0] = the rowid to be deleted
219348 ** argv[0] = SQL NULL
219355 ** argv[0] = rowid to modify. Never NULL
219373 int coordChange = 0; /* Change in coordinates */
219384 oldRowidValid = sqlite3_value_type(aData[0])!=SQLITE_NULL;;
219385 oldRowid = oldRowidValid ? sqlite3_value_int64(aData[0]) : 0;
219387 newRowid = newRowidValid ? sqlite3_value_int64(aData[1]) : 0;
219395 assert( aData[2]!=0 );
219396 geopolyBBox(0, aData[2], cell.aCoord, &rc);
219417 rc = rtreeConstraintError(pRtree, 0);
219423 /* If aData[0] is not an SQL NULL value, it is the rowid of a
219437 RtreeNode *pLeaf = 0;
219443 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
219447 rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
219459 int nChange = 0;
219465 GeoPoly *p = 0;
219467 && (p = geopolyFuncParam(0, aData[2], &rc))!=0
219505 if( sqlite3_stricmp(zName, "geopoly_overlap")==0 ){
219507 *ppArg = 0;
219510 if( sqlite3_stricmp(zName, "geopoly_within")==0 ){
219512 *ppArg = 0;
219515 return 0;
219541 0, /* xRelease */
219542 0, /* xRollbackTo */
219562 { geopolyDebugFunc, 1, 0, "geopoly_debug" },
219576 for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
219584 enc, 0,
219585 aFunc[i].xFunc, 0, 0);
219587 for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){
219589 SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS, 0,
219590 0, aAgg[i].xStep, aAgg[i].xFinal);
219593 rc = sqlite3_create_module_v2(db, "geopoly", &geopolyModule, 0, 0);
219611 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
219613 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
219616 rc = sqlite3_create_function(db, "rtreecheck", -1, utf8, 0,rtreecheck, 0,0);
219624 rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);
219628 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
219658 for(i=0; i<p->nParam; i++){
219682 int memErr = 0;
219691 pBlob->cb = pGeomCtx[0];
219694 for(i=0; i<nArg; i++){
219696 if( pBlob->apSqlParam[i]==0 ) memErr = 1;
219727 pGeomCtx->xQueryFunc = 0;
219728 pGeomCtx->xDestructor = 0;
219731 (void *)pGeomCtx, geomCallback, 0, 0, rtreeFreeCallback
219754 pGeomCtx->xGeom = 0;
219759 (void *)pGeomCtx, geomCallback, 0, 0, rtreeFreeCallback
219844 zBuf[127] = '\0';
219871 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
219872 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
219873 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
219874 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
219875 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
219876 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
219877 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
219878 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
219883 if( c>=0xc0 ){ \
219884 c = icuUtf8Trans1[c-0xc0]; \
219885 while( (*zIn & 0xc0)==0x80 ){ \
219886 c = (c<<6) + (0x3f & *(zIn++)); \
219892 if( *(zIn++)>=0xc0 ){ \
219893 while( (*zIn & 0xc0)==0x80 ){zIn++;} \
219900 ** false (0) if they are different.
219910 int prevEscape = 0; /* True if the previous character was uEsc */
219917 if( uPattern==0 ) break;
219936 if( *zString==0 ) return 0;
219942 if( *zPattern==0 ) return 1;
219950 return 0;
219954 if( *zString==0 ) return 0;
219968 return 0;
219970 prevEscape = 0;
219974 return *zString==0;
219995 const unsigned char *zA = sqlite3_value_text(argv[0]);
219997 UChar32 uEsc = 0;
220002 if( sqlite3_value_bytes(argv[0])>SQLITE_MAX_LIKE_PATTERN_LENGTH ){
220014 int i = 0;
220015 if( zE==0 ) return;
220043 ** is 1 if the string matches the pattern, or 0 otherwise.
220072 pExpr = sqlite3_get_auxdata(p, 0);
220074 const UChar *zPattern = sqlite3_value_text16(apArg[0]);
220078 pExpr = uregex_open(zPattern, -1, 0, 0, &status);
220081 sqlite3_set_auxdata(p, 0, pExpr, icuRegexpDelete);
220082 pExpr = sqlite3_get_auxdata(p, 0);
220098 res = uregex_matches(pExpr, 0, &status);
220109 uregex_setText(pExpr, 0, 0, &status);
220111 /* Return 1 or 0. */
220112 sqlite3_result_int(p, res ? 1 : 0);
220143 UChar *zOutput = 0; /* Pointer to output buffer */
220149 const char *zLocale = 0;
220152 bToUpper = (sqlite3_user_data(p)!=0);
220157 zInput = sqlite3_value_text16(apArg[0]);
220161 nOut = nInput = sqlite3_value_bytes16(apArg[0]);
220162 if( nOut==0 ){
220163 sqlite3_result_text16(p, "", 0, SQLITE_STATIC);
220167 for(cnt=0; cnt<2; cnt++){
220169 if( zNew==0 ){
220185 assert( cnt==0 );
220192 assert( 0 ); /* Unreachable */
220223 case UCOL_EQUAL: return 0;
220226 return 0;
220256 zLocale = (const char *)sqlite3_value_text(apArg[0]);
220283 for(i=0; i<sizeof(aStrength)/sizeof(aStrength[0]); i++){
220284 if( sqlite3_stricmp(zOption,aStrength[i].zName)==0 ){
220289 if( i>=sizeof(aStrength)/sizeof(aStrength[0]) ){
220294 for(i=0; i<sizeof(aStrength)/sizeof(aStrength[0]); i++){
220326 {"regexp", 2, SQLITE_ANY|SQLITEICU_EXTRAFLAGS, 0, icuRegexpFunc},
220327 {"lower", 1, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
220328 {"lower", 2, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
220331 {"lower", 1, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
220332 {"lower", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
220335 {"like", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuLikeFunc},
220336 {"like", 3, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuLikeFunc},
220342 for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){
220346 p->iContext ? (void*)db : (void*)0,
220347 p->xFunc, 0, 0
220429 int n = 0;
220431 if( argc>0 ){
220432 n = strlen(argv[0])+1;
220438 memset(p, 0, sizeof(IcuTokenizer));
220442 memcpy(p->zLocale, argv[0], n);
220461 ** string to be tokenized is pInput[0..nBytes-1]. A cursor
220479 int iInput = 0;
220480 int iOut = 0;
220482 *ppCursor = 0;
220484 if( zInput==0 ){
220485 nInput = 0;
220487 }else if( nInput<0 ){
220499 memset(pCsr, 0, sizeof(IcuCursor));
220505 while( c>0 ){
220506 int isError = 0;
220518 c = 0;
220558 int iStart = 0;
220559 int iEnd = 0;
220560 int nByte = 0;
220614 0, /* iVersion */
220620 0, /* xLanguageid */
220832 ** of zero or more numeric characters (0-9). This can be significant because
220868 ** with the "rbu_control" column set to contain integer value 0. The
220999 #if 0
221210 ** to a value between 0 and 10000 to indicate the permyriadage progress of
221215 ** (*pnTwo) is set to 0 to indicate that stage 2 has not yet started. The
221321 ** sqlite3_multiplex_initialize(0, 0);
221330 ** zipvfs_create_vfs_v3("zipvfs", "rbu", 0, xCompressorAlgorithmDetector);
221356 #if 0
221376 # define RBU_ENABLE_DELTA_CKSUM 0
221483 #define WAL_LOCK_WRITE 0
221549 /* Output variables. zTbl==0 implies EOF. */
221576 ** 0: Table does not exist (error)
221583 #define RBU_PK_NOTABLE 0
221727 rbu_file *pMainRbu; /* List of main db files with pRbu!=0 */
221734 ** If this is a temporary file (pRbu!=0 && flags&DELETE_ON_CLOSE), variable
221756 rbu_file *pMainRbuNext; /* Next MAIN_DB file with pRbu!=0 */
221762 #define rbuIsVacuum(p) ((p)->zTarget==0)
221787 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
221793 unsigned int v = 0;
221797 while( (c = zValue[0x7f&*(z++)])>=0 ){
221812 unsigned sum0 = 0;
221813 unsigned sum1 = 0;
221814 unsigned sum2 = 0;
221815 unsigned sum3 = 0;
221817 sum0 += ((unsigned)z[0] + z[4] + z[8] + z[12]);
221825 sum0 += z[0];
221836 case 1: sum3 += (z[0] << 24);
221871 unsigned int total = 0;
221882 while( *zDelta && lenDelta>0 ){
221885 switch( zDelta[0] ){
221889 if( lenDelta>0 && zDelta[0]!=',' ){
221926 zOut[0] = 0;
221988 nOrig = sqlite3_value_bytes(argv[0]);
221989 aOrig = (const char*)sqlite3_value_blob(argv[0]);
221995 if( nOut<0 ){
222001 if( aOut==0 ){
222031 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
222034 *ppStmt = 0;
222077 assert( *pzErrmsg==0 );
222078 if( zSql==0 ){
222080 *ppStmt = 0;
222094 for(i=0; i<pIter->nTblCol; i++){
222099 pIter->azTblCol = 0;
222100 pIter->azTblType = 0;
222101 pIter->aiSrcOrder = 0;
222102 pIter->abTblPk = 0;
222103 pIter->abNotNull = 0;
222104 pIter->nTblCol = 0;
222105 pIter->eType = 0; /* Invalid value */
222129 pIter->pSelect = 0;
222130 pIter->pInsert = 0;
222131 pIter->pDelete = 0;
222132 pIter->pRbuUpdate = 0;
222133 pIter->pTmpInsert = 0;
222134 pIter->nCol = 0;
222135 pIter->nIdxCol = 0;
222136 pIter->aIdxCol = 0;
222137 pIter->zIdxSql = 0;
222149 memset(pIter, 0, sizeof(RbuObjIter));
222166 if( pIter->zIdx==0 ){
222172 , 0, 0, &p->zErrmsg
222179 pIter->bCleanup = 0;
222183 pIter->zTbl = 0;
222184 pIter->zDataTbl = 0;
222186 pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
222191 if( pIter->zIdx==0 ){
222200 pIter->zIdx = 0;
222202 pIter->zIdx = (const char*)sqlite3_column_text(pIter->pIdxIter, 0);
222224 ** for a view or 0 for a table.
222228 ** data[0-9]_<name>
222239 ** the second argument is either missing or 0 (not a view).
222250 zIn = (const char*)sqlite3_value_text(argv[0]);
222254 if( argc==1 || 0==sqlite3_value_int(argv[1]) ){
222258 if( strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
222260 for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
222279 memset(pIter, 0, sizeof(RbuObjIter));
222288 , rbuIsVacuum(p) ? "AND rootpage!=0 AND rootpage IS NOT NULL" : ""));
222313 char *zSql = 0;
222318 if( zSql==0 ) p->rc = SQLITE_NOMEM;
222321 zSql = 0;
222343 if( zSql==0 ){
222346 p->rc = sqlite3_exec(db, zSql, 0, 0, &p->zErrmsg);
222365 void *pRet = 0;
222367 assert( nByte>0 );
222369 if( pRet==0 ){
222372 memset(pRet, 0, nByte);
222410 char *zRet = 0;
222490 ** 0) SELECT count(*) FROM sqlite_schema where name=%Q AND IsVirtual(%Q)
222495 sqlite3_stmt *aStmt[4] = {0, 0, 0, 0};
222498 *piPk = 0;
222501 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
222509 if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
222513 if( sqlite3_column_int(aStmt[0], 0) ){
222517 *piTnum = sqlite3_column_int(aStmt[0], 1);
222526 if( zOrig && zIdx && zOrig[0]=='p' ){
222533 *piPk = sqlite3_column_int(aStmt[2], 0);
222548 if( sqlite3_column_int(aStmt[3],5)>0 ){
222558 for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){
222569 sqlite3_stmt *pList = 0;
222570 int bIndex = 0;
222579 pIter->nIndex = 0;
222583 sqlite3_stmt *pXInfo = 0;
222584 if( zIdx==0 ) break;
222586 memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
222593 if( iCid>=0 ) pIter->abIndexed[iCid] = 1;
222595 memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
222609 if( bIndex==0 ) pIter->abIndexed = 0;
222623 if( pIter->azTblCol==0 ){
222624 sqlite3_stmt *pStmt = 0;
222625 int nCol = 0;
222627 int bRbuRowid = 0; /* If input table has column "rbu_rowid" */
222628 int iOrder = 0;
222629 int iTnum = 0;
222632 assert( pIter->eType==0 );
222639 if( pIter->zIdx==0 ) pIter->iTnum = iTnum;
222656 for(i=0; p->rc==SQLITE_OK && i<nCol; i++){
222663 else if( 0==sqlite3_stricmp("rbu_rowid", zName) ){
222668 pStmt = 0;
222671 && rbuIsVacuum(p)==0
222691 if( zName==0 ) break; /* An OOM - finalize() below returns S_NOMEM */
222693 if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
222711 assert( iPk>=0 );
222713 pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0);
222720 assert( pIter->eType!=RBU_PK_VTAB || pIter->abIndexed==0 );
222721 assert( pIter->eType!=RBU_PK_VTAB || pIter->nIndex==0 );
222736 char *zList = 0;
222739 for(i=0; i<pIter->nTblCol; i++){
222761 char *zRet = 0;
222765 for(i=0; i<pIter->nTblCol; i++){
222804 sqlite3_stmt *pMax = 0;
222805 char *zRet = 0;
222813 sqlite3_int64 iMax = sqlite3_column_int64(pMax, 0);
222830 const char *zVal = (const char*)sqlite3_column_text(pMax, 0);
222869 char *zOrder = 0;
222870 char *zLhs = 0;
222871 char *zSelect = 0;
222872 char *zVector = 0;
222873 char *zRet = 0;
222874 int bFailed = 0;
222876 int iCol = 0;
222877 sqlite3_stmt *pXInfo = 0;
222891 if( iCid<0 ){
222894 for(i=0; pIter->abTblPk[i]==0; i++);
222920 sqlite3_stmt *pSel = 0;
222929 for(iCol=0; iCol<pIter->nCol; iCol++){
222931 if( zQuoted==0 ){
222933 }else if( zQuoted[0]=='N' ){
222990 char *zRet = 0; /* String to return */
222991 char *zImpCols = 0; /* String to return via *pzImposterCols */
222992 char *zImpPK = 0; /* String to return via *pzImposterPK */
222993 char *zWhere = 0; /* String to return via *pzWhere */
222994 int nBind = 0; /* Value to return via *pnBind */
222997 sqlite3_stmt *pXInfo = 0; /* PRAGMA index_xinfo = ? */
223000 assert( p->zErrmsg==0 );
223010 const char *zCol = 0;
223014 int iSeq = sqlite3_column_int(pXInfo, 0);
223020 if( iCid<0 ){
223025 for(i=0; pIter->abTblPk[i]==0; i++);
223041 if( pIter->bUnique==0 || sqlite3_column_int(pXInfo, 5) ){
223053 if( zRet==0 || zImpPK==0 || zImpCols==0 || zWhere==0 ) rc = SQLITE_NOMEM;
223067 zRet = 0;
223068 zImpCols = 0;
223069 zImpPK = 0;
223070 zWhere = 0;
223097 char *zList = 0;
223101 for(i=0; i<pIter->nTblCol; i++){
223109 if( zList==0 ){
223137 char *zList = 0;
223143 for(i=0; i<pIter->nTblCol; i++){
223156 for(i=0; i<pIter->nTblCol; i++){
223202 char *zList = 0;
223210 for(i=0; i<pIter->nTblCol; i++){
223252 char *zRet = 0;
223258 for(i=0; i<nBind; i++){
223260 zRet[i*2+1] = (i+1==nBind) ? '\0' : ',';
223279 char *z = 0;
223280 assert( pIter->zIdx==0 );
223283 sqlite3_stmt *pXList = 0; /* PRAGMA index_list = (pIter->zTbl) */
223284 sqlite3_stmt *pXInfo = 0; /* PRAGMA index_xinfo = <pk-index> */
223291 if( zOrig && strcmp(zOrig, "pk")==0 ){
223305 /* int iCid = sqlite3_column_int(pXInfo, 0); */
223340 sqlite3_stmt *pQuery = 0; /* SELECT name ... WHERE rootpage = $tnum */
223341 const char *zIdx = 0; /* Name of PK index */
223342 sqlite3_stmt *pXInfo = 0; /* PRAGMA main.index_xinfo = $zIdx */
223344 char *zCols = 0; /* Used to build up list of table cols */
223345 char *zPk = 0; /* Used to build up table PK declaration */
223356 zIdx = (const char*)sqlite3_column_text(pQuery, 0);
223387 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
223415 char *zSql = 0;
223417 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
223419 for(iCol=0; p->rc==SQLITE_OK && iCol<pIter->nTblCol; iCol++){
223422 const char *zColl = 0;
223425 p->dbMain, "main", pIter->zTbl, zCol, 0, &zColl, 0, 0, 0
223452 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
223476 assert( pIter->pTmpInsert==0 );
223494 assert( sqlite3_value_int(apVal[0])!=0
223498 if( sqlite3_value_int(apVal[0])!=0 ){
223502 for(i=0; rc==SQLITE_OK && i<nVal; i++){
223516 sqlite3_stmt *pStmt = 0;
223518 char *zRet = 0;
223520 assert( pIter->zIdxSql==0 && pIter->nIdxCol==0 && pIter->aIdxCol==0 );
223531 char *zSql = (char*)sqlite3_column_text(pStmt, 0);
223536 int nParen = 0; /* Number of open parenthesis */
223538 int iIdxCol = 0;
223539 int nIdxAlloc = 0;
223540 for(i=0; zSql[i]; i++){
223548 if( aIdxCol==0 ){
223557 if( nParen==0 ){
223558 assert( iIdxCol==0 );
223559 pIter->aIdxCol[0].zSpan = &zSql[i+1];
223565 if( nParen==0 ){
223588 if( zSql[i]=='\0' ) break;
223591 if( zSql[i]=='\0' ) break;
223620 assert( pIter->bCleanup==0 );
223621 if( pIter->pSelect==0 && rbuObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){
223623 char *zCollist = 0; /* List of indexed columns */
223626 char *zLimit = 0;
223635 char *zImposterCols = 0; /* Columns for imposter table */
223636 char *zImposterPK = 0; /* Primary key declaration for imposter */
223637 char *zWhere = 0; /* WHERE clause on PK columns */
223638 char *zBind = 0;
223639 char *zPart = 0;
223640 int nBind = 0;
223650 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
223656 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
223668 if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
223679 char *zStart = 0;
223684 zLimit = 0;
223689 "SELECT %s, 0 AS rbu_control FROM '%q' %s %s %s ORDER BY %s%s",
223764 if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
223772 if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
223781 "SELECT *%s FROM '%q' WHERE 0;"
223783 , (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
223811 " SELECT rbu_tmp_insert(0, %s);"
223823 char *zStart = 0;
223824 char *zOrder = 0;
223834 zLimit = 0;
223849 (rbuIsVacuum(p) ? "0 AS " : ""),
223889 RbuUpdateStmt *pUp = 0;
223890 int nUp = 0;
223893 *ppStmt = 0;
223901 if( strcmp(pUp->zMask, zMask)==0 ){
223910 assert( pUp==0 || pUp->pNext==0 );
223914 *pp = 0;
223916 pUp->pUpdate = 0;
223924 char *zUpdate = 0;
223955 sqlite3 *db = 0;
223958 p->rc = sqlite3_open_v2(zName, &db, flags, bUseVfs ? p->zVfsName : 0);
223962 db = 0;
223990 RbuState *pRet = 0;
223991 sqlite3_stmt *pStmt = 0;
223996 if( pRet==0 ) return 0;
224002 switch( sqlite3_column_int(pStmt, 0) ){
224071 assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
224072 assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
224073 assert( dbMain==0 || rbuIsVacuum(p)==0 );
224081 if( p->zState==0 ){
224096 #if 0
224098 p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, 0);
224105 #if 0
224109 int bOk = 0;
224110 sqlite3_stmt *pCnt = 0;
224116 && 1==sqlite3_column_int(pCnt, 0)
224123 if( p->rc==SQLITE_OK && bOk==0 ){
224129 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
224136 int bOpen = 0;
224138 p->nRbu = 0;
224139 p->pRbuFd = 0;
224154 p->eStage = 0;
224155 if( p->rc==SQLITE_OK && p->dbMain==0 ){
224160 p->pRbuFd->bNolock = 0;
224163 p->dbMain = 0;
224164 p->dbRbu = 0;
224172 char *zExtra = 0;
224173 if( strlen(p->zRbu)>=5 && 0==memcmp("file:", p->zRbu, 5) ){
224178 if( *zExtra=='\0' ) zExtra = 0;
224183 (zExtra==0 ? "" : "&"), (zExtra==0 ? "" : zExtra)
224186 if( zTarget==0 ){
224197 "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
224203 "rbu_fossil_delta", 2, SQLITE_UTF8, 0, rbuFossilDeltaFunc, 0, 0
224209 "rbu_target_name", -1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
224254 if( sqlite3_uri_boolean(zBase, "8_3_names", 0) )
224258 sz = (int)strlen(z)&0xffffff;
224259 for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){}
224275 i64 iRet = 0;
224279 p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, (void volatile**)&ptr);
224308 if( pState==0 ){
224309 p->eStage = 0;
224311 p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_schema", 0, 0, 0);
224346 rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
224350 if( p->rc==SQLITE_OK && p->nFrame>0 ){
224352 p->nStep = (pState ? pState->nRow : 0);
224358 if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){
224365 assert( p->nPagePerSector==0 );
224401 if( aNew==0 ) return SQLITE_NOMEM;
224409 pRbu->aFrame[pRbu->nFrame].iDbPage = 0;
224455 sqlite3_file *fd = 0;
224484 const char *zUri = sqlite3_db_filename(db, 0);
224485 return sqlite3_uri_boolean(zUri, RBU_EXCLUSIVE_CHECKPOINT, 0);
224493 nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
224494 if( nChar==0 ){
224495 return 0;
224497 zWideFilename = sqlite3_malloc64( nChar*sizeof(zWideFilename[0]) );
224498 if( zWideFilename==0 ){
224499 return 0;
224501 memset(zWideFilename, 0, nChar*sizeof(zWideFilename[0]));
224502 nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename,
224504 if( nChar==0 ){
224506 zWideFilename = 0;
224532 assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
224533 if( zWal==0 || zOal==0 ){
224543 sqlite3 *dbMain = 0;
224551 p->dbMain = 0;
224552 p->dbRbu = 0;
224566 || rbuExclusiveCheckpoint(dbMain)==0
224569 dbMain = 0;
224573 rbuOpenDatabase(p, dbMain, 0);
224574 rbuSetupCheckpoint(p, 0);
224601 int res = 0; /* Return value */
224607 case 0: res = RBU_INSERT; break;
224618 if( z==0 ){
224632 if( res==0 ){
224644 assert( 0==sqlite3_stricmp(zName, zCol) );
224662 assert( eType!=RBU_DELETE || pIter->zIdx==0 );
224681 for(i=0; i<pIter->nCol; i++){
224686 && pIter->zIdx==0 && pIter->eType==RBU_PK_IPK && pIter->abTblPk[i]
224694 if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){
224702 if( pIter->zIdx==0 ){
224740 const char *zMask = 0;
224748 assert( eType!=RBU_UPDATE || pIter->zIdx==0 );
224750 if( pIter->zIdx==0 && (eType==RBU_IDX_DELETE || eType==RBU_IDX_INSERT) ){
224754 if( pIter->zIdx==0 ){
224765 sqlite3_stmt *pUpdate = 0;
224771 for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
224819 iCookie = sqlite3_column_int(pStmt, 0);
224836 sqlite3_stmt *pInsert = 0;
224840 assert( p->zErrmsg==0 );
224867 assert( pInsert==0 || rc==SQLITE_OK );
224897 sqlite3_stmt *pPragma = 0;
224903 zPragma, sqlite3_column_int(pPragma, 0)
224916 sqlite3_stmt *pSql = 0;
224917 sqlite3_stmt *pInsert = 0;
224920 p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
224923 "SELECT sql FROM sqlite_schema WHERE sql!='' AND rootpage!=0"
224930 const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
224931 p->rc = sqlite3_exec(p->dbMain, zSql, 0, 0, &p->zErrmsg);
224938 "SELECT * FROM sqlite_schema WHERE rootpage=0 OR rootpage IS NULL"
224950 for(i=0; i<5; i++){
224957 p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=0",0,0,&p->zErrmsg);
224975 if( rbuIsVacuum(p) && p->nProgress==0 && p->rc==SQLITE_OK ){
224987 if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
224993 rbuObjIterPrepareAll(p, pIter, 0);
225004 p->nStep = 0;
225012 assert( pIter->zTbl==0 );
225016 p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
225019 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
225045 p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, &ptr);
225092 ** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
225097 if( z1==0 && z2==0 ) return 0;
225098 if( z1==0 || z2==0 ) return 1;
225099 return (sqlite3_stricmp(z1, z2)!=0);
225120 || (pState->zDataTbl==0 && rbuStrCompare(pIter->zTbl, pState->zTbl))
225148 sqlite3_vfs *pVfs = 0;
225150 assert( pVfs && p->rc==SQLITE_OK && p->zErrmsg==0 );
225151 pVfs->xDelete(pVfs, zOal, 0);
225169 p->rc = sqlite3rbu_create_vfs(zRnd, 0);
225185 p->zVfsName = 0;
225200 sqlite3_stmt *pStmt = 0;
225201 char *zErrmsg = 0;
225210 "WHERE type='index' AND tbl_name = %Q", sqlite3_value_text(apVal[0]))
225215 int nIndex = 0;
225217 nIndex = sqlite3_column_int(pStmt, 0);
225247 sqlite3_stmt *pStmt = 0;
225248 int bExists = 0; /* True if rbu_count exists */
225253 "rbu_index_cnt", 1, SQLITE_UTF8, (void*)p, rbuIndexCntFunc, 0, 0
225277 p->nPhaseOneStep = sqlite3_column_int64(pStmt, 0);
225292 size_t nTarget = zTarget ? strlen(zTarget) : 0;
225298 RbuState *pState = 0;
225301 memset(p, 0, sizeof(sqlite3rbu));
225302 sqlite3rbu_rename_handler(p, 0, 0);
225308 int bRetry = 0;
225328 rbuOpenDatabase(p, 0, &bRetry);
225330 rbuOpenDatabase(p, 0, 0);
225339 if( pState->eStage==0 ){
225351 assert( p->rc!=SQLITE_OK || p->eStage!=0 );
225359 p->nStep = 0;
225365 && pState->eStage!=0
225383 p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, &p->zErrmsg);
225392 if( p->rc==SQLITE_OK && p->objiter.zTbl==0 ){
225396 if( p->rc==SQLITE_OK && pState->eStage==0 && rbuIsVacuum(p) ){
225404 p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
225411 int frc = sqlite3_file_control(db, "main", SQLITE_FCNTL_ZIPVFS, 0);
225414 db, "PRAGMA journal_mode=off",0,0,&p->zErrmsg);
225455 memset(pRet, 0, sizeof(sqlite3rbu));
225469 if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); }
225480 if( zTarget==0 ){ return rbuMisuseError(); }
225483 if( n>=7 && 0==memcmp("-vactmp", &zState[n-7], 7) ){
225488 return openRbuHandle(0, zTarget, zState);
225495 sqlite3 *db = 0;
225506 ** the pattern "rbu_imp_[0-9]*".
225512 for(i=0; i<(nErrmsg-8); i++){
225513 if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
225515 while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
225532 p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
225544 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
225556 int rc2 = sqlite3_exec(p->dbRbu, "DELETE FROM stat.rbu_state", 0, 0, 0);
225563 assert( p->szTemp==0 );
225579 *pzErrmsg = 0;
225601 if( p->nPhaseOneStep>0 ){
225606 *pnTwo = 0;
225611 *pnTwo = 0;
225625 assert( 0 );
225634 0, SQLITE_RBU_STATE_OAL, SQLITE_RBU_STATE_MOVE,
225635 0, SQLITE_RBU_STATE_CHECKPOINT, SQLITE_RBU_STATE_DONE
225667 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, 0);
225682 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
225685 rc = sqlite3_exec(p->dbRbu, zBegin, 0, 0, 0);
225687 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0,0);
225739 pRbu->pRenameArg = 0;
225807 for(i=0; i<SQLITE_SHM_NLOCK;i++){
225812 p->pRbu->mLock = 0;
225823 assert( pRbu->szTemp>=0 );
225832 ** for all file descriptors with rbu_file.pDb!=0. If the argument has
225833 ** rbu_file.pDb!=0, then it is assumed to already be present on the
225834 ** main list and is only added to the pDb!=0 list.
225841 if( p->pRbu==0 ){
225847 if( pIter==0 ){
225863 p->pMainNext = 0;
225866 p->pMainRbuNext = 0;
225877 ** rbu_file.pDb!=0.
225900 for(i=0; i<p->nShm; i++){
225904 p->apShm = 0;
225912 pMeth->xShmUnmap(p->pReal, 0);
225916 rbuUpdateTempSize(p, 0);
225918 assert( p->pMainNext==0 && p->pRbuVfs->pMain!=p );
225931 return ((u32)aBuf[0] << 24)
225942 aBuf[0] = (iVal >> 24) & 0xFF;
225943 aBuf[1] = (iVal >> 16) & 0xFF;
225944 aBuf[2] = (iVal >> 8) & 0xFF;
225945 aBuf[3] = (iVal >> 0) & 0xFF;
225949 aBuf[0] = (iVal >> 8) & 0xFF;
225950 aBuf[1] = (iVal >> 0) & 0xFF;
225975 memset(zBuf, 0, iAmt);
225984 && rc==SQLITE_IOERR_SHORT_READ && iOfst==0
225992 u32 iRoot = rbuGetU32(&aBuf[52]) ? 1 : 0;
225994 rbuPutU32(&aBuf[36], 0); /* number of free pages */
225995 rbuPutU32(&aBuf[32], 0); /* first page on free list trunk */
226000 memset(&aBuf[100], 0, iAmt-100);
226001 rbuPutU16(&aBuf[105], iAmt & 0xFFFF);
226002 aBuf[100] = 0x0D;
226008 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
226051 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
226100 if( rc==SQLITE_OK && *pSize==0
226169 void *dummy = 0;
226197 if( zOut==0 ) rc = SQLITE_NOMEM;
226242 int bCapture = 0;
226246 if( bCapture==0 || 0==(flags & SQLITE_SHM_UNLOCK) ){
226269 int eStage = (p->pRbu ? p->pRbu->eStage : 0);
226284 if( apNew==0 ){
226287 memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm));
226294 if( pNew==0 ){
226297 memset(pNew, 0, szRegion);
226305 *pp = 0;
226308 assert( p->apShm==0 );
226329 int eStage = (p->pRbu ? p->pRbu->eStage : 0);
226370 0, 0 /* xFetch, xUnfetch */
226386 0, 0, 0, 0, 0, 0
226398 memset(pFd, 0, sizeof(rbu_file));
226412 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName, 0);
226433 && sqlite3_uri_boolean(zName, "rbu_memory", 0)
226438 zOpen = 0;
226449 if( pMeth->iVersion<2 || pMeth->xShmLock==0 ){
226509 sqlite3_int64 sz = 0;
226511 *pResOut = (sz>0);
226607 return 0;
226633 0, /* szOsFile */
226634 0, /* mxPathname */
226635 0, /* pNext */
226636 0, /* zName */
226637 0, /* pAppData */
226649 0, 0, 0, 0,
226656 0, /* xCurrentTimeInt64 (version 2) */
226657 0, 0, 0 /* Unimplemented version 3 methods */
226660 rbu_vfs *pNew = 0; /* Newly allocated VFS */
226668 if( pNew==0 ){
226672 memset(pNew, 0, nByte);
226674 if( pParent==0 ){
226687 if( pNew->mutex==0 ){
226690 rc = sqlite3_vfs_register(&pNew->base, 0);
226707 if( n>=0 ){
226793 " name TEXT," /* 0 Name of table or index */
226797 " ncell INTEGER," /* 4 Cells on page (0 for overflow) */
226817 u32 iChildPg; /* Child node (or 0 if this is a leaf) */
226836 u32 iRightChildPg; /* Right-child page number (or 0) */
226873 # define get2byte(x) ((x)[0]<<8 | (x)[1])
226886 StatTable *pTab = 0;
226895 if( iDb<0 ){
226900 iDb = 0;
226906 if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
226909 assert( rc==SQLITE_OK || pTab==0 );
226911 memset(pTab, 0, sizeof(StatTable));
226933 ** 0x01 There is a schema=? term in the WHERE clause
226934 ** 0x02 There is a name=? term in the WHERE clause
226935 ** 0x04 There is an aggregate=? term in the WHERE clause
226936 ** 0x08 Output should be ordered by name and path
226950 for(i=0; i<pIdxInfo->nConstraint; i++){
226952 if( pIdxInfo->aConstraint[i].usable==0 ){
226957 case 0: { /* name */
226971 i = 0;
226972 if( iSchema>=0 ){
226975 pIdxInfo->idxNum |= 0x01;
226977 if( iName>=0 ){
226979 pIdxInfo->idxNum |= 0x02;
226981 if( iAgg>=0 ){
226983 pIdxInfo->idxNum |= 0x04;
226992 && pIdxInfo->aOrderBy[0].iColumn==0
226993 && pIdxInfo->aOrderBy[0].desc==0
226996 && pIdxInfo->aOrderBy[0].iColumn==0
226997 && pIdxInfo->aOrderBy[0].desc==0
226999 && pIdxInfo->aOrderBy[1].desc==0
227003 pIdxInfo->idxNum |= 0x08;
227018 if( pCsr==0 ){
227021 memset(pCsr, 0, sizeof(StatCursor));
227033 for(i=0; i<p->nCell; i++){
227038 p->nCell = 0;
227039 p->aCell = 0;
227046 memset(p, 0, sizeof(StatPage));
227056 for(i=0; i<ArraySize(pCsr->aPage); i++){
227059 pCsr->aPage[i].aPg = 0;
227062 pCsr->iPage = 0;
227064 pCsr->zPath = 0;
227065 pCsr->isEof = 0;
227070 pCsr->nCell = 0;
227071 pCsr->nMxPayload = 0;
227072 pCsr->nUnused = 0;
227073 pCsr->nPayload = 0;
227074 pCsr->szPage = 0;
227075 pCsr->nPage = 0;
227103 if( flags==0x0D ){ /* Table leaf node */
227127 u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0];
227129 p->flags = aHdr[0];
227130 if( p->flags==0x0A || p->flags==0x0D ){
227133 }else if( p->flags==0x05 || p->flags==0x02 ){
227134 isLeaf = 0;
227141 p->nMxPayload = 0;
227152 if( iNext<iOff+4 && iNext>0 ) goto statPageIsCorrupt;
227156 p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]);
227166 if( p->aCell==0 ) return SQLITE_NOMEM_BKPT;
227167 memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell));
227169 for(i=0; i<p->nCell; i++){
227178 if( p->flags==0x05 ){
227179 /* A table interior node. nPayload==0. */
227184 if( p->flags==0x0D ){
227190 if( nLocal<0 ) goto statPageIsCorrupt;
227197 if( iOff+nLocal+4>nUsable || nPayload>0x7fffffff ){
227203 if( pCell->aOvfl==0 ) return SQLITE_NOMEM_BKPT;
227204 pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]);
227208 DbPage *pPg = 0;
227209 rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg, 0);
227211 assert( pPg==0 );
227225 p->flags = 0;
227245 x[0] = pCsr->iPageno;
227247 pCsr->iOffset = x[0];
227267 DbPage *pDbPage = 0;
227270 if( pPg->aPg==0 ){
227272 if( pPg->aPg==0 ){
227275 memset(&pPg->aPg[pgsz], 0, DBSTAT_PAGE_PADDING_BYTES);
227278 rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPg, &pDbPage, 0);
227290 ** entry will be the next page, but in aggregated mode (pCsr->isAgg!=0),
227303 pCsr->zPath = 0;
227306 if( pCsr->iPage<0 ){
227314 if( nPage==0 ){
227318 rc = statGetPage(pBt, iRoot, &pCsr->aPage[0]);
227319 pCsr->aPage[0].iPgno = iRoot;
227320 pCsr->aPage[0].iCell = 0;
227322 pCsr->aPage[0].zPath = z = sqlite3_mprintf("/");
227323 if( z==0 ) rc = SQLITE_NOMEM_BKPT;
227325 pCsr->iPage = 0;
227354 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
227360 return z==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
227370 if( pCsr->isAgg && pCsr->iPage<0 ){
227391 p[1].iCell = 0;
227394 if( z==0 ) rc = SQLITE_NOMEM_BKPT;
227406 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
227414 case 0x05: /* table internal */
227415 case 0x02: /* index internal */
227418 case 0x0D: /* table leaf */
227419 case 0x0A: /* index leaf */
227431 if( z==0 ) rc = SQLITE_NOMEM_BKPT;
227433 nPayload = 0;
227434 for(i=0; i<p->nCell; i++){
227455 ** arguments in argv[0]. See statBestIndex() for a description of the
227467 int iArg = 0; /* Count of argv[] parameters used so far */
227469 const char *zName = 0; /* Only provide analysis of this table */
227475 pCsr->pStmt = 0;
227476 if( idxNum & 0x01 ){
227480 if( pCsr->iDb<0 ){
227481 pCsr->iDb = 0;
227488 if( idxNum & 0x02 ){
227492 if( idxNum & 0x04 ){
227496 pCsr->isAgg = 0;
227504 " FROM \"%w\".sqlite_schema WHERE rootpage!=0)",
227509 if( idxNum & 0x08 ){
227513 if( zSql==0 ){
227516 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
227534 case 0: /* name */
227599 0, /* iVersion */
227612 0, /* xUpdate */
227613 0, /* xBegin */
227614 0, /* xSync */
227615 0, /* xCommit */
227616 0, /* xRollback */
227617 0, /* xFindMethod */
227618 0, /* xRename */
227619 0, /* xSavepoint */
227620 0, /* xRelease */
227621 0, /* xRollbackTo */
227622 0, /* xShadowName */
227623 0 /* xIntegrity */
227625 return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
227697 #define DBPAGE_COLUMN_PGNO 0
227712 DbpageTable *pTab = 0;
227725 if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
227728 assert( rc==SQLITE_OK || pTab==0 );
227730 memset(pTab, 0, sizeof(DbpageTable));
227749 ** 0 schema=main, full table scan
227756 int iPlan = 0;
227763 for(i=0; i<pIdxInfo->nConstraint; i++){
227784 for(i=0; i<pIdxInfo->nConstraint; i++){
227786 if( p->usable && p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
227799 && pIdxInfo->aOrderBy[0].iColumn<=0
227800 && pIdxInfo->aOrderBy[0].desc==0
227814 if( pCsr==0 ){
227817 memset(pCsr, 0, sizeof(DbpageCursor));
227854 ** 0 schema=main, full table scan
227876 pCsr->mxPgno = 0;
227881 zSchema = (const char*)sqlite3_value_text(argv[0]);
227883 if( pCsr->iDb<0 ) return SQLITE_OK;
227885 pCsr->iDb = 0;
227888 if( NEVER(pBt==0) ) return SQLITE_OK;
227897 pCsr->mxPgno = 0;
227905 rc = sqlite3PagerGet(pCsr->pPager, 1, &pCsr->pPage1, 0);
227917 case 0: { /* pgno */
227922 DbPage *pDbPage = 0;
227928 rc = sqlite3PagerGet(pCsr->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0);
227963 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
227965 if( pBt ) rc = sqlite3BtreeBeginTrans(pBt, 1, 0);
227978 DbPage *pDbPage = 0;
227980 char *zErr = 0;
227996 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
228000 pgno = sqlite3_value_int(argv[0]);
228005 isInsert = 0;
228008 iDb = 0;
228012 if( iDb<0 ){
228018 if( pgno<1 || NEVER(pBt==0) ){
228044 rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pDbPage, 0);
228050 pTab->pgnoTrunc = 0;
228053 pTab->pgnoTrunc = 0;
228059 pTab->pgnoTrunc = 0;
228067 pTab->pgnoTrunc = 0;
228075 if( pTab->pgnoTrunc>0 ){
228084 pTab->pgnoTrunc = 0;
228092 pTab->pgnoTrunc = 0;
228118 0, /* xCommit */
228119 0, /* xRollback */
228120 0, /* xFindMethod */
228121 0, /* xRename */
228122 0, /* xSavepoint */
228123 0, /* xRelease */
228125 0, /* xShadowName */
228126 0 /* xIntegrity */
228128 return sqlite3_create_module(db, "sqlite_dbpage", &dbpage_module, 0);
228302 ** 0x00: Undefined value.
228303 ** 0x01: Integer value.
228304 ** 0x02: Real value.
228305 ** 0x03: Text value.
228306 ** 0x04: Blob value.
228307 ** 0x05: SQL NULL value.
228341 ** 1 byte: Constant 0x54 (capital 'T')
228343 ** nCol bytes: 0x01 for PK columns, 0x00 otherwise.
228348 ** 1 byte: Either SQLITE_INSERT (0x12), UPDATE (0x17) or DELETE (0x09).
228363 ** of INSERT or DELETE changes never contain any undefined (type byte 0x00)
228383 ** 1 byte: Constant 0x50 (capital 'P')
228385 ** nCol bytes: 0x01 for PK columns, 0x00 otherwise.
228390 ** 1 byte: Either SQLITE_INSERT (0x12), UPDATE (0x17) or DELETE (0x09).
228426 ** 1 byte: Constant 0x54 (capital 'T')
228428 ** nCol bytes: 0x01 for PK columns, 0x00 otherwise.
228433 ** 1 byte: Either SQLITE_INSERT (0x12), DELETE (0x09).
228434 ** 1 byte: Flag. 0x01 for REPLACE, 0x00 for OMIT.
228439 ** it was a DELETE. The second field is set to 0x01 if the conflict
228440 ** resolution strategy was REPLACE, or 0x00 if it was OMIT.
228488 #define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
228505 aBuf[0] = (i>>56) & 0xFF;
228506 aBuf[1] = (i>>48) & 0xFF;
228507 aBuf[2] = (i>>40) & 0xFF;
228508 aBuf[3] = (i>>32) & 0xFF;
228509 aBuf[4] = (i>>24) & 0xFF;
228510 aBuf[5] = (i>>16) & 0xFF;
228511 aBuf[6] = (i>> 8) & 0xFF;
228512 aBuf[7] = (i>> 0) & 0xFF;
228539 if( aBuf ) aBuf[0] = eType;
228578 if( z==0 && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
228583 if( n>0 ) memcpy(&aBuf[nVarint + 1], z, n);
228592 if( aBuf ) aBuf[0] = '\0';
228628 ** hash_key_value = HASH_APPEND(0, <value 1>);
228642 h = HASH_APPEND(h, i & 0xFFFFFFFF);
228643 return HASH_APPEND(h, (i>>32)&0xFFFFFFFF);
228652 for(i=0; i<n; i++) h = HASH_APPEND(h, z[i]);
228683 unsigned int h = 0; /* Hash value to return */
228690 assert( *pbNullPK==0 );
228691 for(i=0; i<pTab->nCol; i++){
228726 if( !z && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
228730 assert( pTab->bStat1==0 || i!=1 );
228749 assert( a!=0 );
228751 if( e==0 || e==0xFF ) return 1;
228772 unsigned int h = 0; /* Value to return */
228776 for(i=0; i<pTab->nCol; i++){
228779 if( bPkOnly && isPK==0 ) continue;
228786 || eType==SQLITE_NULL || eType==0
228788 assert( !isPK || (eType!=0 && eType!=SQLITE_NULL) );
228826 for(iCol=0; iCol<pTab->nCol; iCol++){
228832 return 0;
228837 if( bLeftPkOnly==0 ) a1 += sessionSerialLen(a1);
228838 if( bRightPkOnly==0 ) a2 += sessionSerialLen(a2);
228867 int iCol; /* Used to iterate from 0 to nCol */
228869 for(iCol=0; iCol<nCol; iCol++){
228894 ** *paTwo[0] is not 0x00 - the "no value" placeholder), a copy of the *paTwo
228911 u8 *pRet = 0;
228925 if( pRet==0 ){
228955 if( bPatchset==0 ){
228956 int bRequired = 0;
228961 for(i=0; i<pTab->nCol; i++){
228970 if( pTab->abPK[i]==0 ) bRequired = 1;
228974 *(aOut++) = '\0';
228978 if( !bRequired ) return 0;
228986 for(i=0; i<pTab->nCol; i++){
228994 if( bPatchset==0
228995 && (pTab->abPK[i] || (nOld==nNew && 0==memcmp(aOld, aNew, nNew)))
228997 *(aOut++) = '\0';
229026 if( a[0]!=SQLITE_INTEGER ) return 0;
229031 for(iCol=0; iCol<pTab->nCol; iCol++){
229054 if( sqlite3_value_type(pVal)!=eType ) return 0;
229065 if( sqlite3_value_int64(pVal)!=iVal ) return 0;
229070 if( sqlite3_value_double(pVal)!=rVal ) return 0;
229076 if( sqlite3_value_bytes(pVal)!=n ) return 0;
229082 if( n>0 && memcmp(a, z, n) ) return 0;
229107 if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){
229115 if( apNew==0 ){
229116 if( pTab->nChange==0 ){
229121 memset(apNew, 0, sizeof(SessionChange *) * nNew);
229123 for(i=0; i<pTab->nChange; i++){
229164 ** *pabPK = {1, 0, 0, 1}
229187 int nDbCol = 0;
229190 u8 *pAlloc = 0;
229191 char **azCol = 0;
229192 char **azDflt = 0;
229193 u8 *abPK = 0;
229194 int *aiIdx = 0;
229195 int bRowid = 0; /* Set to true to use rowid as PK */
229199 *pazCol = 0;
229200 *pabPK = 0;
229201 *pnCol = 0;
229202 if( pnTotalCol ) *pnTotalCol = 0;
229203 if( paiIdx ) *paiIdx = 0;
229204 if( pzTab ) *pzTab = 0;
229205 if( pazDflt ) *pazDflt = 0;
229208 if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){
229209 rc = sqlite3_table_column_metadata(db, zDb, zThis, 0, 0, 0, 0, 0, 0);
229213 "SELECT 0, 'tbl', '', 0, '', 1, 0 UNION ALL "
229214 "SELECT 1, 'idx', '', 0, '', 2, 0 UNION ALL "
229215 "SELECT 2, 'stat', '', 0, '', 0, 0"
229229 rc = sqlite3_prepare_v2(db, zPragma, -1, &pStmt, 0);
229236 bRowid = (pbRowid!=0);
229240 if( sqlite3_column_int(pStmt, 6)==0 ){ /* !hidden */
229243 if( sqlite3_column_int(pStmt, 5) ) bRowid = 0; /* pk */
229245 if( nDbCol==0 ) bRowid = 0;
229253 if( pAlloc==0 ){
229256 memset(pAlloc, 0, nByte);
229271 i = 0;
229282 if( sqlite3_column_int(pStmt, 6)==0 ){ /* !hidden */
229288 if( zName==0 ) break;
229297 azDflt[i] = 0;
229300 aiIdx[i] = sqlite3_column_int(pStmt, 0);
229344 if( pTab->nCol==0 ){
229346 assert( pTab->azCol==0 || pTab->abPK==0 );
229348 pTab->abPK = 0;
229350 pTab->zName, &pTab->nCol, &pTab->nTotalCol, 0, &pTab->azCol,
229352 ((pSession==0 || pSession->bImplicitPK) ? &pTab->bRowid : 0)
229356 for(i=0; i<pTab->nCol; i++){
229362 if( 0==sqlite3_stricmp("sqlite_stat1", pTab->zName) ){
229376 return (rc || pTab->abPK==0);
229385 int nCol = 0;
229386 int nTotalCol = 0;
229387 const char **azCol = 0;
229388 const char **azDflt = 0;
229389 int *aiIdx = 0;
229390 u8 *abPK = 0;
229391 int bRowid = 0;
229396 pTab->zName, &nCol, &nTotalCol, 0, &azCol, &azDflt, &aiIdx, &abPK,
229397 (pSession->bImplicitPK ? &bRowid : 0)
229405 for(ii=0; ii<nCol; ii++){
229452 SessionChange *pNew = 0;
229453 int nByte = 0;
229454 int nIncr = 0;
229475 if( pNew==0 ){
229493 i64 iVal = 0;
229542 #define SESSION_MAX_BUFFER_SZ (0x7FFFFF00 - 1)
229566 if( 0==aNew ){
229591 if( 0==sessionBufferGrow(p, nStr+1, pRc) ){
229594 p->aBuf[p->nBuf] = 0x00;
229609 char *zApp = 0;
229613 if( zApp==0 ){
229639 SessionBuffer sql = {0,0,0};
229642 int ii = 0;
229644 *ppStmt = 0;
229646 for(ii=0; ii<pTab->nCol; ii++){
229652 rc = sqlite3_prepare_v2(db, (const char*)sql.aBuf, -1, ppStmt, 0);
229665 sqlite3_stmt *pStmt = 0;
229670 int ii = 0;
229671 SessionChange **pp = 0;
229672 for(ii=0; ii<pTab->nChange; ii++){
229700 sqlite3_value *pVal = 0;
229710 sqlite3_value *pVal = 0;
229738 for(ii=0; ii<pTab->nCol; ii++){
229739 sqlite3_value *p = 0;
229741 sessionSerializeValue(0, p, &nNew);
229746 if( sqlite3_preupdate_blobwrite(pSession->db)>=0 ){
229758 int nOld = 0;
229761 sqlite3_value *p = 0;
229763 if( p==0 ){
229798 && (nByte==0 || 0==memcmp(pCsr, sqlite3_value_blob(p), nByte))
229800 bChanged = 0;
229814 sessionSerializeValue(0, p, &nNew);
229846 int bNull = 0;
229848 int nExpect = 0;
229849 SessionStat1Ctx stat1 = {{0,0,0,0,0},0};
229869 if( sessionGrowHash(pSession, 0, pTab) ){
229882 if( pSession->pZeroBlob==0 ){
229883 sqlite3_value *p = sqlite3ValueNew(0);
229884 if( p==0 ){
229888 sqlite3ValueSetStr(p, 0, "", 0, SQLITE_STATIC);
229901 if( bNull==0 ){
229908 if( pC==0 ){
229922 sqlite3_value *p = 0;
229935 rc = sessionSerializeValue(0, p, &nByte);
229949 memset(pC, 0, sizeof(SessionChange));
229957 nByte = 0;
229959 pC->aRecord[0] = SQLITE_INTEGER;
229964 sqlite3_value *p = 0;
229987 if( pSession->hook.xDepth(pSession->hook.pCtx)==0
229988 && pSession->bIndirect==0
229990 pC->bIndirect = 0;
230022 if( 0==sqlite3_strnicmp(pRet->zName, zName, nName+1) ) break;
230025 if( pRet==0 && pSession->bAutoAttach ){
230026 /* If there is a table-filter configured, invoke it. If it returns 0,
230028 if( pSession->xTableFilter==0
230037 assert( pRet!=0 );
230038 assert( 0==sqlite3_strnicmp(pRet->zName, zName, nName+1) );
230043 assert( rc==SQLITE_OK || pRet==0 );
230073 if( pSession->bEnable==0 ) continue;
230145 return 0;
230171 char *zRet = 0;
230173 for(i=0; i<nCol; i++){
230179 if( zRet==0 ) break;
230194 char *zRet = 0;
230195 int bHave = 0;
230197 for(i=0; i<nCol; i++){
230198 if( abPK[i]==0 ){
230205 if( zRet==0 ) break;
230209 if( bHave==0 ){
230210 assert( zRet==0 );
230211 zRet = sqlite3_mprintf("0");
230247 if( zStmt==0 ){
230251 rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
230255 pDiffCtx->nOldOff = 0;
230258 i64 iRowid = (pTab->bRowid ? sqlite3_column_int64(pStmt, 0) : 0);
230280 char *zRet = 0;
230281 for(ii=0; ii<pTab->nCol; ii++){
230301 if( zExpr2==0 ){
230310 if( zStmt==0 || z1==0 || z2==0 ){
230314 rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
230321 i64 iRowid = (pTab->bRowid ? sqlite3_column_int64(pStmt, 0) : 0);
230345 memset(&d, 0, sizeof(d));
230349 if( pzErrMsg ) *pzErrMsg = 0;
230351 char *zExpr = 0;
230359 if( pTo==0 ) goto diff_out;
230367 int bHasPk = 0;
230368 int bMismatch = 0;
230369 int nCol = 0; /* Columns in zFrom.zTbl */
230370 int bRowid = 0;
230371 u8 *abPK = 0;
230372 const char **azCol = 0;
230373 char *zDbExists = 0;
230377 if( zDbExists==0 ){
230380 sqlite3_stmt *pDbExists = 0;
230381 rc = sqlite3_prepare_v2(db, zDbExists, -1, &pDbExists, 0);
230390 if( rc==SQLITE_OK && nCol==0 ){
230391 rc = sessionTableInfo(0, db, zFrom, zTbl,
230392 &nCol, 0, 0, &azCol, 0, 0, &abPK,
230393 pSession->bImplicitPK ? &bRowid : 0
230398 if( nCol<=0 ){
230408 for(i=0; i<nCol; i++){
230422 if( bHasPk==0 ){
230472 *ppSession = 0;
230477 memset(pNew, 0, sizeof(sqlite3_session));
230507 for(i=0; i<pTab->nChange; i++){
230533 pHead = (sqlite3_session*)sqlite3_preupdate_hook(db, 0, 0);
230534 for(pp=&pHead; ALWAYS((*pp)!=0); pp=&((*pp)->pNext)){
230590 if( 0==sqlite3_strnicmp(pTab->zName, zName, nName+1) ) break;
230606 memset(pTab, 0, sizeof(SessionTable));
230630 sqlite3_int64 nByte = 0;
230631 rc = sessionSerializeValue(0, pVal, &nByte);
230634 rc = sessionSerializeValue(&p->aBuf[p->nBuf], pVal, 0);
230650 if( 0==sessionBufferGrow(p, 1, pRc) ){
230663 if( 0==sessionBufferGrow(p, 9, pRc) ){
230681 if( nBlob>0 && 0==sessionBufferGrow(p, nBlob, pRc) ){
230720 if( 0==sessionBufferGrow(p, nStr, pRc) ){
230724 if( zIn!=0 ){
230732 p->aBuf[p->nBuf] = 0x00;
230772 if( z || (eType==SQLITE_BLOB && nByte==0) ){
230788 ** 1 byte: SQLITE_UPDATE (0x17)
230806 int bPatchset, /* True for "patchset", 0 for "changeset" */
230812 SessionBuffer buf2 = {0,0,0}; /* Buffer to accumulate new.* record in */
230818 assert( abPK!=0 );
230821 for(i=0; i<sqlite3_column_count(pStmt); i++){
230822 int bChanged = 0;
230857 && (n==0 || 0==memcmp(&pCsr[nHdr], sqlite3_column_blob(pStmt, i), n))
230866 if( bChanged ) bNoop = 0;
230870 if( bPatchset==0 ){
230874 sessionAppendByte(pBuf, 0, &rc);
230883 sessionAppendByte(&buf2, 0, &rc);
230906 int bPatchset, /* True for "patchset", 0 for "changeset" */
230916 if( bPatchset==0 ){
230921 for(i=0; i<nCol; i++){
230926 case 0:
230928 assert( abPK[i]==0 );
230977 char *zSql = 0;
230982 SessionBuffer cols = {0, 0, 0};
230983 SessionBuffer nooptest = {0, 0, 0};
230984 SessionBuffer pkfield = {0, 0, 0};
230985 SessionBuffer pkvar = {0, 0, 0};
230989 if( 0==sqlite3_stricmp("sqlite_stat1", zTab) ){
230997 #if 0
231002 for(i=0; i<nCol; i++){
231025 if( zSql==0 ) rc = SQLITE_NOMEM;
231028 #if 0
231029 if( 0==sqlite3_stricmp("sqlite_stat1", zTab) ){
231034 if( zSql==0 ) rc = SQLITE_NOMEM;
231037 SessionBuffer buf = {0, 0, 0};
231044 for(i=0; i<nCol; i++){
231059 rc = sqlite3_prepare_v2(db, zSql, nSql, ppStmt, 0);
231087 for(i=0; i<nCol && rc==SQLITE_OK; i++){
231091 case 0:
231093 assert( abPK[i]==0 );
231169 ** to 0.
231181 SessionBuffer buf = {0,0,0}; /* Buffer in which to accumulate changeset */
231184 assert( xOutput==0 || (pnChangeset==0 && ppChangeset==0) );
231185 assert( xOutput!=0 || (pnChangeset!=0 && ppChangeset!=0) );
231190 if( xOutput==0 ){
231191 assert( pnChangeset!=0 && ppChangeset!=0 );
231192 *pnChangeset = 0;
231193 *ppChangeset = 0;
231197 rc = sqlite3_exec(pSession->db, "SAVEPOINT changeset", 0, 0, 0);
231206 sqlite3_stmt *pSel = 0; /* SELECT statement to query table pTab */
231222 rc = sessionSelectStmt(db, 0, pSession->zDb,
231228 for(i=0; i<pTab->nChange && rc==SQLITE_OK; i++){
231239 for(iCol=0; iCol<pTab->nCol; iCol++){
231243 assert( pTab->abPK!=0 );
231262 buf.nBuf = 0;
231276 if( xOutput==0 ){
231279 buf.aBuf = 0;
231280 }else if( buf.nBuf>0 ){
231286 sqlite3_exec(db, "RELEASE changeset", 0, 0, 0);
231305 if( pnChangeset==0 || ppChangeset==0 ) return SQLITE_MISUSE;
231306 rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset, ppChangeset);
231307 assert( rc || pnChangeset==0
231308 || pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize
231321 if( xOutput==0 ) return SQLITE_MISUSE;
231322 return sessionGenerateChangeset(pSession, 0, xOutput, pOut, 0, 0);
231333 if( xOutput==0 ) return SQLITE_MISUSE;
231334 return sessionGenerateChangeset(pSession, 1, xOutput, pOut, 0, 0);
231349 if( pnPatchset==0 || ppPatchset==0 ) return SQLITE_MISUSE;
231350 return sessionGenerateChangeset(pSession, 1, 0, 0, pnPatchset, ppPatchset);
231359 if( bEnable>=0 ){
231373 if( bIndirect>=0 ){
231386 int ret = 0;
231390 for(pTab=pSession->pTable; pTab && ret==0; pTab=pTab->pNext){
231391 ret = (pTab->nEntry>0);
231395 return (ret==0);
231413 if( iArg>=0 ){
231417 pSession->bEnableSize = (iArg!=0);
231426 if( iArg>=0 ){
231430 pSession->bImplicitPK = (iArg!=0);
231466 assert( xInput==0 || (pChangeset==0 && nChangeset==0) );
231469 *pp = 0;
231475 memset(pRet, 0, sizeof(sqlite3_changeset_iter));
231480 pRet->in.bEof = (xInput ? 0 : 1);
231497 return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset, 0, 0);
231506 return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset, bInvert, 0);
231517 return sessionChangesetStart(pp, xInput, pIn, 0, 0, 0, 0);
231526 return sessionChangesetStart(pp, xInput, pIn, 0, 0, bInvert, 0);
231536 assert( nMove>=0 );
231537 if( nMove>0 ){
231542 pIn->iCurrent = 0;
231560 if( pIn->bNoDiscard==0 ) sessionDiscardData(pIn);
231563 if( nNew==0 ){
231588 for(i=0; i<nCol; i++){
231612 u8 enc /* String encoding (0 for blobs) */
231619 if( aCopy==0 ) return SQLITE_NOMEM;
231659 assert( pbEmpty==0 || *pbEmpty==0 );
231661 for(i=0; i<nCol && rc==SQLITE_OK; i++){
231662 int eType = 0; /* Type of value (SQLITE_NULL, TEXT etc.) */
231663 if( abPK && abPK[i]==0 ) continue;
231670 assert( apOut[i]==0 );
231672 if( pbEmpty ) *pbEmpty = 0;
231673 apOut[i] = sqlite3ValueNew(0);
231686 if( nByte<0 || nByte>pIn->nData-pIn->iNext ){
231689 u8 enc = (eType==SQLITE_TEXT ? SQLITE_UTF8 : 0);
231731 int nCol = 0;
231732 int nRead = 0;
231744 if( nCol<0 || nCol>65536 ){
231778 int nByte = 0;
231780 for(i=0; rc==SQLITE_OK && i<nCol; i++){
231826 if( p->nCol>0 ){
231830 p->tblhdr.nBuf = 0;
231839 memset(p->tblhdr.aBuf, 0, iPK);
231845 if( p->apValue==0 ){
231846 p->abPK = 0;
231847 p->zTab = 0;
231850 p->zTab = p->abPK ? (char*)&p->abPK[p->nCol] : 0;
231875 assert( (paRec==0 && pnRec==0) || (paRec && pnRec) );
231876 assert( pbEmpty==0 || *pbEmpty==0 );
231883 for(i=0; i<p->nCol*2; i++){
231886 memset(p->apValue, 0, sizeof(sqlite3_value*)*p->nCol*2);
231915 if( p->zTab==0 || (p->bPatchset && p->bInvert) ){
231930 if( p->bPatchset==0 && op==SQLITE_UPDATE ){
231933 nVal = 0;
231934 for(i=0; i<p->nCol; i++) if( p->abPK[i] ) nVal++;
231947 if( p->op!=SQLITE_INSERT && (p->bPatchset==0 || p->op==SQLITE_DELETE) ){
231948 u8 *abPK = p->bPatchset ? p->abPK : 0;
231949 p->rc = sessionReadRecord(&p->in, p->nCol, abPK, apOld, 0);
231955 p->rc = sessionReadRecord(&p->in, p->nCol, 0, apNew, pbEmpty);
231964 for(i=0; i<p->nCol; i++){
231965 assert( p->bPatchset==0 || p->apValue[i]==0 );
231967 assert( p->apValue[i]==0 );
231969 if( p->apValue[i]==0 ) return (p->rc = SQLITE_CORRUPT_BKPT);
231970 p->apValue[i+p->nCol] = 0;
231985 if( p->bPatchset==0 && p->op==SQLITE_UPDATE){
231986 for(i=0; i<p->nCol; i++){
231987 if( p->abPK[i]==0 && p->apValue[i+p->nCol]==0 ){
231989 p->apValue[i] = 0;
232023 bEmpty = 0;
232038 return sessionChangesetNext(p, 0, 0, 0);
232097 if( iVal<0 || iVal>=pIter->nCol ){
232125 if( iVal<0 || iVal>=pIter->nCol ){
232159 if( iVal<0 || iVal>=pIter->nCol ){
232198 for(i=0; i<p->nCol*2; i++) sqlite3ValueFree(p->apValue[i]);
232216 int nCol = 0; /* Number of cols in current table */
232217 u8 *abPK = 0; /* PK array for current table */
232218 sqlite3_value **apVal = 0; /* Space for values for UPDATE inversion */
232219 SessionBuffer sPK = {0, 0, 0}; /* PK array for current table */
232222 memset(&sOut, 0, sizeof(SessionBuffer));
232226 *ppInverted = 0;
232227 *pnInverted = 0;
232254 sPK.nBuf = 0;
232262 apVal = 0;
232286 if( 0==apVal ){
232287 apVal = (sqlite3_value **)sqlite3_malloc64(sizeof(apVal[0])*nCol*2);
232288 if( 0==apVal ){
232292 memset(apVal, 0, sizeof(apVal[0])*nCol*2);
232301 rc = sessionReadRecord(pInput, nCol, 0, &apVal[0], 0);
232303 rc = sessionReadRecord(pInput, nCol, 0, &apVal[nCol], 0);
232309 for(iCol=0; iCol<nCol; iCol++){
232310 sqlite3_value *pVal = apVal[iCol + (abPK[iCol] ? 0 : nCol)];
232317 for(iCol=0; iCol<nCol; iCol++){
232318 sqlite3_value *pVal = (abPK[iCol] ? 0 : apVal[iCol]);
232322 for(iCol=0; iCol<nCol*2; iCol++){
232325 memset(apVal, 0, sizeof(apVal[0])*nCol*2);
232341 sOut.nBuf = 0;
232350 sOut.aBuf = 0;
232351 }else if( sOut.nBuf>0 && ALWAYS(xOutput!=0) ){
232375 memset(&sInput, 0, sizeof(SessionInput));
232379 return sessionChangesetInvert(&sInput, 0, 0, pnInverted, ppInverted);
232395 memset(&sInput, 0, sizeof(SessionInput));
232399 rc = sessionChangesetInvert(&sInput, xOutput, pOut, 0, 0);
232450 SessionUpdate *pUp = 0;
232455 if( p->aUpdateMask==0 ){
232457 if( p->aUpdateMask==0 ){
232463 memset(p->aUpdateMask, 0, nU32*sizeof(u32));
232465 for(ii=0; ii<pIter->nCol; ii++){
232477 int nUp = 0;
232481 if( 0==memcmp(p->aUpdateMask, (*pp)->aMask, nU32*sizeof(u32)) ){
232495 *pp = 0;
232502 if( pUp==0 ){
232504 int bStat1 = (sqlite3_stricmp(pIter->zTab, "sqlite_stat1")==0);
232506 if( pUp==0 ){
232512 memset(&buf, 0, sizeof(buf));
232521 for(ii=0; ii<pIter->nCol; ii++){
232522 if( p->abPK[ii]==0 && sessionChangesetNew(pIter, ii) ){
232534 for(ii=0; ii<pIter->nCol; ii++){
232535 if( p->abPK[ii] || (bPatchset==0 && sessionChangesetOld(pIter, ii)) ){
232538 assert( sqlite3_stricmp(p->azCol[ii], "idx")==0 );
232541 "WHEN length(?4)=0 AND typeof(?4)='blob' THEN NULL "
232555 rc = sqlite3_prepare_v2(p->db, zSql, buf.nBuf, &pUp->pStmt, 0);
232560 pUp = 0;
232570 assert( (rc==SQLITE_OK)==(pUp!=0) );
232574 *ppStmt = 0;
232590 p->pUp = 0;
232592 p->aUpdateMask = 0;
232605 ** Variable :5 (nCol+1) is a boolean. It should be set to 0 if we require
232620 SessionBuffer buf = {0, 0, 0};
232621 int nPk = 0;
232627 for(i=0; i<p->nCol; i++){
232644 for(i=0; i<p->nCol; i++){
232657 rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pDelete, 0);
232704 SessionBuffer buf = {0, 0, 0};
232709 for(i=0; i<p->nCol; i++){
232710 if( i!=0 ) sessionAppendStr(&buf, ", ", &rc);
232721 rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pInsert, 0);
232728 return sqlite3_prepare_v2(db, zSql, -1, pp, 0);
232742 "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, "
232749 "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END "
232766 /* COVERAGE: The (pVal->z==0) branch is never true using current versions
232770 if( (eType==SQLITE_TEXT || eType==SQLITE_BLOB) && pVal->z==0 ){
232785 ** statement pStmt. If parameter abPK is NULL, all values from 0 to (nCol-1)
232809 for(i=0; rc==SQLITE_OK && i<nCol; i++){
232811 sqlite3_value *pVal = 0;
232813 if( pVal==0 ){
232853 sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
232861 for(ii=0; rc==SQLITE_OK && ii<nCol; ii++){
232862 if( p->abPK[ii]==0 ){
232863 sqlite3_value *pVal = 0;
232865 sqlite3_bind_int(pSelect, ii+1+nCol, (pVal==0));
232898 if( p->bRebaseStarted==0 ){
232915 for(i=0; i<p->nCol; i++){
232916 sqlite3_value *pVal = 0;
232971 int res = 0; /* Value returned by conflict handler */
232977 sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
232999 pIter->pConflict = 0;
233082 assert( !pbReplace || *pbReplace==0 );
233084 sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
233095 ** * (pbRetry==0), or
233099 u8 *abPK = (pIter->bPatchset ? p->abPK : 0);
233102 rc = sqlite3_bind_int(p->pDelete, nCol+1, (pbRetry==0 || abPK));
233108 if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 && p->bIgnoreNoop==0 ){
233112 }else if( (rc&0xff)==SQLITE_CONSTRAINT ){
233114 SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, 0
233120 sqlite3_stmt *pUp = 0;
233121 int bPatchset = (pbRetry==0 || pIter->bPatchset);
233126 for(i=0; rc==SQLITE_OK && i<nCol; i++){
233129 if( p->abPK[i] || (bPatchset==0 && pOld) ){
233139 ** the result will be SQLITE_OK with 0 rows modified. */
233143 if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 ){
233152 }else if( (rc&0xff)==SQLITE_CONSTRAINT ){
233155 SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, 0
233173 rc = sessionBindRow(pIter, sqlite3changeset_new, nCol, 0, p->pInsert);
233180 if( (rc&0xff)==SQLITE_CONSTRAINT ){
233207 int bReplace = 0;
233208 int bRetry = 0;
233222 rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, 0, 0);
233232 rc = sqlite3_exec(db, "SAVEPOINT replace_op", 0, 0, 0);
233243 rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, 0, 0);
233246 rc = sqlite3_exec(db, "RELEASE replace_op", 0, 0, 0);
233268 sqlite3_changeset_iter *pIter2 = 0;
233270 memset(&pApply->constraints, 0, sizeof(SessionBuffer));
233273 &pIter2, 0, 0, cons.nBuf, cons.aBuf, pApply->bInvertConstraints, 1
233284 if( rc==SQLITE_OK ) memset(pIter2->apValue, 0, nByte);
233293 assert( pApply->bDeferConstraints || pApply->constraints.nBuf==0 );
233299 pApply->bDeferConstraints = 0;
233329 int schemaMismatch = 0;
233331 const char *zTab = 0; /* Name of current table */
233332 int nTab = 0; /* Result of sqlite3Strlen30(zTab) */
233337 assert( xConflict!=0 );
233342 db->aDb[0].pSchema->schema_cookie -= 32;
233346 memset(&sApply, 0, sizeof(sApply));
233350 if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
233351 rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0);
233354 rc = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 1", 0, 0, 0);
233361 sqlite3changeset_op(pIter, &zNew, &nCol, &op, 0);
233363 if( zTab==0 || sqlite3_strnicmp(zNew, zTab, nTab+1) ){
233377 sApply.pDelete = 0;
233378 sApply.pInsert = 0;
233379 sApply.pSelect = 0;
233380 sApply.nCol = 0;
233381 sApply.azCol = 0;
233382 sApply.abPK = 0;
233383 sApply.bStat1 = 0;
233385 sApply.bRebaseStarted = 0;
233386 sApply.bRowid = 0;
233387 memset(&sApply.constraints, 0, sizeof(SessionBuffer));
233392 schemaMismatch = (xFilter && (0==xFilter(pCtx, zNew)));
233395 if( zTab==0 ){
233402 int nMinCol = 0;
233405 sqlite3changeset_pk(pIter, &abPK, 0);
233406 rc = sessionTableInfo(0, db, "main", zNew,
233407 &sApply.nCol, 0, &zTab, &sApply.azCol, 0, 0,
233411 for(i=0; i<sApply.nCol; i++){
233415 if( sApply.nCol==0 ){
233429 else if( nCol<nMinCol || memcmp(sApply.abPK, abPK, nCol)!=0 ){
233437 if( 0==sqlite3_stricmp(zTab, "sqlite_stat1") ){
233449 sApply.bStat1 = 0;
233476 sqlite3_db_status(db, SQLITE_DBSTATUS_DEFERRED_FKS, &nFk, ¬Used, 0);
233477 if( nFk!=0 ){
233480 memset(&sIter, 0, sizeof(sIter));
233490 int rc2 = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 0", 0, 0, 0);
233494 if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
233496 rc = sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
233499 sqlite3_exec(db, "ROLLBACK TO changeset_apply", 0, 0, 0);
233500 sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
233504 assert( sApply.bRebase || sApply.rebase.nBuf==0 );
233505 if( rc==SQLITE_OK && bPatchset==0 && sApply.bRebase ){
233508 sApply.rebase.aBuf = 0;
233518 if( (flags & SQLITE_CHANGESETAPPLY_FKNOACTION) && savedFlag==0 ){
233521 db->aDb[0].pSchema->schema_cookie -= 32;
233550 int rc = sessionChangesetStart(&pIter, 0, 0, nChangeset, pChangeset, bInv, 1);
233582 db, nChangeset, pChangeset, xFilter, xConflict, pCtx, 0, 0, 0
233610 int rc = sessionChangesetStart(&pIter, xInput, pIn, 0, 0, bInverse, 1);
233634 db, xInput, pIn, xFilter, xConflict, pCtx, 0, 0, 0
233667 SessionChange *pNew = 0;
233669 assert( aRec!=0 );
233676 memset(pNew, 0, sizeof(SessionChange));
233680 if( bIndirect==0 || bRebase==0 ){
233687 for(i=0; i<pTab->nCol; i++){
233689 if( *pIn==0 ){
233690 *pOut++ = 0;
233691 }else if( pTab->abPK[i]==0 ){
233692 *pOut++ = 0xFF;
233707 if( pNew==0 ){
233715 memset(pNew, 0, nByte);
233720 for(i=0; i<pTab->nCol; i++){
233723 if( *a1==0xFF || (pTab->abPK[i]==0 && bIndirect) ){
233724 *pOut++ = 0xFF;
233725 }else if( *a2==0 ){
233763 assert( pNew==0 );
233778 memset(pNew, 0, sizeof(SessionChange));
233786 if( bPatchset==0 ) sessionSkipRecord(&a1, pTab->nCol);
233795 if( 0==sessionMergeUpdate(&aCsr, pTab, bPatchset, aExist, 0,aRec,0) ){
233797 pNew = 0;
233804 if( bPatchset==0 ){
233809 if( 0==sessionMergeUpdate(&aCsr, pTab, bPatchset, aRec, aExist,a1,a2) ){
233811 pNew = 0;
233839 ** return 0.
233848 for(ii=0; ii<pTab->nCol; ii++){
233849 u8 bPK = (ii < nCol) ? abPK[ii] : 0;
233850 if( pTab->abPK[ii]!=bPK ) return 0;
233854 return (pTab->nCol==nCol && 0==memcmp(abPK, pTab->abPK, nCol));
233867 int ii = 0;
233872 pOut->nBuf = 0;
233873 if( op==SQLITE_INSERT || (op==SQLITE_DELETE && pGrp->bPatch==0) ){
233876 if( rc==SQLITE_OK && pTab->pDfltStmt==0 ){
233924 int iOff = 0;
233925 if( pGrp->bPatch==0 ){
233926 for(ii=0; ii<nCol; ii++){
233930 for(ii=0; ii<(pTab->nCol-nCol); ii++){
233931 sessionAppendByte(pOut, 0x00, &rc);
233936 for(ii=0; ii<(pTab->nCol-nCol); ii++){
233937 sessionAppendByte(pOut, 0x00, &rc);
233961 SessionTable *pTab = 0;
233963 u8 *abPK = 0;
233964 int nCol = 0;
233966 *ppTab = 0;
233971 if( 0==sqlite3_strnicmp(pTab->zName, zTab, nTab+1) ) break;
233982 memset(pTab, 0, sizeof(SessionTable));
233990 pTab->nCol = 0;
233991 rc = sessionInitTable(0, pTab, pGrp->db, pGrp->zDb);
233993 assert( pTab->azCol==0 );
234026 int nCol = 0;
234027 int op = 0;
234028 int iHash = 0;
234029 int bIndirect = 0;
234030 SessionChange *pChange = 0;
234031 SessionChange *pExist = 0;
234032 SessionChange **pp = 0;
234033 SessionTable *pTab = 0;
234037 assert( nRec>0 );
234042 if( pGrp->pList==0 ){
234049 const char *zTab = 0;
234062 if( rc==SQLITE_OK && sessionGrowHash(0, pIter->bPatchset, pTab) ){
234073 int bPkOnly1 = 0;
234074 int bPkOnly2 = 0;
234117 while( SQLITE_ROW==(sessionChangesetNext(pIter, &aRec, &nRec, 0)) ){
234142 ** are both set to 0 before returning.
234152 SessionBuffer buf = {0, 0, 0};
234154 assert( xOutput==0 || (ppOut==0 && pnOut==0) );
234161 if( pTab->nEntry==0 ) continue;
234164 for(i=0; i<pTab->nChange; i++){
234172 buf.nBuf = 0;
234180 if( buf.nBuf>0 ) rc = xOutput(pOut, buf.aBuf, buf.nBuf);
234184 buf.aBuf = 0;
234199 if( p==0 ){
234202 memset(p, 0, sizeof(sqlite3_changegroup));
234224 if( pGrp->zDb==0 ){
234243 rc = sessionChangesetToHash(pIter, pGrp, 0);
234266 rc = sessionOneChangeToHash(pGrp, pIter, 0);
234280 return sessionChangegroupOutput(pGrp, 0, 0, pnData, ppData);
234296 rc = sessionChangesetToHash(pIter, pGrp, 0);
234310 return sessionChangegroupOutput(pGrp, xOutput, pOut, 0, 0);
234319 sessionDeleteTable(0, pGrp->pList);
234407 for(i=0; i<nCol; i++){
234410 if( *a1==0 || *a1==0xFF ){
234436 ** in the rebase buffer is set to "replaced" (type 0xFF). If this
234441 ** corresponding field in the rebase buffer is not "undefined" (0x00)
234442 ** or "replaced" (0xFF), the old.* value is replaced by the value
234454 int bData = 0;
234462 for(i=0; i<pIter->nCol; i++){
234465 if( pIter->abPK[i] || a2[0]==0 ){
234466 if( !pIter->abPK[i] && a1[0] ) bData = 1;
234469 }else if( a2[0]!=0xFF && a1[0] ){
234474 *pOut++ = '\0';
234481 for(i=0; i<pIter->nCol; i++){
234484 if( pIter->abPK[i] || a2[0]!=0xFF ){
234488 *pOut++ = '\0';
234510 ** pnOut are not NULL, then the two output parameters are set to 0 before
234522 u8 *aRec = 0;
234523 int nRec = 0;
234524 int bNew = 0;
234525 SessionTable *pTab = 0;
234526 SessionBuffer sOut = {0,0,0};
234529 SessionChange *pChange = 0;
234530 int bDone = 0;
234535 if( 0==sqlite3_stricmp(pTab->zName, zTab) ) break;
234537 bNew = 0;
234552 int iHash = sessionChangeHash(pTab, 0, aRec, pTab->nChange);
234555 if( sessionChangeEqual(pTab, 0, aRec, 0, pChange->aRecord) ){
234567 if( pChange->bIndirect==0 ){
234579 if( pChange->bIndirect==0 ){
234610 if( bDone==0 ){
234617 sOut.nBuf = 0;
234624 memset(&sOut, 0, sizeof(sOut));
234629 if( sOut.nBuf>0 ){
234635 sOut.aBuf = 0;
234650 if( pNew==0 ){
234653 memset(pNew, 0, sizeof(sqlite3_rebaser));
234666 sqlite3_changeset_iter *pIter = 0; /* Iterator opened on pData/nData */
234684 sqlite3_changeset_iter *pIter = 0; /* Iterator to skip through input */
234688 rc = sessionRebase(p, pIter, 0, 0, pnOut, ppOut);
234705 sqlite3_changeset_iter *pIter = 0; /* Iterator to skip through input */
234709 rc = sessionRebase(p, pIter, xOutput, pOut, 0, 0);
234721 sessionDeleteTable(0, p->grp.pList);
234735 if( *pInt>0 ){
234814 #if 0
234876 ** created with the "columnsize=0" option.
234895 ** 0 is returned. Otherwise, this function returns the number of tokens in
234906 ** (i.e. if it is a contentless table), then this API always returns 0.
235012 ** iCol>=0;
235030 ** i.e. all those in column 0, sorted by offset, followed by those in
235046 ** iCol>=0;
235081 ** tables, this includes any embedded 0x00 and trailing data.
235093 ** includes any embedded 0x00 and trailing data.
235122 ** to NULL and 0, respectively. However, if the fts5_locale() function
235255 ** on a columnsize=0 database.
235262 ** which case nLocale is always 0) to indicate that the tokenizer should
235274 ** normally be set to 0. The exception is if the tokenizer supports
235291 ** for the current request. If pLocale and nLocale are both 0, then the
235374 ** xToken(pCtx, 0, "i", 1, 0, 1);
235375 ** xToken(pCtx, 0, "won", 3, 2, 5);
235376 ** xToken(pCtx, 0, "first", 5, 6, 11);
235378 ** xToken(pCtx, 0, "place", 5, 12, 17);
235468 #define FTS5_TOKENIZE_QUERY 0x0001
235469 #define FTS5_TOKENIZE_PREFIX 0x0002
235470 #define FTS5_TOKENIZE_DOCUMENT 0x0004
235471 #define FTS5_TOKENIZE_AUX 0x0008
235475 #define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */
235538 #if 0
235578 # define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0])))
235588 # define NEVER(X) (0)
235590 # define ALWAYS(X) ((X)?1:(assert(0),0))
235591 # define NEVER(X) ((X)?(assert(0),1):0)
235603 # define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
235617 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
235619 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
235626 # define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
235683 #define fts5Memcmp(s1, s2, n) ((n)<=0 ? 0 : memcmp((s1), (s2), (n)))
235783 int bContentlessDelete; /* "contentless_delete=" option (dflt==0) */
235784 int bContentlessUnindexed; /* "contentless_unindexed=" option (dflt=0) */
235788 int bTokendata; /* "tokendata=" option value (dflt==0) */
235789 int bLocale; /* "locale=" option value (dflt==0) */
235824 #define FTS5_CONTENT_NORMAL 0
235829 #define FTS5_DETAIL_FULL 0
235833 #define FTS5_PATTERN_NONE 0
235900 (u32)((pBuf)->n) + (u32)(nn) <= (u32)((pBuf)->nSpace) ? 0 : \
235908 #define FTS5_POS2COLUMN(iPos) (int)((iPos >> 32) & 0x7FFFFFFF)
235909 #define FTS5_POS2OFFSET(iPos) (int)(iPos & 0x7FFFFFFF)
235951 /* Bucket of terms object used by the integrity-check in offsets=0 mode. */
235981 #define FTS5INDEX_QUERY_PREFIX 0x0001 /* Prefix query */
235982 #define FTS5INDEX_QUERY_DESC 0x0002 /* Docs in descending rowid order */
235983 #define FTS5INDEX_QUERY_TEST_NOIDX 0x0004 /* Do not use prefix index */
235984 #define FTS5INDEX_QUERY_SCAN 0x0008 /* Scan query (fts5vocab) */
235989 #define FTS5INDEX_QUERY_SKIPEMPTY 0x0010
235990 #define FTS5INDEX_QUERY_NOOUTPUT 0x0020
235991 #define FTS5INDEX_QUERY_SKIPHASH 0x0040
235992 #define FTS5INDEX_QUERY_NOTOKENDATA 0x0080
235993 #define FTS5INDEX_QUERY_SCANONETERM 0x0100
236016 ** buffer, or 0 if there are less than nChar characters in total.
236174 if( nVal & 0x80 ){ \
236280 #define FTS5_STMT_SCAN_ASC 0 /* SELECT rowid, * FROM ... ORDER BY 1 ASC */
236361 ** rc==SQLITE_OK && 0==sqlite3Fts5ExprEof(pExpr);
236681 #define fts5YYDYNSTACK 0
236702 #define fts5YY_NLOOKAHEAD ((int)(sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0])))
236719 #if fts5YYSTACKDEPTH<=0 || fts5YYDYNSTACK
236722 # define fts5YYGROWABLESTACK 0
236727 #if fts5YYSTACKDEPTH<=0
236741 ** 0 <= N <= fts5YY_MAX_SHIFT Shift N. That is, push the lookahead
236785 /* 0 */ 81, 20, 96, 6, 28, 99, 98, 26, 26, 18,
236798 /* 0 */ 16, 17, 18, 19, 20, 22, 22, 24, 24, 17,
236805 /* 70 */ 24, 3, 1, 2, 3, 1, 2, 3, 0, 1,
236813 #define fts5YY_SHIFT_MIN (0)
236816 /* 0 */ 44, 44, 44, 44, 44, 44, 51, 77, 43, 12,
236825 /* 0 */ -16, -8, 0, 9, 17, 25, 46, -17, -17, 37,
236829 /* 0 */ 80, 80, 80, 80, 80, 80, 95, 80, 80, 105,
236901 static FILE *fts5yyTraceFILE = 0;
236902 static char *fts5yyTracePrompt = 0;
236926 if( fts5yyTraceFILE==0 ) fts5yyTracePrompt = 0;
236927 else if( fts5yyTracePrompt==0 ) fts5yyTraceFILE = 0;
236935 /* 0 */ "$",
236969 /* 0 */ "input ::= expr",
237004 ** of errors. Return 0 on success.
237015 pNew = fts5YYREALLOC(0, newSize*sizeof(pNew[0]));
237016 if( pNew==0 ) return 1;
237017 memcpy(pNew, p->fts5yystack, oldSize*sizeof(pNew[0]));
237019 pNew = fts5YYREALLOC(p->fts5yystack, newSize*sizeof(pNew[0]));
237020 if( pNew==0 ) return 1;
237031 return 0;
237057 fts5yypParser->fts5yyhwm = 0;
237065 fts5yypParser->fts5yystack[0].stateno = 0;
237066 fts5yypParser->fts5yystack[0].major = 0;
237162 assert( pParser->fts5yytos!=0 );
237217 if( p==0 ) return;
237254 int nMissed = 0;
237255 for(stateno=0; stateno<fts5YYNSTATE; stateno++){
237257 for(iLookAhead=0; iLookAhead<fts5YYNFTS5TOKEN; iLookAhead++){
237259 if( fts5yycoverage[stateno][iLookAhead]==0 ) nMissed++;
237288 assert( i>=0 );
237298 assert( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0]) );
237300 if( iFallback!=0 ){
237307 assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
237315 assert( j<(int)(sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0])) );
237316 if( fts5yy_lookahead[j]==fts5YYWILDCARD && iLookAhead>0 ){
237330 assert( i>=0 && i<(int)(sizeof(fts5yy_action)/sizeof(fts5yy_action[0])) );
237356 if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
237360 assert( i>=0 && i<fts5YY_ACTTAB_COUNT );
237448 16, /* (0) input ::= expr */
237481 -1, /* (0) input ::= expr */
237503 0, /* (22) neardist_opt ::= */
237508 0, /* (27) star_opt ::= */
237542 ** case 0:
237550 case 0: /* input ::= expr */
237551 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
237563 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
237565 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
237569 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
237575 …yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
237580 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
237582 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
237586 …lite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
237592 …qlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
237598 …lite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
237614 {fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
237615 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
237619 …4 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
237625 …fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5y…
237627 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
237631 …fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5y…
237637 { fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
237638 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
237642 sqlite3Fts5ParseSetCaret(fts5yymsp[0].minor.fts5yy53);
237643 fts5yymsp[-1].minor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
237656 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
237658 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
237662 …5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
237667 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
237670 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
237674 …rm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
237680 …ts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0…
237685 { fts5yymsp[0].minor.fts5yy4 = 1; }
237688 { fts5yymsp[1].minor.fts5yy4 = 0; }
237694 assert( fts5yyruleno<sizeof(fts5yyRuleInfoLhs)/sizeof(fts5yyRuleInfoLhs[0]) );
237816 int fts5yyerrorhit = 0; /* True if fts5yymajor has invoked an error */
237822 assert( fts5yypParser->fts5yytos!=0 );
237824 fts5yyendofinput = (fts5yymajor==0);
237847 assert( fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) );
237867 if( fts5yyRuleInfoNRhs[fts5yyruleno]==0 ){
237924 if( fts5yypParser->fts5yyerrcnt<0 ){
237944 if( fts5yypParser->fts5yytos <= fts5yypParser->fts5yystack || fts5yymajor==0 ){
237980 if( fts5yypParser->fts5yyerrcnt<=0 ){
238012 ** 0 if iToken has no fallback.
238016 assert( iToken<(int)(sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])) );
238020 return 0;
238053 ** (rc==SQLITE_OK && 0==fts5CInstIterEof(&iter);
238088 if( pIter->iStart<0 ){
238116 memset(pIter, 0, sizeof(CInstIter));
238155 ** negative, everything up until the first '\0' is appended to the output.
238167 if( n<0 ) n = (int)strlen(z);
238169 if( p->zOut==0 ) *pRc = SQLITE_NOMEM;
238193 if( p->iRangeEnd>=0 ){
238203 && (iPos<=p->iter.iStart || p->iter.iStart<0)
238207 p->bOpen = 0;
238215 if( iPos==p->iter.iStart && p->bOpen==0 ){
238223 if( p->bOpen==0 ){
238224 assert( p->iRangeEnd>=0 );
238238 if( p->iter.iStart>=0 && iPos>=p->iter.iStart ){
238243 p->bOpen = 0;
238273 iCol = sqlite3_value_int(apVal[0]);
238274 memset(&ctx, 0, sizeof(HighlightContext));
238283 const char *pLoc = 0; /* Locale of column iCol */
238284 int nLoc = 0; /* Size of pLoc in bytes */
238338 if( aNew==0 ) return SQLITE_NOMEM;
238364 if( (tflags & FTS5_TOKEN_COLOCATED)==0 ){
238366 if( p->iPos>0 ){
238368 char c = 0;
238369 for(i=iStartOff-1; i>=0; i--){
238377 rc = fts5SentenceFinderAdd(p, 0);
238397 int ip = 0;
238398 int ic = 0;
238399 int iOff = 0;
238402 int nScore = 0;
238403 int iLast = 0;
238407 for(i=0; i<nInst && rc==SQLITE_OK; i++){
238412 if( iFirst<0 ) iFirst = iOff;
238421 if( iAdj<0 ) iAdj = 0;
238453 int nInst = 0; /* Number of instance matches this row */
238458 int iBestStart = 0; /* First token of best snippet */
238459 int nBestScore = 0; /* Score of best snippet */
238460 int nColSize = 0; /* Total size of iBestCol in tokens */
238471 memset(&ctx, 0, sizeof(HighlightContext));
238472 iCol = sqlite3_value_int(apVal[0]);
238479 iBestCol = (iCol>=0 ? iCol : 0);
238482 if( aSeen==0 ){
238489 memset(&sFinder, 0, sizeof(Fts5SFinder));
238490 for(i=0; i<nCol; i++){
238491 if( iCol<0 || iCol==i ){
238492 const char *pLoc = 0; /* Locale of column iCol */
238493 int nLoc = 0; /* Size of pLoc in bytes */
238497 sFinder.iPos = 0;
238498 sFinder.nFirst = 0;
238510 for(ii=0; rc==SQLITE_OK && ii<nInst; ii++){
238520 memset(aSeen, 0, nPhrase);
238532 for(jj=0; jj<(sFinder.nFirst-1); jj++){
238537 memset(aSeen, 0, nPhrase);
238539 sFinder.aFirst[jj], nToken, &nScore, 0
238542 nScore += (sFinder.aFirst[jj]==0 ? 120 : 100);
238558 if( rc==SQLITE_OK && nColSize==0 ){
238562 const char *pLoc = 0; /* Locale of column iBestCol */
238563 int nLoc = 0; /* Bytes in pLoc */
238572 if( iBestStart>0 ){
238578 while( ctx.iter.iStart>=0 && ctx.iter.iStart<iBestStart && rc==SQLITE_OK ){
238651 p = (Fts5Bm25Data*)pApi->xGetAuxdata(pFts, 0);
238652 if( p==0 ){
238654 sqlite3_int64 nRow = 0; /* Number of rows in table */
238655 sqlite3_int64 nToken = 0; /* Number of tokens in table */
238663 if( p==0 ){
238666 memset(p, 0, (size_t)nByte);
238674 assert( rc!=SQLITE_OK || nRow>0 );
238679 for(i=0; rc==SQLITE_OK && i<nPhrase; i++){
238680 sqlite3_int64 nHit = 0;
238707 if( rc!=SQLITE_OK ) p = 0;
238729 int nInst = 0; /* Value returned by xInstCount() */
238731 double *aFreq = 0; /* Array of phrase freq. for current row */
238738 memset(aFreq, 0, sizeof(double) * pData->nPhrase);
238741 for(i=0; rc==SQLITE_OK && i<nInst; i++){
238760 for(i=0; i<pData->nPhrase; i++){
238782 int iCol = 0;
238783 int eType = 0;
238785 const char *zLocale = 0;
238786 int nLocale = 0;
238797 eType = sqlite3_value_numeric_type(apVal[0]);
238804 iCol = sqlite3_value_int(apVal[0]);
238805 if( iCol<0 || iCol>=pApi->xColumnCount(pFts) ){
238826 { "snippet", 0, fts5SnippetFunction, 0 },
238827 { "highlight", 0, fts5HighlightFunction, 0 },
238828 { "bm25", 0, fts5Bm25Function, 0 },
238829 { "fts5_get_locale", 0, fts5GetLocaleFunction, 0 },
238834 for(i=0; rc==SQLITE_OK && i<ArraySize(aBuiltin); i++){
238871 if( pNew==0 ){
238879 return 0;
238893 aBuf[0] = (iVal>>24) & 0x00FF;
238894 aBuf[1] = (iVal>>16) & 0x00FF;
238895 aBuf[2] = (iVal>> 8) & 0x00FF;
238896 aBuf[3] = (iVal>> 0) & 0x00FF;
238900 return (int)((((u32)aBuf[0])<<24) + (aBuf[1]<<16) + (aBuf[2]<<8) + aBuf[3]);
238916 assert( pBuf->p!=0 );
238924 ** ensures that the byte following the buffer data is set to 0x00, even
238942 ** following the buffer data is set to 0x00, even though this byte is not
238957 if( zTmp==0 ){
238967 char *zRet = 0;
238973 if( zRet==0 ){
238986 memset(pBuf, 0, sizeof(Fts5Buffer));
238994 pBuf->n = 0;
239008 pBuf->n = 0;
239018 assert( a!=0 || i==0 );
239026 assert( a!=0 );
239029 if( iVal==0 ){
239031 return 0;
239035 assert( iOff>=0 );
239042 *piOff = iOff + ((iVal-2) & 0x7FFFFFFF);
239044 *piOff = (iOff & (i64)0x7FFFFFFF<<32)+((iOff + (iVal-2)) & 0x7FFFFFFF);
239048 return 0;
239068 memset(pIter, 0, sizeof(*pIter));
239087 static const i64 colmask = ((i64)(0x7FFFFFFF)) << 32;
239103 int rc = 0; /* Initialized only to suppress erroneous warning from Clang */
239110 void *pRet = 0;
239113 if( pRet==0 ){
239114 if( nByte>0 ) *pRc = SQLITE_NOMEM;
239116 memset(pRet, 0, (size_t)nByte);
239131 char *zRet = 0;
239133 if( nIn<0 ){
239139 zRet[nIn] = '\0';
239155 ** * The underscore character "_" (0x5F).
239156 ** * The unicode "substitute" character (0x1A).
239160 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 .. 0x0F */
239161 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* 0x10 .. 0x1F */
239162 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 .. 0x2F */
239163 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0x30 .. 0x3F */
239164 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 .. 0x4F */
239165 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x50 .. 0x5F */
239166 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 .. 0x6F */
239167 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70 .. 0x7F */
239170 return (t & 0x80) || aBareword[(int)t];
239201 *pbPresent = 0;
239211 for(i=nTerm-1; i>=0; i--){
239220 && memcmp(pEntry->pTerm, pTerm, nTerm)==0
239227 if( pEntry==0 ){
239246 for(i=0; i<ArraySize(p->apHash); i++){
239316 if( p==pIn ) p = 0;
239321 return (a>='0' && a<='9');
239330 if( sqlite3_strnicmp("null", p, 4)==0 ){
239333 p = 0;
239343 || (*p>='0' && *p<='9')
239347 if( *p=='\'' && 0==((p-pIn)%2) ){
239350 p = 0;
239353 p = 0;
239365 if( *p==0 ) p = 0;
239381 if( p==pIn ) p = 0;
239405 int iOut = 0;
239406 q = z[0];
239430 z[iOut] = '\0';
239450 assert( 0==fts5_iswhitespace(z[0]) );
239451 quote = z[0];
239473 for(i=0; aEnum[i].zName; i++){
239474 if( sqlite3_strnicmp(aEnum[i].zName, zEnum, nEnum)==0 ){
239475 if( iVal>=0 ) return SQLITE_ERROR;
239481 return iVal<0 ? SQLITE_ERROR : SQLITE_OK;
239502 if( sqlite3_strnicmp("prefix", zCmd, nCmd)==0 ){
239506 if( pConfig->aPrefix==0 ){
239513 int nPre = 0;
239515 while( p[0]==' ' ) p++;
239516 if( bFirst==0 && p[0]==',' ){
239518 while( p[0]==' ' ) p++;
239519 }else if( p[0]=='\0' ){
239522 if( p[0]<'0' || p[0]>'9' ){
239536 while( p[0]>='0' && p[0]<='9' && nPre<1000 ){
239537 nPre = nPre*10 + (p[0] - '0');
239541 if( nPre<=0 || nPre>=1000 ){
239549 bFirst = 0;
239555 if( sqlite3_strnicmp("tokenize", zCmd, nCmd)==0 ){
239566 for(nArg=0; p && *p; nArg++){
239581 if( p==0 ){
239587 azArg = 0;
239596 if( sqlite3_strnicmp("content", zCmd, nCmd)==0 ){
239601 if( zArg[0] ){
239611 if( sqlite3_strnicmp("contentless_delete", zCmd, nCmd)==0 ){
239612 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
239616 pConfig->bContentlessDelete = (zArg[0]=='1');
239621 if( sqlite3_strnicmp("contentless_unindexed", zCmd, nCmd)==0 ){
239622 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
239626 pConfig->bContentlessUnindexed = (zArg[0]=='1');
239631 if( sqlite3_strnicmp("content_rowid", zCmd, nCmd)==0 ){
239641 if( sqlite3_strnicmp("columnsize", zCmd, nCmd)==0 ){
239642 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
239646 pConfig->bColumnsize = (zArg[0]=='1');
239651 if( sqlite3_strnicmp("locale", zCmd, nCmd)==0 ){
239652 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
239656 pConfig->bLocale = (zArg[0]=='1');
239661 if( sqlite3_strnicmp("detail", zCmd, nCmd)==0 ){
239666 { 0, 0 }
239675 if( sqlite3_strnicmp("tokendata", zCmd, nCmd)==0 ){
239676 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
239680 pConfig->bTokendata = (zArg[0]=='1');
239710 const char *zRet = 0;
239716 *pbQuoted = 0;
239717 *pzOut = 0;
239719 if( zOut==0 ){
239723 if( fts5_isopenquote(zOut[0]) ){
239730 zOut[zRet-zIn] = '\0';
239735 if( zRet==0 ){
239752 if( 0==sqlite3_stricmp(zCol, FTS5_RANK_NAME)
239753 || 0==sqlite3_stricmp(zCol, FTS5_ROWID_NAME)
239758 if( 0==sqlite3_stricmp(zArg, "unindexed") ){
239777 Fts5Buffer buf = {0, 0, 0};
239785 for(i=0; i<p->nCol; i++){
239796 for(i=0; i<p->nCol; i++){
239797 if( p->abUnindexed[i]==0 ){
239805 assert( p->zContentExprlist==0 );
239834 int bUnindexed = 0; /* True if there are one or more UNINDEXED */
239837 if( pRet==0 ) return SQLITE_NOMEM;
239838 memset(pRet, 0, sizeof(Fts5Config));
239845 pRet->abUnindexed = pRet->azCol ? (u8*)&pRet->azCol[nArg] : 0;
239853 if( rc==SQLITE_OK && sqlite3_stricmp(pRet->zName, FTS5_RANK_NAME)==0 ){
239862 char *zOne = 0;
239863 char *zTwo = 0;
239864 int bOption = 0;
239865 int bMustBeCol = 0;
239871 assert( zOne!=0 );
239873 if( bMustBeCol ) z = 0;
239876 if( z && z[0] ){
239879 if( z && z[0] ) z = 0;
239883 if( z==0 ){
239895 zOne = 0;
239915 /* We only allow contentless_delete=1 if columnsize=0 is not present.
239919 if( rc==SQLITE_OK && pRet->bContentlessDelete && pRet->bColumnsize==0 ){
239921 "contentless_delete=1 is incompatible with columnsize=0"
239940 if( rc==SQLITE_OK && pRet->zContent==0 ){
239941 const char *zTail = 0;
239961 if( rc==SQLITE_OK && pRet->zContentRowid==0 ){
239972 *ppOut = 0;
239993 for(i=0; i<pConfig->nCol; i++){
240018 for(i=0; zSql && i<pConfig->nCol; i++){
240019 const char *zSep = (i==0?"":", ");
240046 ** int iPos // Position of token in input (first token is 0)
240067 if( pConfig->t.pTok==0 ){
240098 if( p==0 || *p==')' ) break;
240100 p = 0;
240125 char *zRank = 0;
240126 char *zRankArgs = 0;
240129 *pzRank = 0;
240130 *pzRankArgs = 0;
240132 if( p==0 ){
240157 if( p==0 ){
240169 assert( zRankArgs==0 );
240185 if( 0==sqlite3_stricmp(zKey, "pgsz") ){
240186 int pgsz = 0;
240197 else if( 0==sqlite3_stricmp(zKey, "hashsize") ){
240202 if( nHashSize<=0 ){
240209 else if( 0==sqlite3_stricmp(zKey, "automerge") ){
240214 if( nAutomerge<0 || nAutomerge>64 ){
240222 else if( 0==sqlite3_stricmp(zKey, "usermerge") ){
240234 else if( 0==sqlite3_stricmp(zKey, "crisismerge") ){
240239 if( nCrisisMerge<0 ){
240248 else if( 0==sqlite3_stricmp(zKey, "deletemerge") ){
240255 if( nVal<0 ) nVal = FTS5_DEFAULT_DELETE_AUTOMERGE;
240256 if( nVal>100 ) nVal = 0;
240260 else if( 0==sqlite3_stricmp(zKey, "rank") ){
240276 else if( 0==sqlite3_stricmp(zKey, "secure-delete") ){
240281 if( bVal<0 ){
240284 pConfig->bSecureDelete = (bVal ? 1 : 0);
240288 else if( 0==sqlite3_stricmp(zKey, "insttoken") ){
240293 if( bVal<0 ){
240296 pConfig->bPrefixInsttoken = (bVal ? 1 : 0);
240311 sqlite3_stmt *p = 0;
240313 int iVersion = 0;
240325 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &p, 0);
240329 assert( rc==SQLITE_OK || p==0 );
240332 const char *zK = (const char*)sqlite3_column_text(p, 0);
240334 if( 0==sqlite3_stricmp(zK, "version") ){
240337 int bDummy = 0;
240370 char *zMsg = 0;
240375 assert( *pConfig->pzErrmsg==0 );
240410 ** All token types in the generated fts5parse.h file are greater than 0.
240412 #define FTS5_EOF 0
240414 #define FTS5_LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
240450 ** An expression node with eType==0 may also exist. It always matches zero
240455 ** Distance from this node to furthest leaf. This is always 0 for nodes
240553 if( p->eType==FTS5_TERM || p->eType==FTS5_STRING || p->eType==0 ){
240554 assert( p->iHeight==0 );
240557 int iMaxChild = 0;
240558 for(ii=0; ii<p->nChild; ii++){
240575 assert( pParse->zErr==0 );
240613 case '\0': tok = FTS5_EOF; break;
240620 if( z2[0]=='"' ){
240622 if( z2[0]!='"' ) break;
240624 if( z2[0]=='\0' ){
240635 if( sqlite3Fts5IsBareword(z[0])==0 ){
240642 if( pToken->n==2 && memcmp(pToken->p, "OR", 2)==0 ) tok = FTS5_OR;
240643 if( pToken->n==3 && memcmp(pToken->p, "NOT", 3)==0 ) tok = FTS5_NOT;
240644 if( pToken->n==3 && memcmp(pToken->p, "AND", 3)==0 ) tok = FTS5_AND;
240671 *ppNew = 0;
240672 *pzErr = 0;
240673 memset(&sParse, 0, sizeof(sParse));
240676 if( pEngine==0 ){ return SQLITE_NOMEM; }
240695 pColset->aiCol[0] = iCol;
240700 assert( sParse.rc!=SQLITE_OK || sParse.zErr==0 );
240703 if( pNew==0 ){
240708 pNew->pIndex = 0;
240712 pNew->bDesc = 0;
240713 sParse.apPhrase = 0;
240720 if( 0==*pzErr ){
240733 int nRet = 0;
240735 for(ii=0; ii<nByte; ii++){
240736 if( (z[ii] & 0xC0)!=0x80 ) nRet++;
240756 if( zExpr==0 ){
240760 int iOut = 0;
240761 int i = 0;
240762 int iFirst = 0;
240764 if( bGlob==0 ){
240765 aSpec[0] = '_';
240767 aSpec[2] = 0;
240769 aSpec[0] = '*';
240776 || zText[i]==aSpec[0] || zText[i]==aSpec[1] || zText[i]==aSpec[2]
240798 if( iOut>0 ){
240799 int bAnd = 0;
240806 zExpr[iOut] = '\0';
240809 *pp = 0;
240823 for(i=0; i<p->nChild; i++){
240844 memset(&sParse, 0, sizeof(sParse));
240850 p1->pRoot = sqlite3Fts5ParseNode(&sParse, FTS5_AND, p1->pRoot, p2->pRoot,0);
240851 p2->pRoot = 0;
240857 if( ap==0 ){
240862 for(i=0; i<p2->nPhrase; i++){
240883 i64 iRet = 0;
240884 int bRetValid = 0;
240889 assert( bDesc==0 || bDesc==1 );
240891 if( 0==sqlite3Fts5IterEof(p->pIter) ){
240893 if( bRetValid==0 || (bDesc!=(iRowid<iRet)) ){
240900 if( pbEof && bRetValid==0 ) *pbEof = 1;
240915 int nIter = 0;
240923 if( sqlite3Fts5IterEof(pIter)==0 && pIter->iRowid==iRowid ){
240924 if( pIter->nData==0 ) continue;
240928 if( aNew==0 ){
240938 assert( aIter[nIter].bEof==0 );
240944 *pa = (u8*)aIter[0].a;
240945 *pn = aIter[0].n;
240947 Fts5PoslistWriter writer = {0};
240953 for(i=0; i<nIter; i++){
240954 if( aIter[i].bEof==0 ){
240995 Fts5PoslistWriter writer = {0};
241000 int bFirst = pPhrase->aTerm[0].bFirst;
241011 memset(aIter, 0, sizeof(Fts5PoslistReader) * pPhrase->nTerm);
241014 for(i=0; i<pPhrase->nTerm; i++){
241016 int n = 0;
241017 int bFlag = 0;
241018 u8 *a = 0;
241020 Fts5Buffer buf = {0, 0, 0};
241038 i64 iPos = aIter[0].iPos;
241041 for(i=0; i<pPhrase->nTerm; i++){
241045 bMatch = 0;
241052 }while( bMatch==0 );
241055 if( bFirst==0 || FTS5_POS2OFFSET(iPos)==0 ){
241060 for(i=0; i<pPhrase->nTerm; i++){
241066 *pbMatch = (pPhrase->poslist.n>0);
241067 for(i=0; i<pPhrase->nTerm; i++){
241097 memset(p, 0, sizeof(Fts5LookaheadReader));
241145 memset(aStatic, 0, sizeof(aStatic));
241149 return 0;
241160 for(i=0; i<pNear->nPhrase; i++){
241163 pPoslist->n = 0;
241174 iMax = a[0].reader.iPos;
241177 for(i=0; i<pNear->nPhrase; i++){
241181 bMatch = 0;
241188 }while( bMatch==0 );
241191 for(i=0; i<pNear->nPhrase; i++){
241194 if( a[i].pOut->n==0 || iPos!=pWriter->iPrev ){
241199 iAdv = 0;
241200 iMin = a[0].reader.iLookahead;
241201 for(i=0; i<pNear->nPhrase; i++){
241211 int bRet = a[0].pOut->n>0;
241238 if( (bDesc==0 && iLast>iRowid) || (bDesc && iLast<iRowid) ){
241246 assert( (bDesc==0 && iRowid>=iLast) || (bDesc==1 && iRowid<=iLast) );
241250 return 0;
241262 int bEof = 0;
241265 if( sqlite3Fts5IterEof(p->pIter)==0 ){
241267 if( (bDesc==0 && iLast>iRowid) || (bDesc && iLast<iRowid) ){
241293 Fts5ExprPhrase *pPhrase = pNear->apPhrase[0];
241294 pPhrase->poslist.n = 0;
241295 for(pTerm=&pPhrase->aTerm[0]; pTerm; pTerm=pTerm->pSynonym){
241297 if( sqlite3Fts5IterEof(pIter)==0 ){
241298 if( pIter->iRowid==pNode->iRowid && pIter->nData>0 ){
241310 for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){
241312 if( pPhrase->nTerm>1 || pPhrase->aTerm[0].pSynonym
241313 || pNear->pColset || pPhrase->aTerm[0].bFirst
241315 int bMatch = 0;
241317 if( bMatch==0 ) break;
241319 Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
241328 return 0;
241349 assert( pNode->bNomatch==0 );
241350 for(i=0; i<pNear->nPhrase; i++){
241352 if( pPhrase->nTerm==0 ){
241357 for(j=0; j<pPhrase->nTerm; j++){
241360 int bHit = 0;
241366 p->pIter = 0;
241370 (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) |
241371 (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0),
241375 assert( (rc==SQLITE_OK)==(p->pIter!=0) );
241377 if( 0==sqlite3Fts5IterEof(p->pIter) ){
241382 if( bHit==0 ){
241390 pNode->bEof = 0;
241409 assert( pExpr->bDesc==0 || pExpr->bDesc==1 );
241410 if( pExpr->bDesc==0 ){
241422 pNode->bNomatch = 0;
241423 for(i=0; i<pNode->nChild; i++){
241432 for(i=0; i<pNear->nPhrase; i++){
241434 pPhrase->poslist.n = 0;
241438 for(i=0; i<pNode->nChild; i++){
241484 Fts5ExprPhrase *pLeft = pNear->apPhrase[0];
241493 || pNear->apPhrase[0]->nTerm>1
241494 || pNear->apPhrase[0]->aTerm[0].pSynonym
241495 || pNear->apPhrase[0]->aTerm[0].bFirst
241502 if( pLeft->aTerm[0].pSynonym ){
241503 iLast = fts5ExprSynonymRowid(&pLeft->aTerm[0], bDesc, 0);
241505 iLast = pLeft->aTerm[0].pIter->iRowid;
241510 for(i=0; i<pNear->nPhrase; i++){
241512 for(j=0; j<pPhrase->nTerm; j++){
241515 i64 iRowid = fts5ExprSynonymRowid(pTerm, bDesc, 0);
241517 bMatch = 0;
241519 pNode->bNomatch = 0;
241526 bMatch = 0;
241533 }while( bMatch==0 );
241536 pNode->bNomatch = ((0==fts5ExprNearTest(&rc, pExpr, pNode)) && rc==SQLITE_OK);
241537 assert( pNode->bEof==0 || pNode->bNomatch==0 );
241555 Fts5ExprTerm *pTerm = &pNode->pNear->apPhrase[0]->aTerm[0];
241558 pNode->bNomatch = 0;
241564 i64 iRowid = fts5ExprSynonymRowid(pTerm, pExpr->bDesc, 0);
241569 if( sqlite3Fts5IterEof(p->pIter)==0 ){
241580 if( sqlite3Fts5IterEof(p->pIter)==0 ){
241581 bEof = 0;
241584 bEof = 0;
241605 if( pNode->bEof==0 ){
241623 Fts5ExprPhrase *pPhrase = pNode->pNear->apPhrase[0];
241624 Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
241628 assert( pPhrase->aTerm[0].pSynonym==0 );
241635 pNode->bNomatch = (pPhrase->poslist.n==0);
241649 Fts5IndexIter *pIter = pNode->pNear->apPhrase[0]->aTerm[0].pIter;
241651 assert( pNode->bEof==0 );
241657 if( rc==SQLITE_OK && sqlite3Fts5IterEof(pIter)==0 ){
241661 pNode->bNomatch = 0;
241670 Fts5ExprNode *pNext = pNode->apChild[0];
241676 if( cmp>0 || (cmp==0 && pChild->bNomatch==0) ){
241694 for(i=0; i<pNode->nChild; i++){
241696 assert( p1->bEof || fts5RowidCmp(pExpr, p1->iRowid, iLast)>=0 );
241697 if( p1->bEof==0 ){
241699 || (bFromValid && fts5RowidCmp(pExpr, p1->iRowid, iFrom)<0)
241703 pNode->bNomatch = 0;
241726 assert( pAnd->bEof==0 );
241728 pAnd->bNomatch = 0;
241730 for(iChild=0; iChild<pAnd->nChild; iChild++){
241733 if( cmp>0 ){
241737 pAnd->bNomatch = 0;
241746 assert( pChild->bEof || fts5RowidCmp(pExpr, iLast, pChild->iRowid)<=0 );
241752 bMatch = 0;
241760 }while( bMatch==0 );
241775 int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom);
241779 pNode->bNomatch = 0;
241789 Fts5ExprNode *p1 = pNode->apChild[0];
241793 while( rc==SQLITE_OK && p1->bEof==0 ){
241795 if( cmp>0 ){
241799 assert( rc!=SQLITE_OK || cmp<=0 );
241801 rc = fts5ExprNodeNext(pExpr, p1, 0, 0);
241818 int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom);
241823 pNode->bNomatch = 0;
241838 if( pNode->bEof==0 ){
241880 pNode->bEof = 0;
241881 pNode->bNomatch = 0;
241886 }else if( pNode->xNext==0 ){
241890 int nEof = 0;
241891 for(i=0; i<pNode->nChild && rc==SQLITE_OK; i++){
241894 assert( pChild->bEof==0 || pChild->bEof==1 );
241897 pNode->iRowid = pNode->apChild[0]->iRowid;
241901 if( nEof>0 ) fts5ExprSetEof(pNode);
241910 pNode->bEof = pNode->apChild[0]->bEof;
241928 ** If iterating in ascending rowid order (bDesc==0), the first document
241948 && 0==pRoot->bEof
241949 && fts5RowidCmp(p, pRoot->iRowid, iFirst)<0
241956 assert( pRoot->bEof==0 );
241957 rc = fts5ExprNodeNext(p, pRoot, 0, 0);
241971 assert( pRoot->bEof==0 && pRoot->bNomatch==0 );
241973 rc = fts5ExprNodeNext(p, pRoot, 0, 0);
241974 assert( pRoot->bNomatch==0 || (rc==SQLITE_OK && pRoot->bEof==0) );
241976 if( fts5RowidCmp(p, pRoot->iRowid, iLast)>0 ){
242002 for(i=0; i<pPhrase->nTerm; i++){
242015 if( pPhrase->poslist.nSpace>0 ) fts5BufferFree(&pPhrase->poslist);
242026 pPhrase->aTerm[0].bFirst = 1;
242044 Fts5ExprNearset *pRet = 0;
242047 if( pNear==0 ){
242051 if( pRet==0 ){
242054 memset(pRet, 0, (size_t)nByte);
242056 }else if( (pNear->nPhrase % SZALLOC)==0 ){
242062 if( pRet==0 ){
242070 if( pRet==0 ){
242075 if( pRet->nPhrase>0 ){
242077 assert( pParse!=0 );
242078 assert( pParse->apPhrase!=0 );
242081 if( pPhrase->nTerm==0 ){
242086 }else if( pLast->nTerm==0 ){
242127 if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){
242131 if( pSyn==0 ){
242134 memset(pSyn, 0, (size_t)nByte);
242146 if( pPhrase==0 || (pPhrase->nTerm % SZALLOC)==0 ){
242148 int nNew = SZALLOC + (pPhrase ? pPhrase->nTerm : 0);
242153 if( pNew==0 ){
242156 if( pPhrase==0 ) memset(pNew, 0, SZ_FTS5EXPRPHRASE(1));
242164 memset(pTerm, 0, sizeof(Fts5ExprTerm));
242191 for(i=0; i<pNear->nPhrase; i++){
242200 assert( pParse->pExpr==0 );
242205 if( (pParse->nPhrase % 8)==0 ){
242209 if( apNew==0 ){
242232 char *z = 0;
242234 memset(&sCtx, 0, sizeof(TokenCtx));
242240 int flags = FTS5_TOKENIZE_QUERY | (bPrefix ? FTS5_TOKENIZE_PREFIX : 0);
242250 sCtx.pPhrase = 0;
242253 if( pAppend==0 ){
242256 return 0;
242261 if( sCtx.pPhrase==0 ){
242268 assert( pParse->apPhrase!=0 );
242285 Fts5ExprPhrase *pOrig = 0; /* The phrase extracted from pExpr */
242286 Fts5Expr *pNew = 0; /* Expression to return via *ppNew */
242287 TokenCtx sCtx = {0,0,0}; /* Context object for fts5ParseTokenize */
242288 if( !pExpr || iPhrase<0 || iPhrase>=pExpr->nPhrase ){
242305 if( rc==SQLITE_OK && ALWAYS(pOrig!=0) ){
242323 for(i=0; rc==SQLITE_OK && i<pOrig->nTerm; i++){
242324 int tflags = 0;
242327 rc = fts5ParseTokenize((void*)&sCtx,tflags,p->pTerm,p->nFullTerm,0,0);
242347 pNew->apExprPhrase[0] = sCtx.pPhrase;
242348 pNew->pRoot->pNear->apPhrase[0] = sCtx.pPhrase;
242353 && pOrig->aTerm[0].pSynonym==0
242354 && pOrig->aTerm[0].bFirst==0
242365 pNew = 0;
242392 int nNear = 0;
242395 for(i=0; i<p->n; i++){
242397 if( c<'0' || c>'9' ){
242403 if( nNear<214748363 ) nNear = nNear * 10 + (p->p[i] - '0');
242427 int nCol = p ? p->nCol : 0; /* Num. columns already in colset object */
242431 assert( iCol>=0 && iCol<pParse->pConfig->nCol );
242434 if( pNew==0 ){
242439 for(i=0; i<nCol; i++){
242472 int iOld = 0;
242473 for(i=0; i<nCol; i++){
242491 Fts5Colset *pRet = 0;
242499 for(iCol=0; iCol<pConfig->nCol; iCol++){
242500 if( 0==sqlite3_stricmp(pConfig->azCol[iCol], z) ) break;
242510 if( pRet==0 ){
242535 pRet = 0;
242544 int iIn = 0; /* Next input in pColset */
242545 int iMerge = 0; /* Next input in pMerge */
242546 int iOut = 0; /* Next output slot in pColset */
242550 if( iDiff==0 ){
242554 }else if( iDiff>0 ){
242584 if( pNear->pColset->nCol==0 ){
242586 pNode->xNext = 0;
242590 *ppFree = 0;
242596 assert( pNode->eType!=FTS5_EOF || pNode->nChild==0 );
242597 for(i=0; i<pNode->nChild; i++){
242627 if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1
242628 && pNear->apPhrase[0]->aTerm[0].pSynonym==0
242629 && pNear->apPhrase[0]->aTerm[0].bFirst==0
242689 int nTerm = pNear->apPhrase[0]->nTerm;
242705 for(ii=0; ii<nTerm; ii++){
242713 Fts5ExprTerm *p = &pNear->apPhrase[0]->aTerm[ii];
242714 Fts5ExprTerm *pTo = &pPhrase->aTerm[0];
242721 0, 0, sqlite3Fts5ParseNearset(pParse, 0, pPhrase)
242729 pRet = 0;
242749 Fts5ExprNode *pRet = 0;
242752 int nChild = 0; /* Number of children of returned node */
242758 if( eType==FTS5_STRING && pNear==0 ) return 0;
242759 if( eType!=FTS5_STRING && pLeft==0 ) return pRight;
242760 if( eType!=FTS5_STRING && pRight==0 ) return pLeft;
242764 && pNear->apPhrase[0]->nTerm>1
242785 for(iPhrase=0; iPhrase<pNear->nPhrase; iPhrase++){
242787 if( pNear->apPhrase[iPhrase]->nTerm==0 ){
242788 pRet->xNext = 0;
242794 Fts5ExprPhrase *pPhrase = pNear->apPhrase[0];
242797 || (pPhrase->nTerm>0 && pPhrase->aTerm[0].bFirst)
242804 pRet = 0;
242805 pNear = 0;
242806 assert( pLeft==0 && pRight==0 );
242810 assert( pNear==0 );
242813 pLeft = pRight = 0;
242820 pRet = 0;
242827 if( pRet==0 ){
242841 Fts5ExprNode *pRet = 0;
242871 assert( pParse->apPhrase!=0 );
242872 assert( pParse->nPhrase>0 );
242873 assert( pParse->apPhrase[pParse->nPhrase-1]==pRight->pNear->apPhrase[0] );
242889 assert( ap[0]==pPrev->pNear->apPhrase[0] );
242896 pRet = sqlite3Fts5ParseNode(pParse, FTS5_AND, pLeft, pRight, 0);
242905 sqlite3_int64 nByte = 0;
242916 int i = 0;
242932 zQuoted[i++] = '\0';
242963 char *zRet = 0;
242970 if( zRet==0 ) return 0;
242975 zRet = fts5PrintfAppend(zRet, "-col %d ", aiCol[0]);
242977 zRet = fts5PrintfAppend(zRet, "-col {%d", aiCol[0]);
242983 if( zRet==0 ) return 0;
242988 if( zRet==0 ) return 0;
242992 if( zRet==0 ) return 0;
242994 for(i=0; i<pNear->nPhrase; i++){
242998 for(iTerm=0; zRet && iTerm<pPhrase->nTerm; iTerm++){
243000 zRet = fts5PrintfAppend(zRet, "%s%.*s", iTerm==0?"":" ",
243009 if( zRet==0 ) return 0;
243012 }else if( pExpr->eType==0 ){
243015 char const *zOp = 0;
243027 for(i=0; zRet && i<pExpr->nChild; i++){
243031 zRet = 0;
243042 char *zRet = 0;
243043 if( pExpr->eType==0 ){
243055 for(ii=0; ii<pColset->nCol; ii++){
243063 if( zRet==0 ) return 0;
243068 if( zRet==0 ) return 0;
243071 for(i=0; i<pNear->nPhrase; i++){
243073 if( i!=0 ){
243075 if( zRet==0 ) return 0;
243077 for(iTerm=0; iTerm<pPhrase->nTerm; iTerm++){
243080 zRet = fts5PrintfAppend(zRet, "%s%s", iTerm==0?"":" + ", zTerm);
243083 if( zTerm==0 || zRet==0 ){
243085 return 0;
243092 if( zRet==0 ) return 0;
243096 char const *zOp = 0;
243108 for(i=0; i<pExpr->nChild; i++){
243110 if( z==0 ){
243112 zRet = 0;
243117 (i==0 ? "" : zOp),
243121 if( zRet==0 ) break;
243129 ** The implementation of user-defined scalar functions fts5_expr() (bTcl==0)
243130 ** and fts5_expr_tcl() (bTcl!=0).
243140 const char *zExpr = 0;
243141 char *zErr = 0;
243142 Fts5Expr *pExpr = 0;
243149 Fts5Config *pConfig = 0;
243168 if( azConfig==0 ){
243172 azConfig[0] = 0;
243180 zExpr = (const char*)sqlite3_value_text(apVal[0]);
243181 if( zExpr==0 ) zExpr = "";
243185 rc = sqlite3Fts5ExprNew(pConfig, 0, pConfig->nCol, zExpr, &pExpr, &zErr);
243189 if( pExpr->pRoot->xNext==0 ){
243196 if( zText==0 ){
243222 fts5ExprFunction(pCtx, nArg, apVal, 0);
243235 ** unicode code point, 1 is returned. Otherwise 0.
243250 memset(aArr, 0, sizeof(aArr));
243254 iCode = sqlite3_value_int(apVal[0]);
243269 int bRemoveDiacritics = 0;
243270 iCode = sqlite3_value_int(apVal[0]);
243296 for(i=0; rc==SQLITE_OK && i<ArraySize(aFunc); i++){
243298 rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0);
243319 return (pExpr ? pExpr->nPhrase : 0);
243326 if( iPhrase<0 || iPhrase>=pExpr->nPhrase ) return 0;
243338 if( pNode->bEof==0 && pNode->iRowid==pExpr->pRoot->iRowid ){
243342 *pa = 0;
243343 nRet = 0;
243368 memset(pRet, 0, sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
243369 for(i=0; i<pExpr->nPhrase; i++){
243374 (pBuf->n==0 || pNode->iRowid!=pExpr->pRoot->iRowid || pNode->bEof)
243378 pBuf->n = 0;
243397 for(i=0; i<pColset->nCol; i++){
243400 return 0;
243405 ** an embedded 0x00 byte. If it does, return the number of bytes in
243406 ** the buffer before the 0x00. If it does not, return nToken.
243410 for(ii=0; ii<nToken && pToken[ii]; ii++){}
243434 if( (tflags & FTS5_TOKEN_COLOCATED)==0 ) p->iOff++;
243435 for(i=0; i<pExpr->nPhrase; i++){
243437 if( p->aPopulator[i].bOk==0 ) continue;
243438 for(pT=&pExpr->apExprPhrase[i]->aTerm[0]; pT; pT=pT->pSynonym){
243440 && memcmp(pT->pTerm, pToken, pT->nQueryTerm)==0
243447 int iTokOff = p->iOff & 0x7FFFFFFF;
243473 for(i=0; i<pExpr->nPhrase; i++){
243476 if( (pColset && 0==fts5ExprColsetTest(pColset, iCol))
243479 aPopulator[i].bOk = 0;
243492 pNode->pNear->apPhrase[0]->poslist.n = 0;
243495 for(i=0; i<pNode->nChild; i++){
243503 pNode->bEof = 0;
243505 case 0:
243508 return (pNode->pNear->apPhrase[0]->poslist.n>0);
243512 for(i=0; i<pNode->nChild; i++){
243513 if( fts5ExprCheckPoslists(pNode->apChild[i], iRowid)==0 ){
243515 return 0;
243523 int bRet = 0;
243524 for(i=0; i<pNode->nChild; i++){
243534 if( 0==fts5ExprCheckPoslists(pNode->apChild[0], iRowid)
243535 || 0!=fts5ExprCheckPoslists(pNode->apChild[1], iRowid)
243538 return 0;
243563 assert( iPhrase>=0 && iPhrase<pExpr->nPhrase );
243566 if( pNode->bEof==0
243568 && pPhrase->poslist.n>0
243570 Fts5ExprTerm *pTerm = &pPhrase->aTerm[0];
243577 *ppCollist = pPhrase->aTerm[0].pIter->pData;
243578 *pnCollist = pPhrase->aTerm[0].pIter->nData;
243581 *ppCollist = 0;
243582 *pnCollist = 0;
243598 Fts5ExprPhrase *pPhrase = 0;
243600 if( iPhrase<0 || iPhrase>=pExpr->nPhrase ){
243604 if( iToken<0 || iToken>=pPhrase->nTerm ){
243626 Fts5ExprPhrase *pPhrase = 0;
243627 Fts5ExprTerm *pTerm = 0;
243630 if( iPhrase<0 || iPhrase>=pExpr->nPhrase ){
243634 if( iToken<0 || iToken>=pPhrase->nTerm ){
243656 for(ii=0; ii<pExpr->nPhrase; ii++){
243658 for(pT=&pExpr->apExprPhrase[ii]->aTerm[0]; pT; pT=pT->pSynonym){
243686 ** to accumulate "term -> doclist" content before it is flushed to a level-0
243709 ** followed by the term data. For example: "0token". There is no
243716 ** * Position list, without 0x00 terminator.
243758 if( pNew==0 ){
243762 memset(pNew, 0, sizeof(Fts5Hash));
243769 if( pNew->aSlot==0 ){
243771 *ppNew = 0;
243774 memset(pNew->aSlot, 0, (size_t)nByte);
243796 for(i=0; i<pHash->nSlot; i++){
243804 memset(pHash->aSlot, 0, pHash->nSlot * sizeof(Fts5HashEntry*));
243805 pHash->nEntry = 0;
243811 for(i=n-1; i>=0; i--){
243820 for(i=n-1; i>=0; i--){
243838 memset(apNew, 0, nNew*sizeof(Fts5HashEntry*));
243840 for(i=0; i<pHash->nSlot; i++){
243862 int nRet = 0;
243869 pPtr[nData++] = 0x00;
243871 pPtr[nData++] = 0x00;
243878 assert( p->bDel==0 || p->bDel==1 );
243890 if( p2==0 ){
243891 p->iSzPoslist = 0;
243892 p->bDel = 0;
243893 p->bContent = 0;
243919 int nIncr = 0; /* Amount to increment (*pHash->pnByte) by */
243928 if( zKey[0]==bByte
243930 && memcmp(&zKey[1], pToken, nToken)==0
243937 if( p==0 ){
243953 memset(p, 0, sizeof(Fts5HashEntry));
243956 zKey[0] = bByte;
243960 zKey[nToken+1] = '\0';
243973 p->iCol = (pHash->eDetail==FTS5_DETAIL_FULL ? 0 : -1);
243993 if( pNew==0 ) return SQLITE_NOMEM;
244009 fts5HashAddPoslistSize(pHash, p, 0);
244016 p->iCol = (pHash->eDetail==FTS5_DETAIL_FULL ? 0 : -1);
244017 p->iPos = 0;
244021 if( iCol>=0 ){
244029 pPtr[p->nData++] = 0x01;
244032 p->iPos = 0;
244067 Fts5HashEntry *pRet = 0;
244071 if( p1==0 ){
244073 p2 = 0;
244074 }else if( p2==0 ){
244076 p1 = 0;
244083 if( cmp==0 ){
244086 assert( cmp!=0 );
244088 if( cmp>0 ){
244099 *ppOut = 0;
244121 *ppSorted = 0;
244124 memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
244126 for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
244129 if( pTerm==0
244130 || (pIter->nKey>=nTerm && 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm))
244133 pEntry->pScanNext = 0;
244134 for(i=0; ap[i]; i++){
244136 ap[i] = 0;
244143 pList = 0;
244144 for(i=0; i<nMergeSlot; i++){
244164 char *zKey = 0;
244169 if( nTerm==p->nKey && memcmp(zKey, pTerm, nTerm)==0 ) break;
244182 *pnDoclist = 0;
244186 *ppOut = 0;
244187 *pnDoclist = 0;
244202 int nEntry = 0;
244204 for(ii=0; ii<pHash->nSlot; ii++){
244205 Fts5HashEntry *p = 0;
244219 return pHash->nEntry==0;
244228 return (p->pScan==0);
244242 fts5HashAddPoslistSize(pHash, p, 0);
244248 *pzTerm = 0;
244249 *pnTerm = 0;
244250 *ppDoclist = 0;
244251 *pnDoclist = 0;
244305 #define FTS5_MAIN_PREFIX '0'
244323 ** 4 bytes [0xff 0x00 0x00 0x01]. This is unambiguous as the value of a
244324 ** varint has to be at least 16256 to begin with "0xFF". And the default
244350 ** followed by the following 4 bytes: [0xFF 0x00 0x00 0x01].
244358 ** Then, for each level from 0 to nMax:
244363 ** + segment id (always > 0)
244364 ** + first leaf page number (often 1, always greater than 0)
244403 ** varint: rowid delta (always > 0)
244411 ** collist: collist for column 0
244413 ** 0x01 byte
244431 ** and occurs before the first term (otherwise 0).
244434 ** footer is 0 bytes in size, then this field is the same as the
244466 ** 0x01: Clear if leaf is also the root page, otherwise set.
244474 ** or an 0x00 byte otherwise.
244479 ** 0x01: Clear for root page, otherwise set.
244508 ** 1-byte: rowid-0-tombstone flag. This flag is only valid on the
244509 ** first tombstone hash page for each segment (iPg=0). If set,
244510 ** the hash table contains rowid 0. If clear, it does not.
244511 ** Rowid 0 is handled specially.
244551 #define FTS5_SEGMENT_ROWID(segid, pgno) fts5_dri(segid, 0, 0, pgno)
244553 #define FTS5_TOMBSTONE_ROWID(segid,ipg) fts5_dri(segid+(1<<16), 0, 0, ipg)
244639 /* Output variables. aPoslist==0 at EOF */
244671 Fts5StructureSegment *aSeg; /* Array of segments. aSeg[0] is oldest. */
244675 u64 nWriteCounter; /* Total leaves written to level 0 */
244708 /* TODO1: Can use (writer.pgidx.n==0) instead of bFirstTermInPage */
244832 #define FTS5_SEGITER_ONETERM 0x01
244833 #define FTS5_SEGITER_REVERSE 0x02
244863 ** the smallest key overall. aFirst[0] is unused.
244932 aOut[0] = (iVal>>8);
244933 aOut[1] = (iVal&0xFF);
244937 return ((u16)aIn[0] << 8) + aIn[1];
244946 return ((u64)a[0] << 56)
244953 + ((u64)a[7] << 0);
244962 return ((u32)a[0] << 24)
244965 + ((u32)a[3] << 0);
244973 a[0] = ((iVal >> 56) & 0xFF);
244974 a[1] = ((iVal >> 48) & 0xFF);
244975 a[2] = ((iVal >> 40) & 0xFF);
244976 a[3] = ((iVal >> 32) & 0xFF);
244977 a[4] = ((iVal >> 24) & 0xFF);
244978 a[5] = ((iVal >> 16) & 0xFF);
244979 a[6] = ((iVal >> 8) & 0xFF);
244980 a[7] = ((iVal >> 0) & 0xFF);
244988 a[0] = ((iVal >> 24) & 0xFF);
244989 a[1] = ((iVal >> 16) & 0xFF);
244990 a[2] = ((iVal >> 8) & 0xFF);
244991 a[3] = ((iVal >> 0) & 0xFF);
245007 ** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
245019 return (res==0 ? (pLeft->n - nRight) : res);
245027 ** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
245035 assert( nCmp<=0 || pLeft->p!=0 );
245036 assert( nCmp<=0 || pRight->p!=0 );
245038 return (res==0 ? (pLeft->n - pRight->n) : res);
245054 p->pReader = 0;
245067 Fts5Data *pRet = 0;
245076 p->pReader = 0;
245078 assert( p->pReader==0 );
245088 if( p->pReader==0 && rc==SQLITE_OK ){
245091 pConfig->zDb, p->zDataTbl, "block", iRowid, 0, &p->pReader
245103 u8 *aOut = 0; /* Read blob data into this buffer */
245116 rc = sqlite3_blob_read(p->pReader, aOut, nByte, 0);
245120 pRet = 0;
245123 pRet->p[nByte] = 0x00;
245124 pRet->p[nByte+1] = 0x00;
245132 assert( (pRet==0)==(p->rc!=SQLITE_OK) );
245133 assert( pRet==0 || EIGHT_BYTE_ALIGNMENT( pRet->p ) );
245152 pRet = 0;
245167 ppStmt, 0);
245187 if( p->pWriter==0 ){
245211 if( p->pDeleter==0 ){
245231 i64 iFirst = FTS5_SEGMENT_ROWID(iSegid, 0);
245232 i64 iLast = FTS5_SEGMENT_ROWID(iSegid+1, 0)-1;
245236 i64 iTomb1 = FTS5_TOMBSTONE_ROWID(iSegid, 0);
245240 if( p->pIdxDeleter==0 ){
245259 if( pStruct && 0>=(--pStruct->nRef) ){
245261 assert( pStruct->nRef==0 );
245262 for(i=0; i<pStruct->nLevel; i++){
245304 for(i=0; i<p->nLevel; i++) pNew->aLevel[i].aSeg = 0;
245305 for(i=0; i<p->nLevel; i++){
245309 if( pLvl->aSeg==0 ){
245310 for(i=0; i<p->nLevel; i++){
245344 int i = 0;
245346 int nLevel = 0;
245347 int nSegment = 0;
245349 Fts5Structure *pRet = 0; /* Structure object to return */
245350 int bStructureV2 = 0; /* True for FTS5_STRUCTURE_V2 */
245351 u64 nOriginCntr = 0; /* Largest origin value seen so far */
245358 if( 0==memcmp(&pData[i], FTS5_STRUCTURE_V2, 4) ){
245367 if( nLevel>FTS5_MAX_SEGMENT || nLevel<0
245368 || nSegment>FTS5_MAX_SEGMENT || nSegment<0
245381 for(iLvl=0; rc==SQLITE_OK && iLvl<nLevel; iLvl++){
245383 int nTotal = 0;
245400 for(iSeg=0; iSeg<nTotal; iSeg++){
245406 assert( pSeg!=0 );
245423 if( iLvl>0 && pLvl[-1].nMerge && nTotal==0 ) rc = FTS5_CORRUPT;
245427 if( nSegment!=0 && rc==SQLITE_OK ) rc = FTS5_CORRUPT;
245434 pRet = 0;
245448 assert( (ppStruct!=0 && (*ppStruct)!=0) || (*pRc)!=SQLITE_OK );
245456 memset(&pStruct->aLevel[nLevel], 0, sizeof(Fts5StructureLevel));
245484 if( bInsert==0 ){
245485 memset(&aNew[pLvl->nSeg], 0, sizeof(Fts5StructureSegment) * nExtra);
245489 memset(aNew, 0, sizeof(Fts5StructureSegment) * nExtra);
245499 Fts5Structure *pRet = 0;
245507 memset(&pData->p[pData->nn], 0, FTS5_DATA_PADDING);
245509 if( p->rc==SQLITE_OK && (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
245515 pRet = 0;
245523 i64 iVersion = 0;
245526 if( p->pDataVersion==0 ){
245530 if( p->rc ) return 0;
245534 iVersion = sqlite3_column_int64(p->pDataVersion, 0);
245555 if( p->pStruct==0 ){
245562 #if 0
245569 for(i=0; i<pTest->nLevel; i++){
245572 for(j=0; j<pTest->aLevel[i].nSeg; j++){
245585 if( p->rc!=SQLITE_OK ) return 0;
245586 assert( p->iStructVersion!=0 );
245587 assert( p->pStruct!=0 );
245595 p->pStruct = 0;
245605 int nSegment = 0; /* Total number of segments */
245608 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
245640 int nHdr = (pStruct->nOriginCntr>0 ? (4+4+9+9+9) : (4+9+9));
245643 memset(&buf, 0, sizeof(Fts5Buffer));
245647 if( iCookie<0 ) iCookie = 0;
245649 if( 0==sqlite3Fts5BufferSize(&p->rc, &buf, nHdr) ){
245652 if( pStruct->nOriginCntr>0 ){
245660 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
245667 for(iSeg=0; iSeg<pLvl->nSeg; iSeg++){
245672 if( pStruct->nOriginCntr>0 ){
245687 #if 0
245692 memset(&buf, 0, sizeof(buf));
245720 if( pOut->nMerge==0 ){
245724 for(is=pLvl->nSeg-1; is>=0; is--){
245762 int szPromote = 0; /* Promote anything this size or smaller */
245767 if( nSeg==0 ) return;
245772 for(iTst=iLvl-1; iTst>=0 && pStruct->aLevel[iTst].nSeg==0; iTst--);
245773 if( iTst>=0 ){
245775 int szMax = 0;
245777 assert( pTst->nMerge==0 );
245778 for(i=0; i<pTst->nSeg; i++){
245792 if( iPromote<0 ){
245808 if( pLvl->iOff==0 ){
245809 assert( pLvl->bEof==0 );
245844 if( pLvl[1].bEof==0 ){
245846 memset(pLvl, 0, sizeof(Fts5DlidxLvl));
245855 return pIter->aLvl[0].bEof;
245858 return fts5DlidxIterNextR(p, pIter, 0);
245874 for(i=0; i<pIter->nLvl; i++){
245877 return pIter->aLvl[0].bEof;
245882 return p->rc!=SQLITE_OK || pIter->aLvl[0].bEof;
245889 for(i=pIter->nLvl-1; p->rc==SQLITE_OK && i>=0; i--){
245891 while( fts5DlidxLvlNext(pLvl)==0 );
245892 pLvl->bEof = 0;
245894 if( i>0 ){
245897 memset(pChild, 0, sizeof(Fts5DlidxLvl));
245911 assert( pLvl->bEof==0 );
245917 pLvl->iOff = 0;
245920 int nZero = 0;
245922 u64 delta = 0;
245924 while( a[ii]==0 ){
245947 if( pLvl[1].bEof==0 ){
245949 memset(pLvl, 0, sizeof(Fts5DlidxLvl));
245954 while( fts5DlidxLvlNext(pLvl)==0 );
245955 pLvl->bEof = 0;
245961 return pIter->aLvl[0].bEof;
245964 return fts5DlidxIterPrevR(p, pIter, 0);
245973 for(i=0; i<pIter->nLvl; i++){
245986 Fts5DlidxIter *pIter = 0;
245988 int bDone = 0;
245990 for(i=0; p->rc==SQLITE_OK && bDone==0; i++){
245995 if( pNew==0 ){
246001 memset(pLvl, 0, sizeof(Fts5DlidxLvl));
246003 if( pLvl->pData && (pLvl->pData->p[0] & 0x0001)==0 ){
246012 if( bRev==0 ){
246021 pIter = 0;
246028 return pIter->aLvl[0].iRowid;
246031 return pIter->aLvl[0].iLeafPgno;
246047 pIter->pNextLeaf = 0;
246053 pIter->pLeaf = 0;
246077 int n = 0;
246079 assert_nc( nSz>=0 );
246081 *pbDel = nSz & 0x0001;
246102 pIter->bDel = 0;
246104 if( iOff<iEod && pIter->pLeaf->p[iOff]==0 ){
246107 if( iOff<iEod && pIter->pLeaf->p[iOff]==0 ){
246111 pIter->nPos = 0;
246117 pIter->bDel = (nSz & 0x0001);
246119 assert_nc( pIter->nPos>=0 );
246132 if( pIter->pLeaf==0 ){
246146 ** of the "nPrefix" field (if there was one - it is passed 0 if this is
246164 if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
246208 if( nTomb>0 ){
246233 if( pSeg->pgnoFirst==0 ){
246237 ** The caller will see the (pIter->pLeaf==0) and assume the iterator is
246239 assert( pIter->pLeaf==0 );
246244 memset(pIter, 0, sizeof(*pIter));
246255 assert( pIter->pLeaf!=0 );
246259 fts5SegIterLoadTerm(p, pIter, 0);
246285 int iRowidOffset = 0;
246293 u64 iDelta = 0;
246297 if( i<n && a[i]==0 ){
246299 if( i<n && a[i]==0 ) i++;
246315 if( aNew==0 ){
246338 pIter->pLeaf = 0;
246348 ** In this case leave pIter->pLeaf==0, this iterator is at EOF. */
246350 assert( pIter->pLeaf==0 );
246386 ** points to a delete marker. A delete marker is an entry with a 0 byte
246391 return (p->rc==SQLITE_OK && pSeg->pLeaf && pSeg->nPos==0);
246405 assert( pIter->pNextLeaf==0 );
246408 if( pIter->iRowidOffset>0 ){
246441 assert( (pIter->flags & FTS5_SEGITER_REVERSE)==0 );
246450 if( p->rc || pIter->pLeaf==0 ) return;
246451 pIter->iRowid = 0;
246461 }else if( (pIter->flags & FTS5_SEGITER_ONETERM)==0 ){
246463 int nKeep = 0;
246470 const u8 *pList = 0;
246471 const char *zTerm = 0;
246472 int nTerm = 0;
246476 if( pList==0 ) goto next_none_eof;
246495 pIter->pLeaf = 0;
246513 int bNewTerm = 0;
246514 int nKeep = 0;
246518 assert( pbNewTerm==0 || *pbNewTerm==0 );
246540 assert_nc( iDelta>0 );
246544 }else if( pIter->pSeg==0 ){
246545 const u8 *pList = 0;
246546 const char *zTerm = 0;
246547 int nTerm = 0;
246548 int nList = 0;
246550 if( 0==(pIter->flags & FTS5_SEGITER_ONETERM) ){
246554 if( pList==0 ){
246556 pIter->pLeaf = 0;
246567 iOff = 0;
246569 while( iOff==0 ){
246572 if( pLeaf==0 ) break;
246605 pIter->pLeaf = 0;
246618 pIter->bDel = (nSz & 0x0001);
246620 assert_nc( pIter->nPos>=0 );
246629 while( (a[iOff++] & 0x80) && iOff<iEnd ); \
246639 Fts5Data *pLast = 0;
246640 int pgnoLast = 0;
246682 if( bTermless==0 ) break;
246732 assert( pIter->pDlidx==0 );
246770 u32 nMatch = 0;
246771 u32 nKeep = 0;
246772 u32 nNew = 0;
246775 int bEndOfPage = 0;
246800 for(i=0; i<nCmp; i++){
246835 if( bGe==0 ){
246837 pIter->pLeaf = 0;
246842 if( pIter->pLeaf==0 ) return;
246844 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
246851 nKeep = 0;
246887 if( p->pIdxSelect==0 ){
246914 int bDlidx = 0; /* True if there is a doclist-index */
246915 sqlite3_stmt *pIdxSelect = 0;
246917 assert( bGe==0 || (flags & FTS5INDEX_QUERY_DESC)==0 );
246919 memset(pIter, 0, sizeof(*pIter));
246929 i64 val = sqlite3_column_int(pIdxSelect, 0);
246931 bDlidx = (val & 0x0001);
246938 bDlidx = 0;
246948 if( p->rc==SQLITE_OK && (bGe==0 || (flags & FTS5INDEX_QUERY_SCANONETERM)) ){
246964 if( 0==(flags & FTS5INDEX_QUERY_SCANONETERM) ){
246977 || pIter->pLeaf==0 /* 2 */
246978 || fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)==0 /* 3 */
246979 || (bGe && fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)>0) /* 4 */
246988 if( p->pIdxNextSelect==0 ){
247012 int bDlidx = 0;
247013 sqlite3_stmt *pSel = 0; /* SELECT to find iPg */
247022 i64 val = sqlite3_column_int64(pSel, 0);
247024 bDlidx = (val & 0x0001);
247031 memset(pIter, 0, sizeof(*pIter));
247034 if( iPg>=0 ){
247041 int iTermOff = 0;
247046 fts5SegIterLoadTerm(p, pIter, 0);
247051 fts5BufferCompareBlob(&pIter->term, (const u8*)pTerm, nTerm)>0
247070 int nList = 0;
247071 const u8 *z = 0;
247072 int n = 0;
247073 Fts5Data *pLeaf = 0;
247078 if( pTerm==0 || (flags & FTS5INDEX_QUERY_SCAN) ){
247079 const u8 *pList = 0;
247096 p->bDelete = 0;
247134 for(ii=0; ii<n; ii++){
247143 ** reaches 0, free it and its contents.
247148 if( p->nRef<=0 ){
247150 for(ii=0; ii<p->nTombstone; ii++){
247168 memset(pIter, 0, sizeof(Fts5SegIter));
247189 if( p1->pLeaf==0 ){
247191 }else if( p2->pLeaf==0 ){
247196 if( res==0 ) res = p1->term.n - p2->term.n;
247198 if( res==0 ){
247203 assert( pRes->bTermEq==0 );
247206 if( res<0 ){
247226 assert( (pFirst->pLeaf==0)==pIter->base.bEof );
247229 for(i=0; i<pIter->nSeg; i++){
247232 || p1->pLeaf==0
247239 for(i=0; i<pIter->nSeg; i+=2){
247274 assert( iOut<pIter->nSeg && iOut>0 );
247275 assert( pIter->bRev==0 || pIter->bRev==1 );
247287 pRes->bTermEq = 0;
247288 if( p1->pLeaf==0 ){ /* If p1 is at EOF */
247290 }else if( p2->pLeaf==0 ){ /* If p2 is at EOF */
247294 if( res==0 ){
247296 assert_nc( i2!=0 );
247303 assert( res!=0 );
247304 if( res<0 ){
247312 return 0;
247331 pIter->pNextLeaf = 0;
247337 if( pIter->pLeaf==0 ) break;
247339 if( iOff>0 ){
247374 if( bRev==0 ){
247382 bMove = 0;
247385 assert( pIter->pNextLeaf==0 );
247397 bMove = 0;
247402 if( bMove && p->rc==SQLITE_OK ) pIter->xNext(p, pIter, 0);
247403 if( pIter->pLeaf==0 ) break;
247404 if( bRev==0 && pIter->iRowid>=iMatch ) break;
247405 if( bRev!=0 && pIter->iRowid<=iMatch ) break;
247416 for(i=0; i<pIter->nSeg; i++){
247436 pSeg->xNext(p, pSeg, 0);
247446 ** If it does so successfully, 0 is returned. Otherwise 1.
247463 Fts5SegIter *pOther = &pIter->aSeg[iChanged ^ 0x0001];
247469 assert( pRes->bTermEq==0 || pOther->pLeaf );
247484 pOther = &pIter->aSeg[ pIter->aFirst[i ^ 0x0001].iFirst ];
247489 return 0;
247497 pIter->base.bEof = pSeg->pLeaf==0;
247505 #define TOMBSTONE_KEYSIZE(pPg) (pPg->p[0]==4 ? 4 : 8)
247525 if( iRowid==0 ){
247531 if( nCollide--==0 ) break;
247538 if( nCollide--==0 ) break;
247543 return 0;
247559 assert( iPg>=0 );
247563 if( pArray->apTombstone[iPg]==0 ){
247567 if( pArray->apTombstone[iPg]==0 ) return 0;
247577 return 0;
247594 assert( pIter->base.bEof==0 );
247597 int bNewTerm = 0;
247606 if( pSeg->pLeaf==0 || bNewTerm
247612 if( pSeg->pLeaf==0 ) return;
247617 if( (pIter->bSkipEmpty==0 || pSeg->nPos)
247618 && 0==fts5MultiIterIsDeleted(pIter)
247623 bUseFrom = 0;
247634 *pbNewTerm = 0;
247638 int bNewTerm = 0;
247642 if( pSeg->pLeaf==0 || bNewTerm
247688 assert_nc( nChunk>=0 );
247689 if( nChunk>0 ){
247714 for(i=0; i<pColset->nCol; i++){
247717 return 0;
247727 assert_nc( nChunk>=0 );
247728 if( nChunk>0 ){
247729 int i = 0;
247750 assert_nc( nChunk>=0 );
247751 if( nChunk>0 ){
247754 int i = 0;
247755 int iStart = 0;
247764 pCtx->eState = 0;
247769 while( i<nChunk && pChunk[i]!=0x01 ){
247770 while( pChunk[i] & 0x80 ) i++;
247802 Fts5Data *pData = 0;
247806 int pgnoSave = 0;
247811 if( (pSeg->flags & FTS5_SEGITER_REVERSE)==0 ){
247819 if( nRem<=0 ){
247821 }else if( pSeg->pSeg==0 ){
247827 if( pData==0 ) break;
247831 assert( pSeg->pNextLeaf==0 );
247833 pData = 0;
247851 assert( pBuf!=0 );
247852 assert( pSeg!=0 );
247853 if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+FTS5_DATA_ZERO_PADDING) ){
247854 assert( pBuf->p!=0 );
247856 memset(&pBuf->p[pBuf->n+pSeg->nPos], 0, FTS5_DATA_ZERO_PADDING);
247857 if( pColset==0 ){
247864 sCtx.eState = fts5IndexColsetTest(pColset, 0);
247865 assert( sCtx.eState==0 || sCtx.eState==1 );
247869 memset(&sCtx, 0, sizeof(sCtx));
247900 int i = 0;
247901 int iCurrent = 0;
247917 /* Advance pointer p until it points to pEnd or an 0x01 byte that is
247919 while( p<pEnd && *p!=0x01 ){
247920 while( *p++ & 0x80 );
247938 if( iCurrent & 0x80 ){
247965 assert( pIter->pColset==0 );
247976 fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist);
247982 ** xSetOutputs callback used when the Fts5Colset object has nCol==0 (match
247987 pIter->base.nData = 0;
248023 int iPrev = 0;
248028 int iPrevOut = 0;
248033 iPrev += (int)a++[0] - 2;
248079 assert( pIter!=0 || (*pRc)!=SQLITE_OK );
248086 else if( pIter->pColset==0 ){
248090 else if( pIter->pColset->nCol==0 ){
248116 for(iIter=pIter->nSeg-1; iIter>0; iIter--){
248120 if( p->rc==SQLITE_OK ) pSeg->xNext(p, pSeg, 0);
248130 fts5MultiIterNext(p, pIter, 0, 0);
248131 }else if( pIter->base.bEof==0 ){
248153 const u8 *pTerm, int nTerm, /* Term to seek to (or NULL/0) */
248155 int nSegment, /* Number of segments to merge (iLevel>=0) */
248158 int nSeg = 0; /* Number of segment-iters in use */
248159 int iIter = 0; /* */
248164 assert( (pTerm==0 && nTerm==0) || iLevel<0 );
248168 if( iLevel<0 ){
248171 nSeg += (p->pHash && 0==(flags & FTS5INDEX_QUERY_SKIPHASH));
248177 if( pNew==0 ){
248181 pNew->bRev = (0!=(flags & FTS5INDEX_QUERY_DESC));
248182 pNew->bSkipEmpty = (0!=(flags & FTS5INDEX_QUERY_SKIPEMPTY));
248184 if( (flags & FTS5INDEX_QUERY_NOOUTPUT)==0 ){
248190 if( iLevel<0 ){
248192 if( p->pHash && 0==(flags & FTS5INDEX_QUERY_SKIPHASH) ){
248197 for(pLvl=&pStruct->aLevel[0]; pLvl<pEnd; pLvl++){
248198 for(iSeg=pLvl->nSeg-1; iSeg>=0; iSeg--){
248201 if( pTerm==0 ){
248210 for(iSeg=nSeg-1; iSeg>=0; iSeg--){
248225 *ppOut = 0;
248229 assert( (*ppOut)!=0 || p->rc!=SQLITE_OK );
248248 if( pData->szLeaf>0 ){
248260 pData = 0;
248277 assert( pIter!=0 || p->rc!=SQLITE_OK );
248279 || (pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf==0)==pIter->base.bEof
248307 if( pIter->bRev==0 && iRowid>=iMatch ) break;
248308 if( pIter->bRev!=0 && iRowid<=iMatch ) break;
248328 ** If an error has already occurred, this function is a no-op. 0 is
248332 int iSegid = 0;
248344 memset(aUsed, 0, sizeof(aUsed));
248345 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
248346 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
248348 if( iId<=FTS5_MAX_SEGMENT && iId>0 ){
248354 for(i=0; aUsed[i]==0xFFFFFFFF; i++);
248356 for(iSegid=0; mask & ((u32)1 << iSegid); iSegid++);
248360 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
248361 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
248365 assert_nc( iSegid>0 && iSegid<=FTS5_MAX_SEGMENT );
248370 u8 aBlob[2] = {0xff, 0xff};
248389 assert( p->pHash || p->nPendingData==0 );
248392 p->nPendingData = 0;
248393 p->nPendingRow = 0;
248396 p->nContentlessDelete = 0;
248408 for(i=0; i<nOld; i++){
248420 assert( bFlush==0 || (pWriter->nDlidx>0 && pWriter->aDlidx[0].buf.n>0) );
248421 for(i=0; i<pWriter->nDlidx; i++){
248423 if( pDlidx->buf.n==0 ) break;
248425 assert( pDlidx->pgno!=0 );
248432 pDlidx->bPrevValid = 0;
248449 if( aDlidx==0 ){
248453 memset(&aDlidx[pWriter->nDlidx], 0, nByte);
248467 int bFlag = 0;
248471 if( pWriter->aDlidx[0].buf.n>0 && pWriter->nEmpty>=FTS5_MIN_DLIDX_SIZE ){
248475 pWriter->nEmpty = 0;
248493 assert( pWriter->iBtPage || pWriter->nEmpty==0 );
248494 if( pWriter->iBtPage==0 ) return;
248498 const char *z = (pWriter->btterm.n>0?(const char*)pWriter->btterm.p:"");
248507 pWriter->iBtPage = 0;
248540 ** has already been started, append an 0x00 byte to it. */
248541 if( pWriter->bFirstRowidInPage && pWriter->aDlidx[0].buf.n>0 ){
248542 Fts5DlidxWriter *pDlidx = &pWriter->aDlidx[0];
248544 sqlite3Fts5BufferAppendVarint(&p->rc, &pDlidx->buf, 0);
248571 int bDone = 0;
248573 for(i=0; p->rc==SQLITE_OK && bDone==0; i++){
248583 pDlidx->buf.p[0] = 0x01; /* Not the root node */
248590 if( p->rc==SQLITE_OK && pDlidx[1].buf.n==0 ){
248595 sqlite3Fts5BufferAppendVarint(&p->rc, &pDlidx[1].buf, 0);
248603 pDlidx->bPrevValid = 0;
248612 i64 iPgno = (i==0 ? pWriter->writer.pgno : pDlidx[-1].pgno);
248613 assert( pDlidx->buf.n==0 );
248626 static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
248630 assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
248633 assert( 0==fts5GetU16(&pPage->buf.p[2]) );
248638 assert( pPage->pgidx.n==0 );
248653 pPage->iPrevPgidx = 0;
248699 #if 0
248705 nPrefix = 0;
248740 pWriter->bFirstTermInPage = 0;
248742 pWriter->bFirstRowidInPage = 0;
248745 assert( p->rc || (pWriter->nDlidx>0 && pWriter->aDlidx[0].buf.n==0) );
248746 pWriter->aDlidx[0].pgno = pPage->pgno;
248782 pWriter->bFirstRowidInDoclist = 0;
248783 pWriter->bFirstRowidInPage = 0;
248797 assert( p->pConfig->pgsz>0 || p->rc!=SQLITE_OK );
248802 int nCopy = 0;
248812 if( n>0 ){
248843 for(i=0; i<pWriter->nDlidx; i++){
248856 memset(pWriter, 0, sizeof(Fts5SegWriter));
248864 assert( pWriter->writer.buf.n==0 );
248865 assert( pWriter->writer.pgidx.n==0 );
248871 if( p->pIdxWriter==0 ){
248880 /* Initialize the 4-byte leaf-page header to 0x00. */
248881 memset(pWriter->writer.buf.p, 0, 4);
248899 memset(&buf, 0, sizeof(Fts5Buffer));
248900 for(i=0; i<pIter->nSeg && p->rc==SQLITE_OK; i++){
248902 if( pSeg->pSeg==0 ){
248904 }else if( pSeg->pLeaf==0 ){
248906 ** Set both the first and last page-numbers to 0 to indicate that the
248908 pSeg->pSeg->pgnoLast = 0;
248909 pSeg->pSeg->pgnoFirst = 0;
248915 u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
248983 Fts5Iter *pIter = 0; /* Iterator to read input data */
248984 int nRem = pnRem ? *pnRem : 0; /* Output leaf pages left to write */
248992 int bTermWritten = 0; /* True if current term already output */
248997 memset(&writer, 0, sizeof(Fts5SegWriter));
248998 memset(&term, 0, sizeof(Fts5Buffer));
249001 assert( pLvlOut->nSeg>0 );
249007 writer.iBtPage = 0;
249017 fts5StructureExtendLevel(&p->rc, pStruct, iLvl+1, 1, 0);
249035 if( pStruct->nOriginCntr>0 ){
249036 pSeg->iOrigin1 = pLvl->aSeg[0].iOrigin1;
249042 assert( iLvl>=0 );
249043 for(fts5MultiIterNew(p, pStruct, flags, 0, 0, 0, iLvl, nInput, &pIter);
249044 fts5MultiIterEof(p, pIter)==0;
249045 fts5MultiIterNext(p, pIter, 0, 0)
249058 bTermWritten =0;
249062 if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue;
249064 if( p->rc==SQLITE_OK && bTermWritten==0 ){
249076 fts5BufferAppendVarint(&p->rc, &writer.writer.buf, 0);
249077 if( pSegIter->nPos>0 ){
249078 fts5BufferAppendVarint(&p->rc, &writer.writer.buf, 0);
249093 assert( pIter!=0 || p->rc!=SQLITE_OK );
249098 assert( pSeg->nEntry==0 );
249099 for(i=0; i<nInput; i++){
249112 pLvl->nMerge = 0;
249113 if( pSeg->pgnoLast==0 ){
249118 assert( pSeg->pgnoLast>0 );
249130 ** configuration option is set to 0, then this function always returns -1.
249139 if( pConfig->bContentlessDelete && pConfig->nDeleteMerge>0 ){
249141 int nBest = 0;
249143 for(ii=0; ii<pStruct->nLevel; ii++){
249145 i64 nEntry = 0;
249146 i64 nTomb = 0;
249148 for(iSeg=0; iSeg<pLvl->nSeg; iSeg++){
249152 assert_nc( nEntry>0 || pLvl->nSeg==0 );
249153 if( nEntry>0 ){
249182 int bRet = 0;
249184 while( nRem>0 && p->rc==SQLITE_OK ){
249186 int iBestLvl = 0; /* Level offering the most input segments */
249187 int nBest = 0; /* Number of input segments on best level */
249191 assert( pStruct->nLevel>0 );
249192 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
249210 if( iBestLvl<0 ) break;
249213 if( p->rc==SQLITE_OK && pStruct->aLevel[iBestLvl].nMerge==0 ){
249224 ** A total of nLeaf leaf pages of data has just been flushed to a level-0
249236 if( p->rc==SQLITE_OK && p->pConfig->nAutomerge>0 && ALWAYS((*ppStruct)!=0) ){
249258 if( pStruct && pStruct->nLevel>0 ){
249259 int iLvl = 0;
249261 fts5IndexMergeLevel(p, &pStruct, iLvl, 0);
249327 if( p->pDeleteFromIdx==0 ){
249360 Fts5Data *pLeaf = 0;
249366 int iNext = 0;
249367 u8 *aPg = 0;
249370 if( pLeaf==0 ) break;
249373 iNext = fts5GetU16(&aPg[0]);
249374 if( iNext!=0 ){
249375 *pbLastInDoclist = 0;
249377 if( iNext==0 && pLeaf->szLeaf!=pLeaf->nn ){
249381 if( iNext==0 ){
249384 const u8 aEmpty[] = {0x00, 0x00, 0x00, 0x04};
249385 assert_nc( bDetailNone==0 || pLeaf->nn==4 );
249386 if( bDetailNone==0 ) fts5DataWrite(p, iRowid, aEmpty, sizeof(aEmpty));
249388 pLeaf = 0;
249398 int nIdx = 0;
249399 u8 *aIdx = 0;
249401 /* Unless the current page footer is 0 bytes in size (in which case
249406 int iFirst = 0;
249408 int i2 = 0;
249416 if( aIdx==0 ) break;
249430 if( fts5GetU16(&aPg[0]) ) fts5PutU16(&aPg[0], 4);
249431 if( nIdx>0 ){
249438 assert( nPg>4 || fts5GetU16(aPg)==0 );
249460 u64 iDelta = 0;
249461 int iNextOff = 0;
249462 int iOff = 0;
249463 int nIdx = 0;
249464 u8 *aIdx = 0;
249465 int bLastInDoclist = 0;
249466 int iIdx = 0;
249467 int iStart = 0;
249468 int iDelKeyOff = 0; /* Offset of deleted key, if any */
249510 iStart = fts5GetU16(&aPg[0]);
249518 if( aPg[iSOP]==0x00 ) iSOP++;
249519 if( aPg[iSOP]==0x00 ) iSOP++;
249525 if( iNextOff<pSeg->iEndofDoclist && aPg[iNextOff]==0x00 ) iNextOff++;
249526 if( iNextOff<pSeg->iEndofDoclist && aPg[iNextOff]==0x00 ) iNextOff++;
249529 int nPos = 0;
249555 if( pSeg->bDel==0 ){
249561 int iKeyOff = 0;
249562 for(iIdx=0; iIdx<nIdx; /* no-op */){
249563 u32 iVal = 0;
249574 ** of the header to 0. */
249575 if( fts5GetU16(&aPg[0])==iStart && (bLastInDoclist || iNextOff==iPgIdx) ){
249576 fts5PutU16(&aPg[0], 0);
249582 aPg[iOff++] = 0x01;
249583 }else if( bLastInDoclist==0 ){
249585 u64 iNextDelta = 0;
249595 int iKey = 0;
249596 int iKeyOff = 0;
249600 for(iIdx=0; iIdx<nIdx; iKey++){
249601 u32 iVal = 0;
249617 int nPrefix = 0;
249618 int nSuffix = 0;
249619 int nPrefix2 = 0;
249620 int nSuffix2 = 0;
249662 if( bEmpty==0 ) break;
249671 int iTermIdx = 0;
249672 int iTermOff = 0;
249675 u32 iVal = 0;
249687 if( nTermIdx==0 ){
249708 int iPrevKeyOut = 0;
249709 int iKeyIn = 0;
249716 for(iIdx=0; iIdx<nIdx; /* no-op */){
249717 u32 iVal = 0;
249721 int iKeyOut = (iKeyIn - (iKeyIn>iOff ? nShift : 0));
249727 if( iPgIdx==nPg && nIdx>0 && pSeg->iLeafPgno!=1 ){
249731 assert_nc( nPg>4 || fts5GetU16(aPg)==0 );
249753 Fts5Iter *pIter = 0; /* Used to find term instance */
249758 sqlite3_stmt *pStmt = 0;
249773 fts5MultiIterNew(p, pStruct, f, 0, (const u8*)zTerm, nTerm, -1, 0, &pIter);
249774 if( fts5MultiIterEof(p, pIter)==0 ){
249781 && fts5MultiIterEof(p, pIter)==0
249795 ** Flush the contents of in-memory hash table iHash to a new level-0
249805 int pgnoLast = 0; /* Last leaf page number in segment */
249808 ** for the new level-0 segment. */
249812 if( sqlite3Fts5HashIsEmpty(pHash)==0 ){
249836 p->rc = sqlite3Fts5HashScanInit(pHash, 0, 0);
249838 while( p->rc==SQLITE_OK && 0==sqlite3Fts5HashScanEof(pHash) ){
249846 if( bSecureDelete==0 ){
249849 assert( writer.bFirstRowidInPage==0 );
249857 i64 iRowid = 0;
249858 i64 iPrev = 0;
249859 int iOff = 0;
249865 u64 iDelta = 0;
249874 if( iOff<nDoclist && pDoclist[iOff]==0x00
249878 if( iOff<nDoclist && pDoclist[iOff]==0x00 ){
249880 nDoclist = 0;
249885 }else if( (pDoclist[iOff] & 0x01)
249888 if( p->rc!=SQLITE_OK || pDoclist[iOff]==0x01 ){
249895 if( p->rc==SQLITE_OK && bTermWritten==0 ){
249898 assert( p->rc!=SQLITE_OK || writer.bFirstRowidInPage==0 );
249902 fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
249904 writer.bFirstRowidInPage = 0;
249915 if( iOff<nDoclist && pDoclist[iOff]==0 ){
249916 pBuf->p[pBuf->n++] = 0;
249918 if( iOff<nDoclist && pDoclist[iOff]==0 ){
249919 pBuf->p[pBuf->n++] = 0;
249927 int bDel = 0;
249928 int nPos = 0;
249946 int iPos = 0;
249949 int n = 0;
249955 assert( n>0 );
249970 /* pBuf->p[pBuf->n++] = '\0'; */
249976 assert( p->rc!=SQLITE_OK || bSecureDelete || pgnoLast>0 );
249977 if( pgnoLast>0 ){
249980 if( pStruct->nLevel==0 ){
249983 fts5StructureExtendLevel(&p->rc, pStruct, 0, 1, 0);
249985 pSeg = &pStruct->aLevel[0].aSeg[ pStruct->aLevel[0].nSeg++ ];
249989 if( pStruct->nOriginCntr>0 ){
249997 fts5StructurePromote(p, 0, pStruct);
250022 p->nPendingData = 0;
250023 p->nPendingRow = 0;
250024 p->nContentlessDelete = 0;
250035 Fts5Structure *pNew = 0;
250051 if( nSeg==0 ) return 0;
250052 for(i=0; i<pStruct->nLevel; i++){
250055 if( nThis>0 && (nThis==nSeg || (nThis==nSeg-1 && nMerge==nThis)) ){
250056 if( nSeg==1 && nThis==1 && pStruct->aLevel[i].aSeg[0].nPgTombstone==0 ){
250057 return 0;
250080 int iSegOut = 0;
250082 ** the new Fts5Level object so that pLvl->aSeg[0] is the oldest
250084 for(iLvl=pStruct->nLevel-1; iLvl>=0; iLvl--){
250085 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
250093 pNew = 0;
250102 Fts5Structure *pNew = 0;
250106 assert( p->rc!=SQLITE_OK || p->nContentlessDelete==0 );
250108 assert( p->rc!=SQLITE_OK || pStruct!=0 );
250116 assert( pNew==0 || pNew->nSegment>0 );
250119 for(iLvl=0; pNew->aLevel[iLvl].nSeg==0; iLvl++){}
250120 while( p->rc==SQLITE_OK && pNew->aLevel[iLvl].nSeg>0 ){
250137 Fts5Structure *pStruct = 0;
250144 if( nMerge<0 ){
250179 assert( nData>0 );
250180 if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nByte) ){
250184 memset(&pBuf->p[pBuf->n], 0, FTS5_DATA_ZERO_PADDING);
250192 assert( pIter->aPoslist || (p==0 && pIter->aPoslist==0) );
250194 pIter->aPoslist = 0;
250202 if( p[0] & 0x80 ){
250207 pIter->nPoslist = ((int)(p[0])) >> 1;
250213 pIter->aPoslist = 0;
250222 memset(pIter, 0, sizeof(*pIter));
250223 if( pBuf->n>0 ){
250230 #if 0
250242 assert( pBuf->n!=0 || (*piLastRowid)==0 );
250249 assert( (pBuf)->n!=0 || (iLastRowid)==0 ); \
250284 int i1 = 0;
250285 int i2 = 0;
250286 i64 iRowid1 = 0;
250287 i64 iRowid2 = 0;
250288 i64 iOut = 0;
250289 Fts5Buffer *p2 = &aBuf[0];
250293 memset(&out, 0, sizeof(out));
250300 while( i1>=0 || i2>=0 ){
250301 if( i1>=0 && (i2<0 || iRowid1<iRowid2) ){
250302 assert( iOut==0 || iRowid1>iOut );
250307 assert( iOut==0 || iRowid2>iOut );
250310 if( i1>=0 && iRowid1==iRowid2 ){
250348 if( p->iPos>=0 ){
250373 PrefixMerger *pHead = 0;
250375 int nOut = 0;
250376 Fts5Buffer out = {0, 0, 0};
250377 Fts5Buffer tmp = {0, 0, 0};
250378 i64 iLastRowid = 0;
250383 assert( nBuf+1<=(int)(sizeof(aMerger)/sizeof(aMerger[0])) );
250384 memset(aMerger, 0, sizeof(PrefixMerger)*(nBuf+1));
250387 for(i=0; i<nBuf; i++){
250392 if( nOut==0 ) return;
250414 i64 iPrev = 0;
250416 int nMerge = 0;
250418 PrefixMerger *pThis = 0;
250419 int nTail = 0;
250421 pHead = 0;
250424 pSave->iOff = 0;
250425 pSave->iPos = 0;
250434 if( pHead==0 || pHead->pNext==0 ){
250477 if( nTail>0 ){
250482 for(i=0; i<nBuf+1; i++){
250503 memset(&out.p[out.n], 0, FTS5_DATA_ZERO_PADDING);
250532 ** are passed 0.
250546 const int flags = (bPrefix ? FTS5INDEX_QUERY_SCAN : 0)
250549 Fts5Iter *p1 = 0; /* Iterator used to gather data from index */
250553 fts5MultiIterNew(p, pStruct, flags, pColset, pToken, nToken, -1, 0, &p1);
250556 fts5MultiIterEof(p, p1)==0;
250560 int nNew = 0;
250561 const u8 *pNew = 0;
250601 ** actually an iterator (i.e. with nIter>0, not just a container for
250607 ** (nIter==0), then iIter is an index into the term.p[] buffer where
250619 int nByte; /* Length of token in bytes (or 0) */
250663 int i1 = 0;
250664 int i2 = 0;
250666 assert( n1>=0 && n2>=0 );
250701 if( aNew==0 ){
250725 Fts5TokenDataMap *aTmp = 0;
250736 for(i1=0; i1<pT->nMap; i1+=(nHalf*2)){
250770 for(ii=0; ii<pSet->nIter; ii++){
250806 int iPosOff = 0;
250807 i64 iPos = 0;
250815 while( 0==sqlite3Fts5PoslistNext64(
250853 if( p1->base.nData>0 ){
250854 if( p1->base.iRowid<=pSetup->iLastRowid && pSetup->doclist.n>0 ){
250856 for(i=0; p->rc==SQLITE_OK && pSetup->doclist.n; i++){
250861 if( pSetup->aBuf[iStore].n==0 ){
250874 pSetup->iLastRowid = 0;
250901 memset(&s, 0, sizeof(s));
250902 memset(&s2, 0, sizeof(s2));
250905 s.iLastRowid = 0;
250907 if( iIdx==0
250939 if( iIdx!=0 ){
250940 pToken[0] = FTS5_MAIN_PREFIX;
250941 fts5VisitEntries(p, pColset, pToken, nToken, 0, prefixIterSetupCb, pCtx);
250944 pToken[0] = FTS5_MAIN_PREFIX + iIdx;
250947 assert( (s.nBuf%s.nMerge)==0 );
250948 for(i=0; i<s.nBuf; i+=s.nMerge){
250960 assert( pData!=0 || p->rc!=SQLITE_OK );
250968 assert( (*ppIter)!=0 || p->rc!=SQLITE_OK );
250972 s2.pT = 0;
250991 if( p->pHash==0 ){
250997 || (iRowid==p->iWriteRowid && p->bDelete==0)
251005 if( bDelete==0 ){
251045 memset(pTmp, 0, SZ_FTS5STRUCTURE(1));
251049 fts5DataWrite(p, FTS5_AVERAGES_ROWID, (const u8*)"", 0);
251077 pConfig, "data", "id INTEGER PRIMARY KEY, block BLOB", 0, pzErr
251094 *pp = 0;
251105 assert( p->pReader==0 );
251125 ** buffer, or 0 if there are less than nChar characters in total.
251132 int n = 0;
251134 for(i=0; i<nChar; i++){
251135 if( n>=nByte ) return 0; /* Input contains fewer than nChar chars */
251136 if( (unsigned char)p[n++]>=0xc0 ){
251137 if( n>=nByte ) return 0;
251138 while( (p[n] & 0xc0)==0x80 ){
251142 return 0;
251155 int nChar = 0;
251156 int i = 0;
251158 if( (unsigned char)pIn[i++]>=0xc0 ){
251159 while( i<nIn && (pIn[i] & 0xc0)==0x80 ) i++;
251187 assert( (iCol<0)==p->bDelete );
251194 for(i=0; i<pConfig->nPrefix && rc==SQLITE_OK; i++){
251221 && 0==memcmp(pBuf->p, pToken, nToken)
251222 && (pBuf->n==nToken || pBuf->p[nToken]==0x00)
251231 pSeg->pLeaf = 0;
251256 if( pIn==0 || pIn->nIter==pIn->nIterAlloc ){
251261 if( pNew==0 ){
251264 if( pIn==0 ) memset(pNew, 0, nByte);
251275 assert( pRet==0 || pRet->nIter<=pRet->nIterAlloc );
251282 ** (pIter->pTokenDataIter!=0). This function sets the iterator output
251288 int nHit = 0;
251290 int iMin = 0;
251294 pIter->base.nData = 0;
251295 pIter->base.pData = 0;
251297 for(ii=0; ii<pT->nIter; ii++){
251299 if( p->base.bEof==0 ){
251300 if( nHit==0 || p->base.iRowid<iRowid ){
251312 if( nHit==0 ){
251316 pIter->base.bEof = 0;
251320 fts5TokendataIterAppendMap(pIter->pIndex, pT, iMin, 0, iRowid, -1);
251323 int nReader = 0;
251324 int nByte = 0;
251325 i64 iPrev = 0;
251328 if( pT->aPoslistReader==0 ){
251333 if( pT->aPoslistReader==0 ) return;
251338 for(ii=0; ii<pT->nIter; ii++){
251360 if( aNew==0 ){
251368 pIter->poslist.n = 0;
251374 iMin = 0;
251375 for(ii=0; ii<nReader; ii++){
251377 if( pReader->bEof==0 ){
251407 ** (pIter->pTokenDataIter!=0). This function advances the iterator. If
251417 for(ii=0; ii<pT->nIter; ii++){
251419 if( p->base.bEof==0
251423 while( bFrom && p->base.bEof==0
251427 fts5MultiIterNext(pIndex, p, 0, 0);
251442 if( pIter && pIter->aSeg[0].pLeaf==0 ){
251443 fts5BufferSet(&pIter->pIndex->rc, &pIter->aSeg[0].term, pTerm->n, pTerm->p);
251457 Fts5Iter *pRet = 0;
251458 Fts5TokenDataIter *pSet = 0;
251459 Fts5Structure *pStruct = 0;
251462 Fts5Buffer bSeek = {0, 0, 0};
251463 Fts5Buffer *pSmall = 0;
251469 Fts5Iter *pPrev = pSet ? pSet->apIter[pSet->nIter-1] : 0;
251470 Fts5Iter *pNew = 0;
251471 Fts5SegIter *pNewIter = 0;
251472 Fts5SegIter *pPrevIter = 0;
251479 fts5BufferAppendBlob(&p->rc, &bSeek, 1, (const u8*)"\0");
251488 pNewIter = &pNew->aSeg[0];
251489 pPrevIter = (pPrev ? &pPrev->aSeg[0] : 0);
251490 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
251491 for(iSeg=pStruct->aLevel[iLvl].nSeg-1; iSeg>=0; iSeg--){
251493 int bDone = 0;
251498 memset(pPrevIter, 0, sizeof(Fts5SegIter));
251506 if( bDone==0 ){
251534 pSmall = 0;
251535 for(ii=0; ii<pNew->nSeg; ii++){
251537 if( 0==fts5IsTokendataPrefix(&pII->term, pToken, nToken) ){
251540 if( pII->pLeaf && (!pSmall || fts5BufferCompare(pSmall, &pII->term)>0) ){
251548 if( pSmall==0 ){
251559 for(ii=0; ii<pSet->nIter; ii++){
251562 for(iSeg=0; iSeg<pIter->nSeg; iSeg++){
251570 pRet = fts5MultiIterAlloc(p, 0);
251573 pRet->nSeg = 0;
251601 Fts5Iter *pRet = 0;
251602 Fts5Buffer buf = {0, 0, 0};
251605 assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
251607 if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
251608 int iIdx = 0; /* Index to search */
251609 int iPrefixIdx = 0; /* +1 prefix index */
251611 assert( buf.p!=0 );
251612 if( nToken>0 ) memcpy(&buf.p[1], pToken, nToken);
251620 bTokendata = 0;
251634 if( pConfig->bPrefixIndex==0 || (flags & FTS5INDEX_QUERY_TEST_NOIDX) ){
251648 if( bTokendata && iIdx==0 ){
251649 buf.p[0] = FTS5_MAIN_PREFIX;
251654 buf.p[0] = (u8)(FTS5_MAIN_PREFIX + iIdx);
251657 pColset, buf.p, nToken+1, -1, 0, &pRet
251663 int bDesc = (flags & FTS5INDEX_QUERY_DESC)!=0;
251665 if( pRet==0 ){
251668 assert( pRet->pColset==0 );
251679 pRet = 0;
251698 if( pIter->nSeg==0 ){
251700 fts5TokendataIterNext(pIter, 0, 0);
251702 fts5MultiIterNext(pIter->pIndex, pIter, 0, 0);
251716 fts5MultiIterNext(p, pIter, 0, 0);
251719 if( pSeg->pLeaf && pSeg->term.p[0]!=FTS5_MAIN_PREFIX ){
251721 pSeg->pLeaf = 0;
251736 if( pIter->nSeg==0 ){
251753 return (z ? &z[1] : 0);
251767 Fts5Buffer token = {0, 0, 0};
251770 memset(&ctx, 0, sizeof(ctx));
251773 assert( token.p!=0 || p->rc!=SQLITE_OK );
251780 token.p[0] = FTS5_MAIN_PREFIX;
251785 p, 0, token.p, token.n, 1, prefixIterSetupTokendataCb, (void*)&ctx
251805 ** iterator (pIter->pTokenDataIter!=0).
251820 Fts5TokenDataMap *aMap = 0;
251821 int i1 = 0;
251822 int i2 = 0;
251823 int iTest = 0;
251825 assert( pT || (pToken && pIter->nSeg>0) );
251826 if( pT==0 ){
251844 if( aMap[iTest].iPos<0 ){
251857 if( pIter->nSeg==0 ){
251859 *ppOut = (const char*)pMap->aSeg[0].term.p+1;
251860 *pnOut = pMap->aSeg[0].term.n-1;
251878 && (pIter->nSeg==0 || pIter->pIndex->pConfig->eDetail!=FTS5_DETAIL_FULL)
251880 pIter->pTokenDataIter->nMap = 0;
251902 assert( pIter->pTokenDataIter || pIter->nSeg>0 );
251903 if( pIter->nSeg>0 ){
251905 if( pT==0 ){
251916 for(ii=0; ii<pT->nIter; ii++){
251917 Fts5Buffer *pTerm = &pT->apIter[ii]->aSeg[0].term;
251918 if( nToken==pTerm->n-1 && memcmp(pToken, pTerm->p+1, nToken)==0 ) break;
251921 fts5TokendataIterAppendMap(p, pT, ii, 0, iRowid, iPos);
251948 *pnRow = 0;
251949 memset(anSize, 0, sizeof(i64) * nCol);
251952 int i = 0;
251955 for(iCol=0; i<pData->nn && iCol<nCol; iCol++){
251993 sqlite3_blob *pBlob = 0;
252002 sqlite3_blob_write(pBlob, aCookie, 4, 0);
252056 if( szKey==4 && iRowid>0xFFFFFFFF ) return 2;
252057 if( iRowid==0 ){
252058 pPg->p[1] = 0x01;
252059 return 0;
252062 if( bForce==0 && nElem>=(nSlot/2) ){
252071 if( nCollide--==0 ) return 0;
252078 if( nCollide--==0 ) return 0;
252083 return 0;
252092 ** Return 0 if the hash is successfully rebuilt into the nOut pages.
252108 int res = 0;
252111 for(ii=0; ii<nOut; ii++){
252112 apOut[ii]->p[0] = szKey;
252113 fts5PutU32(&apOut[ii]->p[4], 0);
252117 for(ii=0; res==0 && ii<pSeg->nPgTombstone; ii++){
252118 Fts5Data *pData = 0; /* Page ii of the current hash table */
252119 Fts5Data *pFree = 0; /* Free this at the end of the loop */
252131 for(iIn=0; iIn<nSlotIn; iIn++){
252132 u64 iVal = 0;
252143 /* If iVal is not 0 at this point, insert it into the new hash table */
252146 res = fts5IndexTombstoneAddToPage(pPg, 0, nOut, iVal);
252151 /* If this is page 0 of the old hash, copy the rowid-0-flag from the
252153 if( ii==0 ){
252154 apOut[0]->p[1] = pData->p[1];
252175 ** both output parameters set to 0 before returning.
252188 int nSlot = 0; /* Number of slots in each output page */
252189 int nOut = 0;
252208 if( pSeg->nPgTombstone==0 ){
252215 assert( pData1 && iPg1==0 );
252218 if( nSlot>nSlotPerPage ) nOut = 0;
252220 if( nOut==0 ){
252228 int res = 0;
252229 int ii = 0;
252230 int szPage = 0;
252231 Fts5Data **apOut = 0;
252237 for(ii=0; ii<nOut; ii++){
252252 if( res==0 ){
252255 apOut = 0;
252256 nOut = 0;
252281 Fts5Data *pPg = 0;
252283 int szKey = 0;
252284 int nHash = 0;
252285 Fts5Data **apHash = 0;
252289 if( pSeg->nPgTombstone>0 ){
252292 if( pPg==0 ){
252297 if( 0==fts5IndexTombstoneAddToPage(pPg, 0, pSeg->nPgTombstone, iRowid) ){
252306 if( iRowid>0xFFFFFFFF ) szKey = 8;
252310 assert( p->rc==SQLITE_OK || (nHash==0 && apHash==0) );
252315 int ii = 0;
252317 for(ii=0; ii<nHash; ii++){
252338 int bFound = 0; /* True after pSeg->nEntryTombstone incr. */
252340 for(iLvl=pStruct->nLevel-1; iLvl>=0; iLvl--){
252342 for(iSeg=pStruct->aLevel[iLvl].nSeg-1; iSeg>=0; iSeg--){
252345 if( bFound==0 ){
252379 if( iIdx>=0 ) ret += (ret<<3) + (FTS5_MAIN_PREFIX + iIdx);
252380 for(i=0; i<nTerm; i++) ret += (ret<<3) + pTerm[i];
252398 Fts5DlidxIter *pDlidx = 0;
252402 for(pDlidx=fts5DlidxIterInit(p, 0, iSegid, iLeaf);
252403 fts5DlidxIterEof(p, pDlidx)==0;
252412 pDlidx = 0;
252415 fts5DlidxIterEof(p, pDlidx)==0;
252424 pDlidx = 0;
252439 Fts5IndexIter *pIter = 0;
252441 p, z, n, (flags | FTS5INDEX_QUERY_NOTOKENDATA), 0, &pIter
252444 while( rc==SQLITE_OK && ALWAYS(pIter!=0) && 0==sqlite3Fts5IterEof(pIter) ){
252448 cksum ^= sqlite3Fts5IndexEntryCksum(rowid, 0, 0, iIdx, z, n);
252452 sReader.bEof==0;
252472 ** encoded codepoints. If so, return 0. Otherwise, if the buffer does not
252476 int i = 0;
252477 assert_nc( n>0 );
252479 if( (z[i] & 0x80)==0x00 ){
252482 if( (z[i] & 0xE0)==0xC0 ){
252483 if( i+1>=n || (z[i+1] & 0xC0)!=0x80 ) return 1;
252486 if( (z[i] & 0xF0)==0xE0 ){
252487 if( i+2>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
252490 if( (z[i] & 0xF8)==0xF0 ){
252491 if( i+3>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
252492 if( (z[i+2] & 0xC0)!=0x80 ) return 1;
252499 return 0;
252514 if( pPrev->n==0 ){
252521 int iIdx = (pPrev->p[0] - FTS5_MAIN_PREFIX);
252522 int flags = (iIdx==0 ? 0 : FTS5INDEX_QUERY_PREFIX);
252523 u64 ck1 = 0;
252524 u64 ck2 = 0;
252548 if( p->nPendingData==0 && 0==fts5TestUtf8(zTerm, nTerm) ){
252549 if( iIdx>0 && rc==SQLITE_OK ){
252551 ck2 = 0;
252555 if( iIdx>0 && rc==SQLITE_OK ){
252557 ck2 = 0;
252602 if( i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf) ) p->rc = FTS5_CORRUPT;
252609 i64 iTermOff = 0;
252612 Fts5Buffer buf1 = {0,0,0};
252613 Fts5Buffer buf2 = {0,0,0};
252648 if( res<=0 ) p->rc = FTS5_CORRUPT;
252664 sqlite3_stmt *pStmt = 0;
252669 if( pSeg->pgnoFirst==0 ) return;
252692 if( pLeaf==0 ) break;
252700 if( nIdxTerm==0
252725 if( res==0 ) res = nTerm - nIdxTerm;
252726 if( res<0 ) p->rc = FTS5_CORRUPT;
252743 Fts5DlidxIter *pDlidx = 0; /* For iterating through doclist index */
252746 int iPg = 0;
252749 for(pDlidx=fts5DlidxIterInit(p, 0, iSegid, iIdxLeaf);
252750 fts5DlidxIterEof(p, pDlidx)==0;
252759 if( fts5LeafFirstRowidOff(pLeaf)!=0 ) p->rc = FTS5_CORRUPT;
252775 }else if( bSecureDelete==0 || iRowidOff>0 ){
252778 if( iRowid<iDlRowid || (bSecureDelete==0 && iRowid!=iDlRowid) ){
252801 #if 0
252821 u64 cksum2 = 0; /* Checksum based on contents of indexes */
252822 Fts5Buffer poslist = {0,0,0}; /* Buffer used to hold a poslist */
252829 u64 cksum3 = 0; /* Checksum based on contents of indexes */
252830 Fts5Buffer term = {0,0,0}; /* Buffer used to hold most recent term */
252836 if( pStruct==0 ){
252842 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
252843 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
252862 for(fts5MultiIterNew(p, pStruct, flags, 0, 0, 0, -1, 0, &pIter);
252863 fts5MultiIterEof(p, pIter)==0;
252864 fts5MultiIterNext(p, pIter, 0, 0)
252867 i64 iPos = 0; /* Position read from poslist */
252868 int iOff = 0; /* Offset within poslist */
252877 if( 0==fts5MultiIterIsEmpty(p, pIter) ){
252878 cksum2 ^= sqlite3Fts5IndexEntryCksum(iRowid, 0, 0, -1, z, n);
252881 poslist.n = 0;
252882 fts5SegiterPoslist(p, &pIter->aSeg[pIter->aFirst[1].iFirst], 0, &poslist);
252883 fts5BufferAppendBlob(&p->rc, &poslist, 4, (const u8*)"\0\0\0\0");
252884 while( 0==sqlite3Fts5PoslistNext64(poslist.p, poslist.n, &iOff, &iPos) ){
252891 fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3);
252929 *pbDlidx = (int)(iRowid & 0x0001);
252935 *pbTombstone = (int)(iRowid & 0x0001);
252944 if( iSegid==0 ){
252969 for(iLvl=0; iLvl<p->nLevel; iLvl++){
252974 for(iSeg=0; iSeg<pLvl->nSeg; iSeg++){
252979 if( pSeg->iOrigin1>0 ){
253005 Fts5Structure *p = 0; /* Decoded structure object */
253007 rc = fts5StructureDecode(pBlob, nBlob, 0, &p);
253031 int i = 0;
253047 ** after either the input buffer is exhausted or a 0 value is read.
253052 int iOff = 0;
253072 i64 iDocid = 0;
253073 int iOff = 0;
253075 if( n>0 ){
253116 int i = 0;
253117 i64 iRowid = 0;
253125 if( i<nData && pData[i]==0x00 ){
253127 if( i<nData && pData[i]==0x00 ){
253145 for(ii=0; ii<pTerm->n; ii++){
253146 if( pTerm->p[ii]==0x00 ){
253148 pBuf->p[pBuf->n++] = '0';
253153 pBuf->p[pBuf->n] = 0x00;
253171 u8 *a = 0;
253174 sqlite3_int64 nSpace = 0;
253175 int eDetailNone = (sqlite3_user_data(pCtx)!=0);
253179 memset(&s, 0, sizeof(Fts5Buffer));
253180 iRowid = sqlite3_value_int64(apVal[0]);
253183 ** copy is followed by FTS5_DATA_ZERO_PADDING 0x00 bytes, which prevents
253189 if( a==0 ) goto decode_out;
253190 if( n>0 ) memcpy(a, aBlob, n);
253202 memset(&lvl, 0, sizeof(Fts5DlidxLvl));
253206 for(fts5DlidxLvlNext(&lvl); lvl.bEof==0; fts5DlidxLvlNext(&lvl)){
253213 int szKey = (aBlob[0]==4 || aBlob[0]==8) ? aBlob[0] : 8;
253218 sqlite3Fts5BufferAppendPrintf(&rc, &s, " 0");
253220 for(ii=0; ii<nSlot; ii++){
253221 u64 iVal = 0;
253229 if( iVal!=0 ){
253233 }else if( iSegid==0 ){
253244 int nKeep = 0;
253247 memset(&term, 0, sizeof(Fts5Buffer));
253293 int iPgidxPrev = 0; /* Previous value read from pgidx */
253294 int iTermOff = 0;
253295 int iRowidOff = 0;
253299 memset(&term, 0, sizeof(Fts5Buffer));
253305 iRowidOff = fts5GetU16(&a[0]);
253316 if( iRowidOff!=0 ){
253318 }else if( iTermOff!=0 ){
253358 if( bFirst==0 ){
253403 if( nArg==0 ){
253406 zArg = (const char*)sqlite3_value_text(apVal[0]);
253407 if( 0==sqlite3_stricmp(zArg, "segment") ){
253455 Fts5StructVtab *pNew = 0;
253485 pIdxInfo->idxNum = 0;
253486 for(i=0, p=pIdxInfo->aConstraint; i<pIdxInfo->nConstraint; i++, p++){
253487 if( p->usable==0 ) continue;
253512 Fts5StructVcsr *pNew = 0;
253543 pCsr->iSeg = 0;
253547 pCsr->pStruct = 0;
253558 return pCsr->pStruct==0;
253584 case 0: /* level */
253624 ** idxNum==0 means show all subprograms
253635 const u8 *aBlob = 0;
253636 int nBlob = 0;
253640 pCsr->pStruct = 0;
253642 nBlob = sqlite3_value_bytes(argv[0]);
253643 aBlob = (const u8*)sqlite3_value_blob(argv[0]);
253644 rc = fts5StructureDecode(aBlob, nBlob, 0, &pCsr->pStruct);
253646 pCsr->iLevel = 0;
253647 pCsr->iRowid = 0;
253668 db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0
253674 SQLITE_UTF8, (void*)db, fts5DecodeFunction, 0, 0
253680 db, "fts5_rowid", -1, SQLITE_UTF8, 0, fts5RowidFunction, 0, 0
253686 0, /* iVersion */
253687 0, /* xCreate */
253691 0, /* xDestroy */
253699 0, /* xUpdate */
253700 0, /* xBegin */
253701 0, /* xSync */
253702 0, /* xCommit */
253703 0, /* xRollback */
253704 0, /* xFindFunction */
253705 0, /* xRename */
253706 0, /* xSavepoint */
253707 0, /* xRelease */
253708 0, /* xRollbackTo */
253709 0, /* xShadowName */
253710 0 /* xIntegrity */
253712 rc = sqlite3_create_module(db, "fts5_structure", &fts5structure_module, 0);
253723 assert( p->pStruct==0 || p->iStructVersion!=0 );
253798 int eState; /* 0==closed, 1==open, 2==synced */
253799 int iSavepoint; /* Number of open savepoints (0 -> none) */
253822 #define FTS5_LOCALE_HDR_SIZE ((int)sizeof( ((Fts5Global*)0)->aLocaleHdr ))
253967 #define FTS5_BI_MATCH 0x0001 /* <tbl> MATCH ? */
253968 #define FTS5_BI_RANK 0x0002 /* rank MATCH ? */
253969 #define FTS5_BI_ROWID_EQ 0x0004 /* rowid == ? */
253970 #define FTS5_BI_ROWID_LE 0x0008 /* rowid <= ? */
253971 #define FTS5_BI_ROWID_GE 0x0010 /* rowid >= ? */
253973 #define FTS5_BI_ORDER_RANK 0x0020
253974 #define FTS5_BI_ORDER_ROWID 0x0040
253975 #define FTS5_BI_ORDER_DESC 0x0080
253980 #define FTS5CSR_EOF 0x01
253981 #define FTS5CSR_REQUIRE_CONTENT 0x02
253982 #define FTS5CSR_REQUIRE_DOCSIZE 0x04
253983 #define FTS5CSR_REQUIRE_INST 0x08
253984 #define FTS5CSR_FREE_ZRANK 0x10
253985 #define FTS5CSR_REQUIRE_RESEEK 0x20
253986 #define FTS5CSR_REQUIRE_POSLIST 0x40
253989 #define BitFlagTest(x,y) (((x) & (y))!=0)
254017 assert( p->ts.eState==0 );
254029 p->ts.eState = 0;
254033 assert( p->ts.eState==1 || p->ts.eState==2 || p->ts.eState==0 );
254034 p->ts.eState = 0;
254039 assert( iSavepoint>=0 );
254046 assert( iSavepoint>=0 );
254117 ** argv[0] -> module name ("fts5")
254134 Fts5Config *pConfig = 0; /* Results of parsing argc/argv */
254135 Fts5FullTable *pTab = 0; /* New virtual table object */
254141 assert( (rc==SQLITE_OK && *pzErr==0) || pConfig==0 );
254181 if( pConfig ) pConfig->pzErrmsg = 0;
254184 pTab = 0;
254186 fts5CheckTransactionState(pTab, FTS5_BEGIN, 0);
254204 return fts5InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
254257 return 0;
254325 int idxFlags = 0; /* Parameter passed through to xFilter() */
254329 int iIdxStr = 0;
254330 int iCons = 0;
254332 int bSeenEq = 0;
254333 int bSeenGt = 0;
254334 int bSeenLt = 0;
254335 int nSeenMatch = 0;
254336 int bSeenRank = 0;
254353 if( idxStr==0 ) return SQLITE_NOMEM;
254357 for(i=0; i<pInfo->nConstraint; i++){
254364 if( p->usable==0 || iCol<0 ){
254367 idxStr[iIdxStr] = 0;
254379 assert( idxStr[iIdxStr]=='\0' );
254385 if( iCol>=0 && iCol<nCol && fts5UsePatternMatch(pConfig, p) ){
254391 assert( idxStr[iIdxStr]=='\0' );
254393 }else if( bSeenEq==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ && iCol<0 ){
254401 if( bSeenEq==0 ){
254402 for(i=0; i<pInfo->nConstraint; i++){
254404 if( p->iColumn<0 && p->usable ){
254421 idxStr[iIdxStr] = '\0';
254428 int iSort = pInfo->aOrderBy[0].iColumn;
254429 if( iSort==(pConfig->nCol+1) && nSeenMatch>0 ){
254431 }else if( iSort==-1 && (!pInfo->aOrderBy[0].desc || !pConfig->bTokendata) ){
254436 if( pInfo->aOrderBy[0].desc ){
254445 if( nSeenMatch==0 ) fts5SetUniqueFlag(pInfo);
254475 Fts5Cursor *pCsr = 0; /* New cursor object */
254485 memset(pCsr, 0, (size_t)nByte);
254555 memset(&pCsr->ePlan, 0, sizeof(Fts5Cursor) - ((u8*)&pCsr->ePlan - (u8*)pCsr));
254592 int iOff = 0;
254595 pSorter->iRowid = sqlite3_column_int64(pSorter->pStmt, 0);
254599 /* nBlob==0 in detail=none mode. */
254600 if( nBlob>0 ){
254601 for(i=0; i<(pSorter->nIdx-1); i++){
254647 assert( *pbSkip==0 );
254697 int bSkip = 0;
254747 sqlite3_stmt *pRet = 0;
254754 if( zSql==0 ){
254758 SQLITE_PREPARE_PERSISTENT, &pRet, 0);
254786 if( pSorter==0 ) return SQLITE_NOMEM;
254787 memset(pSorter, 0, (size_t)nByte);
254807 assert( pTab->pSortCsr==0 );
254810 pTab->pSortCsr = 0;
254816 pCsr->pSorter = 0;
254848 while( z[0]==' ' ) z++;
254849 for(n=0; z[n] && z[n]!=' '; n++);
254851 assert( pTab->p.base.zErrMsg==0 );
254854 if( n==5 && 0==sqlite3_strnicmp("reads", z, n) ){
254857 else if( n==2 && 0==sqlite3_strnicmp("id", z, n) ){
254878 if( sqlite3_stricmp(zName, pAux->zFunc)==0 ) return pAux;
254881 /* No function of the specified name was found. Return 0. */
254882 return 0;
254890 Fts5Auxiliary *pAux = 0;
254897 sqlite3_stmt *pStmt = 0;
254899 SQLITE_PREPARE_PERSISTENT, &pStmt, 0);
254901 assert( rc==SQLITE_OK || pCsr->pRankArgStmt==0 );
254910 for(i=0; i<pCsr->nRankArg; i++){
254925 if( pAux==0 ){
254926 assert( pTab->p.base.zErrMsg==0 );
254945 char *zRank = 0;
254946 char *zRankArgs = 0;
254948 if( z==0 ){
254968 pCsr->zRankArgs = 0;
255015 sqlite3Fts5SetLocale(pConfig, 0, 0);
255023 int ret = 0;
255028 ** by both value_blob() and value_bytes() will be 0. If value_bytes() were
255034 && 0==memcmp(pBlob, FTS5_LOCALE_HDR(pConfig), FTS5_LOCALE_HDR_SIZE)
255064 int nLoc = 0;
255104 const char *pText = 0;
255105 int nText = 0;
255106 const char *pLoc = 0;
255107 int nLoc = 0;
255116 *pbFreeAndReset = 0;
255147 sqlite3_value *pRank = 0; /* rank MATCH ? expression (or NULL) */
255148 sqlite3_value *pRowidEq = 0; /* rowid = ? expression (or NULL) */
255149 sqlite3_value *pRowidLe = 0; /* rowid <= ? expression (or NULL) */
255150 sqlite3_value *pRowidGe = 0; /* rowid >= ? expression (or NULL) */
255155 int iIdxStr = 0;
255156 Fts5Expr *pExpr = 0;
255158 assert( pConfig->bLock==0 );
255161 memset(&pCsr->ePlan, 0, sizeof(Fts5Cursor) - ((u8*)&pCsr->ePlan-(u8*)pCsr));
255164 assert( pCsr->pStmt==0 );
255165 assert( pCsr->pExpr==0 );
255166 assert( pCsr->csrflags==0 );
255167 assert( pCsr->pRank==0 );
255168 assert( pCsr->zRank==0 );
255169 assert( pCsr->zRankArgs==0 );
255170 assert( pTab->pSortCsr==0 || nVal==0 );
255172 assert( pzErrmsg==0 || pzErrmsg==&pTab->p.base.zErrMsg );
255176 for(i=0; i<nVal; i++){
255182 char *zText = 0;
255183 int bFreeAndReset = 0;
255184 int bInternal = 0;
255188 if( zText==0 ) zText = "";
255193 iCol = 0;
255195 iCol = iCol*10 + (idxStr[iIdxStr]-'0');
255197 }while( idxStr[iIdxStr]>='0' && idxStr[iIdxStr]<='9' );
255199 if( zText[0]=='*' ){
255207 rc = sqlite3Fts5ExprNew(pConfig, 0, iCol, zText, &pExpr, pzErr);
255210 pExpr = 0;
255227 iCol = 0;
255229 iCol = iCol*10 + (idxStr[iIdxStr]-'0');
255231 }while( idxStr[iIdxStr]>='0' && idxStr[iIdxStr]<='9' );
255237 pExpr = 0;
255253 bOrderByRank = ((idxNum & FTS5_BI_ORDER_RANK) ? 1 : 0);
255254 pCsr->bDesc = bDesc = ((idxNum & FTS5_BI_ORDER_DESC) ? 1 : 0);
255281 assert( pRowidEq==0 && pRowidLe==0 && pRowidGe==0 && pRank==0 );
255282 assert( nVal==0 && bOrderByRank==0 && bDesc==0 );
255307 }else if( pConfig->zContent==0 ){
255318 if( pRowidEq!=0 ){
255342 return (CsrFlagTest(pCsr, FTS5CSR_EOF) ? 1 : 0);
255358 return sqlite3_column_int64(pCsr->pStmt, 0);
255374 assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
255376 *pRowid = 0;
255396 if( pCsr->pStmt==0 ){
255400 pTab->pStorage, eStmt, &pCsr->pStmt, (bErrormsg?&pTab->p.base.zErrMsg:0)
255402 assert( rc!=SQLITE_OK || pTab->p.base.zErrMsg==0 );
255458 int bError = 0;
255459 int bLoadConfig = 0;
255461 if( 0==sqlite3_stricmp("delete-all", zCmd) ){
255472 }else if( 0==sqlite3_stricmp("rebuild", zCmd) ){
255482 }else if( 0==sqlite3_stricmp("optimize", zCmd) ){
255484 }else if( 0==sqlite3_stricmp("merge", zCmd) ){
255487 }else if( 0==sqlite3_stricmp("integrity-check", zCmd) ){
255491 }else if( 0==sqlite3_stricmp("prefix-index", zCmd) ){
255494 }else if( 0==sqlite3_stricmp("flush", zCmd) ){
255508 rc = sqlite3Fts5StorageConfigValue(pTab->pStorage, zCmd, pVal, 0);
255529 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, &apVal[2], 0);
255542 rc = sqlite3Fts5StorageContentInsert(pTab->pStorage, 0, apVal, piRowid);
255580 int bSeenIndex = 0; /* Have seen modified indexed column */
255581 int bSeenIndexNC = 0; /* Have seen unmodified indexed column */
255584 for(ii=0; ii<pConfig->nCol; ii++){
255585 if( pConfig->abUnindexed[ii]==0 ){
255594 if( bSeenIndex==0 && bRowidModified==0 ){
255597 if( bSeenIndexNC || pConfig->bContentlessDelete==0 ){
255633 int eType0; /* value_type() of apVal[0] */
255639 assert( pVtab->zErrMsg==0 );
255641 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER
255642 || sqlite3_value_type(apVal[0])==SQLITE_NULL
255644 assert( pTab->p.pConfig->pzErrmsg==0 );
255645 if( pConfig->pgsz==0 ){
255655 eType0 = sqlite3_value_type(apVal[0]);
255662 && 0==sqlite3_stricmp("delete", z)
255699 if( fts5IsContentless(pTab, 1) && pConfig->bContentlessDelete==0 ){
255705 i64 iDel = sqlite3_value_int64(apVal[0]); /* Rowid to delete */
255706 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0, 0);
255716 if( pConfig->bLocale==0 ){
255718 for(ii=0; ii<pConfig->nCol; ii++){
255733 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0, 0);
255741 i64 iOld = sqlite3_value_int64(apVal[0]); /* Old rowid */
255743 int bContent = 0; /* Content only update */
255755 assert( bContent==0 );
255757 rc = sqlite3Fts5StorageDelete(pStorage, iOld, 0, 1);
255759 rc = sqlite3Fts5StorageDelete(pStorage, iNew, 0, 0);
255765 rc = sqlite3Fts5StorageContentInsert(pStorage, 0, apVal, pRowid);
255768 rc = sqlite3Fts5StorageDelete(pStorage, iOld, 0, 0);
255776 ** UNINDEXED columns. This is a no-op for contentless_unindexed=0
255784 rc = sqlite3Fts5StorageDelete(pStorage, iOld, 0, 1);
255793 pTab->p.pConfig->pzErrmsg = 0;
255803 fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
255806 pTab->p.pConfig->pzErrmsg = 0;
255816 fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_BEGIN, 0);
255828 fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_COMMIT, 0);
255839 fts5CheckTransactionState(pTab, FTS5_ROLLBACK, 0);
255841 pTab->p.pConfig->pgsz = 0;
255891 sqlite3Fts5SetLocale(pTab->pConfig, 0, 0);
255897 ** Implementation of xTokenize() API. This is just xTokenize_v2() with NULL/0
255906 return fts5ApiTokenize_v2(pCtx, pText, nText, 0, 0, pUserData, xToken);
255941 const char *pLoc = 0;
255942 int nLoc = 0;
255973 if( iCol<0 || iCol>=pTab->pConfig->nCol ){
255975 }else if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab), 0) ){
255976 *pz = 0;
255977 *pn = 0;
255979 rc = fts5SeekCursor(pCsr, 0);
256003 int bLive = (pCsr->pSorter==0);
256005 if( iPhrase<0 || iPhrase>=sqlite3Fts5ExprPhraseCount(pCsr->pExpr) ){
256010 *pa = 0;
256011 *pn = 0;
256019 if( aPopulator==0 ) rc = SQLITE_NOMEM;
256021 rc = fts5SeekCursor(pCsr, 0);
256023 for(i=0; i<pConfig->nCol && rc==SQLITE_OK; i++){
256024 const char *z = 0;
256025 int n = 0;
256046 int i1 = (iPhrase==0 ? 0 : pSorter->aIdx[iPhrase-1]);
256053 *pa = 0;
256054 *pn = 0;
256072 if( pCsr->aInstIter==0 ){
256079 int nInst = 0; /* Number instances seen so far */
256083 for(i=0; i<nIter && rc==SQLITE_OK; i++){
256096 for(i=0; i<nIter; i++){
256097 if( (aIter[i].bEof==0)
256098 && (iBest<0 || aIter[i].iPos<aIter[iBest].iPos)
256103 if( iBest<0 ) break;
256122 aInst[0] = iBest;
256125 assert( aInst[1]>=0 );
256143 if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_INST)==0
256159 if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_INST)==0
256162 if( iIdx<0 || iIdx>=pCsr->nInstCount ){
256188 if( (tflags & FTS5_TOKEN_COLOCATED)==0 ){
256206 for(i=0; i<pConfig->nCol; i++){
256207 if( pConfig->abUnindexed[i]==0 ){
256213 rc = fts5SeekCursor(pCsr, 0);
256214 for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
256215 if( pConfig->abUnindexed[i]==0 ){
256216 const char *z = 0;
256217 int n = 0;
256218 pCsr->aColumnSize[i] = 0;
256231 if( iCol<0 ){
256233 *pnToken = 0;
256234 for(i=0; i<pConfig->nCol; i++){
256240 *pnToken = 0;
256270 if( pData==0 ){
256287 void *pRet = 0;
256296 pData->pPtr = 0;
256297 pData->xDelete = 0;
256322 *piOff = 0;
256339 assert( pIter->a || n==0 );
256340 pIter->b = (pIter->a ? &pIter->a[n] : 0);
256341 *piCol = 0;
256342 *piOff = 0;
256361 pIter->a += fts5GetVarint32(&pIter->a[0], iIncr);
256371 if( pIter->a[0]==0x01 ) break;
256392 int i1 = (iPhrase==0 ? 0 : pSorter->aIdx[iPhrase-1]);
256399 assert( pIter->a || n==0 );
256400 pIter->b = (pIter->a ? &pIter->a[n] : 0);
256401 *piCol = 0;
256408 assert( pIter->a || n==0 );
256409 pIter->b = (pIter->a ? &pIter->a[n] : 0);
256410 if( n<=0 ){
256412 }else if( pIter->a[0]==0x01 ){
256415 *piCol = 0;
256448 if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_INST)==0
256451 if( iIdx<0 || iIdx>=pCsr->nInstCount ){
256484 *pzLocale = 0;
256485 *pnLocale = 0;
256488 if( iCol<0 || iCol>=pConfig->nCol ){
256491 pConfig->abUnindexed[iCol]==0
256492 && 0==fts5IsContentless((Fts5FullTable*)pCsr->base.pVtab, 1)
256495 rc = fts5SeekCursor(pCsr, 0);
256497 const char *zDummy = 0;
256498 int nDummy = 0;
256550 Fts5Cursor *pNew = 0;
256562 for(rc = fts5CursorFirst(pTab, pNew, 0);
256563 rc==SQLITE_OK && CsrFlagTest(pNew, FTS5CSR_EOF)==0;
256585 assert( pCsr->pAux==0 );
256589 pCsr->pAux = 0;
256606 char *zErr = 0;
256627 iCsrId = sqlite3_value_int64(argv[0]);
256630 if( pCsr==0 || (pCsr->ePlan==0 || pCsr->ePlan==FTS5_PLAN_SPECIAL) ){
256636 pTab->zErrMsg = 0;
256654 return 0;
256668 ** for phrase 0. The second (same disclaimer) contains the size of position
256678 memset(&val, 0, sizeof(Fts5Buffer));
256683 for(i=0; i<(nPhrase-1); i++){
256690 for(i=0; i<nPhrase; i++){
256701 for(i=0; rc==SQLITE_OK && i<(nPhrase-1); i++){
256709 for(i=0; rc==SQLITE_OK && i<nPhrase; i++){
256739 assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
256776 const char *z = 0;
256777 int n = 0;
256788 pConfig->pzErrmsg = 0;
256818 /* No function of the specified name was found. Return 0. */
256819 return 0;
256886 pTab->p.pConfig->pgsz = 0;
256906 sqlite3_int64 nName; /* Size of zName in bytes, including \0 */
256913 memset(pAux, 0, (size_t)nByte);
256954 sqlite3_int64 nName; /* Size of zName and its \0 terminator */
256967 if( pNew->pNext==0 ){
257000 Fts5VtoVTokenizer *pNew = 0;
257015 pNew = 0;
257051 return p->x2.xTokenize(p->pReal, pCtx, flags, pText, nText, 0, 0, xToken);
257066 assert( p->bV2Native==0 );
257088 Fts5TokenizerModule *pNew = 0;
257112 Fts5TokenizerModule *pNew = 0;
257136 Fts5TokenizerModule *pMod = 0;
257138 if( zName==0 ){
257142 if( sqlite3_stricmp(zName, pMod->zName)==0 ) break;
257171 *ppTokenizer = 0;
257172 *ppUserData = 0;
257194 if( pMod->bV2Native==0 ){
257201 memset(pTokenizer, 0, sizeof(*pTokenizer));
257202 *ppUserData = 0;
257215 Fts5TokenizerModule *pMod = 0;
257218 pMod = fts5LocateTokenizer(pConfig->pGlobal, nArg==0 ? 0 : azArg[0]);
257219 if( pMod==0 ){
257220 assert( nArg>0 );
257222 sqlite3Fts5ConfigErrmsg(pConfig, "no such tokenizer: %s", azArg[0]);
257224 int (*xCreate)(void*, const char**, int, Fts5Tokenizer**) = 0;
257234 (azArg?&azArg[1]:0), (nArg?nArg-1:0), &pConfig->t.pTok
257241 }else if( pMod->bV2Native==0 ){
257249 pConfig->t.pApi1 = 0;
257250 pConfig->t.pApi2 = 0;
257251 pConfig->t.pTok = 0;
257296 ppApi = (fts5_api**)sqlite3_value_pointer(apArg[0], "fts5_api_ptr");
257308 assert( nArg==0 );
257320 ** * The 4 bytes 0x00, 0xE0, 0xB2, 0xEb (FTS5_LOCALE_HEADER).
257322 ** * 0x00, followed by
257332 const char *zLocale = 0;
257333 int nLocale = 0;
257334 const char *zText = 0;
257335 int nText = 0;
257340 zLocale = (const char*)sqlite3_value_text(apArg[0]);
257341 nLocale = sqlite3_value_bytes(apArg[0]);
257346 if( zLocale==0 || zLocale[0]=='\0' ){
257350 u8 *pBlob = 0;
257351 u8 *pCsr = 0;
257352 int nBlob = 0;
257356 if( pBlob==0 ){
257366 (*pCsr++) = 0x00;
257384 sqlite3_result_value(pCtx, apArg[0]);
257397 for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
257398 if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
257400 return 0;
257418 assert( pzErr!=0 && *pzErr==0 );
257420 assert( pTab->p.pConfig->pzErrmsg==0 );
257422 rc = sqlite3Fts5StorageIntegrity(pTab->pStorage, 0);
257423 if( *pzErr==0 && rc!=SQLITE_OK ){
257424 if( (rc&0xff)==SQLITE_CORRUPT ){
257436 pTab->p.pConfig->pzErrmsg = 0;
257471 Fts5Global *pGlobal = 0;
257474 if( pGlobal==0 ){
257478 memset(pGlobal, 0, sizeof(Fts5Global));
257490 pGlobal->aLocaleHdr[0] ^= 0xF924976D;
257491 pGlobal->aLocaleHdr[1] ^= 0x16596E13;
257492 pGlobal->aLocaleHdr[2] ^= 0x7C80BEAA;
257493 pGlobal->aLocaleHdr[3] ^= 0x9B03A67F;
257504 db, "fts5", 1, SQLITE_UTF8, p, fts5Fts5Func, 0, 0
257509 db, "fts5_source_id", 0,
257511 p, fts5SourceIdFunc, 0, 0
257518 p, fts5LocaleFunc, 0, 0
257525 p, fts5InsttokenFunc, 0, 0
257639 #if FTS5_STMT_SCAN_ASC!=0
257681 assert( eStmt>=0 && eStmt<ArraySize(p->aStmt) );
257682 if( p->aStmt[eStmt]==0 ){
257701 char *zSql = 0;
257729 char *zBind = 0;
257740 for(i=0; rc==SQLITE_OK && i<(pC->nCol+1); i++){
257749 for(i=0; rc==SQLITE_OK && i<pC->nCol; i++){
257750 if( pC->abUnindexed[i]==0 ){
257779 if( zSql==0 ){
257785 rc = sqlite3_prepare_v3(pC->db, zSql, -1, f, &p->aStmt[eStmt], 0);
257818 if( zSql==0 ){
257821 rc = sqlite3_exec(db, zSql, 0, 0, pzErr);
257834 int rc = fts5ExecPrintf(pConfig->db, 0,
257843 rc = fts5ExecPrintf(pConfig->db, 0,
257849 rc = fts5ExecPrintf(pConfig->db, 0,
257864 *pRc = fts5ExecPrintf(pConfig->db, 0,
257899 char *zErr = 0;
257942 memset(p, 0, (size_t)nByte);
257953 if( zDefn==0 ){
257960 for(i=0; i<pConfig->nCol; i++){
257969 for(i=0; i<pConfig->nCol; i++){
257970 if( pConfig->abUnindexed[i]==0 ){
257976 rc = sqlite3Fts5CreateTable(pConfig, "content", zDefn, 0, pzErr);
257986 rc = sqlite3Fts5CreateTable(pConfig, "docsize", zCols, 0, pzErr);
257994 rc = sqlite3Fts5StorageConfigValue(p, "version", 0, FTS5_CURRENT_VERSION);
258000 *pp = 0;
258014 for(i=0; i<ArraySize(p->aStmt); i++){
258045 if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
258063 sqlite3_stmt *pSeek = 0;
258065 assert( p->pSavedRow==0 );
258066 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP+1, &pSeek, 0);
258096 sqlite3_stmt *pSeek = 0; /* SELECT to read row iDel from %_data */
258102 assert( bSaveRow==0 || apVal==0 );
258103 assert( bSaveRow==0 || bSaveRow==1 );
258106 if( apVal==0 ){
258109 p->pSavedRow = 0;
258111 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP+bSaveRow, &pSeek, 0);
258123 if( pConfig->abUnindexed[iCol-1]==0 ){
258124 sqlite3_value *pVal = 0;
258125 sqlite3_value *pFree = 0;
258126 const char *pText = 0;
258127 int nText = 0;
258128 const char *pLoc = 0;
258129 int nLoc = 0;
258131 assert( pSeek==0 || apVal==0 );
258132 assert( pSeek!=0 || apVal!=0 );
258147 if( pVal==0 ){
258163 ctx.szCol = 0;
258168 if( rc==SQLITE_OK && p->aTotalSize[iCol-1]<0 ){
258183 assert( p->pSavedRow==0 );
258198 assert( pStorage->pSavedRow==0
258202 pStorage->pSavedRow = 0;
258212 i64 iOrigin = 0;
258213 sqlite3_stmt *pLookup = 0;
258223 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
258232 if( rc==SQLITE_OK && iOrigin!=0 ){
258244 ** If there is no %_docsize table (as happens if the columnsize=0 option
258254 sqlite3_stmt *pReplace = 0;
258255 rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
258259 i64 iOrigin = 0;
258286 if( p->bTotalsValid==0 ){
258305 memset(&buf, 0, sizeof(buf));
258308 for(i=0; i<nCol; i++){
258330 sqlite3_stmt *pDel = 0;
258332 assert( pConfig->eContent!=FTS5_CONTENT_NORMAL || apVal==0 );
258356 rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_DOCSIZE, &pDel, 0);
258369 rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_CONTENT, &pDel, 0);
258388 p->bTotalsValid = 0;
258391 rc = fts5ExecPrintf(pConfig->db, 0,
258398 rc = fts5ExecPrintf(pConfig->db, 0,
258404 rc = fts5ExecPrintf(pConfig->db, 0,
258415 rc = sqlite3Fts5StorageConfigValue(p, "version", 0, FTS5_CURRENT_VERSION);
258421 Fts5Buffer buf = {0,0,0};
258423 sqlite3_stmt *pScan = 0;
258427 memset(&ctx, 0, sizeof(Fts5InsertCtx));
258439 i64 iRowid = sqlite3_column_int64(pScan, 0);
258442 rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
258443 for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
258444 ctx.szCol = 0;
258445 if( pConfig->abUnindexed[ctx.iCol]==0 ){
258446 int nText = 0; /* Size of pText in bytes */
258447 const char *pText = 0; /* Pointer to buffer containing text value */
258448 int nLoc = 0; /* Size of pLoc in bytes */
258449 const char *pLoc = 0; /* Pointer to buffer containing text value */
258521 sqlite3_stmt *pReplace = 0;
258522 rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
258558 sqlite3_stmt *pInsert = 0; /* Statement to write %_content table */
258562 assert( bReplace==0 || bReplace==1 );
258563 rc = fts5StorageGetStmt(p, FTS5_STMT_INSERT_CONTENT+bReplace, &pInsert, 0);
258580 if( pConfig->bLocale && bUnindexed==0 ){
258586 const char *pText = 0;
258587 const char *pLoc = 0;
258588 int nText = 0;
258589 int nLoc = 0;
258595 if( bUnindexed==0 ){
258630 memset(&buf, 0, sizeof(Fts5Buffer));
258635 rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
258637 for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
258638 ctx.szCol = 0;
258639 if( pConfig->abUnindexed[ctx.iCol]==0 ){
258640 int nText = 0; /* Size of pText in bytes */
258641 const char *pText = 0; /* Pointer to buffer containing text value */
258642 int nLoc = 0; /* Size of pText in bytes */
258643 const char *pLoc = 0; /* Pointer to buffer containing text value */
258695 if( zSql==0 ){
258698 sqlite3_stmt *pCnt = 0;
258699 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pCnt, 0);
258702 *pnRow = sqlite3_column_int64(pCnt, 0);
258748 if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
258760 iCol = 0;
258765 iPos = 0;
258766 iCol = 0;
258770 rc = sqlite3Fts5TermsetAdd(pTermset, 0, pToken, nToken, &bPresent);
258771 if( rc==SQLITE_OK && bPresent==0 ){
258773 pCtx->iRowid, iCol, iPos, 0, pToken, nToken
258777 for(ii=0; rc==SQLITE_OK && ii<pCtx->pConfig->nPrefix; ii++){
258782 if( bPresent==0 ){
258808 memset(&ctx, 0, sizeof(Fts5IntegrityCtx));
258813 memset(aTotalSize, 0, sizeof(i64) * pConfig->nCol);
258821 rc = fts5StorageGetStmt(p, FTS5_STMT_SCAN, &pScan, 0);
258826 ctx.iRowid = sqlite3_column_int64(pScan, 0);
258827 ctx.szCol = 0;
258834 for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
258835 if( pConfig->abUnindexed[i]==0 ){
258836 const char *pText = 0;
258837 int nText = 0;
258838 const char *pLoc = 0;
258839 int nLoc = 0;
258859 ctx.szCol = 0;
258876 /* If this is not a columnsize=0 database, check that the number
258888 ctx.pTermset = 0;
258893 ctx.pTermset = 0;
258904 rc = fts5StorageLoadTotals(p, 0);
258905 for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
258913 i64 nRow = 0;
258918 i64 nRow = 0;
258953 p->aStmt[eStmt] = 0;
258972 if( p->aStmt[eStmt]==0 ){
258985 int iOff = 0;
258986 for(i=0; i<nCol; i++){
259003 sqlite3_stmt *pLookup = 0; /* Statement to query %_docsize */
259007 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
259013 const u8 *aBlob = sqlite3_column_blob(pLookup, 0);
259014 int nBlob = sqlite3_column_bytes(pLookup, 0);
259015 if( 0==fts5StorageDecodeSizeArray(aCol, nCol, aBlob, nBlob) ){
259016 bCorrupt = 0;
259031 int rc = fts5StorageLoadTotals(p, 0);
259033 *pnToken = 0;
259034 if( iCol<0 ){
259036 for(i=0; i<p->pConfig->nCol; i++){
259049 int rc = fts5StorageLoadTotals(p, 0);
259057 if( p->nTotalRow<=0 ) rc = FTS5_CORRUPT;
259071 p->bTotalsValid = 0;
259082 p->bTotalsValid = 0;
259092 sqlite3_stmt *pReplace = 0;
259093 int rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_CONFIG, &pReplace, 0);
259140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00..0x0F */
259141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10..0x1F */
259142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20..0x2F */
259143 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0x30..0x3F */
259144 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40..0x4F */
259145 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 0x50..0x5F */
259146 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60..0x6F */
259147 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 0x70..0x7F */
259161 for(i=0; zArg[i]; i++){
259162 if( (zArg[i] & 0x80)==0 ){
259184 AsciiTokenizer *p = 0;
259190 if( p==0 ){
259194 memset(p, 0, sizeof(AsciiTokenizer));
259196 for(i=0; rc==SQLITE_OK && i<nArg; i+=2){
259198 if( 0==sqlite3_stricmp(azArg[i], "tokenchars") ){
259201 if( 0==sqlite3_stricmp(azArg[i], "separators") ){
259202 fts5AsciiAddExceptions(p, zArg, 0);
259209 p = 0;
259221 for(i=0; i<nByte; i++){
259241 int is = 0;
259254 while( is<nText && ((pText[is]&0x80)==0 && a[(int)pText[is]]==0) ){
259261 while( ie<nText && ((pText[ie]&0x80) || a[(int)pText[ie]] ) ){
259270 if( pFold==0 ){
259279 rc = xToken(pCtx, 0, pFold, nByte, is, ie);
259301 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
259302 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
259303 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
259304 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
259305 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
259306 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
259307 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
259308 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
259313 if( c>=0xc0 ){ \
259314 c = sqlite3Utf8Trans1[c-0xc0]; \
259315 while( zIn<zTerm && (*zIn & 0xc0)==0x80 ){ \
259316 c = (c<<6) + (0x3f & *(zIn++)); \
259318 if( c<0x80 \
259319 || (c&0xFFFFF800)==0xD800 \
259320 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
259325 if( c<0x00080 ){ \
259326 *zOut++ = (unsigned char)(c&0xFF); \
259328 else if( c<0x00800 ){ \
259329 *zOut++ = 0xC0 + (unsigned char)((c>>6)&0x1F); \
259330 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
259332 else if( c<0x10000 ){ \
259333 *zOut++ = 0xE0 + (unsigned char)((c>>12)&0x0F); \
259334 *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
259335 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
259337 *zOut++ = 0xF0 + (unsigned char)((c>>18) & 0x07); \
259338 *zOut++ = 0x80 + (unsigned char)((c>>12) & 0x3F); \
259339 *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
259340 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
259347 if( ((unsigned char)(*(zIn++)))>=0xc0 ){ \
259348 while( (((unsigned char)*zIn) & 0xc0)==0x80 ){ zIn++; } \
259365 #define FTS5_REMOVE_DIACRITICS_NONE 0
259372 int bTokenChars /* 1 for 'tokenchars', 0 for 'separators' */
259378 if( n>0 ){
259393 assert( (bToken==0 || bToken==1) );
259394 assert( (bTokenChars==0 || bTokenChars==1) );
259395 if( bToken!=bTokenChars && sqlite3Fts5UnicodeIsdiacritic(iCode)==0 ){
259397 for(i=0; i<nNew; i++){
259420 if( p->nException>0 ){
259422 int iLo = 0;
259437 return 0;
259461 while( *z!=' ' && *z!='\t' && *z!='\0' ) z++;
259477 Unicode61Tokenizer *p = 0; /* New tokenizer object */
259488 memset(p, 0, sizeof(Unicode61Tokenizer));
259493 if( p->aFold==0 ){
259498 for(i=0; rc==SQLITE_OK && i<nArg; i+=2){
259499 if( 0==sqlite3_stricmp(azArg[i], "categories") ){
259507 for(i=0; rc==SQLITE_OK && i<nArg; i+=2){
259509 if( 0==sqlite3_stricmp(azArg[i], "remove_diacritics") ){
259510 if( (zArg[0]!='0' && zArg[0]!='1' && zArg[0]!='2') || zArg[1] ){
259513 p->eRemoveDiacritic = (zArg[0] - '0');
259520 if( 0==sqlite3_stricmp(azArg[i], "tokenchars") ){
259523 if( 0==sqlite3_stricmp(azArg[i], "separators") ){
259524 rc = fts5UnicodeAddExceptions(p, zArg, 0);
259526 if( 0==sqlite3_stricmp(azArg[i], "categories") ){
259537 p = 0;
259588 if( *zCsr & 0x80 ) {
259613 if( aFold==0 ){
259625 if( *zCsr & 0x80 ){
259636 }else if( a[*zCsr]==0 ){
259652 rc = xToken(pCtx, 0, aFold, zOut-aFold, is, ie);
259699 void *pUserdata = 0;
259701 fts5_tokenizer_v2 *pV2 = 0;
259703 if( nArg>0 ){
259704 zBase = azArg[0];
259709 memset(pRet, 0, sizeof(PorterTokenizer));
259715 int nArg2 = (nArg>0 ? nArg-1 : 0);
259716 const char **az2 = (nArg2 ? &azArg[1] : 0);
259723 pRet = 0;
259745 #if 0
259755 if( 0==memcmp(&aBuf[nBuf - p->nSuffix], p->zSuffix, p->nSuffix) ) break;
259760 if( p->xCond==0 || p->xCond(aBuf, nStem) ){
259782 for(i=0; i<nStem; i++){
259783 if( 0==(bCons = !fts5PorterIsVowel(zStem[i], bCons)) ) break;
259790 return 0;
259793 /* porter rule condition: (m > 0) */
259795 return !!fts5PorterGobbleVC(zStem, nStem, 0);
259801 n = fts5PorterGobbleVC(zStem, nStem, 0);
259805 return 0;
259811 n = fts5PorterGobbleVC(zStem, nStem, 0);
259812 if( n && 0==fts5PorterGobbleVC(&zStem[n], nStem-n, 1) ){
259815 return 0;
259821 return 0;
259824 int mask = 0;
259825 int bCons = 0;
259826 for(i=0; i<nStem; i++){
259828 assert( bCons==0 || bCons==1 );
259831 return ((mask & 0x0007)==0x0005);
259837 assert( nStem>0 );
259845 for(i=0; i<nStem; i++){
259846 if( fts5PorterIsVowel(zStem[i], i>0) ){
259850 return 0;
259860 int ret = 0;
259865 if( nBuf>2 && 0==memcmp("al", &aBuf[nBuf-2], 2) ){
259873 if( nBuf>4 && 0==memcmp("ance", &aBuf[nBuf-4], 4) ){
259877 }else if( nBuf>4 && 0==memcmp("ence", &aBuf[nBuf-4], 4) ){
259885 if( nBuf>2 && 0==memcmp("er", &aBuf[nBuf-2], 2) ){
259893 if( nBuf>2 && 0==memcmp("ic", &aBuf[nBuf-2], 2) ){
259901 if( nBuf>4 && 0==memcmp("able", &aBuf[nBuf-4], 4) ){
259905 }else if( nBuf>4 && 0==memcmp("ible", &aBuf[nBuf-4], 4) ){
259913 if( nBuf>3 && 0==memcmp("ant", &aBuf[nBuf-3], 3) ){
259917 }else if( nBuf>5 && 0==memcmp("ement", &aBuf[nBuf-5], 5) ){
259921 }else if( nBuf>4 && 0==memcmp("ment", &aBuf[nBuf-4], 4) ){
259925 }else if( nBuf>3 && 0==memcmp("ent", &aBuf[nBuf-3], 3) ){
259933 if( nBuf>3 && 0==memcmp("ion", &aBuf[nBuf-3], 3) ){
259937 }else if( nBuf>2 && 0==memcmp("ou", &aBuf[nBuf-2], 2) ){
259945 if( nBuf>3 && 0==memcmp("ism", &aBuf[nBuf-3], 3) ){
259953 if( nBuf>3 && 0==memcmp("ate", &aBuf[nBuf-3], 3) ){
259957 }else if( nBuf>3 && 0==memcmp("iti", &aBuf[nBuf-3], 3) ){
259965 if( nBuf>3 && 0==memcmp("ous", &aBuf[nBuf-3], 3) ){
259973 if( nBuf>3 && 0==memcmp("ive", &aBuf[nBuf-3], 3) ){
259981 if( nBuf>3 && 0==memcmp("ize", &aBuf[nBuf-3], 3) ){
259994 int ret = 0;
259999 if( nBuf>2 && 0==memcmp("at", &aBuf[nBuf-2], 2) ){
260007 if( nBuf>2 && 0==memcmp("bl", &aBuf[nBuf-2], 2) ){
260015 if( nBuf>2 && 0==memcmp("iz", &aBuf[nBuf-2], 2) ){
260028 int ret = 0;
260033 if( nBuf>7 && 0==memcmp("ational", &aBuf[nBuf-7], 7) ){
260038 }else if( nBuf>6 && 0==memcmp("tional", &aBuf[nBuf-6], 6) ){
260047 if( nBuf>4 && 0==memcmp("enci", &aBuf[nBuf-4], 4) ){
260052 }else if( nBuf>4 && 0==memcmp("anci", &aBuf[nBuf-4], 4) ){
260061 if( nBuf>4 && 0==memcmp("izer", &aBuf[nBuf-4], 4) ){
260070 if( nBuf>4 && 0==memcmp("logi", &aBuf[nBuf-4], 4) ){
260079 if( nBuf>3 && 0==memcmp("bli", &aBuf[nBuf-3], 3) ){
260084 }else if( nBuf>4 && 0==memcmp("alli", &aBuf[nBuf-4], 4) ){
260089 }else if( nBuf>5 && 0==memcmp("entli", &aBuf[nBuf-5], 5) ){
260094 }else if( nBuf>3 && 0==memcmp("eli", &aBuf[nBuf-3], 3) ){
260099 }else if( nBuf>5 && 0==memcmp("ousli", &aBuf[nBuf-5], 5) ){
260108 if( nBuf>7 && 0==memcmp("ization", &aBuf[nBuf-7], 7) ){
260113 }else if( nBuf>5 && 0==memcmp("ation", &aBuf[nBuf-5], 5) ){
260118 }else if( nBuf>4 && 0==memcmp("ator", &aBuf[nBuf-4], 4) ){
260127 if( nBuf>5 && 0==memcmp("alism", &aBuf[nBuf-5], 5) ){
260132 }else if( nBuf>7 && 0==memcmp("iveness", &aBuf[nBuf-7], 7) ){
260137 }else if( nBuf>7 && 0==memcmp("fulness", &aBuf[nBuf-7], 7) ){
260142 }else if( nBuf>7 && 0==memcmp("ousness", &aBuf[nBuf-7], 7) ){
260151 if( nBuf>5 && 0==memcmp("aliti", &aBuf[nBuf-5], 5) ){
260156 }else if( nBuf>5 && 0==memcmp("iviti", &aBuf[nBuf-5], 5) ){
260161 }else if( nBuf>6 && 0==memcmp("biliti", &aBuf[nBuf-6], 6) ){
260175 int ret = 0;
260180 if( nBuf>4 && 0==memcmp("ical", &aBuf[nBuf-4], 4) ){
260189 if( nBuf>4 && 0==memcmp("ness", &aBuf[nBuf-4], 4) ){
260197 if( nBuf>5 && 0==memcmp("icate", &aBuf[nBuf-5], 5) ){
260202 }else if( nBuf>5 && 0==memcmp("iciti", &aBuf[nBuf-5], 5) ){
260211 if( nBuf>3 && 0==memcmp("ful", &aBuf[nBuf-3], 3) ){
260219 if( nBuf>5 && 0==memcmp("ative", &aBuf[nBuf-5], 5) ){
260227 if( nBuf>5 && 0==memcmp("alize", &aBuf[nBuf-5], 5) ){
260241 int ret = 0;
260246 if( nBuf>3 && 0==memcmp("eed", &aBuf[nBuf-3], 3) ){
260251 }else if( nBuf>2 && 0==memcmp("ed", &aBuf[nBuf-2], 2) ){
260260 if( nBuf>3 && 0==memcmp("ing", &aBuf[nBuf-3], 3) ){
260316 if( fts5PorterStep1B2(aBuf, &nBuf)==0 ){
260318 if( fts5PorterIsVowel(c, 0)==0
260339 assert( nBuf>0 );
260408 TrigramTokenizer *pNew = 0;
260415 if( pNew==0 ){
260419 pNew->iFoldParam = 0;
260421 for(i=0; rc==SQLITE_OK && i<nArg; i+=2){
260423 if( 0==sqlite3_stricmp(azArg[i], "case_sensitive") ){
260424 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1] ){
260427 pNew->bFold = (zArg[0]=='0');
260429 }else if( 0==sqlite3_stricmp(azArg[i], "remove_diacritics") ){
260430 if( (zArg[0]!='0' && zArg[0]!='1' && zArg[0]!='2') || zArg[1] ){
260433 pNew->iFoldParam = (zArg[0]!='0') ? 2 : 0;
260440 if( pNew->iFoldParam!=0 && pNew->bFold==0 ){
260446 pNew = 0;
260470 const unsigned char *zEof = (zIn ? &zIn[nText] : 0);
260471 u32 iCode = 0;
260477 for(ii=0; ii<3; ii++){
260483 }while( iCode==0 );
260503 iCode = 0;
260508 }while( iCode==0 );
260511 rc = xToken(pCtx, 0, aBuf, zOut-aBuf, aStart[0], iNext);
260512 if( iCode==0 || rc!=SQLITE_OK ) break;
260523 aStart[0] = aStart[1];
260539 ** "trigram" tokenizer, case_sensitive=0 (the default) - FTS5_PATTERN_LIKE
260548 if( p->iFoldParam==0 ){
260561 return (p->nArg>=1 && 0==sqlite3_stricmp(p->azArg[0], "trigram"));
260581 for(i=0; rc==SQLITE_OK && i<ArraySize(aBuiltin); i++){
260586 0
260600 0
260638 0, 1797, 1848, 1859, 1891, 1928, 1940, 1995,
260655 #define HIBIT ((unsigned char)0x80)
260657 '\0', 'a', 'c', 'e', 'i', 'n',
260667 'o'|HIBIT, 'y', '\0', '\0', '\0', '\0',
260668 '\0', '\0', '\0', '\0', 'a', 'b',
260680 unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
260681 int iRes = 0;
260682 int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
260683 int iLo = 0;
260694 if( bComplex==0 && (aChar[iRes] & 0x80) ) return c;
260695 return (c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : ((int)aChar[iRes] & 0x7F);
260704 unsigned int mask0 = 0x08029FDF;
260705 unsigned int mask1 = 0x000361F8;
260706 if( c<768 || c>817 ) return 0;
260734 ** case equivalent is ((C + aiOff[flags>>1]) & 0xFFFF).
260749 {386, 1, 4}, {390, 44, 1}, {391, 0, 1},
260750 {393, 42, 2}, {395, 0, 1}, {398, 32, 1},
260751 {399, 38, 1}, {400, 40, 1}, {401, 0, 1},
260753 {407, 48, 1}, {408, 0, 1}, {412, 52, 1},
260755 {422, 60, 1}, {423, 0, 1}, {425, 60, 1},
260756 {428, 0, 1}, {430, 60, 1}, {431, 0, 1},
260758 {440, 0, 1}, {444, 0, 1}, {452, 2, 1},
260759 {453, 0, 1}, {455, 2, 1}, {456, 0, 1},
260763 {546, 1, 18}, {570, 70, 1}, {571, 0, 1},
260764 {573, 108, 1}, {574, 68, 1}, {577, 0, 1},
260767 {886, 0, 1}, {902, 18, 1}, {904, 16, 3},
260769 {931, 14, 9}, {962, 0, 1}, {975, 4, 1},
260773 {1015, 0, 1}, {1017, 152, 1}, {1018, 0, 1},
260789 {8579, 0, 1}, {9398, 10, 26}, {11264, 22, 47},
260790 {11360, 0, 1}, {11362, 88, 1}, {11363, 102, 1},
260793 {11378, 0, 1}, {11381, 0, 1}, {11390, 78, 2},
260794 {11392, 1, 100}, {11499, 1, 4}, {11506, 0, 1},
260797 {42878, 1, 10}, {42891, 0, 1}, {42893, 74, 1},
260822 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
260823 int iLo = 0;
260826 assert( c>aEntry[0].iCode );
260830 if( cmp>=0 ){
260838 assert( iRes>=0 && c>=aEntry[iRes].iCode );
260840 if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
260841 ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
260842 assert( ret>0 );
260859 aArray[0] = 1;
260860 switch( zCat[0] ){
260976 return 0;
260980 0, 1471, 1753, 1760, 1760, 1760, 1760, 1760, 1760, 1760,
260984 0, 32, 33, 36, 37, 40, 41, 42, 43, 44,
261131 65532, 0, 13, 40, 60, 63, 80, 128, 256, 263,
261159 63045, 63104, 63232, 0, 42710, 42752, 46900, 46912, 47133, 63488,
261160 1, 32, 256, 0, 65533,
261350 return 0;
261354 iKey = (iCode & 0xFFFF);
261366 if( iRes<0 ) return 0;
261367 if( iKey>=(aFts5UnicodeMap[iRes]+(aFts5UnicodeData[iRes]>>5)) ) return 0;
261368 ret = aFts5UnicodeData[iRes] & 0x1F;
261370 return ((iKey - aFts5UnicodeMap[iRes]) & 0x01) ? 5 : 9;
261374 int i = 0;
261375 int iTbl = 0;
261377 int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
261384 aAscii[0] = 0; /* 0x00 is never a token character */
261416 if (!(a&0x80))
261418 /* Values between 0 and 127 */
261427 if (!(b&0x80))
261430 a &= 0x7f;
261441 if (!(a&0x80))
261444 a &= (0x7f<<14)|(0x7f);
261445 b &= 0x7f;
261465 *v = ((u32)v64) & 0x7FFFFFFF;
261477 ** SLOT_2_0 A mask for (0x7f<<14) | 0x7f
261479 ** SLOT_4_2_0 A mask for (0x7f<<28) | SLOT_2_0
261481 #define SLOT_2_0 0x001fc07f
261482 #define SLOT_4_2_0 0xf01fc07f
261485 ** Read a 64-bit variable-length integer from memory starting at p[0].
261493 if (!(a&0x80))
261502 if (!(b&0x80))
261504 a &= 0x7f;
261512 assert( SLOT_2_0 == ((0x7f<<14) | (0x7f)) );
261513 assert( SLOT_4_2_0 == ((0xfU<<28) | (0x7f<<14) | (0x7f)) );
261519 if (!(a&0x80))
261522 b &= 0x7f;
261535 if (!(b&0x80))
261539 /* a &= (0x7f<<14)|(0x7f); */
261550 /* a &= (0x7f<<14)|(0x7f); */
261559 if (!(a&0x80))
261562 /* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
261563 /* b &= (0x7f<<14)|(0x7f); */
261580 if (!(b&0x80))
261583 /* b &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
261596 if (!(a&0x80))
261613 if (!(b&0x80))
261617 /* a &= (0x7f<<14)|(0x7f); */
261631 /* a &= (0x7f<<29)|(0x7f<<15)|(0xff); */
261638 b &= 0x7f;
261651 ** A = 0xxxxxxx 7 bits of data and one flag bit
261673 ** Write a 64-bit variable-length integer to memory starting at p[0].
261685 if( v & (((u64)0xff000000)<<32) ){
261688 for(i=7; i>=0; i--){
261689 p[i] = (u8)((v & 0x7f) | 0x80);
261694 n = 0;
261696 buf[n++] = (u8)((v & 0x7f) | 0x80);
261698 }while( v!=0 );
261699 buf[0] &= 0x7f;
261701 for(i=0, j=n-1; j>=0; j--, i++){
261708 if( v<=0x7f ){
261709 p[0] = v&0x7f;
261712 if( v<=0x3fff ){
261713 p[0] = ((v>>7)&0x7f)|0x80;
261714 p[1] = v&0x7f;
261722 #if 0
261814 #define FTS5_VOCAB_COL 0
261825 #define FTS5_VOCAB_TERM_EQ 0x0100
261826 #define FTS5_VOCAB_TERM_GE 0x0200
261827 #define FTS5_VOCAB_TERM_LE 0x0400
261829 #define FTS5_VOCAB_COLUSED_MASK 0xFF
261843 if( sqlite3_stricmp(zCopy, "col")==0 ){
261847 if( sqlite3_stricmp(zCopy, "row")==0 ){
261850 if( sqlite3_stricmp(zCopy, "instance")==0 ){
261888 ** argv[0] -> module name ("fts5vocab")
261917 Fts5VocabTable *pRet = 0;
261921 bDb = (argc==6 && strlen(argv[1])==4 && memcmp("temp", argv[1], 4)==0);
261923 if( argc!=5 && bDb==0 ){
261933 int eType = 0;
261937 assert( eType>=0 && eType<ArraySize(azSchema) );
262007 int nArg = 0;
262013 for(i=0; i<pInfo->nConstraint; i++){
262015 if( p->usable==0 ) continue;
262016 if( p->iColumn==0 ){ /* term column */
262025 if( iTermEq>=0 ){
262031 if( iTermGe>=0 ){
262036 if( iTermLe>=0 ){
262044 ** the "term" column (column 0). So if the user has requested this
262049 && pInfo->aOrderBy[0].iColumn==0
262050 && pInfo->aOrderBy[0].desc==0
262067 Fts5Table *pFts5 = 0;
262068 Fts5VocabCursor *pCsr = 0;
262070 sqlite3_stmt *pStmt = 0;
262071 char *zSql = 0;
262084 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pStmt, 0);
262087 assert( rc==SQLITE_OK || pStmt==0 );
262092 i64 iId = sqlite3_column_int64(pStmt, 0);
262095 pTab->bBusy = 0;
262098 if( pFts5==0 ){
262100 pStmt = 0;
262131 pCsr->rowid = 0;
262134 pCsr->pStruct = 0;
262135 pCsr->pIter = 0;
262138 pCsr->zLeTerm = 0;
262139 pCsr->bEof = 0;
262164 if( pCsr->nLeTerm>=0 ){
262167 if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
262184 assert( sqlite3Fts5IterEof(pIter)==0 );
262185 assert( pCsr->bEof==0 );
262189 pCsr->iInstPos = 0;
262190 pCsr->iInstOff = 0;
262237 assert( nTerm>=0 );
262238 if( pCsr->nLeTerm>=0 ){
262241 if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
262248 memset(pCsr->aCnt, 0, nCol * sizeof(i64));
262249 memset(pCsr->aDoc, 0, nCol * sizeof(i64));
262250 pCsr->iCol = 0;
262256 i64 iPos = 0; /* 64-bit position read from poslist */
262257 int iOff = 0; /* Current offset within position list */
262266 if( eDetail==FTS5_DETAIL_FULL && (pCsr->colUsed & 0x04) ){
262275 pCsr->aCnt[0]++;
262279 pCsr->aDoc[0]++;
262285 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){
262298 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff,&iPos) ){
262299 assert_nc( iPos>=0 && iPos<nCol );
262308 pCsr->aDoc[0]++;
262325 || (nTerm>0 && memcmp(zTerm, pCsr->term.p, nTerm))
262335 if( rc==SQLITE_OK && pCsr->bEof==0 && pTab->eType==FTS5_VOCAB_COL ){
262336 for(/* noop */; pCsr->iCol<nCol && pCsr->aDoc[pCsr->iCol]==0; pCsr->iCol++);
262359 int iVal = 0;
262361 const char *zTerm = 0;
262362 int nTerm = 0;
262364 sqlite3_value *pEq = 0;
262365 sqlite3_value *pGe = 0;
262366 sqlite3_value *pLe = 0;
262387 if( zCopy==0 ) zCopy = "";
262390 if( pCsr->zLeTerm==0 ){
262400 rc = sqlite3Fts5IndexQuery(pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
262435 i64 iVal = 0;
262437 if( iCol==0 ){
262456 iVal = pCsr->aDoc[0];
262458 iVal = pCsr->aCnt[0];
262473 if( ii>=0 && ii<pCsr->pFts5->pConfig->nCol ){
262490 if( iVal>0 ) sqlite3_result_int64(pCtx, iVal);
262523 /* xUpdate */ 0,
262524 /* xBegin */ 0,
262525 /* xSync */ 0,
262526 /* xCommit */ 0,
262527 /* xRollback */ 0,
262528 /* xFindFunction */ 0,
262529 /* xRename */ 0,
262530 /* xSavepoint */ 0,
262531 /* xRelease */ 0,
262532 /* xRollbackTo */ 0,
262533 /* xShadowName */ 0,
262534 /* xIntegrity */ 0
262538 return sqlite3_create_module_v2(db, "fts5vocab", &fts5Vocab, p, 0);
262633 #define STMT_COLUMN_SQL 0 /* SQL for the statement */
262656 if( pNew==0 ) return SQLITE_NOMEM;
262657 memset(pNew, 0, sizeof(*pNew));
262677 if( pCur==0 ) return SQLITE_NOMEM;
262678 memset(pCur, 0, sizeof(*pCur));
262685 StmtRow *pRow = 0;
262686 StmtRow *pNext = 0;
262691 pCur->pRow = 0;
262750 return pCur->pRow==0;
262765 sqlite3_stmt *p = 0;
262767 StmtRow **ppRow = 0;
262775 for(p=sqlite3_next_stmt(pCur->db, 0); p; p=sqlite3_next_stmt(pCur->db, p)){
262777 sqlite3_int64 nSql = zSql ? strlen(zSql)+1 : 0;
262780 if( pNew==0 ) return SQLITE_NOMEM;
262781 memset(pNew, 0, sizeof(StmtRow));
262790 p, SQLITE_STMTSTATUS_FULLSCAN_STEP, 0
262793 p, SQLITE_STMTSTATUS_SORT, 0
262796 p, SQLITE_STMTSTATUS_AUTOINDEX, 0
262799 p, SQLITE_STMTSTATUS_VM_STEP, 0
262802 p, SQLITE_STMTSTATUS_REPREPARE, 0
262805 p, SQLITE_STMTSTATUS_RUN, 0
262808 p, SQLITE_STMTSTATUS_MEMUSED, 0
262839 0, /* iVersion */
262840 0, /* xCreate */
262844 0, /* xDestroy */
262852 0, /* xUpdate */
262853 0, /* xBegin */
262854 0, /* xSync */
262855 0, /* xCommit */
262856 0, /* xRollback */
262857 0, /* xFindMethod */
262858 0, /* xRename */
262859 0, /* xSavepoint */
262860 0, /* xRelease */
262861 0, /* xRollbackTo */
262862 0, /* xShadowName */
262863 0 /* xIntegrity */
262871 rc = sqlite3_create_module(db, "sqlite_stmt", &stmtModule, 0);