| | @@ -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.1. 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. |
| | @@ -20,13 +20,10 @@ |
| 20 | 20 | #define SQLITE_CORE 1 |
| 21 | 21 | #define SQLITE_AMALGAMATION 1 |
| 22 | 22 | #ifndef SQLITE_PRIVATE |
| 23 | 23 | # define SQLITE_PRIVATE static |
| 24 | 24 | #endif |
| 25 | | -#ifndef SQLITE_API |
| 26 | | -# define SQLITE_API |
| 27 | | -#endif |
| 28 | 25 | /************** Begin file sqliteInt.h ***************************************/ |
| 29 | 26 | /* |
| 30 | 27 | ** 2001 September 15 |
| 31 | 28 | ** |
| 32 | 29 | ** The author disclaims copyright to this source code. In place of |
| | @@ -71,10 +68,11 @@ |
| 71 | 68 | #if defined(_MSC_VER) |
| 72 | 69 | #pragma warning(disable : 4054) |
| 73 | 70 | #pragma warning(disable : 4055) |
| 74 | 71 | #pragma warning(disable : 4100) |
| 75 | 72 | #pragma warning(disable : 4127) |
| 73 | +#pragma warning(disable : 4130) |
| 76 | 74 | #pragma warning(disable : 4152) |
| 77 | 75 | #pragma warning(disable : 4189) |
| 78 | 76 | #pragma warning(disable : 4206) |
| 79 | 77 | #pragma warning(disable : 4210) |
| 80 | 78 | #pragma warning(disable : 4232) |
| | @@ -250,27 +248,24 @@ |
| 250 | 248 | extern "C" { |
| 251 | 249 | #endif |
| 252 | 250 | |
| 253 | 251 | |
| 254 | 252 | /* |
| 255 | | -** Add the ability to override 'extern' |
| 253 | +** Provide the ability to override linkage features of the interface. |
| 256 | 254 | */ |
| 257 | 255 | #ifndef SQLITE_EXTERN |
| 258 | 256 | # define SQLITE_EXTERN extern |
| 259 | 257 | #endif |
| 260 | | - |
| 261 | 258 | #ifndef SQLITE_API |
| 262 | 259 | # define SQLITE_API |
| 263 | 260 | #endif |
| 264 | | - |
| 265 | | - |
| 266 | | -/* |
| 267 | | -** Add the ability to override 'cdecl' |
| 268 | | -*/ |
| 269 | 261 | #ifndef SQLITE_CDECL |
| 270 | 262 | # define SQLITE_CDECL |
| 271 | 263 | #endif |
| 264 | +#ifndef SQLITE_STDCALL |
| 265 | +# define SQLITE_STDCALL |
| 266 | +#endif |
| 272 | 267 | |
| 273 | 268 | /* |
| 274 | 269 | ** These no-op macros are used in front of interfaces to mark those |
| 275 | 270 | ** interfaces as either deprecated or experimental. New applications |
| 276 | 271 | ** should not use deprecated interfaces - they are supported for backwards |
| | @@ -321,13 +316,13 @@ |
| 321 | 316 | ** |
| 322 | 317 | ** See also: [sqlite3_libversion()], |
| 323 | 318 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 324 | 319 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 325 | 320 | */ |
| 326 | | -#define SQLITE_VERSION "3.8.9" |
| 327 | | -#define SQLITE_VERSION_NUMBER 3008009 |
| 328 | | -#define SQLITE_SOURCE_ID "2015-03-24 18:19:39 436314b5728c9413f9ac2d837e1c19364f31be72" |
| 321 | +#define SQLITE_VERSION "3.8.10.1" |
| 322 | +#define SQLITE_VERSION_NUMBER 3008010 |
| 323 | +#define SQLITE_SOURCE_ID "2015-05-09 12:14:55 05b4b1f2a937c06c90db70c09890038f6c98ec40" |
| 329 | 324 | |
| 330 | 325 | /* |
| 331 | 326 | ** CAPI3REF: Run-Time Library Version Numbers |
| 332 | 327 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 333 | 328 | ** |
| | @@ -356,13 +351,13 @@ |
| 356 | 351 | ** [SQLITE_SOURCE_ID] C preprocessor macro. |
| 357 | 352 | ** |
| 358 | 353 | ** See also: [sqlite_version()] and [sqlite_source_id()]. |
| 359 | 354 | */ |
| 360 | 355 | SQLITE_API const char sqlite3_version[] = SQLITE_VERSION; |
| 361 | | -SQLITE_API const char *sqlite3_libversion(void); |
| 362 | | -SQLITE_API const char *sqlite3_sourceid(void); |
| 363 | | -SQLITE_API int sqlite3_libversion_number(void); |
| 356 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_libversion(void); |
| 357 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_sourceid(void); |
| 358 | +SQLITE_API int SQLITE_STDCALL sqlite3_libversion_number(void); |
| 364 | 359 | |
| 365 | 360 | /* |
| 366 | 361 | ** CAPI3REF: Run-Time Library Compilation Options Diagnostics |
| 367 | 362 | ** |
| 368 | 363 | ** ^The sqlite3_compileoption_used() function returns 0 or 1 |
| | @@ -383,12 +378,12 @@ |
| 383 | 378 | ** |
| 384 | 379 | ** See also: SQL functions [sqlite_compileoption_used()] and |
| 385 | 380 | ** [sqlite_compileoption_get()] and the [compile_options pragma]. |
| 386 | 381 | */ |
| 387 | 382 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 388 | | -SQLITE_API int sqlite3_compileoption_used(const char *zOptName); |
| 389 | | -SQLITE_API const char *sqlite3_compileoption_get(int N); |
| 383 | +SQLITE_API int SQLITE_STDCALL sqlite3_compileoption_used(const char *zOptName); |
| 384 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_compileoption_get(int N); |
| 390 | 385 | #endif |
| 391 | 386 | |
| 392 | 387 | /* |
| 393 | 388 | ** CAPI3REF: Test To See If The Library Is Threadsafe |
| 394 | 389 | ** |
| | @@ -423,11 +418,11 @@ |
| 423 | 418 | ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() |
| 424 | 419 | ** is unchanged by calls to sqlite3_config().)^ |
| 425 | 420 | ** |
| 426 | 421 | ** See the [threading mode] documentation for additional information. |
| 427 | 422 | */ |
| 428 | | -SQLITE_API int sqlite3_threadsafe(void); |
| 423 | +SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void); |
| 429 | 424 | |
| 430 | 425 | /* |
| 431 | 426 | ** CAPI3REF: Database Connection Handle |
| 432 | 427 | ** KEYWORDS: {database connection} {database connections} |
| 433 | 428 | ** |
| | @@ -480,10 +475,11 @@ |
| 480 | 475 | # define double sqlite3_int64 |
| 481 | 476 | #endif |
| 482 | 477 | |
| 483 | 478 | /* |
| 484 | 479 | ** CAPI3REF: Closing A Database Connection |
| 480 | +** DESTRUCTOR: sqlite3 |
| 485 | 481 | ** |
| 486 | 482 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 487 | 483 | ** for the [sqlite3] object. |
| 488 | 484 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
| 489 | 485 | ** the [sqlite3] object is successfully destroyed and all associated |
| | @@ -519,12 +515,12 @@ |
| 519 | 515 | ** from [sqlite3_open()], [sqlite3_open16()], or |
| 520 | 516 | ** [sqlite3_open_v2()], and not previously closed. |
| 521 | 517 | ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer |
| 522 | 518 | ** argument is a harmless no-op. |
| 523 | 519 | */ |
| 524 | | -SQLITE_API int sqlite3_close(sqlite3*); |
| 525 | | -SQLITE_API int sqlite3_close_v2(sqlite3*); |
| 520 | +SQLITE_API int SQLITE_STDCALL sqlite3_close(sqlite3*); |
| 521 | +SQLITE_API int SQLITE_STDCALL sqlite3_close_v2(sqlite3*); |
| 526 | 522 | |
| 527 | 523 | /* |
| 528 | 524 | ** The type for a callback function. |
| 529 | 525 | ** This is legacy and deprecated. It is included for historical |
| 530 | 526 | ** compatibility and is not documented. |
| | @@ -531,10 +527,11 @@ |
| 531 | 527 | */ |
| 532 | 528 | typedef int (*sqlite3_callback)(void*,int,char**, char**); |
| 533 | 529 | |
| 534 | 530 | /* |
| 535 | 531 | ** CAPI3REF: One-Step Query Execution Interface |
| 532 | +** METHOD: sqlite3 |
| 536 | 533 | ** |
| 537 | 534 | ** The sqlite3_exec() interface is a convenience wrapper around |
| 538 | 535 | ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], |
| 539 | 536 | ** that allows an application to run multiple statements of SQL |
| 540 | 537 | ** without having to use a lot of C code. |
| | @@ -590,11 +587,11 @@ |
| 590 | 587 | ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. |
| 591 | 588 | ** <li> The application must not modify the SQL statement text passed into |
| 592 | 589 | ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. |
| 593 | 590 | ** </ul> |
| 594 | 591 | */ |
| 595 | | -SQLITE_API int sqlite3_exec( |
| 592 | +SQLITE_API int SQLITE_STDCALL sqlite3_exec( |
| 596 | 593 | sqlite3*, /* An open database */ |
| 597 | 594 | const char *sql, /* SQL to be evaluated */ |
| 598 | 595 | int (*callback)(void*,int,char**,char**), /* Callback function */ |
| 599 | 596 | void *, /* 1st argument to callback */ |
| 600 | 597 | char **errmsg /* Error msg written here */ |
| | @@ -1550,14 +1547,14 @@ |
| 1550 | 1547 | ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied |
| 1551 | 1548 | ** implementation of sqlite3_os_init() or sqlite3_os_end() |
| 1552 | 1549 | ** must return [SQLITE_OK] on success and some other [error code] upon |
| 1553 | 1550 | ** failure. |
| 1554 | 1551 | */ |
| 1555 | | -SQLITE_API int sqlite3_initialize(void); |
| 1556 | | -SQLITE_API int sqlite3_shutdown(void); |
| 1557 | | -SQLITE_API int sqlite3_os_init(void); |
| 1558 | | -SQLITE_API int sqlite3_os_end(void); |
| 1552 | +SQLITE_API int SQLITE_STDCALL sqlite3_initialize(void); |
| 1553 | +SQLITE_API int SQLITE_STDCALL sqlite3_shutdown(void); |
| 1554 | +SQLITE_API int SQLITE_STDCALL sqlite3_os_init(void); |
| 1555 | +SQLITE_API int SQLITE_STDCALL sqlite3_os_end(void); |
| 1559 | 1556 | |
| 1560 | 1557 | /* |
| 1561 | 1558 | ** CAPI3REF: Configuring The SQLite Library |
| 1562 | 1559 | ** |
| 1563 | 1560 | ** The sqlite3_config() interface is used to make global configuration |
| | @@ -1584,14 +1581,15 @@ |
| 1584 | 1581 | ** |
| 1585 | 1582 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 1586 | 1583 | ** ^If the option is unknown or SQLite is unable to set the option |
| 1587 | 1584 | ** then this routine returns a non-zero [error code]. |
| 1588 | 1585 | */ |
| 1589 | | -SQLITE_API int sqlite3_config(int, ...); |
| 1586 | +SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...); |
| 1590 | 1587 | |
| 1591 | 1588 | /* |
| 1592 | 1589 | ** CAPI3REF: Configure database connections |
| 1590 | +** METHOD: sqlite3 |
| 1593 | 1591 | ** |
| 1594 | 1592 | ** The sqlite3_db_config() interface is used to make configuration |
| 1595 | 1593 | ** changes to a [database connection]. The interface is similar to |
| 1596 | 1594 | ** [sqlite3_config()] except that the changes apply to a single |
| 1597 | 1595 | ** [database connection] (specified in the first argument). |
| | @@ -1602,11 +1600,11 @@ |
| 1602 | 1600 | ** Subsequent arguments vary depending on the configuration verb. |
| 1603 | 1601 | ** |
| 1604 | 1602 | ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if |
| 1605 | 1603 | ** the call is considered successful. |
| 1606 | 1604 | */ |
| 1607 | | -SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...); |
| 1605 | +SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3*, int op, ...); |
| 1608 | 1606 | |
| 1609 | 1607 | /* |
| 1610 | 1608 | ** CAPI3REF: Memory Allocation Routines |
| 1611 | 1609 | ** |
| 1612 | 1610 | ** An instance of this object defines the interface between SQLite |
| | @@ -2085,19 +2083,21 @@ |
| 2085 | 2083 | #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ |
| 2086 | 2084 | |
| 2087 | 2085 | |
| 2088 | 2086 | /* |
| 2089 | 2087 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
| 2088 | +** METHOD: sqlite3 |
| 2090 | 2089 | ** |
| 2091 | 2090 | ** ^The sqlite3_extended_result_codes() routine enables or disables the |
| 2092 | 2091 | ** [extended result codes] feature of SQLite. ^The extended result |
| 2093 | 2092 | ** codes are disabled by default for historical compatibility. |
| 2094 | 2093 | */ |
| 2095 | | -SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); |
| 2094 | +SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff); |
| 2096 | 2095 | |
| 2097 | 2096 | /* |
| 2098 | 2097 | ** CAPI3REF: Last Insert Rowid |
| 2098 | +** METHOD: sqlite3 |
| 2099 | 2099 | ** |
| 2100 | 2100 | ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) |
| 2101 | 2101 | ** has a unique 64-bit signed |
| 2102 | 2102 | ** integer key called the [ROWID | "rowid"]. ^The rowid is always available |
| 2103 | 2103 | ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those |
| | @@ -2141,14 +2141,15 @@ |
| 2141 | 2141 | ** function is running and thus changes the last insert [rowid], |
| 2142 | 2142 | ** then the value returned by [sqlite3_last_insert_rowid()] is |
| 2143 | 2143 | ** unpredictable and might not equal either the old or the new |
| 2144 | 2144 | ** last insert [rowid]. |
| 2145 | 2145 | */ |
| 2146 | | -SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); |
| 2146 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*); |
| 2147 | 2147 | |
| 2148 | 2148 | /* |
| 2149 | 2149 | ** CAPI3REF: Count The Number Of Rows Modified |
| 2150 | +** METHOD: sqlite3 |
| 2150 | 2151 | ** |
| 2151 | 2152 | ** ^This function returns the number of rows modified, inserted or |
| 2152 | 2153 | ** deleted by the most recently completed INSERT, UPDATE or DELETE |
| 2153 | 2154 | ** statement on the database connection specified by the only parameter. |
| 2154 | 2155 | ** ^Executing any other type of SQL statement does not modify the value |
| | @@ -2193,14 +2194,15 @@ |
| 2193 | 2194 | ** |
| 2194 | 2195 | ** If a separate thread makes changes on the same database connection |
| 2195 | 2196 | ** while [sqlite3_changes()] is running then the value returned |
| 2196 | 2197 | ** is unpredictable and not meaningful. |
| 2197 | 2198 | */ |
| 2198 | | -SQLITE_API int sqlite3_changes(sqlite3*); |
| 2199 | +SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*); |
| 2199 | 2200 | |
| 2200 | 2201 | /* |
| 2201 | 2202 | ** CAPI3REF: Total Number Of Rows Modified |
| 2203 | +** METHOD: sqlite3 |
| 2202 | 2204 | ** |
| 2203 | 2205 | ** ^This function returns the total number of rows inserted, modified or |
| 2204 | 2206 | ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
| 2205 | 2207 | ** since the database connection was opened, including those executed as |
| 2206 | 2208 | ** part of trigger programs. ^Executing any other type of SQL statement |
| | @@ -2216,14 +2218,15 @@ |
| 2216 | 2218 | ** |
| 2217 | 2219 | ** If a separate thread makes changes on the same database connection |
| 2218 | 2220 | ** while [sqlite3_total_changes()] is running then the value |
| 2219 | 2221 | ** returned is unpredictable and not meaningful. |
| 2220 | 2222 | */ |
| 2221 | | -SQLITE_API int sqlite3_total_changes(sqlite3*); |
| 2223 | +SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*); |
| 2222 | 2224 | |
| 2223 | 2225 | /* |
| 2224 | 2226 | ** CAPI3REF: Interrupt A Long-Running Query |
| 2227 | +** METHOD: sqlite3 |
| 2225 | 2228 | ** |
| 2226 | 2229 | ** ^This function causes any pending database operation to abort and |
| 2227 | 2230 | ** return at its earliest opportunity. This routine is typically |
| 2228 | 2231 | ** called in response to a user action such as pressing "Cancel" |
| 2229 | 2232 | ** or Ctrl-C where the user wants a long query operation to halt |
| | @@ -2255,11 +2258,11 @@ |
| 2255 | 2258 | ** that are started after the sqlite3_interrupt() call returns. |
| 2256 | 2259 | ** |
| 2257 | 2260 | ** If the database connection closes while [sqlite3_interrupt()] |
| 2258 | 2261 | ** is running then bad things will likely happen. |
| 2259 | 2262 | */ |
| 2260 | | -SQLITE_API void sqlite3_interrupt(sqlite3*); |
| 2263 | +SQLITE_API void SQLITE_STDCALL sqlite3_interrupt(sqlite3*); |
| 2261 | 2264 | |
| 2262 | 2265 | /* |
| 2263 | 2266 | ** CAPI3REF: Determine If An SQL Statement Is Complete |
| 2264 | 2267 | ** |
| 2265 | 2268 | ** These routines are useful during command-line input to determine if the |
| | @@ -2290,16 +2293,17 @@ |
| 2290 | 2293 | ** UTF-8 string. |
| 2291 | 2294 | ** |
| 2292 | 2295 | ** The input to [sqlite3_complete16()] must be a zero-terminated |
| 2293 | 2296 | ** UTF-16 string in native byte order. |
| 2294 | 2297 | */ |
| 2295 | | -SQLITE_API int sqlite3_complete(const char *sql); |
| 2296 | | -SQLITE_API int sqlite3_complete16(const void *sql); |
| 2298 | +SQLITE_API int SQLITE_STDCALL sqlite3_complete(const char *sql); |
| 2299 | +SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql); |
| 2297 | 2300 | |
| 2298 | 2301 | /* |
| 2299 | 2302 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2300 | 2303 | ** KEYWORDS: {busy-handler callback} {busy handler} |
| 2304 | +** METHOD: sqlite3 |
| 2301 | 2305 | ** |
| 2302 | 2306 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2303 | 2307 | ** that might be invoked with argument P whenever |
| 2304 | 2308 | ** an attempt is made to access a database table associated with |
| 2305 | 2309 | ** [database connection] D when another thread |
| | @@ -2351,14 +2355,15 @@ |
| 2351 | 2355 | ** result in undefined behavior. |
| 2352 | 2356 | ** |
| 2353 | 2357 | ** A busy handler must not close the database connection |
| 2354 | 2358 | ** or [prepared statement] that invoked the busy handler. |
| 2355 | 2359 | */ |
| 2356 | | -SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); |
| 2360 | +SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); |
| 2357 | 2361 | |
| 2358 | 2362 | /* |
| 2359 | 2363 | ** CAPI3REF: Set A Busy Timeout |
| 2364 | +** METHOD: sqlite3 |
| 2360 | 2365 | ** |
| 2361 | 2366 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2362 | 2367 | ** for a specified amount of time when a table is locked. ^The handler |
| 2363 | 2368 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2364 | 2369 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| | @@ -2373,14 +2378,15 @@ |
| 2373 | 2378 | ** was defined (using [sqlite3_busy_handler()]) prior to calling |
| 2374 | 2379 | ** this routine, that other busy handler is cleared.)^ |
| 2375 | 2380 | ** |
| 2376 | 2381 | ** See also: [PRAGMA busy_timeout] |
| 2377 | 2382 | */ |
| 2378 | | -SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); |
| 2383 | +SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms); |
| 2379 | 2384 | |
| 2380 | 2385 | /* |
| 2381 | 2386 | ** CAPI3REF: Convenience Routines For Running Queries |
| 2387 | +** METHOD: sqlite3 |
| 2382 | 2388 | ** |
| 2383 | 2389 | ** This is a legacy interface that is preserved for backwards compatibility. |
| 2384 | 2390 | ** Use of this interface is not recommended. |
| 2385 | 2391 | ** |
| 2386 | 2392 | ** Definition: A <b>result table</b> is memory data structure created by the |
| | @@ -2447,19 +2453,19 @@ |
| 2447 | 2453 | ** interface defined here. As a consequence, errors that occur in the |
| 2448 | 2454 | ** wrapper layer outside of the internal [sqlite3_exec()] call are not |
| 2449 | 2455 | ** reflected in subsequent calls to [sqlite3_errcode()] or |
| 2450 | 2456 | ** [sqlite3_errmsg()]. |
| 2451 | 2457 | */ |
| 2452 | | -SQLITE_API int sqlite3_get_table( |
| 2458 | +SQLITE_API int SQLITE_STDCALL sqlite3_get_table( |
| 2453 | 2459 | sqlite3 *db, /* An open database */ |
| 2454 | 2460 | const char *zSql, /* SQL to be evaluated */ |
| 2455 | 2461 | char ***pazResult, /* Results of the query */ |
| 2456 | 2462 | int *pnRow, /* Number of result rows written here */ |
| 2457 | 2463 | int *pnColumn, /* Number of result columns written here */ |
| 2458 | 2464 | char **pzErrmsg /* Error msg written here */ |
| 2459 | 2465 | ); |
| 2460 | | -SQLITE_API void sqlite3_free_table(char **result); |
| 2466 | +SQLITE_API void SQLITE_STDCALL sqlite3_free_table(char **result); |
| 2461 | 2467 | |
| 2462 | 2468 | /* |
| 2463 | 2469 | ** CAPI3REF: Formatted String Printing Functions |
| 2464 | 2470 | ** |
| 2465 | 2471 | ** These routines are work-alikes of the "printf()" family of functions |
| | @@ -2561,14 +2567,14 @@ |
| 2561 | 2567 | ** |
| 2562 | 2568 | ** ^(The "%z" formatting option works like "%s" but with the |
| 2563 | 2569 | ** addition that after the string has been read and copied into |
| 2564 | 2570 | ** the result, [sqlite3_free()] is called on the input string.)^ |
| 2565 | 2571 | */ |
| 2566 | | -SQLITE_API char *sqlite3_mprintf(const char*,...); |
| 2567 | | -SQLITE_API char *sqlite3_vmprintf(const char*, va_list); |
| 2568 | | -SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); |
| 2569 | | -SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); |
| 2572 | +SQLITE_API char *SQLITE_CDECL sqlite3_mprintf(const char*,...); |
| 2573 | +SQLITE_API char *SQLITE_STDCALL sqlite3_vmprintf(const char*, va_list); |
| 2574 | +SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int,char*,const char*, ...); |
| 2575 | +SQLITE_API char *SQLITE_STDCALL sqlite3_vsnprintf(int,char*,const char*, va_list); |
| 2570 | 2576 | |
| 2571 | 2577 | /* |
| 2572 | 2578 | ** CAPI3REF: Memory Allocation Subsystem |
| 2573 | 2579 | ** |
| 2574 | 2580 | ** The SQLite core uses these three routines for all of its own |
| | @@ -2654,16 +2660,16 @@ |
| 2654 | 2660 | ** |
| 2655 | 2661 | ** The application must not read or write any part of |
| 2656 | 2662 | ** a block of memory after it has been released using |
| 2657 | 2663 | ** [sqlite3_free()] or [sqlite3_realloc()]. |
| 2658 | 2664 | */ |
| 2659 | | -SQLITE_API void *sqlite3_malloc(int); |
| 2660 | | -SQLITE_API void *sqlite3_malloc64(sqlite3_uint64); |
| 2661 | | -SQLITE_API void *sqlite3_realloc(void*, int); |
| 2662 | | -SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64); |
| 2663 | | -SQLITE_API void sqlite3_free(void*); |
| 2664 | | -SQLITE_API sqlite3_uint64 sqlite3_msize(void*); |
| 2665 | +SQLITE_API void *SQLITE_STDCALL sqlite3_malloc(int); |
| 2666 | +SQLITE_API void *SQLITE_STDCALL sqlite3_malloc64(sqlite3_uint64); |
| 2667 | +SQLITE_API void *SQLITE_STDCALL sqlite3_realloc(void*, int); |
| 2668 | +SQLITE_API void *SQLITE_STDCALL sqlite3_realloc64(void*, sqlite3_uint64); |
| 2669 | +SQLITE_API void SQLITE_STDCALL sqlite3_free(void*); |
| 2670 | +SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void*); |
| 2665 | 2671 | |
| 2666 | 2672 | /* |
| 2667 | 2673 | ** CAPI3REF: Memory Allocator Statistics |
| 2668 | 2674 | ** |
| 2669 | 2675 | ** SQLite provides these two interfaces for reporting on the status |
| | @@ -2684,12 +2690,12 @@ |
| 2684 | 2690 | ** [sqlite3_memory_used()] if and only if the parameter to |
| 2685 | 2691 | ** [sqlite3_memory_highwater()] is true. ^The value returned |
| 2686 | 2692 | ** by [sqlite3_memory_highwater(1)] is the high-water mark |
| 2687 | 2693 | ** prior to the reset. |
| 2688 | 2694 | */ |
| 2689 | | -SQLITE_API sqlite3_int64 sqlite3_memory_used(void); |
| 2690 | | -SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); |
| 2695 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_used(void); |
| 2696 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag); |
| 2691 | 2697 | |
| 2692 | 2698 | /* |
| 2693 | 2699 | ** CAPI3REF: Pseudo-Random Number Generator |
| 2694 | 2700 | ** |
| 2695 | 2701 | ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to |
| | @@ -2708,14 +2714,15 @@ |
| 2708 | 2714 | ** ^If the previous call to this routine had an N of 1 or more and a |
| 2709 | 2715 | ** non-NULL P then the pseudo-randomness is generated |
| 2710 | 2716 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2711 | 2717 | ** method. |
| 2712 | 2718 | */ |
| 2713 | | -SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2719 | +SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P); |
| 2714 | 2720 | |
| 2715 | 2721 | /* |
| 2716 | 2722 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2723 | +** METHOD: sqlite3 |
| 2717 | 2724 | ** |
| 2718 | 2725 | ** ^This routine registers an authorizer callback with a particular |
| 2719 | 2726 | ** [database connection], supplied in the first argument. |
| 2720 | 2727 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2721 | 2728 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| | @@ -2790,11 +2797,11 @@ |
| 2790 | 2797 | ** [sqlite3_prepare()] or its variants. Authorization is not |
| 2791 | 2798 | ** performed during statement evaluation in [sqlite3_step()], unless |
| 2792 | 2799 | ** as stated in the previous paragraph, sqlite3_step() invokes |
| 2793 | 2800 | ** sqlite3_prepare_v2() to reprepare a statement after a schema change. |
| 2794 | 2801 | */ |
| 2795 | | -SQLITE_API int sqlite3_set_authorizer( |
| 2802 | +SQLITE_API int SQLITE_STDCALL sqlite3_set_authorizer( |
| 2796 | 2803 | sqlite3*, |
| 2797 | 2804 | int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), |
| 2798 | 2805 | void *pUserData |
| 2799 | 2806 | ); |
| 2800 | 2807 | |
| | @@ -2868,10 +2875,11 @@ |
| 2868 | 2875 | #define SQLITE_COPY 0 /* No longer used */ |
| 2869 | 2876 | #define SQLITE_RECURSIVE 33 /* NULL NULL */ |
| 2870 | 2877 | |
| 2871 | 2878 | /* |
| 2872 | 2879 | ** CAPI3REF: Tracing And Profiling Functions |
| 2880 | +** METHOD: sqlite3 |
| 2873 | 2881 | ** |
| 2874 | 2882 | ** These routines register callback functions that can be used for |
| 2875 | 2883 | ** tracing and profiling the execution of SQL statements. |
| 2876 | 2884 | ** |
| 2877 | 2885 | ** ^The callback function registered by sqlite3_trace() is invoked at |
| | @@ -2894,16 +2902,17 @@ |
| 2894 | 2902 | ** digits in the time are meaningless. Future versions of SQLite |
| 2895 | 2903 | ** might provide greater resolution on the profiler callback. The |
| 2896 | 2904 | ** sqlite3_profile() function is considered experimental and is |
| 2897 | 2905 | ** subject to change in future versions of SQLite. |
| 2898 | 2906 | */ |
| 2899 | | -SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); |
| 2900 | | -SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*, |
| 2907 | +SQLITE_API void *SQLITE_STDCALL sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); |
| 2908 | +SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*, |
| 2901 | 2909 | void(*xProfile)(void*,const char*,sqlite3_uint64), void*); |
| 2902 | 2910 | |
| 2903 | 2911 | /* |
| 2904 | 2912 | ** CAPI3REF: Query Progress Callbacks |
| 2913 | +** METHOD: sqlite3 |
| 2905 | 2914 | ** |
| 2906 | 2915 | ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback |
| 2907 | 2916 | ** function X to be invoked periodically during long running calls to |
| 2908 | 2917 | ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for |
| 2909 | 2918 | ** database connection D. An example use for this |
| | @@ -2929,14 +2938,15 @@ |
| 2929 | 2938 | ** the database connection that invoked the progress handler. |
| 2930 | 2939 | ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their |
| 2931 | 2940 | ** database connections for the meaning of "modify" in this paragraph. |
| 2932 | 2941 | ** |
| 2933 | 2942 | */ |
| 2934 | | -SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2943 | +SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2935 | 2944 | |
| 2936 | 2945 | /* |
| 2937 | 2946 | ** CAPI3REF: Opening A New Database Connection |
| 2947 | +** CONSTRUCTOR: sqlite3 |
| 2938 | 2948 | ** |
| 2939 | 2949 | ** ^These routines open an SQLite database file as specified by the |
| 2940 | 2950 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2941 | 2951 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2942 | 2952 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| | @@ -3157,19 +3167,19 @@ |
| 3157 | 3167 | ** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various |
| 3158 | 3168 | ** features that require the use of temporary files may fail. |
| 3159 | 3169 | ** |
| 3160 | 3170 | ** See also: [sqlite3_temp_directory] |
| 3161 | 3171 | */ |
| 3162 | | -SQLITE_API int sqlite3_open( |
| 3172 | +SQLITE_API int SQLITE_STDCALL sqlite3_open( |
| 3163 | 3173 | const char *filename, /* Database filename (UTF-8) */ |
| 3164 | 3174 | sqlite3 **ppDb /* OUT: SQLite db handle */ |
| 3165 | 3175 | ); |
| 3166 | | -SQLITE_API int sqlite3_open16( |
| 3176 | +SQLITE_API int SQLITE_STDCALL sqlite3_open16( |
| 3167 | 3177 | const void *filename, /* Database filename (UTF-16) */ |
| 3168 | 3178 | sqlite3 **ppDb /* OUT: SQLite db handle */ |
| 3169 | 3179 | ); |
| 3170 | | -SQLITE_API int sqlite3_open_v2( |
| 3180 | +SQLITE_API int SQLITE_STDCALL sqlite3_open_v2( |
| 3171 | 3181 | const char *filename, /* Database filename (UTF-8) */ |
| 3172 | 3182 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 3173 | 3183 | int flags, /* Flags */ |
| 3174 | 3184 | const char *zVfs /* Name of VFS module to use */ |
| 3175 | 3185 | ); |
| | @@ -3211,17 +3221,18 @@ |
| 3211 | 3221 | ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and |
| 3212 | 3222 | ** is not a database file pathname pointer that SQLite passed into the xOpen |
| 3213 | 3223 | ** VFS method, then the behavior of this routine is undefined and probably |
| 3214 | 3224 | ** undesirable. |
| 3215 | 3225 | */ |
| 3216 | | -SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); |
| 3217 | | -SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault); |
| 3218 | | -SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64); |
| 3226 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_uri_parameter(const char *zFilename, const char *zParam); |
| 3227 | +SQLITE_API int SQLITE_STDCALL sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault); |
| 3228 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64); |
| 3219 | 3229 | |
| 3220 | 3230 | |
| 3221 | 3231 | /* |
| 3222 | 3232 | ** CAPI3REF: Error Codes And Messages |
| 3233 | +** METHOD: sqlite3 |
| 3223 | 3234 | ** |
| 3224 | 3235 | ** ^If the most recent sqlite3_* API call associated with |
| 3225 | 3236 | ** [database connection] D failed, then the sqlite3_errcode(D) interface |
| 3226 | 3237 | ** returns the numeric [result code] or [extended result code] for that |
| 3227 | 3238 | ** API call. |
| | @@ -3256,44 +3267,45 @@ |
| 3256 | 3267 | ** |
| 3257 | 3268 | ** If an interface fails with SQLITE_MISUSE, that means the interface |
| 3258 | 3269 | ** was invoked incorrectly by the application. In that case, the |
| 3259 | 3270 | ** error code and message may or may not be set. |
| 3260 | 3271 | */ |
| 3261 | | -SQLITE_API int sqlite3_errcode(sqlite3 *db); |
| 3262 | | -SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); |
| 3263 | | -SQLITE_API const char *sqlite3_errmsg(sqlite3*); |
| 3264 | | -SQLITE_API const void *sqlite3_errmsg16(sqlite3*); |
| 3265 | | -SQLITE_API const char *sqlite3_errstr(int); |
| 3272 | +SQLITE_API int SQLITE_STDCALL sqlite3_errcode(sqlite3 *db); |
| 3273 | +SQLITE_API int SQLITE_STDCALL sqlite3_extended_errcode(sqlite3 *db); |
| 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); |
| 3266 | 3277 | |
| 3267 | 3278 | /* |
| 3268 | | -** CAPI3REF: SQL Statement Object |
| 3279 | +** CAPI3REF: Prepared Statement Object |
| 3269 | 3280 | ** KEYWORDS: {prepared statement} {prepared statements} |
| 3270 | 3281 | ** |
| 3271 | | -** An instance of this object represents a single SQL statement. |
| 3272 | | -** This object is variously known as a "prepared statement" or a |
| 3273 | | -** "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. |
| 3274 | 3284 | ** |
| 3275 | | -** 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: |
| 3276 | 3291 | ** |
| 3277 | 3292 | ** <ol> |
| 3278 | | -** <li> Create the object using [sqlite3_prepare_v2()] or a related |
| 3279 | | -** function. |
| 3280 | | -** <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_*() |
| 3281 | 3295 | ** interfaces. |
| 3282 | 3296 | ** <li> Run the SQL by calling [sqlite3_step()] one or more times. |
| 3283 | | -** <li> Reset the statement using [sqlite3_reset()] then go back |
| 3297 | +** <li> Reset the prepared statement using [sqlite3_reset()] then go back |
| 3284 | 3298 | ** to step 2. Do this zero or more times. |
| 3285 | 3299 | ** <li> Destroy the object using [sqlite3_finalize()]. |
| 3286 | 3300 | ** </ol> |
| 3287 | | -** |
| 3288 | | -** Refer to documentation on individual methods above for additional |
| 3289 | | -** information. |
| 3290 | 3301 | */ |
| 3291 | 3302 | typedef struct sqlite3_stmt sqlite3_stmt; |
| 3292 | 3303 | |
| 3293 | 3304 | /* |
| 3294 | 3305 | ** CAPI3REF: Run-time Limits |
| 3306 | +** METHOD: sqlite3 |
| 3295 | 3307 | ** |
| 3296 | 3308 | ** ^(This interface allows the size of various constructs to be limited |
| 3297 | 3309 | ** on a connection by connection basis. The first parameter is the |
| 3298 | 3310 | ** [database connection] whose limit is to be set or queried. The |
| 3299 | 3311 | ** second parameter is one of the [limit categories] that define a |
| | @@ -3327,11 +3339,11 @@ |
| 3327 | 3339 | ** created by an untrusted script can be contained using the |
| 3328 | 3340 | ** [max_page_count] [PRAGMA]. |
| 3329 | 3341 | ** |
| 3330 | 3342 | ** New run-time limit categories may be added in future releases. |
| 3331 | 3343 | */ |
| 3332 | | -SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); |
| 3344 | +SQLITE_API int SQLITE_STDCALL sqlite3_limit(sqlite3*, int id, int newVal); |
| 3333 | 3345 | |
| 3334 | 3346 | /* |
| 3335 | 3347 | ** CAPI3REF: Run-Time Limit Categories |
| 3336 | 3348 | ** KEYWORDS: {limit category} {*limit categories} |
| 3337 | 3349 | ** |
| | @@ -3401,10 +3413,12 @@ |
| 3401 | 3413 | #define SQLITE_LIMIT_WORKER_THREADS 11 |
| 3402 | 3414 | |
| 3403 | 3415 | /* |
| 3404 | 3416 | ** CAPI3REF: Compiling An SQL Statement |
| 3405 | 3417 | ** KEYWORDS: {SQL statement compiler} |
| 3418 | +** METHOD: sqlite3 |
| 3419 | +** CONSTRUCTOR: sqlite3_stmt |
| 3406 | 3420 | ** |
| 3407 | 3421 | ** To execute an SQL query, it must first be compiled into a byte-code |
| 3408 | 3422 | ** program using one of these routines. |
| 3409 | 3423 | ** |
| 3410 | 3424 | ** The first argument, "db", is a [database connection] obtained from a |
| | @@ -3477,50 +3491,52 @@ |
| 3477 | 3491 | ** or [GLOB] operator or if the parameter is compared to an indexed column |
| 3478 | 3492 | ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled. |
| 3479 | 3493 | ** </li> |
| 3480 | 3494 | ** </ol> |
| 3481 | 3495 | */ |
| 3482 | | -SQLITE_API int sqlite3_prepare( |
| 3496 | +SQLITE_API int SQLITE_STDCALL sqlite3_prepare( |
| 3483 | 3497 | sqlite3 *db, /* Database handle */ |
| 3484 | 3498 | const char *zSql, /* SQL statement, UTF-8 encoded */ |
| 3485 | 3499 | int nByte, /* Maximum length of zSql in bytes. */ |
| 3486 | 3500 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
| 3487 | 3501 | const char **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3488 | 3502 | ); |
| 3489 | | -SQLITE_API int sqlite3_prepare_v2( |
| 3503 | +SQLITE_API int SQLITE_STDCALL sqlite3_prepare_v2( |
| 3490 | 3504 | sqlite3 *db, /* Database handle */ |
| 3491 | 3505 | const char *zSql, /* SQL statement, UTF-8 encoded */ |
| 3492 | 3506 | int nByte, /* Maximum length of zSql in bytes. */ |
| 3493 | 3507 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
| 3494 | 3508 | const char **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3495 | 3509 | ); |
| 3496 | | -SQLITE_API int sqlite3_prepare16( |
| 3510 | +SQLITE_API int SQLITE_STDCALL sqlite3_prepare16( |
| 3497 | 3511 | sqlite3 *db, /* Database handle */ |
| 3498 | 3512 | const void *zSql, /* SQL statement, UTF-16 encoded */ |
| 3499 | 3513 | int nByte, /* Maximum length of zSql in bytes. */ |
| 3500 | 3514 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
| 3501 | 3515 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3502 | 3516 | ); |
| 3503 | | -SQLITE_API int sqlite3_prepare16_v2( |
| 3517 | +SQLITE_API int SQLITE_STDCALL sqlite3_prepare16_v2( |
| 3504 | 3518 | sqlite3 *db, /* Database handle */ |
| 3505 | 3519 | const void *zSql, /* SQL statement, UTF-16 encoded */ |
| 3506 | 3520 | int nByte, /* Maximum length of zSql in bytes. */ |
| 3507 | 3521 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
| 3508 | 3522 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3509 | 3523 | ); |
| 3510 | 3524 | |
| 3511 | 3525 | /* |
| 3512 | 3526 | ** CAPI3REF: Retrieving Statement SQL |
| 3527 | +** METHOD: sqlite3_stmt |
| 3513 | 3528 | ** |
| 3514 | 3529 | ** ^This interface can be used to retrieve a saved copy of the original |
| 3515 | 3530 | ** SQL text used to create a [prepared statement] if that statement was |
| 3516 | 3531 | ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. |
| 3517 | 3532 | */ |
| 3518 | | -SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); |
| 3533 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt); |
| 3519 | 3534 | |
| 3520 | 3535 | /* |
| 3521 | 3536 | ** CAPI3REF: Determine If An SQL Statement Writes The Database |
| 3537 | +** METHOD: sqlite3_stmt |
| 3522 | 3538 | ** |
| 3523 | 3539 | ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if |
| 3524 | 3540 | ** and only if the [prepared statement] X makes no direct changes to |
| 3525 | 3541 | ** the content of the database file. |
| 3526 | 3542 | ** |
| | @@ -3544,14 +3560,15 @@ |
| 3544 | 3560 | ** database. ^The [ATTACH] and [DETACH] statements also cause |
| 3545 | 3561 | ** sqlite3_stmt_readonly() to return true since, while those statements |
| 3546 | 3562 | ** change the configuration of a database connection, they do not make |
| 3547 | 3563 | ** changes to the content of the database files on disk. |
| 3548 | 3564 | */ |
| 3549 | | -SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
| 3565 | +SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
| 3550 | 3566 | |
| 3551 | 3567 | /* |
| 3552 | 3568 | ** CAPI3REF: Determine If A Prepared Statement Has Been Reset |
| 3569 | +** METHOD: sqlite3_stmt |
| 3553 | 3570 | ** |
| 3554 | 3571 | ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the |
| 3555 | 3572 | ** [prepared statement] S has been stepped at least once using |
| 3556 | 3573 | ** [sqlite3_step(S)] but has not run to completion and/or has not |
| 3557 | 3574 | ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) |
| | @@ -3563,11 +3580,11 @@ |
| 3563 | 3580 | ** to locate all prepared statements associated with a database |
| 3564 | 3581 | ** connection that are in need of being reset. This can be used, |
| 3565 | 3582 | ** for example, in diagnostic routines to search for prepared |
| 3566 | 3583 | ** statements that are holding a transaction open. |
| 3567 | 3584 | */ |
| 3568 | | -SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*); |
| 3585 | +SQLITE_API int SQLITE_STDCALL sqlite3_stmt_busy(sqlite3_stmt*); |
| 3569 | 3586 | |
| 3570 | 3587 | /* |
| 3571 | 3588 | ** CAPI3REF: Dynamically Typed Value Object |
| 3572 | 3589 | ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} |
| 3573 | 3590 | ** |
| | @@ -3622,10 +3639,11 @@ |
| 3622 | 3639 | |
| 3623 | 3640 | /* |
| 3624 | 3641 | ** CAPI3REF: Binding Values To Prepared Statements |
| 3625 | 3642 | ** KEYWORDS: {host parameter} {host parameters} {host parameter name} |
| 3626 | 3643 | ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} |
| 3644 | +** METHOD: sqlite3_stmt |
| 3627 | 3645 | ** |
| 3628 | 3646 | ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, |
| 3629 | 3647 | ** literals may be replaced by a [parameter] that matches one of following |
| 3630 | 3648 | ** templates: |
| 3631 | 3649 | ** |
| | @@ -3724,26 +3742,27 @@ |
| 3724 | 3742 | ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. |
| 3725 | 3743 | ** |
| 3726 | 3744 | ** See also: [sqlite3_bind_parameter_count()], |
| 3727 | 3745 | ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. |
| 3728 | 3746 | */ |
| 3729 | | -SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); |
| 3730 | | -SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64, |
| 3747 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); |
| 3748 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64, |
| 3731 | 3749 | void(*)(void*)); |
| 3732 | | -SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); |
| 3733 | | -SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); |
| 3734 | | -SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); |
| 3735 | | -SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); |
| 3736 | | -SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*)); |
| 3737 | | -SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); |
| 3738 | | -SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64, |
| 3750 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_double(sqlite3_stmt*, int, double); |
| 3751 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_int(sqlite3_stmt*, int, int); |
| 3752 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); |
| 3753 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_null(sqlite3_stmt*, int); |
| 3754 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*)); |
| 3755 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); |
| 3756 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64, |
| 3739 | 3757 | void(*)(void*), unsigned char encoding); |
| 3740 | | -SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); |
| 3741 | | -SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
| 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); |
| 3742 | 3760 | |
| 3743 | 3761 | /* |
| 3744 | 3762 | ** CAPI3REF: Number Of SQL Parameters |
| 3763 | +** METHOD: sqlite3_stmt |
| 3745 | 3764 | ** |
| 3746 | 3765 | ** ^This routine can be used to find the number of [SQL parameters] |
| 3747 | 3766 | ** in a [prepared statement]. SQL parameters are tokens of the |
| 3748 | 3767 | ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as |
| 3749 | 3768 | ** placeholders for values that are [sqlite3_bind_blob | bound] |
| | @@ -3756,14 +3775,15 @@ |
| 3756 | 3775 | ** |
| 3757 | 3776 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
| 3758 | 3777 | ** [sqlite3_bind_parameter_name()], and |
| 3759 | 3778 | ** [sqlite3_bind_parameter_index()]. |
| 3760 | 3779 | */ |
| 3761 | | -SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); |
| 3780 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*); |
| 3762 | 3781 | |
| 3763 | 3782 | /* |
| 3764 | 3783 | ** CAPI3REF: Name Of A Host Parameter |
| 3784 | +** METHOD: sqlite3_stmt |
| 3765 | 3785 | ** |
| 3766 | 3786 | ** ^The sqlite3_bind_parameter_name(P,N) interface returns |
| 3767 | 3787 | ** the name of the N-th [SQL parameter] in the [prepared statement] P. |
| 3768 | 3788 | ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| 3769 | 3789 | ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| | @@ -3783,14 +3803,15 @@ |
| 3783 | 3803 | ** |
| 3784 | 3804 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
| 3785 | 3805 | ** [sqlite3_bind_parameter_count()], and |
| 3786 | 3806 | ** [sqlite3_bind_parameter_index()]. |
| 3787 | 3807 | */ |
| 3788 | | -SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); |
| 3808 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int); |
| 3789 | 3809 | |
| 3790 | 3810 | /* |
| 3791 | 3811 | ** CAPI3REF: Index Of A Parameter With A Given Name |
| 3812 | +** METHOD: sqlite3_stmt |
| 3792 | 3813 | ** |
| 3793 | 3814 | ** ^Return the index of an SQL parameter given its name. ^The |
| 3794 | 3815 | ** index value returned is suitable for use as the second |
| 3795 | 3816 | ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero |
| 3796 | 3817 | ** is returned if no matching parameter is found. ^The parameter |
| | @@ -3799,34 +3820,37 @@ |
| 3799 | 3820 | ** |
| 3800 | 3821 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
| 3801 | 3822 | ** [sqlite3_bind_parameter_count()], and |
| 3802 | 3823 | ** [sqlite3_bind_parameter_index()]. |
| 3803 | 3824 | */ |
| 3804 | | -SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3825 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3805 | 3826 | |
| 3806 | 3827 | /* |
| 3807 | 3828 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| 3829 | +** METHOD: sqlite3_stmt |
| 3808 | 3830 | ** |
| 3809 | 3831 | ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset |
| 3810 | 3832 | ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. |
| 3811 | 3833 | ** ^Use this routine to reset all host parameters to NULL. |
| 3812 | 3834 | */ |
| 3813 | | -SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); |
| 3835 | +SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*); |
| 3814 | 3836 | |
| 3815 | 3837 | /* |
| 3816 | 3838 | ** CAPI3REF: Number Of Columns In A Result Set |
| 3839 | +** METHOD: sqlite3_stmt |
| 3817 | 3840 | ** |
| 3818 | 3841 | ** ^Return the number of columns in the result set returned by the |
| 3819 | 3842 | ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL |
| 3820 | 3843 | ** statement that does not return data (for example an [UPDATE]). |
| 3821 | 3844 | ** |
| 3822 | 3845 | ** See also: [sqlite3_data_count()] |
| 3823 | 3846 | */ |
| 3824 | | -SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); |
| 3847 | +SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt); |
| 3825 | 3848 | |
| 3826 | 3849 | /* |
| 3827 | 3850 | ** CAPI3REF: Column Names In A Result Set |
| 3851 | +** METHOD: sqlite3_stmt |
| 3828 | 3852 | ** |
| 3829 | 3853 | ** ^These routines return the name assigned to a particular column |
| 3830 | 3854 | ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() |
| 3831 | 3855 | ** interface returns a pointer to a zero-terminated UTF-8 string |
| 3832 | 3856 | ** and sqlite3_column_name16() returns a pointer to a zero-terminated |
| | @@ -3847,15 +3871,16 @@ |
| 3847 | 3871 | ** ^The name of a result column is the value of the "AS" clause for |
| 3848 | 3872 | ** that column, if there is an AS clause. If there is no AS clause |
| 3849 | 3873 | ** then the name of the column is unspecified and may change from |
| 3850 | 3874 | ** one release of SQLite to the next. |
| 3851 | 3875 | */ |
| 3852 | | -SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); |
| 3853 | | -SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); |
| 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); |
| 3854 | 3878 | |
| 3855 | 3879 | /* |
| 3856 | 3880 | ** CAPI3REF: Source Of Data In A Query Result |
| 3881 | +** METHOD: sqlite3_stmt |
| 3857 | 3882 | ** |
| 3858 | 3883 | ** ^These routines provide a means to determine the database, table, and |
| 3859 | 3884 | ** table column that is the origin of a particular result column in |
| 3860 | 3885 | ** [SELECT] statement. |
| 3861 | 3886 | ** ^The name of the database or table or column can be returned as |
| | @@ -3895,19 +3920,20 @@ |
| 3895 | 3920 | ** If two or more threads call one or more |
| 3896 | 3921 | ** [sqlite3_column_database_name | column metadata interfaces] |
| 3897 | 3922 | ** for the same [prepared statement] and result column |
| 3898 | 3923 | ** at the same time then the results are undefined. |
| 3899 | 3924 | */ |
| 3900 | | -SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); |
| 3901 | | -SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int); |
| 3902 | | -SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int); |
| 3903 | | -SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int); |
| 3904 | | -SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); |
| 3905 | | -SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); |
| 3925 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_column_database_name(sqlite3_stmt*,int); |
| 3926 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_column_database_name16(sqlite3_stmt*,int); |
| 3927 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_column_table_name(sqlite3_stmt*,int); |
| 3928 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_column_table_name16(sqlite3_stmt*,int); |
| 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); |
| 3906 | 3931 | |
| 3907 | 3932 | /* |
| 3908 | 3933 | ** CAPI3REF: Declared Datatype Of A Query Result |
| 3934 | +** METHOD: sqlite3_stmt |
| 3909 | 3935 | ** |
| 3910 | 3936 | ** ^(The first parameter is a [prepared statement]. |
| 3911 | 3937 | ** If this statement is a [SELECT] statement and the Nth column of the |
| 3912 | 3938 | ** returned result set of that [SELECT] is a table column (not an |
| 3913 | 3939 | ** expression or subquery) then the declared type of the table |
| | @@ -3931,15 +3957,16 @@ |
| 3931 | 3957 | ** data stored in that column is of the declared type. SQLite is |
| 3932 | 3958 | ** strongly typed, but the typing is dynamic not static. ^Type |
| 3933 | 3959 | ** is associated with individual values, not with the containers |
| 3934 | 3960 | ** used to hold those values. |
| 3935 | 3961 | */ |
| 3936 | | -SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); |
| 3937 | | -SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); |
| 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); |
| 3938 | 3964 | |
| 3939 | 3965 | /* |
| 3940 | 3966 | ** CAPI3REF: Evaluate An SQL Statement |
| 3967 | +** METHOD: sqlite3_stmt |
| 3941 | 3968 | ** |
| 3942 | 3969 | ** After a [prepared statement] has been prepared using either |
| 3943 | 3970 | ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy |
| 3944 | 3971 | ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function |
| 3945 | 3972 | ** must be called one or more times to evaluate the statement. |
| | @@ -4011,14 +4038,15 @@ |
| 4011 | 4038 | ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead |
| 4012 | 4039 | ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, |
| 4013 | 4040 | ** then the more specific [error codes] are returned directly |
| 4014 | 4041 | ** by sqlite3_step(). The use of the "v2" interface is recommended. |
| 4015 | 4042 | */ |
| 4016 | | -SQLITE_API int sqlite3_step(sqlite3_stmt*); |
| 4043 | +SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*); |
| 4017 | 4044 | |
| 4018 | 4045 | /* |
| 4019 | 4046 | ** CAPI3REF: Number of columns in a result set |
| 4047 | +** METHOD: sqlite3_stmt |
| 4020 | 4048 | ** |
| 4021 | 4049 | ** ^The sqlite3_data_count(P) interface returns the number of columns in the |
| 4022 | 4050 | ** current row of the result set of [prepared statement] P. |
| 4023 | 4051 | ** ^If prepared statement P does not have results ready to return |
| 4024 | 4052 | ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of |
| | @@ -4031,11 +4059,11 @@ |
| 4031 | 4059 | ** where it always returns zero since each step of that multi-step |
| 4032 | 4060 | ** pragma returns 0 columns of data. |
| 4033 | 4061 | ** |
| 4034 | 4062 | ** See also: [sqlite3_column_count()] |
| 4035 | 4063 | */ |
| 4036 | | -SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); |
| 4064 | +SQLITE_API int SQLITE_STDCALL sqlite3_data_count(sqlite3_stmt *pStmt); |
| 4037 | 4065 | |
| 4038 | 4066 | /* |
| 4039 | 4067 | ** CAPI3REF: Fundamental Datatypes |
| 4040 | 4068 | ** KEYWORDS: SQLITE_TEXT |
| 4041 | 4069 | ** |
| | @@ -4068,10 +4096,11 @@ |
| 4068 | 4096 | #define SQLITE3_TEXT 3 |
| 4069 | 4097 | |
| 4070 | 4098 | /* |
| 4071 | 4099 | ** CAPI3REF: Result Values From A Query |
| 4072 | 4100 | ** KEYWORDS: {column access functions} |
| 4101 | +** METHOD: sqlite3_stmt |
| 4073 | 4102 | ** |
| 4074 | 4103 | ** These routines form the "result set" interface. |
| 4075 | 4104 | ** |
| 4076 | 4105 | ** ^These routines return information about a single column of the current |
| 4077 | 4106 | ** result row of a query. ^In every case the first argument is a pointer |
| | @@ -4227,23 +4256,24 @@ |
| 4227 | 4256 | ** of these routines, a default value is returned. The default value |
| 4228 | 4257 | ** is either the integer 0, the floating point number 0.0, or a NULL |
| 4229 | 4258 | ** pointer. Subsequent calls to [sqlite3_errcode()] will return |
| 4230 | 4259 | ** [SQLITE_NOMEM].)^ |
| 4231 | 4260 | */ |
| 4232 | | -SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); |
| 4233 | | -SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); |
| 4234 | | -SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); |
| 4235 | | -SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); |
| 4236 | | -SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); |
| 4237 | | -SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); |
| 4238 | | -SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); |
| 4239 | | -SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); |
| 4240 | | -SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); |
| 4241 | | -SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); |
| 4261 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_column_blob(sqlite3_stmt*, int iCol); |
| 4262 | +SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes(sqlite3_stmt*, int iCol); |
| 4263 | +SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes16(sqlite3_stmt*, int iCol); |
| 4264 | +SQLITE_API double SQLITE_STDCALL sqlite3_column_double(sqlite3_stmt*, int iCol); |
| 4265 | +SQLITE_API int SQLITE_STDCALL sqlite3_column_int(sqlite3_stmt*, int iCol); |
| 4266 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_column_int64(sqlite3_stmt*, int iCol); |
| 4267 | +SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_column_text(sqlite3_stmt*, int iCol); |
| 4268 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_column_text16(sqlite3_stmt*, int iCol); |
| 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); |
| 4242 | 4271 | |
| 4243 | 4272 | /* |
| 4244 | 4273 | ** CAPI3REF: Destroy A Prepared Statement Object |
| 4274 | +** DESTRUCTOR: sqlite3_stmt |
| 4245 | 4275 | ** |
| 4246 | 4276 | ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. |
| 4247 | 4277 | ** ^If the most recent evaluation of the statement encountered no errors |
| 4248 | 4278 | ** or if the statement is never been evaluated, then sqlite3_finalize() returns |
| 4249 | 4279 | ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then |
| | @@ -4263,14 +4293,15 @@ |
| 4263 | 4293 | ** resource leaks. It is a grievous error for the application to try to use |
| 4264 | 4294 | ** a prepared statement after it has been finalized. Any use of a prepared |
| 4265 | 4295 | ** statement after it has been finalized can result in undefined and |
| 4266 | 4296 | ** undesirable behavior such as segfaults and heap corruption. |
| 4267 | 4297 | */ |
| 4268 | | -SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); |
| 4298 | +SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt); |
| 4269 | 4299 | |
| 4270 | 4300 | /* |
| 4271 | 4301 | ** CAPI3REF: Reset A Prepared Statement Object |
| 4302 | +** METHOD: sqlite3_stmt |
| 4272 | 4303 | ** |
| 4273 | 4304 | ** The sqlite3_reset() function is called to reset a [prepared statement] |
| 4274 | 4305 | ** object back to its initial state, ready to be re-executed. |
| 4275 | 4306 | ** ^Any SQL statement variables that had values bound to them using |
| 4276 | 4307 | ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. |
| | @@ -4289,17 +4320,18 @@ |
| 4289 | 4320 | ** [sqlite3_reset(S)] returns an appropriate [error code]. |
| 4290 | 4321 | ** |
| 4291 | 4322 | ** ^The [sqlite3_reset(S)] interface does not change the values |
| 4292 | 4323 | ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. |
| 4293 | 4324 | */ |
| 4294 | | -SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); |
| 4325 | +SQLITE_API int SQLITE_STDCALL sqlite3_reset(sqlite3_stmt *pStmt); |
| 4295 | 4326 | |
| 4296 | 4327 | /* |
| 4297 | 4328 | ** CAPI3REF: Create Or Redefine SQL Functions |
| 4298 | 4329 | ** KEYWORDS: {function creation routines} |
| 4299 | 4330 | ** KEYWORDS: {application-defined SQL function} |
| 4300 | 4331 | ** KEYWORDS: {application-defined SQL functions} |
| 4332 | +** METHOD: sqlite3 |
| 4301 | 4333 | ** |
| 4302 | 4334 | ** ^These functions (collectively known as "function creation routines") |
| 4303 | 4335 | ** are used to add SQL functions or aggregates or to redefine the behavior |
| 4304 | 4336 | ** of existing SQL functions or aggregates. The only differences between |
| 4305 | 4337 | ** these routines are the text encoding expected for |
| | @@ -4388,31 +4420,31 @@ |
| 4388 | 4420 | ** ^An application-defined function is permitted to call other |
| 4389 | 4421 | ** SQLite interfaces. However, such calls must not |
| 4390 | 4422 | ** close the database connection nor finalize or reset the prepared |
| 4391 | 4423 | ** statement in which the function is running. |
| 4392 | 4424 | */ |
| 4393 | | -SQLITE_API int sqlite3_create_function( |
| 4425 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_function( |
| 4394 | 4426 | sqlite3 *db, |
| 4395 | 4427 | const char *zFunctionName, |
| 4396 | 4428 | int nArg, |
| 4397 | 4429 | int eTextRep, |
| 4398 | 4430 | void *pApp, |
| 4399 | 4431 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
| 4400 | 4432 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 4401 | 4433 | void (*xFinal)(sqlite3_context*) |
| 4402 | 4434 | ); |
| 4403 | | -SQLITE_API int sqlite3_create_function16( |
| 4435 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_function16( |
| 4404 | 4436 | sqlite3 *db, |
| 4405 | 4437 | const void *zFunctionName, |
| 4406 | 4438 | int nArg, |
| 4407 | 4439 | int eTextRep, |
| 4408 | 4440 | void *pApp, |
| 4409 | 4441 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
| 4410 | 4442 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 4411 | 4443 | void (*xFinal)(sqlite3_context*) |
| 4412 | 4444 | ); |
| 4413 | | -SQLITE_API int sqlite3_create_function_v2( |
| 4445 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_function_v2( |
| 4414 | 4446 | sqlite3 *db, |
| 4415 | 4447 | const char *zFunctionName, |
| 4416 | 4448 | int nArg, |
| 4417 | 4449 | int eTextRep, |
| 4418 | 4450 | void *pApp, |
| | @@ -4454,21 +4486,22 @@ |
| 4454 | 4486 | ** to be supported. However, new applications should avoid |
| 4455 | 4487 | ** the use of these functions. To encourage programmers to avoid |
| 4456 | 4488 | ** these functions, we will not explain what they do. |
| 4457 | 4489 | */ |
| 4458 | 4490 | #ifndef SQLITE_OMIT_DEPRECATED |
| 4459 | | -SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); |
| 4460 | | -SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); |
| 4461 | | -SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); |
| 4462 | | -SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); |
| 4463 | | -SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); |
| 4464 | | -SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), |
| 4491 | +SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_aggregate_count(sqlite3_context*); |
| 4492 | +SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_expired(sqlite3_stmt*); |
| 4493 | +SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); |
| 4494 | +SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_global_recover(void); |
| 4495 | +SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_thread_cleanup(void); |
| 4496 | +SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), |
| 4465 | 4497 | void*,sqlite3_int64); |
| 4466 | 4498 | #endif |
| 4467 | 4499 | |
| 4468 | 4500 | /* |
| 4469 | 4501 | ** CAPI3REF: Obtaining SQL Function Parameter Values |
| 4502 | +** METHOD: sqlite3_value |
| 4470 | 4503 | ** |
| 4471 | 4504 | ** The C-language implementation of SQL functions and aggregates uses |
| 4472 | 4505 | ** this set of interface routines to access the parameter values on |
| 4473 | 4506 | ** the function or aggregate. |
| 4474 | 4507 | ** |
| | @@ -4508,25 +4541,26 @@ |
| 4508 | 4541 | ** or [sqlite3_value_text16()]. |
| 4509 | 4542 | ** |
| 4510 | 4543 | ** These routines must be called from the same thread as |
| 4511 | 4544 | ** the SQL function that supplied the [sqlite3_value*] parameters. |
| 4512 | 4545 | */ |
| 4513 | | -SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); |
| 4514 | | -SQLITE_API int sqlite3_value_bytes(sqlite3_value*); |
| 4515 | | -SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); |
| 4516 | | -SQLITE_API double sqlite3_value_double(sqlite3_value*); |
| 4517 | | -SQLITE_API int sqlite3_value_int(sqlite3_value*); |
| 4518 | | -SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); |
| 4519 | | -SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*); |
| 4520 | | -SQLITE_API const void *sqlite3_value_text16(sqlite3_value*); |
| 4521 | | -SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*); |
| 4522 | | -SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*); |
| 4523 | | -SQLITE_API int sqlite3_value_type(sqlite3_value*); |
| 4524 | | -SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); |
| 4546 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_value_blob(sqlite3_value*); |
| 4547 | +SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes(sqlite3_value*); |
| 4548 | +SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes16(sqlite3_value*); |
| 4549 | +SQLITE_API double SQLITE_STDCALL sqlite3_value_double(sqlite3_value*); |
| 4550 | +SQLITE_API int SQLITE_STDCALL sqlite3_value_int(sqlite3_value*); |
| 4551 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_value_int64(sqlite3_value*); |
| 4552 | +SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_value_text(sqlite3_value*); |
| 4553 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16(sqlite3_value*); |
| 4554 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value*); |
| 4555 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value*); |
| 4556 | +SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*); |
| 4557 | +SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*); |
| 4525 | 4558 | |
| 4526 | 4559 | /* |
| 4527 | 4560 | ** CAPI3REF: Obtain Aggregate Function Context |
| 4561 | +** METHOD: sqlite3_context |
| 4528 | 4562 | ** |
| 4529 | 4563 | ** Implementations of aggregate SQL functions use this |
| 4530 | 4564 | ** routine to allocate memory for storing their state. |
| 4531 | 4565 | ** |
| 4532 | 4566 | ** ^The first time the sqlite3_aggregate_context(C,N) routine is called |
| | @@ -4563,14 +4597,15 @@ |
| 4563 | 4597 | ** function. |
| 4564 | 4598 | ** |
| 4565 | 4599 | ** This routine must be called from the same thread in which |
| 4566 | 4600 | ** the aggregate SQL function is running. |
| 4567 | 4601 | */ |
| 4568 | | -SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); |
| 4602 | +SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes); |
| 4569 | 4603 | |
| 4570 | 4604 | /* |
| 4571 | 4605 | ** CAPI3REF: User Data For Functions |
| 4606 | +** METHOD: sqlite3_context |
| 4572 | 4607 | ** |
| 4573 | 4608 | ** ^The sqlite3_user_data() interface returns a copy of |
| 4574 | 4609 | ** the pointer that was the pUserData parameter (the 5th parameter) |
| 4575 | 4610 | ** of the [sqlite3_create_function()] |
| 4576 | 4611 | ** and [sqlite3_create_function16()] routines that originally |
| | @@ -4577,25 +4612,27 @@ |
| 4577 | 4612 | ** registered the application defined function. |
| 4578 | 4613 | ** |
| 4579 | 4614 | ** This routine must be called from the same thread in which |
| 4580 | 4615 | ** the application-defined function is running. |
| 4581 | 4616 | */ |
| 4582 | | -SQLITE_API void *sqlite3_user_data(sqlite3_context*); |
| 4617 | +SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*); |
| 4583 | 4618 | |
| 4584 | 4619 | /* |
| 4585 | 4620 | ** CAPI3REF: Database Connection For Functions |
| 4621 | +** METHOD: sqlite3_context |
| 4586 | 4622 | ** |
| 4587 | 4623 | ** ^The sqlite3_context_db_handle() interface returns a copy of |
| 4588 | 4624 | ** the pointer to the [database connection] (the 1st parameter) |
| 4589 | 4625 | ** of the [sqlite3_create_function()] |
| 4590 | 4626 | ** and [sqlite3_create_function16()] routines that originally |
| 4591 | 4627 | ** registered the application defined function. |
| 4592 | 4628 | */ |
| 4593 | | -SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); |
| 4629 | +SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*); |
| 4594 | 4630 | |
| 4595 | 4631 | /* |
| 4596 | 4632 | ** CAPI3REF: Function Auxiliary Data |
| 4633 | +** METHOD: sqlite3_context |
| 4597 | 4634 | ** |
| 4598 | 4635 | ** These functions may be used by (non-aggregate) SQL functions to |
| 4599 | 4636 | ** associate metadata with argument values. If the same value is passed to |
| 4600 | 4637 | ** multiple invocations of the same SQL function during query execution, under |
| 4601 | 4638 | ** some circumstances the associated metadata may be preserved. An example |
| | @@ -4640,12 +4677,12 @@ |
| 4640 | 4677 | ** values and [parameters] and expressions composed from the same.)^ |
| 4641 | 4678 | ** |
| 4642 | 4679 | ** These routines must be called from the same thread in which |
| 4643 | 4680 | ** the SQL function is running. |
| 4644 | 4681 | */ |
| 4645 | | -SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); |
| 4646 | | -SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); |
| 4682 | +SQLITE_API void *SQLITE_STDCALL sqlite3_get_auxdata(sqlite3_context*, int N); |
| 4683 | +SQLITE_API void SQLITE_STDCALL sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); |
| 4647 | 4684 | |
| 4648 | 4685 | |
| 4649 | 4686 | /* |
| 4650 | 4687 | ** CAPI3REF: Constants Defining Special Destructor Behavior |
| 4651 | 4688 | ** |
| | @@ -4664,10 +4701,11 @@ |
| 4664 | 4701 | #define SQLITE_STATIC ((sqlite3_destructor_type)0) |
| 4665 | 4702 | #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) |
| 4666 | 4703 | |
| 4667 | 4704 | /* |
| 4668 | 4705 | ** CAPI3REF: Setting The Result Of An SQL Function |
| 4706 | +** METHOD: sqlite3_context |
| 4669 | 4707 | ** |
| 4670 | 4708 | ** These routines are used by the xFunc or xFinal callbacks that |
| 4671 | 4709 | ** implement SQL functions and aggregates. See |
| 4672 | 4710 | ** [sqlite3_create_function()] and [sqlite3_create_function16()] |
| 4673 | 4711 | ** for additional information. |
| | @@ -4776,33 +4814,34 @@ |
| 4776 | 4814 | ** |
| 4777 | 4815 | ** If these routines are called from within the different thread |
| 4778 | 4816 | ** than the one containing the application-defined function that received |
| 4779 | 4817 | ** the [sqlite3_context] pointer, the results are undefined. |
| 4780 | 4818 | */ |
| 4781 | | -SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); |
| 4782 | | -SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*, |
| 4819 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); |
| 4820 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_blob64(sqlite3_context*,const void*, |
| 4783 | 4821 | sqlite3_uint64,void(*)(void*)); |
| 4784 | | -SQLITE_API void sqlite3_result_double(sqlite3_context*, double); |
| 4785 | | -SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); |
| 4786 | | -SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); |
| 4787 | | -SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); |
| 4788 | | -SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); |
| 4789 | | -SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); |
| 4790 | | -SQLITE_API void sqlite3_result_int(sqlite3_context*, int); |
| 4791 | | -SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); |
| 4792 | | -SQLITE_API void sqlite3_result_null(sqlite3_context*); |
| 4793 | | -SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); |
| 4794 | | -SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64, |
| 4822 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_double(sqlite3_context*, double); |
| 4823 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_error(sqlite3_context*, const char*, int); |
| 4824 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_error16(sqlite3_context*, const void*, int); |
| 4825 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_error_toobig(sqlite3_context*); |
| 4826 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_error_nomem(sqlite3_context*); |
| 4827 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_error_code(sqlite3_context*, int); |
| 4828 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_int(sqlite3_context*, int); |
| 4829 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_int64(sqlite3_context*, sqlite3_int64); |
| 4830 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_null(sqlite3_context*); |
| 4831 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); |
| 4832 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64, |
| 4795 | 4833 | void(*)(void*), unsigned char encoding); |
| 4796 | | -SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); |
| 4797 | | -SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); |
| 4798 | | -SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); |
| 4799 | | -SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); |
| 4800 | | -SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); |
| 4834 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); |
| 4835 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); |
| 4836 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); |
| 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); |
| 4801 | 4839 | |
| 4802 | 4840 | /* |
| 4803 | 4841 | ** CAPI3REF: Define New Collating Sequences |
| 4842 | +** METHOD: sqlite3 |
| 4804 | 4843 | ** |
| 4805 | 4844 | ** ^These functions add, remove, or modify a [collation] associated |
| 4806 | 4845 | ** with the [database connection] specified as the first argument. |
| 4807 | 4846 | ** |
| 4808 | 4847 | ** ^The name of the collation is a UTF-8 string |
| | @@ -4876,35 +4915,36 @@ |
| 4876 | 4915 | ** is unfortunate but cannot be changed without breaking backwards |
| 4877 | 4916 | ** compatibility. |
| 4878 | 4917 | ** |
| 4879 | 4918 | ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. |
| 4880 | 4919 | */ |
| 4881 | | -SQLITE_API int sqlite3_create_collation( |
| 4920 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_collation( |
| 4882 | 4921 | sqlite3*, |
| 4883 | 4922 | const char *zName, |
| 4884 | 4923 | int eTextRep, |
| 4885 | 4924 | void *pArg, |
| 4886 | 4925 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 4887 | 4926 | ); |
| 4888 | | -SQLITE_API int sqlite3_create_collation_v2( |
| 4927 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_collation_v2( |
| 4889 | 4928 | sqlite3*, |
| 4890 | 4929 | const char *zName, |
| 4891 | 4930 | int eTextRep, |
| 4892 | 4931 | void *pArg, |
| 4893 | 4932 | int(*xCompare)(void*,int,const void*,int,const void*), |
| 4894 | 4933 | void(*xDestroy)(void*) |
| 4895 | 4934 | ); |
| 4896 | | -SQLITE_API int sqlite3_create_collation16( |
| 4935 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_collation16( |
| 4897 | 4936 | sqlite3*, |
| 4898 | 4937 | const void *zName, |
| 4899 | 4938 | int eTextRep, |
| 4900 | 4939 | void *pArg, |
| 4901 | 4940 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 4902 | 4941 | ); |
| 4903 | 4942 | |
| 4904 | 4943 | /* |
| 4905 | 4944 | ** CAPI3REF: Collation Needed Callbacks |
| 4945 | +** METHOD: sqlite3 |
| 4906 | 4946 | ** |
| 4907 | 4947 | ** ^To avoid having to register all collation sequences before a database |
| 4908 | 4948 | ** can be used, a single callback function may be registered with the |
| 4909 | 4949 | ** [database connection] to be invoked whenever an undefined collation |
| 4910 | 4950 | ** sequence is required. |
| | @@ -4925,16 +4965,16 @@ |
| 4925 | 4965 | ** |
| 4926 | 4966 | ** The callback function should register the desired collation using |
| 4927 | 4967 | ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or |
| 4928 | 4968 | ** [sqlite3_create_collation_v2()]. |
| 4929 | 4969 | */ |
| 4930 | | -SQLITE_API int sqlite3_collation_needed( |
| 4970 | +SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed( |
| 4931 | 4971 | sqlite3*, |
| 4932 | 4972 | void*, |
| 4933 | 4973 | void(*)(void*,sqlite3*,int eTextRep,const char*) |
| 4934 | 4974 | ); |
| 4935 | | -SQLITE_API int sqlite3_collation_needed16( |
| 4975 | +SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed16( |
| 4936 | 4976 | sqlite3*, |
| 4937 | 4977 | void*, |
| 4938 | 4978 | void(*)(void*,sqlite3*,int eTextRep,const void*) |
| 4939 | 4979 | ); |
| 4940 | 4980 | |
| | @@ -4944,15 +4984,15 @@ |
| 4944 | 4984 | ** called right after sqlite3_open(). |
| 4945 | 4985 | ** |
| 4946 | 4986 | ** The code to implement this API is not available in the public release |
| 4947 | 4987 | ** of SQLite. |
| 4948 | 4988 | */ |
| 4949 | | -SQLITE_API int sqlite3_key( |
| 4989 | +SQLITE_API int SQLITE_STDCALL sqlite3_key( |
| 4950 | 4990 | sqlite3 *db, /* Database to be rekeyed */ |
| 4951 | 4991 | const void *pKey, int nKey /* The key */ |
| 4952 | 4992 | ); |
| 4953 | | -SQLITE_API int sqlite3_key_v2( |
| 4993 | +SQLITE_API int SQLITE_STDCALL sqlite3_key_v2( |
| 4954 | 4994 | sqlite3 *db, /* Database to be rekeyed */ |
| 4955 | 4995 | const char *zDbName, /* Name of the database */ |
| 4956 | 4996 | const void *pKey, int nKey /* The key */ |
| 4957 | 4997 | ); |
| 4958 | 4998 | |
| | @@ -4962,35 +5002,35 @@ |
| 4962 | 5002 | ** database is decrypted. |
| 4963 | 5003 | ** |
| 4964 | 5004 | ** The code to implement this API is not available in the public release |
| 4965 | 5005 | ** of SQLite. |
| 4966 | 5006 | */ |
| 4967 | | -SQLITE_API int sqlite3_rekey( |
| 5007 | +SQLITE_API int SQLITE_STDCALL sqlite3_rekey( |
| 4968 | 5008 | sqlite3 *db, /* Database to be rekeyed */ |
| 4969 | 5009 | const void *pKey, int nKey /* The new key */ |
| 4970 | 5010 | ); |
| 4971 | | -SQLITE_API int sqlite3_rekey_v2( |
| 5011 | +SQLITE_API int SQLITE_STDCALL sqlite3_rekey_v2( |
| 4972 | 5012 | sqlite3 *db, /* Database to be rekeyed */ |
| 4973 | 5013 | const char *zDbName, /* Name of the database */ |
| 4974 | 5014 | const void *pKey, int nKey /* The new key */ |
| 4975 | 5015 | ); |
| 4976 | 5016 | |
| 4977 | 5017 | /* |
| 4978 | 5018 | ** Specify the activation key for a SEE database. Unless |
| 4979 | 5019 | ** activated, none of the SEE routines will work. |
| 4980 | 5020 | */ |
| 4981 | | -SQLITE_API void sqlite3_activate_see( |
| 5021 | +SQLITE_API void SQLITE_STDCALL sqlite3_activate_see( |
| 4982 | 5022 | const char *zPassPhrase /* Activation phrase */ |
| 4983 | 5023 | ); |
| 4984 | 5024 | #endif |
| 4985 | 5025 | |
| 4986 | 5026 | #ifdef SQLITE_ENABLE_CEROD |
| 4987 | 5027 | /* |
| 4988 | 5028 | ** Specify the activation key for a CEROD database. Unless |
| 4989 | 5029 | ** activated, none of the CEROD routines will work. |
| 4990 | 5030 | */ |
| 4991 | | -SQLITE_API void sqlite3_activate_cerod( |
| 5031 | +SQLITE_API void SQLITE_STDCALL sqlite3_activate_cerod( |
| 4992 | 5032 | const char *zPassPhrase /* Activation phrase */ |
| 4993 | 5033 | ); |
| 4994 | 5034 | #endif |
| 4995 | 5035 | |
| 4996 | 5036 | /* |
| | @@ -5008,11 +5048,11 @@ |
| 5008 | 5048 | ** method of the default [sqlite3_vfs] object. If the xSleep() method |
| 5009 | 5049 | ** of the default VFS is not implemented correctly, or not implemented at |
| 5010 | 5050 | ** all, then the behavior of sqlite3_sleep() may deviate from the description |
| 5011 | 5051 | ** in the previous paragraphs. |
| 5012 | 5052 | */ |
| 5013 | | -SQLITE_API int sqlite3_sleep(int); |
| 5053 | +SQLITE_API int SQLITE_STDCALL sqlite3_sleep(int); |
| 5014 | 5054 | |
| 5015 | 5055 | /* |
| 5016 | 5056 | ** CAPI3REF: Name Of The Folder Holding Temporary Files |
| 5017 | 5057 | ** |
| 5018 | 5058 | ** ^(If this global variable is made to point to a string which is |
| | @@ -5108,10 +5148,11 @@ |
| 5108 | 5148 | SQLITE_API char *sqlite3_data_directory; |
| 5109 | 5149 | |
| 5110 | 5150 | /* |
| 5111 | 5151 | ** CAPI3REF: Test For Auto-Commit Mode |
| 5112 | 5152 | ** KEYWORDS: {autocommit mode} |
| 5153 | +** METHOD: sqlite3 |
| 5113 | 5154 | ** |
| 5114 | 5155 | ** ^The sqlite3_get_autocommit() interface returns non-zero or |
| 5115 | 5156 | ** zero if the given database connection is or is not in autocommit mode, |
| 5116 | 5157 | ** respectively. ^Autocommit mode is on by default. |
| 5117 | 5158 | ** ^Autocommit mode is disabled by a [BEGIN] statement. |
| | @@ -5126,26 +5167,28 @@ |
| 5126 | 5167 | ** |
| 5127 | 5168 | ** If another thread changes the autocommit status of the database |
| 5128 | 5169 | ** connection while this routine is running, then the return value |
| 5129 | 5170 | ** is undefined. |
| 5130 | 5171 | */ |
| 5131 | | -SQLITE_API int sqlite3_get_autocommit(sqlite3*); |
| 5172 | +SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*); |
| 5132 | 5173 | |
| 5133 | 5174 | /* |
| 5134 | 5175 | ** CAPI3REF: Find The Database Handle Of A Prepared Statement |
| 5176 | +** METHOD: sqlite3_stmt |
| 5135 | 5177 | ** |
| 5136 | 5178 | ** ^The sqlite3_db_handle interface returns the [database connection] handle |
| 5137 | 5179 | ** to which a [prepared statement] belongs. ^The [database connection] |
| 5138 | 5180 | ** returned by sqlite3_db_handle is the same [database connection] |
| 5139 | 5181 | ** that was the first argument |
| 5140 | 5182 | ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to |
| 5141 | 5183 | ** create the statement in the first place. |
| 5142 | 5184 | */ |
| 5143 | | -SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); |
| 5185 | +SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*); |
| 5144 | 5186 | |
| 5145 | 5187 | /* |
| 5146 | 5188 | ** CAPI3REF: Return The Filename For A Database Connection |
| 5189 | +** METHOD: sqlite3 |
| 5147 | 5190 | ** |
| 5148 | 5191 | ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename |
| 5149 | 5192 | ** associated with database N of connection D. ^The main database file |
| 5150 | 5193 | ** has the name "main". If there is no attached database N on the database |
| 5151 | 5194 | ** connection D, or if database N is a temporary or in-memory database, then |
| | @@ -5154,23 +5197,25 @@ |
| 5154 | 5197 | ** ^The filename returned by this function is the output of the |
| 5155 | 5198 | ** xFullPathname method of the [VFS]. ^In other words, the filename |
| 5156 | 5199 | ** will be an absolute pathname, even if the filename used |
| 5157 | 5200 | ** to open the database originally was a URI or relative pathname. |
| 5158 | 5201 | */ |
| 5159 | | -SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
| 5202 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
| 5160 | 5203 | |
| 5161 | 5204 | /* |
| 5162 | 5205 | ** CAPI3REF: Determine if a database is read-only |
| 5206 | +** METHOD: sqlite3 |
| 5163 | 5207 | ** |
| 5164 | 5208 | ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N |
| 5165 | 5209 | ** of connection D is read-only, 0 if it is read/write, or -1 if N is not |
| 5166 | 5210 | ** the name of a database on connection D. |
| 5167 | 5211 | */ |
| 5168 | | -SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName); |
| 5212 | +SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName); |
| 5169 | 5213 | |
| 5170 | 5214 | /* |
| 5171 | 5215 | ** CAPI3REF: Find the next prepared statement |
| 5216 | +** METHOD: sqlite3 |
| 5172 | 5217 | ** |
| 5173 | 5218 | ** ^This interface returns a pointer to the next [prepared statement] after |
| 5174 | 5219 | ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL |
| 5175 | 5220 | ** then this interface returns a pointer to the first prepared statement |
| 5176 | 5221 | ** associated with the database connection pDb. ^If no prepared statement |
| | @@ -5178,14 +5223,15 @@ |
| 5178 | 5223 | ** |
| 5179 | 5224 | ** The [database connection] pointer D in a call to |
| 5180 | 5225 | ** [sqlite3_next_stmt(D,S)] must refer to an open database |
| 5181 | 5226 | ** connection and in particular must not be a NULL pointer. |
| 5182 | 5227 | */ |
| 5183 | | -SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); |
| 5228 | +SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); |
| 5184 | 5229 | |
| 5185 | 5230 | /* |
| 5186 | 5231 | ** CAPI3REF: Commit And Rollback Notification Callbacks |
| 5232 | +** METHOD: sqlite3 |
| 5187 | 5233 | ** |
| 5188 | 5234 | ** ^The sqlite3_commit_hook() interface registers a callback |
| 5189 | 5235 | ** function to be invoked whenever a transaction is [COMMIT | committed]. |
| 5190 | 5236 | ** ^Any callback set by a previous call to sqlite3_commit_hook() |
| 5191 | 5237 | ** for the same database connection is overridden. |
| | @@ -5226,15 +5272,16 @@ |
| 5226 | 5272 | ** ^The rollback callback is not invoked if a transaction is |
| 5227 | 5273 | ** automatically rolled back because the database connection is closed. |
| 5228 | 5274 | ** |
| 5229 | 5275 | ** See also the [sqlite3_update_hook()] interface. |
| 5230 | 5276 | */ |
| 5231 | | -SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); |
| 5232 | | -SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); |
| 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*); |
| 5233 | 5279 | |
| 5234 | 5280 | /* |
| 5235 | 5281 | ** CAPI3REF: Data Change Notification Callbacks |
| 5282 | +** METHOD: sqlite3 |
| 5236 | 5283 | ** |
| 5237 | 5284 | ** ^The sqlite3_update_hook() interface registers a callback function |
| 5238 | 5285 | ** with the [database connection] identified by the first argument |
| 5239 | 5286 | ** to be invoked whenever a row is updated, inserted or deleted in |
| 5240 | 5287 | ** a rowid table. |
| | @@ -5277,11 +5324,11 @@ |
| 5277 | 5324 | ** the first call on D. |
| 5278 | 5325 | ** |
| 5279 | 5326 | ** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()] |
| 5280 | 5327 | ** interfaces. |
| 5281 | 5328 | */ |
| 5282 | | -SQLITE_API void *sqlite3_update_hook( |
| 5329 | +SQLITE_API void *SQLITE_STDCALL sqlite3_update_hook( |
| 5283 | 5330 | sqlite3*, |
| 5284 | 5331 | void(*)(void *,int ,char const *,char const *,sqlite3_int64), |
| 5285 | 5332 | void* |
| 5286 | 5333 | ); |
| 5287 | 5334 | |
| | @@ -5317,11 +5364,11 @@ |
| 5317 | 5364 | ** This interface is threadsafe on processors where writing a |
| 5318 | 5365 | ** 32-bit integer is atomic. |
| 5319 | 5366 | ** |
| 5320 | 5367 | ** See Also: [SQLite Shared-Cache Mode] |
| 5321 | 5368 | */ |
| 5322 | | -SQLITE_API int sqlite3_enable_shared_cache(int); |
| 5369 | +SQLITE_API int SQLITE_STDCALL sqlite3_enable_shared_cache(int); |
| 5323 | 5370 | |
| 5324 | 5371 | /* |
| 5325 | 5372 | ** CAPI3REF: Attempt To Free Heap Memory |
| 5326 | 5373 | ** |
| 5327 | 5374 | ** ^The sqlite3_release_memory() interface attempts to free N bytes |
| | @@ -5333,24 +5380,25 @@ |
| 5333 | 5380 | ** ^The sqlite3_release_memory() routine is a no-op returning zero |
| 5334 | 5381 | ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. |
| 5335 | 5382 | ** |
| 5336 | 5383 | ** See also: [sqlite3_db_release_memory()] |
| 5337 | 5384 | */ |
| 5338 | | -SQLITE_API int sqlite3_release_memory(int); |
| 5385 | +SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int); |
| 5339 | 5386 | |
| 5340 | 5387 | /* |
| 5341 | 5388 | ** CAPI3REF: Free Memory Used By A Database Connection |
| 5389 | +** METHOD: sqlite3 |
| 5342 | 5390 | ** |
| 5343 | 5391 | ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap |
| 5344 | 5392 | ** memory as possible from database connection D. Unlike the |
| 5345 | 5393 | ** [sqlite3_release_memory()] interface, this interface is in effect even |
| 5346 | 5394 | ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is |
| 5347 | 5395 | ** omitted. |
| 5348 | 5396 | ** |
| 5349 | 5397 | ** See also: [sqlite3_release_memory()] |
| 5350 | 5398 | */ |
| 5351 | | -SQLITE_API int sqlite3_db_release_memory(sqlite3*); |
| 5399 | +SQLITE_API int SQLITE_STDCALL sqlite3_db_release_memory(sqlite3*); |
| 5352 | 5400 | |
| 5353 | 5401 | /* |
| 5354 | 5402 | ** CAPI3REF: Impose A Limit On Heap Size |
| 5355 | 5403 | ** |
| 5356 | 5404 | ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the |
| | @@ -5398,11 +5446,11 @@ |
| 5398 | 5446 | ** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT]. |
| 5399 | 5447 | ** |
| 5400 | 5448 | ** The circumstances under which SQLite will enforce the soft heap limit may |
| 5401 | 5449 | ** changes in future releases of SQLite. |
| 5402 | 5450 | */ |
| 5403 | | -SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N); |
| 5451 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 N); |
| 5404 | 5452 | |
| 5405 | 5453 | /* |
| 5406 | 5454 | ** CAPI3REF: Deprecated Soft Heap Limit Interface |
| 5407 | 5455 | ** DEPRECATED |
| 5408 | 5456 | ** |
| | @@ -5409,15 +5457,16 @@ |
| 5409 | 5457 | ** This is a deprecated version of the [sqlite3_soft_heap_limit64()] |
| 5410 | 5458 | ** interface. This routine is provided for historical compatibility |
| 5411 | 5459 | ** only. All new applications should use the |
| 5412 | 5460 | ** [sqlite3_soft_heap_limit64()] interface rather than this one. |
| 5413 | 5461 | */ |
| 5414 | | -SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); |
| 5462 | +SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N); |
| 5415 | 5463 | |
| 5416 | 5464 | |
| 5417 | 5465 | /* |
| 5418 | 5466 | ** CAPI3REF: Extract Metadata About A Column Of A Table |
| 5467 | +** METHOD: sqlite3 |
| 5419 | 5468 | ** |
| 5420 | 5469 | ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns |
| 5421 | 5470 | ** information about column C of table T in database D |
| 5422 | 5471 | ** on [database connection] X.)^ ^The sqlite3_table_column_metadata() |
| 5423 | 5472 | ** interface returns SQLITE_OK and fills in the non-NULL pointers in |
| | @@ -5478,11 +5527,11 @@ |
| 5478 | 5527 | ** |
| 5479 | 5528 | ** ^This function causes all database schemas to be read from disk and |
| 5480 | 5529 | ** parsed, if that has not already been done, and returns an error if |
| 5481 | 5530 | ** any errors are encountered while loading the schema. |
| 5482 | 5531 | */ |
| 5483 | | -SQLITE_API int sqlite3_table_column_metadata( |
| 5532 | +SQLITE_API int SQLITE_STDCALL sqlite3_table_column_metadata( |
| 5484 | 5533 | sqlite3 *db, /* Connection handle */ |
| 5485 | 5534 | const char *zDbName, /* Database name or NULL */ |
| 5486 | 5535 | const char *zTableName, /* Table name */ |
| 5487 | 5536 | const char *zColumnName, /* Column name */ |
| 5488 | 5537 | char const **pzDataType, /* OUTPUT: Declared data type */ |
| | @@ -5492,10 +5541,11 @@ |
| 5492 | 5541 | int *pAutoinc /* OUTPUT: True if column is auto-increment */ |
| 5493 | 5542 | ); |
| 5494 | 5543 | |
| 5495 | 5544 | /* |
| 5496 | 5545 | ** CAPI3REF: Load An Extension |
| 5546 | +** METHOD: sqlite3 |
| 5497 | 5547 | ** |
| 5498 | 5548 | ** ^This interface loads an SQLite extension library from the named file. |
| 5499 | 5549 | ** |
| 5500 | 5550 | ** ^The sqlite3_load_extension() interface attempts to load an |
| 5501 | 5551 | ** [SQLite extension] library contained in the file zFile. If |
| | @@ -5524,19 +5574,20 @@ |
| 5524 | 5574 | ** [sqlite3_enable_load_extension()] prior to calling this API, |
| 5525 | 5575 | ** otherwise an error will be returned. |
| 5526 | 5576 | ** |
| 5527 | 5577 | ** See also the [load_extension() SQL function]. |
| 5528 | 5578 | */ |
| 5529 | | -SQLITE_API int sqlite3_load_extension( |
| 5579 | +SQLITE_API int SQLITE_STDCALL sqlite3_load_extension( |
| 5530 | 5580 | sqlite3 *db, /* Load the extension into this database connection */ |
| 5531 | 5581 | const char *zFile, /* Name of the shared library containing extension */ |
| 5532 | 5582 | const char *zProc, /* Entry point. Derived from zFile if 0 */ |
| 5533 | 5583 | char **pzErrMsg /* Put error message here if not 0 */ |
| 5534 | 5584 | ); |
| 5535 | 5585 | |
| 5536 | 5586 | /* |
| 5537 | 5587 | ** CAPI3REF: Enable Or Disable Extension Loading |
| 5588 | +** METHOD: sqlite3 |
| 5538 | 5589 | ** |
| 5539 | 5590 | ** ^So as not to open security holes in older applications that are |
| 5540 | 5591 | ** unprepared to deal with [extension loading], and as a means of disabling |
| 5541 | 5592 | ** [extension loading] while evaluating user-entered SQL, the following API |
| 5542 | 5593 | ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. |
| | @@ -5544,11 +5595,11 @@ |
| 5544 | 5595 | ** ^Extension loading is off by default. |
| 5545 | 5596 | ** ^Call the sqlite3_enable_load_extension() routine with onoff==1 |
| 5546 | 5597 | ** to turn extension loading on and call it with onoff==0 to turn |
| 5547 | 5598 | ** it back off again. |
| 5548 | 5599 | */ |
| 5549 | | -SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff); |
| 5600 | +SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff); |
| 5550 | 5601 | |
| 5551 | 5602 | /* |
| 5552 | 5603 | ** CAPI3REF: Automatically Load Statically Linked Extensions |
| 5553 | 5604 | ** |
| 5554 | 5605 | ** ^This interface causes the xEntryPoint() function to be invoked for |
| | @@ -5582,11 +5633,11 @@ |
| 5582 | 5633 | ** will be called more than once for each database connection that is opened. |
| 5583 | 5634 | ** |
| 5584 | 5635 | ** See also: [sqlite3_reset_auto_extension()] |
| 5585 | 5636 | ** and [sqlite3_cancel_auto_extension()] |
| 5586 | 5637 | */ |
| 5587 | | -SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void)); |
| 5638 | +SQLITE_API int SQLITE_STDCALL sqlite3_auto_extension(void (*xEntryPoint)(void)); |
| 5588 | 5639 | |
| 5589 | 5640 | /* |
| 5590 | 5641 | ** CAPI3REF: Cancel Automatic Extension Loading |
| 5591 | 5642 | ** |
| 5592 | 5643 | ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the |
| | @@ -5594,19 +5645,19 @@ |
| 5594 | 5645 | ** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)] |
| 5595 | 5646 | ** routine returns 1 if initialization routine X was successfully |
| 5596 | 5647 | ** unregistered and it returns 0 if X was not on the list of initialization |
| 5597 | 5648 | ** routines. |
| 5598 | 5649 | */ |
| 5599 | | -SQLITE_API int sqlite3_cancel_auto_extension(void (*xEntryPoint)(void)); |
| 5650 | +SQLITE_API int SQLITE_STDCALL sqlite3_cancel_auto_extension(void (*xEntryPoint)(void)); |
| 5600 | 5651 | |
| 5601 | 5652 | /* |
| 5602 | 5653 | ** CAPI3REF: Reset Automatic Extension Loading |
| 5603 | 5654 | ** |
| 5604 | 5655 | ** ^This interface disables all automatic extensions previously |
| 5605 | 5656 | ** registered using [sqlite3_auto_extension()]. |
| 5606 | 5657 | */ |
| 5607 | | -SQLITE_API void sqlite3_reset_auto_extension(void); |
| 5658 | +SQLITE_API void SQLITE_STDCALL sqlite3_reset_auto_extension(void); |
| 5608 | 5659 | |
| 5609 | 5660 | /* |
| 5610 | 5661 | ** The interface to the virtual-table mechanism is currently considered |
| 5611 | 5662 | ** to be experimental. The interface might change in incompatible ways. |
| 5612 | 5663 | ** If this is a problem for you, do not use the interface at this time. |
| | @@ -5782,10 +5833,11 @@ |
| 5782 | 5833 | #define SQLITE_INDEX_CONSTRAINT_GE 32 |
| 5783 | 5834 | #define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
| 5784 | 5835 | |
| 5785 | 5836 | /* |
| 5786 | 5837 | ** CAPI3REF: Register A Virtual Table Implementation |
| 5838 | +** METHOD: sqlite3 |
| 5787 | 5839 | ** |
| 5788 | 5840 | ** ^These routines are used to register a new [virtual table module] name. |
| 5789 | 5841 | ** ^Module names must be registered before |
| 5790 | 5842 | ** creating a new [virtual table] using the module and before using a |
| 5791 | 5843 | ** preexisting [virtual table] for the module. |
| | @@ -5805,17 +5857,17 @@ |
| 5805 | 5857 | ** be invoked if the call to sqlite3_create_module_v2() fails. |
| 5806 | 5858 | ** ^The sqlite3_create_module() |
| 5807 | 5859 | ** interface is equivalent to sqlite3_create_module_v2() with a NULL |
| 5808 | 5860 | ** destructor. |
| 5809 | 5861 | */ |
| 5810 | | -SQLITE_API int sqlite3_create_module( |
| 5862 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_module( |
| 5811 | 5863 | sqlite3 *db, /* SQLite connection to register module with */ |
| 5812 | 5864 | const char *zName, /* Name of the module */ |
| 5813 | 5865 | const sqlite3_module *p, /* Methods for the module */ |
| 5814 | 5866 | void *pClientData /* Client data for xCreate/xConnect */ |
| 5815 | 5867 | ); |
| 5816 | | -SQLITE_API int sqlite3_create_module_v2( |
| 5868 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_module_v2( |
| 5817 | 5869 | sqlite3 *db, /* SQLite connection to register module with */ |
| 5818 | 5870 | const char *zName, /* Name of the module */ |
| 5819 | 5871 | const sqlite3_module *p, /* Methods for the module */ |
| 5820 | 5872 | void *pClientData, /* Client data for xCreate/xConnect */ |
| 5821 | 5873 | void(*xDestroy)(void*) /* Module destructor function */ |
| | @@ -5874,14 +5926,15 @@ |
| 5874 | 5926 | ** ^The [xCreate] and [xConnect] methods of a |
| 5875 | 5927 | ** [virtual table module] call this interface |
| 5876 | 5928 | ** to declare the format (the names and datatypes of the columns) of |
| 5877 | 5929 | ** the virtual tables they implement. |
| 5878 | 5930 | */ |
| 5879 | | -SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL); |
| 5931 | +SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL); |
| 5880 | 5932 | |
| 5881 | 5933 | /* |
| 5882 | 5934 | ** CAPI3REF: Overload A Function For A Virtual Table |
| 5935 | +** METHOD: sqlite3 |
| 5883 | 5936 | ** |
| 5884 | 5937 | ** ^(Virtual tables can provide alternative implementations of functions |
| 5885 | 5938 | ** using the [xFindFunction] method of the [virtual table module]. |
| 5886 | 5939 | ** But global versions of those functions |
| 5887 | 5940 | ** must exist in order to be overloaded.)^ |
| | @@ -5892,11 +5945,11 @@ |
| 5892 | 5945 | ** of the new function always causes an exception to be thrown. So |
| 5893 | 5946 | ** the new function is not good for anything by itself. Its only |
| 5894 | 5947 | ** purpose is to be a placeholder function that can be overloaded |
| 5895 | 5948 | ** by a [virtual table]. |
| 5896 | 5949 | */ |
| 5897 | | -SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); |
| 5950 | +SQLITE_API int SQLITE_STDCALL sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); |
| 5898 | 5951 | |
| 5899 | 5952 | /* |
| 5900 | 5953 | ** The interface to the virtual-table mechanism defined above (back up |
| 5901 | 5954 | ** to a comment remarkably similar to this one) is currently considered |
| 5902 | 5955 | ** to be experimental. The interface might change in incompatible ways. |
| | @@ -5920,10 +5973,12 @@ |
| 5920 | 5973 | */ |
| 5921 | 5974 | typedef struct sqlite3_blob sqlite3_blob; |
| 5922 | 5975 | |
| 5923 | 5976 | /* |
| 5924 | 5977 | ** CAPI3REF: Open A BLOB For Incremental I/O |
| 5978 | +** METHOD: sqlite3 |
| 5979 | +** CONSTRUCTOR: sqlite3_blob |
| 5925 | 5980 | ** |
| 5926 | 5981 | ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located |
| 5927 | 5982 | ** in row iRow, column zColumn, table zTable in database zDb; |
| 5928 | 5983 | ** in other words, the same BLOB that would be selected by: |
| 5929 | 5984 | ** |
| | @@ -5989,11 +6044,11 @@ |
| 5989 | 6044 | ** zero-filled blob to read or write using the incremental-blob interface. |
| 5990 | 6045 | ** |
| 5991 | 6046 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 5992 | 6047 | ** be released by a call to [sqlite3_blob_close()]. |
| 5993 | 6048 | */ |
| 5994 | | -SQLITE_API int sqlite3_blob_open( |
| 6049 | +SQLITE_API int SQLITE_STDCALL sqlite3_blob_open( |
| 5995 | 6050 | sqlite3*, |
| 5996 | 6051 | const char *zDb, |
| 5997 | 6052 | const char *zTable, |
| 5998 | 6053 | const char *zColumn, |
| 5999 | 6054 | sqlite3_int64 iRow, |
| | @@ -6001,10 +6056,11 @@ |
| 6001 | 6056 | sqlite3_blob **ppBlob |
| 6002 | 6057 | ); |
| 6003 | 6058 | |
| 6004 | 6059 | /* |
| 6005 | 6060 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 6061 | +** METHOD: sqlite3_blob |
| 6006 | 6062 | ** |
| 6007 | 6063 | ** ^This function is used to move an existing blob handle so that it points |
| 6008 | 6064 | ** to a different row of the same database table. ^The new row is identified |
| 6009 | 6065 | ** by the rowid value passed as the second argument. Only the row can be |
| 6010 | 6066 | ** changed. ^The database, table and column on which the blob handle is open |
| | @@ -6021,14 +6077,15 @@ |
| 6021 | 6077 | ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle |
| 6022 | 6078 | ** always returns zero. |
| 6023 | 6079 | ** |
| 6024 | 6080 | ** ^This function sets the database handle error code and message. |
| 6025 | 6081 | */ |
| 6026 | | -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 6082 | +SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 6027 | 6083 | |
| 6028 | 6084 | /* |
| 6029 | 6085 | ** CAPI3REF: Close A BLOB Handle |
| 6086 | +** DESTRUCTOR: sqlite3_blob |
| 6030 | 6087 | ** |
| 6031 | 6088 | ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed |
| 6032 | 6089 | ** unconditionally. Even if this routine returns an error code, the |
| 6033 | 6090 | ** handle is still closed.)^ |
| 6034 | 6091 | ** |
| | @@ -6043,14 +6100,15 @@ |
| 6043 | 6100 | ** with a null pointer (such as would be returned by a failed call to |
| 6044 | 6101 | ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function |
| 6045 | 6102 | ** is passed a valid open blob handle, the values returned by the |
| 6046 | 6103 | ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning. |
| 6047 | 6104 | */ |
| 6048 | | -SQLITE_API int sqlite3_blob_close(sqlite3_blob *); |
| 6105 | +SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *); |
| 6049 | 6106 | |
| 6050 | 6107 | /* |
| 6051 | 6108 | ** CAPI3REF: Return The Size Of An Open BLOB |
| 6109 | +** METHOD: sqlite3_blob |
| 6052 | 6110 | ** |
| 6053 | 6111 | ** ^Returns the size in bytes of the BLOB accessible via the |
| 6054 | 6112 | ** successfully opened [BLOB handle] in its only argument. ^The |
| 6055 | 6113 | ** incremental blob I/O routines can only read or overwriting existing |
| 6056 | 6114 | ** blob content; they cannot change the size of a blob. |
| | @@ -6058,14 +6116,15 @@ |
| 6058 | 6116 | ** This routine only works on a [BLOB handle] which has been created |
| 6059 | 6117 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
| 6060 | 6118 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| 6061 | 6119 | ** to this routine results in undefined and probably undesirable behavior. |
| 6062 | 6120 | */ |
| 6063 | | -SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *); |
| 6121 | +SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *); |
| 6064 | 6122 | |
| 6065 | 6123 | /* |
| 6066 | 6124 | ** CAPI3REF: Read Data From A BLOB Incrementally |
| 6125 | +** METHOD: sqlite3_blob |
| 6067 | 6126 | ** |
| 6068 | 6127 | ** ^(This function is used to read data from an open [BLOB handle] into a |
| 6069 | 6128 | ** caller-supplied buffer. N bytes of data are copied into buffer Z |
| 6070 | 6129 | ** from the open BLOB, starting at offset iOffset.)^ |
| 6071 | 6130 | ** |
| | @@ -6086,14 +6145,15 @@ |
| 6086 | 6145 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| 6087 | 6146 | ** to this routine results in undefined and probably undesirable behavior. |
| 6088 | 6147 | ** |
| 6089 | 6148 | ** See also: [sqlite3_blob_write()]. |
| 6090 | 6149 | */ |
| 6091 | | -SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 6150 | +SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 6092 | 6151 | |
| 6093 | 6152 | /* |
| 6094 | 6153 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 6154 | +** METHOD: sqlite3_blob |
| 6095 | 6155 | ** |
| 6096 | 6156 | ** ^(This function is used to write data into an open [BLOB handle] from a |
| 6097 | 6157 | ** caller-supplied buffer. N bytes of data are copied from the buffer Z |
| 6098 | 6158 | ** into the open BLOB, starting at offset iOffset.)^ |
| 6099 | 6159 | ** |
| | @@ -6127,11 +6187,11 @@ |
| 6127 | 6187 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| 6128 | 6188 | ** to this routine results in undefined and probably undesirable behavior. |
| 6129 | 6189 | ** |
| 6130 | 6190 | ** See also: [sqlite3_blob_read()]. |
| 6131 | 6191 | */ |
| 6132 | | -SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); |
| 6192 | +SQLITE_API int SQLITE_STDCALL sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); |
| 6133 | 6193 | |
| 6134 | 6194 | /* |
| 6135 | 6195 | ** CAPI3REF: Virtual File System Objects |
| 6136 | 6196 | ** |
| 6137 | 6197 | ** A virtual filesystem (VFS) is an [sqlite3_vfs] object |
| | @@ -6158,13 +6218,13 @@ |
| 6158 | 6218 | ** |
| 6159 | 6219 | ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface. |
| 6160 | 6220 | ** ^(If the default VFS is unregistered, another VFS is chosen as |
| 6161 | 6221 | ** the default. The choice for the new VFS is arbitrary.)^ |
| 6162 | 6222 | */ |
| 6163 | | -SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); |
| 6164 | | -SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); |
| 6165 | | -SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); |
| 6223 | +SQLITE_API sqlite3_vfs *SQLITE_STDCALL sqlite3_vfs_find(const char *zVfsName); |
| 6224 | +SQLITE_API int SQLITE_STDCALL sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); |
| 6225 | +SQLITE_API int SQLITE_STDCALL sqlite3_vfs_unregister(sqlite3_vfs*); |
| 6166 | 6226 | |
| 6167 | 6227 | /* |
| 6168 | 6228 | ** CAPI3REF: Mutexes |
| 6169 | 6229 | ** |
| 6170 | 6230 | ** The SQLite core uses these routines for thread |
| | @@ -6273,15 +6333,15 @@ |
| 6273 | 6333 | ** sqlite3_mutex_leave() is a NULL pointer, then all three routines |
| 6274 | 6334 | ** behave as no-ops. |
| 6275 | 6335 | ** |
| 6276 | 6336 | ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. |
| 6277 | 6337 | */ |
| 6278 | | -SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int); |
| 6279 | | -SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*); |
| 6280 | | -SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*); |
| 6281 | | -SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*); |
| 6282 | | -SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); |
| 6338 | +SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int); |
| 6339 | +SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex*); |
| 6340 | +SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex*); |
| 6341 | +SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex*); |
| 6342 | +SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex*); |
| 6283 | 6343 | |
| 6284 | 6344 | /* |
| 6285 | 6345 | ** CAPI3REF: Mutex Methods Object |
| 6286 | 6346 | ** |
| 6287 | 6347 | ** An instance of this structure defines the low-level routines |
| | @@ -6387,12 +6447,12 @@ |
| 6387 | 6447 | ** call to sqlite3_mutex_held() to fail, so a non-zero return is |
| 6388 | 6448 | ** the appropriate thing to do. The sqlite3_mutex_notheld() |
| 6389 | 6449 | ** interface should also return 1 when given a NULL pointer. |
| 6390 | 6450 | */ |
| 6391 | 6451 | #ifndef NDEBUG |
| 6392 | | -SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); |
| 6393 | | -SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); |
| 6452 | +SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex*); |
| 6453 | +SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex*); |
| 6394 | 6454 | #endif |
| 6395 | 6455 | |
| 6396 | 6456 | /* |
| 6397 | 6457 | ** CAPI3REF: Mutex Types |
| 6398 | 6458 | ** |
| | @@ -6417,21 +6477,23 @@ |
| 6417 | 6477 | #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ |
| 6418 | 6478 | #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ |
| 6419 | 6479 | |
| 6420 | 6480 | /* |
| 6421 | 6481 | ** CAPI3REF: Retrieve the mutex for a database connection |
| 6482 | +** METHOD: sqlite3 |
| 6422 | 6483 | ** |
| 6423 | 6484 | ** ^This interface returns a pointer the [sqlite3_mutex] object that |
| 6424 | 6485 | ** serializes access to the [database connection] given in the argument |
| 6425 | 6486 | ** when the [threading mode] is Serialized. |
| 6426 | 6487 | ** ^If the [threading mode] is Single-thread or Multi-thread then this |
| 6427 | 6488 | ** routine returns a NULL pointer. |
| 6428 | 6489 | */ |
| 6429 | | -SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); |
| 6490 | +SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*); |
| 6430 | 6491 | |
| 6431 | 6492 | /* |
| 6432 | 6493 | ** CAPI3REF: Low-Level Control Of Database Files |
| 6494 | +** METHOD: sqlite3 |
| 6433 | 6495 | ** |
| 6434 | 6496 | ** ^The [sqlite3_file_control()] interface makes a direct call to the |
| 6435 | 6497 | ** xFileControl method for the [sqlite3_io_methods] object associated |
| 6436 | 6498 | ** with a particular database identified by the second argument. ^The |
| 6437 | 6499 | ** name of the database is "main" for the main database or "temp" for the |
| | @@ -6458,11 +6520,11 @@ |
| 6458 | 6520 | ** an incorrect zDbName and an SQLITE_ERROR return from the underlying |
| 6459 | 6521 | ** xFileControl method. |
| 6460 | 6522 | ** |
| 6461 | 6523 | ** See also: [SQLITE_FCNTL_LOCKSTATE] |
| 6462 | 6524 | */ |
| 6463 | | -SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); |
| 6525 | +SQLITE_API int SQLITE_STDCALL sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); |
| 6464 | 6526 | |
| 6465 | 6527 | /* |
| 6466 | 6528 | ** CAPI3REF: Testing Interface |
| 6467 | 6529 | ** |
| 6468 | 6530 | ** ^The sqlite3_test_control() interface is used to read out internal |
| | @@ -6477,11 +6539,11 @@ |
| 6477 | 6539 | ** The details of the operation codes, their meanings, the parameters |
| 6478 | 6540 | ** they take, and what they do are all subject to change without notice. |
| 6479 | 6541 | ** Unlike most of the SQLite API, this function is not guaranteed to |
| 6480 | 6542 | ** operate consistently from one release to the next. |
| 6481 | 6543 | */ |
| 6482 | | -SQLITE_API int sqlite3_test_control(int op, ...); |
| 6544 | +SQLITE_API int SQLITE_CDECL sqlite3_test_control(int op, ...); |
| 6483 | 6545 | |
| 6484 | 6546 | /* |
| 6485 | 6547 | ** CAPI3REF: Testing Interface Operation Codes |
| 6486 | 6548 | ** |
| 6487 | 6549 | ** These constants are the valid operation code parameters used |
| | @@ -6540,12 +6602,12 @@ |
| 6540 | 6602 | ** be represented by a 32-bit integer, then the values returned by |
| 6541 | 6603 | ** sqlite3_status() are undefined. |
| 6542 | 6604 | ** |
| 6543 | 6605 | ** See also: [sqlite3_db_status()] |
| 6544 | 6606 | */ |
| 6545 | | -SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); |
| 6546 | | -SQLITE_API int sqlite3_status64( |
| 6607 | +SQLITE_API int SQLITE_STDCALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); |
| 6608 | +SQLITE_API int SQLITE_STDCALL sqlite3_status64( |
| 6547 | 6609 | int op, |
| 6548 | 6610 | sqlite3_int64 *pCurrent, |
| 6549 | 6611 | sqlite3_int64 *pHighwater, |
| 6550 | 6612 | int resetFlag |
| 6551 | 6613 | ); |
| | @@ -6644,10 +6706,11 @@ |
| 6644 | 6706 | #define SQLITE_STATUS_SCRATCH_SIZE 8 |
| 6645 | 6707 | #define SQLITE_STATUS_MALLOC_COUNT 9 |
| 6646 | 6708 | |
| 6647 | 6709 | /* |
| 6648 | 6710 | ** CAPI3REF: Database Connection Status |
| 6711 | +** METHOD: sqlite3 |
| 6649 | 6712 | ** |
| 6650 | 6713 | ** ^This interface is used to retrieve runtime status information |
| 6651 | 6714 | ** about a single [database connection]. ^The first argument is the |
| 6652 | 6715 | ** database connection object to be interrogated. ^The second argument |
| 6653 | 6716 | ** is an integer constant, taken from the set of |
| | @@ -6664,11 +6727,11 @@ |
| 6664 | 6727 | ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a |
| 6665 | 6728 | ** non-zero [error code] on failure. |
| 6666 | 6729 | ** |
| 6667 | 6730 | ** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. |
| 6668 | 6731 | */ |
| 6669 | | -SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); |
| 6732 | +SQLITE_API int SQLITE_STDCALL sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); |
| 6670 | 6733 | |
| 6671 | 6734 | /* |
| 6672 | 6735 | ** CAPI3REF: Status Parameters for database connections |
| 6673 | 6736 | ** KEYWORDS: {SQLITE_DBSTATUS options} |
| 6674 | 6737 | ** |
| | @@ -6772,10 +6835,11 @@ |
| 6772 | 6835 | #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */ |
| 6773 | 6836 | |
| 6774 | 6837 | |
| 6775 | 6838 | /* |
| 6776 | 6839 | ** CAPI3REF: Prepared Statement Status |
| 6840 | +** METHOD: sqlite3_stmt |
| 6777 | 6841 | ** |
| 6778 | 6842 | ** ^(Each prepared statement maintains various |
| 6779 | 6843 | ** [SQLITE_STMTSTATUS counters] that measure the number |
| 6780 | 6844 | ** of times it has performed specific operations.)^ These counters can |
| 6781 | 6845 | ** be used to monitor the performance characteristics of the prepared |
| | @@ -6793,11 +6857,11 @@ |
| 6793 | 6857 | ** ^If the resetFlg is true, then the counter is reset to zero after this |
| 6794 | 6858 | ** interface call returns. |
| 6795 | 6859 | ** |
| 6796 | 6860 | ** See also: [sqlite3_status()] and [sqlite3_db_status()]. |
| 6797 | 6861 | */ |
| 6798 | | -SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); |
| 6862 | +SQLITE_API int SQLITE_STDCALL sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); |
| 6799 | 6863 | |
| 6800 | 6864 | /* |
| 6801 | 6865 | ** CAPI3REF: Status Parameters for prepared statements |
| 6802 | 6866 | ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters} |
| 6803 | 6867 | ** |
| | @@ -7262,23 +7326,24 @@ |
| 7262 | 7326 | ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount() |
| 7263 | 7327 | ** APIs are not strictly speaking threadsafe. If they are invoked at the |
| 7264 | 7328 | ** same time as another thread is invoking sqlite3_backup_step() it is |
| 7265 | 7329 | ** possible that they return invalid values. |
| 7266 | 7330 | */ |
| 7267 | | -SQLITE_API sqlite3_backup *sqlite3_backup_init( |
| 7331 | +SQLITE_API sqlite3_backup *SQLITE_STDCALL sqlite3_backup_init( |
| 7268 | 7332 | sqlite3 *pDest, /* Destination database handle */ |
| 7269 | 7333 | const char *zDestName, /* Destination database name */ |
| 7270 | 7334 | sqlite3 *pSource, /* Source database handle */ |
| 7271 | 7335 | const char *zSourceName /* Source database name */ |
| 7272 | 7336 | ); |
| 7273 | | -SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage); |
| 7274 | | -SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p); |
| 7275 | | -SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p); |
| 7276 | | -SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p); |
| 7337 | +SQLITE_API int SQLITE_STDCALL sqlite3_backup_step(sqlite3_backup *p, int nPage); |
| 7338 | +SQLITE_API int SQLITE_STDCALL sqlite3_backup_finish(sqlite3_backup *p); |
| 7339 | +SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p); |
| 7340 | +SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p); |
| 7277 | 7341 | |
| 7278 | 7342 | /* |
| 7279 | 7343 | ** CAPI3REF: Unlock Notification |
| 7344 | +** METHOD: sqlite3 |
| 7280 | 7345 | ** |
| 7281 | 7346 | ** ^When running in shared-cache mode, a database operation may fail with |
| 7282 | 7347 | ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or |
| 7283 | 7348 | ** individual tables within the shared-cache cannot be obtained. See |
| 7284 | 7349 | ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. |
| | @@ -7387,11 +7452,11 @@ |
| 7387 | 7452 | ** by an sqlite3_step() call. ^(If there is a blocking connection, then the |
| 7388 | 7453 | ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in |
| 7389 | 7454 | ** the special "DROP TABLE/INDEX" case, the extended error code is just |
| 7390 | 7455 | ** SQLITE_LOCKED.)^ |
| 7391 | 7456 | */ |
| 7392 | | -SQLITE_API int sqlite3_unlock_notify( |
| 7457 | +SQLITE_API int SQLITE_STDCALL sqlite3_unlock_notify( |
| 7393 | 7458 | sqlite3 *pBlocked, /* Waiting connection */ |
| 7394 | 7459 | void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ |
| 7395 | 7460 | void *pNotifyArg /* Argument to pass to xNotify */ |
| 7396 | 7461 | ); |
| 7397 | 7462 | |
| | @@ -7402,12 +7467,12 @@ |
| 7402 | 7467 | ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications |
| 7403 | 7468 | ** and extensions to compare the contents of two buffers containing UTF-8 |
| 7404 | 7469 | ** strings in a case-independent fashion, using the same definition of "case |
| 7405 | 7470 | ** independence" that SQLite uses internally when comparing identifiers. |
| 7406 | 7471 | */ |
| 7407 | | -SQLITE_API int sqlite3_stricmp(const char *, const char *); |
| 7408 | | -SQLITE_API int sqlite3_strnicmp(const char *, const char *, int); |
| 7472 | +SQLITE_API int SQLITE_STDCALL sqlite3_stricmp(const char *, const char *); |
| 7473 | +SQLITE_API int SQLITE_STDCALL sqlite3_strnicmp(const char *, const char *, int); |
| 7409 | 7474 | |
| 7410 | 7475 | /* |
| 7411 | 7476 | ** CAPI3REF: String Globbing |
| 7412 | 7477 | * |
| 7413 | 7478 | ** ^The [sqlite3_strglob(P,X)] interface returns zero if string X matches |
| | @@ -7418,11 +7483,11 @@ |
| 7418 | 7483 | ** sensitive. |
| 7419 | 7484 | ** |
| 7420 | 7485 | ** Note that this routine returns zero on a match and non-zero if the strings |
| 7421 | 7486 | ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()]. |
| 7422 | 7487 | */ |
| 7423 | | -SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr); |
| 7488 | +SQLITE_API int SQLITE_STDCALL sqlite3_strglob(const char *zGlob, const char *zStr); |
| 7424 | 7489 | |
| 7425 | 7490 | /* |
| 7426 | 7491 | ** CAPI3REF: Error Logging Interface |
| 7427 | 7492 | ** |
| 7428 | 7493 | ** ^The [sqlite3_log()] interface writes a message into the [error log] |
| | @@ -7441,14 +7506,15 @@ |
| 7441 | 7506 | ** will not use dynamically allocated memory. The log message is stored in |
| 7442 | 7507 | ** a fixed-length buffer on the stack. If the log message is longer than |
| 7443 | 7508 | ** a few hundred characters, it will be truncated to the length of the |
| 7444 | 7509 | ** buffer. |
| 7445 | 7510 | */ |
| 7446 | | -SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...); |
| 7511 | +SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...); |
| 7447 | 7512 | |
| 7448 | 7513 | /* |
| 7449 | 7514 | ** CAPI3REF: Write-Ahead Log Commit Hook |
| 7515 | +** METHOD: sqlite3 |
| 7450 | 7516 | ** |
| 7451 | 7517 | ** ^The [sqlite3_wal_hook()] function is used to register a callback that |
| 7452 | 7518 | ** is invoked each time data is committed to a database in wal mode. |
| 7453 | 7519 | ** |
| 7454 | 7520 | ** ^(The callback is invoked by SQLite after the commit has taken place and |
| | @@ -7476,18 +7542,19 @@ |
| 7476 | 7542 | ** previously registered write-ahead log callback. ^Note that the |
| 7477 | 7543 | ** [sqlite3_wal_autocheckpoint()] interface and the |
| 7478 | 7544 | ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will |
| 7479 | 7545 | ** those overwrite any prior [sqlite3_wal_hook()] settings. |
| 7480 | 7546 | */ |
| 7481 | | -SQLITE_API void *sqlite3_wal_hook( |
| 7547 | +SQLITE_API void *SQLITE_STDCALL sqlite3_wal_hook( |
| 7482 | 7548 | sqlite3*, |
| 7483 | 7549 | int(*)(void *,sqlite3*,const char*,int), |
| 7484 | 7550 | void* |
| 7485 | 7551 | ); |
| 7486 | 7552 | |
| 7487 | 7553 | /* |
| 7488 | 7554 | ** CAPI3REF: Configure an auto-checkpoint |
| 7555 | +** METHOD: sqlite3 |
| 7489 | 7556 | ** |
| 7490 | 7557 | ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around |
| 7491 | 7558 | ** [sqlite3_wal_hook()] that causes any database on [database connection] D |
| 7492 | 7559 | ** to automatically [checkpoint] |
| 7493 | 7560 | ** after committing a transaction if there are N or |
| | @@ -7510,14 +7577,15 @@ |
| 7510 | 7577 | ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT] |
| 7511 | 7578 | ** pages. The use of this interface |
| 7512 | 7579 | ** is only necessary if the default setting is found to be suboptimal |
| 7513 | 7580 | ** for a particular application. |
| 7514 | 7581 | */ |
| 7515 | | -SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7582 | +SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 7516 | 7583 | |
| 7517 | 7584 | /* |
| 7518 | 7585 | ** CAPI3REF: Checkpoint a database |
| 7586 | +** METHOD: sqlite3 |
| 7519 | 7587 | ** |
| 7520 | 7588 | ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to |
| 7521 | 7589 | ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ |
| 7522 | 7590 | ** |
| 7523 | 7591 | ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the |
| | @@ -7531,14 +7599,15 @@ |
| 7531 | 7599 | ** interface was added. This interface is retained for backwards |
| 7532 | 7600 | ** compatibility and as a convenience for applications that need to manually |
| 7533 | 7601 | ** start a callback but which do not need the full power (and corresponding |
| 7534 | 7602 | ** complication) of [sqlite3_wal_checkpoint_v2()]. |
| 7535 | 7603 | */ |
| 7536 | | -SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7604 | +SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 7537 | 7605 | |
| 7538 | 7606 | /* |
| 7539 | 7607 | ** CAPI3REF: Checkpoint a database |
| 7608 | +** METHOD: sqlite3 |
| 7540 | 7609 | ** |
| 7541 | 7610 | ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint |
| 7542 | 7611 | ** operation on database X of [database connection] D in mode M. Status |
| 7543 | 7612 | ** information is written back into integers pointed to by L and C.)^ |
| 7544 | 7613 | ** ^(The M parameter must be a valid [checkpoint mode]:)^ |
| | @@ -7624,11 +7693,11 @@ |
| 7624 | 7693 | ** [sqlite3_errcode()] and [sqlite3_errmsg()]. |
| 7625 | 7694 | ** |
| 7626 | 7695 | ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface |
| 7627 | 7696 | ** from SQL. |
| 7628 | 7697 | */ |
| 7629 | | -SQLITE_API int sqlite3_wal_checkpoint_v2( |
| 7698 | +SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint_v2( |
| 7630 | 7699 | sqlite3 *db, /* Database handle */ |
| 7631 | 7700 | const char *zDb, /* Name of attached database (or NULL) */ |
| 7632 | 7701 | int eMode, /* SQLITE_CHECKPOINT_* value */ |
| 7633 | 7702 | int *pnLog, /* OUT: Size of WAL log in frames */ |
| 7634 | 7703 | int *pnCkpt /* OUT: Total number of frames checkpointed */ |
| | @@ -7660,11 +7729,11 @@ |
| 7660 | 7729 | ** |
| 7661 | 7730 | ** At present, there is only one option that may be configured using |
| 7662 | 7731 | ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options |
| 7663 | 7732 | ** may be added in the future. |
| 7664 | 7733 | */ |
| 7665 | | -SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); |
| 7734 | +SQLITE_API int SQLITE_CDECL sqlite3_vtab_config(sqlite3*, int op, ...); |
| 7666 | 7735 | |
| 7667 | 7736 | /* |
| 7668 | 7737 | ** CAPI3REF: Virtual Table Configuration Options |
| 7669 | 7738 | ** |
| 7670 | 7739 | ** These macros define the various options to the |
| | @@ -7713,11 +7782,11 @@ |
| 7713 | 7782 | ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL], |
| 7714 | 7783 | ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode |
| 7715 | 7784 | ** of the SQL statement that triggered the call to the [xUpdate] method of the |
| 7716 | 7785 | ** [virtual table]. |
| 7717 | 7786 | */ |
| 7718 | | -SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); |
| 7787 | +SQLITE_API int SQLITE_STDCALL sqlite3_vtab_on_conflict(sqlite3 *); |
| 7719 | 7788 | |
| 7720 | 7789 | /* |
| 7721 | 7790 | ** CAPI3REF: Conflict resolution modes |
| 7722 | 7791 | ** KEYWORDS: {conflict resolution mode} |
| 7723 | 7792 | ** |
| | @@ -7789,10 +7858,11 @@ |
| 7789 | 7858 | #define SQLITE_SCANSTAT_EXPLAIN 4 |
| 7790 | 7859 | #define SQLITE_SCANSTAT_SELECTID 5 |
| 7791 | 7860 | |
| 7792 | 7861 | /* |
| 7793 | 7862 | ** CAPI3REF: Prepared Statement Scan Status |
| 7863 | +** METHOD: sqlite3_stmt |
| 7794 | 7864 | ** |
| 7795 | 7865 | ** This interface returns information about the predicted and measured |
| 7796 | 7866 | ** performance for pStmt. Advanced applications can use this |
| 7797 | 7867 | ** interface to compare the predicted and the measured performance and |
| 7798 | 7868 | ** issue warnings and/or rerun [ANALYZE] if discrepancies are found. |
| | @@ -7817,26 +7887,27 @@ |
| 7817 | 7887 | ** as if the loop did not exist - it returns non-zero and leave the variable |
| 7818 | 7888 | ** that pOut points to unchanged. |
| 7819 | 7889 | ** |
| 7820 | 7890 | ** See also: [sqlite3_stmt_scanstatus_reset()] |
| 7821 | 7891 | */ |
| 7822 | | -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus( |
| 7892 | +SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_stmt_scanstatus( |
| 7823 | 7893 | sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ |
| 7824 | 7894 | int idx, /* Index of loop to report on */ |
| 7825 | 7895 | int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ |
| 7826 | 7896 | void *pOut /* Result written here */ |
| 7827 | 7897 | ); |
| 7828 | 7898 | |
| 7829 | 7899 | /* |
| 7830 | 7900 | ** CAPI3REF: Zero Scan-Status Counters |
| 7901 | +** METHOD: sqlite3_stmt |
| 7831 | 7902 | ** |
| 7832 | 7903 | ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. |
| 7833 | 7904 | ** |
| 7834 | 7905 | ** This API is only available if the library is built with pre-processor |
| 7835 | 7906 | ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| 7836 | 7907 | */ |
| 7837 | | -SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); |
| 7908 | +SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); |
| 7838 | 7909 | |
| 7839 | 7910 | |
| 7840 | 7911 | /* |
| 7841 | 7912 | ** Undo the hack that converts floating point types to integer for |
| 7842 | 7913 | ** builds on processors without floating point support. |
| | @@ -7887,11 +7958,11 @@ |
| 7887 | 7958 | ** Register a geometry callback named zGeom that can be used as part of an |
| 7888 | 7959 | ** R-Tree geometry query as follows: |
| 7889 | 7960 | ** |
| 7890 | 7961 | ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) |
| 7891 | 7962 | */ |
| 7892 | | -SQLITE_API int sqlite3_rtree_geometry_callback( |
| 7963 | +SQLITE_API int SQLITE_STDCALL sqlite3_rtree_geometry_callback( |
| 7893 | 7964 | sqlite3 *db, |
| 7894 | 7965 | const char *zGeom, |
| 7895 | 7966 | int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*), |
| 7896 | 7967 | void *pContext |
| 7897 | 7968 | ); |
| | @@ -7913,11 +7984,11 @@ |
| 7913 | 7984 | ** Register a 2nd-generation geometry callback named zScore that can be |
| 7914 | 7985 | ** used as part of an R-Tree geometry query as follows: |
| 7915 | 7986 | ** |
| 7916 | 7987 | ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...) |
| 7917 | 7988 | */ |
| 7918 | | -SQLITE_API int sqlite3_rtree_query_callback( |
| 7989 | +SQLITE_API int SQLITE_STDCALL sqlite3_rtree_query_callback( |
| 7919 | 7990 | sqlite3 *db, |
| 7920 | 7991 | const char *zQueryFunc, |
| 7921 | 7992 | int (*xQueryFunc)(sqlite3_rtree_query_info*), |
| 7922 | 7993 | void *pContext, |
| 7923 | 7994 | void (*xDestructor)(void*) |
| | @@ -8436,10 +8507,36 @@ |
| 8436 | 8507 | #else |
| 8437 | 8508 | # define ALWAYS(X) (X) |
| 8438 | 8509 | # define NEVER(X) (X) |
| 8439 | 8510 | #endif |
| 8440 | 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 | + |
| 8441 | 8538 | /* |
| 8442 | 8539 | ** Return true (non-zero) if the input is an integer that is too large |
| 8443 | 8540 | ** to fit in 32-bits. This macro is used inside of various testcase() |
| 8444 | 8541 | ** macros to verify that we have tested SQLite for large-file support. |
| 8445 | 8542 | */ |
| | @@ -9157,12 +9254,12 @@ |
| 9157 | 9254 | */ |
| 9158 | 9255 | #ifdef SQLITE_OMIT_WSD |
| 9159 | 9256 | #define SQLITE_WSD const |
| 9160 | 9257 | #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v))) |
| 9161 | 9258 | #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config) |
| 9162 | | -SQLITE_API int sqlite3_wsd_init(int N, int J); |
| 9163 | | -SQLITE_API void *sqlite3_wsd_find(void *K, int L); |
| 9259 | +SQLITE_API int SQLITE_STDCALL sqlite3_wsd_init(int N, int J); |
| 9260 | +SQLITE_API void *SQLITE_STDCALL sqlite3_wsd_find(void *K, int L); |
| 9164 | 9261 | #else |
| 9165 | 9262 | #define SQLITE_WSD |
| 9166 | 9263 | #define GLOBAL(t,v) v |
| 9167 | 9264 | #define sqlite3GlobalConfig sqlite3Config |
| 9168 | 9265 | #endif |
| | @@ -9847,37 +9944,36 @@ |
| 9847 | 9944 | /* Properties such as "out2" or "jump" that are specified in |
| 9848 | 9945 | ** comments following the "case" for each opcode in the vdbe.c |
| 9849 | 9946 | ** are encoded into bitvectors as follows: |
| 9850 | 9947 | */ |
| 9851 | 9948 | #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */ |
| 9852 | | -#define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */ |
| 9853 | | -#define OPFLG_IN1 0x0004 /* in1: P1 is an input */ |
| 9854 | | -#define OPFLG_IN2 0x0008 /* in2: P2 is an input */ |
| 9855 | | -#define OPFLG_IN3 0x0010 /* in3: P3 is an input */ |
| 9856 | | -#define OPFLG_OUT2 0x0020 /* out2: P2 is an output */ |
| 9857 | | -#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 */ |
| 9858 | 9954 | #define OPFLG_INITIALIZER {\ |
| 9859 | 9955 | /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\ |
| 9860 | | -/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\ |
| 9861 | | -/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\ |
| 9862 | | -/* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\ |
| 9863 | | -/* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\ |
| 9864 | | -/* 40 */ 0x04, 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00,\ |
| 9865 | | -/* 48 */ 0x00, 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00,\ |
| 9866 | | -/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,\ |
| 9867 | | -/* 64 */ 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x4c,\ |
| 9868 | | -/* 72 */ 0x4c, 0x02, 0x02, 0x00, 0x05, 0x05, 0x15, 0x15,\ |
| 9869 | | -/* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\ |
| 9870 | | -/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\ |
| 9871 | | -/* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,\ |
| 9872 | | -/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08, 0x00,\ |
| 9873 | | -/* 112 */ 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,\ |
| 9874 | | -/* 120 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 9875 | | -/* 128 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x02, 0x00, 0x01,\ |
| 9876 | | -/* 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,\ |
| 9877 | 9973 | /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\ |
| 9878 | | -/* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,} |
| 9974 | +/* 152 */ 0x00, 0x10, 0x10, 0x01, 0x00, 0x00,} |
| 9879 | 9975 | |
| 9880 | 9976 | /************** End of opcodes.h *********************************************/ |
| 9881 | 9977 | /************** Continuing where we left off in vdbe.h ***********************/ |
| 9882 | 9978 | |
| 9883 | 9979 | /* |
| | @@ -9932,10 +10028,11 @@ |
| 9932 | 10028 | #endif |
| 9933 | 10029 | SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); |
| 9934 | 10030 | |
| 9935 | 10031 | SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*); |
| 9936 | 10032 | SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*); |
| 10033 | +SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int); |
| 9937 | 10034 | SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **); |
| 9938 | 10035 | |
| 9939 | 10036 | typedef int (*RecordCompare)(int,const void*,UnpackedRecord*); |
| 9940 | 10037 | SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*); |
| 9941 | 10038 | |
| | @@ -11069,10 +11166,11 @@ |
| 11069 | 11166 | #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */ |
| 11070 | 11167 | #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */ |
| 11071 | 11168 | #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */ |
| 11072 | 11169 | #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */ |
| 11073 | 11170 | #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */ |
| 11171 | +#define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */ |
| 11074 | 11172 | |
| 11075 | 11173 | |
| 11076 | 11174 | /* |
| 11077 | 11175 | ** Bits of the sqlite3.dbOptFlags field that are used by the |
| 11078 | 11176 | ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to |
| | @@ -11399,38 +11497,12 @@ |
| 11399 | 11497 | int iSavepoint; /* Depth of the SAVEPOINT stack */ |
| 11400 | 11498 | VTable *pNext; /* Next in linked list (see above) */ |
| 11401 | 11499 | }; |
| 11402 | 11500 | |
| 11403 | 11501 | /* |
| 11404 | | -** Each SQL table is represented in memory by an instance of the |
| 11405 | | -** following structure. |
| 11406 | | -** |
| 11407 | | -** Table.zName is the name of the table. The case of the original |
| 11408 | | -** CREATE TABLE statement is stored, but case is not significant for |
| 11409 | | -** comparisons. |
| 11410 | | -** |
| 11411 | | -** Table.nCol is the number of columns in this table. Table.aCol is a |
| 11412 | | -** pointer to an array of Column structures, one for each column. |
| 11413 | | -** |
| 11414 | | -** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of |
| 11415 | | -** the column that is that key. Otherwise Table.iPKey is negative. Note |
| 11416 | | -** that the datatype of the PRIMARY KEY must be INTEGER for this field to |
| 11417 | | -** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of |
| 11418 | | -** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid |
| 11419 | | -** is generated for each row of the table. TF_HasPrimaryKey is set if |
| 11420 | | -** the table has any PRIMARY KEY, INTEGER or otherwise. |
| 11421 | | -** |
| 11422 | | -** Table.tnum is the page number for the root BTree page of the table in the |
| 11423 | | -** database file. If Table.iDb is the index of the database table backend |
| 11424 | | -** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that |
| 11425 | | -** holds temporary tables and indices. If TF_Ephemeral is set |
| 11426 | | -** then the table is stored in a file that is automatically deleted |
| 11427 | | -** when the VDBE cursor to the table is closed. In this case Table.tnum |
| 11428 | | -** refers VDBE cursor number that holds the table open, not to the root |
| 11429 | | -** page number. Transient tables are used to hold the results of a |
| 11430 | | -** sub-query that appears instead of a real table name in the FROM clause |
| 11431 | | -** 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. |
| 11432 | 11504 | */ |
| 11433 | 11505 | struct Table { |
| 11434 | 11506 | char *zName; /* Name of the table or view */ |
| 11435 | 11507 | Column *aCol; /* Information about each column */ |
| 11436 | 11508 | Index *pIndex; /* List of SQL indexes on this table. */ |
| | @@ -11438,15 +11510,15 @@ |
| 11438 | 11510 | FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| 11439 | 11511 | char *zColAff; /* String defining the affinity of each column */ |
| 11440 | 11512 | #ifndef SQLITE_OMIT_CHECK |
| 11441 | 11513 | ExprList *pCheck; /* All CHECK constraints */ |
| 11442 | 11514 | #endif |
| 11443 | | - LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */ |
| 11444 | | - int tnum; /* Root BTree node for this table (see note above) */ |
| 11445 | | - 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 */ |
| 11446 | 11517 | i16 nCol; /* Number of columns in this table */ |
| 11447 | 11518 | u16 nRef; /* Number of pointers to this Table */ |
| 11519 | + LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */ |
| 11448 | 11520 | LogEst szTabRow; /* Estimated size of each table row in bytes */ |
| 11449 | 11521 | #ifdef SQLITE_ENABLE_COSTMULT |
| 11450 | 11522 | LogEst costMult; /* Cost multiplier for using this table */ |
| 11451 | 11523 | #endif |
| 11452 | 11524 | u8 tabFlags; /* Mask of TF_* values */ |
| | @@ -11464,17 +11536,24 @@ |
| 11464 | 11536 | Table *pNextZombie; /* Next on the Parse.pZombieTab list */ |
| 11465 | 11537 | }; |
| 11466 | 11538 | |
| 11467 | 11539 | /* |
| 11468 | 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. |
| 11469 | 11547 | */ |
| 11470 | 11548 | #define TF_Readonly 0x01 /* Read-only system table */ |
| 11471 | 11549 | #define TF_Ephemeral 0x02 /* An ephemeral table */ |
| 11472 | 11550 | #define TF_HasPrimaryKey 0x04 /* Table has a primary key */ |
| 11473 | 11551 | #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */ |
| 11474 | 11552 | #define TF_Virtual 0x10 /* Is a virtual table */ |
| 11475 | 11553 | #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */ |
| 11554 | +#define TF_OOOHidden 0x40 /* Out-of-Order hidden columns */ |
| 11476 | 11555 | |
| 11477 | 11556 | |
| 11478 | 11557 | /* |
| 11479 | 11558 | ** Test to see whether or not a table is a virtual table. This is |
| 11480 | 11559 | ** done as a macro so that it will be optimized out when virtual |
| | @@ -12227,15 +12306,16 @@ |
| 12227 | 12306 | #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */ |
| 12228 | 12307 | #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */ |
| 12229 | 12308 | #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ |
| 12230 | 12309 | #define SF_Compound 0x0040 /* Part of a compound query */ |
| 12231 | 12310 | #define SF_Values 0x0080 /* Synthesized from VALUES clause */ |
| 12232 | | -#define SF_AllValues 0x0100 /* All terms of compound are VALUES */ |
| 12311 | +#define SF_MultiValue 0x0100 /* Single VALUES term with multiple rows */ |
| 12233 | 12312 | #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */ |
| 12234 | 12313 | #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */ |
| 12235 | 12314 | #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */ |
| 12236 | 12315 | #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */ |
| 12316 | +#define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */ |
| 12237 | 12317 | |
| 12238 | 12318 | |
| 12239 | 12319 | /* |
| 12240 | 12320 | ** The results of a SELECT can be distributed in several ways, as defined |
| 12241 | 12321 | ** by one of the following macros. The "SRT" prefix means "SELECT Result |
| | @@ -12610,24 +12690,24 @@ |
| 12610 | 12690 | * |
| 12611 | 12691 | * (op == TK_INSERT) |
| 12612 | 12692 | * orconf -> stores the ON CONFLICT algorithm |
| 12613 | 12693 | * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then |
| 12614 | 12694 | * this stores a pointer to the SELECT statement. Otherwise NULL. |
| 12615 | | - * target -> A token holding the quoted name of the table to insert into. |
| 12695 | + * zTarget -> Dequoted name of the table to insert into. |
| 12616 | 12696 | * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then |
| 12617 | 12697 | * this stores values to be inserted. Otherwise NULL. |
| 12618 | 12698 | * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ... |
| 12619 | 12699 | * statement, then this stores the column-names to be |
| 12620 | 12700 | * inserted into. |
| 12621 | 12701 | * |
| 12622 | 12702 | * (op == TK_DELETE) |
| 12623 | | - * target -> A token holding the quoted name of the table to delete from. |
| 12703 | + * zTarget -> Dequoted name of the table to delete from. |
| 12624 | 12704 | * pWhere -> The WHERE clause of the DELETE statement if one is specified. |
| 12625 | 12705 | * Otherwise NULL. |
| 12626 | 12706 | * |
| 12627 | 12707 | * (op == TK_UPDATE) |
| 12628 | | - * target -> A token holding the quoted name of the table to update rows of. |
| 12708 | + * zTarget -> Dequoted name of the table to update. |
| 12629 | 12709 | * pWhere -> The WHERE clause of the UPDATE statement if one is specified. |
| 12630 | 12710 | * Otherwise NULL. |
| 12631 | 12711 | * pExprList -> A list of the columns to update and the expressions to update |
| 12632 | 12712 | * them to. See sqlite3Update() documentation of "pChanges" |
| 12633 | 12713 | * argument. |
| | @@ -12635,12 +12715,12 @@ |
| 12635 | 12715 | */ |
| 12636 | 12716 | struct TriggerStep { |
| 12637 | 12717 | u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */ |
| 12638 | 12718 | u8 orconf; /* OE_Rollback etc. */ |
| 12639 | 12719 | Trigger *pTrig; /* The trigger that this step is a part of */ |
| 12640 | | - Select *pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */ |
| 12641 | | - 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 */ |
| 12642 | 12722 | Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ |
| 12643 | 12723 | ExprList *pExprList; /* SET clause for UPDATE. */ |
| 12644 | 12724 | IdList *pIdList; /* Column names for INSERT */ |
| 12645 | 12725 | TriggerStep *pNext; /* Next in the link-list */ |
| 12646 | 12726 | TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ |
| | @@ -12669,12 +12749,11 @@ |
| 12669 | 12749 | sqlite3 *db; /* Optional database for lookaside. Can be NULL */ |
| 12670 | 12750 | char *zBase; /* A base allocation. Not from malloc. */ |
| 12671 | 12751 | char *zText; /* The string collected so far */ |
| 12672 | 12752 | int nChar; /* Length of the string so far */ |
| 12673 | 12753 | int nAlloc; /* Amount of space allocated in zText */ |
| 12674 | | - int mxAlloc; /* Maximum allowed string length */ |
| 12675 | | - u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */ |
| 12754 | + int mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */ |
| 12676 | 12755 | u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */ |
| 12677 | 12756 | }; |
| 12678 | 12757 | #define STRACCUM_NOMEM 1 |
| 12679 | 12758 | #define STRACCUM_TOOBIG 2 |
| 12680 | 12759 | |
| | @@ -12987,11 +13066,11 @@ |
| 12987 | 13066 | SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list); |
| 12988 | 13067 | SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...); |
| 12989 | 13068 | SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 12990 | 13069 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
| 12991 | 13070 | SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...); |
| 12992 | | -#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) |
| 13071 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 12993 | 13072 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...); |
| 12994 | 13073 | #endif |
| 12995 | 13074 | #if defined(SQLITE_TEST) |
| 12996 | 13075 | SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*); |
| 12997 | 13076 | #endif |
| | @@ -13334,11 +13413,11 @@ |
| 13334 | 13413 | SQLITE_PRIVATE void sqlite3Error(sqlite3*,int); |
| 13335 | 13414 | SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n); |
| 13336 | 13415 | SQLITE_PRIVATE u8 sqlite3HexToInt(int h); |
| 13337 | 13416 | SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
| 13338 | 13417 | |
| 13339 | | -#if defined(SQLITE_TEST) |
| 13418 | +#if defined(SQLITE_NEED_ERR_NAME) |
| 13340 | 13419 | SQLITE_PRIVATE const char *sqlite3ErrName(int); |
| 13341 | 13420 | #endif |
| 13342 | 13421 | |
| 13343 | 13422 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 13344 | 13423 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| | @@ -13428,11 +13507,11 @@ |
| 13428 | 13507 | FuncDestructor *pDestructor |
| 13429 | 13508 | ); |
| 13430 | 13509 | SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); |
| 13431 | 13510 | SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); |
| 13432 | 13511 | |
| 13433 | | -SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int); |
| 13512 | +SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int); |
| 13434 | 13513 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int); |
| 13435 | 13514 | SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*); |
| 13436 | 13515 | SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char); |
| 13437 | 13516 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 13438 | 13517 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*); |
| | @@ -13646,11 +13725,11 @@ |
| 13646 | 13725 | ** print I/O tracing messages. |
| 13647 | 13726 | */ |
| 13648 | 13727 | #ifdef SQLITE_ENABLE_IOTRACE |
| 13649 | 13728 | # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; } |
| 13650 | 13729 | SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe*); |
| 13651 | | -void (*sqlite3IoTrace)(const char*,...); |
| 13730 | +SQLITE_API SQLITE_EXTERN void (SQLITE_CDECL *sqlite3IoTrace)(const char*,...); |
| 13652 | 13731 | #else |
| 13653 | 13732 | # define IOTRACE(A) |
| 13654 | 13733 | # define sqlite3VdbeIOTraceSql(X) |
| 13655 | 13734 | #endif |
| 13656 | 13735 | |
| | @@ -14044,10 +14123,13 @@ |
| 14044 | 14123 | #if SQLITE_ENABLE_CEROD |
| 14045 | 14124 | "ENABLE_CEROD", |
| 14046 | 14125 | #endif |
| 14047 | 14126 | #if SQLITE_ENABLE_COLUMN_METADATA |
| 14048 | 14127 | "ENABLE_COLUMN_METADATA", |
| 14128 | +#endif |
| 14129 | +#if SQLITE_ENABLE_DBSTAT_VTAB |
| 14130 | + "ENABLE_DBSTAT_VTAB", |
| 14049 | 14131 | #endif |
| 14050 | 14132 | #if SQLITE_ENABLE_EXPENSIVE_ASSERT |
| 14051 | 14133 | "ENABLE_EXPENSIVE_ASSERT", |
| 14052 | 14134 | #endif |
| 14053 | 14135 | #if SQLITE_ENABLE_FTS1 |
| | @@ -14359,11 +14441,11 @@ |
| 14359 | 14441 | ** was used and false if not. |
| 14360 | 14442 | ** |
| 14361 | 14443 | ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix |
| 14362 | 14444 | ** is not required for a match. |
| 14363 | 14445 | */ |
| 14364 | | -SQLITE_API int sqlite3_compileoption_used(const char *zOptName){ |
| 14446 | +SQLITE_API int SQLITE_STDCALL sqlite3_compileoption_used(const char *zOptName){ |
| 14365 | 14447 | int i, n; |
| 14366 | 14448 | |
| 14367 | 14449 | #if SQLITE_ENABLE_API_ARMOR |
| 14368 | 14450 | if( zOptName==0 ){ |
| 14369 | 14451 | (void)SQLITE_MISUSE_BKPT; |
| | @@ -14387,11 +14469,11 @@ |
| 14387 | 14469 | |
| 14388 | 14470 | /* |
| 14389 | 14471 | ** Return the N-th compile-time option string. If N is out of range, |
| 14390 | 14472 | ** return a NULL pointer. |
| 14391 | 14473 | */ |
| 14392 | | -SQLITE_API const char *sqlite3_compileoption_get(int N){ |
| 14474 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_compileoption_get(int N){ |
| 14393 | 14475 | if( N>=0 && N<ArraySize(azCompileOpt) ){ |
| 14394 | 14476 | return azCompileOpt[N]; |
| 14395 | 14477 | } |
| 14396 | 14478 | return 0; |
| 14397 | 14479 | } |
| | @@ -15024,11 +15106,11 @@ |
| 15024 | 15106 | } |
| 15025 | 15107 | |
| 15026 | 15108 | /* |
| 15027 | 15109 | ** Query status information. |
| 15028 | 15110 | */ |
| 15029 | | -SQLITE_API int sqlite3_status64( |
| 15111 | +SQLITE_API int SQLITE_STDCALL sqlite3_status64( |
| 15030 | 15112 | int op, |
| 15031 | 15113 | sqlite3_int64 *pCurrent, |
| 15032 | 15114 | sqlite3_int64 *pHighwater, |
| 15033 | 15115 | int resetFlag |
| 15034 | 15116 | ){ |
| | @@ -15049,11 +15131,11 @@ |
| 15049 | 15131 | } |
| 15050 | 15132 | sqlite3_mutex_leave(pMutex); |
| 15051 | 15133 | (void)pMutex; /* Prevent warning when SQLITE_THREADSAFE=0 */ |
| 15052 | 15134 | return SQLITE_OK; |
| 15053 | 15135 | } |
| 15054 | | -SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ |
| 15136 | +SQLITE_API int SQLITE_STDCALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ |
| 15055 | 15137 | sqlite3_int64 iCur, iHwtr; |
| 15056 | 15138 | int rc; |
| 15057 | 15139 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 15058 | 15140 | if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; |
| 15059 | 15141 | #endif |
| | @@ -15066,11 +15148,11 @@ |
| 15066 | 15148 | } |
| 15067 | 15149 | |
| 15068 | 15150 | /* |
| 15069 | 15151 | ** Query status information for a single database connection |
| 15070 | 15152 | */ |
| 15071 | | -SQLITE_API int sqlite3_db_status( |
| 15153 | +SQLITE_API int SQLITE_STDCALL sqlite3_db_status( |
| 15072 | 15154 | sqlite3 *db, /* The database connection whose status is desired */ |
| 15073 | 15155 | int op, /* Status verb */ |
| 15074 | 15156 | int *pCurrent, /* Write current value here */ |
| 15075 | 15157 | int *pHighwater, /* Write high-water mark here */ |
| 15076 | 15158 | int resetFlag /* Reset high-water mark if true */ |
| | @@ -16690,11 +16772,11 @@ |
| 16690 | 16772 | |
| 16691 | 16773 | /* |
| 16692 | 16774 | ** Locate a VFS by name. If no name is given, simply return the |
| 16693 | 16775 | ** first VFS on the list. |
| 16694 | 16776 | */ |
| 16695 | | -SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfs){ |
| 16777 | +SQLITE_API sqlite3_vfs *SQLITE_STDCALL sqlite3_vfs_find(const char *zVfs){ |
| 16696 | 16778 | sqlite3_vfs *pVfs = 0; |
| 16697 | 16779 | #if SQLITE_THREADSAFE |
| 16698 | 16780 | sqlite3_mutex *mutex; |
| 16699 | 16781 | #endif |
| 16700 | 16782 | #ifndef SQLITE_OMIT_AUTOINIT |
| | @@ -16736,11 +16818,11 @@ |
| 16736 | 16818 | /* |
| 16737 | 16819 | ** Register a VFS with the system. It is harmless to register the same |
| 16738 | 16820 | ** VFS multiple times. The new VFS becomes the default if makeDflt is |
| 16739 | 16821 | ** true. |
| 16740 | 16822 | */ |
| 16741 | | -SQLITE_API int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){ |
| 16823 | +SQLITE_API int SQLITE_STDCALL sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){ |
| 16742 | 16824 | MUTEX_LOGIC(sqlite3_mutex *mutex;) |
| 16743 | 16825 | #ifndef SQLITE_OMIT_AUTOINIT |
| 16744 | 16826 | int rc = sqlite3_initialize(); |
| 16745 | 16827 | if( rc ) return rc; |
| 16746 | 16828 | #endif |
| | @@ -16764,11 +16846,11 @@ |
| 16764 | 16846 | } |
| 16765 | 16847 | |
| 16766 | 16848 | /* |
| 16767 | 16849 | ** Unregister a VFS so that it is no longer accessible. |
| 16768 | 16850 | */ |
| 16769 | | -SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){ |
| 16851 | +SQLITE_API int SQLITE_STDCALL sqlite3_vfs_unregister(sqlite3_vfs *pVfs){ |
| 16770 | 16852 | #if SQLITE_THREADSAFE |
| 16771 | 16853 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 16772 | 16854 | #endif |
| 16773 | 16855 | sqlite3_mutex_enter(mutex); |
| 16774 | 16856 | vfsUnlink(pVfs); |
| | @@ -19100,11 +19182,11 @@ |
| 19100 | 19182 | } |
| 19101 | 19183 | |
| 19102 | 19184 | /* |
| 19103 | 19185 | ** Retrieve a pointer to a static mutex or allocate a new dynamic one. |
| 19104 | 19186 | */ |
| 19105 | | -SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){ |
| 19187 | +SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int id){ |
| 19106 | 19188 | #ifndef SQLITE_OMIT_AUTOINIT |
| 19107 | 19189 | if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; |
| 19108 | 19190 | if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0; |
| 19109 | 19191 | #endif |
| 19110 | 19192 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| | @@ -19119,31 +19201,31 @@ |
| 19119 | 19201 | } |
| 19120 | 19202 | |
| 19121 | 19203 | /* |
| 19122 | 19204 | ** Free a dynamic mutex. |
| 19123 | 19205 | */ |
| 19124 | | -SQLITE_API void sqlite3_mutex_free(sqlite3_mutex *p){ |
| 19206 | +SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex *p){ |
| 19125 | 19207 | if( p ){ |
| 19126 | 19208 | sqlite3GlobalConfig.mutex.xMutexFree(p); |
| 19127 | 19209 | } |
| 19128 | 19210 | } |
| 19129 | 19211 | |
| 19130 | 19212 | /* |
| 19131 | 19213 | ** Obtain the mutex p. If some other thread already has the mutex, block |
| 19132 | 19214 | ** until it can be obtained. |
| 19133 | 19215 | */ |
| 19134 | | -SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex *p){ |
| 19216 | +SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex *p){ |
| 19135 | 19217 | if( p ){ |
| 19136 | 19218 | sqlite3GlobalConfig.mutex.xMutexEnter(p); |
| 19137 | 19219 | } |
| 19138 | 19220 | } |
| 19139 | 19221 | |
| 19140 | 19222 | /* |
| 19141 | 19223 | ** Obtain the mutex p. If successful, return SQLITE_OK. Otherwise, if another |
| 19142 | 19224 | ** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY. |
| 19143 | 19225 | */ |
| 19144 | | -SQLITE_API int sqlite3_mutex_try(sqlite3_mutex *p){ |
| 19226 | +SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex *p){ |
| 19145 | 19227 | int rc = SQLITE_OK; |
| 19146 | 19228 | if( p ){ |
| 19147 | 19229 | return sqlite3GlobalConfig.mutex.xMutexTry(p); |
| 19148 | 19230 | } |
| 19149 | 19231 | return rc; |
| | @@ -19153,11 +19235,11 @@ |
| 19153 | 19235 | ** The sqlite3_mutex_leave() routine exits a mutex that was previously |
| 19154 | 19236 | ** entered by the same thread. The behavior is undefined if the mutex |
| 19155 | 19237 | ** is not currently entered. If a NULL pointer is passed as an argument |
| 19156 | 19238 | ** this function is a no-op. |
| 19157 | 19239 | */ |
| 19158 | | -SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex *p){ |
| 19240 | +SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex *p){ |
| 19159 | 19241 | if( p ){ |
| 19160 | 19242 | sqlite3GlobalConfig.mutex.xMutexLeave(p); |
| 19161 | 19243 | } |
| 19162 | 19244 | } |
| 19163 | 19245 | |
| | @@ -19164,14 +19246,14 @@ |
| 19164 | 19246 | #ifndef NDEBUG |
| 19165 | 19247 | /* |
| 19166 | 19248 | ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are |
| 19167 | 19249 | ** intended for use inside assert() statements. |
| 19168 | 19250 | */ |
| 19169 | | -SQLITE_API int sqlite3_mutex_held(sqlite3_mutex *p){ |
| 19251 | +SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex *p){ |
| 19170 | 19252 | return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p); |
| 19171 | 19253 | } |
| 19172 | | -SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex *p){ |
| 19254 | +SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex *p){ |
| 19173 | 19255 | return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); |
| 19174 | 19256 | } |
| 19175 | 19257 | #endif |
| 19176 | 19258 | |
| 19177 | 19259 | #endif /* !defined(SQLITE_MUTEX_OMIT) */ |
| | @@ -19812,20 +19894,10 @@ |
| 19812 | 19894 | */ |
| 19813 | 19895 | #ifdef MEMORY_DEBUG |
| 19814 | 19896 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 19815 | 19897 | #endif |
| 19816 | 19898 | |
| 19817 | | -#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 19818 | | -# ifndef SQLITE_DEBUG_OS_TRACE |
| 19819 | | -# define SQLITE_DEBUG_OS_TRACE 0 |
| 19820 | | -# endif |
| 19821 | | - int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; |
| 19822 | | -# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X |
| 19823 | | -#else |
| 19824 | | -# define OSTRACE(X) |
| 19825 | | -#endif |
| 19826 | | - |
| 19827 | 19899 | /* |
| 19828 | 19900 | ** Macros for performance tracing. Normally turned off. Only works |
| 19829 | 19901 | ** on i486 hardware. |
| 19830 | 19902 | */ |
| 19831 | 19903 | #ifdef SQLITE_PERFORMANCE_TRACE |
| | @@ -20163,12 +20235,12 @@ |
| 20163 | 20235 | ** of the sqlite3_initialize() and sqlite3_shutdown() processing, the |
| 20164 | 20236 | ** "interlocked" magic used here is probably not strictly necessary. |
| 20165 | 20237 | */ |
| 20166 | 20238 | static LONG SQLITE_WIN32_VOLATILE winMutex_lock = 0; |
| 20167 | 20239 | |
| 20168 | | -SQLITE_API int sqlite3_win32_is_nt(void); /* os_win.c */ |
| 20169 | | -SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */ |
| 20240 | +SQLITE_API int SQLITE_STDCALL sqlite3_win32_is_nt(void); /* os_win.c */ |
| 20241 | +SQLITE_API void SQLITE_STDCALL sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */ |
| 20170 | 20242 | |
| 20171 | 20243 | static int winMutexInit(void){ |
| 20172 | 20244 | /* The first to increment to 1 does actual initialization */ |
| 20173 | 20245 | if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){ |
| 20174 | 20246 | int i; |
| | @@ -20460,11 +20532,11 @@ |
| 20460 | 20532 | /* |
| 20461 | 20533 | ** Attempt to release up to n bytes of non-essential memory currently |
| 20462 | 20534 | ** held by SQLite. An example of non-essential memory is memory used to |
| 20463 | 20535 | ** cache database pages that are not currently in use. |
| 20464 | 20536 | */ |
| 20465 | | -SQLITE_API int sqlite3_release_memory(int n){ |
| 20537 | +SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int n){ |
| 20466 | 20538 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 20467 | 20539 | return sqlite3PcacheReleaseMemory(n); |
| 20468 | 20540 | #else |
| 20469 | 20541 | /* IMPLEMENTATION-OF: R-34391-24921 The sqlite3_release_memory() routine |
| 20470 | 20542 | ** is a no-op returning zero if SQLite is not compiled with |
| | @@ -20560,11 +20632,11 @@ |
| 20560 | 20632 | #ifndef SQLITE_OMIT_DEPRECATED |
| 20561 | 20633 | /* |
| 20562 | 20634 | ** Deprecated external interface. Internal/core SQLite code |
| 20563 | 20635 | ** should call sqlite3MemoryAlarm. |
| 20564 | 20636 | */ |
| 20565 | | -SQLITE_API int sqlite3_memory_alarm( |
| 20637 | +SQLITE_API int SQLITE_STDCALL sqlite3_memory_alarm( |
| 20566 | 20638 | void(*xCallback)(void *pArg, sqlite3_int64 used,int N), |
| 20567 | 20639 | void *pArg, |
| 20568 | 20640 | sqlite3_int64 iThreshold |
| 20569 | 20641 | ){ |
| 20570 | 20642 | return sqlite3MemoryAlarm(xCallback, pArg, iThreshold); |
| | @@ -20573,11 +20645,11 @@ |
| 20573 | 20645 | |
| 20574 | 20646 | /* |
| 20575 | 20647 | ** Set the soft heap-size limit for the library. Passing a zero or |
| 20576 | 20648 | ** negative value indicates no limit. |
| 20577 | 20649 | */ |
| 20578 | | -SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){ |
| 20650 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 n){ |
| 20579 | 20651 | sqlite3_int64 priorLimit; |
| 20580 | 20652 | sqlite3_int64 excess; |
| 20581 | 20653 | #ifndef SQLITE_OMIT_AUTOINIT |
| 20582 | 20654 | int rc = sqlite3_initialize(); |
| 20583 | 20655 | if( rc ) return -1; |
| | @@ -20593,19 +20665,20 @@ |
| 20593 | 20665 | } |
| 20594 | 20666 | excess = sqlite3_memory_used() - n; |
| 20595 | 20667 | if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff)); |
| 20596 | 20668 | return priorLimit; |
| 20597 | 20669 | } |
| 20598 | | -SQLITE_API void sqlite3_soft_heap_limit(int n){ |
| 20670 | +SQLITE_API void SQLITE_STDCALL sqlite3_soft_heap_limit(int n){ |
| 20599 | 20671 | if( n<0 ) n = 0; |
| 20600 | 20672 | sqlite3_soft_heap_limit64(n); |
| 20601 | 20673 | } |
| 20602 | 20674 | |
| 20603 | 20675 | /* |
| 20604 | 20676 | ** Initialize the memory allocation subsystem. |
| 20605 | 20677 | */ |
| 20606 | 20678 | SQLITE_PRIVATE int sqlite3MallocInit(void){ |
| 20679 | + int rc; |
| 20607 | 20680 | if( sqlite3GlobalConfig.m.xMalloc==0 ){ |
| 20608 | 20681 | sqlite3MemSetDefault(); |
| 20609 | 20682 | } |
| 20610 | 20683 | memset(&mem0, 0, sizeof(mem0)); |
| 20611 | 20684 | if( sqlite3GlobalConfig.bCoreMutex ){ |
| | @@ -20637,11 +20710,13 @@ |
| 20637 | 20710 | || sqlite3GlobalConfig.nPage<1 ){ |
| 20638 | 20711 | sqlite3GlobalConfig.pPage = 0; |
| 20639 | 20712 | sqlite3GlobalConfig.szPage = 0; |
| 20640 | 20713 | sqlite3GlobalConfig.nPage = 0; |
| 20641 | 20714 | } |
| 20642 | | - return sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData); |
| 20715 | + rc = sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData); |
| 20716 | + if( rc!=SQLITE_OK ) memset(&mem0, 0, sizeof(mem0)); |
| 20717 | + return rc; |
| 20643 | 20718 | } |
| 20644 | 20719 | |
| 20645 | 20720 | /* |
| 20646 | 20721 | ** Return true if the heap is currently under memory pressure - in other |
| 20647 | 20722 | ** words if the amount of heap used is close to the limit set by |
| | @@ -20662,11 +20737,11 @@ |
| 20662 | 20737 | } |
| 20663 | 20738 | |
| 20664 | 20739 | /* |
| 20665 | 20740 | ** Return the amount of memory currently checked out. |
| 20666 | 20741 | */ |
| 20667 | | -SQLITE_API sqlite3_int64 sqlite3_memory_used(void){ |
| 20742 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_used(void){ |
| 20668 | 20743 | int n, mx; |
| 20669 | 20744 | sqlite3_int64 res; |
| 20670 | 20745 | sqlite3_status(SQLITE_STATUS_MEMORY_USED, &n, &mx, 0); |
| 20671 | 20746 | res = (sqlite3_int64)n; /* Work around bug in Borland C. Ticket #3216 */ |
| 20672 | 20747 | return res; |
| | @@ -20675,11 +20750,11 @@ |
| 20675 | 20750 | /* |
| 20676 | 20751 | ** Return the maximum amount of memory that has ever been |
| 20677 | 20752 | ** checked out since either the beginning of this process |
| 20678 | 20753 | ** or since the most recent reset. |
| 20679 | 20754 | */ |
| 20680 | | -SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag){ |
| 20755 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag){ |
| 20681 | 20756 | int n, mx; |
| 20682 | 20757 | sqlite3_int64 res; |
| 20683 | 20758 | sqlite3_status(SQLITE_STATUS_MEMORY_USED, &n, &mx, resetFlag); |
| 20684 | 20759 | res = (sqlite3_int64)mx; /* Work around bug in Borland C. Ticket #3216 */ |
| 20685 | 20760 | return res; |
| | @@ -20766,17 +20841,17 @@ |
| 20766 | 20841 | /* |
| 20767 | 20842 | ** This version of the memory allocation is for use by the application. |
| 20768 | 20843 | ** First make sure the memory subsystem is initialized, then do the |
| 20769 | 20844 | ** allocation. |
| 20770 | 20845 | */ |
| 20771 | | -SQLITE_API void *sqlite3_malloc(int n){ |
| 20846 | +SQLITE_API void *SQLITE_STDCALL sqlite3_malloc(int n){ |
| 20772 | 20847 | #ifndef SQLITE_OMIT_AUTOINIT |
| 20773 | 20848 | if( sqlite3_initialize() ) return 0; |
| 20774 | 20849 | #endif |
| 20775 | 20850 | return n<=0 ? 0 : sqlite3Malloc(n); |
| 20776 | 20851 | } |
| 20777 | | -SQLITE_API void *sqlite3_malloc64(sqlite3_uint64 n){ |
| 20852 | +SQLITE_API void *SQLITE_STDCALL sqlite3_malloc64(sqlite3_uint64 n){ |
| 20778 | 20853 | #ifndef SQLITE_OMIT_AUTOINIT |
| 20779 | 20854 | if( sqlite3_initialize() ) return 0; |
| 20780 | 20855 | #endif |
| 20781 | 20856 | return sqlite3Malloc(n); |
| 20782 | 20857 | } |
| | @@ -20913,20 +20988,20 @@ |
| 20913 | 20988 | assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| 20914 | 20989 | return sqlite3GlobalConfig.m.xSize(p); |
| 20915 | 20990 | } |
| 20916 | 20991 | } |
| 20917 | 20992 | } |
| 20918 | | -SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){ |
| 20993 | +SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void *p){ |
| 20919 | 20994 | assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); |
| 20920 | 20995 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 20921 | 20996 | return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p); |
| 20922 | 20997 | } |
| 20923 | 20998 | |
| 20924 | 20999 | /* |
| 20925 | 21000 | ** Free memory previously obtained from sqlite3Malloc(). |
| 20926 | 21001 | */ |
| 20927 | | -SQLITE_API void sqlite3_free(void *p){ |
| 21002 | +SQLITE_API void SQLITE_STDCALL sqlite3_free(void *p){ |
| 20928 | 21003 | if( p==0 ) return; /* IMP: R-49053-54554 */ |
| 20929 | 21004 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 20930 | 21005 | assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); |
| 20931 | 21006 | if( sqlite3GlobalConfig.bMemstat ){ |
| 20932 | 21007 | sqlite3_mutex_enter(mem0.mutex); |
| | @@ -21031,18 +21106,18 @@ |
| 21031 | 21106 | |
| 21032 | 21107 | /* |
| 21033 | 21108 | ** The public interface to sqlite3Realloc. Make sure that the memory |
| 21034 | 21109 | ** subsystem is initialized prior to invoking sqliteRealloc. |
| 21035 | 21110 | */ |
| 21036 | | -SQLITE_API void *sqlite3_realloc(void *pOld, int n){ |
| 21111 | +SQLITE_API void *SQLITE_STDCALL sqlite3_realloc(void *pOld, int n){ |
| 21037 | 21112 | #ifndef SQLITE_OMIT_AUTOINIT |
| 21038 | 21113 | if( sqlite3_initialize() ) return 0; |
| 21039 | 21114 | #endif |
| 21040 | 21115 | if( n<0 ) n = 0; /* IMP: R-26507-47431 */ |
| 21041 | 21116 | return sqlite3Realloc(pOld, n); |
| 21042 | 21117 | } |
| 21043 | | -SQLITE_API void *sqlite3_realloc64(void *pOld, sqlite3_uint64 n){ |
| 21118 | +SQLITE_API void *SQLITE_STDCALL sqlite3_realloc64(void *pOld, sqlite3_uint64 n){ |
| 21044 | 21119 | #ifndef SQLITE_OMIT_AUTOINIT |
| 21045 | 21120 | if( sqlite3_initialize() ) return 0; |
| 21046 | 21121 | #endif |
| 21047 | 21122 | return sqlite3Realloc(pOld, n); |
| 21048 | 21123 | } |
| | @@ -21403,10 +21478,11 @@ |
| 21403 | 21478 | |
| 21404 | 21479 | /* |
| 21405 | 21480 | ** Set the StrAccum object to an error mode. |
| 21406 | 21481 | */ |
| 21407 | 21482 | static void setStrAccumError(StrAccum *p, u8 eError){ |
| 21483 | + assert( eError==STRACCUM_NOMEM || eError==STRACCUM_TOOBIG ); |
| 21408 | 21484 | p->accError = eError; |
| 21409 | 21485 | p->nAlloc = 0; |
| 21410 | 21486 | } |
| 21411 | 21487 | |
| 21412 | 21488 | /* |
| | @@ -21517,45 +21593,52 @@ |
| 21517 | 21593 | case '0': flag_zeropad = 1; break; |
| 21518 | 21594 | default: done = 1; break; |
| 21519 | 21595 | } |
| 21520 | 21596 | }while( !done && (c=(*++fmt))!=0 ); |
| 21521 | 21597 | /* Get the field width */ |
| 21522 | | - width = 0; |
| 21523 | 21598 | if( c=='*' ){ |
| 21524 | 21599 | if( bArgList ){ |
| 21525 | 21600 | width = (int)getIntArg(pArgList); |
| 21526 | 21601 | }else{ |
| 21527 | 21602 | width = va_arg(ap,int); |
| 21528 | 21603 | } |
| 21529 | 21604 | if( width<0 ){ |
| 21530 | 21605 | flag_leftjustify = 1; |
| 21531 | | - width = -width; |
| 21606 | + width = width >= -2147483647 ? -width : 0; |
| 21532 | 21607 | } |
| 21533 | 21608 | c = *++fmt; |
| 21534 | 21609 | }else{ |
| 21610 | + unsigned wx = 0; |
| 21535 | 21611 | while( c>='0' && c<='9' ){ |
| 21536 | | - width = width*10 + c - '0'; |
| 21612 | + wx = wx*10 + c - '0'; |
| 21537 | 21613 | c = *++fmt; |
| 21538 | 21614 | } |
| 21615 | + testcase( wx>0x7fffffff ); |
| 21616 | + width = wx & 0x7fffffff; |
| 21539 | 21617 | } |
| 21618 | + |
| 21540 | 21619 | /* Get the precision */ |
| 21541 | 21620 | if( c=='.' ){ |
| 21542 | | - precision = 0; |
| 21543 | 21621 | c = *++fmt; |
| 21544 | 21622 | if( c=='*' ){ |
| 21545 | 21623 | if( bArgList ){ |
| 21546 | 21624 | precision = (int)getIntArg(pArgList); |
| 21547 | 21625 | }else{ |
| 21548 | 21626 | precision = va_arg(ap,int); |
| 21549 | 21627 | } |
| 21550 | | - if( precision<0 ) precision = -precision; |
| 21551 | 21628 | c = *++fmt; |
| 21629 | + if( precision<0 ){ |
| 21630 | + precision = precision >= -2147483647 ? -precision : -1; |
| 21631 | + } |
| 21552 | 21632 | }else{ |
| 21633 | + unsigned px = 0; |
| 21553 | 21634 | while( c>='0' && c<='9' ){ |
| 21554 | | - precision = precision*10 + c - '0'; |
| 21635 | + px = px*10 + c - '0'; |
| 21555 | 21636 | c = *++fmt; |
| 21556 | 21637 | } |
| 21638 | + testcase( px>0x7fffffff ); |
| 21639 | + precision = px & 0x7fffffff; |
| 21557 | 21640 | } |
| 21558 | 21641 | }else{ |
| 21559 | 21642 | precision = -1; |
| 21560 | 21643 | } |
| 21561 | 21644 | /* Get the conversion type modifier */ |
| | @@ -21715,11 +21798,12 @@ |
| 21715 | 21798 | if( flag_plussign ) prefix = '+'; |
| 21716 | 21799 | else if( flag_blanksign ) prefix = ' '; |
| 21717 | 21800 | else prefix = 0; |
| 21718 | 21801 | } |
| 21719 | 21802 | if( xtype==etGENERIC && precision>0 ) precision--; |
| 21720 | | - for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1){} |
| 21803 | + testcase( precision>0xfff ); |
| 21804 | + for(idx=precision&0xfff, rounder=0.5; idx>0; idx--, rounder*=0.1){} |
| 21721 | 21805 | if( xtype==etFLOAT ) realvalue += rounder; |
| 21722 | 21806 | /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */ |
| 21723 | 21807 | exp = 0; |
| 21724 | 21808 | if( sqlite3IsNaN((double)realvalue) ){ |
| 21725 | 21809 | bufpt = "NaN"; |
| | @@ -21770,12 +21854,13 @@ |
| 21770 | 21854 | if( xtype==etEXP ){ |
| 21771 | 21855 | e2 = 0; |
| 21772 | 21856 | }else{ |
| 21773 | 21857 | e2 = exp; |
| 21774 | 21858 | } |
| 21775 | | - if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){ |
| 21776 | | - bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 ); |
| 21859 | + if( MAX(e2,0)+(i64)precision+(i64)width > etBUFSIZE - 15 ){ |
| 21860 | + bufpt = zExtra |
| 21861 | + = sqlite3Malloc( MAX(e2,0)+(i64)precision+(i64)width+15 ); |
| 21777 | 21862 | if( bufpt==0 ){ |
| 21778 | 21863 | setStrAccumError(pAccum, STRACCUM_NOMEM); |
| 21779 | 21864 | return; |
| 21780 | 21865 | } |
| 21781 | 21866 | } |
| | @@ -22003,17 +22088,17 @@ |
| 22003 | 22088 | ** Return the number of bytes of text that StrAccum is able to accept |
| 22004 | 22089 | ** after the attempted enlargement. The value returned might be zero. |
| 22005 | 22090 | */ |
| 22006 | 22091 | static int sqlite3StrAccumEnlarge(StrAccum *p, int N){ |
| 22007 | 22092 | char *zNew; |
| 22008 | | - assert( p->nChar+N >= p->nAlloc ); /* Only called if really needed */ |
| 22093 | + assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */ |
| 22009 | 22094 | if( p->accError ){ |
| 22010 | 22095 | testcase(p->accError==STRACCUM_TOOBIG); |
| 22011 | 22096 | testcase(p->accError==STRACCUM_NOMEM); |
| 22012 | 22097 | return 0; |
| 22013 | 22098 | } |
| 22014 | | - if( !p->useMalloc ){ |
| 22099 | + if( p->mxAlloc==0 ){ |
| 22015 | 22100 | N = p->nAlloc - p->nChar - 1; |
| 22016 | 22101 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 22017 | 22102 | return N; |
| 22018 | 22103 | }else{ |
| 22019 | 22104 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| | @@ -22029,14 +22114,14 @@ |
| 22029 | 22114 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 22030 | 22115 | return 0; |
| 22031 | 22116 | }else{ |
| 22032 | 22117 | p->nAlloc = (int)szNew; |
| 22033 | 22118 | } |
| 22034 | | - if( p->useMalloc==1 ){ |
| 22119 | + if( p->db ){ |
| 22035 | 22120 | zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc); |
| 22036 | 22121 | }else{ |
| 22037 | | - zNew = sqlite3_realloc(zOld, p->nAlloc); |
| 22122 | + zNew = sqlite3_realloc64(zOld, p->nAlloc); |
| 22038 | 22123 | } |
| 22039 | 22124 | if( zNew ){ |
| 22040 | 22125 | assert( p->zText!=0 || p->nChar==0 ); |
| 22041 | 22126 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 22042 | 22127 | p->zText = zNew; |
| | @@ -22052,11 +22137,14 @@ |
| 22052 | 22137 | |
| 22053 | 22138 | /* |
| 22054 | 22139 | ** Append N copies of character c to the given string buffer. |
| 22055 | 22140 | */ |
| 22056 | 22141 | SQLITE_PRIVATE void sqlite3AppendChar(StrAccum *p, int N, char c){ |
| 22057 | | - if( p->nChar+N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ) return; |
| 22142 | + testcase( p->nChar + (i64)N > 0x7fffffff ); |
| 22143 | + if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){ |
| 22144 | + return; |
| 22145 | + } |
| 22058 | 22146 | while( (N--)>0 ) p->zText[p->nChar++] = c; |
| 22059 | 22147 | } |
| 22060 | 22148 | |
| 22061 | 22149 | /* |
| 22062 | 22150 | ** The StrAccum "p" is not large enough to accept N new bytes of z[]. |
| | @@ -22077,11 +22165,11 @@ |
| 22077 | 22165 | /* |
| 22078 | 22166 | ** Append N bytes of text from z to the StrAccum object. Increase the |
| 22079 | 22167 | ** size of the memory allocation for StrAccum if necessary. |
| 22080 | 22168 | */ |
| 22081 | 22169 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ |
| 22082 | | - assert( z!=0 ); |
| 22170 | + assert( z!=0 || N==0 ); |
| 22083 | 22171 | assert( p->zText!=0 || p->nChar==0 || p->accError ); |
| 22084 | 22172 | assert( N>=0 ); |
| 22085 | 22173 | assert( p->accError==0 || p->nAlloc==0 ); |
| 22086 | 22174 | if( p->nChar+N >= p->nAlloc ){ |
| 22087 | 22175 | enlargeAndAppend(p,z,N); |
| | @@ -22106,16 +22194,12 @@ |
| 22106 | 22194 | ** pointer if any kind of error was encountered. |
| 22107 | 22195 | */ |
| 22108 | 22196 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){ |
| 22109 | 22197 | if( p->zText ){ |
| 22110 | 22198 | p->zText[p->nChar] = 0; |
| 22111 | | - if( p->useMalloc && p->zText==p->zBase ){ |
| 22112 | | - if( p->useMalloc==1 ){ |
| 22113 | | - p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); |
| 22114 | | - }else{ |
| 22115 | | - p->zText = sqlite3_malloc(p->nChar+1); |
| 22116 | | - } |
| 22199 | + if( p->mxAlloc>0 && p->zText==p->zBase ){ |
| 22200 | + p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); |
| 22117 | 22201 | if( p->zText ){ |
| 22118 | 22202 | memcpy(p->zText, p->zBase, p->nChar+1); |
| 22119 | 22203 | }else{ |
| 22120 | 22204 | setStrAccumError(p, STRACCUM_NOMEM); |
| 22121 | 22205 | } |
| | @@ -22127,29 +22211,35 @@ |
| 22127 | 22211 | /* |
| 22128 | 22212 | ** Reset an StrAccum string. Reclaim all malloced memory. |
| 22129 | 22213 | */ |
| 22130 | 22214 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){ |
| 22131 | 22215 | if( p->zText!=p->zBase ){ |
| 22132 | | - if( p->useMalloc==1 ){ |
| 22133 | | - sqlite3DbFree(p->db, p->zText); |
| 22134 | | - }else{ |
| 22135 | | - sqlite3_free(p->zText); |
| 22136 | | - } |
| 22216 | + sqlite3DbFree(p->db, p->zText); |
| 22137 | 22217 | } |
| 22138 | 22218 | p->zText = 0; |
| 22139 | 22219 | } |
| 22140 | 22220 | |
| 22141 | 22221 | /* |
| 22142 | | -** Initialize a string accumulator |
| 22222 | +** Initialize a string accumulator. |
| 22223 | +** |
| 22224 | +** p: The accumulator to be initialized. |
| 22225 | +** db: Pointer to a database connection. May be NULL. Lookaside |
| 22226 | +** memory is used if not NULL. db->mallocFailed is set appropriately |
| 22227 | +** when not NULL. |
| 22228 | +** zBase: An initial buffer. May be NULL in which case the initial buffer |
| 22229 | +** is malloced. |
| 22230 | +** n: Size of zBase in bytes. If total space requirements never exceed |
| 22231 | +** n then no memory allocations ever occur. |
| 22232 | +** mx: Maximum number of bytes to accumulate. If mx==0 then no memory |
| 22233 | +** allocations will ever occur. |
| 22143 | 22234 | */ |
| 22144 | | -SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){ |
| 22235 | +SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){ |
| 22145 | 22236 | p->zText = p->zBase = zBase; |
| 22146 | | - p->db = 0; |
| 22237 | + p->db = db; |
| 22147 | 22238 | p->nChar = 0; |
| 22148 | 22239 | p->nAlloc = n; |
| 22149 | 22240 | p->mxAlloc = mx; |
| 22150 | | - p->useMalloc = 1; |
| 22151 | 22241 | p->accError = 0; |
| 22152 | 22242 | } |
| 22153 | 22243 | |
| 22154 | 22244 | /* |
| 22155 | 22245 | ** Print into memory obtained from sqliteMalloc(). Use the internal |
| | @@ -22158,13 +22248,12 @@ |
| 22158 | 22248 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){ |
| 22159 | 22249 | char *z; |
| 22160 | 22250 | char zBase[SQLITE_PRINT_BUF_SIZE]; |
| 22161 | 22251 | StrAccum acc; |
| 22162 | 22252 | assert( db!=0 ); |
| 22163 | | - sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), |
| 22253 | + sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase), |
| 22164 | 22254 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 22165 | | - acc.db = db; |
| 22166 | 22255 | sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap); |
| 22167 | 22256 | z = sqlite3StrAccumFinish(&acc); |
| 22168 | 22257 | if( acc.accError==STRACCUM_NOMEM ){ |
| 22169 | 22258 | db->mallocFailed = 1; |
| 22170 | 22259 | } |
| | @@ -22204,11 +22293,11 @@ |
| 22204 | 22293 | |
| 22205 | 22294 | /* |
| 22206 | 22295 | ** Print into memory obtained from sqlite3_malloc(). Omit the internal |
| 22207 | 22296 | ** %-conversion extensions. |
| 22208 | 22297 | */ |
| 22209 | | -SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){ |
| 22298 | +SQLITE_API char *SQLITE_STDCALL sqlite3_vmprintf(const char *zFormat, va_list ap){ |
| 22210 | 22299 | char *z; |
| 22211 | 22300 | char zBase[SQLITE_PRINT_BUF_SIZE]; |
| 22212 | 22301 | StrAccum acc; |
| 22213 | 22302 | |
| 22214 | 22303 | #ifdef SQLITE_ENABLE_API_ARMOR |
| | @@ -22218,22 +22307,21 @@ |
| 22218 | 22307 | } |
| 22219 | 22308 | #endif |
| 22220 | 22309 | #ifndef SQLITE_OMIT_AUTOINIT |
| 22221 | 22310 | if( sqlite3_initialize() ) return 0; |
| 22222 | 22311 | #endif |
| 22223 | | - sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); |
| 22224 | | - acc.useMalloc = 2; |
| 22312 | + sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); |
| 22225 | 22313 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22226 | 22314 | z = sqlite3StrAccumFinish(&acc); |
| 22227 | 22315 | return z; |
| 22228 | 22316 | } |
| 22229 | 22317 | |
| 22230 | 22318 | /* |
| 22231 | 22319 | ** Print into memory obtained from sqlite3_malloc()(). Omit the internal |
| 22232 | 22320 | ** %-conversion extensions. |
| 22233 | 22321 | */ |
| 22234 | | -SQLITE_API char *sqlite3_mprintf(const char *zFormat, ...){ |
| 22322 | +SQLITE_API char *SQLITE_CDECL sqlite3_mprintf(const char *zFormat, ...){ |
| 22235 | 22323 | va_list ap; |
| 22236 | 22324 | char *z; |
| 22237 | 22325 | #ifndef SQLITE_OMIT_AUTOINIT |
| 22238 | 22326 | if( sqlite3_initialize() ) return 0; |
| 22239 | 22327 | #endif |
| | @@ -22254,26 +22342,25 @@ |
| 22254 | 22342 | ** this without breaking compatibility, so we just have to live with the |
| 22255 | 22343 | ** mistake. |
| 22256 | 22344 | ** |
| 22257 | 22345 | ** sqlite3_vsnprintf() is the varargs version. |
| 22258 | 22346 | */ |
| 22259 | | -SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){ |
| 22347 | +SQLITE_API char *SQLITE_STDCALL sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){ |
| 22260 | 22348 | StrAccum acc; |
| 22261 | 22349 | if( n<=0 ) return zBuf; |
| 22262 | 22350 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 22263 | 22351 | if( zBuf==0 || zFormat==0 ) { |
| 22264 | 22352 | (void)SQLITE_MISUSE_BKPT; |
| 22265 | 22353 | if( zBuf ) zBuf[0] = 0; |
| 22266 | 22354 | return zBuf; |
| 22267 | 22355 | } |
| 22268 | 22356 | #endif |
| 22269 | | - sqlite3StrAccumInit(&acc, zBuf, n, 0); |
| 22270 | | - acc.useMalloc = 0; |
| 22357 | + sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); |
| 22271 | 22358 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22272 | 22359 | return sqlite3StrAccumFinish(&acc); |
| 22273 | 22360 | } |
| 22274 | | -SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ |
| 22361 | +SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ |
| 22275 | 22362 | char *z; |
| 22276 | 22363 | va_list ap; |
| 22277 | 22364 | va_start(ap,zFormat); |
| 22278 | 22365 | z = sqlite3_vsnprintf(n, zBuf, zFormat, ap); |
| 22279 | 22366 | va_end(ap); |
| | @@ -22291,41 +22378,39 @@ |
| 22291 | 22378 | */ |
| 22292 | 22379 | static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){ |
| 22293 | 22380 | StrAccum acc; /* String accumulator */ |
| 22294 | 22381 | char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */ |
| 22295 | 22382 | |
| 22296 | | - sqlite3StrAccumInit(&acc, zMsg, sizeof(zMsg), 0); |
| 22297 | | - acc.useMalloc = 0; |
| 22383 | + sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0); |
| 22298 | 22384 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22299 | 22385 | sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode, |
| 22300 | 22386 | sqlite3StrAccumFinish(&acc)); |
| 22301 | 22387 | } |
| 22302 | 22388 | |
| 22303 | 22389 | /* |
| 22304 | 22390 | ** Format and write a message to the log if logging is enabled. |
| 22305 | 22391 | */ |
| 22306 | | -SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...){ |
| 22392 | +SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...){ |
| 22307 | 22393 | va_list ap; /* Vararg list */ |
| 22308 | 22394 | if( sqlite3GlobalConfig.xLog ){ |
| 22309 | 22395 | va_start(ap, zFormat); |
| 22310 | 22396 | renderLogMsg(iErrCode, zFormat, ap); |
| 22311 | 22397 | va_end(ap); |
| 22312 | 22398 | } |
| 22313 | 22399 | } |
| 22314 | 22400 | |
| 22315 | | -#if defined(SQLITE_DEBUG) |
| 22401 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 22316 | 22402 | /* |
| 22317 | 22403 | ** A version of printf() that understands %lld. Used for debugging. |
| 22318 | 22404 | ** The printf() built into some versions of windows does not understand %lld |
| 22319 | 22405 | ** and segfaults if you give it a long long int. |
| 22320 | 22406 | */ |
| 22321 | 22407 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){ |
| 22322 | 22408 | va_list ap; |
| 22323 | 22409 | StrAccum acc; |
| 22324 | 22410 | char zBuf[500]; |
| 22325 | | - sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0); |
| 22326 | | - acc.useMalloc = 0; |
| 22411 | + sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
| 22327 | 22412 | va_start(ap,zFormat); |
| 22328 | 22413 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 22329 | 22414 | va_end(ap); |
| 22330 | 22415 | sqlite3StrAccumFinish(&acc); |
| 22331 | 22416 | fprintf(stdout,"%s", zBuf); |
| | @@ -22348,11 +22433,11 @@ |
| 22348 | 22433 | */ |
| 22349 | 22434 | /* Add a new subitem to the tree. The moreToFollow flag indicates that this |
| 22350 | 22435 | ** is not the last item in the tree. */ |
| 22351 | 22436 | SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){ |
| 22352 | 22437 | if( p==0 ){ |
| 22353 | | - p = sqlite3_malloc( sizeof(*p) ); |
| 22438 | + p = sqlite3_malloc64( sizeof(*p) ); |
| 22354 | 22439 | if( p==0 ) return 0; |
| 22355 | 22440 | memset(p, 0, sizeof(*p)); |
| 22356 | 22441 | }else{ |
| 22357 | 22442 | p->iLevel++; |
| 22358 | 22443 | } |
| | @@ -22371,12 +22456,11 @@ |
| 22371 | 22456 | SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){ |
| 22372 | 22457 | va_list ap; |
| 22373 | 22458 | int i; |
| 22374 | 22459 | StrAccum acc; |
| 22375 | 22460 | char zBuf[500]; |
| 22376 | | - sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0); |
| 22377 | | - acc.useMalloc = 0; |
| 22461 | + sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
| 22378 | 22462 | if( p ){ |
| 22379 | 22463 | for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){ |
| 22380 | 22464 | sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4); |
| 22381 | 22465 | } |
| 22382 | 22466 | sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4); |
| | @@ -22437,11 +22521,11 @@ |
| 22437 | 22521 | } sqlite3Prng; |
| 22438 | 22522 | |
| 22439 | 22523 | /* |
| 22440 | 22524 | ** Return N random bytes. |
| 22441 | 22525 | */ |
| 22442 | | -SQLITE_API void sqlite3_randomness(int N, void *pBuf){ |
| 22526 | +SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *pBuf){ |
| 22443 | 22527 | unsigned char t; |
| 22444 | 22528 | unsigned char *zBuf = pBuf; |
| 22445 | 22529 | |
| 22446 | 22530 | /* The "wsdPrng" macro will resolve to the pseudo-random number generator |
| 22447 | 22531 | ** state vector. If writable static data is unsupported on the target, |
| | @@ -23589,11 +23673,11 @@ |
| 23589 | 23673 | ** sqlite3_strnicmp() APIs allow applications and extensions to compare |
| 23590 | 23674 | ** the contents of two buffers containing UTF-8 strings in a |
| 23591 | 23675 | ** case-independent fashion, using the same definition of "case |
| 23592 | 23676 | ** independence" that SQLite uses internally when comparing identifiers. |
| 23593 | 23677 | */ |
| 23594 | | -SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){ |
| 23678 | +SQLITE_API int SQLITE_STDCALL sqlite3_stricmp(const char *zLeft, const char *zRight){ |
| 23595 | 23679 | register unsigned char *a, *b; |
| 23596 | 23680 | if( zLeft==0 ){ |
| 23597 | 23681 | return zRight ? -1 : 0; |
| 23598 | 23682 | }else if( zRight==0 ){ |
| 23599 | 23683 | return 1; |
| | @@ -23601,11 +23685,11 @@ |
| 23601 | 23685 | a = (unsigned char *)zLeft; |
| 23602 | 23686 | b = (unsigned char *)zRight; |
| 23603 | 23687 | while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
| 23604 | 23688 | return UpperToLower[*a] - UpperToLower[*b]; |
| 23605 | 23689 | } |
| 23606 | | -SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ |
| 23690 | +SQLITE_API int SQLITE_STDCALL sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ |
| 23607 | 23691 | register unsigned char *a, *b; |
| 23608 | 23692 | if( zLeft==0 ){ |
| 23609 | 23693 | return zRight ? -1 : 0; |
| 23610 | 23694 | }else if( zRight==0 ){ |
| 23611 | 23695 | return 1; |
| | @@ -23995,10 +24079,11 @@ |
| 23995 | 24079 | }else{ |
| 23996 | 24080 | return 0; |
| 23997 | 24081 | } |
| 23998 | 24082 | } |
| 23999 | 24083 | #endif |
| 24084 | + while( zNum[0]=='0' ) zNum++; |
| 24000 | 24085 | for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){ |
| 24001 | 24086 | v = v*10 + c; |
| 24002 | 24087 | } |
| 24003 | 24088 | |
| 24004 | 24089 | /* The longest decimal representation of a 32 bit integer is 10 digits: |
| | @@ -25249,10 +25334,21 @@ |
| 25249 | 25334 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 25250 | 25335 | # include <sys/ioctl.h> |
| 25251 | 25336 | # include <sys/file.h> |
| 25252 | 25337 | # include <sys/param.h> |
| 25253 | 25338 | #endif /* SQLITE_ENABLE_LOCKING_STYLE */ |
| 25339 | + |
| 25340 | +#if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ |
| 25341 | + (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000)) |
| 25342 | +# if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \ |
| 25343 | + && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0)) |
| 25344 | +# define HAVE_GETHOSTUUID 1 |
| 25345 | +# else |
| 25346 | +# warning "gethostuuid() is disabled." |
| 25347 | +# endif |
| 25348 | +#endif |
| 25349 | + |
| 25254 | 25350 | |
| 25255 | 25351 | #if OS_VXWORKS |
| 25256 | 25352 | /* # include <sys/ioctl.h> */ |
| 25257 | 25353 | # include <semaphore.h> |
| 25258 | 25354 | # include <limits.h> |
| | @@ -25445,20 +25541,10 @@ |
| 25445 | 25541 | */ |
| 25446 | 25542 | #ifdef MEMORY_DEBUG |
| 25447 | 25543 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 25448 | 25544 | #endif |
| 25449 | 25545 | |
| 25450 | | -#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 25451 | | -# ifndef SQLITE_DEBUG_OS_TRACE |
| 25452 | | -# define SQLITE_DEBUG_OS_TRACE 0 |
| 25453 | | -# endif |
| 25454 | | - int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; |
| 25455 | | -# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X |
| 25456 | | -#else |
| 25457 | | -# define OSTRACE(X) |
| 25458 | | -#endif |
| 25459 | | - |
| 25460 | 25546 | /* |
| 25461 | 25547 | ** Macros for performance tracing. Normally turned off. Only works |
| 25462 | 25548 | ** on i486 hardware. |
| 25463 | 25549 | */ |
| 25464 | 25550 | #ifdef SQLITE_PERFORMANCE_TRACE |
| | @@ -25997,11 +26083,11 @@ |
| 25997 | 26083 | return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 25998 | 26084 | } |
| 25999 | 26085 | #endif |
| 26000 | 26086 | |
| 26001 | 26087 | |
| 26002 | | -#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 26088 | +#ifdef SQLITE_HAVE_OS_TRACE |
| 26003 | 26089 | /* |
| 26004 | 26090 | ** Helper function for printing out trace information from debugging |
| 26005 | 26091 | ** binaries. This returns the string representation of the supplied |
| 26006 | 26092 | ** integer lock-type. |
| 26007 | 26093 | */ |
| | @@ -26260,11 +26346,11 @@ |
| 26260 | 26346 | struct vxworksFileId *pCandidate; /* For looping over existing file IDs */ |
| 26261 | 26347 | int n; /* Length of zAbsoluteName string */ |
| 26262 | 26348 | |
| 26263 | 26349 | assert( zAbsoluteName[0]=='/' ); |
| 26264 | 26350 | n = (int)strlen(zAbsoluteName); |
| 26265 | | - pNew = sqlite3_malloc( sizeof(*pNew) + (n+1) ); |
| 26351 | + pNew = sqlite3_malloc64( sizeof(*pNew) + (n+1) ); |
| 26266 | 26352 | if( pNew==0 ) return 0; |
| 26267 | 26353 | pNew->zCanonicalName = (char*)&pNew[1]; |
| 26268 | 26354 | memcpy(pNew->zCanonicalName, zAbsoluteName, n+1); |
| 26269 | 26355 | n = vxworksSimplifyName(pNew->zCanonicalName, n); |
| 26270 | 26356 | |
| | @@ -26664,11 +26750,11 @@ |
| 26664 | 26750 | pInode = inodeList; |
| 26665 | 26751 | while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){ |
| 26666 | 26752 | pInode = pInode->pNext; |
| 26667 | 26753 | } |
| 26668 | 26754 | if( pInode==0 ){ |
| 26669 | | - pInode = sqlite3_malloc( sizeof(*pInode) ); |
| 26755 | + pInode = sqlite3_malloc64( sizeof(*pInode) ); |
| 26670 | 26756 | if( pInode==0 ){ |
| 26671 | 26757 | return SQLITE_NOMEM; |
| 26672 | 26758 | } |
| 26673 | 26759 | memset(pInode, 0, sizeof(*pInode)); |
| 26674 | 26760 | memcpy(&pInode->fileId, &fileId, sizeof(fileId)); |
| | @@ -29150,11 +29236,11 @@ |
| 29150 | 29236 | */ |
| 29151 | 29237 | static int unixFileControl(sqlite3_file *id, int op, void *pArg){ |
| 29152 | 29238 | unixFile *pFile = (unixFile*)id; |
| 29153 | 29239 | switch( op ){ |
| 29154 | 29240 | case SQLITE_FCNTL_WAL_BLOCK: { |
| 29155 | | - pFile->ctrlFlags |= UNIXFILE_BLOCK; |
| 29241 | + /* pFile->ctrlFlags |= UNIXFILE_BLOCK; // Deferred feature */ |
| 29156 | 29242 | return SQLITE_OK; |
| 29157 | 29243 | } |
| 29158 | 29244 | case SQLITE_FCNTL_LOCKSTATE: { |
| 29159 | 29245 | *(int*)pArg = pFile->eFileLock; |
| 29160 | 29246 | return SQLITE_OK; |
| | @@ -29185,11 +29271,11 @@ |
| 29185 | 29271 | case SQLITE_FCNTL_VFSNAME: { |
| 29186 | 29272 | *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); |
| 29187 | 29273 | return SQLITE_OK; |
| 29188 | 29274 | } |
| 29189 | 29275 | case SQLITE_FCNTL_TEMPFILENAME: { |
| 29190 | | - char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname ); |
| 29276 | + char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname ); |
| 29191 | 29277 | if( zTFile ){ |
| 29192 | 29278 | unixGetTempname(pFile->pVfs->mxPathname, zTFile); |
| 29193 | 29279 | *(char**)pArg = zTFile; |
| 29194 | 29280 | } |
| 29195 | 29281 | return SQLITE_OK; |
| | @@ -29626,11 +29712,11 @@ |
| 29626 | 29712 | unixInodeInfo *pInode; /* The inode of fd */ |
| 29627 | 29713 | char *zShmFilename; /* Name of the file used for SHM */ |
| 29628 | 29714 | int nShmFilename; /* Size of the SHM filename in bytes */ |
| 29629 | 29715 | |
| 29630 | 29716 | /* Allocate space for the new unixShm object. */ |
| 29631 | | - p = sqlite3_malloc( sizeof(*p) ); |
| 29717 | + p = sqlite3_malloc64( sizeof(*p) ); |
| 29632 | 29718 | if( p==0 ) return SQLITE_NOMEM; |
| 29633 | 29719 | memset(p, 0, sizeof(*p)); |
| 29634 | 29720 | assert( pDbFd->pShm==0 ); |
| 29635 | 29721 | |
| 29636 | 29722 | /* Check to see if a unixShmNode object already exists. Reuse an existing |
| | @@ -29657,11 +29743,11 @@ |
| 29657 | 29743 | #ifdef SQLITE_SHM_DIRECTORY |
| 29658 | 29744 | nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31; |
| 29659 | 29745 | #else |
| 29660 | 29746 | nShmFilename = 6 + (int)strlen(zBasePath); |
| 29661 | 29747 | #endif |
| 29662 | | - pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename ); |
| 29748 | + pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename ); |
| 29663 | 29749 | if( pShmNode==0 ){ |
| 29664 | 29750 | rc = SQLITE_NOMEM; |
| 29665 | 29751 | goto shm_open_err; |
| 29666 | 29752 | } |
| 29667 | 29753 | memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename); |
| | @@ -29867,11 +29953,11 @@ |
| 29867 | 29953 | if( pMem==MAP_FAILED ){ |
| 29868 | 29954 | rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename); |
| 29869 | 29955 | goto shmpage_out; |
| 29870 | 29956 | } |
| 29871 | 29957 | }else{ |
| 29872 | | - pMem = sqlite3_malloc(szRegion); |
| 29958 | + pMem = sqlite3_malloc64(szRegion); |
| 29873 | 29959 | if( pMem==0 ){ |
| 29874 | 29960 | rc = SQLITE_NOMEM; |
| 29875 | 29961 | goto shmpage_out; |
| 29876 | 29962 | } |
| 29877 | 29963 | memset(pMem, 0, szRegion); |
| | @@ -30704,11 +30790,11 @@ |
| 30704 | 30790 | else if( pLockingStyle == &afpIoMethods ){ |
| 30705 | 30791 | /* AFP locking uses the file path so it needs to be included in |
| 30706 | 30792 | ** the afpLockingContext. |
| 30707 | 30793 | */ |
| 30708 | 30794 | afpLockingContext *pCtx; |
| 30709 | | - pNew->lockingContext = pCtx = sqlite3_malloc( sizeof(*pCtx) ); |
| 30795 | + pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) ); |
| 30710 | 30796 | if( pCtx==0 ){ |
| 30711 | 30797 | rc = SQLITE_NOMEM; |
| 30712 | 30798 | }else{ |
| 30713 | 30799 | /* NB: zFilename exists and remains valid until the file is closed |
| 30714 | 30800 | ** according to requirement F11141. So we do not need to make a |
| | @@ -30734,11 +30820,11 @@ |
| 30734 | 30820 | */ |
| 30735 | 30821 | char *zLockFile; |
| 30736 | 30822 | int nFilename; |
| 30737 | 30823 | assert( zFilename!=0 ); |
| 30738 | 30824 | nFilename = (int)strlen(zFilename) + 6; |
| 30739 | | - zLockFile = (char *)sqlite3_malloc(nFilename); |
| 30825 | + zLockFile = (char *)sqlite3_malloc64(nFilename); |
| 30740 | 30826 | if( zLockFile==0 ){ |
| 30741 | 30827 | rc = SQLITE_NOMEM; |
| 30742 | 30828 | }else{ |
| 30743 | 30829 | sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename); |
| 30744 | 30830 | } |
| | @@ -31111,11 +31197,11 @@ |
| 31111 | 31197 | UnixUnusedFd *pUnused; |
| 31112 | 31198 | pUnused = findReusableFd(zName, flags); |
| 31113 | 31199 | if( pUnused ){ |
| 31114 | 31200 | fd = pUnused->fd; |
| 31115 | 31201 | }else{ |
| 31116 | | - pUnused = sqlite3_malloc(sizeof(*pUnused)); |
| 31202 | + pUnused = sqlite3_malloc64(sizeof(*pUnused)); |
| 31117 | 31203 | if( !pUnused ){ |
| 31118 | 31204 | return SQLITE_NOMEM; |
| 31119 | 31205 | } |
| 31120 | 31206 | } |
| 31121 | 31207 | p->pUnused = pUnused; |
| | @@ -31491,11 +31577,11 @@ |
| 31491 | 31577 | ** that we always use the same random number sequence. This makes the |
| 31492 | 31578 | ** tests repeatable. |
| 31493 | 31579 | */ |
| 31494 | 31580 | memset(zBuf, 0, nBuf); |
| 31495 | 31581 | randomnessPid = osGetpid(0); |
| 31496 | | -#if !defined(SQLITE_TEST) |
| 31582 | +#if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS) |
| 31497 | 31583 | { |
| 31498 | 31584 | int fd, got; |
| 31499 | 31585 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 31500 | 31586 | if( fd<0 ){ |
| 31501 | 31587 | time_t t; |
| | @@ -31903,11 +31989,11 @@ |
| 31903 | 31989 | */ |
| 31904 | 31990 | pUnused = findReusableFd(path, openFlags); |
| 31905 | 31991 | if( pUnused ){ |
| 31906 | 31992 | fd = pUnused->fd; |
| 31907 | 31993 | }else{ |
| 31908 | | - pUnused = sqlite3_malloc(sizeof(*pUnused)); |
| 31994 | + pUnused = sqlite3_malloc64(sizeof(*pUnused)); |
| 31909 | 31995 | if( !pUnused ){ |
| 31910 | 31996 | return SQLITE_NOMEM; |
| 31911 | 31997 | } |
| 31912 | 31998 | } |
| 31913 | 31999 | if( fd<0 ){ |
| | @@ -31936,11 +32022,11 @@ |
| 31936 | 32022 | default: |
| 31937 | 32023 | return SQLITE_CANTOPEN_BKPT; |
| 31938 | 32024 | } |
| 31939 | 32025 | } |
| 31940 | 32026 | |
| 31941 | | - pNew = (unixFile *)sqlite3_malloc(sizeof(*pNew)); |
| 32027 | + pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew)); |
| 31942 | 32028 | if( pNew==NULL ){ |
| 31943 | 32029 | rc = SQLITE_NOMEM; |
| 31944 | 32030 | goto end_create_proxy; |
| 31945 | 32031 | } |
| 31946 | 32032 | memset(pNew, 0, sizeof(unixFile)); |
| | @@ -31969,21 +32055,22 @@ |
| 31969 | 32055 | SQLITE_API int sqlite3_hostid_num = 0; |
| 31970 | 32056 | #endif |
| 31971 | 32057 | |
| 31972 | 32058 | #define PROXY_HOSTIDLEN 16 /* conch file host id length */ |
| 31973 | 32059 | |
| 32060 | +#ifdef HAVE_GETHOSTUUID |
| 31974 | 32061 | /* Not always defined in the headers as it ought to be */ |
| 31975 | 32062 | extern int gethostuuid(uuid_t id, const struct timespec *wait); |
| 32063 | +#endif |
| 31976 | 32064 | |
| 31977 | 32065 | /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN |
| 31978 | 32066 | ** bytes of writable memory. |
| 31979 | 32067 | */ |
| 31980 | 32068 | static int proxyGetHostID(unsigned char *pHostID, int *pError){ |
| 31981 | 32069 | assert(PROXY_HOSTIDLEN == sizeof(uuid_t)); |
| 31982 | 32070 | memset(pHostID, 0, PROXY_HOSTIDLEN); |
| 31983 | | -# if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ |
| 31984 | | - (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000)) |
| 32071 | +#ifdef HAVE_GETHOSTUUID |
| 31985 | 32072 | { |
| 31986 | 32073 | struct timespec timeout = {1, 0}; /* 1 sec timeout */ |
| 31987 | 32074 | if( gethostuuid(pHostID, &timeout) ){ |
| 31988 | 32075 | int err = errno; |
| 31989 | 32076 | if( pError ){ |
| | @@ -32397,11 +32484,11 @@ |
| 32397 | 32484 | return rc; |
| 32398 | 32485 | } |
| 32399 | 32486 | |
| 32400 | 32487 | /* |
| 32401 | 32488 | ** Given the name of a database file, compute the name of its conch file. |
| 32402 | | -** Store the conch filename in memory obtained from sqlite3_malloc(). |
| 32489 | +** Store the conch filename in memory obtained from sqlite3_malloc64(). |
| 32403 | 32490 | ** Make *pConchPath point to the new name. Return SQLITE_OK on success |
| 32404 | 32491 | ** or SQLITE_NOMEM if unable to obtain memory. |
| 32405 | 32492 | ** |
| 32406 | 32493 | ** The caller is responsible for ensuring that the allocated memory |
| 32407 | 32494 | ** space is eventually freed. |
| | @@ -32413,11 +32500,11 @@ |
| 32413 | 32500 | int len = (int)strlen(dbPath); /* Length of database filename - dbPath */ |
| 32414 | 32501 | char *conchPath; /* buffer in which to construct conch name */ |
| 32415 | 32502 | |
| 32416 | 32503 | /* Allocate space for the conch filename and initialize the name to |
| 32417 | 32504 | ** the name of the original database file. */ |
| 32418 | | - *pConchPath = conchPath = (char *)sqlite3_malloc(len + 8); |
| 32505 | + *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8); |
| 32419 | 32506 | if( conchPath==0 ){ |
| 32420 | 32507 | return SQLITE_NOMEM; |
| 32421 | 32508 | } |
| 32422 | 32509 | memcpy(conchPath, dbPath, len+1); |
| 32423 | 32510 | |
| | @@ -32529,11 +32616,11 @@ |
| 32529 | 32616 | } |
| 32530 | 32617 | |
| 32531 | 32618 | OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h, |
| 32532 | 32619 | (lockPath ? lockPath : ":auto:"), osGetpid(0))); |
| 32533 | 32620 | |
| 32534 | | - pCtx = sqlite3_malloc( sizeof(*pCtx) ); |
| 32621 | + pCtx = sqlite3_malloc64( sizeof(*pCtx) ); |
| 32535 | 32622 | if( pCtx==0 ){ |
| 32536 | 32623 | return SQLITE_NOMEM; |
| 32537 | 32624 | } |
| 32538 | 32625 | memset(pCtx, 0, sizeof(*pCtx)); |
| 32539 | 32626 | |
| | @@ -32814,11 +32901,11 @@ |
| 32814 | 32901 | ** This routine is called once during SQLite initialization and by a |
| 32815 | 32902 | ** single thread. The memory allocation and mutex subsystems have not |
| 32816 | 32903 | ** necessarily been initialized when this routine is called, and so they |
| 32817 | 32904 | ** should not be used. |
| 32818 | 32905 | */ |
| 32819 | | -SQLITE_API int sqlite3_os_init(void){ |
| 32906 | +SQLITE_API int SQLITE_STDCALL sqlite3_os_init(void){ |
| 32820 | 32907 | /* |
| 32821 | 32908 | ** The following macro defines an initializer for an sqlite3_vfs object. |
| 32822 | 32909 | ** The name of the VFS is NAME. The pAppData is a pointer to a pointer |
| 32823 | 32910 | ** to the "finder" function. (pAppData is a pointer to a pointer because |
| 32824 | 32911 | ** silly C90 rules prohibit a void* from being cast to a function pointer |
| | @@ -32913,11 +33000,11 @@ |
| 32913 | 33000 | ** |
| 32914 | 33001 | ** Some operating systems might need to do some cleanup in this routine, |
| 32915 | 33002 | ** to release dynamically allocated objects. But not on unix. |
| 32916 | 33003 | ** This routine is a no-op for unix. |
| 32917 | 33004 | */ |
| 32918 | | -SQLITE_API int sqlite3_os_end(void){ |
| 33005 | +SQLITE_API int SQLITE_STDCALL sqlite3_os_end(void){ |
| 32919 | 33006 | return SQLITE_OK; |
| 32920 | 33007 | } |
| 32921 | 33008 | |
| 32922 | 33009 | #endif /* SQLITE_OS_UNIX */ |
| 32923 | 33010 | |
| | @@ -32973,20 +33060,10 @@ |
| 32973 | 33060 | */ |
| 32974 | 33061 | #ifdef MEMORY_DEBUG |
| 32975 | 33062 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 32976 | 33063 | #endif |
| 32977 | 33064 | |
| 32978 | | -#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 32979 | | -# ifndef SQLITE_DEBUG_OS_TRACE |
| 32980 | | -# define SQLITE_DEBUG_OS_TRACE 0 |
| 32981 | | -# endif |
| 32982 | | - int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; |
| 32983 | | -# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X |
| 32984 | | -#else |
| 32985 | | -# define OSTRACE(X) |
| 32986 | | -#endif |
| 32987 | | - |
| 32988 | 33065 | /* |
| 32989 | 33066 | ** Macros for performance tracing. Normally turned off. Only works |
| 32990 | 33067 | ** on i486 hardware. |
| 32991 | 33068 | */ |
| 32992 | 33069 | #ifdef SQLITE_PERFORMANCE_TRACE |
| | @@ -33326,12 +33403,14 @@ |
| 33326 | 33403 | |
| 33327 | 33404 | WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, SIZE_T); |
| 33328 | 33405 | #endif /* SQLITE_OS_WINRT */ |
| 33329 | 33406 | |
| 33330 | 33407 | /* |
| 33331 | | -** This file mapping API is common to both Win32 and WinRT. |
| 33408 | +** These file mapping APIs are common to both Win32 and WinRT. |
| 33332 | 33409 | */ |
| 33410 | + |
| 33411 | +WINBASEAPI BOOL WINAPI FlushViewOfFile(LPCVOID, SIZE_T); |
| 33333 | 33412 | WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID); |
| 33334 | 33413 | #endif /* SQLITE_WIN32_FILEMAPPING_API */ |
| 33335 | 33414 | |
| 33336 | 33415 | /* |
| 33337 | 33416 | ** Some Microsoft compilers lack this definition. |
| | @@ -34212,10 +34291,19 @@ |
| 34212 | 34291 | #endif |
| 34213 | 34292 | |
| 34214 | 34293 | #define osUuidCreateSequential \ |
| 34215 | 34294 | ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent) |
| 34216 | 34295 | |
| 34296 | +#if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0 |
| 34297 | + { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 }, |
| 34298 | +#else |
| 34299 | + { "FlushViewOfFile", (SYSCALL)0, 0 }, |
| 34300 | +#endif |
| 34301 | + |
| 34302 | +#define osFlushViewOfFile \ |
| 34303 | + ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent) |
| 34304 | + |
| 34217 | 34305 | }; /* End of the overrideable system calls */ |
| 34218 | 34306 | |
| 34219 | 34307 | /* |
| 34220 | 34308 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| 34221 | 34309 | ** "win32" VFSes. Return SQLITE_OK opon successfully updating the |
| | @@ -34305,11 +34393,11 @@ |
| 34305 | 34393 | ** compact it. Upon success, SQLITE_OK will be returned. Upon failure, one |
| 34306 | 34394 | ** of SQLITE_NOMEM, SQLITE_ERROR, or SQLITE_NOTFOUND will be returned. The |
| 34307 | 34395 | ** "pnLargest" argument, if non-zero, will be used to return the size of the |
| 34308 | 34396 | ** largest committed free block in the heap, in bytes. |
| 34309 | 34397 | */ |
| 34310 | | -SQLITE_API int sqlite3_win32_compact_heap(LPUINT pnLargest){ |
| 34398 | +SQLITE_API int SQLITE_STDCALL sqlite3_win32_compact_heap(LPUINT pnLargest){ |
| 34311 | 34399 | int rc = SQLITE_OK; |
| 34312 | 34400 | UINT nLargest = 0; |
| 34313 | 34401 | HANDLE hHeap; |
| 34314 | 34402 | |
| 34315 | 34403 | winMemAssertMagic(); |
| | @@ -34345,11 +34433,11 @@ |
| 34345 | 34433 | ** If a Win32 native heap has been configured, this function will attempt to |
| 34346 | 34434 | ** destroy and recreate it. If the Win32 native heap is not isolated and/or |
| 34347 | 34435 | ** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will |
| 34348 | 34436 | ** be returned and no changes will be made to the Win32 native heap. |
| 34349 | 34437 | */ |
| 34350 | | -SQLITE_API int sqlite3_win32_reset_heap(){ |
| 34438 | +SQLITE_API int SQLITE_STDCALL sqlite3_win32_reset_heap(){ |
| 34351 | 34439 | int rc; |
| 34352 | 34440 | MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ |
| 34353 | 34441 | MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */ |
| 34354 | 34442 | MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 34355 | 34443 | MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); ) |
| | @@ -34390,11 +34478,11 @@ |
| 34390 | 34478 | /* |
| 34391 | 34479 | ** This function outputs the specified (ANSI) string to the Win32 debugger |
| 34392 | 34480 | ** (if available). |
| 34393 | 34481 | */ |
| 34394 | 34482 | |
| 34395 | | -SQLITE_API void sqlite3_win32_write_debug(const char *zBuf, int nBuf){ |
| 34483 | +SQLITE_API void SQLITE_STDCALL sqlite3_win32_write_debug(const char *zBuf, int nBuf){ |
| 34396 | 34484 | char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE]; |
| 34397 | 34485 | int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */ |
| 34398 | 34486 | if( nMin<-1 ) nMin = -1; /* all negative values become -1. */ |
| 34399 | 34487 | assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE ); |
| 34400 | 34488 | #if defined(SQLITE_WIN32_HAS_ANSI) |
| | @@ -34430,11 +34518,11 @@ |
| 34430 | 34518 | */ |
| 34431 | 34519 | #if SQLITE_OS_WINRT |
| 34432 | 34520 | static HANDLE sleepObj = NULL; |
| 34433 | 34521 | #endif |
| 34434 | 34522 | |
| 34435 | | -SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds){ |
| 34523 | +SQLITE_API void SQLITE_STDCALL sqlite3_win32_sleep(DWORD milliseconds){ |
| 34436 | 34524 | #if SQLITE_OS_WINRT |
| 34437 | 34525 | if ( sleepObj==NULL ){ |
| 34438 | 34526 | sleepObj = osCreateEventExW(NULL, NULL, CREATE_EVENT_MANUAL_RESET, |
| 34439 | 34527 | SYNCHRONIZE); |
| 34440 | 34528 | } |
| | @@ -34479,11 +34567,11 @@ |
| 34479 | 34567 | |
| 34480 | 34568 | /* |
| 34481 | 34569 | ** This function determines if the machine is running a version of Windows |
| 34482 | 34570 | ** based on the NT kernel. |
| 34483 | 34571 | */ |
| 34484 | | -SQLITE_API int sqlite3_win32_is_nt(void){ |
| 34572 | +SQLITE_API int SQLITE_STDCALL sqlite3_win32_is_nt(void){ |
| 34485 | 34573 | #if SQLITE_OS_WINRT |
| 34486 | 34574 | /* |
| 34487 | 34575 | ** NOTE: The WinRT sub-platform is always assumed to be based on the NT |
| 34488 | 34576 | ** kernel. |
| 34489 | 34577 | */ |
| | @@ -34833,11 +34921,11 @@ |
| 34833 | 34921 | |
| 34834 | 34922 | /* |
| 34835 | 34923 | ** Convert multibyte character string to UTF-8. Space to hold the |
| 34836 | 34924 | ** returned string is obtained from sqlite3_malloc(). |
| 34837 | 34925 | */ |
| 34838 | | -SQLITE_API char *sqlite3_win32_mbcs_to_utf8(const char *zFilename){ |
| 34926 | +SQLITE_API char *SQLITE_STDCALL sqlite3_win32_mbcs_to_utf8(const char *zFilename){ |
| 34839 | 34927 | char *zFilenameUtf8; |
| 34840 | 34928 | LPWSTR zTmpWide; |
| 34841 | 34929 | |
| 34842 | 34930 | zTmpWide = winMbcsToUnicode(zFilename); |
| 34843 | 34931 | if( zTmpWide==0 ){ |
| | @@ -34850,11 +34938,11 @@ |
| 34850 | 34938 | |
| 34851 | 34939 | /* |
| 34852 | 34940 | ** Convert UTF-8 to multibyte character string. Space to hold the |
| 34853 | 34941 | ** returned string is obtained from sqlite3_malloc(). |
| 34854 | 34942 | */ |
| 34855 | | -SQLITE_API char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){ |
| 34943 | +SQLITE_API char *SQLITE_STDCALL sqlite3_win32_utf8_to_mbcs(const char *zFilename){ |
| 34856 | 34944 | char *zFilenameMbcs; |
| 34857 | 34945 | LPWSTR zTmpWide; |
| 34858 | 34946 | |
| 34859 | 34947 | zTmpWide = winUtf8ToUnicode(zFilename); |
| 34860 | 34948 | if( zTmpWide==0 ){ |
| | @@ -34870,11 +34958,11 @@ |
| 34870 | 34958 | ** the provided arguments. The type argument must be 1 in order to set the |
| 34871 | 34959 | ** data directory or 2 in order to set the temporary directory. The zValue |
| 34872 | 34960 | ** argument is the name of the directory to use. The return value will be |
| 34873 | 34961 | ** SQLITE_OK if successful. |
| 34874 | 34962 | */ |
| 34875 | | -SQLITE_API int sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){ |
| 34963 | +SQLITE_API int SQLITE_STDCALL sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){ |
| 34876 | 34964 | char **ppDirectory = 0; |
| 34877 | 34965 | #ifndef SQLITE_OMIT_AUTOINIT |
| 34878 | 34966 | int rc = sqlite3_initialize(); |
| 34879 | 34967 | if( rc ) return rc; |
| 34880 | 34968 | #endif |
| | @@ -35095,15 +35183,15 @@ |
| 35095 | 35183 | } |
| 35096 | 35184 | |
| 35097 | 35185 | /* |
| 35098 | 35186 | ** Log a I/O error retry episode. |
| 35099 | 35187 | */ |
| 35100 | | -static void winLogIoerr(int nRetry){ |
| 35188 | +static void winLogIoerr(int nRetry, int lineno){ |
| 35101 | 35189 | if( nRetry ){ |
| 35102 | | - sqlite3_log(SQLITE_IOERR, |
| 35103 | | - "delayed %dms for lock/sharing conflict", |
| 35104 | | - winIoerrRetryDelay*nRetry*(nRetry+1)/2 |
| 35190 | + sqlite3_log(SQLITE_NOTICE, |
| 35191 | + "delayed %dms for lock/sharing conflict at line %d", |
| 35192 | + winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno |
| 35105 | 35193 | ); |
| 35106 | 35194 | } |
| 35107 | 35195 | } |
| 35108 | 35196 | |
| 35109 | 35197 | #if SQLITE_OS_WINCE |
| | @@ -35579,11 +35667,12 @@ |
| 35579 | 35667 | assert( id!=0 ); |
| 35580 | 35668 | #ifndef SQLITE_OMIT_WAL |
| 35581 | 35669 | assert( pFile->pShm==0 ); |
| 35582 | 35670 | #endif |
| 35583 | 35671 | assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE ); |
| 35584 | | - OSTRACE(("CLOSE file=%p\n", pFile->h)); |
| 35672 | + OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p\n", |
| 35673 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35585 | 35674 | |
| 35586 | 35675 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 35587 | 35676 | winUnmapfile(pFile); |
| 35588 | 35677 | #endif |
| 35589 | 35678 | |
| | @@ -35608,11 +35697,12 @@ |
| 35608 | 35697 | #endif |
| 35609 | 35698 | if( rc ){ |
| 35610 | 35699 | pFile->h = NULL; |
| 35611 | 35700 | } |
| 35612 | 35701 | OpenCounter(-1); |
| 35613 | | - OSTRACE(("CLOSE file=%p, rc=%s\n", pFile->h, rc ? "ok" : "failed")); |
| 35702 | + OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n", |
| 35703 | + osGetCurrentProcessId(), pFile, pFile->h, rc ? "ok" : "failed")); |
| 35614 | 35704 | return rc ? SQLITE_OK |
| 35615 | 35705 | : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(), |
| 35616 | 35706 | "winClose", pFile->zPath); |
| 35617 | 35707 | } |
| 35618 | 35708 | |
| | @@ -35636,20 +35726,22 @@ |
| 35636 | 35726 | |
| 35637 | 35727 | assert( id!=0 ); |
| 35638 | 35728 | assert( amt>0 ); |
| 35639 | 35729 | assert( offset>=0 ); |
| 35640 | 35730 | SimulateIOError(return SQLITE_IOERR_READ); |
| 35641 | | - OSTRACE(("READ file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n", |
| 35731 | + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " |
| 35732 | + "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, |
| 35642 | 35733 | pFile->h, pBuf, amt, offset, pFile->locktype)); |
| 35643 | 35734 | |
| 35644 | 35735 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 35645 | 35736 | /* Deal with as much of this read request as possible by transfering |
| 35646 | 35737 | ** data from the memory mapping using memcpy(). */ |
| 35647 | 35738 | if( offset<pFile->mmapSize ){ |
| 35648 | 35739 | if( offset+amt <= pFile->mmapSize ){ |
| 35649 | 35740 | memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); |
| 35650 | | - OSTRACE(("READ-MMAP file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 35741 | + OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| 35742 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35651 | 35743 | return SQLITE_OK; |
| 35652 | 35744 | }else{ |
| 35653 | 35745 | int nCopy = (int)(pFile->mmapSize - offset); |
| 35654 | 35746 | memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy); |
| 35655 | 35747 | pBuf = &((u8 *)pBuf)[nCopy]; |
| | @@ -35659,11 +35751,12 @@ |
| 35659 | 35751 | } |
| 35660 | 35752 | #endif |
| 35661 | 35753 | |
| 35662 | 35754 | #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 35663 | 35755 | if( winSeekFile(pFile, offset) ){ |
| 35664 | | - OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h)); |
| 35756 | + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n", |
| 35757 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35665 | 35758 | return SQLITE_FULL; |
| 35666 | 35759 | } |
| 35667 | 35760 | while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ |
| 35668 | 35761 | #else |
| 35669 | 35762 | memset(&overlapped, 0, sizeof(OVERLAPPED)); |
| | @@ -35673,23 +35766,26 @@ |
| 35673 | 35766 | osGetLastError()!=ERROR_HANDLE_EOF ){ |
| 35674 | 35767 | #endif |
| 35675 | 35768 | DWORD lastErrno; |
| 35676 | 35769 | if( winRetryIoerr(&nRetry, &lastErrno) ) continue; |
| 35677 | 35770 | pFile->lastErrno = lastErrno; |
| 35678 | | - OSTRACE(("READ file=%p, rc=SQLITE_IOERR_READ\n", pFile->h)); |
| 35771 | + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_READ\n", |
| 35772 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35679 | 35773 | return winLogError(SQLITE_IOERR_READ, pFile->lastErrno, |
| 35680 | 35774 | "winRead", pFile->zPath); |
| 35681 | 35775 | } |
| 35682 | | - winLogIoerr(nRetry); |
| 35776 | + winLogIoerr(nRetry, __LINE__); |
| 35683 | 35777 | if( nRead<(DWORD)amt ){ |
| 35684 | 35778 | /* Unread parts of the buffer must be zero-filled */ |
| 35685 | 35779 | memset(&((char*)pBuf)[nRead], 0, amt-nRead); |
| 35686 | | - OSTRACE(("READ file=%p, rc=SQLITE_IOERR_SHORT_READ\n", pFile->h)); |
| 35780 | + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_SHORT_READ\n", |
| 35781 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35687 | 35782 | return SQLITE_IOERR_SHORT_READ; |
| 35688 | 35783 | } |
| 35689 | 35784 | |
| 35690 | | - OSTRACE(("READ file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 35785 | + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| 35786 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35691 | 35787 | return SQLITE_OK; |
| 35692 | 35788 | } |
| 35693 | 35789 | |
| 35694 | 35790 | /* |
| 35695 | 35791 | ** Write data from a buffer into a file. Return SQLITE_OK on success |
| | @@ -35708,20 +35804,22 @@ |
| 35708 | 35804 | assert( amt>0 ); |
| 35709 | 35805 | assert( pFile ); |
| 35710 | 35806 | SimulateIOError(return SQLITE_IOERR_WRITE); |
| 35711 | 35807 | SimulateDiskfullError(return SQLITE_FULL); |
| 35712 | 35808 | |
| 35713 | | - OSTRACE(("WRITE file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n", |
| 35809 | + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " |
| 35810 | + "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, |
| 35714 | 35811 | pFile->h, pBuf, amt, offset, pFile->locktype)); |
| 35715 | 35812 | |
| 35716 | 35813 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 35717 | 35814 | /* Deal with as much of this write request as possible by transfering |
| 35718 | 35815 | ** data from the memory mapping using memcpy(). */ |
| 35719 | 35816 | if( offset<pFile->mmapSize ){ |
| 35720 | 35817 | if( offset+amt <= pFile->mmapSize ){ |
| 35721 | 35818 | memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); |
| 35722 | | - OSTRACE(("WRITE-MMAP file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 35819 | + OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| 35820 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35723 | 35821 | return SQLITE_OK; |
| 35724 | 35822 | }else{ |
| 35725 | 35823 | int nCopy = (int)(pFile->mmapSize - offset); |
| 35726 | 35824 | memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy); |
| 35727 | 35825 | pBuf = &((u8 *)pBuf)[nCopy]; |
| | @@ -35780,21 +35878,24 @@ |
| 35780 | 35878 | } |
| 35781 | 35879 | |
| 35782 | 35880 | if( rc ){ |
| 35783 | 35881 | if( ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ) |
| 35784 | 35882 | || ( pFile->lastErrno==ERROR_DISK_FULL )){ |
| 35785 | | - OSTRACE(("WRITE file=%p, rc=SQLITE_FULL\n", pFile->h)); |
| 35883 | + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n", |
| 35884 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35786 | 35885 | return winLogError(SQLITE_FULL, pFile->lastErrno, |
| 35787 | 35886 | "winWrite1", pFile->zPath); |
| 35788 | 35887 | } |
| 35789 | | - OSTRACE(("WRITE file=%p, rc=SQLITE_IOERR_WRITE\n", pFile->h)); |
| 35888 | + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_WRITE\n", |
| 35889 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35790 | 35890 | return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno, |
| 35791 | 35891 | "winWrite2", pFile->zPath); |
| 35792 | 35892 | }else{ |
| 35793 | | - winLogIoerr(nRetry); |
| 35893 | + winLogIoerr(nRetry, __LINE__); |
| 35794 | 35894 | } |
| 35795 | | - OSTRACE(("WRITE file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 35895 | + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| 35896 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35796 | 35897 | return SQLITE_OK; |
| 35797 | 35898 | } |
| 35798 | 35899 | |
| 35799 | 35900 | /* |
| 35800 | 35901 | ** Truncate an open file to a specified size |
| | @@ -35804,12 +35905,12 @@ |
| 35804 | 35905 | int rc = SQLITE_OK; /* Return code for this function */ |
| 35805 | 35906 | DWORD lastErrno; |
| 35806 | 35907 | |
| 35807 | 35908 | assert( pFile ); |
| 35808 | 35909 | SimulateIOError(return SQLITE_IOERR_TRUNCATE); |
| 35809 | | - OSTRACE(("TRUNCATE file=%p, size=%lld, lock=%d\n", |
| 35810 | | - pFile->h, nByte, pFile->locktype)); |
| 35910 | + OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, size=%lld, lock=%d\n", |
| 35911 | + osGetCurrentProcessId(), pFile, pFile->h, nByte, pFile->locktype)); |
| 35811 | 35912 | |
| 35812 | 35913 | /* If the user has configured a chunk-size for this file, truncate the |
| 35813 | 35914 | ** file so that it consists of an integer number of chunks (i.e. the |
| 35814 | 35915 | ** actual file size after the operation may be larger than the requested |
| 35815 | 35916 | ** size). |
| | @@ -35837,11 +35938,12 @@ |
| 35837 | 35938 | if( pFile->pMapRegion && nByte<pFile->mmapSize ){ |
| 35838 | 35939 | pFile->mmapSize = nByte; |
| 35839 | 35940 | } |
| 35840 | 35941 | #endif |
| 35841 | 35942 | |
| 35842 | | - OSTRACE(("TRUNCATE file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc))); |
| 35943 | + OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, rc=%s\n", |
| 35944 | + osGetCurrentProcessId(), pFile, pFile->h, sqlite3ErrName(rc))); |
| 35843 | 35945 | return rc; |
| 35844 | 35946 | } |
| 35845 | 35947 | |
| 35846 | 35948 | #ifdef SQLITE_TEST |
| 35847 | 35949 | /* |
| | @@ -35861,11 +35963,11 @@ |
| 35861 | 35963 | ** Used only when SQLITE_NO_SYNC is not defined. |
| 35862 | 35964 | */ |
| 35863 | 35965 | BOOL rc; |
| 35864 | 35966 | #endif |
| 35865 | 35967 | #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \ |
| 35866 | | - (defined(SQLITE_TEST) && defined(SQLITE_DEBUG)) |
| 35968 | + defined(SQLITE_HAVE_OS_TRACE) |
| 35867 | 35969 | /* |
| 35868 | 35970 | ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or |
| 35869 | 35971 | ** OSTRACE() macros. |
| 35870 | 35972 | */ |
| 35871 | 35973 | winFile *pFile = (winFile*)id; |
| | @@ -35882,12 +35984,13 @@ |
| 35882 | 35984 | /* Unix cannot, but some systems may return SQLITE_FULL from here. This |
| 35883 | 35985 | ** line is to test that doing so does not cause any problems. |
| 35884 | 35986 | */ |
| 35885 | 35987 | SimulateDiskfullError( return SQLITE_FULL ); |
| 35886 | 35988 | |
| 35887 | | - OSTRACE(("SYNC file=%p, flags=%x, lock=%d\n", |
| 35888 | | - pFile->h, flags, pFile->locktype)); |
| 35989 | + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, flags=%x, lock=%d\n", |
| 35990 | + osGetCurrentProcessId(), pFile, pFile->h, flags, |
| 35991 | + pFile->locktype)); |
| 35889 | 35992 | |
| 35890 | 35993 | #ifndef SQLITE_TEST |
| 35891 | 35994 | UNUSED_PARAMETER(flags); |
| 35892 | 35995 | #else |
| 35893 | 35996 | if( (flags&0x0F)==SQLITE_SYNC_FULL ){ |
| | @@ -35898,23 +36001,42 @@ |
| 35898 | 36001 | |
| 35899 | 36002 | /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a |
| 35900 | 36003 | ** no-op |
| 35901 | 36004 | */ |
| 35902 | 36005 | #ifdef SQLITE_NO_SYNC |
| 35903 | | - OSTRACE(("SYNC-NOP file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 36006 | + OSTRACE(("SYNC-NOP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| 36007 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35904 | 36008 | return SQLITE_OK; |
| 35905 | 36009 | #else |
| 36010 | +#if SQLITE_MAX_MMAP_SIZE>0 |
| 36011 | + if( pFile->pMapRegion ){ |
| 36012 | + if( osFlushViewOfFile(pFile->pMapRegion, 0) ){ |
| 36013 | + OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, " |
| 36014 | + "rc=SQLITE_OK\n", osGetCurrentProcessId(), |
| 36015 | + pFile, pFile->pMapRegion)); |
| 36016 | + }else{ |
| 36017 | + pFile->lastErrno = osGetLastError(); |
| 36018 | + OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, " |
| 36019 | + "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(), |
| 36020 | + pFile, pFile->pMapRegion)); |
| 36021 | + return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno, |
| 36022 | + "winSync1", pFile->zPath); |
| 36023 | + } |
| 36024 | + } |
| 36025 | +#endif |
| 35906 | 36026 | rc = osFlushFileBuffers(pFile->h); |
| 35907 | 36027 | SimulateIOError( rc=FALSE ); |
| 35908 | 36028 | if( rc ){ |
| 35909 | | - OSTRACE(("SYNC file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 36029 | + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| 36030 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35910 | 36031 | return SQLITE_OK; |
| 35911 | 36032 | }else{ |
| 35912 | 36033 | pFile->lastErrno = osGetLastError(); |
| 35913 | | - OSTRACE(("SYNC file=%p, rc=SQLITE_IOERR_FSYNC\n", pFile->h)); |
| 36034 | + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_FSYNC\n", |
| 36035 | + osGetCurrentProcessId(), pFile, pFile->h)); |
| 35914 | 36036 | return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno, |
| 35915 | | - "winSync", pFile->zPath); |
| 36037 | + "winSync2", pFile->zPath); |
| 35916 | 36038 | } |
| 35917 | 36039 | #endif |
| 35918 | 36040 | } |
| 35919 | 36041 | |
| 35920 | 36042 | /* |
| | @@ -36518,11 +36640,11 @@ |
| 36518 | 36640 | DWORD lastErrno; /* The Windows errno from the last I/O error */ |
| 36519 | 36641 | |
| 36520 | 36642 | int nRef; /* Number of winShm objects pointing to this */ |
| 36521 | 36643 | winShm *pFirst; /* All winShm objects pointing to this */ |
| 36522 | 36644 | winShmNode *pNext; /* Next in list of all winShmNode objects */ |
| 36523 | | -#ifdef SQLITE_DEBUG |
| 36645 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 36524 | 36646 | u8 nextShmId; /* Next available winShm.id value */ |
| 36525 | 36647 | #endif |
| 36526 | 36648 | }; |
| 36527 | 36649 | |
| 36528 | 36650 | /* |
| | @@ -36549,11 +36671,11 @@ |
| 36549 | 36671 | winShmNode *pShmNode; /* The underlying winShmNode object */ |
| 36550 | 36672 | winShm *pNext; /* Next winShm with the same winShmNode */ |
| 36551 | 36673 | u8 hasMutex; /* True if holding the winShmNode mutex */ |
| 36552 | 36674 | u16 sharedMask; /* Mask of shared locks held */ |
| 36553 | 36675 | u16 exclMask; /* Mask of exclusive locks held */ |
| 36554 | | -#ifdef SQLITE_DEBUG |
| 36676 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 36555 | 36677 | u8 id; /* Id of this connection with its winShmNode */ |
| 36556 | 36678 | #endif |
| 36557 | 36679 | }; |
| 36558 | 36680 | |
| 36559 | 36681 | /* |
| | @@ -36740,11 +36862,11 @@ |
| 36740 | 36862 | if( rc ) goto shm_open_err; |
| 36741 | 36863 | } |
| 36742 | 36864 | |
| 36743 | 36865 | /* Make the new connection a child of the winShmNode */ |
| 36744 | 36866 | p->pShmNode = pShmNode; |
| 36745 | | -#ifdef SQLITE_DEBUG |
| 36867 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 36746 | 36868 | p->id = pShmNode->nextShmId++; |
| 36747 | 36869 | #endif |
| 36748 | 36870 | pShmNode->nRef++; |
| 36749 | 36871 | pDbFd->pShm = p; |
| 36750 | 36872 | winShmLeaveMutex(); |
| | @@ -37009,11 +37131,11 @@ |
| 37009 | 37131 | goto shmpage_out; |
| 37010 | 37132 | } |
| 37011 | 37133 | } |
| 37012 | 37134 | |
| 37013 | 37135 | /* Map the requested memory region into this processes address space. */ |
| 37014 | | - apNew = (struct ShmRegion *)sqlite3_realloc( |
| 37136 | + apNew = (struct ShmRegion *)sqlite3_realloc64( |
| 37015 | 37137 | pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0]) |
| 37016 | 37138 | ); |
| 37017 | 37139 | if( !apNew ){ |
| 37018 | 37140 | rc = SQLITE_IOERR_NOMEM; |
| 37019 | 37141 | goto shmpage_out; |
| | @@ -37881,11 +38003,11 @@ |
| 37881 | 38003 | winRetryIoerr(&cnt, &lastErrno) ){ |
| 37882 | 38004 | /* Noop */ |
| 37883 | 38005 | } |
| 37884 | 38006 | } |
| 37885 | 38007 | #endif |
| 37886 | | - winLogIoerr(cnt); |
| 38008 | + winLogIoerr(cnt, __LINE__); |
| 37887 | 38009 | |
| 37888 | 38010 | OSTRACE(("OPEN file=%p, name=%s, access=%lx, rc=%s\n", h, zUtf8Name, |
| 37889 | 38011 | dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok")); |
| 37890 | 38012 | |
| 37891 | 38013 | if( h==INVALID_HANDLE_VALUE ){ |
| | @@ -38065,11 +38187,11 @@ |
| 38065 | 38187 | } |
| 38066 | 38188 | #endif |
| 38067 | 38189 | if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){ |
| 38068 | 38190 | rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, "winDelete", zFilename); |
| 38069 | 38191 | }else{ |
| 38070 | | - winLogIoerr(cnt); |
| 38192 | + winLogIoerr(cnt, __LINE__); |
| 38071 | 38193 | } |
| 38072 | 38194 | sqlite3_free(zConverted); |
| 38073 | 38195 | OSTRACE(("DELETE name=%s, rc=%s\n", zFilename, sqlite3ErrName(rc))); |
| 38074 | 38196 | return rc; |
| 38075 | 38197 | } |
| | @@ -38115,11 +38237,11 @@ |
| 38115 | 38237 | attr = INVALID_FILE_ATTRIBUTES; |
| 38116 | 38238 | }else{ |
| 38117 | 38239 | attr = sAttrData.dwFileAttributes; |
| 38118 | 38240 | } |
| 38119 | 38241 | }else{ |
| 38120 | | - winLogIoerr(cnt); |
| 38242 | + winLogIoerr(cnt, __LINE__); |
| 38121 | 38243 | if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){ |
| 38122 | 38244 | sqlite3_free(zConverted); |
| 38123 | 38245 | return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", |
| 38124 | 38246 | zFilename); |
| 38125 | 38247 | }else{ |
| | @@ -38456,11 +38578,11 @@ |
| 38456 | 38578 | ** Write up to nBuf bytes of randomness into zBuf. |
| 38457 | 38579 | */ |
| 38458 | 38580 | static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ |
| 38459 | 38581 | int n = 0; |
| 38460 | 38582 | UNUSED_PARAMETER(pVfs); |
| 38461 | | -#if defined(SQLITE_TEST) |
| 38583 | +#if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) |
| 38462 | 38584 | n = nBuf; |
| 38463 | 38585 | memset(zBuf, 0, nBuf); |
| 38464 | 38586 | #else |
| 38465 | 38587 | if( sizeof(SYSTEMTIME)<=nBuf-n ){ |
| 38466 | 38588 | SYSTEMTIME x; |
| | @@ -38490,11 +38612,10 @@ |
| 38490 | 38612 | LARGE_INTEGER i; |
| 38491 | 38613 | osQueryPerformanceCounter(&i); |
| 38492 | 38614 | memcpy(&zBuf[n], &i, sizeof(i)); |
| 38493 | 38615 | n += sizeof(i); |
| 38494 | 38616 | } |
| 38495 | | -#endif |
| 38496 | 38617 | #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID |
| 38497 | 38618 | if( sizeof(UUID)<=nBuf-n ){ |
| 38498 | 38619 | UUID id; |
| 38499 | 38620 | memset(&id, 0, sizeof(UUID)); |
| 38500 | 38621 | osUuidCreate(&id); |
| | @@ -38507,10 +38628,11 @@ |
| 38507 | 38628 | osUuidCreateSequential(&id); |
| 38508 | 38629 | memcpy(zBuf, &id, sizeof(UUID)); |
| 38509 | 38630 | n += sizeof(UUID); |
| 38510 | 38631 | } |
| 38511 | 38632 | #endif |
| 38633 | +#endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */ |
| 38512 | 38634 | return n; |
| 38513 | 38635 | } |
| 38514 | 38636 | |
| 38515 | 38637 | |
| 38516 | 38638 | /* |
| | @@ -38630,11 +38752,11 @@ |
| 38630 | 38752 | } |
| 38631 | 38753 | |
| 38632 | 38754 | /* |
| 38633 | 38755 | ** Initialize and deinitialize the operating system interface. |
| 38634 | 38756 | */ |
| 38635 | | -SQLITE_API int sqlite3_os_init(void){ |
| 38757 | +SQLITE_API int SQLITE_STDCALL sqlite3_os_init(void){ |
| 38636 | 38758 | static sqlite3_vfs winVfs = { |
| 38637 | 38759 | 3, /* iVersion */ |
| 38638 | 38760 | sizeof(winFile), /* szOsFile */ |
| 38639 | 38761 | SQLITE_WIN32_MAX_PATH_BYTES, /* mxPathname */ |
| 38640 | 38762 | 0, /* pNext */ |
| | @@ -38684,11 +38806,11 @@ |
| 38684 | 38806 | }; |
| 38685 | 38807 | #endif |
| 38686 | 38808 | |
| 38687 | 38809 | /* Double-check that the aSyscall[] array has been constructed |
| 38688 | 38810 | ** correctly. See ticket [bb3a86e890c8e96ab] */ |
| 38689 | | - assert( ArraySize(aSyscall)==79 ); |
| 38811 | + assert( ArraySize(aSyscall)==80 ); |
| 38690 | 38812 | |
| 38691 | 38813 | /* get memory map allocation granularity */ |
| 38692 | 38814 | memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); |
| 38693 | 38815 | #if SQLITE_OS_WINRT |
| 38694 | 38816 | osGetNativeSystemInfo(&winSysInfo); |
| | @@ -38705,11 +38827,11 @@ |
| 38705 | 38827 | #endif |
| 38706 | 38828 | |
| 38707 | 38829 | return SQLITE_OK; |
| 38708 | 38830 | } |
| 38709 | 38831 | |
| 38710 | | -SQLITE_API int sqlite3_os_end(void){ |
| 38832 | +SQLITE_API int SQLITE_STDCALL sqlite3_os_end(void){ |
| 38711 | 38833 | #if SQLITE_OS_WINRT |
| 38712 | 38834 | if( sleepObj!=NULL ){ |
| 38713 | 38835 | osCloseHandle(sleepObj); |
| 38714 | 38836 | sleepObj = NULL; |
| 38715 | 38837 | } |
| | @@ -39061,11 +39183,11 @@ |
| 39061 | 39183 | |
| 39062 | 39184 | /* Allocate the Bitvec to be tested and a linear array of |
| 39063 | 39185 | ** bits to act as the reference */ |
| 39064 | 39186 | pBitvec = sqlite3BitvecCreate( sz ); |
| 39065 | 39187 | pV = sqlite3MallocZero( (sz+7)/8 + 1 ); |
| 39066 | | - pTmpSpace = sqlite3_malloc(BITVEC_SZ); |
| 39188 | + pTmpSpace = sqlite3_malloc64(BITVEC_SZ); |
| 39067 | 39189 | if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end; |
| 39068 | 39190 | |
| 39069 | 39191 | /* NULL pBitvec tests */ |
| 39070 | 39192 | sqlite3BitvecSet(0, 1); |
| 39071 | 39193 | sqlite3BitvecClear(0, 1, pTmpSpace); |
| | @@ -44550,13 +44672,11 @@ |
| 44550 | 44672 | Pgno nTruncate, /* Database size after this commit */ |
| 44551 | 44673 | int isCommit /* True if this is a commit */ |
| 44552 | 44674 | ){ |
| 44553 | 44675 | int rc; /* Return code */ |
| 44554 | 44676 | int nList; /* Number of pages in pList */ |
| 44555 | | -#if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES) |
| 44556 | 44677 | PgHdr *p; /* For looping over pages */ |
| 44557 | | -#endif |
| 44558 | 44678 | |
| 44559 | 44679 | assert( pPager->pWal ); |
| 44560 | 44680 | assert( pList ); |
| 44561 | 44681 | #ifdef SQLITE_DEBUG |
| 44562 | 44682 | /* Verify that the page list is in accending order */ |
| | @@ -44569,11 +44689,10 @@ |
| 44569 | 44689 | if( isCommit ){ |
| 44570 | 44690 | /* If a WAL transaction is being committed, there is no point in writing |
| 44571 | 44691 | ** any pages with page numbers greater than nTruncate into the WAL file. |
| 44572 | 44692 | ** They will never be read by any client. So remove them from the pDirty |
| 44573 | 44693 | ** list here. */ |
| 44574 | | - PgHdr *p; |
| 44575 | 44694 | PgHdr **ppNext = &pList; |
| 44576 | 44695 | nList = 0; |
| 44577 | 44696 | for(p=pList; (*ppNext = p)!=0; p=p->pDirty){ |
| 44578 | 44697 | if( p->pgno<=nTruncate ){ |
| 44579 | 44698 | ppNext = &p->pDirty; |
| | @@ -44589,11 +44708,10 @@ |
| 44589 | 44708 | if( pList->pgno==1 ) pager_write_changecounter(pList); |
| 44590 | 44709 | rc = sqlite3WalFrames(pPager->pWal, |
| 44591 | 44710 | pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags |
| 44592 | 44711 | ); |
| 44593 | 44712 | if( rc==SQLITE_OK && pPager->pBackup ){ |
| 44594 | | - PgHdr *p; |
| 44595 | 44713 | for(p=pList; p; p=p->pDirty){ |
| 44596 | 44714 | sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData); |
| 44597 | 44715 | } |
| 44598 | 44716 | } |
| 44599 | 44717 | |
| | @@ -48520,10 +48638,12 @@ |
| 48520 | 48638 | }else if( state==PAGER_OPEN ){ |
| 48521 | 48639 | pager_unlock(pPager); |
| 48522 | 48640 | } |
| 48523 | 48641 | assert( state==pPager->eState ); |
| 48524 | 48642 | } |
| 48643 | + }else if( eMode==PAGER_JOURNALMODE_OFF ){ |
| 48644 | + sqlite3OsClose(pPager->jfd); |
| 48525 | 48645 | } |
| 48526 | 48646 | } |
| 48527 | 48647 | |
| 48528 | 48648 | /* Return the new journal mode */ |
| 48529 | 48649 | return (int)pPager->journalMode; |
| | @@ -49302,11 +49422,11 @@ |
| 49302 | 49422 | |
| 49303 | 49423 | /* Enlarge the pWal->apWiData[] array if required */ |
| 49304 | 49424 | if( pWal->nWiData<=iPage ){ |
| 49305 | 49425 | int nByte = sizeof(u32*)*(iPage+1); |
| 49306 | 49426 | volatile u32 **apNew; |
| 49307 | | - apNew = (volatile u32 **)sqlite3_realloc((void *)pWal->apWiData, nByte); |
| 49427 | + apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte); |
| 49308 | 49428 | if( !apNew ){ |
| 49309 | 49429 | *ppPage = 0; |
| 49310 | 49430 | return SQLITE_NOMEM; |
| 49311 | 49431 | } |
| 49312 | 49432 | memset((void*)&apNew[pWal->nWiData], 0, |
| | @@ -49927,11 +50047,11 @@ |
| 49927 | 50047 | goto finished; |
| 49928 | 50048 | } |
| 49929 | 50049 | |
| 49930 | 50050 | /* Malloc a buffer to read frames into. */ |
| 49931 | 50051 | szFrame = szPage + WAL_FRAME_HDRSIZE; |
| 49932 | | - aFrame = (u8 *)sqlite3_malloc(szFrame); |
| 50052 | + aFrame = (u8 *)sqlite3_malloc64(szFrame); |
| 49933 | 50053 | if( !aFrame ){ |
| 49934 | 50054 | rc = SQLITE_NOMEM; |
| 49935 | 50055 | goto recovery_error; |
| 49936 | 50056 | } |
| 49937 | 50057 | aData = &aFrame[WAL_FRAME_HDRSIZE]; |
| | @@ -50320,21 +50440,21 @@ |
| 50320 | 50440 | /* Allocate space for the WalIterator object. */ |
| 50321 | 50441 | nSegment = walFramePage(iLast) + 1; |
| 50322 | 50442 | nByte = sizeof(WalIterator) |
| 50323 | 50443 | + (nSegment-1)*sizeof(struct WalSegment) |
| 50324 | 50444 | + iLast*sizeof(ht_slot); |
| 50325 | | - p = (WalIterator *)sqlite3_malloc(nByte); |
| 50445 | + p = (WalIterator *)sqlite3_malloc64(nByte); |
| 50326 | 50446 | if( !p ){ |
| 50327 | 50447 | return SQLITE_NOMEM; |
| 50328 | 50448 | } |
| 50329 | 50449 | memset(p, 0, nByte); |
| 50330 | 50450 | p->nSegment = nSegment; |
| 50331 | 50451 | |
| 50332 | 50452 | /* Allocate temporary space used by the merge-sort routine. This block |
| 50333 | 50453 | ** of memory will be freed before this function returns. |
| 50334 | 50454 | */ |
| 50335 | | - aTmp = (ht_slot *)sqlite3_malloc( |
| 50455 | + aTmp = (ht_slot *)sqlite3_malloc64( |
| 50336 | 50456 | sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast) |
| 50337 | 50457 | ); |
| 50338 | 50458 | if( !aTmp ){ |
| 50339 | 50459 | rc = SQLITE_NOMEM; |
| 50340 | 50460 | } |
| | @@ -50510,10 +50630,18 @@ |
| 50510 | 50630 | ** cannot be backfilled from the WAL. |
| 50511 | 50631 | */ |
| 50512 | 50632 | mxSafeFrame = pWal->hdr.mxFrame; |
| 50513 | 50633 | mxPage = pWal->hdr.nPage; |
| 50514 | 50634 | for(i=1; i<WAL_NREADER; i++){ |
| 50635 | + /* Thread-sanitizer reports that the following is an unsafe read, |
| 50636 | + ** as some other thread may be in the process of updating the value |
| 50637 | + ** of the aReadMark[] slot. The assumption here is that if that is |
| 50638 | + ** happening, the other client may only be increasing the value, |
| 50639 | + ** not decreasing it. So assuming either that either the "old" or |
| 50640 | + ** "new" version of the value is read, and not some arbitrary value |
| 50641 | + ** that would never be written by a real client, things are still |
| 50642 | + ** safe. */ |
| 50515 | 50643 | u32 y = pInfo->aReadMark[i]; |
| 50516 | 50644 | if( mxSafeFrame>y ){ |
| 50517 | 50645 | assert( y<=pWal->hdr.mxFrame ); |
| 50518 | 50646 | rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1); |
| 50519 | 50647 | if( rc==SQLITE_OK ){ |
| | @@ -52231,10 +52359,11 @@ |
| 52231 | 52359 | u8 noPayload; /* True if internal intKey page (thus w/o data) */ |
| 52232 | 52360 | u8 leaf; /* True if a leaf page */ |
| 52233 | 52361 | u8 hdrOffset; /* 100 for page 1. 0 otherwise */ |
| 52234 | 52362 | u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */ |
| 52235 | 52363 | u8 max1bytePayload; /* min(maxLocal,127) */ |
| 52364 | + u8 bBusy; /* Prevent endless loops on corrupt database files */ |
| 52236 | 52365 | u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */ |
| 52237 | 52366 | u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */ |
| 52238 | 52367 | u16 cellOffset; /* Index in aData of first cell pointer */ |
| 52239 | 52368 | u16 nFree; /* Number of free bytes on the page */ |
| 52240 | 52369 | u16 nCell; /* Number of cells on this page, local and ovfl */ |
| | @@ -53006,11 +53135,11 @@ |
| 53006 | 53135 | ** |
| 53007 | 53136 | ** This routine has no effect on existing database connections. |
| 53008 | 53137 | ** The shared cache setting effects only future calls to |
| 53009 | 53138 | ** sqlite3_open(), sqlite3_open16(), or sqlite3_open_v2(). |
| 53010 | 53139 | */ |
| 53011 | | -SQLITE_API int sqlite3_enable_shared_cache(int enable){ |
| 53140 | +SQLITE_API int SQLITE_STDCALL sqlite3_enable_shared_cache(int enable){ |
| 53012 | 53141 | sqlite3GlobalConfig.sharedCacheEnabled = enable; |
| 53013 | 53142 | return SQLITE_OK; |
| 53014 | 53143 | } |
| 53015 | 53144 | #endif |
| 53016 | 53145 | |
| | @@ -53520,14 +53649,19 @@ |
| 53520 | 53649 | ** prior to calling this routine. |
| 53521 | 53650 | */ |
| 53522 | 53651 | static int saveCursorPosition(BtCursor *pCur){ |
| 53523 | 53652 | int rc; |
| 53524 | 53653 | |
| 53525 | | - assert( CURSOR_VALID==pCur->eState ); |
| 53654 | + assert( CURSOR_VALID==pCur->eState || CURSOR_SKIPNEXT==pCur->eState ); |
| 53526 | 53655 | assert( 0==pCur->pKey ); |
| 53527 | 53656 | assert( cursorHoldsMutex(pCur) ); |
| 53528 | 53657 | |
| 53658 | + if( pCur->eState==CURSOR_SKIPNEXT ){ |
| 53659 | + pCur->eState = CURSOR_VALID; |
| 53660 | + }else{ |
| 53661 | + pCur->skipNext = 0; |
| 53662 | + } |
| 53529 | 53663 | rc = sqlite3BtreeKeySize(pCur, &pCur->nKey); |
| 53530 | 53664 | assert( rc==SQLITE_OK ); /* KeySize() cannot fail */ |
| 53531 | 53665 | |
| 53532 | 53666 | /* If this is an intKey table, then the above call to BtreeKeySize() |
| 53533 | 53667 | ** stores the integer key in pCur->nKey. In this case this value is |
| | @@ -53594,11 +53728,11 @@ |
| 53594 | 53728 | Pgno iRoot, /* Only save cursor with this iRoot. Save all if zero */ |
| 53595 | 53729 | BtCursor *pExcept /* Do not save this cursor */ |
| 53596 | 53730 | ){ |
| 53597 | 53731 | do{ |
| 53598 | 53732 | if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){ |
| 53599 | | - if( p->eState==CURSOR_VALID ){ |
| 53733 | + if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){ |
| 53600 | 53734 | int rc = saveCursorPosition(p); |
| 53601 | 53735 | if( SQLITE_OK!=rc ){ |
| 53602 | 53736 | return rc; |
| 53603 | 53737 | } |
| 53604 | 53738 | }else{ |
| | @@ -53666,21 +53800,23 @@ |
| 53666 | 53800 | ** at most one effective restoreCursorPosition() call after each |
| 53667 | 53801 | ** saveCursorPosition(). |
| 53668 | 53802 | */ |
| 53669 | 53803 | static int btreeRestoreCursorPosition(BtCursor *pCur){ |
| 53670 | 53804 | int rc; |
| 53805 | + int skipNext; |
| 53671 | 53806 | assert( cursorHoldsMutex(pCur) ); |
| 53672 | 53807 | assert( pCur->eState>=CURSOR_REQUIRESEEK ); |
| 53673 | 53808 | if( pCur->eState==CURSOR_FAULT ){ |
| 53674 | 53809 | return pCur->skipNext; |
| 53675 | 53810 | } |
| 53676 | 53811 | pCur->eState = CURSOR_INVALID; |
| 53677 | | - rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &pCur->skipNext); |
| 53812 | + rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext); |
| 53678 | 53813 | if( rc==SQLITE_OK ){ |
| 53679 | 53814 | sqlite3_free(pCur->pKey); |
| 53680 | 53815 | pCur->pKey = 0; |
| 53681 | 53816 | assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID ); |
| 53817 | + pCur->skipNext |= skipNext; |
| 53682 | 53818 | if( pCur->skipNext && pCur->eState==CURSOR_VALID ){ |
| 53683 | 53819 | pCur->eState = CURSOR_SKIPNEXT; |
| 53684 | 53820 | } |
| 53685 | 53821 | } |
| 53686 | 53822 | return rc; |
| | @@ -53728,13 +53864,14 @@ |
| 53728 | 53864 | rc = restoreCursorPosition(pCur); |
| 53729 | 53865 | if( rc ){ |
| 53730 | 53866 | *pDifferentRow = 1; |
| 53731 | 53867 | return rc; |
| 53732 | 53868 | } |
| 53733 | | - if( pCur->eState!=CURSOR_VALID || NEVER(pCur->skipNext!=0) ){ |
| 53869 | + if( pCur->eState!=CURSOR_VALID ){ |
| 53734 | 53870 | *pDifferentRow = 1; |
| 53735 | 53871 | }else{ |
| 53872 | + assert( pCur->skipNext==0 ); |
| 53736 | 53873 | *pDifferentRow = 0; |
| 53737 | 53874 | } |
| 53738 | 53875 | return SQLITE_OK; |
| 53739 | 53876 | } |
| 53740 | 53877 | |
| | @@ -54871,20 +55008,22 @@ |
| 54871 | 55008 | ** If this Btree is a candidate for shared cache, try to find an |
| 54872 | 55009 | ** existing BtShared object that we can share with |
| 54873 | 55010 | */ |
| 54874 | 55011 | if( isTempDb==0 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=0) ){ |
| 54875 | 55012 | if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){ |
| 55013 | + int nFilename = sqlite3Strlen30(zFilename)+1; |
| 54876 | 55014 | int nFullPathname = pVfs->mxPathname+1; |
| 54877 | | - char *zFullPathname = sqlite3Malloc(nFullPathname); |
| 55015 | + char *zFullPathname = sqlite3Malloc(MAX(nFullPathname,nFilename)); |
| 54878 | 55016 | MUTEX_LOGIC( sqlite3_mutex *mutexShared; ) |
| 55017 | + |
| 54879 | 55018 | p->sharable = 1; |
| 54880 | 55019 | if( !zFullPathname ){ |
| 54881 | 55020 | sqlite3_free(p); |
| 54882 | 55021 | return SQLITE_NOMEM; |
| 54883 | 55022 | } |
| 54884 | 55023 | if( isMemdb ){ |
| 54885 | | - memcpy(zFullPathname, zFilename, sqlite3Strlen30(zFilename)+1); |
| 55024 | + memcpy(zFullPathname, zFilename, nFilename); |
| 54886 | 55025 | }else{ |
| 54887 | 55026 | rc = sqlite3OsFullPathname(pVfs, zFilename, |
| 54888 | 55027 | nFullPathname, zFullPathname); |
| 54889 | 55028 | if( rc ){ |
| 54890 | 55029 | sqlite3_free(zFullPathname); |
| | @@ -55339,11 +55478,11 @@ |
| 55339 | 55478 | } |
| 55340 | 55479 | assert( nReserve>=0 && nReserve<=255 ); |
| 55341 | 55480 | if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE && |
| 55342 | 55481 | ((pageSize-1)&pageSize)==0 ){ |
| 55343 | 55482 | assert( (pageSize & 7)==0 ); |
| 55344 | | - assert( !pBt->pPage1 && !pBt->pCursor ); |
| 55483 | + assert( !pBt->pCursor ); |
| 55345 | 55484 | pBt->pageSize = (u32)pageSize; |
| 55346 | 55485 | freeTempSpace(pBt); |
| 55347 | 55486 | } |
| 55348 | 55487 | rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve); |
| 55349 | 55488 | pBt->usableSize = pBt->pageSize - (u16)nReserve; |
| | @@ -56545,11 +56684,11 @@ |
| 56545 | 56684 | if( pBtree ){ |
| 56546 | 56685 | sqlite3BtreeEnter(pBtree); |
| 56547 | 56686 | for(p=pBtree->pBt->pCursor; p; p=p->pNext){ |
| 56548 | 56687 | int i; |
| 56549 | 56688 | if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){ |
| 56550 | | - if( p->eState==CURSOR_VALID ){ |
| 56689 | + if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){ |
| 56551 | 56690 | rc = saveCursorPosition(p); |
| 56552 | 56691 | if( rc!=SQLITE_OK ){ |
| 56553 | 56692 | (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0); |
| 56554 | 56693 | break; |
| 56555 | 56694 | } |
| | @@ -56951,10 +57090,12 @@ |
| 56951 | 57090 | ** to return an integer result code for historical reasons. |
| 56952 | 57091 | */ |
| 56953 | 57092 | SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){ |
| 56954 | 57093 | assert( cursorHoldsMutex(pCur) ); |
| 56955 | 57094 | assert( pCur->eState==CURSOR_VALID ); |
| 57095 | + assert( pCur->iPage>=0 ); |
| 57096 | + assert( pCur->iPage<BTCURSOR_MAX_DEPTH ); |
| 56956 | 57097 | assert( pCur->apPage[pCur->iPage]->intKeyLeaf==1 ); |
| 56957 | 57098 | getCellInfo(pCur); |
| 56958 | 57099 | *pSize = pCur->info.nPayload; |
| 56959 | 57100 | return SQLITE_OK; |
| 56960 | 57101 | } |
| | @@ -57359,17 +57500,22 @@ |
| 57359 | 57500 | */ |
| 57360 | 57501 | static const void *fetchPayload( |
| 57361 | 57502 | BtCursor *pCur, /* Cursor pointing to entry to read from */ |
| 57362 | 57503 | u32 *pAmt /* Write the number of available bytes here */ |
| 57363 | 57504 | ){ |
| 57505 | + u32 amt; |
| 57364 | 57506 | assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]); |
| 57365 | 57507 | assert( pCur->eState==CURSOR_VALID ); |
| 57366 | 57508 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 57367 | 57509 | assert( cursorHoldsMutex(pCur) ); |
| 57368 | 57510 | assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); |
| 57369 | 57511 | assert( pCur->info.nSize>0 ); |
| 57370 | | - *pAmt = pCur->info.nLocal; |
| 57512 | + assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB ); |
| 57513 | + assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB); |
| 57514 | + amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload); |
| 57515 | + if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal; |
| 57516 | + *pAmt = amt; |
| 57371 | 57517 | return (void*)pCur->info.pPayload; |
| 57372 | 57518 | } |
| 57373 | 57519 | |
| 57374 | 57520 | |
| 57375 | 57521 | /* |
| | @@ -57429,19 +57575,21 @@ |
| 57429 | 57575 | return SQLITE_CORRUPT_BKPT; |
| 57430 | 57576 | } |
| 57431 | 57577 | return SQLITE_OK; |
| 57432 | 57578 | } |
| 57433 | 57579 | |
| 57434 | | -#if 0 |
| 57580 | +#if SQLITE_DEBUG |
| 57435 | 57581 | /* |
| 57436 | 57582 | ** Page pParent is an internal (non-leaf) tree page. This function |
| 57437 | 57583 | ** asserts that page number iChild is the left-child if the iIdx'th |
| 57438 | 57584 | ** cell in page pParent. Or, if iIdx is equal to the total number of |
| 57439 | 57585 | ** cells in pParent, that page number iChild is the right-child of |
| 57440 | 57586 | ** the page. |
| 57441 | 57587 | */ |
| 57442 | 57588 | static void assertParentIndex(MemPage *pParent, int iIdx, Pgno iChild){ |
| 57589 | + if( CORRUPT_DB ) return; /* The conditions tested below might not be true |
| 57590 | + ** in a corrupt database */ |
| 57443 | 57591 | assert( iIdx<=pParent->nCell ); |
| 57444 | 57592 | if( iIdx==pParent->nCell ){ |
| 57445 | 57593 | assert( get4byte(&pParent->aData[pParent->hdrOffset+8])==iChild ); |
| 57446 | 57594 | }else{ |
| 57447 | 57595 | assert( get4byte(findCell(pParent, iIdx))==iChild ); |
| | @@ -57462,23 +57610,15 @@ |
| 57462 | 57610 | static void moveToParent(BtCursor *pCur){ |
| 57463 | 57611 | assert( cursorHoldsMutex(pCur) ); |
| 57464 | 57612 | assert( pCur->eState==CURSOR_VALID ); |
| 57465 | 57613 | assert( pCur->iPage>0 ); |
| 57466 | 57614 | assert( pCur->apPage[pCur->iPage] ); |
| 57467 | | - |
| 57468 | | - /* UPDATE: It is actually possible for the condition tested by the assert |
| 57469 | | - ** below to be untrue if the database file is corrupt. This can occur if |
| 57470 | | - ** one cursor has modified page pParent while a reference to it is held |
| 57471 | | - ** by a second cursor. Which can only happen if a single page is linked |
| 57472 | | - ** into more than one b-tree structure in a corrupt database. */ |
| 57473 | | -#if 0 |
| 57474 | 57615 | assertParentIndex( |
| 57475 | 57616 | pCur->apPage[pCur->iPage-1], |
| 57476 | 57617 | pCur->aiIdx[pCur->iPage-1], |
| 57477 | 57618 | pCur->apPage[pCur->iPage]->pgno |
| 57478 | 57619 | ); |
| 57479 | | -#endif |
| 57480 | 57620 | testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell ); |
| 57481 | 57621 | |
| 57482 | 57622 | releasePage(pCur->apPage[pCur->iPage]); |
| 57483 | 57623 | pCur->iPage--; |
| 57484 | 57624 | pCur->info.nSize = 0; |
| | @@ -59649,11 +59789,10 @@ |
| 59649 | 59789 | if( iParentIdx==0 ){ |
| 59650 | 59790 | nxDiv = 0; |
| 59651 | 59791 | }else if( iParentIdx==i ){ |
| 59652 | 59792 | nxDiv = i-2+bBulk; |
| 59653 | 59793 | }else{ |
| 59654 | | - assert( bBulk==0 ); |
| 59655 | 59794 | nxDiv = iParentIdx-1; |
| 59656 | 59795 | } |
| 59657 | 59796 | i = 2-bBulk; |
| 59658 | 59797 | } |
| 59659 | 59798 | nOld = i+1; |
| | @@ -60422,10 +60561,11 @@ |
| 60422 | 60561 | pPage->nOverflow = 0; |
| 60423 | 60562 | |
| 60424 | 60563 | /* The next iteration of the do-loop balances the parent page. */ |
| 60425 | 60564 | releasePage(pPage); |
| 60426 | 60565 | pCur->iPage--; |
| 60566 | + assert( pCur->iPage>=0 ); |
| 60427 | 60567 | } |
| 60428 | 60568 | }while( rc==SQLITE_OK ); |
| 60429 | 60569 | |
| 60430 | 60570 | if( pFree ){ |
| 60431 | 60571 | sqlite3PageFree(pFree); |
| | @@ -60898,13 +61038,17 @@ |
| 60898 | 61038 | |
| 60899 | 61039 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 60900 | 61040 | if( pgno>btreePagecount(pBt) ){ |
| 60901 | 61041 | return SQLITE_CORRUPT_BKPT; |
| 60902 | 61042 | } |
| 60903 | | - |
| 60904 | 61043 | rc = getAndInitPage(pBt, pgno, &pPage, 0); |
| 60905 | 61044 | if( rc ) return rc; |
| 61045 | + if( pPage->bBusy ){ |
| 61046 | + rc = SQLITE_CORRUPT_BKPT; |
| 61047 | + goto cleardatabasepage_out; |
| 61048 | + } |
| 61049 | + pPage->bBusy = 1; |
| 60906 | 61050 | hdr = pPage->hdrOffset; |
| 60907 | 61051 | for(i=0; i<pPage->nCell; i++){ |
| 60908 | 61052 | pCell = findCell(pPage, i); |
| 60909 | 61053 | if( !pPage->leaf ){ |
| 60910 | 61054 | rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange); |
| | @@ -60925,10 +61069,11 @@ |
| 60925 | 61069 | }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){ |
| 60926 | 61070 | zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF); |
| 60927 | 61071 | } |
| 60928 | 61072 | |
| 60929 | 61073 | cleardatabasepage_out: |
| 61074 | + pPage->bBusy = 0; |
| 60930 | 61075 | releasePage(pPage); |
| 60931 | 61076 | return rc; |
| 60932 | 61077 | } |
| 60933 | 61078 | |
| 60934 | 61079 | /* |
| | @@ -61431,10 +61576,61 @@ |
| 61431 | 61576 | iPage = get4byte(pOvflData); |
| 61432 | 61577 | sqlite3PagerUnref(pOvflPage); |
| 61433 | 61578 | } |
| 61434 | 61579 | } |
| 61435 | 61580 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 61581 | + |
| 61582 | +/* |
| 61583 | +** An implementation of a min-heap. |
| 61584 | +** |
| 61585 | +** aHeap[0] is the number of elements on the heap. aHeap[1] is the |
| 61586 | +** root element. The daughter nodes of aHeap[N] are aHeap[N*2] |
| 61587 | +** and aHeap[N*2+1]. |
| 61588 | +** |
| 61589 | +** The heap property is this: Every node is less than or equal to both |
| 61590 | +** of its daughter nodes. A consequence of the heap property is that the |
| 61591 | +** root node aHeap[1] is always the minimum value currently in the heap. |
| 61592 | +** |
| 61593 | +** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto |
| 61594 | +** the heap, preserving the heap property. The btreeHeapPull() routine |
| 61595 | +** removes the root element from the heap (the minimum value in the heap) |
| 61596 | +** and then moves other nodes around as necessary to preserve the heap |
| 61597 | +** property. |
| 61598 | +** |
| 61599 | +** This heap is used for cell overlap and coverage testing. Each u32 |
| 61600 | +** entry represents the span of a cell or freeblock on a btree page. |
| 61601 | +** The upper 16 bits are the index of the first byte of a range and the |
| 61602 | +** lower 16 bits are the index of the last byte of that range. |
| 61603 | +*/ |
| 61604 | +static void btreeHeapInsert(u32 *aHeap, u32 x){ |
| 61605 | + u32 j, i = ++aHeap[0]; |
| 61606 | + aHeap[i] = x; |
| 61607 | + while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){ |
| 61608 | + x = aHeap[j]; |
| 61609 | + aHeap[j] = aHeap[i]; |
| 61610 | + aHeap[i] = x; |
| 61611 | + i = j; |
| 61612 | + } |
| 61613 | +} |
| 61614 | +static int btreeHeapPull(u32 *aHeap, u32 *pOut){ |
| 61615 | + u32 j, i, x; |
| 61616 | + if( (x = aHeap[0])==0 ) return 0; |
| 61617 | + *pOut = aHeap[1]; |
| 61618 | + aHeap[1] = aHeap[x]; |
| 61619 | + aHeap[x] = 0xffffffff; |
| 61620 | + aHeap[0]--; |
| 61621 | + i = 1; |
| 61622 | + while( (j = i*2)<=aHeap[0] ){ |
| 61623 | + if( aHeap[j]>aHeap[j+1] ) j++; |
| 61624 | + if( aHeap[i]<aHeap[j] ) break; |
| 61625 | + x = aHeap[i]; |
| 61626 | + aHeap[i] = aHeap[j]; |
| 61627 | + aHeap[j] = x; |
| 61628 | + i = j; |
| 61629 | + } |
| 61630 | + return 1; |
| 61631 | +} |
| 61436 | 61632 | |
| 61437 | 61633 | #ifndef SQLITE_OMIT_INTEGRITY_CHECK |
| 61438 | 61634 | /* |
| 61439 | 61635 | ** Do various sanity checks on a single page of a tree. Return |
| 61440 | 61636 | ** the tree depth. Root pages return 0. Parents of root pages |
| | @@ -61464,11 +61660,12 @@ |
| 61464 | 61660 | int hdr, cellStart; |
| 61465 | 61661 | int nCell; |
| 61466 | 61662 | u8 *data; |
| 61467 | 61663 | BtShared *pBt; |
| 61468 | 61664 | int usableSize; |
| 61469 | | - char *hit = 0; |
| 61665 | + u32 *heap = 0; |
| 61666 | + u32 x, prev = 0; |
| 61470 | 61667 | i64 nMinKey = 0; |
| 61471 | 61668 | i64 nMaxKey = 0; |
| 61472 | 61669 | const char *saved_zPfx = pCheck->zPfx; |
| 61473 | 61670 | int saved_v1 = pCheck->v1; |
| 61474 | 61671 | int saved_v2 = pCheck->v2; |
| | @@ -61609,19 +61806,19 @@ |
| 61609 | 61806 | |
| 61610 | 61807 | /* Check for complete coverage of the page |
| 61611 | 61808 | */ |
| 61612 | 61809 | data = pPage->aData; |
| 61613 | 61810 | hdr = pPage->hdrOffset; |
| 61614 | | - hit = sqlite3PageMalloc( pBt->pageSize ); |
| 61811 | + heap = (u32*)sqlite3PageMalloc( pBt->pageSize ); |
| 61615 | 61812 | pCheck->zPfx = 0; |
| 61616 | | - if( hit==0 ){ |
| 61813 | + if( heap==0 ){ |
| 61617 | 61814 | pCheck->mallocFailed = 1; |
| 61618 | 61815 | }else{ |
| 61619 | 61816 | int contentOffset = get2byteNotZero(&data[hdr+5]); |
| 61620 | 61817 | assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */ |
| 61621 | | - memset(hit+contentOffset, 0, usableSize-contentOffset); |
| 61622 | | - memset(hit, 1, contentOffset); |
| 61818 | + heap[0] = 0; |
| 61819 | + btreeHeapInsert(heap, contentOffset-1); |
| 61623 | 61820 | /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the |
| 61624 | 61821 | ** number of cells on the page. */ |
| 61625 | 61822 | nCell = get2byte(&data[hdr+3]); |
| 61626 | 61823 | /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page |
| 61627 | 61824 | ** immediately follows the b-tree page header. */ |
| | @@ -61629,20 +61826,19 @@ |
| 61629 | 61826 | /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte |
| 61630 | 61827 | ** integer offsets to the cell contents. */ |
| 61631 | 61828 | for(i=0; i<nCell; i++){ |
| 61632 | 61829 | int pc = get2byte(&data[cellStart+i*2]); |
| 61633 | 61830 | u32 size = 65536; |
| 61634 | | - int j; |
| 61635 | 61831 | if( pc<=usableSize-4 ){ |
| 61636 | 61832 | size = cellSizePtr(pPage, &data[pc]); |
| 61637 | 61833 | } |
| 61638 | 61834 | if( (int)(pc+size-1)>=usableSize ){ |
| 61639 | 61835 | pCheck->zPfx = 0; |
| 61640 | 61836 | checkAppendMsg(pCheck, |
| 61641 | 61837 | "Corruption detected in cell %d on page %d",i,iPage); |
| 61642 | 61838 | }else{ |
| 61643 | | - for(j=pc+size-1; j>=pc; j--) hit[j]++; |
| 61839 | + btreeHeapInsert(heap, (pc<<16)|(pc+size-1)); |
| 61644 | 61840 | } |
| 61645 | 61841 | } |
| 61646 | 61842 | /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header |
| 61647 | 61843 | ** is the offset of the first freeblock, or zero if there are no |
| 61648 | 61844 | ** freeblocks on the page. */ |
| | @@ -61650,11 +61846,11 @@ |
| 61650 | 61846 | while( i>0 ){ |
| 61651 | 61847 | int size, j; |
| 61652 | 61848 | assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */ |
| 61653 | 61849 | size = get2byte(&data[i+2]); |
| 61654 | 61850 | assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */ |
| 61655 | | - for(j=i+size-1; j>=i; j--) hit[j]++; |
| 61851 | + btreeHeapInsert(heap, (i<<16)|(i+size-1)); |
| 61656 | 61852 | /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a |
| 61657 | 61853 | ** big-endian integer which is the offset in the b-tree page of the next |
| 61658 | 61854 | ** freeblock in the chain, or zero if the freeblock is the last on the |
| 61659 | 61855 | ** chain. */ |
| 61660 | 61856 | j = get2byte(&data[i]); |
| | @@ -61662,31 +61858,37 @@ |
| 61662 | 61858 | ** increasing offset. */ |
| 61663 | 61859 | assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */ |
| 61664 | 61860 | assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */ |
| 61665 | 61861 | i = j; |
| 61666 | 61862 | } |
| 61667 | | - for(i=cnt=0; i<usableSize; i++){ |
| 61668 | | - if( hit[i]==0 ){ |
| 61669 | | - cnt++; |
| 61670 | | - }else if( hit[i]>1 ){ |
| 61863 | + cnt = 0; |
| 61864 | + assert( heap[0]>0 ); |
| 61865 | + assert( (heap[1]>>16)==0 ); |
| 61866 | + btreeHeapPull(heap,&prev); |
| 61867 | + while( btreeHeapPull(heap,&x) ){ |
| 61868 | + if( (prev&0xffff)+1>(x>>16) ){ |
| 61671 | 61869 | checkAppendMsg(pCheck, |
| 61672 | | - "Multiple uses for byte %d of page %d", i, iPage); |
| 61870 | + "Multiple uses for byte %u of page %d", x>>16, iPage); |
| 61673 | 61871 | break; |
| 61872 | + }else{ |
| 61873 | + cnt += (x>>16) - (prev&0xffff) - 1; |
| 61874 | + prev = x; |
| 61674 | 61875 | } |
| 61675 | 61876 | } |
| 61877 | + cnt += usableSize - (prev&0xffff) - 1; |
| 61676 | 61878 | /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments |
| 61677 | 61879 | ** is stored in the fifth field of the b-tree page header. |
| 61678 | 61880 | ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the |
| 61679 | 61881 | ** number of fragmented free bytes within the cell content area. |
| 61680 | 61882 | */ |
| 61681 | | - if( cnt!=data[hdr+7] ){ |
| 61883 | + if( heap[0]==0 && cnt!=data[hdr+7] ){ |
| 61682 | 61884 | checkAppendMsg(pCheck, |
| 61683 | 61885 | "Fragmentation of %d bytes reported as %d on page %d", |
| 61684 | 61886 | cnt, data[hdr+7], iPage); |
| 61685 | 61887 | } |
| 61686 | 61888 | } |
| 61687 | | - sqlite3PageFree(hit); |
| 61889 | + sqlite3PageFree(heap); |
| 61688 | 61890 | releasePage(pPage); |
| 61689 | 61891 | |
| 61690 | 61892 | end_of_check: |
| 61691 | 61893 | pCheck->zPfx = saved_zPfx; |
| 61692 | 61894 | pCheck->v1 = saved_v1; |
| | @@ -61746,12 +61948,11 @@ |
| 61746 | 61948 | sqlite3BtreeLeave(p); |
| 61747 | 61949 | return 0; |
| 61748 | 61950 | } |
| 61749 | 61951 | i = PENDING_BYTE_PAGE(pBt); |
| 61750 | 61952 | if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i); |
| 61751 | | - sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH); |
| 61752 | | - sCheck.errMsg.useMalloc = 2; |
| 61953 | + sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH); |
| 61753 | 61954 | |
| 61754 | 61955 | /* Check the integrity of the freelist |
| 61755 | 61956 | */ |
| 61756 | 61957 | sCheck.zPfx = "Main freelist: "; |
| 61757 | 61958 | checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]), |
| | @@ -62239,11 +62440,11 @@ |
| 62239 | 62440 | ** a pointer to the new sqlite3_backup object. |
| 62240 | 62441 | ** |
| 62241 | 62442 | ** If an error occurs, NULL is returned and an error code and error message |
| 62242 | 62443 | ** stored in database handle pDestDb. |
| 62243 | 62444 | */ |
| 62244 | | -SQLITE_API sqlite3_backup *sqlite3_backup_init( |
| 62445 | +SQLITE_API sqlite3_backup *SQLITE_STDCALL sqlite3_backup_init( |
| 62245 | 62446 | sqlite3* pDestDb, /* Database to write to */ |
| 62246 | 62447 | const char *zDestDb, /* Name of database within pDestDb */ |
| 62247 | 62448 | sqlite3* pSrcDb, /* Database connection to read from */ |
| 62248 | 62449 | const char *zSrcDb /* Name of database within pSrcDb */ |
| 62249 | 62450 | ){ |
| | @@ -62447,11 +62648,11 @@ |
| 62447 | 62648 | } |
| 62448 | 62649 | |
| 62449 | 62650 | /* |
| 62450 | 62651 | ** Copy nPage pages from the source b-tree to the destination. |
| 62451 | 62652 | */ |
| 62452 | | -SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage){ |
| 62653 | +SQLITE_API int SQLITE_STDCALL sqlite3_backup_step(sqlite3_backup *p, int nPage){ |
| 62453 | 62654 | int rc; |
| 62454 | 62655 | int destMode; /* Destination journal mode */ |
| 62455 | 62656 | int pgszSrc = 0; /* Source page size */ |
| 62456 | 62657 | int pgszDest = 0; /* Destination page size */ |
| 62457 | 62658 | |
| | @@ -62692,11 +62893,11 @@ |
| 62692 | 62893 | } |
| 62693 | 62894 | |
| 62694 | 62895 | /* |
| 62695 | 62896 | ** Release all resources associated with an sqlite3_backup* handle. |
| 62696 | 62897 | */ |
| 62697 | | -SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p){ |
| 62898 | +SQLITE_API int SQLITE_STDCALL sqlite3_backup_finish(sqlite3_backup *p){ |
| 62698 | 62899 | sqlite3_backup **pp; /* Ptr to head of pagers backup list */ |
| 62699 | 62900 | sqlite3 *pSrcDb; /* Source database connection */ |
| 62700 | 62901 | int rc; /* Value to return */ |
| 62701 | 62902 | |
| 62702 | 62903 | /* Enter the mutexes */ |
| | @@ -62744,11 +62945,11 @@ |
| 62744 | 62945 | |
| 62745 | 62946 | /* |
| 62746 | 62947 | ** Return the number of pages still to be backed up as of the most recent |
| 62747 | 62948 | ** call to sqlite3_backup_step(). |
| 62748 | 62949 | */ |
| 62749 | | -SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p){ |
| 62950 | +SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p){ |
| 62750 | 62951 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 62751 | 62952 | if( p==0 ){ |
| 62752 | 62953 | (void)SQLITE_MISUSE_BKPT; |
| 62753 | 62954 | return 0; |
| 62754 | 62955 | } |
| | @@ -62758,11 +62959,11 @@ |
| 62758 | 62959 | |
| 62759 | 62960 | /* |
| 62760 | 62961 | ** Return the total number of pages in the source database as of the most |
| 62761 | 62962 | ** recent call to sqlite3_backup_step(). |
| 62762 | 62963 | */ |
| 62763 | | -SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p){ |
| 62964 | +SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p){ |
| 62764 | 62965 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 62765 | 62966 | if( p==0 ){ |
| 62766 | 62967 | (void)SQLITE_MISUSE_BKPT; |
| 62767 | 62968 | return 0; |
| 62768 | 62969 | } |
| | @@ -63083,14 +63284,15 @@ |
| 63083 | 63284 | return SQLITE_NOMEM; |
| 63084 | 63285 | } |
| 63085 | 63286 | pMem->z[pMem->n] = 0; |
| 63086 | 63287 | pMem->z[pMem->n+1] = 0; |
| 63087 | 63288 | pMem->flags |= MEM_Term; |
| 63289 | + } |
| 63290 | + pMem->flags &= ~MEM_Ephem; |
| 63088 | 63291 | #ifdef SQLITE_DEBUG |
| 63089 | | - pMem->pScopyFrom = 0; |
| 63292 | + pMem->pScopyFrom = 0; |
| 63090 | 63293 | #endif |
| 63091 | | - } |
| 63092 | 63294 | |
| 63093 | 63295 | return SQLITE_OK; |
| 63094 | 63296 | } |
| 63095 | 63297 | |
| 63096 | 63298 | /* |
| | @@ -64530,11 +64732,11 @@ |
| 64530 | 64732 | int i; |
| 64531 | 64733 | int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField; |
| 64532 | 64734 | Mem *aMem = pRec->aMem; |
| 64533 | 64735 | sqlite3 *db = aMem[0].db; |
| 64534 | 64736 | for(i=0; i<nCol; i++){ |
| 64535 | | - if( aMem[i].szMalloc ) sqlite3DbFree(db, aMem[i].zMalloc); |
| 64737 | + sqlite3VdbeMemRelease(&aMem[i]); |
| 64536 | 64738 | } |
| 64537 | 64739 | sqlite3KeyInfoUnref(pRec->pKeyInfo); |
| 64538 | 64740 | sqlite3DbFree(db, pRec); |
| 64539 | 64741 | } |
| 64540 | 64742 | } |
| | @@ -64633,11 +64835,11 @@ |
| 64633 | 64835 | } |
| 64634 | 64836 | |
| 64635 | 64837 | /* |
| 64636 | 64838 | ** Return the SQL associated with a prepared statement |
| 64637 | 64839 | */ |
| 64638 | | -SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt){ |
| 64840 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt){ |
| 64639 | 64841 | Vdbe *p = (Vdbe *)pStmt; |
| 64640 | 64842 | return (p && p->isPrepareV2) ? p->zSql : 0; |
| 64641 | 64843 | } |
| 64642 | 64844 | |
| 64643 | 64845 | /* |
| | @@ -66366,18 +66568,35 @@ |
| 66366 | 66568 | pVtabCursor->pVtab->nRef--; |
| 66367 | 66569 | pModule->xClose(pVtabCursor); |
| 66368 | 66570 | } |
| 66369 | 66571 | #endif |
| 66370 | 66572 | } |
| 66573 | + |
| 66574 | +/* |
| 66575 | +** Close all cursors in the current frame. |
| 66576 | +*/ |
| 66577 | +static void closeCursorsInFrame(Vdbe *p){ |
| 66578 | + if( p->apCsr ){ |
| 66579 | + int i; |
| 66580 | + for(i=0; i<p->nCursor; i++){ |
| 66581 | + VdbeCursor *pC = p->apCsr[i]; |
| 66582 | + if( pC ){ |
| 66583 | + sqlite3VdbeFreeCursor(p, pC); |
| 66584 | + p->apCsr[i] = 0; |
| 66585 | + } |
| 66586 | + } |
| 66587 | + } |
| 66588 | +} |
| 66371 | 66589 | |
| 66372 | 66590 | /* |
| 66373 | 66591 | ** Copy the values stored in the VdbeFrame structure to its Vdbe. This |
| 66374 | 66592 | ** is used, for example, when a trigger sub-program is halted to restore |
| 66375 | 66593 | ** control to the main program. |
| 66376 | 66594 | */ |
| 66377 | 66595 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){ |
| 66378 | 66596 | Vdbe *v = pFrame->v; |
| 66597 | + closeCursorsInFrame(v); |
| 66379 | 66598 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 66380 | 66599 | v->anExec = pFrame->anExec; |
| 66381 | 66600 | #endif |
| 66382 | 66601 | v->aOnceFlag = pFrame->aOnceFlag; |
| 66383 | 66602 | v->nOnceFlag = pFrame->nOnceFlag; |
| | @@ -66408,21 +66627,11 @@ |
| 66408 | 66627 | sqlite3VdbeFrameRestore(pFrame); |
| 66409 | 66628 | p->pFrame = 0; |
| 66410 | 66629 | p->nFrame = 0; |
| 66411 | 66630 | } |
| 66412 | 66631 | assert( p->nFrame==0 ); |
| 66413 | | - |
| 66414 | | - if( p->apCsr ){ |
| 66415 | | - int i; |
| 66416 | | - for(i=0; i<p->nCursor; i++){ |
| 66417 | | - VdbeCursor *pC = p->apCsr[i]; |
| 66418 | | - if( pC ){ |
| 66419 | | - sqlite3VdbeFreeCursor(p, pC); |
| 66420 | | - p->apCsr[i] = 0; |
| 66421 | | - } |
| 66422 | | - } |
| 66423 | | - } |
| 66632 | + closeCursorsInFrame(p); |
| 66424 | 66633 | if( p->aMem ){ |
| 66425 | 66634 | releaseMemArray(&p->aMem[1], p->nMem); |
| 66426 | 66635 | } |
| 66427 | 66636 | while( p->pDelFrame ){ |
| 66428 | 66637 | VdbeFrame *pDel = p->pDelFrame; |
| | @@ -68163,11 +68372,11 @@ |
| 68163 | 68372 | ** If database corruption is discovered, set pPKey2->errCode to |
| 68164 | 68373 | ** SQLITE_CORRUPT and return 0. If an OOM error is encountered, |
| 68165 | 68374 | ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the |
| 68166 | 68375 | ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db). |
| 68167 | 68376 | */ |
| 68168 | | -static int vdbeRecordCompareWithSkip( |
| 68377 | +SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip( |
| 68169 | 68378 | int nKey1, const void *pKey1, /* Left key */ |
| 68170 | 68379 | UnpackedRecord *pPKey2, /* Right key */ |
| 68171 | 68380 | int bSkip /* If true, skip the first field */ |
| 68172 | 68381 | ){ |
| 68173 | 68382 | u32 d1; /* Offset into aKey[] of next data element */ |
| | @@ -68349,11 +68558,11 @@ |
| 68349 | 68558 | } |
| 68350 | 68559 | SQLITE_PRIVATE int sqlite3VdbeRecordCompare( |
| 68351 | 68560 | int nKey1, const void *pKey1, /* Left key */ |
| 68352 | 68561 | UnpackedRecord *pPKey2 /* Right key */ |
| 68353 | 68562 | ){ |
| 68354 | | - return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0); |
| 68563 | + return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0); |
| 68355 | 68564 | } |
| 68356 | 68565 | |
| 68357 | 68566 | |
| 68358 | 68567 | /* |
| 68359 | 68568 | ** This function is an optimized version of sqlite3VdbeRecordCompare() |
| | @@ -68437,11 +68646,11 @@ |
| 68437 | 68646 | }else if( v<lhs ){ |
| 68438 | 68647 | res = pPKey2->r2; |
| 68439 | 68648 | }else if( pPKey2->nField>1 ){ |
| 68440 | 68649 | /* The first fields of the two keys are equal. Compare the trailing |
| 68441 | 68650 | ** fields. */ |
| 68442 | | - res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 68651 | + res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 68443 | 68652 | }else{ |
| 68444 | 68653 | /* The first fields of the two keys are equal and there are no trailing |
| 68445 | 68654 | ** fields. Return pPKey2->default_rc in this case. */ |
| 68446 | 68655 | res = pPKey2->default_rc; |
| 68447 | 68656 | } |
| | @@ -68485,11 +68694,11 @@ |
| 68485 | 68694 | |
| 68486 | 68695 | if( res==0 ){ |
| 68487 | 68696 | res = nStr - pPKey2->aMem[0].n; |
| 68488 | 68697 | if( res==0 ){ |
| 68489 | 68698 | if( pPKey2->nField>1 ){ |
| 68490 | | - res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 68699 | + res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 68491 | 68700 | }else{ |
| 68492 | 68701 | res = pPKey2->default_rc; |
| 68493 | 68702 | } |
| 68494 | 68703 | }else if( res>0 ){ |
| 68495 | 68704 | res = pPKey2->r2; |
| | @@ -68789,11 +68998,11 @@ |
| 68789 | 68998 | ** execution environment changes in a way that would alter the program |
| 68790 | 68999 | ** that sqlite3_prepare() generates. For example, if new functions or |
| 68791 | 69000 | ** collating sequences are registered or if an authorizer function is |
| 68792 | 69001 | ** added or changed. |
| 68793 | 69002 | */ |
| 68794 | | -SQLITE_API int sqlite3_expired(sqlite3_stmt *pStmt){ |
| 69003 | +SQLITE_API int SQLITE_STDCALL sqlite3_expired(sqlite3_stmt *pStmt){ |
| 68795 | 69004 | Vdbe *p = (Vdbe*)pStmt; |
| 68796 | 69005 | return p==0 || p->expired; |
| 68797 | 69006 | } |
| 68798 | 69007 | #endif |
| 68799 | 69008 | |
| | @@ -68826,11 +69035,11 @@ |
| 68826 | 69035 | ** machine. |
| 68827 | 69036 | ** |
| 68828 | 69037 | ** This routine sets the error code and string returned by |
| 68829 | 69038 | ** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16(). |
| 68830 | 69039 | */ |
| 68831 | | -SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt){ |
| 69040 | +SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt){ |
| 68832 | 69041 | int rc; |
| 68833 | 69042 | if( pStmt==0 ){ |
| 68834 | 69043 | /* IMPLEMENTATION-OF: R-57228-12904 Invoking sqlite3_finalize() on a NULL |
| 68835 | 69044 | ** pointer is a harmless no-op. */ |
| 68836 | 69045 | rc = SQLITE_OK; |
| | @@ -68852,11 +69061,11 @@ |
| 68852 | 69061 | ** the prior execution is returned. |
| 68853 | 69062 | ** |
| 68854 | 69063 | ** This routine sets the error code and string returned by |
| 68855 | 69064 | ** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16(). |
| 68856 | 69065 | */ |
| 68857 | | -SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt){ |
| 69066 | +SQLITE_API int SQLITE_STDCALL sqlite3_reset(sqlite3_stmt *pStmt){ |
| 68858 | 69067 | int rc; |
| 68859 | 69068 | if( pStmt==0 ){ |
| 68860 | 69069 | rc = SQLITE_OK; |
| 68861 | 69070 | }else{ |
| 68862 | 69071 | Vdbe *v = (Vdbe*)pStmt; |
| | @@ -68871,11 +69080,11 @@ |
| 68871 | 69080 | } |
| 68872 | 69081 | |
| 68873 | 69082 | /* |
| 68874 | 69083 | ** Set all the parameters in the compiled SQL statement to NULL. |
| 68875 | 69084 | */ |
| 68876 | | -SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt *pStmt){ |
| 69085 | +SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt *pStmt){ |
| 68877 | 69086 | int i; |
| 68878 | 69087 | int rc = SQLITE_OK; |
| 68879 | 69088 | Vdbe *p = (Vdbe*)pStmt; |
| 68880 | 69089 | #if SQLITE_THREADSAFE |
| 68881 | 69090 | sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex; |
| | @@ -68895,54 +69104,54 @@ |
| 68895 | 69104 | |
| 68896 | 69105 | /**************************** sqlite3_value_ ******************************* |
| 68897 | 69106 | ** The following routines extract information from a Mem or sqlite3_value |
| 68898 | 69107 | ** structure. |
| 68899 | 69108 | */ |
| 68900 | | -SQLITE_API const void *sqlite3_value_blob(sqlite3_value *pVal){ |
| 69109 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_value_blob(sqlite3_value *pVal){ |
| 68901 | 69110 | Mem *p = (Mem*)pVal; |
| 68902 | 69111 | if( p->flags & (MEM_Blob|MEM_Str) ){ |
| 68903 | 69112 | sqlite3VdbeMemExpandBlob(p); |
| 68904 | 69113 | p->flags |= MEM_Blob; |
| 68905 | 69114 | return p->n ? p->z : 0; |
| 68906 | 69115 | }else{ |
| 68907 | 69116 | return sqlite3_value_text(pVal); |
| 68908 | 69117 | } |
| 68909 | 69118 | } |
| 68910 | | -SQLITE_API int sqlite3_value_bytes(sqlite3_value *pVal){ |
| 69119 | +SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes(sqlite3_value *pVal){ |
| 68911 | 69120 | return sqlite3ValueBytes(pVal, SQLITE_UTF8); |
| 68912 | 69121 | } |
| 68913 | | -SQLITE_API int sqlite3_value_bytes16(sqlite3_value *pVal){ |
| 69122 | +SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes16(sqlite3_value *pVal){ |
| 68914 | 69123 | return sqlite3ValueBytes(pVal, SQLITE_UTF16NATIVE); |
| 68915 | 69124 | } |
| 68916 | | -SQLITE_API double sqlite3_value_double(sqlite3_value *pVal){ |
| 69125 | +SQLITE_API double SQLITE_STDCALL sqlite3_value_double(sqlite3_value *pVal){ |
| 68917 | 69126 | return sqlite3VdbeRealValue((Mem*)pVal); |
| 68918 | 69127 | } |
| 68919 | | -SQLITE_API int sqlite3_value_int(sqlite3_value *pVal){ |
| 69128 | +SQLITE_API int SQLITE_STDCALL sqlite3_value_int(sqlite3_value *pVal){ |
| 68920 | 69129 | return (int)sqlite3VdbeIntValue((Mem*)pVal); |
| 68921 | 69130 | } |
| 68922 | | -SQLITE_API sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){ |
| 69131 | +SQLITE_API sqlite_int64 SQLITE_STDCALL sqlite3_value_int64(sqlite3_value *pVal){ |
| 68923 | 69132 | return sqlite3VdbeIntValue((Mem*)pVal); |
| 68924 | 69133 | } |
| 68925 | | -SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value *pVal){ |
| 69134 | +SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_value_text(sqlite3_value *pVal){ |
| 68926 | 69135 | return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8); |
| 68927 | 69136 | } |
| 68928 | 69137 | #ifndef SQLITE_OMIT_UTF16 |
| 68929 | | -SQLITE_API const void *sqlite3_value_text16(sqlite3_value* pVal){ |
| 69138 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16(sqlite3_value* pVal){ |
| 68930 | 69139 | return sqlite3ValueText(pVal, SQLITE_UTF16NATIVE); |
| 68931 | 69140 | } |
| 68932 | | -SQLITE_API const void *sqlite3_value_text16be(sqlite3_value *pVal){ |
| 69141 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value *pVal){ |
| 68933 | 69142 | return sqlite3ValueText(pVal, SQLITE_UTF16BE); |
| 68934 | 69143 | } |
| 68935 | | -SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *pVal){ |
| 69144 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value *pVal){ |
| 68936 | 69145 | return sqlite3ValueText(pVal, SQLITE_UTF16LE); |
| 68937 | 69146 | } |
| 68938 | 69147 | #endif /* SQLITE_OMIT_UTF16 */ |
| 68939 | 69148 | /* EVIDENCE-OF: R-12793-43283 Every value in SQLite has one of five |
| 68940 | 69149 | ** fundamental datatypes: 64-bit signed integer 64-bit IEEE floating |
| 68941 | 69150 | ** point number string BLOB NULL |
| 68942 | 69151 | */ |
| 68943 | | -SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){ |
| 69152 | +SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value* pVal){ |
| 68944 | 69153 | static const u8 aType[] = { |
| 68945 | 69154 | SQLITE_BLOB, /* 0x00 */ |
| 68946 | 69155 | SQLITE_NULL, /* 0x01 */ |
| 68947 | 69156 | SQLITE_TEXT, /* 0x02 */ |
| 68948 | 69157 | SQLITE_NULL, /* 0x03 */ |
| | @@ -69014,21 +69223,21 @@ |
| 69014 | 69223 | xDel((void*)p); |
| 69015 | 69224 | } |
| 69016 | 69225 | if( pCtx ) sqlite3_result_error_toobig(pCtx); |
| 69017 | 69226 | return SQLITE_TOOBIG; |
| 69018 | 69227 | } |
| 69019 | | -SQLITE_API void sqlite3_result_blob( |
| 69228 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_blob( |
| 69020 | 69229 | sqlite3_context *pCtx, |
| 69021 | 69230 | const void *z, |
| 69022 | 69231 | int n, |
| 69023 | 69232 | void (*xDel)(void *) |
| 69024 | 69233 | ){ |
| 69025 | 69234 | assert( n>=0 ); |
| 69026 | 69235 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69027 | 69236 | setResultStrOrError(pCtx, z, n, 0, xDel); |
| 69028 | 69237 | } |
| 69029 | | -SQLITE_API void sqlite3_result_blob64( |
| 69238 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_blob64( |
| 69030 | 69239 | sqlite3_context *pCtx, |
| 69031 | 69240 | const void *z, |
| 69032 | 69241 | sqlite3_uint64 n, |
| 69033 | 69242 | void (*xDel)(void *) |
| 69034 | 69243 | ){ |
| | @@ -69038,50 +69247,50 @@ |
| 69038 | 69247 | (void)invokeValueDestructor(z, xDel, pCtx); |
| 69039 | 69248 | }else{ |
| 69040 | 69249 | setResultStrOrError(pCtx, z, (int)n, 0, xDel); |
| 69041 | 69250 | } |
| 69042 | 69251 | } |
| 69043 | | -SQLITE_API void sqlite3_result_double(sqlite3_context *pCtx, double rVal){ |
| 69252 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_double(sqlite3_context *pCtx, double rVal){ |
| 69044 | 69253 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69045 | 69254 | sqlite3VdbeMemSetDouble(pCtx->pOut, rVal); |
| 69046 | 69255 | } |
| 69047 | | -SQLITE_API void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){ |
| 69256 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){ |
| 69048 | 69257 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69049 | 69258 | pCtx->isError = SQLITE_ERROR; |
| 69050 | 69259 | pCtx->fErrorOrAux = 1; |
| 69051 | 69260 | sqlite3VdbeMemSetStr(pCtx->pOut, z, n, SQLITE_UTF8, SQLITE_TRANSIENT); |
| 69052 | 69261 | } |
| 69053 | 69262 | #ifndef SQLITE_OMIT_UTF16 |
| 69054 | | -SQLITE_API void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){ |
| 69263 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){ |
| 69055 | 69264 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69056 | 69265 | pCtx->isError = SQLITE_ERROR; |
| 69057 | 69266 | pCtx->fErrorOrAux = 1; |
| 69058 | 69267 | sqlite3VdbeMemSetStr(pCtx->pOut, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT); |
| 69059 | 69268 | } |
| 69060 | 69269 | #endif |
| 69061 | | -SQLITE_API void sqlite3_result_int(sqlite3_context *pCtx, int iVal){ |
| 69270 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_int(sqlite3_context *pCtx, int iVal){ |
| 69062 | 69271 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69063 | 69272 | sqlite3VdbeMemSetInt64(pCtx->pOut, (i64)iVal); |
| 69064 | 69273 | } |
| 69065 | | -SQLITE_API void sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){ |
| 69274 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){ |
| 69066 | 69275 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69067 | 69276 | sqlite3VdbeMemSetInt64(pCtx->pOut, iVal); |
| 69068 | 69277 | } |
| 69069 | | -SQLITE_API void sqlite3_result_null(sqlite3_context *pCtx){ |
| 69278 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_null(sqlite3_context *pCtx){ |
| 69070 | 69279 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69071 | 69280 | sqlite3VdbeMemSetNull(pCtx->pOut); |
| 69072 | 69281 | } |
| 69073 | | -SQLITE_API void sqlite3_result_text( |
| 69282 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_text( |
| 69074 | 69283 | sqlite3_context *pCtx, |
| 69075 | 69284 | const char *z, |
| 69076 | 69285 | int n, |
| 69077 | 69286 | void (*xDel)(void *) |
| 69078 | 69287 | ){ |
| 69079 | 69288 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69080 | 69289 | setResultStrOrError(pCtx, z, n, SQLITE_UTF8, xDel); |
| 69081 | 69290 | } |
| 69082 | | -SQLITE_API void sqlite3_result_text64( |
| 69291 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_text64( |
| 69083 | 69292 | sqlite3_context *pCtx, |
| 69084 | 69293 | const char *z, |
| 69085 | 69294 | sqlite3_uint64 n, |
| 69086 | 69295 | void (*xDel)(void *), |
| 69087 | 69296 | unsigned char enc |
| | @@ -69094,47 +69303,47 @@ |
| 69094 | 69303 | }else{ |
| 69095 | 69304 | setResultStrOrError(pCtx, z, (int)n, enc, xDel); |
| 69096 | 69305 | } |
| 69097 | 69306 | } |
| 69098 | 69307 | #ifndef SQLITE_OMIT_UTF16 |
| 69099 | | -SQLITE_API void sqlite3_result_text16( |
| 69308 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_text16( |
| 69100 | 69309 | sqlite3_context *pCtx, |
| 69101 | 69310 | const void *z, |
| 69102 | 69311 | int n, |
| 69103 | 69312 | void (*xDel)(void *) |
| 69104 | 69313 | ){ |
| 69105 | 69314 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69106 | 69315 | setResultStrOrError(pCtx, z, n, SQLITE_UTF16NATIVE, xDel); |
| 69107 | 69316 | } |
| 69108 | | -SQLITE_API void sqlite3_result_text16be( |
| 69317 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be( |
| 69109 | 69318 | sqlite3_context *pCtx, |
| 69110 | 69319 | const void *z, |
| 69111 | 69320 | int n, |
| 69112 | 69321 | void (*xDel)(void *) |
| 69113 | 69322 | ){ |
| 69114 | 69323 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69115 | 69324 | setResultStrOrError(pCtx, z, n, SQLITE_UTF16BE, xDel); |
| 69116 | 69325 | } |
| 69117 | | -SQLITE_API void sqlite3_result_text16le( |
| 69326 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le( |
| 69118 | 69327 | sqlite3_context *pCtx, |
| 69119 | 69328 | const void *z, |
| 69120 | 69329 | int n, |
| 69121 | 69330 | void (*xDel)(void *) |
| 69122 | 69331 | ){ |
| 69123 | 69332 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69124 | 69333 | setResultStrOrError(pCtx, z, n, SQLITE_UTF16LE, xDel); |
| 69125 | 69334 | } |
| 69126 | 69335 | #endif /* SQLITE_OMIT_UTF16 */ |
| 69127 | | -SQLITE_API void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){ |
| 69336 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){ |
| 69128 | 69337 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69129 | 69338 | sqlite3VdbeMemCopy(pCtx->pOut, pValue); |
| 69130 | 69339 | } |
| 69131 | | -SQLITE_API void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){ |
| 69340 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){ |
| 69132 | 69341 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69133 | 69342 | sqlite3VdbeMemSetZeroBlob(pCtx->pOut, n); |
| 69134 | 69343 | } |
| 69135 | | -SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ |
| 69344 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ |
| 69136 | 69345 | pCtx->isError = errCode; |
| 69137 | 69346 | pCtx->fErrorOrAux = 1; |
| 69138 | 69347 | #ifdef SQLITE_DEBUG |
| 69139 | 69348 | if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode; |
| 69140 | 69349 | #endif |
| | @@ -69143,20 +69352,20 @@ |
| 69143 | 69352 | SQLITE_UTF8, SQLITE_STATIC); |
| 69144 | 69353 | } |
| 69145 | 69354 | } |
| 69146 | 69355 | |
| 69147 | 69356 | /* Force an SQLITE_TOOBIG error. */ |
| 69148 | | -SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){ |
| 69357 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_error_toobig(sqlite3_context *pCtx){ |
| 69149 | 69358 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69150 | 69359 | pCtx->isError = SQLITE_TOOBIG; |
| 69151 | 69360 | pCtx->fErrorOrAux = 1; |
| 69152 | 69361 | sqlite3VdbeMemSetStr(pCtx->pOut, "string or blob too big", -1, |
| 69153 | 69362 | SQLITE_UTF8, SQLITE_STATIC); |
| 69154 | 69363 | } |
| 69155 | 69364 | |
| 69156 | 69365 | /* An SQLITE_NOMEM error. */ |
| 69157 | | -SQLITE_API void sqlite3_result_error_nomem(sqlite3_context *pCtx){ |
| 69366 | +SQLITE_API void SQLITE_STDCALL sqlite3_result_error_nomem(sqlite3_context *pCtx){ |
| 69158 | 69367 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69159 | 69368 | sqlite3VdbeMemSetNull(pCtx->pOut); |
| 69160 | 69369 | pCtx->isError = SQLITE_NOMEM; |
| 69161 | 69370 | pCtx->fErrorOrAux = 1; |
| 69162 | 69371 | pCtx->pOut->db->mallocFailed = 1; |
| | @@ -69325,11 +69534,11 @@ |
| 69325 | 69534 | /* |
| 69326 | 69535 | ** This is the top-level implementation of sqlite3_step(). Call |
| 69327 | 69536 | ** sqlite3Step() to do most of the work. If a schema error occurs, |
| 69328 | 69537 | ** call sqlite3Reprepare() and try again. |
| 69329 | 69538 | */ |
| 69330 | | -SQLITE_API int sqlite3_step(sqlite3_stmt *pStmt){ |
| 69539 | +SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt *pStmt){ |
| 69331 | 69540 | int rc = SQLITE_OK; /* Result from sqlite3Step() */ |
| 69332 | 69541 | int rc2 = SQLITE_OK; /* Result from sqlite3Reprepare() */ |
| 69333 | 69542 | Vdbe *v = (Vdbe*)pStmt; /* the prepared statement */ |
| 69334 | 69543 | int cnt = 0; /* Counter to prevent infinite loop of reprepares */ |
| 69335 | 69544 | sqlite3 *db; /* The database connection */ |
| | @@ -69376,11 +69585,11 @@ |
| 69376 | 69585 | |
| 69377 | 69586 | /* |
| 69378 | 69587 | ** Extract the user data from a sqlite3_context structure and return a |
| 69379 | 69588 | ** pointer to it. |
| 69380 | 69589 | */ |
| 69381 | | -SQLITE_API void *sqlite3_user_data(sqlite3_context *p){ |
| 69590 | +SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context *p){ |
| 69382 | 69591 | assert( p && p->pFunc ); |
| 69383 | 69592 | return p->pFunc->pUserData; |
| 69384 | 69593 | } |
| 69385 | 69594 | |
| 69386 | 69595 | /* |
| | @@ -69391,11 +69600,11 @@ |
| 69391 | 69600 | ** returns a copy of the pointer to the database connection (the 1st |
| 69392 | 69601 | ** parameter) of the sqlite3_create_function() and |
| 69393 | 69602 | ** sqlite3_create_function16() routines that originally registered the |
| 69394 | 69603 | ** application defined function. |
| 69395 | 69604 | */ |
| 69396 | | -SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){ |
| 69605 | +SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context *p){ |
| 69397 | 69606 | assert( p && p->pFunc ); |
| 69398 | 69607 | return p->pOut->db; |
| 69399 | 69608 | } |
| 69400 | 69609 | |
| 69401 | 69610 | /* |
| | @@ -69467,11 +69676,11 @@ |
| 69467 | 69676 | /* |
| 69468 | 69677 | ** Allocate or return the aggregate context for a user function. A new |
| 69469 | 69678 | ** context is allocated on the first call. Subsequent calls return the |
| 69470 | 69679 | ** same context that was returned on prior calls. |
| 69471 | 69680 | */ |
| 69472 | | -SQLITE_API void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){ |
| 69681 | +SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context *p, int nByte){ |
| 69473 | 69682 | assert( p && p->pFunc && p->pFunc->xStep ); |
| 69474 | 69683 | assert( sqlite3_mutex_held(p->pOut->db->mutex) ); |
| 69475 | 69684 | testcase( nByte<0 ); |
| 69476 | 69685 | if( (p->pMem->flags & MEM_Agg)==0 ){ |
| 69477 | 69686 | return createAggContext(p, nByte); |
| | @@ -69482,11 +69691,11 @@ |
| 69482 | 69691 | |
| 69483 | 69692 | /* |
| 69484 | 69693 | ** Return the auxiliary data pointer, if any, for the iArg'th argument to |
| 69485 | 69694 | ** the user-function defined by pCtx. |
| 69486 | 69695 | */ |
| 69487 | | -SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){ |
| 69696 | +SQLITE_API void *SQLITE_STDCALL sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){ |
| 69488 | 69697 | AuxData *pAuxData; |
| 69489 | 69698 | |
| 69490 | 69699 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 69491 | 69700 | #if SQLITE_ENABLE_STAT3_OR_STAT4 |
| 69492 | 69701 | if( pCtx->pVdbe==0 ) return 0; |
| | @@ -69503,11 +69712,11 @@ |
| 69503 | 69712 | /* |
| 69504 | 69713 | ** Set the auxiliary data pointer and delete function, for the iArg'th |
| 69505 | 69714 | ** argument to the user-function defined by pCtx. Any previous value is |
| 69506 | 69715 | ** deleted by calling the delete function specified when it was set. |
| 69507 | 69716 | */ |
| 69508 | | -SQLITE_API void sqlite3_set_auxdata( |
| 69717 | +SQLITE_API void SQLITE_STDCALL sqlite3_set_auxdata( |
| 69509 | 69718 | sqlite3_context *pCtx, |
| 69510 | 69719 | int iArg, |
| 69511 | 69720 | void *pAux, |
| 69512 | 69721 | void (*xDelete)(void*) |
| 69513 | 69722 | ){ |
| | @@ -69558,29 +69767,29 @@ |
| 69558 | 69767 | ** This function is deprecated. Do not use it for new code. It is |
| 69559 | 69768 | ** provide only to avoid breaking legacy code. New aggregate function |
| 69560 | 69769 | ** implementations should keep their own counts within their aggregate |
| 69561 | 69770 | ** context. |
| 69562 | 69771 | */ |
| 69563 | | -SQLITE_API int sqlite3_aggregate_count(sqlite3_context *p){ |
| 69772 | +SQLITE_API int SQLITE_STDCALL sqlite3_aggregate_count(sqlite3_context *p){ |
| 69564 | 69773 | assert( p && p->pMem && p->pFunc && p->pFunc->xStep ); |
| 69565 | 69774 | return p->pMem->n; |
| 69566 | 69775 | } |
| 69567 | 69776 | #endif |
| 69568 | 69777 | |
| 69569 | 69778 | /* |
| 69570 | 69779 | ** Return the number of columns in the result set for the statement pStmt. |
| 69571 | 69780 | */ |
| 69572 | | -SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt){ |
| 69781 | +SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt){ |
| 69573 | 69782 | Vdbe *pVm = (Vdbe *)pStmt; |
| 69574 | 69783 | return pVm ? pVm->nResColumn : 0; |
| 69575 | 69784 | } |
| 69576 | 69785 | |
| 69577 | 69786 | /* |
| 69578 | 69787 | ** Return the number of values available from the current row of the |
| 69579 | 69788 | ** currently executing statement pStmt. |
| 69580 | 69789 | */ |
| 69581 | | -SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt){ |
| 69790 | +SQLITE_API int SQLITE_STDCALL sqlite3_data_count(sqlite3_stmt *pStmt){ |
| 69582 | 69791 | Vdbe *pVm = (Vdbe *)pStmt; |
| 69583 | 69792 | if( pVm==0 || pVm->pResultSet==0 ) return 0; |
| 69584 | 69793 | return pVm->nResColumn; |
| 69585 | 69794 | } |
| 69586 | 69795 | |
| | @@ -69678,67 +69887,67 @@ |
| 69678 | 69887 | |
| 69679 | 69888 | /**************************** sqlite3_column_ ******************************* |
| 69680 | 69889 | ** The following routines are used to access elements of the current row |
| 69681 | 69890 | ** in the result set. |
| 69682 | 69891 | */ |
| 69683 | | -SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int i){ |
| 69892 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_column_blob(sqlite3_stmt *pStmt, int i){ |
| 69684 | 69893 | const void *val; |
| 69685 | 69894 | val = sqlite3_value_blob( columnMem(pStmt,i) ); |
| 69686 | 69895 | /* Even though there is no encoding conversion, value_blob() might |
| 69687 | 69896 | ** need to call malloc() to expand the result of a zeroblob() |
| 69688 | 69897 | ** expression. |
| 69689 | 69898 | */ |
| 69690 | 69899 | columnMallocFailure(pStmt); |
| 69691 | 69900 | return val; |
| 69692 | 69901 | } |
| 69693 | | -SQLITE_API int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){ |
| 69902 | +SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){ |
| 69694 | 69903 | int val = sqlite3_value_bytes( columnMem(pStmt,i) ); |
| 69695 | 69904 | columnMallocFailure(pStmt); |
| 69696 | 69905 | return val; |
| 69697 | 69906 | } |
| 69698 | | -SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){ |
| 69907 | +SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){ |
| 69699 | 69908 | int val = sqlite3_value_bytes16( columnMem(pStmt,i) ); |
| 69700 | 69909 | columnMallocFailure(pStmt); |
| 69701 | 69910 | return val; |
| 69702 | 69911 | } |
| 69703 | | -SQLITE_API double sqlite3_column_double(sqlite3_stmt *pStmt, int i){ |
| 69912 | +SQLITE_API double SQLITE_STDCALL sqlite3_column_double(sqlite3_stmt *pStmt, int i){ |
| 69704 | 69913 | double val = sqlite3_value_double( columnMem(pStmt,i) ); |
| 69705 | 69914 | columnMallocFailure(pStmt); |
| 69706 | 69915 | return val; |
| 69707 | 69916 | } |
| 69708 | | -SQLITE_API int sqlite3_column_int(sqlite3_stmt *pStmt, int i){ |
| 69917 | +SQLITE_API int SQLITE_STDCALL sqlite3_column_int(sqlite3_stmt *pStmt, int i){ |
| 69709 | 69918 | int val = sqlite3_value_int( columnMem(pStmt,i) ); |
| 69710 | 69919 | columnMallocFailure(pStmt); |
| 69711 | 69920 | return val; |
| 69712 | 69921 | } |
| 69713 | | -SQLITE_API sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){ |
| 69922 | +SQLITE_API sqlite_int64 SQLITE_STDCALL sqlite3_column_int64(sqlite3_stmt *pStmt, int i){ |
| 69714 | 69923 | sqlite_int64 val = sqlite3_value_int64( columnMem(pStmt,i) ); |
| 69715 | 69924 | columnMallocFailure(pStmt); |
| 69716 | 69925 | return val; |
| 69717 | 69926 | } |
| 69718 | | -SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){ |
| 69927 | +SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_column_text(sqlite3_stmt *pStmt, int i){ |
| 69719 | 69928 | const unsigned char *val = sqlite3_value_text( columnMem(pStmt,i) ); |
| 69720 | 69929 | columnMallocFailure(pStmt); |
| 69721 | 69930 | return val; |
| 69722 | 69931 | } |
| 69723 | | -SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){ |
| 69932 | +SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt *pStmt, int i){ |
| 69724 | 69933 | Mem *pOut = columnMem(pStmt, i); |
| 69725 | 69934 | if( pOut->flags&MEM_Static ){ |
| 69726 | 69935 | pOut->flags &= ~MEM_Static; |
| 69727 | 69936 | pOut->flags |= MEM_Ephem; |
| 69728 | 69937 | } |
| 69729 | 69938 | columnMallocFailure(pStmt); |
| 69730 | 69939 | return (sqlite3_value *)pOut; |
| 69731 | 69940 | } |
| 69732 | 69941 | #ifndef SQLITE_OMIT_UTF16 |
| 69733 | | -SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){ |
| 69942 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_column_text16(sqlite3_stmt *pStmt, int i){ |
| 69734 | 69943 | const void *val = sqlite3_value_text16( columnMem(pStmt,i) ); |
| 69735 | 69944 | columnMallocFailure(pStmt); |
| 69736 | 69945 | return val; |
| 69737 | 69946 | } |
| 69738 | 69947 | #endif /* SQLITE_OMIT_UTF16 */ |
| 69739 | | -SQLITE_API int sqlite3_column_type(sqlite3_stmt *pStmt, int i){ |
| 69948 | +SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt *pStmt, int i){ |
| 69740 | 69949 | int iType = sqlite3_value_type( columnMem(pStmt,i) ); |
| 69741 | 69950 | columnMallocFailure(pStmt); |
| 69742 | 69951 | return iType; |
| 69743 | 69952 | } |
| 69744 | 69953 | |
| | @@ -69798,16 +70007,16 @@ |
| 69798 | 70007 | |
| 69799 | 70008 | /* |
| 69800 | 70009 | ** Return the name of the Nth column of the result set returned by SQL |
| 69801 | 70010 | ** statement pStmt. |
| 69802 | 70011 | */ |
| 69803 | | -SQLITE_API const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){ |
| 70012 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt *pStmt, int N){ |
| 69804 | 70013 | return columnName( |
| 69805 | 70014 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME); |
| 69806 | 70015 | } |
| 69807 | 70016 | #ifndef SQLITE_OMIT_UTF16 |
| 69808 | | -SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){ |
| 70017 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt *pStmt, int N){ |
| 69809 | 70018 | return columnName( |
| 69810 | 70019 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME); |
| 69811 | 70020 | } |
| 69812 | 70021 | #endif |
| 69813 | 70022 | |
| | @@ -69823,16 +70032,16 @@ |
| 69823 | 70032 | #ifndef SQLITE_OMIT_DECLTYPE |
| 69824 | 70033 | /* |
| 69825 | 70034 | ** Return the column declaration type (if applicable) of the 'i'th column |
| 69826 | 70035 | ** of the result set of SQL statement pStmt. |
| 69827 | 70036 | */ |
| 69828 | | -SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){ |
| 70037 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){ |
| 69829 | 70038 | return columnName( |
| 69830 | 70039 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE); |
| 69831 | 70040 | } |
| 69832 | 70041 | #ifndef SQLITE_OMIT_UTF16 |
| 69833 | | -SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){ |
| 70042 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){ |
| 69834 | 70043 | return columnName( |
| 69835 | 70044 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE); |
| 69836 | 70045 | } |
| 69837 | 70046 | #endif /* SQLITE_OMIT_UTF16 */ |
| 69838 | 70047 | #endif /* SQLITE_OMIT_DECLTYPE */ |
| | @@ -69841,16 +70050,16 @@ |
| 69841 | 70050 | /* |
| 69842 | 70051 | ** Return the name of the database from which a result column derives. |
| 69843 | 70052 | ** NULL is returned if the result column is an expression or constant or |
| 69844 | 70053 | ** anything else which is not an unambiguous reference to a database column. |
| 69845 | 70054 | */ |
| 69846 | | -SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){ |
| 70055 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){ |
| 69847 | 70056 | return columnName( |
| 69848 | 70057 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE); |
| 69849 | 70058 | } |
| 69850 | 70059 | #ifndef SQLITE_OMIT_UTF16 |
| 69851 | | -SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){ |
| 70060 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){ |
| 69852 | 70061 | return columnName( |
| 69853 | 70062 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE); |
| 69854 | 70063 | } |
| 69855 | 70064 | #endif /* SQLITE_OMIT_UTF16 */ |
| 69856 | 70065 | |
| | @@ -69857,16 +70066,16 @@ |
| 69857 | 70066 | /* |
| 69858 | 70067 | ** Return the name of the table from which a result column derives. |
| 69859 | 70068 | ** NULL is returned if the result column is an expression or constant or |
| 69860 | 70069 | ** anything else which is not an unambiguous reference to a database column. |
| 69861 | 70070 | */ |
| 69862 | | -SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){ |
| 70071 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){ |
| 69863 | 70072 | return columnName( |
| 69864 | 70073 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE); |
| 69865 | 70074 | } |
| 69866 | 70075 | #ifndef SQLITE_OMIT_UTF16 |
| 69867 | | -SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){ |
| 70076 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){ |
| 69868 | 70077 | return columnName( |
| 69869 | 70078 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE); |
| 69870 | 70079 | } |
| 69871 | 70080 | #endif /* SQLITE_OMIT_UTF16 */ |
| 69872 | 70081 | |
| | @@ -69873,16 +70082,16 @@ |
| 69873 | 70082 | /* |
| 69874 | 70083 | ** Return the name of the table column from which a result column derives. |
| 69875 | 70084 | ** NULL is returned if the result column is an expression or constant or |
| 69876 | 70085 | ** anything else which is not an unambiguous reference to a database column. |
| 69877 | 70086 | */ |
| 69878 | | -SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){ |
| 70087 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){ |
| 69879 | 70088 | return columnName( |
| 69880 | 70089 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN); |
| 69881 | 70090 | } |
| 69882 | 70091 | #ifndef SQLITE_OMIT_UTF16 |
| 69883 | | -SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){ |
| 70092 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){ |
| 69884 | 70093 | return columnName( |
| 69885 | 70094 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN); |
| 69886 | 70095 | } |
| 69887 | 70096 | #endif /* SQLITE_OMIT_UTF16 */ |
| 69888 | 70097 | #endif /* SQLITE_ENABLE_COLUMN_METADATA */ |
| | @@ -69979,20 +70188,20 @@ |
| 69979 | 70188 | |
| 69980 | 70189 | |
| 69981 | 70190 | /* |
| 69982 | 70191 | ** Bind a blob value to an SQL statement variable. |
| 69983 | 70192 | */ |
| 69984 | | -SQLITE_API int sqlite3_bind_blob( |
| 70193 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob( |
| 69985 | 70194 | sqlite3_stmt *pStmt, |
| 69986 | 70195 | int i, |
| 69987 | 70196 | const void *zData, |
| 69988 | 70197 | int nData, |
| 69989 | 70198 | void (*xDel)(void*) |
| 69990 | 70199 | ){ |
| 69991 | 70200 | return bindText(pStmt, i, zData, nData, xDel, 0); |
| 69992 | 70201 | } |
| 69993 | | -SQLITE_API int sqlite3_bind_blob64( |
| 70202 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob64( |
| 69994 | 70203 | sqlite3_stmt *pStmt, |
| 69995 | 70204 | int i, |
| 69996 | 70205 | const void *zData, |
| 69997 | 70206 | sqlite3_uint64 nData, |
| 69998 | 70207 | void (*xDel)(void*) |
| | @@ -70002,52 +70211,52 @@ |
| 70002 | 70211 | return invokeValueDestructor(zData, xDel, 0); |
| 70003 | 70212 | }else{ |
| 70004 | 70213 | return bindText(pStmt, i, zData, (int)nData, xDel, 0); |
| 70005 | 70214 | } |
| 70006 | 70215 | } |
| 70007 | | -SQLITE_API int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){ |
| 70216 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){ |
| 70008 | 70217 | int rc; |
| 70009 | 70218 | Vdbe *p = (Vdbe *)pStmt; |
| 70010 | 70219 | rc = vdbeUnbind(p, i); |
| 70011 | 70220 | if( rc==SQLITE_OK ){ |
| 70012 | 70221 | sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue); |
| 70013 | 70222 | sqlite3_mutex_leave(p->db->mutex); |
| 70014 | 70223 | } |
| 70015 | 70224 | return rc; |
| 70016 | 70225 | } |
| 70017 | | -SQLITE_API int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){ |
| 70226 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){ |
| 70018 | 70227 | return sqlite3_bind_int64(p, i, (i64)iValue); |
| 70019 | 70228 | } |
| 70020 | | -SQLITE_API int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){ |
| 70229 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){ |
| 70021 | 70230 | int rc; |
| 70022 | 70231 | Vdbe *p = (Vdbe *)pStmt; |
| 70023 | 70232 | rc = vdbeUnbind(p, i); |
| 70024 | 70233 | if( rc==SQLITE_OK ){ |
| 70025 | 70234 | sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue); |
| 70026 | 70235 | sqlite3_mutex_leave(p->db->mutex); |
| 70027 | 70236 | } |
| 70028 | 70237 | return rc; |
| 70029 | 70238 | } |
| 70030 | | -SQLITE_API int sqlite3_bind_null(sqlite3_stmt *pStmt, int i){ |
| 70239 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_null(sqlite3_stmt *pStmt, int i){ |
| 70031 | 70240 | int rc; |
| 70032 | 70241 | Vdbe *p = (Vdbe*)pStmt; |
| 70033 | 70242 | rc = vdbeUnbind(p, i); |
| 70034 | 70243 | if( rc==SQLITE_OK ){ |
| 70035 | 70244 | sqlite3_mutex_leave(p->db->mutex); |
| 70036 | 70245 | } |
| 70037 | 70246 | return rc; |
| 70038 | 70247 | } |
| 70039 | | -SQLITE_API int sqlite3_bind_text( |
| 70248 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_text( |
| 70040 | 70249 | sqlite3_stmt *pStmt, |
| 70041 | 70250 | int i, |
| 70042 | 70251 | const char *zData, |
| 70043 | 70252 | int nData, |
| 70044 | 70253 | void (*xDel)(void*) |
| 70045 | 70254 | ){ |
| 70046 | 70255 | return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8); |
| 70047 | 70256 | } |
| 70048 | | -SQLITE_API int sqlite3_bind_text64( |
| 70257 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64( |
| 70049 | 70258 | sqlite3_stmt *pStmt, |
| 70050 | 70259 | int i, |
| 70051 | 70260 | const char *zData, |
| 70052 | 70261 | sqlite3_uint64 nData, |
| 70053 | 70262 | void (*xDel)(void*), |
| | @@ -70060,21 +70269,21 @@ |
| 70060 | 70269 | if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE; |
| 70061 | 70270 | return bindText(pStmt, i, zData, (int)nData, xDel, enc); |
| 70062 | 70271 | } |
| 70063 | 70272 | } |
| 70064 | 70273 | #ifndef SQLITE_OMIT_UTF16 |
| 70065 | | -SQLITE_API int sqlite3_bind_text16( |
| 70274 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16( |
| 70066 | 70275 | sqlite3_stmt *pStmt, |
| 70067 | 70276 | int i, |
| 70068 | 70277 | const void *zData, |
| 70069 | 70278 | int nData, |
| 70070 | 70279 | void (*xDel)(void*) |
| 70071 | 70280 | ){ |
| 70072 | 70281 | return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE); |
| 70073 | 70282 | } |
| 70074 | 70283 | #endif /* SQLITE_OMIT_UTF16 */ |
| 70075 | | -SQLITE_API int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){ |
| 70284 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){ |
| 70076 | 70285 | int rc; |
| 70077 | 70286 | switch( sqlite3_value_type((sqlite3_value*)pValue) ){ |
| 70078 | 70287 | case SQLITE_INTEGER: { |
| 70079 | 70288 | rc = sqlite3_bind_int64(pStmt, i, pValue->u.i); |
| 70080 | 70289 | break; |
| | @@ -70101,11 +70310,11 @@ |
| 70101 | 70310 | break; |
| 70102 | 70311 | } |
| 70103 | 70312 | } |
| 70104 | 70313 | return rc; |
| 70105 | 70314 | } |
| 70106 | | -SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){ |
| 70315 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){ |
| 70107 | 70316 | int rc; |
| 70108 | 70317 | Vdbe *p = (Vdbe *)pStmt; |
| 70109 | 70318 | rc = vdbeUnbind(p, i); |
| 70110 | 70319 | if( rc==SQLITE_OK ){ |
| 70111 | 70320 | sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n); |
| | @@ -70116,11 +70325,11 @@ |
| 70116 | 70325 | |
| 70117 | 70326 | /* |
| 70118 | 70327 | ** Return the number of wildcards that can be potentially bound to. |
| 70119 | 70328 | ** This routine is added to support DBD::SQLite. |
| 70120 | 70329 | */ |
| 70121 | | -SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){ |
| 70330 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){ |
| 70122 | 70331 | Vdbe *p = (Vdbe*)pStmt; |
| 70123 | 70332 | return p ? p->nVar : 0; |
| 70124 | 70333 | } |
| 70125 | 70334 | |
| 70126 | 70335 | /* |
| | @@ -70127,11 +70336,11 @@ |
| 70127 | 70336 | ** Return the name of a wildcard parameter. Return NULL if the index |
| 70128 | 70337 | ** is out of range or if the wildcard is unnamed. |
| 70129 | 70338 | ** |
| 70130 | 70339 | ** The result is always UTF-8. |
| 70131 | 70340 | */ |
| 70132 | | -SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){ |
| 70341 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){ |
| 70133 | 70342 | Vdbe *p = (Vdbe*)pStmt; |
| 70134 | 70343 | if( p==0 || i<1 || i>p->nzVar ){ |
| 70135 | 70344 | return 0; |
| 70136 | 70345 | } |
| 70137 | 70346 | return p->azVar[i-1]; |
| | @@ -70155,11 +70364,11 @@ |
| 70155 | 70364 | } |
| 70156 | 70365 | } |
| 70157 | 70366 | } |
| 70158 | 70367 | return 0; |
| 70159 | 70368 | } |
| 70160 | | -SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){ |
| 70369 | +SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){ |
| 70161 | 70370 | return sqlite3VdbeParameterIndex((Vdbe*)pStmt, zName, sqlite3Strlen30(zName)); |
| 70162 | 70371 | } |
| 70163 | 70372 | |
| 70164 | 70373 | /* |
| 70165 | 70374 | ** Transfer all bindings from the first statement over to the second. |
| | @@ -70189,11 +70398,11 @@ |
| 70189 | 70398 | ** |
| 70190 | 70399 | ** If the two statements contain a different number of bindings, then |
| 70191 | 70400 | ** an SQLITE_ERROR is returned. Nothing else can go wrong, so otherwise |
| 70192 | 70401 | ** SQLITE_OK is returned. |
| 70193 | 70402 | */ |
| 70194 | | -SQLITE_API int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){ |
| 70403 | +SQLITE_API int SQLITE_STDCALL sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){ |
| 70195 | 70404 | Vdbe *pFrom = (Vdbe*)pFromStmt; |
| 70196 | 70405 | Vdbe *pTo = (Vdbe*)pToStmt; |
| 70197 | 70406 | if( pFrom->nVar!=pTo->nVar ){ |
| 70198 | 70407 | return SQLITE_ERROR; |
| 70199 | 70408 | } |
| | @@ -70211,26 +70420,26 @@ |
| 70211 | 70420 | ** Return the sqlite3* database handle to which the prepared statement given |
| 70212 | 70421 | ** in the argument belongs. This is the same database handle that was |
| 70213 | 70422 | ** the first argument to the sqlite3_prepare() that was used to create |
| 70214 | 70423 | ** the statement in the first place. |
| 70215 | 70424 | */ |
| 70216 | | -SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){ |
| 70425 | +SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt *pStmt){ |
| 70217 | 70426 | return pStmt ? ((Vdbe*)pStmt)->db : 0; |
| 70218 | 70427 | } |
| 70219 | 70428 | |
| 70220 | 70429 | /* |
| 70221 | 70430 | ** Return true if the prepared statement is guaranteed to not modify the |
| 70222 | 70431 | ** database. |
| 70223 | 70432 | */ |
| 70224 | | -SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){ |
| 70433 | +SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt){ |
| 70225 | 70434 | return pStmt ? ((Vdbe*)pStmt)->readOnly : 1; |
| 70226 | 70435 | } |
| 70227 | 70436 | |
| 70228 | 70437 | /* |
| 70229 | 70438 | ** Return true if the prepared statement is in need of being reset. |
| 70230 | 70439 | */ |
| 70231 | | -SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){ |
| 70440 | +SQLITE_API int SQLITE_STDCALL sqlite3_stmt_busy(sqlite3_stmt *pStmt){ |
| 70232 | 70441 | Vdbe *v = (Vdbe*)pStmt; |
| 70233 | 70442 | return v!=0 && v->pc>=0 && v->magic==VDBE_MAGIC_RUN; |
| 70234 | 70443 | } |
| 70235 | 70444 | |
| 70236 | 70445 | /* |
| | @@ -70237,11 +70446,11 @@ |
| 70237 | 70446 | ** Return a pointer to the next prepared statement after pStmt associated |
| 70238 | 70447 | ** with database connection pDb. If pStmt is NULL, return the first |
| 70239 | 70448 | ** prepared statement for the database connection. Return NULL if there |
| 70240 | 70449 | ** are no more. |
| 70241 | 70450 | */ |
| 70242 | | -SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){ |
| 70451 | +SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){ |
| 70243 | 70452 | sqlite3_stmt *pNext; |
| 70244 | 70453 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 70245 | 70454 | if( !sqlite3SafetyCheckOk(pDb) ){ |
| 70246 | 70455 | (void)SQLITE_MISUSE_BKPT; |
| 70247 | 70456 | return 0; |
| | @@ -70258,11 +70467,11 @@ |
| 70258 | 70467 | } |
| 70259 | 70468 | |
| 70260 | 70469 | /* |
| 70261 | 70470 | ** Return the value of a status counter for a prepared statement |
| 70262 | 70471 | */ |
| 70263 | | -SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ |
| 70472 | +SQLITE_API int SQLITE_STDCALL sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ |
| 70264 | 70473 | Vdbe *pVdbe = (Vdbe*)pStmt; |
| 70265 | 70474 | u32 v; |
| 70266 | 70475 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 70267 | 70476 | if( !pStmt ){ |
| 70268 | 70477 | (void)SQLITE_MISUSE_BKPT; |
| | @@ -70276,11 +70485,11 @@ |
| 70276 | 70485 | |
| 70277 | 70486 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 70278 | 70487 | /* |
| 70279 | 70488 | ** Return status data for a single loop within query pStmt. |
| 70280 | 70489 | */ |
| 70281 | | -SQLITE_API int sqlite3_stmt_scanstatus( |
| 70490 | +SQLITE_API int SQLITE_STDCALL sqlite3_stmt_scanstatus( |
| 70282 | 70491 | sqlite3_stmt *pStmt, /* Prepared statement being queried */ |
| 70283 | 70492 | int idx, /* Index of loop to report on */ |
| 70284 | 70493 | int iScanStatusOp, /* Which metric to return */ |
| 70285 | 70494 | void *pOut /* OUT: Write the answer here */ |
| 70286 | 70495 | ){ |
| | @@ -70335,11 +70544,11 @@ |
| 70335 | 70544 | } |
| 70336 | 70545 | |
| 70337 | 70546 | /* |
| 70338 | 70547 | ** Zero all counters associated with the sqlite3_stmt_scanstatus() data. |
| 70339 | 70548 | */ |
| 70340 | | -SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){ |
| 70549 | +SQLITE_API void SQLITE_STDCALL sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){ |
| 70341 | 70550 | Vdbe *p = (Vdbe*)pStmt; |
| 70342 | 70551 | memset(p->anExec, 0, p->nOp * sizeof(i64)); |
| 70343 | 70552 | } |
| 70344 | 70553 | #endif /* SQLITE_ENABLE_STMT_SCANSTATUS */ |
| 70345 | 70554 | |
| | @@ -70427,21 +70636,22 @@ |
| 70427 | 70636 | Mem *pVar; /* Value of a host parameter */ |
| 70428 | 70637 | StrAccum out; /* Accumulate the output here */ |
| 70429 | 70638 | char zBase[100]; /* Initial working space */ |
| 70430 | 70639 | |
| 70431 | 70640 | db = p->db; |
| 70432 | | - sqlite3StrAccumInit(&out, zBase, sizeof(zBase), |
| 70641 | + sqlite3StrAccumInit(&out, db, zBase, sizeof(zBase), |
| 70433 | 70642 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 70434 | | - out.db = db; |
| 70435 | 70643 | if( db->nVdbeExec>1 ){ |
| 70436 | 70644 | while( *zRawSql ){ |
| 70437 | 70645 | const char *zStart = zRawSql; |
| 70438 | 70646 | while( *(zRawSql++)!='\n' && *zRawSql ); |
| 70439 | 70647 | sqlite3StrAccumAppend(&out, "-- ", 3); |
| 70440 | 70648 | assert( (zRawSql - zStart) > 0 ); |
| 70441 | 70649 | sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart)); |
| 70442 | 70650 | } |
| 70651 | + }else if( p->nVar==0 ){ |
| 70652 | + sqlite3StrAccumAppend(&out, zRawSql, sqlite3Strlen30(zRawSql)); |
| 70443 | 70653 | }else{ |
| 70444 | 70654 | while( zRawSql[0] ){ |
| 70445 | 70655 | n = findNextHostParameter(zRawSql, &nToken); |
| 70446 | 70656 | assert( n>0 ); |
| 70447 | 70657 | sqlite3StrAccumAppend(&out, zRawSql, n); |
| | @@ -70454,14 +70664,16 @@ |
| 70454 | 70664 | sqlite3GetInt32(&zRawSql[1], &idx); |
| 70455 | 70665 | }else{ |
| 70456 | 70666 | idx = nextIndex; |
| 70457 | 70667 | } |
| 70458 | 70668 | }else{ |
| 70459 | | - assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' ); |
| 70669 | + assert( zRawSql[0]==':' || zRawSql[0]=='$' || |
| 70670 | + zRawSql[0]=='@' || zRawSql[0]=='#' ); |
| 70460 | 70671 | testcase( zRawSql[0]==':' ); |
| 70461 | 70672 | testcase( zRawSql[0]=='$' ); |
| 70462 | 70673 | testcase( zRawSql[0]=='@' ); |
| 70674 | + testcase( zRawSql[0]=='#' ); |
| 70463 | 70675 | idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken); |
| 70464 | 70676 | assert( idx>0 ); |
| 70465 | 70677 | } |
| 70466 | 70678 | zRawSql += nToken; |
| 70467 | 70679 | nextIndex = idx + 1; |
| | @@ -70834,11 +71046,11 @@ |
| 70834 | 71046 | ** Try to convert the type of a function argument or a result column |
| 70835 | 71047 | ** into a numeric representation. Use either INTEGER or REAL whichever |
| 70836 | 71048 | ** is appropriate. But only do the conversion if it is possible without |
| 70837 | 71049 | ** loss of information and return the revised type of the argument. |
| 70838 | 71050 | */ |
| 70839 | | -SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){ |
| 71051 | +SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value *pVal){ |
| 70840 | 71052 | int eType = sqlite3_value_type(pVal); |
| 70841 | 71053 | if( eType==SQLITE_TEXT ){ |
| 70842 | 71054 | Mem *pMem = (Mem*)pVal; |
| 70843 | 71055 | applyNumericAffinity(pMem, 0); |
| 70844 | 71056 | eType = sqlite3_value_type(pVal); |
| | @@ -71132,21 +71344,38 @@ |
| 71132 | 71344 | assert( n==(db->nSavepoint + db->isTransactionSavepoint) ); |
| 71133 | 71345 | return 1; |
| 71134 | 71346 | } |
| 71135 | 71347 | #endif |
| 71136 | 71348 | |
| 71349 | +/* |
| 71350 | +** Return the register of pOp->p2 after first preparing it to be |
| 71351 | +** overwritten with an integer value. |
| 71352 | +*/ |
| 71353 | +static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){ |
| 71354 | + Mem *pOut; |
| 71355 | + assert( pOp->p2>0 ); |
| 71356 | + assert( pOp->p2<=(p->nMem-p->nCursor) ); |
| 71357 | + pOut = &p->aMem[pOp->p2]; |
| 71358 | + memAboutToChange(p, pOut); |
| 71359 | + if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut); |
| 71360 | + pOut->flags = MEM_Int; |
| 71361 | + return pOut; |
| 71362 | +} |
| 71363 | + |
| 71137 | 71364 | |
| 71138 | 71365 | /* |
| 71139 | 71366 | ** Execute as much of a VDBE program as we can. |
| 71140 | 71367 | ** This is the core of sqlite3_step(). |
| 71141 | 71368 | */ |
| 71142 | 71369 | SQLITE_PRIVATE int sqlite3VdbeExec( |
| 71143 | 71370 | Vdbe *p /* The VDBE */ |
| 71144 | 71371 | ){ |
| 71145 | | - int pc=0; /* The program counter */ |
| 71146 | 71372 | Op *aOp = p->aOp; /* Copy of p->aOp */ |
| 71147 | | - Op *pOp; /* Current operation */ |
| 71373 | + Op *pOp = aOp; /* Current operation */ |
| 71374 | +#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 71375 | + Op *pOrigOp; /* Value of pOp at the top of the loop */ |
| 71376 | +#endif |
| 71148 | 71377 | int rc = SQLITE_OK; /* Value to return */ |
| 71149 | 71378 | sqlite3 *db = p->db; /* The database */ |
| 71150 | 71379 | u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ |
| 71151 | 71380 | u8 encoding = ENC(db); /* The database encoding */ |
| 71152 | 71381 | int iCompare = 0; /* Result of last OP_Compare operation */ |
| | @@ -71218,27 +71447,26 @@ |
| 71218 | 71447 | } |
| 71219 | 71448 | if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n"); |
| 71220 | 71449 | } |
| 71221 | 71450 | sqlite3EndBenignMalloc(); |
| 71222 | 71451 | #endif |
| 71223 | | - for(pc=p->pc; rc==SQLITE_OK; pc++){ |
| 71224 | | - assert( pc>=0 && pc<p->nOp ); |
| 71452 | + for(pOp=&aOp[p->pc]; rc==SQLITE_OK; pOp++){ |
| 71453 | + assert( pOp>=aOp && pOp<&aOp[p->nOp]); |
| 71225 | 71454 | if( db->mallocFailed ) goto no_mem; |
| 71226 | 71455 | #ifdef VDBE_PROFILE |
| 71227 | 71456 | start = sqlite3Hwtime(); |
| 71228 | 71457 | #endif |
| 71229 | 71458 | nVmStep++; |
| 71230 | | - pOp = &aOp[pc]; |
| 71231 | 71459 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 71232 | | - if( p->anExec ) p->anExec[pc]++; |
| 71460 | + if( p->anExec ) p->anExec[(int)(pOp-aOp)]++; |
| 71233 | 71461 | #endif |
| 71234 | 71462 | |
| 71235 | 71463 | /* Only allow tracing if SQLITE_DEBUG is defined. |
| 71236 | 71464 | */ |
| 71237 | 71465 | #ifdef SQLITE_DEBUG |
| 71238 | 71466 | if( db->flags & SQLITE_VdbeTrace ){ |
| 71239 | | - sqlite3VdbePrintOp(stdout, pc, pOp); |
| 71467 | + sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp); |
| 71240 | 71468 | } |
| 71241 | 71469 | #endif |
| 71242 | 71470 | |
| 71243 | 71471 | |
| 71244 | 71472 | /* Check to see if we need to simulate an interrupt. This only happens |
| | @@ -71251,27 +71479,13 @@ |
| 71251 | 71479 | sqlite3_interrupt(db); |
| 71252 | 71480 | } |
| 71253 | 71481 | } |
| 71254 | 71482 | #endif |
| 71255 | 71483 | |
| 71256 | | - /* On any opcode with the "out2-prerelease" tag, free any |
| 71257 | | - ** external allocations out of mem[p2] and set mem[p2] to be |
| 71258 | | - ** an undefined integer. Opcodes will either fill in the integer |
| 71259 | | - ** value or convert mem[p2] to a different type. |
| 71260 | | - */ |
| 71261 | | - assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] ); |
| 71262 | | - if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){ |
| 71263 | | - assert( pOp->p2>0 ); |
| 71264 | | - assert( pOp->p2<=(p->nMem-p->nCursor) ); |
| 71265 | | - pOut = &aMem[pOp->p2]; |
| 71266 | | - memAboutToChange(p, pOut); |
| 71267 | | - if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut); |
| 71268 | | - pOut->flags = MEM_Int; |
| 71269 | | - } |
| 71270 | | - |
| 71271 | 71484 | /* Sanity checking on other operands */ |
| 71272 | 71485 | #ifdef SQLITE_DEBUG |
| 71486 | + assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] ); |
| 71273 | 71487 | if( (pOp->opflags & OPFLG_IN1)!=0 ){ |
| 71274 | 71488 | assert( pOp->p1>0 ); |
| 71275 | 71489 | assert( pOp->p1<=(p->nMem-p->nCursor) ); |
| 71276 | 71490 | assert( memIsValid(&aMem[pOp->p1]) ); |
| 71277 | 71491 | assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) ); |
| | @@ -71300,10 +71514,13 @@ |
| 71300 | 71514 | assert( pOp->p3>0 ); |
| 71301 | 71515 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 71302 | 71516 | memAboutToChange(p, &aMem[pOp->p3]); |
| 71303 | 71517 | } |
| 71304 | 71518 | #endif |
| 71519 | +#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 71520 | + pOrigOp = pOp; |
| 71521 | +#endif |
| 71305 | 71522 | |
| 71306 | 71523 | switch( pOp->opcode ){ |
| 71307 | 71524 | |
| 71308 | 71525 | /***************************************************************************** |
| 71309 | 71526 | ** What follows is a massive switch statement where each case implements a |
| | @@ -71323,11 +71540,11 @@ |
| 71323 | 71540 | ** case statement is followed by a comment of the form "/# same as ... #/" |
| 71324 | 71541 | ** that comment is used to determine the particular value of the opcode. |
| 71325 | 71542 | ** |
| 71326 | 71543 | ** Other keywords in the comment that follows each case are used to |
| 71327 | 71544 | ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[]. |
| 71328 | | -** Keywords include: in1, in2, in3, out2_prerelease, out2, out3. See |
| 71545 | +** Keywords include: in1, in2, in3, out2, out3. See |
| 71329 | 71546 | ** the mkopcodeh.awk script for additional information. |
| 71330 | 71547 | ** |
| 71331 | 71548 | ** Documentation about VDBE opcodes is generated by scanning this file |
| 71332 | 71549 | ** for lines of that contain "Opcode:". That line and all subsequent |
| 71333 | 71550 | ** comment lines are used in the generation of the opcode.html documentation |
| | @@ -71351,11 +71568,12 @@ |
| 71351 | 71568 | ** is sometimes set to 1 instead of 0 as a hint to the command-line shell |
| 71352 | 71569 | ** that this Goto is the bottom of a loop and that the lines from P2 down |
| 71353 | 71570 | ** to the current line should be indented for EXPLAIN output. |
| 71354 | 71571 | */ |
| 71355 | 71572 | case OP_Goto: { /* jump */ |
| 71356 | | - pc = pOp->p2 - 1; |
| 71573 | +jump_to_p2_and_check_for_interrupt: |
| 71574 | + pOp = &aOp[pOp->p2 - 1]; |
| 71357 | 71575 | |
| 71358 | 71576 | /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev, |
| 71359 | 71577 | ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon |
| 71360 | 71578 | ** completion. Check to see if sqlite3_interrupt() has been called |
| 71361 | 71579 | ** or if the progress callback needs to be invoked. |
| | @@ -71396,13 +71614,17 @@ |
| 71396 | 71614 | assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 71397 | 71615 | pIn1 = &aMem[pOp->p1]; |
| 71398 | 71616 | assert( VdbeMemDynamic(pIn1)==0 ); |
| 71399 | 71617 | memAboutToChange(p, pIn1); |
| 71400 | 71618 | pIn1->flags = MEM_Int; |
| 71401 | | - pIn1->u.i = pc; |
| 71619 | + pIn1->u.i = (int)(pOp-aOp); |
| 71402 | 71620 | REGISTER_TRACE(pOp->p1, pIn1); |
| 71403 | | - pc = pOp->p2 - 1; |
| 71621 | + |
| 71622 | + /* Most jump operations do a goto to this spot in order to update |
| 71623 | + ** the pOp pointer. */ |
| 71624 | +jump_to_p2: |
| 71625 | + pOp = &aOp[pOp->p2 - 1]; |
| 71404 | 71626 | break; |
| 71405 | 71627 | } |
| 71406 | 71628 | |
| 71407 | 71629 | /* Opcode: Return P1 * * * * |
| 71408 | 71630 | ** |
| | @@ -71410,11 +71632,11 @@ |
| 71410 | 71632 | ** the jump, register P1 becomes undefined. |
| 71411 | 71633 | */ |
| 71412 | 71634 | case OP_Return: { /* in1 */ |
| 71413 | 71635 | pIn1 = &aMem[pOp->p1]; |
| 71414 | 71636 | assert( pIn1->flags==MEM_Int ); |
| 71415 | | - pc = (int)pIn1->u.i; |
| 71637 | + pOp = &aOp[pIn1->u.i]; |
| 71416 | 71638 | pIn1->flags = MEM_Undefined; |
| 71417 | 71639 | break; |
| 71418 | 71640 | } |
| 71419 | 71641 | |
| 71420 | 71642 | /* Opcode: InitCoroutine P1 P2 P3 * * |
| | @@ -71434,11 +71656,11 @@ |
| 71434 | 71656 | assert( pOp->p3>=0 && pOp->p3<p->nOp ); |
| 71435 | 71657 | pOut = &aMem[pOp->p1]; |
| 71436 | 71658 | assert( !VdbeMemDynamic(pOut) ); |
| 71437 | 71659 | pOut->u.i = pOp->p3 - 1; |
| 71438 | 71660 | pOut->flags = MEM_Int; |
| 71439 | | - if( pOp->p2 ) pc = pOp->p2 - 1; |
| 71661 | + if( pOp->p2 ) goto jump_to_p2; |
| 71440 | 71662 | break; |
| 71441 | 71663 | } |
| 71442 | 71664 | |
| 71443 | 71665 | /* Opcode: EndCoroutine P1 * * * * |
| 71444 | 71666 | ** |
| | @@ -71454,11 +71676,11 @@ |
| 71454 | 71676 | assert( pIn1->flags==MEM_Int ); |
| 71455 | 71677 | assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp ); |
| 71456 | 71678 | pCaller = &aOp[pIn1->u.i]; |
| 71457 | 71679 | assert( pCaller->opcode==OP_Yield ); |
| 71458 | 71680 | assert( pCaller->p2>=0 && pCaller->p2<p->nOp ); |
| 71459 | | - pc = pCaller->p2 - 1; |
| 71681 | + pOp = &aOp[pCaller->p2 - 1]; |
| 71460 | 71682 | pIn1->flags = MEM_Undefined; |
| 71461 | 71683 | break; |
| 71462 | 71684 | } |
| 71463 | 71685 | |
| 71464 | 71686 | /* Opcode: Yield P1 P2 * * * |
| | @@ -71478,13 +71700,13 @@ |
| 71478 | 71700 | int pcDest; |
| 71479 | 71701 | pIn1 = &aMem[pOp->p1]; |
| 71480 | 71702 | assert( VdbeMemDynamic(pIn1)==0 ); |
| 71481 | 71703 | pIn1->flags = MEM_Int; |
| 71482 | 71704 | pcDest = (int)pIn1->u.i; |
| 71483 | | - pIn1->u.i = pc; |
| 71705 | + pIn1->u.i = (int)(pOp - aOp); |
| 71484 | 71706 | REGISTER_TRACE(pOp->p1, pIn1); |
| 71485 | | - pc = pcDest; |
| 71707 | + pOp = &aOp[pcDest]; |
| 71486 | 71708 | break; |
| 71487 | 71709 | } |
| 71488 | 71710 | |
| 71489 | 71711 | /* Opcode: HaltIfNull P1 P2 P3 P4 P5 |
| 71490 | 71712 | ** Synopsis: if r[P3]=null halt |
| | @@ -71531,34 +71753,38 @@ |
| 71531 | 71753 | ** is the same as executing Halt. |
| 71532 | 71754 | */ |
| 71533 | 71755 | case OP_Halt: { |
| 71534 | 71756 | const char *zType; |
| 71535 | 71757 | const char *zLogFmt; |
| 71758 | + VdbeFrame *pFrame; |
| 71759 | + int pcx; |
| 71536 | 71760 | |
| 71761 | + pcx = (int)(pOp - aOp); |
| 71537 | 71762 | if( pOp->p1==SQLITE_OK && p->pFrame ){ |
| 71538 | 71763 | /* Halt the sub-program. Return control to the parent frame. */ |
| 71539 | | - VdbeFrame *pFrame = p->pFrame; |
| 71764 | + pFrame = p->pFrame; |
| 71540 | 71765 | p->pFrame = pFrame->pParent; |
| 71541 | 71766 | p->nFrame--; |
| 71542 | 71767 | sqlite3VdbeSetChanges(db, p->nChange); |
| 71543 | | - pc = sqlite3VdbeFrameRestore(pFrame); |
| 71768 | + pcx = sqlite3VdbeFrameRestore(pFrame); |
| 71544 | 71769 | lastRowid = db->lastRowid; |
| 71545 | 71770 | if( pOp->p2==OE_Ignore ){ |
| 71546 | | - /* Instruction pc is the OP_Program that invoked the sub-program |
| 71771 | + /* Instruction pcx is the OP_Program that invoked the sub-program |
| 71547 | 71772 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 71548 | 71773 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 71549 | 71774 | ** an IGNORE exception. In this case jump to the address specified |
| 71550 | 71775 | ** as the p2 of the calling OP_Program. */ |
| 71551 | | - pc = p->aOp[pc].p2-1; |
| 71776 | + pcx = p->aOp[pcx].p2-1; |
| 71552 | 71777 | } |
| 71553 | 71778 | aOp = p->aOp; |
| 71554 | 71779 | aMem = p->aMem; |
| 71780 | + pOp = &aOp[pcx]; |
| 71555 | 71781 | break; |
| 71556 | 71782 | } |
| 71557 | 71783 | p->rc = pOp->p1; |
| 71558 | 71784 | p->errorAction = (u8)pOp->p2; |
| 71559 | | - p->pc = pc; |
| 71785 | + p->pc = pcx; |
| 71560 | 71786 | if( p->rc ){ |
| 71561 | 71787 | if( pOp->p5 ){ |
| 71562 | 71788 | static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK", |
| 71563 | 71789 | "FOREIGN KEY" }; |
| 71564 | 71790 | assert( pOp->p5>=1 && pOp->p5<=4 ); |
| | @@ -71578,11 +71804,11 @@ |
| 71578 | 71804 | }else if( pOp->p4.z ){ |
| 71579 | 71805 | sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z); |
| 71580 | 71806 | }else{ |
| 71581 | 71807 | sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType); |
| 71582 | 71808 | } |
| 71583 | | - sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg); |
| 71809 | + sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg); |
| 71584 | 71810 | } |
| 71585 | 71811 | rc = sqlite3VdbeHalt(p); |
| 71586 | 71812 | assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); |
| 71587 | 71813 | if( rc==SQLITE_BUSY ){ |
| 71588 | 71814 | p->rc = rc = SQLITE_BUSY; |
| | @@ -71597,11 +71823,12 @@ |
| 71597 | 71823 | /* Opcode: Integer P1 P2 * * * |
| 71598 | 71824 | ** Synopsis: r[P2]=P1 |
| 71599 | 71825 | ** |
| 71600 | 71826 | ** The 32-bit integer value P1 is written into register P2. |
| 71601 | 71827 | */ |
| 71602 | | -case OP_Integer: { /* out2-prerelease */ |
| 71828 | +case OP_Integer: { /* out2 */ |
| 71829 | + pOut = out2Prerelease(p, pOp); |
| 71603 | 71830 | pOut->u.i = pOp->p1; |
| 71604 | 71831 | break; |
| 71605 | 71832 | } |
| 71606 | 71833 | |
| 71607 | 71834 | /* Opcode: Int64 * P2 * P4 * |
| | @@ -71608,11 +71835,12 @@ |
| 71608 | 71835 | ** Synopsis: r[P2]=P4 |
| 71609 | 71836 | ** |
| 71610 | 71837 | ** P4 is a pointer to a 64-bit integer value. |
| 71611 | 71838 | ** Write that value into register P2. |
| 71612 | 71839 | */ |
| 71613 | | -case OP_Int64: { /* out2-prerelease */ |
| 71840 | +case OP_Int64: { /* out2 */ |
| 71841 | + pOut = out2Prerelease(p, pOp); |
| 71614 | 71842 | assert( pOp->p4.pI64!=0 ); |
| 71615 | 71843 | pOut->u.i = *pOp->p4.pI64; |
| 71616 | 71844 | break; |
| 71617 | 71845 | } |
| 71618 | 71846 | |
| | @@ -71621,11 +71849,12 @@ |
| 71621 | 71849 | ** Synopsis: r[P2]=P4 |
| 71622 | 71850 | ** |
| 71623 | 71851 | ** P4 is a pointer to a 64-bit floating point value. |
| 71624 | 71852 | ** Write that value into register P2. |
| 71625 | 71853 | */ |
| 71626 | | -case OP_Real: { /* same as TK_FLOAT, out2-prerelease */ |
| 71854 | +case OP_Real: { /* same as TK_FLOAT, out2 */ |
| 71855 | + pOut = out2Prerelease(p, pOp); |
| 71627 | 71856 | pOut->flags = MEM_Real; |
| 71628 | 71857 | assert( !sqlite3IsNaN(*pOp->p4.pReal) ); |
| 71629 | 71858 | pOut->u.r = *pOp->p4.pReal; |
| 71630 | 71859 | break; |
| 71631 | 71860 | } |
| | @@ -71637,12 +71866,13 @@ |
| 71637 | 71866 | ** P4 points to a nul terminated UTF-8 string. This opcode is transformed |
| 71638 | 71867 | ** into a String opcode before it is executed for the first time. During |
| 71639 | 71868 | ** this transformation, the length of string P4 is computed and stored |
| 71640 | 71869 | ** as the P1 parameter. |
| 71641 | 71870 | */ |
| 71642 | | -case OP_String8: { /* same as TK_STRING, out2-prerelease */ |
| 71871 | +case OP_String8: { /* same as TK_STRING, out2 */ |
| 71643 | 71872 | assert( pOp->p4.z!=0 ); |
| 71873 | + pOut = out2Prerelease(p, pOp); |
| 71644 | 71874 | pOp->opcode = OP_String; |
| 71645 | 71875 | pOp->p1 = sqlite3Strlen30(pOp->p4.z); |
| 71646 | 71876 | |
| 71647 | 71877 | #ifndef SQLITE_OMIT_UTF16 |
| 71648 | 71878 | if( encoding!=SQLITE_UTF8 ){ |
| | @@ -71675,12 +71905,13 @@ |
| 71675 | 71905 | ** If P5!=0 and the content of register P3 is greater than zero, then |
| 71676 | 71906 | ** the datatype of the register P2 is converted to BLOB. The content is |
| 71677 | 71907 | ** the same sequence of bytes, it is merely interpreted as a BLOB instead |
| 71678 | 71908 | ** of a string, as if it had been CAST. |
| 71679 | 71909 | */ |
| 71680 | | -case OP_String: { /* out2-prerelease */ |
| 71910 | +case OP_String: { /* out2 */ |
| 71681 | 71911 | assert( pOp->p4.z!=0 ); |
| 71912 | + pOut = out2Prerelease(p, pOp); |
| 71682 | 71913 | pOut->flags = MEM_Str|MEM_Static|MEM_Term; |
| 71683 | 71914 | pOut->z = pOp->p4.z; |
| 71684 | 71915 | pOut->n = pOp->p1; |
| 71685 | 71916 | pOut->enc = encoding; |
| 71686 | 71917 | UPDATE_MAX_BLOBSIZE(pOut); |
| | @@ -71704,13 +71935,14 @@ |
| 71704 | 71935 | ** |
| 71705 | 71936 | ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that |
| 71706 | 71937 | ** NULL values will not compare equal even if SQLITE_NULLEQ is set on |
| 71707 | 71938 | ** OP_Ne or OP_Eq. |
| 71708 | 71939 | */ |
| 71709 | | -case OP_Null: { /* out2-prerelease */ |
| 71940 | +case OP_Null: { /* out2 */ |
| 71710 | 71941 | int cnt; |
| 71711 | 71942 | u16 nullFlag; |
| 71943 | + pOut = out2Prerelease(p, pOp); |
| 71712 | 71944 | cnt = pOp->p3-pOp->p2; |
| 71713 | 71945 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 71714 | 71946 | pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; |
| 71715 | 71947 | while( cnt>0 ){ |
| 71716 | 71948 | pOut++; |
| | @@ -71741,12 +71973,13 @@ |
| 71741 | 71973 | ** Synopsis: r[P2]=P4 (len=P1) |
| 71742 | 71974 | ** |
| 71743 | 71975 | ** P4 points to a blob of data P1 bytes long. Store this |
| 71744 | 71976 | ** blob in register P2. |
| 71745 | 71977 | */ |
| 71746 | | -case OP_Blob: { /* out2-prerelease */ |
| 71978 | +case OP_Blob: { /* out2 */ |
| 71747 | 71979 | assert( pOp->p1 <= SQLITE_MAX_LENGTH ); |
| 71980 | + pOut = out2Prerelease(p, pOp); |
| 71748 | 71981 | sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0); |
| 71749 | 71982 | pOut->enc = encoding; |
| 71750 | 71983 | UPDATE_MAX_BLOBSIZE(pOut); |
| 71751 | 71984 | break; |
| 71752 | 71985 | } |
| | @@ -71757,19 +71990,20 @@ |
| 71757 | 71990 | ** Transfer the values of bound parameter P1 into register P2 |
| 71758 | 71991 | ** |
| 71759 | 71992 | ** If the parameter is named, then its name appears in P4. |
| 71760 | 71993 | ** The P4 value is used by sqlite3_bind_parameter_name(). |
| 71761 | 71994 | */ |
| 71762 | | -case OP_Variable: { /* out2-prerelease */ |
| 71995 | +case OP_Variable: { /* out2 */ |
| 71763 | 71996 | Mem *pVar; /* Value being transferred */ |
| 71764 | 71997 | |
| 71765 | 71998 | assert( pOp->p1>0 && pOp->p1<=p->nVar ); |
| 71766 | 71999 | assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] ); |
| 71767 | 72000 | pVar = &p->aVar[pOp->p1 - 1]; |
| 71768 | 72001 | if( sqlite3VdbeMemTooBig(pVar) ){ |
| 71769 | 72002 | goto too_big; |
| 71770 | 72003 | } |
| 72004 | + pOut = out2Prerelease(p, pOp); |
| 71771 | 72005 | sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); |
| 71772 | 72006 | UPDATE_MAX_BLOBSIZE(pOut); |
| 71773 | 72007 | break; |
| 71774 | 72008 | } |
| 71775 | 72009 | |
| | @@ -71800,14 +72034,15 @@ |
| 71800 | 72034 | assert( pIn1<=&aMem[(p->nMem-p->nCursor)] ); |
| 71801 | 72035 | assert( memIsValid(pIn1) ); |
| 71802 | 72036 | memAboutToChange(p, pOut); |
| 71803 | 72037 | sqlite3VdbeMemMove(pOut, pIn1); |
| 71804 | 72038 | #ifdef SQLITE_DEBUG |
| 71805 | | - if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){ |
| 71806 | | - pOut->pScopyFrom += p1 - pOp->p2; |
| 72039 | + if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){ |
| 72040 | + pOut->pScopyFrom += pOp->p2 - p1; |
| 71807 | 72041 | } |
| 71808 | 72042 | #endif |
| 72043 | + Deephemeralize(pOut); |
| 71809 | 72044 | REGISTER_TRACE(p2++, pOut); |
| 71810 | 72045 | pIn1++; |
| 71811 | 72046 | pOut++; |
| 71812 | 72047 | }while( --n ); |
| 71813 | 72048 | break; |
| | @@ -71942,11 +72177,11 @@ |
| 71942 | 72177 | } |
| 71943 | 72178 | if( db->mallocFailed ) goto no_mem; |
| 71944 | 72179 | |
| 71945 | 72180 | /* Return SQLITE_ROW |
| 71946 | 72181 | */ |
| 71947 | | - p->pc = pc + 1; |
| 72182 | + p->pc = (int)(pOp - aOp) + 1; |
| 71948 | 72183 | rc = SQLITE_ROW; |
| 71949 | 72184 | goto vdbe_return; |
| 71950 | 72185 | } |
| 71951 | 72186 | |
| 71952 | 72187 | /* Opcode: Concat P1 P2 P3 * * |
| | @@ -72188,11 +72423,11 @@ |
| 72188 | 72423 | REGISTER_TRACE(pOp->p2+i, pArg); |
| 72189 | 72424 | } |
| 72190 | 72425 | |
| 72191 | 72426 | assert( pOp->p4type==P4_FUNCDEF ); |
| 72192 | 72427 | ctx.pFunc = pOp->p4.pFunc; |
| 72193 | | - ctx.iOp = pc; |
| 72428 | + ctx.iOp = (int)(pOp - aOp); |
| 72194 | 72429 | ctx.pVdbe = p; |
| 72195 | 72430 | MemSetTypeFlag(ctx.pOut, MEM_Null); |
| 72196 | 72431 | ctx.fErrorOrAux = 0; |
| 72197 | 72432 | db->lastRowid = lastRowid; |
| 72198 | 72433 | (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */ |
| | @@ -72202,11 +72437,11 @@ |
| 72202 | 72437 | if( ctx.fErrorOrAux ){ |
| 72203 | 72438 | if( ctx.isError ){ |
| 72204 | 72439 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut)); |
| 72205 | 72440 | rc = ctx.isError; |
| 72206 | 72441 | } |
| 72207 | | - sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); |
| 72442 | + sqlite3VdbeDeleteAuxData(p, (int)(pOp - aOp), pOp->p1); |
| 72208 | 72443 | } |
| 72209 | 72444 | |
| 72210 | 72445 | /* Copy the result of the function into register P3 */ |
| 72211 | 72446 | sqlite3VdbeChangeEncoding(ctx.pOut, encoding); |
| 72212 | 72447 | if( sqlite3VdbeMemTooBig(ctx.pOut) ){ |
| | @@ -72331,12 +72566,11 @@ |
| 72331 | 72566 | if( (pIn1->flags & MEM_Int)==0 ){ |
| 72332 | 72567 | if( pOp->p2==0 ){ |
| 72333 | 72568 | rc = SQLITE_MISMATCH; |
| 72334 | 72569 | goto abort_due_to_error; |
| 72335 | 72570 | }else{ |
| 72336 | | - pc = pOp->p2 - 1; |
| 72337 | | - break; |
| 72571 | + goto jump_to_p2; |
| 72338 | 72572 | } |
| 72339 | 72573 | } |
| 72340 | 72574 | } |
| 72341 | 72575 | MemSetTypeFlag(pIn1, MEM_Int); |
| 72342 | 72576 | break; |
| | @@ -72518,11 +72752,11 @@ |
| 72518 | 72752 | MemSetTypeFlag(pOut, MEM_Null); |
| 72519 | 72753 | REGISTER_TRACE(pOp->p2, pOut); |
| 72520 | 72754 | }else{ |
| 72521 | 72755 | VdbeBranchTaken(2,3); |
| 72522 | 72756 | if( pOp->p5 & SQLITE_JUMPIFNULL ){ |
| 72523 | | - pc = pOp->p2-1; |
| 72757 | + goto jump_to_p2; |
| 72524 | 72758 | } |
| 72525 | 72759 | } |
| 72526 | 72760 | break; |
| 72527 | 72761 | } |
| 72528 | 72762 | }else{ |
| | @@ -72538,15 +72772,19 @@ |
| 72538 | 72772 | }else if( affinity==SQLITE_AFF_TEXT ){ |
| 72539 | 72773 | if( (pIn1->flags & MEM_Str)==0 && (pIn1->flags & (MEM_Int|MEM_Real))!=0 ){ |
| 72540 | 72774 | testcase( pIn1->flags & MEM_Int ); |
| 72541 | 72775 | testcase( pIn1->flags & MEM_Real ); |
| 72542 | 72776 | sqlite3VdbeMemStringify(pIn1, encoding, 1); |
| 72777 | + testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) ); |
| 72778 | + flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask); |
| 72543 | 72779 | } |
| 72544 | 72780 | if( (pIn3->flags & MEM_Str)==0 && (pIn3->flags & (MEM_Int|MEM_Real))!=0 ){ |
| 72545 | 72781 | testcase( pIn3->flags & MEM_Int ); |
| 72546 | 72782 | testcase( pIn3->flags & MEM_Real ); |
| 72547 | 72783 | sqlite3VdbeMemStringify(pIn3, encoding, 1); |
| 72784 | + testcase( (flags3&MEM_Dyn) != (pIn3->flags&MEM_Dyn) ); |
| 72785 | + flags3 = (pIn3->flags & ~MEM_TypeMask) | (flags3 & MEM_TypeMask); |
| 72548 | 72786 | } |
| 72549 | 72787 | } |
| 72550 | 72788 | assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 ); |
| 72551 | 72789 | if( pIn1->flags & MEM_Zero ){ |
| 72552 | 72790 | sqlite3VdbeMemExpandBlob(pIn1); |
| | @@ -72565,10 +72803,16 @@ |
| 72565 | 72803 | case OP_Lt: res = res<0; break; |
| 72566 | 72804 | case OP_Le: res = res<=0; break; |
| 72567 | 72805 | case OP_Gt: res = res>0; break; |
| 72568 | 72806 | default: res = res>=0; break; |
| 72569 | 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; |
| 72570 | 72814 | |
| 72571 | 72815 | if( pOp->p5 & SQLITE_STOREP2 ){ |
| 72572 | 72816 | pOut = &aMem[pOp->p2]; |
| 72573 | 72817 | memAboutToChange(p, pOut); |
| 72574 | 72818 | MemSetTypeFlag(pOut, MEM_Int); |
| | @@ -72575,16 +72819,13 @@ |
| 72575 | 72819 | pOut->u.i = res; |
| 72576 | 72820 | REGISTER_TRACE(pOp->p2, pOut); |
| 72577 | 72821 | }else{ |
| 72578 | 72822 | VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3); |
| 72579 | 72823 | if( res ){ |
| 72580 | | - pc = pOp->p2-1; |
| 72824 | + goto jump_to_p2; |
| 72581 | 72825 | } |
| 72582 | 72826 | } |
| 72583 | | - /* Undo any changes made by applyAffinity() to the input registers. */ |
| 72584 | | - pIn1->flags = flags1; |
| 72585 | | - pIn3->flags = flags3; |
| 72586 | 72827 | break; |
| 72587 | 72828 | } |
| 72588 | 72829 | |
| 72589 | 72830 | /* Opcode: Permutation * * * P4 * |
| 72590 | 72831 | ** |
| | @@ -72675,15 +72916,15 @@ |
| 72675 | 72916 | ** in the most recent OP_Compare instruction the P1 vector was less than |
| 72676 | 72917 | ** equal to, or greater than the P2 vector, respectively. |
| 72677 | 72918 | */ |
| 72678 | 72919 | case OP_Jump: { /* jump */ |
| 72679 | 72920 | if( iCompare<0 ){ |
| 72680 | | - pc = pOp->p1 - 1; VdbeBranchTaken(0,3); |
| 72921 | + VdbeBranchTaken(0,3); pOp = &aOp[pOp->p1 - 1]; |
| 72681 | 72922 | }else if( iCompare==0 ){ |
| 72682 | | - pc = pOp->p2 - 1; VdbeBranchTaken(1,3); |
| 72923 | + VdbeBranchTaken(1,3); pOp = &aOp[pOp->p2 - 1]; |
| 72683 | 72924 | }else{ |
| 72684 | | - pc = pOp->p3 - 1; VdbeBranchTaken(2,3); |
| 72925 | + VdbeBranchTaken(2,3); pOp = &aOp[pOp->p3 - 1]; |
| 72685 | 72926 | } |
| 72686 | 72927 | break; |
| 72687 | 72928 | } |
| 72688 | 72929 | |
| 72689 | 72930 | /* Opcode: And P1 P2 P3 * * |
| | @@ -72789,11 +73030,11 @@ |
| 72789 | 73030 | */ |
| 72790 | 73031 | case OP_Once: { /* jump */ |
| 72791 | 73032 | assert( pOp->p1<p->nOnceFlag ); |
| 72792 | 73033 | VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2); |
| 72793 | 73034 | if( p->aOnceFlag[pOp->p1] ){ |
| 72794 | | - pc = pOp->p2-1; |
| 73035 | + goto jump_to_p2; |
| 72795 | 73036 | }else{ |
| 72796 | 73037 | p->aOnceFlag[pOp->p1] = 1; |
| 72797 | 73038 | } |
| 72798 | 73039 | break; |
| 72799 | 73040 | } |
| | @@ -72824,11 +73065,11 @@ |
| 72824 | 73065 | #endif |
| 72825 | 73066 | if( pOp->opcode==OP_IfNot ) c = !c; |
| 72826 | 73067 | } |
| 72827 | 73068 | VdbeBranchTaken(c!=0, 2); |
| 72828 | 73069 | if( c ){ |
| 72829 | | - pc = pOp->p2-1; |
| 73070 | + goto jump_to_p2; |
| 72830 | 73071 | } |
| 72831 | 73072 | break; |
| 72832 | 73073 | } |
| 72833 | 73074 | |
| 72834 | 73075 | /* Opcode: IsNull P1 P2 * * * |
| | @@ -72838,11 +73079,11 @@ |
| 72838 | 73079 | */ |
| 72839 | 73080 | case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */ |
| 72840 | 73081 | pIn1 = &aMem[pOp->p1]; |
| 72841 | 73082 | VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2); |
| 72842 | 73083 | if( (pIn1->flags & MEM_Null)!=0 ){ |
| 72843 | | - pc = pOp->p2 - 1; |
| 73084 | + goto jump_to_p2; |
| 72844 | 73085 | } |
| 72845 | 73086 | break; |
| 72846 | 73087 | } |
| 72847 | 73088 | |
| 72848 | 73089 | /* Opcode: NotNull P1 P2 * * * |
| | @@ -72852,11 +73093,11 @@ |
| 72852 | 73093 | */ |
| 72853 | 73094 | case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */ |
| 72854 | 73095 | pIn1 = &aMem[pOp->p1]; |
| 72855 | 73096 | VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2); |
| 72856 | 73097 | if( (pIn1->flags & MEM_Null)==0 ){ |
| 72857 | | - pc = pOp->p2 - 1; |
| 73098 | + goto jump_to_p2; |
| 72858 | 73099 | } |
| 72859 | 73100 | break; |
| 72860 | 73101 | } |
| 72861 | 73102 | |
| 72862 | 73103 | /* Opcode: Column P1 P2 P3 P4 P5 |
| | @@ -73066,11 +73307,11 @@ |
| 73066 | 73307 | rc = SQLITE_CORRUPT_BKPT; |
| 73067 | 73308 | goto op_column_error; |
| 73068 | 73309 | } |
| 73069 | 73310 | } |
| 73070 | 73311 | |
| 73071 | | - /* 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 |
| 73072 | 73313 | ** still not up to p2, that means that the record has fewer than p2 |
| 73073 | 73314 | ** columns. So the result will be either the default value or a NULL. |
| 73074 | 73315 | */ |
| 73075 | 73316 | if( pC->nHdrParsed<=p2 ){ |
| 73076 | 73317 | if( pOp->p4type==P4_MEM ){ |
| | @@ -73190,11 +73431,11 @@ |
| 73190 | 73431 | u8 *zNewRecord; /* A buffer to hold the data for the new record */ |
| 73191 | 73432 | Mem *pRec; /* The new record */ |
| 73192 | 73433 | u64 nData; /* Number of bytes of data space */ |
| 73193 | 73434 | int nHdr; /* Number of bytes of header space */ |
| 73194 | 73435 | i64 nByte; /* Data space required for this record */ |
| 73195 | | - 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 */ |
| 73196 | 73437 | int nVarint; /* Number of bytes in a varint */ |
| 73197 | 73438 | u32 serial_type; /* Type field */ |
| 73198 | 73439 | Mem *pData0; /* First field to be combined into the record */ |
| 73199 | 73440 | Mem *pLast; /* Last field of the record */ |
| 73200 | 73441 | int nField; /* Number of fields in the record */ |
| | @@ -73282,11 +73523,11 @@ |
| 73282 | 73523 | nVarint = sqlite3VarintLen(nHdr); |
| 73283 | 73524 | nHdr += nVarint; |
| 73284 | 73525 | if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++; |
| 73285 | 73526 | } |
| 73286 | 73527 | nByte = nHdr+nData; |
| 73287 | | - if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 73528 | + if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 73288 | 73529 | goto too_big; |
| 73289 | 73530 | } |
| 73290 | 73531 | |
| 73291 | 73532 | /* Make sure the output register has a buffer large enough to store |
| 73292 | 73533 | ** the new record. The output register (pOp->p3) is not allowed to |
| | @@ -73333,18 +73574,19 @@ |
| 73333 | 73574 | ** |
| 73334 | 73575 | ** Store the number of entries (an integer value) in the table or index |
| 73335 | 73576 | ** opened by cursor P1 in register P2 |
| 73336 | 73577 | */ |
| 73337 | 73578 | #ifndef SQLITE_OMIT_BTREECOUNT |
| 73338 | | -case OP_Count: { /* out2-prerelease */ |
| 73579 | +case OP_Count: { /* out2 */ |
| 73339 | 73580 | i64 nEntry; |
| 73340 | 73581 | BtCursor *pCrsr; |
| 73341 | 73582 | |
| 73342 | 73583 | pCrsr = p->apCsr[pOp->p1]->pCursor; |
| 73343 | 73584 | assert( pCrsr ); |
| 73344 | 73585 | nEntry = 0; /* Not needed. Only used to silence a warning. */ |
| 73345 | 73586 | rc = sqlite3BtreeCount(pCrsr, &nEntry); |
| 73587 | + pOut = out2Prerelease(p, pOp); |
| 73346 | 73588 | pOut->u.i = nEntry; |
| 73347 | 73589 | break; |
| 73348 | 73590 | } |
| 73349 | 73591 | #endif |
| 73350 | 73592 | |
| | @@ -73454,11 +73696,11 @@ |
| 73454 | 73696 | if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 73455 | 73697 | goto vdbe_return; |
| 73456 | 73698 | } |
| 73457 | 73699 | db->autoCommit = 1; |
| 73458 | 73700 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 73459 | | - p->pc = pc; |
| 73701 | + p->pc = (int)(pOp - aOp); |
| 73460 | 73702 | db->autoCommit = 0; |
| 73461 | 73703 | p->rc = rc = SQLITE_BUSY; |
| 73462 | 73704 | goto vdbe_return; |
| 73463 | 73705 | } |
| 73464 | 73706 | db->isTransactionSavepoint = 0; |
| | @@ -73513,11 +73755,11 @@ |
| 73513 | 73755 | }else{ |
| 73514 | 73756 | db->nDeferredCons = pSavepoint->nDeferredCons; |
| 73515 | 73757 | db->nDeferredImmCons = pSavepoint->nDeferredImmCons; |
| 73516 | 73758 | } |
| 73517 | 73759 | |
| 73518 | | - if( !isTransaction ){ |
| 73760 | + if( !isTransaction || p1==SAVEPOINT_ROLLBACK ){ |
| 73519 | 73761 | rc = sqlite3VtabSavepoint(db, p1, iSavepoint); |
| 73520 | 73762 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 73521 | 73763 | } |
| 73522 | 73764 | } |
| 73523 | 73765 | } |
| | @@ -73573,11 +73815,11 @@ |
| 73573 | 73815 | }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 73574 | 73816 | goto vdbe_return; |
| 73575 | 73817 | }else{ |
| 73576 | 73818 | db->autoCommit = (u8)desiredAutoCommit; |
| 73577 | 73819 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 73578 | | - p->pc = pc; |
| 73820 | + p->pc = (int)(pOp - aOp); |
| 73579 | 73821 | db->autoCommit = (u8)(1-desiredAutoCommit); |
| 73580 | 73822 | p->rc = rc = SQLITE_BUSY; |
| 73581 | 73823 | goto vdbe_return; |
| 73582 | 73824 | } |
| 73583 | 73825 | } |
| | @@ -73650,11 +73892,11 @@ |
| 73650 | 73892 | pBt = db->aDb[pOp->p1].pBt; |
| 73651 | 73893 | |
| 73652 | 73894 | if( pBt ){ |
| 73653 | 73895 | rc = sqlite3BtreeBeginTrans(pBt, pOp->p2); |
| 73654 | 73896 | if( rc==SQLITE_BUSY ){ |
| 73655 | | - p->pc = pc; |
| 73897 | + p->pc = (int)(pOp - aOp); |
| 73656 | 73898 | p->rc = rc = SQLITE_BUSY; |
| 73657 | 73899 | goto vdbe_return; |
| 73658 | 73900 | } |
| 73659 | 73901 | if( rc!=SQLITE_OK ){ |
| 73660 | 73902 | goto abort_due_to_error; |
| | @@ -73729,11 +73971,11 @@ |
| 73729 | 73971 | ** |
| 73730 | 73972 | ** There must be a read-lock on the database (either a transaction |
| 73731 | 73973 | ** must be started or there must be an open cursor) before |
| 73732 | 73974 | ** executing this instruction. |
| 73733 | 73975 | */ |
| 73734 | | -case OP_ReadCookie: { /* out2-prerelease */ |
| 73976 | +case OP_ReadCookie: { /* out2 */ |
| 73735 | 73977 | int iMeta; |
| 73736 | 73978 | int iDb; |
| 73737 | 73979 | int iCookie; |
| 73738 | 73980 | |
| 73739 | 73981 | assert( p->bIsReader ); |
| | @@ -73743,10 +73985,11 @@ |
| 73743 | 73985 | assert( iDb>=0 && iDb<db->nDb ); |
| 73744 | 73986 | assert( db->aDb[iDb].pBt!=0 ); |
| 73745 | 73987 | assert( DbMaskTest(p->btreeMask, iDb) ); |
| 73746 | 73988 | |
| 73747 | 73989 | sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta); |
| 73990 | + pOut = out2Prerelease(p, pOp); |
| 73748 | 73991 | pOut->u.i = iMeta; |
| 73749 | 73992 | break; |
| 73750 | 73993 | } |
| 73751 | 73994 | |
| 73752 | 73995 | /* Opcode: SetCookie P1 P2 P3 * * |
| | @@ -74064,11 +74307,11 @@ |
| 74064 | 74307 | VdbeCursor *pC; |
| 74065 | 74308 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 74066 | 74309 | pC = p->apCsr[pOp->p1]; |
| 74067 | 74310 | assert( pC->pSorter ); |
| 74068 | 74311 | if( (pC->seqCount++)==0 ){ |
| 74069 | | - pc = pOp->p2 - 1; |
| 74312 | + goto jump_to_p2; |
| 74070 | 74313 | } |
| 74071 | 74314 | break; |
| 74072 | 74315 | } |
| 74073 | 74316 | |
| 74074 | 74317 | /* Opcode: OpenPseudo P1 P2 P3 * * |
| | @@ -74241,11 +74484,11 @@ |
| 74241 | 74484 | ** loss of information, then special processing is required... */ |
| 74242 | 74485 | if( (pIn3->flags & MEM_Int)==0 ){ |
| 74243 | 74486 | if( (pIn3->flags & MEM_Real)==0 ){ |
| 74244 | 74487 | /* If the P3 value cannot be converted into any kind of a number, |
| 74245 | 74488 | ** then the seek is not possible, so jump to P2 */ |
| 74246 | | - pc = pOp->p2 - 1; VdbeBranchTaken(1,2); |
| 74489 | + VdbeBranchTaken(1,2); goto jump_to_p2; |
| 74247 | 74490 | break; |
| 74248 | 74491 | } |
| 74249 | 74492 | |
| 74250 | 74493 | /* If the approximation iKey is larger than the actual real search |
| 74251 | 74494 | ** term, substitute >= for > and < for <=. e.g. if the search term |
| | @@ -74332,11 +74575,11 @@ |
| 74332 | 74575 | } |
| 74333 | 74576 | } |
| 74334 | 74577 | assert( pOp->p2>0 ); |
| 74335 | 74578 | VdbeBranchTaken(res!=0,2); |
| 74336 | 74579 | if( res ){ |
| 74337 | | - pc = pOp->p2 - 1; |
| 74580 | + goto jump_to_p2; |
| 74338 | 74581 | } |
| 74339 | 74582 | break; |
| 74340 | 74583 | } |
| 74341 | 74584 | |
| 74342 | 74585 | /* Opcode: Seek P1 P2 * * * |
| | @@ -74426,10 +74669,11 @@ |
| 74426 | 74669 | */ |
| 74427 | 74670 | case OP_NoConflict: /* jump, in3 */ |
| 74428 | 74671 | case OP_NotFound: /* jump, in3 */ |
| 74429 | 74672 | case OP_Found: { /* jump, in3 */ |
| 74430 | 74673 | int alreadyExists; |
| 74674 | + int takeJump; |
| 74431 | 74675 | int ii; |
| 74432 | 74676 | VdbeCursor *pC; |
| 74433 | 74677 | int res; |
| 74434 | 74678 | char *pFree; |
| 74435 | 74679 | UnpackedRecord *pIdxKey; |
| | @@ -74448,11 +74692,11 @@ |
| 74448 | 74692 | pC->seekOp = pOp->opcode; |
| 74449 | 74693 | #endif |
| 74450 | 74694 | pIn3 = &aMem[pOp->p3]; |
| 74451 | 74695 | assert( pC->pCursor!=0 ); |
| 74452 | 74696 | assert( pC->isTable==0 ); |
| 74453 | | - pFree = 0; /* Not needed. Only used to suppress a compiler warning. */ |
| 74697 | + pFree = 0; |
| 74454 | 74698 | if( pOp->p4.i>0 ){ |
| 74455 | 74699 | r.pKeyInfo = pC->pKeyInfo; |
| 74456 | 74700 | r.nField = (u16)pOp->p4.i; |
| 74457 | 74701 | r.aMem = pIn3; |
| 74458 | 74702 | for(ii=0; ii<r.nField; ii++){ |
| | @@ -74471,25 +74715,24 @@ |
| 74471 | 74715 | assert( pIn3->flags & MEM_Blob ); |
| 74472 | 74716 | ExpandBlob(pIn3); |
| 74473 | 74717 | sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); |
| 74474 | 74718 | } |
| 74475 | 74719 | pIdxKey->default_rc = 0; |
| 74720 | + takeJump = 0; |
| 74476 | 74721 | if( pOp->opcode==OP_NoConflict ){ |
| 74477 | 74722 | /* For the OP_NoConflict opcode, take the jump if any of the |
| 74478 | 74723 | ** input fields are NULL, since any key with a NULL will not |
| 74479 | 74724 | ** conflict */ |
| 74480 | 74725 | for(ii=0; ii<pIdxKey->nField; ii++){ |
| 74481 | 74726 | if( pIdxKey->aMem[ii].flags & MEM_Null ){ |
| 74482 | | - pc = pOp->p2 - 1; VdbeBranchTaken(1,2); |
| 74727 | + takeJump = 1; |
| 74483 | 74728 | break; |
| 74484 | 74729 | } |
| 74485 | 74730 | } |
| 74486 | 74731 | } |
| 74487 | 74732 | rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res); |
| 74488 | | - if( pOp->p4.i==0 ){ |
| 74489 | | - sqlite3DbFree(db, pFree); |
| 74490 | | - } |
| 74733 | + sqlite3DbFree(db, pFree); |
| 74491 | 74734 | if( rc!=SQLITE_OK ){ |
| 74492 | 74735 | break; |
| 74493 | 74736 | } |
| 74494 | 74737 | pC->seekResult = res; |
| 74495 | 74738 | alreadyExists = (res==0); |
| | @@ -74496,14 +74739,14 @@ |
| 74496 | 74739 | pC->nullRow = 1-alreadyExists; |
| 74497 | 74740 | pC->deferredMoveto = 0; |
| 74498 | 74741 | pC->cacheStatus = CACHE_STALE; |
| 74499 | 74742 | if( pOp->opcode==OP_Found ){ |
| 74500 | 74743 | VdbeBranchTaken(alreadyExists!=0,2); |
| 74501 | | - if( alreadyExists ) pc = pOp->p2 - 1; |
| 74744 | + if( alreadyExists ) goto jump_to_p2; |
| 74502 | 74745 | }else{ |
| 74503 | | - VdbeBranchTaken(alreadyExists==0,2); |
| 74504 | | - if( !alreadyExists ) pc = pOp->p2 - 1; |
| 74746 | + VdbeBranchTaken(takeJump||alreadyExists==0,2); |
| 74747 | + if( takeJump || !alreadyExists ) goto jump_to_p2; |
| 74505 | 74748 | } |
| 74506 | 74749 | break; |
| 74507 | 74750 | } |
| 74508 | 74751 | |
| 74509 | 74752 | /* Opcode: NotExists P1 P2 P3 * * |
| | @@ -74548,14 +74791,12 @@ |
| 74548 | 74791 | pC->movetoTarget = iKey; /* Used by OP_Delete */ |
| 74549 | 74792 | pC->nullRow = 0; |
| 74550 | 74793 | pC->cacheStatus = CACHE_STALE; |
| 74551 | 74794 | pC->deferredMoveto = 0; |
| 74552 | 74795 | VdbeBranchTaken(res!=0,2); |
| 74553 | | - if( res!=0 ){ |
| 74554 | | - pc = pOp->p2 - 1; |
| 74555 | | - } |
| 74556 | 74796 | pC->seekResult = res; |
| 74797 | + if( res!=0 ) goto jump_to_p2; |
| 74557 | 74798 | break; |
| 74558 | 74799 | } |
| 74559 | 74800 | |
| 74560 | 74801 | /* Opcode: Sequence P1 P2 * * * |
| 74561 | 74802 | ** Synopsis: r[P2]=cursor[P1].ctr++ |
| | @@ -74563,13 +74804,14 @@ |
| 74563 | 74804 | ** Find the next available sequence number for cursor P1. |
| 74564 | 74805 | ** Write the sequence number into register P2. |
| 74565 | 74806 | ** The sequence number on the cursor is incremented after this |
| 74566 | 74807 | ** instruction. |
| 74567 | 74808 | */ |
| 74568 | | -case OP_Sequence: { /* out2-prerelease */ |
| 74809 | +case OP_Sequence: { /* out2 */ |
| 74569 | 74810 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 74570 | 74811 | assert( p->apCsr[pOp->p1]!=0 ); |
| 74812 | + pOut = out2Prerelease(p, pOp); |
| 74571 | 74813 | pOut->u.i = p->apCsr[pOp->p1]->seqCount++; |
| 74572 | 74814 | break; |
| 74573 | 74815 | } |
| 74574 | 74816 | |
| 74575 | 74817 | |
| | @@ -74586,20 +74828,21 @@ |
| 74586 | 74828 | ** allowed to be less than this value. When this value reaches its maximum, |
| 74587 | 74829 | ** an SQLITE_FULL error is generated. The P3 register is updated with the ' |
| 74588 | 74830 | ** generated record number. This P3 mechanism is used to help implement the |
| 74589 | 74831 | ** AUTOINCREMENT feature. |
| 74590 | 74832 | */ |
| 74591 | | -case OP_NewRowid: { /* out2-prerelease */ |
| 74833 | +case OP_NewRowid: { /* out2 */ |
| 74592 | 74834 | i64 v; /* The new rowid */ |
| 74593 | 74835 | VdbeCursor *pC; /* Cursor of table to get the new rowid */ |
| 74594 | 74836 | int res; /* Result of an sqlite3BtreeLast() */ |
| 74595 | 74837 | int cnt; /* Counter to limit the number of searches */ |
| 74596 | 74838 | Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ |
| 74597 | 74839 | VdbeFrame *pFrame; /* Root frame of VDBE */ |
| 74598 | 74840 | |
| 74599 | 74841 | v = 0; |
| 74600 | 74842 | res = 0; |
| 74843 | + pOut = out2Prerelease(p, pOp); |
| 74601 | 74844 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 74602 | 74845 | pC = p->apCsr[pOp->p1]; |
| 74603 | 74846 | assert( pC!=0 ); |
| 74604 | 74847 | if( NEVER(pC->pCursor==0) ){ |
| 74605 | 74848 | /* The zero initialization above is all that is needed */ |
| | @@ -74909,13 +75152,11 @@ |
| 74909 | 75152 | pIn3 = &aMem[pOp->p3]; |
| 74910 | 75153 | nKeyCol = pOp->p4.i; |
| 74911 | 75154 | res = 0; |
| 74912 | 75155 | rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res); |
| 74913 | 75156 | VdbeBranchTaken(res!=0,2); |
| 74914 | | - if( res ){ |
| 74915 | | - pc = pOp->p2-1; |
| 74916 | | - } |
| 75157 | + if( res ) goto jump_to_p2; |
| 74917 | 75158 | break; |
| 74918 | 75159 | }; |
| 74919 | 75160 | |
| 74920 | 75161 | /* Opcode: SorterData P1 P2 P3 * * |
| 74921 | 75162 | ** Synopsis: r[P2]=data |
| | @@ -75040,16 +75281,17 @@ |
| 75040 | 75281 | ** |
| 75041 | 75282 | ** P1 can be either an ordinary table or a virtual table. There used to |
| 75042 | 75283 | ** be a separate OP_VRowid opcode for use with virtual tables, but this |
| 75043 | 75284 | ** one opcode now works for both table types. |
| 75044 | 75285 | */ |
| 75045 | | -case OP_Rowid: { /* out2-prerelease */ |
| 75286 | +case OP_Rowid: { /* out2 */ |
| 75046 | 75287 | VdbeCursor *pC; |
| 75047 | 75288 | i64 v; |
| 75048 | 75289 | sqlite3_vtab *pVtab; |
| 75049 | 75290 | const sqlite3_module *pModule; |
| 75050 | 75291 | |
| 75292 | + pOut = out2Prerelease(p, pOp); |
| 75051 | 75293 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 75052 | 75294 | pC = p->apCsr[pOp->p1]; |
| 75053 | 75295 | assert( pC!=0 ); |
| 75054 | 75296 | assert( pC->pseudoTableReg==0 || pC->nullRow ); |
| 75055 | 75297 | if( pC->nullRow ){ |
| | @@ -75098,11 +75340,11 @@ |
| 75098 | 75340 | sqlite3BtreeClearCursor(pC->pCursor); |
| 75099 | 75341 | } |
| 75100 | 75342 | break; |
| 75101 | 75343 | } |
| 75102 | 75344 | |
| 75103 | | -/* Opcode: Last P1 P2 * * * |
| 75345 | +/* Opcode: Last P1 P2 P3 * * |
| 75104 | 75346 | ** |
| 75105 | 75347 | ** The next use of the Rowid or Column or Prev instruction for P1 |
| 75106 | 75348 | ** will refer to the last entry in the database table or index. |
| 75107 | 75349 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 75108 | 75350 | ** If P2 is 0 or if the table or index is not empty, fall through |
| | @@ -75125,16 +75367,17 @@ |
| 75125 | 75367 | assert( pCrsr!=0 ); |
| 75126 | 75368 | rc = sqlite3BtreeLast(pCrsr, &res); |
| 75127 | 75369 | pC->nullRow = (u8)res; |
| 75128 | 75370 | pC->deferredMoveto = 0; |
| 75129 | 75371 | pC->cacheStatus = CACHE_STALE; |
| 75372 | + pC->seekResult = pOp->p3; |
| 75130 | 75373 | #ifdef SQLITE_DEBUG |
| 75131 | 75374 | pC->seekOp = OP_Last; |
| 75132 | 75375 | #endif |
| 75133 | 75376 | if( pOp->p2>0 ){ |
| 75134 | 75377 | VdbeBranchTaken(res!=0,2); |
| 75135 | | - if( res ) pc = pOp->p2 - 1; |
| 75378 | + if( res ) goto jump_to_p2; |
| 75136 | 75379 | } |
| 75137 | 75380 | break; |
| 75138 | 75381 | } |
| 75139 | 75382 | |
| 75140 | 75383 | |
| | @@ -75194,13 +75437,11 @@ |
| 75194 | 75437 | pC->cacheStatus = CACHE_STALE; |
| 75195 | 75438 | } |
| 75196 | 75439 | pC->nullRow = (u8)res; |
| 75197 | 75440 | assert( pOp->p2>0 && pOp->p2<p->nOp ); |
| 75198 | 75441 | VdbeBranchTaken(res!=0,2); |
| 75199 | | - if( res ){ |
| 75200 | | - pc = pOp->p2 - 1; |
| 75201 | | - } |
| 75442 | + if( res ) goto jump_to_p2; |
| 75202 | 75443 | break; |
| 75203 | 75444 | } |
| 75204 | 75445 | |
| 75205 | 75446 | /* Opcode: Next P1 P2 P3 P4 P5 |
| 75206 | 75447 | ** |
| | @@ -75307,15 +75548,15 @@ |
| 75307 | 75548 | next_tail: |
| 75308 | 75549 | pC->cacheStatus = CACHE_STALE; |
| 75309 | 75550 | VdbeBranchTaken(res==0,2); |
| 75310 | 75551 | if( res==0 ){ |
| 75311 | 75552 | pC->nullRow = 0; |
| 75312 | | - pc = pOp->p2 - 1; |
| 75313 | 75553 | p->aCounter[pOp->p5]++; |
| 75314 | 75554 | #ifdef SQLITE_TEST |
| 75315 | 75555 | sqlite3_search_count++; |
| 75316 | 75556 | #endif |
| 75557 | + goto jump_to_p2_and_check_for_interrupt; |
| 75317 | 75558 | }else{ |
| 75318 | 75559 | pC->nullRow = 1; |
| 75319 | 75560 | } |
| 75320 | 75561 | goto check_for_interrupt; |
| 75321 | 75562 | } |
| | @@ -75419,15 +75660,16 @@ |
| 75419 | 75660 | ** the end of the index key pointed to by cursor P1. This integer should be |
| 75420 | 75661 | ** the rowid of the table entry to which this index entry points. |
| 75421 | 75662 | ** |
| 75422 | 75663 | ** See also: Rowid, MakeRecord. |
| 75423 | 75664 | */ |
| 75424 | | -case OP_IdxRowid: { /* out2-prerelease */ |
| 75665 | +case OP_IdxRowid: { /* out2 */ |
| 75425 | 75666 | BtCursor *pCrsr; |
| 75426 | 75667 | VdbeCursor *pC; |
| 75427 | 75668 | i64 rowid; |
| 75428 | 75669 | |
| 75670 | + pOut = out2Prerelease(p, pOp); |
| 75429 | 75671 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 75430 | 75672 | pC = p->apCsr[pOp->p1]; |
| 75431 | 75673 | assert( pC!=0 ); |
| 75432 | 75674 | pCrsr = pC->pCursor; |
| 75433 | 75675 | assert( pCrsr!=0 ); |
| | @@ -75536,13 +75778,11 @@ |
| 75536 | 75778 | }else{ |
| 75537 | 75779 | assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT ); |
| 75538 | 75780 | res++; |
| 75539 | 75781 | } |
| 75540 | 75782 | VdbeBranchTaken(res>0,2); |
| 75541 | | - if( res>0 ){ |
| 75542 | | - pc = pOp->p2 - 1 ; |
| 75543 | | - } |
| 75783 | + if( res>0 ) goto jump_to_p2; |
| 75544 | 75784 | break; |
| 75545 | 75785 | } |
| 75546 | 75786 | |
| 75547 | 75787 | /* Opcode: Destroy P1 P2 P3 * * |
| 75548 | 75788 | ** |
| | @@ -75562,15 +75802,16 @@ |
| 75562 | 75802 | ** the last one in the database) then a zero is stored in register P2. |
| 75563 | 75803 | ** If AUTOVACUUM is disabled then a zero is stored in register P2. |
| 75564 | 75804 | ** |
| 75565 | 75805 | ** See also: Clear |
| 75566 | 75806 | */ |
| 75567 | | -case OP_Destroy: { /* out2-prerelease */ |
| 75807 | +case OP_Destroy: { /* out2 */ |
| 75568 | 75808 | int iMoved; |
| 75569 | 75809 | int iDb; |
| 75570 | 75810 | |
| 75571 | 75811 | assert( p->readOnly==0 ); |
| 75812 | + pOut = out2Prerelease(p, pOp); |
| 75572 | 75813 | pOut->flags = MEM_Null; |
| 75573 | 75814 | if( db->nVdbeRead > db->nVDestroy+1 ){ |
| 75574 | 75815 | rc = SQLITE_LOCKED; |
| 75575 | 75816 | p->errorAction = OE_Abort; |
| 75576 | 75817 | }else{ |
| | @@ -75675,16 +75916,17 @@ |
| 75675 | 75916 | ** P1>1. Write the root page number of the new table into |
| 75676 | 75917 | ** register P2. |
| 75677 | 75918 | ** |
| 75678 | 75919 | ** See documentation on OP_CreateTable for additional information. |
| 75679 | 75920 | */ |
| 75680 | | -case OP_CreateIndex: /* out2-prerelease */ |
| 75681 | | -case OP_CreateTable: { /* out2-prerelease */ |
| 75921 | +case OP_CreateIndex: /* out2 */ |
| 75922 | +case OP_CreateTable: { /* out2 */ |
| 75682 | 75923 | int pgno; |
| 75683 | 75924 | int flags; |
| 75684 | 75925 | Db *pDb; |
| 75685 | 75926 | |
| 75927 | + pOut = out2Prerelease(p, pOp); |
| 75686 | 75928 | pgno = 0; |
| 75687 | 75929 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 75688 | 75930 | assert( DbMaskTest(p->btreeMask, pOp->p1) ); |
| 75689 | 75931 | assert( p->readOnly==0 ); |
| 75690 | 75932 | pDb = &db->aDb[pOp->p1]; |
| | @@ -75906,16 +76148,16 @@ |
| 75906 | 76148 | if( (pIn1->flags & MEM_RowSet)==0 |
| 75907 | 76149 | || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0 |
| 75908 | 76150 | ){ |
| 75909 | 76151 | /* The boolean index is empty */ |
| 75910 | 76152 | sqlite3VdbeMemSetNull(pIn1); |
| 75911 | | - pc = pOp->p2 - 1; |
| 75912 | 76153 | VdbeBranchTaken(1,2); |
| 76154 | + goto jump_to_p2_and_check_for_interrupt; |
| 75913 | 76155 | }else{ |
| 75914 | 76156 | /* A value was pulled from the index */ |
| 75915 | | - sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); |
| 75916 | 76157 | VdbeBranchTaken(0,2); |
| 76158 | + sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); |
| 75917 | 76159 | } |
| 75918 | 76160 | goto check_for_interrupt; |
| 75919 | 76161 | } |
| 75920 | 76162 | |
| 75921 | 76163 | /* Opcode: RowSetTest P1 P2 P3 P4 |
| | @@ -75962,14 +76204,11 @@ |
| 75962 | 76204 | assert( pOp->p4type==P4_INT32 ); |
| 75963 | 76205 | assert( iSet==-1 || iSet>=0 ); |
| 75964 | 76206 | if( iSet ){ |
| 75965 | 76207 | exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i); |
| 75966 | 76208 | VdbeBranchTaken(exists!=0,2); |
| 75967 | | - if( exists ){ |
| 75968 | | - pc = pOp->p2 - 1; |
| 75969 | | - break; |
| 75970 | | - } |
| 76209 | + if( exists ) goto jump_to_p2; |
| 75971 | 76210 | } |
| 75972 | 76211 | if( iSet>=0 ){ |
| 75973 | 76212 | sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i); |
| 75974 | 76213 | } |
| 75975 | 76214 | break; |
| | @@ -76054,11 +76293,11 @@ |
| 76054 | 76293 | pRt->u.pFrame = pFrame; |
| 76055 | 76294 | |
| 76056 | 76295 | pFrame->v = p; |
| 76057 | 76296 | pFrame->nChildMem = nMem; |
| 76058 | 76297 | pFrame->nChildCsr = pProgram->nCsr; |
| 76059 | | - pFrame->pc = pc; |
| 76298 | + pFrame->pc = (int)(pOp - aOp); |
| 76060 | 76299 | pFrame->aMem = p->aMem; |
| 76061 | 76300 | pFrame->nMem = p->nMem; |
| 76062 | 76301 | pFrame->apCsr = p->apCsr; |
| 76063 | 76302 | pFrame->nCursor = p->nCursor; |
| 76064 | 76303 | pFrame->aOp = p->aOp; |
| | @@ -76077,11 +76316,11 @@ |
| 76077 | 76316 | } |
| 76078 | 76317 | }else{ |
| 76079 | 76318 | pFrame = pRt->u.pFrame; |
| 76080 | 76319 | assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem ); |
| 76081 | 76320 | assert( pProgram->nCsr==pFrame->nChildCsr ); |
| 76082 | | - assert( pc==pFrame->pc ); |
| 76321 | + assert( (int)(pOp - aOp)==pFrame->pc ); |
| 76083 | 76322 | } |
| 76084 | 76323 | |
| 76085 | 76324 | p->nFrame++; |
| 76086 | 76325 | pFrame->pParent = p->pFrame; |
| 76087 | 76326 | pFrame->lastRowid = lastRowid; |
| | @@ -76098,11 +76337,11 @@ |
| 76098 | 76337 | p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 76099 | 76338 | p->nOnceFlag = pProgram->nOnce; |
| 76100 | 76339 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 76101 | 76340 | p->anExec = 0; |
| 76102 | 76341 | #endif |
| 76103 | | - pc = -1; |
| 76342 | + pOp = &aOp[-1]; |
| 76104 | 76343 | memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 76105 | 76344 | |
| 76106 | 76345 | break; |
| 76107 | 76346 | } |
| 76108 | 76347 | |
| | @@ -76116,13 +76355,14 @@ |
| 76116 | 76355 | ** |
| 76117 | 76356 | ** The address of the cell in the parent frame is determined by adding |
| 76118 | 76357 | ** the value of the P1 argument to the value of the P1 argument to the |
| 76119 | 76358 | ** calling OP_Program instruction. |
| 76120 | 76359 | */ |
| 76121 | | -case OP_Param: { /* out2-prerelease */ |
| 76360 | +case OP_Param: { /* out2 */ |
| 76122 | 76361 | VdbeFrame *pFrame; |
| 76123 | 76362 | Mem *pIn; |
| 76363 | + pOut = out2Prerelease(p, pOp); |
| 76124 | 76364 | pFrame = p->pFrame; |
| 76125 | 76365 | pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1]; |
| 76126 | 76366 | sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem); |
| 76127 | 76367 | break; |
| 76128 | 76368 | } |
| | @@ -76162,14 +76402,14 @@ |
| 76162 | 76402 | ** (immediate foreign key constraint violations). |
| 76163 | 76403 | */ |
| 76164 | 76404 | case OP_FkIfZero: { /* jump */ |
| 76165 | 76405 | if( pOp->p1 ){ |
| 76166 | 76406 | VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2); |
| 76167 | | - if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1; |
| 76407 | + if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2; |
| 76168 | 76408 | }else{ |
| 76169 | 76409 | VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2); |
| 76170 | | - if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1; |
| 76410 | + if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2; |
| 76171 | 76411 | } |
| 76172 | 76412 | break; |
| 76173 | 76413 | } |
| 76174 | 76414 | #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */ |
| 76175 | 76415 | |
| | @@ -76216,13 +76456,11 @@ |
| 76216 | 76456 | */ |
| 76217 | 76457 | case OP_IfPos: { /* jump, in1 */ |
| 76218 | 76458 | pIn1 = &aMem[pOp->p1]; |
| 76219 | 76459 | assert( pIn1->flags&MEM_Int ); |
| 76220 | 76460 | VdbeBranchTaken( pIn1->u.i>0, 2); |
| 76221 | | - if( pIn1->u.i>0 ){ |
| 76222 | | - pc = pOp->p2 - 1; |
| 76223 | | - } |
| 76461 | + if( pIn1->u.i>0 ) goto jump_to_p2; |
| 76224 | 76462 | break; |
| 76225 | 76463 | } |
| 76226 | 76464 | |
| 76227 | 76465 | /* Opcode: IfNeg P1 P2 P3 * * |
| 76228 | 76466 | ** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2 |
| | @@ -76233,13 +76471,11 @@ |
| 76233 | 76471 | case OP_IfNeg: { /* jump, in1 */ |
| 76234 | 76472 | pIn1 = &aMem[pOp->p1]; |
| 76235 | 76473 | assert( pIn1->flags&MEM_Int ); |
| 76236 | 76474 | pIn1->u.i += pOp->p3; |
| 76237 | 76475 | VdbeBranchTaken(pIn1->u.i<0, 2); |
| 76238 | | - if( pIn1->u.i<0 ){ |
| 76239 | | - pc = pOp->p2 - 1; |
| 76240 | | - } |
| 76476 | + if( pIn1->u.i<0 ) goto jump_to_p2; |
| 76241 | 76477 | break; |
| 76242 | 76478 | } |
| 76243 | 76479 | |
| 76244 | 76480 | /* Opcode: IfNotZero P1 P2 P3 * * |
| 76245 | 76481 | ** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2 |
| | @@ -76252,11 +76488,11 @@ |
| 76252 | 76488 | pIn1 = &aMem[pOp->p1]; |
| 76253 | 76489 | assert( pIn1->flags&MEM_Int ); |
| 76254 | 76490 | VdbeBranchTaken(pIn1->u.i<0, 2); |
| 76255 | 76491 | if( pIn1->u.i ){ |
| 76256 | 76492 | pIn1->u.i += pOp->p3; |
| 76257 | | - pc = pOp->p2 - 1; |
| 76493 | + goto jump_to_p2; |
| 76258 | 76494 | } |
| 76259 | 76495 | break; |
| 76260 | 76496 | } |
| 76261 | 76497 | |
| 76262 | 76498 | /* Opcode: DecrJumpZero P1 P2 * * * |
| | @@ -76268,13 +76504,11 @@ |
| 76268 | 76504 | case OP_DecrJumpZero: { /* jump, in1 */ |
| 76269 | 76505 | pIn1 = &aMem[pOp->p1]; |
| 76270 | 76506 | assert( pIn1->flags&MEM_Int ); |
| 76271 | 76507 | pIn1->u.i--; |
| 76272 | 76508 | VdbeBranchTaken(pIn1->u.i==0, 2); |
| 76273 | | - if( pIn1->u.i==0 ){ |
| 76274 | | - pc = pOp->p2 - 1; |
| 76275 | | - } |
| 76509 | + if( pIn1->u.i==0 ) goto jump_to_p2; |
| 76276 | 76510 | break; |
| 76277 | 76511 | } |
| 76278 | 76512 | |
| 76279 | 76513 | |
| 76280 | 76514 | /* Opcode: JumpZeroIncr P1 P2 * * * |
| | @@ -76286,13 +76520,11 @@ |
| 76286 | 76520 | */ |
| 76287 | 76521 | case OP_JumpZeroIncr: { /* jump, in1 */ |
| 76288 | 76522 | pIn1 = &aMem[pOp->p1]; |
| 76289 | 76523 | assert( pIn1->flags&MEM_Int ); |
| 76290 | 76524 | VdbeBranchTaken(pIn1->u.i==0, 2); |
| 76291 | | - if( (pIn1->u.i++)==0 ){ |
| 76292 | | - pc = pOp->p2 - 1; |
| 76293 | | - } |
| 76525 | + if( (pIn1->u.i++)==0 ) goto jump_to_p2; |
| 76294 | 76526 | break; |
| 76295 | 76527 | } |
| 76296 | 76528 | |
| 76297 | 76529 | /* Opcode: AggStep * P2 P3 P4 P5 |
| 76298 | 76530 | ** Synopsis: accum=r[P3] step(r[P2@P5]) |
| | @@ -76330,11 +76562,11 @@ |
| 76330 | 76562 | pMem->n++; |
| 76331 | 76563 | sqlite3VdbeMemInit(&t, db, MEM_Null); |
| 76332 | 76564 | ctx.pOut = &t; |
| 76333 | 76565 | ctx.isError = 0; |
| 76334 | 76566 | ctx.pVdbe = p; |
| 76335 | | - ctx.iOp = pc; |
| 76567 | + ctx.iOp = (int)(pOp - aOp); |
| 76336 | 76568 | ctx.skipFlag = 0; |
| 76337 | 76569 | (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */ |
| 76338 | 76570 | if( ctx.isError ){ |
| 76339 | 76571 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t)); |
| 76340 | 76572 | rc = ctx.isError; |
| | @@ -76425,19 +76657,20 @@ |
| 76425 | 76657 | ** |
| 76426 | 76658 | ** If changing into or out of WAL mode the procedure is more complicated. |
| 76427 | 76659 | ** |
| 76428 | 76660 | ** Write a string containing the final journal-mode to register P2. |
| 76429 | 76661 | */ |
| 76430 | | -case OP_JournalMode: { /* out2-prerelease */ |
| 76662 | +case OP_JournalMode: { /* out2 */ |
| 76431 | 76663 | Btree *pBt; /* Btree to change journal mode of */ |
| 76432 | 76664 | Pager *pPager; /* Pager associated with pBt */ |
| 76433 | 76665 | int eNew; /* New journal mode */ |
| 76434 | 76666 | int eOld; /* The old journal mode */ |
| 76435 | 76667 | #ifndef SQLITE_OMIT_WAL |
| 76436 | 76668 | const char *zFilename; /* Name of database file for pPager */ |
| 76437 | 76669 | #endif |
| 76438 | 76670 | |
| 76671 | + pOut = out2Prerelease(p, pOp); |
| 76439 | 76672 | eNew = pOp->p3; |
| 76440 | 76673 | assert( eNew==PAGER_JOURNALMODE_DELETE |
| 76441 | 76674 | || eNew==PAGER_JOURNALMODE_TRUNCATE |
| 76442 | 76675 | || eNew==PAGER_JOURNALMODE_PERSIST |
| 76443 | 76676 | || eNew==PAGER_JOURNALMODE_OFF |
| | @@ -76509,11 +76742,10 @@ |
| 76509 | 76742 | if( rc ){ |
| 76510 | 76743 | eNew = eOld; |
| 76511 | 76744 | } |
| 76512 | 76745 | eNew = sqlite3PagerSetJournalMode(pPager, eNew); |
| 76513 | 76746 | |
| 76514 | | - pOut = &aMem[pOp->p2]; |
| 76515 | 76747 | pOut->flags = MEM_Str|MEM_Static|MEM_Term; |
| 76516 | 76748 | pOut->z = (char *)sqlite3JournalModename(eNew); |
| 76517 | 76749 | pOut->n = sqlite3Strlen30(pOut->z); |
| 76518 | 76750 | pOut->enc = SQLITE_UTF8; |
| 76519 | 76751 | sqlite3VdbeChangeEncoding(pOut, encoding); |
| | @@ -76550,12 +76782,12 @@ |
| 76550 | 76782 | assert( p->readOnly==0 ); |
| 76551 | 76783 | pBt = db->aDb[pOp->p1].pBt; |
| 76552 | 76784 | rc = sqlite3BtreeIncrVacuum(pBt); |
| 76553 | 76785 | VdbeBranchTaken(rc==SQLITE_DONE,2); |
| 76554 | 76786 | if( rc==SQLITE_DONE ){ |
| 76555 | | - pc = pOp->p2 - 1; |
| 76556 | 76787 | rc = SQLITE_OK; |
| 76788 | + goto jump_to_p2; |
| 76557 | 76789 | } |
| 76558 | 76790 | break; |
| 76559 | 76791 | } |
| 76560 | 76792 | #endif |
| 76561 | 76793 | |
| | @@ -76704,12 +76936,13 @@ |
| 76704 | 76936 | pCur = allocateCursor(p, pOp->p1, 0, -1, 0); |
| 76705 | 76937 | if( pCur ){ |
| 76706 | 76938 | pCur->pVtabCursor = pVtabCursor; |
| 76707 | 76939 | pVtab->nRef++; |
| 76708 | 76940 | }else{ |
| 76709 | | - db->mallocFailed = 1; |
| 76941 | + assert( db->mallocFailed ); |
| 76710 | 76942 | pModule->xClose(pVtabCursor); |
| 76943 | + goto no_mem; |
| 76711 | 76944 | } |
| 76712 | 76945 | } |
| 76713 | 76946 | break; |
| 76714 | 76947 | } |
| 76715 | 76948 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| | @@ -76761,29 +76994,23 @@ |
| 76761 | 76994 | assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int ); |
| 76762 | 76995 | nArg = (int)pArgc->u.i; |
| 76763 | 76996 | iQuery = (int)pQuery->u.i; |
| 76764 | 76997 | |
| 76765 | 76998 | /* Invoke the xFilter method */ |
| 76766 | | - { |
| 76767 | | - res = 0; |
| 76768 | | - apArg = p->apArg; |
| 76769 | | - for(i = 0; i<nArg; i++){ |
| 76770 | | - apArg[i] = &pArgc[i+1]; |
| 76771 | | - } |
| 76772 | | - |
| 76773 | | - rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); |
| 76774 | | - sqlite3VtabImportErrmsg(p, pVtab); |
| 76775 | | - if( rc==SQLITE_OK ){ |
| 76776 | | - res = pModule->xEof(pVtabCursor); |
| 76777 | | - } |
| 76778 | | - VdbeBranchTaken(res!=0,2); |
| 76779 | | - if( res ){ |
| 76780 | | - pc = pOp->p2 - 1; |
| 76781 | | - } |
| 76999 | + res = 0; |
| 77000 | + apArg = p->apArg; |
| 77001 | + for(i = 0; i<nArg; i++){ |
| 77002 | + apArg[i] = &pArgc[i+1]; |
| 77003 | + } |
| 77004 | + rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); |
| 77005 | + sqlite3VtabImportErrmsg(p, pVtab); |
| 77006 | + if( rc==SQLITE_OK ){ |
| 77007 | + res = pModule->xEof(pVtabCursor); |
| 76782 | 77008 | } |
| 76783 | 77009 | pCur->nullRow = 0; |
| 76784 | | - |
| 77010 | + VdbeBranchTaken(res!=0,2); |
| 77011 | + if( res ) goto jump_to_p2; |
| 76785 | 77012 | break; |
| 76786 | 77013 | } |
| 76787 | 77014 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 76788 | 77015 | |
| 76789 | 77016 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -76866,11 +77093,11 @@ |
| 76866 | 77093 | res = pModule->xEof(pCur->pVtabCursor); |
| 76867 | 77094 | } |
| 76868 | 77095 | VdbeBranchTaken(!res,2); |
| 76869 | 77096 | if( !res ){ |
| 76870 | 77097 | /* If there is data, jump to P2 */ |
| 76871 | | - pc = pOp->p2 - 1; |
| 77098 | + goto jump_to_p2_and_check_for_interrupt; |
| 76872 | 77099 | } |
| 76873 | 77100 | goto check_for_interrupt; |
| 76874 | 77101 | } |
| 76875 | 77102 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 76876 | 77103 | |
| | @@ -76989,11 +77216,12 @@ |
| 76989 | 77216 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 76990 | 77217 | /* Opcode: Pagecount P1 P2 * * * |
| 76991 | 77218 | ** |
| 76992 | 77219 | ** Write the current number of pages in database P1 to memory cell P2. |
| 76993 | 77220 | */ |
| 76994 | | -case OP_Pagecount: { /* out2-prerelease */ |
| 77221 | +case OP_Pagecount: { /* out2 */ |
| 77222 | + pOut = out2Prerelease(p, pOp); |
| 76995 | 77223 | pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt); |
| 76996 | 77224 | break; |
| 76997 | 77225 | } |
| 76998 | 77226 | #endif |
| 76999 | 77227 | |
| | @@ -77005,14 +77233,15 @@ |
| 77005 | 77233 | ** Do not let the maximum page count fall below the current page count and |
| 77006 | 77234 | ** do not change the maximum page count value if P3==0. |
| 77007 | 77235 | ** |
| 77008 | 77236 | ** Store the maximum page count after the change in register P2. |
| 77009 | 77237 | */ |
| 77010 | | -case OP_MaxPgcnt: { /* out2-prerelease */ |
| 77238 | +case OP_MaxPgcnt: { /* out2 */ |
| 77011 | 77239 | unsigned int newMax; |
| 77012 | 77240 | Btree *pBt; |
| 77013 | 77241 | |
| 77242 | + pOut = out2Prerelease(p, pOp); |
| 77014 | 77243 | pBt = db->aDb[pOp->p1].pBt; |
| 77015 | 77244 | newMax = 0; |
| 77016 | 77245 | if( pOp->p3 ){ |
| 77017 | 77246 | newMax = sqlite3BtreeLastPage(pBt); |
| 77018 | 77247 | if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3; |
| | @@ -77037,13 +77266,10 @@ |
| 77037 | 77266 | */ |
| 77038 | 77267 | case OP_Init: { /* jump */ |
| 77039 | 77268 | char *zTrace; |
| 77040 | 77269 | char *z; |
| 77041 | 77270 | |
| 77042 | | - if( pOp->p2 ){ |
| 77043 | | - pc = pOp->p2 - 1; |
| 77044 | | - } |
| 77045 | 77271 | #ifndef SQLITE_OMIT_TRACE |
| 77046 | 77272 | if( db->xTrace |
| 77047 | 77273 | && !p->doingRerun |
| 77048 | 77274 | && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 77049 | 77275 | ){ |
| | @@ -77067,10 +77293,11 @@ |
| 77067 | 77293 | ){ |
| 77068 | 77294 | sqlite3DebugPrintf("SQL-trace: %s\n", zTrace); |
| 77069 | 77295 | } |
| 77070 | 77296 | #endif /* SQLITE_DEBUG */ |
| 77071 | 77297 | #endif /* SQLITE_OMIT_TRACE */ |
| 77298 | + if( pOp->p2 ) goto jump_to_p2; |
| 77072 | 77299 | break; |
| 77073 | 77300 | } |
| 77074 | 77301 | |
| 77075 | 77302 | |
| 77076 | 77303 | /* Opcode: Noop * * * * * |
| | @@ -77098,31 +77325,31 @@ |
| 77098 | 77325 | } |
| 77099 | 77326 | |
| 77100 | 77327 | #ifdef VDBE_PROFILE |
| 77101 | 77328 | { |
| 77102 | 77329 | u64 endTime = sqlite3Hwtime(); |
| 77103 | | - if( endTime>start ) pOp->cycles += endTime - start; |
| 77104 | | - pOp->cnt++; |
| 77330 | + if( endTime>start ) pOrigOp->cycles += endTime - start; |
| 77331 | + pOrigOp->cnt++; |
| 77105 | 77332 | } |
| 77106 | 77333 | #endif |
| 77107 | 77334 | |
| 77108 | 77335 | /* The following code adds nothing to the actual functionality |
| 77109 | 77336 | ** of the program. It is only here for testing and debugging. |
| 77110 | 77337 | ** On the other hand, it does burn CPU cycles every time through |
| 77111 | 77338 | ** the evaluator loop. So we can leave it out when NDEBUG is defined. |
| 77112 | 77339 | */ |
| 77113 | 77340 | #ifndef NDEBUG |
| 77114 | | - assert( pc>=-1 && pc<p->nOp ); |
| 77341 | + assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] ); |
| 77115 | 77342 | |
| 77116 | 77343 | #ifdef SQLITE_DEBUG |
| 77117 | 77344 | if( db->flags & SQLITE_VdbeTrace ){ |
| 77118 | 77345 | if( rc!=0 ) printf("rc=%d\n",rc); |
| 77119 | | - if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){ |
| 77120 | | - registerTrace(pOp->p2, &aMem[pOp->p2]); |
| 77346 | + if( pOrigOp->opflags & (OPFLG_OUT2) ){ |
| 77347 | + registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]); |
| 77121 | 77348 | } |
| 77122 | | - if( pOp->opflags & OPFLG_OUT3 ){ |
| 77123 | | - registerTrace(pOp->p3, &aMem[pOp->p3]); |
| 77349 | + if( pOrigOp->opflags & OPFLG_OUT3 ){ |
| 77350 | + registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]); |
| 77124 | 77351 | } |
| 77125 | 77352 | } |
| 77126 | 77353 | #endif /* SQLITE_DEBUG */ |
| 77127 | 77354 | #endif /* NDEBUG */ |
| 77128 | 77355 | } /* The end of the for(;;) loop the loops through opcodes */ |
| | @@ -77133,11 +77360,11 @@ |
| 77133 | 77360 | vdbe_error_halt: |
| 77134 | 77361 | assert( rc ); |
| 77135 | 77362 | p->rc = rc; |
| 77136 | 77363 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 77137 | 77364 | sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 77138 | | - pc, p->zSql, p->zErrMsg); |
| 77365 | + (int)(pOp - aOp), p->zSql, p->zErrMsg); |
| 77139 | 77366 | sqlite3VdbeHalt(p); |
| 77140 | 77367 | if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; |
| 77141 | 77368 | rc = SQLITE_ERROR; |
| 77142 | 77369 | if( resetSchemaOnFault>0 ){ |
| 77143 | 77370 | sqlite3ResetOneSchema(db, resetSchemaOnFault-1); |
| | @@ -77296,11 +77523,11 @@ |
| 77296 | 77523 | } |
| 77297 | 77524 | |
| 77298 | 77525 | /* |
| 77299 | 77526 | ** Open a blob handle. |
| 77300 | 77527 | */ |
| 77301 | | -SQLITE_API int sqlite3_blob_open( |
| 77528 | +SQLITE_API int SQLITE_STDCALL sqlite3_blob_open( |
| 77302 | 77529 | sqlite3* db, /* The database connection */ |
| 77303 | 77530 | const char *zDb, /* The attached database containing the blob */ |
| 77304 | 77531 | const char *zTable, /* The table containing the blob */ |
| 77305 | 77532 | const char *zColumn, /* The column containing the blob */ |
| 77306 | 77533 | sqlite_int64 iRow, /* The row containing the glob */ |
| | @@ -77533,11 +77760,11 @@ |
| 77533 | 77760 | |
| 77534 | 77761 | /* |
| 77535 | 77762 | ** Close a blob handle that was previously created using |
| 77536 | 77763 | ** sqlite3_blob_open(). |
| 77537 | 77764 | */ |
| 77538 | | -SQLITE_API int sqlite3_blob_close(sqlite3_blob *pBlob){ |
| 77765 | +SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *pBlob){ |
| 77539 | 77766 | Incrblob *p = (Incrblob *)pBlob; |
| 77540 | 77767 | int rc; |
| 77541 | 77768 | sqlite3 *db; |
| 77542 | 77769 | |
| 77543 | 77770 | if( p ){ |
| | @@ -77602,28 +77829,28 @@ |
| 77602 | 77829 | } |
| 77603 | 77830 | |
| 77604 | 77831 | /* |
| 77605 | 77832 | ** Read data from a blob handle. |
| 77606 | 77833 | */ |
| 77607 | | -SQLITE_API int sqlite3_blob_read(sqlite3_blob *pBlob, void *z, int n, int iOffset){ |
| 77834 | +SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *pBlob, void *z, int n, int iOffset){ |
| 77608 | 77835 | return blobReadWrite(pBlob, z, n, iOffset, sqlite3BtreeData); |
| 77609 | 77836 | } |
| 77610 | 77837 | |
| 77611 | 77838 | /* |
| 77612 | 77839 | ** Write data to a blob handle. |
| 77613 | 77840 | */ |
| 77614 | | -SQLITE_API int sqlite3_blob_write(sqlite3_blob *pBlob, const void *z, int n, int iOffset){ |
| 77841 | +SQLITE_API int SQLITE_STDCALL sqlite3_blob_write(sqlite3_blob *pBlob, const void *z, int n, int iOffset){ |
| 77615 | 77842 | return blobReadWrite(pBlob, (void *)z, n, iOffset, sqlite3BtreePutData); |
| 77616 | 77843 | } |
| 77617 | 77844 | |
| 77618 | 77845 | /* |
| 77619 | 77846 | ** Query a blob handle for the size of the data. |
| 77620 | 77847 | ** |
| 77621 | 77848 | ** The Incrblob.nByte field is fixed for the lifetime of the Incrblob |
| 77622 | 77849 | ** so no mutex is required for access. |
| 77623 | 77850 | */ |
| 77624 | | -SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *pBlob){ |
| 77851 | +SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *pBlob){ |
| 77625 | 77852 | Incrblob *p = (Incrblob *)pBlob; |
| 77626 | 77853 | return (p && p->pStmt) ? p->nByte : 0; |
| 77627 | 77854 | } |
| 77628 | 77855 | |
| 77629 | 77856 | /* |
| | @@ -77634,11 +77861,11 @@ |
| 77634 | 77861 | ** contain a blob or text value, then an error code is returned and the |
| 77635 | 77862 | ** database handle error code and message set. If this happens, then all |
| 77636 | 77863 | ** subsequent calls to sqlite3_blob_xxx() functions (except blob_close()) |
| 77637 | 77864 | ** immediately return SQLITE_ABORT. |
| 77638 | 77865 | */ |
| 77639 | | -SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *pBlob, sqlite3_int64 iRow){ |
| 77866 | +SQLITE_API int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *pBlob, sqlite3_int64 iRow){ |
| 77640 | 77867 | int rc; |
| 77641 | 77868 | Incrblob *p = (Incrblob *)pBlob; |
| 77642 | 77869 | sqlite3 *db; |
| 77643 | 77870 | |
| 77644 | 77871 | if( p==0 ) return SQLITE_MISUSE_BKPT; |
| | @@ -77959,20 +78186,23 @@ |
| 77959 | 78186 | ** |
| 77960 | 78187 | ** In both cases, the effects of the main thread seeing (bDone==0) even |
| 77961 | 78188 | ** after the thread has finished are not dire. So we don't worry about |
| 77962 | 78189 | ** memory barriers and such here. |
| 77963 | 78190 | */ |
| 78191 | +typedef int (*SorterCompare)(SortSubtask*,int*,const void*,int,const void*,int); |
| 77964 | 78192 | struct SortSubtask { |
| 77965 | 78193 | SQLiteThread *pThread; /* Background thread, if any */ |
| 77966 | 78194 | int bDone; /* Set if thread is finished but not joined */ |
| 77967 | 78195 | VdbeSorter *pSorter; /* Sorter that owns this sub-task */ |
| 77968 | 78196 | UnpackedRecord *pUnpacked; /* Space to unpack a record */ |
| 77969 | 78197 | SorterList list; /* List for thread to write to a PMA */ |
| 77970 | 78198 | int nPMA; /* Number of PMAs currently in file */ |
| 78199 | + SorterCompare xCompare; /* Compare function to use */ |
| 77971 | 78200 | SorterFile file; /* Temp file for level-0 PMAs */ |
| 77972 | 78201 | SorterFile file2; /* Space for other PMAs */ |
| 77973 | 78202 | }; |
| 78203 | + |
| 77974 | 78204 | |
| 77975 | 78205 | /* |
| 77976 | 78206 | ** Main sorter structure. A single instance of this is allocated for each |
| 77977 | 78207 | ** sorter cursor created by the VDBE. |
| 77978 | 78208 | ** |
| | @@ -77996,12 +78226,16 @@ |
| 77996 | 78226 | int nMemory; /* Size of list.aMemory allocation in bytes */ |
| 77997 | 78227 | u8 bUsePMA; /* True if one or more PMAs created */ |
| 77998 | 78228 | u8 bUseThreads; /* True to use background threads */ |
| 77999 | 78229 | u8 iPrev; /* Previous thread used to flush PMA */ |
| 78000 | 78230 | u8 nTask; /* Size of aTask[] array */ |
| 78231 | + u8 typeMask; |
| 78001 | 78232 | SortSubtask aTask[1]; /* One or more subtasks */ |
| 78002 | 78233 | }; |
| 78234 | + |
| 78235 | +#define SORTER_TYPE_INTEGER 0x01 |
| 78236 | +#define SORTER_TYPE_TEXT 0x02 |
| 78003 | 78237 | |
| 78004 | 78238 | /* |
| 78005 | 78239 | ** An instance of the following object is used to read records out of a |
| 78006 | 78240 | ** PMA, in sorted order. The next key to be read is cached in nKey/aKey. |
| 78007 | 78241 | ** aKey might point into aMap or into aBuffer. If neither of those locations |
| | @@ -78410,35 +78644,165 @@ |
| 78410 | 78644 | rc = vdbePmaReaderNext(pReadr); |
| 78411 | 78645 | } |
| 78412 | 78646 | return rc; |
| 78413 | 78647 | } |
| 78414 | 78648 | |
| 78649 | +/* |
| 78650 | +** A version of vdbeSorterCompare() that assumes that it has already been |
| 78651 | +** determined that the first field of key1 is equal to the first field of |
| 78652 | +** key2. |
| 78653 | +*/ |
| 78654 | +static int vdbeSorterCompareTail( |
| 78655 | + SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ |
| 78656 | + int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ |
| 78657 | + const void *pKey1, int nKey1, /* Left side of comparison */ |
| 78658 | + const void *pKey2, int nKey2 /* Right side of comparison */ |
| 78659 | +){ |
| 78660 | + UnpackedRecord *r2 = pTask->pUnpacked; |
| 78661 | + if( *pbKey2Cached==0 ){ |
| 78662 | + sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); |
| 78663 | + *pbKey2Cached = 1; |
| 78664 | + } |
| 78665 | + return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1); |
| 78666 | +} |
| 78415 | 78667 | |
| 78416 | 78668 | /* |
| 78417 | 78669 | ** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2, |
| 78418 | 78670 | ** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences |
| 78419 | 78671 | ** used by the comparison. Return the result of the comparison. |
| 78420 | 78672 | ** |
| 78421 | | -** Before returning, object (pTask->pUnpacked) is populated with the |
| 78422 | | -** unpacked version of key2. Or, if pKey2 is passed a NULL pointer, then it |
| 78423 | | -** is assumed that the (pTask->pUnpacked) structure already contains the |
| 78424 | | -** unpacked key to use as key2. |
| 78673 | +** If IN/OUT parameter *pbKey2Cached is true when this function is called, |
| 78674 | +** it is assumed that (pTask->pUnpacked) contains the unpacked version |
| 78675 | +** of key2. If it is false, (pTask->pUnpacked) is populated with the unpacked |
| 78676 | +** version of key2 and *pbKey2Cached set to true before returning. |
| 78425 | 78677 | ** |
| 78426 | 78678 | ** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set |
| 78427 | 78679 | ** to SQLITE_NOMEM. |
| 78428 | 78680 | */ |
| 78429 | 78681 | static int vdbeSorterCompare( |
| 78430 | 78682 | SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ |
| 78683 | + int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ |
| 78431 | 78684 | const void *pKey1, int nKey1, /* Left side of comparison */ |
| 78432 | 78685 | const void *pKey2, int nKey2 /* Right side of comparison */ |
| 78433 | 78686 | ){ |
| 78434 | 78687 | UnpackedRecord *r2 = pTask->pUnpacked; |
| 78435 | | - if( pKey2 ){ |
| 78688 | + if( !*pbKey2Cached ){ |
| 78436 | 78689 | sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); |
| 78690 | + *pbKey2Cached = 1; |
| 78437 | 78691 | } |
| 78438 | 78692 | return sqlite3VdbeRecordCompare(nKey1, pKey1, r2); |
| 78439 | 78693 | } |
| 78694 | + |
| 78695 | +/* |
| 78696 | +** A specially optimized version of vdbeSorterCompare() that assumes that |
| 78697 | +** the first field of each key is a TEXT value and that the collation |
| 78698 | +** sequence to compare them with is BINARY. |
| 78699 | +*/ |
| 78700 | +static int vdbeSorterCompareText( |
| 78701 | + SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ |
| 78702 | + int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ |
| 78703 | + const void *pKey1, int nKey1, /* Left side of comparison */ |
| 78704 | + const void *pKey2, int nKey2 /* Right side of comparison */ |
| 78705 | +){ |
| 78706 | + const u8 * const p1 = (const u8 * const)pKey1; |
| 78707 | + const u8 * const p2 = (const u8 * const)pKey2; |
| 78708 | + const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */ |
| 78709 | + const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */ |
| 78710 | + |
| 78711 | + int n1; |
| 78712 | + int n2; |
| 78713 | + int res; |
| 78714 | + |
| 78715 | + getVarint32(&p1[1], n1); n1 = (n1 - 13) / 2; |
| 78716 | + getVarint32(&p2[1], n2); n2 = (n2 - 13) / 2; |
| 78717 | + res = memcmp(v1, v2, MIN(n1, n2)); |
| 78718 | + if( res==0 ){ |
| 78719 | + res = n1 - n2; |
| 78720 | + } |
| 78721 | + |
| 78722 | + if( res==0 ){ |
| 78723 | + if( pTask->pSorter->pKeyInfo->nField>1 ){ |
| 78724 | + res = vdbeSorterCompareTail( |
| 78725 | + pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2 |
| 78726 | + ); |
| 78727 | + } |
| 78728 | + }else{ |
| 78729 | + if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ |
| 78730 | + res = res * -1; |
| 78731 | + } |
| 78732 | + } |
| 78733 | + |
| 78734 | + return res; |
| 78735 | +} |
| 78736 | + |
| 78737 | +/* |
| 78738 | +** A specially optimized version of vdbeSorterCompare() that assumes that |
| 78739 | +** the first field of each key is an INTEGER value. |
| 78740 | +*/ |
| 78741 | +static int vdbeSorterCompareInt( |
| 78742 | + SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ |
| 78743 | + int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ |
| 78744 | + const void *pKey1, int nKey1, /* Left side of comparison */ |
| 78745 | + const void *pKey2, int nKey2 /* Right side of comparison */ |
| 78746 | +){ |
| 78747 | + const u8 * const p1 = (const u8 * const)pKey1; |
| 78748 | + const u8 * const p2 = (const u8 * const)pKey2; |
| 78749 | + const int s1 = p1[1]; /* Left hand serial type */ |
| 78750 | + const int s2 = p2[1]; /* Right hand serial type */ |
| 78751 | + const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */ |
| 78752 | + const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */ |
| 78753 | + int res; /* Return value */ |
| 78754 | + |
| 78755 | + assert( (s1>0 && s1<7) || s1==8 || s1==9 ); |
| 78756 | + assert( (s2>0 && s2<7) || s2==8 || s2==9 ); |
| 78757 | + |
| 78758 | + if( s1>7 && s2>7 ){ |
| 78759 | + res = s1 - s2; |
| 78760 | + }else{ |
| 78761 | + if( s1==s2 ){ |
| 78762 | + if( (*v1 ^ *v2) & 0x80 ){ |
| 78763 | + /* The two values have different signs */ |
| 78764 | + res = (*v1 & 0x80) ? -1 : +1; |
| 78765 | + }else{ |
| 78766 | + /* The two values have the same sign. Compare using memcmp(). */ |
| 78767 | + static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 }; |
| 78768 | + int i; |
| 78769 | + res = 0; |
| 78770 | + for(i=0; i<aLen[s1]; i++){ |
| 78771 | + if( (res = v1[i] - v2[i]) ) break; |
| 78772 | + } |
| 78773 | + } |
| 78774 | + }else{ |
| 78775 | + if( s2>7 ){ |
| 78776 | + res = +1; |
| 78777 | + }else if( s1>7 ){ |
| 78778 | + res = -1; |
| 78779 | + }else{ |
| 78780 | + res = s1 - s2; |
| 78781 | + } |
| 78782 | + assert( res!=0 ); |
| 78783 | + |
| 78784 | + if( res>0 ){ |
| 78785 | + if( *v1 & 0x80 ) res = -1; |
| 78786 | + }else{ |
| 78787 | + if( *v2 & 0x80 ) res = +1; |
| 78788 | + } |
| 78789 | + } |
| 78790 | + } |
| 78791 | + |
| 78792 | + if( res==0 ){ |
| 78793 | + if( pTask->pSorter->pKeyInfo->nField>1 ){ |
| 78794 | + res = vdbeSorterCompareTail( |
| 78795 | + pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2 |
| 78796 | + ); |
| 78797 | + } |
| 78798 | + }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ |
| 78799 | + res = res * -1; |
| 78800 | + } |
| 78801 | + |
| 78802 | + return res; |
| 78803 | +} |
| 78440 | 78804 | |
| 78441 | 78805 | /* |
| 78442 | 78806 | ** Initialize the temporary index cursor just opened as a sorter cursor. |
| 78443 | 78807 | ** |
| 78444 | 78808 | ** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField) |
| | @@ -78503,13 +78867,17 @@ |
| 78503 | 78867 | rc = SQLITE_NOMEM; |
| 78504 | 78868 | }else{ |
| 78505 | 78869 | pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz); |
| 78506 | 78870 | memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo); |
| 78507 | 78871 | pKeyInfo->db = 0; |
| 78508 | | - if( nField && nWorker==0 ) pKeyInfo->nField = nField; |
| 78872 | + if( nField && nWorker==0 ){ |
| 78873 | + pKeyInfo->nXField += (pKeyInfo->nField - nField); |
| 78874 | + pKeyInfo->nField = nField; |
| 78875 | + } |
| 78509 | 78876 | pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt); |
| 78510 | 78877 | pSorter->nTask = nWorker + 1; |
| 78878 | + pSorter->iPrev = nWorker-1; |
| 78511 | 78879 | pSorter->bUseThreads = (pSorter->nTask>1); |
| 78512 | 78880 | pSorter->db = db; |
| 78513 | 78881 | for(i=0; i<pSorter->nTask; i++){ |
| 78514 | 78882 | SortSubtask *pTask = &pSorter->aTask[i]; |
| 78515 | 78883 | pTask->pSorter = pSorter; |
| | @@ -78531,10 +78899,16 @@ |
| 78531 | 78899 | pSorter->nMemory = pgsz; |
| 78532 | 78900 | pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz); |
| 78533 | 78901 | if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM; |
| 78534 | 78902 | } |
| 78535 | 78903 | } |
| 78904 | + |
| 78905 | + if( (pKeyInfo->nField+pKeyInfo->nXField)<13 |
| 78906 | + && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl) |
| 78907 | + ){ |
| 78908 | + pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT; |
| 78909 | + } |
| 78536 | 78910 | } |
| 78537 | 78911 | |
| 78538 | 78912 | return rc; |
| 78539 | 78913 | } |
| 78540 | 78914 | #undef nWorker /* Defined at the top of this function */ |
| | @@ -78555,34 +78929,28 @@ |
| 78555 | 78929 | ** Free all resources owned by the object indicated by argument pTask. All |
| 78556 | 78930 | ** fields of *pTask are zeroed before returning. |
| 78557 | 78931 | */ |
| 78558 | 78932 | static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){ |
| 78559 | 78933 | sqlite3DbFree(db, pTask->pUnpacked); |
| 78560 | | - pTask->pUnpacked = 0; |
| 78561 | 78934 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 78562 | 78935 | /* pTask->list.aMemory can only be non-zero if it was handed memory |
| 78563 | 78936 | ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */ |
| 78564 | 78937 | if( pTask->list.aMemory ){ |
| 78565 | 78938 | sqlite3_free(pTask->list.aMemory); |
| 78566 | | - pTask->list.aMemory = 0; |
| 78567 | 78939 | }else |
| 78568 | 78940 | #endif |
| 78569 | 78941 | { |
| 78570 | 78942 | assert( pTask->list.aMemory==0 ); |
| 78571 | 78943 | vdbeSorterRecordFree(0, pTask->list.pList); |
| 78572 | 78944 | } |
| 78573 | | - pTask->list.pList = 0; |
| 78574 | 78945 | if( pTask->file.pFd ){ |
| 78575 | 78946 | sqlite3OsCloseFree(pTask->file.pFd); |
| 78576 | | - pTask->file.pFd = 0; |
| 78577 | | - pTask->file.iEof = 0; |
| 78578 | 78947 | } |
| 78579 | 78948 | if( pTask->file2.pFd ){ |
| 78580 | 78949 | sqlite3OsCloseFree(pTask->file2.pFd); |
| 78581 | | - pTask->file2.pFd = 0; |
| 78582 | | - pTask->file2.iEof = 0; |
| 78583 | 78950 | } |
| 78951 | + memset(pTask, 0, sizeof(SortSubtask)); |
| 78584 | 78952 | } |
| 78585 | 78953 | |
| 78586 | 78954 | #ifdef SQLITE_DEBUG_SORTER_THREADS |
| 78587 | 78955 | static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){ |
| 78588 | 78956 | i64 t; |
| | @@ -78758,10 +79126,11 @@ |
| 78758 | 79126 | vdbeMergeEngineFree(pSorter->pMerger); |
| 78759 | 79127 | pSorter->pMerger = 0; |
| 78760 | 79128 | for(i=0; i<pSorter->nTask; i++){ |
| 78761 | 79129 | SortSubtask *pTask = &pSorter->aTask[i]; |
| 78762 | 79130 | vdbeSortSubtaskCleanup(db, pTask); |
| 79131 | + pTask->pSorter = pSorter; |
| 78763 | 79132 | } |
| 78764 | 79133 | if( pSorter->list.aMemory==0 ){ |
| 78765 | 79134 | vdbeSorterRecordFree(0, pSorter->list.pList); |
| 78766 | 79135 | } |
| 78767 | 79136 | pSorter->list.pList = 0; |
| | @@ -78867,31 +79236,45 @@ |
| 78867 | 79236 | SorterRecord *p2, /* Second list to merge */ |
| 78868 | 79237 | SorterRecord **ppOut /* OUT: Head of merged list */ |
| 78869 | 79238 | ){ |
| 78870 | 79239 | SorterRecord *pFinal = 0; |
| 78871 | 79240 | SorterRecord **pp = &pFinal; |
| 78872 | | - void *pVal2 = p2 ? SRVAL(p2) : 0; |
| 79241 | + int bCached = 0; |
| 78873 | 79242 | |
| 78874 | 79243 | while( p1 && p2 ){ |
| 78875 | 79244 | int res; |
| 78876 | | - res = vdbeSorterCompare(pTask, SRVAL(p1), p1->nVal, pVal2, p2->nVal); |
| 79245 | + res = pTask->xCompare( |
| 79246 | + pTask, &bCached, SRVAL(p1), p1->nVal, SRVAL(p2), p2->nVal |
| 79247 | + ); |
| 79248 | + |
| 78877 | 79249 | if( res<=0 ){ |
| 78878 | 79250 | *pp = p1; |
| 78879 | 79251 | pp = &p1->u.pNext; |
| 78880 | 79252 | p1 = p1->u.pNext; |
| 78881 | | - pVal2 = 0; |
| 78882 | 79253 | }else{ |
| 78883 | 79254 | *pp = p2; |
| 78884 | | - pp = &p2->u.pNext; |
| 79255 | + pp = &p2->u.pNext; |
| 78885 | 79256 | p2 = p2->u.pNext; |
| 78886 | | - if( p2==0 ) break; |
| 78887 | | - pVal2 = SRVAL(p2); |
| 79257 | + bCached = 0; |
| 78888 | 79258 | } |
| 78889 | 79259 | } |
| 78890 | 79260 | *pp = p1 ? p1 : p2; |
| 78891 | 79261 | *ppOut = pFinal; |
| 78892 | 79262 | } |
| 79263 | + |
| 79264 | +/* |
| 79265 | +** Return the SorterCompare function to compare values collected by the |
| 79266 | +** sorter object passed as the only argument. |
| 79267 | +*/ |
| 79268 | +static SorterCompare vdbeSorterGetCompare(VdbeSorter *p){ |
| 79269 | + if( p->typeMask==SORTER_TYPE_INTEGER ){ |
| 79270 | + return vdbeSorterCompareInt; |
| 79271 | + }else if( p->typeMask==SORTER_TYPE_TEXT ){ |
| 79272 | + return vdbeSorterCompareText; |
| 79273 | + } |
| 79274 | + return vdbeSorterCompare; |
| 79275 | +} |
| 78893 | 79276 | |
| 78894 | 79277 | /* |
| 78895 | 79278 | ** Sort the linked list of records headed at pTask->pList. Return |
| 78896 | 79279 | ** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if |
| 78897 | 79280 | ** an error occurs. |
| | @@ -78903,16 +79286,18 @@ |
| 78903 | 79286 | int rc; |
| 78904 | 79287 | |
| 78905 | 79288 | rc = vdbeSortAllocUnpacked(pTask); |
| 78906 | 79289 | if( rc!=SQLITE_OK ) return rc; |
| 78907 | 79290 | |
| 79291 | + p = pList->pList; |
| 79292 | + pTask->xCompare = vdbeSorterGetCompare(pTask->pSorter); |
| 79293 | + |
| 78908 | 79294 | aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *)); |
| 78909 | 79295 | if( !aSlot ){ |
| 78910 | 79296 | return SQLITE_NOMEM; |
| 78911 | 79297 | } |
| 78912 | 79298 | |
| 78913 | | - p = pList->pList; |
| 78914 | 79299 | while( p ){ |
| 78915 | 79300 | SorterRecord *pNext; |
| 78916 | 79301 | if( pList->aMemory ){ |
| 78917 | 79302 | if( (u8*)p==pList->aMemory ){ |
| 78918 | 79303 | pNext = 0; |
| | @@ -79122,28 +79507,27 @@ |
| 79122 | 79507 | /* Update contents of aTree[] */ |
| 79123 | 79508 | if( rc==SQLITE_OK ){ |
| 79124 | 79509 | int i; /* Index of aTree[] to recalculate */ |
| 79125 | 79510 | PmaReader *pReadr1; /* First PmaReader to compare */ |
| 79126 | 79511 | PmaReader *pReadr2; /* Second PmaReader to compare */ |
| 79127 | | - u8 *pKey2; /* To pReadr2->aKey, or 0 if record cached */ |
| 79512 | + int bCached = 0; |
| 79128 | 79513 | |
| 79129 | 79514 | /* Find the first two PmaReaders to compare. The one that was just |
| 79130 | 79515 | ** advanced (iPrev) and the one next to it in the array. */ |
| 79131 | 79516 | pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)]; |
| 79132 | 79517 | pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)]; |
| 79133 | | - pKey2 = pReadr2->aKey; |
| 79134 | 79518 | |
| 79135 | 79519 | for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){ |
| 79136 | 79520 | /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */ |
| 79137 | 79521 | int iRes; |
| 79138 | 79522 | if( pReadr1->pFd==0 ){ |
| 79139 | 79523 | iRes = +1; |
| 79140 | 79524 | }else if( pReadr2->pFd==0 ){ |
| 79141 | 79525 | iRes = -1; |
| 79142 | 79526 | }else{ |
| 79143 | | - iRes = vdbeSorterCompare(pTask, |
| 79144 | | - pReadr1->aKey, pReadr1->nKey, pKey2, pReadr2->nKey |
| 79527 | + iRes = pTask->xCompare(pTask, &bCached, |
| 79528 | + pReadr1->aKey, pReadr1->nKey, pReadr2->aKey, pReadr2->nKey |
| 79145 | 79529 | ); |
| 79146 | 79530 | } |
| 79147 | 79531 | |
| 79148 | 79532 | /* If pReadr1 contained the smaller value, set aTree[i] to its index. |
| 79149 | 79533 | ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this |
| | @@ -79161,13 +79545,13 @@ |
| 79161 | 79545 | ** is sorted from oldest to newest, so pReadr1 contains older values |
| 79162 | 79546 | ** than pReadr2 iff (pReadr1<pReadr2). */ |
| 79163 | 79547 | if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){ |
| 79164 | 79548 | pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr); |
| 79165 | 79549 | pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ]; |
| 79166 | | - pKey2 = pReadr2->aKey; |
| 79550 | + bCached = 0; |
| 79167 | 79551 | }else{ |
| 79168 | | - if( pReadr1->pFd ) pKey2 = 0; |
| 79552 | + if( pReadr1->pFd ) bCached = 0; |
| 79169 | 79553 | pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr); |
| 79170 | 79554 | pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ]; |
| 79171 | 79555 | } |
| 79172 | 79556 | } |
| 79173 | 79557 | *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0); |
| | @@ -79270,10 +79654,20 @@ |
| 79270 | 79654 | SorterRecord *pNew; /* New list element */ |
| 79271 | 79655 | |
| 79272 | 79656 | int bFlush; /* True to flush contents of memory to PMA */ |
| 79273 | 79657 | int nReq; /* Bytes of memory required */ |
| 79274 | 79658 | int nPMA; /* Bytes of PMA space required */ |
| 79659 | + int t; /* serial type of first record field */ |
| 79660 | + |
| 79661 | + getVarint32((const u8*)&pVal->z[1], t); |
| 79662 | + if( t>0 && t<10 && t!=7 ){ |
| 79663 | + pSorter->typeMask &= SORTER_TYPE_INTEGER; |
| 79664 | + }else if( t>10 && (t & 0x01) ){ |
| 79665 | + pSorter->typeMask &= SORTER_TYPE_TEXT; |
| 79666 | + }else{ |
| 79667 | + pSorter->typeMask = 0; |
| 79668 | + } |
| 79275 | 79669 | |
| 79276 | 79670 | assert( pSorter ); |
| 79277 | 79671 | |
| 79278 | 79672 | /* Figure out whether or not the current contents of memory should be |
| 79279 | 79673 | ** flushed to a PMA before continuing. If so, do so. |
| | @@ -79535,14 +79929,16 @@ |
| 79535 | 79929 | if( p1->pFd==0 ){ |
| 79536 | 79930 | iRes = i2; |
| 79537 | 79931 | }else if( p2->pFd==0 ){ |
| 79538 | 79932 | iRes = i1; |
| 79539 | 79933 | }else{ |
| 79934 | + SortSubtask *pTask = pMerger->pTask; |
| 79935 | + int bCached = 0; |
| 79540 | 79936 | int res; |
| 79541 | | - assert( pMerger->pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */ |
| 79542 | | - res = vdbeSorterCompare( |
| 79543 | | - pMerger->pTask, p1->aKey, p1->nKey, p2->aKey, p2->nKey |
| 79937 | + assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */ |
| 79938 | + res = pTask->xCompare( |
| 79939 | + pTask, &bCached, p1->aKey, p1->nKey, p2->aKey, p2->nKey |
| 79544 | 79940 | ); |
| 79545 | 79941 | if( res<=0 ){ |
| 79546 | 79942 | iRes = i1; |
| 79547 | 79943 | }else{ |
| 79548 | 79944 | iRes = i2; |
| | @@ -79562,15 +79958,16 @@ |
| 79562 | 79958 | */ |
| 79563 | 79959 | #define INCRINIT_NORMAL 0 |
| 79564 | 79960 | #define INCRINIT_TASK 1 |
| 79565 | 79961 | #define INCRINIT_ROOT 2 |
| 79566 | 79962 | |
| 79567 | | -/* Forward reference. |
| 79568 | | -** The vdbeIncrMergeInit() and vdbePmaReaderIncrMergeInit() routines call each |
| 79569 | | -** other (when building a merge tree). |
| 79963 | +/* |
| 79964 | +** Forward reference required as the vdbeIncrMergeInit() and |
| 79965 | +** vdbePmaReaderIncrInit() routines are called mutually recursively when |
| 79966 | +** building a merge tree. |
| 79570 | 79967 | */ |
| 79571 | | -static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode); |
| 79968 | +static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode); |
| 79572 | 79969 | |
| 79573 | 79970 | /* |
| 79574 | 79971 | ** Initialize the MergeEngine object passed as the second argument. Once this |
| 79575 | 79972 | ** function returns, the first key of merged data may be read from the |
| 79576 | 79973 | ** MergeEngine object in the usual fashion. |
| | @@ -79613,11 +80010,11 @@ |
| 79613 | 80010 | ** the main thread to fill its buffer. So calling PmaReaderNext() |
| 79614 | 80011 | ** on this PmaReader before any of the multi-threaded PmaReaders takes |
| 79615 | 80012 | ** better advantage of multi-processor hardware. */ |
| 79616 | 80013 | rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]); |
| 79617 | 80014 | }else{ |
| 79618 | | - rc = vdbePmaReaderIncrMergeInit(&pMerger->aReadr[i], INCRINIT_NORMAL); |
| 80015 | + rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i], INCRINIT_NORMAL); |
| 79619 | 80016 | } |
| 79620 | 80017 | if( rc!=SQLITE_OK ) return rc; |
| 79621 | 80018 | } |
| 79622 | 80019 | |
| 79623 | 80020 | for(i=pMerger->nTree-1; i>0; i--){ |
| | @@ -79625,21 +80022,19 @@ |
| 79625 | 80022 | } |
| 79626 | 80023 | return pTask->pUnpacked->errCode; |
| 79627 | 80024 | } |
| 79628 | 80025 | |
| 79629 | 80026 | /* |
| 79630 | | -** Initialize the IncrMerge field of a PmaReader. |
| 79631 | | -** |
| 79632 | | -** If the PmaReader passed as the first argument is not an incremental-reader |
| 79633 | | -** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it serves |
| 79634 | | -** to open and/or initialize the temp file related fields of the IncrMerge |
| 80027 | +** The PmaReader passed as the first argument is guaranteed to be an |
| 80028 | +** incremental-reader (pReadr->pIncr!=0). This function serves to open |
| 80029 | +** and/or initialize the temp file related fields of the IncrMerge |
| 79635 | 80030 | ** object at (pReadr->pIncr). |
| 79636 | 80031 | ** |
| 79637 | 80032 | ** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders |
| 79638 | | -** in the sub-tree headed by pReadr are also initialized. Data is then loaded |
| 79639 | | -** into the buffers belonging to pReadr and it is set to |
| 79640 | | -** point to the first key in its range. |
| 80033 | +** in the sub-tree headed by pReadr are also initialized. Data is then |
| 80034 | +** loaded into the buffers belonging to pReadr and it is set to point to |
| 80035 | +** the first key in its range. |
| 79641 | 80036 | ** |
| 79642 | 80037 | ** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed |
| 79643 | 80038 | ** to be a multi-threaded PmaReader and this function is being called in a |
| 79644 | 80039 | ** background thread. In this case all PmaReaders in the sub-tree are |
| 79645 | 80040 | ** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to |
| | @@ -79662,93 +80057,112 @@ |
| 79662 | 80057 | ** SQLITE_OK is returned if successful, or an SQLite error code otherwise. |
| 79663 | 80058 | */ |
| 79664 | 80059 | static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){ |
| 79665 | 80060 | int rc = SQLITE_OK; |
| 79666 | 80061 | IncrMerger *pIncr = pReadr->pIncr; |
| 80062 | + SortSubtask *pTask = pIncr->pTask; |
| 80063 | + sqlite3 *db = pTask->pSorter->db; |
| 79667 | 80064 | |
| 79668 | 80065 | /* eMode is always INCRINIT_NORMAL in single-threaded mode */ |
| 79669 | 80066 | assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL ); |
| 79670 | 80067 | |
| 79671 | | - if( pIncr ){ |
| 79672 | | - SortSubtask *pTask = pIncr->pTask; |
| 79673 | | - sqlite3 *db = pTask->pSorter->db; |
| 79674 | | - |
| 79675 | | - rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode); |
| 79676 | | - |
| 79677 | | - /* Set up the required files for pIncr. A multi-theaded IncrMerge object |
| 79678 | | - ** requires two temp files to itself, whereas a single-threaded object |
| 79679 | | - ** only requires a region of pTask->file2. */ |
| 79680 | | - if( rc==SQLITE_OK ){ |
| 79681 | | - int mxSz = pIncr->mxSz; |
| 79682 | | -#if SQLITE_MAX_WORKER_THREADS>0 |
| 79683 | | - if( pIncr->bUseThread ){ |
| 79684 | | - rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd); |
| 79685 | | - if( rc==SQLITE_OK ){ |
| 79686 | | - rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd); |
| 79687 | | - } |
| 79688 | | - }else |
| 79689 | | -#endif |
| 79690 | | - /*if( !pIncr->bUseThread )*/{ |
| 79691 | | - if( pTask->file2.pFd==0 ){ |
| 79692 | | - assert( pTask->file2.iEof>0 ); |
| 79693 | | - rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd); |
| 79694 | | - pTask->file2.iEof = 0; |
| 79695 | | - } |
| 79696 | | - if( rc==SQLITE_OK ){ |
| 79697 | | - pIncr->aFile[1].pFd = pTask->file2.pFd; |
| 79698 | | - pIncr->iStartOff = pTask->file2.iEof; |
| 79699 | | - pTask->file2.iEof += mxSz; |
| 79700 | | - } |
| 79701 | | - } |
| 79702 | | - } |
| 79703 | | - |
| 79704 | | -#if SQLITE_MAX_WORKER_THREADS>0 |
| 79705 | | - if( rc==SQLITE_OK && pIncr->bUseThread ){ |
| 79706 | | - /* Use the current thread to populate aFile[1], even though this |
| 79707 | | - ** PmaReader is multi-threaded. The reason being that this function |
| 79708 | | - ** is already running in background thread pIncr->pTask->thread. */ |
| 79709 | | - assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK ); |
| 79710 | | - rc = vdbeIncrPopulate(pIncr); |
| 79711 | | - } |
| 79712 | | -#endif |
| 79713 | | - |
| 79714 | | - if( rc==SQLITE_OK |
| 79715 | | - && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) |
| 79716 | | - ){ |
| 79717 | | - rc = vdbePmaReaderNext(pReadr); |
| 79718 | | - } |
| 79719 | | - } |
| 80068 | + rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode); |
| 80069 | + |
| 80070 | + /* Set up the required files for pIncr. A multi-theaded IncrMerge object |
| 80071 | + ** requires two temp files to itself, whereas a single-threaded object |
| 80072 | + ** only requires a region of pTask->file2. */ |
| 80073 | + if( rc==SQLITE_OK ){ |
| 80074 | + int mxSz = pIncr->mxSz; |
| 80075 | +#if SQLITE_MAX_WORKER_THREADS>0 |
| 80076 | + if( pIncr->bUseThread ){ |
| 80077 | + rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd); |
| 80078 | + if( rc==SQLITE_OK ){ |
| 80079 | + rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd); |
| 80080 | + } |
| 80081 | + }else |
| 80082 | +#endif |
| 80083 | + /*if( !pIncr->bUseThread )*/{ |
| 80084 | + if( pTask->file2.pFd==0 ){ |
| 80085 | + assert( pTask->file2.iEof>0 ); |
| 80086 | + rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd); |
| 80087 | + pTask->file2.iEof = 0; |
| 80088 | + } |
| 80089 | + if( rc==SQLITE_OK ){ |
| 80090 | + pIncr->aFile[1].pFd = pTask->file2.pFd; |
| 80091 | + pIncr->iStartOff = pTask->file2.iEof; |
| 80092 | + pTask->file2.iEof += mxSz; |
| 80093 | + } |
| 80094 | + } |
| 80095 | + } |
| 80096 | + |
| 80097 | +#if SQLITE_MAX_WORKER_THREADS>0 |
| 80098 | + if( rc==SQLITE_OK && pIncr->bUseThread ){ |
| 80099 | + /* Use the current thread to populate aFile[1], even though this |
| 80100 | + ** PmaReader is multi-threaded. If this is an INCRINIT_TASK object, |
| 80101 | + ** then this function is already running in background thread |
| 80102 | + ** pIncr->pTask->thread. |
| 80103 | + ** |
| 80104 | + ** If this is the INCRINIT_ROOT object, then it is running in the |
| 80105 | + ** main VDBE thread. But that is Ok, as that thread cannot return |
| 80106 | + ** control to the VDBE or proceed with anything useful until the |
| 80107 | + ** first results are ready from this merger object anyway. |
| 80108 | + */ |
| 80109 | + assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK ); |
| 80110 | + rc = vdbeIncrPopulate(pIncr); |
| 80111 | + } |
| 80112 | +#endif |
| 80113 | + |
| 80114 | + if( rc==SQLITE_OK && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) ){ |
| 80115 | + rc = vdbePmaReaderNext(pReadr); |
| 80116 | + } |
| 80117 | + |
| 79720 | 80118 | return rc; |
| 79721 | 80119 | } |
| 79722 | 80120 | |
| 79723 | 80121 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 79724 | 80122 | /* |
| 79725 | 80123 | ** The main routine for vdbePmaReaderIncrMergeInit() operations run in |
| 79726 | 80124 | ** background threads. |
| 79727 | 80125 | */ |
| 79728 | | -static void *vdbePmaReaderBgInit(void *pCtx){ |
| 80126 | +static void *vdbePmaReaderBgIncrInit(void *pCtx){ |
| 79729 | 80127 | PmaReader *pReader = (PmaReader*)pCtx; |
| 79730 | 80128 | void *pRet = SQLITE_INT_TO_PTR( |
| 79731 | 80129 | vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK) |
| 79732 | 80130 | ); |
| 79733 | 80131 | pReader->pIncr->pTask->bDone = 1; |
| 79734 | 80132 | return pRet; |
| 79735 | 80133 | } |
| 80134 | +#endif |
| 79736 | 80135 | |
| 79737 | 80136 | /* |
| 79738 | | -** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK) |
| 79739 | | -** on the PmaReader object passed as the first argument. |
| 79740 | | -** |
| 79741 | | -** This call will initialize the various fields of the pReadr->pIncr |
| 79742 | | -** structure and, if it is a multi-threaded IncrMerger, launch a |
| 79743 | | -** background thread to populate aFile[1]. |
| 80137 | +** If the PmaReader passed as the first argument is not an incremental-reader |
| 80138 | +** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes |
| 80139 | +** the vdbePmaReaderIncrMergeInit() function with the parameters passed to |
| 80140 | +** this routine to initialize the incremental merge. |
| 80141 | +** |
| 80142 | +** If the IncrMerger object is multi-threaded (IncrMerger.bUseThread==1), |
| 80143 | +** then a background thread is launched to call vdbePmaReaderIncrMergeInit(). |
| 80144 | +** Or, if the IncrMerger is single threaded, the same function is called |
| 80145 | +** using the current thread. |
| 79744 | 80146 | */ |
| 79745 | | -static int vdbePmaReaderBgIncrInit(PmaReader *pReadr){ |
| 79746 | | - void *pCtx = (void*)pReadr; |
| 79747 | | - return vdbeSorterCreateThread(pReadr->pIncr->pTask, vdbePmaReaderBgInit, pCtx); |
| 80147 | +static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode){ |
| 80148 | + IncrMerger *pIncr = pReadr->pIncr; /* Incremental merger */ |
| 80149 | + int rc = SQLITE_OK; /* Return code */ |
| 80150 | + if( pIncr ){ |
| 80151 | +#if SQLITE_MAX_WORKER_THREADS>0 |
| 80152 | + assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK ); |
| 80153 | + if( pIncr->bUseThread ){ |
| 80154 | + void *pCtx = (void*)pReadr; |
| 80155 | + rc = vdbeSorterCreateThread(pIncr->pTask, vdbePmaReaderBgIncrInit, pCtx); |
| 80156 | + }else |
| 80157 | +#endif |
| 80158 | + { |
| 80159 | + rc = vdbePmaReaderIncrMergeInit(pReadr, eMode); |
| 80160 | + } |
| 80161 | + } |
| 80162 | + return rc; |
| 79748 | 80163 | } |
| 79749 | | -#endif |
| 79750 | 80164 | |
| 79751 | 80165 | /* |
| 79752 | 80166 | ** Allocate a new MergeEngine object to merge the contents of nPMA level-0 |
| 79753 | 80167 | ** PMAs from pTask->file. If no error occurs, set *ppOut to point to |
| 79754 | 80168 | ** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut |
| | @@ -79956,10 +80370,15 @@ |
| 79956 | 80370 | int rc; /* Return code */ |
| 79957 | 80371 | SortSubtask *pTask0 = &pSorter->aTask[0]; |
| 79958 | 80372 | MergeEngine *pMain = 0; |
| 79959 | 80373 | #if SQLITE_MAX_WORKER_THREADS |
| 79960 | 80374 | sqlite3 *db = pTask0->pSorter->db; |
| 80375 | + int i; |
| 80376 | + SorterCompare xCompare = vdbeSorterGetCompare(pSorter); |
| 80377 | + for(i=0; i<pSorter->nTask; i++){ |
| 80378 | + pSorter->aTask[i].xCompare = xCompare; |
| 80379 | + } |
| 79961 | 80380 | #endif |
| 79962 | 80381 | |
| 79963 | 80382 | rc = vdbeSorterMergeTreeBuild(pSorter, &pMain); |
| 79964 | 80383 | if( rc==SQLITE_OK ){ |
| 79965 | 80384 | #if SQLITE_MAX_WORKER_THREADS |
| | @@ -79984,19 +80403,25 @@ |
| 79984 | 80403 | vdbeIncrMergerSetThreads(pIncr); |
| 79985 | 80404 | assert( pIncr->pTask!=pLast ); |
| 79986 | 80405 | } |
| 79987 | 80406 | } |
| 79988 | 80407 | for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){ |
| 80408 | + /* Check that: |
| 80409 | + ** |
| 80410 | + ** a) The incremental merge object is configured to use the |
| 80411 | + ** right task, and |
| 80412 | + ** b) If it is using task (nTask-1), it is configured to run |
| 80413 | + ** in single-threaded mode. This is important, as the |
| 80414 | + ** root merge (INCRINIT_ROOT) will be using the same task |
| 80415 | + ** object. |
| 80416 | + */ |
| 79989 | 80417 | PmaReader *p = &pMain->aReadr[iTask]; |
| 79990 | | - assert( p->pIncr==0 || p->pIncr->pTask==&pSorter->aTask[iTask] ); |
| 79991 | | - if( p->pIncr ){ |
| 79992 | | - if( iTask==pSorter->nTask-1 ){ |
| 79993 | | - rc = vdbePmaReaderIncrMergeInit(p, INCRINIT_TASK); |
| 79994 | | - }else{ |
| 79995 | | - rc = vdbePmaReaderBgIncrInit(p); |
| 79996 | | - } |
| 79997 | | - } |
| 80418 | + assert( p->pIncr==0 || ( |
| 80419 | + (p->pIncr->pTask==&pSorter->aTask[iTask]) /* a */ |
| 80420 | + && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */ |
| 80421 | + )); |
| 80422 | + rc = vdbePmaReaderIncrInit(p, INCRINIT_TASK); |
| 79998 | 80423 | } |
| 79999 | 80424 | } |
| 80000 | 80425 | pMain = 0; |
| 80001 | 80426 | } |
| 80002 | 80427 | if( rc==SQLITE_OK ){ |
| | @@ -80947,11 +81372,11 @@ |
| 80947 | 81372 | ** Should be transformed into: |
| 80948 | 81373 | ** |
| 80949 | 81374 | ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase; |
| 80950 | 81375 | ** |
| 80951 | 81376 | ** The nSubquery parameter specifies how many levels of subquery the |
| 80952 | | -** alias is removed from the original expression. The usually value is |
| 81377 | +** alias is removed from the original expression. The usual value is |
| 80953 | 81378 | ** zero but it might be more if the alias is contained within a subquery |
| 80954 | 81379 | ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION |
| 80955 | 81380 | ** structures must be increased by the nSubquery amount. |
| 80956 | 81381 | */ |
| 80957 | 81382 | static void resolveAlias( |
| | @@ -80967,11 +81392,10 @@ |
| 80967 | 81392 | sqlite3 *db; /* The database connection */ |
| 80968 | 81393 | |
| 80969 | 81394 | assert( iCol>=0 && iCol<pEList->nExpr ); |
| 80970 | 81395 | pOrig = pEList->a[iCol].pExpr; |
| 80971 | 81396 | assert( pOrig!=0 ); |
| 80972 | | - assert( pOrig->flags & EP_Resolved ); |
| 80973 | 81397 | db = pParse->db; |
| 80974 | 81398 | pDup = sqlite3ExprDup(db, pOrig, 0); |
| 80975 | 81399 | if( pDup==0 ) return; |
| 80976 | 81400 | if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){ |
| 80977 | 81401 | incrAggFunctionDepth(pDup, nSubquery); |
| | @@ -81861,13 +82285,15 @@ |
| 81861 | 82285 | pNew->flags |= EP_IntValue; |
| 81862 | 82286 | pNew->u.iValue = iCol; |
| 81863 | 82287 | if( pItem->pExpr==pE ){ |
| 81864 | 82288 | pItem->pExpr = pNew; |
| 81865 | 82289 | }else{ |
| 81866 | | - assert( pItem->pExpr->op==TK_COLLATE ); |
| 81867 | | - assert( pItem->pExpr->pLeft==pE ); |
| 81868 | | - pItem->pExpr->pLeft = pNew; |
| 82290 | + Expr *pParent = pItem->pExpr; |
| 82291 | + assert( pParent->op==TK_COLLATE ); |
| 82292 | + while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft; |
| 82293 | + assert( pParent->pLeft==pE ); |
| 82294 | + pParent->pLeft = pNew; |
| 81869 | 82295 | } |
| 81870 | 82296 | sqlite3ExprDelete(db, pE); |
| 81871 | 82297 | pItem->u.x.iOrderByCol = (u16)iCol; |
| 81872 | 82298 | pItem->done = 1; |
| 81873 | 82299 | }else{ |
| | @@ -82054,10 +82480,24 @@ |
| 82054 | 82480 | sNC.pParse = pParse; |
| 82055 | 82481 | if( sqlite3ResolveExprNames(&sNC, p->pLimit) || |
| 82056 | 82482 | sqlite3ResolveExprNames(&sNC, p->pOffset) ){ |
| 82057 | 82483 | return WRC_Abort; |
| 82058 | 82484 | } |
| 82485 | + |
| 82486 | + /* If the SF_Converted flags is set, then this Select object was |
| 82487 | + ** was created by the convertCompoundSelectToSubquery() function. |
| 82488 | + ** In this case the ORDER BY clause (p->pOrderBy) should be resolved |
| 82489 | + ** as if it were part of the sub-query, not the parent. This block |
| 82490 | + ** moves the pOrderBy down to the sub-query. It will be moved back |
| 82491 | + ** after the names have been resolved. */ |
| 82492 | + if( p->selFlags & SF_Converted ){ |
| 82493 | + Select *pSub = p->pSrc->a[0].pSelect; |
| 82494 | + assert( p->pSrc->nSrc==1 && p->pOrderBy ); |
| 82495 | + assert( pSub->pPrior && pSub->pOrderBy==0 ); |
| 82496 | + pSub->pOrderBy = p->pOrderBy; |
| 82497 | + p->pOrderBy = 0; |
| 82498 | + } |
| 82059 | 82499 | |
| 82060 | 82500 | /* Recursively resolve names in all subqueries |
| 82061 | 82501 | */ |
| 82062 | 82502 | for(i=0; i<p->pSrc->nSrc; i++){ |
| 82063 | 82503 | struct SrcList_item *pItem = &p->pSrc->a[i]; |
| | @@ -82135,17 +82575,35 @@ |
| 82135 | 82575 | /* The ORDER BY and GROUP BY clauses may not refer to terms in |
| 82136 | 82576 | ** outer queries |
| 82137 | 82577 | */ |
| 82138 | 82578 | sNC.pNext = 0; |
| 82139 | 82579 | sNC.ncFlags |= NC_AllowAgg; |
| 82580 | + |
| 82581 | + /* If this is a converted compound query, move the ORDER BY clause from |
| 82582 | + ** the sub-query back to the parent query. At this point each term |
| 82583 | + ** within the ORDER BY clause has been transformed to an integer value. |
| 82584 | + ** These integers will be replaced by copies of the corresponding result |
| 82585 | + ** set expressions by the call to resolveOrderGroupBy() below. */ |
| 82586 | + if( p->selFlags & SF_Converted ){ |
| 82587 | + Select *pSub = p->pSrc->a[0].pSelect; |
| 82588 | + p->pOrderBy = pSub->pOrderBy; |
| 82589 | + pSub->pOrderBy = 0; |
| 82590 | + } |
| 82140 | 82591 | |
| 82141 | 82592 | /* Process the ORDER BY clause for singleton SELECT statements. |
| 82142 | 82593 | ** The ORDER BY clause for compounds SELECT statements is handled |
| 82143 | 82594 | ** below, after all of the result-sets for all of the elements of |
| 82144 | 82595 | ** the compound have been resolved. |
| 82596 | + ** |
| 82597 | + ** If there is an ORDER BY clause on a term of a compound-select other |
| 82598 | + ** than the right-most term, then that is a syntax error. But the error |
| 82599 | + ** is not detected until much later, and so we need to go ahead and |
| 82600 | + ** resolve those symbols on the incorrect ORDER BY for consistency. |
| 82145 | 82601 | */ |
| 82146 | | - if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){ |
| 82602 | + if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */ |
| 82603 | + && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") |
| 82604 | + ){ |
| 82147 | 82605 | return WRC_Abort; |
| 82148 | 82606 | } |
| 82149 | 82607 | if( db->mallocFailed ){ |
| 82150 | 82608 | return WRC_Abort; |
| 82151 | 82609 | } |
| | @@ -83593,11 +84051,12 @@ |
| 83593 | 84051 | SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){ |
| 83594 | 84052 | int i; |
| 83595 | 84053 | u32 m = 0; |
| 83596 | 84054 | if( pList ){ |
| 83597 | 84055 | for(i=0; i<pList->nExpr; i++){ |
| 83598 | | - m |= pList->a[i].pExpr->flags; |
| 84056 | + Expr *pExpr = pList->a[i].pExpr; |
| 84057 | + if( ALWAYS(pExpr) ) m |= pExpr->flags; |
| 83599 | 84058 | } |
| 83600 | 84059 | } |
| 83601 | 84060 | return m; |
| 83602 | 84061 | } |
| 83603 | 84062 | |
| | @@ -84033,11 +84492,11 @@ |
| 84033 | 84492 | /* Check to see if an existing table or index can be used to |
| 84034 | 84493 | ** satisfy the query. This is preferable to generating a new |
| 84035 | 84494 | ** ephemeral table. |
| 84036 | 84495 | */ |
| 84037 | 84496 | p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0); |
| 84038 | | - if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){ |
| 84497 | + if( pParse->nErr==0 && isCandidateForInOpt(p) ){ |
| 84039 | 84498 | sqlite3 *db = pParse->db; /* Database connection */ |
| 84040 | 84499 | Table *pTab; /* Table <table>. */ |
| 84041 | 84500 | Expr *pExpr; /* Expression <column> */ |
| 84042 | 84501 | i16 iCol; /* Index of column <column> */ |
| 84043 | 84502 | i16 iDb; /* Database idx for pTab */ |
| | @@ -84358,10 +84817,11 @@ |
| 84358 | 84817 | } |
| 84359 | 84818 | sqlite3ExprDelete(pParse->db, pSel->pLimit); |
| 84360 | 84819 | pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, |
| 84361 | 84820 | &sqlite3IntTokens[1]); |
| 84362 | 84821 | pSel->iLimit = 0; |
| 84822 | + pSel->selFlags &= ~SF_MultiValue; |
| 84363 | 84823 | if( sqlite3Select(pParse, pSel, &dest) ){ |
| 84364 | 84824 | return 0; |
| 84365 | 84825 | } |
| 84366 | 84826 | rReg = dest.iSDParm; |
| 84367 | 84827 | ExprSetVVAProperty(pExpr, EP_NoReduce); |
| | @@ -85723,11 +86183,11 @@ |
| 85723 | 86183 | sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken); |
| 85724 | 86184 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 85725 | 86185 | break; |
| 85726 | 86186 | } |
| 85727 | 86187 | case TK_ID: { |
| 85728 | | - sqlite3TreeViewLine(pView,"ID %Q", pExpr->u.zToken); |
| 86188 | + sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken); |
| 85729 | 86189 | break; |
| 85730 | 86190 | } |
| 85731 | 86191 | #ifndef SQLITE_OMIT_CAST |
| 85732 | 86192 | case TK_CAST: { |
| 85733 | 86193 | /* Expressions of the form: CAST(pLeft AS token) */ |
| | @@ -86358,11 +86818,11 @@ |
| 86358 | 86818 | if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){ |
| 86359 | 86819 | if( combinedFlags & EP_xIsSelect ) return 2; |
| 86360 | 86820 | if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2; |
| 86361 | 86821 | if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2; |
| 86362 | 86822 | if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2; |
| 86363 | | - if( ALWAYS((combinedFlags & EP_Reduced)==0) ){ |
| 86823 | + if( ALWAYS((combinedFlags & EP_Reduced)==0) && pA->op!=TK_STRING ){ |
| 86364 | 86824 | if( pA->iColumn!=pB->iColumn ) return 2; |
| 86365 | 86825 | if( pA->iTable!=pB->iTable |
| 86366 | 86826 | && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2; |
| 86367 | 86827 | } |
| 86368 | 86828 | } |
| | @@ -86890,10 +87350,11 @@ |
| 86890 | 87350 | do { |
| 86891 | 87351 | z += n; |
| 86892 | 87352 | n = sqlite3GetToken(z, &token); |
| 86893 | 87353 | }while( token==TK_SPACE ); |
| 86894 | 87354 | |
| 87355 | + if( token==TK_ILLEGAL ) break; |
| 86895 | 87356 | zParent = sqlite3DbStrNDup(db, (const char *)z, n); |
| 86896 | 87357 | if( zParent==0 ) break; |
| 86897 | 87358 | sqlite3Dequote(zParent); |
| 86898 | 87359 | if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){ |
| 86899 | 87360 | char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"", |
| | @@ -89116,18 +89577,21 @@ |
| 89116 | 89577 | pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase); |
| 89117 | 89578 | } |
| 89118 | 89579 | z = argv[2]; |
| 89119 | 89580 | |
| 89120 | 89581 | if( pIndex ){ |
| 89582 | + tRowcnt *aiRowEst = 0; |
| 89121 | 89583 | int nCol = pIndex->nKeyCol+1; |
| 89122 | 89584 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 89123 | | - tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero( |
| 89124 | | - sizeof(tRowcnt) * nCol |
| 89125 | | - ); |
| 89126 | | - if( aiRowEst==0 ) pInfo->db->mallocFailed = 1; |
| 89127 | | -#else |
| 89128 | | - tRowcnt * const aiRowEst = 0; |
| 89585 | + /* Index.aiRowEst may already be set here if there are duplicate |
| 89586 | + ** sqlite_stat1 entries for this index. In that case just clobber |
| 89587 | + ** the old data with the new instead of allocating a new array. */ |
| 89588 | + if( pIndex->aiRowEst==0 ){ |
| 89589 | + pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(sizeof(tRowcnt) * nCol); |
| 89590 | + if( pIndex->aiRowEst==0 ) pInfo->db->mallocFailed = 1; |
| 89591 | + } |
| 89592 | + aiRowEst = pIndex->aiRowEst; |
| 89129 | 89593 | #endif |
| 89130 | 89594 | pIndex->bUnordered = 0; |
| 89131 | 89595 | decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex); |
| 89132 | 89596 | if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0]; |
| 89133 | 89597 | }else{ |
| | @@ -89786,11 +90250,11 @@ |
| 89786 | 90250 | } |
| 89787 | 90251 | |
| 89788 | 90252 | sqlite3BtreeClose(pDb->pBt); |
| 89789 | 90253 | pDb->pBt = 0; |
| 89790 | 90254 | pDb->pSchema = 0; |
| 89791 | | - sqlite3ResetAllSchemasOfConnection(db); |
| 90255 | + sqlite3CollapseDatabaseArray(db); |
| 89792 | 90256 | return; |
| 89793 | 90257 | |
| 89794 | 90258 | detach_error: |
| 89795 | 90259 | sqlite3_result_error(context, zErr, -1); |
| 89796 | 90260 | } |
| | @@ -89820,11 +90284,10 @@ |
| 89820 | 90284 | if( |
| 89821 | 90285 | SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) || |
| 89822 | 90286 | SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) || |
| 89823 | 90287 | SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey)) |
| 89824 | 90288 | ){ |
| 89825 | | - pParse->nErr++; |
| 89826 | 90289 | goto attach_end; |
| 89827 | 90290 | } |
| 89828 | 90291 | |
| 89829 | 90292 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 89830 | 90293 | if( pAuthArg ){ |
| | @@ -90142,11 +90605,11 @@ |
| 90142 | 90605 | ** and attempts to write the column will be ignored. |
| 90143 | 90606 | ** |
| 90144 | 90607 | ** Setting the auth function to NULL disables this hook. The default |
| 90145 | 90608 | ** setting of the auth function is NULL. |
| 90146 | 90609 | */ |
| 90147 | | -SQLITE_API int sqlite3_set_authorizer( |
| 90610 | +SQLITE_API int SQLITE_STDCALL sqlite3_set_authorizer( |
| 90148 | 90611 | sqlite3 *db, |
| 90149 | 90612 | int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), |
| 90150 | 90613 | void *pArg |
| 90151 | 90614 | ){ |
| 90152 | 90615 | #ifdef SQLITE_ENABLE_API_ARMOR |
| | @@ -90479,13 +90942,15 @@ |
| 90479 | 90942 | sqlite3 *db; |
| 90480 | 90943 | Vdbe *v; |
| 90481 | 90944 | |
| 90482 | 90945 | assert( pParse->pToplevel==0 ); |
| 90483 | 90946 | db = pParse->db; |
| 90484 | | - if( db->mallocFailed ) return; |
| 90485 | 90947 | if( pParse->nested ) return; |
| 90486 | | - if( pParse->nErr ) return; |
| 90948 | + if( db->mallocFailed || pParse->nErr ){ |
| 90949 | + if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR; |
| 90950 | + return; |
| 90951 | + } |
| 90487 | 90952 | |
| 90488 | 90953 | /* Begin by generating some termination code at the end of the |
| 90489 | 90954 | ** vdbe program |
| 90490 | 90955 | */ |
| 90491 | 90956 | v = sqlite3GetVdbe(pParse); |
| | @@ -90563,11 +91028,11 @@ |
| 90563 | 91028 | } |
| 90564 | 91029 | |
| 90565 | 91030 | |
| 90566 | 91031 | /* Get the VDBE program ready for execution |
| 90567 | 91032 | */ |
| 90568 | | - if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){ |
| 91033 | + if( v && pParse->nErr==0 && !db->mallocFailed ){ |
| 90569 | 91034 | assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */ |
| 90570 | 91035 | /* A minimum of one cursor is required if autoincrement is used |
| 90571 | 91036 | * See ticket [a696379c1f08866] */ |
| 90572 | 91037 | if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1; |
| 90573 | 91038 | sqlite3VdbeMakeReady(v, pParse); |
| | @@ -91098,18 +91563,16 @@ |
| 91098 | 91563 | sqlite3 *db = pParse->db; |
| 91099 | 91564 | |
| 91100 | 91565 | if( ALWAYS(pName2!=0) && pName2->n>0 ){ |
| 91101 | 91566 | if( db->init.busy ) { |
| 91102 | 91567 | sqlite3ErrorMsg(pParse, "corrupt database"); |
| 91103 | | - pParse->nErr++; |
| 91104 | 91568 | return -1; |
| 91105 | 91569 | } |
| 91106 | 91570 | *pUnqual = pName2; |
| 91107 | 91571 | iDb = sqlite3FindDb(db, pName1); |
| 91108 | 91572 | if( iDb<0 ){ |
| 91109 | 91573 | sqlite3ErrorMsg(pParse, "unknown database %T", pName1); |
| 91110 | | - pParse->nErr++; |
| 91111 | 91574 | return -1; |
| 91112 | 91575 | } |
| 91113 | 91576 | }else{ |
| 91114 | 91577 | assert( db->init.iDb==0 || db->init.busy ); |
| 91115 | 91578 | iDb = db->init.iDb; |
| | @@ -91264,11 +91727,11 @@ |
| 91264 | 91727 | pTable = sqlite3FindTable(db, zName, zDb); |
| 91265 | 91728 | if( pTable ){ |
| 91266 | 91729 | if( !noErr ){ |
| 91267 | 91730 | sqlite3ErrorMsg(pParse, "table %T already exists", pName); |
| 91268 | 91731 | }else{ |
| 91269 | | - assert( !db->init.busy ); |
| 91732 | + assert( !db->init.busy || CORRUPT_DB ); |
| 91270 | 91733 | sqlite3CodeVerifySchema(pParse, iDb); |
| 91271 | 91734 | } |
| 91272 | 91735 | goto begin_table_error; |
| 91273 | 91736 | } |
| 91274 | 91737 | if( sqlite3FindIndex(db, zName, zDb)!=0 ){ |
| | @@ -91553,11 +92016,12 @@ |
| 91553 | 92016 | Column *pCol; |
| 91554 | 92017 | |
| 91555 | 92018 | p = pParse->pNewTable; |
| 91556 | 92019 | if( p==0 || NEVER(p->nCol<1) ) return; |
| 91557 | 92020 | pCol = &p->aCol[p->nCol-1]; |
| 91558 | | - assert( pCol->zType==0 ); |
| 92021 | + assert( pCol->zType==0 || CORRUPT_DB ); |
| 92022 | + sqlite3DbFree(pParse->db, pCol->zType); |
| 91559 | 92023 | pCol->zType = sqlite3NameFromToken(pParse->db, pType); |
| 91560 | 92024 | pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst); |
| 91561 | 92025 | } |
| 91562 | 92026 | |
| 91563 | 92027 | /* |
| | @@ -92787,10 +93251,11 @@ |
| 92787 | 93251 | if( db->mallocFailed ){ |
| 92788 | 93252 | goto exit_drop_table; |
| 92789 | 93253 | } |
| 92790 | 93254 | assert( pParse->nErr==0 ); |
| 92791 | 93255 | assert( pName->nSrc==1 ); |
| 93256 | + if( sqlite3ReadSchema(pParse) ) goto exit_drop_table; |
| 92792 | 93257 | if( noErr ) db->suppressErr++; |
| 92793 | 93258 | pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]); |
| 92794 | 93259 | if( noErr ) db->suppressErr--; |
| 92795 | 93260 | |
| 92796 | 93261 | if( pTab==0 ){ |
| | @@ -93100,11 +93565,12 @@ |
| 93100 | 93565 | sqlite3UniqueConstraint(pParse, OE_Abort, pIndex); |
| 93101 | 93566 | }else{ |
| 93102 | 93567 | addr2 = sqlite3VdbeCurrentAddr(v); |
| 93103 | 93568 | } |
| 93104 | 93569 | sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx); |
| 93105 | | - sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1); |
| 93570 | + sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1); |
| 93571 | + sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0); |
| 93106 | 93572 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 93107 | 93573 | sqlite3ReleaseTempReg(pParse, regRecord); |
| 93108 | 93574 | sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v); |
| 93109 | 93575 | sqlite3VdbeJumpHere(v, addr1); |
| 93110 | 93576 | |
| | @@ -93193,12 +93659,11 @@ |
| 93193 | 93659 | int nExtra = 0; /* Space allocated for zExtra[] */ |
| 93194 | 93660 | int nExtraCol; /* Number of extra columns needed */ |
| 93195 | 93661 | char *zExtra = 0; /* Extra space after the Index object */ |
| 93196 | 93662 | Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */ |
| 93197 | 93663 | |
| 93198 | | - assert( pParse->nErr==0 ); /* Never called with prior errors */ |
| 93199 | | - if( db->mallocFailed || IN_DECLARE_VTAB ){ |
| 93664 | + if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){ |
| 93200 | 93665 | goto exit_create_index; |
| 93201 | 93666 | } |
| 93202 | 93667 | if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ |
| 93203 | 93668 | goto exit_create_index; |
| 93204 | 93669 | } |
| | @@ -94113,11 +94578,10 @@ |
| 94113 | 94578 | ** operator with A. This routine shifts that operator over to B. |
| 94114 | 94579 | */ |
| 94115 | 94580 | SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){ |
| 94116 | 94581 | if( p ){ |
| 94117 | 94582 | int i; |
| 94118 | | - assert( p->a || p->nSrc==0 ); |
| 94119 | 94583 | for(i=p->nSrc-1; i>0; i--){ |
| 94120 | 94584 | p->a[i].jointype = p->a[i-1].jointype; |
| 94121 | 94585 | } |
| 94122 | 94586 | p->a[0].jointype = 0; |
| 94123 | 94587 | } |
| | @@ -94360,12 +94824,11 @@ |
| 94360 | 94824 | char *zErr; |
| 94361 | 94825 | int j; |
| 94362 | 94826 | StrAccum errMsg; |
| 94363 | 94827 | Table *pTab = pIdx->pTable; |
| 94364 | 94828 | |
| 94365 | | - sqlite3StrAccumInit(&errMsg, 0, 0, 200); |
| 94366 | | - errMsg.db = pParse->db; |
| 94829 | + sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200); |
| 94367 | 94830 | for(j=0; j<pIdx->nKeyCol; j++){ |
| 94368 | 94831 | char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName; |
| 94369 | 94832 | if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2); |
| 94370 | 94833 | sqlite3StrAccumAppendAll(&errMsg, pTab->zName); |
| 94371 | 94834 | sqlite3StrAccumAppend(&errMsg, ".", 1); |
| | @@ -96190,17 +96653,17 @@ |
| 96190 | 96653 | ){ |
| 96191 | 96654 | PrintfArguments x; |
| 96192 | 96655 | StrAccum str; |
| 96193 | 96656 | const char *zFormat; |
| 96194 | 96657 | int n; |
| 96658 | + sqlite3 *db = sqlite3_context_db_handle(context); |
| 96195 | 96659 | |
| 96196 | 96660 | if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){ |
| 96197 | 96661 | x.nArg = argc-1; |
| 96198 | 96662 | x.nUsed = 0; |
| 96199 | 96663 | x.apArg = argv+1; |
| 96200 | | - sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH); |
| 96201 | | - str.db = sqlite3_context_db_handle(context); |
| 96664 | + sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 96202 | 96665 | sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x); |
| 96203 | 96666 | n = str.nChar; |
| 96204 | 96667 | sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, |
| 96205 | 96668 | SQLITE_DYNAMIC); |
| 96206 | 96669 | } |
| | @@ -96346,11 +96809,11 @@ |
| 96346 | 96809 | sqlite3_result_double(context, r); |
| 96347 | 96810 | } |
| 96348 | 96811 | #endif |
| 96349 | 96812 | |
| 96350 | 96813 | /* |
| 96351 | | -** Allocate nByte bytes of space using sqlite3_malloc(). If the |
| 96814 | +** Allocate nByte bytes of space using sqlite3Malloc(). If the |
| 96352 | 96815 | ** allocation fails, call sqlite3_result_error_nomem() to notify |
| 96353 | 96816 | ** the database handle that malloc() has failed and return NULL. |
| 96354 | 96817 | ** If nByte is larger than the maximum string or blob length, then |
| 96355 | 96818 | ** raise an SQLITE_TOOBIG exception and return NULL. |
| 96356 | 96819 | */ |
| | @@ -96720,11 +97183,11 @@ |
| 96720 | 97183 | } |
| 96721 | 97184 | |
| 96722 | 97185 | /* |
| 96723 | 97186 | ** The sqlite3_strglob() interface. |
| 96724 | 97187 | */ |
| 96725 | | -SQLITE_API int sqlite3_strglob(const char *zGlobPattern, const char *zString){ |
| 97188 | +SQLITE_API int SQLITE_STDCALL sqlite3_strglob(const char *zGlobPattern, const char *zString){ |
| 96726 | 97189 | return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, 0)==0; |
| 96727 | 97190 | } |
| 96728 | 97191 | |
| 96729 | 97192 | /* |
| 96730 | 97193 | ** Count the number of times that the LIKE operator (or GLOB which is |
| | @@ -97015,11 +97478,11 @@ |
| 97015 | 97478 | int argc, |
| 97016 | 97479 | sqlite3_value **argv |
| 97017 | 97480 | ){ |
| 97018 | 97481 | unsigned char *z, *zOut; |
| 97019 | 97482 | int i; |
| 97020 | | - zOut = z = sqlite3_malloc( argc*4+1 ); |
| 97483 | + zOut = z = sqlite3_malloc64( argc*4+1 ); |
| 97021 | 97484 | if( z==0 ){ |
| 97022 | 97485 | sqlite3_result_error_nomem(context); |
| 97023 | 97486 | return; |
| 97024 | 97487 | } |
| 97025 | 97488 | for(i=0; i<argc; i++){ |
| | @@ -97163,11 +97626,11 @@ |
| 97163 | 97626 | sqlite3_result_error_toobig(context); |
| 97164 | 97627 | sqlite3_free(zOut); |
| 97165 | 97628 | return; |
| 97166 | 97629 | } |
| 97167 | 97630 | zOld = zOut; |
| 97168 | | - zOut = sqlite3_realloc(zOut, (int)nOut); |
| 97631 | + zOut = sqlite3_realloc64(zOut, (int)nOut); |
| 97169 | 97632 | if( zOut==0 ){ |
| 97170 | 97633 | sqlite3_result_error_nomem(context); |
| 97171 | 97634 | sqlite3_free(zOld); |
| 97172 | 97635 | return; |
| 97173 | 97636 | } |
| | @@ -97525,12 +97988,11 @@ |
| 97525 | 97988 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 97526 | 97989 | pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum)); |
| 97527 | 97990 | |
| 97528 | 97991 | if( pAccum ){ |
| 97529 | 97992 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 97530 | | - int firstTerm = pAccum->useMalloc==0; |
| 97531 | | - pAccum->useMalloc = 2; |
| 97993 | + int firstTerm = pAccum->mxAlloc==0; |
| 97532 | 97994 | pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH]; |
| 97533 | 97995 | if( !firstTerm ){ |
| 97534 | 97996 | if( argc==2 ){ |
| 97535 | 97997 | zSep = (char*)sqlite3_value_text(argv[1]); |
| 97536 | 97998 | nSep = sqlite3_value_bytes(argv[1]); |
| | @@ -98946,11 +99408,12 @@ |
| 98946 | 99408 | int iFromCol; /* Idx of column in child table */ |
| 98947 | 99409 | Expr *pEq; /* tFromCol = OLD.tToCol */ |
| 98948 | 99410 | |
| 98949 | 99411 | iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; |
| 98950 | 99412 | assert( iFromCol>=0 ); |
| 98951 | | - tToCol.z = pIdx ? pTab->aCol[pIdx->aiColumn[i]].zName : "oid"; |
| 99413 | + assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) ); |
| 99414 | + tToCol.z = pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName; |
| 98952 | 99415 | tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName; |
| 98953 | 99416 | |
| 98954 | 99417 | tToCol.n = sqlite3Strlen30(tToCol.z); |
| 98955 | 99418 | tFromCol.n = sqlite3Strlen30(tFromCol.z); |
| 98956 | 99419 | |
| | @@ -98958,14 +99421,14 @@ |
| 98958 | 99421 | ** that the "OLD.zToCol" term is on the LHS of the = operator, so |
| 98959 | 99422 | ** that the affinity and collation sequence associated with the |
| 98960 | 99423 | ** parent table are used for the comparison. */ |
| 98961 | 99424 | pEq = sqlite3PExpr(pParse, TK_EQ, |
| 98962 | 99425 | sqlite3PExpr(pParse, TK_DOT, |
| 98963 | | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld), |
| 98964 | | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol) |
| 99426 | + sqlite3ExprAlloc(db, TK_ID, &tOld, 0), |
| 99427 | + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0) |
| 98965 | 99428 | , 0), |
| 98966 | | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tFromCol) |
| 99429 | + sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0) |
| 98967 | 99430 | , 0); |
| 98968 | 99431 | pWhere = sqlite3ExprAnd(db, pWhere, pEq); |
| 98969 | 99432 | |
| 98970 | 99433 | /* For ON UPDATE, construct the next term of the WHEN clause. |
| 98971 | 99434 | ** The final WHEN clause will be like this: |
| | @@ -98973,27 +99436,27 @@ |
| 98973 | 99436 | ** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN) |
| 98974 | 99437 | */ |
| 98975 | 99438 | if( pChanges ){ |
| 98976 | 99439 | pEq = sqlite3PExpr(pParse, TK_IS, |
| 98977 | 99440 | sqlite3PExpr(pParse, TK_DOT, |
| 98978 | | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld), |
| 98979 | | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol), |
| 99441 | + sqlite3ExprAlloc(db, TK_ID, &tOld, 0), |
| 99442 | + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0), |
| 98980 | 99443 | 0), |
| 98981 | 99444 | sqlite3PExpr(pParse, TK_DOT, |
| 98982 | | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew), |
| 98983 | | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol), |
| 99445 | + sqlite3ExprAlloc(db, TK_ID, &tNew, 0), |
| 99446 | + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0), |
| 98984 | 99447 | 0), |
| 98985 | 99448 | 0); |
| 98986 | 99449 | pWhen = sqlite3ExprAnd(db, pWhen, pEq); |
| 98987 | 99450 | } |
| 98988 | 99451 | |
| 98989 | 99452 | if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){ |
| 98990 | 99453 | Expr *pNew; |
| 98991 | 99454 | if( action==OE_Cascade ){ |
| 98992 | 99455 | pNew = sqlite3PExpr(pParse, TK_DOT, |
| 98993 | | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew), |
| 98994 | | - sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol) |
| 99456 | + sqlite3ExprAlloc(db, TK_ID, &tNew, 0), |
| 99457 | + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0) |
| 98995 | 99458 | , 0); |
| 98996 | 99459 | }else if( action==OE_SetDflt ){ |
| 98997 | 99460 | Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt; |
| 98998 | 99461 | if( pDflt ){ |
| 98999 | 99462 | pNew = sqlite3ExprDup(db, pDflt, 0); |
| | @@ -99036,17 +99499,16 @@ |
| 99036 | 99499 | db->lookaside.bEnabled = 0; |
| 99037 | 99500 | |
| 99038 | 99501 | pTrigger = (Trigger *)sqlite3DbMallocZero(db, |
| 99039 | 99502 | sizeof(Trigger) + /* struct Trigger */ |
| 99040 | 99503 | sizeof(TriggerStep) + /* Single step in trigger program */ |
| 99041 | | - nFrom + 1 /* Space for pStep->target.z */ |
| 99504 | + nFrom + 1 /* Space for pStep->zTarget */ |
| 99042 | 99505 | ); |
| 99043 | 99506 | if( pTrigger ){ |
| 99044 | 99507 | pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1]; |
| 99045 | | - pStep->target.z = (char *)&pStep[1]; |
| 99046 | | - pStep->target.n = nFrom; |
| 99047 | | - memcpy((char *)pStep->target.z, zFrom, nFrom); |
| 99508 | + pStep->zTarget = (char *)&pStep[1]; |
| 99509 | + memcpy((char *)pStep->zTarget, zFrom, nFrom); |
| 99048 | 99510 | |
| 99049 | 99511 | pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE); |
| 99050 | 99512 | pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE); |
| 99051 | 99513 | pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE); |
| 99052 | 99514 | if( pWhen ){ |
| | @@ -99507,24 +99969,27 @@ |
| 99507 | 99969 | ); |
| 99508 | 99970 | |
| 99509 | 99971 | /* |
| 99510 | 99972 | ** This routine is called to handle SQL of the following forms: |
| 99511 | 99973 | ** |
| 99512 | | -** insert into TABLE (IDLIST) values(EXPRLIST) |
| 99974 | +** insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),... |
| 99513 | 99975 | ** insert into TABLE (IDLIST) select |
| 99976 | +** insert into TABLE (IDLIST) default values |
| 99514 | 99977 | ** |
| 99515 | 99978 | ** The IDLIST following the table name is always optional. If omitted, |
| 99516 | | -** then a list of all columns for the table is substituted. The IDLIST |
| 99517 | | -** appears in the pColumn parameter. pColumn is NULL if IDLIST is omitted. |
| 99979 | +** then a list of all (non-hidden) columns for the table is substituted. |
| 99980 | +** The IDLIST appears in the pColumn parameter. pColumn is NULL if IDLIST |
| 99981 | +** is omitted. |
| 99518 | 99982 | ** |
| 99519 | | -** The pList parameter holds EXPRLIST in the first form of the INSERT |
| 99520 | | -** statement above, and pSelect is NULL. For the second form, pList is |
| 99521 | | -** NULL and pSelect is a pointer to the select statement used to generate |
| 99522 | | -** data for the insert. |
| 99983 | +** For the pSelect parameter holds the values to be inserted for the |
| 99984 | +** first two forms shown above. A VALUES clause is really just short-hand |
| 99985 | +** for a SELECT statement that omits the FROM clause and everything else |
| 99986 | +** that follows. If the pSelect parameter is NULL, that means that the |
| 99987 | +** DEFAULT VALUES form of the INSERT statement is intended. |
| 99523 | 99988 | ** |
| 99524 | 99989 | ** The code generated follows one of four templates. For a simple |
| 99525 | | -** insert with data coming from a VALUES clause, the code executes |
| 99990 | +** insert with data coming from a single-row VALUES clause, the code executes |
| 99526 | 99991 | ** once straight down through. Pseudo-code follows (we call this |
| 99527 | 99992 | ** the "1st template"): |
| 99528 | 99993 | ** |
| 99529 | 99994 | ** open write cursor to <table> and its indices |
| 99530 | 99995 | ** put VALUES clause expressions into registers |
| | @@ -99627,11 +100092,11 @@ |
| 99627 | 100092 | int iDb; /* Index of database holding TABLE */ |
| 99628 | 100093 | Db *pDb; /* The database containing table being inserted into */ |
| 99629 | 100094 | u8 useTempTable = 0; /* Store SELECT results in intermediate table */ |
| 99630 | 100095 | u8 appendFlag = 0; /* True if the insert is likely to be an append */ |
| 99631 | 100096 | u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */ |
| 99632 | | - u8 bIdListInOrder = 1; /* True if IDLIST is in table order */ |
| 100097 | + u8 bIdListInOrder; /* True if IDLIST is in table order */ |
| 99633 | 100098 | ExprList *pList = 0; /* List of VALUES() to be inserted */ |
| 99634 | 100099 | |
| 99635 | 100100 | /* Register allocations */ |
| 99636 | 100101 | int regFromSelect = 0;/* Base register for data coming from SELECT */ |
| 99637 | 100102 | int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */ |
| | @@ -99652,12 +100117,12 @@ |
| 99652 | 100117 | if( pParse->nErr || db->mallocFailed ){ |
| 99653 | 100118 | goto insert_cleanup; |
| 99654 | 100119 | } |
| 99655 | 100120 | |
| 99656 | 100121 | /* If the Select object is really just a simple VALUES() list with a |
| 99657 | | - ** single row values (the common case) then keep that one row of values |
| 99658 | | - ** and go ahead and discard the Select object |
| 100122 | + ** single row (the common case) then keep that one row of values |
| 100123 | + ** and discard the other (unused) parts of the pSelect object |
| 99659 | 100124 | */ |
| 99660 | 100125 | if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){ |
| 99661 | 100126 | pList = pSelect->pEList; |
| 99662 | 100127 | pSelect->pEList = 0; |
| 99663 | 100128 | sqlite3SelectDelete(db, pSelect); |
| | @@ -99761,10 +100226,11 @@ |
| 99761 | 100226 | ** the index into IDLIST of the primary key column. ipkColumn is |
| 99762 | 100227 | ** the index of the primary key as it appears in IDLIST, not as |
| 99763 | 100228 | ** is appears in the original table. (The index of the INTEGER |
| 99764 | 100229 | ** PRIMARY KEY in the original table is pTab->iPKey.) |
| 99765 | 100230 | */ |
| 100231 | + bIdListInOrder = (pTab->tabFlags & TF_OOOHidden)==0; |
| 99766 | 100232 | if( pColumn ){ |
| 99767 | 100233 | for(i=0; i<pColumn->nId; i++){ |
| 99768 | 100234 | pColumn->a[i].idx = -1; |
| 99769 | 100235 | } |
| 99770 | 100236 | for(i=0; i<pColumn->nId; i++){ |
| | @@ -99796,11 +100262,12 @@ |
| 99796 | 100262 | ** is coming from a SELECT statement, then generate a co-routine that |
| 99797 | 100263 | ** produces a single row of the SELECT on each invocation. The |
| 99798 | 100264 | ** co-routine is the common header to the 3rd and 4th templates. |
| 99799 | 100265 | */ |
| 99800 | 100266 | if( pSelect ){ |
| 99801 | | - /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */ |
| 100267 | + /* Data is coming from a SELECT or from a multi-row VALUES clause. |
| 100268 | + ** Generate a co-routine to run the SELECT. */ |
| 99802 | 100269 | int regYield; /* Register holding co-routine entry-point */ |
| 99803 | 100270 | int addrTop; /* Top of the co-routine */ |
| 99804 | 100271 | int rc; /* Result code */ |
| 99805 | 100272 | |
| 99806 | 100273 | regYield = ++pParse->nMem; |
| | @@ -99809,12 +100276,11 @@ |
| 99809 | 100276 | sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); |
| 99810 | 100277 | dest.iSdst = bIdListInOrder ? regData : 0; |
| 99811 | 100278 | dest.nSdst = pTab->nCol; |
| 99812 | 100279 | rc = sqlite3Select(pParse, pSelect, &dest); |
| 99813 | 100280 | regFromSelect = dest.iSdst; |
| 99814 | | - assert( pParse->nErr==0 || rc ); |
| 99815 | | - if( rc || db->mallocFailed ) goto insert_cleanup; |
| 100281 | + if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup; |
| 99816 | 100282 | sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield); |
| 99817 | 100283 | sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */ |
| 99818 | 100284 | assert( pSelect->pEList ); |
| 99819 | 100285 | nColumn = pSelect->pEList->nExpr; |
| 99820 | 100286 | |
| | @@ -99858,12 +100324,12 @@ |
| 99858 | 100324 | sqlite3VdbeJumpHere(v, addrL); |
| 99859 | 100325 | sqlite3ReleaseTempReg(pParse, regRec); |
| 99860 | 100326 | sqlite3ReleaseTempReg(pParse, regTempRowid); |
| 99861 | 100327 | } |
| 99862 | 100328 | }else{ |
| 99863 | | - /* This is the case if the data for the INSERT is coming from a VALUES |
| 99864 | | - ** clause |
| 100329 | + /* This is the case if the data for the INSERT is coming from a |
| 100330 | + ** single-row VALUES clause |
| 99865 | 100331 | */ |
| 99866 | 100332 | NameContext sNC; |
| 99867 | 100333 | memset(&sNC, 0, sizeof(sNC)); |
| 99868 | 100334 | sNC.pParse = pParse; |
| 99869 | 100335 | srcTab = -1; |
| | @@ -100930,10 +101396,11 @@ |
| 100930 | 101396 | Table *pDest, /* The table we are inserting into */ |
| 100931 | 101397 | Select *pSelect, /* A SELECT statement to use as the data source */ |
| 100932 | 101398 | int onError, /* How to handle constraint errors */ |
| 100933 | 101399 | int iDbDest /* The database of pDest */ |
| 100934 | 101400 | ){ |
| 101401 | + sqlite3 *db = pParse->db; |
| 100935 | 101402 | ExprList *pEList; /* The result set of the SELECT */ |
| 100936 | 101403 | Table *pSrc; /* The table in the FROM clause of SELECT */ |
| 100937 | 101404 | Index *pSrcIdx, *pDestIdx; /* Source and destination indices */ |
| 100938 | 101405 | struct SrcList_item *pItem; /* An element of pSelect->pSrc */ |
| 100939 | 101406 | int i; /* Loop counter */ |
| | @@ -101077,15 +101544,15 @@ |
| 101077 | 101544 | ** But the main beneficiary of the transfer optimization is the VACUUM |
| 101078 | 101545 | ** command, and the VACUUM command disables foreign key constraints. So |
| 101079 | 101546 | ** the extra complication to make this rule less restrictive is probably |
| 101080 | 101547 | ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] |
| 101081 | 101548 | */ |
| 101082 | | - if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ |
| 101549 | + if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ |
| 101083 | 101550 | return 0; |
| 101084 | 101551 | } |
| 101085 | 101552 | #endif |
| 101086 | | - if( (pParse->db->flags & SQLITE_CountRows)!=0 ){ |
| 101553 | + if( (db->flags & SQLITE_CountRows)!=0 ){ |
| 101087 | 101554 | return 0; /* xfer opt does not play well with PRAGMA count_changes */ |
| 101088 | 101555 | } |
| 101089 | 101556 | |
| 101090 | 101557 | /* If we get this far, it means that the xfer optimization is at |
| 101091 | 101558 | ** least a possibility, though it might only work if the destination |
| | @@ -101092,28 +101559,32 @@ |
| 101092 | 101559 | ** table (tab1) is initially empty. |
| 101093 | 101560 | */ |
| 101094 | 101561 | #ifdef SQLITE_TEST |
| 101095 | 101562 | sqlite3_xferopt_count++; |
| 101096 | 101563 | #endif |
| 101097 | | - iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema); |
| 101564 | + iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema); |
| 101098 | 101565 | v = sqlite3GetVdbe(pParse); |
| 101099 | 101566 | sqlite3CodeVerifySchema(pParse, iDbSrc); |
| 101100 | 101567 | iSrc = pParse->nTab++; |
| 101101 | 101568 | iDest = pParse->nTab++; |
| 101102 | 101569 | regAutoinc = autoIncBegin(pParse, iDbDest, pDest); |
| 101103 | 101570 | regData = sqlite3GetTempReg(pParse); |
| 101104 | 101571 | regRowid = sqlite3GetTempReg(pParse); |
| 101105 | 101572 | sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite); |
| 101106 | 101573 | assert( HasRowid(pDest) || destHasUniqueIdx ); |
| 101107 | | - if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */ |
| 101574 | + if( (db->flags & SQLITE_Vacuum)==0 && ( |
| 101575 | + (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */ |
| 101108 | 101576 | || destHasUniqueIdx /* (2) */ |
| 101109 | 101577 | || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */ |
| 101110 | | - ){ |
| 101578 | + )){ |
| 101111 | 101579 | /* In some circumstances, we are able to run the xfer optimization |
| 101112 | | - ** only if the destination table is initially empty. This code makes |
| 101113 | | - ** that determination. Conditions under which the destination must |
| 101114 | | - ** be empty: |
| 101580 | + ** only if the destination table is initially empty. Unless the |
| 101581 | + ** SQLITE_Vacuum flag is set, this block generates code to make |
| 101582 | + ** that determination. If SQLITE_Vacuum is set, then the destination |
| 101583 | + ** table is always empty. |
| 101584 | + ** |
| 101585 | + ** Conditions under which the destination must be empty: |
| 101115 | 101586 | ** |
| 101116 | 101587 | ** (1) There is no INTEGER PRIMARY KEY but there are indices. |
| 101117 | 101588 | ** (If the destination is not initially empty, the rowid fields |
| 101118 | 101589 | ** of index entries might need to change.) |
| 101119 | 101590 | ** |
| | @@ -101152,10 +101623,11 @@ |
| 101152 | 101623 | }else{ |
| 101153 | 101624 | sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName); |
| 101154 | 101625 | sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName); |
| 101155 | 101626 | } |
| 101156 | 101627 | for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){ |
| 101628 | + u8 useSeekResult = 0; |
| 101157 | 101629 | for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){ |
| 101158 | 101630 | if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break; |
| 101159 | 101631 | } |
| 101160 | 101632 | assert( pSrcIdx ); |
| 101161 | 101633 | sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc); |
| | @@ -101165,11 +101637,37 @@ |
| 101165 | 101637 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 101166 | 101638 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 101167 | 101639 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 101168 | 101640 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 101169 | 101641 | sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData); |
| 101642 | + if( db->flags & SQLITE_Vacuum ){ |
| 101643 | + /* This INSERT command is part of a VACUUM operation, which guarantees |
| 101644 | + ** that the destination table is empty. If all indexed columns use |
| 101645 | + ** collation sequence BINARY, then it can also be assumed that the |
| 101646 | + ** index will be populated by inserting keys in strictly sorted |
| 101647 | + ** order. In this case, instead of seeking within the b-tree as part |
| 101648 | + ** of every OP_IdxInsert opcode, an OP_Last is added before the |
| 101649 | + ** OP_IdxInsert to seek to the point within the b-tree where each key |
| 101650 | + ** should be inserted. This is faster. |
| 101651 | + ** |
| 101652 | + ** If any of the indexed columns use a collation sequence other than |
| 101653 | + ** BINARY, this optimization is disabled. This is because the user |
| 101654 | + ** might change the definition of a collation sequence and then run |
| 101655 | + ** a VACUUM command. In that case keys may not be written in strictly |
| 101656 | + ** sorted order. */ |
| 101657 | + for(i=0; i<pSrcIdx->nColumn; i++){ |
| 101658 | + char *zColl = pSrcIdx->azColl[i]; |
| 101659 | + assert( zColl!=0 ); |
| 101660 | + if( sqlite3_stricmp("BINARY", zColl) ) break; |
| 101661 | + } |
| 101662 | + if( i==pSrcIdx->nColumn ){ |
| 101663 | + useSeekResult = OPFLAG_USESEEKRESULT; |
| 101664 | + sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1); |
| 101665 | + } |
| 101666 | + } |
| 101170 | 101667 | sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1); |
| 101668 | + sqlite3VdbeChangeP5(v, useSeekResult); |
| 101171 | 101669 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v); |
| 101172 | 101670 | sqlite3VdbeJumpHere(v, addr1); |
| 101173 | 101671 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| 101174 | 101672 | sqlite3VdbeAddOp2(v, OP_Close, iDest, 0); |
| 101175 | 101673 | } |
| | @@ -101215,11 +101713,11 @@ |
| 101215 | 101713 | ** If the SQL is a query, then for each row in the query result |
| 101216 | 101714 | ** the xCallback() function is called. pArg becomes the first |
| 101217 | 101715 | ** argument to xCallback(). If xCallback=NULL then no callback |
| 101218 | 101716 | ** is invoked, even for queries. |
| 101219 | 101717 | */ |
| 101220 | | -SQLITE_API int sqlite3_exec( |
| 101718 | +SQLITE_API int SQLITE_STDCALL sqlite3_exec( |
| 101221 | 101719 | sqlite3 *db, /* The database on which the SQL executes */ |
| 101222 | 101720 | const char *zSql, /* The SQL to be executed */ |
| 101223 | 101721 | sqlite3_callback xCallback, /* Invoke this callback routine */ |
| 101224 | 101722 | void *pArg, /* First argument to xCallback() */ |
| 101225 | 101723 | char **pzErrMsg /* Write error messages here */ |
| | @@ -102284,11 +102782,11 @@ |
| 102284 | 102782 | int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); |
| 102285 | 102783 | char *zErrmsg = 0; |
| 102286 | 102784 | const char *zEntry; |
| 102287 | 102785 | char *zAltEntry = 0; |
| 102288 | 102786 | void **aHandle; |
| 102289 | | - int nMsg = 300 + sqlite3Strlen30(zFile); |
| 102787 | + u64 nMsg = 300 + sqlite3Strlen30(zFile); |
| 102290 | 102788 | int ii; |
| 102291 | 102789 | |
| 102292 | 102790 | /* Shared library endings to try if zFile cannot be loaded as written */ |
| 102293 | 102791 | static const char *azEndings[] = { |
| 102294 | 102792 | #if SQLITE_OS_WIN |
| | @@ -102327,11 +102825,11 @@ |
| 102327 | 102825 | sqlite3_free(zAltFile); |
| 102328 | 102826 | } |
| 102329 | 102827 | #endif |
| 102330 | 102828 | if( handle==0 ){ |
| 102331 | 102829 | if( pzErrMsg ){ |
| 102332 | | - *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg); |
| 102830 | + *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg); |
| 102333 | 102831 | if( zErrmsg ){ |
| 102334 | 102832 | sqlite3_snprintf(nMsg, zErrmsg, |
| 102335 | 102833 | "unable to open shared library [%s]", zFile); |
| 102336 | 102834 | sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); |
| 102337 | 102835 | } |
| | @@ -102353,11 +102851,11 @@ |
| 102353 | 102851 | ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init |
| 102354 | 102852 | */ |
| 102355 | 102853 | if( xInit==0 && zProc==0 ){ |
| 102356 | 102854 | int iFile, iEntry, c; |
| 102357 | 102855 | int ncFile = sqlite3Strlen30(zFile); |
| 102358 | | - zAltEntry = sqlite3_malloc(ncFile+30); |
| 102856 | + zAltEntry = sqlite3_malloc64(ncFile+30); |
| 102359 | 102857 | if( zAltEntry==0 ){ |
| 102360 | 102858 | sqlite3OsDlClose(pVfs, handle); |
| 102361 | 102859 | return SQLITE_NOMEM; |
| 102362 | 102860 | } |
| 102363 | 102861 | memcpy(zAltEntry, "sqlite3_", 8); |
| | @@ -102375,11 +102873,11 @@ |
| 102375 | 102873 | sqlite3OsDlSym(pVfs, handle, zEntry); |
| 102376 | 102874 | } |
| 102377 | 102875 | if( xInit==0 ){ |
| 102378 | 102876 | if( pzErrMsg ){ |
| 102379 | 102877 | nMsg += sqlite3Strlen30(zEntry); |
| 102380 | | - *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg); |
| 102878 | + *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg); |
| 102381 | 102879 | if( zErrmsg ){ |
| 102382 | 102880 | sqlite3_snprintf(nMsg, zErrmsg, |
| 102383 | 102881 | "no entry point [%s] in shared library [%s]", zEntry, zFile); |
| 102384 | 102882 | sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); |
| 102385 | 102883 | } |
| | @@ -102410,11 +102908,11 @@ |
| 102410 | 102908 | db->aExtension = aHandle; |
| 102411 | 102909 | |
| 102412 | 102910 | db->aExtension[db->nExtension++] = handle; |
| 102413 | 102911 | return SQLITE_OK; |
| 102414 | 102912 | } |
| 102415 | | -SQLITE_API int sqlite3_load_extension( |
| 102913 | +SQLITE_API int SQLITE_STDCALL sqlite3_load_extension( |
| 102416 | 102914 | sqlite3 *db, /* Load the extension into this database connection */ |
| 102417 | 102915 | const char *zFile, /* Name of the shared library containing extension */ |
| 102418 | 102916 | const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */ |
| 102419 | 102917 | char **pzErrMsg /* Put error message here if not 0 */ |
| 102420 | 102918 | ){ |
| | @@ -102441,11 +102939,11 @@ |
| 102441 | 102939 | |
| 102442 | 102940 | /* |
| 102443 | 102941 | ** Enable or disable extension loading. Extension loading is disabled by |
| 102444 | 102942 | ** default so as not to open security holes in older applications. |
| 102445 | 102943 | */ |
| 102446 | | -SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff){ |
| 102944 | +SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff){ |
| 102447 | 102945 | sqlite3_mutex_enter(db->mutex); |
| 102448 | 102946 | if( onoff ){ |
| 102449 | 102947 | db->flags |= SQLITE_LoadExtension; |
| 102450 | 102948 | }else{ |
| 102451 | 102949 | db->flags &= ~SQLITE_LoadExtension; |
| | @@ -102474,11 +102972,11 @@ |
| 102474 | 102972 | ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER |
| 102475 | 102973 | ** mutex must be held while accessing this list. |
| 102476 | 102974 | */ |
| 102477 | 102975 | typedef struct sqlite3AutoExtList sqlite3AutoExtList; |
| 102478 | 102976 | static SQLITE_WSD struct sqlite3AutoExtList { |
| 102479 | | - int nExt; /* Number of entries in aExt[] */ |
| 102977 | + u32 nExt; /* Number of entries in aExt[] */ |
| 102480 | 102978 | void (**aExt)(void); /* Pointers to the extension init functions */ |
| 102481 | 102979 | } sqlite3Autoext = { 0, 0 }; |
| 102482 | 102980 | |
| 102483 | 102981 | /* The "wsdAutoext" macro will resolve to the autoextension |
| 102484 | 102982 | ** state vector. If writable static data is unsupported on the target, |
| | @@ -102498,32 +102996,32 @@ |
| 102498 | 102996 | |
| 102499 | 102997 | /* |
| 102500 | 102998 | ** Register a statically linked extension that is automatically |
| 102501 | 102999 | ** loaded by every new database connection. |
| 102502 | 103000 | */ |
| 102503 | | -SQLITE_API int sqlite3_auto_extension(void (*xInit)(void)){ |
| 103001 | +SQLITE_API int SQLITE_STDCALL sqlite3_auto_extension(void (*xInit)(void)){ |
| 102504 | 103002 | int rc = SQLITE_OK; |
| 102505 | 103003 | #ifndef SQLITE_OMIT_AUTOINIT |
| 102506 | 103004 | rc = sqlite3_initialize(); |
| 102507 | 103005 | if( rc ){ |
| 102508 | 103006 | return rc; |
| 102509 | 103007 | }else |
| 102510 | 103008 | #endif |
| 102511 | 103009 | { |
| 102512 | | - int i; |
| 103010 | + u32 i; |
| 102513 | 103011 | #if SQLITE_THREADSAFE |
| 102514 | 103012 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 102515 | 103013 | #endif |
| 102516 | 103014 | wsdAutoextInit; |
| 102517 | 103015 | sqlite3_mutex_enter(mutex); |
| 102518 | 103016 | for(i=0; i<wsdAutoext.nExt; i++){ |
| 102519 | 103017 | if( wsdAutoext.aExt[i]==xInit ) break; |
| 102520 | 103018 | } |
| 102521 | 103019 | if( i==wsdAutoext.nExt ){ |
| 102522 | | - int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]); |
| 103020 | + u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]); |
| 102523 | 103021 | void (**aNew)(void); |
| 102524 | | - aNew = sqlite3_realloc(wsdAutoext.aExt, nByte); |
| 103022 | + aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte); |
| 102525 | 103023 | if( aNew==0 ){ |
| 102526 | 103024 | rc = SQLITE_NOMEM; |
| 102527 | 103025 | }else{ |
| 102528 | 103026 | wsdAutoext.aExt = aNew; |
| 102529 | 103027 | wsdAutoext.aExt[wsdAutoext.nExt] = xInit; |
| | @@ -102543,19 +103041,19 @@ |
| 102543 | 103041 | ** routine is a no-op. |
| 102544 | 103042 | ** |
| 102545 | 103043 | ** Return 1 if xInit was found on the list and removed. Return 0 if xInit |
| 102546 | 103044 | ** was not on the list. |
| 102547 | 103045 | */ |
| 102548 | | -SQLITE_API int sqlite3_cancel_auto_extension(void (*xInit)(void)){ |
| 103046 | +SQLITE_API int SQLITE_STDCALL sqlite3_cancel_auto_extension(void (*xInit)(void)){ |
| 102549 | 103047 | #if SQLITE_THREADSAFE |
| 102550 | 103048 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 102551 | 103049 | #endif |
| 102552 | 103050 | int i; |
| 102553 | 103051 | int n = 0; |
| 102554 | 103052 | wsdAutoextInit; |
| 102555 | 103053 | sqlite3_mutex_enter(mutex); |
| 102556 | | - for(i=wsdAutoext.nExt-1; i>=0; i--){ |
| 103054 | + for(i=(int)wsdAutoext.nExt-1; i>=0; i--){ |
| 102557 | 103055 | if( wsdAutoext.aExt[i]==xInit ){ |
| 102558 | 103056 | wsdAutoext.nExt--; |
| 102559 | 103057 | wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt]; |
| 102560 | 103058 | n++; |
| 102561 | 103059 | break; |
| | @@ -102566,11 +103064,11 @@ |
| 102566 | 103064 | } |
| 102567 | 103065 | |
| 102568 | 103066 | /* |
| 102569 | 103067 | ** Reset the automatic extension loading mechanism. |
| 102570 | 103068 | */ |
| 102571 | | -SQLITE_API void sqlite3_reset_auto_extension(void){ |
| 103069 | +SQLITE_API void SQLITE_STDCALL sqlite3_reset_auto_extension(void){ |
| 102572 | 103070 | #ifndef SQLITE_OMIT_AUTOINIT |
| 102573 | 103071 | if( sqlite3_initialize()==SQLITE_OK ) |
| 102574 | 103072 | #endif |
| 102575 | 103073 | { |
| 102576 | 103074 | #if SQLITE_THREADSAFE |
| | @@ -102589,11 +103087,11 @@ |
| 102589 | 103087 | ** Load all automatic extensions. |
| 102590 | 103088 | ** |
| 102591 | 103089 | ** If anything goes wrong, set an error in the database connection. |
| 102592 | 103090 | */ |
| 102593 | 103091 | SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){ |
| 102594 | | - int i; |
| 103092 | + u32 i; |
| 102595 | 103093 | int go = 1; |
| 102596 | 103094 | int rc; |
| 102597 | 103095 | int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); |
| 102598 | 103096 | |
| 102599 | 103097 | wsdAutoextInit; |
| | @@ -103253,19 +103751,19 @@ |
| 103253 | 103751 | /* |
| 103254 | 103752 | ** Generate code to return a single integer value. |
| 103255 | 103753 | */ |
| 103256 | 103754 | static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){ |
| 103257 | 103755 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 103258 | | - int mem = ++pParse->nMem; |
| 103756 | + int nMem = ++pParse->nMem; |
| 103259 | 103757 | i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value)); |
| 103260 | 103758 | if( pI64 ){ |
| 103261 | 103759 | memcpy(pI64, &value, sizeof(value)); |
| 103262 | 103760 | } |
| 103263 | | - sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64); |
| 103761 | + sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64); |
| 103264 | 103762 | sqlite3VdbeSetNumCols(v, 1); |
| 103265 | 103763 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC); |
| 103266 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); |
| 103764 | + sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1); |
| 103267 | 103765 | } |
| 103268 | 103766 | |
| 103269 | 103767 | |
| 103270 | 103768 | /* |
| 103271 | 103769 | ** Set the safety_level and pager flags for pager iDb. Or if iDb<0 |
| | @@ -103426,15 +103924,15 @@ |
| 103426 | 103924 | aFcntl[3] = 0; |
| 103427 | 103925 | db->busyHandler.nBusy = 0; |
| 103428 | 103926 | rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl); |
| 103429 | 103927 | if( rc==SQLITE_OK ){ |
| 103430 | 103928 | if( aFcntl[0] ){ |
| 103431 | | - int mem = ++pParse->nMem; |
| 103432 | | - sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0); |
| 103929 | + int nMem = ++pParse->nMem; |
| 103930 | + sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0); |
| 103433 | 103931 | sqlite3VdbeSetNumCols(v, 1); |
| 103434 | 103932 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC); |
| 103435 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); |
| 103933 | + sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1); |
| 103436 | 103934 | sqlite3_free(aFcntl[0]); |
| 103437 | 103935 | } |
| 103438 | 103936 | goto pragma_out; |
| 103439 | 103937 | } |
| 103440 | 103938 | if( rc!=SQLITE_NOTFOUND ){ |
| | @@ -104035,11 +104533,13 @@ |
| 104035 | 104533 | }else{ |
| 104036 | 104534 | if( !db->autoCommit ){ |
| 104037 | 104535 | sqlite3ErrorMsg(pParse, |
| 104038 | 104536 | "Safety level may not be changed inside a transaction"); |
| 104039 | 104537 | }else{ |
| 104040 | | - pDb->safety_level = getSafetyLevel(zRight,0,1)+1; |
| 104538 | + int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK; |
| 104539 | + if( iLevel==0 ) iLevel = 1; |
| 104540 | + pDb->safety_level = iLevel; |
| 104041 | 104541 | setAllPagerFlags(db); |
| 104042 | 104542 | } |
| 104043 | 104543 | } |
| 104044 | 104544 | break; |
| 104045 | 104545 | } |
| | @@ -104130,11 +104630,11 @@ |
| 104130 | 104630 | if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){ |
| 104131 | 104631 | k = 0; |
| 104132 | 104632 | }else if( pPk==0 ){ |
| 104133 | 104633 | k = 1; |
| 104134 | 104634 | }else{ |
| 104135 | | - for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){} |
| 104635 | + for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} |
| 104136 | 104636 | } |
| 104137 | 104637 | sqlite3VdbeAddOp2(v, OP_Integer, k, 6); |
| 104138 | 104638 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); |
| 104139 | 104639 | } |
| 104140 | 104640 | } |
| | @@ -105136,11 +105636,11 @@ |
| 105136 | 105636 | |
| 105137 | 105637 | assert( iDb>=0 && iDb<db->nDb ); |
| 105138 | 105638 | if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */ |
| 105139 | 105639 | if( argv[1]==0 ){ |
| 105140 | 105640 | corruptSchema(pData, argv[0], 0); |
| 105141 | | - }else if( argv[2] && argv[2][0] ){ |
| 105641 | + }else if( sqlite3_strnicmp(argv[2],"create ",7)==0 ){ |
| 105142 | 105642 | /* Call the parser to process a CREATE TABLE, INDEX or VIEW. |
| 105143 | 105643 | ** But because db->init.busy is set to 1, no VDBE code is generated |
| 105144 | 105644 | ** or executed. All the parser does is build the internal data |
| 105145 | 105645 | ** structures that describe the table, index, or view. |
| 105146 | 105646 | */ |
| | @@ -105167,12 +105667,12 @@ |
| 105167 | 105667 | corruptSchema(pData, argv[0], sqlite3_errmsg(db)); |
| 105168 | 105668 | } |
| 105169 | 105669 | } |
| 105170 | 105670 | } |
| 105171 | 105671 | sqlite3_finalize(pStmt); |
| 105172 | | - }else if( argv[0]==0 ){ |
| 105173 | | - corruptSchema(pData, 0, 0); |
| 105672 | + }else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){ |
| 105673 | + corruptSchema(pData, argv[0], 0); |
| 105174 | 105674 | }else{ |
| 105175 | 105675 | /* If the SQL column is blank it means this is an index that |
| 105176 | 105676 | ** was created to be the PRIMARY KEY or to fulfill a UNIQUE |
| 105177 | 105677 | ** constraint for a CREATE TABLE. The index should have already |
| 105178 | 105678 | ** been created when we processed the CREATE TABLE. All we have |
| | @@ -105846,11 +106346,11 @@ |
| 105846 | 106346 | ** and so if a schema change occurs, SQLITE_SCHEMA is returned by |
| 105847 | 106347 | ** sqlite3_step(). In the new version, the original SQL text is retained |
| 105848 | 106348 | ** and the statement is automatically recompiled if an schema change |
| 105849 | 106349 | ** occurs. |
| 105850 | 106350 | */ |
| 105851 | | -SQLITE_API int sqlite3_prepare( |
| 106351 | +SQLITE_API int SQLITE_STDCALL sqlite3_prepare( |
| 105852 | 106352 | sqlite3 *db, /* Database handle. */ |
| 105853 | 106353 | const char *zSql, /* UTF-8 encoded SQL statement. */ |
| 105854 | 106354 | int nBytes, /* Length of zSql in bytes. */ |
| 105855 | 106355 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 105856 | 106356 | const char **pzTail /* OUT: End of parsed string */ |
| | @@ -105858,11 +106358,11 @@ |
| 105858 | 106358 | int rc; |
| 105859 | 106359 | rc = sqlite3LockAndPrepare(db,zSql,nBytes,0,0,ppStmt,pzTail); |
| 105860 | 106360 | assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */ |
| 105861 | 106361 | return rc; |
| 105862 | 106362 | } |
| 105863 | | -SQLITE_API int sqlite3_prepare_v2( |
| 106363 | +SQLITE_API int SQLITE_STDCALL sqlite3_prepare_v2( |
| 105864 | 106364 | sqlite3 *db, /* Database handle. */ |
| 105865 | 106365 | const char *zSql, /* UTF-8 encoded SQL statement. */ |
| 105866 | 106366 | int nBytes, /* Length of zSql in bytes. */ |
| 105867 | 106367 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 105868 | 106368 | const char **pzTail /* OUT: End of parsed string */ |
| | @@ -105934,11 +106434,11 @@ |
| 105934 | 106434 | ** and so if a schema change occurs, SQLITE_SCHEMA is returned by |
| 105935 | 106435 | ** sqlite3_step(). In the new version, the original SQL text is retained |
| 105936 | 106436 | ** and the statement is automatically recompiled if an schema change |
| 105937 | 106437 | ** occurs. |
| 105938 | 106438 | */ |
| 105939 | | -SQLITE_API int sqlite3_prepare16( |
| 106439 | +SQLITE_API int SQLITE_STDCALL sqlite3_prepare16( |
| 105940 | 106440 | sqlite3 *db, /* Database handle. */ |
| 105941 | 106441 | const void *zSql, /* UTF-16 encoded SQL statement. */ |
| 105942 | 106442 | int nBytes, /* Length of zSql in bytes. */ |
| 105943 | 106443 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 105944 | 106444 | const void **pzTail /* OUT: End of parsed string */ |
| | @@ -105946,11 +106446,11 @@ |
| 105946 | 106446 | int rc; |
| 105947 | 106447 | rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail); |
| 105948 | 106448 | assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */ |
| 105949 | 106449 | return rc; |
| 105950 | 106450 | } |
| 105951 | | -SQLITE_API int sqlite3_prepare16_v2( |
| 106451 | +SQLITE_API int SQLITE_STDCALL sqlite3_prepare16_v2( |
| 105952 | 106452 | sqlite3 *db, /* Database handle. */ |
| 105953 | 106453 | const void *zSql, /* UTF-16 encoded SQL statement. */ |
| 105954 | 106454 | int nBytes, /* Length of zSql in bytes. */ |
| 105955 | 106455 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 105956 | 106456 | const void **pzTail /* OUT: End of parsed string */ |
| | @@ -106075,11 +106575,10 @@ |
| 106075 | 106575 | ){ |
| 106076 | 106576 | Select *pNew; |
| 106077 | 106577 | Select standin; |
| 106078 | 106578 | sqlite3 *db = pParse->db; |
| 106079 | 106579 | pNew = sqlite3DbMallocZero(db, sizeof(*pNew) ); |
| 106080 | | - assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */ |
| 106081 | 106580 | if( pNew==0 ){ |
| 106082 | 106581 | assert( db->mallocFailed ); |
| 106083 | 106582 | pNew = &standin; |
| 106084 | 106583 | memset(pNew, 0, sizeof(*pNew)); |
| 106085 | 106584 | } |
| | @@ -106095,11 +106594,11 @@ |
| 106095 | 106594 | pNew->pOrderBy = pOrderBy; |
| 106096 | 106595 | pNew->selFlags = selFlags; |
| 106097 | 106596 | pNew->op = TK_SELECT; |
| 106098 | 106597 | pNew->pLimit = pLimit; |
| 106099 | 106598 | pNew->pOffset = pOffset; |
| 106100 | | - assert( pOffset==0 || pLimit!=0 ); |
| 106599 | + assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 ); |
| 106101 | 106600 | pNew->addrOpenEphm[0] = -1; |
| 106102 | 106601 | pNew->addrOpenEphm[1] = -1; |
| 106103 | 106602 | if( db->mallocFailed ) { |
| 106104 | 106603 | clearSelect(db, pNew, pNew!=&standin); |
| 106105 | 106604 | pNew = 0; |
| | @@ -107345,11 +107844,11 @@ |
| 107345 | 107844 | if( pS ){ |
| 107346 | 107845 | /* The "table" is actually a sub-select or a view in the FROM clause |
| 107347 | 107846 | ** of the SELECT statement. Return the declaration type and origin |
| 107348 | 107847 | ** data for the result-set column of the sub-select. |
| 107349 | 107848 | */ |
| 107350 | | - if( iCol>=0 && ALWAYS(iCol<pS->pEList->nExpr) ){ |
| 107849 | + if( iCol>=0 && iCol<pS->pEList->nExpr ){ |
| 107351 | 107850 | /* If iCol is less than zero, then the expression requests the |
| 107352 | 107851 | ** rowid of the sub-select or view. This expression is legal (see |
| 107353 | 107852 | ** test case misc2.2.2) - it always evaluates to NULL. |
| 107354 | 107853 | */ |
| 107355 | 107854 | NameContext sNC; |
| | @@ -107665,16 +108164,18 @@ |
| 107665 | 108164 | memset(&sNC, 0, sizeof(sNC)); |
| 107666 | 108165 | sNC.pSrcList = pSelect->pSrc; |
| 107667 | 108166 | a = pSelect->pEList->a; |
| 107668 | 108167 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
| 107669 | 108168 | p = a[i].pExpr; |
| 107670 | | - pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst)); |
| 108169 | + if( pCol->zType==0 ){ |
| 108170 | + pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst)); |
| 108171 | + } |
| 107671 | 108172 | szAll += pCol->szEst; |
| 107672 | 108173 | pCol->affinity = sqlite3ExprAffinity(p); |
| 107673 | 108174 | if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE; |
| 107674 | 108175 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 107675 | | - if( pColl ){ |
| 108176 | + if( pColl && pCol->zColl==0 ){ |
| 107676 | 108177 | pCol->zColl = sqlite3DbStrDup(db, pColl->zName); |
| 107677 | 108178 | } |
| 107678 | 108179 | } |
| 107679 | 108180 | pTab->szTabRow = sqlite3LogEst(szAll*4); |
| 107680 | 108181 | } |
| | @@ -108072,12 +108573,11 @@ |
| 108072 | 108573 | ){ |
| 108073 | 108574 | Select *pPrior; |
| 108074 | 108575 | int nExpr = p->pEList->nExpr; |
| 108075 | 108576 | int nRow = 1; |
| 108076 | 108577 | int rc = 0; |
| 108077 | | - assert( p->pNext==0 ); |
| 108078 | | - assert( p->selFlags & SF_AllValues ); |
| 108578 | + assert( p->selFlags & SF_MultiValue ); |
| 108079 | 108579 | do{ |
| 108080 | 108580 | assert( p->selFlags & SF_Values ); |
| 108081 | 108581 | assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) ); |
| 108082 | 108582 | assert( p->pLimit==0 ); |
| 108083 | 108583 | assert( p->pOffset==0 ); |
| | @@ -108182,11 +108682,11 @@ |
| 108182 | 108682 | dest.eDest = SRT_Table; |
| 108183 | 108683 | } |
| 108184 | 108684 | |
| 108185 | 108685 | /* Special handling for a compound-select that originates as a VALUES clause. |
| 108186 | 108686 | */ |
| 108187 | | - if( p->selFlags & SF_AllValues ){ |
| 108687 | + if( p->selFlags & SF_MultiValue ){ |
| 108188 | 108688 | rc = multiSelectValues(pParse, p, &dest); |
| 108189 | 108689 | goto multi_select_end; |
| 108190 | 108690 | } |
| 108191 | 108691 | |
| 108192 | 108692 | /* Make sure all SELECTs in the statement have the same number of elements |
| | @@ -108567,11 +109067,11 @@ |
| 108567 | 109067 | ** then there should be a single item on the stack. Write this |
| 108568 | 109068 | ** item into the set table with bogus data. |
| 108569 | 109069 | */ |
| 108570 | 109070 | case SRT_Set: { |
| 108571 | 109071 | int r1; |
| 108572 | | - assert( pIn->nSdst==1 ); |
| 109072 | + assert( pIn->nSdst==1 || pParse->nErr>0 ); |
| 108573 | 109073 | pDest->affSdst = |
| 108574 | 109074 | sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst); |
| 108575 | 109075 | r1 = sqlite3GetTempReg(pParse); |
| 108576 | 109076 | sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1); |
| 108577 | 109077 | sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1); |
| | @@ -108593,11 +109093,11 @@ |
| 108593 | 109093 | /* If this is a scalar select that is part of an expression, then |
| 108594 | 109094 | ** store the results in the appropriate memory cell and break out |
| 108595 | 109095 | ** of the scan loop. |
| 108596 | 109096 | */ |
| 108597 | 109097 | case SRT_Mem: { |
| 108598 | | - assert( pIn->nSdst==1 ); |
| 109098 | + assert( pIn->nSdst==1 || pParse->nErr>0 ); testcase( pIn->nSdst!=1 ); |
| 108599 | 109099 | sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1); |
| 108600 | 109100 | /* The LIMIT clause will jump out of the loop for us */ |
| 108601 | 109101 | break; |
| 108602 | 109102 | } |
| 108603 | 109103 | #endif /* #ifndef SQLITE_OMIT_SUBQUERY */ |
| | @@ -108608,11 +109108,11 @@ |
| 108608 | 109108 | case SRT_Coroutine: { |
| 108609 | 109109 | if( pDest->iSdst==0 ){ |
| 108610 | 109110 | pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst); |
| 108611 | 109111 | pDest->nSdst = pIn->nSdst; |
| 108612 | 109112 | } |
| 108613 | | - sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst); |
| 109113 | + sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst); |
| 108614 | 109114 | sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm); |
| 108615 | 109115 | break; |
| 108616 | 109116 | } |
| 108617 | 109117 | |
| 108618 | 109118 | /* If none of the above, then the result destination must be |
| | @@ -108824,12 +109324,14 @@ |
| 108824 | 109324 | */ |
| 108825 | 109325 | aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy); |
| 108826 | 109326 | if( aPermute ){ |
| 108827 | 109327 | struct ExprList_item *pItem; |
| 108828 | 109328 | for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){ |
| 108829 | | - assert( pItem->u.x.iOrderByCol>0 |
| 108830 | | - && pItem->u.x.iOrderByCol<=p->pEList->nExpr ); |
| 109329 | + assert( pItem->u.x.iOrderByCol>0 ); |
| 109330 | + /* assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ) is also true |
| 109331 | + ** but only for well-formed SELECT statements. */ |
| 109332 | + testcase( pItem->u.x.iOrderByCol > p->pEList->nExpr ); |
| 108831 | 109333 | aPermute[i] = pItem->u.x.iOrderByCol - 1; |
| 108832 | 109334 | } |
| 108833 | 109335 | pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1); |
| 108834 | 109336 | }else{ |
| 108835 | 109337 | pKeyMerge = 0; |
| | @@ -109035,11 +109537,11 @@ |
| 109035 | 109537 | pPrior->pNext = p; |
| 109036 | 109538 | |
| 109037 | 109539 | /*** TBD: Insert subroutine calls to close cursors on incomplete |
| 109038 | 109540 | **** subqueries ****/ |
| 109039 | 109541 | explainComposite(pParse, p->op, iSub1, iSub2, 0); |
| 109040 | | - return SQLITE_OK; |
| 109542 | + return pParse->nErr!=0; |
| 109041 | 109543 | } |
| 109042 | 109544 | #endif |
| 109043 | 109545 | |
| 109044 | 109546 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 109045 | 109547 | /* Forward Declarations */ |
| | @@ -109847,11 +110349,14 @@ |
| 109847 | 110349 | pNew->pGroupBy = 0; |
| 109848 | 110350 | pNew->pHaving = 0; |
| 109849 | 110351 | pNew->pOrderBy = 0; |
| 109850 | 110352 | p->pPrior = 0; |
| 109851 | 110353 | p->pNext = 0; |
| 110354 | + p->pWith = 0; |
| 109852 | 110355 | p->selFlags &= ~SF_Compound; |
| 110356 | + assert( (p->selFlags & SF_Converted)==0 ); |
| 110357 | + p->selFlags |= SF_Converted; |
| 109853 | 110358 | assert( pNew->pPrior!=0 ); |
| 109854 | 110359 | pNew->pPrior->pNext = pNew; |
| 109855 | 110360 | pNew->pLimit = 0; |
| 109856 | 110361 | pNew->pOffset = 0; |
| 109857 | 110362 | return WRC_Continue; |
| | @@ -110383,11 +110888,11 @@ |
| 110383 | 110888 | if( pParse->hasCompound ){ |
| 110384 | 110889 | w.xSelectCallback = convertCompoundSelectToSubquery; |
| 110385 | 110890 | sqlite3WalkSelect(&w, pSelect); |
| 110386 | 110891 | } |
| 110387 | 110892 | w.xSelectCallback = selectExpander; |
| 110388 | | - if( (pSelect->selFlags & SF_AllValues)==0 ){ |
| 110893 | + if( (pSelect->selFlags & SF_MultiValue)==0 ){ |
| 110389 | 110894 | w.xSelectCallback2 = selectPopWith; |
| 110390 | 110895 | } |
| 110391 | 110896 | sqlite3WalkSelect(&w, pSelect); |
| 110392 | 110897 | } |
| 110393 | 110898 | |
| | @@ -110569,11 +111074,12 @@ |
| 110569 | 111074 | nArg = 0; |
| 110570 | 111075 | regAgg = 0; |
| 110571 | 111076 | } |
| 110572 | 111077 | if( pF->iDistinct>=0 ){ |
| 110573 | 111078 | addrNext = sqlite3VdbeMakeLabel(v); |
| 110574 | | - assert( nArg==1 ); |
| 111079 | + testcase( nArg==0 ); /* Error condition */ |
| 111080 | + testcase( nArg>1 ); /* Also an error */ |
| 110575 | 111081 | codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg); |
| 110576 | 111082 | } |
| 110577 | 111083 | if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 110578 | 111084 | CollSeq *pColl = 0; |
| 110579 | 111085 | struct ExprList_item *pItem; |
| | @@ -111444,14 +111950,13 @@ |
| 111444 | 111950 | |
| 111445 | 111951 | /* Jump here to skip this query |
| 111446 | 111952 | */ |
| 111447 | 111953 | sqlite3VdbeResolveLabel(v, iEnd); |
| 111448 | 111954 | |
| 111449 | | - /* The SELECT was successfully coded. Set the return code to 0 |
| 111450 | | - ** to indicate no errors. |
| 111451 | | - */ |
| 111452 | | - rc = 0; |
| 111955 | + /* The SELECT has been coded. If there is an error in the Parse structure, |
| 111956 | + ** set the return code to 1. Otherwise 0. */ |
| 111957 | + rc = (pParse->nErr>0); |
| 111453 | 111958 | |
| 111454 | 111959 | /* Control jumps to here if an error is encountered above, or upon |
| 111455 | 111960 | ** successful coding of the SELECT. |
| 111456 | 111961 | */ |
| 111457 | 111962 | select_end: |
| | @@ -111498,11 +112003,11 @@ |
| 111498 | 112003 | sqlite3TreeViewLine(pView, "FROM"); |
| 111499 | 112004 | for(i=0; i<p->pSrc->nSrc; i++){ |
| 111500 | 112005 | struct SrcList_item *pItem = &p->pSrc->a[i]; |
| 111501 | 112006 | StrAccum x; |
| 111502 | 112007 | char zLine[100]; |
| 111503 | | - sqlite3StrAccumInit(&x, zLine, sizeof(zLine), 0); |
| 112008 | + sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); |
| 111504 | 112009 | sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor); |
| 111505 | 112010 | if( pItem->zDatabase ){ |
| 111506 | 112011 | sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName); |
| 111507 | 112012 | }else if( pItem->zName ){ |
| 111508 | 112013 | sqlite3XPrintf(&x, 0, " %s", pItem->zName); |
| | @@ -111657,11 +112162,11 @@ |
| 111657 | 112162 | for(i=0; i<nCol; i++){ |
| 111658 | 112163 | if( argv[i]==0 ){ |
| 111659 | 112164 | z = 0; |
| 111660 | 112165 | }else{ |
| 111661 | 112166 | int n = sqlite3Strlen30(argv[i])+1; |
| 111662 | | - z = sqlite3_malloc( n ); |
| 112167 | + z = sqlite3_malloc64( n ); |
| 111663 | 112168 | if( z==0 ) goto malloc_failed; |
| 111664 | 112169 | memcpy(z, argv[i], n); |
| 111665 | 112170 | } |
| 111666 | 112171 | p->azResult[p->nData++] = z; |
| 111667 | 112172 | } |
| | @@ -111682,11 +112187,11 @@ |
| 111682 | 112187 | ** The result that is written to ***pazResult is held in memory obtained |
| 111683 | 112188 | ** from malloc(). But the caller cannot free this memory directly. |
| 111684 | 112189 | ** Instead, the entire table should be passed to sqlite3_free_table() when |
| 111685 | 112190 | ** the calling procedure is finished using it. |
| 111686 | 112191 | */ |
| 111687 | | -SQLITE_API int sqlite3_get_table( |
| 112192 | +SQLITE_API int SQLITE_STDCALL sqlite3_get_table( |
| 111688 | 112193 | sqlite3 *db, /* The database on which the SQL executes */ |
| 111689 | 112194 | const char *zSql, /* The SQL to be executed */ |
| 111690 | 112195 | char ***pazResult, /* Write the result table here */ |
| 111691 | 112196 | int *pnRow, /* Write the number of rows in the result here */ |
| 111692 | 112197 | int *pnColumn, /* Write the number of columns of result here */ |
| | @@ -111706,11 +112211,11 @@ |
| 111706 | 112211 | res.nRow = 0; |
| 111707 | 112212 | res.nColumn = 0; |
| 111708 | 112213 | res.nData = 1; |
| 111709 | 112214 | res.nAlloc = 20; |
| 111710 | 112215 | res.rc = SQLITE_OK; |
| 111711 | | - res.azResult = sqlite3_malloc(sizeof(char*)*res.nAlloc ); |
| 112216 | + res.azResult = sqlite3_malloc64(sizeof(char*)*res.nAlloc ); |
| 111712 | 112217 | if( res.azResult==0 ){ |
| 111713 | 112218 | db->errCode = SQLITE_NOMEM; |
| 111714 | 112219 | return SQLITE_NOMEM; |
| 111715 | 112220 | } |
| 111716 | 112221 | res.azResult[0] = 0; |
| | @@ -111734,11 +112239,11 @@ |
| 111734 | 112239 | sqlite3_free_table(&res.azResult[1]); |
| 111735 | 112240 | return rc; |
| 111736 | 112241 | } |
| 111737 | 112242 | if( res.nAlloc>res.nData ){ |
| 111738 | 112243 | char **azNew; |
| 111739 | | - azNew = sqlite3_realloc( res.azResult, sizeof(char*)*res.nData ); |
| 112244 | + azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData ); |
| 111740 | 112245 | if( azNew==0 ){ |
| 111741 | 112246 | sqlite3_free_table(&res.azResult[1]); |
| 111742 | 112247 | db->errCode = SQLITE_NOMEM; |
| 111743 | 112248 | return SQLITE_NOMEM; |
| 111744 | 112249 | } |
| | @@ -111751,11 +112256,11 @@ |
| 111751 | 112256 | } |
| 111752 | 112257 | |
| 111753 | 112258 | /* |
| 111754 | 112259 | ** This routine frees the space the sqlite3_get_table() malloced. |
| 111755 | 112260 | */ |
| 111756 | | -SQLITE_API void sqlite3_free_table( |
| 112261 | +SQLITE_API void SQLITE_STDCALL sqlite3_free_table( |
| 111757 | 112262 | char **azResult /* Result returned from sqlite3_get_table() */ |
| 111758 | 112263 | ){ |
| 111759 | 112264 | if( azResult ){ |
| 111760 | 112265 | int i, n; |
| 111761 | 112266 | azResult--; |
| | @@ -111962,11 +112467,10 @@ |
| 111962 | 112467 | } |
| 111963 | 112468 | |
| 111964 | 112469 | /* Do not create a trigger on a system table */ |
| 111965 | 112470 | if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){ |
| 111966 | 112471 | sqlite3ErrorMsg(pParse, "cannot create trigger on system table"); |
| 111967 | | - pParse->nErr++; |
| 111968 | 112472 | goto trigger_cleanup; |
| 111969 | 112473 | } |
| 111970 | 112474 | |
| 111971 | 112475 | /* INSTEAD of triggers are only for views and views only support INSTEAD |
| 111972 | 112476 | ** of triggers. |
| | @@ -112142,16 +112646,16 @@ |
| 112142 | 112646 | u8 op, /* Trigger opcode */ |
| 112143 | 112647 | Token *pName /* The target name */ |
| 112144 | 112648 | ){ |
| 112145 | 112649 | TriggerStep *pTriggerStep; |
| 112146 | 112650 | |
| 112147 | | - pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n); |
| 112651 | + pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1); |
| 112148 | 112652 | if( pTriggerStep ){ |
| 112149 | 112653 | char *z = (char*)&pTriggerStep[1]; |
| 112150 | 112654 | memcpy(z, pName->z, pName->n); |
| 112151 | | - pTriggerStep->target.z = z; |
| 112152 | | - pTriggerStep->target.n = pName->n; |
| 112655 | + sqlite3Dequote(z); |
| 112656 | + pTriggerStep->zTarget = z; |
| 112153 | 112657 | pTriggerStep->op = op; |
| 112154 | 112658 | } |
| 112155 | 112659 | return pTriggerStep; |
| 112156 | 112660 | } |
| 112157 | 112661 | |
| | @@ -112430,11 +112934,11 @@ |
| 112430 | 112934 | } |
| 112431 | 112935 | return (mask ? pList : 0); |
| 112432 | 112936 | } |
| 112433 | 112937 | |
| 112434 | 112938 | /* |
| 112435 | | -** Convert the pStep->target token into a SrcList and return a pointer |
| 112939 | +** Convert the pStep->zTarget string into a SrcList and return a pointer |
| 112436 | 112940 | ** to that SrcList. |
| 112437 | 112941 | ** |
| 112438 | 112942 | ** This routine adds a specific database name, if needed, to the target when |
| 112439 | 112943 | ** forming the SrcList. This prevents a trigger in one database from |
| 112440 | 112944 | ** referring to a target in another database. An exception is when the |
| | @@ -112443,21 +112947,21 @@ |
| 112443 | 112947 | */ |
| 112444 | 112948 | static SrcList *targetSrcList( |
| 112445 | 112949 | Parse *pParse, /* The parsing context */ |
| 112446 | 112950 | TriggerStep *pStep /* The trigger containing the target token */ |
| 112447 | 112951 | ){ |
| 112952 | + sqlite3 *db = pParse->db; |
| 112448 | 112953 | int iDb; /* Index of the database to use */ |
| 112449 | 112954 | SrcList *pSrc; /* SrcList to be returned */ |
| 112450 | 112955 | |
| 112451 | | - pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0); |
| 112956 | + pSrc = sqlite3SrcListAppend(db, 0, 0, 0); |
| 112452 | 112957 | if( pSrc ){ |
| 112453 | 112958 | assert( pSrc->nSrc>0 ); |
| 112454 | | - assert( pSrc->a!=0 ); |
| 112455 | | - iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema); |
| 112959 | + pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget); |
| 112960 | + iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema); |
| 112456 | 112961 | if( iDb==0 || iDb>=2 ){ |
| 112457 | | - sqlite3 *db = pParse->db; |
| 112458 | | - assert( iDb<pParse->db->nDb ); |
| 112962 | + assert( iDb<db->nDb ); |
| 112459 | 112963 | pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName); |
| 112460 | 112964 | } |
| 112461 | 112965 | } |
| 112462 | 112966 | return pSrc; |
| 112463 | 112967 | } |
| | @@ -112565,10 +113069,11 @@ |
| 112565 | 113069 | assert( pFrom->zErrMsg==0 || pFrom->nErr ); |
| 112566 | 113070 | assert( pTo->zErrMsg==0 || pTo->nErr ); |
| 112567 | 113071 | if( pTo->nErr==0 ){ |
| 112568 | 113072 | pTo->zErrMsg = pFrom->zErrMsg; |
| 112569 | 113073 | pTo->nErr = pFrom->nErr; |
| 113074 | + pTo->rc = pFrom->rc; |
| 112570 | 113075 | }else{ |
| 112571 | 113076 | sqlite3DbFree(pFrom->db, pFrom->zErrMsg); |
| 112572 | 113077 | } |
| 112573 | 113078 | } |
| 112574 | 113079 | |
| | @@ -113915,17 +114420,21 @@ |
| 113915 | 114420 | |
| 113916 | 114421 | /* Loop through the tables in the main database. For each, do |
| 113917 | 114422 | ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy |
| 113918 | 114423 | ** the contents to the temporary database. |
| 113919 | 114424 | */ |
| 114425 | + assert( (db->flags & SQLITE_Vacuum)==0 ); |
| 114426 | + db->flags |= SQLITE_Vacuum; |
| 113920 | 114427 | rc = execExecSql(db, pzErrMsg, |
| 113921 | 114428 | "SELECT 'INSERT INTO vacuum_db.' || quote(name) " |
| 113922 | 114429 | "|| ' SELECT * FROM main.' || quote(name) || ';'" |
| 113923 | 114430 | "FROM main.sqlite_master " |
| 113924 | 114431 | "WHERE type = 'table' AND name!='sqlite_sequence' " |
| 113925 | 114432 | " AND coalesce(rootpage,1)>0" |
| 113926 | 114433 | ); |
| 114434 | + assert( (db->flags & SQLITE_Vacuum)!=0 ); |
| 114435 | + db->flags &= ~SQLITE_Vacuum; |
| 113927 | 114436 | if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 113928 | 114437 | |
| 113929 | 114438 | /* Copy over the sequence table |
| 113930 | 114439 | */ |
| 113931 | 114440 | rc = execExecSql(db, pzErrMsg, |
| | @@ -114060,10 +114569,12 @@ |
| 114060 | 114569 | ** are invoked only from within xCreate and xConnect methods. |
| 114061 | 114570 | */ |
| 114062 | 114571 | struct VtabCtx { |
| 114063 | 114572 | VTable *pVTable; /* The virtual table being constructed */ |
| 114064 | 114573 | Table *pTab; /* The Table object to which the virtual table belongs */ |
| 114574 | + VtabCtx *pPrior; /* Parent context (if any) */ |
| 114575 | + int bDeclared; /* True after sqlite3_declare_vtab() is called */ |
| 114065 | 114576 | }; |
| 114066 | 114577 | |
| 114067 | 114578 | /* |
| 114068 | 114579 | ** The actual function that does the work of creating a new module. |
| 114069 | 114580 | ** This function implements the sqlite3_create_module() and |
| | @@ -114111,11 +114622,11 @@ |
| 114111 | 114622 | |
| 114112 | 114623 | |
| 114113 | 114624 | /* |
| 114114 | 114625 | ** External API function used to create a new virtual-table module. |
| 114115 | 114626 | */ |
| 114116 | | -SQLITE_API int sqlite3_create_module( |
| 114627 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_module( |
| 114117 | 114628 | sqlite3 *db, /* Database in which module is registered */ |
| 114118 | 114629 | const char *zName, /* Name assigned to this module */ |
| 114119 | 114630 | const sqlite3_module *pModule, /* The definition of the module */ |
| 114120 | 114631 | void *pAux /* Context pointer for xCreate/xConnect */ |
| 114121 | 114632 | ){ |
| | @@ -114126,11 +114637,11 @@ |
| 114126 | 114637 | } |
| 114127 | 114638 | |
| 114128 | 114639 | /* |
| 114129 | 114640 | ** External API function used to create a new virtual-table module. |
| 114130 | 114641 | */ |
| 114131 | | -SQLITE_API int sqlite3_create_module_v2( |
| 114642 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_module_v2( |
| 114132 | 114643 | sqlite3 *db, /* Database in which module is registered */ |
| 114133 | 114644 | const char *zName, /* Name assigned to this module */ |
| 114134 | 114645 | const sqlite3_module *pModule, /* The definition of the module */ |
| 114135 | 114646 | void *pAux, /* Context pointer for xCreate/xConnect */ |
| 114136 | 114647 | void (*xDestroy)(void *) /* Module destructor function */ |
| | @@ -114506,11 +115017,11 @@ |
| 114506 | 115017 | Token *pArg = &pParse->sArg; |
| 114507 | 115018 | if( pArg->z==0 ){ |
| 114508 | 115019 | pArg->z = p->z; |
| 114509 | 115020 | pArg->n = p->n; |
| 114510 | 115021 | }else{ |
| 114511 | | - assert(pArg->z < p->z); |
| 115022 | + assert(pArg->z <= p->z); |
| 114512 | 115023 | pArg->n = (int)(&p->z[p->n] - pArg->z); |
| 114513 | 115024 | } |
| 114514 | 115025 | } |
| 114515 | 115026 | |
| 114516 | 115027 | /* |
| | @@ -114523,19 +115034,31 @@ |
| 114523 | 115034 | Table *pTab, |
| 114524 | 115035 | Module *pMod, |
| 114525 | 115036 | int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**), |
| 114526 | 115037 | char **pzErr |
| 114527 | 115038 | ){ |
| 114528 | | - VtabCtx sCtx, *pPriorCtx; |
| 115039 | + VtabCtx sCtx; |
| 114529 | 115040 | VTable *pVTable; |
| 114530 | 115041 | int rc; |
| 114531 | 115042 | const char *const*azArg = (const char *const*)pTab->azModuleArg; |
| 114532 | 115043 | int nArg = pTab->nModuleArg; |
| 114533 | 115044 | char *zErr = 0; |
| 114534 | | - char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); |
| 115045 | + char *zModuleName; |
| 114535 | 115046 | int iDb; |
| 115047 | + VtabCtx *pCtx; |
| 114536 | 115048 | |
| 115049 | + /* Check that the virtual-table is not already being initialized */ |
| 115050 | + for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){ |
| 115051 | + if( pCtx->pTab==pTab ){ |
| 115052 | + *pzErr = sqlite3MPrintf(db, |
| 115053 | + "vtable constructor called recursively: %s", pTab->zName |
| 115054 | + ); |
| 115055 | + return SQLITE_LOCKED; |
| 115056 | + } |
| 115057 | + } |
| 115058 | + |
| 115059 | + zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); |
| 114537 | 115060 | if( !zModuleName ){ |
| 114538 | 115061 | return SQLITE_NOMEM; |
| 114539 | 115062 | } |
| 114540 | 115063 | |
| 114541 | 115064 | pVTable = sqlite3DbMallocZero(db, sizeof(VTable)); |
| | @@ -114552,15 +115075,17 @@ |
| 114552 | 115075 | /* Invoke the virtual table constructor */ |
| 114553 | 115076 | assert( &db->pVtabCtx ); |
| 114554 | 115077 | assert( xConstruct ); |
| 114555 | 115078 | sCtx.pTab = pTab; |
| 114556 | 115079 | sCtx.pVTable = pVTable; |
| 114557 | | - pPriorCtx = db->pVtabCtx; |
| 115080 | + sCtx.pPrior = db->pVtabCtx; |
| 115081 | + sCtx.bDeclared = 0; |
| 114558 | 115082 | db->pVtabCtx = &sCtx; |
| 114559 | 115083 | rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); |
| 114560 | | - db->pVtabCtx = pPriorCtx; |
| 115084 | + db->pVtabCtx = sCtx.pPrior; |
| 114561 | 115085 | if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; |
| 115086 | + assert( sCtx.pTab==pTab ); |
| 114562 | 115087 | |
| 114563 | 115088 | if( SQLITE_OK!=rc ){ |
| 114564 | 115089 | if( zErr==0 ){ |
| 114565 | 115090 | *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); |
| 114566 | 115091 | }else { |
| | @@ -114572,17 +115097,18 @@ |
| 114572 | 115097 | /* Justification of ALWAYS(): A correct vtab constructor must allocate |
| 114573 | 115098 | ** the sqlite3_vtab object if successful. */ |
| 114574 | 115099 | memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0])); |
| 114575 | 115100 | pVTable->pVtab->pModule = pMod->pModule; |
| 114576 | 115101 | pVTable->nRef = 1; |
| 114577 | | - if( sCtx.pTab ){ |
| 115102 | + if( sCtx.bDeclared==0 ){ |
| 114578 | 115103 | const char *zFormat = "vtable constructor did not declare schema: %s"; |
| 114579 | 115104 | *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName); |
| 114580 | 115105 | sqlite3VtabUnlock(pVTable); |
| 114581 | 115106 | rc = SQLITE_ERROR; |
| 114582 | 115107 | }else{ |
| 114583 | 115108 | int iCol; |
| 115109 | + u8 oooHidden = 0; |
| 114584 | 115110 | /* If everything went according to plan, link the new VTable structure |
| 114585 | 115111 | ** into the linked list headed by pTab->pVTable. Then loop through the |
| 114586 | 115112 | ** columns of the table to see if any of them contain the token "hidden". |
| 114587 | 115113 | ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from |
| 114588 | 115114 | ** the type string. */ |
| | @@ -114591,11 +115117,14 @@ |
| 114591 | 115117 | |
| 114592 | 115118 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 114593 | 115119 | char *zType = pTab->aCol[iCol].zType; |
| 114594 | 115120 | int nType; |
| 114595 | 115121 | int i = 0; |
| 114596 | | - if( !zType ) continue; |
| 115122 | + if( !zType ){ |
| 115123 | + pTab->tabFlags |= oooHidden; |
| 115124 | + continue; |
| 115125 | + } |
| 114597 | 115126 | nType = sqlite3Strlen30(zType); |
| 114598 | 115127 | if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){ |
| 114599 | 115128 | for(i=0; i<nType; i++){ |
| 114600 | 115129 | if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7)) |
| 114601 | 115130 | && (zType[i+7]=='\0' || zType[i+7]==' ') |
| | @@ -114614,10 +115143,13 @@ |
| 114614 | 115143 | if( zType[i]=='\0' && i>0 ){ |
| 114615 | 115144 | assert(zType[i-1]==' '); |
| 114616 | 115145 | zType[i-1] = '\0'; |
| 114617 | 115146 | } |
| 114618 | 115147 | pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN; |
| 115148 | + oooHidden = TF_OOOHidden; |
| 115149 | + }else{ |
| 115150 | + pTab->tabFlags |= oooHidden; |
| 114619 | 115151 | } |
| 114620 | 115152 | } |
| 114621 | 115153 | } |
| 114622 | 115154 | } |
| 114623 | 115155 | |
| | @@ -114741,13 +115273,13 @@ |
| 114741 | 115273 | /* |
| 114742 | 115274 | ** This function is used to set the schema of a virtual table. It is only |
| 114743 | 115275 | ** valid to call this function from within the xCreate() or xConnect() of a |
| 114744 | 115276 | ** virtual table module. |
| 114745 | 115277 | */ |
| 114746 | | -SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ |
| 115278 | +SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ |
| 115279 | + VtabCtx *pCtx; |
| 114747 | 115280 | Parse *pParse; |
| 114748 | | - |
| 114749 | 115281 | int rc = SQLITE_OK; |
| 114750 | 115282 | Table *pTab; |
| 114751 | 115283 | char *zErr = 0; |
| 114752 | 115284 | |
| 114753 | 115285 | #ifdef SQLITE_ENABLE_API_ARMOR |
| | @@ -114754,15 +115286,17 @@ |
| 114754 | 115286 | if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){ |
| 114755 | 115287 | return SQLITE_MISUSE_BKPT; |
| 114756 | 115288 | } |
| 114757 | 115289 | #endif |
| 114758 | 115290 | sqlite3_mutex_enter(db->mutex); |
| 114759 | | - if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){ |
| 115291 | + pCtx = db->pVtabCtx; |
| 115292 | + if( !pCtx || pCtx->bDeclared ){ |
| 114760 | 115293 | sqlite3Error(db, SQLITE_MISUSE); |
| 114761 | 115294 | sqlite3_mutex_leave(db->mutex); |
| 114762 | 115295 | return SQLITE_MISUSE_BKPT; |
| 114763 | 115296 | } |
| 115297 | + pTab = pCtx->pTab; |
| 114764 | 115298 | assert( (pTab->tabFlags & TF_Virtual)!=0 ); |
| 114765 | 115299 | |
| 114766 | 115300 | pParse = sqlite3StackAllocZero(db, sizeof(*pParse)); |
| 114767 | 115301 | if( pParse==0 ){ |
| 114768 | 115302 | rc = SQLITE_NOMEM; |
| | @@ -114781,11 +115315,11 @@ |
| 114781 | 115315 | pTab->aCol = pParse->pNewTable->aCol; |
| 114782 | 115316 | pTab->nCol = pParse->pNewTable->nCol; |
| 114783 | 115317 | pParse->pNewTable->nCol = 0; |
| 114784 | 115318 | pParse->pNewTable->aCol = 0; |
| 114785 | 115319 | } |
| 114786 | | - db->pVtabCtx->pTab = 0; |
| 115320 | + pCtx->bDeclared = 1; |
| 114787 | 115321 | }else{ |
| 114788 | 115322 | sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr); |
| 114789 | 115323 | sqlite3DbFree(db, zErr); |
| 114790 | 115324 | rc = SQLITE_ERROR; |
| 114791 | 115325 | } |
| | @@ -114975,11 +115509,11 @@ |
| 114975 | 115509 | */ |
| 114976 | 115510 | SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){ |
| 114977 | 115511 | int rc = SQLITE_OK; |
| 114978 | 115512 | |
| 114979 | 115513 | assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN ); |
| 114980 | | - assert( iSavepoint>=0 ); |
| 115514 | + assert( iSavepoint>=-1 ); |
| 114981 | 115515 | if( db->aVTrans ){ |
| 114982 | 115516 | int i; |
| 114983 | 115517 | for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){ |
| 114984 | 115518 | VTable *pVTab = db->aVTrans[i]; |
| 114985 | 115519 | const sqlite3_module *pMod = pVTab->pMod->pModule; |
| | @@ -115093,11 +115627,11 @@ |
| 115093 | 115627 | assert( IsVirtual(pTab) ); |
| 115094 | 115628 | for(i=0; i<pToplevel->nVtabLock; i++){ |
| 115095 | 115629 | if( pTab==pToplevel->apVtabLock[i] ) return; |
| 115096 | 115630 | } |
| 115097 | 115631 | n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]); |
| 115098 | | - apVtabLock = sqlite3_realloc(pToplevel->apVtabLock, n); |
| 115632 | + apVtabLock = sqlite3_realloc64(pToplevel->apVtabLock, n); |
| 115099 | 115633 | if( apVtabLock ){ |
| 115100 | 115634 | pToplevel->apVtabLock = apVtabLock; |
| 115101 | 115635 | pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab; |
| 115102 | 115636 | }else{ |
| 115103 | 115637 | pToplevel->db->mallocFailed = 1; |
| | @@ -115109,11 +115643,11 @@ |
| 115109 | 115643 | ** table update operation currently in progress. |
| 115110 | 115644 | ** |
| 115111 | 115645 | ** The results of this routine are undefined unless it is called from |
| 115112 | 115646 | ** within an xUpdate method. |
| 115113 | 115647 | */ |
| 115114 | | -SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){ |
| 115648 | +SQLITE_API int SQLITE_STDCALL sqlite3_vtab_on_conflict(sqlite3 *db){ |
| 115115 | 115649 | static const unsigned char aMap[] = { |
| 115116 | 115650 | SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE |
| 115117 | 115651 | }; |
| 115118 | 115652 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 115119 | 115653 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| | @@ -115127,11 +115661,11 @@ |
| 115127 | 115661 | /* |
| 115128 | 115662 | ** Call from within the xCreate() or xConnect() methods to provide |
| 115129 | 115663 | ** the SQLite core with additional information about the behavior |
| 115130 | 115664 | ** of the virtual table being implemented. |
| 115131 | 115665 | */ |
| 115132 | | -SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){ |
| 115666 | +SQLITE_API int SQLITE_CDECL sqlite3_vtab_config(sqlite3 *db, int op, ...){ |
| 115133 | 115667 | va_list ap; |
| 115134 | 115668 | int rc = SQLITE_OK; |
| 115135 | 115669 | |
| 115136 | 115670 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 115137 | 115671 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| | @@ -115892,17 +116426,18 @@ |
| 115892 | 116426 | ** In the previous sentence and in the diagram, "slot[]" refers to |
| 115893 | 116427 | ** the WhereClause.a[] array. The slot[] array grows as needed to contain |
| 115894 | 116428 | ** all terms of the WHERE clause. |
| 115895 | 116429 | */ |
| 115896 | 116430 | static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){ |
| 116431 | + Expr *pE2 = sqlite3ExprSkipCollate(pExpr); |
| 115897 | 116432 | pWC->op = op; |
| 115898 | | - if( pExpr==0 ) return; |
| 115899 | | - if( pExpr->op!=op ){ |
| 116433 | + if( pE2==0 ) return; |
| 116434 | + if( pE2->op!=op ){ |
| 115900 | 116435 | whereClauseInsert(pWC, pExpr, 0); |
| 115901 | 116436 | }else{ |
| 115902 | | - whereSplit(pWC, pExpr->pLeft, op); |
| 115903 | | - whereSplit(pWC, pExpr->pRight, op); |
| 116437 | + whereSplit(pWC, pE2->pLeft, op); |
| 116438 | + whereSplit(pWC, pE2->pRight, op); |
| 115904 | 116439 | } |
| 115905 | 116440 | } |
| 115906 | 116441 | |
| 115907 | 116442 | /* |
| 115908 | 116443 | ** Initialize a WhereMaskSet object |
| | @@ -117169,11 +117704,11 @@ |
| 117169 | 117704 | if( p->op==TK_COLUMN |
| 117170 | 117705 | && p->iColumn==pIdx->aiColumn[iCol] |
| 117171 | 117706 | && p->iTable==iBase |
| 117172 | 117707 | ){ |
| 117173 | 117708 | CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr); |
| 117174 | | - if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){ |
| 117709 | + if( pColl && 0==sqlite3StrICmp(pColl->zName, zColl) ){ |
| 117175 | 117710 | return i; |
| 117176 | 117711 | } |
| 117177 | 117712 | } |
| 117178 | 117713 | } |
| 117179 | 117714 | |
| | @@ -117443,11 +117978,11 @@ |
| 117443 | 117978 | if( (idxCols & cMask)==0 ){ |
| 117444 | 117979 | Expr *pX = pTerm->pExpr; |
| 117445 | 117980 | idxCols |= cMask; |
| 117446 | 117981 | pIdx->aiColumn[n] = pTerm->u.leftColumn; |
| 117447 | 117982 | pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); |
| 117448 | | - pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : "BINARY"; |
| 117983 | + pIdx->azColl[n] = pColl ? pColl->zName : "BINARY"; |
| 117449 | 117984 | n++; |
| 117450 | 117985 | } |
| 117451 | 117986 | } |
| 117452 | 117987 | } |
| 117453 | 117988 | assert( (u32)n==pLoop->u.btree.nEq ); |
| | @@ -118739,12 +119274,11 @@ |
| 118739 | 119274 | |
| 118740 | 119275 | isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 |
| 118741 | 119276 | || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0)) |
| 118742 | 119277 | || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX)); |
| 118743 | 119278 | |
| 118744 | | - sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH); |
| 118745 | | - str.db = db; |
| 119279 | + sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH); |
| 118746 | 119280 | sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN"); |
| 118747 | 119281 | if( pItem->pSelect ){ |
| 118748 | 119282 | sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId); |
| 118749 | 119283 | }else{ |
| 118750 | 119284 | sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName); |
| | @@ -119939,10 +120473,17 @@ |
| 119939 | 120473 | /* |
| 119940 | 120474 | ** Free a WhereInfo structure |
| 119941 | 120475 | */ |
| 119942 | 120476 | static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){ |
| 119943 | 120477 | if( ALWAYS(pWInfo) ){ |
| 120478 | + int i; |
| 120479 | + for(i=0; i<pWInfo->nLevel; i++){ |
| 120480 | + WhereLevel *pLevel = &pWInfo->a[i]; |
| 120481 | + if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){ |
| 120482 | + sqlite3DbFree(db, pLevel->u.in.aInLoop); |
| 120483 | + } |
| 120484 | + } |
| 119944 | 120485 | whereClauseClear(&pWInfo->sWC); |
| 119945 | 120486 | while( pWInfo->pLoops ){ |
| 119946 | 120487 | WhereLoop *p = pWInfo->pLoops; |
| 119947 | 120488 | pWInfo->pLoops = p->pNextLoop; |
| 119948 | 120489 | whereLoopDelete(db, p); |
| | @@ -120418,11 +120959,11 @@ |
| 120418 | 120959 | ** changes "x IN (?)" into "x=?". */ |
| 120419 | 120960 | |
| 120420 | 120961 | }else if( eOp & (WO_EQ) ){ |
| 120421 | 120962 | pNew->wsFlags |= WHERE_COLUMN_EQ; |
| 120422 | 120963 | if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){ |
| 120423 | | - if( iCol>=0 && !IsUniqueIndex(pProbe) ){ |
| 120964 | + if( iCol>=0 && pProbe->uniqNotNull==0 ){ |
| 120424 | 120965 | pNew->wsFlags |= WHERE_UNQ_WANTED; |
| 120425 | 120966 | }else{ |
| 120426 | 120967 | pNew->wsFlags |= WHERE_ONEROW; |
| 120427 | 120968 | } |
| 120428 | 120969 | } |
| | @@ -121878,11 +122419,11 @@ |
| 121878 | 122419 | pWInfo->nOBSat = pFrom->isOrdered; |
| 121879 | 122420 | if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0; |
| 121880 | 122421 | pWInfo->revMask = pFrom->revLoop; |
| 121881 | 122422 | } |
| 121882 | 122423 | if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP) |
| 121883 | | - && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr |
| 122424 | + && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0 |
| 121884 | 122425 | ){ |
| 121885 | 122426 | Bitmask revMask = 0; |
| 121886 | 122427 | int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy, |
| 121887 | 122428 | pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask |
| 121888 | 122429 | ); |
| | @@ -122283,11 +122824,10 @@ |
| 122283 | 122824 | if( pParse->nErr || NEVER(db->mallocFailed) ){ |
| 122284 | 122825 | goto whereBeginError; |
| 122285 | 122826 | } |
| 122286 | 122827 | #ifdef WHERETRACE_ENABLED /* !=0 */ |
| 122287 | 122828 | if( sqlite3WhereTrace ){ |
| 122288 | | - int ii; |
| 122289 | 122829 | sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut); |
| 122290 | 122830 | if( pWInfo->nOBSat>0 ){ |
| 122291 | 122831 | sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask); |
| 122292 | 122832 | } |
| 122293 | 122833 | switch( pWInfo->eDistinct ){ |
| | @@ -122536,11 +123076,10 @@ |
| 122536 | 123076 | VdbeCoverage(v); |
| 122537 | 123077 | VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen); |
| 122538 | 123078 | VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen); |
| 122539 | 123079 | sqlite3VdbeJumpHere(v, pIn->addrInTop-1); |
| 122540 | 123080 | } |
| 122541 | | - sqlite3DbFree(db, pLevel->u.in.aInLoop); |
| 122542 | 123081 | } |
| 122543 | 123082 | sqlite3VdbeResolveLabel(v, pLevel->addrBrk); |
| 122544 | 123083 | if( pLevel->addrSkip ){ |
| 122545 | 123084 | sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip); |
| 122546 | 123085 | VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName)); |
| | @@ -122747,10 +123286,32 @@ |
| 122747 | 123286 | /* |
| 122748 | 123287 | ** An instance of this structure holds the ATTACH key and the key type. |
| 122749 | 123288 | */ |
| 122750 | 123289 | struct AttachKey { int type; Token key; }; |
| 122751 | 123290 | |
| 123291 | + |
| 123292 | + /* |
| 123293 | + ** For a compound SELECT statement, make sure p->pPrior->pNext==p for |
| 123294 | + ** all elements in the list. And make sure list length does not exceed |
| 123295 | + ** SQLITE_LIMIT_COMPOUND_SELECT. |
| 123296 | + */ |
| 123297 | + static void parserDoubleLinkSelect(Parse *pParse, Select *p){ |
| 123298 | + if( p->pPrior ){ |
| 123299 | + Select *pNext = 0, *pLoop; |
| 123300 | + int mxSelect, cnt = 0; |
| 123301 | + for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){ |
| 123302 | + pLoop->pNext = pNext; |
| 123303 | + pLoop->selFlags |= SF_Compound; |
| 123304 | + } |
| 123305 | + if( (p->selFlags & SF_MultiValue)==0 && |
| 123306 | + (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 && |
| 123307 | + cnt>mxSelect |
| 123308 | + ){ |
| 123309 | + sqlite3ErrorMsg(pParse, "too many terms in compound SELECT"); |
| 123310 | + } |
| 123311 | + } |
| 123312 | + } |
| 122752 | 123313 | |
| 122753 | 123314 | /* This is a utility routine used to set the ExprSpan.zStart and |
| 122754 | 123315 | ** ExprSpan.zEnd values of pOut so that the span covers the complete |
| 122755 | 123316 | ** range of text beginning with pStart and going to the end of pEnd. |
| 122756 | 123317 | */ |
| | @@ -125064,31 +125625,14 @@ |
| 125064 | 125625 | sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3); |
| 125065 | 125626 | } |
| 125066 | 125627 | break; |
| 125067 | 125628 | case 112: /* select ::= with selectnowith */ |
| 125068 | 125629 | { |
| 125069 | | - Select *p = yymsp[0].minor.yy3, *pNext, *pLoop; |
| 125630 | + Select *p = yymsp[0].minor.yy3; |
| 125070 | 125631 | if( p ){ |
| 125071 | | - int cnt = 0, mxSelect; |
| 125072 | 125632 | p->pWith = yymsp[-1].minor.yy59; |
| 125073 | | - if( p->pPrior ){ |
| 125074 | | - u16 allValues = SF_Values; |
| 125075 | | - pNext = 0; |
| 125076 | | - for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){ |
| 125077 | | - pLoop->pNext = pNext; |
| 125078 | | - pLoop->selFlags |= SF_Compound; |
| 125079 | | - allValues &= pLoop->selFlags; |
| 125080 | | - } |
| 125081 | | - if( allValues ){ |
| 125082 | | - p->selFlags |= SF_AllValues; |
| 125083 | | - }else if( |
| 125084 | | - (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 |
| 125085 | | - && cnt>mxSelect |
| 125086 | | - ){ |
| 125087 | | - sqlite3ErrorMsg(pParse, "too many terms in compound SELECT"); |
| 125088 | | - } |
| 125089 | | - } |
| 125633 | + parserDoubleLinkSelect(pParse, p); |
| 125090 | 125634 | }else{ |
| 125091 | 125635 | sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59); |
| 125092 | 125636 | } |
| 125093 | 125637 | yygotominor.yy3 = p; |
| 125094 | 125638 | } |
| | @@ -125102,16 +125646,18 @@ |
| 125102 | 125646 | Select *pRhs = yymsp[0].minor.yy3; |
| 125103 | 125647 | if( pRhs && pRhs->pPrior ){ |
| 125104 | 125648 | SrcList *pFrom; |
| 125105 | 125649 | Token x; |
| 125106 | 125650 | x.n = 0; |
| 125651 | + parserDoubleLinkSelect(pParse, pRhs); |
| 125107 | 125652 | pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0); |
| 125108 | 125653 | pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0); |
| 125109 | 125654 | } |
| 125110 | 125655 | if( pRhs ){ |
| 125111 | 125656 | pRhs->op = (u8)yymsp[-1].minor.yy328; |
| 125112 | 125657 | pRhs->pPrior = yymsp[-2].minor.yy3; |
| 125658 | + pRhs->selFlags &= ~SF_MultiValue; |
| 125113 | 125659 | if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1; |
| 125114 | 125660 | }else{ |
| 125115 | 125661 | sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3); |
| 125116 | 125662 | } |
| 125117 | 125663 | yygotominor.yy3 = pRhs; |
| | @@ -125154,17 +125700,20 @@ |
| 125154 | 125700 | yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0); |
| 125155 | 125701 | } |
| 125156 | 125702 | break; |
| 125157 | 125703 | case 121: /* values ::= values COMMA LP exprlist RP */ |
| 125158 | 125704 | { |
| 125159 | | - Select *pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0); |
| 125705 | + Select *pRight, *pLeft = yymsp[-4].minor.yy3; |
| 125706 | + pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values|SF_MultiValue,0,0); |
| 125707 | + if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue; |
| 125160 | 125708 | if( pRight ){ |
| 125161 | 125709 | pRight->op = TK_ALL; |
| 125162 | | - pRight->pPrior = yymsp[-4].minor.yy3; |
| 125710 | + pLeft = yymsp[-4].minor.yy3; |
| 125711 | + pRight->pPrior = pLeft; |
| 125163 | 125712 | yygotominor.yy3 = pRight; |
| 125164 | 125713 | }else{ |
| 125165 | | - yygotominor.yy3 = yymsp[-4].minor.yy3; |
| 125714 | + yygotominor.yy3 = pLeft; |
| 125166 | 125715 | } |
| 125167 | 125716 | } |
| 125168 | 125717 | break; |
| 125169 | 125718 | case 122: /* distinct ::= DISTINCT */ |
| 125170 | 125719 | {yygotominor.yy381 = SF_Distinct;} |
| | @@ -126964,14 +127513,12 @@ |
| 126964 | 127513 | goto abort_parse; |
| 126965 | 127514 | } |
| 126966 | 127515 | break; |
| 126967 | 127516 | } |
| 126968 | 127517 | case TK_ILLEGAL: { |
| 126969 | | - sqlite3DbFree(db, *pzErrMsg); |
| 126970 | | - *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"", |
| 127518 | + sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"", |
| 126971 | 127519 | &pParse->sLastToken); |
| 126972 | | - nErr++; |
| 126973 | 127520 | goto abort_parse; |
| 126974 | 127521 | } |
| 126975 | 127522 | case TK_SEMI: { |
| 126976 | 127523 | pParse->zTail = &zSql[i]; |
| 126977 | 127524 | /* Fall thru into the default case */ |
| | @@ -126985,16 +127532,19 @@ |
| 126985 | 127532 | break; |
| 126986 | 127533 | } |
| 126987 | 127534 | } |
| 126988 | 127535 | } |
| 126989 | 127536 | abort_parse: |
| 126990 | | - if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){ |
| 127537 | + assert( nErr==0 ); |
| 127538 | + if( zSql[i]==0 && pParse->rc==SQLITE_OK && db->mallocFailed==0 ){ |
| 126991 | 127539 | if( lastTokenParsed!=TK_SEMI ){ |
| 126992 | 127540 | sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse); |
| 126993 | 127541 | pParse->zTail = &zSql[i]; |
| 126994 | 127542 | } |
| 126995 | | - sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse); |
| 127543 | + if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){ |
| 127544 | + sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse); |
| 127545 | + } |
| 126996 | 127546 | } |
| 126997 | 127547 | #ifdef YYTRACKMAXSTACKDEPTH |
| 126998 | 127548 | sqlite3_mutex_enter(sqlite3MallocMutex()); |
| 126999 | 127549 | sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK, |
| 127000 | 127550 | sqlite3ParserStackPeak(pEngine) |
| | @@ -127051,13 +127601,11 @@ |
| 127051 | 127601 | while( pParse->pZombieTab ){ |
| 127052 | 127602 | Table *p = pParse->pZombieTab; |
| 127053 | 127603 | pParse->pZombieTab = p->pNextZombie; |
| 127054 | 127604 | sqlite3DeleteTable(db, p); |
| 127055 | 127605 | } |
| 127056 | | - if( nErr>0 && pParse->rc==SQLITE_OK ){ |
| 127057 | | - pParse->rc = SQLITE_ERROR; |
| 127058 | | - } |
| 127606 | + assert( nErr==0 || pParse->rc!=SQLITE_OK ); |
| 127059 | 127607 | return nErr; |
| 127060 | 127608 | } |
| 127061 | 127609 | |
| 127062 | 127610 | /************** End of tokenize.c ********************************************/ |
| 127063 | 127611 | /************** Begin file complete.c ****************************************/ |
| | @@ -127161,11 +127709,11 @@ |
| 127161 | 127709 | ** |
| 127162 | 127710 | ** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed |
| 127163 | 127711 | ** to recognize the end of a trigger can be omitted. All we have to do |
| 127164 | 127712 | ** is look for a semicolon that is not part of an string or comment. |
| 127165 | 127713 | */ |
| 127166 | | -SQLITE_API int sqlite3_complete(const char *zSql){ |
| 127714 | +SQLITE_API int SQLITE_STDCALL sqlite3_complete(const char *zSql){ |
| 127167 | 127715 | u8 state = 0; /* Current state, using numbers defined in header comment */ |
| 127168 | 127716 | u8 token; /* Value of the next token */ |
| 127169 | 127717 | |
| 127170 | 127718 | #ifndef SQLITE_OMIT_TRIGGER |
| 127171 | 127719 | /* A complex statement machine used to detect the end of a CREATE TRIGGER |
| | @@ -127326,14 +127874,14 @@ |
| 127326 | 127874 | /* |
| 127327 | 127875 | ** This routine is the same as the sqlite3_complete() routine described |
| 127328 | 127876 | ** above, except that the parameter is required to be UTF-16 encoded, not |
| 127329 | 127877 | ** UTF-8. |
| 127330 | 127878 | */ |
| 127331 | | -SQLITE_API int sqlite3_complete16(const void *zSql){ |
| 127879 | +SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){ |
| 127332 | 127880 | sqlite3_value *pVal; |
| 127333 | 127881 | char const *zSql8; |
| 127334 | | - int rc = SQLITE_NOMEM; |
| 127882 | + int rc; |
| 127335 | 127883 | |
| 127336 | 127884 | #ifndef SQLITE_OMIT_AUTOINIT |
| 127337 | 127885 | rc = sqlite3_initialize(); |
| 127338 | 127886 | if( rc ) return rc; |
| 127339 | 127887 | #endif |
| | @@ -127476,37 +128024,49 @@ |
| 127476 | 128024 | #endif |
| 127477 | 128025 | |
| 127478 | 128026 | /* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns |
| 127479 | 128027 | ** a pointer to the to the sqlite3_version[] string constant. |
| 127480 | 128028 | */ |
| 127481 | | -SQLITE_API const char *sqlite3_libversion(void){ return sqlite3_version; } |
| 128029 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_libversion(void){ return sqlite3_version; } |
| 127482 | 128030 | |
| 127483 | 128031 | /* IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a |
| 127484 | 128032 | ** pointer to a string constant whose value is the same as the |
| 127485 | 128033 | ** SQLITE_SOURCE_ID C preprocessor macro. |
| 127486 | 128034 | */ |
| 127487 | | -SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 128035 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 127488 | 128036 | |
| 127489 | 128037 | /* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function |
| 127490 | 128038 | ** returns an integer equal to SQLITE_VERSION_NUMBER. |
| 127491 | 128039 | */ |
| 127492 | | -SQLITE_API int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; } |
| 128040 | +SQLITE_API int SQLITE_STDCALL sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; } |
| 127493 | 128041 | |
| 127494 | 128042 | /* IMPLEMENTATION-OF: R-20790-14025 The sqlite3_threadsafe() function returns |
| 127495 | 128043 | ** zero if and only if SQLite was compiled with mutexing code omitted due to |
| 127496 | 128044 | ** the SQLITE_THREADSAFE compile-time option being set to 0. |
| 127497 | 128045 | */ |
| 127498 | | -SQLITE_API int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; } |
| 128046 | +SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; } |
| 128047 | + |
| 128048 | +/* |
| 128049 | +** When compiling the test fixture or with debugging enabled (on Win32), |
| 128050 | +** this variable being set to non-zero will cause OSTRACE macros to emit |
| 128051 | +** extra diagnostic information. |
| 128052 | +*/ |
| 128053 | +#ifdef SQLITE_HAVE_OS_TRACE |
| 128054 | +# ifndef SQLITE_DEBUG_OS_TRACE |
| 128055 | +# define SQLITE_DEBUG_OS_TRACE 0 |
| 128056 | +# endif |
| 128057 | + int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; |
| 128058 | +#endif |
| 127499 | 128059 | |
| 127500 | 128060 | #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE) |
| 127501 | 128061 | /* |
| 127502 | 128062 | ** If the following function pointer is not NULL and if |
| 127503 | 128063 | ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing |
| 127504 | 128064 | ** I/O active are written using this function. These messages |
| 127505 | 128065 | ** are intended for debugging activity only. |
| 127506 | 128066 | */ |
| 127507 | | -/* not-private */ void (*sqlite3IoTrace)(const char*, ...) = 0; |
| 128067 | +SQLITE_API void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...) = 0; |
| 127508 | 128068 | #endif |
| 127509 | 128069 | |
| 127510 | 128070 | /* |
| 127511 | 128071 | ** If the following global variable points to a string which is the |
| 127512 | 128072 | ** name of a directory, then that directory will be used to store |
| | @@ -127554,11 +128114,11 @@ |
| 127554 | 128114 | ** call by X completes. |
| 127555 | 128115 | ** |
| 127556 | 128116 | ** * Recursive calls to this routine from thread X return immediately |
| 127557 | 128117 | ** without blocking. |
| 127558 | 128118 | */ |
| 127559 | | -SQLITE_API int sqlite3_initialize(void){ |
| 128119 | +SQLITE_API int SQLITE_STDCALL sqlite3_initialize(void){ |
| 127560 | 128120 | MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ |
| 127561 | 128121 | int rc; /* Result code */ |
| 127562 | 128122 | #ifdef SQLITE_EXTRA_INIT |
| 127563 | 128123 | int bRunExtraInit = 0; /* Extra initialization needed */ |
| 127564 | 128124 | #endif |
| | @@ -127715,11 +128275,11 @@ |
| 127715 | 128275 | ** while any part of SQLite is otherwise in use in any thread. This |
| 127716 | 128276 | ** routine is not threadsafe. But it is safe to invoke this routine |
| 127717 | 128277 | ** on when SQLite is already shut down. If SQLite is already shut down |
| 127718 | 128278 | ** when this routine is invoked, then this routine is a harmless no-op. |
| 127719 | 128279 | */ |
| 127720 | | -SQLITE_API int sqlite3_shutdown(void){ |
| 128280 | +SQLITE_API int SQLITE_STDCALL sqlite3_shutdown(void){ |
| 127721 | 128281 | #ifdef SQLITE_OMIT_WSD |
| 127722 | 128282 | int rc = sqlite3_wsd_init(4096, 24); |
| 127723 | 128283 | if( rc!=SQLITE_OK ){ |
| 127724 | 128284 | return rc; |
| 127725 | 128285 | } |
| | @@ -127769,11 +128329,11 @@ |
| 127769 | 128329 | ** This routine should only be called when there are no outstanding |
| 127770 | 128330 | ** database connections or memory allocations. This routine is not |
| 127771 | 128331 | ** threadsafe. Failure to heed these warnings can lead to unpredictable |
| 127772 | 128332 | ** behavior. |
| 127773 | 128333 | */ |
| 127774 | | -SQLITE_API int sqlite3_config(int op, ...){ |
| 128334 | +SQLITE_API int SQLITE_CDECL sqlite3_config(int op, ...){ |
| 127775 | 128335 | va_list ap; |
| 127776 | 128336 | int rc = SQLITE_OK; |
| 127777 | 128337 | |
| 127778 | 128338 | /* sqlite3_config() shall return SQLITE_MISUSE if it is invoked while |
| 127779 | 128339 | ** the SQLite library is in use. */ |
| | @@ -128126,11 +128686,11 @@ |
| 128126 | 128686 | } |
| 128127 | 128687 | |
| 128128 | 128688 | /* |
| 128129 | 128689 | ** Return the mutex associated with a database connection. |
| 128130 | 128690 | */ |
| 128131 | | -SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){ |
| 128691 | +SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3 *db){ |
| 128132 | 128692 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128133 | 128693 | if( !sqlite3SafetyCheckOk(db) ){ |
| 128134 | 128694 | (void)SQLITE_MISUSE_BKPT; |
| 128135 | 128695 | return 0; |
| 128136 | 128696 | } |
| | @@ -128140,11 +128700,11 @@ |
| 128140 | 128700 | |
| 128141 | 128701 | /* |
| 128142 | 128702 | ** Free up as much memory as we can from the given database |
| 128143 | 128703 | ** connection. |
| 128144 | 128704 | */ |
| 128145 | | -SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){ |
| 128705 | +SQLITE_API int SQLITE_STDCALL sqlite3_db_release_memory(sqlite3 *db){ |
| 128146 | 128706 | int i; |
| 128147 | 128707 | |
| 128148 | 128708 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128149 | 128709 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 128150 | 128710 | #endif |
| | @@ -128163,11 +128723,11 @@ |
| 128163 | 128723 | } |
| 128164 | 128724 | |
| 128165 | 128725 | /* |
| 128166 | 128726 | ** Configuration settings for an individual database connection |
| 128167 | 128727 | */ |
| 128168 | | -SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){ |
| 128728 | +SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3 *db, int op, ...){ |
| 128169 | 128729 | va_list ap; |
| 128170 | 128730 | int rc; |
| 128171 | 128731 | va_start(ap, op); |
| 128172 | 128732 | switch( op ){ |
| 128173 | 128733 | case SQLITE_DBCONFIG_LOOKASIDE: { |
| | @@ -128282,11 +128842,11 @@ |
| 128282 | 128842 | } |
| 128283 | 128843 | |
| 128284 | 128844 | /* |
| 128285 | 128845 | ** Return the ROWID of the most recent insert |
| 128286 | 128846 | */ |
| 128287 | | -SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){ |
| 128847 | +SQLITE_API sqlite_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3 *db){ |
| 128288 | 128848 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128289 | 128849 | if( !sqlite3SafetyCheckOk(db) ){ |
| 128290 | 128850 | (void)SQLITE_MISUSE_BKPT; |
| 128291 | 128851 | return 0; |
| 128292 | 128852 | } |
| | @@ -128295,11 +128855,11 @@ |
| 128295 | 128855 | } |
| 128296 | 128856 | |
| 128297 | 128857 | /* |
| 128298 | 128858 | ** Return the number of changes in the most recent call to sqlite3_exec(). |
| 128299 | 128859 | */ |
| 128300 | | -SQLITE_API int sqlite3_changes(sqlite3 *db){ |
| 128860 | +SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3 *db){ |
| 128301 | 128861 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128302 | 128862 | if( !sqlite3SafetyCheckOk(db) ){ |
| 128303 | 128863 | (void)SQLITE_MISUSE_BKPT; |
| 128304 | 128864 | return 0; |
| 128305 | 128865 | } |
| | @@ -128308,11 +128868,11 @@ |
| 128308 | 128868 | } |
| 128309 | 128869 | |
| 128310 | 128870 | /* |
| 128311 | 128871 | ** Return the number of changes since the database handle was opened. |
| 128312 | 128872 | */ |
| 128313 | | -SQLITE_API int sqlite3_total_changes(sqlite3 *db){ |
| 128873 | +SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3 *db){ |
| 128314 | 128874 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128315 | 128875 | if( !sqlite3SafetyCheckOk(db) ){ |
| 128316 | 128876 | (void)SQLITE_MISUSE_BKPT; |
| 128317 | 128877 | return 0; |
| 128318 | 128878 | } |
| | @@ -128450,12 +129010,12 @@ |
| 128450 | 129010 | ** statements or unfinished sqlite3_backups. The sqlite3_close_v2() |
| 128451 | 129011 | ** version forces the connection to become a zombie if there are |
| 128452 | 129012 | ** unclosed resources, and arranges for deallocation when the last |
| 128453 | 129013 | ** prepare statement or sqlite3_backup closes. |
| 128454 | 129014 | */ |
| 128455 | | -SQLITE_API int sqlite3_close(sqlite3 *db){ return sqlite3Close(db,0); } |
| 128456 | | -SQLITE_API int sqlite3_close_v2(sqlite3 *db){ return sqlite3Close(db,1); } |
| 129015 | +SQLITE_API int SQLITE_STDCALL sqlite3_close(sqlite3 *db){ return sqlite3Close(db,0); } |
| 129016 | +SQLITE_API int SQLITE_STDCALL sqlite3_close_v2(sqlite3 *db){ return sqlite3Close(db,1); } |
| 128457 | 129017 | |
| 128458 | 129018 | |
| 128459 | 129019 | /* |
| 128460 | 129020 | ** Close the mutex on database connection db. |
| 128461 | 129021 | ** |
| | @@ -128634,11 +129194,11 @@ |
| 128634 | 129194 | |
| 128635 | 129195 | /* |
| 128636 | 129196 | ** Return a static string containing the name corresponding to the error code |
| 128637 | 129197 | ** specified in the argument. |
| 128638 | 129198 | */ |
| 128639 | | -#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST) |
| 129199 | +#if defined(SQLITE_NEED_ERR_NAME) |
| 128640 | 129200 | SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ |
| 128641 | 129201 | const char *zName = 0; |
| 128642 | 129202 | int i, origRc = rc; |
| 128643 | 129203 | for(i=0; i<2 && zName==0; i++, rc &= 0xff){ |
| 128644 | 129204 | switch( rc ){ |
| | @@ -128858,11 +129418,11 @@ |
| 128858 | 129418 | |
| 128859 | 129419 | /* |
| 128860 | 129420 | ** This routine sets the busy callback for an Sqlite database to the |
| 128861 | 129421 | ** given callback function with the given argument. |
| 128862 | 129422 | */ |
| 128863 | | -SQLITE_API int sqlite3_busy_handler( |
| 129423 | +SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler( |
| 128864 | 129424 | sqlite3 *db, |
| 128865 | 129425 | int (*xBusy)(void*,int), |
| 128866 | 129426 | void *pArg |
| 128867 | 129427 | ){ |
| 128868 | 129428 | #ifdef SQLITE_ENABLE_API_ARMOR |
| | @@ -128881,11 +129441,11 @@ |
| 128881 | 129441 | /* |
| 128882 | 129442 | ** This routine sets the progress callback for an Sqlite database to the |
| 128883 | 129443 | ** given callback function with the given argument. The progress callback will |
| 128884 | 129444 | ** be invoked every nOps opcodes. |
| 128885 | 129445 | */ |
| 128886 | | -SQLITE_API void sqlite3_progress_handler( |
| 129446 | +SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler( |
| 128887 | 129447 | sqlite3 *db, |
| 128888 | 129448 | int nOps, |
| 128889 | 129449 | int (*xProgress)(void*), |
| 128890 | 129450 | void *pArg |
| 128891 | 129451 | ){ |
| | @@ -128912,11 +129472,11 @@ |
| 128912 | 129472 | |
| 128913 | 129473 | /* |
| 128914 | 129474 | ** This routine installs a default busy handler that waits for the |
| 128915 | 129475 | ** specified number of milliseconds before returning 0. |
| 128916 | 129476 | */ |
| 128917 | | -SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){ |
| 129477 | +SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3 *db, int ms){ |
| 128918 | 129478 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128919 | 129479 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 128920 | 129480 | #endif |
| 128921 | 129481 | if( ms>0 ){ |
| 128922 | 129482 | sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db); |
| | @@ -128928,11 +129488,11 @@ |
| 128928 | 129488 | } |
| 128929 | 129489 | |
| 128930 | 129490 | /* |
| 128931 | 129491 | ** Cause any pending operation to stop at its earliest opportunity. |
| 128932 | 129492 | */ |
| 128933 | | -SQLITE_API void sqlite3_interrupt(sqlite3 *db){ |
| 129493 | +SQLITE_API void SQLITE_STDCALL sqlite3_interrupt(sqlite3 *db){ |
| 128934 | 129494 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128935 | 129495 | if( !sqlite3SafetyCheckOk(db) ){ |
| 128936 | 129496 | (void)SQLITE_MISUSE_BKPT; |
| 128937 | 129497 | return; |
| 128938 | 129498 | } |
| | @@ -129045,11 +129605,11 @@ |
| 129045 | 129605 | } |
| 129046 | 129606 | |
| 129047 | 129607 | /* |
| 129048 | 129608 | ** Create new user functions. |
| 129049 | 129609 | */ |
| 129050 | | -SQLITE_API int sqlite3_create_function( |
| 129610 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_function( |
| 129051 | 129611 | sqlite3 *db, |
| 129052 | 129612 | const char *zFunc, |
| 129053 | 129613 | int nArg, |
| 129054 | 129614 | int enc, |
| 129055 | 129615 | void *p, |
| | @@ -129059,11 +129619,11 @@ |
| 129059 | 129619 | ){ |
| 129060 | 129620 | return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep, |
| 129061 | 129621 | xFinal, 0); |
| 129062 | 129622 | } |
| 129063 | 129623 | |
| 129064 | | -SQLITE_API int sqlite3_create_function_v2( |
| 129624 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_function_v2( |
| 129065 | 129625 | sqlite3 *db, |
| 129066 | 129626 | const char *zFunc, |
| 129067 | 129627 | int nArg, |
| 129068 | 129628 | int enc, |
| 129069 | 129629 | void *p, |
| | @@ -129102,11 +129662,11 @@ |
| 129102 | 129662 | sqlite3_mutex_leave(db->mutex); |
| 129103 | 129663 | return rc; |
| 129104 | 129664 | } |
| 129105 | 129665 | |
| 129106 | 129666 | #ifndef SQLITE_OMIT_UTF16 |
| 129107 | | -SQLITE_API int sqlite3_create_function16( |
| 129667 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_function16( |
| 129108 | 129668 | sqlite3 *db, |
| 129109 | 129669 | const void *zFunctionName, |
| 129110 | 129670 | int nArg, |
| 129111 | 129671 | int eTextRep, |
| 129112 | 129672 | void *p, |
| | @@ -129142,11 +129702,11 @@ |
| 129142 | 129702 | ** When virtual tables intend to provide an overloaded function, they |
| 129143 | 129703 | ** should call this routine to make sure the global function exists. |
| 129144 | 129704 | ** A global function must exist in order for name resolution to work |
| 129145 | 129705 | ** properly. |
| 129146 | 129706 | */ |
| 129147 | | -SQLITE_API int sqlite3_overload_function( |
| 129707 | +SQLITE_API int SQLITE_STDCALL sqlite3_overload_function( |
| 129148 | 129708 | sqlite3 *db, |
| 129149 | 129709 | const char *zName, |
| 129150 | 129710 | int nArg |
| 129151 | 129711 | ){ |
| 129152 | 129712 | int nName = sqlite3Strlen30(zName); |
| | @@ -129174,11 +129734,11 @@ |
| 129174 | 129734 | ** |
| 129175 | 129735 | ** A NULL trace function means that no tracing is executes. A non-NULL |
| 129176 | 129736 | ** trace is a pointer to a function that is invoked at the start of each |
| 129177 | 129737 | ** SQL statement. |
| 129178 | 129738 | */ |
| 129179 | | -SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){ |
| 129739 | +SQLITE_API void *SQLITE_STDCALL sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){ |
| 129180 | 129740 | void *pOld; |
| 129181 | 129741 | |
| 129182 | 129742 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 129183 | 129743 | if( !sqlite3SafetyCheckOk(db) ){ |
| 129184 | 129744 | (void)SQLITE_MISUSE_BKPT; |
| | @@ -129198,11 +129758,11 @@ |
| 129198 | 129758 | ** |
| 129199 | 129759 | ** A NULL profile function means that no profiling is executes. A non-NULL |
| 129200 | 129760 | ** profile is a pointer to a function that is invoked at the conclusion of |
| 129201 | 129761 | ** each SQL statement that is run. |
| 129202 | 129762 | */ |
| 129203 | | -SQLITE_API void *sqlite3_profile( |
| 129763 | +SQLITE_API void *SQLITE_STDCALL sqlite3_profile( |
| 129204 | 129764 | sqlite3 *db, |
| 129205 | 129765 | void (*xProfile)(void*,const char*,sqlite_uint64), |
| 129206 | 129766 | void *pArg |
| 129207 | 129767 | ){ |
| 129208 | 129768 | void *pOld; |
| | @@ -129225,11 +129785,11 @@ |
| 129225 | 129785 | /* |
| 129226 | 129786 | ** Register a function to be invoked when a transaction commits. |
| 129227 | 129787 | ** If the invoked function returns non-zero, then the commit becomes a |
| 129228 | 129788 | ** rollback. |
| 129229 | 129789 | */ |
| 129230 | | -SQLITE_API void *sqlite3_commit_hook( |
| 129790 | +SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook( |
| 129231 | 129791 | sqlite3 *db, /* Attach the hook to this database */ |
| 129232 | 129792 | int (*xCallback)(void*), /* Function to invoke on each commit */ |
| 129233 | 129793 | void *pArg /* Argument to the function */ |
| 129234 | 129794 | ){ |
| 129235 | 129795 | void *pOld; |
| | @@ -129250,11 +129810,11 @@ |
| 129250 | 129810 | |
| 129251 | 129811 | /* |
| 129252 | 129812 | ** Register a callback to be invoked each time a row is updated, |
| 129253 | 129813 | ** inserted or deleted using this database connection. |
| 129254 | 129814 | */ |
| 129255 | | -SQLITE_API void *sqlite3_update_hook( |
| 129815 | +SQLITE_API void *SQLITE_STDCALL sqlite3_update_hook( |
| 129256 | 129816 | sqlite3 *db, /* Attach the hook to this database */ |
| 129257 | 129817 | void (*xCallback)(void*,int,char const *,char const *,sqlite_int64), |
| 129258 | 129818 | void *pArg /* Argument to the function */ |
| 129259 | 129819 | ){ |
| 129260 | 129820 | void *pRet; |
| | @@ -129275,11 +129835,11 @@ |
| 129275 | 129835 | |
| 129276 | 129836 | /* |
| 129277 | 129837 | ** Register a callback to be invoked each time a transaction is rolled |
| 129278 | 129838 | ** back by this database connection. |
| 129279 | 129839 | */ |
| 129280 | | -SQLITE_API void *sqlite3_rollback_hook( |
| 129840 | +SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook( |
| 129281 | 129841 | sqlite3 *db, /* Attach the hook to this database */ |
| 129282 | 129842 | void (*xCallback)(void*), /* Callback function */ |
| 129283 | 129843 | void *pArg /* Argument to the function */ |
| 129284 | 129844 | ){ |
| 129285 | 129845 | void *pRet; |
| | @@ -129329,11 +129889,11 @@ |
| 129329 | 129889 | ** The callback registered by this function replaces any existing callback |
| 129330 | 129890 | ** registered using sqlite3_wal_hook(). Likewise, registering a callback |
| 129331 | 129891 | ** using sqlite3_wal_hook() disables the automatic checkpoint mechanism |
| 129332 | 129892 | ** configured by this function. |
| 129333 | 129893 | */ |
| 129334 | | -SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){ |
| 129894 | +SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){ |
| 129335 | 129895 | #ifdef SQLITE_OMIT_WAL |
| 129336 | 129896 | UNUSED_PARAMETER(db); |
| 129337 | 129897 | UNUSED_PARAMETER(nFrame); |
| 129338 | 129898 | #else |
| 129339 | 129899 | #ifdef SQLITE_ENABLE_API_ARMOR |
| | @@ -129350,11 +129910,11 @@ |
| 129350 | 129910 | |
| 129351 | 129911 | /* |
| 129352 | 129912 | ** Register a callback to be invoked each time a transaction is written |
| 129353 | 129913 | ** into the write-ahead-log by this database connection. |
| 129354 | 129914 | */ |
| 129355 | | -SQLITE_API void *sqlite3_wal_hook( |
| 129915 | +SQLITE_API void *SQLITE_STDCALL sqlite3_wal_hook( |
| 129356 | 129916 | sqlite3 *db, /* Attach the hook to this db handle */ |
| 129357 | 129917 | int(*xCallback)(void *, sqlite3*, const char*, int), |
| 129358 | 129918 | void *pArg /* First argument passed to xCallback() */ |
| 129359 | 129919 | ){ |
| 129360 | 129920 | #ifndef SQLITE_OMIT_WAL |
| | @@ -129377,11 +129937,11 @@ |
| 129377 | 129937 | } |
| 129378 | 129938 | |
| 129379 | 129939 | /* |
| 129380 | 129940 | ** Checkpoint database zDb. |
| 129381 | 129941 | */ |
| 129382 | | -SQLITE_API int sqlite3_wal_checkpoint_v2( |
| 129942 | +SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint_v2( |
| 129383 | 129943 | sqlite3 *db, /* Database handle */ |
| 129384 | 129944 | const char *zDb, /* Name of attached database (or NULL) */ |
| 129385 | 129945 | int eMode, /* SQLITE_CHECKPOINT_* value */ |
| 129386 | 129946 | int *pnLog, /* OUT: Size of WAL log in frames */ |
| 129387 | 129947 | int *pnCkpt /* OUT: Total number of frames checkpointed */ |
| | @@ -129432,11 +129992,11 @@ |
| 129432 | 129992 | /* |
| 129433 | 129993 | ** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points |
| 129434 | 129994 | ** to contains a zero-length string, all attached databases are |
| 129435 | 129995 | ** checkpointed. |
| 129436 | 129996 | */ |
| 129437 | | -SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){ |
| 129997 | +SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){ |
| 129438 | 129998 | /* EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is equivalent to |
| 129439 | 129999 | ** sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). */ |
| 129440 | 130000 | return sqlite3_wal_checkpoint_v2(db,zDb,SQLITE_CHECKPOINT_PASSIVE,0,0); |
| 129441 | 130001 | } |
| 129442 | 130002 | |
| | @@ -129521,11 +130081,11 @@ |
| 129521 | 130081 | |
| 129522 | 130082 | /* |
| 129523 | 130083 | ** Return UTF-8 encoded English language explanation of the most recent |
| 129524 | 130084 | ** error. |
| 129525 | 130085 | */ |
| 129526 | | -SQLITE_API const char *sqlite3_errmsg(sqlite3 *db){ |
| 130086 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3 *db){ |
| 129527 | 130087 | const char *z; |
| 129528 | 130088 | if( !db ){ |
| 129529 | 130089 | return sqlite3ErrStr(SQLITE_NOMEM); |
| 129530 | 130090 | } |
| 129531 | 130091 | if( !sqlite3SafetyCheckSickOrOk(db) ){ |
| | @@ -129549,11 +130109,11 @@ |
| 129549 | 130109 | #ifndef SQLITE_OMIT_UTF16 |
| 129550 | 130110 | /* |
| 129551 | 130111 | ** Return UTF-16 encoded English language explanation of the most recent |
| 129552 | 130112 | ** error. |
| 129553 | 130113 | */ |
| 129554 | | -SQLITE_API const void *sqlite3_errmsg16(sqlite3 *db){ |
| 130114 | +SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3 *db){ |
| 129555 | 130115 | static const u16 outOfMem[] = { |
| 129556 | 130116 | 'o', 'u', 't', ' ', 'o', 'f', ' ', 'm', 'e', 'm', 'o', 'r', 'y', 0 |
| 129557 | 130117 | }; |
| 129558 | 130118 | static const u16 misuse[] = { |
| 129559 | 130119 | 'l', 'i', 'b', 'r', 'a', 'r', 'y', ' ', |
| | @@ -129594,20 +130154,20 @@ |
| 129594 | 130154 | |
| 129595 | 130155 | /* |
| 129596 | 130156 | ** Return the most recent error code generated by an SQLite routine. If NULL is |
| 129597 | 130157 | ** passed to this function, we assume a malloc() failed during sqlite3_open(). |
| 129598 | 130158 | */ |
| 129599 | | -SQLITE_API int sqlite3_errcode(sqlite3 *db){ |
| 130159 | +SQLITE_API int SQLITE_STDCALL sqlite3_errcode(sqlite3 *db){ |
| 129600 | 130160 | if( db && !sqlite3SafetyCheckSickOrOk(db) ){ |
| 129601 | 130161 | return SQLITE_MISUSE_BKPT; |
| 129602 | 130162 | } |
| 129603 | 130163 | if( !db || db->mallocFailed ){ |
| 129604 | 130164 | return SQLITE_NOMEM; |
| 129605 | 130165 | } |
| 129606 | 130166 | return db->errCode & db->errMask; |
| 129607 | 130167 | } |
| 129608 | | -SQLITE_API int sqlite3_extended_errcode(sqlite3 *db){ |
| 130168 | +SQLITE_API int SQLITE_STDCALL sqlite3_extended_errcode(sqlite3 *db){ |
| 129609 | 130169 | if( db && !sqlite3SafetyCheckSickOrOk(db) ){ |
| 129610 | 130170 | return SQLITE_MISUSE_BKPT; |
| 129611 | 130171 | } |
| 129612 | 130172 | if( !db || db->mallocFailed ){ |
| 129613 | 130173 | return SQLITE_NOMEM; |
| | @@ -129618,11 +130178,11 @@ |
| 129618 | 130178 | /* |
| 129619 | 130179 | ** Return a string that describes the kind of error specified in the |
| 129620 | 130180 | ** argument. For now, this simply calls the internal sqlite3ErrStr() |
| 129621 | 130181 | ** function. |
| 129622 | 130182 | */ |
| 129623 | | -SQLITE_API const char *sqlite3_errstr(int rc){ |
| 130183 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int rc){ |
| 129624 | 130184 | return sqlite3ErrStr(rc); |
| 129625 | 130185 | } |
| 129626 | 130186 | |
| 129627 | 130187 | /* |
| 129628 | 130188 | ** Create a new collating function for database "db". The name is zName |
| | @@ -129766,11 +130326,11 @@ |
| 129766 | 130326 | ** |
| 129767 | 130327 | ** A new lower limit does not shrink existing constructs. |
| 129768 | 130328 | ** It merely prevents new constructs that exceed the limit |
| 129769 | 130329 | ** from forming. |
| 129770 | 130330 | */ |
| 129771 | | -SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){ |
| 130331 | +SQLITE_API int SQLITE_STDCALL sqlite3_limit(sqlite3 *db, int limitId, int newLimit){ |
| 129772 | 130332 | int oldLimit; |
| 129773 | 130333 | |
| 129774 | 130334 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 129775 | 130335 | if( !sqlite3SafetyCheckOk(db) ){ |
| 129776 | 130336 | (void)SQLITE_MISUSE_BKPT; |
| | @@ -129859,18 +130419,18 @@ |
| 129859 | 130419 | ){ |
| 129860 | 130420 | char *zOpt; |
| 129861 | 130421 | int eState; /* Parser state when parsing URI */ |
| 129862 | 130422 | int iIn; /* Input character index */ |
| 129863 | 130423 | int iOut = 0; /* Output character index */ |
| 129864 | | - int nByte = nUri+2; /* Bytes of space to allocate */ |
| 130424 | + u64 nByte = nUri+2; /* Bytes of space to allocate */ |
| 129865 | 130425 | |
| 129866 | 130426 | /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen |
| 129867 | 130427 | ** method that there may be extra parameters following the file-name. */ |
| 129868 | 130428 | flags |= SQLITE_OPEN_URI; |
| 129869 | 130429 | |
| 129870 | 130430 | for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&'); |
| 129871 | | - zFile = sqlite3_malloc(nByte); |
| 130431 | + zFile = sqlite3_malloc64(nByte); |
| 129872 | 130432 | if( !zFile ) return SQLITE_NOMEM; |
| 129873 | 130433 | |
| 129874 | 130434 | iIn = 5; |
| 129875 | 130435 | #ifdef SQLITE_ALLOW_URI_AUTHORITY |
| 129876 | 130436 | if( strncmp(zUri+5, "///", 3)==0 ){ |
| | @@ -130032,11 +130592,11 @@ |
| 130032 | 130592 | |
| 130033 | 130593 | zOpt = &zVal[nVal+1]; |
| 130034 | 130594 | } |
| 130035 | 130595 | |
| 130036 | 130596 | }else{ |
| 130037 | | - zFile = sqlite3_malloc(nUri+2); |
| 130597 | + zFile = sqlite3_malloc64(nUri+2); |
| 130038 | 130598 | if( !zFile ) return SQLITE_NOMEM; |
| 130039 | 130599 | memcpy(zFile, zUri, nUri); |
| 130040 | 130600 | zFile[nUri] = '\0'; |
| 130041 | 130601 | zFile[nUri+1] = '\0'; |
| 130042 | 130602 | flags &= ~SQLITE_OPEN_URI; |
| | @@ -130303,10 +130863,17 @@ |
| 130303 | 130863 | #ifdef SQLITE_ENABLE_RTREE |
| 130304 | 130864 | if( !db->mallocFailed && rc==SQLITE_OK){ |
| 130305 | 130865 | rc = sqlite3RtreeInit(db); |
| 130306 | 130866 | } |
| 130307 | 130867 | #endif |
| 130868 | + |
| 130869 | +#ifdef SQLITE_ENABLE_DBSTAT_VTAB |
| 130870 | + if( !db->mallocFailed && rc==SQLITE_OK){ |
| 130871 | + int sqlite3_dbstat_register(sqlite3*); |
| 130872 | + rc = sqlite3_dbstat_register(db); |
| 130873 | + } |
| 130874 | +#endif |
| 130308 | 130875 | |
| 130309 | 130876 | /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking |
| 130310 | 130877 | ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking |
| 130311 | 130878 | ** mode. Doing nothing at all also makes NORMAL the default. |
| 130312 | 130879 | */ |
| | @@ -130351,18 +130918,18 @@ |
| 130351 | 130918 | } |
| 130352 | 130919 | |
| 130353 | 130920 | /* |
| 130354 | 130921 | ** Open a new database handle. |
| 130355 | 130922 | */ |
| 130356 | | -SQLITE_API int sqlite3_open( |
| 130923 | +SQLITE_API int SQLITE_STDCALL sqlite3_open( |
| 130357 | 130924 | const char *zFilename, |
| 130358 | 130925 | sqlite3 **ppDb |
| 130359 | 130926 | ){ |
| 130360 | 130927 | return openDatabase(zFilename, ppDb, |
| 130361 | 130928 | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0); |
| 130362 | 130929 | } |
| 130363 | | -SQLITE_API int sqlite3_open_v2( |
| 130930 | +SQLITE_API int SQLITE_STDCALL sqlite3_open_v2( |
| 130364 | 130931 | const char *filename, /* Database filename (UTF-8) */ |
| 130365 | 130932 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 130366 | 130933 | int flags, /* Flags */ |
| 130367 | 130934 | const char *zVfs /* Name of VFS module to use */ |
| 130368 | 130935 | ){ |
| | @@ -130371,11 +130938,11 @@ |
| 130371 | 130938 | |
| 130372 | 130939 | #ifndef SQLITE_OMIT_UTF16 |
| 130373 | 130940 | /* |
| 130374 | 130941 | ** Open a new database handle. |
| 130375 | 130942 | */ |
| 130376 | | -SQLITE_API int sqlite3_open16( |
| 130943 | +SQLITE_API int SQLITE_STDCALL sqlite3_open16( |
| 130377 | 130944 | const void *zFilename, |
| 130378 | 130945 | sqlite3 **ppDb |
| 130379 | 130946 | ){ |
| 130380 | 130947 | char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */ |
| 130381 | 130948 | sqlite3_value *pVal; |
| | @@ -130410,11 +130977,11 @@ |
| 130410 | 130977 | #endif /* SQLITE_OMIT_UTF16 */ |
| 130411 | 130978 | |
| 130412 | 130979 | /* |
| 130413 | 130980 | ** Register a new collation sequence with the database handle db. |
| 130414 | 130981 | */ |
| 130415 | | -SQLITE_API int sqlite3_create_collation( |
| 130982 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_collation( |
| 130416 | 130983 | sqlite3* db, |
| 130417 | 130984 | const char *zName, |
| 130418 | 130985 | int enc, |
| 130419 | 130986 | void* pCtx, |
| 130420 | 130987 | int(*xCompare)(void*,int,const void*,int,const void*) |
| | @@ -130423,11 +130990,11 @@ |
| 130423 | 130990 | } |
| 130424 | 130991 | |
| 130425 | 130992 | /* |
| 130426 | 130993 | ** Register a new collation sequence with the database handle db. |
| 130427 | 130994 | */ |
| 130428 | | -SQLITE_API int sqlite3_create_collation_v2( |
| 130995 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_collation_v2( |
| 130429 | 130996 | sqlite3* db, |
| 130430 | 130997 | const char *zName, |
| 130431 | 130998 | int enc, |
| 130432 | 130999 | void* pCtx, |
| 130433 | 131000 | int(*xCompare)(void*,int,const void*,int,const void*), |
| | @@ -130448,11 +131015,11 @@ |
| 130448 | 131015 | |
| 130449 | 131016 | #ifndef SQLITE_OMIT_UTF16 |
| 130450 | 131017 | /* |
| 130451 | 131018 | ** Register a new collation sequence with the database handle db. |
| 130452 | 131019 | */ |
| 130453 | | -SQLITE_API int sqlite3_create_collation16( |
| 131020 | +SQLITE_API int SQLITE_STDCALL sqlite3_create_collation16( |
| 130454 | 131021 | sqlite3* db, |
| 130455 | 131022 | const void *zName, |
| 130456 | 131023 | int enc, |
| 130457 | 131024 | void* pCtx, |
| 130458 | 131025 | int(*xCompare)(void*,int,const void*,int,const void*) |
| | @@ -130478,11 +131045,11 @@ |
| 130478 | 131045 | |
| 130479 | 131046 | /* |
| 130480 | 131047 | ** Register a collation sequence factory callback with the database handle |
| 130481 | 131048 | ** db. Replace any previously installed collation sequence factory. |
| 130482 | 131049 | */ |
| 130483 | | -SQLITE_API int sqlite3_collation_needed( |
| 131050 | +SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed( |
| 130484 | 131051 | sqlite3 *db, |
| 130485 | 131052 | void *pCollNeededArg, |
| 130486 | 131053 | void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*) |
| 130487 | 131054 | ){ |
| 130488 | 131055 | #ifdef SQLITE_ENABLE_API_ARMOR |
| | @@ -130499,11 +131066,11 @@ |
| 130499 | 131066 | #ifndef SQLITE_OMIT_UTF16 |
| 130500 | 131067 | /* |
| 130501 | 131068 | ** Register a collation sequence factory callback with the database handle |
| 130502 | 131069 | ** db. Replace any previously installed collation sequence factory. |
| 130503 | 131070 | */ |
| 130504 | | -SQLITE_API int sqlite3_collation_needed16( |
| 131071 | +SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed16( |
| 130505 | 131072 | sqlite3 *db, |
| 130506 | 131073 | void *pCollNeededArg, |
| 130507 | 131074 | void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*) |
| 130508 | 131075 | ){ |
| 130509 | 131076 | #ifdef SQLITE_ENABLE_API_ARMOR |
| | @@ -130521,11 +131088,11 @@ |
| 130521 | 131088 | #ifndef SQLITE_OMIT_DEPRECATED |
| 130522 | 131089 | /* |
| 130523 | 131090 | ** This function is now an anachronism. It used to be used to recover from a |
| 130524 | 131091 | ** malloc() failure, but SQLite now does this automatically. |
| 130525 | 131092 | */ |
| 130526 | | -SQLITE_API int sqlite3_global_recover(void){ |
| 131093 | +SQLITE_API int SQLITE_STDCALL sqlite3_global_recover(void){ |
| 130527 | 131094 | return SQLITE_OK; |
| 130528 | 131095 | } |
| 130529 | 131096 | #endif |
| 130530 | 131097 | |
| 130531 | 131098 | /* |
| | @@ -130532,11 +131099,11 @@ |
| 130532 | 131099 | ** Test to see whether or not the database connection is in autocommit |
| 130533 | 131100 | ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on |
| 130534 | 131101 | ** by default. Autocommit is disabled by a BEGIN statement and reenabled |
| 130535 | 131102 | ** by the next COMMIT or ROLLBACK. |
| 130536 | 131103 | */ |
| 130537 | | -SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){ |
| 131104 | +SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3 *db){ |
| 130538 | 131105 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 130539 | 131106 | if( !sqlite3SafetyCheckOk(db) ){ |
| 130540 | 131107 | (void)SQLITE_MISUSE_BKPT; |
| 130541 | 131108 | return 0; |
| 130542 | 131109 | } |
| | @@ -130584,19 +131151,19 @@ |
| 130584 | 131151 | ** data for this thread has been deallocated. |
| 130585 | 131152 | ** |
| 130586 | 131153 | ** SQLite no longer uses thread-specific data so this routine is now a |
| 130587 | 131154 | ** no-op. It is retained for historical compatibility. |
| 130588 | 131155 | */ |
| 130589 | | -SQLITE_API void sqlite3_thread_cleanup(void){ |
| 131156 | +SQLITE_API void SQLITE_STDCALL sqlite3_thread_cleanup(void){ |
| 130590 | 131157 | } |
| 130591 | 131158 | #endif |
| 130592 | 131159 | |
| 130593 | 131160 | /* |
| 130594 | 131161 | ** Return meta information about a specific column of a database table. |
| 130595 | 131162 | ** See comment in sqlite3.h (sqlite.h.in) for details. |
| 130596 | 131163 | */ |
| 130597 | | -SQLITE_API int sqlite3_table_column_metadata( |
| 131164 | +SQLITE_API int SQLITE_STDCALL sqlite3_table_column_metadata( |
| 130598 | 131165 | sqlite3 *db, /* Connection handle */ |
| 130599 | 131166 | const char *zDbName, /* Database name or NULL */ |
| 130600 | 131167 | const char *zTableName, /* Table name */ |
| 130601 | 131168 | const char *zColumnName, /* Column name */ |
| 130602 | 131169 | char const **pzDataType, /* OUTPUT: Declared data type */ |
| | @@ -130710,11 +131277,11 @@ |
| 130710 | 131277 | } |
| 130711 | 131278 | |
| 130712 | 131279 | /* |
| 130713 | 131280 | ** Sleep for a little while. Return the amount of time slept. |
| 130714 | 131281 | */ |
| 130715 | | -SQLITE_API int sqlite3_sleep(int ms){ |
| 131282 | +SQLITE_API int SQLITE_STDCALL sqlite3_sleep(int ms){ |
| 130716 | 131283 | sqlite3_vfs *pVfs; |
| 130717 | 131284 | int rc; |
| 130718 | 131285 | pVfs = sqlite3_vfs_find(0); |
| 130719 | 131286 | if( pVfs==0 ) return 0; |
| 130720 | 131287 | |
| | @@ -130726,11 +131293,11 @@ |
| 130726 | 131293 | } |
| 130727 | 131294 | |
| 130728 | 131295 | /* |
| 130729 | 131296 | ** Enable or disable the extended result codes. |
| 130730 | 131297 | */ |
| 130731 | | -SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){ |
| 131298 | +SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3 *db, int onoff){ |
| 130732 | 131299 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 130733 | 131300 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 130734 | 131301 | #endif |
| 130735 | 131302 | sqlite3_mutex_enter(db->mutex); |
| 130736 | 131303 | db->errMask = onoff ? 0xffffffff : 0xff; |
| | @@ -130739,11 +131306,11 @@ |
| 130739 | 131306 | } |
| 130740 | 131307 | |
| 130741 | 131308 | /* |
| 130742 | 131309 | ** Invoke the xFileControl method on a particular database. |
| 130743 | 131310 | */ |
| 130744 | | -SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){ |
| 131311 | +SQLITE_API int SQLITE_STDCALL sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){ |
| 130745 | 131312 | int rc = SQLITE_ERROR; |
| 130746 | 131313 | Btree *pBtree; |
| 130747 | 131314 | |
| 130748 | 131315 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 130749 | 131316 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| | @@ -130773,11 +131340,11 @@ |
| 130773 | 131340 | } |
| 130774 | 131341 | |
| 130775 | 131342 | /* |
| 130776 | 131343 | ** Interface to the testing logic. |
| 130777 | 131344 | */ |
| 130778 | | -SQLITE_API int sqlite3_test_control(int op, ...){ |
| 131345 | +SQLITE_API int SQLITE_CDECL sqlite3_test_control(int op, ...){ |
| 130779 | 131346 | int rc = 0; |
| 130780 | 131347 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 130781 | 131348 | va_list ap; |
| 130782 | 131349 | va_start(ap, op); |
| 130783 | 131350 | switch( op ){ |
| | @@ -131116,11 +131683,11 @@ |
| 131116 | 131683 | ** method of a VFS implementation. The zParam argument is the name of the |
| 131117 | 131684 | ** query parameter we seek. This routine returns the value of the zParam |
| 131118 | 131685 | ** parameter if it exists. If the parameter does not exist, this routine |
| 131119 | 131686 | ** returns a NULL pointer. |
| 131120 | 131687 | */ |
| 131121 | | -SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){ |
| 131688 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_uri_parameter(const char *zFilename, const char *zParam){ |
| 131122 | 131689 | if( zFilename==0 || zParam==0 ) return 0; |
| 131123 | 131690 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 131124 | 131691 | while( zFilename[0] ){ |
| 131125 | 131692 | int x = strcmp(zFilename, zParam); |
| 131126 | 131693 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| | @@ -131131,20 +131698,20 @@ |
| 131131 | 131698 | } |
| 131132 | 131699 | |
| 131133 | 131700 | /* |
| 131134 | 131701 | ** Return a boolean value for a query parameter. |
| 131135 | 131702 | */ |
| 131136 | | -SQLITE_API int sqlite3_uri_boolean(const char *zFilename, const char *zParam, int bDflt){ |
| 131703 | +SQLITE_API int SQLITE_STDCALL sqlite3_uri_boolean(const char *zFilename, const char *zParam, int bDflt){ |
| 131137 | 131704 | const char *z = sqlite3_uri_parameter(zFilename, zParam); |
| 131138 | 131705 | bDflt = bDflt!=0; |
| 131139 | 131706 | return z ? sqlite3GetBoolean(z, bDflt) : bDflt; |
| 131140 | 131707 | } |
| 131141 | 131708 | |
| 131142 | 131709 | /* |
| 131143 | 131710 | ** Return a 64-bit integer value for a query parameter. |
| 131144 | 131711 | */ |
| 131145 | | -SQLITE_API sqlite3_int64 sqlite3_uri_int64( |
| 131712 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64( |
| 131146 | 131713 | const char *zFilename, /* Filename as passed to xOpen */ |
| 131147 | 131714 | const char *zParam, /* URI parameter sought */ |
| 131148 | 131715 | sqlite3_int64 bDflt /* return if parameter is missing */ |
| 131149 | 131716 | ){ |
| 131150 | 131717 | const char *z = sqlite3_uri_parameter(zFilename, zParam); |
| | @@ -131172,11 +131739,11 @@ |
| 131172 | 131739 | |
| 131173 | 131740 | /* |
| 131174 | 131741 | ** Return the filename of the database associated with a database |
| 131175 | 131742 | ** connection. |
| 131176 | 131743 | */ |
| 131177 | | -SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){ |
| 131744 | +SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName){ |
| 131178 | 131745 | Btree *pBt; |
| 131179 | 131746 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 131180 | 131747 | if( !sqlite3SafetyCheckOk(db) ){ |
| 131181 | 131748 | (void)SQLITE_MISUSE_BKPT; |
| 131182 | 131749 | return 0; |
| | @@ -131188,11 +131755,11 @@ |
| 131188 | 131755 | |
| 131189 | 131756 | /* |
| 131190 | 131757 | ** Return 1 if database is read-only or 0 if read/write. Return -1 if |
| 131191 | 131758 | ** no such database exists. |
| 131192 | 131759 | */ |
| 131193 | | -SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){ |
| 131760 | +SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName){ |
| 131194 | 131761 | Btree *pBt; |
| 131195 | 131762 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 131196 | 131763 | if( !sqlite3SafetyCheckOk(db) ){ |
| 131197 | 131764 | (void)SQLITE_MISUSE_BKPT; |
| 131198 | 131765 | return -1; |
| | @@ -131347,11 +131914,11 @@ |
| 131347 | 131914 | ** |
| 131348 | 131915 | ** Each call to this routine overrides any prior callbacks registered |
| 131349 | 131916 | ** on the same "db". If xNotify==0 then any prior callbacks are immediately |
| 131350 | 131917 | ** cancelled. |
| 131351 | 131918 | */ |
| 131352 | | -SQLITE_API int sqlite3_unlock_notify( |
| 131919 | +SQLITE_API int SQLITE_STDCALL sqlite3_unlock_notify( |
| 131353 | 131920 | sqlite3 *db, |
| 131354 | 131921 | void (*xNotify)(void **, int), |
| 131355 | 131922 | void *pArg |
| 131356 | 131923 | ){ |
| 131357 | 131924 | int rc = SQLITE_OK; |
| | @@ -132241,10 +132808,15 @@ |
| 132241 | 132808 | ** false. |
| 132242 | 132809 | */ |
| 132243 | 132810 | #ifdef SQLITE_COVERAGE_TEST |
| 132244 | 132811 | # define ALWAYS(x) (1) |
| 132245 | 132812 | # define NEVER(X) (0) |
| 132813 | +#elif defined(SQLITE_DEBUG) |
| 132814 | +# define ALWAYS(x) sqlite3Fts3Always((x)!=0) |
| 132815 | +# define NEVER(x) sqlite3Fts3Never((x)!=0) |
| 132816 | +SQLITE_PRIVATE int sqlite3Fts3Always(int b); |
| 132817 | +SQLITE_PRIVATE int sqlite3Fts3Never(int b); |
| 132246 | 132818 | #else |
| 132247 | 132819 | # define ALWAYS(x) (x) |
| 132248 | 132820 | # define NEVER(x) (x) |
| 132249 | 132821 | #endif |
| 132250 | 132822 | |
| | @@ -132641,10 +133213,11 @@ |
| 132641 | 133213 | #define fts3GetVarint32(p, piVal) ( \ |
| 132642 | 133214 | (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \ |
| 132643 | 133215 | ) |
| 132644 | 133216 | |
| 132645 | 133217 | /* fts3.c */ |
| 133218 | +SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...); |
| 132646 | 133219 | SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64); |
| 132647 | 133220 | SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *); |
| 132648 | 133221 | SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *); |
| 132649 | 133222 | SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64); |
| 132650 | 133223 | SQLITE_PRIVATE void sqlite3Fts3Dequote(char *); |
| | @@ -132729,10 +133302,17 @@ |
| 132729 | 133302 | |
| 132730 | 133303 | static int fts3EvalNext(Fts3Cursor *pCsr); |
| 132731 | 133304 | static int fts3EvalStart(Fts3Cursor *pCsr); |
| 132732 | 133305 | static int fts3TermSegReaderCursor( |
| 132733 | 133306 | Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **); |
| 133307 | + |
| 133308 | +#ifndef SQLITE_AMALGAMATION |
| 133309 | +# if defined(SQLITE_DEBUG) |
| 133310 | +SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; } |
| 133311 | +SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; } |
| 133312 | +# endif |
| 133313 | +#endif |
| 132734 | 133314 | |
| 132735 | 133315 | /* |
| 132736 | 133316 | ** Write a 64-bit variable-length integer to memory starting at p[0]. |
| 132737 | 133317 | ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes. |
| 132738 | 133318 | ** The number of bytes written is returned. |
| | @@ -132839,11 +133419,11 @@ |
| 132839 | 133419 | int iOut = 0; /* Index of next byte to write to output */ |
| 132840 | 133420 | |
| 132841 | 133421 | /* If the first byte was a '[', then the close-quote character is a ']' */ |
| 132842 | 133422 | if( quote=='[' ) quote = ']'; |
| 132843 | 133423 | |
| 132844 | | - while( ALWAYS(z[iIn]) ){ |
| 133424 | + while( z[iIn] ){ |
| 132845 | 133425 | if( z[iIn]==quote ){ |
| 132846 | 133426 | if( z[iIn+1]!=quote ) break; |
| 132847 | 133427 | z[iOut++] = quote; |
| 132848 | 133428 | iIn += 2; |
| 132849 | 133429 | }else{ |
| | @@ -132917,10 +133497,21 @@ |
| 132917 | 133497 | p->pTokenizer->pModule->xDestroy(p->pTokenizer); |
| 132918 | 133498 | |
| 132919 | 133499 | sqlite3_free(p); |
| 132920 | 133500 | return SQLITE_OK; |
| 132921 | 133501 | } |
| 133502 | + |
| 133503 | +/* |
| 133504 | +** Write an error message into *pzErr |
| 133505 | +*/ |
| 133506 | +SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char **pzErr, const char *zFormat, ...){ |
| 133507 | + va_list ap; |
| 133508 | + sqlite3_free(*pzErr); |
| 133509 | + va_start(ap, zFormat); |
| 133510 | + *pzErr = sqlite3_vmprintf(zFormat, ap); |
| 133511 | + va_end(ap); |
| 133512 | +} |
| 132922 | 133513 | |
| 132923 | 133514 | /* |
| 132924 | 133515 | ** Construct one or more SQL statements from the format string given |
| 132925 | 133516 | ** and then evaluate those statements. The success code is written |
| 132926 | 133517 | ** into *pRc. |
| | @@ -133436,11 +134027,12 @@ |
| 133436 | 134027 | sqlite3 *db, /* Database handle */ |
| 133437 | 134028 | const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */ |
| 133438 | 134029 | const char *zTbl, /* Name of content table */ |
| 133439 | 134030 | const char ***pazCol, /* OUT: Malloc'd array of column names */ |
| 133440 | 134031 | int *pnCol, /* OUT: Size of array *pazCol */ |
| 133441 | | - int *pnStr /* OUT: Bytes of string content */ |
| 134032 | + int *pnStr, /* OUT: Bytes of string content */ |
| 134033 | + char **pzErr /* OUT: error message */ |
| 133442 | 134034 | ){ |
| 133443 | 134035 | int rc = SQLITE_OK; /* Return code */ |
| 133444 | 134036 | char *zSql; /* "SELECT *" statement on zTbl */ |
| 133445 | 134037 | sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */ |
| 133446 | 134038 | |
| | @@ -133447,10 +134039,13 @@ |
| 133447 | 134039 | zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl); |
| 133448 | 134040 | if( !zSql ){ |
| 133449 | 134041 | rc = SQLITE_NOMEM; |
| 133450 | 134042 | }else{ |
| 133451 | 134043 | rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0); |
| 134044 | + if( rc!=SQLITE_OK ){ |
| 134045 | + sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db)); |
| 134046 | + } |
| 133452 | 134047 | } |
| 133453 | 134048 | sqlite3_free(zSql); |
| 133454 | 134049 | |
| 133455 | 134050 | if( rc==SQLITE_OK ){ |
| 133456 | 134051 | const char **azCol; /* Output array */ |
| | @@ -133525,11 +134120,11 @@ |
| 133525 | 134120 | int nName; /* Bytes required to hold table name */ |
| 133526 | 134121 | int isFts4 = (argv[0][3]=='4'); /* True for FTS4, false for FTS3 */ |
| 133527 | 134122 | const char **aCol; /* Array of column names */ |
| 133528 | 134123 | sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */ |
| 133529 | 134124 | |
| 133530 | | - int nIndex; /* Size of aIndex[] array */ |
| 134125 | + int nIndex = 0; /* Size of aIndex[] array */ |
| 133531 | 134126 | struct Fts3Index *aIndex = 0; /* Array of indexes for this table */ |
| 133532 | 134127 | |
| 133533 | 134128 | /* The results of parsing supported FTS4 key=value options: */ |
| 133534 | 134129 | int bNoDocsize = 0; /* True to omit %_docsize table */ |
| 133535 | 134130 | int bDescIdx = 0; /* True to store descending indexes */ |
| | @@ -133613,17 +134208,17 @@ |
| 133613 | 134208 | if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){ |
| 133614 | 134209 | break; |
| 133615 | 134210 | } |
| 133616 | 134211 | } |
| 133617 | 134212 | if( iOpt==SizeofArray(aFts4Opt) ){ |
| 133618 | | - *pzErr = sqlite3_mprintf("unrecognized parameter: %s", z); |
| 134213 | + sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z); |
| 133619 | 134214 | rc = SQLITE_ERROR; |
| 133620 | 134215 | }else{ |
| 133621 | 134216 | switch( iOpt ){ |
| 133622 | 134217 | case 0: /* MATCHINFO */ |
| 133623 | 134218 | if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){ |
| 133624 | | - *pzErr = sqlite3_mprintf("unrecognized matchinfo: %s", zVal); |
| 134219 | + sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal); |
| 133625 | 134220 | rc = SQLITE_ERROR; |
| 133626 | 134221 | } |
| 133627 | 134222 | bNoDocsize = 1; |
| 133628 | 134223 | break; |
| 133629 | 134224 | |
| | @@ -133647,11 +134242,11 @@ |
| 133647 | 134242 | |
| 133648 | 134243 | case 4: /* ORDER */ |
| 133649 | 134244 | if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3)) |
| 133650 | 134245 | && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4)) |
| 133651 | 134246 | ){ |
| 133652 | | - *pzErr = sqlite3_mprintf("unrecognized order: %s", zVal); |
| 134247 | + sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal); |
| 133653 | 134248 | rc = SQLITE_ERROR; |
| 133654 | 134249 | } |
| 133655 | 134250 | bDescIdx = (zVal[0]=='d' || zVal[0]=='D'); |
| 133656 | 134251 | break; |
| 133657 | 134252 | |
| | @@ -133698,11 +134293,11 @@ |
| 133698 | 134293 | zCompress = 0; |
| 133699 | 134294 | zUncompress = 0; |
| 133700 | 134295 | if( nCol==0 ){ |
| 133701 | 134296 | sqlite3_free((void*)aCol); |
| 133702 | 134297 | aCol = 0; |
| 133703 | | - rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString); |
| 134298 | + rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr); |
| 133704 | 134299 | |
| 133705 | 134300 | /* If a languageid= option was specified, remove the language id |
| 133706 | 134301 | ** column from the aCol[] array. */ |
| 133707 | 134302 | if( rc==SQLITE_OK && zLanguageid ){ |
| 133708 | 134303 | int j; |
| | @@ -133733,11 +134328,11 @@ |
| 133733 | 134328 | assert( pTokenizer ); |
| 133734 | 134329 | |
| 133735 | 134330 | rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex); |
| 133736 | 134331 | if( rc==SQLITE_ERROR ){ |
| 133737 | 134332 | assert( zPrefix ); |
| 133738 | | - *pzErr = sqlite3_mprintf("error parsing prefix parameter: %s", zPrefix); |
| 134333 | + sqlite3Fts3ErrMsg(pzErr, "error parsing prefix parameter: %s", zPrefix); |
| 133739 | 134334 | } |
| 133740 | 134335 | if( rc!=SQLITE_OK ) goto fts3_init_out; |
| 133741 | 134336 | |
| 133742 | 134337 | /* Allocate and populate the Fts3Table structure. */ |
| 133743 | 134338 | nByte = sizeof(Fts3Table) + /* Fts3Table */ |
| | @@ -133815,19 +134410,19 @@ |
| 133815 | 134410 | } |
| 133816 | 134411 | } |
| 133817 | 134412 | } |
| 133818 | 134413 | for(i=0; i<nNotindexed; i++){ |
| 133819 | 134414 | if( azNotindexed[i] ){ |
| 133820 | | - *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]); |
| 134415 | + sqlite3Fts3ErrMsg(pzErr, "no such column: %s", azNotindexed[i]); |
| 133821 | 134416 | rc = SQLITE_ERROR; |
| 133822 | 134417 | } |
| 133823 | 134418 | } |
| 133824 | 134419 | |
| 133825 | 134420 | if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){ |
| 133826 | 134421 | char const *zMiss = (zCompress==0 ? "compress" : "uncompress"); |
| 133827 | 134422 | rc = SQLITE_ERROR; |
| 133828 | | - *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss); |
| 134423 | + sqlite3Fts3ErrMsg(pzErr, "missing %s parameter in fts4 constructor", zMiss); |
| 133829 | 134424 | } |
| 133830 | 134425 | p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc); |
| 133831 | 134426 | p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc); |
| 133832 | 134427 | if( rc!=SQLITE_OK ) goto fts3_init_out; |
| 133833 | 134428 | |
| | @@ -134919,30 +135514,37 @@ |
| 134919 | 135514 | ** parameter bDescDoclist should be false. If they are sorted in ascending |
| 134920 | 135515 | ** order, it should be passed a non-zero value. |
| 134921 | 135516 | ** |
| 134922 | 135517 | ** The right-hand input doclist is overwritten by this function. |
| 134923 | 135518 | */ |
| 134924 | | -static void fts3DoclistPhraseMerge( |
| 135519 | +static int fts3DoclistPhraseMerge( |
| 134925 | 135520 | int bDescDoclist, /* True if arguments are desc */ |
| 134926 | 135521 | int nDist, /* Distance from left to right (1=adjacent) */ |
| 134927 | 135522 | char *aLeft, int nLeft, /* Left doclist */ |
| 134928 | | - char *aRight, int *pnRight /* IN/OUT: Right/output doclist */ |
| 135523 | + char **paRight, int *pnRight /* IN/OUT: Right/output doclist */ |
| 134929 | 135524 | ){ |
| 134930 | 135525 | sqlite3_int64 i1 = 0; |
| 134931 | 135526 | sqlite3_int64 i2 = 0; |
| 134932 | 135527 | sqlite3_int64 iPrev = 0; |
| 135528 | + char *aRight = *paRight; |
| 134933 | 135529 | char *pEnd1 = &aLeft[nLeft]; |
| 134934 | 135530 | char *pEnd2 = &aRight[*pnRight]; |
| 134935 | 135531 | char *p1 = aLeft; |
| 134936 | 135532 | char *p2 = aRight; |
| 134937 | 135533 | char *p; |
| 134938 | 135534 | int bFirstOut = 0; |
| 134939 | | - char *aOut = aRight; |
| 135535 | + char *aOut; |
| 134940 | 135536 | |
| 134941 | 135537 | assert( nDist>0 ); |
| 134942 | | - |
| 135538 | + if( bDescDoclist ){ |
| 135539 | + aOut = sqlite3_malloc(*pnRight + FTS3_VARINT_MAX); |
| 135540 | + if( aOut==0 ) return SQLITE_NOMEM; |
| 135541 | + }else{ |
| 135542 | + aOut = aRight; |
| 135543 | + } |
| 134943 | 135544 | p = aOut; |
| 135545 | + |
| 134944 | 135546 | fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1); |
| 134945 | 135547 | fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2); |
| 134946 | 135548 | |
| 134947 | 135549 | while( p1 && p2 ){ |
| 134948 | 135550 | sqlite3_int64 iDiff = DOCID_CMP(i1, i2); |
| | @@ -134967,10 +135569,16 @@ |
| 134967 | 135569 | fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2); |
| 134968 | 135570 | } |
| 134969 | 135571 | } |
| 134970 | 135572 | |
| 134971 | 135573 | *pnRight = (int)(p - aOut); |
| 135574 | + if( bDescDoclist ){ |
| 135575 | + sqlite3_free(aRight); |
| 135576 | + *paRight = aOut; |
| 135577 | + } |
| 135578 | + |
| 135579 | + return SQLITE_OK; |
| 134972 | 135580 | } |
| 134973 | 135581 | |
| 134974 | 135582 | /* |
| 134975 | 135583 | ** Argument pList points to a position list nList bytes in size. This |
| 134976 | 135584 | ** function checks to see if the position list contains any entries for |
| | @@ -135091,12 +135699,26 @@ |
| 135091 | 135699 | char *aDoclist, /* Pointer to doclist */ |
| 135092 | 135700 | int nDoclist /* Size of aDoclist in bytes */ |
| 135093 | 135701 | ){ |
| 135094 | 135702 | if( pTS->aaOutput[0]==0 ){ |
| 135095 | 135703 | /* If this is the first term selected, copy the doclist to the output |
| 135096 | | - ** buffer using memcpy(). */ |
| 135097 | | - pTS->aaOutput[0] = sqlite3_malloc(nDoclist); |
| 135704 | + ** buffer using memcpy(). |
| 135705 | + ** |
| 135706 | + ** Add FTS3_VARINT_MAX bytes of unused space to the end of the |
| 135707 | + ** allocation. This is so as to ensure that the buffer is big enough |
| 135708 | + ** to hold the current doclist AND'd with any other doclist. If the |
| 135709 | + ** doclists are stored in order=ASC order, this padding would not be |
| 135710 | + ** required (since the size of [doclistA AND doclistB] is always less |
| 135711 | + ** than or equal to the size of [doclistA] in that case). But this is |
| 135712 | + ** not true for order=DESC. For example, a doclist containing (1, -1) |
| 135713 | + ** may be smaller than (-1), as in the first example the -1 may be stored |
| 135714 | + ** as a single-byte delta, whereas in the second it must be stored as a |
| 135715 | + ** FTS3_VARINT_MAX byte varint. |
| 135716 | + ** |
| 135717 | + ** Similar padding is added in the fts3DoclistOrMerge() function. |
| 135718 | + */ |
| 135719 | + pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1); |
| 135098 | 135720 | pTS->anOutput[0] = nDoclist; |
| 135099 | 135721 | if( pTS->aaOutput[0] ){ |
| 135100 | 135722 | memcpy(pTS->aaOutput[0], aDoclist, nDoclist); |
| 135101 | 135723 | }else{ |
| 135102 | 135724 | return SQLITE_NOMEM; |
| | @@ -135189,11 +135811,11 @@ |
| 135189 | 135811 | ** Fts3SegReaderPending might segfault, as the data structures used by |
| 135190 | 135812 | ** fts4aux are not completely populated. So it's easiest to filter these |
| 135191 | 135813 | ** calls out here. */ |
| 135192 | 135814 | if( iLevel<0 && p->aIndex ){ |
| 135193 | 135815 | Fts3SegReader *pSeg = 0; |
| 135194 | | - rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix, &pSeg); |
| 135816 | + rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg); |
| 135195 | 135817 | if( rc==SQLITE_OK && pSeg ){ |
| 135196 | 135818 | rc = fts3SegReaderCursorAppend(pCsr, pSeg); |
| 135197 | 135819 | } |
| 135198 | 135820 | } |
| 135199 | 135821 | |
| | @@ -135838,15 +136460,35 @@ |
| 135838 | 136460 | */ |
| 135839 | 136461 | static void fts3ReversePoslist(char *pStart, char **ppPoslist){ |
| 135840 | 136462 | char *p = &(*ppPoslist)[-2]; |
| 135841 | 136463 | char c = 0; |
| 135842 | 136464 | |
| 136465 | + /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */ |
| 135843 | 136466 | while( p>pStart && (c=*p--)==0 ); |
| 136467 | + |
| 136468 | + /* Search backwards for a varint with value zero (the end of the previous |
| 136469 | + ** poslist). This is an 0x00 byte preceded by some byte that does not |
| 136470 | + ** have the 0x80 bit set. */ |
| 135844 | 136471 | while( p>pStart && (*p & 0x80) | c ){ |
| 135845 | 136472 | c = *p--; |
| 135846 | 136473 | } |
| 135847 | | - if( p>pStart ){ p = &p[2]; } |
| 136474 | + assert( p==pStart || c==0 ); |
| 136475 | + |
| 136476 | + /* At this point p points to that preceding byte without the 0x80 bit |
| 136477 | + ** set. So to find the start of the poslist, skip forward 2 bytes then |
| 136478 | + ** over a varint. |
| 136479 | + ** |
| 136480 | + ** Normally. The other case is that p==pStart and the poslist to return |
| 136481 | + ** is the first in the doclist. In this case do not skip forward 2 bytes. |
| 136482 | + ** The second part of the if condition (c==0 && *ppPoslist>&p[2]) |
| 136483 | + ** is required for cases where the first byte of a doclist and the |
| 136484 | + ** doclist is empty. For example, if the first docid is 10, a doclist |
| 136485 | + ** that begins with: |
| 136486 | + ** |
| 136487 | + ** 0x0A 0x00 <next docid delta varint> |
| 136488 | + */ |
| 136489 | + if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; } |
| 135848 | 136490 | while( *p++&0x80 ); |
| 135849 | 136491 | *ppPoslist = p; |
| 135850 | 136492 | } |
| 135851 | 136493 | |
| 135852 | 136494 | /* |
| | @@ -135913,10 +136555,12 @@ |
| 135913 | 136555 | case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]); |
| 135914 | 136556 | case 2: zStart = (const char*)sqlite3_value_text(apVal[1]); |
| 135915 | 136557 | } |
| 135916 | 136558 | if( !zEllipsis || !zEnd || !zStart ){ |
| 135917 | 136559 | sqlite3_result_error_nomem(pContext); |
| 136560 | + }else if( nToken==0 ){ |
| 136561 | + sqlite3_result_text(pContext, "", -1, SQLITE_STATIC); |
| 135918 | 136562 | }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){ |
| 135919 | 136563 | sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken); |
| 135920 | 136564 | } |
| 135921 | 136565 | } |
| 135922 | 136566 | |
| | @@ -136348,18 +136992,21 @@ |
| 136348 | 136992 | ** It is merged into the main doclist stored in p->doclist.aAll/nAll. |
| 136349 | 136993 | ** |
| 136350 | 136994 | ** This function assumes that pList points to a buffer allocated using |
| 136351 | 136995 | ** sqlite3_malloc(). This function takes responsibility for eventually |
| 136352 | 136996 | ** freeing the buffer. |
| 136997 | +** |
| 136998 | +** SQLITE_OK is returned if successful, or SQLITE_NOMEM if an error occurs. |
| 136353 | 136999 | */ |
| 136354 | | -static void fts3EvalPhraseMergeToken( |
| 137000 | +static int fts3EvalPhraseMergeToken( |
| 136355 | 137001 | Fts3Table *pTab, /* FTS Table pointer */ |
| 136356 | 137002 | Fts3Phrase *p, /* Phrase to merge pList/nList into */ |
| 136357 | 137003 | int iToken, /* Token pList/nList corresponds to */ |
| 136358 | 137004 | char *pList, /* Pointer to doclist */ |
| 136359 | 137005 | int nList /* Number of bytes in pList */ |
| 136360 | 137006 | ){ |
| 137007 | + int rc = SQLITE_OK; |
| 136361 | 137008 | assert( iToken!=p->iDoclistToken ); |
| 136362 | 137009 | |
| 136363 | 137010 | if( pList==0 ){ |
| 136364 | 137011 | sqlite3_free(p->doclist.aAll); |
| 136365 | 137012 | p->doclist.aAll = 0; |
| | @@ -136394,17 +137041,20 @@ |
| 136394 | 137041 | pLeft = pList; |
| 136395 | 137042 | nLeft = nList; |
| 136396 | 137043 | nDiff = p->iDoclistToken - iToken; |
| 136397 | 137044 | } |
| 136398 | 137045 | |
| 136399 | | - fts3DoclistPhraseMerge(pTab->bDescIdx, nDiff, pLeft, nLeft, pRight,&nRight); |
| 137046 | + rc = fts3DoclistPhraseMerge( |
| 137047 | + pTab->bDescIdx, nDiff, pLeft, nLeft, &pRight, &nRight |
| 137048 | + ); |
| 136400 | 137049 | sqlite3_free(pLeft); |
| 136401 | 137050 | p->doclist.aAll = pRight; |
| 136402 | 137051 | p->doclist.nAll = nRight; |
| 136403 | 137052 | } |
| 136404 | 137053 | |
| 136405 | 137054 | if( iToken>p->iDoclistToken ) p->iDoclistToken = iToken; |
| 137055 | + return rc; |
| 136406 | 137056 | } |
| 136407 | 137057 | |
| 136408 | 137058 | /* |
| 136409 | 137059 | ** Load the doclist for phrase p into p->doclist.aAll/nAll. The loaded doclist |
| 136410 | 137060 | ** does not take deferred tokens into account. |
| | @@ -136426,11 +137076,11 @@ |
| 136426 | 137076 | if( pToken->pSegcsr ){ |
| 136427 | 137077 | int nThis = 0; |
| 136428 | 137078 | char *pThis = 0; |
| 136429 | 137079 | rc = fts3TermSelect(pTab, pToken, p->iColumn, &nThis, &pThis); |
| 136430 | 137080 | if( rc==SQLITE_OK ){ |
| 136431 | | - fts3EvalPhraseMergeToken(pTab, p, iToken, pThis, nThis); |
| 137081 | + rc = fts3EvalPhraseMergeToken(pTab, p, iToken, pThis, nThis); |
| 136432 | 137082 | } |
| 136433 | 137083 | } |
| 136434 | 137084 | assert( pToken->pSegcsr==0 ); |
| 136435 | 137085 | } |
| 136436 | 137086 | |
| | @@ -136968,16 +137618,18 @@ |
| 136968 | 137618 | Fts3Expr *pExpr, /* Expression to initialize phrases in */ |
| 136969 | 137619 | int *pRc /* IN/OUT: Error code */ |
| 136970 | 137620 | ){ |
| 136971 | 137621 | if( pExpr && SQLITE_OK==*pRc ){ |
| 136972 | 137622 | if( pExpr->eType==FTSQUERY_PHRASE ){ |
| 136973 | | - int i; |
| 136974 | 137623 | int nToken = pExpr->pPhrase->nToken; |
| 136975 | | - for(i=0; i<nToken; i++){ |
| 136976 | | - if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break; |
| 137624 | + if( nToken ){ |
| 137625 | + int i; |
| 137626 | + for(i=0; i<nToken; i++){ |
| 137627 | + if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break; |
| 137628 | + } |
| 137629 | + pExpr->bDeferred = (i==nToken); |
| 136977 | 137630 | } |
| 136978 | | - pExpr->bDeferred = (i==nToken); |
| 136979 | 137631 | *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase); |
| 136980 | 137632 | }else{ |
| 136981 | 137633 | fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc); |
| 136982 | 137634 | fts3EvalStartReaders(pCsr, pExpr->pRight, pRc); |
| 136983 | 137635 | pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred); |
| | @@ -137228,13 +137880,17 @@ |
| 137228 | 137880 | Fts3PhraseToken *pToken = pTC->pToken; |
| 137229 | 137881 | int nList = 0; |
| 137230 | 137882 | char *pList = 0; |
| 137231 | 137883 | rc = fts3TermSelect(pTab, pToken, pTC->iCol, &nList, &pList); |
| 137232 | 137884 | assert( rc==SQLITE_OK || pList==0 ); |
| 137885 | + if( rc==SQLITE_OK ){ |
| 137886 | + rc = fts3EvalPhraseMergeToken( |
| 137887 | + pTab, pTC->pPhrase, pTC->iToken,pList,nList |
| 137888 | + ); |
| 137889 | + } |
| 137233 | 137890 | if( rc==SQLITE_OK ){ |
| 137234 | 137891 | int nCount; |
| 137235 | | - fts3EvalPhraseMergeToken(pTab, pTC->pPhrase, pTC->iToken,pList,nList); |
| 137236 | 137892 | nCount = fts3DoclistCountDocids( |
| 137237 | 137893 | pTC->pPhrase->doclist.aAll, pTC->pPhrase->doclist.nAll |
| 137238 | 137894 | ); |
| 137239 | 137895 | if( ii==0 || nCount<nMinEst ) nMinEst = nCount; |
| 137240 | 137896 | } |
| | @@ -138132,11 +138788,12 @@ |
| 138132 | 138788 | if( rc!=SQLITE_OK ) return rc; |
| 138133 | 138789 | |
| 138134 | 138790 | pIter = pPhrase->pOrPoslist; |
| 138135 | 138791 | iDocid = pPhrase->iOrDocid; |
| 138136 | 138792 | if( pCsr->bDesc==bDescDoclist ){ |
| 138137 | | - bEof = (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll)); |
| 138793 | + bEof = !pPhrase->doclist.nAll || |
| 138794 | + (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll)); |
| 138138 | 138795 | while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ |
| 138139 | 138796 | sqlite3Fts3DoclistNext( |
| 138140 | 138797 | bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, |
| 138141 | 138798 | &pIter, &iDocid, &bEof |
| 138142 | 138799 | ); |
| | @@ -138213,11 +138870,11 @@ |
| 138213 | 138870 | ** Initialize API pointer table, if required. |
| 138214 | 138871 | */ |
| 138215 | 138872 | #ifdef _WIN32 |
| 138216 | 138873 | __declspec(dllexport) |
| 138217 | 138874 | #endif |
| 138218 | | -SQLITE_API int sqlite3_fts3_init( |
| 138875 | +SQLITE_API int SQLITE_STDCALL sqlite3_fts3_init( |
| 138219 | 138876 | sqlite3 *db, |
| 138220 | 138877 | char **pzErrMsg, |
| 138221 | 138878 | const sqlite3_api_routines *pApi |
| 138222 | 138879 | ){ |
| 138223 | 138880 | SQLITE_EXTENSION_INIT2(pApi) |
| | @@ -138344,11 +139001,11 @@ |
| 138344 | 139001 | |
| 138345 | 139002 | *ppVtab = (sqlite3_vtab *)p; |
| 138346 | 139003 | return SQLITE_OK; |
| 138347 | 139004 | |
| 138348 | 139005 | bad_args: |
| 138349 | | - *pzErr = sqlite3_mprintf("invalid arguments to fts4aux constructor"); |
| 139006 | + sqlite3Fts3ErrMsg(pzErr, "invalid arguments to fts4aux constructor"); |
| 138350 | 139007 | return SQLITE_ERROR; |
| 138351 | 139008 | } |
| 138352 | 139009 | |
| 138353 | 139010 | /* |
| 138354 | 139011 | ** This function does the work for both the xDisconnect and xDestroy methods. |
| | @@ -139802,17 +140459,17 @@ |
| 139802 | 140459 | |
| 139803 | 140460 | if( rc!=SQLITE_OK ){ |
| 139804 | 140461 | sqlite3Fts3ExprFree(*ppExpr); |
| 139805 | 140462 | *ppExpr = 0; |
| 139806 | 140463 | if( rc==SQLITE_TOOBIG ){ |
| 139807 | | - *pzErr = sqlite3_mprintf( |
| 140464 | + sqlite3Fts3ErrMsg(pzErr, |
| 139808 | 140465 | "FTS expression tree is too large (maximum depth %d)", |
| 139809 | 140466 | SQLITE_FTS3_MAX_EXPR_DEPTH |
| 139810 | 140467 | ); |
| 139811 | 140468 | rc = SQLITE_ERROR; |
| 139812 | 140469 | }else if( rc==SQLITE_ERROR ){ |
| 139813 | | - *pzErr = sqlite3_mprintf("malformed MATCH expression: [%s]", z); |
| 140470 | + sqlite3Fts3ErrMsg(pzErr, "malformed MATCH expression: [%s]", z); |
| 139814 | 140471 | } |
| 139815 | 140472 | } |
| 139816 | 140473 | |
| 139817 | 140474 | return rc; |
| 139818 | 140475 | } |
| | @@ -141284,11 +141941,11 @@ |
| 141284 | 141941 | z[n] = '\0'; |
| 141285 | 141942 | sqlite3Fts3Dequote(z); |
| 141286 | 141943 | |
| 141287 | 141944 | m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1); |
| 141288 | 141945 | if( !m ){ |
| 141289 | | - *pzErr = sqlite3_mprintf("unknown tokenizer: %s", z); |
| 141946 | + sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", z); |
| 141290 | 141947 | rc = SQLITE_ERROR; |
| 141291 | 141948 | }else{ |
| 141292 | 141949 | char const **aArg = 0; |
| 141293 | 141950 | int iArg = 0; |
| 141294 | 141951 | z = &z[n+1]; |
| | @@ -141307,11 +141964,11 @@ |
| 141307 | 141964 | z = &z[n+1]; |
| 141308 | 141965 | } |
| 141309 | 141966 | rc = m->xCreate(iArg, aArg, ppTok); |
| 141310 | 141967 | assert( rc!=SQLITE_OK || *ppTok ); |
| 141311 | 141968 | if( rc!=SQLITE_OK ){ |
| 141312 | | - *pzErr = sqlite3_mprintf("unknown tokenizer"); |
| 141969 | + sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer"); |
| 141313 | 141970 | }else{ |
| 141314 | 141971 | (*ppTok)->pModule = m; |
| 141315 | 141972 | } |
| 141316 | 141973 | sqlite3_free((void *)aArg); |
| 141317 | 141974 | } |
| | @@ -141391,13 +142048,13 @@ |
| 141391 | 142048 | |
| 141392 | 142049 | pHash = (Fts3Hash *)sqlite3_user_data(context); |
| 141393 | 142050 | p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1); |
| 141394 | 142051 | |
| 141395 | 142052 | if( !p ){ |
| 141396 | | - char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName); |
| 141397 | | - sqlite3_result_error(context, zErr, -1); |
| 141398 | | - sqlite3_free(zErr); |
| 142053 | + char *zErr2 = sqlite3_mprintf("unknown tokenizer: %s", zName); |
| 142054 | + sqlite3_result_error(context, zErr2, -1); |
| 142055 | + sqlite3_free(zErr2); |
| 141399 | 142056 | return; |
| 141400 | 142057 | } |
| 141401 | 142058 | |
| 141402 | 142059 | pRet = Tcl_NewObj(); |
| 141403 | 142060 | Tcl_IncrRefCount(pRet); |
| | @@ -141928,11 +142585,11 @@ |
| 141928 | 142585 | sqlite3_tokenizer_module *p; |
| 141929 | 142586 | int nName = (int)strlen(zName); |
| 141930 | 142587 | |
| 141931 | 142588 | p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1); |
| 141932 | 142589 | if( !p ){ |
| 141933 | | - *pzErr = sqlite3_mprintf("unknown tokenizer: %s", zName); |
| 142590 | + sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", zName); |
| 141934 | 142591 | return SQLITE_ERROR; |
| 141935 | 142592 | } |
| 141936 | 142593 | |
| 141937 | 142594 | *pp = p; |
| 141938 | 142595 | return SQLITE_OK; |
| | @@ -142625,11 +143282,11 @@ |
| 142625 | 143282 | /* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)", |
| 142626 | 143283 | /* 24 */ "", |
| 142627 | 143284 | /* 25 */ "", |
| 142628 | 143285 | |
| 142629 | 143286 | /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?", |
| 142630 | | -/* 27 */ "SELECT DISTINCT level / (1024 * ?) FROM %Q.'%q_segdir'", |
| 143287 | +/* 27 */ "SELECT ? UNION SELECT level / (1024 * ?) FROM %Q.'%q_segdir'", |
| 142631 | 143288 | |
| 142632 | 143289 | /* This statement is used to determine which level to read the input from |
| 142633 | 143290 | ** when performing an incremental merge. It returns the absolute level number |
| 142634 | 143291 | ** of the oldest level in the db that contains at least ? segments. Or, |
| 142635 | 143292 | ** if no level in the FTS index contains more than ? segments, the statement |
| | @@ -145743,11 +146400,12 @@ |
| 145743 | 146400 | sqlite3_stmt *pAllLangid = 0; |
| 145744 | 146401 | |
| 145745 | 146402 | rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 145746 | 146403 | if( rc==SQLITE_OK ){ |
| 145747 | 146404 | int rc2; |
| 145748 | | - sqlite3_bind_int(pAllLangid, 1, p->nIndex); |
| 146405 | + sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid); |
| 146406 | + sqlite3_bind_int(pAllLangid, 2, p->nIndex); |
| 145749 | 146407 | while( sqlite3_step(pAllLangid)==SQLITE_ROW ){ |
| 145750 | 146408 | int i; |
| 145751 | 146409 | int iLangid = sqlite3_column_int(pAllLangid, 0); |
| 145752 | 146410 | for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){ |
| 145753 | 146411 | rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL); |
| | @@ -147075,11 +147733,11 @@ |
| 147075 | 147733 | while( i>0 && (pHint->a[i-1] & 0x80) ) i--; |
| 147076 | 147734 | |
| 147077 | 147735 | pHint->n = i; |
| 147078 | 147736 | i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel); |
| 147079 | 147737 | i += fts3GetVarint32(&pHint->a[i], pnInput); |
| 147080 | | - if( i!=nHint ) return SQLITE_CORRUPT_VTAB; |
| 147738 | + if( i!=nHint ) return FTS_CORRUPT_VTAB; |
| 147081 | 147739 | |
| 147082 | 147740 | return SQLITE_OK; |
| 147083 | 147741 | } |
| 147084 | 147742 | |
| 147085 | 147743 | |
| | @@ -147443,11 +148101,12 @@ |
| 147443 | 148101 | |
| 147444 | 148102 | /* This block calculates the checksum according to the FTS index. */ |
| 147445 | 148103 | rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 147446 | 148104 | if( rc==SQLITE_OK ){ |
| 147447 | 148105 | int rc2; |
| 147448 | | - sqlite3_bind_int(pAllLangid, 1, p->nIndex); |
| 148106 | + sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid); |
| 148107 | + sqlite3_bind_int(pAllLangid, 2, p->nIndex); |
| 147449 | 148108 | while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){ |
| 147450 | 148109 | int iLangid = sqlite3_column_int(pAllLangid, 0); |
| 147451 | 148110 | int i; |
| 147452 | 148111 | for(i=0; i<p->nIndex; i++){ |
| 147453 | 148112 | cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc); |
| | @@ -147456,11 +148115,10 @@ |
| 147456 | 148115 | rc2 = sqlite3_reset(pAllLangid); |
| 147457 | 148116 | if( rc==SQLITE_OK ) rc = rc2; |
| 147458 | 148117 | } |
| 147459 | 148118 | |
| 147460 | 148119 | /* This block calculates the checksum according to the %_content table */ |
| 147461 | | - rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0); |
| 147462 | 148120 | if( rc==SQLITE_OK ){ |
| 147463 | 148121 | sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule; |
| 147464 | 148122 | sqlite3_stmt *pStmt = 0; |
| 147465 | 148123 | char *zSql; |
| 147466 | 148124 | |
| | @@ -147553,11 +148211,11 @@ |
| 147553 | 148211 | Fts3Table *p /* FTS3 table handle */ |
| 147554 | 148212 | ){ |
| 147555 | 148213 | int rc; |
| 147556 | 148214 | int bOk = 0; |
| 147557 | 148215 | rc = fts3IntegrityCheck(p, &bOk); |
| 147558 | | - if( rc==SQLITE_OK && bOk==0 ) rc = SQLITE_CORRUPT_VTAB; |
| 148216 | + if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB; |
| 147559 | 148217 | return rc; |
| 147560 | 148218 | } |
| 147561 | 148219 | |
| 147562 | 148220 | /* |
| 147563 | 148221 | ** Handle a 'special' INSERT of the form: |
| | @@ -147991,10 +148649,11 @@ |
| 147991 | 148649 | #define FTS3_MATCHINFO_NDOC 'n' /* 1 value */ |
| 147992 | 148650 | #define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */ |
| 147993 | 148651 | #define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */ |
| 147994 | 148652 | #define FTS3_MATCHINFO_LCS 's' /* nCol values */ |
| 147995 | 148653 | #define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */ |
| 148654 | +#define FTS3_MATCHINFO_LHITS 'y' /* nCol*nPhrase values */ |
| 147996 | 148655 | |
| 147997 | 148656 | /* |
| 147998 | 148657 | ** The default value for the second argument to matchinfo(). |
| 147999 | 148658 | */ |
| 148000 | 148659 | #define FTS3_MATCHINFO_DEFAULT "pcx" |
| | @@ -148772,10 +149431,55 @@ |
| 148772 | 149431 | } |
| 148773 | 149432 | } |
| 148774 | 149433 | |
| 148775 | 149434 | return rc; |
| 148776 | 149435 | } |
| 149436 | + |
| 149437 | +/* |
| 149438 | +** fts3ExprIterate() callback used to gather information for the matchinfo |
| 149439 | +** directive 'y'. |
| 149440 | +*/ |
| 149441 | +static int fts3ExprLHitsCb( |
| 149442 | + Fts3Expr *pExpr, /* Phrase expression node */ |
| 149443 | + int iPhrase, /* Phrase number */ |
| 149444 | + void *pCtx /* Pointer to MatchInfo structure */ |
| 149445 | +){ |
| 149446 | + MatchInfo *p = (MatchInfo *)pCtx; |
| 149447 | + Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab; |
| 149448 | + int rc = SQLITE_OK; |
| 149449 | + int iStart = iPhrase * p->nCol; |
| 149450 | + Fts3Expr *pEof; /* Ancestor node already at EOF */ |
| 149451 | + |
| 149452 | + /* This must be a phrase */ |
| 149453 | + assert( pExpr->pPhrase ); |
| 149454 | + |
| 149455 | + /* Initialize all output integers to zero. */ |
| 149456 | + memset(&p->aMatchinfo[iStart], 0, sizeof(u32) * p->nCol); |
| 149457 | + |
| 149458 | + /* Check if this or any parent node is at EOF. If so, then all output |
| 149459 | + ** values are zero. */ |
| 149460 | + for(pEof=pExpr; pEof && pEof->bEof==0; pEof=pEof->pParent); |
| 149461 | + |
| 149462 | + if( pEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){ |
| 149463 | + Fts3Phrase *pPhrase = pExpr->pPhrase; |
| 149464 | + char *pIter = pPhrase->doclist.pList; |
| 149465 | + int iCol = 0; |
| 149466 | + |
| 149467 | + while( 1 ){ |
| 149468 | + int nHit = fts3ColumnlistCount(&pIter); |
| 149469 | + if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){ |
| 149470 | + p->aMatchinfo[iStart + iCol] = (u32)nHit; |
| 149471 | + } |
| 149472 | + assert( *pIter==0x00 || *pIter==0x01 ); |
| 149473 | + if( *pIter!=0x01 ) break; |
| 149474 | + pIter++; |
| 149475 | + pIter += fts3GetVarint32(pIter, &iCol); |
| 149476 | + } |
| 149477 | + } |
| 149478 | + |
| 149479 | + return rc; |
| 149480 | +} |
| 148777 | 149481 | |
| 148778 | 149482 | static int fts3MatchinfoCheck( |
| 148779 | 149483 | Fts3Table *pTab, |
| 148780 | 149484 | char cArg, |
| 148781 | 149485 | char **pzErr |
| | @@ -148785,14 +149489,15 @@ |
| 148785 | 149489 | || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4) |
| 148786 | 149490 | || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4) |
| 148787 | 149491 | || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize) |
| 148788 | 149492 | || (cArg==FTS3_MATCHINFO_LCS) |
| 148789 | 149493 | || (cArg==FTS3_MATCHINFO_HITS) |
| 149494 | + || (cArg==FTS3_MATCHINFO_LHITS) |
| 148790 | 149495 | ){ |
| 148791 | 149496 | return SQLITE_OK; |
| 148792 | 149497 | } |
| 148793 | | - *pzErr = sqlite3_mprintf("unrecognized matchinfo request: %c", cArg); |
| 149498 | + sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg); |
| 148794 | 149499 | return SQLITE_ERROR; |
| 148795 | 149500 | } |
| 148796 | 149501 | |
| 148797 | 149502 | static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){ |
| 148798 | 149503 | int nVal; /* Number of integers output by cArg */ |
| | @@ -148807,10 +149512,14 @@ |
| 148807 | 149512 | case FTS3_MATCHINFO_AVGLENGTH: |
| 148808 | 149513 | case FTS3_MATCHINFO_LENGTH: |
| 148809 | 149514 | case FTS3_MATCHINFO_LCS: |
| 148810 | 149515 | nVal = pInfo->nCol; |
| 148811 | 149516 | break; |
| 149517 | + |
| 149518 | + case FTS3_MATCHINFO_LHITS: |
| 149519 | + nVal = pInfo->nCol * pInfo->nPhrase; |
| 149520 | + break; |
| 148812 | 149521 | |
| 148813 | 149522 | default: |
| 148814 | 149523 | assert( cArg==FTS3_MATCHINFO_HITS ); |
| 148815 | 149524 | nVal = pInfo->nCol * pInfo->nPhrase * 3; |
| 148816 | 149525 | break; |
| | @@ -149061,10 +149770,14 @@ |
| 149061 | 149770 | rc = fts3ExprLoadDoclists(pCsr, 0, 0); |
| 149062 | 149771 | if( rc==SQLITE_OK ){ |
| 149063 | 149772 | rc = fts3MatchinfoLcs(pCsr, pInfo); |
| 149064 | 149773 | } |
| 149065 | 149774 | break; |
| 149775 | + |
| 149776 | + case FTS3_MATCHINFO_LHITS: |
| 149777 | + (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLHitsCb, (void*)pInfo); |
| 149778 | + break; |
| 149066 | 149779 | |
| 149067 | 149780 | default: { |
| 149068 | 149781 | Fts3Expr *pExpr; |
| 149069 | 149782 | assert( zArg[i]==FTS3_MATCHINFO_HITS ); |
| 149070 | 149783 | pExpr = pCsr->pExpr; |
| | @@ -153074,15 +153787,23 @@ |
| 153074 | 153787 | ** conflict-handling mode specified by the user. |
| 153075 | 153788 | */ |
| 153076 | 153789 | if( nData>1 ){ |
| 153077 | 153790 | int ii; |
| 153078 | 153791 | |
| 153079 | | - /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */ |
| 153080 | | - assert( nData==(pRtree->nDim*2 + 3) ); |
| 153792 | + /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. |
| 153793 | + ** |
| 153794 | + ** NB: nData can only be less than nDim*2+3 if the rtree is mis-declared |
| 153795 | + ** with "column" that are interpreted as table constraints. |
| 153796 | + ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5)); |
| 153797 | + ** This problem was discovered after years of use, so we silently ignore |
| 153798 | + ** these kinds of misdeclared tables to avoid breaking any legacy. |
| 153799 | + */ |
| 153800 | + assert( nData<=(pRtree->nDim*2 + 3) ); |
| 153801 | + |
| 153081 | 153802 | #ifndef SQLITE_RTREE_INT_ONLY |
| 153082 | 153803 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 153083 | | - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ |
| 153804 | + for(ii=0; ii<nData-4; ii+=2){ |
| 153084 | 153805 | cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]); |
| 153085 | 153806 | cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]); |
| 153086 | 153807 | if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){ |
| 153087 | 153808 | rc = SQLITE_CONSTRAINT; |
| 153088 | 153809 | goto constraint; |
| | @@ -153089,11 +153810,11 @@ |
| 153089 | 153810 | } |
| 153090 | 153811 | } |
| 153091 | 153812 | }else |
| 153092 | 153813 | #endif |
| 153093 | 153814 | { |
| 153094 | | - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ |
| 153815 | + for(ii=0; ii<nData-4; ii+=2){ |
| 153095 | 153816 | cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]); |
| 153096 | 153817 | cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]); |
| 153097 | 153818 | if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){ |
| 153098 | 153819 | rc = SQLITE_CONSTRAINT; |
| 153099 | 153820 | goto constraint; |
| | @@ -153660,11 +154381,11 @@ |
| 153660 | 154381 | } |
| 153661 | 154382 | |
| 153662 | 154383 | /* |
| 153663 | 154384 | ** Register a new geometry function for use with the r-tree MATCH operator. |
| 153664 | 154385 | */ |
| 153665 | | -SQLITE_API int sqlite3_rtree_geometry_callback( |
| 154386 | +SQLITE_API int SQLITE_STDCALL sqlite3_rtree_geometry_callback( |
| 153666 | 154387 | sqlite3 *db, /* Register SQL function on this connection */ |
| 153667 | 154388 | const char *zGeom, /* Name of the new SQL function */ |
| 153668 | 154389 | int (*xGeom)(sqlite3_rtree_geometry*,int,RtreeDValue*,int*), /* Callback */ |
| 153669 | 154390 | void *pContext /* Extra data associated with the callback */ |
| 153670 | 154391 | ){ |
| | @@ -153684,11 +154405,11 @@ |
| 153684 | 154405 | |
| 153685 | 154406 | /* |
| 153686 | 154407 | ** Register a new 2nd-generation geometry function for use with the |
| 153687 | 154408 | ** r-tree MATCH operator. |
| 153688 | 154409 | */ |
| 153689 | | -SQLITE_API int sqlite3_rtree_query_callback( |
| 154410 | +SQLITE_API int SQLITE_STDCALL sqlite3_rtree_query_callback( |
| 153690 | 154411 | sqlite3 *db, /* Register SQL function on this connection */ |
| 153691 | 154412 | const char *zQueryFunc, /* Name of new SQL function */ |
| 153692 | 154413 | int (*xQueryFunc)(sqlite3_rtree_query_info*), /* Callback */ |
| 153693 | 154414 | void *pContext, /* Extra data passed into the callback */ |
| 153694 | 154415 | void (*xDestructor)(void*) /* Destructor for the extra data */ |
| | @@ -153709,11 +154430,11 @@ |
| 153709 | 154430 | |
| 153710 | 154431 | #if !SQLITE_CORE |
| 153711 | 154432 | #ifdef _WIN32 |
| 153712 | 154433 | __declspec(dllexport) |
| 153713 | 154434 | #endif |
| 153714 | | -SQLITE_API int sqlite3_rtree_init( |
| 154435 | +SQLITE_API int SQLITE_STDCALL sqlite3_rtree_init( |
| 153715 | 154436 | sqlite3 *db, |
| 153716 | 154437 | char **pzErrMsg, |
| 153717 | 154438 | const sqlite3_api_routines *pApi |
| 153718 | 154439 | ){ |
| 153719 | 154440 | SQLITE_EXTENSION_INIT2(pApi) |
| | @@ -154214,11 +154935,11 @@ |
| 154214 | 154935 | |
| 154215 | 154936 | #if !SQLITE_CORE |
| 154216 | 154937 | #ifdef _WIN32 |
| 154217 | 154938 | __declspec(dllexport) |
| 154218 | 154939 | #endif |
| 154219 | | -SQLITE_API int sqlite3_icu_init( |
| 154940 | +SQLITE_API int SQLITE_STDCALL sqlite3_icu_init( |
| 154220 | 154941 | sqlite3 *db, |
| 154221 | 154942 | char **pzErrMsg, |
| 154222 | 154943 | const sqlite3_api_routines *pApi |
| 154223 | 154944 | ){ |
| 154224 | 154945 | SQLITE_EXTENSION_INIT2(pApi) |
| | @@ -154489,5 +155210,656 @@ |
| 154489 | 155210 | |
| 154490 | 155211 | #endif /* defined(SQLITE_ENABLE_ICU) */ |
| 154491 | 155212 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ |
| 154492 | 155213 | |
| 154493 | 155214 | /************** End of fts3_icu.c ********************************************/ |
| 155215 | +/************** Begin file dbstat.c ******************************************/ |
| 155216 | +/* |
| 155217 | +** 2010 July 12 |
| 155218 | +** |
| 155219 | +** The author disclaims copyright to this source code. In place of |
| 155220 | +** a legal notice, here is a blessing: |
| 155221 | +** |
| 155222 | +** May you do good and not evil. |
| 155223 | +** May you find forgiveness for yourself and forgive others. |
| 155224 | +** May you share freely, never taking more than you give. |
| 155225 | +** |
| 155226 | +****************************************************************************** |
| 155227 | +** |
| 155228 | +** This file contains an implementation of the "dbstat" virtual table. |
| 155229 | +** |
| 155230 | +** The dbstat virtual table is used to extract low-level formatting |
| 155231 | +** information from an SQLite database in order to implement the |
| 155232 | +** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script |
| 155233 | +** for an example implementation. |
| 155234 | +*/ |
| 155235 | + |
| 155236 | +#if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \ |
| 155237 | + && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 155238 | + |
| 155239 | +/* |
| 155240 | +** Page paths: |
| 155241 | +** |
| 155242 | +** The value of the 'path' column describes the path taken from the |
| 155243 | +** root-node of the b-tree structure to each page. The value of the |
| 155244 | +** root-node path is '/'. |
| 155245 | +** |
| 155246 | +** The value of the path for the left-most child page of the root of |
| 155247 | +** a b-tree is '/000/'. (Btrees store content ordered from left to right |
| 155248 | +** so the pages to the left have smaller keys than the pages to the right.) |
| 155249 | +** The next to left-most child of the root page is |
| 155250 | +** '/001', and so on, each sibling page identified by a 3-digit hex |
| 155251 | +** value. The children of the 451st left-most sibling have paths such |
| 155252 | +** as '/1c2/000/, '/1c2/001/' etc. |
| 155253 | +** |
| 155254 | +** Overflow pages are specified by appending a '+' character and a |
| 155255 | +** six-digit hexadecimal value to the path to the cell they are linked |
| 155256 | +** from. For example, the three overflow pages in a chain linked from |
| 155257 | +** the left-most cell of the 450th child of the root page are identified |
| 155258 | +** by the paths: |
| 155259 | +** |
| 155260 | +** '/1c2/000+000000' // First page in overflow chain |
| 155261 | +** '/1c2/000+000001' // Second page in overflow chain |
| 155262 | +** '/1c2/000+000002' // Third page in overflow chain |
| 155263 | +** |
| 155264 | +** If the paths are sorted using the BINARY collation sequence, then |
| 155265 | +** the overflow pages associated with a cell will appear earlier in the |
| 155266 | +** sort-order than its child page: |
| 155267 | +** |
| 155268 | +** '/1c2/000/' // Left-most child of 451st child of root |
| 155269 | +*/ |
| 155270 | +#define VTAB_SCHEMA \ |
| 155271 | + "CREATE TABLE xx( " \ |
| 155272 | + " name STRING, /* Name of table or index */" \ |
| 155273 | + " path INTEGER, /* Path to page from root */" \ |
| 155274 | + " pageno INTEGER, /* Page number */" \ |
| 155275 | + " pagetype STRING, /* 'internal', 'leaf' or 'overflow' */" \ |
| 155276 | + " ncell INTEGER, /* Cells on page (0 for overflow) */" \ |
| 155277 | + " payload INTEGER, /* Bytes of payload on this page */" \ |
| 155278 | + " unused INTEGER, /* Bytes of unused space on this page */" \ |
| 155279 | + " mx_payload INTEGER, /* Largest payload size of all cells */" \ |
| 155280 | + " pgoffset INTEGER, /* Offset of page in file */" \ |
| 155281 | + " pgsize INTEGER /* Size of the page */" \ |
| 155282 | + ");" |
| 155283 | + |
| 155284 | + |
| 155285 | +typedef struct StatTable StatTable; |
| 155286 | +typedef struct StatCursor StatCursor; |
| 155287 | +typedef struct StatPage StatPage; |
| 155288 | +typedef struct StatCell StatCell; |
| 155289 | + |
| 155290 | +struct StatCell { |
| 155291 | + int nLocal; /* Bytes of local payload */ |
| 155292 | + u32 iChildPg; /* Child node (or 0 if this is a leaf) */ |
| 155293 | + int nOvfl; /* Entries in aOvfl[] */ |
| 155294 | + u32 *aOvfl; /* Array of overflow page numbers */ |
| 155295 | + int nLastOvfl; /* Bytes of payload on final overflow page */ |
| 155296 | + int iOvfl; /* Iterates through aOvfl[] */ |
| 155297 | +}; |
| 155298 | + |
| 155299 | +struct StatPage { |
| 155300 | + u32 iPgno; |
| 155301 | + DbPage *pPg; |
| 155302 | + int iCell; |
| 155303 | + |
| 155304 | + char *zPath; /* Path to this page */ |
| 155305 | + |
| 155306 | + /* Variables populated by statDecodePage(): */ |
| 155307 | + u8 flags; /* Copy of flags byte */ |
| 155308 | + int nCell; /* Number of cells on page */ |
| 155309 | + int nUnused; /* Number of unused bytes on page */ |
| 155310 | + StatCell *aCell; /* Array of parsed cells */ |
| 155311 | + u32 iRightChildPg; /* Right-child page number (or 0) */ |
| 155312 | + int nMxPayload; /* Largest payload of any cell on this page */ |
| 155313 | +}; |
| 155314 | + |
| 155315 | +struct StatCursor { |
| 155316 | + sqlite3_vtab_cursor base; |
| 155317 | + sqlite3_stmt *pStmt; /* Iterates through set of root pages */ |
| 155318 | + int isEof; /* After pStmt has returned SQLITE_DONE */ |
| 155319 | + |
| 155320 | + StatPage aPage[32]; |
| 155321 | + int iPage; /* Current entry in aPage[] */ |
| 155322 | + |
| 155323 | + /* Values to return. */ |
| 155324 | + char *zName; /* Value of 'name' column */ |
| 155325 | + char *zPath; /* Value of 'path' column */ |
| 155326 | + u32 iPageno; /* Value of 'pageno' column */ |
| 155327 | + char *zPagetype; /* Value of 'pagetype' column */ |
| 155328 | + int nCell; /* Value of 'ncell' column */ |
| 155329 | + int nPayload; /* Value of 'payload' column */ |
| 155330 | + int nUnused; /* Value of 'unused' column */ |
| 155331 | + int nMxPayload; /* Value of 'mx_payload' column */ |
| 155332 | + i64 iOffset; /* Value of 'pgOffset' column */ |
| 155333 | + int szPage; /* Value of 'pgSize' column */ |
| 155334 | +}; |
| 155335 | + |
| 155336 | +struct StatTable { |
| 155337 | + sqlite3_vtab base; |
| 155338 | + sqlite3 *db; |
| 155339 | + int iDb; /* Index of database to analyze */ |
| 155340 | +}; |
| 155341 | + |
| 155342 | +#ifndef get2byte |
| 155343 | +# define get2byte(x) ((x)[0]<<8 | (x)[1]) |
| 155344 | +#endif |
| 155345 | + |
| 155346 | +/* |
| 155347 | +** Connect to or create a statvfs virtual table. |
| 155348 | +*/ |
| 155349 | +static int statConnect( |
| 155350 | + sqlite3 *db, |
| 155351 | + void *pAux, |
| 155352 | + int argc, const char *const*argv, |
| 155353 | + sqlite3_vtab **ppVtab, |
| 155354 | + char **pzErr |
| 155355 | +){ |
| 155356 | + StatTable *pTab = 0; |
| 155357 | + int rc = SQLITE_OK; |
| 155358 | + int iDb; |
| 155359 | + |
| 155360 | + if( argc>=4 ){ |
| 155361 | + iDb = sqlite3FindDbName(db, argv[3]); |
| 155362 | + if( iDb<0 ){ |
| 155363 | + *pzErr = sqlite3_mprintf("no such database: %s", argv[3]); |
| 155364 | + return SQLITE_ERROR; |
| 155365 | + } |
| 155366 | + }else{ |
| 155367 | + iDb = 0; |
| 155368 | + } |
| 155369 | + rc = sqlite3_declare_vtab(db, VTAB_SCHEMA); |
| 155370 | + if( rc==SQLITE_OK ){ |
| 155371 | + pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable)); |
| 155372 | + if( pTab==0 ) rc = SQLITE_NOMEM; |
| 155373 | + } |
| 155374 | + |
| 155375 | + assert( rc==SQLITE_OK || pTab==0 ); |
| 155376 | + if( rc==SQLITE_OK ){ |
| 155377 | + memset(pTab, 0, sizeof(StatTable)); |
| 155378 | + pTab->db = db; |
| 155379 | + pTab->iDb = iDb; |
| 155380 | + } |
| 155381 | + |
| 155382 | + *ppVtab = (sqlite3_vtab*)pTab; |
| 155383 | + return rc; |
| 155384 | +} |
| 155385 | + |
| 155386 | +/* |
| 155387 | +** Disconnect from or destroy a statvfs virtual table. |
| 155388 | +*/ |
| 155389 | +static int statDisconnect(sqlite3_vtab *pVtab){ |
| 155390 | + sqlite3_free(pVtab); |
| 155391 | + return SQLITE_OK; |
| 155392 | +} |
| 155393 | + |
| 155394 | +/* |
| 155395 | +** There is no "best-index". This virtual table always does a linear |
| 155396 | +** scan of the binary VFS log file. |
| 155397 | +*/ |
| 155398 | +static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ |
| 155399 | + |
| 155400 | + /* Records are always returned in ascending order of (name, path). |
| 155401 | + ** If this will satisfy the client, set the orderByConsumed flag so that |
| 155402 | + ** SQLite does not do an external sort. |
| 155403 | + */ |
| 155404 | + if( ( pIdxInfo->nOrderBy==1 |
| 155405 | + && pIdxInfo->aOrderBy[0].iColumn==0 |
| 155406 | + && pIdxInfo->aOrderBy[0].desc==0 |
| 155407 | + ) || |
| 155408 | + ( pIdxInfo->nOrderBy==2 |
| 155409 | + && pIdxInfo->aOrderBy[0].iColumn==0 |
| 155410 | + && pIdxInfo->aOrderBy[0].desc==0 |
| 155411 | + && pIdxInfo->aOrderBy[1].iColumn==1 |
| 155412 | + && pIdxInfo->aOrderBy[1].desc==0 |
| 155413 | + ) |
| 155414 | + ){ |
| 155415 | + pIdxInfo->orderByConsumed = 1; |
| 155416 | + } |
| 155417 | + |
| 155418 | + pIdxInfo->estimatedCost = 10.0; |
| 155419 | + return SQLITE_OK; |
| 155420 | +} |
| 155421 | + |
| 155422 | +/* |
| 155423 | +** Open a new statvfs cursor. |
| 155424 | +*/ |
| 155425 | +static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ |
| 155426 | + StatTable *pTab = (StatTable *)pVTab; |
| 155427 | + StatCursor *pCsr; |
| 155428 | + int rc; |
| 155429 | + |
| 155430 | + pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor)); |
| 155431 | + if( pCsr==0 ){ |
| 155432 | + rc = SQLITE_NOMEM; |
| 155433 | + }else{ |
| 155434 | + char *zSql; |
| 155435 | + memset(pCsr, 0, sizeof(StatCursor)); |
| 155436 | + pCsr->base.pVtab = pVTab; |
| 155437 | + |
| 155438 | + zSql = sqlite3_mprintf( |
| 155439 | + "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type" |
| 155440 | + " UNION ALL " |
| 155441 | + "SELECT name, rootpage, type" |
| 155442 | + " FROM \"%w\".sqlite_master WHERE rootpage!=0" |
| 155443 | + " ORDER BY name", pTab->db->aDb[pTab->iDb].zName); |
| 155444 | + if( zSql==0 ){ |
| 155445 | + rc = SQLITE_NOMEM; |
| 155446 | + }else{ |
| 155447 | + rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0); |
| 155448 | + sqlite3_free(zSql); |
| 155449 | + } |
| 155450 | + if( rc!=SQLITE_OK ){ |
| 155451 | + sqlite3_free(pCsr); |
| 155452 | + pCsr = 0; |
| 155453 | + } |
| 155454 | + } |
| 155455 | + |
| 155456 | + *ppCursor = (sqlite3_vtab_cursor *)pCsr; |
| 155457 | + return rc; |
| 155458 | +} |
| 155459 | + |
| 155460 | +static void statClearPage(StatPage *p){ |
| 155461 | + int i; |
| 155462 | + if( p->aCell ){ |
| 155463 | + for(i=0; i<p->nCell; i++){ |
| 155464 | + sqlite3_free(p->aCell[i].aOvfl); |
| 155465 | + } |
| 155466 | + sqlite3_free(p->aCell); |
| 155467 | + } |
| 155468 | + sqlite3PagerUnref(p->pPg); |
| 155469 | + sqlite3_free(p->zPath); |
| 155470 | + memset(p, 0, sizeof(StatPage)); |
| 155471 | +} |
| 155472 | + |
| 155473 | +static void statResetCsr(StatCursor *pCsr){ |
| 155474 | + int i; |
| 155475 | + sqlite3_reset(pCsr->pStmt); |
| 155476 | + for(i=0; i<ArraySize(pCsr->aPage); i++){ |
| 155477 | + statClearPage(&pCsr->aPage[i]); |
| 155478 | + } |
| 155479 | + pCsr->iPage = 0; |
| 155480 | + sqlite3_free(pCsr->zPath); |
| 155481 | + pCsr->zPath = 0; |
| 155482 | +} |
| 155483 | + |
| 155484 | +/* |
| 155485 | +** Close a statvfs cursor. |
| 155486 | +*/ |
| 155487 | +static int statClose(sqlite3_vtab_cursor *pCursor){ |
| 155488 | + StatCursor *pCsr = (StatCursor *)pCursor; |
| 155489 | + statResetCsr(pCsr); |
| 155490 | + sqlite3_finalize(pCsr->pStmt); |
| 155491 | + sqlite3_free(pCsr); |
| 155492 | + return SQLITE_OK; |
| 155493 | +} |
| 155494 | + |
| 155495 | +static void getLocalPayload( |
| 155496 | + int nUsable, /* Usable bytes per page */ |
| 155497 | + u8 flags, /* Page flags */ |
| 155498 | + int nTotal, /* Total record (payload) size */ |
| 155499 | + int *pnLocal /* OUT: Bytes stored locally */ |
| 155500 | +){ |
| 155501 | + int nLocal; |
| 155502 | + int nMinLocal; |
| 155503 | + int nMaxLocal; |
| 155504 | + |
| 155505 | + if( flags==0x0D ){ /* Table leaf node */ |
| 155506 | + nMinLocal = (nUsable - 12) * 32 / 255 - 23; |
| 155507 | + nMaxLocal = nUsable - 35; |
| 155508 | + }else{ /* Index interior and leaf nodes */ |
| 155509 | + nMinLocal = (nUsable - 12) * 32 / 255 - 23; |
| 155510 | + nMaxLocal = (nUsable - 12) * 64 / 255 - 23; |
| 155511 | + } |
| 155512 | + |
| 155513 | + nLocal = nMinLocal + (nTotal - nMinLocal) % (nUsable - 4); |
| 155514 | + if( nLocal>nMaxLocal ) nLocal = nMinLocal; |
| 155515 | + *pnLocal = nLocal; |
| 155516 | +} |
| 155517 | + |
| 155518 | +static int statDecodePage(Btree *pBt, StatPage *p){ |
| 155519 | + int nUnused; |
| 155520 | + int iOff; |
| 155521 | + int nHdr; |
| 155522 | + int isLeaf; |
| 155523 | + int szPage; |
| 155524 | + |
| 155525 | + u8 *aData = sqlite3PagerGetData(p->pPg); |
| 155526 | + u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0]; |
| 155527 | + |
| 155528 | + p->flags = aHdr[0]; |
| 155529 | + p->nCell = get2byte(&aHdr[3]); |
| 155530 | + p->nMxPayload = 0; |
| 155531 | + |
| 155532 | + isLeaf = (p->flags==0x0A || p->flags==0x0D); |
| 155533 | + nHdr = 12 - isLeaf*4 + (p->iPgno==1)*100; |
| 155534 | + |
| 155535 | + nUnused = get2byte(&aHdr[5]) - nHdr - 2*p->nCell; |
| 155536 | + nUnused += (int)aHdr[7]; |
| 155537 | + iOff = get2byte(&aHdr[1]); |
| 155538 | + while( iOff ){ |
| 155539 | + nUnused += get2byte(&aData[iOff+2]); |
| 155540 | + iOff = get2byte(&aData[iOff]); |
| 155541 | + } |
| 155542 | + p->nUnused = nUnused; |
| 155543 | + p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]); |
| 155544 | + szPage = sqlite3BtreeGetPageSize(pBt); |
| 155545 | + |
| 155546 | + if( p->nCell ){ |
| 155547 | + int i; /* Used to iterate through cells */ |
| 155548 | + int nUsable; /* Usable bytes per page */ |
| 155549 | + |
| 155550 | + sqlite3BtreeEnter(pBt); |
| 155551 | + nUsable = szPage - sqlite3BtreeGetReserveNoMutex(pBt); |
| 155552 | + sqlite3BtreeLeave(pBt); |
| 155553 | + p->aCell = sqlite3_malloc64((p->nCell+1) * sizeof(StatCell)); |
| 155554 | + if( p->aCell==0 ) return SQLITE_NOMEM; |
| 155555 | + memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell)); |
| 155556 | + |
| 155557 | + for(i=0; i<p->nCell; i++){ |
| 155558 | + StatCell *pCell = &p->aCell[i]; |
| 155559 | + |
| 155560 | + iOff = get2byte(&aData[nHdr+i*2]); |
| 155561 | + if( !isLeaf ){ |
| 155562 | + pCell->iChildPg = sqlite3Get4byte(&aData[iOff]); |
| 155563 | + iOff += 4; |
| 155564 | + } |
| 155565 | + if( p->flags==0x05 ){ |
| 155566 | + /* A table interior node. nPayload==0. */ |
| 155567 | + }else{ |
| 155568 | + u32 nPayload; /* Bytes of payload total (local+overflow) */ |
| 155569 | + int nLocal; /* Bytes of payload stored locally */ |
| 155570 | + iOff += getVarint32(&aData[iOff], nPayload); |
| 155571 | + if( p->flags==0x0D ){ |
| 155572 | + u64 dummy; |
| 155573 | + iOff += sqlite3GetVarint(&aData[iOff], &dummy); |
| 155574 | + } |
| 155575 | + if( nPayload>(u32)p->nMxPayload ) p->nMxPayload = nPayload; |
| 155576 | + getLocalPayload(nUsable, p->flags, nPayload, &nLocal); |
| 155577 | + pCell->nLocal = nLocal; |
| 155578 | + assert( nLocal>=0 ); |
| 155579 | + assert( nPayload>=(u32)nLocal ); |
| 155580 | + assert( nLocal<=(nUsable-35) ); |
| 155581 | + if( nPayload>(u32)nLocal ){ |
| 155582 | + int j; |
| 155583 | + int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4); |
| 155584 | + pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4); |
| 155585 | + pCell->nOvfl = nOvfl; |
| 155586 | + pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl); |
| 155587 | + if( pCell->aOvfl==0 ) return SQLITE_NOMEM; |
| 155588 | + pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]); |
| 155589 | + for(j=1; j<nOvfl; j++){ |
| 155590 | + int rc; |
| 155591 | + u32 iPrev = pCell->aOvfl[j-1]; |
| 155592 | + DbPage *pPg = 0; |
| 155593 | + rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg); |
| 155594 | + if( rc!=SQLITE_OK ){ |
| 155595 | + assert( pPg==0 ); |
| 155596 | + return rc; |
| 155597 | + } |
| 155598 | + pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg)); |
| 155599 | + sqlite3PagerUnref(pPg); |
| 155600 | + } |
| 155601 | + } |
| 155602 | + } |
| 155603 | + } |
| 155604 | + } |
| 155605 | + |
| 155606 | + return SQLITE_OK; |
| 155607 | +} |
| 155608 | + |
| 155609 | +/* |
| 155610 | +** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on |
| 155611 | +** the current value of pCsr->iPageno. |
| 155612 | +*/ |
| 155613 | +static void statSizeAndOffset(StatCursor *pCsr){ |
| 155614 | + StatTable *pTab = (StatTable *)((sqlite3_vtab_cursor *)pCsr)->pVtab; |
| 155615 | + Btree *pBt = pTab->db->aDb[pTab->iDb].pBt; |
| 155616 | + Pager *pPager = sqlite3BtreePager(pBt); |
| 155617 | + sqlite3_file *fd; |
| 155618 | + sqlite3_int64 x[2]; |
| 155619 | + |
| 155620 | + /* The default page size and offset */ |
| 155621 | + pCsr->szPage = sqlite3BtreeGetPageSize(pBt); |
| 155622 | + pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1); |
| 155623 | + |
| 155624 | + /* If connected to a ZIPVFS backend, override the page size and |
| 155625 | + ** offset with actual values obtained from ZIPVFS. |
| 155626 | + */ |
| 155627 | + fd = sqlite3PagerFile(pPager); |
| 155628 | + x[0] = pCsr->iPageno; |
| 155629 | + if( fd->pMethods!=0 && sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){ |
| 155630 | + pCsr->iOffset = x[0]; |
| 155631 | + pCsr->szPage = (int)x[1]; |
| 155632 | + } |
| 155633 | +} |
| 155634 | + |
| 155635 | +/* |
| 155636 | +** Move a statvfs cursor to the next entry in the file. |
| 155637 | +*/ |
| 155638 | +static int statNext(sqlite3_vtab_cursor *pCursor){ |
| 155639 | + int rc; |
| 155640 | + int nPayload; |
| 155641 | + char *z; |
| 155642 | + StatCursor *pCsr = (StatCursor *)pCursor; |
| 155643 | + StatTable *pTab = (StatTable *)pCursor->pVtab; |
| 155644 | + Btree *pBt = pTab->db->aDb[pTab->iDb].pBt; |
| 155645 | + Pager *pPager = sqlite3BtreePager(pBt); |
| 155646 | + |
| 155647 | + sqlite3_free(pCsr->zPath); |
| 155648 | + pCsr->zPath = 0; |
| 155649 | + |
| 155650 | +statNextRestart: |
| 155651 | + if( pCsr->aPage[0].pPg==0 ){ |
| 155652 | + rc = sqlite3_step(pCsr->pStmt); |
| 155653 | + if( rc==SQLITE_ROW ){ |
| 155654 | + int nPage; |
| 155655 | + u32 iRoot = (u32)sqlite3_column_int64(pCsr->pStmt, 1); |
| 155656 | + sqlite3PagerPagecount(pPager, &nPage); |
| 155657 | + if( nPage==0 ){ |
| 155658 | + pCsr->isEof = 1; |
| 155659 | + return sqlite3_reset(pCsr->pStmt); |
| 155660 | + } |
| 155661 | + rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg); |
| 155662 | + pCsr->aPage[0].iPgno = iRoot; |
| 155663 | + pCsr->aPage[0].iCell = 0; |
| 155664 | + pCsr->aPage[0].zPath = z = sqlite3_mprintf("/"); |
| 155665 | + pCsr->iPage = 0; |
| 155666 | + if( z==0 ) rc = SQLITE_NOMEM; |
| 155667 | + }else{ |
| 155668 | + pCsr->isEof = 1; |
| 155669 | + return sqlite3_reset(pCsr->pStmt); |
| 155670 | + } |
| 155671 | + }else{ |
| 155672 | + |
| 155673 | + /* Page p itself has already been visited. */ |
| 155674 | + StatPage *p = &pCsr->aPage[pCsr->iPage]; |
| 155675 | + |
| 155676 | + while( p->iCell<p->nCell ){ |
| 155677 | + StatCell *pCell = &p->aCell[p->iCell]; |
| 155678 | + if( pCell->iOvfl<pCell->nOvfl ){ |
| 155679 | + int nUsable; |
| 155680 | + sqlite3BtreeEnter(pBt); |
| 155681 | + nUsable = sqlite3BtreeGetPageSize(pBt) - |
| 155682 | + sqlite3BtreeGetReserveNoMutex(pBt); |
| 155683 | + sqlite3BtreeLeave(pBt); |
| 155684 | + pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0); |
| 155685 | + pCsr->iPageno = pCell->aOvfl[pCell->iOvfl]; |
| 155686 | + pCsr->zPagetype = "overflow"; |
| 155687 | + pCsr->nCell = 0; |
| 155688 | + pCsr->nMxPayload = 0; |
| 155689 | + pCsr->zPath = z = sqlite3_mprintf( |
| 155690 | + "%s%.3x+%.6x", p->zPath, p->iCell, pCell->iOvfl |
| 155691 | + ); |
| 155692 | + if( pCell->iOvfl<pCell->nOvfl-1 ){ |
| 155693 | + pCsr->nUnused = 0; |
| 155694 | + pCsr->nPayload = nUsable - 4; |
| 155695 | + }else{ |
| 155696 | + pCsr->nPayload = pCell->nLastOvfl; |
| 155697 | + pCsr->nUnused = nUsable - 4 - pCsr->nPayload; |
| 155698 | + } |
| 155699 | + pCell->iOvfl++; |
| 155700 | + statSizeAndOffset(pCsr); |
| 155701 | + return z==0 ? SQLITE_NOMEM : SQLITE_OK; |
| 155702 | + } |
| 155703 | + if( p->iRightChildPg ) break; |
| 155704 | + p->iCell++; |
| 155705 | + } |
| 155706 | + |
| 155707 | + if( !p->iRightChildPg || p->iCell>p->nCell ){ |
| 155708 | + statClearPage(p); |
| 155709 | + if( pCsr->iPage==0 ) return statNext(pCursor); |
| 155710 | + pCsr->iPage--; |
| 155711 | + goto statNextRestart; /* Tail recursion */ |
| 155712 | + } |
| 155713 | + pCsr->iPage++; |
| 155714 | + assert( p==&pCsr->aPage[pCsr->iPage-1] ); |
| 155715 | + |
| 155716 | + if( p->iCell==p->nCell ){ |
| 155717 | + p[1].iPgno = p->iRightChildPg; |
| 155718 | + }else{ |
| 155719 | + p[1].iPgno = p->aCell[p->iCell].iChildPg; |
| 155720 | + } |
| 155721 | + rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg); |
| 155722 | + p[1].iCell = 0; |
| 155723 | + p[1].zPath = z = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell); |
| 155724 | + p->iCell++; |
| 155725 | + if( z==0 ) rc = SQLITE_NOMEM; |
| 155726 | + } |
| 155727 | + |
| 155728 | + |
| 155729 | + /* Populate the StatCursor fields with the values to be returned |
| 155730 | + ** by the xColumn() and xRowid() methods. |
| 155731 | + */ |
| 155732 | + if( rc==SQLITE_OK ){ |
| 155733 | + int i; |
| 155734 | + StatPage *p = &pCsr->aPage[pCsr->iPage]; |
| 155735 | + pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0); |
| 155736 | + pCsr->iPageno = p->iPgno; |
| 155737 | + |
| 155738 | + rc = statDecodePage(pBt, p); |
| 155739 | + if( rc==SQLITE_OK ){ |
| 155740 | + statSizeAndOffset(pCsr); |
| 155741 | + |
| 155742 | + switch( p->flags ){ |
| 155743 | + case 0x05: /* table internal */ |
| 155744 | + case 0x02: /* index internal */ |
| 155745 | + pCsr->zPagetype = "internal"; |
| 155746 | + break; |
| 155747 | + case 0x0D: /* table leaf */ |
| 155748 | + case 0x0A: /* index leaf */ |
| 155749 | + pCsr->zPagetype = "leaf"; |
| 155750 | + break; |
| 155751 | + default: |
| 155752 | + pCsr->zPagetype = "corrupted"; |
| 155753 | + break; |
| 155754 | + } |
| 155755 | + pCsr->nCell = p->nCell; |
| 155756 | + pCsr->nUnused = p->nUnused; |
| 155757 | + pCsr->nMxPayload = p->nMxPayload; |
| 155758 | + pCsr->zPath = z = sqlite3_mprintf("%s", p->zPath); |
| 155759 | + if( z==0 ) rc = SQLITE_NOMEM; |
| 155760 | + nPayload = 0; |
| 155761 | + for(i=0; i<p->nCell; i++){ |
| 155762 | + nPayload += p->aCell[i].nLocal; |
| 155763 | + } |
| 155764 | + pCsr->nPayload = nPayload; |
| 155765 | + } |
| 155766 | + } |
| 155767 | + |
| 155768 | + return rc; |
| 155769 | +} |
| 155770 | + |
| 155771 | +static int statEof(sqlite3_vtab_cursor *pCursor){ |
| 155772 | + StatCursor *pCsr = (StatCursor *)pCursor; |
| 155773 | + return pCsr->isEof; |
| 155774 | +} |
| 155775 | + |
| 155776 | +static int statFilter( |
| 155777 | + sqlite3_vtab_cursor *pCursor, |
| 155778 | + int idxNum, const char *idxStr, |
| 155779 | + int argc, sqlite3_value **argv |
| 155780 | +){ |
| 155781 | + StatCursor *pCsr = (StatCursor *)pCursor; |
| 155782 | + |
| 155783 | + statResetCsr(pCsr); |
| 155784 | + return statNext(pCursor); |
| 155785 | +} |
| 155786 | + |
| 155787 | +static int statColumn( |
| 155788 | + sqlite3_vtab_cursor *pCursor, |
| 155789 | + sqlite3_context *ctx, |
| 155790 | + int i |
| 155791 | +){ |
| 155792 | + StatCursor *pCsr = (StatCursor *)pCursor; |
| 155793 | + switch( i ){ |
| 155794 | + case 0: /* name */ |
| 155795 | + sqlite3_result_text(ctx, pCsr->zName, -1, SQLITE_TRANSIENT); |
| 155796 | + break; |
| 155797 | + case 1: /* path */ |
| 155798 | + sqlite3_result_text(ctx, pCsr->zPath, -1, SQLITE_TRANSIENT); |
| 155799 | + break; |
| 155800 | + case 2: /* pageno */ |
| 155801 | + sqlite3_result_int64(ctx, pCsr->iPageno); |
| 155802 | + break; |
| 155803 | + case 3: /* pagetype */ |
| 155804 | + sqlite3_result_text(ctx, pCsr->zPagetype, -1, SQLITE_STATIC); |
| 155805 | + break; |
| 155806 | + case 4: /* ncell */ |
| 155807 | + sqlite3_result_int(ctx, pCsr->nCell); |
| 155808 | + break; |
| 155809 | + case 5: /* payload */ |
| 155810 | + sqlite3_result_int(ctx, pCsr->nPayload); |
| 155811 | + break; |
| 155812 | + case 6: /* unused */ |
| 155813 | + sqlite3_result_int(ctx, pCsr->nUnused); |
| 155814 | + break; |
| 155815 | + case 7: /* mx_payload */ |
| 155816 | + sqlite3_result_int(ctx, pCsr->nMxPayload); |
| 155817 | + break; |
| 155818 | + case 8: /* pgoffset */ |
| 155819 | + sqlite3_result_int64(ctx, pCsr->iOffset); |
| 155820 | + break; |
| 155821 | + default: /* pgsize */ |
| 155822 | + assert( i==9 ); |
| 155823 | + sqlite3_result_int(ctx, pCsr->szPage); |
| 155824 | + break; |
| 155825 | + } |
| 155826 | + return SQLITE_OK; |
| 155827 | +} |
| 155828 | + |
| 155829 | +static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){ |
| 155830 | + StatCursor *pCsr = (StatCursor *)pCursor; |
| 155831 | + *pRowid = pCsr->iPageno; |
| 155832 | + return SQLITE_OK; |
| 155833 | +} |
| 155834 | + |
| 155835 | +/* |
| 155836 | +** Invoke this routine to register the "dbstat" virtual table module |
| 155837 | +*/ |
| 155838 | +SQLITE_API int SQLITE_STDCALL sqlite3_dbstat_register(sqlite3 *db){ |
| 155839 | + static sqlite3_module dbstat_module = { |
| 155840 | + 0, /* iVersion */ |
| 155841 | + statConnect, /* xCreate */ |
| 155842 | + statConnect, /* xConnect */ |
| 155843 | + statBestIndex, /* xBestIndex */ |
| 155844 | + statDisconnect, /* xDisconnect */ |
| 155845 | + statDisconnect, /* xDestroy */ |
| 155846 | + statOpen, /* xOpen - open a cursor */ |
| 155847 | + statClose, /* xClose - close a cursor */ |
| 155848 | + statFilter, /* xFilter - configure scan constraints */ |
| 155849 | + statNext, /* xNext - advance a cursor */ |
| 155850 | + statEof, /* xEof - check for end of scan */ |
| 155851 | + statColumn, /* xColumn - read data */ |
| 155852 | + statRowid, /* xRowid - read data */ |
| 155853 | + 0, /* xUpdate */ |
| 155854 | + 0, /* xBegin */ |
| 155855 | + 0, /* xSync */ |
| 155856 | + 0, /* xCommit */ |
| 155857 | + 0, /* xRollback */ |
| 155858 | + 0, /* xFindMethod */ |
| 155859 | + 0, /* xRename */ |
| 155860 | + }; |
| 155861 | + return sqlite3_create_module(db, "dbstat", &dbstat_module, 0); |
| 155862 | +} |
| 155863 | +#endif /* SQLITE_ENABLE_DBSTAT_VTAB */ |
| 155864 | + |
| 155865 | +/************** End of dbstat.c **********************************************/ |
| 154494 | 155866 | |