Fossil SCM
Now really update the built-in SQLite to the first 3.8.10 beta, not only the command line shell.
Commit
acd670f2519599aa965e12b2450368b480fd1524
Parent
a481a8176b9fa8a…
2 files changed
+1928
-724
+91
-15
+1928
-724
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | -** version 3.8.9. By combining all the individual C code files into this | |
| 3 | +** version 3.8.10. By combining all the individual C code files into this | |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| @@ -68,10 +68,11 @@ | ||
| 68 | 68 | #if defined(_MSC_VER) |
| 69 | 69 | #pragma warning(disable : 4054) |
| 70 | 70 | #pragma warning(disable : 4055) |
| 71 | 71 | #pragma warning(disable : 4100) |
| 72 | 72 | #pragma warning(disable : 4127) |
| 73 | +#pragma warning(disable : 4130) | |
| 73 | 74 | #pragma warning(disable : 4152) |
| 74 | 75 | #pragma warning(disable : 4189) |
| 75 | 76 | #pragma warning(disable : 4206) |
| 76 | 77 | #pragma warning(disable : 4210) |
| 77 | 78 | #pragma warning(disable : 4232) |
| @@ -315,13 +316,13 @@ | ||
| 315 | 316 | ** |
| 316 | 317 | ** See also: [sqlite3_libversion()], |
| 317 | 318 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 318 | 319 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 319 | 320 | */ |
| 320 | -#define SQLITE_VERSION "3.8.9" | |
| 321 | -#define SQLITE_VERSION_NUMBER 3008009 | |
| 322 | -#define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09" | |
| 321 | +#define SQLITE_VERSION "3.8.10" | |
| 322 | +#define SQLITE_VERSION_NUMBER 3008010 | |
| 323 | +#define SQLITE_SOURCE_ID "2015-05-04 19:13:25 850c11866686a7b39d7b163fb60898c11283688e" | |
| 323 | 324 | |
| 324 | 325 | /* |
| 325 | 326 | ** CAPI3REF: Run-Time Library Version Numbers |
| 326 | 327 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 327 | 328 | ** |
| @@ -474,10 +475,11 @@ | ||
| 474 | 475 | # define double sqlite3_int64 |
| 475 | 476 | #endif |
| 476 | 477 | |
| 477 | 478 | /* |
| 478 | 479 | ** CAPI3REF: Closing A Database Connection |
| 480 | +** DESTRUCTOR: sqlite3 | |
| 479 | 481 | ** |
| 480 | 482 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 481 | 483 | ** for the [sqlite3] object. |
| 482 | 484 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
| 483 | 485 | ** the [sqlite3] object is successfully destroyed and all associated |
| @@ -525,10 +527,11 @@ | ||
| 525 | 527 | */ |
| 526 | 528 | typedef int (*sqlite3_callback)(void*,int,char**, char**); |
| 527 | 529 | |
| 528 | 530 | /* |
| 529 | 531 | ** CAPI3REF: One-Step Query Execution Interface |
| 532 | +** METHOD: sqlite3 | |
| 530 | 533 | ** |
| 531 | 534 | ** The sqlite3_exec() interface is a convenience wrapper around |
| 532 | 535 | ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], |
| 533 | 536 | ** that allows an application to run multiple statements of SQL |
| 534 | 537 | ** without having to use a lot of C code. |
| @@ -1582,10 +1585,11 @@ | ||
| 1582 | 1585 | */ |
| 1583 | 1586 | SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...); |
| 1584 | 1587 | |
| 1585 | 1588 | /* |
| 1586 | 1589 | ** CAPI3REF: Configure database connections |
| 1590 | +** METHOD: sqlite3 | |
| 1587 | 1591 | ** |
| 1588 | 1592 | ** The sqlite3_db_config() interface is used to make configuration |
| 1589 | 1593 | ** changes to a [database connection]. The interface is similar to |
| 1590 | 1594 | ** [sqlite3_config()] except that the changes apply to a single |
| 1591 | 1595 | ** [database connection] (specified in the first argument). |
| @@ -2079,19 +2083,21 @@ | ||
| 2079 | 2083 | #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ |
| 2080 | 2084 | |
| 2081 | 2085 | |
| 2082 | 2086 | /* |
| 2083 | 2087 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
| 2088 | +** METHOD: sqlite3 | |
| 2084 | 2089 | ** |
| 2085 | 2090 | ** ^The sqlite3_extended_result_codes() routine enables or disables the |
| 2086 | 2091 | ** [extended result codes] feature of SQLite. ^The extended result |
| 2087 | 2092 | ** codes are disabled by default for historical compatibility. |
| 2088 | 2093 | */ |
| 2089 | 2094 | SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff); |
| 2090 | 2095 | |
| 2091 | 2096 | /* |
| 2092 | 2097 | ** CAPI3REF: Last Insert Rowid |
| 2098 | +** METHOD: sqlite3 | |
| 2093 | 2099 | ** |
| 2094 | 2100 | ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) |
| 2095 | 2101 | ** has a unique 64-bit signed |
| 2096 | 2102 | ** integer key called the [ROWID | "rowid"]. ^The rowid is always available |
| 2097 | 2103 | ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those |
| @@ -2139,10 +2145,11 @@ | ||
| 2139 | 2145 | */ |
| 2140 | 2146 | SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*); |
| 2141 | 2147 | |
| 2142 | 2148 | /* |
| 2143 | 2149 | ** CAPI3REF: Count The Number Of Rows Modified |
| 2150 | +** METHOD: sqlite3 | |
| 2144 | 2151 | ** |
| 2145 | 2152 | ** ^This function returns the number of rows modified, inserted or |
| 2146 | 2153 | ** deleted by the most recently completed INSERT, UPDATE or DELETE |
| 2147 | 2154 | ** statement on the database connection specified by the only parameter. |
| 2148 | 2155 | ** ^Executing any other type of SQL statement does not modify the value |
| @@ -2191,10 +2198,11 @@ | ||
| 2191 | 2198 | */ |
| 2192 | 2199 | SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*); |
| 2193 | 2200 | |
| 2194 | 2201 | /* |
| 2195 | 2202 | ** CAPI3REF: Total Number Of Rows Modified |
| 2203 | +** METHOD: sqlite3 | |
| 2196 | 2204 | ** |
| 2197 | 2205 | ** ^This function returns the total number of rows inserted, modified or |
| 2198 | 2206 | ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
| 2199 | 2207 | ** since the database connection was opened, including those executed as |
| 2200 | 2208 | ** part of trigger programs. ^Executing any other type of SQL statement |
| @@ -2214,10 +2222,11 @@ | ||
| 2214 | 2222 | */ |
| 2215 | 2223 | SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*); |
| 2216 | 2224 | |
| 2217 | 2225 | /* |
| 2218 | 2226 | ** CAPI3REF: Interrupt A Long-Running Query |
| 2227 | +** METHOD: sqlite3 | |
| 2219 | 2228 | ** |
| 2220 | 2229 | ** ^This function causes any pending database operation to abort and |
| 2221 | 2230 | ** return at its earliest opportunity. This routine is typically |
| 2222 | 2231 | ** called in response to a user action such as pressing "Cancel" |
| 2223 | 2232 | ** or Ctrl-C where the user wants a long query operation to halt |
| @@ -2290,10 +2299,11 @@ | ||
| 2290 | 2299 | SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql); |
| 2291 | 2300 | |
| 2292 | 2301 | /* |
| 2293 | 2302 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2294 | 2303 | ** KEYWORDS: {busy-handler callback} {busy handler} |
| 2304 | +** METHOD: sqlite3 | |
| 2295 | 2305 | ** |
| 2296 | 2306 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2297 | 2307 | ** that might be invoked with argument P whenever |
| 2298 | 2308 | ** an attempt is made to access a database table associated with |
| 2299 | 2309 | ** [database connection] D when another thread |
| @@ -2349,10 +2359,11 @@ | ||
| 2349 | 2359 | */ |
| 2350 | 2360 | SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); |
| 2351 | 2361 | |
| 2352 | 2362 | /* |
| 2353 | 2363 | ** CAPI3REF: Set A Busy Timeout |
| 2364 | +** METHOD: sqlite3 | |
| 2354 | 2365 | ** |
| 2355 | 2366 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2356 | 2367 | ** for a specified amount of time when a table is locked. ^The handler |
| 2357 | 2368 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2358 | 2369 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| @@ -2371,10 +2382,11 @@ | ||
| 2371 | 2382 | */ |
| 2372 | 2383 | SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms); |
| 2373 | 2384 | |
| 2374 | 2385 | /* |
| 2375 | 2386 | ** CAPI3REF: Convenience Routines For Running Queries |
| 2387 | +** METHOD: sqlite3 | |
| 2376 | 2388 | ** |
| 2377 | 2389 | ** This is a legacy interface that is preserved for backwards compatibility. |
| 2378 | 2390 | ** Use of this interface is not recommended. |
| 2379 | 2391 | ** |
| 2380 | 2392 | ** Definition: A <b>result table</b> is memory data structure created by the |
| @@ -2706,10 +2718,11 @@ | ||
| 2706 | 2718 | */ |
| 2707 | 2719 | SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P); |
| 2708 | 2720 | |
| 2709 | 2721 | /* |
| 2710 | 2722 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2723 | +** METHOD: sqlite3 | |
| 2711 | 2724 | ** |
| 2712 | 2725 | ** ^This routine registers an authorizer callback with a particular |
| 2713 | 2726 | ** [database connection], supplied in the first argument. |
| 2714 | 2727 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2715 | 2728 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| @@ -2862,10 +2875,11 @@ | ||
| 2862 | 2875 | #define SQLITE_COPY 0 /* No longer used */ |
| 2863 | 2876 | #define SQLITE_RECURSIVE 33 /* NULL NULL */ |
| 2864 | 2877 | |
| 2865 | 2878 | /* |
| 2866 | 2879 | ** CAPI3REF: Tracing And Profiling Functions |
| 2880 | +** METHOD: sqlite3 | |
| 2867 | 2881 | ** |
| 2868 | 2882 | ** These routines register callback functions that can be used for |
| 2869 | 2883 | ** tracing and profiling the execution of SQL statements. |
| 2870 | 2884 | ** |
| 2871 | 2885 | ** ^The callback function registered by sqlite3_trace() is invoked at |
| @@ -2894,10 +2908,11 @@ | ||
| 2894 | 2908 | SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*, |
| 2895 | 2909 | void(*xProfile)(void*,const char*,sqlite3_uint64), void*); |
| 2896 | 2910 | |
| 2897 | 2911 | /* |
| 2898 | 2912 | ** CAPI3REF: Query Progress Callbacks |
| 2913 | +** METHOD: sqlite3 | |
| 2899 | 2914 | ** |
| 2900 | 2915 | ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback |
| 2901 | 2916 | ** function X to be invoked periodically during long running calls to |
| 2902 | 2917 | ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for |
| 2903 | 2918 | ** database connection D. An example use for this |
| @@ -2927,10 +2942,11 @@ | ||
| 2927 | 2942 | */ |
| 2928 | 2943 | SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2929 | 2944 | |
| 2930 | 2945 | /* |
| 2931 | 2946 | ** CAPI3REF: Opening A New Database Connection |
| 2947 | +** CONSTRUCTOR: sqlite3 | |
| 2932 | 2948 | ** |
| 2933 | 2949 | ** ^These routines open an SQLite database file as specified by the |
| 2934 | 2950 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2935 | 2951 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2936 | 2952 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| @@ -3212,10 +3228,11 @@ | ||
| 3212 | 3228 | SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64); |
| 3213 | 3229 | |
| 3214 | 3230 | |
| 3215 | 3231 | /* |
| 3216 | 3232 | ** CAPI3REF: Error Codes And Messages |
| 3233 | +** METHOD: sqlite3 | |
| 3217 | 3234 | ** |
| 3218 | 3235 | ** ^If the most recent sqlite3_* API call associated with |
| 3219 | 3236 | ** [database connection] D failed, then the sqlite3_errcode(D) interface |
| 3220 | 3237 | ** returns the numeric [result code] or [extended result code] for that |
| 3221 | 3238 | ** API call. |
| @@ -3257,37 +3274,38 @@ | ||
| 3257 | 3274 | SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*); |
| 3258 | 3275 | SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*); |
| 3259 | 3276 | SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int); |
| 3260 | 3277 | |
| 3261 | 3278 | /* |
| 3262 | -** CAPI3REF: SQL Statement Object | |
| 3279 | +** CAPI3REF: Prepared Statement Object | |
| 3263 | 3280 | ** KEYWORDS: {prepared statement} {prepared statements} |
| 3264 | 3281 | ** |
| 3265 | -** An instance of this object represents a single SQL statement. | |
| 3266 | -** This object is variously known as a "prepared statement" or a | |
| 3267 | -** "compiled SQL statement" or simply as a "statement". | |
| 3282 | +** An instance of this object represents a single SQL statement that | |
| 3283 | +** has been compiled into binary form and is ready to be evaluated. | |
| 3268 | 3284 | ** |
| 3269 | -** The life of a statement object goes something like this: | |
| 3285 | +** Think of each SQL statement as a separate computer program. The | |
| 3286 | +** original SQL text is source code. A prepared statement object | |
| 3287 | +** is the compiled object code. All SQL must be converted into a | |
| 3288 | +** prepared statement before it can be run. | |
| 3289 | +** | |
| 3290 | +** The life-cycle of a prepared statement object usually goes like this: | |
| 3270 | 3291 | ** |
| 3271 | 3292 | ** <ol> |
| 3272 | -** <li> Create the object using [sqlite3_prepare_v2()] or a related | |
| 3273 | -** function. | |
| 3274 | -** <li> Bind values to [host parameters] using the sqlite3_bind_*() | |
| 3293 | +** <li> Create the prepared statement object using [sqlite3_prepare_v2()]. | |
| 3294 | +** <li> Bind values to [parameters] using the sqlite3_bind_*() | |
| 3275 | 3295 | ** interfaces. |
| 3276 | 3296 | ** <li> Run the SQL by calling [sqlite3_step()] one or more times. |
| 3277 | -** <li> Reset the statement using [sqlite3_reset()] then go back | |
| 3297 | +** <li> Reset the prepared statement using [sqlite3_reset()] then go back | |
| 3278 | 3298 | ** to step 2. Do this zero or more times. |
| 3279 | 3299 | ** <li> Destroy the object using [sqlite3_finalize()]. |
| 3280 | 3300 | ** </ol> |
| 3281 | -** | |
| 3282 | -** Refer to documentation on individual methods above for additional | |
| 3283 | -** information. | |
| 3284 | 3301 | */ |
| 3285 | 3302 | typedef struct sqlite3_stmt sqlite3_stmt; |
| 3286 | 3303 | |
| 3287 | 3304 | /* |
| 3288 | 3305 | ** CAPI3REF: Run-time Limits |
| 3306 | +** METHOD: sqlite3 | |
| 3289 | 3307 | ** |
| 3290 | 3308 | ** ^(This interface allows the size of various constructs to be limited |
| 3291 | 3309 | ** on a connection by connection basis. The first parameter is the |
| 3292 | 3310 | ** [database connection] whose limit is to be set or queried. The |
| 3293 | 3311 | ** second parameter is one of the [limit categories] that define a |
| @@ -3395,10 +3413,12 @@ | ||
| 3395 | 3413 | #define SQLITE_LIMIT_WORKER_THREADS 11 |
| 3396 | 3414 | |
| 3397 | 3415 | /* |
| 3398 | 3416 | ** CAPI3REF: Compiling An SQL Statement |
| 3399 | 3417 | ** KEYWORDS: {SQL statement compiler} |
| 3418 | +** METHOD: sqlite3 | |
| 3419 | +** CONSTRUCTOR: sqlite3_stmt | |
| 3400 | 3420 | ** |
| 3401 | 3421 | ** To execute an SQL query, it must first be compiled into a byte-code |
| 3402 | 3422 | ** program using one of these routines. |
| 3403 | 3423 | ** |
| 3404 | 3424 | ** The first argument, "db", is a [database connection] obtained from a |
| @@ -3502,19 +3522,21 @@ | ||
| 3502 | 3522 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3503 | 3523 | ); |
| 3504 | 3524 | |
| 3505 | 3525 | /* |
| 3506 | 3526 | ** CAPI3REF: Retrieving Statement SQL |
| 3527 | +** METHOD: sqlite3_stmt | |
| 3507 | 3528 | ** |
| 3508 | 3529 | ** ^This interface can be used to retrieve a saved copy of the original |
| 3509 | 3530 | ** SQL text used to create a [prepared statement] if that statement was |
| 3510 | 3531 | ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. |
| 3511 | 3532 | */ |
| 3512 | 3533 | SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt); |
| 3513 | 3534 | |
| 3514 | 3535 | /* |
| 3515 | 3536 | ** CAPI3REF: Determine If An SQL Statement Writes The Database |
| 3537 | +** METHOD: sqlite3_stmt | |
| 3516 | 3538 | ** |
| 3517 | 3539 | ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if |
| 3518 | 3540 | ** and only if the [prepared statement] X makes no direct changes to |
| 3519 | 3541 | ** the content of the database file. |
| 3520 | 3542 | ** |
| @@ -3542,10 +3564,11 @@ | ||
| 3542 | 3564 | */ |
| 3543 | 3565 | SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
| 3544 | 3566 | |
| 3545 | 3567 | /* |
| 3546 | 3568 | ** CAPI3REF: Determine If A Prepared Statement Has Been Reset |
| 3569 | +** METHOD: sqlite3_stmt | |
| 3547 | 3570 | ** |
| 3548 | 3571 | ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the |
| 3549 | 3572 | ** [prepared statement] S has been stepped at least once using |
| 3550 | 3573 | ** [sqlite3_step(S)] but has not run to completion and/or has not |
| 3551 | 3574 | ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) |
| @@ -3616,10 +3639,11 @@ | ||
| 3616 | 3639 | |
| 3617 | 3640 | /* |
| 3618 | 3641 | ** CAPI3REF: Binding Values To Prepared Statements |
| 3619 | 3642 | ** KEYWORDS: {host parameter} {host parameters} {host parameter name} |
| 3620 | 3643 | ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} |
| 3644 | +** METHOD: sqlite3_stmt | |
| 3621 | 3645 | ** |
| 3622 | 3646 | ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, |
| 3623 | 3647 | ** literals may be replaced by a [parameter] that matches one of following |
| 3624 | 3648 | ** templates: |
| 3625 | 3649 | ** |
| @@ -3734,10 +3758,11 @@ | ||
| 3734 | 3758 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); |
| 3735 | 3759 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
| 3736 | 3760 | |
| 3737 | 3761 | /* |
| 3738 | 3762 | ** CAPI3REF: Number Of SQL Parameters |
| 3763 | +** METHOD: sqlite3_stmt | |
| 3739 | 3764 | ** |
| 3740 | 3765 | ** ^This routine can be used to find the number of [SQL parameters] |
| 3741 | 3766 | ** in a [prepared statement]. SQL parameters are tokens of the |
| 3742 | 3767 | ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as |
| 3743 | 3768 | ** placeholders for values that are [sqlite3_bind_blob | bound] |
| @@ -3754,10 +3779,11 @@ | ||
| 3754 | 3779 | */ |
| 3755 | 3780 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*); |
| 3756 | 3781 | |
| 3757 | 3782 | /* |
| 3758 | 3783 | ** CAPI3REF: Name Of A Host Parameter |
| 3784 | +** METHOD: sqlite3_stmt | |
| 3759 | 3785 | ** |
| 3760 | 3786 | ** ^The sqlite3_bind_parameter_name(P,N) interface returns |
| 3761 | 3787 | ** the name of the N-th [SQL parameter] in the [prepared statement] P. |
| 3762 | 3788 | ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| 3763 | 3789 | ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| @@ -3781,10 +3807,11 @@ | ||
| 3781 | 3807 | */ |
| 3782 | 3808 | SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int); |
| 3783 | 3809 | |
| 3784 | 3810 | /* |
| 3785 | 3811 | ** CAPI3REF: Index Of A Parameter With A Given Name |
| 3812 | +** METHOD: sqlite3_stmt | |
| 3786 | 3813 | ** |
| 3787 | 3814 | ** ^Return the index of an SQL parameter given its name. ^The |
| 3788 | 3815 | ** index value returned is suitable for use as the second |
| 3789 | 3816 | ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero |
| 3790 | 3817 | ** is returned if no matching parameter is found. ^The parameter |
| @@ -3797,19 +3824,21 @@ | ||
| 3797 | 3824 | */ |
| 3798 | 3825 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3799 | 3826 | |
| 3800 | 3827 | /* |
| 3801 | 3828 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| 3829 | +** METHOD: sqlite3_stmt | |
| 3802 | 3830 | ** |
| 3803 | 3831 | ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset |
| 3804 | 3832 | ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. |
| 3805 | 3833 | ** ^Use this routine to reset all host parameters to NULL. |
| 3806 | 3834 | */ |
| 3807 | 3835 | SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*); |
| 3808 | 3836 | |
| 3809 | 3837 | /* |
| 3810 | 3838 | ** CAPI3REF: Number Of Columns In A Result Set |
| 3839 | +** METHOD: sqlite3_stmt | |
| 3811 | 3840 | ** |
| 3812 | 3841 | ** ^Return the number of columns in the result set returned by the |
| 3813 | 3842 | ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL |
| 3814 | 3843 | ** statement that does not return data (for example an [UPDATE]). |
| 3815 | 3844 | ** |
| @@ -3817,10 +3846,11 @@ | ||
| 3817 | 3846 | */ |
| 3818 | 3847 | SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt); |
| 3819 | 3848 | |
| 3820 | 3849 | /* |
| 3821 | 3850 | ** CAPI3REF: Column Names In A Result Set |
| 3851 | +** METHOD: sqlite3_stmt | |
| 3822 | 3852 | ** |
| 3823 | 3853 | ** ^These routines return the name assigned to a particular column |
| 3824 | 3854 | ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() |
| 3825 | 3855 | ** interface returns a pointer to a zero-terminated UTF-8 string |
| 3826 | 3856 | ** and sqlite3_column_name16() returns a pointer to a zero-terminated |
| @@ -3846,10 +3876,11 @@ | ||
| 3846 | 3876 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N); |
| 3847 | 3877 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N); |
| 3848 | 3878 | |
| 3849 | 3879 | /* |
| 3850 | 3880 | ** CAPI3REF: Source Of Data In A Query Result |
| 3881 | +** METHOD: sqlite3_stmt | |
| 3851 | 3882 | ** |
| 3852 | 3883 | ** ^These routines provide a means to determine the database, table, and |
| 3853 | 3884 | ** table column that is the origin of a particular result column in |
| 3854 | 3885 | ** [SELECT] statement. |
| 3855 | 3886 | ** ^The name of the database or table or column can be returned as |
| @@ -3898,10 +3929,11 @@ | ||
| 3898 | 3929 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int); |
| 3899 | 3930 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int); |
| 3900 | 3931 | |
| 3901 | 3932 | /* |
| 3902 | 3933 | ** CAPI3REF: Declared Datatype Of A Query Result |
| 3934 | +** METHOD: sqlite3_stmt | |
| 3903 | 3935 | ** |
| 3904 | 3936 | ** ^(The first parameter is a [prepared statement]. |
| 3905 | 3937 | ** If this statement is a [SELECT] statement and the Nth column of the |
| 3906 | 3938 | ** returned result set of that [SELECT] is a table column (not an |
| 3907 | 3939 | ** expression or subquery) then the declared type of the table |
| @@ -3930,10 +3962,11 @@ | ||
| 3930 | 3962 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int); |
| 3931 | 3963 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int); |
| 3932 | 3964 | |
| 3933 | 3965 | /* |
| 3934 | 3966 | ** CAPI3REF: Evaluate An SQL Statement |
| 3967 | +** METHOD: sqlite3_stmt | |
| 3935 | 3968 | ** |
| 3936 | 3969 | ** After a [prepared statement] has been prepared using either |
| 3937 | 3970 | ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy |
| 3938 | 3971 | ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function |
| 3939 | 3972 | ** must be called one or more times to evaluate the statement. |
| @@ -4009,10 +4042,11 @@ | ||
| 4009 | 4042 | */ |
| 4010 | 4043 | SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*); |
| 4011 | 4044 | |
| 4012 | 4045 | /* |
| 4013 | 4046 | ** CAPI3REF: Number of columns in a result set |
| 4047 | +** METHOD: sqlite3_stmt | |
| 4014 | 4048 | ** |
| 4015 | 4049 | ** ^The sqlite3_data_count(P) interface returns the number of columns in the |
| 4016 | 4050 | ** current row of the result set of [prepared statement] P. |
| 4017 | 4051 | ** ^If prepared statement P does not have results ready to return |
| 4018 | 4052 | ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of |
| @@ -4062,10 +4096,11 @@ | ||
| 4062 | 4096 | #define SQLITE3_TEXT 3 |
| 4063 | 4097 | |
| 4064 | 4098 | /* |
| 4065 | 4099 | ** CAPI3REF: Result Values From A Query |
| 4066 | 4100 | ** KEYWORDS: {column access functions} |
| 4101 | +** METHOD: sqlite3_stmt | |
| 4067 | 4102 | ** |
| 4068 | 4103 | ** These routines form the "result set" interface. |
| 4069 | 4104 | ** |
| 4070 | 4105 | ** ^These routines return information about a single column of the current |
| 4071 | 4106 | ** result row of a query. ^In every case the first argument is a pointer |
| @@ -4234,10 +4269,11 @@ | ||
| 4234 | 4269 | SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol); |
| 4235 | 4270 | SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol); |
| 4236 | 4271 | |
| 4237 | 4272 | /* |
| 4238 | 4273 | ** CAPI3REF: Destroy A Prepared Statement Object |
| 4274 | +** DESTRUCTOR: sqlite3_stmt | |
| 4239 | 4275 | ** |
| 4240 | 4276 | ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. |
| 4241 | 4277 | ** ^If the most recent evaluation of the statement encountered no errors |
| 4242 | 4278 | ** or if the statement is never been evaluated, then sqlite3_finalize() returns |
| 4243 | 4279 | ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then |
| @@ -4261,10 +4297,11 @@ | ||
| 4261 | 4297 | */ |
| 4262 | 4298 | SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt); |
| 4263 | 4299 | |
| 4264 | 4300 | /* |
| 4265 | 4301 | ** CAPI3REF: Reset A Prepared Statement Object |
| 4302 | +** METHOD: sqlite3_stmt | |
| 4266 | 4303 | ** |
| 4267 | 4304 | ** The sqlite3_reset() function is called to reset a [prepared statement] |
| 4268 | 4305 | ** object back to its initial state, ready to be re-executed. |
| 4269 | 4306 | ** ^Any SQL statement variables that had values bound to them using |
| 4270 | 4307 | ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. |
| @@ -4290,10 +4327,11 @@ | ||
| 4290 | 4327 | /* |
| 4291 | 4328 | ** CAPI3REF: Create Or Redefine SQL Functions |
| 4292 | 4329 | ** KEYWORDS: {function creation routines} |
| 4293 | 4330 | ** KEYWORDS: {application-defined SQL function} |
| 4294 | 4331 | ** KEYWORDS: {application-defined SQL functions} |
| 4332 | +** METHOD: sqlite3 | |
| 4295 | 4333 | ** |
| 4296 | 4334 | ** ^These functions (collectively known as "function creation routines") |
| 4297 | 4335 | ** are used to add SQL functions or aggregates or to redefine the behavior |
| 4298 | 4336 | ** of existing SQL functions or aggregates. The only differences between |
| 4299 | 4337 | ** these routines are the text encoding expected for |
| @@ -4459,10 +4497,11 @@ | ||
| 4459 | 4497 | void*,sqlite3_int64); |
| 4460 | 4498 | #endif |
| 4461 | 4499 | |
| 4462 | 4500 | /* |
| 4463 | 4501 | ** CAPI3REF: Obtaining SQL Function Parameter Values |
| 4502 | +** METHOD: sqlite3_value | |
| 4464 | 4503 | ** |
| 4465 | 4504 | ** The C-language implementation of SQL functions and aggregates uses |
| 4466 | 4505 | ** this set of interface routines to access the parameter values on |
| 4467 | 4506 | ** the function or aggregate. |
| 4468 | 4507 | ** |
| @@ -4517,10 +4556,11 @@ | ||
| 4517 | 4556 | SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*); |
| 4518 | 4557 | SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*); |
| 4519 | 4558 | |
| 4520 | 4559 | /* |
| 4521 | 4560 | ** CAPI3REF: Obtain Aggregate Function Context |
| 4561 | +** METHOD: sqlite3_context | |
| 4522 | 4562 | ** |
| 4523 | 4563 | ** Implementations of aggregate SQL functions use this |
| 4524 | 4564 | ** routine to allocate memory for storing their state. |
| 4525 | 4565 | ** |
| 4526 | 4566 | ** ^The first time the sqlite3_aggregate_context(C,N) routine is called |
| @@ -4561,10 +4601,11 @@ | ||
| 4561 | 4601 | */ |
| 4562 | 4602 | SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes); |
| 4563 | 4603 | |
| 4564 | 4604 | /* |
| 4565 | 4605 | ** CAPI3REF: User Data For Functions |
| 4606 | +** METHOD: sqlite3_context | |
| 4566 | 4607 | ** |
| 4567 | 4608 | ** ^The sqlite3_user_data() interface returns a copy of |
| 4568 | 4609 | ** the pointer that was the pUserData parameter (the 5th parameter) |
| 4569 | 4610 | ** of the [sqlite3_create_function()] |
| 4570 | 4611 | ** and [sqlite3_create_function16()] routines that originally |
| @@ -4575,10 +4616,11 @@ | ||
| 4575 | 4616 | */ |
| 4576 | 4617 | SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*); |
| 4577 | 4618 | |
| 4578 | 4619 | /* |
| 4579 | 4620 | ** CAPI3REF: Database Connection For Functions |
| 4621 | +** METHOD: sqlite3_context | |
| 4580 | 4622 | ** |
| 4581 | 4623 | ** ^The sqlite3_context_db_handle() interface returns a copy of |
| 4582 | 4624 | ** the pointer to the [database connection] (the 1st parameter) |
| 4583 | 4625 | ** of the [sqlite3_create_function()] |
| 4584 | 4626 | ** and [sqlite3_create_function16()] routines that originally |
| @@ -4586,10 +4628,11 @@ | ||
| 4586 | 4628 | */ |
| 4587 | 4629 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*); |
| 4588 | 4630 | |
| 4589 | 4631 | /* |
| 4590 | 4632 | ** CAPI3REF: Function Auxiliary Data |
| 4633 | +** METHOD: sqlite3_context | |
| 4591 | 4634 | ** |
| 4592 | 4635 | ** These functions may be used by (non-aggregate) SQL functions to |
| 4593 | 4636 | ** associate metadata with argument values. If the same value is passed to |
| 4594 | 4637 | ** multiple invocations of the same SQL function during query execution, under |
| 4595 | 4638 | ** some circumstances the associated metadata may be preserved. An example |
| @@ -4658,10 +4701,11 @@ | ||
| 4658 | 4701 | #define SQLITE_STATIC ((sqlite3_destructor_type)0) |
| 4659 | 4702 | #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) |
| 4660 | 4703 | |
| 4661 | 4704 | /* |
| 4662 | 4705 | ** CAPI3REF: Setting The Result Of An SQL Function |
| 4706 | +** METHOD: sqlite3_context | |
| 4663 | 4707 | ** |
| 4664 | 4708 | ** These routines are used by the xFunc or xFinal callbacks that |
| 4665 | 4709 | ** implement SQL functions and aggregates. See |
| 4666 | 4710 | ** [sqlite3_create_function()] and [sqlite3_create_function16()] |
| 4667 | 4711 | ** for additional information. |
| @@ -4793,10 +4837,11 @@ | ||
| 4793 | 4837 | SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*); |
| 4794 | 4838 | SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n); |
| 4795 | 4839 | |
| 4796 | 4840 | /* |
| 4797 | 4841 | ** CAPI3REF: Define New Collating Sequences |
| 4842 | +** METHOD: sqlite3 | |
| 4798 | 4843 | ** |
| 4799 | 4844 | ** ^These functions add, remove, or modify a [collation] associated |
| 4800 | 4845 | ** with the [database connection] specified as the first argument. |
| 4801 | 4846 | ** |
| 4802 | 4847 | ** ^The name of the collation is a UTF-8 string |
| @@ -4895,10 +4940,11 @@ | ||
| 4895 | 4940 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 4896 | 4941 | ); |
| 4897 | 4942 | |
| 4898 | 4943 | /* |
| 4899 | 4944 | ** CAPI3REF: Collation Needed Callbacks |
| 4945 | +** METHOD: sqlite3 | |
| 4900 | 4946 | ** |
| 4901 | 4947 | ** ^To avoid having to register all collation sequences before a database |
| 4902 | 4948 | ** can be used, a single callback function may be registered with the |
| 4903 | 4949 | ** [database connection] to be invoked whenever an undefined collation |
| 4904 | 4950 | ** sequence is required. |
| @@ -5102,10 +5148,11 @@ | ||
| 5102 | 5148 | SQLITE_API char *sqlite3_data_directory; |
| 5103 | 5149 | |
| 5104 | 5150 | /* |
| 5105 | 5151 | ** CAPI3REF: Test For Auto-Commit Mode |
| 5106 | 5152 | ** KEYWORDS: {autocommit mode} |
| 5153 | +** METHOD: sqlite3 | |
| 5107 | 5154 | ** |
| 5108 | 5155 | ** ^The sqlite3_get_autocommit() interface returns non-zero or |
| 5109 | 5156 | ** zero if the given database connection is or is not in autocommit mode, |
| 5110 | 5157 | ** respectively. ^Autocommit mode is on by default. |
| 5111 | 5158 | ** ^Autocommit mode is disabled by a [BEGIN] statement. |
| @@ -5124,10 +5171,11 @@ | ||
| 5124 | 5171 | */ |
| 5125 | 5172 | SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*); |
| 5126 | 5173 | |
| 5127 | 5174 | /* |
| 5128 | 5175 | ** CAPI3REF: Find The Database Handle Of A Prepared Statement |
| 5176 | +** METHOD: sqlite3_stmt | |
| 5129 | 5177 | ** |
| 5130 | 5178 | ** ^The sqlite3_db_handle interface returns the [database connection] handle |
| 5131 | 5179 | ** to which a [prepared statement] belongs. ^The [database connection] |
| 5132 | 5180 | ** returned by sqlite3_db_handle is the same [database connection] |
| 5133 | 5181 | ** that was the first argument |
| @@ -5136,10 +5184,11 @@ | ||
| 5136 | 5184 | */ |
| 5137 | 5185 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*); |
| 5138 | 5186 | |
| 5139 | 5187 | /* |
| 5140 | 5188 | ** CAPI3REF: Return The Filename For A Database Connection |
| 5189 | +** METHOD: sqlite3 | |
| 5141 | 5190 | ** |
| 5142 | 5191 | ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename |
| 5143 | 5192 | ** associated with database N of connection D. ^The main database file |
| 5144 | 5193 | ** has the name "main". If there is no attached database N on the database |
| 5145 | 5194 | ** connection D, or if database N is a temporary or in-memory database, then |
| @@ -5152,19 +5201,21 @@ | ||
| 5152 | 5201 | */ |
| 5153 | 5202 | SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
| 5154 | 5203 | |
| 5155 | 5204 | /* |
| 5156 | 5205 | ** CAPI3REF: Determine if a database is read-only |
| 5206 | +** METHOD: sqlite3 | |
| 5157 | 5207 | ** |
| 5158 | 5208 | ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N |
| 5159 | 5209 | ** of connection D is read-only, 0 if it is read/write, or -1 if N is not |
| 5160 | 5210 | ** the name of a database on connection D. |
| 5161 | 5211 | */ |
| 5162 | 5212 | SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName); |
| 5163 | 5213 | |
| 5164 | 5214 | /* |
| 5165 | 5215 | ** CAPI3REF: Find the next prepared statement |
| 5216 | +** METHOD: sqlite3 | |
| 5166 | 5217 | ** |
| 5167 | 5218 | ** ^This interface returns a pointer to the next [prepared statement] after |
| 5168 | 5219 | ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL |
| 5169 | 5220 | ** then this interface returns a pointer to the first prepared statement |
| 5170 | 5221 | ** associated with the database connection pDb. ^If no prepared statement |
| @@ -5176,10 +5227,11 @@ | ||
| 5176 | 5227 | */ |
| 5177 | 5228 | SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); |
| 5178 | 5229 | |
| 5179 | 5230 | /* |
| 5180 | 5231 | ** CAPI3REF: Commit And Rollback Notification Callbacks |
| 5232 | +** METHOD: sqlite3 | |
| 5181 | 5233 | ** |
| 5182 | 5234 | ** ^The sqlite3_commit_hook() interface registers a callback |
| 5183 | 5235 | ** function to be invoked whenever a transaction is [COMMIT | committed]. |
| 5184 | 5236 | ** ^Any callback set by a previous call to sqlite3_commit_hook() |
| 5185 | 5237 | ** for the same database connection is overridden. |
| @@ -5225,10 +5277,11 @@ | ||
| 5225 | 5277 | SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); |
| 5226 | 5278 | SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); |
| 5227 | 5279 | |
| 5228 | 5280 | /* |
| 5229 | 5281 | ** CAPI3REF: Data Change Notification Callbacks |
| 5282 | +** METHOD: sqlite3 | |
| 5230 | 5283 | ** |
| 5231 | 5284 | ** ^The sqlite3_update_hook() interface registers a callback function |
| 5232 | 5285 | ** with the [database connection] identified by the first argument |
| 5233 | 5286 | ** to be invoked whenever a row is updated, inserted or deleted in |
| 5234 | 5287 | ** a rowid table. |
| @@ -5331,10 +5384,11 @@ | ||
| 5331 | 5384 | */ |
| 5332 | 5385 | SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int); |
| 5333 | 5386 | |
| 5334 | 5387 | /* |
| 5335 | 5388 | ** CAPI3REF: Free Memory Used By A Database Connection |
| 5389 | +** METHOD: sqlite3 | |
| 5336 | 5390 | ** |
| 5337 | 5391 | ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap |
| 5338 | 5392 | ** memory as possible from database connection D. Unlike the |
| 5339 | 5393 | ** [sqlite3_release_memory()] interface, this interface is in effect even |
| 5340 | 5394 | ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is |
| @@ -5408,10 +5462,11 @@ | ||
| 5408 | 5462 | SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N); |
| 5409 | 5463 | |
| 5410 | 5464 | |
| 5411 | 5465 | /* |
| 5412 | 5466 | ** CAPI3REF: Extract Metadata About A Column Of A Table |
| 5467 | +** METHOD: sqlite3 | |
| 5413 | 5468 | ** |
| 5414 | 5469 | ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns |
| 5415 | 5470 | ** information about column C of table T in database D |
| 5416 | 5471 | ** on [database connection] X.)^ ^The sqlite3_table_column_metadata() |
| 5417 | 5472 | ** interface returns SQLITE_OK and fills in the non-NULL pointers in |
| @@ -5486,10 +5541,11 @@ | ||
| 5486 | 5541 | int *pAutoinc /* OUTPUT: True if column is auto-increment */ |
| 5487 | 5542 | ); |
| 5488 | 5543 | |
| 5489 | 5544 | /* |
| 5490 | 5545 | ** CAPI3REF: Load An Extension |
| 5546 | +** METHOD: sqlite3 | |
| 5491 | 5547 | ** |
| 5492 | 5548 | ** ^This interface loads an SQLite extension library from the named file. |
| 5493 | 5549 | ** |
| 5494 | 5550 | ** ^The sqlite3_load_extension() interface attempts to load an |
| 5495 | 5551 | ** [SQLite extension] library contained in the file zFile. If |
| @@ -5527,10 +5583,11 @@ | ||
| 5527 | 5583 | char **pzErrMsg /* Put error message here if not 0 */ |
| 5528 | 5584 | ); |
| 5529 | 5585 | |
| 5530 | 5586 | /* |
| 5531 | 5587 | ** CAPI3REF: Enable Or Disable Extension Loading |
| 5588 | +** METHOD: sqlite3 | |
| 5532 | 5589 | ** |
| 5533 | 5590 | ** ^So as not to open security holes in older applications that are |
| 5534 | 5591 | ** unprepared to deal with [extension loading], and as a means of disabling |
| 5535 | 5592 | ** [extension loading] while evaluating user-entered SQL, the following API |
| 5536 | 5593 | ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. |
| @@ -5776,10 +5833,11 @@ | ||
| 5776 | 5833 | #define SQLITE_INDEX_CONSTRAINT_GE 32 |
| 5777 | 5834 | #define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
| 5778 | 5835 | |
| 5779 | 5836 | /* |
| 5780 | 5837 | ** CAPI3REF: Register A Virtual Table Implementation |
| 5838 | +** METHOD: sqlite3 | |
| 5781 | 5839 | ** |
| 5782 | 5840 | ** ^These routines are used to register a new [virtual table module] name. |
| 5783 | 5841 | ** ^Module names must be registered before |
| 5784 | 5842 | ** creating a new [virtual table] using the module and before using a |
| 5785 | 5843 | ** preexisting [virtual table] for the module. |
| @@ -5872,10 +5930,11 @@ | ||
| 5872 | 5930 | */ |
| 5873 | 5931 | SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL); |
| 5874 | 5932 | |
| 5875 | 5933 | /* |
| 5876 | 5934 | ** CAPI3REF: Overload A Function For A Virtual Table |
| 5935 | +** METHOD: sqlite3 | |
| 5877 | 5936 | ** |
| 5878 | 5937 | ** ^(Virtual tables can provide alternative implementations of functions |
| 5879 | 5938 | ** using the [xFindFunction] method of the [virtual table module]. |
| 5880 | 5939 | ** But global versions of those functions |
| 5881 | 5940 | ** must exist in order to be overloaded.)^ |
| @@ -5914,10 +5973,12 @@ | ||
| 5914 | 5973 | */ |
| 5915 | 5974 | typedef struct sqlite3_blob sqlite3_blob; |
| 5916 | 5975 | |
| 5917 | 5976 | /* |
| 5918 | 5977 | ** CAPI3REF: Open A BLOB For Incremental I/O |
| 5978 | +** METHOD: sqlite3 | |
| 5979 | +** CONSTRUCTOR: sqlite3_blob | |
| 5919 | 5980 | ** |
| 5920 | 5981 | ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located |
| 5921 | 5982 | ** in row iRow, column zColumn, table zTable in database zDb; |
| 5922 | 5983 | ** in other words, the same BLOB that would be selected by: |
| 5923 | 5984 | ** |
| @@ -5995,10 +6056,11 @@ | ||
| 5995 | 6056 | sqlite3_blob **ppBlob |
| 5996 | 6057 | ); |
| 5997 | 6058 | |
| 5998 | 6059 | /* |
| 5999 | 6060 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 6061 | +** METHOD: sqlite3_blob | |
| 6000 | 6062 | ** |
| 6001 | 6063 | ** ^This function is used to move an existing blob handle so that it points |
| 6002 | 6064 | ** to a different row of the same database table. ^The new row is identified |
| 6003 | 6065 | ** by the rowid value passed as the second argument. Only the row can be |
| 6004 | 6066 | ** changed. ^The database, table and column on which the blob handle is open |
| @@ -6019,10 +6081,11 @@ | ||
| 6019 | 6081 | */ |
| 6020 | 6082 | SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 6021 | 6083 | |
| 6022 | 6084 | /* |
| 6023 | 6085 | ** CAPI3REF: Close A BLOB Handle |
| 6086 | +** DESTRUCTOR: sqlite3_blob | |
| 6024 | 6087 | ** |
| 6025 | 6088 | ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed |
| 6026 | 6089 | ** unconditionally. Even if this routine returns an error code, the |
| 6027 | 6090 | ** handle is still closed.)^ |
| 6028 | 6091 | ** |
| @@ -6041,10 +6104,11 @@ | ||
| 6041 | 6104 | */ |
| 6042 | 6105 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *); |
| 6043 | 6106 | |
| 6044 | 6107 | /* |
| 6045 | 6108 | ** CAPI3REF: Return The Size Of An Open BLOB |
| 6109 | +** METHOD: sqlite3_blob | |
| 6046 | 6110 | ** |
| 6047 | 6111 | ** ^Returns the size in bytes of the BLOB accessible via the |
| 6048 | 6112 | ** successfully opened [BLOB handle] in its only argument. ^The |
| 6049 | 6113 | ** incremental blob I/O routines can only read or overwriting existing |
| 6050 | 6114 | ** blob content; they cannot change the size of a blob. |
| @@ -6056,10 +6120,11 @@ | ||
| 6056 | 6120 | */ |
| 6057 | 6121 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *); |
| 6058 | 6122 | |
| 6059 | 6123 | /* |
| 6060 | 6124 | ** CAPI3REF: Read Data From A BLOB Incrementally |
| 6125 | +** METHOD: sqlite3_blob | |
| 6061 | 6126 | ** |
| 6062 | 6127 | ** ^(This function is used to read data from an open [BLOB handle] into a |
| 6063 | 6128 | ** caller-supplied buffer. N bytes of data are copied into buffer Z |
| 6064 | 6129 | ** from the open BLOB, starting at offset iOffset.)^ |
| 6065 | 6130 | ** |
| @@ -6084,10 +6149,11 @@ | ||
| 6084 | 6149 | */ |
| 6085 | 6150 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 6086 | 6151 | |
| 6087 | 6152 | /* |
| 6088 | 6153 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 6154 | +** METHOD: sqlite3_blob | |
| 6089 | 6155 | ** |
| 6090 | 6156 | ** ^(This function is used to write data into an open [BLOB handle] from a |
| 6091 | 6157 | ** caller-supplied buffer. N bytes of data are copied from the buffer Z |
| 6092 | 6158 | ** into the open BLOB, starting at offset iOffset.)^ |
| 6093 | 6159 | ** |
| @@ -6411,10 +6477,11 @@ | ||
| 6411 | 6477 | #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ |
| 6412 | 6478 | #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ |
| 6413 | 6479 | |
| 6414 | 6480 | /* |
| 6415 | 6481 | ** CAPI3REF: Retrieve the mutex for a database connection |
| 6482 | +** METHOD: sqlite3 | |
| 6416 | 6483 | ** |
| 6417 | 6484 | ** ^This interface returns a pointer the [sqlite3_mutex] object that |
| 6418 | 6485 | ** serializes access to the [database connection] given in the argument |
| 6419 | 6486 | ** when the [threading mode] is Serialized. |
| 6420 | 6487 | ** ^If the [threading mode] is Single-thread or Multi-thread then this |
| @@ -6422,10 +6489,11 @@ | ||
| 6422 | 6489 | */ |
| 6423 | 6490 | SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*); |
| 6424 | 6491 | |
| 6425 | 6492 | /* |
| 6426 | 6493 | ** CAPI3REF: Low-Level Control Of Database Files |
| 6494 | +** METHOD: sqlite3 | |
| 6427 | 6495 | ** |
| 6428 | 6496 | ** ^The [sqlite3_file_control()] interface makes a direct call to the |
| 6429 | 6497 | ** xFileControl method for the [sqlite3_io_methods] object associated |
| 6430 | 6498 | ** with a particular database identified by the second argument. ^The |
| 6431 | 6499 | ** name of the database is "main" for the main database or "temp" for the |
| @@ -6638,10 +6706,11 @@ | ||
| 6638 | 6706 | #define SQLITE_STATUS_SCRATCH_SIZE 8 |
| 6639 | 6707 | #define SQLITE_STATUS_MALLOC_COUNT 9 |
| 6640 | 6708 | |
| 6641 | 6709 | /* |
| 6642 | 6710 | ** CAPI3REF: Database Connection Status |
| 6711 | +** METHOD: sqlite3 | |
| 6643 | 6712 | ** |
| 6644 | 6713 | ** ^This interface is used to retrieve runtime status information |
| 6645 | 6714 | ** about a single [database connection]. ^The first argument is the |
| 6646 | 6715 | ** database connection object to be interrogated. ^The second argument |
| 6647 | 6716 | ** is an integer constant, taken from the set of |
| @@ -6766,10 +6835,11 @@ | ||
| 6766 | 6835 | #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */ |
| 6767 | 6836 | |
| 6768 | 6837 | |
| 6769 | 6838 | /* |
| 6770 | 6839 | ** CAPI3REF: Prepared Statement Status |
| 6840 | +** METHOD: sqlite3_stmt | |
| 6771 | 6841 | ** |
| 6772 | 6842 | ** ^(Each prepared statement maintains various |
| 6773 | 6843 | ** [SQLITE_STMTSTATUS counters] that measure the number |
| 6774 | 6844 | ** of times it has performed specific operations.)^ These counters can |
| 6775 | 6845 | ** be used to monitor the performance characteristics of the prepared |
| @@ -7269,10 +7339,11 @@ | ||
| 7269 | 7339 | SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p); |
| 7270 | 7340 | SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p); |
| 7271 | 7341 | |
| 7272 | 7342 | /* |
| 7273 | 7343 | ** CAPI3REF: Unlock Notification |
| 7344 | +** METHOD: sqlite3 | |
| 7274 | 7345 | ** |
| 7275 | 7346 | ** ^When running in shared-cache mode, a database operation may fail with |
| 7276 | 7347 | ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or |
| 7277 | 7348 | ** individual tables within the shared-cache cannot be obtained. See |
| 7278 | 7349 | ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. |
| @@ -7439,10 +7510,11 @@ | ||
| 7439 | 7510 | */ |
| 7440 | 7511 | SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...); |
| 7441 | 7512 | |
| 7442 | 7513 | /* |
| 7443 | 7514 | ** CAPI3REF: Write-Ahead Log Commit Hook |
| 7515 | +** METHOD: sqlite3 | |
| 7444 | 7516 | ** |
| 7445 | 7517 | ** ^The [sqlite3_wal_hook()] function is used to register a callback that |
| 7446 | 7518 | ** is invoked each time data is committed to a database in wal mode. |
| 7447 | 7519 | ** |
| 7448 | 7520 | ** ^(The callback is invoked by SQLite after the commit has taken place and |
| @@ -7478,10 +7550,11 @@ | ||
| 7478 | 7550 | void* |
| 7479 | 7551 | ); |
| 7480 | 7552 | |
| 7481 | 7553 | /* |
| 7482 | 7554 | ** CAPI3REF: Configure an auto-checkpoint |
| 7555 | +** METHOD: sqlite3 | |
| 7483 | 7556 | ** |
| 7484 | 7557 | ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around |
| 7485 | 7558 | ** [sqlite3_wal_hook()] that causes any database on [database connection] D |
| 7486 | 7559 | ** to automatically [checkpoint] |
| 7487 | 7560 | ** after committing a transaction if there are N or |
| @@ -7508,10 +7581,11 @@ | ||
| 7508 | 7581 | */ |
| 7509 | 7582 | SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7510 | 7583 | |
| 7511 | 7584 | /* |
| 7512 | 7585 | ** CAPI3REF: Checkpoint a database |
| 7586 | +** METHOD: sqlite3 | |
| 7513 | 7587 | ** |
| 7514 | 7588 | ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to |
| 7515 | 7589 | ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ |
| 7516 | 7590 | ** |
| 7517 | 7591 | ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the |
| @@ -7529,10 +7603,11 @@ | ||
| 7529 | 7603 | */ |
| 7530 | 7604 | SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7531 | 7605 | |
| 7532 | 7606 | /* |
| 7533 | 7607 | ** CAPI3REF: Checkpoint a database |
| 7608 | +** METHOD: sqlite3 | |
| 7534 | 7609 | ** |
| 7535 | 7610 | ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint |
| 7536 | 7611 | ** operation on database X of [database connection] D in mode M. Status |
| 7537 | 7612 | ** information is written back into integers pointed to by L and C.)^ |
| 7538 | 7613 | ** ^(The M parameter must be a valid [checkpoint mode]:)^ |
| @@ -7783,10 +7858,11 @@ | ||
| 7783 | 7858 | #define SQLITE_SCANSTAT_EXPLAIN 4 |
| 7784 | 7859 | #define SQLITE_SCANSTAT_SELECTID 5 |
| 7785 | 7860 | |
| 7786 | 7861 | /* |
| 7787 | 7862 | ** CAPI3REF: Prepared Statement Scan Status |
| 7863 | +** METHOD: sqlite3_stmt | |
| 7788 | 7864 | ** |
| 7789 | 7865 | ** This interface returns information about the predicted and measured |
| 7790 | 7866 | ** performance for pStmt. Advanced applications can use this |
| 7791 | 7867 | ** interface to compare the predicted and the measured performance and |
| 7792 | 7868 | ** issue warnings and/or rerun [ANALYZE] if discrepancies are found. |
| @@ -7820,10 +7896,11 @@ | ||
| 7820 | 7896 | void *pOut /* Result written here */ |
| 7821 | 7897 | ); |
| 7822 | 7898 | |
| 7823 | 7899 | /* |
| 7824 | 7900 | ** CAPI3REF: Zero Scan-Status Counters |
| 7901 | +** METHOD: sqlite3_stmt | |
| 7825 | 7902 | ** |
| 7826 | 7903 | ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. |
| 7827 | 7904 | ** |
| 7828 | 7905 | ** This API is only available if the library is built with pre-processor |
| 7829 | 7906 | ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| @@ -8430,10 +8507,36 @@ | ||
| 8430 | 8507 | #else |
| 8431 | 8508 | # define ALWAYS(X) (X) |
| 8432 | 8509 | # define NEVER(X) (X) |
| 8433 | 8510 | #endif |
| 8434 | 8511 | |
| 8512 | +/* | |
| 8513 | +** Declarations used for tracing the operating system interfaces. | |
| 8514 | +*/ | |
| 8515 | +#if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \ | |
| 8516 | + (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) | |
| 8517 | + extern int sqlite3OSTrace; | |
| 8518 | +# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X | |
| 8519 | +# define SQLITE_HAVE_OS_TRACE | |
| 8520 | +#else | |
| 8521 | +# define OSTRACE(X) | |
| 8522 | +# undef SQLITE_HAVE_OS_TRACE | |
| 8523 | +#endif | |
| 8524 | + | |
| 8525 | +/* | |
| 8526 | +** Is the sqlite3ErrName() function needed in the build? Currently, | |
| 8527 | +** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when | |
| 8528 | +** OSTRACE is enabled), and by several "test*.c" files (which are | |
| 8529 | +** compiled using SQLITE_TEST). | |
| 8530 | +*/ | |
| 8531 | +#if defined(SQLITE_HAVE_OS_TRACE) || defined(SQLITE_TEST) || \ | |
| 8532 | + (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) | |
| 8533 | +# define SQLITE_NEED_ERR_NAME | |
| 8534 | +#else | |
| 8535 | +# undef SQLITE_NEED_ERR_NAME | |
| 8536 | +#endif | |
| 8537 | + | |
| 8435 | 8538 | /* |
| 8436 | 8539 | ** Return true (non-zero) if the input is an integer that is too large |
| 8437 | 8540 | ** to fit in 32-bits. This macro is used inside of various testcase() |
| 8438 | 8541 | ** macros to verify that we have tested SQLite for large-file support. |
| 8439 | 8542 | */ |
| @@ -9841,37 +9944,36 @@ | ||
| 9841 | 9944 | /* Properties such as "out2" or "jump" that are specified in |
| 9842 | 9945 | ** comments following the "case" for each opcode in the vdbe.c |
| 9843 | 9946 | ** are encoded into bitvectors as follows: |
| 9844 | 9947 | */ |
| 9845 | 9948 | #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */ |
| 9846 | -#define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */ | |
| 9847 | -#define OPFLG_IN1 0x0004 /* in1: P1 is an input */ | |
| 9848 | -#define OPFLG_IN2 0x0008 /* in2: P2 is an input */ | |
| 9849 | -#define OPFLG_IN3 0x0010 /* in3: P3 is an input */ | |
| 9850 | -#define OPFLG_OUT2 0x0020 /* out2: P2 is an output */ | |
| 9851 | -#define OPFLG_OUT3 0x0040 /* out3: P3 is an output */ | |
| 9949 | +#define OPFLG_IN1 0x0002 /* in1: P1 is an input */ | |
| 9950 | +#define OPFLG_IN2 0x0004 /* in2: P2 is an input */ | |
| 9951 | +#define OPFLG_IN3 0x0008 /* in3: P3 is an input */ | |
| 9952 | +#define OPFLG_OUT2 0x0010 /* out2: P2 is an output */ | |
| 9953 | +#define OPFLG_OUT3 0x0020 /* out3: P3 is an output */ | |
| 9852 | 9954 | #define OPFLG_INITIALIZER {\ |
| 9853 | 9955 | /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\ |
| 9854 | -/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\ | |
| 9855 | -/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\ | |
| 9856 | -/* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\ | |
| 9857 | -/* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\ | |
| 9858 | -/* 40 */ 0x04, 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00,\ | |
| 9859 | -/* 48 */ 0x00, 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00,\ | |
| 9860 | -/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,\ | |
| 9861 | -/* 64 */ 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x4c,\ | |
| 9862 | -/* 72 */ 0x4c, 0x02, 0x02, 0x00, 0x05, 0x05, 0x15, 0x15,\ | |
| 9863 | -/* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\ | |
| 9864 | -/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\ | |
| 9865 | -/* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,\ | |
| 9866 | -/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08, 0x00,\ | |
| 9867 | -/* 112 */ 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,\ | |
| 9868 | -/* 120 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ | |
| 9869 | -/* 128 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x02, 0x00, 0x01,\ | |
| 9870 | -/* 136 */ 0x08, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x01,\ | |
| 9956 | +/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\ | |
| 9957 | +/* 16 */ 0x01, 0x01, 0x02, 0x12, 0x01, 0x02, 0x03, 0x08,\ | |
| 9958 | +/* 24 */ 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10,\ | |
| 9959 | +/* 32 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x03, 0x02,\ | |
| 9960 | +/* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\ | |
| 9961 | +/* 48 */ 0x00, 0x00, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,\ | |
| 9962 | +/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09,\ | |
| 9963 | +/* 64 */ 0x09, 0x09, 0x04, 0x09, 0x09, 0x09, 0x09, 0x26,\ | |
| 9964 | +/* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\ | |
| 9965 | +/* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\ | |
| 9966 | +/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\ | |
| 9967 | +/* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\ | |
| 9968 | +/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\ | |
| 9969 | +/* 112 */ 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00, 0x00,\ | |
| 9970 | +/* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ | |
| 9971 | +/* 128 */ 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00, 0x01,\ | |
| 9972 | +/* 136 */ 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x01,\ | |
| 9871 | 9973 | /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\ |
| 9872 | -/* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,} | |
| 9974 | +/* 152 */ 0x00, 0x10, 0x10, 0x01, 0x00, 0x00,} | |
| 9873 | 9975 | |
| 9874 | 9976 | /************** End of opcodes.h *********************************************/ |
| 9875 | 9977 | /************** Continuing where we left off in vdbe.h ***********************/ |
| 9876 | 9978 | |
| 9877 | 9979 | /* |
| @@ -9926,10 +10028,11 @@ | ||
| 9926 | 10028 | #endif |
| 9927 | 10029 | SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); |
| 9928 | 10030 | |
| 9929 | 10031 | SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*); |
| 9930 | 10032 | SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*); |
| 10033 | +SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int); | |
| 9931 | 10034 | SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **); |
| 9932 | 10035 | |
| 9933 | 10036 | typedef int (*RecordCompare)(int,const void*,UnpackedRecord*); |
| 9934 | 10037 | SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*); |
| 9935 | 10038 | |
| @@ -11063,10 +11166,11 @@ | ||
| 11063 | 11166 | #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */ |
| 11064 | 11167 | #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */ |
| 11065 | 11168 | #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */ |
| 11066 | 11169 | #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */ |
| 11067 | 11170 | #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */ |
| 11171 | +#define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */ | |
| 11068 | 11172 | |
| 11069 | 11173 | |
| 11070 | 11174 | /* |
| 11071 | 11175 | ** Bits of the sqlite3.dbOptFlags field that are used by the |
| 11072 | 11176 | ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to |
| @@ -11393,38 +11497,12 @@ | ||
| 11393 | 11497 | int iSavepoint; /* Depth of the SAVEPOINT stack */ |
| 11394 | 11498 | VTable *pNext; /* Next in linked list (see above) */ |
| 11395 | 11499 | }; |
| 11396 | 11500 | |
| 11397 | 11501 | /* |
| 11398 | -** Each SQL table is represented in memory by an instance of the | |
| 11399 | -** following structure. | |
| 11400 | -** | |
| 11401 | -** Table.zName is the name of the table. The case of the original | |
| 11402 | -** CREATE TABLE statement is stored, but case is not significant for | |
| 11403 | -** comparisons. | |
| 11404 | -** | |
| 11405 | -** Table.nCol is the number of columns in this table. Table.aCol is a | |
| 11406 | -** pointer to an array of Column structures, one for each column. | |
| 11407 | -** | |
| 11408 | -** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of | |
| 11409 | -** the column that is that key. Otherwise Table.iPKey is negative. Note | |
| 11410 | -** that the datatype of the PRIMARY KEY must be INTEGER for this field to | |
| 11411 | -** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of | |
| 11412 | -** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid | |
| 11413 | -** is generated for each row of the table. TF_HasPrimaryKey is set if | |
| 11414 | -** the table has any PRIMARY KEY, INTEGER or otherwise. | |
| 11415 | -** | |
| 11416 | -** Table.tnum is the page number for the root BTree page of the table in the | |
| 11417 | -** database file. If Table.iDb is the index of the database table backend | |
| 11418 | -** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that | |
| 11419 | -** holds temporary tables and indices. If TF_Ephemeral is set | |
| 11420 | -** then the table is stored in a file that is automatically deleted | |
| 11421 | -** when the VDBE cursor to the table is closed. In this case Table.tnum | |
| 11422 | -** refers VDBE cursor number that holds the table open, not to the root | |
| 11423 | -** page number. Transient tables are used to hold the results of a | |
| 11424 | -** sub-query that appears instead of a real table name in the FROM clause | |
| 11425 | -** of a SELECT statement. | |
| 11502 | +** The schema for each SQL table and view is represented in memory | |
| 11503 | +** by an instance of the following structure. | |
| 11426 | 11504 | */ |
| 11427 | 11505 | struct Table { |
| 11428 | 11506 | char *zName; /* Name of the table or view */ |
| 11429 | 11507 | Column *aCol; /* Information about each column */ |
| 11430 | 11508 | Index *pIndex; /* List of SQL indexes on this table. */ |
| @@ -11432,15 +11510,15 @@ | ||
| 11432 | 11510 | FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| 11433 | 11511 | char *zColAff; /* String defining the affinity of each column */ |
| 11434 | 11512 | #ifndef SQLITE_OMIT_CHECK |
| 11435 | 11513 | ExprList *pCheck; /* All CHECK constraints */ |
| 11436 | 11514 | #endif |
| 11437 | - LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */ | |
| 11438 | - int tnum; /* Root BTree node for this table (see note above) */ | |
| 11439 | - i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */ | |
| 11515 | + int tnum; /* Root BTree page for this table */ | |
| 11516 | + i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */ | |
| 11440 | 11517 | i16 nCol; /* Number of columns in this table */ |
| 11441 | 11518 | u16 nRef; /* Number of pointers to this Table */ |
| 11519 | + LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */ | |
| 11442 | 11520 | LogEst szTabRow; /* Estimated size of each table row in bytes */ |
| 11443 | 11521 | #ifdef SQLITE_ENABLE_COSTMULT |
| 11444 | 11522 | LogEst costMult; /* Cost multiplier for using this table */ |
| 11445 | 11523 | #endif |
| 11446 | 11524 | u8 tabFlags; /* Mask of TF_* values */ |
| @@ -11458,17 +11536,24 @@ | ||
| 11458 | 11536 | Table *pNextZombie; /* Next on the Parse.pZombieTab list */ |
| 11459 | 11537 | }; |
| 11460 | 11538 | |
| 11461 | 11539 | /* |
| 11462 | 11540 | ** Allowed values for Table.tabFlags. |
| 11541 | +** | |
| 11542 | +** TF_OOOHidden applies to virtual tables that have hidden columns that are | |
| 11543 | +** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING | |
| 11544 | +** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden, | |
| 11545 | +** the TF_OOOHidden attribute would apply in this case. Such tables require | |
| 11546 | +** special handling during INSERT processing. | |
| 11463 | 11547 | */ |
| 11464 | 11548 | #define TF_Readonly 0x01 /* Read-only system table */ |
| 11465 | 11549 | #define TF_Ephemeral 0x02 /* An ephemeral table */ |
| 11466 | 11550 | #define TF_HasPrimaryKey 0x04 /* Table has a primary key */ |
| 11467 | 11551 | #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */ |
| 11468 | 11552 | #define TF_Virtual 0x10 /* Is a virtual table */ |
| 11469 | 11553 | #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */ |
| 11554 | +#define TF_OOOHidden 0x40 /* Out-of-Order hidden columns */ | |
| 11470 | 11555 | |
| 11471 | 11556 | |
| 11472 | 11557 | /* |
| 11473 | 11558 | ** Test to see whether or not a table is a virtual table. This is |
| 11474 | 11559 | ** done as a macro so that it will be optimized out when virtual |
| @@ -12221,11 +12306,11 @@ | ||
| 12221 | 12306 | #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */ |
| 12222 | 12307 | #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */ |
| 12223 | 12308 | #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ |
| 12224 | 12309 | #define SF_Compound 0x0040 /* Part of a compound query */ |
| 12225 | 12310 | #define SF_Values 0x0080 /* Synthesized from VALUES clause */ |
| 12226 | -#define SF_AllValues 0x0100 /* All terms of compound are VALUES */ | |
| 12311 | +#define SF_MultiValue 0x0100 /* Single VALUES term with multiple rows */ | |
| 12227 | 12312 | #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */ |
| 12228 | 12313 | #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */ |
| 12229 | 12314 | #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */ |
| 12230 | 12315 | #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */ |
| 12231 | 12316 | #define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */ |
| @@ -12605,24 +12690,24 @@ | ||
| 12605 | 12690 | * |
| 12606 | 12691 | * (op == TK_INSERT) |
| 12607 | 12692 | * orconf -> stores the ON CONFLICT algorithm |
| 12608 | 12693 | * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then |
| 12609 | 12694 | * this stores a pointer to the SELECT statement. Otherwise NULL. |
| 12610 | - * target -> A token holding the quoted name of the table to insert into. | |
| 12695 | + * zTarget -> Dequoted name of the table to insert into. | |
| 12611 | 12696 | * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then |
| 12612 | 12697 | * this stores values to be inserted. Otherwise NULL. |
| 12613 | 12698 | * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ... |
| 12614 | 12699 | * statement, then this stores the column-names to be |
| 12615 | 12700 | * inserted into. |
| 12616 | 12701 | * |
| 12617 | 12702 | * (op == TK_DELETE) |
| 12618 | - * target -> A token holding the quoted name of the table to delete from. | |
| 12703 | + * zTarget -> Dequoted name of the table to delete from. | |
| 12619 | 12704 | * pWhere -> The WHERE clause of the DELETE statement if one is specified. |
| 12620 | 12705 | * Otherwise NULL. |
| 12621 | 12706 | * |
| 12622 | 12707 | * (op == TK_UPDATE) |
| 12623 | - * target -> A token holding the quoted name of the table to update rows of. | |
| 12708 | + * zTarget -> Dequoted name of the table to update. | |
| 12624 | 12709 | * pWhere -> The WHERE clause of the UPDATE statement if one is specified. |
| 12625 | 12710 | * Otherwise NULL. |
| 12626 | 12711 | * pExprList -> A list of the columns to update and the expressions to update |
| 12627 | 12712 | * them to. See sqlite3Update() documentation of "pChanges" |
| 12628 | 12713 | * argument. |
| @@ -12630,12 +12715,12 @@ | ||
| 12630 | 12715 | */ |
| 12631 | 12716 | struct TriggerStep { |
| 12632 | 12717 | u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */ |
| 12633 | 12718 | u8 orconf; /* OE_Rollback etc. */ |
| 12634 | 12719 | Trigger *pTrig; /* The trigger that this step is a part of */ |
| 12635 | - Select *pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */ | |
| 12636 | - Token target; /* Target table for DELETE, UPDATE, INSERT */ | |
| 12720 | + Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */ | |
| 12721 | + char *zTarget; /* Target table for DELETE, UPDATE, INSERT */ | |
| 12637 | 12722 | Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ |
| 12638 | 12723 | ExprList *pExprList; /* SET clause for UPDATE. */ |
| 12639 | 12724 | IdList *pIdList; /* Column names for INSERT */ |
| 12640 | 12725 | TriggerStep *pNext; /* Next in the link-list */ |
| 12641 | 12726 | TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ |
| @@ -12664,12 +12749,11 @@ | ||
| 12664 | 12749 | sqlite3 *db; /* Optional database for lookaside. Can be NULL */ |
| 12665 | 12750 | char *zBase; /* A base allocation. Not from malloc. */ |
| 12666 | 12751 | char *zText; /* The string collected so far */ |
| 12667 | 12752 | int nChar; /* Length of the string so far */ |
| 12668 | 12753 | int nAlloc; /* Amount of space allocated in zText */ |
| 12669 | - int mxAlloc; /* Maximum allowed string length */ | |
| 12670 | - u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */ | |
| 12754 | + int mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */ | |
| 12671 | 12755 | u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */ |
| 12672 | 12756 | }; |
| 12673 | 12757 | #define STRACCUM_NOMEM 1 |
| 12674 | 12758 | #define STRACCUM_TOOBIG 2 |
| 12675 | 12759 | |
| @@ -12982,11 +13066,11 @@ | ||
| 12982 | 13066 | SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list); |
| 12983 | 13067 | SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...); |
| 12984 | 13068 | SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 12985 | 13069 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
| 12986 | 13070 | SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...); |
| 12987 | -#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) | |
| 13071 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) | |
| 12988 | 13072 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...); |
| 12989 | 13073 | #endif |
| 12990 | 13074 | #if defined(SQLITE_TEST) |
| 12991 | 13075 | SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*); |
| 12992 | 13076 | #endif |
| @@ -13329,11 +13413,11 @@ | ||
| 13329 | 13413 | SQLITE_PRIVATE void sqlite3Error(sqlite3*,int); |
| 13330 | 13414 | SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n); |
| 13331 | 13415 | SQLITE_PRIVATE u8 sqlite3HexToInt(int h); |
| 13332 | 13416 | SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
| 13333 | 13417 | |
| 13334 | -#if defined(SQLITE_TEST) | |
| 13418 | +#if defined(SQLITE_NEED_ERR_NAME) | |
| 13335 | 13419 | SQLITE_PRIVATE const char *sqlite3ErrName(int); |
| 13336 | 13420 | #endif |
| 13337 | 13421 | |
| 13338 | 13422 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 13339 | 13423 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| @@ -13423,11 +13507,11 @@ | ||
| 13423 | 13507 | FuncDestructor *pDestructor |
| 13424 | 13508 | ); |
| 13425 | 13509 | SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); |
| 13426 | 13510 | SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); |
| 13427 | 13511 | |
| 13428 | -SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int); | |
| 13512 | +SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int); | |
| 13429 | 13513 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int); |
| 13430 | 13514 | SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*); |
| 13431 | 13515 | SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char); |
| 13432 | 13516 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 13433 | 13517 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*); |
| @@ -19807,20 +19891,10 @@ | ||
| 19807 | 19891 | */ |
| 19808 | 19892 | #ifdef MEMORY_DEBUG |
| 19809 | 19893 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 19810 | 19894 | #endif |
| 19811 | 19895 | |
| 19812 | -#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) | |
| 19813 | -# ifndef SQLITE_DEBUG_OS_TRACE | |
| 19814 | -# define SQLITE_DEBUG_OS_TRACE 0 | |
| 19815 | -# endif | |
| 19816 | - int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; | |
| 19817 | -# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X | |
| 19818 | -#else | |
| 19819 | -# define OSTRACE(X) | |
| 19820 | -#endif | |
| 19821 | - | |
| 19822 | 19896 | /* |
| 19823 | 19897 | ** Macros for performance tracing. Normally turned off. Only works |
| 19824 | 19898 | ** on i486 hardware. |
| 19825 | 19899 | */ |
| 19826 | 19900 | #ifdef SQLITE_PERFORMANCE_TRACE |
| @@ -21401,10 +21475,11 @@ | ||
| 21401 | 21475 | |
| 21402 | 21476 | /* |
| 21403 | 21477 | ** Set the StrAccum object to an error mode. |
| 21404 | 21478 | */ |
| 21405 | 21479 | static void setStrAccumError(StrAccum *p, u8 eError){ |
| 21480 | + assert( eError==STRACCUM_NOMEM || eError==STRACCUM_TOOBIG ); | |
| 21406 | 21481 | p->accError = eError; |
| 21407 | 21482 | p->nAlloc = 0; |
| 21408 | 21483 | } |
| 21409 | 21484 | |
| 21410 | 21485 | /* |
| @@ -22018,11 +22093,11 @@ | ||
| 22018 | 22093 | if( p->accError ){ |
| 22019 | 22094 | testcase(p->accError==STRACCUM_TOOBIG); |
| 22020 | 22095 | testcase(p->accError==STRACCUM_NOMEM); |
| 22021 | 22096 | return 0; |
| 22022 | 22097 | } |
| 22023 | - if( !p->useMalloc ){ | |
| 22098 | + if( p->mxAlloc==0 ){ | |
| 22024 | 22099 | N = p->nAlloc - p->nChar - 1; |
| 22025 | 22100 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 22026 | 22101 | return N; |
| 22027 | 22102 | }else{ |
| 22028 | 22103 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| @@ -22038,14 +22113,14 @@ | ||
| 22038 | 22113 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 22039 | 22114 | return 0; |
| 22040 | 22115 | }else{ |
| 22041 | 22116 | p->nAlloc = (int)szNew; |
| 22042 | 22117 | } |
| 22043 | - if( p->useMalloc==1 ){ | |
| 22118 | + if( p->db ){ | |
| 22044 | 22119 | zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc); |
| 22045 | 22120 | }else{ |
| 22046 | - zNew = sqlite3_realloc(zOld, p->nAlloc); | |
| 22121 | + zNew = sqlite3_realloc64(zOld, p->nAlloc); | |
| 22047 | 22122 | } |
| 22048 | 22123 | if( zNew ){ |
| 22049 | 22124 | assert( p->zText!=0 || p->nChar==0 ); |
| 22050 | 22125 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 22051 | 22126 | p->zText = zNew; |
| @@ -22089,11 +22164,11 @@ | ||
| 22089 | 22164 | /* |
| 22090 | 22165 | ** Append N bytes of text from z to the StrAccum object. Increase the |
| 22091 | 22166 | ** size of the memory allocation for StrAccum if necessary. |
| 22092 | 22167 | */ |
| 22093 | 22168 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ |
| 22094 | - assert( z!=0 ); | |
| 22169 | + assert( z!=0 || N==0 ); | |
| 22095 | 22170 | assert( p->zText!=0 || p->nChar==0 || p->accError ); |
| 22096 | 22171 | assert( N>=0 ); |
| 22097 | 22172 | assert( p->accError==0 || p->nAlloc==0 ); |
| 22098 | 22173 | if( p->nChar+N >= p->nAlloc ){ |
| 22099 | 22174 | enlargeAndAppend(p,z,N); |
| @@ -22118,16 +22193,12 @@ | ||
| 22118 | 22193 | ** pointer if any kind of error was encountered. |
| 22119 | 22194 | */ |
| 22120 | 22195 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){ |
| 22121 | 22196 | if( p->zText ){ |
| 22122 | 22197 | p->zText[p->nChar] = 0; |
| 22123 | - if( p->useMalloc && p->zText==p->zBase ){ | |
| 22124 | - if( p->useMalloc==1 ){ | |
| 22125 | - p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); | |
| 22126 | - }else{ | |
| 22127 | - p->zText = sqlite3_malloc(p->nChar+1); | |
| 22128 | - } | |
| 22198 | + if( p->mxAlloc>0 && p->zText==p->zBase ){ | |
| 22199 | + p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); | |
| 22129 | 22200 | if( p->zText ){ |
| 22130 | 22201 | memcpy(p->zText, p->zBase, p->nChar+1); |
| 22131 | 22202 | }else{ |
| 22132 | 22203 | setStrAccumError(p, STRACCUM_NOMEM); |
| 22133 | 22204 | } |
| @@ -22139,29 +22210,35 @@ | ||
| 22139 | 22210 | /* |
| 22140 | 22211 | ** Reset an StrAccum string. Reclaim all malloced memory. |
| 22141 | 22212 | */ |
| 22142 | 22213 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){ |
| 22143 | 22214 | if( p->zText!=p->zBase ){ |
| 22144 | - if( p->useMalloc==1 ){ | |
| 22145 | - sqlite3DbFree(p->db, p->zText); | |
| 22146 | - }else{ | |
| 22147 | - sqlite3_free(p->zText); | |
| 22148 | - } | |
| 22215 | + sqlite3DbFree(p->db, p->zText); | |
| 22149 | 22216 | } |
| 22150 | 22217 | p->zText = 0; |
| 22151 | 22218 | } |
| 22152 | 22219 | |
| 22153 | 22220 | /* |
| 22154 | -** Initialize a string accumulator | |
| 22221 | +** Initialize a string accumulator. | |
| 22222 | +** | |
| 22223 | +** p: The accumulator to be initialized. | |
| 22224 | +** db: Pointer to a database connection. May be NULL. Lookaside | |
| 22225 | +** memory is used if not NULL. db->mallocFailed is set appropriately | |
| 22226 | +** when not NULL. | |
| 22227 | +** zBase: An initial buffer. May be NULL in which case the initial buffer | |
| 22228 | +** is malloced. | |
| 22229 | +** n: Size of zBase in bytes. If total space requirements never exceed | |
| 22230 | +** n then no memory allocations ever occur. | |
| 22231 | +** mx: Maximum number of bytes to accumulate. If mx==0 then no memory | |
| 22232 | +** allocations will ever occur. | |
| 22155 | 22233 | */ |
| 22156 | -SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){ | |
| 22234 | +SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){ | |
| 22157 | 22235 | p->zText = p->zBase = zBase; |
| 22158 | - p->db = 0; | |
| 22236 | + p->db = db; | |
| 22159 | 22237 | p->nChar = 0; |
| 22160 | 22238 | p->nAlloc = n; |
| 22161 | 22239 | p->mxAlloc = mx; |
| 22162 | - p->useMalloc = 1; | |
| 22163 | 22240 | p->accError = 0; |
| 22164 | 22241 | } |
| 22165 | 22242 | |
| 22166 | 22243 | /* |
| 22167 | 22244 | ** Print into memory obtained from sqliteMalloc(). Use the internal |
| @@ -22170,13 +22247,12 @@ | ||
| 22170 | 22247 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){ |
| 22171 | 22248 | char *z; |
| 22172 | 22249 | char zBase[SQLITE_PRINT_BUF_SIZE]; |
| 22173 | 22250 | StrAccum acc; |
| 22174 | 22251 | assert( db!=0 ); |
| 22175 | - sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), | |
| 22252 | + sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase), | |
| 22176 | 22253 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 22177 | - acc.db = db; | |
| 22178 | 22254 | sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap); |
| 22179 | 22255 | z = sqlite3StrAccumFinish(&acc); |
| 22180 | 22256 | if( acc.accError==STRACCUM_NOMEM ){ |
| 22181 | 22257 | db->mallocFailed = 1; |
| 22182 | 22258 | } |
| @@ -22230,12 +22306,11 @@ | ||
| 22230 | 22306 | } |
| 22231 | 22307 | #endif |
| 22232 | 22308 | #ifndef SQLITE_OMIT_AUTOINIT |
| 22233 | 22309 | if( sqlite3_initialize() ) return 0; |
| 22234 | 22310 | #endif |
| 22235 | - sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); | |
| 22236 | - acc.useMalloc = 2; | |
| 22311 | + sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); | |
| 22237 | 22312 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22238 | 22313 | z = sqlite3StrAccumFinish(&acc); |
| 22239 | 22314 | return z; |
| 22240 | 22315 | } |
| 22241 | 22316 | |
| @@ -22276,12 +22351,11 @@ | ||
| 22276 | 22351 | (void)SQLITE_MISUSE_BKPT; |
| 22277 | 22352 | if( zBuf ) zBuf[0] = 0; |
| 22278 | 22353 | return zBuf; |
| 22279 | 22354 | } |
| 22280 | 22355 | #endif |
| 22281 | - sqlite3StrAccumInit(&acc, zBuf, n, 0); | |
| 22282 | - acc.useMalloc = 0; | |
| 22356 | + sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); | |
| 22283 | 22357 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22284 | 22358 | return sqlite3StrAccumFinish(&acc); |
| 22285 | 22359 | } |
| 22286 | 22360 | SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ |
| 22287 | 22361 | char *z; |
| @@ -22303,12 +22377,11 @@ | ||
| 22303 | 22377 | */ |
| 22304 | 22378 | static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){ |
| 22305 | 22379 | StrAccum acc; /* String accumulator */ |
| 22306 | 22380 | char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */ |
| 22307 | 22381 | |
| 22308 | - sqlite3StrAccumInit(&acc, zMsg, sizeof(zMsg), 0); | |
| 22309 | - acc.useMalloc = 0; | |
| 22382 | + sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0); | |
| 22310 | 22383 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22311 | 22384 | sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode, |
| 22312 | 22385 | sqlite3StrAccumFinish(&acc)); |
| 22313 | 22386 | } |
| 22314 | 22387 | |
| @@ -22322,22 +22395,21 @@ | ||
| 22322 | 22395 | renderLogMsg(iErrCode, zFormat, ap); |
| 22323 | 22396 | va_end(ap); |
| 22324 | 22397 | } |
| 22325 | 22398 | } |
| 22326 | 22399 | |
| 22327 | -#if defined(SQLITE_DEBUG) | |
| 22400 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) | |
| 22328 | 22401 | /* |
| 22329 | 22402 | ** A version of printf() that understands %lld. Used for debugging. |
| 22330 | 22403 | ** The printf() built into some versions of windows does not understand %lld |
| 22331 | 22404 | ** and segfaults if you give it a long long int. |
| 22332 | 22405 | */ |
| 22333 | 22406 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){ |
| 22334 | 22407 | va_list ap; |
| 22335 | 22408 | StrAccum acc; |
| 22336 | 22409 | char zBuf[500]; |
| 22337 | - sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0); | |
| 22338 | - acc.useMalloc = 0; | |
| 22410 | + sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); | |
| 22339 | 22411 | va_start(ap,zFormat); |
| 22340 | 22412 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22341 | 22413 | va_end(ap); |
| 22342 | 22414 | sqlite3StrAccumFinish(&acc); |
| 22343 | 22415 | fprintf(stdout,"%s", zBuf); |
| @@ -22360,11 +22432,11 @@ | ||
| 22360 | 22432 | */ |
| 22361 | 22433 | /* Add a new subitem to the tree. The moreToFollow flag indicates that this |
| 22362 | 22434 | ** is not the last item in the tree. */ |
| 22363 | 22435 | SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){ |
| 22364 | 22436 | if( p==0 ){ |
| 22365 | - p = sqlite3_malloc( sizeof(*p) ); | |
| 22437 | + p = sqlite3_malloc64( sizeof(*p) ); | |
| 22366 | 22438 | if( p==0 ) return 0; |
| 22367 | 22439 | memset(p, 0, sizeof(*p)); |
| 22368 | 22440 | }else{ |
| 22369 | 22441 | p->iLevel++; |
| 22370 | 22442 | } |
| @@ -22383,12 +22455,11 @@ | ||
| 22383 | 22455 | SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){ |
| 22384 | 22456 | va_list ap; |
| 22385 | 22457 | int i; |
| 22386 | 22458 | StrAccum acc; |
| 22387 | 22459 | char zBuf[500]; |
| 22388 | - sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0); | |
| 22389 | - acc.useMalloc = 0; | |
| 22460 | + sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); | |
| 22390 | 22461 | if( p ){ |
| 22391 | 22462 | for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){ |
| 22392 | 22463 | sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4); |
| 22393 | 22464 | } |
| 22394 | 22465 | sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4); |
| @@ -24007,10 +24078,11 @@ | ||
| 24007 | 24078 | }else{ |
| 24008 | 24079 | return 0; |
| 24009 | 24080 | } |
| 24010 | 24081 | } |
| 24011 | 24082 | #endif |
| 24083 | + while( zNum[0]=='0' ) zNum++; | |
| 24012 | 24084 | for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){ |
| 24013 | 24085 | v = v*10 + c; |
| 24014 | 24086 | } |
| 24015 | 24087 | |
| 24016 | 24088 | /* The longest decimal representation of a 32 bit integer is 10 digits: |
| @@ -25261,10 +25333,21 @@ | ||
| 25261 | 25333 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 25262 | 25334 | # include <sys/ioctl.h> |
| 25263 | 25335 | # include <sys/file.h> |
| 25264 | 25336 | # include <sys/param.h> |
| 25265 | 25337 | #endif /* SQLITE_ENABLE_LOCKING_STYLE */ |
| 25338 | + | |
| 25339 | +#if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ | |
| 25340 | + (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000)) | |
| 25341 | +# if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \ | |
| 25342 | + && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0)) | |
| 25343 | +# define HAVE_GETHOSTUUID 1 | |
| 25344 | +# else | |
| 25345 | +# warning "gethostuuid() is disabled." | |
| 25346 | +# endif | |
| 25347 | +#endif | |
| 25348 | + | |
| 25266 | 25349 | |
| 25267 | 25350 | #if OS_VXWORKS |
| 25268 | 25351 | /* # include <sys/ioctl.h> */ |
| 25269 | 25352 | # include <semaphore.h> |
| 25270 | 25353 | # include <limits.h> |
| @@ -25457,20 +25540,10 @@ | ||
| 25457 | 25540 | */ |
| 25458 | 25541 | #ifdef MEMORY_DEBUG |
| 25459 | 25542 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 25460 | 25543 | #endif |
| 25461 | 25544 | |
| 25462 | -#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) | |
| 25463 | -# ifndef SQLITE_DEBUG_OS_TRACE | |
| 25464 | -# define SQLITE_DEBUG_OS_TRACE 0 | |
| 25465 | -# endif | |
| 25466 | - int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; | |
| 25467 | -# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X | |
| 25468 | -#else | |
| 25469 | -# define OSTRACE(X) | |
| 25470 | -#endif | |
| 25471 | - | |
| 25472 | 25545 | /* |
| 25473 | 25546 | ** Macros for performance tracing. Normally turned off. Only works |
| 25474 | 25547 | ** on i486 hardware. |
| 25475 | 25548 | */ |
| 25476 | 25549 | #ifdef SQLITE_PERFORMANCE_TRACE |
| @@ -26009,11 +26082,11 @@ | ||
| 26009 | 26082 | return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 26010 | 26083 | } |
| 26011 | 26084 | #endif |
| 26012 | 26085 | |
| 26013 | 26086 | |
| 26014 | -#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) | |
| 26087 | +#ifdef SQLITE_HAVE_OS_TRACE | |
| 26015 | 26088 | /* |
| 26016 | 26089 | ** Helper function for printing out trace information from debugging |
| 26017 | 26090 | ** binaries. This returns the string representation of the supplied |
| 26018 | 26091 | ** integer lock-type. |
| 26019 | 26092 | */ |
| @@ -26272,11 +26345,11 @@ | ||
| 26272 | 26345 | struct vxworksFileId *pCandidate; /* For looping over existing file IDs */ |
| 26273 | 26346 | int n; /* Length of zAbsoluteName string */ |
| 26274 | 26347 | |
| 26275 | 26348 | assert( zAbsoluteName[0]=='/' ); |
| 26276 | 26349 | n = (int)strlen(zAbsoluteName); |
| 26277 | - pNew = sqlite3_malloc( sizeof(*pNew) + (n+1) ); | |
| 26350 | + pNew = sqlite3_malloc64( sizeof(*pNew) + (n+1) ); | |
| 26278 | 26351 | if( pNew==0 ) return 0; |
| 26279 | 26352 | pNew->zCanonicalName = (char*)&pNew[1]; |
| 26280 | 26353 | memcpy(pNew->zCanonicalName, zAbsoluteName, n+1); |
| 26281 | 26354 | n = vxworksSimplifyName(pNew->zCanonicalName, n); |
| 26282 | 26355 | |
| @@ -26676,11 +26749,11 @@ | ||
| 26676 | 26749 | pInode = inodeList; |
| 26677 | 26750 | while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){ |
| 26678 | 26751 | pInode = pInode->pNext; |
| 26679 | 26752 | } |
| 26680 | 26753 | if( pInode==0 ){ |
| 26681 | - pInode = sqlite3_malloc( sizeof(*pInode) ); | |
| 26754 | + pInode = sqlite3_malloc64( sizeof(*pInode) ); | |
| 26682 | 26755 | if( pInode==0 ){ |
| 26683 | 26756 | return SQLITE_NOMEM; |
| 26684 | 26757 | } |
| 26685 | 26758 | memset(pInode, 0, sizeof(*pInode)); |
| 26686 | 26759 | memcpy(&pInode->fileId, &fileId, sizeof(fileId)); |
| @@ -29197,11 +29270,11 @@ | ||
| 29197 | 29270 | case SQLITE_FCNTL_VFSNAME: { |
| 29198 | 29271 | *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); |
| 29199 | 29272 | return SQLITE_OK; |
| 29200 | 29273 | } |
| 29201 | 29274 | case SQLITE_FCNTL_TEMPFILENAME: { |
| 29202 | - char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname ); | |
| 29275 | + char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname ); | |
| 29203 | 29276 | if( zTFile ){ |
| 29204 | 29277 | unixGetTempname(pFile->pVfs->mxPathname, zTFile); |
| 29205 | 29278 | *(char**)pArg = zTFile; |
| 29206 | 29279 | } |
| 29207 | 29280 | return SQLITE_OK; |
| @@ -29638,11 +29711,11 @@ | ||
| 29638 | 29711 | unixInodeInfo *pInode; /* The inode of fd */ |
| 29639 | 29712 | char *zShmFilename; /* Name of the file used for SHM */ |
| 29640 | 29713 | int nShmFilename; /* Size of the SHM filename in bytes */ |
| 29641 | 29714 | |
| 29642 | 29715 | /* Allocate space for the new unixShm object. */ |
| 29643 | - p = sqlite3_malloc( sizeof(*p) ); | |
| 29716 | + p = sqlite3_malloc64( sizeof(*p) ); | |
| 29644 | 29717 | if( p==0 ) return SQLITE_NOMEM; |
| 29645 | 29718 | memset(p, 0, sizeof(*p)); |
| 29646 | 29719 | assert( pDbFd->pShm==0 ); |
| 29647 | 29720 | |
| 29648 | 29721 | /* Check to see if a unixShmNode object already exists. Reuse an existing |
| @@ -29669,11 +29742,11 @@ | ||
| 29669 | 29742 | #ifdef SQLITE_SHM_DIRECTORY |
| 29670 | 29743 | nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31; |
| 29671 | 29744 | #else |
| 29672 | 29745 | nShmFilename = 6 + (int)strlen(zBasePath); |
| 29673 | 29746 | #endif |
| 29674 | - pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename ); | |
| 29747 | + pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename ); | |
| 29675 | 29748 | if( pShmNode==0 ){ |
| 29676 | 29749 | rc = SQLITE_NOMEM; |
| 29677 | 29750 | goto shm_open_err; |
| 29678 | 29751 | } |
| 29679 | 29752 | memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename); |
| @@ -29879,11 +29952,11 @@ | ||
| 29879 | 29952 | if( pMem==MAP_FAILED ){ |
| 29880 | 29953 | rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename); |
| 29881 | 29954 | goto shmpage_out; |
| 29882 | 29955 | } |
| 29883 | 29956 | }else{ |
| 29884 | - pMem = sqlite3_malloc(szRegion); | |
| 29957 | + pMem = sqlite3_malloc64(szRegion); | |
| 29885 | 29958 | if( pMem==0 ){ |
| 29886 | 29959 | rc = SQLITE_NOMEM; |
| 29887 | 29960 | goto shmpage_out; |
| 29888 | 29961 | } |
| 29889 | 29962 | memset(pMem, 0, szRegion); |
| @@ -30716,11 +30789,11 @@ | ||
| 30716 | 30789 | else if( pLockingStyle == &afpIoMethods ){ |
| 30717 | 30790 | /* AFP locking uses the file path so it needs to be included in |
| 30718 | 30791 | ** the afpLockingContext. |
| 30719 | 30792 | */ |
| 30720 | 30793 | afpLockingContext *pCtx; |
| 30721 | - pNew->lockingContext = pCtx = sqlite3_malloc( sizeof(*pCtx) ); | |
| 30794 | + pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) ); | |
| 30722 | 30795 | if( pCtx==0 ){ |
| 30723 | 30796 | rc = SQLITE_NOMEM; |
| 30724 | 30797 | }else{ |
| 30725 | 30798 | /* NB: zFilename exists and remains valid until the file is closed |
| 30726 | 30799 | ** according to requirement F11141. So we do not need to make a |
| @@ -30746,11 +30819,11 @@ | ||
| 30746 | 30819 | */ |
| 30747 | 30820 | char *zLockFile; |
| 30748 | 30821 | int nFilename; |
| 30749 | 30822 | assert( zFilename!=0 ); |
| 30750 | 30823 | nFilename = (int)strlen(zFilename) + 6; |
| 30751 | - zLockFile = (char *)sqlite3_malloc(nFilename); | |
| 30824 | + zLockFile = (char *)sqlite3_malloc64(nFilename); | |
| 30752 | 30825 | if( zLockFile==0 ){ |
| 30753 | 30826 | rc = SQLITE_NOMEM; |
| 30754 | 30827 | }else{ |
| 30755 | 30828 | sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename); |
| 30756 | 30829 | } |
| @@ -31123,11 +31196,11 @@ | ||
| 31123 | 31196 | UnixUnusedFd *pUnused; |
| 31124 | 31197 | pUnused = findReusableFd(zName, flags); |
| 31125 | 31198 | if( pUnused ){ |
| 31126 | 31199 | fd = pUnused->fd; |
| 31127 | 31200 | }else{ |
| 31128 | - pUnused = sqlite3_malloc(sizeof(*pUnused)); | |
| 31201 | + pUnused = sqlite3_malloc64(sizeof(*pUnused)); | |
| 31129 | 31202 | if( !pUnused ){ |
| 31130 | 31203 | return SQLITE_NOMEM; |
| 31131 | 31204 | } |
| 31132 | 31205 | } |
| 31133 | 31206 | p->pUnused = pUnused; |
| @@ -31503,11 +31576,11 @@ | ||
| 31503 | 31576 | ** that we always use the same random number sequence. This makes the |
| 31504 | 31577 | ** tests repeatable. |
| 31505 | 31578 | */ |
| 31506 | 31579 | memset(zBuf, 0, nBuf); |
| 31507 | 31580 | randomnessPid = osGetpid(0); |
| 31508 | -#if !defined(SQLITE_TEST) | |
| 31581 | +#if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS) | |
| 31509 | 31582 | { |
| 31510 | 31583 | int fd, got; |
| 31511 | 31584 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 31512 | 31585 | if( fd<0 ){ |
| 31513 | 31586 | time_t t; |
| @@ -31915,11 +31988,11 @@ | ||
| 31915 | 31988 | */ |
| 31916 | 31989 | pUnused = findReusableFd(path, openFlags); |
| 31917 | 31990 | if( pUnused ){ |
| 31918 | 31991 | fd = pUnused->fd; |
| 31919 | 31992 | }else{ |
| 31920 | - pUnused = sqlite3_malloc(sizeof(*pUnused)); | |
| 31993 | + pUnused = sqlite3_malloc64(sizeof(*pUnused)); | |
| 31921 | 31994 | if( !pUnused ){ |
| 31922 | 31995 | return SQLITE_NOMEM; |
| 31923 | 31996 | } |
| 31924 | 31997 | } |
| 31925 | 31998 | if( fd<0 ){ |
| @@ -31948,11 +32021,11 @@ | ||
| 31948 | 32021 | default: |
| 31949 | 32022 | return SQLITE_CANTOPEN_BKPT; |
| 31950 | 32023 | } |
| 31951 | 32024 | } |
| 31952 | 32025 | |
| 31953 | - pNew = (unixFile *)sqlite3_malloc(sizeof(*pNew)); | |
| 32026 | + pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew)); | |
| 31954 | 32027 | if( pNew==NULL ){ |
| 31955 | 32028 | rc = SQLITE_NOMEM; |
| 31956 | 32029 | goto end_create_proxy; |
| 31957 | 32030 | } |
| 31958 | 32031 | memset(pNew, 0, sizeof(unixFile)); |
| @@ -31981,21 +32054,22 @@ | ||
| 31981 | 32054 | SQLITE_API int sqlite3_hostid_num = 0; |
| 31982 | 32055 | #endif |
| 31983 | 32056 | |
| 31984 | 32057 | #define PROXY_HOSTIDLEN 16 /* conch file host id length */ |
| 31985 | 32058 | |
| 32059 | +#ifdef HAVE_GETHOSTUUID | |
| 31986 | 32060 | /* Not always defined in the headers as it ought to be */ |
| 31987 | 32061 | extern int gethostuuid(uuid_t id, const struct timespec *wait); |
| 32062 | +#endif | |
| 31988 | 32063 | |
| 31989 | 32064 | /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN |
| 31990 | 32065 | ** bytes of writable memory. |
| 31991 | 32066 | */ |
| 31992 | 32067 | static int proxyGetHostID(unsigned char *pHostID, int *pError){ |
| 31993 | 32068 | assert(PROXY_HOSTIDLEN == sizeof(uuid_t)); |
| 31994 | 32069 | memset(pHostID, 0, PROXY_HOSTIDLEN); |
| 31995 | -# if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ | |
| 31996 | - (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000)) | |
| 32070 | +#ifdef HAVE_GETHOSTUUID | |
| 31997 | 32071 | { |
| 31998 | 32072 | struct timespec timeout = {1, 0}; /* 1 sec timeout */ |
| 31999 | 32073 | if( gethostuuid(pHostID, &timeout) ){ |
| 32000 | 32074 | int err = errno; |
| 32001 | 32075 | if( pError ){ |
| @@ -32409,11 +32483,11 @@ | ||
| 32409 | 32483 | return rc; |
| 32410 | 32484 | } |
| 32411 | 32485 | |
| 32412 | 32486 | /* |
| 32413 | 32487 | ** Given the name of a database file, compute the name of its conch file. |
| 32414 | -** Store the conch filename in memory obtained from sqlite3_malloc(). | |
| 32488 | +** Store the conch filename in memory obtained from sqlite3_malloc64(). | |
| 32415 | 32489 | ** Make *pConchPath point to the new name. Return SQLITE_OK on success |
| 32416 | 32490 | ** or SQLITE_NOMEM if unable to obtain memory. |
| 32417 | 32491 | ** |
| 32418 | 32492 | ** The caller is responsible for ensuring that the allocated memory |
| 32419 | 32493 | ** space is eventually freed. |
| @@ -32425,11 +32499,11 @@ | ||
| 32425 | 32499 | int len = (int)strlen(dbPath); /* Length of database filename - dbPath */ |
| 32426 | 32500 | char *conchPath; /* buffer in which to construct conch name */ |
| 32427 | 32501 | |
| 32428 | 32502 | /* Allocate space for the conch filename and initialize the name to |
| 32429 | 32503 | ** the name of the original database file. */ |
| 32430 | - *pConchPath = conchPath = (char *)sqlite3_malloc(len + 8); | |
| 32504 | + *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8); | |
| 32431 | 32505 | if( conchPath==0 ){ |
| 32432 | 32506 | return SQLITE_NOMEM; |
| 32433 | 32507 | } |
| 32434 | 32508 | memcpy(conchPath, dbPath, len+1); |
| 32435 | 32509 | |
| @@ -32541,11 +32615,11 @@ | ||
| 32541 | 32615 | } |
| 32542 | 32616 | |
| 32543 | 32617 | OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h, |
| 32544 | 32618 | (lockPath ? lockPath : ":auto:"), osGetpid(0))); |
| 32545 | 32619 | |
| 32546 | - pCtx = sqlite3_malloc( sizeof(*pCtx) ); | |
| 32620 | + pCtx = sqlite3_malloc64( sizeof(*pCtx) ); | |
| 32547 | 32621 | if( pCtx==0 ){ |
| 32548 | 32622 | return SQLITE_NOMEM; |
| 32549 | 32623 | } |
| 32550 | 32624 | memset(pCtx, 0, sizeof(*pCtx)); |
| 32551 | 32625 | |
| @@ -32985,20 +33059,10 @@ | ||
| 32985 | 33059 | */ |
| 32986 | 33060 | #ifdef MEMORY_DEBUG |
| 32987 | 33061 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 32988 | 33062 | #endif |
| 32989 | 33063 | |
| 32990 | -#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) | |
| 32991 | -# ifndef SQLITE_DEBUG_OS_TRACE | |
| 32992 | -# define SQLITE_DEBUG_OS_TRACE 0 | |
| 32993 | -# endif | |
| 32994 | - int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; | |
| 32995 | -# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X | |
| 32996 | -#else | |
| 32997 | -# define OSTRACE(X) | |
| 32998 | -#endif | |
| 32999 | - | |
| 33000 | 33064 | /* |
| 33001 | 33065 | ** Macros for performance tracing. Normally turned off. Only works |
| 33002 | 33066 | ** on i486 hardware. |
| 33003 | 33067 | */ |
| 33004 | 33068 | #ifdef SQLITE_PERFORMANCE_TRACE |
| @@ -35898,11 +35962,11 @@ | ||
| 35898 | 35962 | ** Used only when SQLITE_NO_SYNC is not defined. |
| 35899 | 35963 | */ |
| 35900 | 35964 | BOOL rc; |
| 35901 | 35965 | #endif |
| 35902 | 35966 | #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \ |
| 35903 | - (defined(SQLITE_TEST) && defined(SQLITE_DEBUG)) | |
| 35967 | + defined(SQLITE_HAVE_OS_TRACE) | |
| 35904 | 35968 | /* |
| 35905 | 35969 | ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or |
| 35906 | 35970 | ** OSTRACE() macros. |
| 35907 | 35971 | */ |
| 35908 | 35972 | winFile *pFile = (winFile*)id; |
| @@ -36575,11 +36639,11 @@ | ||
| 36575 | 36639 | DWORD lastErrno; /* The Windows errno from the last I/O error */ |
| 36576 | 36640 | |
| 36577 | 36641 | int nRef; /* Number of winShm objects pointing to this */ |
| 36578 | 36642 | winShm *pFirst; /* All winShm objects pointing to this */ |
| 36579 | 36643 | winShmNode *pNext; /* Next in list of all winShmNode objects */ |
| 36580 | -#ifdef SQLITE_DEBUG | |
| 36644 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) | |
| 36581 | 36645 | u8 nextShmId; /* Next available winShm.id value */ |
| 36582 | 36646 | #endif |
| 36583 | 36647 | }; |
| 36584 | 36648 | |
| 36585 | 36649 | /* |
| @@ -36606,11 +36670,11 @@ | ||
| 36606 | 36670 | winShmNode *pShmNode; /* The underlying winShmNode object */ |
| 36607 | 36671 | winShm *pNext; /* Next winShm with the same winShmNode */ |
| 36608 | 36672 | u8 hasMutex; /* True if holding the winShmNode mutex */ |
| 36609 | 36673 | u16 sharedMask; /* Mask of shared locks held */ |
| 36610 | 36674 | u16 exclMask; /* Mask of exclusive locks held */ |
| 36611 | -#ifdef SQLITE_DEBUG | |
| 36675 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) | |
| 36612 | 36676 | u8 id; /* Id of this connection with its winShmNode */ |
| 36613 | 36677 | #endif |
| 36614 | 36678 | }; |
| 36615 | 36679 | |
| 36616 | 36680 | /* |
| @@ -36797,11 +36861,11 @@ | ||
| 36797 | 36861 | if( rc ) goto shm_open_err; |
| 36798 | 36862 | } |
| 36799 | 36863 | |
| 36800 | 36864 | /* Make the new connection a child of the winShmNode */ |
| 36801 | 36865 | p->pShmNode = pShmNode; |
| 36802 | -#ifdef SQLITE_DEBUG | |
| 36866 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) | |
| 36803 | 36867 | p->id = pShmNode->nextShmId++; |
| 36804 | 36868 | #endif |
| 36805 | 36869 | pShmNode->nRef++; |
| 36806 | 36870 | pDbFd->pShm = p; |
| 36807 | 36871 | winShmLeaveMutex(); |
| @@ -37066,11 +37130,11 @@ | ||
| 37066 | 37130 | goto shmpage_out; |
| 37067 | 37131 | } |
| 37068 | 37132 | } |
| 37069 | 37133 | |
| 37070 | 37134 | /* Map the requested memory region into this processes address space. */ |
| 37071 | - apNew = (struct ShmRegion *)sqlite3_realloc( | |
| 37135 | + apNew = (struct ShmRegion *)sqlite3_realloc64( | |
| 37072 | 37136 | pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0]) |
| 37073 | 37137 | ); |
| 37074 | 37138 | if( !apNew ){ |
| 37075 | 37139 | rc = SQLITE_IOERR_NOMEM; |
| 37076 | 37140 | goto shmpage_out; |
| @@ -38513,11 +38577,11 @@ | ||
| 38513 | 38577 | ** Write up to nBuf bytes of randomness into zBuf. |
| 38514 | 38578 | */ |
| 38515 | 38579 | static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ |
| 38516 | 38580 | int n = 0; |
| 38517 | 38581 | UNUSED_PARAMETER(pVfs); |
| 38518 | -#if defined(SQLITE_TEST) | |
| 38582 | +#if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) | |
| 38519 | 38583 | n = nBuf; |
| 38520 | 38584 | memset(zBuf, 0, nBuf); |
| 38521 | 38585 | #else |
| 38522 | 38586 | if( sizeof(SYSTEMTIME)<=nBuf-n ){ |
| 38523 | 38587 | SYSTEMTIME x; |
| @@ -38547,11 +38611,10 @@ | ||
| 38547 | 38611 | LARGE_INTEGER i; |
| 38548 | 38612 | osQueryPerformanceCounter(&i); |
| 38549 | 38613 | memcpy(&zBuf[n], &i, sizeof(i)); |
| 38550 | 38614 | n += sizeof(i); |
| 38551 | 38615 | } |
| 38552 | -#endif | |
| 38553 | 38616 | #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID |
| 38554 | 38617 | if( sizeof(UUID)<=nBuf-n ){ |
| 38555 | 38618 | UUID id; |
| 38556 | 38619 | memset(&id, 0, sizeof(UUID)); |
| 38557 | 38620 | osUuidCreate(&id); |
| @@ -38564,10 +38627,11 @@ | ||
| 38564 | 38627 | osUuidCreateSequential(&id); |
| 38565 | 38628 | memcpy(zBuf, &id, sizeof(UUID)); |
| 38566 | 38629 | n += sizeof(UUID); |
| 38567 | 38630 | } |
| 38568 | 38631 | #endif |
| 38632 | +#endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */ | |
| 38569 | 38633 | return n; |
| 38570 | 38634 | } |
| 38571 | 38635 | |
| 38572 | 38636 | |
| 38573 | 38637 | /* |
| @@ -39118,11 +39182,11 @@ | ||
| 39118 | 39182 | |
| 39119 | 39183 | /* Allocate the Bitvec to be tested and a linear array of |
| 39120 | 39184 | ** bits to act as the reference */ |
| 39121 | 39185 | pBitvec = sqlite3BitvecCreate( sz ); |
| 39122 | 39186 | pV = sqlite3MallocZero( (sz+7)/8 + 1 ); |
| 39123 | - pTmpSpace = sqlite3_malloc(BITVEC_SZ); | |
| 39187 | + pTmpSpace = sqlite3_malloc64(BITVEC_SZ); | |
| 39124 | 39188 | if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end; |
| 39125 | 39189 | |
| 39126 | 39190 | /* NULL pBitvec tests */ |
| 39127 | 39191 | sqlite3BitvecSet(0, 1); |
| 39128 | 39192 | sqlite3BitvecClear(0, 1, pTmpSpace); |
| @@ -44607,13 +44671,11 @@ | ||
| 44607 | 44671 | Pgno nTruncate, /* Database size after this commit */ |
| 44608 | 44672 | int isCommit /* True if this is a commit */ |
| 44609 | 44673 | ){ |
| 44610 | 44674 | int rc; /* Return code */ |
| 44611 | 44675 | int nList; /* Number of pages in pList */ |
| 44612 | -#if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES) | |
| 44613 | 44676 | PgHdr *p; /* For looping over pages */ |
| 44614 | -#endif | |
| 44615 | 44677 | |
| 44616 | 44678 | assert( pPager->pWal ); |
| 44617 | 44679 | assert( pList ); |
| 44618 | 44680 | #ifdef SQLITE_DEBUG |
| 44619 | 44681 | /* Verify that the page list is in accending order */ |
| @@ -44626,11 +44688,10 @@ | ||
| 44626 | 44688 | if( isCommit ){ |
| 44627 | 44689 | /* If a WAL transaction is being committed, there is no point in writing |
| 44628 | 44690 | ** any pages with page numbers greater than nTruncate into the WAL file. |
| 44629 | 44691 | ** They will never be read by any client. So remove them from the pDirty |
| 44630 | 44692 | ** list here. */ |
| 44631 | - PgHdr *p; | |
| 44632 | 44693 | PgHdr **ppNext = &pList; |
| 44633 | 44694 | nList = 0; |
| 44634 | 44695 | for(p=pList; (*ppNext = p)!=0; p=p->pDirty){ |
| 44635 | 44696 | if( p->pgno<=nTruncate ){ |
| 44636 | 44697 | ppNext = &p->pDirty; |
| @@ -44646,11 +44707,10 @@ | ||
| 44646 | 44707 | if( pList->pgno==1 ) pager_write_changecounter(pList); |
| 44647 | 44708 | rc = sqlite3WalFrames(pPager->pWal, |
| 44648 | 44709 | pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags |
| 44649 | 44710 | ); |
| 44650 | 44711 | if( rc==SQLITE_OK && pPager->pBackup ){ |
| 44651 | - PgHdr *p; | |
| 44652 | 44712 | for(p=pList; p; p=p->pDirty){ |
| 44653 | 44713 | sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData); |
| 44654 | 44714 | } |
| 44655 | 44715 | } |
| 44656 | 44716 | |
| @@ -48577,10 +48637,12 @@ | ||
| 48577 | 48637 | }else if( state==PAGER_OPEN ){ |
| 48578 | 48638 | pager_unlock(pPager); |
| 48579 | 48639 | } |
| 48580 | 48640 | assert( state==pPager->eState ); |
| 48581 | 48641 | } |
| 48642 | + }else if( eMode==PAGER_JOURNALMODE_OFF ){ | |
| 48643 | + sqlite3OsClose(pPager->jfd); | |
| 48582 | 48644 | } |
| 48583 | 48645 | } |
| 48584 | 48646 | |
| 48585 | 48647 | /* Return the new journal mode */ |
| 48586 | 48648 | return (int)pPager->journalMode; |
| @@ -49359,11 +49421,11 @@ | ||
| 49359 | 49421 | |
| 49360 | 49422 | /* Enlarge the pWal->apWiData[] array if required */ |
| 49361 | 49423 | if( pWal->nWiData<=iPage ){ |
| 49362 | 49424 | int nByte = sizeof(u32*)*(iPage+1); |
| 49363 | 49425 | volatile u32 **apNew; |
| 49364 | - apNew = (volatile u32 **)sqlite3_realloc((void *)pWal->apWiData, nByte); | |
| 49426 | + apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte); | |
| 49365 | 49427 | if( !apNew ){ |
| 49366 | 49428 | *ppPage = 0; |
| 49367 | 49429 | return SQLITE_NOMEM; |
| 49368 | 49430 | } |
| 49369 | 49431 | memset((void*)&apNew[pWal->nWiData], 0, |
| @@ -49984,11 +50046,11 @@ | ||
| 49984 | 50046 | goto finished; |
| 49985 | 50047 | } |
| 49986 | 50048 | |
| 49987 | 50049 | /* Malloc a buffer to read frames into. */ |
| 49988 | 50050 | szFrame = szPage + WAL_FRAME_HDRSIZE; |
| 49989 | - aFrame = (u8 *)sqlite3_malloc(szFrame); | |
| 50051 | + aFrame = (u8 *)sqlite3_malloc64(szFrame); | |
| 49990 | 50052 | if( !aFrame ){ |
| 49991 | 50053 | rc = SQLITE_NOMEM; |
| 49992 | 50054 | goto recovery_error; |
| 49993 | 50055 | } |
| 49994 | 50056 | aData = &aFrame[WAL_FRAME_HDRSIZE]; |
| @@ -50377,21 +50439,21 @@ | ||
| 50377 | 50439 | /* Allocate space for the WalIterator object. */ |
| 50378 | 50440 | nSegment = walFramePage(iLast) + 1; |
| 50379 | 50441 | nByte = sizeof(WalIterator) |
| 50380 | 50442 | + (nSegment-1)*sizeof(struct WalSegment) |
| 50381 | 50443 | + iLast*sizeof(ht_slot); |
| 50382 | - p = (WalIterator *)sqlite3_malloc(nByte); | |
| 50444 | + p = (WalIterator *)sqlite3_malloc64(nByte); | |
| 50383 | 50445 | if( !p ){ |
| 50384 | 50446 | return SQLITE_NOMEM; |
| 50385 | 50447 | } |
| 50386 | 50448 | memset(p, 0, nByte); |
| 50387 | 50449 | p->nSegment = nSegment; |
| 50388 | 50450 | |
| 50389 | 50451 | /* Allocate temporary space used by the merge-sort routine. This block |
| 50390 | 50452 | ** of memory will be freed before this function returns. |
| 50391 | 50453 | */ |
| 50392 | - aTmp = (ht_slot *)sqlite3_malloc( | |
| 50454 | + aTmp = (ht_slot *)sqlite3_malloc64( | |
| 50393 | 50455 | sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast) |
| 50394 | 50456 | ); |
| 50395 | 50457 | if( !aTmp ){ |
| 50396 | 50458 | rc = SQLITE_NOMEM; |
| 50397 | 50459 | } |
| @@ -50567,10 +50629,18 @@ | ||
| 50567 | 50629 | ** cannot be backfilled from the WAL. |
| 50568 | 50630 | */ |
| 50569 | 50631 | mxSafeFrame = pWal->hdr.mxFrame; |
| 50570 | 50632 | mxPage = pWal->hdr.nPage; |
| 50571 | 50633 | for(i=1; i<WAL_NREADER; i++){ |
| 50634 | + /* Thread-sanitizer reports that the following is an unsafe read, | |
| 50635 | + ** as some other thread may be in the process of updating the value | |
| 50636 | + ** of the aReadMark[] slot. The assumption here is that if that is | |
| 50637 | + ** happening, the other client may only be increasing the value, | |
| 50638 | + ** not decreasing it. So assuming either that either the "old" or | |
| 50639 | + ** "new" version of the value is read, and not some arbitrary value | |
| 50640 | + ** that would never be written by a real client, things are still | |
| 50641 | + ** safe. */ | |
| 50572 | 50642 | u32 y = pInfo->aReadMark[i]; |
| 50573 | 50643 | if( mxSafeFrame>y ){ |
| 50574 | 50644 | assert( y<=pWal->hdr.mxFrame ); |
| 50575 | 50645 | rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1); |
| 50576 | 50646 | if( rc==SQLITE_OK ){ |
| @@ -57429,17 +57499,22 @@ | ||
| 57429 | 57499 | */ |
| 57430 | 57500 | static const void *fetchPayload( |
| 57431 | 57501 | BtCursor *pCur, /* Cursor pointing to entry to read from */ |
| 57432 | 57502 | u32 *pAmt /* Write the number of available bytes here */ |
| 57433 | 57503 | ){ |
| 57504 | + u32 amt; | |
| 57434 | 57505 | assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]); |
| 57435 | 57506 | assert( pCur->eState==CURSOR_VALID ); |
| 57436 | 57507 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 57437 | 57508 | assert( cursorHoldsMutex(pCur) ); |
| 57438 | 57509 | assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); |
| 57439 | 57510 | assert( pCur->info.nSize>0 ); |
| 57440 | - *pAmt = pCur->info.nLocal; | |
| 57511 | + assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB ); | |
| 57512 | + assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB); | |
| 57513 | + amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload); | |
| 57514 | + if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal; | |
| 57515 | + *pAmt = amt; | |
| 57441 | 57516 | return (void*)pCur->info.pPayload; |
| 57442 | 57517 | } |
| 57443 | 57518 | |
| 57444 | 57519 | |
| 57445 | 57520 | /* |
| @@ -59713,11 +59788,10 @@ | ||
| 59713 | 59788 | if( iParentIdx==0 ){ |
| 59714 | 59789 | nxDiv = 0; |
| 59715 | 59790 | }else if( iParentIdx==i ){ |
| 59716 | 59791 | nxDiv = i-2+bBulk; |
| 59717 | 59792 | }else{ |
| 59718 | - assert( bBulk==0 ); | |
| 59719 | 59793 | nxDiv = iParentIdx-1; |
| 59720 | 59794 | } |
| 59721 | 59795 | i = 2-bBulk; |
| 59722 | 59796 | } |
| 59723 | 59797 | nOld = i+1; |
| @@ -61501,10 +61575,61 @@ | ||
| 61501 | 61575 | iPage = get4byte(pOvflData); |
| 61502 | 61576 | sqlite3PagerUnref(pOvflPage); |
| 61503 | 61577 | } |
| 61504 | 61578 | } |
| 61505 | 61579 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 61580 | + | |
| 61581 | +/* | |
| 61582 | +** An implementation of a min-heap. | |
| 61583 | +** | |
| 61584 | +** aHeap[0] is the number of elements on the heap. aHeap[1] is the | |
| 61585 | +** root element. The daughter nodes of aHeap[N] are aHeap[N*2] | |
| 61586 | +** and aHeap[N*2+1]. | |
| 61587 | +** | |
| 61588 | +** The heap property is this: Every node is less than or equal to both | |
| 61589 | +** of its daughter nodes. A consequence of the heap property is that the | |
| 61590 | +** root node aHeap[1] is always the minimum value currently in the heap. | |
| 61591 | +** | |
| 61592 | +** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto | |
| 61593 | +** the heap, preserving the heap property. The btreeHeapPull() routine | |
| 61594 | +** removes the root element from the heap (the minimum value in the heap) | |
| 61595 | +** and then moves other nodes around as necessary to preserve the heap | |
| 61596 | +** property. | |
| 61597 | +** | |
| 61598 | +** This heap is used for cell overlap and coverage testing. Each u32 | |
| 61599 | +** entry represents the span of a cell or freeblock on a btree page. | |
| 61600 | +** The upper 16 bits are the index of the first byte of a range and the | |
| 61601 | +** lower 16 bits are the index of the last byte of that range. | |
| 61602 | +*/ | |
| 61603 | +static void btreeHeapInsert(u32 *aHeap, u32 x){ | |
| 61604 | + u32 j, i = ++aHeap[0]; | |
| 61605 | + aHeap[i] = x; | |
| 61606 | + while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){ | |
| 61607 | + x = aHeap[j]; | |
| 61608 | + aHeap[j] = aHeap[i]; | |
| 61609 | + aHeap[i] = x; | |
| 61610 | + i = j; | |
| 61611 | + } | |
| 61612 | +} | |
| 61613 | +static int btreeHeapPull(u32 *aHeap, u32 *pOut){ | |
| 61614 | + u32 j, i, x; | |
| 61615 | + if( (x = aHeap[0])==0 ) return 0; | |
| 61616 | + *pOut = aHeap[1]; | |
| 61617 | + aHeap[1] = aHeap[x]; | |
| 61618 | + aHeap[x] = 0xffffffff; | |
| 61619 | + aHeap[0]--; | |
| 61620 | + i = 1; | |
| 61621 | + while( (j = i*2)<=aHeap[0] ){ | |
| 61622 | + if( aHeap[j]>aHeap[j+1] ) j++; | |
| 61623 | + if( aHeap[i]<aHeap[j] ) break; | |
| 61624 | + x = aHeap[i]; | |
| 61625 | + aHeap[i] = aHeap[j]; | |
| 61626 | + aHeap[j] = x; | |
| 61627 | + i = j; | |
| 61628 | + } | |
| 61629 | + return 1; | |
| 61630 | +} | |
| 61506 | 61631 | |
| 61507 | 61632 | #ifndef SQLITE_OMIT_INTEGRITY_CHECK |
| 61508 | 61633 | /* |
| 61509 | 61634 | ** Do various sanity checks on a single page of a tree. Return |
| 61510 | 61635 | ** the tree depth. Root pages return 0. Parents of root pages |
| @@ -61534,11 +61659,12 @@ | ||
| 61534 | 61659 | int hdr, cellStart; |
| 61535 | 61660 | int nCell; |
| 61536 | 61661 | u8 *data; |
| 61537 | 61662 | BtShared *pBt; |
| 61538 | 61663 | int usableSize; |
| 61539 | - char *hit = 0; | |
| 61664 | + u32 *heap = 0; | |
| 61665 | + u32 x, prev = 0; | |
| 61540 | 61666 | i64 nMinKey = 0; |
| 61541 | 61667 | i64 nMaxKey = 0; |
| 61542 | 61668 | const char *saved_zPfx = pCheck->zPfx; |
| 61543 | 61669 | int saved_v1 = pCheck->v1; |
| 61544 | 61670 | int saved_v2 = pCheck->v2; |
| @@ -61679,19 +61805,19 @@ | ||
| 61679 | 61805 | |
| 61680 | 61806 | /* Check for complete coverage of the page |
| 61681 | 61807 | */ |
| 61682 | 61808 | data = pPage->aData; |
| 61683 | 61809 | hdr = pPage->hdrOffset; |
| 61684 | - hit = sqlite3PageMalloc( pBt->pageSize ); | |
| 61810 | + heap = (u32*)sqlite3PageMalloc( pBt->pageSize ); | |
| 61685 | 61811 | pCheck->zPfx = 0; |
| 61686 | - if( hit==0 ){ | |
| 61812 | + if( heap==0 ){ | |
| 61687 | 61813 | pCheck->mallocFailed = 1; |
| 61688 | 61814 | }else{ |
| 61689 | 61815 | int contentOffset = get2byteNotZero(&data[hdr+5]); |
| 61690 | 61816 | assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */ |
| 61691 | - memset(hit+contentOffset, 0, usableSize-contentOffset); | |
| 61692 | - memset(hit, 1, contentOffset); | |
| 61817 | + heap[0] = 0; | |
| 61818 | + btreeHeapInsert(heap, contentOffset-1); | |
| 61693 | 61819 | /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the |
| 61694 | 61820 | ** number of cells on the page. */ |
| 61695 | 61821 | nCell = get2byte(&data[hdr+3]); |
| 61696 | 61822 | /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page |
| 61697 | 61823 | ** immediately follows the b-tree page header. */ |
| @@ -61699,20 +61825,19 @@ | ||
| 61699 | 61825 | /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte |
| 61700 | 61826 | ** integer offsets to the cell contents. */ |
| 61701 | 61827 | for(i=0; i<nCell; i++){ |
| 61702 | 61828 | int pc = get2byte(&data[cellStart+i*2]); |
| 61703 | 61829 | u32 size = 65536; |
| 61704 | - int j; | |
| 61705 | 61830 | if( pc<=usableSize-4 ){ |
| 61706 | 61831 | size = cellSizePtr(pPage, &data[pc]); |
| 61707 | 61832 | } |
| 61708 | 61833 | if( (int)(pc+size-1)>=usableSize ){ |
| 61709 | 61834 | pCheck->zPfx = 0; |
| 61710 | 61835 | checkAppendMsg(pCheck, |
| 61711 | 61836 | "Corruption detected in cell %d on page %d",i,iPage); |
| 61712 | 61837 | }else{ |
| 61713 | - for(j=pc+size-1; j>=pc; j--) hit[j]++; | |
| 61838 | + btreeHeapInsert(heap, (pc<<16)|(pc+size-1)); | |
| 61714 | 61839 | } |
| 61715 | 61840 | } |
| 61716 | 61841 | /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header |
| 61717 | 61842 | ** is the offset of the first freeblock, or zero if there are no |
| 61718 | 61843 | ** freeblocks on the page. */ |
| @@ -61720,11 +61845,11 @@ | ||
| 61720 | 61845 | while( i>0 ){ |
| 61721 | 61846 | int size, j; |
| 61722 | 61847 | assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */ |
| 61723 | 61848 | size = get2byte(&data[i+2]); |
| 61724 | 61849 | assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */ |
| 61725 | - for(j=i+size-1; j>=i; j--) hit[j]++; | |
| 61850 | + btreeHeapInsert(heap, (i<<16)|(i+size-1)); | |
| 61726 | 61851 | /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a |
| 61727 | 61852 | ** big-endian integer which is the offset in the b-tree page of the next |
| 61728 | 61853 | ** freeblock in the chain, or zero if the freeblock is the last on the |
| 61729 | 61854 | ** chain. */ |
| 61730 | 61855 | j = get2byte(&data[i]); |
| @@ -61732,31 +61857,37 @@ | ||
| 61732 | 61857 | ** increasing offset. */ |
| 61733 | 61858 | assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */ |
| 61734 | 61859 | assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */ |
| 61735 | 61860 | i = j; |
| 61736 | 61861 | } |
| 61737 | - for(i=cnt=0; i<usableSize; i++){ | |
| 61738 | - if( hit[i]==0 ){ | |
| 61739 | - cnt++; | |
| 61740 | - }else if( hit[i]>1 ){ | |
| 61862 | + cnt = 0; | |
| 61863 | + assert( heap[0]>0 ); | |
| 61864 | + assert( (heap[1]>>16)==0 ); | |
| 61865 | + btreeHeapPull(heap,&prev); | |
| 61866 | + while( btreeHeapPull(heap,&x) ){ | |
| 61867 | + if( (prev&0xffff)+1>(x>>16) ){ | |
| 61741 | 61868 | checkAppendMsg(pCheck, |
| 61742 | - "Multiple uses for byte %d of page %d", i, iPage); | |
| 61869 | + "Multiple uses for byte %u of page %d", x>>16, iPage); | |
| 61743 | 61870 | break; |
| 61871 | + }else{ | |
| 61872 | + cnt += (x>>16) - (prev&0xffff) - 1; | |
| 61873 | + prev = x; | |
| 61744 | 61874 | } |
| 61745 | 61875 | } |
| 61876 | + cnt += usableSize - (prev&0xffff) - 1; | |
| 61746 | 61877 | /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments |
| 61747 | 61878 | ** is stored in the fifth field of the b-tree page header. |
| 61748 | 61879 | ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the |
| 61749 | 61880 | ** number of fragmented free bytes within the cell content area. |
| 61750 | 61881 | */ |
| 61751 | - if( cnt!=data[hdr+7] ){ | |
| 61882 | + if( heap[0]==0 && cnt!=data[hdr+7] ){ | |
| 61752 | 61883 | checkAppendMsg(pCheck, |
| 61753 | 61884 | "Fragmentation of %d bytes reported as %d on page %d", |
| 61754 | 61885 | cnt, data[hdr+7], iPage); |
| 61755 | 61886 | } |
| 61756 | 61887 | } |
| 61757 | - sqlite3PageFree(hit); | |
| 61888 | + sqlite3PageFree(heap); | |
| 61758 | 61889 | releasePage(pPage); |
| 61759 | 61890 | |
| 61760 | 61891 | end_of_check: |
| 61761 | 61892 | pCheck->zPfx = saved_zPfx; |
| 61762 | 61893 | pCheck->v1 = saved_v1; |
| @@ -61816,12 +61947,11 @@ | ||
| 61816 | 61947 | sqlite3BtreeLeave(p); |
| 61817 | 61948 | return 0; |
| 61818 | 61949 | } |
| 61819 | 61950 | i = PENDING_BYTE_PAGE(pBt); |
| 61820 | 61951 | if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i); |
| 61821 | - sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH); | |
| 61822 | - sCheck.errMsg.useMalloc = 2; | |
| 61952 | + sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH); | |
| 61823 | 61953 | |
| 61824 | 61954 | /* Check the integrity of the freelist |
| 61825 | 61955 | */ |
| 61826 | 61956 | sCheck.zPfx = "Main freelist: "; |
| 61827 | 61957 | checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]), |
| @@ -63153,14 +63283,15 @@ | ||
| 63153 | 63283 | return SQLITE_NOMEM; |
| 63154 | 63284 | } |
| 63155 | 63285 | pMem->z[pMem->n] = 0; |
| 63156 | 63286 | pMem->z[pMem->n+1] = 0; |
| 63157 | 63287 | pMem->flags |= MEM_Term; |
| 63288 | + } | |
| 63289 | + pMem->flags &= ~MEM_Ephem; | |
| 63158 | 63290 | #ifdef SQLITE_DEBUG |
| 63159 | - pMem->pScopyFrom = 0; | |
| 63291 | + pMem->pScopyFrom = 0; | |
| 63160 | 63292 | #endif |
| 63161 | - } | |
| 63162 | 63293 | |
| 63163 | 63294 | return SQLITE_OK; |
| 63164 | 63295 | } |
| 63165 | 63296 | |
| 63166 | 63297 | /* |
| @@ -64600,11 +64731,11 @@ | ||
| 64600 | 64731 | int i; |
| 64601 | 64732 | int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField; |
| 64602 | 64733 | Mem *aMem = pRec->aMem; |
| 64603 | 64734 | sqlite3 *db = aMem[0].db; |
| 64604 | 64735 | for(i=0; i<nCol; i++){ |
| 64605 | - if( aMem[i].szMalloc ) sqlite3DbFree(db, aMem[i].zMalloc); | |
| 64736 | + sqlite3VdbeMemRelease(&aMem[i]); | |
| 64606 | 64737 | } |
| 64607 | 64738 | sqlite3KeyInfoUnref(pRec->pKeyInfo); |
| 64608 | 64739 | sqlite3DbFree(db, pRec); |
| 64609 | 64740 | } |
| 64610 | 64741 | } |
| @@ -66436,18 +66567,35 @@ | ||
| 66436 | 66567 | pVtabCursor->pVtab->nRef--; |
| 66437 | 66568 | pModule->xClose(pVtabCursor); |
| 66438 | 66569 | } |
| 66439 | 66570 | #endif |
| 66440 | 66571 | } |
| 66572 | + | |
| 66573 | +/* | |
| 66574 | +** Close all cursors in the current frame. | |
| 66575 | +*/ | |
| 66576 | +static void closeCursorsInFrame(Vdbe *p){ | |
| 66577 | + if( p->apCsr ){ | |
| 66578 | + int i; | |
| 66579 | + for(i=0; i<p->nCursor; i++){ | |
| 66580 | + VdbeCursor *pC = p->apCsr[i]; | |
| 66581 | + if( pC ){ | |
| 66582 | + sqlite3VdbeFreeCursor(p, pC); | |
| 66583 | + p->apCsr[i] = 0; | |
| 66584 | + } | |
| 66585 | + } | |
| 66586 | + } | |
| 66587 | +} | |
| 66441 | 66588 | |
| 66442 | 66589 | /* |
| 66443 | 66590 | ** Copy the values stored in the VdbeFrame structure to its Vdbe. This |
| 66444 | 66591 | ** is used, for example, when a trigger sub-program is halted to restore |
| 66445 | 66592 | ** control to the main program. |
| 66446 | 66593 | */ |
| 66447 | 66594 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){ |
| 66448 | 66595 | Vdbe *v = pFrame->v; |
| 66596 | + closeCursorsInFrame(v); | |
| 66449 | 66597 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 66450 | 66598 | v->anExec = pFrame->anExec; |
| 66451 | 66599 | #endif |
| 66452 | 66600 | v->aOnceFlag = pFrame->aOnceFlag; |
| 66453 | 66601 | v->nOnceFlag = pFrame->nOnceFlag; |
| @@ -66478,21 +66626,11 @@ | ||
| 66478 | 66626 | sqlite3VdbeFrameRestore(pFrame); |
| 66479 | 66627 | p->pFrame = 0; |
| 66480 | 66628 | p->nFrame = 0; |
| 66481 | 66629 | } |
| 66482 | 66630 | assert( p->nFrame==0 ); |
| 66483 | - | |
| 66484 | - if( p->apCsr ){ | |
| 66485 | - int i; | |
| 66486 | - for(i=0; i<p->nCursor; i++){ | |
| 66487 | - VdbeCursor *pC = p->apCsr[i]; | |
| 66488 | - if( pC ){ | |
| 66489 | - sqlite3VdbeFreeCursor(p, pC); | |
| 66490 | - p->apCsr[i] = 0; | |
| 66491 | - } | |
| 66492 | - } | |
| 66493 | - } | |
| 66631 | + closeCursorsInFrame(p); | |
| 66494 | 66632 | if( p->aMem ){ |
| 66495 | 66633 | releaseMemArray(&p->aMem[1], p->nMem); |
| 66496 | 66634 | } |
| 66497 | 66635 | while( p->pDelFrame ){ |
| 66498 | 66636 | VdbeFrame *pDel = p->pDelFrame; |
| @@ -68233,11 +68371,11 @@ | ||
| 68233 | 68371 | ** If database corruption is discovered, set pPKey2->errCode to |
| 68234 | 68372 | ** SQLITE_CORRUPT and return 0. If an OOM error is encountered, |
| 68235 | 68373 | ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the |
| 68236 | 68374 | ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db). |
| 68237 | 68375 | */ |
| 68238 | -static int vdbeRecordCompareWithSkip( | |
| 68376 | +SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip( | |
| 68239 | 68377 | int nKey1, const void *pKey1, /* Left key */ |
| 68240 | 68378 | UnpackedRecord *pPKey2, /* Right key */ |
| 68241 | 68379 | int bSkip /* If true, skip the first field */ |
| 68242 | 68380 | ){ |
| 68243 | 68381 | u32 d1; /* Offset into aKey[] of next data element */ |
| @@ -68419,11 +68557,11 @@ | ||
| 68419 | 68557 | } |
| 68420 | 68558 | SQLITE_PRIVATE int sqlite3VdbeRecordCompare( |
| 68421 | 68559 | int nKey1, const void *pKey1, /* Left key */ |
| 68422 | 68560 | UnpackedRecord *pPKey2 /* Right key */ |
| 68423 | 68561 | ){ |
| 68424 | - return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0); | |
| 68562 | + return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0); | |
| 68425 | 68563 | } |
| 68426 | 68564 | |
| 68427 | 68565 | |
| 68428 | 68566 | /* |
| 68429 | 68567 | ** This function is an optimized version of sqlite3VdbeRecordCompare() |
| @@ -68507,11 +68645,11 @@ | ||
| 68507 | 68645 | }else if( v<lhs ){ |
| 68508 | 68646 | res = pPKey2->r2; |
| 68509 | 68647 | }else if( pPKey2->nField>1 ){ |
| 68510 | 68648 | /* The first fields of the two keys are equal. Compare the trailing |
| 68511 | 68649 | ** fields. */ |
| 68512 | - res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); | |
| 68650 | + res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); | |
| 68513 | 68651 | }else{ |
| 68514 | 68652 | /* The first fields of the two keys are equal and there are no trailing |
| 68515 | 68653 | ** fields. Return pPKey2->default_rc in this case. */ |
| 68516 | 68654 | res = pPKey2->default_rc; |
| 68517 | 68655 | } |
| @@ -68555,11 +68693,11 @@ | ||
| 68555 | 68693 | |
| 68556 | 68694 | if( res==0 ){ |
| 68557 | 68695 | res = nStr - pPKey2->aMem[0].n; |
| 68558 | 68696 | if( res==0 ){ |
| 68559 | 68697 | if( pPKey2->nField>1 ){ |
| 68560 | - res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); | |
| 68698 | + res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); | |
| 68561 | 68699 | }else{ |
| 68562 | 68700 | res = pPKey2->default_rc; |
| 68563 | 68701 | } |
| 68564 | 68702 | }else if( res>0 ){ |
| 68565 | 68703 | res = pPKey2->r2; |
| @@ -70497,21 +70635,22 @@ | ||
| 70497 | 70635 | Mem *pVar; /* Value of a host parameter */ |
| 70498 | 70636 | StrAccum out; /* Accumulate the output here */ |
| 70499 | 70637 | char zBase[100]; /* Initial working space */ |
| 70500 | 70638 | |
| 70501 | 70639 | db = p->db; |
| 70502 | - sqlite3StrAccumInit(&out, zBase, sizeof(zBase), | |
| 70640 | + sqlite3StrAccumInit(&out, db, zBase, sizeof(zBase), | |
| 70503 | 70641 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 70504 | - out.db = db; | |
| 70505 | 70642 | if( db->nVdbeExec>1 ){ |
| 70506 | 70643 | while( *zRawSql ){ |
| 70507 | 70644 | const char *zStart = zRawSql; |
| 70508 | 70645 | while( *(zRawSql++)!='\n' && *zRawSql ); |
| 70509 | 70646 | sqlite3StrAccumAppend(&out, "-- ", 3); |
| 70510 | 70647 | assert( (zRawSql - zStart) > 0 ); |
| 70511 | 70648 | sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart)); |
| 70512 | 70649 | } |
| 70650 | + }else if( p->nVar==0 ){ | |
| 70651 | + sqlite3StrAccumAppend(&out, zRawSql, sqlite3Strlen30(zRawSql)); | |
| 70513 | 70652 | }else{ |
| 70514 | 70653 | while( zRawSql[0] ){ |
| 70515 | 70654 | n = findNextHostParameter(zRawSql, &nToken); |
| 70516 | 70655 | assert( n>0 ); |
| 70517 | 70656 | sqlite3StrAccumAppend(&out, zRawSql, n); |
| @@ -70524,14 +70663,16 @@ | ||
| 70524 | 70663 | sqlite3GetInt32(&zRawSql[1], &idx); |
| 70525 | 70664 | }else{ |
| 70526 | 70665 | idx = nextIndex; |
| 70527 | 70666 | } |
| 70528 | 70667 | }else{ |
| 70529 | - assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' ); | |
| 70668 | + assert( zRawSql[0]==':' || zRawSql[0]=='$' || | |
| 70669 | + zRawSql[0]=='@' || zRawSql[0]=='#' ); | |
| 70530 | 70670 | testcase( zRawSql[0]==':' ); |
| 70531 | 70671 | testcase( zRawSql[0]=='$' ); |
| 70532 | 70672 | testcase( zRawSql[0]=='@' ); |
| 70673 | + testcase( zRawSql[0]=='#' ); | |
| 70533 | 70674 | idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken); |
| 70534 | 70675 | assert( idx>0 ); |
| 70535 | 70676 | } |
| 70536 | 70677 | zRawSql += nToken; |
| 70537 | 70678 | nextIndex = idx + 1; |
| @@ -71202,21 +71343,38 @@ | ||
| 71202 | 71343 | assert( n==(db->nSavepoint + db->isTransactionSavepoint) ); |
| 71203 | 71344 | return 1; |
| 71204 | 71345 | } |
| 71205 | 71346 | #endif |
| 71206 | 71347 | |
| 71348 | +/* | |
| 71349 | +** Return the register of pOp->p2 after first preparing it to be | |
| 71350 | +** overwritten with an integer value. | |
| 71351 | +*/ | |
| 71352 | +static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){ | |
| 71353 | + Mem *pOut; | |
| 71354 | + assert( pOp->p2>0 ); | |
| 71355 | + assert( pOp->p2<=(p->nMem-p->nCursor) ); | |
| 71356 | + pOut = &p->aMem[pOp->p2]; | |
| 71357 | + memAboutToChange(p, pOut); | |
| 71358 | + if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut); | |
| 71359 | + pOut->flags = MEM_Int; | |
| 71360 | + return pOut; | |
| 71361 | +} | |
| 71362 | + | |
| 71207 | 71363 | |
| 71208 | 71364 | /* |
| 71209 | 71365 | ** Execute as much of a VDBE program as we can. |
| 71210 | 71366 | ** This is the core of sqlite3_step(). |
| 71211 | 71367 | */ |
| 71212 | 71368 | SQLITE_PRIVATE int sqlite3VdbeExec( |
| 71213 | 71369 | Vdbe *p /* The VDBE */ |
| 71214 | 71370 | ){ |
| 71215 | - int pc=0; /* The program counter */ | |
| 71216 | 71371 | Op *aOp = p->aOp; /* Copy of p->aOp */ |
| 71217 | - Op *pOp; /* Current operation */ | |
| 71372 | + Op *pOp = aOp; /* Current operation */ | |
| 71373 | +#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) | |
| 71374 | + Op *pOrigOp; /* Value of pOp at the top of the loop */ | |
| 71375 | +#endif | |
| 71218 | 71376 | int rc = SQLITE_OK; /* Value to return */ |
| 71219 | 71377 | sqlite3 *db = p->db; /* The database */ |
| 71220 | 71378 | u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ |
| 71221 | 71379 | u8 encoding = ENC(db); /* The database encoding */ |
| 71222 | 71380 | int iCompare = 0; /* Result of last OP_Compare operation */ |
| @@ -71288,27 +71446,26 @@ | ||
| 71288 | 71446 | } |
| 71289 | 71447 | if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n"); |
| 71290 | 71448 | } |
| 71291 | 71449 | sqlite3EndBenignMalloc(); |
| 71292 | 71450 | #endif |
| 71293 | - for(pc=p->pc; rc==SQLITE_OK; pc++){ | |
| 71294 | - assert( pc>=0 && pc<p->nOp ); | |
| 71451 | + for(pOp=&aOp[p->pc]; rc==SQLITE_OK; pOp++){ | |
| 71452 | + assert( pOp>=aOp && pOp<&aOp[p->nOp]); | |
| 71295 | 71453 | if( db->mallocFailed ) goto no_mem; |
| 71296 | 71454 | #ifdef VDBE_PROFILE |
| 71297 | 71455 | start = sqlite3Hwtime(); |
| 71298 | 71456 | #endif |
| 71299 | 71457 | nVmStep++; |
| 71300 | - pOp = &aOp[pc]; | |
| 71301 | 71458 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 71302 | - if( p->anExec ) p->anExec[pc]++; | |
| 71459 | + if( p->anExec ) p->anExec[(int)(pOp-aOp)]++; | |
| 71303 | 71460 | #endif |
| 71304 | 71461 | |
| 71305 | 71462 | /* Only allow tracing if SQLITE_DEBUG is defined. |
| 71306 | 71463 | */ |
| 71307 | 71464 | #ifdef SQLITE_DEBUG |
| 71308 | 71465 | if( db->flags & SQLITE_VdbeTrace ){ |
| 71309 | - sqlite3VdbePrintOp(stdout, pc, pOp); | |
| 71466 | + sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp); | |
| 71310 | 71467 | } |
| 71311 | 71468 | #endif |
| 71312 | 71469 | |
| 71313 | 71470 | |
| 71314 | 71471 | /* Check to see if we need to simulate an interrupt. This only happens |
| @@ -71321,27 +71478,13 @@ | ||
| 71321 | 71478 | sqlite3_interrupt(db); |
| 71322 | 71479 | } |
| 71323 | 71480 | } |
| 71324 | 71481 | #endif |
| 71325 | 71482 | |
| 71326 | - /* On any opcode with the "out2-prerelease" tag, free any | |
| 71327 | - ** external allocations out of mem[p2] and set mem[p2] to be | |
| 71328 | - ** an undefined integer. Opcodes will either fill in the integer | |
| 71329 | - ** value or convert mem[p2] to a different type. | |
| 71330 | - */ | |
| 71331 | - assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] ); | |
| 71332 | - if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){ | |
| 71333 | - assert( pOp->p2>0 ); | |
| 71334 | - assert( pOp->p2<=(p->nMem-p->nCursor) ); | |
| 71335 | - pOut = &aMem[pOp->p2]; | |
| 71336 | - memAboutToChange(p, pOut); | |
| 71337 | - if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut); | |
| 71338 | - pOut->flags = MEM_Int; | |
| 71339 | - } | |
| 71340 | - | |
| 71341 | 71483 | /* Sanity checking on other operands */ |
| 71342 | 71484 | #ifdef SQLITE_DEBUG |
| 71485 | + assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] ); | |
| 71343 | 71486 | if( (pOp->opflags & OPFLG_IN1)!=0 ){ |
| 71344 | 71487 | assert( pOp->p1>0 ); |
| 71345 | 71488 | assert( pOp->p1<=(p->nMem-p->nCursor) ); |
| 71346 | 71489 | assert( memIsValid(&aMem[pOp->p1]) ); |
| 71347 | 71490 | assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) ); |
| @@ -71370,10 +71513,13 @@ | ||
| 71370 | 71513 | assert( pOp->p3>0 ); |
| 71371 | 71514 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 71372 | 71515 | memAboutToChange(p, &aMem[pOp->p3]); |
| 71373 | 71516 | } |
| 71374 | 71517 | #endif |
| 71518 | +#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) | |
| 71519 | + pOrigOp = pOp; | |
| 71520 | +#endif | |
| 71375 | 71521 | |
| 71376 | 71522 | switch( pOp->opcode ){ |
| 71377 | 71523 | |
| 71378 | 71524 | /***************************************************************************** |
| 71379 | 71525 | ** What follows is a massive switch statement where each case implements a |
| @@ -71393,11 +71539,11 @@ | ||
| 71393 | 71539 | ** case statement is followed by a comment of the form "/# same as ... #/" |
| 71394 | 71540 | ** that comment is used to determine the particular value of the opcode. |
| 71395 | 71541 | ** |
| 71396 | 71542 | ** Other keywords in the comment that follows each case are used to |
| 71397 | 71543 | ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[]. |
| 71398 | -** Keywords include: in1, in2, in3, out2_prerelease, out2, out3. See | |
| 71544 | +** Keywords include: in1, in2, in3, out2, out3. See | |
| 71399 | 71545 | ** the mkopcodeh.awk script for additional information. |
| 71400 | 71546 | ** |
| 71401 | 71547 | ** Documentation about VDBE opcodes is generated by scanning this file |
| 71402 | 71548 | ** for lines of that contain "Opcode:". That line and all subsequent |
| 71403 | 71549 | ** comment lines are used in the generation of the opcode.html documentation |
| @@ -71421,11 +71567,12 @@ | ||
| 71421 | 71567 | ** is sometimes set to 1 instead of 0 as a hint to the command-line shell |
| 71422 | 71568 | ** that this Goto is the bottom of a loop and that the lines from P2 down |
| 71423 | 71569 | ** to the current line should be indented for EXPLAIN output. |
| 71424 | 71570 | */ |
| 71425 | 71571 | case OP_Goto: { /* jump */ |
| 71426 | - pc = pOp->p2 - 1; | |
| 71572 | +jump_to_p2_and_check_for_interrupt: | |
| 71573 | + pOp = &aOp[pOp->p2 - 1]; | |
| 71427 | 71574 | |
| 71428 | 71575 | /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev, |
| 71429 | 71576 | ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon |
| 71430 | 71577 | ** completion. Check to see if sqlite3_interrupt() has been called |
| 71431 | 71578 | ** or if the progress callback needs to be invoked. |
| @@ -71466,13 +71613,17 @@ | ||
| 71466 | 71613 | assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 71467 | 71614 | pIn1 = &aMem[pOp->p1]; |
| 71468 | 71615 | assert( VdbeMemDynamic(pIn1)==0 ); |
| 71469 | 71616 | memAboutToChange(p, pIn1); |
| 71470 | 71617 | pIn1->flags = MEM_Int; |
| 71471 | - pIn1->u.i = pc; | |
| 71618 | + pIn1->u.i = (int)(pOp-aOp); | |
| 71472 | 71619 | REGISTER_TRACE(pOp->p1, pIn1); |
| 71473 | - pc = pOp->p2 - 1; | |
| 71620 | + | |
| 71621 | + /* Most jump operations do a goto to this spot in order to update | |
| 71622 | + ** the pOp pointer. */ | |
| 71623 | +jump_to_p2: | |
| 71624 | + pOp = &aOp[pOp->p2 - 1]; | |
| 71474 | 71625 | break; |
| 71475 | 71626 | } |
| 71476 | 71627 | |
| 71477 | 71628 | /* Opcode: Return P1 * * * * |
| 71478 | 71629 | ** |
| @@ -71480,11 +71631,11 @@ | ||
| 71480 | 71631 | ** the jump, register P1 becomes undefined. |
| 71481 | 71632 | */ |
| 71482 | 71633 | case OP_Return: { /* in1 */ |
| 71483 | 71634 | pIn1 = &aMem[pOp->p1]; |
| 71484 | 71635 | assert( pIn1->flags==MEM_Int ); |
| 71485 | - pc = (int)pIn1->u.i; | |
| 71636 | + pOp = &aOp[pIn1->u.i]; | |
| 71486 | 71637 | pIn1->flags = MEM_Undefined; |
| 71487 | 71638 | break; |
| 71488 | 71639 | } |
| 71489 | 71640 | |
| 71490 | 71641 | /* Opcode: InitCoroutine P1 P2 P3 * * |
| @@ -71504,11 +71655,11 @@ | ||
| 71504 | 71655 | assert( pOp->p3>=0 && pOp->p3<p->nOp ); |
| 71505 | 71656 | pOut = &aMem[pOp->p1]; |
| 71506 | 71657 | assert( !VdbeMemDynamic(pOut) ); |
| 71507 | 71658 | pOut->u.i = pOp->p3 - 1; |
| 71508 | 71659 | pOut->flags = MEM_Int; |
| 71509 | - if( pOp->p2 ) pc = pOp->p2 - 1; | |
| 71660 | + if( pOp->p2 ) goto jump_to_p2; | |
| 71510 | 71661 | break; |
| 71511 | 71662 | } |
| 71512 | 71663 | |
| 71513 | 71664 | /* Opcode: EndCoroutine P1 * * * * |
| 71514 | 71665 | ** |
| @@ -71524,11 +71675,11 @@ | ||
| 71524 | 71675 | assert( pIn1->flags==MEM_Int ); |
| 71525 | 71676 | assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp ); |
| 71526 | 71677 | pCaller = &aOp[pIn1->u.i]; |
| 71527 | 71678 | assert( pCaller->opcode==OP_Yield ); |
| 71528 | 71679 | assert( pCaller->p2>=0 && pCaller->p2<p->nOp ); |
| 71529 | - pc = pCaller->p2 - 1; | |
| 71680 | + pOp = &aOp[pCaller->p2 - 1]; | |
| 71530 | 71681 | pIn1->flags = MEM_Undefined; |
| 71531 | 71682 | break; |
| 71532 | 71683 | } |
| 71533 | 71684 | |
| 71534 | 71685 | /* Opcode: Yield P1 P2 * * * |
| @@ -71548,13 +71699,13 @@ | ||
| 71548 | 71699 | int pcDest; |
| 71549 | 71700 | pIn1 = &aMem[pOp->p1]; |
| 71550 | 71701 | assert( VdbeMemDynamic(pIn1)==0 ); |
| 71551 | 71702 | pIn1->flags = MEM_Int; |
| 71552 | 71703 | pcDest = (int)pIn1->u.i; |
| 71553 | - pIn1->u.i = pc; | |
| 71704 | + pIn1->u.i = (int)(pOp - aOp); | |
| 71554 | 71705 | REGISTER_TRACE(pOp->p1, pIn1); |
| 71555 | - pc = pcDest; | |
| 71706 | + pOp = &aOp[pcDest]; | |
| 71556 | 71707 | break; |
| 71557 | 71708 | } |
| 71558 | 71709 | |
| 71559 | 71710 | /* Opcode: HaltIfNull P1 P2 P3 P4 P5 |
| 71560 | 71711 | ** Synopsis: if r[P3]=null halt |
| @@ -71601,34 +71752,38 @@ | ||
| 71601 | 71752 | ** is the same as executing Halt. |
| 71602 | 71753 | */ |
| 71603 | 71754 | case OP_Halt: { |
| 71604 | 71755 | const char *zType; |
| 71605 | 71756 | const char *zLogFmt; |
| 71757 | + VdbeFrame *pFrame; | |
| 71758 | + int pcx; | |
| 71606 | 71759 | |
| 71760 | + pcx = (int)(pOp - aOp); | |
| 71607 | 71761 | if( pOp->p1==SQLITE_OK && p->pFrame ){ |
| 71608 | 71762 | /* Halt the sub-program. Return control to the parent frame. */ |
| 71609 | - VdbeFrame *pFrame = p->pFrame; | |
| 71763 | + pFrame = p->pFrame; | |
| 71610 | 71764 | p->pFrame = pFrame->pParent; |
| 71611 | 71765 | p->nFrame--; |
| 71612 | 71766 | sqlite3VdbeSetChanges(db, p->nChange); |
| 71613 | - pc = sqlite3VdbeFrameRestore(pFrame); | |
| 71767 | + pcx = sqlite3VdbeFrameRestore(pFrame); | |
| 71614 | 71768 | lastRowid = db->lastRowid; |
| 71615 | 71769 | if( pOp->p2==OE_Ignore ){ |
| 71616 | - /* Instruction pc is the OP_Program that invoked the sub-program | |
| 71770 | + /* Instruction pcx is the OP_Program that invoked the sub-program | |
| 71617 | 71771 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 71618 | 71772 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 71619 | 71773 | ** an IGNORE exception. In this case jump to the address specified |
| 71620 | 71774 | ** as the p2 of the calling OP_Program. */ |
| 71621 | - pc = p->aOp[pc].p2-1; | |
| 71775 | + pcx = p->aOp[pcx].p2-1; | |
| 71622 | 71776 | } |
| 71623 | 71777 | aOp = p->aOp; |
| 71624 | 71778 | aMem = p->aMem; |
| 71779 | + pOp = &aOp[pcx]; | |
| 71625 | 71780 | break; |
| 71626 | 71781 | } |
| 71627 | 71782 | p->rc = pOp->p1; |
| 71628 | 71783 | p->errorAction = (u8)pOp->p2; |
| 71629 | - p->pc = pc; | |
| 71784 | + p->pc = pcx; | |
| 71630 | 71785 | if( p->rc ){ |
| 71631 | 71786 | if( pOp->p5 ){ |
| 71632 | 71787 | static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK", |
| 71633 | 71788 | "FOREIGN KEY" }; |
| 71634 | 71789 | assert( pOp->p5>=1 && pOp->p5<=4 ); |
| @@ -71648,11 +71803,11 @@ | ||
| 71648 | 71803 | }else if( pOp->p4.z ){ |
| 71649 | 71804 | sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z); |
| 71650 | 71805 | }else{ |
| 71651 | 71806 | sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType); |
| 71652 | 71807 | } |
| 71653 | - sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg); | |
| 71808 | + sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg); | |
| 71654 | 71809 | } |
| 71655 | 71810 | rc = sqlite3VdbeHalt(p); |
| 71656 | 71811 | assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); |
| 71657 | 71812 | if( rc==SQLITE_BUSY ){ |
| 71658 | 71813 | p->rc = rc = SQLITE_BUSY; |
| @@ -71659,19 +71814,21 @@ | ||
| 71659 | 71814 | }else{ |
| 71660 | 71815 | assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ); |
| 71661 | 71816 | assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 ); |
| 71662 | 71817 | rc = p->rc ? SQLITE_ERROR : SQLITE_DONE; |
| 71663 | 71818 | } |
| 71819 | + pOp = &aOp[pcx]; | |
| 71664 | 71820 | goto vdbe_return; |
| 71665 | 71821 | } |
| 71666 | 71822 | |
| 71667 | 71823 | /* Opcode: Integer P1 P2 * * * |
| 71668 | 71824 | ** Synopsis: r[P2]=P1 |
| 71669 | 71825 | ** |
| 71670 | 71826 | ** The 32-bit integer value P1 is written into register P2. |
| 71671 | 71827 | */ |
| 71672 | -case OP_Integer: { /* out2-prerelease */ | |
| 71828 | +case OP_Integer: { /* out2 */ | |
| 71829 | + pOut = out2Prerelease(p, pOp); | |
| 71673 | 71830 | pOut->u.i = pOp->p1; |
| 71674 | 71831 | break; |
| 71675 | 71832 | } |
| 71676 | 71833 | |
| 71677 | 71834 | /* Opcode: Int64 * P2 * P4 * |
| @@ -71678,11 +71835,12 @@ | ||
| 71678 | 71835 | ** Synopsis: r[P2]=P4 |
| 71679 | 71836 | ** |
| 71680 | 71837 | ** P4 is a pointer to a 64-bit integer value. |
| 71681 | 71838 | ** Write that value into register P2. |
| 71682 | 71839 | */ |
| 71683 | -case OP_Int64: { /* out2-prerelease */ | |
| 71840 | +case OP_Int64: { /* out2 */ | |
| 71841 | + pOut = out2Prerelease(p, pOp); | |
| 71684 | 71842 | assert( pOp->p4.pI64!=0 ); |
| 71685 | 71843 | pOut->u.i = *pOp->p4.pI64; |
| 71686 | 71844 | break; |
| 71687 | 71845 | } |
| 71688 | 71846 | |
| @@ -71691,11 +71849,12 @@ | ||
| 71691 | 71849 | ** Synopsis: r[P2]=P4 |
| 71692 | 71850 | ** |
| 71693 | 71851 | ** P4 is a pointer to a 64-bit floating point value. |
| 71694 | 71852 | ** Write that value into register P2. |
| 71695 | 71853 | */ |
| 71696 | -case OP_Real: { /* same as TK_FLOAT, out2-prerelease */ | |
| 71854 | +case OP_Real: { /* same as TK_FLOAT, out2 */ | |
| 71855 | + pOut = out2Prerelease(p, pOp); | |
| 71697 | 71856 | pOut->flags = MEM_Real; |
| 71698 | 71857 | assert( !sqlite3IsNaN(*pOp->p4.pReal) ); |
| 71699 | 71858 | pOut->u.r = *pOp->p4.pReal; |
| 71700 | 71859 | break; |
| 71701 | 71860 | } |
| @@ -71707,12 +71866,13 @@ | ||
| 71707 | 71866 | ** P4 points to a nul terminated UTF-8 string. This opcode is transformed |
| 71708 | 71867 | ** into a String opcode before it is executed for the first time. During |
| 71709 | 71868 | ** this transformation, the length of string P4 is computed and stored |
| 71710 | 71869 | ** as the P1 parameter. |
| 71711 | 71870 | */ |
| 71712 | -case OP_String8: { /* same as TK_STRING, out2-prerelease */ | |
| 71871 | +case OP_String8: { /* same as TK_STRING, out2 */ | |
| 71713 | 71872 | assert( pOp->p4.z!=0 ); |
| 71873 | + pOut = out2Prerelease(p, pOp); | |
| 71714 | 71874 | pOp->opcode = OP_String; |
| 71715 | 71875 | pOp->p1 = sqlite3Strlen30(pOp->p4.z); |
| 71716 | 71876 | |
| 71717 | 71877 | #ifndef SQLITE_OMIT_UTF16 |
| 71718 | 71878 | if( encoding!=SQLITE_UTF8 ){ |
| @@ -71745,12 +71905,13 @@ | ||
| 71745 | 71905 | ** If P5!=0 and the content of register P3 is greater than zero, then |
| 71746 | 71906 | ** the datatype of the register P2 is converted to BLOB. The content is |
| 71747 | 71907 | ** the same sequence of bytes, it is merely interpreted as a BLOB instead |
| 71748 | 71908 | ** of a string, as if it had been CAST. |
| 71749 | 71909 | */ |
| 71750 | -case OP_String: { /* out2-prerelease */ | |
| 71910 | +case OP_String: { /* out2 */ | |
| 71751 | 71911 | assert( pOp->p4.z!=0 ); |
| 71912 | + pOut = out2Prerelease(p, pOp); | |
| 71752 | 71913 | pOut->flags = MEM_Str|MEM_Static|MEM_Term; |
| 71753 | 71914 | pOut->z = pOp->p4.z; |
| 71754 | 71915 | pOut->n = pOp->p1; |
| 71755 | 71916 | pOut->enc = encoding; |
| 71756 | 71917 | UPDATE_MAX_BLOBSIZE(pOut); |
| @@ -71774,13 +71935,14 @@ | ||
| 71774 | 71935 | ** |
| 71775 | 71936 | ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that |
| 71776 | 71937 | ** NULL values will not compare equal even if SQLITE_NULLEQ is set on |
| 71777 | 71938 | ** OP_Ne or OP_Eq. |
| 71778 | 71939 | */ |
| 71779 | -case OP_Null: { /* out2-prerelease */ | |
| 71940 | +case OP_Null: { /* out2 */ | |
| 71780 | 71941 | int cnt; |
| 71781 | 71942 | u16 nullFlag; |
| 71943 | + pOut = out2Prerelease(p, pOp); | |
| 71782 | 71944 | cnt = pOp->p3-pOp->p2; |
| 71783 | 71945 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 71784 | 71946 | pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; |
| 71785 | 71947 | while( cnt>0 ){ |
| 71786 | 71948 | pOut++; |
| @@ -71811,12 +71973,13 @@ | ||
| 71811 | 71973 | ** Synopsis: r[P2]=P4 (len=P1) |
| 71812 | 71974 | ** |
| 71813 | 71975 | ** P4 points to a blob of data P1 bytes long. Store this |
| 71814 | 71976 | ** blob in register P2. |
| 71815 | 71977 | */ |
| 71816 | -case OP_Blob: { /* out2-prerelease */ | |
| 71978 | +case OP_Blob: { /* out2 */ | |
| 71817 | 71979 | assert( pOp->p1 <= SQLITE_MAX_LENGTH ); |
| 71980 | + pOut = out2Prerelease(p, pOp); | |
| 71818 | 71981 | sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0); |
| 71819 | 71982 | pOut->enc = encoding; |
| 71820 | 71983 | UPDATE_MAX_BLOBSIZE(pOut); |
| 71821 | 71984 | break; |
| 71822 | 71985 | } |
| @@ -71827,19 +71990,20 @@ | ||
| 71827 | 71990 | ** Transfer the values of bound parameter P1 into register P2 |
| 71828 | 71991 | ** |
| 71829 | 71992 | ** If the parameter is named, then its name appears in P4. |
| 71830 | 71993 | ** The P4 value is used by sqlite3_bind_parameter_name(). |
| 71831 | 71994 | */ |
| 71832 | -case OP_Variable: { /* out2-prerelease */ | |
| 71995 | +case OP_Variable: { /* out2 */ | |
| 71833 | 71996 | Mem *pVar; /* Value being transferred */ |
| 71834 | 71997 | |
| 71835 | 71998 | assert( pOp->p1>0 && pOp->p1<=p->nVar ); |
| 71836 | 71999 | assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] ); |
| 71837 | 72000 | pVar = &p->aVar[pOp->p1 - 1]; |
| 71838 | 72001 | if( sqlite3VdbeMemTooBig(pVar) ){ |
| 71839 | 72002 | goto too_big; |
| 71840 | 72003 | } |
| 72004 | + pOut = out2Prerelease(p, pOp); | |
| 71841 | 72005 | sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); |
| 71842 | 72006 | UPDATE_MAX_BLOBSIZE(pOut); |
| 71843 | 72007 | break; |
| 71844 | 72008 | } |
| 71845 | 72009 | |
| @@ -71870,14 +72034,15 @@ | ||
| 71870 | 72034 | assert( pIn1<=&aMem[(p->nMem-p->nCursor)] ); |
| 71871 | 72035 | assert( memIsValid(pIn1) ); |
| 71872 | 72036 | memAboutToChange(p, pOut); |
| 71873 | 72037 | sqlite3VdbeMemMove(pOut, pIn1); |
| 71874 | 72038 | #ifdef SQLITE_DEBUG |
| 71875 | - if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){ | |
| 71876 | - pOut->pScopyFrom += p1 - pOp->p2; | |
| 72039 | + if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){ | |
| 72040 | + pOut->pScopyFrom += pOp->p2 - p1; | |
| 71877 | 72041 | } |
| 71878 | 72042 | #endif |
| 72043 | + Deephemeralize(pOut); | |
| 71879 | 72044 | REGISTER_TRACE(p2++, pOut); |
| 71880 | 72045 | pIn1++; |
| 71881 | 72046 | pOut++; |
| 71882 | 72047 | }while( --n ); |
| 71883 | 72048 | break; |
| @@ -72012,11 +72177,11 @@ | ||
| 72012 | 72177 | } |
| 72013 | 72178 | if( db->mallocFailed ) goto no_mem; |
| 72014 | 72179 | |
| 72015 | 72180 | /* Return SQLITE_ROW |
| 72016 | 72181 | */ |
| 72017 | - p->pc = pc + 1; | |
| 72182 | + p->pc = (int)(pOp - aOp) + 1; | |
| 72018 | 72183 | rc = SQLITE_ROW; |
| 72019 | 72184 | goto vdbe_return; |
| 72020 | 72185 | } |
| 72021 | 72186 | |
| 72022 | 72187 | /* Opcode: Concat P1 P2 P3 * * |
| @@ -72258,11 +72423,11 @@ | ||
| 72258 | 72423 | REGISTER_TRACE(pOp->p2+i, pArg); |
| 72259 | 72424 | } |
| 72260 | 72425 | |
| 72261 | 72426 | assert( pOp->p4type==P4_FUNCDEF ); |
| 72262 | 72427 | ctx.pFunc = pOp->p4.pFunc; |
| 72263 | - ctx.iOp = pc; | |
| 72428 | + ctx.iOp = (int)(pOp - aOp); | |
| 72264 | 72429 | ctx.pVdbe = p; |
| 72265 | 72430 | MemSetTypeFlag(ctx.pOut, MEM_Null); |
| 72266 | 72431 | ctx.fErrorOrAux = 0; |
| 72267 | 72432 | db->lastRowid = lastRowid; |
| 72268 | 72433 | (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */ |
| @@ -72272,11 +72437,11 @@ | ||
| 72272 | 72437 | if( ctx.fErrorOrAux ){ |
| 72273 | 72438 | if( ctx.isError ){ |
| 72274 | 72439 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut)); |
| 72275 | 72440 | rc = ctx.isError; |
| 72276 | 72441 | } |
| 72277 | - sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); | |
| 72442 | + sqlite3VdbeDeleteAuxData(p, (int)(pOp - aOp), pOp->p1); | |
| 72278 | 72443 | } |
| 72279 | 72444 | |
| 72280 | 72445 | /* Copy the result of the function into register P3 */ |
| 72281 | 72446 | sqlite3VdbeChangeEncoding(ctx.pOut, encoding); |
| 72282 | 72447 | if( sqlite3VdbeMemTooBig(ctx.pOut) ){ |
| @@ -72401,12 +72566,11 @@ | ||
| 72401 | 72566 | if( (pIn1->flags & MEM_Int)==0 ){ |
| 72402 | 72567 | if( pOp->p2==0 ){ |
| 72403 | 72568 | rc = SQLITE_MISMATCH; |
| 72404 | 72569 | goto abort_due_to_error; |
| 72405 | 72570 | }else{ |
| 72406 | - pc = pOp->p2 - 1; | |
| 72407 | - break; | |
| 72571 | + goto jump_to_p2; | |
| 72408 | 72572 | } |
| 72409 | 72573 | } |
| 72410 | 72574 | } |
| 72411 | 72575 | MemSetTypeFlag(pIn1, MEM_Int); |
| 72412 | 72576 | break; |
| @@ -72588,11 +72752,11 @@ | ||
| 72588 | 72752 | MemSetTypeFlag(pOut, MEM_Null); |
| 72589 | 72753 | REGISTER_TRACE(pOp->p2, pOut); |
| 72590 | 72754 | }else{ |
| 72591 | 72755 | VdbeBranchTaken(2,3); |
| 72592 | 72756 | if( pOp->p5 & SQLITE_JUMPIFNULL ){ |
| 72593 | - pc = pOp->p2-1; | |
| 72757 | + goto jump_to_p2; | |
| 72594 | 72758 | } |
| 72595 | 72759 | } |
| 72596 | 72760 | break; |
| 72597 | 72761 | } |
| 72598 | 72762 | }else{ |
| @@ -72639,10 +72803,16 @@ | ||
| 72639 | 72803 | case OP_Lt: res = res<0; break; |
| 72640 | 72804 | case OP_Le: res = res<=0; break; |
| 72641 | 72805 | case OP_Gt: res = res>0; break; |
| 72642 | 72806 | default: res = res>=0; break; |
| 72643 | 72807 | } |
| 72808 | + | |
| 72809 | + /* Undo any changes made by applyAffinity() to the input registers. */ | |
| 72810 | + assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) ); | |
| 72811 | + pIn1->flags = flags1; | |
| 72812 | + assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) ); | |
| 72813 | + pIn3->flags = flags3; | |
| 72644 | 72814 | |
| 72645 | 72815 | if( pOp->p5 & SQLITE_STOREP2 ){ |
| 72646 | 72816 | pOut = &aMem[pOp->p2]; |
| 72647 | 72817 | memAboutToChange(p, pOut); |
| 72648 | 72818 | MemSetTypeFlag(pOut, MEM_Int); |
| @@ -72649,18 +72819,13 @@ | ||
| 72649 | 72819 | pOut->u.i = res; |
| 72650 | 72820 | REGISTER_TRACE(pOp->p2, pOut); |
| 72651 | 72821 | }else{ |
| 72652 | 72822 | VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3); |
| 72653 | 72823 | if( res ){ |
| 72654 | - pc = pOp->p2-1; | |
| 72824 | + goto jump_to_p2; | |
| 72655 | 72825 | } |
| 72656 | 72826 | } |
| 72657 | - /* Undo any changes made by applyAffinity() to the input registers. */ | |
| 72658 | - assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) ); | |
| 72659 | - pIn1->flags = flags1; | |
| 72660 | - assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) ); | |
| 72661 | - pIn3->flags = flags3; | |
| 72662 | 72827 | break; |
| 72663 | 72828 | } |
| 72664 | 72829 | |
| 72665 | 72830 | /* Opcode: Permutation * * * P4 * |
| 72666 | 72831 | ** |
| @@ -72751,15 +72916,15 @@ | ||
| 72751 | 72916 | ** in the most recent OP_Compare instruction the P1 vector was less than |
| 72752 | 72917 | ** equal to, or greater than the P2 vector, respectively. |
| 72753 | 72918 | */ |
| 72754 | 72919 | case OP_Jump: { /* jump */ |
| 72755 | 72920 | if( iCompare<0 ){ |
| 72756 | - pc = pOp->p1 - 1; VdbeBranchTaken(0,3); | |
| 72921 | + VdbeBranchTaken(0,3); pOp = &aOp[pOp->p1 - 1]; | |
| 72757 | 72922 | }else if( iCompare==0 ){ |
| 72758 | - pc = pOp->p2 - 1; VdbeBranchTaken(1,3); | |
| 72923 | + VdbeBranchTaken(1,3); pOp = &aOp[pOp->p2 - 1]; | |
| 72759 | 72924 | }else{ |
| 72760 | - pc = pOp->p3 - 1; VdbeBranchTaken(2,3); | |
| 72925 | + VdbeBranchTaken(2,3); pOp = &aOp[pOp->p3 - 1]; | |
| 72761 | 72926 | } |
| 72762 | 72927 | break; |
| 72763 | 72928 | } |
| 72764 | 72929 | |
| 72765 | 72930 | /* Opcode: And P1 P2 P3 * * |
| @@ -72865,11 +73030,11 @@ | ||
| 72865 | 73030 | */ |
| 72866 | 73031 | case OP_Once: { /* jump */ |
| 72867 | 73032 | assert( pOp->p1<p->nOnceFlag ); |
| 72868 | 73033 | VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2); |
| 72869 | 73034 | if( p->aOnceFlag[pOp->p1] ){ |
| 72870 | - pc = pOp->p2-1; | |
| 73035 | + goto jump_to_p2; | |
| 72871 | 73036 | }else{ |
| 72872 | 73037 | p->aOnceFlag[pOp->p1] = 1; |
| 72873 | 73038 | } |
| 72874 | 73039 | break; |
| 72875 | 73040 | } |
| @@ -72900,11 +73065,11 @@ | ||
| 72900 | 73065 | #endif |
| 72901 | 73066 | if( pOp->opcode==OP_IfNot ) c = !c; |
| 72902 | 73067 | } |
| 72903 | 73068 | VdbeBranchTaken(c!=0, 2); |
| 72904 | 73069 | if( c ){ |
| 72905 | - pc = pOp->p2-1; | |
| 73070 | + goto jump_to_p2; | |
| 72906 | 73071 | } |
| 72907 | 73072 | break; |
| 72908 | 73073 | } |
| 72909 | 73074 | |
| 72910 | 73075 | /* Opcode: IsNull P1 P2 * * * |
| @@ -72914,11 +73079,11 @@ | ||
| 72914 | 73079 | */ |
| 72915 | 73080 | case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */ |
| 72916 | 73081 | pIn1 = &aMem[pOp->p1]; |
| 72917 | 73082 | VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2); |
| 72918 | 73083 | if( (pIn1->flags & MEM_Null)!=0 ){ |
| 72919 | - pc = pOp->p2 - 1; | |
| 73084 | + goto jump_to_p2; | |
| 72920 | 73085 | } |
| 72921 | 73086 | break; |
| 72922 | 73087 | } |
| 72923 | 73088 | |
| 72924 | 73089 | /* Opcode: NotNull P1 P2 * * * |
| @@ -72928,11 +73093,11 @@ | ||
| 72928 | 73093 | */ |
| 72929 | 73094 | case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */ |
| 72930 | 73095 | pIn1 = &aMem[pOp->p1]; |
| 72931 | 73096 | VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2); |
| 72932 | 73097 | if( (pIn1->flags & MEM_Null)==0 ){ |
| 72933 | - pc = pOp->p2 - 1; | |
| 73098 | + goto jump_to_p2; | |
| 72934 | 73099 | } |
| 72935 | 73100 | break; |
| 72936 | 73101 | } |
| 72937 | 73102 | |
| 72938 | 73103 | /* Opcode: Column P1 P2 P3 P4 P5 |
| @@ -73142,11 +73307,11 @@ | ||
| 73142 | 73307 | rc = SQLITE_CORRUPT_BKPT; |
| 73143 | 73308 | goto op_column_error; |
| 73144 | 73309 | } |
| 73145 | 73310 | } |
| 73146 | 73311 | |
| 73147 | - /* If after trying to extra new entries from the header, nHdrParsed is | |
| 73312 | + /* If after trying to extract new entries from the header, nHdrParsed is | |
| 73148 | 73313 | ** still not up to p2, that means that the record has fewer than p2 |
| 73149 | 73314 | ** columns. So the result will be either the default value or a NULL. |
| 73150 | 73315 | */ |
| 73151 | 73316 | if( pC->nHdrParsed<=p2 ){ |
| 73152 | 73317 | if( pOp->p4type==P4_MEM ){ |
| @@ -73266,11 +73431,11 @@ | ||
| 73266 | 73431 | u8 *zNewRecord; /* A buffer to hold the data for the new record */ |
| 73267 | 73432 | Mem *pRec; /* The new record */ |
| 73268 | 73433 | u64 nData; /* Number of bytes of data space */ |
| 73269 | 73434 | int nHdr; /* Number of bytes of header space */ |
| 73270 | 73435 | i64 nByte; /* Data space required for this record */ |
| 73271 | - int nZero; /* Number of zero bytes at the end of the record */ | |
| 73436 | + i64 nZero; /* Number of zero bytes at the end of the record */ | |
| 73272 | 73437 | int nVarint; /* Number of bytes in a varint */ |
| 73273 | 73438 | u32 serial_type; /* Type field */ |
| 73274 | 73439 | Mem *pData0; /* First field to be combined into the record */ |
| 73275 | 73440 | Mem *pLast; /* Last field of the record */ |
| 73276 | 73441 | int nField; /* Number of fields in the record */ |
| @@ -73358,11 +73523,11 @@ | ||
| 73358 | 73523 | nVarint = sqlite3VarintLen(nHdr); |
| 73359 | 73524 | nHdr += nVarint; |
| 73360 | 73525 | if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++; |
| 73361 | 73526 | } |
| 73362 | 73527 | nByte = nHdr+nData; |
| 73363 | - if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 73528 | + if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 73364 | 73529 | goto too_big; |
| 73365 | 73530 | } |
| 73366 | 73531 | |
| 73367 | 73532 | /* Make sure the output register has a buffer large enough to store |
| 73368 | 73533 | ** the new record. The output register (pOp->p3) is not allowed to |
| @@ -73409,18 +73574,19 @@ | ||
| 73409 | 73574 | ** |
| 73410 | 73575 | ** Store the number of entries (an integer value) in the table or index |
| 73411 | 73576 | ** opened by cursor P1 in register P2 |
| 73412 | 73577 | */ |
| 73413 | 73578 | #ifndef SQLITE_OMIT_BTREECOUNT |
| 73414 | -case OP_Count: { /* out2-prerelease */ | |
| 73579 | +case OP_Count: { /* out2 */ | |
| 73415 | 73580 | i64 nEntry; |
| 73416 | 73581 | BtCursor *pCrsr; |
| 73417 | 73582 | |
| 73418 | 73583 | pCrsr = p->apCsr[pOp->p1]->pCursor; |
| 73419 | 73584 | assert( pCrsr ); |
| 73420 | 73585 | nEntry = 0; /* Not needed. Only used to silence a warning. */ |
| 73421 | 73586 | rc = sqlite3BtreeCount(pCrsr, &nEntry); |
| 73587 | + pOut = out2Prerelease(p, pOp); | |
| 73422 | 73588 | pOut->u.i = nEntry; |
| 73423 | 73589 | break; |
| 73424 | 73590 | } |
| 73425 | 73591 | #endif |
| 73426 | 73592 | |
| @@ -73530,11 +73696,11 @@ | ||
| 73530 | 73696 | if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 73531 | 73697 | goto vdbe_return; |
| 73532 | 73698 | } |
| 73533 | 73699 | db->autoCommit = 1; |
| 73534 | 73700 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 73535 | - p->pc = pc; | |
| 73701 | + p->pc = (int)(pOp - aOp); | |
| 73536 | 73702 | db->autoCommit = 0; |
| 73537 | 73703 | p->rc = rc = SQLITE_BUSY; |
| 73538 | 73704 | goto vdbe_return; |
| 73539 | 73705 | } |
| 73540 | 73706 | db->isTransactionSavepoint = 0; |
| @@ -73589,11 +73755,11 @@ | ||
| 73589 | 73755 | }else{ |
| 73590 | 73756 | db->nDeferredCons = pSavepoint->nDeferredCons; |
| 73591 | 73757 | db->nDeferredImmCons = pSavepoint->nDeferredImmCons; |
| 73592 | 73758 | } |
| 73593 | 73759 | |
| 73594 | - if( !isTransaction ){ | |
| 73760 | + if( !isTransaction || p1==SAVEPOINT_ROLLBACK ){ | |
| 73595 | 73761 | rc = sqlite3VtabSavepoint(db, p1, iSavepoint); |
| 73596 | 73762 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 73597 | 73763 | } |
| 73598 | 73764 | } |
| 73599 | 73765 | } |
| @@ -73649,11 +73815,11 @@ | ||
| 73649 | 73815 | }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 73650 | 73816 | goto vdbe_return; |
| 73651 | 73817 | }else{ |
| 73652 | 73818 | db->autoCommit = (u8)desiredAutoCommit; |
| 73653 | 73819 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 73654 | - p->pc = pc; | |
| 73820 | + p->pc = (int)(pOp - aOp); | |
| 73655 | 73821 | db->autoCommit = (u8)(1-desiredAutoCommit); |
| 73656 | 73822 | p->rc = rc = SQLITE_BUSY; |
| 73657 | 73823 | goto vdbe_return; |
| 73658 | 73824 | } |
| 73659 | 73825 | } |
| @@ -73726,11 +73892,11 @@ | ||
| 73726 | 73892 | pBt = db->aDb[pOp->p1].pBt; |
| 73727 | 73893 | |
| 73728 | 73894 | if( pBt ){ |
| 73729 | 73895 | rc = sqlite3BtreeBeginTrans(pBt, pOp->p2); |
| 73730 | 73896 | if( rc==SQLITE_BUSY ){ |
| 73731 | - p->pc = pc; | |
| 73897 | + p->pc = (int)(pOp - aOp); | |
| 73732 | 73898 | p->rc = rc = SQLITE_BUSY; |
| 73733 | 73899 | goto vdbe_return; |
| 73734 | 73900 | } |
| 73735 | 73901 | if( rc!=SQLITE_OK ){ |
| 73736 | 73902 | goto abort_due_to_error; |
| @@ -73805,11 +73971,11 @@ | ||
| 73805 | 73971 | ** |
| 73806 | 73972 | ** There must be a read-lock on the database (either a transaction |
| 73807 | 73973 | ** must be started or there must be an open cursor) before |
| 73808 | 73974 | ** executing this instruction. |
| 73809 | 73975 | */ |
| 73810 | -case OP_ReadCookie: { /* out2-prerelease */ | |
| 73976 | +case OP_ReadCookie: { /* out2 */ | |
| 73811 | 73977 | int iMeta; |
| 73812 | 73978 | int iDb; |
| 73813 | 73979 | int iCookie; |
| 73814 | 73980 | |
| 73815 | 73981 | assert( p->bIsReader ); |
| @@ -73819,10 +73985,11 @@ | ||
| 73819 | 73985 | assert( iDb>=0 && iDb<db->nDb ); |
| 73820 | 73986 | assert( db->aDb[iDb].pBt!=0 ); |
| 73821 | 73987 | assert( DbMaskTest(p->btreeMask, iDb) ); |
| 73822 | 73988 | |
| 73823 | 73989 | sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta); |
| 73990 | + pOut = out2Prerelease(p, pOp); | |
| 73824 | 73991 | pOut->u.i = iMeta; |
| 73825 | 73992 | break; |
| 73826 | 73993 | } |
| 73827 | 73994 | |
| 73828 | 73995 | /* Opcode: SetCookie P1 P2 P3 * * |
| @@ -74140,11 +74307,11 @@ | ||
| 74140 | 74307 | VdbeCursor *pC; |
| 74141 | 74308 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 74142 | 74309 | pC = p->apCsr[pOp->p1]; |
| 74143 | 74310 | assert( pC->pSorter ); |
| 74144 | 74311 | if( (pC->seqCount++)==0 ){ |
| 74145 | - pc = pOp->p2 - 1; | |
| 74312 | + goto jump_to_p2; | |
| 74146 | 74313 | } |
| 74147 | 74314 | break; |
| 74148 | 74315 | } |
| 74149 | 74316 | |
| 74150 | 74317 | /* Opcode: OpenPseudo P1 P2 P3 * * |
| @@ -74317,11 +74484,11 @@ | ||
| 74317 | 74484 | ** loss of information, then special processing is required... */ |
| 74318 | 74485 | if( (pIn3->flags & MEM_Int)==0 ){ |
| 74319 | 74486 | if( (pIn3->flags & MEM_Real)==0 ){ |
| 74320 | 74487 | /* If the P3 value cannot be converted into any kind of a number, |
| 74321 | 74488 | ** then the seek is not possible, so jump to P2 */ |
| 74322 | - pc = pOp->p2 - 1; VdbeBranchTaken(1,2); | |
| 74489 | + VdbeBranchTaken(1,2); goto jump_to_p2; | |
| 74323 | 74490 | break; |
| 74324 | 74491 | } |
| 74325 | 74492 | |
| 74326 | 74493 | /* If the approximation iKey is larger than the actual real search |
| 74327 | 74494 | ** term, substitute >= for > and < for <=. e.g. if the search term |
| @@ -74408,11 +74575,11 @@ | ||
| 74408 | 74575 | } |
| 74409 | 74576 | } |
| 74410 | 74577 | assert( pOp->p2>0 ); |
| 74411 | 74578 | VdbeBranchTaken(res!=0,2); |
| 74412 | 74579 | if( res ){ |
| 74413 | - pc = pOp->p2 - 1; | |
| 74580 | + goto jump_to_p2; | |
| 74414 | 74581 | } |
| 74415 | 74582 | break; |
| 74416 | 74583 | } |
| 74417 | 74584 | |
| 74418 | 74585 | /* Opcode: Seek P1 P2 * * * |
| @@ -74502,10 +74669,11 @@ | ||
| 74502 | 74669 | */ |
| 74503 | 74670 | case OP_NoConflict: /* jump, in3 */ |
| 74504 | 74671 | case OP_NotFound: /* jump, in3 */ |
| 74505 | 74672 | case OP_Found: { /* jump, in3 */ |
| 74506 | 74673 | int alreadyExists; |
| 74674 | + int takeJump; | |
| 74507 | 74675 | int ii; |
| 74508 | 74676 | VdbeCursor *pC; |
| 74509 | 74677 | int res; |
| 74510 | 74678 | char *pFree; |
| 74511 | 74679 | UnpackedRecord *pIdxKey; |
| @@ -74524,11 +74692,11 @@ | ||
| 74524 | 74692 | pC->seekOp = pOp->opcode; |
| 74525 | 74693 | #endif |
| 74526 | 74694 | pIn3 = &aMem[pOp->p3]; |
| 74527 | 74695 | assert( pC->pCursor!=0 ); |
| 74528 | 74696 | assert( pC->isTable==0 ); |
| 74529 | - pFree = 0; /* Not needed. Only used to suppress a compiler warning. */ | |
| 74697 | + pFree = 0; | |
| 74530 | 74698 | if( pOp->p4.i>0 ){ |
| 74531 | 74699 | r.pKeyInfo = pC->pKeyInfo; |
| 74532 | 74700 | r.nField = (u16)pOp->p4.i; |
| 74533 | 74701 | r.aMem = pIn3; |
| 74534 | 74702 | for(ii=0; ii<r.nField; ii++){ |
| @@ -74547,25 +74715,24 @@ | ||
| 74547 | 74715 | assert( pIn3->flags & MEM_Blob ); |
| 74548 | 74716 | ExpandBlob(pIn3); |
| 74549 | 74717 | sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); |
| 74550 | 74718 | } |
| 74551 | 74719 | pIdxKey->default_rc = 0; |
| 74720 | + takeJump = 0; | |
| 74552 | 74721 | if( pOp->opcode==OP_NoConflict ){ |
| 74553 | 74722 | /* For the OP_NoConflict opcode, take the jump if any of the |
| 74554 | 74723 | ** input fields are NULL, since any key with a NULL will not |
| 74555 | 74724 | ** conflict */ |
| 74556 | 74725 | for(ii=0; ii<pIdxKey->nField; ii++){ |
| 74557 | 74726 | if( pIdxKey->aMem[ii].flags & MEM_Null ){ |
| 74558 | - pc = pOp->p2 - 1; VdbeBranchTaken(1,2); | |
| 74727 | + takeJump = 1; | |
| 74559 | 74728 | break; |
| 74560 | 74729 | } |
| 74561 | 74730 | } |
| 74562 | 74731 | } |
| 74563 | 74732 | rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res); |
| 74564 | - if( pOp->p4.i==0 ){ | |
| 74565 | - sqlite3DbFree(db, pFree); | |
| 74566 | - } | |
| 74733 | + sqlite3DbFree(db, pFree); | |
| 74567 | 74734 | if( rc!=SQLITE_OK ){ |
| 74568 | 74735 | break; |
| 74569 | 74736 | } |
| 74570 | 74737 | pC->seekResult = res; |
| 74571 | 74738 | alreadyExists = (res==0); |
| @@ -74572,14 +74739,14 @@ | ||
| 74572 | 74739 | pC->nullRow = 1-alreadyExists; |
| 74573 | 74740 | pC->deferredMoveto = 0; |
| 74574 | 74741 | pC->cacheStatus = CACHE_STALE; |
| 74575 | 74742 | if( pOp->opcode==OP_Found ){ |
| 74576 | 74743 | VdbeBranchTaken(alreadyExists!=0,2); |
| 74577 | - if( alreadyExists ) pc = pOp->p2 - 1; | |
| 74744 | + if( alreadyExists ) goto jump_to_p2; | |
| 74578 | 74745 | }else{ |
| 74579 | - VdbeBranchTaken(alreadyExists==0,2); | |
| 74580 | - if( !alreadyExists ) pc = pOp->p2 - 1; | |
| 74746 | + VdbeBranchTaken(takeJump||alreadyExists==0,2); | |
| 74747 | + if( takeJump || !alreadyExists ) goto jump_to_p2; | |
| 74581 | 74748 | } |
| 74582 | 74749 | break; |
| 74583 | 74750 | } |
| 74584 | 74751 | |
| 74585 | 74752 | /* Opcode: NotExists P1 P2 P3 * * |
| @@ -74624,14 +74791,12 @@ | ||
| 74624 | 74791 | pC->movetoTarget = iKey; /* Used by OP_Delete */ |
| 74625 | 74792 | pC->nullRow = 0; |
| 74626 | 74793 | pC->cacheStatus = CACHE_STALE; |
| 74627 | 74794 | pC->deferredMoveto = 0; |
| 74628 | 74795 | VdbeBranchTaken(res!=0,2); |
| 74629 | - if( res!=0 ){ | |
| 74630 | - pc = pOp->p2 - 1; | |
| 74631 | - } | |
| 74632 | 74796 | pC->seekResult = res; |
| 74797 | + if( res!=0 ) goto jump_to_p2; | |
| 74633 | 74798 | break; |
| 74634 | 74799 | } |
| 74635 | 74800 | |
| 74636 | 74801 | /* Opcode: Sequence P1 P2 * * * |
| 74637 | 74802 | ** Synopsis: r[P2]=cursor[P1].ctr++ |
| @@ -74639,13 +74804,14 @@ | ||
| 74639 | 74804 | ** Find the next available sequence number for cursor P1. |
| 74640 | 74805 | ** Write the sequence number into register P2. |
| 74641 | 74806 | ** The sequence number on the cursor is incremented after this |
| 74642 | 74807 | ** instruction. |
| 74643 | 74808 | */ |
| 74644 | -case OP_Sequence: { /* out2-prerelease */ | |
| 74809 | +case OP_Sequence: { /* out2 */ | |
| 74645 | 74810 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 74646 | 74811 | assert( p->apCsr[pOp->p1]!=0 ); |
| 74812 | + pOut = out2Prerelease(p, pOp); | |
| 74647 | 74813 | pOut->u.i = p->apCsr[pOp->p1]->seqCount++; |
| 74648 | 74814 | break; |
| 74649 | 74815 | } |
| 74650 | 74816 | |
| 74651 | 74817 | |
| @@ -74662,20 +74828,21 @@ | ||
| 74662 | 74828 | ** allowed to be less than this value. When this value reaches its maximum, |
| 74663 | 74829 | ** an SQLITE_FULL error is generated. The P3 register is updated with the ' |
| 74664 | 74830 | ** generated record number. This P3 mechanism is used to help implement the |
| 74665 | 74831 | ** AUTOINCREMENT feature. |
| 74666 | 74832 | */ |
| 74667 | -case OP_NewRowid: { /* out2-prerelease */ | |
| 74833 | +case OP_NewRowid: { /* out2 */ | |
| 74668 | 74834 | i64 v; /* The new rowid */ |
| 74669 | 74835 | VdbeCursor *pC; /* Cursor of table to get the new rowid */ |
| 74670 | 74836 | int res; /* Result of an sqlite3BtreeLast() */ |
| 74671 | 74837 | int cnt; /* Counter to limit the number of searches */ |
| 74672 | 74838 | Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ |
| 74673 | 74839 | VdbeFrame *pFrame; /* Root frame of VDBE */ |
| 74674 | 74840 | |
| 74675 | 74841 | v = 0; |
| 74676 | 74842 | res = 0; |
| 74843 | + pOut = out2Prerelease(p, pOp); | |
| 74677 | 74844 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 74678 | 74845 | pC = p->apCsr[pOp->p1]; |
| 74679 | 74846 | assert( pC!=0 ); |
| 74680 | 74847 | if( NEVER(pC->pCursor==0) ){ |
| 74681 | 74848 | /* The zero initialization above is all that is needed */ |
| @@ -74985,13 +75152,11 @@ | ||
| 74985 | 75152 | pIn3 = &aMem[pOp->p3]; |
| 74986 | 75153 | nKeyCol = pOp->p4.i; |
| 74987 | 75154 | res = 0; |
| 74988 | 75155 | rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res); |
| 74989 | 75156 | VdbeBranchTaken(res!=0,2); |
| 74990 | - if( res ){ | |
| 74991 | - pc = pOp->p2-1; | |
| 74992 | - } | |
| 75157 | + if( res ) goto jump_to_p2; | |
| 74993 | 75158 | break; |
| 74994 | 75159 | }; |
| 74995 | 75160 | |
| 74996 | 75161 | /* Opcode: SorterData P1 P2 P3 * * |
| 74997 | 75162 | ** Synopsis: r[P2]=data |
| @@ -75116,16 +75281,17 @@ | ||
| 75116 | 75281 | ** |
| 75117 | 75282 | ** P1 can be either an ordinary table or a virtual table. There used to |
| 75118 | 75283 | ** be a separate OP_VRowid opcode for use with virtual tables, but this |
| 75119 | 75284 | ** one opcode now works for both table types. |
| 75120 | 75285 | */ |
| 75121 | -case OP_Rowid: { /* out2-prerelease */ | |
| 75286 | +case OP_Rowid: { /* out2 */ | |
| 75122 | 75287 | VdbeCursor *pC; |
| 75123 | 75288 | i64 v; |
| 75124 | 75289 | sqlite3_vtab *pVtab; |
| 75125 | 75290 | const sqlite3_module *pModule; |
| 75126 | 75291 | |
| 75292 | + pOut = out2Prerelease(p, pOp); | |
| 75127 | 75293 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 75128 | 75294 | pC = p->apCsr[pOp->p1]; |
| 75129 | 75295 | assert( pC!=0 ); |
| 75130 | 75296 | assert( pC->pseudoTableReg==0 || pC->nullRow ); |
| 75131 | 75297 | if( pC->nullRow ){ |
| @@ -75174,11 +75340,11 @@ | ||
| 75174 | 75340 | sqlite3BtreeClearCursor(pC->pCursor); |
| 75175 | 75341 | } |
| 75176 | 75342 | break; |
| 75177 | 75343 | } |
| 75178 | 75344 | |
| 75179 | -/* Opcode: Last P1 P2 * * * | |
| 75345 | +/* Opcode: Last P1 P2 P3 * * | |
| 75180 | 75346 | ** |
| 75181 | 75347 | ** The next use of the Rowid or Column or Prev instruction for P1 |
| 75182 | 75348 | ** will refer to the last entry in the database table or index. |
| 75183 | 75349 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 75184 | 75350 | ** If P2 is 0 or if the table or index is not empty, fall through |
| @@ -75201,16 +75367,17 @@ | ||
| 75201 | 75367 | assert( pCrsr!=0 ); |
| 75202 | 75368 | rc = sqlite3BtreeLast(pCrsr, &res); |
| 75203 | 75369 | pC->nullRow = (u8)res; |
| 75204 | 75370 | pC->deferredMoveto = 0; |
| 75205 | 75371 | pC->cacheStatus = CACHE_STALE; |
| 75372 | + pC->seekResult = pOp->p3; | |
| 75206 | 75373 | #ifdef SQLITE_DEBUG |
| 75207 | 75374 | pC->seekOp = OP_Last; |
| 75208 | 75375 | #endif |
| 75209 | 75376 | if( pOp->p2>0 ){ |
| 75210 | 75377 | VdbeBranchTaken(res!=0,2); |
| 75211 | - if( res ) pc = pOp->p2 - 1; | |
| 75378 | + if( res ) goto jump_to_p2; | |
| 75212 | 75379 | } |
| 75213 | 75380 | break; |
| 75214 | 75381 | } |
| 75215 | 75382 | |
| 75216 | 75383 | |
| @@ -75270,13 +75437,11 @@ | ||
| 75270 | 75437 | pC->cacheStatus = CACHE_STALE; |
| 75271 | 75438 | } |
| 75272 | 75439 | pC->nullRow = (u8)res; |
| 75273 | 75440 | assert( pOp->p2>0 && pOp->p2<p->nOp ); |
| 75274 | 75441 | VdbeBranchTaken(res!=0,2); |
| 75275 | - if( res ){ | |
| 75276 | - pc = pOp->p2 - 1; | |
| 75277 | - } | |
| 75442 | + if( res ) goto jump_to_p2; | |
| 75278 | 75443 | break; |
| 75279 | 75444 | } |
| 75280 | 75445 | |
| 75281 | 75446 | /* Opcode: Next P1 P2 P3 P4 P5 |
| 75282 | 75447 | ** |
| @@ -75383,15 +75548,15 @@ | ||
| 75383 | 75548 | next_tail: |
| 75384 | 75549 | pC->cacheStatus = CACHE_STALE; |
| 75385 | 75550 | VdbeBranchTaken(res==0,2); |
| 75386 | 75551 | if( res==0 ){ |
| 75387 | 75552 | pC->nullRow = 0; |
| 75388 | - pc = pOp->p2 - 1; | |
| 75389 | 75553 | p->aCounter[pOp->p5]++; |
| 75390 | 75554 | #ifdef SQLITE_TEST |
| 75391 | 75555 | sqlite3_search_count++; |
| 75392 | 75556 | #endif |
| 75557 | + goto jump_to_p2_and_check_for_interrupt; | |
| 75393 | 75558 | }else{ |
| 75394 | 75559 | pC->nullRow = 1; |
| 75395 | 75560 | } |
| 75396 | 75561 | goto check_for_interrupt; |
| 75397 | 75562 | } |
| @@ -75495,15 +75660,16 @@ | ||
| 75495 | 75660 | ** the end of the index key pointed to by cursor P1. This integer should be |
| 75496 | 75661 | ** the rowid of the table entry to which this index entry points. |
| 75497 | 75662 | ** |
| 75498 | 75663 | ** See also: Rowid, MakeRecord. |
| 75499 | 75664 | */ |
| 75500 | -case OP_IdxRowid: { /* out2-prerelease */ | |
| 75665 | +case OP_IdxRowid: { /* out2 */ | |
| 75501 | 75666 | BtCursor *pCrsr; |
| 75502 | 75667 | VdbeCursor *pC; |
| 75503 | 75668 | i64 rowid; |
| 75504 | 75669 | |
| 75670 | + pOut = out2Prerelease(p, pOp); | |
| 75505 | 75671 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 75506 | 75672 | pC = p->apCsr[pOp->p1]; |
| 75507 | 75673 | assert( pC!=0 ); |
| 75508 | 75674 | pCrsr = pC->pCursor; |
| 75509 | 75675 | assert( pCrsr!=0 ); |
| @@ -75612,13 +75778,11 @@ | ||
| 75612 | 75778 | }else{ |
| 75613 | 75779 | assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT ); |
| 75614 | 75780 | res++; |
| 75615 | 75781 | } |
| 75616 | 75782 | VdbeBranchTaken(res>0,2); |
| 75617 | - if( res>0 ){ | |
| 75618 | - pc = pOp->p2 - 1 ; | |
| 75619 | - } | |
| 75783 | + if( res>0 ) goto jump_to_p2; | |
| 75620 | 75784 | break; |
| 75621 | 75785 | } |
| 75622 | 75786 | |
| 75623 | 75787 | /* Opcode: Destroy P1 P2 P3 * * |
| 75624 | 75788 | ** |
| @@ -75638,15 +75802,16 @@ | ||
| 75638 | 75802 | ** the last one in the database) then a zero is stored in register P2. |
| 75639 | 75803 | ** If AUTOVACUUM is disabled then a zero is stored in register P2. |
| 75640 | 75804 | ** |
| 75641 | 75805 | ** See also: Clear |
| 75642 | 75806 | */ |
| 75643 | -case OP_Destroy: { /* out2-prerelease */ | |
| 75807 | +case OP_Destroy: { /* out2 */ | |
| 75644 | 75808 | int iMoved; |
| 75645 | 75809 | int iDb; |
| 75646 | 75810 | |
| 75647 | 75811 | assert( p->readOnly==0 ); |
| 75812 | + pOut = out2Prerelease(p, pOp); | |
| 75648 | 75813 | pOut->flags = MEM_Null; |
| 75649 | 75814 | if( db->nVdbeRead > db->nVDestroy+1 ){ |
| 75650 | 75815 | rc = SQLITE_LOCKED; |
| 75651 | 75816 | p->errorAction = OE_Abort; |
| 75652 | 75817 | }else{ |
| @@ -75751,16 +75916,17 @@ | ||
| 75751 | 75916 | ** P1>1. Write the root page number of the new table into |
| 75752 | 75917 | ** register P2. |
| 75753 | 75918 | ** |
| 75754 | 75919 | ** See documentation on OP_CreateTable for additional information. |
| 75755 | 75920 | */ |
| 75756 | -case OP_CreateIndex: /* out2-prerelease */ | |
| 75757 | -case OP_CreateTable: { /* out2-prerelease */ | |
| 75921 | +case OP_CreateIndex: /* out2 */ | |
| 75922 | +case OP_CreateTable: { /* out2 */ | |
| 75758 | 75923 | int pgno; |
| 75759 | 75924 | int flags; |
| 75760 | 75925 | Db *pDb; |
| 75761 | 75926 | |
| 75927 | + pOut = out2Prerelease(p, pOp); | |
| 75762 | 75928 | pgno = 0; |
| 75763 | 75929 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 75764 | 75930 | assert( DbMaskTest(p->btreeMask, pOp->p1) ); |
| 75765 | 75931 | assert( p->readOnly==0 ); |
| 75766 | 75932 | pDb = &db->aDb[pOp->p1]; |
| @@ -75982,16 +76148,16 @@ | ||
| 75982 | 76148 | if( (pIn1->flags & MEM_RowSet)==0 |
| 75983 | 76149 | || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0 |
| 75984 | 76150 | ){ |
| 75985 | 76151 | /* The boolean index is empty */ |
| 75986 | 76152 | sqlite3VdbeMemSetNull(pIn1); |
| 75987 | - pc = pOp->p2 - 1; | |
| 75988 | 76153 | VdbeBranchTaken(1,2); |
| 76154 | + goto jump_to_p2_and_check_for_interrupt; | |
| 75989 | 76155 | }else{ |
| 75990 | 76156 | /* A value was pulled from the index */ |
| 75991 | - sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); | |
| 75992 | 76157 | VdbeBranchTaken(0,2); |
| 76158 | + sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); | |
| 75993 | 76159 | } |
| 75994 | 76160 | goto check_for_interrupt; |
| 75995 | 76161 | } |
| 75996 | 76162 | |
| 75997 | 76163 | /* Opcode: RowSetTest P1 P2 P3 P4 |
| @@ -76038,14 +76204,11 @@ | ||
| 76038 | 76204 | assert( pOp->p4type==P4_INT32 ); |
| 76039 | 76205 | assert( iSet==-1 || iSet>=0 ); |
| 76040 | 76206 | if( iSet ){ |
| 76041 | 76207 | exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i); |
| 76042 | 76208 | VdbeBranchTaken(exists!=0,2); |
| 76043 | - if( exists ){ | |
| 76044 | - pc = pOp->p2 - 1; | |
| 76045 | - break; | |
| 76046 | - } | |
| 76209 | + if( exists ) goto jump_to_p2; | |
| 76047 | 76210 | } |
| 76048 | 76211 | if( iSet>=0 ){ |
| 76049 | 76212 | sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i); |
| 76050 | 76213 | } |
| 76051 | 76214 | break; |
| @@ -76130,11 +76293,11 @@ | ||
| 76130 | 76293 | pRt->u.pFrame = pFrame; |
| 76131 | 76294 | |
| 76132 | 76295 | pFrame->v = p; |
| 76133 | 76296 | pFrame->nChildMem = nMem; |
| 76134 | 76297 | pFrame->nChildCsr = pProgram->nCsr; |
| 76135 | - pFrame->pc = pc; | |
| 76298 | + pFrame->pc = (int)(pOp - aOp); | |
| 76136 | 76299 | pFrame->aMem = p->aMem; |
| 76137 | 76300 | pFrame->nMem = p->nMem; |
| 76138 | 76301 | pFrame->apCsr = p->apCsr; |
| 76139 | 76302 | pFrame->nCursor = p->nCursor; |
| 76140 | 76303 | pFrame->aOp = p->aOp; |
| @@ -76153,11 +76316,11 @@ | ||
| 76153 | 76316 | } |
| 76154 | 76317 | }else{ |
| 76155 | 76318 | pFrame = pRt->u.pFrame; |
| 76156 | 76319 | assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem ); |
| 76157 | 76320 | assert( pProgram->nCsr==pFrame->nChildCsr ); |
| 76158 | - assert( pc==pFrame->pc ); | |
| 76321 | + assert( (int)(pOp - aOp)==pFrame->pc ); | |
| 76159 | 76322 | } |
| 76160 | 76323 | |
| 76161 | 76324 | p->nFrame++; |
| 76162 | 76325 | pFrame->pParent = p->pFrame; |
| 76163 | 76326 | pFrame->lastRowid = lastRowid; |
| @@ -76174,11 +76337,11 @@ | ||
| 76174 | 76337 | p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 76175 | 76338 | p->nOnceFlag = pProgram->nOnce; |
| 76176 | 76339 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 76177 | 76340 | p->anExec = 0; |
| 76178 | 76341 | #endif |
| 76179 | - pc = -1; | |
| 76342 | + pOp = &aOp[-1]; | |
| 76180 | 76343 | memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 76181 | 76344 | |
| 76182 | 76345 | break; |
| 76183 | 76346 | } |
| 76184 | 76347 | |
| @@ -76192,13 +76355,14 @@ | ||
| 76192 | 76355 | ** |
| 76193 | 76356 | ** The address of the cell in the parent frame is determined by adding |
| 76194 | 76357 | ** the value of the P1 argument to the value of the P1 argument to the |
| 76195 | 76358 | ** calling OP_Program instruction. |
| 76196 | 76359 | */ |
| 76197 | -case OP_Param: { /* out2-prerelease */ | |
| 76360 | +case OP_Param: { /* out2 */ | |
| 76198 | 76361 | VdbeFrame *pFrame; |
| 76199 | 76362 | Mem *pIn; |
| 76363 | + pOut = out2Prerelease(p, pOp); | |
| 76200 | 76364 | pFrame = p->pFrame; |
| 76201 | 76365 | pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1]; |
| 76202 | 76366 | sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem); |
| 76203 | 76367 | break; |
| 76204 | 76368 | } |
| @@ -76238,14 +76402,14 @@ | ||
| 76238 | 76402 | ** (immediate foreign key constraint violations). |
| 76239 | 76403 | */ |
| 76240 | 76404 | case OP_FkIfZero: { /* jump */ |
| 76241 | 76405 | if( pOp->p1 ){ |
| 76242 | 76406 | VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2); |
| 76243 | - if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1; | |
| 76407 | + if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2; | |
| 76244 | 76408 | }else{ |
| 76245 | 76409 | VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2); |
| 76246 | - if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1; | |
| 76410 | + if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2; | |
| 76247 | 76411 | } |
| 76248 | 76412 | break; |
| 76249 | 76413 | } |
| 76250 | 76414 | #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */ |
| 76251 | 76415 | |
| @@ -76292,13 +76456,11 @@ | ||
| 76292 | 76456 | */ |
| 76293 | 76457 | case OP_IfPos: { /* jump, in1 */ |
| 76294 | 76458 | pIn1 = &aMem[pOp->p1]; |
| 76295 | 76459 | assert( pIn1->flags&MEM_Int ); |
| 76296 | 76460 | VdbeBranchTaken( pIn1->u.i>0, 2); |
| 76297 | - if( pIn1->u.i>0 ){ | |
| 76298 | - pc = pOp->p2 - 1; | |
| 76299 | - } | |
| 76461 | + if( pIn1->u.i>0 ) goto jump_to_p2; | |
| 76300 | 76462 | break; |
| 76301 | 76463 | } |
| 76302 | 76464 | |
| 76303 | 76465 | /* Opcode: IfNeg P1 P2 P3 * * |
| 76304 | 76466 | ** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2 |
| @@ -76309,13 +76471,11 @@ | ||
| 76309 | 76471 | case OP_IfNeg: { /* jump, in1 */ |
| 76310 | 76472 | pIn1 = &aMem[pOp->p1]; |
| 76311 | 76473 | assert( pIn1->flags&MEM_Int ); |
| 76312 | 76474 | pIn1->u.i += pOp->p3; |
| 76313 | 76475 | VdbeBranchTaken(pIn1->u.i<0, 2); |
| 76314 | - if( pIn1->u.i<0 ){ | |
| 76315 | - pc = pOp->p2 - 1; | |
| 76316 | - } | |
| 76476 | + if( pIn1->u.i<0 ) goto jump_to_p2; | |
| 76317 | 76477 | break; |
| 76318 | 76478 | } |
| 76319 | 76479 | |
| 76320 | 76480 | /* Opcode: IfNotZero P1 P2 P3 * * |
| 76321 | 76481 | ** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2 |
| @@ -76328,11 +76488,11 @@ | ||
| 76328 | 76488 | pIn1 = &aMem[pOp->p1]; |
| 76329 | 76489 | assert( pIn1->flags&MEM_Int ); |
| 76330 | 76490 | VdbeBranchTaken(pIn1->u.i<0, 2); |
| 76331 | 76491 | if( pIn1->u.i ){ |
| 76332 | 76492 | pIn1->u.i += pOp->p3; |
| 76333 | - pc = pOp->p2 - 1; | |
| 76493 | + goto jump_to_p2; | |
| 76334 | 76494 | } |
| 76335 | 76495 | break; |
| 76336 | 76496 | } |
| 76337 | 76497 | |
| 76338 | 76498 | /* Opcode: DecrJumpZero P1 P2 * * * |
| @@ -76344,13 +76504,11 @@ | ||
| 76344 | 76504 | case OP_DecrJumpZero: { /* jump, in1 */ |
| 76345 | 76505 | pIn1 = &aMem[pOp->p1]; |
| 76346 | 76506 | assert( pIn1->flags&MEM_Int ); |
| 76347 | 76507 | pIn1->u.i--; |
| 76348 | 76508 | VdbeBranchTaken(pIn1->u.i==0, 2); |
| 76349 | - if( pIn1->u.i==0 ){ | |
| 76350 | - pc = pOp->p2 - 1; | |
| 76351 | - } | |
| 76509 | + if( pIn1->u.i==0 ) goto jump_to_p2; | |
| 76352 | 76510 | break; |
| 76353 | 76511 | } |
| 76354 | 76512 | |
| 76355 | 76513 | |
| 76356 | 76514 | /* Opcode: JumpZeroIncr P1 P2 * * * |
| @@ -76362,13 +76520,11 @@ | ||
| 76362 | 76520 | */ |
| 76363 | 76521 | case OP_JumpZeroIncr: { /* jump, in1 */ |
| 76364 | 76522 | pIn1 = &aMem[pOp->p1]; |
| 76365 | 76523 | assert( pIn1->flags&MEM_Int ); |
| 76366 | 76524 | VdbeBranchTaken(pIn1->u.i==0, 2); |
| 76367 | - if( (pIn1->u.i++)==0 ){ | |
| 76368 | - pc = pOp->p2 - 1; | |
| 76369 | - } | |
| 76525 | + if( (pIn1->u.i++)==0 ) goto jump_to_p2; | |
| 76370 | 76526 | break; |
| 76371 | 76527 | } |
| 76372 | 76528 | |
| 76373 | 76529 | /* Opcode: AggStep * P2 P3 P4 P5 |
| 76374 | 76530 | ** Synopsis: accum=r[P3] step(r[P2@P5]) |
| @@ -76406,11 +76562,11 @@ | ||
| 76406 | 76562 | pMem->n++; |
| 76407 | 76563 | sqlite3VdbeMemInit(&t, db, MEM_Null); |
| 76408 | 76564 | ctx.pOut = &t; |
| 76409 | 76565 | ctx.isError = 0; |
| 76410 | 76566 | ctx.pVdbe = p; |
| 76411 | - ctx.iOp = pc; | |
| 76567 | + ctx.iOp = (int)(pOp - aOp); | |
| 76412 | 76568 | ctx.skipFlag = 0; |
| 76413 | 76569 | (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */ |
| 76414 | 76570 | if( ctx.isError ){ |
| 76415 | 76571 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t)); |
| 76416 | 76572 | rc = ctx.isError; |
| @@ -76501,19 +76657,20 @@ | ||
| 76501 | 76657 | ** |
| 76502 | 76658 | ** If changing into or out of WAL mode the procedure is more complicated. |
| 76503 | 76659 | ** |
| 76504 | 76660 | ** Write a string containing the final journal-mode to register P2. |
| 76505 | 76661 | */ |
| 76506 | -case OP_JournalMode: { /* out2-prerelease */ | |
| 76662 | +case OP_JournalMode: { /* out2 */ | |
| 76507 | 76663 | Btree *pBt; /* Btree to change journal mode of */ |
| 76508 | 76664 | Pager *pPager; /* Pager associated with pBt */ |
| 76509 | 76665 | int eNew; /* New journal mode */ |
| 76510 | 76666 | int eOld; /* The old journal mode */ |
| 76511 | 76667 | #ifndef SQLITE_OMIT_WAL |
| 76512 | 76668 | const char *zFilename; /* Name of database file for pPager */ |
| 76513 | 76669 | #endif |
| 76514 | 76670 | |
| 76671 | + pOut = out2Prerelease(p, pOp); | |
| 76515 | 76672 | eNew = pOp->p3; |
| 76516 | 76673 | assert( eNew==PAGER_JOURNALMODE_DELETE |
| 76517 | 76674 | || eNew==PAGER_JOURNALMODE_TRUNCATE |
| 76518 | 76675 | || eNew==PAGER_JOURNALMODE_PERSIST |
| 76519 | 76676 | || eNew==PAGER_JOURNALMODE_OFF |
| @@ -76626,12 +76783,12 @@ | ||
| 76626 | 76783 | assert( p->readOnly==0 ); |
| 76627 | 76784 | pBt = db->aDb[pOp->p1].pBt; |
| 76628 | 76785 | rc = sqlite3BtreeIncrVacuum(pBt); |
| 76629 | 76786 | VdbeBranchTaken(rc==SQLITE_DONE,2); |
| 76630 | 76787 | if( rc==SQLITE_DONE ){ |
| 76631 | - pc = pOp->p2 - 1; | |
| 76632 | 76788 | rc = SQLITE_OK; |
| 76789 | + goto jump_to_p2; | |
| 76633 | 76790 | } |
| 76634 | 76791 | break; |
| 76635 | 76792 | } |
| 76636 | 76793 | #endif |
| 76637 | 76794 | |
| @@ -76780,12 +76937,13 @@ | ||
| 76780 | 76937 | pCur = allocateCursor(p, pOp->p1, 0, -1, 0); |
| 76781 | 76938 | if( pCur ){ |
| 76782 | 76939 | pCur->pVtabCursor = pVtabCursor; |
| 76783 | 76940 | pVtab->nRef++; |
| 76784 | 76941 | }else{ |
| 76785 | - db->mallocFailed = 1; | |
| 76942 | + assert( db->mallocFailed ); | |
| 76786 | 76943 | pModule->xClose(pVtabCursor); |
| 76944 | + goto no_mem; | |
| 76787 | 76945 | } |
| 76788 | 76946 | } |
| 76789 | 76947 | break; |
| 76790 | 76948 | } |
| 76791 | 76949 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| @@ -76837,29 +76995,23 @@ | ||
| 76837 | 76995 | assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int ); |
| 76838 | 76996 | nArg = (int)pArgc->u.i; |
| 76839 | 76997 | iQuery = (int)pQuery->u.i; |
| 76840 | 76998 | |
| 76841 | 76999 | /* Invoke the xFilter method */ |
| 76842 | - { | |
| 76843 | - res = 0; | |
| 76844 | - apArg = p->apArg; | |
| 76845 | - for(i = 0; i<nArg; i++){ | |
| 76846 | - apArg[i] = &pArgc[i+1]; | |
| 76847 | - } | |
| 76848 | - | |
| 76849 | - rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); | |
| 76850 | - sqlite3VtabImportErrmsg(p, pVtab); | |
| 76851 | - if( rc==SQLITE_OK ){ | |
| 76852 | - res = pModule->xEof(pVtabCursor); | |
| 76853 | - } | |
| 76854 | - VdbeBranchTaken(res!=0,2); | |
| 76855 | - if( res ){ | |
| 76856 | - pc = pOp->p2 - 1; | |
| 76857 | - } | |
| 77000 | + res = 0; | |
| 77001 | + apArg = p->apArg; | |
| 77002 | + for(i = 0; i<nArg; i++){ | |
| 77003 | + apArg[i] = &pArgc[i+1]; | |
| 77004 | + } | |
| 77005 | + rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); | |
| 77006 | + sqlite3VtabImportErrmsg(p, pVtab); | |
| 77007 | + if( rc==SQLITE_OK ){ | |
| 77008 | + res = pModule->xEof(pVtabCursor); | |
| 76858 | 77009 | } |
| 76859 | 77010 | pCur->nullRow = 0; |
| 76860 | - | |
| 77011 | + VdbeBranchTaken(res!=0,2); | |
| 77012 | + if( res ) goto jump_to_p2; | |
| 76861 | 77013 | break; |
| 76862 | 77014 | } |
| 76863 | 77015 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 76864 | 77016 | |
| 76865 | 77017 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| @@ -76942,11 +77094,11 @@ | ||
| 76942 | 77094 | res = pModule->xEof(pCur->pVtabCursor); |
| 76943 | 77095 | } |
| 76944 | 77096 | VdbeBranchTaken(!res,2); |
| 76945 | 77097 | if( !res ){ |
| 76946 | 77098 | /* If there is data, jump to P2 */ |
| 76947 | - pc = pOp->p2 - 1; | |
| 77099 | + goto jump_to_p2_and_check_for_interrupt; | |
| 76948 | 77100 | } |
| 76949 | 77101 | goto check_for_interrupt; |
| 76950 | 77102 | } |
| 76951 | 77103 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 76952 | 77104 | |
| @@ -77065,11 +77217,12 @@ | ||
| 77065 | 77217 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 77066 | 77218 | /* Opcode: Pagecount P1 P2 * * * |
| 77067 | 77219 | ** |
| 77068 | 77220 | ** Write the current number of pages in database P1 to memory cell P2. |
| 77069 | 77221 | */ |
| 77070 | -case OP_Pagecount: { /* out2-prerelease */ | |
| 77222 | +case OP_Pagecount: { /* out2 */ | |
| 77223 | + pOut = out2Prerelease(p, pOp); | |
| 77071 | 77224 | pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt); |
| 77072 | 77225 | break; |
| 77073 | 77226 | } |
| 77074 | 77227 | #endif |
| 77075 | 77228 | |
| @@ -77081,14 +77234,15 @@ | ||
| 77081 | 77234 | ** Do not let the maximum page count fall below the current page count and |
| 77082 | 77235 | ** do not change the maximum page count value if P3==0. |
| 77083 | 77236 | ** |
| 77084 | 77237 | ** Store the maximum page count after the change in register P2. |
| 77085 | 77238 | */ |
| 77086 | -case OP_MaxPgcnt: { /* out2-prerelease */ | |
| 77239 | +case OP_MaxPgcnt: { /* out2 */ | |
| 77087 | 77240 | unsigned int newMax; |
| 77088 | 77241 | Btree *pBt; |
| 77089 | 77242 | |
| 77243 | + pOut = out2Prerelease(p, pOp); | |
| 77090 | 77244 | pBt = db->aDb[pOp->p1].pBt; |
| 77091 | 77245 | newMax = 0; |
| 77092 | 77246 | if( pOp->p3 ){ |
| 77093 | 77247 | newMax = sqlite3BtreeLastPage(pBt); |
| 77094 | 77248 | if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3; |
| @@ -77113,13 +77267,10 @@ | ||
| 77113 | 77267 | */ |
| 77114 | 77268 | case OP_Init: { /* jump */ |
| 77115 | 77269 | char *zTrace; |
| 77116 | 77270 | char *z; |
| 77117 | 77271 | |
| 77118 | - if( pOp->p2 ){ | |
| 77119 | - pc = pOp->p2 - 1; | |
| 77120 | - } | |
| 77121 | 77272 | #ifndef SQLITE_OMIT_TRACE |
| 77122 | 77273 | if( db->xTrace |
| 77123 | 77274 | && !p->doingRerun |
| 77124 | 77275 | && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 77125 | 77276 | ){ |
| @@ -77143,10 +77294,11 @@ | ||
| 77143 | 77294 | ){ |
| 77144 | 77295 | sqlite3DebugPrintf("SQL-trace: %s\n", zTrace); |
| 77145 | 77296 | } |
| 77146 | 77297 | #endif /* SQLITE_DEBUG */ |
| 77147 | 77298 | #endif /* SQLITE_OMIT_TRACE */ |
| 77299 | + if( pOp->p2 ) goto jump_to_p2; | |
| 77148 | 77300 | break; |
| 77149 | 77301 | } |
| 77150 | 77302 | |
| 77151 | 77303 | |
| 77152 | 77304 | /* Opcode: Noop * * * * * |
| @@ -77174,31 +77326,31 @@ | ||
| 77174 | 77326 | } |
| 77175 | 77327 | |
| 77176 | 77328 | #ifdef VDBE_PROFILE |
| 77177 | 77329 | { |
| 77178 | 77330 | u64 endTime = sqlite3Hwtime(); |
| 77179 | - if( endTime>start ) pOp->cycles += endTime - start; | |
| 77180 | - pOp->cnt++; | |
| 77331 | + if( endTime>start ) pOrigOp->cycles += endTime - start; | |
| 77332 | + pOrigOp->cnt++; | |
| 77181 | 77333 | } |
| 77182 | 77334 | #endif |
| 77183 | 77335 | |
| 77184 | 77336 | /* The following code adds nothing to the actual functionality |
| 77185 | 77337 | ** of the program. It is only here for testing and debugging. |
| 77186 | 77338 | ** On the other hand, it does burn CPU cycles every time through |
| 77187 | 77339 | ** the evaluator loop. So we can leave it out when NDEBUG is defined. |
| 77188 | 77340 | */ |
| 77189 | 77341 | #ifndef NDEBUG |
| 77190 | - assert( pc>=-1 && pc<p->nOp ); | |
| 77342 | + assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] ); | |
| 77191 | 77343 | |
| 77192 | 77344 | #ifdef SQLITE_DEBUG |
| 77193 | 77345 | if( db->flags & SQLITE_VdbeTrace ){ |
| 77194 | 77346 | if( rc!=0 ) printf("rc=%d\n",rc); |
| 77195 | - if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){ | |
| 77196 | - registerTrace(pOp->p2, &aMem[pOp->p2]); | |
| 77347 | + if( pOrigOp->opflags & (OPFLG_OUT2) ){ | |
| 77348 | + registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]); | |
| 77197 | 77349 | } |
| 77198 | - if( pOp->opflags & OPFLG_OUT3 ){ | |
| 77199 | - registerTrace(pOp->p3, &aMem[pOp->p3]); | |
| 77350 | + if( pOrigOp->opflags & OPFLG_OUT3 ){ | |
| 77351 | + registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]); | |
| 77200 | 77352 | } |
| 77201 | 77353 | } |
| 77202 | 77354 | #endif /* SQLITE_DEBUG */ |
| 77203 | 77355 | #endif /* NDEBUG */ |
| 77204 | 77356 | } /* The end of the for(;;) loop the loops through opcodes */ |
| @@ -77209,11 +77361,11 @@ | ||
| 77209 | 77361 | vdbe_error_halt: |
| 77210 | 77362 | assert( rc ); |
| 77211 | 77363 | p->rc = rc; |
| 77212 | 77364 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 77213 | 77365 | sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 77214 | - pc, p->zSql, p->zErrMsg); | |
| 77366 | + (int)(pOp - aOp), p->zSql, p->zErrMsg); | |
| 77215 | 77367 | sqlite3VdbeHalt(p); |
| 77216 | 77368 | if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; |
| 77217 | 77369 | rc = SQLITE_ERROR; |
| 77218 | 77370 | if( resetSchemaOnFault>0 ){ |
| 77219 | 77371 | sqlite3ResetOneSchema(db, resetSchemaOnFault-1); |
| @@ -78035,20 +78187,23 @@ | ||
| 78035 | 78187 | ** |
| 78036 | 78188 | ** In both cases, the effects of the main thread seeing (bDone==0) even |
| 78037 | 78189 | ** after the thread has finished are not dire. So we don't worry about |
| 78038 | 78190 | ** memory barriers and such here. |
| 78039 | 78191 | */ |
| 78192 | +typedef int (*SorterCompare)(SortSubtask*,int*,const void*,int,const void*,int); | |
| 78040 | 78193 | struct SortSubtask { |
| 78041 | 78194 | SQLiteThread *pThread; /* Background thread, if any */ |
| 78042 | 78195 | int bDone; /* Set if thread is finished but not joined */ |
| 78043 | 78196 | VdbeSorter *pSorter; /* Sorter that owns this sub-task */ |
| 78044 | 78197 | UnpackedRecord *pUnpacked; /* Space to unpack a record */ |
| 78045 | 78198 | SorterList list; /* List for thread to write to a PMA */ |
| 78046 | 78199 | int nPMA; /* Number of PMAs currently in file */ |
| 78200 | + SorterCompare xCompare; /* Compare function to use */ | |
| 78047 | 78201 | SorterFile file; /* Temp file for level-0 PMAs */ |
| 78048 | 78202 | SorterFile file2; /* Space for other PMAs */ |
| 78049 | 78203 | }; |
| 78204 | + | |
| 78050 | 78205 | |
| 78051 | 78206 | /* |
| 78052 | 78207 | ** Main sorter structure. A single instance of this is allocated for each |
| 78053 | 78208 | ** sorter cursor created by the VDBE. |
| 78054 | 78209 | ** |
| @@ -78072,12 +78227,16 @@ | ||
| 78072 | 78227 | int nMemory; /* Size of list.aMemory allocation in bytes */ |
| 78073 | 78228 | u8 bUsePMA; /* True if one or more PMAs created */ |
| 78074 | 78229 | u8 bUseThreads; /* True to use background threads */ |
| 78075 | 78230 | u8 iPrev; /* Previous thread used to flush PMA */ |
| 78076 | 78231 | u8 nTask; /* Size of aTask[] array */ |
| 78232 | + u8 typeMask; | |
| 78077 | 78233 | SortSubtask aTask[1]; /* One or more subtasks */ |
| 78078 | 78234 | }; |
| 78235 | + | |
| 78236 | +#define SORTER_TYPE_INTEGER 0x01 | |
| 78237 | +#define SORTER_TYPE_TEXT 0x02 | |
| 78079 | 78238 | |
| 78080 | 78239 | /* |
| 78081 | 78240 | ** An instance of the following object is used to read records out of a |
| 78082 | 78241 | ** PMA, in sorted order. The next key to be read is cached in nKey/aKey. |
| 78083 | 78242 | ** aKey might point into aMap or into aBuffer. If neither of those locations |
| @@ -78486,35 +78645,165 @@ | ||
| 78486 | 78645 | rc = vdbePmaReaderNext(pReadr); |
| 78487 | 78646 | } |
| 78488 | 78647 | return rc; |
| 78489 | 78648 | } |
| 78490 | 78649 | |
| 78650 | +/* | |
| 78651 | +** A version of vdbeSorterCompare() that assumes that it has already been | |
| 78652 | +** determined that the first field of key1 is equal to the first field of | |
| 78653 | +** key2. | |
| 78654 | +*/ | |
| 78655 | +static int vdbeSorterCompareTail( | |
| 78656 | + SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ | |
| 78657 | + int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ | |
| 78658 | + const void *pKey1, int nKey1, /* Left side of comparison */ | |
| 78659 | + const void *pKey2, int nKey2 /* Right side of comparison */ | |
| 78660 | +){ | |
| 78661 | + UnpackedRecord *r2 = pTask->pUnpacked; | |
| 78662 | + if( *pbKey2Cached==0 ){ | |
| 78663 | + sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); | |
| 78664 | + *pbKey2Cached = 1; | |
| 78665 | + } | |
| 78666 | + return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1); | |
| 78667 | +} | |
| 78491 | 78668 | |
| 78492 | 78669 | /* |
| 78493 | 78670 | ** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2, |
| 78494 | 78671 | ** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences |
| 78495 | 78672 | ** used by the comparison. Return the result of the comparison. |
| 78496 | 78673 | ** |
| 78497 | -** Before returning, object (pTask->pUnpacked) is populated with the | |
| 78498 | -** unpacked version of key2. Or, if pKey2 is passed a NULL pointer, then it | |
| 78499 | -** is assumed that the (pTask->pUnpacked) structure already contains the | |
| 78500 | -** unpacked key to use as key2. | |
| 78674 | +** If IN/OUT parameter *pbKey2Cached is true when this function is called, | |
| 78675 | +** it is assumed that (pTask->pUnpacked) contains the unpacked version | |
| 78676 | +** of key2. If it is false, (pTask->pUnpacked) is populated with the unpacked | |
| 78677 | +** version of key2 and *pbKey2Cached set to true before returning. | |
| 78501 | 78678 | ** |
| 78502 | 78679 | ** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set |
| 78503 | 78680 | ** to SQLITE_NOMEM. |
| 78504 | 78681 | */ |
| 78505 | 78682 | static int vdbeSorterCompare( |
| 78506 | 78683 | SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ |
| 78684 | + int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ | |
| 78507 | 78685 | const void *pKey1, int nKey1, /* Left side of comparison */ |
| 78508 | 78686 | const void *pKey2, int nKey2 /* Right side of comparison */ |
| 78509 | 78687 | ){ |
| 78510 | 78688 | UnpackedRecord *r2 = pTask->pUnpacked; |
| 78511 | - if( pKey2 ){ | |
| 78689 | + if( !*pbKey2Cached ){ | |
| 78512 | 78690 | sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); |
| 78691 | + *pbKey2Cached = 1; | |
| 78513 | 78692 | } |
| 78514 | 78693 | return sqlite3VdbeRecordCompare(nKey1, pKey1, r2); |
| 78515 | 78694 | } |
| 78695 | + | |
| 78696 | +/* | |
| 78697 | +** A specially optimized version of vdbeSorterCompare() that assumes that | |
| 78698 | +** the first field of each key is a TEXT value and that the collation | |
| 78699 | +** sequence to compare them with is BINARY. | |
| 78700 | +*/ | |
| 78701 | +static int vdbeSorterCompareText( | |
| 78702 | + SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ | |
| 78703 | + int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ | |
| 78704 | + const void *pKey1, int nKey1, /* Left side of comparison */ | |
| 78705 | + const void *pKey2, int nKey2 /* Right side of comparison */ | |
| 78706 | +){ | |
| 78707 | + const u8 * const p1 = (const u8 * const)pKey1; | |
| 78708 | + const u8 * const p2 = (const u8 * const)pKey2; | |
| 78709 | + const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */ | |
| 78710 | + const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */ | |
| 78711 | + | |
| 78712 | + int n1; | |
| 78713 | + int n2; | |
| 78714 | + int res; | |
| 78715 | + | |
| 78716 | + getVarint32(&p1[1], n1); n1 = (n1 - 13) / 2; | |
| 78717 | + getVarint32(&p2[1], n2); n2 = (n2 - 13) / 2; | |
| 78718 | + res = memcmp(v1, v2, MIN(n1, n2)); | |
| 78719 | + if( res==0 ){ | |
| 78720 | + res = n1 - n2; | |
| 78721 | + } | |
| 78722 | + | |
| 78723 | + if( res==0 ){ | |
| 78724 | + if( pTask->pSorter->pKeyInfo->nField>1 ){ | |
| 78725 | + res = vdbeSorterCompareTail( | |
| 78726 | + pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2 | |
| 78727 | + ); | |
| 78728 | + } | |
| 78729 | + }else{ | |
| 78730 | + if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ | |
| 78731 | + res = res * -1; | |
| 78732 | + } | |
| 78733 | + } | |
| 78734 | + | |
| 78735 | + return res; | |
| 78736 | +} | |
| 78737 | + | |
| 78738 | +/* | |
| 78739 | +** A specially optimized version of vdbeSorterCompare() that assumes that | |
| 78740 | +** the first field of each key is an INTEGER value. | |
| 78741 | +*/ | |
| 78742 | +static int vdbeSorterCompareInt( | |
| 78743 | + SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ | |
| 78744 | + int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ | |
| 78745 | + const void *pKey1, int nKey1, /* Left side of comparison */ | |
| 78746 | + const void *pKey2, int nKey2 /* Right side of comparison */ | |
| 78747 | +){ | |
| 78748 | + const u8 * const p1 = (const u8 * const)pKey1; | |
| 78749 | + const u8 * const p2 = (const u8 * const)pKey2; | |
| 78750 | + const int s1 = p1[1]; /* Left hand serial type */ | |
| 78751 | + const int s2 = p2[1]; /* Right hand serial type */ | |
| 78752 | + const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */ | |
| 78753 | + const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */ | |
| 78754 | + int res; /* Return value */ | |
| 78755 | + | |
| 78756 | + assert( (s1>0 && s1<7) || s1==8 || s1==9 ); | |
| 78757 | + assert( (s2>0 && s2<7) || s2==8 || s2==9 ); | |
| 78758 | + | |
| 78759 | + if( s1>7 && s2>7 ){ | |
| 78760 | + res = s1 - s2; | |
| 78761 | + }else{ | |
| 78762 | + if( s1==s2 ){ | |
| 78763 | + if( (*v1 ^ *v2) & 0x80 ){ | |
| 78764 | + /* The two values have different signs */ | |
| 78765 | + res = (*v1 & 0x80) ? -1 : +1; | |
| 78766 | + }else{ | |
| 78767 | + /* The two values have the same sign. Compare using memcmp(). */ | |
| 78768 | + static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 }; | |
| 78769 | + int i; | |
| 78770 | + res = 0; | |
| 78771 | + for(i=0; i<aLen[s1]; i++){ | |
| 78772 | + if( (res = v1[i] - v2[i]) ) break; | |
| 78773 | + } | |
| 78774 | + } | |
| 78775 | + }else{ | |
| 78776 | + if( s2>7 ){ | |
| 78777 | + res = +1; | |
| 78778 | + }else if( s1>7 ){ | |
| 78779 | + res = -1; | |
| 78780 | + }else{ | |
| 78781 | + res = s1 - s2; | |
| 78782 | + } | |
| 78783 | + assert( res!=0 ); | |
| 78784 | + | |
| 78785 | + if( res>0 ){ | |
| 78786 | + if( *v1 & 0x80 ) res = -1; | |
| 78787 | + }else{ | |
| 78788 | + if( *v2 & 0x80 ) res = +1; | |
| 78789 | + } | |
| 78790 | + } | |
| 78791 | + } | |
| 78792 | + | |
| 78793 | + if( res==0 ){ | |
| 78794 | + if( pTask->pSorter->pKeyInfo->nField>1 ){ | |
| 78795 | + res = vdbeSorterCompareTail( | |
| 78796 | + pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2 | |
| 78797 | + ); | |
| 78798 | + } | |
| 78799 | + }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ | |
| 78800 | + res = res * -1; | |
| 78801 | + } | |
| 78802 | + | |
| 78803 | + return res; | |
| 78804 | +} | |
| 78516 | 78805 | |
| 78517 | 78806 | /* |
| 78518 | 78807 | ** Initialize the temporary index cursor just opened as a sorter cursor. |
| 78519 | 78808 | ** |
| 78520 | 78809 | ** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField) |
| @@ -78579,13 +78868,17 @@ | ||
| 78579 | 78868 | rc = SQLITE_NOMEM; |
| 78580 | 78869 | }else{ |
| 78581 | 78870 | pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz); |
| 78582 | 78871 | memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo); |
| 78583 | 78872 | pKeyInfo->db = 0; |
| 78584 | - if( nField && nWorker==0 ) pKeyInfo->nField = nField; | |
| 78873 | + if( nField && nWorker==0 ){ | |
| 78874 | + pKeyInfo->nXField += (pKeyInfo->nField - nField); | |
| 78875 | + pKeyInfo->nField = nField; | |
| 78876 | + } | |
| 78585 | 78877 | pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt); |
| 78586 | 78878 | pSorter->nTask = nWorker + 1; |
| 78879 | + pSorter->iPrev = nWorker-1; | |
| 78587 | 78880 | pSorter->bUseThreads = (pSorter->nTask>1); |
| 78588 | 78881 | pSorter->db = db; |
| 78589 | 78882 | for(i=0; i<pSorter->nTask; i++){ |
| 78590 | 78883 | SortSubtask *pTask = &pSorter->aTask[i]; |
| 78591 | 78884 | pTask->pSorter = pSorter; |
| @@ -78607,10 +78900,16 @@ | ||
| 78607 | 78900 | pSorter->nMemory = pgsz; |
| 78608 | 78901 | pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz); |
| 78609 | 78902 | if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM; |
| 78610 | 78903 | } |
| 78611 | 78904 | } |
| 78905 | + | |
| 78906 | + if( (pKeyInfo->nField+pKeyInfo->nXField)<13 | |
| 78907 | + && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl) | |
| 78908 | + ){ | |
| 78909 | + pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT; | |
| 78910 | + } | |
| 78612 | 78911 | } |
| 78613 | 78912 | |
| 78614 | 78913 | return rc; |
| 78615 | 78914 | } |
| 78616 | 78915 | #undef nWorker /* Defined at the top of this function */ |
| @@ -78631,34 +78930,28 @@ | ||
| 78631 | 78930 | ** Free all resources owned by the object indicated by argument pTask. All |
| 78632 | 78931 | ** fields of *pTask are zeroed before returning. |
| 78633 | 78932 | */ |
| 78634 | 78933 | static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){ |
| 78635 | 78934 | sqlite3DbFree(db, pTask->pUnpacked); |
| 78636 | - pTask->pUnpacked = 0; | |
| 78637 | 78935 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 78638 | 78936 | /* pTask->list.aMemory can only be non-zero if it was handed memory |
| 78639 | 78937 | ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */ |
| 78640 | 78938 | if( pTask->list.aMemory ){ |
| 78641 | 78939 | sqlite3_free(pTask->list.aMemory); |
| 78642 | - pTask->list.aMemory = 0; | |
| 78643 | 78940 | }else |
| 78644 | 78941 | #endif |
| 78645 | 78942 | { |
| 78646 | 78943 | assert( pTask->list.aMemory==0 ); |
| 78647 | 78944 | vdbeSorterRecordFree(0, pTask->list.pList); |
| 78648 | 78945 | } |
| 78649 | - pTask->list.pList = 0; | |
| 78650 | 78946 | if( pTask->file.pFd ){ |
| 78651 | 78947 | sqlite3OsCloseFree(pTask->file.pFd); |
| 78652 | - pTask->file.pFd = 0; | |
| 78653 | - pTask->file.iEof = 0; | |
| 78654 | 78948 | } |
| 78655 | 78949 | if( pTask->file2.pFd ){ |
| 78656 | 78950 | sqlite3OsCloseFree(pTask->file2.pFd); |
| 78657 | - pTask->file2.pFd = 0; | |
| 78658 | - pTask->file2.iEof = 0; | |
| 78659 | 78951 | } |
| 78952 | + memset(pTask, 0, sizeof(SortSubtask)); | |
| 78660 | 78953 | } |
| 78661 | 78954 | |
| 78662 | 78955 | #ifdef SQLITE_DEBUG_SORTER_THREADS |
| 78663 | 78956 | static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){ |
| 78664 | 78957 | i64 t; |
| @@ -78834,10 +79127,11 @@ | ||
| 78834 | 79127 | vdbeMergeEngineFree(pSorter->pMerger); |
| 78835 | 79128 | pSorter->pMerger = 0; |
| 78836 | 79129 | for(i=0; i<pSorter->nTask; i++){ |
| 78837 | 79130 | SortSubtask *pTask = &pSorter->aTask[i]; |
| 78838 | 79131 | vdbeSortSubtaskCleanup(db, pTask); |
| 79132 | + pTask->pSorter = pSorter; | |
| 78839 | 79133 | } |
| 78840 | 79134 | if( pSorter->list.aMemory==0 ){ |
| 78841 | 79135 | vdbeSorterRecordFree(0, pSorter->list.pList); |
| 78842 | 79136 | } |
| 78843 | 79137 | pSorter->list.pList = 0; |
| @@ -78943,31 +79237,45 @@ | ||
| 78943 | 79237 | SorterRecord *p2, /* Second list to merge */ |
| 78944 | 79238 | SorterRecord **ppOut /* OUT: Head of merged list */ |
| 78945 | 79239 | ){ |
| 78946 | 79240 | SorterRecord *pFinal = 0; |
| 78947 | 79241 | SorterRecord **pp = &pFinal; |
| 78948 | - void *pVal2 = p2 ? SRVAL(p2) : 0; | |
| 79242 | + int bCached = 0; | |
| 78949 | 79243 | |
| 78950 | 79244 | while( p1 && p2 ){ |
| 78951 | 79245 | int res; |
| 78952 | - res = vdbeSorterCompare(pTask, SRVAL(p1), p1->nVal, pVal2, p2->nVal); | |
| 79246 | + res = pTask->xCompare( | |
| 79247 | + pTask, &bCached, SRVAL(p1), p1->nVal, SRVAL(p2), p2->nVal | |
| 79248 | + ); | |
| 79249 | + | |
| 78953 | 79250 | if( res<=0 ){ |
| 78954 | 79251 | *pp = p1; |
| 78955 | 79252 | pp = &p1->u.pNext; |
| 78956 | 79253 | p1 = p1->u.pNext; |
| 78957 | - pVal2 = 0; | |
| 78958 | 79254 | }else{ |
| 78959 | 79255 | *pp = p2; |
| 78960 | - pp = &p2->u.pNext; | |
| 79256 | + pp = &p2->u.pNext; | |
| 78961 | 79257 | p2 = p2->u.pNext; |
| 78962 | - if( p2==0 ) break; | |
| 78963 | - pVal2 = SRVAL(p2); | |
| 79258 | + bCached = 0; | |
| 78964 | 79259 | } |
| 78965 | 79260 | } |
| 78966 | 79261 | *pp = p1 ? p1 : p2; |
| 78967 | 79262 | *ppOut = pFinal; |
| 78968 | 79263 | } |
| 79264 | + | |
| 79265 | +/* | |
| 79266 | +** Return the SorterCompare function to compare values collected by the | |
| 79267 | +** sorter object passed as the only argument. | |
| 79268 | +*/ | |
| 79269 | +static SorterCompare vdbeSorterGetCompare(VdbeSorter *p){ | |
| 79270 | + if( p->typeMask==SORTER_TYPE_INTEGER ){ | |
| 79271 | + return vdbeSorterCompareInt; | |
| 79272 | + }else if( p->typeMask==SORTER_TYPE_TEXT ){ | |
| 79273 | + return vdbeSorterCompareText; | |
| 79274 | + } | |
| 79275 | + return vdbeSorterCompare; | |
| 79276 | +} | |
| 78969 | 79277 | |
| 78970 | 79278 | /* |
| 78971 | 79279 | ** Sort the linked list of records headed at pTask->pList. Return |
| 78972 | 79280 | ** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if |
| 78973 | 79281 | ** an error occurs. |
| @@ -78979,16 +79287,18 @@ | ||
| 78979 | 79287 | int rc; |
| 78980 | 79288 | |
| 78981 | 79289 | rc = vdbeSortAllocUnpacked(pTask); |
| 78982 | 79290 | if( rc!=SQLITE_OK ) return rc; |
| 78983 | 79291 | |
| 79292 | + p = pList->pList; | |
| 79293 | + pTask->xCompare = vdbeSorterGetCompare(pTask->pSorter); | |
| 79294 | + | |
| 78984 | 79295 | aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *)); |
| 78985 | 79296 | if( !aSlot ){ |
| 78986 | 79297 | return SQLITE_NOMEM; |
| 78987 | 79298 | } |
| 78988 | 79299 | |
| 78989 | - p = pList->pList; | |
| 78990 | 79300 | while( p ){ |
| 78991 | 79301 | SorterRecord *pNext; |
| 78992 | 79302 | if( pList->aMemory ){ |
| 78993 | 79303 | if( (u8*)p==pList->aMemory ){ |
| 78994 | 79304 | pNext = 0; |
| @@ -79198,28 +79508,27 @@ | ||
| 79198 | 79508 | /* Update contents of aTree[] */ |
| 79199 | 79509 | if( rc==SQLITE_OK ){ |
| 79200 | 79510 | int i; /* Index of aTree[] to recalculate */ |
| 79201 | 79511 | PmaReader *pReadr1; /* First PmaReader to compare */ |
| 79202 | 79512 | PmaReader *pReadr2; /* Second PmaReader to compare */ |
| 79203 | - u8 *pKey2; /* To pReadr2->aKey, or 0 if record cached */ | |
| 79513 | + int bCached = 0; | |
| 79204 | 79514 | |
| 79205 | 79515 | /* Find the first two PmaReaders to compare. The one that was just |
| 79206 | 79516 | ** advanced (iPrev) and the one next to it in the array. */ |
| 79207 | 79517 | pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)]; |
| 79208 | 79518 | pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)]; |
| 79209 | - pKey2 = pReadr2->aKey; | |
| 79210 | 79519 | |
| 79211 | 79520 | for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){ |
| 79212 | 79521 | /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */ |
| 79213 | 79522 | int iRes; |
| 79214 | 79523 | if( pReadr1->pFd==0 ){ |
| 79215 | 79524 | iRes = +1; |
| 79216 | 79525 | }else if( pReadr2->pFd==0 ){ |
| 79217 | 79526 | iRes = -1; |
| 79218 | 79527 | }else{ |
| 79219 | - iRes = vdbeSorterCompare(pTask, | |
| 79220 | - pReadr1->aKey, pReadr1->nKey, pKey2, pReadr2->nKey | |
| 79528 | + iRes = pTask->xCompare(pTask, &bCached, | |
| 79529 | + pReadr1->aKey, pReadr1->nKey, pReadr2->aKey, pReadr2->nKey | |
| 79221 | 79530 | ); |
| 79222 | 79531 | } |
| 79223 | 79532 | |
| 79224 | 79533 | /* If pReadr1 contained the smaller value, set aTree[i] to its index. |
| 79225 | 79534 | ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this |
| @@ -79237,13 +79546,13 @@ | ||
| 79237 | 79546 | ** is sorted from oldest to newest, so pReadr1 contains older values |
| 79238 | 79547 | ** than pReadr2 iff (pReadr1<pReadr2). */ |
| 79239 | 79548 | if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){ |
| 79240 | 79549 | pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr); |
| 79241 | 79550 | pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ]; |
| 79242 | - pKey2 = pReadr2->aKey; | |
| 79551 | + bCached = 0; | |
| 79243 | 79552 | }else{ |
| 79244 | - if( pReadr1->pFd ) pKey2 = 0; | |
| 79553 | + if( pReadr1->pFd ) bCached = 0; | |
| 79245 | 79554 | pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr); |
| 79246 | 79555 | pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ]; |
| 79247 | 79556 | } |
| 79248 | 79557 | } |
| 79249 | 79558 | *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0); |
| @@ -79346,10 +79655,20 @@ | ||
| 79346 | 79655 | SorterRecord *pNew; /* New list element */ |
| 79347 | 79656 | |
| 79348 | 79657 | int bFlush; /* True to flush contents of memory to PMA */ |
| 79349 | 79658 | int nReq; /* Bytes of memory required */ |
| 79350 | 79659 | int nPMA; /* Bytes of PMA space required */ |
| 79660 | + int t; /* serial type of first record field */ | |
| 79661 | + | |
| 79662 | + getVarint32((const u8*)&pVal->z[1], t); | |
| 79663 | + if( t>0 && t<10 && t!=7 ){ | |
| 79664 | + pSorter->typeMask &= SORTER_TYPE_INTEGER; | |
| 79665 | + }else if( t>10 && (t & 0x01) ){ | |
| 79666 | + pSorter->typeMask &= SORTER_TYPE_TEXT; | |
| 79667 | + }else{ | |
| 79668 | + pSorter->typeMask = 0; | |
| 79669 | + } | |
| 79351 | 79670 | |
| 79352 | 79671 | assert( pSorter ); |
| 79353 | 79672 | |
| 79354 | 79673 | /* Figure out whether or not the current contents of memory should be |
| 79355 | 79674 | ** flushed to a PMA before continuing. If so, do so. |
| @@ -79611,14 +79930,16 @@ | ||
| 79611 | 79930 | if( p1->pFd==0 ){ |
| 79612 | 79931 | iRes = i2; |
| 79613 | 79932 | }else if( p2->pFd==0 ){ |
| 79614 | 79933 | iRes = i1; |
| 79615 | 79934 | }else{ |
| 79935 | + SortSubtask *pTask = pMerger->pTask; | |
| 79936 | + int bCached = 0; | |
| 79616 | 79937 | int res; |
| 79617 | - assert( pMerger->pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */ | |
| 79618 | - res = vdbeSorterCompare( | |
| 79619 | - pMerger->pTask, p1->aKey, p1->nKey, p2->aKey, p2->nKey | |
| 79938 | + assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */ | |
| 79939 | + res = pTask->xCompare( | |
| 79940 | + pTask, &bCached, p1->aKey, p1->nKey, p2->aKey, p2->nKey | |
| 79620 | 79941 | ); |
| 79621 | 79942 | if( res<=0 ){ |
| 79622 | 79943 | iRes = i1; |
| 79623 | 79944 | }else{ |
| 79624 | 79945 | iRes = i2; |
| @@ -79638,15 +79959,16 @@ | ||
| 79638 | 79959 | */ |
| 79639 | 79960 | #define INCRINIT_NORMAL 0 |
| 79640 | 79961 | #define INCRINIT_TASK 1 |
| 79641 | 79962 | #define INCRINIT_ROOT 2 |
| 79642 | 79963 | |
| 79643 | -/* Forward reference. | |
| 79644 | -** The vdbeIncrMergeInit() and vdbePmaReaderIncrMergeInit() routines call each | |
| 79645 | -** other (when building a merge tree). | |
| 79964 | +/* | |
| 79965 | +** Forward reference required as the vdbeIncrMergeInit() and | |
| 79966 | +** vdbePmaReaderIncrInit() routines are called mutually recursively when | |
| 79967 | +** building a merge tree. | |
| 79646 | 79968 | */ |
| 79647 | -static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode); | |
| 79969 | +static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode); | |
| 79648 | 79970 | |
| 79649 | 79971 | /* |
| 79650 | 79972 | ** Initialize the MergeEngine object passed as the second argument. Once this |
| 79651 | 79973 | ** function returns, the first key of merged data may be read from the |
| 79652 | 79974 | ** MergeEngine object in the usual fashion. |
| @@ -79689,11 +80011,11 @@ | ||
| 79689 | 80011 | ** the main thread to fill its buffer. So calling PmaReaderNext() |
| 79690 | 80012 | ** on this PmaReader before any of the multi-threaded PmaReaders takes |
| 79691 | 80013 | ** better advantage of multi-processor hardware. */ |
| 79692 | 80014 | rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]); |
| 79693 | 80015 | }else{ |
| 79694 | - rc = vdbePmaReaderIncrMergeInit(&pMerger->aReadr[i], INCRINIT_NORMAL); | |
| 80016 | + rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i], INCRINIT_NORMAL); | |
| 79695 | 80017 | } |
| 79696 | 80018 | if( rc!=SQLITE_OK ) return rc; |
| 79697 | 80019 | } |
| 79698 | 80020 | |
| 79699 | 80021 | for(i=pMerger->nTree-1; i>0; i--){ |
| @@ -79701,21 +80023,19 @@ | ||
| 79701 | 80023 | } |
| 79702 | 80024 | return pTask->pUnpacked->errCode; |
| 79703 | 80025 | } |
| 79704 | 80026 | |
| 79705 | 80027 | /* |
| 79706 | -** Initialize the IncrMerge field of a PmaReader. | |
| 79707 | -** | |
| 79708 | -** If the PmaReader passed as the first argument is not an incremental-reader | |
| 79709 | -** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it serves | |
| 79710 | -** to open and/or initialize the temp file related fields of the IncrMerge | |
| 80028 | +** The PmaReader passed as the first argument is guaranteed to be an | |
| 80029 | +** incremental-reader (pReadr->pIncr!=0). This function serves to open | |
| 80030 | +** and/or initialize the temp file related fields of the IncrMerge | |
| 79711 | 80031 | ** object at (pReadr->pIncr). |
| 79712 | 80032 | ** |
| 79713 | 80033 | ** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders |
| 79714 | -** in the sub-tree headed by pReadr are also initialized. Data is then loaded | |
| 79715 | -** into the buffers belonging to pReadr and it is set to | |
| 79716 | -** point to the first key in its range. | |
| 80034 | +** in the sub-tree headed by pReadr are also initialized. Data is then | |
| 80035 | +** loaded into the buffers belonging to pReadr and it is set to point to | |
| 80036 | +** the first key in its range. | |
| 79717 | 80037 | ** |
| 79718 | 80038 | ** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed |
| 79719 | 80039 | ** to be a multi-threaded PmaReader and this function is being called in a |
| 79720 | 80040 | ** background thread. In this case all PmaReaders in the sub-tree are |
| 79721 | 80041 | ** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to |
| @@ -79738,93 +80058,112 @@ | ||
| 79738 | 80058 | ** SQLITE_OK is returned if successful, or an SQLite error code otherwise. |
| 79739 | 80059 | */ |
| 79740 | 80060 | static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){ |
| 79741 | 80061 | int rc = SQLITE_OK; |
| 79742 | 80062 | IncrMerger *pIncr = pReadr->pIncr; |
| 80063 | + SortSubtask *pTask = pIncr->pTask; | |
| 80064 | + sqlite3 *db = pTask->pSorter->db; | |
| 79743 | 80065 | |
| 79744 | 80066 | /* eMode is always INCRINIT_NORMAL in single-threaded mode */ |
| 79745 | 80067 | assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL ); |
| 79746 | 80068 | |
| 79747 | - if( pIncr ){ | |
| 79748 | - SortSubtask *pTask = pIncr->pTask; | |
| 79749 | - sqlite3 *db = pTask->pSorter->db; | |
| 79750 | - | |
| 79751 | - rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode); | |
| 79752 | - | |
| 79753 | - /* Set up the required files for pIncr. A multi-theaded IncrMerge object | |
| 79754 | - ** requires two temp files to itself, whereas a single-threaded object | |
| 79755 | - ** only requires a region of pTask->file2. */ | |
| 79756 | - if( rc==SQLITE_OK ){ | |
| 79757 | - int mxSz = pIncr->mxSz; | |
| 79758 | -#if SQLITE_MAX_WORKER_THREADS>0 | |
| 79759 | - if( pIncr->bUseThread ){ | |
| 79760 | - rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd); | |
| 79761 | - if( rc==SQLITE_OK ){ | |
| 79762 | - rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd); | |
| 79763 | - } | |
| 79764 | - }else | |
| 79765 | -#endif | |
| 79766 | - /*if( !pIncr->bUseThread )*/{ | |
| 79767 | - if( pTask->file2.pFd==0 ){ | |
| 79768 | - assert( pTask->file2.iEof>0 ); | |
| 79769 | - rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd); | |
| 79770 | - pTask->file2.iEof = 0; | |
| 79771 | - } | |
| 79772 | - if( rc==SQLITE_OK ){ | |
| 79773 | - pIncr->aFile[1].pFd = pTask->file2.pFd; | |
| 79774 | - pIncr->iStartOff = pTask->file2.iEof; | |
| 79775 | - pTask->file2.iEof += mxSz; | |
| 79776 | - } | |
| 79777 | - } | |
| 79778 | - } | |
| 79779 | - | |
| 79780 | -#if SQLITE_MAX_WORKER_THREADS>0 | |
| 79781 | - if( rc==SQLITE_OK && pIncr->bUseThread ){ | |
| 79782 | - /* Use the current thread to populate aFile[1], even though this | |
| 79783 | - ** PmaReader is multi-threaded. The reason being that this function | |
| 79784 | - ** is already running in background thread pIncr->pTask->thread. */ | |
| 79785 | - assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK ); | |
| 79786 | - rc = vdbeIncrPopulate(pIncr); | |
| 79787 | - } | |
| 79788 | -#endif | |
| 79789 | - | |
| 79790 | - if( rc==SQLITE_OK | |
| 79791 | - && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) | |
| 79792 | - ){ | |
| 79793 | - rc = vdbePmaReaderNext(pReadr); | |
| 79794 | - } | |
| 79795 | - } | |
| 80069 | + rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode); | |
| 80070 | + | |
| 80071 | + /* Set up the required files for pIncr. A multi-theaded IncrMerge object | |
| 80072 | + ** requires two temp files to itself, whereas a single-threaded object | |
| 80073 | + ** only requires a region of pTask->file2. */ | |
| 80074 | + if( rc==SQLITE_OK ){ | |
| 80075 | + int mxSz = pIncr->mxSz; | |
| 80076 | +#if SQLITE_MAX_WORKER_THREADS>0 | |
| 80077 | + if( pIncr->bUseThread ){ | |
| 80078 | + rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd); | |
| 80079 | + if( rc==SQLITE_OK ){ | |
| 80080 | + rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd); | |
| 80081 | + } | |
| 80082 | + }else | |
| 80083 | +#endif | |
| 80084 | + /*if( !pIncr->bUseThread )*/{ | |
| 80085 | + if( pTask->file2.pFd==0 ){ | |
| 80086 | + assert( pTask->file2.iEof>0 ); | |
| 80087 | + rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd); | |
| 80088 | + pTask->file2.iEof = 0; | |
| 80089 | + } | |
| 80090 | + if( rc==SQLITE_OK ){ | |
| 80091 | + pIncr->aFile[1].pFd = pTask->file2.pFd; | |
| 80092 | + pIncr->iStartOff = pTask->file2.iEof; | |
| 80093 | + pTask->file2.iEof += mxSz; | |
| 80094 | + } | |
| 80095 | + } | |
| 80096 | + } | |
| 80097 | + | |
| 80098 | +#if SQLITE_MAX_WORKER_THREADS>0 | |
| 80099 | + if( rc==SQLITE_OK && pIncr->bUseThread ){ | |
| 80100 | + /* Use the current thread to populate aFile[1], even though this | |
| 80101 | + ** PmaReader is multi-threaded. If this is an INCRINIT_TASK object, | |
| 80102 | + ** then this function is already running in background thread | |
| 80103 | + ** pIncr->pTask->thread. | |
| 80104 | + ** | |
| 80105 | + ** If this is the INCRINIT_ROOT object, then it is running in the | |
| 80106 | + ** main VDBE thread. But that is Ok, as that thread cannot return | |
| 80107 | + ** control to the VDBE or proceed with anything useful until the | |
| 80108 | + ** first results are ready from this merger object anyway. | |
| 80109 | + */ | |
| 80110 | + assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK ); | |
| 80111 | + rc = vdbeIncrPopulate(pIncr); | |
| 80112 | + } | |
| 80113 | +#endif | |
| 80114 | + | |
| 80115 | + if( rc==SQLITE_OK && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) ){ | |
| 80116 | + rc = vdbePmaReaderNext(pReadr); | |
| 80117 | + } | |
| 80118 | + | |
| 79796 | 80119 | return rc; |
| 79797 | 80120 | } |
| 79798 | 80121 | |
| 79799 | 80122 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 79800 | 80123 | /* |
| 79801 | 80124 | ** The main routine for vdbePmaReaderIncrMergeInit() operations run in |
| 79802 | 80125 | ** background threads. |
| 79803 | 80126 | */ |
| 79804 | -static void *vdbePmaReaderBgInit(void *pCtx){ | |
| 80127 | +static void *vdbePmaReaderBgIncrInit(void *pCtx){ | |
| 79805 | 80128 | PmaReader *pReader = (PmaReader*)pCtx; |
| 79806 | 80129 | void *pRet = SQLITE_INT_TO_PTR( |
| 79807 | 80130 | vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK) |
| 79808 | 80131 | ); |
| 79809 | 80132 | pReader->pIncr->pTask->bDone = 1; |
| 79810 | 80133 | return pRet; |
| 79811 | 80134 | } |
| 80135 | +#endif | |
| 79812 | 80136 | |
| 79813 | 80137 | /* |
| 79814 | -** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK) | |
| 79815 | -** on the PmaReader object passed as the first argument. | |
| 79816 | -** | |
| 79817 | -** This call will initialize the various fields of the pReadr->pIncr | |
| 79818 | -** structure and, if it is a multi-threaded IncrMerger, launch a | |
| 79819 | -** background thread to populate aFile[1]. | |
| 80138 | +** If the PmaReader passed as the first argument is not an incremental-reader | |
| 80139 | +** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes | |
| 80140 | +** the vdbePmaReaderIncrMergeInit() function with the parameters passed to | |
| 80141 | +** this routine to initialize the incremental merge. | |
| 80142 | +** | |
| 80143 | +** If the IncrMerger object is multi-threaded (IncrMerger.bUseThread==1), | |
| 80144 | +** then a background thread is launched to call vdbePmaReaderIncrMergeInit(). | |
| 80145 | +** Or, if the IncrMerger is single threaded, the same function is called | |
| 80146 | +** using the current thread. | |
| 79820 | 80147 | */ |
| 79821 | -static int vdbePmaReaderBgIncrInit(PmaReader *pReadr){ | |
| 79822 | - void *pCtx = (void*)pReadr; | |
| 79823 | - return vdbeSorterCreateThread(pReadr->pIncr->pTask, vdbePmaReaderBgInit, pCtx); | |
| 80148 | +static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode){ | |
| 80149 | + IncrMerger *pIncr = pReadr->pIncr; /* Incremental merger */ | |
| 80150 | + int rc = SQLITE_OK; /* Return code */ | |
| 80151 | + if( pIncr ){ | |
| 80152 | +#if SQLITE_MAX_WORKER_THREADS>0 | |
| 80153 | + assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK ); | |
| 80154 | + if( pIncr->bUseThread ){ | |
| 80155 | + void *pCtx = (void*)pReadr; | |
| 80156 | + rc = vdbeSorterCreateThread(pIncr->pTask, vdbePmaReaderBgIncrInit, pCtx); | |
| 80157 | + }else | |
| 80158 | +#endif | |
| 80159 | + { | |
| 80160 | + rc = vdbePmaReaderIncrMergeInit(pReadr, eMode); | |
| 80161 | + } | |
| 80162 | + } | |
| 80163 | + return rc; | |
| 79824 | 80164 | } |
| 79825 | -#endif | |
| 79826 | 80165 | |
| 79827 | 80166 | /* |
| 79828 | 80167 | ** Allocate a new MergeEngine object to merge the contents of nPMA level-0 |
| 79829 | 80168 | ** PMAs from pTask->file. If no error occurs, set *ppOut to point to |
| 79830 | 80169 | ** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut |
| @@ -80032,10 +80371,15 @@ | ||
| 80032 | 80371 | int rc; /* Return code */ |
| 80033 | 80372 | SortSubtask *pTask0 = &pSorter->aTask[0]; |
| 80034 | 80373 | MergeEngine *pMain = 0; |
| 80035 | 80374 | #if SQLITE_MAX_WORKER_THREADS |
| 80036 | 80375 | sqlite3 *db = pTask0->pSorter->db; |
| 80376 | + int i; | |
| 80377 | + SorterCompare xCompare = vdbeSorterGetCompare(pSorter); | |
| 80378 | + for(i=0; i<pSorter->nTask; i++){ | |
| 80379 | + pSorter->aTask[i].xCompare = xCompare; | |
| 80380 | + } | |
| 80037 | 80381 | #endif |
| 80038 | 80382 | |
| 80039 | 80383 | rc = vdbeSorterMergeTreeBuild(pSorter, &pMain); |
| 80040 | 80384 | if( rc==SQLITE_OK ){ |
| 80041 | 80385 | #if SQLITE_MAX_WORKER_THREADS |
| @@ -80060,19 +80404,25 @@ | ||
| 80060 | 80404 | vdbeIncrMergerSetThreads(pIncr); |
| 80061 | 80405 | assert( pIncr->pTask!=pLast ); |
| 80062 | 80406 | } |
| 80063 | 80407 | } |
| 80064 | 80408 | for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){ |
| 80409 | + /* Check that: | |
| 80410 | + ** | |
| 80411 | + ** a) The incremental merge object is configured to use the | |
| 80412 | + ** right task, and | |
| 80413 | + ** b) If it is using task (nTask-1), it is configured to run | |
| 80414 | + ** in single-threaded mode. This is important, as the | |
| 80415 | + ** root merge (INCRINIT_ROOT) will be using the same task | |
| 80416 | + ** object. | |
| 80417 | + */ | |
| 80065 | 80418 | PmaReader *p = &pMain->aReadr[iTask]; |
| 80066 | - assert( p->pIncr==0 || p->pIncr->pTask==&pSorter->aTask[iTask] ); | |
| 80067 | - if( p->pIncr ){ | |
| 80068 | - if( iTask==pSorter->nTask-1 ){ | |
| 80069 | - rc = vdbePmaReaderIncrMergeInit(p, INCRINIT_TASK); | |
| 80070 | - }else{ | |
| 80071 | - rc = vdbePmaReaderBgIncrInit(p); | |
| 80072 | - } | |
| 80073 | - } | |
| 80419 | + assert( p->pIncr==0 || ( | |
| 80420 | + (p->pIncr->pTask==&pSorter->aTask[iTask]) /* a */ | |
| 80421 | + && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */ | |
| 80422 | + )); | |
| 80423 | + rc = vdbePmaReaderIncrInit(p, INCRINIT_TASK); | |
| 80074 | 80424 | } |
| 80075 | 80425 | } |
| 80076 | 80426 | pMain = 0; |
| 80077 | 80427 | } |
| 80078 | 80428 | if( rc==SQLITE_OK ){ |
| @@ -81023,11 +81373,11 @@ | ||
| 81023 | 81373 | ** Should be transformed into: |
| 81024 | 81374 | ** |
| 81025 | 81375 | ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase; |
| 81026 | 81376 | ** |
| 81027 | 81377 | ** The nSubquery parameter specifies how many levels of subquery the |
| 81028 | -** alias is removed from the original expression. The usually value is | |
| 81378 | +** alias is removed from the original expression. The usual value is | |
| 81029 | 81379 | ** zero but it might be more if the alias is contained within a subquery |
| 81030 | 81380 | ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION |
| 81031 | 81381 | ** structures must be increased by the nSubquery amount. |
| 81032 | 81382 | */ |
| 81033 | 81383 | static void resolveAlias( |
| @@ -81043,11 +81393,11 @@ | ||
| 81043 | 81393 | sqlite3 *db; /* The database connection */ |
| 81044 | 81394 | |
| 81045 | 81395 | assert( iCol>=0 && iCol<pEList->nExpr ); |
| 81046 | 81396 | pOrig = pEList->a[iCol].pExpr; |
| 81047 | 81397 | assert( pOrig!=0 ); |
| 81048 | - assert( pOrig->flags & EP_Resolved ); | |
| 81398 | + assert( (pOrig->flags & EP_Resolved)!=0 || zType[0]==0 ); | |
| 81049 | 81399 | db = pParse->db; |
| 81050 | 81400 | pDup = sqlite3ExprDup(db, pOrig, 0); |
| 81051 | 81401 | if( pDup==0 ) return; |
| 81052 | 81402 | if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){ |
| 81053 | 81403 | incrAggFunctionDepth(pDup, nSubquery); |
| @@ -81937,13 +82287,15 @@ | ||
| 81937 | 82287 | pNew->flags |= EP_IntValue; |
| 81938 | 82288 | pNew->u.iValue = iCol; |
| 81939 | 82289 | if( pItem->pExpr==pE ){ |
| 81940 | 82290 | pItem->pExpr = pNew; |
| 81941 | 82291 | }else{ |
| 81942 | - assert( pItem->pExpr->op==TK_COLLATE ); | |
| 81943 | - assert( pItem->pExpr->pLeft==pE ); | |
| 81944 | - pItem->pExpr->pLeft = pNew; | |
| 82292 | + Expr *pParent = pItem->pExpr; | |
| 82293 | + assert( pParent->op==TK_COLLATE ); | |
| 82294 | + while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft; | |
| 82295 | + assert( pParent->pLeft==pE ); | |
| 82296 | + pParent->pLeft = pNew; | |
| 81945 | 82297 | } |
| 81946 | 82298 | sqlite3ExprDelete(db, pE); |
| 81947 | 82299 | pItem->u.x.iOrderByCol = (u16)iCol; |
| 81948 | 82300 | pItem->done = 1; |
| 81949 | 82301 | }else{ |
| @@ -82139,11 +82491,11 @@ | ||
| 82139 | 82491 | ** as if it were part of the sub-query, not the parent. This block |
| 82140 | 82492 | ** moves the pOrderBy down to the sub-query. It will be moved back |
| 82141 | 82493 | ** after the names have been resolved. */ |
| 82142 | 82494 | if( p->selFlags & SF_Converted ){ |
| 82143 | 82495 | Select *pSub = p->pSrc->a[0].pSelect; |
| 82144 | - assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy ); | |
| 82496 | + assert( p->pSrc->nSrc==1 && p->pOrderBy ); | |
| 82145 | 82497 | assert( pSub->pPrior && pSub->pOrderBy==0 ); |
| 82146 | 82498 | pSub->pOrderBy = p->pOrderBy; |
| 82147 | 82499 | p->pOrderBy = 0; |
| 82148 | 82500 | } |
| 82149 | 82501 | |
| @@ -82241,12 +82593,19 @@ | ||
| 82241 | 82593 | |
| 82242 | 82594 | /* Process the ORDER BY clause for singleton SELECT statements. |
| 82243 | 82595 | ** The ORDER BY clause for compounds SELECT statements is handled |
| 82244 | 82596 | ** below, after all of the result-sets for all of the elements of |
| 82245 | 82597 | ** the compound have been resolved. |
| 82598 | + ** | |
| 82599 | + ** If there is an ORDER BY clause on a term of a compound-select other | |
| 82600 | + ** than the right-most term, then that is a syntax error. But the error | |
| 82601 | + ** is not detected until much later, and so we need to go ahead and | |
| 82602 | + ** resolve those symbols on the incorrect ORDER BY for consistency. | |
| 82246 | 82603 | */ |
| 82247 | - if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){ | |
| 82604 | + if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */ | |
| 82605 | + && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") | |
| 82606 | + ){ | |
| 82248 | 82607 | return WRC_Abort; |
| 82249 | 82608 | } |
| 82250 | 82609 | if( db->mallocFailed ){ |
| 82251 | 82610 | return WRC_Abort; |
| 82252 | 82611 | } |
| @@ -83694,11 +84053,12 @@ | ||
| 83694 | 84053 | SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){ |
| 83695 | 84054 | int i; |
| 83696 | 84055 | u32 m = 0; |
| 83697 | 84056 | if( pList ){ |
| 83698 | 84057 | for(i=0; i<pList->nExpr; i++){ |
| 83699 | - m |= pList->a[i].pExpr->flags; | |
| 84058 | + Expr *pExpr = pList->a[i].pExpr; | |
| 84059 | + if( ALWAYS(pExpr) ) m |= pList->a[i].pExpr->flags; | |
| 83700 | 84060 | } |
| 83701 | 84061 | } |
| 83702 | 84062 | return m; |
| 83703 | 84063 | } |
| 83704 | 84064 | |
| @@ -84134,11 +84494,11 @@ | ||
| 84134 | 84494 | /* Check to see if an existing table or index can be used to |
| 84135 | 84495 | ** satisfy the query. This is preferable to generating a new |
| 84136 | 84496 | ** ephemeral table. |
| 84137 | 84497 | */ |
| 84138 | 84498 | p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0); |
| 84139 | - if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){ | |
| 84499 | + if( pParse->nErr==0 && isCandidateForInOpt(p) ){ | |
| 84140 | 84500 | sqlite3 *db = pParse->db; /* Database connection */ |
| 84141 | 84501 | Table *pTab; /* Table <table>. */ |
| 84142 | 84502 | Expr *pExpr; /* Expression <column> */ |
| 84143 | 84503 | i16 iCol; /* Index of column <column> */ |
| 84144 | 84504 | i16 iDb; /* Database idx for pTab */ |
| @@ -84459,10 +84819,11 @@ | ||
| 84459 | 84819 | } |
| 84460 | 84820 | sqlite3ExprDelete(pParse->db, pSel->pLimit); |
| 84461 | 84821 | pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, |
| 84462 | 84822 | &sqlite3IntTokens[1]); |
| 84463 | 84823 | pSel->iLimit = 0; |
| 84824 | + pSel->selFlags &= ~SF_MultiValue; | |
| 84464 | 84825 | if( sqlite3Select(pParse, pSel, &dest) ){ |
| 84465 | 84826 | return 0; |
| 84466 | 84827 | } |
| 84467 | 84828 | rReg = dest.iSDParm; |
| 84468 | 84829 | ExprSetVVAProperty(pExpr, EP_NoReduce); |
| @@ -85824,11 +86185,11 @@ | ||
| 85824 | 86185 | sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken); |
| 85825 | 86186 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 85826 | 86187 | break; |
| 85827 | 86188 | } |
| 85828 | 86189 | case TK_ID: { |
| 85829 | - sqlite3TreeViewLine(pView,"ID %Q", pExpr->u.zToken); | |
| 86190 | + sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken); | |
| 85830 | 86191 | break; |
| 85831 | 86192 | } |
| 85832 | 86193 | #ifndef SQLITE_OMIT_CAST |
| 85833 | 86194 | case TK_CAST: { |
| 85834 | 86195 | /* Expressions of the form: CAST(pLeft AS token) */ |
| @@ -86459,11 +86820,11 @@ | ||
| 86459 | 86820 | if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){ |
| 86460 | 86821 | if( combinedFlags & EP_xIsSelect ) return 2; |
| 86461 | 86822 | if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2; |
| 86462 | 86823 | if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2; |
| 86463 | 86824 | if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2; |
| 86464 | - if( ALWAYS((combinedFlags & EP_Reduced)==0) ){ | |
| 86825 | + if( ALWAYS((combinedFlags & EP_Reduced)==0) && pA->op!=TK_STRING ){ | |
| 86465 | 86826 | if( pA->iColumn!=pB->iColumn ) return 2; |
| 86466 | 86827 | if( pA->iTable!=pB->iTable |
| 86467 | 86828 | && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2; |
| 86468 | 86829 | } |
| 86469 | 86830 | } |
| @@ -86991,10 +87352,11 @@ | ||
| 86991 | 87352 | do { |
| 86992 | 87353 | z += n; |
| 86993 | 87354 | n = sqlite3GetToken(z, &token); |
| 86994 | 87355 | }while( token==TK_SPACE ); |
| 86995 | 87356 | |
| 87357 | + if( token==TK_ILLEGAL ) break; | |
| 86996 | 87358 | zParent = sqlite3DbStrNDup(db, (const char *)z, n); |
| 86997 | 87359 | if( zParent==0 ) break; |
| 86998 | 87360 | sqlite3Dequote(zParent); |
| 86999 | 87361 | if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){ |
| 87000 | 87362 | char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"", |
| @@ -89217,18 +89579,21 @@ | ||
| 89217 | 89579 | pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase); |
| 89218 | 89580 | } |
| 89219 | 89581 | z = argv[2]; |
| 89220 | 89582 | |
| 89221 | 89583 | if( pIndex ){ |
| 89584 | + tRowcnt *aiRowEst = 0; | |
| 89222 | 89585 | int nCol = pIndex->nKeyCol+1; |
| 89223 | 89586 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 89224 | - tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero( | |
| 89225 | - sizeof(tRowcnt) * nCol | |
| 89226 | - ); | |
| 89227 | - if( aiRowEst==0 ) pInfo->db->mallocFailed = 1; | |
| 89228 | -#else | |
| 89229 | - tRowcnt * const aiRowEst = 0; | |
| 89587 | + /* Index.aiRowEst may already be set here if there are duplicate | |
| 89588 | + ** sqlite_stat1 entries for this index. In that case just clobber | |
| 89589 | + ** the old data with the new instead of allocating a new array. */ | |
| 89590 | + if( pIndex->aiRowEst==0 ){ | |
| 89591 | + pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(sizeof(tRowcnt) * nCol); | |
| 89592 | + if( pIndex->aiRowEst==0 ) pInfo->db->mallocFailed = 1; | |
| 89593 | + } | |
| 89594 | + aiRowEst = pIndex->aiRowEst; | |
| 89230 | 89595 | #endif |
| 89231 | 89596 | pIndex->bUnordered = 0; |
| 89232 | 89597 | decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex); |
| 89233 | 89598 | if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0]; |
| 89234 | 89599 | }else{ |
| @@ -89887,11 +90252,11 @@ | ||
| 89887 | 90252 | } |
| 89888 | 90253 | |
| 89889 | 90254 | sqlite3BtreeClose(pDb->pBt); |
| 89890 | 90255 | pDb->pBt = 0; |
| 89891 | 90256 | pDb->pSchema = 0; |
| 89892 | - sqlite3ResetAllSchemasOfConnection(db); | |
| 90257 | + sqlite3CollapseDatabaseArray(db); | |
| 89893 | 90258 | return; |
| 89894 | 90259 | |
| 89895 | 90260 | detach_error: |
| 89896 | 90261 | sqlite3_result_error(context, zErr, -1); |
| 89897 | 90262 | } |
| @@ -89921,11 +90286,10 @@ | ||
| 89921 | 90286 | if( |
| 89922 | 90287 | SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) || |
| 89923 | 90288 | SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) || |
| 89924 | 90289 | SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey)) |
| 89925 | 90290 | ){ |
| 89926 | - pParse->nErr++; | |
| 89927 | 90291 | goto attach_end; |
| 89928 | 90292 | } |
| 89929 | 90293 | |
| 89930 | 90294 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 89931 | 90295 | if( pAuthArg ){ |
| @@ -90580,13 +90944,15 @@ | ||
| 90580 | 90944 | sqlite3 *db; |
| 90581 | 90945 | Vdbe *v; |
| 90582 | 90946 | |
| 90583 | 90947 | assert( pParse->pToplevel==0 ); |
| 90584 | 90948 | db = pParse->db; |
| 90585 | - if( db->mallocFailed ) return; | |
| 90586 | 90949 | if( pParse->nested ) return; |
| 90587 | - if( pParse->nErr ) return; | |
| 90950 | + if( db->mallocFailed || pParse->nErr ){ | |
| 90951 | + if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR; | |
| 90952 | + return; | |
| 90953 | + } | |
| 90588 | 90954 | |
| 90589 | 90955 | /* Begin by generating some termination code at the end of the |
| 90590 | 90956 | ** vdbe program |
| 90591 | 90957 | */ |
| 90592 | 90958 | v = sqlite3GetVdbe(pParse); |
| @@ -90664,11 +91030,11 @@ | ||
| 90664 | 91030 | } |
| 90665 | 91031 | |
| 90666 | 91032 | |
| 90667 | 91033 | /* Get the VDBE program ready for execution |
| 90668 | 91034 | */ |
| 90669 | - if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){ | |
| 91035 | + if( v && pParse->nErr==0 && !db->mallocFailed ){ | |
| 90670 | 91036 | assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */ |
| 90671 | 91037 | /* A minimum of one cursor is required if autoincrement is used |
| 90672 | 91038 | * See ticket [a696379c1f08866] */ |
| 90673 | 91039 | if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1; |
| 90674 | 91040 | sqlite3VdbeMakeReady(v, pParse); |
| @@ -91199,18 +91565,16 @@ | ||
| 91199 | 91565 | sqlite3 *db = pParse->db; |
| 91200 | 91566 | |
| 91201 | 91567 | if( ALWAYS(pName2!=0) && pName2->n>0 ){ |
| 91202 | 91568 | if( db->init.busy ) { |
| 91203 | 91569 | sqlite3ErrorMsg(pParse, "corrupt database"); |
| 91204 | - pParse->nErr++; | |
| 91205 | 91570 | return -1; |
| 91206 | 91571 | } |
| 91207 | 91572 | *pUnqual = pName2; |
| 91208 | 91573 | iDb = sqlite3FindDb(db, pName1); |
| 91209 | 91574 | if( iDb<0 ){ |
| 91210 | 91575 | sqlite3ErrorMsg(pParse, "unknown database %T", pName1); |
| 91211 | - pParse->nErr++; | |
| 91212 | 91576 | return -1; |
| 91213 | 91577 | } |
| 91214 | 91578 | }else{ |
| 91215 | 91579 | assert( db->init.iDb==0 || db->init.busy ); |
| 91216 | 91580 | iDb = db->init.iDb; |
| @@ -91365,11 +91729,11 @@ | ||
| 91365 | 91729 | pTable = sqlite3FindTable(db, zName, zDb); |
| 91366 | 91730 | if( pTable ){ |
| 91367 | 91731 | if( !noErr ){ |
| 91368 | 91732 | sqlite3ErrorMsg(pParse, "table %T already exists", pName); |
| 91369 | 91733 | }else{ |
| 91370 | - assert( !db->init.busy ); | |
| 91734 | + assert( !db->init.busy || CORRUPT_DB ); | |
| 91371 | 91735 | sqlite3CodeVerifySchema(pParse, iDb); |
| 91372 | 91736 | } |
| 91373 | 91737 | goto begin_table_error; |
| 91374 | 91738 | } |
| 91375 | 91739 | if( sqlite3FindIndex(db, zName, zDb)!=0 ){ |
| @@ -91654,11 +92018,12 @@ | ||
| 91654 | 92018 | Column *pCol; |
| 91655 | 92019 | |
| 91656 | 92020 | p = pParse->pNewTable; |
| 91657 | 92021 | if( p==0 || NEVER(p->nCol<1) ) return; |
| 91658 | 92022 | pCol = &p->aCol[p->nCol-1]; |
| 91659 | - assert( pCol->zType==0 ); | |
| 92023 | + assert( pCol->zType==0 || CORRUPT_DB ); | |
| 92024 | + sqlite3DbFree(pParse->db, pCol->zType); | |
| 91660 | 92025 | pCol->zType = sqlite3NameFromToken(pParse->db, pType); |
| 91661 | 92026 | pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst); |
| 91662 | 92027 | } |
| 91663 | 92028 | |
| 91664 | 92029 | /* |
| @@ -92888,10 +93253,11 @@ | ||
| 92888 | 93253 | if( db->mallocFailed ){ |
| 92889 | 93254 | goto exit_drop_table; |
| 92890 | 93255 | } |
| 92891 | 93256 | assert( pParse->nErr==0 ); |
| 92892 | 93257 | assert( pName->nSrc==1 ); |
| 93258 | + if( sqlite3ReadSchema(pParse) ) goto exit_drop_table; | |
| 92893 | 93259 | if( noErr ) db->suppressErr++; |
| 92894 | 93260 | pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]); |
| 92895 | 93261 | if( noErr ) db->suppressErr--; |
| 92896 | 93262 | |
| 92897 | 93263 | if( pTab==0 ){ |
| @@ -93201,11 +93567,12 @@ | ||
| 93201 | 93567 | sqlite3UniqueConstraint(pParse, OE_Abort, pIndex); |
| 93202 | 93568 | }else{ |
| 93203 | 93569 | addr2 = sqlite3VdbeCurrentAddr(v); |
| 93204 | 93570 | } |
| 93205 | 93571 | sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx); |
| 93206 | - sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1); | |
| 93572 | + sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1); | |
| 93573 | + sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0); | |
| 93207 | 93574 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 93208 | 93575 | sqlite3ReleaseTempReg(pParse, regRecord); |
| 93209 | 93576 | sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v); |
| 93210 | 93577 | sqlite3VdbeJumpHere(v, addr1); |
| 93211 | 93578 | |
| @@ -93294,12 +93661,11 @@ | ||
| 93294 | 93661 | int nExtra = 0; /* Space allocated for zExtra[] */ |
| 93295 | 93662 | int nExtraCol; /* Number of extra columns needed */ |
| 93296 | 93663 | char *zExtra = 0; /* Extra space after the Index object */ |
| 93297 | 93664 | Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */ |
| 93298 | 93665 | |
| 93299 | - assert( pParse->nErr==0 ); /* Never called with prior errors */ | |
| 93300 | - if( db->mallocFailed || IN_DECLARE_VTAB ){ | |
| 93666 | + if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){ | |
| 93301 | 93667 | goto exit_create_index; |
| 93302 | 93668 | } |
| 93303 | 93669 | if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ |
| 93304 | 93670 | goto exit_create_index; |
| 93305 | 93671 | } |
| @@ -94214,11 +94580,10 @@ | ||
| 94214 | 94580 | ** operator with A. This routine shifts that operator over to B. |
| 94215 | 94581 | */ |
| 94216 | 94582 | SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){ |
| 94217 | 94583 | if( p ){ |
| 94218 | 94584 | int i; |
| 94219 | - assert( p->a || p->nSrc==0 ); | |
| 94220 | 94585 | for(i=p->nSrc-1; i>0; i--){ |
| 94221 | 94586 | p->a[i].jointype = p->a[i-1].jointype; |
| 94222 | 94587 | } |
| 94223 | 94588 | p->a[0].jointype = 0; |
| 94224 | 94589 | } |
| @@ -94461,12 +94826,11 @@ | ||
| 94461 | 94826 | char *zErr; |
| 94462 | 94827 | int j; |
| 94463 | 94828 | StrAccum errMsg; |
| 94464 | 94829 | Table *pTab = pIdx->pTable; |
| 94465 | 94830 | |
| 94466 | - sqlite3StrAccumInit(&errMsg, 0, 0, 200); | |
| 94467 | - errMsg.db = pParse->db; | |
| 94831 | + sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200); | |
| 94468 | 94832 | for(j=0; j<pIdx->nKeyCol; j++){ |
| 94469 | 94833 | char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName; |
| 94470 | 94834 | if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2); |
| 94471 | 94835 | sqlite3StrAccumAppendAll(&errMsg, pTab->zName); |
| 94472 | 94836 | sqlite3StrAccumAppend(&errMsg, ".", 1); |
| @@ -96291,17 +96655,17 @@ | ||
| 96291 | 96655 | ){ |
| 96292 | 96656 | PrintfArguments x; |
| 96293 | 96657 | StrAccum str; |
| 96294 | 96658 | const char *zFormat; |
| 96295 | 96659 | int n; |
| 96660 | + sqlite3 *db = sqlite3_context_db_handle(context); | |
| 96296 | 96661 | |
| 96297 | 96662 | if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){ |
| 96298 | 96663 | x.nArg = argc-1; |
| 96299 | 96664 | x.nUsed = 0; |
| 96300 | 96665 | x.apArg = argv+1; |
| 96301 | - sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH); | |
| 96302 | - str.db = sqlite3_context_db_handle(context); | |
| 96666 | + sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); | |
| 96303 | 96667 | sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x); |
| 96304 | 96668 | n = str.nChar; |
| 96305 | 96669 | sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, |
| 96306 | 96670 | SQLITE_DYNAMIC); |
| 96307 | 96671 | } |
| @@ -96447,11 +96811,11 @@ | ||
| 96447 | 96811 | sqlite3_result_double(context, r); |
| 96448 | 96812 | } |
| 96449 | 96813 | #endif |
| 96450 | 96814 | |
| 96451 | 96815 | /* |
| 96452 | -** Allocate nByte bytes of space using sqlite3_malloc(). If the | |
| 96816 | +** Allocate nByte bytes of space using sqlite3Malloc(). If the | |
| 96453 | 96817 | ** allocation fails, call sqlite3_result_error_nomem() to notify |
| 96454 | 96818 | ** the database handle that malloc() has failed and return NULL. |
| 96455 | 96819 | ** If nByte is larger than the maximum string or blob length, then |
| 96456 | 96820 | ** raise an SQLITE_TOOBIG exception and return NULL. |
| 96457 | 96821 | */ |
| @@ -97116,11 +97480,11 @@ | ||
| 97116 | 97480 | int argc, |
| 97117 | 97481 | sqlite3_value **argv |
| 97118 | 97482 | ){ |
| 97119 | 97483 | unsigned char *z, *zOut; |
| 97120 | 97484 | int i; |
| 97121 | - zOut = z = sqlite3_malloc( argc*4+1 ); | |
| 97485 | + zOut = z = sqlite3_malloc64( argc*4+1 ); | |
| 97122 | 97486 | if( z==0 ){ |
| 97123 | 97487 | sqlite3_result_error_nomem(context); |
| 97124 | 97488 | return; |
| 97125 | 97489 | } |
| 97126 | 97490 | for(i=0; i<argc; i++){ |
| @@ -97264,11 +97628,11 @@ | ||
| 97264 | 97628 | sqlite3_result_error_toobig(context); |
| 97265 | 97629 | sqlite3_free(zOut); |
| 97266 | 97630 | return; |
| 97267 | 97631 | } |
| 97268 | 97632 | zOld = zOut; |
| 97269 | - zOut = sqlite3_realloc(zOut, (int)nOut); | |
| 97633 | + zOut = sqlite3_realloc64(zOut, (int)nOut); | |
| 97270 | 97634 | if( zOut==0 ){ |
| 97271 | 97635 | sqlite3_result_error_nomem(context); |
| 97272 | 97636 | sqlite3_free(zOld); |
| 97273 | 97637 | return; |
| 97274 | 97638 | } |
| @@ -97626,12 +97990,11 @@ | ||
| 97626 | 97990 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 97627 | 97991 | pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum)); |
| 97628 | 97992 | |
| 97629 | 97993 | if( pAccum ){ |
| 97630 | 97994 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 97631 | - int firstTerm = pAccum->useMalloc==0; | |
| 97632 | - pAccum->useMalloc = 2; | |
| 97995 | + int firstTerm = pAccum->mxAlloc==0; | |
| 97633 | 97996 | pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH]; |
| 97634 | 97997 | if( !firstTerm ){ |
| 97635 | 97998 | if( argc==2 ){ |
| 97636 | 97999 | zSep = (char*)sqlite3_value_text(argv[1]); |
| 97637 | 98000 | nSep = sqlite3_value_bytes(argv[1]); |
| @@ -99047,11 +99410,12 @@ | ||
| 99047 | 99410 | int iFromCol; /* Idx of column in child table */ |
| 99048 | 99411 | Expr *pEq; /* tFromCol = OLD.tToCol */ |
| 99049 | 99412 | |
| 99050 | 99413 | iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; |
| 99051 | 99414 | assert( iFromCol>=0 ); |
| 99052 | - tToCol.z = pIdx ? pTab->aCol[pIdx->aiColumn[i]].zName : "oid"; | |
| 99415 | + assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) ); | |
| 99416 | + tToCol.z = pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName; | |
| 99053 | 99417 | tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName; |
| 99054 | 99418 | |
| 99055 | 99419 | tToCol.n = sqlite3Strlen30(tToCol.z); |
| 99056 | 99420 | tFromCol.n = sqlite3Strlen30(tFromCol.z); |
| 99057 | 99421 | |
| @@ -99059,14 +99423,14 @@ | ||
| 99059 | 99423 | ** that the "OLD.zToCol" term is on the LHS of the = operator, so |
| 99060 | 99424 | ** that the affinity and collation sequence associated with the |
| 99061 | 99425 | ** parent table are used for the comparison. */ |
| 99062 | 99426 | pEq = sqlite3PExpr(pParse, TK_EQ, |
| 99063 | 99427 | sqlite3PExpr(pParse, TK_DOT, |
| 99064 | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld), | |
| 99065 | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol) | |
| 99428 | + sqlite3ExprAlloc(db, TK_ID, &tOld, 0), | |
| 99429 | + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0) | |
| 99066 | 99430 | , 0), |
| 99067 | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tFromCol) | |
| 99431 | + sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0) | |
| 99068 | 99432 | , 0); |
| 99069 | 99433 | pWhere = sqlite3ExprAnd(db, pWhere, pEq); |
| 99070 | 99434 | |
| 99071 | 99435 | /* For ON UPDATE, construct the next term of the WHEN clause. |
| 99072 | 99436 | ** The final WHEN clause will be like this: |
| @@ -99074,27 +99438,27 @@ | ||
| 99074 | 99438 | ** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN) |
| 99075 | 99439 | */ |
| 99076 | 99440 | if( pChanges ){ |
| 99077 | 99441 | pEq = sqlite3PExpr(pParse, TK_IS, |
| 99078 | 99442 | sqlite3PExpr(pParse, TK_DOT, |
| 99079 | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld), | |
| 99080 | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol), | |
| 99443 | + sqlite3ExprAlloc(db, TK_ID, &tOld, 0), | |
| 99444 | + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0), | |
| 99081 | 99445 | 0), |
| 99082 | 99446 | sqlite3PExpr(pParse, TK_DOT, |
| 99083 | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew), | |
| 99084 | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol), | |
| 99447 | + sqlite3ExprAlloc(db, TK_ID, &tNew, 0), | |
| 99448 | + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0), | |
| 99085 | 99449 | 0), |
| 99086 | 99450 | 0); |
| 99087 | 99451 | pWhen = sqlite3ExprAnd(db, pWhen, pEq); |
| 99088 | 99452 | } |
| 99089 | 99453 | |
| 99090 | 99454 | if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){ |
| 99091 | 99455 | Expr *pNew; |
| 99092 | 99456 | if( action==OE_Cascade ){ |
| 99093 | 99457 | pNew = sqlite3PExpr(pParse, TK_DOT, |
| 99094 | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew), | |
| 99095 | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol) | |
| 99458 | + sqlite3ExprAlloc(db, TK_ID, &tNew, 0), | |
| 99459 | + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0) | |
| 99096 | 99460 | , 0); |
| 99097 | 99461 | }else if( action==OE_SetDflt ){ |
| 99098 | 99462 | Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt; |
| 99099 | 99463 | if( pDflt ){ |
| 99100 | 99464 | pNew = sqlite3ExprDup(db, pDflt, 0); |
| @@ -99137,17 +99501,16 @@ | ||
| 99137 | 99501 | db->lookaside.bEnabled = 0; |
| 99138 | 99502 | |
| 99139 | 99503 | pTrigger = (Trigger *)sqlite3DbMallocZero(db, |
| 99140 | 99504 | sizeof(Trigger) + /* struct Trigger */ |
| 99141 | 99505 | sizeof(TriggerStep) + /* Single step in trigger program */ |
| 99142 | - nFrom + 1 /* Space for pStep->target.z */ | |
| 99506 | + nFrom + 1 /* Space for pStep->zTarget */ | |
| 99143 | 99507 | ); |
| 99144 | 99508 | if( pTrigger ){ |
| 99145 | 99509 | pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1]; |
| 99146 | - pStep->target.z = (char *)&pStep[1]; | |
| 99147 | - pStep->target.n = nFrom; | |
| 99148 | - memcpy((char *)pStep->target.z, zFrom, nFrom); | |
| 99510 | + pStep->zTarget = (char *)&pStep[1]; | |
| 99511 | + memcpy((char *)pStep->zTarget, zFrom, nFrom); | |
| 99149 | 99512 | |
| 99150 | 99513 | pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE); |
| 99151 | 99514 | pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE); |
| 99152 | 99515 | pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE); |
| 99153 | 99516 | if( pWhen ){ |
| @@ -99608,24 +99971,27 @@ | ||
| 99608 | 99971 | ); |
| 99609 | 99972 | |
| 99610 | 99973 | /* |
| 99611 | 99974 | ** This routine is called to handle SQL of the following forms: |
| 99612 | 99975 | ** |
| 99613 | -** insert into TABLE (IDLIST) values(EXPRLIST) | |
| 99976 | +** insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),... | |
| 99614 | 99977 | ** insert into TABLE (IDLIST) select |
| 99978 | +** insert into TABLE (IDLIST) default values | |
| 99615 | 99979 | ** |
| 99616 | 99980 | ** The IDLIST following the table name is always optional. If omitted, |
| 99617 | -** then a list of all columns for the table is substituted. The IDLIST | |
| 99618 | -** appears in the pColumn parameter. pColumn is NULL if IDLIST is omitted. | |
| 99981 | +** then a list of all (non-hidden) columns for the table is substituted. | |
| 99982 | +** The IDLIST appears in the pColumn parameter. pColumn is NULL if IDLIST | |
| 99983 | +** is omitted. | |
| 99619 | 99984 | ** |
| 99620 | -** The pList parameter holds EXPRLIST in the first form of the INSERT | |
| 99621 | -** statement above, and pSelect is NULL. For the second form, pList is | |
| 99622 | -** NULL and pSelect is a pointer to the select statement used to generate | |
| 99623 | -** data for the insert. | |
| 99985 | +** For the pSelect parameter holds the values to be inserted for the | |
| 99986 | +** first two forms shown above. A VALUES clause is really just short-hand | |
| 99987 | +** for a SELECT statement that omits the FROM clause and everything else | |
| 99988 | +** that follows. If the pSelect parameter is NULL, that means that the | |
| 99989 | +** DEFAULT VALUES form of the INSERT statement is intended. | |
| 99624 | 99990 | ** |
| 99625 | 99991 | ** The code generated follows one of four templates. For a simple |
| 99626 | -** insert with data coming from a VALUES clause, the code executes | |
| 99992 | +** insert with data coming from a single-row VALUES clause, the code executes | |
| 99627 | 99993 | ** once straight down through. Pseudo-code follows (we call this |
| 99628 | 99994 | ** the "1st template"): |
| 99629 | 99995 | ** |
| 99630 | 99996 | ** open write cursor to <table> and its indices |
| 99631 | 99997 | ** put VALUES clause expressions into registers |
| @@ -99728,11 +100094,11 @@ | ||
| 99728 | 100094 | int iDb; /* Index of database holding TABLE */ |
| 99729 | 100095 | Db *pDb; /* The database containing table being inserted into */ |
| 99730 | 100096 | u8 useTempTable = 0; /* Store SELECT results in intermediate table */ |
| 99731 | 100097 | u8 appendFlag = 0; /* True if the insert is likely to be an append */ |
| 99732 | 100098 | u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */ |
| 99733 | - u8 bIdListInOrder = 1; /* True if IDLIST is in table order */ | |
| 100099 | + u8 bIdListInOrder; /* True if IDLIST is in table order */ | |
| 99734 | 100100 | ExprList *pList = 0; /* List of VALUES() to be inserted */ |
| 99735 | 100101 | |
| 99736 | 100102 | /* Register allocations */ |
| 99737 | 100103 | int regFromSelect = 0;/* Base register for data coming from SELECT */ |
| 99738 | 100104 | int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */ |
| @@ -99753,12 +100119,12 @@ | ||
| 99753 | 100119 | if( pParse->nErr || db->mallocFailed ){ |
| 99754 | 100120 | goto insert_cleanup; |
| 99755 | 100121 | } |
| 99756 | 100122 | |
| 99757 | 100123 | /* If the Select object is really just a simple VALUES() list with a |
| 99758 | - ** single row values (the common case) then keep that one row of values | |
| 99759 | - ** and go ahead and discard the Select object | |
| 100124 | + ** single row (the common case) then keep that one row of values | |
| 100125 | + ** and discard the other (unused) parts of the pSelect object | |
| 99760 | 100126 | */ |
| 99761 | 100127 | if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){ |
| 99762 | 100128 | pList = pSelect->pEList; |
| 99763 | 100129 | pSelect->pEList = 0; |
| 99764 | 100130 | sqlite3SelectDelete(db, pSelect); |
| @@ -99862,10 +100228,11 @@ | ||
| 99862 | 100228 | ** the index into IDLIST of the primary key column. ipkColumn is |
| 99863 | 100229 | ** the index of the primary key as it appears in IDLIST, not as |
| 99864 | 100230 | ** is appears in the original table. (The index of the INTEGER |
| 99865 | 100231 | ** PRIMARY KEY in the original table is pTab->iPKey.) |
| 99866 | 100232 | */ |
| 100233 | + bIdListInOrder = (pTab->tabFlags & TF_OOOHidden)==0; | |
| 99867 | 100234 | if( pColumn ){ |
| 99868 | 100235 | for(i=0; i<pColumn->nId; i++){ |
| 99869 | 100236 | pColumn->a[i].idx = -1; |
| 99870 | 100237 | } |
| 99871 | 100238 | for(i=0; i<pColumn->nId; i++){ |
| @@ -99897,11 +100264,12 @@ | ||
| 99897 | 100264 | ** is coming from a SELECT statement, then generate a co-routine that |
| 99898 | 100265 | ** produces a single row of the SELECT on each invocation. The |
| 99899 | 100266 | ** co-routine is the common header to the 3rd and 4th templates. |
| 99900 | 100267 | */ |
| 99901 | 100268 | if( pSelect ){ |
| 99902 | - /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */ | |
| 100269 | + /* Data is coming from a SELECT or from a multi-row VALUES clause. | |
| 100270 | + ** Generate a co-routine to run the SELECT. */ | |
| 99903 | 100271 | int regYield; /* Register holding co-routine entry-point */ |
| 99904 | 100272 | int addrTop; /* Top of the co-routine */ |
| 99905 | 100273 | int rc; /* Result code */ |
| 99906 | 100274 | |
| 99907 | 100275 | regYield = ++pParse->nMem; |
| @@ -99910,12 +100278,11 @@ | ||
| 99910 | 100278 | sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); |
| 99911 | 100279 | dest.iSdst = bIdListInOrder ? regData : 0; |
| 99912 | 100280 | dest.nSdst = pTab->nCol; |
| 99913 | 100281 | rc = sqlite3Select(pParse, pSelect, &dest); |
| 99914 | 100282 | regFromSelect = dest.iSdst; |
| 99915 | - assert( pParse->nErr==0 || rc ); | |
| 99916 | - if( rc || db->mallocFailed ) goto insert_cleanup; | |
| 100283 | + if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup; | |
| 99917 | 100284 | sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield); |
| 99918 | 100285 | sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */ |
| 99919 | 100286 | assert( pSelect->pEList ); |
| 99920 | 100287 | nColumn = pSelect->pEList->nExpr; |
| 99921 | 100288 | |
| @@ -99959,12 +100326,12 @@ | ||
| 99959 | 100326 | sqlite3VdbeJumpHere(v, addrL); |
| 99960 | 100327 | sqlite3ReleaseTempReg(pParse, regRec); |
| 99961 | 100328 | sqlite3ReleaseTempReg(pParse, regTempRowid); |
| 99962 | 100329 | } |
| 99963 | 100330 | }else{ |
| 99964 | - /* This is the case if the data for the INSERT is coming from a VALUES | |
| 99965 | - ** clause | |
| 100331 | + /* This is the case if the data for the INSERT is coming from a | |
| 100332 | + ** single-row VALUES clause | |
| 99966 | 100333 | */ |
| 99967 | 100334 | NameContext sNC; |
| 99968 | 100335 | memset(&sNC, 0, sizeof(sNC)); |
| 99969 | 100336 | sNC.pParse = pParse; |
| 99970 | 100337 | srcTab = -1; |
| @@ -101031,10 +101398,11 @@ | ||
| 101031 | 101398 | Table *pDest, /* The table we are inserting into */ |
| 101032 | 101399 | Select *pSelect, /* A SELECT statement to use as the data source */ |
| 101033 | 101400 | int onError, /* How to handle constraint errors */ |
| 101034 | 101401 | int iDbDest /* The database of pDest */ |
| 101035 | 101402 | ){ |
| 101403 | + sqlite3 *db = pParse->db; | |
| 101036 | 101404 | ExprList *pEList; /* The result set of the SELECT */ |
| 101037 | 101405 | Table *pSrc; /* The table in the FROM clause of SELECT */ |
| 101038 | 101406 | Index *pSrcIdx, *pDestIdx; /* Source and destination indices */ |
| 101039 | 101407 | struct SrcList_item *pItem; /* An element of pSelect->pSrc */ |
| 101040 | 101408 | int i; /* Loop counter */ |
| @@ -101178,15 +101546,15 @@ | ||
| 101178 | 101546 | ** But the main beneficiary of the transfer optimization is the VACUUM |
| 101179 | 101547 | ** command, and the VACUUM command disables foreign key constraints. So |
| 101180 | 101548 | ** the extra complication to make this rule less restrictive is probably |
| 101181 | 101549 | ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] |
| 101182 | 101550 | */ |
| 101183 | - if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ | |
| 101551 | + if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ | |
| 101184 | 101552 | return 0; |
| 101185 | 101553 | } |
| 101186 | 101554 | #endif |
| 101187 | - if( (pParse->db->flags & SQLITE_CountRows)!=0 ){ | |
| 101555 | + if( (db->flags & SQLITE_CountRows)!=0 ){ | |
| 101188 | 101556 | return 0; /* xfer opt does not play well with PRAGMA count_changes */ |
| 101189 | 101557 | } |
| 101190 | 101558 | |
| 101191 | 101559 | /* If we get this far, it means that the xfer optimization is at |
| 101192 | 101560 | ** least a possibility, though it might only work if the destination |
| @@ -101193,28 +101561,32 @@ | ||
| 101193 | 101561 | ** table (tab1) is initially empty. |
| 101194 | 101562 | */ |
| 101195 | 101563 | #ifdef SQLITE_TEST |
| 101196 | 101564 | sqlite3_xferopt_count++; |
| 101197 | 101565 | #endif |
| 101198 | - iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema); | |
| 101566 | + iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema); | |
| 101199 | 101567 | v = sqlite3GetVdbe(pParse); |
| 101200 | 101568 | sqlite3CodeVerifySchema(pParse, iDbSrc); |
| 101201 | 101569 | iSrc = pParse->nTab++; |
| 101202 | 101570 | iDest = pParse->nTab++; |
| 101203 | 101571 | regAutoinc = autoIncBegin(pParse, iDbDest, pDest); |
| 101204 | 101572 | regData = sqlite3GetTempReg(pParse); |
| 101205 | 101573 | regRowid = sqlite3GetTempReg(pParse); |
| 101206 | 101574 | sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite); |
| 101207 | 101575 | assert( HasRowid(pDest) || destHasUniqueIdx ); |
| 101208 | - if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */ | |
| 101576 | + if( (db->flags & SQLITE_Vacuum)==0 && ( | |
| 101577 | + (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */ | |
| 101209 | 101578 | || destHasUniqueIdx /* (2) */ |
| 101210 | 101579 | || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */ |
| 101211 | - ){ | |
| 101580 | + )){ | |
| 101212 | 101581 | /* In some circumstances, we are able to run the xfer optimization |
| 101213 | - ** only if the destination table is initially empty. This code makes | |
| 101214 | - ** that determination. Conditions under which the destination must | |
| 101215 | - ** be empty: | |
| 101582 | + ** only if the destination table is initially empty. Unless the | |
| 101583 | + ** SQLITE_Vacuum flag is set, this block generates code to make | |
| 101584 | + ** that determination. If SQLITE_Vacuum is set, then the destination | |
| 101585 | + ** table is always empty. | |
| 101586 | + ** | |
| 101587 | + ** Conditions under which the destination must be empty: | |
| 101216 | 101588 | ** |
| 101217 | 101589 | ** (1) There is no INTEGER PRIMARY KEY but there are indices. |
| 101218 | 101590 | ** (If the destination is not initially empty, the rowid fields |
| 101219 | 101591 | ** of index entries might need to change.) |
| 101220 | 101592 | ** |
| @@ -101253,10 +101625,11 @@ | ||
| 101253 | 101625 | }else{ |
| 101254 | 101626 | sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName); |
| 101255 | 101627 | sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName); |
| 101256 | 101628 | } |
| 101257 | 101629 | for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){ |
| 101630 | + u8 useSeekResult = 0; | |
| 101258 | 101631 | for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){ |
| 101259 | 101632 | if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break; |
| 101260 | 101633 | } |
| 101261 | 101634 | assert( pSrcIdx ); |
| 101262 | 101635 | sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc); |
| @@ -101266,11 +101639,37 @@ | ||
| 101266 | 101639 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 101267 | 101640 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 101268 | 101641 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 101269 | 101642 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 101270 | 101643 | sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData); |
| 101644 | + if( db->flags & SQLITE_Vacuum ){ | |
| 101645 | + /* This INSERT command is part of a VACUUM operation, which guarantees | |
| 101646 | + ** that the destination table is empty. If all indexed columns use | |
| 101647 | + ** collation sequence BINARY, then it can also be assumed that the | |
| 101648 | + ** index will be populated by inserting keys in strictly sorted | |
| 101649 | + ** order. In this case, instead of seeking within the b-tree as part | |
| 101650 | + ** of every OP_IdxInsert opcode, an OP_Last is added before the | |
| 101651 | + ** OP_IdxInsert to seek to the point within the b-tree where each key | |
| 101652 | + ** should be inserted. This is faster. | |
| 101653 | + ** | |
| 101654 | + ** If any of the indexed columns use a collation sequence other than | |
| 101655 | + ** BINARY, this optimization is disabled. This is because the user | |
| 101656 | + ** might change the definition of a collation sequence and then run | |
| 101657 | + ** a VACUUM command. In that case keys may not be written in strictly | |
| 101658 | + ** sorted order. */ | |
| 101659 | + for(i=0; i<pSrcIdx->nColumn; i++){ | |
| 101660 | + char *zColl = pSrcIdx->azColl[i]; | |
| 101661 | + assert( zColl!=0 ); | |
| 101662 | + if( sqlite3_stricmp("BINARY", zColl) ) break; | |
| 101663 | + } | |
| 101664 | + if( i==pSrcIdx->nColumn ){ | |
| 101665 | + useSeekResult = OPFLAG_USESEEKRESULT; | |
| 101666 | + sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1); | |
| 101667 | + } | |
| 101668 | + } | |
| 101271 | 101669 | sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1); |
| 101670 | + sqlite3VdbeChangeP5(v, useSeekResult); | |
| 101272 | 101671 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v); |
| 101273 | 101672 | sqlite3VdbeJumpHere(v, addr1); |
| 101274 | 101673 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| 101275 | 101674 | sqlite3VdbeAddOp2(v, OP_Close, iDest, 0); |
| 101276 | 101675 | } |
| @@ -102385,11 +102784,11 @@ | ||
| 102385 | 102784 | int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); |
| 102386 | 102785 | char *zErrmsg = 0; |
| 102387 | 102786 | const char *zEntry; |
| 102388 | 102787 | char *zAltEntry = 0; |
| 102389 | 102788 | void **aHandle; |
| 102390 | - int nMsg = 300 + sqlite3Strlen30(zFile); | |
| 102789 | + u64 nMsg = 300 + sqlite3Strlen30(zFile); | |
| 102391 | 102790 | int ii; |
| 102392 | 102791 | |
| 102393 | 102792 | /* Shared library endings to try if zFile cannot be loaded as written */ |
| 102394 | 102793 | static const char *azEndings[] = { |
| 102395 | 102794 | #if SQLITE_OS_WIN |
| @@ -102428,11 +102827,11 @@ | ||
| 102428 | 102827 | sqlite3_free(zAltFile); |
| 102429 | 102828 | } |
| 102430 | 102829 | #endif |
| 102431 | 102830 | if( handle==0 ){ |
| 102432 | 102831 | if( pzErrMsg ){ |
| 102433 | - *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg); | |
| 102832 | + *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg); | |
| 102434 | 102833 | if( zErrmsg ){ |
| 102435 | 102834 | sqlite3_snprintf(nMsg, zErrmsg, |
| 102436 | 102835 | "unable to open shared library [%s]", zFile); |
| 102437 | 102836 | sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); |
| 102438 | 102837 | } |
| @@ -102454,11 +102853,11 @@ | ||
| 102454 | 102853 | ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init |
| 102455 | 102854 | */ |
| 102456 | 102855 | if( xInit==0 && zProc==0 ){ |
| 102457 | 102856 | int iFile, iEntry, c; |
| 102458 | 102857 | int ncFile = sqlite3Strlen30(zFile); |
| 102459 | - zAltEntry = sqlite3_malloc(ncFile+30); | |
| 102858 | + zAltEntry = sqlite3_malloc64(ncFile+30); | |
| 102460 | 102859 | if( zAltEntry==0 ){ |
| 102461 | 102860 | sqlite3OsDlClose(pVfs, handle); |
| 102462 | 102861 | return SQLITE_NOMEM; |
| 102463 | 102862 | } |
| 102464 | 102863 | memcpy(zAltEntry, "sqlite3_", 8); |
| @@ -102476,11 +102875,11 @@ | ||
| 102476 | 102875 | sqlite3OsDlSym(pVfs, handle, zEntry); |
| 102477 | 102876 | } |
| 102478 | 102877 | if( xInit==0 ){ |
| 102479 | 102878 | if( pzErrMsg ){ |
| 102480 | 102879 | nMsg += sqlite3Strlen30(zEntry); |
| 102481 | - *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg); | |
| 102880 | + *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg); | |
| 102482 | 102881 | if( zErrmsg ){ |
| 102483 | 102882 | sqlite3_snprintf(nMsg, zErrmsg, |
| 102484 | 102883 | "no entry point [%s] in shared library [%s]", zEntry, zFile); |
| 102485 | 102884 | sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); |
| 102486 | 102885 | } |
| @@ -102575,11 +102974,11 @@ | ||
| 102575 | 102974 | ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER |
| 102576 | 102975 | ** mutex must be held while accessing this list. |
| 102577 | 102976 | */ |
| 102578 | 102977 | typedef struct sqlite3AutoExtList sqlite3AutoExtList; |
| 102579 | 102978 | static SQLITE_WSD struct sqlite3AutoExtList { |
| 102580 | - int nExt; /* Number of entries in aExt[] */ | |
| 102979 | + u32 nExt; /* Number of entries in aExt[] */ | |
| 102581 | 102980 | void (**aExt)(void); /* Pointers to the extension init functions */ |
| 102582 | 102981 | } sqlite3Autoext = { 0, 0 }; |
| 102583 | 102982 | |
| 102584 | 102983 | /* The "wsdAutoext" macro will resolve to the autoextension |
| 102585 | 102984 | ** state vector. If writable static data is unsupported on the target, |
| @@ -102608,23 +103007,23 @@ | ||
| 102608 | 103007 | if( rc ){ |
| 102609 | 103008 | return rc; |
| 102610 | 103009 | }else |
| 102611 | 103010 | #endif |
| 102612 | 103011 | { |
| 102613 | - int i; | |
| 103012 | + u32 i; | |
| 102614 | 103013 | #if SQLITE_THREADSAFE |
| 102615 | 103014 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 102616 | 103015 | #endif |
| 102617 | 103016 | wsdAutoextInit; |
| 102618 | 103017 | sqlite3_mutex_enter(mutex); |
| 102619 | 103018 | for(i=0; i<wsdAutoext.nExt; i++){ |
| 102620 | 103019 | if( wsdAutoext.aExt[i]==xInit ) break; |
| 102621 | 103020 | } |
| 102622 | 103021 | if( i==wsdAutoext.nExt ){ |
| 102623 | - int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]); | |
| 103022 | + u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]); | |
| 102624 | 103023 | void (**aNew)(void); |
| 102625 | - aNew = sqlite3_realloc(wsdAutoext.aExt, nByte); | |
| 103024 | + aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte); | |
| 102626 | 103025 | if( aNew==0 ){ |
| 102627 | 103026 | rc = SQLITE_NOMEM; |
| 102628 | 103027 | }else{ |
| 102629 | 103028 | wsdAutoext.aExt = aNew; |
| 102630 | 103029 | wsdAutoext.aExt[wsdAutoext.nExt] = xInit; |
| @@ -102652,11 +103051,11 @@ | ||
| 102652 | 103051 | #endif |
| 102653 | 103052 | int i; |
| 102654 | 103053 | int n = 0; |
| 102655 | 103054 | wsdAutoextInit; |
| 102656 | 103055 | sqlite3_mutex_enter(mutex); |
| 102657 | - for(i=wsdAutoext.nExt-1; i>=0; i--){ | |
| 103056 | + for(i=(int)wsdAutoext.nExt-1; i>=0; i--){ | |
| 102658 | 103057 | if( wsdAutoext.aExt[i]==xInit ){ |
| 102659 | 103058 | wsdAutoext.nExt--; |
| 102660 | 103059 | wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt]; |
| 102661 | 103060 | n++; |
| 102662 | 103061 | break; |
| @@ -102690,11 +103089,11 @@ | ||
| 102690 | 103089 | ** Load all automatic extensions. |
| 102691 | 103090 | ** |
| 102692 | 103091 | ** If anything goes wrong, set an error in the database connection. |
| 102693 | 103092 | */ |
| 102694 | 103093 | SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){ |
| 102695 | - int i; | |
| 103094 | + u32 i; | |
| 102696 | 103095 | int go = 1; |
| 102697 | 103096 | int rc; |
| 102698 | 103097 | int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); |
| 102699 | 103098 | |
| 102700 | 103099 | wsdAutoextInit; |
| @@ -103354,19 +103753,19 @@ | ||
| 103354 | 103753 | /* |
| 103355 | 103754 | ** Generate code to return a single integer value. |
| 103356 | 103755 | */ |
| 103357 | 103756 | static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){ |
| 103358 | 103757 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 103359 | - int mem = ++pParse->nMem; | |
| 103758 | + int nMem = ++pParse->nMem; | |
| 103360 | 103759 | i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value)); |
| 103361 | 103760 | if( pI64 ){ |
| 103362 | 103761 | memcpy(pI64, &value, sizeof(value)); |
| 103363 | 103762 | } |
| 103364 | - sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64); | |
| 103763 | + sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64); | |
| 103365 | 103764 | sqlite3VdbeSetNumCols(v, 1); |
| 103366 | 103765 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC); |
| 103367 | - sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); | |
| 103766 | + sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1); | |
| 103368 | 103767 | } |
| 103369 | 103768 | |
| 103370 | 103769 | |
| 103371 | 103770 | /* |
| 103372 | 103771 | ** Set the safety_level and pager flags for pager iDb. Or if iDb<0 |
| @@ -103527,15 +103926,15 @@ | ||
| 103527 | 103926 | aFcntl[3] = 0; |
| 103528 | 103927 | db->busyHandler.nBusy = 0; |
| 103529 | 103928 | rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl); |
| 103530 | 103929 | if( rc==SQLITE_OK ){ |
| 103531 | 103930 | if( aFcntl[0] ){ |
| 103532 | - int mem = ++pParse->nMem; | |
| 103533 | - sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0); | |
| 103931 | + int nMem = ++pParse->nMem; | |
| 103932 | + sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0); | |
| 103534 | 103933 | sqlite3VdbeSetNumCols(v, 1); |
| 103535 | 103934 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC); |
| 103536 | - sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); | |
| 103935 | + sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1); | |
| 103537 | 103936 | sqlite3_free(aFcntl[0]); |
| 103538 | 103937 | } |
| 103539 | 103938 | goto pragma_out; |
| 103540 | 103939 | } |
| 103541 | 103940 | if( rc!=SQLITE_NOTFOUND ){ |
| @@ -104136,11 +104535,13 @@ | ||
| 104136 | 104535 | }else{ |
| 104137 | 104536 | if( !db->autoCommit ){ |
| 104138 | 104537 | sqlite3ErrorMsg(pParse, |
| 104139 | 104538 | "Safety level may not be changed inside a transaction"); |
| 104140 | 104539 | }else{ |
| 104141 | - pDb->safety_level = getSafetyLevel(zRight,0,1)+1; | |
| 104540 | + int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK; | |
| 104541 | + if( iLevel==0 ) iLevel = 1; | |
| 104542 | + pDb->safety_level = iLevel; | |
| 104142 | 104543 | setAllPagerFlags(db); |
| 104143 | 104544 | } |
| 104144 | 104545 | } |
| 104145 | 104546 | break; |
| 104146 | 104547 | } |
| @@ -104231,11 +104632,11 @@ | ||
| 104231 | 104632 | if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){ |
| 104232 | 104633 | k = 0; |
| 104233 | 104634 | }else if( pPk==0 ){ |
| 104234 | 104635 | k = 1; |
| 104235 | 104636 | }else{ |
| 104236 | - for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){} | |
| 104637 | + for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} | |
| 104237 | 104638 | } |
| 104238 | 104639 | sqlite3VdbeAddOp2(v, OP_Integer, k, 6); |
| 104239 | 104640 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); |
| 104240 | 104641 | } |
| 104241 | 104642 | } |
| @@ -105237,11 +105638,11 @@ | ||
| 105237 | 105638 | |
| 105238 | 105639 | assert( iDb>=0 && iDb<db->nDb ); |
| 105239 | 105640 | if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */ |
| 105240 | 105641 | if( argv[1]==0 ){ |
| 105241 | 105642 | corruptSchema(pData, argv[0], 0); |
| 105242 | - }else if( argv[2] && argv[2][0] ){ | |
| 105643 | + }else if( sqlite3_strnicmp(argv[2],"create ",7)==0 ){ | |
| 105243 | 105644 | /* Call the parser to process a CREATE TABLE, INDEX or VIEW. |
| 105244 | 105645 | ** But because db->init.busy is set to 1, no VDBE code is generated |
| 105245 | 105646 | ** or executed. All the parser does is build the internal data |
| 105246 | 105647 | ** structures that describe the table, index, or view. |
| 105247 | 105648 | */ |
| @@ -105268,12 +105669,12 @@ | ||
| 105268 | 105669 | corruptSchema(pData, argv[0], sqlite3_errmsg(db)); |
| 105269 | 105670 | } |
| 105270 | 105671 | } |
| 105271 | 105672 | } |
| 105272 | 105673 | sqlite3_finalize(pStmt); |
| 105273 | - }else if( argv[0]==0 ){ | |
| 105274 | - corruptSchema(pData, 0, 0); | |
| 105674 | + }else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){ | |
| 105675 | + corruptSchema(pData, argv[0], 0); | |
| 105275 | 105676 | }else{ |
| 105276 | 105677 | /* If the SQL column is blank it means this is an index that |
| 105277 | 105678 | ** was created to be the PRIMARY KEY or to fulfill a UNIQUE |
| 105278 | 105679 | ** constraint for a CREATE TABLE. The index should have already |
| 105279 | 105680 | ** been created when we processed the CREATE TABLE. All we have |
| @@ -106176,11 +106577,10 @@ | ||
| 106176 | 106577 | ){ |
| 106177 | 106578 | Select *pNew; |
| 106178 | 106579 | Select standin; |
| 106179 | 106580 | sqlite3 *db = pParse->db; |
| 106180 | 106581 | pNew = sqlite3DbMallocZero(db, sizeof(*pNew) ); |
| 106181 | - assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */ | |
| 106182 | 106582 | if( pNew==0 ){ |
| 106183 | 106583 | assert( db->mallocFailed ); |
| 106184 | 106584 | pNew = &standin; |
| 106185 | 106585 | memset(pNew, 0, sizeof(*pNew)); |
| 106186 | 106586 | } |
| @@ -106196,11 +106596,11 @@ | ||
| 106196 | 106596 | pNew->pOrderBy = pOrderBy; |
| 106197 | 106597 | pNew->selFlags = selFlags; |
| 106198 | 106598 | pNew->op = TK_SELECT; |
| 106199 | 106599 | pNew->pLimit = pLimit; |
| 106200 | 106600 | pNew->pOffset = pOffset; |
| 106201 | - assert( pOffset==0 || pLimit!=0 ); | |
| 106601 | + assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 ); | |
| 106202 | 106602 | pNew->addrOpenEphm[0] = -1; |
| 106203 | 106603 | pNew->addrOpenEphm[1] = -1; |
| 106204 | 106604 | if( db->mallocFailed ) { |
| 106205 | 106605 | clearSelect(db, pNew, pNew!=&standin); |
| 106206 | 106606 | pNew = 0; |
| @@ -107446,11 +107846,11 @@ | ||
| 107446 | 107846 | if( pS ){ |
| 107447 | 107847 | /* The "table" is actually a sub-select or a view in the FROM clause |
| 107448 | 107848 | ** of the SELECT statement. Return the declaration type and origin |
| 107449 | 107849 | ** data for the result-set column of the sub-select. |
| 107450 | 107850 | */ |
| 107451 | - if( iCol>=0 && ALWAYS(iCol<pS->pEList->nExpr) ){ | |
| 107851 | + if( iCol>=0 && iCol<pS->pEList->nExpr ){ | |
| 107452 | 107852 | /* If iCol is less than zero, then the expression requests the |
| 107453 | 107853 | ** rowid of the sub-select or view. This expression is legal (see |
| 107454 | 107854 | ** test case misc2.2.2) - it always evaluates to NULL. |
| 107455 | 107855 | */ |
| 107456 | 107856 | NameContext sNC; |
| @@ -107766,16 +108166,18 @@ | ||
| 107766 | 108166 | memset(&sNC, 0, sizeof(sNC)); |
| 107767 | 108167 | sNC.pSrcList = pSelect->pSrc; |
| 107768 | 108168 | a = pSelect->pEList->a; |
| 107769 | 108169 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
| 107770 | 108170 | p = a[i].pExpr; |
| 107771 | - pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst)); | |
| 108171 | + if( pCol->zType==0 ){ | |
| 108172 | + pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst)); | |
| 108173 | + } | |
| 107772 | 108174 | szAll += pCol->szEst; |
| 107773 | 108175 | pCol->affinity = sqlite3ExprAffinity(p); |
| 107774 | 108176 | if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE; |
| 107775 | 108177 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 107776 | - if( pColl ){ | |
| 108178 | + if( pColl && pCol->zColl==0 ){ | |
| 107777 | 108179 | pCol->zColl = sqlite3DbStrDup(db, pColl->zName); |
| 107778 | 108180 | } |
| 107779 | 108181 | } |
| 107780 | 108182 | pTab->szTabRow = sqlite3LogEst(szAll*4); |
| 107781 | 108183 | } |
| @@ -108173,12 +108575,11 @@ | ||
| 108173 | 108575 | ){ |
| 108174 | 108576 | Select *pPrior; |
| 108175 | 108577 | int nExpr = p->pEList->nExpr; |
| 108176 | 108578 | int nRow = 1; |
| 108177 | 108579 | int rc = 0; |
| 108178 | - assert( p->pNext==0 ); | |
| 108179 | - assert( p->selFlags & SF_AllValues ); | |
| 108580 | + assert( p->selFlags & SF_MultiValue ); | |
| 108180 | 108581 | do{ |
| 108181 | 108582 | assert( p->selFlags & SF_Values ); |
| 108182 | 108583 | assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) ); |
| 108183 | 108584 | assert( p->pLimit==0 ); |
| 108184 | 108585 | assert( p->pOffset==0 ); |
| @@ -108283,11 +108684,11 @@ | ||
| 108283 | 108684 | dest.eDest = SRT_Table; |
| 108284 | 108685 | } |
| 108285 | 108686 | |
| 108286 | 108687 | /* Special handling for a compound-select that originates as a VALUES clause. |
| 108287 | 108688 | */ |
| 108288 | - if( p->selFlags & SF_AllValues ){ | |
| 108689 | + if( p->selFlags & SF_MultiValue ){ | |
| 108289 | 108690 | rc = multiSelectValues(pParse, p, &dest); |
| 108290 | 108691 | goto multi_select_end; |
| 108291 | 108692 | } |
| 108292 | 108693 | |
| 108293 | 108694 | /* Make sure all SELECTs in the statement have the same number of elements |
| @@ -108668,11 +109069,11 @@ | ||
| 108668 | 109069 | ** then there should be a single item on the stack. Write this |
| 108669 | 109070 | ** item into the set table with bogus data. |
| 108670 | 109071 | */ |
| 108671 | 109072 | case SRT_Set: { |
| 108672 | 109073 | int r1; |
| 108673 | - assert( pIn->nSdst==1 ); | |
| 109074 | + assert( pIn->nSdst==1 || pParse->nErr>0 ); | |
| 108674 | 109075 | pDest->affSdst = |
| 108675 | 109076 | sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst); |
| 108676 | 109077 | r1 = sqlite3GetTempReg(pParse); |
| 108677 | 109078 | sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1); |
| 108678 | 109079 | sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1); |
| @@ -108694,11 +109095,11 @@ | ||
| 108694 | 109095 | /* If this is a scalar select that is part of an expression, then |
| 108695 | 109096 | ** store the results in the appropriate memory cell and break out |
| 108696 | 109097 | ** of the scan loop. |
| 108697 | 109098 | */ |
| 108698 | 109099 | case SRT_Mem: { |
| 108699 | - assert( pIn->nSdst==1 ); | |
| 109100 | + assert( pIn->nSdst==1 || pParse->nErr>0 ); testcase( pIn->nSdst!=1 ); | |
| 108700 | 109101 | sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1); |
| 108701 | 109102 | /* The LIMIT clause will jump out of the loop for us */ |
| 108702 | 109103 | break; |
| 108703 | 109104 | } |
| 108704 | 109105 | #endif /* #ifndef SQLITE_OMIT_SUBQUERY */ |
| @@ -108709,11 +109110,11 @@ | ||
| 108709 | 109110 | case SRT_Coroutine: { |
| 108710 | 109111 | if( pDest->iSdst==0 ){ |
| 108711 | 109112 | pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst); |
| 108712 | 109113 | pDest->nSdst = pIn->nSdst; |
| 108713 | 109114 | } |
| 108714 | - sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst); | |
| 109115 | + sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst); | |
| 108715 | 109116 | sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm); |
| 108716 | 109117 | break; |
| 108717 | 109118 | } |
| 108718 | 109119 | |
| 108719 | 109120 | /* If none of the above, then the result destination must be |
| @@ -108925,12 +109326,14 @@ | ||
| 108925 | 109326 | */ |
| 108926 | 109327 | aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy); |
| 108927 | 109328 | if( aPermute ){ |
| 108928 | 109329 | struct ExprList_item *pItem; |
| 108929 | 109330 | for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){ |
| 108930 | - assert( pItem->u.x.iOrderByCol>0 | |
| 108931 | - && pItem->u.x.iOrderByCol<=p->pEList->nExpr ); | |
| 109331 | + assert( pItem->u.x.iOrderByCol>0 ); | |
| 109332 | + /* assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ) is also true | |
| 109333 | + ** but only for well-formed SELECT statements. */ | |
| 109334 | + testcase( pItem->u.x.iOrderByCol > p->pEList->nExpr ); | |
| 108932 | 109335 | aPermute[i] = pItem->u.x.iOrderByCol - 1; |
| 108933 | 109336 | } |
| 108934 | 109337 | pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1); |
| 108935 | 109338 | }else{ |
| 108936 | 109339 | pKeyMerge = 0; |
| @@ -109136,11 +109539,11 @@ | ||
| 109136 | 109539 | pPrior->pNext = p; |
| 109137 | 109540 | |
| 109138 | 109541 | /*** TBD: Insert subroutine calls to close cursors on incomplete |
| 109139 | 109542 | **** subqueries ****/ |
| 109140 | 109543 | explainComposite(pParse, p->op, iSub1, iSub2, 0); |
| 109141 | - return SQLITE_OK; | |
| 109544 | + return pParse->nErr!=0; | |
| 109142 | 109545 | } |
| 109143 | 109546 | #endif |
| 109144 | 109547 | |
| 109145 | 109548 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 109146 | 109549 | /* Forward Declarations */ |
| @@ -109948,10 +110351,11 @@ | ||
| 109948 | 110351 | pNew->pGroupBy = 0; |
| 109949 | 110352 | pNew->pHaving = 0; |
| 109950 | 110353 | pNew->pOrderBy = 0; |
| 109951 | 110354 | p->pPrior = 0; |
| 109952 | 110355 | p->pNext = 0; |
| 110356 | + p->pWith = 0; | |
| 109953 | 110357 | p->selFlags &= ~SF_Compound; |
| 109954 | 110358 | assert( (p->selFlags & SF_Converted)==0 ); |
| 109955 | 110359 | p->selFlags |= SF_Converted; |
| 109956 | 110360 | assert( pNew->pPrior!=0 ); |
| 109957 | 110361 | pNew->pPrior->pNext = pNew; |
| @@ -110486,11 +110890,11 @@ | ||
| 110486 | 110890 | if( pParse->hasCompound ){ |
| 110487 | 110891 | w.xSelectCallback = convertCompoundSelectToSubquery; |
| 110488 | 110892 | sqlite3WalkSelect(&w, pSelect); |
| 110489 | 110893 | } |
| 110490 | 110894 | w.xSelectCallback = selectExpander; |
| 110491 | - if( (pSelect->selFlags & SF_AllValues)==0 ){ | |
| 110895 | + if( (pSelect->selFlags & SF_MultiValue)==0 ){ | |
| 110492 | 110896 | w.xSelectCallback2 = selectPopWith; |
| 110493 | 110897 | } |
| 110494 | 110898 | sqlite3WalkSelect(&w, pSelect); |
| 110495 | 110899 | } |
| 110496 | 110900 | |
| @@ -110672,11 +111076,12 @@ | ||
| 110672 | 111076 | nArg = 0; |
| 110673 | 111077 | regAgg = 0; |
| 110674 | 111078 | } |
| 110675 | 111079 | if( pF->iDistinct>=0 ){ |
| 110676 | 111080 | addrNext = sqlite3VdbeMakeLabel(v); |
| 110677 | - assert( nArg==1 ); | |
| 111081 | + testcase( nArg==0 ); /* Error condition */ | |
| 111082 | + testcase( nArg>1 ); /* Also an error */ | |
| 110678 | 111083 | codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg); |
| 110679 | 111084 | } |
| 110680 | 111085 | if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 110681 | 111086 | CollSeq *pColl = 0; |
| 110682 | 111087 | struct ExprList_item *pItem; |
| @@ -111547,14 +111952,13 @@ | ||
| 111547 | 111952 | |
| 111548 | 111953 | /* Jump here to skip this query |
| 111549 | 111954 | */ |
| 111550 | 111955 | sqlite3VdbeResolveLabel(v, iEnd); |
| 111551 | 111956 | |
| 111552 | - /* The SELECT was successfully coded. Set the return code to 0 | |
| 111553 | - ** to indicate no errors. | |
| 111554 | - */ | |
| 111555 | - rc = 0; | |
| 111957 | + /* The SELECT has been coded. If there is an error in the Parse structure, | |
| 111958 | + ** set the return code to 1. Otherwise 0. */ | |
| 111959 | + rc = (pParse->nErr>0); | |
| 111556 | 111960 | |
| 111557 | 111961 | /* Control jumps to here if an error is encountered above, or upon |
| 111558 | 111962 | ** successful coding of the SELECT. |
| 111559 | 111963 | */ |
| 111560 | 111964 | select_end: |
| @@ -111601,11 +112005,11 @@ | ||
| 111601 | 112005 | sqlite3TreeViewLine(pView, "FROM"); |
| 111602 | 112006 | for(i=0; i<p->pSrc->nSrc; i++){ |
| 111603 | 112007 | struct SrcList_item *pItem = &p->pSrc->a[i]; |
| 111604 | 112008 | StrAccum x; |
| 111605 | 112009 | char zLine[100]; |
| 111606 | - sqlite3StrAccumInit(&x, zLine, sizeof(zLine), 0); | |
| 112010 | + sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); | |
| 111607 | 112011 | sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor); |
| 111608 | 112012 | if( pItem->zDatabase ){ |
| 111609 | 112013 | sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName); |
| 111610 | 112014 | }else if( pItem->zName ){ |
| 111611 | 112015 | sqlite3XPrintf(&x, 0, " %s", pItem->zName); |
| @@ -111760,11 +112164,11 @@ | ||
| 111760 | 112164 | for(i=0; i<nCol; i++){ |
| 111761 | 112165 | if( argv[i]==0 ){ |
| 111762 | 112166 | z = 0; |
| 111763 | 112167 | }else{ |
| 111764 | 112168 | int n = sqlite3Strlen30(argv[i])+1; |
| 111765 | - z = sqlite3_malloc( n ); | |
| 112169 | + z = sqlite3_malloc64( n ); | |
| 111766 | 112170 | if( z==0 ) goto malloc_failed; |
| 111767 | 112171 | memcpy(z, argv[i], n); |
| 111768 | 112172 | } |
| 111769 | 112173 | p->azResult[p->nData++] = z; |
| 111770 | 112174 | } |
| @@ -111809,11 +112213,11 @@ | ||
| 111809 | 112213 | res.nRow = 0; |
| 111810 | 112214 | res.nColumn = 0; |
| 111811 | 112215 | res.nData = 1; |
| 111812 | 112216 | res.nAlloc = 20; |
| 111813 | 112217 | res.rc = SQLITE_OK; |
| 111814 | - res.azResult = sqlite3_malloc(sizeof(char*)*res.nAlloc ); | |
| 112218 | + res.azResult = sqlite3_malloc64(sizeof(char*)*res.nAlloc ); | |
| 111815 | 112219 | if( res.azResult==0 ){ |
| 111816 | 112220 | db->errCode = SQLITE_NOMEM; |
| 111817 | 112221 | return SQLITE_NOMEM; |
| 111818 | 112222 | } |
| 111819 | 112223 | res.azResult[0] = 0; |
| @@ -111837,11 +112241,11 @@ | ||
| 111837 | 112241 | sqlite3_free_table(&res.azResult[1]); |
| 111838 | 112242 | return rc; |
| 111839 | 112243 | } |
| 111840 | 112244 | if( res.nAlloc>res.nData ){ |
| 111841 | 112245 | char **azNew; |
| 111842 | - azNew = sqlite3_realloc( res.azResult, sizeof(char*)*res.nData ); | |
| 112246 | + azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData ); | |
| 111843 | 112247 | if( azNew==0 ){ |
| 111844 | 112248 | sqlite3_free_table(&res.azResult[1]); |
| 111845 | 112249 | db->errCode = SQLITE_NOMEM; |
| 111846 | 112250 | return SQLITE_NOMEM; |
| 111847 | 112251 | } |
| @@ -112065,11 +112469,10 @@ | ||
| 112065 | 112469 | } |
| 112066 | 112470 | |
| 112067 | 112471 | /* Do not create a trigger on a system table */ |
| 112068 | 112472 | if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){ |
| 112069 | 112473 | sqlite3ErrorMsg(pParse, "cannot create trigger on system table"); |
| 112070 | - pParse->nErr++; | |
| 112071 | 112474 | goto trigger_cleanup; |
| 112072 | 112475 | } |
| 112073 | 112476 | |
| 112074 | 112477 | /* INSTEAD of triggers are only for views and views only support INSTEAD |
| 112075 | 112478 | ** of triggers. |
| @@ -112245,16 +112648,16 @@ | ||
| 112245 | 112648 | u8 op, /* Trigger opcode */ |
| 112246 | 112649 | Token *pName /* The target name */ |
| 112247 | 112650 | ){ |
| 112248 | 112651 | TriggerStep *pTriggerStep; |
| 112249 | 112652 | |
| 112250 | - pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n); | |
| 112653 | + pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1); | |
| 112251 | 112654 | if( pTriggerStep ){ |
| 112252 | 112655 | char *z = (char*)&pTriggerStep[1]; |
| 112253 | 112656 | memcpy(z, pName->z, pName->n); |
| 112254 | - pTriggerStep->target.z = z; | |
| 112255 | - pTriggerStep->target.n = pName->n; | |
| 112657 | + sqlite3Dequote(z); | |
| 112658 | + pTriggerStep->zTarget = z; | |
| 112256 | 112659 | pTriggerStep->op = op; |
| 112257 | 112660 | } |
| 112258 | 112661 | return pTriggerStep; |
| 112259 | 112662 | } |
| 112260 | 112663 | |
| @@ -112533,11 +112936,11 @@ | ||
| 112533 | 112936 | } |
| 112534 | 112937 | return (mask ? pList : 0); |
| 112535 | 112938 | } |
| 112536 | 112939 | |
| 112537 | 112940 | /* |
| 112538 | -** Convert the pStep->target token into a SrcList and return a pointer | |
| 112941 | +** Convert the pStep->zTarget string into a SrcList and return a pointer | |
| 112539 | 112942 | ** to that SrcList. |
| 112540 | 112943 | ** |
| 112541 | 112944 | ** This routine adds a specific database name, if needed, to the target when |
| 112542 | 112945 | ** forming the SrcList. This prevents a trigger in one database from |
| 112543 | 112946 | ** referring to a target in another database. An exception is when the |
| @@ -112546,21 +112949,21 @@ | ||
| 112546 | 112949 | */ |
| 112547 | 112950 | static SrcList *targetSrcList( |
| 112548 | 112951 | Parse *pParse, /* The parsing context */ |
| 112549 | 112952 | TriggerStep *pStep /* The trigger containing the target token */ |
| 112550 | 112953 | ){ |
| 112954 | + sqlite3 *db = pParse->db; | |
| 112551 | 112955 | int iDb; /* Index of the database to use */ |
| 112552 | 112956 | SrcList *pSrc; /* SrcList to be returned */ |
| 112553 | 112957 | |
| 112554 | - pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0); | |
| 112958 | + pSrc = sqlite3SrcListAppend(db, 0, 0, 0); | |
| 112555 | 112959 | if( pSrc ){ |
| 112556 | 112960 | assert( pSrc->nSrc>0 ); |
| 112557 | - assert( pSrc->a!=0 ); | |
| 112558 | - iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema); | |
| 112961 | + pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget); | |
| 112962 | + iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema); | |
| 112559 | 112963 | if( iDb==0 || iDb>=2 ){ |
| 112560 | - sqlite3 *db = pParse->db; | |
| 112561 | - assert( iDb<pParse->db->nDb ); | |
| 112964 | + assert( iDb<db->nDb ); | |
| 112562 | 112965 | pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName); |
| 112563 | 112966 | } |
| 112564 | 112967 | } |
| 112565 | 112968 | return pSrc; |
| 112566 | 112969 | } |
| @@ -112668,10 +113071,11 @@ | ||
| 112668 | 113071 | assert( pFrom->zErrMsg==0 || pFrom->nErr ); |
| 112669 | 113072 | assert( pTo->zErrMsg==0 || pTo->nErr ); |
| 112670 | 113073 | if( pTo->nErr==0 ){ |
| 112671 | 113074 | pTo->zErrMsg = pFrom->zErrMsg; |
| 112672 | 113075 | pTo->nErr = pFrom->nErr; |
| 113076 | + pTo->rc = pFrom->rc; | |
| 112673 | 113077 | }else{ |
| 112674 | 113078 | sqlite3DbFree(pFrom->db, pFrom->zErrMsg); |
| 112675 | 113079 | } |
| 112676 | 113080 | } |
| 112677 | 113081 | |
| @@ -114018,17 +114422,21 @@ | ||
| 114018 | 114422 | |
| 114019 | 114423 | /* Loop through the tables in the main database. For each, do |
| 114020 | 114424 | ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy |
| 114021 | 114425 | ** the contents to the temporary database. |
| 114022 | 114426 | */ |
| 114427 | + assert( (db->flags & SQLITE_Vacuum)==0 ); | |
| 114428 | + db->flags |= SQLITE_Vacuum; | |
| 114023 | 114429 | rc = execExecSql(db, pzErrMsg, |
| 114024 | 114430 | "SELECT 'INSERT INTO vacuum_db.' || quote(name) " |
| 114025 | 114431 | "|| ' SELECT * FROM main.' || quote(name) || ';'" |
| 114026 | 114432 | "FROM main.sqlite_master " |
| 114027 | 114433 | "WHERE type = 'table' AND name!='sqlite_sequence' " |
| 114028 | 114434 | " AND coalesce(rootpage,1)>0" |
| 114029 | 114435 | ); |
| 114436 | + assert( (db->flags & SQLITE_Vacuum)!=0 ); | |
| 114437 | + db->flags &= ~SQLITE_Vacuum; | |
| 114030 | 114438 | if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 114031 | 114439 | |
| 114032 | 114440 | /* Copy over the sequence table |
| 114033 | 114441 | */ |
| 114034 | 114442 | rc = execExecSql(db, pzErrMsg, |
| @@ -114163,10 +114571,12 @@ | ||
| 114163 | 114571 | ** are invoked only from within xCreate and xConnect methods. |
| 114164 | 114572 | */ |
| 114165 | 114573 | struct VtabCtx { |
| 114166 | 114574 | VTable *pVTable; /* The virtual table being constructed */ |
| 114167 | 114575 | Table *pTab; /* The Table object to which the virtual table belongs */ |
| 114576 | + VtabCtx *pPrior; /* Parent context (if any) */ | |
| 114577 | + int bDeclared; /* True after sqlite3_declare_vtab() is called */ | |
| 114168 | 114578 | }; |
| 114169 | 114579 | |
| 114170 | 114580 | /* |
| 114171 | 114581 | ** The actual function that does the work of creating a new module. |
| 114172 | 114582 | ** This function implements the sqlite3_create_module() and |
| @@ -114609,11 +115019,11 @@ | ||
| 114609 | 115019 | Token *pArg = &pParse->sArg; |
| 114610 | 115020 | if( pArg->z==0 ){ |
| 114611 | 115021 | pArg->z = p->z; |
| 114612 | 115022 | pArg->n = p->n; |
| 114613 | 115023 | }else{ |
| 114614 | - assert(pArg->z < p->z); | |
| 115024 | + assert(pArg->z <= p->z); | |
| 114615 | 115025 | pArg->n = (int)(&p->z[p->n] - pArg->z); |
| 114616 | 115026 | } |
| 114617 | 115027 | } |
| 114618 | 115028 | |
| 114619 | 115029 | /* |
| @@ -114626,19 +115036,31 @@ | ||
| 114626 | 115036 | Table *pTab, |
| 114627 | 115037 | Module *pMod, |
| 114628 | 115038 | int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**), |
| 114629 | 115039 | char **pzErr |
| 114630 | 115040 | ){ |
| 114631 | - VtabCtx sCtx, *pPriorCtx; | |
| 115041 | + VtabCtx sCtx; | |
| 114632 | 115042 | VTable *pVTable; |
| 114633 | 115043 | int rc; |
| 114634 | 115044 | const char *const*azArg = (const char *const*)pTab->azModuleArg; |
| 114635 | 115045 | int nArg = pTab->nModuleArg; |
| 114636 | 115046 | char *zErr = 0; |
| 114637 | - char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); | |
| 115047 | + char *zModuleName; | |
| 114638 | 115048 | int iDb; |
| 115049 | + VtabCtx *pCtx; | |
| 114639 | 115050 | |
| 115051 | + /* Check that the virtual-table is not already being initialized */ | |
| 115052 | + for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){ | |
| 115053 | + if( pCtx->pTab==pTab ){ | |
| 115054 | + *pzErr = sqlite3MPrintf(db, | |
| 115055 | + "vtable constructor called recursively: %s", pTab->zName | |
| 115056 | + ); | |
| 115057 | + return SQLITE_LOCKED; | |
| 115058 | + } | |
| 115059 | + } | |
| 115060 | + | |
| 115061 | + zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); | |
| 114640 | 115062 | if( !zModuleName ){ |
| 114641 | 115063 | return SQLITE_NOMEM; |
| 114642 | 115064 | } |
| 114643 | 115065 | |
| 114644 | 115066 | pVTable = sqlite3DbMallocZero(db, sizeof(VTable)); |
| @@ -114655,15 +115077,17 @@ | ||
| 114655 | 115077 | /* Invoke the virtual table constructor */ |
| 114656 | 115078 | assert( &db->pVtabCtx ); |
| 114657 | 115079 | assert( xConstruct ); |
| 114658 | 115080 | sCtx.pTab = pTab; |
| 114659 | 115081 | sCtx.pVTable = pVTable; |
| 114660 | - pPriorCtx = db->pVtabCtx; | |
| 115082 | + sCtx.pPrior = db->pVtabCtx; | |
| 115083 | + sCtx.bDeclared = 0; | |
| 114661 | 115084 | db->pVtabCtx = &sCtx; |
| 114662 | 115085 | rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); |
| 114663 | - db->pVtabCtx = pPriorCtx; | |
| 115086 | + db->pVtabCtx = sCtx.pPrior; | |
| 114664 | 115087 | if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; |
| 115088 | + assert( sCtx.pTab==pTab ); | |
| 114665 | 115089 | |
| 114666 | 115090 | if( SQLITE_OK!=rc ){ |
| 114667 | 115091 | if( zErr==0 ){ |
| 114668 | 115092 | *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); |
| 114669 | 115093 | }else { |
| @@ -114675,17 +115099,18 @@ | ||
| 114675 | 115099 | /* Justification of ALWAYS(): A correct vtab constructor must allocate |
| 114676 | 115100 | ** the sqlite3_vtab object if successful. */ |
| 114677 | 115101 | memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0])); |
| 114678 | 115102 | pVTable->pVtab->pModule = pMod->pModule; |
| 114679 | 115103 | pVTable->nRef = 1; |
| 114680 | - if( sCtx.pTab ){ | |
| 115104 | + if( sCtx.bDeclared==0 ){ | |
| 114681 | 115105 | const char *zFormat = "vtable constructor did not declare schema: %s"; |
| 114682 | 115106 | *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName); |
| 114683 | 115107 | sqlite3VtabUnlock(pVTable); |
| 114684 | 115108 | rc = SQLITE_ERROR; |
| 114685 | 115109 | }else{ |
| 114686 | 115110 | int iCol; |
| 115111 | + u8 oooHidden = 0; | |
| 114687 | 115112 | /* If everything went according to plan, link the new VTable structure |
| 114688 | 115113 | ** into the linked list headed by pTab->pVTable. Then loop through the |
| 114689 | 115114 | ** columns of the table to see if any of them contain the token "hidden". |
| 114690 | 115115 | ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from |
| 114691 | 115116 | ** the type string. */ |
| @@ -114694,11 +115119,14 @@ | ||
| 114694 | 115119 | |
| 114695 | 115120 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 114696 | 115121 | char *zType = pTab->aCol[iCol].zType; |
| 114697 | 115122 | int nType; |
| 114698 | 115123 | int i = 0; |
| 114699 | - if( !zType ) continue; | |
| 115124 | + if( !zType ){ | |
| 115125 | + pTab->tabFlags |= oooHidden; | |
| 115126 | + continue; | |
| 115127 | + } | |
| 114700 | 115128 | nType = sqlite3Strlen30(zType); |
| 114701 | 115129 | if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){ |
| 114702 | 115130 | for(i=0; i<nType; i++){ |
| 114703 | 115131 | if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7)) |
| 114704 | 115132 | && (zType[i+7]=='\0' || zType[i+7]==' ') |
| @@ -114717,10 +115145,13 @@ | ||
| 114717 | 115145 | if( zType[i]=='\0' && i>0 ){ |
| 114718 | 115146 | assert(zType[i-1]==' '); |
| 114719 | 115147 | zType[i-1] = '\0'; |
| 114720 | 115148 | } |
| 114721 | 115149 | pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN; |
| 115150 | + oooHidden = TF_OOOHidden; | |
| 115151 | + }else{ | |
| 115152 | + pTab->tabFlags |= oooHidden; | |
| 114722 | 115153 | } |
| 114723 | 115154 | } |
| 114724 | 115155 | } |
| 114725 | 115156 | } |
| 114726 | 115157 | |
| @@ -114845,12 +115276,12 @@ | ||
| 114845 | 115276 | ** This function is used to set the schema of a virtual table. It is only |
| 114846 | 115277 | ** valid to call this function from within the xCreate() or xConnect() of a |
| 114847 | 115278 | ** virtual table module. |
| 114848 | 115279 | */ |
| 114849 | 115280 | SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ |
| 115281 | + VtabCtx *pCtx; | |
| 114850 | 115282 | Parse *pParse; |
| 114851 | - | |
| 114852 | 115283 | int rc = SQLITE_OK; |
| 114853 | 115284 | Table *pTab; |
| 114854 | 115285 | char *zErr = 0; |
| 114855 | 115286 | |
| 114856 | 115287 | #ifdef SQLITE_ENABLE_API_ARMOR |
| @@ -114857,15 +115288,17 @@ | ||
| 114857 | 115288 | if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){ |
| 114858 | 115289 | return SQLITE_MISUSE_BKPT; |
| 114859 | 115290 | } |
| 114860 | 115291 | #endif |
| 114861 | 115292 | sqlite3_mutex_enter(db->mutex); |
| 114862 | - if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){ | |
| 115293 | + pCtx = db->pVtabCtx; | |
| 115294 | + if( !pCtx || pCtx->bDeclared ){ | |
| 114863 | 115295 | sqlite3Error(db, SQLITE_MISUSE); |
| 114864 | 115296 | sqlite3_mutex_leave(db->mutex); |
| 114865 | 115297 | return SQLITE_MISUSE_BKPT; |
| 114866 | 115298 | } |
| 115299 | + pTab = pCtx->pTab; | |
| 114867 | 115300 | assert( (pTab->tabFlags & TF_Virtual)!=0 ); |
| 114868 | 115301 | |
| 114869 | 115302 | pParse = sqlite3StackAllocZero(db, sizeof(*pParse)); |
| 114870 | 115303 | if( pParse==0 ){ |
| 114871 | 115304 | rc = SQLITE_NOMEM; |
| @@ -114884,11 +115317,11 @@ | ||
| 114884 | 115317 | pTab->aCol = pParse->pNewTable->aCol; |
| 114885 | 115318 | pTab->nCol = pParse->pNewTable->nCol; |
| 114886 | 115319 | pParse->pNewTable->nCol = 0; |
| 114887 | 115320 | pParse->pNewTable->aCol = 0; |
| 114888 | 115321 | } |
| 114889 | - db->pVtabCtx->pTab = 0; | |
| 115322 | + pCtx->bDeclared = 1; | |
| 114890 | 115323 | }else{ |
| 114891 | 115324 | sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr); |
| 114892 | 115325 | sqlite3DbFree(db, zErr); |
| 114893 | 115326 | rc = SQLITE_ERROR; |
| 114894 | 115327 | } |
| @@ -115078,11 +115511,11 @@ | ||
| 115078 | 115511 | */ |
| 115079 | 115512 | SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){ |
| 115080 | 115513 | int rc = SQLITE_OK; |
| 115081 | 115514 | |
| 115082 | 115515 | assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN ); |
| 115083 | - assert( iSavepoint>=0 ); | |
| 115516 | + assert( iSavepoint>=-1 ); | |
| 115084 | 115517 | if( db->aVTrans ){ |
| 115085 | 115518 | int i; |
| 115086 | 115519 | for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){ |
| 115087 | 115520 | VTable *pVTab = db->aVTrans[i]; |
| 115088 | 115521 | const sqlite3_module *pMod = pVTab->pMod->pModule; |
| @@ -115196,11 +115629,11 @@ | ||
| 115196 | 115629 | assert( IsVirtual(pTab) ); |
| 115197 | 115630 | for(i=0; i<pToplevel->nVtabLock; i++){ |
| 115198 | 115631 | if( pTab==pToplevel->apVtabLock[i] ) return; |
| 115199 | 115632 | } |
| 115200 | 115633 | n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]); |
| 115201 | - apVtabLock = sqlite3_realloc(pToplevel->apVtabLock, n); | |
| 115634 | + apVtabLock = sqlite3_realloc64(pToplevel->apVtabLock, n); | |
| 115202 | 115635 | if( apVtabLock ){ |
| 115203 | 115636 | pToplevel->apVtabLock = apVtabLock; |
| 115204 | 115637 | pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab; |
| 115205 | 115638 | }else{ |
| 115206 | 115639 | pToplevel->db->mallocFailed = 1; |
| @@ -115995,17 +116428,18 @@ | ||
| 115995 | 116428 | ** In the previous sentence and in the diagram, "slot[]" refers to |
| 115996 | 116429 | ** the WhereClause.a[] array. The slot[] array grows as needed to contain |
| 115997 | 116430 | ** all terms of the WHERE clause. |
| 115998 | 116431 | */ |
| 115999 | 116432 | static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){ |
| 116433 | + Expr *pE2 = sqlite3ExprSkipCollate(pExpr); | |
| 116000 | 116434 | pWC->op = op; |
| 116001 | - if( pExpr==0 ) return; | |
| 116002 | - if( pExpr->op!=op ){ | |
| 116435 | + if( pE2==0 ) return; | |
| 116436 | + if( pE2->op!=op ){ | |
| 116003 | 116437 | whereClauseInsert(pWC, pExpr, 0); |
| 116004 | 116438 | }else{ |
| 116005 | - whereSplit(pWC, pExpr->pLeft, op); | |
| 116006 | - whereSplit(pWC, pExpr->pRight, op); | |
| 116439 | + whereSplit(pWC, pE2->pLeft, op); | |
| 116440 | + whereSplit(pWC, pE2->pRight, op); | |
| 116007 | 116441 | } |
| 116008 | 116442 | } |
| 116009 | 116443 | |
| 116010 | 116444 | /* |
| 116011 | 116445 | ** Initialize a WhereMaskSet object |
| @@ -117272,11 +117706,11 @@ | ||
| 117272 | 117706 | if( p->op==TK_COLUMN |
| 117273 | 117707 | && p->iColumn==pIdx->aiColumn[iCol] |
| 117274 | 117708 | && p->iTable==iBase |
| 117275 | 117709 | ){ |
| 117276 | 117710 | CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr); |
| 117277 | - if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){ | |
| 117711 | + if( pColl && 0==sqlite3StrICmp(pColl->zName, zColl) ){ | |
| 117278 | 117712 | return i; |
| 117279 | 117713 | } |
| 117280 | 117714 | } |
| 117281 | 117715 | } |
| 117282 | 117716 | |
| @@ -117546,11 +117980,11 @@ | ||
| 117546 | 117980 | if( (idxCols & cMask)==0 ){ |
| 117547 | 117981 | Expr *pX = pTerm->pExpr; |
| 117548 | 117982 | idxCols |= cMask; |
| 117549 | 117983 | pIdx->aiColumn[n] = pTerm->u.leftColumn; |
| 117550 | 117984 | pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); |
| 117551 | - pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : "BINARY"; | |
| 117985 | + pIdx->azColl[n] = pColl ? pColl->zName : "BINARY"; | |
| 117552 | 117986 | n++; |
| 117553 | 117987 | } |
| 117554 | 117988 | } |
| 117555 | 117989 | } |
| 117556 | 117990 | assert( (u32)n==pLoop->u.btree.nEq ); |
| @@ -118842,12 +119276,11 @@ | ||
| 118842 | 119276 | |
| 118843 | 119277 | isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 |
| 118844 | 119278 | || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0)) |
| 118845 | 119279 | || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX)); |
| 118846 | 119280 | |
| 118847 | - sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH); | |
| 118848 | - str.db = db; | |
| 119281 | + sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH); | |
| 118849 | 119282 | sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN"); |
| 118850 | 119283 | if( pItem->pSelect ){ |
| 118851 | 119284 | sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId); |
| 118852 | 119285 | }else{ |
| 118853 | 119286 | sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName); |
| @@ -120042,10 +120475,17 @@ | ||
| 120042 | 120475 | /* |
| 120043 | 120476 | ** Free a WhereInfo structure |
| 120044 | 120477 | */ |
| 120045 | 120478 | static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){ |
| 120046 | 120479 | if( ALWAYS(pWInfo) ){ |
| 120480 | + int i; | |
| 120481 | + for(i=0; i<pWInfo->nLevel; i++){ | |
| 120482 | + WhereLevel *pLevel = &pWInfo->a[i]; | |
| 120483 | + if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){ | |
| 120484 | + sqlite3DbFree(db, pLevel->u.in.aInLoop); | |
| 120485 | + } | |
| 120486 | + } | |
| 120047 | 120487 | whereClauseClear(&pWInfo->sWC); |
| 120048 | 120488 | while( pWInfo->pLoops ){ |
| 120049 | 120489 | WhereLoop *p = pWInfo->pLoops; |
| 120050 | 120490 | pWInfo->pLoops = p->pNextLoop; |
| 120051 | 120491 | whereLoopDelete(db, p); |
| @@ -120521,11 +120961,11 @@ | ||
| 120521 | 120961 | ** changes "x IN (?)" into "x=?". */ |
| 120522 | 120962 | |
| 120523 | 120963 | }else if( eOp & (WO_EQ) ){ |
| 120524 | 120964 | pNew->wsFlags |= WHERE_COLUMN_EQ; |
| 120525 | 120965 | if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){ |
| 120526 | - if( iCol>=0 && !IsUniqueIndex(pProbe) ){ | |
| 120966 | + if( iCol>=0 && pProbe->uniqNotNull==0 ){ | |
| 120527 | 120967 | pNew->wsFlags |= WHERE_UNQ_WANTED; |
| 120528 | 120968 | }else{ |
| 120529 | 120969 | pNew->wsFlags |= WHERE_ONEROW; |
| 120530 | 120970 | } |
| 120531 | 120971 | } |
| @@ -121981,11 +122421,11 @@ | ||
| 121981 | 122421 | pWInfo->nOBSat = pFrom->isOrdered; |
| 121982 | 122422 | if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0; |
| 121983 | 122423 | pWInfo->revMask = pFrom->revLoop; |
| 121984 | 122424 | } |
| 121985 | 122425 | if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP) |
| 121986 | - && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr | |
| 122426 | + && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0 | |
| 121987 | 122427 | ){ |
| 121988 | 122428 | Bitmask revMask = 0; |
| 121989 | 122429 | int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy, |
| 121990 | 122430 | pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask |
| 121991 | 122431 | ); |
| @@ -122386,11 +122826,10 @@ | ||
| 122386 | 122826 | if( pParse->nErr || NEVER(db->mallocFailed) ){ |
| 122387 | 122827 | goto whereBeginError; |
| 122388 | 122828 | } |
| 122389 | 122829 | #ifdef WHERETRACE_ENABLED /* !=0 */ |
| 122390 | 122830 | if( sqlite3WhereTrace ){ |
| 122391 | - int ii; | |
| 122392 | 122831 | sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut); |
| 122393 | 122832 | if( pWInfo->nOBSat>0 ){ |
| 122394 | 122833 | sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask); |
| 122395 | 122834 | } |
| 122396 | 122835 | switch( pWInfo->eDistinct ){ |
| @@ -122639,11 +123078,10 @@ | ||
| 122639 | 123078 | VdbeCoverage(v); |
| 122640 | 123079 | VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen); |
| 122641 | 123080 | VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen); |
| 122642 | 123081 | sqlite3VdbeJumpHere(v, pIn->addrInTop-1); |
| 122643 | 123082 | } |
| 122644 | - sqlite3DbFree(db, pLevel->u.in.aInLoop); | |
| 122645 | 123083 | } |
| 122646 | 123084 | sqlite3VdbeResolveLabel(v, pLevel->addrBrk); |
| 122647 | 123085 | if( pLevel->addrSkip ){ |
| 122648 | 123086 | sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip); |
| 122649 | 123087 | VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName)); |
| @@ -122850,10 +123288,32 @@ | ||
| 122850 | 123288 | /* |
| 122851 | 123289 | ** An instance of this structure holds the ATTACH key and the key type. |
| 122852 | 123290 | */ |
| 122853 | 123291 | struct AttachKey { int type; Token key; }; |
| 122854 | 123292 | |
| 123293 | + | |
| 123294 | + /* | |
| 123295 | + ** For a compound SELECT statement, make sure p->pPrior->pNext==p for | |
| 123296 | + ** all elements in the list. And make sure list length does not exceed | |
| 123297 | + ** SQLITE_LIMIT_COMPOUND_SELECT. | |
| 123298 | + */ | |
| 123299 | + static void parserDoubleLinkSelect(Parse *pParse, Select *p){ | |
| 123300 | + if( p->pPrior ){ | |
| 123301 | + Select *pNext = 0, *pLoop; | |
| 123302 | + int mxSelect, cnt = 0; | |
| 123303 | + for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){ | |
| 123304 | + pLoop->pNext = pNext; | |
| 123305 | + pLoop->selFlags |= SF_Compound; | |
| 123306 | + } | |
| 123307 | + if( (p->selFlags & SF_MultiValue)==0 && | |
| 123308 | + (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 && | |
| 123309 | + cnt>mxSelect | |
| 123310 | + ){ | |
| 123311 | + sqlite3ErrorMsg(pParse, "too many terms in compound SELECT"); | |
| 123312 | + } | |
| 123313 | + } | |
| 123314 | + } | |
| 122855 | 123315 | |
| 122856 | 123316 | /* This is a utility routine used to set the ExprSpan.zStart and |
| 122857 | 123317 | ** ExprSpan.zEnd values of pOut so that the span covers the complete |
| 122858 | 123318 | ** range of text beginning with pStart and going to the end of pEnd. |
| 122859 | 123319 | */ |
| @@ -125167,31 +125627,14 @@ | ||
| 125167 | 125627 | sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3); |
| 125168 | 125628 | } |
| 125169 | 125629 | break; |
| 125170 | 125630 | case 112: /* select ::= with selectnowith */ |
| 125171 | 125631 | { |
| 125172 | - Select *p = yymsp[0].minor.yy3, *pNext, *pLoop; | |
| 125632 | + Select *p = yymsp[0].minor.yy3; | |
| 125173 | 125633 | if( p ){ |
| 125174 | - int cnt = 0, mxSelect; | |
| 125175 | 125634 | p->pWith = yymsp[-1].minor.yy59; |
| 125176 | - if( p->pPrior ){ | |
| 125177 | - u16 allValues = SF_Values; | |
| 125178 | - pNext = 0; | |
| 125179 | - for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){ | |
| 125180 | - pLoop->pNext = pNext; | |
| 125181 | - pLoop->selFlags |= SF_Compound; | |
| 125182 | - allValues &= pLoop->selFlags; | |
| 125183 | - } | |
| 125184 | - if( allValues ){ | |
| 125185 | - p->selFlags |= SF_AllValues; | |
| 125186 | - }else if( | |
| 125187 | - (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 | |
| 125188 | - && cnt>mxSelect | |
| 125189 | - ){ | |
| 125190 | - sqlite3ErrorMsg(pParse, "too many terms in compound SELECT"); | |
| 125191 | - } | |
| 125192 | - } | |
| 125635 | + parserDoubleLinkSelect(pParse, p); | |
| 125193 | 125636 | }else{ |
| 125194 | 125637 | sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59); |
| 125195 | 125638 | } |
| 125196 | 125639 | yygotominor.yy3 = p; |
| 125197 | 125640 | } |
| @@ -125205,16 +125648,18 @@ | ||
| 125205 | 125648 | Select *pRhs = yymsp[0].minor.yy3; |
| 125206 | 125649 | if( pRhs && pRhs->pPrior ){ |
| 125207 | 125650 | SrcList *pFrom; |
| 125208 | 125651 | Token x; |
| 125209 | 125652 | x.n = 0; |
| 125653 | + parserDoubleLinkSelect(pParse, pRhs); | |
| 125210 | 125654 | pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0); |
| 125211 | 125655 | pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0); |
| 125212 | 125656 | } |
| 125213 | 125657 | if( pRhs ){ |
| 125214 | 125658 | pRhs->op = (u8)yymsp[-1].minor.yy328; |
| 125215 | 125659 | pRhs->pPrior = yymsp[-2].minor.yy3; |
| 125660 | + pRhs->selFlags &= ~SF_MultiValue; | |
| 125216 | 125661 | if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1; |
| 125217 | 125662 | }else{ |
| 125218 | 125663 | sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3); |
| 125219 | 125664 | } |
| 125220 | 125665 | yygotominor.yy3 = pRhs; |
| @@ -125257,17 +125702,20 @@ | ||
| 125257 | 125702 | yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0); |
| 125258 | 125703 | } |
| 125259 | 125704 | break; |
| 125260 | 125705 | case 121: /* values ::= values COMMA LP exprlist RP */ |
| 125261 | 125706 | { |
| 125262 | - Select *pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0); | |
| 125707 | + Select *pRight, *pLeft = yymsp[-4].minor.yy3; | |
| 125708 | + pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values|SF_MultiValue,0,0); | |
| 125709 | + if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue; | |
| 125263 | 125710 | if( pRight ){ |
| 125264 | 125711 | pRight->op = TK_ALL; |
| 125265 | - pRight->pPrior = yymsp[-4].minor.yy3; | |
| 125712 | + pLeft = yymsp[-4].minor.yy3; | |
| 125713 | + pRight->pPrior = pLeft; | |
| 125266 | 125714 | yygotominor.yy3 = pRight; |
| 125267 | 125715 | }else{ |
| 125268 | - yygotominor.yy3 = yymsp[-4].minor.yy3; | |
| 125716 | + yygotominor.yy3 = pLeft; | |
| 125269 | 125717 | } |
| 125270 | 125718 | } |
| 125271 | 125719 | break; |
| 125272 | 125720 | case 122: /* distinct ::= DISTINCT */ |
| 125273 | 125721 | {yygotominor.yy381 = SF_Distinct;} |
| @@ -127067,14 +127515,12 @@ | ||
| 127067 | 127515 | goto abort_parse; |
| 127068 | 127516 | } |
| 127069 | 127517 | break; |
| 127070 | 127518 | } |
| 127071 | 127519 | case TK_ILLEGAL: { |
| 127072 | - sqlite3DbFree(db, *pzErrMsg); | |
| 127073 | - *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"", | |
| 127520 | + sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"", | |
| 127074 | 127521 | &pParse->sLastToken); |
| 127075 | - nErr++; | |
| 127076 | 127522 | goto abort_parse; |
| 127077 | 127523 | } |
| 127078 | 127524 | case TK_SEMI: { |
| 127079 | 127525 | pParse->zTail = &zSql[i]; |
| 127080 | 127526 | /* Fall thru into the default case */ |
| @@ -127088,16 +127534,19 @@ | ||
| 127088 | 127534 | break; |
| 127089 | 127535 | } |
| 127090 | 127536 | } |
| 127091 | 127537 | } |
| 127092 | 127538 | abort_parse: |
| 127093 | - if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){ | |
| 127539 | + assert( nErr==0 ); | |
| 127540 | + if( zSql[i]==0 && pParse->rc==SQLITE_OK && db->mallocFailed==0 ){ | |
| 127094 | 127541 | if( lastTokenParsed!=TK_SEMI ){ |
| 127095 | 127542 | sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse); |
| 127096 | 127543 | pParse->zTail = &zSql[i]; |
| 127097 | 127544 | } |
| 127098 | - sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse); | |
| 127545 | + if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){ | |
| 127546 | + sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse); | |
| 127547 | + } | |
| 127099 | 127548 | } |
| 127100 | 127549 | #ifdef YYTRACKMAXSTACKDEPTH |
| 127101 | 127550 | sqlite3_mutex_enter(sqlite3MallocMutex()); |
| 127102 | 127551 | sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK, |
| 127103 | 127552 | sqlite3ParserStackPeak(pEngine) |
| @@ -127154,13 +127603,11 @@ | ||
| 127154 | 127603 | while( pParse->pZombieTab ){ |
| 127155 | 127604 | Table *p = pParse->pZombieTab; |
| 127156 | 127605 | pParse->pZombieTab = p->pNextZombie; |
| 127157 | 127606 | sqlite3DeleteTable(db, p); |
| 127158 | 127607 | } |
| 127159 | - if( nErr>0 && pParse->rc==SQLITE_OK ){ | |
| 127160 | - pParse->rc = SQLITE_ERROR; | |
| 127161 | - } | |
| 127608 | + assert( nErr==0 || pParse->rc!=SQLITE_OK ); | |
| 127162 | 127609 | return nErr; |
| 127163 | 127610 | } |
| 127164 | 127611 | |
| 127165 | 127612 | /************** End of tokenize.c ********************************************/ |
| 127166 | 127613 | /************** Begin file complete.c ****************************************/ |
| @@ -127432,11 +127879,11 @@ | ||
| 127432 | 127879 | ** UTF-8. |
| 127433 | 127880 | */ |
| 127434 | 127881 | SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){ |
| 127435 | 127882 | sqlite3_value *pVal; |
| 127436 | 127883 | char const *zSql8; |
| 127437 | - int rc = SQLITE_NOMEM; | |
| 127884 | + int rc; | |
| 127438 | 127885 | |
| 127439 | 127886 | #ifndef SQLITE_OMIT_AUTOINIT |
| 127440 | 127887 | rc = sqlite3_initialize(); |
| 127441 | 127888 | if( rc ) return rc; |
| 127442 | 127889 | #endif |
| @@ -127598,10 +128045,22 @@ | ||
| 127598 | 128045 | ** zero if and only if SQLite was compiled with mutexing code omitted due to |
| 127599 | 128046 | ** the SQLITE_THREADSAFE compile-time option being set to 0. |
| 127600 | 128047 | */ |
| 127601 | 128048 | SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; } |
| 127602 | 128049 | |
| 128050 | +/* | |
| 128051 | +** When compiling the test fixture or with debugging enabled (on Win32), | |
| 128052 | +** this variable being set to non-zero will cause OSTRACE macros to emit | |
| 128053 | +** extra diagnostic information. | |
| 128054 | +*/ | |
| 128055 | +#ifdef SQLITE_HAVE_OS_TRACE | |
| 128056 | +# ifndef SQLITE_DEBUG_OS_TRACE | |
| 128057 | +# define SQLITE_DEBUG_OS_TRACE 0 | |
| 128058 | +# endif | |
| 128059 | + int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; | |
| 128060 | +#endif | |
| 128061 | + | |
| 127603 | 128062 | #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE) |
| 127604 | 128063 | /* |
| 127605 | 128064 | ** If the following function pointer is not NULL and if |
| 127606 | 128065 | ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing |
| 127607 | 128066 | ** I/O active are written using this function. These messages |
| @@ -128737,11 +129196,11 @@ | ||
| 128737 | 129196 | |
| 128738 | 129197 | /* |
| 128739 | 129198 | ** Return a static string containing the name corresponding to the error code |
| 128740 | 129199 | ** specified in the argument. |
| 128741 | 129200 | */ |
| 128742 | -#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST) | |
| 129201 | +#if defined(SQLITE_NEED_ERR_NAME) | |
| 128743 | 129202 | SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ |
| 128744 | 129203 | const char *zName = 0; |
| 128745 | 129204 | int i, origRc = rc; |
| 128746 | 129205 | for(i=0; i<2 && zName==0; i++, rc &= 0xff){ |
| 128747 | 129206 | switch( rc ){ |
| @@ -129962,18 +130421,18 @@ | ||
| 129962 | 130421 | ){ |
| 129963 | 130422 | char *zOpt; |
| 129964 | 130423 | int eState; /* Parser state when parsing URI */ |
| 129965 | 130424 | int iIn; /* Input character index */ |
| 129966 | 130425 | int iOut = 0; /* Output character index */ |
| 129967 | - int nByte = nUri+2; /* Bytes of space to allocate */ | |
| 130426 | + u64 nByte = nUri+2; /* Bytes of space to allocate */ | |
| 129968 | 130427 | |
| 129969 | 130428 | /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen |
| 129970 | 130429 | ** method that there may be extra parameters following the file-name. */ |
| 129971 | 130430 | flags |= SQLITE_OPEN_URI; |
| 129972 | 130431 | |
| 129973 | 130432 | for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&'); |
| 129974 | - zFile = sqlite3_malloc(nByte); | |
| 130433 | + zFile = sqlite3_malloc64(nByte); | |
| 129975 | 130434 | if( !zFile ) return SQLITE_NOMEM; |
| 129976 | 130435 | |
| 129977 | 130436 | iIn = 5; |
| 129978 | 130437 | #ifdef SQLITE_ALLOW_URI_AUTHORITY |
| 129979 | 130438 | if( strncmp(zUri+5, "///", 3)==0 ){ |
| @@ -130135,11 +130594,11 @@ | ||
| 130135 | 130594 | |
| 130136 | 130595 | zOpt = &zVal[nVal+1]; |
| 130137 | 130596 | } |
| 130138 | 130597 | |
| 130139 | 130598 | }else{ |
| 130140 | - zFile = sqlite3_malloc(nUri+2); | |
| 130599 | + zFile = sqlite3_malloc64(nUri+2); | |
| 130141 | 130600 | if( !zFile ) return SQLITE_NOMEM; |
| 130142 | 130601 | memcpy(zFile, zUri, nUri); |
| 130143 | 130602 | zFile[nUri] = '\0'; |
| 130144 | 130603 | zFile[nUri+1] = '\0'; |
| 130145 | 130604 | flags &= ~SQLITE_OPEN_URI; |
| @@ -132344,10 +132803,15 @@ | ||
| 132344 | 132803 | ** false. |
| 132345 | 132804 | */ |
| 132346 | 132805 | #ifdef SQLITE_COVERAGE_TEST |
| 132347 | 132806 | # define ALWAYS(x) (1) |
| 132348 | 132807 | # define NEVER(X) (0) |
| 132808 | +#elif defined(SQLITE_DEBUG) | |
| 132809 | +# define ALWAYS(x) sqlite3Fts3Always((x)!=0) | |
| 132810 | +# define NEVER(x) sqlite3Fts3Never((x)!=0) | |
| 132811 | +SQLITE_PRIVATE int sqlite3Fts3Always(int b); | |
| 132812 | +SQLITE_PRIVATE int sqlite3Fts3Never(int b); | |
| 132349 | 132813 | #else |
| 132350 | 132814 | # define ALWAYS(x) (x) |
| 132351 | 132815 | # define NEVER(x) (x) |
| 132352 | 132816 | #endif |
| 132353 | 132817 | |
| @@ -132744,10 +133208,11 @@ | ||
| 132744 | 133208 | #define fts3GetVarint32(p, piVal) ( \ |
| 132745 | 133209 | (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \ |
| 132746 | 133210 | ) |
| 132747 | 133211 | |
| 132748 | 133212 | /* fts3.c */ |
| 133213 | +SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...); | |
| 132749 | 133214 | SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64); |
| 132750 | 133215 | SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *); |
| 132751 | 133216 | SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *); |
| 132752 | 133217 | SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64); |
| 132753 | 133218 | SQLITE_PRIVATE void sqlite3Fts3Dequote(char *); |
| @@ -132832,10 +133297,17 @@ | ||
| 132832 | 133297 | |
| 132833 | 133298 | static int fts3EvalNext(Fts3Cursor *pCsr); |
| 132834 | 133299 | static int fts3EvalStart(Fts3Cursor *pCsr); |
| 132835 | 133300 | static int fts3TermSegReaderCursor( |
| 132836 | 133301 | Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **); |
| 133302 | + | |
| 133303 | +#ifndef SQLITE_AMALGAMATION | |
| 133304 | +# if defined(SQLITE_DEBUG) | |
| 133305 | +SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; } | |
| 133306 | +SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; } | |
| 133307 | +# endif | |
| 133308 | +#endif | |
| 132837 | 133309 | |
| 132838 | 133310 | /* |
| 132839 | 133311 | ** Write a 64-bit variable-length integer to memory starting at p[0]. |
| 132840 | 133312 | ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes. |
| 132841 | 133313 | ** The number of bytes written is returned. |
| @@ -132942,11 +133414,11 @@ | ||
| 132942 | 133414 | int iOut = 0; /* Index of next byte to write to output */ |
| 132943 | 133415 | |
| 132944 | 133416 | /* If the first byte was a '[', then the close-quote character is a ']' */ |
| 132945 | 133417 | if( quote=='[' ) quote = ']'; |
| 132946 | 133418 | |
| 132947 | - while( ALWAYS(z[iIn]) ){ | |
| 133419 | + while( z[iIn] ){ | |
| 132948 | 133420 | if( z[iIn]==quote ){ |
| 132949 | 133421 | if( z[iIn+1]!=quote ) break; |
| 132950 | 133422 | z[iOut++] = quote; |
| 132951 | 133423 | iIn += 2; |
| 132952 | 133424 | }else{ |
| @@ -133020,10 +133492,21 @@ | ||
| 133020 | 133492 | p->pTokenizer->pModule->xDestroy(p->pTokenizer); |
| 133021 | 133493 | |
| 133022 | 133494 | sqlite3_free(p); |
| 133023 | 133495 | return SQLITE_OK; |
| 133024 | 133496 | } |
| 133497 | + | |
| 133498 | +/* | |
| 133499 | +** Write an error message into *pzErr | |
| 133500 | +*/ | |
| 133501 | +SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char **pzErr, const char *zFormat, ...){ | |
| 133502 | + va_list ap; | |
| 133503 | + sqlite3_free(*pzErr); | |
| 133504 | + va_start(ap, zFormat); | |
| 133505 | + *pzErr = sqlite3_vmprintf(zFormat, ap); | |
| 133506 | + va_end(ap); | |
| 133507 | +} | |
| 133025 | 133508 | |
| 133026 | 133509 | /* |
| 133027 | 133510 | ** Construct one or more SQL statements from the format string given |
| 133028 | 133511 | ** and then evaluate those statements. The success code is written |
| 133029 | 133512 | ** into *pRc. |
| @@ -133539,11 +134022,12 @@ | ||
| 133539 | 134022 | sqlite3 *db, /* Database handle */ |
| 133540 | 134023 | const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */ |
| 133541 | 134024 | const char *zTbl, /* Name of content table */ |
| 133542 | 134025 | const char ***pazCol, /* OUT: Malloc'd array of column names */ |
| 133543 | 134026 | int *pnCol, /* OUT: Size of array *pazCol */ |
| 133544 | - int *pnStr /* OUT: Bytes of string content */ | |
| 134027 | + int *pnStr, /* OUT: Bytes of string content */ | |
| 134028 | + char **pzErr /* OUT: error message */ | |
| 133545 | 134029 | ){ |
| 133546 | 134030 | int rc = SQLITE_OK; /* Return code */ |
| 133547 | 134031 | char *zSql; /* "SELECT *" statement on zTbl */ |
| 133548 | 134032 | sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */ |
| 133549 | 134033 | |
| @@ -133550,10 +134034,13 @@ | ||
| 133550 | 134034 | zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl); |
| 133551 | 134035 | if( !zSql ){ |
| 133552 | 134036 | rc = SQLITE_NOMEM; |
| 133553 | 134037 | }else{ |
| 133554 | 134038 | rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0); |
| 134039 | + if( rc!=SQLITE_OK ){ | |
| 134040 | + sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db)); | |
| 134041 | + } | |
| 133555 | 134042 | } |
| 133556 | 134043 | sqlite3_free(zSql); |
| 133557 | 134044 | |
| 133558 | 134045 | if( rc==SQLITE_OK ){ |
| 133559 | 134046 | const char **azCol; /* Output array */ |
| @@ -133716,17 +134203,17 @@ | ||
| 133716 | 134203 | if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){ |
| 133717 | 134204 | break; |
| 133718 | 134205 | } |
| 133719 | 134206 | } |
| 133720 | 134207 | if( iOpt==SizeofArray(aFts4Opt) ){ |
| 133721 | - *pzErr = sqlite3_mprintf("unrecognized parameter: %s", z); | |
| 134208 | + sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z); | |
| 133722 | 134209 | rc = SQLITE_ERROR; |
| 133723 | 134210 | }else{ |
| 133724 | 134211 | switch( iOpt ){ |
| 133725 | 134212 | case 0: /* MATCHINFO */ |
| 133726 | 134213 | if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){ |
| 133727 | - *pzErr = sqlite3_mprintf("unrecognized matchinfo: %s", zVal); | |
| 134214 | + sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal); | |
| 133728 | 134215 | rc = SQLITE_ERROR; |
| 133729 | 134216 | } |
| 133730 | 134217 | bNoDocsize = 1; |
| 133731 | 134218 | break; |
| 133732 | 134219 | |
| @@ -133750,11 +134237,11 @@ | ||
| 133750 | 134237 | |
| 133751 | 134238 | case 4: /* ORDER */ |
| 133752 | 134239 | if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3)) |
| 133753 | 134240 | && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4)) |
| 133754 | 134241 | ){ |
| 133755 | - *pzErr = sqlite3_mprintf("unrecognized order: %s", zVal); | |
| 134242 | + sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal); | |
| 133756 | 134243 | rc = SQLITE_ERROR; |
| 133757 | 134244 | } |
| 133758 | 134245 | bDescIdx = (zVal[0]=='d' || zVal[0]=='D'); |
| 133759 | 134246 | break; |
| 133760 | 134247 | |
| @@ -133801,11 +134288,11 @@ | ||
| 133801 | 134288 | zCompress = 0; |
| 133802 | 134289 | zUncompress = 0; |
| 133803 | 134290 | if( nCol==0 ){ |
| 133804 | 134291 | sqlite3_free((void*)aCol); |
| 133805 | 134292 | aCol = 0; |
| 133806 | - rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString); | |
| 134293 | + rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr); | |
| 133807 | 134294 | |
| 133808 | 134295 | /* If a languageid= option was specified, remove the language id |
| 133809 | 134296 | ** column from the aCol[] array. */ |
| 133810 | 134297 | if( rc==SQLITE_OK && zLanguageid ){ |
| 133811 | 134298 | int j; |
| @@ -133836,11 +134323,11 @@ | ||
| 133836 | 134323 | assert( pTokenizer ); |
| 133837 | 134324 | |
| 133838 | 134325 | rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex); |
| 133839 | 134326 | if( rc==SQLITE_ERROR ){ |
| 133840 | 134327 | assert( zPrefix ); |
| 133841 | - *pzErr = sqlite3_mprintf("error parsing prefix parameter: %s", zPrefix); | |
| 134328 | + sqlite3Fts3ErrMsg(pzErr, "error parsing prefix parameter: %s", zPrefix); | |
| 133842 | 134329 | } |
| 133843 | 134330 | if( rc!=SQLITE_OK ) goto fts3_init_out; |
| 133844 | 134331 | |
| 133845 | 134332 | /* Allocate and populate the Fts3Table structure. */ |
| 133846 | 134333 | nByte = sizeof(Fts3Table) + /* Fts3Table */ |
| @@ -133918,19 +134405,19 @@ | ||
| 133918 | 134405 | } |
| 133919 | 134406 | } |
| 133920 | 134407 | } |
| 133921 | 134408 | for(i=0; i<nNotindexed; i++){ |
| 133922 | 134409 | if( azNotindexed[i] ){ |
| 133923 | - *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]); | |
| 134410 | + sqlite3Fts3ErrMsg(pzErr, "no such column: %s", azNotindexed[i]); | |
| 133924 | 134411 | rc = SQLITE_ERROR; |
| 133925 | 134412 | } |
| 133926 | 134413 | } |
| 133927 | 134414 | |
| 133928 | 134415 | if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){ |
| 133929 | 134416 | char const *zMiss = (zCompress==0 ? "compress" : "uncompress"); |
| 133930 | 134417 | rc = SQLITE_ERROR; |
| 133931 | - *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss); | |
| 134418 | + sqlite3Fts3ErrMsg(pzErr, "missing %s parameter in fts4 constructor", zMiss); | |
| 133932 | 134419 | } |
| 133933 | 134420 | p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc); |
| 133934 | 134421 | p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc); |
| 133935 | 134422 | if( rc!=SQLITE_OK ) goto fts3_init_out; |
| 133936 | 134423 | |
| @@ -135319,11 +135806,11 @@ | ||
| 135319 | 135806 | ** Fts3SegReaderPending might segfault, as the data structures used by |
| 135320 | 135807 | ** fts4aux are not completely populated. So it's easiest to filter these |
| 135321 | 135808 | ** calls out here. */ |
| 135322 | 135809 | if( iLevel<0 && p->aIndex ){ |
| 135323 | 135810 | Fts3SegReader *pSeg = 0; |
| 135324 | - rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix, &pSeg); | |
| 135811 | + rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg); | |
| 135325 | 135812 | if( rc==SQLITE_OK && pSeg ){ |
| 135326 | 135813 | rc = fts3SegReaderCursorAppend(pCsr, pSeg); |
| 135327 | 135814 | } |
| 135328 | 135815 | } |
| 135329 | 135816 | |
| @@ -135968,15 +136455,35 @@ | ||
| 135968 | 136455 | */ |
| 135969 | 136456 | static void fts3ReversePoslist(char *pStart, char **ppPoslist){ |
| 135970 | 136457 | char *p = &(*ppPoslist)[-2]; |
| 135971 | 136458 | char c = 0; |
| 135972 | 136459 | |
| 136460 | + /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */ | |
| 135973 | 136461 | while( p>pStart && (c=*p--)==0 ); |
| 136462 | + | |
| 136463 | + /* Search backwards for a varint with value zero (the end of the previous | |
| 136464 | + ** poslist). This is an 0x00 byte preceded by some byte that does not | |
| 136465 | + ** have the 0x80 bit set. */ | |
| 135974 | 136466 | while( p>pStart && (*p & 0x80) | c ){ |
| 135975 | 136467 | c = *p--; |
| 135976 | 136468 | } |
| 135977 | - if( p>pStart ){ p = &p[2]; } | |
| 136469 | + assert( p==pStart || c==0 ); | |
| 136470 | + | |
| 136471 | + /* At this point p points to that preceding byte without the 0x80 bit | |
| 136472 | + ** set. So to find the start of the poslist, skip forward 2 bytes then | |
| 136473 | + ** over a varint. | |
| 136474 | + ** | |
| 136475 | + ** Normally. The other case is that p==pStart and the poslist to return | |
| 136476 | + ** is the first in the doclist. In this case do not skip forward 2 bytes. | |
| 136477 | + ** The second part of the if condition (c==0 && *ppPoslist>&p[2]) | |
| 136478 | + ** is required for cases where the first byte of a doclist and the | |
| 136479 | + ** doclist is empty. For example, if the first docid is 10, a doclist | |
| 136480 | + ** that begins with: | |
| 136481 | + ** | |
| 136482 | + ** 0x0A 0x00 <next docid delta varint> | |
| 136483 | + */ | |
| 136484 | + if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; } | |
| 135978 | 136485 | while( *p++&0x80 ); |
| 135979 | 136486 | *ppPoslist = p; |
| 135980 | 136487 | } |
| 135981 | 136488 | |
| 135982 | 136489 | /* |
| @@ -136043,10 +136550,12 @@ | ||
| 136043 | 136550 | case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]); |
| 136044 | 136551 | case 2: zStart = (const char*)sqlite3_value_text(apVal[1]); |
| 136045 | 136552 | } |
| 136046 | 136553 | if( !zEllipsis || !zEnd || !zStart ){ |
| 136047 | 136554 | sqlite3_result_error_nomem(pContext); |
| 136555 | + }else if( nToken==0 ){ | |
| 136556 | + sqlite3_result_text(pContext, "", -1, SQLITE_STATIC); | |
| 136048 | 136557 | }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){ |
| 136049 | 136558 | sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken); |
| 136050 | 136559 | } |
| 136051 | 136560 | } |
| 136052 | 136561 | |
| @@ -137104,16 +137613,18 @@ | ||
| 137104 | 137613 | Fts3Expr *pExpr, /* Expression to initialize phrases in */ |
| 137105 | 137614 | int *pRc /* IN/OUT: Error code */ |
| 137106 | 137615 | ){ |
| 137107 | 137616 | if( pExpr && SQLITE_OK==*pRc ){ |
| 137108 | 137617 | if( pExpr->eType==FTSQUERY_PHRASE ){ |
| 137109 | - int i; | |
| 137110 | 137618 | int nToken = pExpr->pPhrase->nToken; |
| 137111 | - for(i=0; i<nToken; i++){ | |
| 137112 | - if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break; | |
| 137619 | + if( nToken ){ | |
| 137620 | + int i; | |
| 137621 | + for(i=0; i<nToken; i++){ | |
| 137622 | + if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break; | |
| 137623 | + } | |
| 137624 | + pExpr->bDeferred = (i==nToken); | |
| 137113 | 137625 | } |
| 137114 | - pExpr->bDeferred = (i==nToken); | |
| 137115 | 137626 | *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase); |
| 137116 | 137627 | }else{ |
| 137117 | 137628 | fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc); |
| 137118 | 137629 | fts3EvalStartReaders(pCsr, pExpr->pRight, pRc); |
| 137119 | 137630 | pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred); |
| @@ -138272,11 +138783,12 @@ | ||
| 138272 | 138783 | if( rc!=SQLITE_OK ) return rc; |
| 138273 | 138784 | |
| 138274 | 138785 | pIter = pPhrase->pOrPoslist; |
| 138275 | 138786 | iDocid = pPhrase->iOrDocid; |
| 138276 | 138787 | if( pCsr->bDesc==bDescDoclist ){ |
| 138277 | - bEof = (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll)); | |
| 138788 | + bEof = !pPhrase->doclist.nAll || | |
| 138789 | + (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll)); | |
| 138278 | 138790 | while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ |
| 138279 | 138791 | sqlite3Fts3DoclistNext( |
| 138280 | 138792 | bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, |
| 138281 | 138793 | &pIter, &iDocid, &bEof |
| 138282 | 138794 | ); |
| @@ -138484,11 +138996,11 @@ | ||
| 138484 | 138996 | |
| 138485 | 138997 | *ppVtab = (sqlite3_vtab *)p; |
| 138486 | 138998 | return SQLITE_OK; |
| 138487 | 138999 | |
| 138488 | 139000 | bad_args: |
| 138489 | - *pzErr = sqlite3_mprintf("invalid arguments to fts4aux constructor"); | |
| 139001 | + sqlite3Fts3ErrMsg(pzErr, "invalid arguments to fts4aux constructor"); | |
| 138490 | 139002 | return SQLITE_ERROR; |
| 138491 | 139003 | } |
| 138492 | 139004 | |
| 138493 | 139005 | /* |
| 138494 | 139006 | ** This function does the work for both the xDisconnect and xDestroy methods. |
| @@ -139942,17 +140454,17 @@ | ||
| 139942 | 140454 | |
| 139943 | 140455 | if( rc!=SQLITE_OK ){ |
| 139944 | 140456 | sqlite3Fts3ExprFree(*ppExpr); |
| 139945 | 140457 | *ppExpr = 0; |
| 139946 | 140458 | if( rc==SQLITE_TOOBIG ){ |
| 139947 | - *pzErr = sqlite3_mprintf( | |
| 140459 | + sqlite3Fts3ErrMsg(pzErr, | |
| 139948 | 140460 | "FTS expression tree is too large (maximum depth %d)", |
| 139949 | 140461 | SQLITE_FTS3_MAX_EXPR_DEPTH |
| 139950 | 140462 | ); |
| 139951 | 140463 | rc = SQLITE_ERROR; |
| 139952 | 140464 | }else if( rc==SQLITE_ERROR ){ |
| 139953 | - *pzErr = sqlite3_mprintf("malformed MATCH expression: [%s]", z); | |
| 140465 | + sqlite3Fts3ErrMsg(pzErr, "malformed MATCH expression: [%s]", z); | |
| 139954 | 140466 | } |
| 139955 | 140467 | } |
| 139956 | 140468 | |
| 139957 | 140469 | return rc; |
| 139958 | 140470 | } |
| @@ -141424,11 +141936,11 @@ | ||
| 141424 | 141936 | z[n] = '\0'; |
| 141425 | 141937 | sqlite3Fts3Dequote(z); |
| 141426 | 141938 | |
| 141427 | 141939 | m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1); |
| 141428 | 141940 | if( !m ){ |
| 141429 | - *pzErr = sqlite3_mprintf("unknown tokenizer: %s", z); | |
| 141941 | + sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", z); | |
| 141430 | 141942 | rc = SQLITE_ERROR; |
| 141431 | 141943 | }else{ |
| 141432 | 141944 | char const **aArg = 0; |
| 141433 | 141945 | int iArg = 0; |
| 141434 | 141946 | z = &z[n+1]; |
| @@ -141447,11 +141959,11 @@ | ||
| 141447 | 141959 | z = &z[n+1]; |
| 141448 | 141960 | } |
| 141449 | 141961 | rc = m->xCreate(iArg, aArg, ppTok); |
| 141450 | 141962 | assert( rc!=SQLITE_OK || *ppTok ); |
| 141451 | 141963 | if( rc!=SQLITE_OK ){ |
| 141452 | - *pzErr = sqlite3_mprintf("unknown tokenizer"); | |
| 141964 | + sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer"); | |
| 141453 | 141965 | }else{ |
| 141454 | 141966 | (*ppTok)->pModule = m; |
| 141455 | 141967 | } |
| 141456 | 141968 | sqlite3_free((void *)aArg); |
| 141457 | 141969 | } |
| @@ -141531,13 +142043,13 @@ | ||
| 141531 | 142043 | |
| 141532 | 142044 | pHash = (Fts3Hash *)sqlite3_user_data(context); |
| 141533 | 142045 | p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1); |
| 141534 | 142046 | |
| 141535 | 142047 | if( !p ){ |
| 141536 | - char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName); | |
| 141537 | - sqlite3_result_error(context, zErr, -1); | |
| 141538 | - sqlite3_free(zErr); | |
| 142048 | + char *zErr2 = sqlite3_mprintf("unknown tokenizer: %s", zName); | |
| 142049 | + sqlite3_result_error(context, zErr2, -1); | |
| 142050 | + sqlite3_free(zErr2); | |
| 141539 | 142051 | return; |
| 141540 | 142052 | } |
| 141541 | 142053 | |
| 141542 | 142054 | pRet = Tcl_NewObj(); |
| 141543 | 142055 | Tcl_IncrRefCount(pRet); |
| @@ -142068,11 +142580,11 @@ | ||
| 142068 | 142580 | sqlite3_tokenizer_module *p; |
| 142069 | 142581 | int nName = (int)strlen(zName); |
| 142070 | 142582 | |
| 142071 | 142583 | p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1); |
| 142072 | 142584 | if( !p ){ |
| 142073 | - *pzErr = sqlite3_mprintf("unknown tokenizer: %s", zName); | |
| 142585 | + sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", zName); | |
| 142074 | 142586 | return SQLITE_ERROR; |
| 142075 | 142587 | } |
| 142076 | 142588 | |
| 142077 | 142589 | *pp = p; |
| 142078 | 142590 | return SQLITE_OK; |
| @@ -142765,11 +143277,11 @@ | ||
| 142765 | 143277 | /* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)", |
| 142766 | 143278 | /* 24 */ "", |
| 142767 | 143279 | /* 25 */ "", |
| 142768 | 143280 | |
| 142769 | 143281 | /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?", |
| 142770 | -/* 27 */ "SELECT DISTINCT level / (1024 * ?) FROM %Q.'%q_segdir'", | |
| 143282 | +/* 27 */ "SELECT ? UNION SELECT level / (1024 * ?) FROM %Q.'%q_segdir'", | |
| 142771 | 143283 | |
| 142772 | 143284 | /* This statement is used to determine which level to read the input from |
| 142773 | 143285 | ** when performing an incremental merge. It returns the absolute level number |
| 142774 | 143286 | ** of the oldest level in the db that contains at least ? segments. Or, |
| 142775 | 143287 | ** if no level in the FTS index contains more than ? segments, the statement |
| @@ -145883,11 +146395,12 @@ | ||
| 145883 | 146395 | sqlite3_stmt *pAllLangid = 0; |
| 145884 | 146396 | |
| 145885 | 146397 | rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 145886 | 146398 | if( rc==SQLITE_OK ){ |
| 145887 | 146399 | int rc2; |
| 145888 | - sqlite3_bind_int(pAllLangid, 1, p->nIndex); | |
| 146400 | + sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid); | |
| 146401 | + sqlite3_bind_int(pAllLangid, 2, p->nIndex); | |
| 145889 | 146402 | while( sqlite3_step(pAllLangid)==SQLITE_ROW ){ |
| 145890 | 146403 | int i; |
| 145891 | 146404 | int iLangid = sqlite3_column_int(pAllLangid, 0); |
| 145892 | 146405 | for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){ |
| 145893 | 146406 | rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL); |
| @@ -147215,11 +147728,11 @@ | ||
| 147215 | 147728 | while( i>0 && (pHint->a[i-1] & 0x80) ) i--; |
| 147216 | 147729 | |
| 147217 | 147730 | pHint->n = i; |
| 147218 | 147731 | i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel); |
| 147219 | 147732 | i += fts3GetVarint32(&pHint->a[i], pnInput); |
| 147220 | - if( i!=nHint ) return SQLITE_CORRUPT_VTAB; | |
| 147733 | + if( i!=nHint ) return FTS_CORRUPT_VTAB; | |
| 147221 | 147734 | |
| 147222 | 147735 | return SQLITE_OK; |
| 147223 | 147736 | } |
| 147224 | 147737 | |
| 147225 | 147738 | |
| @@ -147583,11 +148096,12 @@ | ||
| 147583 | 148096 | |
| 147584 | 148097 | /* This block calculates the checksum according to the FTS index. */ |
| 147585 | 148098 | rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 147586 | 148099 | if( rc==SQLITE_OK ){ |
| 147587 | 148100 | int rc2; |
| 147588 | - sqlite3_bind_int(pAllLangid, 1, p->nIndex); | |
| 148101 | + sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid); | |
| 148102 | + sqlite3_bind_int(pAllLangid, 2, p->nIndex); | |
| 147589 | 148103 | while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){ |
| 147590 | 148104 | int iLangid = sqlite3_column_int(pAllLangid, 0); |
| 147591 | 148105 | int i; |
| 147592 | 148106 | for(i=0; i<p->nIndex; i++){ |
| 147593 | 148107 | cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc); |
| @@ -147596,11 +148110,10 @@ | ||
| 147596 | 148110 | rc2 = sqlite3_reset(pAllLangid); |
| 147597 | 148111 | if( rc==SQLITE_OK ) rc = rc2; |
| 147598 | 148112 | } |
| 147599 | 148113 | |
| 147600 | 148114 | /* This block calculates the checksum according to the %_content table */ |
| 147601 | - rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); | |
| 147602 | 148115 | if( rc==SQLITE_OK ){ |
| 147603 | 148116 | sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule; |
| 147604 | 148117 | sqlite3_stmt *pStmt = 0; |
| 147605 | 148118 | char *zSql; |
| 147606 | 148119 | |
| @@ -147693,11 +148206,11 @@ | ||
| 147693 | 148206 | Fts3Table *p /* FTS3 table handle */ |
| 147694 | 148207 | ){ |
| 147695 | 148208 | int rc; |
| 147696 | 148209 | int bOk = 0; |
| 147697 | 148210 | rc = fts3IntegrityCheck(p, &bOk); |
| 147698 | - if( rc==SQLITE_OK && bOk==0 ) rc = SQLITE_CORRUPT_VTAB; | |
| 148211 | + if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB; | |
| 147699 | 148212 | return rc; |
| 147700 | 148213 | } |
| 147701 | 148214 | |
| 147702 | 148215 | /* |
| 147703 | 148216 | ** Handle a 'special' INSERT of the form: |
| @@ -148131,10 +148644,11 @@ | ||
| 148131 | 148644 | #define FTS3_MATCHINFO_NDOC 'n' /* 1 value */ |
| 148132 | 148645 | #define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */ |
| 148133 | 148646 | #define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */ |
| 148134 | 148647 | #define FTS3_MATCHINFO_LCS 's' /* nCol values */ |
| 148135 | 148648 | #define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */ |
| 148649 | +#define FTS3_MATCHINFO_LHITS 'y' /* nCol*nPhrase values */ | |
| 148136 | 148650 | |
| 148137 | 148651 | /* |
| 148138 | 148652 | ** The default value for the second argument to matchinfo(). |
| 148139 | 148653 | */ |
| 148140 | 148654 | #define FTS3_MATCHINFO_DEFAULT "pcx" |
| @@ -148912,10 +149426,55 @@ | ||
| 148912 | 149426 | } |
| 148913 | 149427 | } |
| 148914 | 149428 | |
| 148915 | 149429 | return rc; |
| 148916 | 149430 | } |
| 149431 | + | |
| 149432 | +/* | |
| 149433 | +** fts3ExprIterate() callback used to gather information for the matchinfo | |
| 149434 | +** directive 'y'. | |
| 149435 | +*/ | |
| 149436 | +static int fts3ExprLHitsCb( | |
| 149437 | + Fts3Expr *pExpr, /* Phrase expression node */ | |
| 149438 | + int iPhrase, /* Phrase number */ | |
| 149439 | + void *pCtx /* Pointer to MatchInfo structure */ | |
| 149440 | +){ | |
| 149441 | + MatchInfo *p = (MatchInfo *)pCtx; | |
| 149442 | + Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab; | |
| 149443 | + int rc = SQLITE_OK; | |
| 149444 | + int iStart = iPhrase * p->nCol; | |
| 149445 | + Fts3Expr *pEof; /* Ancestor node already at EOF */ | |
| 149446 | + | |
| 149447 | + /* This must be a phrase */ | |
| 149448 | + assert( pExpr->pPhrase ); | |
| 149449 | + | |
| 149450 | + /* Initialize all output integers to zero. */ | |
| 149451 | + memset(&p->aMatchinfo[iStart], 0, sizeof(u32) * p->nCol); | |
| 149452 | + | |
| 149453 | + /* Check if this or any parent node is at EOF. If so, then all output | |
| 149454 | + ** values are zero. */ | |
| 149455 | + for(pEof=pExpr; pEof && pEof->bEof==0; pEof=pEof->pParent); | |
| 149456 | + | |
| 149457 | + if( pEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){ | |
| 149458 | + Fts3Phrase *pPhrase = pExpr->pPhrase; | |
| 149459 | + char *pIter = pPhrase->doclist.pList; | |
| 149460 | + int iCol = 0; | |
| 149461 | + | |
| 149462 | + while( 1 ){ | |
| 149463 | + int nHit = fts3ColumnlistCount(&pIter); | |
| 149464 | + if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){ | |
| 149465 | + p->aMatchinfo[iStart + iCol] = (u32)nHit; | |
| 149466 | + } | |
| 149467 | + assert( *pIter==0x00 || *pIter==0x01 ); | |
| 149468 | + if( *pIter!=0x01 ) break; | |
| 149469 | + pIter++; | |
| 149470 | + pIter += fts3GetVarint32(pIter, &iCol); | |
| 149471 | + } | |
| 149472 | + } | |
| 149473 | + | |
| 149474 | + return rc; | |
| 149475 | +} | |
| 148917 | 149476 | |
| 148918 | 149477 | static int fts3MatchinfoCheck( |
| 148919 | 149478 | Fts3Table *pTab, |
| 148920 | 149479 | char cArg, |
| 148921 | 149480 | char **pzErr |
| @@ -148925,14 +149484,15 @@ | ||
| 148925 | 149484 | || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4) |
| 148926 | 149485 | || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4) |
| 148927 | 149486 | || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize) |
| 148928 | 149487 | || (cArg==FTS3_MATCHINFO_LCS) |
| 148929 | 149488 | || (cArg==FTS3_MATCHINFO_HITS) |
| 149489 | + || (cArg==FTS3_MATCHINFO_LHITS) | |
| 148930 | 149490 | ){ |
| 148931 | 149491 | return SQLITE_OK; |
| 148932 | 149492 | } |
| 148933 | - *pzErr = sqlite3_mprintf("unrecognized matchinfo request: %c", cArg); | |
| 149493 | + sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg); | |
| 148934 | 149494 | return SQLITE_ERROR; |
| 148935 | 149495 | } |
| 148936 | 149496 | |
| 148937 | 149497 | static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){ |
| 148938 | 149498 | int nVal; /* Number of integers output by cArg */ |
| @@ -148947,10 +149507,14 @@ | ||
| 148947 | 149507 | case FTS3_MATCHINFO_AVGLENGTH: |
| 148948 | 149508 | case FTS3_MATCHINFO_LENGTH: |
| 148949 | 149509 | case FTS3_MATCHINFO_LCS: |
| 148950 | 149510 | nVal = pInfo->nCol; |
| 148951 | 149511 | break; |
| 149512 | + | |
| 149513 | + case FTS3_MATCHINFO_LHITS: | |
| 149514 | + nVal = pInfo->nCol * pInfo->nPhrase; | |
| 149515 | + break; | |
| 148952 | 149516 | |
| 148953 | 149517 | default: |
| 148954 | 149518 | assert( cArg==FTS3_MATCHINFO_HITS ); |
| 148955 | 149519 | nVal = pInfo->nCol * pInfo->nPhrase * 3; |
| 148956 | 149520 | break; |
| @@ -149201,10 +149765,14 @@ | ||
| 149201 | 149765 | rc = fts3ExprLoadDoclists(pCsr, 0, 0); |
| 149202 | 149766 | if( rc==SQLITE_OK ){ |
| 149203 | 149767 | rc = fts3MatchinfoLcs(pCsr, pInfo); |
| 149204 | 149768 | } |
| 149205 | 149769 | break; |
| 149770 | + | |
| 149771 | + case FTS3_MATCHINFO_LHITS: | |
| 149772 | + (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLHitsCb, (void*)pInfo); | |
| 149773 | + break; | |
| 149206 | 149774 | |
| 149207 | 149775 | default: { |
| 149208 | 149776 | Fts3Expr *pExpr; |
| 149209 | 149777 | assert( zArg[i]==FTS3_MATCHINFO_HITS ); |
| 149210 | 149778 | pExpr = pCsr->pExpr; |
| @@ -153214,15 +153782,23 @@ | ||
| 153214 | 153782 | ** conflict-handling mode specified by the user. |
| 153215 | 153783 | */ |
| 153216 | 153784 | if( nData>1 ){ |
| 153217 | 153785 | int ii; |
| 153218 | 153786 | |
| 153219 | - /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */ | |
| 153220 | - assert( nData==(pRtree->nDim*2 + 3) ); | |
| 153787 | + /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. | |
| 153788 | + ** | |
| 153789 | + ** NB: nData can only be less than nDim*2+3 if the rtree is mis-declared | |
| 153790 | + ** with "column" that are interpreted as table constraints. | |
| 153791 | + ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5)); | |
| 153792 | + ** This problem was discovered after years of use, so we silently ignore | |
| 153793 | + ** these kinds of misdeclared tables to avoid breaking any legacy. | |
| 153794 | + */ | |
| 153795 | + assert( nData<=(pRtree->nDim*2 + 3) ); | |
| 153796 | + | |
| 153221 | 153797 | #ifndef SQLITE_RTREE_INT_ONLY |
| 153222 | 153798 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 153223 | - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ | |
| 153799 | + for(ii=0; ii<nData-4; ii+=2){ | |
| 153224 | 153800 | cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]); |
| 153225 | 153801 | cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]); |
| 153226 | 153802 | if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){ |
| 153227 | 153803 | rc = SQLITE_CONSTRAINT; |
| 153228 | 153804 | goto constraint; |
| @@ -153229,11 +153805,11 @@ | ||
| 153229 | 153805 | } |
| 153230 | 153806 | } |
| 153231 | 153807 | }else |
| 153232 | 153808 | #endif |
| 153233 | 153809 | { |
| 153234 | - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ | |
| 153810 | + for(ii=0; ii<nData-4; ii+=2){ | |
| 153235 | 153811 | cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]); |
| 153236 | 153812 | cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]); |
| 153237 | 153813 | if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){ |
| 153238 | 153814 | rc = SQLITE_CONSTRAINT; |
| 153239 | 153815 | goto constraint; |
| @@ -154629,5 +155205,633 @@ | ||
| 154629 | 155205 | |
| 154630 | 155206 | #endif /* defined(SQLITE_ENABLE_ICU) */ |
| 154631 | 155207 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ |
| 154632 | 155208 | |
| 154633 | 155209 | /************** End of fts3_icu.c ********************************************/ |
| 155210 | +/************** Begin file dbstat.c ******************************************/ | |
| 155211 | +/* | |
| 155212 | +** 2010 July 12 | |
| 155213 | +** | |
| 155214 | +** The author disclaims copyright to this source code. In place of | |
| 155215 | +** a legal notice, here is a blessing: | |
| 155216 | +** | |
| 155217 | +** May you do good and not evil. | |
| 155218 | +** May you find forgiveness for yourself and forgive others. | |
| 155219 | +** May you share freely, never taking more than you give. | |
| 155220 | +** | |
| 155221 | +****************************************************************************** | |
| 155222 | +** | |
| 155223 | +** This file contains an implementation of the "dbstat" virtual table. | |
| 155224 | +** | |
| 155225 | +** The dbstat virtual table is used to extract low-level formatting | |
| 155226 | +** information from an SQLite database in order to implement the | |
| 155227 | +** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script | |
| 155228 | +** for an example implementation. | |
| 155229 | +*/ | |
| 155230 | + | |
| 155231 | +#if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \ | |
| 155232 | + && !defined(SQLITE_OMIT_VIRTUAL_TABLE) | |
| 155233 | + | |
| 155234 | +/* | |
| 155235 | +** Page paths: | |
| 155236 | +** | |
| 155237 | +** The value of the 'path' column describes the path taken from the | |
| 155238 | +** root-node of the b-tree structure to each page. The value of the | |
| 155239 | +** root-node path is '/'. | |
| 155240 | +** | |
| 155241 | +** The value of the path for the left-most child page of the root of | |
| 155242 | +** a b-tree is '/000/'. (Btrees store content ordered from left to right | |
| 155243 | +** so the pages to the left have smaller keys than the pages to the right.) | |
| 155244 | +** The next to left-most child of the root page is | |
| 155245 | +** '/001', and so on, each sibling page identified by a 3-digit hex | |
| 155246 | +** value. The children of the 451st left-most sibling have paths such | |
| 155247 | +** as '/1c2/000/, '/1c2/001/' etc. | |
| 155248 | +** | |
| 155249 | +** Overflow pages are specified by appending a '+' character and a | |
| 155250 | +** six-digit hexadecimal value to the path to the cell they are linked | |
| 155251 | +** from. For example, the three overflow pages in a chain linked from | |
| 155252 | +** the left-most cell of the 450th child of the root page are identified | |
| 155253 | +** by the paths: | |
| 155254 | +** | |
| 155255 | +** '/1c2/000+000000' // First page in overflow chain | |
| 155256 | +** '/1c2/000+000001' // Second page in overflow chain | |
| 155257 | +** '/1c2/000+000002' // Third page in overflow chain | |
| 155258 | +** | |
| 155259 | +** If the paths are sorted using the BINARY collation sequence, then | |
| 155260 | +** the overflow pages associated with a cell will appear earlier in the | |
| 155261 | +** sort-order than its child page: | |
| 155262 | +** | |
| 155263 | +** '/1c2/000/' // Left-most child of 451st child of root | |
| 155264 | +*/ | |
| 155265 | +#define VTAB_SCHEMA \ | |
| 155266 | + "CREATE TABLE xx( " \ | |
| 155267 | + " name STRING, /* Name of table or index */" \ | |
| 155268 | + " path INTEGER, /* Path to page from root */" \ | |
| 155269 | + " pageno INTEGER, /* Page number */" \ | |
| 155270 | + " pagetype STRING, /* 'internal', 'leaf' or 'overflow' */" \ | |
| 155271 | + " ncell INTEGER, /* Cells on page (0 for overflow) */" \ | |
| 155272 | + " payload INTEGER, /* Bytes of payload on this page */" \ | |
| 155273 | + " unused INTEGER, /* Bytes of unused space on this page */" \ | |
| 155274 | + " mx_payload INTEGER, /* Largest payload size of all cells */" \ | |
| 155275 | + " pgoffset INTEGER, /* Offset of page in file */" \ | |
| 155276 | + " pgsize INTEGER /* Size of the page */" \ | |
| 155277 | + ");" | |
| 155278 | + | |
| 155279 | + | |
| 155280 | +typedef struct StatTable StatTable; | |
| 155281 | +typedef struct StatCursor StatCursor; | |
| 155282 | +typedef struct StatPage StatPage; | |
| 155283 | +typedef struct StatCell StatCell; | |
| 155284 | + | |
| 155285 | +struct StatCell { | |
| 155286 | + int nLocal; /* Bytes of local payload */ | |
| 155287 | + u32 iChildPg; /* Child node (or 0 if this is a leaf) */ | |
| 155288 | + int nOvfl; /* Entries in aOvfl[] */ | |
| 155289 | + u32 *aOvfl; /* Array of overflow page numbers */ | |
| 155290 | + int nLastOvfl; /* Bytes of payload on final overflow page */ | |
| 155291 | + int iOvfl; /* Iterates through aOvfl[] */ | |
| 155292 | +}; | |
| 155293 | + | |
| 155294 | +struct StatPage { | |
| 155295 | + u32 iPgno; | |
| 155296 | + DbPage *pPg; | |
| 155297 | + int iCell; | |
| 155298 | + | |
| 155299 | + char *zPath; /* Path to this page */ | |
| 155300 | + | |
| 155301 | + /* Variables populated by statDecodePage(): */ | |
| 155302 | + u8 flags; /* Copy of flags byte */ | |
| 155303 | + int nCell; /* Number of cells on page */ | |
| 155304 | + int nUnused; /* Number of unused bytes on page */ | |
| 155305 | + StatCell *aCell; /* Array of parsed cells */ | |
| 155306 | + u32 iRightChildPg; /* Right-child page number (or 0) */ | |
| 155307 | + int nMxPayload; /* Largest payload of any cell on this page */ | |
| 155308 | +}; | |
| 155309 | + | |
| 155310 | +struct StatCursor { | |
| 155311 | + sqlite3_vtab_cursor base; | |
| 155312 | + sqlite3_stmt *pStmt; /* Iterates through set of root pages */ | |
| 155313 | + int isEof; /* After pStmt has returned SQLITE_DONE */ | |
| 155314 | + | |
| 155315 | + StatPage aPage[32]; | |
| 155316 | + int iPage; /* Current entry in aPage[] */ | |
| 155317 | + | |
| 155318 | + /* Values to return. */ | |
| 155319 | + char *zName; /* Value of 'name' column */ | |
| 155320 | + char *zPath; /* Value of 'path' column */ | |
| 155321 | + u32 iPageno; /* Value of 'pageno' column */ | |
| 155322 | + char *zPagetype; /* Value of 'pagetype' column */ | |
| 155323 | + int nCell; /* Value of 'ncell' column */ | |
| 155324 | + int nPayload; /* Value of 'payload' column */ | |
| 155325 | + int nUnused; /* Value of 'unused' column */ | |
| 155326 | + int nMxPayload; /* Value of 'mx_payload' column */ | |
| 155327 | + i64 iOffset; /* Value of 'pgOffset' column */ | |
| 155328 | + int szPage; /* Value of 'pgSize' column */ | |
| 155329 | +}; | |
| 155330 | + | |
| 155331 | +struct StatTable { | |
| 155332 | + sqlite3_vtab base; | |
| 155333 | + sqlite3 *db; | |
| 155334 | +}; | |
| 155335 | + | |
| 155336 | +#ifndef get2byte | |
| 155337 | +# define get2byte(x) ((x)[0]<<8 | (x)[1]) | |
| 155338 | +#endif | |
| 155339 | + | |
| 155340 | +/* | |
| 155341 | +** Connect to or create a statvfs virtual table. | |
| 155342 | +*/ | |
| 155343 | +static int statConnect( | |
| 155344 | + sqlite3 *db, | |
| 155345 | + void *pAux, | |
| 155346 | + int argc, const char *const*argv, | |
| 155347 | + sqlite3_vtab **ppVtab, | |
| 155348 | + char **pzErr | |
| 155349 | +){ | |
| 155350 | + StatTable *pTab = 0; | |
| 155351 | + int rc = SQLITE_OK; | |
| 155352 | + | |
| 155353 | + rc = sqlite3_declare_vtab(db, VTAB_SCHEMA); | |
| 155354 | + if( rc==SQLITE_OK ){ | |
| 155355 | + pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable)); | |
| 155356 | + if( pTab==0 ) rc = SQLITE_NOMEM; | |
| 155357 | + } | |
| 155358 | + | |
| 155359 | + assert( rc==SQLITE_OK || pTab==0 ); | |
| 155360 | + if( rc==SQLITE_OK ){ | |
| 155361 | + memset(pTab, 0, sizeof(StatTable)); | |
| 155362 | + pTab->db = db; | |
| 155363 | + } | |
| 155364 | + | |
| 155365 | + *ppVtab = (sqlite3_vtab*)pTab; | |
| 155366 | + return rc; | |
| 155367 | +} | |
| 155368 | + | |
| 155369 | +/* | |
| 155370 | +** Disconnect from or destroy a statvfs virtual table. | |
| 155371 | +*/ | |
| 155372 | +static int statDisconnect(sqlite3_vtab *pVtab){ | |
| 155373 | + sqlite3_free(pVtab); | |
| 155374 | + return SQLITE_OK; | |
| 155375 | +} | |
| 155376 | + | |
| 155377 | +/* | |
| 155378 | +** There is no "best-index". This virtual table always does a linear | |
| 155379 | +** scan of the binary VFS log file. | |
| 155380 | +*/ | |
| 155381 | +static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ | |
| 155382 | + | |
| 155383 | + /* Records are always returned in ascending order of (name, path). | |
| 155384 | + ** If this will satisfy the client, set the orderByConsumed flag so that | |
| 155385 | + ** SQLite does not do an external sort. | |
| 155386 | + */ | |
| 155387 | + if( ( pIdxInfo->nOrderBy==1 | |
| 155388 | + && pIdxInfo->aOrderBy[0].iColumn==0 | |
| 155389 | + && pIdxInfo->aOrderBy[0].desc==0 | |
| 155390 | + ) || | |
| 155391 | + ( pIdxInfo->nOrderBy==2 | |
| 155392 | + && pIdxInfo->aOrderBy[0].iColumn==0 | |
| 155393 | + && pIdxInfo->aOrderBy[0].desc==0 | |
| 155394 | + && pIdxInfo->aOrderBy[1].iColumn==1 | |
| 155395 | + && pIdxInfo->aOrderBy[1].desc==0 | |
| 155396 | + ) | |
| 155397 | + ){ | |
| 155398 | + pIdxInfo->orderByConsumed = 1; | |
| 155399 | + } | |
| 155400 | + | |
| 155401 | + pIdxInfo->estimatedCost = 10.0; | |
| 155402 | + return SQLITE_OK; | |
| 155403 | +} | |
| 155404 | + | |
| 155405 | +/* | |
| 155406 | +** Open a new statvfs cursor. | |
| 155407 | +*/ | |
| 155408 | +static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ | |
| 155409 | + StatTable *pTab = (StatTable *)pVTab; | |
| 155410 | + StatCursor *pCsr; | |
| 155411 | + int rc; | |
| 155412 | + | |
| 155413 | + pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor)); | |
| 155414 | + if( pCsr==0 ){ | |
| 155415 | + rc = SQLITE_NOMEM; | |
| 155416 | + }else{ | |
| 155417 | + memset(pCsr, 0, sizeof(StatCursor)); | |
| 155418 | + pCsr->base.pVtab = pVTab; | |
| 155419 | + | |
| 155420 | + rc = sqlite3_prepare_v2(pTab->db, | |
| 155421 | + "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type" | |
| 155422 | + " UNION ALL " | |
| 155423 | + "SELECT name, rootpage, type FROM sqlite_master WHERE rootpage!=0" | |
| 155424 | + " ORDER BY name", -1, | |
| 155425 | + &pCsr->pStmt, 0 | |
| 155426 | + ); | |
| 155427 | + if( rc!=SQLITE_OK ){ | |
| 155428 | + sqlite3_free(pCsr); | |
| 155429 | + pCsr = 0; | |
| 155430 | + } | |
| 155431 | + } | |
| 155432 | + | |
| 155433 | + *ppCursor = (sqlite3_vtab_cursor *)pCsr; | |
| 155434 | + return rc; | |
| 155435 | +} | |
| 155436 | + | |
| 155437 | +static void statClearPage(StatPage *p){ | |
| 155438 | + int i; | |
| 155439 | + if( p->aCell ){ | |
| 155440 | + for(i=0; i<p->nCell; i++){ | |
| 155441 | + sqlite3_free(p->aCell[i].aOvfl); | |
| 155442 | + } | |
| 155443 | + sqlite3_free(p->aCell); | |
| 155444 | + } | |
| 155445 | + sqlite3PagerUnref(p->pPg); | |
| 155446 | + sqlite3_free(p->zPath); | |
| 155447 | + memset(p, 0, sizeof(StatPage)); | |
| 155448 | +} | |
| 155449 | + | |
| 155450 | +static void statResetCsr(StatCursor *pCsr){ | |
| 155451 | + int i; | |
| 155452 | + sqlite3_reset(pCsr->pStmt); | |
| 155453 | + for(i=0; i<ArraySize(pCsr->aPage); i++){ | |
| 155454 | + statClearPage(&pCsr->aPage[i]); | |
| 155455 | + } | |
| 155456 | + pCsr->iPage = 0; | |
| 155457 | + sqlite3_free(pCsr->zPath); | |
| 155458 | + pCsr->zPath = 0; | |
| 155459 | +} | |
| 155460 | + | |
| 155461 | +/* | |
| 155462 | +** Close a statvfs cursor. | |
| 155463 | +*/ | |
| 155464 | +static int statClose(sqlite3_vtab_cursor *pCursor){ | |
| 155465 | + StatCursor *pCsr = (StatCursor *)pCursor; | |
| 155466 | + statResetCsr(pCsr); | |
| 155467 | + sqlite3_finalize(pCsr->pStmt); | |
| 155468 | + sqlite3_free(pCsr); | |
| 155469 | + return SQLITE_OK; | |
| 155470 | +} | |
| 155471 | + | |
| 155472 | +static void getLocalPayload( | |
| 155473 | + int nUsable, /* Usable bytes per page */ | |
| 155474 | + u8 flags, /* Page flags */ | |
| 155475 | + int nTotal, /* Total record (payload) size */ | |
| 155476 | + int *pnLocal /* OUT: Bytes stored locally */ | |
| 155477 | +){ | |
| 155478 | + int nLocal; | |
| 155479 | + int nMinLocal; | |
| 155480 | + int nMaxLocal; | |
| 155481 | + | |
| 155482 | + if( flags==0x0D ){ /* Table leaf node */ | |
| 155483 | + nMinLocal = (nUsable - 12) * 32 / 255 - 23; | |
| 155484 | + nMaxLocal = nUsable - 35; | |
| 155485 | + }else{ /* Index interior and leaf nodes */ | |
| 155486 | + nMinLocal = (nUsable - 12) * 32 / 255 - 23; | |
| 155487 | + nMaxLocal = (nUsable - 12) * 64 / 255 - 23; | |
| 155488 | + } | |
| 155489 | + | |
| 155490 | + nLocal = nMinLocal + (nTotal - nMinLocal) % (nUsable - 4); | |
| 155491 | + if( nLocal>nMaxLocal ) nLocal = nMinLocal; | |
| 155492 | + *pnLocal = nLocal; | |
| 155493 | +} | |
| 155494 | + | |
| 155495 | +static int statDecodePage(Btree *pBt, StatPage *p){ | |
| 155496 | + int nUnused; | |
| 155497 | + int iOff; | |
| 155498 | + int nHdr; | |
| 155499 | + int isLeaf; | |
| 155500 | + int szPage; | |
| 155501 | + | |
| 155502 | + u8 *aData = sqlite3PagerGetData(p->pPg); | |
| 155503 | + u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0]; | |
| 155504 | + | |
| 155505 | + p->flags = aHdr[0]; | |
| 155506 | + p->nCell = get2byte(&aHdr[3]); | |
| 155507 | + p->nMxPayload = 0; | |
| 155508 | + | |
| 155509 | + isLeaf = (p->flags==0x0A || p->flags==0x0D); | |
| 155510 | + nHdr = 12 - isLeaf*4 + (p->iPgno==1)*100; | |
| 155511 | + | |
| 155512 | + nUnused = get2byte(&aHdr[5]) - nHdr - 2*p->nCell; | |
| 155513 | + nUnused += (int)aHdr[7]; | |
| 155514 | + iOff = get2byte(&aHdr[1]); | |
| 155515 | + while( iOff ){ | |
| 155516 | + nUnused += get2byte(&aData[iOff+2]); | |
| 155517 | + iOff = get2byte(&aData[iOff]); | |
| 155518 | + } | |
| 155519 | + p->nUnused = nUnused; | |
| 155520 | + p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]); | |
| 155521 | + szPage = sqlite3BtreeGetPageSize(pBt); | |
| 155522 | + | |
| 155523 | + if( p->nCell ){ | |
| 155524 | + int i; /* Used to iterate through cells */ | |
| 155525 | + int nUsable; /* Usable bytes per page */ | |
| 155526 | + | |
| 155527 | + sqlite3BtreeEnter(pBt); | |
| 155528 | + nUsable = szPage - sqlite3BtreeGetReserveNoMutex(pBt); | |
| 155529 | + sqlite3BtreeLeave(pBt); | |
| 155530 | + p->aCell = sqlite3_malloc64((p->nCell+1) * sizeof(StatCell)); | |
| 155531 | + if( p->aCell==0 ) return SQLITE_NOMEM; | |
| 155532 | + memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell)); | |
| 155533 | + | |
| 155534 | + for(i=0; i<p->nCell; i++){ | |
| 155535 | + StatCell *pCell = &p->aCell[i]; | |
| 155536 | + | |
| 155537 | + iOff = get2byte(&aData[nHdr+i*2]); | |
| 155538 | + if( !isLeaf ){ | |
| 155539 | + pCell->iChildPg = sqlite3Get4byte(&aData[iOff]); | |
| 155540 | + iOff += 4; | |
| 155541 | + } | |
| 155542 | + if( p->flags==0x05 ){ | |
| 155543 | + /* A table interior node. nPayload==0. */ | |
| 155544 | + }else{ | |
| 155545 | + u32 nPayload; /* Bytes of payload total (local+overflow) */ | |
| 155546 | + int nLocal; /* Bytes of payload stored locally */ | |
| 155547 | + iOff += getVarint32(&aData[iOff], nPayload); | |
| 155548 | + if( p->flags==0x0D ){ | |
| 155549 | + u64 dummy; | |
| 155550 | + iOff += sqlite3GetVarint(&aData[iOff], &dummy); | |
| 155551 | + } | |
| 155552 | + if( nPayload>(u32)p->nMxPayload ) p->nMxPayload = nPayload; | |
| 155553 | + getLocalPayload(nUsable, p->flags, nPayload, &nLocal); | |
| 155554 | + pCell->nLocal = nLocal; | |
| 155555 | + assert( nLocal>=0 ); | |
| 155556 | + assert( nPayload>=(u32)nLocal ); | |
| 155557 | + assert( nLocal<=(nUsable-35) ); | |
| 155558 | + if( nPayload>(u32)nLocal ){ | |
| 155559 | + int j; | |
| 155560 | + int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4); | |
| 155561 | + pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4); | |
| 155562 | + pCell->nOvfl = nOvfl; | |
| 155563 | + pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl); | |
| 155564 | + if( pCell->aOvfl==0 ) return SQLITE_NOMEM; | |
| 155565 | + pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]); | |
| 155566 | + for(j=1; j<nOvfl; j++){ | |
| 155567 | + int rc; | |
| 155568 | + u32 iPrev = pCell->aOvfl[j-1]; | |
| 155569 | + DbPage *pPg = 0; | |
| 155570 | + rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg); | |
| 155571 | + if( rc!=SQLITE_OK ){ | |
| 155572 | + assert( pPg==0 ); | |
| 155573 | + return rc; | |
| 155574 | + } | |
| 155575 | + pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg)); | |
| 155576 | + sqlite3PagerUnref(pPg); | |
| 155577 | + } | |
| 155578 | + } | |
| 155579 | + } | |
| 155580 | + } | |
| 155581 | + } | |
| 155582 | + | |
| 155583 | + return SQLITE_OK; | |
| 155584 | +} | |
| 155585 | + | |
| 155586 | +/* | |
| 155587 | +** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on | |
| 155588 | +** the current value of pCsr->iPageno. | |
| 155589 | +*/ | |
| 155590 | +static void statSizeAndOffset(StatCursor *pCsr){ | |
| 155591 | + StatTable *pTab = (StatTable *)((sqlite3_vtab_cursor *)pCsr)->pVtab; | |
| 155592 | + Btree *pBt = pTab->db->aDb[0].pBt; | |
| 155593 | + Pager *pPager = sqlite3BtreePager(pBt); | |
| 155594 | + sqlite3_file *fd; | |
| 155595 | + sqlite3_int64 x[2]; | |
| 155596 | + | |
| 155597 | + /* The default page size and offset */ | |
| 155598 | + pCsr->szPage = sqlite3BtreeGetPageSize(pBt); | |
| 155599 | + pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1); | |
| 155600 | + | |
| 155601 | + /* If connected to a ZIPVFS backend, override the page size and | |
| 155602 | + ** offset with actual values obtained from ZIPVFS. | |
| 155603 | + */ | |
| 155604 | + fd = sqlite3PagerFile(pPager); | |
| 155605 | + x[0] = pCsr->iPageno; | |
| 155606 | + if( sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){ | |
| 155607 | + pCsr->iOffset = x[0]; | |
| 155608 | + pCsr->szPage = (int)x[1]; | |
| 155609 | + } | |
| 155610 | +} | |
| 155611 | + | |
| 155612 | +/* | |
| 155613 | +** Move a statvfs cursor to the next entry in the file. | |
| 155614 | +*/ | |
| 155615 | +static int statNext(sqlite3_vtab_cursor *pCursor){ | |
| 155616 | + int rc; | |
| 155617 | + int nPayload; | |
| 155618 | + StatCursor *pCsr = (StatCursor *)pCursor; | |
| 155619 | + StatTable *pTab = (StatTable *)pCursor->pVtab; | |
| 155620 | + Btree *pBt = pTab->db->aDb[0].pBt; | |
| 155621 | + Pager *pPager = sqlite3BtreePager(pBt); | |
| 155622 | + | |
| 155623 | + sqlite3_free(pCsr->zPath); | |
| 155624 | + pCsr->zPath = 0; | |
| 155625 | + | |
| 155626 | +statNextRestart: | |
| 155627 | + if( pCsr->aPage[0].pPg==0 ){ | |
| 155628 | + rc = sqlite3_step(pCsr->pStmt); | |
| 155629 | + if( rc==SQLITE_ROW ){ | |
| 155630 | + int nPage; | |
| 155631 | + u32 iRoot = (u32)sqlite3_column_int64(pCsr->pStmt, 1); | |
| 155632 | + sqlite3PagerPagecount(pPager, &nPage); | |
| 155633 | + if( nPage==0 ){ | |
| 155634 | + pCsr->isEof = 1; | |
| 155635 | + return sqlite3_reset(pCsr->pStmt); | |
| 155636 | + } | |
| 155637 | + rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg); | |
| 155638 | + pCsr->aPage[0].iPgno = iRoot; | |
| 155639 | + pCsr->aPage[0].iCell = 0; | |
| 155640 | + pCsr->aPage[0].zPath = sqlite3_mprintf("/"); | |
| 155641 | + pCsr->iPage = 0; | |
| 155642 | + }else{ | |
| 155643 | + pCsr->isEof = 1; | |
| 155644 | + return sqlite3_reset(pCsr->pStmt); | |
| 155645 | + } | |
| 155646 | + }else{ | |
| 155647 | + | |
| 155648 | + /* Page p itself has already been visited. */ | |
| 155649 | + StatPage *p = &pCsr->aPage[pCsr->iPage]; | |
| 155650 | + | |
| 155651 | + while( p->iCell<p->nCell ){ | |
| 155652 | + StatCell *pCell = &p->aCell[p->iCell]; | |
| 155653 | + if( pCell->iOvfl<pCell->nOvfl ){ | |
| 155654 | + int nUsable; | |
| 155655 | + sqlite3BtreeEnter(pBt); | |
| 155656 | + nUsable = sqlite3BtreeGetPageSize(pBt) - | |
| 155657 | + sqlite3BtreeGetReserveNoMutex(pBt); | |
| 155658 | + sqlite3BtreeLeave(pBt); | |
| 155659 | + pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0); | |
| 155660 | + pCsr->iPageno = pCell->aOvfl[pCell->iOvfl]; | |
| 155661 | + pCsr->zPagetype = "overflow"; | |
| 155662 | + pCsr->nCell = 0; | |
| 155663 | + pCsr->nMxPayload = 0; | |
| 155664 | + pCsr->zPath = sqlite3_mprintf( | |
| 155665 | + "%s%.3x+%.6x", p->zPath, p->iCell, pCell->iOvfl | |
| 155666 | + ); | |
| 155667 | + if( pCell->iOvfl<pCell->nOvfl-1 ){ | |
| 155668 | + pCsr->nUnused = 0; | |
| 155669 | + pCsr->nPayload = nUsable - 4; | |
| 155670 | + }else{ | |
| 155671 | + pCsr->nPayload = pCell->nLastOvfl; | |
| 155672 | + pCsr->nUnused = nUsable - 4 - pCsr->nPayload; | |
| 155673 | + } | |
| 155674 | + pCell->iOvfl++; | |
| 155675 | + statSizeAndOffset(pCsr); | |
| 155676 | + return SQLITE_OK; | |
| 155677 | + } | |
| 155678 | + if( p->iRightChildPg ) break; | |
| 155679 | + p->iCell++; | |
| 155680 | + } | |
| 155681 | + | |
| 155682 | + if( !p->iRightChildPg || p->iCell>p->nCell ){ | |
| 155683 | + statClearPage(p); | |
| 155684 | + if( pCsr->iPage==0 ) return statNext(pCursor); | |
| 155685 | + pCsr->iPage--; | |
| 155686 | + goto statNextRestart; /* Tail recursion */ | |
| 155687 | + } | |
| 155688 | + pCsr->iPage++; | |
| 155689 | + assert( p==&pCsr->aPage[pCsr->iPage-1] ); | |
| 155690 | + | |
| 155691 | + if( p->iCell==p->nCell ){ | |
| 155692 | + p[1].iPgno = p->iRightChildPg; | |
| 155693 | + }else{ | |
| 155694 | + p[1].iPgno = p->aCell[p->iCell].iChildPg; | |
| 155695 | + } | |
| 155696 | + rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg); | |
| 155697 | + p[1].iCell = 0; | |
| 155698 | + p[1].zPath = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell); | |
| 155699 | + p->iCell++; | |
| 155700 | + } | |
| 155701 | + | |
| 155702 | + | |
| 155703 | + /* Populate the StatCursor fields with the values to be returned | |
| 155704 | + ** by the xColumn() and xRowid() methods. | |
| 155705 | + */ | |
| 155706 | + if( rc==SQLITE_OK ){ | |
| 155707 | + int i; | |
| 155708 | + StatPage *p = &pCsr->aPage[pCsr->iPage]; | |
| 155709 | + pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0); | |
| 155710 | + pCsr->iPageno = p->iPgno; | |
| 155711 | + | |
| 155712 | + rc = statDecodePage(pBt, p); | |
| 155713 | + if( rc==SQLITE_OK ){ | |
| 155714 | + statSizeAndOffset(pCsr); | |
| 155715 | + | |
| 155716 | + switch( p->flags ){ | |
| 155717 | + case 0x05: /* table internal */ | |
| 155718 | + case 0x02: /* index internal */ | |
| 155719 | + pCsr->zPagetype = "internal"; | |
| 155720 | + break; | |
| 155721 | + case 0x0D: /* table leaf */ | |
| 155722 | + case 0x0A: /* index leaf */ | |
| 155723 | + pCsr->zPagetype = "leaf"; | |
| 155724 | + break; | |
| 155725 | + default: | |
| 155726 | + pCsr->zPagetype = "corrupted"; | |
| 155727 | + break; | |
| 155728 | + } | |
| 155729 | + pCsr->nCell = p->nCell; | |
| 155730 | + pCsr->nUnused = p->nUnused; | |
| 155731 | + pCsr->nMxPayload = p->nMxPayload; | |
| 155732 | + pCsr->zPath = sqlite3_mprintf("%s", p->zPath); | |
| 155733 | + nPayload = 0; | |
| 155734 | + for(i=0; i<p->nCell; i++){ | |
| 155735 | + nPayload += p->aCell[i].nLocal; | |
| 155736 | + } | |
| 155737 | + pCsr->nPayload = nPayload; | |
| 155738 | + } | |
| 155739 | + } | |
| 155740 | + | |
| 155741 | + return rc; | |
| 155742 | +} | |
| 155743 | + | |
| 155744 | +static int statEof(sqlite3_vtab_cursor *pCursor){ | |
| 155745 | + StatCursor *pCsr = (StatCursor *)pCursor; | |
| 155746 | + return pCsr->isEof; | |
| 155747 | +} | |
| 155748 | + | |
| 155749 | +static int statFilter( | |
| 155750 | + sqlite3_vtab_cursor *pCursor, | |
| 155751 | + int idxNum, const char *idxStr, | |
| 155752 | + int argc, sqlite3_value **argv | |
| 155753 | +){ | |
| 155754 | + StatCursor *pCsr = (StatCursor *)pCursor; | |
| 155755 | + | |
| 155756 | + statResetCsr(pCsr); | |
| 155757 | + return statNext(pCursor); | |
| 155758 | +} | |
| 155759 | + | |
| 155760 | +static int statColumn( | |
| 155761 | + sqlite3_vtab_cursor *pCursor, | |
| 155762 | + sqlite3_context *ctx, | |
| 155763 | + int i | |
| 155764 | +){ | |
| 155765 | + StatCursor *pCsr = (StatCursor *)pCursor; | |
| 155766 | + switch( i ){ | |
| 155767 | + case 0: /* name */ | |
| 155768 | + sqlite3_result_text(ctx, pCsr->zName, -1, SQLITE_STATIC); | |
| 155769 | + break; | |
| 155770 | + case 1: /* path */ | |
| 155771 | + sqlite3_result_text(ctx, pCsr->zPath, -1, SQLITE_TRANSIENT); | |
| 155772 | + break; | |
| 155773 | + case 2: /* pageno */ | |
| 155774 | + sqlite3_result_int64(ctx, pCsr->iPageno); | |
| 155775 | + break; | |
| 155776 | + case 3: /* pagetype */ | |
| 155777 | + sqlite3_result_text(ctx, pCsr->zPagetype, -1, SQLITE_STATIC); | |
| 155778 | + break; | |
| 155779 | + case 4: /* ncell */ | |
| 155780 | + sqlite3_result_int(ctx, pCsr->nCell); | |
| 155781 | + break; | |
| 155782 | + case 5: /* payload */ | |
| 155783 | + sqlite3_result_int(ctx, pCsr->nPayload); | |
| 155784 | + break; | |
| 155785 | + case 6: /* unused */ | |
| 155786 | + sqlite3_result_int(ctx, pCsr->nUnused); | |
| 155787 | + break; | |
| 155788 | + case 7: /* mx_payload */ | |
| 155789 | + sqlite3_result_int(ctx, pCsr->nMxPayload); | |
| 155790 | + break; | |
| 155791 | + case 8: /* pgoffset */ | |
| 155792 | + sqlite3_result_int64(ctx, pCsr->iOffset); | |
| 155793 | + break; | |
| 155794 | + case 9: /* pgsize */ | |
| 155795 | + sqlite3_result_int(ctx, pCsr->szPage); | |
| 155796 | + break; | |
| 155797 | + } | |
| 155798 | + return SQLITE_OK; | |
| 155799 | +} | |
| 155800 | + | |
| 155801 | +static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){ | |
| 155802 | + StatCursor *pCsr = (StatCursor *)pCursor; | |
| 155803 | + *pRowid = pCsr->iPageno; | |
| 155804 | + return SQLITE_OK; | |
| 155805 | +} | |
| 155806 | + | |
| 155807 | +/* | |
| 155808 | +** Invoke this routine to register the "dbstat" virtual table module | |
| 155809 | +*/ | |
| 155810 | +SQLITE_API int SQLITE_STDCALL sqlite3_dbstat_register(sqlite3 *db){ | |
| 155811 | + static sqlite3_module dbstat_module = { | |
| 155812 | + 0, /* iVersion */ | |
| 155813 | + statConnect, /* xCreate */ | |
| 155814 | + statConnect, /* xConnect */ | |
| 155815 | + statBestIndex, /* xBestIndex */ | |
| 155816 | + statDisconnect, /* xDisconnect */ | |
| 155817 | + statDisconnect, /* xDestroy */ | |
| 155818 | + statOpen, /* xOpen - open a cursor */ | |
| 155819 | + statClose, /* xClose - close a cursor */ | |
| 155820 | + statFilter, /* xFilter - configure scan constraints */ | |
| 155821 | + statNext, /* xNext - advance a cursor */ | |
| 155822 | + statEof, /* xEof - check for end of scan */ | |
| 155823 | + statColumn, /* xColumn - read data */ | |
| 155824 | + statRowid, /* xRowid - read data */ | |
| 155825 | + 0, /* xUpdate */ | |
| 155826 | + 0, /* xBegin */ | |
| 155827 | + 0, /* xSync */ | |
| 155828 | + 0, /* xCommit */ | |
| 155829 | + 0, /* xRollback */ | |
| 155830 | + 0, /* xFindMethod */ | |
| 155831 | + 0, /* xRename */ | |
| 155832 | + }; | |
| 155833 | + return sqlite3_create_module(db, "dbstat", &dbstat_module, 0); | |
| 155834 | +} | |
| 155835 | +#endif /* SQLITE_ENABLE_DBSTAT_VTAB */ | |
| 155836 | + | |
| 155837 | +/************** End of dbstat.c **********************************************/ | |
| 154634 | 155838 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.8.9. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -68,10 +68,11 @@ | |
| 68 | #if defined(_MSC_VER) |
| 69 | #pragma warning(disable : 4054) |
| 70 | #pragma warning(disable : 4055) |
| 71 | #pragma warning(disable : 4100) |
| 72 | #pragma warning(disable : 4127) |
| 73 | #pragma warning(disable : 4152) |
| 74 | #pragma warning(disable : 4189) |
| 75 | #pragma warning(disable : 4206) |
| 76 | #pragma warning(disable : 4210) |
| 77 | #pragma warning(disable : 4232) |
| @@ -315,13 +316,13 @@ | |
| 315 | ** |
| 316 | ** See also: [sqlite3_libversion()], |
| 317 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 318 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 319 | */ |
| 320 | #define SQLITE_VERSION "3.8.9" |
| 321 | #define SQLITE_VERSION_NUMBER 3008009 |
| 322 | #define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09" |
| 323 | |
| 324 | /* |
| 325 | ** CAPI3REF: Run-Time Library Version Numbers |
| 326 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 327 | ** |
| @@ -474,10 +475,11 @@ | |
| 474 | # define double sqlite3_int64 |
| 475 | #endif |
| 476 | |
| 477 | /* |
| 478 | ** CAPI3REF: Closing A Database Connection |
| 479 | ** |
| 480 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 481 | ** for the [sqlite3] object. |
| 482 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
| 483 | ** the [sqlite3] object is successfully destroyed and all associated |
| @@ -525,10 +527,11 @@ | |
| 525 | */ |
| 526 | typedef int (*sqlite3_callback)(void*,int,char**, char**); |
| 527 | |
| 528 | /* |
| 529 | ** CAPI3REF: One-Step Query Execution Interface |
| 530 | ** |
| 531 | ** The sqlite3_exec() interface is a convenience wrapper around |
| 532 | ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], |
| 533 | ** that allows an application to run multiple statements of SQL |
| 534 | ** without having to use a lot of C code. |
| @@ -1582,10 +1585,11 @@ | |
| 1582 | */ |
| 1583 | SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...); |
| 1584 | |
| 1585 | /* |
| 1586 | ** CAPI3REF: Configure database connections |
| 1587 | ** |
| 1588 | ** The sqlite3_db_config() interface is used to make configuration |
| 1589 | ** changes to a [database connection]. The interface is similar to |
| 1590 | ** [sqlite3_config()] except that the changes apply to a single |
| 1591 | ** [database connection] (specified in the first argument). |
| @@ -2079,19 +2083,21 @@ | |
| 2079 | #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ |
| 2080 | |
| 2081 | |
| 2082 | /* |
| 2083 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
| 2084 | ** |
| 2085 | ** ^The sqlite3_extended_result_codes() routine enables or disables the |
| 2086 | ** [extended result codes] feature of SQLite. ^The extended result |
| 2087 | ** codes are disabled by default for historical compatibility. |
| 2088 | */ |
| 2089 | SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff); |
| 2090 | |
| 2091 | /* |
| 2092 | ** CAPI3REF: Last Insert Rowid |
| 2093 | ** |
| 2094 | ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) |
| 2095 | ** has a unique 64-bit signed |
| 2096 | ** integer key called the [ROWID | "rowid"]. ^The rowid is always available |
| 2097 | ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those |
| @@ -2139,10 +2145,11 @@ | |
| 2139 | */ |
| 2140 | SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*); |
| 2141 | |
| 2142 | /* |
| 2143 | ** CAPI3REF: Count The Number Of Rows Modified |
| 2144 | ** |
| 2145 | ** ^This function returns the number of rows modified, inserted or |
| 2146 | ** deleted by the most recently completed INSERT, UPDATE or DELETE |
| 2147 | ** statement on the database connection specified by the only parameter. |
| 2148 | ** ^Executing any other type of SQL statement does not modify the value |
| @@ -2191,10 +2198,11 @@ | |
| 2191 | */ |
| 2192 | SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*); |
| 2193 | |
| 2194 | /* |
| 2195 | ** CAPI3REF: Total Number Of Rows Modified |
| 2196 | ** |
| 2197 | ** ^This function returns the total number of rows inserted, modified or |
| 2198 | ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
| 2199 | ** since the database connection was opened, including those executed as |
| 2200 | ** part of trigger programs. ^Executing any other type of SQL statement |
| @@ -2214,10 +2222,11 @@ | |
| 2214 | */ |
| 2215 | SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*); |
| 2216 | |
| 2217 | /* |
| 2218 | ** CAPI3REF: Interrupt A Long-Running Query |
| 2219 | ** |
| 2220 | ** ^This function causes any pending database operation to abort and |
| 2221 | ** return at its earliest opportunity. This routine is typically |
| 2222 | ** called in response to a user action such as pressing "Cancel" |
| 2223 | ** or Ctrl-C where the user wants a long query operation to halt |
| @@ -2290,10 +2299,11 @@ | |
| 2290 | SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql); |
| 2291 | |
| 2292 | /* |
| 2293 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2294 | ** KEYWORDS: {busy-handler callback} {busy handler} |
| 2295 | ** |
| 2296 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2297 | ** that might be invoked with argument P whenever |
| 2298 | ** an attempt is made to access a database table associated with |
| 2299 | ** [database connection] D when another thread |
| @@ -2349,10 +2359,11 @@ | |
| 2349 | */ |
| 2350 | SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); |
| 2351 | |
| 2352 | /* |
| 2353 | ** CAPI3REF: Set A Busy Timeout |
| 2354 | ** |
| 2355 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2356 | ** for a specified amount of time when a table is locked. ^The handler |
| 2357 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2358 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| @@ -2371,10 +2382,11 @@ | |
| 2371 | */ |
| 2372 | SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms); |
| 2373 | |
| 2374 | /* |
| 2375 | ** CAPI3REF: Convenience Routines For Running Queries |
| 2376 | ** |
| 2377 | ** This is a legacy interface that is preserved for backwards compatibility. |
| 2378 | ** Use of this interface is not recommended. |
| 2379 | ** |
| 2380 | ** Definition: A <b>result table</b> is memory data structure created by the |
| @@ -2706,10 +2718,11 @@ | |
| 2706 | */ |
| 2707 | SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P); |
| 2708 | |
| 2709 | /* |
| 2710 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2711 | ** |
| 2712 | ** ^This routine registers an authorizer callback with a particular |
| 2713 | ** [database connection], supplied in the first argument. |
| 2714 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2715 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| @@ -2862,10 +2875,11 @@ | |
| 2862 | #define SQLITE_COPY 0 /* No longer used */ |
| 2863 | #define SQLITE_RECURSIVE 33 /* NULL NULL */ |
| 2864 | |
| 2865 | /* |
| 2866 | ** CAPI3REF: Tracing And Profiling Functions |
| 2867 | ** |
| 2868 | ** These routines register callback functions that can be used for |
| 2869 | ** tracing and profiling the execution of SQL statements. |
| 2870 | ** |
| 2871 | ** ^The callback function registered by sqlite3_trace() is invoked at |
| @@ -2894,10 +2908,11 @@ | |
| 2894 | SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*, |
| 2895 | void(*xProfile)(void*,const char*,sqlite3_uint64), void*); |
| 2896 | |
| 2897 | /* |
| 2898 | ** CAPI3REF: Query Progress Callbacks |
| 2899 | ** |
| 2900 | ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback |
| 2901 | ** function X to be invoked periodically during long running calls to |
| 2902 | ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for |
| 2903 | ** database connection D. An example use for this |
| @@ -2927,10 +2942,11 @@ | |
| 2927 | */ |
| 2928 | SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2929 | |
| 2930 | /* |
| 2931 | ** CAPI3REF: Opening A New Database Connection |
| 2932 | ** |
| 2933 | ** ^These routines open an SQLite database file as specified by the |
| 2934 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2935 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2936 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| @@ -3212,10 +3228,11 @@ | |
| 3212 | SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64); |
| 3213 | |
| 3214 | |
| 3215 | /* |
| 3216 | ** CAPI3REF: Error Codes And Messages |
| 3217 | ** |
| 3218 | ** ^If the most recent sqlite3_* API call associated with |
| 3219 | ** [database connection] D failed, then the sqlite3_errcode(D) interface |
| 3220 | ** returns the numeric [result code] or [extended result code] for that |
| 3221 | ** API call. |
| @@ -3257,37 +3274,38 @@ | |
| 3257 | SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*); |
| 3258 | SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*); |
| 3259 | SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int); |
| 3260 | |
| 3261 | /* |
| 3262 | ** CAPI3REF: SQL Statement Object |
| 3263 | ** KEYWORDS: {prepared statement} {prepared statements} |
| 3264 | ** |
| 3265 | ** An instance of this object represents a single SQL statement. |
| 3266 | ** This object is variously known as a "prepared statement" or a |
| 3267 | ** "compiled SQL statement" or simply as a "statement". |
| 3268 | ** |
| 3269 | ** The life of a statement object goes something like this: |
| 3270 | ** |
| 3271 | ** <ol> |
| 3272 | ** <li> Create the object using [sqlite3_prepare_v2()] or a related |
| 3273 | ** function. |
| 3274 | ** <li> Bind values to [host parameters] using the sqlite3_bind_*() |
| 3275 | ** interfaces. |
| 3276 | ** <li> Run the SQL by calling [sqlite3_step()] one or more times. |
| 3277 | ** <li> Reset the statement using [sqlite3_reset()] then go back |
| 3278 | ** to step 2. Do this zero or more times. |
| 3279 | ** <li> Destroy the object using [sqlite3_finalize()]. |
| 3280 | ** </ol> |
| 3281 | ** |
| 3282 | ** Refer to documentation on individual methods above for additional |
| 3283 | ** information. |
| 3284 | */ |
| 3285 | typedef struct sqlite3_stmt sqlite3_stmt; |
| 3286 | |
| 3287 | /* |
| 3288 | ** CAPI3REF: Run-time Limits |
| 3289 | ** |
| 3290 | ** ^(This interface allows the size of various constructs to be limited |
| 3291 | ** on a connection by connection basis. The first parameter is the |
| 3292 | ** [database connection] whose limit is to be set or queried. The |
| 3293 | ** second parameter is one of the [limit categories] that define a |
| @@ -3395,10 +3413,12 @@ | |
| 3395 | #define SQLITE_LIMIT_WORKER_THREADS 11 |
| 3396 | |
| 3397 | /* |
| 3398 | ** CAPI3REF: Compiling An SQL Statement |
| 3399 | ** KEYWORDS: {SQL statement compiler} |
| 3400 | ** |
| 3401 | ** To execute an SQL query, it must first be compiled into a byte-code |
| 3402 | ** program using one of these routines. |
| 3403 | ** |
| 3404 | ** The first argument, "db", is a [database connection] obtained from a |
| @@ -3502,19 +3522,21 @@ | |
| 3502 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3503 | ); |
| 3504 | |
| 3505 | /* |
| 3506 | ** CAPI3REF: Retrieving Statement SQL |
| 3507 | ** |
| 3508 | ** ^This interface can be used to retrieve a saved copy of the original |
| 3509 | ** SQL text used to create a [prepared statement] if that statement was |
| 3510 | ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. |
| 3511 | */ |
| 3512 | SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt); |
| 3513 | |
| 3514 | /* |
| 3515 | ** CAPI3REF: Determine If An SQL Statement Writes The Database |
| 3516 | ** |
| 3517 | ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if |
| 3518 | ** and only if the [prepared statement] X makes no direct changes to |
| 3519 | ** the content of the database file. |
| 3520 | ** |
| @@ -3542,10 +3564,11 @@ | |
| 3542 | */ |
| 3543 | SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
| 3544 | |
| 3545 | /* |
| 3546 | ** CAPI3REF: Determine If A Prepared Statement Has Been Reset |
| 3547 | ** |
| 3548 | ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the |
| 3549 | ** [prepared statement] S has been stepped at least once using |
| 3550 | ** [sqlite3_step(S)] but has not run to completion and/or has not |
| 3551 | ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) |
| @@ -3616,10 +3639,11 @@ | |
| 3616 | |
| 3617 | /* |
| 3618 | ** CAPI3REF: Binding Values To Prepared Statements |
| 3619 | ** KEYWORDS: {host parameter} {host parameters} {host parameter name} |
| 3620 | ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} |
| 3621 | ** |
| 3622 | ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, |
| 3623 | ** literals may be replaced by a [parameter] that matches one of following |
| 3624 | ** templates: |
| 3625 | ** |
| @@ -3734,10 +3758,11 @@ | |
| 3734 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); |
| 3735 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
| 3736 | |
| 3737 | /* |
| 3738 | ** CAPI3REF: Number Of SQL Parameters |
| 3739 | ** |
| 3740 | ** ^This routine can be used to find the number of [SQL parameters] |
| 3741 | ** in a [prepared statement]. SQL parameters are tokens of the |
| 3742 | ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as |
| 3743 | ** placeholders for values that are [sqlite3_bind_blob | bound] |
| @@ -3754,10 +3779,11 @@ | |
| 3754 | */ |
| 3755 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*); |
| 3756 | |
| 3757 | /* |
| 3758 | ** CAPI3REF: Name Of A Host Parameter |
| 3759 | ** |
| 3760 | ** ^The sqlite3_bind_parameter_name(P,N) interface returns |
| 3761 | ** the name of the N-th [SQL parameter] in the [prepared statement] P. |
| 3762 | ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| 3763 | ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| @@ -3781,10 +3807,11 @@ | |
| 3781 | */ |
| 3782 | SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int); |
| 3783 | |
| 3784 | /* |
| 3785 | ** CAPI3REF: Index Of A Parameter With A Given Name |
| 3786 | ** |
| 3787 | ** ^Return the index of an SQL parameter given its name. ^The |
| 3788 | ** index value returned is suitable for use as the second |
| 3789 | ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero |
| 3790 | ** is returned if no matching parameter is found. ^The parameter |
| @@ -3797,19 +3824,21 @@ | |
| 3797 | */ |
| 3798 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3799 | |
| 3800 | /* |
| 3801 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| 3802 | ** |
| 3803 | ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset |
| 3804 | ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. |
| 3805 | ** ^Use this routine to reset all host parameters to NULL. |
| 3806 | */ |
| 3807 | SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*); |
| 3808 | |
| 3809 | /* |
| 3810 | ** CAPI3REF: Number Of Columns In A Result Set |
| 3811 | ** |
| 3812 | ** ^Return the number of columns in the result set returned by the |
| 3813 | ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL |
| 3814 | ** statement that does not return data (for example an [UPDATE]). |
| 3815 | ** |
| @@ -3817,10 +3846,11 @@ | |
| 3817 | */ |
| 3818 | SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt); |
| 3819 | |
| 3820 | /* |
| 3821 | ** CAPI3REF: Column Names In A Result Set |
| 3822 | ** |
| 3823 | ** ^These routines return the name assigned to a particular column |
| 3824 | ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() |
| 3825 | ** interface returns a pointer to a zero-terminated UTF-8 string |
| 3826 | ** and sqlite3_column_name16() returns a pointer to a zero-terminated |
| @@ -3846,10 +3876,11 @@ | |
| 3846 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N); |
| 3847 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N); |
| 3848 | |
| 3849 | /* |
| 3850 | ** CAPI3REF: Source Of Data In A Query Result |
| 3851 | ** |
| 3852 | ** ^These routines provide a means to determine the database, table, and |
| 3853 | ** table column that is the origin of a particular result column in |
| 3854 | ** [SELECT] statement. |
| 3855 | ** ^The name of the database or table or column can be returned as |
| @@ -3898,10 +3929,11 @@ | |
| 3898 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int); |
| 3899 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int); |
| 3900 | |
| 3901 | /* |
| 3902 | ** CAPI3REF: Declared Datatype Of A Query Result |
| 3903 | ** |
| 3904 | ** ^(The first parameter is a [prepared statement]. |
| 3905 | ** If this statement is a [SELECT] statement and the Nth column of the |
| 3906 | ** returned result set of that [SELECT] is a table column (not an |
| 3907 | ** expression or subquery) then the declared type of the table |
| @@ -3930,10 +3962,11 @@ | |
| 3930 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int); |
| 3931 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int); |
| 3932 | |
| 3933 | /* |
| 3934 | ** CAPI3REF: Evaluate An SQL Statement |
| 3935 | ** |
| 3936 | ** After a [prepared statement] has been prepared using either |
| 3937 | ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy |
| 3938 | ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function |
| 3939 | ** must be called one or more times to evaluate the statement. |
| @@ -4009,10 +4042,11 @@ | |
| 4009 | */ |
| 4010 | SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*); |
| 4011 | |
| 4012 | /* |
| 4013 | ** CAPI3REF: Number of columns in a result set |
| 4014 | ** |
| 4015 | ** ^The sqlite3_data_count(P) interface returns the number of columns in the |
| 4016 | ** current row of the result set of [prepared statement] P. |
| 4017 | ** ^If prepared statement P does not have results ready to return |
| 4018 | ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of |
| @@ -4062,10 +4096,11 @@ | |
| 4062 | #define SQLITE3_TEXT 3 |
| 4063 | |
| 4064 | /* |
| 4065 | ** CAPI3REF: Result Values From A Query |
| 4066 | ** KEYWORDS: {column access functions} |
| 4067 | ** |
| 4068 | ** These routines form the "result set" interface. |
| 4069 | ** |
| 4070 | ** ^These routines return information about a single column of the current |
| 4071 | ** result row of a query. ^In every case the first argument is a pointer |
| @@ -4234,10 +4269,11 @@ | |
| 4234 | SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol); |
| 4235 | SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol); |
| 4236 | |
| 4237 | /* |
| 4238 | ** CAPI3REF: Destroy A Prepared Statement Object |
| 4239 | ** |
| 4240 | ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. |
| 4241 | ** ^If the most recent evaluation of the statement encountered no errors |
| 4242 | ** or if the statement is never been evaluated, then sqlite3_finalize() returns |
| 4243 | ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then |
| @@ -4261,10 +4297,11 @@ | |
| 4261 | */ |
| 4262 | SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt); |
| 4263 | |
| 4264 | /* |
| 4265 | ** CAPI3REF: Reset A Prepared Statement Object |
| 4266 | ** |
| 4267 | ** The sqlite3_reset() function is called to reset a [prepared statement] |
| 4268 | ** object back to its initial state, ready to be re-executed. |
| 4269 | ** ^Any SQL statement variables that had values bound to them using |
| 4270 | ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. |
| @@ -4290,10 +4327,11 @@ | |
| 4290 | /* |
| 4291 | ** CAPI3REF: Create Or Redefine SQL Functions |
| 4292 | ** KEYWORDS: {function creation routines} |
| 4293 | ** KEYWORDS: {application-defined SQL function} |
| 4294 | ** KEYWORDS: {application-defined SQL functions} |
| 4295 | ** |
| 4296 | ** ^These functions (collectively known as "function creation routines") |
| 4297 | ** are used to add SQL functions or aggregates or to redefine the behavior |
| 4298 | ** of existing SQL functions or aggregates. The only differences between |
| 4299 | ** these routines are the text encoding expected for |
| @@ -4459,10 +4497,11 @@ | |
| 4459 | void*,sqlite3_int64); |
| 4460 | #endif |
| 4461 | |
| 4462 | /* |
| 4463 | ** CAPI3REF: Obtaining SQL Function Parameter Values |
| 4464 | ** |
| 4465 | ** The C-language implementation of SQL functions and aggregates uses |
| 4466 | ** this set of interface routines to access the parameter values on |
| 4467 | ** the function or aggregate. |
| 4468 | ** |
| @@ -4517,10 +4556,11 @@ | |
| 4517 | SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*); |
| 4518 | SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*); |
| 4519 | |
| 4520 | /* |
| 4521 | ** CAPI3REF: Obtain Aggregate Function Context |
| 4522 | ** |
| 4523 | ** Implementations of aggregate SQL functions use this |
| 4524 | ** routine to allocate memory for storing their state. |
| 4525 | ** |
| 4526 | ** ^The first time the sqlite3_aggregate_context(C,N) routine is called |
| @@ -4561,10 +4601,11 @@ | |
| 4561 | */ |
| 4562 | SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes); |
| 4563 | |
| 4564 | /* |
| 4565 | ** CAPI3REF: User Data For Functions |
| 4566 | ** |
| 4567 | ** ^The sqlite3_user_data() interface returns a copy of |
| 4568 | ** the pointer that was the pUserData parameter (the 5th parameter) |
| 4569 | ** of the [sqlite3_create_function()] |
| 4570 | ** and [sqlite3_create_function16()] routines that originally |
| @@ -4575,10 +4616,11 @@ | |
| 4575 | */ |
| 4576 | SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*); |
| 4577 | |
| 4578 | /* |
| 4579 | ** CAPI3REF: Database Connection For Functions |
| 4580 | ** |
| 4581 | ** ^The sqlite3_context_db_handle() interface returns a copy of |
| 4582 | ** the pointer to the [database connection] (the 1st parameter) |
| 4583 | ** of the [sqlite3_create_function()] |
| 4584 | ** and [sqlite3_create_function16()] routines that originally |
| @@ -4586,10 +4628,11 @@ | |
| 4586 | */ |
| 4587 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*); |
| 4588 | |
| 4589 | /* |
| 4590 | ** CAPI3REF: Function Auxiliary Data |
| 4591 | ** |
| 4592 | ** These functions may be used by (non-aggregate) SQL functions to |
| 4593 | ** associate metadata with argument values. If the same value is passed to |
| 4594 | ** multiple invocations of the same SQL function during query execution, under |
| 4595 | ** some circumstances the associated metadata may be preserved. An example |
| @@ -4658,10 +4701,11 @@ | |
| 4658 | #define SQLITE_STATIC ((sqlite3_destructor_type)0) |
| 4659 | #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) |
| 4660 | |
| 4661 | /* |
| 4662 | ** CAPI3REF: Setting The Result Of An SQL Function |
| 4663 | ** |
| 4664 | ** These routines are used by the xFunc or xFinal callbacks that |
| 4665 | ** implement SQL functions and aggregates. See |
| 4666 | ** [sqlite3_create_function()] and [sqlite3_create_function16()] |
| 4667 | ** for additional information. |
| @@ -4793,10 +4837,11 @@ | |
| 4793 | SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*); |
| 4794 | SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n); |
| 4795 | |
| 4796 | /* |
| 4797 | ** CAPI3REF: Define New Collating Sequences |
| 4798 | ** |
| 4799 | ** ^These functions add, remove, or modify a [collation] associated |
| 4800 | ** with the [database connection] specified as the first argument. |
| 4801 | ** |
| 4802 | ** ^The name of the collation is a UTF-8 string |
| @@ -4895,10 +4940,11 @@ | |
| 4895 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 4896 | ); |
| 4897 | |
| 4898 | /* |
| 4899 | ** CAPI3REF: Collation Needed Callbacks |
| 4900 | ** |
| 4901 | ** ^To avoid having to register all collation sequences before a database |
| 4902 | ** can be used, a single callback function may be registered with the |
| 4903 | ** [database connection] to be invoked whenever an undefined collation |
| 4904 | ** sequence is required. |
| @@ -5102,10 +5148,11 @@ | |
| 5102 | SQLITE_API char *sqlite3_data_directory; |
| 5103 | |
| 5104 | /* |
| 5105 | ** CAPI3REF: Test For Auto-Commit Mode |
| 5106 | ** KEYWORDS: {autocommit mode} |
| 5107 | ** |
| 5108 | ** ^The sqlite3_get_autocommit() interface returns non-zero or |
| 5109 | ** zero if the given database connection is or is not in autocommit mode, |
| 5110 | ** respectively. ^Autocommit mode is on by default. |
| 5111 | ** ^Autocommit mode is disabled by a [BEGIN] statement. |
| @@ -5124,10 +5171,11 @@ | |
| 5124 | */ |
| 5125 | SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*); |
| 5126 | |
| 5127 | /* |
| 5128 | ** CAPI3REF: Find The Database Handle Of A Prepared Statement |
| 5129 | ** |
| 5130 | ** ^The sqlite3_db_handle interface returns the [database connection] handle |
| 5131 | ** to which a [prepared statement] belongs. ^The [database connection] |
| 5132 | ** returned by sqlite3_db_handle is the same [database connection] |
| 5133 | ** that was the first argument |
| @@ -5136,10 +5184,11 @@ | |
| 5136 | */ |
| 5137 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*); |
| 5138 | |
| 5139 | /* |
| 5140 | ** CAPI3REF: Return The Filename For A Database Connection |
| 5141 | ** |
| 5142 | ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename |
| 5143 | ** associated with database N of connection D. ^The main database file |
| 5144 | ** has the name "main". If there is no attached database N on the database |
| 5145 | ** connection D, or if database N is a temporary or in-memory database, then |
| @@ -5152,19 +5201,21 @@ | |
| 5152 | */ |
| 5153 | SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
| 5154 | |
| 5155 | /* |
| 5156 | ** CAPI3REF: Determine if a database is read-only |
| 5157 | ** |
| 5158 | ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N |
| 5159 | ** of connection D is read-only, 0 if it is read/write, or -1 if N is not |
| 5160 | ** the name of a database on connection D. |
| 5161 | */ |
| 5162 | SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName); |
| 5163 | |
| 5164 | /* |
| 5165 | ** CAPI3REF: Find the next prepared statement |
| 5166 | ** |
| 5167 | ** ^This interface returns a pointer to the next [prepared statement] after |
| 5168 | ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL |
| 5169 | ** then this interface returns a pointer to the first prepared statement |
| 5170 | ** associated with the database connection pDb. ^If no prepared statement |
| @@ -5176,10 +5227,11 @@ | |
| 5176 | */ |
| 5177 | SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); |
| 5178 | |
| 5179 | /* |
| 5180 | ** CAPI3REF: Commit And Rollback Notification Callbacks |
| 5181 | ** |
| 5182 | ** ^The sqlite3_commit_hook() interface registers a callback |
| 5183 | ** function to be invoked whenever a transaction is [COMMIT | committed]. |
| 5184 | ** ^Any callback set by a previous call to sqlite3_commit_hook() |
| 5185 | ** for the same database connection is overridden. |
| @@ -5225,10 +5277,11 @@ | |
| 5225 | SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); |
| 5226 | SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); |
| 5227 | |
| 5228 | /* |
| 5229 | ** CAPI3REF: Data Change Notification Callbacks |
| 5230 | ** |
| 5231 | ** ^The sqlite3_update_hook() interface registers a callback function |
| 5232 | ** with the [database connection] identified by the first argument |
| 5233 | ** to be invoked whenever a row is updated, inserted or deleted in |
| 5234 | ** a rowid table. |
| @@ -5331,10 +5384,11 @@ | |
| 5331 | */ |
| 5332 | SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int); |
| 5333 | |
| 5334 | /* |
| 5335 | ** CAPI3REF: Free Memory Used By A Database Connection |
| 5336 | ** |
| 5337 | ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap |
| 5338 | ** memory as possible from database connection D. Unlike the |
| 5339 | ** [sqlite3_release_memory()] interface, this interface is in effect even |
| 5340 | ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is |
| @@ -5408,10 +5462,11 @@ | |
| 5408 | SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N); |
| 5409 | |
| 5410 | |
| 5411 | /* |
| 5412 | ** CAPI3REF: Extract Metadata About A Column Of A Table |
| 5413 | ** |
| 5414 | ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns |
| 5415 | ** information about column C of table T in database D |
| 5416 | ** on [database connection] X.)^ ^The sqlite3_table_column_metadata() |
| 5417 | ** interface returns SQLITE_OK and fills in the non-NULL pointers in |
| @@ -5486,10 +5541,11 @@ | |
| 5486 | int *pAutoinc /* OUTPUT: True if column is auto-increment */ |
| 5487 | ); |
| 5488 | |
| 5489 | /* |
| 5490 | ** CAPI3REF: Load An Extension |
| 5491 | ** |
| 5492 | ** ^This interface loads an SQLite extension library from the named file. |
| 5493 | ** |
| 5494 | ** ^The sqlite3_load_extension() interface attempts to load an |
| 5495 | ** [SQLite extension] library contained in the file zFile. If |
| @@ -5527,10 +5583,11 @@ | |
| 5527 | char **pzErrMsg /* Put error message here if not 0 */ |
| 5528 | ); |
| 5529 | |
| 5530 | /* |
| 5531 | ** CAPI3REF: Enable Or Disable Extension Loading |
| 5532 | ** |
| 5533 | ** ^So as not to open security holes in older applications that are |
| 5534 | ** unprepared to deal with [extension loading], and as a means of disabling |
| 5535 | ** [extension loading] while evaluating user-entered SQL, the following API |
| 5536 | ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. |
| @@ -5776,10 +5833,11 @@ | |
| 5776 | #define SQLITE_INDEX_CONSTRAINT_GE 32 |
| 5777 | #define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
| 5778 | |
| 5779 | /* |
| 5780 | ** CAPI3REF: Register A Virtual Table Implementation |
| 5781 | ** |
| 5782 | ** ^These routines are used to register a new [virtual table module] name. |
| 5783 | ** ^Module names must be registered before |
| 5784 | ** creating a new [virtual table] using the module and before using a |
| 5785 | ** preexisting [virtual table] for the module. |
| @@ -5872,10 +5930,11 @@ | |
| 5872 | */ |
| 5873 | SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL); |
| 5874 | |
| 5875 | /* |
| 5876 | ** CAPI3REF: Overload A Function For A Virtual Table |
| 5877 | ** |
| 5878 | ** ^(Virtual tables can provide alternative implementations of functions |
| 5879 | ** using the [xFindFunction] method of the [virtual table module]. |
| 5880 | ** But global versions of those functions |
| 5881 | ** must exist in order to be overloaded.)^ |
| @@ -5914,10 +5973,12 @@ | |
| 5914 | */ |
| 5915 | typedef struct sqlite3_blob sqlite3_blob; |
| 5916 | |
| 5917 | /* |
| 5918 | ** CAPI3REF: Open A BLOB For Incremental I/O |
| 5919 | ** |
| 5920 | ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located |
| 5921 | ** in row iRow, column zColumn, table zTable in database zDb; |
| 5922 | ** in other words, the same BLOB that would be selected by: |
| 5923 | ** |
| @@ -5995,10 +6056,11 @@ | |
| 5995 | sqlite3_blob **ppBlob |
| 5996 | ); |
| 5997 | |
| 5998 | /* |
| 5999 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 6000 | ** |
| 6001 | ** ^This function is used to move an existing blob handle so that it points |
| 6002 | ** to a different row of the same database table. ^The new row is identified |
| 6003 | ** by the rowid value passed as the second argument. Only the row can be |
| 6004 | ** changed. ^The database, table and column on which the blob handle is open |
| @@ -6019,10 +6081,11 @@ | |
| 6019 | */ |
| 6020 | SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 6021 | |
| 6022 | /* |
| 6023 | ** CAPI3REF: Close A BLOB Handle |
| 6024 | ** |
| 6025 | ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed |
| 6026 | ** unconditionally. Even if this routine returns an error code, the |
| 6027 | ** handle is still closed.)^ |
| 6028 | ** |
| @@ -6041,10 +6104,11 @@ | |
| 6041 | */ |
| 6042 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *); |
| 6043 | |
| 6044 | /* |
| 6045 | ** CAPI3REF: Return The Size Of An Open BLOB |
| 6046 | ** |
| 6047 | ** ^Returns the size in bytes of the BLOB accessible via the |
| 6048 | ** successfully opened [BLOB handle] in its only argument. ^The |
| 6049 | ** incremental blob I/O routines can only read or overwriting existing |
| 6050 | ** blob content; they cannot change the size of a blob. |
| @@ -6056,10 +6120,11 @@ | |
| 6056 | */ |
| 6057 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *); |
| 6058 | |
| 6059 | /* |
| 6060 | ** CAPI3REF: Read Data From A BLOB Incrementally |
| 6061 | ** |
| 6062 | ** ^(This function is used to read data from an open [BLOB handle] into a |
| 6063 | ** caller-supplied buffer. N bytes of data are copied into buffer Z |
| 6064 | ** from the open BLOB, starting at offset iOffset.)^ |
| 6065 | ** |
| @@ -6084,10 +6149,11 @@ | |
| 6084 | */ |
| 6085 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 6086 | |
| 6087 | /* |
| 6088 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 6089 | ** |
| 6090 | ** ^(This function is used to write data into an open [BLOB handle] from a |
| 6091 | ** caller-supplied buffer. N bytes of data are copied from the buffer Z |
| 6092 | ** into the open BLOB, starting at offset iOffset.)^ |
| 6093 | ** |
| @@ -6411,10 +6477,11 @@ | |
| 6411 | #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ |
| 6412 | #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ |
| 6413 | |
| 6414 | /* |
| 6415 | ** CAPI3REF: Retrieve the mutex for a database connection |
| 6416 | ** |
| 6417 | ** ^This interface returns a pointer the [sqlite3_mutex] object that |
| 6418 | ** serializes access to the [database connection] given in the argument |
| 6419 | ** when the [threading mode] is Serialized. |
| 6420 | ** ^If the [threading mode] is Single-thread or Multi-thread then this |
| @@ -6422,10 +6489,11 @@ | |
| 6422 | */ |
| 6423 | SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*); |
| 6424 | |
| 6425 | /* |
| 6426 | ** CAPI3REF: Low-Level Control Of Database Files |
| 6427 | ** |
| 6428 | ** ^The [sqlite3_file_control()] interface makes a direct call to the |
| 6429 | ** xFileControl method for the [sqlite3_io_methods] object associated |
| 6430 | ** with a particular database identified by the second argument. ^The |
| 6431 | ** name of the database is "main" for the main database or "temp" for the |
| @@ -6638,10 +6706,11 @@ | |
| 6638 | #define SQLITE_STATUS_SCRATCH_SIZE 8 |
| 6639 | #define SQLITE_STATUS_MALLOC_COUNT 9 |
| 6640 | |
| 6641 | /* |
| 6642 | ** CAPI3REF: Database Connection Status |
| 6643 | ** |
| 6644 | ** ^This interface is used to retrieve runtime status information |
| 6645 | ** about a single [database connection]. ^The first argument is the |
| 6646 | ** database connection object to be interrogated. ^The second argument |
| 6647 | ** is an integer constant, taken from the set of |
| @@ -6766,10 +6835,11 @@ | |
| 6766 | #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */ |
| 6767 | |
| 6768 | |
| 6769 | /* |
| 6770 | ** CAPI3REF: Prepared Statement Status |
| 6771 | ** |
| 6772 | ** ^(Each prepared statement maintains various |
| 6773 | ** [SQLITE_STMTSTATUS counters] that measure the number |
| 6774 | ** of times it has performed specific operations.)^ These counters can |
| 6775 | ** be used to monitor the performance characteristics of the prepared |
| @@ -7269,10 +7339,11 @@ | |
| 7269 | SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p); |
| 7270 | SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p); |
| 7271 | |
| 7272 | /* |
| 7273 | ** CAPI3REF: Unlock Notification |
| 7274 | ** |
| 7275 | ** ^When running in shared-cache mode, a database operation may fail with |
| 7276 | ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or |
| 7277 | ** individual tables within the shared-cache cannot be obtained. See |
| 7278 | ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. |
| @@ -7439,10 +7510,11 @@ | |
| 7439 | */ |
| 7440 | SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...); |
| 7441 | |
| 7442 | /* |
| 7443 | ** CAPI3REF: Write-Ahead Log Commit Hook |
| 7444 | ** |
| 7445 | ** ^The [sqlite3_wal_hook()] function is used to register a callback that |
| 7446 | ** is invoked each time data is committed to a database in wal mode. |
| 7447 | ** |
| 7448 | ** ^(The callback is invoked by SQLite after the commit has taken place and |
| @@ -7478,10 +7550,11 @@ | |
| 7478 | void* |
| 7479 | ); |
| 7480 | |
| 7481 | /* |
| 7482 | ** CAPI3REF: Configure an auto-checkpoint |
| 7483 | ** |
| 7484 | ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around |
| 7485 | ** [sqlite3_wal_hook()] that causes any database on [database connection] D |
| 7486 | ** to automatically [checkpoint] |
| 7487 | ** after committing a transaction if there are N or |
| @@ -7508,10 +7581,11 @@ | |
| 7508 | */ |
| 7509 | SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7510 | |
| 7511 | /* |
| 7512 | ** CAPI3REF: Checkpoint a database |
| 7513 | ** |
| 7514 | ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to |
| 7515 | ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ |
| 7516 | ** |
| 7517 | ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the |
| @@ -7529,10 +7603,11 @@ | |
| 7529 | */ |
| 7530 | SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7531 | |
| 7532 | /* |
| 7533 | ** CAPI3REF: Checkpoint a database |
| 7534 | ** |
| 7535 | ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint |
| 7536 | ** operation on database X of [database connection] D in mode M. Status |
| 7537 | ** information is written back into integers pointed to by L and C.)^ |
| 7538 | ** ^(The M parameter must be a valid [checkpoint mode]:)^ |
| @@ -7783,10 +7858,11 @@ | |
| 7783 | #define SQLITE_SCANSTAT_EXPLAIN 4 |
| 7784 | #define SQLITE_SCANSTAT_SELECTID 5 |
| 7785 | |
| 7786 | /* |
| 7787 | ** CAPI3REF: Prepared Statement Scan Status |
| 7788 | ** |
| 7789 | ** This interface returns information about the predicted and measured |
| 7790 | ** performance for pStmt. Advanced applications can use this |
| 7791 | ** interface to compare the predicted and the measured performance and |
| 7792 | ** issue warnings and/or rerun [ANALYZE] if discrepancies are found. |
| @@ -7820,10 +7896,11 @@ | |
| 7820 | void *pOut /* Result written here */ |
| 7821 | ); |
| 7822 | |
| 7823 | /* |
| 7824 | ** CAPI3REF: Zero Scan-Status Counters |
| 7825 | ** |
| 7826 | ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. |
| 7827 | ** |
| 7828 | ** This API is only available if the library is built with pre-processor |
| 7829 | ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| @@ -8430,10 +8507,36 @@ | |
| 8430 | #else |
| 8431 | # define ALWAYS(X) (X) |
| 8432 | # define NEVER(X) (X) |
| 8433 | #endif |
| 8434 | |
| 8435 | /* |
| 8436 | ** Return true (non-zero) if the input is an integer that is too large |
| 8437 | ** to fit in 32-bits. This macro is used inside of various testcase() |
| 8438 | ** macros to verify that we have tested SQLite for large-file support. |
| 8439 | */ |
| @@ -9841,37 +9944,36 @@ | |
| 9841 | /* Properties such as "out2" or "jump" that are specified in |
| 9842 | ** comments following the "case" for each opcode in the vdbe.c |
| 9843 | ** are encoded into bitvectors as follows: |
| 9844 | */ |
| 9845 | #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */ |
| 9846 | #define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */ |
| 9847 | #define OPFLG_IN1 0x0004 /* in1: P1 is an input */ |
| 9848 | #define OPFLG_IN2 0x0008 /* in2: P2 is an input */ |
| 9849 | #define OPFLG_IN3 0x0010 /* in3: P3 is an input */ |
| 9850 | #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */ |
| 9851 | #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */ |
| 9852 | #define OPFLG_INITIALIZER {\ |
| 9853 | /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\ |
| 9854 | /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\ |
| 9855 | /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\ |
| 9856 | /* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\ |
| 9857 | /* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\ |
| 9858 | /* 40 */ 0x04, 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00,\ |
| 9859 | /* 48 */ 0x00, 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00,\ |
| 9860 | /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,\ |
| 9861 | /* 64 */ 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x4c,\ |
| 9862 | /* 72 */ 0x4c, 0x02, 0x02, 0x00, 0x05, 0x05, 0x15, 0x15,\ |
| 9863 | /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\ |
| 9864 | /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\ |
| 9865 | /* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,\ |
| 9866 | /* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08, 0x00,\ |
| 9867 | /* 112 */ 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,\ |
| 9868 | /* 120 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 9869 | /* 128 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x02, 0x00, 0x01,\ |
| 9870 | /* 136 */ 0x08, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x01,\ |
| 9871 | /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\ |
| 9872 | /* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,} |
| 9873 | |
| 9874 | /************** End of opcodes.h *********************************************/ |
| 9875 | /************** Continuing where we left off in vdbe.h ***********************/ |
| 9876 | |
| 9877 | /* |
| @@ -9926,10 +10028,11 @@ | |
| 9926 | #endif |
| 9927 | SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); |
| 9928 | |
| 9929 | SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*); |
| 9930 | SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*); |
| 9931 | SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **); |
| 9932 | |
| 9933 | typedef int (*RecordCompare)(int,const void*,UnpackedRecord*); |
| 9934 | SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*); |
| 9935 | |
| @@ -11063,10 +11166,11 @@ | |
| 11063 | #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */ |
| 11064 | #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */ |
| 11065 | #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */ |
| 11066 | #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */ |
| 11067 | #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */ |
| 11068 | |
| 11069 | |
| 11070 | /* |
| 11071 | ** Bits of the sqlite3.dbOptFlags field that are used by the |
| 11072 | ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to |
| @@ -11393,38 +11497,12 @@ | |
| 11393 | int iSavepoint; /* Depth of the SAVEPOINT stack */ |
| 11394 | VTable *pNext; /* Next in linked list (see above) */ |
| 11395 | }; |
| 11396 | |
| 11397 | /* |
| 11398 | ** Each SQL table is represented in memory by an instance of the |
| 11399 | ** following structure. |
| 11400 | ** |
| 11401 | ** Table.zName is the name of the table. The case of the original |
| 11402 | ** CREATE TABLE statement is stored, but case is not significant for |
| 11403 | ** comparisons. |
| 11404 | ** |
| 11405 | ** Table.nCol is the number of columns in this table. Table.aCol is a |
| 11406 | ** pointer to an array of Column structures, one for each column. |
| 11407 | ** |
| 11408 | ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of |
| 11409 | ** the column that is that key. Otherwise Table.iPKey is negative. Note |
| 11410 | ** that the datatype of the PRIMARY KEY must be INTEGER for this field to |
| 11411 | ** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of |
| 11412 | ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid |
| 11413 | ** is generated for each row of the table. TF_HasPrimaryKey is set if |
| 11414 | ** the table has any PRIMARY KEY, INTEGER or otherwise. |
| 11415 | ** |
| 11416 | ** Table.tnum is the page number for the root BTree page of the table in the |
| 11417 | ** database file. If Table.iDb is the index of the database table backend |
| 11418 | ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that |
| 11419 | ** holds temporary tables and indices. If TF_Ephemeral is set |
| 11420 | ** then the table is stored in a file that is automatically deleted |
| 11421 | ** when the VDBE cursor to the table is closed. In this case Table.tnum |
| 11422 | ** refers VDBE cursor number that holds the table open, not to the root |
| 11423 | ** page number. Transient tables are used to hold the results of a |
| 11424 | ** sub-query that appears instead of a real table name in the FROM clause |
| 11425 | ** of a SELECT statement. |
| 11426 | */ |
| 11427 | struct Table { |
| 11428 | char *zName; /* Name of the table or view */ |
| 11429 | Column *aCol; /* Information about each column */ |
| 11430 | Index *pIndex; /* List of SQL indexes on this table. */ |
| @@ -11432,15 +11510,15 @@ | |
| 11432 | FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| 11433 | char *zColAff; /* String defining the affinity of each column */ |
| 11434 | #ifndef SQLITE_OMIT_CHECK |
| 11435 | ExprList *pCheck; /* All CHECK constraints */ |
| 11436 | #endif |
| 11437 | LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */ |
| 11438 | int tnum; /* Root BTree node for this table (see note above) */ |
| 11439 | i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */ |
| 11440 | i16 nCol; /* Number of columns in this table */ |
| 11441 | u16 nRef; /* Number of pointers to this Table */ |
| 11442 | LogEst szTabRow; /* Estimated size of each table row in bytes */ |
| 11443 | #ifdef SQLITE_ENABLE_COSTMULT |
| 11444 | LogEst costMult; /* Cost multiplier for using this table */ |
| 11445 | #endif |
| 11446 | u8 tabFlags; /* Mask of TF_* values */ |
| @@ -11458,17 +11536,24 @@ | |
| 11458 | Table *pNextZombie; /* Next on the Parse.pZombieTab list */ |
| 11459 | }; |
| 11460 | |
| 11461 | /* |
| 11462 | ** Allowed values for Table.tabFlags. |
| 11463 | */ |
| 11464 | #define TF_Readonly 0x01 /* Read-only system table */ |
| 11465 | #define TF_Ephemeral 0x02 /* An ephemeral table */ |
| 11466 | #define TF_HasPrimaryKey 0x04 /* Table has a primary key */ |
| 11467 | #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */ |
| 11468 | #define TF_Virtual 0x10 /* Is a virtual table */ |
| 11469 | #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */ |
| 11470 | |
| 11471 | |
| 11472 | /* |
| 11473 | ** Test to see whether or not a table is a virtual table. This is |
| 11474 | ** done as a macro so that it will be optimized out when virtual |
| @@ -12221,11 +12306,11 @@ | |
| 12221 | #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */ |
| 12222 | #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */ |
| 12223 | #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ |
| 12224 | #define SF_Compound 0x0040 /* Part of a compound query */ |
| 12225 | #define SF_Values 0x0080 /* Synthesized from VALUES clause */ |
| 12226 | #define SF_AllValues 0x0100 /* All terms of compound are VALUES */ |
| 12227 | #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */ |
| 12228 | #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */ |
| 12229 | #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */ |
| 12230 | #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */ |
| 12231 | #define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */ |
| @@ -12605,24 +12690,24 @@ | |
| 12605 | * |
| 12606 | * (op == TK_INSERT) |
| 12607 | * orconf -> stores the ON CONFLICT algorithm |
| 12608 | * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then |
| 12609 | * this stores a pointer to the SELECT statement. Otherwise NULL. |
| 12610 | * target -> A token holding the quoted name of the table to insert into. |
| 12611 | * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then |
| 12612 | * this stores values to be inserted. Otherwise NULL. |
| 12613 | * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ... |
| 12614 | * statement, then this stores the column-names to be |
| 12615 | * inserted into. |
| 12616 | * |
| 12617 | * (op == TK_DELETE) |
| 12618 | * target -> A token holding the quoted name of the table to delete from. |
| 12619 | * pWhere -> The WHERE clause of the DELETE statement if one is specified. |
| 12620 | * Otherwise NULL. |
| 12621 | * |
| 12622 | * (op == TK_UPDATE) |
| 12623 | * target -> A token holding the quoted name of the table to update rows of. |
| 12624 | * pWhere -> The WHERE clause of the UPDATE statement if one is specified. |
| 12625 | * Otherwise NULL. |
| 12626 | * pExprList -> A list of the columns to update and the expressions to update |
| 12627 | * them to. See sqlite3Update() documentation of "pChanges" |
| 12628 | * argument. |
| @@ -12630,12 +12715,12 @@ | |
| 12630 | */ |
| 12631 | struct TriggerStep { |
| 12632 | u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */ |
| 12633 | u8 orconf; /* OE_Rollback etc. */ |
| 12634 | Trigger *pTrig; /* The trigger that this step is a part of */ |
| 12635 | Select *pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */ |
| 12636 | Token target; /* Target table for DELETE, UPDATE, INSERT */ |
| 12637 | Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ |
| 12638 | ExprList *pExprList; /* SET clause for UPDATE. */ |
| 12639 | IdList *pIdList; /* Column names for INSERT */ |
| 12640 | TriggerStep *pNext; /* Next in the link-list */ |
| 12641 | TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ |
| @@ -12664,12 +12749,11 @@ | |
| 12664 | sqlite3 *db; /* Optional database for lookaside. Can be NULL */ |
| 12665 | char *zBase; /* A base allocation. Not from malloc. */ |
| 12666 | char *zText; /* The string collected so far */ |
| 12667 | int nChar; /* Length of the string so far */ |
| 12668 | int nAlloc; /* Amount of space allocated in zText */ |
| 12669 | int mxAlloc; /* Maximum allowed string length */ |
| 12670 | u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */ |
| 12671 | u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */ |
| 12672 | }; |
| 12673 | #define STRACCUM_NOMEM 1 |
| 12674 | #define STRACCUM_TOOBIG 2 |
| 12675 | |
| @@ -12982,11 +13066,11 @@ | |
| 12982 | SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list); |
| 12983 | SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...); |
| 12984 | SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 12985 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
| 12986 | SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...); |
| 12987 | #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) |
| 12988 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...); |
| 12989 | #endif |
| 12990 | #if defined(SQLITE_TEST) |
| 12991 | SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*); |
| 12992 | #endif |
| @@ -13329,11 +13413,11 @@ | |
| 13329 | SQLITE_PRIVATE void sqlite3Error(sqlite3*,int); |
| 13330 | SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n); |
| 13331 | SQLITE_PRIVATE u8 sqlite3HexToInt(int h); |
| 13332 | SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
| 13333 | |
| 13334 | #if defined(SQLITE_TEST) |
| 13335 | SQLITE_PRIVATE const char *sqlite3ErrName(int); |
| 13336 | #endif |
| 13337 | |
| 13338 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 13339 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| @@ -13423,11 +13507,11 @@ | |
| 13423 | FuncDestructor *pDestructor |
| 13424 | ); |
| 13425 | SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); |
| 13426 | SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); |
| 13427 | |
| 13428 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int); |
| 13429 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int); |
| 13430 | SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*); |
| 13431 | SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char); |
| 13432 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 13433 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*); |
| @@ -19807,20 +19891,10 @@ | |
| 19807 | */ |
| 19808 | #ifdef MEMORY_DEBUG |
| 19809 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 19810 | #endif |
| 19811 | |
| 19812 | #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 19813 | # ifndef SQLITE_DEBUG_OS_TRACE |
| 19814 | # define SQLITE_DEBUG_OS_TRACE 0 |
| 19815 | # endif |
| 19816 | int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; |
| 19817 | # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X |
| 19818 | #else |
| 19819 | # define OSTRACE(X) |
| 19820 | #endif |
| 19821 | |
| 19822 | /* |
| 19823 | ** Macros for performance tracing. Normally turned off. Only works |
| 19824 | ** on i486 hardware. |
| 19825 | */ |
| 19826 | #ifdef SQLITE_PERFORMANCE_TRACE |
| @@ -21401,10 +21475,11 @@ | |
| 21401 | |
| 21402 | /* |
| 21403 | ** Set the StrAccum object to an error mode. |
| 21404 | */ |
| 21405 | static void setStrAccumError(StrAccum *p, u8 eError){ |
| 21406 | p->accError = eError; |
| 21407 | p->nAlloc = 0; |
| 21408 | } |
| 21409 | |
| 21410 | /* |
| @@ -22018,11 +22093,11 @@ | |
| 22018 | if( p->accError ){ |
| 22019 | testcase(p->accError==STRACCUM_TOOBIG); |
| 22020 | testcase(p->accError==STRACCUM_NOMEM); |
| 22021 | return 0; |
| 22022 | } |
| 22023 | if( !p->useMalloc ){ |
| 22024 | N = p->nAlloc - p->nChar - 1; |
| 22025 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 22026 | return N; |
| 22027 | }else{ |
| 22028 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| @@ -22038,14 +22113,14 @@ | |
| 22038 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 22039 | return 0; |
| 22040 | }else{ |
| 22041 | p->nAlloc = (int)szNew; |
| 22042 | } |
| 22043 | if( p->useMalloc==1 ){ |
| 22044 | zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc); |
| 22045 | }else{ |
| 22046 | zNew = sqlite3_realloc(zOld, p->nAlloc); |
| 22047 | } |
| 22048 | if( zNew ){ |
| 22049 | assert( p->zText!=0 || p->nChar==0 ); |
| 22050 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 22051 | p->zText = zNew; |
| @@ -22089,11 +22164,11 @@ | |
| 22089 | /* |
| 22090 | ** Append N bytes of text from z to the StrAccum object. Increase the |
| 22091 | ** size of the memory allocation for StrAccum if necessary. |
| 22092 | */ |
| 22093 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ |
| 22094 | assert( z!=0 ); |
| 22095 | assert( p->zText!=0 || p->nChar==0 || p->accError ); |
| 22096 | assert( N>=0 ); |
| 22097 | assert( p->accError==0 || p->nAlloc==0 ); |
| 22098 | if( p->nChar+N >= p->nAlloc ){ |
| 22099 | enlargeAndAppend(p,z,N); |
| @@ -22118,16 +22193,12 @@ | |
| 22118 | ** pointer if any kind of error was encountered. |
| 22119 | */ |
| 22120 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){ |
| 22121 | if( p->zText ){ |
| 22122 | p->zText[p->nChar] = 0; |
| 22123 | if( p->useMalloc && p->zText==p->zBase ){ |
| 22124 | if( p->useMalloc==1 ){ |
| 22125 | p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); |
| 22126 | }else{ |
| 22127 | p->zText = sqlite3_malloc(p->nChar+1); |
| 22128 | } |
| 22129 | if( p->zText ){ |
| 22130 | memcpy(p->zText, p->zBase, p->nChar+1); |
| 22131 | }else{ |
| 22132 | setStrAccumError(p, STRACCUM_NOMEM); |
| 22133 | } |
| @@ -22139,29 +22210,35 @@ | |
| 22139 | /* |
| 22140 | ** Reset an StrAccum string. Reclaim all malloced memory. |
| 22141 | */ |
| 22142 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){ |
| 22143 | if( p->zText!=p->zBase ){ |
| 22144 | if( p->useMalloc==1 ){ |
| 22145 | sqlite3DbFree(p->db, p->zText); |
| 22146 | }else{ |
| 22147 | sqlite3_free(p->zText); |
| 22148 | } |
| 22149 | } |
| 22150 | p->zText = 0; |
| 22151 | } |
| 22152 | |
| 22153 | /* |
| 22154 | ** Initialize a string accumulator |
| 22155 | */ |
| 22156 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){ |
| 22157 | p->zText = p->zBase = zBase; |
| 22158 | p->db = 0; |
| 22159 | p->nChar = 0; |
| 22160 | p->nAlloc = n; |
| 22161 | p->mxAlloc = mx; |
| 22162 | p->useMalloc = 1; |
| 22163 | p->accError = 0; |
| 22164 | } |
| 22165 | |
| 22166 | /* |
| 22167 | ** Print into memory obtained from sqliteMalloc(). Use the internal |
| @@ -22170,13 +22247,12 @@ | |
| 22170 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){ |
| 22171 | char *z; |
| 22172 | char zBase[SQLITE_PRINT_BUF_SIZE]; |
| 22173 | StrAccum acc; |
| 22174 | assert( db!=0 ); |
| 22175 | sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), |
| 22176 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 22177 | acc.db = db; |
| 22178 | sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap); |
| 22179 | z = sqlite3StrAccumFinish(&acc); |
| 22180 | if( acc.accError==STRACCUM_NOMEM ){ |
| 22181 | db->mallocFailed = 1; |
| 22182 | } |
| @@ -22230,12 +22306,11 @@ | |
| 22230 | } |
| 22231 | #endif |
| 22232 | #ifndef SQLITE_OMIT_AUTOINIT |
| 22233 | if( sqlite3_initialize() ) return 0; |
| 22234 | #endif |
| 22235 | sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); |
| 22236 | acc.useMalloc = 2; |
| 22237 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22238 | z = sqlite3StrAccumFinish(&acc); |
| 22239 | return z; |
| 22240 | } |
| 22241 | |
| @@ -22276,12 +22351,11 @@ | |
| 22276 | (void)SQLITE_MISUSE_BKPT; |
| 22277 | if( zBuf ) zBuf[0] = 0; |
| 22278 | return zBuf; |
| 22279 | } |
| 22280 | #endif |
| 22281 | sqlite3StrAccumInit(&acc, zBuf, n, 0); |
| 22282 | acc.useMalloc = 0; |
| 22283 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22284 | return sqlite3StrAccumFinish(&acc); |
| 22285 | } |
| 22286 | SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ |
| 22287 | char *z; |
| @@ -22303,12 +22377,11 @@ | |
| 22303 | */ |
| 22304 | static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){ |
| 22305 | StrAccum acc; /* String accumulator */ |
| 22306 | char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */ |
| 22307 | |
| 22308 | sqlite3StrAccumInit(&acc, zMsg, sizeof(zMsg), 0); |
| 22309 | acc.useMalloc = 0; |
| 22310 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22311 | sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode, |
| 22312 | sqlite3StrAccumFinish(&acc)); |
| 22313 | } |
| 22314 | |
| @@ -22322,22 +22395,21 @@ | |
| 22322 | renderLogMsg(iErrCode, zFormat, ap); |
| 22323 | va_end(ap); |
| 22324 | } |
| 22325 | } |
| 22326 | |
| 22327 | #if defined(SQLITE_DEBUG) |
| 22328 | /* |
| 22329 | ** A version of printf() that understands %lld. Used for debugging. |
| 22330 | ** The printf() built into some versions of windows does not understand %lld |
| 22331 | ** and segfaults if you give it a long long int. |
| 22332 | */ |
| 22333 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){ |
| 22334 | va_list ap; |
| 22335 | StrAccum acc; |
| 22336 | char zBuf[500]; |
| 22337 | sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0); |
| 22338 | acc.useMalloc = 0; |
| 22339 | va_start(ap,zFormat); |
| 22340 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22341 | va_end(ap); |
| 22342 | sqlite3StrAccumFinish(&acc); |
| 22343 | fprintf(stdout,"%s", zBuf); |
| @@ -22360,11 +22432,11 @@ | |
| 22360 | */ |
| 22361 | /* Add a new subitem to the tree. The moreToFollow flag indicates that this |
| 22362 | ** is not the last item in the tree. */ |
| 22363 | SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){ |
| 22364 | if( p==0 ){ |
| 22365 | p = sqlite3_malloc( sizeof(*p) ); |
| 22366 | if( p==0 ) return 0; |
| 22367 | memset(p, 0, sizeof(*p)); |
| 22368 | }else{ |
| 22369 | p->iLevel++; |
| 22370 | } |
| @@ -22383,12 +22455,11 @@ | |
| 22383 | SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){ |
| 22384 | va_list ap; |
| 22385 | int i; |
| 22386 | StrAccum acc; |
| 22387 | char zBuf[500]; |
| 22388 | sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0); |
| 22389 | acc.useMalloc = 0; |
| 22390 | if( p ){ |
| 22391 | for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){ |
| 22392 | sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4); |
| 22393 | } |
| 22394 | sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4); |
| @@ -24007,10 +24078,11 @@ | |
| 24007 | }else{ |
| 24008 | return 0; |
| 24009 | } |
| 24010 | } |
| 24011 | #endif |
| 24012 | for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){ |
| 24013 | v = v*10 + c; |
| 24014 | } |
| 24015 | |
| 24016 | /* The longest decimal representation of a 32 bit integer is 10 digits: |
| @@ -25261,10 +25333,21 @@ | |
| 25261 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 25262 | # include <sys/ioctl.h> |
| 25263 | # include <sys/file.h> |
| 25264 | # include <sys/param.h> |
| 25265 | #endif /* SQLITE_ENABLE_LOCKING_STYLE */ |
| 25266 | |
| 25267 | #if OS_VXWORKS |
| 25268 | /* # include <sys/ioctl.h> */ |
| 25269 | # include <semaphore.h> |
| 25270 | # include <limits.h> |
| @@ -25457,20 +25540,10 @@ | |
| 25457 | */ |
| 25458 | #ifdef MEMORY_DEBUG |
| 25459 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 25460 | #endif |
| 25461 | |
| 25462 | #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 25463 | # ifndef SQLITE_DEBUG_OS_TRACE |
| 25464 | # define SQLITE_DEBUG_OS_TRACE 0 |
| 25465 | # endif |
| 25466 | int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; |
| 25467 | # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X |
| 25468 | #else |
| 25469 | # define OSTRACE(X) |
| 25470 | #endif |
| 25471 | |
| 25472 | /* |
| 25473 | ** Macros for performance tracing. Normally turned off. Only works |
| 25474 | ** on i486 hardware. |
| 25475 | */ |
| 25476 | #ifdef SQLITE_PERFORMANCE_TRACE |
| @@ -26009,11 +26082,11 @@ | |
| 26009 | return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 26010 | } |
| 26011 | #endif |
| 26012 | |
| 26013 | |
| 26014 | #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 26015 | /* |
| 26016 | ** Helper function for printing out trace information from debugging |
| 26017 | ** binaries. This returns the string representation of the supplied |
| 26018 | ** integer lock-type. |
| 26019 | */ |
| @@ -26272,11 +26345,11 @@ | |
| 26272 | struct vxworksFileId *pCandidate; /* For looping over existing file IDs */ |
| 26273 | int n; /* Length of zAbsoluteName string */ |
| 26274 | |
| 26275 | assert( zAbsoluteName[0]=='/' ); |
| 26276 | n = (int)strlen(zAbsoluteName); |
| 26277 | pNew = sqlite3_malloc( sizeof(*pNew) + (n+1) ); |
| 26278 | if( pNew==0 ) return 0; |
| 26279 | pNew->zCanonicalName = (char*)&pNew[1]; |
| 26280 | memcpy(pNew->zCanonicalName, zAbsoluteName, n+1); |
| 26281 | n = vxworksSimplifyName(pNew->zCanonicalName, n); |
| 26282 | |
| @@ -26676,11 +26749,11 @@ | |
| 26676 | pInode = inodeList; |
| 26677 | while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){ |
| 26678 | pInode = pInode->pNext; |
| 26679 | } |
| 26680 | if( pInode==0 ){ |
| 26681 | pInode = sqlite3_malloc( sizeof(*pInode) ); |
| 26682 | if( pInode==0 ){ |
| 26683 | return SQLITE_NOMEM; |
| 26684 | } |
| 26685 | memset(pInode, 0, sizeof(*pInode)); |
| 26686 | memcpy(&pInode->fileId, &fileId, sizeof(fileId)); |
| @@ -29197,11 +29270,11 @@ | |
| 29197 | case SQLITE_FCNTL_VFSNAME: { |
| 29198 | *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); |
| 29199 | return SQLITE_OK; |
| 29200 | } |
| 29201 | case SQLITE_FCNTL_TEMPFILENAME: { |
| 29202 | char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname ); |
| 29203 | if( zTFile ){ |
| 29204 | unixGetTempname(pFile->pVfs->mxPathname, zTFile); |
| 29205 | *(char**)pArg = zTFile; |
| 29206 | } |
| 29207 | return SQLITE_OK; |
| @@ -29638,11 +29711,11 @@ | |
| 29638 | unixInodeInfo *pInode; /* The inode of fd */ |
| 29639 | char *zShmFilename; /* Name of the file used for SHM */ |
| 29640 | int nShmFilename; /* Size of the SHM filename in bytes */ |
| 29641 | |
| 29642 | /* Allocate space for the new unixShm object. */ |
| 29643 | p = sqlite3_malloc( sizeof(*p) ); |
| 29644 | if( p==0 ) return SQLITE_NOMEM; |
| 29645 | memset(p, 0, sizeof(*p)); |
| 29646 | assert( pDbFd->pShm==0 ); |
| 29647 | |
| 29648 | /* Check to see if a unixShmNode object already exists. Reuse an existing |
| @@ -29669,11 +29742,11 @@ | |
| 29669 | #ifdef SQLITE_SHM_DIRECTORY |
| 29670 | nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31; |
| 29671 | #else |
| 29672 | nShmFilename = 6 + (int)strlen(zBasePath); |
| 29673 | #endif |
| 29674 | pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename ); |
| 29675 | if( pShmNode==0 ){ |
| 29676 | rc = SQLITE_NOMEM; |
| 29677 | goto shm_open_err; |
| 29678 | } |
| 29679 | memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename); |
| @@ -29879,11 +29952,11 @@ | |
| 29879 | if( pMem==MAP_FAILED ){ |
| 29880 | rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename); |
| 29881 | goto shmpage_out; |
| 29882 | } |
| 29883 | }else{ |
| 29884 | pMem = sqlite3_malloc(szRegion); |
| 29885 | if( pMem==0 ){ |
| 29886 | rc = SQLITE_NOMEM; |
| 29887 | goto shmpage_out; |
| 29888 | } |
| 29889 | memset(pMem, 0, szRegion); |
| @@ -30716,11 +30789,11 @@ | |
| 30716 | else if( pLockingStyle == &afpIoMethods ){ |
| 30717 | /* AFP locking uses the file path so it needs to be included in |
| 30718 | ** the afpLockingContext. |
| 30719 | */ |
| 30720 | afpLockingContext *pCtx; |
| 30721 | pNew->lockingContext = pCtx = sqlite3_malloc( sizeof(*pCtx) ); |
| 30722 | if( pCtx==0 ){ |
| 30723 | rc = SQLITE_NOMEM; |
| 30724 | }else{ |
| 30725 | /* NB: zFilename exists and remains valid until the file is closed |
| 30726 | ** according to requirement F11141. So we do not need to make a |
| @@ -30746,11 +30819,11 @@ | |
| 30746 | */ |
| 30747 | char *zLockFile; |
| 30748 | int nFilename; |
| 30749 | assert( zFilename!=0 ); |
| 30750 | nFilename = (int)strlen(zFilename) + 6; |
| 30751 | zLockFile = (char *)sqlite3_malloc(nFilename); |
| 30752 | if( zLockFile==0 ){ |
| 30753 | rc = SQLITE_NOMEM; |
| 30754 | }else{ |
| 30755 | sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename); |
| 30756 | } |
| @@ -31123,11 +31196,11 @@ | |
| 31123 | UnixUnusedFd *pUnused; |
| 31124 | pUnused = findReusableFd(zName, flags); |
| 31125 | if( pUnused ){ |
| 31126 | fd = pUnused->fd; |
| 31127 | }else{ |
| 31128 | pUnused = sqlite3_malloc(sizeof(*pUnused)); |
| 31129 | if( !pUnused ){ |
| 31130 | return SQLITE_NOMEM; |
| 31131 | } |
| 31132 | } |
| 31133 | p->pUnused = pUnused; |
| @@ -31503,11 +31576,11 @@ | |
| 31503 | ** that we always use the same random number sequence. This makes the |
| 31504 | ** tests repeatable. |
| 31505 | */ |
| 31506 | memset(zBuf, 0, nBuf); |
| 31507 | randomnessPid = osGetpid(0); |
| 31508 | #if !defined(SQLITE_TEST) |
| 31509 | { |
| 31510 | int fd, got; |
| 31511 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 31512 | if( fd<0 ){ |
| 31513 | time_t t; |
| @@ -31915,11 +31988,11 @@ | |
| 31915 | */ |
| 31916 | pUnused = findReusableFd(path, openFlags); |
| 31917 | if( pUnused ){ |
| 31918 | fd = pUnused->fd; |
| 31919 | }else{ |
| 31920 | pUnused = sqlite3_malloc(sizeof(*pUnused)); |
| 31921 | if( !pUnused ){ |
| 31922 | return SQLITE_NOMEM; |
| 31923 | } |
| 31924 | } |
| 31925 | if( fd<0 ){ |
| @@ -31948,11 +32021,11 @@ | |
| 31948 | default: |
| 31949 | return SQLITE_CANTOPEN_BKPT; |
| 31950 | } |
| 31951 | } |
| 31952 | |
| 31953 | pNew = (unixFile *)sqlite3_malloc(sizeof(*pNew)); |
| 31954 | if( pNew==NULL ){ |
| 31955 | rc = SQLITE_NOMEM; |
| 31956 | goto end_create_proxy; |
| 31957 | } |
| 31958 | memset(pNew, 0, sizeof(unixFile)); |
| @@ -31981,21 +32054,22 @@ | |
| 31981 | SQLITE_API int sqlite3_hostid_num = 0; |
| 31982 | #endif |
| 31983 | |
| 31984 | #define PROXY_HOSTIDLEN 16 /* conch file host id length */ |
| 31985 | |
| 31986 | /* Not always defined in the headers as it ought to be */ |
| 31987 | extern int gethostuuid(uuid_t id, const struct timespec *wait); |
| 31988 | |
| 31989 | /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN |
| 31990 | ** bytes of writable memory. |
| 31991 | */ |
| 31992 | static int proxyGetHostID(unsigned char *pHostID, int *pError){ |
| 31993 | assert(PROXY_HOSTIDLEN == sizeof(uuid_t)); |
| 31994 | memset(pHostID, 0, PROXY_HOSTIDLEN); |
| 31995 | # if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ |
| 31996 | (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000)) |
| 31997 | { |
| 31998 | struct timespec timeout = {1, 0}; /* 1 sec timeout */ |
| 31999 | if( gethostuuid(pHostID, &timeout) ){ |
| 32000 | int err = errno; |
| 32001 | if( pError ){ |
| @@ -32409,11 +32483,11 @@ | |
| 32409 | return rc; |
| 32410 | } |
| 32411 | |
| 32412 | /* |
| 32413 | ** Given the name of a database file, compute the name of its conch file. |
| 32414 | ** Store the conch filename in memory obtained from sqlite3_malloc(). |
| 32415 | ** Make *pConchPath point to the new name. Return SQLITE_OK on success |
| 32416 | ** or SQLITE_NOMEM if unable to obtain memory. |
| 32417 | ** |
| 32418 | ** The caller is responsible for ensuring that the allocated memory |
| 32419 | ** space is eventually freed. |
| @@ -32425,11 +32499,11 @@ | |
| 32425 | int len = (int)strlen(dbPath); /* Length of database filename - dbPath */ |
| 32426 | char *conchPath; /* buffer in which to construct conch name */ |
| 32427 | |
| 32428 | /* Allocate space for the conch filename and initialize the name to |
| 32429 | ** the name of the original database file. */ |
| 32430 | *pConchPath = conchPath = (char *)sqlite3_malloc(len + 8); |
| 32431 | if( conchPath==0 ){ |
| 32432 | return SQLITE_NOMEM; |
| 32433 | } |
| 32434 | memcpy(conchPath, dbPath, len+1); |
| 32435 | |
| @@ -32541,11 +32615,11 @@ | |
| 32541 | } |
| 32542 | |
| 32543 | OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h, |
| 32544 | (lockPath ? lockPath : ":auto:"), osGetpid(0))); |
| 32545 | |
| 32546 | pCtx = sqlite3_malloc( sizeof(*pCtx) ); |
| 32547 | if( pCtx==0 ){ |
| 32548 | return SQLITE_NOMEM; |
| 32549 | } |
| 32550 | memset(pCtx, 0, sizeof(*pCtx)); |
| 32551 | |
| @@ -32985,20 +33059,10 @@ | |
| 32985 | */ |
| 32986 | #ifdef MEMORY_DEBUG |
| 32987 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 32988 | #endif |
| 32989 | |
| 32990 | #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 32991 | # ifndef SQLITE_DEBUG_OS_TRACE |
| 32992 | # define SQLITE_DEBUG_OS_TRACE 0 |
| 32993 | # endif |
| 32994 | int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; |
| 32995 | # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X |
| 32996 | #else |
| 32997 | # define OSTRACE(X) |
| 32998 | #endif |
| 32999 | |
| 33000 | /* |
| 33001 | ** Macros for performance tracing. Normally turned off. Only works |
| 33002 | ** on i486 hardware. |
| 33003 | */ |
| 33004 | #ifdef SQLITE_PERFORMANCE_TRACE |
| @@ -35898,11 +35962,11 @@ | |
| 35898 | ** Used only when SQLITE_NO_SYNC is not defined. |
| 35899 | */ |
| 35900 | BOOL rc; |
| 35901 | #endif |
| 35902 | #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \ |
| 35903 | (defined(SQLITE_TEST) && defined(SQLITE_DEBUG)) |
| 35904 | /* |
| 35905 | ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or |
| 35906 | ** OSTRACE() macros. |
| 35907 | */ |
| 35908 | winFile *pFile = (winFile*)id; |
| @@ -36575,11 +36639,11 @@ | |
| 36575 | DWORD lastErrno; /* The Windows errno from the last I/O error */ |
| 36576 | |
| 36577 | int nRef; /* Number of winShm objects pointing to this */ |
| 36578 | winShm *pFirst; /* All winShm objects pointing to this */ |
| 36579 | winShmNode *pNext; /* Next in list of all winShmNode objects */ |
| 36580 | #ifdef SQLITE_DEBUG |
| 36581 | u8 nextShmId; /* Next available winShm.id value */ |
| 36582 | #endif |
| 36583 | }; |
| 36584 | |
| 36585 | /* |
| @@ -36606,11 +36670,11 @@ | |
| 36606 | winShmNode *pShmNode; /* The underlying winShmNode object */ |
| 36607 | winShm *pNext; /* Next winShm with the same winShmNode */ |
| 36608 | u8 hasMutex; /* True if holding the winShmNode mutex */ |
| 36609 | u16 sharedMask; /* Mask of shared locks held */ |
| 36610 | u16 exclMask; /* Mask of exclusive locks held */ |
| 36611 | #ifdef SQLITE_DEBUG |
| 36612 | u8 id; /* Id of this connection with its winShmNode */ |
| 36613 | #endif |
| 36614 | }; |
| 36615 | |
| 36616 | /* |
| @@ -36797,11 +36861,11 @@ | |
| 36797 | if( rc ) goto shm_open_err; |
| 36798 | } |
| 36799 | |
| 36800 | /* Make the new connection a child of the winShmNode */ |
| 36801 | p->pShmNode = pShmNode; |
| 36802 | #ifdef SQLITE_DEBUG |
| 36803 | p->id = pShmNode->nextShmId++; |
| 36804 | #endif |
| 36805 | pShmNode->nRef++; |
| 36806 | pDbFd->pShm = p; |
| 36807 | winShmLeaveMutex(); |
| @@ -37066,11 +37130,11 @@ | |
| 37066 | goto shmpage_out; |
| 37067 | } |
| 37068 | } |
| 37069 | |
| 37070 | /* Map the requested memory region into this processes address space. */ |
| 37071 | apNew = (struct ShmRegion *)sqlite3_realloc( |
| 37072 | pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0]) |
| 37073 | ); |
| 37074 | if( !apNew ){ |
| 37075 | rc = SQLITE_IOERR_NOMEM; |
| 37076 | goto shmpage_out; |
| @@ -38513,11 +38577,11 @@ | |
| 38513 | ** Write up to nBuf bytes of randomness into zBuf. |
| 38514 | */ |
| 38515 | static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ |
| 38516 | int n = 0; |
| 38517 | UNUSED_PARAMETER(pVfs); |
| 38518 | #if defined(SQLITE_TEST) |
| 38519 | n = nBuf; |
| 38520 | memset(zBuf, 0, nBuf); |
| 38521 | #else |
| 38522 | if( sizeof(SYSTEMTIME)<=nBuf-n ){ |
| 38523 | SYSTEMTIME x; |
| @@ -38547,11 +38611,10 @@ | |
| 38547 | LARGE_INTEGER i; |
| 38548 | osQueryPerformanceCounter(&i); |
| 38549 | memcpy(&zBuf[n], &i, sizeof(i)); |
| 38550 | n += sizeof(i); |
| 38551 | } |
| 38552 | #endif |
| 38553 | #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID |
| 38554 | if( sizeof(UUID)<=nBuf-n ){ |
| 38555 | UUID id; |
| 38556 | memset(&id, 0, sizeof(UUID)); |
| 38557 | osUuidCreate(&id); |
| @@ -38564,10 +38627,11 @@ | |
| 38564 | osUuidCreateSequential(&id); |
| 38565 | memcpy(zBuf, &id, sizeof(UUID)); |
| 38566 | n += sizeof(UUID); |
| 38567 | } |
| 38568 | #endif |
| 38569 | return n; |
| 38570 | } |
| 38571 | |
| 38572 | |
| 38573 | /* |
| @@ -39118,11 +39182,11 @@ | |
| 39118 | |
| 39119 | /* Allocate the Bitvec to be tested and a linear array of |
| 39120 | ** bits to act as the reference */ |
| 39121 | pBitvec = sqlite3BitvecCreate( sz ); |
| 39122 | pV = sqlite3MallocZero( (sz+7)/8 + 1 ); |
| 39123 | pTmpSpace = sqlite3_malloc(BITVEC_SZ); |
| 39124 | if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end; |
| 39125 | |
| 39126 | /* NULL pBitvec tests */ |
| 39127 | sqlite3BitvecSet(0, 1); |
| 39128 | sqlite3BitvecClear(0, 1, pTmpSpace); |
| @@ -44607,13 +44671,11 @@ | |
| 44607 | Pgno nTruncate, /* Database size after this commit */ |
| 44608 | int isCommit /* True if this is a commit */ |
| 44609 | ){ |
| 44610 | int rc; /* Return code */ |
| 44611 | int nList; /* Number of pages in pList */ |
| 44612 | #if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES) |
| 44613 | PgHdr *p; /* For looping over pages */ |
| 44614 | #endif |
| 44615 | |
| 44616 | assert( pPager->pWal ); |
| 44617 | assert( pList ); |
| 44618 | #ifdef SQLITE_DEBUG |
| 44619 | /* Verify that the page list is in accending order */ |
| @@ -44626,11 +44688,10 @@ | |
| 44626 | if( isCommit ){ |
| 44627 | /* If a WAL transaction is being committed, there is no point in writing |
| 44628 | ** any pages with page numbers greater than nTruncate into the WAL file. |
| 44629 | ** They will never be read by any client. So remove them from the pDirty |
| 44630 | ** list here. */ |
| 44631 | PgHdr *p; |
| 44632 | PgHdr **ppNext = &pList; |
| 44633 | nList = 0; |
| 44634 | for(p=pList; (*ppNext = p)!=0; p=p->pDirty){ |
| 44635 | if( p->pgno<=nTruncate ){ |
| 44636 | ppNext = &p->pDirty; |
| @@ -44646,11 +44707,10 @@ | |
| 44646 | if( pList->pgno==1 ) pager_write_changecounter(pList); |
| 44647 | rc = sqlite3WalFrames(pPager->pWal, |
| 44648 | pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags |
| 44649 | ); |
| 44650 | if( rc==SQLITE_OK && pPager->pBackup ){ |
| 44651 | PgHdr *p; |
| 44652 | for(p=pList; p; p=p->pDirty){ |
| 44653 | sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData); |
| 44654 | } |
| 44655 | } |
| 44656 | |
| @@ -48577,10 +48637,12 @@ | |
| 48577 | }else if( state==PAGER_OPEN ){ |
| 48578 | pager_unlock(pPager); |
| 48579 | } |
| 48580 | assert( state==pPager->eState ); |
| 48581 | } |
| 48582 | } |
| 48583 | } |
| 48584 | |
| 48585 | /* Return the new journal mode */ |
| 48586 | return (int)pPager->journalMode; |
| @@ -49359,11 +49421,11 @@ | |
| 49359 | |
| 49360 | /* Enlarge the pWal->apWiData[] array if required */ |
| 49361 | if( pWal->nWiData<=iPage ){ |
| 49362 | int nByte = sizeof(u32*)*(iPage+1); |
| 49363 | volatile u32 **apNew; |
| 49364 | apNew = (volatile u32 **)sqlite3_realloc((void *)pWal->apWiData, nByte); |
| 49365 | if( !apNew ){ |
| 49366 | *ppPage = 0; |
| 49367 | return SQLITE_NOMEM; |
| 49368 | } |
| 49369 | memset((void*)&apNew[pWal->nWiData], 0, |
| @@ -49984,11 +50046,11 @@ | |
| 49984 | goto finished; |
| 49985 | } |
| 49986 | |
| 49987 | /* Malloc a buffer to read frames into. */ |
| 49988 | szFrame = szPage + WAL_FRAME_HDRSIZE; |
| 49989 | aFrame = (u8 *)sqlite3_malloc(szFrame); |
| 49990 | if( !aFrame ){ |
| 49991 | rc = SQLITE_NOMEM; |
| 49992 | goto recovery_error; |
| 49993 | } |
| 49994 | aData = &aFrame[WAL_FRAME_HDRSIZE]; |
| @@ -50377,21 +50439,21 @@ | |
| 50377 | /* Allocate space for the WalIterator object. */ |
| 50378 | nSegment = walFramePage(iLast) + 1; |
| 50379 | nByte = sizeof(WalIterator) |
| 50380 | + (nSegment-1)*sizeof(struct WalSegment) |
| 50381 | + iLast*sizeof(ht_slot); |
| 50382 | p = (WalIterator *)sqlite3_malloc(nByte); |
| 50383 | if( !p ){ |
| 50384 | return SQLITE_NOMEM; |
| 50385 | } |
| 50386 | memset(p, 0, nByte); |
| 50387 | p->nSegment = nSegment; |
| 50388 | |
| 50389 | /* Allocate temporary space used by the merge-sort routine. This block |
| 50390 | ** of memory will be freed before this function returns. |
| 50391 | */ |
| 50392 | aTmp = (ht_slot *)sqlite3_malloc( |
| 50393 | sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast) |
| 50394 | ); |
| 50395 | if( !aTmp ){ |
| 50396 | rc = SQLITE_NOMEM; |
| 50397 | } |
| @@ -50567,10 +50629,18 @@ | |
| 50567 | ** cannot be backfilled from the WAL. |
| 50568 | */ |
| 50569 | mxSafeFrame = pWal->hdr.mxFrame; |
| 50570 | mxPage = pWal->hdr.nPage; |
| 50571 | for(i=1; i<WAL_NREADER; i++){ |
| 50572 | u32 y = pInfo->aReadMark[i]; |
| 50573 | if( mxSafeFrame>y ){ |
| 50574 | assert( y<=pWal->hdr.mxFrame ); |
| 50575 | rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1); |
| 50576 | if( rc==SQLITE_OK ){ |
| @@ -57429,17 +57499,22 @@ | |
| 57429 | */ |
| 57430 | static const void *fetchPayload( |
| 57431 | BtCursor *pCur, /* Cursor pointing to entry to read from */ |
| 57432 | u32 *pAmt /* Write the number of available bytes here */ |
| 57433 | ){ |
| 57434 | assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]); |
| 57435 | assert( pCur->eState==CURSOR_VALID ); |
| 57436 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 57437 | assert( cursorHoldsMutex(pCur) ); |
| 57438 | assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); |
| 57439 | assert( pCur->info.nSize>0 ); |
| 57440 | *pAmt = pCur->info.nLocal; |
| 57441 | return (void*)pCur->info.pPayload; |
| 57442 | } |
| 57443 | |
| 57444 | |
| 57445 | /* |
| @@ -59713,11 +59788,10 @@ | |
| 59713 | if( iParentIdx==0 ){ |
| 59714 | nxDiv = 0; |
| 59715 | }else if( iParentIdx==i ){ |
| 59716 | nxDiv = i-2+bBulk; |
| 59717 | }else{ |
| 59718 | assert( bBulk==0 ); |
| 59719 | nxDiv = iParentIdx-1; |
| 59720 | } |
| 59721 | i = 2-bBulk; |
| 59722 | } |
| 59723 | nOld = i+1; |
| @@ -61501,10 +61575,61 @@ | |
| 61501 | iPage = get4byte(pOvflData); |
| 61502 | sqlite3PagerUnref(pOvflPage); |
| 61503 | } |
| 61504 | } |
| 61505 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 61506 | |
| 61507 | #ifndef SQLITE_OMIT_INTEGRITY_CHECK |
| 61508 | /* |
| 61509 | ** Do various sanity checks on a single page of a tree. Return |
| 61510 | ** the tree depth. Root pages return 0. Parents of root pages |
| @@ -61534,11 +61659,12 @@ | |
| 61534 | int hdr, cellStart; |
| 61535 | int nCell; |
| 61536 | u8 *data; |
| 61537 | BtShared *pBt; |
| 61538 | int usableSize; |
| 61539 | char *hit = 0; |
| 61540 | i64 nMinKey = 0; |
| 61541 | i64 nMaxKey = 0; |
| 61542 | const char *saved_zPfx = pCheck->zPfx; |
| 61543 | int saved_v1 = pCheck->v1; |
| 61544 | int saved_v2 = pCheck->v2; |
| @@ -61679,19 +61805,19 @@ | |
| 61679 | |
| 61680 | /* Check for complete coverage of the page |
| 61681 | */ |
| 61682 | data = pPage->aData; |
| 61683 | hdr = pPage->hdrOffset; |
| 61684 | hit = sqlite3PageMalloc( pBt->pageSize ); |
| 61685 | pCheck->zPfx = 0; |
| 61686 | if( hit==0 ){ |
| 61687 | pCheck->mallocFailed = 1; |
| 61688 | }else{ |
| 61689 | int contentOffset = get2byteNotZero(&data[hdr+5]); |
| 61690 | assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */ |
| 61691 | memset(hit+contentOffset, 0, usableSize-contentOffset); |
| 61692 | memset(hit, 1, contentOffset); |
| 61693 | /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the |
| 61694 | ** number of cells on the page. */ |
| 61695 | nCell = get2byte(&data[hdr+3]); |
| 61696 | /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page |
| 61697 | ** immediately follows the b-tree page header. */ |
| @@ -61699,20 +61825,19 @@ | |
| 61699 | /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte |
| 61700 | ** integer offsets to the cell contents. */ |
| 61701 | for(i=0; i<nCell; i++){ |
| 61702 | int pc = get2byte(&data[cellStart+i*2]); |
| 61703 | u32 size = 65536; |
| 61704 | int j; |
| 61705 | if( pc<=usableSize-4 ){ |
| 61706 | size = cellSizePtr(pPage, &data[pc]); |
| 61707 | } |
| 61708 | if( (int)(pc+size-1)>=usableSize ){ |
| 61709 | pCheck->zPfx = 0; |
| 61710 | checkAppendMsg(pCheck, |
| 61711 | "Corruption detected in cell %d on page %d",i,iPage); |
| 61712 | }else{ |
| 61713 | for(j=pc+size-1; j>=pc; j--) hit[j]++; |
| 61714 | } |
| 61715 | } |
| 61716 | /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header |
| 61717 | ** is the offset of the first freeblock, or zero if there are no |
| 61718 | ** freeblocks on the page. */ |
| @@ -61720,11 +61845,11 @@ | |
| 61720 | while( i>0 ){ |
| 61721 | int size, j; |
| 61722 | assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */ |
| 61723 | size = get2byte(&data[i+2]); |
| 61724 | assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */ |
| 61725 | for(j=i+size-1; j>=i; j--) hit[j]++; |
| 61726 | /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a |
| 61727 | ** big-endian integer which is the offset in the b-tree page of the next |
| 61728 | ** freeblock in the chain, or zero if the freeblock is the last on the |
| 61729 | ** chain. */ |
| 61730 | j = get2byte(&data[i]); |
| @@ -61732,31 +61857,37 @@ | |
| 61732 | ** increasing offset. */ |
| 61733 | assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */ |
| 61734 | assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */ |
| 61735 | i = j; |
| 61736 | } |
| 61737 | for(i=cnt=0; i<usableSize; i++){ |
| 61738 | if( hit[i]==0 ){ |
| 61739 | cnt++; |
| 61740 | }else if( hit[i]>1 ){ |
| 61741 | checkAppendMsg(pCheck, |
| 61742 | "Multiple uses for byte %d of page %d", i, iPage); |
| 61743 | break; |
| 61744 | } |
| 61745 | } |
| 61746 | /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments |
| 61747 | ** is stored in the fifth field of the b-tree page header. |
| 61748 | ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the |
| 61749 | ** number of fragmented free bytes within the cell content area. |
| 61750 | */ |
| 61751 | if( cnt!=data[hdr+7] ){ |
| 61752 | checkAppendMsg(pCheck, |
| 61753 | "Fragmentation of %d bytes reported as %d on page %d", |
| 61754 | cnt, data[hdr+7], iPage); |
| 61755 | } |
| 61756 | } |
| 61757 | sqlite3PageFree(hit); |
| 61758 | releasePage(pPage); |
| 61759 | |
| 61760 | end_of_check: |
| 61761 | pCheck->zPfx = saved_zPfx; |
| 61762 | pCheck->v1 = saved_v1; |
| @@ -61816,12 +61947,11 @@ | |
| 61816 | sqlite3BtreeLeave(p); |
| 61817 | return 0; |
| 61818 | } |
| 61819 | i = PENDING_BYTE_PAGE(pBt); |
| 61820 | if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i); |
| 61821 | sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH); |
| 61822 | sCheck.errMsg.useMalloc = 2; |
| 61823 | |
| 61824 | /* Check the integrity of the freelist |
| 61825 | */ |
| 61826 | sCheck.zPfx = "Main freelist: "; |
| 61827 | checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]), |
| @@ -63153,14 +63283,15 @@ | |
| 63153 | return SQLITE_NOMEM; |
| 63154 | } |
| 63155 | pMem->z[pMem->n] = 0; |
| 63156 | pMem->z[pMem->n+1] = 0; |
| 63157 | pMem->flags |= MEM_Term; |
| 63158 | #ifdef SQLITE_DEBUG |
| 63159 | pMem->pScopyFrom = 0; |
| 63160 | #endif |
| 63161 | } |
| 63162 | |
| 63163 | return SQLITE_OK; |
| 63164 | } |
| 63165 | |
| 63166 | /* |
| @@ -64600,11 +64731,11 @@ | |
| 64600 | int i; |
| 64601 | int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField; |
| 64602 | Mem *aMem = pRec->aMem; |
| 64603 | sqlite3 *db = aMem[0].db; |
| 64604 | for(i=0; i<nCol; i++){ |
| 64605 | if( aMem[i].szMalloc ) sqlite3DbFree(db, aMem[i].zMalloc); |
| 64606 | } |
| 64607 | sqlite3KeyInfoUnref(pRec->pKeyInfo); |
| 64608 | sqlite3DbFree(db, pRec); |
| 64609 | } |
| 64610 | } |
| @@ -66436,18 +66567,35 @@ | |
| 66436 | pVtabCursor->pVtab->nRef--; |
| 66437 | pModule->xClose(pVtabCursor); |
| 66438 | } |
| 66439 | #endif |
| 66440 | } |
| 66441 | |
| 66442 | /* |
| 66443 | ** Copy the values stored in the VdbeFrame structure to its Vdbe. This |
| 66444 | ** is used, for example, when a trigger sub-program is halted to restore |
| 66445 | ** control to the main program. |
| 66446 | */ |
| 66447 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){ |
| 66448 | Vdbe *v = pFrame->v; |
| 66449 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 66450 | v->anExec = pFrame->anExec; |
| 66451 | #endif |
| 66452 | v->aOnceFlag = pFrame->aOnceFlag; |
| 66453 | v->nOnceFlag = pFrame->nOnceFlag; |
| @@ -66478,21 +66626,11 @@ | |
| 66478 | sqlite3VdbeFrameRestore(pFrame); |
| 66479 | p->pFrame = 0; |
| 66480 | p->nFrame = 0; |
| 66481 | } |
| 66482 | assert( p->nFrame==0 ); |
| 66483 | |
| 66484 | if( p->apCsr ){ |
| 66485 | int i; |
| 66486 | for(i=0; i<p->nCursor; i++){ |
| 66487 | VdbeCursor *pC = p->apCsr[i]; |
| 66488 | if( pC ){ |
| 66489 | sqlite3VdbeFreeCursor(p, pC); |
| 66490 | p->apCsr[i] = 0; |
| 66491 | } |
| 66492 | } |
| 66493 | } |
| 66494 | if( p->aMem ){ |
| 66495 | releaseMemArray(&p->aMem[1], p->nMem); |
| 66496 | } |
| 66497 | while( p->pDelFrame ){ |
| 66498 | VdbeFrame *pDel = p->pDelFrame; |
| @@ -68233,11 +68371,11 @@ | |
| 68233 | ** If database corruption is discovered, set pPKey2->errCode to |
| 68234 | ** SQLITE_CORRUPT and return 0. If an OOM error is encountered, |
| 68235 | ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the |
| 68236 | ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db). |
| 68237 | */ |
| 68238 | static int vdbeRecordCompareWithSkip( |
| 68239 | int nKey1, const void *pKey1, /* Left key */ |
| 68240 | UnpackedRecord *pPKey2, /* Right key */ |
| 68241 | int bSkip /* If true, skip the first field */ |
| 68242 | ){ |
| 68243 | u32 d1; /* Offset into aKey[] of next data element */ |
| @@ -68419,11 +68557,11 @@ | |
| 68419 | } |
| 68420 | SQLITE_PRIVATE int sqlite3VdbeRecordCompare( |
| 68421 | int nKey1, const void *pKey1, /* Left key */ |
| 68422 | UnpackedRecord *pPKey2 /* Right key */ |
| 68423 | ){ |
| 68424 | return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0); |
| 68425 | } |
| 68426 | |
| 68427 | |
| 68428 | /* |
| 68429 | ** This function is an optimized version of sqlite3VdbeRecordCompare() |
| @@ -68507,11 +68645,11 @@ | |
| 68507 | }else if( v<lhs ){ |
| 68508 | res = pPKey2->r2; |
| 68509 | }else if( pPKey2->nField>1 ){ |
| 68510 | /* The first fields of the two keys are equal. Compare the trailing |
| 68511 | ** fields. */ |
| 68512 | res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 68513 | }else{ |
| 68514 | /* The first fields of the two keys are equal and there are no trailing |
| 68515 | ** fields. Return pPKey2->default_rc in this case. */ |
| 68516 | res = pPKey2->default_rc; |
| 68517 | } |
| @@ -68555,11 +68693,11 @@ | |
| 68555 | |
| 68556 | if( res==0 ){ |
| 68557 | res = nStr - pPKey2->aMem[0].n; |
| 68558 | if( res==0 ){ |
| 68559 | if( pPKey2->nField>1 ){ |
| 68560 | res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 68561 | }else{ |
| 68562 | res = pPKey2->default_rc; |
| 68563 | } |
| 68564 | }else if( res>0 ){ |
| 68565 | res = pPKey2->r2; |
| @@ -70497,21 +70635,22 @@ | |
| 70497 | Mem *pVar; /* Value of a host parameter */ |
| 70498 | StrAccum out; /* Accumulate the output here */ |
| 70499 | char zBase[100]; /* Initial working space */ |
| 70500 | |
| 70501 | db = p->db; |
| 70502 | sqlite3StrAccumInit(&out, zBase, sizeof(zBase), |
| 70503 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 70504 | out.db = db; |
| 70505 | if( db->nVdbeExec>1 ){ |
| 70506 | while( *zRawSql ){ |
| 70507 | const char *zStart = zRawSql; |
| 70508 | while( *(zRawSql++)!='\n' && *zRawSql ); |
| 70509 | sqlite3StrAccumAppend(&out, "-- ", 3); |
| 70510 | assert( (zRawSql - zStart) > 0 ); |
| 70511 | sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart)); |
| 70512 | } |
| 70513 | }else{ |
| 70514 | while( zRawSql[0] ){ |
| 70515 | n = findNextHostParameter(zRawSql, &nToken); |
| 70516 | assert( n>0 ); |
| 70517 | sqlite3StrAccumAppend(&out, zRawSql, n); |
| @@ -70524,14 +70663,16 @@ | |
| 70524 | sqlite3GetInt32(&zRawSql[1], &idx); |
| 70525 | }else{ |
| 70526 | idx = nextIndex; |
| 70527 | } |
| 70528 | }else{ |
| 70529 | assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' ); |
| 70530 | testcase( zRawSql[0]==':' ); |
| 70531 | testcase( zRawSql[0]=='$' ); |
| 70532 | testcase( zRawSql[0]=='@' ); |
| 70533 | idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken); |
| 70534 | assert( idx>0 ); |
| 70535 | } |
| 70536 | zRawSql += nToken; |
| 70537 | nextIndex = idx + 1; |
| @@ -71202,21 +71343,38 @@ | |
| 71202 | assert( n==(db->nSavepoint + db->isTransactionSavepoint) ); |
| 71203 | return 1; |
| 71204 | } |
| 71205 | #endif |
| 71206 | |
| 71207 | |
| 71208 | /* |
| 71209 | ** Execute as much of a VDBE program as we can. |
| 71210 | ** This is the core of sqlite3_step(). |
| 71211 | */ |
| 71212 | SQLITE_PRIVATE int sqlite3VdbeExec( |
| 71213 | Vdbe *p /* The VDBE */ |
| 71214 | ){ |
| 71215 | int pc=0; /* The program counter */ |
| 71216 | Op *aOp = p->aOp; /* Copy of p->aOp */ |
| 71217 | Op *pOp; /* Current operation */ |
| 71218 | int rc = SQLITE_OK; /* Value to return */ |
| 71219 | sqlite3 *db = p->db; /* The database */ |
| 71220 | u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ |
| 71221 | u8 encoding = ENC(db); /* The database encoding */ |
| 71222 | int iCompare = 0; /* Result of last OP_Compare operation */ |
| @@ -71288,27 +71446,26 @@ | |
| 71288 | } |
| 71289 | if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n"); |
| 71290 | } |
| 71291 | sqlite3EndBenignMalloc(); |
| 71292 | #endif |
| 71293 | for(pc=p->pc; rc==SQLITE_OK; pc++){ |
| 71294 | assert( pc>=0 && pc<p->nOp ); |
| 71295 | if( db->mallocFailed ) goto no_mem; |
| 71296 | #ifdef VDBE_PROFILE |
| 71297 | start = sqlite3Hwtime(); |
| 71298 | #endif |
| 71299 | nVmStep++; |
| 71300 | pOp = &aOp[pc]; |
| 71301 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 71302 | if( p->anExec ) p->anExec[pc]++; |
| 71303 | #endif |
| 71304 | |
| 71305 | /* Only allow tracing if SQLITE_DEBUG is defined. |
| 71306 | */ |
| 71307 | #ifdef SQLITE_DEBUG |
| 71308 | if( db->flags & SQLITE_VdbeTrace ){ |
| 71309 | sqlite3VdbePrintOp(stdout, pc, pOp); |
| 71310 | } |
| 71311 | #endif |
| 71312 | |
| 71313 | |
| 71314 | /* Check to see if we need to simulate an interrupt. This only happens |
| @@ -71321,27 +71478,13 @@ | |
| 71321 | sqlite3_interrupt(db); |
| 71322 | } |
| 71323 | } |
| 71324 | #endif |
| 71325 | |
| 71326 | /* On any opcode with the "out2-prerelease" tag, free any |
| 71327 | ** external allocations out of mem[p2] and set mem[p2] to be |
| 71328 | ** an undefined integer. Opcodes will either fill in the integer |
| 71329 | ** value or convert mem[p2] to a different type. |
| 71330 | */ |
| 71331 | assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] ); |
| 71332 | if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){ |
| 71333 | assert( pOp->p2>0 ); |
| 71334 | assert( pOp->p2<=(p->nMem-p->nCursor) ); |
| 71335 | pOut = &aMem[pOp->p2]; |
| 71336 | memAboutToChange(p, pOut); |
| 71337 | if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut); |
| 71338 | pOut->flags = MEM_Int; |
| 71339 | } |
| 71340 | |
| 71341 | /* Sanity checking on other operands */ |
| 71342 | #ifdef SQLITE_DEBUG |
| 71343 | if( (pOp->opflags & OPFLG_IN1)!=0 ){ |
| 71344 | assert( pOp->p1>0 ); |
| 71345 | assert( pOp->p1<=(p->nMem-p->nCursor) ); |
| 71346 | assert( memIsValid(&aMem[pOp->p1]) ); |
| 71347 | assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) ); |
| @@ -71370,10 +71513,13 @@ | |
| 71370 | assert( pOp->p3>0 ); |
| 71371 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 71372 | memAboutToChange(p, &aMem[pOp->p3]); |
| 71373 | } |
| 71374 | #endif |
| 71375 | |
| 71376 | switch( pOp->opcode ){ |
| 71377 | |
| 71378 | /***************************************************************************** |
| 71379 | ** What follows is a massive switch statement where each case implements a |
| @@ -71393,11 +71539,11 @@ | |
| 71393 | ** case statement is followed by a comment of the form "/# same as ... #/" |
| 71394 | ** that comment is used to determine the particular value of the opcode. |
| 71395 | ** |
| 71396 | ** Other keywords in the comment that follows each case are used to |
| 71397 | ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[]. |
| 71398 | ** Keywords include: in1, in2, in3, out2_prerelease, out2, out3. See |
| 71399 | ** the mkopcodeh.awk script for additional information. |
| 71400 | ** |
| 71401 | ** Documentation about VDBE opcodes is generated by scanning this file |
| 71402 | ** for lines of that contain "Opcode:". That line and all subsequent |
| 71403 | ** comment lines are used in the generation of the opcode.html documentation |
| @@ -71421,11 +71567,12 @@ | |
| 71421 | ** is sometimes set to 1 instead of 0 as a hint to the command-line shell |
| 71422 | ** that this Goto is the bottom of a loop and that the lines from P2 down |
| 71423 | ** to the current line should be indented for EXPLAIN output. |
| 71424 | */ |
| 71425 | case OP_Goto: { /* jump */ |
| 71426 | pc = pOp->p2 - 1; |
| 71427 | |
| 71428 | /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev, |
| 71429 | ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon |
| 71430 | ** completion. Check to see if sqlite3_interrupt() has been called |
| 71431 | ** or if the progress callback needs to be invoked. |
| @@ -71466,13 +71613,17 @@ | |
| 71466 | assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 71467 | pIn1 = &aMem[pOp->p1]; |
| 71468 | assert( VdbeMemDynamic(pIn1)==0 ); |
| 71469 | memAboutToChange(p, pIn1); |
| 71470 | pIn1->flags = MEM_Int; |
| 71471 | pIn1->u.i = pc; |
| 71472 | REGISTER_TRACE(pOp->p1, pIn1); |
| 71473 | pc = pOp->p2 - 1; |
| 71474 | break; |
| 71475 | } |
| 71476 | |
| 71477 | /* Opcode: Return P1 * * * * |
| 71478 | ** |
| @@ -71480,11 +71631,11 @@ | |
| 71480 | ** the jump, register P1 becomes undefined. |
| 71481 | */ |
| 71482 | case OP_Return: { /* in1 */ |
| 71483 | pIn1 = &aMem[pOp->p1]; |
| 71484 | assert( pIn1->flags==MEM_Int ); |
| 71485 | pc = (int)pIn1->u.i; |
| 71486 | pIn1->flags = MEM_Undefined; |
| 71487 | break; |
| 71488 | } |
| 71489 | |
| 71490 | /* Opcode: InitCoroutine P1 P2 P3 * * |
| @@ -71504,11 +71655,11 @@ | |
| 71504 | assert( pOp->p3>=0 && pOp->p3<p->nOp ); |
| 71505 | pOut = &aMem[pOp->p1]; |
| 71506 | assert( !VdbeMemDynamic(pOut) ); |
| 71507 | pOut->u.i = pOp->p3 - 1; |
| 71508 | pOut->flags = MEM_Int; |
| 71509 | if( pOp->p2 ) pc = pOp->p2 - 1; |
| 71510 | break; |
| 71511 | } |
| 71512 | |
| 71513 | /* Opcode: EndCoroutine P1 * * * * |
| 71514 | ** |
| @@ -71524,11 +71675,11 @@ | |
| 71524 | assert( pIn1->flags==MEM_Int ); |
| 71525 | assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp ); |
| 71526 | pCaller = &aOp[pIn1->u.i]; |
| 71527 | assert( pCaller->opcode==OP_Yield ); |
| 71528 | assert( pCaller->p2>=0 && pCaller->p2<p->nOp ); |
| 71529 | pc = pCaller->p2 - 1; |
| 71530 | pIn1->flags = MEM_Undefined; |
| 71531 | break; |
| 71532 | } |
| 71533 | |
| 71534 | /* Opcode: Yield P1 P2 * * * |
| @@ -71548,13 +71699,13 @@ | |
| 71548 | int pcDest; |
| 71549 | pIn1 = &aMem[pOp->p1]; |
| 71550 | assert( VdbeMemDynamic(pIn1)==0 ); |
| 71551 | pIn1->flags = MEM_Int; |
| 71552 | pcDest = (int)pIn1->u.i; |
| 71553 | pIn1->u.i = pc; |
| 71554 | REGISTER_TRACE(pOp->p1, pIn1); |
| 71555 | pc = pcDest; |
| 71556 | break; |
| 71557 | } |
| 71558 | |
| 71559 | /* Opcode: HaltIfNull P1 P2 P3 P4 P5 |
| 71560 | ** Synopsis: if r[P3]=null halt |
| @@ -71601,34 +71752,38 @@ | |
| 71601 | ** is the same as executing Halt. |
| 71602 | */ |
| 71603 | case OP_Halt: { |
| 71604 | const char *zType; |
| 71605 | const char *zLogFmt; |
| 71606 | |
| 71607 | if( pOp->p1==SQLITE_OK && p->pFrame ){ |
| 71608 | /* Halt the sub-program. Return control to the parent frame. */ |
| 71609 | VdbeFrame *pFrame = p->pFrame; |
| 71610 | p->pFrame = pFrame->pParent; |
| 71611 | p->nFrame--; |
| 71612 | sqlite3VdbeSetChanges(db, p->nChange); |
| 71613 | pc = sqlite3VdbeFrameRestore(pFrame); |
| 71614 | lastRowid = db->lastRowid; |
| 71615 | if( pOp->p2==OE_Ignore ){ |
| 71616 | /* Instruction pc is the OP_Program that invoked the sub-program |
| 71617 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 71618 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 71619 | ** an IGNORE exception. In this case jump to the address specified |
| 71620 | ** as the p2 of the calling OP_Program. */ |
| 71621 | pc = p->aOp[pc].p2-1; |
| 71622 | } |
| 71623 | aOp = p->aOp; |
| 71624 | aMem = p->aMem; |
| 71625 | break; |
| 71626 | } |
| 71627 | p->rc = pOp->p1; |
| 71628 | p->errorAction = (u8)pOp->p2; |
| 71629 | p->pc = pc; |
| 71630 | if( p->rc ){ |
| 71631 | if( pOp->p5 ){ |
| 71632 | static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK", |
| 71633 | "FOREIGN KEY" }; |
| 71634 | assert( pOp->p5>=1 && pOp->p5<=4 ); |
| @@ -71648,11 +71803,11 @@ | |
| 71648 | }else if( pOp->p4.z ){ |
| 71649 | sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z); |
| 71650 | }else{ |
| 71651 | sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType); |
| 71652 | } |
| 71653 | sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg); |
| 71654 | } |
| 71655 | rc = sqlite3VdbeHalt(p); |
| 71656 | assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); |
| 71657 | if( rc==SQLITE_BUSY ){ |
| 71658 | p->rc = rc = SQLITE_BUSY; |
| @@ -71659,19 +71814,21 @@ | |
| 71659 | }else{ |
| 71660 | assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ); |
| 71661 | assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 ); |
| 71662 | rc = p->rc ? SQLITE_ERROR : SQLITE_DONE; |
| 71663 | } |
| 71664 | goto vdbe_return; |
| 71665 | } |
| 71666 | |
| 71667 | /* Opcode: Integer P1 P2 * * * |
| 71668 | ** Synopsis: r[P2]=P1 |
| 71669 | ** |
| 71670 | ** The 32-bit integer value P1 is written into register P2. |
| 71671 | */ |
| 71672 | case OP_Integer: { /* out2-prerelease */ |
| 71673 | pOut->u.i = pOp->p1; |
| 71674 | break; |
| 71675 | } |
| 71676 | |
| 71677 | /* Opcode: Int64 * P2 * P4 * |
| @@ -71678,11 +71835,12 @@ | |
| 71678 | ** Synopsis: r[P2]=P4 |
| 71679 | ** |
| 71680 | ** P4 is a pointer to a 64-bit integer value. |
| 71681 | ** Write that value into register P2. |
| 71682 | */ |
| 71683 | case OP_Int64: { /* out2-prerelease */ |
| 71684 | assert( pOp->p4.pI64!=0 ); |
| 71685 | pOut->u.i = *pOp->p4.pI64; |
| 71686 | break; |
| 71687 | } |
| 71688 | |
| @@ -71691,11 +71849,12 @@ | |
| 71691 | ** Synopsis: r[P2]=P4 |
| 71692 | ** |
| 71693 | ** P4 is a pointer to a 64-bit floating point value. |
| 71694 | ** Write that value into register P2. |
| 71695 | */ |
| 71696 | case OP_Real: { /* same as TK_FLOAT, out2-prerelease */ |
| 71697 | pOut->flags = MEM_Real; |
| 71698 | assert( !sqlite3IsNaN(*pOp->p4.pReal) ); |
| 71699 | pOut->u.r = *pOp->p4.pReal; |
| 71700 | break; |
| 71701 | } |
| @@ -71707,12 +71866,13 @@ | |
| 71707 | ** P4 points to a nul terminated UTF-8 string. This opcode is transformed |
| 71708 | ** into a String opcode before it is executed for the first time. During |
| 71709 | ** this transformation, the length of string P4 is computed and stored |
| 71710 | ** as the P1 parameter. |
| 71711 | */ |
| 71712 | case OP_String8: { /* same as TK_STRING, out2-prerelease */ |
| 71713 | assert( pOp->p4.z!=0 ); |
| 71714 | pOp->opcode = OP_String; |
| 71715 | pOp->p1 = sqlite3Strlen30(pOp->p4.z); |
| 71716 | |
| 71717 | #ifndef SQLITE_OMIT_UTF16 |
| 71718 | if( encoding!=SQLITE_UTF8 ){ |
| @@ -71745,12 +71905,13 @@ | |
| 71745 | ** If P5!=0 and the content of register P3 is greater than zero, then |
| 71746 | ** the datatype of the register P2 is converted to BLOB. The content is |
| 71747 | ** the same sequence of bytes, it is merely interpreted as a BLOB instead |
| 71748 | ** of a string, as if it had been CAST. |
| 71749 | */ |
| 71750 | case OP_String: { /* out2-prerelease */ |
| 71751 | assert( pOp->p4.z!=0 ); |
| 71752 | pOut->flags = MEM_Str|MEM_Static|MEM_Term; |
| 71753 | pOut->z = pOp->p4.z; |
| 71754 | pOut->n = pOp->p1; |
| 71755 | pOut->enc = encoding; |
| 71756 | UPDATE_MAX_BLOBSIZE(pOut); |
| @@ -71774,13 +71935,14 @@ | |
| 71774 | ** |
| 71775 | ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that |
| 71776 | ** NULL values will not compare equal even if SQLITE_NULLEQ is set on |
| 71777 | ** OP_Ne or OP_Eq. |
| 71778 | */ |
| 71779 | case OP_Null: { /* out2-prerelease */ |
| 71780 | int cnt; |
| 71781 | u16 nullFlag; |
| 71782 | cnt = pOp->p3-pOp->p2; |
| 71783 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 71784 | pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; |
| 71785 | while( cnt>0 ){ |
| 71786 | pOut++; |
| @@ -71811,12 +71973,13 @@ | |
| 71811 | ** Synopsis: r[P2]=P4 (len=P1) |
| 71812 | ** |
| 71813 | ** P4 points to a blob of data P1 bytes long. Store this |
| 71814 | ** blob in register P2. |
| 71815 | */ |
| 71816 | case OP_Blob: { /* out2-prerelease */ |
| 71817 | assert( pOp->p1 <= SQLITE_MAX_LENGTH ); |
| 71818 | sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0); |
| 71819 | pOut->enc = encoding; |
| 71820 | UPDATE_MAX_BLOBSIZE(pOut); |
| 71821 | break; |
| 71822 | } |
| @@ -71827,19 +71990,20 @@ | |
| 71827 | ** Transfer the values of bound parameter P1 into register P2 |
| 71828 | ** |
| 71829 | ** If the parameter is named, then its name appears in P4. |
| 71830 | ** The P4 value is used by sqlite3_bind_parameter_name(). |
| 71831 | */ |
| 71832 | case OP_Variable: { /* out2-prerelease */ |
| 71833 | Mem *pVar; /* Value being transferred */ |
| 71834 | |
| 71835 | assert( pOp->p1>0 && pOp->p1<=p->nVar ); |
| 71836 | assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] ); |
| 71837 | pVar = &p->aVar[pOp->p1 - 1]; |
| 71838 | if( sqlite3VdbeMemTooBig(pVar) ){ |
| 71839 | goto too_big; |
| 71840 | } |
| 71841 | sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); |
| 71842 | UPDATE_MAX_BLOBSIZE(pOut); |
| 71843 | break; |
| 71844 | } |
| 71845 | |
| @@ -71870,14 +72034,15 @@ | |
| 71870 | assert( pIn1<=&aMem[(p->nMem-p->nCursor)] ); |
| 71871 | assert( memIsValid(pIn1) ); |
| 71872 | memAboutToChange(p, pOut); |
| 71873 | sqlite3VdbeMemMove(pOut, pIn1); |
| 71874 | #ifdef SQLITE_DEBUG |
| 71875 | if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){ |
| 71876 | pOut->pScopyFrom += p1 - pOp->p2; |
| 71877 | } |
| 71878 | #endif |
| 71879 | REGISTER_TRACE(p2++, pOut); |
| 71880 | pIn1++; |
| 71881 | pOut++; |
| 71882 | }while( --n ); |
| 71883 | break; |
| @@ -72012,11 +72177,11 @@ | |
| 72012 | } |
| 72013 | if( db->mallocFailed ) goto no_mem; |
| 72014 | |
| 72015 | /* Return SQLITE_ROW |
| 72016 | */ |
| 72017 | p->pc = pc + 1; |
| 72018 | rc = SQLITE_ROW; |
| 72019 | goto vdbe_return; |
| 72020 | } |
| 72021 | |
| 72022 | /* Opcode: Concat P1 P2 P3 * * |
| @@ -72258,11 +72423,11 @@ | |
| 72258 | REGISTER_TRACE(pOp->p2+i, pArg); |
| 72259 | } |
| 72260 | |
| 72261 | assert( pOp->p4type==P4_FUNCDEF ); |
| 72262 | ctx.pFunc = pOp->p4.pFunc; |
| 72263 | ctx.iOp = pc; |
| 72264 | ctx.pVdbe = p; |
| 72265 | MemSetTypeFlag(ctx.pOut, MEM_Null); |
| 72266 | ctx.fErrorOrAux = 0; |
| 72267 | db->lastRowid = lastRowid; |
| 72268 | (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */ |
| @@ -72272,11 +72437,11 @@ | |
| 72272 | if( ctx.fErrorOrAux ){ |
| 72273 | if( ctx.isError ){ |
| 72274 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut)); |
| 72275 | rc = ctx.isError; |
| 72276 | } |
| 72277 | sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); |
| 72278 | } |
| 72279 | |
| 72280 | /* Copy the result of the function into register P3 */ |
| 72281 | sqlite3VdbeChangeEncoding(ctx.pOut, encoding); |
| 72282 | if( sqlite3VdbeMemTooBig(ctx.pOut) ){ |
| @@ -72401,12 +72566,11 @@ | |
| 72401 | if( (pIn1->flags & MEM_Int)==0 ){ |
| 72402 | if( pOp->p2==0 ){ |
| 72403 | rc = SQLITE_MISMATCH; |
| 72404 | goto abort_due_to_error; |
| 72405 | }else{ |
| 72406 | pc = pOp->p2 - 1; |
| 72407 | break; |
| 72408 | } |
| 72409 | } |
| 72410 | } |
| 72411 | MemSetTypeFlag(pIn1, MEM_Int); |
| 72412 | break; |
| @@ -72588,11 +72752,11 @@ | |
| 72588 | MemSetTypeFlag(pOut, MEM_Null); |
| 72589 | REGISTER_TRACE(pOp->p2, pOut); |
| 72590 | }else{ |
| 72591 | VdbeBranchTaken(2,3); |
| 72592 | if( pOp->p5 & SQLITE_JUMPIFNULL ){ |
| 72593 | pc = pOp->p2-1; |
| 72594 | } |
| 72595 | } |
| 72596 | break; |
| 72597 | } |
| 72598 | }else{ |
| @@ -72639,10 +72803,16 @@ | |
| 72639 | case OP_Lt: res = res<0; break; |
| 72640 | case OP_Le: res = res<=0; break; |
| 72641 | case OP_Gt: res = res>0; break; |
| 72642 | default: res = res>=0; break; |
| 72643 | } |
| 72644 | |
| 72645 | if( pOp->p5 & SQLITE_STOREP2 ){ |
| 72646 | pOut = &aMem[pOp->p2]; |
| 72647 | memAboutToChange(p, pOut); |
| 72648 | MemSetTypeFlag(pOut, MEM_Int); |
| @@ -72649,18 +72819,13 @@ | |
| 72649 | pOut->u.i = res; |
| 72650 | REGISTER_TRACE(pOp->p2, pOut); |
| 72651 | }else{ |
| 72652 | VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3); |
| 72653 | if( res ){ |
| 72654 | pc = pOp->p2-1; |
| 72655 | } |
| 72656 | } |
| 72657 | /* Undo any changes made by applyAffinity() to the input registers. */ |
| 72658 | assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) ); |
| 72659 | pIn1->flags = flags1; |
| 72660 | assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) ); |
| 72661 | pIn3->flags = flags3; |
| 72662 | break; |
| 72663 | } |
| 72664 | |
| 72665 | /* Opcode: Permutation * * * P4 * |
| 72666 | ** |
| @@ -72751,15 +72916,15 @@ | |
| 72751 | ** in the most recent OP_Compare instruction the P1 vector was less than |
| 72752 | ** equal to, or greater than the P2 vector, respectively. |
| 72753 | */ |
| 72754 | case OP_Jump: { /* jump */ |
| 72755 | if( iCompare<0 ){ |
| 72756 | pc = pOp->p1 - 1; VdbeBranchTaken(0,3); |
| 72757 | }else if( iCompare==0 ){ |
| 72758 | pc = pOp->p2 - 1; VdbeBranchTaken(1,3); |
| 72759 | }else{ |
| 72760 | pc = pOp->p3 - 1; VdbeBranchTaken(2,3); |
| 72761 | } |
| 72762 | break; |
| 72763 | } |
| 72764 | |
| 72765 | /* Opcode: And P1 P2 P3 * * |
| @@ -72865,11 +73030,11 @@ | |
| 72865 | */ |
| 72866 | case OP_Once: { /* jump */ |
| 72867 | assert( pOp->p1<p->nOnceFlag ); |
| 72868 | VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2); |
| 72869 | if( p->aOnceFlag[pOp->p1] ){ |
| 72870 | pc = pOp->p2-1; |
| 72871 | }else{ |
| 72872 | p->aOnceFlag[pOp->p1] = 1; |
| 72873 | } |
| 72874 | break; |
| 72875 | } |
| @@ -72900,11 +73065,11 @@ | |
| 72900 | #endif |
| 72901 | if( pOp->opcode==OP_IfNot ) c = !c; |
| 72902 | } |
| 72903 | VdbeBranchTaken(c!=0, 2); |
| 72904 | if( c ){ |
| 72905 | pc = pOp->p2-1; |
| 72906 | } |
| 72907 | break; |
| 72908 | } |
| 72909 | |
| 72910 | /* Opcode: IsNull P1 P2 * * * |
| @@ -72914,11 +73079,11 @@ | |
| 72914 | */ |
| 72915 | case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */ |
| 72916 | pIn1 = &aMem[pOp->p1]; |
| 72917 | VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2); |
| 72918 | if( (pIn1->flags & MEM_Null)!=0 ){ |
| 72919 | pc = pOp->p2 - 1; |
| 72920 | } |
| 72921 | break; |
| 72922 | } |
| 72923 | |
| 72924 | /* Opcode: NotNull P1 P2 * * * |
| @@ -72928,11 +73093,11 @@ | |
| 72928 | */ |
| 72929 | case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */ |
| 72930 | pIn1 = &aMem[pOp->p1]; |
| 72931 | VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2); |
| 72932 | if( (pIn1->flags & MEM_Null)==0 ){ |
| 72933 | pc = pOp->p2 - 1; |
| 72934 | } |
| 72935 | break; |
| 72936 | } |
| 72937 | |
| 72938 | /* Opcode: Column P1 P2 P3 P4 P5 |
| @@ -73142,11 +73307,11 @@ | |
| 73142 | rc = SQLITE_CORRUPT_BKPT; |
| 73143 | goto op_column_error; |
| 73144 | } |
| 73145 | } |
| 73146 | |
| 73147 | /* If after trying to extra new entries from the header, nHdrParsed is |
| 73148 | ** still not up to p2, that means that the record has fewer than p2 |
| 73149 | ** columns. So the result will be either the default value or a NULL. |
| 73150 | */ |
| 73151 | if( pC->nHdrParsed<=p2 ){ |
| 73152 | if( pOp->p4type==P4_MEM ){ |
| @@ -73266,11 +73431,11 @@ | |
| 73266 | u8 *zNewRecord; /* A buffer to hold the data for the new record */ |
| 73267 | Mem *pRec; /* The new record */ |
| 73268 | u64 nData; /* Number of bytes of data space */ |
| 73269 | int nHdr; /* Number of bytes of header space */ |
| 73270 | i64 nByte; /* Data space required for this record */ |
| 73271 | int nZero; /* Number of zero bytes at the end of the record */ |
| 73272 | int nVarint; /* Number of bytes in a varint */ |
| 73273 | u32 serial_type; /* Type field */ |
| 73274 | Mem *pData0; /* First field to be combined into the record */ |
| 73275 | Mem *pLast; /* Last field of the record */ |
| 73276 | int nField; /* Number of fields in the record */ |
| @@ -73358,11 +73523,11 @@ | |
| 73358 | nVarint = sqlite3VarintLen(nHdr); |
| 73359 | nHdr += nVarint; |
| 73360 | if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++; |
| 73361 | } |
| 73362 | nByte = nHdr+nData; |
| 73363 | if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 73364 | goto too_big; |
| 73365 | } |
| 73366 | |
| 73367 | /* Make sure the output register has a buffer large enough to store |
| 73368 | ** the new record. The output register (pOp->p3) is not allowed to |
| @@ -73409,18 +73574,19 @@ | |
| 73409 | ** |
| 73410 | ** Store the number of entries (an integer value) in the table or index |
| 73411 | ** opened by cursor P1 in register P2 |
| 73412 | */ |
| 73413 | #ifndef SQLITE_OMIT_BTREECOUNT |
| 73414 | case OP_Count: { /* out2-prerelease */ |
| 73415 | i64 nEntry; |
| 73416 | BtCursor *pCrsr; |
| 73417 | |
| 73418 | pCrsr = p->apCsr[pOp->p1]->pCursor; |
| 73419 | assert( pCrsr ); |
| 73420 | nEntry = 0; /* Not needed. Only used to silence a warning. */ |
| 73421 | rc = sqlite3BtreeCount(pCrsr, &nEntry); |
| 73422 | pOut->u.i = nEntry; |
| 73423 | break; |
| 73424 | } |
| 73425 | #endif |
| 73426 | |
| @@ -73530,11 +73696,11 @@ | |
| 73530 | if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 73531 | goto vdbe_return; |
| 73532 | } |
| 73533 | db->autoCommit = 1; |
| 73534 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 73535 | p->pc = pc; |
| 73536 | db->autoCommit = 0; |
| 73537 | p->rc = rc = SQLITE_BUSY; |
| 73538 | goto vdbe_return; |
| 73539 | } |
| 73540 | db->isTransactionSavepoint = 0; |
| @@ -73589,11 +73755,11 @@ | |
| 73589 | }else{ |
| 73590 | db->nDeferredCons = pSavepoint->nDeferredCons; |
| 73591 | db->nDeferredImmCons = pSavepoint->nDeferredImmCons; |
| 73592 | } |
| 73593 | |
| 73594 | if( !isTransaction ){ |
| 73595 | rc = sqlite3VtabSavepoint(db, p1, iSavepoint); |
| 73596 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 73597 | } |
| 73598 | } |
| 73599 | } |
| @@ -73649,11 +73815,11 @@ | |
| 73649 | }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 73650 | goto vdbe_return; |
| 73651 | }else{ |
| 73652 | db->autoCommit = (u8)desiredAutoCommit; |
| 73653 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 73654 | p->pc = pc; |
| 73655 | db->autoCommit = (u8)(1-desiredAutoCommit); |
| 73656 | p->rc = rc = SQLITE_BUSY; |
| 73657 | goto vdbe_return; |
| 73658 | } |
| 73659 | } |
| @@ -73726,11 +73892,11 @@ | |
| 73726 | pBt = db->aDb[pOp->p1].pBt; |
| 73727 | |
| 73728 | if( pBt ){ |
| 73729 | rc = sqlite3BtreeBeginTrans(pBt, pOp->p2); |
| 73730 | if( rc==SQLITE_BUSY ){ |
| 73731 | p->pc = pc; |
| 73732 | p->rc = rc = SQLITE_BUSY; |
| 73733 | goto vdbe_return; |
| 73734 | } |
| 73735 | if( rc!=SQLITE_OK ){ |
| 73736 | goto abort_due_to_error; |
| @@ -73805,11 +73971,11 @@ | |
| 73805 | ** |
| 73806 | ** There must be a read-lock on the database (either a transaction |
| 73807 | ** must be started or there must be an open cursor) before |
| 73808 | ** executing this instruction. |
| 73809 | */ |
| 73810 | case OP_ReadCookie: { /* out2-prerelease */ |
| 73811 | int iMeta; |
| 73812 | int iDb; |
| 73813 | int iCookie; |
| 73814 | |
| 73815 | assert( p->bIsReader ); |
| @@ -73819,10 +73985,11 @@ | |
| 73819 | assert( iDb>=0 && iDb<db->nDb ); |
| 73820 | assert( db->aDb[iDb].pBt!=0 ); |
| 73821 | assert( DbMaskTest(p->btreeMask, iDb) ); |
| 73822 | |
| 73823 | sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta); |
| 73824 | pOut->u.i = iMeta; |
| 73825 | break; |
| 73826 | } |
| 73827 | |
| 73828 | /* Opcode: SetCookie P1 P2 P3 * * |
| @@ -74140,11 +74307,11 @@ | |
| 74140 | VdbeCursor *pC; |
| 74141 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 74142 | pC = p->apCsr[pOp->p1]; |
| 74143 | assert( pC->pSorter ); |
| 74144 | if( (pC->seqCount++)==0 ){ |
| 74145 | pc = pOp->p2 - 1; |
| 74146 | } |
| 74147 | break; |
| 74148 | } |
| 74149 | |
| 74150 | /* Opcode: OpenPseudo P1 P2 P3 * * |
| @@ -74317,11 +74484,11 @@ | |
| 74317 | ** loss of information, then special processing is required... */ |
| 74318 | if( (pIn3->flags & MEM_Int)==0 ){ |
| 74319 | if( (pIn3->flags & MEM_Real)==0 ){ |
| 74320 | /* If the P3 value cannot be converted into any kind of a number, |
| 74321 | ** then the seek is not possible, so jump to P2 */ |
| 74322 | pc = pOp->p2 - 1; VdbeBranchTaken(1,2); |
| 74323 | break; |
| 74324 | } |
| 74325 | |
| 74326 | /* If the approximation iKey is larger than the actual real search |
| 74327 | ** term, substitute >= for > and < for <=. e.g. if the search term |
| @@ -74408,11 +74575,11 @@ | |
| 74408 | } |
| 74409 | } |
| 74410 | assert( pOp->p2>0 ); |
| 74411 | VdbeBranchTaken(res!=0,2); |
| 74412 | if( res ){ |
| 74413 | pc = pOp->p2 - 1; |
| 74414 | } |
| 74415 | break; |
| 74416 | } |
| 74417 | |
| 74418 | /* Opcode: Seek P1 P2 * * * |
| @@ -74502,10 +74669,11 @@ | |
| 74502 | */ |
| 74503 | case OP_NoConflict: /* jump, in3 */ |
| 74504 | case OP_NotFound: /* jump, in3 */ |
| 74505 | case OP_Found: { /* jump, in3 */ |
| 74506 | int alreadyExists; |
| 74507 | int ii; |
| 74508 | VdbeCursor *pC; |
| 74509 | int res; |
| 74510 | char *pFree; |
| 74511 | UnpackedRecord *pIdxKey; |
| @@ -74524,11 +74692,11 @@ | |
| 74524 | pC->seekOp = pOp->opcode; |
| 74525 | #endif |
| 74526 | pIn3 = &aMem[pOp->p3]; |
| 74527 | assert( pC->pCursor!=0 ); |
| 74528 | assert( pC->isTable==0 ); |
| 74529 | pFree = 0; /* Not needed. Only used to suppress a compiler warning. */ |
| 74530 | if( pOp->p4.i>0 ){ |
| 74531 | r.pKeyInfo = pC->pKeyInfo; |
| 74532 | r.nField = (u16)pOp->p4.i; |
| 74533 | r.aMem = pIn3; |
| 74534 | for(ii=0; ii<r.nField; ii++){ |
| @@ -74547,25 +74715,24 @@ | |
| 74547 | assert( pIn3->flags & MEM_Blob ); |
| 74548 | ExpandBlob(pIn3); |
| 74549 | sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); |
| 74550 | } |
| 74551 | pIdxKey->default_rc = 0; |
| 74552 | if( pOp->opcode==OP_NoConflict ){ |
| 74553 | /* For the OP_NoConflict opcode, take the jump if any of the |
| 74554 | ** input fields are NULL, since any key with a NULL will not |
| 74555 | ** conflict */ |
| 74556 | for(ii=0; ii<pIdxKey->nField; ii++){ |
| 74557 | if( pIdxKey->aMem[ii].flags & MEM_Null ){ |
| 74558 | pc = pOp->p2 - 1; VdbeBranchTaken(1,2); |
| 74559 | break; |
| 74560 | } |
| 74561 | } |
| 74562 | } |
| 74563 | rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res); |
| 74564 | if( pOp->p4.i==0 ){ |
| 74565 | sqlite3DbFree(db, pFree); |
| 74566 | } |
| 74567 | if( rc!=SQLITE_OK ){ |
| 74568 | break; |
| 74569 | } |
| 74570 | pC->seekResult = res; |
| 74571 | alreadyExists = (res==0); |
| @@ -74572,14 +74739,14 @@ | |
| 74572 | pC->nullRow = 1-alreadyExists; |
| 74573 | pC->deferredMoveto = 0; |
| 74574 | pC->cacheStatus = CACHE_STALE; |
| 74575 | if( pOp->opcode==OP_Found ){ |
| 74576 | VdbeBranchTaken(alreadyExists!=0,2); |
| 74577 | if( alreadyExists ) pc = pOp->p2 - 1; |
| 74578 | }else{ |
| 74579 | VdbeBranchTaken(alreadyExists==0,2); |
| 74580 | if( !alreadyExists ) pc = pOp->p2 - 1; |
| 74581 | } |
| 74582 | break; |
| 74583 | } |
| 74584 | |
| 74585 | /* Opcode: NotExists P1 P2 P3 * * |
| @@ -74624,14 +74791,12 @@ | |
| 74624 | pC->movetoTarget = iKey; /* Used by OP_Delete */ |
| 74625 | pC->nullRow = 0; |
| 74626 | pC->cacheStatus = CACHE_STALE; |
| 74627 | pC->deferredMoveto = 0; |
| 74628 | VdbeBranchTaken(res!=0,2); |
| 74629 | if( res!=0 ){ |
| 74630 | pc = pOp->p2 - 1; |
| 74631 | } |
| 74632 | pC->seekResult = res; |
| 74633 | break; |
| 74634 | } |
| 74635 | |
| 74636 | /* Opcode: Sequence P1 P2 * * * |
| 74637 | ** Synopsis: r[P2]=cursor[P1].ctr++ |
| @@ -74639,13 +74804,14 @@ | |
| 74639 | ** Find the next available sequence number for cursor P1. |
| 74640 | ** Write the sequence number into register P2. |
| 74641 | ** The sequence number on the cursor is incremented after this |
| 74642 | ** instruction. |
| 74643 | */ |
| 74644 | case OP_Sequence: { /* out2-prerelease */ |
| 74645 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 74646 | assert( p->apCsr[pOp->p1]!=0 ); |
| 74647 | pOut->u.i = p->apCsr[pOp->p1]->seqCount++; |
| 74648 | break; |
| 74649 | } |
| 74650 | |
| 74651 | |
| @@ -74662,20 +74828,21 @@ | |
| 74662 | ** allowed to be less than this value. When this value reaches its maximum, |
| 74663 | ** an SQLITE_FULL error is generated. The P3 register is updated with the ' |
| 74664 | ** generated record number. This P3 mechanism is used to help implement the |
| 74665 | ** AUTOINCREMENT feature. |
| 74666 | */ |
| 74667 | case OP_NewRowid: { /* out2-prerelease */ |
| 74668 | i64 v; /* The new rowid */ |
| 74669 | VdbeCursor *pC; /* Cursor of table to get the new rowid */ |
| 74670 | int res; /* Result of an sqlite3BtreeLast() */ |
| 74671 | int cnt; /* Counter to limit the number of searches */ |
| 74672 | Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ |
| 74673 | VdbeFrame *pFrame; /* Root frame of VDBE */ |
| 74674 | |
| 74675 | v = 0; |
| 74676 | res = 0; |
| 74677 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 74678 | pC = p->apCsr[pOp->p1]; |
| 74679 | assert( pC!=0 ); |
| 74680 | if( NEVER(pC->pCursor==0) ){ |
| 74681 | /* The zero initialization above is all that is needed */ |
| @@ -74985,13 +75152,11 @@ | |
| 74985 | pIn3 = &aMem[pOp->p3]; |
| 74986 | nKeyCol = pOp->p4.i; |
| 74987 | res = 0; |
| 74988 | rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res); |
| 74989 | VdbeBranchTaken(res!=0,2); |
| 74990 | if( res ){ |
| 74991 | pc = pOp->p2-1; |
| 74992 | } |
| 74993 | break; |
| 74994 | }; |
| 74995 | |
| 74996 | /* Opcode: SorterData P1 P2 P3 * * |
| 74997 | ** Synopsis: r[P2]=data |
| @@ -75116,16 +75281,17 @@ | |
| 75116 | ** |
| 75117 | ** P1 can be either an ordinary table or a virtual table. There used to |
| 75118 | ** be a separate OP_VRowid opcode for use with virtual tables, but this |
| 75119 | ** one opcode now works for both table types. |
| 75120 | */ |
| 75121 | case OP_Rowid: { /* out2-prerelease */ |
| 75122 | VdbeCursor *pC; |
| 75123 | i64 v; |
| 75124 | sqlite3_vtab *pVtab; |
| 75125 | const sqlite3_module *pModule; |
| 75126 | |
| 75127 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 75128 | pC = p->apCsr[pOp->p1]; |
| 75129 | assert( pC!=0 ); |
| 75130 | assert( pC->pseudoTableReg==0 || pC->nullRow ); |
| 75131 | if( pC->nullRow ){ |
| @@ -75174,11 +75340,11 @@ | |
| 75174 | sqlite3BtreeClearCursor(pC->pCursor); |
| 75175 | } |
| 75176 | break; |
| 75177 | } |
| 75178 | |
| 75179 | /* Opcode: Last P1 P2 * * * |
| 75180 | ** |
| 75181 | ** The next use of the Rowid or Column or Prev instruction for P1 |
| 75182 | ** will refer to the last entry in the database table or index. |
| 75183 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 75184 | ** If P2 is 0 or if the table or index is not empty, fall through |
| @@ -75201,16 +75367,17 @@ | |
| 75201 | assert( pCrsr!=0 ); |
| 75202 | rc = sqlite3BtreeLast(pCrsr, &res); |
| 75203 | pC->nullRow = (u8)res; |
| 75204 | pC->deferredMoveto = 0; |
| 75205 | pC->cacheStatus = CACHE_STALE; |
| 75206 | #ifdef SQLITE_DEBUG |
| 75207 | pC->seekOp = OP_Last; |
| 75208 | #endif |
| 75209 | if( pOp->p2>0 ){ |
| 75210 | VdbeBranchTaken(res!=0,2); |
| 75211 | if( res ) pc = pOp->p2 - 1; |
| 75212 | } |
| 75213 | break; |
| 75214 | } |
| 75215 | |
| 75216 | |
| @@ -75270,13 +75437,11 @@ | |
| 75270 | pC->cacheStatus = CACHE_STALE; |
| 75271 | } |
| 75272 | pC->nullRow = (u8)res; |
| 75273 | assert( pOp->p2>0 && pOp->p2<p->nOp ); |
| 75274 | VdbeBranchTaken(res!=0,2); |
| 75275 | if( res ){ |
| 75276 | pc = pOp->p2 - 1; |
| 75277 | } |
| 75278 | break; |
| 75279 | } |
| 75280 | |
| 75281 | /* Opcode: Next P1 P2 P3 P4 P5 |
| 75282 | ** |
| @@ -75383,15 +75548,15 @@ | |
| 75383 | next_tail: |
| 75384 | pC->cacheStatus = CACHE_STALE; |
| 75385 | VdbeBranchTaken(res==0,2); |
| 75386 | if( res==0 ){ |
| 75387 | pC->nullRow = 0; |
| 75388 | pc = pOp->p2 - 1; |
| 75389 | p->aCounter[pOp->p5]++; |
| 75390 | #ifdef SQLITE_TEST |
| 75391 | sqlite3_search_count++; |
| 75392 | #endif |
| 75393 | }else{ |
| 75394 | pC->nullRow = 1; |
| 75395 | } |
| 75396 | goto check_for_interrupt; |
| 75397 | } |
| @@ -75495,15 +75660,16 @@ | |
| 75495 | ** the end of the index key pointed to by cursor P1. This integer should be |
| 75496 | ** the rowid of the table entry to which this index entry points. |
| 75497 | ** |
| 75498 | ** See also: Rowid, MakeRecord. |
| 75499 | */ |
| 75500 | case OP_IdxRowid: { /* out2-prerelease */ |
| 75501 | BtCursor *pCrsr; |
| 75502 | VdbeCursor *pC; |
| 75503 | i64 rowid; |
| 75504 | |
| 75505 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 75506 | pC = p->apCsr[pOp->p1]; |
| 75507 | assert( pC!=0 ); |
| 75508 | pCrsr = pC->pCursor; |
| 75509 | assert( pCrsr!=0 ); |
| @@ -75612,13 +75778,11 @@ | |
| 75612 | }else{ |
| 75613 | assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT ); |
| 75614 | res++; |
| 75615 | } |
| 75616 | VdbeBranchTaken(res>0,2); |
| 75617 | if( res>0 ){ |
| 75618 | pc = pOp->p2 - 1 ; |
| 75619 | } |
| 75620 | break; |
| 75621 | } |
| 75622 | |
| 75623 | /* Opcode: Destroy P1 P2 P3 * * |
| 75624 | ** |
| @@ -75638,15 +75802,16 @@ | |
| 75638 | ** the last one in the database) then a zero is stored in register P2. |
| 75639 | ** If AUTOVACUUM is disabled then a zero is stored in register P2. |
| 75640 | ** |
| 75641 | ** See also: Clear |
| 75642 | */ |
| 75643 | case OP_Destroy: { /* out2-prerelease */ |
| 75644 | int iMoved; |
| 75645 | int iDb; |
| 75646 | |
| 75647 | assert( p->readOnly==0 ); |
| 75648 | pOut->flags = MEM_Null; |
| 75649 | if( db->nVdbeRead > db->nVDestroy+1 ){ |
| 75650 | rc = SQLITE_LOCKED; |
| 75651 | p->errorAction = OE_Abort; |
| 75652 | }else{ |
| @@ -75751,16 +75916,17 @@ | |
| 75751 | ** P1>1. Write the root page number of the new table into |
| 75752 | ** register P2. |
| 75753 | ** |
| 75754 | ** See documentation on OP_CreateTable for additional information. |
| 75755 | */ |
| 75756 | case OP_CreateIndex: /* out2-prerelease */ |
| 75757 | case OP_CreateTable: { /* out2-prerelease */ |
| 75758 | int pgno; |
| 75759 | int flags; |
| 75760 | Db *pDb; |
| 75761 | |
| 75762 | pgno = 0; |
| 75763 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 75764 | assert( DbMaskTest(p->btreeMask, pOp->p1) ); |
| 75765 | assert( p->readOnly==0 ); |
| 75766 | pDb = &db->aDb[pOp->p1]; |
| @@ -75982,16 +76148,16 @@ | |
| 75982 | if( (pIn1->flags & MEM_RowSet)==0 |
| 75983 | || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0 |
| 75984 | ){ |
| 75985 | /* The boolean index is empty */ |
| 75986 | sqlite3VdbeMemSetNull(pIn1); |
| 75987 | pc = pOp->p2 - 1; |
| 75988 | VdbeBranchTaken(1,2); |
| 75989 | }else{ |
| 75990 | /* A value was pulled from the index */ |
| 75991 | sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); |
| 75992 | VdbeBranchTaken(0,2); |
| 75993 | } |
| 75994 | goto check_for_interrupt; |
| 75995 | } |
| 75996 | |
| 75997 | /* Opcode: RowSetTest P1 P2 P3 P4 |
| @@ -76038,14 +76204,11 @@ | |
| 76038 | assert( pOp->p4type==P4_INT32 ); |
| 76039 | assert( iSet==-1 || iSet>=0 ); |
| 76040 | if( iSet ){ |
| 76041 | exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i); |
| 76042 | VdbeBranchTaken(exists!=0,2); |
| 76043 | if( exists ){ |
| 76044 | pc = pOp->p2 - 1; |
| 76045 | break; |
| 76046 | } |
| 76047 | } |
| 76048 | if( iSet>=0 ){ |
| 76049 | sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i); |
| 76050 | } |
| 76051 | break; |
| @@ -76130,11 +76293,11 @@ | |
| 76130 | pRt->u.pFrame = pFrame; |
| 76131 | |
| 76132 | pFrame->v = p; |
| 76133 | pFrame->nChildMem = nMem; |
| 76134 | pFrame->nChildCsr = pProgram->nCsr; |
| 76135 | pFrame->pc = pc; |
| 76136 | pFrame->aMem = p->aMem; |
| 76137 | pFrame->nMem = p->nMem; |
| 76138 | pFrame->apCsr = p->apCsr; |
| 76139 | pFrame->nCursor = p->nCursor; |
| 76140 | pFrame->aOp = p->aOp; |
| @@ -76153,11 +76316,11 @@ | |
| 76153 | } |
| 76154 | }else{ |
| 76155 | pFrame = pRt->u.pFrame; |
| 76156 | assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem ); |
| 76157 | assert( pProgram->nCsr==pFrame->nChildCsr ); |
| 76158 | assert( pc==pFrame->pc ); |
| 76159 | } |
| 76160 | |
| 76161 | p->nFrame++; |
| 76162 | pFrame->pParent = p->pFrame; |
| 76163 | pFrame->lastRowid = lastRowid; |
| @@ -76174,11 +76337,11 @@ | |
| 76174 | p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 76175 | p->nOnceFlag = pProgram->nOnce; |
| 76176 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 76177 | p->anExec = 0; |
| 76178 | #endif |
| 76179 | pc = -1; |
| 76180 | memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 76181 | |
| 76182 | break; |
| 76183 | } |
| 76184 | |
| @@ -76192,13 +76355,14 @@ | |
| 76192 | ** |
| 76193 | ** The address of the cell in the parent frame is determined by adding |
| 76194 | ** the value of the P1 argument to the value of the P1 argument to the |
| 76195 | ** calling OP_Program instruction. |
| 76196 | */ |
| 76197 | case OP_Param: { /* out2-prerelease */ |
| 76198 | VdbeFrame *pFrame; |
| 76199 | Mem *pIn; |
| 76200 | pFrame = p->pFrame; |
| 76201 | pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1]; |
| 76202 | sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem); |
| 76203 | break; |
| 76204 | } |
| @@ -76238,14 +76402,14 @@ | |
| 76238 | ** (immediate foreign key constraint violations). |
| 76239 | */ |
| 76240 | case OP_FkIfZero: { /* jump */ |
| 76241 | if( pOp->p1 ){ |
| 76242 | VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2); |
| 76243 | if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1; |
| 76244 | }else{ |
| 76245 | VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2); |
| 76246 | if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1; |
| 76247 | } |
| 76248 | break; |
| 76249 | } |
| 76250 | #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */ |
| 76251 | |
| @@ -76292,13 +76456,11 @@ | |
| 76292 | */ |
| 76293 | case OP_IfPos: { /* jump, in1 */ |
| 76294 | pIn1 = &aMem[pOp->p1]; |
| 76295 | assert( pIn1->flags&MEM_Int ); |
| 76296 | VdbeBranchTaken( pIn1->u.i>0, 2); |
| 76297 | if( pIn1->u.i>0 ){ |
| 76298 | pc = pOp->p2 - 1; |
| 76299 | } |
| 76300 | break; |
| 76301 | } |
| 76302 | |
| 76303 | /* Opcode: IfNeg P1 P2 P3 * * |
| 76304 | ** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2 |
| @@ -76309,13 +76471,11 @@ | |
| 76309 | case OP_IfNeg: { /* jump, in1 */ |
| 76310 | pIn1 = &aMem[pOp->p1]; |
| 76311 | assert( pIn1->flags&MEM_Int ); |
| 76312 | pIn1->u.i += pOp->p3; |
| 76313 | VdbeBranchTaken(pIn1->u.i<0, 2); |
| 76314 | if( pIn1->u.i<0 ){ |
| 76315 | pc = pOp->p2 - 1; |
| 76316 | } |
| 76317 | break; |
| 76318 | } |
| 76319 | |
| 76320 | /* Opcode: IfNotZero P1 P2 P3 * * |
| 76321 | ** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2 |
| @@ -76328,11 +76488,11 @@ | |
| 76328 | pIn1 = &aMem[pOp->p1]; |
| 76329 | assert( pIn1->flags&MEM_Int ); |
| 76330 | VdbeBranchTaken(pIn1->u.i<0, 2); |
| 76331 | if( pIn1->u.i ){ |
| 76332 | pIn1->u.i += pOp->p3; |
| 76333 | pc = pOp->p2 - 1; |
| 76334 | } |
| 76335 | break; |
| 76336 | } |
| 76337 | |
| 76338 | /* Opcode: DecrJumpZero P1 P2 * * * |
| @@ -76344,13 +76504,11 @@ | |
| 76344 | case OP_DecrJumpZero: { /* jump, in1 */ |
| 76345 | pIn1 = &aMem[pOp->p1]; |
| 76346 | assert( pIn1->flags&MEM_Int ); |
| 76347 | pIn1->u.i--; |
| 76348 | VdbeBranchTaken(pIn1->u.i==0, 2); |
| 76349 | if( pIn1->u.i==0 ){ |
| 76350 | pc = pOp->p2 - 1; |
| 76351 | } |
| 76352 | break; |
| 76353 | } |
| 76354 | |
| 76355 | |
| 76356 | /* Opcode: JumpZeroIncr P1 P2 * * * |
| @@ -76362,13 +76520,11 @@ | |
| 76362 | */ |
| 76363 | case OP_JumpZeroIncr: { /* jump, in1 */ |
| 76364 | pIn1 = &aMem[pOp->p1]; |
| 76365 | assert( pIn1->flags&MEM_Int ); |
| 76366 | VdbeBranchTaken(pIn1->u.i==0, 2); |
| 76367 | if( (pIn1->u.i++)==0 ){ |
| 76368 | pc = pOp->p2 - 1; |
| 76369 | } |
| 76370 | break; |
| 76371 | } |
| 76372 | |
| 76373 | /* Opcode: AggStep * P2 P3 P4 P5 |
| 76374 | ** Synopsis: accum=r[P3] step(r[P2@P5]) |
| @@ -76406,11 +76562,11 @@ | |
| 76406 | pMem->n++; |
| 76407 | sqlite3VdbeMemInit(&t, db, MEM_Null); |
| 76408 | ctx.pOut = &t; |
| 76409 | ctx.isError = 0; |
| 76410 | ctx.pVdbe = p; |
| 76411 | ctx.iOp = pc; |
| 76412 | ctx.skipFlag = 0; |
| 76413 | (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */ |
| 76414 | if( ctx.isError ){ |
| 76415 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t)); |
| 76416 | rc = ctx.isError; |
| @@ -76501,19 +76657,20 @@ | |
| 76501 | ** |
| 76502 | ** If changing into or out of WAL mode the procedure is more complicated. |
| 76503 | ** |
| 76504 | ** Write a string containing the final journal-mode to register P2. |
| 76505 | */ |
| 76506 | case OP_JournalMode: { /* out2-prerelease */ |
| 76507 | Btree *pBt; /* Btree to change journal mode of */ |
| 76508 | Pager *pPager; /* Pager associated with pBt */ |
| 76509 | int eNew; /* New journal mode */ |
| 76510 | int eOld; /* The old journal mode */ |
| 76511 | #ifndef SQLITE_OMIT_WAL |
| 76512 | const char *zFilename; /* Name of database file for pPager */ |
| 76513 | #endif |
| 76514 | |
| 76515 | eNew = pOp->p3; |
| 76516 | assert( eNew==PAGER_JOURNALMODE_DELETE |
| 76517 | || eNew==PAGER_JOURNALMODE_TRUNCATE |
| 76518 | || eNew==PAGER_JOURNALMODE_PERSIST |
| 76519 | || eNew==PAGER_JOURNALMODE_OFF |
| @@ -76626,12 +76783,12 @@ | |
| 76626 | assert( p->readOnly==0 ); |
| 76627 | pBt = db->aDb[pOp->p1].pBt; |
| 76628 | rc = sqlite3BtreeIncrVacuum(pBt); |
| 76629 | VdbeBranchTaken(rc==SQLITE_DONE,2); |
| 76630 | if( rc==SQLITE_DONE ){ |
| 76631 | pc = pOp->p2 - 1; |
| 76632 | rc = SQLITE_OK; |
| 76633 | } |
| 76634 | break; |
| 76635 | } |
| 76636 | #endif |
| 76637 | |
| @@ -76780,12 +76937,13 @@ | |
| 76780 | pCur = allocateCursor(p, pOp->p1, 0, -1, 0); |
| 76781 | if( pCur ){ |
| 76782 | pCur->pVtabCursor = pVtabCursor; |
| 76783 | pVtab->nRef++; |
| 76784 | }else{ |
| 76785 | db->mallocFailed = 1; |
| 76786 | pModule->xClose(pVtabCursor); |
| 76787 | } |
| 76788 | } |
| 76789 | break; |
| 76790 | } |
| 76791 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| @@ -76837,29 +76995,23 @@ | |
| 76837 | assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int ); |
| 76838 | nArg = (int)pArgc->u.i; |
| 76839 | iQuery = (int)pQuery->u.i; |
| 76840 | |
| 76841 | /* Invoke the xFilter method */ |
| 76842 | { |
| 76843 | res = 0; |
| 76844 | apArg = p->apArg; |
| 76845 | for(i = 0; i<nArg; i++){ |
| 76846 | apArg[i] = &pArgc[i+1]; |
| 76847 | } |
| 76848 | |
| 76849 | rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); |
| 76850 | sqlite3VtabImportErrmsg(p, pVtab); |
| 76851 | if( rc==SQLITE_OK ){ |
| 76852 | res = pModule->xEof(pVtabCursor); |
| 76853 | } |
| 76854 | VdbeBranchTaken(res!=0,2); |
| 76855 | if( res ){ |
| 76856 | pc = pOp->p2 - 1; |
| 76857 | } |
| 76858 | } |
| 76859 | pCur->nullRow = 0; |
| 76860 | |
| 76861 | break; |
| 76862 | } |
| 76863 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 76864 | |
| 76865 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| @@ -76942,11 +77094,11 @@ | |
| 76942 | res = pModule->xEof(pCur->pVtabCursor); |
| 76943 | } |
| 76944 | VdbeBranchTaken(!res,2); |
| 76945 | if( !res ){ |
| 76946 | /* If there is data, jump to P2 */ |
| 76947 | pc = pOp->p2 - 1; |
| 76948 | } |
| 76949 | goto check_for_interrupt; |
| 76950 | } |
| 76951 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 76952 | |
| @@ -77065,11 +77217,12 @@ | |
| 77065 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 77066 | /* Opcode: Pagecount P1 P2 * * * |
| 77067 | ** |
| 77068 | ** Write the current number of pages in database P1 to memory cell P2. |
| 77069 | */ |
| 77070 | case OP_Pagecount: { /* out2-prerelease */ |
| 77071 | pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt); |
| 77072 | break; |
| 77073 | } |
| 77074 | #endif |
| 77075 | |
| @@ -77081,14 +77234,15 @@ | |
| 77081 | ** Do not let the maximum page count fall below the current page count and |
| 77082 | ** do not change the maximum page count value if P3==0. |
| 77083 | ** |
| 77084 | ** Store the maximum page count after the change in register P2. |
| 77085 | */ |
| 77086 | case OP_MaxPgcnt: { /* out2-prerelease */ |
| 77087 | unsigned int newMax; |
| 77088 | Btree *pBt; |
| 77089 | |
| 77090 | pBt = db->aDb[pOp->p1].pBt; |
| 77091 | newMax = 0; |
| 77092 | if( pOp->p3 ){ |
| 77093 | newMax = sqlite3BtreeLastPage(pBt); |
| 77094 | if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3; |
| @@ -77113,13 +77267,10 @@ | |
| 77113 | */ |
| 77114 | case OP_Init: { /* jump */ |
| 77115 | char *zTrace; |
| 77116 | char *z; |
| 77117 | |
| 77118 | if( pOp->p2 ){ |
| 77119 | pc = pOp->p2 - 1; |
| 77120 | } |
| 77121 | #ifndef SQLITE_OMIT_TRACE |
| 77122 | if( db->xTrace |
| 77123 | && !p->doingRerun |
| 77124 | && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 77125 | ){ |
| @@ -77143,10 +77294,11 @@ | |
| 77143 | ){ |
| 77144 | sqlite3DebugPrintf("SQL-trace: %s\n", zTrace); |
| 77145 | } |
| 77146 | #endif /* SQLITE_DEBUG */ |
| 77147 | #endif /* SQLITE_OMIT_TRACE */ |
| 77148 | break; |
| 77149 | } |
| 77150 | |
| 77151 | |
| 77152 | /* Opcode: Noop * * * * * |
| @@ -77174,31 +77326,31 @@ | |
| 77174 | } |
| 77175 | |
| 77176 | #ifdef VDBE_PROFILE |
| 77177 | { |
| 77178 | u64 endTime = sqlite3Hwtime(); |
| 77179 | if( endTime>start ) pOp->cycles += endTime - start; |
| 77180 | pOp->cnt++; |
| 77181 | } |
| 77182 | #endif |
| 77183 | |
| 77184 | /* The following code adds nothing to the actual functionality |
| 77185 | ** of the program. It is only here for testing and debugging. |
| 77186 | ** On the other hand, it does burn CPU cycles every time through |
| 77187 | ** the evaluator loop. So we can leave it out when NDEBUG is defined. |
| 77188 | */ |
| 77189 | #ifndef NDEBUG |
| 77190 | assert( pc>=-1 && pc<p->nOp ); |
| 77191 | |
| 77192 | #ifdef SQLITE_DEBUG |
| 77193 | if( db->flags & SQLITE_VdbeTrace ){ |
| 77194 | if( rc!=0 ) printf("rc=%d\n",rc); |
| 77195 | if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){ |
| 77196 | registerTrace(pOp->p2, &aMem[pOp->p2]); |
| 77197 | } |
| 77198 | if( pOp->opflags & OPFLG_OUT3 ){ |
| 77199 | registerTrace(pOp->p3, &aMem[pOp->p3]); |
| 77200 | } |
| 77201 | } |
| 77202 | #endif /* SQLITE_DEBUG */ |
| 77203 | #endif /* NDEBUG */ |
| 77204 | } /* The end of the for(;;) loop the loops through opcodes */ |
| @@ -77209,11 +77361,11 @@ | |
| 77209 | vdbe_error_halt: |
| 77210 | assert( rc ); |
| 77211 | p->rc = rc; |
| 77212 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 77213 | sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 77214 | pc, p->zSql, p->zErrMsg); |
| 77215 | sqlite3VdbeHalt(p); |
| 77216 | if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; |
| 77217 | rc = SQLITE_ERROR; |
| 77218 | if( resetSchemaOnFault>0 ){ |
| 77219 | sqlite3ResetOneSchema(db, resetSchemaOnFault-1); |
| @@ -78035,20 +78187,23 @@ | |
| 78035 | ** |
| 78036 | ** In both cases, the effects of the main thread seeing (bDone==0) even |
| 78037 | ** after the thread has finished are not dire. So we don't worry about |
| 78038 | ** memory barriers and such here. |
| 78039 | */ |
| 78040 | struct SortSubtask { |
| 78041 | SQLiteThread *pThread; /* Background thread, if any */ |
| 78042 | int bDone; /* Set if thread is finished but not joined */ |
| 78043 | VdbeSorter *pSorter; /* Sorter that owns this sub-task */ |
| 78044 | UnpackedRecord *pUnpacked; /* Space to unpack a record */ |
| 78045 | SorterList list; /* List for thread to write to a PMA */ |
| 78046 | int nPMA; /* Number of PMAs currently in file */ |
| 78047 | SorterFile file; /* Temp file for level-0 PMAs */ |
| 78048 | SorterFile file2; /* Space for other PMAs */ |
| 78049 | }; |
| 78050 | |
| 78051 | /* |
| 78052 | ** Main sorter structure. A single instance of this is allocated for each |
| 78053 | ** sorter cursor created by the VDBE. |
| 78054 | ** |
| @@ -78072,12 +78227,16 @@ | |
| 78072 | int nMemory; /* Size of list.aMemory allocation in bytes */ |
| 78073 | u8 bUsePMA; /* True if one or more PMAs created */ |
| 78074 | u8 bUseThreads; /* True to use background threads */ |
| 78075 | u8 iPrev; /* Previous thread used to flush PMA */ |
| 78076 | u8 nTask; /* Size of aTask[] array */ |
| 78077 | SortSubtask aTask[1]; /* One or more subtasks */ |
| 78078 | }; |
| 78079 | |
| 78080 | /* |
| 78081 | ** An instance of the following object is used to read records out of a |
| 78082 | ** PMA, in sorted order. The next key to be read is cached in nKey/aKey. |
| 78083 | ** aKey might point into aMap or into aBuffer. If neither of those locations |
| @@ -78486,35 +78645,165 @@ | |
| 78486 | rc = vdbePmaReaderNext(pReadr); |
| 78487 | } |
| 78488 | return rc; |
| 78489 | } |
| 78490 | |
| 78491 | |
| 78492 | /* |
| 78493 | ** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2, |
| 78494 | ** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences |
| 78495 | ** used by the comparison. Return the result of the comparison. |
| 78496 | ** |
| 78497 | ** Before returning, object (pTask->pUnpacked) is populated with the |
| 78498 | ** unpacked version of key2. Or, if pKey2 is passed a NULL pointer, then it |
| 78499 | ** is assumed that the (pTask->pUnpacked) structure already contains the |
| 78500 | ** unpacked key to use as key2. |
| 78501 | ** |
| 78502 | ** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set |
| 78503 | ** to SQLITE_NOMEM. |
| 78504 | */ |
| 78505 | static int vdbeSorterCompare( |
| 78506 | SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ |
| 78507 | const void *pKey1, int nKey1, /* Left side of comparison */ |
| 78508 | const void *pKey2, int nKey2 /* Right side of comparison */ |
| 78509 | ){ |
| 78510 | UnpackedRecord *r2 = pTask->pUnpacked; |
| 78511 | if( pKey2 ){ |
| 78512 | sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); |
| 78513 | } |
| 78514 | return sqlite3VdbeRecordCompare(nKey1, pKey1, r2); |
| 78515 | } |
| 78516 | |
| 78517 | /* |
| 78518 | ** Initialize the temporary index cursor just opened as a sorter cursor. |
| 78519 | ** |
| 78520 | ** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField) |
| @@ -78579,13 +78868,17 @@ | |
| 78579 | rc = SQLITE_NOMEM; |
| 78580 | }else{ |
| 78581 | pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz); |
| 78582 | memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo); |
| 78583 | pKeyInfo->db = 0; |
| 78584 | if( nField && nWorker==0 ) pKeyInfo->nField = nField; |
| 78585 | pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt); |
| 78586 | pSorter->nTask = nWorker + 1; |
| 78587 | pSorter->bUseThreads = (pSorter->nTask>1); |
| 78588 | pSorter->db = db; |
| 78589 | for(i=0; i<pSorter->nTask; i++){ |
| 78590 | SortSubtask *pTask = &pSorter->aTask[i]; |
| 78591 | pTask->pSorter = pSorter; |
| @@ -78607,10 +78900,16 @@ | |
| 78607 | pSorter->nMemory = pgsz; |
| 78608 | pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz); |
| 78609 | if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM; |
| 78610 | } |
| 78611 | } |
| 78612 | } |
| 78613 | |
| 78614 | return rc; |
| 78615 | } |
| 78616 | #undef nWorker /* Defined at the top of this function */ |
| @@ -78631,34 +78930,28 @@ | |
| 78631 | ** Free all resources owned by the object indicated by argument pTask. All |
| 78632 | ** fields of *pTask are zeroed before returning. |
| 78633 | */ |
| 78634 | static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){ |
| 78635 | sqlite3DbFree(db, pTask->pUnpacked); |
| 78636 | pTask->pUnpacked = 0; |
| 78637 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 78638 | /* pTask->list.aMemory can only be non-zero if it was handed memory |
| 78639 | ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */ |
| 78640 | if( pTask->list.aMemory ){ |
| 78641 | sqlite3_free(pTask->list.aMemory); |
| 78642 | pTask->list.aMemory = 0; |
| 78643 | }else |
| 78644 | #endif |
| 78645 | { |
| 78646 | assert( pTask->list.aMemory==0 ); |
| 78647 | vdbeSorterRecordFree(0, pTask->list.pList); |
| 78648 | } |
| 78649 | pTask->list.pList = 0; |
| 78650 | if( pTask->file.pFd ){ |
| 78651 | sqlite3OsCloseFree(pTask->file.pFd); |
| 78652 | pTask->file.pFd = 0; |
| 78653 | pTask->file.iEof = 0; |
| 78654 | } |
| 78655 | if( pTask->file2.pFd ){ |
| 78656 | sqlite3OsCloseFree(pTask->file2.pFd); |
| 78657 | pTask->file2.pFd = 0; |
| 78658 | pTask->file2.iEof = 0; |
| 78659 | } |
| 78660 | } |
| 78661 | |
| 78662 | #ifdef SQLITE_DEBUG_SORTER_THREADS |
| 78663 | static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){ |
| 78664 | i64 t; |
| @@ -78834,10 +79127,11 @@ | |
| 78834 | vdbeMergeEngineFree(pSorter->pMerger); |
| 78835 | pSorter->pMerger = 0; |
| 78836 | for(i=0; i<pSorter->nTask; i++){ |
| 78837 | SortSubtask *pTask = &pSorter->aTask[i]; |
| 78838 | vdbeSortSubtaskCleanup(db, pTask); |
| 78839 | } |
| 78840 | if( pSorter->list.aMemory==0 ){ |
| 78841 | vdbeSorterRecordFree(0, pSorter->list.pList); |
| 78842 | } |
| 78843 | pSorter->list.pList = 0; |
| @@ -78943,31 +79237,45 @@ | |
| 78943 | SorterRecord *p2, /* Second list to merge */ |
| 78944 | SorterRecord **ppOut /* OUT: Head of merged list */ |
| 78945 | ){ |
| 78946 | SorterRecord *pFinal = 0; |
| 78947 | SorterRecord **pp = &pFinal; |
| 78948 | void *pVal2 = p2 ? SRVAL(p2) : 0; |
| 78949 | |
| 78950 | while( p1 && p2 ){ |
| 78951 | int res; |
| 78952 | res = vdbeSorterCompare(pTask, SRVAL(p1), p1->nVal, pVal2, p2->nVal); |
| 78953 | if( res<=0 ){ |
| 78954 | *pp = p1; |
| 78955 | pp = &p1->u.pNext; |
| 78956 | p1 = p1->u.pNext; |
| 78957 | pVal2 = 0; |
| 78958 | }else{ |
| 78959 | *pp = p2; |
| 78960 | pp = &p2->u.pNext; |
| 78961 | p2 = p2->u.pNext; |
| 78962 | if( p2==0 ) break; |
| 78963 | pVal2 = SRVAL(p2); |
| 78964 | } |
| 78965 | } |
| 78966 | *pp = p1 ? p1 : p2; |
| 78967 | *ppOut = pFinal; |
| 78968 | } |
| 78969 | |
| 78970 | /* |
| 78971 | ** Sort the linked list of records headed at pTask->pList. Return |
| 78972 | ** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if |
| 78973 | ** an error occurs. |
| @@ -78979,16 +79287,18 @@ | |
| 78979 | int rc; |
| 78980 | |
| 78981 | rc = vdbeSortAllocUnpacked(pTask); |
| 78982 | if( rc!=SQLITE_OK ) return rc; |
| 78983 | |
| 78984 | aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *)); |
| 78985 | if( !aSlot ){ |
| 78986 | return SQLITE_NOMEM; |
| 78987 | } |
| 78988 | |
| 78989 | p = pList->pList; |
| 78990 | while( p ){ |
| 78991 | SorterRecord *pNext; |
| 78992 | if( pList->aMemory ){ |
| 78993 | if( (u8*)p==pList->aMemory ){ |
| 78994 | pNext = 0; |
| @@ -79198,28 +79508,27 @@ | |
| 79198 | /* Update contents of aTree[] */ |
| 79199 | if( rc==SQLITE_OK ){ |
| 79200 | int i; /* Index of aTree[] to recalculate */ |
| 79201 | PmaReader *pReadr1; /* First PmaReader to compare */ |
| 79202 | PmaReader *pReadr2; /* Second PmaReader to compare */ |
| 79203 | u8 *pKey2; /* To pReadr2->aKey, or 0 if record cached */ |
| 79204 | |
| 79205 | /* Find the first two PmaReaders to compare. The one that was just |
| 79206 | ** advanced (iPrev) and the one next to it in the array. */ |
| 79207 | pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)]; |
| 79208 | pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)]; |
| 79209 | pKey2 = pReadr2->aKey; |
| 79210 | |
| 79211 | for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){ |
| 79212 | /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */ |
| 79213 | int iRes; |
| 79214 | if( pReadr1->pFd==0 ){ |
| 79215 | iRes = +1; |
| 79216 | }else if( pReadr2->pFd==0 ){ |
| 79217 | iRes = -1; |
| 79218 | }else{ |
| 79219 | iRes = vdbeSorterCompare(pTask, |
| 79220 | pReadr1->aKey, pReadr1->nKey, pKey2, pReadr2->nKey |
| 79221 | ); |
| 79222 | } |
| 79223 | |
| 79224 | /* If pReadr1 contained the smaller value, set aTree[i] to its index. |
| 79225 | ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this |
| @@ -79237,13 +79546,13 @@ | |
| 79237 | ** is sorted from oldest to newest, so pReadr1 contains older values |
| 79238 | ** than pReadr2 iff (pReadr1<pReadr2). */ |
| 79239 | if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){ |
| 79240 | pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr); |
| 79241 | pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ]; |
| 79242 | pKey2 = pReadr2->aKey; |
| 79243 | }else{ |
| 79244 | if( pReadr1->pFd ) pKey2 = 0; |
| 79245 | pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr); |
| 79246 | pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ]; |
| 79247 | } |
| 79248 | } |
| 79249 | *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0); |
| @@ -79346,10 +79655,20 @@ | |
| 79346 | SorterRecord *pNew; /* New list element */ |
| 79347 | |
| 79348 | int bFlush; /* True to flush contents of memory to PMA */ |
| 79349 | int nReq; /* Bytes of memory required */ |
| 79350 | int nPMA; /* Bytes of PMA space required */ |
| 79351 | |
| 79352 | assert( pSorter ); |
| 79353 | |
| 79354 | /* Figure out whether or not the current contents of memory should be |
| 79355 | ** flushed to a PMA before continuing. If so, do so. |
| @@ -79611,14 +79930,16 @@ | |
| 79611 | if( p1->pFd==0 ){ |
| 79612 | iRes = i2; |
| 79613 | }else if( p2->pFd==0 ){ |
| 79614 | iRes = i1; |
| 79615 | }else{ |
| 79616 | int res; |
| 79617 | assert( pMerger->pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */ |
| 79618 | res = vdbeSorterCompare( |
| 79619 | pMerger->pTask, p1->aKey, p1->nKey, p2->aKey, p2->nKey |
| 79620 | ); |
| 79621 | if( res<=0 ){ |
| 79622 | iRes = i1; |
| 79623 | }else{ |
| 79624 | iRes = i2; |
| @@ -79638,15 +79959,16 @@ | |
| 79638 | */ |
| 79639 | #define INCRINIT_NORMAL 0 |
| 79640 | #define INCRINIT_TASK 1 |
| 79641 | #define INCRINIT_ROOT 2 |
| 79642 | |
| 79643 | /* Forward reference. |
| 79644 | ** The vdbeIncrMergeInit() and vdbePmaReaderIncrMergeInit() routines call each |
| 79645 | ** other (when building a merge tree). |
| 79646 | */ |
| 79647 | static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode); |
| 79648 | |
| 79649 | /* |
| 79650 | ** Initialize the MergeEngine object passed as the second argument. Once this |
| 79651 | ** function returns, the first key of merged data may be read from the |
| 79652 | ** MergeEngine object in the usual fashion. |
| @@ -79689,11 +80011,11 @@ | |
| 79689 | ** the main thread to fill its buffer. So calling PmaReaderNext() |
| 79690 | ** on this PmaReader before any of the multi-threaded PmaReaders takes |
| 79691 | ** better advantage of multi-processor hardware. */ |
| 79692 | rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]); |
| 79693 | }else{ |
| 79694 | rc = vdbePmaReaderIncrMergeInit(&pMerger->aReadr[i], INCRINIT_NORMAL); |
| 79695 | } |
| 79696 | if( rc!=SQLITE_OK ) return rc; |
| 79697 | } |
| 79698 | |
| 79699 | for(i=pMerger->nTree-1; i>0; i--){ |
| @@ -79701,21 +80023,19 @@ | |
| 79701 | } |
| 79702 | return pTask->pUnpacked->errCode; |
| 79703 | } |
| 79704 | |
| 79705 | /* |
| 79706 | ** Initialize the IncrMerge field of a PmaReader. |
| 79707 | ** |
| 79708 | ** If the PmaReader passed as the first argument is not an incremental-reader |
| 79709 | ** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it serves |
| 79710 | ** to open and/or initialize the temp file related fields of the IncrMerge |
| 79711 | ** object at (pReadr->pIncr). |
| 79712 | ** |
| 79713 | ** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders |
| 79714 | ** in the sub-tree headed by pReadr are also initialized. Data is then loaded |
| 79715 | ** into the buffers belonging to pReadr and it is set to |
| 79716 | ** point to the first key in its range. |
| 79717 | ** |
| 79718 | ** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed |
| 79719 | ** to be a multi-threaded PmaReader and this function is being called in a |
| 79720 | ** background thread. In this case all PmaReaders in the sub-tree are |
| 79721 | ** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to |
| @@ -79738,93 +80058,112 @@ | |
| 79738 | ** SQLITE_OK is returned if successful, or an SQLite error code otherwise. |
| 79739 | */ |
| 79740 | static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){ |
| 79741 | int rc = SQLITE_OK; |
| 79742 | IncrMerger *pIncr = pReadr->pIncr; |
| 79743 | |
| 79744 | /* eMode is always INCRINIT_NORMAL in single-threaded mode */ |
| 79745 | assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL ); |
| 79746 | |
| 79747 | if( pIncr ){ |
| 79748 | SortSubtask *pTask = pIncr->pTask; |
| 79749 | sqlite3 *db = pTask->pSorter->db; |
| 79750 | |
| 79751 | rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode); |
| 79752 | |
| 79753 | /* Set up the required files for pIncr. A multi-theaded IncrMerge object |
| 79754 | ** requires two temp files to itself, whereas a single-threaded object |
| 79755 | ** only requires a region of pTask->file2. */ |
| 79756 | if( rc==SQLITE_OK ){ |
| 79757 | int mxSz = pIncr->mxSz; |
| 79758 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 79759 | if( pIncr->bUseThread ){ |
| 79760 | rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd); |
| 79761 | if( rc==SQLITE_OK ){ |
| 79762 | rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd); |
| 79763 | } |
| 79764 | }else |
| 79765 | #endif |
| 79766 | /*if( !pIncr->bUseThread )*/{ |
| 79767 | if( pTask->file2.pFd==0 ){ |
| 79768 | assert( pTask->file2.iEof>0 ); |
| 79769 | rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd); |
| 79770 | pTask->file2.iEof = 0; |
| 79771 | } |
| 79772 | if( rc==SQLITE_OK ){ |
| 79773 | pIncr->aFile[1].pFd = pTask->file2.pFd; |
| 79774 | pIncr->iStartOff = pTask->file2.iEof; |
| 79775 | pTask->file2.iEof += mxSz; |
| 79776 | } |
| 79777 | } |
| 79778 | } |
| 79779 | |
| 79780 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 79781 | if( rc==SQLITE_OK && pIncr->bUseThread ){ |
| 79782 | /* Use the current thread to populate aFile[1], even though this |
| 79783 | ** PmaReader is multi-threaded. The reason being that this function |
| 79784 | ** is already running in background thread pIncr->pTask->thread. */ |
| 79785 | assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK ); |
| 79786 | rc = vdbeIncrPopulate(pIncr); |
| 79787 | } |
| 79788 | #endif |
| 79789 | |
| 79790 | if( rc==SQLITE_OK |
| 79791 | && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) |
| 79792 | ){ |
| 79793 | rc = vdbePmaReaderNext(pReadr); |
| 79794 | } |
| 79795 | } |
| 79796 | return rc; |
| 79797 | } |
| 79798 | |
| 79799 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 79800 | /* |
| 79801 | ** The main routine for vdbePmaReaderIncrMergeInit() operations run in |
| 79802 | ** background threads. |
| 79803 | */ |
| 79804 | static void *vdbePmaReaderBgInit(void *pCtx){ |
| 79805 | PmaReader *pReader = (PmaReader*)pCtx; |
| 79806 | void *pRet = SQLITE_INT_TO_PTR( |
| 79807 | vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK) |
| 79808 | ); |
| 79809 | pReader->pIncr->pTask->bDone = 1; |
| 79810 | return pRet; |
| 79811 | } |
| 79812 | |
| 79813 | /* |
| 79814 | ** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK) |
| 79815 | ** on the PmaReader object passed as the first argument. |
| 79816 | ** |
| 79817 | ** This call will initialize the various fields of the pReadr->pIncr |
| 79818 | ** structure and, if it is a multi-threaded IncrMerger, launch a |
| 79819 | ** background thread to populate aFile[1]. |
| 79820 | */ |
| 79821 | static int vdbePmaReaderBgIncrInit(PmaReader *pReadr){ |
| 79822 | void *pCtx = (void*)pReadr; |
| 79823 | return vdbeSorterCreateThread(pReadr->pIncr->pTask, vdbePmaReaderBgInit, pCtx); |
| 79824 | } |
| 79825 | #endif |
| 79826 | |
| 79827 | /* |
| 79828 | ** Allocate a new MergeEngine object to merge the contents of nPMA level-0 |
| 79829 | ** PMAs from pTask->file. If no error occurs, set *ppOut to point to |
| 79830 | ** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut |
| @@ -80032,10 +80371,15 @@ | |
| 80032 | int rc; /* Return code */ |
| 80033 | SortSubtask *pTask0 = &pSorter->aTask[0]; |
| 80034 | MergeEngine *pMain = 0; |
| 80035 | #if SQLITE_MAX_WORKER_THREADS |
| 80036 | sqlite3 *db = pTask0->pSorter->db; |
| 80037 | #endif |
| 80038 | |
| 80039 | rc = vdbeSorterMergeTreeBuild(pSorter, &pMain); |
| 80040 | if( rc==SQLITE_OK ){ |
| 80041 | #if SQLITE_MAX_WORKER_THREADS |
| @@ -80060,19 +80404,25 @@ | |
| 80060 | vdbeIncrMergerSetThreads(pIncr); |
| 80061 | assert( pIncr->pTask!=pLast ); |
| 80062 | } |
| 80063 | } |
| 80064 | for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){ |
| 80065 | PmaReader *p = &pMain->aReadr[iTask]; |
| 80066 | assert( p->pIncr==0 || p->pIncr->pTask==&pSorter->aTask[iTask] ); |
| 80067 | if( p->pIncr ){ |
| 80068 | if( iTask==pSorter->nTask-1 ){ |
| 80069 | rc = vdbePmaReaderIncrMergeInit(p, INCRINIT_TASK); |
| 80070 | }else{ |
| 80071 | rc = vdbePmaReaderBgIncrInit(p); |
| 80072 | } |
| 80073 | } |
| 80074 | } |
| 80075 | } |
| 80076 | pMain = 0; |
| 80077 | } |
| 80078 | if( rc==SQLITE_OK ){ |
| @@ -81023,11 +81373,11 @@ | |
| 81023 | ** Should be transformed into: |
| 81024 | ** |
| 81025 | ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase; |
| 81026 | ** |
| 81027 | ** The nSubquery parameter specifies how many levels of subquery the |
| 81028 | ** alias is removed from the original expression. The usually value is |
| 81029 | ** zero but it might be more if the alias is contained within a subquery |
| 81030 | ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION |
| 81031 | ** structures must be increased by the nSubquery amount. |
| 81032 | */ |
| 81033 | static void resolveAlias( |
| @@ -81043,11 +81393,11 @@ | |
| 81043 | sqlite3 *db; /* The database connection */ |
| 81044 | |
| 81045 | assert( iCol>=0 && iCol<pEList->nExpr ); |
| 81046 | pOrig = pEList->a[iCol].pExpr; |
| 81047 | assert( pOrig!=0 ); |
| 81048 | assert( pOrig->flags & EP_Resolved ); |
| 81049 | db = pParse->db; |
| 81050 | pDup = sqlite3ExprDup(db, pOrig, 0); |
| 81051 | if( pDup==0 ) return; |
| 81052 | if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){ |
| 81053 | incrAggFunctionDepth(pDup, nSubquery); |
| @@ -81937,13 +82287,15 @@ | |
| 81937 | pNew->flags |= EP_IntValue; |
| 81938 | pNew->u.iValue = iCol; |
| 81939 | if( pItem->pExpr==pE ){ |
| 81940 | pItem->pExpr = pNew; |
| 81941 | }else{ |
| 81942 | assert( pItem->pExpr->op==TK_COLLATE ); |
| 81943 | assert( pItem->pExpr->pLeft==pE ); |
| 81944 | pItem->pExpr->pLeft = pNew; |
| 81945 | } |
| 81946 | sqlite3ExprDelete(db, pE); |
| 81947 | pItem->u.x.iOrderByCol = (u16)iCol; |
| 81948 | pItem->done = 1; |
| 81949 | }else{ |
| @@ -82139,11 +82491,11 @@ | |
| 82139 | ** as if it were part of the sub-query, not the parent. This block |
| 82140 | ** moves the pOrderBy down to the sub-query. It will be moved back |
| 82141 | ** after the names have been resolved. */ |
| 82142 | if( p->selFlags & SF_Converted ){ |
| 82143 | Select *pSub = p->pSrc->a[0].pSelect; |
| 82144 | assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy ); |
| 82145 | assert( pSub->pPrior && pSub->pOrderBy==0 ); |
| 82146 | pSub->pOrderBy = p->pOrderBy; |
| 82147 | p->pOrderBy = 0; |
| 82148 | } |
| 82149 | |
| @@ -82241,12 +82593,19 @@ | |
| 82241 | |
| 82242 | /* Process the ORDER BY clause for singleton SELECT statements. |
| 82243 | ** The ORDER BY clause for compounds SELECT statements is handled |
| 82244 | ** below, after all of the result-sets for all of the elements of |
| 82245 | ** the compound have been resolved. |
| 82246 | */ |
| 82247 | if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){ |
| 82248 | return WRC_Abort; |
| 82249 | } |
| 82250 | if( db->mallocFailed ){ |
| 82251 | return WRC_Abort; |
| 82252 | } |
| @@ -83694,11 +84053,12 @@ | |
| 83694 | SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){ |
| 83695 | int i; |
| 83696 | u32 m = 0; |
| 83697 | if( pList ){ |
| 83698 | for(i=0; i<pList->nExpr; i++){ |
| 83699 | m |= pList->a[i].pExpr->flags; |
| 83700 | } |
| 83701 | } |
| 83702 | return m; |
| 83703 | } |
| 83704 | |
| @@ -84134,11 +84494,11 @@ | |
| 84134 | /* Check to see if an existing table or index can be used to |
| 84135 | ** satisfy the query. This is preferable to generating a new |
| 84136 | ** ephemeral table. |
| 84137 | */ |
| 84138 | p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0); |
| 84139 | if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){ |
| 84140 | sqlite3 *db = pParse->db; /* Database connection */ |
| 84141 | Table *pTab; /* Table <table>. */ |
| 84142 | Expr *pExpr; /* Expression <column> */ |
| 84143 | i16 iCol; /* Index of column <column> */ |
| 84144 | i16 iDb; /* Database idx for pTab */ |
| @@ -84459,10 +84819,11 @@ | |
| 84459 | } |
| 84460 | sqlite3ExprDelete(pParse->db, pSel->pLimit); |
| 84461 | pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, |
| 84462 | &sqlite3IntTokens[1]); |
| 84463 | pSel->iLimit = 0; |
| 84464 | if( sqlite3Select(pParse, pSel, &dest) ){ |
| 84465 | return 0; |
| 84466 | } |
| 84467 | rReg = dest.iSDParm; |
| 84468 | ExprSetVVAProperty(pExpr, EP_NoReduce); |
| @@ -85824,11 +86185,11 @@ | |
| 85824 | sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken); |
| 85825 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 85826 | break; |
| 85827 | } |
| 85828 | case TK_ID: { |
| 85829 | sqlite3TreeViewLine(pView,"ID %Q", pExpr->u.zToken); |
| 85830 | break; |
| 85831 | } |
| 85832 | #ifndef SQLITE_OMIT_CAST |
| 85833 | case TK_CAST: { |
| 85834 | /* Expressions of the form: CAST(pLeft AS token) */ |
| @@ -86459,11 +86820,11 @@ | |
| 86459 | if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){ |
| 86460 | if( combinedFlags & EP_xIsSelect ) return 2; |
| 86461 | if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2; |
| 86462 | if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2; |
| 86463 | if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2; |
| 86464 | if( ALWAYS((combinedFlags & EP_Reduced)==0) ){ |
| 86465 | if( pA->iColumn!=pB->iColumn ) return 2; |
| 86466 | if( pA->iTable!=pB->iTable |
| 86467 | && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2; |
| 86468 | } |
| 86469 | } |
| @@ -86991,10 +87352,11 @@ | |
| 86991 | do { |
| 86992 | z += n; |
| 86993 | n = sqlite3GetToken(z, &token); |
| 86994 | }while( token==TK_SPACE ); |
| 86995 | |
| 86996 | zParent = sqlite3DbStrNDup(db, (const char *)z, n); |
| 86997 | if( zParent==0 ) break; |
| 86998 | sqlite3Dequote(zParent); |
| 86999 | if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){ |
| 87000 | char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"", |
| @@ -89217,18 +89579,21 @@ | |
| 89217 | pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase); |
| 89218 | } |
| 89219 | z = argv[2]; |
| 89220 | |
| 89221 | if( pIndex ){ |
| 89222 | int nCol = pIndex->nKeyCol+1; |
| 89223 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 89224 | tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero( |
| 89225 | sizeof(tRowcnt) * nCol |
| 89226 | ); |
| 89227 | if( aiRowEst==0 ) pInfo->db->mallocFailed = 1; |
| 89228 | #else |
| 89229 | tRowcnt * const aiRowEst = 0; |
| 89230 | #endif |
| 89231 | pIndex->bUnordered = 0; |
| 89232 | decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex); |
| 89233 | if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0]; |
| 89234 | }else{ |
| @@ -89887,11 +90252,11 @@ | |
| 89887 | } |
| 89888 | |
| 89889 | sqlite3BtreeClose(pDb->pBt); |
| 89890 | pDb->pBt = 0; |
| 89891 | pDb->pSchema = 0; |
| 89892 | sqlite3ResetAllSchemasOfConnection(db); |
| 89893 | return; |
| 89894 | |
| 89895 | detach_error: |
| 89896 | sqlite3_result_error(context, zErr, -1); |
| 89897 | } |
| @@ -89921,11 +90286,10 @@ | |
| 89921 | if( |
| 89922 | SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) || |
| 89923 | SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) || |
| 89924 | SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey)) |
| 89925 | ){ |
| 89926 | pParse->nErr++; |
| 89927 | goto attach_end; |
| 89928 | } |
| 89929 | |
| 89930 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 89931 | if( pAuthArg ){ |
| @@ -90580,13 +90944,15 @@ | |
| 90580 | sqlite3 *db; |
| 90581 | Vdbe *v; |
| 90582 | |
| 90583 | assert( pParse->pToplevel==0 ); |
| 90584 | db = pParse->db; |
| 90585 | if( db->mallocFailed ) return; |
| 90586 | if( pParse->nested ) return; |
| 90587 | if( pParse->nErr ) return; |
| 90588 | |
| 90589 | /* Begin by generating some termination code at the end of the |
| 90590 | ** vdbe program |
| 90591 | */ |
| 90592 | v = sqlite3GetVdbe(pParse); |
| @@ -90664,11 +91030,11 @@ | |
| 90664 | } |
| 90665 | |
| 90666 | |
| 90667 | /* Get the VDBE program ready for execution |
| 90668 | */ |
| 90669 | if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){ |
| 90670 | assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */ |
| 90671 | /* A minimum of one cursor is required if autoincrement is used |
| 90672 | * See ticket [a696379c1f08866] */ |
| 90673 | if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1; |
| 90674 | sqlite3VdbeMakeReady(v, pParse); |
| @@ -91199,18 +91565,16 @@ | |
| 91199 | sqlite3 *db = pParse->db; |
| 91200 | |
| 91201 | if( ALWAYS(pName2!=0) && pName2->n>0 ){ |
| 91202 | if( db->init.busy ) { |
| 91203 | sqlite3ErrorMsg(pParse, "corrupt database"); |
| 91204 | pParse->nErr++; |
| 91205 | return -1; |
| 91206 | } |
| 91207 | *pUnqual = pName2; |
| 91208 | iDb = sqlite3FindDb(db, pName1); |
| 91209 | if( iDb<0 ){ |
| 91210 | sqlite3ErrorMsg(pParse, "unknown database %T", pName1); |
| 91211 | pParse->nErr++; |
| 91212 | return -1; |
| 91213 | } |
| 91214 | }else{ |
| 91215 | assert( db->init.iDb==0 || db->init.busy ); |
| 91216 | iDb = db->init.iDb; |
| @@ -91365,11 +91729,11 @@ | |
| 91365 | pTable = sqlite3FindTable(db, zName, zDb); |
| 91366 | if( pTable ){ |
| 91367 | if( !noErr ){ |
| 91368 | sqlite3ErrorMsg(pParse, "table %T already exists", pName); |
| 91369 | }else{ |
| 91370 | assert( !db->init.busy ); |
| 91371 | sqlite3CodeVerifySchema(pParse, iDb); |
| 91372 | } |
| 91373 | goto begin_table_error; |
| 91374 | } |
| 91375 | if( sqlite3FindIndex(db, zName, zDb)!=0 ){ |
| @@ -91654,11 +92018,12 @@ | |
| 91654 | Column *pCol; |
| 91655 | |
| 91656 | p = pParse->pNewTable; |
| 91657 | if( p==0 || NEVER(p->nCol<1) ) return; |
| 91658 | pCol = &p->aCol[p->nCol-1]; |
| 91659 | assert( pCol->zType==0 ); |
| 91660 | pCol->zType = sqlite3NameFromToken(pParse->db, pType); |
| 91661 | pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst); |
| 91662 | } |
| 91663 | |
| 91664 | /* |
| @@ -92888,10 +93253,11 @@ | |
| 92888 | if( db->mallocFailed ){ |
| 92889 | goto exit_drop_table; |
| 92890 | } |
| 92891 | assert( pParse->nErr==0 ); |
| 92892 | assert( pName->nSrc==1 ); |
| 92893 | if( noErr ) db->suppressErr++; |
| 92894 | pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]); |
| 92895 | if( noErr ) db->suppressErr--; |
| 92896 | |
| 92897 | if( pTab==0 ){ |
| @@ -93201,11 +93567,12 @@ | |
| 93201 | sqlite3UniqueConstraint(pParse, OE_Abort, pIndex); |
| 93202 | }else{ |
| 93203 | addr2 = sqlite3VdbeCurrentAddr(v); |
| 93204 | } |
| 93205 | sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx); |
| 93206 | sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1); |
| 93207 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 93208 | sqlite3ReleaseTempReg(pParse, regRecord); |
| 93209 | sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v); |
| 93210 | sqlite3VdbeJumpHere(v, addr1); |
| 93211 | |
| @@ -93294,12 +93661,11 @@ | |
| 93294 | int nExtra = 0; /* Space allocated for zExtra[] */ |
| 93295 | int nExtraCol; /* Number of extra columns needed */ |
| 93296 | char *zExtra = 0; /* Extra space after the Index object */ |
| 93297 | Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */ |
| 93298 | |
| 93299 | assert( pParse->nErr==0 ); /* Never called with prior errors */ |
| 93300 | if( db->mallocFailed || IN_DECLARE_VTAB ){ |
| 93301 | goto exit_create_index; |
| 93302 | } |
| 93303 | if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ |
| 93304 | goto exit_create_index; |
| 93305 | } |
| @@ -94214,11 +94580,10 @@ | |
| 94214 | ** operator with A. This routine shifts that operator over to B. |
| 94215 | */ |
| 94216 | SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){ |
| 94217 | if( p ){ |
| 94218 | int i; |
| 94219 | assert( p->a || p->nSrc==0 ); |
| 94220 | for(i=p->nSrc-1; i>0; i--){ |
| 94221 | p->a[i].jointype = p->a[i-1].jointype; |
| 94222 | } |
| 94223 | p->a[0].jointype = 0; |
| 94224 | } |
| @@ -94461,12 +94826,11 @@ | |
| 94461 | char *zErr; |
| 94462 | int j; |
| 94463 | StrAccum errMsg; |
| 94464 | Table *pTab = pIdx->pTable; |
| 94465 | |
| 94466 | sqlite3StrAccumInit(&errMsg, 0, 0, 200); |
| 94467 | errMsg.db = pParse->db; |
| 94468 | for(j=0; j<pIdx->nKeyCol; j++){ |
| 94469 | char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName; |
| 94470 | if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2); |
| 94471 | sqlite3StrAccumAppendAll(&errMsg, pTab->zName); |
| 94472 | sqlite3StrAccumAppend(&errMsg, ".", 1); |
| @@ -96291,17 +96655,17 @@ | |
| 96291 | ){ |
| 96292 | PrintfArguments x; |
| 96293 | StrAccum str; |
| 96294 | const char *zFormat; |
| 96295 | int n; |
| 96296 | |
| 96297 | if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){ |
| 96298 | x.nArg = argc-1; |
| 96299 | x.nUsed = 0; |
| 96300 | x.apArg = argv+1; |
| 96301 | sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH); |
| 96302 | str.db = sqlite3_context_db_handle(context); |
| 96303 | sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x); |
| 96304 | n = str.nChar; |
| 96305 | sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, |
| 96306 | SQLITE_DYNAMIC); |
| 96307 | } |
| @@ -96447,11 +96811,11 @@ | |
| 96447 | sqlite3_result_double(context, r); |
| 96448 | } |
| 96449 | #endif |
| 96450 | |
| 96451 | /* |
| 96452 | ** Allocate nByte bytes of space using sqlite3_malloc(). If the |
| 96453 | ** allocation fails, call sqlite3_result_error_nomem() to notify |
| 96454 | ** the database handle that malloc() has failed and return NULL. |
| 96455 | ** If nByte is larger than the maximum string or blob length, then |
| 96456 | ** raise an SQLITE_TOOBIG exception and return NULL. |
| 96457 | */ |
| @@ -97116,11 +97480,11 @@ | |
| 97116 | int argc, |
| 97117 | sqlite3_value **argv |
| 97118 | ){ |
| 97119 | unsigned char *z, *zOut; |
| 97120 | int i; |
| 97121 | zOut = z = sqlite3_malloc( argc*4+1 ); |
| 97122 | if( z==0 ){ |
| 97123 | sqlite3_result_error_nomem(context); |
| 97124 | return; |
| 97125 | } |
| 97126 | for(i=0; i<argc; i++){ |
| @@ -97264,11 +97628,11 @@ | |
| 97264 | sqlite3_result_error_toobig(context); |
| 97265 | sqlite3_free(zOut); |
| 97266 | return; |
| 97267 | } |
| 97268 | zOld = zOut; |
| 97269 | zOut = sqlite3_realloc(zOut, (int)nOut); |
| 97270 | if( zOut==0 ){ |
| 97271 | sqlite3_result_error_nomem(context); |
| 97272 | sqlite3_free(zOld); |
| 97273 | return; |
| 97274 | } |
| @@ -97626,12 +97990,11 @@ | |
| 97626 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 97627 | pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum)); |
| 97628 | |
| 97629 | if( pAccum ){ |
| 97630 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 97631 | int firstTerm = pAccum->useMalloc==0; |
| 97632 | pAccum->useMalloc = 2; |
| 97633 | pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH]; |
| 97634 | if( !firstTerm ){ |
| 97635 | if( argc==2 ){ |
| 97636 | zSep = (char*)sqlite3_value_text(argv[1]); |
| 97637 | nSep = sqlite3_value_bytes(argv[1]); |
| @@ -99047,11 +99410,12 @@ | |
| 99047 | int iFromCol; /* Idx of column in child table */ |
| 99048 | Expr *pEq; /* tFromCol = OLD.tToCol */ |
| 99049 | |
| 99050 | iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; |
| 99051 | assert( iFromCol>=0 ); |
| 99052 | tToCol.z = pIdx ? pTab->aCol[pIdx->aiColumn[i]].zName : "oid"; |
| 99053 | tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName; |
| 99054 | |
| 99055 | tToCol.n = sqlite3Strlen30(tToCol.z); |
| 99056 | tFromCol.n = sqlite3Strlen30(tFromCol.z); |
| 99057 | |
| @@ -99059,14 +99423,14 @@ | |
| 99059 | ** that the "OLD.zToCol" term is on the LHS of the = operator, so |
| 99060 | ** that the affinity and collation sequence associated with the |
| 99061 | ** parent table are used for the comparison. */ |
| 99062 | pEq = sqlite3PExpr(pParse, TK_EQ, |
| 99063 | sqlite3PExpr(pParse, TK_DOT, |
| 99064 | sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld), |
| 99065 | sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol) |
| 99066 | , 0), |
| 99067 | sqlite3PExpr(pParse, TK_ID, 0, 0, &tFromCol) |
| 99068 | , 0); |
| 99069 | pWhere = sqlite3ExprAnd(db, pWhere, pEq); |
| 99070 | |
| 99071 | /* For ON UPDATE, construct the next term of the WHEN clause. |
| 99072 | ** The final WHEN clause will be like this: |
| @@ -99074,27 +99438,27 @@ | |
| 99074 | ** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN) |
| 99075 | */ |
| 99076 | if( pChanges ){ |
| 99077 | pEq = sqlite3PExpr(pParse, TK_IS, |
| 99078 | sqlite3PExpr(pParse, TK_DOT, |
| 99079 | sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld), |
| 99080 | sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol), |
| 99081 | 0), |
| 99082 | sqlite3PExpr(pParse, TK_DOT, |
| 99083 | sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew), |
| 99084 | sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol), |
| 99085 | 0), |
| 99086 | 0); |
| 99087 | pWhen = sqlite3ExprAnd(db, pWhen, pEq); |
| 99088 | } |
| 99089 | |
| 99090 | if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){ |
| 99091 | Expr *pNew; |
| 99092 | if( action==OE_Cascade ){ |
| 99093 | pNew = sqlite3PExpr(pParse, TK_DOT, |
| 99094 | sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew), |
| 99095 | sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol) |
| 99096 | , 0); |
| 99097 | }else if( action==OE_SetDflt ){ |
| 99098 | Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt; |
| 99099 | if( pDflt ){ |
| 99100 | pNew = sqlite3ExprDup(db, pDflt, 0); |
| @@ -99137,17 +99501,16 @@ | |
| 99137 | db->lookaside.bEnabled = 0; |
| 99138 | |
| 99139 | pTrigger = (Trigger *)sqlite3DbMallocZero(db, |
| 99140 | sizeof(Trigger) + /* struct Trigger */ |
| 99141 | sizeof(TriggerStep) + /* Single step in trigger program */ |
| 99142 | nFrom + 1 /* Space for pStep->target.z */ |
| 99143 | ); |
| 99144 | if( pTrigger ){ |
| 99145 | pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1]; |
| 99146 | pStep->target.z = (char *)&pStep[1]; |
| 99147 | pStep->target.n = nFrom; |
| 99148 | memcpy((char *)pStep->target.z, zFrom, nFrom); |
| 99149 | |
| 99150 | pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE); |
| 99151 | pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE); |
| 99152 | pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE); |
| 99153 | if( pWhen ){ |
| @@ -99608,24 +99971,27 @@ | |
| 99608 | ); |
| 99609 | |
| 99610 | /* |
| 99611 | ** This routine is called to handle SQL of the following forms: |
| 99612 | ** |
| 99613 | ** insert into TABLE (IDLIST) values(EXPRLIST) |
| 99614 | ** insert into TABLE (IDLIST) select |
| 99615 | ** |
| 99616 | ** The IDLIST following the table name is always optional. If omitted, |
| 99617 | ** then a list of all columns for the table is substituted. The IDLIST |
| 99618 | ** appears in the pColumn parameter. pColumn is NULL if IDLIST is omitted. |
| 99619 | ** |
| 99620 | ** The pList parameter holds EXPRLIST in the first form of the INSERT |
| 99621 | ** statement above, and pSelect is NULL. For the second form, pList is |
| 99622 | ** NULL and pSelect is a pointer to the select statement used to generate |
| 99623 | ** data for the insert. |
| 99624 | ** |
| 99625 | ** The code generated follows one of four templates. For a simple |
| 99626 | ** insert with data coming from a VALUES clause, the code executes |
| 99627 | ** once straight down through. Pseudo-code follows (we call this |
| 99628 | ** the "1st template"): |
| 99629 | ** |
| 99630 | ** open write cursor to <table> and its indices |
| 99631 | ** put VALUES clause expressions into registers |
| @@ -99728,11 +100094,11 @@ | |
| 99728 | int iDb; /* Index of database holding TABLE */ |
| 99729 | Db *pDb; /* The database containing table being inserted into */ |
| 99730 | u8 useTempTable = 0; /* Store SELECT results in intermediate table */ |
| 99731 | u8 appendFlag = 0; /* True if the insert is likely to be an append */ |
| 99732 | u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */ |
| 99733 | u8 bIdListInOrder = 1; /* True if IDLIST is in table order */ |
| 99734 | ExprList *pList = 0; /* List of VALUES() to be inserted */ |
| 99735 | |
| 99736 | /* Register allocations */ |
| 99737 | int regFromSelect = 0;/* Base register for data coming from SELECT */ |
| 99738 | int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */ |
| @@ -99753,12 +100119,12 @@ | |
| 99753 | if( pParse->nErr || db->mallocFailed ){ |
| 99754 | goto insert_cleanup; |
| 99755 | } |
| 99756 | |
| 99757 | /* If the Select object is really just a simple VALUES() list with a |
| 99758 | ** single row values (the common case) then keep that one row of values |
| 99759 | ** and go ahead and discard the Select object |
| 99760 | */ |
| 99761 | if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){ |
| 99762 | pList = pSelect->pEList; |
| 99763 | pSelect->pEList = 0; |
| 99764 | sqlite3SelectDelete(db, pSelect); |
| @@ -99862,10 +100228,11 @@ | |
| 99862 | ** the index into IDLIST of the primary key column. ipkColumn is |
| 99863 | ** the index of the primary key as it appears in IDLIST, not as |
| 99864 | ** is appears in the original table. (The index of the INTEGER |
| 99865 | ** PRIMARY KEY in the original table is pTab->iPKey.) |
| 99866 | */ |
| 99867 | if( pColumn ){ |
| 99868 | for(i=0; i<pColumn->nId; i++){ |
| 99869 | pColumn->a[i].idx = -1; |
| 99870 | } |
| 99871 | for(i=0; i<pColumn->nId; i++){ |
| @@ -99897,11 +100264,12 @@ | |
| 99897 | ** is coming from a SELECT statement, then generate a co-routine that |
| 99898 | ** produces a single row of the SELECT on each invocation. The |
| 99899 | ** co-routine is the common header to the 3rd and 4th templates. |
| 99900 | */ |
| 99901 | if( pSelect ){ |
| 99902 | /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */ |
| 99903 | int regYield; /* Register holding co-routine entry-point */ |
| 99904 | int addrTop; /* Top of the co-routine */ |
| 99905 | int rc; /* Result code */ |
| 99906 | |
| 99907 | regYield = ++pParse->nMem; |
| @@ -99910,12 +100278,11 @@ | |
| 99910 | sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); |
| 99911 | dest.iSdst = bIdListInOrder ? regData : 0; |
| 99912 | dest.nSdst = pTab->nCol; |
| 99913 | rc = sqlite3Select(pParse, pSelect, &dest); |
| 99914 | regFromSelect = dest.iSdst; |
| 99915 | assert( pParse->nErr==0 || rc ); |
| 99916 | if( rc || db->mallocFailed ) goto insert_cleanup; |
| 99917 | sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield); |
| 99918 | sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */ |
| 99919 | assert( pSelect->pEList ); |
| 99920 | nColumn = pSelect->pEList->nExpr; |
| 99921 | |
| @@ -99959,12 +100326,12 @@ | |
| 99959 | sqlite3VdbeJumpHere(v, addrL); |
| 99960 | sqlite3ReleaseTempReg(pParse, regRec); |
| 99961 | sqlite3ReleaseTempReg(pParse, regTempRowid); |
| 99962 | } |
| 99963 | }else{ |
| 99964 | /* This is the case if the data for the INSERT is coming from a VALUES |
| 99965 | ** clause |
| 99966 | */ |
| 99967 | NameContext sNC; |
| 99968 | memset(&sNC, 0, sizeof(sNC)); |
| 99969 | sNC.pParse = pParse; |
| 99970 | srcTab = -1; |
| @@ -101031,10 +101398,11 @@ | |
| 101031 | Table *pDest, /* The table we are inserting into */ |
| 101032 | Select *pSelect, /* A SELECT statement to use as the data source */ |
| 101033 | int onError, /* How to handle constraint errors */ |
| 101034 | int iDbDest /* The database of pDest */ |
| 101035 | ){ |
| 101036 | ExprList *pEList; /* The result set of the SELECT */ |
| 101037 | Table *pSrc; /* The table in the FROM clause of SELECT */ |
| 101038 | Index *pSrcIdx, *pDestIdx; /* Source and destination indices */ |
| 101039 | struct SrcList_item *pItem; /* An element of pSelect->pSrc */ |
| 101040 | int i; /* Loop counter */ |
| @@ -101178,15 +101546,15 @@ | |
| 101178 | ** But the main beneficiary of the transfer optimization is the VACUUM |
| 101179 | ** command, and the VACUUM command disables foreign key constraints. So |
| 101180 | ** the extra complication to make this rule less restrictive is probably |
| 101181 | ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] |
| 101182 | */ |
| 101183 | if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ |
| 101184 | return 0; |
| 101185 | } |
| 101186 | #endif |
| 101187 | if( (pParse->db->flags & SQLITE_CountRows)!=0 ){ |
| 101188 | return 0; /* xfer opt does not play well with PRAGMA count_changes */ |
| 101189 | } |
| 101190 | |
| 101191 | /* If we get this far, it means that the xfer optimization is at |
| 101192 | ** least a possibility, though it might only work if the destination |
| @@ -101193,28 +101561,32 @@ | |
| 101193 | ** table (tab1) is initially empty. |
| 101194 | */ |
| 101195 | #ifdef SQLITE_TEST |
| 101196 | sqlite3_xferopt_count++; |
| 101197 | #endif |
| 101198 | iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema); |
| 101199 | v = sqlite3GetVdbe(pParse); |
| 101200 | sqlite3CodeVerifySchema(pParse, iDbSrc); |
| 101201 | iSrc = pParse->nTab++; |
| 101202 | iDest = pParse->nTab++; |
| 101203 | regAutoinc = autoIncBegin(pParse, iDbDest, pDest); |
| 101204 | regData = sqlite3GetTempReg(pParse); |
| 101205 | regRowid = sqlite3GetTempReg(pParse); |
| 101206 | sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite); |
| 101207 | assert( HasRowid(pDest) || destHasUniqueIdx ); |
| 101208 | if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */ |
| 101209 | || destHasUniqueIdx /* (2) */ |
| 101210 | || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */ |
| 101211 | ){ |
| 101212 | /* In some circumstances, we are able to run the xfer optimization |
| 101213 | ** only if the destination table is initially empty. This code makes |
| 101214 | ** that determination. Conditions under which the destination must |
| 101215 | ** be empty: |
| 101216 | ** |
| 101217 | ** (1) There is no INTEGER PRIMARY KEY but there are indices. |
| 101218 | ** (If the destination is not initially empty, the rowid fields |
| 101219 | ** of index entries might need to change.) |
| 101220 | ** |
| @@ -101253,10 +101625,11 @@ | |
| 101253 | }else{ |
| 101254 | sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName); |
| 101255 | sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName); |
| 101256 | } |
| 101257 | for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){ |
| 101258 | for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){ |
| 101259 | if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break; |
| 101260 | } |
| 101261 | assert( pSrcIdx ); |
| 101262 | sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc); |
| @@ -101266,11 +101639,37 @@ | |
| 101266 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 101267 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 101268 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 101269 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 101270 | sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData); |
| 101271 | sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1); |
| 101272 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v); |
| 101273 | sqlite3VdbeJumpHere(v, addr1); |
| 101274 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| 101275 | sqlite3VdbeAddOp2(v, OP_Close, iDest, 0); |
| 101276 | } |
| @@ -102385,11 +102784,11 @@ | |
| 102385 | int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); |
| 102386 | char *zErrmsg = 0; |
| 102387 | const char *zEntry; |
| 102388 | char *zAltEntry = 0; |
| 102389 | void **aHandle; |
| 102390 | int nMsg = 300 + sqlite3Strlen30(zFile); |
| 102391 | int ii; |
| 102392 | |
| 102393 | /* Shared library endings to try if zFile cannot be loaded as written */ |
| 102394 | static const char *azEndings[] = { |
| 102395 | #if SQLITE_OS_WIN |
| @@ -102428,11 +102827,11 @@ | |
| 102428 | sqlite3_free(zAltFile); |
| 102429 | } |
| 102430 | #endif |
| 102431 | if( handle==0 ){ |
| 102432 | if( pzErrMsg ){ |
| 102433 | *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg); |
| 102434 | if( zErrmsg ){ |
| 102435 | sqlite3_snprintf(nMsg, zErrmsg, |
| 102436 | "unable to open shared library [%s]", zFile); |
| 102437 | sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); |
| 102438 | } |
| @@ -102454,11 +102853,11 @@ | |
| 102454 | ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init |
| 102455 | */ |
| 102456 | if( xInit==0 && zProc==0 ){ |
| 102457 | int iFile, iEntry, c; |
| 102458 | int ncFile = sqlite3Strlen30(zFile); |
| 102459 | zAltEntry = sqlite3_malloc(ncFile+30); |
| 102460 | if( zAltEntry==0 ){ |
| 102461 | sqlite3OsDlClose(pVfs, handle); |
| 102462 | return SQLITE_NOMEM; |
| 102463 | } |
| 102464 | memcpy(zAltEntry, "sqlite3_", 8); |
| @@ -102476,11 +102875,11 @@ | |
| 102476 | sqlite3OsDlSym(pVfs, handle, zEntry); |
| 102477 | } |
| 102478 | if( xInit==0 ){ |
| 102479 | if( pzErrMsg ){ |
| 102480 | nMsg += sqlite3Strlen30(zEntry); |
| 102481 | *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg); |
| 102482 | if( zErrmsg ){ |
| 102483 | sqlite3_snprintf(nMsg, zErrmsg, |
| 102484 | "no entry point [%s] in shared library [%s]", zEntry, zFile); |
| 102485 | sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); |
| 102486 | } |
| @@ -102575,11 +102974,11 @@ | |
| 102575 | ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER |
| 102576 | ** mutex must be held while accessing this list. |
| 102577 | */ |
| 102578 | typedef struct sqlite3AutoExtList sqlite3AutoExtList; |
| 102579 | static SQLITE_WSD struct sqlite3AutoExtList { |
| 102580 | int nExt; /* Number of entries in aExt[] */ |
| 102581 | void (**aExt)(void); /* Pointers to the extension init functions */ |
| 102582 | } sqlite3Autoext = { 0, 0 }; |
| 102583 | |
| 102584 | /* The "wsdAutoext" macro will resolve to the autoextension |
| 102585 | ** state vector. If writable static data is unsupported on the target, |
| @@ -102608,23 +103007,23 @@ | |
| 102608 | if( rc ){ |
| 102609 | return rc; |
| 102610 | }else |
| 102611 | #endif |
| 102612 | { |
| 102613 | int i; |
| 102614 | #if SQLITE_THREADSAFE |
| 102615 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 102616 | #endif |
| 102617 | wsdAutoextInit; |
| 102618 | sqlite3_mutex_enter(mutex); |
| 102619 | for(i=0; i<wsdAutoext.nExt; i++){ |
| 102620 | if( wsdAutoext.aExt[i]==xInit ) break; |
| 102621 | } |
| 102622 | if( i==wsdAutoext.nExt ){ |
| 102623 | int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]); |
| 102624 | void (**aNew)(void); |
| 102625 | aNew = sqlite3_realloc(wsdAutoext.aExt, nByte); |
| 102626 | if( aNew==0 ){ |
| 102627 | rc = SQLITE_NOMEM; |
| 102628 | }else{ |
| 102629 | wsdAutoext.aExt = aNew; |
| 102630 | wsdAutoext.aExt[wsdAutoext.nExt] = xInit; |
| @@ -102652,11 +103051,11 @@ | |
| 102652 | #endif |
| 102653 | int i; |
| 102654 | int n = 0; |
| 102655 | wsdAutoextInit; |
| 102656 | sqlite3_mutex_enter(mutex); |
| 102657 | for(i=wsdAutoext.nExt-1; i>=0; i--){ |
| 102658 | if( wsdAutoext.aExt[i]==xInit ){ |
| 102659 | wsdAutoext.nExt--; |
| 102660 | wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt]; |
| 102661 | n++; |
| 102662 | break; |
| @@ -102690,11 +103089,11 @@ | |
| 102690 | ** Load all automatic extensions. |
| 102691 | ** |
| 102692 | ** If anything goes wrong, set an error in the database connection. |
| 102693 | */ |
| 102694 | SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){ |
| 102695 | int i; |
| 102696 | int go = 1; |
| 102697 | int rc; |
| 102698 | int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); |
| 102699 | |
| 102700 | wsdAutoextInit; |
| @@ -103354,19 +103753,19 @@ | |
| 103354 | /* |
| 103355 | ** Generate code to return a single integer value. |
| 103356 | */ |
| 103357 | static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){ |
| 103358 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 103359 | int mem = ++pParse->nMem; |
| 103360 | i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value)); |
| 103361 | if( pI64 ){ |
| 103362 | memcpy(pI64, &value, sizeof(value)); |
| 103363 | } |
| 103364 | sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64); |
| 103365 | sqlite3VdbeSetNumCols(v, 1); |
| 103366 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC); |
| 103367 | sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); |
| 103368 | } |
| 103369 | |
| 103370 | |
| 103371 | /* |
| 103372 | ** Set the safety_level and pager flags for pager iDb. Or if iDb<0 |
| @@ -103527,15 +103926,15 @@ | |
| 103527 | aFcntl[3] = 0; |
| 103528 | db->busyHandler.nBusy = 0; |
| 103529 | rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl); |
| 103530 | if( rc==SQLITE_OK ){ |
| 103531 | if( aFcntl[0] ){ |
| 103532 | int mem = ++pParse->nMem; |
| 103533 | sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0); |
| 103534 | sqlite3VdbeSetNumCols(v, 1); |
| 103535 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC); |
| 103536 | sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); |
| 103537 | sqlite3_free(aFcntl[0]); |
| 103538 | } |
| 103539 | goto pragma_out; |
| 103540 | } |
| 103541 | if( rc!=SQLITE_NOTFOUND ){ |
| @@ -104136,11 +104535,13 @@ | |
| 104136 | }else{ |
| 104137 | if( !db->autoCommit ){ |
| 104138 | sqlite3ErrorMsg(pParse, |
| 104139 | "Safety level may not be changed inside a transaction"); |
| 104140 | }else{ |
| 104141 | pDb->safety_level = getSafetyLevel(zRight,0,1)+1; |
| 104142 | setAllPagerFlags(db); |
| 104143 | } |
| 104144 | } |
| 104145 | break; |
| 104146 | } |
| @@ -104231,11 +104632,11 @@ | |
| 104231 | if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){ |
| 104232 | k = 0; |
| 104233 | }else if( pPk==0 ){ |
| 104234 | k = 1; |
| 104235 | }else{ |
| 104236 | for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){} |
| 104237 | } |
| 104238 | sqlite3VdbeAddOp2(v, OP_Integer, k, 6); |
| 104239 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); |
| 104240 | } |
| 104241 | } |
| @@ -105237,11 +105638,11 @@ | |
| 105237 | |
| 105238 | assert( iDb>=0 && iDb<db->nDb ); |
| 105239 | if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */ |
| 105240 | if( argv[1]==0 ){ |
| 105241 | corruptSchema(pData, argv[0], 0); |
| 105242 | }else if( argv[2] && argv[2][0] ){ |
| 105243 | /* Call the parser to process a CREATE TABLE, INDEX or VIEW. |
| 105244 | ** But because db->init.busy is set to 1, no VDBE code is generated |
| 105245 | ** or executed. All the parser does is build the internal data |
| 105246 | ** structures that describe the table, index, or view. |
| 105247 | */ |
| @@ -105268,12 +105669,12 @@ | |
| 105268 | corruptSchema(pData, argv[0], sqlite3_errmsg(db)); |
| 105269 | } |
| 105270 | } |
| 105271 | } |
| 105272 | sqlite3_finalize(pStmt); |
| 105273 | }else if( argv[0]==0 ){ |
| 105274 | corruptSchema(pData, 0, 0); |
| 105275 | }else{ |
| 105276 | /* If the SQL column is blank it means this is an index that |
| 105277 | ** was created to be the PRIMARY KEY or to fulfill a UNIQUE |
| 105278 | ** constraint for a CREATE TABLE. The index should have already |
| 105279 | ** been created when we processed the CREATE TABLE. All we have |
| @@ -106176,11 +106577,10 @@ | |
| 106176 | ){ |
| 106177 | Select *pNew; |
| 106178 | Select standin; |
| 106179 | sqlite3 *db = pParse->db; |
| 106180 | pNew = sqlite3DbMallocZero(db, sizeof(*pNew) ); |
| 106181 | assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */ |
| 106182 | if( pNew==0 ){ |
| 106183 | assert( db->mallocFailed ); |
| 106184 | pNew = &standin; |
| 106185 | memset(pNew, 0, sizeof(*pNew)); |
| 106186 | } |
| @@ -106196,11 +106596,11 @@ | |
| 106196 | pNew->pOrderBy = pOrderBy; |
| 106197 | pNew->selFlags = selFlags; |
| 106198 | pNew->op = TK_SELECT; |
| 106199 | pNew->pLimit = pLimit; |
| 106200 | pNew->pOffset = pOffset; |
| 106201 | assert( pOffset==0 || pLimit!=0 ); |
| 106202 | pNew->addrOpenEphm[0] = -1; |
| 106203 | pNew->addrOpenEphm[1] = -1; |
| 106204 | if( db->mallocFailed ) { |
| 106205 | clearSelect(db, pNew, pNew!=&standin); |
| 106206 | pNew = 0; |
| @@ -107446,11 +107846,11 @@ | |
| 107446 | if( pS ){ |
| 107447 | /* The "table" is actually a sub-select or a view in the FROM clause |
| 107448 | ** of the SELECT statement. Return the declaration type and origin |
| 107449 | ** data for the result-set column of the sub-select. |
| 107450 | */ |
| 107451 | if( iCol>=0 && ALWAYS(iCol<pS->pEList->nExpr) ){ |
| 107452 | /* If iCol is less than zero, then the expression requests the |
| 107453 | ** rowid of the sub-select or view. This expression is legal (see |
| 107454 | ** test case misc2.2.2) - it always evaluates to NULL. |
| 107455 | */ |
| 107456 | NameContext sNC; |
| @@ -107766,16 +108166,18 @@ | |
| 107766 | memset(&sNC, 0, sizeof(sNC)); |
| 107767 | sNC.pSrcList = pSelect->pSrc; |
| 107768 | a = pSelect->pEList->a; |
| 107769 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
| 107770 | p = a[i].pExpr; |
| 107771 | pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst)); |
| 107772 | szAll += pCol->szEst; |
| 107773 | pCol->affinity = sqlite3ExprAffinity(p); |
| 107774 | if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE; |
| 107775 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 107776 | if( pColl ){ |
| 107777 | pCol->zColl = sqlite3DbStrDup(db, pColl->zName); |
| 107778 | } |
| 107779 | } |
| 107780 | pTab->szTabRow = sqlite3LogEst(szAll*4); |
| 107781 | } |
| @@ -108173,12 +108575,11 @@ | |
| 108173 | ){ |
| 108174 | Select *pPrior; |
| 108175 | int nExpr = p->pEList->nExpr; |
| 108176 | int nRow = 1; |
| 108177 | int rc = 0; |
| 108178 | assert( p->pNext==0 ); |
| 108179 | assert( p->selFlags & SF_AllValues ); |
| 108180 | do{ |
| 108181 | assert( p->selFlags & SF_Values ); |
| 108182 | assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) ); |
| 108183 | assert( p->pLimit==0 ); |
| 108184 | assert( p->pOffset==0 ); |
| @@ -108283,11 +108684,11 @@ | |
| 108283 | dest.eDest = SRT_Table; |
| 108284 | } |
| 108285 | |
| 108286 | /* Special handling for a compound-select that originates as a VALUES clause. |
| 108287 | */ |
| 108288 | if( p->selFlags & SF_AllValues ){ |
| 108289 | rc = multiSelectValues(pParse, p, &dest); |
| 108290 | goto multi_select_end; |
| 108291 | } |
| 108292 | |
| 108293 | /* Make sure all SELECTs in the statement have the same number of elements |
| @@ -108668,11 +109069,11 @@ | |
| 108668 | ** then there should be a single item on the stack. Write this |
| 108669 | ** item into the set table with bogus data. |
| 108670 | */ |
| 108671 | case SRT_Set: { |
| 108672 | int r1; |
| 108673 | assert( pIn->nSdst==1 ); |
| 108674 | pDest->affSdst = |
| 108675 | sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst); |
| 108676 | r1 = sqlite3GetTempReg(pParse); |
| 108677 | sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1); |
| 108678 | sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1); |
| @@ -108694,11 +109095,11 @@ | |
| 108694 | /* If this is a scalar select that is part of an expression, then |
| 108695 | ** store the results in the appropriate memory cell and break out |
| 108696 | ** of the scan loop. |
| 108697 | */ |
| 108698 | case SRT_Mem: { |
| 108699 | assert( pIn->nSdst==1 ); |
| 108700 | sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1); |
| 108701 | /* The LIMIT clause will jump out of the loop for us */ |
| 108702 | break; |
| 108703 | } |
| 108704 | #endif /* #ifndef SQLITE_OMIT_SUBQUERY */ |
| @@ -108709,11 +109110,11 @@ | |
| 108709 | case SRT_Coroutine: { |
| 108710 | if( pDest->iSdst==0 ){ |
| 108711 | pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst); |
| 108712 | pDest->nSdst = pIn->nSdst; |
| 108713 | } |
| 108714 | sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst); |
| 108715 | sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm); |
| 108716 | break; |
| 108717 | } |
| 108718 | |
| 108719 | /* If none of the above, then the result destination must be |
| @@ -108925,12 +109326,14 @@ | |
| 108925 | */ |
| 108926 | aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy); |
| 108927 | if( aPermute ){ |
| 108928 | struct ExprList_item *pItem; |
| 108929 | for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){ |
| 108930 | assert( pItem->u.x.iOrderByCol>0 |
| 108931 | && pItem->u.x.iOrderByCol<=p->pEList->nExpr ); |
| 108932 | aPermute[i] = pItem->u.x.iOrderByCol - 1; |
| 108933 | } |
| 108934 | pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1); |
| 108935 | }else{ |
| 108936 | pKeyMerge = 0; |
| @@ -109136,11 +109539,11 @@ | |
| 109136 | pPrior->pNext = p; |
| 109137 | |
| 109138 | /*** TBD: Insert subroutine calls to close cursors on incomplete |
| 109139 | **** subqueries ****/ |
| 109140 | explainComposite(pParse, p->op, iSub1, iSub2, 0); |
| 109141 | return SQLITE_OK; |
| 109142 | } |
| 109143 | #endif |
| 109144 | |
| 109145 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 109146 | /* Forward Declarations */ |
| @@ -109948,10 +110351,11 @@ | |
| 109948 | pNew->pGroupBy = 0; |
| 109949 | pNew->pHaving = 0; |
| 109950 | pNew->pOrderBy = 0; |
| 109951 | p->pPrior = 0; |
| 109952 | p->pNext = 0; |
| 109953 | p->selFlags &= ~SF_Compound; |
| 109954 | assert( (p->selFlags & SF_Converted)==0 ); |
| 109955 | p->selFlags |= SF_Converted; |
| 109956 | assert( pNew->pPrior!=0 ); |
| 109957 | pNew->pPrior->pNext = pNew; |
| @@ -110486,11 +110890,11 @@ | |
| 110486 | if( pParse->hasCompound ){ |
| 110487 | w.xSelectCallback = convertCompoundSelectToSubquery; |
| 110488 | sqlite3WalkSelect(&w, pSelect); |
| 110489 | } |
| 110490 | w.xSelectCallback = selectExpander; |
| 110491 | if( (pSelect->selFlags & SF_AllValues)==0 ){ |
| 110492 | w.xSelectCallback2 = selectPopWith; |
| 110493 | } |
| 110494 | sqlite3WalkSelect(&w, pSelect); |
| 110495 | } |
| 110496 | |
| @@ -110672,11 +111076,12 @@ | |
| 110672 | nArg = 0; |
| 110673 | regAgg = 0; |
| 110674 | } |
| 110675 | if( pF->iDistinct>=0 ){ |
| 110676 | addrNext = sqlite3VdbeMakeLabel(v); |
| 110677 | assert( nArg==1 ); |
| 110678 | codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg); |
| 110679 | } |
| 110680 | if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 110681 | CollSeq *pColl = 0; |
| 110682 | struct ExprList_item *pItem; |
| @@ -111547,14 +111952,13 @@ | |
| 111547 | |
| 111548 | /* Jump here to skip this query |
| 111549 | */ |
| 111550 | sqlite3VdbeResolveLabel(v, iEnd); |
| 111551 | |
| 111552 | /* The SELECT was successfully coded. Set the return code to 0 |
| 111553 | ** to indicate no errors. |
| 111554 | */ |
| 111555 | rc = 0; |
| 111556 | |
| 111557 | /* Control jumps to here if an error is encountered above, or upon |
| 111558 | ** successful coding of the SELECT. |
| 111559 | */ |
| 111560 | select_end: |
| @@ -111601,11 +112005,11 @@ | |
| 111601 | sqlite3TreeViewLine(pView, "FROM"); |
| 111602 | for(i=0; i<p->pSrc->nSrc; i++){ |
| 111603 | struct SrcList_item *pItem = &p->pSrc->a[i]; |
| 111604 | StrAccum x; |
| 111605 | char zLine[100]; |
| 111606 | sqlite3StrAccumInit(&x, zLine, sizeof(zLine), 0); |
| 111607 | sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor); |
| 111608 | if( pItem->zDatabase ){ |
| 111609 | sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName); |
| 111610 | }else if( pItem->zName ){ |
| 111611 | sqlite3XPrintf(&x, 0, " %s", pItem->zName); |
| @@ -111760,11 +112164,11 @@ | |
| 111760 | for(i=0; i<nCol; i++){ |
| 111761 | if( argv[i]==0 ){ |
| 111762 | z = 0; |
| 111763 | }else{ |
| 111764 | int n = sqlite3Strlen30(argv[i])+1; |
| 111765 | z = sqlite3_malloc( n ); |
| 111766 | if( z==0 ) goto malloc_failed; |
| 111767 | memcpy(z, argv[i], n); |
| 111768 | } |
| 111769 | p->azResult[p->nData++] = z; |
| 111770 | } |
| @@ -111809,11 +112213,11 @@ | |
| 111809 | res.nRow = 0; |
| 111810 | res.nColumn = 0; |
| 111811 | res.nData = 1; |
| 111812 | res.nAlloc = 20; |
| 111813 | res.rc = SQLITE_OK; |
| 111814 | res.azResult = sqlite3_malloc(sizeof(char*)*res.nAlloc ); |
| 111815 | if( res.azResult==0 ){ |
| 111816 | db->errCode = SQLITE_NOMEM; |
| 111817 | return SQLITE_NOMEM; |
| 111818 | } |
| 111819 | res.azResult[0] = 0; |
| @@ -111837,11 +112241,11 @@ | |
| 111837 | sqlite3_free_table(&res.azResult[1]); |
| 111838 | return rc; |
| 111839 | } |
| 111840 | if( res.nAlloc>res.nData ){ |
| 111841 | char **azNew; |
| 111842 | azNew = sqlite3_realloc( res.azResult, sizeof(char*)*res.nData ); |
| 111843 | if( azNew==0 ){ |
| 111844 | sqlite3_free_table(&res.azResult[1]); |
| 111845 | db->errCode = SQLITE_NOMEM; |
| 111846 | return SQLITE_NOMEM; |
| 111847 | } |
| @@ -112065,11 +112469,10 @@ | |
| 112065 | } |
| 112066 | |
| 112067 | /* Do not create a trigger on a system table */ |
| 112068 | if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){ |
| 112069 | sqlite3ErrorMsg(pParse, "cannot create trigger on system table"); |
| 112070 | pParse->nErr++; |
| 112071 | goto trigger_cleanup; |
| 112072 | } |
| 112073 | |
| 112074 | /* INSTEAD of triggers are only for views and views only support INSTEAD |
| 112075 | ** of triggers. |
| @@ -112245,16 +112648,16 @@ | |
| 112245 | u8 op, /* Trigger opcode */ |
| 112246 | Token *pName /* The target name */ |
| 112247 | ){ |
| 112248 | TriggerStep *pTriggerStep; |
| 112249 | |
| 112250 | pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n); |
| 112251 | if( pTriggerStep ){ |
| 112252 | char *z = (char*)&pTriggerStep[1]; |
| 112253 | memcpy(z, pName->z, pName->n); |
| 112254 | pTriggerStep->target.z = z; |
| 112255 | pTriggerStep->target.n = pName->n; |
| 112256 | pTriggerStep->op = op; |
| 112257 | } |
| 112258 | return pTriggerStep; |
| 112259 | } |
| 112260 | |
| @@ -112533,11 +112936,11 @@ | |
| 112533 | } |
| 112534 | return (mask ? pList : 0); |
| 112535 | } |
| 112536 | |
| 112537 | /* |
| 112538 | ** Convert the pStep->target token into a SrcList and return a pointer |
| 112539 | ** to that SrcList. |
| 112540 | ** |
| 112541 | ** This routine adds a specific database name, if needed, to the target when |
| 112542 | ** forming the SrcList. This prevents a trigger in one database from |
| 112543 | ** referring to a target in another database. An exception is when the |
| @@ -112546,21 +112949,21 @@ | |
| 112546 | */ |
| 112547 | static SrcList *targetSrcList( |
| 112548 | Parse *pParse, /* The parsing context */ |
| 112549 | TriggerStep *pStep /* The trigger containing the target token */ |
| 112550 | ){ |
| 112551 | int iDb; /* Index of the database to use */ |
| 112552 | SrcList *pSrc; /* SrcList to be returned */ |
| 112553 | |
| 112554 | pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0); |
| 112555 | if( pSrc ){ |
| 112556 | assert( pSrc->nSrc>0 ); |
| 112557 | assert( pSrc->a!=0 ); |
| 112558 | iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema); |
| 112559 | if( iDb==0 || iDb>=2 ){ |
| 112560 | sqlite3 *db = pParse->db; |
| 112561 | assert( iDb<pParse->db->nDb ); |
| 112562 | pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName); |
| 112563 | } |
| 112564 | } |
| 112565 | return pSrc; |
| 112566 | } |
| @@ -112668,10 +113071,11 @@ | |
| 112668 | assert( pFrom->zErrMsg==0 || pFrom->nErr ); |
| 112669 | assert( pTo->zErrMsg==0 || pTo->nErr ); |
| 112670 | if( pTo->nErr==0 ){ |
| 112671 | pTo->zErrMsg = pFrom->zErrMsg; |
| 112672 | pTo->nErr = pFrom->nErr; |
| 112673 | }else{ |
| 112674 | sqlite3DbFree(pFrom->db, pFrom->zErrMsg); |
| 112675 | } |
| 112676 | } |
| 112677 | |
| @@ -114018,17 +114422,21 @@ | |
| 114018 | |
| 114019 | /* Loop through the tables in the main database. For each, do |
| 114020 | ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy |
| 114021 | ** the contents to the temporary database. |
| 114022 | */ |
| 114023 | rc = execExecSql(db, pzErrMsg, |
| 114024 | "SELECT 'INSERT INTO vacuum_db.' || quote(name) " |
| 114025 | "|| ' SELECT * FROM main.' || quote(name) || ';'" |
| 114026 | "FROM main.sqlite_master " |
| 114027 | "WHERE type = 'table' AND name!='sqlite_sequence' " |
| 114028 | " AND coalesce(rootpage,1)>0" |
| 114029 | ); |
| 114030 | if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 114031 | |
| 114032 | /* Copy over the sequence table |
| 114033 | */ |
| 114034 | rc = execExecSql(db, pzErrMsg, |
| @@ -114163,10 +114571,12 @@ | |
| 114163 | ** are invoked only from within xCreate and xConnect methods. |
| 114164 | */ |
| 114165 | struct VtabCtx { |
| 114166 | VTable *pVTable; /* The virtual table being constructed */ |
| 114167 | Table *pTab; /* The Table object to which the virtual table belongs */ |
| 114168 | }; |
| 114169 | |
| 114170 | /* |
| 114171 | ** The actual function that does the work of creating a new module. |
| 114172 | ** This function implements the sqlite3_create_module() and |
| @@ -114609,11 +115019,11 @@ | |
| 114609 | Token *pArg = &pParse->sArg; |
| 114610 | if( pArg->z==0 ){ |
| 114611 | pArg->z = p->z; |
| 114612 | pArg->n = p->n; |
| 114613 | }else{ |
| 114614 | assert(pArg->z < p->z); |
| 114615 | pArg->n = (int)(&p->z[p->n] - pArg->z); |
| 114616 | } |
| 114617 | } |
| 114618 | |
| 114619 | /* |
| @@ -114626,19 +115036,31 @@ | |
| 114626 | Table *pTab, |
| 114627 | Module *pMod, |
| 114628 | int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**), |
| 114629 | char **pzErr |
| 114630 | ){ |
| 114631 | VtabCtx sCtx, *pPriorCtx; |
| 114632 | VTable *pVTable; |
| 114633 | int rc; |
| 114634 | const char *const*azArg = (const char *const*)pTab->azModuleArg; |
| 114635 | int nArg = pTab->nModuleArg; |
| 114636 | char *zErr = 0; |
| 114637 | char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); |
| 114638 | int iDb; |
| 114639 | |
| 114640 | if( !zModuleName ){ |
| 114641 | return SQLITE_NOMEM; |
| 114642 | } |
| 114643 | |
| 114644 | pVTable = sqlite3DbMallocZero(db, sizeof(VTable)); |
| @@ -114655,15 +115077,17 @@ | |
| 114655 | /* Invoke the virtual table constructor */ |
| 114656 | assert( &db->pVtabCtx ); |
| 114657 | assert( xConstruct ); |
| 114658 | sCtx.pTab = pTab; |
| 114659 | sCtx.pVTable = pVTable; |
| 114660 | pPriorCtx = db->pVtabCtx; |
| 114661 | db->pVtabCtx = &sCtx; |
| 114662 | rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); |
| 114663 | db->pVtabCtx = pPriorCtx; |
| 114664 | if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; |
| 114665 | |
| 114666 | if( SQLITE_OK!=rc ){ |
| 114667 | if( zErr==0 ){ |
| 114668 | *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); |
| 114669 | }else { |
| @@ -114675,17 +115099,18 @@ | |
| 114675 | /* Justification of ALWAYS(): A correct vtab constructor must allocate |
| 114676 | ** the sqlite3_vtab object if successful. */ |
| 114677 | memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0])); |
| 114678 | pVTable->pVtab->pModule = pMod->pModule; |
| 114679 | pVTable->nRef = 1; |
| 114680 | if( sCtx.pTab ){ |
| 114681 | const char *zFormat = "vtable constructor did not declare schema: %s"; |
| 114682 | *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName); |
| 114683 | sqlite3VtabUnlock(pVTable); |
| 114684 | rc = SQLITE_ERROR; |
| 114685 | }else{ |
| 114686 | int iCol; |
| 114687 | /* If everything went according to plan, link the new VTable structure |
| 114688 | ** into the linked list headed by pTab->pVTable. Then loop through the |
| 114689 | ** columns of the table to see if any of them contain the token "hidden". |
| 114690 | ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from |
| 114691 | ** the type string. */ |
| @@ -114694,11 +115119,14 @@ | |
| 114694 | |
| 114695 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 114696 | char *zType = pTab->aCol[iCol].zType; |
| 114697 | int nType; |
| 114698 | int i = 0; |
| 114699 | if( !zType ) continue; |
| 114700 | nType = sqlite3Strlen30(zType); |
| 114701 | if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){ |
| 114702 | for(i=0; i<nType; i++){ |
| 114703 | if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7)) |
| 114704 | && (zType[i+7]=='\0' || zType[i+7]==' ') |
| @@ -114717,10 +115145,13 @@ | |
| 114717 | if( zType[i]=='\0' && i>0 ){ |
| 114718 | assert(zType[i-1]==' '); |
| 114719 | zType[i-1] = '\0'; |
| 114720 | } |
| 114721 | pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN; |
| 114722 | } |
| 114723 | } |
| 114724 | } |
| 114725 | } |
| 114726 | |
| @@ -114845,12 +115276,12 @@ | |
| 114845 | ** This function is used to set the schema of a virtual table. It is only |
| 114846 | ** valid to call this function from within the xCreate() or xConnect() of a |
| 114847 | ** virtual table module. |
| 114848 | */ |
| 114849 | SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ |
| 114850 | Parse *pParse; |
| 114851 | |
| 114852 | int rc = SQLITE_OK; |
| 114853 | Table *pTab; |
| 114854 | char *zErr = 0; |
| 114855 | |
| 114856 | #ifdef SQLITE_ENABLE_API_ARMOR |
| @@ -114857,15 +115288,17 @@ | |
| 114857 | if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){ |
| 114858 | return SQLITE_MISUSE_BKPT; |
| 114859 | } |
| 114860 | #endif |
| 114861 | sqlite3_mutex_enter(db->mutex); |
| 114862 | if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){ |
| 114863 | sqlite3Error(db, SQLITE_MISUSE); |
| 114864 | sqlite3_mutex_leave(db->mutex); |
| 114865 | return SQLITE_MISUSE_BKPT; |
| 114866 | } |
| 114867 | assert( (pTab->tabFlags & TF_Virtual)!=0 ); |
| 114868 | |
| 114869 | pParse = sqlite3StackAllocZero(db, sizeof(*pParse)); |
| 114870 | if( pParse==0 ){ |
| 114871 | rc = SQLITE_NOMEM; |
| @@ -114884,11 +115317,11 @@ | |
| 114884 | pTab->aCol = pParse->pNewTable->aCol; |
| 114885 | pTab->nCol = pParse->pNewTable->nCol; |
| 114886 | pParse->pNewTable->nCol = 0; |
| 114887 | pParse->pNewTable->aCol = 0; |
| 114888 | } |
| 114889 | db->pVtabCtx->pTab = 0; |
| 114890 | }else{ |
| 114891 | sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr); |
| 114892 | sqlite3DbFree(db, zErr); |
| 114893 | rc = SQLITE_ERROR; |
| 114894 | } |
| @@ -115078,11 +115511,11 @@ | |
| 115078 | */ |
| 115079 | SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){ |
| 115080 | int rc = SQLITE_OK; |
| 115081 | |
| 115082 | assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN ); |
| 115083 | assert( iSavepoint>=0 ); |
| 115084 | if( db->aVTrans ){ |
| 115085 | int i; |
| 115086 | for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){ |
| 115087 | VTable *pVTab = db->aVTrans[i]; |
| 115088 | const sqlite3_module *pMod = pVTab->pMod->pModule; |
| @@ -115196,11 +115629,11 @@ | |
| 115196 | assert( IsVirtual(pTab) ); |
| 115197 | for(i=0; i<pToplevel->nVtabLock; i++){ |
| 115198 | if( pTab==pToplevel->apVtabLock[i] ) return; |
| 115199 | } |
| 115200 | n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]); |
| 115201 | apVtabLock = sqlite3_realloc(pToplevel->apVtabLock, n); |
| 115202 | if( apVtabLock ){ |
| 115203 | pToplevel->apVtabLock = apVtabLock; |
| 115204 | pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab; |
| 115205 | }else{ |
| 115206 | pToplevel->db->mallocFailed = 1; |
| @@ -115995,17 +116428,18 @@ | |
| 115995 | ** In the previous sentence and in the diagram, "slot[]" refers to |
| 115996 | ** the WhereClause.a[] array. The slot[] array grows as needed to contain |
| 115997 | ** all terms of the WHERE clause. |
| 115998 | */ |
| 115999 | static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){ |
| 116000 | pWC->op = op; |
| 116001 | if( pExpr==0 ) return; |
| 116002 | if( pExpr->op!=op ){ |
| 116003 | whereClauseInsert(pWC, pExpr, 0); |
| 116004 | }else{ |
| 116005 | whereSplit(pWC, pExpr->pLeft, op); |
| 116006 | whereSplit(pWC, pExpr->pRight, op); |
| 116007 | } |
| 116008 | } |
| 116009 | |
| 116010 | /* |
| 116011 | ** Initialize a WhereMaskSet object |
| @@ -117272,11 +117706,11 @@ | |
| 117272 | if( p->op==TK_COLUMN |
| 117273 | && p->iColumn==pIdx->aiColumn[iCol] |
| 117274 | && p->iTable==iBase |
| 117275 | ){ |
| 117276 | CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr); |
| 117277 | if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){ |
| 117278 | return i; |
| 117279 | } |
| 117280 | } |
| 117281 | } |
| 117282 | |
| @@ -117546,11 +117980,11 @@ | |
| 117546 | if( (idxCols & cMask)==0 ){ |
| 117547 | Expr *pX = pTerm->pExpr; |
| 117548 | idxCols |= cMask; |
| 117549 | pIdx->aiColumn[n] = pTerm->u.leftColumn; |
| 117550 | pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); |
| 117551 | pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : "BINARY"; |
| 117552 | n++; |
| 117553 | } |
| 117554 | } |
| 117555 | } |
| 117556 | assert( (u32)n==pLoop->u.btree.nEq ); |
| @@ -118842,12 +119276,11 @@ | |
| 118842 | |
| 118843 | isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 |
| 118844 | || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0)) |
| 118845 | || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX)); |
| 118846 | |
| 118847 | sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH); |
| 118848 | str.db = db; |
| 118849 | sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN"); |
| 118850 | if( pItem->pSelect ){ |
| 118851 | sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId); |
| 118852 | }else{ |
| 118853 | sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName); |
| @@ -120042,10 +120475,17 @@ | |
| 120042 | /* |
| 120043 | ** Free a WhereInfo structure |
| 120044 | */ |
| 120045 | static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){ |
| 120046 | if( ALWAYS(pWInfo) ){ |
| 120047 | whereClauseClear(&pWInfo->sWC); |
| 120048 | while( pWInfo->pLoops ){ |
| 120049 | WhereLoop *p = pWInfo->pLoops; |
| 120050 | pWInfo->pLoops = p->pNextLoop; |
| 120051 | whereLoopDelete(db, p); |
| @@ -120521,11 +120961,11 @@ | |
| 120521 | ** changes "x IN (?)" into "x=?". */ |
| 120522 | |
| 120523 | }else if( eOp & (WO_EQ) ){ |
| 120524 | pNew->wsFlags |= WHERE_COLUMN_EQ; |
| 120525 | if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){ |
| 120526 | if( iCol>=0 && !IsUniqueIndex(pProbe) ){ |
| 120527 | pNew->wsFlags |= WHERE_UNQ_WANTED; |
| 120528 | }else{ |
| 120529 | pNew->wsFlags |= WHERE_ONEROW; |
| 120530 | } |
| 120531 | } |
| @@ -121981,11 +122421,11 @@ | |
| 121981 | pWInfo->nOBSat = pFrom->isOrdered; |
| 121982 | if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0; |
| 121983 | pWInfo->revMask = pFrom->revLoop; |
| 121984 | } |
| 121985 | if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP) |
| 121986 | && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr |
| 121987 | ){ |
| 121988 | Bitmask revMask = 0; |
| 121989 | int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy, |
| 121990 | pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask |
| 121991 | ); |
| @@ -122386,11 +122826,10 @@ | |
| 122386 | if( pParse->nErr || NEVER(db->mallocFailed) ){ |
| 122387 | goto whereBeginError; |
| 122388 | } |
| 122389 | #ifdef WHERETRACE_ENABLED /* !=0 */ |
| 122390 | if( sqlite3WhereTrace ){ |
| 122391 | int ii; |
| 122392 | sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut); |
| 122393 | if( pWInfo->nOBSat>0 ){ |
| 122394 | sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask); |
| 122395 | } |
| 122396 | switch( pWInfo->eDistinct ){ |
| @@ -122639,11 +123078,10 @@ | |
| 122639 | VdbeCoverage(v); |
| 122640 | VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen); |
| 122641 | VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen); |
| 122642 | sqlite3VdbeJumpHere(v, pIn->addrInTop-1); |
| 122643 | } |
| 122644 | sqlite3DbFree(db, pLevel->u.in.aInLoop); |
| 122645 | } |
| 122646 | sqlite3VdbeResolveLabel(v, pLevel->addrBrk); |
| 122647 | if( pLevel->addrSkip ){ |
| 122648 | sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip); |
| 122649 | VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName)); |
| @@ -122850,10 +123288,32 @@ | |
| 122850 | /* |
| 122851 | ** An instance of this structure holds the ATTACH key and the key type. |
| 122852 | */ |
| 122853 | struct AttachKey { int type; Token key; }; |
| 122854 | |
| 122855 | |
| 122856 | /* This is a utility routine used to set the ExprSpan.zStart and |
| 122857 | ** ExprSpan.zEnd values of pOut so that the span covers the complete |
| 122858 | ** range of text beginning with pStart and going to the end of pEnd. |
| 122859 | */ |
| @@ -125167,31 +125627,14 @@ | |
| 125167 | sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3); |
| 125168 | } |
| 125169 | break; |
| 125170 | case 112: /* select ::= with selectnowith */ |
| 125171 | { |
| 125172 | Select *p = yymsp[0].minor.yy3, *pNext, *pLoop; |
| 125173 | if( p ){ |
| 125174 | int cnt = 0, mxSelect; |
| 125175 | p->pWith = yymsp[-1].minor.yy59; |
| 125176 | if( p->pPrior ){ |
| 125177 | u16 allValues = SF_Values; |
| 125178 | pNext = 0; |
| 125179 | for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){ |
| 125180 | pLoop->pNext = pNext; |
| 125181 | pLoop->selFlags |= SF_Compound; |
| 125182 | allValues &= pLoop->selFlags; |
| 125183 | } |
| 125184 | if( allValues ){ |
| 125185 | p->selFlags |= SF_AllValues; |
| 125186 | }else if( |
| 125187 | (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 |
| 125188 | && cnt>mxSelect |
| 125189 | ){ |
| 125190 | sqlite3ErrorMsg(pParse, "too many terms in compound SELECT"); |
| 125191 | } |
| 125192 | } |
| 125193 | }else{ |
| 125194 | sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59); |
| 125195 | } |
| 125196 | yygotominor.yy3 = p; |
| 125197 | } |
| @@ -125205,16 +125648,18 @@ | |
| 125205 | Select *pRhs = yymsp[0].minor.yy3; |
| 125206 | if( pRhs && pRhs->pPrior ){ |
| 125207 | SrcList *pFrom; |
| 125208 | Token x; |
| 125209 | x.n = 0; |
| 125210 | pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0); |
| 125211 | pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0); |
| 125212 | } |
| 125213 | if( pRhs ){ |
| 125214 | pRhs->op = (u8)yymsp[-1].minor.yy328; |
| 125215 | pRhs->pPrior = yymsp[-2].minor.yy3; |
| 125216 | if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1; |
| 125217 | }else{ |
| 125218 | sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3); |
| 125219 | } |
| 125220 | yygotominor.yy3 = pRhs; |
| @@ -125257,17 +125702,20 @@ | |
| 125257 | yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0); |
| 125258 | } |
| 125259 | break; |
| 125260 | case 121: /* values ::= values COMMA LP exprlist RP */ |
| 125261 | { |
| 125262 | Select *pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0); |
| 125263 | if( pRight ){ |
| 125264 | pRight->op = TK_ALL; |
| 125265 | pRight->pPrior = yymsp[-4].minor.yy3; |
| 125266 | yygotominor.yy3 = pRight; |
| 125267 | }else{ |
| 125268 | yygotominor.yy3 = yymsp[-4].minor.yy3; |
| 125269 | } |
| 125270 | } |
| 125271 | break; |
| 125272 | case 122: /* distinct ::= DISTINCT */ |
| 125273 | {yygotominor.yy381 = SF_Distinct;} |
| @@ -127067,14 +127515,12 @@ | |
| 127067 | goto abort_parse; |
| 127068 | } |
| 127069 | break; |
| 127070 | } |
| 127071 | case TK_ILLEGAL: { |
| 127072 | sqlite3DbFree(db, *pzErrMsg); |
| 127073 | *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"", |
| 127074 | &pParse->sLastToken); |
| 127075 | nErr++; |
| 127076 | goto abort_parse; |
| 127077 | } |
| 127078 | case TK_SEMI: { |
| 127079 | pParse->zTail = &zSql[i]; |
| 127080 | /* Fall thru into the default case */ |
| @@ -127088,16 +127534,19 @@ | |
| 127088 | break; |
| 127089 | } |
| 127090 | } |
| 127091 | } |
| 127092 | abort_parse: |
| 127093 | if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){ |
| 127094 | if( lastTokenParsed!=TK_SEMI ){ |
| 127095 | sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse); |
| 127096 | pParse->zTail = &zSql[i]; |
| 127097 | } |
| 127098 | sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse); |
| 127099 | } |
| 127100 | #ifdef YYTRACKMAXSTACKDEPTH |
| 127101 | sqlite3_mutex_enter(sqlite3MallocMutex()); |
| 127102 | sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK, |
| 127103 | sqlite3ParserStackPeak(pEngine) |
| @@ -127154,13 +127603,11 @@ | |
| 127154 | while( pParse->pZombieTab ){ |
| 127155 | Table *p = pParse->pZombieTab; |
| 127156 | pParse->pZombieTab = p->pNextZombie; |
| 127157 | sqlite3DeleteTable(db, p); |
| 127158 | } |
| 127159 | if( nErr>0 && pParse->rc==SQLITE_OK ){ |
| 127160 | pParse->rc = SQLITE_ERROR; |
| 127161 | } |
| 127162 | return nErr; |
| 127163 | } |
| 127164 | |
| 127165 | /************** End of tokenize.c ********************************************/ |
| 127166 | /************** Begin file complete.c ****************************************/ |
| @@ -127432,11 +127879,11 @@ | |
| 127432 | ** UTF-8. |
| 127433 | */ |
| 127434 | SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){ |
| 127435 | sqlite3_value *pVal; |
| 127436 | char const *zSql8; |
| 127437 | int rc = SQLITE_NOMEM; |
| 127438 | |
| 127439 | #ifndef SQLITE_OMIT_AUTOINIT |
| 127440 | rc = sqlite3_initialize(); |
| 127441 | if( rc ) return rc; |
| 127442 | #endif |
| @@ -127598,10 +128045,22 @@ | |
| 127598 | ** zero if and only if SQLite was compiled with mutexing code omitted due to |
| 127599 | ** the SQLITE_THREADSAFE compile-time option being set to 0. |
| 127600 | */ |
| 127601 | SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; } |
| 127602 | |
| 127603 | #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE) |
| 127604 | /* |
| 127605 | ** If the following function pointer is not NULL and if |
| 127606 | ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing |
| 127607 | ** I/O active are written using this function. These messages |
| @@ -128737,11 +129196,11 @@ | |
| 128737 | |
| 128738 | /* |
| 128739 | ** Return a static string containing the name corresponding to the error code |
| 128740 | ** specified in the argument. |
| 128741 | */ |
| 128742 | #if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST) |
| 128743 | SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ |
| 128744 | const char *zName = 0; |
| 128745 | int i, origRc = rc; |
| 128746 | for(i=0; i<2 && zName==0; i++, rc &= 0xff){ |
| 128747 | switch( rc ){ |
| @@ -129962,18 +130421,18 @@ | |
| 129962 | ){ |
| 129963 | char *zOpt; |
| 129964 | int eState; /* Parser state when parsing URI */ |
| 129965 | int iIn; /* Input character index */ |
| 129966 | int iOut = 0; /* Output character index */ |
| 129967 | int nByte = nUri+2; /* Bytes of space to allocate */ |
| 129968 | |
| 129969 | /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen |
| 129970 | ** method that there may be extra parameters following the file-name. */ |
| 129971 | flags |= SQLITE_OPEN_URI; |
| 129972 | |
| 129973 | for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&'); |
| 129974 | zFile = sqlite3_malloc(nByte); |
| 129975 | if( !zFile ) return SQLITE_NOMEM; |
| 129976 | |
| 129977 | iIn = 5; |
| 129978 | #ifdef SQLITE_ALLOW_URI_AUTHORITY |
| 129979 | if( strncmp(zUri+5, "///", 3)==0 ){ |
| @@ -130135,11 +130594,11 @@ | |
| 130135 | |
| 130136 | zOpt = &zVal[nVal+1]; |
| 130137 | } |
| 130138 | |
| 130139 | }else{ |
| 130140 | zFile = sqlite3_malloc(nUri+2); |
| 130141 | if( !zFile ) return SQLITE_NOMEM; |
| 130142 | memcpy(zFile, zUri, nUri); |
| 130143 | zFile[nUri] = '\0'; |
| 130144 | zFile[nUri+1] = '\0'; |
| 130145 | flags &= ~SQLITE_OPEN_URI; |
| @@ -132344,10 +132803,15 @@ | |
| 132344 | ** false. |
| 132345 | */ |
| 132346 | #ifdef SQLITE_COVERAGE_TEST |
| 132347 | # define ALWAYS(x) (1) |
| 132348 | # define NEVER(X) (0) |
| 132349 | #else |
| 132350 | # define ALWAYS(x) (x) |
| 132351 | # define NEVER(x) (x) |
| 132352 | #endif |
| 132353 | |
| @@ -132744,10 +133208,11 @@ | |
| 132744 | #define fts3GetVarint32(p, piVal) ( \ |
| 132745 | (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \ |
| 132746 | ) |
| 132747 | |
| 132748 | /* fts3.c */ |
| 132749 | SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64); |
| 132750 | SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *); |
| 132751 | SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *); |
| 132752 | SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64); |
| 132753 | SQLITE_PRIVATE void sqlite3Fts3Dequote(char *); |
| @@ -132832,10 +133297,17 @@ | |
| 132832 | |
| 132833 | static int fts3EvalNext(Fts3Cursor *pCsr); |
| 132834 | static int fts3EvalStart(Fts3Cursor *pCsr); |
| 132835 | static int fts3TermSegReaderCursor( |
| 132836 | Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **); |
| 132837 | |
| 132838 | /* |
| 132839 | ** Write a 64-bit variable-length integer to memory starting at p[0]. |
| 132840 | ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes. |
| 132841 | ** The number of bytes written is returned. |
| @@ -132942,11 +133414,11 @@ | |
| 132942 | int iOut = 0; /* Index of next byte to write to output */ |
| 132943 | |
| 132944 | /* If the first byte was a '[', then the close-quote character is a ']' */ |
| 132945 | if( quote=='[' ) quote = ']'; |
| 132946 | |
| 132947 | while( ALWAYS(z[iIn]) ){ |
| 132948 | if( z[iIn]==quote ){ |
| 132949 | if( z[iIn+1]!=quote ) break; |
| 132950 | z[iOut++] = quote; |
| 132951 | iIn += 2; |
| 132952 | }else{ |
| @@ -133020,10 +133492,21 @@ | |
| 133020 | p->pTokenizer->pModule->xDestroy(p->pTokenizer); |
| 133021 | |
| 133022 | sqlite3_free(p); |
| 133023 | return SQLITE_OK; |
| 133024 | } |
| 133025 | |
| 133026 | /* |
| 133027 | ** Construct one or more SQL statements from the format string given |
| 133028 | ** and then evaluate those statements. The success code is written |
| 133029 | ** into *pRc. |
| @@ -133539,11 +134022,12 @@ | |
| 133539 | sqlite3 *db, /* Database handle */ |
| 133540 | const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */ |
| 133541 | const char *zTbl, /* Name of content table */ |
| 133542 | const char ***pazCol, /* OUT: Malloc'd array of column names */ |
| 133543 | int *pnCol, /* OUT: Size of array *pazCol */ |
| 133544 | int *pnStr /* OUT: Bytes of string content */ |
| 133545 | ){ |
| 133546 | int rc = SQLITE_OK; /* Return code */ |
| 133547 | char *zSql; /* "SELECT *" statement on zTbl */ |
| 133548 | sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */ |
| 133549 | |
| @@ -133550,10 +134034,13 @@ | |
| 133550 | zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl); |
| 133551 | if( !zSql ){ |
| 133552 | rc = SQLITE_NOMEM; |
| 133553 | }else{ |
| 133554 | rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0); |
| 133555 | } |
| 133556 | sqlite3_free(zSql); |
| 133557 | |
| 133558 | if( rc==SQLITE_OK ){ |
| 133559 | const char **azCol; /* Output array */ |
| @@ -133716,17 +134203,17 @@ | |
| 133716 | if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){ |
| 133717 | break; |
| 133718 | } |
| 133719 | } |
| 133720 | if( iOpt==SizeofArray(aFts4Opt) ){ |
| 133721 | *pzErr = sqlite3_mprintf("unrecognized parameter: %s", z); |
| 133722 | rc = SQLITE_ERROR; |
| 133723 | }else{ |
| 133724 | switch( iOpt ){ |
| 133725 | case 0: /* MATCHINFO */ |
| 133726 | if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){ |
| 133727 | *pzErr = sqlite3_mprintf("unrecognized matchinfo: %s", zVal); |
| 133728 | rc = SQLITE_ERROR; |
| 133729 | } |
| 133730 | bNoDocsize = 1; |
| 133731 | break; |
| 133732 | |
| @@ -133750,11 +134237,11 @@ | |
| 133750 | |
| 133751 | case 4: /* ORDER */ |
| 133752 | if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3)) |
| 133753 | && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4)) |
| 133754 | ){ |
| 133755 | *pzErr = sqlite3_mprintf("unrecognized order: %s", zVal); |
| 133756 | rc = SQLITE_ERROR; |
| 133757 | } |
| 133758 | bDescIdx = (zVal[0]=='d' || zVal[0]=='D'); |
| 133759 | break; |
| 133760 | |
| @@ -133801,11 +134288,11 @@ | |
| 133801 | zCompress = 0; |
| 133802 | zUncompress = 0; |
| 133803 | if( nCol==0 ){ |
| 133804 | sqlite3_free((void*)aCol); |
| 133805 | aCol = 0; |
| 133806 | rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString); |
| 133807 | |
| 133808 | /* If a languageid= option was specified, remove the language id |
| 133809 | ** column from the aCol[] array. */ |
| 133810 | if( rc==SQLITE_OK && zLanguageid ){ |
| 133811 | int j; |
| @@ -133836,11 +134323,11 @@ | |
| 133836 | assert( pTokenizer ); |
| 133837 | |
| 133838 | rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex); |
| 133839 | if( rc==SQLITE_ERROR ){ |
| 133840 | assert( zPrefix ); |
| 133841 | *pzErr = sqlite3_mprintf("error parsing prefix parameter: %s", zPrefix); |
| 133842 | } |
| 133843 | if( rc!=SQLITE_OK ) goto fts3_init_out; |
| 133844 | |
| 133845 | /* Allocate and populate the Fts3Table structure. */ |
| 133846 | nByte = sizeof(Fts3Table) + /* Fts3Table */ |
| @@ -133918,19 +134405,19 @@ | |
| 133918 | } |
| 133919 | } |
| 133920 | } |
| 133921 | for(i=0; i<nNotindexed; i++){ |
| 133922 | if( azNotindexed[i] ){ |
| 133923 | *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]); |
| 133924 | rc = SQLITE_ERROR; |
| 133925 | } |
| 133926 | } |
| 133927 | |
| 133928 | if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){ |
| 133929 | char const *zMiss = (zCompress==0 ? "compress" : "uncompress"); |
| 133930 | rc = SQLITE_ERROR; |
| 133931 | *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss); |
| 133932 | } |
| 133933 | p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc); |
| 133934 | p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc); |
| 133935 | if( rc!=SQLITE_OK ) goto fts3_init_out; |
| 133936 | |
| @@ -135319,11 +135806,11 @@ | |
| 135319 | ** Fts3SegReaderPending might segfault, as the data structures used by |
| 135320 | ** fts4aux are not completely populated. So it's easiest to filter these |
| 135321 | ** calls out here. */ |
| 135322 | if( iLevel<0 && p->aIndex ){ |
| 135323 | Fts3SegReader *pSeg = 0; |
| 135324 | rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix, &pSeg); |
| 135325 | if( rc==SQLITE_OK && pSeg ){ |
| 135326 | rc = fts3SegReaderCursorAppend(pCsr, pSeg); |
| 135327 | } |
| 135328 | } |
| 135329 | |
| @@ -135968,15 +136455,35 @@ | |
| 135968 | */ |
| 135969 | static void fts3ReversePoslist(char *pStart, char **ppPoslist){ |
| 135970 | char *p = &(*ppPoslist)[-2]; |
| 135971 | char c = 0; |
| 135972 | |
| 135973 | while( p>pStart && (c=*p--)==0 ); |
| 135974 | while( p>pStart && (*p & 0x80) | c ){ |
| 135975 | c = *p--; |
| 135976 | } |
| 135977 | if( p>pStart ){ p = &p[2]; } |
| 135978 | while( *p++&0x80 ); |
| 135979 | *ppPoslist = p; |
| 135980 | } |
| 135981 | |
| 135982 | /* |
| @@ -136043,10 +136550,12 @@ | |
| 136043 | case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]); |
| 136044 | case 2: zStart = (const char*)sqlite3_value_text(apVal[1]); |
| 136045 | } |
| 136046 | if( !zEllipsis || !zEnd || !zStart ){ |
| 136047 | sqlite3_result_error_nomem(pContext); |
| 136048 | }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){ |
| 136049 | sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken); |
| 136050 | } |
| 136051 | } |
| 136052 | |
| @@ -137104,16 +137613,18 @@ | |
| 137104 | Fts3Expr *pExpr, /* Expression to initialize phrases in */ |
| 137105 | int *pRc /* IN/OUT: Error code */ |
| 137106 | ){ |
| 137107 | if( pExpr && SQLITE_OK==*pRc ){ |
| 137108 | if( pExpr->eType==FTSQUERY_PHRASE ){ |
| 137109 | int i; |
| 137110 | int nToken = pExpr->pPhrase->nToken; |
| 137111 | for(i=0; i<nToken; i++){ |
| 137112 | if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break; |
| 137113 | } |
| 137114 | pExpr->bDeferred = (i==nToken); |
| 137115 | *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase); |
| 137116 | }else{ |
| 137117 | fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc); |
| 137118 | fts3EvalStartReaders(pCsr, pExpr->pRight, pRc); |
| 137119 | pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred); |
| @@ -138272,11 +138783,12 @@ | |
| 138272 | if( rc!=SQLITE_OK ) return rc; |
| 138273 | |
| 138274 | pIter = pPhrase->pOrPoslist; |
| 138275 | iDocid = pPhrase->iOrDocid; |
| 138276 | if( pCsr->bDesc==bDescDoclist ){ |
| 138277 | bEof = (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll)); |
| 138278 | while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ |
| 138279 | sqlite3Fts3DoclistNext( |
| 138280 | bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, |
| 138281 | &pIter, &iDocid, &bEof |
| 138282 | ); |
| @@ -138484,11 +138996,11 @@ | |
| 138484 | |
| 138485 | *ppVtab = (sqlite3_vtab *)p; |
| 138486 | return SQLITE_OK; |
| 138487 | |
| 138488 | bad_args: |
| 138489 | *pzErr = sqlite3_mprintf("invalid arguments to fts4aux constructor"); |
| 138490 | return SQLITE_ERROR; |
| 138491 | } |
| 138492 | |
| 138493 | /* |
| 138494 | ** This function does the work for both the xDisconnect and xDestroy methods. |
| @@ -139942,17 +140454,17 @@ | |
| 139942 | |
| 139943 | if( rc!=SQLITE_OK ){ |
| 139944 | sqlite3Fts3ExprFree(*ppExpr); |
| 139945 | *ppExpr = 0; |
| 139946 | if( rc==SQLITE_TOOBIG ){ |
| 139947 | *pzErr = sqlite3_mprintf( |
| 139948 | "FTS expression tree is too large (maximum depth %d)", |
| 139949 | SQLITE_FTS3_MAX_EXPR_DEPTH |
| 139950 | ); |
| 139951 | rc = SQLITE_ERROR; |
| 139952 | }else if( rc==SQLITE_ERROR ){ |
| 139953 | *pzErr = sqlite3_mprintf("malformed MATCH expression: [%s]", z); |
| 139954 | } |
| 139955 | } |
| 139956 | |
| 139957 | return rc; |
| 139958 | } |
| @@ -141424,11 +141936,11 @@ | |
| 141424 | z[n] = '\0'; |
| 141425 | sqlite3Fts3Dequote(z); |
| 141426 | |
| 141427 | m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1); |
| 141428 | if( !m ){ |
| 141429 | *pzErr = sqlite3_mprintf("unknown tokenizer: %s", z); |
| 141430 | rc = SQLITE_ERROR; |
| 141431 | }else{ |
| 141432 | char const **aArg = 0; |
| 141433 | int iArg = 0; |
| 141434 | z = &z[n+1]; |
| @@ -141447,11 +141959,11 @@ | |
| 141447 | z = &z[n+1]; |
| 141448 | } |
| 141449 | rc = m->xCreate(iArg, aArg, ppTok); |
| 141450 | assert( rc!=SQLITE_OK || *ppTok ); |
| 141451 | if( rc!=SQLITE_OK ){ |
| 141452 | *pzErr = sqlite3_mprintf("unknown tokenizer"); |
| 141453 | }else{ |
| 141454 | (*ppTok)->pModule = m; |
| 141455 | } |
| 141456 | sqlite3_free((void *)aArg); |
| 141457 | } |
| @@ -141531,13 +142043,13 @@ | |
| 141531 | |
| 141532 | pHash = (Fts3Hash *)sqlite3_user_data(context); |
| 141533 | p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1); |
| 141534 | |
| 141535 | if( !p ){ |
| 141536 | char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName); |
| 141537 | sqlite3_result_error(context, zErr, -1); |
| 141538 | sqlite3_free(zErr); |
| 141539 | return; |
| 141540 | } |
| 141541 | |
| 141542 | pRet = Tcl_NewObj(); |
| 141543 | Tcl_IncrRefCount(pRet); |
| @@ -142068,11 +142580,11 @@ | |
| 142068 | sqlite3_tokenizer_module *p; |
| 142069 | int nName = (int)strlen(zName); |
| 142070 | |
| 142071 | p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1); |
| 142072 | if( !p ){ |
| 142073 | *pzErr = sqlite3_mprintf("unknown tokenizer: %s", zName); |
| 142074 | return SQLITE_ERROR; |
| 142075 | } |
| 142076 | |
| 142077 | *pp = p; |
| 142078 | return SQLITE_OK; |
| @@ -142765,11 +143277,11 @@ | |
| 142765 | /* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)", |
| 142766 | /* 24 */ "", |
| 142767 | /* 25 */ "", |
| 142768 | |
| 142769 | /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?", |
| 142770 | /* 27 */ "SELECT DISTINCT level / (1024 * ?) FROM %Q.'%q_segdir'", |
| 142771 | |
| 142772 | /* This statement is used to determine which level to read the input from |
| 142773 | ** when performing an incremental merge. It returns the absolute level number |
| 142774 | ** of the oldest level in the db that contains at least ? segments. Or, |
| 142775 | ** if no level in the FTS index contains more than ? segments, the statement |
| @@ -145883,11 +146395,12 @@ | |
| 145883 | sqlite3_stmt *pAllLangid = 0; |
| 145884 | |
| 145885 | rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 145886 | if( rc==SQLITE_OK ){ |
| 145887 | int rc2; |
| 145888 | sqlite3_bind_int(pAllLangid, 1, p->nIndex); |
| 145889 | while( sqlite3_step(pAllLangid)==SQLITE_ROW ){ |
| 145890 | int i; |
| 145891 | int iLangid = sqlite3_column_int(pAllLangid, 0); |
| 145892 | for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){ |
| 145893 | rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL); |
| @@ -147215,11 +147728,11 @@ | |
| 147215 | while( i>0 && (pHint->a[i-1] & 0x80) ) i--; |
| 147216 | |
| 147217 | pHint->n = i; |
| 147218 | i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel); |
| 147219 | i += fts3GetVarint32(&pHint->a[i], pnInput); |
| 147220 | if( i!=nHint ) return SQLITE_CORRUPT_VTAB; |
| 147221 | |
| 147222 | return SQLITE_OK; |
| 147223 | } |
| 147224 | |
| 147225 | |
| @@ -147583,11 +148096,12 @@ | |
| 147583 | |
| 147584 | /* This block calculates the checksum according to the FTS index. */ |
| 147585 | rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 147586 | if( rc==SQLITE_OK ){ |
| 147587 | int rc2; |
| 147588 | sqlite3_bind_int(pAllLangid, 1, p->nIndex); |
| 147589 | while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){ |
| 147590 | int iLangid = sqlite3_column_int(pAllLangid, 0); |
| 147591 | int i; |
| 147592 | for(i=0; i<p->nIndex; i++){ |
| 147593 | cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc); |
| @@ -147596,11 +148110,10 @@ | |
| 147596 | rc2 = sqlite3_reset(pAllLangid); |
| 147597 | if( rc==SQLITE_OK ) rc = rc2; |
| 147598 | } |
| 147599 | |
| 147600 | /* This block calculates the checksum according to the %_content table */ |
| 147601 | rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 147602 | if( rc==SQLITE_OK ){ |
| 147603 | sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule; |
| 147604 | sqlite3_stmt *pStmt = 0; |
| 147605 | char *zSql; |
| 147606 | |
| @@ -147693,11 +148206,11 @@ | |
| 147693 | Fts3Table *p /* FTS3 table handle */ |
| 147694 | ){ |
| 147695 | int rc; |
| 147696 | int bOk = 0; |
| 147697 | rc = fts3IntegrityCheck(p, &bOk); |
| 147698 | if( rc==SQLITE_OK && bOk==0 ) rc = SQLITE_CORRUPT_VTAB; |
| 147699 | return rc; |
| 147700 | } |
| 147701 | |
| 147702 | /* |
| 147703 | ** Handle a 'special' INSERT of the form: |
| @@ -148131,10 +148644,11 @@ | |
| 148131 | #define FTS3_MATCHINFO_NDOC 'n' /* 1 value */ |
| 148132 | #define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */ |
| 148133 | #define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */ |
| 148134 | #define FTS3_MATCHINFO_LCS 's' /* nCol values */ |
| 148135 | #define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */ |
| 148136 | |
| 148137 | /* |
| 148138 | ** The default value for the second argument to matchinfo(). |
| 148139 | */ |
| 148140 | #define FTS3_MATCHINFO_DEFAULT "pcx" |
| @@ -148912,10 +149426,55 @@ | |
| 148912 | } |
| 148913 | } |
| 148914 | |
| 148915 | return rc; |
| 148916 | } |
| 148917 | |
| 148918 | static int fts3MatchinfoCheck( |
| 148919 | Fts3Table *pTab, |
| 148920 | char cArg, |
| 148921 | char **pzErr |
| @@ -148925,14 +149484,15 @@ | |
| 148925 | || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4) |
| 148926 | || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4) |
| 148927 | || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize) |
| 148928 | || (cArg==FTS3_MATCHINFO_LCS) |
| 148929 | || (cArg==FTS3_MATCHINFO_HITS) |
| 148930 | ){ |
| 148931 | return SQLITE_OK; |
| 148932 | } |
| 148933 | *pzErr = sqlite3_mprintf("unrecognized matchinfo request: %c", cArg); |
| 148934 | return SQLITE_ERROR; |
| 148935 | } |
| 148936 | |
| 148937 | static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){ |
| 148938 | int nVal; /* Number of integers output by cArg */ |
| @@ -148947,10 +149507,14 @@ | |
| 148947 | case FTS3_MATCHINFO_AVGLENGTH: |
| 148948 | case FTS3_MATCHINFO_LENGTH: |
| 148949 | case FTS3_MATCHINFO_LCS: |
| 148950 | nVal = pInfo->nCol; |
| 148951 | break; |
| 148952 | |
| 148953 | default: |
| 148954 | assert( cArg==FTS3_MATCHINFO_HITS ); |
| 148955 | nVal = pInfo->nCol * pInfo->nPhrase * 3; |
| 148956 | break; |
| @@ -149201,10 +149765,14 @@ | |
| 149201 | rc = fts3ExprLoadDoclists(pCsr, 0, 0); |
| 149202 | if( rc==SQLITE_OK ){ |
| 149203 | rc = fts3MatchinfoLcs(pCsr, pInfo); |
| 149204 | } |
| 149205 | break; |
| 149206 | |
| 149207 | default: { |
| 149208 | Fts3Expr *pExpr; |
| 149209 | assert( zArg[i]==FTS3_MATCHINFO_HITS ); |
| 149210 | pExpr = pCsr->pExpr; |
| @@ -153214,15 +153782,23 @@ | |
| 153214 | ** conflict-handling mode specified by the user. |
| 153215 | */ |
| 153216 | if( nData>1 ){ |
| 153217 | int ii; |
| 153218 | |
| 153219 | /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */ |
| 153220 | assert( nData==(pRtree->nDim*2 + 3) ); |
| 153221 | #ifndef SQLITE_RTREE_INT_ONLY |
| 153222 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 153223 | for(ii=0; ii<(pRtree->nDim*2); ii+=2){ |
| 153224 | cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]); |
| 153225 | cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]); |
| 153226 | if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){ |
| 153227 | rc = SQLITE_CONSTRAINT; |
| 153228 | goto constraint; |
| @@ -153229,11 +153805,11 @@ | |
| 153229 | } |
| 153230 | } |
| 153231 | }else |
| 153232 | #endif |
| 153233 | { |
| 153234 | for(ii=0; ii<(pRtree->nDim*2); ii+=2){ |
| 153235 | cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]); |
| 153236 | cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]); |
| 153237 | if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){ |
| 153238 | rc = SQLITE_CONSTRAINT; |
| 153239 | goto constraint; |
| @@ -154629,5 +155205,633 @@ | |
| 154629 | |
| 154630 | #endif /* defined(SQLITE_ENABLE_ICU) */ |
| 154631 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ |
| 154632 | |
| 154633 | /************** End of fts3_icu.c ********************************************/ |
| 154634 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.8.10. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -68,10 +68,11 @@ | |
| 68 | #if defined(_MSC_VER) |
| 69 | #pragma warning(disable : 4054) |
| 70 | #pragma warning(disable : 4055) |
| 71 | #pragma warning(disable : 4100) |
| 72 | #pragma warning(disable : 4127) |
| 73 | #pragma warning(disable : 4130) |
| 74 | #pragma warning(disable : 4152) |
| 75 | #pragma warning(disable : 4189) |
| 76 | #pragma warning(disable : 4206) |
| 77 | #pragma warning(disable : 4210) |
| 78 | #pragma warning(disable : 4232) |
| @@ -315,13 +316,13 @@ | |
| 316 | ** |
| 317 | ** See also: [sqlite3_libversion()], |
| 318 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 319 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 320 | */ |
| 321 | #define SQLITE_VERSION "3.8.10" |
| 322 | #define SQLITE_VERSION_NUMBER 3008010 |
| 323 | #define SQLITE_SOURCE_ID "2015-05-04 19:13:25 850c11866686a7b39d7b163fb60898c11283688e" |
| 324 | |
| 325 | /* |
| 326 | ** CAPI3REF: Run-Time Library Version Numbers |
| 327 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 328 | ** |
| @@ -474,10 +475,11 @@ | |
| 475 | # define double sqlite3_int64 |
| 476 | #endif |
| 477 | |
| 478 | /* |
| 479 | ** CAPI3REF: Closing A Database Connection |
| 480 | ** DESTRUCTOR: sqlite3 |
| 481 | ** |
| 482 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 483 | ** for the [sqlite3] object. |
| 484 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
| 485 | ** the [sqlite3] object is successfully destroyed and all associated |
| @@ -525,10 +527,11 @@ | |
| 527 | */ |
| 528 | typedef int (*sqlite3_callback)(void*,int,char**, char**); |
| 529 | |
| 530 | /* |
| 531 | ** CAPI3REF: One-Step Query Execution Interface |
| 532 | ** METHOD: sqlite3 |
| 533 | ** |
| 534 | ** The sqlite3_exec() interface is a convenience wrapper around |
| 535 | ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], |
| 536 | ** that allows an application to run multiple statements of SQL |
| 537 | ** without having to use a lot of C code. |
| @@ -1582,10 +1585,11 @@ | |
| 1585 | */ |
| 1586 | SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...); |
| 1587 | |
| 1588 | /* |
| 1589 | ** CAPI3REF: Configure database connections |
| 1590 | ** METHOD: sqlite3 |
| 1591 | ** |
| 1592 | ** The sqlite3_db_config() interface is used to make configuration |
| 1593 | ** changes to a [database connection]. The interface is similar to |
| 1594 | ** [sqlite3_config()] except that the changes apply to a single |
| 1595 | ** [database connection] (specified in the first argument). |
| @@ -2079,19 +2083,21 @@ | |
| 2083 | #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ |
| 2084 | |
| 2085 | |
| 2086 | /* |
| 2087 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
| 2088 | ** METHOD: sqlite3 |
| 2089 | ** |
| 2090 | ** ^The sqlite3_extended_result_codes() routine enables or disables the |
| 2091 | ** [extended result codes] feature of SQLite. ^The extended result |
| 2092 | ** codes are disabled by default for historical compatibility. |
| 2093 | */ |
| 2094 | SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff); |
| 2095 | |
| 2096 | /* |
| 2097 | ** CAPI3REF: Last Insert Rowid |
| 2098 | ** METHOD: sqlite3 |
| 2099 | ** |
| 2100 | ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) |
| 2101 | ** has a unique 64-bit signed |
| 2102 | ** integer key called the [ROWID | "rowid"]. ^The rowid is always available |
| 2103 | ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those |
| @@ -2139,10 +2145,11 @@ | |
| 2145 | */ |
| 2146 | SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*); |
| 2147 | |
| 2148 | /* |
| 2149 | ** CAPI3REF: Count The Number Of Rows Modified |
| 2150 | ** METHOD: sqlite3 |
| 2151 | ** |
| 2152 | ** ^This function returns the number of rows modified, inserted or |
| 2153 | ** deleted by the most recently completed INSERT, UPDATE or DELETE |
| 2154 | ** statement on the database connection specified by the only parameter. |
| 2155 | ** ^Executing any other type of SQL statement does not modify the value |
| @@ -2191,10 +2198,11 @@ | |
| 2198 | */ |
| 2199 | SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*); |
| 2200 | |
| 2201 | /* |
| 2202 | ** CAPI3REF: Total Number Of Rows Modified |
| 2203 | ** METHOD: sqlite3 |
| 2204 | ** |
| 2205 | ** ^This function returns the total number of rows inserted, modified or |
| 2206 | ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
| 2207 | ** since the database connection was opened, including those executed as |
| 2208 | ** part of trigger programs. ^Executing any other type of SQL statement |
| @@ -2214,10 +2222,11 @@ | |
| 2222 | */ |
| 2223 | SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*); |
| 2224 | |
| 2225 | /* |
| 2226 | ** CAPI3REF: Interrupt A Long-Running Query |
| 2227 | ** METHOD: sqlite3 |
| 2228 | ** |
| 2229 | ** ^This function causes any pending database operation to abort and |
| 2230 | ** return at its earliest opportunity. This routine is typically |
| 2231 | ** called in response to a user action such as pressing "Cancel" |
| 2232 | ** or Ctrl-C where the user wants a long query operation to halt |
| @@ -2290,10 +2299,11 @@ | |
| 2299 | SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql); |
| 2300 | |
| 2301 | /* |
| 2302 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2303 | ** KEYWORDS: {busy-handler callback} {busy handler} |
| 2304 | ** METHOD: sqlite3 |
| 2305 | ** |
| 2306 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2307 | ** that might be invoked with argument P whenever |
| 2308 | ** an attempt is made to access a database table associated with |
| 2309 | ** [database connection] D when another thread |
| @@ -2349,10 +2359,11 @@ | |
| 2359 | */ |
| 2360 | SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); |
| 2361 | |
| 2362 | /* |
| 2363 | ** CAPI3REF: Set A Busy Timeout |
| 2364 | ** METHOD: sqlite3 |
| 2365 | ** |
| 2366 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2367 | ** for a specified amount of time when a table is locked. ^The handler |
| 2368 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2369 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| @@ -2371,10 +2382,11 @@ | |
| 2382 | */ |
| 2383 | SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms); |
| 2384 | |
| 2385 | /* |
| 2386 | ** CAPI3REF: Convenience Routines For Running Queries |
| 2387 | ** METHOD: sqlite3 |
| 2388 | ** |
| 2389 | ** This is a legacy interface that is preserved for backwards compatibility. |
| 2390 | ** Use of this interface is not recommended. |
| 2391 | ** |
| 2392 | ** Definition: A <b>result table</b> is memory data structure created by the |
| @@ -2706,10 +2718,11 @@ | |
| 2718 | */ |
| 2719 | SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P); |
| 2720 | |
| 2721 | /* |
| 2722 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2723 | ** METHOD: sqlite3 |
| 2724 | ** |
| 2725 | ** ^This routine registers an authorizer callback with a particular |
| 2726 | ** [database connection], supplied in the first argument. |
| 2727 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2728 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| @@ -2862,10 +2875,11 @@ | |
| 2875 | #define SQLITE_COPY 0 /* No longer used */ |
| 2876 | #define SQLITE_RECURSIVE 33 /* NULL NULL */ |
| 2877 | |
| 2878 | /* |
| 2879 | ** CAPI3REF: Tracing And Profiling Functions |
| 2880 | ** METHOD: sqlite3 |
| 2881 | ** |
| 2882 | ** These routines register callback functions that can be used for |
| 2883 | ** tracing and profiling the execution of SQL statements. |
| 2884 | ** |
| 2885 | ** ^The callback function registered by sqlite3_trace() is invoked at |
| @@ -2894,10 +2908,11 @@ | |
| 2908 | SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*, |
| 2909 | void(*xProfile)(void*,const char*,sqlite3_uint64), void*); |
| 2910 | |
| 2911 | /* |
| 2912 | ** CAPI3REF: Query Progress Callbacks |
| 2913 | ** METHOD: sqlite3 |
| 2914 | ** |
| 2915 | ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback |
| 2916 | ** function X to be invoked periodically during long running calls to |
| 2917 | ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for |
| 2918 | ** database connection D. An example use for this |
| @@ -2927,10 +2942,11 @@ | |
| 2942 | */ |
| 2943 | SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2944 | |
| 2945 | /* |
| 2946 | ** CAPI3REF: Opening A New Database Connection |
| 2947 | ** CONSTRUCTOR: sqlite3 |
| 2948 | ** |
| 2949 | ** ^These routines open an SQLite database file as specified by the |
| 2950 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2951 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2952 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| @@ -3212,10 +3228,11 @@ | |
| 3228 | SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64); |
| 3229 | |
| 3230 | |
| 3231 | /* |
| 3232 | ** CAPI3REF: Error Codes And Messages |
| 3233 | ** METHOD: sqlite3 |
| 3234 | ** |
| 3235 | ** ^If the most recent sqlite3_* API call associated with |
| 3236 | ** [database connection] D failed, then the sqlite3_errcode(D) interface |
| 3237 | ** returns the numeric [result code] or [extended result code] for that |
| 3238 | ** API call. |
| @@ -3257,37 +3274,38 @@ | |
| 3274 | SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*); |
| 3275 | SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*); |
| 3276 | SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int); |
| 3277 | |
| 3278 | /* |
| 3279 | ** CAPI3REF: Prepared Statement Object |
| 3280 | ** KEYWORDS: {prepared statement} {prepared statements} |
| 3281 | ** |
| 3282 | ** An instance of this object represents a single SQL statement that |
| 3283 | ** has been compiled into binary form and is ready to be evaluated. |
| 3284 | ** |
| 3285 | ** Think of each SQL statement as a separate computer program. The |
| 3286 | ** original SQL text is source code. A prepared statement object |
| 3287 | ** is the compiled object code. All SQL must be converted into a |
| 3288 | ** prepared statement before it can be run. |
| 3289 | ** |
| 3290 | ** The life-cycle of a prepared statement object usually goes like this: |
| 3291 | ** |
| 3292 | ** <ol> |
| 3293 | ** <li> Create the prepared statement object using [sqlite3_prepare_v2()]. |
| 3294 | ** <li> Bind values to [parameters] using the sqlite3_bind_*() |
| 3295 | ** interfaces. |
| 3296 | ** <li> Run the SQL by calling [sqlite3_step()] one or more times. |
| 3297 | ** <li> Reset the prepared statement using [sqlite3_reset()] then go back |
| 3298 | ** to step 2. Do this zero or more times. |
| 3299 | ** <li> Destroy the object using [sqlite3_finalize()]. |
| 3300 | ** </ol> |
| 3301 | */ |
| 3302 | typedef struct sqlite3_stmt sqlite3_stmt; |
| 3303 | |
| 3304 | /* |
| 3305 | ** CAPI3REF: Run-time Limits |
| 3306 | ** METHOD: sqlite3 |
| 3307 | ** |
| 3308 | ** ^(This interface allows the size of various constructs to be limited |
| 3309 | ** on a connection by connection basis. The first parameter is the |
| 3310 | ** [database connection] whose limit is to be set or queried. The |
| 3311 | ** second parameter is one of the [limit categories] that define a |
| @@ -3395,10 +3413,12 @@ | |
| 3413 | #define SQLITE_LIMIT_WORKER_THREADS 11 |
| 3414 | |
| 3415 | /* |
| 3416 | ** CAPI3REF: Compiling An SQL Statement |
| 3417 | ** KEYWORDS: {SQL statement compiler} |
| 3418 | ** METHOD: sqlite3 |
| 3419 | ** CONSTRUCTOR: sqlite3_stmt |
| 3420 | ** |
| 3421 | ** To execute an SQL query, it must first be compiled into a byte-code |
| 3422 | ** program using one of these routines. |
| 3423 | ** |
| 3424 | ** The first argument, "db", is a [database connection] obtained from a |
| @@ -3502,19 +3522,21 @@ | |
| 3522 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3523 | ); |
| 3524 | |
| 3525 | /* |
| 3526 | ** CAPI3REF: Retrieving Statement SQL |
| 3527 | ** METHOD: sqlite3_stmt |
| 3528 | ** |
| 3529 | ** ^This interface can be used to retrieve a saved copy of the original |
| 3530 | ** SQL text used to create a [prepared statement] if that statement was |
| 3531 | ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. |
| 3532 | */ |
| 3533 | SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt); |
| 3534 | |
| 3535 | /* |
| 3536 | ** CAPI3REF: Determine If An SQL Statement Writes The Database |
| 3537 | ** METHOD: sqlite3_stmt |
| 3538 | ** |
| 3539 | ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if |
| 3540 | ** and only if the [prepared statement] X makes no direct changes to |
| 3541 | ** the content of the database file. |
| 3542 | ** |
| @@ -3542,10 +3564,11 @@ | |
| 3564 | */ |
| 3565 | SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
| 3566 | |
| 3567 | /* |
| 3568 | ** CAPI3REF: Determine If A Prepared Statement Has Been Reset |
| 3569 | ** METHOD: sqlite3_stmt |
| 3570 | ** |
| 3571 | ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the |
| 3572 | ** [prepared statement] S has been stepped at least once using |
| 3573 | ** [sqlite3_step(S)] but has not run to completion and/or has not |
| 3574 | ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) |
| @@ -3616,10 +3639,11 @@ | |
| 3639 | |
| 3640 | /* |
| 3641 | ** CAPI3REF: Binding Values To Prepared Statements |
| 3642 | ** KEYWORDS: {host parameter} {host parameters} {host parameter name} |
| 3643 | ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} |
| 3644 | ** METHOD: sqlite3_stmt |
| 3645 | ** |
| 3646 | ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, |
| 3647 | ** literals may be replaced by a [parameter] that matches one of following |
| 3648 | ** templates: |
| 3649 | ** |
| @@ -3734,10 +3758,11 @@ | |
| 3758 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); |
| 3759 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
| 3760 | |
| 3761 | /* |
| 3762 | ** CAPI3REF: Number Of SQL Parameters |
| 3763 | ** METHOD: sqlite3_stmt |
| 3764 | ** |
| 3765 | ** ^This routine can be used to find the number of [SQL parameters] |
| 3766 | ** in a [prepared statement]. SQL parameters are tokens of the |
| 3767 | ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as |
| 3768 | ** placeholders for values that are [sqlite3_bind_blob | bound] |
| @@ -3754,10 +3779,11 @@ | |
| 3779 | */ |
| 3780 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*); |
| 3781 | |
| 3782 | /* |
| 3783 | ** CAPI3REF: Name Of A Host Parameter |
| 3784 | ** METHOD: sqlite3_stmt |
| 3785 | ** |
| 3786 | ** ^The sqlite3_bind_parameter_name(P,N) interface returns |
| 3787 | ** the name of the N-th [SQL parameter] in the [prepared statement] P. |
| 3788 | ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| 3789 | ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| @@ -3781,10 +3807,11 @@ | |
| 3807 | */ |
| 3808 | SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int); |
| 3809 | |
| 3810 | /* |
| 3811 | ** CAPI3REF: Index Of A Parameter With A Given Name |
| 3812 | ** METHOD: sqlite3_stmt |
| 3813 | ** |
| 3814 | ** ^Return the index of an SQL parameter given its name. ^The |
| 3815 | ** index value returned is suitable for use as the second |
| 3816 | ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero |
| 3817 | ** is returned if no matching parameter is found. ^The parameter |
| @@ -3797,19 +3824,21 @@ | |
| 3824 | */ |
| 3825 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3826 | |
| 3827 | /* |
| 3828 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| 3829 | ** METHOD: sqlite3_stmt |
| 3830 | ** |
| 3831 | ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset |
| 3832 | ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. |
| 3833 | ** ^Use this routine to reset all host parameters to NULL. |
| 3834 | */ |
| 3835 | SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*); |
| 3836 | |
| 3837 | /* |
| 3838 | ** CAPI3REF: Number Of Columns In A Result Set |
| 3839 | ** METHOD: sqlite3_stmt |
| 3840 | ** |
| 3841 | ** ^Return the number of columns in the result set returned by the |
| 3842 | ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL |
| 3843 | ** statement that does not return data (for example an [UPDATE]). |
| 3844 | ** |
| @@ -3817,10 +3846,11 @@ | |
| 3846 | */ |
| 3847 | SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt); |
| 3848 | |
| 3849 | /* |
| 3850 | ** CAPI3REF: Column Names In A Result Set |
| 3851 | ** METHOD: sqlite3_stmt |
| 3852 | ** |
| 3853 | ** ^These routines return the name assigned to a particular column |
| 3854 | ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() |
| 3855 | ** interface returns a pointer to a zero-terminated UTF-8 string |
| 3856 | ** and sqlite3_column_name16() returns a pointer to a zero-terminated |
| @@ -3846,10 +3876,11 @@ | |
| 3876 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N); |
| 3877 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N); |
| 3878 | |
| 3879 | /* |
| 3880 | ** CAPI3REF: Source Of Data In A Query Result |
| 3881 | ** METHOD: sqlite3_stmt |
| 3882 | ** |
| 3883 | ** ^These routines provide a means to determine the database, table, and |
| 3884 | ** table column that is the origin of a particular result column in |
| 3885 | ** [SELECT] statement. |
| 3886 | ** ^The name of the database or table or column can be returned as |
| @@ -3898,10 +3929,11 @@ | |
| 3929 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int); |
| 3930 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int); |
| 3931 | |
| 3932 | /* |
| 3933 | ** CAPI3REF: Declared Datatype Of A Query Result |
| 3934 | ** METHOD: sqlite3_stmt |
| 3935 | ** |
| 3936 | ** ^(The first parameter is a [prepared statement]. |
| 3937 | ** If this statement is a [SELECT] statement and the Nth column of the |
| 3938 | ** returned result set of that [SELECT] is a table column (not an |
| 3939 | ** expression or subquery) then the declared type of the table |
| @@ -3930,10 +3962,11 @@ | |
| 3962 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int); |
| 3963 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int); |
| 3964 | |
| 3965 | /* |
| 3966 | ** CAPI3REF: Evaluate An SQL Statement |
| 3967 | ** METHOD: sqlite3_stmt |
| 3968 | ** |
| 3969 | ** After a [prepared statement] has been prepared using either |
| 3970 | ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy |
| 3971 | ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function |
| 3972 | ** must be called one or more times to evaluate the statement. |
| @@ -4009,10 +4042,11 @@ | |
| 4042 | */ |
| 4043 | SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*); |
| 4044 | |
| 4045 | /* |
| 4046 | ** CAPI3REF: Number of columns in a result set |
| 4047 | ** METHOD: sqlite3_stmt |
| 4048 | ** |
| 4049 | ** ^The sqlite3_data_count(P) interface returns the number of columns in the |
| 4050 | ** current row of the result set of [prepared statement] P. |
| 4051 | ** ^If prepared statement P does not have results ready to return |
| 4052 | ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of |
| @@ -4062,10 +4096,11 @@ | |
| 4096 | #define SQLITE3_TEXT 3 |
| 4097 | |
| 4098 | /* |
| 4099 | ** CAPI3REF: Result Values From A Query |
| 4100 | ** KEYWORDS: {column access functions} |
| 4101 | ** METHOD: sqlite3_stmt |
| 4102 | ** |
| 4103 | ** These routines form the "result set" interface. |
| 4104 | ** |
| 4105 | ** ^These routines return information about a single column of the current |
| 4106 | ** result row of a query. ^In every case the first argument is a pointer |
| @@ -4234,10 +4269,11 @@ | |
| 4269 | SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol); |
| 4270 | SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol); |
| 4271 | |
| 4272 | /* |
| 4273 | ** CAPI3REF: Destroy A Prepared Statement Object |
| 4274 | ** DESTRUCTOR: sqlite3_stmt |
| 4275 | ** |
| 4276 | ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. |
| 4277 | ** ^If the most recent evaluation of the statement encountered no errors |
| 4278 | ** or if the statement is never been evaluated, then sqlite3_finalize() returns |
| 4279 | ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then |
| @@ -4261,10 +4297,11 @@ | |
| 4297 | */ |
| 4298 | SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt); |
| 4299 | |
| 4300 | /* |
| 4301 | ** CAPI3REF: Reset A Prepared Statement Object |
| 4302 | ** METHOD: sqlite3_stmt |
| 4303 | ** |
| 4304 | ** The sqlite3_reset() function is called to reset a [prepared statement] |
| 4305 | ** object back to its initial state, ready to be re-executed. |
| 4306 | ** ^Any SQL statement variables that had values bound to them using |
| 4307 | ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. |
| @@ -4290,10 +4327,11 @@ | |
| 4327 | /* |
| 4328 | ** CAPI3REF: Create Or Redefine SQL Functions |
| 4329 | ** KEYWORDS: {function creation routines} |
| 4330 | ** KEYWORDS: {application-defined SQL function} |
| 4331 | ** KEYWORDS: {application-defined SQL functions} |
| 4332 | ** METHOD: sqlite3 |
| 4333 | ** |
| 4334 | ** ^These functions (collectively known as "function creation routines") |
| 4335 | ** are used to add SQL functions or aggregates or to redefine the behavior |
| 4336 | ** of existing SQL functions or aggregates. The only differences between |
| 4337 | ** these routines are the text encoding expected for |
| @@ -4459,10 +4497,11 @@ | |
| 4497 | void*,sqlite3_int64); |
| 4498 | #endif |
| 4499 | |
| 4500 | /* |
| 4501 | ** CAPI3REF: Obtaining SQL Function Parameter Values |
| 4502 | ** METHOD: sqlite3_value |
| 4503 | ** |
| 4504 | ** The C-language implementation of SQL functions and aggregates uses |
| 4505 | ** this set of interface routines to access the parameter values on |
| 4506 | ** the function or aggregate. |
| 4507 | ** |
| @@ -4517,10 +4556,11 @@ | |
| 4556 | SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*); |
| 4557 | SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*); |
| 4558 | |
| 4559 | /* |
| 4560 | ** CAPI3REF: Obtain Aggregate Function Context |
| 4561 | ** METHOD: sqlite3_context |
| 4562 | ** |
| 4563 | ** Implementations of aggregate SQL functions use this |
| 4564 | ** routine to allocate memory for storing their state. |
| 4565 | ** |
| 4566 | ** ^The first time the sqlite3_aggregate_context(C,N) routine is called |
| @@ -4561,10 +4601,11 @@ | |
| 4601 | */ |
| 4602 | SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes); |
| 4603 | |
| 4604 | /* |
| 4605 | ** CAPI3REF: User Data For Functions |
| 4606 | ** METHOD: sqlite3_context |
| 4607 | ** |
| 4608 | ** ^The sqlite3_user_data() interface returns a copy of |
| 4609 | ** the pointer that was the pUserData parameter (the 5th parameter) |
| 4610 | ** of the [sqlite3_create_function()] |
| 4611 | ** and [sqlite3_create_function16()] routines that originally |
| @@ -4575,10 +4616,11 @@ | |
| 4616 | */ |
| 4617 | SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*); |
| 4618 | |
| 4619 | /* |
| 4620 | ** CAPI3REF: Database Connection For Functions |
| 4621 | ** METHOD: sqlite3_context |
| 4622 | ** |
| 4623 | ** ^The sqlite3_context_db_handle() interface returns a copy of |
| 4624 | ** the pointer to the [database connection] (the 1st parameter) |
| 4625 | ** of the [sqlite3_create_function()] |
| 4626 | ** and [sqlite3_create_function16()] routines that originally |
| @@ -4586,10 +4628,11 @@ | |
| 4628 | */ |
| 4629 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*); |
| 4630 | |
| 4631 | /* |
| 4632 | ** CAPI3REF: Function Auxiliary Data |
| 4633 | ** METHOD: sqlite3_context |
| 4634 | ** |
| 4635 | ** These functions may be used by (non-aggregate) SQL functions to |
| 4636 | ** associate metadata with argument values. If the same value is passed to |
| 4637 | ** multiple invocations of the same SQL function during query execution, under |
| 4638 | ** some circumstances the associated metadata may be preserved. An example |
| @@ -4658,10 +4701,11 @@ | |
| 4701 | #define SQLITE_STATIC ((sqlite3_destructor_type)0) |
| 4702 | #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) |
| 4703 | |
| 4704 | /* |
| 4705 | ** CAPI3REF: Setting The Result Of An SQL Function |
| 4706 | ** METHOD: sqlite3_context |
| 4707 | ** |
| 4708 | ** These routines are used by the xFunc or xFinal callbacks that |
| 4709 | ** implement SQL functions and aggregates. See |
| 4710 | ** [sqlite3_create_function()] and [sqlite3_create_function16()] |
| 4711 | ** for additional information. |
| @@ -4793,10 +4837,11 @@ | |
| 4837 | SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*); |
| 4838 | SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n); |
| 4839 | |
| 4840 | /* |
| 4841 | ** CAPI3REF: Define New Collating Sequences |
| 4842 | ** METHOD: sqlite3 |
| 4843 | ** |
| 4844 | ** ^These functions add, remove, or modify a [collation] associated |
| 4845 | ** with the [database connection] specified as the first argument. |
| 4846 | ** |
| 4847 | ** ^The name of the collation is a UTF-8 string |
| @@ -4895,10 +4940,11 @@ | |
| 4940 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 4941 | ); |
| 4942 | |
| 4943 | /* |
| 4944 | ** CAPI3REF: Collation Needed Callbacks |
| 4945 | ** METHOD: sqlite3 |
| 4946 | ** |
| 4947 | ** ^To avoid having to register all collation sequences before a database |
| 4948 | ** can be used, a single callback function may be registered with the |
| 4949 | ** [database connection] to be invoked whenever an undefined collation |
| 4950 | ** sequence is required. |
| @@ -5102,10 +5148,11 @@ | |
| 5148 | SQLITE_API char *sqlite3_data_directory; |
| 5149 | |
| 5150 | /* |
| 5151 | ** CAPI3REF: Test For Auto-Commit Mode |
| 5152 | ** KEYWORDS: {autocommit mode} |
| 5153 | ** METHOD: sqlite3 |
| 5154 | ** |
| 5155 | ** ^The sqlite3_get_autocommit() interface returns non-zero or |
| 5156 | ** zero if the given database connection is or is not in autocommit mode, |
| 5157 | ** respectively. ^Autocommit mode is on by default. |
| 5158 | ** ^Autocommit mode is disabled by a [BEGIN] statement. |
| @@ -5124,10 +5171,11 @@ | |
| 5171 | */ |
| 5172 | SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*); |
| 5173 | |
| 5174 | /* |
| 5175 | ** CAPI3REF: Find The Database Handle Of A Prepared Statement |
| 5176 | ** METHOD: sqlite3_stmt |
| 5177 | ** |
| 5178 | ** ^The sqlite3_db_handle interface returns the [database connection] handle |
| 5179 | ** to which a [prepared statement] belongs. ^The [database connection] |
| 5180 | ** returned by sqlite3_db_handle is the same [database connection] |
| 5181 | ** that was the first argument |
| @@ -5136,10 +5184,11 @@ | |
| 5184 | */ |
| 5185 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*); |
| 5186 | |
| 5187 | /* |
| 5188 | ** CAPI3REF: Return The Filename For A Database Connection |
| 5189 | ** METHOD: sqlite3 |
| 5190 | ** |
| 5191 | ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename |
| 5192 | ** associated with database N of connection D. ^The main database file |
| 5193 | ** has the name "main". If there is no attached database N on the database |
| 5194 | ** connection D, or if database N is a temporary or in-memory database, then |
| @@ -5152,19 +5201,21 @@ | |
| 5201 | */ |
| 5202 | SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
| 5203 | |
| 5204 | /* |
| 5205 | ** CAPI3REF: Determine if a database is read-only |
| 5206 | ** METHOD: sqlite3 |
| 5207 | ** |
| 5208 | ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N |
| 5209 | ** of connection D is read-only, 0 if it is read/write, or -1 if N is not |
| 5210 | ** the name of a database on connection D. |
| 5211 | */ |
| 5212 | SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName); |
| 5213 | |
| 5214 | /* |
| 5215 | ** CAPI3REF: Find the next prepared statement |
| 5216 | ** METHOD: sqlite3 |
| 5217 | ** |
| 5218 | ** ^This interface returns a pointer to the next [prepared statement] after |
| 5219 | ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL |
| 5220 | ** then this interface returns a pointer to the first prepared statement |
| 5221 | ** associated with the database connection pDb. ^If no prepared statement |
| @@ -5176,10 +5227,11 @@ | |
| 5227 | */ |
| 5228 | SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); |
| 5229 | |
| 5230 | /* |
| 5231 | ** CAPI3REF: Commit And Rollback Notification Callbacks |
| 5232 | ** METHOD: sqlite3 |
| 5233 | ** |
| 5234 | ** ^The sqlite3_commit_hook() interface registers a callback |
| 5235 | ** function to be invoked whenever a transaction is [COMMIT | committed]. |
| 5236 | ** ^Any callback set by a previous call to sqlite3_commit_hook() |
| 5237 | ** for the same database connection is overridden. |
| @@ -5225,10 +5277,11 @@ | |
| 5277 | SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); |
| 5278 | SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); |
| 5279 | |
| 5280 | /* |
| 5281 | ** CAPI3REF: Data Change Notification Callbacks |
| 5282 | ** METHOD: sqlite3 |
| 5283 | ** |
| 5284 | ** ^The sqlite3_update_hook() interface registers a callback function |
| 5285 | ** with the [database connection] identified by the first argument |
| 5286 | ** to be invoked whenever a row is updated, inserted or deleted in |
| 5287 | ** a rowid table. |
| @@ -5331,10 +5384,11 @@ | |
| 5384 | */ |
| 5385 | SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int); |
| 5386 | |
| 5387 | /* |
| 5388 | ** CAPI3REF: Free Memory Used By A Database Connection |
| 5389 | ** METHOD: sqlite3 |
| 5390 | ** |
| 5391 | ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap |
| 5392 | ** memory as possible from database connection D. Unlike the |
| 5393 | ** [sqlite3_release_memory()] interface, this interface is in effect even |
| 5394 | ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is |
| @@ -5408,10 +5462,11 @@ | |
| 5462 | SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N); |
| 5463 | |
| 5464 | |
| 5465 | /* |
| 5466 | ** CAPI3REF: Extract Metadata About A Column Of A Table |
| 5467 | ** METHOD: sqlite3 |
| 5468 | ** |
| 5469 | ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns |
| 5470 | ** information about column C of table T in database D |
| 5471 | ** on [database connection] X.)^ ^The sqlite3_table_column_metadata() |
| 5472 | ** interface returns SQLITE_OK and fills in the non-NULL pointers in |
| @@ -5486,10 +5541,11 @@ | |
| 5541 | int *pAutoinc /* OUTPUT: True if column is auto-increment */ |
| 5542 | ); |
| 5543 | |
| 5544 | /* |
| 5545 | ** CAPI3REF: Load An Extension |
| 5546 | ** METHOD: sqlite3 |
| 5547 | ** |
| 5548 | ** ^This interface loads an SQLite extension library from the named file. |
| 5549 | ** |
| 5550 | ** ^The sqlite3_load_extension() interface attempts to load an |
| 5551 | ** [SQLite extension] library contained in the file zFile. If |
| @@ -5527,10 +5583,11 @@ | |
| 5583 | char **pzErrMsg /* Put error message here if not 0 */ |
| 5584 | ); |
| 5585 | |
| 5586 | /* |
| 5587 | ** CAPI3REF: Enable Or Disable Extension Loading |
| 5588 | ** METHOD: sqlite3 |
| 5589 | ** |
| 5590 | ** ^So as not to open security holes in older applications that are |
| 5591 | ** unprepared to deal with [extension loading], and as a means of disabling |
| 5592 | ** [extension loading] while evaluating user-entered SQL, the following API |
| 5593 | ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. |
| @@ -5776,10 +5833,11 @@ | |
| 5833 | #define SQLITE_INDEX_CONSTRAINT_GE 32 |
| 5834 | #define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
| 5835 | |
| 5836 | /* |
| 5837 | ** CAPI3REF: Register A Virtual Table Implementation |
| 5838 | ** METHOD: sqlite3 |
| 5839 | ** |
| 5840 | ** ^These routines are used to register a new [virtual table module] name. |
| 5841 | ** ^Module names must be registered before |
| 5842 | ** creating a new [virtual table] using the module and before using a |
| 5843 | ** preexisting [virtual table] for the module. |
| @@ -5872,10 +5930,11 @@ | |
| 5930 | */ |
| 5931 | SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL); |
| 5932 | |
| 5933 | /* |
| 5934 | ** CAPI3REF: Overload A Function For A Virtual Table |
| 5935 | ** METHOD: sqlite3 |
| 5936 | ** |
| 5937 | ** ^(Virtual tables can provide alternative implementations of functions |
| 5938 | ** using the [xFindFunction] method of the [virtual table module]. |
| 5939 | ** But global versions of those functions |
| 5940 | ** must exist in order to be overloaded.)^ |
| @@ -5914,10 +5973,12 @@ | |
| 5973 | */ |
| 5974 | typedef struct sqlite3_blob sqlite3_blob; |
| 5975 | |
| 5976 | /* |
| 5977 | ** CAPI3REF: Open A BLOB For Incremental I/O |
| 5978 | ** METHOD: sqlite3 |
| 5979 | ** CONSTRUCTOR: sqlite3_blob |
| 5980 | ** |
| 5981 | ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located |
| 5982 | ** in row iRow, column zColumn, table zTable in database zDb; |
| 5983 | ** in other words, the same BLOB that would be selected by: |
| 5984 | ** |
| @@ -5995,10 +6056,11 @@ | |
| 6056 | sqlite3_blob **ppBlob |
| 6057 | ); |
| 6058 | |
| 6059 | /* |
| 6060 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 6061 | ** METHOD: sqlite3_blob |
| 6062 | ** |
| 6063 | ** ^This function is used to move an existing blob handle so that it points |
| 6064 | ** to a different row of the same database table. ^The new row is identified |
| 6065 | ** by the rowid value passed as the second argument. Only the row can be |
| 6066 | ** changed. ^The database, table and column on which the blob handle is open |
| @@ -6019,10 +6081,11 @@ | |
| 6081 | */ |
| 6082 | SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 6083 | |
| 6084 | /* |
| 6085 | ** CAPI3REF: Close A BLOB Handle |
| 6086 | ** DESTRUCTOR: sqlite3_blob |
| 6087 | ** |
| 6088 | ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed |
| 6089 | ** unconditionally. Even if this routine returns an error code, the |
| 6090 | ** handle is still closed.)^ |
| 6091 | ** |
| @@ -6041,10 +6104,11 @@ | |
| 6104 | */ |
| 6105 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *); |
| 6106 | |
| 6107 | /* |
| 6108 | ** CAPI3REF: Return The Size Of An Open BLOB |
| 6109 | ** METHOD: sqlite3_blob |
| 6110 | ** |
| 6111 | ** ^Returns the size in bytes of the BLOB accessible via the |
| 6112 | ** successfully opened [BLOB handle] in its only argument. ^The |
| 6113 | ** incremental blob I/O routines can only read or overwriting existing |
| 6114 | ** blob content; they cannot change the size of a blob. |
| @@ -6056,10 +6120,11 @@ | |
| 6120 | */ |
| 6121 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *); |
| 6122 | |
| 6123 | /* |
| 6124 | ** CAPI3REF: Read Data From A BLOB Incrementally |
| 6125 | ** METHOD: sqlite3_blob |
| 6126 | ** |
| 6127 | ** ^(This function is used to read data from an open [BLOB handle] into a |
| 6128 | ** caller-supplied buffer. N bytes of data are copied into buffer Z |
| 6129 | ** from the open BLOB, starting at offset iOffset.)^ |
| 6130 | ** |
| @@ -6084,10 +6149,11 @@ | |
| 6149 | */ |
| 6150 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 6151 | |
| 6152 | /* |
| 6153 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 6154 | ** METHOD: sqlite3_blob |
| 6155 | ** |
| 6156 | ** ^(This function is used to write data into an open [BLOB handle] from a |
| 6157 | ** caller-supplied buffer. N bytes of data are copied from the buffer Z |
| 6158 | ** into the open BLOB, starting at offset iOffset.)^ |
| 6159 | ** |
| @@ -6411,10 +6477,11 @@ | |
| 6477 | #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ |
| 6478 | #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ |
| 6479 | |
| 6480 | /* |
| 6481 | ** CAPI3REF: Retrieve the mutex for a database connection |
| 6482 | ** METHOD: sqlite3 |
| 6483 | ** |
| 6484 | ** ^This interface returns a pointer the [sqlite3_mutex] object that |
| 6485 | ** serializes access to the [database connection] given in the argument |
| 6486 | ** when the [threading mode] is Serialized. |
| 6487 | ** ^If the [threading mode] is Single-thread or Multi-thread then this |
| @@ -6422,10 +6489,11 @@ | |
| 6489 | */ |
| 6490 | SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*); |
| 6491 | |
| 6492 | /* |
| 6493 | ** CAPI3REF: Low-Level Control Of Database Files |
| 6494 | ** METHOD: sqlite3 |
| 6495 | ** |
| 6496 | ** ^The [sqlite3_file_control()] interface makes a direct call to the |
| 6497 | ** xFileControl method for the [sqlite3_io_methods] object associated |
| 6498 | ** with a particular database identified by the second argument. ^The |
| 6499 | ** name of the database is "main" for the main database or "temp" for the |
| @@ -6638,10 +6706,11 @@ | |
| 6706 | #define SQLITE_STATUS_SCRATCH_SIZE 8 |
| 6707 | #define SQLITE_STATUS_MALLOC_COUNT 9 |
| 6708 | |
| 6709 | /* |
| 6710 | ** CAPI3REF: Database Connection Status |
| 6711 | ** METHOD: sqlite3 |
| 6712 | ** |
| 6713 | ** ^This interface is used to retrieve runtime status information |
| 6714 | ** about a single [database connection]. ^The first argument is the |
| 6715 | ** database connection object to be interrogated. ^The second argument |
| 6716 | ** is an integer constant, taken from the set of |
| @@ -6766,10 +6835,11 @@ | |
| 6835 | #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */ |
| 6836 | |
| 6837 | |
| 6838 | /* |
| 6839 | ** CAPI3REF: Prepared Statement Status |
| 6840 | ** METHOD: sqlite3_stmt |
| 6841 | ** |
| 6842 | ** ^(Each prepared statement maintains various |
| 6843 | ** [SQLITE_STMTSTATUS counters] that measure the number |
| 6844 | ** of times it has performed specific operations.)^ These counters can |
| 6845 | ** be used to monitor the performance characteristics of the prepared |
| @@ -7269,10 +7339,11 @@ | |
| 7339 | SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p); |
| 7340 | SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p); |
| 7341 | |
| 7342 | /* |
| 7343 | ** CAPI3REF: Unlock Notification |
| 7344 | ** METHOD: sqlite3 |
| 7345 | ** |
| 7346 | ** ^When running in shared-cache mode, a database operation may fail with |
| 7347 | ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or |
| 7348 | ** individual tables within the shared-cache cannot be obtained. See |
| 7349 | ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. |
| @@ -7439,10 +7510,11 @@ | |
| 7510 | */ |
| 7511 | SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...); |
| 7512 | |
| 7513 | /* |
| 7514 | ** CAPI3REF: Write-Ahead Log Commit Hook |
| 7515 | ** METHOD: sqlite3 |
| 7516 | ** |
| 7517 | ** ^The [sqlite3_wal_hook()] function is used to register a callback that |
| 7518 | ** is invoked each time data is committed to a database in wal mode. |
| 7519 | ** |
| 7520 | ** ^(The callback is invoked by SQLite after the commit has taken place and |
| @@ -7478,10 +7550,11 @@ | |
| 7550 | void* |
| 7551 | ); |
| 7552 | |
| 7553 | /* |
| 7554 | ** CAPI3REF: Configure an auto-checkpoint |
| 7555 | ** METHOD: sqlite3 |
| 7556 | ** |
| 7557 | ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around |
| 7558 | ** [sqlite3_wal_hook()] that causes any database on [database connection] D |
| 7559 | ** to automatically [checkpoint] |
| 7560 | ** after committing a transaction if there are N or |
| @@ -7508,10 +7581,11 @@ | |
| 7581 | */ |
| 7582 | SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7583 | |
| 7584 | /* |
| 7585 | ** CAPI3REF: Checkpoint a database |
| 7586 | ** METHOD: sqlite3 |
| 7587 | ** |
| 7588 | ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to |
| 7589 | ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ |
| 7590 | ** |
| 7591 | ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the |
| @@ -7529,10 +7603,11 @@ | |
| 7603 | */ |
| 7604 | SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7605 | |
| 7606 | /* |
| 7607 | ** CAPI3REF: Checkpoint a database |
| 7608 | ** METHOD: sqlite3 |
| 7609 | ** |
| 7610 | ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint |
| 7611 | ** operation on database X of [database connection] D in mode M. Status |
| 7612 | ** information is written back into integers pointed to by L and C.)^ |
| 7613 | ** ^(The M parameter must be a valid [checkpoint mode]:)^ |
| @@ -7783,10 +7858,11 @@ | |
| 7858 | #define SQLITE_SCANSTAT_EXPLAIN 4 |
| 7859 | #define SQLITE_SCANSTAT_SELECTID 5 |
| 7860 | |
| 7861 | /* |
| 7862 | ** CAPI3REF: Prepared Statement Scan Status |
| 7863 | ** METHOD: sqlite3_stmt |
| 7864 | ** |
| 7865 | ** This interface returns information about the predicted and measured |
| 7866 | ** performance for pStmt. Advanced applications can use this |
| 7867 | ** interface to compare the predicted and the measured performance and |
| 7868 | ** issue warnings and/or rerun [ANALYZE] if discrepancies are found. |
| @@ -7820,10 +7896,11 @@ | |
| 7896 | void *pOut /* Result written here */ |
| 7897 | ); |
| 7898 | |
| 7899 | /* |
| 7900 | ** CAPI3REF: Zero Scan-Status Counters |
| 7901 | ** METHOD: sqlite3_stmt |
| 7902 | ** |
| 7903 | ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. |
| 7904 | ** |
| 7905 | ** This API is only available if the library is built with pre-processor |
| 7906 | ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| @@ -8430,10 +8507,36 @@ | |
| 8507 | #else |
| 8508 | # define ALWAYS(X) (X) |
| 8509 | # define NEVER(X) (X) |
| 8510 | #endif |
| 8511 | |
| 8512 | /* |
| 8513 | ** Declarations used for tracing the operating system interfaces. |
| 8514 | */ |
| 8515 | #if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \ |
| 8516 | (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) |
| 8517 | extern int sqlite3OSTrace; |
| 8518 | # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X |
| 8519 | # define SQLITE_HAVE_OS_TRACE |
| 8520 | #else |
| 8521 | # define OSTRACE(X) |
| 8522 | # undef SQLITE_HAVE_OS_TRACE |
| 8523 | #endif |
| 8524 | |
| 8525 | /* |
| 8526 | ** Is the sqlite3ErrName() function needed in the build? Currently, |
| 8527 | ** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when |
| 8528 | ** OSTRACE is enabled), and by several "test*.c" files (which are |
| 8529 | ** compiled using SQLITE_TEST). |
| 8530 | */ |
| 8531 | #if defined(SQLITE_HAVE_OS_TRACE) || defined(SQLITE_TEST) || \ |
| 8532 | (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) |
| 8533 | # define SQLITE_NEED_ERR_NAME |
| 8534 | #else |
| 8535 | # undef SQLITE_NEED_ERR_NAME |
| 8536 | #endif |
| 8537 | |
| 8538 | /* |
| 8539 | ** Return true (non-zero) if the input is an integer that is too large |
| 8540 | ** to fit in 32-bits. This macro is used inside of various testcase() |
| 8541 | ** macros to verify that we have tested SQLite for large-file support. |
| 8542 | */ |
| @@ -9841,37 +9944,36 @@ | |
| 9944 | /* Properties such as "out2" or "jump" that are specified in |
| 9945 | ** comments following the "case" for each opcode in the vdbe.c |
| 9946 | ** are encoded into bitvectors as follows: |
| 9947 | */ |
| 9948 | #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */ |
| 9949 | #define OPFLG_IN1 0x0002 /* in1: P1 is an input */ |
| 9950 | #define OPFLG_IN2 0x0004 /* in2: P2 is an input */ |
| 9951 | #define OPFLG_IN3 0x0008 /* in3: P3 is an input */ |
| 9952 | #define OPFLG_OUT2 0x0010 /* out2: P2 is an output */ |
| 9953 | #define OPFLG_OUT3 0x0020 /* out3: P3 is an output */ |
| 9954 | #define OPFLG_INITIALIZER {\ |
| 9955 | /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\ |
| 9956 | /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\ |
| 9957 | /* 16 */ 0x01, 0x01, 0x02, 0x12, 0x01, 0x02, 0x03, 0x08,\ |
| 9958 | /* 24 */ 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10,\ |
| 9959 | /* 32 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x03, 0x02,\ |
| 9960 | /* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\ |
| 9961 | /* 48 */ 0x00, 0x00, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,\ |
| 9962 | /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09,\ |
| 9963 | /* 64 */ 0x09, 0x09, 0x04, 0x09, 0x09, 0x09, 0x09, 0x26,\ |
| 9964 | /* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\ |
| 9965 | /* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\ |
| 9966 | /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\ |
| 9967 | /* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\ |
| 9968 | /* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\ |
| 9969 | /* 112 */ 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00, 0x00,\ |
| 9970 | /* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 9971 | /* 128 */ 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00, 0x01,\ |
| 9972 | /* 136 */ 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x01,\ |
| 9973 | /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\ |
| 9974 | /* 152 */ 0x00, 0x10, 0x10, 0x01, 0x00, 0x00,} |
| 9975 | |
| 9976 | /************** End of opcodes.h *********************************************/ |
| 9977 | /************** Continuing where we left off in vdbe.h ***********************/ |
| 9978 | |
| 9979 | /* |
| @@ -9926,10 +10028,11 @@ | |
| 10028 | #endif |
| 10029 | SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); |
| 10030 | |
| 10031 | SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*); |
| 10032 | SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*); |
| 10033 | SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int); |
| 10034 | SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **); |
| 10035 | |
| 10036 | typedef int (*RecordCompare)(int,const void*,UnpackedRecord*); |
| 10037 | SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*); |
| 10038 | |
| @@ -11063,10 +11166,11 @@ | |
| 11166 | #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */ |
| 11167 | #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */ |
| 11168 | #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */ |
| 11169 | #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */ |
| 11170 | #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */ |
| 11171 | #define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */ |
| 11172 | |
| 11173 | |
| 11174 | /* |
| 11175 | ** Bits of the sqlite3.dbOptFlags field that are used by the |
| 11176 | ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to |
| @@ -11393,38 +11497,12 @@ | |
| 11497 | int iSavepoint; /* Depth of the SAVEPOINT stack */ |
| 11498 | VTable *pNext; /* Next in linked list (see above) */ |
| 11499 | }; |
| 11500 | |
| 11501 | /* |
| 11502 | ** The schema for each SQL table and view is represented in memory |
| 11503 | ** by an instance of the following structure. |
| 11504 | */ |
| 11505 | struct Table { |
| 11506 | char *zName; /* Name of the table or view */ |
| 11507 | Column *aCol; /* Information about each column */ |
| 11508 | Index *pIndex; /* List of SQL indexes on this table. */ |
| @@ -11432,15 +11510,15 @@ | |
| 11510 | FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| 11511 | char *zColAff; /* String defining the affinity of each column */ |
| 11512 | #ifndef SQLITE_OMIT_CHECK |
| 11513 | ExprList *pCheck; /* All CHECK constraints */ |
| 11514 | #endif |
| 11515 | int tnum; /* Root BTree page for this table */ |
| 11516 | i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */ |
| 11517 | i16 nCol; /* Number of columns in this table */ |
| 11518 | u16 nRef; /* Number of pointers to this Table */ |
| 11519 | LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */ |
| 11520 | LogEst szTabRow; /* Estimated size of each table row in bytes */ |
| 11521 | #ifdef SQLITE_ENABLE_COSTMULT |
| 11522 | LogEst costMult; /* Cost multiplier for using this table */ |
| 11523 | #endif |
| 11524 | u8 tabFlags; /* Mask of TF_* values */ |
| @@ -11458,17 +11536,24 @@ | |
| 11536 | Table *pNextZombie; /* Next on the Parse.pZombieTab list */ |
| 11537 | }; |
| 11538 | |
| 11539 | /* |
| 11540 | ** Allowed values for Table.tabFlags. |
| 11541 | ** |
| 11542 | ** TF_OOOHidden applies to virtual tables that have hidden columns that are |
| 11543 | ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING |
| 11544 | ** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden, |
| 11545 | ** the TF_OOOHidden attribute would apply in this case. Such tables require |
| 11546 | ** special handling during INSERT processing. |
| 11547 | */ |
| 11548 | #define TF_Readonly 0x01 /* Read-only system table */ |
| 11549 | #define TF_Ephemeral 0x02 /* An ephemeral table */ |
| 11550 | #define TF_HasPrimaryKey 0x04 /* Table has a primary key */ |
| 11551 | #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */ |
| 11552 | #define TF_Virtual 0x10 /* Is a virtual table */ |
| 11553 | #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */ |
| 11554 | #define TF_OOOHidden 0x40 /* Out-of-Order hidden columns */ |
| 11555 | |
| 11556 | |
| 11557 | /* |
| 11558 | ** Test to see whether or not a table is a virtual table. This is |
| 11559 | ** done as a macro so that it will be optimized out when virtual |
| @@ -12221,11 +12306,11 @@ | |
| 12306 | #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */ |
| 12307 | #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */ |
| 12308 | #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ |
| 12309 | #define SF_Compound 0x0040 /* Part of a compound query */ |
| 12310 | #define SF_Values 0x0080 /* Synthesized from VALUES clause */ |
| 12311 | #define SF_MultiValue 0x0100 /* Single VALUES term with multiple rows */ |
| 12312 | #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */ |
| 12313 | #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */ |
| 12314 | #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */ |
| 12315 | #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */ |
| 12316 | #define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */ |
| @@ -12605,24 +12690,24 @@ | |
| 12690 | * |
| 12691 | * (op == TK_INSERT) |
| 12692 | * orconf -> stores the ON CONFLICT algorithm |
| 12693 | * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then |
| 12694 | * this stores a pointer to the SELECT statement. Otherwise NULL. |
| 12695 | * zTarget -> Dequoted name of the table to insert into. |
| 12696 | * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then |
| 12697 | * this stores values to be inserted. Otherwise NULL. |
| 12698 | * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ... |
| 12699 | * statement, then this stores the column-names to be |
| 12700 | * inserted into. |
| 12701 | * |
| 12702 | * (op == TK_DELETE) |
| 12703 | * zTarget -> Dequoted name of the table to delete from. |
| 12704 | * pWhere -> The WHERE clause of the DELETE statement if one is specified. |
| 12705 | * Otherwise NULL. |
| 12706 | * |
| 12707 | * (op == TK_UPDATE) |
| 12708 | * zTarget -> Dequoted name of the table to update. |
| 12709 | * pWhere -> The WHERE clause of the UPDATE statement if one is specified. |
| 12710 | * Otherwise NULL. |
| 12711 | * pExprList -> A list of the columns to update and the expressions to update |
| 12712 | * them to. See sqlite3Update() documentation of "pChanges" |
| 12713 | * argument. |
| @@ -12630,12 +12715,12 @@ | |
| 12715 | */ |
| 12716 | struct TriggerStep { |
| 12717 | u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */ |
| 12718 | u8 orconf; /* OE_Rollback etc. */ |
| 12719 | Trigger *pTrig; /* The trigger that this step is a part of */ |
| 12720 | Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */ |
| 12721 | char *zTarget; /* Target table for DELETE, UPDATE, INSERT */ |
| 12722 | Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ |
| 12723 | ExprList *pExprList; /* SET clause for UPDATE. */ |
| 12724 | IdList *pIdList; /* Column names for INSERT */ |
| 12725 | TriggerStep *pNext; /* Next in the link-list */ |
| 12726 | TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ |
| @@ -12664,12 +12749,11 @@ | |
| 12749 | sqlite3 *db; /* Optional database for lookaside. Can be NULL */ |
| 12750 | char *zBase; /* A base allocation. Not from malloc. */ |
| 12751 | char *zText; /* The string collected so far */ |
| 12752 | int nChar; /* Length of the string so far */ |
| 12753 | int nAlloc; /* Amount of space allocated in zText */ |
| 12754 | int mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */ |
| 12755 | u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */ |
| 12756 | }; |
| 12757 | #define STRACCUM_NOMEM 1 |
| 12758 | #define STRACCUM_TOOBIG 2 |
| 12759 | |
| @@ -12982,11 +13066,11 @@ | |
| 13066 | SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list); |
| 13067 | SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...); |
| 13068 | SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 13069 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
| 13070 | SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...); |
| 13071 | #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 13072 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...); |
| 13073 | #endif |
| 13074 | #if defined(SQLITE_TEST) |
| 13075 | SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*); |
| 13076 | #endif |
| @@ -13329,11 +13413,11 @@ | |
| 13413 | SQLITE_PRIVATE void sqlite3Error(sqlite3*,int); |
| 13414 | SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n); |
| 13415 | SQLITE_PRIVATE u8 sqlite3HexToInt(int h); |
| 13416 | SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
| 13417 | |
| 13418 | #if defined(SQLITE_NEED_ERR_NAME) |
| 13419 | SQLITE_PRIVATE const char *sqlite3ErrName(int); |
| 13420 | #endif |
| 13421 | |
| 13422 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 13423 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| @@ -13423,11 +13507,11 @@ | |
| 13507 | FuncDestructor *pDestructor |
| 13508 | ); |
| 13509 | SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); |
| 13510 | SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); |
| 13511 | |
| 13512 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int); |
| 13513 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int); |
| 13514 | SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*); |
| 13515 | SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char); |
| 13516 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 13517 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*); |
| @@ -19807,20 +19891,10 @@ | |
| 19891 | */ |
| 19892 | #ifdef MEMORY_DEBUG |
| 19893 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 19894 | #endif |
| 19895 | |
| 19896 | /* |
| 19897 | ** Macros for performance tracing. Normally turned off. Only works |
| 19898 | ** on i486 hardware. |
| 19899 | */ |
| 19900 | #ifdef SQLITE_PERFORMANCE_TRACE |
| @@ -21401,10 +21475,11 @@ | |
| 21475 | |
| 21476 | /* |
| 21477 | ** Set the StrAccum object to an error mode. |
| 21478 | */ |
| 21479 | static void setStrAccumError(StrAccum *p, u8 eError){ |
| 21480 | assert( eError==STRACCUM_NOMEM || eError==STRACCUM_TOOBIG ); |
| 21481 | p->accError = eError; |
| 21482 | p->nAlloc = 0; |
| 21483 | } |
| 21484 | |
| 21485 | /* |
| @@ -22018,11 +22093,11 @@ | |
| 22093 | if( p->accError ){ |
| 22094 | testcase(p->accError==STRACCUM_TOOBIG); |
| 22095 | testcase(p->accError==STRACCUM_NOMEM); |
| 22096 | return 0; |
| 22097 | } |
| 22098 | if( p->mxAlloc==0 ){ |
| 22099 | N = p->nAlloc - p->nChar - 1; |
| 22100 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 22101 | return N; |
| 22102 | }else{ |
| 22103 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| @@ -22038,14 +22113,14 @@ | |
| 22113 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 22114 | return 0; |
| 22115 | }else{ |
| 22116 | p->nAlloc = (int)szNew; |
| 22117 | } |
| 22118 | if( p->db ){ |
| 22119 | zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc); |
| 22120 | }else{ |
| 22121 | zNew = sqlite3_realloc64(zOld, p->nAlloc); |
| 22122 | } |
| 22123 | if( zNew ){ |
| 22124 | assert( p->zText!=0 || p->nChar==0 ); |
| 22125 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 22126 | p->zText = zNew; |
| @@ -22089,11 +22164,11 @@ | |
| 22164 | /* |
| 22165 | ** Append N bytes of text from z to the StrAccum object. Increase the |
| 22166 | ** size of the memory allocation for StrAccum if necessary. |
| 22167 | */ |
| 22168 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ |
| 22169 | assert( z!=0 || N==0 ); |
| 22170 | assert( p->zText!=0 || p->nChar==0 || p->accError ); |
| 22171 | assert( N>=0 ); |
| 22172 | assert( p->accError==0 || p->nAlloc==0 ); |
| 22173 | if( p->nChar+N >= p->nAlloc ){ |
| 22174 | enlargeAndAppend(p,z,N); |
| @@ -22118,16 +22193,12 @@ | |
| 22193 | ** pointer if any kind of error was encountered. |
| 22194 | */ |
| 22195 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){ |
| 22196 | if( p->zText ){ |
| 22197 | p->zText[p->nChar] = 0; |
| 22198 | if( p->mxAlloc>0 && p->zText==p->zBase ){ |
| 22199 | p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); |
| 22200 | if( p->zText ){ |
| 22201 | memcpy(p->zText, p->zBase, p->nChar+1); |
| 22202 | }else{ |
| 22203 | setStrAccumError(p, STRACCUM_NOMEM); |
| 22204 | } |
| @@ -22139,29 +22210,35 @@ | |
| 22210 | /* |
| 22211 | ** Reset an StrAccum string. Reclaim all malloced memory. |
| 22212 | */ |
| 22213 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){ |
| 22214 | if( p->zText!=p->zBase ){ |
| 22215 | sqlite3DbFree(p->db, p->zText); |
| 22216 | } |
| 22217 | p->zText = 0; |
| 22218 | } |
| 22219 | |
| 22220 | /* |
| 22221 | ** Initialize a string accumulator. |
| 22222 | ** |
| 22223 | ** p: The accumulator to be initialized. |
| 22224 | ** db: Pointer to a database connection. May be NULL. Lookaside |
| 22225 | ** memory is used if not NULL. db->mallocFailed is set appropriately |
| 22226 | ** when not NULL. |
| 22227 | ** zBase: An initial buffer. May be NULL in which case the initial buffer |
| 22228 | ** is malloced. |
| 22229 | ** n: Size of zBase in bytes. If total space requirements never exceed |
| 22230 | ** n then no memory allocations ever occur. |
| 22231 | ** mx: Maximum number of bytes to accumulate. If mx==0 then no memory |
| 22232 | ** allocations will ever occur. |
| 22233 | */ |
| 22234 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){ |
| 22235 | p->zText = p->zBase = zBase; |
| 22236 | p->db = db; |
| 22237 | p->nChar = 0; |
| 22238 | p->nAlloc = n; |
| 22239 | p->mxAlloc = mx; |
| 22240 | p->accError = 0; |
| 22241 | } |
| 22242 | |
| 22243 | /* |
| 22244 | ** Print into memory obtained from sqliteMalloc(). Use the internal |
| @@ -22170,13 +22247,12 @@ | |
| 22247 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){ |
| 22248 | char *z; |
| 22249 | char zBase[SQLITE_PRINT_BUF_SIZE]; |
| 22250 | StrAccum acc; |
| 22251 | assert( db!=0 ); |
| 22252 | sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase), |
| 22253 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 22254 | sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap); |
| 22255 | z = sqlite3StrAccumFinish(&acc); |
| 22256 | if( acc.accError==STRACCUM_NOMEM ){ |
| 22257 | db->mallocFailed = 1; |
| 22258 | } |
| @@ -22230,12 +22306,11 @@ | |
| 22306 | } |
| 22307 | #endif |
| 22308 | #ifndef SQLITE_OMIT_AUTOINIT |
| 22309 | if( sqlite3_initialize() ) return 0; |
| 22310 | #endif |
| 22311 | sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); |
| 22312 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22313 | z = sqlite3StrAccumFinish(&acc); |
| 22314 | return z; |
| 22315 | } |
| 22316 | |
| @@ -22276,12 +22351,11 @@ | |
| 22351 | (void)SQLITE_MISUSE_BKPT; |
| 22352 | if( zBuf ) zBuf[0] = 0; |
| 22353 | return zBuf; |
| 22354 | } |
| 22355 | #endif |
| 22356 | sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); |
| 22357 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22358 | return sqlite3StrAccumFinish(&acc); |
| 22359 | } |
| 22360 | SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ |
| 22361 | char *z; |
| @@ -22303,12 +22377,11 @@ | |
| 22377 | */ |
| 22378 | static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){ |
| 22379 | StrAccum acc; /* String accumulator */ |
| 22380 | char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */ |
| 22381 | |
| 22382 | sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0); |
| 22383 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22384 | sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode, |
| 22385 | sqlite3StrAccumFinish(&acc)); |
| 22386 | } |
| 22387 | |
| @@ -22322,22 +22395,21 @@ | |
| 22395 | renderLogMsg(iErrCode, zFormat, ap); |
| 22396 | va_end(ap); |
| 22397 | } |
| 22398 | } |
| 22399 | |
| 22400 | #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 22401 | /* |
| 22402 | ** A version of printf() that understands %lld. Used for debugging. |
| 22403 | ** The printf() built into some versions of windows does not understand %lld |
| 22404 | ** and segfaults if you give it a long long int. |
| 22405 | */ |
| 22406 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){ |
| 22407 | va_list ap; |
| 22408 | StrAccum acc; |
| 22409 | char zBuf[500]; |
| 22410 | sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
| 22411 | va_start(ap,zFormat); |
| 22412 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22413 | va_end(ap); |
| 22414 | sqlite3StrAccumFinish(&acc); |
| 22415 | fprintf(stdout,"%s", zBuf); |
| @@ -22360,11 +22432,11 @@ | |
| 22432 | */ |
| 22433 | /* Add a new subitem to the tree. The moreToFollow flag indicates that this |
| 22434 | ** is not the last item in the tree. */ |
| 22435 | SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){ |
| 22436 | if( p==0 ){ |
| 22437 | p = sqlite3_malloc64( sizeof(*p) ); |
| 22438 | if( p==0 ) return 0; |
| 22439 | memset(p, 0, sizeof(*p)); |
| 22440 | }else{ |
| 22441 | p->iLevel++; |
| 22442 | } |
| @@ -22383,12 +22455,11 @@ | |
| 22455 | SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){ |
| 22456 | va_list ap; |
| 22457 | int i; |
| 22458 | StrAccum acc; |
| 22459 | char zBuf[500]; |
| 22460 | sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
| 22461 | if( p ){ |
| 22462 | for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){ |
| 22463 | sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4); |
| 22464 | } |
| 22465 | sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4); |
| @@ -24007,10 +24078,11 @@ | |
| 24078 | }else{ |
| 24079 | return 0; |
| 24080 | } |
| 24081 | } |
| 24082 | #endif |
| 24083 | while( zNum[0]=='0' ) zNum++; |
| 24084 | for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){ |
| 24085 | v = v*10 + c; |
| 24086 | } |
| 24087 | |
| 24088 | /* The longest decimal representation of a 32 bit integer is 10 digits: |
| @@ -25261,10 +25333,21 @@ | |
| 25333 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 25334 | # include <sys/ioctl.h> |
| 25335 | # include <sys/file.h> |
| 25336 | # include <sys/param.h> |
| 25337 | #endif /* SQLITE_ENABLE_LOCKING_STYLE */ |
| 25338 | |
| 25339 | #if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ |
| 25340 | (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000)) |
| 25341 | # if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \ |
| 25342 | && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0)) |
| 25343 | # define HAVE_GETHOSTUUID 1 |
| 25344 | # else |
| 25345 | # warning "gethostuuid() is disabled." |
| 25346 | # endif |
| 25347 | #endif |
| 25348 | |
| 25349 | |
| 25350 | #if OS_VXWORKS |
| 25351 | /* # include <sys/ioctl.h> */ |
| 25352 | # include <semaphore.h> |
| 25353 | # include <limits.h> |
| @@ -25457,20 +25540,10 @@ | |
| 25540 | */ |
| 25541 | #ifdef MEMORY_DEBUG |
| 25542 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 25543 | #endif |
| 25544 | |
| 25545 | /* |
| 25546 | ** Macros for performance tracing. Normally turned off. Only works |
| 25547 | ** on i486 hardware. |
| 25548 | */ |
| 25549 | #ifdef SQLITE_PERFORMANCE_TRACE |
| @@ -26009,11 +26082,11 @@ | |
| 26082 | return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 26083 | } |
| 26084 | #endif |
| 26085 | |
| 26086 | |
| 26087 | #ifdef SQLITE_HAVE_OS_TRACE |
| 26088 | /* |
| 26089 | ** Helper function for printing out trace information from debugging |
| 26090 | ** binaries. This returns the string representation of the supplied |
| 26091 | ** integer lock-type. |
| 26092 | */ |
| @@ -26272,11 +26345,11 @@ | |
| 26345 | struct vxworksFileId *pCandidate; /* For looping over existing file IDs */ |
| 26346 | int n; /* Length of zAbsoluteName string */ |
| 26347 | |
| 26348 | assert( zAbsoluteName[0]=='/' ); |
| 26349 | n = (int)strlen(zAbsoluteName); |
| 26350 | pNew = sqlite3_malloc64( sizeof(*pNew) + (n+1) ); |
| 26351 | if( pNew==0 ) return 0; |
| 26352 | pNew->zCanonicalName = (char*)&pNew[1]; |
| 26353 | memcpy(pNew->zCanonicalName, zAbsoluteName, n+1); |
| 26354 | n = vxworksSimplifyName(pNew->zCanonicalName, n); |
| 26355 | |
| @@ -26676,11 +26749,11 @@ | |
| 26749 | pInode = inodeList; |
| 26750 | while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){ |
| 26751 | pInode = pInode->pNext; |
| 26752 | } |
| 26753 | if( pInode==0 ){ |
| 26754 | pInode = sqlite3_malloc64( sizeof(*pInode) ); |
| 26755 | if( pInode==0 ){ |
| 26756 | return SQLITE_NOMEM; |
| 26757 | } |
| 26758 | memset(pInode, 0, sizeof(*pInode)); |
| 26759 | memcpy(&pInode->fileId, &fileId, sizeof(fileId)); |
| @@ -29197,11 +29270,11 @@ | |
| 29270 | case SQLITE_FCNTL_VFSNAME: { |
| 29271 | *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); |
| 29272 | return SQLITE_OK; |
| 29273 | } |
| 29274 | case SQLITE_FCNTL_TEMPFILENAME: { |
| 29275 | char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname ); |
| 29276 | if( zTFile ){ |
| 29277 | unixGetTempname(pFile->pVfs->mxPathname, zTFile); |
| 29278 | *(char**)pArg = zTFile; |
| 29279 | } |
| 29280 | return SQLITE_OK; |
| @@ -29638,11 +29711,11 @@ | |
| 29711 | unixInodeInfo *pInode; /* The inode of fd */ |
| 29712 | char *zShmFilename; /* Name of the file used for SHM */ |
| 29713 | int nShmFilename; /* Size of the SHM filename in bytes */ |
| 29714 | |
| 29715 | /* Allocate space for the new unixShm object. */ |
| 29716 | p = sqlite3_malloc64( sizeof(*p) ); |
| 29717 | if( p==0 ) return SQLITE_NOMEM; |
| 29718 | memset(p, 0, sizeof(*p)); |
| 29719 | assert( pDbFd->pShm==0 ); |
| 29720 | |
| 29721 | /* Check to see if a unixShmNode object already exists. Reuse an existing |
| @@ -29669,11 +29742,11 @@ | |
| 29742 | #ifdef SQLITE_SHM_DIRECTORY |
| 29743 | nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31; |
| 29744 | #else |
| 29745 | nShmFilename = 6 + (int)strlen(zBasePath); |
| 29746 | #endif |
| 29747 | pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename ); |
| 29748 | if( pShmNode==0 ){ |
| 29749 | rc = SQLITE_NOMEM; |
| 29750 | goto shm_open_err; |
| 29751 | } |
| 29752 | memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename); |
| @@ -29879,11 +29952,11 @@ | |
| 29952 | if( pMem==MAP_FAILED ){ |
| 29953 | rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename); |
| 29954 | goto shmpage_out; |
| 29955 | } |
| 29956 | }else{ |
| 29957 | pMem = sqlite3_malloc64(szRegion); |
| 29958 | if( pMem==0 ){ |
| 29959 | rc = SQLITE_NOMEM; |
| 29960 | goto shmpage_out; |
| 29961 | } |
| 29962 | memset(pMem, 0, szRegion); |
| @@ -30716,11 +30789,11 @@ | |
| 30789 | else if( pLockingStyle == &afpIoMethods ){ |
| 30790 | /* AFP locking uses the file path so it needs to be included in |
| 30791 | ** the afpLockingContext. |
| 30792 | */ |
| 30793 | afpLockingContext *pCtx; |
| 30794 | pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) ); |
| 30795 | if( pCtx==0 ){ |
| 30796 | rc = SQLITE_NOMEM; |
| 30797 | }else{ |
| 30798 | /* NB: zFilename exists and remains valid until the file is closed |
| 30799 | ** according to requirement F11141. So we do not need to make a |
| @@ -30746,11 +30819,11 @@ | |
| 30819 | */ |
| 30820 | char *zLockFile; |
| 30821 | int nFilename; |
| 30822 | assert( zFilename!=0 ); |
| 30823 | nFilename = (int)strlen(zFilename) + 6; |
| 30824 | zLockFile = (char *)sqlite3_malloc64(nFilename); |
| 30825 | if( zLockFile==0 ){ |
| 30826 | rc = SQLITE_NOMEM; |
| 30827 | }else{ |
| 30828 | sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename); |
| 30829 | } |
| @@ -31123,11 +31196,11 @@ | |
| 31196 | UnixUnusedFd *pUnused; |
| 31197 | pUnused = findReusableFd(zName, flags); |
| 31198 | if( pUnused ){ |
| 31199 | fd = pUnused->fd; |
| 31200 | }else{ |
| 31201 | pUnused = sqlite3_malloc64(sizeof(*pUnused)); |
| 31202 | if( !pUnused ){ |
| 31203 | return SQLITE_NOMEM; |
| 31204 | } |
| 31205 | } |
| 31206 | p->pUnused = pUnused; |
| @@ -31503,11 +31576,11 @@ | |
| 31576 | ** that we always use the same random number sequence. This makes the |
| 31577 | ** tests repeatable. |
| 31578 | */ |
| 31579 | memset(zBuf, 0, nBuf); |
| 31580 | randomnessPid = osGetpid(0); |
| 31581 | #if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS) |
| 31582 | { |
| 31583 | int fd, got; |
| 31584 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 31585 | if( fd<0 ){ |
| 31586 | time_t t; |
| @@ -31915,11 +31988,11 @@ | |
| 31988 | */ |
| 31989 | pUnused = findReusableFd(path, openFlags); |
| 31990 | if( pUnused ){ |
| 31991 | fd = pUnused->fd; |
| 31992 | }else{ |
| 31993 | pUnused = sqlite3_malloc64(sizeof(*pUnused)); |
| 31994 | if( !pUnused ){ |
| 31995 | return SQLITE_NOMEM; |
| 31996 | } |
| 31997 | } |
| 31998 | if( fd<0 ){ |
| @@ -31948,11 +32021,11 @@ | |
| 32021 | default: |
| 32022 | return SQLITE_CANTOPEN_BKPT; |
| 32023 | } |
| 32024 | } |
| 32025 | |
| 32026 | pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew)); |
| 32027 | if( pNew==NULL ){ |
| 32028 | rc = SQLITE_NOMEM; |
| 32029 | goto end_create_proxy; |
| 32030 | } |
| 32031 | memset(pNew, 0, sizeof(unixFile)); |
| @@ -31981,21 +32054,22 @@ | |
| 32054 | SQLITE_API int sqlite3_hostid_num = 0; |
| 32055 | #endif |
| 32056 | |
| 32057 | #define PROXY_HOSTIDLEN 16 /* conch file host id length */ |
| 32058 | |
| 32059 | #ifdef HAVE_GETHOSTUUID |
| 32060 | /* Not always defined in the headers as it ought to be */ |
| 32061 | extern int gethostuuid(uuid_t id, const struct timespec *wait); |
| 32062 | #endif |
| 32063 | |
| 32064 | /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN |
| 32065 | ** bytes of writable memory. |
| 32066 | */ |
| 32067 | static int proxyGetHostID(unsigned char *pHostID, int *pError){ |
| 32068 | assert(PROXY_HOSTIDLEN == sizeof(uuid_t)); |
| 32069 | memset(pHostID, 0, PROXY_HOSTIDLEN); |
| 32070 | #ifdef HAVE_GETHOSTUUID |
| 32071 | { |
| 32072 | struct timespec timeout = {1, 0}; /* 1 sec timeout */ |
| 32073 | if( gethostuuid(pHostID, &timeout) ){ |
| 32074 | int err = errno; |
| 32075 | if( pError ){ |
| @@ -32409,11 +32483,11 @@ | |
| 32483 | return rc; |
| 32484 | } |
| 32485 | |
| 32486 | /* |
| 32487 | ** Given the name of a database file, compute the name of its conch file. |
| 32488 | ** Store the conch filename in memory obtained from sqlite3_malloc64(). |
| 32489 | ** Make *pConchPath point to the new name. Return SQLITE_OK on success |
| 32490 | ** or SQLITE_NOMEM if unable to obtain memory. |
| 32491 | ** |
| 32492 | ** The caller is responsible for ensuring that the allocated memory |
| 32493 | ** space is eventually freed. |
| @@ -32425,11 +32499,11 @@ | |
| 32499 | int len = (int)strlen(dbPath); /* Length of database filename - dbPath */ |
| 32500 | char *conchPath; /* buffer in which to construct conch name */ |
| 32501 | |
| 32502 | /* Allocate space for the conch filename and initialize the name to |
| 32503 | ** the name of the original database file. */ |
| 32504 | *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8); |
| 32505 | if( conchPath==0 ){ |
| 32506 | return SQLITE_NOMEM; |
| 32507 | } |
| 32508 | memcpy(conchPath, dbPath, len+1); |
| 32509 | |
| @@ -32541,11 +32615,11 @@ | |
| 32615 | } |
| 32616 | |
| 32617 | OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h, |
| 32618 | (lockPath ? lockPath : ":auto:"), osGetpid(0))); |
| 32619 | |
| 32620 | pCtx = sqlite3_malloc64( sizeof(*pCtx) ); |
| 32621 | if( pCtx==0 ){ |
| 32622 | return SQLITE_NOMEM; |
| 32623 | } |
| 32624 | memset(pCtx, 0, sizeof(*pCtx)); |
| 32625 | |
| @@ -32985,20 +33059,10 @@ | |
| 33059 | */ |
| 33060 | #ifdef MEMORY_DEBUG |
| 33061 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 33062 | #endif |
| 33063 | |
| 33064 | /* |
| 33065 | ** Macros for performance tracing. Normally turned off. Only works |
| 33066 | ** on i486 hardware. |
| 33067 | */ |
| 33068 | #ifdef SQLITE_PERFORMANCE_TRACE |
| @@ -35898,11 +35962,11 @@ | |
| 35962 | ** Used only when SQLITE_NO_SYNC is not defined. |
| 35963 | */ |
| 35964 | BOOL rc; |
| 35965 | #endif |
| 35966 | #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \ |
| 35967 | defined(SQLITE_HAVE_OS_TRACE) |
| 35968 | /* |
| 35969 | ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or |
| 35970 | ** OSTRACE() macros. |
| 35971 | */ |
| 35972 | winFile *pFile = (winFile*)id; |
| @@ -36575,11 +36639,11 @@ | |
| 36639 | DWORD lastErrno; /* The Windows errno from the last I/O error */ |
| 36640 | |
| 36641 | int nRef; /* Number of winShm objects pointing to this */ |
| 36642 | winShm *pFirst; /* All winShm objects pointing to this */ |
| 36643 | winShmNode *pNext; /* Next in list of all winShmNode objects */ |
| 36644 | #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 36645 | u8 nextShmId; /* Next available winShm.id value */ |
| 36646 | #endif |
| 36647 | }; |
| 36648 | |
| 36649 | /* |
| @@ -36606,11 +36670,11 @@ | |
| 36670 | winShmNode *pShmNode; /* The underlying winShmNode object */ |
| 36671 | winShm *pNext; /* Next winShm with the same winShmNode */ |
| 36672 | u8 hasMutex; /* True if holding the winShmNode mutex */ |
| 36673 | u16 sharedMask; /* Mask of shared locks held */ |
| 36674 | u16 exclMask; /* Mask of exclusive locks held */ |
| 36675 | #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 36676 | u8 id; /* Id of this connection with its winShmNode */ |
| 36677 | #endif |
| 36678 | }; |
| 36679 | |
| 36680 | /* |
| @@ -36797,11 +36861,11 @@ | |
| 36861 | if( rc ) goto shm_open_err; |
| 36862 | } |
| 36863 | |
| 36864 | /* Make the new connection a child of the winShmNode */ |
| 36865 | p->pShmNode = pShmNode; |
| 36866 | #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 36867 | p->id = pShmNode->nextShmId++; |
| 36868 | #endif |
| 36869 | pShmNode->nRef++; |
| 36870 | pDbFd->pShm = p; |
| 36871 | winShmLeaveMutex(); |
| @@ -37066,11 +37130,11 @@ | |
| 37130 | goto shmpage_out; |
| 37131 | } |
| 37132 | } |
| 37133 | |
| 37134 | /* Map the requested memory region into this processes address space. */ |
| 37135 | apNew = (struct ShmRegion *)sqlite3_realloc64( |
| 37136 | pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0]) |
| 37137 | ); |
| 37138 | if( !apNew ){ |
| 37139 | rc = SQLITE_IOERR_NOMEM; |
| 37140 | goto shmpage_out; |
| @@ -38513,11 +38577,11 @@ | |
| 38577 | ** Write up to nBuf bytes of randomness into zBuf. |
| 38578 | */ |
| 38579 | static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ |
| 38580 | int n = 0; |
| 38581 | UNUSED_PARAMETER(pVfs); |
| 38582 | #if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) |
| 38583 | n = nBuf; |
| 38584 | memset(zBuf, 0, nBuf); |
| 38585 | #else |
| 38586 | if( sizeof(SYSTEMTIME)<=nBuf-n ){ |
| 38587 | SYSTEMTIME x; |
| @@ -38547,11 +38611,10 @@ | |
| 38611 | LARGE_INTEGER i; |
| 38612 | osQueryPerformanceCounter(&i); |
| 38613 | memcpy(&zBuf[n], &i, sizeof(i)); |
| 38614 | n += sizeof(i); |
| 38615 | } |
| 38616 | #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID |
| 38617 | if( sizeof(UUID)<=nBuf-n ){ |
| 38618 | UUID id; |
| 38619 | memset(&id, 0, sizeof(UUID)); |
| 38620 | osUuidCreate(&id); |
| @@ -38564,10 +38627,11 @@ | |
| 38627 | osUuidCreateSequential(&id); |
| 38628 | memcpy(zBuf, &id, sizeof(UUID)); |
| 38629 | n += sizeof(UUID); |
| 38630 | } |
| 38631 | #endif |
| 38632 | #endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */ |
| 38633 | return n; |
| 38634 | } |
| 38635 | |
| 38636 | |
| 38637 | /* |
| @@ -39118,11 +39182,11 @@ | |
| 39182 | |
| 39183 | /* Allocate the Bitvec to be tested and a linear array of |
| 39184 | ** bits to act as the reference */ |
| 39185 | pBitvec = sqlite3BitvecCreate( sz ); |
| 39186 | pV = sqlite3MallocZero( (sz+7)/8 + 1 ); |
| 39187 | pTmpSpace = sqlite3_malloc64(BITVEC_SZ); |
| 39188 | if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end; |
| 39189 | |
| 39190 | /* NULL pBitvec tests */ |
| 39191 | sqlite3BitvecSet(0, 1); |
| 39192 | sqlite3BitvecClear(0, 1, pTmpSpace); |
| @@ -44607,13 +44671,11 @@ | |
| 44671 | Pgno nTruncate, /* Database size after this commit */ |
| 44672 | int isCommit /* True if this is a commit */ |
| 44673 | ){ |
| 44674 | int rc; /* Return code */ |
| 44675 | int nList; /* Number of pages in pList */ |
| 44676 | PgHdr *p; /* For looping over pages */ |
| 44677 | |
| 44678 | assert( pPager->pWal ); |
| 44679 | assert( pList ); |
| 44680 | #ifdef SQLITE_DEBUG |
| 44681 | /* Verify that the page list is in accending order */ |
| @@ -44626,11 +44688,10 @@ | |
| 44688 | if( isCommit ){ |
| 44689 | /* If a WAL transaction is being committed, there is no point in writing |
| 44690 | ** any pages with page numbers greater than nTruncate into the WAL file. |
| 44691 | ** They will never be read by any client. So remove them from the pDirty |
| 44692 | ** list here. */ |
| 44693 | PgHdr **ppNext = &pList; |
| 44694 | nList = 0; |
| 44695 | for(p=pList; (*ppNext = p)!=0; p=p->pDirty){ |
| 44696 | if( p->pgno<=nTruncate ){ |
| 44697 | ppNext = &p->pDirty; |
| @@ -44646,11 +44707,10 @@ | |
| 44707 | if( pList->pgno==1 ) pager_write_changecounter(pList); |
| 44708 | rc = sqlite3WalFrames(pPager->pWal, |
| 44709 | pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags |
| 44710 | ); |
| 44711 | if( rc==SQLITE_OK && pPager->pBackup ){ |
| 44712 | for(p=pList; p; p=p->pDirty){ |
| 44713 | sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData); |
| 44714 | } |
| 44715 | } |
| 44716 | |
| @@ -48577,10 +48637,12 @@ | |
| 48637 | }else if( state==PAGER_OPEN ){ |
| 48638 | pager_unlock(pPager); |
| 48639 | } |
| 48640 | assert( state==pPager->eState ); |
| 48641 | } |
| 48642 | }else if( eMode==PAGER_JOURNALMODE_OFF ){ |
| 48643 | sqlite3OsClose(pPager->jfd); |
| 48644 | } |
| 48645 | } |
| 48646 | |
| 48647 | /* Return the new journal mode */ |
| 48648 | return (int)pPager->journalMode; |
| @@ -49359,11 +49421,11 @@ | |
| 49421 | |
| 49422 | /* Enlarge the pWal->apWiData[] array if required */ |
| 49423 | if( pWal->nWiData<=iPage ){ |
| 49424 | int nByte = sizeof(u32*)*(iPage+1); |
| 49425 | volatile u32 **apNew; |
| 49426 | apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte); |
| 49427 | if( !apNew ){ |
| 49428 | *ppPage = 0; |
| 49429 | return SQLITE_NOMEM; |
| 49430 | } |
| 49431 | memset((void*)&apNew[pWal->nWiData], 0, |
| @@ -49984,11 +50046,11 @@ | |
| 50046 | goto finished; |
| 50047 | } |
| 50048 | |
| 50049 | /* Malloc a buffer to read frames into. */ |
| 50050 | szFrame = szPage + WAL_FRAME_HDRSIZE; |
| 50051 | aFrame = (u8 *)sqlite3_malloc64(szFrame); |
| 50052 | if( !aFrame ){ |
| 50053 | rc = SQLITE_NOMEM; |
| 50054 | goto recovery_error; |
| 50055 | } |
| 50056 | aData = &aFrame[WAL_FRAME_HDRSIZE]; |
| @@ -50377,21 +50439,21 @@ | |
| 50439 | /* Allocate space for the WalIterator object. */ |
| 50440 | nSegment = walFramePage(iLast) + 1; |
| 50441 | nByte = sizeof(WalIterator) |
| 50442 | + (nSegment-1)*sizeof(struct WalSegment) |
| 50443 | + iLast*sizeof(ht_slot); |
| 50444 | p = (WalIterator *)sqlite3_malloc64(nByte); |
| 50445 | if( !p ){ |
| 50446 | return SQLITE_NOMEM; |
| 50447 | } |
| 50448 | memset(p, 0, nByte); |
| 50449 | p->nSegment = nSegment; |
| 50450 | |
| 50451 | /* Allocate temporary space used by the merge-sort routine. This block |
| 50452 | ** of memory will be freed before this function returns. |
| 50453 | */ |
| 50454 | aTmp = (ht_slot *)sqlite3_malloc64( |
| 50455 | sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast) |
| 50456 | ); |
| 50457 | if( !aTmp ){ |
| 50458 | rc = SQLITE_NOMEM; |
| 50459 | } |
| @@ -50567,10 +50629,18 @@ | |
| 50629 | ** cannot be backfilled from the WAL. |
| 50630 | */ |
| 50631 | mxSafeFrame = pWal->hdr.mxFrame; |
| 50632 | mxPage = pWal->hdr.nPage; |
| 50633 | for(i=1; i<WAL_NREADER; i++){ |
| 50634 | /* Thread-sanitizer reports that the following is an unsafe read, |
| 50635 | ** as some other thread may be in the process of updating the value |
| 50636 | ** of the aReadMark[] slot. The assumption here is that if that is |
| 50637 | ** happening, the other client may only be increasing the value, |
| 50638 | ** not decreasing it. So assuming either that either the "old" or |
| 50639 | ** "new" version of the value is read, and not some arbitrary value |
| 50640 | ** that would never be written by a real client, things are still |
| 50641 | ** safe. */ |
| 50642 | u32 y = pInfo->aReadMark[i]; |
| 50643 | if( mxSafeFrame>y ){ |
| 50644 | assert( y<=pWal->hdr.mxFrame ); |
| 50645 | rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1); |
| 50646 | if( rc==SQLITE_OK ){ |
| @@ -57429,17 +57499,22 @@ | |
| 57499 | */ |
| 57500 | static const void *fetchPayload( |
| 57501 | BtCursor *pCur, /* Cursor pointing to entry to read from */ |
| 57502 | u32 *pAmt /* Write the number of available bytes here */ |
| 57503 | ){ |
| 57504 | u32 amt; |
| 57505 | assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]); |
| 57506 | assert( pCur->eState==CURSOR_VALID ); |
| 57507 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 57508 | assert( cursorHoldsMutex(pCur) ); |
| 57509 | assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); |
| 57510 | assert( pCur->info.nSize>0 ); |
| 57511 | assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB ); |
| 57512 | assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB); |
| 57513 | amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload); |
| 57514 | if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal; |
| 57515 | *pAmt = amt; |
| 57516 | return (void*)pCur->info.pPayload; |
| 57517 | } |
| 57518 | |
| 57519 | |
| 57520 | /* |
| @@ -59713,11 +59788,10 @@ | |
| 59788 | if( iParentIdx==0 ){ |
| 59789 | nxDiv = 0; |
| 59790 | }else if( iParentIdx==i ){ |
| 59791 | nxDiv = i-2+bBulk; |
| 59792 | }else{ |
| 59793 | nxDiv = iParentIdx-1; |
| 59794 | } |
| 59795 | i = 2-bBulk; |
| 59796 | } |
| 59797 | nOld = i+1; |
| @@ -61501,10 +61575,61 @@ | |
| 61575 | iPage = get4byte(pOvflData); |
| 61576 | sqlite3PagerUnref(pOvflPage); |
| 61577 | } |
| 61578 | } |
| 61579 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 61580 | |
| 61581 | /* |
| 61582 | ** An implementation of a min-heap. |
| 61583 | ** |
| 61584 | ** aHeap[0] is the number of elements on the heap. aHeap[1] is the |
| 61585 | ** root element. The daughter nodes of aHeap[N] are aHeap[N*2] |
| 61586 | ** and aHeap[N*2+1]. |
| 61587 | ** |
| 61588 | ** The heap property is this: Every node is less than or equal to both |
| 61589 | ** of its daughter nodes. A consequence of the heap property is that the |
| 61590 | ** root node aHeap[1] is always the minimum value currently in the heap. |
| 61591 | ** |
| 61592 | ** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto |
| 61593 | ** the heap, preserving the heap property. The btreeHeapPull() routine |
| 61594 | ** removes the root element from the heap (the minimum value in the heap) |
| 61595 | ** and then moves other nodes around as necessary to preserve the heap |
| 61596 | ** property. |
| 61597 | ** |
| 61598 | ** This heap is used for cell overlap and coverage testing. Each u32 |
| 61599 | ** entry represents the span of a cell or freeblock on a btree page. |
| 61600 | ** The upper 16 bits are the index of the first byte of a range and the |
| 61601 | ** lower 16 bits are the index of the last byte of that range. |
| 61602 | */ |
| 61603 | static void btreeHeapInsert(u32 *aHeap, u32 x){ |
| 61604 | u32 j, i = ++aHeap[0]; |
| 61605 | aHeap[i] = x; |
| 61606 | while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){ |
| 61607 | x = aHeap[j]; |
| 61608 | aHeap[j] = aHeap[i]; |
| 61609 | aHeap[i] = x; |
| 61610 | i = j; |
| 61611 | } |
| 61612 | } |
| 61613 | static int btreeHeapPull(u32 *aHeap, u32 *pOut){ |
| 61614 | u32 j, i, x; |
| 61615 | if( (x = aHeap[0])==0 ) return 0; |
| 61616 | *pOut = aHeap[1]; |
| 61617 | aHeap[1] = aHeap[x]; |
| 61618 | aHeap[x] = 0xffffffff; |
| 61619 | aHeap[0]--; |
| 61620 | i = 1; |
| 61621 | while( (j = i*2)<=aHeap[0] ){ |
| 61622 | if( aHeap[j]>aHeap[j+1] ) j++; |
| 61623 | if( aHeap[i]<aHeap[j] ) break; |
| 61624 | x = aHeap[i]; |
| 61625 | aHeap[i] = aHeap[j]; |
| 61626 | aHeap[j] = x; |
| 61627 | i = j; |
| 61628 | } |
| 61629 | return 1; |
| 61630 | } |
| 61631 | |
| 61632 | #ifndef SQLITE_OMIT_INTEGRITY_CHECK |
| 61633 | /* |
| 61634 | ** Do various sanity checks on a single page of a tree. Return |
| 61635 | ** the tree depth. Root pages return 0. Parents of root pages |
| @@ -61534,11 +61659,12 @@ | |
| 61659 | int hdr, cellStart; |
| 61660 | int nCell; |
| 61661 | u8 *data; |
| 61662 | BtShared *pBt; |
| 61663 | int usableSize; |
| 61664 | u32 *heap = 0; |
| 61665 | u32 x, prev = 0; |
| 61666 | i64 nMinKey = 0; |
| 61667 | i64 nMaxKey = 0; |
| 61668 | const char *saved_zPfx = pCheck->zPfx; |
| 61669 | int saved_v1 = pCheck->v1; |
| 61670 | int saved_v2 = pCheck->v2; |
| @@ -61679,19 +61805,19 @@ | |
| 61805 | |
| 61806 | /* Check for complete coverage of the page |
| 61807 | */ |
| 61808 | data = pPage->aData; |
| 61809 | hdr = pPage->hdrOffset; |
| 61810 | heap = (u32*)sqlite3PageMalloc( pBt->pageSize ); |
| 61811 | pCheck->zPfx = 0; |
| 61812 | if( heap==0 ){ |
| 61813 | pCheck->mallocFailed = 1; |
| 61814 | }else{ |
| 61815 | int contentOffset = get2byteNotZero(&data[hdr+5]); |
| 61816 | assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */ |
| 61817 | heap[0] = 0; |
| 61818 | btreeHeapInsert(heap, contentOffset-1); |
| 61819 | /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the |
| 61820 | ** number of cells on the page. */ |
| 61821 | nCell = get2byte(&data[hdr+3]); |
| 61822 | /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page |
| 61823 | ** immediately follows the b-tree page header. */ |
| @@ -61699,20 +61825,19 @@ | |
| 61825 | /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte |
| 61826 | ** integer offsets to the cell contents. */ |
| 61827 | for(i=0; i<nCell; i++){ |
| 61828 | int pc = get2byte(&data[cellStart+i*2]); |
| 61829 | u32 size = 65536; |
| 61830 | if( pc<=usableSize-4 ){ |
| 61831 | size = cellSizePtr(pPage, &data[pc]); |
| 61832 | } |
| 61833 | if( (int)(pc+size-1)>=usableSize ){ |
| 61834 | pCheck->zPfx = 0; |
| 61835 | checkAppendMsg(pCheck, |
| 61836 | "Corruption detected in cell %d on page %d",i,iPage); |
| 61837 | }else{ |
| 61838 | btreeHeapInsert(heap, (pc<<16)|(pc+size-1)); |
| 61839 | } |
| 61840 | } |
| 61841 | /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header |
| 61842 | ** is the offset of the first freeblock, or zero if there are no |
| 61843 | ** freeblocks on the page. */ |
| @@ -61720,11 +61845,11 @@ | |
| 61845 | while( i>0 ){ |
| 61846 | int size, j; |
| 61847 | assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */ |
| 61848 | size = get2byte(&data[i+2]); |
| 61849 | assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */ |
| 61850 | btreeHeapInsert(heap, (i<<16)|(i+size-1)); |
| 61851 | /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a |
| 61852 | ** big-endian integer which is the offset in the b-tree page of the next |
| 61853 | ** freeblock in the chain, or zero if the freeblock is the last on the |
| 61854 | ** chain. */ |
| 61855 | j = get2byte(&data[i]); |
| @@ -61732,31 +61857,37 @@ | |
| 61857 | ** increasing offset. */ |
| 61858 | assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */ |
| 61859 | assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */ |
| 61860 | i = j; |
| 61861 | } |
| 61862 | cnt = 0; |
| 61863 | assert( heap[0]>0 ); |
| 61864 | assert( (heap[1]>>16)==0 ); |
| 61865 | btreeHeapPull(heap,&prev); |
| 61866 | while( btreeHeapPull(heap,&x) ){ |
| 61867 | if( (prev&0xffff)+1>(x>>16) ){ |
| 61868 | checkAppendMsg(pCheck, |
| 61869 | "Multiple uses for byte %u of page %d", x>>16, iPage); |
| 61870 | break; |
| 61871 | }else{ |
| 61872 | cnt += (x>>16) - (prev&0xffff) - 1; |
| 61873 | prev = x; |
| 61874 | } |
| 61875 | } |
| 61876 | cnt += usableSize - (prev&0xffff) - 1; |
| 61877 | /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments |
| 61878 | ** is stored in the fifth field of the b-tree page header. |
| 61879 | ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the |
| 61880 | ** number of fragmented free bytes within the cell content area. |
| 61881 | */ |
| 61882 | if( heap[0]==0 && cnt!=data[hdr+7] ){ |
| 61883 | checkAppendMsg(pCheck, |
| 61884 | "Fragmentation of %d bytes reported as %d on page %d", |
| 61885 | cnt, data[hdr+7], iPage); |
| 61886 | } |
| 61887 | } |
| 61888 | sqlite3PageFree(heap); |
| 61889 | releasePage(pPage); |
| 61890 | |
| 61891 | end_of_check: |
| 61892 | pCheck->zPfx = saved_zPfx; |
| 61893 | pCheck->v1 = saved_v1; |
| @@ -61816,12 +61947,11 @@ | |
| 61947 | sqlite3BtreeLeave(p); |
| 61948 | return 0; |
| 61949 | } |
| 61950 | i = PENDING_BYTE_PAGE(pBt); |
| 61951 | if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i); |
| 61952 | sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH); |
| 61953 | |
| 61954 | /* Check the integrity of the freelist |
| 61955 | */ |
| 61956 | sCheck.zPfx = "Main freelist: "; |
| 61957 | checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]), |
| @@ -63153,14 +63283,15 @@ | |
| 63283 | return SQLITE_NOMEM; |
| 63284 | } |
| 63285 | pMem->z[pMem->n] = 0; |
| 63286 | pMem->z[pMem->n+1] = 0; |
| 63287 | pMem->flags |= MEM_Term; |
| 63288 | } |
| 63289 | pMem->flags &= ~MEM_Ephem; |
| 63290 | #ifdef SQLITE_DEBUG |
| 63291 | pMem->pScopyFrom = 0; |
| 63292 | #endif |
| 63293 | |
| 63294 | return SQLITE_OK; |
| 63295 | } |
| 63296 | |
| 63297 | /* |
| @@ -64600,11 +64731,11 @@ | |
| 64731 | int i; |
| 64732 | int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField; |
| 64733 | Mem *aMem = pRec->aMem; |
| 64734 | sqlite3 *db = aMem[0].db; |
| 64735 | for(i=0; i<nCol; i++){ |
| 64736 | sqlite3VdbeMemRelease(&aMem[i]); |
| 64737 | } |
| 64738 | sqlite3KeyInfoUnref(pRec->pKeyInfo); |
| 64739 | sqlite3DbFree(db, pRec); |
| 64740 | } |
| 64741 | } |
| @@ -66436,18 +66567,35 @@ | |
| 66567 | pVtabCursor->pVtab->nRef--; |
| 66568 | pModule->xClose(pVtabCursor); |
| 66569 | } |
| 66570 | #endif |
| 66571 | } |
| 66572 | |
| 66573 | /* |
| 66574 | ** Close all cursors in the current frame. |
| 66575 | */ |
| 66576 | static void closeCursorsInFrame(Vdbe *p){ |
| 66577 | if( p->apCsr ){ |
| 66578 | int i; |
| 66579 | for(i=0; i<p->nCursor; i++){ |
| 66580 | VdbeCursor *pC = p->apCsr[i]; |
| 66581 | if( pC ){ |
| 66582 | sqlite3VdbeFreeCursor(p, pC); |
| 66583 | p->apCsr[i] = 0; |
| 66584 | } |
| 66585 | } |
| 66586 | } |
| 66587 | } |
| 66588 | |
| 66589 | /* |
| 66590 | ** Copy the values stored in the VdbeFrame structure to its Vdbe. This |
| 66591 | ** is used, for example, when a trigger sub-program is halted to restore |
| 66592 | ** control to the main program. |
| 66593 | */ |
| 66594 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){ |
| 66595 | Vdbe *v = pFrame->v; |
| 66596 | closeCursorsInFrame(v); |
| 66597 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 66598 | v->anExec = pFrame->anExec; |
| 66599 | #endif |
| 66600 | v->aOnceFlag = pFrame->aOnceFlag; |
| 66601 | v->nOnceFlag = pFrame->nOnceFlag; |
| @@ -66478,21 +66626,11 @@ | |
| 66626 | sqlite3VdbeFrameRestore(pFrame); |
| 66627 | p->pFrame = 0; |
| 66628 | p->nFrame = 0; |
| 66629 | } |
| 66630 | assert( p->nFrame==0 ); |
| 66631 | closeCursorsInFrame(p); |
| 66632 | if( p->aMem ){ |
| 66633 | releaseMemArray(&p->aMem[1], p->nMem); |
| 66634 | } |
| 66635 | while( p->pDelFrame ){ |
| 66636 | VdbeFrame *pDel = p->pDelFrame; |
| @@ -68233,11 +68371,11 @@ | |
| 68371 | ** If database corruption is discovered, set pPKey2->errCode to |
| 68372 | ** SQLITE_CORRUPT and return 0. If an OOM error is encountered, |
| 68373 | ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the |
| 68374 | ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db). |
| 68375 | */ |
| 68376 | SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip( |
| 68377 | int nKey1, const void *pKey1, /* Left key */ |
| 68378 | UnpackedRecord *pPKey2, /* Right key */ |
| 68379 | int bSkip /* If true, skip the first field */ |
| 68380 | ){ |
| 68381 | u32 d1; /* Offset into aKey[] of next data element */ |
| @@ -68419,11 +68557,11 @@ | |
| 68557 | } |
| 68558 | SQLITE_PRIVATE int sqlite3VdbeRecordCompare( |
| 68559 | int nKey1, const void *pKey1, /* Left key */ |
| 68560 | UnpackedRecord *pPKey2 /* Right key */ |
| 68561 | ){ |
| 68562 | return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0); |
| 68563 | } |
| 68564 | |
| 68565 | |
| 68566 | /* |
| 68567 | ** This function is an optimized version of sqlite3VdbeRecordCompare() |
| @@ -68507,11 +68645,11 @@ | |
| 68645 | }else if( v<lhs ){ |
| 68646 | res = pPKey2->r2; |
| 68647 | }else if( pPKey2->nField>1 ){ |
| 68648 | /* The first fields of the two keys are equal. Compare the trailing |
| 68649 | ** fields. */ |
| 68650 | res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 68651 | }else{ |
| 68652 | /* The first fields of the two keys are equal and there are no trailing |
| 68653 | ** fields. Return pPKey2->default_rc in this case. */ |
| 68654 | res = pPKey2->default_rc; |
| 68655 | } |
| @@ -68555,11 +68693,11 @@ | |
| 68693 | |
| 68694 | if( res==0 ){ |
| 68695 | res = nStr - pPKey2->aMem[0].n; |
| 68696 | if( res==0 ){ |
| 68697 | if( pPKey2->nField>1 ){ |
| 68698 | res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 68699 | }else{ |
| 68700 | res = pPKey2->default_rc; |
| 68701 | } |
| 68702 | }else if( res>0 ){ |
| 68703 | res = pPKey2->r2; |
| @@ -70497,21 +70635,22 @@ | |
| 70635 | Mem *pVar; /* Value of a host parameter */ |
| 70636 | StrAccum out; /* Accumulate the output here */ |
| 70637 | char zBase[100]; /* Initial working space */ |
| 70638 | |
| 70639 | db = p->db; |
| 70640 | sqlite3StrAccumInit(&out, db, zBase, sizeof(zBase), |
| 70641 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 70642 | if( db->nVdbeExec>1 ){ |
| 70643 | while( *zRawSql ){ |
| 70644 | const char *zStart = zRawSql; |
| 70645 | while( *(zRawSql++)!='\n' && *zRawSql ); |
| 70646 | sqlite3StrAccumAppend(&out, "-- ", 3); |
| 70647 | assert( (zRawSql - zStart) > 0 ); |
| 70648 | sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart)); |
| 70649 | } |
| 70650 | }else if( p->nVar==0 ){ |
| 70651 | sqlite3StrAccumAppend(&out, zRawSql, sqlite3Strlen30(zRawSql)); |
| 70652 | }else{ |
| 70653 | while( zRawSql[0] ){ |
| 70654 | n = findNextHostParameter(zRawSql, &nToken); |
| 70655 | assert( n>0 ); |
| 70656 | sqlite3StrAccumAppend(&out, zRawSql, n); |
| @@ -70524,14 +70663,16 @@ | |
| 70663 | sqlite3GetInt32(&zRawSql[1], &idx); |
| 70664 | }else{ |
| 70665 | idx = nextIndex; |
| 70666 | } |
| 70667 | }else{ |
| 70668 | assert( zRawSql[0]==':' || zRawSql[0]=='$' || |
| 70669 | zRawSql[0]=='@' || zRawSql[0]=='#' ); |
| 70670 | testcase( zRawSql[0]==':' ); |
| 70671 | testcase( zRawSql[0]=='$' ); |
| 70672 | testcase( zRawSql[0]=='@' ); |
| 70673 | testcase( zRawSql[0]=='#' ); |
| 70674 | idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken); |
| 70675 | assert( idx>0 ); |
| 70676 | } |
| 70677 | zRawSql += nToken; |
| 70678 | nextIndex = idx + 1; |
| @@ -71202,21 +71343,38 @@ | |
| 71343 | assert( n==(db->nSavepoint + db->isTransactionSavepoint) ); |
| 71344 | return 1; |
| 71345 | } |
| 71346 | #endif |
| 71347 | |
| 71348 | /* |
| 71349 | ** Return the register of pOp->p2 after first preparing it to be |
| 71350 | ** overwritten with an integer value. |
| 71351 | */ |
| 71352 | static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){ |
| 71353 | Mem *pOut; |
| 71354 | assert( pOp->p2>0 ); |
| 71355 | assert( pOp->p2<=(p->nMem-p->nCursor) ); |
| 71356 | pOut = &p->aMem[pOp->p2]; |
| 71357 | memAboutToChange(p, pOut); |
| 71358 | if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut); |
| 71359 | pOut->flags = MEM_Int; |
| 71360 | return pOut; |
| 71361 | } |
| 71362 | |
| 71363 | |
| 71364 | /* |
| 71365 | ** Execute as much of a VDBE program as we can. |
| 71366 | ** This is the core of sqlite3_step(). |
| 71367 | */ |
| 71368 | SQLITE_PRIVATE int sqlite3VdbeExec( |
| 71369 | Vdbe *p /* The VDBE */ |
| 71370 | ){ |
| 71371 | Op *aOp = p->aOp; /* Copy of p->aOp */ |
| 71372 | Op *pOp = aOp; /* Current operation */ |
| 71373 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 71374 | Op *pOrigOp; /* Value of pOp at the top of the loop */ |
| 71375 | #endif |
| 71376 | int rc = SQLITE_OK; /* Value to return */ |
| 71377 | sqlite3 *db = p->db; /* The database */ |
| 71378 | u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ |
| 71379 | u8 encoding = ENC(db); /* The database encoding */ |
| 71380 | int iCompare = 0; /* Result of last OP_Compare operation */ |
| @@ -71288,27 +71446,26 @@ | |
| 71446 | } |
| 71447 | if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n"); |
| 71448 | } |
| 71449 | sqlite3EndBenignMalloc(); |
| 71450 | #endif |
| 71451 | for(pOp=&aOp[p->pc]; rc==SQLITE_OK; pOp++){ |
| 71452 | assert( pOp>=aOp && pOp<&aOp[p->nOp]); |
| 71453 | if( db->mallocFailed ) goto no_mem; |
| 71454 | #ifdef VDBE_PROFILE |
| 71455 | start = sqlite3Hwtime(); |
| 71456 | #endif |
| 71457 | nVmStep++; |
| 71458 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 71459 | if( p->anExec ) p->anExec[(int)(pOp-aOp)]++; |
| 71460 | #endif |
| 71461 | |
| 71462 | /* Only allow tracing if SQLITE_DEBUG is defined. |
| 71463 | */ |
| 71464 | #ifdef SQLITE_DEBUG |
| 71465 | if( db->flags & SQLITE_VdbeTrace ){ |
| 71466 | sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp); |
| 71467 | } |
| 71468 | #endif |
| 71469 | |
| 71470 | |
| 71471 | /* Check to see if we need to simulate an interrupt. This only happens |
| @@ -71321,27 +71478,13 @@ | |
| 71478 | sqlite3_interrupt(db); |
| 71479 | } |
| 71480 | } |
| 71481 | #endif |
| 71482 | |
| 71483 | /* Sanity checking on other operands */ |
| 71484 | #ifdef SQLITE_DEBUG |
| 71485 | assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] ); |
| 71486 | if( (pOp->opflags & OPFLG_IN1)!=0 ){ |
| 71487 | assert( pOp->p1>0 ); |
| 71488 | assert( pOp->p1<=(p->nMem-p->nCursor) ); |
| 71489 | assert( memIsValid(&aMem[pOp->p1]) ); |
| 71490 | assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) ); |
| @@ -71370,10 +71513,13 @@ | |
| 71513 | assert( pOp->p3>0 ); |
| 71514 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 71515 | memAboutToChange(p, &aMem[pOp->p3]); |
| 71516 | } |
| 71517 | #endif |
| 71518 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 71519 | pOrigOp = pOp; |
| 71520 | #endif |
| 71521 | |
| 71522 | switch( pOp->opcode ){ |
| 71523 | |
| 71524 | /***************************************************************************** |
| 71525 | ** What follows is a massive switch statement where each case implements a |
| @@ -71393,11 +71539,11 @@ | |
| 71539 | ** case statement is followed by a comment of the form "/# same as ... #/" |
| 71540 | ** that comment is used to determine the particular value of the opcode. |
| 71541 | ** |
| 71542 | ** Other keywords in the comment that follows each case are used to |
| 71543 | ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[]. |
| 71544 | ** Keywords include: in1, in2, in3, out2, out3. See |
| 71545 | ** the mkopcodeh.awk script for additional information. |
| 71546 | ** |
| 71547 | ** Documentation about VDBE opcodes is generated by scanning this file |
| 71548 | ** for lines of that contain "Opcode:". That line and all subsequent |
| 71549 | ** comment lines are used in the generation of the opcode.html documentation |
| @@ -71421,11 +71567,12 @@ | |
| 71567 | ** is sometimes set to 1 instead of 0 as a hint to the command-line shell |
| 71568 | ** that this Goto is the bottom of a loop and that the lines from P2 down |
| 71569 | ** to the current line should be indented for EXPLAIN output. |
| 71570 | */ |
| 71571 | case OP_Goto: { /* jump */ |
| 71572 | jump_to_p2_and_check_for_interrupt: |
| 71573 | pOp = &aOp[pOp->p2 - 1]; |
| 71574 | |
| 71575 | /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev, |
| 71576 | ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon |
| 71577 | ** completion. Check to see if sqlite3_interrupt() has been called |
| 71578 | ** or if the progress callback needs to be invoked. |
| @@ -71466,13 +71613,17 @@ | |
| 71613 | assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 71614 | pIn1 = &aMem[pOp->p1]; |
| 71615 | assert( VdbeMemDynamic(pIn1)==0 ); |
| 71616 | memAboutToChange(p, pIn1); |
| 71617 | pIn1->flags = MEM_Int; |
| 71618 | pIn1->u.i = (int)(pOp-aOp); |
| 71619 | REGISTER_TRACE(pOp->p1, pIn1); |
| 71620 | |
| 71621 | /* Most jump operations do a goto to this spot in order to update |
| 71622 | ** the pOp pointer. */ |
| 71623 | jump_to_p2: |
| 71624 | pOp = &aOp[pOp->p2 - 1]; |
| 71625 | break; |
| 71626 | } |
| 71627 | |
| 71628 | /* Opcode: Return P1 * * * * |
| 71629 | ** |
| @@ -71480,11 +71631,11 @@ | |
| 71631 | ** the jump, register P1 becomes undefined. |
| 71632 | */ |
| 71633 | case OP_Return: { /* in1 */ |
| 71634 | pIn1 = &aMem[pOp->p1]; |
| 71635 | assert( pIn1->flags==MEM_Int ); |
| 71636 | pOp = &aOp[pIn1->u.i]; |
| 71637 | pIn1->flags = MEM_Undefined; |
| 71638 | break; |
| 71639 | } |
| 71640 | |
| 71641 | /* Opcode: InitCoroutine P1 P2 P3 * * |
| @@ -71504,11 +71655,11 @@ | |
| 71655 | assert( pOp->p3>=0 && pOp->p3<p->nOp ); |
| 71656 | pOut = &aMem[pOp->p1]; |
| 71657 | assert( !VdbeMemDynamic(pOut) ); |
| 71658 | pOut->u.i = pOp->p3 - 1; |
| 71659 | pOut->flags = MEM_Int; |
| 71660 | if( pOp->p2 ) goto jump_to_p2; |
| 71661 | break; |
| 71662 | } |
| 71663 | |
| 71664 | /* Opcode: EndCoroutine P1 * * * * |
| 71665 | ** |
| @@ -71524,11 +71675,11 @@ | |
| 71675 | assert( pIn1->flags==MEM_Int ); |
| 71676 | assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp ); |
| 71677 | pCaller = &aOp[pIn1->u.i]; |
| 71678 | assert( pCaller->opcode==OP_Yield ); |
| 71679 | assert( pCaller->p2>=0 && pCaller->p2<p->nOp ); |
| 71680 | pOp = &aOp[pCaller->p2 - 1]; |
| 71681 | pIn1->flags = MEM_Undefined; |
| 71682 | break; |
| 71683 | } |
| 71684 | |
| 71685 | /* Opcode: Yield P1 P2 * * * |
| @@ -71548,13 +71699,13 @@ | |
| 71699 | int pcDest; |
| 71700 | pIn1 = &aMem[pOp->p1]; |
| 71701 | assert( VdbeMemDynamic(pIn1)==0 ); |
| 71702 | pIn1->flags = MEM_Int; |
| 71703 | pcDest = (int)pIn1->u.i; |
| 71704 | pIn1->u.i = (int)(pOp - aOp); |
| 71705 | REGISTER_TRACE(pOp->p1, pIn1); |
| 71706 | pOp = &aOp[pcDest]; |
| 71707 | break; |
| 71708 | } |
| 71709 | |
| 71710 | /* Opcode: HaltIfNull P1 P2 P3 P4 P5 |
| 71711 | ** Synopsis: if r[P3]=null halt |
| @@ -71601,34 +71752,38 @@ | |
| 71752 | ** is the same as executing Halt. |
| 71753 | */ |
| 71754 | case OP_Halt: { |
| 71755 | const char *zType; |
| 71756 | const char *zLogFmt; |
| 71757 | VdbeFrame *pFrame; |
| 71758 | int pcx; |
| 71759 | |
| 71760 | pcx = (int)(pOp - aOp); |
| 71761 | if( pOp->p1==SQLITE_OK && p->pFrame ){ |
| 71762 | /* Halt the sub-program. Return control to the parent frame. */ |
| 71763 | pFrame = p->pFrame; |
| 71764 | p->pFrame = pFrame->pParent; |
| 71765 | p->nFrame--; |
| 71766 | sqlite3VdbeSetChanges(db, p->nChange); |
| 71767 | pcx = sqlite3VdbeFrameRestore(pFrame); |
| 71768 | lastRowid = db->lastRowid; |
| 71769 | if( pOp->p2==OE_Ignore ){ |
| 71770 | /* Instruction pcx is the OP_Program that invoked the sub-program |
| 71771 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 71772 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 71773 | ** an IGNORE exception. In this case jump to the address specified |
| 71774 | ** as the p2 of the calling OP_Program. */ |
| 71775 | pcx = p->aOp[pcx].p2-1; |
| 71776 | } |
| 71777 | aOp = p->aOp; |
| 71778 | aMem = p->aMem; |
| 71779 | pOp = &aOp[pcx]; |
| 71780 | break; |
| 71781 | } |
| 71782 | p->rc = pOp->p1; |
| 71783 | p->errorAction = (u8)pOp->p2; |
| 71784 | p->pc = pcx; |
| 71785 | if( p->rc ){ |
| 71786 | if( pOp->p5 ){ |
| 71787 | static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK", |
| 71788 | "FOREIGN KEY" }; |
| 71789 | assert( pOp->p5>=1 && pOp->p5<=4 ); |
| @@ -71648,11 +71803,11 @@ | |
| 71803 | }else if( pOp->p4.z ){ |
| 71804 | sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z); |
| 71805 | }else{ |
| 71806 | sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType); |
| 71807 | } |
| 71808 | sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg); |
| 71809 | } |
| 71810 | rc = sqlite3VdbeHalt(p); |
| 71811 | assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); |
| 71812 | if( rc==SQLITE_BUSY ){ |
| 71813 | p->rc = rc = SQLITE_BUSY; |
| @@ -71659,19 +71814,21 @@ | |
| 71814 | }else{ |
| 71815 | assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ); |
| 71816 | assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 ); |
| 71817 | rc = p->rc ? SQLITE_ERROR : SQLITE_DONE; |
| 71818 | } |
| 71819 | pOp = &aOp[pcx]; |
| 71820 | goto vdbe_return; |
| 71821 | } |
| 71822 | |
| 71823 | /* Opcode: Integer P1 P2 * * * |
| 71824 | ** Synopsis: r[P2]=P1 |
| 71825 | ** |
| 71826 | ** The 32-bit integer value P1 is written into register P2. |
| 71827 | */ |
| 71828 | case OP_Integer: { /* out2 */ |
| 71829 | pOut = out2Prerelease(p, pOp); |
| 71830 | pOut->u.i = pOp->p1; |
| 71831 | break; |
| 71832 | } |
| 71833 | |
| 71834 | /* Opcode: Int64 * P2 * P4 * |
| @@ -71678,11 +71835,12 @@ | |
| 71835 | ** Synopsis: r[P2]=P4 |
| 71836 | ** |
| 71837 | ** P4 is a pointer to a 64-bit integer value. |
| 71838 | ** Write that value into register P2. |
| 71839 | */ |
| 71840 | case OP_Int64: { /* out2 */ |
| 71841 | pOut = out2Prerelease(p, pOp); |
| 71842 | assert( pOp->p4.pI64!=0 ); |
| 71843 | pOut->u.i = *pOp->p4.pI64; |
| 71844 | break; |
| 71845 | } |
| 71846 | |
| @@ -71691,11 +71849,12 @@ | |
| 71849 | ** Synopsis: r[P2]=P4 |
| 71850 | ** |
| 71851 | ** P4 is a pointer to a 64-bit floating point value. |
| 71852 | ** Write that value into register P2. |
| 71853 | */ |
| 71854 | case OP_Real: { /* same as TK_FLOAT, out2 */ |
| 71855 | pOut = out2Prerelease(p, pOp); |
| 71856 | pOut->flags = MEM_Real; |
| 71857 | assert( !sqlite3IsNaN(*pOp->p4.pReal) ); |
| 71858 | pOut->u.r = *pOp->p4.pReal; |
| 71859 | break; |
| 71860 | } |
| @@ -71707,12 +71866,13 @@ | |
| 71866 | ** P4 points to a nul terminated UTF-8 string. This opcode is transformed |
| 71867 | ** into a String opcode before it is executed for the first time. During |
| 71868 | ** this transformation, the length of string P4 is computed and stored |
| 71869 | ** as the P1 parameter. |
| 71870 | */ |
| 71871 | case OP_String8: { /* same as TK_STRING, out2 */ |
| 71872 | assert( pOp->p4.z!=0 ); |
| 71873 | pOut = out2Prerelease(p, pOp); |
| 71874 | pOp->opcode = OP_String; |
| 71875 | pOp->p1 = sqlite3Strlen30(pOp->p4.z); |
| 71876 | |
| 71877 | #ifndef SQLITE_OMIT_UTF16 |
| 71878 | if( encoding!=SQLITE_UTF8 ){ |
| @@ -71745,12 +71905,13 @@ | |
| 71905 | ** If P5!=0 and the content of register P3 is greater than zero, then |
| 71906 | ** the datatype of the register P2 is converted to BLOB. The content is |
| 71907 | ** the same sequence of bytes, it is merely interpreted as a BLOB instead |
| 71908 | ** of a string, as if it had been CAST. |
| 71909 | */ |
| 71910 | case OP_String: { /* out2 */ |
| 71911 | assert( pOp->p4.z!=0 ); |
| 71912 | pOut = out2Prerelease(p, pOp); |
| 71913 | pOut->flags = MEM_Str|MEM_Static|MEM_Term; |
| 71914 | pOut->z = pOp->p4.z; |
| 71915 | pOut->n = pOp->p1; |
| 71916 | pOut->enc = encoding; |
| 71917 | UPDATE_MAX_BLOBSIZE(pOut); |
| @@ -71774,13 +71935,14 @@ | |
| 71935 | ** |
| 71936 | ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that |
| 71937 | ** NULL values will not compare equal even if SQLITE_NULLEQ is set on |
| 71938 | ** OP_Ne or OP_Eq. |
| 71939 | */ |
| 71940 | case OP_Null: { /* out2 */ |
| 71941 | int cnt; |
| 71942 | u16 nullFlag; |
| 71943 | pOut = out2Prerelease(p, pOp); |
| 71944 | cnt = pOp->p3-pOp->p2; |
| 71945 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 71946 | pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; |
| 71947 | while( cnt>0 ){ |
| 71948 | pOut++; |
| @@ -71811,12 +71973,13 @@ | |
| 71973 | ** Synopsis: r[P2]=P4 (len=P1) |
| 71974 | ** |
| 71975 | ** P4 points to a blob of data P1 bytes long. Store this |
| 71976 | ** blob in register P2. |
| 71977 | */ |
| 71978 | case OP_Blob: { /* out2 */ |
| 71979 | assert( pOp->p1 <= SQLITE_MAX_LENGTH ); |
| 71980 | pOut = out2Prerelease(p, pOp); |
| 71981 | sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0); |
| 71982 | pOut->enc = encoding; |
| 71983 | UPDATE_MAX_BLOBSIZE(pOut); |
| 71984 | break; |
| 71985 | } |
| @@ -71827,19 +71990,20 @@ | |
| 71990 | ** Transfer the values of bound parameter P1 into register P2 |
| 71991 | ** |
| 71992 | ** If the parameter is named, then its name appears in P4. |
| 71993 | ** The P4 value is used by sqlite3_bind_parameter_name(). |
| 71994 | */ |
| 71995 | case OP_Variable: { /* out2 */ |
| 71996 | Mem *pVar; /* Value being transferred */ |
| 71997 | |
| 71998 | assert( pOp->p1>0 && pOp->p1<=p->nVar ); |
| 71999 | assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] ); |
| 72000 | pVar = &p->aVar[pOp->p1 - 1]; |
| 72001 | if( sqlite3VdbeMemTooBig(pVar) ){ |
| 72002 | goto too_big; |
| 72003 | } |
| 72004 | pOut = out2Prerelease(p, pOp); |
| 72005 | sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); |
| 72006 | UPDATE_MAX_BLOBSIZE(pOut); |
| 72007 | break; |
| 72008 | } |
| 72009 | |
| @@ -71870,14 +72034,15 @@ | |
| 72034 | assert( pIn1<=&aMem[(p->nMem-p->nCursor)] ); |
| 72035 | assert( memIsValid(pIn1) ); |
| 72036 | memAboutToChange(p, pOut); |
| 72037 | sqlite3VdbeMemMove(pOut, pIn1); |
| 72038 | #ifdef SQLITE_DEBUG |
| 72039 | if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){ |
| 72040 | pOut->pScopyFrom += pOp->p2 - p1; |
| 72041 | } |
| 72042 | #endif |
| 72043 | Deephemeralize(pOut); |
| 72044 | REGISTER_TRACE(p2++, pOut); |
| 72045 | pIn1++; |
| 72046 | pOut++; |
| 72047 | }while( --n ); |
| 72048 | break; |
| @@ -72012,11 +72177,11 @@ | |
| 72177 | } |
| 72178 | if( db->mallocFailed ) goto no_mem; |
| 72179 | |
| 72180 | /* Return SQLITE_ROW |
| 72181 | */ |
| 72182 | p->pc = (int)(pOp - aOp) + 1; |
| 72183 | rc = SQLITE_ROW; |
| 72184 | goto vdbe_return; |
| 72185 | } |
| 72186 | |
| 72187 | /* Opcode: Concat P1 P2 P3 * * |
| @@ -72258,11 +72423,11 @@ | |
| 72423 | REGISTER_TRACE(pOp->p2+i, pArg); |
| 72424 | } |
| 72425 | |
| 72426 | assert( pOp->p4type==P4_FUNCDEF ); |
| 72427 | ctx.pFunc = pOp->p4.pFunc; |
| 72428 | ctx.iOp = (int)(pOp - aOp); |
| 72429 | ctx.pVdbe = p; |
| 72430 | MemSetTypeFlag(ctx.pOut, MEM_Null); |
| 72431 | ctx.fErrorOrAux = 0; |
| 72432 | db->lastRowid = lastRowid; |
| 72433 | (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */ |
| @@ -72272,11 +72437,11 @@ | |
| 72437 | if( ctx.fErrorOrAux ){ |
| 72438 | if( ctx.isError ){ |
| 72439 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut)); |
| 72440 | rc = ctx.isError; |
| 72441 | } |
| 72442 | sqlite3VdbeDeleteAuxData(p, (int)(pOp - aOp), pOp->p1); |
| 72443 | } |
| 72444 | |
| 72445 | /* Copy the result of the function into register P3 */ |
| 72446 | sqlite3VdbeChangeEncoding(ctx.pOut, encoding); |
| 72447 | if( sqlite3VdbeMemTooBig(ctx.pOut) ){ |
| @@ -72401,12 +72566,11 @@ | |
| 72566 | if( (pIn1->flags & MEM_Int)==0 ){ |
| 72567 | if( pOp->p2==0 ){ |
| 72568 | rc = SQLITE_MISMATCH; |
| 72569 | goto abort_due_to_error; |
| 72570 | }else{ |
| 72571 | goto jump_to_p2; |
| 72572 | } |
| 72573 | } |
| 72574 | } |
| 72575 | MemSetTypeFlag(pIn1, MEM_Int); |
| 72576 | break; |
| @@ -72588,11 +72752,11 @@ | |
| 72752 | MemSetTypeFlag(pOut, MEM_Null); |
| 72753 | REGISTER_TRACE(pOp->p2, pOut); |
| 72754 | }else{ |
| 72755 | VdbeBranchTaken(2,3); |
| 72756 | if( pOp->p5 & SQLITE_JUMPIFNULL ){ |
| 72757 | goto jump_to_p2; |
| 72758 | } |
| 72759 | } |
| 72760 | break; |
| 72761 | } |
| 72762 | }else{ |
| @@ -72639,10 +72803,16 @@ | |
| 72803 | case OP_Lt: res = res<0; break; |
| 72804 | case OP_Le: res = res<=0; break; |
| 72805 | case OP_Gt: res = res>0; break; |
| 72806 | default: res = res>=0; break; |
| 72807 | } |
| 72808 | |
| 72809 | /* Undo any changes made by applyAffinity() to the input registers. */ |
| 72810 | assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) ); |
| 72811 | pIn1->flags = flags1; |
| 72812 | assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) ); |
| 72813 | pIn3->flags = flags3; |
| 72814 | |
| 72815 | if( pOp->p5 & SQLITE_STOREP2 ){ |
| 72816 | pOut = &aMem[pOp->p2]; |
| 72817 | memAboutToChange(p, pOut); |
| 72818 | MemSetTypeFlag(pOut, MEM_Int); |
| @@ -72649,18 +72819,13 @@ | |
| 72819 | pOut->u.i = res; |
| 72820 | REGISTER_TRACE(pOp->p2, pOut); |
| 72821 | }else{ |
| 72822 | VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3); |
| 72823 | if( res ){ |
| 72824 | goto jump_to_p2; |
| 72825 | } |
| 72826 | } |
| 72827 | break; |
| 72828 | } |
| 72829 | |
| 72830 | /* Opcode: Permutation * * * P4 * |
| 72831 | ** |
| @@ -72751,15 +72916,15 @@ | |
| 72916 | ** in the most recent OP_Compare instruction the P1 vector was less than |
| 72917 | ** equal to, or greater than the P2 vector, respectively. |
| 72918 | */ |
| 72919 | case OP_Jump: { /* jump */ |
| 72920 | if( iCompare<0 ){ |
| 72921 | VdbeBranchTaken(0,3); pOp = &aOp[pOp->p1 - 1]; |
| 72922 | }else if( iCompare==0 ){ |
| 72923 | VdbeBranchTaken(1,3); pOp = &aOp[pOp->p2 - 1]; |
| 72924 | }else{ |
| 72925 | VdbeBranchTaken(2,3); pOp = &aOp[pOp->p3 - 1]; |
| 72926 | } |
| 72927 | break; |
| 72928 | } |
| 72929 | |
| 72930 | /* Opcode: And P1 P2 P3 * * |
| @@ -72865,11 +73030,11 @@ | |
| 73030 | */ |
| 73031 | case OP_Once: { /* jump */ |
| 73032 | assert( pOp->p1<p->nOnceFlag ); |
| 73033 | VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2); |
| 73034 | if( p->aOnceFlag[pOp->p1] ){ |
| 73035 | goto jump_to_p2; |
| 73036 | }else{ |
| 73037 | p->aOnceFlag[pOp->p1] = 1; |
| 73038 | } |
| 73039 | break; |
| 73040 | } |
| @@ -72900,11 +73065,11 @@ | |
| 73065 | #endif |
| 73066 | if( pOp->opcode==OP_IfNot ) c = !c; |
| 73067 | } |
| 73068 | VdbeBranchTaken(c!=0, 2); |
| 73069 | if( c ){ |
| 73070 | goto jump_to_p2; |
| 73071 | } |
| 73072 | break; |
| 73073 | } |
| 73074 | |
| 73075 | /* Opcode: IsNull P1 P2 * * * |
| @@ -72914,11 +73079,11 @@ | |
| 73079 | */ |
| 73080 | case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */ |
| 73081 | pIn1 = &aMem[pOp->p1]; |
| 73082 | VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2); |
| 73083 | if( (pIn1->flags & MEM_Null)!=0 ){ |
| 73084 | goto jump_to_p2; |
| 73085 | } |
| 73086 | break; |
| 73087 | } |
| 73088 | |
| 73089 | /* Opcode: NotNull P1 P2 * * * |
| @@ -72928,11 +73093,11 @@ | |
| 73093 | */ |
| 73094 | case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */ |
| 73095 | pIn1 = &aMem[pOp->p1]; |
| 73096 | VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2); |
| 73097 | if( (pIn1->flags & MEM_Null)==0 ){ |
| 73098 | goto jump_to_p2; |
| 73099 | } |
| 73100 | break; |
| 73101 | } |
| 73102 | |
| 73103 | /* Opcode: Column P1 P2 P3 P4 P5 |
| @@ -73142,11 +73307,11 @@ | |
| 73307 | rc = SQLITE_CORRUPT_BKPT; |
| 73308 | goto op_column_error; |
| 73309 | } |
| 73310 | } |
| 73311 | |
| 73312 | /* If after trying to extract new entries from the header, nHdrParsed is |
| 73313 | ** still not up to p2, that means that the record has fewer than p2 |
| 73314 | ** columns. So the result will be either the default value or a NULL. |
| 73315 | */ |
| 73316 | if( pC->nHdrParsed<=p2 ){ |
| 73317 | if( pOp->p4type==P4_MEM ){ |
| @@ -73266,11 +73431,11 @@ | |
| 73431 | u8 *zNewRecord; /* A buffer to hold the data for the new record */ |
| 73432 | Mem *pRec; /* The new record */ |
| 73433 | u64 nData; /* Number of bytes of data space */ |
| 73434 | int nHdr; /* Number of bytes of header space */ |
| 73435 | i64 nByte; /* Data space required for this record */ |
| 73436 | i64 nZero; /* Number of zero bytes at the end of the record */ |
| 73437 | int nVarint; /* Number of bytes in a varint */ |
| 73438 | u32 serial_type; /* Type field */ |
| 73439 | Mem *pData0; /* First field to be combined into the record */ |
| 73440 | Mem *pLast; /* Last field of the record */ |
| 73441 | int nField; /* Number of fields in the record */ |
| @@ -73358,11 +73523,11 @@ | |
| 73523 | nVarint = sqlite3VarintLen(nHdr); |
| 73524 | nHdr += nVarint; |
| 73525 | if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++; |
| 73526 | } |
| 73527 | nByte = nHdr+nData; |
| 73528 | if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 73529 | goto too_big; |
| 73530 | } |
| 73531 | |
| 73532 | /* Make sure the output register has a buffer large enough to store |
| 73533 | ** the new record. The output register (pOp->p3) is not allowed to |
| @@ -73409,18 +73574,19 @@ | |
| 73574 | ** |
| 73575 | ** Store the number of entries (an integer value) in the table or index |
| 73576 | ** opened by cursor P1 in register P2 |
| 73577 | */ |
| 73578 | #ifndef SQLITE_OMIT_BTREECOUNT |
| 73579 | case OP_Count: { /* out2 */ |
| 73580 | i64 nEntry; |
| 73581 | BtCursor *pCrsr; |
| 73582 | |
| 73583 | pCrsr = p->apCsr[pOp->p1]->pCursor; |
| 73584 | assert( pCrsr ); |
| 73585 | nEntry = 0; /* Not needed. Only used to silence a warning. */ |
| 73586 | rc = sqlite3BtreeCount(pCrsr, &nEntry); |
| 73587 | pOut = out2Prerelease(p, pOp); |
| 73588 | pOut->u.i = nEntry; |
| 73589 | break; |
| 73590 | } |
| 73591 | #endif |
| 73592 | |
| @@ -73530,11 +73696,11 @@ | |
| 73696 | if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 73697 | goto vdbe_return; |
| 73698 | } |
| 73699 | db->autoCommit = 1; |
| 73700 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 73701 | p->pc = (int)(pOp - aOp); |
| 73702 | db->autoCommit = 0; |
| 73703 | p->rc = rc = SQLITE_BUSY; |
| 73704 | goto vdbe_return; |
| 73705 | } |
| 73706 | db->isTransactionSavepoint = 0; |
| @@ -73589,11 +73755,11 @@ | |
| 73755 | }else{ |
| 73756 | db->nDeferredCons = pSavepoint->nDeferredCons; |
| 73757 | db->nDeferredImmCons = pSavepoint->nDeferredImmCons; |
| 73758 | } |
| 73759 | |
| 73760 | if( !isTransaction || p1==SAVEPOINT_ROLLBACK ){ |
| 73761 | rc = sqlite3VtabSavepoint(db, p1, iSavepoint); |
| 73762 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 73763 | } |
| 73764 | } |
| 73765 | } |
| @@ -73649,11 +73815,11 @@ | |
| 73815 | }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 73816 | goto vdbe_return; |
| 73817 | }else{ |
| 73818 | db->autoCommit = (u8)desiredAutoCommit; |
| 73819 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 73820 | p->pc = (int)(pOp - aOp); |
| 73821 | db->autoCommit = (u8)(1-desiredAutoCommit); |
| 73822 | p->rc = rc = SQLITE_BUSY; |
| 73823 | goto vdbe_return; |
| 73824 | } |
| 73825 | } |
| @@ -73726,11 +73892,11 @@ | |
| 73892 | pBt = db->aDb[pOp->p1].pBt; |
| 73893 | |
| 73894 | if( pBt ){ |
| 73895 | rc = sqlite3BtreeBeginTrans(pBt, pOp->p2); |
| 73896 | if( rc==SQLITE_BUSY ){ |
| 73897 | p->pc = (int)(pOp - aOp); |
| 73898 | p->rc = rc = SQLITE_BUSY; |
| 73899 | goto vdbe_return; |
| 73900 | } |
| 73901 | if( rc!=SQLITE_OK ){ |
| 73902 | goto abort_due_to_error; |
| @@ -73805,11 +73971,11 @@ | |
| 73971 | ** |
| 73972 | ** There must be a read-lock on the database (either a transaction |
| 73973 | ** must be started or there must be an open cursor) before |
| 73974 | ** executing this instruction. |
| 73975 | */ |
| 73976 | case OP_ReadCookie: { /* out2 */ |
| 73977 | int iMeta; |
| 73978 | int iDb; |
| 73979 | int iCookie; |
| 73980 | |
| 73981 | assert( p->bIsReader ); |
| @@ -73819,10 +73985,11 @@ | |
| 73985 | assert( iDb>=0 && iDb<db->nDb ); |
| 73986 | assert( db->aDb[iDb].pBt!=0 ); |
| 73987 | assert( DbMaskTest(p->btreeMask, iDb) ); |
| 73988 | |
| 73989 | sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta); |
| 73990 | pOut = out2Prerelease(p, pOp); |
| 73991 | pOut->u.i = iMeta; |
| 73992 | break; |
| 73993 | } |
| 73994 | |
| 73995 | /* Opcode: SetCookie P1 P2 P3 * * |
| @@ -74140,11 +74307,11 @@ | |
| 74307 | VdbeCursor *pC; |
| 74308 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 74309 | pC = p->apCsr[pOp->p1]; |
| 74310 | assert( pC->pSorter ); |
| 74311 | if( (pC->seqCount++)==0 ){ |
| 74312 | goto jump_to_p2; |
| 74313 | } |
| 74314 | break; |
| 74315 | } |
| 74316 | |
| 74317 | /* Opcode: OpenPseudo P1 P2 P3 * * |
| @@ -74317,11 +74484,11 @@ | |
| 74484 | ** loss of information, then special processing is required... */ |
| 74485 | if( (pIn3->flags & MEM_Int)==0 ){ |
| 74486 | if( (pIn3->flags & MEM_Real)==0 ){ |
| 74487 | /* If the P3 value cannot be converted into any kind of a number, |
| 74488 | ** then the seek is not possible, so jump to P2 */ |
| 74489 | VdbeBranchTaken(1,2); goto jump_to_p2; |
| 74490 | break; |
| 74491 | } |
| 74492 | |
| 74493 | /* If the approximation iKey is larger than the actual real search |
| 74494 | ** term, substitute >= for > and < for <=. e.g. if the search term |
| @@ -74408,11 +74575,11 @@ | |
| 74575 | } |
| 74576 | } |
| 74577 | assert( pOp->p2>0 ); |
| 74578 | VdbeBranchTaken(res!=0,2); |
| 74579 | if( res ){ |
| 74580 | goto jump_to_p2; |
| 74581 | } |
| 74582 | break; |
| 74583 | } |
| 74584 | |
| 74585 | /* Opcode: Seek P1 P2 * * * |
| @@ -74502,10 +74669,11 @@ | |
| 74669 | */ |
| 74670 | case OP_NoConflict: /* jump, in3 */ |
| 74671 | case OP_NotFound: /* jump, in3 */ |
| 74672 | case OP_Found: { /* jump, in3 */ |
| 74673 | int alreadyExists; |
| 74674 | int takeJump; |
| 74675 | int ii; |
| 74676 | VdbeCursor *pC; |
| 74677 | int res; |
| 74678 | char *pFree; |
| 74679 | UnpackedRecord *pIdxKey; |
| @@ -74524,11 +74692,11 @@ | |
| 74692 | pC->seekOp = pOp->opcode; |
| 74693 | #endif |
| 74694 | pIn3 = &aMem[pOp->p3]; |
| 74695 | assert( pC->pCursor!=0 ); |
| 74696 | assert( pC->isTable==0 ); |
| 74697 | pFree = 0; |
| 74698 | if( pOp->p4.i>0 ){ |
| 74699 | r.pKeyInfo = pC->pKeyInfo; |
| 74700 | r.nField = (u16)pOp->p4.i; |
| 74701 | r.aMem = pIn3; |
| 74702 | for(ii=0; ii<r.nField; ii++){ |
| @@ -74547,25 +74715,24 @@ | |
| 74715 | assert( pIn3->flags & MEM_Blob ); |
| 74716 | ExpandBlob(pIn3); |
| 74717 | sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); |
| 74718 | } |
| 74719 | pIdxKey->default_rc = 0; |
| 74720 | takeJump = 0; |
| 74721 | if( pOp->opcode==OP_NoConflict ){ |
| 74722 | /* For the OP_NoConflict opcode, take the jump if any of the |
| 74723 | ** input fields are NULL, since any key with a NULL will not |
| 74724 | ** conflict */ |
| 74725 | for(ii=0; ii<pIdxKey->nField; ii++){ |
| 74726 | if( pIdxKey->aMem[ii].flags & MEM_Null ){ |
| 74727 | takeJump = 1; |
| 74728 | break; |
| 74729 | } |
| 74730 | } |
| 74731 | } |
| 74732 | rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res); |
| 74733 | sqlite3DbFree(db, pFree); |
| 74734 | if( rc!=SQLITE_OK ){ |
| 74735 | break; |
| 74736 | } |
| 74737 | pC->seekResult = res; |
| 74738 | alreadyExists = (res==0); |
| @@ -74572,14 +74739,14 @@ | |
| 74739 | pC->nullRow = 1-alreadyExists; |
| 74740 | pC->deferredMoveto = 0; |
| 74741 | pC->cacheStatus = CACHE_STALE; |
| 74742 | if( pOp->opcode==OP_Found ){ |
| 74743 | VdbeBranchTaken(alreadyExists!=0,2); |
| 74744 | if( alreadyExists ) goto jump_to_p2; |
| 74745 | }else{ |
| 74746 | VdbeBranchTaken(takeJump||alreadyExists==0,2); |
| 74747 | if( takeJump || !alreadyExists ) goto jump_to_p2; |
| 74748 | } |
| 74749 | break; |
| 74750 | } |
| 74751 | |
| 74752 | /* Opcode: NotExists P1 P2 P3 * * |
| @@ -74624,14 +74791,12 @@ | |
| 74791 | pC->movetoTarget = iKey; /* Used by OP_Delete */ |
| 74792 | pC->nullRow = 0; |
| 74793 | pC->cacheStatus = CACHE_STALE; |
| 74794 | pC->deferredMoveto = 0; |
| 74795 | VdbeBranchTaken(res!=0,2); |
| 74796 | pC->seekResult = res; |
| 74797 | if( res!=0 ) goto jump_to_p2; |
| 74798 | break; |
| 74799 | } |
| 74800 | |
| 74801 | /* Opcode: Sequence P1 P2 * * * |
| 74802 | ** Synopsis: r[P2]=cursor[P1].ctr++ |
| @@ -74639,13 +74804,14 @@ | |
| 74804 | ** Find the next available sequence number for cursor P1. |
| 74805 | ** Write the sequence number into register P2. |
| 74806 | ** The sequence number on the cursor is incremented after this |
| 74807 | ** instruction. |
| 74808 | */ |
| 74809 | case OP_Sequence: { /* out2 */ |
| 74810 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 74811 | assert( p->apCsr[pOp->p1]!=0 ); |
| 74812 | pOut = out2Prerelease(p, pOp); |
| 74813 | pOut->u.i = p->apCsr[pOp->p1]->seqCount++; |
| 74814 | break; |
| 74815 | } |
| 74816 | |
| 74817 | |
| @@ -74662,20 +74828,21 @@ | |
| 74828 | ** allowed to be less than this value. When this value reaches its maximum, |
| 74829 | ** an SQLITE_FULL error is generated. The P3 register is updated with the ' |
| 74830 | ** generated record number. This P3 mechanism is used to help implement the |
| 74831 | ** AUTOINCREMENT feature. |
| 74832 | */ |
| 74833 | case OP_NewRowid: { /* out2 */ |
| 74834 | i64 v; /* The new rowid */ |
| 74835 | VdbeCursor *pC; /* Cursor of table to get the new rowid */ |
| 74836 | int res; /* Result of an sqlite3BtreeLast() */ |
| 74837 | int cnt; /* Counter to limit the number of searches */ |
| 74838 | Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ |
| 74839 | VdbeFrame *pFrame; /* Root frame of VDBE */ |
| 74840 | |
| 74841 | v = 0; |
| 74842 | res = 0; |
| 74843 | pOut = out2Prerelease(p, pOp); |
| 74844 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 74845 | pC = p->apCsr[pOp->p1]; |
| 74846 | assert( pC!=0 ); |
| 74847 | if( NEVER(pC->pCursor==0) ){ |
| 74848 | /* The zero initialization above is all that is needed */ |
| @@ -74985,13 +75152,11 @@ | |
| 75152 | pIn3 = &aMem[pOp->p3]; |
| 75153 | nKeyCol = pOp->p4.i; |
| 75154 | res = 0; |
| 75155 | rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res); |
| 75156 | VdbeBranchTaken(res!=0,2); |
| 75157 | if( res ) goto jump_to_p2; |
| 75158 | break; |
| 75159 | }; |
| 75160 | |
| 75161 | /* Opcode: SorterData P1 P2 P3 * * |
| 75162 | ** Synopsis: r[P2]=data |
| @@ -75116,16 +75281,17 @@ | |
| 75281 | ** |
| 75282 | ** P1 can be either an ordinary table or a virtual table. There used to |
| 75283 | ** be a separate OP_VRowid opcode for use with virtual tables, but this |
| 75284 | ** one opcode now works for both table types. |
| 75285 | */ |
| 75286 | case OP_Rowid: { /* out2 */ |
| 75287 | VdbeCursor *pC; |
| 75288 | i64 v; |
| 75289 | sqlite3_vtab *pVtab; |
| 75290 | const sqlite3_module *pModule; |
| 75291 | |
| 75292 | pOut = out2Prerelease(p, pOp); |
| 75293 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 75294 | pC = p->apCsr[pOp->p1]; |
| 75295 | assert( pC!=0 ); |
| 75296 | assert( pC->pseudoTableReg==0 || pC->nullRow ); |
| 75297 | if( pC->nullRow ){ |
| @@ -75174,11 +75340,11 @@ | |
| 75340 | sqlite3BtreeClearCursor(pC->pCursor); |
| 75341 | } |
| 75342 | break; |
| 75343 | } |
| 75344 | |
| 75345 | /* Opcode: Last P1 P2 P3 * * |
| 75346 | ** |
| 75347 | ** The next use of the Rowid or Column or Prev instruction for P1 |
| 75348 | ** will refer to the last entry in the database table or index. |
| 75349 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 75350 | ** If P2 is 0 or if the table or index is not empty, fall through |
| @@ -75201,16 +75367,17 @@ | |
| 75367 | assert( pCrsr!=0 ); |
| 75368 | rc = sqlite3BtreeLast(pCrsr, &res); |
| 75369 | pC->nullRow = (u8)res; |
| 75370 | pC->deferredMoveto = 0; |
| 75371 | pC->cacheStatus = CACHE_STALE; |
| 75372 | pC->seekResult = pOp->p3; |
| 75373 | #ifdef SQLITE_DEBUG |
| 75374 | pC->seekOp = OP_Last; |
| 75375 | #endif |
| 75376 | if( pOp->p2>0 ){ |
| 75377 | VdbeBranchTaken(res!=0,2); |
| 75378 | if( res ) goto jump_to_p2; |
| 75379 | } |
| 75380 | break; |
| 75381 | } |
| 75382 | |
| 75383 | |
| @@ -75270,13 +75437,11 @@ | |
| 75437 | pC->cacheStatus = CACHE_STALE; |
| 75438 | } |
| 75439 | pC->nullRow = (u8)res; |
| 75440 | assert( pOp->p2>0 && pOp->p2<p->nOp ); |
| 75441 | VdbeBranchTaken(res!=0,2); |
| 75442 | if( res ) goto jump_to_p2; |
| 75443 | break; |
| 75444 | } |
| 75445 | |
| 75446 | /* Opcode: Next P1 P2 P3 P4 P5 |
| 75447 | ** |
| @@ -75383,15 +75548,15 @@ | |
| 75548 | next_tail: |
| 75549 | pC->cacheStatus = CACHE_STALE; |
| 75550 | VdbeBranchTaken(res==0,2); |
| 75551 | if( res==0 ){ |
| 75552 | pC->nullRow = 0; |
| 75553 | p->aCounter[pOp->p5]++; |
| 75554 | #ifdef SQLITE_TEST |
| 75555 | sqlite3_search_count++; |
| 75556 | #endif |
| 75557 | goto jump_to_p2_and_check_for_interrupt; |
| 75558 | }else{ |
| 75559 | pC->nullRow = 1; |
| 75560 | } |
| 75561 | goto check_for_interrupt; |
| 75562 | } |
| @@ -75495,15 +75660,16 @@ | |
| 75660 | ** the end of the index key pointed to by cursor P1. This integer should be |
| 75661 | ** the rowid of the table entry to which this index entry points. |
| 75662 | ** |
| 75663 | ** See also: Rowid, MakeRecord. |
| 75664 | */ |
| 75665 | case OP_IdxRowid: { /* out2 */ |
| 75666 | BtCursor *pCrsr; |
| 75667 | VdbeCursor *pC; |
| 75668 | i64 rowid; |
| 75669 | |
| 75670 | pOut = out2Prerelease(p, pOp); |
| 75671 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 75672 | pC = p->apCsr[pOp->p1]; |
| 75673 | assert( pC!=0 ); |
| 75674 | pCrsr = pC->pCursor; |
| 75675 | assert( pCrsr!=0 ); |
| @@ -75612,13 +75778,11 @@ | |
| 75778 | }else{ |
| 75779 | assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT ); |
| 75780 | res++; |
| 75781 | } |
| 75782 | VdbeBranchTaken(res>0,2); |
| 75783 | if( res>0 ) goto jump_to_p2; |
| 75784 | break; |
| 75785 | } |
| 75786 | |
| 75787 | /* Opcode: Destroy P1 P2 P3 * * |
| 75788 | ** |
| @@ -75638,15 +75802,16 @@ | |
| 75802 | ** the last one in the database) then a zero is stored in register P2. |
| 75803 | ** If AUTOVACUUM is disabled then a zero is stored in register P2. |
| 75804 | ** |
| 75805 | ** See also: Clear |
| 75806 | */ |
| 75807 | case OP_Destroy: { /* out2 */ |
| 75808 | int iMoved; |
| 75809 | int iDb; |
| 75810 | |
| 75811 | assert( p->readOnly==0 ); |
| 75812 | pOut = out2Prerelease(p, pOp); |
| 75813 | pOut->flags = MEM_Null; |
| 75814 | if( db->nVdbeRead > db->nVDestroy+1 ){ |
| 75815 | rc = SQLITE_LOCKED; |
| 75816 | p->errorAction = OE_Abort; |
| 75817 | }else{ |
| @@ -75751,16 +75916,17 @@ | |
| 75916 | ** P1>1. Write the root page number of the new table into |
| 75917 | ** register P2. |
| 75918 | ** |
| 75919 | ** See documentation on OP_CreateTable for additional information. |
| 75920 | */ |
| 75921 | case OP_CreateIndex: /* out2 */ |
| 75922 | case OP_CreateTable: { /* out2 */ |
| 75923 | int pgno; |
| 75924 | int flags; |
| 75925 | Db *pDb; |
| 75926 | |
| 75927 | pOut = out2Prerelease(p, pOp); |
| 75928 | pgno = 0; |
| 75929 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 75930 | assert( DbMaskTest(p->btreeMask, pOp->p1) ); |
| 75931 | assert( p->readOnly==0 ); |
| 75932 | pDb = &db->aDb[pOp->p1]; |
| @@ -75982,16 +76148,16 @@ | |
| 76148 | if( (pIn1->flags & MEM_RowSet)==0 |
| 76149 | || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0 |
| 76150 | ){ |
| 76151 | /* The boolean index is empty */ |
| 76152 | sqlite3VdbeMemSetNull(pIn1); |
| 76153 | VdbeBranchTaken(1,2); |
| 76154 | goto jump_to_p2_and_check_for_interrupt; |
| 76155 | }else{ |
| 76156 | /* A value was pulled from the index */ |
| 76157 | VdbeBranchTaken(0,2); |
| 76158 | sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); |
| 76159 | } |
| 76160 | goto check_for_interrupt; |
| 76161 | } |
| 76162 | |
| 76163 | /* Opcode: RowSetTest P1 P2 P3 P4 |
| @@ -76038,14 +76204,11 @@ | |
| 76204 | assert( pOp->p4type==P4_INT32 ); |
| 76205 | assert( iSet==-1 || iSet>=0 ); |
| 76206 | if( iSet ){ |
| 76207 | exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i); |
| 76208 | VdbeBranchTaken(exists!=0,2); |
| 76209 | if( exists ) goto jump_to_p2; |
| 76210 | } |
| 76211 | if( iSet>=0 ){ |
| 76212 | sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i); |
| 76213 | } |
| 76214 | break; |
| @@ -76130,11 +76293,11 @@ | |
| 76293 | pRt->u.pFrame = pFrame; |
| 76294 | |
| 76295 | pFrame->v = p; |
| 76296 | pFrame->nChildMem = nMem; |
| 76297 | pFrame->nChildCsr = pProgram->nCsr; |
| 76298 | pFrame->pc = (int)(pOp - aOp); |
| 76299 | pFrame->aMem = p->aMem; |
| 76300 | pFrame->nMem = p->nMem; |
| 76301 | pFrame->apCsr = p->apCsr; |
| 76302 | pFrame->nCursor = p->nCursor; |
| 76303 | pFrame->aOp = p->aOp; |
| @@ -76153,11 +76316,11 @@ | |
| 76316 | } |
| 76317 | }else{ |
| 76318 | pFrame = pRt->u.pFrame; |
| 76319 | assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem ); |
| 76320 | assert( pProgram->nCsr==pFrame->nChildCsr ); |
| 76321 | assert( (int)(pOp - aOp)==pFrame->pc ); |
| 76322 | } |
| 76323 | |
| 76324 | p->nFrame++; |
| 76325 | pFrame->pParent = p->pFrame; |
| 76326 | pFrame->lastRowid = lastRowid; |
| @@ -76174,11 +76337,11 @@ | |
| 76337 | p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 76338 | p->nOnceFlag = pProgram->nOnce; |
| 76339 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 76340 | p->anExec = 0; |
| 76341 | #endif |
| 76342 | pOp = &aOp[-1]; |
| 76343 | memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 76344 | |
| 76345 | break; |
| 76346 | } |
| 76347 | |
| @@ -76192,13 +76355,14 @@ | |
| 76355 | ** |
| 76356 | ** The address of the cell in the parent frame is determined by adding |
| 76357 | ** the value of the P1 argument to the value of the P1 argument to the |
| 76358 | ** calling OP_Program instruction. |
| 76359 | */ |
| 76360 | case OP_Param: { /* out2 */ |
| 76361 | VdbeFrame *pFrame; |
| 76362 | Mem *pIn; |
| 76363 | pOut = out2Prerelease(p, pOp); |
| 76364 | pFrame = p->pFrame; |
| 76365 | pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1]; |
| 76366 | sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem); |
| 76367 | break; |
| 76368 | } |
| @@ -76238,14 +76402,14 @@ | |
| 76402 | ** (immediate foreign key constraint violations). |
| 76403 | */ |
| 76404 | case OP_FkIfZero: { /* jump */ |
| 76405 | if( pOp->p1 ){ |
| 76406 | VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2); |
| 76407 | if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2; |
| 76408 | }else{ |
| 76409 | VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2); |
| 76410 | if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2; |
| 76411 | } |
| 76412 | break; |
| 76413 | } |
| 76414 | #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */ |
| 76415 | |
| @@ -76292,13 +76456,11 @@ | |
| 76456 | */ |
| 76457 | case OP_IfPos: { /* jump, in1 */ |
| 76458 | pIn1 = &aMem[pOp->p1]; |
| 76459 | assert( pIn1->flags&MEM_Int ); |
| 76460 | VdbeBranchTaken( pIn1->u.i>0, 2); |
| 76461 | if( pIn1->u.i>0 ) goto jump_to_p2; |
| 76462 | break; |
| 76463 | } |
| 76464 | |
| 76465 | /* Opcode: IfNeg P1 P2 P3 * * |
| 76466 | ** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2 |
| @@ -76309,13 +76471,11 @@ | |
| 76471 | case OP_IfNeg: { /* jump, in1 */ |
| 76472 | pIn1 = &aMem[pOp->p1]; |
| 76473 | assert( pIn1->flags&MEM_Int ); |
| 76474 | pIn1->u.i += pOp->p3; |
| 76475 | VdbeBranchTaken(pIn1->u.i<0, 2); |
| 76476 | if( pIn1->u.i<0 ) goto jump_to_p2; |
| 76477 | break; |
| 76478 | } |
| 76479 | |
| 76480 | /* Opcode: IfNotZero P1 P2 P3 * * |
| 76481 | ** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2 |
| @@ -76328,11 +76488,11 @@ | |
| 76488 | pIn1 = &aMem[pOp->p1]; |
| 76489 | assert( pIn1->flags&MEM_Int ); |
| 76490 | VdbeBranchTaken(pIn1->u.i<0, 2); |
| 76491 | if( pIn1->u.i ){ |
| 76492 | pIn1->u.i += pOp->p3; |
| 76493 | goto jump_to_p2; |
| 76494 | } |
| 76495 | break; |
| 76496 | } |
| 76497 | |
| 76498 | /* Opcode: DecrJumpZero P1 P2 * * * |
| @@ -76344,13 +76504,11 @@ | |
| 76504 | case OP_DecrJumpZero: { /* jump, in1 */ |
| 76505 | pIn1 = &aMem[pOp->p1]; |
| 76506 | assert( pIn1->flags&MEM_Int ); |
| 76507 | pIn1->u.i--; |
| 76508 | VdbeBranchTaken(pIn1->u.i==0, 2); |
| 76509 | if( pIn1->u.i==0 ) goto jump_to_p2; |
| 76510 | break; |
| 76511 | } |
| 76512 | |
| 76513 | |
| 76514 | /* Opcode: JumpZeroIncr P1 P2 * * * |
| @@ -76362,13 +76520,11 @@ | |
| 76520 | */ |
| 76521 | case OP_JumpZeroIncr: { /* jump, in1 */ |
| 76522 | pIn1 = &aMem[pOp->p1]; |
| 76523 | assert( pIn1->flags&MEM_Int ); |
| 76524 | VdbeBranchTaken(pIn1->u.i==0, 2); |
| 76525 | if( (pIn1->u.i++)==0 ) goto jump_to_p2; |
| 76526 | break; |
| 76527 | } |
| 76528 | |
| 76529 | /* Opcode: AggStep * P2 P3 P4 P5 |
| 76530 | ** Synopsis: accum=r[P3] step(r[P2@P5]) |
| @@ -76406,11 +76562,11 @@ | |
| 76562 | pMem->n++; |
| 76563 | sqlite3VdbeMemInit(&t, db, MEM_Null); |
| 76564 | ctx.pOut = &t; |
| 76565 | ctx.isError = 0; |
| 76566 | ctx.pVdbe = p; |
| 76567 | ctx.iOp = (int)(pOp - aOp); |
| 76568 | ctx.skipFlag = 0; |
| 76569 | (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */ |
| 76570 | if( ctx.isError ){ |
| 76571 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t)); |
| 76572 | rc = ctx.isError; |
| @@ -76501,19 +76657,20 @@ | |
| 76657 | ** |
| 76658 | ** If changing into or out of WAL mode the procedure is more complicated. |
| 76659 | ** |
| 76660 | ** Write a string containing the final journal-mode to register P2. |
| 76661 | */ |
| 76662 | case OP_JournalMode: { /* out2 */ |
| 76663 | Btree *pBt; /* Btree to change journal mode of */ |
| 76664 | Pager *pPager; /* Pager associated with pBt */ |
| 76665 | int eNew; /* New journal mode */ |
| 76666 | int eOld; /* The old journal mode */ |
| 76667 | #ifndef SQLITE_OMIT_WAL |
| 76668 | const char *zFilename; /* Name of database file for pPager */ |
| 76669 | #endif |
| 76670 | |
| 76671 | pOut = out2Prerelease(p, pOp); |
| 76672 | eNew = pOp->p3; |
| 76673 | assert( eNew==PAGER_JOURNALMODE_DELETE |
| 76674 | || eNew==PAGER_JOURNALMODE_TRUNCATE |
| 76675 | || eNew==PAGER_JOURNALMODE_PERSIST |
| 76676 | || eNew==PAGER_JOURNALMODE_OFF |
| @@ -76626,12 +76783,12 @@ | |
| 76783 | assert( p->readOnly==0 ); |
| 76784 | pBt = db->aDb[pOp->p1].pBt; |
| 76785 | rc = sqlite3BtreeIncrVacuum(pBt); |
| 76786 | VdbeBranchTaken(rc==SQLITE_DONE,2); |
| 76787 | if( rc==SQLITE_DONE ){ |
| 76788 | rc = SQLITE_OK; |
| 76789 | goto jump_to_p2; |
| 76790 | } |
| 76791 | break; |
| 76792 | } |
| 76793 | #endif |
| 76794 | |
| @@ -76780,12 +76937,13 @@ | |
| 76937 | pCur = allocateCursor(p, pOp->p1, 0, -1, 0); |
| 76938 | if( pCur ){ |
| 76939 | pCur->pVtabCursor = pVtabCursor; |
| 76940 | pVtab->nRef++; |
| 76941 | }else{ |
| 76942 | assert( db->mallocFailed ); |
| 76943 | pModule->xClose(pVtabCursor); |
| 76944 | goto no_mem; |
| 76945 | } |
| 76946 | } |
| 76947 | break; |
| 76948 | } |
| 76949 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| @@ -76837,29 +76995,23 @@ | |
| 76995 | assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int ); |
| 76996 | nArg = (int)pArgc->u.i; |
| 76997 | iQuery = (int)pQuery->u.i; |
| 76998 | |
| 76999 | /* Invoke the xFilter method */ |
| 77000 | res = 0; |
| 77001 | apArg = p->apArg; |
| 77002 | for(i = 0; i<nArg; i++){ |
| 77003 | apArg[i] = &pArgc[i+1]; |
| 77004 | } |
| 77005 | rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); |
| 77006 | sqlite3VtabImportErrmsg(p, pVtab); |
| 77007 | if( rc==SQLITE_OK ){ |
| 77008 | res = pModule->xEof(pVtabCursor); |
| 77009 | } |
| 77010 | pCur->nullRow = 0; |
| 77011 | VdbeBranchTaken(res!=0,2); |
| 77012 | if( res ) goto jump_to_p2; |
| 77013 | break; |
| 77014 | } |
| 77015 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 77016 | |
| 77017 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| @@ -76942,11 +77094,11 @@ | |
| 77094 | res = pModule->xEof(pCur->pVtabCursor); |
| 77095 | } |
| 77096 | VdbeBranchTaken(!res,2); |
| 77097 | if( !res ){ |
| 77098 | /* If there is data, jump to P2 */ |
| 77099 | goto jump_to_p2_and_check_for_interrupt; |
| 77100 | } |
| 77101 | goto check_for_interrupt; |
| 77102 | } |
| 77103 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 77104 | |
| @@ -77065,11 +77217,12 @@ | |
| 77217 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 77218 | /* Opcode: Pagecount P1 P2 * * * |
| 77219 | ** |
| 77220 | ** Write the current number of pages in database P1 to memory cell P2. |
| 77221 | */ |
| 77222 | case OP_Pagecount: { /* out2 */ |
| 77223 | pOut = out2Prerelease(p, pOp); |
| 77224 | pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt); |
| 77225 | break; |
| 77226 | } |
| 77227 | #endif |
| 77228 | |
| @@ -77081,14 +77234,15 @@ | |
| 77234 | ** Do not let the maximum page count fall below the current page count and |
| 77235 | ** do not change the maximum page count value if P3==0. |
| 77236 | ** |
| 77237 | ** Store the maximum page count after the change in register P2. |
| 77238 | */ |
| 77239 | case OP_MaxPgcnt: { /* out2 */ |
| 77240 | unsigned int newMax; |
| 77241 | Btree *pBt; |
| 77242 | |
| 77243 | pOut = out2Prerelease(p, pOp); |
| 77244 | pBt = db->aDb[pOp->p1].pBt; |
| 77245 | newMax = 0; |
| 77246 | if( pOp->p3 ){ |
| 77247 | newMax = sqlite3BtreeLastPage(pBt); |
| 77248 | if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3; |
| @@ -77113,13 +77267,10 @@ | |
| 77267 | */ |
| 77268 | case OP_Init: { /* jump */ |
| 77269 | char *zTrace; |
| 77270 | char *z; |
| 77271 | |
| 77272 | #ifndef SQLITE_OMIT_TRACE |
| 77273 | if( db->xTrace |
| 77274 | && !p->doingRerun |
| 77275 | && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 77276 | ){ |
| @@ -77143,10 +77294,11 @@ | |
| 77294 | ){ |
| 77295 | sqlite3DebugPrintf("SQL-trace: %s\n", zTrace); |
| 77296 | } |
| 77297 | #endif /* SQLITE_DEBUG */ |
| 77298 | #endif /* SQLITE_OMIT_TRACE */ |
| 77299 | if( pOp->p2 ) goto jump_to_p2; |
| 77300 | break; |
| 77301 | } |
| 77302 | |
| 77303 | |
| 77304 | /* Opcode: Noop * * * * * |
| @@ -77174,31 +77326,31 @@ | |
| 77326 | } |
| 77327 | |
| 77328 | #ifdef VDBE_PROFILE |
| 77329 | { |
| 77330 | u64 endTime = sqlite3Hwtime(); |
| 77331 | if( endTime>start ) pOrigOp->cycles += endTime - start; |
| 77332 | pOrigOp->cnt++; |
| 77333 | } |
| 77334 | #endif |
| 77335 | |
| 77336 | /* The following code adds nothing to the actual functionality |
| 77337 | ** of the program. It is only here for testing and debugging. |
| 77338 | ** On the other hand, it does burn CPU cycles every time through |
| 77339 | ** the evaluator loop. So we can leave it out when NDEBUG is defined. |
| 77340 | */ |
| 77341 | #ifndef NDEBUG |
| 77342 | assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] ); |
| 77343 | |
| 77344 | #ifdef SQLITE_DEBUG |
| 77345 | if( db->flags & SQLITE_VdbeTrace ){ |
| 77346 | if( rc!=0 ) printf("rc=%d\n",rc); |
| 77347 | if( pOrigOp->opflags & (OPFLG_OUT2) ){ |
| 77348 | registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]); |
| 77349 | } |
| 77350 | if( pOrigOp->opflags & OPFLG_OUT3 ){ |
| 77351 | registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]); |
| 77352 | } |
| 77353 | } |
| 77354 | #endif /* SQLITE_DEBUG */ |
| 77355 | #endif /* NDEBUG */ |
| 77356 | } /* The end of the for(;;) loop the loops through opcodes */ |
| @@ -77209,11 +77361,11 @@ | |
| 77361 | vdbe_error_halt: |
| 77362 | assert( rc ); |
| 77363 | p->rc = rc; |
| 77364 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 77365 | sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 77366 | (int)(pOp - aOp), p->zSql, p->zErrMsg); |
| 77367 | sqlite3VdbeHalt(p); |
| 77368 | if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; |
| 77369 | rc = SQLITE_ERROR; |
| 77370 | if( resetSchemaOnFault>0 ){ |
| 77371 | sqlite3ResetOneSchema(db, resetSchemaOnFault-1); |
| @@ -78035,20 +78187,23 @@ | |
| 78187 | ** |
| 78188 | ** In both cases, the effects of the main thread seeing (bDone==0) even |
| 78189 | ** after the thread has finished are not dire. So we don't worry about |
| 78190 | ** memory barriers and such here. |
| 78191 | */ |
| 78192 | typedef int (*SorterCompare)(SortSubtask*,int*,const void*,int,const void*,int); |
| 78193 | struct SortSubtask { |
| 78194 | SQLiteThread *pThread; /* Background thread, if any */ |
| 78195 | int bDone; /* Set if thread is finished but not joined */ |
| 78196 | VdbeSorter *pSorter; /* Sorter that owns this sub-task */ |
| 78197 | UnpackedRecord *pUnpacked; /* Space to unpack a record */ |
| 78198 | SorterList list; /* List for thread to write to a PMA */ |
| 78199 | int nPMA; /* Number of PMAs currently in file */ |
| 78200 | SorterCompare xCompare; /* Compare function to use */ |
| 78201 | SorterFile file; /* Temp file for level-0 PMAs */ |
| 78202 | SorterFile file2; /* Space for other PMAs */ |
| 78203 | }; |
| 78204 | |
| 78205 | |
| 78206 | /* |
| 78207 | ** Main sorter structure. A single instance of this is allocated for each |
| 78208 | ** sorter cursor created by the VDBE. |
| 78209 | ** |
| @@ -78072,12 +78227,16 @@ | |
| 78227 | int nMemory; /* Size of list.aMemory allocation in bytes */ |
| 78228 | u8 bUsePMA; /* True if one or more PMAs created */ |
| 78229 | u8 bUseThreads; /* True to use background threads */ |
| 78230 | u8 iPrev; /* Previous thread used to flush PMA */ |
| 78231 | u8 nTask; /* Size of aTask[] array */ |
| 78232 | u8 typeMask; |
| 78233 | SortSubtask aTask[1]; /* One or more subtasks */ |
| 78234 | }; |
| 78235 | |
| 78236 | #define SORTER_TYPE_INTEGER 0x01 |
| 78237 | #define SORTER_TYPE_TEXT 0x02 |
| 78238 | |
| 78239 | /* |
| 78240 | ** An instance of the following object is used to read records out of a |
| 78241 | ** PMA, in sorted order. The next key to be read is cached in nKey/aKey. |
| 78242 | ** aKey might point into aMap or into aBuffer. If neither of those locations |
| @@ -78486,35 +78645,165 @@ | |
| 78645 | rc = vdbePmaReaderNext(pReadr); |
| 78646 | } |
| 78647 | return rc; |
| 78648 | } |
| 78649 | |
| 78650 | /* |
| 78651 | ** A version of vdbeSorterCompare() that assumes that it has already been |
| 78652 | ** determined that the first field of key1 is equal to the first field of |
| 78653 | ** key2. |
| 78654 | */ |
| 78655 | static int vdbeSorterCompareTail( |
| 78656 | SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ |
| 78657 | int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ |
| 78658 | const void *pKey1, int nKey1, /* Left side of comparison */ |
| 78659 | const void *pKey2, int nKey2 /* Right side of comparison */ |
| 78660 | ){ |
| 78661 | UnpackedRecord *r2 = pTask->pUnpacked; |
| 78662 | if( *pbKey2Cached==0 ){ |
| 78663 | sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); |
| 78664 | *pbKey2Cached = 1; |
| 78665 | } |
| 78666 | return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1); |
| 78667 | } |
| 78668 | |
| 78669 | /* |
| 78670 | ** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2, |
| 78671 | ** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences |
| 78672 | ** used by the comparison. Return the result of the comparison. |
| 78673 | ** |
| 78674 | ** If IN/OUT parameter *pbKey2Cached is true when this function is called, |
| 78675 | ** it is assumed that (pTask->pUnpacked) contains the unpacked version |
| 78676 | ** of key2. If it is false, (pTask->pUnpacked) is populated with the unpacked |
| 78677 | ** version of key2 and *pbKey2Cached set to true before returning. |
| 78678 | ** |
| 78679 | ** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set |
| 78680 | ** to SQLITE_NOMEM. |
| 78681 | */ |
| 78682 | static int vdbeSorterCompare( |
| 78683 | SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ |
| 78684 | int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ |
| 78685 | const void *pKey1, int nKey1, /* Left side of comparison */ |
| 78686 | const void *pKey2, int nKey2 /* Right side of comparison */ |
| 78687 | ){ |
| 78688 | UnpackedRecord *r2 = pTask->pUnpacked; |
| 78689 | if( !*pbKey2Cached ){ |
| 78690 | sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); |
| 78691 | *pbKey2Cached = 1; |
| 78692 | } |
| 78693 | return sqlite3VdbeRecordCompare(nKey1, pKey1, r2); |
| 78694 | } |
| 78695 | |
| 78696 | /* |
| 78697 | ** A specially optimized version of vdbeSorterCompare() that assumes that |
| 78698 | ** the first field of each key is a TEXT value and that the collation |
| 78699 | ** sequence to compare them with is BINARY. |
| 78700 | */ |
| 78701 | static int vdbeSorterCompareText( |
| 78702 | SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ |
| 78703 | int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ |
| 78704 | const void *pKey1, int nKey1, /* Left side of comparison */ |
| 78705 | const void *pKey2, int nKey2 /* Right side of comparison */ |
| 78706 | ){ |
| 78707 | const u8 * const p1 = (const u8 * const)pKey1; |
| 78708 | const u8 * const p2 = (const u8 * const)pKey2; |
| 78709 | const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */ |
| 78710 | const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */ |
| 78711 | |
| 78712 | int n1; |
| 78713 | int n2; |
| 78714 | int res; |
| 78715 | |
| 78716 | getVarint32(&p1[1], n1); n1 = (n1 - 13) / 2; |
| 78717 | getVarint32(&p2[1], n2); n2 = (n2 - 13) / 2; |
| 78718 | res = memcmp(v1, v2, MIN(n1, n2)); |
| 78719 | if( res==0 ){ |
| 78720 | res = n1 - n2; |
| 78721 | } |
| 78722 | |
| 78723 | if( res==0 ){ |
| 78724 | if( pTask->pSorter->pKeyInfo->nField>1 ){ |
| 78725 | res = vdbeSorterCompareTail( |
| 78726 | pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2 |
| 78727 | ); |
| 78728 | } |
| 78729 | }else{ |
| 78730 | if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ |
| 78731 | res = res * -1; |
| 78732 | } |
| 78733 | } |
| 78734 | |
| 78735 | return res; |
| 78736 | } |
| 78737 | |
| 78738 | /* |
| 78739 | ** A specially optimized version of vdbeSorterCompare() that assumes that |
| 78740 | ** the first field of each key is an INTEGER value. |
| 78741 | */ |
| 78742 | static int vdbeSorterCompareInt( |
| 78743 | SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ |
| 78744 | int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ |
| 78745 | const void *pKey1, int nKey1, /* Left side of comparison */ |
| 78746 | const void *pKey2, int nKey2 /* Right side of comparison */ |
| 78747 | ){ |
| 78748 | const u8 * const p1 = (const u8 * const)pKey1; |
| 78749 | const u8 * const p2 = (const u8 * const)pKey2; |
| 78750 | const int s1 = p1[1]; /* Left hand serial type */ |
| 78751 | const int s2 = p2[1]; /* Right hand serial type */ |
| 78752 | const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */ |
| 78753 | const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */ |
| 78754 | int res; /* Return value */ |
| 78755 | |
| 78756 | assert( (s1>0 && s1<7) || s1==8 || s1==9 ); |
| 78757 | assert( (s2>0 && s2<7) || s2==8 || s2==9 ); |
| 78758 | |
| 78759 | if( s1>7 && s2>7 ){ |
| 78760 | res = s1 - s2; |
| 78761 | }else{ |
| 78762 | if( s1==s2 ){ |
| 78763 | if( (*v1 ^ *v2) & 0x80 ){ |
| 78764 | /* The two values have different signs */ |
| 78765 | res = (*v1 & 0x80) ? -1 : +1; |
| 78766 | }else{ |
| 78767 | /* The two values have the same sign. Compare using memcmp(). */ |
| 78768 | static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 }; |
| 78769 | int i; |
| 78770 | res = 0; |
| 78771 | for(i=0; i<aLen[s1]; i++){ |
| 78772 | if( (res = v1[i] - v2[i]) ) break; |
| 78773 | } |
| 78774 | } |
| 78775 | }else{ |
| 78776 | if( s2>7 ){ |
| 78777 | res = +1; |
| 78778 | }else if( s1>7 ){ |
| 78779 | res = -1; |
| 78780 | }else{ |
| 78781 | res = s1 - s2; |
| 78782 | } |
| 78783 | assert( res!=0 ); |
| 78784 | |
| 78785 | if( res>0 ){ |
| 78786 | if( *v1 & 0x80 ) res = -1; |
| 78787 | }else{ |
| 78788 | if( *v2 & 0x80 ) res = +1; |
| 78789 | } |
| 78790 | } |
| 78791 | } |
| 78792 | |
| 78793 | if( res==0 ){ |
| 78794 | if( pTask->pSorter->pKeyInfo->nField>1 ){ |
| 78795 | res = vdbeSorterCompareTail( |
| 78796 | pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2 |
| 78797 | ); |
| 78798 | } |
| 78799 | }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ |
| 78800 | res = res * -1; |
| 78801 | } |
| 78802 | |
| 78803 | return res; |
| 78804 | } |
| 78805 | |
| 78806 | /* |
| 78807 | ** Initialize the temporary index cursor just opened as a sorter cursor. |
| 78808 | ** |
| 78809 | ** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField) |
| @@ -78579,13 +78868,17 @@ | |
| 78868 | rc = SQLITE_NOMEM; |
| 78869 | }else{ |
| 78870 | pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz); |
| 78871 | memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo); |
| 78872 | pKeyInfo->db = 0; |
| 78873 | if( nField && nWorker==0 ){ |
| 78874 | pKeyInfo->nXField += (pKeyInfo->nField - nField); |
| 78875 | pKeyInfo->nField = nField; |
| 78876 | } |
| 78877 | pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt); |
| 78878 | pSorter->nTask = nWorker + 1; |
| 78879 | pSorter->iPrev = nWorker-1; |
| 78880 | pSorter->bUseThreads = (pSorter->nTask>1); |
| 78881 | pSorter->db = db; |
| 78882 | for(i=0; i<pSorter->nTask; i++){ |
| 78883 | SortSubtask *pTask = &pSorter->aTask[i]; |
| 78884 | pTask->pSorter = pSorter; |
| @@ -78607,10 +78900,16 @@ | |
| 78900 | pSorter->nMemory = pgsz; |
| 78901 | pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz); |
| 78902 | if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM; |
| 78903 | } |
| 78904 | } |
| 78905 | |
| 78906 | if( (pKeyInfo->nField+pKeyInfo->nXField)<13 |
| 78907 | && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl) |
| 78908 | ){ |
| 78909 | pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT; |
| 78910 | } |
| 78911 | } |
| 78912 | |
| 78913 | return rc; |
| 78914 | } |
| 78915 | #undef nWorker /* Defined at the top of this function */ |
| @@ -78631,34 +78930,28 @@ | |
| 78930 | ** Free all resources owned by the object indicated by argument pTask. All |
| 78931 | ** fields of *pTask are zeroed before returning. |
| 78932 | */ |
| 78933 | static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){ |
| 78934 | sqlite3DbFree(db, pTask->pUnpacked); |
| 78935 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 78936 | /* pTask->list.aMemory can only be non-zero if it was handed memory |
| 78937 | ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */ |
| 78938 | if( pTask->list.aMemory ){ |
| 78939 | sqlite3_free(pTask->list.aMemory); |
| 78940 | }else |
| 78941 | #endif |
| 78942 | { |
| 78943 | assert( pTask->list.aMemory==0 ); |
| 78944 | vdbeSorterRecordFree(0, pTask->list.pList); |
| 78945 | } |
| 78946 | if( pTask->file.pFd ){ |
| 78947 | sqlite3OsCloseFree(pTask->file.pFd); |
| 78948 | } |
| 78949 | if( pTask->file2.pFd ){ |
| 78950 | sqlite3OsCloseFree(pTask->file2.pFd); |
| 78951 | } |
| 78952 | memset(pTask, 0, sizeof(SortSubtask)); |
| 78953 | } |
| 78954 | |
| 78955 | #ifdef SQLITE_DEBUG_SORTER_THREADS |
| 78956 | static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){ |
| 78957 | i64 t; |
| @@ -78834,10 +79127,11 @@ | |
| 79127 | vdbeMergeEngineFree(pSorter->pMerger); |
| 79128 | pSorter->pMerger = 0; |
| 79129 | for(i=0; i<pSorter->nTask; i++){ |
| 79130 | SortSubtask *pTask = &pSorter->aTask[i]; |
| 79131 | vdbeSortSubtaskCleanup(db, pTask); |
| 79132 | pTask->pSorter = pSorter; |
| 79133 | } |
| 79134 | if( pSorter->list.aMemory==0 ){ |
| 79135 | vdbeSorterRecordFree(0, pSorter->list.pList); |
| 79136 | } |
| 79137 | pSorter->list.pList = 0; |
| @@ -78943,31 +79237,45 @@ | |
| 79237 | SorterRecord *p2, /* Second list to merge */ |
| 79238 | SorterRecord **ppOut /* OUT: Head of merged list */ |
| 79239 | ){ |
| 79240 | SorterRecord *pFinal = 0; |
| 79241 | SorterRecord **pp = &pFinal; |
| 79242 | int bCached = 0; |
| 79243 | |
| 79244 | while( p1 && p2 ){ |
| 79245 | int res; |
| 79246 | res = pTask->xCompare( |
| 79247 | pTask, &bCached, SRVAL(p1), p1->nVal, SRVAL(p2), p2->nVal |
| 79248 | ); |
| 79249 | |
| 79250 | if( res<=0 ){ |
| 79251 | *pp = p1; |
| 79252 | pp = &p1->u.pNext; |
| 79253 | p1 = p1->u.pNext; |
| 79254 | }else{ |
| 79255 | *pp = p2; |
| 79256 | pp = &p2->u.pNext; |
| 79257 | p2 = p2->u.pNext; |
| 79258 | bCached = 0; |
| 79259 | } |
| 79260 | } |
| 79261 | *pp = p1 ? p1 : p2; |
| 79262 | *ppOut = pFinal; |
| 79263 | } |
| 79264 | |
| 79265 | /* |
| 79266 | ** Return the SorterCompare function to compare values collected by the |
| 79267 | ** sorter object passed as the only argument. |
| 79268 | */ |
| 79269 | static SorterCompare vdbeSorterGetCompare(VdbeSorter *p){ |
| 79270 | if( p->typeMask==SORTER_TYPE_INTEGER ){ |
| 79271 | return vdbeSorterCompareInt; |
| 79272 | }else if( p->typeMask==SORTER_TYPE_TEXT ){ |
| 79273 | return vdbeSorterCompareText; |
| 79274 | } |
| 79275 | return vdbeSorterCompare; |
| 79276 | } |
| 79277 | |
| 79278 | /* |
| 79279 | ** Sort the linked list of records headed at pTask->pList. Return |
| 79280 | ** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if |
| 79281 | ** an error occurs. |
| @@ -78979,16 +79287,18 @@ | |
| 79287 | int rc; |
| 79288 | |
| 79289 | rc = vdbeSortAllocUnpacked(pTask); |
| 79290 | if( rc!=SQLITE_OK ) return rc; |
| 79291 | |
| 79292 | p = pList->pList; |
| 79293 | pTask->xCompare = vdbeSorterGetCompare(pTask->pSorter); |
| 79294 | |
| 79295 | aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *)); |
| 79296 | if( !aSlot ){ |
| 79297 | return SQLITE_NOMEM; |
| 79298 | } |
| 79299 | |
| 79300 | while( p ){ |
| 79301 | SorterRecord *pNext; |
| 79302 | if( pList->aMemory ){ |
| 79303 | if( (u8*)p==pList->aMemory ){ |
| 79304 | pNext = 0; |
| @@ -79198,28 +79508,27 @@ | |
| 79508 | /* Update contents of aTree[] */ |
| 79509 | if( rc==SQLITE_OK ){ |
| 79510 | int i; /* Index of aTree[] to recalculate */ |
| 79511 | PmaReader *pReadr1; /* First PmaReader to compare */ |
| 79512 | PmaReader *pReadr2; /* Second PmaReader to compare */ |
| 79513 | int bCached = 0; |
| 79514 | |
| 79515 | /* Find the first two PmaReaders to compare. The one that was just |
| 79516 | ** advanced (iPrev) and the one next to it in the array. */ |
| 79517 | pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)]; |
| 79518 | pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)]; |
| 79519 | |
| 79520 | for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){ |
| 79521 | /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */ |
| 79522 | int iRes; |
| 79523 | if( pReadr1->pFd==0 ){ |
| 79524 | iRes = +1; |
| 79525 | }else if( pReadr2->pFd==0 ){ |
| 79526 | iRes = -1; |
| 79527 | }else{ |
| 79528 | iRes = pTask->xCompare(pTask, &bCached, |
| 79529 | pReadr1->aKey, pReadr1->nKey, pReadr2->aKey, pReadr2->nKey |
| 79530 | ); |
| 79531 | } |
| 79532 | |
| 79533 | /* If pReadr1 contained the smaller value, set aTree[i] to its index. |
| 79534 | ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this |
| @@ -79237,13 +79546,13 @@ | |
| 79546 | ** is sorted from oldest to newest, so pReadr1 contains older values |
| 79547 | ** than pReadr2 iff (pReadr1<pReadr2). */ |
| 79548 | if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){ |
| 79549 | pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr); |
| 79550 | pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ]; |
| 79551 | bCached = 0; |
| 79552 | }else{ |
| 79553 | if( pReadr1->pFd ) bCached = 0; |
| 79554 | pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr); |
| 79555 | pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ]; |
| 79556 | } |
| 79557 | } |
| 79558 | *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0); |
| @@ -79346,10 +79655,20 @@ | |
| 79655 | SorterRecord *pNew; /* New list element */ |
| 79656 | |
| 79657 | int bFlush; /* True to flush contents of memory to PMA */ |
| 79658 | int nReq; /* Bytes of memory required */ |
| 79659 | int nPMA; /* Bytes of PMA space required */ |
| 79660 | int t; /* serial type of first record field */ |
| 79661 | |
| 79662 | getVarint32((const u8*)&pVal->z[1], t); |
| 79663 | if( t>0 && t<10 && t!=7 ){ |
| 79664 | pSorter->typeMask &= SORTER_TYPE_INTEGER; |
| 79665 | }else if( t>10 && (t & 0x01) ){ |
| 79666 | pSorter->typeMask &= SORTER_TYPE_TEXT; |
| 79667 | }else{ |
| 79668 | pSorter->typeMask = 0; |
| 79669 | } |
| 79670 | |
| 79671 | assert( pSorter ); |
| 79672 | |
| 79673 | /* Figure out whether or not the current contents of memory should be |
| 79674 | ** flushed to a PMA before continuing. If so, do so. |
| @@ -79611,14 +79930,16 @@ | |
| 79930 | if( p1->pFd==0 ){ |
| 79931 | iRes = i2; |
| 79932 | }else if( p2->pFd==0 ){ |
| 79933 | iRes = i1; |
| 79934 | }else{ |
| 79935 | SortSubtask *pTask = pMerger->pTask; |
| 79936 | int bCached = 0; |
| 79937 | int res; |
| 79938 | assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */ |
| 79939 | res = pTask->xCompare( |
| 79940 | pTask, &bCached, p1->aKey, p1->nKey, p2->aKey, p2->nKey |
| 79941 | ); |
| 79942 | if( res<=0 ){ |
| 79943 | iRes = i1; |
| 79944 | }else{ |
| 79945 | iRes = i2; |
| @@ -79638,15 +79959,16 @@ | |
| 79959 | */ |
| 79960 | #define INCRINIT_NORMAL 0 |
| 79961 | #define INCRINIT_TASK 1 |
| 79962 | #define INCRINIT_ROOT 2 |
| 79963 | |
| 79964 | /* |
| 79965 | ** Forward reference required as the vdbeIncrMergeInit() and |
| 79966 | ** vdbePmaReaderIncrInit() routines are called mutually recursively when |
| 79967 | ** building a merge tree. |
| 79968 | */ |
| 79969 | static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode); |
| 79970 | |
| 79971 | /* |
| 79972 | ** Initialize the MergeEngine object passed as the second argument. Once this |
| 79973 | ** function returns, the first key of merged data may be read from the |
| 79974 | ** MergeEngine object in the usual fashion. |
| @@ -79689,11 +80011,11 @@ | |
| 80011 | ** the main thread to fill its buffer. So calling PmaReaderNext() |
| 80012 | ** on this PmaReader before any of the multi-threaded PmaReaders takes |
| 80013 | ** better advantage of multi-processor hardware. */ |
| 80014 | rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]); |
| 80015 | }else{ |
| 80016 | rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i], INCRINIT_NORMAL); |
| 80017 | } |
| 80018 | if( rc!=SQLITE_OK ) return rc; |
| 80019 | } |
| 80020 | |
| 80021 | for(i=pMerger->nTree-1; i>0; i--){ |
| @@ -79701,21 +80023,19 @@ | |
| 80023 | } |
| 80024 | return pTask->pUnpacked->errCode; |
| 80025 | } |
| 80026 | |
| 80027 | /* |
| 80028 | ** The PmaReader passed as the first argument is guaranteed to be an |
| 80029 | ** incremental-reader (pReadr->pIncr!=0). This function serves to open |
| 80030 | ** and/or initialize the temp file related fields of the IncrMerge |
| 80031 | ** object at (pReadr->pIncr). |
| 80032 | ** |
| 80033 | ** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders |
| 80034 | ** in the sub-tree headed by pReadr are also initialized. Data is then |
| 80035 | ** loaded into the buffers belonging to pReadr and it is set to point to |
| 80036 | ** the first key in its range. |
| 80037 | ** |
| 80038 | ** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed |
| 80039 | ** to be a multi-threaded PmaReader and this function is being called in a |
| 80040 | ** background thread. In this case all PmaReaders in the sub-tree are |
| 80041 | ** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to |
| @@ -79738,93 +80058,112 @@ | |
| 80058 | ** SQLITE_OK is returned if successful, or an SQLite error code otherwise. |
| 80059 | */ |
| 80060 | static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){ |
| 80061 | int rc = SQLITE_OK; |
| 80062 | IncrMerger *pIncr = pReadr->pIncr; |
| 80063 | SortSubtask *pTask = pIncr->pTask; |
| 80064 | sqlite3 *db = pTask->pSorter->db; |
| 80065 | |
| 80066 | /* eMode is always INCRINIT_NORMAL in single-threaded mode */ |
| 80067 | assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL ); |
| 80068 | |
| 80069 | rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode); |
| 80070 | |
| 80071 | /* Set up the required files for pIncr. A multi-theaded IncrMerge object |
| 80072 | ** requires two temp files to itself, whereas a single-threaded object |
| 80073 | ** only requires a region of pTask->file2. */ |
| 80074 | if( rc==SQLITE_OK ){ |
| 80075 | int mxSz = pIncr->mxSz; |
| 80076 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 80077 | if( pIncr->bUseThread ){ |
| 80078 | rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd); |
| 80079 | if( rc==SQLITE_OK ){ |
| 80080 | rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd); |
| 80081 | } |
| 80082 | }else |
| 80083 | #endif |
| 80084 | /*if( !pIncr->bUseThread )*/{ |
| 80085 | if( pTask->file2.pFd==0 ){ |
| 80086 | assert( pTask->file2.iEof>0 ); |
| 80087 | rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd); |
| 80088 | pTask->file2.iEof = 0; |
| 80089 | } |
| 80090 | if( rc==SQLITE_OK ){ |
| 80091 | pIncr->aFile[1].pFd = pTask->file2.pFd; |
| 80092 | pIncr->iStartOff = pTask->file2.iEof; |
| 80093 | pTask->file2.iEof += mxSz; |
| 80094 | } |
| 80095 | } |
| 80096 | } |
| 80097 | |
| 80098 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 80099 | if( rc==SQLITE_OK && pIncr->bUseThread ){ |
| 80100 | /* Use the current thread to populate aFile[1], even though this |
| 80101 | ** PmaReader is multi-threaded. If this is an INCRINIT_TASK object, |
| 80102 | ** then this function is already running in background thread |
| 80103 | ** pIncr->pTask->thread. |
| 80104 | ** |
| 80105 | ** If this is the INCRINIT_ROOT object, then it is running in the |
| 80106 | ** main VDBE thread. But that is Ok, as that thread cannot return |
| 80107 | ** control to the VDBE or proceed with anything useful until the |
| 80108 | ** first results are ready from this merger object anyway. |
| 80109 | */ |
| 80110 | assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK ); |
| 80111 | rc = vdbeIncrPopulate(pIncr); |
| 80112 | } |
| 80113 | #endif |
| 80114 | |
| 80115 | if( rc==SQLITE_OK && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) ){ |
| 80116 | rc = vdbePmaReaderNext(pReadr); |
| 80117 | } |
| 80118 | |
| 80119 | return rc; |
| 80120 | } |
| 80121 | |
| 80122 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 80123 | /* |
| 80124 | ** The main routine for vdbePmaReaderIncrMergeInit() operations run in |
| 80125 | ** background threads. |
| 80126 | */ |
| 80127 | static void *vdbePmaReaderBgIncrInit(void *pCtx){ |
| 80128 | PmaReader *pReader = (PmaReader*)pCtx; |
| 80129 | void *pRet = SQLITE_INT_TO_PTR( |
| 80130 | vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK) |
| 80131 | ); |
| 80132 | pReader->pIncr->pTask->bDone = 1; |
| 80133 | return pRet; |
| 80134 | } |
| 80135 | #endif |
| 80136 | |
| 80137 | /* |
| 80138 | ** If the PmaReader passed as the first argument is not an incremental-reader |
| 80139 | ** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes |
| 80140 | ** the vdbePmaReaderIncrMergeInit() function with the parameters passed to |
| 80141 | ** this routine to initialize the incremental merge. |
| 80142 | ** |
| 80143 | ** If the IncrMerger object is multi-threaded (IncrMerger.bUseThread==1), |
| 80144 | ** then a background thread is launched to call vdbePmaReaderIncrMergeInit(). |
| 80145 | ** Or, if the IncrMerger is single threaded, the same function is called |
| 80146 | ** using the current thread. |
| 80147 | */ |
| 80148 | static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode){ |
| 80149 | IncrMerger *pIncr = pReadr->pIncr; /* Incremental merger */ |
| 80150 | int rc = SQLITE_OK; /* Return code */ |
| 80151 | if( pIncr ){ |
| 80152 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 80153 | assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK ); |
| 80154 | if( pIncr->bUseThread ){ |
| 80155 | void *pCtx = (void*)pReadr; |
| 80156 | rc = vdbeSorterCreateThread(pIncr->pTask, vdbePmaReaderBgIncrInit, pCtx); |
| 80157 | }else |
| 80158 | #endif |
| 80159 | { |
| 80160 | rc = vdbePmaReaderIncrMergeInit(pReadr, eMode); |
| 80161 | } |
| 80162 | } |
| 80163 | return rc; |
| 80164 | } |
| 80165 | |
| 80166 | /* |
| 80167 | ** Allocate a new MergeEngine object to merge the contents of nPMA level-0 |
| 80168 | ** PMAs from pTask->file. If no error occurs, set *ppOut to point to |
| 80169 | ** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut |
| @@ -80032,10 +80371,15 @@ | |
| 80371 | int rc; /* Return code */ |
| 80372 | SortSubtask *pTask0 = &pSorter->aTask[0]; |
| 80373 | MergeEngine *pMain = 0; |
| 80374 | #if SQLITE_MAX_WORKER_THREADS |
| 80375 | sqlite3 *db = pTask0->pSorter->db; |
| 80376 | int i; |
| 80377 | SorterCompare xCompare = vdbeSorterGetCompare(pSorter); |
| 80378 | for(i=0; i<pSorter->nTask; i++){ |
| 80379 | pSorter->aTask[i].xCompare = xCompare; |
| 80380 | } |
| 80381 | #endif |
| 80382 | |
| 80383 | rc = vdbeSorterMergeTreeBuild(pSorter, &pMain); |
| 80384 | if( rc==SQLITE_OK ){ |
| 80385 | #if SQLITE_MAX_WORKER_THREADS |
| @@ -80060,19 +80404,25 @@ | |
| 80404 | vdbeIncrMergerSetThreads(pIncr); |
| 80405 | assert( pIncr->pTask!=pLast ); |
| 80406 | } |
| 80407 | } |
| 80408 | for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){ |
| 80409 | /* Check that: |
| 80410 | ** |
| 80411 | ** a) The incremental merge object is configured to use the |
| 80412 | ** right task, and |
| 80413 | ** b) If it is using task (nTask-1), it is configured to run |
| 80414 | ** in single-threaded mode. This is important, as the |
| 80415 | ** root merge (INCRINIT_ROOT) will be using the same task |
| 80416 | ** object. |
| 80417 | */ |
| 80418 | PmaReader *p = &pMain->aReadr[iTask]; |
| 80419 | assert( p->pIncr==0 || ( |
| 80420 | (p->pIncr->pTask==&pSorter->aTask[iTask]) /* a */ |
| 80421 | && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */ |
| 80422 | )); |
| 80423 | rc = vdbePmaReaderIncrInit(p, INCRINIT_TASK); |
| 80424 | } |
| 80425 | } |
| 80426 | pMain = 0; |
| 80427 | } |
| 80428 | if( rc==SQLITE_OK ){ |
| @@ -81023,11 +81373,11 @@ | |
| 81373 | ** Should be transformed into: |
| 81374 | ** |
| 81375 | ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase; |
| 81376 | ** |
| 81377 | ** The nSubquery parameter specifies how many levels of subquery the |
| 81378 | ** alias is removed from the original expression. The usual value is |
| 81379 | ** zero but it might be more if the alias is contained within a subquery |
| 81380 | ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION |
| 81381 | ** structures must be increased by the nSubquery amount. |
| 81382 | */ |
| 81383 | static void resolveAlias( |
| @@ -81043,11 +81393,11 @@ | |
| 81393 | sqlite3 *db; /* The database connection */ |
| 81394 | |
| 81395 | assert( iCol>=0 && iCol<pEList->nExpr ); |
| 81396 | pOrig = pEList->a[iCol].pExpr; |
| 81397 | assert( pOrig!=0 ); |
| 81398 | assert( (pOrig->flags & EP_Resolved)!=0 || zType[0]==0 ); |
| 81399 | db = pParse->db; |
| 81400 | pDup = sqlite3ExprDup(db, pOrig, 0); |
| 81401 | if( pDup==0 ) return; |
| 81402 | if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){ |
| 81403 | incrAggFunctionDepth(pDup, nSubquery); |
| @@ -81937,13 +82287,15 @@ | |
| 82287 | pNew->flags |= EP_IntValue; |
| 82288 | pNew->u.iValue = iCol; |
| 82289 | if( pItem->pExpr==pE ){ |
| 82290 | pItem->pExpr = pNew; |
| 82291 | }else{ |
| 82292 | Expr *pParent = pItem->pExpr; |
| 82293 | assert( pParent->op==TK_COLLATE ); |
| 82294 | while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft; |
| 82295 | assert( pParent->pLeft==pE ); |
| 82296 | pParent->pLeft = pNew; |
| 82297 | } |
| 82298 | sqlite3ExprDelete(db, pE); |
| 82299 | pItem->u.x.iOrderByCol = (u16)iCol; |
| 82300 | pItem->done = 1; |
| 82301 | }else{ |
| @@ -82139,11 +82491,11 @@ | |
| 82491 | ** as if it were part of the sub-query, not the parent. This block |
| 82492 | ** moves the pOrderBy down to the sub-query. It will be moved back |
| 82493 | ** after the names have been resolved. */ |
| 82494 | if( p->selFlags & SF_Converted ){ |
| 82495 | Select *pSub = p->pSrc->a[0].pSelect; |
| 82496 | assert( p->pSrc->nSrc==1 && p->pOrderBy ); |
| 82497 | assert( pSub->pPrior && pSub->pOrderBy==0 ); |
| 82498 | pSub->pOrderBy = p->pOrderBy; |
| 82499 | p->pOrderBy = 0; |
| 82500 | } |
| 82501 | |
| @@ -82241,12 +82593,19 @@ | |
| 82593 | |
| 82594 | /* Process the ORDER BY clause for singleton SELECT statements. |
| 82595 | ** The ORDER BY clause for compounds SELECT statements is handled |
| 82596 | ** below, after all of the result-sets for all of the elements of |
| 82597 | ** the compound have been resolved. |
| 82598 | ** |
| 82599 | ** If there is an ORDER BY clause on a term of a compound-select other |
| 82600 | ** than the right-most term, then that is a syntax error. But the error |
| 82601 | ** is not detected until much later, and so we need to go ahead and |
| 82602 | ** resolve those symbols on the incorrect ORDER BY for consistency. |
| 82603 | */ |
| 82604 | if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */ |
| 82605 | && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") |
| 82606 | ){ |
| 82607 | return WRC_Abort; |
| 82608 | } |
| 82609 | if( db->mallocFailed ){ |
| 82610 | return WRC_Abort; |
| 82611 | } |
| @@ -83694,11 +84053,12 @@ | |
| 84053 | SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){ |
| 84054 | int i; |
| 84055 | u32 m = 0; |
| 84056 | if( pList ){ |
| 84057 | for(i=0; i<pList->nExpr; i++){ |
| 84058 | Expr *pExpr = pList->a[i].pExpr; |
| 84059 | if( ALWAYS(pExpr) ) m |= pList->a[i].pExpr->flags; |
| 84060 | } |
| 84061 | } |
| 84062 | return m; |
| 84063 | } |
| 84064 | |
| @@ -84134,11 +84494,11 @@ | |
| 84494 | /* Check to see if an existing table or index can be used to |
| 84495 | ** satisfy the query. This is preferable to generating a new |
| 84496 | ** ephemeral table. |
| 84497 | */ |
| 84498 | p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0); |
| 84499 | if( pParse->nErr==0 && isCandidateForInOpt(p) ){ |
| 84500 | sqlite3 *db = pParse->db; /* Database connection */ |
| 84501 | Table *pTab; /* Table <table>. */ |
| 84502 | Expr *pExpr; /* Expression <column> */ |
| 84503 | i16 iCol; /* Index of column <column> */ |
| 84504 | i16 iDb; /* Database idx for pTab */ |
| @@ -84459,10 +84819,11 @@ | |
| 84819 | } |
| 84820 | sqlite3ExprDelete(pParse->db, pSel->pLimit); |
| 84821 | pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, |
| 84822 | &sqlite3IntTokens[1]); |
| 84823 | pSel->iLimit = 0; |
| 84824 | pSel->selFlags &= ~SF_MultiValue; |
| 84825 | if( sqlite3Select(pParse, pSel, &dest) ){ |
| 84826 | return 0; |
| 84827 | } |
| 84828 | rReg = dest.iSDParm; |
| 84829 | ExprSetVVAProperty(pExpr, EP_NoReduce); |
| @@ -85824,11 +86185,11 @@ | |
| 86185 | sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken); |
| 86186 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 86187 | break; |
| 86188 | } |
| 86189 | case TK_ID: { |
| 86190 | sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken); |
| 86191 | break; |
| 86192 | } |
| 86193 | #ifndef SQLITE_OMIT_CAST |
| 86194 | case TK_CAST: { |
| 86195 | /* Expressions of the form: CAST(pLeft AS token) */ |
| @@ -86459,11 +86820,11 @@ | |
| 86820 | if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){ |
| 86821 | if( combinedFlags & EP_xIsSelect ) return 2; |
| 86822 | if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2; |
| 86823 | if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2; |
| 86824 | if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2; |
| 86825 | if( ALWAYS((combinedFlags & EP_Reduced)==0) && pA->op!=TK_STRING ){ |
| 86826 | if( pA->iColumn!=pB->iColumn ) return 2; |
| 86827 | if( pA->iTable!=pB->iTable |
| 86828 | && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2; |
| 86829 | } |
| 86830 | } |
| @@ -86991,10 +87352,11 @@ | |
| 87352 | do { |
| 87353 | z += n; |
| 87354 | n = sqlite3GetToken(z, &token); |
| 87355 | }while( token==TK_SPACE ); |
| 87356 | |
| 87357 | if( token==TK_ILLEGAL ) break; |
| 87358 | zParent = sqlite3DbStrNDup(db, (const char *)z, n); |
| 87359 | if( zParent==0 ) break; |
| 87360 | sqlite3Dequote(zParent); |
| 87361 | if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){ |
| 87362 | char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"", |
| @@ -89217,18 +89579,21 @@ | |
| 89579 | pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase); |
| 89580 | } |
| 89581 | z = argv[2]; |
| 89582 | |
| 89583 | if( pIndex ){ |
| 89584 | tRowcnt *aiRowEst = 0; |
| 89585 | int nCol = pIndex->nKeyCol+1; |
| 89586 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 89587 | /* Index.aiRowEst may already be set here if there are duplicate |
| 89588 | ** sqlite_stat1 entries for this index. In that case just clobber |
| 89589 | ** the old data with the new instead of allocating a new array. */ |
| 89590 | if( pIndex->aiRowEst==0 ){ |
| 89591 | pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(sizeof(tRowcnt) * nCol); |
| 89592 | if( pIndex->aiRowEst==0 ) pInfo->db->mallocFailed = 1; |
| 89593 | } |
| 89594 | aiRowEst = pIndex->aiRowEst; |
| 89595 | #endif |
| 89596 | pIndex->bUnordered = 0; |
| 89597 | decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex); |
| 89598 | if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0]; |
| 89599 | }else{ |
| @@ -89887,11 +90252,11 @@ | |
| 90252 | } |
| 90253 | |
| 90254 | sqlite3BtreeClose(pDb->pBt); |
| 90255 | pDb->pBt = 0; |
| 90256 | pDb->pSchema = 0; |
| 90257 | sqlite3CollapseDatabaseArray(db); |
| 90258 | return; |
| 90259 | |
| 90260 | detach_error: |
| 90261 | sqlite3_result_error(context, zErr, -1); |
| 90262 | } |
| @@ -89921,11 +90286,10 @@ | |
| 90286 | if( |
| 90287 | SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) || |
| 90288 | SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) || |
| 90289 | SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey)) |
| 90290 | ){ |
| 90291 | goto attach_end; |
| 90292 | } |
| 90293 | |
| 90294 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 90295 | if( pAuthArg ){ |
| @@ -90580,13 +90944,15 @@ | |
| 90944 | sqlite3 *db; |
| 90945 | Vdbe *v; |
| 90946 | |
| 90947 | assert( pParse->pToplevel==0 ); |
| 90948 | db = pParse->db; |
| 90949 | if( pParse->nested ) return; |
| 90950 | if( db->mallocFailed || pParse->nErr ){ |
| 90951 | if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR; |
| 90952 | return; |
| 90953 | } |
| 90954 | |
| 90955 | /* Begin by generating some termination code at the end of the |
| 90956 | ** vdbe program |
| 90957 | */ |
| 90958 | v = sqlite3GetVdbe(pParse); |
| @@ -90664,11 +91030,11 @@ | |
| 91030 | } |
| 91031 | |
| 91032 | |
| 91033 | /* Get the VDBE program ready for execution |
| 91034 | */ |
| 91035 | if( v && pParse->nErr==0 && !db->mallocFailed ){ |
| 91036 | assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */ |
| 91037 | /* A minimum of one cursor is required if autoincrement is used |
| 91038 | * See ticket [a696379c1f08866] */ |
| 91039 | if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1; |
| 91040 | sqlite3VdbeMakeReady(v, pParse); |
| @@ -91199,18 +91565,16 @@ | |
| 91565 | sqlite3 *db = pParse->db; |
| 91566 | |
| 91567 | if( ALWAYS(pName2!=0) && pName2->n>0 ){ |
| 91568 | if( db->init.busy ) { |
| 91569 | sqlite3ErrorMsg(pParse, "corrupt database"); |
| 91570 | return -1; |
| 91571 | } |
| 91572 | *pUnqual = pName2; |
| 91573 | iDb = sqlite3FindDb(db, pName1); |
| 91574 | if( iDb<0 ){ |
| 91575 | sqlite3ErrorMsg(pParse, "unknown database %T", pName1); |
| 91576 | return -1; |
| 91577 | } |
| 91578 | }else{ |
| 91579 | assert( db->init.iDb==0 || db->init.busy ); |
| 91580 | iDb = db->init.iDb; |
| @@ -91365,11 +91729,11 @@ | |
| 91729 | pTable = sqlite3FindTable(db, zName, zDb); |
| 91730 | if( pTable ){ |
| 91731 | if( !noErr ){ |
| 91732 | sqlite3ErrorMsg(pParse, "table %T already exists", pName); |
| 91733 | }else{ |
| 91734 | assert( !db->init.busy || CORRUPT_DB ); |
| 91735 | sqlite3CodeVerifySchema(pParse, iDb); |
| 91736 | } |
| 91737 | goto begin_table_error; |
| 91738 | } |
| 91739 | if( sqlite3FindIndex(db, zName, zDb)!=0 ){ |
| @@ -91654,11 +92018,12 @@ | |
| 92018 | Column *pCol; |
| 92019 | |
| 92020 | p = pParse->pNewTable; |
| 92021 | if( p==0 || NEVER(p->nCol<1) ) return; |
| 92022 | pCol = &p->aCol[p->nCol-1]; |
| 92023 | assert( pCol->zType==0 || CORRUPT_DB ); |
| 92024 | sqlite3DbFree(pParse->db, pCol->zType); |
| 92025 | pCol->zType = sqlite3NameFromToken(pParse->db, pType); |
| 92026 | pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst); |
| 92027 | } |
| 92028 | |
| 92029 | /* |
| @@ -92888,10 +93253,11 @@ | |
| 93253 | if( db->mallocFailed ){ |
| 93254 | goto exit_drop_table; |
| 93255 | } |
| 93256 | assert( pParse->nErr==0 ); |
| 93257 | assert( pName->nSrc==1 ); |
| 93258 | if( sqlite3ReadSchema(pParse) ) goto exit_drop_table; |
| 93259 | if( noErr ) db->suppressErr++; |
| 93260 | pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]); |
| 93261 | if( noErr ) db->suppressErr--; |
| 93262 | |
| 93263 | if( pTab==0 ){ |
| @@ -93201,11 +93567,12 @@ | |
| 93567 | sqlite3UniqueConstraint(pParse, OE_Abort, pIndex); |
| 93568 | }else{ |
| 93569 | addr2 = sqlite3VdbeCurrentAddr(v); |
| 93570 | } |
| 93571 | sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx); |
| 93572 | sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1); |
| 93573 | sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0); |
| 93574 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 93575 | sqlite3ReleaseTempReg(pParse, regRecord); |
| 93576 | sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v); |
| 93577 | sqlite3VdbeJumpHere(v, addr1); |
| 93578 | |
| @@ -93294,12 +93661,11 @@ | |
| 93661 | int nExtra = 0; /* Space allocated for zExtra[] */ |
| 93662 | int nExtraCol; /* Number of extra columns needed */ |
| 93663 | char *zExtra = 0; /* Extra space after the Index object */ |
| 93664 | Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */ |
| 93665 | |
| 93666 | if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){ |
| 93667 | goto exit_create_index; |
| 93668 | } |
| 93669 | if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ |
| 93670 | goto exit_create_index; |
| 93671 | } |
| @@ -94214,11 +94580,10 @@ | |
| 94580 | ** operator with A. This routine shifts that operator over to B. |
| 94581 | */ |
| 94582 | SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){ |
| 94583 | if( p ){ |
| 94584 | int i; |
| 94585 | for(i=p->nSrc-1; i>0; i--){ |
| 94586 | p->a[i].jointype = p->a[i-1].jointype; |
| 94587 | } |
| 94588 | p->a[0].jointype = 0; |
| 94589 | } |
| @@ -94461,12 +94826,11 @@ | |
| 94826 | char *zErr; |
| 94827 | int j; |
| 94828 | StrAccum errMsg; |
| 94829 | Table *pTab = pIdx->pTable; |
| 94830 | |
| 94831 | sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200); |
| 94832 | for(j=0; j<pIdx->nKeyCol; j++){ |
| 94833 | char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName; |
| 94834 | if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2); |
| 94835 | sqlite3StrAccumAppendAll(&errMsg, pTab->zName); |
| 94836 | sqlite3StrAccumAppend(&errMsg, ".", 1); |
| @@ -96291,17 +96655,17 @@ | |
| 96655 | ){ |
| 96656 | PrintfArguments x; |
| 96657 | StrAccum str; |
| 96658 | const char *zFormat; |
| 96659 | int n; |
| 96660 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 96661 | |
| 96662 | if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){ |
| 96663 | x.nArg = argc-1; |
| 96664 | x.nUsed = 0; |
| 96665 | x.apArg = argv+1; |
| 96666 | sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 96667 | sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x); |
| 96668 | n = str.nChar; |
| 96669 | sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, |
| 96670 | SQLITE_DYNAMIC); |
| 96671 | } |
| @@ -96447,11 +96811,11 @@ | |
| 96811 | sqlite3_result_double(context, r); |
| 96812 | } |
| 96813 | #endif |
| 96814 | |
| 96815 | /* |
| 96816 | ** Allocate nByte bytes of space using sqlite3Malloc(). If the |
| 96817 | ** allocation fails, call sqlite3_result_error_nomem() to notify |
| 96818 | ** the database handle that malloc() has failed and return NULL. |
| 96819 | ** If nByte is larger than the maximum string or blob length, then |
| 96820 | ** raise an SQLITE_TOOBIG exception and return NULL. |
| 96821 | */ |
| @@ -97116,11 +97480,11 @@ | |
| 97480 | int argc, |
| 97481 | sqlite3_value **argv |
| 97482 | ){ |
| 97483 | unsigned char *z, *zOut; |
| 97484 | int i; |
| 97485 | zOut = z = sqlite3_malloc64( argc*4+1 ); |
| 97486 | if( z==0 ){ |
| 97487 | sqlite3_result_error_nomem(context); |
| 97488 | return; |
| 97489 | } |
| 97490 | for(i=0; i<argc; i++){ |
| @@ -97264,11 +97628,11 @@ | |
| 97628 | sqlite3_result_error_toobig(context); |
| 97629 | sqlite3_free(zOut); |
| 97630 | return; |
| 97631 | } |
| 97632 | zOld = zOut; |
| 97633 | zOut = sqlite3_realloc64(zOut, (int)nOut); |
| 97634 | if( zOut==0 ){ |
| 97635 | sqlite3_result_error_nomem(context); |
| 97636 | sqlite3_free(zOld); |
| 97637 | return; |
| 97638 | } |
| @@ -97626,12 +97990,11 @@ | |
| 97990 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 97991 | pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum)); |
| 97992 | |
| 97993 | if( pAccum ){ |
| 97994 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 97995 | int firstTerm = pAccum->mxAlloc==0; |
| 97996 | pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH]; |
| 97997 | if( !firstTerm ){ |
| 97998 | if( argc==2 ){ |
| 97999 | zSep = (char*)sqlite3_value_text(argv[1]); |
| 98000 | nSep = sqlite3_value_bytes(argv[1]); |
| @@ -99047,11 +99410,12 @@ | |
| 99410 | int iFromCol; /* Idx of column in child table */ |
| 99411 | Expr *pEq; /* tFromCol = OLD.tToCol */ |
| 99412 | |
| 99413 | iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; |
| 99414 | assert( iFromCol>=0 ); |
| 99415 | assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) ); |
| 99416 | tToCol.z = pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName; |
| 99417 | tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName; |
| 99418 | |
| 99419 | tToCol.n = sqlite3Strlen30(tToCol.z); |
| 99420 | tFromCol.n = sqlite3Strlen30(tFromCol.z); |
| 99421 | |
| @@ -99059,14 +99423,14 @@ | |
| 99423 | ** that the "OLD.zToCol" term is on the LHS of the = operator, so |
| 99424 | ** that the affinity and collation sequence associated with the |
| 99425 | ** parent table are used for the comparison. */ |
| 99426 | pEq = sqlite3PExpr(pParse, TK_EQ, |
| 99427 | sqlite3PExpr(pParse, TK_DOT, |
| 99428 | sqlite3ExprAlloc(db, TK_ID, &tOld, 0), |
| 99429 | sqlite3ExprAlloc(db, TK_ID, &tToCol, 0) |
| 99430 | , 0), |
| 99431 | sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0) |
| 99432 | , 0); |
| 99433 | pWhere = sqlite3ExprAnd(db, pWhere, pEq); |
| 99434 | |
| 99435 | /* For ON UPDATE, construct the next term of the WHEN clause. |
| 99436 | ** The final WHEN clause will be like this: |
| @@ -99074,27 +99438,27 @@ | |
| 99438 | ** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN) |
| 99439 | */ |
| 99440 | if( pChanges ){ |
| 99441 | pEq = sqlite3PExpr(pParse, TK_IS, |
| 99442 | sqlite3PExpr(pParse, TK_DOT, |
| 99443 | sqlite3ExprAlloc(db, TK_ID, &tOld, 0), |
| 99444 | sqlite3ExprAlloc(db, TK_ID, &tToCol, 0), |
| 99445 | 0), |
| 99446 | sqlite3PExpr(pParse, TK_DOT, |
| 99447 | sqlite3ExprAlloc(db, TK_ID, &tNew, 0), |
| 99448 | sqlite3ExprAlloc(db, TK_ID, &tToCol, 0), |
| 99449 | 0), |
| 99450 | 0); |
| 99451 | pWhen = sqlite3ExprAnd(db, pWhen, pEq); |
| 99452 | } |
| 99453 | |
| 99454 | if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){ |
| 99455 | Expr *pNew; |
| 99456 | if( action==OE_Cascade ){ |
| 99457 | pNew = sqlite3PExpr(pParse, TK_DOT, |
| 99458 | sqlite3ExprAlloc(db, TK_ID, &tNew, 0), |
| 99459 | sqlite3ExprAlloc(db, TK_ID, &tToCol, 0) |
| 99460 | , 0); |
| 99461 | }else if( action==OE_SetDflt ){ |
| 99462 | Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt; |
| 99463 | if( pDflt ){ |
| 99464 | pNew = sqlite3ExprDup(db, pDflt, 0); |
| @@ -99137,17 +99501,16 @@ | |
| 99501 | db->lookaside.bEnabled = 0; |
| 99502 | |
| 99503 | pTrigger = (Trigger *)sqlite3DbMallocZero(db, |
| 99504 | sizeof(Trigger) + /* struct Trigger */ |
| 99505 | sizeof(TriggerStep) + /* Single step in trigger program */ |
| 99506 | nFrom + 1 /* Space for pStep->zTarget */ |
| 99507 | ); |
| 99508 | if( pTrigger ){ |
| 99509 | pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1]; |
| 99510 | pStep->zTarget = (char *)&pStep[1]; |
| 99511 | memcpy((char *)pStep->zTarget, zFrom, nFrom); |
| 99512 | |
| 99513 | pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE); |
| 99514 | pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE); |
| 99515 | pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE); |
| 99516 | if( pWhen ){ |
| @@ -99608,24 +99971,27 @@ | |
| 99971 | ); |
| 99972 | |
| 99973 | /* |
| 99974 | ** This routine is called to handle SQL of the following forms: |
| 99975 | ** |
| 99976 | ** insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),... |
| 99977 | ** insert into TABLE (IDLIST) select |
| 99978 | ** insert into TABLE (IDLIST) default values |
| 99979 | ** |
| 99980 | ** The IDLIST following the table name is always optional. If omitted, |
| 99981 | ** then a list of all (non-hidden) columns for the table is substituted. |
| 99982 | ** The IDLIST appears in the pColumn parameter. pColumn is NULL if IDLIST |
| 99983 | ** is omitted. |
| 99984 | ** |
| 99985 | ** For the pSelect parameter holds the values to be inserted for the |
| 99986 | ** first two forms shown above. A VALUES clause is really just short-hand |
| 99987 | ** for a SELECT statement that omits the FROM clause and everything else |
| 99988 | ** that follows. If the pSelect parameter is NULL, that means that the |
| 99989 | ** DEFAULT VALUES form of the INSERT statement is intended. |
| 99990 | ** |
| 99991 | ** The code generated follows one of four templates. For a simple |
| 99992 | ** insert with data coming from a single-row VALUES clause, the code executes |
| 99993 | ** once straight down through. Pseudo-code follows (we call this |
| 99994 | ** the "1st template"): |
| 99995 | ** |
| 99996 | ** open write cursor to <table> and its indices |
| 99997 | ** put VALUES clause expressions into registers |
| @@ -99728,11 +100094,11 @@ | |
| 100094 | int iDb; /* Index of database holding TABLE */ |
| 100095 | Db *pDb; /* The database containing table being inserted into */ |
| 100096 | u8 useTempTable = 0; /* Store SELECT results in intermediate table */ |
| 100097 | u8 appendFlag = 0; /* True if the insert is likely to be an append */ |
| 100098 | u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */ |
| 100099 | u8 bIdListInOrder; /* True if IDLIST is in table order */ |
| 100100 | ExprList *pList = 0; /* List of VALUES() to be inserted */ |
| 100101 | |
| 100102 | /* Register allocations */ |
| 100103 | int regFromSelect = 0;/* Base register for data coming from SELECT */ |
| 100104 | int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */ |
| @@ -99753,12 +100119,12 @@ | |
| 100119 | if( pParse->nErr || db->mallocFailed ){ |
| 100120 | goto insert_cleanup; |
| 100121 | } |
| 100122 | |
| 100123 | /* If the Select object is really just a simple VALUES() list with a |
| 100124 | ** single row (the common case) then keep that one row of values |
| 100125 | ** and discard the other (unused) parts of the pSelect object |
| 100126 | */ |
| 100127 | if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){ |
| 100128 | pList = pSelect->pEList; |
| 100129 | pSelect->pEList = 0; |
| 100130 | sqlite3SelectDelete(db, pSelect); |
| @@ -99862,10 +100228,11 @@ | |
| 100228 | ** the index into IDLIST of the primary key column. ipkColumn is |
| 100229 | ** the index of the primary key as it appears in IDLIST, not as |
| 100230 | ** is appears in the original table. (The index of the INTEGER |
| 100231 | ** PRIMARY KEY in the original table is pTab->iPKey.) |
| 100232 | */ |
| 100233 | bIdListInOrder = (pTab->tabFlags & TF_OOOHidden)==0; |
| 100234 | if( pColumn ){ |
| 100235 | for(i=0; i<pColumn->nId; i++){ |
| 100236 | pColumn->a[i].idx = -1; |
| 100237 | } |
| 100238 | for(i=0; i<pColumn->nId; i++){ |
| @@ -99897,11 +100264,12 @@ | |
| 100264 | ** is coming from a SELECT statement, then generate a co-routine that |
| 100265 | ** produces a single row of the SELECT on each invocation. The |
| 100266 | ** co-routine is the common header to the 3rd and 4th templates. |
| 100267 | */ |
| 100268 | if( pSelect ){ |
| 100269 | /* Data is coming from a SELECT or from a multi-row VALUES clause. |
| 100270 | ** Generate a co-routine to run the SELECT. */ |
| 100271 | int regYield; /* Register holding co-routine entry-point */ |
| 100272 | int addrTop; /* Top of the co-routine */ |
| 100273 | int rc; /* Result code */ |
| 100274 | |
| 100275 | regYield = ++pParse->nMem; |
| @@ -99910,12 +100278,11 @@ | |
| 100278 | sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); |
| 100279 | dest.iSdst = bIdListInOrder ? regData : 0; |
| 100280 | dest.nSdst = pTab->nCol; |
| 100281 | rc = sqlite3Select(pParse, pSelect, &dest); |
| 100282 | regFromSelect = dest.iSdst; |
| 100283 | if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup; |
| 100284 | sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield); |
| 100285 | sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */ |
| 100286 | assert( pSelect->pEList ); |
| 100287 | nColumn = pSelect->pEList->nExpr; |
| 100288 | |
| @@ -99959,12 +100326,12 @@ | |
| 100326 | sqlite3VdbeJumpHere(v, addrL); |
| 100327 | sqlite3ReleaseTempReg(pParse, regRec); |
| 100328 | sqlite3ReleaseTempReg(pParse, regTempRowid); |
| 100329 | } |
| 100330 | }else{ |
| 100331 | /* This is the case if the data for the INSERT is coming from a |
| 100332 | ** single-row VALUES clause |
| 100333 | */ |
| 100334 | NameContext sNC; |
| 100335 | memset(&sNC, 0, sizeof(sNC)); |
| 100336 | sNC.pParse = pParse; |
| 100337 | srcTab = -1; |
| @@ -101031,10 +101398,11 @@ | |
| 101398 | Table *pDest, /* The table we are inserting into */ |
| 101399 | Select *pSelect, /* A SELECT statement to use as the data source */ |
| 101400 | int onError, /* How to handle constraint errors */ |
| 101401 | int iDbDest /* The database of pDest */ |
| 101402 | ){ |
| 101403 | sqlite3 *db = pParse->db; |
| 101404 | ExprList *pEList; /* The result set of the SELECT */ |
| 101405 | Table *pSrc; /* The table in the FROM clause of SELECT */ |
| 101406 | Index *pSrcIdx, *pDestIdx; /* Source and destination indices */ |
| 101407 | struct SrcList_item *pItem; /* An element of pSelect->pSrc */ |
| 101408 | int i; /* Loop counter */ |
| @@ -101178,15 +101546,15 @@ | |
| 101546 | ** But the main beneficiary of the transfer optimization is the VACUUM |
| 101547 | ** command, and the VACUUM command disables foreign key constraints. So |
| 101548 | ** the extra complication to make this rule less restrictive is probably |
| 101549 | ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] |
| 101550 | */ |
| 101551 | if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ |
| 101552 | return 0; |
| 101553 | } |
| 101554 | #endif |
| 101555 | if( (db->flags & SQLITE_CountRows)!=0 ){ |
| 101556 | return 0; /* xfer opt does not play well with PRAGMA count_changes */ |
| 101557 | } |
| 101558 | |
| 101559 | /* If we get this far, it means that the xfer optimization is at |
| 101560 | ** least a possibility, though it might only work if the destination |
| @@ -101193,28 +101561,32 @@ | |
| 101561 | ** table (tab1) is initially empty. |
| 101562 | */ |
| 101563 | #ifdef SQLITE_TEST |
| 101564 | sqlite3_xferopt_count++; |
| 101565 | #endif |
| 101566 | iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema); |
| 101567 | v = sqlite3GetVdbe(pParse); |
| 101568 | sqlite3CodeVerifySchema(pParse, iDbSrc); |
| 101569 | iSrc = pParse->nTab++; |
| 101570 | iDest = pParse->nTab++; |
| 101571 | regAutoinc = autoIncBegin(pParse, iDbDest, pDest); |
| 101572 | regData = sqlite3GetTempReg(pParse); |
| 101573 | regRowid = sqlite3GetTempReg(pParse); |
| 101574 | sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite); |
| 101575 | assert( HasRowid(pDest) || destHasUniqueIdx ); |
| 101576 | if( (db->flags & SQLITE_Vacuum)==0 && ( |
| 101577 | (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */ |
| 101578 | || destHasUniqueIdx /* (2) */ |
| 101579 | || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */ |
| 101580 | )){ |
| 101581 | /* In some circumstances, we are able to run the xfer optimization |
| 101582 | ** only if the destination table is initially empty. Unless the |
| 101583 | ** SQLITE_Vacuum flag is set, this block generates code to make |
| 101584 | ** that determination. If SQLITE_Vacuum is set, then the destination |
| 101585 | ** table is always empty. |
| 101586 | ** |
| 101587 | ** Conditions under which the destination must be empty: |
| 101588 | ** |
| 101589 | ** (1) There is no INTEGER PRIMARY KEY but there are indices. |
| 101590 | ** (If the destination is not initially empty, the rowid fields |
| 101591 | ** of index entries might need to change.) |
| 101592 | ** |
| @@ -101253,10 +101625,11 @@ | |
| 101625 | }else{ |
| 101626 | sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName); |
| 101627 | sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName); |
| 101628 | } |
| 101629 | for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){ |
| 101630 | u8 useSeekResult = 0; |
| 101631 | for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){ |
| 101632 | if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break; |
| 101633 | } |
| 101634 | assert( pSrcIdx ); |
| 101635 | sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc); |
| @@ -101266,11 +101639,37 @@ | |
| 101639 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 101640 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 101641 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 101642 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 101643 | sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData); |
| 101644 | if( db->flags & SQLITE_Vacuum ){ |
| 101645 | /* This INSERT command is part of a VACUUM operation, which guarantees |
| 101646 | ** that the destination table is empty. If all indexed columns use |
| 101647 | ** collation sequence BINARY, then it can also be assumed that the |
| 101648 | ** index will be populated by inserting keys in strictly sorted |
| 101649 | ** order. In this case, instead of seeking within the b-tree as part |
| 101650 | ** of every OP_IdxInsert opcode, an OP_Last is added before the |
| 101651 | ** OP_IdxInsert to seek to the point within the b-tree where each key |
| 101652 | ** should be inserted. This is faster. |
| 101653 | ** |
| 101654 | ** If any of the indexed columns use a collation sequence other than |
| 101655 | ** BINARY, this optimization is disabled. This is because the user |
| 101656 | ** might change the definition of a collation sequence and then run |
| 101657 | ** a VACUUM command. In that case keys may not be written in strictly |
| 101658 | ** sorted order. */ |
| 101659 | for(i=0; i<pSrcIdx->nColumn; i++){ |
| 101660 | char *zColl = pSrcIdx->azColl[i]; |
| 101661 | assert( zColl!=0 ); |
| 101662 | if( sqlite3_stricmp("BINARY", zColl) ) break; |
| 101663 | } |
| 101664 | if( i==pSrcIdx->nColumn ){ |
| 101665 | useSeekResult = OPFLAG_USESEEKRESULT; |
| 101666 | sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1); |
| 101667 | } |
| 101668 | } |
| 101669 | sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1); |
| 101670 | sqlite3VdbeChangeP5(v, useSeekResult); |
| 101671 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v); |
| 101672 | sqlite3VdbeJumpHere(v, addr1); |
| 101673 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| 101674 | sqlite3VdbeAddOp2(v, OP_Close, iDest, 0); |
| 101675 | } |
| @@ -102385,11 +102784,11 @@ | |
| 102784 | int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); |
| 102785 | char *zErrmsg = 0; |
| 102786 | const char *zEntry; |
| 102787 | char *zAltEntry = 0; |
| 102788 | void **aHandle; |
| 102789 | u64 nMsg = 300 + sqlite3Strlen30(zFile); |
| 102790 | int ii; |
| 102791 | |
| 102792 | /* Shared library endings to try if zFile cannot be loaded as written */ |
| 102793 | static const char *azEndings[] = { |
| 102794 | #if SQLITE_OS_WIN |
| @@ -102428,11 +102827,11 @@ | |
| 102827 | sqlite3_free(zAltFile); |
| 102828 | } |
| 102829 | #endif |
| 102830 | if( handle==0 ){ |
| 102831 | if( pzErrMsg ){ |
| 102832 | *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg); |
| 102833 | if( zErrmsg ){ |
| 102834 | sqlite3_snprintf(nMsg, zErrmsg, |
| 102835 | "unable to open shared library [%s]", zFile); |
| 102836 | sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); |
| 102837 | } |
| @@ -102454,11 +102853,11 @@ | |
| 102853 | ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init |
| 102854 | */ |
| 102855 | if( xInit==0 && zProc==0 ){ |
| 102856 | int iFile, iEntry, c; |
| 102857 | int ncFile = sqlite3Strlen30(zFile); |
| 102858 | zAltEntry = sqlite3_malloc64(ncFile+30); |
| 102859 | if( zAltEntry==0 ){ |
| 102860 | sqlite3OsDlClose(pVfs, handle); |
| 102861 | return SQLITE_NOMEM; |
| 102862 | } |
| 102863 | memcpy(zAltEntry, "sqlite3_", 8); |
| @@ -102476,11 +102875,11 @@ | |
| 102875 | sqlite3OsDlSym(pVfs, handle, zEntry); |
| 102876 | } |
| 102877 | if( xInit==0 ){ |
| 102878 | if( pzErrMsg ){ |
| 102879 | nMsg += sqlite3Strlen30(zEntry); |
| 102880 | *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg); |
| 102881 | if( zErrmsg ){ |
| 102882 | sqlite3_snprintf(nMsg, zErrmsg, |
| 102883 | "no entry point [%s] in shared library [%s]", zEntry, zFile); |
| 102884 | sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); |
| 102885 | } |
| @@ -102575,11 +102974,11 @@ | |
| 102974 | ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER |
| 102975 | ** mutex must be held while accessing this list. |
| 102976 | */ |
| 102977 | typedef struct sqlite3AutoExtList sqlite3AutoExtList; |
| 102978 | static SQLITE_WSD struct sqlite3AutoExtList { |
| 102979 | u32 nExt; /* Number of entries in aExt[] */ |
| 102980 | void (**aExt)(void); /* Pointers to the extension init functions */ |
| 102981 | } sqlite3Autoext = { 0, 0 }; |
| 102982 | |
| 102983 | /* The "wsdAutoext" macro will resolve to the autoextension |
| 102984 | ** state vector. If writable static data is unsupported on the target, |
| @@ -102608,23 +103007,23 @@ | |
| 103007 | if( rc ){ |
| 103008 | return rc; |
| 103009 | }else |
| 103010 | #endif |
| 103011 | { |
| 103012 | u32 i; |
| 103013 | #if SQLITE_THREADSAFE |
| 103014 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 103015 | #endif |
| 103016 | wsdAutoextInit; |
| 103017 | sqlite3_mutex_enter(mutex); |
| 103018 | for(i=0; i<wsdAutoext.nExt; i++){ |
| 103019 | if( wsdAutoext.aExt[i]==xInit ) break; |
| 103020 | } |
| 103021 | if( i==wsdAutoext.nExt ){ |
| 103022 | u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]); |
| 103023 | void (**aNew)(void); |
| 103024 | aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte); |
| 103025 | if( aNew==0 ){ |
| 103026 | rc = SQLITE_NOMEM; |
| 103027 | }else{ |
| 103028 | wsdAutoext.aExt = aNew; |
| 103029 | wsdAutoext.aExt[wsdAutoext.nExt] = xInit; |
| @@ -102652,11 +103051,11 @@ | |
| 103051 | #endif |
| 103052 | int i; |
| 103053 | int n = 0; |
| 103054 | wsdAutoextInit; |
| 103055 | sqlite3_mutex_enter(mutex); |
| 103056 | for(i=(int)wsdAutoext.nExt-1; i>=0; i--){ |
| 103057 | if( wsdAutoext.aExt[i]==xInit ){ |
| 103058 | wsdAutoext.nExt--; |
| 103059 | wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt]; |
| 103060 | n++; |
| 103061 | break; |
| @@ -102690,11 +103089,11 @@ | |
| 103089 | ** Load all automatic extensions. |
| 103090 | ** |
| 103091 | ** If anything goes wrong, set an error in the database connection. |
| 103092 | */ |
| 103093 | SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){ |
| 103094 | u32 i; |
| 103095 | int go = 1; |
| 103096 | int rc; |
| 103097 | int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); |
| 103098 | |
| 103099 | wsdAutoextInit; |
| @@ -103354,19 +103753,19 @@ | |
| 103753 | /* |
| 103754 | ** Generate code to return a single integer value. |
| 103755 | */ |
| 103756 | static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){ |
| 103757 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 103758 | int nMem = ++pParse->nMem; |
| 103759 | i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value)); |
| 103760 | if( pI64 ){ |
| 103761 | memcpy(pI64, &value, sizeof(value)); |
| 103762 | } |
| 103763 | sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64); |
| 103764 | sqlite3VdbeSetNumCols(v, 1); |
| 103765 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC); |
| 103766 | sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1); |
| 103767 | } |
| 103768 | |
| 103769 | |
| 103770 | /* |
| 103771 | ** Set the safety_level and pager flags for pager iDb. Or if iDb<0 |
| @@ -103527,15 +103926,15 @@ | |
| 103926 | aFcntl[3] = 0; |
| 103927 | db->busyHandler.nBusy = 0; |
| 103928 | rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl); |
| 103929 | if( rc==SQLITE_OK ){ |
| 103930 | if( aFcntl[0] ){ |
| 103931 | int nMem = ++pParse->nMem; |
| 103932 | sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0); |
| 103933 | sqlite3VdbeSetNumCols(v, 1); |
| 103934 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC); |
| 103935 | sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1); |
| 103936 | sqlite3_free(aFcntl[0]); |
| 103937 | } |
| 103938 | goto pragma_out; |
| 103939 | } |
| 103940 | if( rc!=SQLITE_NOTFOUND ){ |
| @@ -104136,11 +104535,13 @@ | |
| 104535 | }else{ |
| 104536 | if( !db->autoCommit ){ |
| 104537 | sqlite3ErrorMsg(pParse, |
| 104538 | "Safety level may not be changed inside a transaction"); |
| 104539 | }else{ |
| 104540 | int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK; |
| 104541 | if( iLevel==0 ) iLevel = 1; |
| 104542 | pDb->safety_level = iLevel; |
| 104543 | setAllPagerFlags(db); |
| 104544 | } |
| 104545 | } |
| 104546 | break; |
| 104547 | } |
| @@ -104231,11 +104632,11 @@ | |
| 104632 | if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){ |
| 104633 | k = 0; |
| 104634 | }else if( pPk==0 ){ |
| 104635 | k = 1; |
| 104636 | }else{ |
| 104637 | for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} |
| 104638 | } |
| 104639 | sqlite3VdbeAddOp2(v, OP_Integer, k, 6); |
| 104640 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); |
| 104641 | } |
| 104642 | } |
| @@ -105237,11 +105638,11 @@ | |
| 105638 | |
| 105639 | assert( iDb>=0 && iDb<db->nDb ); |
| 105640 | if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */ |
| 105641 | if( argv[1]==0 ){ |
| 105642 | corruptSchema(pData, argv[0], 0); |
| 105643 | }else if( sqlite3_strnicmp(argv[2],"create ",7)==0 ){ |
| 105644 | /* Call the parser to process a CREATE TABLE, INDEX or VIEW. |
| 105645 | ** But because db->init.busy is set to 1, no VDBE code is generated |
| 105646 | ** or executed. All the parser does is build the internal data |
| 105647 | ** structures that describe the table, index, or view. |
| 105648 | */ |
| @@ -105268,12 +105669,12 @@ | |
| 105669 | corruptSchema(pData, argv[0], sqlite3_errmsg(db)); |
| 105670 | } |
| 105671 | } |
| 105672 | } |
| 105673 | sqlite3_finalize(pStmt); |
| 105674 | }else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){ |
| 105675 | corruptSchema(pData, argv[0], 0); |
| 105676 | }else{ |
| 105677 | /* If the SQL column is blank it means this is an index that |
| 105678 | ** was created to be the PRIMARY KEY or to fulfill a UNIQUE |
| 105679 | ** constraint for a CREATE TABLE. The index should have already |
| 105680 | ** been created when we processed the CREATE TABLE. All we have |
| @@ -106176,11 +106577,10 @@ | |
| 106577 | ){ |
| 106578 | Select *pNew; |
| 106579 | Select standin; |
| 106580 | sqlite3 *db = pParse->db; |
| 106581 | pNew = sqlite3DbMallocZero(db, sizeof(*pNew) ); |
| 106582 | if( pNew==0 ){ |
| 106583 | assert( db->mallocFailed ); |
| 106584 | pNew = &standin; |
| 106585 | memset(pNew, 0, sizeof(*pNew)); |
| 106586 | } |
| @@ -106196,11 +106596,11 @@ | |
| 106596 | pNew->pOrderBy = pOrderBy; |
| 106597 | pNew->selFlags = selFlags; |
| 106598 | pNew->op = TK_SELECT; |
| 106599 | pNew->pLimit = pLimit; |
| 106600 | pNew->pOffset = pOffset; |
| 106601 | assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 ); |
| 106602 | pNew->addrOpenEphm[0] = -1; |
| 106603 | pNew->addrOpenEphm[1] = -1; |
| 106604 | if( db->mallocFailed ) { |
| 106605 | clearSelect(db, pNew, pNew!=&standin); |
| 106606 | pNew = 0; |
| @@ -107446,11 +107846,11 @@ | |
| 107846 | if( pS ){ |
| 107847 | /* The "table" is actually a sub-select or a view in the FROM clause |
| 107848 | ** of the SELECT statement. Return the declaration type and origin |
| 107849 | ** data for the result-set column of the sub-select. |
| 107850 | */ |
| 107851 | if( iCol>=0 && iCol<pS->pEList->nExpr ){ |
| 107852 | /* If iCol is less than zero, then the expression requests the |
| 107853 | ** rowid of the sub-select or view. This expression is legal (see |
| 107854 | ** test case misc2.2.2) - it always evaluates to NULL. |
| 107855 | */ |
| 107856 | NameContext sNC; |
| @@ -107766,16 +108166,18 @@ | |
| 108166 | memset(&sNC, 0, sizeof(sNC)); |
| 108167 | sNC.pSrcList = pSelect->pSrc; |
| 108168 | a = pSelect->pEList->a; |
| 108169 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
| 108170 | p = a[i].pExpr; |
| 108171 | if( pCol->zType==0 ){ |
| 108172 | pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst)); |
| 108173 | } |
| 108174 | szAll += pCol->szEst; |
| 108175 | pCol->affinity = sqlite3ExprAffinity(p); |
| 108176 | if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE; |
| 108177 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 108178 | if( pColl && pCol->zColl==0 ){ |
| 108179 | pCol->zColl = sqlite3DbStrDup(db, pColl->zName); |
| 108180 | } |
| 108181 | } |
| 108182 | pTab->szTabRow = sqlite3LogEst(szAll*4); |
| 108183 | } |
| @@ -108173,12 +108575,11 @@ | |
| 108575 | ){ |
| 108576 | Select *pPrior; |
| 108577 | int nExpr = p->pEList->nExpr; |
| 108578 | int nRow = 1; |
| 108579 | int rc = 0; |
| 108580 | assert( p->selFlags & SF_MultiValue ); |
| 108581 | do{ |
| 108582 | assert( p->selFlags & SF_Values ); |
| 108583 | assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) ); |
| 108584 | assert( p->pLimit==0 ); |
| 108585 | assert( p->pOffset==0 ); |
| @@ -108283,11 +108684,11 @@ | |
| 108684 | dest.eDest = SRT_Table; |
| 108685 | } |
| 108686 | |
| 108687 | /* Special handling for a compound-select that originates as a VALUES clause. |
| 108688 | */ |
| 108689 | if( p->selFlags & SF_MultiValue ){ |
| 108690 | rc = multiSelectValues(pParse, p, &dest); |
| 108691 | goto multi_select_end; |
| 108692 | } |
| 108693 | |
| 108694 | /* Make sure all SELECTs in the statement have the same number of elements |
| @@ -108668,11 +109069,11 @@ | |
| 109069 | ** then there should be a single item on the stack. Write this |
| 109070 | ** item into the set table with bogus data. |
| 109071 | */ |
| 109072 | case SRT_Set: { |
| 109073 | int r1; |
| 109074 | assert( pIn->nSdst==1 || pParse->nErr>0 ); |
| 109075 | pDest->affSdst = |
| 109076 | sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst); |
| 109077 | r1 = sqlite3GetTempReg(pParse); |
| 109078 | sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1); |
| 109079 | sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1); |
| @@ -108694,11 +109095,11 @@ | |
| 109095 | /* If this is a scalar select that is part of an expression, then |
| 109096 | ** store the results in the appropriate memory cell and break out |
| 109097 | ** of the scan loop. |
| 109098 | */ |
| 109099 | case SRT_Mem: { |
| 109100 | assert( pIn->nSdst==1 || pParse->nErr>0 ); testcase( pIn->nSdst!=1 ); |
| 109101 | sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1); |
| 109102 | /* The LIMIT clause will jump out of the loop for us */ |
| 109103 | break; |
| 109104 | } |
| 109105 | #endif /* #ifndef SQLITE_OMIT_SUBQUERY */ |
| @@ -108709,11 +109110,11 @@ | |
| 109110 | case SRT_Coroutine: { |
| 109111 | if( pDest->iSdst==0 ){ |
| 109112 | pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst); |
| 109113 | pDest->nSdst = pIn->nSdst; |
| 109114 | } |
| 109115 | sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst); |
| 109116 | sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm); |
| 109117 | break; |
| 109118 | } |
| 109119 | |
| 109120 | /* If none of the above, then the result destination must be |
| @@ -108925,12 +109326,14 @@ | |
| 109326 | */ |
| 109327 | aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy); |
| 109328 | if( aPermute ){ |
| 109329 | struct ExprList_item *pItem; |
| 109330 | for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){ |
| 109331 | assert( pItem->u.x.iOrderByCol>0 ); |
| 109332 | /* assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ) is also true |
| 109333 | ** but only for well-formed SELECT statements. */ |
| 109334 | testcase( pItem->u.x.iOrderByCol > p->pEList->nExpr ); |
| 109335 | aPermute[i] = pItem->u.x.iOrderByCol - 1; |
| 109336 | } |
| 109337 | pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1); |
| 109338 | }else{ |
| 109339 | pKeyMerge = 0; |
| @@ -109136,11 +109539,11 @@ | |
| 109539 | pPrior->pNext = p; |
| 109540 | |
| 109541 | /*** TBD: Insert subroutine calls to close cursors on incomplete |
| 109542 | **** subqueries ****/ |
| 109543 | explainComposite(pParse, p->op, iSub1, iSub2, 0); |
| 109544 | return pParse->nErr!=0; |
| 109545 | } |
| 109546 | #endif |
| 109547 | |
| 109548 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 109549 | /* Forward Declarations */ |
| @@ -109948,10 +110351,11 @@ | |
| 110351 | pNew->pGroupBy = 0; |
| 110352 | pNew->pHaving = 0; |
| 110353 | pNew->pOrderBy = 0; |
| 110354 | p->pPrior = 0; |
| 110355 | p->pNext = 0; |
| 110356 | p->pWith = 0; |
| 110357 | p->selFlags &= ~SF_Compound; |
| 110358 | assert( (p->selFlags & SF_Converted)==0 ); |
| 110359 | p->selFlags |= SF_Converted; |
| 110360 | assert( pNew->pPrior!=0 ); |
| 110361 | pNew->pPrior->pNext = pNew; |
| @@ -110486,11 +110890,11 @@ | |
| 110890 | if( pParse->hasCompound ){ |
| 110891 | w.xSelectCallback = convertCompoundSelectToSubquery; |
| 110892 | sqlite3WalkSelect(&w, pSelect); |
| 110893 | } |
| 110894 | w.xSelectCallback = selectExpander; |
| 110895 | if( (pSelect->selFlags & SF_MultiValue)==0 ){ |
| 110896 | w.xSelectCallback2 = selectPopWith; |
| 110897 | } |
| 110898 | sqlite3WalkSelect(&w, pSelect); |
| 110899 | } |
| 110900 | |
| @@ -110672,11 +111076,12 @@ | |
| 111076 | nArg = 0; |
| 111077 | regAgg = 0; |
| 111078 | } |
| 111079 | if( pF->iDistinct>=0 ){ |
| 111080 | addrNext = sqlite3VdbeMakeLabel(v); |
| 111081 | testcase( nArg==0 ); /* Error condition */ |
| 111082 | testcase( nArg>1 ); /* Also an error */ |
| 111083 | codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg); |
| 111084 | } |
| 111085 | if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 111086 | CollSeq *pColl = 0; |
| 111087 | struct ExprList_item *pItem; |
| @@ -111547,14 +111952,13 @@ | |
| 111952 | |
| 111953 | /* Jump here to skip this query |
| 111954 | */ |
| 111955 | sqlite3VdbeResolveLabel(v, iEnd); |
| 111956 | |
| 111957 | /* The SELECT has been coded. If there is an error in the Parse structure, |
| 111958 | ** set the return code to 1. Otherwise 0. */ |
| 111959 | rc = (pParse->nErr>0); |
| 111960 | |
| 111961 | /* Control jumps to here if an error is encountered above, or upon |
| 111962 | ** successful coding of the SELECT. |
| 111963 | */ |
| 111964 | select_end: |
| @@ -111601,11 +112005,11 @@ | |
| 112005 | sqlite3TreeViewLine(pView, "FROM"); |
| 112006 | for(i=0; i<p->pSrc->nSrc; i++){ |
| 112007 | struct SrcList_item *pItem = &p->pSrc->a[i]; |
| 112008 | StrAccum x; |
| 112009 | char zLine[100]; |
| 112010 | sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); |
| 112011 | sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor); |
| 112012 | if( pItem->zDatabase ){ |
| 112013 | sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName); |
| 112014 | }else if( pItem->zName ){ |
| 112015 | sqlite3XPrintf(&x, 0, " %s", pItem->zName); |
| @@ -111760,11 +112164,11 @@ | |
| 112164 | for(i=0; i<nCol; i++){ |
| 112165 | if( argv[i]==0 ){ |
| 112166 | z = 0; |
| 112167 | }else{ |
| 112168 | int n = sqlite3Strlen30(argv[i])+1; |
| 112169 | z = sqlite3_malloc64( n ); |
| 112170 | if( z==0 ) goto malloc_failed; |
| 112171 | memcpy(z, argv[i], n); |
| 112172 | } |
| 112173 | p->azResult[p->nData++] = z; |
| 112174 | } |
| @@ -111809,11 +112213,11 @@ | |
| 112213 | res.nRow = 0; |
| 112214 | res.nColumn = 0; |
| 112215 | res.nData = 1; |
| 112216 | res.nAlloc = 20; |
| 112217 | res.rc = SQLITE_OK; |
| 112218 | res.azResult = sqlite3_malloc64(sizeof(char*)*res.nAlloc ); |
| 112219 | if( res.azResult==0 ){ |
| 112220 | db->errCode = SQLITE_NOMEM; |
| 112221 | return SQLITE_NOMEM; |
| 112222 | } |
| 112223 | res.azResult[0] = 0; |
| @@ -111837,11 +112241,11 @@ | |
| 112241 | sqlite3_free_table(&res.azResult[1]); |
| 112242 | return rc; |
| 112243 | } |
| 112244 | if( res.nAlloc>res.nData ){ |
| 112245 | char **azNew; |
| 112246 | azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData ); |
| 112247 | if( azNew==0 ){ |
| 112248 | sqlite3_free_table(&res.azResult[1]); |
| 112249 | db->errCode = SQLITE_NOMEM; |
| 112250 | return SQLITE_NOMEM; |
| 112251 | } |
| @@ -112065,11 +112469,10 @@ | |
| 112469 | } |
| 112470 | |
| 112471 | /* Do not create a trigger on a system table */ |
| 112472 | if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){ |
| 112473 | sqlite3ErrorMsg(pParse, "cannot create trigger on system table"); |
| 112474 | goto trigger_cleanup; |
| 112475 | } |
| 112476 | |
| 112477 | /* INSTEAD of triggers are only for views and views only support INSTEAD |
| 112478 | ** of triggers. |
| @@ -112245,16 +112648,16 @@ | |
| 112648 | u8 op, /* Trigger opcode */ |
| 112649 | Token *pName /* The target name */ |
| 112650 | ){ |
| 112651 | TriggerStep *pTriggerStep; |
| 112652 | |
| 112653 | pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1); |
| 112654 | if( pTriggerStep ){ |
| 112655 | char *z = (char*)&pTriggerStep[1]; |
| 112656 | memcpy(z, pName->z, pName->n); |
| 112657 | sqlite3Dequote(z); |
| 112658 | pTriggerStep->zTarget = z; |
| 112659 | pTriggerStep->op = op; |
| 112660 | } |
| 112661 | return pTriggerStep; |
| 112662 | } |
| 112663 | |
| @@ -112533,11 +112936,11 @@ | |
| 112936 | } |
| 112937 | return (mask ? pList : 0); |
| 112938 | } |
| 112939 | |
| 112940 | /* |
| 112941 | ** Convert the pStep->zTarget string into a SrcList and return a pointer |
| 112942 | ** to that SrcList. |
| 112943 | ** |
| 112944 | ** This routine adds a specific database name, if needed, to the target when |
| 112945 | ** forming the SrcList. This prevents a trigger in one database from |
| 112946 | ** referring to a target in another database. An exception is when the |
| @@ -112546,21 +112949,21 @@ | |
| 112949 | */ |
| 112950 | static SrcList *targetSrcList( |
| 112951 | Parse *pParse, /* The parsing context */ |
| 112952 | TriggerStep *pStep /* The trigger containing the target token */ |
| 112953 | ){ |
| 112954 | sqlite3 *db = pParse->db; |
| 112955 | int iDb; /* Index of the database to use */ |
| 112956 | SrcList *pSrc; /* SrcList to be returned */ |
| 112957 | |
| 112958 | pSrc = sqlite3SrcListAppend(db, 0, 0, 0); |
| 112959 | if( pSrc ){ |
| 112960 | assert( pSrc->nSrc>0 ); |
| 112961 | pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget); |
| 112962 | iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema); |
| 112963 | if( iDb==0 || iDb>=2 ){ |
| 112964 | assert( iDb<db->nDb ); |
| 112965 | pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName); |
| 112966 | } |
| 112967 | } |
| 112968 | return pSrc; |
| 112969 | } |
| @@ -112668,10 +113071,11 @@ | |
| 113071 | assert( pFrom->zErrMsg==0 || pFrom->nErr ); |
| 113072 | assert( pTo->zErrMsg==0 || pTo->nErr ); |
| 113073 | if( pTo->nErr==0 ){ |
| 113074 | pTo->zErrMsg = pFrom->zErrMsg; |
| 113075 | pTo->nErr = pFrom->nErr; |
| 113076 | pTo->rc = pFrom->rc; |
| 113077 | }else{ |
| 113078 | sqlite3DbFree(pFrom->db, pFrom->zErrMsg); |
| 113079 | } |
| 113080 | } |
| 113081 | |
| @@ -114018,17 +114422,21 @@ | |
| 114422 | |
| 114423 | /* Loop through the tables in the main database. For each, do |
| 114424 | ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy |
| 114425 | ** the contents to the temporary database. |
| 114426 | */ |
| 114427 | assert( (db->flags & SQLITE_Vacuum)==0 ); |
| 114428 | db->flags |= SQLITE_Vacuum; |
| 114429 | rc = execExecSql(db, pzErrMsg, |
| 114430 | "SELECT 'INSERT INTO vacuum_db.' || quote(name) " |
| 114431 | "|| ' SELECT * FROM main.' || quote(name) || ';'" |
| 114432 | "FROM main.sqlite_master " |
| 114433 | "WHERE type = 'table' AND name!='sqlite_sequence' " |
| 114434 | " AND coalesce(rootpage,1)>0" |
| 114435 | ); |
| 114436 | assert( (db->flags & SQLITE_Vacuum)!=0 ); |
| 114437 | db->flags &= ~SQLITE_Vacuum; |
| 114438 | if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 114439 | |
| 114440 | /* Copy over the sequence table |
| 114441 | */ |
| 114442 | rc = execExecSql(db, pzErrMsg, |
| @@ -114163,10 +114571,12 @@ | |
| 114571 | ** are invoked only from within xCreate and xConnect methods. |
| 114572 | */ |
| 114573 | struct VtabCtx { |
| 114574 | VTable *pVTable; /* The virtual table being constructed */ |
| 114575 | Table *pTab; /* The Table object to which the virtual table belongs */ |
| 114576 | VtabCtx *pPrior; /* Parent context (if any) */ |
| 114577 | int bDeclared; /* True after sqlite3_declare_vtab() is called */ |
| 114578 | }; |
| 114579 | |
| 114580 | /* |
| 114581 | ** The actual function that does the work of creating a new module. |
| 114582 | ** This function implements the sqlite3_create_module() and |
| @@ -114609,11 +115019,11 @@ | |
| 115019 | Token *pArg = &pParse->sArg; |
| 115020 | if( pArg->z==0 ){ |
| 115021 | pArg->z = p->z; |
| 115022 | pArg->n = p->n; |
| 115023 | }else{ |
| 115024 | assert(pArg->z <= p->z); |
| 115025 | pArg->n = (int)(&p->z[p->n] - pArg->z); |
| 115026 | } |
| 115027 | } |
| 115028 | |
| 115029 | /* |
| @@ -114626,19 +115036,31 @@ | |
| 115036 | Table *pTab, |
| 115037 | Module *pMod, |
| 115038 | int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**), |
| 115039 | char **pzErr |
| 115040 | ){ |
| 115041 | VtabCtx sCtx; |
| 115042 | VTable *pVTable; |
| 115043 | int rc; |
| 115044 | const char *const*azArg = (const char *const*)pTab->azModuleArg; |
| 115045 | int nArg = pTab->nModuleArg; |
| 115046 | char *zErr = 0; |
| 115047 | char *zModuleName; |
| 115048 | int iDb; |
| 115049 | VtabCtx *pCtx; |
| 115050 | |
| 115051 | /* Check that the virtual-table is not already being initialized */ |
| 115052 | for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){ |
| 115053 | if( pCtx->pTab==pTab ){ |
| 115054 | *pzErr = sqlite3MPrintf(db, |
| 115055 | "vtable constructor called recursively: %s", pTab->zName |
| 115056 | ); |
| 115057 | return SQLITE_LOCKED; |
| 115058 | } |
| 115059 | } |
| 115060 | |
| 115061 | zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); |
| 115062 | if( !zModuleName ){ |
| 115063 | return SQLITE_NOMEM; |
| 115064 | } |
| 115065 | |
| 115066 | pVTable = sqlite3DbMallocZero(db, sizeof(VTable)); |
| @@ -114655,15 +115077,17 @@ | |
| 115077 | /* Invoke the virtual table constructor */ |
| 115078 | assert( &db->pVtabCtx ); |
| 115079 | assert( xConstruct ); |
| 115080 | sCtx.pTab = pTab; |
| 115081 | sCtx.pVTable = pVTable; |
| 115082 | sCtx.pPrior = db->pVtabCtx; |
| 115083 | sCtx.bDeclared = 0; |
| 115084 | db->pVtabCtx = &sCtx; |
| 115085 | rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); |
| 115086 | db->pVtabCtx = sCtx.pPrior; |
| 115087 | if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; |
| 115088 | assert( sCtx.pTab==pTab ); |
| 115089 | |
| 115090 | if( SQLITE_OK!=rc ){ |
| 115091 | if( zErr==0 ){ |
| 115092 | *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); |
| 115093 | }else { |
| @@ -114675,17 +115099,18 @@ | |
| 115099 | /* Justification of ALWAYS(): A correct vtab constructor must allocate |
| 115100 | ** the sqlite3_vtab object if successful. */ |
| 115101 | memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0])); |
| 115102 | pVTable->pVtab->pModule = pMod->pModule; |
| 115103 | pVTable->nRef = 1; |
| 115104 | if( sCtx.bDeclared==0 ){ |
| 115105 | const char *zFormat = "vtable constructor did not declare schema: %s"; |
| 115106 | *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName); |
| 115107 | sqlite3VtabUnlock(pVTable); |
| 115108 | rc = SQLITE_ERROR; |
| 115109 | }else{ |
| 115110 | int iCol; |
| 115111 | u8 oooHidden = 0; |
| 115112 | /* If everything went according to plan, link the new VTable structure |
| 115113 | ** into the linked list headed by pTab->pVTable. Then loop through the |
| 115114 | ** columns of the table to see if any of them contain the token "hidden". |
| 115115 | ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from |
| 115116 | ** the type string. */ |
| @@ -114694,11 +115119,14 @@ | |
| 115119 | |
| 115120 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 115121 | char *zType = pTab->aCol[iCol].zType; |
| 115122 | int nType; |
| 115123 | int i = 0; |
| 115124 | if( !zType ){ |
| 115125 | pTab->tabFlags |= oooHidden; |
| 115126 | continue; |
| 115127 | } |
| 115128 | nType = sqlite3Strlen30(zType); |
| 115129 | if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){ |
| 115130 | for(i=0; i<nType; i++){ |
| 115131 | if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7)) |
| 115132 | && (zType[i+7]=='\0' || zType[i+7]==' ') |
| @@ -114717,10 +115145,13 @@ | |
| 115145 | if( zType[i]=='\0' && i>0 ){ |
| 115146 | assert(zType[i-1]==' '); |
| 115147 | zType[i-1] = '\0'; |
| 115148 | } |
| 115149 | pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN; |
| 115150 | oooHidden = TF_OOOHidden; |
| 115151 | }else{ |
| 115152 | pTab->tabFlags |= oooHidden; |
| 115153 | } |
| 115154 | } |
| 115155 | } |
| 115156 | } |
| 115157 | |
| @@ -114845,12 +115276,12 @@ | |
| 115276 | ** This function is used to set the schema of a virtual table. It is only |
| 115277 | ** valid to call this function from within the xCreate() or xConnect() of a |
| 115278 | ** virtual table module. |
| 115279 | */ |
| 115280 | SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ |
| 115281 | VtabCtx *pCtx; |
| 115282 | Parse *pParse; |
| 115283 | int rc = SQLITE_OK; |
| 115284 | Table *pTab; |
| 115285 | char *zErr = 0; |
| 115286 | |
| 115287 | #ifdef SQLITE_ENABLE_API_ARMOR |
| @@ -114857,15 +115288,17 @@ | |
| 115288 | if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){ |
| 115289 | return SQLITE_MISUSE_BKPT; |
| 115290 | } |
| 115291 | #endif |
| 115292 | sqlite3_mutex_enter(db->mutex); |
| 115293 | pCtx = db->pVtabCtx; |
| 115294 | if( !pCtx || pCtx->bDeclared ){ |
| 115295 | sqlite3Error(db, SQLITE_MISUSE); |
| 115296 | sqlite3_mutex_leave(db->mutex); |
| 115297 | return SQLITE_MISUSE_BKPT; |
| 115298 | } |
| 115299 | pTab = pCtx->pTab; |
| 115300 | assert( (pTab->tabFlags & TF_Virtual)!=0 ); |
| 115301 | |
| 115302 | pParse = sqlite3StackAllocZero(db, sizeof(*pParse)); |
| 115303 | if( pParse==0 ){ |
| 115304 | rc = SQLITE_NOMEM; |
| @@ -114884,11 +115317,11 @@ | |
| 115317 | pTab->aCol = pParse->pNewTable->aCol; |
| 115318 | pTab->nCol = pParse->pNewTable->nCol; |
| 115319 | pParse->pNewTable->nCol = 0; |
| 115320 | pParse->pNewTable->aCol = 0; |
| 115321 | } |
| 115322 | pCtx->bDeclared = 1; |
| 115323 | }else{ |
| 115324 | sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr); |
| 115325 | sqlite3DbFree(db, zErr); |
| 115326 | rc = SQLITE_ERROR; |
| 115327 | } |
| @@ -115078,11 +115511,11 @@ | |
| 115511 | */ |
| 115512 | SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){ |
| 115513 | int rc = SQLITE_OK; |
| 115514 | |
| 115515 | assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN ); |
| 115516 | assert( iSavepoint>=-1 ); |
| 115517 | if( db->aVTrans ){ |
| 115518 | int i; |
| 115519 | for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){ |
| 115520 | VTable *pVTab = db->aVTrans[i]; |
| 115521 | const sqlite3_module *pMod = pVTab->pMod->pModule; |
| @@ -115196,11 +115629,11 @@ | |
| 115629 | assert( IsVirtual(pTab) ); |
| 115630 | for(i=0; i<pToplevel->nVtabLock; i++){ |
| 115631 | if( pTab==pToplevel->apVtabLock[i] ) return; |
| 115632 | } |
| 115633 | n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]); |
| 115634 | apVtabLock = sqlite3_realloc64(pToplevel->apVtabLock, n); |
| 115635 | if( apVtabLock ){ |
| 115636 | pToplevel->apVtabLock = apVtabLock; |
| 115637 | pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab; |
| 115638 | }else{ |
| 115639 | pToplevel->db->mallocFailed = 1; |
| @@ -115995,17 +116428,18 @@ | |
| 116428 | ** In the previous sentence and in the diagram, "slot[]" refers to |
| 116429 | ** the WhereClause.a[] array. The slot[] array grows as needed to contain |
| 116430 | ** all terms of the WHERE clause. |
| 116431 | */ |
| 116432 | static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){ |
| 116433 | Expr *pE2 = sqlite3ExprSkipCollate(pExpr); |
| 116434 | pWC->op = op; |
| 116435 | if( pE2==0 ) return; |
| 116436 | if( pE2->op!=op ){ |
| 116437 | whereClauseInsert(pWC, pExpr, 0); |
| 116438 | }else{ |
| 116439 | whereSplit(pWC, pE2->pLeft, op); |
| 116440 | whereSplit(pWC, pE2->pRight, op); |
| 116441 | } |
| 116442 | } |
| 116443 | |
| 116444 | /* |
| 116445 | ** Initialize a WhereMaskSet object |
| @@ -117272,11 +117706,11 @@ | |
| 117706 | if( p->op==TK_COLUMN |
| 117707 | && p->iColumn==pIdx->aiColumn[iCol] |
| 117708 | && p->iTable==iBase |
| 117709 | ){ |
| 117710 | CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr); |
| 117711 | if( pColl && 0==sqlite3StrICmp(pColl->zName, zColl) ){ |
| 117712 | return i; |
| 117713 | } |
| 117714 | } |
| 117715 | } |
| 117716 | |
| @@ -117546,11 +117980,11 @@ | |
| 117980 | if( (idxCols & cMask)==0 ){ |
| 117981 | Expr *pX = pTerm->pExpr; |
| 117982 | idxCols |= cMask; |
| 117983 | pIdx->aiColumn[n] = pTerm->u.leftColumn; |
| 117984 | pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); |
| 117985 | pIdx->azColl[n] = pColl ? pColl->zName : "BINARY"; |
| 117986 | n++; |
| 117987 | } |
| 117988 | } |
| 117989 | } |
| 117990 | assert( (u32)n==pLoop->u.btree.nEq ); |
| @@ -118842,12 +119276,11 @@ | |
| 119276 | |
| 119277 | isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 |
| 119278 | || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0)) |
| 119279 | || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX)); |
| 119280 | |
| 119281 | sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH); |
| 119282 | sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN"); |
| 119283 | if( pItem->pSelect ){ |
| 119284 | sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId); |
| 119285 | }else{ |
| 119286 | sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName); |
| @@ -120042,10 +120475,17 @@ | |
| 120475 | /* |
| 120476 | ** Free a WhereInfo structure |
| 120477 | */ |
| 120478 | static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){ |
| 120479 | if( ALWAYS(pWInfo) ){ |
| 120480 | int i; |
| 120481 | for(i=0; i<pWInfo->nLevel; i++){ |
| 120482 | WhereLevel *pLevel = &pWInfo->a[i]; |
| 120483 | if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){ |
| 120484 | sqlite3DbFree(db, pLevel->u.in.aInLoop); |
| 120485 | } |
| 120486 | } |
| 120487 | whereClauseClear(&pWInfo->sWC); |
| 120488 | while( pWInfo->pLoops ){ |
| 120489 | WhereLoop *p = pWInfo->pLoops; |
| 120490 | pWInfo->pLoops = p->pNextLoop; |
| 120491 | whereLoopDelete(db, p); |
| @@ -120521,11 +120961,11 @@ | |
| 120961 | ** changes "x IN (?)" into "x=?". */ |
| 120962 | |
| 120963 | }else if( eOp & (WO_EQ) ){ |
| 120964 | pNew->wsFlags |= WHERE_COLUMN_EQ; |
| 120965 | if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){ |
| 120966 | if( iCol>=0 && pProbe->uniqNotNull==0 ){ |
| 120967 | pNew->wsFlags |= WHERE_UNQ_WANTED; |
| 120968 | }else{ |
| 120969 | pNew->wsFlags |= WHERE_ONEROW; |
| 120970 | } |
| 120971 | } |
| @@ -121981,11 +122421,11 @@ | |
| 122421 | pWInfo->nOBSat = pFrom->isOrdered; |
| 122422 | if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0; |
| 122423 | pWInfo->revMask = pFrom->revLoop; |
| 122424 | } |
| 122425 | if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP) |
| 122426 | && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0 |
| 122427 | ){ |
| 122428 | Bitmask revMask = 0; |
| 122429 | int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy, |
| 122430 | pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask |
| 122431 | ); |
| @@ -122386,11 +122826,10 @@ | |
| 122826 | if( pParse->nErr || NEVER(db->mallocFailed) ){ |
| 122827 | goto whereBeginError; |
| 122828 | } |
| 122829 | #ifdef WHERETRACE_ENABLED /* !=0 */ |
| 122830 | if( sqlite3WhereTrace ){ |
| 122831 | sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut); |
| 122832 | if( pWInfo->nOBSat>0 ){ |
| 122833 | sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask); |
| 122834 | } |
| 122835 | switch( pWInfo->eDistinct ){ |
| @@ -122639,11 +123078,10 @@ | |
| 123078 | VdbeCoverage(v); |
| 123079 | VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen); |
| 123080 | VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen); |
| 123081 | sqlite3VdbeJumpHere(v, pIn->addrInTop-1); |
| 123082 | } |
| 123083 | } |
| 123084 | sqlite3VdbeResolveLabel(v, pLevel->addrBrk); |
| 123085 | if( pLevel->addrSkip ){ |
| 123086 | sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip); |
| 123087 | VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName)); |
| @@ -122850,10 +123288,32 @@ | |
| 123288 | /* |
| 123289 | ** An instance of this structure holds the ATTACH key and the key type. |
| 123290 | */ |
| 123291 | struct AttachKey { int type; Token key; }; |
| 123292 | |
| 123293 | |
| 123294 | /* |
| 123295 | ** For a compound SELECT statement, make sure p->pPrior->pNext==p for |
| 123296 | ** all elements in the list. And make sure list length does not exceed |
| 123297 | ** SQLITE_LIMIT_COMPOUND_SELECT. |
| 123298 | */ |
| 123299 | static void parserDoubleLinkSelect(Parse *pParse, Select *p){ |
| 123300 | if( p->pPrior ){ |
| 123301 | Select *pNext = 0, *pLoop; |
| 123302 | int mxSelect, cnt = 0; |
| 123303 | for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){ |
| 123304 | pLoop->pNext = pNext; |
| 123305 | pLoop->selFlags |= SF_Compound; |
| 123306 | } |
| 123307 | if( (p->selFlags & SF_MultiValue)==0 && |
| 123308 | (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 && |
| 123309 | cnt>mxSelect |
| 123310 | ){ |
| 123311 | sqlite3ErrorMsg(pParse, "too many terms in compound SELECT"); |
| 123312 | } |
| 123313 | } |
| 123314 | } |
| 123315 | |
| 123316 | /* This is a utility routine used to set the ExprSpan.zStart and |
| 123317 | ** ExprSpan.zEnd values of pOut so that the span covers the complete |
| 123318 | ** range of text beginning with pStart and going to the end of pEnd. |
| 123319 | */ |
| @@ -125167,31 +125627,14 @@ | |
| 125627 | sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3); |
| 125628 | } |
| 125629 | break; |
| 125630 | case 112: /* select ::= with selectnowith */ |
| 125631 | { |
| 125632 | Select *p = yymsp[0].minor.yy3; |
| 125633 | if( p ){ |
| 125634 | p->pWith = yymsp[-1].minor.yy59; |
| 125635 | parserDoubleLinkSelect(pParse, p); |
| 125636 | }else{ |
| 125637 | sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59); |
| 125638 | } |
| 125639 | yygotominor.yy3 = p; |
| 125640 | } |
| @@ -125205,16 +125648,18 @@ | |
| 125648 | Select *pRhs = yymsp[0].minor.yy3; |
| 125649 | if( pRhs && pRhs->pPrior ){ |
| 125650 | SrcList *pFrom; |
| 125651 | Token x; |
| 125652 | x.n = 0; |
| 125653 | parserDoubleLinkSelect(pParse, pRhs); |
| 125654 | pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0); |
| 125655 | pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0); |
| 125656 | } |
| 125657 | if( pRhs ){ |
| 125658 | pRhs->op = (u8)yymsp[-1].minor.yy328; |
| 125659 | pRhs->pPrior = yymsp[-2].minor.yy3; |
| 125660 | pRhs->selFlags &= ~SF_MultiValue; |
| 125661 | if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1; |
| 125662 | }else{ |
| 125663 | sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3); |
| 125664 | } |
| 125665 | yygotominor.yy3 = pRhs; |
| @@ -125257,17 +125702,20 @@ | |
| 125702 | yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0); |
| 125703 | } |
| 125704 | break; |
| 125705 | case 121: /* values ::= values COMMA LP exprlist RP */ |
| 125706 | { |
| 125707 | Select *pRight, *pLeft = yymsp[-4].minor.yy3; |
| 125708 | pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values|SF_MultiValue,0,0); |
| 125709 | if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue; |
| 125710 | if( pRight ){ |
| 125711 | pRight->op = TK_ALL; |
| 125712 | pLeft = yymsp[-4].minor.yy3; |
| 125713 | pRight->pPrior = pLeft; |
| 125714 | yygotominor.yy3 = pRight; |
| 125715 | }else{ |
| 125716 | yygotominor.yy3 = pLeft; |
| 125717 | } |
| 125718 | } |
| 125719 | break; |
| 125720 | case 122: /* distinct ::= DISTINCT */ |
| 125721 | {yygotominor.yy381 = SF_Distinct;} |
| @@ -127067,14 +127515,12 @@ | |
| 127515 | goto abort_parse; |
| 127516 | } |
| 127517 | break; |
| 127518 | } |
| 127519 | case TK_ILLEGAL: { |
| 127520 | sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"", |
| 127521 | &pParse->sLastToken); |
| 127522 | goto abort_parse; |
| 127523 | } |
| 127524 | case TK_SEMI: { |
| 127525 | pParse->zTail = &zSql[i]; |
| 127526 | /* Fall thru into the default case */ |
| @@ -127088,16 +127534,19 @@ | |
| 127534 | break; |
| 127535 | } |
| 127536 | } |
| 127537 | } |
| 127538 | abort_parse: |
| 127539 | assert( nErr==0 ); |
| 127540 | if( zSql[i]==0 && pParse->rc==SQLITE_OK && db->mallocFailed==0 ){ |
| 127541 | if( lastTokenParsed!=TK_SEMI ){ |
| 127542 | sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse); |
| 127543 | pParse->zTail = &zSql[i]; |
| 127544 | } |
| 127545 | if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){ |
| 127546 | sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse); |
| 127547 | } |
| 127548 | } |
| 127549 | #ifdef YYTRACKMAXSTACKDEPTH |
| 127550 | sqlite3_mutex_enter(sqlite3MallocMutex()); |
| 127551 | sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK, |
| 127552 | sqlite3ParserStackPeak(pEngine) |
| @@ -127154,13 +127603,11 @@ | |
| 127603 | while( pParse->pZombieTab ){ |
| 127604 | Table *p = pParse->pZombieTab; |
| 127605 | pParse->pZombieTab = p->pNextZombie; |
| 127606 | sqlite3DeleteTable(db, p); |
| 127607 | } |
| 127608 | assert( nErr==0 || pParse->rc!=SQLITE_OK ); |
| 127609 | return nErr; |
| 127610 | } |
| 127611 | |
| 127612 | /************** End of tokenize.c ********************************************/ |
| 127613 | /************** Begin file complete.c ****************************************/ |
| @@ -127432,11 +127879,11 @@ | |
| 127879 | ** UTF-8. |
| 127880 | */ |
| 127881 | SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){ |
| 127882 | sqlite3_value *pVal; |
| 127883 | char const *zSql8; |
| 127884 | int rc; |
| 127885 | |
| 127886 | #ifndef SQLITE_OMIT_AUTOINIT |
| 127887 | rc = sqlite3_initialize(); |
| 127888 | if( rc ) return rc; |
| 127889 | #endif |
| @@ -127598,10 +128045,22 @@ | |
| 128045 | ** zero if and only if SQLite was compiled with mutexing code omitted due to |
| 128046 | ** the SQLITE_THREADSAFE compile-time option being set to 0. |
| 128047 | */ |
| 128048 | SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; } |
| 128049 | |
| 128050 | /* |
| 128051 | ** When compiling the test fixture or with debugging enabled (on Win32), |
| 128052 | ** this variable being set to non-zero will cause OSTRACE macros to emit |
| 128053 | ** extra diagnostic information. |
| 128054 | */ |
| 128055 | #ifdef SQLITE_HAVE_OS_TRACE |
| 128056 | # ifndef SQLITE_DEBUG_OS_TRACE |
| 128057 | # define SQLITE_DEBUG_OS_TRACE 0 |
| 128058 | # endif |
| 128059 | int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; |
| 128060 | #endif |
| 128061 | |
| 128062 | #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE) |
| 128063 | /* |
| 128064 | ** If the following function pointer is not NULL and if |
| 128065 | ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing |
| 128066 | ** I/O active are written using this function. These messages |
| @@ -128737,11 +129196,11 @@ | |
| 129196 | |
| 129197 | /* |
| 129198 | ** Return a static string containing the name corresponding to the error code |
| 129199 | ** specified in the argument. |
| 129200 | */ |
| 129201 | #if defined(SQLITE_NEED_ERR_NAME) |
| 129202 | SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ |
| 129203 | const char *zName = 0; |
| 129204 | int i, origRc = rc; |
| 129205 | for(i=0; i<2 && zName==0; i++, rc &= 0xff){ |
| 129206 | switch( rc ){ |
| @@ -129962,18 +130421,18 @@ | |
| 130421 | ){ |
| 130422 | char *zOpt; |
| 130423 | int eState; /* Parser state when parsing URI */ |
| 130424 | int iIn; /* Input character index */ |
| 130425 | int iOut = 0; /* Output character index */ |
| 130426 | u64 nByte = nUri+2; /* Bytes of space to allocate */ |
| 130427 | |
| 130428 | /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen |
| 130429 | ** method that there may be extra parameters following the file-name. */ |
| 130430 | flags |= SQLITE_OPEN_URI; |
| 130431 | |
| 130432 | for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&'); |
| 130433 | zFile = sqlite3_malloc64(nByte); |
| 130434 | if( !zFile ) return SQLITE_NOMEM; |
| 130435 | |
| 130436 | iIn = 5; |
| 130437 | #ifdef SQLITE_ALLOW_URI_AUTHORITY |
| 130438 | if( strncmp(zUri+5, "///", 3)==0 ){ |
| @@ -130135,11 +130594,11 @@ | |
| 130594 | |
| 130595 | zOpt = &zVal[nVal+1]; |
| 130596 | } |
| 130597 | |
| 130598 | }else{ |
| 130599 | zFile = sqlite3_malloc64(nUri+2); |
| 130600 | if( !zFile ) return SQLITE_NOMEM; |
| 130601 | memcpy(zFile, zUri, nUri); |
| 130602 | zFile[nUri] = '\0'; |
| 130603 | zFile[nUri+1] = '\0'; |
| 130604 | flags &= ~SQLITE_OPEN_URI; |
| @@ -132344,10 +132803,15 @@ | |
| 132803 | ** false. |
| 132804 | */ |
| 132805 | #ifdef SQLITE_COVERAGE_TEST |
| 132806 | # define ALWAYS(x) (1) |
| 132807 | # define NEVER(X) (0) |
| 132808 | #elif defined(SQLITE_DEBUG) |
| 132809 | # define ALWAYS(x) sqlite3Fts3Always((x)!=0) |
| 132810 | # define NEVER(x) sqlite3Fts3Never((x)!=0) |
| 132811 | SQLITE_PRIVATE int sqlite3Fts3Always(int b); |
| 132812 | SQLITE_PRIVATE int sqlite3Fts3Never(int b); |
| 132813 | #else |
| 132814 | # define ALWAYS(x) (x) |
| 132815 | # define NEVER(x) (x) |
| 132816 | #endif |
| 132817 | |
| @@ -132744,10 +133208,11 @@ | |
| 133208 | #define fts3GetVarint32(p, piVal) ( \ |
| 133209 | (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \ |
| 133210 | ) |
| 133211 | |
| 133212 | /* fts3.c */ |
| 133213 | SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...); |
| 133214 | SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64); |
| 133215 | SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *); |
| 133216 | SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *); |
| 133217 | SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64); |
| 133218 | SQLITE_PRIVATE void sqlite3Fts3Dequote(char *); |
| @@ -132832,10 +133297,17 @@ | |
| 133297 | |
| 133298 | static int fts3EvalNext(Fts3Cursor *pCsr); |
| 133299 | static int fts3EvalStart(Fts3Cursor *pCsr); |
| 133300 | static int fts3TermSegReaderCursor( |
| 133301 | Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **); |
| 133302 | |
| 133303 | #ifndef SQLITE_AMALGAMATION |
| 133304 | # if defined(SQLITE_DEBUG) |
| 133305 | SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; } |
| 133306 | SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; } |
| 133307 | # endif |
| 133308 | #endif |
| 133309 | |
| 133310 | /* |
| 133311 | ** Write a 64-bit variable-length integer to memory starting at p[0]. |
| 133312 | ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes. |
| 133313 | ** The number of bytes written is returned. |
| @@ -132942,11 +133414,11 @@ | |
| 133414 | int iOut = 0; /* Index of next byte to write to output */ |
| 133415 | |
| 133416 | /* If the first byte was a '[', then the close-quote character is a ']' */ |
| 133417 | if( quote=='[' ) quote = ']'; |
| 133418 | |
| 133419 | while( z[iIn] ){ |
| 133420 | if( z[iIn]==quote ){ |
| 133421 | if( z[iIn+1]!=quote ) break; |
| 133422 | z[iOut++] = quote; |
| 133423 | iIn += 2; |
| 133424 | }else{ |
| @@ -133020,10 +133492,21 @@ | |
| 133492 | p->pTokenizer->pModule->xDestroy(p->pTokenizer); |
| 133493 | |
| 133494 | sqlite3_free(p); |
| 133495 | return SQLITE_OK; |
| 133496 | } |
| 133497 | |
| 133498 | /* |
| 133499 | ** Write an error message into *pzErr |
| 133500 | */ |
| 133501 | SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char **pzErr, const char *zFormat, ...){ |
| 133502 | va_list ap; |
| 133503 | sqlite3_free(*pzErr); |
| 133504 | va_start(ap, zFormat); |
| 133505 | *pzErr = sqlite3_vmprintf(zFormat, ap); |
| 133506 | va_end(ap); |
| 133507 | } |
| 133508 | |
| 133509 | /* |
| 133510 | ** Construct one or more SQL statements from the format string given |
| 133511 | ** and then evaluate those statements. The success code is written |
| 133512 | ** into *pRc. |
| @@ -133539,11 +134022,12 @@ | |
| 134022 | sqlite3 *db, /* Database handle */ |
| 134023 | const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */ |
| 134024 | const char *zTbl, /* Name of content table */ |
| 134025 | const char ***pazCol, /* OUT: Malloc'd array of column names */ |
| 134026 | int *pnCol, /* OUT: Size of array *pazCol */ |
| 134027 | int *pnStr, /* OUT: Bytes of string content */ |
| 134028 | char **pzErr /* OUT: error message */ |
| 134029 | ){ |
| 134030 | int rc = SQLITE_OK; /* Return code */ |
| 134031 | char *zSql; /* "SELECT *" statement on zTbl */ |
| 134032 | sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */ |
| 134033 | |
| @@ -133550,10 +134034,13 @@ | |
| 134034 | zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl); |
| 134035 | if( !zSql ){ |
| 134036 | rc = SQLITE_NOMEM; |
| 134037 | }else{ |
| 134038 | rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0); |
| 134039 | if( rc!=SQLITE_OK ){ |
| 134040 | sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db)); |
| 134041 | } |
| 134042 | } |
| 134043 | sqlite3_free(zSql); |
| 134044 | |
| 134045 | if( rc==SQLITE_OK ){ |
| 134046 | const char **azCol; /* Output array */ |
| @@ -133716,17 +134203,17 @@ | |
| 134203 | if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){ |
| 134204 | break; |
| 134205 | } |
| 134206 | } |
| 134207 | if( iOpt==SizeofArray(aFts4Opt) ){ |
| 134208 | sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z); |
| 134209 | rc = SQLITE_ERROR; |
| 134210 | }else{ |
| 134211 | switch( iOpt ){ |
| 134212 | case 0: /* MATCHINFO */ |
| 134213 | if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){ |
| 134214 | sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal); |
| 134215 | rc = SQLITE_ERROR; |
| 134216 | } |
| 134217 | bNoDocsize = 1; |
| 134218 | break; |
| 134219 | |
| @@ -133750,11 +134237,11 @@ | |
| 134237 | |
| 134238 | case 4: /* ORDER */ |
| 134239 | if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3)) |
| 134240 | && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4)) |
| 134241 | ){ |
| 134242 | sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal); |
| 134243 | rc = SQLITE_ERROR; |
| 134244 | } |
| 134245 | bDescIdx = (zVal[0]=='d' || zVal[0]=='D'); |
| 134246 | break; |
| 134247 | |
| @@ -133801,11 +134288,11 @@ | |
| 134288 | zCompress = 0; |
| 134289 | zUncompress = 0; |
| 134290 | if( nCol==0 ){ |
| 134291 | sqlite3_free((void*)aCol); |
| 134292 | aCol = 0; |
| 134293 | rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr); |
| 134294 | |
| 134295 | /* If a languageid= option was specified, remove the language id |
| 134296 | ** column from the aCol[] array. */ |
| 134297 | if( rc==SQLITE_OK && zLanguageid ){ |
| 134298 | int j; |
| @@ -133836,11 +134323,11 @@ | |
| 134323 | assert( pTokenizer ); |
| 134324 | |
| 134325 | rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex); |
| 134326 | if( rc==SQLITE_ERROR ){ |
| 134327 | assert( zPrefix ); |
| 134328 | sqlite3Fts3ErrMsg(pzErr, "error parsing prefix parameter: %s", zPrefix); |
| 134329 | } |
| 134330 | if( rc!=SQLITE_OK ) goto fts3_init_out; |
| 134331 | |
| 134332 | /* Allocate and populate the Fts3Table structure. */ |
| 134333 | nByte = sizeof(Fts3Table) + /* Fts3Table */ |
| @@ -133918,19 +134405,19 @@ | |
| 134405 | } |
| 134406 | } |
| 134407 | } |
| 134408 | for(i=0; i<nNotindexed; i++){ |
| 134409 | if( azNotindexed[i] ){ |
| 134410 | sqlite3Fts3ErrMsg(pzErr, "no such column: %s", azNotindexed[i]); |
| 134411 | rc = SQLITE_ERROR; |
| 134412 | } |
| 134413 | } |
| 134414 | |
| 134415 | if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){ |
| 134416 | char const *zMiss = (zCompress==0 ? "compress" : "uncompress"); |
| 134417 | rc = SQLITE_ERROR; |
| 134418 | sqlite3Fts3ErrMsg(pzErr, "missing %s parameter in fts4 constructor", zMiss); |
| 134419 | } |
| 134420 | p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc); |
| 134421 | p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc); |
| 134422 | if( rc!=SQLITE_OK ) goto fts3_init_out; |
| 134423 | |
| @@ -135319,11 +135806,11 @@ | |
| 135806 | ** Fts3SegReaderPending might segfault, as the data structures used by |
| 135807 | ** fts4aux are not completely populated. So it's easiest to filter these |
| 135808 | ** calls out here. */ |
| 135809 | if( iLevel<0 && p->aIndex ){ |
| 135810 | Fts3SegReader *pSeg = 0; |
| 135811 | rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg); |
| 135812 | if( rc==SQLITE_OK && pSeg ){ |
| 135813 | rc = fts3SegReaderCursorAppend(pCsr, pSeg); |
| 135814 | } |
| 135815 | } |
| 135816 | |
| @@ -135968,15 +136455,35 @@ | |
| 136455 | */ |
| 136456 | static void fts3ReversePoslist(char *pStart, char **ppPoslist){ |
| 136457 | char *p = &(*ppPoslist)[-2]; |
| 136458 | char c = 0; |
| 136459 | |
| 136460 | /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */ |
| 136461 | while( p>pStart && (c=*p--)==0 ); |
| 136462 | |
| 136463 | /* Search backwards for a varint with value zero (the end of the previous |
| 136464 | ** poslist). This is an 0x00 byte preceded by some byte that does not |
| 136465 | ** have the 0x80 bit set. */ |
| 136466 | while( p>pStart && (*p & 0x80) | c ){ |
| 136467 | c = *p--; |
| 136468 | } |
| 136469 | assert( p==pStart || c==0 ); |
| 136470 | |
| 136471 | /* At this point p points to that preceding byte without the 0x80 bit |
| 136472 | ** set. So to find the start of the poslist, skip forward 2 bytes then |
| 136473 | ** over a varint. |
| 136474 | ** |
| 136475 | ** Normally. The other case is that p==pStart and the poslist to return |
| 136476 | ** is the first in the doclist. In this case do not skip forward 2 bytes. |
| 136477 | ** The second part of the if condition (c==0 && *ppPoslist>&p[2]) |
| 136478 | ** is required for cases where the first byte of a doclist and the |
| 136479 | ** doclist is empty. For example, if the first docid is 10, a doclist |
| 136480 | ** that begins with: |
| 136481 | ** |
| 136482 | ** 0x0A 0x00 <next docid delta varint> |
| 136483 | */ |
| 136484 | if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; } |
| 136485 | while( *p++&0x80 ); |
| 136486 | *ppPoslist = p; |
| 136487 | } |
| 136488 | |
| 136489 | /* |
| @@ -136043,10 +136550,12 @@ | |
| 136550 | case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]); |
| 136551 | case 2: zStart = (const char*)sqlite3_value_text(apVal[1]); |
| 136552 | } |
| 136553 | if( !zEllipsis || !zEnd || !zStart ){ |
| 136554 | sqlite3_result_error_nomem(pContext); |
| 136555 | }else if( nToken==0 ){ |
| 136556 | sqlite3_result_text(pContext, "", -1, SQLITE_STATIC); |
| 136557 | }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){ |
| 136558 | sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken); |
| 136559 | } |
| 136560 | } |
| 136561 | |
| @@ -137104,16 +137613,18 @@ | |
| 137613 | Fts3Expr *pExpr, /* Expression to initialize phrases in */ |
| 137614 | int *pRc /* IN/OUT: Error code */ |
| 137615 | ){ |
| 137616 | if( pExpr && SQLITE_OK==*pRc ){ |
| 137617 | if( pExpr->eType==FTSQUERY_PHRASE ){ |
| 137618 | int nToken = pExpr->pPhrase->nToken; |
| 137619 | if( nToken ){ |
| 137620 | int i; |
| 137621 | for(i=0; i<nToken; i++){ |
| 137622 | if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break; |
| 137623 | } |
| 137624 | pExpr->bDeferred = (i==nToken); |
| 137625 | } |
| 137626 | *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase); |
| 137627 | }else{ |
| 137628 | fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc); |
| 137629 | fts3EvalStartReaders(pCsr, pExpr->pRight, pRc); |
| 137630 | pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred); |
| @@ -138272,11 +138783,12 @@ | |
| 138783 | if( rc!=SQLITE_OK ) return rc; |
| 138784 | |
| 138785 | pIter = pPhrase->pOrPoslist; |
| 138786 | iDocid = pPhrase->iOrDocid; |
| 138787 | if( pCsr->bDesc==bDescDoclist ){ |
| 138788 | bEof = !pPhrase->doclist.nAll || |
| 138789 | (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll)); |
| 138790 | while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ |
| 138791 | sqlite3Fts3DoclistNext( |
| 138792 | bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, |
| 138793 | &pIter, &iDocid, &bEof |
| 138794 | ); |
| @@ -138484,11 +138996,11 @@ | |
| 138996 | |
| 138997 | *ppVtab = (sqlite3_vtab *)p; |
| 138998 | return SQLITE_OK; |
| 138999 | |
| 139000 | bad_args: |
| 139001 | sqlite3Fts3ErrMsg(pzErr, "invalid arguments to fts4aux constructor"); |
| 139002 | return SQLITE_ERROR; |
| 139003 | } |
| 139004 | |
| 139005 | /* |
| 139006 | ** This function does the work for both the xDisconnect and xDestroy methods. |
| @@ -139942,17 +140454,17 @@ | |
| 140454 | |
| 140455 | if( rc!=SQLITE_OK ){ |
| 140456 | sqlite3Fts3ExprFree(*ppExpr); |
| 140457 | *ppExpr = 0; |
| 140458 | if( rc==SQLITE_TOOBIG ){ |
| 140459 | sqlite3Fts3ErrMsg(pzErr, |
| 140460 | "FTS expression tree is too large (maximum depth %d)", |
| 140461 | SQLITE_FTS3_MAX_EXPR_DEPTH |
| 140462 | ); |
| 140463 | rc = SQLITE_ERROR; |
| 140464 | }else if( rc==SQLITE_ERROR ){ |
| 140465 | sqlite3Fts3ErrMsg(pzErr, "malformed MATCH expression: [%s]", z); |
| 140466 | } |
| 140467 | } |
| 140468 | |
| 140469 | return rc; |
| 140470 | } |
| @@ -141424,11 +141936,11 @@ | |
| 141936 | z[n] = '\0'; |
| 141937 | sqlite3Fts3Dequote(z); |
| 141938 | |
| 141939 | m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1); |
| 141940 | if( !m ){ |
| 141941 | sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", z); |
| 141942 | rc = SQLITE_ERROR; |
| 141943 | }else{ |
| 141944 | char const **aArg = 0; |
| 141945 | int iArg = 0; |
| 141946 | z = &z[n+1]; |
| @@ -141447,11 +141959,11 @@ | |
| 141959 | z = &z[n+1]; |
| 141960 | } |
| 141961 | rc = m->xCreate(iArg, aArg, ppTok); |
| 141962 | assert( rc!=SQLITE_OK || *ppTok ); |
| 141963 | if( rc!=SQLITE_OK ){ |
| 141964 | sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer"); |
| 141965 | }else{ |
| 141966 | (*ppTok)->pModule = m; |
| 141967 | } |
| 141968 | sqlite3_free((void *)aArg); |
| 141969 | } |
| @@ -141531,13 +142043,13 @@ | |
| 142043 | |
| 142044 | pHash = (Fts3Hash *)sqlite3_user_data(context); |
| 142045 | p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1); |
| 142046 | |
| 142047 | if( !p ){ |
| 142048 | char *zErr2 = sqlite3_mprintf("unknown tokenizer: %s", zName); |
| 142049 | sqlite3_result_error(context, zErr2, -1); |
| 142050 | sqlite3_free(zErr2); |
| 142051 | return; |
| 142052 | } |
| 142053 | |
| 142054 | pRet = Tcl_NewObj(); |
| 142055 | Tcl_IncrRefCount(pRet); |
| @@ -142068,11 +142580,11 @@ | |
| 142580 | sqlite3_tokenizer_module *p; |
| 142581 | int nName = (int)strlen(zName); |
| 142582 | |
| 142583 | p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1); |
| 142584 | if( !p ){ |
| 142585 | sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", zName); |
| 142586 | return SQLITE_ERROR; |
| 142587 | } |
| 142588 | |
| 142589 | *pp = p; |
| 142590 | return SQLITE_OK; |
| @@ -142765,11 +143277,11 @@ | |
| 143277 | /* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)", |
| 143278 | /* 24 */ "", |
| 143279 | /* 25 */ "", |
| 143280 | |
| 143281 | /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?", |
| 143282 | /* 27 */ "SELECT ? UNION SELECT level / (1024 * ?) FROM %Q.'%q_segdir'", |
| 143283 | |
| 143284 | /* This statement is used to determine which level to read the input from |
| 143285 | ** when performing an incremental merge. It returns the absolute level number |
| 143286 | ** of the oldest level in the db that contains at least ? segments. Or, |
| 143287 | ** if no level in the FTS index contains more than ? segments, the statement |
| @@ -145883,11 +146395,12 @@ | |
| 146395 | sqlite3_stmt *pAllLangid = 0; |
| 146396 | |
| 146397 | rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 146398 | if( rc==SQLITE_OK ){ |
| 146399 | int rc2; |
| 146400 | sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid); |
| 146401 | sqlite3_bind_int(pAllLangid, 2, p->nIndex); |
| 146402 | while( sqlite3_step(pAllLangid)==SQLITE_ROW ){ |
| 146403 | int i; |
| 146404 | int iLangid = sqlite3_column_int(pAllLangid, 0); |
| 146405 | for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){ |
| 146406 | rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL); |
| @@ -147215,11 +147728,11 @@ | |
| 147728 | while( i>0 && (pHint->a[i-1] & 0x80) ) i--; |
| 147729 | |
| 147730 | pHint->n = i; |
| 147731 | i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel); |
| 147732 | i += fts3GetVarint32(&pHint->a[i], pnInput); |
| 147733 | if( i!=nHint ) return FTS_CORRUPT_VTAB; |
| 147734 | |
| 147735 | return SQLITE_OK; |
| 147736 | } |
| 147737 | |
| 147738 | |
| @@ -147583,11 +148096,12 @@ | |
| 148096 | |
| 148097 | /* This block calculates the checksum according to the FTS index. */ |
| 148098 | rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 148099 | if( rc==SQLITE_OK ){ |
| 148100 | int rc2; |
| 148101 | sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid); |
| 148102 | sqlite3_bind_int(pAllLangid, 2, p->nIndex); |
| 148103 | while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){ |
| 148104 | int iLangid = sqlite3_column_int(pAllLangid, 0); |
| 148105 | int i; |
| 148106 | for(i=0; i<p->nIndex; i++){ |
| 148107 | cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc); |
| @@ -147596,11 +148110,10 @@ | |
| 148110 | rc2 = sqlite3_reset(pAllLangid); |
| 148111 | if( rc==SQLITE_OK ) rc = rc2; |
| 148112 | } |
| 148113 | |
| 148114 | /* This block calculates the checksum according to the %_content table */ |
| 148115 | if( rc==SQLITE_OK ){ |
| 148116 | sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule; |
| 148117 | sqlite3_stmt *pStmt = 0; |
| 148118 | char *zSql; |
| 148119 | |
| @@ -147693,11 +148206,11 @@ | |
| 148206 | Fts3Table *p /* FTS3 table handle */ |
| 148207 | ){ |
| 148208 | int rc; |
| 148209 | int bOk = 0; |
| 148210 | rc = fts3IntegrityCheck(p, &bOk); |
| 148211 | if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB; |
| 148212 | return rc; |
| 148213 | } |
| 148214 | |
| 148215 | /* |
| 148216 | ** Handle a 'special' INSERT of the form: |
| @@ -148131,10 +148644,11 @@ | |
| 148644 | #define FTS3_MATCHINFO_NDOC 'n' /* 1 value */ |
| 148645 | #define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */ |
| 148646 | #define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */ |
| 148647 | #define FTS3_MATCHINFO_LCS 's' /* nCol values */ |
| 148648 | #define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */ |
| 148649 | #define FTS3_MATCHINFO_LHITS 'y' /* nCol*nPhrase values */ |
| 148650 | |
| 148651 | /* |
| 148652 | ** The default value for the second argument to matchinfo(). |
| 148653 | */ |
| 148654 | #define FTS3_MATCHINFO_DEFAULT "pcx" |
| @@ -148912,10 +149426,55 @@ | |
| 149426 | } |
| 149427 | } |
| 149428 | |
| 149429 | return rc; |
| 149430 | } |
| 149431 | |
| 149432 | /* |
| 149433 | ** fts3ExprIterate() callback used to gather information for the matchinfo |
| 149434 | ** directive 'y'. |
| 149435 | */ |
| 149436 | static int fts3ExprLHitsCb( |
| 149437 | Fts3Expr *pExpr, /* Phrase expression node */ |
| 149438 | int iPhrase, /* Phrase number */ |
| 149439 | void *pCtx /* Pointer to MatchInfo structure */ |
| 149440 | ){ |
| 149441 | MatchInfo *p = (MatchInfo *)pCtx; |
| 149442 | Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab; |
| 149443 | int rc = SQLITE_OK; |
| 149444 | int iStart = iPhrase * p->nCol; |
| 149445 | Fts3Expr *pEof; /* Ancestor node already at EOF */ |
| 149446 | |
| 149447 | /* This must be a phrase */ |
| 149448 | assert( pExpr->pPhrase ); |
| 149449 | |
| 149450 | /* Initialize all output integers to zero. */ |
| 149451 | memset(&p->aMatchinfo[iStart], 0, sizeof(u32) * p->nCol); |
| 149452 | |
| 149453 | /* Check if this or any parent node is at EOF. If so, then all output |
| 149454 | ** values are zero. */ |
| 149455 | for(pEof=pExpr; pEof && pEof->bEof==0; pEof=pEof->pParent); |
| 149456 | |
| 149457 | if( pEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){ |
| 149458 | Fts3Phrase *pPhrase = pExpr->pPhrase; |
| 149459 | char *pIter = pPhrase->doclist.pList; |
| 149460 | int iCol = 0; |
| 149461 | |
| 149462 | while( 1 ){ |
| 149463 | int nHit = fts3ColumnlistCount(&pIter); |
| 149464 | if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){ |
| 149465 | p->aMatchinfo[iStart + iCol] = (u32)nHit; |
| 149466 | } |
| 149467 | assert( *pIter==0x00 || *pIter==0x01 ); |
| 149468 | if( *pIter!=0x01 ) break; |
| 149469 | pIter++; |
| 149470 | pIter += fts3GetVarint32(pIter, &iCol); |
| 149471 | } |
| 149472 | } |
| 149473 | |
| 149474 | return rc; |
| 149475 | } |
| 149476 | |
| 149477 | static int fts3MatchinfoCheck( |
| 149478 | Fts3Table *pTab, |
| 149479 | char cArg, |
| 149480 | char **pzErr |
| @@ -148925,14 +149484,15 @@ | |
| 149484 | || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4) |
| 149485 | || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4) |
| 149486 | || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize) |
| 149487 | || (cArg==FTS3_MATCHINFO_LCS) |
| 149488 | || (cArg==FTS3_MATCHINFO_HITS) |
| 149489 | || (cArg==FTS3_MATCHINFO_LHITS) |
| 149490 | ){ |
| 149491 | return SQLITE_OK; |
| 149492 | } |
| 149493 | sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg); |
| 149494 | return SQLITE_ERROR; |
| 149495 | } |
| 149496 | |
| 149497 | static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){ |
| 149498 | int nVal; /* Number of integers output by cArg */ |
| @@ -148947,10 +149507,14 @@ | |
| 149507 | case FTS3_MATCHINFO_AVGLENGTH: |
| 149508 | case FTS3_MATCHINFO_LENGTH: |
| 149509 | case FTS3_MATCHINFO_LCS: |
| 149510 | nVal = pInfo->nCol; |
| 149511 | break; |
| 149512 | |
| 149513 | case FTS3_MATCHINFO_LHITS: |
| 149514 | nVal = pInfo->nCol * pInfo->nPhrase; |
| 149515 | break; |
| 149516 | |
| 149517 | default: |
| 149518 | assert( cArg==FTS3_MATCHINFO_HITS ); |
| 149519 | nVal = pInfo->nCol * pInfo->nPhrase * 3; |
| 149520 | break; |
| @@ -149201,10 +149765,14 @@ | |
| 149765 | rc = fts3ExprLoadDoclists(pCsr, 0, 0); |
| 149766 | if( rc==SQLITE_OK ){ |
| 149767 | rc = fts3MatchinfoLcs(pCsr, pInfo); |
| 149768 | } |
| 149769 | break; |
| 149770 | |
| 149771 | case FTS3_MATCHINFO_LHITS: |
| 149772 | (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLHitsCb, (void*)pInfo); |
| 149773 | break; |
| 149774 | |
| 149775 | default: { |
| 149776 | Fts3Expr *pExpr; |
| 149777 | assert( zArg[i]==FTS3_MATCHINFO_HITS ); |
| 149778 | pExpr = pCsr->pExpr; |
| @@ -153214,15 +153782,23 @@ | |
| 153782 | ** conflict-handling mode specified by the user. |
| 153783 | */ |
| 153784 | if( nData>1 ){ |
| 153785 | int ii; |
| 153786 | |
| 153787 | /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. |
| 153788 | ** |
| 153789 | ** NB: nData can only be less than nDim*2+3 if the rtree is mis-declared |
| 153790 | ** with "column" that are interpreted as table constraints. |
| 153791 | ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5)); |
| 153792 | ** This problem was discovered after years of use, so we silently ignore |
| 153793 | ** these kinds of misdeclared tables to avoid breaking any legacy. |
| 153794 | */ |
| 153795 | assert( nData<=(pRtree->nDim*2 + 3) ); |
| 153796 | |
| 153797 | #ifndef SQLITE_RTREE_INT_ONLY |
| 153798 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 153799 | for(ii=0; ii<nData-4; ii+=2){ |
| 153800 | cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]); |
| 153801 | cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]); |
| 153802 | if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){ |
| 153803 | rc = SQLITE_CONSTRAINT; |
| 153804 | goto constraint; |
| @@ -153229,11 +153805,11 @@ | |
| 153805 | } |
| 153806 | } |
| 153807 | }else |
| 153808 | #endif |
| 153809 | { |
| 153810 | for(ii=0; ii<nData-4; ii+=2){ |
| 153811 | cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]); |
| 153812 | cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]); |
| 153813 | if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){ |
| 153814 | rc = SQLITE_CONSTRAINT; |
| 153815 | goto constraint; |
| @@ -154629,5 +155205,633 @@ | |
| 155205 | |
| 155206 | #endif /* defined(SQLITE_ENABLE_ICU) */ |
| 155207 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ |
| 155208 | |
| 155209 | /************** End of fts3_icu.c ********************************************/ |
| 155210 | /************** Begin file dbstat.c ******************************************/ |
| 155211 | /* |
| 155212 | ** 2010 July 12 |
| 155213 | ** |
| 155214 | ** The author disclaims copyright to this source code. In place of |
| 155215 | ** a legal notice, here is a blessing: |
| 155216 | ** |
| 155217 | ** May you do good and not evil. |
| 155218 | ** May you find forgiveness for yourself and forgive others. |
| 155219 | ** May you share freely, never taking more than you give. |
| 155220 | ** |
| 155221 | ****************************************************************************** |
| 155222 | ** |
| 155223 | ** This file contains an implementation of the "dbstat" virtual table. |
| 155224 | ** |
| 155225 | ** The dbstat virtual table is used to extract low-level formatting |
| 155226 | ** information from an SQLite database in order to implement the |
| 155227 | ** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script |
| 155228 | ** for an example implementation. |
| 155229 | */ |
| 155230 | |
| 155231 | #if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \ |
| 155232 | && !defined(SQLITE_OMIT_VIRTUAL_TABLE) |
| 155233 | |
| 155234 | /* |
| 155235 | ** Page paths: |
| 155236 | ** |
| 155237 | ** The value of the 'path' column describes the path taken from the |
| 155238 | ** root-node of the b-tree structure to each page. The value of the |
| 155239 | ** root-node path is '/'. |
| 155240 | ** |
| 155241 | ** The value of the path for the left-most child page of the root of |
| 155242 | ** a b-tree is '/000/'. (Btrees store content ordered from left to right |
| 155243 | ** so the pages to the left have smaller keys than the pages to the right.) |
| 155244 | ** The next to left-most child of the root page is |
| 155245 | ** '/001', and so on, each sibling page identified by a 3-digit hex |
| 155246 | ** value. The children of the 451st left-most sibling have paths such |
| 155247 | ** as '/1c2/000/, '/1c2/001/' etc. |
| 155248 | ** |
| 155249 | ** Overflow pages are specified by appending a '+' character and a |
| 155250 | ** six-digit hexadecimal value to the path to the cell they are linked |
| 155251 | ** from. For example, the three overflow pages in a chain linked from |
| 155252 | ** the left-most cell of the 450th child of the root page are identified |
| 155253 | ** by the paths: |
| 155254 | ** |
| 155255 | ** '/1c2/000+000000' // First page in overflow chain |
| 155256 | ** '/1c2/000+000001' // Second page in overflow chain |
| 155257 | ** '/1c2/000+000002' // Third page in overflow chain |
| 155258 | ** |
| 155259 | ** If the paths are sorted using the BINARY collation sequence, then |
| 155260 | ** the overflow pages associated with a cell will appear earlier in the |
| 155261 | ** sort-order than its child page: |
| 155262 | ** |
| 155263 | ** '/1c2/000/' // Left-most child of 451st child of root |
| 155264 | */ |
| 155265 | #define VTAB_SCHEMA \ |
| 155266 | "CREATE TABLE xx( " \ |
| 155267 | " name STRING, /* Name of table or index */" \ |
| 155268 | " path INTEGER, /* Path to page from root */" \ |
| 155269 | " pageno INTEGER, /* Page number */" \ |
| 155270 | " pagetype STRING, /* 'internal', 'leaf' or 'overflow' */" \ |
| 155271 | " ncell INTEGER, /* Cells on page (0 for overflow) */" \ |
| 155272 | " payload INTEGER, /* Bytes of payload on this page */" \ |
| 155273 | " unused INTEGER, /* Bytes of unused space on this page */" \ |
| 155274 | " mx_payload INTEGER, /* Largest payload size of all cells */" \ |
| 155275 | " pgoffset INTEGER, /* Offset of page in file */" \ |
| 155276 | " pgsize INTEGER /* Size of the page */" \ |
| 155277 | ");" |
| 155278 | |
| 155279 | |
| 155280 | typedef struct StatTable StatTable; |
| 155281 | typedef struct StatCursor StatCursor; |
| 155282 | typedef struct StatPage StatPage; |
| 155283 | typedef struct StatCell StatCell; |
| 155284 | |
| 155285 | struct StatCell { |
| 155286 | int nLocal; /* Bytes of local payload */ |
| 155287 | u32 iChildPg; /* Child node (or 0 if this is a leaf) */ |
| 155288 | int nOvfl; /* Entries in aOvfl[] */ |
| 155289 | u32 *aOvfl; /* Array of overflow page numbers */ |
| 155290 | int nLastOvfl; /* Bytes of payload on final overflow page */ |
| 155291 | int iOvfl; /* Iterates through aOvfl[] */ |
| 155292 | }; |
| 155293 | |
| 155294 | struct StatPage { |
| 155295 | u32 iPgno; |
| 155296 | DbPage *pPg; |
| 155297 | int iCell; |
| 155298 | |
| 155299 | char *zPath; /* Path to this page */ |
| 155300 | |
| 155301 | /* Variables populated by statDecodePage(): */ |
| 155302 | u8 flags; /* Copy of flags byte */ |
| 155303 | int nCell; /* Number of cells on page */ |
| 155304 | int nUnused; /* Number of unused bytes on page */ |
| 155305 | StatCell *aCell; /* Array of parsed cells */ |
| 155306 | u32 iRightChildPg; /* Right-child page number (or 0) */ |
| 155307 | int nMxPayload; /* Largest payload of any cell on this page */ |
| 155308 | }; |
| 155309 | |
| 155310 | struct StatCursor { |
| 155311 | sqlite3_vtab_cursor base; |
| 155312 | sqlite3_stmt *pStmt; /* Iterates through set of root pages */ |
| 155313 | int isEof; /* After pStmt has returned SQLITE_DONE */ |
| 155314 | |
| 155315 | StatPage aPage[32]; |
| 155316 | int iPage; /* Current entry in aPage[] */ |
| 155317 | |
| 155318 | /* Values to return. */ |
| 155319 | char *zName; /* Value of 'name' column */ |
| 155320 | char *zPath; /* Value of 'path' column */ |
| 155321 | u32 iPageno; /* Value of 'pageno' column */ |
| 155322 | char *zPagetype; /* Value of 'pagetype' column */ |
| 155323 | int nCell; /* Value of 'ncell' column */ |
| 155324 | int nPayload; /* Value of 'payload' column */ |
| 155325 | int nUnused; /* Value of 'unused' column */ |
| 155326 | int nMxPayload; /* Value of 'mx_payload' column */ |
| 155327 | i64 iOffset; /* Value of 'pgOffset' column */ |
| 155328 | int szPage; /* Value of 'pgSize' column */ |
| 155329 | }; |
| 155330 | |
| 155331 | struct StatTable { |
| 155332 | sqlite3_vtab base; |
| 155333 | sqlite3 *db; |
| 155334 | }; |
| 155335 | |
| 155336 | #ifndef get2byte |
| 155337 | # define get2byte(x) ((x)[0]<<8 | (x)[1]) |
| 155338 | #endif |
| 155339 | |
| 155340 | /* |
| 155341 | ** Connect to or create a statvfs virtual table. |
| 155342 | */ |
| 155343 | static int statConnect( |
| 155344 | sqlite3 *db, |
| 155345 | void *pAux, |
| 155346 | int argc, const char *const*argv, |
| 155347 | sqlite3_vtab **ppVtab, |
| 155348 | char **pzErr |
| 155349 | ){ |
| 155350 | StatTable *pTab = 0; |
| 155351 | int rc = SQLITE_OK; |
| 155352 | |
| 155353 | rc = sqlite3_declare_vtab(db, VTAB_SCHEMA); |
| 155354 | if( rc==SQLITE_OK ){ |
| 155355 | pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable)); |
| 155356 | if( pTab==0 ) rc = SQLITE_NOMEM; |
| 155357 | } |
| 155358 | |
| 155359 | assert( rc==SQLITE_OK || pTab==0 ); |
| 155360 | if( rc==SQLITE_OK ){ |
| 155361 | memset(pTab, 0, sizeof(StatTable)); |
| 155362 | pTab->db = db; |
| 155363 | } |
| 155364 | |
| 155365 | *ppVtab = (sqlite3_vtab*)pTab; |
| 155366 | return rc; |
| 155367 | } |
| 155368 | |
| 155369 | /* |
| 155370 | ** Disconnect from or destroy a statvfs virtual table. |
| 155371 | */ |
| 155372 | static int statDisconnect(sqlite3_vtab *pVtab){ |
| 155373 | sqlite3_free(pVtab); |
| 155374 | return SQLITE_OK; |
| 155375 | } |
| 155376 | |
| 155377 | /* |
| 155378 | ** There is no "best-index". This virtual table always does a linear |
| 155379 | ** scan of the binary VFS log file. |
| 155380 | */ |
| 155381 | static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ |
| 155382 | |
| 155383 | /* Records are always returned in ascending order of (name, path). |
| 155384 | ** If this will satisfy the client, set the orderByConsumed flag so that |
| 155385 | ** SQLite does not do an external sort. |
| 155386 | */ |
| 155387 | if( ( pIdxInfo->nOrderBy==1 |
| 155388 | && pIdxInfo->aOrderBy[0].iColumn==0 |
| 155389 | && pIdxInfo->aOrderBy[0].desc==0 |
| 155390 | ) || |
| 155391 | ( pIdxInfo->nOrderBy==2 |
| 155392 | && pIdxInfo->aOrderBy[0].iColumn==0 |
| 155393 | && pIdxInfo->aOrderBy[0].desc==0 |
| 155394 | && pIdxInfo->aOrderBy[1].iColumn==1 |
| 155395 | && pIdxInfo->aOrderBy[1].desc==0 |
| 155396 | ) |
| 155397 | ){ |
| 155398 | pIdxInfo->orderByConsumed = 1; |
| 155399 | } |
| 155400 | |
| 155401 | pIdxInfo->estimatedCost = 10.0; |
| 155402 | return SQLITE_OK; |
| 155403 | } |
| 155404 | |
| 155405 | /* |
| 155406 | ** Open a new statvfs cursor. |
| 155407 | */ |
| 155408 | static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ |
| 155409 | StatTable *pTab = (StatTable *)pVTab; |
| 155410 | StatCursor *pCsr; |
| 155411 | int rc; |
| 155412 | |
| 155413 | pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor)); |
| 155414 | if( pCsr==0 ){ |
| 155415 | rc = SQLITE_NOMEM; |
| 155416 | }else{ |
| 155417 | memset(pCsr, 0, sizeof(StatCursor)); |
| 155418 | pCsr->base.pVtab = pVTab; |
| 155419 | |
| 155420 | rc = sqlite3_prepare_v2(pTab->db, |
| 155421 | "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type" |
| 155422 | " UNION ALL " |
| 155423 | "SELECT name, rootpage, type FROM sqlite_master WHERE rootpage!=0" |
| 155424 | " ORDER BY name", -1, |
| 155425 | &pCsr->pStmt, 0 |
| 155426 | ); |
| 155427 | if( rc!=SQLITE_OK ){ |
| 155428 | sqlite3_free(pCsr); |
| 155429 | pCsr = 0; |
| 155430 | } |
| 155431 | } |
| 155432 | |
| 155433 | *ppCursor = (sqlite3_vtab_cursor *)pCsr; |
| 155434 | return rc; |
| 155435 | } |
| 155436 | |
| 155437 | static void statClearPage(StatPage *p){ |
| 155438 | int i; |
| 155439 | if( p->aCell ){ |
| 155440 | for(i=0; i<p->nCell; i++){ |
| 155441 | sqlite3_free(p->aCell[i].aOvfl); |
| 155442 | } |
| 155443 | sqlite3_free(p->aCell); |
| 155444 | } |
| 155445 | sqlite3PagerUnref(p->pPg); |
| 155446 | sqlite3_free(p->zPath); |
| 155447 | memset(p, 0, sizeof(StatPage)); |
| 155448 | } |
| 155449 | |
| 155450 | static void statResetCsr(StatCursor *pCsr){ |
| 155451 | int i; |
| 155452 | sqlite3_reset(pCsr->pStmt); |
| 155453 | for(i=0; i<ArraySize(pCsr->aPage); i++){ |
| 155454 | statClearPage(&pCsr->aPage[i]); |
| 155455 | } |
| 155456 | pCsr->iPage = 0; |
| 155457 | sqlite3_free(pCsr->zPath); |
| 155458 | pCsr->zPath = 0; |
| 155459 | } |
| 155460 | |
| 155461 | /* |
| 155462 | ** Close a statvfs cursor. |
| 155463 | */ |
| 155464 | static int statClose(sqlite3_vtab_cursor *pCursor){ |
| 155465 | StatCursor *pCsr = (StatCursor *)pCursor; |
| 155466 | statResetCsr(pCsr); |
| 155467 | sqlite3_finalize(pCsr->pStmt); |
| 155468 | sqlite3_free(pCsr); |
| 155469 | return SQLITE_OK; |
| 155470 | } |
| 155471 | |
| 155472 | static void getLocalPayload( |
| 155473 | int nUsable, /* Usable bytes per page */ |
| 155474 | u8 flags, /* Page flags */ |
| 155475 | int nTotal, /* Total record (payload) size */ |
| 155476 | int *pnLocal /* OUT: Bytes stored locally */ |
| 155477 | ){ |
| 155478 | int nLocal; |
| 155479 | int nMinLocal; |
| 155480 | int nMaxLocal; |
| 155481 | |
| 155482 | if( flags==0x0D ){ /* Table leaf node */ |
| 155483 | nMinLocal = (nUsable - 12) * 32 / 255 - 23; |
| 155484 | nMaxLocal = nUsable - 35; |
| 155485 | }else{ /* Index interior and leaf nodes */ |
| 155486 | nMinLocal = (nUsable - 12) * 32 / 255 - 23; |
| 155487 | nMaxLocal = (nUsable - 12) * 64 / 255 - 23; |
| 155488 | } |
| 155489 | |
| 155490 | nLocal = nMinLocal + (nTotal - nMinLocal) % (nUsable - 4); |
| 155491 | if( nLocal>nMaxLocal ) nLocal = nMinLocal; |
| 155492 | *pnLocal = nLocal; |
| 155493 | } |
| 155494 | |
| 155495 | static int statDecodePage(Btree *pBt, StatPage *p){ |
| 155496 | int nUnused; |
| 155497 | int iOff; |
| 155498 | int nHdr; |
| 155499 | int isLeaf; |
| 155500 | int szPage; |
| 155501 | |
| 155502 | u8 *aData = sqlite3PagerGetData(p->pPg); |
| 155503 | u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0]; |
| 155504 | |
| 155505 | p->flags = aHdr[0]; |
| 155506 | p->nCell = get2byte(&aHdr[3]); |
| 155507 | p->nMxPayload = 0; |
| 155508 | |
| 155509 | isLeaf = (p->flags==0x0A || p->flags==0x0D); |
| 155510 | nHdr = 12 - isLeaf*4 + (p->iPgno==1)*100; |
| 155511 | |
| 155512 | nUnused = get2byte(&aHdr[5]) - nHdr - 2*p->nCell; |
| 155513 | nUnused += (int)aHdr[7]; |
| 155514 | iOff = get2byte(&aHdr[1]); |
| 155515 | while( iOff ){ |
| 155516 | nUnused += get2byte(&aData[iOff+2]); |
| 155517 | iOff = get2byte(&aData[iOff]); |
| 155518 | } |
| 155519 | p->nUnused = nUnused; |
| 155520 | p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]); |
| 155521 | szPage = sqlite3BtreeGetPageSize(pBt); |
| 155522 | |
| 155523 | if( p->nCell ){ |
| 155524 | int i; /* Used to iterate through cells */ |
| 155525 | int nUsable; /* Usable bytes per page */ |
| 155526 | |
| 155527 | sqlite3BtreeEnter(pBt); |
| 155528 | nUsable = szPage - sqlite3BtreeGetReserveNoMutex(pBt); |
| 155529 | sqlite3BtreeLeave(pBt); |
| 155530 | p->aCell = sqlite3_malloc64((p->nCell+1) * sizeof(StatCell)); |
| 155531 | if( p->aCell==0 ) return SQLITE_NOMEM; |
| 155532 | memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell)); |
| 155533 | |
| 155534 | for(i=0; i<p->nCell; i++){ |
| 155535 | StatCell *pCell = &p->aCell[i]; |
| 155536 | |
| 155537 | iOff = get2byte(&aData[nHdr+i*2]); |
| 155538 | if( !isLeaf ){ |
| 155539 | pCell->iChildPg = sqlite3Get4byte(&aData[iOff]); |
| 155540 | iOff += 4; |
| 155541 | } |
| 155542 | if( p->flags==0x05 ){ |
| 155543 | /* A table interior node. nPayload==0. */ |
| 155544 | }else{ |
| 155545 | u32 nPayload; /* Bytes of payload total (local+overflow) */ |
| 155546 | int nLocal; /* Bytes of payload stored locally */ |
| 155547 | iOff += getVarint32(&aData[iOff], nPayload); |
| 155548 | if( p->flags==0x0D ){ |
| 155549 | u64 dummy; |
| 155550 | iOff += sqlite3GetVarint(&aData[iOff], &dummy); |
| 155551 | } |
| 155552 | if( nPayload>(u32)p->nMxPayload ) p->nMxPayload = nPayload; |
| 155553 | getLocalPayload(nUsable, p->flags, nPayload, &nLocal); |
| 155554 | pCell->nLocal = nLocal; |
| 155555 | assert( nLocal>=0 ); |
| 155556 | assert( nPayload>=(u32)nLocal ); |
| 155557 | assert( nLocal<=(nUsable-35) ); |
| 155558 | if( nPayload>(u32)nLocal ){ |
| 155559 | int j; |
| 155560 | int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4); |
| 155561 | pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4); |
| 155562 | pCell->nOvfl = nOvfl; |
| 155563 | pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl); |
| 155564 | if( pCell->aOvfl==0 ) return SQLITE_NOMEM; |
| 155565 | pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]); |
| 155566 | for(j=1; j<nOvfl; j++){ |
| 155567 | int rc; |
| 155568 | u32 iPrev = pCell->aOvfl[j-1]; |
| 155569 | DbPage *pPg = 0; |
| 155570 | rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg); |
| 155571 | if( rc!=SQLITE_OK ){ |
| 155572 | assert( pPg==0 ); |
| 155573 | return rc; |
| 155574 | } |
| 155575 | pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg)); |
| 155576 | sqlite3PagerUnref(pPg); |
| 155577 | } |
| 155578 | } |
| 155579 | } |
| 155580 | } |
| 155581 | } |
| 155582 | |
| 155583 | return SQLITE_OK; |
| 155584 | } |
| 155585 | |
| 155586 | /* |
| 155587 | ** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on |
| 155588 | ** the current value of pCsr->iPageno. |
| 155589 | */ |
| 155590 | static void statSizeAndOffset(StatCursor *pCsr){ |
| 155591 | StatTable *pTab = (StatTable *)((sqlite3_vtab_cursor *)pCsr)->pVtab; |
| 155592 | Btree *pBt = pTab->db->aDb[0].pBt; |
| 155593 | Pager *pPager = sqlite3BtreePager(pBt); |
| 155594 | sqlite3_file *fd; |
| 155595 | sqlite3_int64 x[2]; |
| 155596 | |
| 155597 | /* The default page size and offset */ |
| 155598 | pCsr->szPage = sqlite3BtreeGetPageSize(pBt); |
| 155599 | pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1); |
| 155600 | |
| 155601 | /* If connected to a ZIPVFS backend, override the page size and |
| 155602 | ** offset with actual values obtained from ZIPVFS. |
| 155603 | */ |
| 155604 | fd = sqlite3PagerFile(pPager); |
| 155605 | x[0] = pCsr->iPageno; |
| 155606 | if( sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){ |
| 155607 | pCsr->iOffset = x[0]; |
| 155608 | pCsr->szPage = (int)x[1]; |
| 155609 | } |
| 155610 | } |
| 155611 | |
| 155612 | /* |
| 155613 | ** Move a statvfs cursor to the next entry in the file. |
| 155614 | */ |
| 155615 | static int statNext(sqlite3_vtab_cursor *pCursor){ |
| 155616 | int rc; |
| 155617 | int nPayload; |
| 155618 | StatCursor *pCsr = (StatCursor *)pCursor; |
| 155619 | StatTable *pTab = (StatTable *)pCursor->pVtab; |
| 155620 | Btree *pBt = pTab->db->aDb[0].pBt; |
| 155621 | Pager *pPager = sqlite3BtreePager(pBt); |
| 155622 | |
| 155623 | sqlite3_free(pCsr->zPath); |
| 155624 | pCsr->zPath = 0; |
| 155625 | |
| 155626 | statNextRestart: |
| 155627 | if( pCsr->aPage[0].pPg==0 ){ |
| 155628 | rc = sqlite3_step(pCsr->pStmt); |
| 155629 | if( rc==SQLITE_ROW ){ |
| 155630 | int nPage; |
| 155631 | u32 iRoot = (u32)sqlite3_column_int64(pCsr->pStmt, 1); |
| 155632 | sqlite3PagerPagecount(pPager, &nPage); |
| 155633 | if( nPage==0 ){ |
| 155634 | pCsr->isEof = 1; |
| 155635 | return sqlite3_reset(pCsr->pStmt); |
| 155636 | } |
| 155637 | rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg); |
| 155638 | pCsr->aPage[0].iPgno = iRoot; |
| 155639 | pCsr->aPage[0].iCell = 0; |
| 155640 | pCsr->aPage[0].zPath = sqlite3_mprintf("/"); |
| 155641 | pCsr->iPage = 0; |
| 155642 | }else{ |
| 155643 | pCsr->isEof = 1; |
| 155644 | return sqlite3_reset(pCsr->pStmt); |
| 155645 | } |
| 155646 | }else{ |
| 155647 | |
| 155648 | /* Page p itself has already been visited. */ |
| 155649 | StatPage *p = &pCsr->aPage[pCsr->iPage]; |
| 155650 | |
| 155651 | while( p->iCell<p->nCell ){ |
| 155652 | StatCell *pCell = &p->aCell[p->iCell]; |
| 155653 | if( pCell->iOvfl<pCell->nOvfl ){ |
| 155654 | int nUsable; |
| 155655 | sqlite3BtreeEnter(pBt); |
| 155656 | nUsable = sqlite3BtreeGetPageSize(pBt) - |
| 155657 | sqlite3BtreeGetReserveNoMutex(pBt); |
| 155658 | sqlite3BtreeLeave(pBt); |
| 155659 | pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0); |
| 155660 | pCsr->iPageno = pCell->aOvfl[pCell->iOvfl]; |
| 155661 | pCsr->zPagetype = "overflow"; |
| 155662 | pCsr->nCell = 0; |
| 155663 | pCsr->nMxPayload = 0; |
| 155664 | pCsr->zPath = sqlite3_mprintf( |
| 155665 | "%s%.3x+%.6x", p->zPath, p->iCell, pCell->iOvfl |
| 155666 | ); |
| 155667 | if( pCell->iOvfl<pCell->nOvfl-1 ){ |
| 155668 | pCsr->nUnused = 0; |
| 155669 | pCsr->nPayload = nUsable - 4; |
| 155670 | }else{ |
| 155671 | pCsr->nPayload = pCell->nLastOvfl; |
| 155672 | pCsr->nUnused = nUsable - 4 - pCsr->nPayload; |
| 155673 | } |
| 155674 | pCell->iOvfl++; |
| 155675 | statSizeAndOffset(pCsr); |
| 155676 | return SQLITE_OK; |
| 155677 | } |
| 155678 | if( p->iRightChildPg ) break; |
| 155679 | p->iCell++; |
| 155680 | } |
| 155681 | |
| 155682 | if( !p->iRightChildPg || p->iCell>p->nCell ){ |
| 155683 | statClearPage(p); |
| 155684 | if( pCsr->iPage==0 ) return statNext(pCursor); |
| 155685 | pCsr->iPage--; |
| 155686 | goto statNextRestart; /* Tail recursion */ |
| 155687 | } |
| 155688 | pCsr->iPage++; |
| 155689 | assert( p==&pCsr->aPage[pCsr->iPage-1] ); |
| 155690 | |
| 155691 | if( p->iCell==p->nCell ){ |
| 155692 | p[1].iPgno = p->iRightChildPg; |
| 155693 | }else{ |
| 155694 | p[1].iPgno = p->aCell[p->iCell].iChildPg; |
| 155695 | } |
| 155696 | rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg); |
| 155697 | p[1].iCell = 0; |
| 155698 | p[1].zPath = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell); |
| 155699 | p->iCell++; |
| 155700 | } |
| 155701 | |
| 155702 | |
| 155703 | /* Populate the StatCursor fields with the values to be returned |
| 155704 | ** by the xColumn() and xRowid() methods. |
| 155705 | */ |
| 155706 | if( rc==SQLITE_OK ){ |
| 155707 | int i; |
| 155708 | StatPage *p = &pCsr->aPage[pCsr->iPage]; |
| 155709 | pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0); |
| 155710 | pCsr->iPageno = p->iPgno; |
| 155711 | |
| 155712 | rc = statDecodePage(pBt, p); |
| 155713 | if( rc==SQLITE_OK ){ |
| 155714 | statSizeAndOffset(pCsr); |
| 155715 | |
| 155716 | switch( p->flags ){ |
| 155717 | case 0x05: /* table internal */ |
| 155718 | case 0x02: /* index internal */ |
| 155719 | pCsr->zPagetype = "internal"; |
| 155720 | break; |
| 155721 | case 0x0D: /* table leaf */ |
| 155722 | case 0x0A: /* index leaf */ |
| 155723 | pCsr->zPagetype = "leaf"; |
| 155724 | break; |
| 155725 | default: |
| 155726 | pCsr->zPagetype = "corrupted"; |
| 155727 | break; |
| 155728 | } |
| 155729 | pCsr->nCell = p->nCell; |
| 155730 | pCsr->nUnused = p->nUnused; |
| 155731 | pCsr->nMxPayload = p->nMxPayload; |
| 155732 | pCsr->zPath = sqlite3_mprintf("%s", p->zPath); |
| 155733 | nPayload = 0; |
| 155734 | for(i=0; i<p->nCell; i++){ |
| 155735 | nPayload += p->aCell[i].nLocal; |
| 155736 | } |
| 155737 | pCsr->nPayload = nPayload; |
| 155738 | } |
| 155739 | } |
| 155740 | |
| 155741 | return rc; |
| 155742 | } |
| 155743 | |
| 155744 | static int statEof(sqlite3_vtab_cursor *pCursor){ |
| 155745 | StatCursor *pCsr = (StatCursor *)pCursor; |
| 155746 | return pCsr->isEof; |
| 155747 | } |
| 155748 | |
| 155749 | static int statFilter( |
| 155750 | sqlite3_vtab_cursor *pCursor, |
| 155751 | int idxNum, const char *idxStr, |
| 155752 | int argc, sqlite3_value **argv |
| 155753 | ){ |
| 155754 | StatCursor *pCsr = (StatCursor *)pCursor; |
| 155755 | |
| 155756 | statResetCsr(pCsr); |
| 155757 | return statNext(pCursor); |
| 155758 | } |
| 155759 | |
| 155760 | static int statColumn( |
| 155761 | sqlite3_vtab_cursor *pCursor, |
| 155762 | sqlite3_context *ctx, |
| 155763 | int i |
| 155764 | ){ |
| 155765 | StatCursor *pCsr = (StatCursor *)pCursor; |
| 155766 | switch( i ){ |
| 155767 | case 0: /* name */ |
| 155768 | sqlite3_result_text(ctx, pCsr->zName, -1, SQLITE_STATIC); |
| 155769 | break; |
| 155770 | case 1: /* path */ |
| 155771 | sqlite3_result_text(ctx, pCsr->zPath, -1, SQLITE_TRANSIENT); |
| 155772 | break; |
| 155773 | case 2: /* pageno */ |
| 155774 | sqlite3_result_int64(ctx, pCsr->iPageno); |
| 155775 | break; |
| 155776 | case 3: /* pagetype */ |
| 155777 | sqlite3_result_text(ctx, pCsr->zPagetype, -1, SQLITE_STATIC); |
| 155778 | break; |
| 155779 | case 4: /* ncell */ |
| 155780 | sqlite3_result_int(ctx, pCsr->nCell); |
| 155781 | break; |
| 155782 | case 5: /* payload */ |
| 155783 | sqlite3_result_int(ctx, pCsr->nPayload); |
| 155784 | break; |
| 155785 | case 6: /* unused */ |
| 155786 | sqlite3_result_int(ctx, pCsr->nUnused); |
| 155787 | break; |
| 155788 | case 7: /* mx_payload */ |
| 155789 | sqlite3_result_int(ctx, pCsr->nMxPayload); |
| 155790 | break; |
| 155791 | case 8: /* pgoffset */ |
| 155792 | sqlite3_result_int64(ctx, pCsr->iOffset); |
| 155793 | break; |
| 155794 | case 9: /* pgsize */ |
| 155795 | sqlite3_result_int(ctx, pCsr->szPage); |
| 155796 | break; |
| 155797 | } |
| 155798 | return SQLITE_OK; |
| 155799 | } |
| 155800 | |
| 155801 | static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){ |
| 155802 | StatCursor *pCsr = (StatCursor *)pCursor; |
| 155803 | *pRowid = pCsr->iPageno; |
| 155804 | return SQLITE_OK; |
| 155805 | } |
| 155806 | |
| 155807 | /* |
| 155808 | ** Invoke this routine to register the "dbstat" virtual table module |
| 155809 | */ |
| 155810 | SQLITE_API int SQLITE_STDCALL sqlite3_dbstat_register(sqlite3 *db){ |
| 155811 | static sqlite3_module dbstat_module = { |
| 155812 | 0, /* iVersion */ |
| 155813 | statConnect, /* xCreate */ |
| 155814 | statConnect, /* xConnect */ |
| 155815 | statBestIndex, /* xBestIndex */ |
| 155816 | statDisconnect, /* xDisconnect */ |
| 155817 | statDisconnect, /* xDestroy */ |
| 155818 | statOpen, /* xOpen - open a cursor */ |
| 155819 | statClose, /* xClose - close a cursor */ |
| 155820 | statFilter, /* xFilter - configure scan constraints */ |
| 155821 | statNext, /* xNext - advance a cursor */ |
| 155822 | statEof, /* xEof - check for end of scan */ |
| 155823 | statColumn, /* xColumn - read data */ |
| 155824 | statRowid, /* xRowid - read data */ |
| 155825 | 0, /* xUpdate */ |
| 155826 | 0, /* xBegin */ |
| 155827 | 0, /* xSync */ |
| 155828 | 0, /* xCommit */ |
| 155829 | 0, /* xRollback */ |
| 155830 | 0, /* xFindMethod */ |
| 155831 | 0, /* xRename */ |
| 155832 | }; |
| 155833 | return sqlite3_create_module(db, "dbstat", &dbstat_module, 0); |
| 155834 | } |
| 155835 | #endif /* SQLITE_ENABLE_DBSTAT_VTAB */ |
| 155836 | |
| 155837 | /************** End of dbstat.c **********************************************/ |
| 155838 |
+91
-15
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -109,13 +109,13 @@ | ||
| 109 | 109 | ** |
| 110 | 110 | ** See also: [sqlite3_libversion()], |
| 111 | 111 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 112 | 112 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 113 | 113 | */ |
| 114 | -#define SQLITE_VERSION "3.8.9" | |
| 115 | -#define SQLITE_VERSION_NUMBER 3008009 | |
| 116 | -#define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09" | |
| 114 | +#define SQLITE_VERSION "3.8.10" | |
| 115 | +#define SQLITE_VERSION_NUMBER 3008010 | |
| 116 | +#define SQLITE_SOURCE_ID "2015-05-04 19:13:25 850c11866686a7b39d7b163fb60898c11283688e" | |
| 117 | 117 | |
| 118 | 118 | /* |
| 119 | 119 | ** CAPI3REF: Run-Time Library Version Numbers |
| 120 | 120 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 121 | 121 | ** |
| @@ -268,10 +268,11 @@ | ||
| 268 | 268 | # define double sqlite3_int64 |
| 269 | 269 | #endif |
| 270 | 270 | |
| 271 | 271 | /* |
| 272 | 272 | ** CAPI3REF: Closing A Database Connection |
| 273 | +** DESTRUCTOR: sqlite3 | |
| 273 | 274 | ** |
| 274 | 275 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 275 | 276 | ** for the [sqlite3] object. |
| 276 | 277 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
| 277 | 278 | ** the [sqlite3] object is successfully destroyed and all associated |
| @@ -319,10 +320,11 @@ | ||
| 319 | 320 | */ |
| 320 | 321 | typedef int (*sqlite3_callback)(void*,int,char**, char**); |
| 321 | 322 | |
| 322 | 323 | /* |
| 323 | 324 | ** CAPI3REF: One-Step Query Execution Interface |
| 325 | +** METHOD: sqlite3 | |
| 324 | 326 | ** |
| 325 | 327 | ** The sqlite3_exec() interface is a convenience wrapper around |
| 326 | 328 | ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], |
| 327 | 329 | ** that allows an application to run multiple statements of SQL |
| 328 | 330 | ** without having to use a lot of C code. |
| @@ -1376,10 +1378,11 @@ | ||
| 1376 | 1378 | */ |
| 1377 | 1379 | SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...); |
| 1378 | 1380 | |
| 1379 | 1381 | /* |
| 1380 | 1382 | ** CAPI3REF: Configure database connections |
| 1383 | +** METHOD: sqlite3 | |
| 1381 | 1384 | ** |
| 1382 | 1385 | ** The sqlite3_db_config() interface is used to make configuration |
| 1383 | 1386 | ** changes to a [database connection]. The interface is similar to |
| 1384 | 1387 | ** [sqlite3_config()] except that the changes apply to a single |
| 1385 | 1388 | ** [database connection] (specified in the first argument). |
| @@ -1873,19 +1876,21 @@ | ||
| 1873 | 1876 | #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ |
| 1874 | 1877 | |
| 1875 | 1878 | |
| 1876 | 1879 | /* |
| 1877 | 1880 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
| 1881 | +** METHOD: sqlite3 | |
| 1878 | 1882 | ** |
| 1879 | 1883 | ** ^The sqlite3_extended_result_codes() routine enables or disables the |
| 1880 | 1884 | ** [extended result codes] feature of SQLite. ^The extended result |
| 1881 | 1885 | ** codes are disabled by default for historical compatibility. |
| 1882 | 1886 | */ |
| 1883 | 1887 | SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff); |
| 1884 | 1888 | |
| 1885 | 1889 | /* |
| 1886 | 1890 | ** CAPI3REF: Last Insert Rowid |
| 1891 | +** METHOD: sqlite3 | |
| 1887 | 1892 | ** |
| 1888 | 1893 | ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) |
| 1889 | 1894 | ** has a unique 64-bit signed |
| 1890 | 1895 | ** integer key called the [ROWID | "rowid"]. ^The rowid is always available |
| 1891 | 1896 | ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those |
| @@ -1933,10 +1938,11 @@ | ||
| 1933 | 1938 | */ |
| 1934 | 1939 | SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*); |
| 1935 | 1940 | |
| 1936 | 1941 | /* |
| 1937 | 1942 | ** CAPI3REF: Count The Number Of Rows Modified |
| 1943 | +** METHOD: sqlite3 | |
| 1938 | 1944 | ** |
| 1939 | 1945 | ** ^This function returns the number of rows modified, inserted or |
| 1940 | 1946 | ** deleted by the most recently completed INSERT, UPDATE or DELETE |
| 1941 | 1947 | ** statement on the database connection specified by the only parameter. |
| 1942 | 1948 | ** ^Executing any other type of SQL statement does not modify the value |
| @@ -1985,10 +1991,11 @@ | ||
| 1985 | 1991 | */ |
| 1986 | 1992 | SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*); |
| 1987 | 1993 | |
| 1988 | 1994 | /* |
| 1989 | 1995 | ** CAPI3REF: Total Number Of Rows Modified |
| 1996 | +** METHOD: sqlite3 | |
| 1990 | 1997 | ** |
| 1991 | 1998 | ** ^This function returns the total number of rows inserted, modified or |
| 1992 | 1999 | ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
| 1993 | 2000 | ** since the database connection was opened, including those executed as |
| 1994 | 2001 | ** part of trigger programs. ^Executing any other type of SQL statement |
| @@ -2008,10 +2015,11 @@ | ||
| 2008 | 2015 | */ |
| 2009 | 2016 | SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*); |
| 2010 | 2017 | |
| 2011 | 2018 | /* |
| 2012 | 2019 | ** CAPI3REF: Interrupt A Long-Running Query |
| 2020 | +** METHOD: sqlite3 | |
| 2013 | 2021 | ** |
| 2014 | 2022 | ** ^This function causes any pending database operation to abort and |
| 2015 | 2023 | ** return at its earliest opportunity. This routine is typically |
| 2016 | 2024 | ** called in response to a user action such as pressing "Cancel" |
| 2017 | 2025 | ** or Ctrl-C where the user wants a long query operation to halt |
| @@ -2084,10 +2092,11 @@ | ||
| 2084 | 2092 | SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql); |
| 2085 | 2093 | |
| 2086 | 2094 | /* |
| 2087 | 2095 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2088 | 2096 | ** KEYWORDS: {busy-handler callback} {busy handler} |
| 2097 | +** METHOD: sqlite3 | |
| 2089 | 2098 | ** |
| 2090 | 2099 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2091 | 2100 | ** that might be invoked with argument P whenever |
| 2092 | 2101 | ** an attempt is made to access a database table associated with |
| 2093 | 2102 | ** [database connection] D when another thread |
| @@ -2143,10 +2152,11 @@ | ||
| 2143 | 2152 | */ |
| 2144 | 2153 | SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); |
| 2145 | 2154 | |
| 2146 | 2155 | /* |
| 2147 | 2156 | ** CAPI3REF: Set A Busy Timeout |
| 2157 | +** METHOD: sqlite3 | |
| 2148 | 2158 | ** |
| 2149 | 2159 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2150 | 2160 | ** for a specified amount of time when a table is locked. ^The handler |
| 2151 | 2161 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2152 | 2162 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| @@ -2165,10 +2175,11 @@ | ||
| 2165 | 2175 | */ |
| 2166 | 2176 | SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms); |
| 2167 | 2177 | |
| 2168 | 2178 | /* |
| 2169 | 2179 | ** CAPI3REF: Convenience Routines For Running Queries |
| 2180 | +** METHOD: sqlite3 | |
| 2170 | 2181 | ** |
| 2171 | 2182 | ** This is a legacy interface that is preserved for backwards compatibility. |
| 2172 | 2183 | ** Use of this interface is not recommended. |
| 2173 | 2184 | ** |
| 2174 | 2185 | ** Definition: A <b>result table</b> is memory data structure created by the |
| @@ -2500,10 +2511,11 @@ | ||
| 2500 | 2511 | */ |
| 2501 | 2512 | SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P); |
| 2502 | 2513 | |
| 2503 | 2514 | /* |
| 2504 | 2515 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2516 | +** METHOD: sqlite3 | |
| 2505 | 2517 | ** |
| 2506 | 2518 | ** ^This routine registers an authorizer callback with a particular |
| 2507 | 2519 | ** [database connection], supplied in the first argument. |
| 2508 | 2520 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2509 | 2521 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| @@ -2656,10 +2668,11 @@ | ||
| 2656 | 2668 | #define SQLITE_COPY 0 /* No longer used */ |
| 2657 | 2669 | #define SQLITE_RECURSIVE 33 /* NULL NULL */ |
| 2658 | 2670 | |
| 2659 | 2671 | /* |
| 2660 | 2672 | ** CAPI3REF: Tracing And Profiling Functions |
| 2673 | +** METHOD: sqlite3 | |
| 2661 | 2674 | ** |
| 2662 | 2675 | ** These routines register callback functions that can be used for |
| 2663 | 2676 | ** tracing and profiling the execution of SQL statements. |
| 2664 | 2677 | ** |
| 2665 | 2678 | ** ^The callback function registered by sqlite3_trace() is invoked at |
| @@ -2688,10 +2701,11 @@ | ||
| 2688 | 2701 | SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*, |
| 2689 | 2702 | void(*xProfile)(void*,const char*,sqlite3_uint64), void*); |
| 2690 | 2703 | |
| 2691 | 2704 | /* |
| 2692 | 2705 | ** CAPI3REF: Query Progress Callbacks |
| 2706 | +** METHOD: sqlite3 | |
| 2693 | 2707 | ** |
| 2694 | 2708 | ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback |
| 2695 | 2709 | ** function X to be invoked periodically during long running calls to |
| 2696 | 2710 | ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for |
| 2697 | 2711 | ** database connection D. An example use for this |
| @@ -2721,10 +2735,11 @@ | ||
| 2721 | 2735 | */ |
| 2722 | 2736 | SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2723 | 2737 | |
| 2724 | 2738 | /* |
| 2725 | 2739 | ** CAPI3REF: Opening A New Database Connection |
| 2740 | +** CONSTRUCTOR: sqlite3 | |
| 2726 | 2741 | ** |
| 2727 | 2742 | ** ^These routines open an SQLite database file as specified by the |
| 2728 | 2743 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2729 | 2744 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2730 | 2745 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| @@ -3006,10 +3021,11 @@ | ||
| 3006 | 3021 | SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64); |
| 3007 | 3022 | |
| 3008 | 3023 | |
| 3009 | 3024 | /* |
| 3010 | 3025 | ** CAPI3REF: Error Codes And Messages |
| 3026 | +** METHOD: sqlite3 | |
| 3011 | 3027 | ** |
| 3012 | 3028 | ** ^If the most recent sqlite3_* API call associated with |
| 3013 | 3029 | ** [database connection] D failed, then the sqlite3_errcode(D) interface |
| 3014 | 3030 | ** returns the numeric [result code] or [extended result code] for that |
| 3015 | 3031 | ** API call. |
| @@ -3051,37 +3067,38 @@ | ||
| 3051 | 3067 | SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*); |
| 3052 | 3068 | SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*); |
| 3053 | 3069 | SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int); |
| 3054 | 3070 | |
| 3055 | 3071 | /* |
| 3056 | -** CAPI3REF: SQL Statement Object | |
| 3072 | +** CAPI3REF: Prepared Statement Object | |
| 3057 | 3073 | ** KEYWORDS: {prepared statement} {prepared statements} |
| 3058 | 3074 | ** |
| 3059 | -** An instance of this object represents a single SQL statement. | |
| 3060 | -** This object is variously known as a "prepared statement" or a | |
| 3061 | -** "compiled SQL statement" or simply as a "statement". | |
| 3075 | +** An instance of this object represents a single SQL statement that | |
| 3076 | +** has been compiled into binary form and is ready to be evaluated. | |
| 3062 | 3077 | ** |
| 3063 | -** The life of a statement object goes something like this: | |
| 3078 | +** Think of each SQL statement as a separate computer program. The | |
| 3079 | +** original SQL text is source code. A prepared statement object | |
| 3080 | +** is the compiled object code. All SQL must be converted into a | |
| 3081 | +** prepared statement before it can be run. | |
| 3082 | +** | |
| 3083 | +** The life-cycle of a prepared statement object usually goes like this: | |
| 3064 | 3084 | ** |
| 3065 | 3085 | ** <ol> |
| 3066 | -** <li> Create the object using [sqlite3_prepare_v2()] or a related | |
| 3067 | -** function. | |
| 3068 | -** <li> Bind values to [host parameters] using the sqlite3_bind_*() | |
| 3086 | +** <li> Create the prepared statement object using [sqlite3_prepare_v2()]. | |
| 3087 | +** <li> Bind values to [parameters] using the sqlite3_bind_*() | |
| 3069 | 3088 | ** interfaces. |
| 3070 | 3089 | ** <li> Run the SQL by calling [sqlite3_step()] one or more times. |
| 3071 | -** <li> Reset the statement using [sqlite3_reset()] then go back | |
| 3090 | +** <li> Reset the prepared statement using [sqlite3_reset()] then go back | |
| 3072 | 3091 | ** to step 2. Do this zero or more times. |
| 3073 | 3092 | ** <li> Destroy the object using [sqlite3_finalize()]. |
| 3074 | 3093 | ** </ol> |
| 3075 | -** | |
| 3076 | -** Refer to documentation on individual methods above for additional | |
| 3077 | -** information. | |
| 3078 | 3094 | */ |
| 3079 | 3095 | typedef struct sqlite3_stmt sqlite3_stmt; |
| 3080 | 3096 | |
| 3081 | 3097 | /* |
| 3082 | 3098 | ** CAPI3REF: Run-time Limits |
| 3099 | +** METHOD: sqlite3 | |
| 3083 | 3100 | ** |
| 3084 | 3101 | ** ^(This interface allows the size of various constructs to be limited |
| 3085 | 3102 | ** on a connection by connection basis. The first parameter is the |
| 3086 | 3103 | ** [database connection] whose limit is to be set or queried. The |
| 3087 | 3104 | ** second parameter is one of the [limit categories] that define a |
| @@ -3189,10 +3206,12 @@ | ||
| 3189 | 3206 | #define SQLITE_LIMIT_WORKER_THREADS 11 |
| 3190 | 3207 | |
| 3191 | 3208 | /* |
| 3192 | 3209 | ** CAPI3REF: Compiling An SQL Statement |
| 3193 | 3210 | ** KEYWORDS: {SQL statement compiler} |
| 3211 | +** METHOD: sqlite3 | |
| 3212 | +** CONSTRUCTOR: sqlite3_stmt | |
| 3194 | 3213 | ** |
| 3195 | 3214 | ** To execute an SQL query, it must first be compiled into a byte-code |
| 3196 | 3215 | ** program using one of these routines. |
| 3197 | 3216 | ** |
| 3198 | 3217 | ** The first argument, "db", is a [database connection] obtained from a |
| @@ -3296,19 +3315,21 @@ | ||
| 3296 | 3315 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3297 | 3316 | ); |
| 3298 | 3317 | |
| 3299 | 3318 | /* |
| 3300 | 3319 | ** CAPI3REF: Retrieving Statement SQL |
| 3320 | +** METHOD: sqlite3_stmt | |
| 3301 | 3321 | ** |
| 3302 | 3322 | ** ^This interface can be used to retrieve a saved copy of the original |
| 3303 | 3323 | ** SQL text used to create a [prepared statement] if that statement was |
| 3304 | 3324 | ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. |
| 3305 | 3325 | */ |
| 3306 | 3326 | SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt); |
| 3307 | 3327 | |
| 3308 | 3328 | /* |
| 3309 | 3329 | ** CAPI3REF: Determine If An SQL Statement Writes The Database |
| 3330 | +** METHOD: sqlite3_stmt | |
| 3310 | 3331 | ** |
| 3311 | 3332 | ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if |
| 3312 | 3333 | ** and only if the [prepared statement] X makes no direct changes to |
| 3313 | 3334 | ** the content of the database file. |
| 3314 | 3335 | ** |
| @@ -3336,10 +3357,11 @@ | ||
| 3336 | 3357 | */ |
| 3337 | 3358 | SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
| 3338 | 3359 | |
| 3339 | 3360 | /* |
| 3340 | 3361 | ** CAPI3REF: Determine If A Prepared Statement Has Been Reset |
| 3362 | +** METHOD: sqlite3_stmt | |
| 3341 | 3363 | ** |
| 3342 | 3364 | ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the |
| 3343 | 3365 | ** [prepared statement] S has been stepped at least once using |
| 3344 | 3366 | ** [sqlite3_step(S)] but has not run to completion and/or has not |
| 3345 | 3367 | ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) |
| @@ -3410,10 +3432,11 @@ | ||
| 3410 | 3432 | |
| 3411 | 3433 | /* |
| 3412 | 3434 | ** CAPI3REF: Binding Values To Prepared Statements |
| 3413 | 3435 | ** KEYWORDS: {host parameter} {host parameters} {host parameter name} |
| 3414 | 3436 | ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} |
| 3437 | +** METHOD: sqlite3_stmt | |
| 3415 | 3438 | ** |
| 3416 | 3439 | ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, |
| 3417 | 3440 | ** literals may be replaced by a [parameter] that matches one of following |
| 3418 | 3441 | ** templates: |
| 3419 | 3442 | ** |
| @@ -3528,10 +3551,11 @@ | ||
| 3528 | 3551 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); |
| 3529 | 3552 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
| 3530 | 3553 | |
| 3531 | 3554 | /* |
| 3532 | 3555 | ** CAPI3REF: Number Of SQL Parameters |
| 3556 | +** METHOD: sqlite3_stmt | |
| 3533 | 3557 | ** |
| 3534 | 3558 | ** ^This routine can be used to find the number of [SQL parameters] |
| 3535 | 3559 | ** in a [prepared statement]. SQL parameters are tokens of the |
| 3536 | 3560 | ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as |
| 3537 | 3561 | ** placeholders for values that are [sqlite3_bind_blob | bound] |
| @@ -3548,10 +3572,11 @@ | ||
| 3548 | 3572 | */ |
| 3549 | 3573 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*); |
| 3550 | 3574 | |
| 3551 | 3575 | /* |
| 3552 | 3576 | ** CAPI3REF: Name Of A Host Parameter |
| 3577 | +** METHOD: sqlite3_stmt | |
| 3553 | 3578 | ** |
| 3554 | 3579 | ** ^The sqlite3_bind_parameter_name(P,N) interface returns |
| 3555 | 3580 | ** the name of the N-th [SQL parameter] in the [prepared statement] P. |
| 3556 | 3581 | ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| 3557 | 3582 | ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| @@ -3575,10 +3600,11 @@ | ||
| 3575 | 3600 | */ |
| 3576 | 3601 | SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int); |
| 3577 | 3602 | |
| 3578 | 3603 | /* |
| 3579 | 3604 | ** CAPI3REF: Index Of A Parameter With A Given Name |
| 3605 | +** METHOD: sqlite3_stmt | |
| 3580 | 3606 | ** |
| 3581 | 3607 | ** ^Return the index of an SQL parameter given its name. ^The |
| 3582 | 3608 | ** index value returned is suitable for use as the second |
| 3583 | 3609 | ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero |
| 3584 | 3610 | ** is returned if no matching parameter is found. ^The parameter |
| @@ -3591,19 +3617,21 @@ | ||
| 3591 | 3617 | */ |
| 3592 | 3618 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3593 | 3619 | |
| 3594 | 3620 | /* |
| 3595 | 3621 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| 3622 | +** METHOD: sqlite3_stmt | |
| 3596 | 3623 | ** |
| 3597 | 3624 | ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset |
| 3598 | 3625 | ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. |
| 3599 | 3626 | ** ^Use this routine to reset all host parameters to NULL. |
| 3600 | 3627 | */ |
| 3601 | 3628 | SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*); |
| 3602 | 3629 | |
| 3603 | 3630 | /* |
| 3604 | 3631 | ** CAPI3REF: Number Of Columns In A Result Set |
| 3632 | +** METHOD: sqlite3_stmt | |
| 3605 | 3633 | ** |
| 3606 | 3634 | ** ^Return the number of columns in the result set returned by the |
| 3607 | 3635 | ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL |
| 3608 | 3636 | ** statement that does not return data (for example an [UPDATE]). |
| 3609 | 3637 | ** |
| @@ -3611,10 +3639,11 @@ | ||
| 3611 | 3639 | */ |
| 3612 | 3640 | SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt); |
| 3613 | 3641 | |
| 3614 | 3642 | /* |
| 3615 | 3643 | ** CAPI3REF: Column Names In A Result Set |
| 3644 | +** METHOD: sqlite3_stmt | |
| 3616 | 3645 | ** |
| 3617 | 3646 | ** ^These routines return the name assigned to a particular column |
| 3618 | 3647 | ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() |
| 3619 | 3648 | ** interface returns a pointer to a zero-terminated UTF-8 string |
| 3620 | 3649 | ** and sqlite3_column_name16() returns a pointer to a zero-terminated |
| @@ -3640,10 +3669,11 @@ | ||
| 3640 | 3669 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N); |
| 3641 | 3670 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N); |
| 3642 | 3671 | |
| 3643 | 3672 | /* |
| 3644 | 3673 | ** CAPI3REF: Source Of Data In A Query Result |
| 3674 | +** METHOD: sqlite3_stmt | |
| 3645 | 3675 | ** |
| 3646 | 3676 | ** ^These routines provide a means to determine the database, table, and |
| 3647 | 3677 | ** table column that is the origin of a particular result column in |
| 3648 | 3678 | ** [SELECT] statement. |
| 3649 | 3679 | ** ^The name of the database or table or column can be returned as |
| @@ -3692,10 +3722,11 @@ | ||
| 3692 | 3722 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int); |
| 3693 | 3723 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int); |
| 3694 | 3724 | |
| 3695 | 3725 | /* |
| 3696 | 3726 | ** CAPI3REF: Declared Datatype Of A Query Result |
| 3727 | +** METHOD: sqlite3_stmt | |
| 3697 | 3728 | ** |
| 3698 | 3729 | ** ^(The first parameter is a [prepared statement]. |
| 3699 | 3730 | ** If this statement is a [SELECT] statement and the Nth column of the |
| 3700 | 3731 | ** returned result set of that [SELECT] is a table column (not an |
| 3701 | 3732 | ** expression or subquery) then the declared type of the table |
| @@ -3724,10 +3755,11 @@ | ||
| 3724 | 3755 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int); |
| 3725 | 3756 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int); |
| 3726 | 3757 | |
| 3727 | 3758 | /* |
| 3728 | 3759 | ** CAPI3REF: Evaluate An SQL Statement |
| 3760 | +** METHOD: sqlite3_stmt | |
| 3729 | 3761 | ** |
| 3730 | 3762 | ** After a [prepared statement] has been prepared using either |
| 3731 | 3763 | ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy |
| 3732 | 3764 | ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function |
| 3733 | 3765 | ** must be called one or more times to evaluate the statement. |
| @@ -3803,10 +3835,11 @@ | ||
| 3803 | 3835 | */ |
| 3804 | 3836 | SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*); |
| 3805 | 3837 | |
| 3806 | 3838 | /* |
| 3807 | 3839 | ** CAPI3REF: Number of columns in a result set |
| 3840 | +** METHOD: sqlite3_stmt | |
| 3808 | 3841 | ** |
| 3809 | 3842 | ** ^The sqlite3_data_count(P) interface returns the number of columns in the |
| 3810 | 3843 | ** current row of the result set of [prepared statement] P. |
| 3811 | 3844 | ** ^If prepared statement P does not have results ready to return |
| 3812 | 3845 | ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of |
| @@ -3856,10 +3889,11 @@ | ||
| 3856 | 3889 | #define SQLITE3_TEXT 3 |
| 3857 | 3890 | |
| 3858 | 3891 | /* |
| 3859 | 3892 | ** CAPI3REF: Result Values From A Query |
| 3860 | 3893 | ** KEYWORDS: {column access functions} |
| 3894 | +** METHOD: sqlite3_stmt | |
| 3861 | 3895 | ** |
| 3862 | 3896 | ** These routines form the "result set" interface. |
| 3863 | 3897 | ** |
| 3864 | 3898 | ** ^These routines return information about a single column of the current |
| 3865 | 3899 | ** result row of a query. ^In every case the first argument is a pointer |
| @@ -4028,10 +4062,11 @@ | ||
| 4028 | 4062 | SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol); |
| 4029 | 4063 | SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol); |
| 4030 | 4064 | |
| 4031 | 4065 | /* |
| 4032 | 4066 | ** CAPI3REF: Destroy A Prepared Statement Object |
| 4067 | +** DESTRUCTOR: sqlite3_stmt | |
| 4033 | 4068 | ** |
| 4034 | 4069 | ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. |
| 4035 | 4070 | ** ^If the most recent evaluation of the statement encountered no errors |
| 4036 | 4071 | ** or if the statement is never been evaluated, then sqlite3_finalize() returns |
| 4037 | 4072 | ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then |
| @@ -4055,10 +4090,11 @@ | ||
| 4055 | 4090 | */ |
| 4056 | 4091 | SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt); |
| 4057 | 4092 | |
| 4058 | 4093 | /* |
| 4059 | 4094 | ** CAPI3REF: Reset A Prepared Statement Object |
| 4095 | +** METHOD: sqlite3_stmt | |
| 4060 | 4096 | ** |
| 4061 | 4097 | ** The sqlite3_reset() function is called to reset a [prepared statement] |
| 4062 | 4098 | ** object back to its initial state, ready to be re-executed. |
| 4063 | 4099 | ** ^Any SQL statement variables that had values bound to them using |
| 4064 | 4100 | ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. |
| @@ -4084,10 +4120,11 @@ | ||
| 4084 | 4120 | /* |
| 4085 | 4121 | ** CAPI3REF: Create Or Redefine SQL Functions |
| 4086 | 4122 | ** KEYWORDS: {function creation routines} |
| 4087 | 4123 | ** KEYWORDS: {application-defined SQL function} |
| 4088 | 4124 | ** KEYWORDS: {application-defined SQL functions} |
| 4125 | +** METHOD: sqlite3 | |
| 4089 | 4126 | ** |
| 4090 | 4127 | ** ^These functions (collectively known as "function creation routines") |
| 4091 | 4128 | ** are used to add SQL functions or aggregates or to redefine the behavior |
| 4092 | 4129 | ** of existing SQL functions or aggregates. The only differences between |
| 4093 | 4130 | ** these routines are the text encoding expected for |
| @@ -4253,10 +4290,11 @@ | ||
| 4253 | 4290 | void*,sqlite3_int64); |
| 4254 | 4291 | #endif |
| 4255 | 4292 | |
| 4256 | 4293 | /* |
| 4257 | 4294 | ** CAPI3REF: Obtaining SQL Function Parameter Values |
| 4295 | +** METHOD: sqlite3_value | |
| 4258 | 4296 | ** |
| 4259 | 4297 | ** The C-language implementation of SQL functions and aggregates uses |
| 4260 | 4298 | ** this set of interface routines to access the parameter values on |
| 4261 | 4299 | ** the function or aggregate. |
| 4262 | 4300 | ** |
| @@ -4311,10 +4349,11 @@ | ||
| 4311 | 4349 | SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*); |
| 4312 | 4350 | SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*); |
| 4313 | 4351 | |
| 4314 | 4352 | /* |
| 4315 | 4353 | ** CAPI3REF: Obtain Aggregate Function Context |
| 4354 | +** METHOD: sqlite3_context | |
| 4316 | 4355 | ** |
| 4317 | 4356 | ** Implementations of aggregate SQL functions use this |
| 4318 | 4357 | ** routine to allocate memory for storing their state. |
| 4319 | 4358 | ** |
| 4320 | 4359 | ** ^The first time the sqlite3_aggregate_context(C,N) routine is called |
| @@ -4355,10 +4394,11 @@ | ||
| 4355 | 4394 | */ |
| 4356 | 4395 | SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes); |
| 4357 | 4396 | |
| 4358 | 4397 | /* |
| 4359 | 4398 | ** CAPI3REF: User Data For Functions |
| 4399 | +** METHOD: sqlite3_context | |
| 4360 | 4400 | ** |
| 4361 | 4401 | ** ^The sqlite3_user_data() interface returns a copy of |
| 4362 | 4402 | ** the pointer that was the pUserData parameter (the 5th parameter) |
| 4363 | 4403 | ** of the [sqlite3_create_function()] |
| 4364 | 4404 | ** and [sqlite3_create_function16()] routines that originally |
| @@ -4369,10 +4409,11 @@ | ||
| 4369 | 4409 | */ |
| 4370 | 4410 | SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*); |
| 4371 | 4411 | |
| 4372 | 4412 | /* |
| 4373 | 4413 | ** CAPI3REF: Database Connection For Functions |
| 4414 | +** METHOD: sqlite3_context | |
| 4374 | 4415 | ** |
| 4375 | 4416 | ** ^The sqlite3_context_db_handle() interface returns a copy of |
| 4376 | 4417 | ** the pointer to the [database connection] (the 1st parameter) |
| 4377 | 4418 | ** of the [sqlite3_create_function()] |
| 4378 | 4419 | ** and [sqlite3_create_function16()] routines that originally |
| @@ -4380,10 +4421,11 @@ | ||
| 4380 | 4421 | */ |
| 4381 | 4422 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*); |
| 4382 | 4423 | |
| 4383 | 4424 | /* |
| 4384 | 4425 | ** CAPI3REF: Function Auxiliary Data |
| 4426 | +** METHOD: sqlite3_context | |
| 4385 | 4427 | ** |
| 4386 | 4428 | ** These functions may be used by (non-aggregate) SQL functions to |
| 4387 | 4429 | ** associate metadata with argument values. If the same value is passed to |
| 4388 | 4430 | ** multiple invocations of the same SQL function during query execution, under |
| 4389 | 4431 | ** some circumstances the associated metadata may be preserved. An example |
| @@ -4452,10 +4494,11 @@ | ||
| 4452 | 4494 | #define SQLITE_STATIC ((sqlite3_destructor_type)0) |
| 4453 | 4495 | #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) |
| 4454 | 4496 | |
| 4455 | 4497 | /* |
| 4456 | 4498 | ** CAPI3REF: Setting The Result Of An SQL Function |
| 4499 | +** METHOD: sqlite3_context | |
| 4457 | 4500 | ** |
| 4458 | 4501 | ** These routines are used by the xFunc or xFinal callbacks that |
| 4459 | 4502 | ** implement SQL functions and aggregates. See |
| 4460 | 4503 | ** [sqlite3_create_function()] and [sqlite3_create_function16()] |
| 4461 | 4504 | ** for additional information. |
| @@ -4587,10 +4630,11 @@ | ||
| 4587 | 4630 | SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*); |
| 4588 | 4631 | SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n); |
| 4589 | 4632 | |
| 4590 | 4633 | /* |
| 4591 | 4634 | ** CAPI3REF: Define New Collating Sequences |
| 4635 | +** METHOD: sqlite3 | |
| 4592 | 4636 | ** |
| 4593 | 4637 | ** ^These functions add, remove, or modify a [collation] associated |
| 4594 | 4638 | ** with the [database connection] specified as the first argument. |
| 4595 | 4639 | ** |
| 4596 | 4640 | ** ^The name of the collation is a UTF-8 string |
| @@ -4689,10 +4733,11 @@ | ||
| 4689 | 4733 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 4690 | 4734 | ); |
| 4691 | 4735 | |
| 4692 | 4736 | /* |
| 4693 | 4737 | ** CAPI3REF: Collation Needed Callbacks |
| 4738 | +** METHOD: sqlite3 | |
| 4694 | 4739 | ** |
| 4695 | 4740 | ** ^To avoid having to register all collation sequences before a database |
| 4696 | 4741 | ** can be used, a single callback function may be registered with the |
| 4697 | 4742 | ** [database connection] to be invoked whenever an undefined collation |
| 4698 | 4743 | ** sequence is required. |
| @@ -4896,10 +4941,11 @@ | ||
| 4896 | 4941 | SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory; |
| 4897 | 4942 | |
| 4898 | 4943 | /* |
| 4899 | 4944 | ** CAPI3REF: Test For Auto-Commit Mode |
| 4900 | 4945 | ** KEYWORDS: {autocommit mode} |
| 4946 | +** METHOD: sqlite3 | |
| 4901 | 4947 | ** |
| 4902 | 4948 | ** ^The sqlite3_get_autocommit() interface returns non-zero or |
| 4903 | 4949 | ** zero if the given database connection is or is not in autocommit mode, |
| 4904 | 4950 | ** respectively. ^Autocommit mode is on by default. |
| 4905 | 4951 | ** ^Autocommit mode is disabled by a [BEGIN] statement. |
| @@ -4918,10 +4964,11 @@ | ||
| 4918 | 4964 | */ |
| 4919 | 4965 | SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*); |
| 4920 | 4966 | |
| 4921 | 4967 | /* |
| 4922 | 4968 | ** CAPI3REF: Find The Database Handle Of A Prepared Statement |
| 4969 | +** METHOD: sqlite3_stmt | |
| 4923 | 4970 | ** |
| 4924 | 4971 | ** ^The sqlite3_db_handle interface returns the [database connection] handle |
| 4925 | 4972 | ** to which a [prepared statement] belongs. ^The [database connection] |
| 4926 | 4973 | ** returned by sqlite3_db_handle is the same [database connection] |
| 4927 | 4974 | ** that was the first argument |
| @@ -4930,10 +4977,11 @@ | ||
| 4930 | 4977 | */ |
| 4931 | 4978 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*); |
| 4932 | 4979 | |
| 4933 | 4980 | /* |
| 4934 | 4981 | ** CAPI3REF: Return The Filename For A Database Connection |
| 4982 | +** METHOD: sqlite3 | |
| 4935 | 4983 | ** |
| 4936 | 4984 | ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename |
| 4937 | 4985 | ** associated with database N of connection D. ^The main database file |
| 4938 | 4986 | ** has the name "main". If there is no attached database N on the database |
| 4939 | 4987 | ** connection D, or if database N is a temporary or in-memory database, then |
| @@ -4946,19 +4994,21 @@ | ||
| 4946 | 4994 | */ |
| 4947 | 4995 | SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
| 4948 | 4996 | |
| 4949 | 4997 | /* |
| 4950 | 4998 | ** CAPI3REF: Determine if a database is read-only |
| 4999 | +** METHOD: sqlite3 | |
| 4951 | 5000 | ** |
| 4952 | 5001 | ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N |
| 4953 | 5002 | ** of connection D is read-only, 0 if it is read/write, or -1 if N is not |
| 4954 | 5003 | ** the name of a database on connection D. |
| 4955 | 5004 | */ |
| 4956 | 5005 | SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName); |
| 4957 | 5006 | |
| 4958 | 5007 | /* |
| 4959 | 5008 | ** CAPI3REF: Find the next prepared statement |
| 5009 | +** METHOD: sqlite3 | |
| 4960 | 5010 | ** |
| 4961 | 5011 | ** ^This interface returns a pointer to the next [prepared statement] after |
| 4962 | 5012 | ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL |
| 4963 | 5013 | ** then this interface returns a pointer to the first prepared statement |
| 4964 | 5014 | ** associated with the database connection pDb. ^If no prepared statement |
| @@ -4970,10 +5020,11 @@ | ||
| 4970 | 5020 | */ |
| 4971 | 5021 | SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); |
| 4972 | 5022 | |
| 4973 | 5023 | /* |
| 4974 | 5024 | ** CAPI3REF: Commit And Rollback Notification Callbacks |
| 5025 | +** METHOD: sqlite3 | |
| 4975 | 5026 | ** |
| 4976 | 5027 | ** ^The sqlite3_commit_hook() interface registers a callback |
| 4977 | 5028 | ** function to be invoked whenever a transaction is [COMMIT | committed]. |
| 4978 | 5029 | ** ^Any callback set by a previous call to sqlite3_commit_hook() |
| 4979 | 5030 | ** for the same database connection is overridden. |
| @@ -5019,10 +5070,11 @@ | ||
| 5019 | 5070 | SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); |
| 5020 | 5071 | SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); |
| 5021 | 5072 | |
| 5022 | 5073 | /* |
| 5023 | 5074 | ** CAPI3REF: Data Change Notification Callbacks |
| 5075 | +** METHOD: sqlite3 | |
| 5024 | 5076 | ** |
| 5025 | 5077 | ** ^The sqlite3_update_hook() interface registers a callback function |
| 5026 | 5078 | ** with the [database connection] identified by the first argument |
| 5027 | 5079 | ** to be invoked whenever a row is updated, inserted or deleted in |
| 5028 | 5080 | ** a rowid table. |
| @@ -5125,10 +5177,11 @@ | ||
| 5125 | 5177 | */ |
| 5126 | 5178 | SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int); |
| 5127 | 5179 | |
| 5128 | 5180 | /* |
| 5129 | 5181 | ** CAPI3REF: Free Memory Used By A Database Connection |
| 5182 | +** METHOD: sqlite3 | |
| 5130 | 5183 | ** |
| 5131 | 5184 | ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap |
| 5132 | 5185 | ** memory as possible from database connection D. Unlike the |
| 5133 | 5186 | ** [sqlite3_release_memory()] interface, this interface is in effect even |
| 5134 | 5187 | ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is |
| @@ -5202,10 +5255,11 @@ | ||
| 5202 | 5255 | SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N); |
| 5203 | 5256 | |
| 5204 | 5257 | |
| 5205 | 5258 | /* |
| 5206 | 5259 | ** CAPI3REF: Extract Metadata About A Column Of A Table |
| 5260 | +** METHOD: sqlite3 | |
| 5207 | 5261 | ** |
| 5208 | 5262 | ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns |
| 5209 | 5263 | ** information about column C of table T in database D |
| 5210 | 5264 | ** on [database connection] X.)^ ^The sqlite3_table_column_metadata() |
| 5211 | 5265 | ** interface returns SQLITE_OK and fills in the non-NULL pointers in |
| @@ -5280,10 +5334,11 @@ | ||
| 5280 | 5334 | int *pAutoinc /* OUTPUT: True if column is auto-increment */ |
| 5281 | 5335 | ); |
| 5282 | 5336 | |
| 5283 | 5337 | /* |
| 5284 | 5338 | ** CAPI3REF: Load An Extension |
| 5339 | +** METHOD: sqlite3 | |
| 5285 | 5340 | ** |
| 5286 | 5341 | ** ^This interface loads an SQLite extension library from the named file. |
| 5287 | 5342 | ** |
| 5288 | 5343 | ** ^The sqlite3_load_extension() interface attempts to load an |
| 5289 | 5344 | ** [SQLite extension] library contained in the file zFile. If |
| @@ -5321,10 +5376,11 @@ | ||
| 5321 | 5376 | char **pzErrMsg /* Put error message here if not 0 */ |
| 5322 | 5377 | ); |
| 5323 | 5378 | |
| 5324 | 5379 | /* |
| 5325 | 5380 | ** CAPI3REF: Enable Or Disable Extension Loading |
| 5381 | +** METHOD: sqlite3 | |
| 5326 | 5382 | ** |
| 5327 | 5383 | ** ^So as not to open security holes in older applications that are |
| 5328 | 5384 | ** unprepared to deal with [extension loading], and as a means of disabling |
| 5329 | 5385 | ** [extension loading] while evaluating user-entered SQL, the following API |
| 5330 | 5386 | ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. |
| @@ -5570,10 +5626,11 @@ | ||
| 5570 | 5626 | #define SQLITE_INDEX_CONSTRAINT_GE 32 |
| 5571 | 5627 | #define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
| 5572 | 5628 | |
| 5573 | 5629 | /* |
| 5574 | 5630 | ** CAPI3REF: Register A Virtual Table Implementation |
| 5631 | +** METHOD: sqlite3 | |
| 5575 | 5632 | ** |
| 5576 | 5633 | ** ^These routines are used to register a new [virtual table module] name. |
| 5577 | 5634 | ** ^Module names must be registered before |
| 5578 | 5635 | ** creating a new [virtual table] using the module and before using a |
| 5579 | 5636 | ** preexisting [virtual table] for the module. |
| @@ -5666,10 +5723,11 @@ | ||
| 5666 | 5723 | */ |
| 5667 | 5724 | SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL); |
| 5668 | 5725 | |
| 5669 | 5726 | /* |
| 5670 | 5727 | ** CAPI3REF: Overload A Function For A Virtual Table |
| 5728 | +** METHOD: sqlite3 | |
| 5671 | 5729 | ** |
| 5672 | 5730 | ** ^(Virtual tables can provide alternative implementations of functions |
| 5673 | 5731 | ** using the [xFindFunction] method of the [virtual table module]. |
| 5674 | 5732 | ** But global versions of those functions |
| 5675 | 5733 | ** must exist in order to be overloaded.)^ |
| @@ -5708,10 +5766,12 @@ | ||
| 5708 | 5766 | */ |
| 5709 | 5767 | typedef struct sqlite3_blob sqlite3_blob; |
| 5710 | 5768 | |
| 5711 | 5769 | /* |
| 5712 | 5770 | ** CAPI3REF: Open A BLOB For Incremental I/O |
| 5771 | +** METHOD: sqlite3 | |
| 5772 | +** CONSTRUCTOR: sqlite3_blob | |
| 5713 | 5773 | ** |
| 5714 | 5774 | ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located |
| 5715 | 5775 | ** in row iRow, column zColumn, table zTable in database zDb; |
| 5716 | 5776 | ** in other words, the same BLOB that would be selected by: |
| 5717 | 5777 | ** |
| @@ -5789,10 +5849,11 @@ | ||
| 5789 | 5849 | sqlite3_blob **ppBlob |
| 5790 | 5850 | ); |
| 5791 | 5851 | |
| 5792 | 5852 | /* |
| 5793 | 5853 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 5854 | +** METHOD: sqlite3_blob | |
| 5794 | 5855 | ** |
| 5795 | 5856 | ** ^This function is used to move an existing blob handle so that it points |
| 5796 | 5857 | ** to a different row of the same database table. ^The new row is identified |
| 5797 | 5858 | ** by the rowid value passed as the second argument. Only the row can be |
| 5798 | 5859 | ** changed. ^The database, table and column on which the blob handle is open |
| @@ -5813,10 +5874,11 @@ | ||
| 5813 | 5874 | */ |
| 5814 | 5875 | SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 5815 | 5876 | |
| 5816 | 5877 | /* |
| 5817 | 5878 | ** CAPI3REF: Close A BLOB Handle |
| 5879 | +** DESTRUCTOR: sqlite3_blob | |
| 5818 | 5880 | ** |
| 5819 | 5881 | ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed |
| 5820 | 5882 | ** unconditionally. Even if this routine returns an error code, the |
| 5821 | 5883 | ** handle is still closed.)^ |
| 5822 | 5884 | ** |
| @@ -5835,10 +5897,11 @@ | ||
| 5835 | 5897 | */ |
| 5836 | 5898 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *); |
| 5837 | 5899 | |
| 5838 | 5900 | /* |
| 5839 | 5901 | ** CAPI3REF: Return The Size Of An Open BLOB |
| 5902 | +** METHOD: sqlite3_blob | |
| 5840 | 5903 | ** |
| 5841 | 5904 | ** ^Returns the size in bytes of the BLOB accessible via the |
| 5842 | 5905 | ** successfully opened [BLOB handle] in its only argument. ^The |
| 5843 | 5906 | ** incremental blob I/O routines can only read or overwriting existing |
| 5844 | 5907 | ** blob content; they cannot change the size of a blob. |
| @@ -5850,10 +5913,11 @@ | ||
| 5850 | 5913 | */ |
| 5851 | 5914 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *); |
| 5852 | 5915 | |
| 5853 | 5916 | /* |
| 5854 | 5917 | ** CAPI3REF: Read Data From A BLOB Incrementally |
| 5918 | +** METHOD: sqlite3_blob | |
| 5855 | 5919 | ** |
| 5856 | 5920 | ** ^(This function is used to read data from an open [BLOB handle] into a |
| 5857 | 5921 | ** caller-supplied buffer. N bytes of data are copied into buffer Z |
| 5858 | 5922 | ** from the open BLOB, starting at offset iOffset.)^ |
| 5859 | 5923 | ** |
| @@ -5878,10 +5942,11 @@ | ||
| 5878 | 5942 | */ |
| 5879 | 5943 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 5880 | 5944 | |
| 5881 | 5945 | /* |
| 5882 | 5946 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 5947 | +** METHOD: sqlite3_blob | |
| 5883 | 5948 | ** |
| 5884 | 5949 | ** ^(This function is used to write data into an open [BLOB handle] from a |
| 5885 | 5950 | ** caller-supplied buffer. N bytes of data are copied from the buffer Z |
| 5886 | 5951 | ** into the open BLOB, starting at offset iOffset.)^ |
| 5887 | 5952 | ** |
| @@ -6205,10 +6270,11 @@ | ||
| 6205 | 6270 | #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ |
| 6206 | 6271 | #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ |
| 6207 | 6272 | |
| 6208 | 6273 | /* |
| 6209 | 6274 | ** CAPI3REF: Retrieve the mutex for a database connection |
| 6275 | +** METHOD: sqlite3 | |
| 6210 | 6276 | ** |
| 6211 | 6277 | ** ^This interface returns a pointer the [sqlite3_mutex] object that |
| 6212 | 6278 | ** serializes access to the [database connection] given in the argument |
| 6213 | 6279 | ** when the [threading mode] is Serialized. |
| 6214 | 6280 | ** ^If the [threading mode] is Single-thread or Multi-thread then this |
| @@ -6216,10 +6282,11 @@ | ||
| 6216 | 6282 | */ |
| 6217 | 6283 | SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*); |
| 6218 | 6284 | |
| 6219 | 6285 | /* |
| 6220 | 6286 | ** CAPI3REF: Low-Level Control Of Database Files |
| 6287 | +** METHOD: sqlite3 | |
| 6221 | 6288 | ** |
| 6222 | 6289 | ** ^The [sqlite3_file_control()] interface makes a direct call to the |
| 6223 | 6290 | ** xFileControl method for the [sqlite3_io_methods] object associated |
| 6224 | 6291 | ** with a particular database identified by the second argument. ^The |
| 6225 | 6292 | ** name of the database is "main" for the main database or "temp" for the |
| @@ -6432,10 +6499,11 @@ | ||
| 6432 | 6499 | #define SQLITE_STATUS_SCRATCH_SIZE 8 |
| 6433 | 6500 | #define SQLITE_STATUS_MALLOC_COUNT 9 |
| 6434 | 6501 | |
| 6435 | 6502 | /* |
| 6436 | 6503 | ** CAPI3REF: Database Connection Status |
| 6504 | +** METHOD: sqlite3 | |
| 6437 | 6505 | ** |
| 6438 | 6506 | ** ^This interface is used to retrieve runtime status information |
| 6439 | 6507 | ** about a single [database connection]. ^The first argument is the |
| 6440 | 6508 | ** database connection object to be interrogated. ^The second argument |
| 6441 | 6509 | ** is an integer constant, taken from the set of |
| @@ -6560,10 +6628,11 @@ | ||
| 6560 | 6628 | #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */ |
| 6561 | 6629 | |
| 6562 | 6630 | |
| 6563 | 6631 | /* |
| 6564 | 6632 | ** CAPI3REF: Prepared Statement Status |
| 6633 | +** METHOD: sqlite3_stmt | |
| 6565 | 6634 | ** |
| 6566 | 6635 | ** ^(Each prepared statement maintains various |
| 6567 | 6636 | ** [SQLITE_STMTSTATUS counters] that measure the number |
| 6568 | 6637 | ** of times it has performed specific operations.)^ These counters can |
| 6569 | 6638 | ** be used to monitor the performance characteristics of the prepared |
| @@ -7063,10 +7132,11 @@ | ||
| 7063 | 7132 | SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p); |
| 7064 | 7133 | SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p); |
| 7065 | 7134 | |
| 7066 | 7135 | /* |
| 7067 | 7136 | ** CAPI3REF: Unlock Notification |
| 7137 | +** METHOD: sqlite3 | |
| 7068 | 7138 | ** |
| 7069 | 7139 | ** ^When running in shared-cache mode, a database operation may fail with |
| 7070 | 7140 | ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or |
| 7071 | 7141 | ** individual tables within the shared-cache cannot be obtained. See |
| 7072 | 7142 | ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. |
| @@ -7233,10 +7303,11 @@ | ||
| 7233 | 7303 | */ |
| 7234 | 7304 | SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...); |
| 7235 | 7305 | |
| 7236 | 7306 | /* |
| 7237 | 7307 | ** CAPI3REF: Write-Ahead Log Commit Hook |
| 7308 | +** METHOD: sqlite3 | |
| 7238 | 7309 | ** |
| 7239 | 7310 | ** ^The [sqlite3_wal_hook()] function is used to register a callback that |
| 7240 | 7311 | ** is invoked each time data is committed to a database in wal mode. |
| 7241 | 7312 | ** |
| 7242 | 7313 | ** ^(The callback is invoked by SQLite after the commit has taken place and |
| @@ -7272,10 +7343,11 @@ | ||
| 7272 | 7343 | void* |
| 7273 | 7344 | ); |
| 7274 | 7345 | |
| 7275 | 7346 | /* |
| 7276 | 7347 | ** CAPI3REF: Configure an auto-checkpoint |
| 7348 | +** METHOD: sqlite3 | |
| 7277 | 7349 | ** |
| 7278 | 7350 | ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around |
| 7279 | 7351 | ** [sqlite3_wal_hook()] that causes any database on [database connection] D |
| 7280 | 7352 | ** to automatically [checkpoint] |
| 7281 | 7353 | ** after committing a transaction if there are N or |
| @@ -7302,10 +7374,11 @@ | ||
| 7302 | 7374 | */ |
| 7303 | 7375 | SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7304 | 7376 | |
| 7305 | 7377 | /* |
| 7306 | 7378 | ** CAPI3REF: Checkpoint a database |
| 7379 | +** METHOD: sqlite3 | |
| 7307 | 7380 | ** |
| 7308 | 7381 | ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to |
| 7309 | 7382 | ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ |
| 7310 | 7383 | ** |
| 7311 | 7384 | ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the |
| @@ -7323,10 +7396,11 @@ | ||
| 7323 | 7396 | */ |
| 7324 | 7397 | SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7325 | 7398 | |
| 7326 | 7399 | /* |
| 7327 | 7400 | ** CAPI3REF: Checkpoint a database |
| 7401 | +** METHOD: sqlite3 | |
| 7328 | 7402 | ** |
| 7329 | 7403 | ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint |
| 7330 | 7404 | ** operation on database X of [database connection] D in mode M. Status |
| 7331 | 7405 | ** information is written back into integers pointed to by L and C.)^ |
| 7332 | 7406 | ** ^(The M parameter must be a valid [checkpoint mode]:)^ |
| @@ -7577,10 +7651,11 @@ | ||
| 7577 | 7651 | #define SQLITE_SCANSTAT_EXPLAIN 4 |
| 7578 | 7652 | #define SQLITE_SCANSTAT_SELECTID 5 |
| 7579 | 7653 | |
| 7580 | 7654 | /* |
| 7581 | 7655 | ** CAPI3REF: Prepared Statement Scan Status |
| 7656 | +** METHOD: sqlite3_stmt | |
| 7582 | 7657 | ** |
| 7583 | 7658 | ** This interface returns information about the predicted and measured |
| 7584 | 7659 | ** performance for pStmt. Advanced applications can use this |
| 7585 | 7660 | ** interface to compare the predicted and the measured performance and |
| 7586 | 7661 | ** issue warnings and/or rerun [ANALYZE] if discrepancies are found. |
| @@ -7614,10 +7689,11 @@ | ||
| 7614 | 7689 | void *pOut /* Result written here */ |
| 7615 | 7690 | ); |
| 7616 | 7691 | |
| 7617 | 7692 | /* |
| 7618 | 7693 | ** CAPI3REF: Zero Scan-Status Counters |
| 7694 | +** METHOD: sqlite3_stmt | |
| 7619 | 7695 | ** |
| 7620 | 7696 | ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. |
| 7621 | 7697 | ** |
| 7622 | 7698 | ** This API is only available if the library is built with pre-processor |
| 7623 | 7699 | ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| 7624 | 7700 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -109,13 +109,13 @@ | |
| 109 | ** |
| 110 | ** See also: [sqlite3_libversion()], |
| 111 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 112 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 113 | */ |
| 114 | #define SQLITE_VERSION "3.8.9" |
| 115 | #define SQLITE_VERSION_NUMBER 3008009 |
| 116 | #define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09" |
| 117 | |
| 118 | /* |
| 119 | ** CAPI3REF: Run-Time Library Version Numbers |
| 120 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 121 | ** |
| @@ -268,10 +268,11 @@ | |
| 268 | # define double sqlite3_int64 |
| 269 | #endif |
| 270 | |
| 271 | /* |
| 272 | ** CAPI3REF: Closing A Database Connection |
| 273 | ** |
| 274 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 275 | ** for the [sqlite3] object. |
| 276 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
| 277 | ** the [sqlite3] object is successfully destroyed and all associated |
| @@ -319,10 +320,11 @@ | |
| 319 | */ |
| 320 | typedef int (*sqlite3_callback)(void*,int,char**, char**); |
| 321 | |
| 322 | /* |
| 323 | ** CAPI3REF: One-Step Query Execution Interface |
| 324 | ** |
| 325 | ** The sqlite3_exec() interface is a convenience wrapper around |
| 326 | ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], |
| 327 | ** that allows an application to run multiple statements of SQL |
| 328 | ** without having to use a lot of C code. |
| @@ -1376,10 +1378,11 @@ | |
| 1376 | */ |
| 1377 | SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...); |
| 1378 | |
| 1379 | /* |
| 1380 | ** CAPI3REF: Configure database connections |
| 1381 | ** |
| 1382 | ** The sqlite3_db_config() interface is used to make configuration |
| 1383 | ** changes to a [database connection]. The interface is similar to |
| 1384 | ** [sqlite3_config()] except that the changes apply to a single |
| 1385 | ** [database connection] (specified in the first argument). |
| @@ -1873,19 +1876,21 @@ | |
| 1873 | #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ |
| 1874 | |
| 1875 | |
| 1876 | /* |
| 1877 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
| 1878 | ** |
| 1879 | ** ^The sqlite3_extended_result_codes() routine enables or disables the |
| 1880 | ** [extended result codes] feature of SQLite. ^The extended result |
| 1881 | ** codes are disabled by default for historical compatibility. |
| 1882 | */ |
| 1883 | SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff); |
| 1884 | |
| 1885 | /* |
| 1886 | ** CAPI3REF: Last Insert Rowid |
| 1887 | ** |
| 1888 | ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) |
| 1889 | ** has a unique 64-bit signed |
| 1890 | ** integer key called the [ROWID | "rowid"]. ^The rowid is always available |
| 1891 | ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those |
| @@ -1933,10 +1938,11 @@ | |
| 1933 | */ |
| 1934 | SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*); |
| 1935 | |
| 1936 | /* |
| 1937 | ** CAPI3REF: Count The Number Of Rows Modified |
| 1938 | ** |
| 1939 | ** ^This function returns the number of rows modified, inserted or |
| 1940 | ** deleted by the most recently completed INSERT, UPDATE or DELETE |
| 1941 | ** statement on the database connection specified by the only parameter. |
| 1942 | ** ^Executing any other type of SQL statement does not modify the value |
| @@ -1985,10 +1991,11 @@ | |
| 1985 | */ |
| 1986 | SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*); |
| 1987 | |
| 1988 | /* |
| 1989 | ** CAPI3REF: Total Number Of Rows Modified |
| 1990 | ** |
| 1991 | ** ^This function returns the total number of rows inserted, modified or |
| 1992 | ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
| 1993 | ** since the database connection was opened, including those executed as |
| 1994 | ** part of trigger programs. ^Executing any other type of SQL statement |
| @@ -2008,10 +2015,11 @@ | |
| 2008 | */ |
| 2009 | SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*); |
| 2010 | |
| 2011 | /* |
| 2012 | ** CAPI3REF: Interrupt A Long-Running Query |
| 2013 | ** |
| 2014 | ** ^This function causes any pending database operation to abort and |
| 2015 | ** return at its earliest opportunity. This routine is typically |
| 2016 | ** called in response to a user action such as pressing "Cancel" |
| 2017 | ** or Ctrl-C where the user wants a long query operation to halt |
| @@ -2084,10 +2092,11 @@ | |
| 2084 | SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql); |
| 2085 | |
| 2086 | /* |
| 2087 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2088 | ** KEYWORDS: {busy-handler callback} {busy handler} |
| 2089 | ** |
| 2090 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2091 | ** that might be invoked with argument P whenever |
| 2092 | ** an attempt is made to access a database table associated with |
| 2093 | ** [database connection] D when another thread |
| @@ -2143,10 +2152,11 @@ | |
| 2143 | */ |
| 2144 | SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); |
| 2145 | |
| 2146 | /* |
| 2147 | ** CAPI3REF: Set A Busy Timeout |
| 2148 | ** |
| 2149 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2150 | ** for a specified amount of time when a table is locked. ^The handler |
| 2151 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2152 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| @@ -2165,10 +2175,11 @@ | |
| 2165 | */ |
| 2166 | SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms); |
| 2167 | |
| 2168 | /* |
| 2169 | ** CAPI3REF: Convenience Routines For Running Queries |
| 2170 | ** |
| 2171 | ** This is a legacy interface that is preserved for backwards compatibility. |
| 2172 | ** Use of this interface is not recommended. |
| 2173 | ** |
| 2174 | ** Definition: A <b>result table</b> is memory data structure created by the |
| @@ -2500,10 +2511,11 @@ | |
| 2500 | */ |
| 2501 | SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P); |
| 2502 | |
| 2503 | /* |
| 2504 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2505 | ** |
| 2506 | ** ^This routine registers an authorizer callback with a particular |
| 2507 | ** [database connection], supplied in the first argument. |
| 2508 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2509 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| @@ -2656,10 +2668,11 @@ | |
| 2656 | #define SQLITE_COPY 0 /* No longer used */ |
| 2657 | #define SQLITE_RECURSIVE 33 /* NULL NULL */ |
| 2658 | |
| 2659 | /* |
| 2660 | ** CAPI3REF: Tracing And Profiling Functions |
| 2661 | ** |
| 2662 | ** These routines register callback functions that can be used for |
| 2663 | ** tracing and profiling the execution of SQL statements. |
| 2664 | ** |
| 2665 | ** ^The callback function registered by sqlite3_trace() is invoked at |
| @@ -2688,10 +2701,11 @@ | |
| 2688 | SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*, |
| 2689 | void(*xProfile)(void*,const char*,sqlite3_uint64), void*); |
| 2690 | |
| 2691 | /* |
| 2692 | ** CAPI3REF: Query Progress Callbacks |
| 2693 | ** |
| 2694 | ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback |
| 2695 | ** function X to be invoked periodically during long running calls to |
| 2696 | ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for |
| 2697 | ** database connection D. An example use for this |
| @@ -2721,10 +2735,11 @@ | |
| 2721 | */ |
| 2722 | SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2723 | |
| 2724 | /* |
| 2725 | ** CAPI3REF: Opening A New Database Connection |
| 2726 | ** |
| 2727 | ** ^These routines open an SQLite database file as specified by the |
| 2728 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2729 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2730 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| @@ -3006,10 +3021,11 @@ | |
| 3006 | SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64); |
| 3007 | |
| 3008 | |
| 3009 | /* |
| 3010 | ** CAPI3REF: Error Codes And Messages |
| 3011 | ** |
| 3012 | ** ^If the most recent sqlite3_* API call associated with |
| 3013 | ** [database connection] D failed, then the sqlite3_errcode(D) interface |
| 3014 | ** returns the numeric [result code] or [extended result code] for that |
| 3015 | ** API call. |
| @@ -3051,37 +3067,38 @@ | |
| 3051 | SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*); |
| 3052 | SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*); |
| 3053 | SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int); |
| 3054 | |
| 3055 | /* |
| 3056 | ** CAPI3REF: SQL Statement Object |
| 3057 | ** KEYWORDS: {prepared statement} {prepared statements} |
| 3058 | ** |
| 3059 | ** An instance of this object represents a single SQL statement. |
| 3060 | ** This object is variously known as a "prepared statement" or a |
| 3061 | ** "compiled SQL statement" or simply as a "statement". |
| 3062 | ** |
| 3063 | ** The life of a statement object goes something like this: |
| 3064 | ** |
| 3065 | ** <ol> |
| 3066 | ** <li> Create the object using [sqlite3_prepare_v2()] or a related |
| 3067 | ** function. |
| 3068 | ** <li> Bind values to [host parameters] using the sqlite3_bind_*() |
| 3069 | ** interfaces. |
| 3070 | ** <li> Run the SQL by calling [sqlite3_step()] one or more times. |
| 3071 | ** <li> Reset the statement using [sqlite3_reset()] then go back |
| 3072 | ** to step 2. Do this zero or more times. |
| 3073 | ** <li> Destroy the object using [sqlite3_finalize()]. |
| 3074 | ** </ol> |
| 3075 | ** |
| 3076 | ** Refer to documentation on individual methods above for additional |
| 3077 | ** information. |
| 3078 | */ |
| 3079 | typedef struct sqlite3_stmt sqlite3_stmt; |
| 3080 | |
| 3081 | /* |
| 3082 | ** CAPI3REF: Run-time Limits |
| 3083 | ** |
| 3084 | ** ^(This interface allows the size of various constructs to be limited |
| 3085 | ** on a connection by connection basis. The first parameter is the |
| 3086 | ** [database connection] whose limit is to be set or queried. The |
| 3087 | ** second parameter is one of the [limit categories] that define a |
| @@ -3189,10 +3206,12 @@ | |
| 3189 | #define SQLITE_LIMIT_WORKER_THREADS 11 |
| 3190 | |
| 3191 | /* |
| 3192 | ** CAPI3REF: Compiling An SQL Statement |
| 3193 | ** KEYWORDS: {SQL statement compiler} |
| 3194 | ** |
| 3195 | ** To execute an SQL query, it must first be compiled into a byte-code |
| 3196 | ** program using one of these routines. |
| 3197 | ** |
| 3198 | ** The first argument, "db", is a [database connection] obtained from a |
| @@ -3296,19 +3315,21 @@ | |
| 3296 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3297 | ); |
| 3298 | |
| 3299 | /* |
| 3300 | ** CAPI3REF: Retrieving Statement SQL |
| 3301 | ** |
| 3302 | ** ^This interface can be used to retrieve a saved copy of the original |
| 3303 | ** SQL text used to create a [prepared statement] if that statement was |
| 3304 | ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. |
| 3305 | */ |
| 3306 | SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt); |
| 3307 | |
| 3308 | /* |
| 3309 | ** CAPI3REF: Determine If An SQL Statement Writes The Database |
| 3310 | ** |
| 3311 | ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if |
| 3312 | ** and only if the [prepared statement] X makes no direct changes to |
| 3313 | ** the content of the database file. |
| 3314 | ** |
| @@ -3336,10 +3357,11 @@ | |
| 3336 | */ |
| 3337 | SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
| 3338 | |
| 3339 | /* |
| 3340 | ** CAPI3REF: Determine If A Prepared Statement Has Been Reset |
| 3341 | ** |
| 3342 | ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the |
| 3343 | ** [prepared statement] S has been stepped at least once using |
| 3344 | ** [sqlite3_step(S)] but has not run to completion and/or has not |
| 3345 | ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) |
| @@ -3410,10 +3432,11 @@ | |
| 3410 | |
| 3411 | /* |
| 3412 | ** CAPI3REF: Binding Values To Prepared Statements |
| 3413 | ** KEYWORDS: {host parameter} {host parameters} {host parameter name} |
| 3414 | ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} |
| 3415 | ** |
| 3416 | ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, |
| 3417 | ** literals may be replaced by a [parameter] that matches one of following |
| 3418 | ** templates: |
| 3419 | ** |
| @@ -3528,10 +3551,11 @@ | |
| 3528 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); |
| 3529 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
| 3530 | |
| 3531 | /* |
| 3532 | ** CAPI3REF: Number Of SQL Parameters |
| 3533 | ** |
| 3534 | ** ^This routine can be used to find the number of [SQL parameters] |
| 3535 | ** in a [prepared statement]. SQL parameters are tokens of the |
| 3536 | ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as |
| 3537 | ** placeholders for values that are [sqlite3_bind_blob | bound] |
| @@ -3548,10 +3572,11 @@ | |
| 3548 | */ |
| 3549 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*); |
| 3550 | |
| 3551 | /* |
| 3552 | ** CAPI3REF: Name Of A Host Parameter |
| 3553 | ** |
| 3554 | ** ^The sqlite3_bind_parameter_name(P,N) interface returns |
| 3555 | ** the name of the N-th [SQL parameter] in the [prepared statement] P. |
| 3556 | ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| 3557 | ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| @@ -3575,10 +3600,11 @@ | |
| 3575 | */ |
| 3576 | SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int); |
| 3577 | |
| 3578 | /* |
| 3579 | ** CAPI3REF: Index Of A Parameter With A Given Name |
| 3580 | ** |
| 3581 | ** ^Return the index of an SQL parameter given its name. ^The |
| 3582 | ** index value returned is suitable for use as the second |
| 3583 | ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero |
| 3584 | ** is returned if no matching parameter is found. ^The parameter |
| @@ -3591,19 +3617,21 @@ | |
| 3591 | */ |
| 3592 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3593 | |
| 3594 | /* |
| 3595 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| 3596 | ** |
| 3597 | ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset |
| 3598 | ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. |
| 3599 | ** ^Use this routine to reset all host parameters to NULL. |
| 3600 | */ |
| 3601 | SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*); |
| 3602 | |
| 3603 | /* |
| 3604 | ** CAPI3REF: Number Of Columns In A Result Set |
| 3605 | ** |
| 3606 | ** ^Return the number of columns in the result set returned by the |
| 3607 | ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL |
| 3608 | ** statement that does not return data (for example an [UPDATE]). |
| 3609 | ** |
| @@ -3611,10 +3639,11 @@ | |
| 3611 | */ |
| 3612 | SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt); |
| 3613 | |
| 3614 | /* |
| 3615 | ** CAPI3REF: Column Names In A Result Set |
| 3616 | ** |
| 3617 | ** ^These routines return the name assigned to a particular column |
| 3618 | ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() |
| 3619 | ** interface returns a pointer to a zero-terminated UTF-8 string |
| 3620 | ** and sqlite3_column_name16() returns a pointer to a zero-terminated |
| @@ -3640,10 +3669,11 @@ | |
| 3640 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N); |
| 3641 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N); |
| 3642 | |
| 3643 | /* |
| 3644 | ** CAPI3REF: Source Of Data In A Query Result |
| 3645 | ** |
| 3646 | ** ^These routines provide a means to determine the database, table, and |
| 3647 | ** table column that is the origin of a particular result column in |
| 3648 | ** [SELECT] statement. |
| 3649 | ** ^The name of the database or table or column can be returned as |
| @@ -3692,10 +3722,11 @@ | |
| 3692 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int); |
| 3693 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int); |
| 3694 | |
| 3695 | /* |
| 3696 | ** CAPI3REF: Declared Datatype Of A Query Result |
| 3697 | ** |
| 3698 | ** ^(The first parameter is a [prepared statement]. |
| 3699 | ** If this statement is a [SELECT] statement and the Nth column of the |
| 3700 | ** returned result set of that [SELECT] is a table column (not an |
| 3701 | ** expression or subquery) then the declared type of the table |
| @@ -3724,10 +3755,11 @@ | |
| 3724 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int); |
| 3725 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int); |
| 3726 | |
| 3727 | /* |
| 3728 | ** CAPI3REF: Evaluate An SQL Statement |
| 3729 | ** |
| 3730 | ** After a [prepared statement] has been prepared using either |
| 3731 | ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy |
| 3732 | ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function |
| 3733 | ** must be called one or more times to evaluate the statement. |
| @@ -3803,10 +3835,11 @@ | |
| 3803 | */ |
| 3804 | SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*); |
| 3805 | |
| 3806 | /* |
| 3807 | ** CAPI3REF: Number of columns in a result set |
| 3808 | ** |
| 3809 | ** ^The sqlite3_data_count(P) interface returns the number of columns in the |
| 3810 | ** current row of the result set of [prepared statement] P. |
| 3811 | ** ^If prepared statement P does not have results ready to return |
| 3812 | ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of |
| @@ -3856,10 +3889,11 @@ | |
| 3856 | #define SQLITE3_TEXT 3 |
| 3857 | |
| 3858 | /* |
| 3859 | ** CAPI3REF: Result Values From A Query |
| 3860 | ** KEYWORDS: {column access functions} |
| 3861 | ** |
| 3862 | ** These routines form the "result set" interface. |
| 3863 | ** |
| 3864 | ** ^These routines return information about a single column of the current |
| 3865 | ** result row of a query. ^In every case the first argument is a pointer |
| @@ -4028,10 +4062,11 @@ | |
| 4028 | SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol); |
| 4029 | SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol); |
| 4030 | |
| 4031 | /* |
| 4032 | ** CAPI3REF: Destroy A Prepared Statement Object |
| 4033 | ** |
| 4034 | ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. |
| 4035 | ** ^If the most recent evaluation of the statement encountered no errors |
| 4036 | ** or if the statement is never been evaluated, then sqlite3_finalize() returns |
| 4037 | ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then |
| @@ -4055,10 +4090,11 @@ | |
| 4055 | */ |
| 4056 | SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt); |
| 4057 | |
| 4058 | /* |
| 4059 | ** CAPI3REF: Reset A Prepared Statement Object |
| 4060 | ** |
| 4061 | ** The sqlite3_reset() function is called to reset a [prepared statement] |
| 4062 | ** object back to its initial state, ready to be re-executed. |
| 4063 | ** ^Any SQL statement variables that had values bound to them using |
| 4064 | ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. |
| @@ -4084,10 +4120,11 @@ | |
| 4084 | /* |
| 4085 | ** CAPI3REF: Create Or Redefine SQL Functions |
| 4086 | ** KEYWORDS: {function creation routines} |
| 4087 | ** KEYWORDS: {application-defined SQL function} |
| 4088 | ** KEYWORDS: {application-defined SQL functions} |
| 4089 | ** |
| 4090 | ** ^These functions (collectively known as "function creation routines") |
| 4091 | ** are used to add SQL functions or aggregates or to redefine the behavior |
| 4092 | ** of existing SQL functions or aggregates. The only differences between |
| 4093 | ** these routines are the text encoding expected for |
| @@ -4253,10 +4290,11 @@ | |
| 4253 | void*,sqlite3_int64); |
| 4254 | #endif |
| 4255 | |
| 4256 | /* |
| 4257 | ** CAPI3REF: Obtaining SQL Function Parameter Values |
| 4258 | ** |
| 4259 | ** The C-language implementation of SQL functions and aggregates uses |
| 4260 | ** this set of interface routines to access the parameter values on |
| 4261 | ** the function or aggregate. |
| 4262 | ** |
| @@ -4311,10 +4349,11 @@ | |
| 4311 | SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*); |
| 4312 | SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*); |
| 4313 | |
| 4314 | /* |
| 4315 | ** CAPI3REF: Obtain Aggregate Function Context |
| 4316 | ** |
| 4317 | ** Implementations of aggregate SQL functions use this |
| 4318 | ** routine to allocate memory for storing their state. |
| 4319 | ** |
| 4320 | ** ^The first time the sqlite3_aggregate_context(C,N) routine is called |
| @@ -4355,10 +4394,11 @@ | |
| 4355 | */ |
| 4356 | SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes); |
| 4357 | |
| 4358 | /* |
| 4359 | ** CAPI3REF: User Data For Functions |
| 4360 | ** |
| 4361 | ** ^The sqlite3_user_data() interface returns a copy of |
| 4362 | ** the pointer that was the pUserData parameter (the 5th parameter) |
| 4363 | ** of the [sqlite3_create_function()] |
| 4364 | ** and [sqlite3_create_function16()] routines that originally |
| @@ -4369,10 +4409,11 @@ | |
| 4369 | */ |
| 4370 | SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*); |
| 4371 | |
| 4372 | /* |
| 4373 | ** CAPI3REF: Database Connection For Functions |
| 4374 | ** |
| 4375 | ** ^The sqlite3_context_db_handle() interface returns a copy of |
| 4376 | ** the pointer to the [database connection] (the 1st parameter) |
| 4377 | ** of the [sqlite3_create_function()] |
| 4378 | ** and [sqlite3_create_function16()] routines that originally |
| @@ -4380,10 +4421,11 @@ | |
| 4380 | */ |
| 4381 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*); |
| 4382 | |
| 4383 | /* |
| 4384 | ** CAPI3REF: Function Auxiliary Data |
| 4385 | ** |
| 4386 | ** These functions may be used by (non-aggregate) SQL functions to |
| 4387 | ** associate metadata with argument values. If the same value is passed to |
| 4388 | ** multiple invocations of the same SQL function during query execution, under |
| 4389 | ** some circumstances the associated metadata may be preserved. An example |
| @@ -4452,10 +4494,11 @@ | |
| 4452 | #define SQLITE_STATIC ((sqlite3_destructor_type)0) |
| 4453 | #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) |
| 4454 | |
| 4455 | /* |
| 4456 | ** CAPI3REF: Setting The Result Of An SQL Function |
| 4457 | ** |
| 4458 | ** These routines are used by the xFunc or xFinal callbacks that |
| 4459 | ** implement SQL functions and aggregates. See |
| 4460 | ** [sqlite3_create_function()] and [sqlite3_create_function16()] |
| 4461 | ** for additional information. |
| @@ -4587,10 +4630,11 @@ | |
| 4587 | SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*); |
| 4588 | SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n); |
| 4589 | |
| 4590 | /* |
| 4591 | ** CAPI3REF: Define New Collating Sequences |
| 4592 | ** |
| 4593 | ** ^These functions add, remove, or modify a [collation] associated |
| 4594 | ** with the [database connection] specified as the first argument. |
| 4595 | ** |
| 4596 | ** ^The name of the collation is a UTF-8 string |
| @@ -4689,10 +4733,11 @@ | |
| 4689 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 4690 | ); |
| 4691 | |
| 4692 | /* |
| 4693 | ** CAPI3REF: Collation Needed Callbacks |
| 4694 | ** |
| 4695 | ** ^To avoid having to register all collation sequences before a database |
| 4696 | ** can be used, a single callback function may be registered with the |
| 4697 | ** [database connection] to be invoked whenever an undefined collation |
| 4698 | ** sequence is required. |
| @@ -4896,10 +4941,11 @@ | |
| 4896 | SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory; |
| 4897 | |
| 4898 | /* |
| 4899 | ** CAPI3REF: Test For Auto-Commit Mode |
| 4900 | ** KEYWORDS: {autocommit mode} |
| 4901 | ** |
| 4902 | ** ^The sqlite3_get_autocommit() interface returns non-zero or |
| 4903 | ** zero if the given database connection is or is not in autocommit mode, |
| 4904 | ** respectively. ^Autocommit mode is on by default. |
| 4905 | ** ^Autocommit mode is disabled by a [BEGIN] statement. |
| @@ -4918,10 +4964,11 @@ | |
| 4918 | */ |
| 4919 | SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*); |
| 4920 | |
| 4921 | /* |
| 4922 | ** CAPI3REF: Find The Database Handle Of A Prepared Statement |
| 4923 | ** |
| 4924 | ** ^The sqlite3_db_handle interface returns the [database connection] handle |
| 4925 | ** to which a [prepared statement] belongs. ^The [database connection] |
| 4926 | ** returned by sqlite3_db_handle is the same [database connection] |
| 4927 | ** that was the first argument |
| @@ -4930,10 +4977,11 @@ | |
| 4930 | */ |
| 4931 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*); |
| 4932 | |
| 4933 | /* |
| 4934 | ** CAPI3REF: Return The Filename For A Database Connection |
| 4935 | ** |
| 4936 | ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename |
| 4937 | ** associated with database N of connection D. ^The main database file |
| 4938 | ** has the name "main". If there is no attached database N on the database |
| 4939 | ** connection D, or if database N is a temporary or in-memory database, then |
| @@ -4946,19 +4994,21 @@ | |
| 4946 | */ |
| 4947 | SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
| 4948 | |
| 4949 | /* |
| 4950 | ** CAPI3REF: Determine if a database is read-only |
| 4951 | ** |
| 4952 | ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N |
| 4953 | ** of connection D is read-only, 0 if it is read/write, or -1 if N is not |
| 4954 | ** the name of a database on connection D. |
| 4955 | */ |
| 4956 | SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName); |
| 4957 | |
| 4958 | /* |
| 4959 | ** CAPI3REF: Find the next prepared statement |
| 4960 | ** |
| 4961 | ** ^This interface returns a pointer to the next [prepared statement] after |
| 4962 | ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL |
| 4963 | ** then this interface returns a pointer to the first prepared statement |
| 4964 | ** associated with the database connection pDb. ^If no prepared statement |
| @@ -4970,10 +5020,11 @@ | |
| 4970 | */ |
| 4971 | SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); |
| 4972 | |
| 4973 | /* |
| 4974 | ** CAPI3REF: Commit And Rollback Notification Callbacks |
| 4975 | ** |
| 4976 | ** ^The sqlite3_commit_hook() interface registers a callback |
| 4977 | ** function to be invoked whenever a transaction is [COMMIT | committed]. |
| 4978 | ** ^Any callback set by a previous call to sqlite3_commit_hook() |
| 4979 | ** for the same database connection is overridden. |
| @@ -5019,10 +5070,11 @@ | |
| 5019 | SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); |
| 5020 | SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); |
| 5021 | |
| 5022 | /* |
| 5023 | ** CAPI3REF: Data Change Notification Callbacks |
| 5024 | ** |
| 5025 | ** ^The sqlite3_update_hook() interface registers a callback function |
| 5026 | ** with the [database connection] identified by the first argument |
| 5027 | ** to be invoked whenever a row is updated, inserted or deleted in |
| 5028 | ** a rowid table. |
| @@ -5125,10 +5177,11 @@ | |
| 5125 | */ |
| 5126 | SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int); |
| 5127 | |
| 5128 | /* |
| 5129 | ** CAPI3REF: Free Memory Used By A Database Connection |
| 5130 | ** |
| 5131 | ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap |
| 5132 | ** memory as possible from database connection D. Unlike the |
| 5133 | ** [sqlite3_release_memory()] interface, this interface is in effect even |
| 5134 | ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is |
| @@ -5202,10 +5255,11 @@ | |
| 5202 | SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N); |
| 5203 | |
| 5204 | |
| 5205 | /* |
| 5206 | ** CAPI3REF: Extract Metadata About A Column Of A Table |
| 5207 | ** |
| 5208 | ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns |
| 5209 | ** information about column C of table T in database D |
| 5210 | ** on [database connection] X.)^ ^The sqlite3_table_column_metadata() |
| 5211 | ** interface returns SQLITE_OK and fills in the non-NULL pointers in |
| @@ -5280,10 +5334,11 @@ | |
| 5280 | int *pAutoinc /* OUTPUT: True if column is auto-increment */ |
| 5281 | ); |
| 5282 | |
| 5283 | /* |
| 5284 | ** CAPI3REF: Load An Extension |
| 5285 | ** |
| 5286 | ** ^This interface loads an SQLite extension library from the named file. |
| 5287 | ** |
| 5288 | ** ^The sqlite3_load_extension() interface attempts to load an |
| 5289 | ** [SQLite extension] library contained in the file zFile. If |
| @@ -5321,10 +5376,11 @@ | |
| 5321 | char **pzErrMsg /* Put error message here if not 0 */ |
| 5322 | ); |
| 5323 | |
| 5324 | /* |
| 5325 | ** CAPI3REF: Enable Or Disable Extension Loading |
| 5326 | ** |
| 5327 | ** ^So as not to open security holes in older applications that are |
| 5328 | ** unprepared to deal with [extension loading], and as a means of disabling |
| 5329 | ** [extension loading] while evaluating user-entered SQL, the following API |
| 5330 | ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. |
| @@ -5570,10 +5626,11 @@ | |
| 5570 | #define SQLITE_INDEX_CONSTRAINT_GE 32 |
| 5571 | #define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
| 5572 | |
| 5573 | /* |
| 5574 | ** CAPI3REF: Register A Virtual Table Implementation |
| 5575 | ** |
| 5576 | ** ^These routines are used to register a new [virtual table module] name. |
| 5577 | ** ^Module names must be registered before |
| 5578 | ** creating a new [virtual table] using the module and before using a |
| 5579 | ** preexisting [virtual table] for the module. |
| @@ -5666,10 +5723,11 @@ | |
| 5666 | */ |
| 5667 | SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL); |
| 5668 | |
| 5669 | /* |
| 5670 | ** CAPI3REF: Overload A Function For A Virtual Table |
| 5671 | ** |
| 5672 | ** ^(Virtual tables can provide alternative implementations of functions |
| 5673 | ** using the [xFindFunction] method of the [virtual table module]. |
| 5674 | ** But global versions of those functions |
| 5675 | ** must exist in order to be overloaded.)^ |
| @@ -5708,10 +5766,12 @@ | |
| 5708 | */ |
| 5709 | typedef struct sqlite3_blob sqlite3_blob; |
| 5710 | |
| 5711 | /* |
| 5712 | ** CAPI3REF: Open A BLOB For Incremental I/O |
| 5713 | ** |
| 5714 | ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located |
| 5715 | ** in row iRow, column zColumn, table zTable in database zDb; |
| 5716 | ** in other words, the same BLOB that would be selected by: |
| 5717 | ** |
| @@ -5789,10 +5849,11 @@ | |
| 5789 | sqlite3_blob **ppBlob |
| 5790 | ); |
| 5791 | |
| 5792 | /* |
| 5793 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 5794 | ** |
| 5795 | ** ^This function is used to move an existing blob handle so that it points |
| 5796 | ** to a different row of the same database table. ^The new row is identified |
| 5797 | ** by the rowid value passed as the second argument. Only the row can be |
| 5798 | ** changed. ^The database, table and column on which the blob handle is open |
| @@ -5813,10 +5874,11 @@ | |
| 5813 | */ |
| 5814 | SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 5815 | |
| 5816 | /* |
| 5817 | ** CAPI3REF: Close A BLOB Handle |
| 5818 | ** |
| 5819 | ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed |
| 5820 | ** unconditionally. Even if this routine returns an error code, the |
| 5821 | ** handle is still closed.)^ |
| 5822 | ** |
| @@ -5835,10 +5897,11 @@ | |
| 5835 | */ |
| 5836 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *); |
| 5837 | |
| 5838 | /* |
| 5839 | ** CAPI3REF: Return The Size Of An Open BLOB |
| 5840 | ** |
| 5841 | ** ^Returns the size in bytes of the BLOB accessible via the |
| 5842 | ** successfully opened [BLOB handle] in its only argument. ^The |
| 5843 | ** incremental blob I/O routines can only read or overwriting existing |
| 5844 | ** blob content; they cannot change the size of a blob. |
| @@ -5850,10 +5913,11 @@ | |
| 5850 | */ |
| 5851 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *); |
| 5852 | |
| 5853 | /* |
| 5854 | ** CAPI3REF: Read Data From A BLOB Incrementally |
| 5855 | ** |
| 5856 | ** ^(This function is used to read data from an open [BLOB handle] into a |
| 5857 | ** caller-supplied buffer. N bytes of data are copied into buffer Z |
| 5858 | ** from the open BLOB, starting at offset iOffset.)^ |
| 5859 | ** |
| @@ -5878,10 +5942,11 @@ | |
| 5878 | */ |
| 5879 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 5880 | |
| 5881 | /* |
| 5882 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 5883 | ** |
| 5884 | ** ^(This function is used to write data into an open [BLOB handle] from a |
| 5885 | ** caller-supplied buffer. N bytes of data are copied from the buffer Z |
| 5886 | ** into the open BLOB, starting at offset iOffset.)^ |
| 5887 | ** |
| @@ -6205,10 +6270,11 @@ | |
| 6205 | #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ |
| 6206 | #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ |
| 6207 | |
| 6208 | /* |
| 6209 | ** CAPI3REF: Retrieve the mutex for a database connection |
| 6210 | ** |
| 6211 | ** ^This interface returns a pointer the [sqlite3_mutex] object that |
| 6212 | ** serializes access to the [database connection] given in the argument |
| 6213 | ** when the [threading mode] is Serialized. |
| 6214 | ** ^If the [threading mode] is Single-thread or Multi-thread then this |
| @@ -6216,10 +6282,11 @@ | |
| 6216 | */ |
| 6217 | SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*); |
| 6218 | |
| 6219 | /* |
| 6220 | ** CAPI3REF: Low-Level Control Of Database Files |
| 6221 | ** |
| 6222 | ** ^The [sqlite3_file_control()] interface makes a direct call to the |
| 6223 | ** xFileControl method for the [sqlite3_io_methods] object associated |
| 6224 | ** with a particular database identified by the second argument. ^The |
| 6225 | ** name of the database is "main" for the main database or "temp" for the |
| @@ -6432,10 +6499,11 @@ | |
| 6432 | #define SQLITE_STATUS_SCRATCH_SIZE 8 |
| 6433 | #define SQLITE_STATUS_MALLOC_COUNT 9 |
| 6434 | |
| 6435 | /* |
| 6436 | ** CAPI3REF: Database Connection Status |
| 6437 | ** |
| 6438 | ** ^This interface is used to retrieve runtime status information |
| 6439 | ** about a single [database connection]. ^The first argument is the |
| 6440 | ** database connection object to be interrogated. ^The second argument |
| 6441 | ** is an integer constant, taken from the set of |
| @@ -6560,10 +6628,11 @@ | |
| 6560 | #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */ |
| 6561 | |
| 6562 | |
| 6563 | /* |
| 6564 | ** CAPI3REF: Prepared Statement Status |
| 6565 | ** |
| 6566 | ** ^(Each prepared statement maintains various |
| 6567 | ** [SQLITE_STMTSTATUS counters] that measure the number |
| 6568 | ** of times it has performed specific operations.)^ These counters can |
| 6569 | ** be used to monitor the performance characteristics of the prepared |
| @@ -7063,10 +7132,11 @@ | |
| 7063 | SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p); |
| 7064 | SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p); |
| 7065 | |
| 7066 | /* |
| 7067 | ** CAPI3REF: Unlock Notification |
| 7068 | ** |
| 7069 | ** ^When running in shared-cache mode, a database operation may fail with |
| 7070 | ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or |
| 7071 | ** individual tables within the shared-cache cannot be obtained. See |
| 7072 | ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. |
| @@ -7233,10 +7303,11 @@ | |
| 7233 | */ |
| 7234 | SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...); |
| 7235 | |
| 7236 | /* |
| 7237 | ** CAPI3REF: Write-Ahead Log Commit Hook |
| 7238 | ** |
| 7239 | ** ^The [sqlite3_wal_hook()] function is used to register a callback that |
| 7240 | ** is invoked each time data is committed to a database in wal mode. |
| 7241 | ** |
| 7242 | ** ^(The callback is invoked by SQLite after the commit has taken place and |
| @@ -7272,10 +7343,11 @@ | |
| 7272 | void* |
| 7273 | ); |
| 7274 | |
| 7275 | /* |
| 7276 | ** CAPI3REF: Configure an auto-checkpoint |
| 7277 | ** |
| 7278 | ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around |
| 7279 | ** [sqlite3_wal_hook()] that causes any database on [database connection] D |
| 7280 | ** to automatically [checkpoint] |
| 7281 | ** after committing a transaction if there are N or |
| @@ -7302,10 +7374,11 @@ | |
| 7302 | */ |
| 7303 | SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7304 | |
| 7305 | /* |
| 7306 | ** CAPI3REF: Checkpoint a database |
| 7307 | ** |
| 7308 | ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to |
| 7309 | ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ |
| 7310 | ** |
| 7311 | ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the |
| @@ -7323,10 +7396,11 @@ | |
| 7323 | */ |
| 7324 | SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7325 | |
| 7326 | /* |
| 7327 | ** CAPI3REF: Checkpoint a database |
| 7328 | ** |
| 7329 | ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint |
| 7330 | ** operation on database X of [database connection] D in mode M. Status |
| 7331 | ** information is written back into integers pointed to by L and C.)^ |
| 7332 | ** ^(The M parameter must be a valid [checkpoint mode]:)^ |
| @@ -7577,10 +7651,11 @@ | |
| 7577 | #define SQLITE_SCANSTAT_EXPLAIN 4 |
| 7578 | #define SQLITE_SCANSTAT_SELECTID 5 |
| 7579 | |
| 7580 | /* |
| 7581 | ** CAPI3REF: Prepared Statement Scan Status |
| 7582 | ** |
| 7583 | ** This interface returns information about the predicted and measured |
| 7584 | ** performance for pStmt. Advanced applications can use this |
| 7585 | ** interface to compare the predicted and the measured performance and |
| 7586 | ** issue warnings and/or rerun [ANALYZE] if discrepancies are found. |
| @@ -7614,10 +7689,11 @@ | |
| 7614 | void *pOut /* Result written here */ |
| 7615 | ); |
| 7616 | |
| 7617 | /* |
| 7618 | ** CAPI3REF: Zero Scan-Status Counters |
| 7619 | ** |
| 7620 | ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. |
| 7621 | ** |
| 7622 | ** This API is only available if the library is built with pre-processor |
| 7623 | ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| 7624 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -109,13 +109,13 @@ | |
| 109 | ** |
| 110 | ** See also: [sqlite3_libversion()], |
| 111 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 112 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 113 | */ |
| 114 | #define SQLITE_VERSION "3.8.10" |
| 115 | #define SQLITE_VERSION_NUMBER 3008010 |
| 116 | #define SQLITE_SOURCE_ID "2015-05-04 19:13:25 850c11866686a7b39d7b163fb60898c11283688e" |
| 117 | |
| 118 | /* |
| 119 | ** CAPI3REF: Run-Time Library Version Numbers |
| 120 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 121 | ** |
| @@ -268,10 +268,11 @@ | |
| 268 | # define double sqlite3_int64 |
| 269 | #endif |
| 270 | |
| 271 | /* |
| 272 | ** CAPI3REF: Closing A Database Connection |
| 273 | ** DESTRUCTOR: sqlite3 |
| 274 | ** |
| 275 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 276 | ** for the [sqlite3] object. |
| 277 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
| 278 | ** the [sqlite3] object is successfully destroyed and all associated |
| @@ -319,10 +320,11 @@ | |
| 320 | */ |
| 321 | typedef int (*sqlite3_callback)(void*,int,char**, char**); |
| 322 | |
| 323 | /* |
| 324 | ** CAPI3REF: One-Step Query Execution Interface |
| 325 | ** METHOD: sqlite3 |
| 326 | ** |
| 327 | ** The sqlite3_exec() interface is a convenience wrapper around |
| 328 | ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], |
| 329 | ** that allows an application to run multiple statements of SQL |
| 330 | ** without having to use a lot of C code. |
| @@ -1376,10 +1378,11 @@ | |
| 1378 | */ |
| 1379 | SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...); |
| 1380 | |
| 1381 | /* |
| 1382 | ** CAPI3REF: Configure database connections |
| 1383 | ** METHOD: sqlite3 |
| 1384 | ** |
| 1385 | ** The sqlite3_db_config() interface is used to make configuration |
| 1386 | ** changes to a [database connection]. The interface is similar to |
| 1387 | ** [sqlite3_config()] except that the changes apply to a single |
| 1388 | ** [database connection] (specified in the first argument). |
| @@ -1873,19 +1876,21 @@ | |
| 1876 | #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ |
| 1877 | |
| 1878 | |
| 1879 | /* |
| 1880 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
| 1881 | ** METHOD: sqlite3 |
| 1882 | ** |
| 1883 | ** ^The sqlite3_extended_result_codes() routine enables or disables the |
| 1884 | ** [extended result codes] feature of SQLite. ^The extended result |
| 1885 | ** codes are disabled by default for historical compatibility. |
| 1886 | */ |
| 1887 | SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff); |
| 1888 | |
| 1889 | /* |
| 1890 | ** CAPI3REF: Last Insert Rowid |
| 1891 | ** METHOD: sqlite3 |
| 1892 | ** |
| 1893 | ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) |
| 1894 | ** has a unique 64-bit signed |
| 1895 | ** integer key called the [ROWID | "rowid"]. ^The rowid is always available |
| 1896 | ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those |
| @@ -1933,10 +1938,11 @@ | |
| 1938 | */ |
| 1939 | SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*); |
| 1940 | |
| 1941 | /* |
| 1942 | ** CAPI3REF: Count The Number Of Rows Modified |
| 1943 | ** METHOD: sqlite3 |
| 1944 | ** |
| 1945 | ** ^This function returns the number of rows modified, inserted or |
| 1946 | ** deleted by the most recently completed INSERT, UPDATE or DELETE |
| 1947 | ** statement on the database connection specified by the only parameter. |
| 1948 | ** ^Executing any other type of SQL statement does not modify the value |
| @@ -1985,10 +1991,11 @@ | |
| 1991 | */ |
| 1992 | SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*); |
| 1993 | |
| 1994 | /* |
| 1995 | ** CAPI3REF: Total Number Of Rows Modified |
| 1996 | ** METHOD: sqlite3 |
| 1997 | ** |
| 1998 | ** ^This function returns the total number of rows inserted, modified or |
| 1999 | ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
| 2000 | ** since the database connection was opened, including those executed as |
| 2001 | ** part of trigger programs. ^Executing any other type of SQL statement |
| @@ -2008,10 +2015,11 @@ | |
| 2015 | */ |
| 2016 | SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*); |
| 2017 | |
| 2018 | /* |
| 2019 | ** CAPI3REF: Interrupt A Long-Running Query |
| 2020 | ** METHOD: sqlite3 |
| 2021 | ** |
| 2022 | ** ^This function causes any pending database operation to abort and |
| 2023 | ** return at its earliest opportunity. This routine is typically |
| 2024 | ** called in response to a user action such as pressing "Cancel" |
| 2025 | ** or Ctrl-C where the user wants a long query operation to halt |
| @@ -2084,10 +2092,11 @@ | |
| 2092 | SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql); |
| 2093 | |
| 2094 | /* |
| 2095 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2096 | ** KEYWORDS: {busy-handler callback} {busy handler} |
| 2097 | ** METHOD: sqlite3 |
| 2098 | ** |
| 2099 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2100 | ** that might be invoked with argument P whenever |
| 2101 | ** an attempt is made to access a database table associated with |
| 2102 | ** [database connection] D when another thread |
| @@ -2143,10 +2152,11 @@ | |
| 2152 | */ |
| 2153 | SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); |
| 2154 | |
| 2155 | /* |
| 2156 | ** CAPI3REF: Set A Busy Timeout |
| 2157 | ** METHOD: sqlite3 |
| 2158 | ** |
| 2159 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2160 | ** for a specified amount of time when a table is locked. ^The handler |
| 2161 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2162 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| @@ -2165,10 +2175,11 @@ | |
| 2175 | */ |
| 2176 | SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms); |
| 2177 | |
| 2178 | /* |
| 2179 | ** CAPI3REF: Convenience Routines For Running Queries |
| 2180 | ** METHOD: sqlite3 |
| 2181 | ** |
| 2182 | ** This is a legacy interface that is preserved for backwards compatibility. |
| 2183 | ** Use of this interface is not recommended. |
| 2184 | ** |
| 2185 | ** Definition: A <b>result table</b> is memory data structure created by the |
| @@ -2500,10 +2511,11 @@ | |
| 2511 | */ |
| 2512 | SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P); |
| 2513 | |
| 2514 | /* |
| 2515 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2516 | ** METHOD: sqlite3 |
| 2517 | ** |
| 2518 | ** ^This routine registers an authorizer callback with a particular |
| 2519 | ** [database connection], supplied in the first argument. |
| 2520 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2521 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| @@ -2656,10 +2668,11 @@ | |
| 2668 | #define SQLITE_COPY 0 /* No longer used */ |
| 2669 | #define SQLITE_RECURSIVE 33 /* NULL NULL */ |
| 2670 | |
| 2671 | /* |
| 2672 | ** CAPI3REF: Tracing And Profiling Functions |
| 2673 | ** METHOD: sqlite3 |
| 2674 | ** |
| 2675 | ** These routines register callback functions that can be used for |
| 2676 | ** tracing and profiling the execution of SQL statements. |
| 2677 | ** |
| 2678 | ** ^The callback function registered by sqlite3_trace() is invoked at |
| @@ -2688,10 +2701,11 @@ | |
| 2701 | SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*, |
| 2702 | void(*xProfile)(void*,const char*,sqlite3_uint64), void*); |
| 2703 | |
| 2704 | /* |
| 2705 | ** CAPI3REF: Query Progress Callbacks |
| 2706 | ** METHOD: sqlite3 |
| 2707 | ** |
| 2708 | ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback |
| 2709 | ** function X to be invoked periodically during long running calls to |
| 2710 | ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for |
| 2711 | ** database connection D. An example use for this |
| @@ -2721,10 +2735,11 @@ | |
| 2735 | */ |
| 2736 | SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2737 | |
| 2738 | /* |
| 2739 | ** CAPI3REF: Opening A New Database Connection |
| 2740 | ** CONSTRUCTOR: sqlite3 |
| 2741 | ** |
| 2742 | ** ^These routines open an SQLite database file as specified by the |
| 2743 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2744 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2745 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| @@ -3006,10 +3021,11 @@ | |
| 3021 | SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64); |
| 3022 | |
| 3023 | |
| 3024 | /* |
| 3025 | ** CAPI3REF: Error Codes And Messages |
| 3026 | ** METHOD: sqlite3 |
| 3027 | ** |
| 3028 | ** ^If the most recent sqlite3_* API call associated with |
| 3029 | ** [database connection] D failed, then the sqlite3_errcode(D) interface |
| 3030 | ** returns the numeric [result code] or [extended result code] for that |
| 3031 | ** API call. |
| @@ -3051,37 +3067,38 @@ | |
| 3067 | SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*); |
| 3068 | SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*); |
| 3069 | SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int); |
| 3070 | |
| 3071 | /* |
| 3072 | ** CAPI3REF: Prepared Statement Object |
| 3073 | ** KEYWORDS: {prepared statement} {prepared statements} |
| 3074 | ** |
| 3075 | ** An instance of this object represents a single SQL statement that |
| 3076 | ** has been compiled into binary form and is ready to be evaluated. |
| 3077 | ** |
| 3078 | ** Think of each SQL statement as a separate computer program. The |
| 3079 | ** original SQL text is source code. A prepared statement object |
| 3080 | ** is the compiled object code. All SQL must be converted into a |
| 3081 | ** prepared statement before it can be run. |
| 3082 | ** |
| 3083 | ** The life-cycle of a prepared statement object usually goes like this: |
| 3084 | ** |
| 3085 | ** <ol> |
| 3086 | ** <li> Create the prepared statement object using [sqlite3_prepare_v2()]. |
| 3087 | ** <li> Bind values to [parameters] using the sqlite3_bind_*() |
| 3088 | ** interfaces. |
| 3089 | ** <li> Run the SQL by calling [sqlite3_step()] one or more times. |
| 3090 | ** <li> Reset the prepared statement using [sqlite3_reset()] then go back |
| 3091 | ** to step 2. Do this zero or more times. |
| 3092 | ** <li> Destroy the object using [sqlite3_finalize()]. |
| 3093 | ** </ol> |
| 3094 | */ |
| 3095 | typedef struct sqlite3_stmt sqlite3_stmt; |
| 3096 | |
| 3097 | /* |
| 3098 | ** CAPI3REF: Run-time Limits |
| 3099 | ** METHOD: sqlite3 |
| 3100 | ** |
| 3101 | ** ^(This interface allows the size of various constructs to be limited |
| 3102 | ** on a connection by connection basis. The first parameter is the |
| 3103 | ** [database connection] whose limit is to be set or queried. The |
| 3104 | ** second parameter is one of the [limit categories] that define a |
| @@ -3189,10 +3206,12 @@ | |
| 3206 | #define SQLITE_LIMIT_WORKER_THREADS 11 |
| 3207 | |
| 3208 | /* |
| 3209 | ** CAPI3REF: Compiling An SQL Statement |
| 3210 | ** KEYWORDS: {SQL statement compiler} |
| 3211 | ** METHOD: sqlite3 |
| 3212 | ** CONSTRUCTOR: sqlite3_stmt |
| 3213 | ** |
| 3214 | ** To execute an SQL query, it must first be compiled into a byte-code |
| 3215 | ** program using one of these routines. |
| 3216 | ** |
| 3217 | ** The first argument, "db", is a [database connection] obtained from a |
| @@ -3296,19 +3315,21 @@ | |
| 3315 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3316 | ); |
| 3317 | |
| 3318 | /* |
| 3319 | ** CAPI3REF: Retrieving Statement SQL |
| 3320 | ** METHOD: sqlite3_stmt |
| 3321 | ** |
| 3322 | ** ^This interface can be used to retrieve a saved copy of the original |
| 3323 | ** SQL text used to create a [prepared statement] if that statement was |
| 3324 | ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. |
| 3325 | */ |
| 3326 | SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt); |
| 3327 | |
| 3328 | /* |
| 3329 | ** CAPI3REF: Determine If An SQL Statement Writes The Database |
| 3330 | ** METHOD: sqlite3_stmt |
| 3331 | ** |
| 3332 | ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if |
| 3333 | ** and only if the [prepared statement] X makes no direct changes to |
| 3334 | ** the content of the database file. |
| 3335 | ** |
| @@ -3336,10 +3357,11 @@ | |
| 3357 | */ |
| 3358 | SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
| 3359 | |
| 3360 | /* |
| 3361 | ** CAPI3REF: Determine If A Prepared Statement Has Been Reset |
| 3362 | ** METHOD: sqlite3_stmt |
| 3363 | ** |
| 3364 | ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the |
| 3365 | ** [prepared statement] S has been stepped at least once using |
| 3366 | ** [sqlite3_step(S)] but has not run to completion and/or has not |
| 3367 | ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) |
| @@ -3410,10 +3432,11 @@ | |
| 3432 | |
| 3433 | /* |
| 3434 | ** CAPI3REF: Binding Values To Prepared Statements |
| 3435 | ** KEYWORDS: {host parameter} {host parameters} {host parameter name} |
| 3436 | ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} |
| 3437 | ** METHOD: sqlite3_stmt |
| 3438 | ** |
| 3439 | ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, |
| 3440 | ** literals may be replaced by a [parameter] that matches one of following |
| 3441 | ** templates: |
| 3442 | ** |
| @@ -3528,10 +3551,11 @@ | |
| 3551 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); |
| 3552 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
| 3553 | |
| 3554 | /* |
| 3555 | ** CAPI3REF: Number Of SQL Parameters |
| 3556 | ** METHOD: sqlite3_stmt |
| 3557 | ** |
| 3558 | ** ^This routine can be used to find the number of [SQL parameters] |
| 3559 | ** in a [prepared statement]. SQL parameters are tokens of the |
| 3560 | ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as |
| 3561 | ** placeholders for values that are [sqlite3_bind_blob | bound] |
| @@ -3548,10 +3572,11 @@ | |
| 3572 | */ |
| 3573 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*); |
| 3574 | |
| 3575 | /* |
| 3576 | ** CAPI3REF: Name Of A Host Parameter |
| 3577 | ** METHOD: sqlite3_stmt |
| 3578 | ** |
| 3579 | ** ^The sqlite3_bind_parameter_name(P,N) interface returns |
| 3580 | ** the name of the N-th [SQL parameter] in the [prepared statement] P. |
| 3581 | ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| 3582 | ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| @@ -3575,10 +3600,11 @@ | |
| 3600 | */ |
| 3601 | SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int); |
| 3602 | |
| 3603 | /* |
| 3604 | ** CAPI3REF: Index Of A Parameter With A Given Name |
| 3605 | ** METHOD: sqlite3_stmt |
| 3606 | ** |
| 3607 | ** ^Return the index of an SQL parameter given its name. ^The |
| 3608 | ** index value returned is suitable for use as the second |
| 3609 | ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero |
| 3610 | ** is returned if no matching parameter is found. ^The parameter |
| @@ -3591,19 +3617,21 @@ | |
| 3617 | */ |
| 3618 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3619 | |
| 3620 | /* |
| 3621 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| 3622 | ** METHOD: sqlite3_stmt |
| 3623 | ** |
| 3624 | ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset |
| 3625 | ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. |
| 3626 | ** ^Use this routine to reset all host parameters to NULL. |
| 3627 | */ |
| 3628 | SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*); |
| 3629 | |
| 3630 | /* |
| 3631 | ** CAPI3REF: Number Of Columns In A Result Set |
| 3632 | ** METHOD: sqlite3_stmt |
| 3633 | ** |
| 3634 | ** ^Return the number of columns in the result set returned by the |
| 3635 | ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL |
| 3636 | ** statement that does not return data (for example an [UPDATE]). |
| 3637 | ** |
| @@ -3611,10 +3639,11 @@ | |
| 3639 | */ |
| 3640 | SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt); |
| 3641 | |
| 3642 | /* |
| 3643 | ** CAPI3REF: Column Names In A Result Set |
| 3644 | ** METHOD: sqlite3_stmt |
| 3645 | ** |
| 3646 | ** ^These routines return the name assigned to a particular column |
| 3647 | ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() |
| 3648 | ** interface returns a pointer to a zero-terminated UTF-8 string |
| 3649 | ** and sqlite3_column_name16() returns a pointer to a zero-terminated |
| @@ -3640,10 +3669,11 @@ | |
| 3669 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N); |
| 3670 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N); |
| 3671 | |
| 3672 | /* |
| 3673 | ** CAPI3REF: Source Of Data In A Query Result |
| 3674 | ** METHOD: sqlite3_stmt |
| 3675 | ** |
| 3676 | ** ^These routines provide a means to determine the database, table, and |
| 3677 | ** table column that is the origin of a particular result column in |
| 3678 | ** [SELECT] statement. |
| 3679 | ** ^The name of the database or table or column can be returned as |
| @@ -3692,10 +3722,11 @@ | |
| 3722 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int); |
| 3723 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int); |
| 3724 | |
| 3725 | /* |
| 3726 | ** CAPI3REF: Declared Datatype Of A Query Result |
| 3727 | ** METHOD: sqlite3_stmt |
| 3728 | ** |
| 3729 | ** ^(The first parameter is a [prepared statement]. |
| 3730 | ** If this statement is a [SELECT] statement and the Nth column of the |
| 3731 | ** returned result set of that [SELECT] is a table column (not an |
| 3732 | ** expression or subquery) then the declared type of the table |
| @@ -3724,10 +3755,11 @@ | |
| 3755 | SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int); |
| 3756 | SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int); |
| 3757 | |
| 3758 | /* |
| 3759 | ** CAPI3REF: Evaluate An SQL Statement |
| 3760 | ** METHOD: sqlite3_stmt |
| 3761 | ** |
| 3762 | ** After a [prepared statement] has been prepared using either |
| 3763 | ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy |
| 3764 | ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function |
| 3765 | ** must be called one or more times to evaluate the statement. |
| @@ -3803,10 +3835,11 @@ | |
| 3835 | */ |
| 3836 | SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*); |
| 3837 | |
| 3838 | /* |
| 3839 | ** CAPI3REF: Number of columns in a result set |
| 3840 | ** METHOD: sqlite3_stmt |
| 3841 | ** |
| 3842 | ** ^The sqlite3_data_count(P) interface returns the number of columns in the |
| 3843 | ** current row of the result set of [prepared statement] P. |
| 3844 | ** ^If prepared statement P does not have results ready to return |
| 3845 | ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of |
| @@ -3856,10 +3889,11 @@ | |
| 3889 | #define SQLITE3_TEXT 3 |
| 3890 | |
| 3891 | /* |
| 3892 | ** CAPI3REF: Result Values From A Query |
| 3893 | ** KEYWORDS: {column access functions} |
| 3894 | ** METHOD: sqlite3_stmt |
| 3895 | ** |
| 3896 | ** These routines form the "result set" interface. |
| 3897 | ** |
| 3898 | ** ^These routines return information about a single column of the current |
| 3899 | ** result row of a query. ^In every case the first argument is a pointer |
| @@ -4028,10 +4062,11 @@ | |
| 4062 | SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol); |
| 4063 | SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol); |
| 4064 | |
| 4065 | /* |
| 4066 | ** CAPI3REF: Destroy A Prepared Statement Object |
| 4067 | ** DESTRUCTOR: sqlite3_stmt |
| 4068 | ** |
| 4069 | ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. |
| 4070 | ** ^If the most recent evaluation of the statement encountered no errors |
| 4071 | ** or if the statement is never been evaluated, then sqlite3_finalize() returns |
| 4072 | ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then |
| @@ -4055,10 +4090,11 @@ | |
| 4090 | */ |
| 4091 | SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt); |
| 4092 | |
| 4093 | /* |
| 4094 | ** CAPI3REF: Reset A Prepared Statement Object |
| 4095 | ** METHOD: sqlite3_stmt |
| 4096 | ** |
| 4097 | ** The sqlite3_reset() function is called to reset a [prepared statement] |
| 4098 | ** object back to its initial state, ready to be re-executed. |
| 4099 | ** ^Any SQL statement variables that had values bound to them using |
| 4100 | ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. |
| @@ -4084,10 +4120,11 @@ | |
| 4120 | /* |
| 4121 | ** CAPI3REF: Create Or Redefine SQL Functions |
| 4122 | ** KEYWORDS: {function creation routines} |
| 4123 | ** KEYWORDS: {application-defined SQL function} |
| 4124 | ** KEYWORDS: {application-defined SQL functions} |
| 4125 | ** METHOD: sqlite3 |
| 4126 | ** |
| 4127 | ** ^These functions (collectively known as "function creation routines") |
| 4128 | ** are used to add SQL functions or aggregates or to redefine the behavior |
| 4129 | ** of existing SQL functions or aggregates. The only differences between |
| 4130 | ** these routines are the text encoding expected for |
| @@ -4253,10 +4290,11 @@ | |
| 4290 | void*,sqlite3_int64); |
| 4291 | #endif |
| 4292 | |
| 4293 | /* |
| 4294 | ** CAPI3REF: Obtaining SQL Function Parameter Values |
| 4295 | ** METHOD: sqlite3_value |
| 4296 | ** |
| 4297 | ** The C-language implementation of SQL functions and aggregates uses |
| 4298 | ** this set of interface routines to access the parameter values on |
| 4299 | ** the function or aggregate. |
| 4300 | ** |
| @@ -4311,10 +4349,11 @@ | |
| 4349 | SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*); |
| 4350 | SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*); |
| 4351 | |
| 4352 | /* |
| 4353 | ** CAPI3REF: Obtain Aggregate Function Context |
| 4354 | ** METHOD: sqlite3_context |
| 4355 | ** |
| 4356 | ** Implementations of aggregate SQL functions use this |
| 4357 | ** routine to allocate memory for storing their state. |
| 4358 | ** |
| 4359 | ** ^The first time the sqlite3_aggregate_context(C,N) routine is called |
| @@ -4355,10 +4394,11 @@ | |
| 4394 | */ |
| 4395 | SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes); |
| 4396 | |
| 4397 | /* |
| 4398 | ** CAPI3REF: User Data For Functions |
| 4399 | ** METHOD: sqlite3_context |
| 4400 | ** |
| 4401 | ** ^The sqlite3_user_data() interface returns a copy of |
| 4402 | ** the pointer that was the pUserData parameter (the 5th parameter) |
| 4403 | ** of the [sqlite3_create_function()] |
| 4404 | ** and [sqlite3_create_function16()] routines that originally |
| @@ -4369,10 +4409,11 @@ | |
| 4409 | */ |
| 4410 | SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*); |
| 4411 | |
| 4412 | /* |
| 4413 | ** CAPI3REF: Database Connection For Functions |
| 4414 | ** METHOD: sqlite3_context |
| 4415 | ** |
| 4416 | ** ^The sqlite3_context_db_handle() interface returns a copy of |
| 4417 | ** the pointer to the [database connection] (the 1st parameter) |
| 4418 | ** of the [sqlite3_create_function()] |
| 4419 | ** and [sqlite3_create_function16()] routines that originally |
| @@ -4380,10 +4421,11 @@ | |
| 4421 | */ |
| 4422 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*); |
| 4423 | |
| 4424 | /* |
| 4425 | ** CAPI3REF: Function Auxiliary Data |
| 4426 | ** METHOD: sqlite3_context |
| 4427 | ** |
| 4428 | ** These functions may be used by (non-aggregate) SQL functions to |
| 4429 | ** associate metadata with argument values. If the same value is passed to |
| 4430 | ** multiple invocations of the same SQL function during query execution, under |
| 4431 | ** some circumstances the associated metadata may be preserved. An example |
| @@ -4452,10 +4494,11 @@ | |
| 4494 | #define SQLITE_STATIC ((sqlite3_destructor_type)0) |
| 4495 | #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) |
| 4496 | |
| 4497 | /* |
| 4498 | ** CAPI3REF: Setting The Result Of An SQL Function |
| 4499 | ** METHOD: sqlite3_context |
| 4500 | ** |
| 4501 | ** These routines are used by the xFunc or xFinal callbacks that |
| 4502 | ** implement SQL functions and aggregates. See |
| 4503 | ** [sqlite3_create_function()] and [sqlite3_create_function16()] |
| 4504 | ** for additional information. |
| @@ -4587,10 +4630,11 @@ | |
| 4630 | SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*); |
| 4631 | SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n); |
| 4632 | |
| 4633 | /* |
| 4634 | ** CAPI3REF: Define New Collating Sequences |
| 4635 | ** METHOD: sqlite3 |
| 4636 | ** |
| 4637 | ** ^These functions add, remove, or modify a [collation] associated |
| 4638 | ** with the [database connection] specified as the first argument. |
| 4639 | ** |
| 4640 | ** ^The name of the collation is a UTF-8 string |
| @@ -4689,10 +4733,11 @@ | |
| 4733 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 4734 | ); |
| 4735 | |
| 4736 | /* |
| 4737 | ** CAPI3REF: Collation Needed Callbacks |
| 4738 | ** METHOD: sqlite3 |
| 4739 | ** |
| 4740 | ** ^To avoid having to register all collation sequences before a database |
| 4741 | ** can be used, a single callback function may be registered with the |
| 4742 | ** [database connection] to be invoked whenever an undefined collation |
| 4743 | ** sequence is required. |
| @@ -4896,10 +4941,11 @@ | |
| 4941 | SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory; |
| 4942 | |
| 4943 | /* |
| 4944 | ** CAPI3REF: Test For Auto-Commit Mode |
| 4945 | ** KEYWORDS: {autocommit mode} |
| 4946 | ** METHOD: sqlite3 |
| 4947 | ** |
| 4948 | ** ^The sqlite3_get_autocommit() interface returns non-zero or |
| 4949 | ** zero if the given database connection is or is not in autocommit mode, |
| 4950 | ** respectively. ^Autocommit mode is on by default. |
| 4951 | ** ^Autocommit mode is disabled by a [BEGIN] statement. |
| @@ -4918,10 +4964,11 @@ | |
| 4964 | */ |
| 4965 | SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*); |
| 4966 | |
| 4967 | /* |
| 4968 | ** CAPI3REF: Find The Database Handle Of A Prepared Statement |
| 4969 | ** METHOD: sqlite3_stmt |
| 4970 | ** |
| 4971 | ** ^The sqlite3_db_handle interface returns the [database connection] handle |
| 4972 | ** to which a [prepared statement] belongs. ^The [database connection] |
| 4973 | ** returned by sqlite3_db_handle is the same [database connection] |
| 4974 | ** that was the first argument |
| @@ -4930,10 +4977,11 @@ | |
| 4977 | */ |
| 4978 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*); |
| 4979 | |
| 4980 | /* |
| 4981 | ** CAPI3REF: Return The Filename For A Database Connection |
| 4982 | ** METHOD: sqlite3 |
| 4983 | ** |
| 4984 | ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename |
| 4985 | ** associated with database N of connection D. ^The main database file |
| 4986 | ** has the name "main". If there is no attached database N on the database |
| 4987 | ** connection D, or if database N is a temporary or in-memory database, then |
| @@ -4946,19 +4994,21 @@ | |
| 4994 | */ |
| 4995 | SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
| 4996 | |
| 4997 | /* |
| 4998 | ** CAPI3REF: Determine if a database is read-only |
| 4999 | ** METHOD: sqlite3 |
| 5000 | ** |
| 5001 | ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N |
| 5002 | ** of connection D is read-only, 0 if it is read/write, or -1 if N is not |
| 5003 | ** the name of a database on connection D. |
| 5004 | */ |
| 5005 | SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName); |
| 5006 | |
| 5007 | /* |
| 5008 | ** CAPI3REF: Find the next prepared statement |
| 5009 | ** METHOD: sqlite3 |
| 5010 | ** |
| 5011 | ** ^This interface returns a pointer to the next [prepared statement] after |
| 5012 | ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL |
| 5013 | ** then this interface returns a pointer to the first prepared statement |
| 5014 | ** associated with the database connection pDb. ^If no prepared statement |
| @@ -4970,10 +5020,11 @@ | |
| 5020 | */ |
| 5021 | SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); |
| 5022 | |
| 5023 | /* |
| 5024 | ** CAPI3REF: Commit And Rollback Notification Callbacks |
| 5025 | ** METHOD: sqlite3 |
| 5026 | ** |
| 5027 | ** ^The sqlite3_commit_hook() interface registers a callback |
| 5028 | ** function to be invoked whenever a transaction is [COMMIT | committed]. |
| 5029 | ** ^Any callback set by a previous call to sqlite3_commit_hook() |
| 5030 | ** for the same database connection is overridden. |
| @@ -5019,10 +5070,11 @@ | |
| 5070 | SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); |
| 5071 | SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); |
| 5072 | |
| 5073 | /* |
| 5074 | ** CAPI3REF: Data Change Notification Callbacks |
| 5075 | ** METHOD: sqlite3 |
| 5076 | ** |
| 5077 | ** ^The sqlite3_update_hook() interface registers a callback function |
| 5078 | ** with the [database connection] identified by the first argument |
| 5079 | ** to be invoked whenever a row is updated, inserted or deleted in |
| 5080 | ** a rowid table. |
| @@ -5125,10 +5177,11 @@ | |
| 5177 | */ |
| 5178 | SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int); |
| 5179 | |
| 5180 | /* |
| 5181 | ** CAPI3REF: Free Memory Used By A Database Connection |
| 5182 | ** METHOD: sqlite3 |
| 5183 | ** |
| 5184 | ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap |
| 5185 | ** memory as possible from database connection D. Unlike the |
| 5186 | ** [sqlite3_release_memory()] interface, this interface is in effect even |
| 5187 | ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is |
| @@ -5202,10 +5255,11 @@ | |
| 5255 | SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N); |
| 5256 | |
| 5257 | |
| 5258 | /* |
| 5259 | ** CAPI3REF: Extract Metadata About A Column Of A Table |
| 5260 | ** METHOD: sqlite3 |
| 5261 | ** |
| 5262 | ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns |
| 5263 | ** information about column C of table T in database D |
| 5264 | ** on [database connection] X.)^ ^The sqlite3_table_column_metadata() |
| 5265 | ** interface returns SQLITE_OK and fills in the non-NULL pointers in |
| @@ -5280,10 +5334,11 @@ | |
| 5334 | int *pAutoinc /* OUTPUT: True if column is auto-increment */ |
| 5335 | ); |
| 5336 | |
| 5337 | /* |
| 5338 | ** CAPI3REF: Load An Extension |
| 5339 | ** METHOD: sqlite3 |
| 5340 | ** |
| 5341 | ** ^This interface loads an SQLite extension library from the named file. |
| 5342 | ** |
| 5343 | ** ^The sqlite3_load_extension() interface attempts to load an |
| 5344 | ** [SQLite extension] library contained in the file zFile. If |
| @@ -5321,10 +5376,11 @@ | |
| 5376 | char **pzErrMsg /* Put error message here if not 0 */ |
| 5377 | ); |
| 5378 | |
| 5379 | /* |
| 5380 | ** CAPI3REF: Enable Or Disable Extension Loading |
| 5381 | ** METHOD: sqlite3 |
| 5382 | ** |
| 5383 | ** ^So as not to open security holes in older applications that are |
| 5384 | ** unprepared to deal with [extension loading], and as a means of disabling |
| 5385 | ** [extension loading] while evaluating user-entered SQL, the following API |
| 5386 | ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. |
| @@ -5570,10 +5626,11 @@ | |
| 5626 | #define SQLITE_INDEX_CONSTRAINT_GE 32 |
| 5627 | #define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
| 5628 | |
| 5629 | /* |
| 5630 | ** CAPI3REF: Register A Virtual Table Implementation |
| 5631 | ** METHOD: sqlite3 |
| 5632 | ** |
| 5633 | ** ^These routines are used to register a new [virtual table module] name. |
| 5634 | ** ^Module names must be registered before |
| 5635 | ** creating a new [virtual table] using the module and before using a |
| 5636 | ** preexisting [virtual table] for the module. |
| @@ -5666,10 +5723,11 @@ | |
| 5723 | */ |
| 5724 | SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL); |
| 5725 | |
| 5726 | /* |
| 5727 | ** CAPI3REF: Overload A Function For A Virtual Table |
| 5728 | ** METHOD: sqlite3 |
| 5729 | ** |
| 5730 | ** ^(Virtual tables can provide alternative implementations of functions |
| 5731 | ** using the [xFindFunction] method of the [virtual table module]. |
| 5732 | ** But global versions of those functions |
| 5733 | ** must exist in order to be overloaded.)^ |
| @@ -5708,10 +5766,12 @@ | |
| 5766 | */ |
| 5767 | typedef struct sqlite3_blob sqlite3_blob; |
| 5768 | |
| 5769 | /* |
| 5770 | ** CAPI3REF: Open A BLOB For Incremental I/O |
| 5771 | ** METHOD: sqlite3 |
| 5772 | ** CONSTRUCTOR: sqlite3_blob |
| 5773 | ** |
| 5774 | ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located |
| 5775 | ** in row iRow, column zColumn, table zTable in database zDb; |
| 5776 | ** in other words, the same BLOB that would be selected by: |
| 5777 | ** |
| @@ -5789,10 +5849,11 @@ | |
| 5849 | sqlite3_blob **ppBlob |
| 5850 | ); |
| 5851 | |
| 5852 | /* |
| 5853 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 5854 | ** METHOD: sqlite3_blob |
| 5855 | ** |
| 5856 | ** ^This function is used to move an existing blob handle so that it points |
| 5857 | ** to a different row of the same database table. ^The new row is identified |
| 5858 | ** by the rowid value passed as the second argument. Only the row can be |
| 5859 | ** changed. ^The database, table and column on which the blob handle is open |
| @@ -5813,10 +5874,11 @@ | |
| 5874 | */ |
| 5875 | SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 5876 | |
| 5877 | /* |
| 5878 | ** CAPI3REF: Close A BLOB Handle |
| 5879 | ** DESTRUCTOR: sqlite3_blob |
| 5880 | ** |
| 5881 | ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed |
| 5882 | ** unconditionally. Even if this routine returns an error code, the |
| 5883 | ** handle is still closed.)^ |
| 5884 | ** |
| @@ -5835,10 +5897,11 @@ | |
| 5897 | */ |
| 5898 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *); |
| 5899 | |
| 5900 | /* |
| 5901 | ** CAPI3REF: Return The Size Of An Open BLOB |
| 5902 | ** METHOD: sqlite3_blob |
| 5903 | ** |
| 5904 | ** ^Returns the size in bytes of the BLOB accessible via the |
| 5905 | ** successfully opened [BLOB handle] in its only argument. ^The |
| 5906 | ** incremental blob I/O routines can only read or overwriting existing |
| 5907 | ** blob content; they cannot change the size of a blob. |
| @@ -5850,10 +5913,11 @@ | |
| 5913 | */ |
| 5914 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *); |
| 5915 | |
| 5916 | /* |
| 5917 | ** CAPI3REF: Read Data From A BLOB Incrementally |
| 5918 | ** METHOD: sqlite3_blob |
| 5919 | ** |
| 5920 | ** ^(This function is used to read data from an open [BLOB handle] into a |
| 5921 | ** caller-supplied buffer. N bytes of data are copied into buffer Z |
| 5922 | ** from the open BLOB, starting at offset iOffset.)^ |
| 5923 | ** |
| @@ -5878,10 +5942,11 @@ | |
| 5942 | */ |
| 5943 | SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 5944 | |
| 5945 | /* |
| 5946 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 5947 | ** METHOD: sqlite3_blob |
| 5948 | ** |
| 5949 | ** ^(This function is used to write data into an open [BLOB handle] from a |
| 5950 | ** caller-supplied buffer. N bytes of data are copied from the buffer Z |
| 5951 | ** into the open BLOB, starting at offset iOffset.)^ |
| 5952 | ** |
| @@ -6205,10 +6270,11 @@ | |
| 6270 | #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ |
| 6271 | #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ |
| 6272 | |
| 6273 | /* |
| 6274 | ** CAPI3REF: Retrieve the mutex for a database connection |
| 6275 | ** METHOD: sqlite3 |
| 6276 | ** |
| 6277 | ** ^This interface returns a pointer the [sqlite3_mutex] object that |
| 6278 | ** serializes access to the [database connection] given in the argument |
| 6279 | ** when the [threading mode] is Serialized. |
| 6280 | ** ^If the [threading mode] is Single-thread or Multi-thread then this |
| @@ -6216,10 +6282,11 @@ | |
| 6282 | */ |
| 6283 | SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*); |
| 6284 | |
| 6285 | /* |
| 6286 | ** CAPI3REF: Low-Level Control Of Database Files |
| 6287 | ** METHOD: sqlite3 |
| 6288 | ** |
| 6289 | ** ^The [sqlite3_file_control()] interface makes a direct call to the |
| 6290 | ** xFileControl method for the [sqlite3_io_methods] object associated |
| 6291 | ** with a particular database identified by the second argument. ^The |
| 6292 | ** name of the database is "main" for the main database or "temp" for the |
| @@ -6432,10 +6499,11 @@ | |
| 6499 | #define SQLITE_STATUS_SCRATCH_SIZE 8 |
| 6500 | #define SQLITE_STATUS_MALLOC_COUNT 9 |
| 6501 | |
| 6502 | /* |
| 6503 | ** CAPI3REF: Database Connection Status |
| 6504 | ** METHOD: sqlite3 |
| 6505 | ** |
| 6506 | ** ^This interface is used to retrieve runtime status information |
| 6507 | ** about a single [database connection]. ^The first argument is the |
| 6508 | ** database connection object to be interrogated. ^The second argument |
| 6509 | ** is an integer constant, taken from the set of |
| @@ -6560,10 +6628,11 @@ | |
| 6628 | #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */ |
| 6629 | |
| 6630 | |
| 6631 | /* |
| 6632 | ** CAPI3REF: Prepared Statement Status |
| 6633 | ** METHOD: sqlite3_stmt |
| 6634 | ** |
| 6635 | ** ^(Each prepared statement maintains various |
| 6636 | ** [SQLITE_STMTSTATUS counters] that measure the number |
| 6637 | ** of times it has performed specific operations.)^ These counters can |
| 6638 | ** be used to monitor the performance characteristics of the prepared |
| @@ -7063,10 +7132,11 @@ | |
| 7132 | SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p); |
| 7133 | SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p); |
| 7134 | |
| 7135 | /* |
| 7136 | ** CAPI3REF: Unlock Notification |
| 7137 | ** METHOD: sqlite3 |
| 7138 | ** |
| 7139 | ** ^When running in shared-cache mode, a database operation may fail with |
| 7140 | ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or |
| 7141 | ** individual tables within the shared-cache cannot be obtained. See |
| 7142 | ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. |
| @@ -7233,10 +7303,11 @@ | |
| 7303 | */ |
| 7304 | SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...); |
| 7305 | |
| 7306 | /* |
| 7307 | ** CAPI3REF: Write-Ahead Log Commit Hook |
| 7308 | ** METHOD: sqlite3 |
| 7309 | ** |
| 7310 | ** ^The [sqlite3_wal_hook()] function is used to register a callback that |
| 7311 | ** is invoked each time data is committed to a database in wal mode. |
| 7312 | ** |
| 7313 | ** ^(The callback is invoked by SQLite after the commit has taken place and |
| @@ -7272,10 +7343,11 @@ | |
| 7343 | void* |
| 7344 | ); |
| 7345 | |
| 7346 | /* |
| 7347 | ** CAPI3REF: Configure an auto-checkpoint |
| 7348 | ** METHOD: sqlite3 |
| 7349 | ** |
| 7350 | ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around |
| 7351 | ** [sqlite3_wal_hook()] that causes any database on [database connection] D |
| 7352 | ** to automatically [checkpoint] |
| 7353 | ** after committing a transaction if there are N or |
| @@ -7302,10 +7374,11 @@ | |
| 7374 | */ |
| 7375 | SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7376 | |
| 7377 | /* |
| 7378 | ** CAPI3REF: Checkpoint a database |
| 7379 | ** METHOD: sqlite3 |
| 7380 | ** |
| 7381 | ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to |
| 7382 | ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ |
| 7383 | ** |
| 7384 | ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the |
| @@ -7323,10 +7396,11 @@ | |
| 7396 | */ |
| 7397 | SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7398 | |
| 7399 | /* |
| 7400 | ** CAPI3REF: Checkpoint a database |
| 7401 | ** METHOD: sqlite3 |
| 7402 | ** |
| 7403 | ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint |
| 7404 | ** operation on database X of [database connection] D in mode M. Status |
| 7405 | ** information is written back into integers pointed to by L and C.)^ |
| 7406 | ** ^(The M parameter must be a valid [checkpoint mode]:)^ |
| @@ -7577,10 +7651,11 @@ | |
| 7651 | #define SQLITE_SCANSTAT_EXPLAIN 4 |
| 7652 | #define SQLITE_SCANSTAT_SELECTID 5 |
| 7653 | |
| 7654 | /* |
| 7655 | ** CAPI3REF: Prepared Statement Scan Status |
| 7656 | ** METHOD: sqlite3_stmt |
| 7657 | ** |
| 7658 | ** This interface returns information about the predicted and measured |
| 7659 | ** performance for pStmt. Advanced applications can use this |
| 7660 | ** interface to compare the predicted and the measured performance and |
| 7661 | ** issue warnings and/or rerun [ANALYZE] if discrepancies are found. |
| @@ -7614,10 +7689,11 @@ | |
| 7689 | void *pOut /* Result written here */ |
| 7690 | ); |
| 7691 | |
| 7692 | /* |
| 7693 | ** CAPI3REF: Zero Scan-Status Counters |
| 7694 | ** METHOD: sqlite3_stmt |
| 7695 | ** |
| 7696 | ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. |
| 7697 | ** |
| 7698 | ** This API is only available if the library is built with pre-processor |
| 7699 | ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| 7700 |