Lines Matching +full:0 +full:xff3c0000
130 #define HAVE_LOG2 0
163 #define SQLITE_OS_OTHER 0
166 #define SQLITE_ENABLE_LOCKING_STYLE 0
170 #define OS_VXWORKS 0
213 ** value of 0 means that compiler is not being used. The
215 ** optimizations, and hence set all compiler macros to 0
227 # define GCC_VERSION 0
232 # define MSVC_VERSION 0
240 # if MSVC_VERSION==0 || MSVC_VERSION>=1800
243 # define SQLITE_HAVE_C99_MATH_FUNCS (0)
353 #if 0
480 ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
481 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
506 ** ^The sqlite3_compileoption_used() function returns 0 or 1
529 # define sqlite3_compileoption_used(X) 0
530 # define sqlite3_compileoption_get(X) ((void*)0)
538 ** [SQLITE_THREADSAFE] compile-time option being set to 0.
543 ** [SQLITE_THREADSAFE] macro is 0,
601 ** between 0 and +18446744073709551615 inclusive.
759 #define SQLITE_OK 0 /* Successful result */
908 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
909 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
910 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
911 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
912 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
913 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
914 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
915 #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
916 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
917 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
918 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
919 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
920 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
921 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
922 #define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */
923 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
924 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
925 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
926 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
927 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
928 #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
929 #define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */
931 /* Reserved: 0x00F00000 */
933 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
969 #define SQLITE_IOCAP_ATOMIC 0x00000001
970 #define SQLITE_IOCAP_ATOMIC512 0x00000002
971 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
972 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
973 #define SQLITE_IOCAP_ATOMIC4K 0x00000010
974 #define SQLITE_IOCAP_ATOMIC8K 0x00000020
975 #define SQLITE_IOCAP_ATOMIC16K 0x00000040
976 #define SQLITE_IOCAP_ATOMIC32K 0x00000080
977 #define SQLITE_IOCAP_ATOMIC64K 0x00000100
978 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
979 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
980 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
981 #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
982 #define SQLITE_IOCAP_IMMUTABLE 0x00002000
983 #define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000
996 #define SQLITE_LOCK_NONE 0 /* xUnlock() only */
1028 #define SQLITE_SYNC_NORMAL 0x00002
1029 #define SQLITE_SYNC_FULL 0x00003
1030 #define SQLITE_SYNC_DATAONLY 0x00010
1284 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
1294 ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
1503 ** currently has an SQL transaction open on the database. It is set to 0 if
1620 ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
1621 ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
1627 ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
1839 #define SQLITE_ACCESS_EXISTS 0
1874 ** between 0 and this upper bound as its "offset" argument.
2055 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
2108 ** As of SQLite version 3.42.0, the complete set of anytime configuration
2128 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2143 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2159 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2205 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
2270 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2283 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2369 ** fourth parameter. If the fourth parameter is 0, then the database connection
2471 ** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off. If SQLite
2549 ** The first argument is an integer which is 0 to disable FK enforcement,
2552 ** is written 0 or 1 to indicate whether FK enforcement is off or on
2560 ** The first argument is an integer which is 0 to disable triggers,
2563 ** is written 0 or 1 to indicate whether triggers are disabled or enabled
2568 ** SQLite version 3.35.0, TEMP triggers are still allowed even if
2577 ** The first argument is an integer which is 0 to disable views,
2580 ** is written 0 or 1 to indicate whether views are disabled or enabled
2585 ** SQLite version 3.35.0, TEMP views are still allowed even if
2596 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2600 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2613 ** this interface is 0, then both the C-API and the SQL function are disabled.
2617 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2641 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
2642 ** have been disabled - 0 if they are not disabled, 1 if they are.
2654 ** The first argument to this setting is an integer which is 0 to disable
2657 ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
2669 ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
2685 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
2686 ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
2687 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2716 ** The first argument to this setting is an integer which is 0 to disable
2719 ** integer into which is written 0 or 1 to indicate whether the writable_schema
2727 ** behaves as it did prior to [version 3.24.0] (2018-06-04). See the
2778 ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
2780 ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
2782 ** all the way back to version 3.0.0, and so this setting is of little
2785 ** 3.0.0.
2789 ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2802 ** an integer.. The first argument is 1, 0, or -1 to enable, disable, or
2817 ** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
2819 ** then 0 or 1 is written into the integer that the second argument points to
3071 ** It returns 1 if an interrupt is currently in effect, or 0 otherwise.
3091 ** ^These routines return 0 if the statement is incomplete. ^If a
3133 ** busy callback returns 0, then no additional attempts are made to
3181 ** the handler returns 0 which causes [sqlite3_step()] to return
3239 ** azResult[0] = "Name";
3617 #define SQLITE_COPY 0 /* No longer used */
3709 #define SQLITE_TRACE_STMT 0x01
3710 #define SQLITE_TRACE_PROFILE 0x02
3711 #define SQLITE_TRACE_ROW 0x04
3712 #define SQLITE_TRACE_CLOSE 0x08
3787 ** SQLite version 3.41.0, the progress handler callback might also be
4114 ** parameter and returns true (1) or false (0) according to the value
4118 ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
4122 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4132 ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
4142 ** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F
4144 ** in addition to the main database file. Prior to version 3.31.0, these
4455 #define SQLITE_LIMIT_LENGTH 0
4503 #define SQLITE_PREPARE_PERSISTENT 0x01
4504 #define SQLITE_PREPARE_NORMALIZE 0x02
4505 #define SQLITE_PREPARE_NO_VTAB 0x04
4755 ** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
4782 ** began with EXPLAIN or EXPLAIN QUERY PLAN, but sqlite3_stmt_explain(S,0)
4837 ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
4991 ** [pointer passing interface] added for SQLite 3.20.0.
5065 ** ^The first host parameter has an index of 1, not 0.
5112 ** [prepared statement]. ^If this routine returns 0, that means the
5133 ** column number. ^The leftmost column is number 0.
5176 ** ^The left-most column is column 0 for these routines.
5223 ** column (i==1), and a NULL pointer for the first result column (i==0).)^
5327 ** interfaces) then sqlite3_data_count(P) returns 0.
5328 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
5329 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
5334 ** pragma returns 0 columns of data.
5378 ** <blockquote><table border=0 cellpadding=0 cellspacing=0>
5404 ** should be returned. ^The leftmost column of the result set has the index 0.
5498 ** <tr><td> NULL <td> INTEGER <td> Result is 0
5694 ** aggregate may take any number of arguments between 0 and the limit
5934 #define SQLITE_DETERMINISTIC 0x000000800
5935 #define SQLITE_DIRECTONLY 0x000080000
5936 #define SQLITE_SUBTYPE 0x000100000
5937 #define SQLITE_INNOCUOUS 0x000200000
5938 #define SQLITE_RESULT_SUBTYPE 0x001000000
5965 ** <blockquote><table border=0 cellpadding=0 cellspacing=0>
6018 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
6191 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
6353 ** version 3.44.0 ([dateof:3.44.0]) and later.
6375 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
6490 ** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the
6519 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
6749 ** at all. ^In SQLite version 3.42.0 and later, a negative
6805 ** memset(zPathBuf, 0, sizeof(zPathBuf));
6806 ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),
6928 ** out of range. An N value of 0 means the main database file. An N of 1 is
6981 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
6995 ** <li value="0"> SQLITE_TXN_NONE
7033 #define SQLITE_TXN_NONE 0
7244 ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
7345 ** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the
7445 ** not null: 0
7447 ** auto increment: 0
7481 ** ^(zProc may be 0, in which case SQLite will try to come up with an
7489 ** ^If an error occurs and pzErrMsg is not 0, then the
7513 const char *zProc, /* Entry point. Derived from zFile if 0 */
7514 char **pzErrMsg /* Put error message here if not 0 */
7528 ** to turn extension loading on and call it with onoff==0 to turn
7589 ** unregistered and it returns 0 if X was not on the list of initialization
7703 ** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62),
7712 ** about what parameters to pass to xFilter. ^If argvIndex>0 then
7765 ** was added for [version 3.9.0] ([dateof:3.9.0]).
7786 int argvIndex; /* if >0, constraint is part of argv to xFilter */
7796 /* Fields below are only available in SQLite 3.9.0 and later */
7798 /* Fields below are only available in SQLite 3.10.0 and later */
8525 #define SQLITE_MUTEX_FAST 0
8679 ** The sqlite3_keyword_name(N,Z,L) interface finds the 0-based N-th keyword and
8750 ** [sqlite3_str_errcode()], always return 0 for
8844 ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
8953 #define SQLITE_STATUS_MEMORY_USED 0
9031 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
9043 ** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
9052 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
9058 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
9064 ** is always 0.
9070 ** is always 0.
9081 ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
9096 ** resolved.)^ ^The highwater mark is always 0.
9100 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
9353 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
9360 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
9811 ** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0.
9879 ** a copy of the third parameter from the previous call, if any, or 0.
9926 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
10002 ** the writer lock retried until either the busy-handler returns 0 or the lock
10004 ** database readers as described above. ^If the busy-handler returns 0 before
10052 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
10234 ** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
10241 ** <ol><li value="0"><p>
10242 ** ^If the sqlite3_vtab_distinct() interface returns 0, that means
10269 ** if the sqlite3_vtab_distinct() interface had returned 0. However if
10285 ** <table border=1 cellspacing=0 cellpadding=10 width="90%">
10291 ** <tr><td>0<td>yes<td>yes<td>no
10354 ** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
10452 ** J being a 0-based index into P->aConstraint[], then this routine
10564 #define SQLITE_SCANSTAT_NLOOP 0
10628 #define SQLITE_SCANSTAT_COMPLEX 0x0001
10737 ** the table row before it is updated. The N parameter must be between 0
10746 ** the table row after it is updated. The N parameter must be between 0
10753 ** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate
11058 #define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */
11093 ** to 0x01 prior to invoking sqlite3_deserialize(D,S,P,N,M,F) to force the
11154 # define SQLITE_THREADSAFE 0
11158 #if 0
11181 #if 0
11270 #define NOT_WITHIN 0 /* Object completely outside of query region */
11275 #if 0
11290 #if 0
11385 ** 0, then the sqlite3session_changeset_size() API is disabled. If it
11386 ** is greater than 0, then the same API is enabled. Or, if the initial
11389 ** enabled following the current call, or 0 otherwise.
11424 ** The return value indicates the final state of the session object: 0 if
11454 ** The return value indicates the final state of the indirect flag: 0 if
11490 ** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
11512 ** Legacy (older than 3.22.0) versions of the sessions module cannot capture
11529 ** If xFilter returns 0, changes are not tracked. Note that once a table is
11656 ** By default, this function always returns 0. For it to return
11857 #define SQLITE_CHANGESETSTART_INVERT 0x0002
11909 ** is an indirect change, or false (0) otherwise. See the documentation for
11940 ** 0x01 if the corresponding column is part of the tables primary key, or
11941 ** 0x00 if it is not.
11969 ** Argument iVal must be greater than or equal to 0, and less than the number
12000 ** Argument iVal must be greater than or equal to 0, and less than the number
12032 ** Argument iVal must be greater than or equal to 0, and less than the number
12151 ** *ppOut = 0;
12152 ** *pnOut = 0;
12384 ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
12633 #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001
12634 #define SQLITE_CHANGESETAPPLY_INVERT 0x0002
12635 #define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004
12636 #define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008
12730 #define SQLITE_CHANGESET_OMIT 0
13086 ** If this value is greater than 0, it is used as the new streaming data
13105 #if 0
13137 #if 0
13199 ** created with the "columnsize=0" option.
13218 ** 0 is returned. Otherwise, this function returns the number of tokens in
13229 ** (i.e. if it is a contentless table), then this API always returns 0.
13335 ** iCol>=0;
13365 ** iCol>=0;
13400 ** tables, this includes any embedded 0x00 and trailing data.
13410 ** to 0.
13414 ** includes any embedded 0x00 and trailing data.
13527 ** on a columnsize=0 database.
13539 ** normally be set to 0. The exception is if the tokenizer supports
13615 ** xToken(pCtx, 0, "i", 1, 0, 1);
13616 ** xToken(pCtx, 0, "won", 3, 2, 5);
13617 ** xToken(pCtx, 0, "first", 5, 6, 11);
13619 ** xToken(pCtx, 0, "place", 5, 12, 17);
13681 #define FTS5_TOKENIZE_QUERY 0x0001
13682 #define FTS5_TOKENIZE_PREFIX 0x0002
13683 #define FTS5_TOKENIZE_DOCUMENT 0x0004
13684 #define FTS5_TOKENIZE_AUX 0x0008
13688 #define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */
13732 #if 0
13821 ** expression. A value of 0 means that there is no limit.
13832 ** never has more than 3 or 4 terms. Use a value of 0 to disable
13876 ** The maximum number of attached databases. This must be between 0
13948 # define SQLITE_MAX_PAGE_COUNT 0xfffffffe /* 4294967294 */
13963 ** fire any triggers. A value of 0 means that no trigger programs at all
13987 # define __has_extension(x) 0 /* compatibility with non-clang compilers */
13994 # define SQLITE_ATOMIC_INTRINSICS 0
14021 ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
14032 # define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X])
14033 # define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0))
14089 ** disables it using -DSQLITE_DIRECT_OVERFLOW_READ=0
14092 /* Disable if -DSQLITE_DIRECT_OVERFLOW_READ=0 */
14101 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
14102 ** 0 means mutexes are permanently disable and the library is never
14126 ** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option.
14134 ** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in
14170 + defined(SQLITE_MEMDEBUG)==0
14289 # define NEVER(X) (0)
14291 # define ALWAYS(X) ((X)?1:(assert(0),0))
14292 # define NEVER(X) ((X)?(assert(0),1):0)
14300 ** conditionals are replaced with a constant 1 (true) or 0 (false) then
14307 # define OK_IF_ALWAYS_FALSE(X) (0)
14323 # define ONLY_IF_REALLOC_STRESS(X) ((X)?(assert(0),1):0)
14325 # define ONLY_IF_REALLOC_STRESS(X) (0)
14375 #define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0)
14693 int xxn=(N);while(xxn-->0)*(xxd++)=*(xxs++);}
14717 ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
14724 #define OMIT_TEMPDB 0
14743 # define SQLITE_DEFAULT_RECURSIVE_TRIGGERS 0
14759 #if SQLITE_TEMP_STORE==3 || SQLITE_THREADSAFE==0
14761 # define SQLITE_MAX_WORKER_THREADS 0
14767 # define SQLITE_DEFAULT_WORKER_THREADS 0
14791 # define SQLITE_DEFAULT_SORTERREF_SIZE 0x7fffffff
14808 #define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD))
14892 ** is 0x00000000ffffffff. But because of quirks of some compilers, we
14915 ** 1 -> 0 20 -> 43 10000 -> 132
14994 ** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined
15024 # define SQLITE_BYTEORDER 0
15029 # define SQLITE_LITTLEENDIAN 0
15032 # define SQLITE_BIGENDIAN 0
15041 # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
15051 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
15052 #define LARGEST_UINT64 (0xffffffff|(((u64)0xffffffff)<<32))
15087 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
15089 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
15097 # define SQLITE_MAX_MMAP_SIZE 0
15113 # define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */
15115 # define SQLITE_MAX_MMAP_SIZE 0
15125 # define SQLITE_DEFAULT_MMAP_SIZE 0
15133 ** TREETRACE_ENABLED will be either 1 or 0 depending on whether or not
15149 # define TREETRACE_ENABLED 0
15154 ** 0x00000001 Beginning and end of SELECT processing
15155 ** 0x00000002 WHERE clause processing
15156 ** 0x00000004 Query flattener
15157 ** 0x00000008 Result-set wildcard expansion
15158 ** 0x00000010 Query name resolution
15159 ** 0x00000020 Aggregate analysis
15160 ** 0x00000040 Window functions
15161 ** 0x00000080 Generated column names
15162 ** 0x00000100 Move HAVING terms into WHERE
15163 ** 0x00000200 Count-of-view optimization
15164 ** 0x00000400 Compound SELECT processing
15165 ** 0x00000800 Drop superfluous ORDER BY
15166 ** 0x00001000 LEFT JOIN simplifies to JOIN
15167 ** 0x00002000 Constant propagation
15168 ** 0x00004000 Push-down optimization
15169 ** 0x00008000 After all FROM-clause analysis
15170 ** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
15171 ** 0x00020000 Transform DISTINCT into GROUP BY
15172 ** 0x00040000 SELECT tree dump after all code has been generated
15173 ** 0x00080000 NOT NULL strength reduction
15192 ** 0x-------F High-level debug messages
15193 ** 0x----FFF- More detail
15194 ** 0xFFFF---- Low-level debug messages
15196 ** 0x00000001 Code generation
15197 ** 0x00000002 Solver
15198 ** 0x00000004 Solver costs
15199 ** 0x00000008 WhereLoop inserts
15201 ** 0x00000010 Display sqlite3_index_info xBestIndex calls
15202 ** 0x00000020 Range an equality scan metrics
15203 ** 0x00000040 IN operator decisions
15204 ** 0x00000080 WhereLoop cost adjustments
15205 ** 0x00000100
15206 ** 0x00000200 Covering index decisions
15207 ** 0x00000400 OR optimization
15208 ** 0x00000800 Index scanner
15209 ** 0x00001000 More details associated with code generation
15210 ** 0x00002000
15211 ** 0x00004000 Show all WHERE terms at key points
15212 ** 0x00008000 Show the full SELECT statement at key places
15214 ** 0x00010000 Show more detail when printing WHERE terms
15215 ** 0x00020000 Show WHERE terms returned from whereScanNext()
15273 #define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0])))
15278 #define IsPowerOfTwo(X) (((X)&((X)-1))==0)
15424 #define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0)
15500 ** will defined to either 1 or 0. One of them will be 1. The others will be 0.
15513 # define SQLITE_OS_UNIX 0
15515 # define SQLITE_OS_WIN 0
15521 # define SQLITE_OS_KV 0
15523 # define SQLITE_OS_UNIX 0
15525 # define SQLITE_OS_WIN 0
15529 # define SQLITE_OS_OTHER 0
15531 # define SQLITE_OS_UNIX 0
15533 # define SQLITE_OS_WIN 0
15539 # define SQLITE_DQS 0
15545 # define SQLITE_OS_KV 0
15547 # define SQLITE_OS_OTHER 0
15549 # define SQLITE_OS_WIN 0
15553 # define SQLITE_OS_KV 0
15555 # define SQLITE_OS_OTHER 0
15557 # define SQLITE_OS_UNIX 0
15635 #define NO_LOCK 0
15697 # define PENDING_BYTE (0x40000000)
15724 #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
15798 ** is called page 1. 0 is used to represent "not a page".
15828 #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
15829 #define PAGER_MEMORY 0x0002 /* In-memory database */
15835 #define PAGER_LOCKINGMODE_NORMAL 0
15846 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
15856 #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
15857 #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
15867 #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
15868 #define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
15869 #define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
15870 #define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */
15871 #define PAGER_SYNCHRONOUS_MASK 0x07 /* Mask for four values above */
15872 #define PAGER_FULLFSYNC 0x08 /* PRAGMA fullfsync=ON */
15873 #define PAGER_CKPT_FULLFSYNC 0x10 /* PRAGMA checkpoint_fullfsync=ON */
15874 #define PAGER_CACHESPILL 0x20 /* PRAGMA cache_spill=ON */
15875 #define PAGER_FLAGS_MASK 0x38 /* All above except SYNCHRONOUS */
16048 #define SQLITE_DEFAULT_AUTOVACUUM 0
16051 #define BTREE_AUTOVACUUM_NONE 0 /* Do not do auto-vacuum */
16087 #if SQLITE_MAX_MMAP_SIZE>0
16171 #define BTREE_FREE_PAGE_COUNT 0
16209 #define BTREE_HINT_RANGE 0 /* Range constraints on queries */
16224 #define BTREE_BULKLOAD 0x00000001 /* Used to full index in sorted order */
16225 #define BTREE_SEEK_EQ 0x00000002 /* EQ seeks only - no range seeks */
16248 ** FORDELETE cursor may return a null row: 0x01 0x00.
16250 #define BTREE_WRCSR 0x00000004 /* read-write cursor */
16251 #define BTREE_FORDELETE 0x00000008 /* Cursor is for seek/delete only */
16256 int wrFlag, /* 1 for writing. 0 for read-only */
16285 #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */
16286 #define BTREE_AUXDELETE 0x04 /* not the primary delete operation */
16287 #define BTREE_APPEND 0x08 /* Insert is likely an append */
16288 #define BTREE_PREFORMAT 0x80 /* Inserted data is a preformated cell */
16329 int nData; /* Size of pData. 0 if none. */
16376 # define sqlite3BtreeSeekCount(X) 0
16413 # define sqlite3BtreeSharable(X) 0
16555 #define P4_NOTUSED 0 /* The P4 parameter is not used */
16556 #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
16586 #define COLNAME_NAME 0
16616 #define OP_Savepoint 0
16665 #define OP_FkIfZero 49 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
16675 #define OP_IfPos 59 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
16676 #define OP_IfNotZero 60 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
16677 #define OP_DecrJumpZero 61 /* jump, synopsis: if (--r[P1])==0 goto P2 */
16708 #define OP_ZeroOrNull 92 /* synopsis: r[P2] = 0 OR NULL */
16776 #define OP_OffsetLimit 160 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) …
16796 #define OP_ClrSubtype 180 /* synopsis: r[P1].subtype = 0 */
16811 #define OPFLG_JUMP 0x01 /* jump: P2 holds jmp target */
16812 #define OPFLG_IN1 0x02 /* in1: P1 is an input */
16813 #define OPFLG_IN2 0x04 /* in2: P2 is an input */
16814 #define OPFLG_IN3 0x08 /* in3: P3 is an input */
16815 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
16816 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
16817 #define OPFLG_NCYCLE 0x40 /* ncycle:Cycles count against P1 */
16818 #define OPFLG_JUMP0 0x80 /* jump0: P2 might be zero */
16820 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x41, 0x00,\
16821 /* 8 */ 0x81, 0x01, 0x01, 0x81, 0x83, 0x83, 0x01, 0x01,\
16822 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0xc9, 0xc9, 0xc9,\
16823 /* 24 */ 0xc9, 0x01, 0x49, 0x49, 0x49, 0x49, 0xc9, 0x49,\
16824 /* 32 */ 0xc1, 0x01, 0x41, 0x41, 0xc1, 0x01, 0x41, 0x41,\
16825 /* 40 */ 0x41, 0x41, 0x41, 0x26, 0x26, 0x41, 0x23, 0x0b,\
16826 /* 48 */ 0x81, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
16827 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x41,\
16828 /* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
16829 /* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
16830 /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
16831 /* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x40, 0x00,\
16832 /* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x40, 0x26, 0x26,\
16833 /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
16834 /* 112 */ 0x40, 0x00, 0x12, 0x40, 0x40, 0x10, 0x40, 0x00,\
16835 /* 120 */ 0x00, 0x00, 0x40, 0x00, 0x40, 0x40, 0x10, 0x10,\
16836 /* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x50,\
16837 /* 136 */ 0x00, 0x40, 0x04, 0x04, 0x00, 0x40, 0x50, 0x40,\
16838 /* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
16839 /* 152 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
16840 /* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
16841 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x50,\
16842 /* 176 */ 0x40, 0x00, 0x10, 0x10, 0x02, 0x12, 0x12, 0x00,\
16843 /* 184 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}
16859 #define SQLITE_PREPARE_SAVESQL 0x80 /* Preserve SQL text */
16860 #define SQLITE_PREPARE_MASK 0x0f /* Mask of public flags */
16911 # define ExplainQueryPlanParent(P) 0
17061 sqlite3VdbeSetLineNumber(v,__LINE__|0x5000000);
17063 sqlite3VdbeSetLineNumber(v,__LINE__|0x6000000);
17065 sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
17067 if(x)sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
17069 sqlite3VdbeSetLineNumber(v,__LINE__|0x8000000);
17079 # define VDBE_OFFSET_LINENO(x) 0
17156 #define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */
17157 #define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */
17158 #define PGHDR_WRITEABLE 0x004 /* Journaled and ready to modify */
17159 #define PGHDR_NEED_SYNC 0x008 /* Fsync the rollback journal before
17161 #define PGHDR_DONT_WRITE 0x010 /* Do not write content to disk */
17162 #define PGHDR_MMAP 0x020 /* This is an mmap page object */
17164 #define PGHDR_WAL_APPEND 0x040 /* Appended to wal file */
17213 /* Remove all pages with pgno>x. Reset the cache if x==0 */
17391 ** OFF 1 0
17410 ** in the sqlite.aDb[] array. aDb[0] is the main database file and
17458 #define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->schemaFlags&(P))!=0)
17472 #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */
17473 #define DB_UnresetViews 0x0002 /* Some views have defined column names */
17474 #define DB_ResetWanted 0x0008 /* Reset the schema when nSchemaLock==0 */
17502 ** New lookaside allocations are only allowed if bDisable==0. When
17533 u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
17544 void *pTrueEnd; /* True value of pEnd, when db->pnBytesFreed!=0 */
17550 #define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0
17552 db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue
17556 # define LOOKASIDE_SMALL 0
17593 #define UAUTH_Unknown 0 /* Authentication not yet checked */
17621 #define SQLITE_TRACE_LEGACY 0x40 /* Use the legacy xTrace */
17622 #define SQLITE_TRACE_XPROFILE 0x80 /* Use the legacy xProfile */
17624 #define SQLITE_TRACE_LEGACY 0
17625 #define SQLITE_TRACE_XPROFILE 0
17627 #define SQLITE_TRACE_NONLEGACY_MASK 0x0f /* Normal flags */
17658 u8 temp_store; /* 1: file 2: memory 0: default */
17662 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
17670 int nextPagesize; /* Pagesize after VACUUM if >0 */
17784 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
17802 #define SQLITE_WriteSchema 0x00000001 /* OK to update SQLITE_SCHEMA */
17803 #define SQLITE_LegacyFileFmt 0x00000002 /* Create new databases in format 1 */
17804 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
17805 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
17806 #define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */
17807 #define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */
17808 #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
17809 #define SQLITE_TrustedSchema 0x00000080 /* Allow unsafe functions and
17811 #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
17813 #define SQLITE_IgnoreChecks 0x00000200 /* Do not enforce check constraints */
17814 #define SQLITE_StmtScanStatus 0x00000400 /* Enable stmt_scanstats() counters */
17815 #define SQLITE_NoCkptOnClose 0x00000800 /* No checkpoint on close()/DETACH */
17816 #define SQLITE_ReverseOrder 0x00001000 /* Reverse unordered SELECTs */
17817 #define SQLITE_RecTriggers 0x00002000 /* Enable recursive triggers */
17818 #define SQLITE_ForeignKeys 0x00004000 /* Enforce foreign key constraints */
17819 #define SQLITE_AutoIndex 0x00008000 /* Enable automatic indexes */
17820 #define SQLITE_LoadExtension 0x00010000 /* Enable load_extension */
17821 #define SQLITE_LoadExtFunc 0x00020000 /* Enable load_extension() SQL func */
17822 #define SQLITE_EnableTrigger 0x00040000 /* True to enable triggers */
17823 #define SQLITE_DeferFKs 0x00080000 /* Defer all FK constraints */
17824 #define SQLITE_QueryOnly 0x00100000 /* Disable database changes */
17825 #define SQLITE_CellSizeCk 0x00200000 /* Check btree cell sizes on load */
17826 #define SQLITE_Fts3Tokenizer 0x00400000 /* Enable fts3_tokenizer(2) */
17827 #define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee*/
17828 #define SQLITE_TriggerEQP 0x01000000 /* Show trigger EXPLAIN QUERY PLAN */
17829 #define SQLITE_ResetDatabase 0x02000000 /* Reset the database */
17830 #define SQLITE_LegacyAlter 0x04000000 /* Legacy ALTER TABLE behaviour */
17831 #define SQLITE_NoSchemaError 0x08000000 /* Do not report schema parse errors*/
17832 #define SQLITE_Defensive 0x10000000 /* Input SQL is likely hostile */
17833 #define SQLITE_DqsDDL 0x20000000 /* dbl-quoted strings allowed in DDL*/
17834 #define SQLITE_DqsDML 0x40000000 /* dbl-quoted strings allowed in DML*/
17835 #define SQLITE_EnableView 0x80000000 /* Enable the use of views */
17836 #define SQLITE_CountRows HI(0x00001) /* Count rows changed by INSERT, */
17839 #define SQLITE_CorruptRdOnly HI(0x00002) /* Prohibit writes due to error */
17840 #define SQLITE_ReadUncommit HI(0x00004) /* READ UNCOMMITTED in shared-cache */
17841 #define SQLITE_FkNoAction HI(0x00008) /* Treat all FK as NO ACTION */
17845 #define SQLITE_SqlTrace HI(0x0100000) /* Debug print SQL as it executes */
17846 #define SQLITE_VdbeListing HI(0x0200000) /* Debug listings of VDBE progs */
17847 #define SQLITE_VdbeTrace HI(0x0400000) /* True to trace VDBE execution */
17848 #define SQLITE_VdbeAddopTrace HI(0x0800000) /* Trace sqlite3VdbeAddOp() calls */
17849 #define SQLITE_VdbeEQP HI(0x1000000) /* Debug EXPLAIN QUERY PLAN */
17850 #define SQLITE_ParserTrace HI(0x2000000) /* PRAGMA parser_trace=ON */
17856 #define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */
17857 #define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */
17858 #define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */
17859 #define DBFLAG_VacuumInto 0x0008 /* Currently running VACUUM INTO */
17860 #define DBFLAG_SchemaKnownOk 0x0010 /* Schema is known to be valid */
17861 #define DBFLAG_InternalFunc 0x0020 /* Allow use of internal functions */
17862 #define DBFLAG_EncodingFixed 0x0040 /* No longer possible to change enc. */
17869 #define SQLITE_QueryFlattener 0x00000001 /* Query flattening */
17870 #define SQLITE_WindowFunc 0x00000002 /* Use xInverse for window functions */
17871 #define SQLITE_GroupByOrder 0x00000004 /* GROUPBY cover of ORDERBY */
17872 #define SQLITE_FactorOutConst 0x00000008 /* Constant factoring */
17873 #define SQLITE_DistinctOpt 0x00000010 /* DISTINCT using indexes */
17874 #define SQLITE_CoverIdxScan 0x00000020 /* Covering index scans */
17875 #define SQLITE_OrderByIdxJoin 0x00000040 /* ORDER BY of joins via index */
17876 #define SQLITE_Transitive 0x00000080 /* Transitive constraints */
17877 #define SQLITE_OmitNoopJoin 0x00000100 /* Omit unused tables in joins */
17878 #define SQLITE_CountOfView 0x00000200 /* The count-of-view optimization */
17879 #define SQLITE_CursorHints 0x00000400 /* Add OP_CursorHint opcodes */
17880 #define SQLITE_Stat4 0x00000800 /* Use STAT4 data */
17881 /* TH3 expects this value ^^^^^^^^^^ to be 0x0000800. Don't change it */
17882 #define SQLITE_PushDown 0x00001000 /* WHERE-clause push-down opt */
17883 #define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */
17884 #define SQLITE_SkipScan 0x00004000 /* Skip-scans */
17885 #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */
17886 #define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */
17887 #define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */
17888 #define SQLITE_OmitOrderBy 0x00040000 /* Omit pointless ORDER BY */
17889 /* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */
17890 #define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
17891 #define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
17892 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
17893 #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
17894 #define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
17896 #define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
17897 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
17898 #define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
17899 #define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
17900 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17905 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0)
17906 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0)
17918 #define SQLITE_STATE_OPEN 0x76 /* Database is open */
17919 #define SQLITE_STATE_CLOSED 0xce /* Database is closed */
17920 #define SQLITE_STATE_SICK 0xba /* Error and awaiting close */
17921 #define SQLITE_STATE_BUSY 0x6d /* Database currently in use */
17922 #define SQLITE_STATE_ERROR 0xd5 /* An SQLITE_MISUSE error occurred */
17923 #define SQLITE_STATE_ZOMBIE 0xa7 /* Close with last statement close */
17962 ** count on this object is decremented. When it reaches 0, the destructor
17994 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
17995 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
17996 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
17997 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
17998 #define SQLITE_FUNC_NEEDCOLL 0x0020 /* sqlite3GetFuncCollSeq() might be called*/
17999 #define SQLITE_FUNC_LENGTH 0x0040 /* Built-in length() function */
18000 #define SQLITE_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */
18001 #define SQLITE_FUNC_BYTELEN 0x00c0 /* Built-in octet_length() function */
18002 #define SQLITE_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */
18003 /* 0x0200 -- available for reuse */
18004 #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
18005 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
18006 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
18007 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
18009 #define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */
18010 #define SQLITE_FUNC_RUNONLY 0x8000 /* Cannot be used by valueFromFunction */
18011 #define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
18012 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
18013 #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
18014 /* SQLITE_SUBTYPE 0x00100000 // Consumer of subtypes */
18015 #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
18016 #define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */
18017 #define SQLITE_FUNC_BUILTIN 0x00800000 /* This is a built-in function */
18018 /* SQLITE_RESULT_SUBTYPE 0x01000000 // Generator of subtypes */
18019 #define SQLITE_FUNC_ANYORDER 0x08000000 /* count/min/max aggregate */
18022 #define INLINEFUNC_coalesce 0
18100 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
18103 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
18106 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
18109 xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
18114 SQLITE_INT_TO_PTR(iArg|((bJsonB)*JSON_BLOB)),0,xFunc,0, 0, 0, #zName, {0} }
18118 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
18123 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
18126 0, 0, xFunc, 0, 0, 0, #zName, {0} }
18130 (void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} }
18134 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
18138 pArg, 0, xFunc, 0, 0, 0, #zName, }
18141 (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
18144 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
18148 0, 0, xFunc, 0, 0, 0, #zName, {0} }
18168 #define SAVEPOINT_BEGIN 0
18207 ** a single allocation. Each string is 0x00 terminated. The datatype
18219 u16 iDflt; /* 1-based index of DEFAULT. 0 means "none" */
18230 #define COLTYPE_CUSTOM 0 /* Type appended to zName */
18246 #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */
18247 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
18248 #define COLFLAG_HASTYPE 0x0004 /* Type name follows column name */
18249 #define COLFLAG_UNIQUE 0x0008 /* Column def contains "UNIQUE" or "PK" */
18250 #define COLFLAG_SORTERREF 0x0010 /* Use sorter-refs with this column */
18251 #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
18252 #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
18253 #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
18254 #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
18255 #define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
18256 #define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */
18257 #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
18258 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
18280 #define SQLITE_SO_ASC 0 /* Sort in ascending order */
18291 ** But rather than start with 0 or 1, we begin with 'A'. That way,
18298 #define SQLITE_AFF_NONE 0x40 /* '@' */
18299 #define SQLITE_AFF_BLOB 0x41 /* 'A' */
18300 #define SQLITE_AFF_TEXT 0x42 /* 'B' */
18301 #define SQLITE_AFF_NUMERIC 0x43 /* 'C' */
18302 #define SQLITE_AFF_INTEGER 0x44 /* 'D' */
18303 #define SQLITE_AFF_REAL 0x45 /* 'E' */
18304 #define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
18312 #define SQLITE_AFF_MASK 0x47
18323 #define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */
18324 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */
18325 #define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */
18383 #define SQLITE_VTABRISK_Low 0
18410 u8 eTabType; /* 0: normal, 1: virtual, 2: view */
18423 char **azArg; /* 0: module 1: schema 2: vtab name 3...: args */
18446 #define TF_Readonly 0x00000001 /* Read-only system table */
18447 #define TF_HasHidden 0x00000002 /* Has one or more hidden columns */
18448 #define TF_HasPrimaryKey 0x00000004 /* Table has a primary key */
18449 #define TF_Autoincrement 0x00000008 /* Integer primary key is autoincrement */
18450 #define TF_HasStat1 0x00000010 /* nRowLogEst set from sqlite_stat1 */
18451 #define TF_HasVirtual 0x00000020 /* Has one or more VIRTUAL columns */
18452 #define TF_HasStored 0x00000040 /* Has one or more STORED columns */
18453 #define TF_HasGenerated 0x00000060 /* Combo: HasVirtual + HasStored */
18454 #define TF_WithoutRowid 0x00000080 /* No rowid. PRIMARY KEY is the key */
18455 #define TF_MaybeReanalyze 0x00000100 /* Maybe run ANALYZE on this table */
18456 #define TF_NoVisibleRowid 0x00000200 /* No user-visible "rowid" column */
18457 #define TF_OOOHidden 0x00000400 /* Out-of-Order hidden columns */
18458 #define TF_HasNotNull 0x00000800 /* Contains NOT NULL constraints */
18459 #define TF_Shadow 0x00001000 /* True for a shadow table */
18460 #define TF_HasStat4 0x00002000 /* STAT4 info available for this table */
18461 #define TF_Ephemeral 0x00004000 /* An ephemeral table */
18462 #define TF_Eponymous 0x00008000 /* An eponymous virtual table */
18463 #define TF_Strict 0x00010000 /* STRICT mode */
18468 #define TABTYP_NORM 0 /* Ordinary table */
18485 # define IsVirtual(X) 0
18486 # define ExprIsVtab(X) 0
18496 # define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0)
18497 # define IsOrdinaryHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0)
18499 # define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0)
18500 # define IsOrdinaryHiddenColumn(X) 0
18502 # define IsHiddenColumn(X) 0
18503 # define IsOrdinaryHiddenColumn(X) 0
18508 #define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0)
18509 #define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0)
18515 # define ViewCanHaveRowid 0
18517 # define ViewCanHaveRowid (sqlite3Config.mNoVisibleRowid==0)
18596 #define OE_None 0 /* There is no constraint to check */
18632 #define KEYINFO_ORDER_DESC 0x01 /* DESC sort order */
18633 #define KEYINFO_ORDER_BIGNULL 0x02 /* NULL is larger than any other value */
18657 ** an equals comparison. default_rc can be -1, 0, or +1. If there are
18665 ** When default_rc!=0, the search might end up on the record immediately
18674 char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */
18675 i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */
18677 int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */
18701 ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the
18703 ** The second column to be indexed (c1) has an index of 0 in
18704 ** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
18735 i16 *aiColumn; /* Which columns are used by this index. 1st is 0 */
18750 unsigned idxType:2; /* 0:Normal 1:UNIQUE, 2:PRIMARY KEY, 3:IPK */
18778 #define SQLITE_IDXTYPE_APPDEF 0 /* Created using CREATE INDEX */
18811 #define SQLITE_TOKEN_QUOTED 0x1 /* Token is a quoted identifier. */
18812 #define SQLITE_TOKEN_KEYWORD 0x2 /* Token is a keyword. */
19003 #if SQLITE_MAX_EXPR_DEPTH>0
19008 ** TK_TRIGGER: 1 -> new, 0 -> old
19039 #define EP_OuterON 0x000001 /* Originates in ON/USING clause of outer join */
19040 #define EP_InnerON 0x000002 /* Originates in ON/USING of an inner join */
19041 #define EP_Distinct 0x000004 /* Aggregate function with DISTINCT keyword */
19042 #define EP_HasFunc 0x000008 /* Contains one or more functions of any kind */
19043 #define EP_Agg 0x000010 /* Contains one or more aggregate functions */
19044 #define EP_FixedCol 0x000020 /* TK_Column with a known fixed value */
19045 #define EP_VarSelect 0x000040 /* pSelect is correlated, not constant */
19046 #define EP_DblQuoted 0x000080 /* token.z was originally in "..." */
19047 #define EP_InfixFunc 0x000100 /* True for an infix function: LIKE, GLOB, etc */
19048 #define EP_Collate 0x000200 /* Tree contains a TK_COLLATE operator */
19049 #define EP_Commuted 0x000400 /* Comparison operator has been commuted */
19050 #define EP_IntValue 0x000800 /* Integer value contained in u.iValue */
19051 #define EP_xIsSelect 0x001000 /* x.pSelect is valid (otherwise x.pList is) */
19052 #define EP_Skip 0x002000 /* Operator does not contribute to affinity */
19053 #define EP_Reduced 0x004000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
19054 #define EP_Win 0x008000 /* Contains window functions */
19055 #define EP_TokenOnly 0x010000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
19056 #define EP_FullSize 0x020000 /* Expr structure must remain full sized */
19057 #define EP_IfNullRow 0x040000 /* The TK_IF_NULL_ROW opcode */
19058 #define EP_Unlikely 0x080000 /* unlikely() or likelihood() function */
19059 #define EP_ConstFunc 0x100000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
19060 #define EP_CanBeNull 0x200000 /* Can be null despite NOT NULL constraint */
19061 #define EP_Subquery 0x400000 /* Tree contains a TK_SELECT operator */
19062 #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
19063 #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
19064 #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
19065 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
19066 #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
19067 #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
19068 #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
19069 #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
19070 /* 0x80000000 // Available */
19080 #define ExprHasProperty(E,P) (((E)->flags&(P))!=0)
19086 #define ExprIsFullSize(E) (((E)->flags&(EP_Reduced|EP_TokenOnly))==0)
19091 #define ExprUseUToken(E) (((E)->flags&EP_IntValue)==0)
19092 #define ExprUseUValue(E) (((E)->flags&EP_IntValue)!=0)
19093 #define ExprUseWOfst(E) (((E)->flags&(EP_InnerON|EP_OuterON))==0)
19094 #define ExprUseWJoin(E) (((E)->flags&(EP_InnerON|EP_OuterON))!=0)
19095 #define ExprUseXList(E) (((E)->flags&EP_xIsSelect)==0)
19096 #define ExprUseXSelect(E) (((E)->flags&EP_xIsSelect)!=0)
19097 #define ExprUseYTab(E) (((E)->flags&(EP_WinFunc|EP_Subrtn))==0)
19098 #define ExprUseYWin(E) (((E)->flags&EP_WinFunc)!=0)
19099 #define ExprUseYSub(E) (((E)->flags&EP_Subrtn)!=0)
19103 #define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */
19104 #define EP_Immutable 0x02 /* Do not change this Expr node */
19112 # define ExprHasVVAProperty(E,P) (((E)->vvaFlags&(P))!=0)
19113 # define ExprClearVVAProperties(E) (E)->vvaFlags = 0
19116 # define ExprHasVVAProperty(E,P) 0
19133 #define EXPRDUP_REDUCE 0x0001 /* Used reduced-size Expr nodes */
19140 # define IsWindowFunc(p) 0
19201 #define ENAME_NAME 0 /* The AS clause of a result set */
19219 ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
19237 #define EU4_NONE 0 /* Does not use IdList.a.u4 */
19292 Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */
19332 #define JT_INNER 0x01 /* Any kind of inner or cross join */
19333 #define JT_CROSS 0x02 /* Explicit use of the CROSS keyword */
19334 #define JT_NATURAL 0x04 /* True for a "natural" join */
19335 #define JT_LEFT 0x08 /* Left outer join */
19336 #define JT_RIGHT 0x10 /* Right outer join */
19337 #define JT_OUTER 0x20 /* The "OUTER" keyword is present */
19338 #define JT_LTORJ 0x40 /* One of the LEFT operands of a RIGHT JOIN
19340 #define JT_ERROR 0x80 /* unknown or unsupported join type */
19349 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
19350 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
19351 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
19352 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
19353 #define WHERE_ONEPASS_MULTIROW 0x0008 /* ONEPASS is ok with multiple rows */
19354 #define WHERE_DUPLICATES_OK 0x0010 /* Ok to return a row more than once */
19355 #define WHERE_OR_SUBCLAUSE 0x0020 /* Processing a sub-WHERE as part of
19357 #define WHERE_GROUPBY 0x0040 /* pOrderBy is really a GROUP BY */
19358 #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
19359 #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
19360 #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
19361 #define WHERE_AGG_DISTINCT 0x0400 /* Query is "SELECT agg(DISTINCT ...)" */
19362 #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
19363 #define WHERE_RIGHT_JOIN 0x1000 /* Processing a RIGHT JOIN */
19364 #define WHERE_KEEP_ALL_JOINS 0x2000 /* Do not do the omit-noop-join opt */
19365 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
19366 /* 0x8000 not currently used */
19370 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
19423 #define NC_AllowAgg 0x000001 /* Aggregate functions are allowed here */
19424 #define NC_PartIdx 0x000002 /* True if resolving a partial index WHERE */
19425 #define NC_IsCheck 0x000004 /* True if resolving a CHECK constraint */
19426 #define NC_GenCol 0x000008 /* True for a GENERATED ALWAYS AS clause */
19427 #define NC_HasAgg 0x000010 /* One or more aggregate functions seen */
19428 #define NC_IdxExpr 0x000020 /* True if resolving columns of CREATE INDEX */
19429 #define NC_SelfRef 0x00002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */
19430 #define NC_Subquery 0x000040 /* A subquery has been seen */
19431 #define NC_UEList 0x000080 /* True if uNC.pEList is used */
19432 #define NC_UAggInfo 0x000100 /* True if uNC.pAggInfo is used */
19433 #define NC_UUpsert 0x000200 /* True if uNC.pUpsert is used */
19434 #define NC_UBaseReg 0x000400 /* True if uNC.iBaseReg is used */
19435 #define NC_MinMaxAgg 0x001000 /* min/max aggregates seen. See note above */
19436 #define NC_Complex 0x002000 /* True if a function or subquery seen */
19437 #define NC_AllowWin 0x004000 /* Window functions are allowed here */
19438 #define NC_HasWin 0x008000 /* One or more window functions seen */
19439 #define NC_IsDDL 0x010000 /* Resolving names in a CREATE statement */
19440 #define NC_InAggFunc 0x020000 /* True if analyzing arguments to an agg func */
19441 #define NC_FromDDL 0x040000 /* SQL text comes from sqlite_schema */
19442 #define NC_NoSelect 0x080000 /* Do not descend into sub-selects */
19443 #define NC_Where 0x100000 /* Processing WHERE clause of a SELECT */
19444 #define NC_OrderAgg 0x8000000 /* Has an aggregate other than count/min/max */
19496 ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
19533 #define SF_Distinct 0x0000001 /* Output should be DISTINCT */
19534 #define SF_All 0x0000002 /* Includes the ALL keyword */
19535 #define SF_Resolved 0x0000004 /* Identifiers have been resolved */
19536 #define SF_Aggregate 0x0000008 /* Contains agg functions or a GROUP BY */
19537 #define SF_HasAgg 0x0000010 /* Contains aggregate functions */
19538 #define SF_UsesEphemeral 0x0000020 /* Uses the OpenEphemeral opcode */
19539 #define SF_Expanded 0x0000040 /* sqlite3SelectExpand() called on this */
19540 #define SF_HasTypeInfo 0x0000080 /* FROM subqueries have Table metadata */
19541 #define SF_Compound 0x0000100 /* Part of a compound query */
19542 #define SF_Values 0x0000200 /* Synthesized from VALUES clause */
19543 #define SF_MultiValue 0x0000400 /* Single VALUES term with multiple rows */
19544 #define SF_NestedFrom 0x0000800 /* Part of a parenthesized FROM clause */
19545 #define SF_MinMaxAgg 0x0001000 /* Aggregate containing min() or max() */
19546 #define SF_Recursive 0x0002000 /* The recursive part of a recursive CTE */
19547 #define SF_FixedLimit 0x0004000 /* nSelectRow set by a constant LIMIT */
19548 #define SF_MaybeConvert 0x0008000 /* Need convertCompoundSelectToSubquery() */
19549 #define SF_Converted 0x0010000 /* By convertCompoundSelectToSubquery() */
19550 #define SF_IncludeHidden 0x0020000 /* Include hidden columns in output */
19551 #define SF_ComplexResult 0x0040000 /* Result contains subquery or function */
19552 #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */
19553 #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */
19554 #define SF_View 0x0200000 /* SELECT statement is a view */
19555 #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */
19556 #define SF_UFSrcCheck 0x0800000 /* Check pSrc as required by UPDATE...FROM */
19557 #define SF_PushDown 0x1000000 /* Modified by WHERE-clause push-down opt */
19558 #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */
19559 #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */
19560 #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */
19561 #define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */
19562 #define SF_Correlated 0x20000000 /* True if references the outer context */
19565 #define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0)
19629 ** pDest->iSDParm. If (pDest->iSDParm<0), then the temp
19632 ** key. If (pDest->iSDParm>0), then the table is an index
19704 ** The TriggerPrg.aColmask[0] variable is set to a mask of old.* columns
19705 ** accessed (or set to 0 for triggers fired as a result of INSERT
19722 # define DbMaskTest(M,I) (((M)[(I)/8]&(1<<((I)&7)))!=0)
19723 # define DbMaskZero(M) memset((M),0,sizeof(M))
19726 # define DbMaskNonZero(M) (sqlite3DbMaskAllZero(M)==0)
19729 # define DbMaskTest(M,I) (((M)&(((yDbMask)1)<<(I)))!=0)
19730 # define DbMaskZero(M) ((M)=0)
19732 # define DbMaskAllZero(M) ((M)==0)
19733 # define DbMaskNonZero(M) ((M)!=0)
19905 #define PARSE_MODE_NORMAL 0
19923 #define IN_DECLARE_VTAB 0
19929 #define IN_RENAME_OBJECT 0
19935 #define IN_SPECIAL_PARSE 0
19961 #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
19963 #define OPFLAG_NOCHNG 0x01 /* OP_VColumn nochange for UPDATE */
19964 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
19965 #define OPFLAG_LASTROWID 0x20 /* Set to update db->lastRowid */
19966 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
19967 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */
19968 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
19969 #define OPFLAG_ISNOOP 0x40 /* OP_Delete does pre-update-hook only */
19970 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
19971 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
19972 #define OPFLAG_BYTELENARG 0xc0 /* OP_Column only for octet_length() */
19973 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
19974 #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */
19975 #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */
19976 #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */
19977 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
19978 #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */
19979 #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */
19980 #define OPFLAG_NOCHNG_MAGIC 0x6d /* OP_MakeRecord: serialtype 10 is ok */
19981 #define OPFLAG_PREFORMAT 0x80 /* OP_Insert uses preformatted cell */
20105 u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
20110 #define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */
20111 #define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */
20112 #define SQLITE_PRINTF_MALLOCED 0x04 /* True if xText is allocated space */
20114 #define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0)
20146 int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */
20150 Pgno mxPage; /* Maximum page number. 0 for no limit. */
20156 #define INITFLAG_AlterMask 0x0003 /* Types of ALTER */
20157 #define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */
20158 #define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */
20159 #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */
20174 # define Tuning(X) 0
20243 ** feature is disabled. 0 if rowids can
20273 #define CORRUPT_DB (sqlite3Config.neverCorrupt==0)
20344 # define sqlite3SelectPopWith 0
20351 #define WRC_Continue 0 /* Continue down into children */
20370 #define M10d_Yes 0 /* AS MATERIALIZED */
20455 u8 eFrmType; /* TK_RANGE, TK_GROUPS, TK_ROWS, or 0 */
20459 u8 eExclude; /* TK_NO, TK_CURRENT, TK_TIES, TK_GROUP, or 0 */
20513 if( (*(zIn++))>=0xc0 ){ \
20514 while( (*zIn & 0xc0)==0x80 ){ zIn++; } \
20580 # define sqlite3Toupper(x) ((x)&~(sqlite3CtypeMap[(unsigned char)(x)]&0x20))
20581 # define sqlite3Isspace(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x01)
20582 # define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06)
20583 # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
20584 # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
20585 # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
20587 # define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80)
20588 # define sqlite3JsonId1(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x42)
20589 # define sqlite3JsonId2(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x46)
20599 # define sqlite3JsonId1(x) (sqlite3IsIdChar(x)&&(x)<'0')
20609 #define sqlite3Strlen30NN(C) (strlen(C)&0x3fffffff)
20701 # define EXP754 (((u64)0x7ff)<<52)
20703 # define IsNaN(X) (((X)&EXP754)==EXP754 && ((X)&MAN754)!=0)
20708 # define IsNaN(X) 0
20709 # define sqlite3IsNaN(X) 0
20710 # define sqlite3IsOVerflow(X) 0
20892 #define sqlite3CodecQueryParameters(A,B,C) 0
20924 # define sqlite3ViewGetColumnNames(A,B) 0
20993 #define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */
21011 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
21012 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
21013 #define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */
21014 #define SQLITE_ECEL_OMITREF 0x08 /* Omit if ExprList.u.x.iOrderByCol */
21019 #define LOCATE_VIEW 0x01
21020 #define LOCATE_NOERR 0x02
21141 # define sqlite3IsToplevel(p) ((p)->pToplevel==0)
21143 # define sqlite3TriggersExist(B,C,D,E,F) 0
21149 # define sqlite3TriggerList(X, Y) 0
21152 # define sqlite3TriggerColmask(A,B,C,D,E,F,G) 0
21153 # define sqlite3TriggerStepSrc(A,B) 0
21220 (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B)))
21222 B=(u32)*(A);if(B>=0x80)sqlite3GetVarint32((A),(u32*)&(B))
21224 (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\
21258 # define sqlite3IsMemdb(X) 0
21467 # define sqlite3VtabInSync(db) 0
21473 # define sqlite3GetVTable(X,Y) ((VTable*)0)
21494 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
21502 # define sqlite3ShadowTableName(A,B) 0
21503 # define sqlite3IsShadowTableOf(A,B,C) 0
21547 # define sqlite3CteNew(P,T,E,S) ((void*)0)
21549 # define sqlite3CteWithAdd(P,W,C) ((void*)0)
21551 # define sqlite3WithPush(x,y,z) ((void*)0)
21562 #define sqlite3UpsertNew(u,v,w,x,y,z) ((Upsert*)0)
21564 #define sqlite3UpsertDup(x,y) ((Upsert*)0)
21565 #define sqlite3UpsertOfIndex(x,y) ((Upsert*)0)
21566 #define sqlite3UpsertNextIsIPK(x) 0
21589 #define sqlite3FkOldmask(a,b) 0
21590 #define sqlite3FkRequired(a,b,c,d) 0
21591 #define sqlite3FkReferences(a) 0
21604 ** Available fault injectors. Should be numbered beginning with 0.
21606 #define SQLITE_FAULTINJECTOR_MALLOC 0
21633 #define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */
21634 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */
21635 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
21649 #if SQLITE_MAX_EXPR_DEPTH>0
21653 #define sqlite3SelectExprHeight(x) 0
21729 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
21730 #define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */
21731 #define MEMTYPE_PCACHE 0x04 /* Page cache allocations */
21736 #if SQLITE_MAX_WORKER_THREADS>0
21771 # define IS_STMT_SCANSTATUS(db) 0
21823 #define TIMER_ELAPSED ((sqlite_uint64)0)
22671 *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]); in sqlite3CompileOptions()
22704 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
22721 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 0x */
22760 1, 0, 0, 1, 1, 0, /* aLTb[]: Use when compare(A,B) less than zero */
22761 0, 1, 0, 1, 0, 1, /* aEQb[]: Use when compare(A,B) equals zero */
22762 1, 0, 1, 0, 0, 1 /* aGTb[]: Use when compare(A,B) greater than zero*/
22772 ** isspace() 0x01
22773 ** isalpha() 0x02
22774 ** isdigit() 0x04
22775 ** isalnum() 0x06
22776 ** isxdigit() 0x08
22777 ** toupper() 0x20
22778 ** SQLite identifier character 0x40 $, _, or non-ascii
22779 ** Quote character 0x80
22781 ** Bit 0x20 is set if the mapped character requires translation to upper
22784 ** is (x - 0x20). Therefore toupper() can be implemented as:
22786 ** (x & ~(map[x]&0x20))
22791 ** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
22794 ** part of an identifier is 0x46.
22797 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
22798 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
22799 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
22800 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
22801 0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80, /* 20..27 !"#$%&' */
22802 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */
22803 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */
22804 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */
22806 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */
22807 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */
22808 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */
22809 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
22810 0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
22811 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */
22812 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */
22813 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */
22815 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */
22816 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 88..8f ........ */
22817 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 90..97 ........ */
22818 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 98..9f ........ */
22819 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a0..a7 ........ */
22820 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a8..af ........ */
22821 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b0..b7 ........ */
22822 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b8..bf ........ */
22824 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c0..c7 ........ */
22825 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c8..cf ........ */
22826 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d0..d7 ........ */
22827 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d8..df ........ */
22828 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e0..e7 ........ */
22829 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e8..ef ........ */
22830 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
22831 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
22839 ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
22846 # define SQLITE_USE_URI 0
22858 -DSQLITE_ALLOW_COVERING_INDEX_SCAN=0 option is deprecated.\
22872 ** threshold (in bytes). 0 means that statement journals are created and
22874 ** before 3.12.0). -1 means always keep the entire statement journal in
22922 0, /* bSmallMalloc */
22926 0, /* bJsonSelfcheck */
22928 0x7ffffffe, /* mxStrlen */
22929 0, /* neverCorrupt */
22932 {0,0,0,0,0,0,0,0}, /* m */
22933 {0,0,0,0,0,0,0,0,0}, /* mutex */
22934 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
22935 (void*)0, /* pHeap */
22936 0, /* nHeap */
22937 0, 0, /* mnHeap, mxHeap */
22940 (void*)0, /* pPage */
22941 0, /* szPage */
22943 0, /* mxParserStack */
22944 0, /* sharedCacheEnabled */
22947 0, /* isInit */
22948 0, /* inProgress */
22949 0, /* isMutexInit */
22950 0, /* isMallocInit */
22951 0, /* isPCacheInit */
22952 0, /* nRefInitMutex */
22953 0, /* pInitMutex */
22954 0, /* xLog */
22955 0, /* pLogArg */
22957 0, /* xSqllog */
22958 0, /* pSqllogArg */
22961 0, /* xVdbeBranch */
22962 0, /* pVbeBranchArg */
22968 0, /* xTestCallback */
22971 0, /* mNoVisibleRowid. 0 == allow rowid-in-view */
22973 0, /* bLocaltimeFault */
22974 0, /* xAltLocaltime */
22975 0x7ffffffe, /* iOnceResetThreshold */
22977 0, /* iPrngSeed */
22979 {0,0,0,0,0,0}, /* aTune */
23007 SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt = 0;
23011 ** The value of the "pending" byte must be 0x40000000 (1 byte past the
23024 ** 0x40000000 results in an incompatible database file format!
23029 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
23035 SQLITE_PRIVATE u32 sqlite3TreeTrace = 0;
23036 SQLITE_PRIVATE u32 sqlite3WhereTrace = 0;
23139 # define VDBE_DISPLAY_P4 0
23164 #define CURTYPE_BTREE 0
23204 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
23207 int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
23246 ((P)->eCurType==CURTYPE_PSEUDO && (P)->nullRow && (P)->seekResult==0)
23251 #define CACHE_STALE 0
23313 #define SQLITE_FRAME_MAGIC 0x879fb71e
23335 int n; /* Number of characters in string value, excluding '\0' */
23343 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
23384 ** MEM.u.i extra 0x00 bytes at the end.
23402 #define MEM_Undefined 0x0000 /* Value is undefined */
23403 #define MEM_Null 0x0001 /* Value is NULL (or a pointer) */
23404 #define MEM_Str 0x0002 /* Value is a string */
23405 #define MEM_Int 0x0004 /* Value is an integer */
23406 #define MEM_Real 0x0008 /* Value is a real number */
23407 #define MEM_Blob 0x0010 /* Value is a BLOB */
23408 #define MEM_IntReal 0x0020 /* MEM_Int that stringifies like MEM_Real */
23409 #define MEM_AffMask 0x003f /* Mask of affinity bits */
23413 #define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */
23414 /* 0x0080 // Available */
23415 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
23416 #define MEM_Term 0x0200 /* String in Mem.z is zero terminated */
23417 #define MEM_Zero 0x0400 /* Mem.i contains count of 0s appended to blob */
23418 #define MEM_Subtype 0x0800 /* Mem.eSubtype is valid */
23419 #define MEM_TypeMask 0x0dbf /* Mask of type bits */
23424 #define MEM_Dyn 0x1000 /* Need to call Mem.xDel() on Mem.z */
23425 #define MEM_Static 0x2000 /* Mem.z points to a static string */
23426 #define MEM_Ephem 0x4000 /* Mem.z points to an ephemeral string */
23427 #define MEM_Agg 0x8000 /* Mem.z points to an agg function context */
23433 (((X)->flags&(MEM_Agg|MEM_Dyn))!=0)
23446 && (X)->n==0 && (X)->u.nZero==0)
23457 #define memIsValid(M) ((M)->flags & MEM_AffMask)!=0
23515 ** instructions. A start value of 0 indicates an empty range.
23559 int iStatement; /* Statement number (or 0 if has no opened stmt) */
23593 bft explain:2; /* 0: normal, 1: EXPLAIN, 2: EXPLAIN QUERY PLAN */
23623 #define VDBE_INIT_STATE 0 /* Prepared statement under construction */
23798 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
23812 # define sqlite3VdbeCheckFk(p,i) 0
23826 #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
23849 } sqlite3Stat = { {0,}, {0,} };
23856 0, /* SQLITE_STATUS_MEMORY_USED */
23859 0, /* SQLITE_STATUS_SCRATCH_USED */
23860 0, /* SQLITE_STATUS_SCRATCH_OVERFLOW */
23861 0, /* SQLITE_STATUS_MALLOC_SIZE */
23862 0, /* SQLITE_STATUS_PARSER_STACK */
23864 0, /* SQLITE_STATUS_SCRATCH_SIZE */
23865 0, /* SQLITE_STATUS_MALLOC_COUNT */
23877 # define wsdStat x[0]
23889 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); in sqlite3StatusValue()
23890 assert( op>=0 && op<ArraySize(statMutex) ); in sqlite3StatusValue()
23909 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); in sqlite3StatusUp()
23910 assert( op>=0 && op<ArraySize(statMutex) ); in sqlite3StatusUp()
23920 assert( N>=0 ); in sqlite3StatusDown()
23921 assert( op>=0 && op<ArraySize(statMutex) ); in sqlite3StatusDown()
23924 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); in sqlite3StatusDown()
23935 assert( X>=0 ); in sqlite3StatusHighwater()
23937 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); in sqlite3StatusHighwater()
23938 assert( op>=0 && op<ArraySize(statMutex) ); in sqlite3StatusHighwater()
23960 if( op<0 || op>=ArraySize(wsdStat.nowValue) ){ in sqlite3_status64()
23964 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; in sqlite3_status64()
23974 (void)pMutex; /* Prevent warning when SQLITE_THREADSAFE=0 */ in sqlite3_status64()
23978 sqlite3_int64 iCur = 0, iHwtr = 0; in sqlite3_status()
23981 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; in sqlite3_status()
23984 if( rc==0 ){ in sqlite3_status()
23995 u32 cnt = 0; in countLookasideSlots()
24029 if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){ in sqlite3_db_status()
24043 db->lookaside.pFree = 0; in sqlite3_db_status()
24051 db->lookaside.pSmallFree = 0; in sqlite3_db_status()
24064 assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 ); in sqlite3_db_status()
24066 *pCurrent = 0; in sqlite3_db_status()
24069 db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0; in sqlite3_db_status()
24081 int totalUsed = 0; in sqlite3_db_status()
24084 for(i=0; i<db->nDb; i++){ in sqlite3_db_status()
24097 *pHighwater = 0; in sqlite3_db_status()
24108 int nByte = 0; /* Used to accumulate return value */ in sqlite3_db_status()
24114 for(i=0; i<db->nDb; i++){ in sqlite3_db_status()
24116 if( ALWAYS(pSchema!=0) ){ in sqlite3_db_status()
24138 db->pnBytesFreed = 0; in sqlite3_db_status()
24142 *pHighwater = 0; in sqlite3_db_status()
24154 int nByte = 0; /* Used to accumulate return value */ in sqlite3_db_status()
24163 db->pnBytesFreed = 0; in sqlite3_db_status()
24165 *pHighwater = 0; /* IMP: R-64479-57858 */ in sqlite3_db_status()
24183 u64 nRet = 0; in sqlite3_db_status()
24187 for(i=0; i<db->nDb; i++){ in sqlite3_db_status()
24193 *pHighwater = 0; /* IMP: R-42420-56072 */ in sqlite3_db_status()
24196 *pCurrent = (int)nRet & 0x7fffffff; in sqlite3_db_status()
24205 *pHighwater = 0; /* IMP: R-11967-56545 */ in sqlite3_db_status()
24206 *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0; in sqlite3_db_status()
24261 ** ISBN 0-943396-61-1
24313 ** B: minimum value. Always "0" or "1".
24336 int cnt = 0; in getDigits()
24340 char N = zFormat[0] - '0'; in getDigits()
24341 char min = zFormat[1] - '0'; in getDigits()
24342 int val = 0; in getDigits()
24348 val = 0; in getDigits()
24353 val = val*10 + *zDate - '0'; in getDigits()
24356 if( val<(int)min || val>(int)max || (nextC!=0 && nextC!=*zDate) ){ in getDigits()
24380 ** of change in p->tz and return 0. If a parser error occurs,
24386 int sgn = 0; in parseTimezone()
24390 p->tz = 0; in parseTimezone()
24398 p->isLocal = 0; in parseTimezone()
24402 return c!=0; in parseTimezone()
24412 return *zDate!=0; in parseTimezone()
24420 ** Return 1 if there is a parsing error and 0 on success.
24439 ms = ms*10.0 + *zDate - '0'; in parseHhMmSs()
24446 s = 0; in parseHhMmSs()
24448 p->validJD = 0; in parseHhMmSs()
24449 p->rawS = 0; in parseHhMmSs()
24455 return 0; in parseHhMmSs()
24462 memset(p, 0, sizeof(*p)); in datetimeError()
24503 p->validYMD = 0; in computeJD()
24504 p->validHMS = 0; in computeJD()
24505 p->tz = 0; in computeJD()
24507 p->isLocal = 0; in computeJD()
24520 assert( p->D>=0 && p->D<=31 ); in computeFloor()
24521 assert( p->M>=0 && p->M<=12 ); in computeFloor()
24523 p->nFloor = 0; in computeFloor()
24524 }else if( (1<<p->M) & 0x15aa ){ in computeFloor()
24525 p->nFloor = 0; in computeFloor()
24528 }else if( p->Y%4!=0 || (p->Y%100==0 && p->Y%400!=0) ){ in computeFloor()
24543 ** Write the result into the DateTime structure and return 0
24550 if( zDate[0]=='-' ){ in parseYyyyMmDd()
24554 neg = 0; in parseYyyyMmDd()
24561 if( parseHhMmSs(zDate, p)==0 ){ in parseYyyyMmDd()
24563 }else if( *zDate==0 ){ in parseYyyyMmDd()
24564 p->validHMS = 0; in parseYyyyMmDd()
24568 p->validJD = 0; in parseYyyyMmDd()
24577 return 0; in parseYyyyMmDd()
24590 if( p->iJD>0 ){ in setDateTimeToCurrent()
24593 p->isLocal = 0; in setDateTimeToCurrent()
24595 return 0; in setDateTimeToCurrent()
24638 if( parseYyyyMmDd(zDate,p)==0 ){ in parseDateOrTime()
24639 return 0; in parseDateOrTime()
24640 }else if( parseHhMmSs(zDate, p)==0 ){ in parseDateOrTime()
24641 return 0; in parseDateOrTime()
24642 }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){ in parseDateOrTime()
24644 }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8)>0 ){ in parseDateOrTime()
24646 return 0; in parseDateOrTime()
24647 }else if( (sqlite3StrICmp(zDate,"subsec")==0 in parseDateOrTime()
24648 || sqlite3StrICmp(zDate,"subsecond")==0) in parseDateOrTime()
24663 #define INT_464269060799999 ((((i64)0x1a640)<<32)|0x1072fdff)
24671 return iJD>=0 && iJD<=INT_464269060799999; in validJulianDay()
24715 p->rawS = 0; in computeHMS()
24731 p->validYMD = 0; in clearYMD_HMS_TZ()
24732 p->validHMS = 0; in clearYMD_HMS_TZ()
24733 p->tz = 0; in clearYMD_HMS_TZ()
24758 ** is available. This routine returns 0 on success and
24774 #if SQLITE_THREADSAFE>0 in osLocaltime()
24781 if( sqlite3GlobalConfig.xAltLocaltime!=0 in osLocaltime()
24782 && 0==sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm) in osLocaltime()
24786 pX = 0; in osLocaltime()
24791 #if SQLITE_THREADSAFE>0 in osLocaltime()
24794 rc = pX==0; in osLocaltime()
24798 if( sqlite3GlobalConfig.xAltLocaltime!=0 ){ in osLocaltime()
24806 rc = localtime_r(t, pTm)==0; in osLocaltime()
24829 memset(&sLocal, 0, sizeof(sLocal)); in toLocaltime()
24844 x.validJD = 0; in toLocaltime()
24848 iYearDiff = 0; in toLocaltime()
24863 p->validJD = 0; in toLocaltime()
24864 p->rawS = 0; in toLocaltime()
24865 p->tz = 0; in toLocaltime()
24866 p->isError = 0; in toLocaltime()
24885 /* 0 */ { 6, "second", 4.6427e+14, 1.0 },
24900 p->rawS = 0; in autoAdjustDate()
24908 p->rawS = 0; in autoAdjustDate()
24937 ** Return 0 on success and 1 if there is any kind of error. If the error
24951 switch(sqlite3UpperToLower[(u8)z[0]] ){ in parseModifier()
24959 if( sqlite3_stricmp(z, "auto")==0 ){ in parseModifier()
24962 rc = 0; in parseModifier()
24974 if( sqlite3_stricmp(z, "ceiling")==0 ){ in parseModifier()
24977 rc = 0; in parseModifier()
24978 p->nFloor = 0; in parseModifier()
24989 if( sqlite3_stricmp(z, "floor")==0 ){ in parseModifier()
24993 rc = 0; in parseModifier()
25004 ** SQLite (0..5373484.5) then the result will be NULL. in parseModifier()
25006 if( sqlite3_stricmp(z, "julianday")==0 ){ in parseModifier()
25009 rc = 0; in parseModifier()
25010 p->rawS = 0; in parseModifier()
25022 if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){ in parseModifier()
25024 p->isUtc = 0; in parseModifier()
25037 if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){ in parseModifier()
25044 p->rawS = 0; in parseModifier()
25045 rc = 0; in parseModifier()
25049 else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){ in parseModifier()
25050 if( p->isUtc==0 ){ in parseModifier()
25053 int cnt = 0; /* Safety to prevent infinite loop */ in parseModifier()
25058 iErr = 0; in parseModifier()
25061 memset(&new, 0, sizeof(new)); in parseModifier()
25070 memset(p, 0, sizeof(*p)); in parseModifier()
25074 p->isLocal = 0; in parseModifier()
25086 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the in parseModifier()
25089 if( sqlite3_strnicmp(z, "weekday ", 8)==0 in parseModifier()
25090 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)>0 in parseModifier()
25094 p->tz = 0; in parseModifier()
25095 p->validJD = 0; in parseModifier()
25101 rc = 0; in parseModifier()
25118 if( sqlite3_strnicmp(z, "start of ", 9)!=0 ){ in parseModifier()
25119 if( sqlite3_stricmp(z, "subsec")==0 in parseModifier()
25120 || sqlite3_stricmp(z, "subsecond")==0 in parseModifier()
25123 rc = 0; in parseModifier()
25131 p->h = p->m = 0; in parseModifier()
25133 p->rawS = 0; in parseModifier()
25134 p->tz = 0; in parseModifier()
25135 p->validJD = 0; in parseModifier()
25136 if( sqlite3_stricmp(z,"month")==0 ){ in parseModifier()
25138 rc = 0; in parseModifier()
25139 }else if( sqlite3_stricmp(z,"year")==0 ){ in parseModifier()
25142 rc = 0; in parseModifier()
25143 }else if( sqlite3_stricmp(z,"day")==0 ){ in parseModifier()
25144 rc = 0; in parseModifier()
25150 case '0': in parseModifier()
25164 char z0 = z[0]; in parseModifier()
25173 if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){ in parseModifier()
25180 ** the range 0-11 and DD is limited to 0-30. in parseModifier()
25190 if( M>=12 ) break; /* M range 0..11 */ in parseModifier()
25191 if( D>=31 ) break; /* D range 0..30 */ in parseModifier()
25193 p->validJD = 0; in parseModifier()
25202 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; in parseModifier()
25207 p->validHMS = 0; in parseModifier()
25208 p->validYMD = 0; in parseModifier()
25210 if( z[11]==0 ){ in parseModifier()
25211 rc = 0; in parseModifier()
25233 memset(&tx, 0, sizeof(tx)); in parseModifier()
25243 rc = 0; in parseModifier()
25256 rRounder = r<0 ? -0.5 : +0.5; in parseModifier()
25257 p->nFloor = 0; in parseModifier()
25258 for(i=0; i<ArraySize(aXformType); i++){ in parseModifier()
25260 && sqlite3_strnicmp(aXformType[i].zName, z, n)==0 in parseModifier()
25265 assert( strcmp(aXformType[4].zName,"month")==0 ); in parseModifier()
25268 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; in parseModifier()
25272 p->validJD = 0; in parseModifier()
25278 assert( strcmp(aXformType[5].zName,"year")==0 ); in parseModifier()
25280 assert( p->M>=0 && p->M<=12 ); in parseModifier()
25283 p->validJD = 0; in parseModifier()
25290 rc = 0; in parseModifier()
25305 ** Process time function arguments. argv[0] is a date-time stamp.
25307 ** the resulting time into the DateTime structure p. Return 0
25310 ** If there are zero parameters (if even argv[0] is undefined)
25311 ** then assume a default value of "now" for argv[0].
25322 memset(p, 0, sizeof(*p)); in isDate()
25323 if( argc==0 ){ in isDate()
25327 if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT in isDate()
25329 setRawDateNumber(p, sqlite3_value_double(argv[0])); in isDate()
25331 z = sqlite3_value_text(argv[0]); in isDate()
25339 if( z==0 || parseModifier(context, (char*)z, n, p, i) ) return 1; in isDate()
25347 p->validYMD = 0; in isDate()
25349 return 0; in isDate()
25369 if( isDate(context, argc, argv, &x)==0 ){ in juliandayFunc()
25387 if( isDate(context, argc, argv, &x)==0 ){ in unixepochFunc()
25408 if( isDate(context, argc, argv, &x)==0 ){ in datetimeFunc()
25413 if( Y<0 ) Y = -Y; in datetimeFunc()
25414 zBuf[1] = '0' + (Y/1000)%10; in datetimeFunc()
25415 zBuf[2] = '0' + (Y/100)%10; in datetimeFunc()
25416 zBuf[3] = '0' + (Y/10)%10; in datetimeFunc()
25417 zBuf[4] = '0' + (Y)%10; in datetimeFunc()
25419 zBuf[6] = '0' + (x.M/10)%10; in datetimeFunc()
25420 zBuf[7] = '0' + (x.M)%10; in datetimeFunc()
25422 zBuf[9] = '0' + (x.D/10)%10; in datetimeFunc()
25423 zBuf[10] = '0' + (x.D)%10; in datetimeFunc()
25425 zBuf[12] = '0' + (x.h/10)%10; in datetimeFunc()
25426 zBuf[13] = '0' + (x.h)%10; in datetimeFunc()
25428 zBuf[15] = '0' + (x.m/10)%10; in datetimeFunc()
25429 zBuf[16] = '0' + (x.m)%10; in datetimeFunc()
25433 zBuf[18] = '0' + (s/10000)%10; in datetimeFunc()
25434 zBuf[19] = '0' + (s/1000)%10; in datetimeFunc()
25436 zBuf[21] = '0' + (s/100)%10; in datetimeFunc()
25437 zBuf[22] = '0' + (s/10)%10; in datetimeFunc()
25438 zBuf[23] = '0' + (s)%10; in datetimeFunc()
25439 zBuf[24] = 0; in datetimeFunc()
25443 zBuf[18] = '0' + (s/10)%10; in datetimeFunc()
25444 zBuf[19] = '0' + (s)%10; in datetimeFunc()
25445 zBuf[20] = 0; in datetimeFunc()
25448 if( x.Y<0 ){ in datetimeFunc()
25449 zBuf[0] = '-'; in datetimeFunc()
25468 if( isDate(context, argc, argv, &x)==0 ){ in timeFunc()
25472 zBuf[0] = '0' + (x.h/10)%10; in timeFunc()
25473 zBuf[1] = '0' + (x.h)%10; in timeFunc()
25475 zBuf[3] = '0' + (x.m/10)%10; in timeFunc()
25476 zBuf[4] = '0' + (x.m)%10; in timeFunc()
25480 zBuf[6] = '0' + (s/10000)%10; in timeFunc()
25481 zBuf[7] = '0' + (s/1000)%10; in timeFunc()
25483 zBuf[9] = '0' + (s/100)%10; in timeFunc()
25484 zBuf[10] = '0' + (s/10)%10; in timeFunc()
25485 zBuf[11] = '0' + (s)%10; in timeFunc()
25486 zBuf[12] = 0; in timeFunc()
25490 zBuf[6] = '0' + (s/10)%10; in timeFunc()
25491 zBuf[7] = '0' + (s)%10; in timeFunc()
25492 zBuf[8] = 0; in timeFunc()
25510 if( isDate(context, argc, argv, &x)==0 ){ in dateFunc()
25515 if( Y<0 ) Y = -Y; in dateFunc()
25516 zBuf[1] = '0' + (Y/1000)%10; in dateFunc()
25517 zBuf[2] = '0' + (Y/100)%10; in dateFunc()
25518 zBuf[3] = '0' + (Y/10)%10; in dateFunc()
25519 zBuf[4] = '0' + (Y)%10; in dateFunc()
25521 zBuf[6] = '0' + (x.M/10)%10; in dateFunc()
25522 zBuf[7] = '0' + (x.M)%10; in dateFunc()
25524 zBuf[9] = '0' + (x.D/10)%10; in dateFunc()
25525 zBuf[10] = '0' + (x.D)%10; in dateFunc()
25526 zBuf[11] = 0; in dateFunc()
25527 if( x.Y<0 ){ in dateFunc()
25528 zBuf[0] = '-'; in dateFunc()
25542 ** Jan01 = 0, Jan02 = 1, ..., Jan31 = 30, Feb01 = 31, ...
25550 jan01.validJD = 0; in daysAfterJan01()
25563 ** 0=Monday, 1=Tuesday, 2=Wednesday, ..., 6=Sunday.
25576 ** 0=Sunday, 1=Monday, 2=Tues, ..., 6=Saturday
25595 ** %k hour 0-24 (leading zero converted to space)
25609 ** %w day of week 0-6 Sunday==0, Monday==1
25628 if( argc==0 ) return; in strftimeFunc()
25629 zFmt = (const char*)sqlite3_value_text(argv[0]); in strftimeFunc()
25630 if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return; in strftimeFunc()
25632 sqlite3StrAccumInit(&sRes, 0, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); in strftimeFunc()
25636 for(i=j=0; zFmt[i]; i++){ in strftimeFunc()
25665 y.validYMD = 0; in strftimeFunc()
25683 if( h==0 ) h = 12; in strftimeFunc()
25735 case 'w': { /* Day of week. 0 to 6. Sunday==0, Monday==1 */ in strftimeFunc()
25736 char c = (char)daysAfterSunday(&x) + '0'; in strftimeFunc()
25737 if( c=='0' && cf=='u' ) c = '7'; in strftimeFunc()
25751 y.validYMD = 0; in strftimeFunc()
25790 timeFunc(context, 0, 0); in ctimeFunc()
25804 dateFunc(context, 0, 0); in cdateFunc()
25834 if( isDate(context, 1, &argv[0], &d1) ) return; in timediffFunc()
25843 d2.validJD = 0; in timediffFunc()
25847 if( M<0 ){ in timediffFunc()
25851 if( M!=0 ){ in timediffFunc()
25853 d2.validJD = 0; in timediffFunc()
25858 if( M<0 ){ in timediffFunc()
25867 d2.validJD = 0; in timediffFunc()
25877 d2.validJD = 0; in timediffFunc()
25881 if( M<0 ){ in timediffFunc()
25885 if( M!=0 ){ in timediffFunc()
25887 d2.validJD = 0; in timediffFunc()
25892 if( M<0 ){ in timediffFunc()
25901 d2.validJD = 0; in timediffFunc()
25909 sqlite3StrAccumInit(&sRes, 0, 0, 0, 100); in timediffFunc()
25927 datetimeFunc(context, 0, 0); in ctimestampFunc()
25959 if( iT<=0 ) return; in currentTimeFunc()
25989 if( isDate(context, argc, argv, &x)==0 ){ in datedebugFunc()
26014 PURE_DATE(julianday, -1, 0, 0, juliandayFunc ), in sqlite3RegisterDateTimeFunctions()
26015 PURE_DATE(unixepoch, -1, 0, 0, unixepochFunc ), in sqlite3RegisterDateTimeFunctions()
26016 PURE_DATE(date, -1, 0, 0, dateFunc ), in sqlite3RegisterDateTimeFunctions()
26017 PURE_DATE(time, -1, 0, 0, timeFunc ), in sqlite3RegisterDateTimeFunctions()
26018 PURE_DATE(datetime, -1, 0, 0, datetimeFunc ), in sqlite3RegisterDateTimeFunctions()
26019 PURE_DATE(strftime, -1, 0, 0, strftimeFunc ), in sqlite3RegisterDateTimeFunctions()
26020 PURE_DATE(timediff, 2, 0, 0, timediffFunc ), in sqlite3RegisterDateTimeFunctions()
26022 PURE_DATE(datedebug, -1, 0, 0, datedebugFunc ), in sqlite3RegisterDateTimeFunctions()
26024 DFUNCTION(current_time, 0, 0, 0, ctimeFunc ), in sqlite3RegisterDateTimeFunctions()
26025 DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc), in sqlite3RegisterDateTimeFunctions()
26026 DFUNCTION(current_date, 0, 0, 0, cdateFunc ), in sqlite3RegisterDateTimeFunctions()
26028 STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc), in sqlite3RegisterDateTimeFunctions()
26029 STR_FUNCTION(current_date, 0, "%Y-%m-%d", 0, currentTimeFunc), in sqlite3RegisterDateTimeFunctions()
26030 STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc), in sqlite3RegisterDateTimeFunctions()
26061 SQLITE_API int sqlite3_io_error_hit = 0; /* Total number of I/O Errors */
26062 SQLITE_API int sqlite3_io_error_hardhit = 0; /* Number of non-benign errors */
26063 SQLITE_API int sqlite3_io_error_pending = 0; /* Count down to first I/O error */
26064 SQLITE_API int sqlite3_io_error_persist = 0; /* True if I/O errors persist */
26065 SQLITE_API int sqlite3_io_error_benign = 0; /* True if errors are benign */
26066 SQLITE_API int sqlite3_diskfull_pending = 0;
26067 SQLITE_API int sqlite3_diskfull = 0;
26074 SQLITE_API int sqlite3_open_file_count = 0;
26122 pId->pMethods = 0; in sqlite3OsClose()
26167 if( id->pMethods==0 ) return SQLITE_NOTFOUND; in sqlite3OsFileControl()
26203 if( NEVER(id->pMethods==0) ) return 0; in sqlite3OsDeviceCharacteristics()
26228 #if SQLITE_MAX_MMAP_SIZE>0
26240 *pp = 0; in sqlite3OsFetch()
26260 DO_OS_MALLOC_TEST(0); in sqlite3OsOpen()
26261 /* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed in sqlite3OsOpen()
26266 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut); in sqlite3OsOpen()
26267 assert( rc==SQLITE_OK || pFile->pMethods==0 ); in sqlite3OsOpen()
26271 DO_OS_MALLOC_TEST(0); in sqlite3OsDelete()
26272 assert( dirSync==0 || dirSync==1 ); in sqlite3OsDelete()
26273 return pVfs->xDelete!=0 ? pVfs->xDelete(pVfs, zPath, dirSync) : SQLITE_OK; in sqlite3OsDelete()
26281 DO_OS_MALLOC_TEST(0); in sqlite3OsAccess()
26290 DO_OS_MALLOC_TEST(0); in sqlite3OsFullPathname()
26291 zPathOut[0] = 0; in sqlite3OsFullPathname()
26296 assert( zPath!=0 ); in sqlite3OsDlOpen()
26312 memset(zBufOut, 0, nByte); in sqlite3OsRandomness()
26325 return pVfs->xGetLastError ? pVfs->xGetLastError(pVfs, 0, 0) : 0; in sqlite3OsGetLastError()
26359 *ppFile = 0; in sqlite3OsOpenMalloc()
26364 *ppFile = 0; in sqlite3OsOpenMalloc()
26367 assert( *ppFile!=0 || rc!=SQLITE_OK ); in sqlite3OsOpenMalloc()
26384 if( p==0 ) return SQLITE_NOMEM_BKPT; in sqlite3OsInit()
26392 static sqlite3_vfs * SQLITE_WSD vfsList = 0;
26400 sqlite3_vfs *pVfs = 0; in sqlite3_vfs_find()
26406 if( rc ) return 0; in sqlite3_vfs_find()
26413 if( zVfs==0 ) break; in sqlite3_vfs_find()
26414 if( strcmp(zVfs, pVfs->zName)==0 ) break; in sqlite3_vfs_find()
26425 if( pVfs==0 ){ in vfsUnlink()
26452 if( pVfs==0 ) return SQLITE_MISUSE_BKPT; in sqlite3_vfs_register()
26458 if( makeDflt || vfsList==0 ){ in sqlite3_vfs_register()
26503 ** and returns 0).
26525 } sqlite3Hooks = { 0, 0 };
26536 # define wsdHooks x[0]
26608 static void *sqlite3MemMalloc(int nByte){ return 0; } in sqlite3MemMalloc()
26610 static void *sqlite3MemRealloc(void *pPrior, int nByte){ return 0; } in sqlite3MemRealloc()
26611 static int sqlite3MemSize(void *pPrior){ return 0; } in sqlite3MemSize()
26631 0 in sqlite3MemSetDefault()
26763 ** For this low-level routine, we are guaranteed that nByte>0 because
26764 ** cases of nByte<=0 will be intercepted and dealt with by higher level
26772 if( p==0 ){ in sqlite3MemMalloc()
26773 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3MemMalloc()
26779 assert( nByte>0 ); in sqlite3MemMalloc()
26783 p[0] = nByte; in sqlite3MemMalloc()
26786 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3MemMalloc()
26797 ** For this low-level routine, we already know that pPrior!=0 since
26798 ** cases where pPrior==0 will have been intercepted and dealt with
26806 assert( pPrior!=0 ); in sqlite3MemFree()
26818 assert( pPrior!=0 ); in sqlite3MemSize()
26822 assert( pPrior!=0 ); in sqlite3MemSize()
26825 return (int)p[0]; in sqlite3MemSize()
26833 ** For this low-level interface, we know that pPrior!=0. Cases where
26834 ** pPrior==0 while have been intercepted by higher-level routine and
26835 ** redirected to xMalloc. Similarly, we know that nByte>0 because
26836 ** cases where nByte<=0 will have been intercepted by higher-level
26842 if( p==0 ){ in sqlite3MemRealloc()
26843 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3MemRealloc()
26851 assert( pPrior!=0 && nByte>0 ); in sqlite3MemRealloc()
26856 p[0] = nByte; in sqlite3MemRealloc()
26859 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3MemRealloc()
26887 sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0); in sqlite3MemInit()
26894 _sqliteZone_ = malloc_create_zone(4096, 0); in sqlite3MemInit()
26925 0 in sqlite3MemSetDefault()
26993 u8 nTitle; /* Bytes of title; includes '\0' */
27001 #define FOREGUARD 0x80F5E153
27002 #define REARGUARD 0xE4676B53
27037 int nTitle; /* Bytes of zTitle to save. Includes '\0' and padding */
27067 if( increment>0 ){ in adjustStats()
27075 assert( mem.nCurrent[i]>=0 ); in adjustStats()
27102 while( nReserve-- > p->iSize ) assert( pU8[nReserve]==0x65 ); in sqlite3MemsysGetHeader()
27112 return 0; in sqlite3MemSize()
27123 assert( (sizeof(struct MemBlockHdr)&7) == 0 ); in sqlite3MemInit()
27137 mem.mutex = 0; in sqlite3MemShutdown()
27157 x = (x>>1) ^ (-(int)(x&1) & 0xd0000001); in randomFill()
27164 while( nByte-- > 0 ){ in randomFill()
27165 x = (x>>1) ^ (-(int)(x&1) & 0xd0000001); in randomFill()
27168 *(pBuf++) = r & 0xff; in randomFill()
27180 void *p = 0; in sqlite3MemMalloc()
27184 assert( mem.disallow==0 ); in sqlite3MemMalloc()
27193 pHdr->pNext = 0; in sqlite3MemMalloc()
27209 assert(pBt[0]); in sqlite3MemMalloc()
27214 pHdr->nBacktrace = 0; in sqlite3MemMalloc()
27224 memset(((char*)pInt)+nByte, 0x65, nReserve-nByte); in sqlite3MemMalloc()
27238 assert( sqlite3GlobalConfig.bMemstat || sqlite3GlobalConfig.bCoreMutex==0 in sqlite3MemFree()
27239 || mem.mutex!=0 ); in sqlite3MemFree()
27279 assert( mem.disallow==0 ); in sqlite3MemRealloc()
27280 assert( (nByte & 7)==0 ); /* EV: R-46199-30249 */ in sqlite3MemRealloc()
27306 0 in sqlite3MemSetDefault()
27338 if( (pHdr->eType&eType)==0 ){ in sqlite3MemdebugHasType()
27339 rc = 0; in sqlite3MemdebugHasType()
27360 if( (pHdr->eType&eType)!=0 ){ in sqlite3MemdebugNoType()
27361 rc = 0; in sqlite3MemdebugNoType()
27373 if( depth<0 ){ depth = 0; } in sqlite3MemdebugBacktrace()
27375 depth = (depth+1)&0xfe; in sqlite3MemdebugBacktrace()
27391 mem.zTitle[n] = 0; in sqlite3MemdebugSettitle()
27415 if( out==0 ){ in sqlite3MemdebugDump()
27434 for(i=0; i<NCSIZE-1; i++){ in sqlite3MemdebugDump()
27453 int nTotal = 0; in sqlite3MemdebugMallocCount()
27454 for(i=0; i<NCSIZE; i++){ in sqlite3MemdebugMallocCount()
27532 ** A chunk index of 0 means "no such chunk" and is the equivalent
27590 ** of the current key chunk. iKeyBlk is 0 if there is no key chunk.
27615 if( prev==0 ){ in memsys3UnlinkFromList()
27623 mem3.aPool[i].u.list.next = 0; in memsys3UnlinkFromList()
27624 mem3.aPool[i].u.list.prev = 0; in memsys3UnlinkFromList()
27634 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 ); in memsys3Unlink()
27654 mem3.aPool[i].u.list.prev = 0; in memsys3LinkIntoList()
27669 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 ); in memsys3Link()
27687 if( sqlite3GlobalConfig.bMemstat==0 && mem3.mutex==0 ){ in memsys3Enter()
27706 mem3.alarmBusy = 0; in memsys3OutOfMemory()
27732 ** is not large enough, return 0.
27740 mem3.iKeyBlk = 0; in memsys3FromKeyBlk()
27741 mem3.szKeyBlk = 0; in memsys3FromKeyBlk()
27742 mem3.mnKeyBlk = 0; in memsys3FromKeyBlk()
27783 for(i=*pRoot; i>0; i=iNext){ in memsys3Merge()
27786 assert( (size&1)==0 ); in memsys3Merge()
27787 if( (size&2)==0 ){ in memsys3Merge()
27839 if( i>0 ){ in memsys3MallocUnsafe()
27845 for(i=mem3.aiHash[hash]; i>0; i=mem3.aPool[i].u.list.next){ in memsys3MallocUnsafe()
27873 mem3.iKeyBlk = 0; in memsys3MallocUnsafe()
27874 mem3.szKeyBlk = 0; in memsys3MallocUnsafe()
27876 for(i=0; i<N_HASH; i++){ in memsys3MallocUnsafe()
27879 for(i=0; i<MX_SMALL-1; i++){ in memsys3MallocUnsafe()
27891 return 0; in memsys3MallocUnsafe()
27917 while( (mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x&2)==0 ){ in memsys3FreeUnsafe()
27927 while( (mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x&1)==0 ){ in memsys3FreeUnsafe()
27943 assert( p!=0 ); in memsys3Size()
27945 assert( (pBlock[-1].u.hdr.size4x&1)!=0 ); in memsys3Size()
27965 assert( nBytes>0 ); /* malloc.c filters out 0 byte requests */ in memsys3Malloc()
27988 if( pPrior==0 ){ in memsys3Realloc()
27991 if( nBytes<=0 ){ in memsys3Realloc()
27993 return 0; in memsys3Realloc()
28031 mem3.aPool[0].u.hdr.size4x = (mem3.szKeyBlk<<2) + 2; in memsys3Init()
28043 mem3.mutex = 0; in memsys3Shutdown()
28058 if( zFilename==0 || zFilename[0]==0 ){ in sqlite3Memsys3Dump()
28062 if( out==0 ){ in sqlite3Memsys3Dump()
28074 assert( 0 ); in sqlite3Memsys3Dump()
28077 if( (size&1)==0 && mem3.aPool[i+size/4-1].u.hdr.prevSize!=size/4 ){ in sqlite3Memsys3Dump()
28079 assert( 0 ); in sqlite3Memsys3Dump()
28084 assert( 0 ); in sqlite3Memsys3Dump()
28094 for(i=0; i<MX_SMALL-1; i++){ in sqlite3Memsys3Dump()
28095 if( mem3.aiSmall[i]==0 ) continue; in sqlite3Memsys3Dump()
28097 for(j = mem3.aiSmall[i]; j>0; j=mem3.aPool[j].u.list.next){ in sqlite3Memsys3Dump()
28103 for(i=0; i<N_HASH; i++){ in sqlite3Memsys3Dump()
28104 if( mem3.aiHash[i]==0 ) continue; in sqlite3Memsys3Dump()
28106 for(j = mem3.aiHash[i]; j>0; j=mem3.aPool[j].u.list.next){ in sqlite3Memsys3Dump()
28146 0 in sqlite3MemGetMemsys3()
28237 #define CTRL_LOGSIZE 0x1f /* Log2 Size of this block */
28238 #define CTRL_FREE 0x20 /* True if not checked out */
28274 ** Lists of free blocks. aiFreelist[0] is a list of free blocks of
28305 assert( i>=0 && i<mem5.nBlock ); in memsys5Unlink()
28306 assert( iLogsize>=0 && iLogsize<=LOGMAX ); in memsys5Unlink()
28311 if( prev<0 ){ in memsys5Unlink()
28316 if( next>=0 ){ in memsys5Unlink()
28328 assert( i>=0 && i<mem5.nBlock ); in memsys5Link()
28329 assert( iLogsize>=0 && iLogsize<=LOGMAX ); in memsys5Link()
28334 if( x>=0 ){ in memsys5Link()
28357 assert( p!=0 ); in memsys5Size()
28359 assert( i>=0 && i<mem5.nBlock ); in memsys5Size()
28366 ** Return NULL if unable. Return NULL if nBytes==0.
28381 assert( nByte>0 ); in memsys5MallocUnsafe()
28384 if( nByte > 0x40000000 ) return 0; in memsys5MallocUnsafe()
28396 for(iFullSz=mem5.szAtom,iLogsize=0; iFullSz<nByte; iFullSz*=2,iLogsize++){} in memsys5MallocUnsafe()
28402 for(iBin=iLogsize; iBin<=LOGMAX && mem5.aiFreelist[iBin]<0; iBin++){} in memsys5MallocUnsafe()
28404 testcase( sqlite3GlobalConfig.xLog!=0 ); in memsys5MallocUnsafe()
28406 return 0; in memsys5MallocUnsafe()
28434 memset(&mem5.zPool[i*mem5.szAtom], 0xAA, iFullSz); in memsys5MallocUnsafe()
28454 assert( iBlock>=0 && iBlock<mem5.nBlock ); in memsys5FreeUnsafe()
28455 assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 ); in memsys5FreeUnsafe()
28456 assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 ); in memsys5FreeUnsafe()
28466 assert( mem5.currentCount>0 ); in memsys5FreeUnsafe()
28470 assert( mem5.currentOut>0 || mem5.currentCount==0 ); in memsys5FreeUnsafe()
28471 assert( mem5.currentCount>0 || mem5.currentOut==0 ); in memsys5FreeUnsafe()
28479 assert( iBuddy>=0 ); in memsys5FreeUnsafe()
28489 mem5.aCtrl[iBlock] = 0; in memsys5FreeUnsafe()
28493 mem5.aCtrl[iBuddy] = 0; in memsys5FreeUnsafe()
28499 /* Overwrite freed memory with the 0x55 bit pattern to verify that it is in memsys5FreeUnsafe()
28501 memset(&mem5.zPool[iBlock*mem5.szAtom], 0x55, size); in memsys5FreeUnsafe()
28511 sqlite3_int64 *p = 0; in memsys5Malloc()
28512 if( nBytes>0 ){ in memsys5Malloc()
28524 ** being called with pPrior==0.
28527 assert( pPrior!=0 ); in memsys5Free()
28537 ** being called with pPrior==0.
28541 ** of two. If nBytes==0 that means that an oversize allocation
28542 ** (an allocation larger than 0x40000000) was requested and this
28543 ** routine should return 0 without freeing pPrior.
28548 assert( pPrior!=0 ); in memsys5Realloc()
28549 assert( (nBytes&(nBytes-1))==0 ); /* EV: R-46199-30249 */ in memsys5Realloc()
28550 assert( nBytes>=0 ); in memsys5Realloc()
28551 if( nBytes==0 ){ in memsys5Realloc()
28552 return 0; in memsys5Realloc()
28569 ** return 0.
28572 ** 32-bit signed integer. Hence the largest allocation is 0x40000000
28581 if( n>0x10000000 ){ in memsys5Roundup()
28582 if( n>0x40000000 ) return 0; in memsys5Roundup()
28583 if( n>0x20000000 ) return 0x40000000; in memsys5Roundup()
28584 return 0x20000000; in memsys5Roundup()
28594 ** Examples: memsys5Log(1) -> 0
28603 for(iLog=0; (iLog<(int)((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++); in memsys5Log()
28623 mem5.mutex = 0; in memsys5Init()
28628 assert( (sizeof(Mem5Link)&(sizeof(Mem5Link)-1))==0 ); in memsys5Init()
28632 assert( zByte!=0 ); /* sqlite3_config() does not allow otherwise */ in memsys5Init()
28645 for(ii=0; ii<=LOGMAX; ii++){ in memsys5Init()
28649 iOffset = 0; in memsys5Init()
28650 for(ii=LOGMAX; ii>=0; ii--){ in memsys5Init()
28661 if( sqlite3GlobalConfig.bMemstat==0 ){ in memsys5Init()
28673 mem5.mutex = 0; in memsys5Shutdown()
28687 if( zFilename==0 || zFilename[0]==0 ){ in sqlite3Memsys5Dump()
28691 if( out==0 ){ in sqlite3Memsys5Dump()
28699 for(i=0; i<=LOGMAX && i+nMinLog<32; i++){ in sqlite3Memsys5Dump()
28700 for(n=0, j=mem5.aiFreelist[i]; j>=0; j = MEM5LINK(j)->next, n++){} in sqlite3Memsys5Dump()
28734 0 in sqlite3MemGetMemsys5()
28766 static SQLITE_WSD int mutexIsInit = 0;
28827 pGlobalMutexMethods = 0; in checkMutexEnd()
28836 {2, 0}, {3, 0}, {4, 0}, {5, 0}, in checkMutexAlloc()
28837 {6, 0}, {7, 0}, {8, 0}, {9, 0}, in checkMutexAlloc()
28838 {10, 0}, {11, 0}, {12, 0}, {13, 0} in checkMutexAlloc()
28840 CheckMutex *p = 0; in checkMutexAlloc()
28842 assert( SQLITE_MUTEX_RECURSIVE==1 && SQLITE_MUTEX_FAST==0 ); in checkMutexAlloc()
28845 if( p==0 ) return 0; in checkMutexAlloc()
28851 return 0; in checkMutexAlloc()
28857 if( p->mutex==0 ){ in checkMutexAlloc()
28859 if( p->mutex==0 ){ in checkMutexAlloc()
28863 p = 0; in checkMutexAlloc()
28938 0, in multiThreadedCheckMutex()
28939 0 in multiThreadedCheckMutex()
29014 GLOBAL(int, mutexIsInit) = 0; in sqlite3MutexEnd()
29025 if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; in sqlite3_mutex_alloc()
29026 if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0; in sqlite3_mutex_alloc()
29034 return 0; in sqlite3MutexAlloc()
29094 assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld ); in sqlite3_mutex_held()
29095 return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p); in sqlite3_mutex_held()
29098 assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld ); in sqlite3_mutex_notheld()
29099 return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); in sqlite3_mutex_notheld()
29168 0, in sqlite3NoopMutex()
29169 0, in sqlite3NoopMutex()
29197 return p==0 || p->cnt>0; in debugMutexHeld()
29201 return p==0 || p->cnt==0; in debugMutexNotheld()
29217 sqlite3_debug_mutex *pNew = 0; in debugMutexAlloc()
29224 pNew->cnt = 0; in debugMutexAlloc()
29230 if( id-2<0 || id-2>=ArraySize(aStatic) ){ in debugMutexAlloc()
29232 return 0; in debugMutexAlloc()
29248 assert( p->cnt==0 ); in debugMutexFree()
29359 # define SQLITE_MUTEX_NREF 0
29378 {PTHREAD_MUTEX_INITIALIZER,id,0,(pthread_t)0,0}
29403 return (p->nRef!=0 && pthread_equal(p->owner, pthread_self())); in pthreadMutexHeld()
29406 return p->nRef==0 || pthread_equal(p->owner, pthread_self())==0; in pthreadMutexNotheld()
29500 pthread_mutex_init(&p->mutex, 0); in pthreadMutexAlloc()
29518 pthread_mutex_init(&p->mutex, 0); in pthreadMutexAlloc()
29527 if( iType-2<0 || iType-2>=ArraySize(staticMutexes) ){ in pthreadMutexAlloc()
29529 return 0; in pthreadMutexAlloc()
29537 assert( p==0 || p->id==iType ); in pthreadMutexAlloc()
29549 assert( p->nRef==0 ); in pthreadMutexFree()
29591 if( p->nRef>0 && pthread_equal(p->owner, self) ){ in pthreadMutexEnter()
29595 assert( p->nRef==0 ); in pthreadMutexEnter()
29605 assert( p->nRef>0 || p->owner==0 ); in pthreadMutexEnter()
29634 if( p->nRef>0 && pthread_equal(p->owner, self) ){ in pthreadMutexTry()
29637 }else if( pthread_mutex_trylock(&p->mutex)==0 ){ in pthreadMutexTry()
29638 assert( p->nRef==0 ); in pthreadMutexTry()
29649 if( pthread_mutex_trylock(&p->mutex)==0 ){ in pthreadMutexTry()
29678 if( p->nRef==0 ) p->owner = 0; in pthreadMutexLeave()
29680 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE ); in pthreadMutexLeave()
29683 if( p->nRef==0 ){ in pthreadMutexLeave()
29710 0, in sqlite3DefaultMutex()
29711 0 in sqlite3DefaultMutex()
29784 ** # define SQLITE_OS_WINNT 0
29790 ** by setting SQLITE_OS_WINNT to 0.
29803 # define SQLITE_OS_WINCE 0
29811 # define SQLITE_OS_WINRT 0
29829 SQLITE_THREADSAFE>0 && !defined(__CYGWIN__)
29832 # define SQLITE_OS_WIN_THREADS 0
29865 #define SQLITE_W32_MUTEX_INITIALIZER { 0 }
29869 0L, (DWORD)0, 0 }
29880 return p->nRef!=0 && p->owner==GetCurrentThreadId(); in winMutexHeld()
29884 return p->nRef==0 || p->owner!=tid; in winMutexNotheld2()
29896 ** compiled without mutexes (SQLITE_THREADSAFE=0).
29928 static int winMutex_isInit = 0;
29929 static int winMutex_isNt = -1; /* <0 means "need to query" */
29935 static LONG SQLITE_WIN32_VOLATILE winMutex_lock = 0;
29942 if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){ in winMutexInit()
29944 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){ in winMutexInit()
29946 InitializeCriticalSectionEx(&winMutex_staticMutexes[i].mutex, 0, 0); in winMutexInit()
29963 /* The first to decrement to 0 does actual shutdown in winMutexEnd()
29965 if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){ in winMutexEnd()
29968 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){ in winMutexEnd()
29971 winMutex_isInit = 0; in winMutexEnd()
30040 InitializeCriticalSectionEx(&p->mutex, 0, 0); in winMutexAlloc()
30049 if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){ in winMutexAlloc()
30051 return 0; in winMutexAlloc()
30057 InterlockedCompareExchange(&p->trace, 1, 0); in winMutexAlloc()
30063 assert( p==0 || p->id==iType ); in winMutexAlloc()
30075 assert( p->nRef==0 && p->owner==0 ); in winMutexFree()
30110 assert( p->nRef>0 || p->owner==0 ); in winMutexEnter()
30138 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400 in winMutexTry()
30141 if( winMutex_isNt<0 ){ in winMutexTry()
30144 assert( winMutex_isNt==0 || winMutex_isNt==1 ); in winMutexTry()
30176 assert( p->nRef>0 ); in winMutexLeave()
30179 if( p->nRef==0 ) p->owner = 0; in winMutexLeave()
30180 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE ); in winMutexLeave()
30205 0, in sqlite3DefaultMutex()
30206 0 in sqlite3DefaultMutex()
30246 return 0; in sqlite3_release_memory()
30251 ** Default value of the hard heap limit. 0 means "no limit".
30254 # define SQLITE_MAX_MEMORY 0
30270 } mem0 = { 0, SQLITE_MAX_MEMORY, SQLITE_MAX_MEMORY, 0 };
30320 if( n<0 ){ in sqlite3_soft_heap_limit64()
30324 if( mem0.hardLimit>0 && (n>mem0.hardLimit || n==0) ){ in sqlite3_soft_heap_limit64()
30329 AtomicStore(&mem0.nearlyFull, n>0 && n<=nUsed); in sqlite3_soft_heap_limit64()
30332 if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff)); in sqlite3_soft_heap_limit64()
30336 if( n<0 ) n = 0; in sqlite3_soft_heap_limit()
30360 if( n>=0 ){ in sqlite3_hard_heap_limit64()
30362 if( n<mem0.alarmThreshold || mem0.alarmThreshold==0 ){ in sqlite3_hard_heap_limit64()
30376 if( sqlite3GlobalConfig.m.xMalloc==0 ){ in sqlite3MallocInit()
30380 if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512 in sqlite3MallocInit()
30381 || sqlite3GlobalConfig.nPage<=0 ){ in sqlite3MallocInit()
30382 sqlite3GlobalConfig.pPage = 0; in sqlite3MallocInit()
30383 sqlite3GlobalConfig.szPage = 0; in sqlite3MallocInit()
30386 if( rc!=SQLITE_OK ) memset(&mem0, 0, sizeof(mem0)); in sqlite3MallocInit()
30406 memset(&mem0, 0, sizeof(mem0)); in sqlite3MallocEnd()
30414 sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, 0); in sqlite3_memory_used()
30433 if( mem0.alarmThreshold<=0 ) return; in sqlite3MallocAlarm()
30447 static u64 nOomFault = 0; in test_oom_breakpoint()
30451 assert( (nOomFault>>32) < 0xffffffff ); in test_oom_breakpoint()
30465 assert( n>0 ); in mallocWithAlarm()
30475 if( mem0.alarmThreshold>0 ){ in mallocWithAlarm()
30484 *pp = 0; in mallocWithAlarm()
30489 AtomicStore(&mem0.nearlyFull, 0); in mallocWithAlarm()
30494 if( p==0 && mem0.alarmThreshold>0 ){ in mallocWithAlarm()
30513 ** The upper bound is slightly less than 2GiB: 0x7ffffeff == 2,147,483,391
30517 ** further for an even larger safety margin. 0x3fffffff or 0x0fffffff
30534 if( n==0 || n>SQLITE_MAX_ALLOCATION_SIZE ){ in sqlite3Malloc()
30535 p = 0; in sqlite3Malloc()
30554 if( sqlite3_initialize() ) return 0; in sqlite3_malloc()
30556 return n<=0 ? 0 : sqlite3Malloc(n); in sqlite3_malloc()
30560 if( sqlite3_initialize() ) return 0; in sqlite3_malloc64()
30573 #define isLookaside(A,B) 0
30592 assert( p!=0 ); in sqlite3DbMallocSize()
30594 if( db==0 ){ in sqlite3DbMallocSize()
30621 return p ? sqlite3GlobalConfig.m.xSize(p) : 0; in sqlite3_msize()
30628 if( p==0 ) return; /* IMP: R-49053-54554 */ in sqlite3_free()
30652 ** connection. Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
30656 assert( db==0 || sqlite3_mutex_held(db->mutex) ); in sqlite3DbFreeNN()
30657 assert( p!=0 ); in sqlite3DbFreeNN()
30663 assert( db->pnBytesFreed==0 ); in sqlite3DbFreeNN()
30665 memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */ in sqlite3DbFreeNN()
30674 assert( db->pnBytesFreed==0 ); in sqlite3DbFreeNN()
30676 memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */ in sqlite3DbFreeNN()
30690 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); in sqlite3DbFreeNN()
30695 assert( db!=0 ); in sqlite3DbNNFreeNN()
30697 assert( p!=0 ); in sqlite3DbNNFreeNN()
30702 assert( db->pnBytesFreed==0 ); in sqlite3DbNNFreeNN()
30704 memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */ in sqlite3DbNNFreeNN()
30713 assert( db->pnBytesFreed==0 ); in sqlite3DbNNFreeNN()
30715 memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */ in sqlite3DbNNFreeNN()
30732 assert( db==0 || sqlite3_mutex_held(db->mutex) ); in sqlite3DbFree()
30744 if( pOld==0 ){ in sqlite3Realloc()
30747 if( nBytes==0 ){ in sqlite3Realloc()
30749 return 0; in sqlite3Realloc()
30751 if( nBytes>=0x7fffff00 ){ in sqlite3Realloc()
30752 /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */ in sqlite3Realloc()
30753 return 0; in sqlite3Realloc()
30767 if( nDiff>0 && (nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)) >= in sqlite3Realloc()
30770 if( mem0.hardLimit>0 && nUsed >= mem0.hardLimit - nDiff ){ in sqlite3Realloc()
30773 return 0; in sqlite3Realloc()
30778 if( pNew==0 && mem0.alarmThreshold>0 ){ in sqlite3Realloc()
30801 if( sqlite3_initialize() ) return 0; in sqlite3_realloc()
30803 if( n<0 ) n = 0; /* IMP: R-26507-47431 */ in sqlite3_realloc()
30808 if( sqlite3_initialize() ) return 0; in sqlite3_realloc64()
30820 memset(p, 0, (size_t)n); in sqlite3MallocZero()
30831 testcase( db==0 ); in sqlite3DbMallocZero()
30833 if( p ) memset(p, 0, (size_t)n); in sqlite3DbMallocZero()
30843 assert( db!=0 ); in dbMallocRawFinish()
30847 (db->lookaside.bDisable==0) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP); in dbMallocRawFinish()
30856 ** If db!=0 and db->mallocFailed is true (indicating a prior malloc
30857 ** failure on the same database connection) then always return 0.
30883 assert( db!=0 ); in sqlite3DbMallocRawNN()
30885 assert( db->pnBytesFreed==0 ); in sqlite3DbMallocRawNN()
30890 return 0; in sqlite3DbMallocRawNN()
30896 if( (pBuf = db->lookaside.pSmallFree)!=0 ){ in sqlite3DbMallocRawNN()
30898 db->lookaside.anStat[0]++; in sqlite3DbMallocRawNN()
30900 }else if( (pBuf = db->lookaside.pSmallInit)!=0 ){ in sqlite3DbMallocRawNN()
30902 db->lookaside.anStat[0]++; in sqlite3DbMallocRawNN()
30907 if( (pBuf = db->lookaside.pFree)!=0 ){ in sqlite3DbMallocRawNN()
30909 db->lookaside.anStat[0]++; in sqlite3DbMallocRawNN()
30911 }else if( (pBuf = db->lookaside.pInit)!=0 ){ in sqlite3DbMallocRawNN()
30913 db->lookaside.anStat[0]++; in sqlite3DbMallocRawNN()
30919 assert( db!=0 ); in sqlite3DbMallocRawNN()
30921 assert( db->pnBytesFreed==0 ); in sqlite3DbMallocRawNN()
30923 return 0; in sqlite3DbMallocRawNN()
30937 assert( db!=0 ); in sqlite3DbRealloc()
30938 if( p==0 ) return sqlite3DbMallocRawNN(db, n); in sqlite3DbRealloc()
30953 void *pNew = 0; in dbReallocFinish()
30954 assert( db!=0 ); in dbReallocFinish()
30955 assert( p!=0 ); in dbReallocFinish()
30956 if( db->mallocFailed==0 ){ in dbReallocFinish()
30972 (db->lookaside.bDisable==0 ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP)); in dbReallocFinish()
31001 if( z==0 ){ in sqlite3DbStrDup()
31002 return 0; in sqlite3DbStrDup()
31013 assert( db!=0 ); in sqlite3DbStrNDup()
31014 assert( z!=0 || n==0 ); in sqlite3DbStrNDup()
31015 assert( (n&0x7fffffff)==n ); in sqlite3DbStrNDup()
31016 zNew = z ? sqlite3DbMallocRawNN(db, n+1) : 0; in sqlite3DbStrNDup()
31019 zNew[n] = 0; in sqlite3DbStrNDup()
31034 for(n=0; sqlite3Isspace(zStart[n]); n++){ assert( &zStart[n]<zEnd ); } in sqlite3DbSpanDup()
31036 while( sqlite3Isspace(zStart[0]) ) zStart++; in sqlite3DbSpanDup()
31065 if( db->mallocFailed==0 && db->bBenignMalloc==0 ){ in sqlite3OomFault()
31067 if( db->nVdbeExec>0 ){ in sqlite3OomFault()
31081 return 0; in sqlite3OomFault()
31092 if( db->mallocFailed && db->nVdbeExec==0 ){ in sqlite3OomClear()
31093 db->mallocFailed = 0; in sqlite3OomClear()
31094 AtomicStore(&db->u1.isInterrupted, 0); in sqlite3OomClear()
31095 assert( db->lookaside.bDisable>0 ); in sqlite3OomClear()
31129 assert( db!=0 ); in sqlite3ApiExit()
31134 return 0; in sqlite3ApiExit()
31156 #define etRADIX 0 /* non-decimal integer types. %x %o */
31211 { 'd', 10, 1, etDECIMAL, 0, 0 },
31212 { 's', 0, 4, etSTRING, 0, 0 },
31213 { 'g', 0, 1, etGENERIC, 30, 0 },
31214 { 'z', 0, 4, etDYNSTRING, 0, 0 },
31215 { 'q', 0, 4, etSQLESCAPE, 0, 0 },
31216 { 'Q', 0, 4, etSQLESCAPE2, 0, 0 },
31217 { 'w', 0, 4, etSQLESCAPE3, 0, 0 },
31218 { 'c', 0, 0, etCHARX, 0, 0 },
31219 { 'o', 8, 0, etRADIX, 0, 2 },
31220 { 'u', 10, 0, etDECIMAL, 0, 0 },
31221 { 'x', 16, 0, etRADIX, 16, 1 },
31222 { 'X', 16, 0, etRADIX, 0, 4 },
31224 { 'f', 0, 1, etFLOAT, 0, 0 },
31225 { 'e', 0, 1, etEXP, 30, 0 },
31226 { 'E', 0, 1, etEXP, 14, 0 },
31227 { 'G', 0, 1, etGENERIC, 14, 0 },
31229 { 'i', 10, 1, etDECIMAL, 0, 0 },
31230 { 'n', 0, 0, etSIZE, 0, 0 },
31231 { '%', 0, 0, etPERCENT, 0, 0 },
31232 { 'p', 16, 0, etPOINTER, 0, 1 },
31235 { 'T', 0, 0, etTOKEN, 0, 0 },
31236 { 'S', 0, 0, etSRCITEM, 0, 0 },
31237 { 'r', 10, 1, etORDINAL, 0, 0 },
31260 if( p->nArg<=p->nUsed ) return 0; in getIntArg()
31268 if( p->nArg<=p->nUsed ) return 0; in getTextArg()
31283 if( pAccum->accError ) return 0; in printfTempBuf()
31286 return 0; in printfTempBuf()
31289 if( z==0 ){ in printfTempBuf()
31326 etByte flag_prefix; /* '+' or ' ' or 0 for prefix */ in sqlite3_str_vappendf()
31330 etByte flag_long; /* 1 for the "l" flag, 2 for "ll", 0 by default */ in sqlite3_str_vappendf()
31335 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ in sqlite3_str_vappendf()
31341 char *zExtra = 0; /* Malloced memory used by some conversion */ in sqlite3_str_vappendf()
31346 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ in sqlite3_str_vappendf()
31352 assert( pAccum->nChar>0 || (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 ); in sqlite3_str_vappendf()
31354 bufpt = 0; in sqlite3_str_vappendf()
31355 if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){ in sqlite3_str_vappendf()
31359 bArgList = 0; in sqlite3_str_vappendf()
31361 for(; (c=(*fmt))!=0; ++fmt){ in sqlite3_str_vappendf()
31370 if( *fmt==0 ) break; in sqlite3_str_vappendf()
31372 if( (c=(*++fmt))==0 ){ in sqlite3_str_vappendf()
31378 flag_alternateform = flag_altform2 = flag_zeropad = 0; in sqlite3_str_vappendf()
31379 done = 0; in sqlite3_str_vappendf()
31380 width = 0; in sqlite3_str_vappendf()
31381 flag_long = 0; in sqlite3_str_vappendf()
31390 case '0': flag_zeropad = 1; break; in sqlite3_str_vappendf()
31405 unsigned wx = c - '0'; in sqlite3_str_vappendf()
31406 while( (c = *++fmt)>='0' && c<='9' ){ in sqlite3_str_vappendf()
31407 wx = wx*10 + c - '0'; in sqlite3_str_vappendf()
31409 testcase( wx>0x7fffffff ); in sqlite3_str_vappendf()
31410 width = wx & 0x7fffffff; in sqlite3_str_vappendf()
31429 if( width<0 ){ in sqlite3_str_vappendf()
31431 width = width >= -2147483647 ? -width : 0; in sqlite3_str_vappendf()
31452 if( precision<0 ){ in sqlite3_str_vappendf()
31457 unsigned px = 0; in sqlite3_str_vappendf()
31458 while( c>='0' && c<='9' ){ in sqlite3_str_vappendf()
31459 px = px*10 + c - '0'; in sqlite3_str_vappendf()
31462 testcase( px>0x7fffffff ); in sqlite3_str_vappendf()
31463 precision = px & 0x7fffffff; in sqlite3_str_vappendf()
31478 }while( !done && (c=(*++fmt))!=0 ); in sqlite3_str_vappendf()
31481 infop = &fmtinfo[0]; in sqlite3_str_vappendf()
31483 for(idx=0; idx<ArraySize(fmtinfo); idx++){ in sqlite3_str_vappendf()
31499 ** flag_zeropad TRUE if the width began with 0. in sqlite3_str_vappendf()
31508 assert( width>=0 ); in sqlite3_str_vappendf()
31513 sizeof(char*)==sizeof(long int) ? 1 : 0; in sqlite3_str_vappendf()
31517 cThousand = 0; in sqlite3_str_vappendf()
31533 if( v<0 ){ in sqlite3_str_vappendf()
31555 prefix = 0; in sqlite3_str_vappendf()
31557 if( longvalue==0 ) flag_alternateform = 0; in sqlite3_str_vappendf()
31558 if( flag_zeropad && precision<width-(prefix!=0) ){ in sqlite3_str_vappendf()
31559 precision = width-(prefix!=0); in sqlite3_str_vappendf()
31569 if( zOut==0 ) return; in sqlite3_str_vappendf()
31577 x = 0; in sqlite3_str_vappendf()
31588 }while( longvalue>0 ); in sqlite3_str_vappendf()
31592 *(--bufpt) = '0'; /* Zero pad */ in sqlite3_str_vappendf()
31599 for(idx=0; nn>0; idx++){ in sqlite3_str_vappendf()
31602 if( ix==0 ){ in sqlite3_str_vappendf()
31610 if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */ in sqlite3_str_vappendf()
31614 for(; (x=(*pre))!=0; pre++) *(--bufpt) = x; in sqlite3_str_vappendf()
31630 if( precision<0 ) precision = 6; /* Set default precision */ in sqlite3_str_vappendf()
31639 if( precision==0 ) precision = 1; in sqlite3_str_vappendf()
31651 s.z[0] = '9'; in sqlite3_str_vappendf()
31660 buf[0] = flag_prefix; in sqlite3_str_vappendf()
31681 assert( precision>0 ); in sqlite3_str_vappendf()
31694 e2 = 0; in sqlite3_str_vappendf()
31701 szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15; in sqlite3_str_vappendf()
31702 if( cThousand && e2>0 ) szBufNeeded += (e2+2)/3; in sqlite3_str_vappendf()
31705 if( bufpt==0 ) return; in sqlite3_str_vappendf()
31709 flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2; in sqlite3_str_vappendf()
31715 j = 0; in sqlite3_str_vappendf()
31716 if( e2<0 ){ in sqlite3_str_vappendf()
31717 *(bufpt++) = '0'; in sqlite3_str_vappendf()
31719 for(; e2>=0; e2--){ in sqlite3_str_vappendf()
31720 *(bufpt++) = j<s.n ? s.z[j++] : '0'; in sqlite3_str_vappendf()
31721 if( cThousand && (e2%3)==0 && e2>1 ) *(bufpt++) = ','; in sqlite3_str_vappendf()
31728 /* "0" digits after the decimal point but before the first in sqlite3_str_vappendf()
31730 for(e2++; e2<0 && precision>0; precision--, e2++){ in sqlite3_str_vappendf()
31731 *(bufpt++) = '0'; in sqlite3_str_vappendf()
31734 while( (precision--)>0 ){ in sqlite3_str_vappendf()
31735 *(bufpt++) = j<s.n ? s.z[j++] : '0'; in sqlite3_str_vappendf()
31739 while( bufpt[-1]=='0' ) *(--bufpt) = 0; in sqlite3_str_vappendf()
31743 *(bufpt++) = '0'; in sqlite3_str_vappendf()
31745 *(--bufpt) = 0; in sqlite3_str_vappendf()
31753 if( exp<0 ){ in sqlite3_str_vappendf()
31759 *(bufpt++) = (char)((exp/100)+'0'); /* 100's digit */ in sqlite3_str_vappendf()
31762 *(bufpt++) = (char)(exp/10+'0'); /* 10's digit */ in sqlite3_str_vappendf()
31763 *(bufpt++) = (char)(exp%10+'0'); /* 1's digit */ in sqlite3_str_vappendf()
31765 *bufpt = 0; in sqlite3_str_vappendf()
31781 i = prefix!=0; in sqlite3_str_vappendf()
31782 while( nPad-- ) bufpt[i++] = '0'; in sqlite3_str_vappendf()
31791 length = width = 0; in sqlite3_str_vappendf()
31794 buf[0] = '%'; in sqlite3_str_vappendf()
31803 buf[0] = c = *(bufpt++); in sqlite3_str_vappendf()
31804 if( (c&0xc0)==0xc0 ){ in sqlite3_str_vappendf()
31805 while( length<4 && (bufpt[0]&0xc0)==0x80 ){ in sqlite3_str_vappendf()
31810 buf[0] = 0; in sqlite3_str_vappendf()
31814 if( ch<0x00080 ){ in sqlite3_str_vappendf()
31815 buf[0] = ch & 0xff; in sqlite3_str_vappendf()
31817 }else if( ch<0x00800 ){ in sqlite3_str_vappendf()
31818 buf[0] = 0xc0 + (u8)((ch>>6)&0x1f); in sqlite3_str_vappendf()
31819 buf[1] = 0x80 + (u8)(ch & 0x3f); in sqlite3_str_vappendf()
31821 }else if( ch<0x10000 ){ in sqlite3_str_vappendf()
31822 buf[0] = 0xe0 + (u8)((ch>>12)&0x0f); in sqlite3_str_vappendf()
31823 buf[1] = 0x80 + (u8)((ch>>6) & 0x3f); in sqlite3_str_vappendf()
31824 buf[2] = 0x80 + (u8)(ch & 0x3f); in sqlite3_str_vappendf()
31827 buf[0] = 0xf0 + (u8)((ch>>18) & 0x07); in sqlite3_str_vappendf()
31828 buf[1] = 0x80 + (u8)((ch>>12) & 0x3f); in sqlite3_str_vappendf()
31829 buf[2] = 0x80 + (u8)((ch>>6) & 0x3f); in sqlite3_str_vappendf()
31830 buf[3] = 0x80 + (u8)(ch & 0x3f); in sqlite3_str_vappendf()
31839 width = 0; in sqlite3_str_vappendf()
31868 if( bufpt==0 ){ in sqlite3_str_vappendf()
31871 if( pAccum->nChar==0 in sqlite3_str_vappendf()
31873 && width==0 in sqlite3_str_vappendf()
31874 && precision<0 in sqlite3_str_vappendf()
31875 && pAccum->accError==0 in sqlite3_str_vappendf()
31880 assert( (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 ); in sqlite3_str_vappendf()
31883 pAccum->nChar = 0x7fffffff & (int)strlen(bufpt); in sqlite3_str_vappendf()
31885 length = 0; in sqlite3_str_vappendf()
31890 if( precision>=0 ){ in sqlite3_str_vappendf()
31895 while( precision-- > 0 && z[0] ){ in sqlite3_str_vappendf()
31900 for(length=0; length<precision && bufpt[length]; length++){} in sqlite3_str_vappendf()
31903 length = 0x7fffffff & (int)strlen(bufpt); in sqlite3_str_vappendf()
31906 if( flag_altform2 && width>0 ){ in sqlite3_str_vappendf()
31909 while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++; in sqlite3_str_vappendf()
31926 isnull = escarg==0; in sqlite3_str_vappendf()
31934 for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){ in sqlite3_str_vappendf()
31936 if( flag_altform2 && (ch&0xc0)==0xc0 ){ in sqlite3_str_vappendf()
31937 while( (escarg[i+1]&0xc0)==0x80 ){ i++; } in sqlite3_str_vappendf()
31944 if( bufpt==0 ) return; in sqlite3_str_vappendf()
31948 j = 0; in sqlite3_str_vappendf()
31951 for(i=0; i<k; i++){ in sqlite3_str_vappendf()
31956 bufpt[j] = 0; in sqlite3_str_vappendf()
31961 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; in sqlite3_str_vappendf()
31972 assert( bArgList==0 ); in sqlite3_str_vappendf()
31978 length = width = 0; in sqlite3_str_vappendf()
31983 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; in sqlite3_str_vappendf()
31985 assert( bArgList==0 ); in sqlite3_str_vappendf()
31998 assert( pSel!=0 ); /* Because of tag-20240424-1 */ in sqlite3_str_vappendf()
32009 length = width = 0; in sqlite3_str_vappendf()
32026 if( width>0 ){ in sqlite3_str_vappendf()
32036 zExtra = 0; in sqlite3_str_vappendf()
32052 assert( z!=0 ); in sqlite3RecordErrorByteOffset()
32053 if( NEVER(db==0) ) return; in sqlite3RecordErrorByteOffset()
32056 if( NEVER(pParse==0) ) return; in sqlite3RecordErrorByteOffset()
32058 if( NEVER(zText==0) ) return; in sqlite3RecordErrorByteOffset()
32071 && (ExprHasProperty(pExpr,EP_OuterON|EP_InnerON) || pExpr->w.iOfst<=0) in sqlite3RecordErrorOffsetOfExpr()
32075 if( pExpr==0 ) return; in sqlite3RecordErrorOffsetOfExpr()
32092 return 0; in sqlite3StrAccumEnlarge()
32094 if( p->mxAlloc==0 ){ in sqlite3StrAccumEnlarge()
32098 char *zOld = isMalloced(p) ? p->zText : 0; in sqlite3StrAccumEnlarge()
32108 return 0; in sqlite3StrAccumEnlarge()
32118 assert( p->zText!=0 || p->nChar==0 ); in sqlite3StrAccumEnlarge()
32119 if( !isMalloced(p) && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); in sqlite3StrAccumEnlarge()
32126 return 0; in sqlite3StrAccumEnlarge()
32129 assert( N>=0 && N<=0x7fffffff ); in sqlite3StrAccumEnlarge()
32137 testcase( p->nChar + (i64)N > 0x7fffffff ); in sqlite3_str_appendchar()
32138 if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){ in sqlite3_str_appendchar()
32141 while( (N--)>0 ) p->zText[p->nChar++] = c; in sqlite3_str_appendchar()
32154 if( N>0 ){ in enlargeAndAppend()
32165 assert( z!=0 || N==0 ); in sqlite3_str_append()
32166 assert( p->zText!=0 || p->nChar==0 || p->accError ); in sqlite3_str_append()
32167 assert( N>=0 ); in sqlite3_str_append()
32168 assert( p->accError==0 || p->nAlloc==0 || p->mxAlloc==0 ); in sqlite3_str_append()
32193 assert( p->mxAlloc>0 && !isMalloced(p) ); in strAccumFinishRealloc()
32206 p->zText[p->nChar] = 0; in sqlite3StrAccumFinish()
32207 if( p->mxAlloc>0 && !isMalloced(p) ){ in sqlite3StrAccumFinish()
32225 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC); in sqlite3ResultStrAccum()
32237 0, 0, 0, 0, 0, SQLITE_NOMEM, 0
32244 if( p!=0 && p!=&sqlite3OomStr ){ in sqlite3_str_finish()
32248 z = 0; in sqlite3_str_finish()
32260 return p ? p->nChar : 0; in sqlite3_str_length()
32265 if( p==0 || p->nChar==0 ) return 0; in sqlite3_str_value()
32266 p->zText[p->nChar] = 0; in sqlite3_str_value()
32278 p->nAlloc = 0; in sqlite3_str_reset()
32279 p->nChar = 0; in sqlite3_str_reset()
32280 p->zText = 0; in sqlite3_str_reset()
32294 ** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
32302 p->nChar = 0; in sqlite3StrAccumInit()
32303 p->accError = 0; in sqlite3StrAccumInit()
32304 p->printfFlags = 0; in sqlite3StrAccumInit()
32311 sqlite3StrAccumInit(p, 0, 0, 0, in sqlite3_str_new()
32327 assert( db!=0 ); in sqlite3VMPrintf()
32362 if( zFormat==0 ){ in sqlite3_vmprintf()
32364 return 0; in sqlite3_vmprintf()
32368 if( sqlite3_initialize() ) return 0; in sqlite3_vmprintf()
32370 sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); in sqlite3_vmprintf()
32384 if( sqlite3_initialize() ) return 0; in sqlite3_mprintf()
32407 if( n<=0 ) return zBuf; in sqlite3_vsnprintf()
32409 if( zBuf==0 || zFormat==0 ) { in sqlite3_vsnprintf()
32411 if( zBuf ) zBuf[0] = 0; in sqlite3_vsnprintf()
32415 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); in sqlite3_vsnprintf()
32417 zBuf[acc.nChar] = 0; in sqlite3_vsnprintf()
32423 if( n<=0 ) return zBuf; in sqlite3_snprintf()
32425 if( zBuf==0 || zFormat==0 ) { in sqlite3_snprintf()
32427 if( zBuf ) zBuf[0] = 0; in sqlite3_snprintf()
32431 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); in sqlite3_snprintf()
32435 zBuf[acc.nChar] = 0; in sqlite3_snprintf()
32457 sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0); in renderLogMsg()
32485 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); in sqlite3DebugPrintf()
32526 assert( p!=0 ); in sqlite3RCStrRef()
32538 assert( p!=0 ); in sqlite3RCStrUnref()
32540 assert( p->nRCRef>0 ); in sqlite3RCStrUnref()
32555 ** This routine returns 0 on an OOM.
32559 if( p==0 ) return 0; in sqlite3RCStrNew()
32571 assert( p!=0 ); in sqlite3RCStrResize()
32575 if( pNew==0 ){ in sqlite3RCStrResize()
32577 return 0; in sqlite3RCStrResize()
32613 if( p==0 ){ in sqlite3TreeViewPush()
32615 if( p==0 ) return; in sqlite3TreeViewPush()
32616 memset(p, 0, sizeof(*p)); in sqlite3TreeViewPush()
32620 assert( moreToFollow==0 || moreToFollow==1 ); in sqlite3TreeViewPush()
32629 if( p==0 ) return; in sqlite3TreeViewPop()
32631 if( p->iLevel<0 ){ in sqlite3TreeViewPop()
32633 *pp = 0; in sqlite3TreeViewPop()
32646 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); in sqlite3TreeViewLine()
32648 for(i=0; i<p->iLevel && i<(int)sizeof(p->bLine)-1; i++){ in sqlite3TreeViewLine()
32653 if( zFormat!=0 ){ in sqlite3TreeViewLine()
32657 assert( acc.nChar>0 || acc.accError ); in sqlite3TreeViewLine()
32685 for(i=0; i<nCol; i++){ in sqlite3TreeViewColumnList()
32689 sqlite3TreeViewLine(pView, 0); in sqlite3TreeViewColumnList()
32725 if( pWith==0 ) return; in sqlite3TreeViewWith()
32726 if( pWith->nCte==0 ) return; in sqlite3TreeViewWith()
32728 sqlite3TreeViewLine(pView, "WITH (0x%p, pOuter=0x%p)",pWith,pWith->pOuter); in sqlite3TreeViewWith()
32730 sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith); in sqlite3TreeViewWith()
32732 if( pWith->nCte>0 ){ in sqlite3TreeViewWith()
32734 for(i=0; i<pWith->nCte; i++){ in sqlite3TreeViewWith()
32738 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); in sqlite3TreeViewWith()
32740 if( pCte->pCols && pCte->pCols->nExpr>0 ){ in sqlite3TreeViewWith()
32743 for(j=0; j<pCte->pCols->nExpr; j++){ in sqlite3TreeViewWith()
32754 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse, in sqlite3TreeViewWith()
32759 sqlite3TreeViewSelect(pView, pCte->pSelect, 0); in sqlite3TreeViewWith()
32771 if( pSrc==0 ) return; in sqlite3TreeViewSrcList()
32772 for(i=0; i<pSrc->nSrc; i++){ in sqlite3TreeViewSrcList()
32775 int n = 0; in sqlite3TreeViewSrcList()
32777 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); in sqlite3TreeViewSrcList()
32802 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse); in sqlite3TreeViewSrcList()
32804 if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){ in sqlite3TreeViewSrcList()
32816 n = 0; in sqlite3TreeViewSrcList()
32821 sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING"); in sqlite3TreeViewSrcList()
32830 sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0); in sqlite3TreeViewSrcList()
32834 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); in sqlite3TreeViewSrcList()
32844 int n = 0; in sqlite3TreeViewSelect()
32845 int cnt = 0; in sqlite3TreeViewSelect()
32846 if( p==0 ){ in sqlite3TreeViewSelect()
32861 "SELECT%s%s (%u/%p) selFlags=0x%x nSelectRow=%d", in sqlite3TreeViewSelect()
32872 n = 0; in sqlite3TreeViewSelect()
32885 sqlite3TreeViewExprList(pView, p->pEList, n>0, "result-set"); in sqlite3TreeViewSelect()
32891 sqlite3TreeViewPush(&pView, (n--)>0); in sqlite3TreeViewSelect()
32894 sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0); in sqlite3TreeViewSelect()
32900 sqlite3TreeViewPush(&pView, (n--)>0); in sqlite3TreeViewSelect()
32906 sqlite3TreeViewItem(pView, "WHERE", (n--)>0); in sqlite3TreeViewSelect()
32907 sqlite3TreeViewExpr(pView, p->pWhere, 0); in sqlite3TreeViewSelect()
32911 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY"); in sqlite3TreeViewSelect()
32914 sqlite3TreeViewItem(pView, "HAVING", (n--)>0); in sqlite3TreeViewSelect()
32915 sqlite3TreeViewExpr(pView, p->pHaving, 0); in sqlite3TreeViewSelect()
32921 sqlite3TreeViewItem(pView, "WINDOW", (n--)>0); in sqlite3TreeViewSelect()
32923 sqlite3TreeViewWindow(pView, pX, pX->pNextWin!=0); in sqlite3TreeViewSelect()
32929 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY"); in sqlite3TreeViewSelect()
32932 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0); in sqlite3TreeViewSelect()
32933 sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0); in sqlite3TreeViewSelect()
32935 sqlite3TreeViewItem(pView, "OFFSET", 0); in sqlite3TreeViewSelect()
32936 sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0); in sqlite3TreeViewSelect()
32951 }while( p!=0 ); in sqlite3TreeViewSelect()
32978 sqlite3TreeViewExpr(pView, pExpr, 0); in sqlite3TreeViewBound()
32984 sqlite3TreeViewExpr(pView, pExpr, 0); in sqlite3TreeViewBound()
32997 int nElement = 0; in sqlite3TreeViewWindow()
32998 if( pWin==0 ) return; in sqlite3TreeViewWindow()
33001 sqlite3TreeViewExpr(pView, pWin->pFilter, 0); in sqlite3TreeViewWindow()
33013 if( pWin->eFrmType!=0 && pWin->eFrmType!=TK_FILTER ) nElement++; in sqlite3TreeViewWindow()
33016 sqlite3TreeViewPush(&pView, (--nElement)>0); in sqlite3TreeViewWindow()
33021 sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY"); in sqlite3TreeViewWindow()
33024 sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY"); in sqlite3TreeViewWindow()
33026 if( pWin->eFrmType!=0 && pWin->eFrmType!=TK_FILTER ){ in sqlite3TreeViewWindow()
33033 sqlite3TreeViewItem(pView, zBuf, (--nElement)>0); in sqlite3TreeViewWindow()
33035 sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0); in sqlite3TreeViewWindow()
33051 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewWindow()
33064 if( pWin==0 ) return; in sqlite3TreeViewWinFunc()
33068 sqlite3TreeViewWindow(pView, pWin, 0); in sqlite3TreeViewWinFunc()
33077 const char *zBinOp = 0; /* Binary operator */ in sqlite3TreeViewExpr()
33078 const char *zUniOp = 0; /* Unary operator */ in sqlite3TreeViewExpr()
33081 if( pExpr==0 ){ in sqlite3TreeViewExpr()
33088 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); in sqlite3TreeViewExpr()
33103 if( pExpr->pAggInfo!=0 ){ in sqlite3TreeViewExpr()
33108 zFlgs[0] = 0; in sqlite3TreeViewExpr()
33117 if( pExpr->iTable<0 ){ in sqlite3TreeViewExpr()
33121 sqlite3_snprintf(sizeof(zOp2),zOp2," op2=0x%02x",pExpr->op2); in sqlite3TreeViewExpr()
33123 zOp2[0] = 0; in sqlite3TreeViewExpr()
33134 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33194 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33245 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33259 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33268 pFarg = 0; in sqlite3TreeViewExpr()
33269 pWin = 0; in sqlite3TreeViewExpr()
33274 pWin = IsWindowFunc(pExpr) ? pExpr->y.pWin : 0; in sqlite3TreeViewExpr()
33276 pWin = 0; in sqlite3TreeViewExpr()
33283 pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0, in sqlite3TreeViewExpr()
33285 }else if( pExpr->op2!=0 ){ in sqlite3TreeViewExpr()
33288 sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2); in sqlite3TreeViewExpr()
33300 sqlite3TreeViewExprList(pView, pFarg, pWin!=0 || pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33305 sqlite3TreeViewExprList(pView, pOB->x.pList, pWin!=0, "ORDERBY"); in sqlite3TreeViewExpr()
33310 sqlite3TreeViewWindow(pView, pWin, 0); in sqlite3TreeViewExpr()
33316 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, "ORDERBY"); in sqlite3TreeViewExpr()
33322 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags); in sqlite3TreeViewExpr()
33323 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); in sqlite3TreeViewExpr()
33328 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags); in sqlite3TreeViewExpr()
33329 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); in sqlite3TreeViewExpr()
33333 sqlite3_str *pStr = sqlite3_str_new(0); in sqlite3TreeViewExpr()
33335 sqlite3_str_appendf(pStr, "IN flags=0x%x", pExpr->flags); in sqlite3TreeViewExpr()
33346 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); in sqlite3TreeViewExpr()
33348 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); in sqlite3TreeViewExpr()
33362 ** Y is stored in pExpr->pList->a[0].pExpr. in sqlite3TreeViewExpr()
33370 pY = pExpr->x.pList->a[0].pExpr; in sqlite3TreeViewExpr()
33375 sqlite3TreeViewExpr(pView, pZ, 0); in sqlite3TreeViewExpr()
33382 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn in sqlite3TreeViewExpr()
33394 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); in sqlite3TreeViewExpr()
33414 sqlite3TreeViewExpr(pView, pExpr->pRight, 0); in sqlite3TreeViewExpr()
33425 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s", in sqlite3TreeViewExpr()
33429 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0); in sqlite3TreeViewExpr()
33434 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33442 sqlite3TreeViewExpr(pView, &tmp, 0); in sqlite3TreeViewExpr()
33446 if( pExpr->iColumn<=0 ){ in sqlite3TreeViewExpr()
33462 sqlite3TreeViewExpr(pView, pExpr->pRight, 0); in sqlite3TreeViewExpr()
33465 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); in sqlite3TreeViewExpr()
33479 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; in sqlite3TreeViewBareExprList()
33480 if( pList==0 ){ in sqlite3TreeViewBareExprList()
33485 for(i=0; i<pList->nExpr; i++){ in sqlite3TreeViewBareExprList()
33491 moreToFollow = 0; in sqlite3TreeViewBareExprList()
33492 sqlite3TreeViewLine(pView, 0); in sqlite3TreeViewBareExprList()
33541 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; in sqlite3TreeViewBareIdList()
33542 if( pList==0 ){ in sqlite3TreeViewBareIdList()
33547 for(i=0; i<pList->nId; i++){ in sqlite3TreeViewBareIdList()
33550 if( zName==0 ) zName = "(null)"; in sqlite3TreeViewBareIdList()
33552 sqlite3TreeViewLine(pView, 0); in sqlite3TreeViewBareIdList()
33559 if( pList->a[i].u4.pExpr==0 ){ in sqlite3TreeViewBareIdList()
33564 sqlite3TreeViewExpr(pView, pList->a[i].u4.pExpr, 0); in sqlite3TreeViewBareIdList()
33591 if( pUpsert==0 ) return; in sqlite3TreeViewUpsert()
33595 sqlite3TreeViewPush(&pView, pUpsert->pNextUpsert!=0 || moreToFollow); in sqlite3TreeViewUpsert()
33598 n = (pUpsert->pUpsertSet!=0) + (pUpsert->pUpsertWhere!=0); in sqlite3TreeViewUpsert()
33599 sqlite3TreeViewExprList(pView, pUpsert->pUpsertTarget, (n--)>0, "TARGET"); in sqlite3TreeViewUpsert()
33600 sqlite3TreeViewExprList(pView, pUpsert->pUpsertSet, (n--)>0, "SET"); in sqlite3TreeViewUpsert()
33602 sqlite3TreeViewItem(pView, "WHERE", (n--)>0); in sqlite3TreeViewUpsert()
33603 sqlite3TreeViewExpr(pView, pUpsert->pUpsertWhere, 0); in sqlite3TreeViewUpsert()
33625 int n = 0; in sqlite3TreeViewDelete()
33626 TreeView *pView = 0; in sqlite3TreeViewDelete()
33627 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewDelete()
33636 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewDelete()
33637 sqlite3TreeViewWith(pView, pWith, 0); in sqlite3TreeViewDelete()
33641 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewDelete()
33647 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewDelete()
33649 sqlite3TreeViewExpr(pView, pWhere, 0); in sqlite3TreeViewDelete()
33653 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); in sqlite3TreeViewDelete()
33656 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewDelete()
33658 sqlite3TreeViewExpr(pView, pLimit, 0); in sqlite3TreeViewDelete()
33662 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); in sqlite3TreeViewDelete()
33683 TreeView *pView = 0; in sqlite3TreeViewInsert()
33684 int n = 0; in sqlite3TreeViewInsert()
33693 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewInsert()
33703 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewInsert()
33704 sqlite3TreeViewWith(pView, pWith, 0); in sqlite3TreeViewInsert()
33708 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewInsert()
33714 sqlite3TreeViewIdList(pView, pColumnList, (--n)>0, "COLUMNS"); in sqlite3TreeViewInsert()
33717 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewInsert()
33719 sqlite3TreeViewSelect(pView, pSelect, 0); in sqlite3TreeViewInsert()
33723 sqlite3TreeViewExprList(pView, pExprList, (--n)>0, "VALUES"); in sqlite3TreeViewInsert()
33726 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewInsert()
33728 sqlite3TreeViewUpsert(pView, pUpsert, 0); in sqlite3TreeViewInsert()
33732 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); in sqlite3TreeViewInsert()
33754 int n = 0; in sqlite3TreeViewUpdate()
33755 TreeView *pView = 0; in sqlite3TreeViewUpdate()
33764 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewUpdate()
33775 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
33776 sqlite3TreeViewWith(pView, pWith, 0); in sqlite3TreeViewUpdate()
33780 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
33786 sqlite3TreeViewExprList(pView, pChanges, (--n)>0, "SET"); in sqlite3TreeViewUpdate()
33789 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
33791 sqlite3TreeViewExpr(pView, pWhere, 0); in sqlite3TreeViewUpdate()
33795 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); in sqlite3TreeViewUpdate()
33798 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
33800 sqlite3TreeViewExpr(pView, pLimit, 0); in sqlite3TreeViewUpdate()
33804 sqlite3TreeViewPush(&pView, (--n)>0); in sqlite3TreeViewUpdate()
33806 sqlite3TreeViewUpsert(pView, pUpsert, 0); in sqlite3TreeViewUpdate()
33810 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); in sqlite3TreeViewUpdate()
33826 int cnt = 0; in sqlite3TreeViewTriggerStep()
33827 if( pStep==0 ) return; in sqlite3TreeViewTriggerStep()
33829 moreToFollow || (showFullList && pStep->pNext!=0)); in sqlite3TreeViewTriggerStep()
33831 if( cnt++ && pStep->pNext==0 ){ in sqlite3TreeViewTriggerStep()
33833 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewTriggerStep()
33836 }while( showFullList && (pStep = pStep->pNext)!=0 ); in sqlite3TreeViewTriggerStep()
33849 int cnt = 0; in sqlite3TreeViewTrigger()
33850 if( pTrigger==0 ) return; in sqlite3TreeViewTrigger()
33852 moreToFollow || (showFullList && pTrigger->pNext!=0)); in sqlite3TreeViewTrigger()
33854 if( cnt++ && pTrigger->pNext==0 ){ in sqlite3TreeViewTrigger()
33856 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewTrigger()
33859 sqlite3TreeViewPush(&pView, 0); in sqlite3TreeViewTrigger()
33860 sqlite3TreeViewTriggerStep(pView, pTrigger->step_list, 0, 1); in sqlite3TreeViewTrigger()
33862 }while( showFullList && (pTrigger = pTrigger->pNext)!=0 ); in sqlite3TreeViewTrigger()
33878 SQLITE_PRIVATE void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); } in sqlite3ShowExpr()
33879 SQLITE_PRIVATE void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);} in sqlite3ShowExprList()
33880 SQLITE_PRIVATE void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); } in sqlite3ShowIdList()
33881 SQLITE_PRIVATE void sqlite3ShowSrcList(const SrcList *p){ sqlite3TreeViewSrcList(0,p); } in sqlite3ShowSrcList()
33882 SQLITE_PRIVATE void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); } in sqlite3ShowSelect()
33883 SQLITE_PRIVATE void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); } in sqlite3ShowWith()
33884 SQLITE_PRIVATE void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); } in sqlite3ShowUpsert()
33887 sqlite3TreeViewTriggerStep(0,p,0,0); in sqlite3ShowTriggerStep()
33890 sqlite3TreeViewTriggerStep(0,p,0,1); in sqlite3ShowTriggerStepList()
33892 SQLITE_PRIVATE void sqlite3ShowTrigger(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,0); } in sqlite3ShowTrigger()
33893 SQLITE_PRIVATE void sqlite3ShowTriggerList(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,1);} in sqlite3ShowTriggerList()
33896 SQLITE_PRIVATE void sqlite3ShowWindow(const Window *p){ sqlite3TreeViewWindow(0,p,0); } in sqlite3ShowWindow()
33897 SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window *p){ sqlite3TreeViewWinFunc(0,p,0); } in sqlite3ShowWinFunc()
33946 for(i=0; i<10; i++){ in chacha_block()
33947 QR(x[0], x[4], x[ 8], x[12]); in chacha_block()
33951 QR(x[0], x[5], x[10], x[15]); in chacha_block()
33956 for(i=0; i<16; i++) out[i] = x[i]+in[i]; in chacha_block()
33973 # define wsdPrng p[0] in sqlite3_randomness()
33991 if( N<=0 || pBuf==0 ){ in sqlite3_randomness()
33992 wsdPrng.s[0] = 0; in sqlite3_randomness()
34000 if( wsdPrng.s[0]==0 ){ in sqlite3_randomness()
34001 sqlite3_vfs *pVfs = sqlite3_vfs_find(0); in sqlite3_randomness()
34003 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 in sqlite3_randomness()
34005 memcpy(&wsdPrng.s[0], chacha20_init, 16); in sqlite3_randomness()
34006 if( NEVER(pVfs==0) ){ in sqlite3_randomness()
34007 memset(&wsdPrng.s[4], 0, 44); in sqlite3_randomness()
34012 wsdPrng.s[12] = 0; in sqlite3_randomness()
34013 wsdPrng.n = 0; in sqlite3_randomness()
34016 assert( N>0 ); in sqlite3_randomness()
34023 if( wsdPrng.n>0 ){ in sqlite3_randomness()
34096 #if SQLITE_MAX_WORKER_THREADS>0
34099 #if SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) && SQLITE_THREADSAFE>0
34122 assert( ppThread!=0 ); in sqlite3ThreadCreate()
34123 assert( xTask!=0 ); in sqlite3ThreadCreate()
34125 assert( sqlite3GlobalConfig.bCoreMutex!=0 ); in sqlite3ThreadCreate()
34127 *ppThread = 0; in sqlite3ThreadCreate()
34129 if( p==0 ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadCreate()
34130 memset(p, 0, sizeof(*p)); in sqlite3ThreadCreate()
34140 rc = pthread_create(&p->tid, 0, xTask, pIn); in sqlite3ThreadCreate()
34154 assert( ppOut!=0 ); in sqlite3ThreadJoin()
34155 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadJoin()
34191 assert( p!=0 ); in sqlite3ThreadProc()
34192 #if 0 in sqlite3ThreadProc()
34201 assert( p->xTask!=0 ); in sqlite3ThreadProc()
34204 _endthreadex(0); in sqlite3ThreadProc()
34205 return 0; /* NOT REACHED */ in sqlite3ThreadProc()
34216 assert( ppThread!=0 ); in sqlite3ThreadCreate()
34217 assert( xTask!=0 ); in sqlite3ThreadCreate()
34218 *ppThread = 0; in sqlite3ThreadCreate()
34220 if( p==0 ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadCreate()
34226 if( sqlite3GlobalConfig.bCoreMutex==0 || sqlite3FaultSim(200) ){ in sqlite3ThreadCreate()
34227 memset(p, 0, sizeof(*p)); in sqlite3ThreadCreate()
34231 p->tid = (void*)_beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id); in sqlite3ThreadCreate()
34232 if( p->tid==0 ){ in sqlite3ThreadCreate()
34233 memset(p, 0, sizeof(*p)); in sqlite3ThreadCreate()
34236 if( p->xTask==0 ){ in sqlite3ThreadCreate()
34251 assert( ppOut!=0 ); in sqlite3ThreadJoin()
34252 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadJoin()
34253 if( p->xTask==0 ){ in sqlite3ThreadJoin()
34256 assert( p->tid==0 ); in sqlite3ThreadJoin()
34258 assert( p->id!=0 && p->id!=GetCurrentThreadId() ); in sqlite3ThreadJoin()
34296 assert( ppThread!=0 ); in sqlite3ThreadCreate()
34297 assert( xTask!=0 ); in sqlite3ThreadCreate()
34298 *ppThread = 0; in sqlite3ThreadCreate()
34300 if( p==0 ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadCreate()
34305 p->xTask = 0; in sqlite3ThreadCreate()
34315 assert( ppOut!=0 ); in sqlite3ThreadJoin()
34316 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT; in sqlite3ThreadJoin()
34337 #endif /* SQLITE_MAX_WORKER_THREADS>0 */
34357 ** Byte-0 Byte-1 Byte-2 Byte-3 Value
34358 ** 0xxxxxxx 00000000 00000000 0xxxxxxx
34366 ** Word-0 Word-1 Value
34372 ** 0xff 0xfe little-endian utf-16 follows
34373 ** 0xfe 0xff big-endian utf-16 follows
34380 #if !defined(SQLITE_AMALGAMATION) && SQLITE_BYTEORDER==0
34386 #endif /* SQLITE_AMALGAMATION && SQLITE_BYTEORDER==0 */
34393 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
34394 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
34395 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
34396 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
34397 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
34398 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
34399 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
34400 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
34405 if( c<0x00080 ){ \
34406 *zOut++ = (u8)(c&0xFF); \
34408 else if( c<0x00800 ){ \
34409 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \
34410 *zOut++ = 0x80 + (u8)(c & 0x3F); \
34412 else if( c<0x10000 ){ \
34413 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \
34414 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
34415 *zOut++ = 0x80 + (u8)(c & 0x3F); \
34417 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07); \
34418 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \
34419 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
34420 *zOut++ = 0x80 + (u8)(c & 0x3F); \
34425 if( c<=0xFFFF ){ \
34426 *zOut++ = (u8)(c&0x00FF); \
34427 *zOut++ = (u8)((c>>8)&0x00FF); \
34429 *zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
34430 *zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03)); \
34431 *zOut++ = (u8)(c&0x00FF); \
34432 *zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); \
34437 if( c<=0xFFFF ){ \
34438 *zOut++ = (u8)((c>>8)&0x00FF); \
34439 *zOut++ = (u8)(c&0x00FF); \
34441 *zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03)); \
34442 *zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
34443 *zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); \
34444 *zOut++ = (u8)(c&0x00FF); \
34452 ** is a 0x00.
34458 ** * This routine never allows a 7-bit character (0x00 through 0x7f) to
34460 ** attempts to encode a value between 0x00 and 0x7f is rendered as 0xfffd.
34464 ** 0xd800 and 0xe000 then it is rendered as 0xfffd.
34466 ** * Bytes in the range of 0x80 through 0xbf which occur as the first
34472 ** for unicode values 0x80 and greater. It does not change over-length
34473 ** encodings to 0xfffd as some systems recommend.
34477 if( c>=0xc0 ){ \
34478 c = sqlite3Utf8Trans1[c-0xc0]; \
34479 while( zIn!=zTerm && (*zIn & 0xc0)==0x80 ){ \
34480 c = (c<<6) + (0x3f & *(zIn++)); \
34482 if( c<0x80 \
34483 || (c&0xFFFFF800)==0xD800 \
34484 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
34495 if( c>=0xc0 ){ in sqlite3Utf8Read()
34496 c = sqlite3Utf8Trans1[c-0xc0]; in sqlite3Utf8Read()
34497 while( (*(*pz) & 0xc0)==0x80 ){ in sqlite3Utf8Read()
34498 c = (c<<6) + (0x3f & *((*pz)++)); in sqlite3Utf8Read()
34500 if( c<0x80 in sqlite3Utf8Read()
34501 || (c&0xFFFFF800)==0xD800 in sqlite3Utf8Read()
34502 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } in sqlite3Utf8Read()
34526 assert( n>0 ); in sqlite3Utf8ReadLimited()
34527 c = z[0]; in sqlite3Utf8ReadLimited()
34528 if( c>=0xc0 ){ in sqlite3Utf8ReadLimited()
34529 c = sqlite3Utf8Trans1[c-0xc0]; in sqlite3Utf8ReadLimited()
34531 while( i<n && (z[i] & 0xc0)==0x80 ){ in sqlite3Utf8ReadLimited()
34532 c = (c<<6) + (0x3f & z[i]); in sqlite3Utf8ReadLimited()
34561 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); in sqlite3VdbeMemTranslate()
34564 assert( pMem->enc!=0 ); in sqlite3VdbeMemTranslate()
34565 assert( pMem->n>=0 ); in sqlite3VdbeMemTranslate()
34571 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); in sqlite3VdbeMemTranslate()
34649 *z++ = 0; in sqlite3VdbeMemTranslate()
34657 if( c>=0xd800 && c<0xe000 ){ in sqlite3VdbeMemTranslate()
34659 if( c>=0xdc00 || zIn>=zTerm ){ in sqlite3VdbeMemTranslate()
34660 c = 0xfffd; in sqlite3VdbeMemTranslate()
34664 if( c2<0xdc00 || c2>=0xe000 ){ in sqlite3VdbeMemTranslate()
34666 c = 0xfffd; in sqlite3VdbeMemTranslate()
34668 c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; in sqlite3VdbeMemTranslate()
34675 c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); in sqlite3VdbeMemTranslate()
34686 if( c>=0xd800 && c<0xe000 ){ in sqlite3VdbeMemTranslate()
34688 if( c>=0xdc00 || zIn>=zTerm ){ in sqlite3VdbeMemTranslate()
34689 c = 0xfffd; in sqlite3VdbeMemTranslate()
34693 if( c2<0xdc00 || c2>=0xe000 ){ in sqlite3VdbeMemTranslate()
34695 c = 0xfffd; in sqlite3VdbeMemTranslate()
34697 c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; in sqlite3VdbeMemTranslate()
34704 c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); in sqlite3VdbeMemTranslate()
34713 *z = 0; in sqlite3VdbeMemTranslate()
34729 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); in sqlite3VdbeMemTranslate()
34750 u8 bom = 0; in sqlite3VdbeMemHandleBom()
34752 assert( pMem->n>=0 ); in sqlite3VdbeMemHandleBom()
34756 if( b1==0xFE && b2==0xFF ){ in sqlite3VdbeMemHandleBom()
34759 if( b1==0xFF && b2==0xFE ){ in sqlite3VdbeMemHandleBom()
34769 pMem->z[pMem->n] = '\0'; in sqlite3VdbeMemHandleBom()
34770 pMem->z[pMem->n+1] = '\0'; in sqlite3VdbeMemHandleBom()
34782 ** the first 0x00 byte. If nByte is not less than zero, return the
34784 ** the first 0x00, whichever comes first).
34787 int r = 0; in sqlite3Utf8CharLen()
34790 if( nByte>=0 ){ in sqlite3Utf8CharLen()
34796 while( *z!=0 && z<zTerm ){ in sqlite3Utf8CharLen()
34821 while( zIn[0] && zOut<=zIn ){ in sqlite3Utf8To8()
34823 if( c!=0xfffd ){ in sqlite3Utf8To8()
34827 *zOut = 0; in sqlite3Utf8To8()
34842 memset(&m, 0, sizeof(m)); in sqlite3Utf16to8()
34848 m.z = 0; in sqlite3Utf16to8()
34850 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed ); in sqlite3Utf16to8()
34851 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed ); in sqlite3Utf16to8()
34864 int n = 0; in sqlite3Utf16ByteLen()
34868 c = z[0]; in sqlite3Utf16ByteLen()
34870 if( c>=0xd8 && c<0xdc && z[0]>=0xdc && z[0]<0xe0 ) z += 2; in sqlite3Utf16ByteLen()
34890 for(i=0; i<0x00110000; i++){ in sqlite3UtfSelfTest()
34894 assert( n>0 && n<=4 ); in sqlite3UtfSelfTest()
34895 z[0] = 0; in sqlite3UtfSelfTest()
34899 if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD; in sqlite3UtfSelfTest()
34900 if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD; in sqlite3UtfSelfTest()
34938 ** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0). The
35002 if( z==0 ) return 0; in sqlite3Strlen30()
35003 return 0x3fffffff & (int)strlen(z); in sqlite3Strlen30()
35040 assert( db!=0 ); in sqlite3Error()
35054 assert( db!=0 ); in sqlite3ErrorClear()
35071 for(ii=0; ii<db->nDb; ii++){ in sqlite3SystemError()
35083 rc &= 0xff; in sqlite3SystemError()
35102 assert( db!=0 ); in sqlite3ErrorWithMsg()
35105 if( zFormat==0 ){ in sqlite3ErrorWithMsg()
35107 }else if( db->pErr || (db->pErr = sqlite3ValueNew(db))!=0 ){ in sqlite3ErrorWithMsg()
35129 p->nProgressSteps = 0; in sqlite3ProgressCheck()
35135 p->nProgressSteps = 0; in sqlite3ProgressCheck()
35155 assert( db!=0 ); in sqlite3ErrorMsg()
35173 pParse->pWith = 0; in sqlite3ErrorMsg()
35184 if( db==0 || (pParse = db->pParse)==0 ) return errCode; in sqlite3ErrorToParser()
35210 if( z==0 ) return; in sqlite3Dequote()
35211 quote = z[0]; in sqlite3Dequote()
35214 for(i=1, j=0;; i++){ in sqlite3Dequote()
35227 z[j] = 0; in sqlite3Dequote()
35231 assert( sqlite3Isquote(p->u.zToken[0]) ); in sqlite3DequoteExpr()
35232 p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted; in sqlite3DequoteExpr()
35242 assert( p!=0 || pParse->db->mallocFailed ); in sqlite3DequoteNumber()
35246 int bHex = (pIn[0]=='0' && (pIn[1]=='x' || pIn[1]=='X')); in sqlite3DequoteNumber()
35255 if( (bHex==0 && (!sqlite3Isdigit(pIn[-1]) || !sqlite3Isdigit(pIn[1]))) in sqlite3DequoteNumber()
35288 if( !sqlite3Isquote(p->z[0]) ) return; in sqlite3DequoteToken()
35318 if( zLeft==0 ){ in sqlite3_stricmp()
35319 return zRight ? -1 : 0; in sqlite3_stricmp()
35320 }else if( zRight==0 ){ in sqlite3_stricmp()
35334 if( c==0 ) break; in sqlite3StrICmp()
35346 if( zLeft==0 ){ in sqlite3_strnicmp()
35347 return zRight ? -1 : 0; in sqlite3_strnicmp()
35348 }else if( zRight==0 ){ in sqlite3_strnicmp()
35353 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } in sqlite3_strnicmp()
35354 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; in sqlite3_strnicmp()
35361 u8 h = 0; in sqlite3StrIHash()
35362 if( z==0 ) return 0; in sqlite3StrIHash()
35363 while( z[0] ){ in sqlite3StrIHash()
35364 h += UpperToLower[(unsigned char)z[0]]; in sqlite3StrIHash()
35370 /* Double-Double multiplication. (x[0],x[1]) *= (y,yy)
35388 memcpy(&m, (void*)&x[0], 8); in dekkerMul2()
35389 m &= 0xfffffffffc000000LL; in dekkerMul2()
35391 tx = x[0] - hx; in dekkerMul2()
35393 m &= 0xfffffffffc000000LL; in dekkerMul2()
35400 cc = x[0]*yy + x[1]*y + cc; in dekkerMul2()
35401 x[0] = c + cc; in dekkerMul2()
35402 x[1] = c - x[0]; in dekkerMul2()
35418 ** 0 or less => The input string is not a valid number
35444 u64 s = 0; /* significand */ in sqlite3AtoF()
35445 int d = 0; /* adjust exponent for shifting decimal point */ in sqlite3AtoF()
35447 int e = 0; /* exponent */ in sqlite3AtoF()
35449 int nDigit = 0; /* Number of digits processed */ in sqlite3AtoF()
35454 if( length==0 ) return 0; in sqlite3AtoF()
35466 for(i=3-enc; i<length && z[i]==0; i+=2){} in sqlite3AtoF()
35474 if( z>=zEnd ) return 0; in sqlite3AtoF()
35486 s = s*10 + (*z - '0'); in sqlite3AtoF()
35504 s = s*10 + (*z - '0'); in sqlite3AtoF()
35516 eValid = 0; in sqlite3AtoF()
35533 e = e<10000 ? (e*10 + (*z - '0')) : 10000; in sqlite3AtoF()
35544 if( s==0 ){ in sqlite3AtoF()
35545 *pResult = sign<0 ? -0.0 : +0.0; in sqlite3AtoF()
35553 while( e>0 && s<(LARGEST_UINT64/10) ){ in sqlite3AtoF()
35557 while( e<0 && (s%10)==0 ){ in sqlite3AtoF()
35562 if( e==0 ){ in sqlite3AtoF()
35566 if( e>0 ){ in sqlite3AtoF()
35588 rr[0] = (double)s; in sqlite3AtoF()
35589 s2 = (u64)rr[0]; in sqlite3AtoF()
35591 if( s2==0x8000000000000000LL ){ s2 = 2*(u64)(0.5*rr[0]); } in sqlite3AtoF()
35594 if( e>0 ){ in sqlite3AtoF()
35621 *pResult = rr[0]+rr[1]; in sqlite3AtoF()
35624 if( sign<0 ) *pResult = -*pResult; in sqlite3AtoF()
35629 if( z==zEnd && nDigit>0 && eValid && eType>0 ){ in sqlite3AtoF()
35631 }else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){ in sqlite3AtoF()
35634 return 0; in sqlite3AtoF()
35656 if( v<0 ){ in sqlite3Int64ToText()
35662 zTemp[sizeof(zTemp)-1] = 0; in sqlite3Int64ToText()
35664 zTemp[i] = (x%10) + '0'; in sqlite3Int64ToText()
35666 if( x==0 ) break; in sqlite3Int64ToText()
35669 if( v<0 ) zTemp[--i] = '-'; in sqlite3Int64ToText()
35689 int c = 0; in compare2pow63()
35693 for(i=0; c==0 && i<18; i++){ in compare2pow63()
35696 if( c==0 ){ in compare2pow63()
35699 testcase( c==0 ); in compare2pow63()
35712 ** 0 Successful transformation. Fits in a 64-bit signed integer.
35723 u64 u = 0; in sqlite3Atoi64()
35724 int neg = 0; /* assume positive */ in sqlite3Atoi64()
35726 int c = 0; in sqlite3Atoi64()
35727 int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */ in sqlite3Atoi64()
35738 for(i=3-enc; i<length && zNum[i]==0; i+=2){} in sqlite3Atoi64()
35753 while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */ in sqlite3Atoi64()
35754 for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){ in sqlite3Atoi64()
35755 u = u*10 + c - '0'; in sqlite3Atoi64()
35771 rc = 0; in sqlite3Atoi64()
35772 if( i==0 && zStart==zNum ){ /* No digits */ in sqlite3Atoi64()
35793 if( c<0 ){ in sqlite3Atoi64()
35799 if( c>0 ){ in sqlite3Atoi64()
35819 ** 0 Successful transformation. Fits in a 64-bit signed integer.
35826 if( z[0]=='0' in sqlite3DecOrHexToI64()
35829 u64 u = 0; in sqlite3DecOrHexToI64()
35831 for(i=2; z[i]=='0'; i++){} in sqlite3DecOrHexToI64()
35837 if( z[k]!=0 ) return 1; in sqlite3DecOrHexToI64()
35838 return 0; in sqlite3DecOrHexToI64()
35842 int n = (int)(0x3fffffff&strspn(z,"+- \n\t0123456789")); in sqlite3DecOrHexToI64()
35859 sqlite_int64 v = 0; in sqlite3GetInt32()
35861 int neg = 0; in sqlite3GetInt32()
35862 if( zNum[0]=='-' ){ in sqlite3GetInt32()
35865 }else if( zNum[0]=='+' ){ in sqlite3GetInt32()
35869 else if( zNum[0]=='0' in sqlite3GetInt32()
35873 u32 u = 0; in sqlite3GetInt32()
35875 while( zNum[0]=='0' ) zNum++; in sqlite3GetInt32()
35876 for(i=0; i<8 && sqlite3Isxdigit(zNum[i]); i++){ in sqlite3GetInt32()
35879 if( (u&0x80000000)==0 && sqlite3Isxdigit(zNum[i])==0 ){ in sqlite3GetInt32()
35883 return 0; in sqlite3GetInt32()
35887 if( !sqlite3Isdigit(zNum[0]) ) return 0; in sqlite3GetInt32()
35888 while( zNum[0]=='0' ) zNum++; in sqlite3GetInt32()
35889 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){ in sqlite3GetInt32()
35900 return 0; in sqlite3GetInt32()
35904 return 0; in sqlite3GetInt32()
35915 ** string is not an integer, just return 0.
35918 int x = 0; in sqlite3Atoi()
35940 int e, exp = 0; in sqlite3FpDecode()
35941 p->isSpecial = 0; in sqlite3FpDecode()
35953 p->z = "0"; in sqlite3FpDecode()
35960 if( (e&0x7ff)==0x7ff ){ in sqlite3FpDecode()
35961 p->isSpecial = 1 + (v!=0x7ff0000000000000LL); in sqlite3FpDecode()
35962 p->n = 0; in sqlite3FpDecode()
35963 p->iDP = 0; in sqlite3FpDecode()
35993 rr[0] = r; in sqlite3FpDecode()
35995 if( rr[0]>9.223372036854774784e+18 ){ in sqlite3FpDecode()
35996 while( rr[0]>9.223372036854774784e+118 ){ in sqlite3FpDecode()
36000 while( rr[0]>9.223372036854774784e+28 ){ in sqlite3FpDecode()
36004 while( rr[0]>9.223372036854774784e+18 ){ in sqlite3FpDecode()
36009 while( rr[0]<9.223372036854774784e-83 ){ in sqlite3FpDecode()
36013 while( rr[0]<9.223372036854774784e+07 ){ in sqlite3FpDecode()
36017 while( rr[0]<9.22337203685477478e+17 ){ in sqlite3FpDecode()
36022 v = rr[1]<0.0 ? (u64)rr[0]-(u64)(-rr[1]) : (u64)rr[0]+(u64)rr[1]; in sqlite3FpDecode()
36028 assert( v>0 ); in sqlite3FpDecode()
36029 while( v ){ p->zBuf[i--] = (v%10) + '0'; v /= 10; } in sqlite3FpDecode()
36030 assert( i>=0 && i<sizeof(p->zBuf)-1 ); in sqlite3FpDecode()
36032 assert( p->n>0 ); in sqlite3FpDecode()
36035 if( iRound<=0 ){ in sqlite3FpDecode()
36037 if( iRound==0 && p->zBuf[i+1]>='5' ){ in sqlite3FpDecode()
36039 p->zBuf[i--] = '0'; in sqlite3FpDecode()
36044 if( iRound>0 && (iRound<p->n || p->n>mxRound) ){ in sqlite3FpDecode()
36053 z[j] = '0'; in sqlite3FpDecode()
36054 if( j==0 ){ in sqlite3FpDecode()
36067 while( ALWAYS(p->n>0) && p->z[p->n-1]=='0' ){ p->n--; } in sqlite3FpDecode()
36077 u64 v = 0; in sqlite3GetUInt32()
36079 for(i=0; sqlite3Isdigit(z[i]); i++){ in sqlite3GetUInt32()
36080 v = v*10 + z[i] - '0'; in sqlite3GetUInt32()
36081 if( v>4294967296LL ){ *pI = 0; return 0; } in sqlite3GetUInt32()
36083 if( i==0 || z[i]!=0 ){ *pI = 0; return 0; } in sqlite3GetUInt32()
36092 ** A = 0xxxxxxx 7 bits of data and one flag bit
36108 ** Write a 64-bit variable-length integer to memory starting at p[0].
36120 if( v & (((u64)0xff000000)<<32) ){ in putVarint64()
36123 for(i=7; i>=0; i--){ in putVarint64()
36124 p[i] = (u8)((v & 0x7f) | 0x80); in putVarint64()
36129 n = 0; in putVarint64()
36131 buf[n++] = (u8)((v & 0x7f) | 0x80); in putVarint64()
36133 }while( v!=0 ); in putVarint64()
36134 buf[0] &= 0x7f; in putVarint64()
36136 for(i=0, j=n-1; j>=0; j--, i++){ in putVarint64()
36142 if( v<=0x7f ){ in sqlite3PutVarint()
36143 p[0] = v&0x7f; in sqlite3PutVarint()
36146 if( v<=0x3fff ){ in sqlite3PutVarint()
36147 p[0] = ((v>>7)&0x7f)|0x80; in sqlite3PutVarint()
36148 p[1] = v&0x7f; in sqlite3PutVarint()
36159 ** SLOT_2_0 A mask for (0x7f<<14) | 0x7f
36161 ** SLOT_4_2_0 A mask for (0x7f<<28) | SLOT_2_0
36163 #define SLOT_2_0 0x001fc07f
36164 #define SLOT_4_2_0 0xf01fc07f
36168 ** Read a 64-bit variable-length integer from memory starting at p[0].
36174 if( ((signed char*)p)[0]>=0 ){ in sqlite3GetVarint()
36178 if( ((signed char*)p)[1]>=0 ){ in sqlite3GetVarint()
36179 *v = ((u32)(p[0]&0x7f)<<7) | p[1]; in sqlite3GetVarint()
36184 assert( SLOT_2_0 == ((0x7f<<14) | (0x7f)) ); in sqlite3GetVarint()
36185 assert( SLOT_4_2_0 == ((0xfU<<28) | (0x7f<<14) | (0x7f)) ); in sqlite3GetVarint()
36187 a = ((u32)p[0])<<14; in sqlite3GetVarint()
36192 if (!(a&0x80)) in sqlite3GetVarint()
36195 b &= 0x7f; in sqlite3GetVarint()
36208 if (!(b&0x80)) in sqlite3GetVarint()
36212 /* a &= (0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36223 /* a &= (0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36232 if (!(a&0x80)) in sqlite3GetVarint()
36236 /* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36237 /* b &= (0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36254 if (!(b&0x80)) in sqlite3GetVarint()
36257 /* b &= (0x7f<<28)|(0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36270 if (!(a&0x80)) in sqlite3GetVarint()
36287 if (!(b&0x80)) in sqlite3GetVarint()
36291 /* a &= (0x7f<<14)|(0x7f); */ in sqlite3GetVarint()
36305 /* a &= (0x7f<<29)|(0x7f<<15)|(0xff); */ in sqlite3GetVarint()
36312 b &= 0x7f; in sqlite3GetVarint()
36322 ** Read a 32-bit variable-length integer from memory starting at p[0].
36325 ** If the varint stored in p[0] is larger than can fit in a 32-bit unsigned
36326 ** integer, then set *v to 0xffffffff.
36338 assert( (p[0] & 0x80)!=0 ); in sqlite3GetVarint32()
36340 if( (p[1] & 0x80)==0 ){ in sqlite3GetVarint32()
36342 *v = ((p[0]&0x7f)<<7) | p[1]; in sqlite3GetVarint32()
36345 if( (p[2] & 0x80)==0 ){ in sqlite3GetVarint32()
36347 *v = ((p[0]&0x7f)<<14) | ((p[1]&0x7f)<<7) | p[2]; in sqlite3GetVarint32()
36354 *v = 0xffffffff; in sqlite3GetVarint32()
36367 for(i=1; (v >>= 7)!=0; i++){ assert( i<10 ); } in sqlite3VarintLen()
36389 testcase( p[0]&0x80 ); in sqlite3Get4byte()
36390 return ((unsigned)p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]; in sqlite3Get4byte()
36403 p[0] = (u8)(v>>24); in sqlite3Put4byte()
36415 ** character: 0..9a..fA..F
36418 assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') ); in sqlite3HexToInt()
36425 return (u8)(h & 0xf); in sqlite3HexToInt()
36442 for(i=0; i<n; i+=2){ in sqlite3HexToBlob()
36445 zBlob[i/2] = 0; in sqlite3HexToBlob()
36468 ** 1 it means that the db pointer is valid and 0 if it should not be
36479 if( db==0 ){ in sqlite3SafetyCheckOk()
36481 return 0; in sqlite3SafetyCheckOk()
36486 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3SafetyCheckOk()
36489 return 0; in sqlite3SafetyCheckOk()
36500 testcase( sqlite3GlobalConfig.xLog!=0 ); in sqlite3SafetyCheckSickOrOk()
36502 return 0; in sqlite3SafetyCheckSickOrOk()
36511 ** Return 0 on success. Or if the operation would have resulted in an
36519 testcase( iA==0 ); testcase( iA==1 ); in sqlite3AddInt64()
36520 testcase( iB==-1 ); testcase( iB==0 ); in sqlite3AddInt64()
36521 if( iB>=0 ){ in sqlite3AddInt64()
36522 testcase( iA>0 && LARGEST_INT64 - iA == iB ); in sqlite3AddInt64()
36523 testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 ); in sqlite3AddInt64()
36524 if( iA>0 && LARGEST_INT64 - iA < iB ) return 1; in sqlite3AddInt64()
36526 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 ); in sqlite3AddInt64()
36527 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 ); in sqlite3AddInt64()
36528 if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1; in sqlite3AddInt64()
36531 return 0; in sqlite3AddInt64()
36540 testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); in sqlite3SubInt64()
36541 if( (*pA)>=0 ) return 1; in sqlite3SubInt64()
36543 return 0; in sqlite3SubInt64()
36554 if( iB>0 ){ in sqlite3MulInt64()
36557 }else if( iB<0 ){ in sqlite3MulInt64()
36558 if( iA>0 ){ in sqlite3MulInt64()
36560 }else if( iA<0 ){ in sqlite3MulInt64()
36567 return 0; in sqlite3MulInt64()
36576 if( x>=0 ) return x; in sqlite3AbsInt32()
36577 if( x==(int)0x80000000 ) return 0x7fffffff; in sqlite3AbsInt32()
36601 if( sqlite3_uri_boolean(zBaseFilename, "8_3_names", 0) ) in sqlite3FileSuffix3()
36606 for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){} in sqlite3FileSuffix3()
36620 10, 10, /* 0,1 */ in sqlite3LogEstAdd()
36646 static LogEst a[] = { 0, 2, 3, 5, 6, 7, 8, 9 }; in sqlite3LogEst()
36649 if( x<2 ) return 0; in sqlite3LogEst()
36672 if( x<=1 ) return 0; in sqlite3LogEstFromDouble()
36720 ** } a[0];
36740 assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */ in sqlite3VListAdd()
36741 if( pIn==0 || pIn[1]+nInt > pIn[0] ){ in sqlite3VListAdd()
36743 sqlite3_int64 nAlloc = (pIn ? 2*(sqlite3_int64)pIn[0] : 10) + nInt; in sqlite3VListAdd()
36745 if( pOut==0 ) return pIn; in sqlite3VListAdd()
36746 if( pIn==0 ) pOut[1] = 2; in sqlite3VListAdd()
36748 pIn[0] = nAlloc; in sqlite3VListAdd()
36755 assert( pIn[1]<=pIn[0] ); in sqlite3VListAdd()
36757 z[nName] = 0; in sqlite3VListAdd()
36768 if( pIn==0 ) return 0; in sqlite3VListNumToName()
36775 return 0; in sqlite3VListNumToName()
36780 ** or return 0 if there is no such variable.
36784 if( pIn==0 ) return 0; in sqlite3VListNameToNum()
36789 if( strncmp(z,zName,nName)==0 && z[nName]==0 ) return pIn[i]; in sqlite3VListNameToNum()
36792 return 0; in sqlite3VListNameToNum()
36866 mftbu %0\n\
36867 cmpw %0,%1\n\
36883 SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
36918 assert( pNew!=0 );
36919 pNew->first = 0;
36920 pNew->count = 0;
36921 pNew->htsize = 0;
36922 pNew->ht = 0;
36932 assert( pH!=0 );
36934 pH->first = 0;
36936 pH->ht = 0;
36937 pH->htsize = 0;
36943 pH->count = 0;
36950 unsigned int h = 0;
36952 while( (c = (unsigned char)*z++)!=0 ){ /*OPTIMIZATION-IF-TRUE*/
36954 ** 0x9e3779b1 is 2654435761 which is the closest prime number to
36957 h *= 0x9e3779b1;
36963 /* Link pNew element into the hash table pH. If pEntry!=0 then also
36973 pHead = pEntry->count ? pEntry->chain : 0;
36977 pHead = 0;
36988 pNew->prev = 0;
37004 #if SQLITE_MALLOC_SOFT_LIMIT>0
37008 if( new_size==pH->htsize ) return 0;
37013 ** allocation as a benign. Use sqlite3Malloc()/memset(0) instead of
37023 if( new_ht==0 ) return 0;
37027 memset(new_ht, 0, new_size*sizeof(struct _ht));
37028 for(elem=pH->first, pH->first=0; elem; elem = next_elem){
37038 ** a pointer to a static null element with HashElem.data==0 is returned.
37049 static HashElem nullElement = { 0, 0, 0, 0 };
37058 h = 0;
37064 assert( elem!=0 );
37065 if( sqlite3StrICmp(elem->pKey,pKey)==0 ){
37096 assert( pEntry->count>0 );
37101 if( pH->count==0 ){
37102 assert( pH->first==0 );
37103 assert( pH->count==0 );
37113 assert( pH!=0 );
37114 assert( pKey!=0 );
37115 return findElementWithHash(pH, pKey, 0)->data;
37137 assert( pH!=0 );
37138 assert( pKey!=0 );
37142 if( data==0 ){
37150 if( data==0 ) return 0;
37152 if( new_elem==0 ) return data;
37158 assert( pH->htsize>0 );
37162 insertElement(pH, pH->ht ? &pH->ht[h] : 0, new_elem);
37163 return 0;
37174 # define OpHelp(X) "\0" X
37180 /* 0 */ "Savepoint" OpHelp(""),
37229 /* 49 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
37239 /* 59 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
37240 /* 60 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
37241 /* 61 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
37272 /* 92 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"),
37340 /* 160 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
37360 /* 180 */ "ClrSubtype" OpHelp("r[P1].subtype = 0"),
37401 #if 0
37408 #if 0
37474 0, /* pNext */
37476 0, /* pAppData */
37482 0, /* xDlError */
37483 0, /* xDlSym */
37484 0, /* xDlClose */
37488 0, /* xGetLastError */
37508 0, /* xShmMap */
37509 0, /* xShmLock */
37510 0, /* xShmBarrier */
37511 0, /* xShmUnmap */
37512 0, /* xFetch */
37513 0 /* xUnfetch */
37532 0, /* xShmMap */
37533 0, /* xShmLock */
37534 0, /* xShmBarrier */
37535 0, /* xShmUnmap */
37536 0, /* xFetch */
37537 0 /* xUnfetch */
37586 return 0;
37601 return 0;
37614 ** If nBuf<=0 then this routine simply returns the size of the data without
37627 if( access(zXKey, R_OK)!=0
37628 || stat(zXKey, &buf)!=0
37634 if( nBuf<=0 ){
37637 zBuf[0] = 0;
37646 if( fd==0 ){
37652 zBuf[n] = 0;
37715 ** base-26 number using a..z. "a" means 0. "b" means 1,
37725 for(i=j=0; i<nData; i++){
37727 if( c!=0 ){
37729 aOut[j++] = "0123456789ABCDEF"[c&0xf];
37737 for(k=1; i+k<nData && a[i+k]==0; k++){}
37739 while( k>0 ){
37745 aOut[j] = 0;
37753 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
37779 i = 0;
37780 j = 0;
37783 if( c<0 ){
37784 int n = 0;
37787 if( c==0 ) break;
37794 memset(&aOut[j], 0, n);
37796 if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */
37800 if( c<0 ) break;
37824 unsigned int n = 0;
37826 i = 0;
37834 if( pFile->aJrnl==0 ){
37835 pFile->nJrnl = 0;
37842 pFile->aJrnl = 0;
37843 pFile->nJrnl = 0;
37852 zData[0] = 0;
37854 return strtoll(zData, 0, 0);
37889 if( pFile->aJrnl==0 ){
37890 int szTxt = kvstorageRead(pFile->zClass, "jrnl", 0, 0);
37896 if( aTxt==0 ) return SQLITE_NOMEM;
37900 if( pFile->aJrnl==0 ) return SQLITE_IOERR;
37923 assert( iOfst>=0 );
37924 assert( iAmt>=0 );
37927 if( (iOfst % iAmt)!=0 ){
37930 if( (iAmt & (iAmt-1))!=0 || iAmt<512 || iAmt>65536 ){
37941 if( got<0 ){
37942 n = 0;
37944 aData[got] = 0;
37947 aData[k*2] = 0;
37953 n = 0;
37960 memset(zBuf+n, 0, iAmt-n);
37979 if( iEnd>=0x10000000 ) return SQLITE_FULL;
37980 if( pFile->aJrnl==0 || pFile->nJrnl<iEnd ){
37982 if( aNew==0 ){
37987 memset(pFile->aJrnl+pFile->nJrnl, 0, iOfst-pFile->nJrnl);
38010 assert( (iAmt & (iAmt-1))==0 );
38011 assert( pFile->szPage<0 || pFile->szPage==iAmt );
38031 assert( size==0 );
38034 pFile->aJrnl = 0;
38035 pFile->nJrnl = 0;
38041 && pFile->szPage>0
38042 && (size % pFile->szPage)==0
38068 if( pFile->nJrnl<=0 ){
38069 return kvvfsTruncateJrnl(pProtoFile, 0);
38072 if( zOut==0 ){
38076 i = 0;
38080 }while( n>0 );
38103 if( pFile->szDb>=0 ){
38143 *pResOut = 0;
38160 if( pFile->szDb>0 && 0!=kvvfsWriteFileSize(pFile, pFile->szDb) ){
38179 return 0;
38195 if( zName==0 ) zName = "";
38197 if( strcmp(zName, "local")==0
38198 || strcmp(zName, "session")==0
38200 pFile->isJournal = 0;
38203 if( strcmp(zName, "local-journal")==0
38204 || strcmp(zName, "session-journal")==0
38211 if( zName[0]=='s' ){
38217 if( pFile->aData==0 ){
38220 pFile->aJrnl = 0;
38221 pFile->nJrnl = 0;
38233 if( strcmp(zPath, "local-journal")==0 ){
38236 if( strcmp(zPath, "session-journal")==0 ){
38253 if( strcmp(zPath, "local-journal")==0 ){
38254 *pResOut = sqlite3KvvfsMethods.xRead("local", "jrnl", 0, 0)>0;
38256 if( strcmp(zPath, "session-journal")==0 ){
38257 *pResOut = sqlite3KvvfsMethods.xRead("session", "jrnl", 0, 0)>0;
38259 if( strcmp(zPath, "local")==0 ){
38260 *pResOut = sqlite3KvvfsMethods.xRead("local", "sz", 0, 0)>0;
38262 if( strcmp(zPath, "session")==0 ){
38263 *pResOut = sqlite3KvvfsMethods.xRead("session", "sz", 0, 0)>0;
38266 *pResOut = 0;
38291 zOut[nPath] = 0;
38299 return 0;
38307 memset(zBufOut, 0, nByte);
38323 sqlite3_int64 i = 0;
38325 rc = kvvfsCurrentTimeInt64(0, &i);
38333 (void)gettimeofday(&sNow, 0); /* Cannot fail given valid arguments */
38353 return sqlite3_vfs_register(&sqlite3OsKvvfsObject, 0);
38428 # define SQLITE_ENABLE_LOCKING_STYLE 0
38456 #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
38473 ** -DHAVE_GETHOSTUUID=0
38480 # define HAVE_GETHOSTUUID 0
38483 # if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
38484 && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))\
38485 && (!defined(TARGET_OS_MACCATALYST) || (TARGET_OS_MACCATALYST==0))
38512 #define SQLITE_FSFLAGS_IS_MSDOS 0x1
38553 # define HAVE_MREMAP 0
38559 # define F_RDLCK 0
38562 # if __LONG_MAX == 0x7fffffffL
38628 #if SQLITE_MAX_MMAP_SIZE>0
38675 static pid_t randomnessPid = 0;
38680 #define UNIXFILE_EXCL 0x01 /* Connections from one process only */
38681 #define UNIXFILE_RDONLY 0x02 /* Connection is read only */
38682 #define UNIXFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */
38684 # define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */
38686 # define UNIXFILE_DIRSYNC 0x00
38688 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
38689 #define UNIXFILE_DELETE 0x20 /* Delete on close */
38690 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */
38691 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
38702 # define O_LARGEFILE 0
38706 # define O_LARGEFILE 0
38709 # define O_NOFOLLOW 0
38712 # define O_BINARY 0
38716 ** The threadid macro resolves to the thread-id or to 0. Used for
38722 #define threadid 0
38732 # define HAVE_MREMAP 0
38748 #define F2FS_IOCTL_MAGIC 0xf5
38754 #define F2FS_FEATURE_ATOMIC_WRITE 0x0004
38785 { "open", (sqlite3_syscall_ptr)posixOpen, 0 },
38786 #define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent)
38788 { "close", (sqlite3_syscall_ptr)close, 0 },
38791 { "access", (sqlite3_syscall_ptr)access, 0 },
38794 { "getcwd", (sqlite3_syscall_ptr)getcwd, 0 },
38797 { "stat", (sqlite3_syscall_ptr)stat, 0 },
38807 { "fstat", 0, 0 },
38808 #define osFstat(a,b,c) 0
38810 { "fstat", (sqlite3_syscall_ptr)fstat, 0 },
38814 { "ftruncate", (sqlite3_syscall_ptr)ftruncate, 0 },
38817 { "fcntl", (sqlite3_syscall_ptr)fcntl, 0 },
38820 { "read", (sqlite3_syscall_ptr)read, 0 },
38824 { "pread", (sqlite3_syscall_ptr)pread, 0 },
38826 { "pread", (sqlite3_syscall_ptr)0, 0 },
38831 { "pread64", (sqlite3_syscall_ptr)pread64, 0 },
38833 { "pread64", (sqlite3_syscall_ptr)0, 0 },
38837 { "write", (sqlite3_syscall_ptr)write, 0 },
38841 { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 },
38843 { "pwrite", (sqlite3_syscall_ptr)0, 0 },
38849 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 },
38851 { "pwrite64", (sqlite3_syscall_ptr)0, 0 },
38857 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
38859 { "fchmod", (sqlite3_syscall_ptr)0, 0 },
38864 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
38866 { "fallocate", (sqlite3_syscall_ptr)0, 0 },
38870 { "unlink", (sqlite3_syscall_ptr)unlink, 0 },
38873 { "openDirectory", (sqlite3_syscall_ptr)openDirectory, 0 },
38876 { "mkdir", (sqlite3_syscall_ptr)mkdir, 0 },
38879 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 },
38883 { "fchown", (sqlite3_syscall_ptr)fchown, 0 },
38885 { "fchown", (sqlite3_syscall_ptr)0, 0 },
38890 { "geteuid", (sqlite3_syscall_ptr)geteuid, 0 },
38892 { "geteuid", (sqlite3_syscall_ptr)0, 0 },
38896 #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
38898 { "mmap", (sqlite3_syscall_ptr)mmap, 0 },
38900 { "mmap", (sqlite3_syscall_ptr)0, 0 },
38904 #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
38906 { "munmap", (sqlite3_syscall_ptr)munmap, 0 },
38908 { "munmap", (sqlite3_syscall_ptr)0, 0 },
38912 #if HAVE_MREMAP && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
38913 { "mremap", (sqlite3_syscall_ptr)mremap, 0 },
38915 { "mremap", (sqlite3_syscall_ptr)0, 0 },
38919 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
38920 { "getpagesize", (sqlite3_syscall_ptr)unixGetpagesize, 0 },
38922 { "getpagesize", (sqlite3_syscall_ptr)0, 0 },
38927 { "readlink", (sqlite3_syscall_ptr)readlink, 0 },
38929 { "readlink", (sqlite3_syscall_ptr)0, 0 },
38934 { "lstat", (sqlite3_syscall_ptr)lstat, 0 },
38936 { "lstat", (sqlite3_syscall_ptr)0, 0 },
38942 { "ioctl", (sqlite3_syscall_ptr)(int(*)(int, int, ...))ioctl, 0 },
38945 { "ioctl", (sqlite3_syscall_ptr)ioctl, 0 },
38949 { "ioctl", (sqlite3_syscall_ptr)0, 0 },
38962 return osGeteuid() ? 0 : osFchown(fd,uid,gid);
38964 return 0;
38983 if( zName==0 ){
38988 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
38997 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
38998 if( strcmp(zName, aSyscall[i].zName)==0 ){
38999 if( aSyscall[i].pDefault==0 ){
39003 if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault;
39024 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
39025 if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent;
39027 return 0;
39041 for(i=0; i<ArraySize(aSyscall)-1; i++){
39042 if( strcmp(zName, aSyscall[i].zName)==0 ) break;
39046 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName;
39048 return 0;
39064 ** If the file creation mode "m" is 0 then set it to the default for
39066 ** 0644) as modified by the system umask. If m is not 0, then
39086 if( fd<0 ){
39098 if( osOpen("/dev/null", O_RDONLY, m)<0 ) break;
39100 if( fd>=0 ){
39101 if( m!=0 ){
39103 if( osFstat(fd, &statbuf)==0
39104 && statbuf.st_size==0
39110 #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
39111 osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
39142 static sqlite3_mutex *unixBigLock = 0;
39205 assert( 0 );
39224 assert( 0 );
39250 if( sz>(sqlite3_int64)0x7FFFFFFF ){
39254 do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR );
39322 static struct vxworksFileId *vxworksFileList = 0;
39334 ** The original filename is in z[0..n-1]. Return the number of
39340 for(i=j=0; i<n; i++){
39348 while( j>0 && z[j-1]!='/' ){ j--; }
39349 if( j>0 ){ j--; }
39356 z[j] = 0;
39376 assert( zAbsoluteName[0]=='/' );
39379 if( pNew==0 ) return 0;
39391 && memcmp(pCandidate->zCanonicalName, pNew->zCanonicalName, n)==0
39415 assert( pId->nRef>0 );
39417 if( pId->nRef==0 ){
39478 ** field that tells us its internal lock status. cnt==0 means the
39480 ** cnt>0 means there are cnt shared locks on the file.
39515 ** was dropped beginning with version 3.7.0. SQLite will still work with
39555 ** (2) When nRef>0, then the following fields are unchanging and can
39592 static unixInodeInfo *inodeList = 0; /* All unixInodeInfo objects */
39636 /* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use
39642 memset(aErr, 0, sizeof(aErr));
39674 if( zPath==0 ) zPath = "";
39699 pFile ? pFile->zPath : 0, lineno);
39724 pInode->pUnused = 0;
39739 if( pInode->nRef==0 ){
39740 assert( pInode->pShmNode==0 );
39778 unixInodeInfo *pInode = 0; /* Candidate unixInodeInfo object */
39787 if( rc!=0 ){
39806 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
39807 do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR );
39813 if( rc!=0 ){
39820 memset(&fileId, 0, sizeof(fileId));
39832 if( pInode==0 ){
39834 if( pInode==0 ){
39837 memset(pInode, 0, sizeof(*pInode));
39841 if( pInode->pLockMutex==0 ){
39849 pInode->pPrev = 0;
39864 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId;
39867 return pFile->pInode!=0 &&
39868 (osStat(pFile->zPath, &buf)!=0
39891 if( rc!=0 ){
39895 if( buf.st_nlink==0 ){
39918 int reserved = 0;
39983 while( rc<0 && tm>0 ){
39989 unixSleep(0,1000);
40020 assert( pInode!=0 );
40023 if( pInode->bProcessLock==0 ){
40025 assert( pInode->nLock==0 );
40031 if( rc<0 ) return rc;
40035 rc = 0;
40112 int tErrno = 0;
40118 osGetpid(0)));
40161 assert( pFile->eFileLock==0 );
40162 assert( pInode->nShared>0 );
40199 assert( pInode->nShared==0 );
40200 assert( pInode->eFileLock==0 );
40240 assert( 0!=pFile->eFileLock );
40272 pFile->transCntrChng = 0;
40273 pFile->dbUpdate = 0;
40301 pFile->pPreallocatedUnused = 0;
40326 osGetpid(0)));
40334 assert( pInode->nShared!=0 );
40347 pFile->inNormalWrite = 0;
40362 assert( handleNFSUnlock==0 );
40425 if( unixFileLock(pFile, &lock)==0 ){
40439 if( pInode->nShared==0 ){
40442 lock.l_start = lock.l_len = 0L;
40443 if( unixFileLock(pFile, &lock)==0 ){
40458 assert( pInode->nLock>=0 );
40459 if( pInode->nLock==0 ) closePendingFds(pFile);
40478 #if SQLITE_MAX_MMAP_SIZE>0
40479 assert( eFileLock==SHARED_LOCK || ((unixFile *)id)->nFetchOut==0 );
40481 return posixUnlock(id, eFileLock, 0);
40484 #if SQLITE_MAX_MMAP_SIZE>0
40493 ** structure to 0.
40501 #if SQLITE_MAX_MMAP_SIZE>0
40504 if( pFile->h>=0 ){
40514 pFile->pId = 0;
40521 pFile->zPath = 0;
40527 memset(pFile, 0, sizeof(unixFile));
40539 assert( pInode!=0 );
40548 assert( pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 );
40560 assert( pFile->pShm==0 );
40588 *pResOut = 0;
40650 int reserved = 0;
40656 reserved = osAccess((const char*)pFile->lockingContext, 0)==0;
40711 if( rc<0 ){
40746 pFile->eFileLock, osGetpid(0)));
40765 if( rc<0 ){
40784 assert( id!=0 );
40814 do{ rc = flock(fd,op); }while( rc<0 && errno==EINTR );
40830 int reserved = 0;
40870 if( (rc & 0xff) == SQLITE_IOERR ){
40937 if( (rc & 0xff) == SQLITE_IOERR ){
40957 pFile->eFileLock, osGetpid(0)));
40987 assert( id!=0 );
41017 int reserved = 0;
41122 pFile->eFileLock, osGetpid(0)));
41199 unsigned char unLockFlag; /* 1 = unlock, 0 = lock */
41200 unsigned char startEndFlag; /* 1=rel to end of fork, 0=rel to start */
41222 pb.unLockFlag = setLockFlag ? 0 : 1;
41223 pb.startEndFlag = 0;
41231 err = fsctl(path, afpfsByteRangeLock2FSCTL, &pb, 0);
41260 int reserved = 0;
41286 lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0);
41336 azFileLock(pInode->eFileLock), pInode->nShared , osGetpid(0)));
41379 assert( pFile->eFileLock==0 );
41380 assert( pInode->nShared>0 );
41406 int lrc1, lrc2, lrc1Errno = 0;
41409 assert( pInode->nShared==0 );
41410 assert( pInode->eFileLock==0 );
41412 mask = (sizeof(long)==8) ? LARGEST_INT64 : 0x7fffffff;
41423 lrc2 = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
41448 int failed = 0;
41449 assert( 0!=pFile->eFileLock );
41464 pInode->sharedByte, 1, 0)) ){
41474 rc = ((failed & 0xff) == SQLITE_IOERR) ? failed2 :
41514 int skipShared = 0;
41519 osGetpid(0)));
41527 assert( pInode->nShared!=0 );
41540 assert( pFile->inNormalWrite==0
41541 || pFile->dbUpdate==0
41543 pFile->inNormalWrite = 0;
41547 rc = afpSetLock(context->dbPath, pFile, SHARED_FIRST, SHARED_SIZE, 0);
41557 rc = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
41560 rc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0);
41562 context->reserved = 0;
41577 if( pInode->nShared==0 ){
41579 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 0);
41588 assert( pInode->nLock>=0 );
41589 if( pInode->nLock==0 ) closePendingFds(pFile);
41606 assert( id!=0 );
41683 int prior = 0;
41688 assert( cnt==(cnt&0x1ffff) );
41700 if( newOffset<0 ){
41707 if( got<0 ){
41709 prior = 0;
41712 }else if( got>0 ){
41718 }while( got>0 );
41739 assert( offset>=0 );
41740 assert( amt>0 );
41744 #if 0
41745 assert( pFile->pPreallocatedUnused==0
41751 #if SQLITE_MAX_MMAP_SIZE>0
41771 }else if( got<0 ){
41792 storeLastErrno(pFile, 0); /* not a system error */
41794 memset(&((char*)pBuf)[got], 0, amt-got);
41813 int rc = 0; /* Value returned by system call */
41815 assert( nBuf==(nBuf&0x1ffff) );
41817 assert( piErrno!=0 );
41818 nBuf &= 0x1ffff;
41822 do{ rc = (int)osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR );
41824 do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
41829 if( iSeek<0 ){
41834 }while( rc<0 && errno==EINTR );
41840 if( rc<0 ) *piErrno = errno;
41868 int wrote = 0;
41870 assert( amt>0 );
41874 #if 0
41875 assert( pFile->pPreallocatedUnused==0
41895 SimulateIOErrorBenign(0);
41896 if( rc!=4 || memcmp(oldCntr, &((char*)pBuf)[24-offset], 4)!=0 ){
41903 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0
41920 while( (wrote = seekAndWrite(pFile, offset, pBuf, amt))<amt && wrote>0 ){
41926 SimulateDiskfullError(( wrote=0, amt=1 ));
41929 if( wrote<0 && pFile->lastErrno!=ENOSPC ){
41933 storeLastErrno(pFile, 0); /* not a system error */
41946 SQLITE_API int sqlite3_sync_count = 0;
41947 SQLITE_API int sqlite3_fullsync_count = 0;
41961 ** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not
41968 # define HAVE_FULLFSYNC 0
42035 rc = osFcntl(fd, F_FULLFSYNC, 0);
42064 rc = 0;
42098 for(ii=(int)strlen(zDirname); ii>0 && zDirname[ii]!='/'; ii--);
42099 if( ii>0 ){
42100 zDirname[ii] = '\0';
42102 if( zDirname[0]!='/' ) zDirname[0] = '.';
42103 zDirname[1] = 0;
42105 fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0);
42106 if( fd>=0 ){
42110 if( fd>=0 ) return SQLITE_OK;
42117 ** If dataOnly==0 then both the file itself and its metadata (file
42118 ** size, access time, etc) are synced. If dataOnly!=0 then only the
42134 int isFullsync = (flags&0x0F)==SQLITE_SYNC_FULL;
42137 assert((flags&0x0F)==SQLITE_SYNC_NORMAL
42138 || (flags&0x0F)==SQLITE_SYNC_FULL
42165 full_fsync(dirfd, 0, 0);
42190 if( pFile->szChunk>0 ){
42207 if( pFile->inNormalWrite && nByte==0 ){
42212 #if SQLITE_MAX_MMAP_SIZE>0
42235 if( rc!=0 ){
42247 if( *pSize==1 ) *pSize = 0;
42268 if( pFile->szChunk>0 ){
42297 int nWrite = 0; /* Number of bytes written by seekAndWrite */
42302 assert( ((iWrite+1)%nBlk)==0 );
42312 #if SQLITE_MAX_MMAP_SIZE>0
42313 if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){
42315 if( pFile->szChunk<=0 ){
42332 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
42334 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
42337 if( *pArg<0 ){
42338 *pArg = (pFile->ctrlFlags & mask)!=0;
42339 }else if( (*pArg)==0 ){
42389 SimulateIOErrorBenign(0);
42430 #if SQLITE_MAX_MMAP_SIZE>0
42441 if( newLimit>0 && sizeof(size_t)<8 ){
42442 newLimit = (newLimit & 0x7FFFFFFF);
42446 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
42448 if( pFile->mmapSize>0 ){
42463 ((unixFile*)id)->dbUpdate = 0;
42478 *(int*)pArg = 0;
42497 assert( pFd->deviceCharacteristics==0 || pFd->sectorSize!=0 );
42498 if( pFd->sectorSize==0 ){
42501 u32 f = 0;
42505 if( res==0 && (f & F2FS_FEATURE_ATOMIC_WRITE) ){
42522 if( pFile->sectorSize == 0 ){
42527 pFile->deviceCharacteristics = 0;
42540 0;
42550 0;
42559 0;
42567 0;
42575 0;
42581 0;
42586 if( pFile->sectorSize % 512 != 0 ){
42587 pFile->deviceCharacteristics = 0;
42628 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
42646 #endif /* !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 */
42675 ** Either unixShmNode.pShmMutex must be held or unixShmNode.nRef==0 and
42681 ** SQLITE_SHM_NLOCK slots. If the aLock[] entry is set to 0, then no
42751 ** such transactions, or 0 otherwise. If an error occurs, return an
42757 *piOut = 0;
42762 memset(&f, 0, sizeof(f));
42769 if( osFcntl(pShmNode->hShm, F_GETLK, &f)<0 ){
42801 assert( pShmNode->nRef>=0 );
42806 assert( pShmNode->nRef>0 || unixMutexHeld() );
42807 assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->pShmMutex) );
42816 assert( pShmNode->nRef>0 );
42827 if( pShmNode->hShm>=0 ){
42883 assert( ((pgsz-1)&pgsz)==0 ); /* Page size must be a power of 2 */
42889 ** Purge the unixShmNodeList list of all entries with unixShmNode.nRef==0.
42897 if( p && ALWAYS(p->nRef==0) ){
42903 for(i=0; i<SQLITE_SHM_NLOCK; i++){
42907 for(i=0; i<p->nRegion; i+=nShmPerMap){
42908 if( p->hShm>=0 ){
42915 if( p->hShm>=0 ){
42919 p->pInode->pShmNode = 0;
42959 if( osFcntl(pShmNode->hShm, F_GETLK, &lock)!=0 ) {
42974 pDbFd->iBusyTimeout = 0;
42982 ** -shm header size) rather than 0 as a system debugging aid, to
43036 struct unixShm *p = 0; /* The connection to be opened */
43045 if( p==0 ) return SQLITE_NOMEM_BKPT;
43046 memset(p, 0, sizeof(*p));
43047 assert( pDbFd->pShm==0 );
43056 if( pShmNode==0 ){
43077 if( pShmNode==0 ){
43081 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
43096 if( pShmNode->pShmMutex==0 ){
43103 for(ii=0; ii<SQLITE_SHM_NLOCK; ii++){
43105 if( pShmNode->aMutex[ii]==0 ){
43114 if( pInode->bProcessLock==0 ){
43115 if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
43119 if( pShmNode->hShm<0 ){
43122 if( pShmNode->hShm<0 ){
43178 ** Otherwise, if the bExtend parameter is 0 and the requested shared-memory
43204 if( pDbFd->pShm==0 ){
43215 pShmNode->isUnlocked = 0;
43217 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
43219 assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 );
43220 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
43232 if( pShmNode->hShm>=0 ){
43262 assert( (nByte % pgsz)==0 );
43264 int x = 0;
43288 if( pShmNode->hShm>=0 ){
43289 pMem = osMmap(0, nMap,
43299 if( pMem==0 ){
43303 memset(pMem, 0, nMap);
43306 for(i=0; i<nShmPerMap; i++){
43317 *pp = 0;
43339 memset(aLock, 0, sizeof(aLock));
43342 for(i=0; i<SQLITE_SHM_NLOCK; i++){
43344 assert( aLock[i]==0 );
43347 assert( aLock[i]>=0 );
43353 assert( 0==memcmp(pShmNode->aLock, aLock, sizeof(aLock)) );
43354 return (memcmp(pShmNode->aLock, aLock, sizeof(aLock))==0);
43381 if( p==0 ) return SQLITE_IOERR_SHMLOCK;
43383 if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
43388 assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
43394 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
43395 assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 );
43396 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
43402 ** 2. Write lock (ofst==0).
43414 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
43416 && (ofst!=1 || lockMask==0 || lockMask==2)
43417 && (ofst!=0 || lockMask<3)
43433 || 0==(p->exclMask & mask)
43436 || (flags==(SQLITE_SHM_SHARED|SQLITE_SHM_LOCK) && 0==(p->sharedMask & mask))
43473 assert( (p->exclMask & p->sharedMask)==0 );
43479 ** this case, set bUnlock to 0 so that the posix lock is not removed
43485 bUnlock = 0;
43494 memset(&aLock[ofst], 0, sizeof(int)*n);
43502 if( aLock[ofst]<0 ){
43505 }else if( aLock[ofst]==0 ){
43519 assert( (p->sharedMask & mask)==0 );
43520 assert( (p->exclMask & mask)==0 );
43558 p->id, osGetpid(0), p->sharedMask, p->exclMask));
43598 if( p==0 ) return SQLITE_OK;
43612 pDbFd->pShm = 0;
43615 /* If pShmNode->nRef has reached 0, then close the underlying
43619 assert( pShmNode->nRef>0 );
43621 if( pShmNode->nRef==0 ){
43622 if( deleteFlag && pShmNode->hShm>=0 ){
43634 # define unixShmMap 0
43635 # define unixShmLock 0
43636 # define unixShmBarrier 0
43637 # define unixShmUnmap 0
43640 #if SQLITE_MAX_MMAP_SIZE>0
43645 assert( pFd->nFetchOut==0 );
43648 pFd->pMapRegion = 0;
43649 pFd->mmapSize = 0;
43650 pFd->mmapSizeActual = 0;
43677 u8 *pNew = 0; /* Location of new mapping */
43680 assert( pFd->nFetchOut==0 );
43683 assert( nNew>0 );
43685 assert( MAP_FAILED!=0 );
43688 if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
43713 pNew = 0;
43721 if( pNew==MAP_FAILED || pNew==0 ){
43727 if( pNew==0 ){
43728 pNew = osMmap(0, nNew, flags, MAP_SHARED, h, 0);
43732 pNew = 0;
43733 nNew = 0;
43739 pFd->mmapSizeMax = 0;
43762 assert( nMap>=0 || pFd->nFetchOut==0 );
43763 assert( nMap>0 || (pFd->mmapSize==0 && pFd->pMapRegion==0) );
43764 if( pFd->nFetchOut>0 ) return SQLITE_OK;
43766 if( nMap<0 ){
43777 assert( nMap>0 || (pFd->mmapSize==0 && pFd->pMapRegion==0) );
43784 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
43791 ** Or, if one cannot but no error occurs, set *pp to 0 and return SQLITE_OK.
43799 #if SQLITE_MAX_MMAP_SIZE>0
43802 *pp = 0;
43804 #if SQLITE_MAX_MMAP_SIZE>0
43805 if( pFd->mmapSizeMax>0 ){
43811 if( pFd->pMapRegion==0 ){
43835 #if SQLITE_MAX_MMAP_SIZE>0
43839 /* If p==0 (unmap the entire file) then there must be no outstanding
43840 ** xFetch references. Or, if p!=0 (meaning it is an xFetch reference),
43842 assert( (p==0)==(pFd->nFetchOut==0) );
43844 /* If p!=0, it must match the iOff value. */
43845 assert( p==0 || p==&((u8 *)pFd->pMapRegion)[iOff] );
43853 assert( pFd->nFetchOut>=0 );
43954 0 /* xShmMap method */
43964 0 /* xShmMap method */
43976 0 /* xShmMap method */
43989 0 /* xShmMap method */
44002 0 /* xShmMap method */
44028 0 /* xShmMap method */
44042 0 /* xShmMap method */
44067 { 0, 0 }
44082 for(i=0; aMap[i].zFilesystem; i++){
44083 if( strcmp(fsInfo.f_fstypename, aMap[i].zFilesystem)==0 ){
44094 lockInfo.l_start = 0;
44098 if( strcmp(fsInfo.f_fstypename, "nfs")==0 ){
44134 lockInfo.l_start = 0;
44178 assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 );
44185 #if SQLITE_MAX_MMAP_SIZE>0
44188 if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0),
44192 if( strcmp(pVfs->zName,"unix-excl")==0 ){
44198 if( pNew->pId==0 ){
44255 if( pCtx==0 ){
44262 pCtx->reserved = 0;
44282 assert( zFilename!=0 );
44285 if( zLockFile==0 ){
44310 pNew->pInode->aSemName[0] = '\0';
44317 storeLastErrno(pNew, 0);
44320 if( h>=0 ) robust_close(pNew, h, __LINE__);
44327 if( h>=0 ) robust_close(pNew, h, __LINE__);
44340 0,
44341 0,
44352 azTempDirs[0] = getenv("SQLITE_TMPDIR");
44361 unsigned int i = 0;
44366 if( zDir!=0
44367 && osStat(zDir, &buf)==0
44369 && osAccess(zDir, 03)==0
44373 if( i>=sizeof(azTempDirs)/sizeof(azTempDirs[0]) ) break;
44376 return 0;
44386 int iLimit = 0;
44393 zBuf[0] = 0;
44398 if( zDir==0 ){
44405 zBuf[nBuf-2] = 0;
44407 zDir, r, 0);
44408 if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ){
44412 }while( osAccess(zBuf,0)==0 );
44444 UnixUnusedFd *pUnused = 0;
44464 if( inodeList!=0 && 0==osStat(zPath, &sStat) ){
44501 if( 0==osStat(zFile, &sStat) ){
44518 ** In most cases, this routine sets *pMode to 0, which will become
44540 *pMode = 0;
44541 *pUid = 0;
44542 *pGid = 0;
44563 ** the filename. In that case, just return SQLITE_OK with *pMode==0.
44566 while( nDb>0 && zPath[nDb]!='.' ){
44569 zDb[nDb] = '\0';
44621 int openFlags = 0; /* Flags to pass to open() */
44622 int eType = flags&0x0FFF00; /* Type of file to open */
44625 int ctrlFlags = 0; /* UNIXFILE_* flags */
44662 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
44663 assert(isCreate==0 || isReadWrite);
44664 assert(isExclusive==0 || isCreate);
44665 assert(isDelete==0 || isCreate);
44686 if( randomnessPid!=osGetpid(0) ){
44687 randomnessPid = osGetpid(0);
44688 sqlite3_randomness(0,0);
44690 memset(p, 0, sizeof(unixFile));
44694 assert( zName==0 );
44713 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 );
44726 assert( zName[strlen(zName)+1]==0 );
44739 if( fd<0 ){
44750 OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
44751 assert( !isExclusive || (openFlags & O_CREAT)!=0 );
44752 if( fd<0 ){
44759 UnixUnusedFd *pReadonly = 0;
44774 if( fd<0 ){
44788 ** If openMode==0, then that means uid and gid are not set correctly
44792 if( openMode && (flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL))!=0 ){
44796 assert( fd>=0 );
44812 if( zPath==0 ){
44832 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) {
44835 if (0 == strncmp("exfat", fsInfo.f_fstypename, 5)) {
44854 int useProxy = 0;
44856 /* SQLITE_FORCE_PROXY_LOCKING==1 means force always use proxy, 0 means
44859 useProxy = atoi(envforce)>0;
44881 assert( zPath==0 || zPath[0]=='/'
44909 || osAccess(zPath,0)!=0
44919 if( (dirSync & 1)!=0 ){
44923 if( full_fsync(fd,0,0) ){
44926 robust_close(0, fd, __LINE__);
44944 ** Otherwise return 0.
44954 assert( pResOut!=0 );
44962 *pResOut = 0==osStat(zPath, &buf) &&
44963 (!S_ISREG(buf.st_mode) || buf.st_size>0);
44965 *pResOut = osAccess(zPath, W_OK|R_OK)==0;
44993 assert( nName>0 );
44994 assert( zName!=0 );
44995 if( zName[0]=='.' ){
44999 assert( pPath->zOut[0]=='/' );
45016 pPath->zOut[pPath->nUsed] = 0;
45018 if( osLstat(zIn, &buf)!=0 ){
45030 if( got<=0 || got>=(ssize_t)sizeof(zLnk)-2 ){
45034 zLnk[got] = 0;
45035 if( zLnk[0]=='/' ){
45036 pPath->nUsed = 0;
45053 int i = 0;
45054 int j = 0;
45081 path.rc = 0;
45082 path.nUsed = 0;
45083 path.nSymlink = 0;
45086 if( zPath[0]!='/' ){
45088 if( osGetcwd(zPwd, sizeof(zPwd)-2)==0 ){
45094 zOut[path.nUsed] = 0;
45156 #define unixDlOpen 0
45157 #define unixDlError 0
45158 #define unixDlSym 0
45159 #define unixDlClose 0
45181 memset(zBuf, 0, nBuf);
45182 randomnessPid = osGetpid(0);
45186 fd = robust_open("/dev/urandom", O_RDONLY, 0);
45187 if( fd<0 ){
45195 do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR );
45196 robust_close(0, fd, __LINE__);
45213 #if !defined(HAVE_NANOSLEEP) || HAVE_NANOSLEEP+0
45220 ** -DHAVE_NANOSLEEP=0 (perhaps in conjuction with -DHAVE_USLEEP if
45245 SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
45271 (void)gettimeofday(&sNow, 0); /* Cannot fail given valid arguments */
45288 ** return 0. Return 1 if the time and date cannot be found.
45291 sqlite3_int64 i = 0;
45294 rc = unixCurrentTimeInt64(0, &i);
45299 # define unixCurrentTime 0
45344 ** PENDING_BYTE 0x40000000
45345 ** RESERVED_BYTE 0x40000001
45346 ** SHARED_RANGE 0x40000002 -> 0x40000200
45464 ** force proxy locking to be used for every database file opened, and 0
45509 lPath, errno, osGetpid(0)));
45525 for( i=0; i<dbLen && (i+len+7)<(int)maxLen; i++){
45529 lPath[i+len]='\0';
45531 OSTRACE(("GETLOCKPATH proxy lock path=%s pid=%d\n", lPath, osGetpid(0)));
45541 int start = 0;
45546 buf[0] = lockPath[0];
45548 if( lockPath[i] == '/' && (i - start > 0) ){
45552 buf[i]='\0';
45558 buf, strerror(err), lockPath, osGetpid(0)));
45567 OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n",lockPath,osGetpid(0)));
45568 return 0;
45588 int terrno = 0;
45606 if( fd<0 ){
45607 fd = robust_open(path, openFlags, 0);
45609 if( fd<0 && errno==ENOENT && islockfile ){
45611 fd = robust_open(path, openFlags, 0);
45615 if( fd<0 ){
45617 fd = robust_open(path, openFlags, 0);
45620 if( fd<0 ){
45639 memset(pNew, 0, sizeof(unixFile));
45641 memset(&dummyVfs, 0, sizeof(dummyVfs));
45648 rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0);
45662 SQLITE_API int sqlite3_hostid_num = 0;
45677 memset(pHostID, 0, PROXY_HOSTIDLEN);
45680 struct timespec timeout = {1, 0}; /* 1 sec timeout */
45694 if( sqlite3_hostid_num != 0){
45695 pHostID[0] = (char)(pHostID[0] + (char)(sqlite3_hostid_num & 0xFF));
45721 size_t readLen = 0;
45722 size_t pathLen = 0;
45736 readLen = osPread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0);
45742 fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW), 0);
45743 if( fd<0 ){
45747 if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
45755 rc = 0;
45763 if( fd>=0 ){
45779 int nTries = 0;
45782 memset(&conchModTime, 0, sizeof(conchModTime));
45801 unixSleep(0,500000); /* wait 0.5 sec and try the lock again*/
45813 int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0);
45814 if( len<0 ){
45818 if( len>PROXY_PATHINDEX && tBuf[0]==(char)PROXY_CONCHVERSION){
45820 if( 0!=memcmp(&tBuf[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN) ){
45827 unixSleep(0,10000000); /* wait 10 sec and try the lock again */
45832 if( 0==proxyBreakConchLock(pFile, myHostID) ){
45856 if( pCtx->conchHeld!=0 ){
45861 int pError = 0;
45866 int createConch = 0;
45867 int hostIdMatch = 0;
45868 int readLen = 0;
45869 int tryOldLockPath = 0;
45870 int forceNewLockPath = 0;
45874 osGetpid(0)));
45877 if( (rc&0xff)==SQLITE_IOERR ){
45886 readLen = seekAndRead((unixFile*)conchFile, 0, readBuf, PROXY_MAXCONCHLEN);
45887 if( readLen<0 ){
45893 readBuf[0]!=(char)PROXY_CONCHVERSION ){
45920 lockPath[pathLen] = 0;
45936 if( (conchFile->openFlags&O_RDWR) == 0 ){
45966 int writeSize = 0;
45968 writeBuffer[0] = (char)PROXY_CONCHVERSION;
45978 rc = unixWrite((sqlite3_file *)conchFile, writeBuffer, writeSize, 0);
45979 full_fsync(conchFile->h,0,0);
45986 if( err==0 ){
45996 if( rc!=0 ){
46017 if( pFile->h>=0 ){
46021 fd = robust_open(pCtx->dbPath, pFile->openFlags, 0);
46023 if( fd>=0 ){
46038 tryOldLockPath = 0;
46047 pCtx->lockProxyPath = sqlite3DbStrDup(0, tempLockPath);
46084 osGetpid(0)));
46085 if( pCtx->conchHeld>0 ){
46088 pCtx->conchHeld = 0;
46113 if( conchPath==0 ){
46119 for( i=(len-1); i>=0; i-- ){
46152 if( !path || path[0]=='\0' || !strcmp(path, ":auto:") ||
46158 pCtx->conchHeld = 0;
46165 pCtx->lockProxyPath = sqlite3DbStrDup(0, path);
46219 if( !path || path[0]=='\0' || !strcmp(path, ":auto:") ){
46226 (lockPath ? lockPath : ":auto:"), osGetpid(0)));
46229 if( pCtx==0 ){
46232 memset(pCtx, 0, sizeof(*pCtx));
46236 rc = proxyCreateUnixFile(pCtx->conchFilePath, &pCtx->conchFile, 0);
46237 if( rc==SQLITE_CANTOPEN && ((pFile->openFlags&O_RDWR) == 0) ){
46240 ** Ugh, since O_RDONLY==0x0000 we test for !O_RDWR since unixOpen asserts
46245 int goLockless = 0;
46260 pCtx->lockProxyPath = sqlite3DbStrDup(0, lockPath);
46264 pCtx->dbPath = sqlite3DbStrDup(0, dbPath);
46282 sqlite3DbFree(0, pCtx->lockProxyPath);
46317 if( pArg==NULL || (const char *)pArg==0 ){
46349 assert( 0 ); /* The call assures that only valid opcodes are sent */
46352 /*NOTREACHED*/ assert(0);
46374 if( pCtx->conchHeld>0 ){
46377 }else{ /* conchHeld < 0 is lockless */
46378 pResOut=0;
46413 if( pCtx->conchHeld>0 ){
46418 /* conchHeld < 0 is lockless */
46437 if( pCtx->conchHeld>0 ){
46442 /* conchHeld < 0 is lockless */
46465 pCtx->lockProxy = 0;
46476 sqlite3DbFree(0, pCtx->lockProxyPath);
46478 sqlite3DbFree(0, pCtx->dbPath);
46538 0, /* pNext */ \
46599 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
46602 0==strcmp(aVfs[i].zName,SQLITE_DEFAULT_UNIX_VFS));
46604 sqlite3_vfs_register(&aVfs[i], i==0);
46620 ** READ-0 UNIX_SHM_BASE+3 123
46644 unixBigLock = 0;
46688 #if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0
46690 compile with SQLITE_MAX_MMAP_SIZE=0."
46723 # define NTDDI_WIN8 0x06020000
46727 # define NTDDI_WINBLUE 0x06030000
46731 # define NTDDI_WINTHRESHOLD 0x06040000
46740 # define SQLITE_WIN32_GETVERSIONEX 0 /* GetVersionEx() is deprecated */
46753 # define SQLITE_WIN32_CREATEFILEMAPPINGA 0
46843 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
46883 # define FILE_FLAG_MASK (0xFF3C0000)
46887 # define FILE_ATTRIBUTE_MASK (0x0003FFF7)
46934 #if SQLITE_MAX_MMAP_SIZE>0
46957 #define WINFILE_RDONLY 0x02 /* Connection is read only */
46958 #define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */
46959 #define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
47024 # if SQLITE_DEFAULT_CACHE_SIZE>=0
47054 # define SQLITE_WIN32_HEAP_MAX_SIZE (0)
47062 # define SQLITE_WIN32_HEAP_FLAGS (0)
47083 #define WINMEM_MAGIC1 0x42b2830b
47084 #define WINMEM_MAGIC2 0xbd4d7cf4
47125 ** 0: Operating system unknown.
47133 SQLITE_API LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0;
47135 static LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0;
47162 { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 },
47164 { "AreFileApisANSI", (SYSCALL)0, 0 },
47168 #define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent)
47172 { "CharLowerW", (SYSCALL)CharLowerW, 0 },
47174 { "CharLowerW", (SYSCALL)0, 0 },
47180 { "CharUpperW", (SYSCALL)CharUpperW, 0 },
47182 { "CharUpperW", (SYSCALL)0, 0 },
47187 { "CloseHandle", (SYSCALL)CloseHandle, 0 },
47192 { "CreateFileA", (SYSCALL)CreateFileA, 0 },
47194 { "CreateFileA", (SYSCALL)0, 0 },
47201 { "CreateFileW", (SYSCALL)CreateFileW, 0 },
47203 { "CreateFileW", (SYSCALL)0, 0 },
47210 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) && \
47212 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
47214 { "CreateFileMappingA", (SYSCALL)0, 0 },
47221 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
47222 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
47224 { "CreateFileMappingW", (SYSCALL)0, 0 },
47231 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 },
47233 { "CreateMutexW", (SYSCALL)0, 0 },
47240 { "DeleteFileA", (SYSCALL)DeleteFileA, 0 },
47242 { "DeleteFileA", (SYSCALL)0, 0 },
47248 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
47250 { "DeleteFileW", (SYSCALL)0, 0 },
47256 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
47258 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
47265 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
47267 { "FileTimeToSystemTime", (SYSCALL)0, 0 },
47273 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
47278 { "FormatMessageA", (SYSCALL)FormatMessageA, 0 },
47280 { "FormatMessageA", (SYSCALL)0, 0 },
47287 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
47289 { "FormatMessageW", (SYSCALL)0, 0 },
47296 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
47298 { "FreeLibrary", (SYSCALL)0, 0 },
47303 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
47308 { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 },
47310 { "GetDiskFreeSpaceA", (SYSCALL)0, 0 },
47317 { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 },
47319 { "GetDiskFreeSpaceW", (SYSCALL)0, 0 },
47326 { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 },
47328 { "GetFileAttributesA", (SYSCALL)0, 0 },
47334 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
47336 { "GetFileAttributesW", (SYSCALL)0, 0 },
47342 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
47344 { "GetFileAttributesExW", (SYSCALL)0, 0 },
47351 { "GetFileSize", (SYSCALL)GetFileSize, 0 },
47353 { "GetFileSize", (SYSCALL)0, 0 },
47359 { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 },
47361 { "GetFullPathNameA", (SYSCALL)0, 0 },
47368 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
47370 { "GetFullPathNameW", (SYSCALL)0, 0 },
47376 { "GetLastError", (SYSCALL)GetLastError, 0 },
47383 { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 },
47387 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
47390 { "GetProcAddressA", (SYSCALL)0, 0 },
47397 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
47399 { "GetSystemInfo", (SYSCALL)0, 0 },
47404 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
47409 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
47411 { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 },
47418 { "GetTempPathA", (SYSCALL)GetTempPathA, 0 },
47420 { "GetTempPathA", (SYSCALL)0, 0 },
47426 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
47428 { "GetTempPathW", (SYSCALL)0, 0 },
47434 { "GetTickCount", (SYSCALL)GetTickCount, 0 },
47436 { "GetTickCount", (SYSCALL)0, 0 },
47442 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
47444 { "GetVersionExA", (SYSCALL)0, 0 },
47452 { "GetVersionExW", (SYSCALL)GetVersionExW, 0 },
47454 { "GetVersionExW", (SYSCALL)0, 0 },
47460 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
47466 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
47468 { "HeapCreate", (SYSCALL)0, 0 },
47475 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
47477 { "HeapDestroy", (SYSCALL)0, 0 },
47482 { "HeapFree", (SYSCALL)HeapFree, 0 },
47486 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
47491 { "HeapSize", (SYSCALL)HeapSize, 0 },
47497 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
47499 { "HeapValidate", (SYSCALL)0, 0 },
47506 { "HeapCompact", (SYSCALL)HeapCompact, 0 },
47508 { "HeapCompact", (SYSCALL)0, 0 },
47514 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
47516 { "LoadLibraryA", (SYSCALL)0, 0 },
47523 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
47525 { "LoadLibraryW", (SYSCALL)0, 0 },
47531 { "LocalFree", (SYSCALL)LocalFree, 0 },
47533 { "LocalFree", (SYSCALL)0, 0 },
47539 { "LockFile", (SYSCALL)LockFile, 0 },
47541 { "LockFile", (SYSCALL)0, 0 },
47550 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
47552 { "LockFileEx", (SYSCALL)0, 0 },
47561 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
47562 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
47564 { "MapViewOfFile", (SYSCALL)0, 0 },
47570 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
47575 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
47580 { "ReadFile", (SYSCALL)ReadFile, 0 },
47585 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
47590 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
47592 { "SetFilePointer", (SYSCALL)0, 0 },
47599 { "Sleep", (SYSCALL)Sleep, 0 },
47601 { "Sleep", (SYSCALL)0, 0 },
47606 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
47612 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
47614 { "UnlockFile", (SYSCALL)0, 0 },
47623 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
47625 { "UnlockFileEx", (SYSCALL)0, 0 },
47631 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
47632 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
47634 { "UnmapViewOfFile", (SYSCALL)0, 0 },
47639 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
47644 { "WriteFile", (SYSCALL)WriteFile, 0 },
47650 { "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
47652 { "CreateEventExW", (SYSCALL)0, 0 },
47659 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
47661 { "WaitForSingleObject", (SYSCALL)0, 0 },
47668 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
47670 { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
47677 { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
47679 { "SetFilePointerEx", (SYSCALL)0, 0 },
47686 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
47688 { "GetFileInformationByHandleEx", (SYSCALL)0, 0 },
47694 #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
47695 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
47697 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
47704 { "CreateFile2", (SYSCALL)CreateFile2, 0 },
47706 { "CreateFile2", (SYSCALL)0, 0 },
47713 { "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
47715 { "LoadPackagedLibrary", (SYSCALL)0, 0 },
47722 { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
47724 { "GetTickCount64", (SYSCALL)0, 0 },
47730 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
47732 { "GetNativeSystemInfo", (SYSCALL)0, 0 },
47739 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
47741 { "OutputDebugStringA", (SYSCALL)0, 0 },
47747 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
47749 { "OutputDebugStringW", (SYSCALL)0, 0 },
47754 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
47758 #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
47759 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
47761 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
47773 { "InterlockedCompareExchange", (SYSCALL)0, 0 },
47777 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
47784 { "UuidCreate", (SYSCALL)UuidCreate, 0 },
47786 { "UuidCreate", (SYSCALL)0, 0 },
47792 { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
47794 { "UuidCreateSequential", (SYSCALL)0, 0 },
47800 #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
47801 { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
47803 { "FlushViewOfFile", (SYSCALL)0, 0 },
47826 if( zName==0 ){
47831 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
47840 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
47841 if( strcmp(zName, aSyscall[i].zName)==0 ){
47842 if( aSyscall[i].pDefault==0 ){
47846 if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault;
47867 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
47868 if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent;
47870 return 0;
47884 for(i=0; i<ArraySize(aSyscall)-1; i++){
47885 if( strcmp(zName, aSyscall[i].zName)==0 ) break;
47889 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName;
47891 return 0;
47904 UINT nLargest = 0;
47909 assert( hHeap!=0 );
47915 if( (nLargest=osHeapCompact(hHeap, SQLITE_WIN32_HEAP_FLAGS))==0 ){
47951 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
47961 assert( sqlite3_memory_used()==0 );
47965 assert( sqlite3_memory_used()==0 );
47969 assert( rc!=SQLITE_OK || sqlite3_memory_used()==0 );
47991 assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE );
47999 if( nMin>0 ){
48000 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
48007 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
48009 osAreFileApisANSI() ? CP_ACP : CP_OEMCP, 0, zBuf,
48010 nMin, (LPWSTR)zDbgBuf, SQLITE_WIN32_DBG_BUF_SIZE/sizeof(WCHAR))<=0 ){
48015 if( nMin>0 ){
48016 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
48046 #if SQLITE_MAX_WORKER_THREADS>0 && !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
48047 SQLITE_THREADSAFE>0
48073 # define osIsNT() (0)
48090 if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){
48096 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
48102 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
48127 assert( hHeap!=0 );
48132 assert( nBytes>=0 );
48149 assert( hHeap!=0 );
48170 assert( hHeap!=0 );
48175 assert( nBytes>=0 );
48198 assert( hHeap!=0 );
48203 if( !p ) return 0;
48208 return 0;
48234 if( dwMaximumSize==0 ){
48261 assert( pWinMemData->hHeap!=0 );
48331 nChar = osMultiByteToWideChar(CP_UTF8, 0, zText, -1, NULL, 0);
48332 if( nChar==0 ){
48333 return 0;
48336 if( zWideText==0 ){
48337 return 0;
48339 nChar = osMultiByteToWideChar(CP_UTF8, 0, zText, -1, zWideText,
48341 if( nChar==0 ){
48343 zWideText = 0;
48357 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideText, -1, 0, 0, 0, 0);
48358 if( nByte == 0 ){
48359 return 0;
48362 if( zText==0 ){
48363 return 0;
48365 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideText, -1, zText, nByte,
48366 0, 0);
48367 if( nByte == 0 ){
48369 zText = 0;
48385 nByte = osMultiByteToWideChar(codepage, 0, zText, -1, NULL,
48386 0)*sizeof(WCHAR);
48387 if( nByte==0 ){
48388 return 0;
48391 if( zMbcsText==0 ){
48392 return 0;
48394 nByte = osMultiByteToWideChar(codepage, 0, zText, -1, zMbcsText,
48396 if( nByte==0 ){
48398 zMbcsText = 0;
48414 nByte = osWideCharToMultiByte(codepage, 0, zWideText, -1, 0, 0, 0, 0);
48415 if( nByte == 0 ){
48416 return 0;
48419 if( zText==0 ){
48420 return 0;
48422 nByte = osWideCharToMultiByte(codepage, 0, zWideText, -1, zText,
48423 nByte, 0, 0);
48424 if( nByte == 0 ){
48426 zText = 0;
48441 if( zTmpWide==0 ){
48442 return 0;
48459 if( zTmpWide==0 ){
48460 return 0;
48474 return 0;
48478 if( sqlite3_initialize() ) return 0;
48490 return 0;
48494 if( sqlite3_initialize() ) return 0;
48506 return 0;
48510 if( sqlite3_initialize() ) return 0;
48522 return 0;
48526 if( sqlite3_initialize() ) return 0;
48538 return 0;
48542 if( sqlite3_initialize() ) return 0;
48554 return 0;
48558 if( sqlite3_initialize() ) return 0;
48571 char **ppDirectory = 0;
48588 char *zCopy = 0;
48589 if( zValue && zValue[0] ){
48591 if ( zCopy==0 ){
48616 char *zUtf8 = 0;
48619 if( zUtf8==0 ) return SQLITE_NOMEM_BKPT;
48646 /* FormatMessage returns 0 on failure. Otherwise it
48650 DWORD dwLen = 0;
48651 char *zOut = 0;
48660 0,
48663 0);
48671 0,
48673 0,
48674 0);
48676 if( dwLen > 0 ){
48695 0,
48697 0,
48698 0);
48699 if( dwLen > 0 ){
48709 if( 0 == dwLen ){
48710 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%lx (%lu)", lastErrno, lastErrno);
48717 return 0;
48746 zMsg[0] = 0;
48749 if( zPath==0 ) zPath = "";
48750 for(i=0; zMsg[i] && zMsg[i]!='\r' && zMsg[i]!='\n'; i++){}
48751 zMsg[i] = 0;
48812 return 0;
48829 return 0;
48863 uTm.dwLowDateTime = (DWORD)(t64 & 0xFFFFFFFF);
48910 if( zName==0 ){
48916 memset(&pFile->local, 0, sizeof(pFile->local));
48943 PAGE_READWRITE, 0, sizeof(winceLock),
48958 FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock));
48986 memset(pFile->shared, 0, sizeof(winceLock));
49049 if (pFile->shared->nReaders == 0 && pFile->shared->bExclusive == 0){
49059 if (pFile->shared->bExclusive == 0){
49072 if (pFile->shared->bPending == 0) {
49082 if (pFile->shared->bReserved == 0) {
49127 if (pFile->local.nReaders == 0)
49183 memset(&ovlp, 0, sizeof(OVERLAPPED));
49186 return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp);
49214 memset(&ovlp, 0, sizeof(OVERLAPPED));
49217 return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp);
49239 ** argument to offset iOffset within the file. If successful, return 0.
49251 upperBits = (LONG)((iOffset>>32) & 0x7fffffff);
49252 lowerBits = (LONG)(iOffset & 0xffffffff);
49273 return 0;
49283 bRet = osSetFilePointerEx(pFile->h, x, 0, FILE_BEGIN);
49294 return 0;
49298 #if SQLITE_MAX_MMAP_SIZE>0
49316 int rc, cnt = 0;
49319 assert( id!=0 );
49321 assert( pFile->pShm==0 );
49327 #if SQLITE_MAX_MMAP_SIZE>0
49333 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
49334 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
49344 int cnt = 0;
49346 osDeleteFileW(pFile->zDeleteOnClose)==0
49347 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff
49382 int nRetry = 0; /* Number of retrys */
49384 assert( id!=0 );
49385 assert( amt>0 );
49386 assert( offset>=0 );
49392 #if SQLITE_MAX_MMAP_SIZE>0
49417 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
49419 memset(&overlapped, 0, sizeof(OVERLAPPED));
49420 overlapped.Offset = (LONG)(offset & 0xffffffff);
49421 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
49436 memset(&((char*)pBuf)[nRead], 0, amt-nRead);
49457 int rc = 0; /* True if error has occurred, else false */
49459 int nRetry = 0; /* Number of retries */
49461 assert( amt>0 );
49470 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0
49491 if( rc==0 ){
49504 memset(&overlapped, 0, sizeof(OVERLAPPED));
49505 overlapped.Offset = (LONG)(offset & 0xffffffff);
49506 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
49509 while( nRem>0 ){
49511 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
49518 assert( nWrite==0 || nWrite<=(DWORD)nRem );
49519 if( nWrite==0 || nWrite>(DWORD)nRem ){
49525 overlapped.Offset = (LONG)(offset & 0xffffffff);
49526 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
49531 if( nRem>0 ){
49564 #if SQLITE_MAX_MMAP_SIZE>0
49566 if( pFile->nFetchOut>0 ){
49598 if( pFile->szChunk>0 ){
49602 #if SQLITE_MAX_MMAP_SIZE>0
49606 oldMmapSize = 0;
49615 }else if( 0==osSetEndOfFile(pFile->h) &&
49622 #if SQLITE_MAX_MMAP_SIZE>0
49623 if( rc==SQLITE_OK && oldMmapSize>0 ){
49642 SQLITE_API int sqlite3_sync_count = 0;
49643 SQLITE_API int sqlite3_fullsync_count = 0;
49669 assert((flags&0x0F)==SQLITE_SYNC_NORMAL
49670 || (flags&0x0F)==SQLITE_SYNC_FULL
49685 if( (flags&0x0F)==SQLITE_SYNC_FULL ){
49699 #if SQLITE_MAX_MMAP_SIZE>0
49701 if( osFlushViewOfFile(pFile->pMapRegion, 0) ){
49738 assert( id!=0 );
49739 assert( pSize!=0 );
49821 res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
49823 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
49824 SHARED_SIZE, 0);
49831 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
49833 SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
49836 if( res == 0 ){
49852 res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
49856 res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
49859 if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
49890 ** erases all locks at once and returns us immediately to locking level 0.
49892 ** must go straight to locking level 0.
49898 int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */
49902 assert( id!=0 );
49917 if( (pFile->ctrlFlags & WINFILE_RDONLY)!=0 && locktype>=RESERVED_LOCK ){
49936 while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
49937 PENDING_BYTE, 0, 1, 0))==0 ){
49978 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
49990 gotPendingLock = 0;
49998 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
49999 SHARED_SIZE, 0);
50012 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
50044 assert( id!=0 );
50049 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0);
50051 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
50077 assert( pFile!=0 );
50083 winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
50092 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
50098 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
50146 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
50148 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
50151 if( *pArg<0 ){
50152 *pArg = (pFile->ctrlFlags & mask)!=0;
50153 }else if( (*pArg)==0 ){
50189 if( pFile->szChunk>0 ){
50197 SimulateIOErrorBenign(0);
50223 if( a[0]>0 ){
50224 winIoerrRetry = a[0];
50226 a[0] = winIoerrRetry;
50228 if( a[1]>0 ){
50254 char *zTFile = 0;
50262 #if SQLITE_MAX_MMAP_SIZE>0
50273 if( newLimit>0 && sizeof(SIZE_T)<8 ){
50274 newLimit = (newLimit & 0x7FFFFFFF);
50278 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
50280 if( pFile->mmapSize>0 ){
50315 ((p->ctrlFlags & WINFILE_PSOW)?SQLITE_IOCAP_POWERSAFE_OVERWRITE:0);
50341 static sqlite3_mutex *winBigLock = 0;
50372 ** Either winShmNode.mutex must be held or winShmNode.nRef==0 and
50406 static winShmNode *winShmNodeList = 0;
50450 int rc = 0; /* Result code form Lock/UnlockFileEx() */
50453 assert( pFile->nRef==0 || sqlite3_mutex_held(pFile->mutex) );
50460 rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0);
50465 rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
50468 if( rc!= 0 ){
50487 ** Purge the winShmNodeList list of all entries with winShmNode.nRef==0.
50499 while( (p = *pp)!=0 ){
50500 if( p->nRef==0 ){
50503 for(i=0; i<p->nRegion; i++){
50516 SimulateIOErrorBenign(0);
50521 winDelete(pVfs, p->zFilename, 0);
50523 SimulateIOErrorBenign(0);
50551 }else if( winTruncate((sqlite3_file*)&pShmNode->hFile, 0) ){
50574 winShmNode *pShmNode = 0; /* The underlying mmapped file */
50579 assert( pDbFd->pShm==0 ); /* Not previously opened */
50585 if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT;
50588 if( pNew==0 ){
50604 if( sqlite3StrICmp(pShmNode->zFilename, pNew->zFilename)==0 ) break;
50610 int outFlags = 0;
50613 pNew = 0;
50620 if( pShmNode->mutex==0 ){
50626 if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
50670 winShmPurge(pDbFd->pVfs, 0); /* This call frees pShmNode if required */
50692 if( p==0 ) return SQLITE_OK;
50703 pDbFd->pShm = 0;
50706 /* If pShmNode->nRef has reached 0, then close the underlying
50709 assert( pShmNode->nRef>0 );
50711 if( pShmNode->nRef==0 ){
50735 if( p==0 ) return SQLITE_IOERR_SHMLOCK;
50737 if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
50739 assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
50745 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
50751 u16 allMask = 0; /* Mask of locks held by siblings */
50756 assert( (pX->exclMask & (p->exclMask|p->sharedMask))==0 );
50761 if( (mask & allMask)==0 ){
50773 u16 allShared = 0; /* Union of locks held by connections other than "p" */
50780 if( (pX->exclMask & mask)!=0 ){
50789 if( (allShared & mask)==0 ){
50805 if( (pX->exclMask & mask)!=0 || (pX->sharedMask & mask)!=0 ){
50817 assert( (p->sharedMask & mask)==0 );
50852 ** Otherwise, if the isWrite parameter is 0 and the requested shared-memory
50881 assert( pShm!=0 );
50889 pShmNode->isUnlocked = 0;
50891 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
50929 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
50944 void *pMap = 0; /* Mapped memory region */
50952 NULL, protect, 0, nByte, NULL
50956 NULL, protect, 0, nByte, NULL
50971 0, iOffset - iOffsetShift, szRegion + iOffsetShift
50999 *pp = 0;
51007 # define winShmMap 0
51008 # define winShmLock 0
51009 # define winShmBarrier 0
51010 # define winShmUnmap 0
51016 #if SQLITE_MAX_MMAP_SIZE>0
51018 assert( pFile!=0 );
51032 pFile->pMapRegion = 0;
51033 pFile->mmapSize = 0;
51070 assert( nMap>=0 || pFd->nFetchOut==0 );
51074 if( pFd->nFetchOut>0 ) return SQLITE_OK;
51076 if( nMap<0 ){
51089 if( nMap==0 && pFd->mmapSize>0 ){
51093 void *pNew = 0;
51099 if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){
51108 (DWORD)((nMap>>32) & 0xffffffff),
51109 (DWORD)(nMap & 0xffffffff), NULL);
51112 (DWORD)((nMap>>32) & 0xffffffff),
51113 (DWORD)(nMap & 0xffffffff), NULL);
51124 assert( (nMap % winSysInfo.dwPageSize)==0 );
51125 assert( sizeof(SIZE_T)==sizeof(sqlite3_int64) || nMap<=0xffffffff );
51127 pNew = osMapViewOfFileFromApp(pFd->hMap, flags, 0, (SIZE_T)nMap);
51129 pNew = osMapViewOfFile(pFd->hMap, flags, 0, 0, (SIZE_T)nMap);
51150 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
51157 ** Or, if one cannot but no error occurs, set *pp to 0 and return SQLITE_OK.
51165 #if SQLITE_MAX_MMAP_SIZE>0
51168 *pp = 0;
51173 #if SQLITE_MAX_MMAP_SIZE>0
51174 if( pFd->mmapSizeMax>0 ){
51180 if( pFd->pMapRegion==0 ){
51189 assert( pFd->pMapRegion!=0 );
51212 #if SQLITE_MAX_MMAP_SIZE>0
51215 /* If p==0 (unmap the entire file) then there must be no outstanding
51216 ** xFetch references. Or, if p!=0 (meaning it is an xFetch reference),
51218 assert( (p==0)==(pFd->nFetchOut==0) );
51220 /* If p!=0, it must match the iOff value. */
51221 assert( p==0 || p==&((u8 *)pFd->pMapRegion)[iOff] );
51236 assert( pFd->nFetchOut>=0 );
51304 0, /* pAppData */
51305 0 /* bNoLock */
51310 0, /* pAppData */
51328 char *zConverted = 0;
51349 void *zConverted = 0;
51370 if( nLen>0 ){
51375 zBuf[nLen+1] = '\0';
51380 return 0;
51391 if( sqlite3_temp_directory!=0 ) return 1;
51393 return 0;
51432 assert( nDir>0 );
51435 if( nDirLen>0 ){
51443 return winLogError(SQLITE_ERROR, 0, "winGetTempname1", 0);
51453 0, /* getenv("SQLITE_TMPDIR") */
51454 0, /* getenv("TMPDIR") */
51455 0, /* getenv("TMP") */
51456 0, /* getenv("TEMP") */
51457 0, /* getenv("USERPROFILE") */
51462 0 /* List terminator */
51465 const char *zDir = 0;
51467 if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
51472 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
51474 if( zDir==0 ) continue;
51502 zConverted, nMax+1)<0 ){
51539 if( osGetTempPathW(nMax, zWidePath)==0 ){
51544 "winGetTempname2", 0);
51567 if( osGetTempPathA(nMax, zMbcsPath)==0 ){
51571 "winGetTempname3", 0);
51594 return winLogError(SQLITE_ERROR, 0, "winGetTempname4", 0);
51601 ** "<temporary_directory>/etilqs_XXXXXXXXXXXXXXX\0\0"
51612 return winLogError(SQLITE_ERROR, 0, "winGetTempname5", 0);
51620 for(i=0; i<15; i++, j++){
51621 zBuf[j] += pid & 0xff;
51625 zBuf[j] = 0;
51626 zBuf[j+1] = 0;
51640 int rc = 0;
51644 int cnt = 0;
51646 memset(&sAttrData, 0, sizeof(sAttrData));
51651 return 0; /* Invalid name? */
51654 #if SQLITE_OS_WINCE==0
51681 DWORD lastErrno = 0;
51685 DWORD dwFlagsAndAttributes = 0;
51687 int isTemp = 0;
51693 int cnt = 0;
51698 char *zTmpname = 0; /* For temporary filename, if necessary. */
51702 int eType = flags&0xFFFFFF00; /* Type of file to open */
51729 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
51730 assert(isCreate==0 || isReadWrite);
51731 assert(isExclusive==0 || isCreate);
51732 assert(isDelete==0 || isCreate);
51748 assert( pFile!=0 );
51749 memset(pFile, 0, sizeof(winFile));
51777 zUtf8Name[sqlite3Strlen30(zUtf8Name)+1]==0 );
51781 if( zConverted==0 ){
51816 if( 0==sqlite3_uri_boolean(zName, "exclusive", 0) ){
51819 dwShareMode = 0;
51858 int rc2, isRO = 0;
51875 int rc2, isRO = 0;
51895 int rc2, isRO = 0;
51934 *pOutFlags : 0, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
51973 #if SQLITE_MAX_MMAP_SIZE>0
51975 pFile->pMapRegion = 0;
51976 pFile->mmapSize = 0;
52001 int cnt = 0;
52004 DWORD lastErrno = 0;
52013 if( zConverted==0 ){
52021 memset(&sAttrData, 0, sizeof(sAttrData));
52111 int rc = 0;
52112 DWORD lastErrno = 0;
52120 if( zFilename==0 ){
52121 *pResOut = 0;
52128 if( zConverted==0 ){
52133 int cnt = 0;
52135 memset(&sAttrData, 0, sizeof(sAttrData));
52144 && sAttrData.nFileSizeHigh==0
52145 && sAttrData.nFileSizeLow==0 ){
52174 (attr & FILE_ATTRIBUTE_READONLY)==0;
52192 return ( zPathname[0]=='\\' && zPathname[1]=='\\'
52203 return ( sqlite3Isalpha(zPathname[0]) && zPathname[1]==':' );
52222 if ( winIsDirSep(zPathname[0]) ){
52263 if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1)
52285 CCP_RELATIVE, zRelative, zOut, pVfs->mxPathname+1)<0 ){
52307 zRelative, zOut, pVfs->mxPathname+1)<0 ){
52363 if( zConverted==0 ){
52368 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0);
52369 if( nByte==0 ){
52375 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
52376 if( zTemp==0 ){
52380 nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
52381 if( nByte==0 ){
52394 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0);
52395 if( nByte==0 ){
52401 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
52402 if( zTemp==0 ){
52406 nByte = osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
52407 if( nByte==0 ){
52452 void *zConverted = 0;
52453 if( zFull==0 ){
52454 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
52455 return 0;
52459 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
52460 return 0;
52468 if( zConverted==0 ){
52469 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
52470 return 0;
52474 h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0);
52506 #define winDlOpen 0
52507 #define winDlError 0
52508 #define winDlSym 0
52509 #define winDlClose 0
52525 for(j=0, k=p->i; j<sz; j++){
52527 if( k>=p->na ) k = 0;
52540 memset(zBuf, 0, nBuf);
52545 memset(zBuf, 0, nBuf);
52548 e.nXor = 0;
52549 e.i = 0;
52578 memset(&id, 0, sizeof(UUID));
52581 memset(&id, 0, sizeof(UUID));
52606 SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
52660 ** return 0. Return 1 if the time and date cannot be found.
52694 ** assert(zBuf[0]=='\0');
52695 ** return 0;
52705 if( nBuf>0 ) winGetLastErrorMsg(e, nBuf, zBuf);
52717 0, /* pNext */
52742 0, /* pNext */
52767 0, /* pNext */
52792 0, /* pNext */
52819 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
52825 assert( winSysInfo.dwAllocationGranularity>0 );
52826 assert( winSysInfo.dwPageSize>0 );
52831 sqlite3_vfs_register(&winLongPathVfs, 0);
52834 sqlite3_vfs_register(&winNolockVfs, 0);
52837 sqlite3_vfs_register(&winLongPathNolockVfs, 0);
52856 winBigLock = 0;
52907 ** Shared memdb objects have .zFName!=0 and .pMutex!=0. They are created
52944 int nWrLock; /* Number of writers. (Always 0 or 1) */
53004 0, /* szOsFile (set when registered) */
53006 0, /* pNext */
53008 0, /* pAppData (set when registered) */
53010 0, /* memdbDelete, */ /* xDelete */
53019 0, /* memdbCurrentTime, */ /* xCurrentTime */
53022 0, /* xSetSystemCall */
53023 0, /* xGetSystemCall */
53024 0, /* xNextSystemCall */
53037 0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */
53039 0, /* memdbSectorSize,*/ /* xSectorSize */
53041 0, /* xShmMap */
53042 0, /* xShmLock */
53043 0, /* xShmBarrier */
53044 0, /* xShmUnmap */
53052 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE==0
53083 for(i=0; ALWAYS(i<memdb_g.nMemStore); i++){
53088 if( memdb_g.nMemStore==0 ){
53090 memdb_g.apMemStore = 0;
53101 if( p->nRef<=0 ){
53126 memset(zBuf, 0, iAmt);
53141 if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || NEVER(p->nMmap>0) ){
53150 if( pNew==0 ) return SQLITE_IOERR_NOMEM;
53181 if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz);
53240 assert( p->nWrLock==0 || p->nWrLock==1 );
53250 if( p->nWrLock>0 ){
53262 if( p->nWrLock>0 ){
53314 #if 0
53320 *pResOut = 0;
53340 if( iLimit<0 ){
53354 #if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */
53383 if( iOfst+iAmt>p->sz || (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)!=0 ){
53384 *pp = 0;
53415 MemStore *p = 0;
53419 memset(pFile, 0, sizeof(*pFile));
53421 if( szName>1 && (zName[0]=='/' || zName[0]=='\\') ){
53427 for(i=0; i<memdb_g.nMemStore; i++){
53428 if( strcmp(memdb_g.apMemStore[i]->zFName,zName)==0 ){
53433 if( p==0 ){
53436 if( p==0 ){
53441 sizeof(apNew[0])*(memdb_g.nMemStore+1) );
53442 if( apNew==0 ){
53449 memset(p, 0, sizeof(*p));
53455 if( p->pMutex==0 ){
53470 if( p==0 ){
53473 memset(p, 0, sizeof(*p));
53478 if( pOutFlags!=0 ){
53486 #if 0 /* Only used to delete rollback journals, super-journals, and WAL
53513 *pResOut = 0;
53579 #if 0 /* Never used. Modern cores only call xCurrentTimeInt64() */
53600 MemFile *p = 0;
53603 if( rc ) return 0;
53604 if( p->base.pMethods!=&memdb_io_methods ) return 0;
53607 if( pStore->zFName!=0 ) p = 0;
53625 int szPage = 0;
53626 sqlite3_stmt *pStmt = 0;
53634 return 0;
53638 if( zSchema==0 ) zSchema = db->aDb[0].zDbSName;
53642 if( iDb<0 ) return 0;
53645 assert( pStore->pMutex==0 );
53656 if( pBt==0 ) return 0;
53659 rc = zSql ? sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) : SQLITE_NOMEM;
53661 if( rc ) return 0;
53664 pOut = 0;
53666 sz = sqlite3_column_int64(pStmt, 0)*szPage;
53667 if( sz==0 ){
53669 sqlite3_exec(db, "BEGIN IMMEDIATE; COMMIT;", 0, 0, 0);
53672 sz = sqlite3_column_int64(pStmt, 0)*szPage;
53677 pOut = 0;
53681 int nPage = sqlite3_column_int(pStmt, 0);
53685 DbPage *pPage = 0;
53687 rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pPage, 0);
53691 memset(pTo, 0, szPage);
53714 sqlite3_stmt *pStmt = 0;
53722 if( szDb<0 ) return SQLITE_MISUSE_BKPT;
53723 if( szBuf<0 ) return SQLITE_MISUSE_BKPT;
53727 if( zSchema==0 ) zSchema = db->aDb[0].zDbSName;
53730 if( iDb<2 && iDb!=0 ){
53735 if( zSql==0 ){
53738 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
53745 db->init.reopenMemdb = 0;
53751 if( p==0 ){
53756 pData = 0;
53769 if( pData && (mFlags & SQLITE_DESERIALIZE_FREEONCLOSE)!=0 ){
53788 sqlite3_vfs *pLower = sqlite3_vfs_find(0);
53790 if( NEVER(pLower==0) ) return SQLITE_ERROR;
53794 ** Windows x86 and SQLITE_MAX_MMAP_SIZE=0. We always leave
53799 return sqlite3_vfs_register(&memdb_vfs, 0);
53887 ** If iSize>BITVEC_NBIT and iDivisor==0 then Bitvec.u.aHash[] is
53892 ** handles up to iDivisor separate values of i. apSub[0] holds
53904 /* Should >=0 for apSub element. */
53915 ** Create a new bitmap object able to handle bits between 0 and iSize,
53935 assert( p!=0 );
53937 if( i>=p->iSize ) return 0;
53943 return 0;
53947 return (p->u.aBitmap[i/BITVEC_SZELEM] & (1<<(i&(BITVEC_SZELEM-1))))!=0;
53954 return 0;
53958 return p!=0 && sqlite3BitvecTestNotNull(p,i);
53962 ** Set the i-th bit. Return 0 on success and an error code if
53975 if( p==0 ) return SQLITE_OK;
53976 assert( i>0 );
53982 if( p->u.apSub[bin]==0 ){
53984 if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM_BKPT;
54008 if( h>=BITVEC_NINT ) h = 0;
54017 u32 *aiValues = sqlite3StackAllocRaw(0, sizeof(p->u.aHash));
54018 if( aiValues==0 ){
54022 memset(p->u.apSub, 0, sizeof(p->u.apSub));
54025 for(j=0; j<BITVEC_NINT; j++){
54028 sqlite3StackFree(0, aiValues);
54045 if( p==0 ) return;
54046 assert( i>0 );
54062 memset(p->u.aHash, 0, sizeof(p->u.aHash));
54063 p->nSet = 0;
54064 for(j=0; j<BITVEC_NINT; j++){
54070 if( h>=BITVEC_NINT ) h = 0;
54082 if( p==0 ) return;
54085 for(i=0; i<BITVEC_NPTR; i++){
54103 ** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
54109 #define TESTBIT(V,I) (V[I>>3]&(1<<(I&7)))!=0
54116 ** by 0, 1, or 3 operands, depending on the opcode. Another
54119 ** There are 6 opcodes numbered from 0 through 5. 0 is the
54122 ** 0 Halt and return the number of errors
54142 Bitvec *pBitvec = 0;
54143 unsigned char *pV = 0;
54153 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
54156 sqlite3BitvecSet(0, 1);
54157 sqlite3BitvecClear(0, 1, pTmpSpace);
54160 pc = i = 0;
54161 while( (op = aOp[pc])!=0 ){
54179 if( (--aOp[pc+1]) > 0 ) nx = 0;
54181 i = (i & 0x7fffffff)%sz;
54182 if( (op & 1)!=0 ){
54195 ** match (rc==0). Change rc to non-zero if a discrepancy
54198 rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1)
54199 + sqlite3BitvecTest(pBitvec, 0)
54276 ** Debug tracing macros. Enable by by changing the "0" to "1" and
54283 #if defined(SQLITE_DEBUG) && 0
54284 int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
54291 if( pLower==0 ){
54297 for(j=0; j<12; j++) printf("%02x", a[j]);
54307 if( pCache->pCache==0 ) return;
54311 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
54313 if( pLower && ((PgHdr*)pLower)->pPage==0 ){
54314 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
54325 ** Return 1 if pPg is on the dirty list for pCache. Return 0 if not.
54334 return 0;
54339 if( p==pPg ) return 0;
54360 assert( pPg!=0 );
54361 assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
54363 assert( pCache!=0 ); /* Every page has an associated PCache */
54365 assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
54368 assert( (pPg->flags & PGHDR_DIRTY)!=0 );/* If not CLEAN must be DIRTY */
54369 assert( pPg->pDirtyNext==0 || pPg->pDirtyNext->pDirtyPrev==pPg );
54370 assert( pPg->pDirtyPrev==0 || pPg->pDirtyPrev->pDirtyNext==pPg );
54371 assert( pPg->pDirtyPrev!=0 || pCache->pDirty==pPg );
54409 ** argument determines what operation to do. The 0x01 bit means first
54410 ** remove pPage from the dirty list. The 0x02 means add pPage back to
54444 if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/
54445 assert( p->bPurgeable==0 || p->eCreate==1 );
54451 pPage->pDirtyPrev = 0;
54454 assert( pPage->pDirtyNext->pDirtyPrev==0 );
54471 && 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
54486 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
54496 if( p->szCache>=0 ){
54518 if( sqlite3GlobalConfig.pcache2.xInit==0 ){
54523 assert( sqlite3GlobalConfig.pcache2.xInit!=0 );
54559 memset(p, 0, sizeof(PCache));
54578 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
54585 if( pNew==0 ) return SQLITE_NOMEM_BKPT;
54605 ** The createFlags should be 0 to check for existing pages and should
54608 ** If the createFlag is 0, then NULL is always returned if the page
54629 assert( pCache!=0 );
54630 assert( pCache->pCache!=0 );
54631 assert( createFlag==3 || createFlag==0 );
54635 ** 0 Do not allocate a new page. (createFlag==0)
54642 assert( eCreate==0 || eCreate==1 || eCreate==2 );
54643 assert( createFlag==0 || pCache->eCreate==eCreate );
54644 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
54669 if( pCache->eCreate==2 ) return 0;
54707 return *ppPage==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
54725 assert( pPage!=0 );
54727 assert( pPgHdr->pPage==0 );
54728 memset(&pPgHdr->pDirty, 0, sizeof(PgHdr) - offsetof(PgHdr,pDirty));
54732 memset(pPgHdr->pExtra, 0, 8);
54752 assert( pPage!=0 );
54766 ** reference count drops to 0, then it is made eligible for recycling.
54769 assert( p->nRef>0 );
54771 if( (--p->nRef)==0 ){
54785 assert(p->nRef>0);
54811 assert( p->nRef>0 );
54832 assert( (p->flags & PGHDR_DIRTY)!=0 );
54833 assert( (p->flags & PGHDR_CLEAN)==0 );
54839 if( p->nRef==0 ){
54850 while( (p = pCache->pDirty)!=0 ){
54884 assert( p->nRef>0 );
54885 assert( newPgno>0 );
54888 pOther = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, newPgno, 0);
54891 assert( pXPage->nRef==0 );
54910 ** function is 0, then the data area associated with page 1 is zeroed, but
54922 ** it must be that pgno==0.
54924 assert( p->pgno>0 );
54930 if( pgno==0 && pCache->nRefSum ){
54932 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
54934 ** pCache->nRefSum>0 */
54935 memset(pPage1->pBuf, 0, pCache->szPage);
54947 assert( pCache->pCache!=0 );
54956 sqlite3PcacheTruncate(pCache, 0);
54966 assert( pA!=0 && pB!=0 );
54972 if( pA==0 ){
54980 if( pB==0 ){
55003 memset(a, 0, sizeof(a));
55007 p->pDirty = 0;
55008 for(i=0; ALWAYS(i<N_SORT_BUCKET-1); i++){
55009 if( a[i]==0 ){
55014 a[i] = 0;
55024 p = a[0];
55026 if( a[i]==0 ) continue;
55064 assert( pCache->pCache!=0 );
55081 assert( pCache->pCache!=0 );
55094 assert( p->pCache!=0 );
55096 if( mxPage<0 ){
55110 assert( pCache->pCache!=0 );
55126 int nDirty = 0;
55129 return nCache ? (int)(((i64)nDirty * 100) / nCache) : 0;
55137 return (pCache->pDirty!=0);
55225 ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, N).
55282 /* NB: pLruPrev is only valid if pLruNext!=0 */
55289 #define PAGE_IS_PINNED(p) ((p)->pLruNext==0)
55290 #define PAGE_IS_UNPINNED(p) ((p)->pLruNext!=0)
55408 #if !defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || SQLITE_THREADSAFE==0
55409 # define pcache1EnterMutex(X) assert((X)->mutex==0)
55410 # define pcache1LeaveMutex(X) assert((X)->mutex==0)
55411 # define PCACHE1_MIGHT_USE_GROUP_MUTEX 0
55434 if( pBuf==0 ) sz = n = 0;
55435 if( n==0 ) sz = 0;
55441 pcache1.pFree = 0;
55442 pcache1.bUnderPressure = 0;
55460 if( pcache1.nInitPage==0 ) return 0;
55462 if( pCache->nMax<3 ) return 0;
55464 if( pcache1.nInitPage>0 ){
55481 pX->isAnchor = 0;
55483 pX->pLruPrev = 0; /* Initializing this saves a valgrind error */
55488 return pCache->pFree!=0;
55501 void *p = 0;
55510 assert( pcache1.nFreeSlot>=0 );
55516 if( p==0 ){
55539 if( p==0 ) return;
55556 int nFreed = 0;
55589 PgHdr1 *p = 0;
55593 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
55594 assert( pCache->pFree!=0 );
55597 p->pNext = 0;
55603 assert( pcache1.separateCache==0 );
55613 if( pPg==0 ) return 0;
55617 p->isBulkLocal = 0;
55618 p->isAnchor = 0;
55619 p->pLruPrev = 0; /* Initializing this saves a valgrind error */
55630 assert( p!=0 );
55711 for(i=0; i<p->nHash; i++){
55714 while( (pPage = pNext)!=0 ){
55735 assert( pPage!=0 );
55742 pPage->pLruNext = 0;
55743 /* pPage->pLruPrev = 0;
55744 ** No need to clear pLruPrev as it is never accessed if pLruNext is 0 */
55745 assert( pPage->isAnchor==0 );
55782 && (p=pGroup->lru.pLruPrev)->isAnchor==0
55789 if( pCache->nPage==0 && pCache->pBulk ){
55791 pCache->pBulk = pCache->pFree = 0;
55806 TESTONLY( int nPage = 0; ) /* To assert pCache->nPage is correct */
55810 assert( pCache->nHash > 0 );
55830 while( (pPage = *pp)!=0 ){
55838 TESTONLY( if( nPage>=0 ) nPage++; )
55844 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
55855 assert( pcache1.isInit==0 );
55856 memset(&pcache1, 0, sizeof(pcache1));
55874 pcache1.separateCache = 0;
55876 pcache1.separateCache = sqlite3GlobalConfig.pPage==0
55877 || sqlite3GlobalConfig.bCoreMutex>0;
55879 pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
55889 && sqlite3GlobalConfig.nPage!=0
55890 && sqlite3GlobalConfig.pPage==0
55894 pcache1.nInitPage = 0;
55908 assert( pcache1.isInit!=0 );
55909 memset(&pcache1, 0, sizeof(pcache1));
55925 assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
55938 if( pGroup->lru.isAnchor==0 ){
55946 pCache->bPurgeable = (bPurgeable ? 1 : 0);
55957 if( pCache->nHash==0 ){
55959 pCache = 0;
55973 assert( nMax>=0 );
55978 if( n > 0x7fff0000 - pGroup->nMaxPage + pCache->nMax ){
55979 n = 0x7fff0000 - pGroup->nMaxPage + pCache->nMax;
56002 pGroup->nMaxPage = 0;
56037 PgHdr1 *pPage = 0;
56049 return 0;
56053 assert( pCache->nHash>0 && pCache->apHash );
56063 pcache1RemoveFromHash(pPage, 0);
56068 pPage = 0;
56087 pPage->pLruNext = 0;
56088 /* pPage->pLruPrev = 0;
56089 ** No need to clear pLruPrev since it is not accessed when pLruNext==0 */
56090 *(void **)pPage->page.pExtra = 0;
56105 ** the value of the createFlag argument. 0 means do not allocate a new
56115 ** depending on the value of parameter createFlag (which may be 0, 1 or 2).
56120 ** 2. If createFlag==0 and the page is not already in the cache, NULL is
56164 PgHdr1 *pPage = 0;
56171 ** If the page was not in the hash table and createFlag is 0, abort.
56172 ** Otherwise (page not in hash and createFlag!=0) continue with
56184 return 0;
56198 assert( pPage==0 || pCache->iMaxKey>=iKey );
56212 assert( offsetof(PgHdr1,page)==0 );
56214 assert( pCache->bPurgeable || pCache->nMin==0 );
56215 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
56216 assert( pCache->nMin==0 || pCache->bPurgeable );
56217 assert( pCache->nHash>0 );
56249 assert( pPage->pLruNext==0 );
56285 assert( pcache1FetchNoMutex(p, iOld, 0)==pPage ); /* pPg really is iOld */
56293 assert( pcache1FetchNoMutex(p, iNew, 0)==0 ); /* iNew not in cache */
56330 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
56332 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0);
56353 0, /* pArg */
56393 int nFree = 0;
56396 if( sqlite3GlobalConfig.pPage==0 ){
56399 while( (nReq<0 || nFree<nReq)
56400 && (p=pcache1.grp.lru.pLruPrev)!=0
56401 && p->isAnchor==0
56426 int nRecyclable = 0;
56562 #define ROWSET_SORTED 0x01 /* True if RowSet.pEntry is sorted */
56563 #define ROWSET_NEXT 0x02 /* True if sqlite3RowSetNext() has been called */
56573 p->pChunk = 0;
56575 p->pEntry = 0;
56576 p->pLast = 0;
56577 p->pForest = 0;
56581 p->iBatch = 0;
56598 p->pChunk = 0;
56599 p->nFresh = 0;
56600 p->pEntry = 0;
56601 p->pLast = 0;
56602 p->pForest = 0;
56625 assert( p!=0 );
56626 if( p->nFresh==0 ){ /*OPTIMIZATION-IF-FALSE*/
56631 if( pNew==0 ){
56632 return 0;
56654 assert( p!=0 && (p->rsFlags & ROWSET_NEXT)==0 );
56657 if( pEntry==0 ) return;
56659 pEntry->pRight = 0;
56688 assert( pA!=0 && pB!=0 );
56690 assert( pA->pRight==0 || pA->v<=pA->pRight->v );
56691 assert( pB->pRight==0 || pB->v<=pB->pRight->v );
56695 if( pA==0 ){
56702 if( pB==0 ){
56719 memset(aBucket, 0, sizeof(aBucket));
56722 pIn->pRight = 0;
56723 for(i=0; aBucket[i]; i++){
56725 aBucket[i] = 0;
56730 pIn = aBucket[0];
56731 for(i=1; i<sizeof(aBucket)/sizeof(aBucket[0]); i++){
56732 if( aBucket[i]==0 ) continue;
56749 assert( pIn!=0 );
56762 assert( (*ppLast)->pRight==0 );
56785 if( *ppList==0 ){ /*OPTIMIZATION-IF-TRUE*/
56787 return 0;
56795 if( p==0 ){ /*OPTIMIZATION-IF-FALSE*/
56806 p->pLeft = p->pRight = 0;
56820 assert( pList!=0 );
56823 p->pLeft = p->pRight = 0;
56837 ** 0 if the RowSet is already empty.
56848 assert( p!=0 );
56849 assert( p->pForest==0 ); /* Cannot be used with sqlite3RowSetText() */
56852 if( (p->rsFlags & ROWSET_NEXT)==0 ){ /*OPTIMIZATION-IF-FALSE*/
56853 if( (p->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
56863 if( p->pEntry==0 ){ /*OPTIMIZATION-IF-TRUE*/
56869 return 0;
56875 ** part of any insert batch prior to iBatch. Return 1 or 0.
56885 assert( pRowSet!=0 && (pRowSet->rsFlags & ROWSET_NEXT)==0 );
56894 if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
56900 if( pTree->pLeft==0 ){
56906 pTree->pLeft = 0;
56910 if( pTree==0 ){
56913 pTree->v = 0;
56914 pTree->pRight = 0;
56918 pRowSet->pEntry = 0;
56919 pRowSet->pLast = 0;
56926 ** Return 1 if it does and 0 if not.
56940 return 0;
56993 #define WAL_SYNC_FLAGS(X) ((X)&0x03)
56994 #define CKPT_SYNC_FLAGS(X) (((X)>>2)&0x03)
56997 # define sqlite3WalOpen(x,y,z) 0
56999 # define sqlite3WalClose(v,w,x,y,z) 0
57000 # define sqlite3WalBeginReadTransaction(y,z) 0
57002 # define sqlite3WalDbsize(y) 0
57003 # define sqlite3WalBeginWriteTransaction(y) 0
57004 # define sqlite3WalEndWriteTransaction(x) 0
57005 # define sqlite3WalUndo(x,y,z) 0
57007 # define sqlite3WalSavepointUndo(y,z) 0
57008 # define sqlite3WalFrames(u,v,w,x,y,z) 0
57009 # define sqlite3WalCheckpoint(q,r,s,t,u,v,w,x,y,z) 0
57010 # define sqlite3WalCallback(z) 0
57011 # define sqlite3WalExclusiveMode(y,z) 0
57012 # define sqlite3WalHeapMemory(z) 0
57013 # define sqlite3WalFramesize(z) 0
57014 # define sqlite3WalFindFrame(x,y,z) 0
57015 # define sqlite3WalFile(x) 0
57075 int sync_flags, /* Flags to sync db file with (or 0) */
57085 ** the last call, then return 0.
57223 #if 0
57459 #define PAGER_OPEN 0
57523 #define MAX_SECTOR_SIZE 0x10000
57533 ** set to 0. If a journal-header is written into the main journal while
57555 #define SPILLFLAG_OFF 0x01 /* Never spill cache. Set via pragma */
57556 #define SPILLFLAG_ROLLBACK 0x02 /* Current rolling back, so do not spill */
57557 #define SPILLFLAG_NOSYNC 0x04 /* Spill is ok, but do not sync */
57665 ** Except, any file that is greater than 0 bytes in size is considered
57717 ** syncFlags is either SQLITE_SYNC_NORMAL (0x02) or SQLITE_SYNC_FULL (0x03).
57721 ** file in bits 0x04 and 0x08. In other words, to get the correct sync flags
57722 ** for checkpoint operations, use (walSyncFlags&0x03) and to get the correct
57723 ** sync flags for transaction commit, use ((walSyncFlags>>2)&0x03). Note
57725 ** meaning that the 0x04 and 0x08 bits are both zero.
57818 #define PAGER_STAT_HIT 0
57829 SQLITE_API int sqlite3_pager_readdb_count = 0; /* Number of full pages read from DB */
57830 SQLITE_API int sqlite3_pager_writedb_count = 0; /* Number of full pages written to DB */
57831 SQLITE_API int sqlite3_pager_writej_count = 0; /* Number of pages written to journal */
57843 ** Since version 2.8.0, the journal format contains additional sanity
57863 0xd9, 0xd5, 0x05, 0xf9, 0x20, 0xa1, 0x63, 0xd7,
57885 # define MEMDB 0
57894 #if SQLITE_MAX_MMAP_SIZE>0
57897 # define USEFETCH(x) 0
57902 ** Return 0 if it is not open, or non-zero (but not 1) if it is.
57912 #define isOpen(pFd) ((pFd)->pMethods!=0)
57924 if( pPager->fd->pMethods==0 ) return 0;
57925 if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
57928 u32 iRead = 0;
57930 return iRead==0;
57938 # define pagerUseWal(x) ((x)->pWal!=0)
57940 # define pagerUseWal(x) 0
57941 # define pagerRollbackWal(x) 0
57942 # define pagerWalFrames(v,w,x,y) 0
57973 assert( p->tempFile==0 || p->eLock==EXCLUSIVE_LOCK );
57974 assert( p->tempFile==0 || pPager->changeCountDone );
57997 assert( pagerUseWal(p)==0 );
58003 assert( pPager->changeCountDone==0 || pPager->eLock>=RESERVED_LOCK );
58010 assert( sqlite3PcacheRefCount(pPager->pPCache)==0 || pPager->tempFile );
58028 assert( pPager->setSuper==0 );
58080 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 || pPager->tempFile );
58146 #if SQLITE_MAX_MMAP_SIZE>0
58157 #if SQLITE_MAX_MMAP_SIZE>0
58160 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
58180 for(i=0; i<pPager->nSavepoint; i++){
58182 if( p->nOrig>=pgno && 0==sqlite3BitvecTestNotNull(p->pInSavepoint, pgno) ){
58184 pPager->aSavepoint[i].bTruncateOnRelease = 0;
58189 return 0;
58247 assert( eLock!=NO_LOCK || pagerUseWal(pPager)==0 );
58301 ** If neither optimization can be used, 0 is returned.
58317 if( pPager->dbSize>0 && (dc&SQLITE_IOCAP_BATCH_ATOMIC) ){
58329 if( 0==(dc&(SQLITE_IOCAP_ATOMIC|(szPage>>8)) || nSector>szPage) ){
58330 return 0;
58337 return 0;
58350 u32 hash = 0;
58352 for(i=0; i<nByte; i++){
58377 #define pager_datahash(X,Y) 0
58378 #define pager_pagehash(X) 0
58403 ** zSuper[0] is set to 0 and SQLITE_OK returned.
58415 zSuper[0] = '\0';
58422 || len==0
58432 for(u=0; u<len; u++){
58441 len = 0;
58443 zSuper[len] = '\0';
58444 zSuper[len+1] = '\0';
58458 ** 0 0
58465 i64 offset = 0;
58470 assert( offset%JOURNAL_HDR_SZ(pPager)==0 );
58480 ** within the current transaction (i.e. if Pager.journalOff==0).
58483 ** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
58505 if( doTruncate || iLimit==0 ){
58506 rc = sqlite3OsTruncate(pPager->jfd, 0);
58508 static const char zeroHdr[28] = {0};
58509 rc = sqlite3OsWrite(pPager->jfd, zeroHdr, sizeof(zeroHdr), 0);
58521 if( rc==SQLITE_OK && iLimit>0 ){
58564 for(ii=0; ii<pPager->nSavepoint; ii++){
58565 if( pPager->aSavepoint[ii].iHdrOffset==0 ){
58579 ** A faster alternative is to write 0xFFFFFFFF to the nRec field. When
58597 put32bits(&zHeader[sizeof(aJournalMagic)], 0xffffffff);
58599 memset(zHeader, 0, sizeof(aJournalMagic)+4);
58616 ** case the journal file is always 0 bytes in size at this point.
58619 i64 sz = 0;
58621 assert( sz==0 );
58641 memset(&zHeader[sizeof(aJournalMagic)+20], 0,
58661 for(nWrite=0; rc==SQLITE_OK&&nWrite<JOURNAL_HDR_SZ(pPager); nWrite+=nHeader){
58721 if( memcmp(aMagic, aJournalMagic, sizeof(aMagic))!=0 ){
58737 if( pPager->journalOff==0 ){
58752 if( iPageSize==0 ){
58763 || ((iPageSize-1)&iPageSize)!=0 || ((iSectorSize-1)&iSectorSize)!=0
58818 u32 cksum = 0; /* Checksum of string zSuper */
58820 assert( pPager->setSuper==0 );
58833 for(nSuper=0; zSuper[nSuper]; nSuper++){
58849 if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_SJ_PGNO(pPager))))
58850 || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4)))
58851 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper)))
58852 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum)))
58853 || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8,
58901 for(ii=0; ii<pPager->nSavepoint; ii++){
58908 pPager->aSavepoint = 0;
58909 pPager->nSavepoint = 0;
58910 pPager->nSubRec = 0;
58922 for(ii=0; ii<pPager->nSavepoint; ii++){
58958 pPager->pInJournal = 0;
58967 int iDc = isOpen(pPager->fd)?sqlite3OsDeviceCharacteristics(pPager->fd):0;
58980 if( 0==(iDc & SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN)
59011 if( pPager->tempFile==0 ){
59013 pPager->changeCountDone = 0;
59018 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
59023 pPager->journalOff = 0;
59024 pPager->journalHdr = 0;
59025 pPager->setSuper = 0;
59048 int rc2 = rc & 0xff;
59053 (pPager->errCode & 0xff)==SQLITE_IOERR
59067 ** or rolled back (bCommit==0).
59082 if( pPager->tempFile==0 ) return 1;
59083 if( !bCommit ) return 0;
59084 if( !isOpen(pPager->fd) ) return 0;
59165 assert( isOpen(pPager->jfd) || pPager->pInJournal==0
59176 if( pPager->journalOff==0 ){
59179 rc = sqlite3OsTruncate(pPager->jfd, 0);
59189 pPager->journalOff = 0;
59194 pPager->journalOff = 0;
59202 assert( sqlite3JournalIsInMemory(pPager->jfd)==0 );
59216 if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){
59219 p->pageHash = 0;
59226 pPager->pInJournal = 0;
59227 pPager->nRec = 0;
59256 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_COMMIT_PHASETWO, 0);
59261 && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
59266 pPager->setSuper = 0;
59300 pager_end_transaction(pPager, 0, 0);
59343 while( i>0 ){
59352 ** from the sub-journal (if isMainJrnl==0) and playback that page.
59377 ** * If the record page-number is illegal (0 or PAGER_SJ_PGNO), or
59391 int isMainJrnl, /* 1 -> main journal. 0 -> sub-journal. */
59402 assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */
59403 assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */
59405 assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */
59409 assert( pagerUseWal(pPager)==0 || (!isMainJrnl && isSavepnt) );
59437 if( pgno==0 || pgno==PAGER_SJ_PGNO(pPager) ){
59494 ** the page is marked as needSync==0.
59501 pPg = 0;
59506 assert( pPager->eState!=PAGER_OPEN || pPg==0 || pPager->tempFile );
59514 isSynced = (pPg==0 || 0==(pPg->flags & PGHDR_NEED_SYNC));
59521 testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
59538 }else if( !isMainJrnl && pPg==0 ){
59556 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)==0 );
59559 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 );
59603 ** nul-terminator byte (0x00). i.e. the entire contents of a super-journal
59639 char *zSuperJournal = 0; /* Contents of super-journal file */
59643 char *zFree = 0; /* Free this buffer */
59652 pJournal = 0;
59655 rc = sqlite3OsOpen(pVfs, zSuper, pSuper, flags, 0);
59673 zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0;
59676 rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
59678 zSuperJournal[nSuperJournal] = 0;
59679 zSuperJournal[nSuperJournal+1] = 0;
59698 rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
59709 c = zSuperPtr[0]!=0 && strcmp(zSuperPtr, zSuper)==0;
59719 rc = sqlite3OsDelete(pVfs, zSuper, 0);
59773 memset(pTmp, 0, szPage);
59830 SQLITE_IOCAP_POWERSAFE_OVERWRITE)!=0
59849 ** in the journal. If this value is 0xffffffff, then compute the
59876 ** If the nRec value is 0xffffffff it means that nRec should be computed
59903 Pgno mxPg = 0; /* Size of the original file in pages */
59906 char *zSuper = 0; /* Name of super-journal file if any */
59908 int nPlayback = 0; /* Total number of pages restored from journal */
59933 if( rc==SQLITE_OK && zSuper[0] ){
59936 zSuper = 0;
59940 pPager->journalOff = 0;
59961 /* If nRec is 0xffffffff, then this journal was created by a process
59966 if( nRec==0xffffffff ){
59971 /* If nRec is 0 and this rollback is of a transaction created by this
59978 ** When rolling back a hot journal, nRec==0 always means that the next
59980 ** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
59985 if( nRec==0 && !isHot &&
60007 for(u=0; u<nRec; u++){
60010 needPagerReset = 0;
60012 rc = pager_playback_one_page(pPager,&pPager->journalOff,0,1,0);
60039 assert( 0 );
60051 sqlite3OsFileControlHint(pPager->fd,SQLITE_FCNTL_DB_UNCHANGED,0);
60068 ** which case it requires 4 0x00 bytes in memory immediately before
60077 rc = sqlite3PagerSync(pPager, 0);
60080 rc = pager_end_transaction(pPager, zSuper[0]!='\0', 0);
60083 if( rc==SQLITE_OK && zSuper[0] && res ){
60088 memset(pPager->pTmpSpace, 0, 4);
60123 u32 iFrame = 0; /* Frame of WAL containing pgno */
60150 ** should be page numbers which are never 0xffffffff. So filling
60151 ** pPager->dbFileVers[] with all 0xff bytes should suffice.
60155 ** white noise equaling 16 bytes of 0xff is vanishingly small so
60158 memset(pPager->dbFileVers, 0xff, sizeof(pPager->dbFileVers));
60183 if( NEVER(pPg==0) ) return;
60252 ** + Discard the cached page (if refcount==0), or
60253 ** + Reload page content from the database (if refcount>0).
60295 assert( pList->pDirty==0 || isCommit );
60302 nList = 0;
60303 for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
60345 int changed = 0; /* True if cache must be reset */
60360 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
60380 ** function returns zero if the WAL is not open (i.e. Pager.pWal==0), or
60388 assert( pPager->tempFile==0 );
60396 if( nPage==0 && ALWAYS(isOpen(pPager->fd)) ){
60397 i64 n = 0; /* Size of db file in bytes */
60452 if( nPage==0 ){
60453 rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0);
60455 testcase( sqlite3PcachePagecount(pPager->pPCache)==0 );
60456 rc = sqlite3PagerOpenWal(pPager, 0);
60507 Bitvec *pDone = 0; /* Bitvec to ensure pages played back only once */
60536 assert( pagerUseWal(pPager)==0 || szJ==0 );
60553 pPager->journalOff = 0;
60563 u32 nJRec = 0; /* Number of Journal Records */
60565 rc = readJournalHdr(pPager, 0, szJ, &nJRec, &dummy);
60573 if( nJRec==0
60578 for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
60598 rc = pager_playback_one_page(pPager, &offset, pDone, 0, 1);
60631 #if SQLITE_MAX_MMAP_SIZE>0
60636 pPager->bUseFetch = (sz>0);
60716 pPager->fullSync = 0;
60717 pPager->extraSync = 0;
60719 pPager->noSync = level==PAGER_SYNCHRONOUS_OFF ?1:0;
60720 pPager->fullSync = level>=PAGER_SYNCHRONOUS_FULL ?1:0;
60721 pPager->extraSync = level==PAGER_SYNCHRONOUS_EXTRA ?1:0;
60724 pPager->syncFlags = 0;
60750 SQLITE_API int sqlite3_opentemp_count = 0;
60781 rc = sqlite3OsOpen(pPager->pVfs, 0, pFile, vfsFlags, 0);
60816 assert( ((int(*)(void *))(ap[0]))==xBusyHandler );
60865 assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) );
60866 if( (pPager->memDb==0 || pPager->dbSize==0)
60867 && sqlite3PcacheRefCount(pPager->pPCache)==0
60871 i64 nByte = 0;
60883 memset(pNew+pageSize, 0, 8);
60904 if( nReserve<0 ) nReserve = pPager->nReserve;
60905 assert( nReserve>=0 && nReserve<1000 );
60932 if( mxPage>0 ){
60983 memset(pDest, 0, N);
60993 IOTRACE(("DBHDR %p 0 %d\n", pPager, N))
60994 rc = sqlite3OsRead(pPager->fd, pDest, N, 0);
61077 for(i=0; i<pPg->pPager->nSavepoint; i++){
61112 ** Pager object may still have open savepoints (Pager.nSavepoint!=0),
61143 #if SQLITE_MAX_MMAP_SIZE>0
61165 p->pDirty = 0;
61167 memset(p->pExtra, 0, 8);
61170 if( p==0 ){
61181 assert( p->pPage==0 );
61226 int bHasMoved = 0;
61230 if( pPager->dbSize==0 ) return SQLITE_OK;
61231 assert( pPager->zFilename && pPager->zFilename[0] );
61261 assert( db || pagerUseWal(pPager)==0 );
61266 /* pPager->errCode = 0; */
61267 pPager->exclusiveMode = 0;
61270 u8 *a = 0;
61271 assert( db || pPager->pWal==0 );
61272 if( db && 0==(db->flags & SQLITE_NoCkptOnClose)
61278 pPager->pWal = 0;
61385 if( 0==(iDc&SQLITE_IOCAP_SAFE_APPEND) ){
61400 ** a valid header following Pager.journalOff, then write a 0x00
61417 if( rc==SQLITE_OK && 0==memcmp(aMagic, aJournalMagic, 8) ){
61418 static const u8 zerobyte = 0;
61433 ** is populated with 0xFFFFFFFF when the journal header is written
61436 if( pPager->fullSync && 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
61448 if( 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
61452 (pPager->syncFlags==SQLITE_SYNC_FULL?SQLITE_SYNC_DATAONLY:0)
61458 if( newHdr && 0==(iDc&SQLITE_IOCAP_SAFE_APPEND) ){
61459 pPager->nRec = 0;
61517 assert( isOpen(pPager->fd) || pList->pDirty==0 );
61552 if( pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
61556 assert( (pList->flags&PGHDR_NEED_SYNC)==0 );
61611 rc = sqlite3JournalOpen(pPager->pVfs, 0, pPager->sjfd, flags, nStmtSpill);
61635 assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 );
61658 assert( pPager->nSavepoint>0 );
61718 && ((pPager->doNotSpill & (SPILLFLAG_ROLLBACK|SPILLFLAG_OFF))!=0
61719 || (pPg->flags & PGHDR_NEED_SYNC)!=0)
61725 pPg->pDirty = 0;
61730 rc = pagerWalFrames(pPager, pPg, 0, 0);
61735 if( pPager->tempFile==0 ){
61750 assert( (pPg->flags&PGHDR_NEED_SYNC)==0 );
61774 if( pList->nRef==0 ){
61826 Pager *pPager = 0; /* Pager object to allocate and return */
61828 int tempFile = 0; /* True for temp files (incl. in-memory files) */
61829 int memDb = 0; /* True if this is an in-memory file */
61830 int memJM = 0; /* Memory journal mode */
61831 int readOnly = 0; /* True if this is a read-only file */
61833 char *zPathname = 0; /* Full path to database file */
61834 int nPathname = 0; /* Number of bytes in zPathname */
61835 int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
61838 const char *zUri = 0; /* URI args to copy */
61846 *ppPager = 0;
61851 if( zFilename && zFilename[0] ){
61852 zPathname = sqlite3DbStrDup(0, zFilename);
61853 if( zPathname==0 ) return SQLITE_NOMEM_BKPT;
61855 zFilename = 0;
61862 ** leave both nPathname and zPathname set to 0.
61864 if( zFilename && zFilename[0] ){
61867 zPathname = sqlite3DbMallocRaw(0, nPathname*2);
61868 if( zPathname==0 ){
61871 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
61900 sqlite3DbFree(0, zPathname);
61915 ** \0\0\0\0 database prefix (4 bytes)
61920 ** \0\0\0 terminator (3 bytes)
61923 ** the specific order of the filenames and the \0 separators between them
61932 ** - \0
61935 ** - \0
61937 ** - \0
61938 ** - \0
61940 ** - \0
61942 ** - \0
61967 sqlite3DbFree(0, zPathname);
61981 if( nPathname>0 ){
61992 if( nPathname>0 ){
62001 pPager->zJournal = 0;
62006 if( nPathname>0 ){
62015 pPager->zWal = 0;
62020 if( nPathname ) sqlite3DbFree(0, zPathname);
62026 if( zFilename && zFilename[0] ){
62027 int fout = 0; /* VFS flags returned by xOpen() */
62030 pPager->memVfs = memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
62031 readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
62067 pPager->noLock = sqlite3_uri_boolean(pPager->zFilename, "nolock", 0);
62068 if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
62069 || sqlite3_uri_boolean(pPager->zFilename, "immutable", 0) ){
62097 assert( pPager->memDb==0 );
62107 !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
62123 /* pPager->stmtOpen = 0; */
62124 /* pPager->stmtInUse = 0; */
62125 /* pPager->nRef = 0; */
62126 /* pPager->stmtSize = 0; */
62127 /* pPager->stmtJSize = 0; */
62128 /* pPager->nPage = 0; */
62131 /* pPager->errMask = 0; */
62142 /* pPager->pFirst = 0; */
62143 /* pPager->pFirstSynced = 0; */
62144 /* pPager->pLast = 0; */
62154 /* pPager->xBusyHandler = 0; */
62155 /* pPager->pBusyHandlerArg = 0; */
62158 /* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
62173 while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){
62192 ** * The database file itself is greater than 0 bytes in size, and
62193 ** * The first byte of the journal file exists and is not 0x00.
62195 ** If the current size of the database file is 0 but a journal file
62198 ** just deleted using OsDelete, *pExists is set to 0 and SQLITE_OK
62210 ** set to 0 and SQLITE_OK returned. If an IO error occurs while trying
62224 assert( jrnlOpen==0 || ( sqlite3OsDeviceCharacteristics(pPager->jfd) &
62228 *pExists = 0;
62233 int locked = 0; /* True if some process holds a RESERVED lock */
62247 assert( pPager->tempFile==0 );
62258 if( nPage==0 && !jrnlOpen ){
62261 sqlite3OsDelete(pVfs, pPager->zJournal, 0);
62277 u8 first = 0;
62278 rc = sqlite3OsRead(pPager->jfd, (void *)&first, 1, 0);
62285 *pExists = (first!=0);
62341 assert( sqlite3PcacheRefCount(pPager->pPCache)==0 );
62350 assert( pPager->tempFile==0 || pPager->eLock==EXCLUSIVE_LOCK );
62412 int fout = 0;
62495 memset(dbFileVers, 0, sizeof(dbFileVers));
62498 if( memcmp(pPager->dbFileVers, dbFileVers, sizeof(dbFileVers))!=0 ){
62508 sqlite3OsUnfetch(pPager->fd, 0, 0);
62518 assert( pPager->pWal==0 || rc==SQLITE_OK );
62527 if( pPager->tempFile==0 && pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){
62552 if( sqlite3PcacheRefCount(pPager->pPCache)==0 ){
62553 assert( pPager->nMmapOut==0 ); /* because page1 is never memory mapped */
62610 ** just returns 0. This routine acquires a read-lock the first time it
62631 if( pgno==0 ) return SQLITE_CORRUPT_BKPT;
62633 if( pBase==0 ){
62634 pPg = 0;
62637 if( pBase==0 ){
62645 assert( pPg->pPager==pPager || pPg->pPager==0 );
62647 noContent = (flags & PAGER_GET_NOCONTENT)!=0;
62675 pPg = 0;
62695 memset(pPg->pData, 0, pPager->pageSize);
62715 *ppPage = 0;
62719 #if SQLITE_MAX_MMAP_SIZE>0
62728 PgHdr *pPg = 0;
62729 u32 iFrame = 0; /* Frame to read from WAL file */
62741 /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here
62743 ** test in the previous statement, and avoid testing pgno==0 in the
62745 if( pgno<=1 && pgno==0 ){
62756 *ppPage = 0;
62760 if( bMmapOk && iFrame==0 ){
62761 void *pData = 0;
62769 if( pPg==0 ){
62781 *ppPage = 0;
62787 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
62799 *ppPage = 0;
62812 #if 0 /* Trace page fetch by setting to 1 */
62818 printf("PAGE %u failed with 0x%02x\n", pgno, rc);
62831 ** or 0 if the page is not in cache.
62841 assert( pPager!=0 );
62842 assert( pgno!=0 );
62843 assert( pPager->pPCache!=0 );
62844 pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
62845 assert( pPage==0 || pPager->hasHeldSharedLock );
62846 if( pPage==0 ) return 0;
62866 assert( pPg!=0 );
62874 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 ); /* tag-20230419-2 */
62881 assert( pPg!=0 );
62883 assert( (pPg->flags & PGHDR_MMAP)==0 ); /* Page1 is never memory mapped */
62917 assert( pPager->pInJournal==0 );
62926 if( pPager->pInJournal==0 ){
62965 pPager->nRec = 0;
62966 pPager->journalOff = 0;
62967 pPager->setSuper = 0;
62968 pPager->journalHdr = 0;
62975 pPager->pInJournal = 0;
62976 pPager->journalOff = 0;
63010 assert( pPager->pInJournal==0 );
63056 pPager->journalOff = 0;
63108 ((pPg->flags&PGHDR_NEED_SYNC)?1:0), pager_pagehash(pPg)));
63112 assert( pPager->pInJournal!=0 );
63141 assert( pPager->errCode==0 );
63142 assert( pPager->readOnly==0 );
63168 assert( (pPager->pInJournal!=0) == isOpen(pPager->jfd) );
63169 if( pPager->pInJournal!=0
63170 && sqlite3BitvecTestNotNull(pPager->pInJournal, pPg->pgno)==0
63172 assert( pagerUseWal(pPager)==0 );
63184 ((pPg->flags&PGHDR_NEED_SYNC)?1:0)));
63198 if( pPager->nSavepoint>0 ){
63224 int nPage = 0; /* Number of pages starting at pg1 to journal */
63226 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
63235 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)==0 );
63252 assert(nPage>0);
63256 for(ii=0; ii<nPage && rc==SQLITE_OK; ii++){
63261 rc = sqlite3PagerGet(pPager, pg, &pPage, 0);
63270 }else if( (pPage = sqlite3PagerLookup(pPager, pg))!=0 ){
63286 for(ii=0; ii<nPage; ii++){
63295 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
63316 assert( (pPg->flags & PGHDR_MMAP)==0 );
63319 if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
63325 assert( pPager->tempFile==0 );
63365 if( !pPager->tempFile && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
63416 # define DIRECT_MODE 0
63417 assert( isDirectMode==0 );
63423 if( !pPager->changeCountDone && pPager->dbSize>0 ){
63429 rc = sqlite3PagerGet(pPager, 1, &pPgHdr, 0);
63430 assert( pPgHdr==0 || rc==SQLITE_OK );
63448 assert( pPager->dbFileSize>0 );
63451 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
63512 if( 0==pagerUseWal(pPager) ){
63571 assert( MEMDB==0 || pPager->tempFile );
63573 if( 0==pagerFlushOnCommit(pPager, 1) ){
63581 PgHdr *pPageOne = 0;
63583 if( pList==0 ){
63586 rc = sqlite3PagerGet(pPager, 1, &pPageOne, 0);
63588 pList->pDirty = 0;
63605 int bBatch = zSuper==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
63610 # define bBatch 0
63637 if( bBatch==0 ){
63646 && (!(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
63658 rc = pager_incr_changecounter(pPager, 0);
63667 assert( bBatch==0 );
63670 rc = pager_incr_changecounter(pPager, 0);
63692 rc = syncJournal(pPager, 0);
63698 rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, 0);
63704 memset(pTmp, 0, szPage);
63709 rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, 0);
63712 sqlite3OsFileControlHint(fd, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 0);
63716 if( (rc&0xFF)==SQLITE_IOERR && rc!=SQLITE_IOERR_NOMEM ){
63722 bBatch = 0;
63729 if( bBatch==0 ){
63802 ** header with the nRec field set to 0. If such a journal is used as
63803 ** a hot-journal during hot-journal rollback, 0 changes will be made
63863 rc2 = pager_end_transaction(pPager, pPager->setSuper, 0);
63867 rc = pager_end_transaction(pPager, 0, 0);
63879 rc = pager_playback(pPager, 0);
63884 || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR
63936 a[0] = sqlite3PcacheRefCount(pPager->pPCache);
63942 a[6] = (int)pPager->aStat[PAGER_STAT_HIT] & 0x7fffffff;
63943 a[7] = (int)pPager->aStat[PAGER_STAT_MISS] & 0x7fffffff;
63944 a[8] = 0; /* Used to be pPager->nOvfl */
63946 a[10] = (int)pPager->aStat[PAGER_STAT_WRITE] & 0x7fffffff;
63972 assert( PAGER_STAT_HIT==0 && PAGER_STAT_MISS==1
63978 pPager->aStat[eStat] = 0;
64019 memset(&aNew[nCurrent], 0, (nSavepoint-nCurrent) * sizeof(PagerSavepoint));
64025 if( isOpen(pPager->jfd) && pPager->journalOff>0 ){
64068 ** iSavepoint. A value of 0 means to operate on the outermost savepoint
64095 assert( iSavepoint>=0 || op==SAVEPOINT_ROLLBACK );
64105 nNew = iSavepoint + (( op==SAVEPOINT_RELEASE ) ? 0 : 1);
64131 PagerSavepoint *pSavepoint = (nNew==0)?0:&pPager->aSavepoint[nNew-1];
64162 ** shared cache, it uses nullIfMemDb==0 so that in-memory databases can
64169 static const char zFake[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
64240 Pgno needSyncPgno = 0; /* Old value of pPg->pgno, if sync is required */
64244 assert( pPg->nRef>0 );
64277 if( (pPg->flags & PGHDR_DIRTY)!=0
64284 PAGERID(pPager), pPg->pgno, (pPg->flags&PGHDR_NEED_SYNC)?1:0, pgno));
64353 rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr, 0);
64356 assert( pPager->pTmpSpace!=0 );
64386 assert( pPg->nRef>0 || pPg->pPager->memDb );
64412 assert( PAGER_LOCKINGMODE_QUERY<0 );
64413 assert( PAGER_LOCKINGMODE_NORMAL>=0 && PAGER_LOCKINGMODE_EXCLUSIVE>=0 );
64414 assert( pPager->exclusiveMode || 0==sqlite3WalHeapMemory(pPager->pWal) );
64415 if( eMode>=0 && !pPager->tempFile && !sqlite3WalHeapMemory(pPager->pWal) ){
64445 assert( eMode==PAGER_JOURNALMODE_DELETE /* 0 */
64456 assert( pPager->tempFile==0 || eMode!=PAGER_JOURNALMODE_WAL );
64480 assert( (PAGER_JOURNALMODE_DELETE & 5)==0 );
64482 assert( (PAGER_JOURNALMODE_OFF & 5)==0 );
64486 if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){
64497 sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
64510 sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
64542 if( pPager->eState>=PAGER_WRITER_CACHEMOD ) return 0;
64543 if( NEVER(isOpen(pPager->jfd) && pPager->journalOff>0) ) return 0;
64576 assert( MEMDB==0 || pPager->tempFile );
64577 if( pPager->tempFile==0 ) pager_reset(pPager);
64598 if( pPager->pWal==0 && pPager->journalMode==PAGER_JOURNALMODE_WAL ){
64608 sqlite3_exec(db, "PRAGMA table_list",0,0,0);
64612 (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
64631 if( pPager->noLock ) return 0;
64664 assert( pPager->pWal==0 && pPager->tempFile==0 );
64715 assert( pbOpen==0 || *pbOpen==0 );
64716 assert( pbOpen!=0 || (!pPager->tempFile && !pPager->pWal) );
64755 int logexists = 0;
64775 pPager->pWal = 0;
64792 if( pagerUseWal(pPager) && pPager->exclusiveMode==0 ){
64894 ** is empty, return 0.
64948 ** 0: Magic number. 0x377f0682 or 0x377f0683
64962 ** 0: Page number.
64982 ** magic number in the first 4 bytes of the WAL is 0x377f0683 and it
64983 ** is computed using little-endian if the magic number is 0x377f0682.
64987 ** an even number of unsigned 32-bit integers: x[0] through x[N]. The
64990 ** for i from 0 to n-1 step 2:
65113 ** contain a value of 0.
65169 SQLITE_PRIVATE int sqlite3WalTrace = 0;
65205 #define WAL_WRITE_LOCK 0
65224 ** For all versions of SQLite through 3.10.0 and probably beyond,
65271 ** the mxFrame for that reader. The value READMARK_NOT_USED (0xffffffff)
65272 ** for any aReadMark[] means that entry is unused. aReadMark[0] is
65275 ** WAL_READ_LOCK(0) always ignore the entire WAL and read all content
65291 ** will choose aReadMark[0] which has value 0 and hence such reader will
65298 ** (in other words, if there are no WAL_READ_LOCK(i) where i>0) then
65312 #define READMARK_NOT_USED 0xffffffff
65319 ** 0: | iVersion | \
65394 ** significant bit also set (WAL_MAGIC | 0x00000001) is stored in 32-bit
65402 #define WAL_MAGIC 0x377f0682
65421 u32 iCallback; /* Value to pass to log callback (or 0) */
65464 #define WAL_NORMAL_MODE 0
65471 #define WAL_RDWR 0 /* Normal read/write connection */
65504 int iZero; /* Frame number associated with aPgno[0] */
65548 assert( walAssertLockmask(pWal) && pWal->nSehTry==0 ); \
65554 assert( pWal->nSehTry==0 ); \
65571 ** ExceptionInformation[] array is a read-write flag - 0 if the exception
65590 assert( pWal->nSehTry>0 );
65593 if( res!=0 ){
65595 aArg[0] = 0;
65596 aArg[1] = 0;
65598 RaiseException(EXCEPTION_IN_PAGE_ERROR, 0, 3, (const ULONG_PTR*)aArg);
65606 ** SEH_FREE_ON_ERROR(0, pPtr);
65610 ** SEH_FREE_ON_ERROR(pPtr, 0);
65616 assert( (X==0 || Y==0) && pWal->pFree==X ); pWal->pFree = Y
65626 ** SEH_SET_ON_ERROR(0, 0);
65632 # define SEH_EXCEPT(X) VVA_ONLY(pWal->nSehTry--); assert( pWal->nSehTry==0 );
65633 # define SEH_INJECT_FAULT assert( pWal->nSehTry>0 );
65653 ** (3) rc==SQLITE_OK and *ppPage==NULL // only if iPage==0
65655 ** Scenario (3) can only occur when pWal->writeLock is false and iPage==0
65670 *ppPage = 0;
65673 memset((void*)&apNew[pWal->nWiData], 0,
65680 assert( pWal->apWiData[iPage]==0 );
65688 assert( pWal->apWiData[iPage]!=0
65690 || (pWal->writeLock==0 && iPage==0) );
65691 testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK );
65693 if( iPage>0 && sqlite3FaultSim(600) ) rc = SQLITE_NOMEM;
65694 }else if( (rc&0xff)==SQLITE_READONLY ){
65703 assert( iPage==0 || *ppPage || rc!=SQLITE_OK );
65712 if( pWal->nWiData<=iPage || (*ppPage = pWal->apWiData[iPage])==0 ){
65722 assert( pWal->nWiData>0 && pWal->apWiData[0] );
65724 return (volatile WalCkptInfo*)&(pWal->apWiData[0][sizeof(WalIndexHdr)/2]);
65731 assert( pWal->nWiData>0 && pWal->apWiData[0] );
65733 return (volatile WalIndexHdr*)pWal->apWiData[0];
65744 (((x)&0x000000FF)<<24) + (((x)&0x0000FF00)<<8) \
65745 + (((x)&0x00FF0000)>>8) + (((x)&0xFF000000)>>24) \
65750 ** array aByte[] and the initial values of aIn[0] and aIn[1] (or
65751 ** initial values of 0 and 0 if aIn==NULL).
65769 s1 = aIn[0];
65772 s1 = s2 = 0;
65776 assert( (nByte&0x00000007)==0 );
65778 assert( nByte%4==0 );
65782 s1 += BYTESWAP32(aData[0]) + s2;
65786 }else if( nByte%64==0 ){
65813 aOut[0] = s1;
65852 walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum);
65856 memcpy((void*)&aHdr[0], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
65864 ** 0: Page number.
65875 u32 nTruncate, /* New db size (or 0 for non-commit frames) */
65882 sqlite3Put4byte(&aFrame[0], iPage);
65884 if( pWal->iReCksum==0 ){
65891 sqlite3Put4byte(&aFrame[16], aCksum[0]);
65894 memset(&aFrame[8], 0, 16);
65906 u32 *pnTruncate, /* OUT: New db size (or 0 if not commit) */
65918 if( memcmp(&pWal->hdr.aSalt, &aFrame[8], 8)!=0 ){
65919 return 0;
65924 pgno = sqlite3Get4byte(&aFrame[0]);
65925 if( pgno==0 ){
65926 return 0;
65937 if( aCksum[0]!=sqlite3Get4byte(&aFrame[16])
65941 return 0;
65968 lockIdx-WAL_READ_LOCK(0));
65989 VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && (rc&0xFF)!=SQLITE_BUSY); )
66011 VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && (rc&0xFF)!=SQLITE_BUSY); )
66032 ** between 0 and (HASHTABLE_NSLOT-1). The walHashNext() function advances
66036 assert( iPage>0 );
66037 assert( (HASHTABLE_NSLOT & (HASHTABLE_NSLOT-1))==0 );
66059 ** numbered starting from 0.
66067 ** Finally, set pLoc->aPgno so that pLoc->aPgno[0] is the page number of the
66078 assert( rc==SQLITE_OK || iHash>0 );
66082 if( iHash==0 ){
66084 pLoc->iZero = 0;
66098 ** are numbered starting from 0.
66102 assert( (iHash==0 || iFrame>HASHTABLE_NPAGE_ONE)
66108 assert( iHash>=0 );
66118 if( iHash==0 ){
66119 return pWal->apWiData[0][WALINDEX_HDR_SIZE/sizeof(u32) + iFrame - 1];
66138 int iLimit = 0; /* Zero values greater than this */
66147 if( pWal->hdr.mxFrame==0 ) return;
66162 assert( iLimit>0 );
66163 for(i=0; i<HASHTABLE_NSLOT; i++){
66165 sLoc.aHash[i] = 0;
66173 assert( nByte>=0 );
66174 memset((void *)&sLoc.aPgno[iLimit], 0, nByte);
66183 for(j=0; j<iLimit; j++){
66220 assert( nByte>=0 );
66221 memset((void*)sLoc.aPgno, 0, nByte);
66238 if( (nCollide--)==0 ) return SQLITE_CORRUPT_BKPT;
66249 int nEntry = 0; /* Number of entries in the hash table */
66250 for(i=0; i<HASHTABLE_NSLOT; i++){ if( sLoc.aHash[i] ) nEntry++; }
66259 if( (idx&0x3ff)==0 ){
66261 for(i=0; i<idx; i++){
66290 u32 aFrameCksum[2] = {0, 0};
66299 assert( pWal->ckptLock==1 || pWal->ckptLock==0 );
66304 rc = walLockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
66311 memset(&pWal->hdr, 0, sizeof(WalIndexHdr));
66320 u32 *aPrivate = 0; /* Heap copy of *-shm hash being populated */
66321 u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */
66332 rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0);
66342 magic = sqlite3Get4byte(&aBuf[0]);
66344 if( (magic&0xFFFFFFFE)!=WAL_MAGIC
66351 pWal->hdr.bigEndCksum = (u8)(magic&0x00000001);
66358 aBuf, WAL_HDRSIZE-2*4, 0, pWal->hdr.aFrameCksum
66360 if( pWal->hdr.aFrameCksum[0]!=sqlite3Get4byte(&aBuf[24])
66377 SEH_FREE_ON_ERROR(0, aFrame);
66387 for(iPg=0; iPg<=(u32)walFramePage(iLastFrame); iPg++){
66391 u32 iFirst = 1 + (iPg==0?0:HASHTABLE_NPAGE_ONE+(iPg-1)*HASHTABLE_NPAGE);
66394 assert( aShare!=0 || rc!=SQLITE_OK );
66395 if( aShare==0 ) break;
66416 pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16));
66419 aFrameCksum[0] = pWal->hdr.aFrameCksum[0];
66424 SEH_SET_ON_ERROR(0,0);
66425 nHdr = (iPg==0 ? WALINDEX_HDR_SIZE : 0);
66459 SEH_FREE_ON_ERROR(aFrame, 0);
66467 pWal->hdr.aFrameCksum[0] = aFrameCksum[0];
66476 pInfo->nBackfill = 0;
66478 pInfo->aReadMark[0] = 0;
66509 walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
66519 for(i=0; i<pWal->nWiData; i++){
66521 pWal->apWiData[i] = 0;
66556 assert( zWalName && zWalName[0] );
66584 assert( 123 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(0) );
66605 *ppWal = 0;
66629 walIndexClose(pRet, 0);
66634 if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; }
66636 pRet->padToSectorBoundary = 0;
66658 ** Return 0 on success. If there are no pages in the WAL with a page
66667 u32 iRet = 0xFFFFFFFF; /* 0xffffffff is never a valid page number */
66671 assert( iMin<0xffffffff );
66672 for(i=p->nSegment-1; i>=0; i--){
66688 return (iRet==0xFFFFFFFF);
66722 int iLeft = 0; /* Current index in aLeft */
66723 int iRight = 0; /* Current index in aRight */
66724 int iOut = 0; /* Current index in output buffer */
66728 assert( nLeft>0 && nRight>0 );
66751 memcpy(aLeft, aTmp, sizeof(aTmp[0])*iOut);
66783 int nMerge = 0; /* Number of elements in list aMerge */
66784 ht_slot *aMerge = 0; /* List to be merged */
66786 u32 iSub = 0; /* Index into aSub array */
66789 memset(aSub, 0, sizeof(aSub));
66790 assert( nList<=HASHTABLE_NPAGE && nList>0 );
66793 for(iList=0; iList<nList; iList++){
66796 for(iSub=0; iList & (1<<iSub); iSub++){
66861 ** it only runs if there is actually content in the log (mxFrame>0).
66863 assert( pWal->ckptLock && pWal->hdr.mxFrame>0 );
66877 memset(p, 0, nByte);
66880 SEH_FREE_ON_ERROR(0, p);
66898 for(j=0; j<nEntry; j++){
66909 SEH_FREE_ON_ERROR(p, 0);
66911 p = 0;
66922 ** blocking locks are successfully enabled, or 0 otherwise.
66935 ** or 0 otherwise.
66938 int res = 0;
66952 int tmout = 0;
66967 assert( pWal->readLock<0 || bLock==0 );
66979 pWal->writeLock = 0;
66992 # define walEnableBlocking(x) 0
66994 # define walEnableBlockingMs(pWal, ms) 0
67003 ** lock is successfully obtained or the busy-handler returns 0.
67030 return (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
67055 pWal->hdr.mxFrame = 0;
67056 sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
67059 AtomicStore(&pInfo->nBackfill, 0);
67060 pInfo->nBackfillAttempted = 0;
67061 pInfo->aReadMark[1] = 0;
67063 assert( pInfo->aReadMark[0]==0 );
67103 int sync_flags, /* Flags for OsSync() (or 0) */
67108 WalIterator *pIter = 0; /* Wal iterator context */
67109 u32 iDbpage = 0; /* Next database page to write */
67110 u32 iFrame = 0; /* Wal frame containing data for iDbpage */
67124 assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
67144 xBusy = 0;
67154 assert( rc==SQLITE_OK || pIter==0 );
67158 && (rc = walBusyLock(pWal,xBusy,pBusyArg,WAL_READ_LOCK(0),1))==SQLITE_OK
67172 sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_START, 0);
67189 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
67209 sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_DONE, 0);
67227 walUnlockExclusive(pWal, WAL_READ_LOCK(0), 1);
67268 rc = sqlite3OsTruncate(pWal->pWalFd, 0);
67276 SEH_FREE_ON_ERROR(pIter, 0);
67322 if( pWal->exclusiveMode==0 ){
67327 (pWal->readLock<0 ? 0 : (S << WAL_READ_LOCK(pWal->readLock)))
67328 | (pWal->writeLock ? (E << WAL_WRITE_LOCK) : 0)
67329 | (pWal->ckptLock ? (E << WAL_CKPT_LOCK) : 0)
67331 for(ii=0; ii<SQLITE_SHM_NLOCK; ii++){
67337 pWal->pFree = 0;
67340 pWal->pWiValue = 0;
67353 if( pWal->exclusiveMode==0 ){
67357 (pWal->readLock<0 ? 0 : (S << WAL_READ_LOCK(pWal->readLock)))
67358 | (pWal->writeLock ? (E << WAL_WRITE_LOCK) : 0)
67359 | (pWal->ckptLock ? (E << WAL_CKPT_LOCK) : 0)
67361 | (pWal->pSnapshot ? (pWal->lockMask & (1 << WAL_CKPT_LOCK)) : 0)
67374 int iRet = 0;
67377 pWal->iSysErrno = 0;
67392 int sync_flags, /* Flags to pass to OsSync() (or 0) */
67398 int isDelete = 0; /* True to unlink wal and wal-index files */
67410 if( zBuf!=0
67417 SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0
67429 }else if( pWal->mxWalSize>=0 ){
67433 ** non-negative value (pWal->mxWalSize>=0). Note that we truncate
67436 walLimitSize(pWal, 0);
67445 sqlite3OsDelete(pWal->pVfs, pWal->zWalName, 0);
67456 ** Try to read the wal-index header. Return 0 on success and 1 if
67478 assert( pWal->nWiData>0 && pWal->apWiData[0] );
67487 ** When reading, read [0] first then [1]. Writes are in the reverse order.
67497 memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */
67501 if( memcmp(&h1, &h2, sizeof(h1))!=0 ){
67504 if( h1.isInit==0 ){
67507 walChecksumBytes(1, (u8*)&h1, sizeof(h1)-sizeof(h1.aCksum), 0, aCksum);
67508 if( aCksum[0]!=h1.aCksum[0] || aCksum[1]!=h1.aCksum[1] ){
67515 pWal->szPage = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
67521 return 0;
67537 ** to 0.
67547 /* Ensure that page 0 of the wal-index (the page that contains the
67551 rc = walIndexPage(pWal, 0, &page0);
67561 assert( page0==0 );
67562 assert( pWal->writeLock==0 );
67573 testcase( page0!=0 );
67575 assert( page0!=0 || pWal->writeLock==0 );
67588 if( pWal->bShmUnreliable==0 && (pWal->readOnly & WAL_SHM_RDONLY) ){
67599 if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
67611 if( bWriteLock==0 ){
67612 pWal->writeLock = 0;
67623 if( badHdr==0 && pWal->hdr.iVersion!=WALINDEX_MAX_VERSION ){
67628 walIndexClose(pWal, 0);
67629 pWal->bShmUnreliable = 0;
67630 assert( pWal->nWiData>0 && pWal->apWiData[0]==0 );
67673 u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */
67682 assert( pWal->nWiData>0 && pWal->apWiData[0] );
67684 /* Take WAL_READ_LOCK(0). This has the effect of preventing any
67687 rc = walLockShared(pWal, WAL_READ_LOCK(0));
67692 pWal->readLock = 0;
67704 ** the WAL_READ_LOCK(0) which prevents a checkpoint, a writer might
67716 rc = sqlite3OsShmMap(pWal->pDbFd, 0, WALINDEX_PGSZ, 0, &pDummy);
67738 ** wal-index header has mxFrame==0, then it must be safe to proceed
67744 rc = (pWal->hdr.mxFrame==0 ? SQLITE_OK : WAL_RETRY);
67749 rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0);
67762 assert( (pWal->szPage & (pWal->szPage-1))==0 );
67766 if( aFrame==0 ){
67776 aSaveCksum[0] = pWal->hdr.aFrameCksum[0];
67798 pWal->hdr.aFrameCksum[0] = aSaveCksum[0];
67805 for(i=0; i<pWal->nWiData; i++){
67807 pWal->apWiData[i] = 0;
67809 pWal->bShmUnreliable = 0;
67820 ** int cnt = 0;
67842 # define WAL_RETRY_BLOCKED_MASK 0x10000000
67844 # define WAL_RETRY_BLOCKED_MASK 0
67858 ** checkpointed. If useWal==0 then this routine calls walIndexReadHdr()
67878 ** in the range 0 <= pWal->readLock < WAL_NREADER. If pWal->readLock==(-1)
67882 ** use WAL frames up to and including pWal->hdr.mxFrame if pWal->readLock>0
67883 ** Or if pWal->readLock==0, then the reader will ignore the WAL
67886 ** this routine will always set pWal->readLock>0 on success.
67905 int nBlockTmout = 0;
67908 assert( pWal->readLock<0 ); /* Not currently locked */
67911 assert( (pWal->readOnly & WAL_SHM_RDONLY)==0 || useWal==0 );
67962 if( pWal->bShmUnreliable==0 ){
67981 if( pWal->apWiData[0]==0 ){
68005 assert( pWal->nWiData>0 );
68006 assert( pWal->apWiData[0]!=0 );
68011 && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0)
68017 rc = walLockShared(pWal, WAL_READ_LOCK(0));
68022 ** may have been appended to the log before READ_LOCK(0) was obtained.
68023 ** When holding READ_LOCK(0), the reader ignores the entire log file,
68025 ** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from
68029 ** is wrapped and written for that matter) before the READ_LOCK(0)
68034 walUnlockShared(pWal, WAL_READ_LOCK(0));
68037 pWal->readLock = 0;
68049 mxReadMark = 0;
68050 mxI = 0;
68065 if( (pWal->readOnly & WAL_SHM_RDONLY)==0
68066 && (mxReadMark<mxFrame || mxI==0)
68081 if( mxI==0 ){
68082 assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 );
68097 assert( (rc&0xFF)!=SQLITE_BUSY||rc==SQLITE_BUSY||rc==SQLITE_BUSY_TIMEOUT );
68098 return (rc&0xFF)==SQLITE_BUSY ? WAL_RETRY : rc;
68173 assert( i - sLoc.iZero - 1 >=0 );
68185 if( rc!=SQLITE_OK || 0==memcmp(pBuf1, pBuf2, szPage) ){
68219 assert( pWal->readLock>=0 );
68224 if( pBuf1==0 || pBuf2==0 ){
68232 pWal->ckptLock = 0;
68250 int cnt = 0; /* Number of TryBeginRead attempts */
68252 int ckptLock = 0;
68253 int bChanged = 0;
68257 assert( pWal->ckptLock==0 );
68258 assert( pWal->nSehTry>0 );
68262 if( memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
68286 rc = walTryBeginRead(pWal, pChanged, 0, &cnt);
68288 testcase( (rc&0xff)==SQLITE_BUSY );
68289 testcase( (rc&0xff)==SQLITE_IOERR );
68295 if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
68311 assert( pWal->readLock>0 || pWal->hdr.mxFrame==0 );
68323 assert( pWal->readLock>0 );
68382 if( pWal->readLock>=0 ){
68401 u32 iRead = 0; /* If !=0, WAL frame to return data from */
68407 assert( pWal->readLock>=0 || pWal->lockError );
68409 /* If the "last page" field of the wal-index header snapshot is 0, then
68411 ** in this case as an optimization. Likewise, if pWal->readLock==0,
68415 if( iLast==0 || (pWal->readLock==0 && pWal->bShmUnreliable==0) ){
68416 *piRead = 0;
68460 while( (iH = AtomicLoad(&sLoc.aHash[iKey]))!=0 ){
68466 if( (nCollide--)==0 ){
68467 *piRead = 0;
68480 u32 iRead2 = 0;
68482 assert( pWal->bShmUnreliable || pWal->minFrame>0 );
68483 for(iTest=iLast; iTest>=pWal->minFrame && iTest>0; iTest--){
68535 sz = (sz&0xfe00) + ((sz&0x0001)<<16);
68547 if( pWal && ALWAYS(pWal->readLock>=0) ){
68550 return 0;
68582 assert( pWal->readLock>=0 );
68583 assert( pWal->writeLock==0 && pWal->iReCksum==0 );
68603 if( memcmp(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr))!=0 ){
68611 pWal->writeLock = 0;
68623 pWal->writeLock = 0;
68624 pWal->iReCksum = 0;
68625 pWal->truncateOnCommit = 0;
68687 aWalData[0] = pWal->hdr.mxFrame;
68688 aWalData[1] = pWal->hdr.aFrameCksum[0];
68703 assert( aWalData[3]!=pWal->nCkpt || aWalData[0]<=pWal->hdr.mxFrame );
68710 aWalData[0] = 0;
68714 if( aWalData[0]<pWal->hdr.mxFrame ){
68715 pWal->hdr.mxFrame = aWalData[0];
68716 pWal->hdr.aFrameCksum[0] = aWalData[1];
68732 ** it sets pWal->hdr.mxFrame to 0. Otherwise, pWal->hdr.mxFrame is left
68743 if( pWal->readLock==0 ){
68746 if( pInfo->nBackfill>0 ){
68751 /* If all readers are using WAL_READ_LOCK(0) (in other words if no
68766 walUnlockShared(pWal, WAL_READ_LOCK(0));
68768 cnt = 0;
68773 assert( (rc&0xff)!=SQLITE_BUSY ); /* BUSY not possible when useWal==1 */
68774 testcase( (rc&0xff)==SQLITE_IOERR );
68816 assert( WAL_SYNC_FLAGS(p->syncFlags)!=0 );
68818 if( iAmt==0 || rc ) return rc;
68830 int nTruncate, /* The commit flag. Usually 0. >0 for commit */
68862 if( aBuf==0 ) return SQLITE_NOMEM_BKPT;
68869 assert( pWal->iReCksum>0 );
68876 pWal->hdr.aFrameCksum[0] = sqlite3Get4byte(aBuf);
68880 pWal->iReCksum = 0;
68908 int sync_flags /* Flags to pass to OsSync() (or 0) */
68913 PgHdr *pLast = 0; /* Last frame in list */
68914 int nExtra = 0; /* Number of extra copies of last page */
68918 u32 iFirst = 0; /* First frame that may be overwritten */
68924 /* If this frame set completes a transaction, then nTruncate>0. If
68925 ** nTruncate==0 then this frame set does not complete the transaction. */
68926 assert( (isCommit!=0)==(nTruncate!=0) );
68929 { int cnt; for(cnt=0, p=pList; p; p=p->pDirty, cnt++){}
68936 if( memcmp(&pWal->hdr, (void *)pLive, sizeof(WalIndexHdr))!=0 ){
68952 if( iFrame==0 ){
68956 sqlite3Put4byte(&aWalHdr[0], (WAL_MAGIC | SQLITE_BIGENDIAN));
68960 if( pWal->nCkpt==0 ) sqlite3_randomness(8, pWal->hdr.aSalt);
68962 walChecksumBytes(1, aWalHdr, WAL_HDRSIZE-2*4, 0, aCksum);
68963 sqlite3Put4byte(&aWalHdr[24], aCksum[0]);
68968 pWal->hdr.aFrameCksum[0] = aCksum[0];
68972 rc = sqlite3OsWrite(pWal->pWalFd, aWalHdr, sizeof(aWalHdr), 0);
68997 w.iSyncPoint = 0;
69005 int nDbSize; /* 0 normally. Positive == commit flag */
69011 if( iFirst && (p->pDirty || isCommit==0) ){
69012 u32 iWrite = 0;
69014 assert( rc==SQLITE_OK || iWrite==0 );
69018 if( pWal->iReCksum==0 || iWrite<pWal->iReCksum ){
69031 nDbSize = (isCommit && p->pDirty==0) ? nTruncate : 0;
69059 if( isCommit && WAL_SYNC_FLAGS(sync_flags)!=0 ){
69071 assert( pLast!=0 );
69084 if( isCommit && pWal->truncateOnCommit && pWal->mxWalSize>=0 ){
69090 pWal->truncateOnCommit = 0;
69100 if( (p->flags & PGHDR_WAL_APPEND)==0 ) continue;
69104 assert( pLast!=0 || nExtra==0 );
69105 while( rc==SQLITE_OK && nExtra>0 ){
69113 pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16));
69145 int sync_flags /* Flags to pass to OsSync() (or 0) */
69171 int sync_flags, /* Flags to sync db file with (or 0) */
69178 int isChanged = 0; /* True if a new wal-index header is loaded */
69182 assert( pWal->ckptLock==0 );
69183 assert( pWal->writeLock==0 );
69187 assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
69206 testcase( rc!=SQLITE_OK && xBusy2!=0 );
69216 ** writer lock retried until either the busy-handler returns 0 or the
69225 xBusy2 = 0;
69244 sqlite3OsUnfetch(pWal->pDbFd, 0, 0);
69273 memset(&pWal->hdr, 0, sizeof(WalIndexHdr));
69277 sqlite3WalDb(pWal, 0);
69283 pWal->ckptLock = 0;
69295 ** the last call, then return 0.
69298 u32 ret = 0;
69301 pWal->iCallback = 0;
69313 ** or if the acquisition of the lock fails, then return 0. If the
69320 ** be released. Return 1 if the transition is made and 0 if the
69332 assert( pWal->writeLock==0 );
69342 assert( pWal->readLock>=0 || pWal->lockError );
69344 assert( pWal->readLock>=0 || (op<=0 && pWal->exclusiveMode==0) );
69346 if( op==0 ){
69355 rc = 0;
69357 }else if( op>0 ){
69359 assert( pWal->readLock>=0 );
69386 static const u32 aZero[4] = { 0, 0, 0, 0 };
69388 assert( pWal->readLock>=0 && pWal->writeLock==0 );
69390 if( memcmp(&pWal->hdr.aFrameCksum[0],aZero,16)==0 ){
69391 *ppSnapshot = 0;
69395 if( pRet==0 ){
69422 /* aSalt[0] is a copy of the value stored in the wal file header. It
69424 if( pHdr1->aSalt[0]<pHdr2->aSalt[0] ) return -1;
69425 if( pHdr1->aSalt[0]>pHdr2->aSalt[0] ) return +1;
69428 return 0;
69479 assert( pWal==0 || pWal->readLock>=0 );
69480 return (pWal ? pWal->szPage : 0);
69535 ** | Ptr(0) | Key(0) | Ptr(1) | Key(1) | ... | Key(N-1) | Ptr(N) |
69538 ** All of the keys on the page that Ptr(0) points to have values less
69539 ** than Key(0). All of the keys on page Ptr(1) and its subpages have
69540 ** values greater than Key(0) and less than Key(1). All of the keys
69570 ** 0 16 Header string: "SQLite format 3\000"
69641 ** 0 1 Flags. 1: intkey, 2: zerodata, 4: leafdata, 8: leaf
69690 ** 0x00 becomes 0x00000000
69691 ** 0x7f becomes 0x0000007f
69692 ** 0x81 0x00 becomes 0x00000080
69693 ** 0x82 0x00 becomes 0x00000100
69694 ** 0x80 0x7f becomes 0x0000007f
69695 ** 0x81 0x91 0xd1 0xac 0x78 becomes 0x12345678
69696 ** 0x81 0x81 0x81 0x81 0x01 becomes 0x10204081
69768 #define PTF_INTKEY 0x01
69769 #define PTF_ZERODATA 0x02
69770 #define PTF_LEAFDATA 0x04
69771 #define PTF_LEAF 0x08
69793 u8 hdrOffset; /* 100 for page 1. 0 otherwise */
69794 u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
69887 #define TRANS_NONE 0
69915 ** may not be modified once it is initially set as long as nRef>0.
69917 ** thereafter is unchanged as long as nRef>0.
69977 #define BTS_READ_ONLY 0x0001 /* Underlying file is readonly */
69978 #define BTS_PAGESIZE_FIXED 0x0002 /* Page size can no longer be changed */
69979 #define BTS_SECURE_DELETE 0x0004 /* PRAGMA secure_delete is enabled */
69980 #define BTS_OVERWRITE 0x0008 /* Overwrite deleted content with zeros */
69981 #define BTS_FAST_SECURE 0x000c /* Combination of the previous two */
69982 #define BTS_INITIALLY_EMPTY 0x0010 /* Database was empty at trans start */
69983 #define BTS_NO_WAL 0x0020 /* Do not open write-ahead-log files */
69984 #define BTS_EXCLUSIVE 0x0040 /* pWriter has an exclusive lock */
69985 #define BTS_PENDING 0x0080 /* Waiting for read-locks to clear */
70031 ** SKIPNEXT sqlite3BtreeNext() is a no-op if skipNext>0 and
70032 ** sqlite3BtreePrevious() is no-op if skipNext<0.
70034 ** eState=SKIPNEXT if skipNext!=0
70057 u8 curIntKey; /* Value of apPage[0]->intKey */
70068 #define BTCF_WriteFlag 0x01 /* True if a write cursor */
70069 #define BTCF_ValidNKey 0x02 /* True if info.nKey is valid */
70070 #define BTCF_ValidOvfl 0x04 /* True if aOverflow is valid */
70071 #define BTCF_AtLast 0x08 /* Cursor is pointing to the last entry */
70072 #define BTCF_Incrblob 0x10 /* True if an incremental I/O handle */
70073 #define BTCF_Multiple 0x20 /* Maybe another cursor on the same btree */
70074 #define BTCF_Pinned 0x40 /* Cursor is busy and cannot be moved */
70106 #define CURSOR_VALID 0
70140 ** 0 or 1 parent pages. (In this context 'database page' refers
70177 assert( p->pBt->inTransaction!=TRANS_NONE || p->pBt->nTransaction==0 ); \
70191 #define ISAUTOVACUUM(pBt) 0
70210 Pgno nCkPage; /* Pages in the database. 0 for partial check */
70228 #define get2byte(x) ((x)[0]<<8 | (x)[1])
70229 #define put2byte(p,v) ((p)[0] = (u8)((v)>>8), (p)[1] = (u8)(v))
70245 # define get2byteAligned(x) ((x)[0]<<8 | (x)[1])
70259 assert( p->locked==0 );
70280 p->locked = 0;
70307 assert( p->pNext==0 || p->pNext->pBt>p->pBt );
70308 assert( p->pPrev==0 || p->pPrev->pBt<p->pBt );
70309 assert( p->pNext==0 || p->pNext->db==p->db );
70310 assert( p->pPrev==0 || p->pPrev->db==p->db );
70311 assert( p->sharable || (p->pNext==0 && p->pPrev==0) );
70314 assert( !p->locked || p->wantToLock>0 );
70315 assert( p->sharable || p->wantToLock==0 );
70322 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );
70356 assert( pLater->pNext==0 || pLater->pNext->pBt>pLater->pBt );
70357 assert( !pLater->locked || pLater->wantToLock>0 );
70377 assert( p->wantToLock>0 );
70379 if( p->wantToLock==0 ){
70393 assert( p->sharable==0 || p->locked==0 || p->wantToLock>0 );
70394 assert( p->sharable==0 || p->locked==0 || p->db==p->pBt->db );
70395 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->pBt->mutex) );
70396 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->db->mutex) );
70398 return (p->sharable==0 || p->locked);
70422 for(i=0; i<db->nDb; i++){
70426 skipOk = 0;
70432 if( db->noSharedCache==0 ) btreeEnterAll(db);
70438 for(i=0; i<db->nDb; i++){
70444 if( db->noSharedCache==0 ) btreeLeaveAll(db);
70457 return 0;
70459 for(i=0; i<db->nDb; i++){
70463 (p->wantToLock==0 || !sqlite3_mutex_held(p->pBt->mutex)) ){
70464 return 0;
70485 assert( db!=0 );
70486 if( db->pVfs==0 && db->nDb==0 ) return 1;
70488 assert( iDb>=0 && iDb<db->nDb );
70489 if( !sqlite3_mutex_held(db->mutex) ) return 0;
70492 assert( p!=0 );
70493 return p->sharable==0 || p->locked==1;
70497 #else /* SQLITE_THREADSAFE>0 above. SQLITE_THREADSAFE==0 below */
70513 for(i=0; i<db->nDb; i++){
70571 #if 0
70587 #define get2byteNotZero(X) (((((int)get2byte(X))-1)&0xffff)+1)
70592 #define BTALLOC_ANY 0 /* Allocate any page */
70598 ** defined, or 0 if it is. For example:
70605 #define IfNotOmitAV(expr) 0
70618 SQLITE_PRIVATE BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
70620 static BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
70655 #define hasReadConflicts(a, b) 0
70664 pBt->nSeek = 0;
70683 p->pgno, sqlite3PagerFilename(p->pBt->pPager, 0)
70705 #if 0
70718 if( iRoot>0 ){
70743 ** table with root page iRoot. Return 1 if it does and 0 if not.
70748 ** assert( hasSharedCacheTableLock(pBtree, iRoot, 0, WRITE_LOCK) );
70768 Pgno iTab = 0;
70775 if( (pBtree->sharable==0)
70786 if( isIndex && (!pSchema || (pSchema->schemaFlags&DB_SchemaLoaded)==0) ){
70796 int bSeen = 0;
70829 return 0;
70857 && 0==(p->pBtree->db->flags & SQLITE_ReadUncommit)
70862 return 0;
70878 assert( p->db!=0 );
70896 if( pBt->pWriter!=p && (pBt->btsFlags & BTS_EXCLUSIVE)!=0 ){
70946 BtLock *pLock = 0;
70953 assert( p->db!=0 );
70959 assert( 0==(p->db->flags&SQLITE_ReadUncommit) || eLock==WRITE_LOCK );
71015 assert( p->sharable || 0==*ppIter );
71016 assert( p->inTrans>0 );
71018 SHARED_LOCK_TRACE(pBt, "clearAllLocks", 0, 0);
71022 assert( (pBt->btsFlags & BTS_EXCLUSIVE)==0 || pBt->pWriter==pLock->pBtree );
71035 assert( (pBt->btsFlags & BTS_PENDING)==0 || pBt->pWriter );
71037 pBt->pWriter = 0;
71044 ** set the BTS_PENDING flag to 0.
71059 SHARED_LOCK_TRACE(pBt, "downgradeLocks", 0, 0);
71063 pBt->pWriter = 0;
71143 pBtree->hasIncrblobCur = 0;
71145 if( (p->curFlags & BTCF_Incrblob)!=0 ){
71227 pBt->pHasContent = 0;
71235 if( pCur->iPage>=0 ){
71236 for(i=0; i<pCur->iPage; i++){
71260 assert( 0==pCur->pKey );
71277 rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey);
71279 memset(((u8*)pKey)+pCur->nKey, 0, 9+8);
71303 assert( 0==pCur->pKey );
71312 pCur->skipNext = 0;
71352 assert( pExcept==0 || pExcept->pBt==pBt );
71354 if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ) break;
71372 if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){
71379 testcase( p->iPage>=0 );
71394 pCur->pKey = 0;
71417 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
71419 if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
71426 pIdxKey = 0;
71441 int skipNext = 0;
71451 rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
71455 pCur->pKey = 0;
71485 assert( offsetof(BtCursor, eState)==0 );
71497 assert( offsetof(BtCursor, eState)==0 );
71517 assert( pCur!=0 );
71527 *pDifferentRow = 0;
71545 memset(&w, 0, sizeof(w));
71551 assert( pExpr!=0 );
71552 assert( w.u.aMem!=0 );
71564 assert( x==BTREE_SEEK_EQ || x==BTREE_BULKLOAD || x==0 );
71575 ** Return 0 (not a valid page) for pgno==1 since there is
71583 if( pgno<2 ) return 0;
71614 assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) );
71617 if( key==0 ){
71622 rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage, 0);
71627 if( ((char*)sqlite3PagerGetExtra(pDbPage))[0]!=0 ){
71635 if( offset<0 ){
71672 rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage, 0);
71673 if( rc!=0 ){
71679 if( offset<0 ){
71684 assert( pEType!=0 );
71700 ** Given a btree page and a cell index (0 means the first cell on
71790 assert( pPage->leaf==0 );
71796 pInfo->nPayload = 0;
71797 pInfo->nLocal = 0;
71798 pInfo->pPayload = 0;
71811 assert( pPage->leaf==0 || pPage->leaf==1 );
71813 assert( pPage->childPtrSize==0 );
71823 if( nPayload>=0x80 ){
71825 nPayload &= 0x7f;
71827 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
71828 }while( (*pIter)>=0x80 && pIter<pEnd );
71840 if( iKey>=0x80 ){
71843 if( x>=0x80 ){
71845 if( x>=0x80 ){
71846 iKey = (iKey<<7) ^ 0x10204000 ^ (x = *++pIter);
71847 if( x>=0x80 ){
71848 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++pIter);
71849 if( x>=0x80 ){
71850 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++pIter);
71851 if( x>=0x80 ){
71852 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++pIter);
71853 if( x>=0x80 ){
71854 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++pIter);
71855 if( x>=0x80 ){
71856 iKey = (iKey<<8) ^ 0x8000 ^ (*++pIter);
71863 iKey ^= 0x204000;
71866 iKey ^= 0x4000;
71896 assert( pPage->leaf==0 || pPage->leaf==1 );
71897 assert( pPage->intKeyLeaf==0 );
71900 if( nPayload>=0x80 ){
71902 nPayload &= 0x7f;
71904 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
71905 }while( *(pIter)>=0x80 && pIter<pEnd );
71926 int iCell, /* The cell index. First cell is 0 */
71962 if( nSize>=0x80 ){
71964 nSize &= 0x7f;
71966 nSize = (nSize<<7) | (*++pIter & 0x7f);
71967 }while( *(pIter)>=0x80 && pIter<pEnd );
72002 assert( pPage->childPtrSize==0 );
72004 if( nSize>=0x80 ){
72006 nSize &= 0x7f;
72008 nSize = (nSize<<7) | (*++pIter & 0x7f);
72009 }while( *(pIter)>=0x80 && pIter<pEnd );
72047 while( (*pIter++)&0x80 && pIter<pEnd );
72066 if( nSize>=0x80 ){
72068 nSize &= 0x7f;
72070 nSize = (nSize<<7) | (*++pIter & 0x7f);
72071 }while( *(pIter)>=0x80 && pIter<pEnd );
72077 if( (*pIter++)&0x80
72078 && (*pIter++)&0x80
72079 && (*pIter++)&0x80
72080 && (*pIter++)&0x80
72081 && (*pIter++)&0x80
72082 && (*pIter++)&0x80
72083 && (*pIter++)&0x80
72084 && (*pIter++)&0x80 ){ pIter++; }
72123 assert( pCell!=0 );
72168 assert( pPage->pBt!=0 );
72170 assert( pPage->nOverflow==0 );
72191 if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){
72194 int sz2 = 0;
72226 if( nCell>0 ){
72230 for(i=0; i<nCell; i++){
72242 assert( pc>=0 && pc<=iCellLast );
72255 data[hdr+7] = 0;
72258 assert( pPage->nFree>=0 );
72264 data[hdr+1] = 0;
72265 data[hdr+2] = 0;
72266 memset(&data[iCellFirst], 0, cbrk-iCellFirst);
72295 assert( pc>0 );
72302 if( (x = size - nByte)>=0 ){
72308 if( aData[hdr+7]>57 ) return 0;
72318 return 0;
72334 return 0;
72341 return 0;
72368 assert( nByte>=0 ); /* Minimum cell size is 4 */
72370 assert( pPage->nOverflow==0 );
72380 ** integer, so a value of 0 is used in its place. */
72384 if( top==0 && pPage->pBt->usableSize==65536 ){
72421 assert( pPage->nCell>0 || CORRUPT_DB );
72422 assert( pPage->nFree>=0 );
72459 u8 hdr; /* Page header size. 0 or 100 */
72460 u8 nFrag = 0; /* Reduction in fragmentation */
72467 assert( pPage->pBt!=0 );
72480 if( data[iPtr+1]==0 && data[iPtr]==0 ){
72481 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
72485 if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
72493 assert( iFreeBlk>iPtr || iFreeBlk==0 || CORRUPT_DB );
72533 memset(&data[iStart], 0, iSize);
72560 ** PTF_ZERODATA (0x02, 2)
72561 ** PTF_LEAFDATA | PTF_INTKEY (0x05, 5)
72562 ** PTF_ZERODATA | PTF_LEAF (0x0a, 10)
72563 ** PTF_LEAFDATA | PTF_INTKEY | PTF_LEAF (0x0d, 13)
72568 assert( pPage->hdrOffset==(pPage->pgno==1 ? 100 : 0) );
72573 pPage->childPtrSize = 0;
72583 pPage->intKey = 0;
72584 pPage->intKeyLeaf = 0;
72590 pPage->intKey = 0;
72591 pPage->intKeyLeaf = 0;
72598 pPage->leaf = 0;
72600 pPage->intKey = 0;
72601 pPage->intKeyLeaf = 0;
72607 pPage->intKeyLeaf = 0;
72614 pPage->intKey = 0;
72615 pPage->intKeyLeaf = 0;
72638 assert( pPage->pBt!=0 );
72639 assert( pPage->pBt->db!=0 );
72645 assert( pPage->nFree<0 );
72663 if( pc>0 ){
72682 if( next>0 ){
72726 for(i=0; i<pPage->nCell; i++){
72755 assert( pPage->pBt!=0 );
72756 assert( pPage->pBt->db!=0 );
72761 assert( pPage->isInit==0 );
72765 /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
72767 if( decodeFlags(pPage, data[0]) ){
72772 pPage->nOverflow = 0;
72789 assert( pPage->nCell>0
72816 memset(&data[hdr], 0, pBt->usableSize - hdr);
72819 first = hdr + ((flags&PTF_LEAF)==0 ? 12 : 8);
72820 memset(&data[hdr+1], 0, 4);
72821 data[hdr+7] = 0;
72829 pPage->nOverflow = 0;
72832 pPage->nCell = 0;
72848 pPage->hdrOffset = pgno==1 ? 100 : 0;
72874 assert( flags==0 || flags==PAGER_GET_NOCONTENT || flags==PAGER_GET_READONLY );
72894 return 0;
72924 *ppPage = 0;
72929 *ppPage = 0;
72933 if( pPage->isInit==0 ){
72938 *ppPage = 0;
72957 assert( pPage->pDbPage!=0 );
72967 assert( pPage!=0 );
72970 assert( pPage->pDbPage!=0 );
72996 *ppPage = 0;
72999 (*ppPage)->isInit = 0;
73001 *ppPage = 0;
73018 assert( sqlite3PagerPageRefcount(pData)>0 );
73021 pPage->isInit = 0;
73073 BtShared *pBt = 0; /* Shared part of btree structure */
73075 sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */
73081 const int isTempDb = zFilename==0 || zFilename[0]==0;
73087 const int isMemdb = 0;
73089 const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
73091 || (vfsFlags & SQLITE_OPEN_MEMORY)!=0;
73094 assert( db!=0 );
73095 assert( pVfs!=0 );
73097 assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
73100 assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 );
73103 assert( (flags & BTREE_SINGLE)==0 || isTempDb );
73108 if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){
73127 if( isTempDb==0 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=0) ){
73161 assert( pBt->nRef>0 );
73162 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0))
73165 for(iDb=db->nDb-1; iDb>=0; iDb--){
73195 if( pBt==0 ){
73208 memset(&zDbHeader[16], 0, 8);
73211 if( pBt==0 ){
73229 pBt->pCursor = 0;
73230 pBt->pPage1 = 0;
73242 || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
73243 pBt->pageSize = 0;
73246 ** leave the autoVacuum mode at 0 (do not auto-vacuum), even if
73252 pBt->autoVacuum = (SQLITE_DEFAULT_AUTOVACUUM ? 1 : 0);
73253 pBt->incrVacuum = (SQLITE_DEFAULT_AUTOVACUUM==2 ? 1 : 0);
73256 nReserve = 0;
73264 pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
73265 pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
73271 assert( (pBt->pageSize & 7)==0 ); /* 8-byte alignment of pageSize */
73282 if( pBt->mutex==0 ){
73303 for(i=0; i<db->nDb; i++){
73304 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
73308 p->pPrev = 0;
73331 sqlite3PagerClose(pBt->pPager, 0);
73335 *ppBtree = 0;
73343 if( sqlite3BtreeSchema(p, 0, 0)==0 ){
73356 assert( rc!=SQLITE_OK || sqlite3BtreeConnectionCount(*ppBtree)>0 );
73370 int removed = 0;
73376 if( pBt->nRef<=0 ){
73406 assert( pBt!=0 );
73407 assert( pBt->pTmpSpace==0 );
73410 assert( pBt->pCursor!=0 && (pBt->pCursor->curFlags & BTCF_WriteFlag)!=0 );
73412 if( pBt->pTmpSpace==0 ){
73415 memset(pCur, 0, sizeof(*pCur));
73434 memset(pBt->pTmpSpace, 0, 8);
73446 pBt->pTmpSpace = 0;
73477 sqlite3BtreeRollback(p, SQLITE_OK, 0);
73484 assert( p->wantToLock==0 && p->locked==0 );
73496 sqlite3DbFree(0, pBt->pSchema);
73502 assert( p->wantToLock==0 );
73503 assert( p->locked==0 );
73536 ** using mxPage of 0 is a way to query the current spill size.
73548 #if SQLITE_MAX_MMAP_SIZE>0
73561 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
73596 ** the first byte past the 1GB boundary, 0x40000000) needs to occur
73602 ** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size
73609 assert( nReserve>=0 && nReserve<=255 );
73618 assert( nReserve>=0 && nReserve<=255 );
73620 ((pageSize-1)&pageSize)==0 ){
73621 assert( (pageSize & 7)==0 );
73680 ** No changes are made if mxPage is 0 or negative.
73694 ** newFlag==0 Both BTS_SECURE_DELETE and BTS_OVERWRITE are cleared
73711 if( p==0 ) return 0;
73715 if( newFlag>=0 ){
73739 if( (pBt->btsFlags & BTS_PAGESIZE_FIXED)!=0 && (av ?1:0)!=pBt->autoVacuum ){
73742 pBt->autoVacuum = av ?1:0;
73743 pBt->incrVacuum = av==2 ?1:0;
73752 ** enabled 1 is returned. Otherwise 0.
73781 if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){
73782 while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; }
73783 if( pDb->bSyncSet==0
73814 u32 nPageFile = 0; /* Number of pages in the database file */
73817 assert( pBt->pPage1==0 );
73820 rc = btreeGetPage(pBt, 1, &pPage1, 0);
73828 if( nPage==0 || memcmp(24+(u8*)pPage1->aData, 92+(u8*)pPage1->aData,4)!=0 ){
73831 if( (pBt->db->flags & SQLITE_ResetDatabase)!=0 ){
73832 nPage = 0;
73834 if( nPage>0 ){
73842 if( memcmp(page1, zMagicHeader, 16)!=0 ){
73869 if( page1[19]==2 && (pBt->btsFlags & BTS_NO_WAL)==0 ){
73870 int isOpen = 0;
73876 if( isOpen==0 ){
73891 ** version 3.6.0, we require them to be fixed.
73893 if( memcmp(&page1[21], "\100\040\040",3)!=0 ){
73902 if( ((pageSize-1)&pageSize)!=0
73908 assert( (pageSize & 7)==0 );
73934 if( sqlite3WritableSchema(pBt->db)==0 ){
73951 pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0);
73952 pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0);
73966 ** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow
73985 pBt->pPage1 = 0;
74004 int r = 0;
74006 if( (wrOnly==0 || (pCur->curFlags & BTCF_WriteFlag)!=0)
74023 assert( countValidCursors(pBt,0)==0 || pBt->inTransaction>TRANS_NONE );
74024 if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){
74028 pBt->pPage1 = 0;
74044 if( pBt->nPage>0 ){
74048 assert( pP1!=0 );
74054 data[16] = (u8)((pBt->pageSize>>8)&0xff);
74055 data[17] = (u8)((pBt->pageSize>>16)&0xff);
74063 memset(&data[24], 0, 100-24);
74067 assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
74068 assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
74085 p->pBt->nPage = 0;
74145 assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 );
74148 && sqlite3PagerIsreadonly(pPager)==0
74154 if( (pBt->btsFlags & BTS_READ_ONLY)!=0 && wrflag ){
74161 sqlite3 *pBlock = 0;
74167 || (pBt->btsFlags & BTS_PENDING)!=0
74194 if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY;
74201 if( pBt->pPage1==0 && wrflag ){
74210 ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
74215 while( pBt->pPage1==0 && SQLITE_OK==(rc = lockBtree(pBt)) );
74218 if( (pBt->btsFlags & BTS_READ_ONLY)!=0 ){
74234 (void)sqlite3PagerWalWriteLock(pPager, 0);
74237 }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
74239 sqlite3PagerWalDb(pPager, 0);
74291 ** open savepoints. If the second parameter is greater than 0 and
74306 || (p->inTrans==TRANS_READ && wrflag!=0)
74316 ** open savepoints. If the second parameter is greater than 0 and
74344 for(i=0; i<nCell; i++){
74395 for(i=0; i<nCell; i++){
74484 if( nextOvfl!=0 ){
74497 rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0);
74547 if( nFreeList==0 ){
74560 if( bCommit==0 ){
74579 Pgno iNear = 0; /* nearby parameter for allocateBtreePage() */
74581 rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0);
74593 if( bCommit==0 ){
74621 if( bCommit==0 ){
74677 }else if( nFree>0 ){
74678 rc = saveAllCursors(pBt, 0, 0);
74681 rc = incrVacuumStep(pBt, nFin, nOrig, 0);
74706 assert( p!=0 );
74734 for(iDb=0; ALWAYS(iDb<db->nDb); iDb++){
74747 if( nVac==0 ){
74756 rc = saveAllCursors(pBt, 0, 0);
74761 if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
74764 put4byte(&pBt->pPage1->aData[32], 0);
74765 put4byte(&pBt->pPage1->aData[36], 0);
74827 rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zSuperJrnl, 0);
74843 pBt->bDoTruncate = 0;
74854 ** reaches 0, set the shared state to TRANS_NONE. The unlockBtreeIfUnused()
74859 if( 0==pBt->nTransaction ){
74912 assert( pBt->nTransaction>0 );
74914 if( rc!=SQLITE_OK && bCleanup==0 ){
74934 rc = sqlite3BtreeCommitPhaseOne(p, 0);
74936 rc = sqlite3BtreeCommitPhaseTwo(p, 0);
74972 assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
74976 if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){
74980 (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0);
75002 testcase( nPage==0 );
75003 if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
75024 assert( writeOnly==1 || writeOnly==0 );
75028 rc = tripCode = saveAllCursors(pBt, 0, 0);
75029 if( rc ) writeOnly = 0;
75035 assert( rc==SQLITE_OK || (writeOnly==0 && rc2==SQLITE_OK) );
75052 if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
75056 assert( countValidCursors(pBt, 1)==0 );
75089 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
75090 assert( iStatement>0 );
75120 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
75123 rc = saveAllCursors(pBt, 0, 0);
75129 if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){
75130 pBt->nPage = 0;
75137 assert( CORRUPT_DB || pBt->nPage>0 );
75161 ** cursors open with wrFlag==0 on the same table. Otherwise
75177 ** return a null row (2-bytes: 0x01 0x00).
75189 int wrFlag, /* 1 to write. 0 read-only */
75197 assert( wrFlag==0
75206 assert( hasSharedCacheTableLock(p, iTable, pKeyInfo!=0, (wrFlag?2:1))
75208 assert( wrFlag==0 || !hasReadConflicts(p, iTable) );
75212 assert( wrFlag==0 || p->inTrans==TRANS_WRITE );
75214 assert( wrFlag==0 || (pBt->btsFlags & BTS_READ_ONLY)==0 );
75219 }else if( btreePagecount(pBt)==0 ){
75220 assert( wrFlag==0 );
75221 iTable = 0;
75232 pCur->curFlags = 0;
75246 pCur->curPagerFlags = 0;
75247 if( pBt->pTmpSpace==0 ) return allocateTempSpace(pBt);
75256 int wrFlag, /* 1 to write. 0 read-only */
75269 int wrFlag, /* 1 to write. 0 read-only */
75301 memset(p, 0, offsetof(BtCursor, BTCURSOR_FIRST_UNINIT));
75313 assert( pBt->pCursor!=0 );
75330 if( (pBt->openFlags & BTREE_SINGLE) && pBt->pCursor==0 ){
75333 assert( pBtree->sharable==0 );
75338 pCur->pBtree = 0;
75353 if( a->nKey!=b->nKey ) return 0;
75354 if( a->pPayload!=b->pPayload ) return 0;
75355 if( a->nPayload!=b->nPayload ) return 0;
75356 if( a->nLocal!=b->nLocal ) return 0;
75357 if( a->nSize!=b->nSize ) return 0;
75362 memset(&info, 0, sizeof(info));
75370 if( pCur->info.nSize==0 ){
75389 assert( pCur!=0 );
75411 assert( (pCur->curFlags & BTCF_Pinned)==0 );
75415 assert( (pCur->curFlags & BTCF_Pinned)!=0 );
75491 Pgno next = 0;
75492 MemPage *pPage = 0;
75524 assert( next==0 || rc==SQLITE_DONE );
75526 rc = btreeGetPage(pBt, ovfl, &pPage, (ppPage==0) ? PAGER_GET_READONLY : 0);
75527 assert( rc==SQLITE_OK || pPage==0 );
75557 int eOp, /* 0 -> copy from page, 1 -> copy to page */
75579 ** 0: The operation is a read. Populate the overflow cache.
75612 int iIdx = 0;
75620 assert( eOp==0 || eOp==1 );
75648 offset = 0;
75656 if( rc==SQLITE_OK && amt>0 ){
75666 ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
75669 if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){
75671 if( pCur->aOverflow==0
75676 aNew = 0;
75680 if( aNew==0 ){
75686 memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
75690 assert( pCur->aOverflow[0]==nextPage
75691 || pCur->aOverflow[0]==0
75693 assert( pCur->aOverflow[0]!=0 || pCur->aOverflow[offset/ovflSize]==0 );
75706 assert( rc==SQLITE_OK && amt>0 );
75710 assert( pCur->aOverflow[iIdx]==0
75727 rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
75732 ** range of data that is being read (eOp==0) or written (eOp!=0).
75753 if( eOp==0 /* (1) */
75754 && offset==0 /* (2) */
75772 (eOp==0 ? PAGER_GET_READONLY : 0)
75779 offset = 0;
75783 if( amt==0 ) return rc;
75791 if( rc==SQLITE_OK && amt>0 ){
75818 assert( pCur->iPage>=0 && pCur->pPage );
75819 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
75840 return rc ? rc : accessPayload(pCur, offset, amt, pBuf, 0);
75845 return accessPayload(pCur, offset, amt, pBuf, 0);
75855 ** the key if index btrees (pPage->intKey==0) and is the data for
75857 ** key/data is written into *pAmt. If *pAmt==0, then the value
75876 assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
75881 assert( pCur->info.nSize>0 );
75889 amt = MAX(0, (int)(pCur->pPage->aDataEnd - pCur->info.pPayload));
75929 assert( pCur->iPage>=0 );
75933 pCur->info.nSize = 0;
75937 pCur->ix = 0;
75940 assert( pCur->pPage!=0 || rc!=SQLITE_OK );
75987 assert( pCur->iPage>0 );
75995 pCur->info.nSize = 0;
76019 ** specify a KeyInfo structure the flags byte is set to 0x05 or 0x0D,
76021 ** structure the flags byte is set to 0x02 or 0x0A, indicating an index
76032 assert( pCur->eState < CURSOR_REQUIRESEEK || pCur->iPage<0 );
76033 assert( pCur->pgnoRoot>0 || pCur->iPage<0 );
76035 if( pCur->iPage>=0 ){
76041 pRoot = pCur->pPage = pCur->apPage[0];
76044 }else if( pCur->pgnoRoot==0 ){
76062 pCur->iPage = 0;
76075 ** if pCur->iPage>=0). But this is not so if the database is corrupted
76078 assert( pRoot->intKey==1 || pRoot->intKey==0 );
76079 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
76084 pCur->ix = 0;
76085 pCur->info.nSize = 0;
76088 if( pRoot->nCell>0 ){
76138 MemPage *pPage = 0;
76149 assert( pCur->info.nSize==0 );
76150 assert( (pCur->curFlags & BTCF_ValidNKey)==0 );
76155 ** on success. Set *pRes to 0 if the cursor actually points to something
76165 assert( pCur->pPage->nCell>0 );
76166 *pRes = 0;
76169 assert( pCur->pgnoRoot==0 || (pCur->pPage!=0 && pCur->pPage->nCell==0) );
76186 for(ii=0; ii<pCur->iPage; ii++){
76187 if( pCur->aiIdx[ii]!=pCur->apPage[ii]->nCell ) return 0;
76189 return pCur->ix==pCur->pPage->nCell-1 && pCur->pPage->leaf!=0;
76194 ** on success. Set *pRes to 0 if the cursor actually points to something
76201 *pRes = 0;
76209 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
76220 if( CURSOR_VALID==pCur->eState && (pCur->curFlags & BTCF_AtLast)!=0 ){
76222 *pRes = 0;
76241 ** *pRes<0 The cursor is left pointing at an entry that
76245 ** *pRes==0 The cursor is left pointing at an entry that
76248 ** *pRes>0 The cursor is left pointing at an entry that
76262 assert( pCur->pKeyInfo==0 );
76263 assert( pCur->eState!=CURSOR_VALID || pCur->curIntKey!=0 );
76267 if( pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0 ){
76269 *pRes = 0;
76273 if( (pCur->curFlags & BTCF_AtLast)!=0 ){
76283 *pRes = 0;
76284 rc = sqlite3BtreeNext(pCur, 0);
76304 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
76313 assert( pCur->pPage->nCell > 0 );
76314 assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey );
76329 assert( pPage->nCell>0 );
76331 lwr = 0;
76333 assert( biasRight==0 || biasRight==1 );
76339 while( 0x80 <= *(pCell++) ){
76361 pCur->info.nSize = 0;
76362 *pRes = 0;
76366 assert( lwr+upr>=0 );
76389 pCur->info.nSize = 0;
76390 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
76421 nCell = pCell[0];
76428 }else if( !(pCell[1] & 0x80)
76429 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
76450 for(i=0; i<pCur->iPage; i++){
76452 if( pCur->aiIdx[i]<pPage->nCell ) return 0;
76470 ** *pRes<0 The cursor is left pointing at an entry that
76474 ** *pRes==0 The cursor is left pointing at an entry that
76477 ** *pRes>0 The cursor is left pointing at an entry that
76494 assert( pCur->pKeyInfo!=0 );
76501 pIdxKey->errCode = 0;
76503 || pIdxKey->default_rc==0
76525 && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0
76531 if( pCur->iPage>0
76532 && indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0
76547 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
76558 assert( pCur->pPage->nCell > 0 );
76559 assert( pCur->curIntKey==0 );
76560 assert( pIdxKey!=0 );
76573 assert( pPage->nCell>0 );
76574 assert( pPage->intKey==0 );
76575 lwr = 0;
76590 nCell = pCell[0];
76597 }else if( !(pCell[1] & 0x80)
76598 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
76619 testcase( nCell<0 ); /* True if key size is 2^32 or more */
76620 testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
76621 testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
76628 if( pCellKey==0 ){
76633 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
76634 memset(((u8*)pCellKey)+nCell,0,nOverrun); /* Fix uninit warnings */
76644 (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
76647 if( c<0 ){
76649 }else if( c>0 ){
76652 assert( c==0 );
76653 *pRes = 0;
76660 assert( lwr+upr>=0 );
76684 pCur->info.nSize = 0;
76691 pCur->ix = 0;
76708 pCur->info.nSize = 0;
76709 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
76744 if( pCur->eState!=CURSOR_VALID ) return 0;
76745 if( NEVER(pCur->pPage->leaf==0) ) return -1;
76748 for(i=0; i<pCur->iPage; i++){
76768 ** If bit 0x01 of the F argument in sqlite3BtreeNext(C,F) is 1, then the
76781 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
76791 if( pCur->skipNext>0 ) return SQLITE_OK;
76797 if( sqlite3FaultSim(412) ) pPage->isInit = 0;
76809 if( pCur->iPage==0 ){
76817 return sqlite3BtreeNext(pCur, 0);
76832 assert( flags==0 || flags==1 );
76833 pCur->info.nSize = 0;
76862 ** If bit 0x01 of the F argument to sqlite3BtreePrevious(C,F) is 1, then
76873 assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
76874 assert( pCur->info.nSize==0 );
76885 if( pCur->skipNext<0 ) return SQLITE_OK;
76890 if( sqlite3FaultSim(412) ) pPage->isInit = 0;
76900 while( pCur->ix==0 ){
76901 if( pCur->iPage==0 ){
76907 assert( pCur->info.nSize==0 );
76908 assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
76913 rc = sqlite3BtreePrevious(pCur, 0);
76922 assert( flags==0 || flags==1 );
76925 pCur->info.nSize = 0;
76927 || pCur->ix==0
76928 || pCur->pPage->leaf==0
76947 ** If the "nearby" parameter is not 0, then an effort is made to
76969 MemPage *pTrunk = 0;
76970 MemPage *pPrevTrunk = 0;
76974 assert( eMode==BTALLOC_ANY || (nearby>0 && IfNotOmitAV(pBt->autoVacuum)) );
76984 if( n>0 ){
76987 u8 searchList = 0; /* If the free-list must be searched for 'nearby' */
76988 u32 nSearch = 0; /* Count of the number of search attempts */
76998 assert( nearby>0 );
77000 rc = ptrmapGet(pBt, nearby, &eType, 0);
77029 iTrunk = get4byte(&pPrevTrunk->aData[0]);
77040 rc = btreeGetUnusedPage(pBt, iTrunk, &pTrunk, 0);
77043 pTrunk = 0;
77046 assert( pTrunk!=0 );
77047 assert( pTrunk->aData!=0 );
77051 if( k==0 && !searchList ){
77055 assert( pPrevTrunk==0 );
77061 memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
77063 pTrunk = 0;
77078 searchList = 0;
77083 if( k==0 ){
77085 memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
77091 memcpy(&pPrevTrunk->aData[0], &pTrunk->aData[0], 4);
77105 rc = btreeGetUnusedPage(pBt, iNewTrunk, &pNewTrunk, 0);
77114 memcpy(&pNewTrunk->aData[0], &pTrunk->aData[0], 4);
77126 put4byte(&pPrevTrunk->aData[0], iNewTrunk);
77129 pTrunk = 0;
77132 }else if( k>0 ){
77137 if( nearby>0 ){
77139 closest = 0;
77141 for(i=0; i<k; i++){
77160 closest = 0;
77184 noContent = !btreeGetHasContent(pBt, *pPgno)? PAGER_GET_NOCONTENT : 0;
77190 *ppPage = 0;
77193 searchList = 0;
77197 pPrevTrunk = 0;
77218 int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate))? PAGER_GET_NOCONTENT:0;
77231 MemPage *pPg = 0;
77253 *ppPage = 0;
77264 assert( rc!=SQLITE_OK || (*ppPage)->isInit==0 );
77281 MemPage *pTrunk = 0; /* Free-list trunk page */
77282 Pgno iTrunk = 0; /* Page number of free-list trunk page */
77312 if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
77313 || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0)
77317 memset(pPage->aData, 0, pPage->pBt->pageSize);
77324 ptrmapPut(pBt, iPage, PTRMAP_FREEPAGE, 0, &rc);
77335 if( nFree!=0 ){
77343 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
77361 ** 3.6.0, databases with freelist trunk pages holding more than
77366 ** to 3.6.0 or later) we should consider fixing the conditional above
77378 if( pPage && (pBt->btsFlags & BTS_SECURE_DELETE)==0 ){
77394 if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0)) ){
77402 put4byte(&pPage->aData[4], 0);
77408 pPage->isInit = 0;
77447 assert( nOvfl>0 ||
77451 Pgno iNext = 0;
77452 MemPage *pOvfl = 0;
77454 /* 0 is not a legal page number and page 1 cannot be an
77464 if( ( pOvfl || ((pOvfl = btreePageLookup(pBt, ovflPgno))!=0) )
77552 assert( pX->nKey<=0x7fffffff && pX->pKey!=0 );
77568 pPayload[nPayload] = 0;
77574 memset(pPayload+nSrc, 0, nPayload-nSrc);
77589 pToRelease = 0;
77590 pgnoOvfl = 0;
77623 assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );
77632 }else if( nSrc>0 ){
77636 memset(pPayload, 0, n);
77639 if( nPayload<=0 ) break;
77644 if( spaceLeft==0 ){
77645 MemPage *pOvfl = 0;
77656 rc = allocateBtreePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, 0);
77683 assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );
77694 put4byte(pPrior, 0);
77716 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
77719 assert( idx>=0 );
77724 assert( pPage->nFree>=0 );
77742 if( pPage->nCell==0 ){
77743 memset(&data[hdr+1], 0, 4);
77744 data[hdr+7] = 0;
77783 int idx = 0; /* Where to write new cell content in data[] */
77788 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
77795 assert( pPage->nFree>=0 );
77796 assert( iChild>0 );
77816 assert( j==0 || pPage->aiOvfl[j-1]<(u16)i ); /* Overflows in sorted order */
77817 assert( j==0 || i==pPage->aiOvfl[j-1]+1 ); /* Overflows are sequential */
77830 assert( idx >= 0 );
77846 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
77878 int idx = 0; /* Where to write new cell content in data[] */
77883 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
77890 assert( pPage->nFree>=0 );
77891 assert( pPage->nOverflow==0 );
77906 assert( j==0 || pPage->aiOvfl[j-1]<(u16)i ); /* Overflows in sorted order */
77907 assert( j==0 || i==pPage->aiOvfl[j-1]+1 ); /* Overflows are sequential */
77920 assert( idx >= 0 );
77930 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
78011 ** ixNx[0] = Number of cells in Child-1.
78017 ** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
78020 ** ixNx[0] = Number of cells in Child-1.
78046 assert( idx>=0 && idx+N<=p->nCell );
78047 while( N>0 ){
78048 assert( p->apCell[idx]!=0 );
78049 if( szCell[idx]==0 ){
78064 assert( N>=0 && N<p->nCell );
78065 assert( p->szCell[N]==0 );
78070 assert( N>=0 && N<p->nCell );
78107 assert( nCell>0 );
78110 if( j>(u32)usableSize ){ j = 0; }
78113 for(k=0; ALWAYS(k<NB*2) && pCArray->ixNx[k]<=i; k++){}
78120 assert( sz>0 );
78146 pPg->nOverflow = 0;
78148 put2byte(&aData[hdr+1], 0);
78151 aData[hdr+7] = 0x00;
78163 ** (part of page pPg) to populate. After cell apCell[0] is written to the
78194 assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
78195 if( iEnd<=iFirst ) return 0;
78196 for(k=0; ALWAYS(k<NB*2) && pCArray->ixNx[k]<=i ; k++){}
78201 assert( pCArray->szCell[i]!=0 );
78203 if( (aData[1]==0 && aData[2]==0) || (pSlot = pageFindSlot(pPg,sz,&rc))==0 ){
78232 return 0;
78253 int nRet = 0;
78256 int nFree = 0;
78269 sz = pCArray->szCell[i]; assert( sz>0 );
78272 for(j=0; j<nFree; j++){
78282 if( nFree>=(int)(sizeof(aOfst)/sizeof(aOfst[0])) ){
78283 for(j=0; j<nFree; j++){
78286 nFree = 0;
78290 if( &aData[iAfter]>pEnd ) return 0;
78296 for(j=0; j<nFree; j++){
78337 assert( nCell>=0 );
78357 assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
78358 assert( nAdd>=0 );
78369 for(i=0; i<pPg->nOverflow; i++){
78371 if( iCell>=0 && iCell<nNew ){
78386 assert( nCell>=0 );
78394 pPg->nOverflow = 0;
78400 for(i=0; i<nNew && !CORRUPT_DB; i++){
78406 assert( 0==memcmp(pCell, &aData[iOff],
78454 if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT; /* dbfuzz001.test */
78455 assert( pPage->nFree>=0 );
78456 assert( pParent->nFree>=0 );
78462 rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
78467 u8 *pCell = pPage->apOvfl[0];
78473 assert( CORRUPT_DB || pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
78479 b.apEnd[0] = pPage->aDataEnd;
78480 b.ixNx[0] = 2;
78481 rc = rebuildPage(&b, 0, 1, pNew);
78519 while( (*(pCell++)&0x80) && pCell<pStop );
78521 while( ((*(pOut++) = *(pCell++))&0x80) && pCell<pStop );
78526 0, pPage->pgno);
78540 #if 0
78548 for(i=0; i<nPage; i++){
78555 for(j=0; j<pPage->nCell; j++){
78605 int const iToHdr = ((pTo->pgno==1) ? 100 : 0);
78624 pTo->isInit = 0;
78689 int nMaxCells = 0; /* Allocated size of apCell, szCell, aFrom. */
78690 int nNew = 0; /* Number of pages in apNew[] */
78695 u16 leafCorrection; /* 4 if pPage is a leaf. 0 if not */
78698 int pageFlags; /* Value of pPage->aData[0] */
78699 int iSpace1 = 0; /* First unused byte of aSpace1[] */
78700 int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */
78715 memset(abDone, 0, sizeof(abDone));
78716 memset(&b, 0, sizeof(b));
78726 assert( pParent->nOverflow==0 || pParent->nOverflow==1 );
78727 assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );
78732 assert( pParent->nFree>=0 );
78747 nxDiv = 0;
78749 assert( bBulk==0 || bBulk==1 );
78750 if( iParentIdx==0 ){
78751 nxDiv = 0;
78768 rc = getAndInitPage(pBt, pgno, &apOld[i], 0);
78771 memset(apOld, 0, (i+1)*sizeof(MemPage*));
78774 if( apOld[i]->nFree<0 ){
78777 memset(apOld, 0, (i)*sizeof(MemPage*));
78782 if( (i--)==0 ) break;
78784 if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
78785 apDiv[i] = pParent->apOvfl[0];
78788 pParent->nOverflow = 0;
78834 b.apCell = sqlite3StackAllocRaw(0, szScratch );
78835 if( b.apCell==0 ){
78856 ** leafCorrection: 4 if pPage is a leaf. 0 if pPage is not a leaf.
78859 b.pRef = apOld[0];
78862 for(i=0; i<nOld; i++){
78874 if( pOld->aData[0]!=apOld[0]->aData[0] ){
78896 memset(&b.szCell[b.nCell], 0, sizeof(b.szCell[0])*(limit+pOld->nOverflow));
78897 if( pOld->nOverflow>0 ){
78898 if( NEVER(limit<pOld->aiOvfl[0]) ){
78902 limit = pOld->aiOvfl[0];
78903 for(j=0; j<limit; j++){
78908 for(k=0; k<pOld->nOverflow; k++){
78909 assert( k==0 || pOld->aiOvfl[k-1]+1==pOld->aiOvfl[k] );/* NOTE 1 */
78935 assert( leafCorrection==0 || leafCorrection==4 );
78938 assert( leafCorrection==0 );
78939 assert( pOld->hdrOffset==0 || CORRUPT_DB );
78947 ** does exist, pad it with 0x00 bytes. */
78950 aSpace1[iSpace1++] = 0x00;
78975 for(i=k=0; i<nOld; i++, k++){
78987 assert( p->nFree>=0 );
78989 for(j=0; j<p->nOverflow; j++){
78995 for(i=0; i<k; i++){
79001 szNew[k-1] = 0;
79010 sz = 0;
79025 sz = 0;
79032 }else if( cntNew[i] <= (i>0 ? cntNew[i-1] : 0) ){
79049 for(i=k-1; i>0; i--){
79064 if( szRight!=0
79065 && (bBulk || szRight+szD+2 > szLeft-(szR+(i==k-1?0:2)))){
79073 }while( r>=0 );
79076 if( cntNew[i-1] <= (i>1 ? cntNew[i-2] : 0) ){
79084 ** (1) We found one or more cells (cntNew[0])>0), or
79089 assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) || CORRUPT_DB);
79091 apOld[0]->pgno, apOld[0]->nCell,
79092 nOld>=2 ? apOld[1]->pgno : 0, nOld>=2 ? apOld[1]->nCell : 0,
79093 nOld>=3 ? apOld[2]->pgno : 0, nOld>=3 ? apOld[2]->nCell : 0
79099 pageFlags = apOld[0]->aData[0];
79100 for(i=0; i<k; i++){
79104 apOld[i] = 0;
79114 assert( i>0 );
79115 rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0);
79144 for(i=0; i<nNew; i++){
79149 for(i=0; i<nNew-1; i++){
79176 apNew[0]->pgno, szNew[0], cntNew[0],
79177 nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0,
79178 nNew>=2 ? cntNew[1] - cntNew[0] - !leafData : 0,
79179 nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0,
79180 nNew>=3 ? cntNew[2] - cntNew[1] - !leafData : 0,
79181 nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0,
79182 nNew>=4 ? cntNew[3] - cntNew[2] - !leafData : 0,
79183 nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0,
79184 nNew>=5 ? cntNew[4] - cntNew[3] - !leafData : 0
79189 assert( apNew[nNew-1]!=0 );
79195 if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){
79218 MemPage *pNew = pOld = apNew[0];
79220 int iNew = 0;
79221 int iOld = 0;
79223 for(i=0; i<b.nCell; i++){
79228 assert( iOld>=0 && iOld<NB );
79259 for(i=0; i<nNew-1; i++){
79268 assert( b.apCell[j]!=0 );
79285 pTemp = 0;
79307 for(k=0; ALWAYS(k<NB*2) && b.ixNx[k]<=j; k++){}
79333 ** to 0, then back up to nNew-1 again, thus making two passes over
79341 int iPg = i<0 ? -i : i;
79342 assert( iPg>=0 && iPg<nNew );
79343 assert( iPg>=1 || i>=0 );
79346 if( i>=0 /* On the upwards pass, or... */
79355 assert( iPg==0 || cntOld[iPg-1]>=cntNew[iPg-1] || abDone[iPg-1] );
79361 if( iPg==0 ){
79362 iNew = iOld = 0;
79363 nNewCell = cntNew[0];
79374 assert( apNew[iPg]->nOverflow==0 );
79380 assert( memcmp(abDone, "\01\01\01\01\01", nNew)==0 );
79382 assert( nOld>0 );
79383 assert( nNew>0 );
79385 if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){
79402 rc = defragmentPage(apNew[0], -1);
79404 assert( apNew[0]->nFree ==
79405 (get2byteNotZero(&apNew[0]->aData[5]) - apNew[0]->cellOffset
79406 - apNew[0]->nCell*2)
79409 copyNodeContent(apNew[0], pParent, &rc);
79410 freePage(apNew[0], &rc);
79415 for(i=0; i<nNew; i++){
79431 #if 0
79432 if( ISAUTOVACUUM(pBt) && rc==SQLITE_OK && apNew[0]->isInit ){
79446 sqlite3StackFree(0, b.apCell);
79447 for(i=0; i<nOld; i++){
79450 for(i=0; i<nNew; i++){
79475 ** an error code is returned and *ppChild is set to 0.
79479 MemPage *pChild = 0; /* Pointer to a new child page */
79480 Pgno pgnoChild = 0; /* Page number of the new child page */
79483 assert( pRoot->nOverflow>0 );
79492 rc = allocateBtreePage(pBt,&pChild,&pgnoChild,pRoot->pgno,0);
79499 *ppChild = 0;
79511 pRoot->nOverflow*sizeof(pRoot->aiOvfl[0]));
79513 pRoot->nOverflow*sizeof(pRoot->apOvfl[0]));
79517 zeroPage(pRoot, pChild->aData[0] & ~PTF_LEAF);
79561 u8 *pFree = 0;
79563 VVA_ONLY( int balance_quick_called = 0 );
79564 VVA_ONLY( int balance_deeper_called = 0 );
79570 if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
79571 if( pPage->nOverflow==0 && pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
79577 }else if( (iPage = pCur->iPage)==0 ){
79584 assert( balance_deeper_called==0 );
79589 pCur->ix = 0;
79590 pCur->aiIdx[0] = 0;
79591 pCur->apPage[0] = pPage;
79608 if( rc==SQLITE_OK && pParent->nFree<0 ){
79615 && pPage->aiOvfl[0]==pPage->nCell
79632 assert( balance_quick_called==0 );
79673 pPage->nOverflow = 0;
79678 assert( pCur->iPage>=0 );
79700 if( nData<=0 ){
79703 for(i=0; i<iAmt && pDest[i]==0; i++){}
79707 memset(pDest + i, 0, iAmt - i);
79718 if( memcmp(pDest, ((u8*)pX->pData) + iOffset, iAmt)!=0 ){
79752 0, pCur->info.nLocal);
79757 assert( nTotal>=0 );
79758 assert( iOffset>=0 );
79763 rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
79799 0, pCur->info.nLocal);
79824 ** been performed. In other words, if seekResult!=0 then the cursor
79826 ** to be inserted. If seekResult<0 then pCur points to a cell that is
79827 ** smaller then (pKey,nKey). If seekResult>0 then pCur points to a cell
79830 ** If seekResult==0, that means pCur is pointing at some unknown location.
79845 int szNew = 0;
79850 unsigned char *newCell = 0;
79853 assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 );
79869 if( loc && pCur->iPage<0 ){
79890 assert( (pCur->curFlags & BTCF_WriteFlag)!=0
79892 && (p->pBt->btsFlags & BTS_READ_ONLY)==0 );
79893 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
79900 assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
79902 if( pCur->pKeyInfo==0 ){
79903 assert( pX->pKey==0 );
79907 invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
79917 assert( loc==0 );
79921 /* On the other hand, BTREE_SAVEPOSITION==0 does not imply
79925 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
79928 assert( pX->nData>=0 && pX->nZero>=0 );
79929 if( pCur->info.nSize!=0
79935 assert( loc==0 );
79936 }else if( loc==0 ){
79942 (flags & BTREE_APPEND)!=0, &loc);
79951 assert( (flags & BTREE_SAVEPOSITION)==0 || loc==0 );
79958 if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
79964 r.default_rc = 0;
79965 r.eqSeen = 0;
79969 (flags & BTREE_APPEND)!=0, &loc);
79978 if( loc==0 ){
79984 x2.nZero = 0;
79993 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
79995 if( pPage->nFree<0 ){
80007 loc==0 ? "overwrite" : "new entry"));
80010 assert( newCell!=0 );
80017 newCell[3] = 0;
80035 pCur->info.nSize = 0;
80036 if( loc==0 ){
80038 assert( idx>=0 );
80077 }else if( loc<0 && pPage->nCell>0 ){
80085 assert( pPage->nOverflow==0 || rc==SQLITE_OK );
80086 assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
80117 pCur->pPage->nOverflow = 0;
80122 assert( pCur->pKey==0 );
80124 if( pCur->pKey==0 ){
80134 assert( pCur->iPage<0 || pCur->pPage->nOverflow==0 );
80163 if( pSrc->info.nPayload<0x80 ){
80168 if( pDest->pKeyInfo==0 ) aOut += putVarint(aOut, iKey);
80182 u8 *pPgnoOut = 0;
80183 Pgno ovflIn = 0;
80184 DbPage *pPageIn = 0;
80185 MemPage *pPageOut = 0;
80205 assert( nOut>0 );
80206 if( nIn>0 ){
80214 if( nOut>0 ){
80216 pPageIn = 0;
80225 }while( rc==SQLITE_OK && nOut>0 );
80227 if( rc==SQLITE_OK && nRem>0 && ALWAYS(pPgnoOut) ){
80229 MemPage *pNew = 0;
80230 rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
80239 put4byte(pPgnoOut, 0);
80244 }while( nRem>0 && rc==SQLITE_OK );
80282 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
80284 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
80286 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
80305 if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){
80324 ** bPreserve==0 Not necessary to save the cursor position
80328 bPreserve = (flags & BTREE_SAVEPOSITION)!=0;
80352 rc = sqlite3BtreePrevious(pCur, 0);
80366 if( pCur->pKeyInfo==0 && p->hasIncrblobCur ){
80367 invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0);
80390 if( pLeaf->nFree<0 ){
80404 assert( pTmp!=0 );
80428 assert( pCur->pPage->nOverflow==0 );
80429 assert( pCur->pPage->nFree>=0 );
80451 assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
80491 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
80494 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
80545 u8 eType = 0;
80546 Pgno iPtrPage = 0;
80551 rc = saveAllCursors(pBt, 0, 0);
80558 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
80572 rc = relocatePage(pBt, pRoot, eType, iPtrPage, pgnoMove, 0);
80579 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
80593 ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
80611 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
80623 assert( (pBt->openFlags & BTREE_SINGLE)==0 || pgnoRoot==2 );
80656 rc = getAndInitPage(pBt, pgno, &pPage, 0);
80658 if( (pBt->openFlags & BTREE_SINGLE)==0
80665 for(i=0; i<pPage->nCell; i++){
80677 if( pPage->intKey ) pnChange = 0;
80685 }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
80712 rc = saveAllCursors(pBt, (Pgno)iTable, 0);
80719 invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
80721 rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
80733 return sqlite3BtreeClearTable(pCur->pBtree, pCur->pgnoRoot, 0);
80752 ** the move. If no page gets moved, *piMoved is set to 0.
80758 MemPage *pPage = 0;
80768 rc = sqlite3BtreeClearTable(p, iTable, 0);
80770 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
80776 *piMoved = 0;
80802 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
80806 rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0);
80811 pMove = 0;
80812 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
80854 ** Read the meta-information out of a database file. Meta[0]
80856 ** through meta[15] are available for use by higher layers. Meta[0]
80861 ** free pages is not visible. So Cookie[0] is the same as Meta[1].
80877 assert( idx>=0 && idx<=15 );
80888 if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
80897 ** Write meta-information back into the database. Meta[0] is
80907 assert( pBt->pPage1!=0 );
80914 assert( pBt->autoVacuum || iMeta==0 );
80915 assert( iMeta==0 || iMeta==1 );
80933 i64 nEntry = 0; /* Value to return in *pnEntry */
80938 *pnEntry = 0;
80970 if( pCur->iPage==0 ){
81011 pCheck->mxErr = 0; /* Causes integrity_check processing to stop */
81012 if( pCheck->nErr==0 ) pCheck->nErr++;
81024 pCheck->mxErr = 0;
81028 assert( db->nProgressOps>0 );
81030 if( (pCheck->nStep % db->nProgressOps)==0
81035 pCheck->mxErr = 0;
81077 assert( pCheck->aPgRef!=0 );
81078 assert( iPg<=pCheck->nCkPage && sizeof(pCheck->aPgRef[0])==1 );
81079 return (pCheck->aPgRef[iPg/8] & (1 << (iPg & 0x07)));
81086 assert( pCheck->aPgRef!=0 );
81087 assert( iPg<=pCheck->nCkPage && sizeof(pCheck->aPgRef[0])==1 );
81088 pCheck->aPgRef[iPg/8] |= (1 << (iPg & 0x07));
81095 ** Return 1 if there are 2 or more references to the page and 0 if
81101 if( iPage>pCheck->nCkPage || iPage==0 ){
81110 return 0;
81157 while( iPage!=0 && pCheck->mxErr ){
81162 if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage, 0) ){
81171 checkPtrmap(pCheck, iPage, PTRMAP_FREEPAGE, 0);
81179 for(i=0; i<(int)n; i++){
81183 checkPtrmap(pCheck, iFreePage, PTRMAP_FREEPAGE, 0);
81197 if( pCheck->pBt->autoVacuum && N>0 ){
81218 ** aHeap[0] is the number of elements on the heap. aHeap[1] is the
81239 assert( aHeap!=0 );
81240 i = ++aHeap[0];
81242 while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){
81251 if( (x = aHeap[0])==0 ) return 0;
81254 aHeap[x] = 0xffffffff;
81255 aHeap[0]--;
81257 while( (j = i*2)<=aHeap[0] ){
81271 ** the tree depth. Root pages return 0. Parents of root pages
81289 MemPage *pPage = 0; /* The page being analyzed */
81308 u32 *heap = 0; /* Min-heap used for checking cell coverage */
81309 u32 x, prev = 0; /* Next and previous entry on the min-heap */
81313 u8 savedIsInit = 0;
81318 if( pCheck->mxErr==0 ) goto end_of_check;
81321 if( iPage==0 ) return 0;
81322 if( checkRef(pCheck, iPage) ) return 0;
81325 if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
81335 pPage->isInit = 0;
81336 if( (rc = btreeInitPage(pPage))!=0 ){
81342 if( (rc = btreeComputeFreeSpace(pPage))!=0 ){
81359 if( pPage->leaf || pPage->intKey==0 ){
81379 keyCanBeEqual = 0;
81384 heap[0] = 0;
81389 for(i=nCell-1; i>=0 && pCheck->mxErr; i--){
81400 doCoverageCheck = 0;
81407 doCoverageCheck = 0;
81417 keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
81432 checkList(pCheck, 0, pgnoOvfl, nPage);
81444 keyCanBeEqual = 0;
81458 pCheck->zPfx = 0;
81459 if( doCoverageCheck && pCheck->mxErr>0 ){
81465 heap[0] = 0;
81466 for(i=nCell-1; i>=0; i--){
81473 assert( heap!=0 );
81481 while( i>0 ){
81494 assert( j==0 || j>i+size ); /* Enforced by btreeComputeFreeSpace() */
81511 nFrag = 0;
81514 if( (prev&0xffff)>=(x>>16) ){
81519 nFrag += (x>>16) - (prev&0xffff) - 1;
81523 nFrag += usableSize - (prev&0xffff) - 1;
81529 if( heap[0]==0 && nFrag!=data[hdr+7] ){
81557 ** malloc is returned if *pnErr is non-zero. If *pnErr==0 then NULL is
81560 ** If the first entry in aRoot[] is 0, that indicates that the list of
81584 int bPartial = 0; /* True if not checking all btrees */
81588 assert( nRoot>0 );
81589 assert( aCnt!=0 );
81591 /* aRoot[0]==0 means this is a partial check */
81592 if( aRoot[0]==0 ){
81595 if( aRoot[1]!=1 ) bCkFreelist = 0;
81601 assert( nRef>=0 );
81602 memset(&sCheck, 0, sizeof(sCheck));
81608 sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
81610 if( sCheck.nCkPage==0 ){
81620 if( sCheck.heap==0 ){
81634 sCheck.zPfx = 0;
81642 Pgno mx = 0;
81644 for(i=0; (int)i<nRoot; i++) if( mx<aRoot[i] ) mx = aRoot[i];
81652 }else if( get4byte(&pBt->pPage1->aData[64])!=0 ){
81661 for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
81662 sCheck.nRow = 0;
81667 checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
81682 if( getPageReferenced(&sCheck, i)==0 ){
81689 if( getPageReferenced(&sCheck, i)==0 &&
81693 if( getPageReferenced(&sCheck, i)!=0 &&
81707 if( sCheck.nErr==0 ){
81709 *pzOut = 0;
81728 assert( p->pBt->pPager!=0 );
81741 assert( p->pBt->pPager!=0 );
81750 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
81751 return p ? p->inTrans : 0;
81785 return p->nBackup!=0;
81799 ** If the nBytes parameter is 0 and the blob of memory has not yet been
81812 pBt->pSchema = sqlite3DbMallocZero(0, nBytes);
81847 assert( isWriteLock==0 || isWriteLock==1 );
81904 if( (pCsr->curFlags & BTCF_WriteFlag)==0 ){
81907 assert( (pCsr->pBt->btsFlags & BTS_READ_ONLY)==0
81909 assert( hasSharedCacheTableLock(pCsr->pBtree, pCsr->pgnoRoot, 0, 2) );
81942 rc = sqlite3BtreeBeginTrans(pBtree, 0, 0);
81946 rc = sqlite3BtreeBeginTrans(pBtree, 2, 0);
81966 return (pCsr->hints & mask)!=0;
81973 return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
82091 ** function. If an error occurs while doing so, return 0 and write an
82099 int rc = 0;
82108 return 0;
82112 if( i<0 ){
82114 return 0;
82126 rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),0,0);
82163 return 0;
82182 p = 0;
82201 p->isAttached = 0;
82203 if( 0==p->pSrc || 0==p->pDest
82212 p = 0;
82252 assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
82257 assert( nSrcPgsz==nDestPgsz || sqlite3PagerIsMemdb(pDestPager)==0 );
82264 DbPage *pDestPg = 0;
82267 if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg, 0))
82282 ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0;
82283 if( iOff==0 && bUpdate==0 ){
82329 int pgszSrc = 0; /* Source page size */
82330 int pgszDest = 0; /* Destination page size */
82333 if( p==0 ) return SQLITE_MISUSE_BKPT;
82347 int bCloseTrans = 0; /* True if src db requires unlocking */
82363 rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0);
82373 if( p->bDestLocked==0 && rc==SQLITE_OK && setDestPgsz(p)==SQLITE_NOMEM ){
82378 if( SQLITE_OK==rc && p->bDestLocked==0
82401 assert( nSrcPage>=0 );
82402 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
82408 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
82430 if( nSrcPage==0 ){
82470 assert( nDestTruncate>0 );
82490 assert( nDestTruncate==0
82506 rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0);
82514 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1);
82524 PgHdr *pSrcPg = 0;
82526 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg, 0);
82539 rc = sqlite3PagerSync(pDestPager, 0);
82543 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
82548 && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0))
82562 TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0);
82563 TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0);
82589 if( p==0 ) return SQLITE_OK;
82603 assert( pp!=0 );
82606 assert( pp!=0 );
82612 sqlite3BtreeRollback(p->pDest, SQLITE_OK, 0);
82639 if( p==0 ){
82641 return 0;
82653 if( p==0 ){
82655 return 0;
82678 assert( p!=0 );
82696 }while( (p = p->pNext)!=0 );
82747 ** to 0. This is used by the implementations of sqlite3_backup_step()
82751 memset(&b, 0, sizeof(b));
82757 /* 0x7FFFFFFF is the hard limit for the number of pages in a database
82763 sqlite3_backup_step(&b, 0x7FFFFFFF);
82803 /* True if X is a power of two. 0 is considered a power of two here.
82806 #define ISPOWEROF2(X) (((X)&((X)-1))==0)
82816 /* If MEM_Dyn is set then Mem.xDel!=0.
82819 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
82821 /* MEM_Dyn may only be set if Mem.szMalloc==0. In this way we
82822 ** ensure that if Mem.szMalloc>0 then it is safe to do
82825 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
82832 assert( (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob|MEM_Agg))==0 );
82842 assert( ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
82843 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
82844 ((p->flags&MEM_Static)!=0 ? 1 : 0) <= 1 );
82848 |MEM_Dyn|MEM_Ephem|MEM_Static))==0 );
82855 assert( (p->flags & MEM_Cleared)==0 );
82859 assert( p->szMalloc==0
82872 if( (p->flags & (MEM_Str|MEM_Blob)) && p->n>0 ){
82874 ((p->szMalloc>0 && p->z==p->zMalloc)? 1 : 0) +
82875 ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
82876 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
82877 ((p->flags&MEM_Static)!=0 ? 1 : 0) == 1
82904 sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0);
82906 (p->flags & MEM_IntReal)!=0 ? (double)p->u.i : p->u.r);
82907 assert( acc.zText==zBuf && acc.mxAlloc<=0 );
82908 zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
82941 if( (p->flags & MEM_Str)==0 ) return 1;
82946 if( p->szMalloc>0 && p->z==p->zMalloc ){
82950 assert( p->z[p->n]==0 );
82951 assert( p->enc==SQLITE_UTF8 || p->z[(p->n+1)&~1]==0 );
82952 assert( p->enc==SQLITE_UTF8 || p->z[((p->n+1)&~1)+1]==0 );
82954 if( (p->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 ) return 1;
82958 i = j = 0;
82965 if( zBuf[j++]!=z[i] ) return 0;
82989 assert( pMem!=0 );
83000 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
83027 testcase( pMem->db==0 );
83031 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
83032 testcase( bPreserve && pMem->z==0 );
83034 assert( pMem->szMalloc==0
83038 if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
83043 if( pMem->zMalloc==0 ) sqlite3_free(pMem->z);
83046 bPreserve = 0;
83048 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
83051 if( pMem->zMalloc==0 ){
83053 pMem->z = 0;
83054 pMem->szMalloc = 0;
83064 if( (pMem->flags&MEM_Dyn)!=0 ){
83065 assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
83088 assert( CORRUPT_DB || szNew>0 );
83089 assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
83091 return sqlite3VdbeMemGrow(pMem, szNew, 0);
83093 assert( (pMem->flags & MEM_Dyn)==0 );
83112 if( NEVER(pMem->z==0) ) return;
83117 pMem->z[pMem->n] = 0;
83127 pMem->z[pMem->n] = 0;
83146 pMem->z[pMem->n] = 0;
83147 pMem->z[pMem->n+1] = 0;
83148 pMem->z[pMem->n+2] = 0;
83160 assert( pMem!=0 );
83161 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
83163 if( (pMem->flags & (MEM_Str|MEM_Blob))!=0 ){
83165 if( pMem->szMalloc==0 || pMem->z!=pMem->zMalloc ){
83172 pMem->pScopyFrom = 0;
83185 assert( pMem!=0 );
83187 assert( (pMem->flags&MEM_Blob)!=0 || MemNullNochng(pMem) );
83190 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
83194 if( nByte<=0 ){
83195 if( (pMem->flags & MEM_Blob)==0 ) return SQLITE_OK;
83201 assert( pMem->z!=0 );
83204 memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
83215 assert( pMem!=0 );
83216 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
83218 testcase( (pMem->flags & (MEM_Term|MEM_Str))==0 );
83243 assert( pMem!=0 );
83244 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
83253 pMem->enc = 0;
83258 assert( pMem->z!=0 );
83278 assert( pFunc!=0 );
83279 assert( pMem!=0 );
83280 assert( pMem->db!=0 );
83281 assert( pFunc->xFinalize!=0 );
83282 assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef );
83284 memset(&ctx, 0, sizeof(ctx));
83285 memset(&t, 0, sizeof(t));
83293 assert( (pMem->flags & MEM_Dyn)==0 );
83294 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
83310 assert( pFunc!=0 );
83311 assert( pFunc->xValue!=0 );
83312 assert( (pAccum->flags & MEM_Null)!=0 || pFunc==pAccum->u.pDef );
83313 assert( pAccum->db!=0 );
83315 memset(&ctx, 0, sizeof(ctx));
83336 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
83340 assert( (p->flags & MEM_Agg)==0 );
83344 assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 );
83364 p->szMalloc = 0;
83366 p->z = 0;
83401 ** an SQL-NULL value, return 0.
83406 i64 value = 0;
83412 assert( pMem!=0 );
83413 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
83421 }else if( (flags & (MEM_Str|MEM_Blob))!=0 && pMem->z!=0 ){
83424 return 0;
83435 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
83436 double val = (double)0;
83441 assert( pMem!=0 );
83442 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
83452 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
83453 return (double)0;
83458 ** Return 1 if pMem represents true, and return 0 if pMem represents false.
83463 if( pMem->flags & (MEM_Int|MEM_IntReal) ) return pMem->u.i!=0;
83473 assert( pMem!=0 );
83476 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
83505 assert( pMem!=0 );
83506 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
83520 assert( pMem!=0 );
83521 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
83541 || (memcmp(&r1, &r2, sizeof(r1))==0
83564 assert( pMem!=0 );
83569 if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){
83572 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
83573 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
83575 if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
83584 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))!=0 );
83600 if( (pMem->flags & MEM_Blob)==0 ){
83644 assert( (flags & ~MEM_TypeMask)==0 );
83647 pMem->szMalloc = 0;
83682 pMem->n = 0;
83683 if( n<0 ) n = 0;
83686 pMem->z = 0;
83690 int nByte = n>0?n:1;
83691 if( sqlite3VdbeMemGrow(pMem, nByte, 0) ){
83694 assert( pMem->z!=0 );
83696 memset(pMem->z, 0, nByte);
83697 pMem->n = n>0?n:0;
83792 assert( db!=0 );
83796 if( p==0 ) return SQLITE_NOMEM;
83808 assert( p->db!=0 );
83816 return 0;
83845 assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
83850 pX->pScopyFrom = 0;
83853 pMem->pScopyFrom = 0;
83873 if( (pFrom->flags&MEM_Static)==0 ){
83892 if( 0==(pFrom->flags&MEM_Static) ){
83908 assert( pFrom->db==0 || sqlite3_mutex_held(pFrom->db->mutex) );
83909 assert( pTo->db==0 || sqlite3_mutex_held(pTo->db->mutex) );
83910 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
83915 pFrom->szMalloc = 0;
83944 u8 enc, /* Encoding of z. 0 for BLOBs */
83951 assert( pMem!=0 );
83952 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
83954 assert( enc!=0 || n>=0 );
83967 if( nByte<0 ){
83968 assert( enc!=0 );
83972 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
83975 }else if( enc==0 ){
84002 testcase( nAlloc==0 );
84021 pMem->n = (int)(nByte & 0x7fffffff);
84064 pMem->z[amt] = 0; /* Overrun area used when reading malformed records */
84078 u32 available = 0; /* Number of bytes available on the local btree page */
84088 assert( pMem->z!=0 );
84094 rc = sqlite3VdbeMemFromBtree(pCur, 0, amt, pMem);
84106 assert( pVal!=0 );
84107 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
84110 assert( (pVal->flags & (MEM_Null))==0 );
84112 if( ExpandBlob(pVal) ) return 0;
84117 if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&SQLITE_PTR_TO_INT(pVal->z)) ){
84118 assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 );
84120 return 0;
84125 sqlite3VdbeMemStringify(pVal, enc, 0);
84126 assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) );
84128 assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
84134 return 0;
84149 if( !pVal ) return 0;
84150 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
84158 return 0;
84170 if( ALWAYS(pVal!=0)
84171 && ALWAYS((pVal->flags & (MEM_Str|MEM_Blob))!=0)
84172 && (pVal->flags & MEM_Dyn)!=0
84177 return 0;
84218 UnpackedRecord *pRec = p->ppRec[0];
84220 if( pRec==0 ){
84234 for(i=0; i<nCol; i++){
84240 pRec = 0;
84243 if( pRec==0 ) return 0;
84244 p->ppRec[0] = pRec;
84287 sqlite3_value **apVal = 0; /* Function arguments */
84288 int nVal = 0; /* Size of apVal[] array */
84289 FuncDef *pFunc = 0; /* Function definition */
84290 sqlite3_value *pVal = 0; /* New value */
84292 ExprList *pList = 0; /* Function arguments */
84295 assert( pCtx!=0 );
84296 assert( (p->flags & EP_TokenOnly)==0 );
84301 pFunc = sqlite3FindFunction(db, p->u.zToken, nVal, enc, 0);
84303 if( pFunc==0 ) return SQLITE_OK;
84306 if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
84307 || (pFunc->funcFlags & (SQLITE_FUNC_NEEDCOLL|SQLITE_FUNC_RUNONLY))!=0
84313 apVal = (sqlite3_value**)sqlite3DbMallocZero(db, sizeof(apVal[0]) * nVal);
84314 if( apVal==0 ){
84318 for(i=0; i<nVal; i++){
84320 if( apVal[i]==0 || rc!=SQLITE_OK ) goto value_from_function_out;
84325 if( pVal==0 ){
84330 memset(&ctx, 0, sizeof(ctx));
84350 pVal = 0;
84354 for(i=0; i<nVal; i++){
84386 char *zVal = 0;
84387 sqlite3_value *pVal = 0;
84392 assert( pExpr!=0 );
84397 ** on a table column definition, and hence only when pCtx==0. This
84400 assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );
84405 aff = sqlite3AffinityType(pExpr->u.zToken,0);
84414 assert( (ppVal[0][0].flags & MEM_Zero)==0 );
84429 || pLeft->u.zToken[0]!='0' || (pLeft->u.zToken[1] & ~0x20)!='X'
84441 if( pVal==0 ) goto no_mem;
84446 if( op==TK_INTEGER && 0==sqlite3DecOrHexToI64(pExpr->u.zToken, &iVal) ){
84450 if( zVal==0 ) goto no_mem;
84468 assert( (pVal->flags & MEM_IntReal)==0 );
84480 && pVal!=0
84499 if( pVal==0 ) goto no_mem;
84506 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
84514 0, SQLITE_DYNAMIC);
84518 else if( op==TK_FUNCTION && pCtx!=0 ){
84527 pVal->u.i = pExpr->u.zToken[4]==0;
84537 if( pCtx==0 || NEVER(pCtx->pParse->nErr==0) )
84541 assert( *ppVal==0 );
84543 if( pCtx==0 ) sqlite3ValueFree(pVal);
84545 assert( pCtx==0 ); sqlite3ValueFree(pVal);
84567 return pExpr ? valueFromExpr(db, pExpr, enc, affinity, ppVal, 0) : 0;
84580 ** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
84597 sqlite3_value *pVal = 0;
84603 assert( pExpr==0 || pExpr->op!=TK_REGISTER || pExpr->op2!=TK_VARIABLE );
84609 }else if( pExpr->op==TK_VARIABLE && (db->flags & SQLITE_EnableQPSG)==0 ){
84613 if( (v = pParse->pReprepare)!=0 ){
84625 assert( pVal==0 || pVal->db==db );
84637 ** right starting with 0). A single field is populated if:
84639 ** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
84674 int nExtract = 0;
84676 if( pExpr==0 || pExpr->op!=TK_SELECT ){
84684 for(i=0; i<nElem; i++){
84685 sqlite3_value *pVal = 0;
84686 Expr *pElem = (pExpr ? sqlite3VectorFieldSubexpr(pExpr, i) : 0);
84715 return stat4ValueFromExpr(pParse, pExpr, affinity, 0, ppVal);
84733 u32 t = 0; /* a column type code */
84737 u32 szField = 0; /* Size of the current data field */
84742 assert( iCol>0 );
84746 for(i=0; i<=iCol; i++){
84757 if( pMem==0 ){
84759 if( pMem==0 ) return SQLITE_NOMEM_BKPT;
84776 sqlite3 *db = aMem[0].db;
84777 for(i=0; i<nCol; i++){
84814 return valueToText(pVal, enc)!=0 ? pVal->n : 0;
84818 assert( (p->flags & MEM_Null)==0 || (p->flags & (MEM_Str|MEM_Blob))==0 );
84819 if( (p->flags & MEM_Str)!=0 && pVal->enc==enc ){
84822 if( (p->flags & MEM_Str)!=0 && enc!=SQLITE_UTF8 && pVal->enc!=SQLITE_UTF8 ){
84825 if( (p->flags & MEM_Blob)!=0 ){
84832 if( p->flags & MEM_Null ) return 0;
84866 if( p==0 ) return 0;
84867 memset(&p->aOp, 0, sizeof(Vdbe)-offsetof(Vdbe,aOp));
84878 assert( pParse->aLabel==0 );
84879 assert( pParse->nLabel==0 );
84880 assert( p->nOpAlloc==0 );
84881 assert( pParse->szOpAlloc==0 );
84882 sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
84908 if( p==0 ) return;
84910 if( (prepFlags & SQLITE_PREPARE_SAVESQL)==0 ){
84911 p->expmask = 0;
84913 assert( p->zSql==0 );
84945 assert( zId!=0 );
84946 if( pVdbe->pDblStr==0 ) return 0;
84948 if( strcmp(zId, pStr->z)==0 ) return 1;
84950 return 0;
85051 static u64 n = 0;
85079 if( p->db->mallocFailed==0 ){
85101 return sqlite3VdbeAddOp3(p, op, 0, 0, 0);
85104 return sqlite3VdbeAddOp3(p, op, p1, 0, 0);
85107 return sqlite3VdbeAddOp3(p, op, p1, p2, 0);
85115 assert( op>=0 && op<0xff );
85119 assert( p->aOp!=0 );
85122 assert( pOp!=0 );
85124 pOp->p5 = 0;
85128 pOp->p4.p = 0;
85134 pOp->zComment = 0;
85137 pOp->nExec = 0;
85138 pOp->nCycle = 0;
85142 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
85147 pOp->iSrcLine = 0;
85171 assert( pOp!=0 );
85173 pOp->p5 = 0;
85183 pOp->zComment = 0;
85186 pOp->nExec = 0;
85187 pOp->nCycle = 0;
85191 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
85196 pOp->iSrcLine = 0;
85207 return sqlite3VdbeAddOp3(p, OP_Goto, 0, iDest, 0);
85214 return sqlite3VdbeAddOp4(p, OP_String8, 0, iDest, 0, zStr, 0);
85233 for(i=0; (c = zTypes[i])!=0; i++){
85236 sqlite3VdbeAddOp4(p, z==0 ? OP_Null : OP_String8, 0, iDest+i, 0, z, 0);
85269 ** that describes the calling context of the function. 0 means a general
85273 ** while computing a generated column value. 0 is the usual case.
85291 if( pCtx==0 ){
85294 return 0;
85296 pCtx->pOut = 0;
85298 pCtx->pVdbe = 0;
85299 pCtx->isError = 0;
85330 ** 0 means "none".
85334 if( pParse->addrExplain==0 ) return 0;
85357 int addr = 0;
85373 addr = sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
85379 sqlite3VdbeScanStatus(v, iThis, -1, -1, 0, 0);
85388 sqlite3ExplainBreakpoint("POP", 0);
85403 sqlite3VdbeAddOp4(p, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC);
85405 for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
85420 v->pParse->nTempReg = 0;
85421 v->pParse->nRangeReg = 0;
85461 nNewSize*sizeof(p->aLabel[0]));
85462 if( p->aLabel==0 ){
85463 p->nLabelAlloc = 0;
85481 assert( j>=0 );
85487 if( p->nLabelAlloc + p->nLabel < 0 ){
85525 ** memset(&sIter, 0, sizeof(sIter));
85539 int iSub; /* 0 = main program, 1 = first sub-program etc. */
85543 Op *pRet = 0;
85549 if( p->iSub==0 ){
85562 p->iAddr = 0;
85568 for(j=0; j<p->nSub; j++){
85574 pRet = 0;
85597 ** * OP_FkCounter with P2==0 (immediate foreign key constraint)
85609 int hasAbort = 0;
85610 int hasFkCounter = 0;
85611 int hasCreateTable = 0;
85612 int hasCreateIndex = 0;
85613 int hasInitCoroutine = 0;
85617 if( v==0 ) return 0;
85618 memset(&sIter, 0, sizeof(sIter));
85621 while( (pOp = opIterNext(&sIter))!=0 ){
85645 if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
85669 if( pC==0
85685 assert( p->nWrite==0 || p->usesStmtJournal );
85716 assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
85718 p->bIsReader = 0;
85720 assert( p->aOp[0].opcode==OP_Init );
85733 if( pOp->p2!=0 ) p->readOnly = 0;
85746 p->readOnly = 0;
85751 assert( pOp->p2>=0 );
85770 if( pOp->p2<0 ){
85774 assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 );
85776 assert( aLabel!=0 ); /* True because of tag-20230419-1 */
85780 /* OPFLG_JUMP opcodes never have P2==0, though OPFLG_JUMP0 opcodes
85782 assert( pOp->p2>0
85783 || (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP0)!=0 );
85787 || (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)==0 );
85794 assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
85802 pParse->aLabel = 0;
85804 pParse->nLabel = 0;
85806 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
85839 sqlite3_str *pErr = 0;
85840 assert( v!=0 );
85842 assert( pParse!=0 );
85848 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 ){
85850 if( iDest==0 ) continue;
85856 if( iDest<0 ){
85858 assert( j>=0 );
85859 if( j>=-pParse->nLabel || pParse->aLabel[j]<0 ){
85874 if( pErr==0 ){
85875 pErr = sqlite3_str_new(0);
85890 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_INTERNAL, OE_Abort, 0, zErr, 0);
85929 for(i=0; i<p->nOp; i++){
85966 p->aOp = 0;
85985 assert( nOp>0 );
85988 return 0;
85991 for(i=0; i<nOp; i++, aOp++, pOut++){
85995 assert( aOp->p2>=0 );
85996 if( (sqlite3OpcodeProperty[aOp->opcode] & OPFLG_JUMP)!=0 && aOp->p2>0 ){
86001 pOut->p4.p = 0;
86002 pOut->p5 = 0;
86004 pOut->zComment = 0;
86013 sqlite3VdbePrintOp(0, i+p->nOp, &p->aOp[i+p->nOp]);
86027 int addrExplain, /* Address of OP_Explain (or 0) */
86039 memset(pNew, 0, sizeof(ScanStatus));
86064 ScanStatus *pScan = 0;
86066 for(ii=p->nScan-1; ii>=0; ii--){
86069 pScan = 0;
86072 if( addrEnd<0 ) addrEnd = sqlite3VdbeCurrentAddr(p)-1;
86073 for(ii=0; ii<ArraySize(pScan->aAddrRange); ii+=2){
86074 if( pScan->aAddrRange[ii]==0 ){
86096 ScanStatus *pScan = 0;
86098 for(ii=p->nScan-1; ii>=0; ii--){
86101 pScan = 0;
86104 if( addrLoop>0 ) pScan->addrLoop = addrLoop;
86105 if( addrVisit>0 ) pScan->addrVisit = addrVisit;
86117 assert( addr>=0 );
86121 assert( addr>=0 );
86125 assert( addr>=0 || p->db->mallocFailed );
86129 assert( addr>=0 );
86133 assert( p->nOp>0 || p->db->mallocFailed );
86134 if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5;
86167 ** 7 Once 0 8 0
86175 assert( p->aOp[addr].p4type==0 );
86177 sqlite3VdbeGetLastOp(p)->iSrcLine = 0; /* Erase VdbeCoverage() macros */
86191 assert( db!=0 );
86192 if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
86205 assert( db!=0 );
86224 if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4);
86238 if( db->pnBytesFreed==0 ){
86246 if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
86250 if( db->pnBytesFreed==0 ) sqlite3DeleteTable(db, (Table*)p4);
86262 assert( nOp>=0 );
86263 assert( db!=0 );
86292 return pVdbe->pProgram!=0;
86300 if( p->db->mallocFailed ) return 0;
86301 assert( addr>=0 && addr<p->nOp );
86305 pOp->p4.z = 0;
86315 if( p->nOp>0 && p->aOp[p->nOp-1].opcode==op ){
86318 return 0;
86334 if( N==0 || OptimizationDisabled(pParse->db, SQLITE_ReleaseReg) ) return;
86338 if( N<=31 && mask!=0 ){
86339 while( N>0 && (mask&1)!=0 ){
86344 while( N>0 && N<=32 && (mask & MASKBIT32(N-1))!=0 ){
86349 if( N>0 ){
86362 ** If n>=0 then the P4 operand is dynamic, meaning that a copy of
86364 ** A value of n==0 means copy bytes of zP4 up to and including the
86365 ** first null byte. If n>0 then copy n+1 bytes of zP4.
86371 ** If addr<0 then change P4 on the most recently inserted instruction.
86381 pOp->p4type = 0;
86382 pOp->p4.p = 0;
86384 if( n<0 ){
86387 if( n==0 ) n = sqlite3Strlen30(zP4);
86395 assert( p!=0 );
86398 assert( p->aOp!=0 || db->mallocFailed );
86403 assert( p->nOp>0 );
86405 if( addr<0 ){
86409 if( n>=0 || pOp->p4type ){
86418 }else if( zP4!=0 ){
86419 assert( n<0 );
86438 assert( n<=0 );
86442 assert( pP4!=0 || n==P4_DYNAMIC );
86443 assert( p->nOp>0 );
86458 assert( v!=0 );
86459 assert( pIdx!=0 );
86472 assert( p->nOp>0 || p->aOp==0 );
86473 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->pParse->nErr>0 );
86517 ** this routine is a valid pointer. But because the dummy.opcode is 0,
86526 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
86562 ** "PX@PY" -> "r[X..X+Y-1]" or "r[x]" if y is 0 or 1
86563 ** "PX@PY+1" -> "r[X..X+Y]" or "r[x]" if y is 0
86578 sqlite3StrAccumInit(&x, 0, 0, 0, SQLITE_MAX_LENGTH);
86582 int seenCom = 0;
86585 if( strncmp(zSynopsis,"IF ",3)==0 ){
86589 for(ii=0; (c = zSynopsis[ii])!=0; ii++){
86595 if( pOp->zComment && pOp->zComment[0] ){
86603 if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
86606 if( strncmp(zSynopsis+ii+1,"+1",2)==0 ){
86615 }else if( strncmp(zSynopsis+ii+1, "@NP", 3)==0 ){
86621 }else if( x.accError==0 ){
86629 if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){
86644 if( (x.accError & SQLITE_NOMEM)!=0 && db!=0 ){
86657 const char *zOp = 0;
86674 if( pExpr->iColumn<0 ){
86732 char *zP4 = 0;
86735 sqlite3StrAccumInit(&x, 0, 0, 0, SQLITE_MAX_LENGTH);
86740 assert( pKeyInfo->aSortFlags!=0 );
86742 for(j=0; j<pKeyInfo->nKeyField; j++){
86745 if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
86816 u32 n = ai[0]; /* The first element of an INTARRAY is always the
86837 if( (x.accError & SQLITE_NOMEM)!=0 ){
86853 assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
86892 for(i=0; i<nDb; i++){
86893 if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
86900 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
86912 for(i=0; i<nDb; i++){
86913 if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
86933 if( pOut==0 ) pOut = stdout;
86938 zCom = sqlite3VdbeDisplayComment(0, pOp, zP4);
86940 zCom = 0;
86967 ** Mem.szMalloc = 0
86973 if( N>0 ){
86977 p->szMalloc = 0;
86979 p->pScopyFrom = 0;
86982 }while( (--N)>0 );
87005 assert( (&p[1])==pEnd || p[0].db==p[1].db );
87023 testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel );
87028 p->szMalloc = 0;
87048 if( pFrame->iFrameMagic!=SQLITE_FRAME_MAGIC ) return 0;
87079 int eMode, /* 0: normal. 1: EQP. 2: TablesUsed */
87085 int nSub = 0; /* Number of sub-vdbes seen so far */
87086 SubProgram **apSub = 0; /* Array of sub-vdbes */
87089 Op *aOp = 0; /* Opcode array */
87100 if( pSub!=0 ){
87107 for(i=0; i<nSub; i++){
87128 assert( apSub!=0 );
87129 assert( nSub>0 );
87130 for(j=0; i>=apSub[j]->nOp; j++){
87142 if( pSub!=0 && aOp[i].p4type==P4_SUBPROGRAM ){
87145 for(j=0; j<nSub; j++){
87149 p->rc = sqlite3VdbeMemGrow(pSub, nByte, nSub!=0);
87161 if( eMode==0 ) break;
87166 if( pOp->opcode==OP_OpenWrite && (pOp->p5 & OPFLAG_P2ISREG)==0 ) break;
87193 for(i=0; i<p->nChildCsr; i++){
87197 sqlite3VdbeDeleteAuxData(p->v->db, &p->pAuxData, -1, 0);
87223 Mem *pSub = 0; /* Memory cell hold array of subprogs */
87228 int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0);
87257 pSub = 0;
87278 sqlite3VdbeMemSetInt64(pMem+0, i);
87316 const char *z = 0;
87320 const VdbeOp *pOp = &p->aOp[0];
87321 if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
87337 if( sqlite3IoTrace==0 ) return;
87339 pOp = &p->aOp[0];
87340 if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
87344 for(i=0; sqlite3Isspace(z[i]); i++){}
87345 for(j=0; z[i]; i++){
87354 z[j] = 0;
87390 if( pBuf==0 ){
87411 assert( p!=0 );
87418 assert( p->nOp>0 );
87423 for(i=0; i<p->nMem; i++){
87430 p->nChange = 0;
87433 p->iStatement = 0;
87434 p->nFkConstraint = 0;
87436 for(i=0; i<p->nOp; i++){
87437 p->aOp[i].nExec = 0;
87438 p->aOp[i].nCycle = 0;
87473 assert( p!=0 );
87474 assert( p->nOp>0 );
87475 assert( pParse!=0 );
87479 pParse->pVList = 0;
87481 assert( db->mallocFailed==0 );
87487 /* Each cursor uses a memory cell. The first cursor (cursor 0) can
87488 ** use aMem[0] which is not otherwise used by the VDBE program. Allocate
87493 if( nCursor==0 && nMem>0 ) nMem++; /* Space for aMem[0] even if not used */
87503 assert( x.nFree>=0 );
87513 p->expired = 0;
87525 x.nNeeded = 0;
87526 p->aMem = allocSpace(&x, 0, nMem*sizeof(Mem));
87527 p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
87528 p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
87529 p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
87542 p->nVar = 0;
87543 p->nCursor = 0;
87544 p->nMem = 0;
87551 memset(p->apCsr, 0, nCursor*sizeof(VdbeCursor*));
87566 pCx->colCache = 0;
87567 pCx->pCache = 0;
87570 pCache->pCValue = 0;
87586 assert( pCx->uc.pCursor!=0 );
87594 assert( pVCur->pVtab->nRef>0 );
87608 for(i=0; i<p->nCursor; i++){
87612 p->apCsr[i] = 0;
87634 sqlite3VdbeDeleteAuxData(v->db, &v->pAuxData, -1, 0);
87636 pFrame->pAuxData = 0;
87653 p->pFrame = 0;
87654 p->nFrame = 0;
87656 assert( p->nFrame==0 );
87666 if( p->pAuxData ) sqlite3VdbeDeleteAuxData(p->db, &p->pAuxData, -1, 0);
87667 assert( p->pAuxData==0 );
87687 if( p->aColName==0 ) return;
87716 assert( p->aColName!=0 );
87719 assert( rc!=0 || !zName || (pColName->flags&MEM_Term)!=0 );
87731 int nTrans = 0; /* Number of databases with an active write-transaction
87735 int needXcommit = 0;
87758 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
87767 /* OFF */ 0,
87769 /* MEMORY */ 0,
87770 /* WAL */ 0
87778 && sqlite3PagerIsMemdb(pPager)==0
87808 if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
87811 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
87814 rc = sqlite3BtreeCommitPhaseOne(pBt, 0);
87823 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
87826 rc = sqlite3BtreeCommitPhaseTwo(pBt, 0);
87841 char *zSuper = 0; /* File-name for the super-journal */
87842 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
87843 sqlite3_file *pSuperJrnl = 0;
87844 i64 offset = 0;
87846 int retryCount = 0;
87851 zSuper = sqlite3MPrintf(db, "%.4c%s%.16c", 0,zMainFile,0);
87852 if( zSuper==0 ) return SQLITE_NOMEM_BKPT;
87859 sqlite3OsDelete(pVfs, zSuper, 0);
87868 (iRandom>>8)&0xffffff, iRandom&0xff);
87879 SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_SUPER_JOURNAL, 0
87893 for(i=0; i<db->nDb; i++){
87897 if( zFile==0 ){
87900 assert( zFile[0]!=0 );
87905 sqlite3OsDelete(pVfs, zSuper, 0);
87915 if( 0==(sqlite3OsDeviceCharacteristics(pSuperJrnl)&SQLITE_IOCAP_SEQUENTIAL)
87919 sqlite3OsDelete(pVfs, zSuper, 0);
87934 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
87953 zSuper = 0;
87967 for(i=0; i<db->nDb; i++){
87995 int cnt = 0;
87996 int nWrite = 0;
87997 int nRead = 0;
88002 if( p->readOnly==0 ) nWrite++;
88032 assert( db->nStatement>0 );
88035 for(i=0; i<db->nDb; i++){
88051 p->iStatement = 0;
88092 if( (deferred && (db->nDeferredCons+db->nDeferredImmCons)>0)
88093 || (!deferred && p->nFkConstraint>0)
88098 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)==0 ) return SQLITE_ERROR;
88149 int eStatementOp = 0;
88157 mrc = p->rc & 0xff;
88163 mrc = isSpecialError = 0;
88188 p->nChange = 0;
88195 (void)sqlite3VdbeCheckFk(p, 0);
88206 && db->nVdbeWrite==(p->readOnly==0)
88233 p->nChange = 0;
88235 db->nDeferredCons = 0;
88236 db->nDeferredImmCons = 0;
88241 p->nChange = 0;
88244 p->nChange = 0;
88246 db->nStatement = 0;
88247 }else if( eStatementOp==0 ){
88256 p->nChange = 0;
88269 if( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ){
88272 p->zErrMsg = 0;
88277 p->nChange = 0;
88288 sqlite3VdbeSetChanges(db, 0);
88290 p->nChange = 0;
88303 assert( db->nVdbeWrite>=0 );
88318 assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 );
88345 if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db);
88363 if( sqlite3GlobalConfig.xSqllog && v->rc==SQLITE_OK && v->zSql && v->pc>=0 ){
88365 assert( v->db->init.busy==0 );
88408 if( p->pc>=0 ){
88422 if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
88424 for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
88429 p->zErrMsg = 0;
88431 p->pResultRow = 0;
88433 p->nWrite = 0;
88443 for(i=0; i<p->nOp; i++){
88448 char c, pc = 0;
88450 for(i=0; (c = p->zSql[i])!=0; i++){
88457 for(i=0; i<p->nOp; i++){
88464 cnt>0 ? cycles/cnt : 0
88507 ** function parameter corresponds to bit 0 etc.).
88512 if( (iOp<0)
88514 && pAux->iAuxArg>=0
88539 assert( db!=0 );
88540 assert( p->db==0 || p->db==db );
88570 for(i=0; i<p->nScan; i++){
88584 assert( p!=0 );
88586 assert( db!=0 );
88589 if( db->pnBytesFreed==0 ){
88590 assert( p->ppVPrev!=0 );
88612 rc = sqlite3BtreeTableMoveto(p->uc.pCursor, p->movetoTarget, 0, &res);
88614 if( res!=0 ) return SQLITE_CORRUPT_BKPT;
88618 p->deferredMoveto = 0;
88633 assert( p->uc.pCursor!=0 );
88677 ** 0 0 NULL
88685 ** 8 0 Integer constant 0
88686 ** 9 0 Integer constant 1
88691 ** The 8 and 9 types were added in 3.3.0, file format 4. Prior versions
88695 #if 0 /* Inlined into the OP_MakeRecord opcode */
88711 assert( pLen!=0 );
88713 *pLen = 0;
88714 return 0;
88718 # define MAX_6BYTE ((((i64)0x00008000)<<32)-1)
88723 if( i<0 ){
88730 *pLen = 0;
88758 assert( pMem->n>=0 );
88764 return ((n*2) + 12 + ((flags&MEM_Str)!=0));
88772 /* 0 1 2 3 4 5 6 7 8 9 */
88773 /* 0 */ 0, 1, 2, 3, 4, 6, 8, 8, 0, 0,
88774 /* 10 */ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
88848 t = u.i[0];
88849 u.i[0] = u.i[1];
88859 #define ONE_BYTE_INT(x) ((i8)(x)[0])
88860 #define TWO_BYTE_INT(x) (256*(i8)((x)[0])|(x)[1])
88861 #define THREE_BYTE_INT(x) (65536*(i8)((x)[0])|((x)[1]<<8)|(x)[2])
88862 #define FOUR_BYTE_UINT(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
88863 #define FOUR_BYTE_INT(x) (16777216*(i8)((x)[0])|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
88887 testcase( pMem->u.i<0 );
88897 static const u64 t1 = ((u64)0x3ff00000)<<32;
88901 assert( sizeof(r1)==sizeof(t2) && memcmp(&r1, &t2, sizeof(r1))==0 );
88924 return 0;
88935 pMem->n = 0;
88936 pMem->u.nZero = 0;
88940 case 0: { /* Null */
88950 testcase( pMem->u.i<0 );
88958 testcase( pMem->u.i<0 );
88966 testcase( pMem->u.i<0 );
88975 if( buf[0]&0x80 ) pMem->u.i |= 0xffffffff80000000LL;
88978 testcase( pMem->u.i<0 );
88986 testcase( pMem->u.i<0 );
88996 case 8: /* Integer 0 */
88998 /* EVIDENCE-OF: R-12976-22893 Value is the integer 0. */
89039 if( !p ) return 0;
89041 assert( pKeyInfo->aSortFlags!=0 );
89065 p->default_rc = 0;
89069 u = 0;
89076 /* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
89077 pMem->szMalloc = 0;
89078 pMem->z = 0;
89115 int i = 0;
89116 int rc = 0;
89122 if( pKeyInfo->db==0 ) return 1;
89125 /* mem1.flags = 0; // Will be initialized by sqlite3VdbeSerialGet() */
89126 VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
89135 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
89141 assert( pKeyInfo->aSortFlags!=0 );
89142 assert( pKeyInfo->nKeyField>0 );
89179 pKeyInfo->nAllField>i ? pKeyInfo->aColl[i] : 0);
89180 if( rc!=0 ){
89181 assert( mem1.szMalloc==0 ); /* See comment below */
89199 assert( mem1.szMalloc==0 );
89201 /* rc==0 here means that one of the keys ran out of fields and
89207 if( desiredResult==0 && rc==0 ) return 1;
89208 if( desiredResult<0 && rc<0 ) return 1;
89209 if( desiredResult>0 && rc>0 ) return 1;
89212 return 0;
89232 int nField = 0;
89240 assert( nKey>=0 );
89279 if( (v1==0 || v2==0) ){
89281 rc = 0;
89297 for(i=0; i<n; i++){
89298 if( z[i] ) return 0;
89317 assert( (pB1->flags & MEM_Zero)==0 || n1==0 );
89318 assert( (pB2->flags & MEM_Zero)==0 || n2==0 );
89396 ** are NULL, return 0.
89408 if( (f1 & f2 & (MEM_Int|MEM_IntReal))!=0 ){
89413 return 0;
89415 if( (f1 & f2 & MEM_Real)!=0 ){
89418 return 0;
89420 if( (f1&(MEM_Int|MEM_IntReal))!=0 ){
89423 if( (f2&MEM_Real)!=0 ){
89425 }else if( (f2&(MEM_Int|MEM_IntReal))!=0 ){
89428 return 0;
89433 if( (f1&MEM_Real)!=0 ){
89434 if( (f2&(MEM_Int|MEM_IntReal))!=0 ){
89449 if( (f1 & MEM_Str)==0 ){
89452 if( (f2 & MEM_Str)==0 ){
89467 return vdbeCompareMemString(pMem1, pMem2, pColl, 0);
89489 case 0:
89491 testcase( aKey[0]&0x80 );
89494 testcase( aKey[0]&0x80 );
89497 testcase( aKey[0]&0x80 );
89500 testcase( aKey[0]&0x80 );
89505 testcase( aKey[0]&0x80 );
89510 testcase( aKey[0]&0x80 );
89536 ** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
89549 int rc = 0; /* Return value */
89560 if( s1<0x80 ){
89565 szHdr1 = aKey1[0];
89570 if( (szHdr1 = aKey1[0])<0x80 ){
89576 i = 0;
89580 return 0; /* Corruption */
89583 VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
89586 assert( pPKey2->pKeyInfo->aSortFlags!=0 );
89587 assert( pPKey2->pKeyInfo->nKeyField>0 );
89600 }else if( serial_type==0 ){
89625 }else if( serial_type==0 ){
89636 assert( rc==0 );
89651 }else if( !(serial_type & 0x01) ){
89661 return 0; /* Corruption */
89673 if( rc==0 ) rc = mem1.n - pRhs->n;
89680 assert( (pRhs->flags & MEM_Zero)==0 || pRhs->n==0 );
89683 if( serial_type<12 || (serial_type & 0x01) ){
89691 return 0; /* Corruption */
89701 if( rc==0 ) rc = nStr - pRhs->n;
89709 if( serial_type==0
89711 || (serial_type==7 && serialGet7(&aKey1[d1], &mem1)!=0)
89713 assert( rc==0 );
89719 if( rc!=0 ){
89722 if( (sortFlags & KEYINFO_ORDER_BIGNULL)==0
89724 !=(serial_type==0 || (pRhs->flags&MEM_Null)))
89730 assert( mem1.szMalloc==0 ); /* See comment below */
89742 return 0; /* Corrupt index */
89749 assert( mem1.szMalloc==0 );
89751 /* rc==0 here means that one or both of the keys ran out of fields and
89765 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
89782 const u8 *aKey = &((const u8*)pKey1)[*(const u8*)pKey1 & 0x3F];
89791 assert( (*(u8*)pKey1)<=0x3F || CORRUPT_DB );
89795 testcase( lhs<0 );
89800 testcase( lhs<0 );
89805 testcase( lhs<0 );
89811 testcase( lhs<0 );
89816 testcase( lhs<0 );
89823 testcase( lhs<0 );
89827 lhs = 0;
89839 case 0: case 7:
89846 assert( pPKey2->u.i == pPKey2->aMem[0].u.i );
89881 assert( pPKey2->aMem[0].flags & MEM_Str );
89882 assert( pPKey2->aMem[0].n == pPKey2->n );
89883 assert( pPKey2->aMem[0].z == pPKey2->u.z );
89889 if( serial_type<0 ){
89895 }else if( !(serial_type & 0x01) ){
89900 int szHdr = aKey1[0];
89905 return 0; /* Corruption */
89910 if( res>0 ){
89912 }else if( res<0 ){
89916 if( res==0 ){
89923 }else if( res>0 ){
89958 int flags = p->aMem[0].flags;
89959 if( p->pKeyInfo->aSortFlags[0] ){
89960 if( p->pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL ){
89970 p->u.i = p->aMem[0].u.i;
89976 if( (flags & (MEM_Real|MEM_IntReal|MEM_Null|MEM_Blob))==0
89977 && p->pKeyInfo->aColl[0]==0
89980 p->u.z = p->aMem[0].z;
89981 p->n = p->aMem[0].n;
89998 i64 nCellKey = 0;
90015 sqlite3VdbeMemInit(&m, db, 0);
90025 testcase( szHdr>0x7fffffff );
90026 assert( m.n>=0 );
90060 testcase( m.szMalloc!=0 );
90082 i64 nCellKey = 0;
90091 /* nCellKey will always be between 0 and 0xffffffff because of the way
90093 if( nCellKey<=0 || nCellKey>0x7fffffff ){
90094 *res = 0;
90097 sqlite3VdbeMemInit(&m, db, 0);
90102 *res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, pUnpacked, 0);
90167 ** 0 instead. Unless it is NULL, apply affinity aff (one of the SQLITE_AFF_*
90173 assert( iVar>0 );
90176 assert( (v->db->flags & SQLITE_EnableQPSG)==0
90177 || (v->db->mDbFlags & DBFLAG_InternalFunc)!=0 );
90178 if( 0==(pMem->flags & MEM_Null) ){
90187 return 0;
90196 assert( iVar>0 );
90197 assert( (v->db->flags & SQLITE_EnableQPSG)==0
90198 || (v->db->mDbFlags & DBFLAG_InternalFunc)!=0 );
90200 v->expmask |= 0x80000000;
90218 if( pCtx->pVdbe==0 ) return 1;
90235 return 0;
90248 assert( (pWalker->u.aMem[pExpr->iTable].flags & MEM_Undefined)==0 );
90266 pVtab->zErrMsg = 0;
90282 assert( db!=0 );
90285 for(i=0; i<nField; i++){
90315 static const u8 fakeSortOrder = 0;
90327 assert( db->pPreUpdate==0 );
90328 memset(&preupdate, 0, sizeof(PreUpdate));
90329 if( HasRowid(pTab)==0 ){
90330 iKey1 = iKey2 = 0;
90340 assert( pCsr!=0 );
90361 db->pPreUpdate = 0;
90367 for(i=0; i<pCsr->nField; i++){
90407 return p==0 || p->expired;
90417 if( p->db==0 ){
90421 return 0;
90425 if( p==0 ){
90441 assert( p->startTime>0 );
90442 assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 );
90443 assert( db->init.busy==0 );
90444 assert( p->zSql!=0 );
90455 p->startTime = 0;
90462 if( ((P)->startTime)>0 ){ invokeProfileCallback(DB,P); }
90478 if( pStmt==0 ){
90507 if( pStmt==0 ){
90534 if( pStmt==0 ){
90542 for(i=0; i<p->nVar; i++){
90546 assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || p->expmask==0 );
90563 assert( p->flags==MEM_Null && p->z==0 );
90564 return 0;
90567 return p->n ? p->z : 0;
90589 return ((pMem->flags & MEM_Subtype) ? pMem->eSubtype : 0);
90595 && zPType!=0
90597 && strcmp(p->u.zPType, zPType)==0
90601 return 0;
90624 SQLITE_BLOB, /* 0x00 (not possible) */
90625 SQLITE_NULL, /* 0x01 NULL */
90626 SQLITE_TEXT, /* 0x02 TEXT */
90627 SQLITE_NULL, /* 0x03 (not possible) */
90628 SQLITE_INTEGER, /* 0x04 INTEGER */
90629 SQLITE_NULL, /* 0x05 (not possible) */
90630 SQLITE_INTEGER, /* 0x06 INTEGER + TEXT */
90631 SQLITE_NULL, /* 0x07 (not possible) */
90632 SQLITE_FLOAT, /* 0x08 FLOAT */
90633 SQLITE_NULL, /* 0x09 (not possible) */
90634 SQLITE_FLOAT, /* 0x0a FLOAT + TEXT */
90635 SQLITE_NULL, /* 0x0b (not possible) */
90636 SQLITE_INTEGER, /* 0x0c (not possible) */
90637 SQLITE_NULL, /* 0x0d (not possible) */
90638 SQLITE_INTEGER, /* 0x0e (not possible) */
90639 SQLITE_NULL, /* 0x0f (not possible) */
90640 SQLITE_BLOB, /* 0x10 BLOB */
90641 SQLITE_NULL, /* 0x11 (not possible) */
90642 SQLITE_TEXT, /* 0x12 (not possible) */
90643 SQLITE_NULL, /* 0x13 (not possible) */
90644 SQLITE_INTEGER, /* 0x14 INTEGER + BLOB */
90645 SQLITE_NULL, /* 0x15 (not possible) */
90646 SQLITE_INTEGER, /* 0x16 (not possible) */
90647 SQLITE_NULL, /* 0x17 (not possible) */
90648 SQLITE_FLOAT, /* 0x18 FLOAT + BLOB */
90649 SQLITE_NULL, /* 0x19 (not possible) */
90650 SQLITE_FLOAT, /* 0x1a (not possible) */
90651 SQLITE_NULL, /* 0x1b (not possible) */
90652 SQLITE_INTEGER, /* 0x1c (not possible) */
90653 SQLITE_NULL, /* 0x1d (not possible) */
90654 SQLITE_INTEGER, /* 0x1e (not possible) */
90655 SQLITE_NULL, /* 0x1f (not possible) */
90656 SQLITE_FLOAT, /* 0x20 INTREAL */
90657 SQLITE_NULL, /* 0x21 (not possible) */
90658 SQLITE_FLOAT, /* 0x22 INTREAL + TEXT */
90659 SQLITE_NULL, /* 0x23 (not possible) */
90660 SQLITE_FLOAT, /* 0x24 (not possible) */
90661 SQLITE_NULL, /* 0x25 (not possible) */
90662 SQLITE_FLOAT, /* 0x26 (not possible) */
90663 SQLITE_NULL, /* 0x27 (not possible) */
90664 SQLITE_FLOAT, /* 0x28 (not possible) */
90665 SQLITE_NULL, /* 0x29 (not possible) */
90666 SQLITE_FLOAT, /* 0x2a (not possible) */
90667 SQLITE_NULL, /* 0x2b (not possible) */
90668 SQLITE_FLOAT, /* 0x2c (not possible) */
90669 SQLITE_NULL, /* 0x2d (not possible) */
90670 SQLITE_FLOAT, /* 0x2e (not possible) */
90671 SQLITE_NULL, /* 0x2f (not possible) */
90672 SQLITE_BLOB, /* 0x30 (not possible) */
90673 SQLITE_NULL, /* 0x31 (not possible) */
90674 SQLITE_TEXT, /* 0x32 (not possible) */
90675 SQLITE_NULL, /* 0x33 (not possible) */
90676 SQLITE_FLOAT, /* 0x34 (not possible) */
90677 SQLITE_NULL, /* 0x35 (not possible) */
90678 SQLITE_FLOAT, /* 0x36 (not possible) */
90679 SQLITE_NULL, /* 0x37 (not possible) */
90680 SQLITE_FLOAT, /* 0x38 (not possible) */
90681 SQLITE_NULL, /* 0x39 (not possible) */
90682 SQLITE_FLOAT, /* 0x3a (not possible) */
90683 SQLITE_NULL, /* 0x3b (not possible) */
90684 SQLITE_FLOAT, /* 0x3c (not possible) */
90685 SQLITE_NULL, /* 0x3d (not possible) */
90686 SQLITE_FLOAT, /* 0x3e (not possible) */
90687 SQLITE_NULL, /* 0x3f (not possible) */
90717 return (pVal->flags&MEM_FromBind)!=0;
90724 if( pOrig==0 ) return 0;
90726 if( pNew==0 ) return 0;
90727 memset(pNew, 0, sizeof(*pNew));
90730 pNew->db = 0;
90736 pNew = 0;
90768 u8 enc, /* Encoding of z. 0 for BLOBs */
90795 if( xDel==0 ){
90803 if( pCtx!=0 ){
90807 assert( pCtx!=0 );
90819 if( pCtx==0 || n<0 ){
90824 assert( n>=0 );
90826 setResultStrOrError(pCtx, z, n, 0, xDel);
90836 if( pCtx==0 ){
90837 invokeValueDestructor(z, xDel, 0);
90842 if( n>0x7fffffff ){
90845 setResultStrOrError(pCtx, z, (int)n, 0, xDel);
90850 if( pCtx==0 ) return;
90857 if( pCtx==0 ) return;
90866 if( pCtx==0 ) return;
90875 if( pCtx==0 ) return;
90882 if( pCtx==0 ) return;
90889 if( pCtx==0 ) return;
90902 if( pCtx==0 ){
90903 invokeValueDestructor(pPtr, xDestructor, 0);
90916 if( pCtx==0 ) return;
90918 #if defined(SQLITE_STRICT_SUBTYPE) && SQLITE_STRICT_SUBTYPE+0!=0
90919 if( pCtx->pFunc!=0
90920 && (pCtx->pFunc->funcFlags & SQLITE_RESULT_SUBTYPE)==0
90932 pOut->eSubtype = eSubtype & 0xff;
90942 if( pCtx==0 ){
90943 invokeValueDestructor(z, xDel, 0);
90958 if( pCtx==0 ){
90959 invokeValueDestructor(z, xDel, 0);
90969 if( n>0x7fffffff ){
91009 if( pCtx==0 ) return;
91010 if( pValue==0 ){
91024 sqlite3_result_zeroblob64(pCtx, n>0 ? n : 0);
91030 if( pCtx==0 ) return SQLITE_MISUSE_BKPT;
91047 if( pCtx==0 ) return;
91062 if( pCtx==0 ) return;
91073 if( pCtx==0 ) return;
91104 for(i=0; i<db->nDb; i++){
91111 if( nEntry>0 && db->xWalCallback && rc==SQLITE_OK ){
91142 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
91157 if( db->nVdbeActive==0 ){
91158 AtomicStore(&db->u1.isInterrupted, 0);
91161 assert( db->nVdbeWrite>0 || db->autoCommit==0
91162 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
91166 if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
91170 assert( p->startTime==0 );
91175 if( p->readOnly==0 ) db->nVdbeWrite++;
91177 p->pc = 0;
91184 ** with version 3.7.0, we changed this so that sqlite3_reset() would
91199 if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
91228 assert( db->mallocFailed==0 );
91236 p->pResultRow = 0;
91243 }else if( rc!=SQLITE_DONE && (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
91255 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ) rc = p->rc;
91260 assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0
91262 || (rc&0xff)==SQLITE_BUSY || rc==SQLITE_MISUSE
91275 int cnt = 0; /* Counter to prevent infinite loop of reprepares */
91292 ** program counter to 0 to ensure that when the statement is
91302 v->zErrMsg = 0;
91308 if( savedPc>=0 ){
91315 assert( v->expired==0 );
91328 if( p==0 ) return 0;
91346 if( p==0 ) return 0;
91369 if( p==0 ) return 0;
91388 ** Implementation of sqlite3_vtab_in_first() (if bNext==0) and
91389 ** sqlite3_vtab_in_next() (if bNext!=0).
91394 int bNext /* 1 for _next(). 0 for _first() */
91399 *ppOut = 0;
91400 if( pVal==0 ) return SQLITE_MISUSE_BKPT;
91401 if( (pVal->flags & MEM_Dyn)==0 || pVal->xDel!=sqlite3VdbeValueListFree ){
91407 assert( pVal->u.zPType!=0 && strcmp(pVal->u.zPType,"ValueList")==0 );
91411 rc = sqlite3BtreeNext(pRhs->pCsr, 0);
91413 int dummy = 0;
91421 memset(&sMem, 0, sizeof(sMem));
91431 if( (pOut->flags & MEM_Ephem)!=0 && sqlite3VdbeMemMakeWriteable(pOut) ){
91447 return valueFromValueList(pVal, ppOut, 0);
91469 assert( p->pVdbe!=0 );
91471 sqlite3_int64 iTime = 0;
91472 sqlite3_int64 *piTime = p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime;
91474 if( *piTime==0 ){
91476 if( rc ) *piTime = 0;
91487 assert( (pMem->flags & MEM_Agg)==0 );
91488 if( nByte<=0 ){
91490 pMem->z = 0;
91496 memset(pMem->z, 0, nByte);
91510 testcase( nByte<0 );
91511 if( (p->pMem->flags & MEM_Agg)==0 ){
91522 ** The left-most argument is 0.
91532 if( pCtx==0 ) return 0;
91536 if( pCtx->pVdbe==0 ) return 0;
91538 assert( pCtx->pVdbe!=0 );
91541 if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
91545 return 0;
91553 ** The left-most argument is 0.
91569 if( pCtx==0 ) return;
91574 if( pVdbe==0 ) goto failed;
91576 assert( pVdbe!=0 );
91580 if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
91584 if( pAuxData==0 ){
91591 if( pCtx->isError==0 ) pCtx->isError = -1;
91627 if( pVm==0 ) return 0;
91637 if( pVm==0 || pVm->pResultRow==0 ) return 0;
91659 /* .u = */ {0},
91660 /* .z = */ (char*)0,
91661 /* .n = */ (int)0,
91663 /* .enc = */ (u8)0,
91664 /* .eSubtype = */ (u8)0,
91665 /* .db = */ (sqlite3*)0,
91666 /* .szMalloc = */ (int)0,
91667 /* .uTemp = */ (u32)0,
91668 /* .zMalloc = */ (char*)0,
91669 /* .xDel = */ (void(*)(void*))0,
91671 /* .pScopyFrom = */ (Mem*)0,
91672 /* .mScopyFlags= */ 0,
91689 if( pVm==0 ) return (Mem*)columnNullValue();
91692 if( pVm->pResultRow!=0 && i<pVm->nResColumn && i>=0 ){
91728 assert( p->db!=0 );
91809 /* 0 */ 'a', 'd', 'd', 'r', 0,
91810 /* 5 */ 'o', 'p', 'c', 'o', 'd', 'e', 0,
91811 /* 12 */ 'p', '1', 0,
91812 /* 15 */ 'p', '2', 0,
91813 /* 18 */ 'p', '3', 0,
91814 /* 21 */ 'p', '4', 0,
91815 /* 24 */ 'p', '5', 0,
91816 /* 27 */ 'c', 'o', 'm', 'm', 'e', 'n', 't', 0,
91817 /* 35 */ 'i', 'd', 0,
91818 /* 38 */ 'p', 'a', 'r', 'e', 'n', 't', 0,
91819 /* 45 */ 'n', 'o', 't', 'u', 's', 'e', 'd', 0,
91820 /* 53 */ 'd', 'e', 't', 'a', 'i', 'l', 0
91823 0, 5, 12, 15, 18, 21, 24, 27,
91829 ** xFunc() then return that string. If N is out of range, return 0.
91834 ** 0 The column name as it should be displayed for output
91854 if( pStmt==0 ){
91856 return 0;
91859 if( N<0 ) return 0;
91860 ret = 0;
91863 assert( db!=0 );
91867 if( useType>0 ) goto columnName_end;
91893 assert( db->mallocFailed==0 || db->mallocFailed==1 );
91896 ret = 0;
91909 return columnName(pStmt, N, 0, COLNAME_NAME);
91932 return columnName(pStmt, N, 0, COLNAME_DECLTYPE);
91948 return columnName(pStmt, N, 0, COLNAME_DATABASE);
91962 return columnName(pStmt, N, 0, COLNAME_TABLE);
91976 return columnName(pStmt, N, 0, COLNAME_COLUMN);
92033 assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || p->expmask==0 );
92034 if( p->expmask!=0 && (p->expmask & (i>=31 ? 0x80000000 : (u32)1<<i))!=0 ){
92057 if( zData!=0 ){
92060 if( rc==SQLITE_OK && encoding!=0 ){
92087 if( nData<0 ) return SQLITE_MISUSE_BKPT;
92089 return bindText(pStmt, i, zData, nData, xDel, 0);
92099 return bindText(pStmt, i, zData, nData, xDel, 0);
92238 if( p==0 ) return SQLITE_MISUSE_BKPT;
92244 assert( (n & 0x7FFFFFFF)==n );
92258 return p ? p->nVar : 0;
92269 if( p==0 ) return 0;
92276 ** return 0.
92279 if( p==0 || zName==0 ) return 0;
92296 for(i=0; i<pFrom->nVar; i++){
92322 assert( (pTo->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || pTo->expmask==0 );
92326 assert( (pFrom->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || pFrom->expmask==0 );
92341 return pStmt ? ((Vdbe*)pStmt)->db : 0;
92357 return pStmt ? ((Vdbe*)pStmt)->explain : 0;
92367 if( pStmt==0 ) return SQLITE_MISUSE_BKPT;
92372 }else if( eMode<0 || eMode>2 ){
92374 }else if( (v->prepFlags & SQLITE_PREPARE_SAVESQL)==0 ){
92401 return v!=0 && v->eVdbeState==VDBE_RUN_STATE;
92415 return 0;
92419 if( pStmt==0 ){
92436 || (op!=SQLITE_STMTSTATUS_MEMUSED && (op<0||op>=ArraySize(pVdbe->aCounter)))
92439 return 0;
92445 v = 0;
92450 db->pnBytesFreed = 0;
92455 if( resetFlag ) pVdbe->aCounter[op] = 0;
92465 return p ? p->zSql : 0;
92479 return 0;
92481 char *z = 0;
92499 if( p==0 ) return 0;
92500 if( p->zNormSql==0 && ALWAYS(p->zSql!=0) ){
92524 memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1));
92540 if( db==0 || ppValue==0 ){
92554 if( iIdx>=p->pCsr->nField || iIdx<0 ){
92560 if( p->pUnpacked==0 ){
92568 rc = sqlite3BtreePayload(p->pCsr->uc.pCursor, 0, nRec, aRec);
92607 p = db!=0 ? db->pPreUpdate : 0;
92611 return (p ? p->keyinfo.nKeyField : 0);
92630 p = db!=0 ? db->pPreUpdate : 0;
92634 return (p ? p->v->nFrame : 0);
92646 p = db!=0 ? db->pPreUpdate : 0;
92665 if( db==0 || ppValue==0 ){
92677 if( iIdx>=p->pCsr->nField || iIdx<0 ){
92717 assert( iIdx>=0 && iIdx<p->pCsr->nField );
92719 if( pMem->flags==0 ){
92750 ScanStatus *pScan = 0;
92754 if( p==0 || pOut==0
92769 if( iScan<0 ){
92772 i64 res = 0;
92773 for(ii=0; ii<nOp; ii++){
92777 return 0;
92785 ** ScanStatus structures with ScanStatus.addrLoop set to 0. */
92786 for(idx=0; idx<p->nScan; idx++){
92790 if( iScan<0 ) break;
92795 assert( pScan==0 || pScan==&p->aScan[idx] );
92800 if( pScan->addrLoop>0 ){
92808 if( pScan->addrVisit>0 ){
92833 *(const char**)pOut = 0;
92854 i64 res = 0;
92855 if( pScan->aAddrRange[0]==0 ){
92859 for(ii=0; ii<ArraySize(pScan->aAddrRange); ii+=2){
92862 if( iIns==0 ) break;
92863 if( iIns>0 ){
92870 for(iOp=0; iOp<nOp; iOp++){
92873 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_NCYCLE)==0 ){
92888 return 0;
92900 return sqlite3_stmt_scanstatus_v2(pStmt, iScan, iScanStatusOp, 0, pOut);
92909 for(ii=0; p!=0 && ii<p->nOp; ii++){
92911 pOp->nExec = 0;
92912 pOp->nCycle = 0;
92949 int nTotal = 0;
92952 *pnToken = 0;
92953 while( zSql[0] ){
92955 assert( n>0 && tokenType!=TK_ILLEGAL );
92995 int idx = 0; /* Index of a host parameter */
93007 sqlite3StrAccumInit(&out, 0, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
93013 assert( (zRawSql - zStart) > 0 );
93016 }else if( p->nVar==0 ){
93019 while( zRawSql[0] ){
93021 assert( n>0 );
93024 assert( zRawSql[0] || nToken==0 );
93025 if( nToken==0 ) break;
93026 if( zRawSql[0]=='?' ){
93034 assert( zRawSql[0]==':' || zRawSql[0]=='$' ||
93035 zRawSql[0]=='@' || zRawSql[0]=='#' );
93036 testcase( zRawSql[0]==':' );
93037 testcase( zRawSql[0]=='$' );
93038 testcase( zRawSql[0]=='@' );
93039 testcase( zRawSql[0]=='#' );
93041 assert( idx>0 );
93045 assert( idx>0 && idx<=p->nVar );
93058 memset(&utf8, 0, sizeof(utf8));
93063 out.nAlloc = 0;
93072 while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
93094 for(i=0; i<nOut; i++){
93095 sqlite3_str_appendf(&out, "%02x", pVar->z[i]&0xff);
93160 SQLITE_API int sqlite3_search_count = 0;
93172 SQLITE_API int sqlite3_interrupt_count = 0;
93183 SQLITE_API int sqlite3_sort_count = 0;
93194 SQLITE_API int sqlite3_max_blobsize = 0;
93196 if( (p->flags & (MEM_Str|MEM_Blob))!=0 && p->n>sqlite3_max_blobsize ){
93220 SQLITE_API int sqlite3_found_count = 0;
93248 static u64 n = 0;
93265 ** M: 2 - two-way branch (I=0: fall-thru 1: jump )
93266 ** 3 - two-way + NULL (I=0: fall-thru 1: jump 2: NULL )
93267 ** 4 - OP_Jump (I=0: jump p1 1: jump p2 2: jump p3)
93269 ** In other words, if M is 2, then I is either 0 (for fall-through) or
93270 ** 1 (for when the branch is taken). If M is 3, the I is 0 for an
93274 ** When M is 4, that means that an OP_Jump is being run. I is 0, 1, or 2
93282 ** always taken, the flags should be 0x05 since the fall-through and
93284 ** flags should be 0x06 since only the fall-through approach is allowed.
93286 ** Bit 0x08 of the flags indicates an OP_Jump opcode that is only
93287 ** interested in equal or not-equal. In other words, I==0 and I==2
93300 assert( I<=2 ); /* 0: fall through, 1: taken, 2: alternate taken */
93303 /* Transform I from a integer [0,1,2] into a bitmask of [1,2,4] */
93310 assert( (I & mNever)==0 );
93311 if( sqlite3GlobalConfig.xVdbeBranch==0 ) return; /*NO_TEST*/
93315 ** I - Mask of bits 0x07 indicating which cases are are
93316 ** fulfilled by this instance of the jump. 0x01 means
93317 ** fall-thru, 0x02 means taken, 0x04 means NULL. Any
93325 if( M==2 ) I |= 0x04;
93327 I |= 0x08;
93328 if( (mNever&0x08)!=0 && (I&0x05)!=0) I |= 0x05; /*NO_TEST*/
93331 iSrcLine&0xffffff, I, M);
93347 if( ((P)->flags&MEM_Ephem)!=0 \
93377 ** The memory cell for cursor 0 is aMem[0]. The rest are allocated from
93381 Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem;
93384 VdbeCursor *pCx = 0;
93387 (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
93389 assert( iCur>=0 && iCur<p->nCursor );
93392 p->apCsr[iCur] = 0;
93400 assert( (pMem->flags & MEM_Dyn)==0 );
93401 assert( pMem->szMalloc==0 || pMem->z==pMem->zMalloc );
93403 if( pMem->szMalloc>0 ){
93407 if( pMem->zMalloc==0 ){
93408 pMem->szMalloc = 0;
93409 return 0;
93415 memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
93440 return 0==sqlite3Atoi64(pRec->z, piValue, pRec->n, pRec->enc);
93464 if( rc<=0 ) return;
93510 if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
93511 if( (pRec->flags & (MEM_Real|MEM_IntReal))==0 ){
93523 if( 0==(pRec->flags&MEM_Str) ){ /*OPTIMIZATION-IF-FALSE*/
93545 applyNumericAffinity(pMem, 0);
93572 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 );
93573 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
93575 pMem->u.i = 0;
93579 if( rc<=0 ){
93580 if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
93586 }else if( rc==1 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)==0 ){
93601 assert( (pMem->flags & MEM_Null)==0
93602 || pMem->db==0 || pMem->db->mallocFailed );
93613 return 0;
93629 assert( (f & (MEM_Static|MEM_Ephem))==0 );
93632 assert( (f & (MEM_Dyn|MEM_Ephem))==0 );
93635 assert( (f & (MEM_Static|MEM_Dyn))==0 );
93640 for(i=0; i<25 && i<pMem->n; i++){
93641 sqlite3_str_appendf(pStr, "%02X", ((int)pMem->z[i] & 0xFF));
93644 for(i=0; i<25 && i<pMem->n; i++){
93657 assert( (f & (MEM_Static|MEM_Ephem))==0 );
93660 assert( (f & (MEM_Dyn|MEM_Ephem))==0 );
93663 assert( (f & (MEM_Static|MEM_Dyn))==0 );
93668 for(j=0; j<25 && j<pMem->n; j++){
93670 sqlite3_str_appendchar(pStr, 1, (c>=0x20&&c<=0x7f) ? c : '.');
93674 sqlite3_str_appendf(pStr, "(0-term)");
93691 }else if( (p->flags & (MEM_IntReal))!=0 ){
93704 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
93708 if( p->flags & MEM_Subtype ) printf(" subtype=0x%02x", p->eSubtype);
93756 int n = 0;
93775 assert( pOp->p2>0 );
93793 u64 h = 0;
93835 if( len > 4000 && pC->pKeyInfo==0 ){
93848 if( pC->colCache==0 ){
93850 if( pC->pCache==0 ) return SQLITE_NOMEM;
93854 if( pCache->pCValue==0
93862 if( pBuf==0 ) return SQLITE_NOMEM;
93865 pBuf[len] = 0;
93866 pBuf[len+1] = 0;
93867 pBuf[len+2] = 0;
93882 rc = sqlite3VdbeMemSetStr(pDest, pBuf, len, 0,
93889 if( (t&1)!=0 && encoding==SQLITE_UTF8 ){
93890 pDest->z[len] = 0;
93924 int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */
93925 u8 iCompareIsInit = 0; /* iCompare is initialized */
93929 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
93931 int iCompare = 0; /* Result of last comparison */
93932 u64 nVmStep = 0; /* Number of virtual machine steps */
93937 Mem *pIn1 = 0; /* 1st input operand */
93938 Mem *pIn2 = 0; /* 2nd input operand */
93939 Mem *pIn3 = 0; /* 3rd input operand */
93940 Mem *pOut = 0; /* Output operand */
93941 u32 colCacheCtr = 0; /* Column cache counter */
93943 u64 *pnCycle = 0;
93944 int bStmtScanStatus = IS_STMT_SCANSTATUS(db)!=0;
93955 assert( 0 < db->nProgressOps );
93966 assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
93969 assert( p->bIsReader || p->readOnly!=0 );
93970 p->iCurrentTime = 0;
93971 assert( p->explain==0 );
93972 db->busyHandler.nBusy = 0;
93977 if( p->pc==0
93978 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
93985 for(i=0; i<p->nOp; i++){
93990 for(i=0; i<p->nOp; i++){
93994 once = 0;
94013 if( sqlite3NProfileCnt==0 ) *pnCycle -= sqlite3Hwtime();
94036 if( sqlite3_interrupt_count>0 ){
94038 if( sqlite3_interrupt_count==0 ){
94048 if( (opProperty & OPFLG_IN1)!=0 ){
94049 assert( pOp->p1>0 );
94055 if( (opProperty & OPFLG_IN2)!=0 ){
94056 assert( pOp->p2>0 );
94062 if( (opProperty & OPFLG_IN3)!=0 ){
94063 assert( pOp->p3>0 );
94069 if( (opProperty & OPFLG_OUT2)!=0 ){
94070 assert( pOp->p2>0 );
94074 if( (opProperty & OPFLG_OUT3)!=0 ){
94075 assert( pOp->p3>0 );
94130 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell
94171 while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
94172 assert( db->nProgressOps!=0 );
94191 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
94193 assert( VdbeMemDynamic(pIn1)==0 );
94208 ** OP_Return becomes a no-op. If P3 is 0, then register P1 must hold an
94210 ** this opcode is used in combination with OP_BeginSubrtn, and set to 0
94229 VdbeBranchTaken(0, 2);
94239 ** If P2!=0 then the coroutine implementation immediately follows
94246 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
94247 assert( pOp->p2>=0 && pOp->p2<p->nOp );
94248 assert( pOp->p3>=0 && pOp->p3<p->nOp );
94253 if( pOp->p2==0 ) break;
94258 assert( pOp->p2>0 ); /* There are never any jumps to instruction 0 */
94278 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
94281 assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
94303 assert( VdbeMemDynamic(pIn1)==0 );
94325 if( (pIn3->flags & MEM_Null)==0 ) break;
94336 ** or sqlite3_finalize(). For a normal halt, this should be SQLITE_OK (0).
94337 ** For errors, it can be some other value. If P1!=0 then P2 will determine
94345 ** P5 is a value between 0 and 4, inclusive, that modifies the P4 string.
94347 ** 0: (no change)
94356 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
94419 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
94420 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
94445 assert( pOp->p4.pI64!=0 );
94475 assert( pOp->p4.z!=0 );
94485 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
94486 assert( VdbeMemDynamic(pOut)==0 );
94487 pOut->szMalloc = 0;
94516 ** if( P3!=0 and reg[P3]==P5 ) reg[P2] := CAST(reg[P2] as BLOB)
94519 assert( pOp->p4.z!=0 );
94527 if( pOp->p3>0 ){
94579 pOut->n = 0;
94581 pOut->uTemp = 0;
94583 while( cnt>0 ){
94588 pOut->n = 0;
94603 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
94619 if( pOp->p4.z==0 ){
94623 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
94638 assert( pOp->p1>0 && pOp->p1<=p->nVar );
94669 assert( n>0 && p1>0 && p2>0 );
94681 pIn1->pScopyFrom = 0;
94703 ** If the 0x0002 bit of P5 is set then also clear the MEM_Subtype flag in the
94704 ** destination. The 0x0001 bit of P5 indicates that this Copy opcode cannot
94705 ** be merged. The 0x0001 bit is used by the query planner and does not
94722 if( (pOut->flags & MEM_Subtype)!=0 && (pOp->p5 & 0x0002)!=0 ){
94726 pOut->pScopyFrom = 0;
94729 if( (n--)==0 ) break;
94771 assert( (pIn1->flags & MEM_Int)!=0 );
94789 if( (rc = sqlite3VdbeCheckFk(p,0))!=SQLITE_OK ){
94806 assert( pOp->p1>0 || CORRUPT_DB );
94815 for(i=0; i<pOp->p2; i++){
94823 pMem[i].pScopyFrom = 0;
94829 db->trace.xV2(SQLITE_TRACE_ROW, db->pTraceArg, p, 0);
94866 if( (flags1 & (MEM_Str|MEM_Blob))==0 ){
94867 if( sqlite3VdbeMemStringify(pIn1,encoding,0) ) goto no_mem;
94869 }else if( (flags1 & MEM_Zero)!=0 ){
94874 if( (flags2 & (MEM_Str|MEM_Blob))==0 ){
94875 if( sqlite3VdbeMemStringify(pIn2,encoding,0) ) goto no_mem;
94877 }else if( (flags2 & MEM_Zero)!=0 ){
94898 pOut->z[nByte]=0;
94899 pOut->z[nByte+1] = 0;
94962 if( (type1 & type2 & MEM_Int)!=0 ){
94971 if( iA==0 ) goto arithmetic_result_is_null;
94977 if( iA==0 ) goto arithmetic_result_is_null;
94985 }else if( ((type1 | type2) & MEM_Null)!=0 ){
94990 if( (type1 & type2 & MEM_Int)!=0 ) goto int_math;
94999 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
95000 if( rA==(double)0 ) goto arithmetic_result_is_null;
95007 if( iA==0 ) goto arithmetic_result_is_null;
95040 ** maximum. The P1 register is initialized to 0 by this instruction.
95049 sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
95107 }else if( iB!=0 ){
95111 if( iB<0 ){
95118 iA = (iA>=0 || op==OP_ShiftLeft) ? 0 : -1;
95126 if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB);
95142 ** To force any register to be an integer, just add 0.
95156 ** without data loss, then jump immediately to P2, or if P2==0
95161 if( (pIn1->flags & MEM_Int)==0 ){
95163 if( (pIn1->flags & MEM_Int)==0 ){
95165 if( pOp->p2==0 ){
95173 VdbeBranchTaken(0, 2);
95244 ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
95288 ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
95342 if( (flags1 & flags3 & MEM_Int)!=0 ){
95363 iCompare = 0;
95366 VdbeBranchTaken(0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
95376 assert( (flags1 & MEM_Cleared)==0 );
95377 assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 || CORRUPT_DB );
95378 testcase( (pOp->p5 & SQLITE_JUMPIFNULL)!=0 );
95379 if( (flags1&flags3&MEM_Null)!=0
95380 && (flags3&MEM_Cleared)==0
95382 res = 0; /* Operands are equal */
95406 applyNumericAffinity(pIn1,0);
95411 applyNumericAffinity(pIn3,0);
95414 }else if( affinity==SQLITE_AFF_TEXT && ((flags1 | flags3) & MEM_Str)!=0 ){
95415 if( (flags1 & MEM_Str)!=0 ){
95417 }else if( (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
95426 if( (flags3 & MEM_Str)!=0 ){
95428 }else if( (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
95437 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
95449 if( res<0 ){
95451 }else if( res==0 ){
95465 VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
95490 for(iAddr = (int)(pOp - aOp) - 1; ALWAYS(iAddr>=0); iAddr--){
95497 VdbeBranchTaken(iCompare==0, 2);
95498 if( iCompare==0 ) goto jump_to_p2;
95555 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ){
95556 aPermute = 0;
95562 assert( aPermute!=0 );
95566 assert( n>0 );
95567 assert( pKeyInfo!=0 );
95572 int k, mx = 0;
95573 for(k=0; k<n; k++) if( aPermute[k]>(u32)mx ) mx = aPermute[k];
95574 assert( p1>0 && p1+mx<=(p->nMem+1 - p->nCursor)+1 );
95575 assert( p2>0 && p2+mx<=(p->nMem+1 - p->nCursor)+1 );
95577 assert( p1>0 && p1+n<=(p->nMem+1 - p->nCursor)+1 );
95578 assert( p2>0 && p2+n<=(p->nMem+1 - p->nCursor)+1 );
95581 for(i=0; i<n; i++){
95617 if( iCompare<0 ){
95618 VdbeBranchTaken(0,4); pOp = &aOp[pOp->p1 - 1];
95619 }else if( iCompare==0 ){
95633 ** If either P1 or P2 is 0 (false) then the result is 0 even if
95649 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
95650 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
95655 static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
95658 static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
95678 ** boolean (a 0 or 1) in register P2. Or if the value in register P1 is
95685 ** <li> If P3==0 and P4==0 then r[P2] := r[P1] IS TRUE
95687 ** <li> If P3==0 and P4==1 then r[P2] := r[P1] IS NOT TRUE
95688 ** <li> If P3==1 and P4==0 then r[P2] := r[P1] IS NOT FALSE
95693 assert( pOp->p4.i==0 || pOp->p4.i==1 );
95694 assert( pOp->p3==0 || pOp->p3==1 );
95710 if( (pIn1->flags & MEM_Null)==0 ){
95711 sqlite3VdbeMemSetInt64(pOut, !sqlite3VdbeBooleanValue(pIn1,0));
95729 if( (pIn1->flags & MEM_Null)==0 ){
95755 assert( p->aOp[0].opcode==OP_Init );
95758 if( (p->pFrame->aOnce[iAddr/8] & (1<<(iAddr & 7)))!=0 ){
95764 if( p->aOp[0].p1==pOp->p1 ){
95769 VdbeBranchTaken(0, 2);
95770 pOp->p1 = p->aOp[0].p1;
95783 VdbeBranchTaken(c!=0, 2);
95797 VdbeBranchTaken(c!=0, 2);
95809 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
95810 if( (pIn1->flags & MEM_Null)!=0 ){
95833 ** (0x01) bit. SQLITE_FLOAT is the 0x02 bit. SQLITE_TEXT is 0x04.
95834 ** SQLITE_BLOB is 0x08. SQLITE_NULL is 0x10.
95837 ** when P1>=0. If the database contains a NaN value, this opcode will think
95838 ** that the datatype is REAL when it should be NULL. When P1<0 and the value
95840 ** distinguish between NULL and REAL. The problem only arises then P1>=0.
95853 assert( pOp->p1>=0 || (pOp->p3>=0 && pOp->p3<=(p->nMem+1 - p->nCursor)) );
95854 if( pOp->p1>=0 ){
95856 assert( pC!=0 );
95857 assert( pOp->p3>=0 );
95862 typeMask = 0x04; /* SQLITE_TEXT */
95864 typeMask = 0x08; /* SQLITE_BLOB */
95868 0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x2,
95869 0x01, 0x01, 0x10, 0x10
95871 testcase( serialType==0 );
95887 testcase( typeMask==0x01 );
95888 testcase( typeMask==0x02 );
95889 testcase( typeMask==0x04 );
95890 testcase( typeMask==0x08 );
95891 testcase( typeMask==0x10 );
95896 testcase( typeMask==0x01 );
95897 testcase( typeMask==0x02 );
95898 testcase( typeMask==0x04 );
95899 testcase( typeMask==0x08 );
95900 testcase( typeMask==0x10 );
95902 VdbeBranchTaken( (typeMask & pOp->p5)!=0, 2);
95910 ** Synopsis: r[P2] = 0 OR NULL
95917 if( (aMem[pOp->p1].flags & MEM_Null)!=0
95918 || (aMem[pOp->p3].flags & MEM_Null)!=0
95922 sqlite3VdbeMemSetInt64(aMem + pOp->p2, 0);
95934 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
95935 if( (pIn1->flags & MEM_Null)==0 ){
95953 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
95980 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
95983 if( pC==0 || pC->eCurType!=CURTYPE_BTREE ){
96038 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
96039 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
96044 assert( pC!=0 );
96046 || (pC->eCurType==CURTYPE_PSEUDO && pC->seekResult==0) );
96055 if( pC->eCurType==CURTYPE_PSEUDO && pC->seekResult>0 ){
96074 if( pC->ub.aAltMap && (iMap = pC->ub.aAltMap[1+p2])>0 ){
96095 if( (aOffset[0] = pC->aRow[0])<0x80 ){
96100 pC->nHdrParsed = 0;
96102 if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/
96107 pC->aRow = 0;
96108 pC->szRow = 0;
96119 if( aOffset[0] > 98307 || aOffset[0] > pC->payloadSize ){
96127 ** This branch is taken even if aOffset[0]==0. Such a record is never
96129 ** accept it for historical reasons. When aOffset[0]==0, the code this
96138 testcase( aOffset[0]==0 );
96154 if( pC->iHdrOffset<aOffset[0] ){
96156 if( pC->aRow==0 ){
96157 memset(&sMem, 0, sizeof(sMem));
96158 rc = sqlite3VdbeMemFromBtreeZeroOffset(pC->uc.pCursor,aOffset[0],&sMem);
96170 zEndHdr = zData + aOffset[0];
96173 if( (pC->aType[i] = t = zHdr[0])<0x80 ){
96181 aOffset[++i] = (u32)(offset64 & 0xffffffff);
96192 if( aOffset[0]==0 ){
96193 i = 0;
96196 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
96203 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
96205 t = 0;
96256 if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem;
96261 pDest->z[len] = 0;
96262 pDest->z[len+1] = 0;
96270 if( ((p5 = (pOp->p5 & OPFLAG_BYTELENARG))!=0
96272 || (t>=12 && ((t&1)==0 || p5==OPFLAG_BYTELENARG))
96275 || sqlite3VdbeSerialTypeLen(t)==0
96308 if( aOp[0].p3>0 ){
96309 pOp = &aOp[aOp[0].p3-1];
96354 for(i=0; i<pTab->nCol; i++){
96361 if( (pIn1->flags & MEM_Null)==0 ){
96364 if( (pIn1->flags & MEM_Blob)==0 ) goto vdbe_type_error;
96369 if( (pIn1->flags & MEM_Int)==0 ) goto vdbe_type_error;
96373 if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error;
96378 assert( (pIn1->flags & MEM_IntReal)==0 );
96396 }else if( (pIn1->flags & (MEM_Real|MEM_IntReal))==0 ){
96434 assert( zAffinity!=0 );
96435 assert( pOp->p2>0 );
96436 assert( zAffinity[pOp->p2]==0 );
96440 assert( zAffinity[0]==SQLITE_AFF_NONE || memIsValid(pIn1) );
96441 applyAffinity(pIn1, zAffinity[0], encoding);
96442 if( zAffinity[0]==SQLITE_AFF_REAL && (pIn1->flags & MEM_Int)!=0 ){
96462 if( zAffinity[0]==0 ) break;
96515 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
96518 ** Data(0) is taken from register P1. Data(1) comes from register P1+1
96526 nData = 0; /* Number of bytes of data space */
96527 nHdr = 0; /* Number of bytes of header space */
96528 nZero = 0; /* Number of zero bytes at the end of the record */
96531 assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem+1 - p->nCursor)+1 );
96547 applyAffinity(pRec, zAffinity[0], encoding);
96548 if( zAffinity[0]==SQLITE_AFF_REAL && (pRec->flags & MEM_Int) ){
96555 assert( zAffinity[0]==0 || pRec<=pLast );
96556 }while( zAffinity[0] );
96563 ** at least one field. If P5>0 then it will be one more than the
96566 while( (pLast->flags & MEM_Null)!=0 && nField>pOp->p5 ){
96580 ** 0 NULL
96588 ** 8 Integer constant 0
96615 pRec->uTemp = 0;
96624 if( i<0 ){
96674 assert( pRec->n>=0 );
96676 serial_type = (len*2) + 12 + ((pRec->flags & MEM_Str)!=0);
96741 if( nHdr<0x80 ){
96756 if( serial_type==0 ){
96770 default: zPayload[7] = (u8)(v&0xff); v >>= 8;
96771 zPayload[6] = (u8)(v&0xff); v >>= 8;
96773 case 6: zPayload[5] = (u8)(v&0xff); v >>= 8;
96774 zPayload[4] = (u8)(v&0xff); v >>= 8;
96776 case 4: zPayload[3] = (u8)(v&0xff); v >>= 8;
96778 case 3: zPayload[2] = (u8)(v&0xff); v >>= 8;
96780 case 2: zPayload[1] = (u8)(v&0xff); v >>= 8;
96782 case 1: zPayload[0] = (u8)(v&0xff);
96786 }else if( serial_type<0x80 ){
96788 if( serial_type>=14 && pRec->n>0 ){
96789 assert( pRec->z!=0 );
96796 assert( pRec->z!=0 );
96807 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
96818 ** If P3==0, then an exact count is obtained, which involves visiting
96832 nEntry = 0; /* Not needed. Only used to silence a warning. */
96844 ** on the value of P1. To open a new savepoint set P1==0 (SAVEPOINT_BEGIN).
96864 assert( db->pSavepoint==0 || db->autoCommit==0 );
96866 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
96871 if( db->nVdbeWrite>0 ){
96885 assert( db->autoCommit==0 || db->nVTrans==0 );
96900 db->autoCommit = 0;
96915 iSavepoint = 0;
96929 }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){
96942 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
96950 db->autoCommit = 0;
96956 db->autoCommit = 0;
96958 db->isTransactionSavepoint = 0;
96964 isSchemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0;
96965 for(ii=0; ii<db->nDb; ii++){
96968 isSchemaChange==0);
96973 isSchemaChange = 0;
96975 for(ii=0; ii<db->nDb; ii++){
96982 sqlite3ExpirePreparedStatements(db, 0);
97031 ** Set the database auto-commit flag to P1 (1 or 0). If P2 is true, roll
97044 assert( desiredAutoCommit==1 || desiredAutoCommit==0 );
97045 assert( desiredAutoCommit==1 || iRollback==0 );
97046 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
97054 }else if( desiredAutoCommit && db->nVdbeWrite>0 ){
97089 /*NOTREACHED*/ assert(0);
97102 ** started. Index 0 is the main database file and index 1 is the
97116 ** If P5!=0 then this opcode also checks the schema cookie against P3
97130 int iMeta = 0;
97133 assert( p->readOnly==0 || pOp->p2==0 );
97134 assert( pOp->p2>=0 && pOp->p2<=2 );
97135 assert( pOp->p1>=0 && pOp->p1<db->nDb );
97138 if( pOp->p2 && (db->flags & (SQLITE_QueryOnly|SQLITE_CorruptRdOnly))!=0 ){
97157 if( (rc&0xff)==SQLITE_BUSY ){
97167 && (db->autoCommit==0 || db->nVdbeRead>1)
97170 if( p->iStatement==0 ){
97171 assert( db->nStatement>=0 && db->nSavepoint>=0 );
97188 assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
97219 /* Set changeCntOn to 0 to prevent the value returned by sqlite3_changes()
97222 p->changeCntOn = 0;
97232 ** P3==3 is the recommended pager cache size, and so forth. P1==0 is
97249 assert( iDb>=0 && iDb<db->nDb );
97250 assert( db->aDb[iDb].pBt!=0 );
97264 ** size, and so forth. P1==0 is the main database file and P1==1 is the
97277 sqlite3VdbeIncrWriteCounter(p, 0);
97279 assert( pOp->p1>=0 && pOp->p1<db->nDb );
97281 assert( p->readOnly==0 );
97283 assert( pDb->pBt!=0 );
97284 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
97299 sqlite3ExpirePreparedStatements(db, 0);
97300 p->expired = 0;
97311 ** P3==0 means the main database, P3==1 means the database used for
97319 ** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
97342 ** The ReopenIdx opcode may only be used with P5==0 or P5==OPFLAG_SEEKEQ
97349 ** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
97373 ** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
97376 ** <li> <b>0x08 OPFLAG_FORDELETE</b>: This cursor is used only to seek
97381 ** <li> <b>0x10 OPFLAG_P2ISREG</b>: Use the content of register P2
97400 assert( pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
97414 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
97417 || p->readOnly==0 );
97424 nField = 0;
97425 pKeyInfo = 0;
97428 assert( iDb>=0 && iDb<db->nDb );
97432 assert( pX!=0 );
97436 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
97441 wrFlag = 0;
97444 assert( p2>0 );
97449 assert( (pIn2->flags & MEM_Int)!=0 );
97466 assert( pOp->p1>=0 );
97467 assert( nField>=0 );
97468 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
97470 if( pCur==0 ) goto no_mem;
97514 if( pCx==0 ) goto no_mem;
97546 ** The cursor points to a BTree table if P4==0 and to a BTree index
97547 ** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
97578 assert( pOp->p1>=0 );
97579 assert( pOp->p2>=0 );
97580 if( pOp->p3>0 ){
97583 assert( pOp->p2==0 ); /* Only used when number of columns is zero */
97586 aMem[pOp->p3].n = 0;
97595 pCx->seqCount = 0;
97597 rc = sqlite3BtreeClearTable(pCx->ub.pBtx, pCx->pgnoRoot, 0);
97600 if( pCx==0 ) goto no_mem;
97602 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->ub.pBtx,
97606 rc = sqlite3BtreeBeginTrans(pCx->ub.pBtx, 1, 0);
97613 if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
97624 pCx->isTable = 0;
97628 0, pCx->uc.pCursor);
97656 assert( pOp->p1>=0 );
97657 assert( pOp->p2>=0 );
97659 if( pCx==0 ) goto no_mem;
97677 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
97680 if( (pC->seqCount++)==0 ){
97700 ** the pseudo-table. If P2 is 0 or negative then the pseudo-cursor
97706 assert( pOp->p1>=0 );
97707 assert( pOp->p3>=0 );
97709 if( pCx==0 ) goto no_mem;
97718 assert( pOp->p5==0 );
97728 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
97730 p->apCsr[pOp->p1] = 0;
97856 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
97857 assert( pOp->p2!=0 );
97859 assert( pC!=0 );
97865 assert( pC->uc.pCursor!=0 );
97867 eqOnly = 0;
97868 pC->nullRow = 0;
97873 pC->deferredMoveto = 0;
97878 assert( sqlite3BtreeCursorHasHint(pC->uc.pCursor, BTREE_SEEK_EQ)==0
97887 applyNumericAffinity(pIn3, 0);
97895 if( (newType & (MEM_Int|MEM_IntReal))==0 ){
97897 if( (newType & MEM_Real)==0 ){
97916 if( c>0 ){
97919 assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) );
97920 if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--;
97925 else if( c<0 ){
97928 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
97929 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
97932 rc = sqlite3BtreeTableMoveto(pC->uc.pCursor, (u64)iKey, 0, &res);
97949 assert( pOp[1].p1==pOp[0].p1 );
97950 assert( pOp[1].p2==pOp[0].p2 );
97951 assert( pOp[1].p3==pOp[0].p3 );
97952 assert( pOp[1].p4.i==pOp[0].p4.i );
97957 assert( nField>0 );
97978 for(i=0; i<r.nField; i++){
97980 if( i>0 ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
97984 r.eqSeen = 0;
97989 if( eqOnly && r.eqSeen==0 ){
97990 assert( res!=0 );
97998 if( res<0 || (res==0 && oc==OP_SeekGT) ){
97999 res = 0;
98000 rc = sqlite3BtreeNext(pC->uc.pCursor, 0);
98010 res = 0;
98014 if( res>0 || (res==0 && oc==OP_SeekLT) ){
98015 res = 0;
98016 rc = sqlite3BtreePrevious(pC->uc.pCursor, 0);
98033 assert( pOp->p2>0 );
98034 VdbeBranchTaken(res!=0,2);
98080 ** row. If This.P5 is false (0) then a jump is made to SeekGE.P2. If
98081 ** This.P5 is true (non-zero) then a jump is made to This.P2. The P5==0
98083 ** the IN constraint. The jump to SeekGE.P2 ends the loop. The P5!=0 case
98110 ** jump to SeekOP.P2 if This.P5==0 or to This.P2 if This.P5>0.
98126 if( pOp->p5==0 ){
98141 assert( pOp->p1>0 );
98143 assert( pC!=0 );
98158 r.default_rc = 0;
98163 for(i=0; i<r.nField; i++){
98169 res = 0; /* Not needed. Only used to silence a warning. */
98173 if( res>0 && pOp->p5==0 ){
98185 if( res>=0 ){
98196 if( nStep<=0 ){
98202 VdbeBranchTaken(0,3);
98207 rc = sqlite3BtreeNext(pC->uc.pCursor, 0);
98238 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98240 assert( pC!=0 );
98269 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98271 VdbeBranchTaken(pCur==0 || pCur->nullRow, 2);
98272 if( pCur==0 || pCur->nullRow ){
98281 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
98282 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
98298 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
98299 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
98348 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
98349 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
98370 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98372 assert( pC!=0 );
98395 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98398 assert( pC!=0 );
98404 assert( pC->uc.pCursor!=0 );
98405 assert( pC->isTable==0 );
98407 if( r.nField>0 ){
98410 r.default_rc = 0;
98412 for(ii=0; ii<r.nField; ii++){
98414 assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
98427 if( pIdxKey==0 ) goto no_mem;
98429 pIdxKey->default_rc = 0;
98436 alreadyExists = (pC->seekResult==0);
98438 pC->deferredMoveto = 0;
98441 VdbeBranchTaken(alreadyExists!=0,2);
98452 for(ii=0; ii<r.nField; ii++){
98459 VdbeBranchTaken(0,2);
98473 ** Or, if P2 is 0, raise an SQLITE_CORRUPT error. If P1 does contain
98496 ** rowid P3 then jump immediately to P2. Or, if P2 is 0, raise an
98525 if( (pIn3->flags & (MEM_Int|MEM_IntReal))==0 ){
98531 Mem x = pIn3[0];
98533 if( (x.flags & MEM_Int)==0 ) goto jump_to_p2;
98541 assert( (pIn3->flags & MEM_Int)!=0 || pOp->opcode==OP_SeekRowid );
98542 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98546 assert( pC!=0 );
98553 assert( pCrsr!=0 );
98554 res = 0;
98555 rc = sqlite3BtreeTableMoveto(pCrsr, iKey, 0, &res);
98556 assert( rc==SQLITE_OK || res==0 );
98558 pC->nullRow = 0;
98560 pC->deferredMoveto = 0;
98561 VdbeBranchTaken(res!=0,2);
98563 if( res!=0 ){
98565 if( pOp->p2==0 ){
98584 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98585 assert( p->apCsr[pOp->p1]!=0 );
98601 ** If P3>0 then P3 is a register in the root frame of this VDBE that holds
98618 v = 0;
98619 res = 0;
98621 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98623 assert( pC!=0 );
98626 assert( pC->uc.pCursor!=0 );
98644 # define MAX_ROWID 0x7fffffff
98646 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
98647 ** Others complain about 0x7ffffffffffffffffLL. The following macro seems
98650 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
98674 assert( pOp->p3>0 );
98690 assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
98706 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
98708 cnt = 0;
98713 0, &res))==SQLITE_OK)
98714 && (res==0)
98717 if( res==0 ){
98721 assert( v>0 ); /* EV: R-40812-03570 */
98723 pC->deferredMoveto = 0;
98771 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
98777 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98780 assert( pC!=0 );
98782 assert( pC->deferredMoveto==0 );
98783 assert( pC->uc.pCursor!=0 );
98796 assert( pC->iDb>=0 );
98801 pTab = 0;
98802 zDb = 0;
98811 if( db->xUpdateCallback==0 || pTab->aCol==0 ){
98813 pTab = 0;
98819 assert( (pOp->p5 & OPFLAG_LASTROWID)==0 || (pOp->p5 & OPFLAG_NCHANGE)!=0 );
98824 assert( (pData->flags & (MEM_Blob|MEM_Str))!=0 || pData->n==0 );
98827 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
98831 x.nZero = 0;
98833 x.pKey = 0;
98839 pC->deferredMoveto = 0;
98846 assert( db->xUpdateCallback!=0 );
98847 assert( pTab->aCol!=0 );
98871 assert( pOp[1].opcode==OP_Insert || pOp->p3==0 );
98872 assert( pOp[1].opcode==OP_IdxInsert || pOp->p3>0 );
98876 iKey = pOp->p3 ? aMem[pOp->p3].u.i : 0;
98900 ** If the OPFLAG_NCHANGE (0x01) flag of P2 (NB: P2 not P5) is set, then
98903 ** If the OPFLAG_ISNOOP (0x40) flag of P2 (not P5!) is set, then the
98929 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98931 assert( pC!=0 );
98933 assert( pC->uc.pCursor!=0 );
98934 assert( pC->deferredMoveto==0 );
98940 && pOp->p5==0
98957 assert( pC->iDb>=0 );
98958 assert( pOp->p4.pTab!=0 );
98961 if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){
98965 zDb = 0;
98966 pTab = 0;
98971 assert( db->xPreUpdateCallback==0 || pTab==pOp->p4.pTab );
98974 || HasRowid(pTab)==0
98987 assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_AUXDELETE))==0 );
98992 if( p->pFrame==0 ){
98993 if( pC->isEphemeral==0
98994 && (pOp->p5 & OPFLAG_AUXDELETE)==0
98995 && (pC->wrFlag & OPFLAG_FORDELETE)==0
99008 pC->seekResult = 0;
99014 if( db->xUpdateCallback && ALWAYS(pTab!=0) && HasRowid(pTab) ){
99017 assert( pC->iDb>=0 );
99027 ** Then the VMs internal change counter resets to 0.
99032 p->nChange = 0;
99061 res = 0;
99063 VdbeBranchTaken(res!=0,2);
99089 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99110 ** If P3!=0 then this opcode is allowed to make an ephemeral pointer
99114 ** position in order that they can write to the same table. If P3==0
99115 ** then a copy of the data is made into memory. P3!=0 is faster, but
99116 ** P3==0 is safer.
99118 ** If P3!=0 then the content of the P2 register is unsuitable for use
99130 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99132 assert( pC!=0 );
99134 assert( isSorter(pC)==0 );
99135 assert( pC->nullRow==0 );
99136 assert( pC->uc.pCursor!=0 );
99147 assert( pC->deferredMoveto==0 );
99154 testcase( n==0 );
99180 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99182 assert( pC!=0 );
99191 assert( pC->uc.pVCur!=0 );
99201 assert( pC->uc.pCursor!=0 );
99226 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99228 if( pC==0 ){
99232 if( pC==0 ) goto no_mem;
99233 pC->seekResult = 0;
99241 assert( pC->uc.pCursor!=0 );
99245 if( pC->seekOp==0 ) pC->seekOp = OP_NullRow;
99264 ** If the table or index is empty and P2>0, then jump immediately to P2.
99265 ** If P2 is 0 or if the table or index is not empty, fall through
99278 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99280 assert( pC!=0 );
99283 res = 0;
99284 assert( pCrsr!=0 );
99289 assert( pOp->p2==0 );
99297 pC->deferredMoveto = 0;
99300 if( pOp->p2>0 ){
99301 VdbeBranchTaken(res!=0,2);
99321 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99326 assert( pC!=0 );
99331 if( res!=0 ){
99335 assert( sz>0 );
99339 VdbeBranchTaken(res!=0,2);
99396 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99397 assert( pOp->p5==0 );
99398 assert( pOp->p2>=0 && pOp->p2<p->nOp );
99401 assert( pC!=0 );
99414 pC->deferredMoveto = 0;
99419 if( pOp->p2>0 ){
99420 VdbeBranchTaken(res!=0,2);
99442 ** omitted if that index had been unique. P3 is usually 0. P3 is
99443 ** always either 0 or 1.
99467 ** omitted if that index had been unique. P3 is usually 0. P3 is
99468 ** always either 0 or 1.
99489 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99490 assert( pOp->p5==0
99494 assert( pC!=0 );
99495 assert( pC->deferredMoveto==0 );
99504 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99505 assert( pOp->p5==0
99509 assert( pC!=0 );
99510 assert( pC->deferredMoveto==0 );
99522 pC->nullRow = 0;
99567 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99570 assert( pC!=0 );
99576 assert( pC->isTable==0 );
99585 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
99587 assert( pC->deferredMoveto==0 );
99603 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99606 assert( pC!=0 );
99610 assert( pC->isTable==0 );
99639 assert( pOp->p3>0 );
99640 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem+1 - p->nCursor)+1 );
99641 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99643 assert( pC!=0 );
99647 assert( pCrsr!=0 );
99650 r.default_rc = 0;
99654 if( res==0 ){
99661 assert( pC->deferredMoveto==0 );
99663 pC->seekResult = 0;
99701 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99703 assert( pC!=0 );
99705 assert( pC->uc.pCursor!=0 );
99706 assert( pC->isTable==0 || IsNullCursor(pC) );
99707 assert( pC->deferredMoveto==0 );
99720 rowid = 0; /* Not needed. Only used to silence a warning. */
99726 assert( pOp->p3>=0 && pOp->p3<p->nCursor );
99728 assert( pTabCur!=0 );
99730 assert( pTabCur->uc.pCursor!=0 );
99732 pTabCur->nullRow = 0;
99736 assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 );
99761 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99822 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99824 assert( pC!=0 );
99827 assert( pC->uc.pCursor!=0);
99828 assert( pC->deferredMoveto==0 );
99837 r.default_rc = 0;
99843 for(i=0; i<r.nField; i++){
99852 i64 nCellKey = 0;
99860 /* nCellKey will always be between 0 and 0xffffffff because of the way
99862 if( nCellKey<=0 || nCellKey>0x7fffffff ){
99866 sqlite3VdbeMemInit(&m, db, 0);
99869 res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, &r, 0);
99882 VdbeBranchTaken(res>0,2);
99884 if( res>0 ) goto jump_to_p2;
99893 ** The table being destroyed is in the main database file if P3==0. If
99919 sqlite3VdbeIncrWriteCounter(p, 0);
99920 assert( p->readOnly==0 );
99931 iMoved = 0; /* Not needed. Only to silence a warning. */
99937 if( iMoved!=0 ){
99940 assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 );
99954 ** The table being cleared is in the main database file if P2==0. If
99968 sqlite3VdbeIncrWriteCounter(p, 0);
99969 nChange = 0;
99970 assert( p->readOnly==0 );
99975 if( pOp->p3>0 ){
99996 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99998 assert( pC!=0 );
100013 ** Allocate a new b-tree in the main database file if P1==0 or in the
100023 sqlite3VdbeIncrWriteCounter(p, 0);
100025 pgno = 0;
100027 assert( pOp->p1>=0 && pOp->p1<db->nDb );
100029 assert( p->readOnly==0 );
100031 assert( pDb->pBt!=0 );
100044 ** 0x0001 Disable Auth and Trace callbacks while the statements
100047 ** 0x0002 Set db->nAnalysisLimit to P2 while the statements in
100059 sqlite3VdbeIncrWriteCounter(p, 0);
100061 zErr = 0;
100067 if( pOp->p1 & 0x0001 ){
100069 db->xAuth = 0;
100071 db->mTrace = 0;
100073 if( pOp->p1 & 0x0002 ){
100076 rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
100112 for(iDb=0; iDb<db->nDb; iDb++){
100118 assert( iDb>=0 && iDb<db->nDb );
100121 || (CORRUPT_DB && (db->flags & SQLITE_NoSchemaError)!=0) );
100124 if( pOp->p4.z==0 ){
100129 p->expired = 0;
100137 initData.mInitFlags = 0;
100142 if( zSql==0 ){
100145 assert( db->init.busy==0 );
100148 initData.nInitRow = 0;
100150 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
100152 if( rc==SQLITE_OK && initData.nInitRow==0 ){
100159 db->init.busy = 0;
100180 assert( pOp->p1>=0 && pOp->p1<db->nDb );
100196 sqlite3VdbeIncrWriteCounter(p, 0);
100210 sqlite3VdbeIncrWriteCounter(p, 0);
100224 sqlite3VdbeIncrWriteCounter(p, 0);
100261 assert( nRoot>0 );
100262 assert( aRoot!=0 );
100263 assert( aRoot[0]==(Pgno)nRoot );
100264 assert( pOp->p1>0 && (pOp->p1+1)<=(p->nMem+1 - p->nCursor) );
100266 assert( (pnErr->flags & MEM_Int)!=0 );
100267 assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
100274 if( nErr==0 ){
100275 assert( z==0 );
100300 assert( (pIn2->flags & MEM_Int)!=0 );
100301 if( (pIn1->flags & MEM_Blob)==0 ){
100321 assert( (pIn1->flags & MEM_Blob)==0 || sqlite3VdbeMemIsRowSet(pIn1) );
100322 if( (pIn1->flags & MEM_Blob)==0
100323 || sqlite3RowSetNext((RowSet*)pIn1->z, &val)==0
100331 VdbeBranchTaken(0,2);
100349 ** must have P4==0, the final set must have P4==-1, and for all other sets
100350 ** must have P4>0.
100352 ** This allows optimizations: (a) when P4==0 there is no need to test
100372 if( (pIn1->flags & MEM_Blob)==0 ){
100377 assert( iSet==-1 || iSet>=0 );
100380 VdbeBranchTaken(exists!=0,2);
100383 if( iSet>=0 ){
100421 assert( pProgram->nOp>0 );
100450 if( (pRt->flags&MEM_Blob)==0 ){
100457 assert( nMem>0 );
100458 if( pProgram->nCsr==0 ) nMem++;
100497 || (pProgram->nCsr==0 && pProgram->nMem+1==pFrame->nChildMem) );
100507 assert( pFrame->pAuxData==0 );
100509 p->pAuxData = 0;
100510 p->nChange = 0;
100517 memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
100525 for(i=0; i<p->nMem; i++){
100526 aMem[i].pScopyFrom = 0; /* Prevent false-positive AboutToChange() errs */
100580 ** Synopsis: if fkctr[P1]==0 goto P2
100593 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
100594 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
100596 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
100597 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
100635 ** Synopsis: if r[P1]>0 then r[P1]-=P3, goto P2
100647 VdbeBranchTaken( pIn1->u.i>0, 2);
100648 if( pIn1->u.i>0 ){
100656 ** Synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)
100681 if( x<=0 || sqlite3AddInt64(&x, pIn3->u.i>0?pIn3->u.i:0) ){
100697 ** Synopsis: if r[P1]!=0 then r[P1]--, goto P2
100707 VdbeBranchTaken(pIn1->u.i<0, 2);
100709 if( pIn1->u.i>0 ) pIn1->u.i--;
100716 ** Synopsis: if (--r[P1])==0 goto P2
100725 VdbeBranchTaken(pIn1->u.i==0, 2);
100726 if( pIn1->u.i==0 ) goto jump_to_p2;
100756 ** Execute the xStep (if P1==0) or xInverse (if P1!=0) function for an
100777 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
100778 assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) );
100781 (sizeof(pCtx[0]) + sizeof(Mem) - sizeof(sqlite3_value*)));
100782 if( pCtx==0 ) goto no_mem;
100783 pCtx->pMem = 0;
100789 pCtx->skipFlag = 0;
100790 pCtx->isError = 0;
100796 /* OP_AggInverse must have P1==1 and OP_AggStep must have P1==0 */
100816 assert( pMem->uTemp==0x1122e0e3 );
100819 pMem->uTemp = 0x1122e0e3;
100829 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
100833 for(i=0; i<pCtx->argc; i++){
100841 assert( pCtx->isError==0 );
100842 assert( pCtx->skipFlag==0 );
100851 if( pCtx->isError>0 ){
100859 pCtx->skipFlag = 0;
100863 pCtx->isError = 0;
100867 assert( pCtx->skipFlag==0 );
100900 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
100901 assert( pOp->p3==0 || pOp->opcode==OP_AggValue );
100903 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
100930 ** RESTART, or TRUNCATE. Write 1 or 0 into mem[P3] if the checkpoint returns
100942 assert( p->readOnly==0 );
100943 aRes[0] = 0;
100954 aRes[0] = 1;
100956 for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){
100994 assert( pOp->p1>=0 && pOp->p1<db->nDb );
100995 assert( p->readOnly==0 );
101011 && (sqlite3Strlen30(zFilename)==0 /* Temp file */
101072 ** Vacuum the entire database P1. P1 is 0 for "main", and 2 or more
101080 assert( p->readOnly==0 );
101082 pOp->p2 ? &aMem[pOp->p2] : 0);
101098 assert( pOp->p1>=0 && pOp->p1<db->nDb );
101100 assert( p->readOnly==0 );
101120 ** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
101123 ** If P2 is 0, then SQL statements are expired immediately. If P2 is 1,
101130 assert( pOp->p2==0 || pOp->p2==1 );
101146 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
101148 assert( pC!=0 );
101161 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
101163 assert( pC!=0 );
101177 ** on which the lock is acquired. A readlock is obtained if P3==0 or
101187 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommit) ){
101189 assert( p1>=0 && p1<db->nDb );
101191 assert( isWriteLock==0 || isWriteLock==1 );
101194 if( (rc&0xFF)==SQLITE_LOCKED ){
101235 memset(&sMem, 0, sizeof(sMem));
101239 assert( (aMem[pOp->p2].flags & MEM_Str)!=0 );
101240 assert( (aMem[pOp->p2].flags & MEM_Static)!=0 );
101284 pCur = 0;
101285 pVCur = 0;
101287 if( pVtab==0 || NEVER(pVtab->pModule==0) ){
101300 pCur = allocateCursor(p, pOp->p1, 0, CURTYPE_VTAB);
101327 char *zErr = 0;
101333 assert( pTab!=0 );
101334 assert( pTab->nTabRef>0 );
101336 if( pTab->u.vtab.p==0 ) break;
101338 assert( pVtab!=0 );
101340 assert( pModule!=0 );
101342 assert( pModule->xIntegrity!=0 );
101344 assert( pOp->p1>=0 && pOp->p1<db->nDb );
101376 if( pRhs==0 ) goto no_mem;
101403 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
101425 assert( pCur!=0 );
101432 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
101438 for(i = 0; i<nArg; i++){
101445 pCur->nullRow = 0;
101446 VdbeBranchTaken(res!=0,2);
101475 assert( pCur!=0 );
101476 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
101487 memset(&sContext, 0, sizeof(sContext));
101490 nullFunc.pUserData = 0;
101493 assert( pOp->p5==OPFLAG_NOCHNG || pOp->p5==0 );
101497 pDest->u.nZero = 0;
101503 if( sContext.isError>0 ){
101530 assert( pCur!=0 );
101576 assert( p->readOnly==0 );
101585 if( isLegacy==0 ) db->flags &= ~(u64)SQLITE_LegacyAlter;
101587 p->expired = 0;
101604 ** The argv[0] element (which corresponds to memory cell P3)
101605 ** is the rowid of a row to delete. If argv[0] is NULL then no
101611 ** If P2==1 then no insert is performed. argv[0] is the rowid of
101626 sqlite_int64 rowid = 0;
101633 assert( p->readOnly==0 );
101635 sqlite3VdbeIncrWriteCounter(p, 0);
101637 if( pVtab==0 || NEVER(pVtab->pModule==0) ){
101648 for(i=0; i<nArg; i++){
101659 assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
101662 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
101695 ** do not change the maximum page count value if P3==0.
101705 newMax = 0;
101727 ** argument was constant then bit 0 of P1 is set. This is used to determine
101746 ** argument was constant then bit 0 of P1 is set. This is used to determine
101778 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
101784 for(i=0; i<pCtx->argc; i++){
101790 assert( pCtx->isError==0 );
101795 if( pCtx->isError>0 ){
101800 pCtx->isError = 0;
101804 assert( (pOut->flags&MEM_Str)==0
101815 ** Synopsis: r[P1].subtype = 0
101856 pOut->eSubtype = (u8)(pIn1->u.i & 0xff);
101870 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
101873 assert( pIn1->n>0 );
101906 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
101908 assert( (pIn1->flags & MEM_Blob)!=0 );
101921 if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){
101927 VdbeBranchTaken(0, 2);
101937 ** Operand P1 must be 0x7fffffff and P2 must positive.
101973 assert( pOp->p4.z==0 || strncmp(pOp->p4.z, "-" "- ", 3)==0 );
101975 /* OP_Init is always instruction 0 */
101979 if( (db->mTrace & (SQLITE_TRACE_STMT|SQLITE_TRACE_LEGACY))!=0
101981 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
102002 for(j=0; j<db->nDb; j++){
102003 if( DbMaskTest(p->btreeMask, j)==0 ) continue;
102009 if( (db->flags & SQLITE_SqlTrace)!=0
102010 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
102016 assert( pOp->p2>0 );
102020 if( p->aOp[i].opcode==OP_Once ) p->aOp[i].p1 = 0;
102022 pOp->p1 = 0;
102040 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
102103 assert( pOp->p1>0 );
102107 for(i=0; i<pOp->p2; i++, pMem++){
102108 if( i>=32 || (constMask & MASKBIT32(i))==0 ){
102109 pMem->pScopyFrom = 0;
102144 pnCycle = 0;
102148 pnCycle = 0;
102163 if( rc!=0 ) printf("rc=%d\n",rc);
102170 if( opProperty==0xff ){
102194 if( zTrace==0 ){
102195 if( aOp[0].opcode==OP_Trace ){
102196 zTrace = aOp[0].p4.z;
102198 if( zTrace==0 ) zTrace = "???";
102203 if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){
102208 testcase( sqlite3GlobalConfig.xLog!=0 );
102213 if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){
102217 if( resetSchemaOnFault>0 ){
102228 pnCycle = 0;
102233 pnCycle = 0;
102238 while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
102251 assert( rc!=SQLITE_OK || nExtraDelete==0
102252 || sqlite3_strlike("DELETE%",p->zSql,0)!=0
102339 char *zErr = 0; /* Error message */
102359 VdbeCursor *pC = v->apCsr[0];
102361 assert( pC!=0 );
102363 type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0;
102368 type==0?"null": type==7?"real": "integer"
102372 p->pStmt = 0;
102385 p->pStmt = 0;
102394 assert( rc!=SQLITE_OK || zErr==0 );
102413 int nAttempt = 0;
102416 char *zErr = 0;
102418 Incrblob *pBlob = 0;
102422 if( ppBlob==0 ){
102426 *ppBlob = 0;
102428 if( !sqlite3SafetyCheckOk(db) || zTable==0 || zColumn==0 ){
102432 wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
102441 zErr = 0;
102444 pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
102446 pTab = 0;
102450 pTab = 0;
102455 pTab = 0;
102463 sParse.zErrMsg = 0;
102473 for(iCol=0; iCol<pTab->nCol; iCol++) {
102474 if( sqlite3StrICmp(pTab->aCol[iCol].zCnName, zColumn)==0 ){
102490 const char *zFault = 0;
102502 for(j=0; j<pFKey->nCol; j++){
102512 for(j=0; j<pIdx->nKeyCol; j++){
102549 {OP_TableLock, 0, 0, 0}, /* 0: Acquire a read or write lock */
102550 {OP_OpenRead, 0, 0, 0}, /* 1: Open a cursor */
102552 {OP_NotExists, 0, 5, 1}, /* 2: Seek the cursor to rowid=r[1] */
102553 {OP_Column, 0, 0, 1}, /* 3 */
102554 {OP_ResultRow, 1, 0, 0}, /* 4 */
102555 {OP_Halt, 0, 0, 0}, /* 5 */
102571 if( db->mallocFailed==0 ){
102572 assert( aOp!=0 );
102575 aOp[0].opcode = OP_Noop;
102577 aOp[0].p1 = iDb;
102578 aOp[0].p2 = pTab->tnum;
102579 aOp[0].p3 = wrFlag;
102582 if( db->mallocFailed==0 ){
102602 sParse.nVar = 0;
102621 if( rc==SQLITE_OK && db->mallocFailed==0 ){
102627 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : (char*)0), zErr);
102672 if( p==0 ) return SQLITE_MISUSE_BKPT;
102677 if( n<0 || iOffset<0 || ((sqlite3_int64)iOffset+n)>p->nByte ){
102680 }else if( v==0 ){
102709 assert( v->apCsr[0]!=0 );
102710 assert( v->apCsr[0]->eCurType==CURTYPE_BTREE );
102712 v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1, p->iCol
102721 p->pStmt = 0;
102754 return (p && p->pStmt) ? p->nByte : 0;
102772 if( p==0 ) return SQLITE_MISUSE_BKPT;
102776 if( p->pStmt==0 ){
102786 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : (char*)0), zErr);
102793 assert( rc==SQLITE_OK || p->pStmt==0 );
102882 ** A PMA created at this point is known as a "level-0 PMA". Higher levels
102884 ** merging two or more level-0 PMAs together creates a level-1 PMA.
102904 ** "PRAGMA threads=N" with some value of N greater than 0.
102947 #if 0
102953 ** to a level 0 PMA. The purpose of this limit is to prevent various integer
102982 ** If aMemory==0 then each object is allocated separately and the objects
102983 ** are connected using SorterRecord.u.pNext. If aMemory!=0 then all objects
103022 ** currently points to the smallest key value. aTree[0] is unused.
103026 ** aReadr[0] -> Banana
103035 ** aTree[] = { X, 5 0, 5 0, 3, 5, 6 }
103048 ** 5, so aTree[3] is set to 6. Key 0 is smaller than key 6 (Banana<Durian),
103049 ** so the value written into element 1 of the array is 0. As follows:
103051 ** aTree[] = { X, 0 0, 6 0, 3, 5, 6 }
103078 ** Before a background thread is launched, variable bDone is set to 0. Then,
103082 ** 1. When flushing the contents of memory to a level-0 PMA on disk, to
103091 ** In both cases, the effects of the main thread seeing (bDone==0) even
103104 SorterFile file; /* Temp file for level-0 PMAs */
103120 int mxPmaSize; /* Maximum PMA size, in bytes. 0==no limit */
103124 MergeEngine *pMerger; /* Or here, if bUseThreads==0 */
103139 #define SORTER_TYPE_INTEGER 0x01
103140 #define SORTER_TYPE_TEXT 0x02
103149 ** pFd==0 at EOF.
103171 ** There are two types of IncrMerger object - single (bUseThread==0) and
103174 ** A multi-threaded IncrMerger object uses two temporary files - aFile[0]
103177 ** pMerger to populate aFile[0]. It then sets variables within the
103182 ** When the PmaReader reaches the end of aFile[0], it blocks until the
103184 ** the contents of the aFile[0] and aFile[1] variables within this structure,
103185 ** sets the PmaReader fields to read from the new aFile[0] and kicks off
103204 SorterFile aFile[2]; /* aFile[0] for reading, [1] for writing */
103231 ** (VdbeSorter.list.aMemory==0), then the list is always connected using the
103234 ** Or, if using the single large allocation method (VdbeSorter.list.aMemory!=0),
103273 if( pReadr->aMap ) sqlite3OsUnfetch(pReadr->pFd, 0, pReadr->aMap);
103275 memset(pReadr, 0, sizeof(PmaReader));
103307 if( iBuf==0 ){
103317 assert( nRead>0 );
103357 while( nRem>0 ){
103392 int i = 0, rc;
103396 aVarint[(i++)&0xf] = a[0];
103397 }while( (a[0]&0x80)!=0 );
103419 rc = sqlite3OsFetch(pFd, 0, (int)pFile->iEof, (void**)pp);
103439 assert( pReadr->pIncr==0 || pReadr->pIncr->bEof==0 );
103443 sqlite3OsUnfetch(pReadr->pFd, 0, pReadr->aMap);
103444 pReadr->aMap = 0;
103451 if( rc==SQLITE_OK && pReadr->aMap==0 ){
103454 if( pReadr->aBuffer==0 ){
103456 if( pReadr->aBuffer==0 ) rc = SQLITE_NOMEM_BKPT;
103480 u64 nRec = 0; /* Size of record in bytes */
103488 if( rc==SQLITE_OK && pIncr->bEof==0 ){
103490 pIncr->pTask, pReadr, &pIncr->aFile[0], pIncr->iStartOff
103492 bEof = 0;
103535 assert( pReadr->aAlloc==0 && pReadr->nAlloc==0 );
103536 assert( pReadr->aBuffer==0 );
103537 assert( pReadr->aMap==0 );
103541 u64 nByte = 0; /* Size of PMA in bytes */
103565 if( *pbKey2Cached==0 ){
103612 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
103613 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
103622 if( res==0 ){
103626 if( res==0 ){
103633 assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
103634 if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
103656 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
103657 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
103660 assert( (s1>0 && s1<7) || s1==8 || s1==9 );
103661 assert( (s2>0 && s2<7) || s2==8 || s2==9 );
103665 static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8, 0, 0, 0 };
103668 res = 0;
103669 for(i=0; i<n; i++){
103670 if( (res = v1[i] - v2[i])!=0 ){
103671 if( ((v1[0] ^ v2[0]) & 0x80)!=0 ){
103672 res = v1[0] & 0x80 ? -1 : +1;
103687 assert( res!=0 );
103689 if( res>0 ){
103690 if( *v1 & 0x80 ) res = -1;
103692 if( *v2 & 0x80 ) res = +1;
103696 if( res==0 ){
103702 }else if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
103703 assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
103737 KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
103741 #if SQLITE_MAX_WORKER_THREADS==0
103742 # define nWorker 0
103748 #if SQLITE_MAX_WORKER_THREADS>0
103749 if( sqlite3TempInMemory(db) || sqlite3GlobalConfig.bCoreMutex==0 ){
103750 nWorker = 0;
103772 if( pSorter==0 ){
103775 Btree *pBt = db->aDb[0].pBt;
103778 pKeyInfo->db = 0;
103779 if( nField && nWorker==0 ){
103789 for(i=0; i<pSorter->nTask; i++){
103799 mxCache = db->aDb[0].pSchema->cache_size;
103800 if( mxCache<0 ){
103812 if( sqlite3GlobalConfig.bSmallMalloc==0 ){
103813 assert( pSorter->iMemory==0 );
103821 && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
103822 && (pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL)==0
103850 #if SQLITE_MAX_WORKER_THREADS>0
103852 ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
103858 assert( pTask->list.aMemory==0 );
103859 vdbeSorterRecordFree(0, pTask->list.pList);
103867 memset(pTask, 0, sizeof(SortSubtask));
103878 i64 t = 0;
103879 sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
103910 #if SQLITE_MAX_WORKER_THREADS>0
103926 pTask->bDone = 0;
103927 pTask->pThread = 0;
103940 assert( pTask->pThread==0 && pTask->bDone==0 );
103946 ** level-0 PMAs.
103959 for(i=pSorter->nTask-1; i>=0; i--){
103988 pNew = sqlite3FaultSim(100) ? 0 : (MergeEngine*)sqlite3MallocZero(nByte);
103991 pNew->pTask = 0;
104004 for(i=0; i<pMerger->nTree; i++){
104017 #if SQLITE_MAX_WORKER_THREADS>0
104020 if( pIncr->aFile[0].pFd ) sqlite3OsCloseFree(pIncr->aFile[0].pFd);
104035 assert( pSorter->bUseThreads || pSorter->pReader==0 );
104036 #if SQLITE_MAX_WORKER_THREADS>0
104040 pSorter->pReader = 0;
104044 pSorter->pMerger = 0;
104045 for(i=0; i<pSorter->nTask; i++){
104050 if( pSorter->list.aMemory==0 ){
104051 vdbeSorterRecordFree(0, pSorter->list.pList);
104053 pSorter->list.pList = 0;
104054 pSorter->list.szPMA = 0;
104055 pSorter->bUsePMA = 0;
104056 pSorter->iMemory = 0;
104057 pSorter->mxKeysize = 0;
104059 pSorter->pUnpacked = 0;
104073 pCsr->uc.pSorter = 0;
104077 #if SQLITE_MAX_MMAP_SIZE>0
104089 void *p = 0;
104093 sqlite3OsFetch(pFd, 0, (int)nByte, &p);
104094 if( p ) sqlite3OsUnfetch(pFd, 0, p);
104104 ** Otherwise, set *ppFd to 0 and return an SQLite error code.
104113 rc = sqlite3OsOpenMalloc(db->pVfs, 0, ppFd,
104121 if( nExtend>0 ){
104134 if( pTask->pUnpacked==0 ){
104136 if( pTask->pUnpacked==0 ) return SQLITE_NOMEM_BKPT;
104138 pTask->pUnpacked->errCode = 0;
104152 SorterRecord *pFinal = 0;
104154 int bCached = 0;
104156 assert( p1!=0 && p2!=0 );
104163 if( res<=0 ){
104167 if( p1==0 ){
104175 bCached = 0;
104176 if( p2==0 ){
104214 memset(aSlot, 0, sizeof(aSlot));
104220 pNext = 0;
104229 p->u.pNext = 0;
104230 for(i=0; aSlot[i]; i++){
104232 aSlot[i] = 0;
104238 p = 0;
104239 for(i=0; i<ArraySize(aSlot); i++){
104240 if( aSlot[i]==0 ) continue;
104260 memset(p, 0, sizeof(PmaWriter));
104278 while( nRem>0 && p->eFWErr==0 ){
104291 p->iBufStart = p->iBufEnd = 0;
104311 if( p->eFWErr==0 && ALWAYS(p->aBuffer) && p->iBufEnd>p->iBufStart ){
104320 memset(p, 0, sizeof(PmaWriter));
104336 ** Write the current contents of in-memory linked-list pList to a level-0
104361 memset(&writer, 0, sizeof(PmaWriter));
104362 assert( pList->szPMA>0 );
104365 if( pTask->file.pFd==0 ){
104366 rc = vdbeSorterOpenTempFile(db, 0, &pTask->file.pFd);
104368 assert( pTask->file.iEof==0 );
104369 assert( pTask->nPMA==0 );
104384 SorterRecord *pNext = 0;
104394 if( pList->aMemory==0 ) sqlite3_free(p);
104401 assert( rc!=SQLITE_OK || pList->pList==0 );
104429 int bCached = 0;
104433 pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
104434 pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
104436 for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
104439 if( pReadr1->pFd==0 ){
104441 }else if( pReadr2->pFd==0 ){
104464 if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
104466 pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
104467 bCached = 0;
104469 if( pReadr1->pFd ) bCached = 0;
104471 pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
104474 *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
104480 #if SQLITE_MAX_WORKER_THREADS>0
104482 ** The main routine for background threads that write level-0 PMAs.
104487 assert( pTask->bDone==0 );
104492 #endif /* SQLITE_MAX_WORKER_THREADS>0 */
104499 #if SQLITE_MAX_WORKER_THREADS==0
104501 return vdbeSorterListToPMA(&pSorter->aTask[0], &pSorter->list);
104505 SortSubtask *pTask = 0; /* Thread context used to create new PMA */
104520 for(i=0; i<nWorker; i++){
104526 if( rc!=SQLITE_OK || pTask->pThread==0 ) break;
104538 assert( pTask!=0 );
104539 assert( pTask->pThread==0 && pTask->bDone==0 );
104540 assert( pTask->list.pList==0 );
104541 assert( pTask->list.aMemory==0 || pSorter->list.aMemory!=0 );
104547 pSorter->list.pList = 0;
104548 pSorter->list.szPMA = 0;
104562 #endif /* SQLITE_MAX_WORKER_THREADS!=0 */
104583 if( t>0 && t<10 && t!=7 ){
104585 }else if( t>10 && (t & 0x01) ){
104588 pSorter->typeMask = 0;
104596 ** If using the single large allocation mode (pSorter->aMemory!=0), then
104622 pSorter->list.szPMA = 0;
104623 pSorter->iMemory = 0;
104624 assert( rc!=SQLITE_OK || pSorter->list.pList==0 );
104648 if( iListOff>=0 ){
104662 if( pNew==0 ){
104688 assert( pIncr->bEof==0 );
104701 if( pReader->pFd==0 ) break;
104717 #if SQLITE_MAX_WORKER_THREADS>0
104741 ** finished reading the contents of aFile[0]. Its purpose is to "refill"
104742 ** aFile[0] such that the PmaReader should start rereading it from the
104746 ** keys from pIncr->pMerger and repopulating aFile[0].
104750 ** aFile[0] and aFile[1] in place. If the contents of pMerger have not
104759 #if SQLITE_MAX_WORKER_THREADS>0
104764 SorterFile f0 = pIncr->aFile[0];
104765 pIncr->aFile[0] = pIncr->aFile[1];
104770 if( pIncr->aFile[0].iEof==pIncr->iStartOff ){
104780 pIncr->aFile[0] = pIncr->aFile[1];
104781 if( pIncr->aFile[0].iEof==pIncr->iStartOff ){
104802 (sqlite3FaultSim(100) ? 0 : sqlite3MallocZero(sizeof(*pIncr)));
104812 assert( *ppOut!=0 || rc!=SQLITE_OK );
104816 #if SQLITE_MAX_WORKER_THREADS>0
104824 #endif /* SQLITE_MAX_WORKER_THREADS>0 */
104843 assert( iOut<pMerger->nTree && iOut>0 );
104856 if( p1->pFd==0 ){
104858 }else if( p2->pFd==0 ){
104862 int bCached = 0;
104864 assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
104868 if( res<=0 ){
104883 ** SQLITE_MAX_WORKER_THREADS==0). The other values are only used
104886 #define INCRINIT_NORMAL 0
104904 ** already been populated, but that they have not yet populated aFile[0] and
104926 assert( pMerger!=0 );
104929 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
104932 assert( pMerger->pTask==0 );
104936 for(i=0; i<nTree; i++){
104937 if( SQLITE_MAX_WORKER_THREADS>0 && eMode==INCRINIT_ROOT ){
104952 for(i=pMerger->nTree-1; i>0; i--){
104960 ** incremental-reader (pReadr->pIncr!=0). This function serves to open
104998 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
105007 #if SQLITE_MAX_WORKER_THREADS>0
105009 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
105016 if( pTask->file2.pFd==0 ){
105017 assert( pTask->file2.iEof>0 );
105019 pTask->file2.iEof = 0;
105029 #if SQLITE_MAX_WORKER_THREADS>0
105046 if( rc==SQLITE_OK && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) ){
105053 #if SQLITE_MAX_WORKER_THREADS>0
105070 ** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes
105083 #if SQLITE_MAX_WORKER_THREADS>0
105084 assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK );
105098 ** Allocate a new MergeEngine object to merge the contents of nPMA level-0
105121 if( pNew==0 ) rc = SQLITE_NOMEM_BKPT;
105123 for(i=0; i<nPMA && rc==SQLITE_OK; i++){
105124 i64 nDummy = 0;
105132 *ppOut = 0;
105144 ** nPMA<=16 -> TreeDepth() == 0
105149 int nDepth = 0;
105189 if( pReadr->pIncr==0 ){
105191 if( pNew==0 ){
105213 ** that has already written two or more level-0 PMAs to one or more temp
105226 MergeEngine *pMain = 0;
105230 #if SQLITE_MAX_WORKER_THREADS>0
105237 if( pMain==0 ) rc = SQLITE_NOMEM_BKPT;
105241 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
105243 assert( pTask->nPMA>0 || SQLITE_MAX_WORKER_THREADS>0 );
105244 if( SQLITE_MAX_WORKER_THREADS==0 || pTask->nPMA ){
105245 MergeEngine *pRoot = 0; /* Root node of tree for this task */
105247 i64 iReadOff = 0;
105253 int iSeq = 0;
105255 if( pRoot==0 ) rc = SQLITE_NOMEM_BKPT;
105256 for(i=0; i<pTask->nPMA && rc==SQLITE_OK; i += SORTER_MAX_MERGE_COUNT){
105257 MergeEngine *pMerger = 0; /* New level-0 PMA merger */
105258 int nReader; /* Number of level-0 PMAs to merge */
105269 #if SQLITE_MAX_WORKER_THREADS>0
105270 if( pMain!=0 ){
105275 assert( pMain==0 );
105286 pMain = 0;
105303 SortSubtask *pTask0 = &pSorter->aTask[0];
105304 MergeEngine *pMain = 0;
105309 for(i=0; i<pSorter->nTask; i++){
105317 assert( pSorter->bUseThreads==0 || pSorter->nTask>1 );
105320 PmaReader *pReadr = 0;
105326 if( pReadr==0 ) rc = SQLITE_NOMEM_BKPT;
105332 for(iTask=0; iTask<(pSorter->nTask-1); iTask++){
105339 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
105350 assert( p->pIncr==0 || (
105352 && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */
105357 pMain = 0;
105367 pMain = 0;
105394 if( pSorter->bUsePMA==0 ){
105396 *pbEof = 0;
105397 rc = vdbeSorterSort(&pSorter->aTask[0], &pSorter->list);
105418 assert( pSorter->pReader==0 );
105421 *pbEof = 0;
105441 assert( pSorter->bUsePMA || (pSorter->pReader==0 && pSorter->pMerger==0) );
105443 assert( pSorter->pReader==0 || pSorter->pMerger==0 );
105444 assert( pSorter->bUseThreads==0 || pSorter->pReader );
105446 #if SQLITE_MAX_WORKER_THREADS>0
105449 if( rc==SQLITE_OK && pSorter->pReader->pFd==0 ) rc = SQLITE_DONE;
105453 int res = 0;
105454 assert( pSorter->pMerger!=0 );
105455 assert( pSorter->pMerger->pTask==(&pSorter->aTask[0]) );
105462 pFree->u.pNext = 0;
105463 if( pSorter->list.aMemory==0 ) vdbeSorterRecordFree(db, pFree);
105480 #if SQLITE_MAX_WORKER_THREADS>0
105549 if( r2==0 ){
105551 if( r2==0 ) return SQLITE_NOMEM_BKPT;
105558 for(i=0; i<nKeyCol; i++){
105596 int bTablesUsed; /* 2 for tables_used(). 0 for bytecode(). */
105629 int isTabUsed = pAux!=0;
105665 if( pNew==0 ) return SQLITE_NOMEM;
105666 memset(pNew, 0, sizeof(*pNew));
105689 if( pCur==0 ) return SQLITE_NOMEM;
105690 memset(pCur, 0, sizeof(*pCur));
105701 pCur->zP4 = 0;
105707 pCur->pStmt = 0;
105708 pCur->needFinalize = 0;
105709 pCur->zType = 0;
105710 pCur->zSchema = 0;
105711 pCur->zName = 0;
105734 pCur->zP4 = 0;
105737 pCur->zName = 0;
105738 pCur->zType = 0;
105739 pCur->zSchema = 0;
105743 pCur->showSubprograms ? &pCur->sub : 0,
105750 pCur->aOp = 0;
105761 return pCur->aOp==0;
105780 if( i<=2 && pCur->zType==0 ){
105796 if( pCur->zName==0 ){
105810 case 0: /* addr */
105828 if( pCur->zP4==0 ){
105845 assert( aOp[0].opcode==OP_Init );
105846 assert( aOp[0].p4.z==0 || strncmp(aOp[0].p4.z,"-" "- ",3)==0 );
105849 }else if( aOp[0].p4.z!=0 ){
105850 sqlite3_result_text(ctx, aOp[0].p4.z+3, -1, SQLITE_STATIC);
105867 sqlite3_result_int(ctx, 0);
105900 ** idxNum==0 means show all subprograms
105914 pCur->iRowid = 0;
105915 pCur->iAddr = 0;
105916 pCur->showSubprograms = idxNum==0;
105918 if( sqlite3_value_type(argv[0])==SQLITE_TEXT ){
105919 const char *zSql = (const char*)sqlite3_value_text(argv[0]);
105920 if( zSql==0 ){
105923 rc = sqlite3_prepare_v2(pVTab->db, zSql, -1, &pCur->pStmt, 0);
105927 pCur->pStmt = (sqlite3_stmt*)sqlite3_value_pointer(argv[0],"stmt-pointer");
105929 if( pCur->pStmt==0 ){
105957 pIdxInfo->idxNum = 0;
105958 for(i=0, p=pIdxInfo->aConstraint; i<pIdxInfo->nConstraint; i++, p++){
105959 if( p->usable==0 ) continue;
105978 /* iVersion */ 0,
105979 /* xCreate */ 0,
105983 /* xDestroy */ 0,
105991 /* xUpdate */ 0,
105992 /* xBegin */ 0,
105993 /* xSync */ 0,
105994 /* xCommit */ 0,
105995 /* xRollback */ 0,
105996 /* xFindMethod */ 0,
105997 /* xRename */ 0,
105998 /* xSavepoint */ 0,
105999 /* xRelease */ 0,
106000 /* xRollbackTo */ 0,
106001 /* xShadowName */ 0,
106002 /* xIntegrity */ 0
106008 rc = sqlite3_create_module(db, "bytecode", &bytecodevtabModule, 0);
106120 assert( p->readpoint.iOffset==0 || p->readpoint.pChunk!=0 );
106121 if( p->readpoint.iOffset!=iOfst || iOfst==0 ){
106122 sqlite3_int64 iOff = 0;
106131 assert( pChunk!=0 );
106141 iChunkOffset = 0;
106142 } while( nRead>=0 && (pChunk=pChunk->pNext)!=0 && nRead>0 );
106143 p->readpoint.iOffset = pChunk ? iOfst+iAmt : 0;
106169 memset(p, 0, sizeof(MemJournal));
106170 rc = sqlite3OsOpen(copy.pVfs, copy.zJournal, pReal, copy.flags, 0);
106173 i64 iOff = 0;
106218 if( p->nSpill>0 && (iAmt+iOfst)>p->nSpill ){
106234 if( iOfst>0 && iOfst!=p->endpoint.iOffset ){
106237 if( iOfst==0 && p->pFirst ){
106241 while( nWrite>0 ){
106246 assert( pChunk!=0 || iChunkOffset==0 );
106247 if( iChunkOffset==0 ){
106253 pNew->pNext = 0;
106264 assert( pChunk!=0 );
106281 assert( p->endpoint.pChunk==0 || p->endpoint.pChunk->pNext==0 );
106283 FileChunk *pIter = 0;
106284 if( size==0 ){
106286 p->pFirst = 0;
106294 pIter->pNext = 0;
106300 p->readpoint.pChunk = 0;
106301 p->readpoint.iOffset = 0;
106346 0, /* xLock */
106347 0, /* xUnlock */
106348 0, /* xCheckReservedLock */
106349 0, /* xFileControl */
106350 0, /* xSectorSize */
106351 0, /* xDeviceCharacteristics */
106352 0, /* xShmMap */
106353 0, /* xShmLock */
106354 0, /* xShmBarrier */
106355 0, /* xShmUnmap */
106356 0, /* xFetch */
106357 0 /* xUnfetch */
106364 ** nSpill. If nSpill is 0, then the journal file is always create and
106381 assert( zName || nSpill<0 || (flags & SQLITE_OPEN_EXCLUSIVE) );
106387 memset(p, 0, sizeof(MemJournal));
106388 if( nSpill==0 ){
106389 return sqlite3OsOpen(pVfs, zName, pJfd, flags, 0);
106392 if( nSpill>0 ){
106411 sqlite3JournalOpen(0, 0, pJfd, 0, -1);
106427 p->nSpill>0
106432 NEVER(p->nSpill>0)
106534 assert( pExpr->x.pList==0 || pExpr->pRight==0 );
106572 for(i=p->nExpr, pItem=p->a; i>0; i--, pItem++){
106606 || ((pParse = pWalker->pParse)!=0 && IN_RENAME_OBJECT)
106613 int rc = walkWindowList(pWalker, p->pWinDefn, 0);
106635 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
106668 if( p==0 ) return WRC_Continue;
106669 if( pWalker->xSelectCallback==0 ) return WRC_Continue;
106682 }while( p!=0 );
106764 if( N>0 ){
106766 memset(&w, 0, sizeof(w));
106795 int iCol, /* A column in the result set. 0..pEList->nExpr-1 */
106803 assert( iCol>=0 && iCol<pEList->nExpr );
106805 assert( pOrig!=0 );
106809 pDup = sqlite3ExprDup(db, pOrig, 0);
106812 pDup = 0;
106824 if( ALWAYS(pExpr->y.pWin!=0) ){
106859 if( eEName!=ENAME_TAB && (eEName!=ENAME_ROWID || NEVER(pbRowid==0)) ){
106860 return 0;
106862 assert( pbRowid==0 || *pbRowid==0 );
106864 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
106865 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
106866 return 0;
106869 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
106870 if( zTab && (sqlite3StrNICmp(zSpan, zTab, n)!=0 || zTab[n]!=0) ){
106871 return 0;
106875 if( eEName==ENAME_TAB && sqlite3StrICmp(zSpan, zCol)!=0 ) return 0;
106876 if( eEName==ENAME_ROWID && sqlite3IsRowid(zCol)==0 ) return 0;
106889 if( sqlite3WritableSchema(db) && (db->flags & SQLITE_DqsDML)!=0 ){
106892 return (db->flags & SQLITE_DqsDDL)!=0;
106895 return (db->flags & SQLITE_DqsDML)!=0;
106910 assert( pExTab!=0 );
106912 if( (pExTab->tabFlags & TF_HasGenerated)!=0
106913 && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
106938 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
106943 assert( (pMatch->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 );
106958 assert( pTab!=0 );
106960 if( sqlite3StrNICmp(zTab, "sqlite_", 7)!=0 ) return 0;
106962 if( strcmp(zLegacy+7, &LEGACY_TEMP_SCHEMA_TABLE[7])==0 ){
106963 if( sqlite3StrICmp(zTab+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 ){
106966 if( zDb==0 ) return 0;
106967 if( sqlite3StrICmp(zTab+7, &LEGACY_SCHEMA_TABLE[7])==0 ) return 1;
106968 if( sqlite3StrICmp(zTab+7, &PREFERRED_SCHEMA_TABLE[7])==0 ) return 1;
106970 if( sqlite3StrICmp(zTab+7, &PREFERRED_SCHEMA_TABLE[7])==0 ) return 1;
106972 return 0;
107011 int cnt = 0; /* Number of matching column names */
107012 int cntTab = 0; /* Number of potential "rowid" matches */
107013 int nSubquery = 0; /* How many levels of subquery */
107016 SrcItem *pMatch = 0; /* The matching pSrcList item */
107018 Schema *pSchema = 0; /* Schema of the expression */
107020 Table *pTab = 0; /* Table holding the row */
107022 ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */
107027 assert( zDb==0 || zTab!=0 );
107041 if( (pNC->ncFlags & (NC_PartIdx|NC_IsCheck))!=0 ){
107046 zDb = 0;
107048 for(i=0; i<db->nDb; i++){
107050 if( sqlite3StrICmp(db->aDb[i].zDbSName,zDb)==0 ){
107055 if( i==db->nDb && sqlite3StrICmp("main", zDb)==0 ){
107058 pSchema = db->aDb[0].pSchema;
107059 zDb = db->aDb[0].zDbSName;
107065 assert( pNC && cnt==0 );
107071 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
107074 assert( pTab!=0 && pTab->zName!=0 );
107075 assert( pTab->nCol>0 || pParse->nErr );
107084 int hit = 0;
107085 assert( pItem->pSelect!=0 );
107087 assert( pEList!=0 );
107089 for(j=0; j<pEList->nExpr; j++){
107090 int bRowid = 0; /* True if possible rowid match */
107094 if( bRowid==0 ){
107095 if( cnt>0 ){
107096 if( pItem->fg.isUsing==0
107097 || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
107103 pFJMatch = 0;
107105 if( (pItem->fg.jointype & JT_RIGHT)==0 ){
107109 if( (pItem->fg.jointype & JT_LEFT)==0 ){
107111 cnt = 0;
107113 pFJMatch = 0;
107121 }else if( cnt>0 ){
107132 assert( bRowid==0 || pEList->a[j].fg.bUsingTerm==0 );
107135 if( hit || zTab==0 ) continue;
107137 assert( zDb==0 || zTab!=0 );
107141 if( pSchema==0 && strcmp(zDb,"*")!=0 ) continue;
107143 if( pItem->zAlias!=0 ){
107144 if( sqlite3StrICmp(zTab, pItem->zAlias)!=0 ){
107147 }else if( sqlite3StrICmp(zTab, pTab->zName)!=0 ){
107153 sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
107157 for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
107159 && sqlite3StrICmp(pCol->zCnName, zCol)==0
107161 if( cnt>0 ){
107162 if( pItem->fg.isUsing==0
107163 || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
107169 pFJMatch = 0;
107171 if( (pItem->fg.jointype & JT_RIGHT)==0 ){
107175 if( (pItem->fg.jointype & JT_LEFT)==0 ){
107177 cnt = 0;
107179 pFJMatch = 0;
107195 if( 0==cnt && VisibleRowid(pTab) ){
107207 if( cntTab==0
107209 && ALWAYS(pMatch!=0)
107210 && ALWAYS(pMatch->pTab!=0)
107211 && (pMatch->pTab->tabFlags & TF_Ephemeral)!=0
107212 && (pTab->tabFlags & TF_Ephemeral)==0)
107233 if( (pMatch->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 ){
107246 if( cnt==0 && zDb==0 ){
107247 pTab = 0;
107249 if( pParse->pTriggerTab!=0 ){
107253 if( (pNC->ncFlags & NC_UBaseReg)!=0
107254 && ALWAYS(zTab==0
107255 || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0
107256 || isValidSchemaTableName(zTab, pParse->pTriggerTab, 0))
107261 }else if( op!=TK_DELETE && zTab && sqlite3StrICmp("new",zTab) == 0 ){
107264 }else if( op!=TK_INSERT && zTab && sqlite3StrICmp("old",zTab)==0 ){
107265 pExpr->iTable = 0;
107271 if( (pNC->ncFlags & NC_UUpsert)!=0 && zTab!=0 ){
107273 if( pUpsert && sqlite3StrICmp("excluded",zTab)==0 ){
107274 pTab = pUpsert->pUpsertSrc->a[0].pTab;
107285 for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){
107287 && sqlite3StrICmp(pCol->zCnName, zCol)==0
107301 pMatch = 0;
107330 if( iCol<0 ){
107332 }else if( pExpr->iTable==0 ){
107335 pParse->oldmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
107339 pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
107352 if( cnt==0
107355 && (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0
107360 #if SQLITE_ALLOW_ROWID_IN_VIEW+0==2
107361 if( pMatch->pTab!=0 && IsView(pMatch->pTab) ){
107365 if( pMatch->fg.isNestedFrom==0 ) pExpr->iColumn = -1;
107387 if( cnt==0
107388 && (pNC->ncFlags & NC_UEList)!=0
107389 && zTab==0
107392 assert( pEList!=0 );
107393 for(j=0; j<pEList->nExpr; j++){
107396 && sqlite3_stricmp(zAs, zCol)==0
107399 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
107400 assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
107401 assert( ExprUseXSelect(pExpr)==0 || pExpr->x.pSelect==0 );
107403 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
107408 && ((pNC->ncFlags&NC_AllowWin)==0 || pNC!=pTopNC )
107419 pMatch = 0;
107420 assert( zTab==0 && zDb==0 );
107422 sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr);
107430 ** we have a match (cnt>0) or when we run out of name contexts.
107448 if( cnt==0 && zTab==0 ){
107473 memset(&pExpr->y, 0, sizeof(pExpr->y));
107482 ** cnt==0 means there was not match.
107485 ** cnt==0 is always an error. cnt>1 is often an error, but might
107488 assert( pFJMatch==0 || cnt>0 );
107498 pExpr->pLeft = 0;
107500 pExpr->pRight = 0;
107510 pFJMatch = 0;
107513 zErr = cnt==0 ? "no such column" : "ambiguous column name";
107518 }else if( cnt==0 && ExprHasProperty(pRight,EP_DblQuoted) ){
107530 assert( pFJMatch==0 );
107535 pExpr->pLeft = 0;
107537 pExpr->pRight = 0;
107542 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
107543 ** bit 0 to be set. Column 1 sets bit 1. And so forth. Bit 63 is
107556 if( pExpr->iColumn>=0 ){
107566 assert( pNC!=0 );
107577 assert( pTopNC!=0 );
107593 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
107604 if( (pTab->tabFlags & TF_HasGenerated)!=0
107605 && (pTab->aCol[iCol].colFlags & COLFLAG_GENERATED)!=0
107656 assert( ((X)&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 ); \
107657 if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E,R);
107678 ** node in the expression tree. Return 0 to continue the search down
107690 assert( pNC!=0 );
107695 if( pNC->pSrcList && pNC->pSrcList->nAlloc>0 ){
107698 for(i=0; i<pNC->pSrcList->nSrc; i++){
107699 assert( pSrcList->a[i].iCursor>=0 && pSrcList->a[i].iCursor<pParse->nTab);
107756 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
107766 for(i=0, p=pNC; p; p=p->pNext, i++){
107767 if( (p->ncFlags & NC_Where)==0 ){
107774 if( sqlite3TreeTrace & 0x80000 ){
107785 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
107789 pExpr->pLeft = 0;
107808 zDb = 0;
107809 zTable = 0;
107817 NC_IdxExpr|NC_GenCol, 0, pExpr);
107820 zDb = 0;
107843 int n = pList ? pList->nExpr : 0; /* Number of arguments */
107844 int no_such_func = 0; /* True if no such function exists */
107845 int wrong_num_args = 0; /* True if wrong number of arguments */
107846 int is_agg = 0; /* True if is an aggregate function */
107852 Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
107855 assert( pExpr->pLeft==0 || pExpr->pLeft->op==TK_ORDER );
107857 pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
107858 if( pDef==0 ){
107859 pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
107860 if( pDef==0 ){
107866 is_agg = pDef->xFinalize!=0;
107871 if( pExpr->iTable<0 ){
107887 pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120;
107892 int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0);
107911 if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
107919 NC_IdxExpr|NC_PartIdx|NC_GenCol, 0, pExpr);
107921 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
107925 if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
107926 && pParse->nested==0
107927 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
107934 pDef = 0;
107936 if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
107943 if( 0==IN_RENAME_OBJECT ){
107945 assert( is_agg==0 || (pDef->funcFlags & SQLITE_FUNC_MINMAX)
107946 || (pDef->xValue==0 && pDef->xInverse==0)
107949 if( pDef && pDef->xValue==0 && pWin ){
107955 (is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
107957 || (is_agg && pWin && (pNC->ncFlags & NC_AllowWin)==0)
107967 is_agg = 0;
107970 if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){
107973 is_agg = 0;
107976 else if( no_such_func && pParse->db->init.busy==0
107978 && pParse->explain==0
107989 else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
107997 else if( is_agg==0 && pExpr->pLeft ){
108006 pNC->ncFlags &= ~(NC_AllowWin | (!pWin ? NC_AllowAgg : 0));
108025 assert( pWin==0 || (ExprUseYWin(pExpr) && pWin==pExpr->y.pWin) );
108026 if( IN_RENAME_OBJECT==0 ){
108027 sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
108040 pExpr->op2 = 0;
108048 && sqlite3ReferencesSrcList(pParse, pExpr, pNC2->pSrcList)==0
108053 assert( pDef!=0 || IN_RENAME_OBJECT );
108058 testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 );
108059 testcase( (pDef->funcFlags & SQLITE_FUNC_ANYORDER)!=0 );
108134 assert( pExpr->pLeft!=0 );
108138 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
108143 assert( pExpr->pRight!=0 );
108162 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
108174 ** return 0.
108191 for(i=0; i<pEList->nExpr; i++){
108193 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
108199 return 0;
108218 ** If there is no match, return 0. Return -1 if an error occurs.
108232 assert( sqlite3ExprIsInteger(pE, &i)==0 );
108237 memset(&nc, 0, sizeof(nc));
108242 nc.nNcErr = 0;
108248 if( rc ) return 0;
108254 for(i=0; i<pEList->nExpr; i++){
108255 if( sqlite3ExprCompare(0, pEList->a[i].pExpr, pE, -1)<2 ){
108260 /* If no match, return 0. */
108261 return 0;
108306 if( pOrderBy==0 ) return 0;
108312 for(i=0; i<pOrderBy->nExpr; i++){
108313 pOrderBy->a[i].fg.done = 0;
108315 pSelect->pNext = 0;
108322 moreToDo = 0;
108324 assert( pEList!=0 );
108325 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
108330 if( NEVER(pE==0) ) continue;
108332 if( iCol<=0 || iCol>pEList->nExpr ){
108338 if( iCol==0 ){
108350 pDup = sqlite3ExprDup(db, pE, 0);
108354 if( IN_RENAME_OBJECT && iCol>0 ){
108361 if( iCol>0 ){
108365 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
108366 if( pNew==0 ) return 1;
108388 for(i=0; i<pOrderBy->nExpr; i++){
108389 if( pOrderBy->a[i].fg.done==0 ){
108395 return 0;
108419 if( pOrderBy==0 || pParse->db->mallocFailed || IN_RENAME_OBJECT ) return 0;
108425 assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
108426 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
108429 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr, 0);
108432 resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,0);
108435 return 0;
108458 memset(&sWalker, 0, sizeof(Walker));
108498 assert( pOrderBy!=0 );
108501 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
108504 if( NEVER(pE2==0) ) continue;
108505 if( zType[0]!='G' ){
108507 if( iCol>0 ){
108520 if( iCol<1 || iCol>0xffff ){
108529 pItem->u.x.iOrderByCol = 0;
108533 for(j=0; j<pSelect->pEList->nExpr; j++){
108534 if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
108561 assert( p!=0 );
108577 if( (p->selFlags & SF_Expanded)==0 ){
108582 isCompound = p->pPrior!=0;
108583 nCompound = 0;
108586 assert( (p->selFlags & SF_Expanded)!=0 );
108587 assert( (p->selFlags & SF_Resolved)==0 );
108593 memset(&sNC, 0, sizeof(sNC));
108607 Select *pSub = p->pSrc->a[0].pSelect;
108609 assert( pSub->pPrior && pSub->pOrderBy==0 );
108611 p->pOrderBy = 0;
108617 for(i=0; i<p->pSrc->nSrc; i++){
108619 assert( pItem->zName!=0 || pItem->pSelect!=0 );/* Test of tag-20240424-1*/
108620 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){
108621 int nRef = pOuterNC ? pOuterNC->nRef : 0;
108628 assert( db->mallocFailed==0 );
108637 assert( pItem->fg.isCorrelated==0 && pOuterNC->nRef>=nRef );
108642 if( pOuterNC && ALWAYS(pOuterNC->nNestedSelect>0) ){
108660 assert( (p->selFlags & SF_Aggregate)==0 );
108662 if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
108678 assert( (sNC.ncFlags & (NC_UAggInfo|NC_UUpsert|NC_UBaseReg))==0 );
108682 if( (p->selFlags & SF_Aggregate)==0 ){
108693 for(i=0; i<p->pSrc->nSrc; i++){
108718 sNC.pNext = 0;
108727 Select *pSub = p->pSrc->a[0].pSelect;
108729 pSub->pOrderBy = 0;
108742 if( p->pOrderBy!=0
108762 for(i=0, pItem=pGroupBy->a; i<pGroupBy->nExpr; i++, pItem++){
108849 if( pExpr==0 ) return SQLITE_OK;
108854 w.xSelectCallback = (pNC->ncFlags & NC_NoSelect) ? 0 : resolveSelectStep;
108855 w.xSelectCallback2 = 0;
108857 #if SQLITE_MAX_EXPR_DEPTH>0
108863 assert( pExpr!=0 );
108865 #if SQLITE_MAX_EXPR_DEPTH>0
108874 return pNC->nNcErr>0 || w.pParse->nErr>0;
108882 ** The return value is SQLITE_OK (0) for success or SQLITE_ERROR (1) for a
108890 int savedHasAgg = 0;
108892 if( pList==0 ) return SQLITE_OK;
108896 w.xSelectCallback2 = 0;
108900 for(i=0; i<pList->nExpr; i++){
108902 if( pExpr==0 ) continue;
108903 #if SQLITE_MAX_EXPR_DEPTH>0
108910 #if SQLITE_MAX_EXPR_DEPTH>0
108923 if( w.pParse->nErr>0 ) return SQLITE_ERROR;
108948 assert( p!=0 );
108951 w.xSelectCallback2 = 0;
108966 ** (4) Expression arguments to VACUUM INTO. 0
108978 int type, /* NC_IsCheck, NC_PartIdx, NC_IdxExpr, NC_GenCol, or 0 */
108986 assert( type==0 || pTab!=0 );
108988 || type==NC_GenCol || pTab==0 );
108989 memset(&sNC, 0, sizeof(sNC));
108990 memset(&sSrc, 0, sizeof(sSrc));
108993 sSrc.a[0].zName = pTab->zName;
108994 sSrc.a[0].pTab = pTab;
108995 sSrc.a[0].iCursor = -1;
109036 if( iCol<0 || NEVER(iCol>=pTab->nCol) ) return SQLITE_AFF_INTEGER;
109045 ** affinity of that column is returned. Otherwise, 0x00 is returned,
109060 if( op==TK_COLUMN || (op==TK_AGG_COLUMN && pExpr->y.pTab!=0) ){
109062 assert( pExpr->y.pTab!=0 );
109067 assert( pExpr->x.pSelect!=0 );
109068 assert( pExpr->x.pSelect->pEList!=0 );
109069 assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
109070 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
109075 return sqlite3AffinityType(pExpr->u.zToken, 0);
109079 assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
109081 assert( pExpr->iColumn >= 0 );
109089 return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
109108 ** 0x01 Numeric
109109 ** 0x02 Text
109110 ** 0x04 Blob
109112 ** If the expression must return NULL, then 0x00 is returned.
109124 pExpr = 0;
109128 return 0x02;
109131 return 0x04;
109134 return 0x06;
109139 return 0x07;
109148 if( aff>=SQLITE_AFF_NUMERIC ) return 0x05;
109149 if( aff==SQLITE_AFF_TEXT ) return 0x06;
109150 return 0x07;
109153 int res = 0;
109156 assert( ExprUseXList(pExpr) && pList!=0 );
109157 assert( pList->nExpr > 0);
109167 return 0x01;
109171 return 0x00;
109188 if( pCollName->n>0 ){
109204 assert( zC!=0 );
109206 return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0);
109229 assert( pExpr->x.pList->nExpr>0 );
109231 pExpr = pExpr->x.pList->a[0].pExpr;
109257 CollSeq *pColl = 0;
109262 if( (op==TK_AGG_COLUMN && p->y.pTab!=0)
109267 assert( p->y.pTab!=0 );
109268 if( (j = p->iColumn)>=0 ){
109270 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
109280 p = p->x.pList->a[0].pExpr;
109285 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
109289 if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){
109294 assert( !ExprUseXList(p) || p->x.pList==0 || p->pRight==0 );
109295 if( ExprUseXList(p) && p->x.pList!=0 && !db->mallocFailed ){
109297 for(i=0; i<p->x.pList->nExpr; i++){
109311 pColl = 0;
109328 if( p==0 ) p = pParse->db->pDfltColl;
109329 assert( p!=0 );
109339 return sqlite3StrICmp(pColl1->zName, pColl2->zName)==0;
109379 aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
109380 }else if( aff==0 ){
109438 }else if( pRight && (pRight->flags & EP_Collate)!=0 ){
109482 if( pParse->nErr ) return 0;
109530 ** column of the vector (numbered starting with 0). The caller must
109546 assert( pVector->op2==0 || pVector->op==TK_REGISTER );
109563 ** It is ok for pVector to be a scalar (as long as iField==0).
109593 ** iTable: 0 or the number of columns on the LHS of an assignment
109594 ** pLeft->iTable: First in an array of register holding result, or 0
109604 pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0);
109619 *ppVector = 0;
109623 pRet = sqlite3ExprDup(pParse->db, pVector, 0);
109634 ** If pExpr is not a TK_SELECT expression, return 0.
109637 int reg = 0;
109688 return 0;
109693 ** the result of the comparison (1, 0, or NULL) and write that
109700 ** otherwise: op==pExpr->op and p5==0
109714 int regLeft = 0;
109715 int regRight = 0;
109717 int addrCmp = 0;
109734 assert( p5==0 || pExpr->op!=op );
109745 for(i=0; 1 /*Loop exits by "break"*/; i++){
109746 int regFree1 = 0, regFree2 = 0;
109747 Expr *pL = 0, *pR = 0;
109749 assert( i>=0 && i<nLeft );
109769 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest);
109780 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
109791 #if SQLITE_MAX_EXPR_DEPTH>0
109828 for(i=0; i<p->nExpr; i++){
109856 int nHeight = p->pLeft ? p->pLeft->nHeight : 0;
109888 int nHeight = 0;
109904 #endif /* SQLITE_MAX_EXPR_DEPTH>0 */
109910 if( pExpr==0 ) return;
109943 int nExtra = 0;
109944 int iValue = 0;
109946 assert( db!=0 );
109948 if( op!=TK_INTEGER || pToken->z==0
109949 || sqlite3GetInt32(pToken->z, &iValue)==0 ){
109951 assert( iValue>=0 );
109956 memset(pNew, 0, sizeof(Expr));
109960 if( nExtra==0 ){
109965 assert( pToken->z!=0 || pToken->n==0 );
109967 pNew->u.zToken[pToken->n] = 0;
109968 if( dequote && sqlite3Isquote(pNew->u.zToken[0]) ){
109973 #if SQLITE_MAX_EXPR_DEPTH>0
109992 return sqlite3ExprAlloc(db, op, &x, 0);
110007 if( pRoot==0 ){
110013 assert( pRoot->x.pSelect==0 );
110017 #if SQLITE_MAX_EXPR_DEPTH>0
110026 #if SQLITE_MAX_EXPR_DEPTH>0
110051 memset(p, 0, sizeof(Expr));
110052 p->op = op & 0xff;
110099 Select *pRet = 0;
110101 for(ii=0; ii<pEList->nExpr; ii++){
110118 pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0);
110119 pExpr->x.pList = 0;
110146 if( pLeft==0 ){
110148 }else if( pRight==0 ){
110157 return sqlite3Expr(db, TK_INTEGER, "0");
110172 int eDistinct /* SF_Distinct or SF_ALL or 0 */
110178 if( pNew==0 ){
110180 return 0;
110225 if( NEVER(pOrderBy==0) ){
110229 if( pExpr==0 ){
110235 assert( pExpr->pLeft==0 );
110237 if( pExpr->x.pList==0 || NEVER(pExpr->x.pList->nExpr==0) ){
110248 pOB = sqlite3ExprAlloc(db, TK_ORDER, 0, 0);
110249 if( pOB==0 ){
110276 assert( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 );
110278 if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0
110279 || (pParse->db->flags & SQLITE_TrustedSchema)==0
110314 if( pExpr==0 ) return;
110317 assert( z!=0 );
110318 assert( z[0]!=0 );
110320 if( z[1]==0 ){
110322 assert( z[0]=='?' );
110325 int doAdd = 0;
110326 if( z[0]=='?' ){
110332 i = z[1]-'0'; /* The common case of ?N for a single digit N */
110335 bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
110337 testcase( i==0 );
110341 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
110351 }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
110360 if( x==0 ){
110380 assert( p!=0 );
110381 assert( db!=0 );
110383 assert( !ExprUseUValue(p) || p->u.iValue>=0 );
110385 assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed );
110389 assert( p->pLeft==0 );
110390 assert( p->pRight==0 );
110391 assert( !ExprUseXSelect(p) || p->x.pSelect==0 );
110392 assert( !ExprUseXList(p) || p->x.pList==0 );
110397 assert( (ExprUseXList(p) && p->x.pList==0) || p->pRight==0 );
110441 if( p==0 ){
110457 ** Return 0 if the delete was successfully deferred. Return non-zero
110461 return 0==sqlite3ParserAddCleanup(pParse, sqlite3ExprDeleteGeneric, pExpr);
110508 ** of this routine with 0xfff. The flags can be found by masking the
110523 assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
110524 assert( EXPR_FULLSIZE<=0xfff );
110525 assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
110526 if( 0==flags || ExprHasProperty(p, EP_FullSize) ){
110535 assert( p->pRight==0 );
110548 int nByte = dupedExprStructSize(p, flags) & 0xfff;
110568 assert( p!=0 );
110601 int dupFlags, /* EXPRDUP_REDUCE for compression. 0 if not */
110609 assert( db!=0 );
110611 assert( dupFlags==0 || dupFlags==EXPRDUP_REDUCE );
110612 assert( pEdupBuf==0 || dupFlags==EXPRDUP_REDUCE );
110621 assert( sEdupBuf.zAlloc!=0 );
110631 nToken = 0;
110637 sEdupBuf.zEnd = sEdupBuf.zAlloc ? sEdupBuf.zAlloc+nAlloc : 0;
110640 staticFlag = 0;
110652 int nNewSize = nStructSize & 0xfff;
110653 if( nToken<0 ){
110657 nToken = 0;
110662 assert( ExprHasProperty(p, EP_Reduced)==0 );
110670 memset(&sEdupBuf.zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
110685 assert( nToken>=0 );
110686 if( nToken>0 ){
110693 if( ((p->flags|pNew->flags)&(EP_TokenOnly|EP_Leaf))==0 ){
110700 p->op!=TK_ORDER ? dupFlags : 0);
110714 assert( p->pRight==0
110719 exprDup(db, p->pLeft, EXPRDUP_REDUCE, &sEdupBuf) : 0;
110722 exprDup(db, p->pRight, EXPRDUP_REDUCE, &sEdupBuf) : 0;
110726 assert( p->pRight==0
110730 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
110732 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
110748 With *pRet = 0;
110750 sqlite3_int64 nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
110755 for(i=0; i<p->nCte; i++){
110756 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
110757 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
110766 # define sqlite3WithDup(x,y) 0
110782 assert( pWin->ppThis==0 );
110794 w.xSelectCallback2 = 0;
110795 w.pParse = 0;
110820 assert( flags==0 || flags==EXPRDUP_REDUCE );
110821 return p ? exprDup(db, p, flags, 0) : 0;
110828 Expr *pPriorSelectColOld = 0;
110829 Expr *pPriorSelectColNew = 0;
110830 assert( db!=0 );
110831 if( p==0 ) return 0;
110833 if( pNew==0 ) return 0;
110838 for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
110844 && (pNewExpr = pItem->pExpr)!=0
110861 pItem->fg.done = 0;
110879 assert( db!=0 );
110880 if( p==0 ) return 0;
110881 nByte = sizeof(*p) + (p->nSrc>0 ? sizeof(p->a[0]) * (p->nSrc-1) : 0);
110883 if( pNew==0 ) return 0;
110885 for(i=0; i<p->nSrc; i++){
110928 assert( db!=0 );
110929 if( p==0 ) return 0;
110931 pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew)+(p->nId-1)*sizeof(p->a[0]) );
110932 if( pNew==0 ) return 0;
110935 for(i=0; i<p->nId; i++){
110944 Select *pRet = 0;
110945 Select *pNext = 0;
110949 assert( db!=0 );
110952 if( pNew==0 ) break;
110961 pNew->pPrior = 0;
110963 pNew->iLimit = 0;
110964 pNew->iOffset = 0;
110966 pNew->addrOpenEphm[0] = -1;
110971 pNew->pWin = 0;
110973 if( p->pWin && db->mallocFailed==0 ) gatherSelectWindows(pNew);
110980 pNew->pNext = 0;
110993 assert( p==0 );
110994 return 0;
111010 static const struct ExprList_item zeroItem = {0};
111018 pList = sqlite3DbMallocRawNN(db, sizeof(ExprList)+sizeof(pList->a[0])*4 );
111019 if( pList==0 ){
111021 return 0;
111025 pItem = &pList->a[0];
111039 sizeof(*pList)+(pList->nAlloc-1)*sizeof(pList->a[0]));
111040 if( pNew==0 ){
111043 return 0;
111058 if( pList==0 ){
111090 int iFirst = pList ? pList->nExpr : 0;
111093 if( NEVER(pColumns==0) ) goto vector_append_error;
111094 if( pExpr==0 ) goto vector_append_error;
111107 for(i=0; i<pColumns->nId; i++){
111109 assert( pSubExpr!=0 || db->mallocFailed );
111110 if( pSubExpr==0 ) continue;
111115 pColumns->a[i].zName = 0;
111119 if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){
111121 assert( pFirst!=0 );
111127 pExpr = 0;
111145 if( p==0 ) return;
111146 assert( p->nExpr>0 );
111148 assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC==0 && SQLITE_SO_DESC>0 );
111159 assert( pItem->fg.bNulls==0 );
111187 assert( pList!=0 || pParse->db->mallocFailed!=0 );
111188 assert( pParse->eParseMode!=PARSE_MODE_UNMAP || dequote==0 );
111191 assert( pList->nExpr>0 );
111193 assert( pItem->zEName==0 );
111197 /* If dequote==0, then pName->z does not point to part of a DDL
111223 assert( pList!=0 || db->mallocFailed!=0 );
111226 assert( pList->nExpr>0 );
111227 if( pItem->zEName==0 ){
111257 assert( pList->nExpr>0 );
111258 assert( db!=0 );
111263 }while( --i>0 );
111279 u32 m = 0;
111280 assert( pList!=0 );
111281 for(i=0; i<pList->nExpr; i++){
111283 assert( pExpr!=0 );
111298 pWalker->eCode = 0;
111308 ** anything else 0
111311 if( sqlite3StrICmp(zIn, "true")==0 ) return EP_IsTrue;
111312 if( sqlite3StrICmp(zIn, "false")==0 ) return EP_IsFalse;
111313 return 0;
111326 && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0
111332 return 0;
111337 ** and 0 if it is FALSE.
111343 assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
111344 || sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
111345 return pExpr->u.zToken[4]==0;
111362 assert( pExpr!=0 );
111385 ** This routine sets pWalker->eCode to 0 if pExpr is not a constant.
111402 || (pList = pExpr->x.pList)==0
111404 n = 0;
111408 if( pWalker->eCode==0 ) return WRC_Abort;
111411 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
111412 if( pDef==0
111413 || pDef->xFinalize!=0
111414 || (pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
111417 pWalker->eCode = 0;
111437 ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
111451 assert( pWalker->eCode>0 );
111457 pWalker->eCode = 0;
111474 pWalker->eCode = 0;
111506 pWalker->eCode = 0;
111517 pWalker->eCode = 0;
111542 ** and 0 if it involves variables or function calls.
111582 assert( pSelect!=0 );
111583 assert( pWalker->eCode==3 || pWalker->eCode==0 );
111584 if( (pSelect->selFlags & SF_Correlated)!=0 ){
111585 pWalker->eCode = 0;
111603 w.pParse = 0;
111627 ** doubt, return 0.
111670 return 0; /* rule (3) */
111673 if( !ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (4a) */
111674 if( pExpr->w.iJoin!=pSrc->iCursor ) return 0; /* rule (4b) */
111676 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (5) */
111679 && (pSrcList->a[0].fg.jointype & JT_LTORJ)!=0 /* Fast pre-test of (6b) */
111682 for(jj=0; jj<iSrc; jj++){
111684 if( (pSrcList->a[jj].fg.jointype & JT_LTORJ)!=0 ){
111685 return 0; /* restriction (6) */
111705 for(i=0; i<pGroupBy->nExpr; i++){
111707 if( sqlite3ExprCompare(0, pExpr, p, -1)<2 ){
111717 pWalker->eCode = 0;
111747 w.xSelectCallback = 0;
111759 ** Return and 0 if there are any variables.
111776 assert( isInit==0 || isInit==1 );
111777 return exprIsConst(0, p, 4+isInit);
111783 ** subquery of some kind. Return 0 if there are no subqueries.
111794 return w.eCode==0;
111802 ** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged.
111805 int rc = 0;
111806 if( NEVER(p==0) ) return 0; /* Used to only happen following on OOM */
111810 assert( p->op!=TK_INTEGER || (p->flags & EP_IntValue)!=0
111811 || sqlite3GetInt32(p->u.zToken, &rc)==0 );
111823 int v = 0;
111825 assert( ((unsigned int)v)!=0x80000000 );
111852 assert( p!=0 );
111855 assert( p!=0 );
111864 return 0;
111868 || NEVER(p->y.pTab==0) /* Reference to column of index on expr */
111872 || (p->iColumn>=0
111873 && p->y.pTab->aCol!=0 /* Possible due to prior error */
111875 && p->y.pTab->aCol[p->iColumn].notNull==0);
111893 int unaryMinus = 0;
111915 assert( p->iTable>=0 ); /* p cannot be part of a CHECK constraint */
111916 return aff>=SQLITE_AFF_NUMERIC && p->iColumn<0;
111919 return 0;
111928 if( sqlite3StrICmp(z, "_ROWID_")==0 ) return 1;
111929 if( sqlite3StrICmp(z, "ROWID")==0 ) return 1;
111930 if( sqlite3StrICmp(z, "OID")==0 ) return 1;
111931 return 0;
111943 for(ii=0; ii<ArraySize(azOpt); ii++){
111945 for(iCol=0; iCol<pTab->nCol; iCol++){
111946 if( sqlite3_stricmp(azOpt[ii], pTab->aCol[iCol].zCnName)==0 ) break;
111952 return 0;
111969 if( !ExprUseXSelect(pX) ) return 0; /* Not a subquery */
111970 if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */
111972 if( p->pPrior ) return 0; /* Not a compound SELECT */
111976 return 0; /* No DISTINCT keyword and no aggregate functions */
111978 assert( p->pGroupBy==0 ); /* Has no GROUP BY clause */
111979 if( p->pLimit ) return 0; /* Has no LIMIT clause */
111980 if( p->pWhere ) return 0; /* Has no WHERE clause */
111982 assert( pSrc!=0 );
111983 if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
111984 if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */
111985 pTab = pSrc->a[0].pTab;
111986 assert( pTab!=0 );
111988 if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
111990 assert( pEList!=0 );
111992 for(i=0; i<pEList->nExpr; i++){
111994 if( pRes->op!=TK_COLUMN ) return 0;
111995 assert( pRes->iTable==pSrc->a[0].iCursor ); /* Not a correlated subquery */
112010 sqlite3VdbeAddOp2(v, OP_Integer, 0, regHasNull);
112012 sqlite3VdbeAddOp3(v, OP_Column, iCur, 0, regHasNull);
112030 pIn->pLeft = 0;
112118 ** then aiMap[] is populated with {2, 0, 1}.
112130 int eType = 0; /* Type of RHS table. IN_INDEX_* */
112136 mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
112143 ** set prRhsHasNull to 0 before continuing. */
112147 for(i=0; i<pEList->nExpr; i++){
112151 prRhsHasNull = 0;
112158 if( pParse->nErr==0 && (p = isCandidateForInOpt(pX))!=0 ){
112165 assert( p->pEList!=0 ); /* Because of isCandidateForInOpt(p) */
112166 assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */
112167 assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
112168 pTab = p->pSrc->a[0].pTab;
112172 assert( iDb>=0 && iDb<SQLITE_MAX_DB );
112174 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
112177 if( nExpr==1 && pEList->a[0].pExpr->iColumn<0 ){
112184 ExplainQueryPlan((pParse, 0,
112196 for(i=0; i<nExpr && affinity_ok; i++){
112220 for(pIdx=pTab->pIndex; pIdx && eType==0; pIdx=pIdx->pNext){
112224 if( pIdx->pPartIdxWhere!=0 ) continue;
112238 colUsed = 0; /* Columns of index used so far */
112239 for(i=0; i<nExpr; i++){
112245 for(j=0; j<nExpr; j++){
112248 if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){
112264 ExplainQueryPlan((pParse, 0,
112270 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
112276 iTab, 0, 0, (u8*)&mask, P4_INT64);
112297 if( eType==0
112307 if( eType==0 ){
112312 int rMayHaveNull = 0;
112315 pParse->nQueryLoop = 0;
112330 for(i=0; i<n; i++) aiMap[i] = i;
112349 Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0;
112356 for(i=0; i<nVal; i++){
112365 zRet[nVal] = '\0';
112379 if( pParse->nErr==0 ){
112436 int addrOnce = 0; /* Address of the OP_Once instruction at top */
112439 KeyInfo *pKeyInfo = 0; /* Key information */
112444 assert( v!=0 );
112456 if( !ExprHasProperty(pExpr, EP_VarSelect) && pParse->iSelfTab==0 ){
112464 ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d",
112482 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1;
112526 pSelect->iLimit = 0;
112528 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
112529 pCopy = sqlite3SelectDup(pParse->db, pSelect, 0);
112537 assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
112538 assert( pEList!=0 );
112539 assert( pEList->nExpr>0 );
112541 for(i=0; i<nVal; i++){
112548 }else if( ALWAYS(pExpr->x.pList!=0) ){
112569 pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
112575 for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
112587 addrOnce = 0;
112628 ** Return 0 if an error occurs.
112632 int addrOnce = 0; /* Address of OP_Once at top of subroutine */
112633 int rReg = 0; /* Register storing resulting */
112643 assert( v!=0 );
112644 if( pParse->nErr ) return 0;
112654 ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
112667 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1;
112687 ** If this is an EXISTS, write an integer 0 (not exists) or 1 (exists)
112697 sqlite3SelectDestInit(&dest, 0, pParse->nMem+1);
112703 sqlite3VdbeAddOp3(v, OP_Null, 0, dest.iSDParm, dest.iSDParm+nReg-1);
112707 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
112712 ** then make the new limit X<>0 so that the new limit is either 1 or 0 */
112714 pLimit = sqlite3Expr(db, TK_INTEGER, "0");
112718 sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit);
112725 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
112727 pSel->iLimit = 0;
112731 return 0;
112770 return 0;
112806 int rRhsHasNull = 0; /* Register that is true if RHS contains NULL values */
112811 int *aiMap = 0; /* Map from vector field to index column */
112812 char *zAff = 0; /* Affinity string for comparisons */
112818 int destStep6 = 0; /* Start of code for Step 6 */
112822 int iTab = 0; /* Index to use */
112840 assert( v!=0 ); /* OOM detected prior to this routine */
112844 destIfFalse==destIfNull ? 0 : &rRhsHasNull,
112851 /* Confirm that aiMap[] contains nVector integer values between 0 and
112853 for(i=0; i<nVector; i++){
112855 for(cnt=j=0; j<nVector; j++) if( aiMap[j]==i ) cnt++;
112873 pParse->okConstFactor = 0;
112876 for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */
112883 for(i=0; i<nVector; i++){
112884 sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0);
112899 int regCkNull = 0;
112908 for(ii=0; ii<pList->nExpr; ii++){
112922 sqlite3VdbeChangeP5(v, zAff[0]);
112930 sqlite3VdbeChangeP5(v, zAff[0] | SQLITE_JUMPIFNULL);
112951 for(i=0; i<nVector; i++){
112972 sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
112980 addrTruthOp = sqlite3VdbeAddOp4Int(v, OP_Found, iTab, 0,
113014 for(i=0; i<nVector; i++){
113026 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
113034 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
113052 ** value described by z[0..n-1] into register iMem.
113059 if( ALWAYS(z!=0) ){
113064 sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
113072 ** text z[0..n-1] into register iMem.
113080 assert( i>=0 );
113087 assert( z!=0 );
113094 if( sqlite3_strnicmp(z,"0x",2)==0 ){
113105 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64);
113127 pParse->iSelfTab = 0;
113148 assert( v!=0 );
113149 assert( pParse->iSelfTab!=0 );
113150 if( pParse->iSelfTab>0 ){
113151 iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
113153 iAddr = 0;
113157 sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
113175 assert( v!=0 );
113176 assert( pTab!=0 );
113178 if( iCol<0 || iCol==pTab->iPKey ){
113222 ** is called. If iColumn<0 then code is generated that extracts the rowid.
113232 assert( pParse->pVdbe!=0 );
113234 assert( IsVirtual(pTab) || (p5 & OPFLAG_NOCHNG)==0 );
113259 if( NEVER(p==0) ) return;
113274 ** to 0.
113282 *piFreeable = 0;
113285 iResult = 0;
113294 for(i=0; i<nResult; i++){
113324 assert( v!=0 );
113325 assert( pFarg!=0 );
113327 assert( nFarg>0 ); /* All in-line functions have at least one argument */
113337 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
113349 memset(&caseExpr, 0, sizeof(caseExpr));
113356 Expr *pArg = pFarg->a[0].pExpr;
113357 if( pArg->op==TK_COLUMN && pArg->iTable>=0 ){
113360 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
113370 target = sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target);
113383 sqlite3ExprCompare(0,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
113392 sqlite3ExprImpliesExpr(pParse,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
113404 sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable,1),
113407 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
113421 aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
113449 if( iDataCur<0 ) continue;
113454 if( sqlite3ExprCompare(0, pExpr, p->pExpr, iDataCur)!=0 ) continue;
113466 assert( v!=0 );
113476 sqlite3VdbeGoto(v, 0);
113478 pParse->pIdxEpr = 0;
113507 int addr = 0;
113514 sqlite3VdbeAddOp4(pParse->pVdbe, OP_Affinity, ret, 1, 0,
113523 return 0;
113542 int regFree1 = 0; /* If non-zero free this temporary register */
113543 int regFree2 = 0; /* If non-zero free this temporary register */
113546 int p5 = 0;
113548 assert( target>0 && target<=pParse->nMem );
113549 assert( v!=0 );
113552 if( pExpr==0 ){
113554 }else if( pParse->pIdxEpr!=0
113556 && (r1 = sqlite3IndexedExprLookup(pParse, pExpr, target))>=0
113568 assert( pAggInfo!=0 );
113569 assert( pExpr->iAgg>=0 );
113573 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
113589 if( pTab==0 ){
113591 }else if( pCol->iColumn<0 ){
113601 }else if( pExpr->y.pTab==0 ){
113623 assert( pExpr->y.pTab!=0 );
113629 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0,
113634 if( iTab<0 ){
113635 if( pParse->iSelfTab<0 ){
113639 ** 0-(pParse->iSelfTab). The rowid (if any) is in a register
113648 assert( pTab!=0 );
113651 if( iCol<0 ){
113662 return 0;
113686 && 0!=(r1 = exprPartidxExprLookup(pParse, pExpr, target))
113691 assert( pExpr->y.pTab!=0 );
113698 codeInteger(pParse, pExpr, 0, target);
113708 codeReal(v, pExpr->u.zToken, 0, target);
113723 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
113732 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
113738 sqlite3VdbeAddOp4(v, OP_Blob, n/2, target, 0, zBlob, P4_DYNAMIC);
113744 assert( pExpr->u.zToken!=0 );
113745 assert( pExpr->u.zToken[0]!=0 );
113759 sqlite3AffinityType(pExpr->u.zToken, 0));
113791 sqlite3VdbeAddOp2(v, OP_Integer, 0, inReg);
113795 testcase( regFree1==0 );
113796 testcase( regFree2==0 );
113826 testcase( regFree1==0 );
113827 testcase( regFree2==0 );
113845 tempX.u.iValue = 0;
113850 testcase( regFree2==0 );
113859 testcase( regFree1==0 );
113867 testcase( regFree1==0 );
113882 testcase( regFree1==0 );
113886 sqlite3VdbeAddOp2(v, OP_Integer, 0, target);
113892 if( pInfo==0
113893 || NEVER(pExpr->iAgg<0)
113908 u32 constMask = 0; /* Mask of function arguments that are constant */
113912 CollSeq *pColl = 0; /* A collating sequence */
113930 nFarg = pFarg ? pFarg->nExpr : 0;
113933 pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0);
113935 if( pDef==0 && pParse->explain ){
113936 pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0);
113939 if( pDef==0 || pDef->xFinalize!=0 ){
113943 if( (pDef->funcFlags & SQLITE_FUNC_INLINE)!=0 && ALWAYS(pFarg!=0) ){
113944 assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 );
113945 assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 );
113952 for(i=0; i<nFarg; i++){
113957 if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
113974 if( (pDef->funcFlags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
113977 assert( pFarg->a[0].pExpr!=0 );
113978 exprOp = pFarg->a[0].pExpr->op;
113987 pFarg->a[0].pExpr->op2 = pDef->funcFlags & OPFLAG_BYTELENARG;
113991 sqlite3ExprCodeExprList(pParse, pFarg, r1, 0, SQLITE_ECEL_FACTOR);
113993 r1 = 0;
114010 }else if( nFarg>0 ){
114011 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
114016 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
114021 if( constMask==0 ){
114036 return 0;
114050 if( pLeft->iTable==0 || pParse->withinRJSubrtn > pLeft->op2 ){
114065 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
114069 sqlite3VdbeAddOp2(v, OP_AddImm, target, 0);
114084 ** Y is stored in pExpr->pList->a[0].pExpr.
114088 exprCodeBetween(pParse, pExpr, target, 0, 0);
114118 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
114123 ** parameter is set to 0 for an old.rowid reference, or to (i+1)
114136 ** p1==0 -> old.rowid p1==3 -> new.rowid
114150 assert( pExpr->iTable==0 || pExpr->iTable==1 );
114152 assert( pTab->iPKey<0 || iCol!=pTab->iPKey );
114153 assert( p1>=0 && p1<(pTab->nCol*2+2) );
114158 (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[iCol].zCnName)
114167 if( iCol>=0 && pTab->aCol[iCol].affinity==SQLITE_AFF_REAL ){
114190 assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
114203 addrINR = sqlite3VdbeAddOp3(v, OP_IfNullRow, pExpr->iTable, 0, target);
114211 pParse->okConstFactor = 0; /* note (1) above */
114249 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
114250 Expr *pDel = 0;
114253 assert( ExprUseXList(pExpr) && pExpr->x.pList!=0 );
114254 assert(pExpr->x.pList->nExpr > 0);
114259 if( (pX = pExpr->pLeft)!=0 ){
114260 pDel = sqlite3ExprDup(db, pX, 0);
114267 testcase( regFree1==0 );
114268 memset(&opCompare, 0, sizeof(opCompare));
114276 regFree1 = 0;
114278 for(i=0; i<nExpr-1; i=i+2){
114280 assert( pTest!=0 );
114293 if( (nExpr&1)!=0 ){
114296 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
114313 return 0;
114321 v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
114326 pExpr->affExpr, pExpr->u.zToken, 0, 0);
114347 ** If regDest>0 then the result is always stored in that register and the
114348 ** result is not reusable. If regDest<0 then this routine is free to
114350 ** is stored is returned. When regDest<0, two identical expressions might
114362 assert( regDest!=0 );
114364 if( regDest<0 && p ){
114367 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
114369 && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0
114375 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
114376 if( pExpr!=0 && ExprHasProperty(pExpr, EP_HasFunc) ){
114381 pParse->okConstFactor = 0;
114383 if( regDest<0 ) regDest = ++pParse->nMem;
114393 pItem->fg.reusable = regDest<0;
114394 if( regDest<0 ) regDest = ++pParse->nMem;
114419 && ALWAYS(pExpr!=0)
114423 *pReg = 0;
114432 *pReg = 0;
114446 assert( pExpr==0 || !ExprHasVVAProperty(pExpr,EP_Immutable) );
114447 assert( target>0 && target<=pParse->nMem );
114448 assert( pParse->pVdbe!=0 || pParse->db->mallocFailed );
114449 if( pParse->pVdbe==0 ) return;
114473 pExpr = sqlite3ExprDup(db, pExpr, 0);
114507 ** ExprList.a[].u.x.iOrderByCol>0 have already been evaluated and stored
114509 ** If SQLITE_ECEL_OMITREF is also set, then the values with u.x.iOrderByCol>0
114523 assert( pList!=0 );
114524 assert( target>0 );
114525 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
114528 for(pItem=pList->a, i=0; i<n; i++, pItem++){
114536 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
114543 }else if( (flags & SQLITE_ECEL_FACTOR)!=0
114555 && pOp->p5==0 /* The do-not-merge flag must be clear */
114597 int regFree1 = 0; /* Temporary use register */
114598 Expr *pDel = 0;
114601 memset(&compLeft, 0, sizeof(Expr));
114602 memset(&compRight, 0, sizeof(Expr));
114603 memset(&exprAnd, 0, sizeof(Expr));
114606 pDel = sqlite3ExprDup(db, pExpr->pLeft, 0);
114607 if( db->mallocFailed==0 ){
114613 compLeft.pRight = pExpr->x.pList->a[0].pExpr;
114634 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull==0 && regFree1==0 );
114635 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull==0 && regFree1!=0 );
114636 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull!=0 && regFree1==0 );
114637 testcase( xJump==sqlite3ExprIfTrue && jumpIfNull!=0 && regFree1!=0 );
114638 testcase( xJump==sqlite3ExprIfFalse && jumpIfNull==0 && regFree1==0 );
114639 testcase( xJump==sqlite3ExprIfFalse && jumpIfNull==0 && regFree1!=0 );
114640 testcase( xJump==sqlite3ExprIfFalse && jumpIfNull!=0 && regFree1==0 );
114641 testcase( xJump==sqlite3ExprIfFalse && jumpIfNull!=0 && regFree1!=0 );
114642 testcase( xJump==0 );
114661 int op = 0;
114662 int regFree1 = 0;
114663 int regFree2 = 0;
114666 assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
114667 if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
114668 if( NEVER(pExpr==0) ) return; /* No way this can happen */
114679 testcase( jumpIfNull==0 );
114685 testcase( jumpIfNull==0 );
114692 testcase( jumpIfNull==0 );
114699 testcase( jumpIfNull==0 );
114706 isNot ? SQLITE_JUMPIFNULL : 0);
114709 isNot ? SQLITE_JUMPIFNULL : 0);
114727 testcase( jumpIfNull==0 );
114742 testcase( regFree1==0 );
114743 testcase( regFree2==0 );
114755 testcase( regFree1==0 );
114759 testcase( jumpIfNull==0 );
114781 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
114783 testcase( regFree1==0 );
114784 testcase( jumpIfNull==0 );
114800 ** is 0.
114804 int op = 0;
114805 int regFree1 = 0;
114806 int regFree2 = 0;
114809 assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
114810 if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
114811 if( pExpr==0 ) return;
114852 testcase( jumpIfNull==0 );
114857 testcase( jumpIfNull==0 );
114866 testcase( jumpIfNull==0 );
114873 testcase( jumpIfNull==0 );
114881 isNot ? 0 : SQLITE_JUMPIFNULL);
114886 isNot ? 0 : SQLITE_JUMPIFNULL);
114904 testcase( jumpIfNull==0 );
114919 testcase( regFree1==0 );
114920 testcase( regFree2==0 );
114930 testcase( regFree1==0 );
114934 testcase( jumpIfNull==0 );
114958 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
114960 testcase( regFree1==0 );
114961 testcase( jumpIfNull==0 );
114977 Expr *pCopy = sqlite3ExprDup(db, pExpr, 0);
114978 if( db->mallocFailed==0 ){
115002 int res = 0;
115004 sqlite3_value *pL, *pR = 0;
115015 res = 0==sqlite3MemCompare(pL, pR, 0);
115025 ** Do a deep comparison of two expression trees. Return 0 if the two
115034 ** not using TK_REGISTER but is otherwise equivalent, then still return 0.
115040 ** expressions are the same. But if you get a 0 or 1 return, then you
115044 ** an incorrect 0 or 1 could lead to a malfunction.
115060 if( pA==0 || pB==0 ){
115061 return pB==pA ? 0 : 2;
115064 return 0;
115068 if( (pA->flags&pB->flags&EP_IntValue)!=0 && pA->u.iValue==pB->u.iValue ){
115069 return 0;
115081 && pB->iTable<0 && pA->iTable==iTab
115092 if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
115099 if( sqlite3WindowCompare(pParse, pA->y.pWin, pB->y.pWin, 1)!=0 ){
115105 return 0;
115107 if( sqlite3_stricmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
115109 if( pB->u.zToken!=0
115112 && strcmp(pA->u.zToken,pB->u.zToken)!=0
115119 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
115121 if( (combinedFlags & EP_FixedCol)==0
115127 && ALWAYS((combinedFlags & EP_Reduced)==0)
115136 return 0;
115140 ** Compare two ExprList objects. Return 0 if they are identical, 1
115149 ** must never return 0 if the two ExprList objects are different, or
115157 if( pA==0 && pB==0 ) return 0;
115158 if( pA==0 || pB==0 ) return 1;
115160 for(i=0; i<pA->nExpr; i++){
115165 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
115167 return 0;
115175 return sqlite3ExprCompare(0,
115196 if( sqlite3ExprCompare(pParse, p, pNN, iTab)==0 ){
115201 if( seenNot && ExprHasProperty(p, EP_xIsSelect) ) return 0;
115202 assert( ExprUseXSelect(p) || (p->x.pList!=0 && p->x.pList->nExpr>0) );
115209 assert( pList!=0 );
115211 if( seenNot ) return 0;
115212 if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, 1)
115247 if( seenNot ) return 0;
115248 if( p->op2!=TK_IS ) return 0;
115256 return 0;
115265 ** pE1: x>0 pE2: x==5 Result: false
115273 ** Expr.iTable<0 then assume a table number given by iTab.
115290 if( sqlite3ExprCompare(pParse, pE1, pE2, iTab)==0 ){
115300 && exprImpliesNotNull(pParse, pE1, pE2->pLeft, iTab, 0)
115304 return 0;
115312 if( pWalker->eCode==0 ){
115315 pWalker->eCode = 0;
115391 if( ExprUseXList(pExpr) && ALWAYS(pExpr->x.pList->nExpr>0) ){
115402 bothImplyNotNullRow(pWalker, pExpr->x.pList->a[0].pExpr,
115423 /* The y.pTab=0 assignment in wherecode.c always happens after the
115428 && ALWAYS(pLeft->y.pTab!=0)
115431 && ALWAYS(pRight->y.pTab!=0)
115468 if( p==0 ) return 0;
115478 w.xSelectCallback = 0;
115479 w.xSelectCallback2 = 0;
115480 w.eCode = 0;
115481 w.mWFlags = isRJ!=0;
115507 && sqlite3TableColumnToIndex(pWalker->u.pIdxCover->pIdx, pExpr->iColumn)<0
115532 memset(&w, 0, sizeof(w));
115565 if( pSrc->nSrc==0 ) return WRC_Continue;
115569 if( piNew==0 ){
115570 p->nExclude = 0;
115575 for(i=0; i<pSrc->nSrc; i++, j++){
115591 ** Set the 0x01 bit of pWalker->eCode if there is a reference to any
115594 ** Set the 0x02 bit of pWalker->eCode if there is a reference to a
115604 int nSrc = pSrc ? pSrc->nSrc : 0;
115605 for(i=0; i<nSrc; i++){
115611 for(i=0; i<p->nExclude && p->aiExclude[i]!=pExpr->iTable; i++){}
115625 ** 0 pExpr references some table that is not defined in either
115637 assert( pParse->db!=0 );
115638 memset(&w, 0, sizeof(w));
115639 memset(&x, 0, sizeof(x));
115652 assert( pExpr->pLeft->x.pList!=0 );
115661 if( w.eCode & 0x01 ){
115664 return 0;
115683 && pExpr->pAggInfo!=0
115689 assert( iAgg>=0 );
115694 pExpr = sqlite3ExprDup(db, pExpr, 0);
115704 pExpr = sqlite3ExprDup(db, pExpr, 0);
115719 memset(pWalker, 0, sizeof(*pWalker));
115734 sizeof(pInfo->aCol[0]),
115750 sizeof(pInfo->aFunc[0]),
115772 assert( pAggInfo->iFirstReg==0 );
115774 for(k=0; k<pAggInfo->nColumn; k++, pCol++){
115784 if( k<0 ){
115801 for(j=0; j<n; j++, pTerm++){
115812 if( pCol->iSorterColumn<0 ){
115817 assert( pExpr->pAggInfo==0 || pExpr->pAggInfo==pAggInfo );
115838 assert( pAggInfo->iFirstReg==0 );
115843 assert( pParse->iSelfTab==0 );
115844 if( (pNC->ncFlags & NC_InAggFunc)==0 ) break;
115845 if( pParse->pIdxEpr==0 ) break;
115848 if( iDataCur<0 ) continue;
115849 if( sqlite3ExprCompare(0, pExpr, pIEpr->pExpr, iDataCur)==0 ) break;
115851 if( pIEpr==0 ) break;
115853 for(i=0; i<pSrcList->nSrc; i++){
115854 if( pSrcList->a[0].iCursor==pIEpr->iDataCur ) break;
115857 if( NEVER(pExpr->pAggInfo!=0) ) break; /* Resolved by outer context */
115864 memset(&tmp, 0, sizeof(tmp));
115870 assert( pAggInfo->aCol!=0 );
115885 if( ALWAYS(pSrcList!=0) ){
115887 for(i=0; i<pSrcList->nSrc; i++, pItem++){
115898 if( (pNC->ncFlags & NC_InAggFunc)==0
115900 && pExpr->pAggInfo==0
115906 for(i=0; i<pAggInfo->nFunc; i++, pItem++){
115908 if( sqlite3ExprCompare(0, pItem->pFExpr, pExpr, -1)==0 ){
115917 if( i>=0 ){
115923 nArg = pExpr->x.pList ? pExpr->x.pList->nExpr : 0;
115925 pExpr->u.zToken, nArg, enc, 0);
115926 assert( pItem->bOBUnique==0 );
115928 && (pItem->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)==0
115933 assert( nArg>0 );
115938 assert( pOBList->nExpr>0 );
115939 assert( pItem->bOBUnique==0 );
115942 && sqlite3ExprCompare(0,pOBList->a[0].pExpr,
115943 pExpr->x.pList->a[0].pExpr,0)==0
115945 pItem->bOBPayload = 0;
115951 (pItem->pFunc->funcFlags & SQLITE_SUBTYPE)!=0;
115991 w.walkerDepth = 0;
115993 w.pParse = 0;
115994 assert( pNC->pSrcList!=0 );
116008 for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
116018 if( pParse->nTempReg==0 ){
116030 sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0, 0);
116059 sqlite3VdbeReleaseRegisters(pParse, iReg, nReg, 0, 0);
116075 pParse->nTempReg = 0;
116076 pParse->nRangeReg = 0;
116098 for(i=0; i<pList->nExpr; i++){
116104 pParse->nTempReg = 0;
116105 pParse->nRangeReg = 0;
116118 if( pParse->nRangeReg>0
116122 return 0;
116124 for(i=0; i<pParse->nTempReg; i++){
116126 return 0;
116131 for(i=0; i<pList->nExpr; i++){
116133 if( iReg==0 ) continue;
116134 if( iReg>=iFirst && iReg<=iLast ) return 0;
116174 if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)
116176 || (pTab->tabFlags & TF_Eponymous)!=0
116177 || ( (pTab->tabFlags & TF_Shadow)!=0
116185 return 0;
116213 if( bTemp==0 ){
116239 if( bTemp==0 ){
116257 sqlite3VdbeAddParseSchemaOp(pParse->pVdbe, iDb, 0, p5);
116258 if( iDb!=1 ) sqlite3VdbeAddParseSchemaOp(pParse->pVdbe, 1, 0, p5);
116274 char *zName = 0; /* NULL-terminated version of pName */
116279 VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */
116285 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
116325 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
116336 if( pVTab->pVtab->pModule->xRename==0 ){
116337 pVTab = 0;
116347 if( v==0 ){
116404 " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename', 0) "
116419 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
116424 renameTestSchema(pParse, zDb, iDb==1, "after rename", 0);
116471 assert( db->mallocFailed==0 );
116486 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
116505 if( (pCol->colFlags & COLFLAG_GENERATED)==0 ){
116507 ** literal NULL, then set pDflt to 0. This simplifies checking
116510 assert( pDflt==0 || pDflt->op==TK_SPAN );
116512 pDflt = 0;
116529 sqlite3_value *pVal = 0;
116553 *zEnd-- = '\0';
116589 if( pNew->pCheck!=0
116590 || (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0)
116591 || (pTab->tabFlags & TF_Strict)!=0
116634 assert( pParse->pNewTable==0 );
116637 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
116658 assert( pTab->u.tab.addColOffset>0 );
116673 assert( pNew->nCol>0 );
116675 assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
116683 for(i=0; i<pNew->nCol; i++){
116689 pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0);
116709 const char *zType = 0;
116727 return 0;
116730 # define isRealTable(x,y,z) (0)
116747 char *zOld = 0; /* Old column name */
116748 char *zNew = 0; /* New column name */
116754 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
116759 if( SQLITE_OK!=isRealTable(pParse, pTab, 0) ) goto exit_rename_column;
116763 assert( iSchema>=0 );
116768 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
116777 for(iCol=0; iCol<pTab->nCol; iCol++){
116778 if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break;
116786 renameTestSchema(pParse, zDb, iSchema==1, "", 0);
116796 assert( pNew->n>0 );
116797 bQuote = sqlite3Isquote(pNew->z[0]);
116888 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
116889 if( pParse->nErr==0 ){
116898 assert( i>0 );
116959 sqlite3RenameTokenRemap(pParse, 0, (const void*)pExpr);
116961 sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab);
116975 With *pCopy = 0;
116976 assert( pWith->nCte>0 );
116977 if( (pWith->a[0].pSelect->selFlags & SF_Expanded)==0 ){
116986 for(i=0; i<pWith->nCte; i++){
116989 memset(&sNC, 0, sizeof(sNC));
117010 assert( pIdList!=0 );
117011 for(ii=0; ii<pIdList->nId; ii++){
117012 sqlite3RenameTokenRemap(pParse, 0, (const void*)pIdList->a[ii].zName);
117030 for(i=0; i<pList->nExpr; i++){
117032 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
117038 for(i=0; i<pSrc->nSrc; i++){
117039 sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
117040 if( pSrc->a[i].fg.isUsing==0 ){
117058 memset(&sWalker, 0, sizeof(Walker));
117075 memset(&sWalker, 0, sizeof(Walker));
117079 for(i=0; i<pEList->nExpr; i++){
117081 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
117114 if( NEVER(pPtr==0) ){
117115 return 0;
117129 return 0;
117215 zT, zN, (zWhen[0] ? " " : ""), zWhen,
117236 for(i=0; i<pEList->nExpr; i++){
117239 && ALWAYS(zName!=0)
117240 && 0==sqlite3_stricmp(zName, zOld)
117261 for(i=0; i<pIdList->nId; i++){
117263 if( 0==sqlite3_stricmp(zName, zOld) ){
117285 if( zSql==0 ){
117288 if( sqlite3StrNICmp(zSql,"CREATE ",7)!=0 ){
117298 && NEVER(p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0)
117315 db->init.iDb = 0;
117339 char *zQuot = 0;
117341 i64 nQuot = 0;
117342 char *zBuf1 = 0;
117343 char *zBuf2 = 0;
117352 if( zQuot==0 ){
117382 if( bQuote==0 && sqlite3IsIdChar(*pBest->t.z) ){
117398 zBuf1[pBest->t.n] = 0;
117413 zOut[nOut] = '\0';
117435 for(i=0; i<pEList->nExpr; i++){
117455 memset(&sNC, 0, sizeof(sNC));
117465 rc = sqlite3ViewGetColumnNames(pParse, pParse->pTriggerTab)!=0;
117482 pParse, pStep->pExprList, pSrc, 0, 0, 0, 0, 0, 0
117484 if( pSel==0 ){
117485 pStep->pExprList = 0;
117486 pSrc = 0;
117498 sqlite3SelectPrep(pParse, pSel, 0);
117501 assert( pStep->pExprList==0 || pStep->pExprList==pSel->pEList );
117503 if( pStep->pExprList ) pSel->pEList = 0;
117504 pSel->pSrc = 0;
117509 for(i=0; i<pStep->pFrom->nSrc && rc==SQLITE_OK; i++){
117512 sqlite3SelectPrep(pParse, p->pSelect, 0);
117544 sNC.ncFlags = 0;
117546 sNC.pSrcList = 0;
117580 for(i=0; i<pStep->pFrom->nSrc; i++){
117598 while( (pIdx = pParse->pNewIndex)!=0 ){
117613 ** 0. zSql: SQL statement to rewrite
117624 ** The iCol-th column (left-most is 0) of table zTable is renamed from zCol
117639 const char *zSql = (const char*)sqlite3_value_text(argv[0]);
117658 if( zSql==0 ) return;
117659 if( zTable==0 ) return;
117660 if( zNew==0 ) return;
117661 if( iCol<0 ) return;
117664 if( pTab==0 || iCol>=pTab->nCol ){
117669 memset(&sCtx, 0, sizeof(sCtx));
117673 db->xAuth = 0;
117678 memset(&sWalker, 0, sizeof(Walker));
117691 sqlite3SelectPrep(&sParse, pSelect, 0);
117702 if( bFKOnly==0 ){
117708 if( sCtx.iCol<0 ){
117719 for(i=0; i<sParse.pNewTable->nCol; i++){
117729 for(i=0; i<pFKey->nCol; i++){
117730 if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
117733 if( 0==sqlite3_stricmp(pFKey->zTo, zTable)
117734 && 0==sqlite3_stricmp(pFKey->aCol[i].zCol, zOld)
117752 Table *pTarget = sqlite3LocateTable(&sParse, 0, pStep->zTarget, zDb);
117780 sqlite3_result_value(context, argv[0]);
117822 if( NEVER(pSrc==0) ){
117826 for(i=0; i<pSrc->nSrc; i++){
117844 ** 0: The database containing the table being renamed.
117854 ** sqlite_rename_table('main', 'CREATE TABLE t1(a REFERENCES t2)','t2','t3',0)
117863 const char *zDb = (const char*)sqlite3_value_text(argv[0]);
117879 db->xAuth = 0;
117884 memset(&sCtx, 0, sizeof(RenameCtx));
117886 memset(&sWalker, 0, sizeof(Walker));
117900 if( isLegacy==0 ){
117903 memset(&sNC, 0, sizeof(sNC));
117918 if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys))
117924 if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
117934 if( sqlite3_stricmp(zOld, pTab->zName)==0 ){
117936 if( isLegacy==0 ){
117946 if( isLegacy==0 ){
117955 if( 0==sqlite3_stricmp(sParse.pNewTrigger->table, zOld)
117961 if( isLegacy==0 ){
117966 if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){
117971 for(i=0; i<pStep->pFrom->nSrc; i++){
117973 if( 0==sqlite3_stricmp(pItem->zName, zOld) ){
118023 ** 0: Database name ("main", "temp" etc.).
118049 char const *zDb = (const char*)sqlite3_value_text(argv[0]);
118054 db->xAuth = 0;
118063 rc = renameParseSql(&sParse, zDb, db, zInput, 0);
118070 memset(&sCtx, 0, sizeof(RenameCtx));
118071 memset(&sWalker, 0, sizeof(Walker));
118082 sqlite3SelectPrep(&sParse, pSelect, 0);
118091 for(i=0; i<sParse.pNewTable->nCol; i++){
118111 rc = renameEditSql(context, &sCtx, zInput, 0, 0);
118140 ** 0: Database name ("main", "temp" etc.).
118162 char const *zDb = (const char*)sqlite3_value_text(argv[0]);
118171 db->xAuth = 0;
118184 if( isLegacy==0 && sParse.pNewTable && IsView(sParse.pNewTable) ){
118186 memset(&sNC, 0, sizeof(sNC));
118193 if( isLegacy==0 ){
118224 ** argv[0]: An integer - the index of the schema containing the table
118237 int iSchema = sqlite3_value_int(argv[0]);
118246 char *zNew = 0;
118250 db->xAuth = 0;
118257 if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
118263 pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zCnName);
118266 pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName);
118271 while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
118301 char *zCol = 0; /* Name of column to drop */
118305 assert( pParse->pNewTable==0 );
118308 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
118318 if( zCol==0 ){
118323 if( iCol<0 ){
118346 assert( iDb>=0 );
118354 renameTestSchema(pParse, zDb, iDb==1, "", 0);
118368 if( pParse->nErr==0 && (pTab->aCol[iCol].colFlags & COLFLAG_VIRTUAL)==0 ){
118373 Index *pPk = 0;
118374 int nField = 0; /* Number of non-virtual columns after drop */
118387 for(i=0; i<pPk->nKeyCol; i++){
118393 for(i=0; i<pTab->nCol; i++){
118394 if( i!=iCol && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
118405 sqlite3VdbeAddOp2(v, OP_Null, 0, regOut);
118417 if( nField==0 ){
118420 sqlite3VdbeAddOp2(v, OP_Null, 0, reg+1);
118486 ** created and used by SQLite versions 3.7.9 through 3.29.0 when
118533 ** The sqlite_stat2 entries for an index that have sampleno between 0 and 9
118541 ** For i between 0 and S-1. Conceptually, the index space is divided into
118604 # define IsStat4 0
118620 ** If zWhere==0, then code is generated to delete all stat table entries.
118637 { "sqlite_stat4", 0 },
118639 { "sqlite_stat3", 0 },
118653 if( v==0 ) return;
118661 for(i=0; i<ArraySize(aTable); i++){
118664 aCreateTbl[i] = 0;
118665 if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){
118700 for(i=0; i<nToOpen; i++){
118753 int nMaxEqZero; /* Max leading 0 in anEq[] for any a[] entry */
118763 assert( db!=0 );
118766 p->nRowid = 0;
118775 assert( db!=0 );
118782 p->nRowid = 0;
118791 assert( db!=0 );
118793 p->nRowid = 0;
118826 for(i=0; i<p->nCol; i++) sampleClear(p->db, p->aBest+i);
118827 for(i=0; i<p->mxSample; i++) sampleClear(p->db, p->a+i);
118840 ** L: A limit on the number of rows to scan, or 0 for no-limit
118868 /* Maximum number of samples. 0 if STAT4 data is not collected */
118869 int mxSample = OptimizationEnabled(db,SQLITE_Stat4) ?SQLITE_STAT4_SAMPLES :0;
118874 nCol = sqlite3_value_int(argv[0]);
118875 assert( nCol>0 );
118879 assert( nKeyCol>0 );
118893 if( p==0 ){
118900 p->nRow = 0;
118904 p->nSkipAhead = 0;
118909 p->mxSample = p->nLimit==0 ? mxSample : 0;
118917 p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]);
118923 for(i=0; i<(mxSample+nCol); i++){
118930 for(i=0; i<nCol; i++){
118945 0, /* pUserData */
118946 0, /* pNext */
118948 0, /* xFinalize */
118949 0, 0, /* xValue, xInverse */
118951 {0}
118976 if( pNew->anEq[i]<pOld->anEq[i] ) return 0;
118979 return 0;
118998 assert( pOld->isPSample==0 && pNew->isPSample==0 );
118999 assert( IsStat4 || (pNew->iCol==0 && pOld->iCol==0) );
119006 return 0;
119014 StatSample *pSample = 0;
119017 assert( IsStat4 || nEqZero==0 );
119019 /* StatAccum.nMaxEqZero is set to the maximum number of leading 0
119022 ** are no samples with StatSample.anEq[m]==0 for (m>=n). */
119026 if( pNew->isPSample==0 ){
119027 StatSample *pUpgrade = 0;
119028 assert( pNew->anEq[pNew->iCol]>0 );
119035 for(i=p->nSample-1; i>=0; i--){
119037 if( pOld->anEq[pNew->iCol]==0 ){
119041 if( pUpgrade==0 || sampleIsBetter(p, pOld, pUpgrade) ){
119060 memmove(pMin, &pMin[1], sizeof(p->a[0])*(p->nSample-p->iMin-1));
119062 pSample->nRowid = 0;
119072 assert( p->nSample==0
119081 memset(pSample->anEq, 0, sizeof(tRowcnt)*nEqZero);
119086 for(i=0; i<p->mxSample; i++){
119088 if( iMin<0 || sampleIsBetter(p, &p->a[iMin], &p->a[i]) ){
119092 assert( iMin>=0 );
119120 for(i=p->nSample-1; i>=0; i--){
119122 for(j=p->nMaxEqZero; j<p->nCol; j++) assert( p->a[i].anEq[j]>0 );
119127 for(i=p->nSample-1; i>=0; i--){
119130 if( p->a[i].anEq[j]==0 ) p->a[i].anEq[j] = p->current.anEq[j];
119165 StatAccum *p = (StatAccum*)sqlite3_value_blob(argv[0]);
119170 assert( p->nCol>0 );
119173 if( p->nRow==0 ){
119176 for(i=0; i<p->nCol; i++) p->current.anEq[i] = 1;
119187 for(i=0; i<iChng; i++){
119216 p->current.iCol = 0;
119218 p->current.isPSample = 0;
119222 for(i=0; i<(p->nCol-1); i++){
119232 sqlite3_result_int(context, p->current.anDLt[0]>0);
119239 0, /* pUserData */
119240 0, /* pNext */
119242 0, /* xFinalize */
119243 0, 0, /* xValue, xInverse */
119245 {0}
119248 #define STAT_GET_STAT1 0 /* "stat" column of stat1 table */
119278 StatAccum *p = (StatAccum*)sqlite3_value_blob(argv[0]);
119322 sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
119325 for(i=0; i<p->nKeyCol; i++){
119331 assert( p->current.anEq[i] || p->nRow==0 );
119338 if( p->iGet<0 ){
119339 samplePushPrevious(p, 0);
119340 p->iGet = 0;
119344 if( pS->nRowid==0 ){
119352 tRowcnt *aCnt = 0;
119366 sqlite3StrAccumInit(&sStat, 0, 0, 0, p->nCol*100);
119367 for(i=0; i<p->nCol; i++){
119381 0, /* pUserData */
119382 0, /* pNext */
119384 0, /* xFinalize */
119385 0, 0, /* xValue, xInverse */
119387 {0}
119399 sqlite3VdbeAddFunctionCall(pParse, 0, regStat, regOut, 1+IsStat4,
119400 &statGetFuncdef, 0);
119413 assert( k>=0 && k<pIdx->nColumn );
119463 Table *pStat1 = 0;
119469 if( v==0 || NEVER(pTab==0) ){
119476 if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){
119482 assert( iDb>=0 );
119483 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
119485 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
119494 if( pStat1==0 ) return;
119499 sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNAMIC);
119507 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
119522 if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0;
119540 ** regChng = 0
119543 ** stat_init() with count = 0;
119551 ** regChng = 0
119552 ** if( idx(0) != regPrev(0) ) goto chng_addr_0
119560 ** regPrev(0) = idx(0)
119588 ** regChng = 0
119591 ** stat_init() with count = 0;
119611 sqlite3VdbeAddFunctionCall(pParse, 0, regStat+1, regStat, 4,
119612 &statInitFuncdef, 0);
119616 sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
119619 if( nColTest>0 ){
119623 if( aGotoChng==0 ) continue;
119627 ** regChng = 0
119628 ** if( idx(0) != regPrev(0) ) goto chng_addr_0
119644 for(i=0; i<nColTest; i++){
119650 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
119660 ** regPrev(0) = idx(0)
119666 for(i=0; i<nColTest; i++){
119691 for(j=0; j<pPk->nKeyCol; j++){
119693 assert( k>=0 && k<pIdx->nColumn );
119705 &statPushFuncdef, 0);
119710 j3 = sqlite3VdbeAddOp4Int(v, OP_SeekGT, iIdxCur, 0, regPrev, 1);
119726 addrGotoEnd = 0;
119729 assert( "BBB"[0]==SQLITE_AFF_TEXT );
119730 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
119740 if( OptimizationEnabled(db, SQLITE_Stat4) && db->nAnalysisLimit==0 ){
119752 if( addrGotoEnd==0 ){
119775 doOnce = 0;
119795 sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
119797 for(i=0; i<nCol; i++){
119817 if( pOnlyIdx==0 && needTableCnt ){
119821 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
119822 assert( "BBB"[0]==SQLITE_AFF_TEXT );
119823 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
119857 sqlite3BeginWriteOperation(pParse, 0, iDb);
119860 openStatTable(pParse, iDb, iStatCur, 0, 0);
119863 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
119866 analyzeOneTable(pParse, pTab, 0, iStatCur, iMem, iTab);
119885 assert( pTab!=0 );
119888 sqlite3BeginWriteOperation(pParse, 0, iDb);
119929 assert( pName2!=0 || pName1==0 );
119930 if( pName1==0 ){
119932 for(i=0; i<db->nDb; i++){
119936 }else if( pName2->n==0 && (iDb = sqlite3FindDb(db, pName1))>=0 ){
119942 if( iDb>=0 ){
119943 zDb = pName2->n ? db->aDb[iDb].zDbSName : 0;
119946 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
119948 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
119949 analyzeTable(pParse, pTab, 0);
119955 if( db->nSqlExec==0 && (v = sqlite3GetVdbe(pParse))!=0 ){
119979 LogEst *aLog, /* Or, if aOut==0, here */
119988 if( z==0 ) z = "";
119990 assert( z!=0 );
119992 for(i=0; *z && i<nOut; i++){
119993 v = 0;
119994 while( (c=z[0])>='0' && c<='9' ){
119995 v = v*10 + c - '0';
120002 assert( aOut==0 );
120004 assert( aLog!=0 );
120010 assert( pIndex!=0 ); {
120014 pIndex->bUnordered = 0;
120015 pIndex->noSkipScan = 0;
120016 while( z[0] ){
120017 if( sqlite3_strglob("unordered*", z)==0 ){
120019 }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
120023 }else if( sqlite3_strglob("noskipscan*", z)==0 ){
120027 else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){
120031 while( z[0]!=0 && z[0]!=' ' ) z++;
120032 while( z[0]==' ' ) z++;
120039 if( aLog[0] > 66 /* Index has more than 100 rows */
120040 && aLog[0] <= aLog[nOut-1] /* And only a single value seen */
120051 ** argv[0] = name of the table
120067 if( argv==0 || argv[0]==0 || argv[2]==0 ){
120068 return 0;
120070 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
120071 if( pTable==0 ){
120072 return 0;
120074 if( argv[1]==0 ){
120075 pIndex = 0;
120076 }else if( sqlite3_stricmp(argv[0],argv[1])==0 ){
120084 tRowcnt *aiRowEst = 0;
120090 if( pIndex->aiRowEst==0 ){
120092 if( pIndex->aiRowEst==0 ) sqlite3OomFault(pInfo->db);
120096 pIndex->bUnordered = 0;
120099 if( pIndex->pPartIdxWhere==0 ){
120100 pTable->nRowLogEst = pIndex->aiRowLogEst[0];
120109 decodeIntArray((char*)z, 1, 0, &pTable->nRowLogEst, &fakeIdx);
120114 return 0;
120122 assert( db!=0 );
120123 assert( pIdx!=0 );
120127 for(j=0; j<pIdx->nSample; j++){
120133 if( db->pnBytesFreed==0 ){
120134 pIdx->nSample = 0;
120135 pIdx->aSample = 0;
120162 for(iCol=0; iCol<nCol; iCol++){
120165 tRowcnt sumEq = 0; /* Sum of the nEq values */
120166 tRowcnt avgEq = 0;
120168 i64 nSum100 = 0; /* Number of terms contributing to sumEq */
120171 if( !pIdx->aiRowEst || iCol>=pIdx->nKeyCol || pIdx->aiRowEst[iCol+1]==0 ){
120176 nRow = pIdx->aiRowEst[0];
120177 nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
120185 for(i=0; i<nSample; i++){
120197 if( avgEq==0 ) avgEq = 1;
120213 if( pIdx==0 ){
120239 sqlite3_stmt *pStmt = 0; /* An SQL statement being run */
120241 Index *pPrevIdx = 0; /* Previous index in the loop */
120249 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
120263 zIndex = (char *)sqlite3_column_text(pStmt, 0);
120264 if( zIndex==0 ) continue;
120267 assert( pIdx==0 || pIdx->nSample==0 );
120268 if( pIdx==0 ) continue;
120269 if( pIdx->aSample!=0 ){
120286 if( pIdx->aSample==0 ){
120293 for(i=0; i<nSample; i++){
120307 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
120316 zIndex = (char *)sqlite3_column_text(pStmt, 0);
120317 if( zIndex==0 ) continue;
120319 if( pIdx==0 ) continue;
120333 decodeIntArray((char*)sqlite3_column_text(pStmt,1),nCol,pSample->anEq,0,0);
120334 decodeIntArray((char*)sqlite3_column_text(pStmt,2),nCol,pSample->anLt,0,0);
120335 decodeIntArray((char*)sqlite3_column_text(pStmt,3),nCol,pSample->anDLt,0,0);
120337 /* Take a copy of the sample. Add 8 extra 0x00 bytes the end of the buffer.
120342 ** buffer. In any case, eight 0x00 bytes prevents this from causing
120346 if( pSample->p==0 ){
120370 && (pStat4 = sqlite3FindTable(db, "sqlite_stat4", zDb))!=0
120411 assert( iDb>=0 && iDb<db->nDb );
120412 assert( db->aDb[iDb].pBt!=0 );
120415 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
120422 pIdx->hasStat1 = 0;
120425 pIdx->aSample = 0;
120437 if( zSql==0 ){
120440 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
120446 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
120462 pIdx->aiRowEst = 0;
120530 sqlite3StrICmp(db->aDb[iDb].zDbSName, zName)==0
120531 || (iDb==0 && sqlite3StrICmp("main", zName)==0)
120556 int rc = 0;
120560 char *zPath = 0;
120561 char *zErr = 0;
120564 Db *pNew = 0; /* Db object for the newly attached database */
120565 char *zErrDyn = 0;
120569 zFile = (const char *)sqlite3_value_text(argv[0]);
120571 if( zFile==0 ) zFile = "";
120572 if( zName==0 ) zName = "";
120577 # define REOPEN_AS_MEMDB(db) (0)
120584 Btree *pNewBt = 0;
120586 if( pVfs==0 ) return;
120587 rc = sqlite3BtreeOpen(pVfs, "x\0", db, &pNewBt, 0, SQLITE_OPEN_MAIN_DB);
120619 for(i=0; i<db->nDb; i++){
120631 aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 );
120632 if( aNew==0 ) return;
120633 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
120635 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
120636 if( aNew==0 ) return;
120640 memset(pNew, 0, sizeof(*pNew));
120656 rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags);
120660 db->noSharedCache = 0;
120678 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
120686 if( rc==SQLITE_OK && pNew->zDbSName==0 ){
120698 db->init.iDb = 0;
120704 assert( zErrDyn==0 || rc!=SQLITE_OK );
120708 u8 newAuth = 0;
120721 db->aDb[iDb].pBt = 0;
120722 db->aDb[iDb].pSchema = 0;
120730 }else if( zErrDyn==0 ){
120761 const char *zName = (const char *)sqlite3_value_text(argv[0]);
120764 Db *pDb = 0;
120770 if( zName==0 ) zName = "";
120771 for(i=0; i<db->nDb; i++){
120773 if( pDb->pBt==0 ) continue;
120805 pDb->pBt = 0;
120806 pDb->pSchema = 0;
120836 memset(&sName, 0, sizeof(NameContext));
120854 zAuthArg = 0;
120856 rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
120872 sqlite3VdbeAddFunctionCall(pParse, 0, regArgs+3-pFunc->nArg, regArgs+3,
120873 pFunc->nArg, pFunc, 0);
120896 0, /* pUserData */
120897 0, /* pNext */
120899 0, /* xFinalize */
120900 0, 0, /* xValue, xInverse */
120902 {0}
120904 codeAttach(pParse, SQLITE_DETACH, &detach_func, pDbname, 0, 0, pDbname);
120916 0, /* pUserData */
120917 0, /* pNext */
120919 0, /* xFinalize */
120920 0, 0, /* xValue, xInverse */
120922 {0}
120956 if( NEVER(pList==0) ) return WRC_Continue;
120957 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
120958 if( pFix->bTemp==0 ){
120967 pItem->zDatabase = 0;
120974 if( pList->a[i].fg.isUsing==0
120982 for(i=0; i<pSelect->pWith->nCte; i++){
121014 pFix->w.walkerDepth = 0;
121015 pFix->w.eCode = 0;
121031 ** checks out, these routines return 0.
121037 int res = 0;
121040 memset(&s, 0, sizeof(s));
121091 return 0;
121218 if( db->nDb>2 || iDb!=0 ) z = sqlite3_mprintf("%s.%z", zDb, z);
121242 Table *pTab = 0; /* The table being read */
121250 assert( pParse->db->xAuth!=0 );
121252 if( iDb<0 ){
121262 for(iSrc=0; iSrc<pTabList->nSrc; iSrc++){
121270 if( pTab==0 ) return;
121272 if( iCol>=0 ){
121275 }else if( pTab->iPKey>=0 ){
121281 assert( iDb>=0 && iDb<pParse->db->nDb );
121306 assert( !IN_RENAME_OBJECT || db->xAuth==0 );
121307 if( db->xAuth==0 || db->init.busy || IN_SPECIAL_PARSE ){
121317 testcase( zArg1==0 );
121318 testcase( zArg2==0 );
121319 testcase( zArg3==0 );
121320 testcase( pParse->zAuthContext==0 );
121340 ** popped. Or if pParse==0, this routine is a no-op.
121360 pContext->pParse = 0;
121427 assert( iDb>=0 );
121430 for(i=0; i<pToplevel->nTableLock; i++){
121448 pToplevel->nTableLock = 0;
121471 assert( pVdbe!=0 );
121473 for(i=0; i<pParse->nTableLock; i++){
121492 for(i=0; i<sizeof(yDbMask); i++) if( m[i] ) return 0;
121512 assert( pParse->pToplevel==0 );
121520 assert( db->mallocFailed==0 );
121526 if( v==0 ){
121532 if( v==0 ) pParse->rc = SQLITE_ERROR;
121548 for(i=0; i<pReturning->nRetCol; i++){
121560 if( pParse->nTableLock>0 && db->init.busy==0 ){
121571 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
121576 assert( pParse->nErr>0 || sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
121577 sqlite3VdbeJumpHere(v, 0);
121578 assert( db->nDb>0 );
121579 iDb = 0;
121582 if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
121592 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
121597 for(i=0; i<pParse->nVtabLock; i++){
121599 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
121601 pParse->nVtabLock = 0;
121620 pParse->okConstFactor = 0;
121621 for(i=0; i<pEL->nExpr; i++){
121622 assert( pEL->a[i].u.iConstExprReg>0 );
121640 assert( v!=0 || pParse->nErr );
121641 assert( db->mallocFailed==0 || pParse->nErr );
121642 if( pParse->nErr==0 ){
121645 assert( pParse->pAinc==0 || pParse->nTab>0 );
121679 if( zSql==0 ){
121689 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
121704 return sqlite3_stricmp(zTable, "sqlite_user")==0;
121713 ** If zDatabase is 0, all databases are searched for the table and the
121721 Table *p = 0;
121725 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
121729 if( db->auth.authLevel<UAUTH_Admin && sqlite3UserAuthTable(zName)!=0 ){
121730 return 0;
121734 for(i=0; i<db->nDb; i++){
121735 if( sqlite3StrICmp(zDatabase, db->aDb[i].zDbSName)==0 ) break;
121739 ** to schema 0 as a legacy fallback. */
121740 if( sqlite3StrICmp(zDatabase,"main")==0 ){
121741 i = 0;
121743 return 0;
121747 if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
121749 if( sqlite3StrICmp(zName+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0
121750 || sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0
121751 || sqlite3StrICmp(zName+7, &LEGACY_SCHEMA_TABLE[7])==0
121757 if( sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0 ){
121768 p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, zName);
121772 assert( sqlite3SchemaMutexHeld(db, i, 0) );
121776 if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
121777 if( sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0 ){
121778 p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, LEGACY_SCHEMA_TABLE);
121779 }else if( sqlite3StrICmp(zName+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 ){
121809 if( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0
121812 return 0;
121816 if( p==0 ){
121821 if( (pParse->prepFlags & SQLITE_PREPARE_NO_VTAB)==0 && db->init.busy==0 ){
121823 if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
121827 testcase( pMod->pEpoTab==0 );
121832 if( flags & LOCATE_NOERR ) return 0;
121834 }else if( IsVirtual(p) && (pParse->prepFlags & SQLITE_PREPARE_NO_VTAB)!=0 ){
121835 p = 0;
121838 if( p==0 ){
121846 assert( HasRowid(p) || p->iPKey<0 );
121867 assert( p->pSchema==0 || p->zDatabase==0 );
121882 if( sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
121883 if( sqlite3StrICmp(zName+7, &LEGACY_SCHEMA_TABLE[7])==0 ){
121886 if( sqlite3StrICmp(zName+7, &LEGACY_TEMP_SCHEMA_TABLE[7])==0 ){
121899 ** If zDatabase is 0, all databases are searched for the
121906 Index *p = 0;
121909 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
121914 if( zDb && sqlite3DbIsNamed(db, j, zDb)==0 ) continue;
121915 assert( sqlite3SchemaMutexHeld(db, j, 0) );
121949 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
121951 pIndex = sqlite3HashInsert(pHash, zIdxName, 0);
121975 ** Entry 0 (the "main" database) and entry 1 (the "temp" database)
121982 if( pDb->pBt==0 ){
121984 pDb->zDbSName = 0;
121994 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
122003 ** Deferred resets may be run by calling with iDb<0.
122009 if( iDb>=0 ){
122010 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
122016 if( db->nSchemaLock==0 ){
122017 for(i=0; i<db->nDb; i++){
122032 for(i=0; i<db->nDb; i++){
122035 if( db->nSchemaLock==0 ){
122045 if( db->nSchemaLock==0 ){
122071 if( pCol->iDflt==0
122072 || NEVER(pList==0)
122075 pCol->iDflt = pList==0 ? 1 : pList->nExpr+1;
122089 if( pCol->iDflt==0 ) return 0;
122090 if( !IsOrdinaryTable(pTab) ) return 0;
122091 if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
122092 if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
122107 assert( zColl!=0 );
122126 if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0;
122142 assert( pTable!=0 );
122143 assert( db!=0 );
122144 if( (pCol = pTable->aCol)!=0 ){
122145 for(i=0; i<pTable->nCol; i++, pCol++){
122146 assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
122153 if( db->pnBytesFreed==0 ){
122154 pTable->aCol = 0;
122155 pTable->nCol = 0;
122157 pTable->u.tab.pDfltList = 0;
122189 int nLookaside = 0;
122190 assert( db!=0 );
122191 if( !db->mallocFailed && (pTable->tabFlags & TF_Ephemeral)==0 ){
122192 nLookaside = sqlite3LookasideUsed(db, 0);
122201 if( db->pnBytesFreed==0 && !IsVirtual(pTable) ){
122204 &pIndex->pSchema->idxHash, zName, 0
122206 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
122207 assert( pOld==pIndex || pOld==0 );
122234 assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) );
122238 assert( db!=0 );
122240 if( db->pnBytesFreed==0 && (--pTable->nTabRef)>0 ) return;
122256 assert( db!=0 );
122257 assert( iDb>=0 && iDb<db->nDb );
122259 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
122260 testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
122262 p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, 0);
122286 zName = 0;
122293 ** writing. The table is opened using cursor 0.
122298 sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, SCHEMA_ROOT, iDb, 5);
122299 if( p->nTab==0 ){
122314 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
122315 if( 0==sqlite3_stricmp(pDb->zDbSName, zName) ) break;
122318 if( i==0 && 0==sqlite3_stricmp("main", zName) ) break;
122364 assert( pName2!=0 );
122365 if( pName2->n>0 ){
122372 if( iDb<0 ){
122377 assert( db->init.iDb==0 || db->init.busy || IN_SPECIAL_PARSE
122378 || (db->mDbFlags & DBFLAG_Vacuum)!=0);
122389 testcase( (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))==0 );
122425 if( sqlite3_stricmp(zType, db->init.azInit[0])
122433 if( (pParse->nested==0 && 0==sqlite3StrNICmp(zName, "sqlite_", 7))
122462 for(i=0; i<pIdx->nColumn; i++){
122471 ** The storage column number (0,1,2,....) is the index of the value
122473 ** is the index (0,1,2,...) of the column in the CREATE TABLE statement.
122483 for(i=0; i<=iCol; i++){
122494 ** The storage column number (0,1,2,....) is the index of the value
122499 ** The true column number is the index (0,1,2,...) of the column in
122513 ** -- 0 1 2 3 4 5 6 7 8
122517 ** INPUTS: 0 1 2 3 4 5 6 7 8
122518 ** OUTPUTS: 0 1 6 2 3 7 4 5 8
122532 if( (pTab->tabFlags & TF_HasVirtual)==0 || iCol<0 ) return iCol;
122533 for(i=0, n=0; i<iCol; i++){
122534 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) n++;
122558 sqlite3VdbeAddOp3(v, OP_JournalMode, 0, iReg, PAGER_JOURNALMODE_QUERY);
122559 sqlite3VdbeUsesBtree(v, 0);
122589 char *zName = 0; /* The name of the new table */
122603 if( iDb<0 ) return;
122604 if( !OMIT_TEMPDB && isTemp && pName2->n>0 && iDb!=1 ){
122617 if( zName==0 ) return;
122623 assert( isTemp==0 || isTemp==1 );
122624 assert( isView==0 || isView==1 );
122633 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
122637 zName, 0, zDb) ){
122667 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
122674 if( pTable==0 ){
122689 assert( pParse->pNewTable==0 );
122700 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
122705 static const char nullRow[] = { 6, 0, 0, 0, 0, 0 };
122723 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
122740 sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
122749 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
122750 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
122751 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
122771 if( sqlite3_strnicmp(pCol->zCnName, "__hidden__", 10)==0 ){
122787 sqlite3HashInsert(pHash, pRet->zName, 0);
122815 assert( pParse->bReturning==0 || pParse->ifNotExists );
122819 if( pRet==0 ){
122842 assert( sqlite3HashFind(pHash, pRet->zName)==0
122871 if( (p = pParse->pNewTable)==0 ) return;
122883 && sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0
122886 while( ALWAYS(sType.n>0) && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--;
122888 && sqlite3_strnicmp(sType.z+(sType.n-9),"generated",9)==0
122891 while( sType.n>0 && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--;
122900 for(i=0; i<SQLITE_N_STDTYPE; i++){
122902 && sqlite3_strnicmp(sType.z, sqlite3StdType[i], sType.n)==0
122904 sType.n = 0;
122913 z = sqlite3DbMallocRaw(db, (i64)sName.n + 1 + (i64)sType.n + (sType.n>0) );
122914 if( z==0 ) return;
122917 z[sName.n] = 0;
122920 for(i=0; i<p->nCol; i++){
122921 if( p->aCol[i].hName==hName && sqlite3StrICmp(z, p->aCol[i].zCnName)==0 ){
122927 aNew = sqlite3DbRealloc(db,p->aCol,((i64)p->nCol+1)*sizeof(p->aCol[0]));
122928 if( aNew==0 ){
122934 memset(pCol, 0, sizeof(p->aCol[0]));
122939 if( sType.n==0 ){
122955 zType[sType.n] = 0;
122962 pParse->constraintName.n = 0;
122975 if( p==0 || NEVER(p->nCol<1) ) return;
122986 if( pIdx->aiColumn[0]==p->nCol-1 ){
123019 u32 h = 0;
123021 const char *zChar = 0;
123023 assert( zIn!=0 );
123024 while( zIn[0] ){
123038 if( zIn[0]=='(' ) zChar = zIn;
123050 }else if( (h&0x00FFFFFF)==(('i'<<16)+('n'<<8)+'t') ){ /* INT */
123059 int v = 0; /* default size is approx 4 bytes */
123062 while( zChar[0] ){
123063 if( sqlite3Isdigit(zChar[0]) ){
123106 if( p!=0 ){
123123 memset(&x, 0, sizeof(x));
123204 Column *pCol = 0;
123207 if( pTab==0 ) goto primary_key_exit;
123214 if( pList==0 ){
123221 for(i=0; i<nTerm; i++){
123223 assert( pCExpr!=0 );
123229 for(iCol=0; iCol<pTab->nCol; iCol++){
123230 if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){
123245 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
123250 assert( autoInc==0 || autoInc==1 );
123252 if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags;
123260 sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
123261 0, sortOrder, 0, SQLITE_IDXTYPE_PRIMARYKEY);
123262 pList = 0;
123290 for(zStart++; sqlite3Isspace(zStart[0]); zStart++){}
123313 if( (p = pParse->pNewTable)==0 || IN_RENAME_OBJECT ) return;
123329 if( pIdx->aiColumn[0]==i ){
123330 pIdx->azColl[0] = sqlite3ColumnColl(&p->aCol[i]);
123345 if( pTab==0 ){
123354 if( pCol->iDflt>0 ) goto generated_error;
123356 if( pType->n==7 && sqlite3StrNICmp("virtual",pType->z,7)==0 ){
123358 }else if( pType->n==6 && sqlite3StrNICmp("stored",pType->z,6)==0 ){
123377 pExpr = sqlite3PExpr(pParse, TK_UPLUS, pExpr, 0);
123381 pExpr = 0;
123419 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
123434 for(n=0; *z; n++, z++){
123458 for(j=0; zIdent[j]; j++){
123461 needQuote = sqlite3Isdigit(zIdent[0])
123463 || zIdent[j]!=0
123464 || j==0;
123467 for(j=0; zIdent[j]; j++){
123472 z[i] = 0;
123486 n = 0;
123487 for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){
123501 zStmt = sqlite3DbMallocRaw(0, n);
123502 if( zStmt==0 ){
123504 return 0;
123510 for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
123526 assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 );
123539 || pCol->affinity==sqlite3AffinityType(zType, 0) );
123556 assert( pIdx->isResized==0 );
123559 if( zExtra==0 ) return SQLITE_NOMEM_BKPT;
123580 unsigned wTable = 0;
123583 for(i=pTab->nCol, pTabCol=pTab->aCol; i>0; i--, pTabCol++){
123586 if( pTab->iPKey<0 ) wTable++;
123594 unsigned wIndex = 0;
123597 for(i=0; i<pIdx->nColumn; i++){
123600 wIndex += x<0 ? 1 : aCol[x].szEst;
123610 while( nCol-- > 0 ){
123615 return 0;
123641 for(i=0; i<nKey; i++){
123642 assert( pIdx->aiColumn[i]>=0 || j>=0 );
123644 && sqlite3StrICmp(pIdx->azColl[i], pPk->azColl[iCol])==0
123649 return 0;
123654 ** colNotIdxed is a bitmask that has a 0 bit representing each indexed
123672 Bitmask m = 0;
123675 for(j=pIdx->nColumn-1; j>=0; j--){
123677 if( x>=0 && (pTab->aCol[x].colFlags & COLFLAG_VIRTUAL)==0 ){
123723 for(i=0; i<pTab->nCol; i++){
123724 if( (pTab->aCol[i].colFlags & COLFLAG_PRIMKEY)!=0
123745 if( pTab->iPKey>=0 ){
123749 pList = sqlite3ExprListAppend(pParse, 0,
123750 sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
123751 if( pList==0 ){
123756 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
123758 pList->a[0].fg.sortFlags = pParse->iPkSortOrder;
123761 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
123767 assert( db->mallocFailed==0 );
123772 assert( pPk!=0 );
123791 assert( pPk!=0 );
123800 if( v && pPk->tnum>0 ){
123801 assert( db->init.busy==0 );
123814 for(i=n=0; i<nPk; i++){
123820 if( n==0 ){
123826 for(i=0, j=pIdx->nKeyCol; i<nPk; i++){
123844 nExtra = 0;
123845 for(i=0; i<pTab->nCol; i++){
123847 && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) nExtra++;
123850 for(i=0, j=nPk; i<pTab->nCol; i++){
123852 && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0
123875 if( !IsVirtual(pTab) ) return 0;
123877 if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0;
123878 if( zName[nName]!='_' ) return 0;
123879 pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]);
123880 if( pMod==0 ) return 0;
123881 if( pMod->pModule->iVersion<3 ) return 0;
123882 if( pMod->pModule->xShadowName==0 ) return 0;
123900 pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]);
123901 if( pMod==0 ) return;
123902 if( NEVER(pMod->pModule==0) ) return;
123904 if( pMod->pModule->xShadowName==0 ) return;
123905 assert( pTab->zName!=0 );
123909 assert( pOther->zName!=0 );
123912 if( sqlite3StrNICmp(pOther->zName, pTab->zName, nName)==0
123934 if( zTail==0 ) return 0;
123935 *zTail = 0;
123936 pTab = sqlite3FindTable(db, zName, 0);
123938 if( pTab==0 ) return 0;
123939 if( !IsVirtual(pTab) ) return 0;
123960 memset(&w, 0, sizeof(w));
123963 w.xSelectCallback2 = 0;
123996 u32 tabOpts, /* Extra table options. Usually 0. */
124004 if( pEnd==0 && pSelect==0 ){
124008 if( p==0 ) return;
124010 if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){
124044 for(ii=0; ii<p->nCol; ii++){
124060 if( (pCol->colFlags & COLFLAG_PRIMKEY)!=0
124070 assert( (p->tabFlags & TF_HasPrimaryKey)==0
124071 || p->iPKey>=0 || sqlite3PrimaryKeyIndex(p)!=0 );
124072 assert( (p->tabFlags & TF_HasPrimaryKey)!=0
124073 || (p->iPKey<0 && sqlite3PrimaryKeyIndex(p)==0) );
124082 if( (p->tabFlags & TF_HasPrimaryKey)==0 ){
124095 sqlite3ResolveSelfReference(pParse, p, NC_IsCheck, 0, p->pCheck);
124100 p->pCheck = 0;
124108 int ii, nNG = 0;
124111 for(ii=0; ii<p->nCol; ii++){
124113 if( (colFlags & COLFLAG_GENERATED)!=0 ){
124117 if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){
124125 sqlite3ExprAlloc(db, TK_NULL, 0, 0));
124131 if( nNG==0 ){
124158 if( NEVER(v==0) ) return;
124160 sqlite3VdbeAddOp1(v, OP_Close, 0);
124213 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
124216 if( pSelTab==0 ) return;
124217 assert( p->aCol==0 );
124220 pSelTab->nCol = 0;
124221 pSelTab->aCol = 0;
124231 sqlite3TableAffinity(v, p, 0);
124245 if( pEnd2->z[0]!=';' ) n += pEnd2->n;
124274 if( (p->tabFlags & TF_Autoincrement)!=0 && !IN_SPECIAL_PARSE ){
124276 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
124277 if( pDb->pSchema->pSeqTab==0 ){
124288 sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName),0);
124293 sqlite3VdbeAddOp4(v, OP_SqlExec, 0x0001, 0, 0,
124304 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
124305 assert( HasRowid(p) || p->iPKey<0 );
124312 pParse->pNewTable = 0;
124320 if( strcmp(p->zName, "sqlite_sequence")==0 ){
124321 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
124330 if( pCons->z==0 ){
124357 Token *pName = 0;
124361 if( pParse->nVar>0 ){
124365 sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
124367 if( p==0 || pParse->nErr ) goto create_view_fail;
124394 pSelect = 0;
124406 assert( sEnd.z[0]!=0 || sEnd.n==0 );
124407 if( sEnd.z[0]!=';' ){
124410 sEnd.n = 0;
124412 assert( n>0 );
124419 sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
124441 int nErr = 0; /* Number of errors encountered */
124466 assert( pTable->nCol<=0 );
124483 if( pTable->nCol<0 ){
124487 assert( pTable->nCol>=0 );
124497 pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
124508 db->xAuth = 0;
124516 if( pSelTab==0 ){
124517 pTable->nCol = 0;
124528 if( pParse->nErr==0
124531 assert( db->mallocFailed==0 );
124538 assert( pTable->aCol==0 );
124542 pSelTab->nCol = 0;
124543 pSelTab->aCol = 0;
124544 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
124562 assert( pTable!=0 );
124563 if( !IsVirtual(pTable) && pTable->nCol>0 ) return 0;
124574 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
124611 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
124674 ** OP_Destroy 4 0
124676 ** OP_Destroy 5 0
124680 ** "OP_Destroy 4 0" opcode. The subsequent "OP_Destroy 5 0" would hit
124684 Pgno iDestroyed = 0;
124688 Pgno iLargest = 0;
124690 if( iDestroyed==0 || iTab<iDestroyed ){
124696 if( (iDestroyed==0 || (iIdx<iDestroyed)) && iIdx>iLargest ){
124700 if( iLargest==0 ){
124704 assert( iDb>=0 && iDb<pParse->db->nDb );
124745 assert( v!=0 );
124799 sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
124802 sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
124813 if( (db->flags & SQLITE_Defensive)!=0
124814 && db->pVtabCtx==0
124815 && db->nVdbeExec==0
124821 return 0;
124828 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
124829 if( sqlite3StrNICmp(pTab->zName+7, "stat", 4)==0 ) return 0;
124830 if( sqlite3StrNICmp(pTab->zName+7, "parameters", 10)==0 ) return 0;
124833 if( (pTab->tabFlags & TF_Shadow)!=0 && sqlite3ReadOnlyShadowTables(db) ){
124839 return 0;
124855 assert( pParse->nErr==0 );
124859 assert( isView==0 || isView==LOCATE_VIEW );
124860 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
124863 if( pTab==0 ){
124865 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
124871 assert( iDb>=0 && iDb<db->nDb );
124884 const char *zArg2 = 0;
124885 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
124909 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
124953 ** in the current table point to the foreign key. If pFromCol==0 then
124975 FKey *pFKey = 0;
124983 assert( pTo!=0 );
124984 if( p==0 || IN_DECLARE_VTAB ) goto fk_end;
124985 if( pFromCol==0 ){
124987 if( NEVER(iCol<0) ) goto fk_end;
125003 nByte = sizeof(*pFKey) + (nCol-1)*sizeof(pFKey->aCol[0]) + pTo->n + 1;
125005 for(i=0; i<pToCol->nExpr; i++){
125010 if( pFKey==0 ){
125022 z[pTo->n] = 0;
125026 if( pFromCol==0 ){
125027 pFKey->aCol[0].iFrom = p->nCol-1;
125029 for(i=0; i<nCol; i++){
125031 for(j=0; j<p->nCol; j++){
125032 if( sqlite3StrICmp(p->aCol[j].zCnName, pFromCol->a[i].zEName)==0 ){
125049 for(i=0; i<nCol; i++){
125056 z[n] = 0;
125060 pFKey->isDeferred = 0;
125061 pFKey->aAction[0] = (u8)(flags & 0xff); /* ON DELETE action */
125062 pFKey->aAction[1] = (u8)((flags >> 8 ) & 0xff); /* ON UPDATE action */
125064 assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
125073 assert( pNextTo->pPrevTo==0 );
125082 pFKey = 0;
125094 ** parameter is 1 for INITIALLY DEFERRED and 0 for INITIALLY IMMEDIATE.
125102 if( (pTab = pParse->pNewTable)==0 ) return;
125104 if( (pFKey = pTab->u.tab.pFKey)==0 ) return;
125105 assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */
125137 if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
125147 if( v==0 ) return;
125148 if( memRootPage>=0 ){
125154 assert( pKey!=0 || pParse->nErr );
125158 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*)
125164 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); VdbeCoverage(v);
125168 sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0);
125173 if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
125176 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
125178 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
125263 for(i=0; i<pList->nExpr; i++){
125267 (sf==0 || sf==3) ? "FIRST" : "LAST"
125273 return 0;
125292 SrcList *pTblName, /* Table to index. Use pParse->pNewTable if 0 */
125301 Table *pTab = 0; /* Table to be indexed */
125302 Index *pIndex = 0; /* The index to be created */
125303 char *zName = 0; /* Name of the index */
125307 int sortOrderMask; /* 1 to honor DESC in index. 0 to ignore. */
125311 Token *pName = 0; /* Unqualified name of the index to create */
125313 int nExtra = 0; /* Space allocated for zExtra[] */
125315 char *zExtra = 0; /* Extra space after the Index object */
125316 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
125322 assert( db->mallocFailed==0 );
125336 if( pTblName!=0 ){
125344 if( iDb<0 ) goto exit_create_index;
125354 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
125364 assert(0);
125366 pTab = sqlite3LocateTableItem(pParse, 0, &pTblName->a[0]);
125367 assert( db->mallocFailed==0 || pTab==0 );
125368 if( pTab==0 ) goto exit_create_index;
125377 assert( pName==0 );
125378 assert( pStart==0 );
125385 assert( pTab!=0 );
125386 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
125387 && db->init.busy==0
125388 && pTblName!=0
125390 && sqlite3UserAuthTable(pTab->zName)==0
125418 ** If pName==0 it means that we are
125424 if( zName==0 ) goto exit_create_index;
125425 assert( pName->z!=0 );
125431 if( sqlite3FindTable(db, zName, pDb->zDbSName)!=0 ){
125436 if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
125452 if( zName==0 ){
125469 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
125480 /* If pList==0, it means this routine was called to make a primary
125484 if( pList==0 ){
125489 pList = sqlite3ExprListAppend(pParse, 0,
125490 sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
125491 if( pList==0 ) goto exit_create_index;
125502 for(i=0; i<pList->nExpr; i++){
125504 assert( pExpr!=0 );
125534 sqlite3ResolveSelfReference(pParse, pTab, NC_PartIdx, pPIWhere, 0);
125536 pPIWhere = 0;
125538 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
125545 sortOrderMask = 0; /* Ignore DESC */
125560 pList = 0;
125562 for(i=0; i<pIndex->nKeyCol; i++, pListItem++){
125568 sqlite3ResolveSelfReference(pParse, pTab, NC_IdxExpr, pListItem->pExpr, 0);
125577 if( pIndex->aColExpr==0 ){
125579 pList = 0;
125583 pIndex->uniqNotNull = 0;
125587 assert( j<=0x7fff );
125588 if( j<0 ){
125591 if( pTab->aCol[j].notNull==0 ){
125592 pIndex->uniqNotNull = 0;
125601 zColl = 0;
125612 }else if( j>=0 ){
125625 ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
125626 ** normal tables (when pPk==0) this will be the rowid.
125629 for(j=0; j<pPk->nKeyCol; j++){
125631 assert( x>=0 );
125648 if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex);
125653 || pTab->iPKey<0 || sqlite3TableColumnToIndex(pIndex, pTab->iPKey)>=0 );
125655 if( pTblName!=0 && pIndex->nColumn>=pTab->nCol ){
125657 for(j=0; j<pTab->nCol; j++){
125659 if( sqlite3TableColumnToIndex(pIndex,j)>=0 ) continue;
125660 pIndex->isCovering = 0;
125695 for(k=0; k<pIdx->nKeyCol; k++){
125698 assert( pIdx->aiColumn[k]>=0 );
125715 "conflicting ON CONFLICT clauses specified", 0);
125725 pIndex = 0;
125737 assert( pParse->nErr==0 );
125741 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
125742 if( pTblName!=0 ){
125768 ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
125773 else if( HasRowid(pTab) || pTblName!=0 ){
125779 if( v==0 ) goto exit_create_index;
125795 assert( pName!=0 || pStart==0 );
125805 zStmt = 0;
125827 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName), 0);
125828 sqlite3VdbeAddOp2(v, OP_Expire, 0, 1);
125834 if( db->init.busy || pTblName==0 ){
125837 pIndex = 0;
125840 assert( pParse->pNewIndex==0 );
125842 pIndex = 0;
125855 for(ppFrom=&pTab->pIndex; (pThis = *ppFrom)!=0; ppFrom=&pThis->pNext){
125858 while( (pNext = pThis->pNext)!=0 && pNext->onError!=OE_Replace ){
125872 || pThis->pNext==0
125887 ** aiRowEst[0] is supposed to contain the number of elements in the index.
125927 if( pIdx->pPartIdxWhere!=0 ){ x -= 10; assert( 10==sqlite3LogEst(2) ); }
125928 a[0] = x;
125937 assert( 0==sqlite3LogEst(1) );
125938 if( IsUniqueIndex(pIdx) ) a[pIdx->nKeyCol] = 0;
125954 assert( pParse->nErr==0 ); /* Never called with prior non-OOM errors */
125959 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
125960 if( pIndex==0 ){
125964 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
125972 "or PRIMARY KEY constraint cannot be dropped", 0);
125982 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
126003 sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
126036 if( (n & (n-1))==0 ){
126037 sqlite3_int64 sz = (n==0) ? 1 : 2*n;
126039 if( pNew==0 ){
126046 memset(&z[n * szEntry], 0, szEntry);
126060 if( pList==0 ){
126062 if( pList==0 ) return 0;
126067 if( pNew==0 ){
126069 return 0;
126086 assert( db!=0 );
126087 if( pList==0 ) return;
126089 for(i=0; i<pList->nId; i++){
126101 assert( pList!=0 );
126102 for(i=0; i<pList->nId; i++){
126103 if( sqlite3StrICmp(pList->a[i].zName, zName)==0 ) return i;
126133 ** the iStart value would be 0. The result then would
126149 assert( iStart>=0 );
126151 assert( pSrc!=0 );
126163 return 0;
126167 sizeof(*pSrc) + (nAlloc-1)*sizeof(pSrc->a[0]) );
126168 if( pNew==0 ){
126170 return 0;
126184 memset(&pSrc->a[iStart], 0, sizeof(pSrc->a[0])*nExtra);
126214 ** sqlite3SrcListAppend(D,A,B,0);
126224 ** sqlite3SrcListAppend(D,A,0,C);
126237 assert( pDatabase==0 || pTable!=0 ); /* Cannot have C without B */
126238 assert( pParse!=0 );
126239 assert( pParse->db!=0 );
126241 if( pList==0 ){
126243 if( pList==0 ) return 0;
126246 memset(&pList->a[0], 0, sizeof(pList->a[0]));
126247 pList->a[0].iCursor = -1;
126250 if( pNew==0 ){
126252 return 0;
126258 if( pDatabase && pDatabase->z==0 ){
126259 pDatabase = 0;
126266 pItem->zDatabase = 0;
126279 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
126280 if( pItem->iCursor>=0 ) continue;
126295 assert( db!=0 );
126296 if( pList==0 ) return;
126297 for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
126341 if( !p && pOnUsing!=0 && (pOnUsing->pOn || pOnUsing->pUsing) ){
126348 if( p==0 ){
126351 assert( p->nSrc>0 );
126353 assert( (pTable==0)==(pDatabase==0) );
126354 assert( pItem->zName==0 || pDatabase!=0 );
126359 assert( pAlias!=0 );
126369 assert( pOnUsing==0 || pOnUsing->pOn==0 || pOnUsing->pUsing==0 );
126370 assert( pItem->fg.isUsing==0 );
126371 if( pOnUsing==0 ){
126372 pItem->u3.pOn = 0;
126382 assert( p==0 );
126385 return 0;
126393 assert( pIndexedBy!=0 );
126394 if( p && pIndexedBy->n>0 ){
126396 assert( p->nSrc>0 );
126398 assert( pItem->fg.notIndexed==0 );
126399 assert( pItem->fg.isIndexedBy==0 );
126400 assert( pItem->fg.isTabFunc==0 );
126408 assert( pItem->fg.isCte==0 ); /* No collision on union u2 */
126422 if( pNew==0 ){
126428 p1->a[0].fg.jointype |= (JT_LTORJ & p1->a[1].fg.jointype);
126441 assert( pItem->fg.notIndexed==0 );
126442 assert( pItem->fg.isIndexedBy==0 );
126443 assert( pItem->fg.isTabFunc==0 );
126463 ** in p->a[0] and p->a[1], respectively. The parser initially stores the
126477 u8 allFlags = 0;
126480 }while( (--i)>0 );
126481 p->a[0].fg.jointype = 0;
126486 for(i=p->nSrc-1; ALWAYS(i>0) && (p->a[i].fg.jointype&JT_RIGHT)==0; i--){}
126488 assert( i>=0 );
126491 }while( (--i)>=0 );
126504 assert( pParse!=0 );
126506 assert( db!=0 );
126507 if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "BEGIN", 0, 0) ){
126513 for(i=0; i<db->nDb; i++){
126517 eTxnType = 0; /* Read txn */
126539 assert( pParse!=0 );
126540 assert( pParse->db!=0 );
126544 isRollback ? "ROLLBACK" : "COMMIT", 0, 0) ){
126565 if( !v || sqlite3AuthCheck(pParse, SQLITE_SAVEPOINT, az[op], zName, 0) ){
126569 sqlite3VdbeAddOp4(v, OP_Savepoint, op, 0, 0, zName, P4_DYNAMIC);
126579 if( db->aDb[1].pBt==0 && !pParse->explain ){
126589 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
126598 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, 0, 0) ){
126603 return 0;
126613 assert( iDb>=0 && iDb<pToplevel->db->nDb );
126614 assert( pToplevel->db->aDb[iDb].pBt!=0 || iDb==1 );
126616 assert( sqlite3SchemaMutexHeld(pToplevel->db, iDb, 0) );
126617 if( DbMaskTest(pToplevel->cookieMask, iDb)==0 ){
126636 for(i=0; i<db->nDb; i++){
126638 if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zDbSName)) ){
126711 assert( pParse->pVdbe!=0 );
126713 assert( (errCode&0xff)==SQLITE_CONSTRAINT || pParse->nested );
126717 sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type);
126734 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0,
126739 for(j=0; j<pIdx->nKeyCol; j++){
126741 assert( pIdx->aiColumn[j]>=0 );
126767 if( pTab->iPKey>=0 ){
126786 assert( zColl!=0 );
126787 for(i=0; i<pIndex->nColumn; i++){
126789 assert( z!=0 || pIndex->aiColumn[i]<0 );
126790 if( pIndex->aiColumn[i]>=0 && 0==sqlite3StrICmp(z, zColl) ){
126794 return 0;
126800 ** If pColl==0 then recompute all indices of pTab.
126808 if( zColl==0 || collationMatch(zColl, pIndex) ){
126810 sqlite3BeginWriteOperation(pParse, 0, iDb);
126820 ** indices use the collating sequence pColl. If pColl==0 then recompute
126832 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
126833 assert( pDb!=0 );
126872 if( pName1==0 ){
126873 reindexDatabases(pParse, 0);
126875 }else if( NEVER(pName2==0) || pName2->z==0 ){
126880 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
126889 if( iDb<0 ) return;
126891 if( z==0 ) return;
126892 zDb = pName2->n ? db->aDb[iDb].zDbSName : 0;
126895 reindexTable(pParse, pTab, 0);
126903 sqlite3BeginWriteOperation(pParse, 0, iDb);
126922 if( pParse->nErr ) return 0;
126926 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
126930 for(i=0; i<nCol; i++){
126932 pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
126935 assert( 0==(pKey->aSortFlags[i] & KEYINFO_ORDER_BIGNULL) );
126939 if( pIdx->bNoQuery==0 ){
126951 pKey = 0;
126972 assert( pNew!=0 || db->mallocFailed );
126991 assert( pCte!=0 );
127001 assert( pCte!=0 );
127021 if( pCte==0 ){
127030 for(i=0; i<pWith->nCte; i++){
127031 if( sqlite3StrICmp(zName, pWith->a[i].zName)==0 ){
127043 assert( (pNew!=0 && zName!=0) || db->mallocFailed );
127062 for(i=0; i<pWith->nCte; i++){
127131 for(i=0; i<3; i++){
127132 pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, 0);
127133 if( pColl2->xCmp!=0 ){
127135 pColl->xDel = 0; /* Do not copy the destructor */
127154 if( pColl && pColl->xCmp==0 ){
127189 if( 0==pColl && create ){
127193 CollSeq *pDel = 0;
127194 pColl[0].zName = (char*)&pColl[3];
127195 pColl[0].enc = SQLITE_UTF8;
127200 memcpy(pColl[0].zName, zName, nName);
127201 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, pColl);
127207 assert( pDel==0 || pDel==pColl );
127208 if( pDel!=0 ){
127211 pColl = 0;
127261 db->pDfltColl = sqlite3FindCollSeq(db, enc, sqlite3StrBINARY, 0);
127290 p = sqlite3FindCollSeq(db, enc, zName, 0);
127297 p = sqlite3FindCollSeq(db, enc, zName, 0);
127300 p = 0;
127303 if( p==0 ){
127358 ** The returned value is always between 0 and 6, as follows:
127360 ** 0: Not a match.
127383 if( nArg==(-2) ) return (p->xSFunc==0) ? 0 : FUNC_PERFECT_MATCH;
127384 if( p->nArg>=0 ) return 0;
127398 }else if( (enc & p->funcFlags & 2)!=0 ){
127407 ** a pointer to the matching FuncDef if found, or 0 if there is no match.
127416 if( sqlite3StrICmp(p->zName, zFunc)==0 ){
127420 return 0;
127431 for(i=0; i<nDef; i++){
127435 int h = SQLITE_FUNC_HASH(zName[0], nName);
127443 aDef[i].pNext = 0;
127465 ** of arguments. If nArg is -2, then createFlag must be 0.
127479 FuncDef *pBest = 0; /* Best match found so far */
127480 int bestScore = 0; /* Score of best match */
127485 assert( nArg>=(-1) || createFlag==0 );
127512 if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){
127513 bestScore = 0;
127514 h = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zName[0]], nName);
127531 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
127543 return 0;
127552 return 0;
127570 memset(&xdb, 0, sizeof(xdb));
127586 pSchema->pSeqTab = 0;
127602 p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema));
127606 }else if ( 0==p->file_format ){
127644 ** pSrc->a[0].pTab Pointer to the Table object
127645 ** pSrc->a[0].pIndex Pointer to the INDEXED BY index, if there is one
127652 pTab = sqlite3LocateTableItem(pParse, 0, pItem);
127659 pTab = 0;
127672 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zColName, SQLITE_STATIC);
127695 if( sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 ){
127705 if( pParse->pToplevel!=0
127707 ((pParse->db->flags & SQLITE_TrustedSchema)!=0)
127712 return 0;
127719 if( (pTab->tabFlags & (TF_Readonly|TF_Shadow))==0 ) return 0;
127721 if( (pTab->tabFlags & TF_Readonly)!=0 ){
127722 return sqlite3WritableSchema(db)==0 && pParse->nested==0;
127733 ** If pTab is writable and no prior errors -> return 0;
127742 && (pTrigger==0 || (pTrigger->bReturning && pTrigger->pNext==0))
127748 return 0;
127771 pWhere = sqlite3ExprDup(db, pWhere, 0);
127772 pFrom = sqlite3SrcListAppend(pParse, 0, 0, 0);
127775 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
127776 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
127777 assert( pFrom->a[0].fg.isUsing==0 );
127778 assert( pFrom->a[0].u3.pOn==0 );
127780 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy,
127815 if( pOrderBy && pLimit==0 ) {
127819 return 0;
127825 if( pLimit == 0 ) {
127838 pTab = pSrc->a[0].pTab;
127840 pLhs = sqlite3PExpr(pParse, TK_ROW, 0, 0);
127842 pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0)
127846 assert( pPk!=0 );
127850 assert( pPk->aiColumn[0]>=0 && pPk->aiColumn[0]<pTab->nCol );
127851 zName = pTab->aCol[pPk->aiColumn[0]].zCnName;
127853 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName));
127856 for(i=0; i<pPk->nKeyCol; i++){
127858 assert( pPk->aiColumn[i]>=0 && pPk->aiColumn[i]<pTab->nCol );
127862 pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
127864 pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0);
127871 pSrc->a[0].pTab = 0;
127872 pSelectSrc = sqlite3SrcListDup(db, pSrc, 0);
127873 pSrc->a[0].pTab = pTab;
127874 if( pSrc->a[0].fg.isIndexedBy ){
127875 assert( pSrc->a[0].fg.isCte==0 );
127876 pSrc->a[0].u2.pIBIndex = 0;
127877 pSrc->a[0].fg.isIndexedBy = 0;
127878 sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy);
127879 }else if( pSrc->a[0].fg.isCte ){
127880 pSrc->a[0].u2.pCteUse->nUse++;
127884 pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
127885 pOrderBy,0,pLimit
127889 pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0);
127916 int iDataCur = 0; /* VDBE cursor for the canonical data source */
127917 int iIdxCur = 0; /* Cursor number of the first index */
127923 int memCnt = 0; /* Memory cell used for change counting */
127927 u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */
127929 int iPk = 0; /* First of nPk registers holding PRIMARY KEY value */
127933 int iEphCur = 0; /* Ephemeral table holding all primary key values */
127934 int iRowSet = 0; /* Register for rowset of rows to delete */
127935 int addrBypass = 0; /* Address of jump over the delete logic */
127936 int addrLoop = 0; /* Top of the delete loop */
127937 int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
127946 memset(&sContext, 0, sizeof(sContext));
127952 assert( db->mallocFailed==0 );
127961 if( pTab==0 ) goto delete_from_cleanup;
127967 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
127970 # define pTrigger 0
127971 # define isView 0
127973 bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
127976 # define isView 0
127980 if( sqlite3TreeTrace & 0x10000 ){
127981 sqlite3TreeViewLine(0, "In sqlite3Delete() at %s:%d", __FILE__, __LINE__);
127992 pOrderBy = 0;
127993 pLimit = 0;
128008 rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0,
128019 iTabCur = pTabList->a[0].iCursor = pParse->nTab++;
128020 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
128033 if( v==0 ){
128036 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
128048 pOrderBy = 0;
128049 pLimit = 0;
128055 memset(&sNC, 0, sizeof(sNC));
128065 if( (db->flags & SQLITE_CountRows)!=0
128071 sqlite3VdbeAddOp2(v, OP_Integer, 0, memCnt);
128087 && pWhere==0
128091 && db->xPreUpdateCallback==0
128113 wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
128116 pPk = 0;
128119 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
128124 assert( pPk!=0 );
128141 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,0,wcf,iTabCur+1);
128142 if( pWInfo==0 ) goto delete_from_cleanup;
128144 assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI );
128159 for(i=0; i<nPk; i++){
128160 assert( pPk->aiColumn[i]>=0 );
128176 if( aToOpen==0 ){
128181 aToOpen[nIdx+1] = 0;
128182 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
128183 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
128190 nKey = 0; /* Zero tells OP_Found to use a composite key */
128208 int iAddrOnce = 0;
128228 assert( pPk!=0 || IsView(pTab) );
128235 sqlite3VdbeAddOp3(v, OP_Column, iEphCur, 0, iKey);
128239 assert( nKey==0 ); /* OP_Found will use a composite key */
128241 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
128256 pParse->isMultiWrite = 0;
128259 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iKey, pVTab, P4_VTAB);
128264 int count = (pParse->nested==0); /* True to count changes */
128286 if( pParse->nested==0 && pParse->pTriggerTab==0 ){
128335 ** sequence of nPk memory cells starting at iPk. If nPk==0 that means
128340 ** Parameter eMode may be passed either ONEPASS_OFF (0), ONEPASS_SINGLE, or
128348 ** iIdxNoSeek is a valid cursor number (>=0) and is not the same as
128354 ** If iIdxNoSeek is a valid cursor number (>=0) not equal to iDataCur,
128374 int iOld = 0; /* First register in OLD.* array */
128396 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
128404 pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf
128413 for(iCol=0; iCol<pTab->nCol; iCol++){
128414 testcase( mask!=0xffffffff && iCol==31 );
128415 testcase( mask!=0xffffffff && iCol==32 );
128416 if( mask==0xffffffff || (iCol<=31 && (mask & MASKBIT32(iCol))!=0) ){
128425 TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
128440 testcase( iIdxNoSeek>=0 );
128447 sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
128461 u8 p5 = 0;
128462 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
128463 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
128464 if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){
128470 if( iIdxNoSeek>=0 && iIdxNoSeek!=iDataCur ){
128480 sqlite3FkActions(pParse, pTab, 0, iOld, 0, 0);
128485 TK_DELETE, 0, TRIGGER_AFTER, pTab, iOld, onconf, iLabel
128509 ** index is the 0-th index.)
128519 int *aRegIdx, /* Only delete if aRegIdx!=0 && aRegIdx[i]>0 */
128526 Index *pPrior = 0; /* Prior index */
128531 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
128532 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
128534 if( aRegIdx!=0 && aRegIdx[i]==0 ) continue;
128538 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1,
128583 int regOut, /* Put the new key into this register if not 0 */
128600 pParse->iSelfTab = 0;
128601 pPrior = 0; /* Ticket a9efb42811fa41ee 2019-11-02;
128604 *piPartIdxLabel = 0;
128609 if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;
128610 for(j=0; j<nCol; j++){
128619 if( pIdx->aiColumn[j]>=0 ){
128677 assert( context->pVdbe!=0 );
128689 assert( context->isError<=0 );
128703 int mask; /* 0 for min() or 0xffffffff for max() */
128708 mask = sqlite3_user_data(context)==0 ? 0 : -1;
128711 assert( mask==-1 || mask==0 );
128712 iBest = 0;
128713 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
128716 if( (sqlite3MemCompare(argv[iBest], argv[i], pColl)^mask)>=0 ){
128717 testcase( mask==0 );
128733 int i = sqlite3_value_type(argv[0]) - 1;
128735 assert( i>=0 && i<ArraySize(azType) );
128758 sqlite3_result_int(context, sqlite3_value_subtype(argv[0]));
128771 switch( sqlite3_value_type(argv[0]) ){
128775 sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
128779 const unsigned char *z = sqlite3_value_text(argv[0]);
128782 if( z==0 ) return;
128784 while( (c = *z)!=0 ){
128786 if( c>=0xc0 ){
128787 while( (*z & 0xc0)==0x80 ){ z++; z0++; }
128810 switch( sqlite3_value_type(argv[0]) ){
128812 sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
128818 sqlite3_result_int64(context, sqlite3_value_bytes(argv[0])*m);
128822 if( sqlite3_value_encoding(argv[0])<=SQLITE_UTF8 ){
128823 sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
128825 sqlite3_result_int(context, sqlite3_value_bytes16(argv[0]));
128845 switch( sqlite3_value_type(argv[0]) ){
128847 i64 iVal = sqlite3_value_int64(argv[0]);
128848 if( iVal<0 ){
128872 double rVal = sqlite3_value_double(argv[0]);
128873 if( rVal<0 ) rVal = -rVal;
128885 ** or 0 if needle does not occur within haystack.
128889 ** or 0 if needle never occurs in haystack.
128904 sqlite3_value *pC1 = 0;
128905 sqlite3_value *pC2 = 0;
128908 typeHaystack = sqlite3_value_type(argv[0]);
128911 nHaystack = sqlite3_value_bytes(argv[0]);
128913 if( nNeedle>0 ){
128915 zHaystack = sqlite3_value_blob(argv[0]);
128917 isText = 0;
128919 zHaystack = sqlite3_value_text(argv[0]);
128923 pC1 = sqlite3_value_dup(argv[0]);
128925 if( zHaystack==0 ) goto endInstrOOM;
128929 if( zNeedle==0 ) goto endInstrOOM;
128933 if( zNeedle==0 || (nHaystack && zHaystack==0) ) goto endInstrOOM;
128934 firstChar = zNeedle[0];
128936 && (zHaystack[0]!=firstChar || memcmp(zHaystack, zNeedle, nNeedle)!=0)
128942 }while( isText && (zHaystack[0]&0xc0)==0x80 );
128944 if( nNeedle>nHaystack ) N = 0;
128970 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
128972 x.nUsed = 0;
128974 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
129005 int negP2 = 0;
129013 p0type = sqlite3_value_type(argv[0]);
129016 len = sqlite3_value_bytes(argv[0]);
129017 z = sqlite3_value_blob(argv[0]);
129018 if( z==0 ) return;
129019 assert( len==sqlite3_value_bytes(argv[0]) );
129021 z = sqlite3_value_text(argv[0]);
129022 if( z==0 ) return;
129023 len = 0;
129024 if( p1<0 ){
129031 /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
129036 if( p1==0 ) p1 = 1; /* <rdar://problem/6778339> */
129040 if( p2<0 ){
129047 if( p1<0 ){
129049 if( p1<0 ){
129051 if( p2<0 ) p2 = 0;
129052 p1 = 0;
129054 }else if( p1>0 ){
129056 }else if( p2>0 ){
129061 if( p1<0 ){
129063 p1 = 0;
129066 assert( p1>=0 && p2>=0 );
129080 if( p2<0 ) p2 = 0;
129091 int n = 0;
129099 if( n<0 ) n = 0;
129101 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
129102 r = sqlite3_value_double(argv[0]);
129103 /* If Y==0 and X will fit in a 64-bit int,
129109 }else if( n==0 ){
129110 r = (double)((sqlite_int64)(r+(r<0?-0.5:+0.5)));
129113 if( zBuf==0 ){
129134 assert( nByte>0 );
129139 z = 0;
129157 z2 = (char*)sqlite3_value_text(argv[0]);
129158 n = sqlite3_value_bytes(argv[0]);
129160 assert( z2==(char*)sqlite3_value_text(argv[0]) );
129164 for(i=0; i<n; i++){
129176 z2 = (char*)sqlite3_value_text(argv[0]);
129177 n = sqlite3_value_bytes(argv[0]);
129179 assert( z2==(char*)sqlite3_value_text(argv[0]) );
129183 for(i=0; i<n; i++){
129212 if( r<0 ){
129213 /* We need to prevent a random number of 0x8000000000000000
129239 n = sqlite3_value_int64(argv[0]);
129306 u8 matchSet; /* "[" or 0 */
129320 # define Utf8Read(A) (A[0]<0x80?*(A++):sqlite3Utf8Read(&A))
129323 static const struct compareInfo globInfo = { '*', '?', '[', 0 };
129326 static const struct compareInfo likeInfoNorm = { '%', '_', 0, 1 };
129329 static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
129334 #define SQLITE_MATCH 0
129386 const u8 *zEscaped = 0; /* One past the last escaped input char */
129388 while( (c = Utf8Read(zPattern))!=0 ){
129394 || (c == matchOne && matchOne!=0) ){
129395 if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
129399 if( c==0 ){
129402 if( pInfo->matchSet==0 ){
129404 if( c==0 ) return SQLITE_NOWILDCARDMATCH;
129408 assert( matchOther<0x80 ); /* '[' is a single-byte character */
129427 if( c<0x80 ){
129431 zStop[0] = sqlite3Toupper(c);
129433 zStop[2] = 0;
129435 zStop[0] = c;
129436 zStop[1] = 0;
129440 if( zString[0]==0 ) break;
129447 while( (c2 = Utf8Read(zString))!=0 ){
129456 if( pInfo->matchSet==0 ){
129458 if( c==0 ) return SQLITE_NOMATCH;
129461 u32 prior_c = 0;
129462 int seen = 0;
129463 int invert = 0;
129465 if( c==0 ) return SQLITE_NOMATCH;
129476 if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
129479 prior_c = 0;
129488 if( c2==0 || (seen ^ invert)==0 ){
129496 if( noCase && sqlite3Tolower(c)==sqlite3Tolower(c2) && c<0x80 && c2<0x80 ){
129499 if( c==matchOne && zPattern!=zEscaped && c2!=0 ) continue;
129502 return *zString==0 ? SQLITE_MATCH : SQLITE_NOMATCH;
129506 ** The sqlite3_strglob() interface. Return 0 on a match (like strcmp()) and
129510 if( zString==0 ){
129511 return zGlobPattern!=0;
129512 }else if( zGlobPattern==0 ){
129520 ** The sqlite3_strlike() interface. Return 0 on a match and non-zero for
129524 if( zStr==0 ){
129525 return zPattern!=0;
129526 }else if( zPattern==0 ){
129539 SQLITE_API int sqlite3_like_count = 0;
129568 if( sqlite3_value_type(argv[0])==SQLITE_BLOB
129574 sqlite3_result_int(context, 0);
129582 nPat = sqlite3_value_bytes(argv[0]);
129594 if( zEsc==0 ) return;
129604 if( escape==pInfo->matchAll ) pInfo->matchAll = 0;
129605 if( escape==pInfo->matchOne ) pInfo->matchOne = 0;
129610 zB = sqlite3_value_text(argv[0]);
129633 if( sqlite3MemCompare(argv[0], argv[1], pColl)!=0 ){
129634 sqlite3_result_value(context, argv[0]);
129681 sqlite3_log(sqlite3_value_int(argv[0]), "%s", sqlite3_value_text(argv[1]));
129702 if( (zOptName = (const char*)sqlite3_value_text(argv[0]))!=0 ){
129725 n = sqlite3_value_int(argv[0]);
129733 '0', '1', '2', '3', '4', '5', '6', '7',
129745 assert( pStr!=0 && pStr->nChar==0 );
129772 if( pStr->accError==0 ){
129775 for(i=0; i<nBlob; i++){
129776 zText[(i*2)+2] = hexdigits[(zBlob[i]>>4)&0x0F];
129777 zText[(i*2)+3] = hexdigits[(zBlob[i])&0x0F];
129780 zText[(nBlob*2)+3] = '\0';
129781 zText[0] = 'X';
129815 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
129816 sqlite3QuoteValue(&str,argv[0]);
129834 const unsigned char *z = sqlite3_value_text(argv[0]);
129836 if( z && z[0] ) sqlite3_result_int(context, sqlite3Utf8Read(&z));
129852 if( z==0 ){
129856 for(i=0; i<argc; i++){
129860 if( x<0 || x>0x10ffff ) x = 0xfffd;
129861 c = (unsigned)(x & 0x1fffff);
129862 if( c<0x00080 ){
129863 *zOut++ = (u8)(c&0xFF);
129864 }else if( c<0x00800 ){
129865 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F);
129866 *zOut++ = 0x80 + (u8)(c & 0x3F);
129867 }else if( c<0x10000 ){
129868 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F);
129869 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F);
129870 *zOut++ = 0x80 + (u8)(c & 0x3F);
129872 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07);
129873 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F);
129874 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F);
129875 *zOut++ = 0x80 + (u8)(c & 0x3F);
129878 *zOut = 0;
129896 pBlob = sqlite3_value_blob(argv[0]);
129897 n = sqlite3_value_bytes(argv[0]);
129898 assert( pBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
129901 for(i=0; i<n; i++, pBlob++){
129903 *(z++) = hexdigits[(c>>4)&0xf];
129904 *(z++) = hexdigits[c&0xf];
129906 *z = 0;
129914 ** contains character ch, or 0 if it does not.
129923 return 0;
129954 int nPass = 0;
129955 const u8 *zHex = sqlite3_value_text(argv[0]);
129956 int nHex = sqlite3_value_bytes(argv[0]);
129958 const u8 *zEnd = zHex ? &zHex[nHex] : 0;
129960 u8 *pBlob = 0;
129961 u8 *p = 0;
129975 while( (c = *zHex)!=0x00 ){
129981 if( c==0x00 ) goto unhex_done;
129984 assert( *zEnd==0x00 );
130014 n = sqlite3_value_int64(argv[0]);
130015 if( n<0 ) n = 0;
130048 zStr = sqlite3_value_text(argv[0]);
130049 if( zStr==0 ) return;
130050 nStr = sqlite3_value_bytes(argv[0]);
130051 assert( zStr==sqlite3_value_text(argv[0]) ); /* No encoding change */
130053 if( zPattern==0 ){
130058 if( zPattern[0]==0 ){
130066 if( zRep==0 ) return;
130072 if( zOut==0 ){
130076 cntExpand = 0;
130077 for(i=j=0; i<=loopLimit; i++){
130078 if( zStr[i]!=zPattern[0] || memcmp(&zStr[i], zPattern, nPattern) ){
130091 if( (cntExpand&(cntExpand-1))==0 ){
130097 if( zOut==0 ){
130113 zOut[j] = 0;
130119 ** The userdata is 0x1 for left trim, 0x2 for right trim, 0x3 for both.
130131 unsigned int *aLen = 0; /* Length of each character in zCharSet */
130132 unsigned char **azChar = 0; /* Individual characters in zCharSet */
130135 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
130138 zIn = sqlite3_value_text(argv[0]);
130139 if( zIn==0 ) return;
130140 nIn = (unsigned)sqlite3_value_bytes(argv[0]);
130141 assert( zIn==sqlite3_value_text(argv[0]) );
130148 zCharSet = 0;
130149 }else if( (zCharSet = sqlite3_value_text(argv[1]))==0 ){
130153 for(z=zCharSet, nChar=0; *z; nChar++){
130156 if( nChar>0 ){
130159 if( azChar==0 ){
130163 for(z=zCharSet, nChar=0; *z; nChar++){
130170 if( nChar>0 ){
130173 while( nIn>0 ){
130174 unsigned int len = 0;
130175 for(i=0; i<nChar; i++){
130177 if( len<=nIn && memcmp(zIn, azChar[i], len)==0 ) break;
130185 while( nIn>0 ){
130186 unsigned int len = 0;
130187 for(i=0; i<nChar; i++){
130189 if( len<=nIn && memcmp(&zIn[nIn-len],azChar[i],len)==0 ) break;
130215 i64 j, k, n = 0;
130218 for(i=0; i<argc; i++){
130223 if( z==0 ){
130227 j = 0;
130228 for(i=0; i<argc; i++){
130230 if( k>0 ){
130232 if( v!=0 ){
130233 if( j>0 && nSep>0 ){
130242 z[j] = 0;
130256 concatFuncCore(context, argc, argv, 0, "");
130271 int nSep = sqlite3_value_bytes(argv[0]);
130272 const char *zSep = (const char*)sqlite3_value_text(argv[0]);
130273 if( zSep==0 ) return;
130321 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
130322 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
130323 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
130324 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
130325 0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
130326 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
130327 0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
130328 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
130331 zIn = (u8*)sqlite3_value_text(argv[0]);
130332 if( zIn==0 ) zIn = (u8*)"";
130333 for(i=0; zIn[i] && !sqlite3Isalpha(zIn[i]); i++){}
130335 u8 prevcode = iCode[zIn[i]&0x7f];
130336 zResult[0] = sqlite3Toupper(zIn[i]);
130338 int code = iCode[zIn[i]&0x7f];
130339 if( code>0 ){
130342 zResult[j++] = code + '0';
130345 prevcode = 0;
130349 zResult[j++] = '0';
130351 zResult[j] = 0;
130366 const char *zFile = (const char *)sqlite3_value_text(argv[0]);
130369 char *zErrMsg = 0;
130374 if( (db->flags & SQLITE_LoadExtFunc)==0 ){
130382 zProc = 0;
130476 type = sqlite3_value_numeric_type(argv[0]);
130479 if( p->approx==0 ){
130483 kahanBabuskaNeumaierStep(p, sqlite3_value_double(argv[0]));
130486 if( sqlite3AddInt64(&x, sqlite3_value_int64(argv[0]))==0 ){
130492 kahanBabuskaNeumaierStepInt64(p, sqlite3_value_int64(argv[0]));
130497 kahanBabuskaNeumaierStepInt64(p, sqlite3_value_int64(argv[0]));
130499 p->ovrfl = 0;
130500 kahanBabuskaNeumaierStep(p, sqlite3_value_double(argv[0]));
130512 type = sqlite3_value_numeric_type(argv[0]);
130516 assert( p->cnt>0 );
130519 p->iSum -= sqlite3_value_int64(argv[0]);
130521 i64 iVal = sqlite3_value_int64(argv[0]);
130529 kahanBabuskaNeumaierStep(p, -sqlite3_value_double(argv[0]));
130534 # define sumInverse 0
130538 p = sqlite3_aggregate_context(context, 0);
130539 if( p && p->cnt>0 ){
130555 p = sqlite3_aggregate_context(context, 0);
130556 if( p && p->cnt>0 ){
130570 p = sqlite3_aggregate_context(context, 0);
130600 if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && p ){
130609 assert( argc==1 || p==0 || p->n>0x7fffffff || p->bInverse
130615 p = sqlite3_aggregate_context(context, 0);
130616 sqlite3_result_int64(context, p ? p->n : 0);
130623 if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && ALWAYS(p) ){
130631 # define countInverse 0
130642 Mem *pArg = (Mem *)argv[0];
130661 ** aggregate, or 0 for min().
130663 max = sqlite3_user_data(context)!=0;
130665 if( (max && cmp<0) || (!max && cmp>0) ){
130677 pRes = (sqlite3_value *)sqlite3_aggregate_context(context, 0);
130682 if( bValue==0 ) sqlite3VdbeMemRelease(pRes);
130690 # define minMaxValue 0
130693 minMaxValueFinalize(context, 0);
130711 /* If pnSepLengths!=0, refs an array of inter-string separator lengths,
130714 ** If pnSepLengths==0, nFirstSepLength is the length used throughout.
130730 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
130734 int firstTerm = pGCC->str.mxAlloc==0;
130753 nSep = 0;
130755 if( nSep != pGCC->nFirstSepLength || pGCC->pnSepLengths != 0 ){
130757 if( pnsl == 0 ){
130760 if( pnsl!=0 ){
130761 int i = 0, nA = pGCC->nAccum-1;
130767 if( pnsl!=0 ){
130768 if( ALWAYS(pGCC->nAccum>0) ){
130784 zVal = (char*)sqlite3_value_text(argv[0]);
130785 nVal = sqlite3_value_bytes(argv[0]);
130799 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
130807 (void)sqlite3_value_text(argv[0]);
130808 nVS = sqlite3_value_bytes(argv[0]);
130810 if( pGCC->pnSepLengths!=0 ){
130811 assert(pGCC->nAccum >= 0);
130812 if( pGCC->nAccum>0 ){
130822 pGCC->str.nChar = 0;
130827 if( pGCC->str.nChar==0 ){
130828 pGCC->str.mxAlloc = 0;
130830 pGCC->pnSepLengths = 0;
130835 # define groupConcatInverse 0
130839 = (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
130850 = (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
130857 }else if( pGCC->nAccum>0 && pAccum->nChar==0 ){
130866 # define groupConcatValue 0
130901 0, 0, 0, 0, 0);
130902 pDef = sqlite3FindFunction(db, "like", nArg, SQLITE_UTF8, 0);
130911 ** then set aWc[0] through aWc[2] to the wildcard characters and the
130928 assert( pExpr!=0 );
130932 return 0;
130936 pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0);
130938 if( pDef==0 ) return 0;
130940 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
130941 return 0;
130954 aWc[3] = 0;
130958 if( pEscape->op!=TK_STRING ) return 0;
130961 if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
130962 if( zEscape[0]==aWc[0] ) return 0;
130963 if( zEscape[0]==aWc[1] ) return 0;
130964 aWc[3] = zEscape[0];
130967 *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0;
131002 switch( sqlite3_value_numeric_type(argv[0]) ){
131004 sqlite3_result_int64(context, sqlite3_value_int64(argv[0]));
131009 sqlite3_result_double(context, x(sqlite3_value_double(argv[0])));
131030 #if defined(HAVE_LOG10) && HAVE_LOG10==0
131033 #if defined(HAVE_LOG2) && HAVE_LOG2==0
131053 switch( sqlite3_value_numeric_type(argv[0]) ){
131056 x = sqlite3_value_double(argv[0]);
131063 switch( sqlite3_value_numeric_type(argv[0]) ){
131111 type0 = sqlite3_value_numeric_type(argv[0]);
131113 v0 = sqlite3_value_double(argv[0]);
131133 type0 = sqlite3_value_numeric_type(argv[0]);
131137 v0 = sqlite3_value_double(argv[0]);
131145 ** Implementation of 0-argument pi() function.
131152 assert( argc==0 );
131171 type0 = sqlite3_value_numeric_type(argv[0]);
131173 x = sqlite3_value_double(argv[0]);
131174 sqlite3_result_int(context, x<0.0 ? -1 : x>0.0 ? +1 : 0);
131195 x = sqlite3_value_double(argv[0]);
131229 TEST_FUNC(implies_nonnull_row, 2, INLINEFUNC_implies_nonnull_row, 0),
131230 TEST_FUNC(expr_compare, 2, INLINEFUNC_expr_compare, 0),
131231 TEST_FUNC(expr_implies_expr, 2, INLINEFUNC_expr_implies_expr, 0),
131232 TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0),
131236 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
131239 SFUNCTION(load_extension, 1, 0, 0, loadExt ),
131240 SFUNCTION(load_extension, 2, 0, 0, loadExt ),
131243 FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ),
131246 DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
131247 DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
131253 INLINE_FUNC(sqlite_offset, 1, INLINEFUNC_sqlite_offset, 0 ),
131255 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
131256 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
131257 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
131258 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
131259 FUNCTION(trim, 1, 3, 0, trimFunc ),
131260 FUNCTION(trim, 2, 3, 0, trimFunc ),
131261 FUNCTION(min, -1, 0, 1, minmaxFunc ),
131262 FUNCTION(min, 0, 0, 1, 0 ),
131263 WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
131266 FUNCTION(max, 0, 1, 1, 0 ),
131267 WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
131269 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
131270 FUNCTION2(subtype, 1, 0, 0, subtypeFunc, SQLITE_FUNC_TYPEOF),
131271 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
131272 FUNCTION2(octet_length, 1, 0, 0, bytelengthFunc,SQLITE_FUNC_BYTELEN),
131273 FUNCTION(instr, 2, 0, 0, instrFunc ),
131274 FUNCTION(printf, -1, 0, 0, printfFunc ),
131275 FUNCTION(format, -1, 0, 0, printfFunc ),
131276 FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
131277 FUNCTION(char, -1, 0, 0, charFunc ),
131278 FUNCTION(abs, 1, 0, 0, absFunc ),
131280 FUNCTION(fpdecode, 3, 0, 0, fpdecodeFunc ),
131283 FUNCTION(round, 1, 0, 0, roundFunc ),
131284 FUNCTION(round, 2, 0, 0, roundFunc ),
131286 FUNCTION(upper, 1, 0, 0, upperFunc ),
131287 FUNCTION(lower, 1, 0, 0, lowerFunc ),
131288 FUNCTION(hex, 1, 0, 0, hexFunc ),
131289 FUNCTION(unhex, 1, 0, 0, unhexFunc ),
131290 FUNCTION(unhex, 2, 0, 0, unhexFunc ),
131291 FUNCTION(concat, -1, 0, 0, concatFunc ),
131292 FUNCTION(concat, 0, 0, 0, 0 ),
131293 FUNCTION(concat_ws, -1, 0, 0, concatwsFunc ),
131294 FUNCTION(concat_ws, 0, 0, 0, 0 ),
131295 FUNCTION(concat_ws, 1, 0, 0, 0 ),
131296 INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, 0 ),
131297 VFUNCTION(random, 0, 0, 0, randomFunc ),
131298 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
131299 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
131300 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
131301 DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
131302 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
131303 FUNCTION(quote, 1, 0, 0, quoteFunc ),
131304 VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
131305 VFUNCTION(changes, 0, 0, 0, changes ),
131306 VFUNCTION(total_changes, 0, 0, 0, total_changes ),
131307 FUNCTION(replace, 3, 0, 0, replaceFunc ),
131308 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
131309 FUNCTION(substr, 2, 0, 0, substrFunc ),
131310 FUNCTION(substr, 3, 0, 0, substrFunc ),
131311 FUNCTION(substring, 2, 0, 0, substrFunc ),
131312 FUNCTION(substring, 3, 0, 0, substrFunc ),
131313 WAGGREGATE(sum, 1,0,0, sumStep, sumFinalize, sumFinalize, sumInverse, 0),
131314 WAGGREGATE(total, 1,0,0, sumStep,totalFinalize,totalFinalize,sumInverse, 0),
131315 WAGGREGATE(avg, 1,0,0, sumStep, avgFinalize, avgFinalize, sumInverse, 0),
131316 WAGGREGATE(count, 0,0,0, countStep,
131319 WAGGREGATE(count, 1,0,0, countStep,
131321 WAGGREGATE(group_concat, 1, 0, 0, groupConcatStep,
131322 groupConcatFinalize, groupConcatValue, groupConcatInverse, 0),
131323 WAGGREGATE(group_concat, 2, 0, 0, groupConcatStep,
131324 groupConcatFinalize, groupConcatValue, groupConcatInverse, 0),
131325 WAGGREGATE(string_agg, 2, 0, 0, groupConcatStep,
131326 groupConcatFinalize, groupConcatValue, groupConcatInverse, 0),
131337 FUNCTION(unknown, -1, 0, 0, unknownFunc ),
131339 FUNCTION(coalesce, 1, 0, 0, 0 ),
131340 FUNCTION(coalesce, 0, 0, 0, 0 ),
131348 FUNCTION(ln, 1, 0, 0, logFunc ),
131349 FUNCTION(log, 1, 1, 0, logFunc ),
131350 FUNCTION(log10, 1, 1, 0, logFunc ),
131351 FUNCTION(log2, 1, 2, 0, logFunc ),
131352 FUNCTION(log, 2, 0, 0, logFunc ),
131375 FUNCTION(pi, 0, 0, 0, piFunc ),
131377 FUNCTION(sign, 1, 0, 0, signFunc ),
131378 INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ),
131379 INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ),
131389 #if 0 /* Enable to print out how the built-in functions are hashed */
131393 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
131397 int h = p->zName[0] + n;
131598 Index *pIdx = 0; /* Value to return via *ppIdx */
131599 int *aiCol = 0; /* Value to return via *paiCol */
131601 char *zKey = pFKey->aCol[0].zCol; /* Name of left-most parent key column */
131604 assert( ppIdx && *ppIdx==0 );
131605 assert( !paiCol || *paiCol==0 );
131624 if( pParent->iPKey>=0 ){
131625 if( !zKey ) return 0;
131627 return 0;
131638 if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) && pIdx->pPartIdxWhere==0 ){
131643 if( zKey==0 ){
131650 for(i=0; i<nCol; i++) aiCol[i] = pFKey->aCol[i].iFrom;
131660 for(i=0; i<nCol; i++){
131665 if( iCol<0 ) break; /* No foreign keys against expression indexes */
131675 for(j=0; j<nCol; j++){
131676 if( sqlite3StrICmp(pFKey->aCol[j].zCol, zIdxCol)==0 ){
131699 return 0;
131757 if( nIncr<0 ){
131761 for(i=0; i<pFKey->nCol; i++){
131766 if( isIgnore==0 ){
131767 if( pIdx==0 ){
131779 sqlite3TableColumnToStorage(pFKey->pFrom,aiCol[0])+1+regData, regTemp);
131780 iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
131793 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
131804 for(i=0; i<nCol; i++){
131822 for(i=0; i<nCol; i++){
131828 assert( pIdx->aiColumn[i]>=0 );
131840 sqlite3VdbeAddOp4(v, OP_Affinity, regTemp, nCol, 0,
131858 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
131860 if( nIncr>0 && pFKey->isDeferred==0 ){
131890 pExpr = sqlite3Expr(db, TK_REGISTER, 0);
131892 if( iCol>=0 && iCol!=pTab->iPKey ){
131897 if( zColl==0 ) zColl = db->pDfltColl->zName;
131917 Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
131967 Expr *pWhere = 0; /* WHERE clause to scan with */
131970 int iFkIfZero = 0; /* Address of OP_FkIfZero */
131973 assert( pIdx==0 || pIdx->pTable==pTab );
131974 assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
131975 assert( pIdx!=0 || pFKey->nCol==1 );
131976 assert( pIdx!=0 || HasRowid(pTab) );
131978 if( nIncr<0 ){
131979 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
131991 for(i=0; i<pFKey->nCol; i++){
132000 iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
132001 assert( iCol>=0 );
132022 if( pTab==pFKey->pFrom && nIncr>0 ){
132028 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
132031 Expr *pEq, *pAll = 0;
132032 assert( pIdx!=0 );
132033 for(i=0; i<pIdx->nKeyCol; i++){
132035 assert( iCol>=0 );
132041 pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
132047 memset(&sNameContext, 0, sizeof(NameContext));
132055 if( pParse->nErr==0 ){
132056 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0, 0);
132120 fkTriggerDelete(db, pFKey->apTrigger[0]); pFKey->apTrigger[0] = 0;
132121 fkTriggerDelete(db, pFKey->apTrigger[1]); pFKey->apTrigger[1] = 0;
132146 int iSkip = 0;
132151 if( sqlite3FkReferences(pTab)==0 ){
132167 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0);
132168 pParse->disableTriggers = 0;
132179 if( (db->flags & SQLITE_DeferFKs)==0 ){
132181 sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
132184 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
132213 for(i=0; i<p->nCol; i++){
132215 if( aChange[iChildKey]>=0 ) return 1;
132218 return 0;
132240 for(i=0; i<p->nCol; i++){
132243 for(iKey=0; iKey<pTab->nCol; iKey++){
132244 if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){
132247 if( 0==sqlite3StrICmp(pCol->zCnName, zKey) ) return 1;
132254 return 0;
132266 if( (p==pFKey->apTrigger[0] && pFKey->aAction[0]==OE_SetNull)
132269 assert( (pTop->db->flags & SQLITE_FkNoAction)==0 );
132273 return 0;
132301 int *aChange, /* Array indicating UPDATEd columns (or 0) */
132311 assert( (regOld==0)!=(regNew==0) );
132314 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
132324 Index *pIdx = 0; /* Index on key columns in pTo */
132325 int *aiFree = 0;
132329 int bIgnore = 0;
132332 && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
132333 && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
132345 pTo = sqlite3LocateTable(pParse, 0, pFKey->zTo, zDb);
132348 assert( isIgnoreErrors==0 || (regOld!=0 && regNew==0) );
132350 if( pTo==0 ){
132360 for(i=0; i<pFKey->nCol; i++){
132375 iCol = pFKey->aCol[0].iFrom;
132378 for(i=0; i<pFKey->nCol; i++){
132382 assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
132399 sqlite3TableLock(pParse, iDb, pTo->tnum, 0, pTo->zName);
132402 if( regOld!=0 ){
132408 if( regNew!=0 && !isSetNullAction(pParse, pFKey) ){
132426 Index *pIdx = 0; /* Foreign key index for pFKey */
132428 int *aiCol = 0;
132430 if( aChange && fkParentIsModified(pTab, pFKey, aChange, bChngRowid)==0 ){
132437 assert( regOld==0 && regNew!=0 );
132451 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
132459 if( regNew!=0 ){
132462 if( regOld!=0 ){
132463 int eAction = pFKey->aAction[aChange!=0];
132488 pItem->zName = 0;
132495 #define COLUMN_MASK(x) (((x)>31) ? 0xffffffff : ((u32)1<<(x)))
132505 u32 mask = 0;
132510 for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
132513 Index *pIdx = 0;
132514 sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0);
132516 for(i=0; i<pIdx->nKeyCol; i++){
132517 assert( pIdx->aiColumn[i]>=0 );
132534 ** the value is 0 or greater. Parameter chngRowid is set to true if the
132558 int bHaveFK = 0; /* If FK processing is required */
132573 if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) eRet = 2;
132581 if( (pParse->db->flags & SQLITE_FkNoAction)==0
132591 return bHaveFK ? eRet : 0;
132632 int iAction = (pChanges!=0); /* 1 for UPDATE, 0 for DELETE */
132637 return 0;
132644 Index *pIdx = 0; /* Parent key index for this FK */
132645 int *aiCol = 0; /* child table cols -> parent key cols */
132646 TriggerStep *pStep = 0; /* First (only) step of trigger program */
132647 Expr *pWhere = 0; /* WHERE clause of trigger step */
132648 ExprList *pList = 0; /* Changes list if ON UPDATE CASCADE */
132649 Select *pSelect = 0; /* If RESTRICT, "SELECT RAISE(...)" */
132651 Expr *pWhen = 0; /* WHEN clause for the trigger */
132653 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ) return 0;
132656 for(i=0; i<pFKey->nCol; i++){
132664 iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
132665 assert( iFromCol>=0 );
132666 assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
132667 assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
132678 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
132679 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
132680 sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
132692 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
132693 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
132695 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
132696 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0))
132705 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
132706 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0));
132713 pDflt = 0;
132718 pNew = sqlite3ExprDup(db, pDflt, 0);
132720 pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
132723 pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
132726 sqlite3ExprListSetName(pParse, pList, &tFromCol, 0);
132743 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
132746 pSrc->a[0].zName = sqlite3DbStrDup(db, zFrom);
132747 pSrc->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
132750 sqlite3ExprListAppend(pParse, 0, pRaise),
132753 0, 0, 0, 0, 0
132755 pWhere = 0;
132775 pWhen = sqlite3PExpr(pParse, TK_NOT, pWhen, 0);
132789 return 0;
132791 assert( pStep!=0 );
132792 assert( pTrigger!=0 );
132826 int *aChange, /* Array indicating UPDATEd columns (or 0) */
132836 if( aChange==0 || fkParentIsModified(pTab, pFKey, aChange, bChngRowid) ){
132839 sqlite3CodeRowTriggerDirect(pParse, pAct, pTab, regOld, OE_Abort, 0);
132858 assert( db!=0 );
132860 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
132863 if( db->pnBytesFreed==0 ){
132878 assert( pFKey->isDeferred==0 || pFKey->isDeferred==1 );
132882 fkTriggerDelete(db, pFKey->apTrigger[0]);
132928 assert( pParse->pVdbe!=0 );
132933 (opcode==OP_OpenWrite)?1:0, pTab->zName);
132940 assert( pPk!=0 );
132979 pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
132982 return 0;
132984 for(n=0; n<pIdx->nColumn; n++){
132987 if( x>=0 ){
132994 assert( pIdx->aColExpr!=0 );
133001 pIdx->zColAff[n] = 0;
133020 for(i=j=0; i<pTab->nCol; i++){
133021 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
133026 zColAff[j--] = 0;
133027 }while( j>=0 && zColAff[j]<=SQLITE_AFF_BLOB );
133045 ** Otherwise if iReg>0 then code an OP_Affinity opcode that will set the
133046 ** affinities for register iReg and following. Or if iReg==0,
133064 ** datatypes against the column definitions in pTab. If iReg==0, that
133068 ** register set as the OP_MakeRecord. If iReg>0 then register iReg is
133076 if( iReg==0 ){
133083 assert( pPrev!=0 );
133095 if( zColAff==0 ){
133096 zColAff = sqlite3TableAffinityStr(0, pTab);
133103 assert( zColAff!=0 );
133107 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i);
133127 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
133132 assert( pOp!=0 );
133147 assert( pOp->p4.pVtab!=0 );
133153 return 0;
133160 if( pExpr->op==TK_COLUMN && pExpr->iColumn>=0 ){
133194 if( (pTab->tabFlags & TF_HasStored)!=0 ){
133202 assert( zP4!=0 );
133204 for(ii=jj=0; zP4[jj]; ii++){
133225 for(i=0; i<pTab->nCol; i++){
133235 w.xSelectCallback = 0;
133236 w.xSelectCallback2 = 0;
133245 eProgress = 0;
133246 pRedo = 0;
133247 for(i=0; i<pTab->nCol; i++){
133249 if( (pCol->colFlags & COLFLAG_NOTAVAIL)!=0 ){
133252 w.eCode = 0;
133270 pParse->iSelfTab = 0;
133304 int memId = 0; /* Register holding maximum rowid */
133305 assert( pParse->db->aDb[iDb].pSchema!=0 );
133306 if( (pTab->tabFlags & TF_Autoincrement)!=0
133307 && (pParse->db->mDbFlags & DBFLAG_Vacuum)==0
133316 if( pSeqTab==0
133323 return 0;
133328 if( pInfo==0 ){
133332 if( pParse->db->mallocFailed ) return 0;
133359 assert( pParse->pTriggerTab==0 );
133366 /* 0 */ {OP_Null, 0, 0, 0},
133367 /* 1 */ {OP_Rewind, 0, 10, 0},
133368 /* 2 */ {OP_Column, 0, 0, 0},
133369 /* 3 */ {OP_Ne, 0, 9, 0},
133370 /* 4 */ {OP_Rowid, 0, 0, 0},
133371 /* 5 */ {OP_Column, 0, 1, 0},
133372 /* 6 */ {OP_AddImm, 0, 0, 0},
133373 /* 7 */ {OP_Copy, 0, 0, 0},
133374 /* 8 */ {OP_Goto, 0, 11, 0},
133375 /* 9 */ {OP_Next, 0, 2, 0},
133376 /* 10 */ {OP_Integer, 0, 0, 0},
133377 /* 11 */ {OP_Close, 0, 0, 0}
133382 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
133383 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
133386 if( aOp==0 ) break;
133387 aOp[0].p2 = memId;
133388 aOp[0].p3 = memId+2;
133399 if( pParse->nTab==0 ) pParse->nTab = 1;
133412 if( memId>0 ){
133433 /* 0 */ {OP_NotNull, 0, 2, 0},
133434 /* 1 */ {OP_NewRowid, 0, 0, 0},
133435 /* 2 */ {OP_MakeRecord, 0, 2, 0},
133436 /* 3 */ {OP_Insert, 0, 0, 0},
133437 /* 4 */ {OP_Close, 0, 0, 0}
133445 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
133448 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
133450 if( aOp==0 ) break;
133451 aOp[0].p1 = memId+1;
133469 # define autoIncBegin(A,B,C) (0)
133479 if( ALWAYS(pVal) && pVal->pSrc->nSrc>0 ){
133480 SrcItem *pItem = &pVal->pSrc->a[0];
133492 for(ii=0; ii<pRow->nExpr; ii++){
133493 if( 0==sqlite3ExprIsConstant(pParse, pRow->a[ii].pExpr) ) return 0;
133504 if( exprListIsConstant(pParse,pRow)==0 ) return 0;
133505 for(ii=0; ii<pRow->nExpr; ii++){
133508 assert( pExpr->affExpr==0 );
133509 if( 0!=sqlite3ExprAffinity(pExpr) ) return 0;
133570 || exprListIsConstant(pParse,pRow)==0 /* condition (c) above */
133571 || (pLeft->pSrc->nSrc==0 &&
133572 exprListIsNoAffinity(pParse,pLeft->pEList)==0) /* condition (d) above */
133576 Select *pSelect = 0;
133585 pSelect = sqlite3SelectNew(pParse, pRow, 0, 0, 0, 0, 0, f, 0);
133593 SrcItem *p = 0; /* SrcItem that reads from co-routine */
133595 if( pLeft->pSrc->nSrc==0 ){
133600 Select *pRet = sqlite3SelectNew(pParse, 0, 0, 0, 0, 0, 0, 0, 0);
133604 if( (pParse->db->mDbFlags & DBFLAG_SchemaKnownOk)==0 ){
133614 pLeft->pPrior = 0;
133616 assert( pLeft->pNext==0 );
133617 assert( pRet->pNext==0 );
133618 p = &pRet->pSrc->a[0];
133625 sqlite3VdbeAddOp3(v,OP_InitCoroutine,p->regReturn,0,p->addrFillSub);
133640 assert( pParse->nErr || dest.iSdst>0 );
133644 p = &pLeft->pSrc->a[0];
133649 if( pParse->nErr==0 ){
133650 assert( p!=0 );
133654 sqlite3ExprCodeExprList(pParse, pRow, p->regResult, 0, 0);
133784 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
133785 int iDataCur = 0; /* VDBE cursor that is the main data repository */
133786 int iIdxCur = 0; /* First index cursor */
133789 int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
133790 int addrInsTop = 0; /* Jump to label "D" */
133791 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
133794 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
133795 u8 appendFlag = 0; /* True if the insert is likely to be an append */
133796 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
133798 ExprList *pList = 0; /* List of VALUES() to be inserted */
133802 int regFromSelect = 0;/* Base register for data coming from SELECT */
133803 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
133804 int regRowCount = 0; /* Memory cell used for the row counter */
133808 int *aRegIdx = 0; /* One register allocated to each index */
133821 assert( db->mallocFailed==0 );
133822 dest.iSDParm = 0; /* Suppress a harmless compiler warning */
133828 if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
133830 pSelect->pEList = 0;
133832 pSelect = 0;
133839 if( pTab==0 ){
133844 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0,
133854 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0, &tmask);
133857 # define pTrigger 0
133858 # define tmask 0
133859 # define isView 0
133863 # define isView 0
133865 assert( (pTrigger && tmask) || (pTrigger==0 && tmask==0) );
133868 if( sqlite3TreeTrace & 0x10000 ){
133869 sqlite3TreeViewLine(0, "In sqlite3Insert() at %s:%d", __FILE__, __LINE__);
133891 if( v==0 ) goto insert_cleanup;
133892 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
133905 if( pColumn==0
133906 && pSelect!=0
133907 && pTrigger==0
133911 assert( pList==0 );
133951 bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
133955 for(i=0; i<pColumn->nId; i++){
133958 for(i=0; i<pColumn->nId; i++){
133959 for(j=0; j<pTab->nCol; j++){
133960 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zCnName)==0 ){
133962 if( i!=j ) bIdListInOrder = 0;
133980 bIdListInOrder = 0;
134002 && pSelect->pSrc->a[0].fg.viaCoroutine
134003 && pSelect->pPrior==0
134005 SrcItem *pItem = &pSelect->pSrc->a[0];
134009 ExplainQueryPlan((pParse, 0, "SCAN %S", pItem));
134013 regIns = regRowid - (IsVirtual(pTab) ? 1 : 0);
134019 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
134021 dest.iSdst = bIdListInOrder ? regData : 0;
134027 assert( db->mallocFailed==0 );
134080 memset(&sNC, 0, sizeof(sNC));
134083 assert( useTempTable==0 );
134090 nColumn = 0;
134098 if( pColumn==0 && nColumn>0 ){
134101 if( ipkColumn>=0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
134104 for(i=ipkColumn-1; i>=0; i--){
134120 if( (pTab->tabFlags & (TF_HasGenerated|TF_HasHidden))!=0 ){
134121 for(i=0; i<pTab->nCol; i++){
134132 if( pColumn!=0 && nColumn!=pColumn->nId ){
134139 if( (db->flags & SQLITE_CountRows)!=0
134145 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
134151 nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, -1, 0,
134154 if( aRegIdx==0 ){
134157 for(i=0, pIdx=pTab->pIndex; i<nIdx; pIdx=pIdx->pNext, i++){
134179 pTabList->a[0].iCursor = iDataCur;
134192 }while( pNx!=0 );
134219 sqlite3VdbeReleaseRegisters(pParse, regData, pTab->nCol, 0, 0);
134222 if( ipkColumn>=0 ){
134237 nHidden = 0;
134239 for(i=0; i<pTab->nCol; i++, iRegStore++){
134251 if( ((colFlags = pTab->aCol[i].colFlags) & COLFLAG_NOINSERT)!=0 ){
134253 if( (colFlags & COLFLAG_VIRTUAL)!=0 ){
134259 }else if( (colFlags & COLFLAG_STORED)!=0 ){
134268 }else if( pColumn==0 ){
134279 for(j=0; j<pColumn->nId && pColumn->a[j].u4.idx!=i; j++){}
134289 }else if( nColumn==0 ){
134328 if( ipkColumn<0 ){
134336 assert( pSelect==0 ); /* Otherwise useTempTable is true */
134346 assert( pTab->nNVCol>0 || pParse->nErr>0 );
134371 sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE,
134380 sqlite3VdbeAddOp2(v, OP_Null, 0, regIns);
134382 if( ipkColumn>=0 ){
134413 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
134443 int isReplace = 0;/* Set to true if constraints may cause a replace */
134446 regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert
134449 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
134460 bUseSeek = (isReplace==0 || !sqlite3VdbeHasSubProgram(v));
134462 regIns, aRegIdx, 0, appendFlag, bUseSeek
134482 sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_AFTER,
134515 if( pParse->nested==0 && pParse->pTriggerTab==0 ){
134554 #define CKCNSTRNT_COLUMN 0x01 /* CHECK constraint uses a changing column */
134555 #define CKCNSTRNT_ROWID 0x02 /* CHECK constraint references the ROWID */
134558 * Set bit 0x01 of pWalker->eCode if pWalker->eCode to 0 and if this
134564 assert( pExpr->iColumn>=0 || pExpr->iColumn==-1 );
134565 if( pExpr->iColumn>=0 ){
134566 if( pWalker->u.aiCol[pExpr->iColumn]>=0 ){
134579 ** aiChng[i]>=0, and also the ROWID is modified if chngRowid is true.
134593 int *aiChng, /* aiChng[x]>=0 if column x changed by the UPDATE */
134597 memset(&w, 0, sizeof(w));
134598 w.eCode = 0;
134603 testcase( (w.eCode & CKCNSTRNT_ROWID)!=0 );
134606 testcase( w.eCode==0 );
134610 return w.eCode!=0;
134627 int eType; /* 0 for Index.pNext list. 1 for an array of IndexListTerm */
134630 struct { /* Use this object for eType==0: A Index.pNext list */
134650 assert( pIter->i==0 );
134652 *pIx = pIter->u.ax.aIdx[0].ix;
134653 return pIter->u.ax.aIdx[0].p;
134655 *pIx = 0;
134666 return 0;
134708 ** indices where aRegIdx[i]==0. The order of indices in aRegIdx[] is
134771 int *aRegIdx, /* Use register aRegIdx[i] for index i. 0 for unused */
134775 int regOldData, /* Previous content. 0 for INSERTs */
134780 int *aiChng, /* column i is unchanged if aiChng[i]<0 */
134785 Index *pPk = 0; /* The PRIMARY KEY index for WITHOUT ROWID tables */
134791 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
134793 Upsert *pUpsertClause = 0; /* The specific ON CONFLICT clause for pIdx */
134795 u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
134796 int upsertIpkReturn = 0; /* Address of Goto at end of IPK uniqueness check */
134797 int upsertIpkDelay = 0; /* Address of Goto to bypass initial IPK check */
134798 int ipkTop = 0; /* Top of the IPK uniqueness check */
134799 int ipkBottom = 0; /* OP_Goto at the end of the IPK uniqueness check */
134803 int addrRecheck = 0; /* Jump here to recheck all uniqueness constraints */
134804 int lblRecheckOk = 0; /* Each recheck jumps to this label if it passes */
134806 int nReplaceTrig = 0; /* Number of replace triggers coded */
134809 isUpdate = regOldData!=0;
134812 assert( v!=0 );
134821 pPk = 0;
134835 int b2ndPass = 0; /* True if currently running 2nd pass */
134836 int nSeenReplace = 0; /* Number of ON CONFLICT REPLACE operations */
134837 int nGenerated = 0; /* Number of generated columns with NOT NULL */
134839 for(i=0; i<nCol; i++){
134853 if( aiChng && aiChng[i]<0 && !isGenerated ){
134864 || pCol->iDflt==0 /* REPLACE is ABORT if no DEFAULT value */
134884 assert( (pCol->colFlags & COLFLAG_GENERATED)==0 );
134898 testcase( zMsg==0 && db->mallocFailed==0 );
134914 if( nGenerated==0 && nSeenReplace==0 ){
134923 if( nSeenReplace>0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
134937 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
134941 for(i=0; i<pCheck->nExpr; i++){
134952 if( bAffinityDone==0 ){
134958 pCopy = sqlite3ExprDup(db, pExpr, 0);
134967 assert( zName!=0 || pParse->db->mallocFailed );
134975 pParse->iSelfTab = 0;
135007 sIdxIter.eType = 0;
135008 sIdxIter.i = 0;
135009 sIdxIter.u.ax.aIdx = 0; /* Silence harmless compiler warning */
135012 if( pUpsert->pUpsertTarget==0 ){
135014 assert( pUpsert->pNextUpsert==0 );
135015 if( pUpsert->isDoUpdate==0 ){
135019 pUpsert = 0;
135024 }else if( pTab->pIndex!=0 ){
135032 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
135033 assert( aRegIdx[nIdx]>0 );
135039 if( sIdxIter.u.ax.aIdx==0 ) return; /* OOM */
135042 for(i=0, pTerm=pUpsert; pTerm; pTerm=pTerm->pNextUpsert){
135043 if( pTerm->pUpsertTarget==0 ) break;
135044 if( pTerm->pUpsertIdx==0 ) continue; /* Skip ON CONFLICT for the IPK */
135045 jj = 0;
135047 while( ALWAYS(pIdx!=0) && pIdx!=pTerm->pUpsertIdx ){
135057 for(jj=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, jj++){
135087 if( (db->flags & (SQLITE_RecTriggers|SQLITE_ForeignKeys))==0 ){
135090 pTrigger = 0;
135091 regTrigCnt = 0;
135094 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
135095 regTrigCnt = pTrigger!=0 || sqlite3FkRequired(pParse, pTab, 0, 0);
135097 pTrigger = 0;
135098 regTrigCnt = sqlite3FkRequired(pParse, pTab, 0, 0);
135104 sqlite3VdbeAddOp2(v, OP_Integer, 0, regTrigCnt);
135114 if( pkChng && pPk==0 ){
135127 pUpsertClause = sqlite3UpsertOfIndex(pUpsert,0);
135128 if( pUpsertClause!=0 ){
135129 if( pUpsertClause->isDoUpdate==0 ){
135158 /* pkChng!=0 does not mean that the rowid has changed, only that
135213 regNewData, 1, 0, OE_Replace, 1, -1);
135228 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,-1);
135236 sqlite3UpsertDoUpdate(pParse, pUpsert, pTab, 0, iDataCur);
135272 if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
135280 if( bAffinityDone==0 ){
135290 sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[ix]);
135294 pParse->iSelfTab = 0;
135301 for(i=0; i<pIdx->nColumn; i++){
135307 pParse->iSelfTab = 0;
135327 sqlite3VdbeReleaseRegisters(pParse, regIdx, pIdx->nColumn, 0, 0);
135333 if( isUpdate && pPk==pIdx && pkChng==0 ){
135352 if( pUpsertClause->isDoUpdate==0 ){
135371 if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
135374 && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
135375 0==sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0))
135376 && ( 0==(db->flags&SQLITE_ForeignKeys) || /* Condition 5 */
135377 (0==pTab->u.tab.pFKey && 0==sqlite3FkReferences(pTab)))
135407 for(i=0; i<pPk->nKeyCol; i++){
135408 assert( pPk->aiColumn[i]>=0 );
135427 for(i=0; i<pPk->nKeyCol; i++){
135430 assert( x>=0 );
135476 assert( nConflictCk>0 || db->mallocFailed );
135477 testcase( nConflictCk<=0 );
135487 regR, nPkField, 0, OE_Replace,
135513 while( nConflictCk>0 ){
135552 upsertIpkReturn = 0;
135560 assert( ipkBottom>0 );
135565 testcase( regTrigCnt!=0 && nReplaceTrig==0 );
135566 assert( regTrigCnt!=0 || nReplaceTrig==0 );
135590 sqlite3TableAffinity(v, pTab, 0);
135612 for(i=pTab->nCol-1; i>0; i--){
135613 if( pTab->aCol[i].iDflt!=0 ) break;
135636 assert( 0==(pParse->db->mDbFlags & DBFLAG_Vacuum) || CORRUPT_DB );
135637 sqlite3VdbeAddOp2(v, OP_Integer, 0, r);
135661 int *aRegIdx, /* Register used by each index. 0 for unused indices */
135671 assert( update_flags==0
135677 assert( v!=0 );
135679 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
135682 || pIdx->pNext==0
135684 if( aRegIdx[i]==0 ) continue;
135689 pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
135693 if( update_flags==0 ){
135704 pik_flags = 0;
135760 assert( op==OP_OpenWrite || p5==0 );
135761 assert( piDataCur!=0 );
135762 assert( piIdxCur!=0 );
135768 return 0;
135772 assert( v!=0 );
135773 if( iBase<0 ) iBase = pParse->nTab;
135776 if( HasRowid(pTab) && (aToOpen==0 || aToOpen[0]) ){
135778 }else if( pParse->db->noSharedCache==0 ){
135782 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
135787 p5 = 0;
135789 if( aToOpen==0 || aToOpen[i+1] ){
135829 return 0; /* Different number of columns */
135832 return 0; /* Different conflict resolution strategies */
135834 for(i=0; i<pSrc->nKeyCol; i++){
135836 return 0; /* Different columns indexed */
135839 assert( pSrc->aColExpr!=0 && pDest->aColExpr!=0 );
135840 if( sqlite3ExprCompare(0, pSrc->aColExpr->a[i].pExpr,
135841 pDest->aColExpr->a[i].pExpr, -1)!=0 ){
135842 return 0; /* Different expressions in the index */
135846 return 0; /* Different sort orders */
135848 if( sqlite3_stricmp(pSrc->azColl[i],pDest->azColl[i])!=0 ){
135849 return 0; /* Different collating sequences */
135852 if( sqlite3ExprCompare(0, pSrc->pPartIdxWhere, pDest->pPartIdxWhere, -1) ){
135853 return 0; /* Different WHERE clauses */
135901 int emptyDestTest = 0; /* Address of test for empty pDest */
135902 int emptySrcTest = 0; /* Address of test for empty pSrc */
135905 int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */
135908 assert( pSelect!=0 );
135913 return 0;
135917 return 0; /* tab1 must not be a virtual table */
135921 if( pDest->iPKey>=0 ) onError = pDest->keyConf;
135926 return 0; /* FROM clause must have exactly one term */
135928 if( pSelect->pSrc->a[0].pSelect ){
135929 return 0; /* FROM clause cannot contain a subquery */
135932 return 0; /* SELECT may not have a WHERE clause */
135935 return 0; /* SELECT may not have an ORDER BY clause */
135940 return 0; /* SELECT may not have a GROUP BY clause */
135943 return 0; /* SELECT may not have a LIMIT clause */
135946 return 0; /* SELECT may not be a compound query */
135949 return 0; /* SELECT may not be DISTINCT */
135952 assert( pEList!=0 );
135954 return 0; /* The result set must have exactly one column */
135956 assert( pEList->a[0].pExpr );
135957 if( pEList->a[0].pExpr->op!=TK_ASTERISK ){
135958 return 0; /* The result set must be the special operator "*" */
135966 pSrc = sqlite3LocateTableItem(pParse, 0, pItem);
135967 if( pSrc==0 ){
135968 return 0; /* FROM clause does not contain a real table */
135972 return 0; /* tab1 and tab2 may not be the same table */
135975 return 0; /* source and destination must both be WITHOUT ROWID or not */
135978 return 0; /* tab2 may not be a view or virtual table */
135981 return 0; /* Number of columns must be the same in tab1 and tab2 */
135984 return 0; /* Both tables must have the same INTEGER PRIMARY KEY */
135986 if( (pDest->tabFlags & TF_Strict)!=0 && (pSrc->tabFlags & TF_Strict)==0 ){
135987 return 0; /* Cannot feed from a non-strict into a strict table */
135989 for(i=0; i<pDest->nCol; i++){
135993 if( (db->mDbFlags & DBFLAG_Vacuum)==0
135996 return 0; /* Neither table may have __hidden__ columns */
136018 return 0; /* Both columns have the same generated-column type */
136024 if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){
136025 if( sqlite3ExprCompare(0,
136027 sqlite3ColumnExpr(pDest, pDestCol), -1)!=0 ){
136030 return 0; /* Different generator expressions */
136035 return 0; /* Affinity must be the same on all columns */
136038 sqlite3ColumnColl(pSrcCol))!=0 ){
136039 return 0; /* Collating sequence must be the same on all columns */
136042 return 0; /* tab2 must be NOT NULL if tab1 is */
136045 if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
136048 assert( pDestExpr==0 || pDestExpr->op==TK_SPAN );
136049 assert( pDestExpr==0 || !ExprHasProperty(pDestExpr, EP_IntValue) );
136050 assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN );
136051 assert( pSrcExpr==0 || !ExprHasProperty(pSrcExpr, EP_IntValue) );
136052 if( (pDestExpr==0)!=(pSrcExpr==0)
136053 || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken,
136054 pSrcExpr->u.zToken)!=0)
136056 return 0; /* Default values must be the same for all columns */
136067 if( pSrcIdx==0 ){
136068 return 0; /* pDestIdx has no corresponding index in pSrc */
136075 return 0; /* Corrupt schema - two indexes on the same btree */
136080 && (db->mDbFlags & DBFLAG_Vacuum)==0
136083 return 0; /* Tables have different CHECK constraints. Ticket #2252 */
136095 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){
136096 return 0;
136099 if( (db->flags & SQLITE_CountRows)!=0 ){
136100 return 0; /* xfer opt does not play well with PRAGMA count_changes */
136117 sqlite3VdbeAddOp2(v, OP_Null, 0, regData);
136121 if( (db->mDbFlags & DBFLAG_Vacuum)==0 && (
136122 (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
136143 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
136150 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
136151 if( pDest->iPKey>=0 ){
136153 if( (db->mDbFlags & DBFLAG_Vacuum)==0 ){
136155 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
136161 }else if( pDest->pIndex==0 && !(db->mDbFlags & DBFLAG_VacuumInto) ){
136165 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
136175 if( (db->mDbFlags & DBFLAG_Vacuum)==0 ){
136184 if( (db->mDbFlags & DBFLAG_Vacuum)==0 ){
136190 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
136191 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
136194 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
136197 u8 idxInsFlags = 0;
136209 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
136225 for(i=0; i<pSrcIdx->nColumn; i++){
136239 if( (db->mDbFlags & DBFLAG_Vacuum)==0
136250 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
136251 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
136258 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0);
136260 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
136261 return 0;
136308 sqlite3_stmt *pStmt = 0; /* The current SQL statement */
136309 char **azCols = 0; /* Names of result columns */
136313 if( zSql==0 ) zSql = "";
136317 while( rc==SQLITE_OK && zSql[0] ){
136318 int nCol = 0;
136319 char **azVals = 0;
136321 pStmt = 0;
136323 assert( rc==SQLITE_OK || pStmt==0 );
136332 callbackIsInit = 0;
136345 if( azCols==0 ){
136348 for(i=0; i<nCol; i++){
136352 assert( azCols[i]!=0 );
136358 for(i=0; i<nCol; i++){
136365 azVals[i] = 0;
136373 pStmt = 0;
136381 pStmt = 0;
136383 while( sqlite3Isspace(zSql[0]) ) zSql++;
136389 azCols = 0;
136398 *pzErrMsg = sqlite3DbStrDup(0, sqlite3_errmsg(db));
136399 if( *pzErrMsg==0 ){
136404 *pzErrMsg = 0;
136603 /* Added by 3.5.0 */
136706 /* Version 3.9.0 and later */
136709 /* Version 3.10.0 and later */
136713 /* Version 3.12.0 and later */
136715 /* Version 3.14.0 and later */
136718 /* Version 3.18.0 and later */
136720 /* Version 3.20.0 and later */
136731 /* Version 3.24.0 and later */
136746 /* Version 3.25.0 and later */
136753 /* Version 3.26.0 and later */
136755 /* Version 3.28.0 and later */
136758 /* Version 3.30.0 and later */
136760 /* Version 3.31.0 and later */
136766 /* Version 3.32.0 and later */
136771 /* Version 3.34.0 and later */
136776 /* Version 3.37.0 and later */
136780 /* Version 3.38.0 and later */
136787 /* Version 3.39.0 and later */
136793 /* Version 3.40.0 and later */
136795 /* Version 3.41.0 and later */
136797 /* Version 3.43.0 and later */
136799 /* Version 3.44.0 and later */
137048 /* Version 3.9.0 and later */
137051 /* Version 3.10.0 and later */
137055 /* Version 3.12.0 and later */
137057 /* Version 3.14.0 and later */
137060 /* Version 3.18.0 and later */
137062 /* Version 3.20.0 and later */
137068 /* Version 3.22.0 and later */
137072 /* Version 3.24.0 and later */
137087 /* Version 3.25.0 and later */
137089 /* Version 3.26.0 and later */
137091 /* Version 3.28.0 and later */
137094 /* Version 3.30.0 and later */
137096 /* Version 3.31.0 and later */
137102 /* Version 3.32.0 and later */
137106 /* Version 3.34.0 and later */
137111 /* Version 3.37.0 and later */
137113 /* Version 3.38.0 and later */
137120 /* Version 3.39.0 and later */
137126 /* Version 3.40.0 and later */
137128 /* Version 3.41.0 and later */
137130 /* Version 3.43.0 and later */
137132 /* Version 3.44.0 and later */
137140 # define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
137165 # define sqlite3_column_database_name 0
137166 # define sqlite3_column_database_name16 0
137167 # define sqlite3_column_table_name 0
137168 # define sqlite3_column_table_name16 0
137169 # define sqlite3_column_origin_name 0
137170 # define sqlite3_column_origin_name16 0
137174 # define sqlite3_set_authorizer 0
137178 # define sqlite3_bind_text16 0
137179 # define sqlite3_collation_needed16 0
137180 # define sqlite3_column_decltype16 0
137181 # define sqlite3_column_name16 0
137182 # define sqlite3_column_text16 0
137183 # define sqlite3_complete16 0
137184 # define sqlite3_create_collation16 0
137185 # define sqlite3_create_function16 0
137186 # define sqlite3_errmsg16 0
137187 # define sqlite3_open16 0
137188 # define sqlite3_prepare16 0
137189 # define sqlite3_prepare16_v2 0
137190 # define sqlite3_prepare16_v3 0
137191 # define sqlite3_result_error16 0
137192 # define sqlite3_result_text16 0
137193 # define sqlite3_result_text16be 0
137194 # define sqlite3_result_text16le 0
137195 # define sqlite3_value_text16 0
137196 # define sqlite3_value_text16be 0
137197 # define sqlite3_value_text16le 0
137198 # define sqlite3_column_database_name16 0
137199 # define sqlite3_column_table_name16 0
137200 # define sqlite3_column_origin_name16 0
137204 # define sqlite3_complete 0
137205 # define sqlite3_complete16 0
137209 # define sqlite3_column_decltype16 0
137210 # define sqlite3_column_decltype 0
137214 # define sqlite3_progress_handler 0
137218 # define sqlite3_create_module 0
137219 # define sqlite3_create_module_v2 0
137220 # define sqlite3_declare_vtab 0
137221 # define sqlite3_vtab_config 0
137222 # define sqlite3_vtab_on_conflict 0
137223 # define sqlite3_vtab_collation 0
137227 # define sqlite3_enable_shared_cache 0
137231 # define sqlite3_profile 0
137232 # define sqlite3_trace 0
137236 # define sqlite3_free_table 0
137237 # define sqlite3_get_table 0
137241 #define sqlite3_bind_zeroblob 0
137242 #define sqlite3_blob_bytes 0
137243 #define sqlite3_blob_close 0
137244 #define sqlite3_blob_open 0
137245 #define sqlite3_blob_read 0
137246 #define sqlite3_blob_write 0
137247 #define sqlite3_blob_reopen 0
137251 # define sqlite3_trace_v2 0
137274 0,
137333 0,
137341 0, /* Was sqlite3_global_recover(), but that function is deprecated */
137377 0,
137384 0,
137424 ** Added for 3.5.0
137437 0,
137438 0,
137439 0,
137440 0,
137441 0,
137470 ** Added for 3.6.0
137490 0,
137491 0,
137506 0,
137513 0,
137514 0,
137515 0,
137551 /* Version 3.9.0 and later */
137554 /* Version 3.10.0 and later */
137558 /* Version 3.12.0 and later */
137560 /* Version 3.14.0 and later */
137563 /* Version 3.18.0 and later */
137565 /* Version 3.20.0 and later */
137571 /* Version 3.22.0 and later */
137575 /* Version 3.24.0 and later */
137590 /* Version 3.25.0 and later */
137592 /* Version 3.26.0 and later */
137596 0,
137598 /* Version 3.28.0 and later */
137601 /* Version 3.30.0 and later */
137605 0,
137607 /* Version 3.31.0 and later */
137613 /* Version 3.32.0 and later */
137617 /* Version 3.34.0 and later */
137622 /* Version 3.37.0 and later */
137624 /* Version 3.38.0 and later */
137633 0,
137634 0,
137635 0,
137636 0,
137637 0,
137639 /* Version 3.39.0 and later */
137644 0,
137645 0,
137648 /* Version 3.40.0 and later */
137650 /* Version 3.41.0 and later */
137652 /* Version 3.43.0 and later */
137654 /* Version 3.44.0 and later */
137669 ** zFile. The entry point is zProc. zProc may be 0 in which case a
137675 ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
137682 const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
137683 char **pzErrMsg /* Put error message here if not 0 */
137688 char *zErrmsg = 0;
137690 char *zAltEntry = 0;
137708 if( pzErrMsg ) *pzErrMsg = 0;
137714 ** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0)
137717 if( (db->flags & SQLITE_LoadExtension)==0 ){
137738 if( nMsg==0 ) goto extension_not_found;
137742 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
137744 if( zAltFile==0 ) return SQLITE_NOMEM_BKPT;
137751 if( handle==0 ) goto extension_not_found;
137765 if( xInit==0 && zProc==0 ){
137769 if( zAltEntry==0 ){
137774 for(iFile=ncFile-1; iFile>=0 && !DirSep(zFile[iFile]); iFile--){}
137776 if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
137777 for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
137786 if( xInit==0 ){
137791 assert( nMsg<0x7fffffff ); /* zErrmsg would be NULL if not so */
137815 if( aHandle==0 ){
137818 if( db->nExtension>0 ){
137832 assert( nMsg<0x7fffffff ); /* zErrmsg would be NULL if not so */
137843 const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
137844 char **pzErrMsg /* Put error message here if not 0 */
137861 for(i=0; i<db->nExtension; i++){
137898 } sqlite3Autoext = { 0, 0 };
137909 # define wsdAutoext x[0]
137925 if( xInit==0 ) return SQLITE_MISUSE_BKPT;
137940 for(i=0; i<wsdAutoext.nExt; i++){
137944 u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
137947 if( aNew==0 ){
137956 assert( (rc&0xff)==rc );
137967 ** Return 1 if xInit was found on the list and removed. Return 0 if xInit
137977 int n = 0;
137980 if( xInit==0 ) return 0;
137983 for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
138009 wsdAutoext.aExt = 0;
138010 wsdAutoext.nExt = 0;
138027 if( wsdAutoext.nExt==0 ){
138031 for(i=0; go; i++){
138037 const sqlite3_api_routines *pThunk = 0;
138043 xInit = 0;
138044 go = 0;
138049 zErrmsg = 0;
138050 if( xInit && (rc = xInit(db, &zErrmsg, pThunk))!=0 ){
138053 go = 0;
138080 # define SQLITE_ENABLE_LOCKING_STYLE 0
138100 #define PragTyp_ACTIVATE_EXTENSIONS 0
138148 #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
138149 #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
138150 #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
138151 #define PragFlg_ReadOnly 0x08 /* Read-only HEADER_VALUE */
138152 #define PragFlg_Result0 0x10 /* Acts as query when no argument */
138153 #define PragFlg_Result1 0x20 /* Acts as query when has one argument */
138154 #define PragFlg_SchemaOpt 0x40 /* Schema restricts name search if present */
138155 #define PragFlg_SchemaReq 0x80 /* Schema required - "main" is default */
138162 /* 0 */ "id", /* Used by: foreign_key_list */
138231 u8 nPragCName; /* Num of col names. 0 means use pragma name */
138238 /* ePragFlg: */ 0,
138239 /* ColNames: */ 0, 0,
138240 /* iArg: */ 0 },
138245 /* ColNames: */ 0, 0,
138246 /* iArg: */ 0 },
138251 /* ColNames: */ 0, 0,
138258 /* ColNames: */ 0, 0,
138259 /* iArg: */ 0 },
138266 /* ColNames: */ 0, 0,
138274 /* iArg: */ 0 },
138279 /* ColNames: */ 0, 0,
138280 /* iArg: */ 0 },
138286 /* ColNames: */ 0, 0,
138287 /* iArg: */ 0 },
138293 /* ColNames: */ 0, 0,
138294 /* iArg: */ 0 },
138299 /* ColNames: */ 0, 0,
138305 /* ColNames: */ 0, 0,
138313 /* iArg: */ 0 },
138319 /* ColNames: */ 0, 0,
138320 /* iArg: */ 0 },
138326 /* ColNames: */ 0, 0,
138333 /* ColNames: */ 0, 0,
138334 /* iArg: */ 0 },
138340 /* ColNames: */ 0, 0,
138348 /* iArg: */ 0 },
138355 /* iArg: */ 0 },
138362 /* ColNames: */ 0, 0,
138370 /* ColNames: */ 0, 0,
138377 /* ColNames: */ 0, 0,
138378 /* iArg: */ 0 },
138385 /* iArg: */ 0 },
138391 /* ColNames: */ 0, 8,
138392 /* iArg: */ 0 },
138399 /* ColNames: */ 0, 0,
138407 /* ColNames: */ 0, 0,
138414 /* ColNames: */ 0, 0,
138419 /* ColNames: */ 0, 0,
138428 /* iArg: */ 0 },
138434 /* ColNames: */ 0, 0,
138435 /* iArg: */ 0 },
138441 /* ColNames: */ 0, 0,
138449 /* ColNames: */ 0, 0,
138450 /* iArg: */ 0 },
138457 /* iArg: */ 0 },
138462 /* iArg: */ 0 },
138473 /* ColNames: */ 0, 0,
138474 /* iArg: */ 0 },
138480 /* ColNames: */ 0, 0,
138481 /* iArg: */ 0 },
138485 /* ColNames: */ 0, 0,
138486 /* iArg: */ 0 },
138492 /* ColNames: */ 0, 0,
138499 /* ColNames: */ 0, 0,
138500 /* iArg: */ 0 },
138507 /* iArg: */ 0 },
138513 /* ColNames: */ 0, 0,
138514 /* iArg: */ 0 },
138518 /* ColNames: */ 0, 0,
138519 /* iArg: */ 0 },
138522 /* ePragFlg: */ 0,
138523 /* ColNames: */ 0, 0,
138524 /* iArg: */ 0 },
138533 /* iArg: */ 0 },
138540 /* ColNames: */ 0, 0,
138541 /* iArg: */ 0 },
138546 /* ColNames: */ 0, 0,
138547 /* iArg: */ 0 },
138551 /* ColNames: */ 0, 0,
138552 /* iArg: */ 0 },
138559 /* ColNames: */ 0, 0,
138568 /* iArg: */ 0 },
138574 /* ColNames: */ 0, 0,
138581 /* ColNames: */ 0, 0,
138582 /* iArg: */ 0 },
138588 /* ColNames: */ 0, 0,
138593 /* ColNames: */ 0, 0,
138598 /* ColNames: */ 0, 0,
138605 /* ColNames: */ 0, 0,
138612 /* ColNames: */ 0, 0,
138613 /* iArg: */ 0 },
138619 /* ColNames: */ 0, 0,
138625 /* ColNames: */ 0, 0,
138626 /* iArg: */ 0 },
138630 /* ColNames: */ 0, 0,
138631 /* iArg: */ 0 },
138637 /* ColNames: */ 0, 0,
138646 /* iArg: */ 0 },
138652 /* ColNames: */ 0, 0,
138653 /* iArg: */ 0 },
138660 /* iArg: */ 0 },
138665 /* iArg: */ 0 },
138676 /* ColNames: */ 0, 0,
138677 /* iArg: */ 0 },
138681 /* ColNames: */ 0, 0,
138682 /* iArg: */ 0 },
138687 /* ColNames: */ 0, 0,
138688 /* iArg: */ 0 },
138693 /* ColNames: */ 0, 0,
138700 /* ColNames: */ 0, 0,
138708 /* ColNames: */ 0, 0,
138713 /* ColNames: */ 0, 0,
138718 /* ColNames: */ 0, 0,
138723 /* ColNames: */ 0, 0,
138728 /* ColNames: */ 0, 0,
138735 /* ePragFlg: */ 0,
138736 /* ColNames: */ 0, 0,
138737 /* iArg: */ 0 },
138742 /* iArg: */ 0 },
138748 /* ColNames: */ 0, 0,
138758 ** When the 0x10 bit of PRAGMA optimize is set, any ANALYZE commands
138770 ** has not been previously run and the 0x10000 flag is included so that
138774 ** optimize on a PI-4 is more like 1 millisecond or less with the 0x10000
138775 ** flag or less than 100 microseconds without the 0x10000 flag.
138786 ** Interpret the given string as a safety level. Return 0 for OFF,
138794 ** and older scripts may have used numbers 0 for OFF and 1 for ON.
138799 static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 15, 20};
138801 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 3, 2};
138808 for(i=0; i<ArraySize(iLength); i++){
138809 if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0
138822 return getSafetyLevel(z,1,dflt)!=0;
138836 if( 0==sqlite3StrICmp(z, "exclusive") ) return PAGER_LOCKINGMODE_EXCLUSIVE;
138837 if( 0==sqlite3StrICmp(z, "normal") ) return PAGER_LOCKINGMODE_NORMAL;
138847 ** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
138851 if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE;
138852 if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL;
138853 if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR;
138855 return (u8)((i>=0&&i<=2)?i:0);
138863 ** and 0 to use the compile-time default.
138866 if( z[0]>='0' && z[0]<='2' ){
138867 return z[0] - '0';
138868 }else if( sqlite3StrICmp(z, "file")==0 ){
138870 }else if( sqlite3StrICmp(z, "memory")==0 ){
138873 return 0;
138885 if( db->aDb[1].pBt!=0 ){
138894 db->aDb[1].pBt = 0;
138927 sqlite3VdbeSetNumCols(v, n==0 ? 1 : n);
138928 if( n==0 ){
138929 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, pPragma->zName, SQLITE_STATIC);
138932 for(i=0, j=pPragma->iPragCName; i<n; i++, j++){
138942 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
138961 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
138975 while( (n--) > 0 ){
139020 assert( PAGER_JOURNALMODE_DELETE==0 );
139026 assert( eMode>=0 && eMode<=ArraySize(azModeName) );
139028 if( eMode==ArraySize(azModeName) ) return 0;
139036 int upr, lwr, mid = 0, rc;
139037 lwr = 0;
139042 if( rc==0 ) break;
139043 if( rc<0 ){
139049 return lwr>upr ? 0 : &aPragmaName[mid];
139069 if( showInternFuncs ) mask = 0xffffffff;
139072 static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" };
139074 assert( SQLITE_FUNC_ENCMASK==0x3 );
139075 assert( strcmp(azEnc[SQLITE_UTF8],"utf8")==0 );
139076 assert( strcmp(azEnc[SQLITE_UTF16LE],"utf16le")==0 );
139077 assert( strcmp(azEnc[SQLITE_UTF16BE],"utf16be")==0 );
139079 if( p->xSFunc==0 ) continue;
139080 if( (p->funcFlags & SQLITE_FUNC_INTERNAL)!=0
139081 && showInternFuncs==0
139085 if( p->xValue!=0 ){
139087 }else if( p->xFinalize!=0 ){
139140 char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */
139141 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
139142 const char *zDb = 0; /* The database name */
139152 if( v==0 ) return;
139159 if( iDb<0 ) return;
139178 zDb = pId2->n>0 ? pDb->zDbSName : 0;
139198 aFcntl[0] = 0;
139201 aFcntl[3] = 0;
139202 db->busyHandler.nBusy = 0;
139206 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, aFcntl[0], SQLITE_TRANSIENT);
139207 returnSingleText(v, aFcntl[0]);
139208 sqlite3_free(aFcntl[0]);
139212 if( aFcntl[0] ){
139213 sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
139214 sqlite3_free(aFcntl[0]);
139223 if( pPragma==0 ){
139230 if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){
139235 if( (pPragma->mPragFlg & PragFlg_NoColumns)==0
139236 && ((pPragma->mPragFlg & PragFlg_NoColumns1)==0 || zRight==0)
139264 { OP_Transaction, 0, 0, 0}, /* 0 */
139265 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
139266 { OP_IfPos, 1, 8, 0},
139267 { OP_Integer, 0, 2, 0},
139269 { OP_IfPos, 1, 8, 0},
139270 { OP_Integer, 0, 1, 0}, /* 6 */
139271 { OP_Noop, 0, 0, 0},
139272 { OP_ResultRow, 1, 1, 0},
139280 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
139281 aOp[0].p1 = iDb;
139286 sqlite3BeginWriteOperation(pParse, 0, iDb);
139288 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
139308 assert( pBt!=0 );
139310 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
139317 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,0,0) ){
139335 assert( pBt!=0 );
139337 if( sqlite3_stricmp(zRight, "fast")==0 ){
139340 b = sqlite3GetBoolean(zRight, 0);
139343 if( pId2->n==0 && b>=0 ){
139345 for(ii=0; ii<db->nDb; ii++){
139373 i64 x = 0;
139376 if( sqlite3Tolower(zLeft[0])=='p' ){
139379 if( zRight && sqlite3DecOrHexToI64(zRight,&x)==0 ){
139380 if( x<0 ) x = 0;
139381 else if( x>0xfffffffe ) x = 0xfffffffe;
139383 x = 0;
139399 if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
139407 if( pId2->n==0 ){
139417 assert(pDb==&db->aDb[0]);
139446 if( zRight==0 ){
139453 for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){
139454 if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
139461 if( eMode==PAGER_JOURNALMODE_OFF && (db->flags & SQLITE_Defensive)!=0 ){
139467 if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){
139469 iDb = 0;
139472 for(ii=db->nDb-1; ii>=0; ii--){
139473 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
139507 ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
139512 assert( pBt!=0 );
139517 assert( eAuto>=0 && eAuto<=2 );
139533 { OP_Transaction, 0, 1, 0}, /* 0 */
139534 { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE},
139535 { OP_If, 1, 0, 0}, /* 2 */
139536 { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
139537 { OP_SetCookie, 0, BTREE_INCR_VACUUM, 0}, /* 4 */
139543 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
139544 aOp[0].p1 = iDb;
139563 int iLimit = 0, addr;
139564 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
139565 iLimit = 0x7fffffff;
139567 sqlite3BeginWriteOperation(pParse, 0, iDb);
139591 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
139625 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
139628 (db->flags & SQLITE_CacheSpill)==0 ? 0 :
139629 sqlite3BtreeSetSpillSize(pDb->pBt,0));
139635 if( sqlite3GetBoolean(zRight, size!=0) ){
139656 ** as little or as much as it wants. Except, if N is set to 0 then the
139661 #if SQLITE_MAX_MMAP_SIZE>0
139662 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
139666 if( sz<0 ) sz = sqlite3GlobalConfig.szMmap;
139667 if( pId2->n==0 ) db->szMmap = sz;
139668 for(ii=db->nDb-1; ii>=0; ii--){
139669 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
139677 sz = 0;
139725 if( zRight[0] ){
139728 if( rc!=SQLITE_OK || res==0 ){
139734 if( SQLITE_TEMP_STORE==0
139741 if( zRight[0] ){
139744 sqlite3_temp_directory = 0;
139772 if( zRight[0] ){
139775 if( rc!=SQLITE_OK || res==0 ){
139782 if( zRight[0] ){
139785 sqlite3_data_directory = 0;
139815 if( zRight[0] ){
139848 int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
139849 if( iLevel==0 ) iLevel = 1;
139861 if( zRight==0 ){
139863 returnSingleInt(v, (db->flags & pPragma->iArg)!=0 );
139866 if( db->autoCommit==0 ){
139878 if( sqlite3GetBoolean(zRight, 0) ){
139879 if( (mask & SQLITE_WriteSchema)==0
139880 || (db->flags & SQLITE_Defensive)==0
139886 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
139887 if( (mask & SQLITE_WriteSchema)!=0
139888 && sqlite3_stricmp(zRight, "reset")==0
139915 ** cid: Column id (numbered from left to right, starting at 0)
139928 int nHidden = 0;
139933 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
139934 int isHidden = 0;
139937 if( pPragma->iArg==0 ){
139949 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
139950 k = 0;
139951 }else if( pPk==0 ){
139957 assert( pColExpr==0 || pColExpr->op==TK_SPAN || isHidden>=2 );
139958 assert( pColExpr==0 || !ExprHasProperty(pColExpr, EP_IntValue)
139964 pCol->notNull ? 1 : 0,
139965 (isHidden>=2 || pColExpr==0) ? 0 : pColExpr->u.zToken,
139990 for(ii=0; ii<db->nDb; ii++){
139994 if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue;
140006 if( k==0 ){ initNCol = 0; break; }
140008 if( pTab->nCol==0 ){
140011 sqlite3_stmt *pDummy = 0;
140012 (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0);
140029 if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue;
140044 (pTab->tabFlags & TF_WithoutRowid)!=0,
140045 (pTab->tabFlags & TF_Strict)!=0
140062 0,
140070 pIdx->aiRowLogEst[0],
140083 if( pIdx==0 ){
140108 for(i=0; i<mx; i++){
140111 cnum<0 ? 0 : pTab->aCol[cnum].zCnName);
140133 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
140140 pIdx->pPartIdxWhere!=0);
140149 for(i=0; i<db->nDb; i++){
140150 if( db->aDb[i].pBt==0 ) continue;
140151 assert( db->aDb[i].zDbSName!=0 );
140161 int i = 0;
140176 int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0;
140178 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
140186 assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
140187 pragmaFunclistLine(v, p, 0, showInternFunc);
140206 for(i=0; i<ArraySize(aPragmaName); i++){
140224 int i = 0;
140229 for(j=0; j<pFK->nCol; j++){
140237 actionName(pFK->aAction[0]), /* ON DELETE */
140272 pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
140273 k = 0;
140278 if( pTab==0 || !IsOrdinaryTable(pTab) || pTab->u.tab.pFKey==0 ) continue;
140282 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
140284 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
140289 if( pParent==0 ) continue;
140290 pIdx = 0;
140291 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
140292 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
140293 if( x==0 ){
140294 if( pIdx==0 ){
140301 k = 0;
140305 assert( pParse->nErr>0 || pFK==0 );
140308 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
140312 pIdx = 0;
140313 aiCols = 0;
140316 assert( x==0 || db->mallocFailed );
140325 for(j=0; j<pFK->nCol; j++){
140327 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
140334 sqlite3VdbeAddOp4(v, OP_Affinity, regRow, pFK->nCol, 0,
140347 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
140349 sqlite3VdbeAddOp2(v, OP_Null, 0, regResult+1);
140356 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
140370 sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
140407 Table *pObjTab = 0; /* Check only this one table, if not NULL */
140409 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
140417 ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb
140420 assert( iDb>=0 );
140421 assert( iDb==0 || pId2->z );
140422 if( pId2->z==0 ) iDb = -1;
140431 if( mxErr<=0 ){
140435 pObjTab = sqlite3LocateTable(pParse, 0, zRight,
140436 iDb>=0 ? db->aDb[iDb].zDbSName : 0);
140442 for(i=0; i<db->nDb; i++){
140446 int cnt = 0; /* Number of entries in aRoot[] */
140449 if( iDb>=0 && i!=iDb ) continue;
140452 pParse->okConstFactor = 0; /* tag-20230327-1 */
140459 assert( sqlite3SchemaMutexHeld(db, i, 0) );
140461 for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
140467 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
140469 if( cnt==0 ) continue;
140472 if( aRoot==0 ) break;
140473 cnt = 0;
140474 if( pObjTab ) aRoot[++cnt] = 0;
140484 aRoot[0] = cnt;
140494 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
140502 cnt = pObjTab ? 1 : 0;
140505 int iTab = 0;
140519 if( pIdx->pPartIdxWhere==0 ){
140520 addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+cnt, 0, 8+iTab);
140536 Index *pPrior = 0; /* Previous index */
140547 pPk = 0;
140548 r2 = 0;
140554 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
140555 1, 0, &iDataCur, &iIdxCur);
140559 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
140560 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
140561 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
140565 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
140576 for(j=0; j<pTab->nCol; j++){
140577 if( (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)==0 ) mxCol++;
140586 if( mxCol>=0 ){
140596 a1 = sqlite3VdbeAddOp4Int(v, OP_IdxGT, iDataCur, 0,r2,pPk->nKeyCol);
140602 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
140606 for(j=0; j<pPk->nKeyCol; j++){
140620 bStrict = (pTab->tabFlags & TF_Strict)!=0;
140621 for(j=0; j<pTab->nCol; j++){
140635 if( pCol->notNull==0 && !doTypeCheck ) continue;
140645 sqlite3_value *pDfltValue = 0;
140670 if( p1<0 ){
140671 sqlite3VdbeChangeP5(v, 0x0f); /* INT, REAL, TEXT, or BLOB */
140674 sqlite3VdbeChangeP5(v, 0x0d); /* INT, TEXT, or BLOB */
140686 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
140698 0x1f, /* ANY */
140699 0x18, /* BLOB */
140700 0x11, /* INT */
140701 0x11, /* INTEGER */
140702 0x13, /* REAL */
140703 0x14 /* TEXT */
140712 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
140717 sqlite3VdbeChangeP5(v, 0x1c); /* NULL, TEXT, or BLOB */
140721 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
140726 sqlite3VdbeChangeP5(v, 0x1b); /* NULL, INT, FLOAT, or BLOB */
140728 if( p1>=0 ){
140731 sqlite3VdbeAddOp4(v, OP_Affinity, 3, 1, 0, "C", P4_STATIC);
140733 sqlite3VdbeChangeP5(v, 0x1c); /* NULL, TEXT, or BLOB */
140737 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
140744 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
140745 ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
140746 if( db->mallocFailed==0 ){
140752 for(k=pCheck->nExpr-1; k>0; k--){
140753 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
140755 sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
140758 pParse->iSelfTab = 0;
140761 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
140769 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
140774 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
140797 jmp7 = sqlite3VdbeAddOp3(v, OP_Eq, 3, 0, r1+pIdx->nColumn-1);
140809 label6 = 0;
140810 for(kk=0; kk<pIdx->nKeyCol; kk++){
140812 if( label6==0 ) label6 = sqlite3VdbeMakeLabel(pParse);
140832 for(kk=0; kk<pIdx->nKeyCol; kk++){
140835 if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
140871 if( pTab->nCol<=0 ){
140872 const char *zMod = pTab->u.vtab.azArg[0];
140873 if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue;
140876 if( pTab->u.vtab.p==0 ) continue;
140878 if( NEVER(pVTab==0) ) continue;
140879 if( NEVER(pVTab->pModule==0) ) continue;
140881 if( pVTab->pModule->xIntegrity==0 ) continue;
140895 { OP_AddImm, 1, 0, 0}, /* 0 */
140896 { OP_IfNotZero, 1, 4, 0}, /* 1 */
140897 { OP_String8, 0, 3, 0}, /* 2 */
140898 { OP_ResultRow, 3, 1, 0}, /* 3 */
140899 { OP_Halt, 0, 0, 0}, /* 4 */
140900 { OP_String8, 0, 3, 0}, /* 5 */
140901 { OP_Goto, 0, 3, 0}, /* 6 */
140907 aOp[0].p2 = 1-mxErr;
140913 sqlite3VdbeChangeP3(v, 0, sqlite3VdbeCurrentAddr(v)-2);
140953 { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
140954 { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
140955 { 0, 0 }
140970 if( (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){
140971 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
140972 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
141024 if( zRight && (pPragma->mPragFlg & PragFlg_ReadOnly)==0 ){
141027 { OP_Transaction, 0, 1, 0}, /* 0 */
141028 { OP_SetCookie, 0, 0, 0}, /* 1 */
141032 aOp = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
141033 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
141034 aOp[0].p1 = iDb;
141039 if( iCookie==BTREE_SCHEMA_VERSION && (db->flags & SQLITE_Defensive)!=0 ){
141047 { OP_Transaction, 0, 0, 0}, /* 0 */
141048 { OP_ReadCookie, 0, 1, 0}, /* 1 */
141049 { OP_ResultRow, 1, 1, 0}
141053 aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0);
141054 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
141055 aOp[0].p1 = iDb;
141072 int i = 0;
141075 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
141094 if( sqlite3StrICmp(zRight, "full")==0 ){
141096 }else if( sqlite3StrICmp(zRight, "restart")==0 ){
141098 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
141122 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
141154 ** 0x00001 Debugging mode. Do not actually perform any optimizations
141158 ** 0x00002 Run ANALYZE on tables that might benefit. On by default.
141161 ** 0x00010 Run all ANALYZE operations using an analysis_limit that
141170 ** 0x10000 Look at tables to see if they need to be reanalyzed
141174 ** The default MASK is and always shall be 0x0fffe. In the current
141175 ** implementation, the default mask only covers the 0x00002 optimization,
141176 ** though additional optimizations that are covered by 0x0fffe might be
141178 ** be explicitly requested have masks of 0x10000 or greater.
141185 ** (1) MASK bit 0x00002 is set.
141192 ** (4a) The 0x10000 MASK bit is set.
141223 int nCheck = 0; /* Number of tables to be optimized */
141224 int nBtree = 0; /* Number of btrees to scan */
141229 if( (opMask & 0x02)==0 ) break;
141231 opMask = 0xfffe;
141233 if( (opMask & 0x10)==0 ){
141234 nLimit = 0;
141235 }else if( db->nAnalysisLimit>0
141237 nLimit = 0;
141253 if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ) continue;
141260 nIndex = 0;
141270 ** unless the 0x10000 MASK bit is set. */
141271 if( (pTab->tabFlags & TF_MaybeReanalyze)!=0 ){
141273 }else if( opMask & 0x10000 ){
141274 /* Check for size change if 0x10000 is set */
141275 }else if( pTab->pIndex!=0 && szThreshold<0 ){
141286 sqlite3BeginWriteOperation(pParse, 0, iDb);
141294 if( szThreshold>=0 ){
141308 if( opMask & 0x01 ){
141310 sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC);
141313 sqlite3VdbeAddOp4(v, OP_SqlExec, nLimit ? 0x02 : 00, nLimit, 0,
141323 if( !db->mallocFailed && nLimit>0 && nBtree>100 ){
141328 aOp = sqlite3VdbeGetOp(v, 0);
141330 for(iAddr=0; iAddr<iEnd; iAddr++){
141343 ** then 0 is returned. Setting the busy_timeout to 0 or negative
141390 if( N>0 && (iPrior==0 || iPrior>N) ) sqlite3_hard_heap_limit64(N);
141407 && N>=0
141409 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
141426 && N>=0
141428 db->nAnalysisLimit = (int)(N&0x7fffffff);
141444 for(i=0; i<db->nDb; i++){
141448 if( db->aDb[i].zDbSName==0 ) continue;
141450 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
141452 }else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0,
141464 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
141518 PragmaVtab *pTab = 0;
141527 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
141529 for(i=0, j=pPragma->iPragCName; i<pPragma->nPragCName; i++, j++){
141533 if( i==0 ){
141537 j = 0;
141552 if( pTab==0 ){
141555 memset(pTab, 0, sizeof(PragmaVtab));
141592 if( pTab->nHidden==0 ){ return SQLITE_OK; }
141594 seen[0] = 0;
141595 seen[1] = 0;
141596 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
141599 if( pConstraint->usable==0 ) return SQLITE_CONSTRAINT;
141604 if( seen[0]==0 ){
141609 j = seen[0]-1;
141626 if( pCsr==0 ) return SQLITE_NOMEM;
141627 memset(pCsr, 0, sizeof(PragmaVtabCursor));
141637 pCsr->pPragma = 0;
141638 pCsr->iRowid = 0;
141639 for(i=0; i<ArraySize(pCsr->azArg); i++){
141641 pCsr->azArg[i] = 0;
141663 pCsr->pPragma = 0;
141687 j = (pTab->pName->mPragFlg & PragFlg_Result1)!=0 ? 0 : 1;
141688 for(i=0; i<argc; i++, j++){
141691 assert( pCsr->azArg[j]==0 );
141694 if( pCsr->azArg[j]==0 ){
141699 sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]);
141705 if( pCsr->azArg[0] ){
141706 sqlite3_str_appendf(&acc, "=%Q", pCsr->azArg[0]);
141709 if( zSql==0 ) return SQLITE_NOMEM;
141710 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pPragma, 0);
141724 return (pCsr->pPragma==0);
141756 0, /* iVersion */
141757 0, /* xCreate - create a table */
141761 0, /* xDestroy - Drop a table */
141769 0, /* xUpdate - write data */
141770 0, /* xBegin - begin transaction */
141771 0, /* xSync - sync transaction */
141772 0, /* xCommit - commit transaction */
141773 0, /* xRollback - rollback transaction */
141774 0, /* xFindFunction - function overloading */
141775 0, /* xRename - rename the table */
141776 0, /* xSavepoint */
141777 0, /* xRelease */
141778 0, /* xRollbackTo */
141779 0, /* xShadowName */
141780 0 /* xIntegrity */
141790 assert( sqlite3_strnicmp(zName, "pragma_", 7)==0 );
141792 if( pName==0 ) return 0;
141793 if( (pName->mPragFlg & (PragFlg_Result0|PragFlg_Result1))==0 ) return 0;
141794 assert( sqlite3HashFind(&db->aModule, zName)==0 );
141795 return sqlite3VtabCreateModule(db, zName, &pragmaVtabModule, (void*)pName, 0);
141833 }else if( pData->pzErrMsg[0]!=0 ){
141842 "error in %s %s after %s: %s", azObj[0], azObj[1],
141853 if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra);
141869 return 0;
141891 ** argv[0] = type of object: "table", "index", "trigger", or "view".
141894 ** argv[3] = root page number for table or index. 0 for trigger or view.
141907 if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
141910 corruptSchema(pData, argv, 0);
141914 assert( iDb>=0 && iDb<db->nDb );
141915 if( argv[3]==0 ){
141916 corruptSchema(pData, argv, 0);
141918 && 'c'==sqlite3UpperToLower[(unsigned char)argv[4][0]]
141937 if( sqlite3GetUInt32(argv[3], &db->init.newTnum)==0
141938 || (db->init.newTnum>pData->mxPage && pData->mxPage>0)
141944 db->init.orphanTrigger = 0;
141946 pStmt = 0;
141947 TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, 0);
141949 assert( (rc&0xFF)==(rcp&0xFF) );
141951 /* assert( saved_iDb==0 || (db->mDbFlags & DBFLAG_Vacuum)!=0 ); */
141959 }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){
141966 }else if( argv[1]==0 || (argv[4]!=0 && argv[4][0]!=0) ){
141967 corruptSchema(pData, argv, 0);
141977 if( pIndex==0 ){
141980 if( sqlite3GetUInt32(argv[3],&pIndex->tnum)==0
141990 return 0;
141996 ** database file is given by iDb. iDb==0 is used for the main
142012 int openedTransaction = 0;
142015 assert( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0 );
142016 assert( iDb>=0 && iDb<db->nDb );
142028 azArg[0] = "table";
142034 azArg[5] = 0;
142040 initData.nInitRow = 0;
142041 initData.mxPage = 0;
142042 sqlite3InitCallback(&initData, 5, (char **)azArg, 0);
142052 if( pDb->pBt==0 ){
142064 rc = sqlite3BtreeBeginTrans(pDb->pBt, 0, 0);
142075 ** meta[0] Schema cookie. Changes with each schema change.
142089 for(i=0; i<ArraySize(meta); i++){
142092 if( (db->flags & SQLITE_ResetDatabase)!=0 ){
142093 memset(meta, 0, sizeof(meta));
142103 if( iDb==0 && (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){
142108 if( encoding==0 ) encoding = SQLITE_UTF8;
142112 if( db->nVdbeActive>0 && encoding!=ENC(db)
142113 && (db->mDbFlags & DBFLAG_Vacuum)==0
142132 if( pDb->pSchema->cache_size==0 ){
142135 if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; }
142144 ** file_format==1 Version 3.0.0.
142147 ** file_format==4 Version 3.3.0. // DESC indices. Boolean constants
142150 if( pDb->pSchema->file_format==0 ){
142164 if( iDb==0 && meta[BTREE_FILE_FORMAT-1]>=4 ){
142181 db->xAuth = 0;
142183 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
142234 db->init.busy = 0;
142252 assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
142253 assert( db->init.busy==0 );
142255 assert( db->nDb>0 );
142257 if( !DbHasProperty(db, 0, DB_SchemaLoaded) ){
142258 rc = sqlite3InitOne(db, 0, pzErrMsg, 0);
142262 for(i=db->nDb-1; i>0; i--){
142265 rc = sqlite3InitOne(db, i, pzErrMsg, 0);
142309 for(iDb=0; iDb<db->nDb; iDb++){
142310 int openedTransaction = 0; /* True if a transaction is opened */
142312 if( pBt==0 ) continue;
142318 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
142331 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
142367 for(i=0; 1; i++){
142373 assert( i>=0 && i<db->nDb );
142383 assert( db!=0 );
142385 assert( pParse->nested==0 );
142401 db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
142441 pCleanup = 0;
142453 pPtr = 0;
142471 memset(PARSE_HDR(pParse), 0, PARSE_HDR_SZ);
142472 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
142505 memset(PARSE_HDR(&sParse), 0, PARSE_HDR_SZ);
142506 memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ);
142514 assert( sParse.pReprepare==0 );
142516 assert( ppStmt && *ppStmt==0 );
142531 sParse.prepFlags = prepFlags & 0xff;
142557 for(i=0; i<db->nDb; i++) {
142576 if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
142597 assert( 0==sParse.nQueryLoop );
142603 if( db->init.busy==0 ){
142608 sParse.checkSchema = 0;
142611 if( sParse.checkSchema && db->init.busy==0 ){
142617 assert( 0==(*ppStmt) );
142626 assert( sParse.zErrMsg==0 );
142655 int cnt = 0;
142658 if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
142660 *ppStmt = 0;
142661 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
142671 assert( rc==SQLITE_OK || *ppStmt==0 );
142674 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
142678 db->busyHandler.nBusy = 0;
142680 assert( rc==SQLITE_OK || (*ppStmt)==0 );
142702 assert( zSql!=0 ); /* Reprepare only called for prepare_v2() statements */
142706 rc = sqlite3LockAndPrepare(db, zSql, -1, prepFlags, p, &pNew, 0);
142711 assert( pNew==0 );
142714 assert( pNew!=0 );
142740 rc = sqlite3LockAndPrepare(db,zSql,nBytes,0,0,ppStmt,pzTail);
142741 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
142756 ** Proof in that the 5th parameter to sqlite3LockAndPrepare is 0 */
142757 rc = sqlite3LockAndPrepare(db,zSql,nBytes,SQLITE_PREPARE_SAVESQL,0,
142759 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 );
142780 0,ppStmt,pzTail);
142781 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 );
142803 const char *zTail8 = 0;
142807 if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
142809 *ppStmt = 0;
142810 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
142813 if( nBytes>=0 ){
142816 for(sz=0; sz<nBytes && (z[sz]!=0 || z[sz+1]!=0); sz += 2){}
142822 rc = sqlite3LockAndPrepare(db, zSql8, -1, prepFlags, 0, ppStmt, &zTail8);
142856 rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
142857 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
142869 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
142884 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
142915 u8 isTnct; /* 0: Not distinct. 1: DISTICT 2: DISTINCT and ORDER BY */
142964 #define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
142971 ** If bFree==0, Leave the first Select object unfreed
142974 assert( db!=0 );
143006 pDest->iSDParm2 = 0;
143007 pDest->zAffSdst = 0;
143008 pDest->iSdst = 0;
143009 pDest->nSdst = 0;
143031 if( pNew==0 ){
143035 if( pEList==0 ){
143036 pEList = sqlite3ExprListAppend(pParse, 0,
143037 sqlite3Expr(pParse->db,TK_ASTERISK,0));
143042 pNew->iLimit = 0;
143043 pNew->iOffset = 0;
143045 pNew->addrOpenEphm[0] = -1;
143047 pNew->nSelectRow = 0;
143048 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(pParse->db, sizeof(*pSrc));
143054 pNew->pPrior = 0;
143055 pNew->pNext = 0;
143057 pNew->pWith = 0;
143059 pNew->pWin = 0;
143060 pNew->pWinDefn = 0;
143064 pAllocated = 0;
143066 assert( pNew->pSrc!=0 || pParse->nErr>0 );
143154 int jointype = 0;
143164 /* (0) natural */ { 0, 7, JT_NATURAL },
143173 apAll[0] = pA;
143176 for(i=0; i<3 && apAll[i]; i++){
143178 for(j=0; j<ArraySize(aKeyword); j++){
143180 && sqlite3StrNICmp((char*)p->z, &zKeyText[aKeyword[j].i], p->n)==0 ){
143185 testcase( j==0 || j==1 || j==2 || j==3 || j==4 || j==5 || j==6 );
143193 (jointype & JT_ERROR)!=0 ||
143198 if( pB==0 ){ zSp1++; }
143199 if( pC==0 ){ zSp2++; }
143215 for(pCol=pTab->aCol, i=0; i<pTab->nCol; pCol++, i++){
143216 if( pCol->hName==h && sqlite3StrICmp(pCol->zCnName, zCol)==0 ) return i;
143225 assert( pItem!=0 );
143229 assert( pItem->pSelect!=0 );
143231 assert( pResults!=0 );
143232 assert( iCol>=0 && iCol<pResults->nExpr );
143260 assert( iStart>=0 );
143261 assert( (piTab==0)==(piCol==0) ); /* Both or neither are NULL */
143265 if( iCol>=0
143266 && (bIgnoreHidden==0 || IsHiddenColumn(&pSrc->a[i].pTab->aCol[iCol])==0)
143276 return 0;
143316 for(i=0; i<p->x.pList->nExpr; i++){
143331 ** an ordinary term that omits the EP_OuterON mark. Or if iTable<0, then
143342 if( iTable<0 || (ExprHasProperty(p, EP_OuterON) && p->w.iJoin==iTable) ){
143344 if( iTable>=0 ) ExprSetProperty(p, EP_InnerON);
143351 assert( p->pLeft==0 );
143354 for(i=0; i<p->x.pList->nExpr; i++){
143380 ** entries 0 and 1. Any ON or USING clauses associated with the join are
143392 pLeft = &pSrc->a[0];
143394 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
143398 if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
143399 joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_OuterON : EP_InnerON;
143405 IdList *pUsing = 0;
143408 "an ON or USING clause", 0);
143411 for(j=0; j<pRightTab->nCol; j++){
143416 if( tableAndColumnIndex(pSrc, 0, i, zName, 0, 0, 1) ){
143417 pUsing = sqlite3IdListAppend(pParse, pUsing, 0);
143419 assert( pUsing->nId>0 );
143420 assert( pUsing->a[pUsing->nId-1].zName==0 );
143443 assert( pList!=0 );
143444 for(j=0; j<pList->nId; j++){
143455 if( iRightCol<0
143456 || tableAndColumnIndex(pSrc, 0, i, zName, &iLeft, &iLeftCol,
143457 pRight->fg.isSynthUsing)==0
143465 if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
143479 ExprList *pFuncArgs = 0; /* Arguments to the coalesce() */
143482 pRight->fg.isSynthUsing)!=0 ){
143483 if( pSrc->a[iLeft].fg.isUsing==0
143484 || sqlite3IdListIndex(pSrc->a[iLeft].u3.pUsing, zName)<0
143496 pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0);
143502 assert( pE2!=0 || pEq==0 );
143519 pRight->u3.pOn = 0;
143523 return 0;
143550 0, pInfo->ecelFlags);
143553 sqlite3ExprCodeExprList(pParse, pInfo->pExtra, pInfo->regExtraResult, 0, 0);
143596 int bSeq = ((pSort->sortFlags & SORTFLAG_UseSorter)==0);
143600 int regRecord = 0; /* Assembled sorter record */
143604 int iSkip = 0; /* End of the sorter insert loop */
143606 assert( bSeq==0 || bSeq==1 );
143618 ** regOrigData is 0 to prevent this routine from trying to copy
143621 assert( nData==1 || regData==regOrigData || regOrigData==0 );
143634 assert( pSelect->iOffset==0 || pSelect->iLimit!=0 );
143638 SQLITE_ECEL_DUP | (regOrigData? SQLITE_ECEL_REF : 0));
143642 if( nPrefixReg==0 && nData>0 ){
143645 if( nOBSat>0 ){
143668 memset(pKI->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */
143673 pOp = 0; /* Ensure pOp not used after sqlite3VdbeAddOp3() */
143675 sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
143707 sqlite3VdbeAddOp2(v, OP_Last, iCsr, 0);
143709 iCsr, 0, regBase+nOBSat, nExpr-nOBSat);
143713 if( regRecord==0 ){
143740 if( iOffset>0 ){
143797 int iRet = 0;
143812 for(i=0; i<nResultCol; i++){
143879 if( pParse->nErr==0
143932 int nDefer = 0;
143933 ExprList *pExtra = 0;
143934 for(i=0; i<pEList->nExpr; i++){
143936 if( pItem->u.x.iOrderByCol==0 ){
143940 && pExpr->iColumn>=0
143942 && (pTab = pExpr->y.pTab)!=0
143944 && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)!=0
143947 for(j=0; j<nDefer; j++){
143956 Index *pPk = 0;
143961 for(k=0; k<nKey; k++){
143962 Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0);
144011 int nPrefixReg = 0; /* Number of extra registers before regResult */
144020 int regOrig; /* Start of memory holding full result (or 0) */
144023 assert( p->pEList!=0 );
144025 if( pSort && pSort->pOrderBy==0 ) pSort = 0;
144026 if( pSort==0 && !hasDistinct ){
144027 assert( iContinue!=0 );
144035 if( pDest->iSdst==0 ){
144053 if( srcTab>=0 ){
144054 for(i=0; i<nResultCol; i++){
144060 ExprList *pExtra = 0;
144070 ecelFlags = 0;
144072 if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab && eDest!=SRT_Table ){
144083 if( (j = pSort->pOrderBy->a[i].u.x.iOrderByCol)>0 ){
144089 if( pExtra && pParse->db->mallocFailed==0 ){
144105 for(i=0; i<pEList->nExpr; i++){
144106 if( pEList->a[i].u.x.iOrderByCol>0
144112 regOrig = 0;
144133 && (ecelFlags & SQLITE_ECEL_OMITREF)!=0
144134 && nPrefixReg>0
144136 assert( pSort!=0 );
144137 assert( hasDistinct==0 );
144139 regOrig = 0;
144155 if( pSort==0 ){
144214 sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
144217 assert( pSort==0 );
144248 regResult+(i2<0), nResultCol-(i2<0), r1);
144249 if( i2<0 ){
144335 int addrTest = 0;
144347 addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0,
144356 for(i=0; i<nKey; i++){
144390 if( pSort==0 && p->iLimit ){
144409 memset(&p[1], 0, nExtra);
144421 assert( p->db!=0 );
144422 assert( p->nRef>0 );
144424 if( p->nRef==0 ) sqlite3DbNNFreeNN(p->db, p);
144433 assert( p->nRef>0 );
144513 ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s", zUsage));
144549 int addrOnce = 0;
144561 int nRefKey = 0;
144568 if( pSort->nOBSat==0 || nKey==1 ){
144569 ExplainQueryPlan2(addrExplain, (pParse, 0,
144573 ExplainQueryPlan2(addrExplain, (pParse, 0,
144581 assert( addrBreak<0 );
144590 for(i=0; i<pSort->nDefer; i++){
144601 sqlite3VdbeAddOp2(v, OP_Null, 0, pDest->iSdst);
144603 regRowid = 0;
144609 nColumn = 0;
144625 assert( p->iLimit==0 && p->iOffset==0 );
144627 bSeq = 0;
144633 if( p->iOffset>0 ){
144637 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
144641 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
144648 for(i=0; i<pSort->nDefer; i++){
144662 for(k=0; k<nKey; k++){
144674 for(i=nColumn-1; i>=0; i--){
144717 sqlite3VdbeAddOp3(v, OP_MakeRecord,regRow+(i2<0),nColumn-(i2<0),r1);
144718 if( i2<0 ){
144795 char const *zType = 0;
144798 char const *zOrigDb = 0;
144799 char const *zOrigTab = 0;
144800 char const *zOrigCol = 0;
144803 assert( pExpr!=0 );
144804 assert( pNC->pSrcList!=0 );
144811 Table *pTab = 0; /* Table structure column is extracted from */
144812 Select *pS = 0; /* Select the column is extracted from */
144816 for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
144825 if( pTab==0 ){
144853 && (!ViewCanHaveRowid || iCol>=0)
144870 if( iCol<0 ) iCol = pTab->iPKey;
144871 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
144872 if( iCol<0 ){
144877 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
144885 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
144886 if( iCol<0 ){
144889 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
144906 p = pS->pEList->a[0].pExpr;
144942 sNC.pNext = 0;
144943 for(i=0; i<pEList->nExpr; i++){
144947 const char *zOrigDb = 0;
144948 const char *zOrigTab = 0;
144949 const char *zOrigCol = 0;
144960 zType = columnType(&sNC, p, 0, 0, 0);
145014 TREETRACE(0x80,pParse,pSelect,("generating column names\n"));
145017 assert( v!=0 );
145018 assert( pTabList!=0 );
145020 fullName = (db->flags & SQLITE_FullColNames)!=0;
145021 srcName = (db->flags & SQLITE_ShortColNames)!=0 || fullName;
145023 for(i=0; i<pEList->nExpr; i++){
145026 assert( p!=0 );
145029 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
145038 assert( pTab!=0 );
145039 if( iCol<0 ) iCol = pTab->iPKey;
145040 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
145041 if( iCol<0 ){
145047 char *zName = 0;
145055 z = z==0 ? sqlite3MPrintf(db, "column%d", i+1) : sqlite3DbStrDup(db, z);
145073 ** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
145103 aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
145104 testcase( aCol==0 );
145107 nCol = 0;
145108 aCol = 0;
145114 for(i=0, pCol=aCol; i<nCol && !pParse->nErr; i++, pCol++){
145119 if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
145123 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
145125 assert( pColExpr!=0 );
145129 && ALWAYS( pColExpr->y.pTab!=0 )
145134 if( iCol<0 ) iCol = pTab->iPKey;
145135 zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
145153 cnt = 0;
145154 while( zName && (pCollide = sqlite3HashFind(&ht, zName))!=0 ){
145159 if( nName>0 ){
145160 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
145174 sqlite3ColumnPropertiesFromName(0, pCol);
145181 for(j=0; j<i; j++){
145185 *paCol = 0;
145186 *pnCol = 0;
145217 assert( pSelect!=0 );
145218 assert( (pSelect->selFlags & SF_Resolved)!=0 );
145219 assert( pTab->nCol==pSelect->pEList->nExpr || pParse->nErr>0 );
145224 memset(&sNC, 0, sizeof(sNC));
145226 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
145229 int m = 0;
145235 while( pCol->affinity<=SQLITE_AFF_NONE && pS2->pNext!=0 ){
145247 if( pCol->affinity==SQLITE_AFF_TEXT && (m&0x01)!=0 ){
145250 if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
145257 zType = columnType(&sNC, p, 0, 0, 0);
145258 if( zType==0 || pCol->affinity!=sqlite3AffinityType(zType, 0) ){
145264 zType = 0;
145285 assert( pTab->pIndex==0 );
145304 sqlite3SelectPrep(pParse, pSelect, 0);
145306 if( pParse->nErr ) return 0;
145309 if( pTab==0 ){
145310 return 0;
145313 pTab->zName = 0;
145320 return 0;
145333 if( pParse->pToplevel==0
145360 ** Only if pLimit->pLeft!=0 do the limit registers get
145366 Vdbe *v = 0;
145367 int iLimit = 0;
145377 ** The current implementation interprets "LIMIT 0" to mean
145382 assert( pLimit->pLeft!=0 );
145385 assert( v!=0 );
145389 if( n==0 ){
145391 }else if( n>=0 && p->nSelectRow>sqlite3LogEst((u64)n) ){
145427 pRet = 0;
145429 assert( iCol>=0 );
145433 if( pRet==0 && ALWAYS(iCol<p->pEList->nExpr) ){
145450 int nOrderBy = ALWAYS(pOrderBy!=0) ? pOrderBy->nExpr : 0;
145455 for(i=0; i<nOrderBy; i++){
145464 if( pColl==0 ) pColl = db->pDfltColl;
145526 int iCurrent = 0; /* The Current table */
145529 int iDistinct = 0; /* To ensure unique results if UNION */
145546 if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
145555 p->pLimit = 0;
145556 p->iLimit = p->iOffset = 0;
145560 for(i=0; ALWAYS(i<pSrc->nSrc); i++){
145584 sqlite3VdbeAddOp4(v, OP_OpenEphemeral, iQueue, pOrderBy->nExpr+2, 0,
145592 p->addrOpenEphm[0] = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iDistinct, 0);
145597 p->pOrderBy = 0;
145606 for(pFirstRec=p; ALWAYS(pFirstRec!=0); pFirstRec=pFirstRec->pPrior){
145612 if( (pFirstRec->pPrior->selFlags & SF_Recursive)==0 ) break;
145617 pSetup->pNext = 0;
145639 0, 0, pDest, addrCont, addrBreak);
145649 pFirstRec->pPrior = 0;
145652 assert( pFirstRec->pPrior==0 );
145696 int rc = 0;
145697 int bShowAll = p->pLimit==0;
145701 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
145702 assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
145706 if( p->pPrior==0 ) break;
145711 ExplainQueryPlan((pParse, 0, "SCAN %d CONSTANT ROW%s", nRow,
145714 selectInnerLoop(pParse, p, -1, 0, 0, pDest, 1, 1);
145728 while( p && (p->selFlags & SF_Recursive)!=0 ){ p = p->pPrior; }
145729 return p!=0;
145772 Select *pDelete = 0; /* Chain of simple selects to delete */
145779 assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
145784 assert( pPrior->pOrderBy==0 );
145785 assert( pPrior->pLimit==0 );
145788 assert( v!=0 ); /* The VDBE already created by calling function */
145802 if( rc>=0 ) goto multi_select_end;
145813 if( (p->selFlags & SF_Recursive)!=0 && hasAnchor(p) ){
145825 if( pPrior->pPrior==0 ){
145835 int addr = 0;
145836 int nLimit = 0; /* Initialize to suppress harmless compiler warning */
145841 TREETRACE(0x200, pParse, p, ("multiSelect UNION ALL left...\n"));
145843 pPrior->pLimit = 0;
145847 p->pPrior = 0;
145859 TREETRACE(0x200, pParse, p, ("multiSelect UNION ALL right...\n"));
145867 && nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit)
145879 u8 op = 0; /* One of the SRT_ operations to apply to self */
145892 assert( p->pLimit==0 ); /* Not allowed on leftward elements */
145899 assert( p->pOrderBy==0 );
145900 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, unionTab, 0);
145901 assert( p->addrOpenEphm[0] == -1 );
145902 p->addrOpenEphm[0] = addr;
145912 TREETRACE(0x200, pParse, p, ("multiSelect EXCEPT/UNION left...\n"));
145926 p->pPrior = 0;
145928 p->pLimit = 0;
145932 TREETRACE(0x200, pParse, p, ("multiSelect EXCEPT/UNION right...\n"));
145935 assert( p->pOrderBy==0 );
145938 p->pOrderBy = 0;
145944 p->iLimit = 0;
145945 p->iOffset = 0;
145952 if( dest.eDest!=priorOp && db->mallocFailed==0 ){
145960 0, 0, &dest, iCont, iBreak);
145964 sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
145982 assert( p->pOrderBy==0 );
145984 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0);
145985 assert( p->addrOpenEphm[0] == -1 );
145986 p->addrOpenEphm[0] = addr;
145993 TREETRACE(0x400, pParse, p, ("multiSelect INTERSECT left...\n"));
146001 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab2, 0);
146004 p->pPrior = 0;
146006 p->pLimit = 0;
146010 TREETRACE(0x400, pParse, p, ("multiSelect INTERSECT right...\n"));
146032 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
146036 0, 0, &dest, iCont, iBreak);
146040 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
146041 sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
146047 if( p->pNext==0 ){
146070 assert( p->pNext==0 );
146071 assert( p->pEList!=0 );
146078 for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
146080 if( 0==*apColl ){
146086 for(i=0; i<2; i++){
146088 if( addr<0 ){
146089 /* If [0] is unused then [1] is also unused. So we can
146091 assert( pLoop->addrOpenEphm[1]<0 );
146138 ** If regPrev>0 then it is the first register in a vector that
146140 ** if there has been no previous output. If regPrev>0 then code is
146153 int regPrev, /* Previous result register. No uniqueness if 0 */
146176 if( pParse->db->mallocFailed ) return 0;
146231 if( pDest->iSdst==0 ){
146374 int addrOutB = 0; /* Address of the output-B subroutine */
146390 KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */
146397 assert( p->pOrderBy!=0 );
146398 assert( pKeyDup==0 ); /* "Managed" code needs this. Ticket #3382. */
146401 assert( v!=0 ); /* Already thrown the error if VDBE alloc failed */
146409 assert( p->pPrior->pOrderBy==0 );
146419 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
146421 for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){
146422 assert( pItem!=0 );
146423 assert( pItem->u.x.iOrderByCol>0 );
146427 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
146428 if( pNew==0 ) return SQLITE_NOMEM_BKPT;
146447 aPermute[0] = nOrderBy;
146449 assert( pItem!=0 );
146450 assert( pItem->u.x.iOrderByCol>0 );
146456 pKeyMerge = 0;
146464 regPrev = 0;
146470 sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
146474 for(i=0; i<nExpr; i++){
146476 pKeyDup->aSortFlags[i] = 0;
146487 for(pSplit=p; pSplit->pPrior!=0 && pSplit->op==op; pSplit=pSplit->pPrior){
146499 assert( pPrior!=0 );
146500 pSplit->pPrior = 0;
146501 pPrior->pNext = 0;
146503 assert( pOrderBy!=0 || db->mallocFailed );
146504 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
146517 regLimitA = regLimitB = 0;
146520 p->pLimit = 0;
146535 addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrA, 0, addrSelectA);
146547 addr1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrB, 0, addrSelectB);
146552 p->iOffset = 0;
146645 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
146663 pPrior->pOrderBy = 0;
146668 return pParse->nErr!=0;
146738 if( pExpr==0 ) return 0;
146750 if( pExpr->iColumn<0 ){
146760 assert( iColumn>=0 );
146761 assert( pSubst->pEList!=0 && iColumn<pSubst->pEList->nExpr );
146762 assert( pExpr->pRight==0 );
146771 memset(&ifNullRow, 0, sizeof(ifNullRow));
146780 pNew = sqlite3ExprDup(db, pCopy, 0);
146843 if( pList==0 ) return;
146844 for(i=0; i<pList->nExpr; i++){
146864 assert( pSrc!=0 );
146865 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
146871 }while( doPrior && (p = p->pPrior)!=0 );
146888 if( pExpr->iColumn<0 ) return WRC_Continue;
146897 if( NEVER(pSrcItem->pTab==0) ) return;
146898 memset(&w, 0, sizeof(w));
146902 pSrcItem->colUsed = 0;
146916 ** existing cursor numbers in pSrc. aCsrMap[0] is the array size.
146929 for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
146932 assert( pItem->iCursor < aCsrMap[0] );
146933 if( !pItem->fg.isRecursive || aCsrMap[pItem->iCursor+1]==0 ){
146950 if( iCsr < aCsrMap[0] && aCsrMap[iCsr+1]>0 ){
146996 memset(&w, 0, sizeof(w));
147023 assert( p!=0 );
147024 assert( p->pEList!=0 );
147025 assert( p->pPrior!=0 );
147027 for(ii=0; ii<pList->nExpr; ii++){
147030 assert( pList->a[ii].pExpr!=0 );
147033 assert( pSub1->pEList!=0 );
147035 assert( pSub1->pEList->a[ii].pExpr!=0 );
147041 return 0;
147047 ** This routine returns 1 if it makes changes and 0 if no flattening occurs.
147212 ** If flattening is not attempted, this routine is a no-op and returns 0.
147232 int isOuterJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
147238 int *aCsrMap = 0;
147240 /* Check to see if flattening is permitted. Return 0 if not.
147242 assert( p!=0 );
147243 assert( p->pPrior==0 );
147244 if( OptimizationDisabled(db, SQLITE_QueryFlattener) ) return 0;
147246 assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
147250 assert( pSub!=0 );
147253 if( p->pWin || pSub->pWin ) return 0; /* Restriction (25) */
147263 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
147264 if( pSub->pLimit && pSub->pLimit->pRight ) return 0; /* Restriction (14) */
147265 if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){
147266 return 0; /* Restriction (15) */
147268 if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
147269 if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (4) */
147271 return 0; /* Restrictions (8)(9) */
147274 return 0; /* Restriction (11) */
147276 if( isAgg && pSub->pOrderBy ) return 0; /* Restriction (16) */
147277 if( pSub->pLimit && p->pWhere ) return 0; /* Restriction (19) */
147278 if( pSub->pLimit && (p->selFlags & SF_Distinct)!=0 ){
147279 return 0; /* Restriction (21) */
147282 return 0; /* Restrictions (22) */
147300 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
147302 || IsVirtual(pSubSrc->a[0].pTab) /* (3b) */
147303 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
147304 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
147306 return 0;
147311 assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
147312 if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
147313 return 0; /* Restriction (27a) */
147327 return 0; /* Restriction (20) */
147329 if( isAgg || (p->selFlags & SF_Distinct)!=0 || isOuterJoin>0 ){
147330 return 0; /* (17d1), (17d2), or (17f) */
147335 assert( pSub->pSrc!=0 );
147336 assert( (pSub->selFlags & SF_Recursive)==0 );
147338 if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 /* (17b) */
147345 return 0;
147347 if( iFrom>0 && (pSub1->pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
147351 return 0; /* Restrictions (17g), (27b) */
147358 for(ii=0; ii<p->pOrderBy->nExpr; ii++){
147359 if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
147364 if( (p->selFlags & SF_Recursive) ) return 0;
147367 if( compoundHasDifferentAffinities(pSub) ) return 0;
147370 if( pParse->nSelect>500 ) return 0;
147371 if( OptimizationDisabled(db, SQLITE_FlttnUnionAll) ) return 0;
147373 if( aCsrMap ) aCsrMap[0] = pParse->nTab;
147378 TREETRACE(0x4,pParse,p,("flatten %u.%p from term %d\n",
147383 TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
147392 pSubitem->zDatabase = 0;
147393 pSubitem->zName = 0;
147394 pSubitem->zAlias = 0;
147395 pSubitem->pSelect = 0;
147396 assert( pSubitem->fg.isUsing!=0 || pSubitem->u3.pOn==0 );
147437 pSubitem->pTab = 0;
147438 p->pOrderBy = 0;
147439 p->pPrior = 0;
147440 p->pLimit = 0;
147441 pNew = sqlite3SelectDup(db, p, 0);
147446 if( pNew==0 ){
147450 if( aCsrMap && ALWAYS(db->mallocFailed==0) ){
147457 TREETRACE(0x4,pParse,p,("compound-subquery flattener"
147460 assert( pSubitem->pSelect==0 );
147475 if( ALWAYS(pSubitem->pTab!=0) ){
147484 pSubitem->pTab = 0;
147503 u8 jointype = 0;
147505 assert( pSub!=0 );
147531 if( pSrc==0 ) break;
147538 for(i=0; i<nSubSrc; i++){
147541 assert( pItem->fg.isTabFunc==0 );
147545 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
147562 if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){
147574 for(i=0; i<pOrderBy->nExpr; i++){
147575 pOrderBy->a[i].u.x.iOrderByCol = 0;
147577 assert( pParent->pOrderBy==0 );
147579 pSub->pOrderBy = 0;
147582 pSub->pWhere = 0;
147583 if( isOuterJoin>0 ){
147593 if( db->mallocFailed==0 ){
147601 substSelect(&x, pParent, 0);
147607 assert( (pSub->selFlags & SF_Distinct)==0 ); /* restriction (17b) */
147617 pSub->pLimit = 0;
147622 for(i=0; i<nSubSrc; i++){
147634 if( sqlite3TreeTrace & 0x4 ){
147635 TREETRACE(0x4,pParse,p,("After flattening:\n"));
147636 sqlite3TreeViewSelect(0, p, 0);
147679 if( sqlite3ExprAffinity(pValue)!=0 ) return;
147686 for(i=0; i<pConst->nConst; i++){
147702 if( pConst->apExpr==0 ){
147703 pConst->nConst = 0;
147718 if( NEVER(pExpr==0) ) return;
147732 assert( pRight!=0 );
147733 assert( pLeft!=0 );
147757 if( pConst->pOomFault[0] ) return WRC_Prune;
147765 for(i=0; i<pConst->nConst; i++){
147777 assert( pExpr->pLeft==0 );
147778 pExpr->pLeft = sqlite3ExprDup(pConst->pParse->db, pConst->apExpr[i*2+1], 0);
147811 propagateConstantExprRewriteOne(pConst, pExpr->pLeft, 0);
147812 if( pConst->pOomFault[0] ) return WRC_Prune;
147814 propagateConstantExprRewriteOne(pConst, pExpr->pRight, 0);
147878 int nChng = 0;
147882 x.nConst = 0;
147883 x.nChng = 0;
147884 x.apExpr = 0;
147885 x.bHasAffBlob = 0;
147886 if( ALWAYS(p->pSrc!=0)
147887 && p->pSrc->nSrc>0
147888 && (p->pSrc->a[0].fg.jointype & JT_LTORJ)!=0
147899 memset(&w, 0, sizeof(w));
147903 w.xSelectCallback2 = 0;
147904 w.walkerDepth = 0;
147920 ** if it is safe and the expression should be pushed down, or 0
147936 assert( (pSubq->selFlags & SF_MultiPart)==0 );
147937 assert( pSubq->pPrior==0 );
148048 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
148060 int nChng = 0;
148062 if( pWhere==0 ) return 0;
148064 return 0; /* restrictions (2) and (11) */
148067 return 0; /* restrictions (10) */
148072 int notUnionAll = 0;
148081 if( pSel->pWin ) return 0; /* restriction (6b) */
148091 assert( pList!=0 );
148092 for(ii=0; ii<pList->nExpr; ii++){
148095 return 0; /* Restriction (8) */
148102 if( pSubq->pWin && pSubq->pWin->pPartition==0 ) return 0;
148114 assert( (pX->selFlags & (SF_Recursive))==0 );
148119 if( pSubq->pLimit!=0 ){
148120 return 0; /* restriction (3) */
148127 #if 0 /* These checks now done by sqlite3ExprIsSingleTableConstraint() */
148129 && (pSrcList->a[0].fg.jointype & JT_LTORJ)!=0 /* Fast pre-test of (9c) */
148132 for(jj=0; jj<iSrc; jj++){
148138 if( (pSrcList->a[jj].fg.jointype & JT_RIGHT)!=0 ){
148139 return 0; /* restriction (9) */
148146 && (ExprHasProperty(pWhere,EP_OuterON)==0
148149 return 0; /* restriction (4) */
148154 return 0; /* restriction (5) */
148163 && pLeft->iColumn < 0
148165 return 0; /* Restriction (12) */
148175 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
148180 x.isOuterJoin = 0;
148185 if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
148217 int nChng = 0; /* Number of columns converted to NULL */
148220 assert( pItem!=0 );
148222 return 0;
148224 assert( pItem->pTab!=0 );
148226 assert( pItem->pSelect!=0 );
148230 if( (pX->selFlags & (SF_Distinct|SF_Aggregate))!=0 ){
148233 return 0;
148238 return 0;
148244 return 0;
148251 for(j=0; j<pList->nExpr; j++){
148253 if( iCol>0 ){
148260 for(j=0; j<nCol; j++){
148262 if( (m & colUsed)!=0 ) continue;
148297 u8 sortFlags = 0;
148299 assert( *ppMinMax==0 );
148304 if( pEList==0
148313 if( sqlite3StrICmp(zFunc, "min")==0 ){
148315 if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){
148318 }else if( sqlite3StrICmp(zFunc, "max")==0 ){
148324 *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
148325 assert( pOrderBy!=0 || db->mallocFailed );
148326 if( pOrderBy ) pOrderBy->a[0].fg.sortFlags = sortFlags;
148356 || p->pSrc->a[0].pSelect
148360 return 0;
148362 pTab = p->pSrc->a[0].pTab;
148363 assert( pTab!=0 );
148365 if( !IsOrdinaryTable(pTab) ) return 0;
148366 pExpr = p->pEList->a[0].pExpr;
148367 assert( pExpr!=0 );
148368 if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
148369 if( pExpr->pAggInfo!=pAggInfo ) return 0;
148370 if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0;
148371 assert( pAggInfo->aFunc[0].pFExpr==pExpr );
148374 if( ExprHasProperty(pExpr, EP_Distinct|EP_WinFunc) ) return 0;
148390 assert( pTab!=0 );
148391 assert( pFrom->fg.isIndexedBy!=0 );
148398 sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
148402 assert( pFrom->fg.isCte==0 );
148438 if( p->pPrior==0 ) return WRC_Continue;
148439 if( p->pOrderBy==0 ) return WRC_Continue;
148441 if( pX==0 ) return WRC_Continue;
148449 if( a[0].u.x.iOrderByCol ) return WRC_Continue;
148451 for(i=p->pOrderBy->nExpr-1; i>=0; i--){
148454 if( i<0 ) return WRC_Continue;
148461 if( pNew==0 ) return WRC_Abort;
148462 memset(&dummy, 0, sizeof(dummy));
148463 pNewSrc = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&dummy,pNew,0);
148464 if( pNewSrc==0 ) return WRC_Abort;
148467 p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ASTERISK, 0));
148469 p->pWhere = 0;
148470 pNew->pGroupBy = 0;
148471 pNew->pHaving = 0;
148472 pNew->pOrderBy = 0;
148473 p->pPrior = 0;
148474 p->pNext = 0;
148475 p->pWith = 0;
148477 p->pWinDefn = 0;
148480 assert( (p->selFlags & SF_Converted)==0 );
148482 assert( pNew->pPrior!=0 );
148484 pNew->pLimit = 0;
148498 return 0;
148519 assert( pItem->zDatabase==0 );
148520 assert( zName!=0 );
148523 for(i=0; i<p->nCte; i++){
148524 if( sqlite3StrICmp(zName, p->a[i].zName)==0 ){
148531 return 0;
148541 ** bFree==0, the With object will be freed along with the SELECT
148556 if( pWith==0 ) return 0;
148558 if( pParse->nErr==0 ){
148577 ** Return 0 if no match is found.
148589 assert( pFrom->pTab==0 );
148590 if( pParse->pWith==0 ){
148592 return 0;
148597 return 0;
148599 if( pFrom->zDatabase!=0 ){
148602 return 0;
148610 return 0;
148635 assert( pFrom->pTab==0 );
148637 if( pTab==0 ) return 2;
148639 if( pCteUse==0 ){
148640 pCte->pUse = pCteUse = sqlite3DbMallocZero(db, sizeof(pCteUse[0]));
148641 if( pCteUse==0
148642 || sqlite3ParserAddCleanup(pParse,sqlite3DbFree,pCteUse)==0
148655 pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
148673 assert( pRecTerm->pPrior!=0 );
148674 for(i=0; i<pSrc->nSrc; i++){
148676 if( pItem->zDatabase==0
148677 && pItem->zName!=0
148678 && 0==sqlite3StrICmp(pItem->zName, pCte->zName)
148690 if( iRecTab<0 ) iRecTab = pParse->nTab++;
148694 if( (pRecTerm->selFlags & SF_Recursive)==0 ) break;
148703 assert( pRecTerm!=0 );
148704 assert( (pRecTerm->selFlags & SF_Recursive)==0 );
148705 assert( pRecTerm->pNext!=0 );
148706 assert( (pRecTerm->pNext->selFlags & SF_Recursive)!=0 );
148707 assert( pRecTerm->pWith==0 );
148710 pRecTerm->pWith = 0;
148745 pCte->zCteErr = 0;
148749 return 0; /* No match */
148764 if( OK_IF_ALWAYS_TRUE(pParse->pWith) && p->pPrior==0 ){
148766 if( pWith!=0 ){
148787 if( pTab==0 ) return SQLITE_NOMEM;
148824 while( N>0 ){
148827 if( pBase->fg.isUsing==0 ) continue;
148828 if( NEVER(pBase->u3.pUsing==0) ) continue;
148829 if( sqlite3IdListIndex(pBase->u3.pUsing, zName)>=0 ) return 1;
148831 return 0;
148868 u32 elistFlags = 0;
148874 assert( p->pSrc!=0 );
148875 if( (selFlags & SF_Expanded)!=0 ){
148885 if( p->pWith==0 ){
148887 if( p->pWith==0 ){
148893 sqlite3WithPush(pParse, p->pWith, 0);
148904 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
148906 assert( pFrom->fg.isRecursive==0 || pFrom->pTab!=0 );
148908 assert( pFrom->fg.isRecursive==0 );
148909 if( pFrom->zName==0 ){
148913 assert( pSel!=0 );
148914 assert( pFrom->pTab==0 );
148919 }else if( (rc = resolveFromTermToCte(pParse, pWalker, pFrom))!=0 ){
148922 assert( pTab!=0 );
148926 assert( pFrom->pTab==0 );
148927 pFrom->pTab = pTab = sqlite3LocateTableItem(pParse, 0, pFrom);
148928 if( pTab==0 ) return WRC_Abort;
148929 if( pTab->nTabRef>=0xffff ){
148932 pFrom->pTab = 0;
148944 assert( pFrom->pSelect==0 );
148946 if( (db->flags & SQLITE_EnableView)==0
148952 pFrom->pSelect = sqlite3SelectDup(db, pTab->u.view.pSelect, 0);
148957 && ALWAYS(pTab->u.vtab.p!=0)
148958 && pTab->u.vtab.p->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0)
148983 assert( db->mallocFailed==0 || pParse->nErr!=0 );
148999 for(k=0; k<pEList->nExpr; k++){
149002 assert( pE->op!=TK_DOT || pE->pRight!=0 );
149003 assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) );
149014 ExprList *pNew = 0;
149016 int longNames = (flags & SQLITE_FullColNames)!=0
149017 && (flags & SQLITE_ShortColNames)==0;
149019 for(k=0; k<pEList->nExpr; k++){
149023 assert( pE->op!=TK_DOT || pRight!=0 );
149033 a[k].zEName = 0;
149035 a[k].pExpr = 0;
149039 int tableSeen = 0; /* Set to 1 when TABLE matches */
149040 char *zTName = 0; /* text of name of TABLE */
149043 assert( (selFlags & SF_NestedFrom)==0 );
149044 assert( pE->pLeft!=0 );
149053 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
149058 const char *zSchemaName = 0; /* Schema name for this data source */
149062 if( (zTabName = pFrom->zAlias)==0 ){
149068 assert( pFrom->pSelect!=0 );
149070 assert( pNestedFrom!=0 );
149072 assert( VisibleRowid(pTab)==0 || ViewCanHaveRowid );
149074 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
149077 pNestedFrom = 0;
149079 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
149083 && (selFlags & SF_NestedFrom)!=0
149087 for(ii=0; ii<pUsing->nId; ii++){
149094 assert( pX->zEName==0 );
149101 pUsing = 0;
149105 if( VisibleRowid(pTab) && (selFlags & SF_NestedFrom)!=0 ) nAdd++;
149106 for(j=0; j<nAdd; j++){
149112 if( zName==0 ) continue;
149124 && sqlite3MatchEName(&pNestedFrom->a[j], 0, zTName, 0, 0)==0
149133 if( (p->selFlags & SF_IncludeHidden)==0
149138 if( (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
149139 && zTName==0
149140 && (selFlags & (SF_NestedFrom))==0
149148 if( i>0 && zTName==0 && (selFlags & SF_NestedFrom)==0 ){
149150 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
149159 && ( (pFrom->fg.jointype & JT_LTORJ)==0
149160 || (selFlags & SF_NestedFrom)!=0
149181 if( pNew==0 ){
149185 assert( pX->zEName==0 );
149186 if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
149190 testcase( pX->zEName==0 );
149194 testcase( pX->zEName==0 );
149198 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0)
149199 || (pUsing && sqlite3IdListIndex(pUsing, zName)>=0)
149230 if( (elistFlags & (EP_HasFunc|EP_Subquery))!=0 ){
149235 if( sqlite3TreeTrace & 0x8 ){
149236 TREETRACE(0x8,pParse,p,("After result-set wildcard expansion:\n"));
149237 sqlite3TreeViewSelect(0, p, 0);
149250 assert( 0 );
149272 w.xSelectCallback2 = 0;
149277 w.eCode = 0;
149307 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
149309 assert( pTab!=0 );
149310 if( (pTab->tabFlags & TF_Ephemeral)!=0 ){
149358 assert( p!=0 || pParse->db->mallocFailed );
149377 for(ii=0; ii<pAggInfo->nColumn; ii++){
149386 sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0);
149388 for(ii=0; ii<pAggInfo->nFunc; ii++){
149391 sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pFExpr, 0);
149418 assert( pAggInfo!=0 );
149419 assert( pAggInfo->iFirstReg==0 );
149421 for(i=0; i<pAggInfo->nFunc; i++){
149454 assert( pAggInfo->iFirstReg==0 );
149455 assert( pSelect!=0 );
149456 assert( pSelect->pGroupBy!=0 );
149458 if( ALWAYS(pAggInfo->nSortingColumn>0) ){
149461 for(j=0; j<pAggInfo->nColumn; j++){
149469 if( sqlite3TreeTrace & 0x20 ){
149471 TREETRACE(0x20, pParse, pSelect,
149473 sqlite3TreeViewSelect(0, pSelect, 0);
149477 sqlite3TreeViewExpr(0, pIEpr->pExpr, 0);
149494 if( pExpr->pAggInfo==0 ) return WRC_Continue;
149500 assert( pExpr->iAgg>=0 );
149517 memset(&w, 0, sizeof(w));
149519 for(i=0; i<pAggInfo->nFunc; i++){
149543 assert( pAggInfo!=0 );
149544 assert( pAggInfo->iFirstReg==0 );
149562 assert( pAggInfo->iFirstReg>0 );
149564 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
149565 if( nReg==0 ) return;
149567 sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->iFirstReg,
149569 for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
149570 if( pFunc->iDistinct>=0 ){
149573 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
149578 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pE->x.pList,0,0);
149580 pFunc->iDistinct, 0, 0, (char*)pKeyInfo, P4_KEYINFO);
149581 ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s(DISTINCT)",
149585 if( pFunc->iOBTab>=0 ){
149588 int nExtra = 0;
149589 assert( pFunc->pFExpr->pLeft!=0 );
149592 assert( pFunc->pFunc!=0 );
149605 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOBList, 0, nExtra);
149606 if( !pFunc->bOBUnique && pParse->nErr==0 ){
149610 pFunc->iOBTab, pOBList->nExpr+nExtra, 0,
149612 ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s(ORDER BY)",
149626 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
149630 if( pF->iOBTab>=0 ){
149641 assert( pF->pFunc!=0 );
149645 if( pF->bOBPayload==0 ){
149646 nKey = 0;
149648 assert( pF->pFExpr->pLeft!=0 );
149650 assert( pF->pFExpr->pLeft->x.pList!=0 );
149655 for(j=nArg-1; j>=0; j--){
149660 int iBaseCol = nKey + nArg + (pF->bOBPayload==0 && pF->bOBUnique==0);
149661 for(j=nArg-1; j>=0; j--){
149667 sqlite3VdbeAddOp3(v, OP_AggStep, 0, regAgg, AggInfoFuncReg(pAggInfo,i));
149675 pList ? pList->nExpr : 0);
149686 ** registers if register regAcc contains 0. The caller will take care
149704 int regHit = 0;
149705 int addrHitTest = 0;
149709 assert( pAggInfo->iFirstReg>0 );
149712 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
149714 int addrNext = 0;
149716 int regAggSz = 0;
149717 int regDistinct = 0;
149721 assert( pF->pFunc!=0 );
149729 /* If regAcc==0, there there exists some min() or max() function
149732 if( regHit==0 ) regHit = ++pParse->nMem;
149733 /* If this is the first row of the group (regAcc contains 0), clear the
149745 if( pF->iOBTab>=0 ){
149750 assert( pList!=0 );
149752 assert( nArg>0 );
149753 assert( pF->pFExpr->pLeft!=0 );
149757 assert( pOBList!=0 );
149758 assert( pOBList->nExpr>0 );
149772 sqlite3ExprCodeExprList(pParse, pOBList, regAgg, 0, SQLITE_ECEL_DUP);
149780 sqlite3ExprCodeExprList(pParse, pList, regDistinct, 0, SQLITE_ECEL_DUP);
149786 for(kk=0; kk<nArg; kk++, jj++){
149794 sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
149796 nArg = 0;
149797 regAgg = 0;
149799 if( pF->iDistinct>=0 && pList ){
149800 if( addrNext==0 ){
149806 if( pF->iOBTab>=0 ){
149816 CollSeq *pColl = 0;
149819 assert( pList!=0 ); /* pList!=0 if pF->pFunc has NEEDCOLL */
149820 for(j=0, pItem=pList->a; !pColl && j<nArg; j++, pItem++){
149826 if( regHit==0 && pAggInfo->nAccumulator ) regHit = ++pParse->nMem;
149827 sqlite3VdbeAddOp4(v, OP_CollSeq, regHit, 0, 0,
149830 sqlite3VdbeAddOp3(v, OP_AggStep, 0, regAgg, AggInfoFuncReg(pAggInfo,i));
149839 if( regHit==0 && pAggInfo->nAccumulator ){
149845 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
149849 pAggInfo->directMode = 0;
149866 int bCover = (pIdx!=0 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pIdx)));
149867 sqlite3VdbeExplain(pParse, 0, "SCAN %s%s%s",
149900 && ExprAlwaysFalse(pExpr)==0
149901 && pExpr->pAggInfo==0
149935 memset(&sWalker, 0, sizeof(sWalker));
149941 if( sWalker.eCode && (sqlite3TreeTrace & 0x100)!=0 ){
149942 TREETRACE(0x100,pParse,p,("Move HAVING terms into WHERE:\n"));
149943 sqlite3TreeViewSelect(0, p, 0);
149954 ** instance of that view found. If pThis is not a self-join then return 0.
149962 assert( pThis->pSelect!=0 );
149963 if( pThis->pSelect->selFlags & SF_PushDown ) return 0;
149967 if( pItem->pSelect==0 ) continue;
149969 if( pItem->zName==0 ) continue;
149970 assert( pItem->pTab!=0 );
149971 assert( pThis->pTab!=0 );
149973 if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
149975 if( pItem->pTab->pSchema==0 && pThis->pSelect->selId!=pS1->selId ){
149987 return 0;
150024 if( (p->selFlags & SF_Aggregate)==0 ) return 0; /* This is an aggregate */
150025 if( p->pEList->nExpr!=1 ) return 0; /* Single result column */
150026 if( p->pWhere ) return 0;
150027 if( p->pHaving ) return 0;
150028 if( p->pGroupBy ) return 0;
150029 if( p->pOrderBy ) return 0;
150030 pExpr = p->pEList->a[0].pExpr;
150031 if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */
150033 if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */
150035 if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */
150036 if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */
150037 if( ExprHasProperty(pExpr, EP_WinFunc) ) return 0;/* Not a window function */
150038 pSub = p->pSrc->a[0].pSelect;
150039 if( pSub==0 ) return 0; /* The FROM is a subquery */
150040 if( pSub->pPrior==0 ) return 0; /* Must be a compound */
150041 if( pSub->selFlags & SF_CopyCte ) return 0; /* Not a CTE */
150043 if( pSub->op!=TK_ALL && pSub->pPrior ) return 0; /* Must be UNION ALL */
150044 if( pSub->pWhere ) return 0; /* No WHERE clause */
150045 if( pSub->pLimit ) return 0; /* No LIMIT clause */
150046 if( pSub->selFlags & SF_Aggregate ) return 0; /* Not an aggregate */
150047 assert( pSub->pHaving==0 ); /* Due to the previous */
150055 pExpr = 0;
150056 pSub = p->pSrc->a[0].pSelect;
150057 p->pSrc->a[0].pSelect = 0;
150063 pSub->pPrior = 0;
150064 pSub->pNext = 0;
150067 pSub->nSelectRow = 0;
150069 pTerm = pPrior ? sqlite3ExprDup(db, pCount, 0) : pCount;
150070 pSub->pEList = sqlite3ExprListAppend(pParse, 0, pTerm);
150071 pTerm = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
150073 if( pExpr==0 ){
150080 p->pEList->a[0].pExpr = pExpr;
150084 if( sqlite3TreeTrace & 0x200 ){
150085 TREETRACE(0x200,pParse,p,("After count-of-view optimization:\n"));
150086 sqlite3TreeViewSelect(0, p, 0);
150099 for(i=0; i<pSrc->nSrc; i++){
150102 if( p0->pTab==p1->pTab && 0==sqlite3_stricmp(p0->zAlias, p1->zAlias) ){
150106 && (p1->pSelect->selFlags & SF_NestedFrom)!=0
150112 return 0;
150152 if( pCteUse->eM10d==M10d_Yes ) return 0; /* (2a) */
150153 if( pCteUse->nUse>=2 && pCteUse->eM10d!=M10d_No ) return 0; /* (2b) */
150155 if( pTabList->a[0].fg.jointype & JT_LTORJ ) return 0; /* (3) */
150156 if( OptimizationDisabled(pParse->db, SQLITE_Coroutines) ) return 0; /* (4) */
150157 if( isSelfJoinView(pTabList, pItem, i+1, pTabList->nSrc)!=0 ){
150158 return 0; /* (5) */
150160 if( i==0 ){
150163 if( selFlags & SF_UpdateFrom ) return 0; /* (1c-iii) */
150166 if( selFlags & SF_UpdateFrom ) return 0; /* (1c-iii) */
150168 if( pItem->fg.jointype & (JT_OUTER|JT_CROSS) ) return 0; /* (1c-ii) */
150169 if( i==0 ) break;
150172 if( pItem->pSelect!=0 ) return 0; /* (1c-i) */
150199 ExprList *pEList = 0; /* List of columns to extract. */
150204 AggInfo *pAggInfo = 0; /* Aggregate information */
150210 ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
150216 if( p==0 || pParse->nErr ){
150219 assert( db->mallocFailed==0 );
150220 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
150222 TREETRACE(0x1,pParse,p, ("begin processing:\n", pParse->addrExplain));
150223 if( sqlite3TreeTrace & 0x10000 ){
150224 if( (sqlite3TreeTrace & 0x10001)==0x10000 ){
150225 sqlite3TreeViewLine(0, "In sqlite3Select() at %s:%d",
150232 assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistFifo );
150233 assert( p->pOrderBy==0 || pDest->eDest!=SRT_Fifo );
150234 assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistQueue );
150235 assert( p->pOrderBy==0 || pDest->eDest!=SRT_Queue );
150243 TREETRACE(0x800,pParse,p, ("dropping superfluous ORDER BY:\n"));
150244 if( sqlite3TreeTrace & 0x800 ){
150245 sqlite3TreeViewExprList(0, p->pOrderBy, 0, "ORDERBY");
150251 p->pOrderBy = 0;
150256 sqlite3SelectPrep(pParse, p, 0);
150260 assert( db->mallocFailed==0 );
150261 assert( p->pEList!=0 );
150263 if( sqlite3TreeTrace & 0x10 ){
150264 TREETRACE(0x10,pParse,p, ("after name resolution:\n"));
150265 sqlite3TreeViewSelect(0, p, 0);
150271 ** In this case, it is an error if the target object (pSrc->a[0]) name
150279 SrcItem *p0 = &p->pSrc->a[0];
150305 if( p->pWin && (sqlite3TreeTrace & 0x40)!=0 ){
150306 TREETRACE(0x40,pParse,p, ("after window rewrite:\n"));
150307 sqlite3TreeViewSelect(0, p, 0);
150312 isAgg = (p->selFlags & SF_Aggregate)!=0;
150313 memset(&sSort, 0, sizeof(sSort));
150320 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
150328 assert( pTab!=0 );
150341 if( (pItem->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
150348 TREETRACE(0x1000,pParse,p,
150352 TREETRACE(0x1000,pParse,p,
150355 unsetJoinExpr(p->pWhere, pItem->iCursor, 0);
150363 TREETRACE(0x1000,pParse,p,
150367 TREETRACE(0x1000,pParse,p,
150374 for(j=pTabList->nSrc-1; j>=0; j--){
150382 if( pSub==0 ) continue;
150407 if( (pSub->selFlags & SF_Aggregate)!=0 ) continue;
150408 assert( pSub->pGroupBy==0 );
150432 if( pSub->pOrderBy!=0
150433 && (p->pOrderBy!=0 || pTabList->nSrc>1) /* Condition (5) */
150434 && pSub->pLimit==0 /* Condition (1) */
150435 && (pSub->selFlags & SF_OrderByReqd)==0 /* Condition (2) */
150436 && (p->selFlags & SF_OrderByReqd)==0 /* Condition (3) and (4) */
150439 TREETRACE(0x800,pParse,p,
150443 pSub->pOrderBy = 0;
150464 if( pSub->pOrderBy!=0
150465 && i==0
150466 && (p->selFlags & SF_ComplexResult)!=0
150468 || (pTabList->a[1].fg.jointype&(JT_OUTER|JT_CROSS))!=0)
150493 TREETRACE(0x400,pParse,p,("end compound-select processing\n"));
150494 if( (sqlite3TreeTrace & 0x400)!=0 && ExplainQueryPlanParent(pParse)==0 ){
150495 sqlite3TreeViewSelect(0, p, 0);
150498 if( p->pNext==0 ) ExplainQueryPlanPop(pParse);
150508 if( p->pWhere!=0
150514 if( sqlite3TreeTrace & 0x2000 ){
150515 TREETRACE(0x2000,pParse,p,("After constant propagation:\n"));
150516 sqlite3TreeViewSelect(0, p, 0);
150520 TREETRACE(0x2000,pParse,p,("Constant propagation not helpful\n"));
150534 for(i=0; i<pTabList->nSrc; i++){
150559 if( pItem->colUsed==0 && pItem->zName!=0 ){
150567 if( pSub==0 || pItem->addrFillSub!=0 ) continue;
150570 assert( pItem->addrFillSub==0 );
150585 && (pItem->fg.isCte==0
150590 if( sqlite3TreeTrace & 0x4000 ){
150591 TREETRACE(0x4000,pParse,p,
150593 sqlite3TreeViewSelect(0, p, 0);
150596 assert( pItem->pSelect && (pItem->pSelect->selFlags & SF_PushDown)!=0 );
150598 TREETRACE(0x4000,pParse,p,("WHERE-lcause push-down not possible\n"));
150608 if( sqlite3TreeTrace & 0x4000 ){
150609 TREETRACE(0x4000,pParse,p,
150612 sqlite3TreeViewSelect(0, p, 0);
150629 sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);
150641 }else if( pItem->fg.isCte && pItem->u2.pCteUse->addrM9e>0 ){
150653 }else if( (pPrior = isSelfJoinView(pTabList, pItem, 0, i))!=0 ){
150666 int onceAddr = 0;
150675 if( pItem->fg.isCorrelated==0 ){
150695 if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
150715 sDistinct.isTnct = (p->selFlags & SF_Distinct)!=0;
150718 if( sqlite3TreeTrace & 0x8000 ){
150719 TREETRACE(0x8000,pParse,p,("After all FROM-clause analysis:\n"));
150720 sqlite3TreeViewSelect(0, p, 0);
150740 && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
150742 && p->pWin==0
150746 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
150755 if( sqlite3TreeTrace & 0x20000 ){
150756 TREETRACE(0x20000,pParse,p,("Transform DISTINCT into GROUP BY:\n"));
150757 sqlite3TreeViewSelect(0, p, 0);
150773 pParse, sSort.pOrderBy, 0, pEList->nExpr);
150777 sSort.iECursor, sSort.pOrderBy->nExpr+1+pEList->nExpr, 0,
150791 for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].fg.bUsed==0; ii--){
150796 for(ii=0; ii<pEList->nExpr; ii++){
150797 if( pEList->a[ii].fg.bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
150805 if( (p->selFlags & SF_FixedLimit)==0 ){
150809 if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
150819 sDistinct.tabTnct, 0, 0,
150820 (char*)sqlite3KeyInfoFromExprList(pParse, p->pEList,0,0),
150828 if( !isAgg && pGroupBy==0 ){
150830 u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0)
150842 TREETRACE(0x2,pParse,p,("WhereBegin\n"));
150845 if( pWInfo==0 ) goto select_end;
150856 sSort.pOrderBy = 0;
150859 TREETRACE(0x2,pParse,p,("WhereBegin returns\n"));
150865 if( sSort.addrSortIndex>=0 && sSort.pOrderBy==0 ){
150879 sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
150882 sSort.labelOBLopt = 0;
150898 TREETRACE(0x2,pParse,p,("WhereEnd\n"));
150913 int sortPTab = 0; /* Pseudotable used to decode sorting results */
150914 int sortOut = 0; /* Output register from the sorter */
150915 int orderByGrp = 0; /* True if the GROUP BY and ORDER BY are the same */
150924 for(k=p->pEList->nExpr, pItem=p->pEList->a; k>0; k--, pItem++){
150925 pItem->u.x.iAlias = 0;
150927 for(k=pGroupBy->nExpr, pItem=pGroupBy->a; k>0; k--, pItem++){
150928 pItem->u.x.iAlias = 0;
150948 for(ii=0; ii<pGroupBy->nExpr; ii++){
150953 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
150958 assert( 0==sqlite3LogEst(1) );
150959 p->nSelectRow = 0;
150981 memset(&sNC, 0, sizeof(sNC));
150986 pAggInfo->nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
151001 if( p->pGroupBy==0 && p->pHaving==0 && pAggInfo->nFunc==1 ){
151002 minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pFExpr, &pMinMaxOrderBy);
151009 if( sqlite3TreeTrace & 0x20 ){
151010 TREETRACE(0x20,pParse,p,("After aggregate analysis %p:\n", pAggInfo));
151011 sqlite3TreeViewSelect(0, p, 0);
151013 sqlite3DebugPrintf("MIN/MAX Optimization (0x%02x) adds:\n", minMaxFlag);
151014 sqlite3TreeViewExprList(0, pMinMaxOrderBy, 0, "ORDERBY");
151034 ExprList *pDistinct = 0;
151035 u16 distFlag = 0;
151039 && pAggInfo->aFunc[0].iDistinct>=0
151040 && ALWAYS(pAggInfo->aFunc[0].pFExpr!=0)
151041 && ALWAYS(ExprUseXList(pAggInfo->aFunc[0].pFExpr))
151042 && pAggInfo->aFunc[0].pFExpr->x.pList!=0
151044 Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr;
151045 pExpr = sqlite3ExprDup(db, pExpr, 0);
151046 pDistinct = sqlite3ExprListDup(db, pGroupBy, 0);
151048 distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
151058 0, pAggInfo->nColumn);
151061 0, (char*)pKeyInfo, P4_KEYINFO);
151075 sqlite3VdbeAddOp2(v, OP_Integer, 0, iAbortFlag);
151077 sqlite3VdbeAddOp3(v, OP_Null, 0, iAMem, iAMem+pGroupBy->nExpr-1);
151085 TREETRACE(0x2,pParse,p,("WhereBegin\n"));
151088 | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
151090 if( pWInfo==0 ){
151099 TREETRACE(0x2,pParse,p,("WhereBegin returns\n"));
151105 groupBySort = 0;
151120 ExplainQueryPlan2(addrExp, (pParse, 0, "USE TEMP B-TREE FOR %s",
151121 (sDistinct.isTnct && (p->selFlags&SF_Distinct)==0) ?
151129 for(i=0; i<pAggInfo->nColumn; i++){
151136 sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
151139 for(i=0; i<pAggInfo->nColumn; i++){
151146 pAggInfo->directMode = 0;
151148 sqlite3VdbeScanStatusCounters(v, addrExp, 0, sqlite3VdbeCurrentAddr(v));
151154 TREETRACE(0x2,pParse,p,("WhereEnd\n"));
151158 sqlite3VdbeScanStatusCounters(v, addrExp, sqlite3VdbeCurrentAddr(v), 0);
151175 if( sqlite3TreeTrace & 0x20 ){
151176 TREETRACE(0x20, pParse, p,
151178 sqlite3TreeViewSelect(0, p, 0);
151194 sSort.pOrderBy = 0;
151199 ** (b0 is memory location iBMem+0, b1 is iBMem+1, and so forth)
151208 for(j=0; j<pGroupBy->nExpr; j++){
151219 sqlite3VdbeAddOp3(v, OP_Jump, addr1+1, 0, addr1+1); VdbeCoverage(v);
151252 TREETRACE(0x2,pParse,p,("WhereEnd\n"));
151296 sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
151300 if( distFlag!=0 && eDist!=WHERE_DISTINCT_NOOP ){
151301 struct AggInfo_func *pF = &pAggInfo->aFunc[0];
151307 if( (pTab = isSimpleCount(p, pAggInfo))!=0 ){
151324 KeyInfo *pKeyInfo = 0; /* Keyinfo for scanned index */
151325 Index *pBest = 0; /* Best index found so far */
151329 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
151341 if( !p->pSrc->a[0].fg.notIndexed ){
151343 if( pIdx->bUnordered==0
151345 && pIdx->pPartIdxWhere==0
151363 sqlite3VdbeAddOp2(v, OP_Count, iCsr, AggInfoFuncReg(pAggInfo,0));
151367 int regAcc = 0; /* "populate accumulators" flag */
151368 ExprList *pDistinct = 0;
151369 u16 distFlag = 0;
151374 ** will contain 0 the first time the inner loop runs, and 1 thereafter.
151382 for(i=0; i<pAggInfo->nFunc; i++){
151392 sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
151394 }else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){
151395 assert( ExprUseXList(pAggInfo->aFunc[0].pFExpr) );
151396 pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList;
151397 distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
151405 assert( p->pGroupBy==0 );
151413 assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
151414 assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
151416 TREETRACE(0x2,pParse,p,("WhereBegin\n"));
151418 pDistinct, p, minMaxFlag|distFlag, 0);
151419 if( pWInfo==0 ){
151422 TREETRACE(0x2,pParse,p,("WhereBegin returns\n"));
151436 TREETRACE(0x2,pParse,p,("WhereEnd\n"));
151441 sSort.pOrderBy = 0;
151443 selectInnerLoop(pParse, p, -1, 0, 0,
151467 ** set the return code to 1. Otherwise 0. */
151468 rc = (pParse->nErr>0);
151474 assert( db->mallocFailed==0 || db->mallocFailed==1 );
151475 assert( db->mallocFailed==0 || pParse->nErr!=0 );
151480 if( sqlite3TreeTrace & 0x20 ){
151481 TREETRACE(0x20,pParse,p,("Finished with AggInfo\n"));
151485 for(i=0; i<pAggInfo->nColumn; i++){
151487 if( pExpr==0 ) continue;
151491 for(i=0; i<pAggInfo->nFunc; i++){
151493 assert( pExpr!=0 );
151501 TREETRACE(0x1,pParse,p,("end processing\n"));
151502 if( (sqlite3TreeTrace & 0x40000)!=0 && ExplainQueryPlanParent(pParse)==0 ){
151503 sqlite3TreeViewSelect(0, p, 0);
151562 if( p->nRow==0 && argv!=0 ){
151571 if( azNew==0 ) goto malloc_failed;
151578 if( p->nRow==0 ){
151580 for(i=0; i<nCol; i++){
151582 if( z==0 ) goto malloc_failed;
151596 if( argv!=0 ){
151597 for(i=0; i<nCol; i++){
151598 if( argv[i]==0 ){
151599 z = 0;
151603 if( z==0 ) goto malloc_failed;
151610 return 0;
151639 if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT;
151641 *pazResult = 0;
151642 if( pnColumn ) *pnColumn = 0;
151643 if( pnRow ) *pnRow = 0;
151644 if( pzErrMsg ) *pzErrMsg = 0;
151645 res.zErrMsg = 0;
151646 res.nRow = 0;
151647 res.nColumn = 0;
151652 if( res.azResult==0 ){
151656 res.azResult[0] = 0;
151658 assert( sizeof(res.azResult[0])>= sizeof(res.nData) );
151659 res.azResult[0] = SQLITE_INT_TO_PTR(res.nData);
151660 if( (rc&0xff)==SQLITE_ABORT ){
151680 if( azNew==0 ){
151702 assert( azResult!=0 );
151703 n = SQLITE_PTR_TO_INT(azResult[0]);
151767 assert( pParse->disableTriggers==0 );
151775 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
151782 assert( pParse->db->pVtabCtx==0 );
151793 #if 0
151827 Trigger *pTrigger = 0; /* The new trigger */
151829 char *zName = 0; /* Name of the trigger */
151835 assert( pName1!=0 ); /* pName1->z might be NULL, but not pName1 itself */
151836 assert( pName2!=0 );
151838 assert( op>0 && op<0xff );
151841 if( pName2->n>0 ){
151850 if( iDb<0 ){
151867 sqlite3DbFree(db, pTableName->a[0].zDatabase);
151868 pTableName->a[0].zDatabase = 0;
151873 ** If sqlite3SrcListLookup() returns 0, indicating the table does not
151877 if( db->init.busy==0 && pName2->n==0 && pTab
151898 if( (pTab->tabFlags & TF_Shadow)!=0 && sqlite3ReadOnlyShadowTables(db) ){
151906 if( zName==0 ){
151913 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
151928 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
151957 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
151974 if( pTrigger==0 ) goto trigger_cleanup;
151976 zName = 0;
151977 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
151983 sqlite3RenameTokenRemap(pParse, pTrigger->table, pTableName->a[0].zName);
151985 pWhen = 0;
151990 pColumns = 0;
151991 assert( pParse->pNewTrigger==0 );
152039 pParse->pNewTrigger = 0;
152060 pTrig = 0;
152077 if( pStep->zTarget!=0
152090 if( v==0 ) goto triggerfinish_cleanup;
152091 sqlite3BeginWriteOperation(pParse, 0, iDb);
152093 testcase( z==0 );
152096 " VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
152102 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName), 0);
152108 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
152109 assert( pLink!=0 );
152116 assert( pTab!=0 );
152135 if( z ) for(i=0; z[i]; i++) if( sqlite3Isspace(z[i]) ) z[i] = ' ';
152153 if( pTriggerStep==0 ) {
152155 return 0;
152180 if( pParse->nErr ) return 0;
152216 assert(pSelect != 0 || db->mallocFailed);
152222 pSelect = 0;
152267 pEList = 0;
152268 pWhere = 0;
152269 pFrom = 0;
152302 pWhere = 0;
152316 if( pTrigger==0 || pTrigger->bReturning ) return;
152334 Trigger *pTrigger = 0;
152346 zDb = pName->a[0].zDatabase;
152347 zName = pName->a[0].zName;
152348 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
152351 if( zDb && sqlite3DbIsNamed(db, j, zDb)==0 ) continue;
152352 assert( sqlite3SchemaMutexHeld(db, j, 0) );
152390 assert( iDb>=0 && iDb<db->nDb );
152400 sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
152408 if( (v = sqlite3GetVdbe(pParse))!=0 ){
152414 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
152425 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
152427 pTrigger = sqlite3HashInsert(pHash, zName, 0);
152457 if( pIdList==0 || NEVER(pEList==0) ) return 1;
152458 for(e=0; e<pEList->nExpr; e++){
152459 if( sqlite3IdListIndex(pIdList, pEList->a[e].zEName)>=0 ) return 1;
152461 return 0;
152468 if( NEVER(db->aDb[1].pSchema==0) ) return 0;
152469 if( sqliteHashFirst(&db->aDb[1].pSchema->trigHash)==0 ) return 0;
152486 int mask = 0;
152487 Trigger *pList = 0;
152491 assert( pList==0 || IsVirtual(pTab)==0
152492 || (pList->bReturning && pList->pNext==0) );
152493 if( pList!=0 ){
152495 if( (pParse->db->flags & SQLITE_EnableTrigger)==0
152496 && pTab->pTrigger!=0
152502 pList = 0;
152506 p->pNext = 0;
152540 return (mask ? pList : 0);
152549 assert( pTab!=0 );
152550 if( (pTab->pTrigger==0 && !tempTriggersExist(pParse->db))
152553 if( pMask ) *pMask = 0;
152554 return 0;
152576 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
152577 assert( pSrc==0 || pSrc->nSrc==1 );
152578 assert( zName || pSrc==0 );
152581 pSrc->a[0].zName = zName;
152583 pSrc->a[0].pSchema = pSchema;
152586 SrcList *pDup = sqlite3SrcListDup(db, pStep->pFrom, 0);
152590 pSubquery = sqlite3SelectNew(pParse,0,pDup,0,0,0,0,SF_NestedFrom,0);
152591 as.n = 0;
152592 as.z = 0;
152593 pDup = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
152612 assert( pTerm!=0 );
152614 if( pTerm->op!=TK_DOT ) return 0;
152615 assert( pTerm->pRight!=0 );
152616 assert( pTerm->pLeft!=0 );
152617 if( pTerm->pRight->op!=TK_ASTERISK ) return 0;
152633 ExprList *pNew = 0;
152637 for(i=0; i<pList->nExpr; i++){
152639 if( NEVER(pOldExpr==0) ) continue;
152642 for(jj=0; jj<pTab->nCol; jj++){
152654 Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
152656 if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
152673 && (pExpr->x.pSelect->selFlags & SF_Correlated)!=0
152692 assert( pSelect!=0 );
152694 assert( pSrc!=0 );
152695 for(i=0; i<pSrc->nSrc; i++){
152720 memset(&w, 0, sizeof(w));
152750 assert( v!=0 );
152762 memset(&sSelect, 0, sizeof(sSelect));
152763 memset(&sFrom, 0, sizeof(sFrom));
152764 sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
152767 sFrom.a[0].pTab = pTab;
152768 sFrom.a[0].zName = pTab->zName; /* tag-20240424-1 */
152769 sFrom.a[0].iCursor = -1;
152770 sqlite3SelectPrep(pParse, &sSelect, 0);
152771 if( pParse->nErr==0 ){
152772 assert( db->mallocFailed==0 );
152777 if( pParse->nErr==0 ){
152779 memset(&sNC, 0, sizeof(sNC));
152780 if( pReturning->nRetCol==0 ){
152798 for(i=0; i<nCol; i++){
152800 assert( pCol!=0 ); /* Due to !db->mallocFailed ~9 lines above */
152812 pParse->eTriggerOp = 0;
152813 pParse->pTriggerTab = 0;
152833 assert( v!=0 );
152849 assert( pParse->okConstFactor==0 );
152853 sqlite3VdbeAddOp4(v, OP_Trace, 0x7fffffff, 1, 0,
152863 sqlite3ExprListDup(db, pStep->pExprList, 0),
152864 sqlite3ExprDup(db, pStep->pWhere, 0),
152865 pParse->eOrconf, 0, 0, 0
152873 sqlite3SelectDup(db, pStep->pSelect, 0),
152884 sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0
152891 Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
152892 sqlite3SelectDestInit(&sDest, SRT_Discard, 0);
152900 return 0;
152927 assert( pFrom->zErrMsg==0 || pFrom->nErr );
152928 assert( pTo->zErrMsg==0 || pTo->nErr );
152929 if( pTo->nErr==0 ){
152951 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
152954 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
152955 int iEndTrigger = 0; /* Label to jump to if WHEN is false */
152958 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
152965 if( !pPrg ) return 0;
152969 if( !pProgram ) return 0;
152973 pPrg->aColmask[0] = 0xffffffff;
152974 pPrg->aColmask[1] = 0xffffffff;
152979 memset(&sNC, 0, sizeof(sNC));
153010 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
153011 if( db->mallocFailed==0
153031 if( pParse->nErr==0 ){
153032 assert( db->mallocFailed==0 );
153038 pPrg->aColmask[0] = sSubParse.oldmask;
153065 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
153107 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
153140 ** reg+0 OLD.rowid
153178 assert( (op==TK_UPDATE)==(pChanges!=0) );
153185 assert( p->pSchema!=0 );
153186 assert( p->pTabSchema!=0 );
153215 ** Bit 0 of the returned mask is set if the left-most column of the
153219 ** with an index greater than 32 may be accessed, 0xffffffff is returned.
153224 ** Parameter isNew must be either 1 or 0. If it is 0, then the mask returned
153237 int isNew, /* 1 for new.* ref mask, 0 for old.* ref mask */
153243 u32 mask = 0;
153246 assert( isNew==1 || isNew==0 );
153248 return 0xffffffff;
153256 mask = 0xffffffff;
153336 assert( pTab!=0 );
153340 sqlite3_value *pValue = 0;
153373 int *aXRef, /* aXRef[j]>=0 if column j is being updated */
153378 if( iIdxCol>=0 ){
153379 return aXRef[iIdxCol]>=0;
153382 assert( pIdx->aColExpr!=0 );
153383 assert( pIdx->aColExpr->a[iCol].pExpr!=0 );
153402 int *aXRef, /* aXRef[j]>=0 if column j is being updated */
153405 if( pIdx->pPartIdxWhere==0 ) return 0;
153414 ** table in the source-list (pSrc->a[0]).
153417 Expr *pRet = sqlite3PExpr(pParse, TK_ROW, 0, 0);
153443 ** of table pTabList->a[0].pTab.
153463 Index *pPk, /* PK if table 0 is WITHOUT ROWID */
153472 Select *pSelect = 0;
153473 ExprList *pList = 0;
153474 ExprList *pGrp = 0;
153475 Expr *pLimit2 = 0;
153476 ExprList *pOrderBy2 = 0;
153478 Table *pTab = pTabList->a[0].pTab;
153484 if( pOrderBy && pLimit==0 ) {
153488 pOrderBy2 = sqlite3ExprListDup(db, pOrderBy, 0);
153489 pLimit2 = sqlite3ExprDup(db, pLimit, 0);
153495 pSrc = sqlite3SrcListDup(db, pTabList, 0);
153496 pWhere2 = sqlite3ExprDup(db, pWhere, 0);
153500 assert( pSrc->a[0].fg.notCte );
153501 pSrc->a[0].iCursor = -1;
153502 pSrc->a[0].pTab->nTabRef--;
153503 pSrc->a[0].pTab = 0;
153506 for(i=0; i<pPk->nKeyCol; i++){
153510 pGrp = sqlite3ExprListAppend(pParse, pGrp, sqlite3ExprDup(db, pNew, 0));
153517 for(i=0; i<pTab->nCol; i++){
153523 pList = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
153526 pGrp = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
153530 assert( pChanges!=0 || pParse->db->mallocFailed );
153532 for(i=0; i<pChanges->nExpr; i++){
153534 sqlite3ExprDup(db, pChanges->a[i].pExpr, 0)
153539 pSrc, pWhere2, pGrp, 0, pOrderBy2,
153570 int addrTop = 0; /* VDBE instruction address of the start of the loop */
153571 WhereInfo *pWInfo = 0; /* Information about the WHERE clause */
153581 int *aRegIdx = 0; /* Registers for to each index and the main table */
153582 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
153589 Expr *pRowidExpr = 0; /* Expression defining the new record number */
153606 int iEph = 0; /* Ephemeral table holding all primary key values */
153607 int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */
153609 int addrOpen = 0; /* Address of OP_OpenEphemeral */
153610 int iPk = 0; /* First of nPk cells holding PRIMARY KEY value */
153611 i16 nPk = 0; /* Number of components of the PRIMARY KEY */
153612 int bReplace = 0; /* True if REPLACE conflict resolution might happen */
153614 int nChangeFrom = 0; /* If there is a FROM, pChanges->nExpr, else 0 */
153617 int regRowCount = 0; /* A count of rows changed */
153618 int regOldRowid = 0; /* The old rowid */
153619 int regNewRowid = 0; /* The new rowid */
153620 int regNew = 0; /* Content of the NEW.* table in triggers */
153621 int regOld = 0; /* Content of OLD.* table in triggers */
153622 int regRowSet = 0; /* Rowset of rows to be updated */
153623 int regKey = 0; /* composite PRIMARY KEY value */
153625 memset(&sContext, 0, sizeof(sContext));
153631 assert( db->mallocFailed==0 );
153636 if( pTab==0 ) goto update_cleanup;
153645 assert( pTrigger || tmask==0 );
153647 # define pTrigger 0
153648 # define isView 0
153649 # define tmask 0
153653 # define isView 0
153657 if( sqlite3TreeTrace & 0x10000 ){
153658 sqlite3TreeViewLine(0, "In sqlite3Update() at %s:%d", __FILE__, __LINE__);
153665 ** in the change-list. Otherwise, set it to 0. There cannot be a FROM
153668 nChangeFrom = (pTabList->nSrc>1) ? pChanges->nExpr : 0;
153669 assert( nChangeFrom==0 || pUpsert==0 );
153672 if( !isView && nChangeFrom==0 ){
153676 pOrderBy = 0;
153677 pLimit = 0;
153695 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
153696 testcase( pPk!=0 && pPk!=pTab->pIndex );
153697 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
153709 pTabList->a[0].iCursor = iDataCur;
153715 if( aXRef==0 ) goto update_cleanup;
153719 aToOpen[nIdx+1] = 0;
153720 for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
153723 memset(&sNC, 0, sizeof(sNC));
153731 if( v==0 ) goto update_cleanup;
153739 chngRowid = chngPk = 0;
153740 for(i=0; i<pChanges->nExpr; i++){
153744 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
153747 for(j=0; j<pTab->nCol; j++){
153749 && sqlite3StrICmp(pTab->aCol[j].zCnName, pChanges->a[i].zEName)==0
153755 }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
153773 if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){
153788 j<0 ? "ROWID" : pTab->aCol[j].zCnName,
153798 assert( (chngRowid & chngPk)==0 );
153799 assert( chngRowid==0 || chngRowid==1 );
153800 assert( chngPk==0 || chngPk==1 );
153816 bProgress = 0;
153817 for(i=0; i<pTab->nCol; i++){
153818 if( aXRef[i]>=0 ) continue;
153819 if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ) continue;
153837 pTabList->a[0].colUsed = IsVirtual(pTab) ? ALLBITS : 0;
153846 for(nAllIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nAllIdx++){
153854 reg = 0;
153855 for(i=0; i<pIdx->nKeyCol; i++){
153866 if( reg==0 ) aToOpen[nAllIdx+1] = 0;
153876 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
153909 if( nChangeFrom==0 && isView ){
153913 pOrderBy = 0;
153914 pLimit = 0;
153921 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pWhere) ){
153939 if( (db->flags&SQLITE_CountRows)!=0
153943 && pUpsert==0
153946 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
153949 if( nChangeFrom==0 && HasRowid(pTab) ){
153950 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
153952 addrOpen = sqlite3VdbeAddOp3(v, OP_OpenEphemeral, iEph, 0, regRowSet);
153954 assert( pPk!=0 || HasRowid(pTab) );
153955 nPk = pPk ? pPk->nKeyCol : 0;
153960 if( pUpsert==0 ){
153961 int nEphCol = nPk + nChangeFrom + (isView ? pTab->nCol : 0);
153963 if( pPk ) sqlite3VdbeAddOp3(v, OP_Null, 0, iPk, iPk+nPk-1);
153995 pWInfo = 0;
153998 bFinishSeek = 0;
154017 && (pWhere==0 || !ExprHasProperty(pWhere, EP_Subquery))
154021 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0,0,0,flags,iIdxCur);
154022 if( pWInfo==0 ) goto update_cleanup;
154040 if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){
154065 for(i=0; i<nPk; i++){
154066 assert( pPk->aiColumn[i]>=0 );
154082 if( pUpsert==0 ){
154083 if( nChangeFrom==0 && eOnePass!=ONEPASS_MULTI ){
154088 int addrOnce = 0;
154089 int iNotUsed1 = 0;
154090 int iNotUsed2 = 0;
154094 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0;
154095 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0;
154098 if( eOnePass==ONEPASS_MULTI && (nIdx-(aiCurOnePass[1]>=0))>0 ){
154101 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur,
154110 if( aiCurOnePass[0]!=iDataCur
154124 VdbeCoverageIf(v, pPk==0);
154125 VdbeCoverageIf(v, pPk!=0);
154133 for(i=0; i<nPk; i++){
154148 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey,0);
154167 assert( iRowidExpr>=0 );
154168 if( nChangeFrom==0 ){
154179 u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);
154181 pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError
154183 for(i=0; i<pTab->nCol; i++){
154186 if( oldmask==0xffffffff
154187 || (i<32 && (oldmask & MASKBIT32(i))!=0)
154188 || (colFlags & COLFLAG_PRIMKEY)!=0
154190 testcase( oldmask!=0xffffffff && i==31 );
154193 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
154196 if( chngRowid==0 && pPk==0 ){
154198 if( isView ) sqlite3VdbeAddOp2(v, OP_Null, 0, regOldRowid);
154220 for(i=0, k=regNew; i<pTab->nCol; i++, k++){
154222 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
154223 }else if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)!=0 ){
154227 if( j>=0 ){
154235 }else if( 0==(tmask&TRIGGER_BEFORE) || i>31 || (newmask & MASKBIT32(i)) ){
154244 bFinishSeek = 0;
154246 sqlite3VdbeAddOp2(v, OP_Null, 0, k);
154290 for(i=0, k=regNew; i<pTab->nCol; i++, k++){
154293 }else if( aXRef[i]<0 && i!=pTab->iPKey ){
154309 assert( regOldRowid>0 );
154312 aXRef, 0);
154328 sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
154355 OPFLAG_ISUPDATE | ((hasFK>1 || chngKey) ? 0 : OPFLAG_ISNOOP),
154359 assert( hasFK==0 && chngKey==0 );
154367 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
154372 sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey);
154378 OPFLAG_ISUPDATE | (eOnePass==ONEPASS_MULTI ? OPFLAG_SAVEPOSITION : 0),
154379 0, 0
154419 if( pParse->nested==0 && pParse->pTriggerTab==0 && pUpsert==0 ){
154490 WhereInfo *pWInfo = 0;
154495 int iCsr = pSrc->a[0].iCursor; /* Cursor used for virtual table scan */
154509 Index *pPk = 0;
154514 pRow = sqlite3ExprDup(db, pRowid, 0);
154516 pRow = sqlite3PExpr(pParse, TK_ROW, 0, 0);
154521 assert( pPk!=0 );
154523 iPk = pPk->aiColumn[0];
154524 if( aXRef[iPk]>=0 ){
154525 pRow = sqlite3ExprDup(db, pChanges->a[aXRef[iPk]].pExpr, 0);
154530 pList = sqlite3ExprListAppend(pParse, 0, pRow);
154532 for(i=0; i<pTab->nCol; i++){
154533 if( aXRef[i]>=0 ){
154535 sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0)
154544 updateFromSelect(pParse, ephemTab, pPk, pList, pSrc, pWhere, 0, 0);
154553 pParse, pSrc, pWhere, 0, 0, 0, WHERE_ONEPASS_DESIRED, 0
154555 if( pWInfo==0 ) return;
154558 for(i=0; i<pTab->nCol; i++){
154559 assert( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 );
154560 if( aXRef[i]>=0 ){
154578 assert( pPk!=0 );
154580 iPk = pPk->aiColumn[0];
154622 for(i=0; i<nArg; i++){
154627 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, nArg, regArg, pVTab, P4_VTAB);
154636 sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
154686 if( p==0 ) return 0;
154688 sqlite3ExprListDup(db, p->pUpsertTarget, 0),
154689 sqlite3ExprDup(db, p->pUpsertTargetWhere, 0),
154690 sqlite3ExprListDup(db, p->pUpsertSet, 0),
154691 sqlite3ExprDup(db, p->pUpsertWhere, 0),
154709 if( pNew==0 ){
154715 return 0;
154721 pNew->isDoUpdate = pSet!=0;
154748 int nClause = 0; /* Counter of ON CONFLICT clauses */
154751 assert( pTabList->a[0].pTab!=0 );
154752 assert( pUpsert!=0 );
154753 assert( pUpsert->pUpsertTarget!=0 );
154759 memset(&sNC, 0, sizeof(sNC));
154770 pTab = pTabList->a[0].pTab;
154772 iCursor = pTabList->a[0].iCursor;
154775 && (pTerm = pTarget->a[0].pExpr)->op==TK_COLUMN
154779 assert( pUpsert->pUpsertIdx==0 );
154783 /* Initialize sCol[0..1] to be an expression parse tree for a
154784 ** single column of an index. The sCol[0] node will be the TK_COLLATE
154789 memset(sCol, 0, sizeof(sCol));
154790 sCol[0].op = TK_COLLATE;
154791 sCol[0].pLeft = &sCol[1];
154793 sCol[1].iTable = pTabList->a[0].iCursor;
154801 if( pUpsert->pUpsertTargetWhere==0 ) continue;
154803 pIdx->pPartIdxWhere, iCursor)!=0 ){
154808 for(ii=0; ii<nn; ii++){
154810 sCol[0].u.zToken = (char*)pIdx->azColl[ii];
154812 assert( pIdx->aColExpr!=0 );
154817 sCol[0].pLeft = pExpr;
154818 pExpr = &sCol[0];
154821 sCol[0].pLeft = &sCol[1];
154823 pExpr = &sCol[0];
154825 for(jj=0; jj<nn; jj++){
154826 if( sqlite3ExprCompare(0,pTarget->a[jj].pExpr,pExpr,iCursor)<2 ){
154851 if( pUpsert->pUpsertIdx==0 ){
154853 if( nClause==0 && pUpsert->pNextUpsert==0 ){
154854 zWhich[0] = 0;
154873 if( NEVER(pUpsert==0) ) return 0;
154876 if( pNext==0 ) return 1;
154877 if( pNext->pUpsertTarget==0 ) return 1;
154878 if( pNext->pUpsertIdx==0 ) return 1;
154879 if( !pNext->isDup ) return 0;
154882 return 0;
154894 && pUpsert->pUpsertTarget!=0
154925 assert( v!=0 );
154926 assert( pUpsert!=0 );
154934 sqlite3VdbeAddOp3(v, OP_SeekRowid, iDataCur, 0, regRowid);
154942 for(i=0; i<nPk; i++){
154944 assert( pPk->aiColumn[i]>=0 );
154951 i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk);
154953 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0,
154961 pSrc = sqlite3SrcListDup(db, pTop->pUpsertSrc, 0);
154963 for(i=0; i<pTab->nCol; i++){
154968 sqlite3Update(pParse, pSrc, sqlite3ExprListDup(db,pUpsert->pUpsertSet,0),
154969 sqlite3ExprDup(db,pUpsert->pUpsertWhere,0), OE_Abort, 0, 0, pUpsert);
155013 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
155016 const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0);
155017 assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 );
155024 && (strncmp(zSubSql,"CRE",3)==0 || strncmp(zSubSql,"INS",3)==0)
155045 if( z==0 ) return SQLITE_NOMEM;
155083 int iDb = 0;
155084 if( v==0 ) goto build_vacuum_end;
155091 if( iDb<0 ) goto build_vacuum_end;
155099 if( iDb<0 ) iDb = 0;
155103 int iIntoReg = 0;
155104 if( pInto && sqlite3ResolveSelfReference(pParse,0,0,pInto,0)==0 ){
155134 Db *pDb = 0; /* Database to detach at end of vacuum */
155175 db->mTrace = 0;
155201 assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
155205 i64 sz = 0;
155206 if( id->pMethods!=0 && (sqlite3OsFileSize(id, &sz)!=SQLITE_OK || sz>0) ){
155221 sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
155230 rc = sqlite3BtreeBeginTrans(pMain, pOut==0 ? 2 : 0, 0);
155236 && pOut==0
155238 db->nextPagesize = 0;
155241 if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0)
155242 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
155250 sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
155261 " AND coalesce(rootpage,1)>0",
155271 db->init.iDb = 0;
155281 "WHERE type='table'AND coalesce(rootpage,1)>0",
155284 assert( (db->mDbFlags & DBFLAG_Vacuum)!=0 );
155297 " OR(type='table'AND rootpage=0)",
155320 BTREE_DEFAULT_CACHE_SIZE, 0, /* Preserve the default page cache size */
155321 BTREE_TEXT_ENCODING, 0, /* Preserve the text encoding */
155322 BTREE_USER_VERSION, 0, /* Preserve the user version */
155323 BTREE_APPLICATION_ID, 0, /* Preserve the application id */
155327 assert( pOut!=0 || SQLITE_TXN_WRITE==sqlite3BtreeTxnState(pMain) );
155330 for(i=0; i<ArraySize(aCopy); i+=2){
155338 if( pOut==0 ){
155345 if( pOut==0 ){
155352 if( pOut==0 ){
155359 db->init.iDb = 0;
155365 sqlite3BtreeSetPageSize(pMain, -1, 0, 1);
155378 pDb->pBt = 0;
155379 pDb->pSchema = 0;
155429 ** If pModule==0, then delete the module zName if it exists.
155441 if( pModule==0 ){
155443 pMod = 0;
155447 if( pMod==0 ){
155449 return 0;
155457 pMod->pEpoTab = 0;
155465 pMod = 0;
155507 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
155509 return createModule(db, zName, pModule, pAux, 0);
155523 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
155542 for(ii=0; azNames[ii]!=0 && strcmp(azNames[ii],pMod->zName)!=0; ii++){}
155543 if( azNames[ii]!=0 ) continue;
155545 createModule(db, pMod->zName, 0, 0, 0);
155555 assert( pMod->nRefModule>0 );
155557 if( pMod->nRefModule==0 ){
155561 assert( pMod->pEpoTab==0 );
155599 assert( pVTab->nRef>0 );
155604 if( pVTab->nRef==0 ){
155622 VTable *pRet = 0;
155627 p->u.vtab.p = 0;
155635 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
155644 pRet->pNext = 0;
155709 db->pDisconnect = 0;
155734 assert( db!=0 );
155735 if( db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
155738 for(i=0; i<p->u.vtab.nArg; i++){
155762 if( azModuleArg==0 ){
155767 azModuleArg[i+1] = 0;
155787 sqlite3StartTable(pParse, pName1, pName2, 0, 0, 1, ifNotExists);
155789 if( pTable==0 ) return;
155790 assert( 0==pTable->pIndex );
155795 assert( pTable->u.vtab.nArg==0 );
155797 addModuleArgument(pParse, pTable, 0);
155799 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
155800 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
155814 assert( iDb>=0 ); /* The database the table is being created in */
155816 pTable->u.vtab.azArg[0], pParse->db->aDb[iDb].zDbSName);
155843 if( pTab==0 ) return;
155846 pParse->sArg.z = 0;
155881 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
155894 sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere, 0);
155906 assert( zName!=0 );
155914 pParse->pNewTable = 0;
155924 pParse->sArg.z = 0;
155925 pParse->sArg.n = 0;
155934 if( pArg->z==0 ){
155960 char *zErr = 0;
156002 sCtx.bDeclared = 0;
156006 assert( pTab!=0 );
156014 if( zErr==0 ){
156024 memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
156028 if( sCtx.bDeclared==0 ){
156035 u16 oooHidden = 0;
156044 for(iCol=0; iCol<pTab->nCol; iCol++){
156047 int i = 0;
156049 for(i=0; i<nType; i++){
156050 if( 0==sqlite3StrNICmp("hidden", &zType[i], 6)
156051 && (i==0 || zType[i-1]==' ')
156052 && (zType[i+6]=='\0' || zType[i+6]==' ')
156059 int nDel = 6 + (zType[i+6] ? 1 : 0);
156063 if( zType[i]=='\0' && i>0 ){
156065 zType[i-1] = '\0';
156101 zMod = pTab->u.vtab.azArg[0];
156105 const char *zModule = pTab->u.vtab.azArg[0];
156109 char *zErr = 0;
156128 if( (db->nVTrans%ARRAY_INCR)==0 ){
156136 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
156171 zMod = pTab->u.vtab.azArg[0];
156178 if( pMod==0 || pMod->pModule->xCreate==0 || pMod->pModule->xDestroy==0 ){
156210 static const u8 aKeyword[] = { TK_CREATE, TK_TABLE, 0 };
156213 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
156223 for(i=0; aKeyword[i]; i++){
156224 int tokenType = 0;
156249 assert( db->init.busy==0 );
156251 db->init.busy = 0;
156254 assert( sParse.pNewTable!=0 );
156257 assert( sParse.zErrMsg==0 );
156265 pNew->nCol = 0;
156266 pNew->aCol = 0;
156267 assert( pTab->pIndex==0 );
156268 assert( HasRowid(pNew) || sqlite3PrimaryKeyIndex(pNew)!=0 );
156270 && pCtx->pVTable->pMod->pModule->xUpdate!=0
156273 /* WITHOUT ROWID virtual tables must either be read-only (xUpdate==0)
156279 assert( pIdx->pNext==0 );
156281 pNew->pIndex = 0;
156288 (sParse.zErrMsg ? "%s" : 0), sParse.zErrMsg);
156301 assert( (rc&0xff)==rc );
156319 if( ALWAYS(pTab!=0)
156321 && ALWAYS(pTab->u.vtab.p!=0)
156327 if( p->pVtab->nRef>0 ){
156333 if( xDestroy==0 ) xDestroy = p->pMod->pModule->xDisconnect;
156334 assert( xDestroy!=0 );
156339 assert( pTab->u.vtab.p==p && p->pNext==0 );
156340 p->pVtab = 0;
156341 pTab->u.vtab.p = 0;
156362 db->aVTrans = 0;
156363 for(i=0; i<db->nVTrans; i++){
156371 pVTab->iSavepoint = 0;
156375 db->nVTrans = 0;
156391 db->aVTrans = 0;
156392 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
156395 if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
156451 for(i=0; i<db->nVTrans; i++){
156497 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
156550 void (*xSFunc)(sqlite3_context*,int,sqlite3_value**) = 0;
156551 void *pArg = 0;
156553 int rc = 0;
156556 if( NEVER(pExpr==0) ) return pDef;
156560 if( NEVER(pTab==0) ) return pDef;
156563 assert( pVtab!=0 );
156564 assert( pVtab->pModule!=0 );
156566 if( pMod->xFindFunction==0 ) return pDef;
156578 for(i=0; pDef->zName[i]; i++){
156585 if( rc==0 ){
156593 if( pNew==0 ){
156617 for(i=0; i<pToplevel->nVtabLock; i++){
156620 n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
156648 char *zErr = 0;
156652 if( pModule->xCreate!=0 && pModule->xCreate!=pModule->xConnect ) return 0;
156654 if( pTab==0 ) return 0;
156656 if( pTab->zName==0 ){
156658 return 0;
156663 pTab->pSchema = db->aDb[0].pSchema;
156664 assert( pTab->u.vtab.nArg==0 );
156668 addModuleArgument(pParse, pTab, 0);
156685 if( pTab!=0 ){
156691 pMod->pEpoTab = 0;
156733 assert( p->pTab==0 || IsVirtual(p->pTab) );
156860 ** the loop nested order, with WhereInfo.a[0] being the outer loop and
156925 u8 iSortIdx; /* Sorting index number. 0==None */
157037 ** categories, then eOperator==0. The WhereTerm.pExpr field is still set
157041 ** When eOperator!=0, prereqRight and prereqAll record sets of cursor numbers,
157049 ** beginning with 0 in order to make the best possible use of the available
157051 ** would be mapped into integers 0 through 7.
157072 WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */
157073 WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */
157082 #define TERM_DYNAMIC 0x0001 /* Need to call sqlite3ExprDelete(db, pExpr) */
157083 #define TERM_VIRTUAL 0x0002 /* Added by the optimizer. Do not code */
157084 #define TERM_CODED 0x0004 /* This term is already coded */
157085 #define TERM_COPIED 0x0008 /* Has a child */
157086 #define TERM_ORINFO 0x0010 /* Need to free the WhereTerm.u.pOrInfo object */
157087 #define TERM_ANDINFO 0x0020 /* Need to free the WhereTerm.u.pAndInfo obj */
157088 #define TERM_OK 0x0040 /* Used during OR-clause processing */
157089 #define TERM_VNULL 0x0080 /* Manufactured x>NULL or x<=NULL term */
157090 #define TERM_LIKEOPT 0x0100 /* Virtual terms from the LIKE optimization */
157091 #define TERM_LIKECOND 0x0200 /* Conditionally this LIKE operator term */
157092 #define TERM_LIKE 0x0400 /* The original LIKE operator */
157093 #define TERM_IS 0x0800 /* Term.pExpr is an IS operator */
157094 #define TERM_VARSELECT 0x1000 /* Term.pExpr contains a correlated sub-query */
157095 #define TERM_HEURTRUTH 0x2000 /* Heuristic truthProb used */
157097 # define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */
157099 # define TERM_HIGHTRUTH 0 /* Only used with STAT4 */
157101 #define TERM_SLICE 0x8000 /* One slice of a row-value/vector comparison */
157172 ** clause, the cursor numbers might not begin with 0 and they might
157176 ** with 0.
157183 ** would map those cursor numbers into bits 0 through 5.
157186 ** above, the mapping might go like this: 4->3, 5->1, 8->2, 29->0,
157189 ** numbers all get mapped into bit numbers that begin with 0 and contain
157217 #define SQLITE_BLDF1_INDEXED 0x0001 /* An index is used */
157218 #define SQLITE_BLDF1_UNIQUE 0x0002 /* All keys of a UNIQUE index used */
157220 #define SQLITE_BLDF2_2NDPASS 0x0004 /* Second builder pass needed */
157322 # define sqlite3WhereExplainOneScan(u,v,w,x) 0
157323 # define sqlite3WhereExplainBloomFilter(u,v,w) 0
157330 int addrExplain /* Address of OP_Explain (or 0) */
157377 #define WO_IN 0x0001
157378 #define WO_EQ 0x0002
157383 #define WO_AUX 0x0040 /* Op useful to virtual tables only */
157384 #define WO_IS 0x0080
157385 #define WO_ISNULL 0x0100
157386 #define WO_OR 0x0200 /* Two or more OR-connected terms */
157387 #define WO_AND 0x0400 /* Two or more AND-connected terms */
157388 #define WO_EQUIV 0x0800 /* Of the form A==B, both columns */
157389 #define WO_NOOP 0x1000 /* This term does not restrict search space */
157390 #define WO_ROWVAL 0x2000 /* A row-value term */
157392 #define WO_ALL 0x3fff /* Mask of all possible WO_* values */
157393 #define WO_SINGLE 0x01ff /* Mask of all non-compound WO_* values */
157400 #define WHERE_COLUMN_EQ 0x00000001 /* x=EXPR */
157401 #define WHERE_COLUMN_RANGE 0x00000002 /* x<EXPR and/or x>EXPR */
157402 #define WHERE_COLUMN_IN 0x00000004 /* x IN (...) */
157403 #define WHERE_COLUMN_NULL 0x00000008 /* x IS NULL */
157404 #define WHERE_CONSTRAINT 0x0000000f /* Any of the WHERE_COLUMN_xxx values */
157405 #define WHERE_TOP_LIMIT 0x00000010 /* x<EXPR or x<=EXPR constraint */
157406 #define WHERE_BTM_LIMIT 0x00000020 /* x>EXPR or x>=EXPR constraint */
157407 #define WHERE_BOTH_LIMIT 0x00000030 /* Both x>EXPR and x<EXPR */
157408 #define WHERE_IDX_ONLY 0x00000040 /* Use index only - omit table */
157409 #define WHERE_IPK 0x00000100 /* x is the INTEGER PRIMARY KEY */
157410 #define WHERE_INDEXED 0x00000200 /* WhereLoop.u.btree.pIndex is valid */
157411 #define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
157412 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
157413 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
157414 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
157415 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
157416 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
157417 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
157418 #define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */
157419 #define WHERE_IN_EARLYOUT 0x00040000 /* Perhaps quit IN loops early */
157420 #define WHERE_BIGNULL_SORT 0x00080000 /* Column nEq of index is BIGNULL */
157421 #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
157422 #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
157423 #define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */
157424 #define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */
157425 #define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */
157426 /* 0x02000000 -- available for reuse */
157427 #define WHERE_EXPRIDX 0x04000000 /* Uses an index-on-expressions */
157468 for(i=0; i<nTerm; i++){
157477 for(i=0; i<nTerm; i++){
157504 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
157506 for(i=0; i<nEq; i++){
157538 int ret = 0;
157555 if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_OR_SUBCLAUSE) ) return 0;
157557 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
157558 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
157564 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
157565 const char *zFmt = 0;
157568 assert( pLoop->u.btree.pIndex!=0 );
157589 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
157591 #if 0 /* Better output, but breaks many tests */
157593 const char *zRowid = pTab->iPKey>=0 ? pTab->aCol[pTab->iPKey].zCnName:
157613 else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
157632 pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
157652 int ret = 0;
157668 if( pTab->iPKey>=0 ){
157683 pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
157685 sqlite3VdbeScanStatus(v, sqlite3VdbeCurrentAddr(v)-1, 0, 0, 0, 0);
157697 ** If argument addrExplain is not 0, it must be the address of an
157704 int addrExplain /* Address of OP_Explain (or 0) */
157707 const char *zObj = 0;
157710 int viaCoroutine = 0;
157712 if( (wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){
157722 if( viaCoroutine==0 ){
157723 if( (wsFlags & (WHERE_MULTI_OR|WHERE_AUTO_INDEX))==0 ){
157784 int nLoop = 0;
157785 assert( pTerm!=0 );
157786 while( (pTerm->wtFlags & TERM_CODED)==0
157787 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_OuterON))
157788 && (pLevel->notReady & pTerm->prereqAll)==0
157790 if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
157796 if( (sqlite3WhereTrace & 0x4001)==0x4001 ){
157801 if( pTerm->iParent<0 ) break;
157803 assert( pTerm!=0 );
157805 if( pTerm->nChild!=0 ) break;
157823 if( zAff==0 ){
157827 assert( v!=0 );
157833 while( n>0 && zAff[0]<=SQLITE_AFF_BLOB ){
157843 if( n>0 ){
157844 sqlite3VdbeAddOp4(v, OP_Affinity, base, n, 0, zAff, n);
157864 for(i=0; i<n; i++){
157913 pNew = sqlite3ExprDup(db, pX, 0);
157914 if( db->mallocFailed==0 ){
157917 ExprList *pOrigLhs = 0; /* Original unmodified LHS */
157918 ExprList *pRhs = 0; /* New RHS after modifications */
157919 ExprList *pLhs = 0; /* New LHS after mods */
157924 assert( pNew->pLeft!=0 );
157932 assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 );
157934 if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */
157936 pOrigRhs->a[iField].pExpr = 0;
157938 assert( pOrigLhs->a[iField].pExpr!=0 );
157940 pOrigLhs->a[iField].pExpr = 0;
157954 Expr *p = pLhs->a[0].pExpr;
157955 pLhs->a[0].pExpr = 0;
157968 for(i=0; i<pOrderBy->nExpr; i++){
157969 pOrderBy->a[i].u.x.iOrderByCol = 0;
157973 #if 0
157975 sqlite3TreeViewExpr(0, pX, 0);
157977 sqlite3TreeViewExpr(0, pNew, 0);
158013 assert( iTarget>0 );
158018 sqlite3VdbeAddOp2(v, OP_Null, 0, iReg);
158026 int nEq = 0;
158027 int *aiMap = 0;
158029 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0
158030 && pLoop->u.btree.pIndex!=0
158033 testcase( iEq==0 );
158040 for(i=0; i<iEq; i++){
158047 assert( pLoop->aLTerm[i]!=0 );
158051 iTab = 0;
158053 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
158056 if( pExpr->iTable==0 || !ExprHasProperty(pExpr, EP_Subrtn) ){
158061 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab);
158068 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
158077 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
158081 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
158083 if( pLevel->u.in.nIn==0 ){
158086 if( iEq>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0 ){
158095 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
158098 int iMap = 0; /* Index in aiMap[] */
158106 int iCol = aiMap ? aiMap[iMap++] : 0;
158113 if( iEq>0 ){
158117 pIn->nPrefix = 0;
158125 testcase( iEq>0
158126 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0
158127 && (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 );
158128 if( iEq>0
158129 && (pLoop->wsFlags & (WHERE_IN_SEEKSCAN|WHERE_VIRTUALTABLE))==0
158131 sqlite3VdbeAddOp3(v, OP_SeekHit, pLevel->iIdxCur, 0, iEq);
158134 pLevel->u.in.nIn = 0;
158149 if( (pLevel->pWLoop->wsFlags & WHERE_TRANSCONS)==0
158150 || (pTerm->eOperator & WO_EQUIV)==0
158171 ** of nEq including 0. If nEq==0, this routine is nearly a no-op.
158175 ** The nExtraReg parameter is 0 or 1. It is 0 if all WHERE clause constraints
158223 assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
158227 assert( pIdx!=0 );
158236 assert( zAff!=0 || pParse->db->mallocFailed );
158240 sqlite3VdbeAddOp3(v, OP_Null, 0, regBase, regBase+nSkip-1);
158242 VdbeCoverageIf(v, bRev==0);
158243 VdbeCoverageIf(v, bRev!=0);
158246 assert( pLevel->addrSkip==0 );
158248 iIdxCur, 0, regBase, nSkip);
158249 VdbeCoverageIf(v, bRev==0);
158250 VdbeCoverageIf(v, bRev!=0);
158252 for(j=0; j<nSkip; j++){
158261 assert( zAff==0 || (int)strlen(zAff)>=nEq );
158265 assert( pTerm!=0 );
158267 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
158268 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
158287 }else if( (pTerm->eOperator & WO_ISNULL)==0 ){
158289 if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
158293 if( pParse->nErr==0 ){
158294 assert( pParse->db->mallocFailed==0 );
158333 assert( pLevel->iLikeRepCntr>0 );
158335 assert( pOp!=0 );
158354 int iIdxCur; /* Cursor for the index, if pIdx!=0. Unused otherwise */
158366 assert( pHint->pIdx!=0 );
158369 && sqlite3TableColumnToIndex(pHint->pIdx, pExpr->iColumn)<0
158389 ** CASE WHEN col THEN 0 ELSE 1 END
158400 if( 0==sqlite3IsLikeFunction(pWalker->pParse->db, pExpr, &d1, d2) ){
158423 ** know because CCurHint.pIdx!=0) then transform the TK_COLUMN into
158436 }else if( pHint->pIdx!=0 ){
158439 assert( pExpr->iColumn>=0 );
158466 Expr *pExpr = 0;
158481 memset(&sWalker, 0, sizeof(sWalker));
158485 for(i=0; i<pWC->nBase; i++){
158517 sWalker.eCode = 0;
158529 if( pLoop->u.btree.nEq==0 && pTerm!=pEndRange ){
158530 for(j=0; j<pLoop->nLTerm && pLoop->aLTerm[j]!=pTerm; j++){}
158539 if( sHint.pIdx!=0 ){
158540 sWalker.eCode = 0;
158547 pExpr = sqlite3ExprAnd(pParse, pExpr, sqlite3ExprDup(db, pTerm->pExpr, 0));
158549 if( pExpr!=0 ){
158551 if( pParse->nErr==0 ) sqlite3WalkExpr(&sWalker, pExpr);
158553 (sHint.pIdx ? sHint.iIdxCur : sHint.iTabCur), 0, 0,
158582 ** to 0. The OP_Column opcode can check this array to see if the column it
158596 assert( iIdxCur>0 );
158600 sqlite3VdbeAddOp3(v, OP_DeferredSeek, iIdxCur, 0, iCur);
158608 ai[0] = pTab->nCol;
158609 for(i=0; i<pIdx->nColumn-1; i++){
158615 if( x1>=0 ) ai[x2+1] = i+1;
158632 assert( nReg>0 );
158649 for(i=0; i<nReg; i++){
158677 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
158681 if( sqlite3ExprCompare(0, pExpr, pTruth, iTabCur)==0 ){
158712 if( pLevel->regFilter==0 ) continue;
158717 assert( pLevel->addrBrk==0 );
158720 WhereTerm *pTerm = pLoop->aLTerm[0];
158722 assert( pTerm!=0 );
158723 assert( pTerm->pExpr!=0 );
158726 regRowid = codeEqualityTerm(pParse, pTerm, pLevel, 0, 0, regRowid);
158738 assert( (pLoop->wsFlags & WHERE_COLUMN_IN)==0 );
158739 r1 = codeAllEqualityTerms(pParse,pLevel,0,0,&zStartAff);
158746 pLevel->regFilter = 0;
158747 pLevel->addrBrk = 0;
158758 && pLoop->nSkip==0
158762 for(ii=0; ii<pLoop->u.btree.nEq; ii++){
158764 return 0;
158769 return 0;
158796 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
158797 int iReleaseReg = 0; /* Temp register to free before returning */
158798 Index *pIdx = 0; /* Index used by loop (if any) */
158809 #if WHERETRACE_ENABLED /* 0x4001 */
158810 if( sqlite3WhereTrace & 0x1 ){
158813 if( sqlite3WhereTrace & 0x1000 ){
158817 if( (sqlite3WhereTrace & 0x4001)==0x4001 ){
158818 if( iLevel==0 ){
158820 sqlite3TreeViewExpr(0, pWInfo->pWhere, 0);
158845 || pLevel->iFrom>0 || (pTabItem[0].fg.jointype & JT_LEFT)==0
158847 if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
158849 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
158855 for(j=iLevel; j>0; j--){
158864 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
158872 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
158882 for(j=0; j<nConstraint; j++){
158885 if( NEVER(pTerm==0) ) continue;
158903 assert( pWInfo->pSelect!=0 );
158904 assert( pWInfo->pSelect->iOffset>0 );
158905 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWInfo->pSelect->iOffset);
158916 pLoop->u.vtab.needFree = 0;
158919 if( db->mallocFailed ) pLoop->u.vtab.idxStr = 0;
158923 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
158925 for(j=0; j<nConstraint; j++){
158931 if( (pTerm->eOperator & WO_IN)!=0
158932 && (SMASKBIT32(j) & pLoop->u.vtab.mHandleIn)==0
158945 for(iIn=0; ALWAYS(iIn<pLevel->u.in.nIn); iIn++){
158959 pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0);
158963 assert( pLeft!=0 );
158964 if( iFld>0 ){
158972 pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0);
158979 pCompare->pLeft = 0;
158987 ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems
158995 if( (pLoop->wsFlags & WHERE_IPK)!=0
158996 && (pLoop->wsFlags & (WHERE_COLUMN_IN|WHERE_COLUMN_EQ))!=0
159004 pTerm = pLoop->aLTerm[0];
159005 assert( pTerm!=0 );
159006 assert( pTerm->pExpr!=0 );
159009 iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
159023 }else if( (pLoop->wsFlags & WHERE_IPK)!=0
159024 && (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0
159030 int memEndValue = 0;
159033 j = 0;
159034 pStart = pEnd = 0;
159037 assert( pStart!=0 || pEnd!=0 );
159062 assert( (pStart->wtFlags & TERM_VNULL)==0 );
159065 assert( pX!=0 );
159074 op = aMoveOp[((pX->op - TK_GT - 1) & 0x3) | 0x1];
159093 VdbeCoverageIf(v, bRev==0);
159094 VdbeCoverageIf(v, bRev!=0);
159099 assert( pX!=0 );
159100 assert( (pEnd->wtFlags & TERM_VNULL)==0 );
159105 if( 0==sqlite3ExprIsVector(pX->pRight)
159112 if( 0==sqlite3ExprIsVector(pX->pRight) ){
159120 assert( pLevel->p5==0 );
159164 0,
159165 0,
159174 OP_IdxGE, /* 0: (end_constraints && !bRev && !endEq) */
159183 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
159184 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
159190 int nExtraReg = 0; /* Number of extra registers needed */
159193 char *zEndAff = 0; /* Affinity for end of range constraint */
159194 u8 bSeekPastNull = 0; /* True to seek past initial nulls */
159195 u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
159197 int regBignull = 0; /* big-null flag register */
159198 int addrSeekScan = 0; /* Opcode of the OP_SeekScan, if any */
159212 assert( (pRangeStart->wtFlags & TERM_LIKEOPT)==0 ||
159213 (pLoop->wsFlags & WHERE_TOP_LIMIT)!=0 );
159219 if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
159220 assert( pRangeStart!=0 ); /* LIKE opt constraints */
159230 assert( (bRev & ~1)==0 );
159235 if( pRangeStart==0 ){
159237 if( (j>=0 && pIdx->pTable->aCol[j].notNull==0) || j==XN_EXPR ){
159242 assert( pRangeEnd==0 || (pRangeEnd->wtFlags & TERM_VNULL)==0 );
159251 if( (pLoop->wsFlags & (WHERE_TOP_LIMIT|WHERE_BTM_LIMIT))==0
159252 && (pLoop->wsFlags & WHERE_BIGNULL_SORT)!=0
159254 assert( bSeekPastNull==0 && nExtraReg==0 && nBtm==0 && nTop==0 );
159255 assert( pRangeEnd==0 && pRangeStart==0 );
159256 testcase( pLoop->nSkip>0 );
159261 sqlite3VdbeAddOp2(v, OP_Integer, 0, regBignull);
159276 if( iLevel>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)!=0 ){
159288 assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
159294 testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
159295 testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
159296 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
159297 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_GE)!=0 );
159300 start_constraints = pRangeStart || nEq>0;
159308 if( (pRangeStart->wtFlags & TERM_VNULL)==0
159319 if( sqlite3ExprIsVector(pRight)==0 ){
159324 bSeekPastNull = 0;
159326 startEq = 0;
159327 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
159331 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
159336 if( pLoop->nSkip>0 && nConstraint==pLoop->nSkip ){
159353 assert( op!=0 );
159354 if( (pLoop->wsFlags & WHERE_IN_SEEKSCAN)!=0 && op==OP_SeekGE ){
159355 assert( regBignull==0 );
159365 (pIdx->aiRowLogEst[0]+9)/10);
159369 addrSeekScan = 0;
159382 assert( bSeekPastNull==0 || bStopAtNull==0 );
159387 sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
159404 assert( pLevel->p2==0 );
159407 assert( addrSeekScan==0 );
159410 if( (pRangeEnd->wtFlags & TERM_VNULL)==0
159425 if( sqlite3ExprIsVector(pRight)==0 ){
159431 if( regBignull==0 ){
159432 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
159433 endEq = 0;
159464 assert( nConstraint+bSeekPastNull>0 );
159477 if( (pLoop->wsFlags & WHERE_IN_EARLYOUT)!=0 ){
159482 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
159483 && (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))==0;
159491 for(j=0; j<pPk->nKeyCol; j++){
159499 if( pLevel->iLeftJoin==0 ){
159515 assert( (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))==0 );
159520 || (pLevel->u.in.nIn && regBignull==0 && whereLoopIsOneRow(pLoop))
159529 pLevel->p3 = (pLoop->wsFlags&WHERE_UNQ_WANTED)!=0 ? 1:0;
159530 if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
159533 assert( pLevel->p5==0 );
159535 if( omitTable ) pIdx = 0;
159585 Index *pCov = 0; /* Potential covering index (or NULL) */
159589 int regRowset = 0; /* Register for RowSet object */
159590 int regRowid = 0; /* Register holding rowid */
159593 int untestedTerms = 0; /* Some terms not completely tested */
159595 Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
159598 pTerm = pLoop->aLTerm[0];
159599 assert( pTerm!=0 );
159601 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
159607 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
159615 sizeof(*pOrTab)+ nNotReady*sizeof(pOrTab->a[0]));
159616 if( pOrTab==0 ) return notReady;
159640 if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
159643 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowset);
159652 iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
159684 for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
159690 if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){
159693 if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
159695 pExpr = sqlite3ExprDup(db, pExpr, 0);
159699 /* The extra 0x10000 bit on the opcode is masked off and does not
159704 pAndExpr = sqlite3PExpr(pParse, TK_AND|0x10000, 0, pAndExpr);
159713 for(ii=0; ii<pOrWc->nTerm; ii++){
159715 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
159719 int jmp1 = 0; /* Address of jump operation */
159720 testcase( (pTabItem[0].fg.jointype & JT_LEFT)!=0
159723 pDelete = pOrExpr = sqlite3ExprDup(db, pOrExpr, 0);
159734 WHERETRACE(0xffffffff, ("Subplan for OR-clause:\n"));
159735 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, 0,
159741 pParse, pOrTab, &pSubWInfo->a[0], 0
159743 sqlite3WhereAddScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain);
159750 if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
159754 jmp1 = sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset, 0,
159765 for(iPk=0; iPk<nPk; iPk++){
159782 jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, regRowset, 0, r, nPk);
159785 if( iSet>=0 ){
159823 pSubLoop = pSubWInfo->a[0].pWLoop;
159824 assert( (pSubLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
159825 if( (pSubLoop->wsFlags & WHERE_INDEXED)!=0
159826 && (ii==0 || pSubLoop->u.btree.pIndex==pCov)
159829 assert( pSubWInfo->a[0].iIdxCur==iCovCur );
159832 pCov = 0;
159847 assert( (pLoop->wsFlags & WHERE_MULTI_OR)!=0 );
159848 assert( (pLoop->wsFlags & WHERE_IN_ABLE)==0 );
159852 pAndExpr->pLeft = 0;
159878 assert( bRev==0 || bRev==1 );
159884 codeCursorHint(pTabItem, pWInfo, pLevel, 0);
159888 VdbeCoverageIf(v, bRev==0);
159889 VdbeCoverageIf(v, bRev!=0);
159920 int iNext = 0; /* Next value for iLoop */
159921 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
159923 int skipLikeAddr = 0;
159927 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
159928 testcase( pWInfo->untestedTerms==0
159929 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
159934 assert( pE!=0 );
159956 if( iNext==0 ) iNext = 3;
159960 if( (pTerm->wtFlags & TERM_LIKECOND)!=0 ){
159970 if( x>0 ){
159973 VdbeCoverageIf(v, (x&1)==0);
159977 #ifdef WHERETRACE_ENABLED /* 0xffffffff */
159982 if( sqlite3WhereTrace & 0x4000 ){
159992 }while( iLoop>0 );
160002 for(pTerm=pWC->a, j=pWC->nBase; j>0; j--, pTerm++){
160006 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue;
160007 if( (pTerm->eOperator & WO_EQUIV)==0 ) continue;
160011 #ifdef WHERETRACE_ENABLED /* 0x4001 */
160012 if( (sqlite3WhereTrace & 0x4001)==0x4001 ){
160018 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
160019 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
160021 WO_EQ|WO_IN|WO_IS, 0);
160022 if( pAlt==0 ) continue;
160047 int jmp1 = 0;
160065 for(iPk=0; iPk<nPk; iPk++){
160070 jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, 0, r+1, nPk);
160075 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pRJ->regBloom, 0, r+1, nPk);
160088 if( pLevel->pRJ==0 ){
160101 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pRJ->regReturn);
160112 for(pTerm=pWC->a, j=0; j<pWC->nBase; j++, pTerm++){
160116 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
160127 #if WHERETRACE_ENABLED /* 0x4001 */
160128 if( sqlite3WhereTrace & 0x4000 ){
160133 if( sqlite3WhereTrace & 0x1 ){
160153 Expr *pSubWhere = 0;
160159 Bitmask mAll = 0;
160165 for(k=0; k<iLevel; k++){
160173 v, OP_Null, 0, pRight->regResult,
160183 if( (pTabItem->fg.jointype & JT_LTORJ)==0 ){
160185 for(k=0; k<pWC->nTerm; k++){
160187 if( (pTerm->wtFlags & (TERM_VIRTUAL|TERM_SLICE))!=0
160195 sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
160200 memcpy(&sFrom.a[0], pTabItem, sizeof(SrcItem));
160201 sFrom.a[0].fg.jointype = 0;
160204 pSubWInfo = sqlite3WhereBegin(pParse, &sFrom, pSubWhere, 0, 0, 0,
160205 WHERE_RIGHT_JOIN, 0);
160221 for(iPk=0; iPk<nPk; iPk++){
160226 jmp = sqlite3VdbeAddOp4Int(v, OP_Filter, pRJ->regBloom, 0, r, nPk);
160236 assert( pParse->withinRJSubrtn>0 );
160286 ** 0 is returned if the new WhereTerm could not be added due to a memory
160308 pWC->a = sqlite3WhereMalloc(pWC->pWInfo, sizeof(pWC->a[0])*pWC->nSlot*2 );
160309 if( pWC->a==0 ){
160314 return 0;
160316 memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm);
160320 if( (wtFlags & TERM_VIRTUAL)==0 ) pWC->nBase = pWC->nTerm;
160330 memset(&pTerm->eOperator, 0,
160369 return 0;
160385 assert( (WO_EQ<<(op-TK_EQ)) < 0x7fff );
160420 const u8 *z = 0; /* String on RHS of LIKE operator */
160427 sqlite3_value *pVal = 0;
160432 return 0;
160435 if( *pnoCase ) return 0;
160441 pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
160443 if( op==TK_VARIABLE && (db->flags & SQLITE_EnableQPSG)==0 ){
160459 cnt = 0;
160460 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
160462 if( c==wc[3] && z[cnt]!=0 ) cnt++;
160467 ** an (illegal 0xff) character, or (3) the pattern does not consist of
160473 if( (cnt>1 || (cnt>0 && z[0]!=wc[3])) && 255!=(u8)z[cnt-1] ){
160477 *pisComplete = c==wc[0] && z[cnt+1]==0;
160486 zNew[cnt] = 0;
160487 for(iFrom=iTo=0; iFrom<cnt; iFrom++){
160491 zNew[iTo] = 0;
160492 assert( iTo>0 );
160505 ** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
160516 if( isNum<=0 ){
160517 if( iTo==1 && zNew[0]=='-' ){
160525 if( isNum>0 ){
160528 return 0;
160549 sqlite3VdbeChangeP3(v, sqlite3VdbeCurrentAddr(v)-1, 0);
160554 z = 0;
160558 rc = (z!=0);
160590 ** If the expression matches none of the patterns above, return 0.
160595 unsigned char *peOp2, /* OUT: 0 for MATCH, or else an op2 value */
160615 if( pList==0 || pList->nExpr!=2 ){
160616 return 0;
160627 assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) );
160629 for(i=0; i<ArraySize(aOp); i++){
160631 if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
160633 *ppRight = pList->a[0].pExpr;
160650 pCol = pList->a[0].pExpr;
160652 assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) );
160659 assert( pVtab!=0 );
160660 assert( pVtab->pModule!=0 );
160663 if( pMod->xFindFunction!=0 ){
160674 int res = 0;
160677 assert( pLeft->op!=TK_COLUMN || (ExprUseYTab(pLeft) && pLeft->y.pTab!=0) );
160681 assert( pRight==0 || pRight->op!=TK_COLUMN
160682 || (ExprUseYTab(pRight) && pRight->y.pTab!=0) );
160694 return 0;
160720 ** a conjunction, then return just pTerm when N==0. If N is exceeds
160725 return N==0 ? pTerm : 0;
160730 return 0;
160766 if( (pOne->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
160767 if( (pTwo->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
160770 assert( pOne->pExpr->pLeft!=0 && pOne->pExpr->pRight!=0 );
160771 assert( pTwo->pExpr->pLeft!=0 && pTwo->pExpr->pRight!=0 );
160772 if( sqlite3ExprCompare(0,pOne->pExpr->pLeft, pTwo->pExpr->pLeft, -1) ) return;
160773 if( sqlite3ExprCompare(0,pOne->pExpr->pRight, pTwo->pExpr->pRight,-1) )return;
160775 if( (eOp & (eOp-1))!=0 ){
160784 pNew = sqlite3ExprDup(db, pOne->pExpr, 0);
160785 if( pNew==0 ) return;
160902 assert( (pTerm->wtFlags & (TERM_DYNAMIC|TERM_ORINFO|TERM_ANDINFO))==0 );
160905 if( pOrInfo==0 ) return;
160908 memset(pOrWc->aStatic, 0, sizeof(pOrWc->aStatic));
160918 indexable = ~(Bitmask)0;
160919 chngToIN = ~(Bitmask)0;
160920 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0 && indexable; i--, pOrTerm++){
160921 if( (pOrTerm->eOperator & WO_SINGLE)==0 ){
160923 assert( (pOrTerm->wtFlags & (TERM_ANDINFO|TERM_ORINFO))==0 );
160924 chngToIN = 0;
160930 Bitmask b = 0;
160936 memset(pAndWC->aStatic, 0, sizeof(pAndWC->aStatic));
160942 for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){
160964 if( (pOrTerm->eOperator & WO_EQ)==0 ){
160965 chngToIN = 0;
160986 int iOne = 0;
160988 while( (pOne = whereNthSubterm(&pOrWc->a[0],iOne++))!=0 ){
160989 int iTwo = 0;
160991 while( (pTwo = whereNthSubterm(&pOrWc->a[1],iTwo++))!=0 ){
161002 ** chngToIN will hold either 0, 1, or 2 bits. The 0-bit case means
161019 int okToChngToIN = 0; /* True if the conversion to IN is valid */
161022 int j = 0; /* Loop counter */
161030 for(j=0; j<2 && !okToChngToIN; j++){
161031 Expr *pLeft = 0;
161033 for(i=pOrWc->nTerm-1; i>=0; i--, pOrTerm++){
161043 pOrTerm->leftCursor))==0 ){
161053 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
161059 if( i<0 ){
161072 for(; i>=0 && okToChngToIN; i--, pOrTerm++){
161074 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
161080 okToChngToIN = 0;
161089 if( affRight!=0 && affRight!=affLeft ){
161090 okToChngToIN = 0;
161104 ExprList *pList = 0; /* The RHS of the IN operator */
161105 Expr *pLeft = 0; /* The LHS of the IN operator */
161108 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
161109 if( (pOrTerm->wtFlags & TERM_OK)==0 ) continue;
161111 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
161114 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
161118 assert( pLeft!=0 );
161119 pDup = sqlite3ExprDup(db, pLeft, 0);
161120 pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
161127 testcase( idxNew==0 );
161151 ** This is an optimization. No harm comes from returning 0. But if 1 is
161157 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0;
161158 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0;
161159 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0;
161165 return 0;
161178 Bitmask mask = 0;
161186 if( ALWAYS(pSrc!=0) ){
161188 for(i=0; i<pSrc->nSrc; i++){
161190 if( pSrc->a[i].fg.isUsing==0 ){
161207 ** FALSE (0) if not. If TRUE is returned, also set aiCurCol[0] to the cursor
161228 if( pIdx->aColExpr==0 ) continue;
161229 for(i=0; i<pIdx->nKeyCol; i++){
161232 if( sqlite3ExprCompareSkip(pExpr,pIdx->aColExpr->a[i].pExpr,iCur)==0
161233 && !sqlite3ExprIsConstant(0,pIdx->aColExpr->a[i].pExpr)
161235 aiCurCol[0] = iCur;
161242 return 0;
161260 pExpr = pExpr->x.pList->a[0].pExpr;
161264 aiCurCol[0] = pExpr->iTable;
161269 for(i=0; i<pFrom->nSrc; i++){
161277 return 0;
161310 Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */
161311 Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */
161312 int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */
161313 int noCase = 0; /* uppercase equivalent to lowercase */
161317 unsigned char eOp2 = 0; /* op2 value for LIKE/REGEXP/GLOB */
161327 assert( pExpr!=0 ); /* Because malloc() has not failed */
161329 pMaskSet->bVarSelect = 0;
161333 assert( pExpr->pRight==0 );
161343 if( pExpr->pLeft==0
161345 || pExpr->x.pList!=0
161357 sqlite3TreeViewExpr(0,pExpr,0);
161358 assert( 0 );
161379 if( ALWAYS(pSrc->nSrc>0) && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
161389 pTerm->eOperator = 0;
161394 u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
161396 if( pTerm->u.x.iField>0 ){
161404 pTerm->leftCursor = aiCurCol[0];
161405 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
161416 u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
161417 assert( pTerm->u.x.iField==0 );
161418 if( pTerm->leftCursor>=0 ){
161420 pDup = sqlite3ExprDup(db, pExpr, 0);
161426 if( idxNew==0 ) return;
161442 pNew->leftCursor = aiCurCol[0];
161443 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
161452 && 0==sqlite3ExprCanBeNull(pLeft)
161458 pTerm->prereqAll = 0;
161459 pTerm->eOperator = 0;
161485 assert( pList!=0 );
161487 for(i=0; i<2; i++){
161491 sqlite3ExprDup(db, pExpr->pLeft, 0),
161492 sqlite3ExprDup(db, pList->a[i].pExpr, 0));
161495 testcase( idxNew==0 );
161521 && pExpr->pLeft->iColumn>=0
161530 sqlite3ExprDup(db, pLeft, 0),
161531 sqlite3ExprAlloc(db, TK_NULL, 0, 0));
161537 pNewTerm->prereqRight = 0;
161579 pStr2 = sqlite3ExprDup(db, pStr1, 0);
161580 assert( pStr1==0 || !ExprHasProperty(pStr1, EP_IntValue) );
161581 assert( pStr2==0 || !ExprHasProperty(pStr2, EP_IntValue) );
161592 for(i=0; (c = pStr1->u.zToken[i])!=0; i++){
161609 if( c=='A'-1 ) isComplete = 0;
161615 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
161621 testcase( idxNew1==0 );
161622 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
161628 testcase( idxNew2==0 );
161652 && ( (pExpr->pLeft->flags & EP_xIsSelect)==0
161653 || (pExpr->pRight->flags & EP_xIsSelect)==0)
161657 for(i=0; i<nLeft; i++){
161683 && pTerm->u.x.iField==0
161686 && (pExpr->x.pSelect->pPrior==0 || (pExpr->x.pSelect->selFlags & SF_Values))
161688 && pExpr->x.pSelect->pWin==0
161693 for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){
161713 Expr *pRight = 0, *pLeft = 0;
161715 while( res-- > 0 ){
161722 if( (prereqExpr & prereqColumn)==0 ){
161725 0, sqlite3ExprDup(db, pRight, 0));
161731 testcase( idxNew==0 );
161769 ** slot[0] slot[1] slot[2]
161781 assert( pE2!=0 || pExpr==0 );
161782 if( pE2==0 ) return;
161784 whereClauseInsert(pWC, pExpr, 0);
161812 int iVal = 0;
161814 if( sqlite3ExprIsInteger(pExpr, &iVal) && iVal>=0 ){
161815 Expr *pVal = sqlite3Expr(db, TK_INTEGER, 0);
161816 if( pVal==0 ) return;
161819 pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal);
161821 Expr *pVal = sqlite3Expr(db, TK_REGISTER, 0);
161822 if( pVal==0 ) return;
161824 pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal);
161856 assert( p!=0 && p->pLimit!=0 ); /* 1 -- checked by caller */
161857 if( p->pGroupBy==0
161858 && (p->selFlags & (SF_Distinct|SF_Aggregate))==0 /* 2 */
161859 && (p->pSrc->nSrc==1 && IsVirtual(p->pSrc->a[0].pTab)) /* 3 */
161862 int iCsr = p->pSrc->a[0].iCursor;
161866 for(ii=0; ii<pWC->nTerm; ii++){
161882 if( pWC->a[ii].prereqRight!=0 ) return;
161887 for(ii=0; ii<pOrderBy->nExpr; ii++){
161897 if( p->iOffset!=0 && (p->selFlags & SF_Compound)==0 ){
161901 if( p->iOffset==0 || (p->selFlags & SF_Compound)==0 ){
161916 pWC->hasOr = 0;
161917 pWC->pOuter = 0;
161918 pWC->nTerm = 0;
161919 pWC->nBase = 0;
161932 if( pWC->nTerm>0 ){
161939 assert( (pWC->a[i].wtFlags & TERM_VIRTUAL)!=0 );
161943 assert( a->eMatchOp==0 || a->eOperator==WO_AUX );
161949 assert( (a->wtFlags & TERM_ANDINFO)==0 );
161952 assert( (a->wtFlags & TERM_ANDINFO)!=0 );
161971 ** be NULL, in which case 0 is returned.
161982 ** case 0 is returned.
161999 mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0;
162003 assert( p->x.pList==0 );
162012 assert( p->y.pWin!=0 );
162025 return 0;
162030 return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
162034 Bitmask mask = 0;
162036 for(i=0; i<pList->nExpr; i++){
162057 for(i=pWC->nTerm-1; i>=0; i--){
162079 if( pItem->fg.isTabFunc==0 ) return;
162081 assert( pTab!=0 );
162083 if( pArgs==0 ) return;
162084 for(j=k=0; j<pArgs->nExpr; j++){
162087 while( k<pTab->nCol && (pTab->aCol[k].colFlags & COLFLAG_HIDDEN)==0 ){k++;}
162093 pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
162094 if( pColRef==0 ) return;
162101 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
162180 ** WHERE clause. A return of 0 means that the output must be
162187 return pWInfo->nOBSat<0 ? 0 : pWInfo->nOBSat;
162221 assert( pInner->addrNxt!=0 );
162240 if( pWInfo->nOBSat==0 ) return;
162241 for(i=pWInfo->nLevel-1; i>=0; i--){
162243 if( (pInner->pWLoop->wsFlags & WHERE_COLUMN_IN)!=0 ){
162256 assert( pWInfo->iContinue!=0 );
162269 ** Return ONEPASS_OFF (0) if an UPDATE or DELETE statement is unable to
162277 ** into aiCur[0] and aiCur[1]. iaCur[0] gets the cursor of the data
162282 ** aiCur[0] and aiCur[1] both get -1 if the where-clause logic is
162291 aiCur[0], aiCur[1]);
162310 memcpy(pDest->a, pSrc->a, pDest->n*sizeof(pDest->a[0]));
162328 for(i=pSet->n, p=pSet->a; i>0; i--, p++){
162333 return 0;
162344 if( p->rRun<=rRun ) return 0;
162354 ** Return the bitmask for the given cursor number. Return 0 if
162360 assert( pMaskSet->n>0 || pMaskSet->ix[0]<0 );
162362 if( pMaskSet->ix[0]==iCursor ){
162370 return 0;
162416 if( ALWAYS(p!=0) && p->op==TK_COLUMN && !ExprHasProperty(p, EP_FixedCol) ){
162419 return 0;
162443 inexpr.flags = 0;
162455 return 0;
162476 assert( pWC!=0 );
162477 assert( iCur>=0 );
162480 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 || pTerm->leftCursor<0 );
162485 pScan->pIdxExpr,iCur)==0)
162488 if( (pTerm->eOperator & WO_EQUIV)!=0
162490 && (pX = whereRightSubexprIsColumn(pTerm->pExpr))!=0
162493 for(j=0; j<pScan->nEquiv; j++){
162505 if( (pTerm->eOperator & pScan->opMask)!=0 ){
162507 if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){
162529 if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0
162530 && (pX = pTerm->pExpr->pRight, ALWAYS(pX!=0))
162532 && pX->iTable==pScan->aiCur[0]
162533 && pX->iColumn==pScan->aiColumn[0]
162541 if( sqlite3WhereTrace & 0x20000 ){
162545 for(ii=0; ii<pScan->nEquiv; ii++){
162557 k = 0;
162558 }while( pWC!=0 );
162561 k = 0;
162564 return 0;
162584 ** iCur. Or if pIdx!=0 then X is column iColumn of index pIdx. pIdx
162607 pScan->pIdxExpr = 0;
162608 pScan->idxaff = 0;
162609 pScan->zCollName = 0;
162611 pScan->k = 0;
162612 pScan->aiCur[0] = iCur;
162620 }else if( iColumn>=0 ){
162626 pScan->aiColumn[0] = XN_EXPR;
162630 return 0;
162632 pScan->aiColumn[0] = iColumn;
162639 ** if pIdx!=0 and <op> is one of the WO_xx operator codes specified by
162640 ** the op parameter. Return a pointer to the term. Return 0 if not found.
162642 ** If pIdx!=0 then it must be one of the indexes of table iCur.
162669 WhereTerm *pResult = 0;
162676 if( (p->prereqRight & notReady)==0 ){
162677 if( p->prereqRight==0 && (p->eOperator&op)!=0 ){
162681 if( pResult==0 ) pResult = p;
162705 for(i=0; i<pList->nExpr; i++){
162707 if( ALWAYS(p!=0)
162713 if( 0==sqlite3StrICmp(pColl->zName, zColl) ){
162727 assert( pIdx!=0 );
162728 assert( iCol>=0 && iCol<pIdx->nColumn );
162730 if( j>=0 ){
162736 return 0; /* Assume an indexed expression can always yield a NULL */
162762 if( pTabList->nSrc!=1 ) return 0;
162763 iBase = pTabList->a[0].iCursor;
162764 pTab = pTabList->a[0].pTab;
162770 for(i=0; i<pDistinct->nExpr; i++){
162772 if( NEVER(p==0) ) continue;
162774 if( p->iTable==iBase && p->iColumn<0 ) return 1;
162793 for(i=0; i<pIdx->nKeyCol; i++){
162794 if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
162795 if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
162796 if( indexColumnNotNull(pIdx, i)==0 ) break;
162805 return 0;
162813 return N<=10 ? 0 : sqlite3LogEst(N) - 33;
162850 pOp->p3 = 0;
162861 if( iAutoidxCur==0 ){
162863 pOp->p3 = 0;
162882 if( (sqlite3WhereTrace & 0x10)==0 ) return;
162884 for(i=0; i<p->nConstraint; i++){
162894 for(i=0; i<p->nOrderBy; i++){
162906 if( (sqlite3WhereTrace & 0x10)==0 ) return;
162908 for(i=0; i<p->nConstraint; i++){
162942 assert( (pSrc->fg.jointype&(JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ); /* By caller */
162950 return 0;
162952 if( (pSrc->fg.jointype & (JT_LEFT|JT_RIGHT))!=0
162955 return 0;
162974 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
162975 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
162976 assert( (pSrc->fg.jointype & JT_RIGHT)==0 );
162977 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0
162980 return 0; /* See https://sqlite.org/forum/forumpost/51e6959f61 */
162982 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
162983 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
162984 if( pTerm->u.x.leftColumn<0 ) return 0;
162986 if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
163016 char *zText = 0;
163017 int ii = 0;
163022 for(ii=0; ii<(pIdx->nColumn-1); ii++){
163023 const char *zName = 0;
163031 if( zText==0 ){
163035 pParse, 0, "%s)%s", zText, (bPartial ? " WHERE <expr>" : "")
163073 u8 sentWarning = 0; /* True if a warning has been issued */
163074 u8 useBloomFilter = 0; /* True to also add a Bloom filter */
163075 Expr *pPartial = 0; /* Partial Index Expression */
163076 int iContinue = 0; /* Jump here to skip excluded rows */
163079 int addrCounter = 0; /* Address where integer counter is initialized */
163082 int addrExp = 0; /* Address of OP_Explain */
163088 assert( v!=0 );
163093 nKeyCol = 0;
163099 idxCols = 0;
163105 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
163106 && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, pLevel->iFrom, 0)
163109 sqlite3ExprDup(pParse->db, pExpr, 0));
163114 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
163125 if( (idxCols & cMask)==0 ){
163134 assert( nKeyCol>0 || pParse->db->mallocFailed );
163155 for(i=0; i<mxBitCol; i++){
163163 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
163164 if( pIdx==0 ) goto end_auto_index_create;
163168 n = 0;
163169 idxCols = 0;
163174 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
163179 if( (idxCols & cMask)==0 ){
163184 assert( pColl!=0 || pParse->nErr>0 ); /* TH3 collate01.800 */
163187 if( ALWAYS(pX->pLeft!=0)
163204 for(i=0; i<mxBitCol; i++){
163223 explainAutomaticIndex(pParse, pIdx, pPartial!=0, &addrExp);
163224 assert( pLevel->iIdxCur>=0 );
163239 addrCounter = sqlite3VdbeAddOp2(v, OP_Integer, 0, 0);
163240 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pSrc->addrFillSub);
163254 pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0
163257 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0,
163267 assert( pLevel->iIdxCur>0 );
163271 pSrc->fg.viaCoroutine = 0;
163328 pParse->pIdxEpr = 0;
163329 pParse->pIdxPartExpr = 0;
163331 assert( pLoop!=0 );
163332 assert( v!=0 );
163334 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 );
163359 assert( pItem!=0 );
163361 assert( pTab!=0 );
163374 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
163375 && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, iSrc, 0)
163383 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, 1);
163390 for(jj=0; jj<n; jj++){
163394 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, n);
163409 if( NEVER(pLoop==0) ) continue;
163451 u16 mNoOmit = 0;
163453 int eDistinct = 0;
163456 assert( pSrc!=0 );
163458 assert( pTab!=0 );
163465 for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
163474 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
163477 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
163480 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0
163493 nOrderBy = 0;
163496 for(i=0; i<n; i++){
163501 if( sqlite3ExprIsConstant(0, pExpr) ){
163522 assert( pExpr->u.zToken!=0 );
163525 if( pE2->iColumn<0 ) continue; /* Collseq does not matter for rowid */
163527 if( zColl==0 ) zColl = sqlite3StrBINARY;
163528 if( sqlite3_stricmp(pExpr->u.zToken, zColl)==0 ) continue;
163537 eDistinct = 2 + ((pWInfo->wctrlFlags & WHERE_SORTBYGROUP)!=0);
163550 if( pIdxInfo==0 ){
163552 return 0;
163564 pHidden->mIn = 0;
163565 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
163567 if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
163572 if( (pTerm->wtFlags & TERM_SLICE)==0 ){
163611 for(i=j=0; i<nOrderBy; i++){
163613 if( sqlite3ExprIsConstant(0, pExpr) ) continue;
163634 assert( pIdxInfo!=0 );
163636 assert( pHidden->pParse!=0 );
163638 for(i=0; i<pIdxInfo->nConstraint; i++){
163640 pHidden->aRhs[i] = 0;
163684 pVtab->zErrMsg = 0;
163694 ** aStat[0] Est. number of rows less than pRec
163714 int iMin = 0; /* Smallest sample not yet tested */
163718 tRowcnt iLower = 0; /* anLt[] + anEq[] of largest sample pRec is > */
163723 assert( pRec!=0 );
163724 assert( pIdx->nSample>0 );
163725 assert( pRec->nField>0 );
163738 ** aSample[0] = (a, 5)
163748 ** 0: (a)
163760 ** effective sample array. In the above, samples 0 and 1 are based on
163761 ** sample aSample[0]. Samples 2 and 3 on aSample[1] etc.
163778 iCol = 0;
163786 if( iSamp>0 ){
163799 if( res<0 ){
163802 }else if( res==0 && n<nField ){
163817 if( pParse->db->mallocFailed==0 ){
163818 if( res==0 ){
163819 /* If (res==0) is true, then pRec must be equal to sample i. */
163823 assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
163830 assert( i<=pIdx->nSample && i>=0 );
163833 || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
163836 /* if i==0 and iCol==0, then record pRec is smaller than all samples
163837 ** in the aSample[] array. Otherwise, if (iCol>0) then pRec must
163839 ** If (i>0), then pRec must also be greater than sample (i-1). */
163840 if( iCol>0 ){
163842 assert( sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)<=0
163845 if( i>0 ){
163847 assert( sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
163854 if( res==0 ){
163857 aStat[0] = aSample[i].anLt[iCol];
163871 iGap = 0;
163880 aStat[0] = iLower + iGap;
163904 if( pTerm->truthProb<=0 ){
163906 }else if( (pTerm->wtFlags & TERM_VNULL)==0 ){
163919 assert( iCol>=0 && iCol<pIdx->nColumn );
163921 if( sqlite3IndexAffinityStr(db, pIdx)==0 ) return SQLITE_AFF_BLOB;
163923 assert( pIdx->zColAff[iCol]!=0 );
163981 sqlite3_value *p1 = 0; /* Value extracted from pLower */
163982 sqlite3_value *p2 = 0; /* Value extracted from pUpper */
163983 sqlite3_value *pVal = 0; /* Value extracted from record */
163988 nLower = 0;
163992 nUpper = p2 ? 0 : p->nSample;
163998 for(i=0; rc==SQLITE_OK && i<p->nSample; i++){
164002 if( res>=0 ) nLower++;
164006 if( res>=0 ) nUpper++;
164010 if( nDiff<=0 ) nDiff = 1;
164017 if( nDiff!=1 || pUpper==0 || pLower==0 ){
164021 WHERETRACE(0x20, ("range skip-scan regions: %u..%u adjust=%d est=%d\n",
164026 assert( *pbDone==0 );
164064 ** then nEq is set to 0.
164068 ** considering the range constraints. If nEq is 0, then *pnOut is the number of
164092 if( p->nSample>0 && ALWAYS(nEq<p->nSampleCol)
164130 if( nEq==0 ){
164131 iLower = 0;
164136 whereKeyStats(pParse, p, pRec, 0, a);
164137 iLower = a[0];
164138 iUpper = a[0] + a[1];
164141 assert( pLower==0 || (pLower->eOperator & (WO_GT|WO_GE))!=0 );
164142 assert( pUpper==0 || (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
164143 assert( p->aSortOrder!=0 );
164159 iLwrIdx = whereKeyStats(pParse, p, pRec, 0, a);
164160 iNew = a[0] + ((pLower->eOperator & mask) ? a[1] : 0);
164163 pLower = 0;
164177 iNew = a[0] + ((pUpper->eOperator & mask) ? a[1] : 0);
164180 pUpper = 0;
164200 WHERETRACE(0x20, ("STAT4 range scan: %u..%u est=%d\n",
164204 int bDone = 0;
164214 assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 || pParse->nErr>0 );
164224 if( pLower && pLower->truthProb>0 && pUpper && pUpper->truthProb>0 ){
164228 nOut -= (pLower!=0) + (pUpper!=0);
164233 WHERETRACE(0x20,("Range scan lowers nOut from %d to %d\n",
164274 assert( p->aSample!=0 );
164275 assert( p->nSample>0 );
164294 if( bOk==0 ) return SQLITE_NOTFOUND;
164297 whereKeyStats(pParse, p, pRec, 0, a);
164298 WHERETRACE(0x20,("equality scan regions %s(%d): %d\n",
164330 i64 nRow0 = sqlite3LogEstToInt(p->aiRowLogEst[0]);
164334 tRowcnt nRowEst = 0; /* New estimate of the number of rows */
164337 assert( p->aSample!=0 );
164338 for(i=0; rc==SQLITE_OK && i<pList->nExpr; i++){
164348 WHERETRACE(0x20,("IN row estimate: est=%d\n", nRowEst));
164361 if( pTerm==0 ){
164367 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
164372 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
164375 }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){
164376 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
164384 /* The 0x10000 .wheretrace flag causes extra information to be
164386 if( sqlite3WhereTrace & 0x10000 ){
164390 if( (pTerm->eOperator & (WO_OR|WO_AND))==0 && pTerm->u.x.iField ){
164393 if( pTerm->iParent>=0 ){
164397 sqlite3TreeViewExpr(0, pTerm->pExpr, 0);
164408 for(i=0; i<pWC->nTerm; i++){
164428 ** 1.002.001 t2.t2xy 2 f 010241 N 2 cost 0,56,31
164437 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
164443 p->cId, p->iTab, p->maskSelf, p->prereq & 0xfff, p->cId, p->iTab);
164445 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
164447 if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
164448 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
164474 if( p->nLTerm && (sqlite3WhereTrace & 0x4000)!=0 ){
164476 for(i=0; i<p->nLTerm; i++){
164482 if( p ) sqlite3WhereLoopPrint(p, 0);
164498 p->nLTerm = 0;
164500 p->wsFlags = 0;
164508 if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 && p->u.vtab.needFree ){
164510 p->u.vtab.needFree = 0;
164511 p->u.vtab.idxStr = 0;
164512 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
164515 p->u.btree.pIndex = 0;
164531 p->nLTerm = 0;
164532 p->wsFlags = 0;
164542 paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);
164543 if( paNew==0 ) return SQLITE_NOMEM_BKPT;
164544 memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0])*p->nLSlot);
164559 memset(pTo, 0, WHERE_LOOP_XFER_SZ);
164563 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
164565 pFrom->u.vtab.needFree = 0;
164566 }else if( (pFrom->wsFlags & WHERE_AUTO_INDEX)!=0 ){
164567 pFrom->u.btree.pIndex = 0;
164576 assert( db!=0 );
164585 assert( pWInfo!=0 );
164586 assert( db!=0 );
164631 if( pX->rRun>pY->rRun && pX->nOut>pY->nOut ) return 0; /* (1d) and (2a) */
164632 assert( (pX->wsFlags & WHERE_VIRTUALTABLE)==0 );
164633 assert( (pY->wsFlags & WHERE_VIRTUALTABLE)==0 );
164636 && pX->nSkip==0 && pY->nSkip==0 /* (1c) */
164641 return 0; /* (2b) */
164643 if( pY->nSkip > pX->nSkip ) return 0; /* (2d) */
164644 for(i=pX->nLTerm-1; i>=0; i--){
164645 if( pX->aLTerm[i]==0 ) continue;
164646 for(j=pY->nLTerm-1; j>=0; j--){
164649 if( j<0 ) return 0; /* (2c) */
164651 if( (pX->wsFlags&WHERE_IDX_ONLY)!=0
164652 && (pY->wsFlags&WHERE_IDX_ONLY)==0 ){
164653 return 0; /* (2e) */
164673 if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return;
164676 if( (p->wsFlags & WHERE_INDEXED)==0 ) continue;
164680 WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
164689 WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
164728 assert( p->rSetup==0 || pTemplate->rSetup==0
164739 if( (p->wsFlags & WHERE_AUTO_INDEX)!=0
164740 && (pTemplate->nSkip)==0
164741 && (pTemplate->wsFlags & WHERE_INDEXED)!=0
164742 && (pTemplate->wsFlags & WHERE_COLUMN_EQ)!=0
164758 return 0; /* Discard pTemplate */
164808 if( pBuilder->iPlanLimit==0 ){
164809 WHERETRACE(0xffffffff,("=== query planner search limit reached ===\n"));
164810 if( pBuilder->pOrSet ) pBuilder->pOrSet->n = 0;
164820 if( pBuilder->pOrSet!=0 ){
164828 #if WHERETRACE_ENABLED /* 0x8 */
164829 if( sqlite3WhereTrace & 0x8 ){
164842 if( ppPrev==0 ){
164845 #if WHERETRACE_ENABLED /* 0x8 */
164846 if( sqlite3WhereTrace & 0x8 ){
164860 #if WHERETRACE_ENABLED /* 0x8 */
164861 if( sqlite3WhereTrace & 0x8 ){
164862 if( p!=0 ){
164872 if( p==0 ){
164875 if( p==0 ) return SQLITE_NOMEM_BKPT;
164877 p->pNextLoop = 0;
164886 if( ppTail==0 ) break;
164888 if( pToDel==0 ) break;
164890 #if WHERETRACE_ENABLED /* 0x8 */
164891 if( sqlite3WhereTrace & 0x8 ){
164900 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
164903 p->u.btree.pIndex = 0;
164930 ** form "x==EXPR" and EXPR is not a constant 0 or 1, then make sure the
164933 ** out at least 3 out of 4 rows. If EXPR is -1 or 0 or 1, then maybe the
164934 ** "x" column is boolean or else -1 or 0 or 1 is a common default value
164946 LogEst iReduce = 0; /* pLoop->nOut should not exceed nRow-iReduce */
164948 assert( (pLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
164949 for(i=pWC->nBase, pTerm=pWC->a; i>0; i--, pTerm++){
164950 assert( pTerm!=0 );
164951 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
164952 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
164953 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) continue;
164954 for(j=pLoop->nLTerm-1; j>=0; j--){
164956 if( pX==0 ) continue;
164958 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
164960 if( j<0 ){
164972 if( (pTerm->eOperator & 0x3f)!=0
164974 & (JT_LEFT|JT_LTORJ))==0
164979 if( pTerm->truthProb<=0 ){
164987 if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0
164988 && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */
164991 int k = 0;
165043 char idxaff = 0; /* Indexed columns affinity */
165074 if( pColl==0 ) break;
165126 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
165129 assert( db->mallocFailed==0 || pParse->nErr>0 );
165133 WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d, rRun=%d\n",
165137 assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
165138 assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
165142 assert( pNew->u.btree.nBtm==0 );
165147 if( pProbe->bLowQual && pSrc->fg.isIndexedBy==0 ){
165166 pNew->rSetup = 0;
165167 rSize = pProbe->aiRowLogEst[0];
165169 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
165173 int nIn = 0;
165177 if( (eOp==WO_ISNULL || (pTerm->wtFlags&TERM_VNULL)!=0)
165188 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0
165211 assert( nInMul==0
165212 || (pNew->wsFlags & WHERE_COLUMN_NULL)!=0
165213 || (pNew->wsFlags & WHERE_COLUMN_IN)!=0
165214 || (pNew->wsFlags & WHERE_SKIPSCAN)!=0
165228 ** first such term in use, and sets nIn back to 0 if it is not. */
165229 for(i=0; i<pNew->nLTerm-1; i++){
165230 if( pNew->aLTerm[i] && pNew->aLTerm[i]->pExpr==pExpr ) nIn = 0;
165262 if( x>=0 ){
165263 WHERETRACE(0x40,
165268 WHERETRACE(0x40,
165274 WHERETRACE(0x40,
165287 || (iCol>=0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1)
165310 pTop = 0;
165330 pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
165331 pNew->aLTerm[pNew->nLTerm-2] : 0;
165350 if( pTerm->truthProb<=0 && pProbe->aiColumn[saved_nEq]>=0 ){
165351 assert( (eOp & WO_IN) || nIn==0 );
165357 tRowcnt nOut = 0;
165358 if( nInMul==0
165361 && ((eOp & WO_IN)==0 || ExprUseXList(pTerm->pExpr))
165365 if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){
165381 && pNew->nOut+10 > pProbe->aiRowLogEst[0]
165383 #if WHERETRACE_ENABLED /* 0x01 */
165384 if( sqlite3WhereTrace & 0x20 ){
165402 if( nOut==0 )
165423 assert( pSrc->pTab->szTabRow>0 );
165442 if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK|WHERE_EXPRIDX))==0 ){
165459 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
165497 && pProbe->noSkipScan==0
165498 && pProbe->hasStat1!=0
165506 pNew->aLTerm[pNew->nLTerm++] = 0;
165520 WHERETRACE(0x800, ("END %s.addBtreeIdx(%s), nEq=%d, rc=%d\n",
165542 if( pIndex->bUnordered ) return 0;
165543 if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
165544 for(ii=0; ii<pOB->nExpr; ii++){
165546 if( NEVER(pExpr==0) ) continue;
165550 if( pExpr->iColumn<0 ) return 1;
165551 for(jj=0; jj<pIndex->nKeyCol; jj++){
165554 }else if( (aColExpr = pIndex->aColExpr)!=0 ){
165555 for(jj=0; jj<pIndex->nKeyCol; jj++){
165557 if( sqlite3ExprCompareSkip(pExpr,aColExpr->a[jj].pExpr,iCursor)==0 ){
165563 return 0;
165579 if( jointype & JT_LTORJ ) return 0;
165582 if( !whereUsablePartialIndex(iTab,jointype,pWC,pWhere->pLeft) ) return 0;
165585 if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
165586 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
165590 && ((jointype & JT_OUTER)==0 || ExprHasProperty(pExpr, EP_OuterON))
165592 && (pTerm->wtFlags & TERM_VNULL)==0
165597 return 0;
165610 for(i=0; i<pIdx->nColumn; i++){
165612 && sqlite3ExprCompare(0, pExpr, pIdx->aColExpr->a[i].pExpr, iTabCur)==0
165617 return 0;
165658 /* if( pExpr->iColumn<(BMS-1) && pIdx->bHasExpr==0 ) return WRC_Continue;*/
165663 for(i=0; i<nColumn; i++){
165679 ** pWInfo->pSelect (columns from 0 through 62) or an index that has
165686 ** 0 The index is definitely not a covering index
165708 if( pWInfo->pSelect==0 ){
165711 return 0;
165713 if( pIdx->bHasExpr==0 ){
165714 for(i=0; i<pIdx->nColumn; i++){
165721 return 0;
165726 ck.bExpr = 0;
165727 ck.bUnidx = 0;
165728 memset(&w, 0, sizeof(w));
165734 rc = 0;
165749 while( *pp!=0 ){
165792 assert( pItem==0 || (pItem->fg.jointype & JT_RIGHT)==0 );
165793 assert( (pItem==0 || pMask==0) && (pMask!=0 || pItem!=0) );
165806 if( !sqlite3ExprIsConstant(0, pRight) ) return;
165808 if( pLeft->iColumn<0 ) return;
165815 int bNullRow = (pItem->fg.jointype&(JT_LEFT|JT_LTORJ))!=0;
165816 p->pExpr = sqlite3ExprDup(db, pRight, 0);
165824 if( p->pIENext==0 ){
165901 assert( pSrc->fg.isCte==0 );
165912 memset(&sPk, 0, sizeof(Index));
165921 aiRowEstPk[0] = pTab->nRowLogEst;
165922 aiRowEstPk[1] = 0;
165924 if( pSrc->fg.notIndexed==0 ){
165936 && (pWInfo->wctrlFlags & (WHERE_RIGHT_JOIN|WHERE_OR_SUBCLAUSE))==0
165937 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
165943 && (pSrc->fg.jointype & JT_RIGHT)==0 /* Not the right tab of a RIGHT JOIN */
165952 if( termCanDriveIndex(pTerm, pSrc, 0) ){
165954 pNew->nSkip = 0;
165955 pNew->u.btree.pIndex = 0;
165957 pNew->aLTerm[0] = pTerm;
165967 if( !IsView(pTab) && (pTab->tabFlags & TF_Ephemeral)==0 ){
165974 if( pNew->rSetup<0 ) pNew->rSetup = 0;
165992 pProbe=(pSrc->fg.isIndexedBy ? 0 : pProbe->pNext), iSortIdx++
165994 if( pProbe->pPartIdxWhere!=0
166002 rSize = pProbe->aiRowLogEst[0];
166003 pNew->u.btree.nEq = 0;
166004 pNew->u.btree.nBtm = 0;
166005 pNew->u.btree.nTop = 0;
166006 pNew->nSkip = 0;
166007 pNew->nLTerm = 0;
166008 pNew->iSortIdx = 0;
166009 pNew->rSetup = 0;
166016 assert( (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || b==0 );
166022 pNew->iSortIdx = b ? iSortIdx : 0;
166036 pNew->rRun = rSize + 16 - 2*((pTab->tabFlags & TF_HasStat4)!=0);
166048 m = 0;
166054 pWInfo->pParse, pProbe, pProbe->pPartIdxWhere, &m, 0, 0
166058 if( m==TOPBIT || (pProbe->bHasExpr && !pProbe->bHasVCol && m!=0) ){
166060 if( isCov==0 ){
166061 WHERETRACE(0x200,
166064 assert( m!=0 );
166066 m = 0;
166069 WHERETRACE(0x200,
166074 WHERETRACE(0x200,
166079 }else if( m==0
166080 && (HasRowid(pTab) || pWInfo->pSelect!=0 || sqlite3FaultSim(700))
166082 WHERETRACE(0x200,
166084 pProbe->zName, m==0 ? "is" : "is not"));
166092 || pProbe->pPartIdxWhere!=0
166094 || ( m==0
166095 && pProbe->bUnordered==0
166097 && (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
166102 pNew->iSortIdx = b ? iSortIdx : 0;
166108 if( m!=0 ){
166118 for(ii=0; ii<pWC2->nTerm; ii++){
166125 if( pTerm->truthProb<=0 ){
166137 if( (pSrc->fg.jointype & JT_RIGHT)!=0 && pProbe->aColExpr ){
166150 pBuilder->bldFlags1 = 0;
166151 rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0);
166161 pBuilder->nRecValid = 0;
166162 pBuilder->pRec = 0;
166174 assert( pTerm->eOperator==WO_AUX || pTerm->eMatchOp==0 );
166181 ** marked as in-use (have argvIndex>0). False otherwise.
166188 for(ii=0; ii<nCons; ii++){
166189 if( aUsage[ii].argvIndex<=0 ) return 0;
166205 ** as the fourth argument (which in practice is either WO_IN or 0).
166237 *pbIn = 0;
166243 for(i=0; i<nConstraint; i++, pIdxCons++){
166245 pIdxCons->usable = 0;
166247 && (pTerm->eOperator & mExclude)==0
166255 memset(pUsage, 0, sizeof(pUsage[0])*nConstraint);
166256 assert( pIdxInfo->needToFreeIdxStr==0 );
166257 pIdxInfo->idxStr = 0;
166258 pIdxInfo->idxNum = 0;
166259 pIdxInfo->orderByConsumed = 0;
166262 pIdxInfo->idxFlags = 0;
166264 pHidden->mHandleIn = 0;
166274 WHERETRACE(0xffffffff, (" ^^^^--- non-viable plan rejected!\n"));
166282 memset(pNew->aLTerm, 0, sizeof(pNew->aLTerm[0])*nConstraint );
166283 memset(&pNew->u.vtab, 0, sizeof(pNew->u.vtab));
166285 for(i=0; i<nConstraint; i++, pIdxCons++){
166287 if( (iTerm = pUsage[i].argvIndex - 1)>=0 ){
166291 || j<0
166293 || pNew->aLTerm[iTerm]!=0
166294 || pIdxCons->usable==0
166301 testcase( j==0 );
166311 if( i<16 && ((1<<i)&mNoOmit)==0 ){
166323 }else if( (pTerm->eOperator & WO_IN)!=0 ){
166329 pIdxInfo->orderByConsumed = 0;
166331 *pbIn = 1; assert( (mExclude & WO_IN)==0 );
166350 pIdxInfo->idxStr = 0;
166351 pIdxInfo->needToFreeIdxStr = 0;
166360 for(i=0; i<=mxTerm; i++){
166361 if( pNew->aLTerm[i]==0 ){
166372 pIdxInfo->needToFreeIdxStr = 0;
166375 pIdxInfo->nOrderBy : 0);
166376 pNew->rSetup = 0;
166390 pNew->u.vtab.needFree = 0;
166392 WHERETRACE(0xffffffff, (" bIn=%d prereqIn=%04llx prereqOut=%04llx\n",
166416 const char *zRet = 0;
166417 if( iCons>=0 && iCons<pIdxInfo->nConstraint ){
166418 CollSeq *pC = 0;
166431 ** false otherwise. If iCons is an IN(...) constraint, set (if bHandle!=0)
166432 ** or clear (if bHandle==0) the flag to handle it using an iterator.
166438 if( bHandle==0 ){
166440 }else if( bHandle>0 ){
166445 return 0;
166460 sqlite3_value *pVal = 0;
166462 if( iCons<0 || iCons>=pIdxInfo->nConstraint ){
166465 if( pH->aRhs[iCons]==0 ){
166477 if( rc==SQLITE_OK && pVal==0 ){ /* IMP: R-19933-32160 */
166489 assert( pHidden->eDistinct>=0 && pHidden->eDistinct<=3 );
166505 for(i=0; i<nDb; i++){
166509 for(i=0; i<nDb; i++){
166510 sqlite3BeginWriteOperation(pParse, 0, i);
166520 ** mUnusable are set to 0. Otherwise, mPrereq is a mask of all FROM clause
166556 int bRetry = 0; /* True to retry with LIMIT/OFFSET disabled */
166558 assert( (mPrereq & mUnusable)==0 );
166566 if( p==0 ) return SQLITE_NOMEM_BKPT;
166567 pNew->rSetup = 0;
166569 pNew->nLTerm = 0;
166570 pNew->u.vtab.needFree = 0;
166578 WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
166579 WHERETRACE(0x800, (" VirtualOne: all usable\n"));
166581 pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, &bRetry
166586 pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, 0
166591 ** that does not require any source tables (IOW: a plan with mBest==0)
166595 if( rc==SQLITE_OK && ((mBest = (pNew->prereq & ~mPrereq))!=0 || bIn) ){
166596 int seenZero = 0; /* True if a plan with no prereqs seen */
166597 int seenZeroNoIN = 0; /* Plan with no prereqs and no IN(...) seen */
166598 Bitmask mPrev = 0;
166599 Bitmask mBestNoIn = 0;
166604 WHERETRACE(0x800, (" VirtualOne: all usable w/o IN\n"));
166606 pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn, 0);
166607 assert( bIn==0 );
166609 if( mBestNoIn==0 ){
166620 assert( mNext>0 );
166621 for(i=0; i<nConstraint; i++){
166630 WHERETRACE(0x800, (" VirtualOne: mPrev=%04llx mNext=%04llx\n",
166633 pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn, 0);
166636 if( bIn==0 ) seenZeroNoIN = 1;
166643 if( rc==SQLITE_OK && seenZero==0 ){
166644 WHERETRACE(0x800, (" VirtualOne: all disabled\n"));
166646 pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn, 0);
166647 if( bIn==0 ) seenZeroNoIN = 1;
166653 if( rc==SQLITE_OK && seenZeroNoIN==0 ){
166654 WHERETRACE(0x800, (" VirtualOne: all disabled and w/o IN\n"));
166656 pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn, 0);
166662 WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pTab->zName, rc));
166690 memset(&sSum, 0, sizeof(sSum));
166698 if( (pTerm->eOperator & WO_OR)!=0
166699 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
166710 WHERETRACE(0x400, ("Begin processing OR-clause %p\n", pTerm));
166712 if( (pOrTerm->eOperator & WO_AND)!=0 ){
166725 sCur.n = 0;
166727 WHERETRACE(0x400, ("OR-term %d of %p has %d subterms:\n",
166729 if( sqlite3WhereTrace & 0x20000 ){
166744 testcase( rc==SQLITE_NOMEM && sCur.n>0 );
166746 if( sCur.n==0 ){
166747 sSum.n = 0;
166751 once = 0;
166755 sSum.n = 0;
166756 for(i=0; i<sPrev.n; i++){
166757 for(j=0; j<sCur.n; j++){
166766 pNew->aLTerm[0] = pTerm;
166768 pNew->rSetup = 0;
166769 pNew->iSortIdx = 0;
166770 memset(&pNew->u, 0, sizeof(pNew->u));
166771 for(i=0; rc==SQLITE_OK && i<sSum.n; i++){
166789 WHERETRACE(0x400, ("End processing OR-clause %p\n", pTerm));
166800 Bitmask mPrereq = 0;
166801 Bitmask mPrior = 0;
166808 int bFirstPastRJ = 0;
166809 int hasRightJoin = 0;
166817 assert( pNew->nLTerm==0 );
166818 assert( pNew->wsFlags==0 );
166820 assert( pNew->aLTerm!=0 );
166823 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
166824 Bitmask mUnusable = 0;
166829 || (pItem->fg.jointype & (JT_OUTER|JT_CROSS|JT_LTORJ))!=0
166843 bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
166845 mPrereq = 0;
166885 ** N>0: N terms of the ORDER BY clause are satisfied
166886 ** N==0: No terms of the ORDER BY clause are satisfied
166887 ** N<0: Unknown yet how many terms of ORDER BY might be satisfied.
166920 WhereLoop *pLoop = 0; /* Current WhereLoop being processed. */
166926 Bitmask obSat = 0; /* Mask of ORDER BY terms satisfied so far */
166953 assert( pOrderBy!=0 );
166954 if( nLoop && OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ) return 0;
166958 if( nOrderBy>BMS-1 ) return 0; /* Cannot optimize overly large ORDER BYs */
166961 orderDistinctMask = 0;
166962 ready = 0;
166967 for(iLoop=0; isOrderDistinct && obSat<obDone && iLoop<=nLoop; iLoop++){
166968 if( iLoop>0 ) ready |= pLoop->maskSelf;
166983 pLoop->u.btree.nDistinctCol = 0;
166992 for(i=0; i<nOrderBy; i++){
166995 if( NEVER(pOBExpr==0) ) continue;
166999 ~ready, eqOpMask, 0);
167000 if( pTerm==0 ) continue;
167007 for(j=0; j<pLoop->nLTerm && pTerm!=pLoop->aLTerm[j]; j++){}
167010 if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 && pOBExpr->iColumn>=0 ){
167015 if( pColl2==0 || sqlite3StrICmp(pColl1->zName, pColl2->zName) ){
167023 if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
167025 pIndex = 0;
167026 nKeyCol = 0;
167028 }else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
167029 return 0;
167041 && (pLoop->wsFlags & WHERE_SKIPSCAN)==0;
167047 rev = revSet = 0;
167048 distinctColumns = 0;
167049 for(j=0; j<nColumn; j++){
167053 || (pLoop->aLTerm[j]==0)==(j<pLoop->nSkip)
167070 if( (eOp & eqOpMask)!=0 ){
167075 isOrderDistinct = 0;
167087 bOnce = 0;
167103 revIdx = 0;
167110 if( iColumn>=0
167112 && pIndex->pTable->aCol[iColumn].notNull==0
167114 isOrderDistinct = 0;
167117 isOrderDistinct = 0;
167124 isMatch = 0;
167125 for(i=0; bOnce && i<nOrderBy; i++){
167130 if( NEVER(pOBExpr==0) ) continue;
167131 if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0;
167144 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
167152 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
167159 isMatch = 0;
167171 isMatch = 0;
167176 testcase( distinctColumns==0 );
167182 if( j==0 || j<nKeyCol ){
167183 testcase( isOrderDistinct!=0 );
167184 isOrderDistinct = 0;
167190 testcase( isOrderDistinct==0 );
167198 for(i=0; i<nOrderBy; i++){
167204 if( mTerm==0 && !sqlite3ExprIsConstant(0,p) ) continue;
167205 if( (mTerm&~orderDistinctMask)==0 ){
167213 for(i=nOrderBy-1; i>0; i--){
167214 Bitmask m = ALWAYS(i<BMS) ? MASKBIT(i) - 1 : 0;
167217 return 0;
167244 ** SELECT * FROM t1 GROUP BY y,x ORDER BY y,x; -- IsSorted()==0
167257 for(i=0; i<nLoop; i++){ zName[i] = pPath->aLoop[i]->cId; }
167259 zName[i] = 0;
167297 assert( pWInfo->pSelect!=0 );
167298 assert( pWInfo->pSelect->pEList!=0 );
167302 if( nSorted>0 ){
167312 if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 ){
167314 if( nSorted!=0 ){
167336 ** costs if nRowEst==0.
167347 int mxI = 0; /* Index of next entry to replace */
167349 LogEst mxCost = 0; /* Maximum cost of a set of paths */
167350 LogEst mxUnsorted = 0; /* Maximum unsorted cost of a set of path */
167358 LogEst *aSortCost = 0; /* Sorting and partial sorting costs */
167369 WHERETRACE(0x002, ("---- begin solver. (nRowEst=%d, nQueryLoop=%d)\n",
167377 if( pWInfo->pOrderBy==0 || nRowEst==0 ){
167378 nOrderBy = 0;
167387 if( pSpace==0 ) return SQLITE_NOMEM_BKPT;
167390 memset(aFrom, 0, sizeof(aFrom[0]));
167392 for(ii=mxChoice*2, pFrom=aTo; ii>0; ii--, pFrom++, pX += nLoop){
167403 memset(aSortCost, 0, sizeof(LogEst) * nOrderBy);
167405 assert( aSortCost==0 || &pSpace[nSpace]==(char*)&aSortCost[nOrderBy] );
167406 assert( aSortCost!=0 || &pSpace[nSpace]==(char*)pX );
167413 aFrom[0].nRow = MIN(pParse->nQueryLoop, 48); assert( 48==sqlite3LogEst(28) );
167415 assert( aFrom[0].isOrdered==0 );
167423 aFrom[0].isOrdered = nLoop>0 ? -1 : nOrderBy;
167429 for(iLoop=0; iLoop<nLoop; iLoop++){
167430 nTo = 0;
167431 for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
167440 if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
167441 if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
167442 if( (pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 && pFrom->nRow<3 ){
167458 if( isOrdered<0 ){
167459 revMask = 0;
167466 if( isOrdered>=0 && isOrdered<nOrderBy ){
167467 if( aSortCost[isOrdered]==0 ){
167478 WHERETRACE(0x002,
167494 ** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent
167498 for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
167500 && ((pTo->isOrdered^isOrdered)&0x80)==0
167514 #ifdef WHERETRACE_ENABLED /* 0x4 */
167515 if( sqlite3WhereTrace&0x4 ){
167518 isOrdered>=0 ? isOrdered+'0' : '?');
167533 #ifdef WHERETRACE_ENABLED /* 0x4 */
167534 if( sqlite3WhereTrace&0x4 ){
167537 isOrdered>=0 ? isOrdered+'0' : '?');
167556 #ifdef WHERETRACE_ENABLED /* 0x4 */
167557 if( sqlite3WhereTrace&0x4 ){
167561 isOrdered>=0 ? isOrdered+'0' : '?');
167563 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
167564 pTo->rUnsorted, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
167574 #ifdef WHERETRACE_ENABLED /* 0x4 */
167575 if( sqlite3WhereTrace&0x4 ){
167579 isOrdered>=0 ? isOrdered+'0' : '?');
167581 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
167582 pTo->rUnsorted, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
167596 mxI = 0;
167597 mxCost = aTo[0].rCost;
167598 mxUnsorted = aTo[0].nRow;
167613 if( sqlite3WhereTrace & 0x02 ){
167615 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
167617 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
167618 pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?');
167619 if( pTo->isOrdered>0 ){
167620 sqlite3DebugPrintf(" rev=0x%llx\n", pTo->revLoop);
167635 if( nFrom==0 ){
167648 for(iLoop=0; iLoop<nLoop; iLoop++){
167654 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0
167655 && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
167666 pWInfo->bOrderedInnerLoop = 0;
167674 assert( pWInfo->pSelect->pOrderBy==0
167678 if( pWInfo->nOBSat<=0 ){
167679 pWInfo->nOBSat = 0;
167680 if( nLoop>0 ){
167682 if( (wsFlags & WHERE_ONEROW)==0
167685 Bitmask m = 0;
167698 && (pWInfo->wctrlFlags & (WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX))!=0
167704 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0
167706 Bitmask revMask = 0;
167708 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
167710 assert( pWInfo->sorted==0 );
167770 int once = 0;
167772 for(i=0; i<pWInfo->nLevel; i++){
167774 if( p==0 ) break;
167775 if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 ) continue;
167776 if( (p->wsFlags & (WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0 ){
167781 if( (pLoop->wsFlags & (WHERE_CONSTRAINT|WHERE_AUTO_INDEX))!=0 ){
167786 if( sqlite3WhereTrace & 0x80 ){
167787 if( once==0 ){
167826 if( pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE ) return 0;
167830 if( IsVirtual(pTab) ) return 0;
167834 return 0;
167839 pLoop->wsFlags = 0;
167840 pLoop->nSkip = 0;
167841 pTerm = whereScanInit(&scan, pWC, iCur, -1, WO_EQ|WO_IS, 0);
167846 pLoop->aLTerm[0] = pTerm;
167856 || pIdx->pPartIdxWhere!=0
167860 for(j=0; j<pIdx->nKeyCol; j++){
167863 if( pTerm==0 ) break;
167869 if( pIdx->isCovering || (pItem->colUsed & pIdx->colNotIdxed)==0 ){
167882 pWInfo->a[0].pWLoop = pLoop;
167883 assert( pWInfo->sMaskSet.n==1 && iCur==pWInfo->sMaskSet.ix[0] );
167885 pWInfo->a[0].iTabCur = iCur;
167893 pLoop->cId = '0';
167896 if( sqlite3WhereTrace & 0x02 ){
167902 return 0;
167909 if( pExpr->op==TK_FUNCTION && ExprHasProperty(pExpr, EP_ConstFunc)==0 ){
167910 pWalker->eCode = 0;
167923 memset(&w, 0, sizeof(w));
167942 for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
168007 assert( pWInfo->pResultSet!=0 );
168008 assert( 0==(pWInfo->wctrlFlags & WHERE_AGG_DISTINCT) );
168014 hasRightJoin = (pWInfo->pTabList->a[0].fg.jointype & JT_LTORJ)!=0;
168022 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)==0
168023 && (pLoop->wsFlags & WHERE_ONEROW)==0
168027 if( (tabUsed & pLoop->maskSelf)!=0 ) continue;
168030 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
168045 WHERETRACE(0xffffffff, ("-> drop loop %c not used\n", pLoop->cId));
168048 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
168057 assert( pWInfo->nLevel>0 );
168084 LogEst nSearch = 0;
168088 for(i=0; i<pWInfo->nLevel; i++){
168093 if( (pTab->tabFlags & TF_HasStat1)==0 ) break;
168098 && ALWAYS((pLoop->wsFlags & (WHERE_IPK|WHERE_INDEXED))!=0)
168104 WHERETRACE(0xffffffff, (
168141 n = pExpr->x.pList ? pExpr->x.pList->nExpr : 0;
168142 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
168143 if( pDef==0 || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
168160 memset(&w, 0, sizeof(w));
168189 for(i=0; i<pIdx->nColumn; i++){
168194 }else if( j>=0 && (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)!=0 ){
168199 if( sqlite3ExprIsConstant(0,pExpr) ) continue;
168207 if( p==0 ) break;
168210 if( sqlite3WhereTrace & 0x200 ){
168212 if( sqlite3WhereTrace & 0x5000 ) sqlite3ShowExpr(pExpr);
168215 p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
168219 p->bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0;
168227 if( p->pIENext==0 ){
168244 for(ii=0; ii<pWInfo->pTabList->nSrc; ii++){
168248 || NEVER(pItem->pSelect==0)
168249 || pItem->pSelect->pOrderBy==0
168289 ** number pTabList->a[0].iCursor. t2 uses the cursor pTabList->a[1].iCursor.
168317 ** flag = 0
168323 ** if flag==0 then
168367 u8 bFordelete = 0; /* OPFLAG_FORDELETE or zero, as appropriate */
168369 assert( (wctrlFlags & WHERE_ONEPASS_MULTIROW)==0 || (
168370 (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0
168371 && (wctrlFlags & WHERE_OR_SUBCLAUSE)==0
168375 assert( (wctrlFlags & WHERE_OR_SUBCLAUSE)==0
168376 || (wctrlFlags & WHERE_USE_LIMIT)==0 );
168380 memset(&sWLB, 0, sizeof(sWLB));
168385 pOrderBy = 0;
168396 return 0;
168420 pWInfo = 0;
168430 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
168437 memset(&pWInfo->nOBSat, 0,
168439 memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel));
168442 pMaskSet->n = 0;
168443 pMaskSet->ix[0] = -99; /* Initialize ix[0] to a value that can never be
168445 ** test for pMaskSet->n==0 in sqlite3WhereGetMask() */
168463 if( nTabList==0 ){
168465 if( (wctrlFlags & WHERE_WANT_DISTINCT)!=0
168471 && (pWInfo->pSelect->selFlags & SF_MultiValue)==0
168473 ExplainQueryPlan((pParse, 0, "SCAN CONSTANT ROW"));
168490 ii = 0;
168497 Bitmask mx = 0;
168498 for(ii=0; ii<pTabList->nSrc; ii++){
168531 ** WHERE random()>0; -- eval random() once per row
168532 ** WHERE (SELECT random())>0; -- eval random() just once overall
168540 for(ii=0; ii<sWLB.pWC->nBase; ii++){
168545 assert( pX!=0 );
168546 assert( pT->prereqAll!=0 || !ExprHasProperty(pX, EP_OuterON) );
168547 if( pT->prereqAll==0 /* Conditions (1) and (2) */
168548 && (nTabList==0 || exprIsDeterministic(pX)) /* Condition (4) */
168550 && (pTabList->a[0].fg.jointype & JT_LTORJ)!=0 )
168566 }else if( pOrderBy==0 ){
168575 if( sqlite3WhereTrace & 0xffffffff ){
168576 sqlite3DebugPrintf("*** Optimizer Start *** (wctrlFlags: 0x%x",wctrlFlags);
168581 if( sqlite3WhereTrace & 0x8000 ){
168583 memset(&sSelect, 0, sizeof(sSelect));
168589 sqlite3TreeViewSelect(0, &sSelect, 0);
168591 if( sqlite3WhereTrace & 0x4000 ){ /* Display all WHERE clause terms */
168598 if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
168610 WHERETRACE(0xffffffff,
168624 wherePathSolver(pWInfo, 0);
168635 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
168636 WHERETRACE(0x0080,("nRowOut reduced from %d to %d due to DISTINCT\n",
168642 assert( pWInfo->pTabList!=0 );
168643 if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
168649 assert( db->mallocFailed==0 );
168653 if( pWInfo->nOBSat>0 ){
168654 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
168671 for(ii=0; ii<pWInfo->nLevel; ii++){
168687 notReady = ~(Bitmask)0;
168689 && pResultSet!=0 /* Condition (1) */
168690 && 0==(wctrlFlags & (WHERE_AGG_DISTINCT|WHERE_KEEP_ALL_JOINS)) /* (1),(6) */
168695 assert( nTabList>0 );
168708 if( sqlite3WhereTrace & 0x4000 ){ /* Display all terms of the WHERE clause */
168712 WHERETRACE(0xffffffff,("*** Optimizer Finished ***\n"));
168735 assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 );
168736 if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 ){
168737 int wsFlags = pWInfo->a[0].pWLoop->wsFlags;
168738 int bOnerow = (wsFlags & WHERE_ONEROW)!=0;
168739 assert( !(wsFlags & WHERE_VIRTUALTABLE) || IsVirtual(pTabList->a[0].pTab) );
168741 0!=(wctrlFlags & WHERE_ONEPASS_MULTIROW)
168742 && !IsVirtual(pTabList->a[0].pTab)
168743 && (0==(wsFlags & WHERE_MULTI_OR) || (wctrlFlags & WHERE_DUPLICATES_OK))
168747 if( HasRowid(pTabList->a[0].pTab) && (wsFlags & WHERE_IDX_ONLY) ){
168751 pWInfo->a[0].pWLoop->wsFlags = (wsFlags & ~WHERE_IDX_ONLY);
168759 for(ii=0, pLevel=pWInfo->a; ii<nTabList; ii++, pLevel++){
168768 if( (pTab->tabFlags & TF_Ephemeral)!=0 || IsView(pTab) ){
168772 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
168775 sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
168780 if( ((pLoop->wsFlags & WHERE_IDX_ONLY)==0
168781 && (wctrlFlags & WHERE_OR_SUBCLAUSE)==0)
168782 || (pTabItem->fg.jointype & (JT_LTORJ|JT_RIGHT))!=0
168787 pWInfo->aiCurOnePass[0] = pTabItem->iCursor;
168795 && (pTab->tabFlags & (TF_HasGenerated|TF_WithoutRowid))==0
168796 && (pLoop->wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))==0
168802 int n = 0;
168808 if( pLoop->u.btree.pIndex!=0 && (pTab->tabFlags & TF_WithoutRowid)==0 ){
168816 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, pTabItem->iCursor, 0, 0,
168820 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
168827 assert( iAuxArg!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
168829 && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0
168834 op = 0;
168845 }else if( iAuxArg && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 ){
168853 if( pIx->pPartIdxWhere && (pTabItem->fg.jointype & JT_RIGHT)==0 ){
168855 pParse, pIx, pIx->pPartIdxWhere, 0, iIndexCur, pTabItem
168860 assert( pIx!=0 );
168862 assert( iIndexCur>=0 );
168866 if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
168867 && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
168868 && (pLoop->wsFlags & WHERE_BIGNULL_SORT)==0
168869 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0
168870 && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
168878 u64 colUsed = 0;
168880 for(ii=0; ii<pIx->nColumn; ii++){
168882 if( jj<0 ) continue;
168884 if( (pTabItem->colUsed & MASKBIT(jj))==0 ) continue;
168887 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, iIndexCur, 0, 0,
168893 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
168894 if( (pTabItem->fg.jointype & JT_RIGHT)!=0
168895 && (pLevel->pRJ = sqlite3WhereMalloc(pWInfo, sizeof(WhereRightJoin)))!=0
168902 sqlite3VdbeAddOp2(v, OP_Null, 0, pRJ->regReturn);
168907 pInfo = sqlite3KeyInfoAlloc(pParse->db, 1, 0);
168909 pInfo->aColl[0] = 0;
168910 pInfo->aSortFlags[0] = 0;
168922 pWInfo->nOBSat = 0;
168933 for(ii=0; ii<nTabList; ii++){
168951 if( (wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))!=0 ){
168952 if( (wsFlags & WHERE_AUTO_INDEX)!=0 ){
168967 if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_OR_SUBCLAUSE)==0 ){
168986 sqlite3ShowWhereLoopList(0);
168988 return 0;
169006 if( (db->flags & SQLITE_VdbeAddopTrace)==0 ) return;
169007 sqlite3VdbePrintOp(0, pc, pOp);
169024 int nRJ = 0;
169029 for(i=pWInfo->nLevel-1; i>=0; i--){
169037 pLevel->addrCont = 0;
169046 int addrSeek = 0;
169051 && (pLoop->wsFlags & WHERE_INDEXED)!=0
169053 && (n = pLoop->u.btree.nDistinctCol)>0
169058 for(j=0; j<n; j++){
169063 addrSeek = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
169088 if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
169092 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
169099 (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0
169100 && (pLoop->wsFlags & WHERE_IN_EARLYOUT)!=0;
169136 sqlite3VdbeAddOp3(v, OP_Return, pLevel->pRJ->regReturn, 0, 1);
169155 assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 );
169156 if( (ws & WHERE_IDX_ONLY)==0 ){
169162 assert( pSrc->pTab!=0 );
169164 sqlite3VdbeAddOp3(v, OP_Null, 0, n, n+m-1);
169191 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
169194 Index *pIdx = 0;
169197 assert( pTab!=0 );
169215 assert( pTabItem->regResult>=0 );
169217 pTabItem->regResult, 0);
169250 if( sqlite3WhereTrace & 0x200 ){
169253 if( sqlite3WhereTrace & 0x5000 ) sqlite3ShowExpr(p->pExpr);
169295 assert( x>=0 );
169301 if( x>=0 ){
169506 sqlite3_result_int64(pCtx, (p ? *p : 0));
169542 p->nStep = 0;
169579 if( iVal<=0 ) goto error_out;
169583 p->pValue = sqlite3_value_dup(apArg[0]);
169600 p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, 0);
169604 p->pValue = 0;
169617 if( p && p->pValue==0 ){
169618 p->pValue = sqlite3_value_dup(apArg[0]);
169632 p->pValue = 0;
169653 if( p->nValue==0 ){
169665 p->nValue = 0;
169681 UNUSED_PARAMETER(nArg); assert( nArg==0 );
169694 UNUSED_PARAMETER(nArg); assert( nArg==0 );
169726 UNUSED_PARAMETER(nArg); assert( nArg==0 );
169739 UNUSED_PARAMETER(nArg); assert( nArg==0 );
169746 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, 0);
169778 if( p->nTotal==0 ){
169779 p->nParam = sqlite3_value_int64(apArg[0]);
169780 if( p->nParam<=0 ){
169803 if( p && p->nParam>0 ){
169805 if( nSize==0 ){
169845 p->pVal = sqlite3_value_dup(apArg[0]);
169846 if( p->pVal==0 ){
169864 if( p->nVal==0 ){
169866 p->pVal = 0;
169872 p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, 0);
169883 p->pVal = 0;
169924 assert(0); /*NO_TEST*/
169931 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
169933 name ## InvFunc, name ## Name, {0} \
169939 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
169941 noopStepFunc, name ## Name, {0} \
169948 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
169950 noopStepFunc, name ## Name, {0} \
169959 WINDOWFUNCX(row_number, 0, 0),
169960 WINDOWFUNCX(dense_rank, 0, 0),
169961 WINDOWFUNCX(rank, 0, 0),
169962 WINDOWFUNCALL(percent_rank, 0, 0),
169963 WINDOWFUNCALL(cume_dist, 0, 0),
169964 WINDOWFUNCALL(ntile, 1, 0),
169965 WINDOWFUNCALL(last_value, 1, 0),
169966 WINDOWFUNCALL(nth_value, 2, 0),
169967 WINDOWFUNCALL(first_value, 1, 0),
169968 WINDOWFUNCNOOP(lead, 1, 0),
169969 WINDOWFUNCNOOP(lead, 2, 0),
169970 WINDOWFUNCNOOP(lead, 3, 0),
169971 WINDOWFUNCNOOP(lag, 1, 0),
169972 WINDOWFUNCNOOP(lag, 2, 0),
169973 WINDOWFUNCNOOP(lag, 3, 0),
169981 if( sqlite3StrICmp(p->zName, zName)==0 ) break;
169983 if( p==0 ){
170012 if( pWin->zName && pWin->eFrmType==0 ){
170014 if( p==0 ) return;
170015 pWin->pPartition = sqlite3ExprListDup(pParse->db, p->pPartition, 0);
170016 pWin->pOrderBy = sqlite3ExprListDup(pParse->db, p->pOrderBy, 0);
170017 pWin->pStart = sqlite3ExprDup(pParse->db, p->pStart, 0);
170018 pWin->pEnd = sqlite3ExprDup(pParse->db, p->pEnd, 0);
170028 && (pWin->pOrderBy==0 || pWin->pOrderBy->nExpr!=1)
170057 for(i=0; i<ArraySize(aUp); i++){
170061 pWin->pEnd = pWin->pStart = 0;
170065 pWin->eExclude = 0;
170098 assert( p!=0 );
170099 assert( p->pWin!=0 );
170112 for(i=0; i<nSrc; i++){
170142 for(i=0; i<p->pSub->nExpr; i++){
170143 if( 0==sqlite3ExprCompare(0, p->pSub->a[i].pExpr, pExpr, -1) ){
170149 if( iCol<0 ){
170150 Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0);
170156 assert( ExprHasProperty(pExpr, EP_Static)==0 );
170160 memset(pExpr, 0, sizeof(Expr));
170163 pExpr->iColumn = (iCol<0 ? p->pSub->nExpr-1: iCol);
170216 assert( pWin!=0 );
170217 memset(&sWalker, 0, sizeof(Walker));
170218 memset(&sRewrite, 0, sizeof(WindowRewrite));
170247 int nInit = pList ? pList->nExpr : 0;
170248 for(i=0; i<pAppend->nExpr; i++){
170250 Expr *pDup = sqlite3ExprDup(db, pAppend->a[i].pExpr, 0);
170262 pSub->u.zToken = 0;
170290 if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){
170308 && p->pPrior==0
170309 && ALWAYS((p->selFlags & SF_WinRewrite)==0)
170314 Select *pSub = 0; /* The subquery */
170319 ExprList *pSort = 0;
170321 ExprList *pSublist = 0; /* Expression list for sub-query */
170330 if( pTab==0 ){
170335 if( (p->selFlags & SF_Aggregate)==0 ){
170337 w.xSelectCallback = 0;
170341 p->pSrc = 0;
170342 p->pWhere = 0;
170343 p->pGroupBy = 0;
170344 p->pHaving = 0;
170351 pSort = exprListAppendList(pParse, 0, pMWin->pPartition, 1);
170356 if( sqlite3ExprListCompare(pSort, p->pOrderBy, -1)==0 ){
170358 p->pOrderBy = 0;
170371 pMWin->nBufferCol = (pSublist ? pSublist->nExpr : 0);
170376 pSublist = exprListAppendList(pParse, pSublist, pMWin->pPartition, 0);
170377 pSublist = exprListAppendList(pParse, pSublist, pMWin->pOrderBy, 0);
170386 assert( pWin->pWFunc!=0 );
170390 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
170393 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
170394 pSublist = exprListAppendList(pParse, pSublist, pArgs, 0);
170397 Expr *pFilter = sqlite3ExprDup(db, pWin->pFilter, 0);
170402 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
170411 if( pSublist==0 ){
170412 pSublist = sqlite3ExprListAppend(pParse, 0,
170413 sqlite3Expr(db, TK_INTEGER, "0")
170418 pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
170420 TREETRACE(0x40,pParse,pSub,
170423 p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
170424 assert( pSub!=0 || p->pSrc==0 ); /* Due to db->mallocFailed test inside
170429 p->pSrc->a[0].pSelect = pSub;
170430 p->pSrc->a[0].fg.isCorrelated = 1;
170435 if( pTab2==0 ){
170443 p->pSrc->a[0].pTab = pTab;
170445 memset(&w, 0, sizeof(w));
170462 assert( rc==SQLITE_OK || pParse->nErr!=0 );
170474 p->ppThis = 0;
170514 if( 0==sqlite3ExprIsConstant(0,pExpr) ){
170517 pExpr = sqlite3ExprAlloc(pParse->db, TK_NULL, 0, 0);
170527 int eType, /* Frame type. TK_RANGE, TK_ROWS, TK_GROUPS, or 0 */
170534 Window *pWin = 0;
170535 int bImplicitFrame = 0;
170538 assert( eType==0 || eType==TK_RANGE || eType==TK_ROWS || eType==TK_GROUPS );
170543 assert( (eStart==TK_PRECEDING || eStart==TK_FOLLOWING)==(pStart!=0) );
170544 assert( (eEnd==TK_FOLLOWING || eEnd==TK_PRECEDING)==(pEnd!=0) );
170546 if( eType==0 ){
170573 if( pWin==0 ) goto windowAllocErr;
170577 if( eExclude==0 && OptimizationDisabled(pParse->db, SQLITE_WindowFunc) ){
170589 return 0;
170629 const char *zErr = 0;
170635 }else if( pExist->bImplicitFrame==0 ){
170643 pWin->pPartition = sqlite3ExprListDup(db, pExist->pPartition, 0);
170645 assert( pWin->pOrderBy==0 );
170646 pWin->pOrderBy = sqlite3ExprListDup(db, pExist->pOrderBy, 0);
170649 pWin->zBase = 0;
170684 if( 0==pSel->pWin || 0==sqlite3WindowCompare(0, pSel->pWin, pWin, 0) ){
170700 ** Return 0 if the two window objects are identical, 1 if they are
170711 if( NEVER(p1==0) || NEVER(p2==0) ) return 1;
170729 return 0;
170739 int nEphExpr = pSelect->pSrc->a[0].pSelect->pEList->nExpr;
170755 sqlite3VdbeAddOp3(v, OP_Null, 0, pMWin->regPart, pMWin->regPart+nExpr-1);
170766 sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
170777 ** regApp+0: slot to copy min()/max() argument to for MakeRecord
170785 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
170790 assert( pKeyInfo->aSortFlags[0]==0 );
170791 pKeyInfo->aSortFlags[0] = KEYINFO_ORDER_DESC;
170795 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
170812 #define WINDOW_STARTING_INT 0
170819 ** A "PRECEDING <expr>" (eCond==0) or "FOLLOWING <expr>" (eCond==1) or the
170836 assert( eCond>=0 && eCond<ArraySize(azErr) );
170837 sqlite3VdbeAddOp2(v, OP_Integer, 0, regZero);
170840 sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
170850 assert( eCond==0 || eCond==1 || eCond==2 );
170851 VdbeCoverageIf(v, eCond==0);
170857 VdbeCoverageNeverNullIf(v, eCond==0); /* NULL case captured by */
170876 return (pList ? pList->nExpr : 0);
170943 ** 0.
170974 int iColOff = pMWin->nBufferCol + (pPart ? pPart->nExpr : 0);
170976 for(i=0; i<pOrderBy->nExpr; i++){
170983 ** Generate VM code to invoke either xStep() (if bInverse is 0) or
170989 ** If argument csr is greater than or equal to 0, then argument reg is
171014 int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin);
171017 assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );
171021 assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)!=1 );
171023 for(i=0; i<nArg; i++){
171032 if( pMWin->regStartRowid==0
171038 if( bInverse==0 ){
171044 sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
171054 assert( bInverse==0 || bInverse==1 );
171057 int addrIf = 0;
171062 assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
171065 addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
171077 sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
171088 assert( nArg>0 );
171090 pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
171091 sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
171113 ** Generate VM code to invoke either xValue() (bFin==0) or xFinalize()
171125 if( pMWin->regStartRowid==0
171129 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
171132 sqlite3VdbeAddOp3(v, OP_Column, pWin->csrApp, 0, pWin->regResult);
171135 assert( pMWin->regStartRowid==0 );
171142 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
171163 int regCRowid = 0; /* Current rowid value */
171164 int regCPeer = 0; /* Current peer values */
171165 int regRowid = 0; /* AggStep rowid value */
171166 int regPeer = 0; /* AggStep peer values */
171176 assert( pMWin!=0 );
171178 nPeer = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
171194 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
171209 int addrEq = 0;
171210 KeyInfo *pKeyInfo = 0;
171213 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pMWin->pOrderBy, 0, 0);
171216 addrEq = sqlite3VdbeAddOp3(v, OP_Eq, regCRowid, 0, regRowid);
171227 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblNext);
171232 windowAggStep(p, pMWin, csr, 0, p->regArg);
171282 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
171293 sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, 0, tmpReg);
171307 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
171343 int nArg = 0;
171348 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
171350 if( pMWin->regStartRowid==0 ){
171352 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp);
171353 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
171359 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
171385 return 0;
171408 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
171417 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
171469 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_DESC ){
171502 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_BIGNULL ){
171507 sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
171519 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
171541 sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
171542 addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
171554 pColl = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[0].pExpr);
171585 int ret = 0;
171587 int addrContinue = 0;
171591 int addrNextRange = 0;
171596 assert( regCountdown==0 && jumpOnEof==0 );
171597 return 0;
171600 if( regCountdown>0 ){
171625 if( op==WINDOW_RETURN_ROW && pMWin->regStartRowid==0 ){
171626 windowAggFinal(p, 0);
171682 windowAggStep(p, pMWin, csr, 0, p->regArg);
171700 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblDone);
171705 int nReg = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
171706 int regTmp = (nReg ? sqlite3GetTempRange(pParse, nReg) : 0);
171713 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNextRange);
171726 Window *pNew = 0;
171732 pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0);
171734 pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0);
171735 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0);
171745 pNew->pStart = sqlite3ExprDup(db, p->pStart, 0);
171746 pNew->pEnd = sqlite3ExprDup(db, p->pEnd, 0);
171760 Window *pRet = 0;
171764 *pp = sqlite3WindowDup(db, 0, pWin);
171765 if( *pp==0 ) break;
171781 int ret = 0;
171783 sqlite3_value *pVal = 0;
171785 if( pVal && sqlite3_value_int(pVal)>0 ){
171826 ** if( (regEnd--)<=0 ){
171828 ** if( (regStart--)<=0 ){
171839 ** if( (regStart--)<=0 ){
171879 ** if( (regEnd--)<=0 ){
171883 ** if( (regStart--)<=0 ){
171889 ** if( (regEnd--)<=0 ){
171908 ** if( (regEnd--)<=0 ){
171911 ** if( (regStart--)<=0 ){
171919 ** if( (regEnd--)<=0 ){
171923 ** if( (regStart--)<=0 ){
171934 ** CURRENT ROW by assuming that it is equivalent to "0 PRECEDING/FOLLOWING".
171956 ** if( (regStart--)<=0 ){
172138 int csrInput = p->pSrc->a[0].iCursor; /* Cursor of sub-select */
172139 int nInput = p->pSrc->a[0].pTab->nCol; /* Number of cols returned by sub */
172142 int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */
172143 int addrInteger = 0; /* Address of OP_Integer */
172147 int regNewPeer = 0; /* Peer values for new row (part of regNew) */
172148 int regPeer = 0; /* Peer values for current row */
172149 int regFlushPart = 0; /* Register for "Gosub flush_partition" */
172152 int regStart = 0; /* Value of <expr> PRECEDING */
172153 int regEnd = 0; /* Value of <expr> FOLLOWING */
172161 assert( pMWin->eExclude==0 || pMWin->eExclude==TK_CURRENT
172169 memset(&s, 0, sizeof(WindowCodeArg));
172181 ** are four options - they may never be deleted (eDelete==0), they may
172195 if( windowCacheFrame(pMWin)==0 ){
172234 int nPeer = (pOrderBy ? pOrderBy->nExpr : 0);
172246 for(iInput=0; iInput<nInput; iInput++){
172261 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
172276 addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, s.regRowid);
172284 windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE?3:0));
172288 windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE?3:0));
172293 int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
172296 windowAggFinal(&s, 0);
172300 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
172320 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
172329 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
172335 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
172336 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
172337 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
172340 windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 0);
172341 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
172347 windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
172348 if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
172349 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
172350 if( !bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
172352 int addr = 0;
172353 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
172356 int lbl = 0;
172362 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
172363 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
172365 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
172370 addr = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0, 1);
172373 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
172374 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
172386 addrInteger = sqlite3VdbeAddOp2(v, OP_Integer, 0, regFlushPart);
172390 s.regRowid = 0;
172395 windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
172396 if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
172397 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
172403 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
172407 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
172412 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, 0, 1);
172419 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
172422 addrBreak3 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
172423 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
172429 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
172431 addrBreak = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
172432 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
172433 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
172442 sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
172566 assert( p!=0 );
172568 Select *pNext = 0, *pLoop = p;
172575 if( pLoop==0 ) break;
172579 pLoop->pOrderBy!=0 ? "ORDER BY" : "LIMIT",
172584 if( (p->selFlags & (SF_MultiValue|SF_Values))==0
172585 && (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
172611 return sqlite3FaultSim(700) ? 0 : sqlite3_realloc(pOld, newSize);
172619 /* memset(p, 0, sizeof(Expr)); */
172621 p->affExpr = 0;
172625 p->pLeft = p->pRight = 0;
172626 p->pAggInfo = 0;
172627 memset(&p->x, 0, sizeof(p->x));
172628 memset(&p->y, 0, sizeof(p->y));
172629 p->op2 = 0;
172630 p->iTable = 0;
172631 p->iColumn = 0;
172634 p->u.zToken[t.n] = 0;
172636 if( sqlite3Isquote(p->u.zToken[0]) ){
172639 #if SQLITE_MAX_EXPR_DEPTH>0
172657 pA->pRight = 0;
172673 ExprList *p = sqlite3ExprListAppend(pParse, pPrior, 0);
172675 && pParse->db->init.busy==0
172998 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
173015 #if YYSTACKDEPTH<=0 || YYDYNSTACK
173018 # define YYGROWABLESTACK 0
173023 #if YYSTACKDEPTH<=0
173037 ** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
173081 /* 0 */ 576, 128, 125, 232, 1622, 549, 576, 1290, 1281, 576,
173298 /* 0 */ 194, 276, 277, 278, 216, 194, 194, 217, 194, 194,
173456 /* 1580 */ 218, 131, 59, 153, 154, 155, 156, 157, 0, 1,
173533 #define YY_SHIFT_MIN (0)
173536 /* 0 */ 1792, 1588, 1494, 322, 322, 399, 306, 1319, 1339, 1430,
173537 /* 10 */ 1828, 1828, 1828, 580, 399, 399, 399, 399, 399, 0,
173538 /* 20 */ 0, 214, 1093, 1828, 1828, 1828, 1828, 1828, 1828, 1828,
173600 /* 0 */ -71, 194, 343, 835, -180, -177, 838, -194, -188, -185,
173644 /* 0 */ 1663, 1663, 1663, 1491, 1254, 1367, 1254, 1254, 1254, 1254,
173722 0, /* $ => nothing */
173723 0, /* SEMI => nothing */
173728 0, /* TRANSACTION => nothing */
173732 0, /* COMMIT => nothing */
173737 0, /* TO => nothing */
173738 0, /* TABLE => nothing */
173739 0, /* CREATE => nothing */
173741 0, /* NOT => nothing */
173742 0, /* EXISTS => nothing */
173744 0, /* LP => nothing */
173745 0, /* RP => nothing */
173746 0, /* AS => nothing */
173747 0, /* COMMA => nothing */
173765 0, /* OR => nothing */
173766 0, /* AND => nothing */
173767 0, /* IS => nothing */
173770 0, /* BETWEEN => nothing */
173771 0, /* IN => nothing */
173772 0, /* ISNULL => nothing */
173773 0, /* NOTNULL => nothing */
173774 0, /* NE => nothing */
173775 0, /* EQ => nothing */
173776 0, /* GT => nothing */
173777 0, /* LE => nothing */
173778 0, /* LT => nothing */
173779 0, /* GE => nothing */
173780 0, /* ESCAPE => nothing */
173781 0, /* ID => nothing */
173823 0, /* ANY => nothing */
173824 0, /* BITAND => nothing */
173825 0, /* BITOR => nothing */
173826 0, /* LSHIFT => nothing */
173827 0, /* RSHIFT => nothing */
173828 0, /* PLUS => nothing */
173829 0, /* MINUS => nothing */
173830 0, /* STAR => nothing */
173831 0, /* SLASH => nothing */
173832 0, /* REM => nothing */
173833 0, /* CONCAT => nothing */
173834 0, /* PTR => nothing */
173835 0, /* COLLATE => nothing */
173836 0, /* BITNOT => nothing */
173837 0, /* ON => nothing */
173838 0, /* INDEXED => nothing */
173839 0, /* STRING => nothing */
173840 0, /* JOIN_KW => nothing */
173841 0, /* CONSTRAINT => nothing */
173842 0, /* DEFAULT => nothing */
173843 0, /* NULL => nothing */
173844 0, /* PRIMARY => nothing */
173845 0, /* UNIQUE => nothing */
173846 0, /* CHECK => nothing */
173847 0, /* REFERENCES => nothing */
173848 0, /* AUTOINCR => nothing */
173849 0, /* INSERT => nothing */
173850 0, /* DELETE => nothing */
173851 0, /* UPDATE => nothing */
173852 0, /* SET => nothing */
173853 0, /* DEFERRABLE => nothing */
173854 0, /* FOREIGN => nothing */
173855 0, /* DROP => nothing */
173856 0, /* UNION => nothing */
173857 0, /* ALL => nothing */
173858 0, /* EXCEPT => nothing */
173859 0, /* INTERSECT => nothing */
173860 0, /* SELECT => nothing */
173861 0, /* VALUES => nothing */
173862 0, /* DISTINCT => nothing */
173863 0, /* DOT => nothing */
173864 0, /* FROM => nothing */
173865 0, /* JOIN => nothing */
173866 0, /* USING => nothing */
173867 0, /* ORDER => nothing */
173868 0, /* GROUP => nothing */
173869 0, /* HAVING => nothing */
173870 0, /* LIMIT => nothing */
173871 0, /* WHERE => nothing */
173872 0, /* RETURNING => nothing */
173873 0, /* INTO => nothing */
173874 0, /* NOTHING => nothing */
173875 0, /* FLOAT => nothing */
173876 0, /* BLOB => nothing */
173877 0, /* INTEGER => nothing */
173878 0, /* VARIABLE => nothing */
173879 0, /* CASE => nothing */
173880 0, /* WHEN => nothing */
173881 0, /* THEN => nothing */
173882 0, /* ELSE => nothing */
173883 0, /* INDEX => nothing */
173884 0, /* ALTER => nothing */
173885 0, /* ADD => nothing */
173886 0, /* WINDOW => nothing */
173887 0, /* OVER => nothing */
173888 0, /* FILTER => nothing */
173889 0, /* COLUMN => nothing */
173890 0, /* AGG_FUNCTION => nothing */
173891 0, /* AGG_COLUMN => nothing */
173892 0, /* TRUEFALSE => nothing */
173893 0, /* ISNOT => nothing */
173894 0, /* FUNCTION => nothing */
173895 0, /* UPLUS => nothing */
173896 0, /* UMINUS => nothing */
173897 0, /* TRUTH => nothing */
173898 0, /* REGISTER => nothing */
173899 0, /* VECTOR => nothing */
173900 0, /* SELECT_COLUMN => nothing */
173901 0, /* IF_NULL_ROW => nothing */
173902 0, /* ASTERISK => nothing */
173903 0, /* SPAN => nothing */
173904 0, /* ERROR => nothing */
173905 0, /* QNUMBER => nothing */
173906 0, /* SPACE => nothing */
173907 0, /* ILLEGAL => nothing */
173957 static FILE *yyTraceFILE = 0;
173958 static char *yyTracePrompt = 0;
173982 if( yyTraceFILE==0 ) yyTracePrompt = 0;
173983 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
173991 /* 0 */ "$",
174320 /* 0 */ "explain ::= EXPLAIN",
174736 ** of errors. Return 0 on success.
174747 pNew = YYREALLOC(0, newSize*sizeof(pNew[0]));
174748 if( pNew==0 ) return 1;
174749 memcpy(pNew, p->yystack, oldSize*sizeof(pNew[0]));
174751 pNew = YYREALLOC(p->yystack, newSize*sizeof(pNew[0]));
174752 if( pNew==0 ) return 1;
174763 return 0;
174789 yypParser->yyhwm = 0;
174797 yypParser->yystack[0].stateno = 0;
174798 yypParser->yystack[0].major = 0;
174959 assert( pParser->yytos!=0 );
175014 if( p==0 ) return;
175051 int nMissed = 0;
175052 for(stateno=0; stateno<YYNSTATE; stateno++){
175054 for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
175056 if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
175085 assert( i>=0 );
175095 assert( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) );
175097 if( iFallback!=0 ){
175104 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
175112 assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) );
175113 if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){
175127 assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) );
175153 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
175157 assert( i>=0 && i<YY_ACTTAB_COUNT );
175245 190, /* (0) explain ::= EXPLAIN */
175659 -1, /* (0) explain ::= EXPLAIN */
175663 0, /* (4) transtype ::= */
175674 0, /* (15) ifnotexists ::= */
175677 0, /* (18) temp ::= */
175680 0, /* (21) table_option_set ::= */
175685 0, /* (26) typetoken ::= */
175689 0, /* (30) scanpt ::= */
175690 0, /* (31) scantok ::= */
175706 0, /* (47) autoinc ::= */
175708 0, /* (49) refargs ::= */
175721 0, /* (62) init_deferred_pred_opt ::= */
175724 0, /* (65) conslist_opt ::= */
175731 0, /* (72) defer_subclause_opt ::= */
175732 0, /* (73) onconf ::= */
175734 0, /* (75) orconf ::= */
175740 0, /* (81) ifexists ::= */
175759 0, /* (100) distinct ::= */
175760 0, /* (101) sclp ::= */
175765 0, /* (106) as ::= */
175766 0, /* (107) from ::= */
175769 0, /* (110) stl_prefix ::= */
175775 0, /* (116) dbnm ::= */
175789 0, /* (130) on_using ::= */
175790 0, /* (131) indexed_opt ::= */
175793 0, /* (134) orderby_opt ::= */
175799 0, /* (140) sortorder ::= */
175802 0, /* (143) nulls ::= */
175803 0, /* (144) groupby_opt ::= */
175805 0, /* (146) having_opt ::= */
175807 0, /* (148) limit_opt ::= */
175812 0, /* (153) where_opt ::= */
175814 0, /* (155) where_opt_ret ::= */
175825 0, /* (166) upsert ::= */
175834 0, /* (175) idlist_opt ::= */
175891 0, /* (232) case_else ::= */
175892 0, /* (233) case_operand ::= */
175893 0, /* (234) exprlist ::= */
175896 0, /* (237) paren_exprlist ::= */
175900 0, /* (241) uniqueflag ::= */
175901 0, /* (242) eidlist_opt ::= */
175905 0, /* (246) collate ::= */
175911 0, /* (252) vinto ::= */
175923 0, /* (264) trigger_time ::= */
175927 0, /* (268) when_clause ::= */
175946 0, /* (287) key_opt ::= */
175960 0, /* (301) vtabarg ::= */
175980 0, /* (321) frame_opt ::= */
175990 0, /* (331) frame_exclude_opt ::= */
176009 0, /* (350) trans_opt ::= */
176013 0, /* (354) savepoint_opt ::= */
176025 0, /* (366) carglist ::= */
176032 0, /* (373) tconscomma ::= */
176040 0, /* (381) returning ::= */
176051 0, /* (392) foreach_clause ::= */
176054 0, /* (395) tridxby ::= */
176056 0, /* (397) database_kw_opt ::= */
176057 0, /* (398) kwcolumn_opt ::= */
176062 0, /* (403) anylist ::= */
176065 0, /* (406) with ::= */
176101 ** case 0:
176109 case 0: /* explain ::= EXPLAIN */
176110 { if( pParse->pReprepare==0 ) pParse->explain = 1; }
176113 { if( pParse->pReprepare==0 ) pParse->explain = 2; }
176128 {yymsp[0].minor.yy144 = yymsp[0].major; /*A-overwrites-X*/}
176136 sqlite3Savepoint(pParse, SAVEPOINT_BEGIN, &yymsp[0].minor.yy0);
176141 sqlite3Savepoint(pParse, SAVEPOINT_RELEASE, &yymsp[0].minor.yy0);
176146 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
176151 …sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy144,0,0,yymsp[…
176165 {yymsp[1].minor.yy144 = 0;}
176171 {yymsp[0].minor.yy144 = pParse->db->init.busy==0;}
176175 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy391,0);
176180 sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy555);
176181 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy555);
176185 {yymsp[1].minor.yy391 = 0;}
176188 {yylhsminor.yy391 = yymsp[-2].minor.yy391|yymsp[0].minor.yy391;}
176193 if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
176196 yymsp[-1].minor.yy391 = 0;
176197 … sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
176203 if( yymsp[0].minor.yy0.n==6 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"strict",6)==0 ){
176206 yylhsminor.yy391 = 0;
176207 … sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
176210 yymsp[0].minor.yy391 = yylhsminor.yy391;
176213 {sqlite3AddColumn(pParse,yymsp[-1].minor.yy0,yymsp[0].minor.yy0);}
176218 {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;}
176222 …yymsp[-3].minor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
176227 …yymsp[-5].minor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
176231 {yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
176247 {pParse->constraintName = yymsp[0].minor.yy0;}
176250 {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy454,yymsp[-1].minor.yy0.z,&yymsp[-1].minor.yy0.z[yy…
176253 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy454,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);}
176256 {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy454,yymsp[-2].minor.yy0.z,&yymsp[-1].minor.yy0.z[yy…
176260 Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy454, 0);
176266 Expr *p = tokenExpr(pParse, TK_STRING, yymsp[0].minor.yy0);
176271 sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n);
176275 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy144);}
176278 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy144,yymsp[0].minor.yy144,yymsp[-2].minor.yy144);}
176281 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy144,0,0,0,0,
176285 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy454,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy0.z)…
176288 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy14,yymsp[0].minor.yy144);}
176291 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy144);}
176294 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
176297 {sqlite3AddGenerated(pParse,yymsp[-1].minor.yy454,0);}
176300 {sqlite3AddGenerated(pParse,yymsp[-2].minor.yy454,&yymsp[0].minor.yy0);}
176303 {yymsp[0].minor.yy144 = 1;}
176306 { yymsp[1].minor.yy144 = OE_None*0x0101; /* EV: R-19803-45884 */}
176309 { yymsp[-1].minor.yy144 = (yymsp[-1].minor.yy144 & ~yymsp[0].minor.yy383.mask) | yymsp[0].minor.yy3…
176312 { yymsp[-1].minor.yy383.value = 0; yymsp[-1].minor.yy383.mask = 0x000000; }
176315 { yymsp[-2].minor.yy383.value = 0; yymsp[-2].minor.yy383.mask = 0x000000; }
176318 { yymsp[-2].minor.yy383.value = yymsp[0].minor.yy144; yymsp[-2].minor.yy383.mask = 0x0000ff; }
176321 { yymsp[-2].minor.yy383.value = yymsp[0].minor.yy144<<8; yymsp[-2].minor.yy383.mask = 0x00ff00; }
176330 { yymsp[0].minor.yy144 = OE_Cascade; /* EV: R-33326-45252 */}
176333 { yymsp[0].minor.yy144 = OE_Restrict; /* EV: R-33326-45252 */}
176339 {yymsp[-2].minor.yy144 = 0;}
176344 {yymsp[-1].minor.yy144 = yymsp[0].minor.yy144;}
176354 {yymsp[-1].minor.yy144 = 0;}
176357 {pParse->constraintName.n = 0;}
176360 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy14,yymsp[0].minor.yy144,yymsp[-2].minor.yy144,0);}
176363 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy14,yymsp[0].minor.yy144,0,0,0,0,
176372 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy144);
176380 {yymsp[-2].minor.yy144 = yymsp[0].minor.yy144;}
176383 {yymsp[0].minor.yy144 = OE_Ignore;}
176387 {yymsp[0].minor.yy144 = OE_Replace;}
176391 sqlite3DropTable(pParse, yymsp[0].minor.yy203, 0, yymsp[-1].minor.yy144);
176396 …y0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy14, yymsp[0].minor.yy555, yymsp[…
176401 sqlite3DropTable(pParse, yymsp[0].minor.yy203, 1, yymsp[-1].minor.yy144);
176406 SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0, 0};
176407 sqlite3Select(pParse, yymsp[0].minor.yy555, &dest);
176408 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy555);
176412 {yymsp[-2].minor.yy555 = attachWithToSelect(pParse,yymsp[0].minor.yy555,yymsp[-1].minor.yy59);}
176415 {yymsp[-3].minor.yy555 = attachWithToSelect(pParse,yymsp[0].minor.yy555,yymsp[-1].minor.yy59);}
176419 Select *p = yymsp[0].minor.yy555;
176427 Select *pRhs = yymsp[0].minor.yy555;
176432 x.n = 0;
176434 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0);
176435 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
176451 {yymsp[0].minor.yy144 = yymsp[0].major; /*A-overwrites-OP*/}
176458 ….minor.yy14,yymsp[-2].minor.yy454,yymsp[-1].minor.yy14,yymsp[-7].minor.yy144,yymsp[0].minor.yy454);
176463 ….minor.yy14,yymsp[-3].minor.yy454,yymsp[-1].minor.yy14,yymsp[-8].minor.yy144,yymsp[0].minor.yy454);
176473 yymsp[-3].minor.yy555 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0);
176478 sqlite3MultiValuesEnd(pParse, yymsp[0].minor.yy555);
176488 {yymsp[0].minor.yy144 = SF_Distinct;}
176491 {yymsp[0].minor.yy144 = SF_All;}
176499 {yymsp[1].minor.yy14 = 0;}
176504 …if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy14, &yymsp[0].minor.…
176510 Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
176511 sqlite3ExprSetErrorOffset(p, (int)(yymsp[0].minor.yy0.z - pParse->zTail));
176518 pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
176519 sqlite3ExprSetErrorOffset(pRight, (int)(yymsp[0].minor.yy0.z - pParse->zTail));
176529 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
176533 {yymsp[1].minor.yy203 = 0;}
176537 yymsp[-1].minor.yy203 = yymsp[0].minor.yy203;
176543 …3 && yymsp[-1].minor.yy203->nSrc>0) ) yymsp[-1].minor.yy203->a[yymsp[-1].minor.yy203->nSrc-1].fg.j…
176548 …inor.yy203,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0,&yymsp[0].minor.yy269);
176553 …inor.yy203,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,0,&yymsp[0].minor.yy269);
176559 …inor.yy203,&yymsp[-6].minor.yy0,&yymsp[-5].minor.yy0,&yymsp[-1].minor.yy0,0,&yymsp[0].minor.yy269);
176565 …cListAppendFromTerm(pParse,yymsp[-5].minor.yy203,0,0,&yymsp[-1].minor.yy0,yymsp[-3].minor.yy555,&y…
176570 …if( yymsp[-5].minor.yy203==0 && yymsp[-1].minor.yy0.n==0 && yymsp[0].minor.yy269.pOn==0 && yymsp[0…
176572 }else if( ALWAYS(yymsp[-3].minor.yy203!=0) && yymsp[-3].minor.yy203->nSrc==1 ){
176573 … sqlite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy203,0,0,&yymsp[-1].minor.yy0,0,&yymsp[0].mi…
176580 if( pNew->pSelect && (pNew->pSelect->selFlags & SF_NestedFrom)!=0 ){
176585 pOld->u1.pFuncArg = 0;
176586 pOld->fg.isTabFunc = 0;
176589 pOld->zName = pOld->zDatabase = 0;
176590 pOld->pSelect = 0;
176596 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-3].minor.yy203,0,0,0,0,SF_NestedFrom,0);
176597 …ite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy203,0,0,&yymsp[-1].minor.yy0,pSubquery,&yymsp[0…
176603 {yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;}
176607 yylhsminor.yy203 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0);
176608 …ylhsminor.yy203 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy203->a[0].zName, &yymsp[0].minor.yy0);
176610 yymsp[0].minor.yy203 = yylhsminor.yy203;
176614 yylhsminor.yy203 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
176615 …ylhsminor.yy203 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy203->a[0].zName, &yymsp[0].minor.yy0);
176620 {yymsp[0].minor.yy203 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/}
176623 {yymsp[-2].minor.yy203 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /…
176627 …yymsp[-4].minor.yy203 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); …
176628 … yymsp[-4].minor.yy203 ) yymsp[-4].minor.yy203->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yy…
176633 yymsp[-2].minor.yy203 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/
176634 … yymsp[-2].minor.yy203 ) yymsp[-2].minor.yy203->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yy…
176638 { yymsp[0].minor.yy144 = JT_INNER; }
176641 {yymsp[-1].minor.yy144 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
176644 {yymsp[-2].minor.yy144 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-o…
176650 {yymsp[-1].minor.yy269.pOn = yymsp[0].minor.yy454; yymsp[-1].minor.yy269.pUsing = 0;}
176653 {yymsp[-3].minor.yy269.pOn = 0; yymsp[-3].minor.yy269.pUsing = yymsp[-1].minor.yy132;}
176656 {yymsp[1].minor.yy269.pOn = 0; yymsp[1].minor.yy269.pUsing = 0;}
176659 {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
176662 {yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;}
176666 {yymsp[-2].minor.yy14 = yymsp[0].minor.yy14;}
176671 sqlite3ExprListSetSortOrder(yymsp[-4].minor.yy14,yymsp[-1].minor.yy144,yymsp[0].minor.yy144);
176676 yymsp[-2].minor.yy14 = sqlite3ExprListAppend(pParse,0,yymsp[-2].minor.yy454); /*A-overwrites-Y*/
176677 sqlite3ExprListSetSortOrder(yymsp[-2].minor.yy14,yymsp[-1].minor.yy144,yymsp[0].minor.yy144);
176681 {yymsp[0].minor.yy144 = SQLITE_SO_ASC;}
176684 {yymsp[0].minor.yy144 = SQLITE_SO_DESC;}
176703 {yymsp[1].minor.yy454 = 0;}
176710 {yymsp[-1].minor.yy454 = yymsp[0].minor.yy454;}
176713 {yymsp[-1].minor.yy454 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy454,0);}
176716 {yymsp[-3].minor.yy454 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy454,yymsp[0].minor.yy454);}
176719 {yymsp[-3].minor.yy454 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy454,yymsp[-2].minor.yy454);}
176724 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy203,yymsp[0].minor.yy454,0,0);
176728 {sqlite3AddReturning(pParse,yymsp[0].minor.yy14); yymsp[-1].minor.yy454 = 0;}
176731 {sqlite3AddReturning(pParse,yymsp[0].minor.yy14); yymsp[-3].minor.yy454 = yymsp[-2].minor.yy454;}
176742 pSubquery = sqlite3SelectNew(pParse,0,pFromClause,0,0,0,0,SF_NestedFrom,0);
176743 as.n = 0;
176744 as.z = 0;
176745 pFromClause = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
176749 …Parse,yymsp[-5].minor.yy203,yymsp[-2].minor.yy14,yymsp[0].minor.yy454,yymsp[-6].minor.yy144,0,0,0);
176754 yymsp[-4].minor.yy14 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy14, yymsp[0].minor.yy454);
176760 …te3ExprListAppendVector(pParse, yymsp[-6].minor.yy14, yymsp[-3].minor.yy132, yymsp[0].minor.yy454);
176765 yylhsminor.yy14 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy454);
176772 …yymsp[-4].minor.yy14 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy132, yymsp[0].mino…
176777 ….yy203, yymsp[-1].minor.yy555, yymsp[-2].minor.yy132, yymsp[-5].minor.yy144, yymsp[0].minor.yy122);
176782 sqlite3Insert(pParse, yymsp[-4].minor.yy203, 0, yymsp[-3].minor.yy132, yymsp[-6].minor.yy144, 0);
176786 { yymsp[1].minor.yy122 = 0; }
176789 { yymsp[-1].minor.yy122 = 0; sqlite3AddReturning(pParse,yymsp[0].minor.yy14); }
176792 …minor.yy14,yymsp[-6].minor.yy454,yymsp[-2].minor.yy14,yymsp[-1].minor.yy454,yymsp[0].minor.yy122);}
176795 …sqlite3UpsertNew(pParse->db,yymsp[-5].minor.yy14,yymsp[-3].minor.yy454,0,0,yymsp[0].minor.yy122); }
176798 { yymsp[-4].minor.yy122 = sqlite3UpsertNew(pParse->db,0,0,0,0,0); }
176801 …yymsp[-7].minor.yy122 = sqlite3UpsertNew(pParse->db,0,0,yymsp[-2].minor.yy14,yymsp[-1].minor.yy454…
176804 {sqlite3AddReturning(pParse,yymsp[0].minor.yy14);}
176807 {yymsp[1].minor.yy132 = 0;}
176813 {yymsp[-2].minor.yy132 = sqlite3IdListAppend(pParse,yymsp[-2].minor.yy132,&yymsp[0].minor.yy0);}
176816 {yymsp[0].minor.yy132 = sqlite3IdListAppend(pParse,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
176822 {yymsp[0].minor.yy454=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
176827 Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
176836 Expr *temp3 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
176839 sqlite3RenameTokenRemap(pParse, 0, temp1);
176847 {yymsp[0].minor.yy454=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
176851 yylhsminor.yy454 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
176852 if( yylhsminor.yy454 ) yylhsminor.yy454->w.iOfst = (int)(yymsp[0].minor.yy0.z - pParse->zTail);
176854 yymsp[0].minor.yy454 = yylhsminor.yy454;
176858 if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
176859 u32 n = yymsp[0].minor.yy0.n;
176860 yymsp[0].minor.yy454 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0);
176861 sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy454, n);
176866 Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
176868 if( pParse->nested==0 ){
176870 yymsp[0].minor.yy454 = 0;
176872 yymsp[0].minor.yy454 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
176873 if( yymsp[0].minor.yy454 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy454->iTable);
176880 …yymsp[-2].minor.yy454 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy454, &yymsp[0].minor.…
176886 sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy454, yymsp[-3].minor.yy454, 0);
176904 yylhsminor.yy454 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0, 0);
176911 sqlite3WindowAttach(pParse, yylhsminor.yy454, yymsp[0].minor.yy211);
176918 sqlite3WindowAttach(pParse, yylhsminor.yy454, yymsp[0].minor.yy211);
176925 yylhsminor.yy454 = sqlite3ExprFunction(pParse, 0, &yymsp[-4].minor.yy0, 0);
176926 sqlite3WindowAttach(pParse, yylhsminor.yy454, yymsp[0].minor.yy211);
176932 yylhsminor.yy454 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0, 0);
176934 yymsp[0].minor.yy454 = yylhsminor.yy454;
176939 yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
176943 yymsp[-4].minor.yy454->flags |= pList->a[0].pExpr->flags & EP_Propagate;
176951 {yymsp[-2].minor.yy454=sqlite3ExprAnd(pParse,yymsp[-2].minor.yy454,yymsp[0].minor.yy454);}
176960 {yymsp[-2].minor.yy454=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy454,yymsp[0].minor.yy4…
176963 {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-o…
176968 int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
176969 yymsp[-1].minor.yy0.n &= 0x7fffffff;
176970 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy454);
176972 yymsp[-2].minor.yy454 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
176973 if( bNot ) yymsp[-2].minor.yy454 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy454, 0);
176980 int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
176981 yymsp[-3].minor.yy0.n &= 0x7fffffff;
176982 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy454);
176984 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy454);
176985 yymsp[-4].minor.yy454 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0, 0);
176986 if( bNot ) yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy454, 0);
176991 {yymsp[-1].minor.yy454 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy454,0);}
176994 {yymsp[-2].minor.yy454 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy454,0);}
176998 yymsp[-2].minor.yy454 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy454,yymsp[0].minor.yy454);
176999 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy454, yymsp[-2].minor.yy454, TK_ISNULL);
177004 yymsp[-3].minor.yy454 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy454,yymsp[0].minor.yy454);
177005 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy454, yymsp[-3].minor.yy454, TK_NOTNULL);
177010 yymsp[-5].minor.yy454 = sqlite3PExpr(pParse,TK_IS,yymsp[-5].minor.yy454,yymsp[0].minor.yy454);
177011 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy454, yymsp[-5].minor.yy454, TK_ISNULL);
177016 yymsp[-4].minor.yy454 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-4].minor.yy454,yymsp[0].minor.yy454);
177017 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy454, yymsp[-4].minor.yy454, TK_NOTNULL);
177022 {yymsp[-1].minor.yy454 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy454, 0);/*A-overwri…
177026 Expr *p = yymsp[0].minor.yy454;
177034 yymsp[-1].minor.yy454 = sqlite3PExpr(pParse, op, p, 0);
177041 ExprList *pList = sqlite3ExprListAppend(pParse, 0, yymsp[-2].minor.yy454);
177042 pList = sqlite3ExprListAppend(pParse, pList, yymsp[0].minor.yy454);
177043 yylhsminor.yy454 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
177049 {yymsp[0].minor.yy144 = 0;}
177053 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy454);
177054 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy454);
177055 yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy454, 0);
177061 …p[-3].minor.yy144 ) yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy454, 0);
177066 if( yymsp[-1].minor.yy14==0 ){
177072 ** simplify to constants 0 (false) and 1 (true), respectively,
177079 Expr *pRHS = yymsp[-1].minor.yy14->a[0].pExpr;
177081 yymsp[-1].minor.yy14->a[0].pExpr = 0;
177083 pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0);
177086 yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy454, 0);
177088 pRHS->x.pSelect = 0;
177091 yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy454, 0);
177092 if( yymsp[-4].minor.yy454==0 ){
177106 …p[-3].minor.yy144 ) yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy454, 0);
177112 yymsp[-2].minor.yy454 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
177118 yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy454, 0);
177120 …p[-3].minor.yy144 ) yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy454, 0);
177125 SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
177126 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
177127 …if( yymsp[0].minor.yy14 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy14);
177128 yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy454, 0);
177130 …p[-3].minor.yy144 ) yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy454, 0);
177136 p = yymsp[-3].minor.yy454 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
177142 yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy454, 0);
177155 yymsp[-4].minor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy14, yymsp[0].minor.yy454);
177160 yymsp[-3].minor.yy14 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy454);
177161 yymsp[-3].minor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy14, yymsp[0].minor.yy454);
177165 {yymsp[-2].minor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy14,yymsp[0].minor.yy454);}
177168 {yymsp[0].minor.yy14 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy454); /*A-overwrites-Y*/}
177177 …sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy14, yymsp[-10].minor.yy14…
177178 …&yymsp[-11].minor.yy0, yymsp[0].minor.yy454, SQLITE_SO_ASC, yymsp[-8].minor.yy144, SQLITE_IDXTYPE_…
177186 {yymsp[0].minor.yy144 = OE_Abort;}
177193 …m(pParse, yymsp[-4].minor.yy14, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy144, yymsp[0].minor.yy144);
177198 …-2].minor.yy14 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy144, y…
177202 {sqlite3DropIndex(pParse, yymsp[0].minor.yy203, yymsp[-1].minor.yy144);}
177205 {sqlite3Vacuum(pParse,0,yymsp[0].minor.yy454);}
177208 {sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy454);}
177211 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
177214 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
177217 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
177220 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
177229 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
177235 …sp[-4].minor.yy286.a, yymsp[-4].minor.yy286.b, yymsp[-2].minor.yy203, yymsp[0].minor.yy454, yymsp[…
177236 …yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-ove…
177240 { yymsp[0].minor.yy144 = yymsp[0].major; /*A-overwrites-X*/ }
177250 {yymsp[0].minor.yy286.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy286.b = 0;}
177253 {yymsp[-2].minor.yy286.a = TK_UPDATE; yymsp[-2].minor.yy286.b = yymsp[0].minor.yy132;}
177257 { yymsp[1].minor.yy454 = 0; }
177261 { yymsp[-1].minor.yy454 = yymsp[0].minor.yy454; }
177265 assert( yymsp[-2].minor.yy427!=0 );
177272 assert( yymsp[-1].minor.yy427!=0 );
177278 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
177299 ….yy14, yymsp[-1].minor.yy454, yymsp[-7].minor.yy144, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy168);}
177304 …555,yymsp[-6].minor.yy144,yymsp[-1].minor.yy122,yymsp[-7].minor.yy168,yymsp[0].minor.yy168);/*yylh…
177309 …pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy454, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy168);}
177313 …rSelectStep(pParse->db, yymsp[-1].minor.yy555, yymsp[-2].minor.yy168, yymsp[0].minor.yy168); /*yyl…
177318 yymsp[-3].minor.yy454 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
177333 {yymsp[0].minor.yy144 = OE_Rollback;}
177336 {yymsp[0].minor.yy144 = OE_Fail;}
177340 sqlite3DropTrigger(pParse,yymsp[0].minor.yy203,yymsp[-1].minor.yy144);
177345 sqlite3Attach(pParse, yymsp[-3].minor.yy454, yymsp[-1].minor.yy454, yymsp[0].minor.yy454);
177350 sqlite3Detach(pParse, yymsp[0].minor.yy454);
177354 {sqlite3Reindex(pParse, 0, 0);}
177357 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
177360 {sqlite3Analyze(pParse, 0, 0);}
177363 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
177367 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy203,&yymsp[0].minor.yy0);
177378 sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy203, &yymsp[0].minor.yy0);
177384 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy203);
177389 …sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy203, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
177393 {sqlite3VtabFinishParse(pParse,0);}
177396 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
177400 …sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yym…
177409 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
177413 { sqlite3WithPush(pParse, yymsp[0].minor.yy59, 1); }
177416 {yymsp[0].minor.yy462 = M10d_Any;}
177434 yymsp[0].minor.yy59 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy67); /*A-overwrites-X*/
177439 yymsp[-2].minor.yy59 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy59, yymsp[0].minor.yy67);
177444 assert( yymsp[0].minor.yy211!=0 );
177445 sqlite3WindowChain(pParse, yymsp[0].minor.yy211, yymsp[-2].minor.yy211);
177446 yymsp[0].minor.yy211->pNextWin = yymsp[-2].minor.yy211;
177447 yylhsminor.yy211 = yymsp[0].minor.yy211;
177462 …r.yy211 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy211, yymsp[-2].minor.yy14, yymsp[-1].mino…
177467 …yylhsminor.yy211 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy211, yymsp[-2].minor.yy14, yymsp…
177473 …[-3].minor.yy211 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy211, 0, yymsp[-1].minor.yy14, 0);
177478 …yylhsminor.yy211 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy211, 0, yymsp[-1].minor.yy14, &y…
177484 …yylhsminor.yy211 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy211, 0, 0, &yymsp[-1].minor.yy0);
177490 yymsp[1].minor.yy211 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
177495 …44, yymsp[-1].minor.yy509.eType, yymsp[-1].minor.yy509.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy462);
177501 …minor.yy509.pExpr, yymsp[-1].minor.yy509.eType, yymsp[-1].minor.yy509.pExpr, yymsp[0].minor.yy462);
177507 {yylhsminor.yy509 = yymsp[0].minor.yy509;}
177508 yymsp[0].minor.yy509 = yylhsminor.yy509;
177513 {yylhsminor.yy509.eType = yymsp[-1].major; yylhsminor.yy509.pExpr = 0;}
177517 {yylhsminor.yy509.eType = yymsp[0].major; yylhsminor.yy509.pExpr = yymsp[-1].minor.yy454;}
177521 {yymsp[1].minor.yy462 = 0;}
177524 {yymsp[-1].minor.yy462 = yymsp[0].minor.yy462;}
177531 {yymsp[0].minor.yy462 = yymsp[0].major; /*A-overwrites-X*/}
177534 { yymsp[-1].minor.yy211 = yymsp[0].minor.yy211; }
177538 if( yymsp[0].minor.yy211 ){
177539 yymsp[0].minor.yy211->pFilter = yymsp[-1].minor.yy454;
177543 yylhsminor.yy211 = yymsp[0].minor.yy211;
177549 yylhsminor.yy211 = yymsp[0].minor.yy211;
177551 yymsp[0].minor.yy211 = yylhsminor.yy211;
177558 yylhsminor.yy211->pFilter = yymsp[0].minor.yy454;
177560 sqlite3ExprDelete(pParse->db, yymsp[0].minor.yy454);
177563 yymsp[0].minor.yy211 = yylhsminor.yy211;
177568 assert( yymsp[-3].minor.yy211!=0 );
177575 …yymsp[-1].minor.yy211->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.y…
177584 yylhsminor.yy454=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0);
177587 yymsp[0].minor.yy454 = yylhsminor.yy454;
177658 assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
177716 if( TOKEN.z[0] ){
177782 int yyerrorhit = 0; /* True if yymajor has invoked an error */
177788 assert( yypParser->yytos!=0 );
177790 yyendofinput = (yymajor==0);
177813 assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) );
177833 if( yyRuleInfoNRhs[yyruleno]==0 ){
177890 if( yypParser->yyerrcnt<0 ){
177910 if( yypParser->yytos <= yypParser->yystack || yymajor==0 ){
177946 if( yypParser->yyerrcnt<=0 ){
177978 ** 0 if iToken has no fallback.
177982 assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) );
177986 return 0;
178020 #define CC_X 0 /* The letter 'x', or start of BLOB literal */
178049 #define CC_NUL 29 /* 0x00 */
178050 #define CC_BOM 30 /* First byte of UTF8 BOM: 0xEF 0xBB 0xBF */
178055 /* 0x */ 29, 28, 28, 28, 28, 28, 28, 28, 28, 7, 7, 28, 7, 7, 28, 28,
178060 /* 5x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 9, 28, 28, 28, 2,
178062 /* 7x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 28, 10, 28, 25, 28,
178074 /* 0x */ 29, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 7, 7, 28, 28,
178084 /* Ax */ 28, 25, 1, 1, 1, 1, 1, 0, 2, 2, 28, 28, 28, 28, 28, 28,
178088 /* Ex */ 28, 28, 1, 1, 1, 1, 1, 0, 2, 2, 28, 28, 28, 28, 28, 28,
178108 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
178109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
178110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
178111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
178112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3x */
178113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 4x */
178114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 5x */
178115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 95, 0, 0, /* 6x */
178116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 7x */
178117 0, 97, 98, 99,100,101,102,103,104,105, 0, 0, 0, 0, 0, 0, /* 8x */
178118 0,106,107,108,109,110,111,112,113,114, 0, 0, 0, 0, 0, 0, /* 9x */
178119 0, 0,115,116,117,118,119,120,121,122, 0, 0, 0, 0, 0, 0, /* Ax */
178120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */
178121 0, 97, 98, 99,100,101,102,103,104,105, 0, 0, 0, 0, 0, 0, /* Cx */
178122 0,106,107,108,109,110,111,112,113,114, 0, 0, 0, 0, 0, 0, /* Dx */
178123 0, 0,115,116,117,118,119,120,121,122, 0, 0, 0, 0, 0, 0, /* Ex */
178124 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Fx */
178209 84, 92, 134, 82, 105, 29, 0, 0, 94, 0, 85, 72, 0,
178210 53, 35, 86, 15, 0, 42, 97, 54, 89, 135, 19, 0, 0,
178211 140, 0, 40, 129, 0, 22, 107, 0, 9, 0, 0, 123, 80,
178212 0, 78, 6, 0, 65, 103, 147, 0, 136, 115, 0, 0, 48,
178213 0, 90, 24, 0, 17, 0, 27, 70, 23, 26, 5, 60, 142,
178214 110, 122, 0, 73, 91, 71, 145, 61, 120, 74, 0, 49, 0,
178215 11, 41, 0, 113, 0, 0, 0, 109, 10, 111, 116, 125, 14,
178216 50, 124, 0, 100, 0, 18, 121, 144, 56, 130, 139, 88, 83,
178217 37, 30, 126, 0, 0, 108, 51, 131, 128, 0, 34, 0, 0,
178218 132, 0, 98, 38, 39, 0, 20, 45, 117, 93,
178220 /* aKWNext[] forms the hash collision chain. If aKWHash[i]==0
178223 static const unsigned char aKWNext[148] = {0,
178224 0, 0, 0, 0, 4, 0, 43, 0, 0, 106, 114, 0, 0,
178225 0, 2, 0, 0, 143, 0, 0, 0, 13, 0, 0, 0, 0,
178226 141, 0, 0, 119, 52, 0, 0, 137, 12, 0, 0, 62, 0,
178227 138, 0, 133, 0, 0, 36, 0, 0, 28, 77, 0, 0, 0,
178228 0, 59, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0,
178229 0, 69, 0, 0, 0, 0, 0, 146, 3, 0, 58, 0, 1,
178230 75, 0, 0, 0, 31, 0, 0, 0, 0, 0, 127, 0, 104,
178231 0, 64, 66, 63, 0, 0, 0, 0, 0, 46, 0, 16, 8,
178232 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 81, 101, 0,
178233 112, 21, 7, 67, 0, 79, 96, 118, 0, 0, 68, 0, 0,
178234 99, 44, 0, 55, 0, 76, 0, 95, 32, 33, 57, 25, 0,
178235 102, 0, 0, 87,
178238 static const unsigned char aKWLen[148] = {0,
178254 static const unsigned short int aKWOffset[148] = {0,
178255 0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
178269 static const unsigned char aKWCode[148] = {0,
178302 ** 0: INSERT
178430 /* Check to see if z[0..n-1] is a keyword. If it is, write the
178437 i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n*1) % 127;
178438 for(i=(int)aKWHash[i]; i>0; i=aKWNext[i]){
178442 if( (z[0]&~0x20)!=zKW[0] ) continue;
178443 if( (z[1]&~0x20)!=zKW[1] ) continue;
178445 while( j<n && (z[j]&~0x20)==zKW[j] ){ j++; }
178448 if( toupper(z[0])!=zKW[0] ) continue;
178613 if( i<0 || i>=SQLITE_N_KEYWORD ) return SQLITE_ERROR;
178645 #define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
178650 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 4x */
178651 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, /* 5x */
178652 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, /* 6x */
178653 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, /* 7x */
178654 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, /* 8x */
178655 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, /* 9x */
178656 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, /* Ax */
178657 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */
178658 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Cx */
178659 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Dx */
178660 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Ex */
178661 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* Fx */
178663 #define IdChar(C) (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))
178747 ** Return the length (in bytes) of the token that begins at z[0].
178756 testcase( z[0]==' ' );
178757 testcase( z[0]=='\t' );
178758 testcase( z[0]=='\n' );
178759 testcase( z[0]=='\f' );
178760 testcase( z[0]=='\r' );
178767 for(i=2; (c=z[i])!=0 && c!='\n'; i++){}
178798 if( z[1]!='*' || z[2]==0 ){
178802 for(i=3, c=z[2]; (c!='*' || z[i]!='/') && (c=z[i])!=0; i++){}
178873 int delim = z[0];
178877 for(i=1; (c=z[i])!=0; i++){
178889 }else if( c!=0 ){
178910 testcase( z[0]=='0' ); testcase( z[0]=='1' ); testcase( z[0]=='2' );
178911 testcase( z[0]=='3' ); testcase( z[0]=='4' ); testcase( z[0]=='5' );
178912 testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' );
178913 testcase( z[0]=='9' ); testcase( z[0]=='.' );
178916 if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){
178918 if( sqlite3Isxdigit(z[i])==0 ){
178929 for(i=0; 1; i++){
178930 if( sqlite3Isdigit(z[i])==0 ){
178942 if( sqlite3Isdigit(z[i])==0 ){
178958 if( sqlite3Isdigit(z[i])==0 ){
178976 for(i=1, c=z[0]; c!=']' && (c=z[i])!=0; i++){}
178987 int n = 0;
178988 testcase( z[0]=='$' ); testcase( z[0]=='@' );
178989 testcase( z[0]==':' ); testcase( z[0]=='#' );
178991 for(i=1; (c=z[i])!=0; i++){
178995 }else if( c=='(' && n>0 ){
178998 }while( (c=z[i])!=0 && !sqlite3Isspace(c) && c!=')' );
179012 if( n==0 ) *tokenType = TK_ILLEGAL;
179030 testcase( z[0]=='x' ); testcase( z[0]=='X' );
179052 if( z[1]==0xbb && z[2]==0xbf ){
179061 return 0;
179077 int nErr = 0; /* Number of errors encountered */
179079 int n = 0; /* Length of the next token token */
179084 Parse *pParentParse = 0; /* Outer parse context, if any */
179090 assert( zSql!=0 );
179092 if( db->nVdbeActive==0 ){
179093 AtomicStore(&db->u1.isInterrupted, 0);
179102 sqlite3ParserTrace(0, 0);
179110 if( pEngine==0 ){
179115 assert( pParse->pNewTable==0 );
179116 assert( pParse->pNewTrigger==0 );
179117 assert( pParse->nVar==0 );
179118 assert( pParse->pVList==0 );
179124 if( mxSqlLen<0 ){
179150 if( zSql[0]==0 ){
179152 ** with tokens TK_SEMI and 0, in that order. */
179154 tokenType = 0;
179155 }else if( lastTokenParsed==0 ){
179160 n = 0;
179185 assert( db->mallocFailed==0 || pParse->rc!=SQLITE_OK || startedWithOom );
179188 assert( nErr==0 );
179205 if( pParse->zErrMsg==0 ){
179228 assert( nErr==0 || pParse->rc!=SQLITE_OK );
179245 ** Compute a normalization of the SQL given by zSql[0..nSql-1]. Return
179257 int prevType = 0; /* Previous non-whitespace token */
179266 nParen = iStartIN = nParenAtIN = 0;
179268 assert( pStr!=0 ); /* sqlite3_str_new() never returns NULL */
179269 for(i=0; zSql[i] && pStr->accError==0; i+=n){
179274 if( NEVER(n<=0) ) break;
179304 if( iStartIN>0 && nParen==nParenAtIN ){
179308 iStartIN = 0;
179315 iStartIN = 0;
179320 int eType = 0;
179321 if( zId==0 ) break;
179347 iStartIN = 0;
179395 #define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
179399 #define IdChar(C) (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))
179408 #define tkSEMI 0
179428 ** (0) INVALID We have not yet seen a non-whitespace character.
179431 ** returns 1 if it ends in the START state and 0 if it ends
179456 ** (0) tkSEMI A semicolon.
179473 u8 state = 0; /* Current state, using numbers defined in header comment */
179483 /* 0 INVALID: */ { 1, 0, 2, 3, 4, 2, 2, 2, },
179499 /* 0 INVALID: */ { 1, 0, 2, },
179506 if( zSql==0 ){
179508 return 0;
179532 while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
179533 if( zSql[0]==0 ) return 0;
179544 if( *zSql==0 ) return state==1;
179551 if( *zSql==0 ) return 0;
179561 if( *zSql==0 ) return 0;
179578 if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
179586 if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
179588 }else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
179590 }else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
179598 if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
179602 if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
179646 pVal = sqlite3ValueNew(0);
179655 return rc & 0xff;
179700 #if 0
179706 #if 0
179737 #if 0
179743 #if 0
179770 #if 0
179776 #if 0
179873 ** the SQLITE_THREADSAFE compile-time option being set to 0.
179884 # define SQLITE_DEBUG_OS_TRACE 0
179896 SQLITE_API void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...) = 0;
179906 SQLITE_API char *sqlite3_temp_directory = 0;
179915 SQLITE_API char *sqlite3_data_directory = 0;
179925 return 0;
179929 ** clearing the 0x100 bit in the floating-point control word on Intel
179978 int bRunExtraInit = 0; /* Extra initialization needed */
180062 if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){
180070 memset(&sqlite3BuiltinFunctions, 0, sizeof(sqlite3BuiltinFunctions));
180072 if( sqlite3GlobalConfig.isPCacheInit==0 ){
180093 sqlite3GlobalConfig.inProgress = 0;
180102 if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
180103 assert( sqlite3GlobalConfig.nRefInitMutex==0 );
180105 sqlite3GlobalConfig.pInitMutex = 0;
180134 rc = SQLITE_EXTRA_INIT(0);
180170 sqlite3GlobalConfig.isInit = 0;
180174 sqlite3GlobalConfig.isPCacheInit = 0;
180178 sqlite3GlobalConfig.isMallocInit = 0;
180188 sqlite3_data_directory = 0;
180189 sqlite3_temp_directory = 0;
180194 sqlite3GlobalConfig.isMutexInit = 0;
180218 static const u64 mAnytimeConfigOption = 0
180222 if( op<0 || op>63 || (MASKBIT64(op) & mAnytimeConfigOption)==0 ){
180235 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
180239 sqlite3GlobalConfig.bCoreMutex = 0; /* Disable mutex on core */
180240 sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
180244 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
180249 sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
180253 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
180262 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
180269 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */
180291 if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
180352 if( sqlite3GlobalConfig.pcache2.xInit==0 ){
180379 if( sqlite3GlobalConfig.pHeap==0 ){
180388 memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
180430 ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
180475 if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
180478 if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
180508 if( iVal<0 ){
180526 if( 0==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = TF_NoVisibleRowid;
180527 if( 1==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = 0;
180528 *pVal = (sqlite3GlobalConfig.mNoVisibleRowid==0);
180530 *pVal = 0;
180562 if( sqlite3LookasideUsed(db,0)>0 ){
180576 if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;
180577 if( cnt<0 ) cnt = 0;
180578 if( sz==0 || cnt==0 ){
180579 sz = 0;
180580 pStart = 0;
180581 }else if( pBuf==0 ){
180598 if( sz>0 ){
180600 nSm = 0;
180602 nBig = nSm = 0;
180605 db->lookaside.pInit = 0;
180606 db->lookaside.pFree = 0;
180614 for(i=0; i<nBig; i++){
180620 db->lookaside.pSmallInit = 0;
180621 db->lookaside.pSmallFree = 0;
180623 for(i=0; i<nSm; i++){
180631 db->lookaside.bDisable = 0;
180632 db->lookaside.bMalloced = pBuf==0 ?1:0;
180635 db->lookaside.pStart = 0;
180637 db->lookaside.pSmallInit = 0;
180638 db->lookaside.pSmallFree = 0;
180639 db->lookaside.pMiddle = 0;
180641 db->lookaside.pEnd = 0;
180643 db->lookaside.sz = 0;
180644 db->lookaside.bMalloced = 0;
180645 db->lookaside.nSlot = 0;
180648 assert( sqlite3LookasideUsed(db,0)==0 );
180660 return 0;
180678 for(i=0; i<db->nDb; i++){
180697 int bSeenBusy = 0;
180704 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
180736 db->aDb[0].zDbSName = va_arg(ap,char*);
180774 for(i=0; i<ArraySize(aFlagOp); i++){
180779 if( onoff>0 ){
180781 }else if( onoff==0 ){
180785 sqlite3ExpirePreparedStatements(db, 0);
180788 *pRes = (db->flags & aFlagOp[i].mask)!=0;
180819 if( rc==0 ){
180845 assert( p==0 || p->xCmp!=binCollFunc || strcmp(p->zName,"BINARY")==0 );
180846 return p==0 || p->xCmp==binCollFunc;
180866 if( 0==r ){
180879 return 0;
180907 return 0;
180923 return 0;
180943 db->nSavepoint = 0;
180944 db->nStatement = 0;
180945 db->isTransactionSavepoint = 0;
180956 assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
180960 if( pDestructor->nRef==0 ){
180976 for(i=0; i<db->nDb; i++){
181006 for(j=0; j<db->nDb; j++){
181010 return 0;
181027 db->trace.xV2(SQLITE_TRACE_CLOSE, db->pTraceArg, db, 0);
181055 sqlite3GlobalConfig.xSqllog(sqlite3GlobalConfig.pSqllogArg, db, 0, 2);
181062 assert( p->pData!=0 );
181090 if( iDb<0 ) nDb--;
181092 iDb = 0;
181097 int x = pBt!=0 ? sqlite3BtreeTxnState(pBt) : SQLITE_TXN_NONE;
181113 SQLITE_API int sqlite3_close(sqlite3 *db){ return sqlite3Close(db,0); }
181154 for(j=0; j<db->nDb; j++){
181158 pDb->pBt = 0;
181160 pDb->pSchema = 0;
181194 for(j=0; j<3; j++){
181234 assert( sqlite3LookasideUsed(db,0)==0 );
181250 int inTrans = 0;
181262 schemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0 && db->init.busy==0;
181264 for(i=0; i<db->nDb; i++){
181277 sqlite3ExpirePreparedStatements(db, 0);
181283 db->nDeferredCons = 0;
181284 db->nDeferredImmCons = 0;
181299 const char *zName = 0;
181301 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
181397 if( zName==0 ){
181414 /* SQLITE_INTERNAL */ 0,
181428 /* SQLITE_EMPTY */ 0,
181437 /* SQLITE_NOLFS */ 0,
181440 /* SQLITE_FORMAT */ 0,
181461 rc &= 0xff;
181462 if( ALWAYS(rc>=0) && rc<ArraySize(aMsg) && aMsg[rc]!=0 ){
181490 { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
181496 assert( count>=0 );
181506 if( delay<=0 ) return 0;
181516 return 0;
181530 ** returns 0, the operation aborts with an SQLITE_BUSY error.
181534 if( p->xBusyHandler==0 || p->nBusy<0 ) return 0;
181536 if( rc==0 ){
181559 db->busyHandler.nBusy = 0;
181560 db->busyTimeout = 0;
181584 if( nOps>0 ){
181589 db->xProgress = 0;
181590 db->nProgressOps = 0;
181591 db->pProgressArg = 0;
181600 ** specified number of milliseconds before returning 0.
181606 if( ms>0 ){
181611 sqlite3_busy_handler(db, 0, 0);
181622 && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE)
181638 && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE)
181641 return 0;
181644 return AtomicLoad(&db->u1.isInterrupted)!=0;
181670 assert( xValue==0 || xSFunc==0 );
181671 if( zFunctionName==0 /* Must have a valid name */
181672 || (xSFunc!=0 && xFinal!=0) /* Not both xSFunc and xFinal */
181673 || ((xFinal==0)!=(xStep==0)) /* Both or neither of xFinal and xStep */
181674 || ((xValue==0)!=(xInverse==0)) /* Both or neither of xValue, xInverse */
181738 p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 0);
181746 sqlite3ExpirePreparedStatements(db, 0);
181748 }else if( xSFunc==0 && xFinal==0 ){
181801 FuncDestructor *pArg = 0;
181816 pArg->nRef = 0;
181823 if( pArg && pArg->nRef==0 ){
181824 assert( rc!=SQLITE_OK || (xStep==0 && xFinal==0) );
181849 xFinal, 0, 0, 0);
181863 xFinal, 0, 0, xDestroy);
181877 return createFunctionApi(db, zFunc, nArg, enc, p, 0, xStep,
181896 if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT;
181901 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xSFunc,xStep,xFinal,0,0,0);
181953 if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){
181958 rc = sqlite3FindFunction(db, zName, nArg, SQLITE_UTF8, 0)!=0;
181962 if( zCopy==0 ) return SQLITE_NOMEM;
181964 zCopy, sqlite3InvalidFunction, 0, 0, sqlite3_free);
181983 return 0;
181988 db->mTrace = xTrace ? SQLITE_TRACE_LEGACY : 0;
182010 if( mTrace==0 ) xTrace = 0;
182011 if( xTrace==0 ) mTrace = 0;
182038 return 0;
182068 return 0;
182093 return 0;
182118 return 0;
182143 if( db==0 ){
182144 return 0;
182225 if( nFrame>0 ){
182228 sqlite3_wal_hook(db, 0, 0);
182248 return 0;
182258 return 0;
182286 assert( SQLITE_CHECKPOINT_PASSIVE==0 );
182297 if( zDb && zDb[0] ){
182302 if( iDb<0 ){
182306 db->busyHandler.nBusy = 0;
182314 if( db->nVdbeActive==0 ){
182315 AtomicStore(&db->u1.isInterrupted, 0);
182331 ** sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). */
182332 return sqlite3_wal_checkpoint_v2(db,zDb,SQLITE_CHECKPOINT_PASSIVE,0,0);
182359 int bBusy = 0; /* True if SQLITE_BUSY has been encountered */
182367 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
182370 pnLog = 0;
182371 pnCkpt = 0;
182393 ** 0 any file (return 0)
182394 ** 1 1 file (return 0)
182396 ** 1 0 file (return 0)
182397 ** 2 1 file (return 0)
182399 ** 2 0 memory (return 1)
182415 return 0;
182435 testcase( db->pErr==0 );
182436 z = db->errCode ? (char*)sqlite3_value_text(db->pErr) : 0;
182438 if( z==0 ){
182466 'o', 'u', 't', ' ', 'o', 'f', ' ', 'm', 'e', 'm', 'o', 'r', 'y', 0
182471 'm', 'i', 's', 'u', 's', 'e', 0
182486 if( z==0 ){
182525 return db ? db->iSysErrno : 0;
182572 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
182579 sqlite3ExpirePreparedStatements(db, 0);
182590 for(j=0; j<3; j++){
182596 p->xCmp = 0;
182603 if( pColl==0 ) return SQLITE_NOMEM_BKPT;
182651 #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>127
182652 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 127
182654 #if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>125
182655 # error SQLITE_MAX_ATTACHED must be between 0 and 125
182666 #if SQLITE_MAX_WORKER_THREADS<0 || SQLITE_MAX_WORKER_THREADS>50
182667 # error SQLITE_MAX_WORKER_THREADS must be between 0 and 50
182712 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
182716 if( newLimit>=0 ){ /* IMP: R-52476-28732 */
182768 assert( *pzErrMsg==0 );
182772 && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
182777 int iOut = 0; /* Output character index */
182784 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
182788 memset(zFile, 0, 4); /* 4-byte of 0x00 is the start of DB name marker */
182793 if( strncmp(zUri+5, "///", 3)==0 ){
182800 if( strncmp(zUri+7, "///", 3)==0 ){ iIn++; }
182801 }else if( strncmp(zUri+5, "//localhost/", 12)==0 ){
182821 ** Within this loop, variable eState may be set to 0, 1 or 2, depending
182824 ** 0: Parsing file-name.
182828 eState = 0;
182829 while( (c = zUri[iIn])!=0 && c!='#' ){
182838 assert( octet>=0 && octet<256 );
182839 if( octet==0 ){
182845 while( (c = zUri[iIn])!=0 && c!='#'
182846 && (eState!=0 || c!='?')
182862 if( zFile[iOut-1]==0 ){
182868 zFile[iOut++] = '\0';
182872 c = 0;
182873 }else if( (eState==0 && c=='?') || (eState==2 && c=='&') ){
182874 c = 0;
182879 if( eState==1 ) zFile[iOut++] = '\0';
182880 memset(zFile+iOut, 0, 4); /* end-of-options + empty journal filenames */
182887 while( zOpt[0] ){
182892 if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
182898 } *aMode = 0;
182899 char *zModeType = 0;
182900 int mask = 0;
182901 int limit = 0;
182903 if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
182907 { 0, 0 }
182915 if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
182921 { 0, 0 }
182933 int mode = 0;
182934 for(i=0; aMode[i].z; i++){
182936 if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){
182941 if( mode==0 ){
182962 memset(zFile, 0, 4);
182967 memset(zFile+nUri, 0, 4);
182972 if( *ppVfs==0 ){
182979 zFile = 0;
182992 while( ALWAYS(zFilename!=0) && zFilename[0] ){
182995 if( x==0 ) return zFilename;
182998 return 0;
183017 char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
183018 char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
183022 if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
183024 *ppDb = 0;
183030 if( sqlite3GlobalConfig.bCoreMutex==0 ){
183031 isThreadsafe = 0;
183033 isThreadsafe = 0;
183071 if( db==0 ) goto opendb_out;
183078 if( db->mutex==0 ){
183080 db = 0;
183083 if( isThreadsafe==0 ){
183088 db->errMask = (flags & SQLITE_OPEN_EXRESCODE)!=0 ? 0xffffffff : 0xff;
183093 db->lookaside.sz = 0;
183101 db->nextPagesize = 0;
183104 /* Beginning with version 3.37.0, using the VFS xFetch() API to memory-map
183109 db->nMaxSorterMmap = 0x7FFFFFFF;
183115 #if !defined(SQLITE_TRUSTED_SCHEMA) || SQLITE_TRUSTED_SCHEMA+0!=0
183127 ** 0 off off
183131 ** -DSQLITE_DQS=0 (best) or -DSQLITE_DQS=1 (second choice) if possible.
183195 createCollation(db, sqlite3StrBINARY, SQLITE_UTF8, 0, binCollFunc, 0);
183196 createCollation(db, sqlite3StrBINARY, SQLITE_UTF16BE, 0, binCollFunc, 0);
183197 createCollation(db, sqlite3StrBINARY, SQLITE_UTF16LE, 0, binCollFunc, 0);
183198 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
183199 createCollation(db, "RTRIM", SQLITE_UTF8, 0, rtrimCollFunc, 0);
183206 if( zFilename && zFilename[0]==':' ){
183207 if( strcmp(zFilename, ":localStorage:")==0 ){
183210 }else if( strcmp(zFilename, ":sessionStorage:")==0 ){
183230 assert( SQLITE_OPEN_READONLY == 0x01 );
183231 assert( SQLITE_OPEN_READWRITE == 0x02 );
183232 assert( SQLITE_OPEN_CREATE == 0x04 );
183233 testcase( (1<<(flags&7))==0x02 ); /* READONLY */
183234 testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
183235 testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
183236 if( ((1<<(flags&7)) & 0x46)==0 ){
183243 sqlite3ErrorWithMsg(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
183247 assert( db->pVfs!=0 );
183249 if( sqlite3_stricmp(db->pVfs->zName, "kvvfs")==0 ){
183255 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
183264 sqlite3BtreeEnter(db->aDb[0].pBt);
183265 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
183269 sqlite3BtreeLeave(db->aDb[0].pBt);
183270 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
183275 db->aDb[0].zDbSName = "main";
183276 db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
183295 for(i=0; rc==SQLITE_OK && i<ArraySize(sqlite3BuiltinExtensions); i++){
183318 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
183323 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
183330 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
183337 assert( db->mutex!=0 || isThreadsafe==0
183338 || sqlite3GlobalConfig.bFullMutex==0 );
183342 assert( db!=0 || (rc&0xff)==SQLITE_NOMEM );
183343 if( (rc&0xff)==SQLITE_NOMEM ){
183345 db = 0;
183352 /* Opening a db handle. Fourth parameter is passed 0. */
183354 sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
183370 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
183394 if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
183396 *ppDb = 0;
183401 if( zFilename==0 ) zFilename = "\000\000";
183402 pVal = sqlite3ValueNew(0);
183407 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
183409 if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
183417 return rc & 0xff;
183431 return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0);
183448 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
183473 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
183479 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
183502 db->xCollNeeded16 = 0;
183522 db->xCollNeeded = 0;
183537 if( strcmp(p->zName, zName)==0 ){
183544 return 0;
183563 assert( p->pData!=0 );
183565 if( pData==0 ){
183571 }else if( pData==0 ){
183577 if( p==0 ){
183613 return 0;
183636 testcase( sqlite3GlobalConfig.xLog!=0 );
183640 testcase( sqlite3GlobalConfig.xLog!=0 );
183644 testcase( sqlite3GlobalConfig.xLog!=0 );
183651 testcase( sqlite3GlobalConfig.xLog!=0 );
183657 testcase( sqlite3GlobalConfig.xLog!=0 );
183661 testcase( sqlite3GlobalConfig.xLog!=0 );
183694 char *zErrMsg = 0;
183695 Table *pTab = 0;
183696 Column *pCol = 0;
183697 int iCol = 0;
183698 char const *zDataType = 0;
183699 char const *zCollSeq = 0;
183700 int notnull = 0;
183701 int primarykey = 0;
183702 int autoinc = 0;
183706 if( !sqlite3SafetyCheckOk(db) || zTableName==0 ){
183722 pTab = 0;
183727 if( zColumnName==0 ){
183730 for(iCol=0; iCol<pTab->nCol; iCol++){
183732 if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){
183739 pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
183741 pTab = 0;
183758 zDataType = sqlite3ColumnType(pCol,0);
183760 notnull = pCol->notNull!=0;
183761 primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
183762 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
183790 sqlite3ErrorWithMsg(db, rc, (zErrMsg?"%s":0), zErrMsg);
183803 pVfs = sqlite3_vfs_find(0);
183804 if( pVfs==0 ) return 0;
183809 rc = (sqlite3OsSleep(pVfs, ms<0 ? 0 : 1000*ms)/1000);
183821 db->errMask = onoff ? 0xffffffff : 0xff;
183843 assert( pPager!=0 );
183845 assert( fd!=0 );
183861 if( iNew>=0 && iNew<=255 ){
183862 sqlite3BtreeSetPageSize(pBtree, 0, iNew, 0);
183883 int rc = 0;
183914 ** x!=0 && db!=0 Seed the PRNG to the current value of the
183921 ** x!=0 && db==0 Seed the PRNG to the value of x.
183923 ** x==0 && db==0 Revert to default behavior of using the
183934 assert( db==0 || db->aDb[0].pSchema!=0 );
183935 if( db && (y = db->aDb[0].pSchema->schema_cookie)!=0 ){ x = y; }
183937 sqlite3_randomness(0,0);
183969 ** memory allocation error, 0 on success, or non-zero for an error.
183985 ** As a test of the fault simulator mechanism itself, sqlite3FaultSim(0)
183987 ** value from sqlite3FaultSim(0) becomes the return from
184001 rc = sqlite3FaultSim(0);
184024 ** Set the PENDING byte to the value in the argument, if X>0.
184025 ** Make no changes if X==0. Return the value of the pending byte
184028 ** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
184056 volatile int x = 0;
184057 assert( /*side-effects-ok*/ (x = va_arg(ap,int))!=0 );
184063 sqlite3ShowExpr(0);
184064 sqlite3ShowExpr(0);
184065 sqlite3ShowExprList(0);
184066 sqlite3ShowIdList(0);
184067 sqlite3ShowSrcList(0);
184068 sqlite3ShowWith(0);
184069 sqlite3ShowUpsert(0);
184071 sqlite3ShowTriggerStep(0);
184072 sqlite3ShowTriggerStepList(0);
184073 sqlite3ShowTrigger(0);
184074 sqlite3ShowTriggerList(0);
184077 sqlite3ShowWindow(0);
184078 sqlite3ShowWinFunc(0);
184080 sqlite3ShowSelect(0);
184093 ** The return value is ALWAYS(X) if X is true, or 0 if X is false.
184111 ** // ALWAYS(x) is a constant 1. NEVER(x) is a constant 0.
184116 rc = x ? ALWAYS(x) : 0;
184140 ** operation N should be 0. The idea is that a test program (like the
184154 ** If 2, then invoke xAlt() instead of localtime(). If 0, normal
184170 sqlite3GlobalConfig.xAltLocaltime = 0;
184217 ** By default this is 0x7ffffffe (over 2 billion), but that value is
184254 if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
184270 ** If onOff==0 and tnum>0 then reset the schema for all databases, causing
184279 if( iDb>=0 ){
184283 if( db->init.busy==0 && db->init.newTnum>0 ){
184344 ** op==0 Store the current sqlite3TreeTrace in *ptr
184353 case 0: *ptr = sqlite3TreeTrace; break;
184385 ** X<0 Make no changes to the bUseLongDouble. Just report value.
184386 ** X==0 Disable bUseLongDouble
184393 if( b>=0 ) sqlite3Config.bUseLongDouble = b>0;
184394 rc = sqlite3Config.bUseLongDouble!=0;
184419 if( id>0 && id<=SQLITE_NTUNE ){
184421 }else if( id<0 && id>=-SQLITE_NTUNE ){
184443 if( *pOnOff<0 ){
184446 sqlite3Config.bJsonSelfcheck = (u8)((*pOnOff)&0xff);
184466 while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){
184502 for(i=0; i<nParam*2; i++){
184506 if( p==0 ) return 0;
184507 memset(p, 0, 4);
184510 for(i=0; i<nParam*2; i++){
184513 *(p++) = 0;
184516 *(p++) = 0;
184517 *(p++) = 0;
184528 if( p==0 ) return;
184546 if( zFilename==0 || zParam==0 ) return 0;
184555 if( zFilename==0 || N<0 ) return 0;
184558 while( ALWAYS(zFilename) && zFilename[0] && (N--)>0 ){
184562 return zFilename[0] ? zFilename : 0;
184570 bDflt = bDflt!=0;
184584 if( z && sqlite3DecOrHexToI64(z, &v)==0 ){
184601 if( zFilename==0 ) return 0;
184605 if( zFilename==0 ) return 0;
184608 while( ALWAYS(zFilename) && zFilename[0] ){
184616 return 0;
184628 int iDb = zDbName ? sqlite3FindDbName(db, zDbName) : 0;
184629 return iDb<0 ? 0 : db->aDb[iDb].pBt;
184640 return 0;
184643 if( N<0 || N>=db->nDb ){
184644 return 0;
184659 return 0;
184663 return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
184667 ** Return 1 if database is read-only or 0 if read/write. Return -1 if
184702 if( db->autoCommit==0 ){
184704 if( iDb==0 || iDb>1 ){
184707 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
184737 if( db->autoCommit==0 ){
184740 if( iDb==0 || iDb>1 ){
184744 int bUnlock = 0;
184746 if( db->nVdbeActive==0 ){
184760 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
184761 sqlite3PagerSnapshotOpen(pPager, 0);
184792 if( iDb==0 || iDb>1 ){
184795 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
184829 if( zOptName==0 ){
184831 return 0;
184837 if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
184842 for(i=0; i<nOpt; i++){
184843 if( sqlite3StrNICmp(zOptName, azCompileOpt[i], n)==0
184844 && sqlite3IsIdChar((unsigned char)azCompileOpt[i][n])==0
184849 return 0;
184860 if( N>=0 && N<nOpt ){
184863 return 0;
184908 static sqlite3 *SQLITE_WSD sqlite3BlockedList = 0;
184928 int seen = 0;
184938 assert( db==0 || p->pUnlockConnection!=db );
184939 assert( db==0 || p->pBlockingConnection!=db );
184983 checkListProperties(0);
184991 checkListProperties(0);
185013 ** on the same "db". If xNotify==0 then any prior callbacks are immediately
185029 if( xNotify==0 ){
185031 db->pBlockingConnection = 0;
185032 db->pUnlockConnection = 0;
185033 db->xUnlockNotify = 0;
185034 db->pUnlockArg = 0;
185035 }else if( 0==db->pBlockingConnection ){
185058 sqlite3ErrorWithMsg(db, rc, (rc?"database is deadlocked":0));
185071 if( db->pBlockingConnection==0 && db->pUnlockConnection==0 ){
185087 ** set to db, then set pBlockingConnection=0.
185091 ** set pUnlockConnection=0.
185093 ** 3) If the two steps above mean that pBlockingConnection==0 and
185094 ** pUnlockConnection==0, remove the entry from the blocked connections
185098 void (*xUnlockNotify)(void **, int) = 0; /* Unlock-notify cb to invoke */
185099 int nArg = 0; /* Number of entries in aArg[] */
185102 void **aDyn = 0; /* Dynamically allocated space for aArg[] */
185114 p->pBlockingConnection = 0;
185120 if( p->xUnlockNotify!=xUnlockNotify && nArg!=0 ){
185122 nArg = 0;
185126 assert( aArg==aDyn || (aDyn==0 && aArg==aStatic) );
185163 nArg = 0;
185170 p->pUnlockConnection = 0;
185171 p->xUnlockNotify = 0;
185172 p->pUnlockArg = 0;
185176 if( p->pBlockingConnection==0 && p->pUnlockConnection==0 ){
185179 p->pNextBlocked = 0;
185185 if( nArg!=0 ){
185246 ** A = 0xxxxxxx 7 bits of data and one flag bit
185261 ** 1: 0x01
185262 ** 127: 0x7f
185263 ** 128: 0x81 0x00
185271 ** word of the document has a position of 0.
185280 ** array { (position list for column 0)
185297 ** ending a position list array. POS_END is 0. POS_COLUMN is 1.
185303 ** value: 123 5 9 1 1 14 35 0 234 72 0
185309 ** (14-2 and 35-2+12). The 0 at H indicate the end-of-document. The
185311 ** (72-2) and then terminates with the 0 at K.
185329 ** varint iHeight; (height from leaf level, always 0)
185375 ** varint iHeight; (height from leaf level, always >0)
185433 ** leaves_end_block, and end_block are all 0.
185442 ** written individually (using LeafWriter) to a level 0 segment, with
185444 ** level 0 segments are merged into a single level 1 segment. Level 1
185445 ** is populated like level 0, and eventually MERGE_COUNT level 1
185599 ** Structure version. Should always be set to 0 or 1.
185614 ** This method should return either SQLITE_OK (0), or an SQLite error
185861 #define SizeofArray(X) ((int)(sizeof(X)/sizeof(X[0])))
185887 ** level values between 0 and 1023 (inclusive) belong to index 0, all levels
185909 #define POS_END (0) /* Position-list terminator */
185938 # define NEVER(X) (0)
185940 # define ALWAYS(X) ((X)?1:(assert(0),0))
185941 # define NEVER(X) ((X)?(assert(0),1):0)
185979 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
186056 ** there is an entry in the aIndex[] array. Index 0 is an index of all the
186068 int nPrefix; /* Prefix length (0 for main terms index) */
186134 #define FTS3_EVAL_FILTER 0
186148 ** Fts3Cursor.eSearch will be set to FTS3_FULLTEXT_SEARCH+1. (+0 for a,
186153 #define FTS3_FULLSCAN_SEARCH 0 /* Linear scan of %_content table */
186163 #define FTS3_HAVE_LANGID 0x00010000 /* languageid=? */
186164 #define FTS3_HAVE_DOCID_GE 0x00020000 /* docid>=? */
186165 #define FTS3_HAVE_DOCID_LE 0x00040000 /* docid<=? */
186172 sqlite3_int64 iDocid; /* Current docid (if pList!=0) */
186188 int bFirst; /* True if token must appear at position 0 */
186230 ** aMI[iCol*3 + 0] = Undefined
186319 #define FTS3_SEGMENT_REQUIRE_POS 0x00000001
186320 #define FTS3_SEGMENT_IGNORE_EMPTY 0x00000002
186321 #define FTS3_SEGMENT_COLUMN_FILTER 0x00000004
186322 #define FTS3_SEGMENT_PREFIX 0x00000008
186323 #define FTS3_SEGMENT_SCAN 0x00000010
186324 #define FTS3_SEGMENT_FIRST 0x00000020
186343 int iColFilter; /* If >=0, filter for this column */
186360 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
186483 ** Write a 64-bit variable-length integer to memory starting at p[0].
186491 *q++ = (unsigned char) ((vu & 0x7f) | 0x80);
186493 }while( vu!=0 );
186494 q[-1] &= 0x7f; /* turn off high bit in final byte */
186501 if( (v & mask2)==0 ){ var = v; return ret; }
186504 if( (v & mask2)==0 ){ var = v; return ret; }
186513 GETVARINT_INIT(a, p, 0, 0x00, 0x80, *v, 1);
186514 GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *v, 2);
186515 GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *v, 3);
186516 GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *v, 4);
186517 b = (a & 0x0FFFFFFF );
186521 b += (c&0x7F) << shift;
186522 if( (c & 0x80)==0 ) break;
186529 ** Read a 64-bit variable-length integer from memory starting at p[0].
186530 ** Return the number of bytes read, or 0 on error.
186538 ** Read a 64-bit variable-length integer from memory starting at p[0] and
186540 ** Return the number of bytes read, or 0 on error.
186551 u64 b = 0;
186553 for(shift=0; shift<=63; shift+=7){
186554 u64 c = p<pX ? *p : 0;
186556 b += (c&0x7F) << shift;
186557 if( (c & 0x80)==0 ) break;
186572 GETVARINT_INIT(a, ptr, 0, 0x00, 0x80, *pi, 1);
186575 assert( a & 0x80 );
186578 GETVARINT_STEP(a, ptr, 7, 0x7F, 0x4000, *pi, 2);
186579 GETVARINT_STEP(a, ptr, 14, 0x3FFF, 0x200000, *pi, 3);
186580 GETVARINT_STEP(a, ptr, 21, 0x1FFFFF, 0x10000000, *pi, 4);
186581 a = (a & 0x0FFFFFFF );
186582 *pi = (int)(a | ((u32)(*ptr & 0x07) << 28));
186583 assert( 0==(a & 0x80000000) );
186584 assert( *pi>=0 );
186592 int i = 0;
186596 }while( v!=0 );
186617 quote = z[0];
186620 int iOut = 0; /* Index of next byte to write to output */
186634 z[iOut] = '\0';
186667 ** interested in. So, unless the doclist is corrupt, the 0x80 bit is
186669 for(p = (*pp)-2; p>=pStart && *p&0x80; p--);
186684 assert( p->nPendingData==0 );
186685 assert( p->pSegments==0 );
186689 for(i=0; i<SizeofArray(p->aStmt); i++){
186735 if( zSql==0 ){
186738 *pRc = sqlite3_exec(db, zSql, 0, 0, 0);
186796 zCols = sqlite3_mprintf("%Q, ", p->azColumn[0]);
186844 if( p->zContentTbl==0 ){
186850 for(i=0; zContentCols && i<p->nColumn; i++){
186857 if( zContentCols==0 ) rc = SQLITE_NOMEM;
186914 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
186917 p->nPgsz = sqlite3_column_int(pStmt, 0);
186924 assert( p->nPgsz>0 || rc!=SQLITE_OK );
186947 if( *zCsr=='\0' ) return 0;
186980 if( z==0 ) *pRc = SQLITE_NOMEM;
187005 for(i=0; zInput[i]; i++){
187010 *(z++) = '\0';
187039 char *zRet = 0;
187040 char *zFree = 0;
187044 if( p->zContentTbl==0 ){
187051 for(i=0; i<p->nColumn; i++){
187060 for(i=0; i<p->nColumn; i++){
187096 char *zRet = 0;
187097 char *zFree = 0;
187107 for(i=0; i<p->nColumn; i++){
187123 u64 iVal = 0;
187125 for(i=0; z[i]>='0' && z[i]<='9'; i++){
187126 iVal = iVal*10 + (z[i] - '0');
187127 if( iVal>0x7FFFFFFF ) return -1;
187139 ** Only decimal digits ('0'..'9') may be part of an integer value.
187148 int nInt = 0; /* Output value */
187152 nInt = 0;
187154 if( nByte==0 ){
187187 if( zParam && zParam[0] ){
187201 memset(aIndex, 0, sizeof(struct Fts3Index) * nIndex);
187206 int nPrefix = 0;
187208 assert( nPrefix>=0 );
187209 if( nPrefix==0 ){
187259 sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */
187265 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
187274 sqlite3_int64 nStr = 0; /* Size of all column names (incl. 0x00) */
187282 for(i=0; i<nCol; i++){
187289 if( azCol==0 ){
187293 for(i=0; i<nCol; i++){
187318 ** argv[0] -> module name ("fts3" or "fts4")
187333 Fts3Table *p = 0; /* Pointer to allocated vtab */
187338 int nString = 0; /* Bytes required to hold all column names */
187339 int nCol = 0; /* Number of columns in the FTS table */
187343 int isFts4 = (argv[0][3]=='4'); /* True for FTS4, false for FTS3 */
187345 sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */
187347 int nIndex = 0; /* Size of aIndex[] array */
187348 struct Fts3Index *aIndex = 0; /* Array of indexes for this table */
187351 int bNoDocsize = 0; /* True to omit %_docsize table */
187352 int bDescIdx = 0; /* True to store descending indexes */
187353 char *zPrefix = 0; /* Prefix parameter value (or NULL) */
187354 char *zCompress = 0; /* compress=? parameter (or NULL) */
187355 char *zUncompress = 0; /* uncompress=? parameter (or NULL) */
187356 char *zContent = 0; /* content=? parameter (or NULL) */
187357 char *zLanguageid = 0; /* languageid=? parameter (or NULL) */
187358 char **azNotindexed = 0; /* The set of notindexed= columns */
187359 int nNotindexed = 0; /* Size of azNotindexed[] array */
187361 assert( strlen(argv[0])==4 );
187362 assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
187363 || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
187372 memset((void*)aCol, 0, nByte);
187376 memset(azNotindexed, 0, nByte);
187402 && 0==sqlite3_strnicmp(z, "tokenize", 8)
187403 && 0==sqlite3Fts3IsIdChar(z[8])
187414 { "matchinfo", 9 }, /* 0 -> MATCHINFO */
187428 for(iOpt=0; iOpt<SizeofArray(aFts4Opt); iOpt++){
187435 case 0: /* MATCHINFO */
187446 zVal = 0;
187452 zVal = 0;
187458 zVal = 0;
187468 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
187474 zVal = 0;
187481 zVal = 0;
187486 zVal = 0;
187516 zCompress = 0;
187517 zUncompress = 0;
187518 if( nCol==0 ){
187520 aCol = 0;
187527 for(j=0; j<nCol; j++){
187528 if( sqlite3_stricmp(zLanguageid, aCol[j])==0 ){
187540 if( nCol==0 ){
187541 assert( nString==0 );
187542 aCol[0] = "content";
187547 if( pTokenizer==0 ){
187569 if( p==0 ){
187573 memset(p, 0, nByte);
187576 p->nPendingData = 0;
187580 p->bHasDocsize = (isFts4 && bNoDocsize==0);
187584 p->nAutoincrmerge = 0xff; /* 0xff means setting unknown */
187587 zContent = 0;
187588 zLanguageid = 0;
187595 for(i=0; i<nIndex; i++){
187610 for(iCol=0; iCol<nCol; iCol++){
187612 int n = 0;
187614 if( n>0 ){
187617 zCsr[n] = '\0';
187625 for(iCol=0; iCol<nCol; iCol++){
187627 for(i=0; i<nNotindexed; i++){
187630 && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n)
187634 azNotindexed[i] = 0;
187638 for(i=0; i<nNotindexed; i++){
187645 if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
187646 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
187687 for(i=0; i<nNotindexed; i++) sqlite3_free(azNotindexed[i]);
187697 assert( p->pSegments==0 );
187715 return fts3InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
187782 for(i=0; i<pInfo->nConstraint; i++){
187785 if( pCons->usable==0 ){
187800 bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1);
187803 if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){
187819 && pCons->iColumn>=0 && pCons->iColumn<=p->nColumn
187852 if( iCons>=0 ){
187856 if( iLangidCons>=0 ){
187860 if( iDocidGe>=0 ){
187864 if( iDocidLe>=0 ){
187873 struct sqlite3_index_orderby *pOrder = &pInfo->aOrderBy[0];
187874 if( pOrder->iColumn<0 || pOrder->iColumn==p->nColumn+1 ){
187884 assert( p->pSegments==0 );
187904 memset(pCsr, 0, sizeof(Fts3Cursor));
187918 if( p->pSeekStmt==0 ){
187921 pCsr->pStmt = 0;
187923 pCsr->bSeekStmt = 0;
187938 memset(&(&pCsr->base)[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
187947 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
187949 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
187955 ** If pCsr->pStmt has not been prepared (i.e. if pCsr->pStmt==0), then
187965 if( pCsr->pStmt==0 ){
187970 p->pSeekStmt = 0;
187976 p->db, zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
187999 pCsr->isRequireSeek = 0;
188006 if( rc==SQLITE_OK && ((Fts3Table *)pCsr->base.pVtab)->zContentTbl==0 ){
188049 char *zBuffer = 0; /* Buffer to load terms into */
188050 i64 nAlloc = 0; /* Size of allocated buffer */
188053 int nBuffer = 0; /* Total term size */
188077 int nPrefix = 0; /* Size of term prefix */
188088 isFirstTerm = 0;
188091 assert( nPrefix>=0 && nSuffix>=0 );
188092 if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){
188121 if( piFirst && (cmp<0 || (cmp==0 && nBuffer>nTerm)) ){
188123 piFirst = 0;
188126 if( piLast && cmp<0 ){
188128 piLast = 0;
188183 char *zBlob = 0; /* Blob read from %_segments table */
188184 int nBlob = 0; /* Size of zBlob in bytes */
188187 rc = sqlite3Fts3ReadBlock(p, *piLeaf, &zBlob, &nBlob, 0);
188189 rc = fts3SelectLeaf(p, zTerm, nTerm, zBlob, nBlob, piLeaf, 0);
188192 piLeaf = 0;
188193 zBlob = 0;
188197 rc = sqlite3Fts3ReadBlock(p, piLeaf?*piLeaf:*piLeaf2, &zBlob, &nBlob, 0);
188200 int iNewHeight = 0;
188223 assert_fts3_nc( iVal-*piPrev > 0 || (*piPrev==0 && iVal==0) );
188244 char c = 0;
188247 ** varint. A single POS_END (0) byte. Except, if the 0 byte is preceded by
188248 ** a byte with the 0x80 bit set, then it is not a varint 0, but the tail
188252 ** immediately preceded by a byte with the 0x80 bit set. Then increments
188257 c = *pEnd++ & 0x80;
188258 testcase( c!=0 && (*pEnd)==0 );
188281 ** a POS_END varint (0). This routine leaves *ppPoslist pointing to
188291 char c = 0;
188293 /* A column-list is terminated by either a 0x01 or 0x00 byte that is
188296 while( 0xFE & (*pEnd | c) ){
188297 c = *pEnd++ & 0x80;
188298 testcase( c!=0 && ((*pEnd)&0xfe)==0 );
188321 ** (in which case **pp will be a terminator bytes POS_END (0) or
188339 if( (**pp)&0xFE ){
188350 ** If parameter iCol is not 0, write an POS_COLUMN (1) byte followed by
188355 ** returning (do not modify it if iCol==0). Return the total number of bytes
188356 ** written (0 if iCol==0).
188359 int n = 0; /* Number of bytes written */
188363 *p = 0x01;
188391 if( iCol1==0 ) return FTS_CORRUPT_VTAB;
188393 else if( *p1==POS_END ) iCol1 = 0x7fffffff;
188394 else iCol1 = 0;
188398 if( iCol2==0 ) return FTS_CORRUPT_VTAB;
188400 else if( *p2==POS_END ) iCol2 = 0x7fffffff;
188401 else iCol2 = 0;
188404 sqlite3_int64 i1 = 0; /* Last position from pp1 */
188405 sqlite3_int64 i2 = 0; /* Last position from pp2 */
188406 sqlite3_int64 iPrev = 0;
188415 ** POS_END (0) or POS_COLUMN (1). The following block merges the two lists
188463 ** 0x02 0x01 0x02 0x03 0x03 0x00
188466 ** byte following the 0x00 terminator of their respective position lists.
188468 ** If isSaveLeft is 0, an entry is added to the output position list for
188487 int iCol1 = 0;
188488 int iCol2 = 0;
188491 assert( isSaveLeft==0 || isExact==0 );
188493 assert_fts3_nc( p!=0 && *p1!=0 && *p2!=0 );
188506 sqlite3_int64 iPrev = 0;
188507 sqlite3_int64 iPos1 = 0;
188508 sqlite3_int64 iPos2 = 0;
188517 if( iPos1<0 || iPos2<0 ) break;
188521 || (isExact==0 && iPos2>iPos1 && iPos2<=iPos1+nToken)
188526 pSave = 0;
188530 if( (*p2&0xFE)==0 ) break;
188533 if( (*p1&0xFE)==0 ) break;
188543 fts3ColumnlistCopy(0, &p1);
188544 fts3ColumnlistCopy(0, &p2);
188545 assert( (*p1&0xFE)==0 && (*p2&0xFE)==0 );
188546 if( 0==*p1 || 0==*p2 ) break;
188555 ** iCol1 and iCol2) so that it points to either the 0x00 that marks the
188556 ** end of the position list, or the 0x01 that precedes the next
188560 fts3ColumnlistCopy(0, &p1);
188561 if( 0==*p1 ) break;
188565 fts3ColumnlistCopy(0, &p2);
188566 if( 0==*p2 ) break;
188572 fts3PoslistCopy(0, &p2);
188573 fts3PoslistCopy(0, &p1);
188577 return 0;
188579 *p++ = 0x00;
188615 fts3PoslistPhraseMerge(&pTmp1, nRight, 0, 0, pp1, pp2);
188619 fts3PoslistPhraseMerge(&pTmp2, nLeft, 1, 0, pp2, pp1);
188627 res = 0;
188648 ** has been reached. In this case *pp is set to 0 and the function returns.
188664 *pp = 0;
188699 if( bDescIdx==0 || *pbFirst==0 ){
188700 assert_fts3_nc( *pbFirst==0 || iVal>=*piPrev );
188706 assert( *pbFirst || *piPrev==0 );
188707 assert_fts3_nc( *pbFirst==0 || iWrite>0 );
188717 ** bDescDoclist is 0 when this macro is invoked, then it returns (i1-i2).
188724 #define DOCID_CMP(i1, i2) ((bDescDoclist?-1:1) * (i1>i2?1:((i1==i2)?0:-1)))
188747 sqlite3_int64 i1 = 0;
188748 sqlite3_int64 i2 = 0;
188749 sqlite3_int64 iPrev = 0;
188756 int bFirstOut = 0;
188758 *paOut = 0;
188759 *pnOut = 0;
188762 ** are delta encoded. If they are in ascending order (bDescDoclist==0),
188794 fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
188795 fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
188799 if( p2 && p1 && iDiff==0 ){
188805 }else if( !p2 || (p1 && iDiff<0) ){
188820 p = aOut = 0;
188823 memset(&aOut[(p-aOut)], 0, FTS3_BUFFER_PADDING);
188848 sqlite3_int64 i1 = 0;
188849 sqlite3_int64 i2 = 0;
188850 sqlite3_int64 iPrev = 0;
188857 int bFirstOut = 0;
188860 assert( nDist>0 );
188863 if( aOut==0 ) return SQLITE_NOMEM;
188869 fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
188870 fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
188874 if( iDiff==0 ){
188880 if( 0==fts3PoslistPhraseMerge(&p, nDist, 0, 1, &p1, &p2) ){
188887 }else if( iDiff<0 ){
188888 fts3PoslistCopy(0, &p1);
188891 fts3PoslistCopy(0, &p2);
188908 ** a token in position 0 (of any column). If so, it writes argument iDelta
188910 ** of the entries from pList at position 0, and terminated by an 0x00 byte.
188915 char *pList, /* Position list (no 0x00 term) */
188919 int nOut = 0;
188920 int bWritten = 0; /* True once iDelta has been written */
188924 if( *p!=0x01 ){
188925 if( *p==0x02 ){
188927 pOut[nOut++] = 0x02;
188930 fts3ColumnlistCopy(0, &p);
188937 if( *p==0x02 ){
188938 if( bWritten==0 ){
188942 pOut[nOut++] = 0x01;
188944 pOut[nOut++] = 0x02;
188946 fts3ColumnlistCopy(0, &p);
188949 pOut[nOut++] = 0x00;
188958 ** doclist stored in TermSelect.aaOutput[0]. If successful, delete all
188959 ** other doclists (except the aaOutput[0] one) and return SQLITE_OK.
188966 char *aOut = 0;
188967 int nOut = 0;
188973 for(i=0; i<SizeofArray(pTS->aaOutput); i++){
188978 pTS->aaOutput[i] = 0;
188993 pTS->aaOutput[i] = 0;
189000 pTS->aaOutput[0] = aOut;
189001 pTS->anOutput[0] = nOut;
189025 if( pTS->aaOutput[0]==0 ){
189042 pTS->aaOutput[0] = sqlite3_malloc64((i64)nDoclist + FTS3_VARINT_MAX + 1);
189043 pTS->anOutput[0] = nDoclist;
189044 if( pTS->aaOutput[0] ){
189045 memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
189046 memset(&pTS->aaOutput[0][nDoclist], 0, FTS3_VARINT_MAX);
189055 for(iOut=0; iOut<SizeofArray(pTS->aaOutput); iOut++){
189056 if( pTS->aaOutput[iOut]==0 ){
189057 assert( iOut>0 );
189075 pTS->aaOutput[iOut] = 0;
189096 if( (pCsr->nSegment%16)==0 ){
189120 int iIndex, /* Index to search (from 0 to p->nIndex-1) */
189129 sqlite3_stmt *pStmt = 0; /* Statement to iterate through segments */
189132 /* If iLevel is less than 0 and this is not a scan, include a seg-reader
189138 if( iLevel<0 && p->aIndex && p->iPrevLangid==iLangid ){
189139 Fts3SegReader *pSeg = 0;
189152 Fts3SegReader *pSeg = 0;
189164 sqlite3_int64 *pi = (isPrefix ? &iLeavesEndBlock : 0);
189167 if( isPrefix==0 && isScan==0 ) iLeavesEndBlock = iStartBlock;
189171 (isPrefix==0 && isScan==0),
189194 int iIndex, /* Index to search (from 0 to p->nIndex-1) */
189202 assert( iIndex>=0 && iIndex<p->nIndex );
189205 || iLevel>=0
189208 assert( FTS3_SEGCURSOR_ALL<0 && FTS3_SEGCURSOR_PENDING<0 );
189209 assert( isPrefix==0 || isScan==0 );
189211 memset(pCsr, 0, sizeof(Fts3MultiSegReader));
189231 iLangid, 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0,pCsr
189246 ** Output parameter *ppSegcsr is set to 0 if an error occurs.
189261 int bFound = 0; /* True once an index has been found */
189265 for(i=1; bFound==0 && i<p->nIndex; i++){
189269 i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0, pSegcsr
189275 for(i=1; bFound==0 && i<p->nIndex; i++){
189279 i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 1, 0, pSegcsr
189290 if( bFound==0 ){
189292 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, isPrefix, 0, pSegcsr
189327 memset(&tsc, 0, sizeof(TermSelect));
189330 | (pTok->isPrefix ? FTS3_SEGMENT_PREFIX : 0)
189331 | (pTok->bFirst ? FTS3_SEGMENT_FIRST : 0)
189332 | (iColumn<p->nColumn ? FTS3_SEGMENT_COLUMN_FILTER : 0);
189348 *ppOut = tsc.aaOutput[0];
189349 *pnOut = tsc.anOutput[0];
189352 for(i=0; i<SizeofArray(tsc.aaOutput); i++){
189358 pTok->pSegcsr = 0;
189372 int nDoc = 0; /* Return value */
189378 while( (*p++)&0x80 ); /* Skip docid varint */
189379 fts3PoslistCopy(0, &p); /* Skip over position list */
189407 pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0);
189414 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
189446 ** number idxNum-FTS3_FULLTEXT_SEARCH, 0 indexed. argv[0] is the right-hand
189462 sqlite3_value *pCons = 0; /* The MATCH or rowid constraint, if any */
189463 sqlite3_value *pLangid = 0; /* The "langid = ?" constraint, if any */
189464 sqlite3_value *pDocidGe = 0; /* The "docid >= ?" constraint, if any */
189465 sqlite3_value *pDocidLe = 0; /* The "docid <= ?" constraint, if any */
189475 eSearch = (idxNum & 0x0000FFFF);
189476 assert( eSearch>=0 && eSearch<=(FTS3_FULLTEXT_SEARCH+p->nColumn) );
189477 assert( p->pSegments==0 );
189480 iIdx = 0;
189495 pCsr->bDesc = (idxStr[0]=='D');
189505 if( zQuery==0 && sqlite3_value_type(pCons)!=SQLITE_NULL ){
189509 pCsr->iLangid = 0;
189512 assert( p->base.zErrMsg==0 );
189525 pCsr->iPrevId = 0;
189548 p->db,zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
189612 assert( iCol>=0 && iCol<=p->nColumn+2 );
189615 case 0:
189617 sqlite3_result_pointer(pCtx, pCsr, "fts3cursor", 0);
189629 }else if( p->zLanguageid==0 ){
189630 sqlite3_result_int(pCtx, 0);
189640 rc = fts3CursorSeek(0, pCsr);
189647 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
189679 ** small - often between 0 and 2. So the overhead of the incremental
189699 && p->nAutoincrmerge && p->nAutoincrmerge!=0xff
189701 int mxLevel = 0; /* Maximum relative level value in db */
189705 assert( rc==SQLITE_OK || mxLevel==0 );
189718 ** to 0 or 1). Return SQLITE_OK if successful, or an SQLite error code
189726 int res = sqlite3_table_column_metadata(p->db, p->zDb, zTbl, 0,0,0,0,0,0);
189743 assert( p->pSegments==0 );
189744 assert( p->nPendingData==0 );
189746 p->nLeafAdd = 0;
189765 assert( p->nPendingData==0 );
189766 assert( p->inTransaction!=0 );
189767 assert( p->pSegments==0 );
189768 TESTONLY( p->inTransaction = 0 );
189780 assert( p->inTransaction!=0 );
189781 TESTONLY( p->inTransaction = 0 );
189794 char c = 0;
189796 /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */
189797 while( p>pStart && (c=*p--)==0 );
189800 ** poslist). This is an 0x00 byte preceded by some byte that does not
189801 ** have the 0x80 bit set. */
189802 while( p>pStart && (*p & 0x80) | c ){
189805 assert( p==pStart || c==0 );
189807 /* At this point p points to that preceding byte without the 0x80 bit
189813 ** The second part of the if condition (c==0 && *ppPoslist>&p[2])
189818 ** 0x0A 0x00 <next docid delta varint>
189820 if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; }
189821 while( *p++&0x80 );
189838 sqlite3_value *pVal, /* argv[0] passed to function */
189843 if( (*ppCsr)!=0 ){
189862 Fts3Cursor *pCsr; /* Cursor handle passed through apVal[0] */
189879 if( fts3FunctionArg(pContext, "snippet", apVal[0], &pCsr) ) return;
189894 }else if( nToken==0 ){
189909 Fts3Cursor *pCsr; /* Cursor handle passed through apVal[0] */
189914 if( fts3FunctionArg(pContext, "offsets", apVal[0], &pCsr) ) return;
189937 Fts3Cursor *pCursor; /* Cursor handle passed through apVal[0] */
189942 if( fts3FunctionArg(pContext, "optimize", apVal[0], &pCursor) ) return;
189969 Fts3Cursor *pCsr; /* Cursor handle passed through apVal[0] */
189971 if( SQLITE_OK==fts3FunctionArg(pContext, "matchinfo", apVal[0], &pCsr) ){
189972 const char *zArg = 0;
190006 for(i=0; i<SizeofArray(aOverload); i++){
190007 if( strcmp(zName, aOverload[i].zName)==0 ){
190013 /* No function of the specified name was found. Return 0. */
190014 return 0;
190038 assert( p->nPendingData==0 );
190045 if( p->zContentTbl==0 ){
190073 p->bIgnoreSavepoint = 0;
190089 if( pTab->bIgnoreSavepoint==0 ){
190090 if( fts3HashCount(&pTab->aIndex[0].hPending)>0 ){
190096 rc = sqlite3_exec(pTab->db, zSql, 0, 0, 0);
190097 pTab->bIgnoreSavepoint = 0;
190149 for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
190150 if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
190152 return 0;
190168 int bOk = 0;
190173 if( rc==SQLITE_ERROR || (rc&0xFF)==SQLITE_CORRUPT ){
190178 }else if( rc==SQLITE_OK && bOk==0 ){
190181 if( *pzErr==0 ) rc = SQLITE_NOMEM;
190225 if( pHash->nRef<=0 ){
190258 Fts3HashWrapper *pHash = 0;
190259 const sqlite3_tokenizer_module *pSimple = 0;
190260 const sqlite3_tokenizer_module *pPorter = 0;
190262 const sqlite3_tokenizer_module *pUnicode = 0;
190266 const sqlite3_tokenizer_module *pIcu = 0;
190291 pHash->nRef = 0;
190382 for(i=0; i<nToken; i++){
190392 assert( pExpr->pPhrase->iDoclistToken==0 );
190422 if( pList==0 ){
190424 p->doclist.aAll = 0;
190425 p->doclist.nAll = 0;
190428 else if( p->iDoclistToken<0 ){
190433 else if( p->doclist.aAll==0 ){
190484 for(iToken=0; rc==SQLITE_OK && iToken<p->nToken; iToken++){
190486 assert( pToken->pDeferred==0 || pToken->pSegcsr==0 );
190489 int nThis = 0;
190490 char *pThis = 0;
190496 assert( pToken->pSegcsr==0 );
190515 char *aPoslist = 0; /* Position list for deferred tokens */
190516 int nPoslist = 0; /* Number of bytes in aPoslist */
190518 char *aFree = (pPhrase->doclist.bFreeList ? pPhrase->doclist.pList : 0);
190520 for(iToken=0; iToken<pPhrase->nToken; iToken++){
190530 if( pList==0 ){
190533 pPhrase->doclist.pList = 0;
190534 pPhrase->doclist.nList = 0;
190537 }else if( aPoslist==0 ){
190546 assert( iPrev>=0 );
190547 fts3PoslistPhraseMerge(&aOut, iToken-iPrev, 0, 1, &p1, &p2);
190551 if( nPoslist==0 ){
190554 pPhrase->doclist.pList = 0;
190555 pPhrase->doclist.nList = 0;
190563 if( iPrev>=0 ){
190565 if( nMaxUndeferred<0 ){
190594 if( fts3PoslistPhraseMerge(&aOut, nDistance, 0, 1, &p1, &p2) ){
190599 pPhrase->doclist.pList = 0;
190600 pPhrase->doclist.nList = 0;
190639 int bHaveIncr = 0;
190642 && p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0
190644 && pTab->bNoIncrDoclist==0
190647 for(i=0; bIncrOk==1 && i<p->nToken; i++){
190649 if( pToken->bFirst || (pToken->pSegcsr!=0 && !pToken->pSegcsr->bLookup) ){
190650 bIncrOk = 0;
190658 for(i=0; rc==SQLITE_OK && i<p->nToken; i++){
190669 p->bIncr = 0;
190672 assert( rc!=SQLITE_OK || p->nToken<1 || p->aToken[0].pSegcsr==0 || p->bIncr );
190682 ** The doclist may be sorted in ascending (parameter bDescIdx==0) or
190697 assert( nDoclist>0 );
190698 assert( *pbEof==0 );
190699 assert_fts3_nc( p || *piDocid==0 );
190702 if( p==0 ){
190703 sqlite3_int64 iDocid = 0;
190704 char *pNext = 0;
190714 fts3PoslistCopy(0, &pDocid);
190715 while( pDocid<pEnd && *pDocid==0 ) pDocid++;
190752 assert( nDoclist>0 );
190753 assert( *pbEof==0 );
190754 assert_fts3_nc( p || *piDocid==0 );
190757 if( p==0 ){
190761 fts3PoslistCopy(0, &p);
190762 while( p<&aDoclist[nDoclist] && *p==0 ) p++;
190789 assert( pDL->aAll!=0 || pIter==0 );
190794 if( pIter==0 || pIter>=(pEnd = pDL->aAll + pDL->nAll) ){
190800 if( pTab->bDescIdx==0 || pDL->pNextDocid==0 ){
190806 fts3PoslistCopy(0, &pIter);
190809 /* pIter now points just past the 0x00 that terminates the position-
190815 while( pIter<pEnd && *pIter==0 ) pIter++;
190819 *pbEof = 0;
190853 assert( p->bIgnore==0 );
190854 assert( pPhrase->aToken[iToken].pSegcsr==0 );
190861 assert( pToken->pDeferred==0 );
190862 assert( pToken->pSegcsr || pPhrase->iDoclistToken>=0 );
190864 assert( p->bIgnore==0 );
190868 if( p->pList==0 ) *pbEof = 1;
190890 ** successfully advanced, *pbEof is set to 0.
190903 u8 bEof = 0;
190910 rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr,
190913 if( pDL->pList==0 ) bEof = 1;
190918 memset(a, 0, sizeof(a));
190922 while( bEof==0 ){
190923 int bMaxSet = 0;
190924 sqlite3_int64 iMax = 0; /* Largest docid for all iterators */
190928 for(i=0; rc==SQLITE_OK && i<p->nToken && bEof==0; i++){
190930 if( a[i].bIgnore==0 && (bMaxSet==0 || DOCID_CMP(iMax, a[i].iDocid)<0) ){
190935 assert( rc!=SQLITE_OK || (p->nToken>=1 && a[p->nToken-1].bIgnore==0) );
190939 for(i=0; i<p->nToken; i++){
190940 while( rc==SQLITE_OK && bEof==0
190941 && a[i].bIgnore==0 && DOCID_CMP(a[i].iDocid, iMax)<0
190944 if( DOCID_CMP(a[i].iDocid, iMax)>0 ){
190946 i = 0;
190952 if( bEof==0 ){
190953 int nList = 0;
190958 memset(&aDoclist[nByte], 0, FTS3_BUFFER_PADDING);
190960 for(i=0; i<(p->nToken-1); i++){
190961 if( a[i].bIgnore==0 ){
190966 int res = fts3PoslistPhraseMerge(&pOut, nDist, 0, 1, &pL, &pR);
190967 if( res==0 ) break;
190994 ** successfully advanced, *pbEof is set to 0.
191045 for(i=0; i<nToken; i++){
191046 if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
191100 for(i=0; *pRc==SQLITE_OK && i<pPhrase->nToken; i++){
191144 if( pCsr->nRowAvg==0 ){
191149 ** Entry 0 of the %_stat table is a blob containing (nCol+1) FTS3
191158 sqlite3_int64 nDoc = 0;
191159 sqlite3_int64 nByte = 0;
191165 a = sqlite3_column_blob(pStmt, 0);
191166 testcase( a==0 ); /* If %_stat.value set to X'' */
191168 pEnd = &a[sqlite3_column_bytes(pStmt, 0)];
191174 if( nDoc==0 || nByte==0 ){
191181 assert( pCsr->nRowAvg>0 );
191210 int nDocSize = 0; /* Number of pages per doc loaded */
191213 int nOvfl = 0; /* Total overflow pages used by doclists */
191214 int nToken = 0; /* Total number of tokens in cluster */
191216 int nMinEst = 0; /* The minimum count for any phrase so far. */
191231 for(ii=0; ii<nTC; ii++){
191237 if( nOvfl==0 || nToken<2 ) return SQLITE_OK;
191241 assert( rc!=SQLITE_OK || nDocSize>0 );
191266 for(ii=0; ii<nToken && rc==SQLITE_OK; ii++){
191268 Fts3TokenAndCost *pTC = 0; /* Set to cheapest remaining token. */
191271 for(iTC=0; iTC<nTC; iTC++){
191288 pToken->pSegcsr = 0;
191295 if( ii==0 || (pTC->pPhrase->nToken>1 && ii!=nToken-1) ){
191300 int nList = 0;
191301 char *pList = 0;
191303 assert( rc==SQLITE_OK || pList==0 );
191314 if( ii==0 || nCount<nMinEst ) nMinEst = nCount;
191318 pTC->pToken = 0;
191339 int nToken = 0;
191340 int nOr = 0;
191362 fts3EvalTokenCosts(pCsr, 0, pCsr->pExpr, &pTC, &ppOr, &rc);
191367 rc = fts3EvalSelectDeferred(pCsr, 0, aTC, nToken);
191368 for(ii=0; rc==SQLITE_OK && ii<nOr; ii++){
191389 pPhrase->doclist.pList = 0;
191390 pPhrase->doclist.nList = 0;
191391 pPhrase->doclist.bFreeList = 0;
191410 ** leaves 0 positions, zero is returned. Otherwise, non-zero.
191438 assert_fts3_nc( nNew<=pPhrase->doclist.nList && nNew>0 );
191439 if( nNew>=0 && nNew<=pPhrase->doclist.nList ){
191440 assert( pPhrase->doclist.pList[nNew]=='\0' );
191441 memset(&pPhrase->doclist.pList[nNew], 0, pPhrase->doclist.nList - nNew);
191462 ** Fts3Expr.iDocid (valid if bEof==0. The docid of the next row)
191497 if( *pRc==SQLITE_OK && pExpr->bEof==0 ){
191526 if( iDiff==0 ) break;
191527 if( iDiff<0 ){
191539 while( *pRc==SQLITE_OK && pRight->bEof==0 ){
191540 memset(pDl->pList, 0, pDl->nList);
191546 while( *pRc==SQLITE_OK && pLeft->bEof==0 ){
191547 memset(pDl->pList, 0, pDl->nList);
191565 if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
191567 }else if( pLeft->bEof || iCmp>0 ){
191576 if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
191589 if( pRight->bStart==0 ){
191595 if( pLeft->bEof==0 ){
191598 && DOCID_CMP(pLeft->iDocid, pRight->iDocid)>0
191631 ** match the current row, 0 is returned. The position lists may or may not
191632 ** be edited if 0 is returned.
191659 && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
191662 sqlite3_int64 nTmp = 0; /* Bytes of temp space */
191667 assert( p->pRight->pPhrase->doclist.nList>0 );
191674 res = 0;
191747 if( bHit==0
191749 && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
191752 for(p=pExpr; p->pPhrase==0; p=p->pLeft){
191788 bHit = (pPhrase->doclist.pList!=0);
191794 pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId
191795 && pExpr->pPhrase->doclist.nList>0
191817 ** returns 0. Otherwise, it tests whether or not after considering NEAR
191827 ** query, return 0.
191831 int bMiss = 0;
191841 rc = fts3CursorSeek(0, pCsr);
191846 bMiss = (0==fts3EvalTestExpr(pCsr, pCsr->pExpr, &rc));
191862 assert( pCsr->isEof==0 );
191863 if( pExpr==0 ){
191867 if( pCsr->isRequireSeek==0 ){
191870 assert( sqlite3_data_count(pCsr->pStmt)==0 );
191876 }while( pCsr->isEof==0 && sqlite3Fts3EvalTestDeferred(pCsr, &rc) );
191882 (pCsr->bDesc==0 && pCsr->iPrevId>pCsr->iMaxDocid)
191883 || (pCsr->bDesc!=0 && pCsr->iPrevId<pCsr->iMinDocid)
191912 for(i=0; i<pPhrase->nToken; i++){
191914 assert( pToken->pDeferred==0 );
191919 *pRc = fts3EvalPhraseStart(pCsr, 0, pPhrase);
191921 pPhrase->doclist.pNextDocid = 0;
191922 pPhrase->doclist.iDocid = 0;
191923 pPhrase->pOrPoslist = 0;
191926 pExpr->iDocid = 0;
191927 pExpr->bEof = 0;
191928 pExpr->bStart = 0;
191947 int iCol = 0;
191951 u8 c = 0;
191952 int iCnt = 0;
191953 while( 0xFE & (*p | c) ){
191954 if( (c&0x80)==0 ) iCnt++;
191955 c = *p++ & 0x80;
191962 pExpr->aMI[iCol*3 + 2] += (iCnt>0);
191963 if( *p==0x00 ) break;
191982 if( pExpr->aMI==0 ){
191984 if( pExpr->aMI==0 ) return SQLITE_NOMEM;
191986 memset(pExpr->aMI, 0, pTab->nColumn * 3 * sizeof(u32));
192008 if( pExpr->aMI==0 ){
192032 while( pCsr->isEof==0 && rc==SQLITE_OK ){
192036 if( pCsr->isRequireSeek==0 ) sqlite3_reset(pCsr->pStmt);
192037 assert( sqlite3_data_count(pCsr->pStmt)==0 );
192045 }while( pCsr->isEof==0
192050 if( rc==SQLITE_OK && pCsr->isEof==0 ){
192055 pCsr->isEof = 0;
192070 assert_fts3_nc( pRoot->bEof==0 );
192118 assert( pCsr->nDoc>0 );
192119 for(iCol=0; iCol<pTab->nColumn; iCol++){
192127 for(iCol=0; iCol<pTab->nColumn; iCol++){
192147 ** compression and is terminated by either an 0x01 or 0x00 byte. For example,
192151 ** 0x04 0x05 0x03 0x01 or 0x04 0x05 0x03 0x00
192170 *ppOut = 0;
192171 assert( iCol>=0 && iCol<pTab->nColumn );
192181 int bOr = 0;
192182 u8 bTreeEof = 0;
192199 if( bOr==0 ) return SQLITE_OK;
192214 if( bEofSave==0 && pRun->iDocid==iDocid ) break;
192216 assert( rc!=SQLITE_OK || pPhrase->bIncr==0 );
192230 u8 bEof = 0;
192243 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
192251 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){
192261 if( bEof || iDocid!=pCsr->iPrevId ) bMatch = 0;
192267 pIter = 0;
192270 if( pIter==0 ) return SQLITE_OK;
192272 if( *pIter==0x01 ){
192276 iThis = 0;
192279 fts3ColumnlistCopy(0, &pIter);
192280 if( *pIter==0x00 ) return SQLITE_OK;
192284 if( *pIter==0x00 ){
192285 pIter = 0;
192288 *ppOut = ((iCol==iThis)?pIter:0);
192304 memset(&pPhrase->doclist, 0, sizeof(Fts3Doclist));
192305 for(i=0; i<pPhrase->nToken; i++){
192307 pPhrase->aToken[i].pSegcsr = 0;
192427 if( nDb==4 && 0==sqlite3_strnicmp("temp", zDb, 4) ){
192445 memset(p, 0, nByte);
192476 for(i=0; i<SizeofArray(pFts3->aStmt); i++){
192506 && pInfo->aOrderBy[0].iColumn==0
192507 && pInfo->aOrderBy[0].desc==0
192514 for(i=0; i<pInfo->nConstraint; i++){
192519 if( iCol==0 ){
192532 if( iEq>=0 ){
192537 pInfo->idxNum = 0;
192539 if( iGe>=0 ){
192544 if( iLe>=0 ){
192550 if( iLangid>=0 ){
192568 memset(pCsr, 0, sizeof(Fts3auxCursor));
192596 if( aNew==0 ) return SQLITE_NOMEM;
192597 memset(&aNew[pCsr->nStat], 0,
192618 if( pCsr->aStat[pCsr->iCol].nDoc>0 ) return SQLITE_OK;
192623 int i = 0;
192628 int eState = 0;
192633 if( mc<0 || (mc==0 && pCsr->csr.nTerm>pCsr->nStop) ){
192640 memset(pCsr->aStat, 0, sizeof(struct Fts3auxColstats) * pCsr->nStat);
192641 iCol = 0;
192645 sqlite3_int64 v = 0;
192649 /* State 0. In this state the integer just read was a docid. */
192650 case 0:
192651 pCsr->aStat[0].nDoc++;
192653 iCol = 0;
192658 ** start of a position list for column 0.
192661 ** integer encountered in state 1 is not 0 or 1, then we need to
192662 ** increment the column 0 "nDoc" count for this term.
192665 assert( iCol==0 );
192673 if( v==0 ){ /* 0x00. Next integer will be a docid. */
192674 eState = 0;
192675 }else if( v==1 ){ /* 0x01. Next integer will be a column number. */
192679 pCsr->aStat[0].nOcc++;
192697 pCsr->iCol = 0;
192717 int isScan = 0;
192718 int iLangVal = 0; /* Language id to query */
192724 int iNext = 0;
192729 assert( idxStr==0 );
192730 assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0
192756 memset(&pCsr->csr, 0, ((u8*)&pCsr[1]) - (u8*)&pCsr->csr);
192761 if( iEq>=0 || iGe>=0 ){
192762 const unsigned char *zStr = sqlite3_value_text(apVal[0]);
192763 assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
192766 if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
192771 if( iLe>=0 ){
192773 if( pCsr->zStop==0 ) return SQLITE_NOMEM;
192777 if( iLangid>=0 ){
192785 if( iLangVal<0 ) iLangVal = 0;
192789 rc = sqlite3Fts3SegReaderCursor(pFts3, iLangVal, 0, FTS3_SEGCURSOR_ALL,
192790 pCsr->filter.zTerm, pCsr->filter.nTerm, 0, isScan, &pCsr->csr
192818 assert( p->isEof==0 );
192820 case 0: /* term */
192867 0, /* iVersion */
192880 0, /* xUpdate */
192881 0, /* xBegin */
192882 0, /* xSync */
192883 0, /* xCommit */
192884 0, /* xRollback */
192885 0, /* xFindFunction */
192886 0, /* xRename */
192887 0, /* xSavepoint */
192888 0, /* xRelease */
192889 0, /* xRollbackTo */
192890 0, /* xShadowName */
192891 0 /* xIntegrity */
192895 rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
192969 SQLITE_API int sqlite3_fts3_enable_parentheses = 0;
192974 # define sqlite3_fts3_enable_parentheses 0
193014 ** is defined to accept an argument of type char, and always returns 0 for
193029 if( pRet ) memset(pRet, 0, nByte);
193041 sqlite3_tokenizer_cursor *pCsr = 0;
193045 assert( rc==SQLITE_OK || pCsr==0 );
193052 pCsr = 0;
193089 Fts3Expr *pRet = 0;
193090 int i = 0;
193093 for(i=0; i<n; i++){
193102 int nToken = 0, iStart = 0, iEnd = 0, iPosition = 0;
193116 pRet->pPhrase->aToken[0].n = nToken;
193117 pRet->pPhrase->aToken[0].z = (char *)&pRet->pPhrase[1];
193118 memcpy(pRet->pPhrase->aToken[0].z, zToken, nToken);
193121 pRet->pPhrase->aToken[0].isPrefix = 1;
193127 && iStart>0 && z[iStart-1]=='-'
193131 }else if( pParse->bFts4 && iStart>0 && z[iStart-1]=='^' ){
193132 pRet->pPhrase->aToken[0].bFirst = 1;
193175 ** to 0.
193185 Fts3Expr *p = 0;
193186 sqlite3_tokenizer_cursor *pCursor = 0;
193187 char *zTemp = 0;
193188 int nTemp = 0;
193191 int nToken = 0;
193216 for(ii=0; rc==SQLITE_OK; ii++){
193218 int nByte = 0, iBegin = 0, iEnd = 0, iPos = 0;
193231 memset(pToken, 0, sizeof(Fts3PhraseToken));
193238 pToken->bFirst = (iBegin>0 && zInput[iBegin-1]=='^');
193244 pCursor = 0;
193249 char *zBuf = 0;
193253 memset(p, 0, (char *)&(((Fts3Phrase *)&p[1])->aToken[0])-(char *)p);
193264 assert( nTemp==0 );
193267 for(jj=0; jj<p->pPhrase->nToken; jj++){
193283 *ppExpr = 0;
193289 ** structure, or set to 0 if the end of the input buffer is reached.
193307 { "OR" , 2, 0, FTSQUERY_OR },
193310 { "NEAR", 4, 0, FTSQUERY_NEAR }
193316 Fts3Expr *pRet = 0;
193321 pParse->isNot = 0;
193326 while( nInput>0 && fts3isspace(*zInput) ){
193330 if( nInput==0 ){
193335 for(ii=0; ii<(int)(sizeof(aKeyword)/sizeof(struct Fts3Keyword)); ii++){
193338 if( (pKey->parenOnly & ~sqlite3_fts3_enable_parentheses)!=0 ){
193342 if( nInput>=pKey->n && 0==memcmp(zInput, pKey->z, pKey->n) ){
193350 if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){
193361 || cNext=='"' || cNext=='(' || cNext==')' || cNext==0
193396 int nConsumed = 0;
193400 #elif SQLITE_MAX_EXPR_DEPTH>0
193409 *ppExpr = 0;
193426 iColLen = 0;
193427 for(ii=0; ii<pParse->nCol; ii++){
193431 && sqlite3_strnicmp(zStr, zInput, nStr)==0
193511 ** bytes read from buffer z. Otherwise, *ppExpr is set to 0 and SQLITE_NOMEM
193520 Fts3Expr *pRet = 0;
193521 Fts3Expr *pPrev = 0;
193522 Fts3Expr *pNotBranch = 0; /* Only used in legacy parse mode */
193529 Fts3Expr *p = 0;
193530 int nByte = 0;
193533 assert( nByte>0 || (rc!=SQLITE_OK && p==0) );
193607 assert( pPrev && pPrev->pLeft && pPrev->pRight==0 );
193620 assert( nByte>0 );
193622 assert( rc!=SQLITE_OK || (nByte>0 && nByte<=nIn) );
193653 pRet = 0;
193666 if( nMaxDepth<0 ){
193692 Fts3Expr *pFree = 0; /* List of free nodes. Linked by pParent. */
193695 if( nMaxDepth==0 ){
193703 if( 0==apLeaf ){
193706 memset(apLeaf, 0, sizeof(Fts3Expr *) * nMaxDepth);
193715 assert( p->pParent==0 || p->pParent->pLeft==p );
193724 assert( pParent==0 || pParent->pLeft==p );
193725 p->pParent = 0;
193727 pParent->pLeft = 0;
193729 pRoot = 0;
193734 for(iLvl=0; p && iLvl<nMaxDepth; iLvl++){
193735 if( apLeaf[iLvl]==0 ){
193737 p = 0;
193747 p->pParent = 0;
193748 apLeaf[iLvl] = 0;
193758 if( pParent==0 ) break;
193764 assert( pParent->pParent==0 || pParent->pParent->pLeft==pParent );
193780 p = 0;
193781 for(i=0; i<nMaxDepth; i++){
193783 if( p==0 ){
193785 p->pParent = 0;
193787 assert( pFree!=0 );
193795 p->pParent = 0;
193805 for(i=0; i<nMaxDepth; i++){
193808 while( (pDel=pFree)!=0 ){
193814 assert( pFree==0 );
193821 pRoot->pLeft = 0;
193822 pRoot->pRight = 0;
193823 pLeft->pParent = 0;
193824 pRight->pParent = 0;
193846 pRoot = 0;
193877 memset(&sParse, 0, sizeof(ParseContext));
193884 if( z==0 ){
193885 *ppExpr = 0;
193888 if( n<0 ){
193892 assert( rc==SQLITE_OK || *ppExpr==0 );
193909 ** error) is returned and *ppExpr is set to 0.
193952 *ppExpr = 0;
193971 assert( p->eType==FTSQUERY_PHRASE || p->pPhrase==0 );
193986 assert( pDel==0 || pDel->pParent==0 );
193988 assert( p->pParent==0 || p==p->pParent->pRight || p==p->pParent->pLeft );
194025 if( pExpr==0 ){
194033 "%zPHRASE %d 0", zBuf, pPhrase->iColumn);
194034 for(i=0; zBuf && i<pPhrase->nToken; i++){
194087 sqlite3_tokenizer *pTokenizer = 0;
194089 char **azCol = 0;
194095 char *zBuf = 0;
194097 const char *zTokenizer = 0;
194098 char *zErr = 0;
194107 zTokenizer = (const char*)sqlite3_value_text(argv[0]);
194127 for(ii=0; ii<nCol; ii++){
194132 char *zDummy = 0;
194134 pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr, &zDummy
194136 assert( rc==SQLITE_OK || pExpr==0 );
194140 pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr
194147 }else if( rc==SQLITE_NOMEM || !(zBuf = exprToString(pExpr, 0)) ){
194168 fts3ExprTestCommon(0, context, argc, argv);
194184 db, "fts3_exprtest", -1, SQLITE_UTF8, (void*)pHash, fts3ExprTest, 0, 0
194188 -1, SQLITE_UTF8, (void*)pHash, fts3ExprTestRebalance, 0, 0
194239 memset(p, 0, n);
194258 assert( pNew!=0 );
194262 pNew->first = 0;
194263 pNew->count = 0;
194264 pNew->htsize = 0;
194265 pNew->ht = 0;
194275 assert( pH!=0 );
194277 pH->first = 0;
194279 pH->ht = 0;
194280 pH->htsize = 0;
194289 pH->count = 0;
194297 unsigned h = 0;
194298 if( nKey<=0 ) nKey = (int) strlen(z);
194299 while( nKey > 0 ){
194303 return (int)(h & 0x7fffffff);
194314 int h = 0;
194316 while( nKey-- > 0 ){
194319 return h & 0x7fffffff;
194380 pNew->prev = 0;
194399 assert( (new_size & (new_size-1))==0 );
194401 if( new_ht==0 ) return 1;
194406 for(elem=pH->first, pH->first=0; elem; elem = next_elem){
194411 return 0;
194434 if( (*xCompare)(elem->pKey,elem->nKey,pKey,nKey)==0 ){
194440 return 0;
194465 if( pEntry->count<=0 ){
194466 pEntry->chain = 0;
194473 if( pH->count<=0 ){
194474 assert( pH->first==0 );
194475 assert( pH->count==0 );
194488 if( pH==0 || pH->ht==0 ) return 0;
194490 assert( xHash!=0 );
194492 assert( (pH->htsize & (pH->htsize-1))==0 );
194505 return pElem ? pElem->data : 0;
194535 assert( pH!=0 );
194537 assert( xHash!=0 );
194539 assert( (pH->htsize & (pH->htsize-1))==0 );
194544 if( data==0 ){
194551 if( data==0 ) return 0;
194552 if( (pH->htsize==0 && fts3Rehash(pH,8))
194555 pH->count = 0;
194558 assert( pH->htsize>0 );
194560 if( new_elem==0 ) return data;
194561 if( pH->copyKey && pKey!=0 ){
194563 if( new_elem->pKey==0 ){
194573 assert( pH->htsize>0 );
194574 assert( (pH->htsize & (pH->htsize-1))==0 );
194578 return 0;
194654 memset(t, 0, sizeof(*t));
194669 ** string to be tokenized is zInput[0..nInput-1]. A cursor
194686 if( zInput==0 ){
194687 c->nInput = 0;
194688 }else if( nInput<0 ){
194693 c->iOffset = 0; /* start tokenizing at the beginning */
194694 c->iToken = 0;
194696 c->nAllocated = 0;
194716 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0,
194737 if( x==0 ) return 0;
194741 return z[1]==0 || isVowel(z + 1);
194746 if( x==0 ) return 0;
194774 if( *z==0 ) return 0;
194776 return *z!=0;
194784 if( *z==0 ) return 0;
194786 if( *z==0 ) return 0;
194788 if( *z==0 ) return 1;
194790 return *z==0;
194794 ** or m>0
194798 if( *z==0 ) return 0;
194800 if( *z==0 ) return 0;
194802 if( *z==0 ) return 0;
194804 return *z!=0;
194808 ** Return TRUE if there is a vowel anywhere within z[0..n-1]
194812 return *z!=0;
194822 return isConsonant(z) && z[0]==z[1];
194836 z[0]!='w' && z[0]!='x' && z[0]!='y' &&
194861 if( *zFrom!=0 ) return 0;
194880 int hasDigit = 0;
194881 for(i=0; i<nIn; i++){
194886 if( c>='0' && c<='9' ) hasDigit = 1;
194897 zOut[i] = 0;
194903 ** Stem the input word zIn[0..nIn-1]. Store the output in zOut.
194905 ** size of the output word (exclusive of the '\0' terminator) into *pnOut.
194935 for(i=0, j=sizeof(zReverse)-6; i<nIn; i++, j--){
194948 memset(&zReverse[sizeof(zReverse)-5], 0, 5);
194953 if( z[0]=='s' ){
194955 !stem(&z, "sess", "ss", 0) &&
194956 !stem(&z, "sei", "i", 0) &&
194957 !stem(&z, "ss", "ss", 0)
194971 if( stem(&z, "ta", "ate", 0) ||
194972 stem(&z, "lb", "ble", 0) ||
194973 stem(&z, "zi", "ize", 0) ){
194983 if( z[0]=='y' && hasVowel(z+1) ){
194984 z[0] = 'i';
195039 switch( z[0] ){
195063 if( z[0]=='l' && m_gt_1(z+2) ){
195068 if( z[0]=='e' && z[2]=='n' && (z[3]=='a' || z[3]=='e') && m_gt_1(z+4) ){
195073 if( z[0]=='r' && m_gt_1(z+2) ){
195078 if( z[0]=='c' && m_gt_1(z+2) ){
195083 if( z[0]=='e' && z[2]=='b' && (z[3]=='a' || z[3]=='i') && m_gt_1(z+4) ){
195088 if( z[0]=='t' ){
195103 if( z[0]=='u' ){
195112 if( z[0]=='m' && z[2]=='i' && m_gt_1(z+3) ){
195122 if( z[0]=='s' && z[2]=='o' && m_gt_1(z+3) ){
195128 if( z[0]=='e' && z[2]=='i' && m_gt_1(z+3) ){
195135 if( z[0]=='e' ){
195144 if( m_gt_1(z) && z[0]=='l' && z[1]=='l' ){
195152 zOut[i] = 0;
195160 ** whose value is greater than 0x80 (any UTF character) can be
195162 ** values of 0x7f or lower.
195166 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
195167 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
195168 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */
195169 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
195170 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
195172 #define isDelim(C) (((ch=C)&0x80)==0 && (ch<0x30 || !porterIdChar[ch-0x30]))
195227 0,
195233 0
195284 ** SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, 1, 0);
195288 int isEnabled = 0;
195319 void *pPtr = 0;
195327 zName = sqlite3_value_text(argv[0]);
195328 nName = sqlite3_value_bytes(argv[0])+1;
195334 if( zName==0 || n!=sizeof(pPtr) ){
195358 if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[0]) ){
195365 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
195366 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
195367 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
195368 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
195369 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
195370 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */
195371 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
195372 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
195374 return (c&0x80 || isFtsIdChar[(int)(c)]);
195379 const char *z2 = 0;
195383 while( z2==0 ){
195386 case '\0': return 0; /* No more tokens here */
195396 while( *z2 && z2[0]!=']' ) z2++;
195422 int n = 0;
195432 if( z==0 ){
195433 assert( n==0 );
195436 z[n] = '\0';
195444 char const **aArg = 0;
195445 int iArg = 0;
195457 z[n] = '\0';
195507 ** "{0 i I 1 dont don't 2 see see 3 how how}"
195517 sqlite3_tokenizer *pTokenizer = 0;
195518 sqlite3_tokenizer_cursor *pCsr = 0;
195520 const char *zErr = 0;
195530 int nToken = 0;
195531 int iStart = 0;
195532 int iEnd = 0;
195533 int iPos = 0;
195543 nName = sqlite3_value_bytes(argv[0]);
195544 zName = (const char *)sqlite3_value_text(argv[0]);
195570 if( sqlite3Fts3OpenTokenizer(pTokenizer, 0, zInput, nInput, &pCsr) ){
195576 Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(iPos));
195577 Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zToken, nToken));
195580 Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zToken, nToken));
195611 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
195634 *pp = 0;
195635 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
195642 if( sqlite3_column_type(pStmt, 0)==SQLITE_BLOB
195643 && sqlite3_column_bytes(pStmt, 0)==sizeof(*pp)
195645 memcpy((void *)pp, sqlite3_column_blob(pStmt, 0), sizeof(*pp));
195692 assert( p2==0 );
195693 assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") );
195736 char *zTest = 0;
195737 char *zTest2 = 0;
195747 rc = sqlite3_create_function(db, zName, 1, any, p, fts3TokenizerFunc, 0, 0);
195750 rc = sqlite3_create_function(db, zName, 2, any, p, fts3TokenizerFunc, 0, 0);
195754 rc = sqlite3_create_function(db, zTest, -1, any, p, testFunc, 0, 0);
195757 rc = sqlite3_create_function(db, zTest2, 0, any, pdb, intTestFunc, 0, 0);
195824 return c<0x80 && t->delim[c];
195827 return (x>='0' && x<='9') || (x>='A' && x<='Z') || (x>='a' && x<='z');
195841 memset(t, 0, sizeof(*t));
195850 for(i=0; i<n; i++){
195853 if( ch>=0x80 ){
195862 for(i=1; i<0x80; i++){
195863 t->delim[i] = !fts3_isalnum(i) ? -1 : 0;
195881 ** string to be tokenized is pInput[0..nBytes-1]. A cursor
195898 if( pInput==0 ){
195899 c->nBytes = 0;
195900 }else if( nBytes<0 ){
195905 c->iOffset = 0; /* start tokenizing at the beginning */
195906 c->iToken = 0;
195908 c->nTokenAllocated = 0;
195964 for(i=0; i<n; i++){
195987 0,
195993 0,
196123 if( argc==0 ){
196124 *pazDequote = 0;
196127 int nByte = 0;
196130 for(i=0; i<argc; i++){
196135 if( azDequote==0 ){
196139 for(i=0; i<argc; i++){
196162 ** argv[0]: module name
196175 Fts3tokTable *pTab = 0;
196176 const sqlite3_tokenizer_module *pMod = 0;
196177 sqlite3_tokenizer *pTok = 0;
196179 char **azDequote = 0;
196193 zModule = azDequote[0];
196198 assert( (rc==SQLITE_OK)==(pMod!=0) );
196200 const char * const *azArg = 0;
196202 rc = pMod->xCreate((nDequote>1 ? nDequote-1 : 0), azArg, &pTok);
196207 if( pTab==0 ){
196213 memset(pTab, 0, sizeof(Fts3tokTable));
196250 for(i=0; i<pInfo->nConstraint; i++){
196252 && pInfo->aConstraint[i].iColumn==0
196263 pInfo->idxNum = 0;
196277 if( pCsr==0 ){
196280 memset(pCsr, 0, sizeof(Fts3tokCursor));
196294 pCsr->pCsr = 0;
196297 pCsr->zInput = 0;
196298 pCsr->zToken = 0;
196299 pCsr->nToken = 0;
196300 pCsr->iStart = 0;
196301 pCsr->iEnd = 0;
196302 pCsr->iPos = 0;
196303 pCsr->iRowid = 0;
196357 const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
196358 int nByte = sqlite3_value_bytes(apVal[0]);
196360 if( pCsr->zInput==0 ){
196363 if( nByte>0 ) memcpy(pCsr->zInput, zByte, nByte);
196364 pCsr->zInput[nByte] = 0;
196381 return (pCsr->zToken==0);
196396 case 0:
196434 0, /* iVersion */
196447 0, /* xUpdate */
196448 0, /* xBegin */
196449 0, /* xSync */
196450 0, /* xCommit */
196451 0, /* xRollback */
196452 0, /* xFindFunction */
196453 0, /* xRename */
196454 0, /* xSavepoint */
196455 0, /* xRelease */
196456 0, /* xRollbackTo */
196457 0, /* xShadowName */
196458 0 /* xIntegrity */
196544 #define FTS_STAT_DOCTOTAL 0
196609 int iIdx; /* Index within level, or 0x7FFFFFFF for PT */
196615 sqlite3_int64 iEndBlock; /* Rowid of final block in segment (or 0) */
196616 sqlite3_int64 iCurrentBlock; /* Current leaf block (or 0) */
196619 int nNode; /* Size of buffer at aNode (or 0) */
196620 int nPopulate; /* If >0, bytes of buffer aNode[] loaded */
196644 #define fts3SegReaderIsPending(p) ((p)->ppNextElem!=0)
196645 #define fts3SegReaderIsRootOnly(p) ((p)->rootOnly!=0)
196704 #define SQL_DELETE_CONTENT 0
196751 ** Otherwise, an SQLite error code is returned and *pp is set to 0.
196765 /* 0 */ "DELETE FROM %Q.'%q_content' WHERE rowid = ?",
196868 assert( eStmt<SizeofArray(azSql) && eStmt>=0 );
196887 assert( rc==SQLITE_OK || pStmt==0 );
196894 for(i=0; rc==SQLITE_OK && i<nParam; i++){
196908 sqlite3_stmt *pStmt = 0; /* Statement requested from fts3SqlStmt() */
196911 rc = fts3SqlStmt(pTab, SQL_SELECT_DOCSIZE, &pStmt, 0);
196915 if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){
196918 pStmt = 0;
196932 sqlite3_stmt *pStmt = 0;
196934 rc = fts3SqlStmt(pTab, SQL_SELECT_STAT, &pStmt, 0);
196938 || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB
196942 pStmt = 0;
197000 if( p->nPendingData==0 ){
197002 rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_LEVEL, &pStmt, 0);
197028 ** for language-id 0 is allocate values 0-1023. The first prefix index
197029 ** (if any) for language-id 0 is allocated values 1024-2047. And so on.
197030 ** Language 1 indexes are allocated immediately following language 0.
197043 assert_fts3_nc( iLangid>=0 );
197044 assert( p->nIndex>0 );
197045 assert( iIndex>=0 && iIndex<p->nIndex );
197062 ** 0: idx
197076 sqlite3_stmt *pStmt = 0;
197078 assert( iLevel==FTS3_SEGCURSOR_ALL || iLevel>=0 );
197080 assert( iIndex>=0 && iIndex<p->nIndex );
197082 if( iLevel<0 ){
197084 rc = fts3SqlStmt(p, SQL_SELECT_LEVEL_RANGE, &pStmt, 0);
197086 sqlite3_bind_int64(pStmt, 1, getAbsoluteLevel(p, iLangid, iIndex, 0));
197093 rc = fts3SqlStmt(p, SQL_SELECT_LEVEL, &pStmt, 0);
197111 ** PendingList *p = 0;
197129 p->nData = 0;
197136 *pp = 0;
197145 p->aData[p->nData] = '\0';
197172 u64 iDelta = (u64)iDocid - (u64)(p ? p->iLastDocid : 0);
197175 assert( p->aData[p->nData]==0 );
197182 p->iLastPos = 0;
197185 if( iCol>0 && p->iLastCol!=iCol ){
197192 p->iLastPos = 0;
197194 if( iCol>=0 ){
197195 assert( iPos>p->iLastPos || (iPos==0 && p->iLastPos==0) );
197208 return 0;
197241 assert( 0==fts3HashFind(pHash, zToken, nToken) );
197267 int iStart = 0;
197268 int iEnd = 0;
197269 int iPos = 0;
197270 int nWord = 0;
197273 int nToken = 0;
197284 ** zText==0. In this case, add zero token entries to the hash table and
197286 if( zText==0 ){
197287 *pnWord = 0;
197306 if( iPos<0 || !zToken || nToken<=0 ){
197313 p, iCol, iPos, &p->aIndex[0].hPending, zToken, nToken
197343 assert( iLangid>=0 );
197344 assert( bDelete==1 || bDelete==0 );
197353 || (iDocid==p->iPrevDocid && p->bPrevDelete==0)
197371 for(i=0; i<p->nIndex; i++){
197380 p->nPendingData = 0;
197400 if( p->abNotindexed[iCol]==0 ){
197417 ** apVal[0] Not used for INSERT.
197474 if( SQLITE_NULL==sqlite3_value_type(apVal[0])
197508 assert( p->zContentTbl==0 || bContent==0 );
197509 if( bContent ) fts3SqlExec(&rc, p, SQL_DELETE_ALL_CONTENT, 0);
197510 fts3SqlExec(&rc, p, SQL_DELETE_ALL_SEGMENTS, 0);
197511 fts3SqlExec(&rc, p, SQL_DELETE_ALL_SEGDIR, 0);
197513 fts3SqlExec(&rc, p, SQL_DELETE_ALL_DOCSIZE, 0);
197516 fts3SqlExec(&rc, p, SQL_DELETE_ALL_STAT, 0);
197525 int iLangid = 0;
197545 assert( *pbFound==0 );
197552 i64 iDocid = sqlite3_column_int64(pSelect, 0);
197556 if( p->abNotindexed[iCol]==0 ){
197585 ** with 0, so the allocated index is one greater than the value returned
197592 ** allocated index is 0.
197606 int iNext = 0; /* Result of query pNextIdx */
197608 assert( iLangid>=0 );
197612 rc = fts3SqlStmt(p, SQL_NEXT_SEGMENT_INDEX, &pNextIdx, 0);
197618 iNext = sqlite3_column_int(pNextIdx, 0);
197626 ** segment and allocate (newly freed) index 0 at level iLevel. Otherwise,
197632 *piIdx = 0;
197683 if( 0==p->zSegmentsTbl ){
197685 if( 0==p->zSegmentsTbl ) return SQLITE_NOMEM;
197688 p->db, p->zDb, p->zSegmentsTbl, "block", iBlockid, 0, &p->pSegments
197704 rc = sqlite3_blob_read(p->pSegments, aByte, nByte, 0);
197705 memset(&aByte[nByte], 0, FTS3_NODE_PADDING);
197708 aByte = 0;
197726 p->pSegments = 0;
197743 memset(&pReader->aNode[pReader->nPopulate], 0, FTS3_NODE_PADDING);
197746 pReader->pBlob = 0;
197747 pReader->nPopulate = 0;
197773 pSeg->pBlob = 0;
197775 pSeg->aNode = 0;
197804 pReader->aNode = 0;
197818 pReader->zTerm[nTerm] = '\0';
197845 (bIncr ? &pReader->nPopulate : 0)
197848 assert( pReader->pBlob==0 );
197851 p->pSegments = 0;
197865 if( nSuffix<=0
197873 ** between 0 and 0x7FFFFFFF. But the sum of the two may cause integer
197893 pReader->pOffsetList = 0;
197896 ** b-tree node. And that the final byte of the doclist is 0x00. If either
197900 || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1])
197901 || pReader->nDoclist==0
197917 u8 bEof = 0;
197918 pReader->iDocid = 0;
197919 pReader->nOffsetList = 0;
197920 sqlite3Fts3DoclistPrev(0,
197952 char c = 0;
197960 u8 bEof = 0;
197965 sqlite3Fts3DoclistPrev(0,
197970 pReader->pOffsetList = 0;
197988 while( *p | c ) c = *p++ & 0x80;
197989 assert( *p==0 );
197991 if( pReader->pBlob==0 || p<&pReader->aNode[pReader->nPopulate] ) break;
198006 while( p<pEnd && *p==0 ) p++;
198014 pReader->pOffsetList = 0;
198039 int nOvfl = 0;
198045 assert( pgsz>0 );
198047 for(ii=0; rc==SQLITE_OK && ii<pMsr->nSegment; ii++){
198055 rc = sqlite3Fts3ReadBlock(p, jj, 0, &nBlob, 0);
198096 int nExtra = 0; /* Bytes to allocate segment root node */
198098 assert( zRoot!=0 || nRoot==0 );
198100 assert( zRoot!=0 || CORRUPT_DB );
198103 if( iStartLeaf==0 ){
198104 if( iEndLeaf!=0 ) return FTS_CORRUPT_VTAB;
198112 memset(pReader, 0, sizeof(Fts3SegReader));
198114 pReader->bLookup = bLookup!=0;
198125 memset(&pReader->aNode[nRoot], 0, FTS3_NODE_PADDING);
198149 if( c==0 ){
198182 Fts3SegReader *pReader = 0; /* Fts3SegReader object to return */
198184 Fts3HashElem **aElem = 0; /* Array of term hash entries to scan */
198185 int nElem = 0; /* Size of array at aElem */
198191 int nAlloc = 0; /* Size of allocated array at aElem */
198196 if( nTerm==0 || (nKey>=nTerm && 0==memcmp(zKey, zTerm, nTerm)) ){
198205 nElem = 0;
198238 if( nElem>0 ){
198245 memset(pReader, 0, nByte);
198246 pReader->iIdx = 0x7FFFFFFF;
198275 if( rc2<0 ){
198280 if( rc==0 ){
198284 rc = (pLhs->aNode==0) - (pRhs->aNode==0);
198286 if( rc==0 ){
198289 assert_fts3_nc( rc!=0 );
198305 int rc = (pLhs->pOffsetList==0)-(pRhs->pOffsetList==0);
198306 if( rc==0 ){
198317 int rc = (pLhs->pOffsetList==0)-(pRhs->pOffsetList==0);
198318 if( rc==0 ){
198333 ** If the pSeg iterator is already at EOF, return 0. Otherwise, return
198334 ** -ve if the pSeg term is less than zTerm/nTerm, 0 if the two terms are
198342 int res = 0;
198349 if( res==0 ){
198373 for(i=nSuspect-1; i>=0; i--){
198377 if( xCmp(apSegment[j], apSegment[j+1])<0 ) break;
198386 for(i=0; i<(nSuspect-1); i++){
198387 assert( xCmp(apSegment[i], apSegment[i+1])<0 );
198402 int rc = fts3SqlStmt(p, SQL_INSERT_SEGMENTS, &pStmt, 0);
198420 int mxLevel = 0;
198421 sqlite3_stmt *pStmt = 0;
198423 rc = fts3SqlStmt(p, SQL_SELECT_MXLEVEL, &pStmt, 0);
198426 mxLevel = sqlite3_column_int(pStmt, 0);
198449 int rc = fts3SqlStmt(p, SQL_INSERT_SEGDIR, &pStmt, 0);
198455 if( nLeafData==0 ){
198476 ** fts3PrefixCompress("abX", 3, "Xbcdef", 6) // returns 0
198485 for(n=0; n<nPrev && n<nNext && zPrev[n]==zNext[n]; n++);
198520 if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
198582 memset(pNew, 0, sizeof(SegmentNode));
198589 if( pTree->pParent==0 ){
198597 pTree->zMalloc = 0;
198689 assert( pRight==0 || p->zMalloc==0 );
198727 memset(pWriter, 0, sizeof(SegmentWriter));
198736 rc = fts3SqlStmt(p, SQL_NEXT_SEGMENTS_ID, &pStmt, 0);
198739 pWriter->iFree = sqlite3_column_int64(pStmt, 0);
198753 if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
198762 if( nData>0 && nData+nReq>p->nNodeSize ){
198787 nData = 0;
198788 pWriter->nTerm = 0;
198790 nPrefix = 0;
198816 assert( nSuffix>0 );
198820 assert( nDoclist>0 );
198840 assert( nTerm>0 );
198864 sqlite3_int64 iLast = 0; /* Largest block id written to database */
198867 int nRoot = 0; /* Size of buffer zRoot */
198882 0, 0, 0, pWriter->nLeafData, pWriter->aData, pWriter->nData);
198916 *pisEmpty = 0;
198922 *pisEmpty = sqlite3_column_int(pStmt, 0);
198946 assert( iIndex>=0 && iIndex<p->nIndex );
198954 rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR_MAX_LEVEL, &pStmt, 0);
198956 sqlite3_bind_int64(pStmt, 1, getAbsoluteLevel(p, iLangid, iIndex, 0));
198961 *pnMax = sqlite3_column_int64(pStmt, 0);
198970 ** iAbsLevel is indeed the largest level, or 0 otherwise, and SQLITE_OK
198983 int rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR_MAX_LEVEL, &pStmt, 0);
198990 *pbMax = 0;
198992 *pbMax = sqlite3_column_type(pStmt, 0)==SQLITE_NULL;
199009 rc = fts3SqlStmt(p, SQL_DELETE_SEGMENTS_RANGE, &pDelete, 0);
199030 ** entries regardless of level if (iLevel<0).
199044 sqlite3_stmt *pDelete = 0; /* SQL statement to delete rows */
199046 for(i=0; rc==SQLITE_OK && i<nReader; i++){
199053 assert( iLevel>=0 || iLevel==FTS3_SEGCURSOR_ALL );
199055 rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_RANGE, &pDelete, 0);
199057 sqlite3_bind_int64(pDelete, 1, getAbsoluteLevel(p, iLangid, iIndex, 0));
199063 rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_LEVEL, &pDelete, 0);
199100 int iCurrent = 0;
199103 assert( iCol>=0 );
199105 char c = 0;
199106 while( p<pEnd && (c | *p)&0xFE ) c = *p++ & 0x80;
199115 if( nList<=0 ){
199122 if( bZero && (pEnd - &pList[nList])>0){
199123 memset(&pList[nList], 0, pEnd - &pList[nList]);
199150 assert( nList>0 );
199152 memset(&pMsr->aBuffer[nList], 0, FTS3_NODE_PADDING);
199169 if( nMerge==0 ){
199170 *paPoslist = 0;
199176 pSeg = pMsr->apSegment[0];
199178 if( pSeg->pOffsetList==0 ){
199179 *paPoslist = 0;
199186 sqlite3_int64 iDocid = apSegment[0]->iDocid;
199188 rc = fts3SegReaderNextDocid(p, apSegment[0], &pList, &nList);
199195 rc = fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
199201 if( nList>0 && fts3SegReaderIsPending(apSegment[0]) ){
199204 assert( (pMsr->aBuffer[nList] & 0xFE)==0x00 );
199208 if( pMsr->iColFilter>=0 ){
199212 if( nList>0 ){
199239 for(i=0; pCsr->bRestart==0 && i<pCsr->nSegment; i++){
199240 int res = 0;
199243 int rc = fts3SegReaderNext(p, pSeg, 0);
199245 }while( zTerm && (res = fts3SegReaderTermCmp(pSeg, zTerm, nTerm))<0 );
199247 if( pSeg->bLookup && res!=0 ){
199279 assert( pCsr->pFilter==0 );
199280 assert( zTerm && nTerm>0 );
199287 for(i=0; i<nSegment; i++){
199296 for(i=0; i<pCsr->nAdvance; i++){
199302 assert( iCol<0 || iCol<p->nColumn );
199323 assert( pCsr->zTerm==0 );
199324 assert( pCsr->nTerm==0 );
199325 assert( pCsr->aDoclist==0 );
199326 assert( pCsr->nDoclist==0 );
199328 pCsr->nAdvance = 0;
199330 for(i=0; i<pCsr->nSegment; i++){
199331 pCsr->apSegment[i]->pOffsetList = 0;
199332 pCsr->apSegment[i]->nOffsetList = 0;
199333 pCsr->apSegment[i]->iDocid = 0;
199373 if( pCsr->nSegment==0 ) return SQLITE_OK;
199382 for(i=0; i<pCsr->nAdvance; i++){
199387 rc = fts3SegReaderNext(p, pSeg, 0);
199392 pCsr->nAdvance = 0;
199396 if( apSegment[0]->aNode==0 ) break;
199398 pCsr->nTerm = apSegment[0]->nTerm;
199399 pCsr->zTerm = apSegment[0]->zTerm;
199401 /* If this is a prefix-search, and if the term that apSegment[0] points
199406 ** of segment apSegment[0] is not a match, exit early.
199421 && 0==memcmp(pCsr->zTerm, apSegment[nMerge]->zTerm, pCsr->nTerm)
199430 && (p->bDescIdx==0 || fts3SegReaderIsPending(apSegment[0])==0)
199432 pCsr->nDoclist = apSegment[0]->nDoclist;
199433 if( fts3SegReaderIsPending(apSegment[0]) ){
199434 rc = fts3MsrBufferData(pCsr, apSegment[0]->aDoclist,
199438 pCsr->aDoclist = apSegment[0]->aDoclist;
199442 int nDoclist = 0; /* Size of doclist */
199443 sqlite3_int64 iPrev = 0; /* Previous docid stored in doclist */
199449 for(i=0; i<nMerge; i++){
199453 while( apSegment[0]->pOffsetList ){
199455 char *pList = 0;
199456 int nList = 0;
199458 sqlite3_int64 iDocid = apSegment[0]->iDocid;
199459 fts3SegReaderNextDocid(p, apSegment[0], &pList, &nList);
199465 fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
199470 fts3ColumnFilter(pFilter->iCol, 0, &pList, &nList);
199473 if( !isIgnoreEmpty || nList>0 ){
199478 if( p->bDescIdx && nDoclist>0 ){
199482 if( nDoclist>0 && iPrev>=iDocid ) return FTS_CORRUPT_VTAB;
199486 nByte = sqlite3Fts3VarintLen(iDelta) + (isRequirePos?nList+1:0);
199507 pCsr->aBuffer[nDoclist++] = '\0';
199514 if( nDoclist>0 ){
199517 memset(&pCsr->aBuffer[nDoclist], 0, FTS3_NODE_PADDING);
199535 for(i=0; i<pCsr->nSegment; i++){
199541 pCsr->nSegment = 0;
199542 pCsr->apSegment = 0;
199543 pCsr->aBuffer = 0;
199553 ** by one or more space (0x20) characters. In the first case, set *piEndBlock
199567 u64 iVal = 0;
199568 for(i=0; zText[i]>='0' && zText[i]<='9'; i++){
199569 iVal = iVal*10 + (zText[i] - '0');
199573 iVal = 0;
199578 for(/* no-op */; zText[i]>='0' && zText[i]<='9'; i++){
199579 iVal = iVal*10 + (zText[i] - '0');
199598 rc = fts3SqlStmt(p, SQL_SELECT_LEVEL_RANGE2, &pRange, 0);
199601 int bOk = 0;
199613 i64 nSize = 0, dummy;
199615 if( nSize<=0 || nSize>nLimit ){
199616 /* If nSize==0, then the %_segdir.end_block field does not not
199621 bOk = 0;
199629 int iIdx = 0;
199630 sqlite3_stmt *pUpdate1 = 0;
199631 sqlite3_stmt *pUpdate2 = 0;
199634 rc = fts3SqlStmt(p, SQL_UPDATE_LEVEL_IDX, &pUpdate1, 0);
199637 rc = fts3SqlStmt(p, SQL_UPDATE_LEVEL, &pUpdate2, 0);
199644 ** updated it to set (level = -1) and (idx = N), where N is 0 for the
199654 sqlite3_bind_int(pUpdate1, 2, sqlite3_column_int(pRange, 0));
199683 ** iLevel+1 segment. Or, if iLevel<0, merge all segments into a
199687 ** If this function is called with iLevel<0, but there is only one
199699 int iIdx = 0; /* Index of new segment */
199700 sqlite3_int64 iNewLevel = 0; /* Level/index to create new segment at */
199701 SegmentWriter *pWriter = 0; /* Used to write the new, merged, segment */
199704 int bIgnoreEmpty = 0; /* True to ignore empty segments */
199705 i64 iMaxLevel = 0; /* Max level number for this index/langid */
199709 || iLevel>=0
199712 assert( iIndex>=0 && iIndex<p->nIndex );
199714 rc = sqlite3Fts3SegReaderCursor(p, iLangid, iIndex, iLevel, 0, 0, 1, 0, &csr);
199715 if( rc!=SQLITE_OK || csr.nSegment==0 ) goto finished;
199726 ** index. The idx of the new segment is always 0. */
199727 if( csr.nSegment==1 && 0==fts3SegReaderIsPending(csr.apSegment[0]) ){
199746 assert( csr.nSegment>0 );
199747 assert_fts3_nc( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
199752 memset(&filter, 0, sizeof(Fts3SegFilter));
199754 filter.flags |= (bIgnoreEmpty ? FTS3_SEGMENT_IGNORE_EMPTY : 0);
199789 ** Flush the contents of pendingTerms to level 0 segments.
199795 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
199804 && p->nAutoincrmerge==0xff && p->nLeafAdd>0
199806 sqlite3_stmt *pStmt = 0;
199807 rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pStmt, 0);
199812 p->nAutoincrmerge = sqlite3_column_int(pStmt, 0);
199815 p->nAutoincrmerge = 0;
199837 for(i=j=0; i<N; i++){
199852 int i = 0;
199853 if( nBuf && (zBuf[nBuf-1]&0x80)==0 ){
199855 for(i=j=0; i<N && j<nBuf; i++){
199858 a[i] = (u32)(x & 0xffffffff);
199861 while( i<N ) a[i++] = 0;
199881 if( pBlob==0 ){
199886 rc = fts3SqlStmt(p, SQL_REPLACE_DOCSIZE, &pStmt, 0);
199899 ** Record 0 of the %_stat table contains a blob consisting of N varints,
199904 ** Varint 0: Total number of rows in the table.
199931 if( a==0 ){
199936 rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pStmt, 0);
199945 sqlite3_column_blob(pStmt, 0),
199946 sqlite3_column_bytes(pStmt, 0));
199948 memset(a, 0, sizeof(u32)*(nStat) );
199956 if( nChng<0 && a[0]<(u32)(-nChng) ){
199957 a[0] = 0;
199959 a[0] += nChng;
199961 for(i=0; i<p->nColumn+1; i++){
199964 x = 0;
199971 rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0);
199990 int bSeenDone = 0;
199992 sqlite3_stmt *pAllLangid = 0;
199996 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
200004 int iLangid = sqlite3_column_int(pAllLangid, 0);
200005 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
200035 rc = fts3DeleteAll(p, 0);
200037 u32 *aSz = 0;
200038 u32 *aSzIns = 0;
200039 u32 *aSzDel = 0;
200040 sqlite3_stmt *pStmt = 0;
200041 int nEntry = 0;
200048 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
200055 if( aSz==0 ){
200058 memset(aSz, 0, nByte);
200067 rc = fts3PendingTermsDocid(p, 0, iLangid, sqlite3_column_int64(pStmt, 0));
200068 memset(aSz, 0, sizeof(aSz[0]) * (p->nColumn+1));
200069 for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
200070 if( p->abNotindexed[iCol]==0 ){
200081 pStmt = 0;
200084 for(iCol=0; iCol<=p->nColumn; iCol++){
200109 ** the oldest nSeg segments (idx=0 through idx=(nSeg-1)) in absolute
200119 sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */
200123 memset(pCsr, 0, sizeof(*pCsr));
200127 if( pCsr->apSegment==0 ){
200130 memset(pCsr->apSegment, 0, nByte);
200131 rc = fts3SqlStmt(p, SQL_SELECT_LEVEL, &pStmt, 0);
200137 assert( pCsr->nSegment==0 );
200138 for(i=0; rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW && i<nSeg; i++){
200139 rc = sqlite3Fts3SegReaderNew(i, 0,
200195 u8 bNoLeafData; /* If true, store 0 for segment size */
200252 int bFirst = (p->term.n==0); /* True for first term on the node */
200253 int nPrefix = 0; /* Bytes to copy from previous term */
200254 int nSuffix = 0; /* Bytes to append to the prefix */
200258 if( p->iChild && bFirst==0 ) p->iChild++;
200261 p->aNode = 0;
200263 if( bFirst==0 ){
200268 if( nPrefix>p->term.n || nSuffix>p->nNode-p->iOff || nSuffix==0 ){
200272 if( rc==SQLITE_OK && ALWAYS(p->term.a!=0) ){
200276 if( p->iChild==0 ){
200306 memset(p, 0, sizeof(NodeReader));
200311 if( aNode && aNode[0] ){
200329 ** (pWriter->aNodeWriter[0].iBlock) when this function is called.
200337 sqlite3_int64 iPtr = pWriter->aNodeWriter[0].iBlock;
200340 assert( nTerm>0 );
200342 sqlite3_int64 iNextPtr = 0;
200355 if(nSuffix<=0 ) return FTS_CORRUPT_VTAB;
200359 if( pNode->key.n==0 || (pNode->block.n + nSpace)<=p->nNodeSize ){
200365 if( pBlk->n==0 ){
200368 pBlk->a[0] = (char)iLayer;
200381 assert( nPrefix>=0 );
200395 pNode->block.a[0] = (char)iLayer;
200400 pNode->key.n = 0;
200403 if( rc!=SQLITE_OK || iNextPtr==0 ) return rc;
200407 assert( 0 );
200408 return 0;
200416 ** A node header is a single 0x00 byte for a leaf node, or a height varint
200421 ** node, both aDoclist and nDoclist must be passed 0.
200444 int bFirst = (pPrev->n==0); /* True if this is the first term written */
200450 assert( pNode->n>0 );
200451 assert_fts3_nc( (pNode->a[0]=='\0')==(aDoclist!=0) );
200455 assert( pPrev!=0 );
200456 assert( pPrev->a!=0 );
200460 if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
200464 if( bFirst==0 ){
200503 pLeaf = &pWriter->aNodeWriter[0];
200506 if(nSuffix<=0 ) return FTS_CORRUPT_VTAB;
200516 if( pLeaf->block.n>0
200541 pLeaf->key.n = 0;
200542 pLeaf->block.n = 0;
200553 if( pLeaf->block.n==0 ){
200555 pLeaf->block.a[0] = '\0';
200590 ** will be set to 0. If the root node is the parent of the leaves, iRoot
200592 for(iRoot=FTS_MAX_APPENDABLE_HEIGHT-1; iRoot>=0; iRoot--){
200594 if( pNode->block.n>0 ) break;
200595 assert( *pRc || pNode->block.nAlloc==0 );
200596 assert( *pRc || pNode->key.nAlloc==0 );
200602 if( iRoot<0 ) return;
200610 ** segments that fit entirely on the root node with start_block!=0.
200619 if( iRoot==0 ){
200623 pBlock->a[0] = 0x01;
200625 &pBlock->a[1], pWriter->aNodeWriter[0].iBlock
200633 for(i=0; i<iRoot; i++){
200635 if( pNode->block.n>0 && rc==SQLITE_OK ){
200648 pWriter->aNodeWriter[0].iBlock, /* leaves_end_block */
200650 (pWriter->bNoLeafData==0 ? pWriter->nLeafData : 0), /* end_block */
200665 ** Return -ve if zLhs is smaller than zRhs, 0 if it is equal, or +ve
200678 res = 0;
200680 if( res==0 ) res = nLhs - nRhs;
200689 ** returning. Otherwise, set *pbRes to 0.
200699 int bRes = 0; /* Result to set *pbRes to */
200700 sqlite3_stmt *pCheck = 0; /* Statement to query database with */
200703 rc = fts3SqlStmt(p, SQL_SEGMENT_IS_APPENDABLE, &pCheck, 0);
200738 sqlite3_stmt *pSelect = 0; /* SELECT to read %_segdir entry */
200740 rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR, &pSelect, 0);
200742 sqlite3_int64 iStart = 0; /* Value of %_segdir.start_block */
200743 sqlite3_int64 iLeafEnd = 0; /* Value of %_segdir.leaves_end_block */
200744 sqlite3_int64 iEnd = 0; /* Value of %_segdir.end_block */
200745 const char *aRoot = 0; /* Pointer to %_segdir.root buffer */
200746 int nRoot = 0; /* Size of aRoot[] in bytes */
200748 int bAppendable = 0; /* Set to true if segment is appendable */
200757 if( pWriter->nLeafData<0 ){
200760 pWriter->bNoLeafData = (pWriter->nLeafData==0);
200763 if( aRoot==0 ){
200776 char *aLeaf = 0;
200777 int nLeaf = 0;
200779 rc = sqlite3Fts3ReadBlock(p, iLeafEnd, &aLeaf, &nLeaf, 0);
200788 if( fts3TermCmp(zKey, nKey, reader.term.a, reader.term.n)<=0 ){
200789 bAppendable = 0;
200800 int nHeight = (int)aRoot[0];
200825 memset(&pNode->block.a[nRoot], 0, FTS3_NODE_PADDING);
200828 for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){
200830 memset(&reader, 0, sizeof(reader));
200838 assert_fts3_nc( reader.term.n>0 || reader.aNode==0 );
200839 if( reader.term.n>0 ){
200843 if( i>0 ){
200844 char *aBlock = 0;
200845 int nBlock = 0;
200848 rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock,0);
200855 memset(&pNode->block.a[nBlock], 0, FTS3_NODE_PADDING);
200887 sqlite3_stmt *pOutputIdx = 0; /* SQL used to find output index */
200889 rc = fts3SqlStmt(p, SQL_NEXT_SEGMENT_INDEX, &pOutputIdx, 0);
200893 *piIdx = sqlite3_column_int(pOutputIdx, 0);
200935 int nLeafEst = 0; /* Blocks allocated for leaf nodes */
200936 sqlite3_stmt *pLeafEst = 0; /* SQL used to determine nLeafEst */
200937 sqlite3_stmt *pFirstBlock = 0; /* SQL used to determine first block */
200940 rc = fts3SqlStmt(p, SQL_MAX_LEAF_NODE_ESTIMATE, &pLeafEst, 0);
200945 nLeafEst = sqlite3_column_int(pLeafEst, 0);
200952 rc = fts3SqlStmt(p, SQL_NEXT_SEGMENTS_ID, &pFirstBlock, 0);
200955 pWriter->iStart = sqlite3_column_int64(pFirstBlock, 0);
200966 rc = fts3WriteSegment(p, pWriter->iEnd, 0, 0);
200974 for(i=0; i<FTS_MAX_APPENDABLE_HEIGHT; i++){
200997 sqlite3_stmt *pDelete = 0; /* DELETE statement */
200999 rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_ENTRY, &pDelete, 0);
201013 ** the idx values are a contiguous sequence starting from 0.
201020 int *aIdx = 0; /* Array of remaining idx values */
201021 int nIdx = 0; /* Valid entries in aIdx[] */
201022 int nAlloc = 0; /* Allocated size of aIdx[] */
201024 sqlite3_stmt *pSelect = 0; /* Select statement to read idx values */
201025 sqlite3_stmt *pUpdate = 0; /* Update statement to modify idx values */
201027 rc = fts3SqlStmt(p, SQL_SELECT_INDEXES, &pSelect, 0);
201042 aIdx[nIdx++] = sqlite3_column_int(pSelect, 0);
201049 rc = fts3SqlStmt(p, SQL_SHIFT_SEGDIR_ENTRY, &pUpdate, 0);
201055 assert( p->bIgnoreSavepoint==0 );
201057 for(i=0; rc==SQLITE_OK && i<nIdx; i++){
201065 p->bIgnoreSavepoint = 0;
201072 pNode->a[0] = (char)iHeight;
201099 Blob prev = {0, 0, 0}; /* Previous term written to new node */
201104 bLeaf = aNode[0]=='\0';
201109 pNew->n = 0;
201116 if( pNew->n==0 ){
201118 if( res<0 || (bLeaf==0 && res==0) ) continue;
201119 fts3StartNode(pNew, (int)aNode[0], reader.iChild);
201128 if( pNew->n==0 ){
201129 fts3StartNode(pNew, (int)aNode[0], reader.iChild);
201156 Blob root = {0,0,0}; /* New root page image */
201157 Blob block = {0,0,0}; /* Buffer used for any other block */
201158 sqlite3_int64 iBlock = 0; /* Block id */
201159 sqlite3_int64 iNewStart = 0; /* New value for iStartBlock */
201160 sqlite3_int64 iOldStart = 0; /* Old value for iStartBlock */
201161 sqlite3_stmt *pFetch = 0; /* Statement used to fetch segdir */
201163 rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR, &pFetch, 0);
201179 char *aBlock = 0;
201180 int nBlock = 0;
201183 rc = sqlite3Fts3ReadBlock(p, iBlock, &aBlock, &nBlock, 0);
201195 sqlite3_stmt *pDel = 0;
201196 rc = fts3SqlStmt(p, SQL_DELETE_SEGMENTS_RANGE, &pDel, 0);
201206 sqlite3_stmt *pChomp = 0;
201207 rc = fts3SqlStmt(p, SQL_CHOMP_SEGDIR, &pChomp, 0);
201241 int nRem = 0;
201244 for(i=pCsr->nSegment-1; i>=0 && rc==SQLITE_OK; i--){
201245 Fts3SegReader *pSeg = 0;
201250 for(j=0; ALWAYS(j<pCsr->nSegment); j++){
201256 if( pSeg->aNode==0 ){
201262 *pnRem = 0;
201286 sqlite3_stmt *pReplace = 0;
201289 rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pReplace, 0);
201310 sqlite3_stmt *pSelect = 0;
201313 pHint->n = 0;
201314 rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pSelect, 0);
201319 const char *aHint = sqlite3_column_blob(pSelect, 0);
201320 int nHint = sqlite3_column_bytes(pSelect, 0);
201324 if( ALWAYS(pHint->a!=0) ) memcpy(pHint->a, aHint, nHint);
201371 if( (pHint->a[i] & 0x80) ) return FTS_CORRUPT_VTAB;
201372 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
201373 if( i==0 ) return FTS_CORRUPT_VTAB;
201375 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
201402 int nSeg = 0; /* Number of input segments */
201403 sqlite3_int64 iAbsLevel = 0; /* Absolute level number to work on */
201404 Blob hint = {0, 0, 0}; /* Hint read from %_stat table */
201405 int bDirtyHint = 0; /* True if blob 'hint' has been modified */
201415 while( rc==SQLITE_OK && nRem>0 ){
201417 sqlite3_stmt *pFindLevel = 0; /* SQL used to determine iAbsLevel */
201418 int bUseHint = 0; /* True if attempting to append */
201419 int iIdx = 0; /* Largest idx in level (iAbsLevel+1) */
201427 rc = fts3SqlStmt(p, SQL_FIND_MERGE_LEVEL, &pFindLevel, 0);
201430 iAbsLevel = sqlite3_column_int64(pFindLevel, 0);
201445 sqlite3_int64 iHintAbsLevel = 0; /* Hint level */
201446 int nHintSeg = 0; /* Hint number of segments */
201449 if( nSeg<0 || (iAbsLevel % nMod) >= (iHintAbsLevel % nMod) ){
201470 if( nSeg<=0 ) break;
201472 assert( nMod<=0x7FFFFFFF );
201473 if( iAbsLevel<0 || iAbsLevel>(nMod<<32) ){
201484 memset(pWriter, 0, nAlloc);
201489 assert( bUseHint==1 || bUseHint==0 );
201490 if( iIdx==0 || (bUseHint && iIdx==1) ){
201491 int bIgnore = 0;
201505 int bEmpty = 0;
201513 if( bUseHint && iIdx>0 ){
201523 if( bEmpty==0 ){
201535 if( nSeg!=0 ){
201542 if( nSeg!=0 ){
201546 if( nSeg==0 && pWriter->bNoLeafData==0 ){
201574 int i = 0;
201575 while( (*z)>='0' && (*z)<='9' && i<214748363 ) i = 10*i + *(z++) - '0';
201595 int nMerge = 0;
201603 if( z[0]==',' && z[1]!='\0' ){
201608 if( z[0]!='\0' || nMin<2 ){
201613 assert( p->bFts4==0 );
201629 ** where X is an integer. X==0 means to turn automerge off. X!=0 means
201637 sqlite3_stmt *pStmt = 0;
201643 assert( p->bFts4==0 );
201647 rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0);
201664 int iIndex, /* Index (0..Fts3Table.nIndex-1) */
201676 for(i=0; i<nTerm; i++) ret += (ret<<3) + zTerm[i];
201693 int iIndex, /* Index to cksum (0..p->nIndex-1) */
201699 u64 cksum = 0;
201701 if( *pRc ) return 0;
201703 memset(&filter, 0, sizeof(filter));
201704 memset(&csr, 0, sizeof(csr));
201709 p, iLangid, iIndex, FTS3_SEGCURSOR_ALL, 0, 0, 0, 1,&csr
201720 i64 iDocid = 0;
201721 i64 iCol = 0;
201722 u64 iPos = 0;
201726 u64 iVal = 0;
201729 if( iVal==0 || iVal==1 ){
201730 iCol = 0;
201731 iPos = 0;
201770 u64 cksum1 = 0; /* Checksum based on FTS index contents */
201771 u64 cksum2 = 0; /* Checksum based on %_content contents */
201772 sqlite3_stmt *pAllLangid = 0; /* Statement to return all language-ids */
201775 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
201781 int iLangid = sqlite3_column_int(pAllLangid, 0);
201783 for(i=0; i<p->nIndex; i++){
201794 sqlite3_stmt *pStmt = 0;
201801 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
201806 i64 iDocid = sqlite3_column_int64(pStmt, 0);
201810 for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
201811 if( p->abNotindexed[iCol]==0 ){
201813 sqlite3_tokenizer_cursor *pT = 0;
201818 int nToken = 0; /* Number of bytes in token */
201819 int iDum1 = 0, iDum2 = 0; /* Dummy variables */
201820 int iPos = 0; /* Position of token in zText */
201826 zToken, nToken, iLang, 0, iDocid, iCol, iPos
201848 *pbOk = 0;
201867 ** + The index number (0 for the main index, 1 for the first prefix
201890 int bOk = 0;
201892 if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB;
201911 }else if( nVal==8 && 0==sqlite3_strnicmp(zVal, "optimize", 8) ){
201912 rc = fts3DoOptimize(p, 0);
201913 }else if( nVal==7 && 0==sqlite3_strnicmp(zVal, "rebuild", 7) ){
201915 }else if( nVal==15 && 0==sqlite3_strnicmp(zVal, "integrity-check", 15) ){
201917 }else if( nVal>6 && 0==sqlite3_strnicmp(zVal, "merge=", 6) ){
201919 }else if( nVal>10 && 0==sqlite3_strnicmp(zVal, "automerge=", 10) ){
201921 }else if( nVal==5 && 0==sqlite3_strnicmp(zVal, "flush", 5) ){
201927 if( nVal>9 && 0==sqlite3_strnicmp(zVal, "nodesize=", 9) ){
201931 }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 9) ){
201935 }else if( nVal>21 && 0==sqlite3_strnicmp(zVal,"test-no-incr-doclist=",21) ){
201938 }else if( nVal>11 && 0==sqlite3_strnicmp(zVal,"mergecount=",11) ){
201940 if( v>=4 && v<=FTS3_MERGE_COUNT && (v&1)==0 ) p->nMergeCount = v;
201957 pDef->pList = 0;
201973 pCsr->pDeferred = 0;
201995 assert( pCsr->isRequireSeek==0 );
201996 iDocid = sqlite3_column_int64(pCsr->pStmt, 0);
201998 for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){
201999 if( p->abNotindexed[i]==0 ){
202001 sqlite3_tokenizer_cursor *pTC = 0;
202006 int nToken = 0; /* Number of bytes in token */
202007 int iDum1 = 0, iDum2 = 0; /* Dummy variables */
202008 int iPos = 0; /* Position of token in zText */
202014 && (pPT->bFirst==0 || iPos==0)
202016 && (0==memcmp(zToken, pPT->z, pPT->n))
202029 rc = fts3PendingListAppendVarint(&pDef->pList, 0);
202046 *ppData = 0;
202047 *pnData = 0;
202049 if( p->pList==0 ){
202077 memset(pDeferred, 0, sizeof(*pDeferred));
202083 assert( pToken->pDeferred==0 );
202102 int bFound = 0; /* True if *pRowid really is in the table */
202106 int isEmpty = 0; /* Deleting *pRowid leaves the table empty */
202114 *pnChng = 0;
202115 memset(aSzDel, 0, sizeof(u32) * (p->nColumn+1) * 2);
202118 if( p->zContentTbl==0 ){
202152 u32 *aSzIns = 0; /* Sizes of inserted documents */
202153 u32 *aSzDel = 0; /* Sizes of deleted documents */
202154 int nChng = 0; /* Net change in number of documents */
202155 int bInsertDone = 0;
202159 assert( p->bHasStat==0 || p->bHasStat==1 );
202161 assert( p->pSegments==0 );
202172 && sqlite3_value_type(apVal[0])==SQLITE_NULL
202179 if( nArg>1 && sqlite3_value_int(apVal[2 + p->nColumn + 2])<0 ){
202185 aSzDel = sqlite3_malloc64(sizeof(aSzDel[0])*((sqlite3_int64)p->nColumn+1)*2);
202186 if( aSzDel==0 ){
202191 memset(aSzDel, 0, sizeof(aSzDel[0])*(p->nColumn+1)*2);
202205 if( nArg>1 && p->zContentTbl==0 ){
202213 sqlite3_value_type(apVal[0])==SQLITE_NULL
202214 || sqlite3_value_int64(apVal[0])!=sqlite3_value_int64(pNewRowid)
202246 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
202247 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER );
202248 rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel);
202254 if( bInsertDone==0 ){
202256 if( rc==SQLITE_CONSTRAINT && p->zContentTbl==0 ){
202261 rc = fts3PendingTermsDocid(p, 0, iLangid, *pRowid);
202290 rc = sqlite3_exec(p->db, "SAVEPOINT fts3", 0, 0, 0);
202294 int rc2 = sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
202297 sqlite3_exec(p->db, "ROLLBACK TO fts3", 0, 0, 0);
202298 sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
202451 pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
202452 pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
202457 pRet->aRef[0] = 1;
202470 pBuf->aRef[1] = 0;
202472 pBuf->aRef[2] = 0;
202475 if( pBuf->aRef[0]==0 && pBuf->aRef[1]==0 && pBuf->aRef[2]==0 ){
202481 void (*xRet)(void*) = 0;
202482 u32 *aOut = 0;
202484 if( p->aRef[1]==0 ){
202489 else if( p->aRef[2]==0 ){
202515 assert( p->aRef[0]==1 );
202516 p->aRef[0] = 0;
202517 if( p->aRef[0]==0 && p->aRef[1]==0 && p->aRef[2]==0 ){
202594 int iPhrase = 0; /* Variable used as the phrase counter */
202632 LoadDoclistCtx sCtx = {0,0,0}; /* Context for sqlite3Fts3ExprIterate() */
202646 int nPhrase = 0;
202662 if( 0==(*pIter & 0xFE) ){
202664 pIter = 0;
202681 if( pIter->iCurrent<0 ){
202683 ** candidate always starts at offset 0 (even if this candidate has a
202686 pIter->iCurrent = 0;
202691 for(i=0; i<pIter->nPhrase; i++){
202697 int iEnd = 0x7FFFFFFF;
202699 for(i=0; i<pIter->nPhrase; i++){
202705 if( iEnd==0x7FFFFFFF ){
202710 for(i=0; i<pIter->nPhrase; i++){
202717 return 0;
202733 int iScore = 0; /* Score of this snippet */
202735 u64 mCover = 0; /* Mask of phrases covered by this snippet */
202736 u64 mHighlight = 0; /* Mask of tokens to highlight in snippet */
202738 for(i=0; i<pIter->nPhrase; i++){
202749 assert( i>=0 );
202757 for(j=0; j<pPhrase->nToken && j<pIter->nSnippet; j++){
202761 if( 0==(*pCsr & 0x0FE) ) break;
202787 assert( rc==SQLITE_OK || pCsr==0 );
202789 i64 iFirst = 0;
202792 if( iFirst<0 ){
202802 pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0
202840 memset(&sIter, 0, sizeof(sIter));
202845 rc = fts3ExprLoadDoclists(pCsr, &nList, 0);
202873 for(i=0; i<nList; i++){
202889 assert( iScore>=0 );
202916 if( nAppend<0 ){
202933 assert( pStr->z!=0 && (pStr->nAlloc >= pStr->n+nAppend+1) );
202938 pStr->z[pStr->n] = '\0';
202979 for(nLeft=0; !(hlmask & ((u64)1 << nLeft)); nLeft++);
202980 for(nRight=0; !(hlmask & ((u64)1 << (nSnippet-1-nRight))); nRight++);
202981 assert( (nSnippet-1-nRight)<=63 && (nSnippet-1-nRight)>=0 );
202991 if( nDesired>0 ){
202993 int iCurrent = 0; /* Token counter */
203007 const char *ZDUMMY; int DUMMY1 = 0, DUMMY2 = 0, DUMMY3 = 0;
203015 if( nShift>0 ){
203043 int iCurrent = 0; /* Current token number of document */
203044 int iEnd = 0; /* Byte offset of end of current token */
203045 int isShiftDone = 0; /* True after snippet is shifted */
203053 if( zDoc==0 ){
203071 int iBegin = 0; /* Offset in zDoc of start of token */
203072 int iFin = 0; /* Offset in zDoc of end of token */
203073 int isHighlight = 0; /* True for highlighted terms */
203108 ** or (b) this fragment does not begin at position 0 of its column.
203111 if( iPos>0 || iFragment>0 ){
203128 isHighlight = (hlmask & ((u64)1 << (iCurrent-iPos)))!=0;
203150 ** the last varint in the column-list (either the 0x00 signifying the end
203151 ** of the position-list, or the 0x01 that precedes the column number of
203158 char c = 0;
203159 int nEntry = 0;
203161 /* A column-list is terminated by either a 0x01 or 0x00. */
203162 while( 0xFE & (*pEnd | c) ){
203163 c = *pEnd++ & 0x80;
203182 int iCol = 0;
203197 p->aMatchinfo[iStart + (iCol+1)/32] |= (1 << (iCol&0x1F));
203200 assert( *pIter==0x00 || *pIter==0x01 );
203201 if( *pIter!=0x01 ) break;
203217 assert( (pExpr->pLeft==0)==(pExpr->pRight==0) );
203218 if( pExpr->bEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
203241 ** for(iCol=0; iCol<nCol; iCol++){
203282 for(i=0; i<p->nCol && rc==SQLITE_OK; i++){
203288 p->aMatchinfo[iStart+i*3] = 0;
203370 n = sqlite3_column_bytes(pStmt, 0);
203371 a = sqlite3_column_blob(pStmt, 0);
203372 if( a==0 ){
203377 if( nDoc<=0 || a>pEnd ){
203405 #define LCS_ITERATOR_FINISHED 0x7FFFFFFF;
203425 int rc = 0;
203427 if( NEVER(pIter==0) ) return 1;
203430 if( iRead==0 || iRead==1 ){
203431 pRead = 0;
203456 int nToken = 0;
203466 for(i=0; i<pInfo->nPhrase; i++){
203472 for(iCol=0; iCol<pInfo->nCol; iCol++){
203473 int nLcs = 0; /* LCS value for this column */
203474 int nLive = 0; /* Number of iterators in aIter not at EOF */
203476 for(i=0; i<pInfo->nPhrase; i++){
203483 if( pIt->pRead==0 ){
203491 while( nLive>0 ){
203492 LcsIterator *pAdv = 0; /* The iterator to advance by one position */
203493 int nThisLcs = 0; /* LCS for the current iterator positions */
203495 for(i=0; i<pInfo->nPhrase; i++){
203497 if( pIter->pRead==0 ){
203499 nThisLcs = 0;
203501 if( pAdv==0 || pIter->iPos<pAdv->iPos ){
203504 if( nThisLcs==0 || pIter->iPos==pIter[-1].iPos ){
203549 sqlite3_stmt *pSelect = 0;
203551 for(i=0; rc==SQLITE_OK && zArg[i]; i++){
203555 if( bGlobal ) pInfo->aMatchinfo[0] = pInfo->nPhrase;
203559 if( bGlobal ) pInfo->aMatchinfo[0] = pInfo->nCol;
203564 sqlite3_int64 nDoc = 0;
203565 rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &nDoc, 0, 0);
203566 pInfo->aMatchinfo[0] = (u32)nDoc;
203579 for(iCol=0; iCol<pInfo->nCol; iCol++){
203587 iVal = (u32)(((u32)(nToken&0xffffffff)+nDoc/2)/nDoc);
203595 sqlite3_stmt *pSelectDocsize = 0;
203599 const char *a = sqlite3_column_blob(pSelectDocsize, 0);
203600 const char *pEnd = a + sqlite3_column_bytes(pSelectDocsize, 0);
203601 for(iCol=0; iCol<pInfo->nCol; iCol++){
203616 rc = fts3ExprLoadDoclists(pCsr, 0, 0);
203625 memset(pInfo->aMatchinfo, 0, nZero);
203634 rc = fts3ExprLoadDoclists(pCsr, 0, 0);
203638 rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &pInfo->nDoc,0,0);
203670 int bGlobal = 0; /* Collect 'global' stats as well as local */
203672 u32 *aOut = 0;
203673 void (*xDestroyOut)(void*) = 0;
203675 memset(&sInfo, 0, sizeof(MatchInfo));
203684 pCsr->pMIBuffer = 0;
203692 if( pCsr->pMIBuffer==0 ){
203693 size_t nMatchinfo = 0; /* Number of u32 elements in match-info */
203701 for(i=0; zArg[i]; i++){
203702 char *zErr = 0;
203721 if( xDestroyOut==0 ){
203759 StrBuffer res = {0, 0, 0};
203769 int nSnippet = 0; /* Number of fragments in this snippet */
203774 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
203784 int iSnip; /* Loop counter 0..nSnippet-1 */
203785 u64 mCovered = 0; /* Bitmask of phrases covered by snippet */
203786 u64 mSeen = 0; /* Bitmask of phrases seen by BestSnippet() */
203788 if( nToken>=0 ){
203794 for(iSnip=0; iSnip<nSnippet; iSnip++){
203799 memset(pFragment, 0, sizeof(*pFragment));
203805 for(iRead=0; iRead<pTab->nColumn; iRead++){
203806 SnippetFragment sF = {0, 0, 0, 0};
203807 int iS = 0;
203808 if( iCol>=0 && iRead!=iCol ) continue;
203831 assert( nFToken>0 );
203833 for(i=0; i<nSnippet && rc==SQLITE_OK; i++){
203875 i64 iPos = 0; /* First position in position-list */
203883 assert_fts3_nc( iPos>=0 );
203886 for(iTerm=0; iTerm<nTerm; iTerm++){
203908 StrBuffer res = {0, 0, 0}; /* Result string */
203912 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
203916 memset(&sCtx, 0, sizeof(sCtx));
203917 assert( pCsr->isRequireSeek==0 );
203920 rc = fts3ExprLoadDoclists(pCsr, 0, &nToken);
203925 if( 0==sCtx.aTerm ){
203935 for(iCol=0; iCol<pTab->nColumn; iCol++){
203938 int NDUMMY = 0; /* Dummy argument used with xNext() */
203939 int iStart = 0;
203940 int iEnd = 0;
203941 int iCurrent = 0;
203949 sCtx.iTerm = 0;
203963 if( zDoc==0 ){
203980 int iMinPos = 0x7FFFFFFF; /* Position of next token */
203981 TermOffset *pTerm = 0; /* TermOffset associated with next token */
203983 for(i=0; i<nToken; i++){
203996 if( 0==(0xFE&*pTerm->pList) ){
203997 pTerm->pList = 0;
204010 }else if( rc==SQLITE_DONE && pTab->zContentTbl==0 ){
204054 sqlite3_result_blob(pContext, "", 0, SQLITE_STATIC);
204102 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
204103 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
204104 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
204105 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
204106 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
204107 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
204108 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
204109 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
204114 if( c>=0xc0 ){ \
204115 c = sqlite3Utf8Trans1[c-0xc0]; \
204116 while( zIn!=zTerm && (*zIn & 0xc0)==0x80 ){ \
204117 c = (c<<6) + (0x3f & *(zIn++)); \
204119 if( c<0x80 \
204120 || (c&0xFFFFF800)==0xD800 \
204121 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
204125 if( c<0x00080 ){ \
204126 *zOut++ = (u8)(c&0xFF); \
204128 else if( c<0x00800 ){ \
204129 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \
204130 *zOut++ = 0x80 + (u8)(c & 0x3F); \
204132 else if( c<0x10000 ){ \
204133 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \
204134 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
204135 *zOut++ = 0x80 + (u8)(c & 0x3F); \
204137 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07); \
204138 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \
204139 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
204140 *zOut++ = 0x80 + (u8)(c & 0x3F); \
204182 ** all characters in string zIn/nIn to be separators (if bAlnum==0) or
204206 int nEntry = 0;
204208 assert( bAlnum==0 || bAlnum==1 );
204212 assert( (sqlite3FtsUnicodeIsalnum((int)iCode) & 0xFFFFFFFE)==0 );
204214 && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
204225 if( aNew==0 ) return SQLITE_NOMEM;
204232 && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
204235 for(i=0; i<nNew && aNew[i]<(int)iCode; i++);
204252 if( p->nException>0 ){
204254 int iLo = 0;
204269 return 0;
204277 assert( (sqlite3FtsUnicodeIsalnum(iCode) & 0xFFFFFFFE)==0 );
204295 memset(pNew, 0, sizeof(unicode_tokenizer));
204298 for(i=0; rc==SQLITE_OK && i<nArg; i++){
204302 if( n==19 && memcmp("remove_diacritics=1", z, 19)==0 ){
204305 else if( n==19 && memcmp("remove_diacritics=0", z, 19)==0 ){
204306 pNew->eRemoveDiacritic = 0;
204308 else if( n==19 && memcmp("remove_diacritics=2", z, 19)==0 ){
204311 else if( n>=11 && memcmp("tokenchars=", z, 11)==0 ){
204314 else if( n>=11 && memcmp("separators=", z, 11)==0 ){
204315 rc = unicodeAddExceptions(pNew, 0, &z[11], n-11);
204325 pNew = 0;
204333 ** string to be tokenized is pInput[0..nBytes-1]. A cursor
204346 if( pCsr==0 ){
204349 memset(pCsr, 0, sizeof(unicode_cursor));
204352 if( aInput==0 ){
204353 pCsr->nInput = 0;
204355 }else if( nInput<0 ){
204391 unsigned int iCode = 0;
204451 0,
204457 0,
204499 ** codepoints for which this function should return 0).
204509 0x00000030, 0x0000E807, 0x00016C06, 0x0001EC2F, 0x0002AC07,
204510 0x0002D001, 0x0002D803, 0x0002EC01, 0x0002FC01, 0x00035C01,
204511 0x0003DC01, 0x000B0804, 0x000B480E, 0x000B9407, 0x000BB401,
204512 0x000BBC81, 0x000DD401, 0x000DF801, 0x000E1002, 0x000E1C01,
204513 0x000FD801, 0x00120808, 0x00156806, 0x00162402, 0x00163C01,
204514 0x00164437, 0x0017CC02, 0x00180005, 0x00181816, 0x00187802,
204515 0x00192C15, 0x0019A804, 0x0019C001, 0x001B5001, 0x001B580F,
204516 0x001B9C07, 0x001BF402, 0x001C000E, 0x001C3C01, 0x001C4401,
204517 0x001CC01B, 0x001E980B, 0x001FAC09, 0x001FD804, 0x00205804,
204518 0x00206C09, 0x00209403, 0x0020A405, 0x0020C00F, 0x00216403,
204519 0x00217801, 0x0023901B, 0x00240004, 0x0024E803, 0x0024F812,
204520 0x00254407, 0x00258804, 0x0025C001, 0x00260403, 0x0026F001,
204521 0x0026F807, 0x00271C02, 0x00272C03, 0x00275C01, 0x00278802,
204522 0x0027C802, 0x0027E802, 0x00280403, 0x0028F001, 0x0028F805,
204523 0x00291C02, 0x00292C03, 0x00294401, 0x0029C002, 0x0029D401,
204524 0x002A0403, 0x002AF001, 0x002AF808, 0x002B1C03, 0x002B2C03,
204525 0x002B8802, 0x002BC002, 0x002C0403, 0x002CF001, 0x002CF807,
204526 0x002D1C02, 0x002D2C03, 0x002D5802, 0x002D8802, 0x002DC001,
204527 0x002E0801, 0x002EF805, 0x002F1803, 0x002F2804, 0x002F5C01,
204528 0x002FCC08, 0x00300403, 0x0030F807, 0x00311803, 0x00312804,
204529 0x00315402, 0x00318802, 0x0031FC01, 0x00320802, 0x0032F001,
204530 0x0032F807, 0x00331803, 0x00332804, 0x00335402, 0x00338802,
204531 0x00340802, 0x0034F807, 0x00351803, 0x00352804, 0x00355C01,
204532 0x00358802, 0x0035E401, 0x00360802, 0x00372801, 0x00373C06,
204533 0x00375801, 0x00376008, 0x0037C803, 0x0038C401, 0x0038D007,
204534 0x0038FC01, 0x00391C09, 0x00396802, 0x003AC401, 0x003AD006,
204535 0x003AEC02, 0x003B2006, 0x003C041F, 0x003CD00C, 0x003DC417,
204536 0x003E340B, 0x003E6424, 0x003EF80F, 0x003F380D, 0x0040AC14,
204537 0x00412806, 0x00415804, 0x00417803, 0x00418803, 0x00419C07,
204538 0x0041C404, 0x0042080C, 0x00423C01, 0x00426806, 0x0043EC01,
204539 0x004D740C, 0x004E400A, 0x00500001, 0x0059B402, 0x005A0001,
204540 0x005A6C02, 0x005BAC03, 0x005C4803, 0x005CC805, 0x005D4802,
204541 0x005DC802, 0x005ED023, 0x005F6004, 0x005F7401, 0x0060000F,
204542 0x0062A401, 0x0064800C, 0x0064C00C, 0x00650001, 0x00651002,
204543 0x0066C011, 0x00672002, 0x00677822, 0x00685C05, 0x00687802,
204544 0x0069540A, 0x0069801D, 0x0069FC01, 0x006A8007, 0x006AA006,
204545 0x006C0005, 0x006CD011, 0x006D6823, 0x006E0003, 0x006E840D,
204546 0x006F980E, 0x006FF004, 0x00709014, 0x0070EC05, 0x0071F802,
204547 0x00730008, 0x00734019, 0x0073B401, 0x0073C803, 0x00770027,
204548 0x0077F004, 0x007EF401, 0x007EFC03, 0x007F3403, 0x007F7403,
204549 0x007FB403, 0x007FF402, 0x00800065, 0x0081A806, 0x0081E805,
204550 0x00822805, 0x0082801A, 0x00834021, 0x00840002, 0x00840C04,
204551 0x00842002, 0x00845001, 0x00845803, 0x00847806, 0x00849401,
204552 0x00849C01, 0x0084A401, 0x0084B801, 0x0084E802, 0x00850005,
204553 0x00852804, 0x00853C01, 0x00864264, 0x00900027, 0x0091000B,
204554 0x0092704E, 0x00940200, 0x009C0475, 0x009E53B9, 0x00AD400A,
204555 0x00B39406, 0x00B3BC03, 0x00B3E404, 0x00B3F802, 0x00B5C001,
204556 0x00B5FC01, 0x00B7804F, 0x00B8C00C, 0x00BA001A, 0x00BA6C59,
204557 0x00BC00D6, 0x00BFC00C, 0x00C00005, 0x00C02019, 0x00C0A807,
204558 0x00C0D802, 0x00C0F403, 0x00C26404, 0x00C28001, 0x00C3EC01,
204559 0x00C64002, 0x00C6580A, 0x00C70024, 0x00C8001F, 0x00C8A81E,
204560 0x00C94001, 0x00C98020, 0x00CA2827, 0x00CB003F, 0x00CC0100,
204561 0x01370040, 0x02924037, 0x0293F802, 0x02983403, 0x0299BC10,
204562 0x029A7C01, 0x029BC008, 0x029C0017, 0x029C8002, 0x029E2402,
204563 0x02A00801, 0x02A01801, 0x02A02C01, 0x02A08C09, 0x02A0D804,
204564 0x02A1D004, 0x02A20002, 0x02A2D011, 0x02A33802, 0x02A38012,
204565 0x02A3E003, 0x02A4980A, 0x02A51C0D, 0x02A57C01, 0x02A60004,
204566 0x02A6CC1B, 0x02A77802, 0x02A8A40E, 0x02A90C01, 0x02A93002,
204567 0x02A97004, 0x02A9DC03, 0x02A9EC01, 0x02AAC001, 0x02AAC803,
204568 0x02AADC02, 0x02AAF802, 0x02AB0401, 0x02AB7802, 0x02ABAC07,
204569 0x02ABD402, 0x02AF8C0B, 0x03600001, 0x036DFC02, 0x036FFC02,
204570 0x037FFC01, 0x03EC7801, 0x03ECA401, 0x03EEC810, 0x03F4F802,
204571 0x03F7F002, 0x03F8001A, 0x03F88007, 0x03F8C023, 0x03F95013,
204572 0x03F9A004, 0x03FBFC01, 0x03FC040F, 0x03FC6807, 0x03FCEC06,
204573 0x03FD6C0B, 0x03FF8007, 0x03FFA007, 0x03FFE405, 0x04040003,
204574 0x0404DC09, 0x0405E411, 0x0406400C, 0x0407402E, 0x040E7C01,
204575 0x040F4001, 0x04215C01, 0x04247C01, 0x0424FC01, 0x04280403,
204576 0x04281402, 0x04283004, 0x0428E003, 0x0428FC01, 0x04294009,
204577 0x0429FC01, 0x042CE407, 0x04400003, 0x0440E016, 0x04420003,
204578 0x0442C012, 0x04440003, 0x04449C0E, 0x04450004, 0x04460003,
204579 0x0446CC0E, 0x04471404, 0x045AAC0D, 0x0491C004, 0x05BD442E,
204580 0x05BE3C04, 0x074000F6, 0x07440027, 0x0744A4B5, 0x07480046,
204581 0x074C0057, 0x075B0401, 0x075B6C01, 0x075BEC01, 0x075C5401,
204582 0x075CD401, 0x075D3C01, 0x075DBC01, 0x075E2401, 0x075EA401,
204583 0x075F0C01, 0x07BBC002, 0x07C0002C, 0x07C0C064, 0x07C2800F,
204584 0x07C2C40E, 0x07C3040F, 0x07C3440F, 0x07C4401F, 0x07C4C03C,
204585 0x07C5C02B, 0x07C7981D, 0x07C8402B, 0x07C90009, 0x07C94002,
204586 0x07CC0021, 0x07CCC006, 0x07CCDC46, 0x07CE0014, 0x07CE8025,
204587 0x07CF1805, 0x07CF8011, 0x07D0003F, 0x07D10001, 0x07D108B6,
204588 0x07D3E404, 0x07D4003E, 0x07D50004, 0x07D54018, 0x07D7EC46,
204589 0x07D9140B, 0x07DA0046, 0x07DC0074, 0x38000401, 0x38008060,
204590 0x380400F0,
204593 0xFFFFFFFF, 0xFC00FFFF, 0xF8000001, 0xF8000001,
204597 return ( (aAscii[c >> 5] & ((unsigned int)1 << (c & 0x001F)))==0 );
204599 unsigned int key = (((unsigned int)c)<<10) | 0x000003FF;
204600 int iRes = 0;
204601 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
204602 int iLo = 0;
204612 assert( aEntry[0]<key );
204614 return (((unsigned int)c) >= ((aEntry[iRes]>>10) + (aEntry[iRes]&0x3FF)));
204630 0, 1797, 1848, 1859, 1891, 1928, 1940, 1995,
204647 #define HIBIT ((unsigned char)0x80)
204649 '\0', 'a', 'c', 'e', 'i', 'n',
204659 'o'|HIBIT, 'y', '\0', '\0', '\0', '\0',
204660 '\0', '\0', '\0', '\0', 'a', 'b',
204672 unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
204673 int iRes = 0;
204674 int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
204675 int iLo = 0;
204686 if( bComplex==0 && (aChar[iRes] & 0x80) ) return c;
204687 return (c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : ((int)aChar[iRes] & 0x7F);
204696 unsigned int mask0 = 0x08029FDF;
204697 unsigned int mask1 = 0x000361F8;
204698 if( c<768 || c>817 ) return 0;
204726 ** case equivalent is ((C + aiOff[flags>>1]) & 0xFFFF).
204741 {386, 1, 4}, {390, 44, 1}, {391, 0, 1},
204742 {393, 42, 2}, {395, 0, 1}, {398, 32, 1},
204743 {399, 38, 1}, {400, 40, 1}, {401, 0, 1},
204745 {407, 48, 1}, {408, 0, 1}, {412, 52, 1},
204747 {422, 60, 1}, {423, 0, 1}, {425, 60, 1},
204748 {428, 0, 1}, {430, 60, 1}, {431, 0, 1},
204750 {440, 0, 1}, {444, 0, 1}, {452, 2, 1},
204751 {453, 0, 1}, {455, 2, 1}, {456, 0, 1},
204755 {546, 1, 18}, {570, 70, 1}, {571, 0, 1},
204756 {573, 108, 1}, {574, 68, 1}, {577, 0, 1},
204759 {886, 0, 1}, {902, 18, 1}, {904, 16, 3},
204761 {931, 14, 9}, {962, 0, 1}, {975, 4, 1},
204765 {1015, 0, 1}, {1017, 152, 1}, {1018, 0, 1},
204781 {8579, 0, 1}, {9398, 10, 26}, {11264, 22, 47},
204782 {11360, 0, 1}, {11362, 88, 1}, {11363, 102, 1},
204785 {11378, 0, 1}, {11381, 0, 1}, {11390, 78, 2},
204786 {11392, 1, 100}, {11499, 1, 4}, {11506, 0, 1},
204789 {42878, 1, 10}, {42891, 0, 1}, {42893, 74, 1},
204814 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
204815 int iLo = 0;
204818 assert( c>aEntry[0].iCode );
204822 if( cmp>=0 ){
204830 assert( iRes>=0 && c>=aEntry[iRes].iCode );
204832 if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
204833 ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
204834 assert( ret>0 );
204871 ** Support for JSON-5 extensions was added with version 3.42.0 (2023-05-16).
204875 ** Beginning with version 3.45.0 (circa 2024-01-01), these routines also
204901 ** 0: NULL
204920 ** of the element and if X>>4 is between 0 and 11, then the payload
204929 ** 12 1 byte (0-255) 2
204930 ** 13 2 byte (0-65535) 3
204931 ** 14 4 byte (0-4294967295) 5
204932 ** 15 8 byte (0-1.8e19) 9
204936 ** ways: (1) (X>>4)==10, (2) (X>>4)==12 following by on 0x0a byte,
204937 ** (3) (X>>4)==13 followed by 0x00 and 0x0a, (4) (X>>4)==14 followed by
204938 ** 0x00 0x00 0x00 0x0a, or (5) (X>>4)==15 followed by 7 bytes of 0x00 and
204939 ** a single byte of 0x0a. The shorter forms are preferred, of course, but
204963 ** code is between 0 and 12 and that the total size of the element
204977 #define JSONB_NULL 0 /* "null" */
204981 #define JSONB_INT5 4 /* integer in 0x000 notation */
205006 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
205007 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205008 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205009 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205010 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205011 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205012 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205013 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205015 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205016 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205017 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205018 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205019 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205020 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205021 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205022 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205039 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205040 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205041 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
205044 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
205073 #define JSON_INVALID_CHAR 0x99999
205113 #define JSTRING_OOM 0x01 /* Out of memory */
205114 #define JSTRING_MALFORMED 0x02 /* Malformed JSONB */
205115 #define JSTRING_ERR 0x04 /* Error already sent to sqlite3_result */
205126 #define JSON_JSON 0x01 /* Result is always JSON */
205127 #define JSON_SQL 0x02 /* Result is always SQL */
205128 #define JSON_ABPATH 0x03 /* Allow abbreviated JSON path specs */
205129 #define JSON_ISSET 0x04 /* json_set(), not json_insert() */
205130 #define JSON_BLOB 0x08 /* Use the BLOB output format */
205151 u32 nBlobAlloc; /* Bytes allocated to aBlob[]. 0 if aBlob is external */
205182 ** should go. Historical note: This limit was 2000 prior to version 3.42.0
205193 #define JSON_EDITABLE 0x01 /* Generate a writable JsonParse object */
205194 #define JSON_KEEPERROR 0x02 /* Return non-NULL even if there is an error */
205217 for(i=0; i<p->nUsed; i++){
205239 assert( pParse->zJson!=0 );
205241 assert( pParse->delta==0 );
205243 if( p==0 ){
205246 if( p==0 ) return SQLITE_NOMEM;
205250 if( p==0 ) return SQLITE_NOMEM;
205253 jsonParseFree(p->a[0]);
205254 memmove(p->a, &p->a[1], (JSON_CACHE_SIZE-1)*sizeof(p->a[0]));
205257 assert( pParse->nBlobAlloc>0 );
205258 pParse->eEdit = 0;
205287 return 0;
205290 if( zJson==0 ) return 0;
205294 if( p==0 ){
205295 return 0;
205297 for(i=0; i<p->nUsed; i++){
205301 for(i=0; i<p->nUsed; i++){
205303 if( memcmp(p->a[i]->zJson, zJson, nJson)==0 ) break;
205314 assert( p->a[i]->delta==0 );
205317 return 0;
205331 p->nUsed = 0;
205339 p->eErr = 0;
205368 if( zNew==0 ){
205374 p->bStatic = 0;
205377 if( p->zBuf==0 ){
205394 assert( N>0 );
205400 if( N==0 ) return;
205409 assert( N>0 );
205446 if( p->eErr==0 ){
205447 assert( p->nUsed>0 );
205459 jsonAppendChar(p, 0);
205461 return p->eErr==0;
205469 if( p->nUsed==0 ) return;
205483 0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0,
205484 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
205492 assert( c>=0 && c<sizeof(aSpecial) );
205501 p->zBuf[p->nUsed+2] = '0';
205502 p->zBuf[p->nUsed+3] = '0';
205504 p->zBuf[p->nUsed+5] = "0123456789abcdef"[c&0xf];
205521 if( z==0 ) return;
205522 if( (N+p->nUsed+2 >= p->nAlloc) && jsonStringGrow(p,N+2)!=0 ) return;
205525 k = 0;
205554 if( k>0 ){
205560 if( k>0 ){
205566 c = z[0];
205568 if( (p->nUsed+N+3 > p->nAlloc) && jsonStringGrow(p,N+3)!=0 ) return;
205574 if( (p->nUsed+N+7 > p->nAlloc) && jsonStringGrow(p,N+7)!=0 ) return;
205620 memset(&px, 0, sizeof(px));
205623 jsonTranslateBlobToText(&px, 0, p);
205624 }else if( p->eErr==0 ){
205648 assert( (pParse!=0)==(ctx!=0) );
205649 assert( ctx==0 || ctx==p->pCtx );
205650 if( p->eErr==0 ){
205658 if( pParse && pParse->bJsonIsRCStr==0 && pParse->nBlobAlloc>0 ){
205696 pParse->zJson = 0;
205697 pParse->nJson = 0;
205698 pParse->bJsonIsRCStr = 0;
205702 pParse->aBlob = 0;
205703 pParse->nBlob = 0;
205704 pParse->nBlobAlloc = 0;
205730 ** character: 0..9a..fA..F. But unlike sqlite3HexToInt(), it does not
205740 return (u8)(h & 0xf);
205748 v = (jsonHexToInt(z[0])<<12)
205759 return sqlite3Isxdigit(z[0]) && sqlite3Isxdigit(z[1]);
205777 ** U+000a 0a line feed
205778 ** U+000b 0b vertical tab
205779 ** U+000c 0c form feed
205780 ** U+000d 0d carriage return
205806 int n = 0;
205810 case 0x09:
205811 case 0x0a:
205812 case 0x0b:
205813 case 0x0c:
205814 case 0x0d:
205815 case 0x20: {
205820 if( z[n+1]=='*' && z[n+2]!=0 ){
205823 if( z[j]==0 ) goto whitespace_done;
205830 for(j=n+2; (c = z[j])!=0; j++){
205832 if( 0xe2==(u8)c && 0x80==(u8)z[j+1]
205833 && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2])
205845 case 0xc2: {
205846 if( z[n+1]==0xa0 ){
205852 case 0xe1: {
205853 if( z[n+1]==0x9a && z[n+2]==0x80 ){
205859 case 0xe2: {
205860 if( z[n+1]==0x80 ){
205862 if( c<0x80 ) goto whitespace_done;
205863 if( c<=0x8a || c==0xa8 || c==0xa9 || c==0xaf ){
205867 }else if( z[n+1]==0x81 && z[n+2]==0x9f ){
205873 case 0xe3: {
205874 if( z[n+1]==0x80 && z[n+2]==0x80 ){
205880 case 0xef: {
205881 if( z[n+1]==0xbb && z[n+2]==0xbf ){
205943 if( pParse->nBlobAlloc==0 ){
205950 if( aNew==0 ){ pParse->oom = 1; return 1; }
205953 return 0;
205959 ** pParse->nBlobAlloc==0 and pParse->nBlob>0) then make it editable
205968 if( pParse->oom ) return 0;
205969 if( pParse->nBlobAlloc>0 ) return 1;
205972 pParse->aBlob = 0;
205974 return 0;
205988 if( pParse->oom==0 ){
206039 assert( pParse->aBlob!=0 );
206042 a[0] = eType | (szPayload<<4);
206044 }else if( szPayload<=0xff ){
206045 a[0] = eType | 0xc0;
206046 a[1] = szPayload & 0xff;
206048 }else if( szPayload<=0xffff ){
206049 a[0] = eType | 0xd0;
206050 a[1] = (szPayload >> 8) & 0xff;
206051 a[2] = szPayload & 0xff;
206054 a[0] = eType | 0xe0;
206055 a[1] = (szPayload >> 24) & 0xff;
206056 a[2] = (szPayload >> 16) & 0xff;
206057 a[3] = (szPayload >> 8) & 0xff;
206058 a[4] = szPayload & 0xff;
206079 if( pParse->oom ) return 0;
206081 szType = a[0]>>4;
206083 nExtra = 0;
206092 nNeeded = 0;
206093 }else if( szPayload<=0xff ){
206095 }else if( szPayload<=0xffff ){
206103 if( delta>0 ){
206105 return 0; /* OOM error. Error state recorded in pParse->oom. */
206114 if( nNeeded==0 ){
206115 a[0] = (a[0] & 0x0f) | (szPayload<<4);
206117 a[0] = (a[0] & 0x0f) | 0xc0;
206118 a[1] = szPayload & 0xff;
206120 a[0] = (a[0] & 0x0f) | 0xd0;
206121 a[1] = (szPayload >> 8) & 0xff;
206122 a[2] = szPayload & 0xff;
206124 a[0] = (a[0] & 0x0f) | 0xe0;
206125 a[1] = (szPayload >> 24) & 0xff;
206126 a[2] = (szPayload >> 16) & 0xff;
206127 a[3] = (szPayload >> 8) & 0xff;
206128 a[4] = szPayload & 0xff;
206134 ** If z[0] is 'u' and is followed by exactly 4 hexadecimal character,
206139 if( z[0]!='u' ) return 0;
206140 if( !jsonIs4Hex(&z[1]) ) return 0;
206151 ** Return 0 if everything is correct. Return the 1-based byte offset of the
206153 ** 0, return 1).
206165 sz = 0;
206167 if( NEVER(n==0) ) return i+1; /* Checked by caller */
206170 x = z[i] & 0x0f;
206175 return n+sz==1 ? 0 : i+1;
206192 return 0;
206201 if( z[j]!='0' ) return i+1;
206212 return 0;
206216 u8 seen = 0; /* 0: initial. 1: '.' seen 2: 'e' seen */
206229 }else if( z[j]=='0' && x==JSONB_FLOAT ){
206237 if( seen>0 ) return j+1;
206256 if( seen==0 ) return i+1;
206257 return 0;
206266 return 0;
206276 }else if( z[j]<=0x1f ){
206281 }else if( strchr("\"\\/bfnrt",z[j+1])!=0 ){
206290 u32 c = 0;
206298 return 0;
206301 return 0;
206308 sz = 0;
206310 if( n==0 ) return j+1;
206317 return 0;
206320 u32 cnt = 0;
206325 sz = 0;
206327 if( n==0 ) return j+1;
206329 if( (cnt & 1)==0 ){
206330 x = z[j] & 0x0f;
206339 if( (cnt & 1)!=0 ) return j+1;
206340 return 0;
206357 ** 0 End of input
206376 jsonBlobAppendNode(pParse, JSONB_OBJECT, pParse->nJson-i, 0);
206385 if( x<=0 ){
206398 while( (sqlite3JsonId2(z[k]) && json5Whitespace(&z[k])==0)
206413 t = pParse->aBlob[iBlob] & 0x0f;
206439 if( x<=0 ){
206478 jsonBlobAppendNode(pParse, JSONB_ARRAY, pParse->nJson - i, 0);
206487 if( x<=0 ){
206559 }else if( c=='\'' || c=='0' || c=='v' || c=='\n'
206560 || (0xe2==(u8)c && 0x80==(u8)z[j+1]
206561 && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2]))
206573 }else if( c<=0x1f ){
206574 if( c==0 ){
206591 if( strncmp(z+i,"true",4)==0 && !sqlite3Isalnum(z[i+4]) ){
206599 if( strncmp(z+i,"false",5)==0 && !sqlite3Isalnum(z[i+5]) ){
206609 t = 0x00; /* Bit 0x01: JSON5. Bit 0x02: FLOAT */
206614 t = 0x03; /* Bit 0x01: JSON5. Bit 0x02: FLOAT */
206615 seenE = 0;
206621 case '0':
206632 t = 0x00; /* Bit 0x01: JSON5. Bit 0x02: FLOAT */
206634 seenE = 0;
206635 assert( '-' < '0' );
206636 assert( '+' < '0' );
206637 assert( '.' < '0' );
206640 if( c<='0' ){
206641 if( c=='0' ){
206643 assert( t==0x00 );
206645 t = 0x01;
206658 && sqlite3StrNICmp(&z[i+1], "inf",3)==0
206666 return i + (sqlite3StrNICmp(&z[i+4],"inity",5)==0 ? 9 : 4);
206670 t |= 0x01;
206676 if( z[i+1]=='0' ){
206682 t |= 0x01;
206695 if( (t & 0x02)!=0 ){
206699 t |= 0x02;
206703 if( z[j-1]<'0' ){
206706 t |= 0x01;
206716 t |= 0x02;
206723 if( c<'0' || c>'9' ){
206731 if( z[j-1]<'0' ){
206734 t |= 0x01;
206741 assert( JSONB_INT+0x01==JSONB_INT5 );
206742 assert( JSONB_FLOAT+0x01==JSONB_FLOAT5 );
206743 assert( JSONB_INT+0x02==JSONB_FLOAT );
206764 case 0: {
206765 return 0; /* End of file */
206767 case 0x09:
206768 case 0x0a:
206769 case 0x0d:
206770 case 0x20: {
206774 case 0x0b:
206775 case 0x0c:
206777 case 0xc2:
206778 case 0xe1:
206779 case 0xe2:
206780 case 0xe3:
206781 case 0xef: {
206783 if( j>0 ){
206792 if( strncmp(z+i,"null",4)==0 && !sqlite3Isalnum(z[i+4]) ){
206803 for(k=0; k<sizeof(aNanInfName)/sizeof(aNanInfName[0]); k++){
206806 if( sqlite3StrNICmp(&z[i], aNanInfName[k].zMatch, nn)!=0 ){
206826 ** Parse a complete JSON string. Return 0 on success or non-zero if there
206839 i = jsonTranslateTextToBlob(pParse, 0);
206841 if( i>0 ){
206843 assert( pParse->iDepth==0 );
206845 assert( jsonbValidityCheck(pParse, 0, pParse->nBlob, 0)==0 );
206859 if( i<=0 ){
206860 if( pCtx!=0 ){
206870 return 0;
206880 memset(&px, 0, sizeof(px));
206889 (void)jsonTranslateTextToBlob(&px, 0);
206894 assert( px.nBlobAlloc>0 );
206903 ** beginning of the payload. Return 0 on error.
206910 *pSz = 0;
206911 return 0;
206919 *pSz = 0;
206920 return 0;
206926 *pSz = 0;
206927 return 0;
206933 *pSz = 0;
206934 return 0;
206941 || pParse->aBlob[i+1]!=0
206942 || pParse->aBlob[i+2]!=0
206943 || pParse->aBlob[i+3]!=0
206944 || pParse->aBlob[i+4]!=0
206946 *pSz = 0;
206947 return 0;
206956 sz = 0;
206957 n = 0;
206985 if( n==0 ){
206989 switch( pParse->aBlob[i] & 0x0f ){
207004 if( sz==0 ) goto malformed_jsonb;
207010 sqlite3_uint64 u = 0;
207012 int bOverflow = 0;
207013 if( sz==0 ) goto malformed_jsonb;
207014 if( zIn[0]=='-' ){
207017 }else if( zIn[0]=='+' ){
207024 }else if( (u>>60)!=0 ){
207034 u32 k = 0;
207036 if( sz==0 ) goto malformed_jsonb;
207037 if( zIn[0]=='-' ){
207042 jsonAppendChar(pOut, '0');
207047 jsonAppendChar(pOut, '0');
207065 while( sz2>0 ){
207066 for(k=0; k<sz2 && (jsonIsOk[(u8)zIn[k]] || zIn[k]=='\''); k++){}
207067 if( k>0 ){
207075 if( zIn[0]=='"' ){
207081 if( zIn[0]<=0x1f ){
207083 jsonAppendControlChar(pOut, zIn[0]);
207088 assert( zIn[0]=='\\' );
207112 case '0':
207123 case 0xe2:
207125 ** whitespace. Not that in UTF8, U+2028 is 0xe2 0x80 0x29.
207128 || 0x80!=(u8)zIn[2]
207129 || (0xa8!=(u8)zIn[3] && 0xa9!=(u8)zIn[3])
207157 while( j<iEnd && pOut->eErr==0 ){
207162 if( sz>0 ) jsonStringTrimOneChar(pOut);
207167 int x = 0;
207171 while( j<iEnd && pOut->eErr==0 ){
207175 if( (x & 1)!=0 || j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
207176 if( sz>0 ) jsonStringTrimOneChar(pOut);
207204 for(jj=0; jj<pPretty->nIndent; jj++){
207234 if( n==0 ){
207238 switch( pParse->aBlob[i] & 0x0f ){
207246 while( pOut->eErr==0 ){
207267 while( pOut->eErr==0 ){
207307 if( sqlite3_value_type(pJson)!=SQLITE_BLOB ) return 0;
207310 if( nBlob<1 ) return 0;
207311 if( NEVER(aBlob==0) || (aBlob[0] & 0x0f)>JSONB_OBJECT ) return 0;
207312 memset(&s, 0, sizeof(s));
207315 n = jsonbPayloadSize(&s, 0, &sz);
207316 if( n==0 ) return 0;
207317 if( sz+n!=(u32)nBlob ) return 0;
207318 if( (aBlob[0] & 0x0f)<=JSONB_FALSE && sz>0 ) return 0;
207328 u32 k = 0;
207331 for(i=iRoot+n; n>0 && i<iEnd; i+=sz+n, k++){
207342 u32 sz = 0;
207344 assert( pParse->delta!=0 );
207375 if( d!=0 ){
207393 ** 0x5c 0x0a
207394 ** 0x5c 0x0d
207395 ** 0x5c 0x0d 0x0a
207396 ** 0x5c 0xe2 0x80 0xa8
207397 ** 0x5c 0xe2 0x80 0xa9
207400 u32 i = 0;
207415 if( 0xe2==(u8)z[i+1]
207417 && 0x80==(u8)z[i+2]
207418 && (0xa8==(u8)z[i+3] || 0xa9==(u8)z[i+3])
207429 ** Input z[0..n] defines JSON escape sequence including the leading '\\'.
207438 assert( n>0 );
207439 assert( z[0]=='\\' );
207452 if( (v & 0xfc00)==0xd800
207456 && ((vlo = jsonHexToInt4(&z[8]))&0xfc00)==0xdc00
207458 *piOut = ((v&0x3ff)<<10) + (vlo&0x3ff) + 0x10000;
207471 case '0': { *piOut = 0; return 2; }
207484 case 0xe2:
207488 if( nSkip==0 ){
207492 *piOut = 0;
207511 ** 0 if they differ.
207525 assert( rawLeft==0 || rawRight==0 );
207527 if( nLeft==0 ){
207528 cLeft = 0;
207529 }else if( rawLeft || zLeft[0]!='\\' ){
207530 cLeft = ((u8*)zLeft)[0];
207531 if( cLeft>=0xc0 ){
207545 if( nRight==0 ){
207546 cRight = 0;
207547 }else if( rawRight || zRight[0]!='\\' ){
207548 cRight = ((u8*)zRight)[0];
207549 if( cRight>=0xc0 ){
207563 if( cLeft!=cRight ) return 0;
207564 if( cLeft==0 ) return 1;
207570 ** 0 if they differ. Return -1 if an OOM occurs.
207583 if( nLeft!=nRight ) return 0;
207584 return memcmp(zLeft, zRight, nLeft)==0;
207594 #define JSON_LOOKUP_ERROR 0xffffffff
207595 #define JSON_LOOKUP_NOTFOUND 0xfffffffe
207596 #define JSON_LOOKUP_PATHERROR 0xfffffffd
207629 memset(pIns, 0, sizeof(*pIns));
207631 if( zTail[0]==0 ){
207635 rc = 0;
207639 pIns->aBlob = (u8*)&emptyObject[zTail[0]=='.'];
207643 rc = jsonLookupStep(pIns, 0, zTail, 0);
207676 if( zPath[0]==0 ){
207681 if( iLabel>0 ){
207685 jsonBlobEdit(pParse, iRoot, sz, 0, 0);
207696 if( zPath[0]=='.' ){
207700 if( zPath[0]=='"' ){
207709 testcase( nKey==0 );
207710 rawKey = memchr(zKey, '\\', nKey)==0;
207713 for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){}
207715 if( nKey==0 ){
207719 if( (x & 0x0f)!=JSONB_OBJECT ) return JSON_LOOKUP_NOTFOUND;
207726 x = pParse->aBlob[j] & 0x0f;
207729 if( n==0 ) return JSON_LOOKUP_ERROR;
207736 if( ((pParse->aBlob[v])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
207738 if( n==0 || v+n+sz>iEnd ) return JSON_LOOKUP_ERROR;
207739 assert( j>0 );
207745 if( ((pParse->aBlob[j])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
207747 if( n==0 ) return JSON_LOOKUP_ERROR;
207757 memset(&ix, 0, sizeof(ix));
207759 jsonBlobAppendNode(&ix, rawKey?JSONB_TEXTRAW:JSONB_TEXT5, nKey, 0);
207767 jsonBlobEdit(pParse, j, 0, 0, nIns);
207769 assert( pParse->aBlob!=0 ); /* Because pParse->oom!=0 */
207770 assert( ix.aBlob!=0 ); /* Because pPasre->oom!=0 */
207783 }else if( zPath[0]=='[' ){
207784 x = pParse->aBlob[iRoot] & 0x0f;
207787 k = 0;
207790 k = k*10 + zPath[i] - '0';
207798 unsigned int nn = 0;
207801 nn = nn*10 + zPath[i] - '0';
207817 if( k==0 ){
207818 rc = jsonLookupStep(pParse, j, &zPath[i+1], 0);
207824 if( n==0 ) return JSON_LOOKUP_ERROR;
207828 if( k>0 ) return JSON_LOOKUP_NOTFOUND;
207838 jsonBlobEdit(pParse, j, 0, v.aBlob, v.nBlob);
207862 if( NEVER(aBlob==0) ) return;
207863 memset(&x, 0, sizeof(x));
207867 jsonTranslateBlobToText(&x, 0, &s);
207868 jsonReturnString(&s, 0, 0);
207891 if( n==0 ){
207895 switch( pParse->aBlob[i] & 0x0f ){
207908 sqlite3_result_int(pCtx, 0);
207913 sqlite3_int64 iRes = 0;
207915 int bNeg = 0;
207917 if( sz==0 ) goto returnfromblob_malformed;
207926 if( z==0 ) goto returnfromblob_oom;
207929 if( rc==0 ){
207945 if( sz==0 ) goto returnfromblob_malformed;
207948 if( z==0 ) goto returnfromblob_oom;
207951 if( rc<=0 ) goto returnfromblob_malformed;
207970 if( zOut==0 ) goto returnfromblob_oom;
207971 for(iIn=iOut=0; iIn<sz; iIn++){
207976 if( v<=0x7f ){
207978 }else if( v<=0x7ff ){
207980 zOut[iOut++] = (char)(0xc0 | (v>>6));
207981 zOut[iOut++] = 0x80 | (v&0x3f);
207982 }else if( v<0x10000 ){
207984 zOut[iOut++] = 0xe0 | (v>>12);
207985 zOut[iOut++] = 0x80 | ((v>>6)&0x3f);
207986 zOut[iOut++] = 0x80 | (v&0x3f);
207991 zOut[iOut++] = 0xf0 | (v>>18);
207992 zOut[iOut++] = 0x80 | ((v>>12)&0x3f);
207993 zOut[iOut++] = 0x80 | ((v>>6)&0x3f);
207994 zOut[iOut++] = 0x80 | (v&0x3f);
208002 zOut[iOut] = 0;
208008 int flags = textOnly ? 0 : SQLITE_PTR_TO_INT(sqlite3_user_data(pCtx));
208054 static u8 aNull[] = { 0x00 };
208055 memset(pParse, 0, sizeof(pParse[0]));
208061 return 0;
208076 if( zJson==0 ) return 1;
208083 memset(pParse, 0, sizeof(pParse[0]));
208094 jsonBlobAppendNode(pParse, JSONB_NULL, 0, 0);
208098 if( z==0 ) return 1;
208099 if( z[0]=='I' ){
208101 }else if( z[0]=='-' && z[1]=='I' ){
208112 if( z==0 ) return 1;
208121 return 0;
208136 if( ctx==0 ) return zMsg;
208143 return 0;
208146 /* argv[0] is a BLOB that seems likely to be a JSONB. Subsequent
208161 u32 rc = 0;
208162 const char *zPath = 0;
208168 flgs = argc==1 ? 0 : JSON_EDITABLE;
208169 p = jsonParseFuncArg(ctx, argv[0], flgs);
208170 if( p==0 ) return;
208174 if( zPath==0 ){
208179 if( zPath[0]!='$' ) goto jsonInsertIntoBlob_patherror;
208185 if( zPath[1]==0 ){
208187 jsonBlobEdit(p, 0, p->nBlob, ax.aBlob, ax.nBlob);
208189 rc = 0;
208194 p->delta = 0;
208195 rc = jsonLookupStep(p, 0, zPath+1, 0);
208225 u32 n, sz = 0;
208228 if( p->nBlob==0 ){
208229 p->aBlob = 0;
208230 return 0;
208232 if( NEVER(p->aBlob==0) ){
208233 return 0;
208235 if( (p->aBlob[0] & 0x0f)<=JSONB_OBJECT
208236 && (n = jsonbPayloadSize(p, 0, &sz))>0
208238 && ((p->aBlob[0] & 0x0f)>JSONB_FALSE || sz==0)
208242 p->aBlob = 0;
208243 p->nBlob = 0;
208244 return 0;
208269 JsonParse *p = 0; /* Value to be returned */
208270 JsonParse *pFromCache = 0; /* Value taken from cache */
208273 assert( ctx!=0 );
208276 return 0;
208281 if( (flgs & JSON_EDITABLE)==0 ){
208288 if( p==0 ) goto json_pfa_oom;
208289 memset(p, 0, sizeof(*p));
208292 if( pFromCache!=0 ){
208295 if( p->aBlob==0 ) goto json_pfa_oom;
208304 if( (flgs & JSON_EDITABLE)!=0 && jsonBlobMakeEditable(p, 0)==0 ){
208325 if( p->nJson==0 ) goto json_pfa_malformed;
208326 assert( p->zJson!=0 );
208327 if( jsonConvertTextToBlob(p, (flgs & JSON_KEEPERROR) ? 0 : ctx) ){
208333 return 0;
208340 if( zNew==0 ) goto json_pfa_oom;
208343 p->zJson[p->nJson] = 0;
208352 p = 0;
208365 return 0;
208372 return 0;
208391 if( p->nBlobAlloc>0 && !p->bReadOnly ){
208393 p->nBlobAlloc = 0;
208400 p->delta = 0;
208401 jsonTranslateBlobToText(p, 0, &s);
208425 u32 i, n, nn, sz = 0;
208427 u8 x = pParse->aBlob[iStart] & 0x0f;
208434 if( nn==0 ) nn = 1;
208435 if( sz>0 && x<JSONB_ARRAY ){
208438 for(i=0; i<nn; i++){
208441 if( n==0 ){
208443 iStart = n==0 ? iStart+1 : iEnd;
208450 if( pParse->nBlobAlloc>0 && iEnd>pParse->nBlobAlloc ){
208473 showContent = 0;
208479 showContent = 0;
208484 showContent = 0;
208489 if( sz==0 && x<=JSONB_FALSE ){
208496 if( c<0x20 || c>=0x7f ) c = '.';
208508 if( pParse==0 ){
208515 if( pParse->nBlob==0 ) return;
208516 printf("content (bytes 0..%u):\n", pParse->nBlob-1);
208518 sqlite3StrAccumInit(&out, 0, zBuf, sizeof(zBuf), 1000000);
208519 jsonDebugPrintBlob(pParse, 0, pParse->nBlob, 0, &out);
208541 sqlite3StrAccumInit(&out, 0, 0, 0, 1000000);
208542 p = jsonParseFuncArg(ctx, argv[0], 0);
208543 if( p==0 ) return;
208545 jsonDebugPrintBlob(p, 0, p->nBlob, 0, &out);
208574 jsonAppendSqlValue(&jx, argv[0]);
208575 jsonReturnString(&jx, 0, 0);
208594 for(i=0; i<argc; i++){
208599 jsonReturnString(&jx, 0, 0);
208608 ** Return 0 if the input is not a well-formed JSON array.
208616 sqlite3_int64 cnt = 0;
208618 u8 eErr = 0;
208620 p = jsonParseFuncArg(ctx, argv[0], 0);
208621 if( p==0 ) return;
208624 if( zPath==0 ){
208628 i = jsonLookupStep(p, 0, zPath[0]=='$' ? zPath+1 : "@", 0);
208638 i = 0;
208641 i = 0;
208643 if( (p->aBlob[i] & 0x0f)==JSONB_ARRAY ){
208653 for(i=0; i<n && (sqlite3Isalnum(z[i]) || z[i]=='_'); i++){}
208682 JsonParse *p = 0; /* The parse */
208688 p = jsonParseFuncArg(ctx, argv[0], 0);
208689 if( p==0 ) return;
208700 if( zPath==0 ) goto json_extract_error;
208702 if( zPath[0]=='$' ){
208703 j = jsonLookupStep(p, 0, zPath+1, 0);
208721 }else if( zPath[0]=='[' && nPath>=3 && zPath[nPath-1]==']' ){
208729 j = jsonLookupStep(p, 0, jx.zBuf, 0);
208740 jsonReturnString(&jx, 0, 0);
208742 assert( (flags & JSON_BLOB)==0 );
208745 jsonReturnFromBlob(p, j, ctx, 0);
208746 if( (flags & (JSON_SQL|JSON_BLOB))==0
208747 && (p->aBlob[j]&0x0f)>=JSONB_ARRAY
208773 jsonReturnString(&jx, 0, 0);
208774 if( (flags & JSON_BLOB)==0 ){
208787 #define JSON_MERGE_OK 0 /* Success */
208845 u32 n, sz=0; /* Return values from jsonbPayloadSize() */
208851 u32 iTLabel = 0; /* Index of the label */
208852 u32 nTLabel = 0; /* Header size in bytes for the target label */
208853 u32 szTLabel = 0; /* Size of the target label payload */
208854 u32 iTValue = 0; /* Index of the target value */
208855 u32 nTValue = 0; /* Header size of the target value */
208856 u32 szTValue = 0; /* Payload size for the target value */
208868 assert( iTarget>=0 && iTarget<pTarget->nBlob );
208869 assert( iPatch>=0 && iPatch<pPatch->nBlob );
208870 x = pPatch->aBlob[iPatch] & 0x0f;
208876 sz = 0;
208882 x = pTarget->aBlob[iTarget] & 0x0f;
208885 jsonBlobEdit(pTarget, iTarget+n, sz, 0, 0);
208887 pTarget->aBlob[iTarget] = (x & 0xf0) | JSONB_OBJECT;
208890 if( NEVER(n==0) ) return JSON_MERGE_BADPATCH;
208894 if( NEVER(n==0) ) return JSON_MERGE_BADTARGET;
208900 ePLabel = pPatch->aBlob[iPCursor] & 0x0f;
208905 if( nPLabel==0 ) return JSON_MERGE_BADPATCH;
208909 if( nPValue==0 ) return JSON_MERGE_BADPATCH;
208918 eTLabel = pTarget->aBlob[iTCursor] & 0x0f;
208923 if( nTLabel==0 ) return JSON_MERGE_BADTARGET;
208927 if( nTValue==0 ) return JSON_MERGE_BADTARGET;
208939 x = pPatch->aBlob[iPValue] & 0x0f;
208942 if( x==0 ){
208944 jsonBlobEdit(pTarget, iTLabel, nTLabel+szTLabel+nTValue+szTValue, 0,0);
208950 pTarget->delta = 0;
208955 }else if( x>0 ){ /* Algorithm line 13 */
208958 if( (pPatch->aBlob[iPValue] & 0x0f)!=JSONB_OBJECT ){ /* Line 14 */
208959 jsonBlobEdit(pTarget, iTEnd, 0, 0, szPValue+nPValue+szNew);
208966 jsonBlobEdit(pTarget, iTEnd, 0, 0, szNew+1);
208969 pTarget->aBlob[iTEnd+szNew] = 0x00;
208971 pTarget->delta = 0;
208999 pTarget = jsonParseFuncArg(ctx, argv[0], JSON_EDITABLE);
209000 if( pTarget==0 ) return;
209001 pPatch = jsonParseFuncArg(ctx, argv[1], 0);
209003 rc = jsonMergePatch(pTarget, 0, pPatch, 0);
209039 for(i=0; i<argc; i+=2){
209053 jsonReturnString(&jx, 0, 0);
209070 const char *zPath = 0; /* Path of element to be removed */
209075 p = jsonParseFuncArg(ctx, argv[0], argc>1 ? JSON_EDITABLE : 0);
209076 if( p==0 ) return;
209079 if( zPath==0 ){
209082 if( zPath[0]!='$' ){
209085 if( zPath[1]==0 ){
209090 p->delta = 0;
209091 rc = jsonLookupStep(p, 0, zPath+1, 0);
209127 if( (argc&1)==0 ) {
209154 int bIsSet = (flags&JSON_ISSET)!=0;
209157 if( (argc&1)==0 ) {
209177 const char *zPath = 0;
209180 p = jsonParseFuncArg(ctx, argv[0], 0);
209181 if( p==0 ) return;
209184 if( zPath==0 ) goto json_type_done;
209185 if( zPath[0]!='$' ){
209189 i = jsonLookupStep(p, 0, zPath+1, 0);
209201 i = 0;
209203 sqlite3_result_text(ctx, jsonbType[p->aBlob[i]&0x0f], -1, SQLITE_STATIC);
209226 memset(&x, 0, sizeof(x));
209227 x.pParse = jsonParseFuncArg(ctx, argv[0], 0);
209228 if( x.pParse==0 ) return;
209231 if( argc==1 || (x.zIndent = (const char*)sqlite3_value_text(argv[1]))==0 ){
209237 jsonTranslateBlobToPrettyText(&x, 0);
209238 jsonReturnString(&s, 0, 0);
209249 ** 0x01 Canonical RFC-8259 JSON text
209250 ** 0x02 JSON text with optional JSON-5 extensions
209251 ** 0x04 Superficially appears to be JSONB
209252 ** 0x08 Strictly well-formed JSONB
209297 ** * Return 0 if the input is not well-formed.
209306 u8 res = 0;
209314 flags = f & 0x0f;
209316 switch( sqlite3_value_type(argv[0]) ){
209320 sqlite3_result_int(ctx, 0);
209325 if( jsonFuncArgMightBeBinary(argv[0]) ){
209326 if( flags & 0x04 ){
209330 }else if( flags & 0x08 ){
209335 memset(&px, 0, sizeof(px));
209336 px.aBlob = (u8*)sqlite3_value_blob(argv[0]);
209337 px.nBlob = sqlite3_value_bytes(argv[0]);
209338 iErr = jsonbValidityCheck(&px, 0, px.nBlob, 1);
209339 res = iErr==0;
209349 if( (flags & 0x3)==0 ) break;
209350 memset(&px, 0, sizeof(px));
209352 p = jsonParseFuncArg(ctx, argv[0], JSON_KEEPERROR);
209358 }else if( (flags & 0x02)!=0 || p->hasNonstd==0 ){
209382 ** that the input was not valid JSON, or return 0 if the input text looks
209390 i64 iErrPos = 0; /* Error position to be returned */
209395 memset(&s, 0, sizeof(s));
209397 if( jsonFuncArgMightBeBinary(argv[0]) ){
209398 s.aBlob = (u8*)sqlite3_value_blob(argv[0]);
209399 s.nBlob = sqlite3_value_bytes(argv[0]);
209400 iErrPos = (i64)jsonbValidityCheck(&s, 0, s.nBlob, 1);
209402 s.zJson = (char*)sqlite3_value_text(argv[0]);
209403 if( s.zJson==0 ) return; /* NULL input or OOM */
209404 s.nJson = sqlite3_value_bytes(argv[0]);
209405 if( jsonConvertTextToBlob(&s,0) ){
209411 assert( s.zJson!=0 ); /* Because s.oom is false */
209412 for(k=0; k<s.iErr && ALWAYS(s.zJson[k]); k++){
209413 if( (s.zJson[k] & 0xc0)!=0x80 ) iErrPos++;
209420 if( iErrPos<0 ){
209444 if( pStr->zBuf==0 ){
209451 jsonAppendSqlValue(pStr, argv[0]);
209456 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
209463 jsonReturnString(pStr, 0, 0);
209488 jsonArrayCompute(ctx, 0);
209507 int inStr = 0;
209508 int nNest = 0;
209514 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
209534 z[pStr->nUsed] = 0;
209540 # define jsonGroupInverse 0
209560 if( pStr->zBuf==0 ){
209567 z = (const char*)sqlite3_value_text(argv[0]);
209576 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
209583 jsonReturnString(pStr, 0, 0);
209608 jsonObjectCompute(ctx, 0);
209664 #define JEACH_KEY 0
209688 if( pNew==0 ) return SQLITE_NOMEM;
209709 if( pCur==0 ) return SQLITE_NOMEM;
209732 p->iRowid = 0;
209733 p->i = 0;
209734 p->aParent = 0;
209735 p->nParent = 0;
209736 p->nParentAlloc = 0;
209737 p->iEnd = 0;
209738 p->eType = 0;
209764 u32 sz = 0;
209776 assert( p->nParent>0 );
209781 u32 n, sz = 0, k, i;
209783 int needQuote = 0;
209787 if( sz==0 || !sqlite3Isalpha(z[0]) ){
209790 for(i=0; i<sz; i++){
209811 u8 levelChange = 0;
209812 u32 n, sz = 0;
209814 x = p->sParse.aBlob[i] & 0x0f;
209823 if( pNew==0 ) return SQLITE_NOMEM;
209843 while( p->nParent>0 && p->i >= p->aParent[p->nParent-1].iEnd ){
209849 if( p->nParent>0 ){
209852 p->eType = p->sParse.aBlob[iVal] & 0x0f;
209854 p->eType = 0;
209858 u32 n, sz = 0;
209870 /* Length of the path for rowid==0 in bRecursive mode.
209875 if( p->iRowid==0 && p->bRecursive && n>=2 ){
209879 u32 x, sz = 0;
209881 z[n] = 0;
209882 assert( p->sParse.eEdit==0 );
209883 x = jsonLookupStep(&p->sParse, 0, z+1, 0);
209902 if( p->nParent==0 ){
209907 if( n==0 ){
209931 if( (p->sParse.aBlob[i] & 0x0f)>=JSONB_ARRAY ){
209938 u8 eType = p->sParse.aBlob[i] & 0x0f;
209944 if( (p->sParse.aBlob[i] & 0x0f)<JSONB_ARRAY ){
209954 if( p->nParent>0 && p->bRecursive ){
209978 if( p->sParse.zJson==0 ){
210000 ** and 0 otherwise.
210008 int unusableMask = 0; /* Mask of unusable JSON and ROOT constraints */
210009 int idxMask = 0; /* Mask of usable == constraints JSON and ROOT */
210016 aIdx[0] = aIdx[1] = -1;
210018 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
210023 assert( iCol==0 || iCol==1 );
210024 testcase( iCol==0 );
210026 if( pConstraint->usable==0 ){
210033 if( pIdxInfo->nOrderBy>0
210034 && pIdxInfo->aOrderBy[0].iColumn<0
210035 && pIdxInfo->aOrderBy[0].desc==0
210040 if( (unusableMask & ~idxMask)!=0 ){
210045 if( aIdx[0]<0 ){
210049 pIdxInfo->idxNum = 0;
210052 i = aIdx[0];
210055 if( aIdx[1]<0 ){
210074 const char *zRoot = 0;
210080 if( idxNum==0 ) return SQLITE_OK;
210081 memset(&p->sParse, 0, sizeof(p->sParse));
210084 if( jsonFuncArgMightBeBinary(argv[0]) ){
210085 p->sParse.nBlob = sqlite3_value_bytes(argv[0]);
210086 p->sParse.aBlob = (u8*)sqlite3_value_blob(argv[0]);
210088 p->sParse.zJson = (char*)sqlite3_value_text(argv[0]);
210089 p->sParse.nJson = sqlite3_value_bytes(argv[0]);
210090 if( p->sParse.zJson==0 ){
210091 p->i = p->iEnd = 0;
210094 if( jsonConvertTextToBlob(&p->sParse, 0) ){
210103 if( zRoot==0 ) return SQLITE_OK;
210104 if( zRoot[0]!='$' ){
210106 cur->pVtab->zErrMsg = jsonBadPathError(0, zRoot);
210111 if( zRoot[1]==0 ){
210112 i = p->i = 0;
210113 p->eType = 0;
210115 i = jsonLookupStep(&p->sParse, 0, zRoot+1, 0);
210118 p->i = 0;
210119 p->eType = 0;
210120 p->iEnd = 0;
210124 cur->pVtab->zErrMsg = jsonBadPathError(0, zRoot);
210138 i = p->i = 0;
210139 p->eType = 0;
210143 p->nParent = 0;
210146 if( (p->sParse.aBlob[i] & 0x0f)>=JSONB_ARRAY && !p->bRecursive ){
210148 p->eType = p->sParse.aBlob[i] & 0x0f;
210150 if( p->aParent==0 ) return SQLITE_NOMEM;
210153 p->aParent[0].iKey = 0;
210154 p->aParent[0].iEnd = p->iEnd;
210155 p->aParent[0].iHead = p->i;
210156 p->aParent[0].iValue = i;
210169 0, /* iVersion */
210170 0, /* xCreate */
210174 0, /* xDestroy */
210182 0, /* xUpdate */
210183 0, /* xBegin */
210184 0, /* xSync */
210185 0, /* xCommit */
210186 0, /* xRollback */
210187 0, /* xFindMethod */
210188 0, /* xRename */
210189 0, /* xSavepoint */
210190 0, /* xRelease */
210191 0, /* xRollbackTo */
210192 0, /* xShadowName */
210193 0 /* xIntegrity */
210198 0, /* iVersion */
210199 0, /* xCreate */
210203 0, /* xDestroy */
210211 0, /* xUpdate */
210212 0, /* xBegin */
210213 0, /* xSync */
210214 0, /* xCommit */
210215 0, /* xRollback */
210216 0, /* xFindMethod */
210217 0, /* xRename */
210218 0, /* xSavepoint */
210219 0, /* xRelease */
210220 0, /* xRollbackTo */
210221 0, /* xShadowName */
210222 0 /* xIntegrity */
210239 JFUNCTION(json, 1,1,1, 0,0,0, jsonRemoveFunc),
210240 JFUNCTION(jsonb, 1,1,0, 0,1,0, jsonRemoveFunc),
210241 JFUNCTION(json_array, -1,0,1, 1,0,0, jsonArrayFunc),
210242 JFUNCTION(jsonb_array, -1,0,1, 1,1,0, jsonArrayFunc),
210243 JFUNCTION(json_array_length, 1,1,0, 0,0,0, jsonArrayLengthFunc),
210244 JFUNCTION(json_array_length, 2,1,0, 0,0,0, jsonArrayLengthFunc),
210245 JFUNCTION(json_error_position,1,1,0, 0,0,0, jsonErrorFunc),
210246 JFUNCTION(json_extract, -1,1,1, 0,0,0, jsonExtractFunc),
210247 JFUNCTION(jsonb_extract, -1,1,0, 0,1,0, jsonExtractFunc),
210248 JFUNCTION(->, 2,1,1, 0,0,JSON_JSON, jsonExtractFunc),
210249 JFUNCTION(->>, 2,1,0, 0,0,JSON_SQL, jsonExtractFunc),
210250 JFUNCTION(json_insert, -1,1,1, 1,0,0, jsonSetFunc),
210251 JFUNCTION(jsonb_insert, -1,1,0, 1,1,0, jsonSetFunc),
210252 JFUNCTION(json_object, -1,0,1, 1,0,0, jsonObjectFunc),
210253 JFUNCTION(jsonb_object, -1,0,1, 1,1,0, jsonObjectFunc),
210254 JFUNCTION(json_patch, 2,1,1, 0,0,0, jsonPatchFunc),
210255 JFUNCTION(jsonb_patch, 2,1,0, 0,1,0, jsonPatchFunc),
210256 JFUNCTION(json_pretty, 1,1,0, 0,0,0, jsonPrettyFunc),
210257 JFUNCTION(json_pretty, 2,1,0, 0,0,0, jsonPrettyFunc),
210258 JFUNCTION(json_quote, 1,0,1, 1,0,0, jsonQuoteFunc),
210259 JFUNCTION(json_remove, -1,1,1, 0,0,0, jsonRemoveFunc),
210260 JFUNCTION(jsonb_remove, -1,1,0, 0,1,0, jsonRemoveFunc),
210261 JFUNCTION(json_replace, -1,1,1, 1,0,0, jsonReplaceFunc),
210262 JFUNCTION(jsonb_replace, -1,1,0, 1,1,0, jsonReplaceFunc),
210263 JFUNCTION(json_set, -1,1,1, 1,0,JSON_ISSET, jsonSetFunc),
210264 JFUNCTION(jsonb_set, -1,1,0, 1,1,JSON_ISSET, jsonSetFunc),
210265 JFUNCTION(json_type, 1,1,0, 0,0,0, jsonTypeFunc),
210266 JFUNCTION(json_type, 2,1,0, 0,0,0, jsonTypeFunc),
210267 JFUNCTION(json_valid, 1,1,0, 0,0,0, jsonValidFunc),
210268 JFUNCTION(json_valid, 2,1,0, 0,0,0, jsonValidFunc),
210270 JFUNCTION(json_parse, 1,1,0, 0,0,0, jsonParseFunc),
210272 WAGGREGATE(json_group_array, 1, 0, 0,
210276 WAGGREGATE(jsonb_group_array, 1, JSON_BLOB, 0,
210279 WAGGREGATE(json_group_object, 2, 0, 0,
210282 WAGGREGATE(jsonb_group_object,2, JSON_BLOB, 0,
210305 for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
210306 rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
210402 # define NEVER(X) (0)
210404 # define ALWAYS(X) ((X)?1:(assert(0),0))
210405 # define NEVER(X) ((X)?(assert(0),1):0)
210414 # define FOUR_BYTE_ALIGNED(X) ((((char*)(X) - (char*)0) & 3)==0)
210492 ** headed by the node (leaf nodes have RtreeNode.iNode==0).
210520 #define RTREE_COORD_REAL32 0
210531 # define RTREE_ZERO 0
210552 ** the node that the RtreeSearchPoint represents. When iLevel==0, however,
210559 u8 iLevel; /* 0=entries. 1=leaf node. 2+ for higher */
210659 #define RTREE_EQ 0x41 /* A */
210660 #define RTREE_LE 0x42 /* B */
210661 #define RTREE_LT 0x43 /* C */
210662 #define RTREE_GE 0x44 /* D */
210663 #define RTREE_GT 0x45 /* E */
210664 #define RTREE_MATCH 0x46 /* F: Old-style sqlite3_rtree_geometry_callback() */
210665 #define RTREE_QUERY 0x47 /* G: New-style sqlite3_rtree_query_callback() */
210671 #define RTREE_TRUE 0x3f /* ? */
210672 #define RTREE_FALSE 0x40 /* @ */
210740 /* What version of GCC is being used. 0 means GCC is not being used .
210749 # define GCC_VERSION 0
210758 unsigned int sqlite3RtreeTestcase = 0;
210806 # define SQLITE_BYTEORDER 0
210811 /* What version of MSVC is being used. 0 means MSVC is not being used */
210816 # define MSVC_VERSION 0
210825 return (p[0]<<8) + p[1];
210837 (((u32)p[0]) << 24) +
210840 (((u32)p[3]) << 0)
210859 (((u64)p[0]) << 56) +
210866 (((u64)p[7]) << 0)
210877 p[0] = (i>> 8)&0xFF;
210878 p[1] = (i>> 0)&0xFF;
210896 p[0] = (i>>24)&0xFF;
210897 p[1] = (i>>16)&0xFF;
210898 p[2] = (i>> 8)&0xFF;
210899 p[3] = (i>> 0)&0xFF;
210913 p[0] = (i>>56)&0xFF;
210914 p[1] = (i>>48)&0xFF;
210915 p[2] = (i>>40)&0xFF;
210916 p[3] = (i>>32)&0xFF;
210917 p[4] = (i>>24)&0xFF;
210918 p[5] = (i>>16)&0xFF;
210919 p[6] = (i>> 8)&0xFF;
210920 p[7] = (i>> 0)&0xFF;
210930 assert( p->nRef>0 );
210936 ** Clear the content of node p (set all bytes to 0x00).
210939 memset(&p->zData[2], 0, pRtree->iNodeSize-2);
210953 ** to it. Otherwise, return 0.
210966 assert( pNode->pNext==0 );
210977 if( pNode->iNode!=0 ){
210981 pNode->pNext = 0;
210986 ** Allocate and return new r-tree node. Initially, (RtreeNode.iNode==0),
210995 memset(pNode, 0, sizeof(RtreeNode) + pRtree->iNodeSize);
211011 pRtree->pNodeBlob = 0;
211025 RtreeNode *pNode = 0;
211030 if( (pNode = nodeHashLookup(pRtree, iNode))!=0 ){
211042 pRtree->pNodeBlob = 0;
211050 if( pRtree->pNodeBlob==0 ){
211052 "data", iNode, 0,
211056 *ppNode = 0;
211073 pNode->isDirty = 0;
211074 pNode->pNext = 0;
211076 pRtree->iNodeSize, 0);
211106 if( pNode!=0 ){
211120 *ppNode = 0;
211138 for(ii=0; ii<pRtree->nDim2; ii++){
211197 pNode->isDirty = 0;
211200 if( pNode->iNode==0 && rc==SQLITE_OK ){
211215 assert( pNode->nRef>0 );
211216 assert( pRtree->nNodeRef>0 );
211218 if( pNode->nRef==0 ){
211276 int ii = 0;
211319 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
211335 if( pRtree->nBusy==0 ){
211336 pRtree->inWrTrans = 0;
211337 assert( pRtree->nCursor==0 );
211339 assert( pRtree->nNodeRef==0 || pRtree->bCorrupt );
211380 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
211400 memset(pCsr, 0, sizeof(RtreeCursor));
211420 for(i=0; i<pCsr->nConstraint; i++){
211428 pCsr->aConstraint = 0;
211430 for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
211433 memset(pCsr, 0, sizeof(RtreeCursor));
211445 assert( pRtree->nCursor>0 );
211450 if( pRtree->nCursor==0 && pRtree->inWrTrans==0 ){
211494 c.u = ((c.u>>24)&0xff)|((c.u>>8)&0xff00)| \
211495 ((c.u&0xff)<<24)|((c.u&0xff00)<<8); \
211507 c.u = ((u32)a[0]<<24) + ((u32)a[1]<<16) \
211539 if( eInt==0 ){
211550 readCoord(pCellData, &c); aCoord[0] = c.f;
211565 readCoord(pCellData, &c); aCoord[0] = c.i;
211569 int eWithin = 0;
211572 if( eWithin==0 ) *peWithin = NOT_WITHIN;
211604 pCellData += 8 + 4*(p->iCoord&0xfe);
211689 for(ii=0; ii<nCell; ii++){
211731 return 0;
211746 p->aNode[i] = 0;
211759 return pCur->bPoint ? &pCur->sPoint : pCur->nPoint ? pCur->aPoint : 0;
211768 assert( ii==0 || ii==1 );
211770 if( pCur->aNode[ii]==0 ){
211771 assert( pRC!=0 );
211772 id = ii ? pCur->aPoint[0].id : pCur->sPoint.id;
211773 *pRC = nodeAcquire(RTREE_OF_CURSOR(pCur), id, 0, &pCur->aNode[ii]);
211790 pNew = sqlite3_realloc64(pCur->aPoint, nNew*sizeof(pCur->aPoint[0]));
211791 if( pNew==0 ) return 0;
211800 while( i>0 ){
211804 if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break;
211824 if( pFirst==0
211831 if( pNew==0 ) return 0;
211835 assert( pCur->aNode[ii]==0 );
211836 pCur->aNode[ii] = pCur->aNode[0];
211838 nodeRelease(RTREE_OF_CURSOR(pCur), pCur->aNode[0]);
211840 pCur->aNode[0] = 0;
211852 #if 0
211855 if( idx<0 ){ printf(" s"); }else{ printf("%2d", idx); }
211872 for(ii=0; ii<pCur->nPoint; ii++){
211873 if( ii>0 || pCur->bPoint ) printf(" ");
211887 assert( i==0 || i==1 );
211890 p->aNode[i] = 0;
211894 p->bPoint = 0;
211896 p->anQueue[p->aPoint[0].iLevel]--;
211898 p->aPoint[0] = p->aPoint[n];
211901 p->aNode[n+1] = 0;
211903 i = 0;
211906 if( k<n && rtreeSearchPointCompare(&p->aPoint[k], &p->aPoint[j])<0 ){
211907 if( rtreeSearchPointCompare(&p->aPoint[k], &p->aPoint[i])<0 ){
211914 if( rtreeSearchPointCompare(&p->aPoint[j], &p->aPoint[i])<0 ){
211945 while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){
211955 for(ii=0; ii<nConstraint; ii++){
211977 for(ii=0; ii<pCur->nPoint; ii++){
211983 x.iCell = 0;
211994 if( p==0 ) return SQLITE_NOMEM;
212006 pCur->atEOF = p==0;
212020 pCsr->bAuxValid = 0;
212058 if( NEVER(p==0) ) return SQLITE_OK;
212060 if( i==0 ){
212075 if( pCsr->pReadAux==0 ){
212076 rc = sqlite3_prepare_v3(pRtree->db, pRtree->zReadAuxSql, -1, 0,
212077 &pCsr->pReadAux, 0);
212101 ** *ppLeaf to 0 and return SQLITE_OK. If an error occurs, set *ppLeaf
212111 *ppLeaf = 0;
212114 i64 iNode = sqlite3_column_int64(pRtree->pReadRowid, 0);
212116 rc = nodeAcquire(pRtree, iNode, 0, ppLeaf);
212135 if( pSrc==0 ) return SQLITE_ERROR;
212139 memset(pInfo, 0, sizeof(*pInfo));
212169 RtreeNode *pRoot = 0;
212172 int iCell = 0;
212184 i64 iRowid = sqlite3_value_int64(argv[0]);
212185 i64 iNode = 0;
212186 int eType = sqlite3_value_numeric_type(argv[0]);
212189 && 0==sqlite3IntFloatCompare(iRowid,sqlite3_value_double(argv[0])))
212194 pLeaf = 0;
212196 if( rc==SQLITE_OK && pLeaf!=0 ){
212197 p = rtreeSearchPointNew(pCsr, RTREE_ZERO, 0);
212198 assert( p!=0 ); /* Always returns pCsr->sPoint */
212199 pCsr->aNode[0] = pLeaf;
212212 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
212213 if( rc==SQLITE_OK && argc>0 ){
212219 memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc);
212220 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
212221 assert( (idxStr==0 && argc==0)
212223 for(ii=0; ii<argc; ii++){
212227 p->iCoord = idxStr[ii*2+1]-'0';
212274 assert( pCsr->bPoint==0 ); /* Due to the resetCursor() call above */
212276 if( NEVER(pNew==0) ){ /* Because pCsr->bPoint was FALSE */
212280 pNew->iCell = 0;
212283 pCsr->aNode[0] = pRoot;
212284 pRoot = 0;
212317 ** = 0x41 ('A')
212318 ** <= 0x42 ('B')
212319 ** < 0x43 ('C')
212320 ** >= 0x44 ('D')
212321 ** > 0x45 ('E')
212322 ** MATCH 0x46 ('F')
212333 int bMatch = 0; /* True if there exists a MATCH constraint */
212336 int iIdx = 0;
212338 memset(zIdxStr, 0, sizeof(zIdxStr));
212344 for(ii=0; ii<pIdxInfo->nConstraint; ii++){
212350 assert( pIdxInfo->idxStr==0 );
212351 for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
212354 if( bMatch==0 && p->usable
212355 && p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ
212359 for(jj=0; jj<ii; jj++){
212360 pIdxInfo->aConstraintUsage[jj].argvIndex = 0;
212361 pIdxInfo->aConstraintUsage[jj].omit = 0;
212380 && ((p->iColumn>0 && p->iColumn<=pRtree->nDim2)
212386 case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; doOmit = 0; break;
212387 case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; doOmit = 0; break;
212389 case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; doOmit = 0; break;
212392 default: op = 0; break;
212396 zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0');
212405 if( iIdx>0 ){
212407 if( pIdxInfo->idxStr==0 ){
212433 default: area *= p->aCoord[1].f - p->aCoord[0].f;
212443 default: area *= (i64)p->aCoord[1].i - (i64)p->aCoord[0].i;
212454 RtreeDValue margin = 0;
212459 }while( ii>=0 );
212467 int ii = 0;
212490 for(ii=0; ii<pRtree->nDim2; ii+=2){
212493 if( a2[0].i<a1[0].i || a2[1].i>a1[1].i ) return 0;
212496 for(ii=0; ii<pRtree->nDim2; ii+=2){
212499 if( a2[0].f<a1[0].f || a2[1].f>a1[1].f ) return 0;
212513 for(ii=0; ii<nCell; ii++){
212516 for(jj=0; jj<pRtree->nDim2; jj+=2){
212521 o = (RtreeDValue)0;
212545 RtreeNode *pNode = 0;
212546 rc = nodeAcquire(pRtree, 1, 0, &pNode);
212548 for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){
212550 sqlite3_int64 iBest = 0;
212551 int bFound = 0;
212555 RtreeNode *pChild = 0;
212561 for(iCell=0; iCell<nCell; iCell++){
212566 if( bFound==0 || area<fMinArea ){
212578 for(iCell=0; iCell<nCell; iCell++){
212586 if( iCell==0
212617 int cnt = 0;
212672 ** nIdx. The aIdx array contains the set of integers from 0 to
212691 int iLeft = 0;
212692 int iRight = 0;
212721 #if 0
212753 int iBestDim = 0;
212754 int iBestSplit = 0;
212765 memset(aaSorted, 0, nByte);
212766 for(ii=0; ii<pRtree->nDim; ii++){
212769 for(jj=0; jj<nCell; jj++){
212775 for(ii=0; ii<pRtree->nDim; ii++){
212779 int iBestLeft = 0;
212793 memcpy(&left, &aCell[aaSorted[ii][0]], sizeof(RtreeCell));
212816 if( ii==0 || margin<fBestMargin ){
212823 memcpy(pBboxLeft, &aCell[aaSorted[iBestDim][0]], sizeof(RtreeCell));
212825 for(ii=0; ii<nCell; ii++){
212845 xSetMapping = ((iHeight==0)?rowidWrite:parentWrite);
212846 if( iHeight>0 ){
212858 if( NEVER(pNode==0) ) return SQLITE_ERROR;
212869 int newCellIsRight = 0;
212876 RtreeNode *pLeft = 0;
212877 RtreeNode *pRight = 0;
212891 memset(aiUsed, 0, sizeof(int)*(nCell+1));
212892 for(i=0; i<nCell; i++){
212916 memset(pLeft->zData, 0, pRtree->iNodeSize);
212917 memset(pRight->zData, 0, pRtree->iNodeSize);
212931 || (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft)))
212961 for(i=0; i<NCELL(pRight); i++){
212972 for(i=0; i<NCELL(pLeft); i++){
212979 }else if( newCellIsRight==0 ){
212985 pRight = 0;
212989 pLeft = 0;
213013 while( rc==SQLITE_OK && pChild->iNode!=1 && pChild->pParent==0 ){
213026 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
213028 if( pTest==0 ){
213029 rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
213048 RtreeNode *pParent = 0;
213057 pNode->pParent = 0;
213102 nodeGetCell(pRtree, pNode, 0, &box);
213155 ** subtree iHeight high (leaf nodes have iHeight==0).
213164 if( iHeight>0 ){
213177 if( iHeight==0 ){
213192 for(ii=0; rc==SQLITE_OK && ii<nCell; ii++){
213231 RtreeNode *pLeaf = 0; /* Leaf node containing record iDelete */
213233 RtreeNode *pRoot = 0; /* Root node of rtree structure */
213237 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
213243 rc = findLeafNode(pRtree, iDelete, &pLeaf, 0);
213247 assert( pLeaf!=0 || rc!=SQLITE_OK || CORRUPT_DB );
213255 rc = deleteCell(pRtree, pLeaf, iCell, 0);
213278 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
213280 RtreeNode *pChild = 0;
213281 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
213330 f = (float)(d*(d<0 ? RNDAWAY : RNDTOWARDS));
213338 f = (float)(d*(d<0 ? RNDTOWARDS : RNDAWAY));
213351 ** constraint failure. If it is 0, then the constraint that failed is
213358 sqlite3_stmt *pStmt = 0;
213362 assert( iCol==0 || iCol%2 );
213365 rc = sqlite3_prepare_v2(pRtree->db, zSql, -1, &pStmt, 0);
213372 if( iCol==0 ){
213373 const char *zCol = sqlite3_column_name(pStmt, 0);
213404 int bHaveRowid = 0; /* Set to 1 after new rowid is determined */
213415 memset(&cell, 0, sizeof(cell));
213444 for(ii=0; ii<nn; ii+=2){
213455 for(ii=0; ii<nn; ii+=2){
213469 if( sqlite3_value_type(aData[0])==SQLITE_NULL
213470 || sqlite3_value_int64(aData[0])!=cell.iRowid
213480 rc = rtreeConstraintError(pRtree, 0);
213489 /* If aData[0] is not an SQL NULL value, it is the rowid of a
213493 if( sqlite3_value_type(aData[0])!=SQLITE_NULL ){
213494 rc = rtreeDeleteRowid(pRtree, sqlite3_value_int64(aData[0]));
213503 RtreeNode *pLeaf = 0;
213506 if( bHaveRowid==0 ){
213512 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
213516 rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
213526 for(jj=0; jj<pRtree->nAux; jj++){
213544 assert( pRtree->inWrTrans==0 );
213555 pRtree->inWrTrans = 0;
213579 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
213603 pRtree->inWrTrans = 0;
213622 db, pRtree->zDb, "sqlite_stat1",0,0,0,0,0,0
213629 if( zSql==0 ){
213632 rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
213634 if( sqlite3_step(p)==SQLITE_ROW ) nRow = sqlite3_column_int64(p, 0);
213653 for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
213654 if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
213656 return 0;
213681 0, /* xFindFunction - function overloading */
213684 0, /* xRelease */
213685 0, /* xRollbackTo */
213728 for(ii=0; ii<pRtree->nAux; ii++){
213744 rc = sqlite3_exec(db, zCreate, 0, 0, 0);
213751 appStmt[0] = &pRtree->pWriteNode;
213761 for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){
213764 if( i!=3 || pRtree->nAux==0 ){
213774 rc = sqlite3_prepare_v3(db, zSql, -1, f, appStmt[i], 0);
213784 if( pRtree->zReadAuxSql==0 ){
213791 for(ii=0; ii<pRtree->nAux; ii++){
213804 if( zSql==0 ){
213807 rc = sqlite3_prepare_v3(db, zSql, -1, f, &pRtree->pWriteAux, 0);
213826 sqlite3_stmt *pStmt = 0;
213827 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
213830 *piVal = sqlite3_column_int(pStmt, 0);
213862 int iPageSize = 0;
213897 int dummy = 0;
213905 ** argv[0] -> module name
213929 0, /* 0 */
213953 memset(pRtree, 0, sizeof(Rtree)+nDb+nName*2+8);
213975 if( zArg[0]=='+' ){
213978 }else if( pRtree->nAux>0 ){
214007 iErr = 0;
214029 assert( *ppVtab==0 );
214061 memset(&node, 0, sizeof(RtreeNode));
214062 memset(&tree, 0, sizeof(Rtree));
214063 tree.nDim = (u8)sqlite3_value_int(apArg[0]);
214068 if( node.zData==0 ) return;
214073 pOut = sqlite3_str_new(0);
214074 for(ii=0; ii<NCELL(&node); ii++){
214079 if( ii>0 ) sqlite3_str_append(pOut, " ", 1);
214081 for(jj=0; jj<tree.nDim2; jj++){
214100 ** The depth value is 0 for all nodes other than the root node, and the root
214106 if( sqlite3_value_type(apArg[0])!=SQLITE_BLOB
214107 || sqlite3_value_bytes(apArg[0])<2
214112 u8 *zBlob = (u8 *)sqlite3_value_blob(apArg[0]);
214166 sqlite3_stmt *pRet = 0;
214172 if( z==0 ){
214175 pCheck->rc = sqlite3_prepare_v2(pCheck->db, z, -1, &pRet, 0);
214194 if( z==0 ){
214200 if( pCheck->zReport==0 ){
214224 u8 *pRet = 0; /* Return value */
214226 if( pCheck->rc==SQLITE_OK && pCheck->pGetNode==0 ){
214236 int nNode = sqlite3_column_bytes(pCheck->pGetNode, 0);
214237 const u8 *pNode = (const u8*)sqlite3_column_blob(pCheck->pGetNode, 0);
214239 if( pRet==0 ){
214247 if( pCheck->rc==SQLITE_OK && pRet==0 ){
214256 ** This function is used to check that the %_parent (if bLeaf==0) or %_rowid
214280 assert( bLeaf==0 || bLeaf==1 );
214281 if( pCheck->aCheckMapping[bLeaf]==0 ){
214296 i64 ii = sqlite3_column_int64(pStmt, 0);
214330 for(i=0; i<pCheck->nDim; i++){
214367 int iDepth, /* Depth of iNode (0==leaf) */
214371 u8 *aNode = 0;
214372 int nNode = 0;
214374 assert( iNode==1 || aParent!=0 );
214375 assert( pCheck->nDim>0 );
214386 if( aParent==0 ){
214401 for(i=0; i<nCell; i++){
214406 if( iDepth>0 ){
214407 rtreeCheckMapping(pCheck, 0, iVal, iNode);
214436 i64 nActual = sqlite3_column_int64(pCount, 0);
214459 sqlite3_stmt *pStmt = 0; /* Used to find column count of rtree table */
214460 int nAux = 0; /* Number of extra columns. */
214463 memset(&check, 0, sizeof(check));
214495 rtreeCheckNode(&check, 0, 0, 1);
214503 sqlite3_finalize(check.aCheckMapping[0]);
214522 assert( pzErr!=0 && *pzErr==0 );
214530 if( (*pzErr)==0 ) rc = SQLITE_NOMEM;
214579 char *zReport = 0;
214580 const char *zDb = (const char*)sqlite3_value_text(apArg[0]);
214624 static int geo_debug = 0;
214651 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
214652 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214653 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214654 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214655 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214656 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214657 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214658 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214659 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214660 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214661 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214662 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214663 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214664 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214665 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214666 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214676 # define GCC_VERSION 0
214683 # define MSVC_VERSION 0
214705 ** encoding (1 byte) 0=big-endian, 1=little-endian
214747 unsigned char t = a[0];
214748 a[0] = a[3];
214757 while( fast_isspace(p->z[0]) ) p->z++;
214758 return p->z[0];
214761 /* Parse out a number. Write the value into *pVal if pVal!=0.
214767 int j = 0;
214768 int seenDP = 0;
214769 int seenE = 0;
214774 if( c=='0' && z[j+1]>='0' && z[j+1]<='9' ) return 0;
214779 if( z[j-1]=='-' ) return 0;
214780 if( seenDP ) return 0;
214785 if( z[j-1]<'0' ) return 0;
214793 if( c<'0' || c>'9' ) return 0;
214798 if( z[j-1]<'0' ) return 0;
214825 memset(&s, 0, sizeof(s));
214830 int ii = 0;
214837 if( aNew==0 ){
214844 while( geopolyParseNumber(&s, ii<=1 ? &s.a[s.nVertex*2+ii] : 0) ){
214863 && s.a[0]==s.a[s.nVertex*2-2]
214865 && (s.z++, geopolySkipSpace(&s)==0)
214872 if( pOut==0 ) goto parse_json_err;
214875 pOut->hdr[0] = *(unsigned char*)&x;
214876 pOut->hdr[1] = (s.nVertex>>16)&0xff;
214877 pOut->hdr[2] = (s.nVertex>>8)&0xff;
214878 pOut->hdr[3] = s.nVertex&0xff;
214890 return 0;
214904 GeoPoly *p = 0;
214906 testcase( pCtx==0 );
214912 if( a==0 ){
214914 return 0;
214917 if( (a[0]==0 || a[0]==1)
214921 if( p==0 ){
214928 if( a[0] != *(unsigned char*)&x ){
214930 for(ii=0; ii<nVertex; ii++){
214934 p->hdr[0] ^= 1;
214942 if( zJson==0 ){
214944 return 0;
214949 return 0;
214965 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
214985 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
214992 for(i=0; i<p->nVertex; i++){
214995 sqlite3_str_appendf(x, "[%!g,%!g]]", GeoX(p,0), GeoY(p,0));
215014 p = geopolyFuncParam(context, argv[0], 0);
215021 for(i=0; i<p->nVertex; i++){
215025 sqlite3_str_appendf(x, " %g,%g'", GeoX(p,0), GeoY(p,0));
215028 if( z && z[0] ){
215048 ** geopoly_xform(poly, 1, 0, 0, 1, x-offset, y-offset)
215050 ** Rotate by R around the point (0,0):
215052 ** geopoly_xform(poly, cos(R), sin(R), -sin(R), cos(R), 0, 0)
215059 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
215070 for(ii=0; ii<p->nVertex; ii++){
215094 for(ii=0; ii<p->nVertex-1; ii++){
215099 rArea += (GeoX(p,ii) - GeoX(p,0)) /* (xN - x0) */
215100 * (GeoY(p,ii) + GeoY(p,0)) /* (yN + y0) */
215118 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
215144 GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
215194 double x = sqlite3_value_double(argv[0]);
215205 if( p==0 ){
215210 p->hdr[0] = *(unsigned char*)&i;
215211 p->hdr[1] = 0;
215212 p->hdr[2] = (n>>8)&0xff;
215213 p->hdr[3] = n&0xff;
215214 for(i=0; i<n; i++){
215226 ** (1) if aCoord!=0 store the bounding box in aCoord, returning NULL
215239 GeoPoly *pOut = 0;
215242 if( pPoly==0 && aCoord!=0 ){
215243 p = 0;
215244 mnX = aCoord[0].f;
215254 mnX = mxX = GeoX(p,0);
215255 mnY = mxY = GeoY(p,0);
215265 if( aCoord==0 ){
215268 if( pOut==0 ){
215272 return 0;
215276 pOut->hdr[0] = *(unsigned char*)ⅈ
215277 pOut->hdr[1] = 0;
215278 pOut->hdr[2] = 0;
215280 GeoX(pOut,0) = mnX;
215281 GeoY(pOut,0) = mnY;
215290 aCoord[0].f = mnX;
215296 memset(aCoord, 0, sizeof(RtreeCoord)*4);
215309 GeoPoly *p = geopolyBBox(context, argv[0], 0, 0);
215339 (void)geopolyBBox(context, argv[0], a, &rc);
215343 if( pBBox==0 ) return;
215344 if( pBBox->isInit==0 ){
215348 if( a[0].f < pBBox->a[0].f ) pBBox->a[0] = a[0];
215360 pBBox = (GeoBBox*)sqlite3_aggregate_context(context, 0);
215361 if( pBBox==0 ) return;
215362 p = geopolyBBox(context, 0, pBBox->a, 0);
215379 ** 0 x0,y0 is not on or beneath the line segment or the line segment
215393 if( x0<=x1 || x0>x2 ) return 0;
215395 if( x0<=x2 || x0>x1 ) return 0;
215398 if( x0!=x1 ) return 0;
215399 if( y0<y1 && y0<y2 ) return 0;
215400 if( y0>y1 && y0>y2 ) return 0;
215406 return 0;
215414 ** Return 0 if point X,Y is outside the polygon
215421 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
215424 int v = 0;
215425 int cnt = 0;
215429 if( p1==0 ) return;
215430 for(ii=0; ii<p1->nVertex-1; ii++){
215438 GeoX(p1,0), GeoY(p1,0));
215442 }else if( ((v+cnt)&1)==0 ){
215443 sqlite3_result_int(context, 0);
215458 ** Return 0 if any part of P2 is on the outside of P1
215466 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
215467 GeoPoly *p2 = geopolyFuncParam(context, argv[1], 0);
215471 if( x<0 ){
215474 sqlite3_result_int(context, x==2 ? 1 : x==4 ? 2 : 0);
215487 int eType; /* 0 for ADD, 1 for REMOVE */
215539 pEvent->eType = 0;
215560 for(i=0; i<(unsigned)pPoly->nVertex-1; i++){
215562 geopolyAddOneSegment(p, x[0], x[1], x[2], x[3], side, i);
215565 geopolyAddOneSegment(p, x[0], x[1], pPoly->a[0], pPoly->a[1], side, i);
215573 head.pNext = 0;
215594 int mx = 0;
215598 for(i=0; i<nEvent; i++){
215600 p->pNext = 0;
215601 for(j=0; j<mx && a[j]; j++){
215603 a[j] = 0;
215608 p = 0;
215609 for(i=0; i<mx; i++){
215620 head.pNext = 0;
215644 int mx = 0;
215651 p->pNext = 0;
215652 for(i=0; i<mx && a[i]; i++){
215654 a[i] = 0;
215659 p = 0;
215660 for(i=0; i<mx; i++){
215675 int rc = 0;
215676 int needSort = 0;
215677 GeoSegment *pActive = 0;
215685 if( p==0 ) return -1;
215688 p->nEvent = p->nSegment = 0;
215693 memset(aOverlap, 0, sizeof(aOverlap));
215696 GeoSegment *pPrev = 0;
215697 int iMask = 0;
215703 needSort = 0;
215715 pPrev = 0;
215741 if( pThisEvent->eType==0 ){
215751 pActive = ALWAYS(pActive) ? pActive->pNext : 0;
215755 pSeg->pNext = ALWAYS(pSeg->pNext) ? pSeg->pNext->pNext : 0;
215763 if( aOverlap[3]==0 ){
215764 rc = 0;
215765 }else if( aOverlap[1]!=0 && aOverlap[2]==0 ){
215767 }else if( aOverlap[1]==0 && aOverlap[2]!=0 ){
215769 }else if( aOverlap[1]==0 && aOverlap[2]==0 ){
215785 ** 0 The two polygons are disjoint
215797 GeoPoly *p1 = geopolyFuncParam(context, argv[0], 0);
215798 GeoPoly *p2 = geopolyFuncParam(context, argv[1], 0);
215802 if( x<0 ){
215823 geo_debug = sqlite3_value_int(argv[0]);
215833 ** argv[0] -> module name
215865 memset(pRtree, 0, sizeof(Rtree)+nDb+nName*2+8);
215917 assert( *ppVtab==0 );
215947 return geopolyInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
215958 ** that contains polygon argv[0]
215960 ** that contains polygon argv[0]
215971 RtreeNode *pRoot = 0;
215973 int iCell = 0;
215986 i64 iRowid = sqlite3_value_int64(argv[0]);
215987 i64 iNode = 0;
215989 if( rc==SQLITE_OK && pLeaf!=0 ){
215990 p = rtreeSearchPointNew(pCsr, RTREE_ZERO, 0);
215991 assert( p!=0 ); /* Always returns pCsr->sPoint */
215992 pCsr->aNode[0] = pLeaf;
216005 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
216010 assert( argv[0]!=0 );
216011 geopolyBBox(0, argv[0], bbox, &rc);
216017 if( p==0 ){
216020 memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*4);
216021 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
216025 p->iCoord = 0;
216030 p->u.rValue = bbox[0].f;
216042 p->iCoord = 0;
216043 p->u.rValue = bbox[0].f;
216062 if( pNew==0 ){
216067 pNew->iCell = 0;
216070 pCsr->aNode[0] = pRoot;
216071 pRoot = 0;
216100 int idxNum = 0;
216103 for(ii=0; ii<pIdxInfo->nConstraint; ii++){
216106 if( p->iColumn<0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
216110 if( p->iColumn==0 && p->op>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
216119 if( iRowidTerm>=0 ){
216129 if( iFuncTerm>=0 ){
216133 pIdxInfo->aConstraintUsage[iFuncTerm].omit = 0;
216157 if( p==0 ) return SQLITE_OK;
216158 if( i==0 && sqlite3_vtab_nochange(ctx) ) return SQLITE_OK;
216161 if( pCsr->pReadAux==0 ){
216162 rc = sqlite3_prepare_v3(pRtree->db, pRtree->zReadAuxSql, -1, 0,
216163 &pCsr->pReadAux, 0);
216188 ** argv[0] = the rowid to be deleted
216192 ** argv[0] = SQL NULL
216199 ** argv[0] = rowid to modify. Never NULL
216217 int coordChange = 0; /* Change in coordinates */
216228 oldRowidValid = sqlite3_value_type(aData[0])!=SQLITE_NULL;;
216229 oldRowid = oldRowidValid ? sqlite3_value_int64(aData[0]) : 0;
216231 newRowid = newRowidValid ? sqlite3_value_int64(aData[1]) : 0;
216239 assert( aData[2]!=0 );
216240 geopolyBBox(0, aData[2], cell.aCoord, &rc);
216261 rc = rtreeConstraintError(pRtree, 0);
216267 /* If aData[0] is not an SQL NULL value, it is the rowid of a
216281 RtreeNode *pLeaf = 0;
216287 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
216291 rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
216303 int nChange = 0;
216309 GeoPoly *p = 0;
216311 && (p = geopolyFuncParam(0, aData[2], &rc))!=0
216349 if( sqlite3_stricmp(zName, "geopoly_overlap")==0 ){
216351 *ppArg = 0;
216354 if( sqlite3_stricmp(zName, "geopoly_within")==0 ){
216356 *ppArg = 0;
216359 return 0;
216385 0, /* xRelease */
216386 0, /* xRollbackTo */
216406 { geopolyDebugFunc, 1, 0, "geopoly_debug" },
216420 for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
216428 enc, 0,
216429 aFunc[i].xFunc, 0, 0);
216431 for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){
216433 SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS, 0,
216434 0, aAgg[i].xStep, aAgg[i].xFinal);
216437 rc = sqlite3_create_module_v2(db, "geopoly", &geopolyModule, 0, 0);
216455 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
216457 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
216460 rc = sqlite3_create_function(db, "rtreecheck", -1, utf8, 0,rtreecheck, 0,0);
216468 rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);
216472 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
216502 for(i=0; i<p->nParam; i++){
216526 int memErr = 0;
216536 pBlob->cb = pGeomCtx[0];
216539 for(i=0; i<nArg; i++){
216541 if( pBlob->apSqlParam[i]==0 ) memErr = 1;
216572 pGeomCtx->xQueryFunc = 0;
216573 pGeomCtx->xDestructor = 0;
216576 (void *)pGeomCtx, geomCallback, 0, 0, rtreeFreeCallback
216599 pGeomCtx->xGeom = 0;
216604 (void *)pGeomCtx, geomCallback, 0, 0, rtreeFreeCallback
216689 zBuf[127] = '\0';
216716 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
216717 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
216718 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
216719 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
216720 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
216721 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
216722 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
216723 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
216728 if( c>=0xc0 ){ \
216729 c = icuUtf8Trans1[c-0xc0]; \
216730 while( (*zIn & 0xc0)==0x80 ){ \
216731 c = (c<<6) + (0x3f & *(zIn++)); \
216737 if( *(zIn++)>=0xc0 ){ \
216738 while( (*zIn & 0xc0)==0x80 ){zIn++;} \
216745 ** false (0) if they are different.
216755 int prevEscape = 0; /* True if the previous character was uEsc */
216762 if( uPattern==0 ) break;
216781 if( *zString==0 ) return 0;
216787 if( *zPattern==0 ) return 1;
216795 return 0;
216799 if( *zString==0 ) return 0;
216813 return 0;
216815 prevEscape = 0;
216819 return *zString==0;
216840 const unsigned char *zA = sqlite3_value_text(argv[0]);
216842 UChar32 uEsc = 0;
216847 if( sqlite3_value_bytes(argv[0])>SQLITE_MAX_LIKE_PATTERN_LENGTH ){
216859 int i = 0;
216860 if( zE==0 ) return;
216888 ** is 1 if the string matches the pattern, or 0 otherwise.
216917 pExpr = sqlite3_get_auxdata(p, 0);
216919 const UChar *zPattern = sqlite3_value_text16(apArg[0]);
216923 pExpr = uregex_open(zPattern, -1, 0, 0, &status);
216926 sqlite3_set_auxdata(p, 0, pExpr, icuRegexpDelete);
216927 pExpr = sqlite3_get_auxdata(p, 0);
216943 res = uregex_matches(pExpr, 0, &status);
216954 uregex_setText(pExpr, 0, 0, &status);
216956 /* Return 1 or 0. */
216957 sqlite3_result_int(p, res ? 1 : 0);
216988 UChar *zOutput = 0; /* Pointer to output buffer */
216994 const char *zLocale = 0;
216997 bToUpper = (sqlite3_user_data(p)!=0);
217002 zInput = sqlite3_value_text16(apArg[0]);
217006 nOut = nInput = sqlite3_value_bytes16(apArg[0]);
217007 if( nOut==0 ){
217008 sqlite3_result_text16(p, "", 0, SQLITE_STATIC);
217012 for(cnt=0; cnt<2; cnt++){
217014 if( zNew==0 ){
217030 assert( cnt==0 );
217037 assert( 0 ); /* Unreachable */
217068 case UCOL_EQUAL: return 0;
217071 return 0;
217101 zLocale = (const char *)sqlite3_value_text(apArg[0]);
217128 for(i=0; i<sizeof(aStrength)/sizeof(aStrength[0]); i++){
217129 if( sqlite3_stricmp(zOption,aStrength[i].zName)==0 ){
217134 if( i>=sizeof(aStrength)/sizeof(aStrength[0]) ){
217139 for(i=0; i<sizeof(aStrength)/sizeof(aStrength[0]); i++){
217171 {"regexp", 2, SQLITE_ANY|SQLITEICU_EXTRAFLAGS, 0, icuRegexpFunc},
217172 {"lower", 1, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
217173 {"lower", 2, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
217176 {"lower", 1, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
217177 {"lower", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16},
217180 {"like", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuLikeFunc},
217181 {"like", 3, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuLikeFunc},
217187 for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){
217191 p->iContext ? (void*)db : (void*)0,
217192 p->xFunc, 0, 0
217274 int n = 0;
217276 if( argc>0 ){
217277 n = strlen(argv[0])+1;
217283 memset(p, 0, sizeof(IcuTokenizer));
217287 memcpy(p->zLocale, argv[0], n);
217306 ** string to be tokenized is pInput[0..nBytes-1]. A cursor
217324 int iInput = 0;
217325 int iOut = 0;
217327 *ppCursor = 0;
217329 if( zInput==0 ){
217330 nInput = 0;
217332 }else if( nInput<0 ){
217344 memset(pCsr, 0, sizeof(IcuCursor));
217350 while( c>0 ){
217351 int isError = 0;
217363 c = 0;
217403 int iStart = 0;
217404 int iEnd = 0;
217405 int nByte = 0;
217459 0, /* iVersion */
217465 0, /* xLanguageid */
217677 ** of zero or more numeric characters (0-9). This can be significant because
217713 ** with the "rbu_control" column set to contain integer value 0. The
217844 #if 0
218055 ** to a value between 0 and 10000 to indicate the permyriadage progress of
218060 ** (*pnTwo) is set to 0 to indicate that stage 2 has not yet started. The
218166 ** sqlite3_multiplex_initialize(0, 0);
218175 ** zipvfs_create_vfs_v3("zipvfs", "rbu", 0, xCompressorAlgorithmDetector);
218201 #if 0
218221 # define RBU_ENABLE_DELTA_CKSUM 0
218328 #define WAL_LOCK_WRITE 0
218394 /* Output variables. zTbl==0 implies EOF. */
218421 ** 0: Table does not exist (error)
218428 #define RBU_PK_NOTABLE 0
218551 rbu_file *pMainRbu; /* List of main db files with pRbu!=0 */
218558 ** If this is a temporary file (pRbu!=0 && flags&DELETE_ON_CLOSE), variable
218580 rbu_file *pMainRbuNext; /* Next MAIN_DB file with pRbu!=0 */
218586 #define rbuIsVacuum(p) ((p)->zTarget==0)
218611 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
218617 unsigned int v = 0;
218621 while( (c = zValue[0x7f&*(z++)])>=0 ){
218636 unsigned sum0 = 0;
218637 unsigned sum1 = 0;
218638 unsigned sum2 = 0;
218639 unsigned sum3 = 0;
218641 sum0 += ((unsigned)z[0] + z[4] + z[8] + z[12]);
218649 sum0 += z[0];
218660 case 1: sum3 += (z[0] << 24);
218695 unsigned int total = 0;
218706 while( *zDelta && lenDelta>0 ){
218709 switch( zDelta[0] ){
218713 if( lenDelta>0 && zDelta[0]!=',' ){
218750 zOut[0] = 0;
218811 nOrig = sqlite3_value_bytes(argv[0]);
218812 aOrig = (const char*)sqlite3_value_blob(argv[0]);
218818 if( nOut<0 ){
218824 if( aOut==0 ){
218854 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
218857 *ppStmt = 0;
218900 assert( *pzErrmsg==0 );
218901 if( zSql==0 ){
218903 *ppStmt = 0;
218917 for(i=0; i<pIter->nTblCol; i++){
218922 pIter->azTblCol = 0;
218923 pIter->azTblType = 0;
218924 pIter->aiSrcOrder = 0;
218925 pIter->abTblPk = 0;
218926 pIter->abNotNull = 0;
218927 pIter->nTblCol = 0;
218928 pIter->eType = 0; /* Invalid value */
218952 pIter->pSelect = 0;
218953 pIter->pInsert = 0;
218954 pIter->pDelete = 0;
218955 pIter->pRbuUpdate = 0;
218956 pIter->pTmpInsert = 0;
218957 pIter->nCol = 0;
218958 pIter->nIdxCol = 0;
218959 pIter->aIdxCol = 0;
218960 pIter->zIdxSql = 0;
218972 memset(pIter, 0, sizeof(RbuObjIter));
218989 if( pIter->zIdx==0 ){
218995 , 0, 0, &p->zErrmsg
219002 pIter->bCleanup = 0;
219006 pIter->zTbl = 0;
219007 pIter->zDataTbl = 0;
219009 pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
219014 if( pIter->zIdx==0 ){
219023 pIter->zIdx = 0;
219025 pIter->zIdx = (const char*)sqlite3_column_text(pIter->pIdxIter, 0);
219047 ** for a view or 0 for a table.
219051 ** data[0-9]_<name>
219062 ** the second argument is either missing or 0 (not a view).
219073 zIn = (const char*)sqlite3_value_text(argv[0]);
219077 if( argc==1 || 0==sqlite3_value_int(argv[1]) ){
219081 if( strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
219083 for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
219102 memset(pIter, 0, sizeof(RbuObjIter));
219111 , rbuIsVacuum(p) ? "AND rootpage!=0 AND rootpage IS NOT NULL" : ""));
219136 char *zSql = 0;
219141 if( zSql==0 ) p->rc = SQLITE_NOMEM;
219144 zSql = 0;
219166 if( zSql==0 ){
219169 p->rc = sqlite3_exec(db, zSql, 0, 0, &p->zErrmsg);
219188 void *pRet = 0;
219190 assert( nByte>0 );
219192 if( pRet==0 ){
219195 memset(pRet, 0, nByte);
219233 char *zRet = 0;
219313 ** 0) SELECT count(*) FROM sqlite_schema where name=%Q AND IsVirtual(%Q)
219318 sqlite3_stmt *aStmt[4] = {0, 0, 0, 0};
219321 *piPk = 0;
219324 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
219332 if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
219336 if( sqlite3_column_int(aStmt[0], 0) ){
219340 *piTnum = sqlite3_column_int(aStmt[0], 1);
219349 if( zOrig && zIdx && zOrig[0]=='p' ){
219356 *piPk = sqlite3_column_int(aStmt[2], 0);
219371 if( sqlite3_column_int(aStmt[3],5)>0 ){
219381 for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){
219392 sqlite3_stmt *pList = 0;
219393 int bIndex = 0;
219402 pIter->nIndex = 0;
219406 sqlite3_stmt *pXInfo = 0;
219407 if( zIdx==0 ) break;
219409 memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
219416 if( iCid>=0 ) pIter->abIndexed[iCid] = 1;
219418 memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
219432 if( bIndex==0 ) pIter->abIndexed = 0;
219446 if( pIter->azTblCol==0 ){
219447 sqlite3_stmt *pStmt = 0;
219448 int nCol = 0;
219450 int bRbuRowid = 0; /* If input table has column "rbu_rowid" */
219451 int iOrder = 0;
219452 int iTnum = 0;
219455 assert( pIter->eType==0 );
219462 if( pIter->zIdx==0 ) pIter->iTnum = iTnum;
219479 for(i=0; p->rc==SQLITE_OK && i<nCol; i++){
219486 else if( 0==sqlite3_stricmp("rbu_rowid", zName) ){
219491 pStmt = 0;
219494 && rbuIsVacuum(p)==0
219514 if( zName==0 ) break; /* An OOM - finalize() below returns S_NOMEM */
219516 if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
219534 assert( iPk>=0 );
219536 pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0);
219543 assert( pIter->eType!=RBU_PK_VTAB || pIter->abIndexed==0 );
219544 assert( pIter->eType!=RBU_PK_VTAB || pIter->nIndex==0 );
219559 char *zList = 0;
219562 for(i=0; i<pIter->nTblCol; i++){
219584 char *zRet = 0;
219588 for(i=0; i<pIter->nTblCol; i++){
219627 sqlite3_stmt *pMax = 0;
219628 char *zRet = 0;
219636 sqlite3_int64 iMax = sqlite3_column_int64(pMax, 0);
219653 const char *zVal = (const char*)sqlite3_column_text(pMax, 0);
219692 char *zOrder = 0;
219693 char *zLhs = 0;
219694 char *zSelect = 0;
219695 char *zVector = 0;
219696 char *zRet = 0;
219697 int bFailed = 0;
219699 int iCol = 0;
219700 sqlite3_stmt *pXInfo = 0;
219714 if( iCid<0 ){
219717 for(i=0; pIter->abTblPk[i]==0; i++);
219743 sqlite3_stmt *pSel = 0;
219752 for(iCol=0; iCol<pIter->nCol; iCol++){
219754 if( zQuoted==0 ){
219756 }else if( zQuoted[0]=='N' ){
219813 char *zRet = 0; /* String to return */
219814 char *zImpCols = 0; /* String to return via *pzImposterCols */
219815 char *zImpPK = 0; /* String to return via *pzImposterPK */
219816 char *zWhere = 0; /* String to return via *pzWhere */
219817 int nBind = 0; /* Value to return via *pnBind */
219820 sqlite3_stmt *pXInfo = 0; /* PRAGMA index_xinfo = ? */
219823 assert( p->zErrmsg==0 );
219833 const char *zCol = 0;
219837 int iSeq = sqlite3_column_int(pXInfo, 0);
219843 if( iCid<0 ){
219848 for(i=0; pIter->abTblPk[i]==0; i++);
219864 if( pIter->bUnique==0 || sqlite3_column_int(pXInfo, 5) ){
219876 if( zRet==0 || zImpPK==0 || zImpCols==0 || zWhere==0 ) rc = SQLITE_NOMEM;
219890 zRet = 0;
219891 zImpCols = 0;
219892 zImpPK = 0;
219893 zWhere = 0;
219920 char *zList = 0;
219924 for(i=0; i<pIter->nTblCol; i++){
219932 if( zList==0 ){
219960 char *zList = 0;
219966 for(i=0; i<pIter->nTblCol; i++){
219979 for(i=0; i<pIter->nTblCol; i++){
220025 char *zList = 0;
220033 for(i=0; i<pIter->nTblCol; i++){
220075 char *zRet = 0;
220081 for(i=0; i<nBind; i++){
220083 zRet[i*2+1] = (i+1==nBind) ? '\0' : ',';
220102 char *z = 0;
220103 assert( pIter->zIdx==0 );
220106 sqlite3_stmt *pXList = 0; /* PRAGMA index_list = (pIter->zTbl) */
220107 sqlite3_stmt *pXInfo = 0; /* PRAGMA index_xinfo = <pk-index> */
220114 if( zOrig && strcmp(zOrig, "pk")==0 ){
220128 /* int iCid = sqlite3_column_int(pXInfo, 0); */
220163 sqlite3_stmt *pQuery = 0; /* SELECT name ... WHERE rootpage = $tnum */
220164 const char *zIdx = 0; /* Name of PK index */
220165 sqlite3_stmt *pXInfo = 0; /* PRAGMA main.index_xinfo = $zIdx */
220167 char *zCols = 0; /* Used to build up list of table cols */
220168 char *zPk = 0; /* Used to build up table PK declaration */
220179 zIdx = (const char*)sqlite3_column_text(pQuery, 0);
220210 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
220238 char *zSql = 0;
220240 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
220242 for(iCol=0; p->rc==SQLITE_OK && iCol<pIter->nTblCol; iCol++){
220245 const char *zColl = 0;
220248 p->dbMain, "main", pIter->zTbl, zCol, 0, &zColl, 0, 0, 0
220275 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
220299 assert( pIter->pTmpInsert==0 );
220317 assert( sqlite3_value_int(apVal[0])!=0
220321 if( sqlite3_value_int(apVal[0])!=0 ){
220325 for(i=0; rc==SQLITE_OK && i<nVal; i++){
220339 sqlite3_stmt *pStmt = 0;
220341 char *zRet = 0;
220343 assert( pIter->zIdxSql==0 && pIter->nIdxCol==0 && pIter->aIdxCol==0 );
220354 char *zSql = (char*)sqlite3_column_text(pStmt, 0);
220359 int nParen = 0; /* Number of open parenthesis */
220361 int iIdxCol = 0;
220362 int nIdxAlloc = 0;
220363 for(i=0; zSql[i]; i++){
220371 if( aIdxCol==0 ){
220380 if( nParen==0 ){
220381 assert( iIdxCol==0 );
220382 pIter->aIdxCol[0].zSpan = &zSql[i+1];
220388 if( nParen==0 ){
220411 if( zSql[i]=='\0' ) break;
220414 if( zSql[i]=='\0' ) break;
220443 assert( pIter->bCleanup==0 );
220444 if( pIter->pSelect==0 && rbuObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){
220446 char *zCollist = 0; /* List of indexed columns */
220449 char *zLimit = 0;
220458 char *zImposterCols = 0; /* Columns for imposter table */
220459 char *zImposterPK = 0; /* Primary key declaration for imposter */
220460 char *zWhere = 0; /* WHERE clause on PK columns */
220461 char *zBind = 0;
220462 char *zPart = 0;
220463 int nBind = 0;
220473 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
220479 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
220491 if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
220502 char *zStart = 0;
220507 zLimit = 0;
220512 "SELECT %s, 0 AS rbu_control FROM '%q' %s %s %s ORDER BY %s%s",
220587 if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
220595 if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
220604 "SELECT *%s FROM '%q' WHERE 0;"
220606 , (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
220634 " SELECT rbu_tmp_insert(0, %s);"
220646 char *zStart = 0;
220647 char *zOrder = 0;
220657 zLimit = 0;
220672 (rbuIsVacuum(p) ? "0 AS " : ""),
220712 RbuUpdateStmt *pUp = 0;
220713 int nUp = 0;
220716 *ppStmt = 0;
220724 if( strcmp(pUp->zMask, zMask)==0 ){
220733 assert( pUp==0 || pUp->pNext==0 );
220737 *pp = 0;
220739 pUp->pUpdate = 0;
220747 char *zUpdate = 0;
220778 sqlite3 *db = 0;
220781 p->rc = sqlite3_open_v2(zName, &db, flags, bUseVfs ? p->zVfsName : 0);
220785 db = 0;
220813 RbuState *pRet = 0;
220814 sqlite3_stmt *pStmt = 0;
220819 if( pRet==0 ) return 0;
220825 switch( sqlite3_column_int(pStmt, 0) ){
220894 assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
220895 assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
220896 assert( dbMain==0 || rbuIsVacuum(p)==0 );
220904 if( p->zState==0 ){
220919 #if 0
220921 p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, 0);
220928 #if 0
220932 int bOk = 0;
220933 sqlite3_stmt *pCnt = 0;
220939 && 1==sqlite3_column_int(pCnt, 0)
220946 if( p->rc==SQLITE_OK && bOk==0 ){
220952 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
220959 int bOpen = 0;
220961 p->nRbu = 0;
220962 p->pRbuFd = 0;
220977 p->eStage = 0;
220978 if( p->rc==SQLITE_OK && p->dbMain==0 ){
220983 p->pRbuFd->bNolock = 0;
220986 p->dbMain = 0;
220987 p->dbRbu = 0;
220995 char *zExtra = 0;
220996 if( strlen(p->zRbu)>=5 && 0==memcmp("file:", p->zRbu, 5) ){
221001 if( *zExtra=='\0' ) zExtra = 0;
221006 (zExtra==0 ? "" : "&"), (zExtra==0 ? "" : zExtra)
221009 if( zTarget==0 ){
221020 "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
221026 "rbu_fossil_delta", 2, SQLITE_UTF8, 0, rbuFossilDeltaFunc, 0, 0
221032 "rbu_target_name", -1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
221077 if( sqlite3_uri_boolean(zBase, "8_3_names", 0) )
221081 sz = (int)strlen(z)&0xffffff;
221082 for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){}
221096 i64 iRet = 0;
221100 p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, (void volatile**)&ptr);
221129 if( pState==0 ){
221130 p->eStage = 0;
221132 p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_schema", 0, 0, 0);
221167 rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
221171 if( p->rc==SQLITE_OK && p->nFrame>0 ){
221173 p->nStep = (pState ? pState->nRow : 0);
221179 if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){
221186 assert( p->nPagePerSector==0 );
221222 if( aNew==0 ) return SQLITE_NOMEM;
221230 pRbu->aFrame[pRbu->nFrame].iDbPage = 0;
221276 sqlite3_file *fd = 0;
221305 const char *zUri = sqlite3_db_filename(db, 0);
221306 return sqlite3_uri_boolean(zUri, RBU_EXCLUSIVE_CHECKPOINT, 0);
221314 nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
221315 if( nChar==0 ){
221316 return 0;
221318 zWideFilename = sqlite3_malloc64( nChar*sizeof(zWideFilename[0]) );
221319 if( zWideFilename==0 ){
221320 return 0;
221322 memset(zWideFilename, 0, nChar*sizeof(zWideFilename[0]));
221323 nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename,
221325 if( nChar==0 ){
221327 zWideFilename = 0;
221353 assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
221354 if( zWal==0 || zOal==0 ){
221364 sqlite3 *dbMain = 0;
221372 p->dbMain = 0;
221373 p->dbRbu = 0;
221387 || rbuExclusiveCheckpoint(dbMain)==0
221390 dbMain = 0;
221394 rbuOpenDatabase(p, dbMain, 0);
221395 rbuSetupCheckpoint(p, 0);
221422 int res = 0; /* Return value */
221428 case 0: res = RBU_INSERT; break;
221439 if( z==0 ){
221453 if( res==0 ){
221465 assert( 0==sqlite3_stricmp(zName, zCol) );
221483 assert( eType!=RBU_DELETE || pIter->zIdx==0 );
221502 for(i=0; i<pIter->nCol; i++){
221507 && pIter->zIdx==0 && pIter->eType==RBU_PK_IPK && pIter->abTblPk[i]
221515 if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){
221523 if( pIter->zIdx==0 ){
221561 const char *zMask = 0;
221569 assert( eType!=RBU_UPDATE || pIter->zIdx==0 );
221571 if( pIter->zIdx==0 && (eType==RBU_IDX_DELETE || eType==RBU_IDX_INSERT) ){
221575 if( pIter->zIdx==0 ){
221586 sqlite3_stmt *pUpdate = 0;
221592 for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
221640 iCookie = sqlite3_column_int(pStmt, 0);
221657 sqlite3_stmt *pInsert = 0;
221661 assert( p->zErrmsg==0 );
221688 assert( pInsert==0 || rc==SQLITE_OK );
221718 sqlite3_stmt *pPragma = 0;
221724 zPragma, sqlite3_column_int(pPragma, 0)
221737 sqlite3_stmt *pSql = 0;
221738 sqlite3_stmt *pInsert = 0;
221741 p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
221744 "SELECT sql FROM sqlite_schema WHERE sql!='' AND rootpage!=0"
221751 const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
221752 p->rc = sqlite3_exec(p->dbMain, zSql, 0, 0, &p->zErrmsg);
221759 "SELECT * FROM sqlite_schema WHERE rootpage=0 OR rootpage IS NULL"
221771 for(i=0; i<5; i++){
221778 p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=0",0,0,&p->zErrmsg);
221796 if( rbuIsVacuum(p) && p->nProgress==0 && p->rc==SQLITE_OK ){
221808 if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
221814 rbuObjIterPrepareAll(p, pIter, 0);
221825 p->nStep = 0;
221833 assert( pIter->zTbl==0 );
221837 p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
221840 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
221866 p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, &ptr);
221913 ** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
221918 if( z1==0 && z2==0 ) return 0;
221919 if( z1==0 || z2==0 ) return 1;
221920 return (sqlite3_stricmp(z1, z2)!=0);
221941 || (pState->zDataTbl==0 && rbuStrCompare(pIter->zTbl, pState->zTbl))
221969 sqlite3_vfs *pVfs = 0;
221971 assert( pVfs && p->rc==SQLITE_OK && p->zErrmsg==0 );
221972 pVfs->xDelete(pVfs, zOal, 0);
221990 p->rc = sqlite3rbu_create_vfs(zRnd, 0);
222006 p->zVfsName = 0;
222021 sqlite3_stmt *pStmt = 0;
222022 char *zErrmsg = 0;
222030 "WHERE type='index' AND tbl_name = %Q", sqlite3_value_text(apVal[0]))
222035 int nIndex = 0;
222037 nIndex = sqlite3_column_int(pStmt, 0);
222067 sqlite3_stmt *pStmt = 0;
222068 int bExists = 0; /* True if rbu_count exists */
222073 "rbu_index_cnt", 1, SQLITE_UTF8, (void*)p, rbuIndexCntFunc, 0, 0
222097 p->nPhaseOneStep = sqlite3_column_int64(pStmt, 0);
222112 size_t nTarget = zTarget ? strlen(zTarget) : 0;
222118 RbuState *pState = 0;
222121 memset(p, 0, sizeof(sqlite3rbu));
222122 sqlite3rbu_rename_handler(p, 0, 0);
222128 int bRetry = 0;
222148 rbuOpenDatabase(p, 0, &bRetry);
222150 rbuOpenDatabase(p, 0, 0);
222159 if( pState->eStage==0 ){
222171 assert( p->rc!=SQLITE_OK || p->eStage!=0 );
222179 p->nStep = 0;
222185 && pState->eStage!=0
222203 p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, &p->zErrmsg);
222212 if( p->rc==SQLITE_OK && p->objiter.zTbl==0 ){
222216 if( p->rc==SQLITE_OK && pState->eStage==0 && rbuIsVacuum(p) ){
222224 p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
222231 int frc = sqlite3_file_control(db, "main", SQLITE_FCNTL_ZIPVFS, 0);
222234 db, "PRAGMA journal_mode=off",0,0,&p->zErrmsg);
222275 memset(pRet, 0, sizeof(sqlite3rbu));
222289 if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); }
222300 if( zTarget==0 ){ return rbuMisuseError(); }
222303 if( n>=7 && 0==memcmp("-vactmp", &zState[n-7], 7) ){
222308 return openRbuHandle(0, zTarget, zState);
222315 sqlite3 *db = 0;
222326 ** the pattern "rbu_imp_[0-9]*".
222332 for(i=0; i<(nErrmsg-8); i++){
222333 if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
222335 while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
222352 p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
222364 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
222376 int rc2 = sqlite3_exec(p->dbRbu, "DELETE FROM stat.rbu_state", 0, 0, 0);
222383 assert( p->szTemp==0 );
222399 *pzErrmsg = 0;
222421 if( p->nPhaseOneStep>0 ){
222426 *pnTwo = 0;
222431 *pnTwo = 0;
222445 assert( 0 );
222454 0, SQLITE_RBU_STATE_OAL, SQLITE_RBU_STATE_MOVE,
222455 0, SQLITE_RBU_STATE_CHECKPOINT, SQLITE_RBU_STATE_DONE
222487 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, 0);
222502 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
222505 rc = sqlite3_exec(p->dbRbu, zBegin, 0, 0, 0);
222507 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0,0);
222558 pRbu->pRenameArg = 0;
222626 for(i=0; i<SQLITE_SHM_NLOCK;i++){
222631 p->pRbu->mLock = 0;
222642 assert( pRbu->szTemp>=0 );
222651 ** for all file descriptors with rbu_file.pDb!=0. If the argument has
222652 ** rbu_file.pDb!=0, then it is assumed to already be present on the
222653 ** main list and is only added to the pDb!=0 list.
222660 if( p->pRbu==0 ){
222666 if( pIter==0 ){
222682 p->pMainNext = 0;
222685 p->pMainRbuNext = 0;
222696 ** rbu_file.pDb!=0.
222719 for(i=0; i<p->nShm; i++){
222723 p->apShm = 0;
222731 pMeth->xShmUnmap(p->pReal, 0);
222735 rbuUpdateTempSize(p, 0);
222737 assert( p->pMainNext==0 && p->pRbuVfs->pMain!=p );
222750 return ((u32)aBuf[0] << 24)
222761 aBuf[0] = (iVal >> 24) & 0xFF;
222762 aBuf[1] = (iVal >> 16) & 0xFF;
222763 aBuf[2] = (iVal >> 8) & 0xFF;
222764 aBuf[3] = (iVal >> 0) & 0xFF;
222768 aBuf[0] = (iVal >> 8) & 0xFF;
222769 aBuf[1] = (iVal >> 0) & 0xFF;
222794 memset(zBuf, 0, iAmt);
222803 && rc==SQLITE_IOERR_SHORT_READ && iOfst==0
222811 u32 iRoot = rbuGetU32(&aBuf[52]) ? 1 : 0;
222813 rbuPutU32(&aBuf[36], 0); /* number of free pages */
222814 rbuPutU32(&aBuf[32], 0); /* first page on free list trunk */
222819 memset(&aBuf[100], 0, iAmt-100);
222820 rbuPutU16(&aBuf[105], iAmt & 0xFFFF);
222821 aBuf[100] = 0x0D;
222827 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
222870 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
222919 if( rc==SQLITE_OK && *pSize==0
222988 void *dummy = 0;
223016 if( zOut==0 ) rc = SQLITE_NOMEM;
223061 int bCapture = 0;
223065 if( bCapture==0 || 0==(flags & SQLITE_SHM_UNLOCK) ){
223088 int eStage = (p->pRbu ? p->pRbu->eStage : 0);
223103 if( apNew==0 ){
223106 memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm));
223113 if( pNew==0 ){
223116 memset(pNew, 0, szRegion);
223124 *pp = 0;
223127 assert( p->apShm==0 );
223148 int eStage = (p->pRbu ? p->pRbu->eStage : 0);
223189 0, 0 /* xFetch, xUnfetch */
223205 0, 0, 0, 0, 0, 0
223217 memset(pFd, 0, sizeof(rbu_file));
223231 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName, 0);
223252 && sqlite3_uri_boolean(zName, "rbu_memory", 0)
223257 zOpen = 0;
223268 if( pMeth->iVersion<2 || pMeth->xShmLock==0 ){
223328 sqlite3_int64 sz = 0;
223330 *pResOut = (sz>0);
223423 return 0;
223449 0, /* szOsFile */
223450 0, /* mxPathname */
223451 0, /* pNext */
223452 0, /* zName */
223453 0, /* pAppData */
223465 0, 0, 0, 0,
223472 0, /* xCurrentTimeInt64 (version 2) */
223473 0, 0, 0 /* Unimplemented version 3 methods */
223476 rbu_vfs *pNew = 0; /* Newly allocated VFS */
223484 if( pNew==0 ){
223488 memset(pNew, 0, nByte);
223490 if( pParent==0 ){
223503 if( pNew->mutex==0 ){
223506 rc = sqlite3_vfs_register(&pNew->base, 0);
223523 if( n>=0 ){
223609 " name TEXT," /* 0 Name of table or index */
223613 " ncell INTEGER," /* 4 Cells on page (0 for overflow) */
223633 u32 iChildPg; /* Child node (or 0 if this is a leaf) */
223652 u32 iRightChildPg; /* Right-child page number (or 0) */
223689 # define get2byte(x) ((x)[0]<<8 | (x)[1])
223702 StatTable *pTab = 0;
223711 if( iDb<0 ){
223716 iDb = 0;
223722 if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
223725 assert( rc==SQLITE_OK || pTab==0 );
223727 memset(pTab, 0, sizeof(StatTable));
223749 ** 0x01 There is a schema=? term in the WHERE clause
223750 ** 0x02 There is a name=? term in the WHERE clause
223751 ** 0x04 There is an aggregate=? term in the WHERE clause
223752 ** 0x08 Output should be ordered by name and path
223766 for(i=0; i<pIdxInfo->nConstraint; i++){
223768 if( pIdxInfo->aConstraint[i].usable==0 ){
223773 case 0: { /* name */
223787 i = 0;
223788 if( iSchema>=0 ){
223791 pIdxInfo->idxNum |= 0x01;
223793 if( iName>=0 ){
223795 pIdxInfo->idxNum |= 0x02;
223797 if( iAgg>=0 ){
223799 pIdxInfo->idxNum |= 0x04;
223808 && pIdxInfo->aOrderBy[0].iColumn==0
223809 && pIdxInfo->aOrderBy[0].desc==0
223812 && pIdxInfo->aOrderBy[0].iColumn==0
223813 && pIdxInfo->aOrderBy[0].desc==0
223815 && pIdxInfo->aOrderBy[1].desc==0
223819 pIdxInfo->idxNum |= 0x08;
223833 if( pCsr==0 ){
223836 memset(pCsr, 0, sizeof(StatCursor));
223848 for(i=0; i<p->nCell; i++){
223853 p->nCell = 0;
223854 p->aCell = 0;
223861 memset(p, 0, sizeof(StatPage));
223871 for(i=0; i<ArraySize(pCsr->aPage); i++){
223874 pCsr->aPage[i].aPg = 0;
223877 pCsr->iPage = 0;
223879 pCsr->zPath = 0;
223880 pCsr->isEof = 0;
223885 pCsr->nCell = 0;
223886 pCsr->nMxPayload = 0;
223887 pCsr->nUnused = 0;
223888 pCsr->nPayload = 0;
223889 pCsr->szPage = 0;
223890 pCsr->nPage = 0;
223918 if( flags==0x0D ){ /* Table leaf node */
223942 u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0];
223944 p->flags = aHdr[0];
223945 if( p->flags==0x0A || p->flags==0x0D ){
223948 }else if( p->flags==0x05 || p->flags==0x02 ){
223949 isLeaf = 0;
223956 p->nMxPayload = 0;
223967 if( iNext<iOff+4 && iNext>0 ) goto statPageIsCorrupt;
223971 p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]);
223981 if( p->aCell==0 ) return SQLITE_NOMEM_BKPT;
223982 memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell));
223984 for(i=0; i<p->nCell; i++){
223993 if( p->flags==0x05 ){
223994 /* A table interior node. nPayload==0. */
223999 if( p->flags==0x0D ){
224005 if( nLocal<0 ) goto statPageIsCorrupt;
224012 if( iOff+nLocal+4>nUsable || nPayload>0x7fffffff ){
224018 if( pCell->aOvfl==0 ) return SQLITE_NOMEM_BKPT;
224019 pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]);
224023 DbPage *pPg = 0;
224024 rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg, 0);
224026 assert( pPg==0 );
224040 p->flags = 0;
224060 x[0] = pCsr->iPageno;
224062 pCsr->iOffset = x[0];
224082 DbPage *pDbPage = 0;
224085 if( pPg->aPg==0 ){
224087 if( pPg->aPg==0 ){
224090 memset(&pPg->aPg[pgsz], 0, DBSTAT_PAGE_PADDING_BYTES);
224093 rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPg, &pDbPage, 0);
224105 ** entry will be the next page, but in aggregated mode (pCsr->isAgg!=0),
224118 pCsr->zPath = 0;
224121 if( pCsr->iPage<0 ){
224129 if( nPage==0 ){
224133 rc = statGetPage(pBt, iRoot, &pCsr->aPage[0]);
224134 pCsr->aPage[0].iPgno = iRoot;
224135 pCsr->aPage[0].iCell = 0;
224137 pCsr->aPage[0].zPath = z = sqlite3_mprintf("/");
224138 if( z==0 ) rc = SQLITE_NOMEM_BKPT;
224140 pCsr->iPage = 0;
224169 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
224175 return z==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
224185 if( pCsr->isAgg && pCsr->iPage<0 ){
224206 p[1].iCell = 0;
224209 if( z==0 ) rc = SQLITE_NOMEM_BKPT;
224221 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
224229 case 0x05: /* table internal */
224230 case 0x02: /* index internal */
224233 case 0x0D: /* table leaf */
224234 case 0x0A: /* index leaf */
224246 if( z==0 ) rc = SQLITE_NOMEM_BKPT;
224248 nPayload = 0;
224249 for(i=0; i<p->nCell; i++){
224270 ** arguments in argv[0]. See statBestIndex() for a description of the
224282 int iArg = 0; /* Count of argv[] parameters used so far */
224284 const char *zName = 0; /* Only provide analysis of this table */
224290 pCsr->pStmt = 0;
224291 if( idxNum & 0x01 ){
224295 if( pCsr->iDb<0 ){
224296 pCsr->iDb = 0;
224303 if( idxNum & 0x02 ){
224307 if( idxNum & 0x04 ){
224311 pCsr->isAgg = 0;
224319 " FROM \"%w\".sqlite_schema WHERE rootpage!=0)",
224324 if( idxNum & 0x08 ){
224328 if( zSql==0 ){
224331 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
224349 case 0: /* name */
224414 0, /* iVersion */
224427 0, /* xUpdate */
224428 0, /* xBegin */
224429 0, /* xSync */
224430 0, /* xCommit */
224431 0, /* xRollback */
224432 0, /* xFindMethod */
224433 0, /* xRename */
224434 0, /* xSavepoint */
224435 0, /* xRelease */
224436 0, /* xRollbackTo */
224437 0, /* xShadowName */
224438 0 /* xIntegrity */
224440 return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
224504 #define DBPAGE_COLUMN_PGNO 0
224520 DbpageTable *pTab = 0;
224533 if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
224536 assert( rc==SQLITE_OK || pTab==0 );
224538 memset(pTab, 0, sizeof(DbpageTable));
224557 ** 0 schema=main, full table scan
224564 int iPlan = 0;
224571 for(i=0; i<pIdxInfo->nConstraint; i++){
224592 for(i=0; i<pIdxInfo->nConstraint; i++){
224594 if( p->usable && p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
224607 && pIdxInfo->aOrderBy[0].iColumn<=0
224608 && pIdxInfo->aOrderBy[0].desc==0
224622 if( pCsr==0 ){
224625 memset(pCsr, 0, sizeof(DbpageCursor));
224662 ** 0 schema=main, full table scan
224684 pCsr->mxPgno = 0;
224689 zSchema = (const char*)sqlite3_value_text(argv[0]);
224691 if( pCsr->iDb<0 ) return SQLITE_OK;
224693 pCsr->iDb = 0;
224696 if( NEVER(pBt==0) ) return SQLITE_OK;
224705 pCsr->mxPgno = 0;
224713 rc = sqlite3PagerGet(pCsr->pPager, 1, &pCsr->pPage1, 0);
224725 case 0: { /* pgno */
224730 DbPage *pDbPage = 0;
224736 rc = sqlite3PagerGet(pCsr->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0);
224768 DbPage *pDbPage = 0;
224770 char *zErr = 0;
224786 pgno = sqlite3_value_int(argv[0]);
224787 if( sqlite3_value_type(argv[0])==SQLITE_NULL
224795 if( NEVER(iDb<0) ){
224800 if( NEVER(pgno<1) || NEVER(pBt==0) || NEVER(pgno>sqlite3BtreeLastPage(pBt)) ){
224812 rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pDbPage, 0);
224815 assert( pData!=0 || pTab->db->mallocFailed );
224839 for(i=0; i<db->nDb; i++){
224841 if( pBt ) (void)sqlite3BtreeBeginTrans(pBt, 1, 0);
224852 0, /* iVersion */
224867 0, /* xSync */
224868 0, /* xCommit */
224869 0, /* xRollback */
224870 0, /* xFindMethod */
224871 0, /* xRename */
224872 0, /* xSavepoint */
224873 0, /* xRelease */
224874 0, /* xRollbackTo */
224875 0, /* xShadowName */
224876 0 /* xIntegrity */
224878 return sqlite3_create_module(db, "sqlite_dbpage", &dbpage_module, 0);
225046 ** 0x00: Undefined value.
225047 ** 0x01: Integer value.
225048 ** 0x02: Real value.
225049 ** 0x03: Text value.
225050 ** 0x04: Blob value.
225051 ** 0x05: SQL NULL value.
225085 ** 1 byte: Constant 0x54 (capital 'T')
225087 ** nCol bytes: 0x01 for PK columns, 0x00 otherwise.
225092 ** 1 byte: Either SQLITE_INSERT (0x12), UPDATE (0x17) or DELETE (0x09).
225107 ** of INSERT or DELETE changes never contain any undefined (type byte 0x00)
225127 ** 1 byte: Constant 0x50 (capital 'P')
225129 ** nCol bytes: 0x01 for PK columns, 0x00 otherwise.
225134 ** 1 byte: Either SQLITE_INSERT (0x12), UPDATE (0x17) or DELETE (0x09).
225170 ** 1 byte: Constant 0x54 (capital 'T')
225172 ** nCol bytes: 0x01 for PK columns, 0x00 otherwise.
225177 ** 1 byte: Either SQLITE_INSERT (0x12), DELETE (0x09).
225178 ** 1 byte: Flag. 0x01 for REPLACE, 0x00 for OMIT.
225183 ** it was a DELETE. The second field is set to 0x01 if the conflict
225184 ** resolution strategy was REPLACE, or 0x00 if it was OMIT.
225232 #define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
225249 aBuf[0] = (i>>56) & 0xFF;
225250 aBuf[1] = (i>>48) & 0xFF;
225251 aBuf[2] = (i>>40) & 0xFF;
225252 aBuf[3] = (i>>32) & 0xFF;
225253 aBuf[4] = (i>>24) & 0xFF;
225254 aBuf[5] = (i>>16) & 0xFF;
225255 aBuf[6] = (i>> 8) & 0xFF;
225256 aBuf[7] = (i>> 0) & 0xFF;
225283 if( aBuf ) aBuf[0] = eType;
225322 if( z==0 && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
225327 if( n>0 ) memcpy(&aBuf[nVarint + 1], z, n);
225336 if( aBuf ) aBuf[0] = '\0';
225372 ** hash_key_value = HASH_APPEND(0, <value 1>);
225386 h = HASH_APPEND(h, i & 0xFFFFFFFF);
225387 return HASH_APPEND(h, (i>>32)&0xFFFFFFFF);
225396 for(i=0; i<n; i++) h = HASH_APPEND(h, z[i]);
225427 unsigned int h = 0; /* Hash value to return */
225434 assert( *pbNullPK==0 );
225436 for(i=0; i<pTab->nCol; i++){
225470 if( !z && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
225474 assert( pTab->bStat1==0 || i!=1 );
225493 assert( a!=0 );
225495 if( e==0 || e==0xFF ) return 1;
225516 unsigned int h = 0; /* Value to return */
225520 for(i=0; i<pTab->nCol; i++){
225523 if( bPkOnly && isPK==0 ) continue;
225530 || eType==SQLITE_NULL || eType==0
225532 assert( !isPK || (eType!=0 && eType!=SQLITE_NULL) );
225570 for(iCol=0; iCol<pTab->nCol; iCol++){
225576 return 0;
225581 if( bLeftPkOnly==0 ) a1 += sessionSerialLen(a1);
225582 if( bRightPkOnly==0 ) a2 += sessionSerialLen(a2);
225611 int iCol; /* Used to iterate from 0 to nCol */
225613 for(iCol=0; iCol<nCol; iCol++){
225638 ** *paTwo[0] is not 0x00 - the "no value" placeholder), a copy of the *paTwo
225655 u8 *pRet = 0;
225669 if( pRet==0 ){
225699 if( bPatchset==0 ){
225700 int bRequired = 0;
225705 for(i=0; i<pTab->nCol; i++){
225714 if( pTab->abPK[i]==0 ) bRequired = 1;
225718 *(aOut++) = '\0';
225722 if( !bRequired ) return 0;
225730 for(i=0; i<pTab->nCol; i++){
225738 if( bPatchset==0
225739 && (pTab->abPK[i] || (nOld==nNew && 0==memcmp(aOld, aNew, nNew)))
225741 *(aOut++) = '\0';
225770 if( a[0]!=SQLITE_INTEGER ) return 0;
225775 for(iCol=0; iCol<pTab->nCol; iCol++){
225797 if( sqlite3_value_type(pVal)!=eType ) return 0;
225808 if( sqlite3_value_int64(pVal)!=iVal ) return 0;
225813 if( sqlite3_value_double(pVal)!=rVal ) return 0;
225819 if( sqlite3_value_bytes(pVal)!=n ) return 0;
225825 if( n>0 && memcmp(a, z, n) ) return 0;
225850 if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){
225858 if( apNew==0 ){
225859 if( pTab->nChange==0 ){
225864 memset(apNew, 0, sizeof(SessionChange *) * nNew);
225866 for(i=0; i<pTab->nChange; i++){
225907 ** *pabPK = {1, 0, 0, 1}
225928 int nDbCol = 0;
225931 u8 *pAlloc = 0;
225932 char **azCol = 0;
225933 char **azDflt = 0;
225934 u8 *abPK = 0;
225935 int bRowid = 0; /* Set to true to use rowid as PK */
225939 *pazCol = 0;
225940 *pabPK = 0;
225941 *pnCol = 0;
225942 if( pzTab ) *pzTab = 0;
225943 if( pazDflt ) *pazDflt = 0;
225946 if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){
225947 rc = sqlite3_table_column_metadata(db, zDb, zThis, 0, 0, 0, 0, 0, 0);
225951 "SELECT 0, 'tbl', '', 0, '', 1 UNION ALL "
225952 "SELECT 1, 'idx', '', 0, '', 2 UNION ALL "
225953 "SELECT 2, 'stat', '', 0, '', 0"
225967 rc = sqlite3_prepare_v2(db, zPragma, -1, &pStmt, 0);
225974 bRowid = (pbRowid!=0);
225979 if( sqlite3_column_int(pStmt, 5) ) bRowid = 0; /* pk */
225981 if( nDbCol==0 ) bRowid = 0;
225989 if( pAlloc==0 ){
225992 memset(pAlloc, 0, nByte);
226007 i = 0;
226022 if( zName==0 ) break;
226031 azDflt[i] = 0;
226074 if( pTab->nCol==0 ){
226076 assert( pTab->azCol==0 || pTab->abPK==0 );
226078 pTab->zName, &pTab->nCol, 0, &pTab->azCol, &pTab->azDflt, &abPK,
226079 ((pSession==0 || pSession->bImplicitPK) ? &pTab->bRowid : 0)
226083 for(i=0; i<pTab->nCol; i++){
226089 if( 0==sqlite3_stricmp("sqlite_stat1", pTab->zName) ){
226103 return (rc || pTab->abPK==0);
226112 int nCol = 0;
226113 const char **azCol = 0;
226114 const char **azDflt = 0;
226115 u8 *abPK = 0;
226116 int bRowid = 0;
226121 pTab->zName, &nCol, 0, &azCol, &azDflt, &abPK,
226122 (pSession->bImplicitPK ? &bRowid : 0)
226130 for(ii=0; ii<nCol; ii++){
226175 SessionChange *pNew = 0;
226176 int nByte = 0;
226177 int nIncr = 0;
226198 if( pNew==0 ){
226216 i64 iVal = 0;
226265 #define SESSION_MAX_BUFFER_SZ (0x7FFFFF00 - 1)
226289 if( 0==aNew ){
226314 if( 0==sessionBufferGrow(p, nStr+1, pRc) ){
226317 p->aBuf[p->nBuf] = 0x00;
226332 char *zApp = 0;
226336 if( zApp==0 ){
226362 SessionBuffer sql = {0,0,0};
226365 int ii = 0;
226367 *ppStmt = 0;
226369 for(ii=0; ii<pTab->nCol; ii++){
226375 rc = sqlite3_prepare_v2(db, (const char*)sql.aBuf, -1, ppStmt, 0);
226388 sqlite3_stmt *pStmt = 0;
226393 int ii = 0;
226394 SessionChange **pp = 0;
226395 for(ii=0; ii<pTab->nChange; ii++){
226423 sqlite3_value *pVal = 0;
226433 sqlite3_value *pVal = 0;
226461 for(ii=0; ii<pTab->nCol; ii++){
226462 sqlite3_value *p = 0;
226464 sessionSerializeValue(0, p, &nNew);
226469 if( sqlite3_preupdate_blobwrite(pSession->db)>=0 ){
226481 int nOld = 0;
226483 sqlite3_value *p = 0;
226485 if( p==0 ){
226520 && (nByte==0 || 0==memcmp(pCsr, sqlite3_value_blob(p), nByte))
226522 bChanged = 0;
226536 sessionSerializeValue(0, p, &nNew);
226568 int bNull = 0;
226570 int nExpect = 0;
226571 SessionStat1Ctx stat1 = {{0,0,0,0,0},0};
226591 if( sessionGrowHash(pSession, 0, pTab) ){
226604 if( pSession->pZeroBlob==0 ){
226605 sqlite3_value *p = sqlite3ValueNew(0);
226606 if( p==0 ){
226610 sqlite3ValueSetStr(p, 0, "", 0, SQLITE_STATIC);
226623 if( bNull==0 ){
226630 if( pC==0 ){
226642 for(i=0; i<(pTab->nCol-pTab->bRowid); i++){
226643 sqlite3_value *p = 0;
226654 rc = sessionSerializeValue(0, p, &nByte);
226667 memset(pC, 0, sizeof(SessionChange));
226675 nByte = 0;
226677 pC->aRecord[0] = SQLITE_INTEGER;
226681 for(i=0; i<(pTab->nCol-pTab->bRowid); i++){
226682 sqlite3_value *p = 0;
226704 if( pSession->hook.xDepth(pSession->hook.pCtx)==0
226705 && pSession->bIndirect==0
226707 pC->bIndirect = 0;
226739 if( 0==sqlite3_strnicmp(pRet->zName, zName, nName+1) ) break;
226742 if( pRet==0 && pSession->bAutoAttach ){
226743 /* If there is a table-filter configured, invoke it. If it returns 0,
226745 if( pSession->xTableFilter==0
226754 assert( pRet!=0 );
226755 assert( 0==sqlite3_strnicmp(pRet->zName, zName, nName+1) );
226760 assert( rc==SQLITE_OK || pRet==0 );
226790 if( pSession->bEnable==0 ) continue;
226862 return 0;
226888 char *zRet = 0;
226890 for(i=0; i<nCol; i++){
226896 if( zRet==0 ) break;
226911 char *zRet = 0;
226912 int bHave = 0;
226914 for(i=0; i<nCol; i++){
226915 if( abPK[i]==0 ){
226922 if( zRet==0 ) break;
226926 if( bHave==0 ){
226927 assert( zRet==0 );
226928 zRet = sqlite3_mprintf("0");
226964 if( zStmt==0 ){
226968 rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
226972 pDiffCtx->nOldOff = 0;
226975 i64 iRowid = (pTab->bRowid ? sqlite3_column_int64(pStmt, 0) : 0);
226997 char *zRet = 0;
226998 for(ii=0; ii<pTab->nCol; ii++){
227018 if( zExpr2==0 ){
227027 if( zStmt==0 || z1==0 || z2==0 ){
227031 rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
227038 i64 iRowid = (pTab->bRowid ? sqlite3_column_int64(pStmt, 0) : 0);
227062 memset(&d, 0, sizeof(d));
227066 if( pzErrMsg ) *pzErrMsg = 0;
227068 char *zExpr = 0;
227074 if( pTo==0 ) goto diff_out;
227082 int bHasPk = 0;
227083 int bMismatch = 0;
227085 int bRowid = 0;
227087 const char **azCol = 0;
227088 rc = sessionTableInfo(0, db, zFrom, zTbl, &nCol, 0, &azCol, 0, &abPK,
227089 pSession->bImplicitPK ? &bRowid : 0
227096 for(i=0; i<nCol; i++){
227110 if( bHasPk==0 ){
227160 *ppSession = 0;
227165 memset(pNew, 0, sizeof(sqlite3_session));
227195 for(i=0; i<pTab->nChange; i++){
227221 pHead = (sqlite3_session*)sqlite3_preupdate_hook(db, 0, 0);
227222 for(pp=&pHead; ALWAYS((*pp)!=0); pp=&((*pp)->pNext)){
227278 if( 0==sqlite3_strnicmp(pTab->zName, zName, nName+1) ) break;
227294 memset(pTab, 0, sizeof(SessionTable));
227318 sqlite3_int64 nByte = 0;
227319 rc = sessionSerializeValue(0, pVal, &nByte);
227322 rc = sessionSerializeValue(&p->aBuf[p->nBuf], pVal, 0);
227338 if( 0==sessionBufferGrow(p, 1, pRc) ){
227351 if( 0==sessionBufferGrow(p, 9, pRc) ){
227369 if( nBlob>0 && 0==sessionBufferGrow(p, nBlob, pRc) ){
227408 if( 0==sessionBufferGrow(p, nStr, pRc) ){
227418 p->aBuf[p->nBuf] = 0x00;
227458 if( z || (eType==SQLITE_BLOB && nByte==0) ){
227474 ** 1 byte: SQLITE_UPDATE (0x17)
227492 int bPatchset, /* True for "patchset", 0 for "changeset" */
227498 SessionBuffer buf2 = {0,0,0}; /* Buffer to accumulate new.* record in */
227504 assert( abPK!=0 );
227507 for(i=0; i<sqlite3_column_count(pStmt); i++){
227508 int bChanged = 0;
227543 && (n==0 || 0==memcmp(&pCsr[nHdr], sqlite3_column_blob(pStmt, i), n))
227552 if( bChanged ) bNoop = 0;
227556 if( bPatchset==0 ){
227560 sessionAppendByte(pBuf, 0, &rc);
227569 sessionAppendByte(&buf2, 0, &rc);
227592 int bPatchset, /* True for "patchset", 0 for "changeset" */
227602 if( bPatchset==0 ){
227607 for(i=0; i<nCol; i++){
227612 case 0:
227614 assert( abPK[i]==0 );
227663 char *zSql = 0;
227669 SessionBuffer nooptest = {0, 0, 0};
227670 SessionBuffer pkfield = {0, 0, 0};
227671 SessionBuffer pkvar = {0, 0, 0};
227675 if( 0==sqlite3_stricmp("sqlite_stat1", zTab) ){
227683 for(i=0; i<nCol; i++){
227704 if( zSql==0 ) rc = SQLITE_NOMEM;
227707 #if 0
227708 if( 0==sqlite3_stricmp("sqlite_stat1", zTab) ){
227713 if( zSql==0 ) rc = SQLITE_NOMEM;
227716 SessionBuffer buf = {0, 0, 0};
227723 for(i=0; i<nCol; i++){
227738 rc = sqlite3_prepare_v2(db, zSql, nSql, ppStmt, 0);
227765 for(i=0; i<nCol && rc==SQLITE_OK; i++){
227769 case 0:
227771 assert( abPK[i]==0 );
227847 ** to 0.
227859 SessionBuffer buf = {0,0,0}; /* Buffer in which to accumlate changeset */
227862 assert( xOutput==0 || (pnChangeset==0 && ppChangeset==0) );
227863 assert( xOutput!=0 || (pnChangeset!=0 && ppChangeset!=0) );
227868 if( xOutput==0 ){
227869 assert( pnChangeset!=0 && ppChangeset!=0 );
227870 *pnChangeset = 0;
227871 *ppChangeset = 0;
227875 rc = sqlite3_exec(pSession->db, "SAVEPOINT changeset", 0, 0, 0);
227884 sqlite3_stmt *pSel = 0; /* SELECT statement to query table pTab */
227900 rc = sessionSelectStmt(db, 0, pSession->zDb,
227906 for(i=0; i<pTab->nChange && rc==SQLITE_OK; i++){
227917 for(iCol=0; iCol<pTab->nCol; iCol++){
227921 assert( pTab->abPK!=0 );
227940 buf.nBuf = 0;
227954 if( xOutput==0 ){
227957 buf.aBuf = 0;
227958 }else if( buf.nBuf>0 ){
227964 sqlite3_exec(db, "RELEASE changeset", 0, 0, 0);
227983 if( pnChangeset==0 || ppChangeset==0 ) return SQLITE_MISUSE;
227984 rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset, ppChangeset);
227985 assert( rc || pnChangeset==0
227986 || pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize
227999 if( xOutput==0 ) return SQLITE_MISUSE;
228000 return sessionGenerateChangeset(pSession, 0, xOutput, pOut, 0, 0);
228011 if( xOutput==0 ) return SQLITE_MISUSE;
228012 return sessionGenerateChangeset(pSession, 1, xOutput, pOut, 0, 0);
228027 if( pnPatchset==0 || ppPatchset==0 ) return SQLITE_MISUSE;
228028 return sessionGenerateChangeset(pSession, 1, 0, 0, pnPatchset, ppPatchset);
228037 if( bEnable>=0 ){
228051 if( bIndirect>=0 ){
228064 int ret = 0;
228068 for(pTab=pSession->pTable; pTab && ret==0; pTab=pTab->pNext){
228069 ret = (pTab->nEntry>0);
228073 return (ret==0);
228091 if( iArg>=0 ){
228095 pSession->bEnableSize = (iArg!=0);
228104 if( iArg>=0 ){
228108 pSession->bImplicitPK = (iArg!=0);
228144 assert( xInput==0 || (pChangeset==0 && nChangeset==0) );
228147 *pp = 0;
228153 memset(pRet, 0, sizeof(sqlite3_changeset_iter));
228158 pRet->in.bEof = (xInput ? 0 : 1);
228175 return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset, 0, 0);
228184 return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset, bInvert, 0);
228195 return sessionChangesetStart(pp, xInput, pIn, 0, 0, 0, 0);
228204 return sessionChangesetStart(pp, xInput, pIn, 0, 0, bInvert, 0);
228214 assert( nMove>=0 );
228215 if( nMove>0 ){
228219 pIn->iNext = 0;
228237 if( pIn->bNoDiscard==0 ) sessionDiscardData(pIn);
228240 if( nNew==0 ){
228265 for(i=0; i<nCol; i++){
228289 u8 enc /* String encoding (0 for blobs) */
228296 if( aCopy==0 ) return SQLITE_NOMEM;
228336 assert( pbEmpty==0 || *pbEmpty==0 );
228338 for(i=0; i<nCol && rc==SQLITE_OK; i++){
228339 int eType = 0; /* Type of value (SQLITE_NULL, TEXT etc.) */
228340 if( abPK && abPK[i]==0 ) continue;
228347 assert( apOut[i]==0 );
228349 if( pbEmpty ) *pbEmpty = 0;
228350 apOut[i] = sqlite3ValueNew(0);
228363 if( nByte<0 || nByte>pIn->nData-pIn->iNext ){
228366 u8 enc = (eType==SQLITE_TEXT ? SQLITE_UTF8 : 0);
228408 int nCol = 0;
228409 int nRead = 0;
228421 if( nCol<0 || nCol>65536 ){
228455 int nByte = 0;
228457 for(i=0; rc==SQLITE_OK && i<nCol; i++){
228503 if( p->nCol>0 ){
228507 p->tblhdr.nBuf = 0;
228516 memset(p->tblhdr.aBuf, 0, iPK);
228522 if( p->apValue==0 ){
228523 p->abPK = 0;
228524 p->zTab = 0;
228527 p->zTab = p->abPK ? (char*)&p->abPK[p->nCol] : 0;
228552 assert( (paRec==0 && pnRec==0) || (paRec && pnRec) );
228553 assert( pbEmpty==0 || *pbEmpty==0 );
228560 for(i=0; i<p->nCol*2; i++){
228563 memset(p->apValue, 0, sizeof(sqlite3_value*)*p->nCol*2);
228592 if( p->zTab==0 || (p->bPatchset && p->bInvert) ){
228607 if( p->bPatchset==0 && op==SQLITE_UPDATE ){
228610 nVal = 0;
228611 for(i=0; i<p->nCol; i++) if( p->abPK[i] ) nVal++;
228624 if( p->op!=SQLITE_INSERT && (p->bPatchset==0 || p->op==SQLITE_DELETE) ){
228625 u8 *abPK = p->bPatchset ? p->abPK : 0;
228626 p->rc = sessionReadRecord(&p->in, p->nCol, abPK, apOld, 0);
228632 p->rc = sessionReadRecord(&p->in, p->nCol, 0, apNew, pbEmpty);
228641 for(i=0; i<p->nCol; i++){
228642 assert( p->bPatchset==0 || p->apValue[i]==0 );
228644 assert( p->apValue[i]==0 );
228646 if( p->apValue[i]==0 ) return (p->rc = SQLITE_CORRUPT_BKPT);
228647 p->apValue[i+p->nCol] = 0;
228662 if( p->bPatchset==0 && p->op==SQLITE_UPDATE){
228663 for(i=0; i<p->nCol; i++){
228664 if( p->abPK[i]==0 && p->apValue[i+p->nCol]==0 ){
228666 p->apValue[i] = 0;
228700 bEmpty = 0;
228715 return sessionChangesetNext(p, 0, 0, 0);
228774 if( iVal<0 || iVal>=pIter->nCol ){
228802 if( iVal<0 || iVal>=pIter->nCol ){
228836 if( iVal<0 || iVal>=pIter->nCol ){
228875 for(i=0; i<p->nCol*2; i++) sqlite3ValueFree(p->apValue[i]);
228893 int nCol = 0; /* Number of cols in current table */
228894 u8 *abPK = 0; /* PK array for current table */
228895 sqlite3_value **apVal = 0; /* Space for values for UPDATE inversion */
228896 SessionBuffer sPK = {0, 0, 0}; /* PK array for current table */
228899 memset(&sOut, 0, sizeof(SessionBuffer));
228903 *ppInverted = 0;
228904 *pnInverted = 0;
228931 sPK.nBuf = 0;
228939 apVal = 0;
228963 if( 0==apVal ){
228964 apVal = (sqlite3_value **)sqlite3_malloc64(sizeof(apVal[0])*nCol*2);
228965 if( 0==apVal ){
228969 memset(apVal, 0, sizeof(apVal[0])*nCol*2);
228978 rc = sessionReadRecord(pInput, nCol, 0, &apVal[0], 0);
228980 rc = sessionReadRecord(pInput, nCol, 0, &apVal[nCol], 0);
228986 for(iCol=0; iCol<nCol; iCol++){
228987 sqlite3_value *pVal = apVal[iCol + (abPK[iCol] ? 0 : nCol)];
228994 for(iCol=0; iCol<nCol; iCol++){
228995 sqlite3_value *pVal = (abPK[iCol] ? 0 : apVal[iCol]);
228999 for(iCol=0; iCol<nCol*2; iCol++){
229002 memset(apVal, 0, sizeof(apVal[0])*nCol*2);
229018 sOut.nBuf = 0;
229027 sOut.aBuf = 0;
229028 }else if( sOut.nBuf>0 && ALWAYS(xOutput!=0) ){
229052 memset(&sInput, 0, sizeof(SessionInput));
229056 return sessionChangesetInvert(&sInput, 0, 0, pnInverted, ppInverted);
229072 memset(&sInput, 0, sizeof(SessionInput));
229076 rc = sessionChangesetInvert(&sInput, xOutput, pOut, 0, 0);
229127 SessionUpdate *pUp = 0;
229132 if( p->aUpdateMask==0 ){
229134 if( p->aUpdateMask==0 ){
229140 memset(p->aUpdateMask, 0, nU32*sizeof(u32));
229142 for(ii=0; ii<pIter->nCol; ii++){
229154 int nUp = 0;
229158 if( 0==memcmp(p->aUpdateMask, (*pp)->aMask, nU32*sizeof(u32)) ){
229172 *pp = 0;
229179 if( pUp==0 ){
229181 int bStat1 = (sqlite3_stricmp(pIter->zTab, "sqlite_stat1")==0);
229183 if( pUp==0 ){
229189 memset(&buf, 0, sizeof(buf));
229198 for(ii=0; ii<pIter->nCol; ii++){
229199 if( p->abPK[ii]==0 && sessionChangesetNew(pIter, ii) ){
229211 for(ii=0; ii<pIter->nCol; ii++){
229212 if( p->abPK[ii] || (bPatchset==0 && sessionChangesetOld(pIter, ii)) ){
229215 assert( sqlite3_stricmp(p->azCol[ii], "idx")==0 );
229218 "WHEN length(?4)=0 AND typeof(?4)='blob' THEN NULL "
229232 rc = sqlite3_prepare_v2(p->db, zSql, buf.nBuf, &pUp->pStmt, 0);
229237 pUp = 0;
229247 assert( (rc==SQLITE_OK)==(pUp!=0) );
229251 *ppStmt = 0;
229267 p->pUp = 0;
229269 p->aUpdateMask = 0;
229282 ** Variable :5 (nCol+1) is a boolean. It should be set to 0 if we require
229297 SessionBuffer buf = {0, 0, 0};
229298 int nPk = 0;
229304 for(i=0; i<p->nCol; i++){
229321 for(i=0; i<p->nCol; i++){
229334 rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pDelete, 0);
229381 SessionBuffer buf = {0, 0, 0};
229386 for(i=0; i<p->nCol; i++){
229387 if( i!=0 ) sessionAppendStr(&buf, ", ", &rc);
229398 rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pInsert, 0);
229405 return sqlite3_prepare_v2(db, zSql, -1, pp, 0);
229419 "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, "
229426 "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END "
229443 /* COVERAGE: The (pVal->z==0) branch is never true using current versions
229447 if( (eType==SQLITE_TEXT || eType==SQLITE_BLOB) && pVal->z==0 ){
229462 ** statement pStmt. If parameter abPK is NULL, all values from 0 to (nCol-1)
229486 for(i=0; rc==SQLITE_OK && i<nCol; i++){
229488 sqlite3_value *pVal = 0;
229490 if( pVal==0 ){
229530 sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
229538 for(ii=0; rc==SQLITE_OK && ii<nCol; ii++){
229539 if( p->abPK[ii]==0 ){
229540 sqlite3_value *pVal = 0;
229542 sqlite3_bind_int(pSelect, ii+1+nCol, (pVal==0));
229575 if( p->bRebaseStarted==0 ){
229592 for(i=0; i<p->nCol; i++){
229593 sqlite3_value *pVal = 0;
229648 int res = 0; /* Value returned by conflict handler */
229654 sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
229676 pIter->pConflict = 0;
229759 assert( !pbReplace || *pbReplace==0 );
229761 sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
229772 ** * (pbRetry==0), or
229776 u8 *abPK = (pIter->bPatchset ? p->abPK : 0);
229779 rc = sqlite3_bind_int(p->pDelete, nCol+1, (pbRetry==0 || abPK));
229785 if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 && p->bIgnoreNoop==0 ){
229789 }else if( (rc&0xff)==SQLITE_CONSTRAINT ){
229791 SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, 0
229797 sqlite3_stmt *pUp = 0;
229798 int bPatchset = (pbRetry==0 || pIter->bPatchset);
229803 for(i=0; rc==SQLITE_OK && i<nCol; i++){
229806 if( p->abPK[i] || (bPatchset==0 && pOld) ){
229816 ** the result will be SQLITE_OK with 0 rows modified. */
229820 if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 ){
229829 }else if( (rc&0xff)==SQLITE_CONSTRAINT ){
229832 SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, 0
229850 rc = sessionBindRow(pIter, sqlite3changeset_new, nCol, 0, p->pInsert);
229857 if( (rc&0xff)==SQLITE_CONSTRAINT ){
229884 int bReplace = 0;
229885 int bRetry = 0;
229899 rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, 0, 0);
229909 rc = sqlite3_exec(db, "SAVEPOINT replace_op", 0, 0, 0);
229920 rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, 0, 0);
229923 rc = sqlite3_exec(db, "RELEASE replace_op", 0, 0, 0);
229945 sqlite3_changeset_iter *pIter2 = 0;
229947 memset(&pApply->constraints, 0, sizeof(SessionBuffer));
229950 &pIter2, 0, 0, cons.nBuf, cons.aBuf, pApply->bInvertConstraints, 1
229961 if( rc==SQLITE_OK ) memset(pIter2->apValue, 0, nByte);
229970 assert( pApply->bDeferConstraints || pApply->constraints.nBuf==0 );
229976 pApply->bDeferConstraints = 0;
230006 int schemaMismatch = 0;
230008 const char *zTab = 0; /* Name of current table */
230009 int nTab = 0; /* Result of sqlite3Strlen30(zTab) */
230013 assert( xConflict!=0 );
230016 memset(&sApply, 0, sizeof(sApply));
230021 if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
230022 rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0);
230025 rc = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 1", 0, 0, 0);
230032 sqlite3changeset_op(pIter, &zNew, &nCol, &op, 0);
230034 if( zTab==0 || sqlite3_strnicmp(zNew, zTab, nTab+1) ){
230048 sApply.pDelete = 0;
230049 sApply.pInsert = 0;
230050 sApply.pSelect = 0;
230051 sApply.nCol = 0;
230052 sApply.azCol = 0;
230053 sApply.abPK = 0;
230054 sApply.bStat1 = 0;
230056 sApply.bRebaseStarted = 0;
230057 sApply.bRowid = 0;
230058 memset(&sApply.constraints, 0, sizeof(SessionBuffer));
230063 schemaMismatch = (xFilter && (0==xFilter(pCtx, zNew)));
230066 if( zTab==0 ){
230073 int nMinCol = 0;
230076 sqlite3changeset_pk(pIter, &abPK, 0);
230077 rc = sessionTableInfo(0, db, "main", zNew,
230078 &sApply.nCol, &zTab, &sApply.azCol, 0, &sApply.abPK, &sApply.bRowid
230081 for(i=0; i<sApply.nCol; i++){
230085 if( sApply.nCol==0 ){
230099 else if( nCol<nMinCol || memcmp(sApply.abPK, abPK, nCol)!=0 ){
230107 if( 0==sqlite3_stricmp(zTab, "sqlite_stat1") ){
230119 sApply.bStat1 = 0;
230146 sqlite3_db_status(db, SQLITE_DBSTATUS_DEFERRED_FKS, &nFk, ¬Used, 0);
230147 if( nFk!=0 ){
230150 memset(&sIter, 0, sizeof(sIter));
230158 sqlite3_exec(db, "PRAGMA defer_foreign_keys = 0", 0, 0, 0);
230160 if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
230162 rc = sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
230164 sqlite3_exec(db, "ROLLBACK TO changeset_apply", 0, 0, 0);
230165 sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
230169 assert( sApply.bRebase || sApply.rebase.nBuf==0 );
230170 if( rc==SQLITE_OK && bPatchset==0 && sApply.bRebase ){
230173 sApply.rebase.aBuf = 0;
230209 int rc = sessionChangesetStart(&pIter, 0, 0, nChangeset, pChangeset, bInv, 1);
230214 db->aDb[0].pSchema->schema_cookie -= 32;
230223 if( (flags & SQLITE_CHANGESETAPPLY_FKNOACTION) && savedFlag==0 ){
230226 db->aDb[0].pSchema->schema_cookie -= 32;
230252 db, nChangeset, pChangeset, xFilter, xConflict, pCtx, 0, 0, 0
230280 int rc = sessionChangesetStart(&pIter, xInput, pIn, 0, 0, bInverse, 1);
230304 db, xInput, pIn, xFilter, xConflict, pCtx, 0, 0, 0
230337 SessionChange *pNew = 0;
230339 assert( aRec!=0 );
230346 memset(pNew, 0, sizeof(SessionChange));
230350 if( bIndirect==0 || bRebase==0 ){
230357 for(i=0; i<pTab->nCol; i++){
230359 if( *pIn==0 ){
230360 *pOut++ = 0;
230361 }else if( pTab->abPK[i]==0 ){
230362 *pOut++ = 0xFF;
230377 if( pNew==0 ){
230385 memset(pNew, 0, nByte);
230390 for(i=0; i<pTab->nCol; i++){
230393 if( *a1==0xFF || (pTab->abPK[i]==0 && bIndirect) ){
230394 *pOut++ = 0xFF;
230395 }else if( *a2==0 ){
230433 assert( pNew==0 );
230448 memset(pNew, 0, sizeof(SessionChange));
230456 if( bPatchset==0 ) sessionSkipRecord(&a1, pTab->nCol);
230465 if( 0==sessionMergeUpdate(&aCsr, pTab, bPatchset, aExist, 0,aRec,0) ){
230467 pNew = 0;
230474 if( bPatchset==0 ){
230479 if( 0==sessionMergeUpdate(&aCsr, pTab, bPatchset, aRec, aExist,a1,a2) ){
230481 pNew = 0;
230509 ** return 0.
230518 for(ii=0; ii<pTab->nCol; ii++){
230519 u8 bPK = (ii < nCol) ? abPK[ii] : 0;
230520 if( pTab->abPK[ii]!=bPK ) return 0;
230524 return (pTab->nCol==nCol && 0==memcmp(abPK, pTab->abPK, nCol));
230537 int ii = 0;
230542 pOut->nBuf = 0;
230543 if( op==SQLITE_INSERT || (op==SQLITE_DELETE && pGrp->bPatch==0) ){
230546 if( rc==SQLITE_OK && pTab->pDfltStmt==0 ){
230590 int iOff = 0;
230591 if( pGrp->bPatch==0 ){
230592 for(ii=0; ii<nCol; ii++){
230596 for(ii=0; ii<(pTab->nCol-nCol); ii++){
230597 sessionAppendByte(pOut, 0x00, &rc);
230602 for(ii=0; ii<(pTab->nCol-nCol); ii++){
230603 sessionAppendByte(pOut, 0x00, &rc);
230627 SessionTable *pTab = 0;
230629 u8 *abPK = 0;
230630 int nCol = 0;
230632 *ppTab = 0;
230637 if( 0==sqlite3_strnicmp(pTab->zName, zTab, nTab+1) ) break;
230648 memset(pTab, 0, sizeof(SessionTable));
230656 pTab->nCol = 0;
230657 rc = sessionInitTable(0, pTab, pGrp->db, pGrp->zDb);
230659 assert( pTab->azCol==0 );
230692 int nCol = 0;
230693 int op = 0;
230694 int iHash = 0;
230695 int bIndirect = 0;
230696 SessionChange *pChange = 0;
230697 SessionChange *pExist = 0;
230698 SessionChange **pp = 0;
230699 SessionTable *pTab = 0;
230706 if( pGrp->pList==0 ){
230713 const char *zTab = 0;
230726 if( rc==SQLITE_OK && sessionGrowHash(0, pIter->bPatchset, pTab) ){
230737 int bPkOnly1 = 0;
230738 int bPkOnly2 = 0;
230780 while( SQLITE_ROW==(sessionChangesetNext(pIter, &aRec, &nRec, 0)) ){
230805 ** are both set to 0 before returning.
230815 SessionBuffer buf = {0, 0, 0};
230817 assert( xOutput==0 || (ppOut==0 && pnOut==0) );
230824 if( pTab->nEntry==0 ) continue;
230827 for(i=0; i<pTab->nChange; i++){
230835 buf.nBuf = 0;
230843 if( buf.nBuf>0 ) rc = xOutput(pOut, buf.aBuf, buf.nBuf);
230847 buf.aBuf = 0;
230862 if( p==0 ){
230865 memset(p, 0, sizeof(sqlite3_changegroup));
230887 if( pGrp->zDb==0 ){
230906 rc = sessionChangesetToHash(pIter, pGrp, 0);
230926 return sessionOneChangeToHash(pGrp, pIter, 0);
230938 return sessionChangegroupOutput(pGrp, 0, 0, pnData, ppData);
230954 rc = sessionChangesetToHash(pIter, pGrp, 0);
230968 return sessionChangegroupOutput(pGrp, xOutput, pOut, 0, 0);
230977 sessionDeleteTable(0, pGrp->pList);
231065 for(i=0; i<nCol; i++){
231068 if( *a1==0 || *a1==0xFF ){
231094 ** in the rebase buffer is set to "replaced" (type 0xFF). If this
231099 ** corresponding field in the rebase buffer is not "undefined" (0x00)
231100 ** or "replaced" (0xFF), the old.* value is replaced by the value
231112 int bData = 0;
231120 for(i=0; i<pIter->nCol; i++){
231123 if( pIter->abPK[i] || a2[0]==0 ){
231124 if( !pIter->abPK[i] && a1[0] ) bData = 1;
231127 }else if( a2[0]!=0xFF && a1[0] ){
231132 *pOut++ = '\0';
231139 for(i=0; i<pIter->nCol; i++){
231142 if( pIter->abPK[i] || a2[0]!=0xFF ){
231146 *pOut++ = '\0';
231168 ** pnOut are not NULL, then the two output parameters are set to 0 before
231180 u8 *aRec = 0;
231181 int nRec = 0;
231182 int bNew = 0;
231183 SessionTable *pTab = 0;
231184 SessionBuffer sOut = {0,0,0};
231187 SessionChange *pChange = 0;
231188 int bDone = 0;
231193 if( 0==sqlite3_stricmp(pTab->zName, zTab) ) break;
231195 bNew = 0;
231210 int iHash = sessionChangeHash(pTab, 0, aRec, pTab->nChange);
231213 if( sessionChangeEqual(pTab, 0, aRec, 0, pChange->aRecord) ){
231225 if( pChange->bIndirect==0 ){
231237 if( pChange->bIndirect==0 ){
231268 if( bDone==0 ){
231275 sOut.nBuf = 0;
231282 memset(&sOut, 0, sizeof(sOut));
231287 if( sOut.nBuf>0 ){
231293 sOut.aBuf = 0;
231308 if( pNew==0 ){
231311 memset(pNew, 0, sizeof(sqlite3_rebaser));
231324 sqlite3_changeset_iter *pIter = 0; /* Iterator opened on pData/nData */
231342 sqlite3_changeset_iter *pIter = 0; /* Iterator to skip through input */
231346 rc = sessionRebase(p, pIter, 0, 0, pnOut, ppOut);
231363 sqlite3_changeset_iter *pIter = 0; /* Iterator to skip through input */
231367 rc = sessionRebase(p, pIter, xOutput, pOut, 0, 0);
231379 sessionDeleteTable(0, p->grp.pList);
231393 if( *pInt>0 ){
231446 #if 0
231508 ** created with the "columnsize=0" option.
231527 ** 0 is returned. Otherwise, this function returns the number of tokens in
231538 ** (i.e. if it is a contentless table), then this API always returns 0.
231644 ** iCol>=0;
231674 ** iCol>=0;
231709 ** tables, this includes any embedded 0x00 and trailing data.
231719 ** to 0.
231723 ** includes any embedded 0x00 and trailing data.
231836 ** on a columnsize=0 database.
231848 ** normally be set to 0. The exception is if the tokenizer supports
231924 ** xToken(pCtx, 0, "i", 1, 0, 1);
231925 ** xToken(pCtx, 0, "won", 3, 2, 5);
231926 ** xToken(pCtx, 0, "first", 5, 6, 11);
231928 ** xToken(pCtx, 0, "place", 5, 12, 17);
231990 #define FTS5_TOKENIZE_QUERY 0x0001
231991 #define FTS5_TOKENIZE_PREFIX 0x0002
231992 #define FTS5_TOKENIZE_DOCUMENT 0x0004
231993 #define FTS5_TOKENIZE_AUX 0x0008
231997 #define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */
232041 #if 0
232080 # define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0])))
232090 # define NEVER(X) (0)
232092 # define ALWAYS(X) ((X)?1:(assert(0),0))
232093 # define NEVER(X) ((X)?(assert(0),1):0)
232105 # define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
232157 #define fts5Memcmp(s1, s2, n) ((n)<=0 ? 0 : memcmp((s1), (s2), (n)))
232241 int bContentlessDelete; /* "contentless_delete=" option (dflt==0) */
232245 int bTokendata; /* "tokendata=" option value (dflt==0) */
232280 #define FTS5_CONTENT_NORMAL 0
232284 #define FTS5_DETAIL_FULL 0
232288 #define FTS5_PATTERN_NONE 0
232353 (u32)((pBuf)->n) + (u32)(nn) <= (u32)((pBuf)->nSpace) ? 0 : \
232362 #define FTS5_POS2OFFSET(iPos) (int)(iPos & 0x7FFFFFFF)
232404 /* Bucket of terms object used by the integrity-check in offsets=0 mode. */
232434 #define FTS5INDEX_QUERY_PREFIX 0x0001 /* Prefix query */
232435 #define FTS5INDEX_QUERY_DESC 0x0002 /* Docs in descending rowid order */
232436 #define FTS5INDEX_QUERY_TEST_NOIDX 0x0004 /* Do not use prefix index */
232437 #define FTS5INDEX_QUERY_SCAN 0x0008 /* Scan query (fts5vocab) */
232442 #define FTS5INDEX_QUERY_SKIPEMPTY 0x0010
232443 #define FTS5INDEX_QUERY_NOOUTPUT 0x0020
232444 #define FTS5INDEX_QUERY_SKIPHASH 0x0040
232445 #define FTS5INDEX_QUERY_NOTOKENDATA 0x0080
232446 #define FTS5INDEX_QUERY_SCANONETERM 0x0100
232469 ** buffer, or 0 if there are less than nChar characters in total.
232620 if( nVal & 0x80 ){ \
232724 #define FTS5_STMT_SCAN_ASC 0 /* SELECT rowid, * FROM ... ORDER BY 1 ASC */
232802 ** rc==SQLITE_OK && 0==sqlite3Fts5ExprEof(pExpr);
233121 #define fts5YYDYNSTACK 0
233142 #define fts5YY_NLOOKAHEAD ((int)(sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0])))
233159 #if fts5YYSTACKDEPTH<=0 || fts5YYDYNSTACK
233162 # define fts5YYGROWABLESTACK 0
233167 #if fts5YYSTACKDEPTH<=0
233181 ** 0 <= N <= fts5YY_MAX_SHIFT Shift N. That is, push the lookahead
233225 /* 0 */ 81, 20, 96, 6, 28, 99, 98, 26, 26, 18,
233238 /* 0 */ 16, 17, 18, 19, 20, 22, 22, 24, 24, 17,
233245 /* 70 */ 24, 3, 1, 2, 3, 1, 2, 3, 0, 1,
233253 #define fts5YY_SHIFT_MIN (0)
233256 /* 0 */ 44, 44, 44, 44, 44, 44, 51, 77, 43, 12,
233265 /* 0 */ -16, -8, 0, 9, 17, 25, 46, -17, -17, 37,
233269 /* 0 */ 80, 80, 80, 80, 80, 80, 95, 80, 80, 105,
233341 static FILE *fts5yyTraceFILE = 0;
233342 static char *fts5yyTracePrompt = 0;
233366 if( fts5yyTraceFILE==0 ) fts5yyTracePrompt = 0;
233367 else if( fts5yyTracePrompt==0 ) fts5yyTraceFILE = 0;
233375 /* 0 */ "$",
233409 /* 0 */ "input ::= expr",
233444 ** of errors. Return 0 on success.
233455 pNew = fts5YYREALLOC(0, newSize*sizeof(pNew[0]));
233456 if( pNew==0 ) return 1;
233457 memcpy(pNew, p->fts5yystack, oldSize*sizeof(pNew[0]));
233459 pNew = fts5YYREALLOC(p->fts5yystack, newSize*sizeof(pNew[0]));
233460 if( pNew==0 ) return 1;
233471 return 0;
233497 fts5yypParser->fts5yyhwm = 0;
233505 fts5yypParser->fts5yystack[0].stateno = 0;
233506 fts5yypParser->fts5yystack[0].major = 0;
233602 assert( pParser->fts5yytos!=0 );
233657 if( p==0 ) return;
233694 int nMissed = 0;
233695 for(stateno=0; stateno<fts5YYNSTATE; stateno++){
233697 for(iLookAhead=0; iLookAhead<fts5YYNFTS5TOKEN; iLookAhead++){
233699 if( fts5yycoverage[stateno][iLookAhead]==0 ) nMissed++;
233728 assert( i>=0 );
233738 assert( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0]) );
233740 if( iFallback!=0 ){
233747 assert( fts5yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
233755 assert( j<(int)(sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0])) );
233756 if( fts5yy_lookahead[j]==fts5YYWILDCARD && iLookAhead>0 ){
233770 assert( i>=0 && i<(int)(sizeof(fts5yy_action)/sizeof(fts5yy_action[0])) );
233796 if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
233800 assert( i>=0 && i<fts5YY_ACTTAB_COUNT );
233888 16, /* (0) input ::= expr */
233921 -1, /* (0) input ::= expr */
233943 0, /* (22) neardist_opt ::= */
233948 0, /* (27) star_opt ::= */
233982 ** case 0:
233990 case 0: /* input ::= expr */
233991 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
234003 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
234005 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
234009 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
234015 …yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
234020 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
234022 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
234026 …lite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
234032 …qlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
234038 …lite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
234054 {fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
234055 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
234059 …4 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
234065 …fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5y…
234067 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
234071 …fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5y…
234077 { fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
234078 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
234082 sqlite3Fts5ParseSetCaret(fts5yymsp[0].minor.fts5yy53);
234083 fts5yymsp[-1].minor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
234096 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
234098 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
234102 …5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
234107 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
234110 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
234114 …rm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
234120 …ts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0…
234125 { fts5yymsp[0].minor.fts5yy4 = 1; }
234128 { fts5yymsp[1].minor.fts5yy4 = 0; }
234134 assert( fts5yyruleno<sizeof(fts5yyRuleInfoLhs)/sizeof(fts5yyRuleInfoLhs[0]) );
234256 int fts5yyerrorhit = 0; /* True if fts5yymajor has invoked an error */
234262 assert( fts5yypParser->fts5yytos!=0 );
234264 fts5yyendofinput = (fts5yymajor==0);
234287 assert( fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) );
234307 if( fts5yyRuleInfoNRhs[fts5yyruleno]==0 ){
234364 if( fts5yypParser->fts5yyerrcnt<0 ){
234384 if( fts5yypParser->fts5yytos <= fts5yypParser->fts5yystack || fts5yymajor==0 ){
234420 if( fts5yypParser->fts5yyerrcnt<=0 ){
234452 ** 0 if iToken has no fallback.
234456 assert( iToken<(int)(sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])) );
234460 return 0;
234493 ** (rc==SQLITE_OK && 0==fts5CInstIterEof(&iter);
234528 if( pIter->iStart<0 ){
234556 memset(pIter, 0, sizeof(CInstIter));
234595 ** negative, everything up until the first '\0' is appended to the output.
234607 if( n<0 ) n = (int)strlen(z);
234609 if( p->zOut==0 ) *pRc = SQLITE_NOMEM;
234633 if( p->iRangeEnd>=0 ){
234643 && (iPos<=p->iter.iStart || p->iter.iStart<0)
234647 p->bOpen = 0;
234655 if( iPos==p->iter.iStart && p->bOpen==0 ){
234663 if( p->bOpen==0 ){
234664 assert( p->iRangeEnd>=0 );
234678 if( p->iter.iStart>=0 && iPos>=p->iter.iStart ){
234683 p->bOpen = 0;
234712 iCol = sqlite3_value_int(apVal[0]);
234713 memset(&ctx, 0, sizeof(HighlightContext));
234770 if( aNew==0 ) return SQLITE_NOMEM;
234796 if( (tflags & FTS5_TOKEN_COLOCATED)==0 ){
234798 if( p->iPos>0 ){
234800 char c = 0;
234801 for(i=iStartOff-1; i>=0; i--){
234809 rc = fts5SentenceFinderAdd(p, 0);
234829 int ip = 0;
234830 int ic = 0;
234831 int iOff = 0;
234834 int nScore = 0;
234835 int iLast = 0;
234839 for(i=0; i<nInst && rc==SQLITE_OK; i++){
234844 if( iFirst<0 ) iFirst = iOff;
234853 if( iAdj<0 ) iAdj = 0;
234885 int nInst = 0; /* Number of instance matches this row */
234890 int iBestStart = 0; /* First token of best snippet */
234891 int nBestScore = 0; /* Score of best snippet */
234892 int nColSize = 0; /* Total size of iBestCol in tokens */
234903 memset(&ctx, 0, sizeof(HighlightContext));
234904 iCol = sqlite3_value_int(apVal[0]);
234911 iBestCol = (iCol>=0 ? iCol : 0);
234914 if( aSeen==0 ){
234921 memset(&sFinder, 0, sizeof(Fts5SFinder));
234922 for(i=0; i<nCol; i++){
234923 if( iCol<0 || iCol==i ){
234927 sFinder.iPos = 0;
234928 sFinder.nFirst = 0;
234938 for(ii=0; rc==SQLITE_OK && ii<nInst; ii++){
234948 memset(aSeen, 0, nPhrase);
234960 for(jj=0; jj<(sFinder.nFirst-1); jj++){
234965 memset(aSeen, 0, nPhrase);
234967 sFinder.aFirst[jj], nToken, &nScore, 0
234970 nScore += (sFinder.aFirst[jj]==0 ? 120 : 100);
234986 if( rc==SQLITE_OK && nColSize==0 ){
234997 if( iBestStart>0 ){
235003 while( ctx.iter.iStart>=0 && ctx.iter.iStart<iBestStart && rc==SQLITE_OK ){
235071 p = (Fts5Bm25Data*)pApi->xGetAuxdata(pFts, 0);
235072 if( p==0 ){
235074 sqlite3_int64 nRow = 0; /* Number of rows in table */
235075 sqlite3_int64 nToken = 0; /* Number of tokens in table */
235083 if( p==0 ){
235086 memset(p, 0, (size_t)nByte);
235094 assert( rc!=SQLITE_OK || nRow>0 );
235099 for(i=0; rc==SQLITE_OK && i<nPhrase; i++){
235100 sqlite3_int64 nHit = 0;
235127 if( rc!=SQLITE_OK ) p = 0;
235149 int nInst = 0; /* Value returned by xInstCount() */
235151 double *aFreq = 0; /* Array of phrase freq. for current row */
235158 memset(aFreq, 0, sizeof(double) * pData->nPhrase);
235161 for(i=0; rc==SQLITE_OK && i<nInst; i++){
235180 for(i=0; i<pData->nPhrase; i++){
235199 { "snippet", 0, fts5SnippetFunction, 0 },
235200 { "highlight", 0, fts5HighlightFunction, 0 },
235201 { "bm25", 0, fts5Bm25Function, 0 },
235206 for(i=0; rc==SQLITE_OK && i<ArraySize(aBuiltin); i++){
235243 if( pNew==0 ){
235251 return 0;
235265 aBuf[0] = (iVal>>24) & 0x00FF;
235266 aBuf[1] = (iVal>>16) & 0x00FF;
235267 aBuf[2] = (iVal>> 8) & 0x00FF;
235268 aBuf[3] = (iVal>> 0) & 0x00FF;
235272 return (int)((((u32)aBuf[0])<<24) + (aBuf[1]<<16) + (aBuf[2]<<8) + aBuf[3]);
235288 assert( pBuf->p!=0 );
235296 ** ensures that the byte following the buffer data is set to 0x00, even
235314 ** following the buffer data is set to 0x00, even though this byte is not
235329 if( zTmp==0 ){
235339 char *zRet = 0;
235345 if( zRet==0 ){
235358 memset(pBuf, 0, sizeof(Fts5Buffer));
235366 pBuf->n = 0;
235380 pBuf->n = 0;
235390 assert( a!=0 || i==0 );
235398 assert( a!=0 );
235401 if( iVal==0 ){
235403 return 0;
235407 assert( iOff>=0 );
235414 *piOff = iOff + ((iVal-2) & 0x7FFFFFFF);
235416 *piOff = (iOff & (i64)0x7FFFFFFF<<32)+((iOff + (iVal-2)) & 0x7FFFFFFF);
235420 return 0;
235440 memset(pIter, 0, sizeof(*pIter));
235459 static const i64 colmask = ((i64)(0x7FFFFFFF)) << 32;
235475 int rc = 0; /* Initialized only to suppress erroneous warning from Clang */
235482 void *pRet = 0;
235485 if( pRet==0 ){
235486 if( nByte>0 ) *pRc = SQLITE_NOMEM;
235488 memset(pRet, 0, (size_t)nByte);
235503 char *zRet = 0;
235505 if( nIn<0 ){
235511 zRet[nIn] = '\0';
235527 ** * The underscore character "_" (0x5F).
235528 ** * The unicode "subsitute" character (0x1A).
235532 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 .. 0x0F */
235533 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* 0x10 .. 0x1F */
235534 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 .. 0x2F */
235535 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0x30 .. 0x3F */
235536 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 .. 0x4F */
235537 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x50 .. 0x5F */
235538 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 .. 0x6F */
235539 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70 .. 0x7F */
235542 return (t & 0x80) || aBareword[(int)t];
235573 *pbPresent = 0;
235583 for(i=nTerm-1; i>=0; i--){
235592 && memcmp(pEntry->pTerm, pTerm, nTerm)==0
235599 if( pEntry==0 ){
235618 for(i=0; i<ArraySize(p->apHash); i++){
235688 if( p==pIn ) p = 0;
235693 return (a>='0' && a<='9');
235702 if( sqlite3_strnicmp("null", p, 4)==0 ){
235705 p = 0;
235715 || (*p>='0' && *p<='9')
235719 if( *p=='\'' && 0==((p-pIn)%2) ){
235722 p = 0;
235725 p = 0;
235737 if( *p==0 ) p = 0;
235753 if( p==pIn ) p = 0;
235777 int iOut = 0;
235778 q = z[0];
235802 z[iOut] = '\0';
235822 assert( 0==fts5_iswhitespace(z[0]) );
235823 quote = z[0];
235845 for(i=0; aEnum[i].zName; i++){
235846 if( sqlite3_strnicmp(aEnum[i].zName, zEnum, nEnum)==0 ){
235847 if( iVal>=0 ) return SQLITE_ERROR;
235853 return iVal<0 ? SQLITE_ERROR : SQLITE_OK;
235874 if( sqlite3_strnicmp("prefix", zCmd, nCmd)==0 ){
235878 if( pConfig->aPrefix==0 ){
235885 int nPre = 0;
235887 while( p[0]==' ' ) p++;
235888 if( bFirst==0 && p[0]==',' ){
235890 while( p[0]==' ' ) p++;
235891 }else if( p[0]=='\0' ){
235894 if( p[0]<'0' || p[0]>'9' ){
235908 while( p[0]>='0' && p[0]<='9' && nPre<1000 ){
235909 nPre = nPre*10 + (p[0] - '0');
235913 if( nPre<=0 || nPre>=1000 ){
235921 bFirst = 0;
235927 if( sqlite3_strnicmp("tokenize", zCmd, nCmd)==0 ){
235939 for(nArg=0; p && *p; nArg++){
235954 if( p==0 ){
235971 if( sqlite3_strnicmp("content", zCmd, nCmd)==0 ){
235976 if( zArg[0] ){
235986 if( sqlite3_strnicmp("contentless_delete", zCmd, nCmd)==0 ){
235987 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
235991 pConfig->bContentlessDelete = (zArg[0]=='1');
235996 if( sqlite3_strnicmp("content_rowid", zCmd, nCmd)==0 ){
236006 if( sqlite3_strnicmp("columnsize", zCmd, nCmd)==0 ){
236007 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
236011 pConfig->bColumnsize = (zArg[0]=='1');
236016 if( sqlite3_strnicmp("detail", zCmd, nCmd)==0 ){
236021 { 0, 0 }
236030 if( sqlite3_strnicmp("tokendata", zCmd, nCmd)==0 ){
236031 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
236035 pConfig->bTokendata = (zArg[0]=='1');
236050 assert( pConfig->pTok==0 && pConfig->pTokApi==0 );
236051 return sqlite3Fts5GetTokenizer(pGlobal, 0, 0, pConfig, 0);
236075 const char *zRet = 0;
236081 *pbQuoted = 0;
236082 *pzOut = 0;
236084 if( zOut==0 ){
236088 if( fts5_isopenquote(zOut[0]) ){
236095 zOut[zRet-zIn] = '\0';
236100 if( zRet==0 ){
236116 if( 0==sqlite3_stricmp(zCol, FTS5_RANK_NAME)
236117 || 0==sqlite3_stricmp(zCol, FTS5_ROWID_NAME)
236122 if( 0==sqlite3_stricmp(zArg, "unindexed") ){
236140 Fts5Buffer buf = {0, 0, 0};
236144 for(i=0; i<p->nCol; i++){
236153 assert( p->zContentExprlist==0 );
236184 if( pRet==0 ) return SQLITE_NOMEM;
236185 memset(pRet, 0, sizeof(Fts5Config));
236191 pRet->abUnindexed = pRet->azCol ? (u8*)&pRet->azCol[nArg] : 0;
236199 if( rc==SQLITE_OK && sqlite3_stricmp(pRet->zName, FTS5_RANK_NAME)==0 ){
236208 char *zOne = 0;
236209 char *zTwo = 0;
236210 int bOption = 0;
236211 int bMustBeCol = 0;
236217 assert( zOne!=0 );
236219 if( bMustBeCol ) z = 0;
236222 if( z && z[0] ){
236225 if( z && z[0] ) z = 0;
236229 if( z==0 ){
236241 zOne = 0;
236261 /* We only allow contentless_delete=1 if columnsize=0 is not present.
236265 if( rc==SQLITE_OK && pRet->bContentlessDelete && pRet->bColumnsize==0 ){
236267 "contentless_delete=1 is incompatible with columnsize=0"
236275 if( rc==SQLITE_OK && pRet->pTok==0 ){
236280 if( rc==SQLITE_OK && pRet->zContent==0 ){
236281 const char *zTail = 0;
236298 if( rc==SQLITE_OK && pRet->zContentRowid==0 ){
236309 *ppOut = 0;
236325 for(i=0; i<pConfig->nCol; i++){
236350 for(i=0; zSql && i<pConfig->nCol; i++){
236351 const char *zSep = (i==0?"":", ");
236378 ** int iPos // Position of token in input (first token is 0)
236397 if( pText==0 ) return SQLITE_OK;
236416 if( p==0 || *p==')' ) break;
236418 p = 0;
236443 char *zRank = 0;
236444 char *zRankArgs = 0;
236447 *pzRank = 0;
236448 *pzRankArgs = 0;
236450 if( p==0 ){
236475 if( p==0 ){
236487 assert( zRankArgs==0 );
236503 if( 0==sqlite3_stricmp(zKey, "pgsz") ){
236504 int pgsz = 0;
236515 else if( 0==sqlite3_stricmp(zKey, "hashsize") ){
236520 if( nHashSize<=0 ){
236527 else if( 0==sqlite3_stricmp(zKey, "automerge") ){
236532 if( nAutomerge<0 || nAutomerge>64 ){
236540 else if( 0==sqlite3_stricmp(zKey, "usermerge") ){
236552 else if( 0==sqlite3_stricmp(zKey, "crisismerge") ){
236557 if( nCrisisMerge<0 ){
236566 else if( 0==sqlite3_stricmp(zKey, "deletemerge") ){
236573 if( nVal<0 ) nVal = FTS5_DEFAULT_DELETE_AUTOMERGE;
236574 if( nVal>100 ) nVal = 0;
236578 else if( 0==sqlite3_stricmp(zKey, "rank") ){
236594 else if( 0==sqlite3_stricmp(zKey, "secure-delete") ){
236599 if( bVal<0 ){
236602 pConfig->bSecureDelete = (bVal ? 1 : 0);
236616 sqlite3_stmt *p = 0;
236618 int iVersion = 0;
236630 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &p, 0);
236634 assert( rc==SQLITE_OK || p==0 );
236637 const char *zK = (const char*)sqlite3_column_text(p, 0);
236639 if( 0==sqlite3_stricmp(zK, "version") ){
236642 int bDummy = 0;
236655 assert( 0==*pConfig->pzErrmsg );
236695 ** All token types in the generated fts5parse.h file are greater than 0.
236697 #define FTS5_EOF 0
236699 #define FTS5_LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
236736 ** Distance from this node to furthest leaf. This is always 0 for nodes
236823 if( p->eType==FTS5_TERM || p->eType==FTS5_STRING || p->eType==0 ){
236824 assert( p->iHeight==0 );
236827 int iMaxChild = 0;
236828 for(ii=0; ii<p->nChild; ii++){
236845 assert( pParse->zErr==0 );
236883 case '\0': tok = FTS5_EOF; break;
236890 if( z2[0]=='"' ){
236892 if( z2[0]!='"' ) break;
236894 if( z2[0]=='\0' ){
236905 if( sqlite3Fts5IsBareword(z[0])==0 ){
236912 if( pToken->n==2 && memcmp(pToken->p, "OR", 2)==0 ) tok = FTS5_OR;
236913 if( pToken->n==3 && memcmp(pToken->p, "NOT", 3)==0 ) tok = FTS5_NOT;
236914 if( pToken->n==3 && memcmp(pToken->p, "AND", 3)==0 ) tok = FTS5_AND;
236941 *ppNew = 0;
236942 *pzErr = 0;
236943 memset(&sParse, 0, sizeof(sParse));
236946 if( pEngine==0 ){ return SQLITE_NOMEM; }
236964 pColset->aiCol[0] = iCol;
236969 assert( sParse.rc!=SQLITE_OK || sParse.zErr==0 );
236972 if( pNew==0 ){
236985 pNew->pIndex = 0;
236989 pNew->bDesc = 0;
236990 sParse.apPhrase = 0;
236997 if( 0==*pzErr ){
237010 int nRet = 0;
237012 for(ii=0; ii<nByte; ii++){
237013 if( (z[ii] & 0xC0)!=0x80 ) nRet++;
237033 if( zExpr==0 ){
237037 int iOut = 0;
237038 int i = 0;
237039 int iFirst = 0;
237041 if( bGlob==0 ){
237042 aSpec[0] = '_';
237044 aSpec[2] = 0;
237046 aSpec[0] = '*';
237053 || zText[i]==aSpec[0] || zText[i]==aSpec[1] || zText[i]==aSpec[2]
237075 if( iOut>0 ){
237076 int bAnd = 0;
237083 zExpr[iOut] = '\0';
237086 *pp = 0;
237100 for(i=0; i<p->nChild; i++){
237121 memset(&sParse, 0, sizeof(sParse));
237127 p1->pRoot = sqlite3Fts5ParseNode(&sParse, FTS5_AND, p1->pRoot, p2->pRoot,0);
237128 p2->pRoot = 0;
237134 if( ap==0 ){
237139 for(i=0; i<p2->nPhrase; i++){
237160 i64 iRet = 0;
237161 int bRetValid = 0;
237166 assert( bDesc==0 || bDesc==1 );
237168 if( 0==sqlite3Fts5IterEof(p->pIter) ){
237170 if( bRetValid==0 || (bDesc!=(iRowid<iRet)) ){
237177 if( pbEof && bRetValid==0 ) *pbEof = 1;
237192 int nIter = 0;
237200 if( sqlite3Fts5IterEof(pIter)==0 && pIter->iRowid==iRowid ){
237201 if( pIter->nData==0 ) continue;
237205 if( aNew==0 ){
237215 assert( aIter[nIter].bEof==0 );
237221 *pa = (u8*)aIter[0].a;
237222 *pn = aIter[0].n;
237224 Fts5PoslistWriter writer = {0};
237230 for(i=0; i<nIter; i++){
237231 if( aIter[i].bEof==0 ){
237272 Fts5PoslistWriter writer = {0};
237277 int bFirst = pPhrase->aTerm[0].bFirst;
237288 memset(aIter, 0, sizeof(Fts5PoslistReader) * pPhrase->nTerm);
237291 for(i=0; i<pPhrase->nTerm; i++){
237293 int n = 0;
237294 int bFlag = 0;
237295 u8 *a = 0;
237297 Fts5Buffer buf = {0, 0, 0};
237315 i64 iPos = aIter[0].iPos;
237318 for(i=0; i<pPhrase->nTerm; i++){
237322 bMatch = 0;
237329 }while( bMatch==0 );
237332 if( bFirst==0 || FTS5_POS2OFFSET(iPos)==0 ){
237337 for(i=0; i<pPhrase->nTerm; i++){
237343 *pbMatch = (pPhrase->poslist.n>0);
237344 for(i=0; i<pPhrase->nTerm; i++){
237374 memset(p, 0, sizeof(Fts5LookaheadReader));
237422 memset(aStatic, 0, sizeof(aStatic));
237426 return 0;
237437 for(i=0; i<pNear->nPhrase; i++){
237440 pPoslist->n = 0;
237451 iMax = a[0].reader.iPos;
237454 for(i=0; i<pNear->nPhrase; i++){
237458 bMatch = 0;
237465 }while( bMatch==0 );
237468 for(i=0; i<pNear->nPhrase; i++){
237471 if( a[i].pOut->n==0 || iPos!=pWriter->iPrev ){
237476 iAdv = 0;
237477 iMin = a[0].reader.iLookahead;
237478 for(i=0; i<pNear->nPhrase; i++){
237488 int bRet = a[0].pOut->n>0;
237515 if( (bDesc==0 && iLast>iRowid) || (bDesc && iLast<iRowid) ){
237523 assert( (bDesc==0 && iRowid>=iLast) || (bDesc==1 && iRowid<=iLast) );
237527 return 0;
237539 int bEof = 0;
237542 if( sqlite3Fts5IterEof(p->pIter)==0 ){
237544 if( (bDesc==0 && iLast>iRowid) || (bDesc && iLast<iRowid) ){
237570 Fts5ExprPhrase *pPhrase = pNear->apPhrase[0];
237571 pPhrase->poslist.n = 0;
237572 for(pTerm=&pPhrase->aTerm[0]; pTerm; pTerm=pTerm->pSynonym){
237574 if( sqlite3Fts5IterEof(pIter)==0 ){
237575 if( pIter->iRowid==pNode->iRowid && pIter->nData>0 ){
237587 for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){
237589 if( pPhrase->nTerm>1 || pPhrase->aTerm[0].pSynonym
237590 || pNear->pColset || pPhrase->aTerm[0].bFirst
237592 int bMatch = 0;
237594 if( bMatch==0 ) break;
237596 Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
237605 return 0;
237626 assert( pNode->bNomatch==0 );
237627 for(i=0; i<pNear->nPhrase; i++){
237629 if( pPhrase->nTerm==0 ){
237634 for(j=0; j<pPhrase->nTerm; j++){
237637 int bHit = 0;
237643 p->pIter = 0;
237647 (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) |
237648 (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0),
237652 assert( (rc==SQLITE_OK)==(p->pIter!=0) );
237654 if( 0==sqlite3Fts5IterEof(p->pIter) ){
237659 if( bHit==0 ){
237667 pNode->bEof = 0;
237686 assert( pExpr->bDesc==0 || pExpr->bDesc==1 );
237687 if( pExpr->bDesc==0 ){
237699 pNode->bNomatch = 0;
237700 for(i=0; i<pNode->nChild; i++){
237709 for(i=0; i<pNear->nPhrase; i++){
237711 pPhrase->poslist.n = 0;
237715 for(i=0; i<pNode->nChild; i++){
237761 Fts5ExprPhrase *pLeft = pNear->apPhrase[0];
237770 || pNear->apPhrase[0]->nTerm>1
237771 || pNear->apPhrase[0]->aTerm[0].pSynonym
237772 || pNear->apPhrase[0]->aTerm[0].bFirst
237779 if( pLeft->aTerm[0].pSynonym ){
237780 iLast = fts5ExprSynonymRowid(&pLeft->aTerm[0], bDesc, 0);
237782 iLast = pLeft->aTerm[0].pIter->iRowid;
237787 for(i=0; i<pNear->nPhrase; i++){
237789 for(j=0; j<pPhrase->nTerm; j++){
237792 i64 iRowid = fts5ExprSynonymRowid(pTerm, bDesc, 0);
237794 bMatch = 0;
237796 pNode->bNomatch = 0;
237803 bMatch = 0;
237810 }while( bMatch==0 );
237813 pNode->bNomatch = ((0==fts5ExprNearTest(&rc, pExpr, pNode)) && rc==SQLITE_OK);
237814 assert( pNode->bEof==0 || pNode->bNomatch==0 );
237832 Fts5ExprTerm *pTerm = &pNode->pNear->apPhrase[0]->aTerm[0];
237835 pNode->bNomatch = 0;
237841 i64 iRowid = fts5ExprSynonymRowid(pTerm, pExpr->bDesc, 0);
237846 if( sqlite3Fts5IterEof(p->pIter)==0 ){
237857 if( sqlite3Fts5IterEof(p->pIter)==0 ){
237858 bEof = 0;
237861 bEof = 0;
237882 if( pNode->bEof==0 ){
237900 Fts5ExprPhrase *pPhrase = pNode->pNear->apPhrase[0];
237901 Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
237905 assert( pPhrase->aTerm[0].pSynonym==0 );
237912 pNode->bNomatch = (pPhrase->poslist.n==0);
237926 Fts5IndexIter *pIter = pNode->pNear->apPhrase[0]->aTerm[0].pIter;
237928 assert( pNode->bEof==0 );
237934 if( rc==SQLITE_OK && sqlite3Fts5IterEof(pIter)==0 ){
237938 pNode->bNomatch = 0;
237947 Fts5ExprNode *pNext = pNode->apChild[0];
237953 if( cmp>0 || (cmp==0 && pChild->bNomatch==0) ){
237971 for(i=0; i<pNode->nChild; i++){
237973 assert( p1->bEof || fts5RowidCmp(pExpr, p1->iRowid, iLast)>=0 );
237974 if( p1->bEof==0 ){
237976 || (bFromValid && fts5RowidCmp(pExpr, p1->iRowid, iFrom)<0)
237980 pNode->bNomatch = 0;
238003 assert( pAnd->bEof==0 );
238005 pAnd->bNomatch = 0;
238007 for(iChild=0; iChild<pAnd->nChild; iChild++){
238010 if( cmp>0 ){
238014 pAnd->bNomatch = 0;
238023 assert( pChild->bEof || fts5RowidCmp(pExpr, iLast, pChild->iRowid)<=0 );
238029 bMatch = 0;
238037 }while( bMatch==0 );
238052 int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom);
238056 pNode->bNomatch = 0;
238066 Fts5ExprNode *p1 = pNode->apChild[0];
238070 while( rc==SQLITE_OK && p1->bEof==0 ){
238072 if( cmp>0 ){
238076 assert( rc!=SQLITE_OK || cmp<=0 );
238078 rc = fts5ExprNodeNext(pExpr, p1, 0, 0);
238095 int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom);
238100 pNode->bNomatch = 0;
238115 if( pNode->bEof==0 ){
238157 pNode->bEof = 0;
238158 pNode->bNomatch = 0;
238163 }else if( pNode->xNext==0 ){
238167 int nEof = 0;
238168 for(i=0; i<pNode->nChild && rc==SQLITE_OK; i++){
238171 assert( pChild->bEof==0 || pChild->bEof==1 );
238174 pNode->iRowid = pNode->apChild[0]->iRowid;
238178 if( nEof>0 ) fts5ExprSetEof(pNode);
238187 pNode->bEof = pNode->apChild[0]->bEof;
238205 ** If iterating in ascending rowid order (bDesc==0), the first document
238225 && 0==pRoot->bEof
238226 && fts5RowidCmp(p, pRoot->iRowid, iFirst)<0
238233 assert( pRoot->bEof==0 );
238234 rc = fts5ExprNodeNext(p, pRoot, 0, 0);
238248 assert( pRoot->bEof==0 && pRoot->bNomatch==0 );
238250 rc = fts5ExprNodeNext(p, pRoot, 0, 0);
238251 assert( pRoot->bNomatch==0 || (rc==SQLITE_OK && pRoot->bEof==0) );
238253 if( fts5RowidCmp(p, pRoot->iRowid, iLast)>0 ){
238279 for(i=0; i<pPhrase->nTerm; i++){
238292 if( pPhrase->poslist.nSpace>0 ) fts5BufferFree(&pPhrase->poslist);
238303 pPhrase->aTerm[0].bFirst = 1;
238321 Fts5ExprNearset *pRet = 0;
238324 if( pPhrase==0 ){
238327 if( pNear==0 ){
238331 if( pRet==0 ){
238334 memset(pRet, 0, (size_t)nByte);
238336 }else if( (pNear->nPhrase % SZALLOC)==0 ){
238342 if( pRet==0 ){
238350 if( pRet==0 ){
238355 if( pRet->nPhrase>0 ){
238357 assert( pParse!=0 );
238358 assert( pParse->apPhrase!=0 );
238361 if( pPhrase->nTerm==0 ){
238366 }else if( pLast->nTerm==0 ){
238407 if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){
238411 if( pSyn==0 ){
238414 memset(pSyn, 0, (size_t)nByte);
238426 if( pPhrase==0 || (pPhrase->nTerm % SZALLOC)==0 ){
238428 int nNew = SZALLOC + (pPhrase ? pPhrase->nTerm : 0);
238433 if( pNew==0 ){
238436 if( pPhrase==0 ) memset(pNew, 0, sizeof(Fts5ExprPhrase));
238444 memset(pTerm, 0, sizeof(Fts5ExprTerm));
238471 for(i=0; i<pNear->nPhrase; i++){
238480 assert( pParse->pExpr==0 );
238485 if( (pParse->nPhrase % 8)==0 ){
238489 if( apNew==0 ){
238512 char *z = 0;
238514 memset(&sCtx, 0, sizeof(TokenCtx));
238520 int flags = FTS5_TOKENIZE_QUERY | (bPrefix ? FTS5_TOKENIZE_PREFIX : 0);
238530 sCtx.pPhrase = 0;
238533 if( pAppend==0 ){
238536 return 0;
238541 if( sCtx.pPhrase==0 ){
238564 Fts5ExprPhrase *pOrig = 0; /* The phrase extracted from pExpr */
238565 Fts5Expr *pNew = 0; /* Expression to return via *ppNew */
238566 TokenCtx sCtx = {0,0,0}; /* Context object for fts5ParseTokenize */
238567 if( iPhrase<0 || iPhrase>=pExpr->nPhrase ){
238585 if( rc==SQLITE_OK && ALWAYS(pOrig!=0) ){
238603 for(i=0; rc==SQLITE_OK && i<pOrig->nTerm; i++){
238604 int tflags = 0;
238607 rc = fts5ParseTokenize((void*)&sCtx,tflags,p->pTerm,p->nFullTerm,0,0);
238627 pNew->apExprPhrase[0] = sCtx.pPhrase;
238628 pNew->pRoot->pNear->apPhrase[0] = sCtx.pPhrase;
238633 && pOrig->aTerm[0].pSynonym==0
238634 && pOrig->aTerm[0].bFirst==0
238645 pNew = 0;
238672 int nNear = 0;
238675 for(i=0; i<p->n; i++){
238677 if( c<'0' || c>'9' ){
238683 nNear = nNear * 10 + (p->p[i] - '0');
238706 int nCol = p ? p->nCol : 0; /* Num. columns already in colset object */
238710 assert( iCol>=0 && iCol<pParse->pConfig->nCol );
238713 if( pNew==0 ){
238718 for(i=0; i<nCol; i++){
238751 int iOld = 0;
238752 for(i=0; i<nCol; i++){
238770 Fts5Colset *pRet = 0;
238778 for(iCol=0; iCol<pConfig->nCol; iCol++){
238779 if( 0==sqlite3_stricmp(pConfig->azCol[iCol], z) ) break;
238789 if( pRet==0 ){
238814 pRet = 0;
238823 int iIn = 0; /* Next input in pColset */
238824 int iMerge = 0; /* Next input in pMerge */
238825 int iOut = 0; /* Next output slot in pColset */
238829 if( iDiff==0 ){
238833 }else if( iDiff>0 ){
238863 if( pNear->pColset->nCol==0 ){
238865 pNode->xNext = 0;
238869 *ppFree = 0;
238875 assert( pNode->eType!=FTS5_EOF || pNode->nChild==0 );
238876 for(i=0; i<pNode->nChild; i++){
238906 if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1
238907 && pNear->apPhrase[0]->aTerm[0].pSynonym==0
238908 && pNear->apPhrase[0]->aTerm[0].bFirst==0
238965 int nTerm = pNear->apPhrase[0]->nTerm;
238981 for(ii=0; ii<nTerm; ii++){
238989 Fts5ExprTerm *p = &pNear->apPhrase[0]->aTerm[ii];
238990 Fts5ExprTerm *pTo = &pPhrase->aTerm[0];
238997 0, 0, sqlite3Fts5ParseNearset(pParse, 0, pPhrase)
239005 pRet = 0;
239025 Fts5ExprNode *pRet = 0;
239028 int nChild = 0; /* Number of children of returned node */
239034 if( eType==FTS5_STRING && pNear==0 ) return 0;
239035 if( eType!=FTS5_STRING && pLeft==0 ) return pRight;
239036 if( eType!=FTS5_STRING && pRight==0 ) return pLeft;
239040 && pNear->apPhrase[0]->nTerm>1
239061 for(iPhrase=0; iPhrase<pNear->nPhrase; iPhrase++){
239063 if( pNear->apPhrase[iPhrase]->nTerm==0 ){
239064 pRet->xNext = 0;
239070 Fts5ExprPhrase *pPhrase = pNear->apPhrase[0];
239073 || (pPhrase->nTerm>0 && pPhrase->aTerm[0].bFirst)
239080 pRet = 0;
239092 pRet = 0;
239099 if( pRet==0 ){
239113 Fts5ExprNode *pRet = 0;
239143 assert( pParse->apPhrase[pParse->nPhrase-1]==pRight->pNear->apPhrase[0] );
239159 assert( ap[0]==pPrev->pNear->apPhrase[0] );
239166 pRet = sqlite3Fts5ParseNode(pParse, FTS5_AND, pLeft, pRight, 0);
239175 sqlite3_int64 nByte = 0;
239186 int i = 0;
239202 zQuoted[i++] = '\0';
239233 char *zRet = 0;
239240 if( zRet==0 ) return 0;
239245 zRet = fts5PrintfAppend(zRet, "-col %d ", aiCol[0]);
239247 zRet = fts5PrintfAppend(zRet, "-col {%d", aiCol[0]);
239253 if( zRet==0 ) return 0;
239258 if( zRet==0 ) return 0;
239262 if( zRet==0 ) return 0;
239264 for(i=0; i<pNear->nPhrase; i++){
239268 for(iTerm=0; zRet && iTerm<pPhrase->nTerm; iTerm++){
239270 zRet = fts5PrintfAppend(zRet, "%s%.*s", iTerm==0?"":" ",
239279 if( zRet==0 ) return 0;
239282 }else if( pExpr->eType==0 ){
239285 char const *zOp = 0;
239297 for(i=0; zRet && i<pExpr->nChild; i++){
239301 zRet = 0;
239312 char *zRet = 0;
239313 if( pExpr->eType==0 ){
239325 for(ii=0; ii<pColset->nCol; ii++){
239333 if( zRet==0 ) return 0;
239338 if( zRet==0 ) return 0;
239341 for(i=0; i<pNear->nPhrase; i++){
239343 if( i!=0 ){
239345 if( zRet==0 ) return 0;
239347 for(iTerm=0; iTerm<pPhrase->nTerm; iTerm++){
239350 zRet = fts5PrintfAppend(zRet, "%s%s", iTerm==0?"":" + ", zTerm);
239353 if( zTerm==0 || zRet==0 ){
239355 return 0;
239362 if( zRet==0 ) return 0;
239366 char const *zOp = 0;
239378 for(i=0; i<pExpr->nChild; i++){
239380 if( z==0 ){
239382 zRet = 0;
239387 (i==0 ? "" : zOp),
239391 if( zRet==0 ) break;
239399 ** The implementation of user-defined scalar functions fts5_expr() (bTcl==0)
239400 ** and fts5_expr_tcl() (bTcl!=0).
239410 const char *zExpr = 0;
239411 char *zErr = 0;
239412 Fts5Expr *pExpr = 0;
239419 Fts5Config *pConfig = 0;
239438 if( azConfig==0 ){
239442 azConfig[0] = 0;
239450 zExpr = (const char*)sqlite3_value_text(apVal[0]);
239451 if( zExpr==0 ) zExpr = "";
239455 rc = sqlite3Fts5ExprNew(pConfig, 0, pConfig->nCol, zExpr, &pExpr, &zErr);
239459 if( pExpr->pRoot->xNext==0 ){
239466 if( zText==0 ){
239492 fts5ExprFunction(pCtx, nArg, apVal, 0);
239505 ** unicode code point, 1 is returned. Otherwise 0.
239520 memset(aArr, 0, sizeof(aArr));
239524 iCode = sqlite3_value_int(apVal[0]);
239539 int bRemoveDiacritics = 0;
239540 iCode = sqlite3_value_int(apVal[0]);
239566 for(i=0; rc==SQLITE_OK && i<ArraySize(aFunc); i++){
239568 rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0);
239589 return (pExpr ? pExpr->nPhrase : 0);
239596 if( iPhrase<0 || iPhrase>=pExpr->nPhrase ) return 0;
239608 if( pNode->bEof==0 && pNode->iRowid==pExpr->pRoot->iRowid ){
239612 *pa = 0;
239613 nRet = 0;
239638 memset(pRet, 0, sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
239639 for(i=0; i<pExpr->nPhrase; i++){
239644 (pBuf->n==0 || pNode->iRowid!=pExpr->pRoot->iRowid || pNode->bEof)
239648 pBuf->n = 0;
239667 for(i=0; i<pColset->nCol; i++){
239670 return 0;
239675 ** an embedded 0x00 byte. If it does, return the number of bytes in
239676 ** the buffer before the 0x00. If it does not, return nToken.
239680 for(ii=0; ii<nToken && pToken[ii]; ii++){}
239704 if( (tflags & FTS5_TOKEN_COLOCATED)==0 ) p->iOff++;
239705 for(i=0; i<pExpr->nPhrase; i++){
239707 if( p->aPopulator[i].bOk==0 ) continue;
239708 for(pT=&pExpr->apExprPhrase[i]->aTerm[0]; pT; pT=pT->pSynonym){
239710 && memcmp(pT->pTerm, pToken, pT->nQueryTerm)==0
239717 int iTokOff = p->iOff & 0x7FFFFFFF;
239743 for(i=0; i<pExpr->nPhrase; i++){
239746 if( (pColset && 0==fts5ExprColsetTest(pColset, iCol))
239749 aPopulator[i].bOk = 0;
239762 pNode->pNear->apPhrase[0]->poslist.n = 0;
239765 for(i=0; i<pNode->nChild; i++){
239773 pNode->bEof = 0;
239777 return (pNode->pNear->apPhrase[0]->poslist.n>0);
239781 for(i=0; i<pNode->nChild; i++){
239782 if( fts5ExprCheckPoslists(pNode->apChild[i], iRowid)==0 ){
239784 return 0;
239792 int bRet = 0;
239793 for(i=0; i<pNode->nChild; i++){
239803 if( 0==fts5ExprCheckPoslists(pNode->apChild[0], iRowid)
239804 || 0!=fts5ExprCheckPoslists(pNode->apChild[1], iRowid)
239807 return 0;
239832 assert( iPhrase>=0 && iPhrase<pExpr->nPhrase );
239835 if( pNode->bEof==0
239837 && pPhrase->poslist.n>0
239839 Fts5ExprTerm *pTerm = &pPhrase->aTerm[0];
239846 *ppCollist = pPhrase->aTerm[0].pIter->pData;
239847 *pnCollist = pPhrase->aTerm[0].pIter->nData;
239850 *ppCollist = 0;
239851 *pnCollist = 0;
239867 Fts5ExprPhrase *pPhrase = 0;
239869 if( iPhrase<0 || iPhrase>=pExpr->nPhrase ){
239873 if( iToken<0 || iToken>=pPhrase->nTerm ){
239895 Fts5ExprPhrase *pPhrase = 0;
239896 Fts5ExprTerm *pTerm = 0;
239899 if( iPhrase<0 || iPhrase>=pExpr->nPhrase ){
239903 if( iToken<0 || iToken>=pPhrase->nTerm ){
239907 if( pTerm->bPrefix==0 ){
239926 for(ii=0; ii<pExpr->nPhrase; ii++){
239928 for(pT=&pExpr->apExprPhrase[ii]->aTerm[0]; pT; pT=pT->pSynonym){
239956 ** to accumuluate "term -> doclist" content before it is flused to a level-0
239979 ** followed by the term data. For example: "0token". There is no
239986 ** * Position list, without 0x00 terminator.
240028 if( pNew==0 ){
240032 memset(pNew, 0, sizeof(Fts5Hash));
240039 if( pNew->aSlot==0 ){
240041 *ppNew = 0;
240044 memset(pNew->aSlot, 0, (size_t)nByte);
240066 for(i=0; i<pHash->nSlot; i++){
240074 memset(pHash->aSlot, 0, pHash->nSlot * sizeof(Fts5HashEntry*));
240075 pHash->nEntry = 0;
240081 for(i=n-1; i>=0; i--){
240090 for(i=n-1; i>=0; i--){
240108 memset(apNew, 0, nNew*sizeof(Fts5HashEntry*));
240110 for(i=0; i<pHash->nSlot; i++){
240132 int nRet = 0;
240139 pPtr[nData++] = 0x00;
240141 pPtr[nData++] = 0x00;
240148 assert( p->bDel==0 || p->bDel==1 );
240160 if( p2==0 ){
240161 p->iSzPoslist = 0;
240162 p->bDel = 0;
240163 p->bContent = 0;
240189 int nIncr = 0; /* Amount to increment (*pHash->pnByte) by */
240198 if( zKey[0]==bByte
240200 && memcmp(&zKey[1], pToken, nToken)==0
240207 if( p==0 ){
240223 memset(p, 0, sizeof(Fts5HashEntry));
240226 zKey[0] = bByte;
240230 zKey[nToken+1] = '\0';
240243 p->iCol = (pHash->eDetail==FTS5_DETAIL_FULL ? 0 : -1);
240263 if( pNew==0 ) return SQLITE_NOMEM;
240279 fts5HashAddPoslistSize(pHash, p, 0);
240286 p->iCol = (pHash->eDetail==FTS5_DETAIL_FULL ? 0 : -1);
240287 p->iPos = 0;
240291 if( iCol>=0 ){
240299 pPtr[p->nData++] = 0x01;
240302 p->iPos = 0;
240337 Fts5HashEntry *pRet = 0;
240341 if( p1==0 ){
240343 p2 = 0;
240344 }else if( p2==0 ){
240346 p1 = 0;
240353 if( cmp==0 ){
240356 assert( cmp!=0 );
240358 if( cmp>0 ){
240369 *ppOut = 0;
240391 *ppSorted = 0;
240394 memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
240396 for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
240399 if( pTerm==0
240400 || (pIter->nKey>=nTerm && 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm))
240403 pEntry->pScanNext = 0;
240404 for(i=0; ap[i]; i++){
240406 ap[i] = 0;
240413 pList = 0;
240414 for(i=0; i<nMergeSlot; i++){
240434 char *zKey = 0;
240439 if( nTerm==p->nKey && memcmp(zKey, pTerm, nTerm)==0 ) break;
240452 *pnDoclist = 0;
240456 *ppOut = 0;
240457 *pnDoclist = 0;
240472 int nEntry = 0;
240474 for(ii=0; ii<pHash->nSlot; ii++){
240475 Fts5HashEntry *p = 0;
240489 return pHash->nEntry==0;
240498 return (p->pScan==0);
240512 fts5HashAddPoslistSize(pHash, p, 0);
240518 *pzTerm = 0;
240519 *pnTerm = 0;
240520 *ppDoclist = 0;
240521 *pnDoclist = 0;
240575 #define FTS5_MAIN_PREFIX '0'
240593 ** 4 bytes [0xff 0x00 0x00 0x01]. This is unambiguous as the value of a
240594 ** varint has to be at least 16256 to begin with "0xFF". And the default
240620 ** followed by the following 4 bytes: [0xFF 0x00 0x00 0x01].
240628 ** Then, for each level from 0 to nMax:
240633 ** + segment id (always > 0)
240634 ** + first leaf page number (often 1, always greater than 0)
240673 ** varint: rowid delta (always > 0)
240681 ** collist: collist for column 0
240683 ** 0x01 byte
240701 ** and occurs before the first term (otherwise 0).
240704 ** footer is 0 bytes in size, then this field is the same as the
240736 ** 0x01: Clear if leaf is also the root page, otherwise set.
240744 ** or an 0x00 byte otherwise.
240749 ** 0x01: Clear for root page, otherwise set.
240778 ** 1-byte: rowid-0-tombstone flag. This flag is only valid on the
240779 ** first tombstone hash page for each segment (iPg=0). If set,
240780 ** the hash table contains rowid 0. If clear, it does not.
240781 ** Rowid 0 is handled specially.
240821 #define FTS5_SEGMENT_ROWID(segid, pgno) fts5_dri(segid, 0, 0, pgno)
240823 #define FTS5_TOMBSTONE_ROWID(segid,ipg) fts5_dri(segid+(1<<16), 0, 0, ipg)
240909 /* Output variables. aPoslist==0 at EOF */
240941 Fts5StructureSegment *aSeg; /* Array of segments. aSeg[0] is oldest. */
240945 u64 nWriteCounter; /* Total leaves written to level 0 */
240974 /* TODO1: Can use (writer.pgidx.n==0) instead of bFirstTermInPage */
241094 #define FTS5_SEGITER_ONETERM 0x01
241095 #define FTS5_SEGITER_REVERSE 0x02
241125 ** the smallest key overall. aFirst[0] is unused.
241187 aOut[0] = (iVal>>8);
241188 aOut[1] = (iVal&0xFF);
241192 return ((u16)aIn[0] << 8) + aIn[1];
241201 return ((u64)a[0] << 56)
241208 + ((u64)a[7] << 0);
241217 return ((u32)a[0] << 24)
241220 + ((u32)a[3] << 0);
241228 a[0] = ((iVal >> 56) & 0xFF);
241229 a[1] = ((iVal >> 48) & 0xFF);
241230 a[2] = ((iVal >> 40) & 0xFF);
241231 a[3] = ((iVal >> 32) & 0xFF);
241232 a[4] = ((iVal >> 24) & 0xFF);
241233 a[5] = ((iVal >> 16) & 0xFF);
241234 a[6] = ((iVal >> 8) & 0xFF);
241235 a[7] = ((iVal >> 0) & 0xFF);
241243 a[0] = ((iVal >> 24) & 0xFF);
241244 a[1] = ((iVal >> 16) & 0xFF);
241245 a[2] = ((iVal >> 8) & 0xFF);
241246 a[3] = ((iVal >> 0) & 0xFF);
241262 ** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
241274 return (res==0 ? (pLeft->n - nRight) : res);
241282 ** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
241290 assert( nCmp<=0 || pLeft->p!=0 );
241291 assert( nCmp<=0 || pRight->p!=0 );
241293 return (res==0 ? (pLeft->n - pRight->n) : res);
241308 p->pReader = 0;
241320 Fts5Data *pRet = 0;
241329 p->pReader = 0;
241331 assert( p->pReader==0 );
241341 if( p->pReader==0 && rc==SQLITE_OK ){
241344 pConfig->zDb, p->zDataTbl, "block", iRowid, 0, &p->pReader
241356 u8 *aOut = 0; /* Read blob data into this buffer */
241368 rc = sqlite3_blob_read(p->pReader, aOut, nByte, 0);
241372 pRet = 0;
241375 pRet->p[nByte] = 0x00;
241376 pRet->p[nByte+1] = 0x00;
241384 assert( (pRet==0)==(p->rc!=SQLITE_OK) );
241403 pRet = 0;
241418 ppStmt, 0);
241434 if( p->pWriter==0 ){
241458 if( p->pDeleter==0 ){
241478 i64 iFirst = FTS5_SEGMENT_ROWID(iSegid, 0);
241479 i64 iLast = FTS5_SEGMENT_ROWID(iSegid+1, 0)-1;
241483 i64 iTomb1 = FTS5_TOMBSTONE_ROWID(iSegid, 0);
241487 if( p->pIdxDeleter==0 ){
241506 if( pStruct && 0>=(--pStruct->nRef) ){
241508 assert( pStruct->nRef==0 );
241509 for(i=0; i<pStruct->nLevel; i++){
241551 for(i=0; i<p->nLevel; i++) pNew->aLevel[i].aSeg = 0;
241552 for(i=0; i<p->nLevel; i++){
241556 if( pLvl->aSeg==0 ){
241557 for(i=0; i<p->nLevel; i++){
241591 int i = 0;
241593 int nLevel = 0;
241594 int nSegment = 0;
241596 Fts5Structure *pRet = 0; /* Structure object to return */
241597 int bStructureV2 = 0; /* True for FTS5_STRUCTURE_V2 */
241598 u64 nOriginCntr = 0; /* Largest origin value seen so far */
241605 if( 0==memcmp(&pData[i], FTS5_STRUCTURE_V2, 4) ){
241614 if( nLevel>FTS5_MAX_SEGMENT || nLevel<0
241615 || nSegment>FTS5_MAX_SEGMENT || nSegment<0
241631 for(iLvl=0; rc==SQLITE_OK && iLvl<nLevel; iLvl++){
241633 int nTotal = 0;
241650 for(iSeg=0; iSeg<nTotal; iSeg++){
241656 assert( pSeg!=0 );
241673 if( iLvl>0 && pLvl[-1].nMerge && nTotal==0 ) rc = FTS5_CORRUPT;
241677 if( nSegment!=0 && rc==SQLITE_OK ) rc = FTS5_CORRUPT;
241684 pRet = 0;
241698 assert( (ppStruct!=0 && (*ppStruct)!=0) || (*pRc)!=SQLITE_OK );
241709 memset(&pStruct->aLevel[nLevel], 0, sizeof(Fts5StructureLevel));
241737 if( bInsert==0 ){
241738 memset(&aNew[pLvl->nSeg], 0, sizeof(Fts5StructureSegment) * nExtra);
241742 memset(aNew, 0, sizeof(Fts5StructureSegment) * nExtra);
241752 Fts5Structure *pRet = 0;
241760 memset(&pData->p[pData->nn], 0, FTS5_DATA_PADDING);
241762 if( p->rc==SQLITE_OK && (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
241768 pRet = 0;
241776 i64 iVersion = 0;
241779 if( p->pDataVersion==0 ){
241783 if( p->rc ) return 0;
241787 iVersion = sqlite3_column_int64(p->pDataVersion, 0);
241808 if( p->pStruct==0 ){
241815 #if 0
241822 for(i=0; i<pTest->nLevel; i++){
241825 for(j=0; j<pTest->aLevel[i].nSeg; j++){
241838 if( p->rc!=SQLITE_OK ) return 0;
241839 assert( p->iStructVersion!=0 );
241840 assert( p->pStruct!=0 );
241848 p->pStruct = 0;
241858 int nSegment = 0; /* Total number of segments */
241861 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
241893 int nHdr = (pStruct->nOriginCntr>0 ? (4+4+9+9+9) : (4+9+9));
241896 memset(&buf, 0, sizeof(Fts5Buffer));
241900 if( iCookie<0 ) iCookie = 0;
241902 if( 0==sqlite3Fts5BufferSize(&p->rc, &buf, nHdr) ){
241905 if( pStruct->nOriginCntr>0 ){
241913 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
241920 for(iSeg=0; iSeg<pLvl->nSeg; iSeg++){
241925 if( pStruct->nOriginCntr>0 ){
241940 #if 0
241945 memset(&buf, 0, sizeof(buf));
241973 if( pOut->nMerge==0 ){
241977 for(is=pLvl->nSeg-1; is>=0; is--){
242015 int szPromote = 0; /* Promote anything this size or smaller */
242020 if( nSeg==0 ) return;
242025 for(iTst=iLvl-1; iTst>=0 && pStruct->aLevel[iTst].nSeg==0; iTst--);
242026 if( iTst>=0 ){
242028 int szMax = 0;
242030 assert( pTst->nMerge==0 );
242031 for(i=0; i<pTst->nSeg; i++){
242045 if( iPromote<0 ){
242061 if( pLvl->iOff==0 ){
242062 assert( pLvl->bEof==0 );
242097 if( pLvl[1].bEof==0 ){
242099 memset(pLvl, 0, sizeof(Fts5DlidxLvl));
242108 return pIter->aLvl[0].bEof;
242111 return fts5DlidxIterNextR(p, pIter, 0);
242127 for(i=0; i<pIter->nLvl; i++){
242130 return pIter->aLvl[0].bEof;
242135 return p->rc!=SQLITE_OK || pIter->aLvl[0].bEof;
242142 for(i=pIter->nLvl-1; p->rc==SQLITE_OK && i>=0; i--){
242144 while( fts5DlidxLvlNext(pLvl)==0 );
242145 pLvl->bEof = 0;
242147 if( i>0 ){
242150 memset(pChild, 0, sizeof(Fts5DlidxLvl));
242164 assert( pLvl->bEof==0 );
242170 pLvl->iOff = 0;
242173 int nZero = 0;
242175 u64 delta = 0;
242177 while( a[ii]==0 ){
242200 if( pLvl[1].bEof==0 ){
242202 memset(pLvl, 0, sizeof(Fts5DlidxLvl));
242207 while( fts5DlidxLvlNext(pLvl)==0 );
242208 pLvl->bEof = 0;
242214 return pIter->aLvl[0].bEof;
242217 return fts5DlidxIterPrevR(p, pIter, 0);
242226 for(i=0; i<pIter->nLvl; i++){
242239 Fts5DlidxIter *pIter = 0;
242241 int bDone = 0;
242243 for(i=0; p->rc==SQLITE_OK && bDone==0; i++){
242248 if( pNew==0 ){
242254 memset(pLvl, 0, sizeof(Fts5DlidxLvl));
242256 if( pLvl->pData && (pLvl->pData->p[0] & 0x0001)==0 ){
242265 if( bRev==0 ){
242274 pIter = 0;
242281 return pIter->aLvl[0].iRowid;
242284 return pIter->aLvl[0].iLeafPgno;
242300 pIter->pNextLeaf = 0;
242306 pIter->pLeaf = 0;
242330 int n = 0;
242332 assert_nc( nSz>=0 );
242334 *pbDel = nSz & 0x0001;
242355 pIter->bDel = 0;
242357 if( iOff<iEod && pIter->pLeaf->p[iOff]==0 ){
242360 if( iOff<iEod && pIter->pLeaf->p[iOff]==0 ){
242364 pIter->nPos = 0;
242370 pIter->bDel = (nSz & 0x0001);
242372 assert_nc( pIter->nPos>=0 );
242385 if( pIter->pLeaf==0 ){
242399 ** of the "nPrefix" field (if there was one - it is passed 0 if this is
242417 if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
242461 if( nTomb>0 ){
242486 if( pSeg->pgnoFirst==0 ){
242490 ** The caller will see the (pIter->pLeaf==0) and assume the iterator is
242492 assert( pIter->pLeaf==0 );
242497 memset(pIter, 0, sizeof(*pIter));
242508 assert( pIter->pLeaf!=0 );
242512 fts5SegIterLoadTerm(p, pIter, 0);
242538 int iRowidOffset = 0;
242546 u64 iDelta = 0;
242550 if( i<n && a[i]==0 ){
242552 if( i<n && a[i]==0 ) i++;
242568 if( aNew==0 ){
242591 pIter->pLeaf = 0;
242601 ** In this case leave pIter->pLeaf==0, this iterator is at EOF. */
242603 assert( pIter->pLeaf==0 );
242639 ** points to a delete marker. A delete marker is an entry with a 0 byte
242644 return (p->rc==SQLITE_OK && pSeg->pLeaf && pSeg->nPos==0);
242658 assert( pIter->pNextLeaf==0 );
242661 if( pIter->iRowidOffset>0 ){
242694 assert( (pIter->flags & FTS5_SEGITER_REVERSE)==0 );
242703 if( p->rc || pIter->pLeaf==0 ) return;
242704 pIter->iRowid = 0;
242714 }else if( (pIter->flags & FTS5_SEGITER_ONETERM)==0 ){
242716 int nKeep = 0;
242723 const u8 *pList = 0;
242724 const char *zTerm = 0;
242725 int nTerm = 0;
242729 if( pList==0 ) goto next_none_eof;
242748 pIter->pLeaf = 0;
242766 int bNewTerm = 0;
242767 int nKeep = 0;
242771 assert( pbNewTerm==0 || *pbNewTerm==0 );
242793 assert_nc( iDelta>0 );
242797 }else if( pIter->pSeg==0 ){
242798 const u8 *pList = 0;
242799 const char *zTerm = 0;
242800 int nTerm = 0;
242801 int nList = 0;
242803 if( 0==(pIter->flags & FTS5_SEGITER_ONETERM) ){
242807 if( pList==0 ){
242809 pIter->pLeaf = 0;
242820 iOff = 0;
242822 while( iOff==0 ){
242825 if( pLeaf==0 ) break;
242858 pIter->pLeaf = 0;
242871 pIter->bDel = (nSz & 0x0001);
242873 assert_nc( pIter->nPos>=0 );
242882 while( (a[iOff++] & 0x80) && iOff<iEnd ); \
242892 Fts5Data *pLast = 0;
242893 int pgnoLast = 0;
242935 if( bTermless==0 ) break;
242985 assert( pIter->pDlidx==0 );
243023 u32 nMatch = 0;
243024 u32 nKeep = 0;
243025 u32 nNew = 0;
243028 int bEndOfPage = 0;
243053 for(i=0; i<nCmp; i++){
243088 if( bGe==0 ){
243090 pIter->pLeaf = 0;
243095 if( pIter->pLeaf==0 ) return;
243097 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
243104 nKeep = 0;
243140 if( p->pIdxSelect==0 ){
243167 int bDlidx = 0; /* True if there is a doclist-index */
243168 sqlite3_stmt *pIdxSelect = 0;
243170 assert( bGe==0 || (flags & FTS5INDEX_QUERY_DESC)==0 );
243172 memset(pIter, 0, sizeof(*pIter));
243182 i64 val = sqlite3_column_int(pIdxSelect, 0);
243184 bDlidx = (val & 0x0001);
243191 bDlidx = 0;
243201 if( p->rc==SQLITE_OK && (bGe==0 || (flags & FTS5INDEX_QUERY_SCANONETERM)) ){
243217 if( 0==(flags & FTS5INDEX_QUERY_SCANONETERM) ){
243230 || pIter->pLeaf==0 /* 2 */
243231 || fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)==0 /* 3 */
243232 || (bGe && fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)>0) /* 4 */
243241 if( p->pIdxNextSelect==0 ){
243265 int bDlidx = 0;
243266 sqlite3_stmt *pSel = 0; /* SELECT to find iPg */
243275 i64 val = sqlite3_column_int64(pSel, 0);
243277 bDlidx = (val & 0x0001);
243284 memset(pIter, 0, sizeof(*pIter));
243287 if( iPg>=0 ){
243294 int iTermOff = 0;
243299 fts5SegIterLoadTerm(p, pIter, 0);
243304 fts5BufferCompareBlob(&pIter->term, (const u8*)pTerm, nTerm)>0
243323 int nList = 0;
243324 const u8 *z = 0;
243325 int n = 0;
243326 Fts5Data *pLeaf = 0;
243331 if( pTerm==0 || (flags & FTS5INDEX_QUERY_SCAN) ){
243332 const u8 *pList = 0;
243349 p->bDelete = 0;
243387 for(ii=0; ii<n; ii++){
243396 ** reaches 0, free it and its contents.
243401 if( p->nRef<=0 ){
243403 for(ii=0; ii<p->nTombstone; ii++){
243421 memset(pIter, 0, sizeof(Fts5SegIter));
243442 if( p1->pLeaf==0 ){
243444 }else if( p2->pLeaf==0 ){
243449 if( res==0 ) res = p1->term.n - p2->term.n;
243451 if( res==0 ){
243456 assert( pRes->bTermEq==0 );
243459 if( res<0 ){
243479 assert( (pFirst->pLeaf==0)==pIter->base.bEof );
243482 for(i=0; i<pIter->nSeg; i++){
243485 || p1->pLeaf==0
243492 for(i=0; i<pIter->nSeg; i+=2){
243527 assert( iOut<pIter->nSeg && iOut>0 );
243528 assert( pIter->bRev==0 || pIter->bRev==1 );
243540 pRes->bTermEq = 0;
243541 if( p1->pLeaf==0 ){ /* If p1 is at EOF */
243543 }else if( p2->pLeaf==0 ){ /* If p2 is at EOF */
243547 if( res==0 ){
243549 assert_nc( i2!=0 );
243556 assert( res!=0 );
243557 if( res<0 ){
243565 return 0;
243584 pIter->pNextLeaf = 0;
243590 if( pIter->pLeaf==0 ) break;
243592 if( iOff>0 ){
243627 if( bRev==0 ){
243635 bMove = 0;
243638 assert( pIter->pNextLeaf==0 );
243650 bMove = 0;
243655 if( bMove && p->rc==SQLITE_OK ) pIter->xNext(p, pIter, 0);
243656 if( pIter->pLeaf==0 ) break;
243657 if( bRev==0 && pIter->iRowid>=iMatch ) break;
243658 if( bRev!=0 && pIter->iRowid<=iMatch ) break;
243669 for(i=0; i<pIter->nSeg; i++){
243689 pSeg->xNext(p, pSeg, 0);
243699 ** If it does so successfully, 0 is returned. Otherwise 1.
243716 Fts5SegIter *pOther = &pIter->aSeg[iChanged ^ 0x0001];
243722 assert( pRes->bTermEq==0 || pOther->pLeaf );
243737 pOther = &pIter->aSeg[ pIter->aFirst[i ^ 0x0001].iFirst ];
243742 return 0;
243750 pIter->base.bEof = pSeg->pLeaf==0;
243758 #define TOMBSTONE_KEYSIZE(pPg) (pPg->p[0]==4 ? 4 : 8)
243778 if( iRowid==0 ){
243784 if( nCollide--==0 ) break;
243791 if( nCollide--==0 ) break;
243796 return 0;
243812 assert( iPg>=0 );
243816 if( pArray->apTombstone[iPg]==0 ){
243820 if( pArray->apTombstone[iPg]==0 ) return 0;
243830 return 0;
243847 assert( pIter->base.bEof==0 );
243850 int bNewTerm = 0;
243859 if( pSeg->pLeaf==0 || bNewTerm
243865 if( pSeg->pLeaf==0 ) return;
243870 if( (pIter->bSkipEmpty==0 || pSeg->nPos)
243871 && 0==fts5MultiIterIsDeleted(pIter)
243876 bUseFrom = 0;
243887 *pbNewTerm = 0;
243891 int bNewTerm = 0;
243895 if( pSeg->pLeaf==0 || bNewTerm
243942 assert_nc( nChunk>=0 );
243943 if( nChunk>0 ){
243968 for(i=0; i<pColset->nCol; i++){
243971 return 0;
243981 assert_nc( nChunk>=0 );
243982 if( nChunk>0 ){
243983 int i = 0;
244004 assert_nc( nChunk>=0 );
244005 if( nChunk>0 ){
244008 int i = 0;
244009 int iStart = 0;
244018 pCtx->eState = 0;
244023 while( i<nChunk && pChunk[i]!=0x01 ){
244024 while( pChunk[i] & 0x80 ) i++;
244056 Fts5Data *pData = 0;
244060 int pgnoSave = 0;
244065 if( (pSeg->flags & FTS5_SEGITER_REVERSE)==0 ){
244073 if( nRem<=0 ){
244075 }else if( pSeg->pSeg==0 ){
244081 if( pData==0 ) break;
244085 assert( pSeg->pNextLeaf==0 );
244087 pData = 0;
244105 assert( pBuf!=0 );
244106 assert( pSeg!=0 );
244107 if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+FTS5_DATA_ZERO_PADDING) ){
244108 assert( pBuf->p!=0 );
244110 memset(&pBuf->p[pBuf->n+pSeg->nPos], 0, FTS5_DATA_ZERO_PADDING);
244111 if( pColset==0 ){
244118 sCtx.eState = fts5IndexColsetTest(pColset, 0);
244119 assert( sCtx.eState==0 || sCtx.eState==1 );
244123 memset(&sCtx, 0, sizeof(sCtx));
244154 int i = 0;
244155 int iCurrent = 0;
244171 /* Advance pointer p until it points to pEnd or an 0x01 byte that is
244173 while( p<pEnd && *p!=0x01 ){
244174 while( *p++ & 0x80 );
244192 if( iCurrent & 0x80 ){
244219 assert( pIter->pColset==0 );
244230 fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist);
244236 ** xSetOutputs callback used when the Fts5Colset object has nCol==0 (match
244241 pIter->base.nData = 0;
244277 int iPrev = 0;
244282 int iPrevOut = 0;
244287 iPrev += (int)a++[0] - 2;
244333 assert( pIter!=0 || (*pRc)!=SQLITE_OK );
244340 else if( pIter->pColset==0 ){
244344 else if( pIter->pColset->nCol==0 ){
244370 for(iIter=pIter->nSeg-1; iIter>0; iIter--){
244374 if( p->rc==SQLITE_OK ) pSeg->xNext(p, pSeg, 0);
244384 fts5MultiIterNext(p, pIter, 0, 0);
244385 }else if( pIter->base.bEof==0 ){
244407 const u8 *pTerm, int nTerm, /* Term to seek to (or NULL/0) */
244409 int nSegment, /* Number of segments to merge (iLevel>=0) */
244412 int nSeg = 0; /* Number of segment-iters in use */
244413 int iIter = 0; /* */
244418 assert( (pTerm==0 && nTerm==0) || iLevel<0 );
244422 if( iLevel<0 ){
244425 nSeg += (p->pHash && 0==(flags & FTS5INDEX_QUERY_SKIPHASH));
244431 if( pNew==0 ){
244435 pNew->bRev = (0!=(flags & FTS5INDEX_QUERY_DESC));
244436 pNew->bSkipEmpty = (0!=(flags & FTS5INDEX_QUERY_SKIPEMPTY));
244438 if( (flags & FTS5INDEX_QUERY_NOOUTPUT)==0 ){
244444 if( iLevel<0 ){
244446 if( p->pHash && 0==(flags & FTS5INDEX_QUERY_SKIPHASH) ){
244451 for(pLvl=&pStruct->aLevel[0]; pLvl<pEnd; pLvl++){
244452 for(iSeg=pLvl->nSeg-1; iSeg>=0; iSeg--){
244455 if( pTerm==0 ){
244464 for(iSeg=nSeg-1; iSeg>=0; iSeg--){
244479 *ppOut = 0;
244483 assert( (*ppOut)!=0 || p->rc!=SQLITE_OK );
244502 if( pData->szLeaf>0 ){
244514 pData = 0;
244531 assert( pIter!=0 || p->rc!=SQLITE_OK );
244533 || (pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf==0)==pIter->base.bEof
244561 if( pIter->bRev==0 && iRowid>=iMatch ) break;
244562 if( pIter->bRev!=0 && iRowid<=iMatch ) break;
244582 ** If an error has already occurred, this function is a no-op. 0 is
244586 int iSegid = 0;
244598 memset(aUsed, 0, sizeof(aUsed));
244599 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
244600 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
244602 if( iId<=FTS5_MAX_SEGMENT && iId>0 ){
244608 for(i=0; aUsed[i]==0xFFFFFFFF; i++);
244610 for(iSegid=0; mask & ((u32)1 << iSegid); iSegid++);
244614 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
244615 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
244619 assert_nc( iSegid>0 && iSegid<=FTS5_MAX_SEGMENT );
244624 u8 aBlob[2] = {0xff, 0xff};
244643 assert( p->pHash || p->nPendingData==0 );
244646 p->nPendingData = 0;
244647 p->nPendingRow = 0;
244650 p->nContentlessDelete = 0;
244662 for(i=0; i<nOld; i++){
244674 assert( bFlush==0 || (pWriter->nDlidx>0 && pWriter->aDlidx[0].buf.n>0) );
244675 for(i=0; i<pWriter->nDlidx; i++){
244677 if( pDlidx->buf.n==0 ) break;
244679 assert( pDlidx->pgno!=0 );
244686 pDlidx->bPrevValid = 0;
244703 if( aDlidx==0 ){
244707 memset(&aDlidx[pWriter->nDlidx], 0, nByte);
244721 int bFlag = 0;
244725 if( pWriter->aDlidx[0].buf.n>0 && pWriter->nEmpty>=FTS5_MIN_DLIDX_SIZE ){
244729 pWriter->nEmpty = 0;
244747 assert( pWriter->iBtPage || pWriter->nEmpty==0 );
244748 if( pWriter->iBtPage==0 ) return;
244752 const char *z = (pWriter->btterm.n>0?(const char*)pWriter->btterm.p:"");
244761 pWriter->iBtPage = 0;
244794 ** has already been started, append an 0x00 byte to it. */
244795 if( pWriter->bFirstRowidInPage && pWriter->aDlidx[0].buf.n>0 ){
244796 Fts5DlidxWriter *pDlidx = &pWriter->aDlidx[0];
244798 sqlite3Fts5BufferAppendVarint(&p->rc, &pDlidx->buf, 0);
244825 int bDone = 0;
244827 for(i=0; p->rc==SQLITE_OK && bDone==0; i++){
244837 pDlidx->buf.p[0] = 0x01; /* Not the root node */
244844 if( p->rc==SQLITE_OK && pDlidx[1].buf.n==0 ){
244849 sqlite3Fts5BufferAppendVarint(&p->rc, &pDlidx[1].buf, 0);
244857 pDlidx->bPrevValid = 0;
244866 i64 iPgno = (i==0 ? pWriter->writer.pgno : pDlidx[-1].pgno);
244867 assert( pDlidx->buf.n==0 );
244880 static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
244884 assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
244887 assert( 0==fts5GetU16(&pPage->buf.p[2]) );
244892 assert( pPage->pgidx.n==0 );
244907 pPage->iPrevPgidx = 0;
244953 #if 0
244959 nPrefix = 0;
244994 pWriter->bFirstTermInPage = 0;
244996 pWriter->bFirstRowidInPage = 0;
244999 assert( p->rc || (pWriter->nDlidx>0 && pWriter->aDlidx[0].buf.n==0) );
245000 pWriter->aDlidx[0].pgno = pPage->pgno;
245036 pWriter->bFirstRowidInDoclist = 0;
245037 pWriter->bFirstRowidInPage = 0;
245051 assert( p->pConfig->pgsz>0 || p->rc!=SQLITE_OK );
245056 int nCopy = 0;
245066 if( n>0 ){
245097 for(i=0; i<pWriter->nDlidx; i++){
245110 memset(pWriter, 0, sizeof(Fts5SegWriter));
245118 assert( pWriter->writer.buf.n==0 );
245119 assert( pWriter->writer.pgidx.n==0 );
245125 if( p->pIdxWriter==0 ){
245134 /* Initialize the 4-byte leaf-page header to 0x00. */
245135 memset(pWriter->writer.buf.p, 0, 4);
245153 memset(&buf, 0, sizeof(Fts5Buffer));
245154 for(i=0; i<pIter->nSeg && p->rc==SQLITE_OK; i++){
245156 if( pSeg->pSeg==0 ){
245158 }else if( pSeg->pLeaf==0 ){
245160 ** Set both the first and last page-numbers to 0 to indicate that the
245162 pSeg->pSeg->pgnoLast = 0;
245163 pSeg->pSeg->pgnoFirst = 0;
245169 u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
245237 Fts5Iter *pIter = 0; /* Iterator to read input data */
245238 int nRem = pnRem ? *pnRem : 0; /* Output leaf pages left to write */
245246 int bTermWritten = 0; /* True if current term already output */
245251 memset(&writer, 0, sizeof(Fts5SegWriter));
245252 memset(&term, 0, sizeof(Fts5Buffer));
245255 assert( pLvlOut->nSeg>0 );
245261 writer.iBtPage = 0;
245271 fts5StructureExtendLevel(&p->rc, pStruct, iLvl+1, 1, 0);
245289 if( pStruct->nOriginCntr>0 ){
245290 pSeg->iOrigin1 = pLvl->aSeg[0].iOrigin1;
245296 assert( iLvl>=0 );
245297 for(fts5MultiIterNew(p, pStruct, flags, 0, 0, 0, iLvl, nInput, &pIter);
245298 fts5MultiIterEof(p, pIter)==0;
245299 fts5MultiIterNext(p, pIter, 0, 0)
245312 bTermWritten =0;
245316 if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue;
245318 if( p->rc==SQLITE_OK && bTermWritten==0 ){
245330 fts5BufferAppendVarint(&p->rc, &writer.writer.buf, 0);
245331 if( pSegIter->nPos>0 ){
245332 fts5BufferAppendVarint(&p->rc, &writer.writer.buf, 0);
245347 assert( pIter!=0 || p->rc!=SQLITE_OK );
245352 assert( pSeg->nEntry==0 );
245353 for(i=0; i<nInput; i++){
245366 pLvl->nMerge = 0;
245367 if( pSeg->pgnoLast==0 ){
245372 assert( pSeg->pgnoLast>0 );
245384 ** configuration option is set to 0, then this function always returns -1.
245393 if( pConfig->bContentlessDelete && pConfig->nDeleteMerge>0 ){
245395 int nBest = 0;
245397 for(ii=0; ii<pStruct->nLevel; ii++){
245399 i64 nEntry = 0;
245400 i64 nTomb = 0;
245402 for(iSeg=0; iSeg<pLvl->nSeg; iSeg++){
245406 assert_nc( nEntry>0 || pLvl->nSeg==0 );
245407 if( nEntry>0 ){
245431 int bRet = 0;
245433 while( nRem>0 && p->rc==SQLITE_OK ){
245435 int iBestLvl = 0; /* Level offering the most input segments */
245436 int nBest = 0; /* Number of input segments on best level */
245440 assert( pStruct->nLevel>0 );
245441 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
245459 if( iBestLvl<0 ) break;
245462 if( p->rc==SQLITE_OK && pStruct->aLevel[iBestLvl].nMerge==0 ){
245473 ** A total of nLeaf leaf pages of data has just been flushed to a level-0
245485 if( p->rc==SQLITE_OK && p->pConfig->nAutomerge>0 && ALWAYS((*ppStruct)!=0) ){
245507 if( pStruct && pStruct->nLevel>0 ){
245508 int iLvl = 0;
245510 fts5IndexMergeLevel(p, &pStruct, iLvl, 0);
245568 if( p->pDeleteFromIdx==0 ){
245601 Fts5Data *pLeaf = 0;
245607 int iNext = 0;
245608 u8 *aPg = 0;
245611 if( pLeaf==0 ) break;
245614 iNext = fts5GetU16(&aPg[0]);
245615 if( iNext!=0 ){
245616 *pbLastInDoclist = 0;
245618 if( iNext==0 && pLeaf->szLeaf!=pLeaf->nn ){
245622 if( iNext==0 ){
245625 const u8 aEmpty[] = {0x00, 0x00, 0x00, 0x04};
245626 assert_nc( bDetailNone==0 || pLeaf->nn==4 );
245627 if( bDetailNone==0 ) fts5DataWrite(p, iRowid, aEmpty, sizeof(aEmpty));
245629 pLeaf = 0;
245639 int nIdx = 0;
245640 u8 *aIdx = 0;
245642 /* Unless the current page footer is 0 bytes in size (in which case
245647 int iFirst = 0;
245649 int i2 = 0;
245657 if( aIdx==0 ) break;
245671 if( fts5GetU16(&aPg[0]) ) fts5PutU16(&aPg[0], 4);
245672 if( nIdx>0 ){
245679 assert( nPg>4 || fts5GetU16(aPg)==0 );
245701 u64 iDelta = 0;
245702 int iNextOff = 0;
245703 int iOff = 0;
245704 int nIdx = 0;
245705 u8 *aIdx = 0;
245706 int bLastInDoclist = 0;
245707 int iIdx = 0;
245708 int iStart = 0;
245709 int iDelKeyOff = 0; /* Offset of deleted key, if any */
245751 iStart = fts5GetU16(&aPg[0]);
245759 if( aPg[iSOP]==0x00 ) iSOP++;
245760 if( aPg[iSOP]==0x00 ) iSOP++;
245766 if( iNextOff<pSeg->iEndofDoclist && aPg[iNextOff]==0x00 ) iNextOff++;
245767 if( iNextOff<pSeg->iEndofDoclist && aPg[iNextOff]==0x00 ) iNextOff++;
245770 int nPos = 0;
245796 if( pSeg->bDel==0 ){
245802 int iKeyOff = 0;
245803 for(iIdx=0; iIdx<nIdx; /* no-op */){
245804 u32 iVal = 0;
245815 ** of the header to 0. */
245816 if( fts5GetU16(&aPg[0])==iStart && (bLastInDoclist || iNextOff==iPgIdx) ){
245817 fts5PutU16(&aPg[0], 0);
245823 aPg[iOff++] = 0x01;
245824 }else if( bLastInDoclist==0 ){
245826 u64 iNextDelta = 0;
245836 int iKey = 0;
245837 int iKeyOff = 0;
245841 for(iIdx=0; iIdx<nIdx; iKey++){
245842 u32 iVal = 0;
245858 int nPrefix = 0;
245859 int nSuffix = 0;
245860 int nPrefix2 = 0;
245861 int nSuffix2 = 0;
245903 if( bEmpty==0 ) break;
245912 int iTermIdx = 0;
245913 int iTermOff = 0;
245916 u32 iVal = 0;
245928 if( nTermIdx==0 ){
245949 int iPrevKeyOut = 0;
245950 int iKeyIn = 0;
245957 for(iIdx=0; iIdx<nIdx; /* no-op */){
245958 u32 iVal = 0;
245962 int iKeyOut = (iKeyIn - (iKeyIn>iOff ? nShift : 0));
245968 if( iPgIdx==nPg && nIdx>0 && pSeg->iLeafPgno!=1 ){
245972 assert_nc( nPg>4 || fts5GetU16(aPg)==0 );
245991 Fts5Iter *pIter = 0; /* Used to find term instance */
245993 fts5MultiIterNew(p, pStruct, f, 0, (const u8*)zTerm, nTerm, -1, 0, &pIter);
245994 if( fts5MultiIterEof(p, pIter)==0 ){
246001 && fts5MultiIterEof(p, pIter)==0
246014 ** Flush the contents of in-memory hash table iHash to a new level-0
246024 int pgnoLast = 0; /* Last leaf page number in segment */
246027 ** for the new level-0 segment. */
246031 if( sqlite3Fts5HashIsEmpty(pHash)==0 ){
246055 p->rc = sqlite3Fts5HashScanInit(pHash, 0, 0);
246057 while( p->rc==SQLITE_OK && 0==sqlite3Fts5HashScanEof(pHash) ){
246065 if( bSecureDelete==0 ){
246068 assert( writer.bFirstRowidInPage==0 );
246076 i64 iRowid = 0;
246077 i64 iPrev = 0;
246078 int iOff = 0;
246084 u64 iDelta = 0;
246093 if( iOff<nDoclist && pDoclist[iOff]==0x00 ){
246096 if( iOff<nDoclist && pDoclist[iOff]==0x00 ){
246098 nDoclist = 0;
246103 }else if( (pDoclist[iOff] & 0x01) ){
246105 if( p->rc!=SQLITE_OK || pDoclist[iOff]==0x01 ){
246112 if( p->rc==SQLITE_OK && bTermWritten==0 ){
246115 assert( p->rc!=SQLITE_OK || writer.bFirstRowidInPage==0 );
246119 fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
246121 writer.bFirstRowidInPage = 0;
246132 if( iOff<nDoclist && pDoclist[iOff]==0 ){
246133 pBuf->p[pBuf->n++] = 0;
246135 if( iOff<nDoclist && pDoclist[iOff]==0 ){
246136 pBuf->p[pBuf->n++] = 0;
246144 int bDel = 0;
246145 int nPos = 0;
246163 int iPos = 0;
246166 int n = 0;
246172 assert( n>0 );
246187 /* pBuf->p[pBuf->n++] = '\0'; */
246193 assert( p->rc!=SQLITE_OK || bSecureDelete || pgnoLast>0 );
246194 if( pgnoLast>0 ){
246197 if( pStruct->nLevel==0 ){
246200 fts5StructureExtendLevel(&p->rc, pStruct, 0, 1, 0);
246202 pSeg = &pStruct->aLevel[0].aSeg[ pStruct->aLevel[0].nSeg++ ];
246206 if( pStruct->nOriginCntr>0 ){
246214 fts5StructurePromote(p, 0, pStruct);
246239 p->nPendingData = 0;
246240 p->nPendingRow = 0;
246241 p->nContentlessDelete = 0;
246252 Fts5Structure *pNew = 0;
246268 if( nSeg==0 ) return 0;
246269 for(i=0; i<pStruct->nLevel; i++){
246272 if( nThis>0 && (nThis==nSeg || (nThis==nSeg-1 && nMerge==nThis)) ){
246273 if( nSeg==1 && nThis==1 && pStruct->aLevel[i].aSeg[0].nPgTombstone==0 ){
246274 return 0;
246296 int iSegOut = 0;
246298 ** the new Fts5Level object so that pLvl->aSeg[0] is the oldest
246300 for(iLvl=pStruct->nLevel-1; iLvl>=0; iLvl--){
246301 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
246309 pNew = 0;
246318 Fts5Structure *pNew = 0;
246322 assert( p->rc!=SQLITE_OK || p->nContentlessDelete==0 );
246324 assert( p->rc!=SQLITE_OK || pStruct!=0 );
246332 assert( pNew==0 || pNew->nSegment>0 );
246335 for(iLvl=0; pNew->aLevel[iLvl].nSeg==0; iLvl++){}
246336 while( p->rc==SQLITE_OK && pNew->aLevel[iLvl].nSeg>0 ){
246353 Fts5Structure *pStruct = 0;
246360 if( nMerge<0 ){
246395 assert( nData>0 );
246396 if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nByte) ){
246400 memset(&pBuf->p[pBuf->n], 0, FTS5_DATA_ZERO_PADDING);
246408 assert( pIter->aPoslist || (p==0 && pIter->aPoslist==0) );
246410 pIter->aPoslist = 0;
246418 if( p[0] & 0x80 ){
246423 pIter->nPoslist = ((int)(p[0])) >> 1;
246429 pIter->aPoslist = 0;
246438 memset(pIter, 0, sizeof(*pIter));
246439 if( pBuf->n>0 ){
246446 #if 0
246458 assert( pBuf->n!=0 || (*piLastRowid)==0 );
246465 assert( (pBuf)->n!=0 || (iLastRowid)==0 ); \
246500 int i1 = 0;
246501 int i2 = 0;
246502 i64 iRowid1 = 0;
246503 i64 iRowid2 = 0;
246504 i64 iOut = 0;
246505 Fts5Buffer *p2 = &aBuf[0];
246509 memset(&out, 0, sizeof(out));
246516 while( i1>=0 || i2>=0 ){
246517 if( i1>=0 && (i2<0 || iRowid1<iRowid2) ){
246518 assert( iOut==0 || iRowid1>iOut );
246523 assert( iOut==0 || iRowid2>iOut );
246526 if( i1>=0 && iRowid1==iRowid2 ){
246564 if( p->iPos>=0 ){
246589 PrefixMerger *pHead = 0;
246591 int nOut = 0;
246592 Fts5Buffer out = {0, 0, 0};
246593 Fts5Buffer tmp = {0, 0, 0};
246594 i64 iLastRowid = 0;
246599 assert( nBuf+1<=(int)(sizeof(aMerger)/sizeof(aMerger[0])) );
246600 memset(aMerger, 0, sizeof(PrefixMerger)*(nBuf+1));
246603 for(i=0; i<nBuf; i++){
246608 if( nOut==0 ) return;
246630 i64 iPrev = 0;
246632 int nMerge = 0;
246634 PrefixMerger *pThis = 0;
246635 int nTail = 0;
246637 pHead = 0;
246640 pSave->iOff = 0;
246641 pSave->iPos = 0;
246650 if( pHead==0 || pHead->pNext==0 ){
246693 if( nTail>0 ){
246698 for(i=0; i<nBuf+1; i++){
246719 memset(&out.p[out.n], 0, FTS5_DATA_ZERO_PADDING);
246758 i64 iLastRowid = 0;
246759 Fts5Iter *p1 = 0; /* Iterator used to gather data from index */
246764 memset(&doclist, 0, sizeof(doclist));
246771 if( iIdx!=0 ){
246772 int dummy = 0;
246774 pToken[0] = FTS5_MAIN_PREFIX;
246775 fts5MultiIterNew(p, pStruct, f2, pColset, pToken, nToken, -1, 0, &p1);
246778 fts5MultiIterEof(p, p1)==0;
246791 pToken[0] = FTS5_MAIN_PREFIX + iIdx;
246792 fts5MultiIterNew(p, pStruct, flags, pColset, pToken, nToken, -1, 0, &p1);
246796 fts5MultiIterEof(p, p1)==0;
246804 assert_nc( memcmp(pToken, pTerm, MIN(nToken, nTerm))<=0 );
246809 if( p1->base.nData==0 ) continue;
246810 if( p1->base.iRowid<=iLastRowid && doclist.n>0 ){
246811 for(i=0; p->rc==SQLITE_OK && doclist.n; i++){
246816 if( aBuf[iStore].n==0 ){
246829 iLastRowid = 0;
246836 assert( (nBuf%nMerge)==0 );
246837 for(i=0; i<nBuf; i+=nMerge){
246871 if( p->pHash==0 ){
246877 || (iRowid==p->iWriteRowid && p->bDelete==0)
246885 if( bDelete==0 ){
246924 memset(&s, 0, sizeof(Fts5Structure));
246928 fts5DataWrite(p, FTS5_AVERAGES_ROWID, (const u8*)"", 0);
246956 pConfig, "data", "id INTEGER PRIMARY KEY, block BLOB", 0, pzErr
246973 *pp = 0;
246984 assert( p->pReader==0 );
247004 ** buffer, or 0 if there are less than nChar characters in total.
247011 int n = 0;
247013 for(i=0; i<nChar; i++){
247014 if( n>=nByte ) return 0; /* Input contains fewer than nChar chars */
247015 if( (unsigned char)p[n++]>=0xc0 ){
247016 if( n>=nByte ) return 0;
247017 while( (p[n] & 0xc0)==0x80 ){
247021 return 0;
247034 int nChar = 0;
247035 int i = 0;
247037 if( (unsigned char)pIn[i++]>=0xc0 ){
247038 while( i<nIn && (pIn[i] & 0xc0)==0x80 ) i++;
247066 assert( (iCol<0)==p->bDelete );
247073 for(i=0; i<pConfig->nPrefix && rc==SQLITE_OK; i++){
247100 && 0==memcmp(pBuf->p, pToken, nToken)
247101 && (pBuf->n==nToken || pBuf->p[nToken]==0x00)
247110 pSeg->pLeaf = 0;
247157 if( pIn==0 || pIn->nIter==pIn->nIterAlloc ){
247162 if( pNew==0 ){
247165 if( pIn==0 ) memset(pNew, 0, nByte);
247176 assert( pRet==0 || pRet->nIter<=pRet->nIterAlloc );
247187 for(ii=0; ii<pSet->nIter; ii++){
247213 if( aNew==0 ){
247231 ** (pIter->pTokenDataIter!=0). This function sets the iterator output
247237 int nHit = 0;
247239 int iMin = 0;
247243 pIter->base.nData = 0;
247244 pIter->base.pData = 0;
247246 for(ii=0; ii<pT->nIter; ii++){
247248 if( p->base.bEof==0 ){
247249 if( nHit==0 || p->base.iRowid<iRowid ){
247261 if( nHit==0 ){
247265 pIter->base.bEof = 0;
247272 int nReader = 0;
247273 int nByte = 0;
247274 i64 iPrev = 0;
247277 if( pT->aPoslistReader==0 ){
247282 if( pT->aPoslistReader==0 ) return;
247287 for(ii=0; ii<pT->nIter; ii++){
247309 if( aNew==0 ){
247317 pIter->poslist.n = 0;
247323 iMin = 0;
247324 for(ii=0; ii<nReader; ii++){
247326 if( pReader->bEof==0 ){
247356 ** (pIter->pTokenDataIter!=0). This function advances the iterator. If
247366 for(ii=0; ii<pT->nIter; ii++){
247368 if( p->base.bEof==0
247372 while( bFrom && p->base.bEof==0
247376 fts5MultiIterNext(pIndex, p, 0, 0);
247391 if( pIter && pIter->aSeg[0].pLeaf==0 ){
247392 fts5BufferSet(&pIter->pIndex->rc, &pIter->aSeg[0].term, pTerm->n, pTerm->p);
247406 Fts5Iter *pRet = 0;
247407 Fts5TokenDataIter *pSet = 0;
247408 Fts5Structure *pStruct = 0;
247411 Fts5Buffer bSeek = {0, 0, 0};
247412 Fts5Buffer *pSmall = 0;
247418 Fts5Iter *pPrev = pSet ? pSet->apIter[pSet->nIter-1] : 0;
247419 Fts5Iter *pNew = 0;
247420 Fts5SegIter *pNewIter = 0;
247421 Fts5SegIter *pPrevIter = 0;
247428 fts5BufferAppendBlob(&p->rc, &bSeek, 1, (const u8*)"\0");
247437 pNewIter = &pNew->aSeg[0];
247438 pPrevIter = (pPrev ? &pPrev->aSeg[0] : 0);
247439 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
247440 for(iSeg=pStruct->aLevel[iLvl].nSeg-1; iSeg>=0; iSeg--){
247442 int bDone = 0;
247447 memset(pPrevIter, 0, sizeof(Fts5SegIter));
247455 if( bDone==0 ){
247483 pSmall = 0;
247484 for(ii=0; ii<pNew->nSeg; ii++){
247486 if( 0==fts5IsTokendataPrefix(&pII->term, pToken, nToken) ){
247489 if( pII->pLeaf && (!pSmall || fts5BufferCompare(pSmall, &pII->term)>0) ){
247497 if( pSmall==0 ){
247508 for(ii=0; ii<pSet->nIter; ii++){
247511 for(iSeg=0; iSeg<pIter->nSeg; iSeg++){
247519 pRet = fts5MultiIterAlloc(p, 0);
247550 Fts5Iter *pRet = 0;
247551 Fts5Buffer buf = {0, 0, 0};
247554 assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
247556 if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
247557 int iIdx = 0; /* Index to search */
247558 int iPrefixIdx = 0; /* +1 prefix index */
247560 if( nToken>0 ) memcpy(&buf.p[1], pToken, nToken);
247563 bTokendata = 0;
247577 if( pConfig->bPrefixIndex==0 || (flags & FTS5INDEX_QUERY_TEST_NOIDX) ){
247591 if( bTokendata && iIdx==0 ){
247592 buf.p[0] = '0';
247597 buf.p[0] = (u8)(FTS5_MAIN_PREFIX + iIdx);
247600 pColset, buf.p, nToken+1, -1, 0, &pRet
247606 int bDesc = (flags & FTS5INDEX_QUERY_DESC)!=0;
247608 if( pRet==0 ){
247611 assert( pRet->pColset==0 );
247622 pRet = 0;
247642 fts5TokendataIterNext(pIter, 0, 0);
247644 fts5MultiIterNext(pIter->pIndex, pIter, 0, 0);
247658 fts5MultiIterNext(p, pIter, 0, 0);
247661 if( pSeg->pLeaf && pSeg->term.p[0]!=FTS5_MAIN_PREFIX ){
247663 pSeg->pLeaf = 0;
247694 return (z ? &z[1] : 0);
247701 ** iterator (pIter->pTokenDataIter!=0).
247715 int i1 = 0;
247717 int iTest = 0;
247728 if( aMap[iTest].iPos<0 ){
247742 *ppOut = (const char*)pMap->aSeg[0].term.p+1;
247743 *pnOut = pMap->aSeg[0].term.n-1;
247756 pIter->pTokenDataIter->nMap = 0;
247780 for(ii=0; ii<pT->nIter; ii++){
247781 Fts5Buffer *pTerm = &pT->apIter[ii]->aSeg[0].term;
247782 if( nToken==pTerm->n-1 && memcmp(pToken, pTerm->p+1, nToken)==0 ) break;
247813 *pnRow = 0;
247814 memset(anSize, 0, sizeof(i64) * nCol);
247817 int i = 0;
247820 for(iCol=0; i<pData->nn && iCol<nCol; iCol++){
247858 sqlite3_blob *pBlob = 0;
247867 sqlite3_blob_write(pBlob, aCookie, 4, 0);
247921 if( szKey==4 && iRowid>0xFFFFFFFF ) return 2;
247922 if( iRowid==0 ){
247923 pPg->p[1] = 0x01;
247924 return 0;
247927 if( bForce==0 && nElem>=(nSlot/2) ){
247936 if( nCollide--==0 ) return 0;
247943 if( nCollide--==0 ) return 0;
247948 return 0;
247957 ** Return 0 if the hash is successfully rebuilt into the nOut pages.
247973 int res = 0;
247976 for(ii=0; ii<nOut; ii++){
247977 apOut[ii]->p[0] = szKey;
247978 fts5PutU32(&apOut[ii]->p[4], 0);
247982 for(ii=0; res==0 && ii<pSeg->nPgTombstone; ii++){
247983 Fts5Data *pData = 0; /* Page ii of the current hash table */
247984 Fts5Data *pFree = 0; /* Free this at the end of the loop */
247996 for(iIn=0; iIn<nSlotIn; iIn++){
247997 u64 iVal = 0;
248008 /* If iVal is not 0 at this point, insert it into the new hash table */
248011 res = fts5IndexTombstoneAddToPage(pPg, 0, nOut, iVal);
248016 /* If this is page 0 of the old hash, copy the rowid-0-flag from the
248018 if( ii==0 ){
248019 apOut[0]->p[1] = pData->p[1];
248040 ** both output parameters set to 0 before returning.
248053 int nSlot = 0; /* Number of slots in each output page */
248054 int nOut = 0;
248073 if( pSeg->nPgTombstone==0 ){
248080 assert( pData1 && iPg1==0 );
248083 if( nSlot>nSlotPerPage ) nOut = 0;
248085 if( nOut==0 ){
248093 int res = 0;
248094 int ii = 0;
248095 int szPage = 0;
248096 Fts5Data **apOut = 0;
248102 for(ii=0; ii<nOut; ii++){
248117 if( res==0 ){
248120 apOut = 0;
248121 nOut = 0;
248146 Fts5Data *pPg = 0;
248148 int szKey = 0;
248149 int nHash = 0;
248150 Fts5Data **apHash = 0;
248154 if( pSeg->nPgTombstone>0 ){
248157 if( pPg==0 ){
248162 if( 0==fts5IndexTombstoneAddToPage(pPg, 0, pSeg->nPgTombstone, iRowid) ){
248171 if( iRowid>0xFFFFFFFF ) szKey = 8;
248175 assert( p->rc==SQLITE_OK || (nHash==0 && apHash==0) );
248180 int ii = 0;
248182 for(ii=0; ii<nHash; ii++){
248203 int bFound = 0; /* True after pSeg->nEntryTombstone incr. */
248205 for(iLvl=pStruct->nLevel-1; iLvl>=0; iLvl--){
248207 for(iSeg=pStruct->aLevel[iLvl].nSeg-1; iSeg>=0; iSeg--){
248210 if( bFound==0 ){
248244 if( iIdx>=0 ) ret += (ret<<3) + (FTS5_MAIN_PREFIX + iIdx);
248245 for(i=0; i<nTerm; i++) ret += (ret<<3) + pTerm[i];
248263 Fts5DlidxIter *pDlidx = 0;
248267 for(pDlidx=fts5DlidxIterInit(p, 0, iSegid, iLeaf);
248268 fts5DlidxIterEof(p, pDlidx)==0;
248277 pDlidx = 0;
248280 fts5DlidxIterEof(p, pDlidx)==0;
248289 pDlidx = 0;
248304 Fts5IndexIter *pIter = 0;
248306 p, z, n, (flags | FTS5INDEX_QUERY_NOTOKENDATA), 0, &pIter
248309 while( rc==SQLITE_OK && ALWAYS(pIter!=0) && 0==sqlite3Fts5IterEof(pIter) ){
248313 cksum ^= sqlite3Fts5IndexEntryCksum(rowid, 0, 0, iIdx, z, n);
248317 sReader.bEof==0;
248337 ** encoded codepoints. If so, return 0. Otherwise, if the buffer does not
248341 int i = 0;
248342 assert_nc( n>0 );
248344 if( (z[i] & 0x80)==0x00 ){
248347 if( (z[i] & 0xE0)==0xC0 ){
248348 if( i+1>=n || (z[i+1] & 0xC0)!=0x80 ) return 1;
248351 if( (z[i] & 0xF0)==0xE0 ){
248352 if( i+2>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
248355 if( (z[i] & 0xF8)==0xF0 ){
248356 if( i+3>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
248357 if( (z[i+2] & 0xC0)!=0x80 ) return 1;
248364 return 0;
248379 if( pPrev->n==0 ){
248386 int iIdx = (pPrev->p[0] - FTS5_MAIN_PREFIX);
248387 int flags = (iIdx==0 ? 0 : FTS5INDEX_QUERY_PREFIX);
248388 u64 ck1 = 0;
248389 u64 ck2 = 0;
248413 if( p->nPendingData==0 && 0==fts5TestUtf8(zTerm, nTerm) ){
248414 if( iIdx>0 && rc==SQLITE_OK ){
248416 ck2 = 0;
248420 if( iIdx>0 && rc==SQLITE_OK ){
248422 ck2 = 0;
248467 if( i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf) ) p->rc = FTS5_CORRUPT;
248474 i64 iTermOff = 0;
248477 Fts5Buffer buf1 = {0,0,0};
248478 Fts5Buffer buf2 = {0,0,0};
248513 if( res<=0 ) p->rc = FTS5_CORRUPT;
248529 sqlite3_stmt *pStmt = 0;
248534 if( pSeg->pgnoFirst==0 ) return;
248557 if( pLeaf==0 ) break;
248565 if( nIdxTerm==0
248590 if( res==0 ) res = nTerm - nIdxTerm;
248591 if( res<0 ) p->rc = FTS5_CORRUPT;
248608 Fts5DlidxIter *pDlidx = 0; /* For iterating through doclist index */
248611 int iPg = 0;
248614 for(pDlidx=fts5DlidxIterInit(p, 0, iSegid, iIdxLeaf);
248615 fts5DlidxIterEof(p, pDlidx)==0;
248624 if( fts5LeafFirstRowidOff(pLeaf)!=0 ) p->rc = FTS5_CORRUPT;
248640 }else if( bSecureDelete==0 || iRowidOff>0 ){
248643 if( iRowid<iDlRowid || (bSecureDelete==0 && iRowid!=iDlRowid) ){
248666 #if 0
248686 u64 cksum2 = 0; /* Checksum based on contents of indexes */
248687 Fts5Buffer poslist = {0,0,0}; /* Buffer used to hold a poslist */
248694 u64 cksum3 = 0; /* Checksum based on contents of indexes */
248695 Fts5Buffer term = {0,0,0}; /* Buffer used to hold most recent term */
248701 if( pStruct==0 ){
248707 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
248708 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
248727 for(fts5MultiIterNew(p, pStruct, flags, 0, 0, 0, -1, 0, &pIter);
248728 fts5MultiIterEof(p, pIter)==0;
248729 fts5MultiIterNext(p, pIter, 0, 0)
248732 i64 iPos = 0; /* Position read from poslist */
248733 int iOff = 0; /* Offset within poslist */
248742 if( 0==fts5MultiIterIsEmpty(p, pIter) ){
248743 cksum2 ^= sqlite3Fts5IndexEntryCksum(iRowid, 0, 0, -1, z, n);
248746 poslist.n = 0;
248747 fts5SegiterPoslist(p, &pIter->aSeg[pIter->aFirst[1].iFirst], 0, &poslist);
248748 fts5BufferAppendBlob(&p->rc, &poslist, 4, (const u8*)"\0\0\0\0");
248749 while( 0==sqlite3Fts5PoslistNext64(poslist.p, poslist.n, &iOff, &iPos) ){
248756 fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3);
248794 *pbDlidx = (int)(iRowid & 0x0001);
248800 *pbTombstone = (int)(iRowid & 0x0001);
248809 if( iSegid==0 ){
248834 for(iLvl=0; iLvl<p->nLevel; iLvl++){
248839 for(iSeg=0; iSeg<pLvl->nSeg; iSeg++){
248844 if( pSeg->iOrigin1>0 ){
248870 Fts5Structure *p = 0; /* Decoded structure object */
248872 rc = fts5StructureDecode(pBlob, nBlob, 0, &p);
248896 int i = 0;
248912 ** after either the input buffer is exhausted or a 0 value is read.
248917 int iOff = 0;
248937 i64 iDocid = 0;
248938 int iOff = 0;
248940 if( n>0 ){
248981 int i = 0;
248982 i64 iRowid = 0;
248990 if( i<nData && pData[i]==0x00 ){
248992 if( i<nData && pData[i]==0x00 ){
249010 for(ii=0; ii<pTerm->n; ii++){
249011 if( pTerm->p[ii]==0x00 ){
249013 pBuf->p[pBuf->n++] = '0';
249018 pBuf->p[pBuf->n] = 0x00;
249036 u8 *a = 0;
249039 sqlite3_int64 nSpace = 0;
249040 int eDetailNone = (sqlite3_user_data(pCtx)!=0);
249044 memset(&s, 0, sizeof(Fts5Buffer));
249045 iRowid = sqlite3_value_int64(apVal[0]);
249048 ** copy is followed by FTS5_DATA_ZERO_PADDING 0x00 bytes, which prevents
249054 if( a==0 ) goto decode_out;
249055 if( n>0 ) memcpy(a, aBlob, n);
249067 memset(&lvl, 0, sizeof(Fts5DlidxLvl));
249071 for(fts5DlidxLvlNext(&lvl); lvl.bEof==0; fts5DlidxLvlNext(&lvl)){
249078 int szKey = (aBlob[0]==4 || aBlob[0]==8) ? aBlob[0] : 8;
249083 sqlite3Fts5BufferAppendPrintf(&rc, &s, " 0");
249085 for(ii=0; ii<nSlot; ii++){
249086 u64 iVal = 0;
249094 if( iVal!=0 ){
249098 }else if( iSegid==0 ){
249109 int nKeep = 0;
249112 memset(&term, 0, sizeof(Fts5Buffer));
249158 int iPgidxPrev = 0; /* Previous value read from pgidx */
249159 int iTermOff = 0;
249160 int iRowidOff = 0;
249164 memset(&term, 0, sizeof(Fts5Buffer));
249170 iRowidOff = fts5GetU16(&a[0]);
249181 if( iRowidOff!=0 ){
249183 }else if( iTermOff!=0 ){
249223 if( bFirst==0 ){
249268 if( nArg==0 ){
249271 zArg = (const char*)sqlite3_value_text(apVal[0]);
249272 if( 0==sqlite3_stricmp(zArg, "segment") ){
249320 Fts5StructVtab *pNew = 0;
249350 pIdxInfo->idxNum = 0;
249351 for(i=0, p=pIdxInfo->aConstraint; i<pIdxInfo->nConstraint; i++, p++){
249352 if( p->usable==0 ) continue;
249377 Fts5StructVcsr *pNew = 0;
249408 pCsr->iSeg = 0;
249412 pCsr->pStruct = 0;
249423 return pCsr->pStruct==0;
249449 case 0: /* level */
249489 ** idxNum==0 means show all subprograms
249500 const u8 *aBlob = 0;
249501 int nBlob = 0;
249505 pCsr->pStruct = 0;
249507 nBlob = sqlite3_value_bytes(argv[0]);
249508 aBlob = (const u8*)sqlite3_value_blob(argv[0]);
249509 rc = fts5StructureDecode(aBlob, nBlob, 0, &pCsr->pStruct);
249511 pCsr->iLevel = 0;
249512 pCsr->iRowid = 0;
249533 db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0
249539 SQLITE_UTF8, (void*)db, fts5DecodeFunction, 0, 0
249545 db, "fts5_rowid", -1, SQLITE_UTF8, 0, fts5RowidFunction, 0, 0
249551 0, /* iVersion */
249552 0, /* xCreate */
249556 0, /* xDestroy */
249564 0, /* xUpdate */
249565 0, /* xBegin */
249566 0, /* xSync */
249567 0, /* xCommit */
249568 0, /* xRollback */
249569 0, /* xFindFunction */
249570 0, /* xRename */
249571 0, /* xSavepoint */
249572 0, /* xRelease */
249573 0, /* xRollbackTo */
249574 0, /* xShadowName */
249575 0 /* xIntegrity */
249577 rc = sqlite3_create_module(db, "fts5_structure", &fts5structure_module, 0);
249588 assert( p->pStruct==0 || p->iStructVersion!=0 );
249663 int eState; /* 0==closed, 1==open, 2==synced */
249664 int iSavepoint; /* Number of open savepoints (0 -> none) */
249803 #define FTS5_BI_MATCH 0x0001 /* <tbl> MATCH ? */
249804 #define FTS5_BI_RANK 0x0002 /* rank MATCH ? */
249805 #define FTS5_BI_ROWID_EQ 0x0004 /* rowid == ? */
249806 #define FTS5_BI_ROWID_LE 0x0008 /* rowid <= ? */
249807 #define FTS5_BI_ROWID_GE 0x0010 /* rowid >= ? */
249809 #define FTS5_BI_ORDER_RANK 0x0020
249810 #define FTS5_BI_ORDER_ROWID 0x0040
249811 #define FTS5_BI_ORDER_DESC 0x0080
249816 #define FTS5CSR_EOF 0x01
249817 #define FTS5CSR_REQUIRE_CONTENT 0x02
249818 #define FTS5CSR_REQUIRE_DOCSIZE 0x04
249819 #define FTS5CSR_REQUIRE_INST 0x08
249820 #define FTS5CSR_FREE_ZRANK 0x10
249821 #define FTS5CSR_REQUIRE_RESEEK 0x20
249822 #define FTS5CSR_REQUIRE_POSLIST 0x40
249825 #define BitFlagTest(x,y) (((x) & (y))!=0)
249853 assert( p->ts.eState==0 );
249865 p->ts.eState = 0;
249869 assert( p->ts.eState==1 || p->ts.eState==2 || p->ts.eState==0 );
249870 p->ts.eState = 0;
249875 assert( iSavepoint>=0 );
249882 assert( iSavepoint>=0 );
249947 ** argv[0] -> module name ("fts5")
249964 Fts5Config *pConfig = 0; /* Results of parsing argc/argv */
249965 Fts5FullTable *pTab = 0; /* New virtual table object */
249971 assert( (rc==SQLITE_OK && *pzErr==0) || pConfig==0 );
249997 assert( pConfig->pzErrmsg==0 );
250001 pConfig->pzErrmsg = 0;
250013 pTab = 0;
250015 fts5CheckTransactionState(pTab, FTS5_BEGIN, 0);
250033 return fts5InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
250086 return 0;
250154 int idxFlags = 0; /* Parameter passed through to xFilter() */
250158 int iIdxStr = 0;
250159 int iCons = 0;
250161 int bSeenEq = 0;
250162 int bSeenGt = 0;
250163 int bSeenLt = 0;
250164 int bSeenMatch = 0;
250165 int bSeenRank = 0;
250182 if( idxStr==0 ) return SQLITE_NOMEM;
250186 for(i=0; i<pInfo->nConstraint; i++){
250193 if( p->usable==0 || iCol<0 ){
250198 idxStr[iIdxStr] = 0;
250205 }else if( iCol>=0 ){
250210 assert( idxStr[iIdxStr]=='\0' );
250216 if( iCol>=0 && iCol<nCol && fts5UsePatternMatch(pConfig, p) ){
250222 assert( idxStr[iIdxStr]=='\0' );
250223 }else if( bSeenEq==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ && iCol<0 ){
250231 if( bSeenEq==0 ){
250232 for(i=0; i<pInfo->nConstraint; i++){
250234 if( p->iColumn<0 && p->usable ){
250251 idxStr[iIdxStr] = '\0';
250258 int iSort = pInfo->aOrderBy[0].iColumn;
250261 }else if( iSort==-1 && (!pInfo->aOrderBy[0].desc || !pConfig->bTokendata) ){
250266 if( pInfo->aOrderBy[0].desc ){
250275 if( bSeenMatch==0 ) fts5SetUniqueFlag(pInfo);
250302 Fts5Cursor *pCsr = 0; /* New cursor object */
250312 memset(pCsr, 0, (size_t)nByte);
250382 memset(&pCsr->ePlan, 0, sizeof(Fts5Cursor) - ((u8*)&pCsr->ePlan - (u8*)pCsr));
250419 int iOff = 0;
250422 pSorter->iRowid = sqlite3_column_int64(pSorter->pStmt, 0);
250426 /* nBlob==0 in detail=none mode. */
250427 if( nBlob>0 ){
250428 for(i=0; i<(pSorter->nIdx-1); i++){
250474 assert( *pbSkip==0 );
250524 int bSkip = 0;
250573 sqlite3_stmt *pRet = 0;
250580 if( zSql==0 ){
250584 SQLITE_PREPARE_PERSISTENT, &pRet, 0);
250612 if( pSorter==0 ) return SQLITE_NOMEM;
250613 memset(pSorter, 0, (size_t)nByte);
250633 assert( pTab->pSortCsr==0 );
250636 pTab->pSortCsr = 0;
250642 pCsr->pSorter = 0;
250674 while( z[0]==' ' ) z++;
250675 for(n=0; z[n] && z[n]!=' '; n++);
250677 assert( pTab->p.base.zErrMsg==0 );
250680 if( n==5 && 0==sqlite3_strnicmp("reads", z, n) ){
250683 else if( n==2 && 0==sqlite3_strnicmp("id", z, n) ){
250704 if( sqlite3_stricmp(zName, pAux->zFunc)==0 ) return pAux;
250707 /* No function of the specified name was found. Return 0. */
250708 return 0;
250716 Fts5Auxiliary *pAux = 0;
250723 sqlite3_stmt *pStmt = 0;
250725 SQLITE_PREPARE_PERSISTENT, &pStmt, 0);
250727 assert( rc==SQLITE_OK || pCsr->pRankArgStmt==0 );
250736 for(i=0; i<pCsr->nRankArg; i++){
250751 if( pAux==0 ){
250752 assert( pTab->p.base.zErrMsg==0 );
250771 char *zRank = 0;
250772 char *zRankArgs = 0;
250774 if( z==0 ){
250794 pCsr->zRankArgs = 0;
250834 sqlite3_value *pRank = 0; /* rank MATCH ? expression (or NULL) */
250835 sqlite3_value *pRowidEq = 0; /* rowid = ? expression (or NULL) */
250836 sqlite3_value *pRowidLe = 0; /* rowid <= ? expression (or NULL) */
250837 sqlite3_value *pRowidGe = 0; /* rowid >= ? expression (or NULL) */
250841 int iIdxStr = 0;
250842 Fts5Expr *pExpr = 0;
250853 memset(&pCsr->ePlan, 0, sizeof(Fts5Cursor) - ((u8*)&pCsr->ePlan-(u8*)pCsr));
250856 assert( pCsr->pStmt==0 );
250857 assert( pCsr->pExpr==0 );
250858 assert( pCsr->csrflags==0 );
250859 assert( pCsr->pRank==0 );
250860 assert( pCsr->zRank==0 );
250861 assert( pCsr->zRankArgs==0 );
250862 assert( pTab->pSortCsr==0 || nVal==0 );
250864 assert( pzErrmsg==0 || pzErrmsg==&pTab->p.base.zErrMsg );
250868 for(i=0; i<nVal; i++){
250875 if( zText==0 ) zText = "";
250876 iCol = 0;
250878 iCol = iCol*10 + (idxStr[iIdxStr]-'0');
250880 }while( idxStr[iIdxStr]>='0' && idxStr[iIdxStr]<='9' );
250882 if( zText[0]=='*' ){
250890 rc = sqlite3Fts5ExprNew(pConfig, 0, iCol, zText, &pExpr, pzErr);
250893 pExpr = 0;
250904 iCol = 0;
250906 iCol = iCol*10 + (idxStr[iIdxStr]-'0');
250908 }while( idxStr[iIdxStr]>='0' && idxStr[iIdxStr]<='9' );
250914 pExpr = 0;
250930 bOrderByRank = ((idxNum & FTS5_BI_ORDER_RANK) ? 1 : 0);
250931 pCsr->bDesc = bDesc = ((idxNum & FTS5_BI_ORDER_DESC) ? 1 : 0);
250958 assert( pRowidEq==0 && pRowidLe==0 && pRowidGe==0 && pRank==0 );
250959 assert( nVal==0 && bOrderByRank==0 && bDesc==0 );
250984 }else if( pConfig->zContent==0 ){
250997 if( pRowidEq!=0 ){
251020 return (CsrFlagTest(pCsr, FTS5CSR_EOF) ? 1 : 0);
251048 assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
251051 *pRowid = 0;
251061 *pRowid = sqlite3_column_int64(pCsr->pStmt, 0);
251079 if( pCsr->pStmt==0 ){
251083 pTab->pStorage, eStmt, &pCsr->pStmt, (bErrormsg?&pTab->p.base.zErrMsg:0)
251085 assert( rc!=SQLITE_OK || pTab->p.base.zErrMsg==0 );
251117 assert( p->p.base.zErrMsg==0 );
251144 int bError = 0;
251145 int bLoadConfig = 0;
251147 if( 0==sqlite3_stricmp("delete-all", zCmd) ){
251158 }else if( 0==sqlite3_stricmp("rebuild", zCmd) ){
251168 }else if( 0==sqlite3_stricmp("optimize", zCmd) ){
251170 }else if( 0==sqlite3_stricmp("merge", zCmd) ){
251173 }else if( 0==sqlite3_stricmp("integrity-check", zCmd) ){
251177 }else if( 0==sqlite3_stricmp("prefix-index", zCmd) ){
251180 }else if( 0==sqlite3_stricmp("flush", zCmd) ){
251194 rc = sqlite3Fts5StorageConfigValue(pTab->pStorage, zCmd, pVal, 0);
251258 int eType0; /* value_type() of apVal[0] */
251260 int bUpdateOrDelete = 0;
251265 assert( pVtab->zErrMsg==0 );
251267 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER
251268 || sqlite3_value_type(apVal[0])==SQLITE_NULL
251270 assert( pTab->p.pConfig->pzErrmsg==0 );
251271 if( pConfig->pgsz==0 ){
251281 eType0 = sqlite3_value_type(apVal[0]);
251288 && 0==sqlite3_stricmp("delete", z)
251327 && pConfig->bContentlessDelete==0
251338 i64 iDel = sqlite3_value_int64(apVal[0]); /* Rowid to delete */
251339 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0);
251356 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
251364 i64 iOld = sqlite3_value_int64(apVal[0]); /* Old rowid */
251368 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
251370 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
251376 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
251383 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
251397 pTab->pStorage, "version", 0, FTS5_CURRENT_VERSION_SECUREDELETE
251404 pTab->p.pConfig->pzErrmsg = 0;
251414 fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
251417 pTab->p.pConfig->pzErrmsg = 0;
251425 fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_BEGIN, 0);
251437 fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_COMMIT, 0);
251448 fts5CheckTransactionState(pTab, FTS5_ROLLBACK, 0);
251513 if( iCol<0 || iCol>=pTab->pConfig->nCol ){
251518 *pz = 0;
251519 *pn = 0;
251521 rc = fts5SeekCursor(pCsr, 0);
251538 int bLive = (pCsr->pSorter==0);
251540 if( iPhrase<0 || iPhrase>=sqlite3Fts5ExprPhraseCount(pCsr->pExpr) ){
251547 if( aPopulator==0 ) rc = SQLITE_NOMEM;
251548 for(i=0; i<pConfig->nCol && rc==SQLITE_OK; i++){
251569 int i1 = (iPhrase==0 ? 0 : pSorter->aIdx[iPhrase-1]);
251576 *pa = 0;
251577 *pn = 0;
251596 if( pCsr->aInstIter==0 ){
251603 int nInst = 0; /* Number instances seen so far */
251607 for(i=0; i<nIter && rc==SQLITE_OK; i++){
251620 for(i=0; i<nIter; i++){
251621 if( (aIter[i].bEof==0)
251622 && (iBest<0 || aIter[i].iPos<aIter[iBest].iPos)
251627 if( iBest<0 ) break;
251646 aInst[0] = iBest;
251649 if( aInst[1]<0 || aInst[1]>=nCol ){
251666 if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_INST)==0
251682 if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_INST)==0
251685 if( iIdx<0 || iIdx>=pCsr->nInstCount ){
251711 if( (tflags & FTS5_TOKEN_COLOCATED)==0 ){
251727 }else if( pConfig->zContent==0 ){
251729 for(i=0; i<pConfig->nCol; i++){
251730 if( pConfig->abUnindexed[i]==0 ){
251736 for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
251737 if( pConfig->abUnindexed[i]==0 ){
251740 pCsr->aColumnSize[i] = 0;
251752 if( iCol<0 ){
251754 *pnToken = 0;
251755 for(i=0; i<pConfig->nCol; i++){
251761 *pnToken = 0;
251791 if( pData==0 ){
251808 void *pRet = 0;
251817 pData->pPtr = 0;
251818 pData->xDelete = 0;
251840 *piOff = 0;
251857 assert( pIter->a || n==0 );
251858 pIter->b = (pIter->a ? &pIter->a[n] : 0);
251859 *piCol = 0;
251860 *piOff = 0;
251879 pIter->a += fts5GetVarint32(&pIter->a[0], iIncr);
251889 if( pIter->a[0]==0x01 ) break;
251910 int i1 = (iPhrase==0 ? 0 : pSorter->aIdx[iPhrase-1]);
251917 assert( pIter->a || n==0 );
251918 pIter->b = (pIter->a ? &pIter->a[n] : 0);
251919 *piCol = 0;
251926 assert( pIter->a || n==0 );
251927 pIter->b = (pIter->a ? &pIter->a[n] : 0);
251928 if( n<=0 ){
251930 }else if( pIter->a[0]==0x01 ){
251933 *piCol = 0;
251966 if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_INST)==0
251969 if( iIdx<0 || iIdx>=pCsr->nInstCount ){
252026 Fts5Cursor *pNew = 0;
252038 for(rc = fts5CursorFirst(pTab, pNew, 0);
252039 rc==SQLITE_OK && CsrFlagTest(pNew, FTS5CSR_EOF)==0;
252061 assert( pCsr->pAux==0 );
252064 pCsr->pAux = 0;
252087 iCsrId = sqlite3_value_int64(argv[0]);
252090 if( pCsr==0 || pCsr->ePlan==0 ){
252113 return 0;
252127 ** for phrase 0. The second (same disclaimer) contains the size of position
252137 memset(&val, 0, sizeof(Fts5Buffer));
252142 for(i=0; i<(nPhrase-1); i++){
252149 for(i=0; i<nPhrase; i++){
252160 for(i=0; rc==SQLITE_OK && i<(nPhrase-1); i++){
252168 for(i=0; rc==SQLITE_OK && i<nPhrase; i++){
252198 assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
252231 pConfig->pzErrmsg = 0;
252265 /* No function of the specified name was found. Return 0. */
252266 return 0;
252333 pTab->p.pConfig->pgsz = 0;
252353 sqlite3_int64 nName; /* Size of zName in bytes, including \0 */
252360 memset(pAux, 0, (size_t)nByte);
252390 sqlite3_int64 nName; /* Size of zName and its \0 terminator */
252398 memset(pNew, 0, (size_t)nByte);
252406 if( pNew->pNext==0 ){
252420 Fts5TokenizerModule *pMod = 0;
252422 if( zName==0 ){
252426 if( sqlite3_stricmp(zName, pMod->zName)==0 ) break;
252451 memset(pTokenizer, 0, sizeof(fts5_tokenizer));
252468 pMod = fts5LocateTokenizer(pGlobal, nArg==0 ? 0 : azArg[0]);
252469 if( pMod==0 ){
252470 assert( nArg>0 );
252472 if( pzErr ) *pzErr = sqlite3_mprintf("no such tokenizer: %s", azArg[0]);
252475 pMod->pUserData, (azArg?&azArg[1]:0), (nArg?nArg-1:0), &pConfig->pTok
252490 pConfig->pTokApi = 0;
252491 pConfig->pTok = 0;
252526 ppApi = (fts5_api**)sqlite3_value_pointer(apArg[0], "fts5_api_ptr");
252538 assert( nArg==0 );
252552 for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
252553 if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
252555 return 0;
252573 assert( pzErr!=0 && *pzErr==0 );
252575 assert( pTab->p.pConfig->pzErrmsg==0 );
252577 rc = sqlite3Fts5StorageIntegrity(pTab->pStorage, 0);
252578 if( *pzErr==0 && rc!=SQLITE_OK ){
252579 if( (rc&0xff)==SQLITE_CORRUPT ){
252591 pTab->p.pConfig->pzErrmsg = 0;
252626 Fts5Global *pGlobal = 0;
252629 if( pGlobal==0 ){
252633 memset(pGlobal, 0, sizeof(Fts5Global));
252647 db, "fts5", 1, SQLITE_UTF8, p, fts5Fts5Func, 0, 0
252652 db, "fts5_source_id", 0,
252654 p, fts5SourceIdFunc, 0, 0
252741 #if FTS5_STMT_SCAN_ASC!=0
252782 assert( eStmt>=0 && eStmt<ArraySize(p->aStmt) );
252783 if( p->aStmt[eStmt]==0 ){
252801 char *zSql = 0;
252832 for(i=0; i<nCol; i++){
252836 zBind[i*2-1] = '\0';
252861 if( zSql==0 ){
252867 rc = sqlite3_prepare_v3(pC->db, zSql, -1, f, &p->aStmt[eStmt], 0);
252895 if( zSql==0 ){
252898 rc = sqlite3_exec(db, zSql, 0, 0, pzErr);
252911 int rc = fts5ExecPrintf(pConfig->db, 0,
252920 rc = fts5ExecPrintf(pConfig->db, 0,
252926 rc = fts5ExecPrintf(pConfig->db, 0,
252941 *pRc = fts5ExecPrintf(pConfig->db, 0,
252976 char *zErr = 0;
253019 memset(p, 0, (size_t)nByte);
253028 if( zDefn==0 ){
253035 for(i=0; i<pConfig->nCol; i++){
253039 rc = sqlite3Fts5CreateTable(pConfig, "content", zDefn, 0, pzErr);
253049 rc = sqlite3Fts5CreateTable(pConfig, "docsize", zCols, 0, pzErr);
253057 rc = sqlite3Fts5StorageConfigValue(p, "version", 0, FTS5_CURRENT_VERSION);
253063 *pp = 0;
253077 for(i=0; i<ArraySize(p->aStmt); i++){
253108 if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
253125 sqlite3_stmt *pSeek = 0; /* SELECT to read row iDel from %_data */
253131 if( apVal==0 ){
253132 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP, &pSeek, 0);
253143 if( pConfig->abUnindexed[iCol-1]==0 ){
253146 assert( pSeek==0 || apVal==0 );
253147 assert( pSeek!=0 || apVal!=0 );
253157 ctx.szCol = 0;
253162 if( p->aTotalSize[iCol-1]<0 ){
253185 i64 iOrigin = 0;
253186 sqlite3_stmt *pLookup = 0;
253194 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
253203 if( rc==SQLITE_OK && iOrigin!=0 ){
253215 ** If there is no %_docsize table (as happens if the columnsize=0 option
253225 sqlite3_stmt *pReplace = 0;
253226 rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
253230 i64 iOrigin = 0;
253257 if( p->bTotalsValid==0 ){
253276 memset(&buf, 0, sizeof(buf));
253279 for(i=0; i<nCol; i++){
253296 sqlite3_stmt *pDel = 0;
253298 assert( pConfig->eContent!=FTS5_CONTENT_NORMAL || apVal==0 );
253316 rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_DOCSIZE, &pDel, 0);
253327 rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_CONTENT, &pDel, 0);
253346 p->bTotalsValid = 0;
253349 rc = fts5ExecPrintf(pConfig->db, 0,
253356 rc = fts5ExecPrintf(pConfig->db, 0,
253368 rc = sqlite3Fts5StorageConfigValue(p, "version", 0, FTS5_CURRENT_VERSION);
253374 Fts5Buffer buf = {0,0,0};
253376 sqlite3_stmt *pScan = 0;
253380 memset(&ctx, 0, sizeof(Fts5InsertCtx));
253392 i64 iRowid = sqlite3_column_int64(pScan, 0);
253395 rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
253396 for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
253397 ctx.szCol = 0;
253398 if( pConfig->abUnindexed[ctx.iCol]==0 ){
253452 sqlite3_stmt *pReplace = 0;
253453 rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
253486 sqlite3_stmt *pInsert = 0; /* Statement to write %_content table */
253488 rc = fts5StorageGetStmt(p, FTS5_STMT_INSERT_CONTENT, &pInsert, 0);
253515 memset(&buf, 0, sizeof(Fts5Buffer));
253520 rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
253522 for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
253523 ctx.szCol = 0;
253524 if( pConfig->abUnindexed[ctx.iCol]==0 ){
253556 if( zSql==0 ){
253559 sqlite3_stmt *pCnt = 0;
253560 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pCnt, 0);
253563 *pnRow = sqlite3_column_int64(pCnt, 0);
253609 if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
253621 iCol = 0;
253626 iPos = 0;
253627 iCol = 0;
253631 rc = sqlite3Fts5TermsetAdd(pTermset, 0, pToken, nToken, &bPresent);
253632 if( rc==SQLITE_OK && bPresent==0 ){
253634 pCtx->iRowid, iCol, iPos, 0, pToken, nToken
253638 for(ii=0; rc==SQLITE_OK && ii<pCtx->pConfig->nPrefix; ii++){
253643 if( bPresent==0 ){
253669 memset(&ctx, 0, sizeof(Fts5IntegrityCtx));
253674 memset(aTotalSize, 0, sizeof(i64) * pConfig->nCol);
253682 rc = fts5StorageGetStmt(p, FTS5_STMT_SCAN, &pScan, 0);
253687 ctx.iRowid = sqlite3_column_int64(pScan, 0);
253688 ctx.szCol = 0;
253695 for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
253698 ctx.szCol = 0;
253718 ctx.pTermset = 0;
253722 ctx.pTermset = 0;
253733 rc = fts5StorageLoadTotals(p, 0);
253734 for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
253742 i64 nRow = 0;
253747 i64 nRow = 0;
253782 p->aStmt[eStmt] = 0;
253801 if( p->aStmt[eStmt]==0 ){
253814 int iOff = 0;
253815 for(i=0; i<nCol; i++){
253832 sqlite3_stmt *pLookup = 0; /* Statement to query %_docsize */
253836 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
253842 const u8 *aBlob = sqlite3_column_blob(pLookup, 0);
253843 int nBlob = sqlite3_column_bytes(pLookup, 0);
253844 if( 0==fts5StorageDecodeSizeArray(aCol, nCol, aBlob, nBlob) ){
253845 bCorrupt = 0;
253860 int rc = fts5StorageLoadTotals(p, 0);
253862 *pnToken = 0;
253863 if( iCol<0 ){
253865 for(i=0; i<p->pConfig->nCol; i++){
253878 int rc = fts5StorageLoadTotals(p, 0);
253886 if( p->nTotalRow<=0 ) rc = FTS5_CORRUPT;
253900 p->bTotalsValid = 0;
253911 p->bTotalsValid = 0;
253921 sqlite3_stmt *pReplace = 0;
253922 int rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_CONFIG, &pReplace, 0);
253969 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00..0x0F */
253970 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10..0x1F */
253971 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20..0x2F */
253972 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0x30..0x3F */
253973 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40..0x4F */
253974 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 0x50..0x5F */
253975 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60..0x6F */
253976 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 0x70..0x7F */
253990 for(i=0; zArg[i]; i++){
253991 if( (zArg[i] & 0x80)==0 ){
254013 AsciiTokenizer *p = 0;
254019 if( p==0 ){
254023 memset(p, 0, sizeof(AsciiTokenizer));
254025 for(i=0; rc==SQLITE_OK && i<nArg-1; i+=2){
254027 if( 0==sqlite3_stricmp(azArg[i], "tokenchars") ){
254030 if( 0==sqlite3_stricmp(azArg[i], "separators") ){
254031 fts5AsciiAddExceptions(p, zArg, 0);
254039 p = 0;
254051 for(i=0; i<nByte; i++){
254071 int is = 0;
254084 while( is<nText && ((pText[is]&0x80)==0 && a[(int)pText[is]]==0) ){
254091 while( ie<nText && ((pText[ie]&0x80) || a[(int)pText[ie]] ) ){
254100 if( pFold==0 ){
254109 rc = xToken(pCtx, 0, pFold, nByte, is, ie);
254131 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
254132 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
254133 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
254134 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
254135 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
254136 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
254137 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
254138 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
254143 if( c>=0xc0 ){ \
254144 c = sqlite3Utf8Trans1[c-0xc0]; \
254145 while( zIn!=zTerm && (*zIn & 0xc0)==0x80 ){ \
254146 c = (c<<6) + (0x3f & *(zIn++)); \
254148 if( c<0x80 \
254149 || (c&0xFFFFF800)==0xD800 \
254150 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
254155 if( c<0x00080 ){ \
254156 *zOut++ = (unsigned char)(c&0xFF); \
254158 else if( c<0x00800 ){ \
254159 *zOut++ = 0xC0 + (unsigned char)((c>>6)&0x1F); \
254160 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
254162 else if( c<0x10000 ){ \
254163 *zOut++ = 0xE0 + (unsigned char)((c>>12)&0x0F); \
254164 *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
254165 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
254167 *zOut++ = 0xF0 + (unsigned char)((c>>18) & 0x07); \
254168 *zOut++ = 0x80 + (unsigned char)((c>>12) & 0x3F); \
254169 *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
254170 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
254177 if( ((unsigned char)(*(zIn++)))>=0xc0 ){ \
254178 while( (((unsigned char)*zIn) & 0xc0)==0x80 ){ zIn++; } \
254195 #define FTS5_REMOVE_DIACRITICS_NONE 0
254202 int bTokenChars /* 1 for 'tokenchars', 0 for 'separators' */
254208 if( n>0 ){
254223 assert( (bToken==0 || bToken==1) );
254224 assert( (bTokenChars==0 || bTokenChars==1) );
254225 if( bToken!=bTokenChars && sqlite3Fts5UnicodeIsdiacritic(iCode)==0 ){
254227 for(i=0; i<nNew; i++){
254250 if( p->nException>0 ){
254252 int iLo = 0;
254267 return 0;
254291 while( *z!=' ' && *z!='\t' && *z!='\0' ) z++;
254307 Unicode61Tokenizer *p = 0; /* New tokenizer object */
254318 memset(p, 0, sizeof(Unicode61Tokenizer));
254323 if( p->aFold==0 ){
254328 for(i=0; rc==SQLITE_OK && i<nArg-1; i+=2){
254329 if( 0==sqlite3_stricmp(azArg[i], "categories") ){
254337 for(i=0; rc==SQLITE_OK && i<nArg-1; i+=2){
254339 if( 0==sqlite3_stricmp(azArg[i], "remove_diacritics") ){
254340 if( (zArg[0]!='0' && zArg[0]!='1' && zArg[0]!='2') || zArg[1] ){
254343 p->eRemoveDiacritic = (zArg[0] - '0');
254350 if( 0==sqlite3_stricmp(azArg[i], "tokenchars") ){
254353 if( 0==sqlite3_stricmp(azArg[i], "separators") ){
254354 rc = fts5UnicodeAddExceptions(p, zArg, 0);
254356 if( 0==sqlite3_stricmp(azArg[i], "categories") ){
254369 p = 0;
254420 if( *zCsr & 0x80 ) {
254445 if( aFold==0 ){
254457 if( *zCsr & 0x80 ){
254468 }else if( a[*zCsr]==0 ){
254484 rc = xToken(pCtx, 0, aFold, zOut-aFold, is, ie);
254531 void *pUserdata = 0;
254534 if( nArg>0 ){
254535 zBase = azArg[0];
254540 memset(pRet, 0, sizeof(PorterTokenizer));
254546 int nArg2 = (nArg>0 ? nArg-1 : 0);
254547 const char **azArg2 = (nArg2 ? &azArg[1] : 0);
254553 pRet = 0;
254575 #if 0
254585 if( 0==memcmp(&aBuf[nBuf - p->nSuffix], p->zSuffix, p->nSuffix) ) break;
254590 if( p->xCond==0 || p->xCond(aBuf, nStem) ){
254612 for(i=0; i<nStem; i++){
254613 if( 0==(bCons = !fts5PorterIsVowel(zStem[i], bCons)) ) break;
254620 return 0;
254623 /* porter rule condition: (m > 0) */
254625 return !!fts5PorterGobbleVC(zStem, nStem, 0);
254631 n = fts5PorterGobbleVC(zStem, nStem, 0);
254635 return 0;
254641 n = fts5PorterGobbleVC(zStem, nStem, 0);
254642 if( n && 0==fts5PorterGobbleVC(&zStem[n], nStem-n, 1) ){
254645 return 0;
254651 return 0;
254654 int mask = 0;
254655 int bCons = 0;
254656 for(i=0; i<nStem; i++){
254658 assert( bCons==0 || bCons==1 );
254661 return ((mask & 0x0007)==0x0005);
254667 assert( nStem>0 );
254675 for(i=0; i<nStem; i++){
254676 if( fts5PorterIsVowel(zStem[i], i>0) ){
254680 return 0;
254690 int ret = 0;
254695 if( nBuf>2 && 0==memcmp("al", &aBuf[nBuf-2], 2) ){
254703 if( nBuf>4 && 0==memcmp("ance", &aBuf[nBuf-4], 4) ){
254707 }else if( nBuf>4 && 0==memcmp("ence", &aBuf[nBuf-4], 4) ){
254715 if( nBuf>2 && 0==memcmp("er", &aBuf[nBuf-2], 2) ){
254723 if( nBuf>2 && 0==memcmp("ic", &aBuf[nBuf-2], 2) ){
254731 if( nBuf>4 && 0==memcmp("able", &aBuf[nBuf-4], 4) ){
254735 }else if( nBuf>4 && 0==memcmp("ible", &aBuf[nBuf-4], 4) ){
254743 if( nBuf>3 && 0==memcmp("ant", &aBuf[nBuf-3], 3) ){
254747 }else if( nBuf>5 && 0==memcmp("ement", &aBuf[nBuf-5], 5) ){
254751 }else if( nBuf>4 && 0==memcmp("ment", &aBuf[nBuf-4], 4) ){
254755 }else if( nBuf>3 && 0==memcmp("ent", &aBuf[nBuf-3], 3) ){
254763 if( nBuf>3 && 0==memcmp("ion", &aBuf[nBuf-3], 3) ){
254767 }else if( nBuf>2 && 0==memcmp("ou", &aBuf[nBuf-2], 2) ){
254775 if( nBuf>3 && 0==memcmp("ism", &aBuf[nBuf-3], 3) ){
254783 if( nBuf>3 && 0==memcmp("ate", &aBuf[nBuf-3], 3) ){
254787 }else if( nBuf>3 && 0==memcmp("iti", &aBuf[nBuf-3], 3) ){
254795 if( nBuf>3 && 0==memcmp("ous", &aBuf[nBuf-3], 3) ){
254803 if( nBuf>3 && 0==memcmp("ive", &aBuf[nBuf-3], 3) ){
254811 if( nBuf>3 && 0==memcmp("ize", &aBuf[nBuf-3], 3) ){
254824 int ret = 0;
254829 if( nBuf>2 && 0==memcmp("at", &aBuf[nBuf-2], 2) ){
254837 if( nBuf>2 && 0==memcmp("bl", &aBuf[nBuf-2], 2) ){
254845 if( nBuf>2 && 0==memcmp("iz", &aBuf[nBuf-2], 2) ){
254858 int ret = 0;
254863 if( nBuf>7 && 0==memcmp("ational", &aBuf[nBuf-7], 7) ){
254868 }else if( nBuf>6 && 0==memcmp("tional", &aBuf[nBuf-6], 6) ){
254877 if( nBuf>4 && 0==memcmp("enci", &aBuf[nBuf-4], 4) ){
254882 }else if( nBuf>4 && 0==memcmp("anci", &aBuf[nBuf-4], 4) ){
254891 if( nBuf>4 && 0==memcmp("izer", &aBuf[nBuf-4], 4) ){
254900 if( nBuf>4 && 0==memcmp("logi", &aBuf[nBuf-4], 4) ){
254909 if( nBuf>3 && 0==memcmp("bli", &aBuf[nBuf-3], 3) ){
254914 }else if( nBuf>4 && 0==memcmp("alli", &aBuf[nBuf-4], 4) ){
254919 }else if( nBuf>5 && 0==memcmp("entli", &aBuf[nBuf-5], 5) ){
254924 }else if( nBuf>3 && 0==memcmp("eli", &aBuf[nBuf-3], 3) ){
254929 }else if( nBuf>5 && 0==memcmp("ousli", &aBuf[nBuf-5], 5) ){
254938 if( nBuf>7 && 0==memcmp("ization", &aBuf[nBuf-7], 7) ){
254943 }else if( nBuf>5 && 0==memcmp("ation", &aBuf[nBuf-5], 5) ){
254948 }else if( nBuf>4 && 0==memcmp("ator", &aBuf[nBuf-4], 4) ){
254957 if( nBuf>5 && 0==memcmp("alism", &aBuf[nBuf-5], 5) ){
254962 }else if( nBuf>7 && 0==memcmp("iveness", &aBuf[nBuf-7], 7) ){
254967 }else if( nBuf>7 && 0==memcmp("fulness", &aBuf[nBuf-7], 7) ){
254972 }else if( nBuf>7 && 0==memcmp("ousness", &aBuf[nBuf-7], 7) ){
254981 if( nBuf>5 && 0==memcmp("aliti", &aBuf[nBuf-5], 5) ){
254986 }else if( nBuf>5 && 0==memcmp("iviti", &aBuf[nBuf-5], 5) ){
254991 }else if( nBuf>6 && 0==memcmp("biliti", &aBuf[nBuf-6], 6) ){
255005 int ret = 0;
255010 if( nBuf>4 && 0==memcmp("ical", &aBuf[nBuf-4], 4) ){
255019 if( nBuf>4 && 0==memcmp("ness", &aBuf[nBuf-4], 4) ){
255027 if( nBuf>5 && 0==memcmp("icate", &aBuf[nBuf-5], 5) ){
255032 }else if( nBuf>5 && 0==memcmp("iciti", &aBuf[nBuf-5], 5) ){
255041 if( nBuf>3 && 0==memcmp("ful", &aBuf[nBuf-3], 3) ){
255049 if( nBuf>5 && 0==memcmp("ative", &aBuf[nBuf-5], 5) ){
255057 if( nBuf>5 && 0==memcmp("alize", &aBuf[nBuf-5], 5) ){
255071 int ret = 0;
255076 if( nBuf>3 && 0==memcmp("eed", &aBuf[nBuf-3], 3) ){
255081 }else if( nBuf>2 && 0==memcmp("ed", &aBuf[nBuf-2], 2) ){
255090 if( nBuf>3 && 0==memcmp("ing", &aBuf[nBuf-3], 3) ){
255146 if( fts5PorterStep1B2(aBuf, &nBuf)==0 ){
255148 if( fts5PorterIsVowel(c, 0)==0
255169 assert( nBuf>0 );
255239 if( pNew==0 ){
255244 pNew->iFoldParam = 0;
255245 for(i=0; rc==SQLITE_OK && i<nArg-1; i+=2){
255247 if( 0==sqlite3_stricmp(azArg[i], "case_sensitive") ){
255248 if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1] ){
255251 pNew->bFold = (zArg[0]=='0');
255253 }else if( 0==sqlite3_stricmp(azArg[i], "remove_diacritics") ){
255254 if( (zArg[0]!='0' && zArg[0]!='1' && zArg[0]!='2') || zArg[1] ){
255257 pNew->iFoldParam = (zArg[0]!='0') ? 2 : 0;
255265 if( pNew->iFoldParam!=0 && pNew->bFold==0 ){
255271 pNew = 0;
255301 for(ii=0; ii<3; ii++){
255305 if( iCode==0 ) return SQLITE_OK;
255307 }while( iCode==0 );
255327 if( iCode==0 ) break;
255329 }while( iCode==0 );
255332 rc = xToken(pCtx, 0, aBuf, zOut-aBuf, aStart[0], iNext);
255333 if( iCode==0 || rc!=SQLITE_OK ) break;
255344 aStart[0] = aStart[1];
255360 ** "trigram" tokenizer, case_sensitive=0 (the default) - FTS5_PATTERN_LIKE
255369 if( p->iFoldParam==0 ){
255393 for(i=0; rc==SQLITE_OK && i<ArraySize(aBuiltin); i++){
255398 0
255437 0, 1797, 1848, 1859, 1891, 1928, 1940, 1995,
255454 #define HIBIT ((unsigned char)0x80)
255456 '\0', 'a', 'c', 'e', 'i', 'n',
255466 'o'|HIBIT, 'y', '\0', '\0', '\0', '\0',
255467 '\0', '\0', '\0', '\0', 'a', 'b',
255479 unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
255480 int iRes = 0;
255481 int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
255482 int iLo = 0;
255493 if( bComplex==0 && (aChar[iRes] & 0x80) ) return c;
255494 return (c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : ((int)aChar[iRes] & 0x7F);
255503 unsigned int mask0 = 0x08029FDF;
255504 unsigned int mask1 = 0x000361F8;
255505 if( c<768 || c>817 ) return 0;
255533 ** case equivalent is ((C + aiOff[flags>>1]) & 0xFFFF).
255548 {386, 1, 4}, {390, 44, 1}, {391, 0, 1},
255549 {393, 42, 2}, {395, 0, 1}, {398, 32, 1},
255550 {399, 38, 1}, {400, 40, 1}, {401, 0, 1},
255552 {407, 48, 1}, {408, 0, 1}, {412, 52, 1},
255554 {422, 60, 1}, {423, 0, 1}, {425, 60, 1},
255555 {428, 0, 1}, {430, 60, 1}, {431, 0, 1},
255557 {440, 0, 1}, {444, 0, 1}, {452, 2, 1},
255558 {453, 0, 1}, {455, 2, 1}, {456, 0, 1},
255562 {546, 1, 18}, {570, 70, 1}, {571, 0, 1},
255563 {573, 108, 1}, {574, 68, 1}, {577, 0, 1},
255566 {886, 0, 1}, {902, 18, 1}, {904, 16, 3},
255568 {931, 14, 9}, {962, 0, 1}, {975, 4, 1},
255572 {1015, 0, 1}, {1017, 152, 1}, {1018, 0, 1},
255588 {8579, 0, 1}, {9398, 10, 26}, {11264, 22, 47},
255589 {11360, 0, 1}, {11362, 88, 1}, {11363, 102, 1},
255592 {11378, 0, 1}, {11381, 0, 1}, {11390, 78, 2},
255593 {11392, 1, 100}, {11499, 1, 4}, {11506, 0, 1},
255596 {42878, 1, 10}, {42891, 0, 1}, {42893, 74, 1},
255621 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
255622 int iLo = 0;
255625 assert( c>aEntry[0].iCode );
255629 if( cmp>=0 ){
255637 assert( iRes>=0 && c>=aEntry[iRes].iCode );
255639 if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
255640 ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
255641 assert( ret>0 );
255658 aArray[0] = 1;
255659 switch( zCat[0] ){
255772 return 0;
255776 0, 1471, 1753, 1760, 1760, 1760, 1760, 1760, 1760, 1760,
255780 0, 32, 33, 36, 37, 40, 41, 42, 43, 44,
255927 65532, 0, 13, 40, 60, 63, 80, 128, 256, 263,
255955 63045, 63104, 63232, 0, 42710, 42752, 46900, 46912, 47133, 63488,
255956 1, 32, 256, 0, 65533,
256146 return 0;
256150 iKey = (iCode & 0xFFFF);
256162 if( iRes<0 ) return 0;
256163 if( iKey>=(aFts5UnicodeMap[iRes]+(aFts5UnicodeData[iRes]>>5)) ) return 0;
256164 ret = aFts5UnicodeData[iRes] & 0x1F;
256166 return ((iKey - aFts5UnicodeMap[iRes]) & 0x01) ? 5 : 9;
256170 int i = 0;
256171 int iTbl = 0;
256173 int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
256180 aAscii[0] = 0; /* 0x00 is never a token character */
256213 if (!(a&0x80))
256215 /* Values between 0 and 127 */
256224 if (!(b&0x80))
256227 a &= 0x7f;
256238 if (!(a&0x80))
256241 a &= (0x7f<<14)|(0x7f);
256242 b &= 0x7f;
256262 *v = ((u32)v64) & 0x7FFFFFFF;
256274 ** SLOT_2_0 A mask for (0x7f<<14) | 0x7f
256276 ** SLOT_4_2_0 A mask for (0x7f<<28) | SLOT_2_0
256278 #define SLOT_2_0 0x001fc07f
256279 #define SLOT_4_2_0 0xf01fc07f
256282 ** Read a 64-bit variable-length integer from memory starting at p[0].
256290 if (!(a&0x80))
256299 if (!(b&0x80))
256301 a &= 0x7f;
256309 assert( SLOT_2_0 == ((0x7f<<14) | (0x7f)) );
256310 assert( SLOT_4_2_0 == ((0xfU<<28) | (0x7f<<14) | (0x7f)) );
256316 if (!(a&0x80))
256319 b &= 0x7f;
256332 if (!(b&0x80))
256336 /* a &= (0x7f<<14)|(0x7f); */
256347 /* a &= (0x7f<<14)|(0x7f); */
256356 if (!(a&0x80))
256359 /* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
256360 /* b &= (0x7f<<14)|(0x7f); */
256377 if (!(b&0x80))
256380 /* b &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
256393 if (!(a&0x80))
256410 if (!(b&0x80))
256414 /* a &= (0x7f<<14)|(0x7f); */
256428 /* a &= (0x7f<<29)|(0x7f<<15)|(0xff); */
256435 b &= 0x7f;
256448 ** A = 0xxxxxxx 7 bits of data and one flag bit
256470 ** Write a 64-bit variable-length integer to memory starting at p[0].
256482 if( v & (((u64)0xff000000)<<32) ){
256485 for(i=7; i>=0; i--){
256486 p[i] = (u8)((v & 0x7f) | 0x80);
256491 n = 0;
256493 buf[n++] = (u8)((v & 0x7f) | 0x80);
256495 }while( v!=0 );
256496 buf[0] &= 0x7f;
256498 for(i=0, j=n-1; j>=0; j--, i++){
256505 if( v<=0x7f ){
256506 p[0] = v&0x7f;
256509 if( v<=0x3fff ){
256510 p[0] = ((v>>7)&0x7f)|0x80;
256511 p[1] = v&0x7f;
256519 #if 0
256610 #define FTS5_VOCAB_COL 0
256621 #define FTS5_VOCAB_TERM_EQ 0x01
256622 #define FTS5_VOCAB_TERM_GE 0x02
256623 #define FTS5_VOCAB_TERM_LE 0x04
256637 if( sqlite3_stricmp(zCopy, "col")==0 ){
256641 if( sqlite3_stricmp(zCopy, "row")==0 ){
256644 if( sqlite3_stricmp(zCopy, "instance")==0 ){
256682 ** argv[0] -> module name ("fts5vocab")
256711 Fts5VocabTable *pRet = 0;
256715 bDb = (argc==6 && strlen(argv[1])==4 && memcmp("temp", argv[1], 4)==0);
256717 if( argc!=5 && bDb==0 ){
256727 int eType = 0;
256731 assert( eType>=0 && eType<ArraySize(azSchema) );
256800 int idxNum = 0;
256801 int nArg = 0;
256805 for(i=0; i<pInfo->nConstraint; i++){
256807 if( p->usable==0 ) continue;
256808 if( p->iColumn==0 ){ /* term column */
256817 if( iTermEq>=0 ){
256823 if( iTermGe>=0 ){
256828 if( iTermLe>=0 ){
256836 ** the "term" column (column 0). So if the user has requested this
256841 && pInfo->aOrderBy[0].iColumn==0
256842 && pInfo->aOrderBy[0].desc==0
256859 Fts5Table *pFts5 = 0;
256860 Fts5VocabCursor *pCsr = 0;
256862 sqlite3_stmt *pStmt = 0;
256863 char *zSql = 0;
256876 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pStmt, 0);
256879 assert( rc==SQLITE_OK || pStmt==0 );
256884 i64 iId = sqlite3_column_int64(pStmt, 0);
256887 pTab->bBusy = 0;
256890 if( pFts5==0 ){
256892 pStmt = 0;
256923 pCsr->rowid = 0;
256926 pCsr->pStruct = 0;
256927 pCsr->pIter = 0;
256930 pCsr->zLeTerm = 0;
256931 pCsr->bEof = 0;
256956 if( pCsr->nLeTerm>=0 ){
256959 if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
256976 assert( sqlite3Fts5IterEof(pIter)==0 );
256977 assert( pCsr->bEof==0 );
256981 pCsr->iInstPos = 0;
256982 pCsr->iInstOff = 0;
257029 assert( nTerm>=0 );
257030 if( pCsr->nLeTerm>=0 ){
257033 if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
257040 memset(pCsr->aCnt, 0, nCol * sizeof(i64));
257041 memset(pCsr->aDoc, 0, nCol * sizeof(i64));
257042 pCsr->iCol = 0;
257048 i64 iPos = 0; /* 64-bit position read from poslist */
257049 int iOff = 0; /* Current offset within position list */
257057 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){
257058 pCsr->aCnt[0]++;
257061 pCsr->aDoc[0]++;
257067 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){
257080 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff,&iPos) ){
257081 assert_nc( iPos>=0 && iPos<nCol );
257090 pCsr->aDoc[0]++;
257107 || (nTerm>0 && memcmp(zTerm, pCsr->term.p, nTerm))
257117 if( rc==SQLITE_OK && pCsr->bEof==0 && pTab->eType==FTS5_VOCAB_COL ){
257118 for(/* noop */; pCsr->iCol<nCol && pCsr->aDoc[pCsr->iCol]==0; pCsr->iCol++);
257141 int iVal = 0;
257143 const char *zTerm = 0;
257144 int nTerm = 0;
257146 sqlite3_value *pEq = 0;
257147 sqlite3_value *pGe = 0;
257148 sqlite3_value *pLe = 0;
257168 if( zCopy==0 ) zCopy = "";
257171 if( pCsr->zLeTerm==0 ){
257181 rc = sqlite3Fts5IndexQuery(pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
257216 i64 iVal = 0;
257218 if( iCol==0 ){
257237 iVal = pCsr->aDoc[0];
257239 iVal = pCsr->aCnt[0];
257254 if( ii>=0 && ii<pCsr->pFts5->pConfig->nCol ){
257271 if( iVal>0 ) sqlite3_result_int64(pCtx, iVal);
257304 /* xUpdate */ 0,
257305 /* xBegin */ 0,
257306 /* xSync */ 0,
257307 /* xCommit */ 0,
257308 /* xRollback */ 0,
257309 /* xFindFunction */ 0,
257310 /* xRename */ 0,
257311 /* xSavepoint */ 0,
257312 /* xRelease */ 0,
257313 /* xRollbackTo */ 0,
257314 /* xShadowName */ 0,
257315 /* xIntegrity */ 0
257319 return sqlite3_create_module_v2(db, "fts5vocab", &fts5Vocab, p, 0);
257414 #define STMT_COLUMN_SQL 0 /* SQL for the statement */
257437 if( pNew==0 ) return SQLITE_NOMEM;
257438 memset(pNew, 0, sizeof(*pNew));
257458 if( pCur==0 ) return SQLITE_NOMEM;
257459 memset(pCur, 0, sizeof(*pCur));
257466 StmtRow *pRow = 0;
257467 StmtRow *pNext = 0;
257472 pCur->pRow = 0;
257531 return pCur->pRow==0;
257546 sqlite3_stmt *p = 0;
257548 StmtRow **ppRow = 0;
257556 for(p=sqlite3_next_stmt(pCur->db, 0); p; p=sqlite3_next_stmt(pCur->db, p)){
257558 sqlite3_int64 nSql = zSql ? strlen(zSql)+1 : 0;
257561 if( pNew==0 ) return SQLITE_NOMEM;
257562 memset(pNew, 0, sizeof(StmtRow));
257571 p, SQLITE_STMTSTATUS_FULLSCAN_STEP, 0
257574 p, SQLITE_STMTSTATUS_SORT, 0
257577 p, SQLITE_STMTSTATUS_AUTOINDEX, 0
257580 p, SQLITE_STMTSTATUS_VM_STEP, 0
257583 p, SQLITE_STMTSTATUS_REPREPARE, 0
257586 p, SQLITE_STMTSTATUS_RUN, 0
257589 p, SQLITE_STMTSTATUS_MEMUSED, 0
257620 0, /* iVersion */
257621 0, /* xCreate */
257625 0, /* xDestroy */
257633 0, /* xUpdate */
257634 0, /* xBegin */
257635 0, /* xSync */
257636 0, /* xCommit */
257637 0, /* xRollback */
257638 0, /* xFindMethod */
257639 0, /* xRename */
257640 0, /* xSavepoint */
257641 0, /* xRelease */
257642 0, /* xRollbackTo */
257643 0, /* xShadowName */
257644 0 /* xIntegrity */
257652 rc = sqlite3_create_module(db, "sqlite_stmt", &stmtModule, 0);