| | @@ -73,10 +73,19 @@ |
| 73 | 73 | # define _FILE_OFFSET_BITS 64 |
| 74 | 74 | # endif |
| 75 | 75 | # define _LARGEFILE_SOURCE 1 |
| 76 | 76 | #endif |
| 77 | 77 | |
| 78 | +/* Needed for various definitions... */ |
| 79 | +#if defined(__GNUC__) && !defined(_GNU_SOURCE) |
| 80 | +# define _GNU_SOURCE |
| 81 | +#endif |
| 82 | + |
| 83 | +#if defined(__OpenBSD__) && !defined(_BSD_SOURCE) |
| 84 | +# define _BSD_SOURCE |
| 85 | +#endif |
| 86 | + |
| 78 | 87 | /* |
| 79 | 88 | ** For MinGW, check to see if we can include the header file containing its |
| 80 | 89 | ** version information, among other things. Normally, this internal MinGW |
| 81 | 90 | ** header file would [only] be included automatically by other MinGW header |
| 82 | 91 | ** files; however, the contained version information is now required by this |
| | @@ -222,11 +231,11 @@ |
| 222 | 231 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 223 | 232 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 224 | 233 | */ |
| 225 | 234 | #define SQLITE_VERSION "3.8.7" |
| 226 | 235 | #define SQLITE_VERSION_NUMBER 3008007 |
| 227 | | -#define SQLITE_SOURCE_ID "2014-09-01 18:21:27 672e7387b1bda8d007da7de4244226577d7ab2dc" |
| 236 | +#define SQLITE_SOURCE_ID "2014-09-20 00:35:05 59e2c9df02d7e988c5ad44c560ead1e5288b12e7" |
| 228 | 237 | |
| 229 | 238 | /* |
| 230 | 239 | ** CAPI3REF: Run-Time Library Version Numbers |
| 231 | 240 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 232 | 241 | ** |
| | @@ -610,10 +619,11 @@ |
| 610 | 619 | #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8)) |
| 611 | 620 | #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8)) |
| 612 | 621 | #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) |
| 613 | 622 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
| 614 | 623 | #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
| 624 | +#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
| 615 | 625 | |
| 616 | 626 | /* |
| 617 | 627 | ** CAPI3REF: Flags For File Open Operations |
| 618 | 628 | ** |
| 619 | 629 | ** These bit values are intended for use in the |
| | @@ -2212,11 +2222,11 @@ |
| 2212 | 2222 | ** |
| 2213 | 2223 | ** ^Calling this routine with an argument less than or equal to zero |
| 2214 | 2224 | ** turns off all busy handlers. |
| 2215 | 2225 | ** |
| 2216 | 2226 | ** ^(There can only be a single busy handler for a particular |
| 2217 | | -** [database connection] any any given moment. If another busy handler |
| 2227 | +** [database connection] at any given moment. If another busy handler |
| 2218 | 2228 | ** was defined (using [sqlite3_busy_handler()]) prior to calling |
| 2219 | 2229 | ** this routine, that other busy handler is cleared.)^ |
| 2220 | 2230 | ** |
| 2221 | 2231 | ** See also: [PRAGMA busy_timeout] |
| 2222 | 2232 | */ |
| | @@ -2415,10 +2425,14 @@ |
| 2415 | 2425 | ** of memory at least N bytes in length, where N is the parameter. |
| 2416 | 2426 | ** ^If sqlite3_malloc() is unable to obtain sufficient free |
| 2417 | 2427 | ** memory, it returns a NULL pointer. ^If the parameter N to |
| 2418 | 2428 | ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns |
| 2419 | 2429 | ** a NULL pointer. |
| 2430 | +** |
| 2431 | +** ^The sqlite3_malloc64(N) routine works just like |
| 2432 | +** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead |
| 2433 | +** of a signed 32-bit integer. |
| 2420 | 2434 | ** |
| 2421 | 2435 | ** ^Calling sqlite3_free() with a pointer previously returned |
| 2422 | 2436 | ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so |
| 2423 | 2437 | ** that it might be reused. ^The sqlite3_free() routine is |
| 2424 | 2438 | ** a no-op if is called with a NULL pointer. Passing a NULL pointer |
| | @@ -2427,28 +2441,42 @@ |
| 2427 | 2441 | ** memory might result in a segmentation fault or other severe error. |
| 2428 | 2442 | ** Memory corruption, a segmentation fault, or other severe error |
| 2429 | 2443 | ** might result if sqlite3_free() is called with a non-NULL pointer that |
| 2430 | 2444 | ** was not obtained from sqlite3_malloc() or sqlite3_realloc(). |
| 2431 | 2445 | ** |
| 2432 | | -** ^(The sqlite3_realloc() interface attempts to resize a |
| 2433 | | -** prior memory allocation to be at least N bytes, where N is the |
| 2434 | | -** second parameter. The memory allocation to be resized is the first |
| 2435 | | -** parameter.)^ ^ If the first parameter to sqlite3_realloc() |
| 2446 | +** ^The sqlite3_realloc(X,N) interface attempts to resize a |
| 2447 | +** prior memory allocation X to be at least N bytes. |
| 2448 | +** ^If the X parameter to sqlite3_realloc(X,N) |
| 2436 | 2449 | ** is a NULL pointer then its behavior is identical to calling |
| 2437 | | -** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc(). |
| 2438 | | -** ^If the second parameter to sqlite3_realloc() is zero or |
| 2450 | +** sqlite3_malloc(N). |
| 2451 | +** ^If the N parameter to sqlite3_realloc(X,N) is zero or |
| 2439 | 2452 | ** negative then the behavior is exactly the same as calling |
| 2440 | | -** sqlite3_free(P) where P is the first parameter to sqlite3_realloc(). |
| 2441 | | -** ^sqlite3_realloc() returns a pointer to a memory allocation |
| 2442 | | -** of at least N bytes in size or NULL if sufficient memory is unavailable. |
| 2453 | +** sqlite3_free(X). |
| 2454 | +** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation |
| 2455 | +** of at least N bytes in size or NULL if insufficient memory is available. |
| 2443 | 2456 | ** ^If M is the size of the prior allocation, then min(N,M) bytes |
| 2444 | 2457 | ** of the prior allocation are copied into the beginning of buffer returned |
| 2445 | | -** by sqlite3_realloc() and the prior allocation is freed. |
| 2446 | | -** ^If sqlite3_realloc() returns NULL, then the prior allocation |
| 2447 | | -** is not freed. |
| 2458 | +** by sqlite3_realloc(X,N) and the prior allocation is freed. |
| 2459 | +** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the |
| 2460 | +** prior allocation is not freed. |
| 2448 | 2461 | ** |
| 2449 | | -** ^The memory returned by sqlite3_malloc() and sqlite3_realloc() |
| 2462 | +** ^The sqlite3_realloc64(X,N) interfaces works the same as |
| 2463 | +** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead |
| 2464 | +** of a 32-bit signed integer. |
| 2465 | +** |
| 2466 | +** ^If X is a memory allocation previously obtained from sqlite3_malloc(), |
| 2467 | +** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then |
| 2468 | +** sqlite3_msize(X) returns the size of that memory allocation in bytes. |
| 2469 | +** ^The value returned by sqlite3_msize(X) might be larger than the number |
| 2470 | +** of bytes requested when X was allocated. ^If X is a NULL pointer then |
| 2471 | +** sqlite3_msize(X) returns zero. If X points to something that is not |
| 2472 | +** the beginning of memory allocation, or if it points to a formerly |
| 2473 | +** valid memory allocation that has now been freed, then the behavior |
| 2474 | +** of sqlite3_msize(X) is undefined and possibly harmful. |
| 2475 | +** |
| 2476 | +** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(), |
| 2477 | +** sqlite3_malloc64(), and sqlite3_realloc64() |
| 2450 | 2478 | ** is always aligned to at least an 8 byte boundary, or to a |
| 2451 | 2479 | ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time |
| 2452 | 2480 | ** option is used. |
| 2453 | 2481 | ** |
| 2454 | 2482 | ** In SQLite version 3.5.0 and 3.5.1, it was possible to define |
| | @@ -2472,12 +2500,15 @@ |
| 2472 | 2500 | ** The application must not read or write any part of |
| 2473 | 2501 | ** a block of memory after it has been released using |
| 2474 | 2502 | ** [sqlite3_free()] or [sqlite3_realloc()]. |
| 2475 | 2503 | */ |
| 2476 | 2504 | SQLITE_API void *sqlite3_malloc(int); |
| 2505 | +SQLITE_API void *sqlite3_malloc64(sqlite3_uint64); |
| 2477 | 2506 | SQLITE_API void *sqlite3_realloc(void*, int); |
| 2507 | +SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64); |
| 2478 | 2508 | SQLITE_API void sqlite3_free(void*); |
| 2509 | +SQLITE_API sqlite3_uint64 sqlite3_msize(void*); |
| 2479 | 2510 | |
| 2480 | 2511 | /* |
| 2481 | 2512 | ** CAPI3REF: Memory Allocator Statistics |
| 2482 | 2513 | ** |
| 2483 | 2514 | ** SQLite provides these two interfaces for reporting on the status |
| | @@ -3482,11 +3513,12 @@ |
| 3482 | 3513 | ** is negative, then the length of the string is |
| 3483 | 3514 | ** the number of bytes up to the first zero terminator. |
| 3484 | 3515 | ** If the fourth parameter to sqlite3_bind_blob() is negative, then |
| 3485 | 3516 | ** the behavior is undefined. |
| 3486 | 3517 | ** If a non-negative fourth parameter is provided to sqlite3_bind_text() |
| 3487 | | -** or sqlite3_bind_text16() then that parameter must be the byte offset |
| 3518 | +** or sqlite3_bind_text16() or sqlite3_bind_text64() then |
| 3519 | +** that parameter must be the byte offset |
| 3488 | 3520 | ** where the NUL terminator would occur assuming the string were NUL |
| 3489 | 3521 | ** terminated. If any NUL characters occur at byte offsets less than |
| 3490 | 3522 | ** the value of the fourth parameter then the resulting string value will |
| 3491 | 3523 | ** contain embedded NULs. The result of expressions involving strings |
| 3492 | 3524 | ** with embedded NULs is undefined. |
| | @@ -3500,10 +3532,18 @@ |
| 3500 | 3532 | ** the special value [SQLITE_STATIC], then SQLite assumes that the |
| 3501 | 3533 | ** information is in static, unmanaged space and does not need to be freed. |
| 3502 | 3534 | ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then |
| 3503 | 3535 | ** SQLite makes its own private copy of the data immediately, before |
| 3504 | 3536 | ** the sqlite3_bind_*() routine returns. |
| 3537 | +** |
| 3538 | +** ^The sixth argument to sqlite3_bind_text64() must be one of |
| 3539 | +** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE] |
| 3540 | +** to specify the encoding of the text in the third parameter. If |
| 3541 | +** the sixth argument to sqlite3_bind_text64() is not how of the |
| 3542 | +** allowed values shown above, or if the text encoding is different |
| 3543 | +** from the encoding specified by the sixth parameter, then the behavior |
| 3544 | +** is undefined. |
| 3505 | 3545 | ** |
| 3506 | 3546 | ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that |
| 3507 | 3547 | ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory |
| 3508 | 3548 | ** (just an integer to hold its size) while it is being processed. |
| 3509 | 3549 | ** Zeroblobs are intended to serve as placeholders for BLOBs whose |
| | @@ -3521,23 +3561,30 @@ |
| 3521 | 3561 | ** ^Bindings are not cleared by the [sqlite3_reset()] routine. |
| 3522 | 3562 | ** ^Unbound parameters are interpreted as NULL. |
| 3523 | 3563 | ** |
| 3524 | 3564 | ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an |
| 3525 | 3565 | ** [error code] if anything goes wrong. |
| 3566 | +** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB |
| 3567 | +** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or |
| 3568 | +** [SQLITE_MAX_LENGTH]. |
| 3526 | 3569 | ** ^[SQLITE_RANGE] is returned if the parameter |
| 3527 | 3570 | ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. |
| 3528 | 3571 | ** |
| 3529 | 3572 | ** See also: [sqlite3_bind_parameter_count()], |
| 3530 | 3573 | ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. |
| 3531 | 3574 | */ |
| 3532 | 3575 | SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); |
| 3576 | +SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64, |
| 3577 | + void(*)(void*)); |
| 3533 | 3578 | SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); |
| 3534 | 3579 | SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); |
| 3535 | 3580 | SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); |
| 3536 | 3581 | SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); |
| 3537 | | -SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*)); |
| 3582 | +SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*)); |
| 3538 | 3583 | SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); |
| 3584 | +SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64, |
| 3585 | + void(*)(void*), unsigned char encoding); |
| 3539 | 3586 | SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); |
| 3540 | 3587 | SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
| 3541 | 3588 | |
| 3542 | 3589 | /* |
| 3543 | 3590 | ** CAPI3REF: Number Of SQL Parameters |
| | @@ -4282,11 +4329,11 @@ |
| 4282 | 4329 | ** These routines work only with [protected sqlite3_value] objects. |
| 4283 | 4330 | ** Any attempt to use these routines on an [unprotected sqlite3_value] |
| 4284 | 4331 | ** object results in undefined behavior. |
| 4285 | 4332 | ** |
| 4286 | 4333 | ** ^These routines work just like the corresponding [column access functions] |
| 4287 | | -** except that these routines take a single [protected sqlite3_value] object |
| 4334 | +** except that these routines take a single [protected sqlite3_value] object |
| 4288 | 4335 | ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. |
| 4289 | 4336 | ** |
| 4290 | 4337 | ** ^The sqlite3_value_text16() interface extracts a UTF-16 string |
| 4291 | 4338 | ** in the native byte-order of the host machine. ^The |
| 4292 | 4339 | ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces |
| | @@ -4525,14 +4572,18 @@ |
| 4525 | 4572 | ** |
| 4526 | 4573 | ** ^The sqlite3_result_null() interface sets the return value |
| 4527 | 4574 | ** of the application-defined function to be NULL. |
| 4528 | 4575 | ** |
| 4529 | 4576 | ** ^The sqlite3_result_text(), sqlite3_result_text16(), |
| 4530 | | -** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces |
| 4577 | +** sqlite3_result_text16le(), and sqlite3_result_text16be() |
| 4531 | 4578 | ** set the return value of the application-defined function to be |
| 4532 | 4579 | ** a text string which is represented as UTF-8, UTF-16 native byte order, |
| 4533 | 4580 | ** UTF-16 little endian, or UTF-16 big endian, respectively. |
| 4581 | +** ^The sqlite3_result_text64() interface sets the return value of an |
| 4582 | +** application-defined function to be a text string in an encoding |
| 4583 | +** specified by the fifth (and last) parameter, which must be one |
| 4584 | +** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]. |
| 4534 | 4585 | ** ^SQLite takes the text result from the application from |
| 4535 | 4586 | ** the 2nd parameter of the sqlite3_result_text* interfaces. |
| 4536 | 4587 | ** ^If the 3rd parameter to the sqlite3_result_text* interfaces |
| 4537 | 4588 | ** is negative, then SQLite takes result text from the 2nd parameter |
| 4538 | 4589 | ** through the first zero character. |
| | @@ -4572,10 +4623,11 @@ |
| 4572 | 4623 | ** If these routines are called from within the different thread |
| 4573 | 4624 | ** than the one containing the application-defined function that received |
| 4574 | 4625 | ** the [sqlite3_context] pointer, the results are undefined. |
| 4575 | 4626 | */ |
| 4576 | 4627 | SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); |
| 4628 | +SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*)); |
| 4577 | 4629 | SQLITE_API void sqlite3_result_double(sqlite3_context*, double); |
| 4578 | 4630 | SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); |
| 4579 | 4631 | SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); |
| 4580 | 4632 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); |
| 4581 | 4633 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); |
| | @@ -4582,10 +4634,12 @@ |
| 4582 | 4634 | SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); |
| 4583 | 4635 | SQLITE_API void sqlite3_result_int(sqlite3_context*, int); |
| 4584 | 4636 | SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); |
| 4585 | 4637 | SQLITE_API void sqlite3_result_null(sqlite3_context*); |
| 4586 | 4638 | SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); |
| 4639 | +SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64, |
| 4640 | + void(*)(void*), unsigned char encoding); |
| 4587 | 4641 | SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); |
| 4588 | 4642 | SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); |
| 4589 | 4643 | SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); |
| 4590 | 4644 | SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); |
| 4591 | 4645 | SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); |
| | @@ -6475,25 +6529,25 @@ |
| 6475 | 6529 | ** memory already being in use. |
| 6476 | 6530 | ** Only the high-water value is meaningful; |
| 6477 | 6531 | ** the current value is always zero.)^ |
| 6478 | 6532 | ** |
| 6479 | 6533 | ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> |
| 6480 | | -** <dd>This parameter returns the approximate number of of bytes of heap |
| 6534 | +** <dd>This parameter returns the approximate number of bytes of heap |
| 6481 | 6535 | ** memory used by all pager caches associated with the database connection.)^ |
| 6482 | 6536 | ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. |
| 6483 | 6537 | ** |
| 6484 | 6538 | ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> |
| 6485 | | -** <dd>This parameter returns the approximate number of of bytes of heap |
| 6539 | +** <dd>This parameter returns the approximate number of bytes of heap |
| 6486 | 6540 | ** memory used to store the schema for all databases associated |
| 6487 | 6541 | ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ |
| 6488 | 6542 | ** ^The full amount of memory used by the schemas is reported, even if the |
| 6489 | 6543 | ** schema memory is shared with other database connections due to |
| 6490 | 6544 | ** [shared cache mode] being enabled. |
| 6491 | 6545 | ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. |
| 6492 | 6546 | ** |
| 6493 | 6547 | ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> |
| 6494 | | -** <dd>This parameter returns the approximate number of of bytes of heap |
| 6548 | +** <dd>This parameter returns the approximate number of bytes of heap |
| 6495 | 6549 | ** and lookaside memory used by all prepared statements associated with |
| 6496 | 6550 | ** the database connection.)^ |
| 6497 | 6551 | ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. |
| 6498 | 6552 | ** </dd> |
| 6499 | 6553 | ** |
| | @@ -7846,19 +7900,10 @@ |
| 7846 | 7900 | #pragma warn -aus /* Assigned value is never used */ |
| 7847 | 7901 | #pragma warn -csu /* Comparing signed and unsigned */ |
| 7848 | 7902 | #pragma warn -spa /* Suspicious pointer arithmetic */ |
| 7849 | 7903 | #endif |
| 7850 | 7904 | |
| 7851 | | -/* Needed for various definitions... */ |
| 7852 | | -#ifndef _GNU_SOURCE |
| 7853 | | -# define _GNU_SOURCE |
| 7854 | | -#endif |
| 7855 | | - |
| 7856 | | -#if defined(__OpenBSD__) && !defined(_BSD_SOURCE) |
| 7857 | | -# define _BSD_SOURCE |
| 7858 | | -#endif |
| 7859 | | - |
| 7860 | 7905 | /* |
| 7861 | 7906 | ** Include standard header files as necessary |
| 7862 | 7907 | */ |
| 7863 | 7908 | #ifdef HAVE_STDINT_H |
| 7864 | 7909 | #include <stdint.h> |
| | @@ -8093,11 +8138,11 @@ |
| 8093 | 8138 | # define ALWAYS(X) (X) |
| 8094 | 8139 | # define NEVER(X) (X) |
| 8095 | 8140 | #endif |
| 8096 | 8141 | |
| 8097 | 8142 | /* |
| 8098 | | -** Return true (non-zero) if the input is a integer that is too large |
| 8143 | +** Return true (non-zero) if the input is an integer that is too large |
| 8099 | 8144 | ** to fit in 32-bits. This macro is used inside of various testcase() |
| 8100 | 8145 | ** macros to verify that we have tested SQLite for large-file support. |
| 8101 | 8146 | */ |
| 8102 | 8147 | #define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0) |
| 8103 | 8148 | |
| | @@ -8644,11 +8689,11 @@ |
| 8644 | 8689 | ** Assert that the pointer X is aligned to an 8-byte boundary. This |
| 8645 | 8690 | ** macro is used only within assert() to verify that the code gets |
| 8646 | 8691 | ** all alignment restrictions correct. |
| 8647 | 8692 | ** |
| 8648 | 8693 | ** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the |
| 8649 | | -** underlying malloc() implemention might return us 4-byte aligned |
| 8694 | +** underlying malloc() implementation might return us 4-byte aligned |
| 8650 | 8695 | ** pointers. In that case, only verify 4-byte alignment. |
| 8651 | 8696 | */ |
| 8652 | 8697 | #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC |
| 8653 | 8698 | # define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&3)==0) |
| 8654 | 8699 | #else |
| | @@ -9537,14 +9582,14 @@ |
| 9537 | 9582 | SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*); |
| 9538 | 9583 | #endif |
| 9539 | 9584 | SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); |
| 9540 | 9585 | |
| 9541 | 9586 | SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*); |
| 9542 | | -SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*,int); |
| 9587 | +SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*); |
| 9543 | 9588 | SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **); |
| 9544 | 9589 | |
| 9545 | | -typedef int (*RecordCompare)(int,const void*,UnpackedRecord*,int); |
| 9590 | +typedef int (*RecordCompare)(int,const void*,UnpackedRecord*); |
| 9546 | 9591 | SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*); |
| 9547 | 9592 | |
| 9548 | 9593 | #ifndef SQLITE_OMIT_TRIGGER |
| 9549 | 9594 | SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *); |
| 9550 | 9595 | #endif |
| | @@ -10180,11 +10225,11 @@ |
| 10180 | 10225 | ** SHARED_SIZE is the number of bytes available in the pool from which |
| 10181 | 10226 | ** a random byte is selected for a shared lock. The pool of bytes for |
| 10182 | 10227 | ** shared locks begins at SHARED_FIRST. |
| 10183 | 10228 | ** |
| 10184 | 10229 | ** The same locking strategy and |
| 10185 | | -** byte ranges are used for Unix. This leaves open the possiblity of having |
| 10230 | +** byte ranges are used for Unix. This leaves open the possibility of having |
| 10186 | 10231 | ** clients on win95, winNT, and unix all talking to the same shared file |
| 10187 | 10232 | ** and all locking correctly. To do so would require that samba (or whatever |
| 10188 | 10233 | ** tool is being used for file sharing) implements locks correctly between |
| 10189 | 10234 | ** windows and unix. I'm guessing that isn't likely to happen, but by |
| 10190 | 10235 | ** using the same locking range we are at least open to the possibility. |
| | @@ -10299,11 +10344,11 @@ |
| 10299 | 10344 | |
| 10300 | 10345 | /* |
| 10301 | 10346 | ** Figure out what version of the code to use. The choices are |
| 10302 | 10347 | ** |
| 10303 | 10348 | ** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The |
| 10304 | | -** mutexes implemention cannot be overridden |
| 10349 | +** mutexes implementation cannot be overridden |
| 10305 | 10350 | ** at start-time. |
| 10306 | 10351 | ** |
| 10307 | 10352 | ** SQLITE_MUTEX_NOOP For single-threaded applications. No |
| 10308 | 10353 | ** mutual exclusion is provided. But this |
| 10309 | 10354 | ** implementation can be overridden at |
| | @@ -10465,10 +10510,49 @@ |
| 10465 | 10510 | ** Collisions are on the FuncDef.pHash chain. |
| 10466 | 10511 | */ |
| 10467 | 10512 | struct FuncDefHash { |
| 10468 | 10513 | FuncDef *a[23]; /* Hash table for functions */ |
| 10469 | 10514 | }; |
| 10515 | + |
| 10516 | +#ifdef SQLITE_USER_AUTHENTICATION |
| 10517 | +/* |
| 10518 | +** Information held in the "sqlite3" database connection object and used |
| 10519 | +** to manage user authentication. |
| 10520 | +*/ |
| 10521 | +typedef struct sqlite3_userauth sqlite3_userauth; |
| 10522 | +struct sqlite3_userauth { |
| 10523 | + u8 authLevel; /* Current authentication level */ |
| 10524 | + int nAuthPW; /* Size of the zAuthPW in bytes */ |
| 10525 | + char *zAuthPW; /* Password used to authenticate */ |
| 10526 | + char *zAuthUser; /* User name used to authenticate */ |
| 10527 | +}; |
| 10528 | + |
| 10529 | +/* Allowed values for sqlite3_userauth.authLevel */ |
| 10530 | +#define UAUTH_Unknown 0 /* Authentication not yet checked */ |
| 10531 | +#define UAUTH_Fail 1 /* User authentication failed */ |
| 10532 | +#define UAUTH_User 2 /* Authenticated as a normal user */ |
| 10533 | +#define UAUTH_Admin 3 /* Authenticated as an administrator */ |
| 10534 | + |
| 10535 | +/* Functions used only by user authorization logic */ |
| 10536 | +SQLITE_PRIVATE int sqlite3UserAuthTable(const char*); |
| 10537 | +SQLITE_PRIVATE int sqlite3UserAuthCheckLogin(sqlite3*,const char*,u8*); |
| 10538 | +SQLITE_PRIVATE void sqlite3UserAuthInit(sqlite3*); |
| 10539 | +SQLITE_PRIVATE void sqlite3CryptFunc(sqlite3_context*,int,sqlite3_value**); |
| 10540 | + |
| 10541 | +#endif /* SQLITE_USER_AUTHENTICATION */ |
| 10542 | + |
| 10543 | +/* |
| 10544 | +** typedef for the authorization callback function. |
| 10545 | +*/ |
| 10546 | +#ifdef SQLITE_USER_AUTHENTICATION |
| 10547 | + typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*, |
| 10548 | + const char*, const char*); |
| 10549 | +#else |
| 10550 | + typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*, |
| 10551 | + const char*); |
| 10552 | +#endif |
| 10553 | + |
| 10470 | 10554 | |
| 10471 | 10555 | /* |
| 10472 | 10556 | ** Each database connection is an instance of the following structure. |
| 10473 | 10557 | */ |
| 10474 | 10558 | struct sqlite3 { |
| | @@ -10533,12 +10617,11 @@ |
| 10533 | 10617 | volatile int isInterrupted; /* True if sqlite3_interrupt has been called */ |
| 10534 | 10618 | double notUsed1; /* Spacer */ |
| 10535 | 10619 | } u1; |
| 10536 | 10620 | Lookaside lookaside; /* Lookaside malloc configuration */ |
| 10537 | 10621 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 10538 | | - int (*xAuth)(void*,int,const char*,const char*,const char*,const char*); |
| 10539 | | - /* Access authorization function */ |
| 10622 | + sqlite3_xauth xAuth; /* Access authorization function */ |
| 10540 | 10623 | void *pAuthArg; /* 1st argument to the access auth function */ |
| 10541 | 10624 | #endif |
| 10542 | 10625 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 10543 | 10626 | int (*xProgress)(void *); /* The progress callback */ |
| 10544 | 10627 | void *pProgressArg; /* Argument to the progress callback */ |
| | @@ -10560,11 +10643,10 @@ |
| 10560 | 10643 | int nSavepoint; /* Number of non-transaction savepoints */ |
| 10561 | 10644 | int nStatement; /* Number of nested statement-transactions */ |
| 10562 | 10645 | i64 nDeferredCons; /* Net deferred constraints this transaction. */ |
| 10563 | 10646 | i64 nDeferredImmCons; /* Net deferred immediate constraints */ |
| 10564 | 10647 | int *pnBytesFreed; /* If not NULL, increment this in DbFree() */ |
| 10565 | | - |
| 10566 | 10648 | #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY |
| 10567 | 10649 | /* The following variables are all protected by the STATIC_MASTER |
| 10568 | 10650 | ** mutex, not by sqlite3.mutex. They are used by code in notify.c. |
| 10569 | 10651 | ** |
| 10570 | 10652 | ** When X.pUnlockConnection==Y, that means that X is waiting for Y to |
| | @@ -10578,10 +10660,13 @@ |
| 10578 | 10660 | sqlite3 *pUnlockConnection; /* Connection to watch for unlock */ |
| 10579 | 10661 | void *pUnlockArg; /* Argument to xUnlockNotify */ |
| 10580 | 10662 | void (*xUnlockNotify)(void **, int); /* Unlock notify callback */ |
| 10581 | 10663 | sqlite3 *pNextBlocked; /* Next in list of all blocked connections */ |
| 10582 | 10664 | #endif |
| 10665 | +#ifdef SQLITE_USER_AUTHENTICATION |
| 10666 | + sqlite3_userauth auth; /* User authentication information */ |
| 10667 | +#endif |
| 10583 | 10668 | }; |
| 10584 | 10669 | |
| 10585 | 10670 | /* |
| 10586 | 10671 | ** A macro to discover the encoding of a database. |
| 10587 | 10672 | */ |
| | @@ -10637,11 +10722,10 @@ |
| 10637 | 10722 | #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 10638 | 10723 | #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 10639 | 10724 | #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| 10640 | 10725 | #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */ |
| 10641 | 10726 | #define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */ |
| 10642 | | -#define SQLITE_AdjustOutEst 0x1000 /* Adjust output estimates using WHERE */ |
| 10643 | 10727 | #define SQLITE_AllOpts 0xffff /* All optimizations */ |
| 10644 | 10728 | |
| 10645 | 10729 | /* |
| 10646 | 10730 | ** Macros for testing whether or not optimizations are enabled or disabled. |
| 10647 | 10731 | */ |
| | @@ -10724,10 +10808,11 @@ |
| 10724 | 10808 | #define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */ |
| 10725 | 10809 | #define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */ |
| 10726 | 10810 | #define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */ |
| 10727 | 10811 | #define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */ |
| 10728 | 10812 | #define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */ |
| 10813 | +#define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */ |
| 10729 | 10814 | |
| 10730 | 10815 | /* |
| 10731 | 10816 | ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are |
| 10732 | 10817 | ** used to create the initializers for the FuncDef structures. |
| 10733 | 10818 | ** |
| | @@ -10770,10 +10855,13 @@ |
| 10770 | 10855 | #define LIKEFUNC(zName, nArg, arg, flags) \ |
| 10771 | 10856 | {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ |
| 10772 | 10857 | (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0} |
| 10773 | 10858 | #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \ |
| 10774 | 10859 | {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \ |
| 10860 | + SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0} |
| 10861 | +#define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \ |
| 10862 | + {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \ |
| 10775 | 10863 | SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0} |
| 10776 | 10864 | |
| 10777 | 10865 | /* |
| 10778 | 10866 | ** All current savepoints are stored in a linked list starting at |
| 10779 | 10867 | ** sqlite3.pSavepoint. The first element in the list is the most recently |
| | @@ -10857,30 +10945,30 @@ |
| 10857 | 10945 | ** |
| 10858 | 10946 | ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and |
| 10859 | 10947 | ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve |
| 10860 | 10948 | ** the speed a little by numbering the values consecutively. |
| 10861 | 10949 | ** |
| 10862 | | -** But rather than start with 0 or 1, we begin with 'a'. That way, |
| 10950 | +** But rather than start with 0 or 1, we begin with 'A'. That way, |
| 10863 | 10951 | ** when multiple affinity types are concatenated into a string and |
| 10864 | 10952 | ** used as the P4 operand, they will be more readable. |
| 10865 | 10953 | ** |
| 10866 | 10954 | ** Note also that the numeric types are grouped together so that testing |
| 10867 | | -** for a numeric type is a single comparison. |
| 10955 | +** for a numeric type is a single comparison. And the NONE type is first. |
| 10868 | 10956 | */ |
| 10869 | | -#define SQLITE_AFF_TEXT 'a' |
| 10870 | | -#define SQLITE_AFF_NONE 'b' |
| 10871 | | -#define SQLITE_AFF_NUMERIC 'c' |
| 10872 | | -#define SQLITE_AFF_INTEGER 'd' |
| 10873 | | -#define SQLITE_AFF_REAL 'e' |
| 10957 | +#define SQLITE_AFF_NONE 'A' |
| 10958 | +#define SQLITE_AFF_TEXT 'B' |
| 10959 | +#define SQLITE_AFF_NUMERIC 'C' |
| 10960 | +#define SQLITE_AFF_INTEGER 'D' |
| 10961 | +#define SQLITE_AFF_REAL 'E' |
| 10874 | 10962 | |
| 10875 | 10963 | #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC) |
| 10876 | 10964 | |
| 10877 | 10965 | /* |
| 10878 | 10966 | ** The SQLITE_AFF_MASK values masks off the significant bits of an |
| 10879 | 10967 | ** affinity value. |
| 10880 | 10968 | */ |
| 10881 | | -#define SQLITE_AFF_MASK 0x67 |
| 10969 | +#define SQLITE_AFF_MASK 0x47 |
| 10882 | 10970 | |
| 10883 | 10971 | /* |
| 10884 | 10972 | ** Additional bit values that can be ORed with an affinity without |
| 10885 | 10973 | ** changing the affinity. |
| 10886 | 10974 | ** |
| | @@ -10887,14 +10975,14 @@ |
| 10887 | 10975 | ** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL. |
| 10888 | 10976 | ** It causes an assert() to fire if either operand to a comparison |
| 10889 | 10977 | ** operator is NULL. It is added to certain comparison operators to |
| 10890 | 10978 | ** prove that the operands are always NOT NULL. |
| 10891 | 10979 | */ |
| 10892 | | -#define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */ |
| 10893 | | -#define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */ |
| 10980 | +#define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */ |
| 10981 | +#define SQLITE_STOREP2 0x20 /* Store result in reg[P2] rather than jump */ |
| 10894 | 10982 | #define SQLITE_NULLEQ 0x80 /* NULL=NULL */ |
| 10895 | | -#define SQLITE_NOTNULL 0x88 /* Assert that operands are never NULL */ |
| 10983 | +#define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */ |
| 10896 | 10984 | |
| 10897 | 10985 | /* |
| 10898 | 10986 | ** An object of this type is created for each virtual table present in |
| 10899 | 10987 | ** the database schema. |
| 10900 | 10988 | ** |
| | @@ -11693,21 +11781,26 @@ |
| 11693 | 11781 | ExprList *pEList; /* Optional list of result-set columns */ |
| 11694 | 11782 | AggInfo *pAggInfo; /* Information about aggregates at this level */ |
| 11695 | 11783 | NameContext *pNext; /* Next outer name context. NULL for outermost */ |
| 11696 | 11784 | int nRef; /* Number of names resolved by this context */ |
| 11697 | 11785 | int nErr; /* Number of errors encountered while resolving names */ |
| 11698 | | - u8 ncFlags; /* Zero or more NC_* flags defined below */ |
| 11786 | + u16 ncFlags; /* Zero or more NC_* flags defined below */ |
| 11699 | 11787 | }; |
| 11700 | 11788 | |
| 11701 | 11789 | /* |
| 11702 | 11790 | ** Allowed values for the NameContext, ncFlags field. |
| 11791 | +** |
| 11792 | +** Note: NC_MinMaxAgg must have the same value as SF_MinMaxAgg and |
| 11793 | +** SQLITE_FUNC_MINMAX. |
| 11794 | +** |
| 11703 | 11795 | */ |
| 11704 | | -#define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */ |
| 11705 | | -#define NC_HasAgg 0x02 /* One or more aggregate functions seen */ |
| 11706 | | -#define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */ |
| 11707 | | -#define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */ |
| 11708 | | -#define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */ |
| 11796 | +#define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */ |
| 11797 | +#define NC_HasAgg 0x0002 /* One or more aggregate functions seen */ |
| 11798 | +#define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */ |
| 11799 | +#define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */ |
| 11800 | +#define NC_PartIdx 0x0010 /* True if resolving a partial index WHERE */ |
| 11801 | +#define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */ |
| 11709 | 11802 | |
| 11710 | 11803 | /* |
| 11711 | 11804 | ** An instance of the following structure contains all information |
| 11712 | 11805 | ** needed to generate code for a single SELECT statement. |
| 11713 | 11806 | ** |
| | @@ -11754,17 +11847,17 @@ |
| 11754 | 11847 | #define SF_Resolved 0x0002 /* Identifiers have been resolved */ |
| 11755 | 11848 | #define SF_Aggregate 0x0004 /* Contains aggregate functions */ |
| 11756 | 11849 | #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */ |
| 11757 | 11850 | #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */ |
| 11758 | 11851 | #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ |
| 11759 | | - /* 0x0040 NOT USED */ |
| 11852 | +#define SF_Compound 0x0040 /* Part of a compound query */ |
| 11760 | 11853 | #define SF_Values 0x0080 /* Synthesized from VALUES clause */ |
| 11761 | 11854 | /* 0x0100 NOT USED */ |
| 11762 | 11855 | #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */ |
| 11763 | 11856 | #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */ |
| 11764 | 11857 | #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */ |
| 11765 | | -#define SF_Compound 0x1000 /* Part of a compound query */ |
| 11858 | +#define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */ |
| 11766 | 11859 | |
| 11767 | 11860 | |
| 11768 | 11861 | /* |
| 11769 | 11862 | ** The results of a SELECT can be distributed in several ways, as defined |
| 11770 | 11863 | ** by one of the following macros. The "SRT" prefix means "SELECT Result |
| | @@ -12362,12 +12455,12 @@ |
| 12362 | 12455 | #define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__) |
| 12363 | 12456 | |
| 12364 | 12457 | |
| 12365 | 12458 | /* |
| 12366 | 12459 | ** FTS4 is really an extension for FTS3. It is enabled using the |
| 12367 | | -** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also all |
| 12368 | | -** the SQLITE_ENABLE_FTS4 macro to serve as an alisse for SQLITE_ENABLE_FTS3. |
| 12460 | +** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call |
| 12461 | +** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3. |
| 12369 | 12462 | */ |
| 12370 | 12463 | #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3) |
| 12371 | 12464 | # define SQLITE_ENABLE_FTS3 |
| 12372 | 12465 | #endif |
| 12373 | 12466 | |
| | @@ -12410,19 +12503,19 @@ |
| 12410 | 12503 | SQLITE_PRIVATE int sqlite3Strlen30(const char*); |
| 12411 | 12504 | #define sqlite3StrNICmp sqlite3_strnicmp |
| 12412 | 12505 | |
| 12413 | 12506 | SQLITE_PRIVATE int sqlite3MallocInit(void); |
| 12414 | 12507 | SQLITE_PRIVATE void sqlite3MallocEnd(void); |
| 12415 | | -SQLITE_PRIVATE void *sqlite3Malloc(int); |
| 12416 | | -SQLITE_PRIVATE void *sqlite3MallocZero(int); |
| 12417 | | -SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3*, int); |
| 12418 | | -SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3*, int); |
| 12508 | +SQLITE_PRIVATE void *sqlite3Malloc(u64); |
| 12509 | +SQLITE_PRIVATE void *sqlite3MallocZero(u64); |
| 12510 | +SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3*, u64); |
| 12511 | +SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3*, u64); |
| 12419 | 12512 | SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*); |
| 12420 | | -SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, int); |
| 12421 | | -SQLITE_PRIVATE void *sqlite3Realloc(void*, int); |
| 12422 | | -SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, int); |
| 12423 | | -SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, int); |
| 12513 | +SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64); |
| 12514 | +SQLITE_PRIVATE void *sqlite3Realloc(void*, u64); |
| 12515 | +SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64); |
| 12516 | +SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64); |
| 12424 | 12517 | SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*); |
| 12425 | 12518 | SQLITE_PRIVATE int sqlite3MallocSize(void*); |
| 12426 | 12519 | SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*); |
| 12427 | 12520 | SQLITE_PRIVATE void *sqlite3ScratchMalloc(int); |
| 12428 | 12521 | SQLITE_PRIVATE void sqlite3ScratchFree(void*); |
| | @@ -12959,11 +13052,11 @@ |
| 12959 | 13052 | #endif |
| 12960 | 13053 | |
| 12961 | 13054 | /* |
| 12962 | 13055 | ** The interface to the LEMON-generated parser |
| 12963 | 13056 | */ |
| 12964 | | -SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(size_t)); |
| 13057 | +SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64)); |
| 12965 | 13058 | SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*)); |
| 12966 | 13059 | SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*); |
| 12967 | 13060 | #ifdef YYTRACKMAXSTACKDEPTH |
| 12968 | 13061 | SQLITE_PRIVATE int sqlite3ParserStackPeak(void*); |
| 12969 | 13062 | #endif |
| | @@ -13228,11 +13321,11 @@ |
| 13228 | 13321 | ** May you find forgiveness for yourself and forgive others. |
| 13229 | 13322 | ** May you share freely, never taking more than you give. |
| 13230 | 13323 | ** |
| 13231 | 13324 | ************************************************************************* |
| 13232 | 13325 | ** |
| 13233 | | -** This file contains definitions of global variables and contants. |
| 13326 | +** This file contains definitions of global variables and constants. |
| 13234 | 13327 | */ |
| 13235 | 13328 | |
| 13236 | 13329 | /* An array to map all upper-case characters into their corresponding |
| 13237 | 13330 | ** lower-case character. |
| 13238 | 13331 | ** |
| | @@ -13824,10 +13917,13 @@ |
| 13824 | 13917 | #if defined(SQLITE_THREADSAFE) |
| 13825 | 13918 | "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE), |
| 13826 | 13919 | #endif |
| 13827 | 13920 | #ifdef SQLITE_USE_ALLOCA |
| 13828 | 13921 | "USE_ALLOCA", |
| 13922 | +#endif |
| 13923 | +#ifdef SQLITE_USER_AUTHENTICATION |
| 13924 | + "USER_AUTHENTICATION", |
| 13829 | 13925 | #endif |
| 13830 | 13926 | #ifdef SQLITE_WIN32_MALLOC |
| 13831 | 13927 | "WIN32_MALLOC", |
| 13832 | 13928 | #endif |
| 13833 | 13929 | #ifdef SQLITE_ZERO_MALLOC |
| | @@ -14052,29 +14148,32 @@ |
| 14052 | 14148 | ** Internally, the vdbe manipulates nearly all SQL values as Mem |
| 14053 | 14149 | ** structures. Each Mem struct may cache multiple representations (string, |
| 14054 | 14150 | ** integer etc.) of the same value. |
| 14055 | 14151 | */ |
| 14056 | 14152 | struct Mem { |
| 14057 | | - sqlite3 *db; /* The associated database connection */ |
| 14058 | | - char *z; /* String or BLOB value */ |
| 14059 | | - double r; /* Real value */ |
| 14060 | | - union { |
| 14153 | + union MemValue { |
| 14154 | + double r; /* Real value used when MEM_Real is set in flags */ |
| 14061 | 14155 | i64 i; /* Integer value used when MEM_Int is set in flags */ |
| 14062 | 14156 | int nZero; /* Used when bit MEM_Zero is set in flags */ |
| 14063 | 14157 | FuncDef *pDef; /* Used only when flags==MEM_Agg */ |
| 14064 | 14158 | RowSet *pRowSet; /* Used only when flags==MEM_RowSet */ |
| 14065 | 14159 | VdbeFrame *pFrame; /* Used when flags==MEM_Frame */ |
| 14066 | 14160 | } u; |
| 14067 | | - int n; /* Number of characters in string value, excluding '\0' */ |
| 14068 | 14161 | u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ |
| 14069 | 14162 | u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */ |
| 14163 | + int n; /* Number of characters in string value, excluding '\0' */ |
| 14164 | + char *z; /* String or BLOB value */ |
| 14165 | + /* ShallowCopy only needs to copy the information above */ |
| 14166 | + char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */ |
| 14167 | + int szMalloc; /* Size of the zMalloc allocation */ |
| 14168 | + int iPadding1; /* Padding for 8-byte alignment */ |
| 14169 | + sqlite3 *db; /* The associated database connection */ |
| 14170 | + void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */ |
| 14070 | 14171 | #ifdef SQLITE_DEBUG |
| 14071 | 14172 | Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */ |
| 14072 | 14173 | void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */ |
| 14073 | 14174 | #endif |
| 14074 | | - void (*xDel)(void *); /* If not null, call this function to delete Mem.z */ |
| 14075 | | - char *zMalloc; /* Dynamic buffer allocated by sqlite3_malloc() */ |
| 14076 | 14175 | }; |
| 14077 | 14176 | |
| 14078 | 14177 | /* One or more of the following flags are set to indicate the validOK |
| 14079 | 14178 | ** representations of the value stored in the Mem struct. |
| 14080 | 14179 | ** |
| | @@ -14129,11 +14228,11 @@ |
| 14129 | 14228 | #ifdef SQLITE_DEBUG |
| 14130 | 14229 | #define memIsValid(M) ((M)->flags & MEM_Undefined)==0 |
| 14131 | 14230 | #endif |
| 14132 | 14231 | |
| 14133 | 14232 | /* |
| 14134 | | -** Each auxilliary data pointer stored by a user defined function |
| 14233 | +** Each auxiliary data pointer stored by a user defined function |
| 14135 | 14234 | ** implementation calling sqlite3_set_auxdata() is stored in an instance |
| 14136 | 14235 | ** of this structure. All such structures associated with a single VM |
| 14137 | 14236 | ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed |
| 14138 | 14237 | ** when the VM is halted (if not before). |
| 14139 | 14238 | */ |
| | @@ -14144,11 +14243,11 @@ |
| 14144 | 14243 | void (*xDelete)(void *); /* Destructor for the aux data */ |
| 14145 | 14244 | AuxData *pNext; /* Next element in list */ |
| 14146 | 14245 | }; |
| 14147 | 14246 | |
| 14148 | 14247 | /* |
| 14149 | | -** The "context" argument for a installable function. A pointer to an |
| 14248 | +** The "context" argument for an installable function. A pointer to an |
| 14150 | 14249 | ** instance of this structure is the first argument to the routines used |
| 14151 | 14250 | ** implement the SQL functions. |
| 14152 | 14251 | ** |
| 14153 | 14252 | ** There is a typedef for this structure in sqlite.h. So all routines, |
| 14154 | 14253 | ** even the public interface to SQLite, can use a pointer to this structure. |
| | @@ -14158,17 +14257,17 @@ |
| 14158 | 14257 | ** This structure is defined inside of vdbeInt.h because it uses substructures |
| 14159 | 14258 | ** (Mem) which are only defined there. |
| 14160 | 14259 | */ |
| 14161 | 14260 | struct sqlite3_context { |
| 14162 | 14261 | Mem *pOut; /* The return value is stored here */ |
| 14163 | | - FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */ |
| 14262 | + FuncDef *pFunc; /* Pointer to function information */ |
| 14164 | 14263 | Mem *pMem; /* Memory cell used to store aggregate context */ |
| 14165 | 14264 | CollSeq *pColl; /* Collating sequence */ |
| 14166 | 14265 | Vdbe *pVdbe; /* The VM that owns this context */ |
| 14167 | 14266 | int iOp; /* Instruction number of OP_Function */ |
| 14168 | 14267 | int isError; /* Error code returned by the function. */ |
| 14169 | | - u8 skipFlag; /* Skip skip accumulator loading if true */ |
| 14268 | + u8 skipFlag; /* Skip accumulator loading if true */ |
| 14170 | 14269 | u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */ |
| 14171 | 14270 | }; |
| 14172 | 14271 | |
| 14173 | 14272 | /* |
| 14174 | 14273 | ** An Explain object accumulates indented output which is helpful |
| | @@ -14287,12 +14386,12 @@ |
| 14287 | 14386 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); |
| 14288 | 14387 | SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| 14289 | 14388 | SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int); |
| 14290 | 14389 | |
| 14291 | 14390 | int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); |
| 14292 | | -SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*); |
| 14293 | | -SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *); |
| 14391 | +SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*); |
| 14392 | +SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*); |
| 14294 | 14393 | SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*); |
| 14295 | 14394 | SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*); |
| 14296 | 14395 | SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*); |
| 14297 | 14396 | SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int); |
| 14298 | 14397 | SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*); |
| | @@ -14305,10 +14404,11 @@ |
| 14305 | 14404 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 14306 | 14405 | # define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64 |
| 14307 | 14406 | #else |
| 14308 | 14407 | SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double); |
| 14309 | 14408 | #endif |
| 14409 | +SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem*,sqlite3*,u16); |
| 14310 | 14410 | SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*); |
| 14311 | 14411 | SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int); |
| 14312 | 14412 | SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*); |
| 14313 | 14413 | SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*); |
| 14314 | 14414 | SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8); |
| | @@ -14319,18 +14419,16 @@ |
| 14319 | 14419 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); |
| 14320 | 14420 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); |
| 14321 | 14421 | SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8); |
| 14322 | 14422 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*); |
| 14323 | 14423 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); |
| 14324 | | -SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p); |
| 14325 | 14424 | #define VdbeMemDynamic(X) \ |
| 14326 | 14425 | (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0) |
| 14327 | | -#define VdbeMemReleaseExtern(X) \ |
| 14328 | | - if( VdbeMemDynamic(X) ) sqlite3VdbeMemReleaseExternal(X); |
| 14329 | 14426 | SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); |
| 14330 | 14427 | SQLITE_PRIVATE const char *sqlite3OpcodeName(int); |
| 14331 | 14428 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); |
| 14429 | +SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int n); |
| 14332 | 14430 | SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int); |
| 14333 | 14431 | SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); |
| 14334 | 14432 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *); |
| 14335 | 14433 | SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p); |
| 14336 | 14434 | |
| | @@ -14653,11 +14751,11 @@ |
| 14653 | 14751 | ** calendar system. |
| 14654 | 14752 | ** |
| 14655 | 14753 | ** 1970-01-01 00:00:00 is JD 2440587.5 |
| 14656 | 14754 | ** 2000-01-01 00:00:00 is JD 2451544.5 |
| 14657 | 14755 | ** |
| 14658 | | -** This implemention requires years to be expressed as a 4-digit number |
| 14756 | +** This implementation requires years to be expressed as a 4-digit number |
| 14659 | 14757 | ** which means that only dates between 0000-01-01 and 9999-12-31 can |
| 14660 | 14758 | ** be represented, even though julian day numbers allow a much wider |
| 14661 | 14759 | ** range of dates. |
| 14662 | 14760 | ** |
| 14663 | 14761 | ** The Gregorian calendar system is used for all dates and times, |
| | @@ -16497,11 +16595,11 @@ |
| 16497 | 16595 | ** Like realloc(). Resize an allocation previously obtained from |
| 16498 | 16596 | ** sqlite3MemMalloc(). |
| 16499 | 16597 | ** |
| 16500 | 16598 | ** For this low-level interface, we know that pPrior!=0. Cases where |
| 16501 | 16599 | ** pPrior==0 while have been intercepted by higher-level routine and |
| 16502 | | -** redirected to xMalloc. Similarly, we know that nByte>0 becauses |
| 16600 | +** redirected to xMalloc. Similarly, we know that nByte>0 because |
| 16503 | 16601 | ** cases where nByte<=0 will have been intercepted by higher-level |
| 16504 | 16602 | ** routines and redirected to xFree. |
| 16505 | 16603 | */ |
| 16506 | 16604 | static void *sqlite3MemRealloc(void *pPrior, int nByte){ |
| 16507 | 16605 | #ifdef SQLITE_MALLOCSIZE |
| | @@ -17854,11 +17952,11 @@ |
| 17854 | 17952 | ** This memory allocator uses the following algorithm: |
| 17855 | 17953 | ** |
| 17856 | 17954 | ** 1. All memory allocations sizes are rounded up to a power of 2. |
| 17857 | 17955 | ** |
| 17858 | 17956 | ** 2. If two adjacent free blocks are the halves of a larger block, |
| 17859 | | -** then the two blocks are coalesed into the single larger block. |
| 17957 | +** then the two blocks are coalesced into the single larger block. |
| 17860 | 17958 | ** |
| 17861 | 17959 | ** 3. New memory is allocated from the first available free block. |
| 17862 | 17960 | ** |
| 17863 | 17961 | ** This algorithm is described in: J. M. Robson. "Bounds for Some Functions |
| 17864 | 17962 | ** Concerning Dynamic Storage Allocation". Journal of the Association for |
| | @@ -20081,27 +20179,25 @@ |
| 20081 | 20179 | |
| 20082 | 20180 | /* |
| 20083 | 20181 | ** Allocate memory. This routine is like sqlite3_malloc() except that it |
| 20084 | 20182 | ** assumes the memory subsystem has already been initialized. |
| 20085 | 20183 | */ |
| 20086 | | -SQLITE_PRIVATE void *sqlite3Malloc(int n){ |
| 20184 | +SQLITE_PRIVATE void *sqlite3Malloc(u64 n){ |
| 20087 | 20185 | void *p; |
| 20088 | | - if( n<=0 /* IMP: R-65312-04917 */ |
| 20089 | | - || n>=0x7fffff00 |
| 20090 | | - ){ |
| 20186 | + if( n==0 || n>=0x7fffff00 ){ |
| 20091 | 20187 | /* A memory allocation of a number of bytes which is near the maximum |
| 20092 | 20188 | ** signed integer value might cause an integer overflow inside of the |
| 20093 | 20189 | ** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving |
| 20094 | 20190 | ** 255 bytes of overhead. SQLite itself will never use anything near |
| 20095 | 20191 | ** this amount. The only way to reach the limit is with sqlite3_malloc() */ |
| 20096 | 20192 | p = 0; |
| 20097 | 20193 | }else if( sqlite3GlobalConfig.bMemstat ){ |
| 20098 | 20194 | sqlite3_mutex_enter(mem0.mutex); |
| 20099 | | - mallocWithAlarm(n, &p); |
| 20195 | + mallocWithAlarm((int)n, &p); |
| 20100 | 20196 | sqlite3_mutex_leave(mem0.mutex); |
| 20101 | 20197 | }else{ |
| 20102 | | - p = sqlite3GlobalConfig.m.xMalloc(n); |
| 20198 | + p = sqlite3GlobalConfig.m.xMalloc((int)n); |
| 20103 | 20199 | } |
| 20104 | 20200 | assert( EIGHT_BYTE_ALIGNMENT(p) ); /* IMP: R-04675-44850 */ |
| 20105 | 20201 | return p; |
| 20106 | 20202 | } |
| 20107 | 20203 | |
| | @@ -20112,10 +20208,16 @@ |
| 20112 | 20208 | */ |
| 20113 | 20209 | SQLITE_API void *sqlite3_malloc(int n){ |
| 20114 | 20210 | #ifndef SQLITE_OMIT_AUTOINIT |
| 20115 | 20211 | if( sqlite3_initialize() ) return 0; |
| 20116 | 20212 | #endif |
| 20213 | + return n<=0 ? 0 : sqlite3Malloc(n); |
| 20214 | +} |
| 20215 | +SQLITE_API void *sqlite3_malloc64(sqlite3_uint64 n){ |
| 20216 | +#ifndef SQLITE_OMIT_AUTOINIT |
| 20217 | + if( sqlite3_initialize() ) return 0; |
| 20218 | +#endif |
| 20117 | 20219 | return sqlite3Malloc(n); |
| 20118 | 20220 | } |
| 20119 | 20221 | |
| 20120 | 20222 | /* |
| 20121 | 20223 | ** Each thread may only have a single outstanding allocation from |
| | @@ -20234,21 +20336,27 @@ |
| 20234 | 20336 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 20235 | 20337 | assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) ); |
| 20236 | 20338 | return sqlite3GlobalConfig.m.xSize(p); |
| 20237 | 20339 | } |
| 20238 | 20340 | SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){ |
| 20239 | | - assert( db!=0 ); |
| 20240 | | - assert( sqlite3_mutex_held(db->mutex) ); |
| 20241 | | - if( isLookaside(db, p) ){ |
| 20242 | | - return db->lookaside.sz; |
| 20341 | + if( db==0 ){ |
| 20342 | + return sqlite3MallocSize(p); |
| 20243 | 20343 | }else{ |
| 20244 | | - assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); |
| 20245 | | - assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) ); |
| 20246 | | - assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); |
| 20247 | | - return sqlite3GlobalConfig.m.xSize(p); |
| 20344 | + assert( sqlite3_mutex_held(db->mutex) ); |
| 20345 | + if( isLookaside(db, p) ){ |
| 20346 | + return db->lookaside.sz; |
| 20347 | + }else{ |
| 20348 | + assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); |
| 20349 | + assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) ); |
| 20350 | + assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); |
| 20351 | + return sqlite3GlobalConfig.m.xSize(p); |
| 20352 | + } |
| 20248 | 20353 | } |
| 20249 | 20354 | } |
| 20355 | +SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){ |
| 20356 | + return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p); |
| 20357 | +} |
| 20250 | 20358 | |
| 20251 | 20359 | /* |
| 20252 | 20360 | ** Free memory previously obtained from sqlite3Malloc(). |
| 20253 | 20361 | */ |
| 20254 | 20362 | SQLITE_API void sqlite3_free(void *p){ |
| | @@ -20306,17 +20414,17 @@ |
| 20306 | 20414 | } |
| 20307 | 20415 | |
| 20308 | 20416 | /* |
| 20309 | 20417 | ** Change the size of an existing memory allocation |
| 20310 | 20418 | */ |
| 20311 | | -SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, int nBytes){ |
| 20419 | +SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){ |
| 20312 | 20420 | int nOld, nNew, nDiff; |
| 20313 | 20421 | void *pNew; |
| 20314 | 20422 | if( pOld==0 ){ |
| 20315 | 20423 | return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */ |
| 20316 | 20424 | } |
| 20317 | | - if( nBytes<=0 ){ |
| 20425 | + if( nBytes==0 ){ |
| 20318 | 20426 | sqlite3_free(pOld); /* IMP: R-31593-10574 */ |
| 20319 | 20427 | return 0; |
| 20320 | 20428 | } |
| 20321 | 20429 | if( nBytes>=0x7fffff00 ){ |
| 20322 | 20430 | /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */ |
| | @@ -20324,26 +20432,26 @@ |
| 20324 | 20432 | } |
| 20325 | 20433 | nOld = sqlite3MallocSize(pOld); |
| 20326 | 20434 | /* IMPLEMENTATION-OF: R-46199-30249 SQLite guarantees that the second |
| 20327 | 20435 | ** argument to xRealloc is always a value returned by a prior call to |
| 20328 | 20436 | ** xRoundup. */ |
| 20329 | | - nNew = sqlite3GlobalConfig.m.xRoundup(nBytes); |
| 20437 | + nNew = sqlite3GlobalConfig.m.xRoundup((int)nBytes); |
| 20330 | 20438 | if( nOld==nNew ){ |
| 20331 | 20439 | pNew = pOld; |
| 20332 | 20440 | }else if( sqlite3GlobalConfig.bMemstat ){ |
| 20333 | 20441 | sqlite3_mutex_enter(mem0.mutex); |
| 20334 | | - sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes); |
| 20442 | + sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes); |
| 20335 | 20443 | nDiff = nNew - nOld; |
| 20336 | 20444 | if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= |
| 20337 | 20445 | mem0.alarmThreshold-nDiff ){ |
| 20338 | 20446 | sqlite3MallocAlarm(nDiff); |
| 20339 | 20447 | } |
| 20340 | 20448 | assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) ); |
| 20341 | 20449 | assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) ); |
| 20342 | 20450 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 20343 | 20451 | if( pNew==0 && mem0.alarmCallback ){ |
| 20344 | | - sqlite3MallocAlarm(nBytes); |
| 20452 | + sqlite3MallocAlarm((int)nBytes); |
| 20345 | 20453 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 20346 | 20454 | } |
| 20347 | 20455 | if( pNew ){ |
| 20348 | 20456 | nNew = sqlite3MallocSize(pNew); |
| 20349 | 20457 | sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld); |
| | @@ -20362,33 +20470,40 @@ |
| 20362 | 20470 | */ |
| 20363 | 20471 | SQLITE_API void *sqlite3_realloc(void *pOld, int n){ |
| 20364 | 20472 | #ifndef SQLITE_OMIT_AUTOINIT |
| 20365 | 20473 | if( sqlite3_initialize() ) return 0; |
| 20366 | 20474 | #endif |
| 20475 | + if( n<0 ) n = 0; |
| 20476 | + return sqlite3Realloc(pOld, n); |
| 20477 | +} |
| 20478 | +SQLITE_API void *sqlite3_realloc64(void *pOld, sqlite3_uint64 n){ |
| 20479 | +#ifndef SQLITE_OMIT_AUTOINIT |
| 20480 | + if( sqlite3_initialize() ) return 0; |
| 20481 | +#endif |
| 20367 | 20482 | return sqlite3Realloc(pOld, n); |
| 20368 | 20483 | } |
| 20369 | 20484 | |
| 20370 | 20485 | |
| 20371 | 20486 | /* |
| 20372 | 20487 | ** Allocate and zero memory. |
| 20373 | 20488 | */ |
| 20374 | | -SQLITE_PRIVATE void *sqlite3MallocZero(int n){ |
| 20489 | +SQLITE_PRIVATE void *sqlite3MallocZero(u64 n){ |
| 20375 | 20490 | void *p = sqlite3Malloc(n); |
| 20376 | 20491 | if( p ){ |
| 20377 | | - memset(p, 0, n); |
| 20492 | + memset(p, 0, (size_t)n); |
| 20378 | 20493 | } |
| 20379 | 20494 | return p; |
| 20380 | 20495 | } |
| 20381 | 20496 | |
| 20382 | 20497 | /* |
| 20383 | 20498 | ** Allocate and zero memory. If the allocation fails, make |
| 20384 | 20499 | ** the mallocFailed flag in the connection pointer. |
| 20385 | 20500 | */ |
| 20386 | | -SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, int n){ |
| 20501 | +SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, u64 n){ |
| 20387 | 20502 | void *p = sqlite3DbMallocRaw(db, n); |
| 20388 | 20503 | if( p ){ |
| 20389 | | - memset(p, 0, n); |
| 20504 | + memset(p, 0, (size_t)n); |
| 20390 | 20505 | } |
| 20391 | 20506 | return p; |
| 20392 | 20507 | } |
| 20393 | 20508 | |
| 20394 | 20509 | /* |
| | @@ -20407,11 +20522,11 @@ |
| 20407 | 20522 | ** if( b ) a[10] = 9; |
| 20408 | 20523 | ** |
| 20409 | 20524 | ** In other words, if a subsequent malloc (ex: "b") worked, it is assumed |
| 20410 | 20525 | ** that all prior mallocs (ex: "a") worked too. |
| 20411 | 20526 | */ |
| 20412 | | -SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, int n){ |
| 20527 | +SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, u64 n){ |
| 20413 | 20528 | void *p; |
| 20414 | 20529 | assert( db==0 || sqlite3_mutex_held(db->mutex) ); |
| 20415 | 20530 | assert( db==0 || db->pnBytesFreed==0 ); |
| 20416 | 20531 | #ifndef SQLITE_OMIT_LOOKASIDE |
| 20417 | 20532 | if( db ){ |
| | @@ -20451,11 +20566,11 @@ |
| 20451 | 20566 | |
| 20452 | 20567 | /* |
| 20453 | 20568 | ** Resize the block of memory pointed to by p to n bytes. If the |
| 20454 | 20569 | ** resize fails, set the mallocFailed flag in the connection object. |
| 20455 | 20570 | */ |
| 20456 | | -SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){ |
| 20571 | +SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){ |
| 20457 | 20572 | void *pNew = 0; |
| 20458 | 20573 | assert( db!=0 ); |
| 20459 | 20574 | assert( sqlite3_mutex_held(db->mutex) ); |
| 20460 | 20575 | if( db->mallocFailed==0 ){ |
| 20461 | 20576 | if( p==0 ){ |
| | @@ -20472,11 +20587,11 @@ |
| 20472 | 20587 | } |
| 20473 | 20588 | }else{ |
| 20474 | 20589 | assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); |
| 20475 | 20590 | assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) ); |
| 20476 | 20591 | sqlite3MemdebugSetType(p, MEMTYPE_HEAP); |
| 20477 | | - pNew = sqlite3_realloc(p, n); |
| 20592 | + pNew = sqlite3_realloc64(p, n); |
| 20478 | 20593 | if( !pNew ){ |
| 20479 | 20594 | sqlite3MemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP); |
| 20480 | 20595 | db->mallocFailed = 1; |
| 20481 | 20596 | } |
| 20482 | 20597 | sqlite3MemdebugSetType(pNew, MEMTYPE_DB | |
| | @@ -20488,11 +20603,11 @@ |
| 20488 | 20603 | |
| 20489 | 20604 | /* |
| 20490 | 20605 | ** Attempt to reallocate p. If the reallocation fails, then free p |
| 20491 | 20606 | ** and set the mallocFailed flag in the database connection. |
| 20492 | 20607 | */ |
| 20493 | | -SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){ |
| 20608 | +SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, u64 n){ |
| 20494 | 20609 | void *pNew; |
| 20495 | 20610 | pNew = sqlite3DbRealloc(db, p, n); |
| 20496 | 20611 | if( !pNew ){ |
| 20497 | 20612 | sqlite3DbFree(db, p); |
| 20498 | 20613 | } |
| | @@ -20518,19 +20633,19 @@ |
| 20518 | 20633 | if( zNew ){ |
| 20519 | 20634 | memcpy(zNew, z, n); |
| 20520 | 20635 | } |
| 20521 | 20636 | return zNew; |
| 20522 | 20637 | } |
| 20523 | | -SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, int n){ |
| 20638 | +SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, u64 n){ |
| 20524 | 20639 | char *zNew; |
| 20525 | 20640 | if( z==0 ){ |
| 20526 | 20641 | return 0; |
| 20527 | 20642 | } |
| 20528 | 20643 | assert( (n&0x7fffffff)==n ); |
| 20529 | 20644 | zNew = sqlite3DbMallocRaw(db, n+1); |
| 20530 | 20645 | if( zNew ){ |
| 20531 | | - memcpy(zNew, z, n); |
| 20646 | + memcpy(zNew, z, (size_t)n); |
| 20532 | 20647 | zNew[n] = 0; |
| 20533 | 20648 | } |
| 20534 | 20649 | return zNew; |
| 20535 | 20650 | } |
| 20536 | 20651 | |
| | @@ -20599,10 +20714,25 @@ |
| 20599 | 20714 | ** This file contains code for a set of "printf"-like routines. These |
| 20600 | 20715 | ** routines format strings much like the printf() from the standard C |
| 20601 | 20716 | ** library, though the implementation here has enhancements to support |
| 20602 | 20717 | ** SQLlite. |
| 20603 | 20718 | */ |
| 20719 | + |
| 20720 | +/* |
| 20721 | +** If the strchrnul() library function is available, then set |
| 20722 | +** HAVE_STRCHRNUL. If that routine is not available, this module |
| 20723 | +** will supply its own. The built-in version is slower than |
| 20724 | +** the glibc version so the glibc version is definitely preferred. |
| 20725 | +*/ |
| 20726 | +#if !defined(HAVE_STRCHRNUL) |
| 20727 | +# if defined(linux) |
| 20728 | +# define HAVE_STRCHRNUL 1 |
| 20729 | +# else |
| 20730 | +# define HAVE_STRCHRNUL 0 |
| 20731 | +# endif |
| 20732 | +#endif |
| 20733 | + |
| 20604 | 20734 | |
| 20605 | 20735 | /* |
| 20606 | 20736 | ** Conversion types fall into various categories as defined by the |
| 20607 | 20737 | ** following enumeration. |
| 20608 | 20738 | */ |
| | @@ -20810,13 +20940,17 @@ |
| 20810 | 20940 | bArgList = useIntern = 0; |
| 20811 | 20941 | } |
| 20812 | 20942 | for(; (c=(*fmt))!=0; ++fmt){ |
| 20813 | 20943 | if( c!='%' ){ |
| 20814 | 20944 | bufpt = (char *)fmt; |
| 20815 | | - while( (c=(*++fmt))!='%' && c!=0 ){}; |
| 20945 | +#if HAVE_STRCHRNUL |
| 20946 | + fmt = strchrnul(fmt, '%'); |
| 20947 | +#else |
| 20948 | + do{ fmt++; }while( *fmt && *fmt != '%' ); |
| 20949 | +#endif |
| 20816 | 20950 | sqlite3StrAccumAppend(pAccum, bufpt, (int)(fmt - bufpt)); |
| 20817 | | - if( c==0 ) break; |
| 20951 | + if( *fmt==0 ) break; |
| 20818 | 20952 | } |
| 20819 | 20953 | if( (c=(*++fmt))==0 ){ |
| 20820 | 20954 | sqlite3StrAccumAppend(pAccum, "%", 1); |
| 20821 | 20955 | break; |
| 20822 | 20956 | } |
| | @@ -21490,11 +21624,11 @@ |
| 21490 | 21624 | return z; |
| 21491 | 21625 | } |
| 21492 | 21626 | |
| 21493 | 21627 | /* |
| 21494 | 21628 | ** Like sqlite3MPrintf(), but call sqlite3DbFree() on zStr after formatting |
| 21495 | | -** the string and before returnning. This routine is intended to be used |
| 21629 | +** the string and before returning. This routine is intended to be used |
| 21496 | 21630 | ** to modify an existing string. For example: |
| 21497 | 21631 | ** |
| 21498 | 21632 | ** x = sqlite3MPrintf(db, x, "prefix %s suffix", x); |
| 21499 | 21633 | ** |
| 21500 | 21634 | */ |
| | @@ -22341,16 +22475,17 @@ |
| 22341 | 22475 | pMem->n = (int)(z - zOut); |
| 22342 | 22476 | } |
| 22343 | 22477 | *z = 0; |
| 22344 | 22478 | assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len ); |
| 22345 | 22479 | |
| 22480 | + c = pMem->flags; |
| 22346 | 22481 | sqlite3VdbeMemRelease(pMem); |
| 22347 | | - pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem); |
| 22482 | + pMem->flags = MEM_Str|MEM_Term|(c&MEM_AffMask); |
| 22348 | 22483 | pMem->enc = desiredEnc; |
| 22349 | | - pMem->flags |= (MEM_Term); |
| 22350 | 22484 | pMem->z = (char*)zOut; |
| 22351 | 22485 | pMem->zMalloc = pMem->z; |
| 22486 | + pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z); |
| 22352 | 22487 | |
| 22353 | 22488 | translate_out: |
| 22354 | 22489 | #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG) |
| 22355 | 22490 | { |
| 22356 | 22491 | char zBuf[100]; |
| | @@ -22762,11 +22897,11 @@ |
| 22762 | 22897 | ** The return value is -1 if no dequoting occurs or the length of the |
| 22763 | 22898 | ** dequoted string, exclusive of the zero terminator, if dequoting does |
| 22764 | 22899 | ** occur. |
| 22765 | 22900 | ** |
| 22766 | 22901 | ** 2002-Feb-14: This routine is extended to remove MS-Access style |
| 22767 | | -** brackets from around identifers. For example: "[a-b-c]" becomes |
| 22902 | +** brackets from around identifiers. For example: "[a-b-c]" becomes |
| 22768 | 22903 | ** "a-b-c". |
| 22769 | 22904 | */ |
| 22770 | 22905 | SQLITE_PRIVATE int sqlite3Dequote(char *z){ |
| 22771 | 22906 | char quote; |
| 22772 | 22907 | int i, j; |
| | @@ -24872,10 +25007,18 @@ |
| 24872 | 25007 | # else |
| 24873 | 25008 | # define HAVE_MREMAP 0 |
| 24874 | 25009 | # endif |
| 24875 | 25010 | #endif |
| 24876 | 25011 | |
| 25012 | +/* |
| 25013 | +** Explicitly call the 64-bit version of lseek() on Android. Otherwise, lseek() |
| 25014 | +** is the 32-bit version, even if _FILE_OFFSET_BITS=64 is defined. |
| 25015 | +*/ |
| 25016 | +#ifdef __ANDROID__ |
| 25017 | +# define lseek lseek64 |
| 25018 | +#endif |
| 25019 | + |
| 24877 | 25020 | /* |
| 24878 | 25021 | ** Different Unix systems declare open() in different ways. Same use |
| 24879 | 25022 | ** open(const char*,int,mode_t). Others use open(const char*,int,...). |
| 24880 | 25023 | ** The difference is important when using a pointer to the function. |
| 24881 | 25024 | ** |
| | @@ -25204,11 +25347,11 @@ |
| 25204 | 25347 | |
| 25205 | 25348 | |
| 25206 | 25349 | #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 25207 | 25350 | /* |
| 25208 | 25351 | ** Helper function for printing out trace information from debugging |
| 25209 | | -** binaries. This returns the string represetation of the supplied |
| 25352 | +** binaries. This returns the string representation of the supplied |
| 25210 | 25353 | ** integer lock-type. |
| 25211 | 25354 | */ |
| 25212 | 25355 | static const char *azFileLock(int eFileLock){ |
| 25213 | 25356 | switch( eFileLock ){ |
| 25214 | 25357 | case NO_LOCK: return "NONE"; |
| | @@ -25281,13 +25424,26 @@ |
| 25281 | 25424 | #define osFcntl lockTrace |
| 25282 | 25425 | #endif /* SQLITE_LOCK_TRACE */ |
| 25283 | 25426 | |
| 25284 | 25427 | /* |
| 25285 | 25428 | ** Retry ftruncate() calls that fail due to EINTR |
| 25429 | +** |
| 25430 | +** All calls to ftruncate() within this file should be made through this wrapper. |
| 25431 | +** On the Android platform, bypassing the logic below could lead to a corrupt |
| 25432 | +** database. |
| 25286 | 25433 | */ |
| 25287 | 25434 | static int robust_ftruncate(int h, sqlite3_int64 sz){ |
| 25288 | 25435 | int rc; |
| 25436 | +#ifdef __ANDROID__ |
| 25437 | + /* On Android, ftruncate() always uses 32-bit offsets, even if |
| 25438 | + ** _FILE_OFFSET_BITS=64 is defined. This means it is unsafe to attempt to |
| 25439 | + ** truncate a file to any size larger than 2GiB. Silently ignore any |
| 25440 | + ** such attempts. */ |
| 25441 | + if( sz>(sqlite3_int64)0x7FFFFFFF ){ |
| 25442 | + rc = SQLITE_OK; |
| 25443 | + }else |
| 25444 | +#endif |
| 25289 | 25445 | do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR ); |
| 25290 | 25446 | return rc; |
| 25291 | 25447 | } |
| 25292 | 25448 | |
| 25293 | 25449 | /* |
| | @@ -27671,11 +27827,11 @@ |
| 27671 | 27827 | ** bytes into pBuf. Return the number of bytes actually read. |
| 27672 | 27828 | ** |
| 27673 | 27829 | ** NB: If you define USE_PREAD or USE_PREAD64, then it might also |
| 27674 | 27830 | ** be necessary to define _XOPEN_SOURCE to be 500. This varies from |
| 27675 | 27831 | ** one system to another. Since SQLite does not define USE_PREAD |
| 27676 | | -** any any form by default, we will not attempt to define _XOPEN_SOURCE. |
| 27832 | +** in any form by default, we will not attempt to define _XOPEN_SOURCE. |
| 27677 | 27833 | ** See tickets #2741 and #2681. |
| 27678 | 27834 | ** |
| 27679 | 27835 | ** To avoid stomping the errno value on a failed read the lastErrno value |
| 27680 | 27836 | ** is set before returning. |
| 27681 | 27837 | */ |
| | @@ -28168,11 +28324,11 @@ |
| 28168 | 28324 | */ |
| 28169 | 28325 | if( pFile->szChunk>0 ){ |
| 28170 | 28326 | nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; |
| 28171 | 28327 | } |
| 28172 | 28328 | |
| 28173 | | - rc = robust_ftruncate(pFile->h, (off_t)nByte); |
| 28329 | + rc = robust_ftruncate(pFile->h, nByte); |
| 28174 | 28330 | if( rc ){ |
| 28175 | 28331 | pFile->lastErrno = errno; |
| 28176 | 28332 | return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); |
| 28177 | 28333 | }else{ |
| 28178 | 28334 | #ifdef SQLITE_DEBUG |
| | @@ -28303,11 +28459,11 @@ |
| 28303 | 28459 | |
| 28304 | 28460 | return SQLITE_OK; |
| 28305 | 28461 | } |
| 28306 | 28462 | |
| 28307 | 28463 | /* |
| 28308 | | -** If *pArg is inititially negative then this is a query. Set *pArg to |
| 28464 | +** If *pArg is initially negative then this is a query. Set *pArg to |
| 28309 | 28465 | ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set. |
| 28310 | 28466 | ** |
| 28311 | 28467 | ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags. |
| 28312 | 28468 | */ |
| 28313 | 28469 | static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){ |
| | @@ -28510,11 +28666,11 @@ |
| 28510 | 28666 | |
| 28511 | 28667 | /* |
| 28512 | 28668 | ** Return the device characteristics for the file. |
| 28513 | 28669 | ** |
| 28514 | 28670 | ** This VFS is set up to return SQLITE_IOCAP_POWERSAFE_OVERWRITE by default. |
| 28515 | | -** However, that choice is contraversial since technically the underlying |
| 28671 | +** However, that choice is controversial since technically the underlying |
| 28516 | 28672 | ** file system does not always provide powersafe overwrites. (In other |
| 28517 | 28673 | ** words, after a power-loss event, parts of the file that were never |
| 28518 | 28674 | ** written might end up being altered.) However, non-PSOW behavior is very, |
| 28519 | 28675 | ** very rare. And asserting PSOW makes a large reduction in the amount |
| 28520 | 28676 | ** of required I/O for journaling, since a lot of padding is eliminated. |
| | @@ -29482,11 +29638,11 @@ |
| 29482 | 29638 | ** Most finder functions return a pointer to a fixed sqlite3_io_methods |
| 29483 | 29639 | ** object. The only interesting finder-function is autolockIoFinder, which |
| 29484 | 29640 | ** looks at the filesystem type and tries to guess the best locking |
| 29485 | 29641 | ** strategy from that. |
| 29486 | 29642 | ** |
| 29487 | | -** For finder-funtion F, two objects are created: |
| 29643 | +** For finder-function F, two objects are created: |
| 29488 | 29644 | ** |
| 29489 | 29645 | ** (1) The real finder-function named "FImpt()". |
| 29490 | 29646 | ** |
| 29491 | 29647 | ** (2) A constant pointer to this function named just "F". |
| 29492 | 29648 | ** |
| | @@ -29549,11 +29705,11 @@ |
| 29549 | 29705 | unixCheckReservedLock /* xCheckReservedLock method */ |
| 29550 | 29706 | ) |
| 29551 | 29707 | IOMETHODS( |
| 29552 | 29708 | nolockIoFinder, /* Finder function name */ |
| 29553 | 29709 | nolockIoMethods, /* sqlite3_io_methods object name */ |
| 29554 | | - 1, /* shared memory is disabled */ |
| 29710 | + 3, /* shared memory is disabled */ |
| 29555 | 29711 | nolockClose, /* xClose method */ |
| 29556 | 29712 | nolockLock, /* xLock method */ |
| 29557 | 29713 | nolockUnlock, /* xUnlock method */ |
| 29558 | 29714 | nolockCheckReservedLock /* xCheckReservedLock method */ |
| 29559 | 29715 | ) |
| | @@ -29744,11 +29900,11 @@ |
| 29744 | 29900 | *(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl; |
| 29745 | 29901 | |
| 29746 | 29902 | #endif /* OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE */ |
| 29747 | 29903 | |
| 29748 | 29904 | /* |
| 29749 | | -** An abstract type for a pointer to a IO method finder function: |
| 29905 | +** An abstract type for a pointer to an IO method finder function: |
| 29750 | 29906 | */ |
| 29751 | 29907 | typedef const sqlite3_io_methods *(*finder_type)(const char*,unixFile*); |
| 29752 | 29908 | |
| 29753 | 29909 | |
| 29754 | 29910 | /**************************************************************************** |
| | @@ -30058,11 +30214,11 @@ |
| 30058 | 30214 | ** For this reason, if an error occurs in the stat() call here, it is |
| 30059 | 30215 | ** ignored and -1 is returned. The caller will try to open a new file |
| 30060 | 30216 | ** descriptor on the same path, fail, and return an error to SQLite. |
| 30061 | 30217 | ** |
| 30062 | 30218 | ** Even if a subsequent open() call does succeed, the consequences of |
| 30063 | | - ** not searching for a resusable file descriptor are not dire. */ |
| 30219 | + ** not searching for a reusable file descriptor are not dire. */ |
| 30064 | 30220 | if( 0==osStat(zPath, &sStat) ){ |
| 30065 | 30221 | unixInodeInfo *pInode; |
| 30066 | 30222 | |
| 30067 | 30223 | unixEnterMutex(); |
| 30068 | 30224 | pInode = inodeList; |
| | @@ -30089,11 +30245,11 @@ |
| 30089 | 30245 | ** to create new files with. If no error occurs, then SQLITE_OK is returned |
| 30090 | 30246 | ** and a value suitable for passing as the third argument to open(2) is |
| 30091 | 30247 | ** written to *pMode. If an IO error occurs, an SQLite error code is |
| 30092 | 30248 | ** returned and the value of *pMode is not modified. |
| 30093 | 30249 | ** |
| 30094 | | -** In most cases cases, this routine sets *pMode to 0, which will become |
| 30250 | +** In most cases, this routine sets *pMode to 0, which will become |
| 30095 | 30251 | ** an indication to robust_open() to create the file using |
| 30096 | 30252 | ** SQLITE_DEFAULT_FILE_PERMISSIONS adjusted by the umask. |
| 30097 | 30253 | ** But if the file being opened is a WAL or regular journal file, then |
| 30098 | 30254 | ** this function queries the file-system for the permissions on the |
| 30099 | 30255 | ** corresponding database file and sets *pMode to this value. Whenever |
| | @@ -30881,11 +31037,11 @@ |
| 30881 | 31037 | ** by taking an sqlite-style shared lock on the conch file, reading the |
| 30882 | 31038 | ** contents and comparing the host's unique host ID (see below) and lock |
| 30883 | 31039 | ** proxy path against the values stored in the conch. The conch file is |
| 30884 | 31040 | ** stored in the same directory as the database file and the file name |
| 30885 | 31041 | ** is patterned after the database file name as ".<databasename>-conch". |
| 30886 | | -** If the conch file does not exist, or it's contents do not match the |
| 31042 | +** If the conch file does not exist, or its contents do not match the |
| 30887 | 31043 | ** host ID and/or proxy path, then the lock is escalated to an exclusive |
| 30888 | 31044 | ** lock and the conch file contents is updated with the host ID and proxy |
| 30889 | 31045 | ** path and the lock is downgraded to a shared lock again. If the conch |
| 30890 | 31046 | ** is held by another process (with a shared lock), the exclusive lock |
| 30891 | 31047 | ** will fail and SQLITE_BUSY is returned. |
| | @@ -30933,11 +31089,11 @@ |
| 30933 | 31089 | ** |
| 30934 | 31090 | ** As mentioned above, when compiled with SQLITE_PREFER_PROXY_LOCKING, |
| 30935 | 31091 | ** setting the environment variable SQLITE_FORCE_PROXY_LOCKING to 1 will |
| 30936 | 31092 | ** force proxy locking to be used for every database file opened, and 0 |
| 30937 | 31093 | ** will force automatic proxy locking to be disabled for all database |
| 30938 | | -** files (explicity calling the SQLITE_SET_LOCKPROXYFILE pragma or |
| 31094 | +** files (explicitly calling the SQLITE_SET_LOCKPROXYFILE pragma or |
| 30939 | 31095 | ** sqlite_file_control API is not affected by SQLITE_FORCE_PROXY_LOCKING). |
| 30940 | 31096 | */ |
| 30941 | 31097 | |
| 30942 | 31098 | /* |
| 30943 | 31099 | ** Proxy locking is only available on MacOSX |
| | @@ -33571,16 +33727,18 @@ |
| 33571 | 33727 | #else |
| 33572 | 33728 | osSleep(milliseconds); |
| 33573 | 33729 | #endif |
| 33574 | 33730 | } |
| 33575 | 33731 | |
| 33732 | +#if SQLITE_MAX_WORKER_THREADS>0 && !SQLITE_OS_WINRT && SQLITE_THREADSAFE>0 |
| 33576 | 33733 | SQLITE_PRIVATE DWORD sqlite3Win32Wait(HANDLE hObject){ |
| 33577 | 33734 | DWORD rc; |
| 33578 | 33735 | while( (rc = osWaitForSingleObjectEx(hObject, INFINITE, |
| 33579 | 33736 | TRUE))==WAIT_IO_COMPLETION ){} |
| 33580 | 33737 | return rc; |
| 33581 | 33738 | } |
| 33739 | +#endif |
| 33582 | 33740 | |
| 33583 | 33741 | /* |
| 33584 | 33742 | ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP, |
| 33585 | 33743 | ** or WinCE. Return false (zero) for Win95, Win98, or WinME. |
| 33586 | 33744 | ** |
| | @@ -33605,31 +33763,40 @@ |
| 33605 | 33763 | /* |
| 33606 | 33764 | ** This function determines if the machine is running a version of Windows |
| 33607 | 33765 | ** based on the NT kernel. |
| 33608 | 33766 | */ |
| 33609 | 33767 | SQLITE_API int sqlite3_win32_is_nt(void){ |
| 33610 | | -#if defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX |
| 33768 | +#if SQLITE_OS_WINRT |
| 33769 | + /* |
| 33770 | + ** NOTE: The WinRT sub-platform is always assumed to be based on the NT |
| 33771 | + ** kernel. |
| 33772 | + */ |
| 33773 | + return 1; |
| 33774 | +#elif defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX |
| 33611 | 33775 | if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){ |
| 33612 | | -#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ |
| 33613 | | - defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WIN8 |
| 33614 | | - OSVERSIONINFOW sInfo; |
| 33615 | | - sInfo.dwOSVersionInfoSize = sizeof(sInfo); |
| 33616 | | - osGetVersionExW(&sInfo); |
| 33617 | | - osInterlockedCompareExchange(&sqlite3_os_type, |
| 33618 | | - (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0); |
| 33619 | | -#elif defined(SQLITE_WIN32_HAS_ANSI) |
| 33776 | +#if defined(SQLITE_WIN32_HAS_ANSI) |
| 33620 | 33777 | OSVERSIONINFOA sInfo; |
| 33621 | 33778 | sInfo.dwOSVersionInfoSize = sizeof(sInfo); |
| 33622 | 33779 | osGetVersionExA(&sInfo); |
| 33780 | + osInterlockedCompareExchange(&sqlite3_os_type, |
| 33781 | + (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0); |
| 33782 | +#elif defined(SQLITE_WIN32_HAS_WIDE) |
| 33783 | + OSVERSIONINFOW sInfo; |
| 33784 | + sInfo.dwOSVersionInfoSize = sizeof(sInfo); |
| 33785 | + osGetVersionExW(&sInfo); |
| 33623 | 33786 | osInterlockedCompareExchange(&sqlite3_os_type, |
| 33624 | 33787 | (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0); |
| 33625 | 33788 | #endif |
| 33626 | 33789 | } |
| 33627 | 33790 | return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2; |
| 33628 | 33791 | #elif SQLITE_TEST |
| 33629 | 33792 | return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2; |
| 33630 | 33793 | #else |
| 33794 | + /* |
| 33795 | + ** NOTE: All sub-platforms where the GetVersionEx[AW] functions are |
| 33796 | + ** deprecated are always assumed to be based on the NT kernel. |
| 33797 | + */ |
| 33631 | 33798 | return 1; |
| 33632 | 33799 | #endif |
| 33633 | 33800 | } |
| 33634 | 33801 | |
| 33635 | 33802 | #ifdef SQLITE_WIN32_MALLOC |
| | @@ -35402,11 +35569,11 @@ |
| 35402 | 35569 | pFile->h, pFile->locktype, sqlite3ErrName(rc))); |
| 35403 | 35570 | return rc; |
| 35404 | 35571 | } |
| 35405 | 35572 | |
| 35406 | 35573 | /* |
| 35407 | | -** If *pArg is inititially negative then this is a query. Set *pArg to |
| 35574 | +** If *pArg is initially negative then this is a query. Set *pArg to |
| 35408 | 35575 | ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set. |
| 35409 | 35576 | ** |
| 35410 | 35577 | ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags. |
| 35411 | 35578 | */ |
| 35412 | 35579 | static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){ |
| | @@ -36416,11 +36583,11 @@ |
| 36416 | 36583 | if( p ){ |
| 36417 | 36584 | pFd->nFetchOut--; |
| 36418 | 36585 | }else{ |
| 36419 | 36586 | /* FIXME: If Windows truly always prevents truncating or deleting a |
| 36420 | 36587 | ** file while a mapping is held, then the following winUnmapfile() call |
| 36421 | | - ** is unnecessary can can be omitted - potentially improving |
| 36588 | + ** is unnecessary can be omitted - potentially improving |
| 36422 | 36589 | ** performance. */ |
| 36423 | 36590 | winUnmapfile(pFd); |
| 36424 | 36591 | } |
| 36425 | 36592 | |
| 36426 | 36593 | assert( pFd->nFetchOut>=0 ); |
| | @@ -38274,27 +38441,10 @@ |
| 38274 | 38441 | # define expensive_assert(X) |
| 38275 | 38442 | #endif |
| 38276 | 38443 | |
| 38277 | 38444 | /********************************** Linked List Management ********************/ |
| 38278 | 38445 | |
| 38279 | | -#if !defined(NDEBUG) && defined(SQLITE_ENABLE_EXPENSIVE_ASSERT) |
| 38280 | | -/* |
| 38281 | | -** Check that the pCache->pSynced variable is set correctly. If it |
| 38282 | | -** is not, either fail an assert or return zero. Otherwise, return |
| 38283 | | -** non-zero. This is only used in debugging builds, as follows: |
| 38284 | | -** |
| 38285 | | -** expensive_assert( pcacheCheckSynced(pCache) ); |
| 38286 | | -*/ |
| 38287 | | -static int pcacheCheckSynced(PCache *pCache){ |
| 38288 | | - PgHdr *p; |
| 38289 | | - for(p=pCache->pDirtyTail; p!=pCache->pSynced; p=p->pDirtyPrev){ |
| 38290 | | - assert( p->nRef || (p->flags&PGHDR_NEED_SYNC) ); |
| 38291 | | - } |
| 38292 | | - return (p==0 || p->nRef || (p->flags&PGHDR_NEED_SYNC)==0); |
| 38293 | | -} |
| 38294 | | -#endif /* !NDEBUG && SQLITE_ENABLE_EXPENSIVE_ASSERT */ |
| 38295 | | - |
| 38296 | 38446 | /* Allowed values for second argument to pcacheManageDirtyList() */ |
| 38297 | 38447 | #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */ |
| 38298 | 38448 | #define PCACHE_DIRTYLIST_ADD 2 /* Add pPage to the dirty list */ |
| 38299 | 38449 | #define PCACHE_DIRTYLIST_FRONT 3 /* Move pPage to the front of the list */ |
| 38300 | 38450 | |
| | @@ -38336,31 +38486,29 @@ |
| 38336 | 38486 | p->eCreate = 2; |
| 38337 | 38487 | } |
| 38338 | 38488 | } |
| 38339 | 38489 | pPage->pDirtyNext = 0; |
| 38340 | 38490 | pPage->pDirtyPrev = 0; |
| 38341 | | - expensive_assert( pcacheCheckSynced(p) ); |
| 38342 | 38491 | } |
| 38343 | 38492 | if( addRemove & PCACHE_DIRTYLIST_ADD ){ |
| 38344 | 38493 | assert( pPage->pDirtyNext==0 && pPage->pDirtyPrev==0 && p->pDirty!=pPage ); |
| 38345 | 38494 | |
| 38346 | 38495 | pPage->pDirtyNext = p->pDirty; |
| 38347 | 38496 | if( pPage->pDirtyNext ){ |
| 38348 | 38497 | assert( pPage->pDirtyNext->pDirtyPrev==0 ); |
| 38349 | 38498 | pPage->pDirtyNext->pDirtyPrev = pPage; |
| 38350 | | - }else if( p->bPurgeable ){ |
| 38351 | | - assert( p->eCreate==2 ); |
| 38352 | | - p->eCreate = 1; |
| 38353 | | - } |
| 38354 | | - p->pDirty = pPage; |
| 38355 | | - if( !p->pDirtyTail ){ |
| 38499 | + }else{ |
| 38356 | 38500 | p->pDirtyTail = pPage; |
| 38501 | + if( p->bPurgeable ){ |
| 38502 | + assert( p->eCreate==2 ); |
| 38503 | + p->eCreate = 1; |
| 38504 | + } |
| 38357 | 38505 | } |
| 38506 | + p->pDirty = pPage; |
| 38358 | 38507 | if( !p->pSynced && 0==(pPage->flags&PGHDR_NEED_SYNC) ){ |
| 38359 | 38508 | p->pSynced = pPage; |
| 38360 | 38509 | } |
| 38361 | | - expensive_assert( pcacheCheckSynced(p) ); |
| 38362 | 38510 | } |
| 38363 | 38511 | } |
| 38364 | 38512 | |
| 38365 | 38513 | /* |
| 38366 | 38514 | ** Wrapper around the pluggable caches xUnpin method. If the cache is |
| | @@ -38533,11 +38681,10 @@ |
| 38533 | 38681 | /* Find a dirty page to write-out and recycle. First try to find a |
| 38534 | 38682 | ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC |
| 38535 | 38683 | ** cleared), but if that is not possible settle for any other |
| 38536 | 38684 | ** unreferenced dirty page. |
| 38537 | 38685 | */ |
| 38538 | | - expensive_assert( pcacheCheckSynced(pCache) ); |
| 38539 | 38686 | for(pPg=pCache->pSynced; |
| 38540 | 38687 | pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC)); |
| 38541 | 38688 | pPg=pPg->pDirtyPrev |
| 38542 | 38689 | ); |
| 38543 | 38690 | pCache->pSynced = pPg; |
| | @@ -38619,20 +38766,20 @@ |
| 38619 | 38766 | return pPgHdr; |
| 38620 | 38767 | } |
| 38621 | 38768 | |
| 38622 | 38769 | /* |
| 38623 | 38770 | ** Decrement the reference count on a page. If the page is clean and the |
| 38624 | | -** reference count drops to 0, then it is made elible for recycling. |
| 38771 | +** reference count drops to 0, then it is made eligible for recycling. |
| 38625 | 38772 | */ |
| 38626 | 38773 | SQLITE_PRIVATE void SQLITE_NOINLINE sqlite3PcacheRelease(PgHdr *p){ |
| 38627 | 38774 | assert( p->nRef>0 ); |
| 38628 | 38775 | p->nRef--; |
| 38629 | 38776 | if( p->nRef==0 ){ |
| 38630 | 38777 | p->pCache->nRef--; |
| 38631 | 38778 | if( (p->flags&PGHDR_DIRTY)==0 ){ |
| 38632 | 38779 | pcacheUnpin(p); |
| 38633 | | - }else{ |
| 38780 | + }else if( p->pDirtyPrev!=0 ){ |
| 38634 | 38781 | /* Move the page to the head of the dirty list. */ |
| 38635 | 38782 | pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT); |
| 38636 | 38783 | } |
| 38637 | 38784 | } |
| 38638 | 38785 | } |
| | @@ -38931,11 +39078,11 @@ |
| 38931 | 39078 | ************************************************************************* |
| 38932 | 39079 | ** |
| 38933 | 39080 | ** This file implements the default page cache implementation (the |
| 38934 | 39081 | ** sqlite3_pcache interface). It also contains part of the implementation |
| 38935 | 39082 | ** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features. |
| 38936 | | -** If the default page cache implementation is overriden, then neither of |
| 39083 | +** If the default page cache implementation is overridden, then neither of |
| 38937 | 39084 | ** these two features are available. |
| 38938 | 39085 | */ |
| 38939 | 39086 | |
| 38940 | 39087 | |
| 38941 | 39088 | typedef struct PCache1 PCache1; |
| | @@ -38942,11 +39089,11 @@ |
| 38942 | 39089 | typedef struct PgHdr1 PgHdr1; |
| 38943 | 39090 | typedef struct PgFreeslot PgFreeslot; |
| 38944 | 39091 | typedef struct PGroup PGroup; |
| 38945 | 39092 | |
| 38946 | 39093 | /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set |
| 38947 | | -** of one or more PCaches that are able to recycle each others unpinned |
| 39094 | +** of one or more PCaches that are able to recycle each other's unpinned |
| 38948 | 39095 | ** pages when they are under memory pressure. A PGroup is an instance of |
| 38949 | 39096 | ** the following object. |
| 38950 | 39097 | ** |
| 38951 | 39098 | ** This page cache implementation works in one of two modes: |
| 38952 | 39099 | ** |
| | @@ -40009,11 +40156,11 @@ |
| 40009 | 40156 | ** a non-zero batch number, it will see all prior INSERTs. |
| 40010 | 40157 | ** |
| 40011 | 40158 | ** No INSERTs may occurs after a SMALLEST. An assertion will fail if |
| 40012 | 40159 | ** that is attempted. |
| 40013 | 40160 | ** |
| 40014 | | -** The cost of an INSERT is roughly constant. (Sometime new memory |
| 40161 | +** The cost of an INSERT is roughly constant. (Sometimes new memory |
| 40015 | 40162 | ** has to be allocated on an INSERT.) The cost of a TEST with a new |
| 40016 | 40163 | ** batch number is O(NlogN) where N is the number of elements in the RowSet. |
| 40017 | 40164 | ** The cost of a TEST using the same batch number is O(logN). The cost |
| 40018 | 40165 | ** of the first SMALLEST is O(NlogN). Second and subsequent SMALLEST |
| 40019 | 40166 | ** primitives are constant time. The cost of DESTROY is O(N). |
| | @@ -40401,12 +40548,12 @@ |
| 40401 | 40548 | |
| 40402 | 40549 | /* |
| 40403 | 40550 | ** Check to see if element iRowid was inserted into the rowset as |
| 40404 | 40551 | ** part of any insert batch prior to iBatch. Return 1 or 0. |
| 40405 | 40552 | ** |
| 40406 | | -** If this is the first test of a new batch and if there exist entires |
| 40407 | | -** on pRowSet->pEntry, then sort those entires into the forest at |
| 40553 | +** If this is the first test of a new batch and if there exist entries |
| 40554 | +** on pRowSet->pEntry, then sort those entries into the forest at |
| 40408 | 40555 | ** pRowSet->pForest so that they can be tested. |
| 40409 | 40556 | */ |
| 40410 | 40557 | SQLITE_PRIVATE int sqlite3RowSetTest(RowSet *pRowSet, int iBatch, sqlite3_int64 iRowid){ |
| 40411 | 40558 | struct RowSetEntry *p, *pTree; |
| 40412 | 40559 | |
| | @@ -40684,16 +40831,16 @@ |
| 40684 | 40831 | ** are synced prior to the master journal being deleted. |
| 40685 | 40832 | ** |
| 40686 | 40833 | ** Definition: Two databases (or the same database at two points it time) |
| 40687 | 40834 | ** are said to be "logically equivalent" if they give the same answer to |
| 40688 | 40835 | ** all queries. Note in particular the content of freelist leaf |
| 40689 | | -** pages can be changed arbitarily without effecting the logical equivalence |
| 40836 | +** pages can be changed arbitrarily without affecting the logical equivalence |
| 40690 | 40837 | ** of the database. |
| 40691 | 40838 | ** |
| 40692 | 40839 | ** (7) At any time, if any subset, including the empty set and the total set, |
| 40693 | 40840 | ** of the unsynced changes to a rollback journal are removed and the |
| 40694 | | -** journal is rolled back, the resulting database file will be logical |
| 40841 | +** journal is rolled back, the resulting database file will be logically |
| 40695 | 40842 | ** equivalent to the database file at the beginning of the transaction. |
| 40696 | 40843 | ** |
| 40697 | 40844 | ** (8) When a transaction is rolled back, the xTruncate method of the VFS |
| 40698 | 40845 | ** is called to restore the database file to the same size it was at |
| 40699 | 40846 | ** the beginning of the transaction. (In some VFSes, the xTruncate |
| | @@ -40986,11 +41133,11 @@ |
| 40986 | 41133 | ** be a few redundant xLock() calls or a lock may be held for longer than |
| 40987 | 41134 | ** required, but nothing really goes wrong. |
| 40988 | 41135 | ** |
| 40989 | 41136 | ** The exception is when the database file is unlocked as the pager moves |
| 40990 | 41137 | ** from ERROR to OPEN state. At this point there may be a hot-journal file |
| 40991 | | -** in the file-system that needs to be rolled back (as part of a OPEN->SHARED |
| 41138 | +** in the file-system that needs to be rolled back (as part of an OPEN->SHARED |
| 40992 | 41139 | ** transition, by the same pager or any other). If the call to xUnlock() |
| 40993 | 41140 | ** fails at this point and the pager is left holding an EXCLUSIVE lock, this |
| 40994 | 41141 | ** can confuse the call to xCheckReservedLock() call made later as part |
| 40995 | 41142 | ** of hot-journal detection. |
| 40996 | 41143 | ** |
| | @@ -41069,11 +41216,11 @@ |
| 41069 | 41216 | #define SPILLFLAG_OFF 0x01 /* Never spill cache. Set via pragma */ |
| 41070 | 41217 | #define SPILLFLAG_ROLLBACK 0x02 /* Current rolling back, so do not spill */ |
| 41071 | 41218 | #define SPILLFLAG_NOSYNC 0x04 /* Spill is ok, but do not sync */ |
| 41072 | 41219 | |
| 41073 | 41220 | /* |
| 41074 | | -** A open page cache is an instance of struct Pager. A description of |
| 41221 | +** An open page cache is an instance of struct Pager. A description of |
| 41075 | 41222 | ** some of the more important member variables follows: |
| 41076 | 41223 | ** |
| 41077 | 41224 | ** eState |
| 41078 | 41225 | ** |
| 41079 | 41226 | ** The current 'state' of the pager object. See the comment and state |
| | @@ -41241,11 +41388,11 @@ |
| 41241 | 41388 | u8 readOnly; /* True for a read-only database */ |
| 41242 | 41389 | u8 memDb; /* True to inhibit all file I/O */ |
| 41243 | 41390 | |
| 41244 | 41391 | /************************************************************************** |
| 41245 | 41392 | ** The following block contains those class members that change during |
| 41246 | | - ** routine opertion. Class members not in this block are either fixed |
| 41393 | + ** routine operation. Class members not in this block are either fixed |
| 41247 | 41394 | ** when the pager is first created or else only change when there is a |
| 41248 | 41395 | ** significant mode change (such as changing the page_size, locking_mode, |
| 41249 | 41396 | ** or the journal_mode). From another view, these class members describe |
| 41250 | 41397 | ** the "state" of the pager, while other class members describe the |
| 41251 | 41398 | ** "configuration" of the pager. |
| | @@ -43036,11 +43183,11 @@ |
| 43036 | 43183 | ** journal files extracted from regular rollback-journals. |
| 43037 | 43184 | */ |
| 43038 | 43185 | rc = sqlite3OsFileSize(pMaster, &nMasterJournal); |
| 43039 | 43186 | if( rc!=SQLITE_OK ) goto delmaster_out; |
| 43040 | 43187 | nMasterPtr = pVfs->mxPathname+1; |
| 43041 | | - zMasterJournal = sqlite3Malloc((int)nMasterJournal + nMasterPtr + 1); |
| 43188 | + zMasterJournal = sqlite3Malloc(nMasterJournal + nMasterPtr + 1); |
| 43042 | 43189 | if( !zMasterJournal ){ |
| 43043 | 43190 | rc = SQLITE_NOMEM; |
| 43044 | 43191 | goto delmaster_out; |
| 43045 | 43192 | } |
| 43046 | 43193 | zMasterPtr = &zMasterJournal[nMasterJournal+1]; |
| | @@ -43105,11 +43252,11 @@ |
| 43105 | 43252 | ** DBMOD or OPEN state, this function is a no-op. Otherwise, the size |
| 43106 | 43253 | ** of the file is changed to nPage pages (nPage*pPager->pageSize bytes). |
| 43107 | 43254 | ** If the file on disk is currently larger than nPage pages, then use the VFS |
| 43108 | 43255 | ** xTruncate() method to truncate it. |
| 43109 | 43256 | ** |
| 43110 | | -** Or, it might might be the case that the file on disk is smaller than |
| 43257 | +** Or, it might be the case that the file on disk is smaller than |
| 43111 | 43258 | ** nPage pages. Some operating system implementations can get confused if |
| 43112 | 43259 | ** you try to truncate a file to some size that is larger than it |
| 43113 | 43260 | ** currently is, so detect this case and write a single zero byte to |
| 43114 | 43261 | ** the end of the new file instead. |
| 43115 | 43262 | ** |
| | @@ -43164,11 +43311,11 @@ |
| 43164 | 43311 | } |
| 43165 | 43312 | |
| 43166 | 43313 | /* |
| 43167 | 43314 | ** Set the value of the Pager.sectorSize variable for the given |
| 43168 | 43315 | ** pager based on the value returned by the xSectorSize method |
| 43169 | | -** of the open database file. The sector size will be used used |
| 43316 | +** of the open database file. The sector size will be used |
| 43170 | 43317 | ** to determine the size and alignment of journal header and |
| 43171 | 43318 | ** master journal pointers within created journal files. |
| 43172 | 43319 | ** |
| 43173 | 43320 | ** For temporary files the effective sector size is always 512 bytes. |
| 43174 | 43321 | ** |
| | @@ -44226,16 +44373,18 @@ |
| 44226 | 44373 | if( !pNew ) rc = SQLITE_NOMEM; |
| 44227 | 44374 | } |
| 44228 | 44375 | |
| 44229 | 44376 | if( rc==SQLITE_OK ){ |
| 44230 | 44377 | pager_reset(pPager); |
| 44231 | | - pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize); |
| 44232 | | - pPager->pageSize = pageSize; |
| 44233 | 44378 | sqlite3PageFree(pPager->pTmpSpace); |
| 44234 | 44379 | pPager->pTmpSpace = pNew; |
| 44235 | 44380 | rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize); |
| 44236 | 44381 | } |
| 44382 | + if( rc==SQLITE_OK ){ |
| 44383 | + pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize); |
| 44384 | + pPager->pageSize = pageSize; |
| 44385 | + } |
| 44237 | 44386 | } |
| 44238 | 44387 | |
| 44239 | 44388 | *pPageSize = pPager->pageSize; |
| 44240 | 44389 | if( rc==SQLITE_OK ){ |
| 44241 | 44390 | if( nReserve<0 ) nReserve = pPager->nReserve; |
| | @@ -44364,11 +44513,11 @@ |
| 44364 | 44513 | */ |
| 44365 | 44514 | static int pager_wait_on_lock(Pager *pPager, int locktype){ |
| 44366 | 44515 | int rc; /* Return code */ |
| 44367 | 44516 | |
| 44368 | 44517 | /* Check that this is either a no-op (because the requested lock is |
| 44369 | | - ** already held, or one of the transistions that the busy-handler |
| 44518 | + ** already held), or one of the transitions that the busy-handler |
| 44370 | 44519 | ** may be invoked during, according to the comment above |
| 44371 | 44520 | ** sqlite3PagerSetBusyhandler(). |
| 44372 | 44521 | */ |
| 44373 | 44522 | assert( (pPager->eLock>=locktype) |
| 44374 | 44523 | || (pPager->eLock==NO_LOCK && locktype==SHARED_LOCK) |
| | @@ -44992,11 +45141,11 @@ |
| 44992 | 45141 | ** The doNotSpill ROLLBACK and OFF bits inhibits all cache spilling |
| 44993 | 45142 | ** regardless of whether or not a sync is required. This is set during |
| 44994 | 45143 | ** a rollback or by user request, respectively. |
| 44995 | 45144 | ** |
| 44996 | 45145 | ** Spilling is also prohibited when in an error state since that could |
| 44997 | | - ** lead to database corruption. In the current implementaton it |
| 45146 | + ** lead to database corruption. In the current implementation it |
| 44998 | 45147 | ** is impossible for sqlite3PcacheFetch() to be called with createFlag==3 |
| 44999 | 45148 | ** while in the error state, hence it is impossible for this routine to |
| 45000 | 45149 | ** be called in the error state. Nevertheless, we include a NEVER() |
| 45001 | 45150 | ** test for the error state as a safeguard against future changes. |
| 45002 | 45151 | */ |
| | @@ -45532,11 +45681,11 @@ |
| 45532 | 45681 | sqlite3OsClose(pPager->jfd); |
| 45533 | 45682 | } |
| 45534 | 45683 | *pExists = (first!=0); |
| 45535 | 45684 | }else if( rc==SQLITE_CANTOPEN ){ |
| 45536 | 45685 | /* If we cannot open the rollback journal file in order to see if |
| 45537 | | - ** its has a zero header, that might be due to an I/O error, or |
| 45686 | + ** it has a zero header, that might be due to an I/O error, or |
| 45538 | 45687 | ** it might be due to the race condition described above and in |
| 45539 | 45688 | ** ticket #3883. Either way, assume that the journal is hot. |
| 45540 | 45689 | ** This might be a false positive. But if it is, then the |
| 45541 | 45690 | ** automatic journal playback and recovery mechanism will deal |
| 45542 | 45691 | ** with it under an EXCLUSIVE lock where we do not need to |
| | @@ -47836,11 +47985,11 @@ |
| 47836 | 47985 | ** frames, return the size in bytes of the page images stored within the |
| 47837 | 47986 | ** WAL frames. Otherwise, if this is not a WAL database or the WAL file |
| 47838 | 47987 | ** is empty, return 0. |
| 47839 | 47988 | */ |
| 47840 | 47989 | SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){ |
| 47841 | | - assert( pPager->eState==PAGER_READER ); |
| 47990 | + assert( pPager->eState>=PAGER_READER ); |
| 47842 | 47991 | return sqlite3WalFramesize(pPager->pWal); |
| 47843 | 47992 | } |
| 47844 | 47993 | #endif |
| 47845 | 47994 | |
| 47846 | 47995 | #endif /* SQLITE_OMIT_DISKIO */ |
| | @@ -48420,11 +48569,11 @@ |
| 48420 | 48569 | |
| 48421 | 48570 | /* |
| 48422 | 48571 | ** The argument to this macro must be of type u32. On a little-endian |
| 48423 | 48572 | ** architecture, it returns the u32 value that results from interpreting |
| 48424 | 48573 | ** the 4 bytes as a big-endian value. On a big-endian architecture, it |
| 48425 | | -** returns the value that would be produced by intepreting the 4 bytes |
| 48574 | +** returns the value that would be produced by interpreting the 4 bytes |
| 48426 | 48575 | ** of the input value as a little-endian integer. |
| 48427 | 48576 | */ |
| 48428 | 48577 | #define BYTESWAP32(x) ( \ |
| 48429 | 48578 | (((x)&0x000000FF)<<24) + (((x)&0x0000FF00)<<8) \ |
| 48430 | 48579 | + (((x)&0x00FF0000)>>8) + (((x)&0xFF000000)>>24) \ |
| | @@ -48834,11 +48983,11 @@ |
| 48834 | 48983 | |
| 48835 | 48984 | idx = iFrame - iZero; |
| 48836 | 48985 | assert( idx <= HASHTABLE_NSLOT/2 + 1 ); |
| 48837 | 48986 | |
| 48838 | 48987 | /* If this is the first entry to be added to this hash-table, zero the |
| 48839 | | - ** entire hash table and aPgno[] array before proceding. |
| 48988 | + ** entire hash table and aPgno[] array before proceeding. |
| 48840 | 48989 | */ |
| 48841 | 48990 | if( idx==1 ){ |
| 48842 | 48991 | int nByte = (int)((u8 *)&aHash[HASHTABLE_NSLOT] - (u8 *)&aPgno[1]); |
| 48843 | 48992 | memset((void*)&aPgno[1], 0, nByte); |
| 48844 | 48993 | } |
| | @@ -49492,11 +49641,11 @@ |
| 49492 | 49641 | ** WAL content is copied into the database file. This second fsync makes |
| 49493 | 49642 | ** it safe to delete the WAL since the new content will persist in the |
| 49494 | 49643 | ** database file. |
| 49495 | 49644 | ** |
| 49496 | 49645 | ** This routine uses and updates the nBackfill field of the wal-index header. |
| 49497 | | -** This is the only routine tha will increase the value of nBackfill. |
| 49646 | +** This is the only routine that will increase the value of nBackfill. |
| 49498 | 49647 | ** (A WAL reset or recovery will revert nBackfill to zero, but not increase |
| 49499 | 49648 | ** its value.) |
| 49500 | 49649 | ** |
| 49501 | 49650 | ** The caller must be holding sufficient locks to ensure that no other |
| 49502 | 49651 | ** checkpoint is running (in any other thread or process) at the same |
| | @@ -49796,11 +49945,11 @@ |
| 49796 | 49945 | ** Read the wal-index header from the wal-index and into pWal->hdr. |
| 49797 | 49946 | ** If the wal-header appears to be corrupt, try to reconstruct the |
| 49798 | 49947 | ** wal-index from the WAL before returning. |
| 49799 | 49948 | ** |
| 49800 | 49949 | ** Set *pChanged to 1 if the wal-index header value in pWal->hdr is |
| 49801 | | -** changed by this opertion. If pWal->hdr is unchanged, set *pChanged |
| 49950 | +** changed by this operation. If pWal->hdr is unchanged, set *pChanged |
| 49802 | 49951 | ** to 0. |
| 49803 | 49952 | ** |
| 49804 | 49953 | ** If the wal-index header is successfully read, return SQLITE_OK. |
| 49805 | 49954 | ** Otherwise an SQLite error code. |
| 49806 | 49955 | */ |
| | @@ -50000,11 +50149,11 @@ |
| 50000 | 50149 | if( memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr)) ){ |
| 50001 | 50150 | /* It is not safe to allow the reader to continue here if frames |
| 50002 | 50151 | ** may have been appended to the log before READ_LOCK(0) was obtained. |
| 50003 | 50152 | ** When holding READ_LOCK(0), the reader ignores the entire log file, |
| 50004 | 50153 | ** which implies that the database file contains a trustworthy |
| 50005 | | - ** snapshoT. Since holding READ_LOCK(0) prevents a checkpoint from |
| 50154 | + ** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from |
| 50006 | 50155 | ** happening, this is usually correct. |
| 50007 | 50156 | ** |
| 50008 | 50157 | ** However, if frames have been appended to the log (or if the log |
| 50009 | 50158 | ** is wrapped and written for that matter) before the READ_LOCK(0) |
| 50010 | 50159 | ** is obtained, that is not necessarily true. A checkpointer may |
| | @@ -50668,11 +50817,11 @@ |
| 50668 | 50817 | /* If this is the end of a transaction, then we might need to pad |
| 50669 | 50818 | ** the transaction and/or sync the WAL file. |
| 50670 | 50819 | ** |
| 50671 | 50820 | ** Padding and syncing only occur if this set of frames complete a |
| 50672 | 50821 | ** transaction and if PRAGMA synchronous=FULL. If synchronous==NORMAL |
| 50673 | | - ** or synchonous==OFF, then no padding or syncing are needed. |
| 50822 | + ** or synchronous==OFF, then no padding or syncing are needed. |
| 50674 | 50823 | ** |
| 50675 | 50824 | ** If SQLITE_IOCAP_POWERSAFE_OVERWRITE is defined, then padding is not |
| 50676 | 50825 | ** needed and only the sync is done. If padding is needed, then the |
| 50677 | 50826 | ** final frame is repeated (with its commit mark) until the next sector |
| 50678 | 50827 | ** boundary is crossed. Only the part of the WAL prior to the last |
| | @@ -50971,11 +51120,11 @@ |
| 50971 | 51120 | ** May you do good and not evil. |
| 50972 | 51121 | ** May you find forgiveness for yourself and forgive others. |
| 50973 | 51122 | ** May you share freely, never taking more than you give. |
| 50974 | 51123 | ** |
| 50975 | 51124 | ************************************************************************* |
| 50976 | | -** This file implements a external (disk-based) database using BTrees. |
| 51125 | +** This file implements an external (disk-based) database using BTrees. |
| 50977 | 51126 | ** For a detailed discussion of BTrees, refer to |
| 50978 | 51127 | ** |
| 50979 | 51128 | ** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3: |
| 50980 | 51129 | ** "Sorting And Searching", pages 473-480. Addison-Wesley |
| 50981 | 51130 | ** Publishing Company, Reading, Massachusetts. |
| | @@ -51097,11 +51246,11 @@ |
| 51097 | 51246 | ** 7 1 number of fragmented free bytes |
| 51098 | 51247 | ** 8 4 Right child (the Ptr(N) value). Omitted on leaves. |
| 51099 | 51248 | ** |
| 51100 | 51249 | ** The flags define the format of this btree page. The leaf flag means that |
| 51101 | 51250 | ** this page has no children. The zerodata flag means that this page carries |
| 51102 | | -** only keys and no data. The intkey flag means that the key is a integer |
| 51251 | +** only keys and no data. The intkey flag means that the key is an integer |
| 51103 | 51252 | ** which is stored in the key size entry of the cell header rather than in |
| 51104 | 51253 | ** the payload area. |
| 51105 | 51254 | ** |
| 51106 | 51255 | ** The cell pointer array begins on the first byte after the page header. |
| 51107 | 51256 | ** The cell pointer array contains zero or more 2-byte numbers which are |
| | @@ -51505,11 +51654,11 @@ |
| 51505 | 51654 | ** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in |
| 51506 | 51655 | ** this state, restoreCursorPosition() can be called to attempt to |
| 51507 | 51656 | ** seek the cursor to the saved position. |
| 51508 | 51657 | ** |
| 51509 | 51658 | ** CURSOR_FAULT: |
| 51510 | | -** A unrecoverable error (an I/O error or a malloc failure) has occurred |
| 51659 | +** An unrecoverable error (an I/O error or a malloc failure) has occurred |
| 51511 | 51660 | ** on a different connection that shares the BtShared cache with this |
| 51512 | 51661 | ** cursor. The error has left the cache in an inconsistent state. |
| 51513 | 51662 | ** Do nothing else with this cursor. Any attempt to use the cursor |
| 51514 | 51663 | ** should return the error code stored in BtCursor.skip |
| 51515 | 51664 | */ |
| | @@ -51722,11 +51871,11 @@ |
| 51722 | 51871 | */ |
| 51723 | 51872 | static void SQLITE_NOINLINE btreeLockCarefully(Btree *p){ |
| 51724 | 51873 | Btree *pLater; |
| 51725 | 51874 | |
| 51726 | 51875 | /* In most cases, we should be able to acquire the lock we |
| 51727 | | - ** want without having to go throught the ascending lock |
| 51876 | + ** want without having to go through the ascending lock |
| 51728 | 51877 | ** procedure that follows. Just be sure not to block. |
| 51729 | 51878 | */ |
| 51730 | 51879 | if( sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK ){ |
| 51731 | 51880 | p->pBt->db = p->db; |
| 51732 | 51881 | p->locked = 1; |
| | @@ -51928,11 +52077,11 @@ |
| 51928 | 52077 | ** May you do good and not evil. |
| 51929 | 52078 | ** May you find forgiveness for yourself and forgive others. |
| 51930 | 52079 | ** May you share freely, never taking more than you give. |
| 51931 | 52080 | ** |
| 51932 | 52081 | ************************************************************************* |
| 51933 | | -** This file implements a external (disk-based) database using BTrees. |
| 52082 | +** This file implements an external (disk-based) database using BTrees. |
| 51934 | 52083 | ** See the header comment on "btreeInt.h" for additional information. |
| 51935 | 52084 | ** Including a description of file format and an overview of operation. |
| 51936 | 52085 | */ |
| 51937 | 52086 | |
| 51938 | 52087 | /* |
| | @@ -52524,11 +52673,11 @@ |
| 52524 | 52673 | ** all that is required. Otherwise, if pCur is not open on an intKey |
| 52525 | 52674 | ** table, then malloc space for and store the pCur->nKey bytes of key |
| 52526 | 52675 | ** data. |
| 52527 | 52676 | */ |
| 52528 | 52677 | if( 0==pCur->apPage[0]->intKey ){ |
| 52529 | | - void *pKey = sqlite3Malloc( (int)pCur->nKey ); |
| 52678 | + void *pKey = sqlite3Malloc( pCur->nKey ); |
| 52530 | 52679 | if( pKey ){ |
| 52531 | 52680 | rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey); |
| 52532 | 52681 | if( rc==SQLITE_OK ){ |
| 52533 | 52682 | pCur->pKey = pKey; |
| 52534 | 52683 | }else{ |
| | @@ -53062,11 +53211,11 @@ |
| 53062 | 53211 | ** big FreeBlk that occurs in between the header and cell |
| 53063 | 53212 | ** pointer array and the cell content area. |
| 53064 | 53213 | */ |
| 53065 | 53214 | static int defragmentPage(MemPage *pPage){ |
| 53066 | 53215 | int i; /* Loop counter */ |
| 53067 | | - int pc; /* Address of a i-th cell */ |
| 53216 | + int pc; /* Address of the i-th cell */ |
| 53068 | 53217 | int hdr; /* Offset to the page header */ |
| 53069 | 53218 | int size; /* Size of a cell */ |
| 53070 | 53219 | int usableSize; /* Number of usable bytes on a page */ |
| 53071 | 53220 | int cellOffset; /* Offset to the cell pointer array */ |
| 53072 | 53221 | int cbrk; /* Offset to the cell content area */ |
| | @@ -54519,11 +54668,11 @@ |
| 54519 | 54668 | ** |
| 54520 | 54669 | ** Only write cursors are counted if wrOnly is true. If wrOnly is |
| 54521 | 54670 | ** false then all cursors are counted. |
| 54522 | 54671 | ** |
| 54523 | 54672 | ** For the purposes of this routine, a cursor is any cursor that |
| 54524 | | -** is capable of reading or writing to the databse. Cursors that |
| 54673 | +** is capable of reading or writing to the database. Cursors that |
| 54525 | 54674 | ** have been tripped into the CURSOR_FAULT state are not counted. |
| 54526 | 54675 | */ |
| 54527 | 54676 | static int countValidCursors(BtShared *pBt, int wrOnly){ |
| 54528 | 54677 | BtCursor *pCur; |
| 54529 | 54678 | int r = 0; |
| | @@ -54983,19 +55132,19 @@ |
| 54983 | 55132 | ** Perform a single step of an incremental-vacuum. If successful, return |
| 54984 | 55133 | ** SQLITE_OK. If there is no work to do (and therefore no point in |
| 54985 | 55134 | ** calling this function again), return SQLITE_DONE. Or, if an error |
| 54986 | 55135 | ** occurs, return some other error code. |
| 54987 | 55136 | ** |
| 54988 | | -** More specificly, this function attempts to re-organize the database so |
| 55137 | +** More specifically, this function attempts to re-organize the database so |
| 54989 | 55138 | ** that the last page of the file currently in use is no longer in use. |
| 54990 | 55139 | ** |
| 54991 | 55140 | ** Parameter nFin is the number of pages that this database would contain |
| 54992 | 55141 | ** were this function called until it returns SQLITE_DONE. |
| 54993 | 55142 | ** |
| 54994 | 55143 | ** If the bCommit parameter is non-zero, this function assumes that the |
| 54995 | 55144 | ** caller will keep calling incrVacuumStep() until it returns SQLITE_DONE |
| 54996 | | -** or an error. bCommit is passed true for an auto-vacuum-on-commmit |
| 55145 | +** or an error. bCommit is passed true for an auto-vacuum-on-commit |
| 54997 | 55146 | ** operation, or false for an incremental vacuum. |
| 54998 | 55147 | */ |
| 54999 | 55148 | static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit){ |
| 55000 | 55149 | Pgno nFreeList; /* Number of pages still on the free-list */ |
| 55001 | 55150 | int rc; |
| | @@ -55458,11 +55607,11 @@ |
| 55458 | 55607 | sqlite3BtreeLeave(p); |
| 55459 | 55608 | return rc; |
| 55460 | 55609 | } |
| 55461 | 55610 | |
| 55462 | 55611 | /* |
| 55463 | | -** Start a statement subtransaction. The subtransaction can can be rolled |
| 55612 | +** Start a statement subtransaction. The subtransaction can be rolled |
| 55464 | 55613 | ** back independently of the main transaction. You must start a transaction |
| 55465 | 55614 | ** before starting a subtransaction. The subtransaction is ended automatically |
| 55466 | 55615 | ** if the main transaction commits or rolls back. |
| 55467 | 55616 | ** |
| 55468 | 55617 | ** Statement subtransactions are used around individual SQL statements |
| | @@ -55692,11 +55841,11 @@ |
| 55692 | 55841 | ** |
| 55693 | 55842 | ** 2007-06-25: There is a bug in some versions of MSVC that cause the |
| 55694 | 55843 | ** compiler to crash when getCellInfo() is implemented as a macro. |
| 55695 | 55844 | ** But there is a measureable speed advantage to using the macro on gcc |
| 55696 | 55845 | ** (when less compiler optimizations like -Os or -O0 are used and the |
| 55697 | | -** compiler is not doing agressive inlining.) So we use a real function |
| 55846 | +** compiler is not doing aggressive inlining.) So we use a real function |
| 55698 | 55847 | ** for MSVC and a macro for everything else. Ticket #2457. |
| 55699 | 55848 | */ |
| 55700 | 55849 | #ifndef NDEBUG |
| 55701 | 55850 | static void assertCellInfo(BtCursor *pCur){ |
| 55702 | 55851 | CellInfo info; |
| | @@ -55909,11 +56058,11 @@ |
| 55909 | 56058 | ** The content being read or written might appear on the main page |
| 55910 | 56059 | ** or be scattered out on multiple overflow pages. |
| 55911 | 56060 | ** |
| 55912 | 56061 | ** If the current cursor entry uses one or more overflow pages and the |
| 55913 | 56062 | ** eOp argument is not 2, this function may allocate space for and lazily |
| 55914 | | -** popluates the overflow page-list cache array (BtCursor.aOverflow). |
| 56063 | +** populates the overflow page-list cache array (BtCursor.aOverflow). |
| 55915 | 56064 | ** Subsequent calls use this cache to make seeking to the supplied offset |
| 55916 | 56065 | ** more efficient. |
| 55917 | 56066 | ** |
| 55918 | 56067 | ** Once an overflow page-list cache has been allocated, it may be |
| 55919 | 56068 | ** invalidated if some other cursor writes to the same table, or if |
| | @@ -56111,11 +56260,11 @@ |
| 56111 | 56260 | return rc; |
| 56112 | 56261 | } |
| 56113 | 56262 | |
| 56114 | 56263 | /* |
| 56115 | 56264 | ** Read part of the key associated with cursor pCur. Exactly |
| 56116 | | -** "amt" bytes will be transfered into pBuf[]. The transfer |
| 56265 | +** "amt" bytes will be transferred into pBuf[]. The transfer |
| 56117 | 56266 | ** begins at "offset". |
| 56118 | 56267 | ** |
| 56119 | 56268 | ** The caller must ensure that pCur is pointing to a valid row |
| 56120 | 56269 | ** in the table. |
| 56121 | 56270 | ** |
| | @@ -56664,18 +56813,18 @@ |
| 56664 | 56813 | if( nCell<=pPage->max1bytePayload ){ |
| 56665 | 56814 | /* This branch runs if the record-size field of the cell is a |
| 56666 | 56815 | ** single byte varint and the record fits entirely on the main |
| 56667 | 56816 | ** b-tree page. */ |
| 56668 | 56817 | testcase( pCell+nCell+1==pPage->aDataEnd ); |
| 56669 | | - c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey, 0); |
| 56818 | + c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey); |
| 56670 | 56819 | }else if( !(pCell[1] & 0x80) |
| 56671 | 56820 | && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal |
| 56672 | 56821 | ){ |
| 56673 | 56822 | /* The record-size field is a 2 byte varint and the record |
| 56674 | 56823 | ** fits entirely on the main b-tree page. */ |
| 56675 | 56824 | testcase( pCell+nCell+2==pPage->aDataEnd ); |
| 56676 | | - c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey, 0); |
| 56825 | + c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey); |
| 56677 | 56826 | }else{ |
| 56678 | 56827 | /* The record flows over onto one or more overflow pages. In |
| 56679 | 56828 | ** this case the whole cell needs to be parsed, a buffer allocated |
| 56680 | 56829 | ** and accessPayload() used to retrieve the record into the |
| 56681 | 56830 | ** buffer before VdbeRecordCompare() can be called. */ |
| | @@ -56692,11 +56841,11 @@ |
| 56692 | 56841 | rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 2); |
| 56693 | 56842 | if( rc ){ |
| 56694 | 56843 | sqlite3_free(pCellKey); |
| 56695 | 56844 | goto moveto_finish; |
| 56696 | 56845 | } |
| 56697 | | - c = xRecordCompare(nCell, pCellKey, pIdxKey, 0); |
| 56846 | + c = xRecordCompare(nCell, pCellKey, pIdxKey); |
| 56698 | 56847 | sqlite3_free(pCellKey); |
| 56699 | 56848 | } |
| 56700 | 56849 | assert( |
| 56701 | 56850 | (pIdxKey->errCode!=SQLITE_CORRUPT || c==0) |
| 56702 | 56851 | && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed) |
| | @@ -57807,11 +57956,11 @@ |
| 57807 | 57956 | /* |
| 57808 | 57957 | ** Add a list of cells to a page. The page should be initially empty. |
| 57809 | 57958 | ** The cells are guaranteed to fit on the page. |
| 57810 | 57959 | */ |
| 57811 | 57960 | static void assemblePage( |
| 57812 | | - MemPage *pPage, /* The page to be assemblied */ |
| 57961 | + MemPage *pPage, /* The page to be assembled */ |
| 57813 | 57962 | int nCell, /* The number of cells to add to this page */ |
| 57814 | 57963 | u8 **apCell, /* Pointers to cell bodies */ |
| 57815 | 57964 | u16 *aSize /* Sizes of the cells */ |
| 57816 | 57965 | ){ |
| 57817 | 57966 | int i; /* Loop counter */ |
| | @@ -58473,11 +58622,11 @@ |
| 58473 | 58622 | apOld[i] = 0; |
| 58474 | 58623 | i++; |
| 58475 | 58624 | } |
| 58476 | 58625 | |
| 58477 | 58626 | /* |
| 58478 | | - ** Put the new pages in accending order. This helps to |
| 58627 | + ** Put the new pages in ascending order. This helps to |
| 58479 | 58628 | ** keep entries in the disk file in order so that a scan |
| 58480 | 58629 | ** of the table is a linear scan through the file. That |
| 58481 | 58630 | ** in turn helps the operating system to deliver pages |
| 58482 | 58631 | ** from the disk more rapidly. |
| 58483 | 58632 | ** |
| | @@ -58868,11 +59017,11 @@ |
| 58868 | 59017 | && pParent->nCell==iIdx |
| 58869 | 59018 | ){ |
| 58870 | 59019 | /* Call balance_quick() to create a new sibling of pPage on which |
| 58871 | 59020 | ** to store the overflow cell. balance_quick() inserts a new cell |
| 58872 | 59021 | ** into pParent, which may cause pParent overflow. If this |
| 58873 | | - ** happens, the next interation of the do-loop will balance pParent |
| 59022 | + ** happens, the next iteration of the do-loop will balance pParent |
| 58874 | 59023 | ** use either balance_nonroot() or balance_deeper(). Until this |
| 58875 | 59024 | ** happens, the overflow cell is stored in the aBalanceQuickSpace[] |
| 58876 | 59025 | ** buffer. |
| 58877 | 59026 | ** |
| 58878 | 59027 | ** The purpose of the following assert() is to check that only a |
| | @@ -58945,11 +59094,11 @@ |
| 58945 | 59094 | ** |
| 58946 | 59095 | ** If the seekResult parameter is non-zero, then a successful call to |
| 58947 | 59096 | ** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already |
| 58948 | 59097 | ** been performed. seekResult is the search result returned (a negative |
| 58949 | 59098 | ** number if pCur points at an entry that is smaller than (pKey, nKey), or |
| 58950 | | -** a positive value if pCur points at an etry that is larger than |
| 59099 | +** a positive value if pCur points at an entry that is larger than |
| 58951 | 59100 | ** (pKey, nKey)). |
| 58952 | 59101 | ** |
| 58953 | 59102 | ** If the seekResult parameter is non-zero, then the caller guarantees that |
| 58954 | 59103 | ** cursor pCur is pointing at the existing copy of a row that is to be |
| 58955 | 59104 | ** overwritten. If the seekResult parameter is 0, then cursor pCur may |
| | @@ -59102,11 +59251,11 @@ |
| 59102 | 59251 | return rc; |
| 59103 | 59252 | } |
| 59104 | 59253 | |
| 59105 | 59254 | /* |
| 59106 | 59255 | ** Delete the entry that the cursor is pointing to. The cursor |
| 59107 | | -** is left pointing at a arbitrary location. |
| 59256 | +** is left pointing at an arbitrary location. |
| 59108 | 59257 | */ |
| 59109 | 59258 | SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur){ |
| 59110 | 59259 | Btree *p = pCur->pBtree; |
| 59111 | 59260 | BtShared *pBt = p->pBt; |
| 59112 | 59261 | int rc; /* Return code */ |
| | @@ -59800,11 +59949,11 @@ |
| 59800 | 59949 | |
| 59801 | 59950 | |
| 59802 | 59951 | /* |
| 59803 | 59952 | ** Add 1 to the reference count for page iPage. If this is the second |
| 59804 | 59953 | ** reference to the page, add an error message to pCheck->zErrMsg. |
| 59805 | | -** Return 1 if there are 2 ore more references to the page and 0 if |
| 59954 | +** Return 1 if there are 2 or more references to the page and 0 if |
| 59806 | 59955 | ** if this is the first reference to the page. |
| 59807 | 59956 | ** |
| 59808 | 59957 | ** Also check that the page number is in bounds. |
| 59809 | 59958 | */ |
| 59810 | 59959 | static int checkRef(IntegrityCk *pCheck, Pgno iPage, char *zContext){ |
| | @@ -61307,33 +61456,41 @@ |
| 61307 | 61456 | ** |
| 61308 | 61457 | ** This routine is intended for use inside of assert() statements, like |
| 61309 | 61458 | ** this: assert( sqlite3VdbeCheckMemInvariants(pMem) ); |
| 61310 | 61459 | */ |
| 61311 | 61460 | SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){ |
| 61312 | | - /* The MEM_Dyn bit is set if and only if Mem.xDel is a non-NULL destructor |
| 61313 | | - ** function for Mem.z |
| 61461 | + /* If MEM_Dyn is set then Mem.xDel!=0. |
| 61462 | + ** Mem.xDel is might not be initialized if MEM_Dyn is clear. |
| 61314 | 61463 | */ |
| 61315 | 61464 | assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 ); |
| 61316 | | - assert( (p->flags & MEM_Dyn)!=0 || p->xDel==0 ); |
| 61465 | + |
| 61466 | + /* MEM_Dyn may only be set if Mem.szMalloc==0 */ |
| 61467 | + assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 ); |
| 61468 | + |
| 61469 | + /* Cannot be both MEM_Int and MEM_Real at the same time */ |
| 61470 | + assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) ); |
| 61471 | + |
| 61472 | + /* The szMalloc field holds the correct memory allocation size */ |
| 61473 | + assert( p->szMalloc==0 |
| 61474 | + || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) ); |
| 61317 | 61475 | |
| 61318 | 61476 | /* If p holds a string or blob, the Mem.z must point to exactly |
| 61319 | 61477 | ** one of the following: |
| 61320 | 61478 | ** |
| 61321 | 61479 | ** (1) Memory in Mem.zMalloc and managed by the Mem object |
| 61322 | 61480 | ** (2) Memory to be freed using Mem.xDel |
| 61323 | | - ** (3) An ephermal string or blob |
| 61481 | + ** (3) An ephemeral string or blob |
| 61324 | 61482 | ** (4) A static string or blob |
| 61325 | 61483 | */ |
| 61326 | | - if( (p->flags & (MEM_Str|MEM_Blob)) && p->z!=0 ){ |
| 61484 | + if( (p->flags & (MEM_Str|MEM_Blob)) && p->n>0 ){ |
| 61327 | 61485 | assert( |
| 61328 | | - ((p->z==p->zMalloc)? 1 : 0) + |
| 61486 | + ((p->szMalloc>0 && p->z==p->zMalloc)? 1 : 0) + |
| 61329 | 61487 | ((p->flags&MEM_Dyn)!=0 ? 1 : 0) + |
| 61330 | 61488 | ((p->flags&MEM_Ephem)!=0 ? 1 : 0) + |
| 61331 | 61489 | ((p->flags&MEM_Static)!=0 ? 1 : 0) == 1 |
| 61332 | 61490 | ); |
| 61333 | 61491 | } |
| 61334 | | - |
| 61335 | 61492 | return 1; |
| 61336 | 61493 | } |
| 61337 | 61494 | #endif |
| 61338 | 61495 | |
| 61339 | 61496 | |
| | @@ -61383,33 +61540,37 @@ |
| 61383 | 61540 | ** If the bPreserve argument is true, then copy of the content of |
| 61384 | 61541 | ** pMem->z into the new allocation. pMem must be either a string or |
| 61385 | 61542 | ** blob if bPreserve is true. If bPreserve is false, any prior content |
| 61386 | 61543 | ** in pMem->z is discarded. |
| 61387 | 61544 | */ |
| 61388 | | -SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){ |
| 61545 | +SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){ |
| 61389 | 61546 | assert( sqlite3VdbeCheckMemInvariants(pMem) ); |
| 61390 | 61547 | assert( (pMem->flags&MEM_RowSet)==0 ); |
| 61391 | 61548 | |
| 61392 | 61549 | /* If the bPreserve flag is set to true, then the memory cell must already |
| 61393 | 61550 | ** contain a valid string or blob value. */ |
| 61394 | 61551 | assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); |
| 61395 | 61552 | testcase( bPreserve && pMem->z==0 ); |
| 61396 | 61553 | |
| 61397 | | - if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){ |
| 61554 | + assert( pMem->szMalloc==0 |
| 61555 | + || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) ); |
| 61556 | + if( pMem->szMalloc<n ){ |
| 61398 | 61557 | if( n<32 ) n = 32; |
| 61399 | | - if( bPreserve && pMem->z==pMem->zMalloc ){ |
| 61558 | + if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){ |
| 61400 | 61559 | pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n); |
| 61401 | 61560 | bPreserve = 0; |
| 61402 | 61561 | }else{ |
| 61403 | | - sqlite3DbFree(pMem->db, pMem->zMalloc); |
| 61562 | + if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc); |
| 61404 | 61563 | pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n); |
| 61405 | 61564 | } |
| 61406 | 61565 | if( pMem->zMalloc==0 ){ |
| 61407 | | - VdbeMemReleaseExtern(pMem); |
| 61566 | + sqlite3VdbeMemSetNull(pMem); |
| 61408 | 61567 | pMem->z = 0; |
| 61409 | | - pMem->flags = MEM_Null; |
| 61568 | + pMem->szMalloc = 0; |
| 61410 | 61569 | return SQLITE_NOMEM; |
| 61570 | + }else{ |
| 61571 | + pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc); |
| 61411 | 61572 | } |
| 61412 | 61573 | } |
| 61413 | 61574 | |
| 61414 | 61575 | if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){ |
| 61415 | 61576 | memcpy(pMem->zMalloc, pMem->z, pMem->n); |
| | @@ -61419,29 +61580,50 @@ |
| 61419 | 61580 | pMem->xDel((void *)(pMem->z)); |
| 61420 | 61581 | } |
| 61421 | 61582 | |
| 61422 | 61583 | pMem->z = pMem->zMalloc; |
| 61423 | 61584 | pMem->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Static); |
| 61424 | | - pMem->xDel = 0; |
| 61425 | 61585 | return SQLITE_OK; |
| 61426 | 61586 | } |
| 61427 | 61587 | |
| 61428 | 61588 | /* |
| 61429 | | -** Make the given Mem object MEM_Dyn. In other words, make it so |
| 61430 | | -** that any TEXT or BLOB content is stored in memory obtained from |
| 61431 | | -** malloc(). In this way, we know that the memory is safe to be |
| 61432 | | -** overwritten or altered. |
| 61589 | +** Change the pMem->zMalloc allocation to be at least szNew bytes. |
| 61590 | +** If pMem->zMalloc already meets or exceeds the requested size, this |
| 61591 | +** routine is a no-op. |
| 61592 | +** |
| 61593 | +** Any prior string or blob content in the pMem object may be discarded. |
| 61594 | +** The pMem->xDel destructor is called, if it exists. Though MEM_Str |
| 61595 | +** and MEM_Blob values may be discarded, MEM_Int, MEM_Real, and MEM_Null |
| 61596 | +** values are preserved. |
| 61597 | +** |
| 61598 | +** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM) |
| 61599 | +** if unable to complete the resizing. |
| 61600 | +*/ |
| 61601 | +SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){ |
| 61602 | + assert( szNew>=0 ); |
| 61603 | + if( pMem->szMalloc<szNew ){ |
| 61604 | + return sqlite3VdbeMemGrow(pMem, szNew, 0); |
| 61605 | + } |
| 61606 | + assert( (pMem->flags & MEM_Dyn)==0 ); |
| 61607 | + pMem->z = pMem->zMalloc; |
| 61608 | + pMem->flags &= (MEM_Null|MEM_Int|MEM_Real); |
| 61609 | + return SQLITE_OK; |
| 61610 | +} |
| 61611 | + |
| 61612 | +/* |
| 61613 | +** Change pMem so that its MEM_Str or MEM_Blob value is stored in |
| 61614 | +** MEM.zMalloc, where it can be safely written. |
| 61433 | 61615 | ** |
| 61434 | 61616 | ** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails. |
| 61435 | 61617 | */ |
| 61436 | 61618 | SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *pMem){ |
| 61437 | 61619 | int f; |
| 61438 | 61620 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 61439 | 61621 | assert( (pMem->flags&MEM_RowSet)==0 ); |
| 61440 | 61622 | ExpandBlob(pMem); |
| 61441 | 61623 | f = pMem->flags; |
| 61442 | | - if( (f&(MEM_Str|MEM_Blob)) && pMem->z!=pMem->zMalloc ){ |
| 61624 | + if( (f&(MEM_Str|MEM_Blob)) && (pMem->szMalloc==0 || pMem->z!=pMem->zMalloc) ){ |
| 61443 | 61625 | if( sqlite3VdbeMemGrow(pMem, pMem->n + 2, 1) ){ |
| 61444 | 61626 | return SQLITE_NOMEM; |
| 61445 | 61627 | } |
| 61446 | 61628 | pMem->z[pMem->n] = 0; |
| 61447 | 61629 | pMem->z[pMem->n+1] = 0; |
| | @@ -61521,11 +61703,11 @@ |
| 61521 | 61703 | ** |
| 61522 | 61704 | ** A MEM_Null value will never be passed to this function. This function is |
| 61523 | 61705 | ** used for converting values to text for returning to the user (i.e. via |
| 61524 | 61706 | ** sqlite3_value_text()), or for ensuring that values to be used as btree |
| 61525 | 61707 | ** keys are strings. In the former case a NULL pointer is returned the |
| 61526 | | -** user and the later is an internal programming error. |
| 61708 | +** user and the latter is an internal programming error. |
| 61527 | 61709 | */ |
| 61528 | 61710 | SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem *pMem, u8 enc, u8 bForce){ |
| 61529 | 61711 | int fg = pMem->flags; |
| 61530 | 61712 | const int nByte = 32; |
| 61531 | 61713 | |
| | @@ -61535,11 +61717,11 @@ |
| 61535 | 61717 | assert( fg&(MEM_Int|MEM_Real) ); |
| 61536 | 61718 | assert( (pMem->flags&MEM_RowSet)==0 ); |
| 61537 | 61719 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 61538 | 61720 | |
| 61539 | 61721 | |
| 61540 | | - if( sqlite3VdbeMemGrow(pMem, nByte, 0) ){ |
| 61722 | + if( sqlite3VdbeMemClearAndResize(pMem, nByte) ){ |
| 61541 | 61723 | return SQLITE_NOMEM; |
| 61542 | 61724 | } |
| 61543 | 61725 | |
| 61544 | 61726 | /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8 |
| 61545 | 61727 | ** string representation of the value. Then, if the required encoding |
| | @@ -61549,11 +61731,11 @@ |
| 61549 | 61731 | */ |
| 61550 | 61732 | if( fg & MEM_Int ){ |
| 61551 | 61733 | sqlite3_snprintf(nByte, pMem->z, "%lld", pMem->u.i); |
| 61552 | 61734 | }else{ |
| 61553 | 61735 | assert( fg & MEM_Real ); |
| 61554 | | - sqlite3_snprintf(nByte, pMem->z, "%!.15g", pMem->r); |
| 61736 | + sqlite3_snprintf(nByte, pMem->z, "%!.15g", pMem->u.r); |
| 61555 | 61737 | } |
| 61556 | 61738 | pMem->n = sqlite3Strlen30(pMem->z); |
| 61557 | 61739 | pMem->enc = SQLITE_UTF8; |
| 61558 | 61740 | pMem->flags |= MEM_Str|MEM_Term; |
| 61559 | 61741 | if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real); |
| | @@ -61582,76 +61764,83 @@ |
| 61582 | 61764 | t.db = pMem->db; |
| 61583 | 61765 | ctx.pOut = &t; |
| 61584 | 61766 | ctx.pMem = pMem; |
| 61585 | 61767 | ctx.pFunc = pFunc; |
| 61586 | 61768 | pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */ |
| 61587 | | - assert( 0==(pMem->flags&MEM_Dyn) && !pMem->xDel ); |
| 61588 | | - sqlite3DbFree(pMem->db, pMem->zMalloc); |
| 61769 | + assert( (pMem->flags & MEM_Dyn)==0 ); |
| 61770 | + if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc); |
| 61589 | 61771 | memcpy(pMem, &t, sizeof(t)); |
| 61590 | 61772 | rc = ctx.isError; |
| 61591 | 61773 | } |
| 61592 | 61774 | return rc; |
| 61593 | 61775 | } |
| 61594 | 61776 | |
| 61595 | 61777 | /* |
| 61596 | | -** If the memory cell contains a string value that must be freed by |
| 61597 | | -** invoking an external callback, free it now. Calling this function |
| 61598 | | -** does not free any Mem.zMalloc buffer. |
| 61778 | +** If the memory cell contains a value that must be freed by |
| 61779 | +** invoking the external callback in Mem.xDel, then this routine |
| 61780 | +** will free that value. It also sets Mem.flags to MEM_Null. |
| 61599 | 61781 | ** |
| 61600 | | -** The VdbeMemReleaseExtern() macro invokes this routine if only if there |
| 61601 | | -** is work for this routine to do. |
| 61782 | +** This is a helper routine for sqlite3VdbeMemSetNull() and |
| 61783 | +** for sqlite3VdbeMemRelease(). Use those other routines as the |
| 61784 | +** entry point for releasing Mem resources. |
| 61602 | 61785 | */ |
| 61603 | | -SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p){ |
| 61786 | +static SQLITE_NOINLINE void vdbeMemClearExternAndSetNull(Mem *p){ |
| 61604 | 61787 | assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) ); |
| 61788 | + assert( VdbeMemDynamic(p) ); |
| 61605 | 61789 | if( p->flags&MEM_Agg ){ |
| 61606 | 61790 | sqlite3VdbeMemFinalize(p, p->u.pDef); |
| 61607 | 61791 | assert( (p->flags & MEM_Agg)==0 ); |
| 61608 | | - sqlite3VdbeMemRelease(p); |
| 61609 | | - }else if( p->flags&MEM_Dyn ){ |
| 61792 | + testcase( p->flags & MEM_Dyn ); |
| 61793 | + } |
| 61794 | + if( p->flags&MEM_Dyn ){ |
| 61610 | 61795 | assert( (p->flags&MEM_RowSet)==0 ); |
| 61611 | 61796 | assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 ); |
| 61612 | 61797 | p->xDel((void *)p->z); |
| 61613 | | - p->xDel = 0; |
| 61614 | 61798 | }else if( p->flags&MEM_RowSet ){ |
| 61615 | 61799 | sqlite3RowSetClear(p->u.pRowSet); |
| 61616 | 61800 | }else if( p->flags&MEM_Frame ){ |
| 61617 | | - sqlite3VdbeMemSetNull(p); |
| 61801 | + VdbeFrame *pFrame = p->u.pFrame; |
| 61802 | + pFrame->pParent = pFrame->v->pDelFrame; |
| 61803 | + pFrame->v->pDelFrame = pFrame; |
| 61618 | 61804 | } |
| 61805 | + p->flags = MEM_Null; |
| 61619 | 61806 | } |
| 61620 | 61807 | |
| 61621 | 61808 | /* |
| 61622 | 61809 | ** Release memory held by the Mem p, both external memory cleared |
| 61623 | 61810 | ** by p->xDel and memory in p->zMalloc. |
| 61624 | 61811 | ** |
| 61625 | 61812 | ** This is a helper routine invoked by sqlite3VdbeMemRelease() in |
| 61626 | | -** the uncommon case when there really is memory in p that is |
| 61627 | | -** need of freeing. |
| 61813 | +** the unusual case where there really is memory in p that needs |
| 61814 | +** to be freed. |
| 61628 | 61815 | */ |
| 61629 | | -static SQLITE_NOINLINE void vdbeMemRelease(Mem *p){ |
| 61816 | +static SQLITE_NOINLINE void vdbeMemClear(Mem *p){ |
| 61630 | 61817 | if( VdbeMemDynamic(p) ){ |
| 61631 | | - sqlite3VdbeMemReleaseExternal(p); |
| 61818 | + vdbeMemClearExternAndSetNull(p); |
| 61632 | 61819 | } |
| 61633 | | - if( p->zMalloc ){ |
| 61820 | + if( p->szMalloc ){ |
| 61634 | 61821 | sqlite3DbFree(p->db, p->zMalloc); |
| 61635 | | - p->zMalloc = 0; |
| 61822 | + p->szMalloc = 0; |
| 61636 | 61823 | } |
| 61637 | 61824 | p->z = 0; |
| 61638 | 61825 | } |
| 61639 | 61826 | |
| 61640 | 61827 | /* |
| 61641 | | -** Release any memory held by the Mem. This may leave the Mem in an |
| 61642 | | -** inconsistent state, for example with (Mem.z==0) and |
| 61643 | | -** (Mem.flags==MEM_Str). |
| 61828 | +** Release any memory resources held by the Mem. Both the memory that is |
| 61829 | +** free by Mem.xDel and the Mem.zMalloc allocation are freed. |
| 61830 | +** |
| 61831 | +** Use this routine prior to clean up prior to abandoning a Mem, or to |
| 61832 | +** reset a Mem back to its minimum memory utilization. |
| 61833 | +** |
| 61834 | +** Use sqlite3VdbeMemSetNull() to release just the Mem.xDel space |
| 61835 | +** prior to inserting new content into the Mem. |
| 61644 | 61836 | */ |
| 61645 | 61837 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){ |
| 61646 | 61838 | assert( sqlite3VdbeCheckMemInvariants(p) ); |
| 61647 | | - if( VdbeMemDynamic(p) || p->zMalloc ){ |
| 61648 | | - vdbeMemRelease(p); |
| 61649 | | - }else{ |
| 61650 | | - p->z = 0; |
| 61839 | + if( VdbeMemDynamic(p) || p->szMalloc ){ |
| 61840 | + vdbeMemClear(p); |
| 61651 | 61841 | } |
| 61652 | | - assert( p->xDel==0 ); |
| 61653 | 61842 | } |
| 61654 | 61843 | |
| 61655 | 61844 | /* |
| 61656 | 61845 | ** Convert a 64-bit IEEE double into a 64-bit signed integer. |
| 61657 | 61846 | ** If the double is out of range of a 64-bit signed integer then |
| | @@ -61686,11 +61875,11 @@ |
| 61686 | 61875 | ** Return some kind of integer value which is the best we can do |
| 61687 | 61876 | ** at representing the value that *pMem describes as an integer. |
| 61688 | 61877 | ** If pMem is an integer, then the value is exact. If pMem is |
| 61689 | 61878 | ** a floating-point then the value returned is the integer part. |
| 61690 | 61879 | ** If pMem is a string or blob, then we make an attempt to convert |
| 61691 | | -** it into a integer and return that. If pMem represents an |
| 61880 | +** it into an integer and return that. If pMem represents an |
| 61692 | 61881 | ** an SQL-NULL value, return 0. |
| 61693 | 61882 | ** |
| 61694 | 61883 | ** If pMem represents a string value, its encoding might be changed. |
| 61695 | 61884 | */ |
| 61696 | 61885 | SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){ |
| | @@ -61699,11 +61888,11 @@ |
| 61699 | 61888 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 61700 | 61889 | flags = pMem->flags; |
| 61701 | 61890 | if( flags & MEM_Int ){ |
| 61702 | 61891 | return pMem->u.i; |
| 61703 | 61892 | }else if( flags & MEM_Real ){ |
| 61704 | | - return doubleToInt64(pMem->r); |
| 61893 | + return doubleToInt64(pMem->u.r); |
| 61705 | 61894 | }else if( flags & (MEM_Str|MEM_Blob) ){ |
| 61706 | 61895 | i64 value = 0; |
| 61707 | 61896 | assert( pMem->z || pMem->n==0 ); |
| 61708 | 61897 | sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc); |
| 61709 | 61898 | return value; |
| | @@ -61720,11 +61909,11 @@ |
| 61720 | 61909 | */ |
| 61721 | 61910 | SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){ |
| 61722 | 61911 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 61723 | 61912 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 61724 | 61913 | if( pMem->flags & MEM_Real ){ |
| 61725 | | - return pMem->r; |
| 61914 | + return pMem->u.r; |
| 61726 | 61915 | }else if( pMem->flags & MEM_Int ){ |
| 61727 | 61916 | return (double)pMem->u.i; |
| 61728 | 61917 | }else if( pMem->flags & (MEM_Str|MEM_Blob) ){ |
| 61729 | 61918 | /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ |
| 61730 | 61919 | double val = (double)0; |
| | @@ -61739,16 +61928,17 @@ |
| 61739 | 61928 | /* |
| 61740 | 61929 | ** The MEM structure is already a MEM_Real. Try to also make it a |
| 61741 | 61930 | ** MEM_Int if we can. |
| 61742 | 61931 | */ |
| 61743 | 61932 | SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){ |
| 61933 | + i64 ix; |
| 61744 | 61934 | assert( pMem->flags & MEM_Real ); |
| 61745 | 61935 | assert( (pMem->flags & MEM_RowSet)==0 ); |
| 61746 | 61936 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 61747 | 61937 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 61748 | 61938 | |
| 61749 | | - pMem->u.i = doubleToInt64(pMem->r); |
| 61939 | + ix = doubleToInt64(pMem->u.r); |
| 61750 | 61940 | |
| 61751 | 61941 | /* Only mark the value as an integer if |
| 61752 | 61942 | ** |
| 61753 | 61943 | ** (1) the round-trip conversion real->int->real is a no-op, and |
| 61754 | 61944 | ** (2) The integer is neither the largest nor the smallest |
| | @@ -61756,15 +61946,13 @@ |
| 61756 | 61946 | ** |
| 61757 | 61947 | ** The second and third terms in the following conditional enforces |
| 61758 | 61948 | ** the second condition under the assumption that addition overflow causes |
| 61759 | 61949 | ** values to wrap around. |
| 61760 | 61950 | */ |
| 61761 | | - if( pMem->r==(double)pMem->u.i |
| 61762 | | - && pMem->u.i>SMALLEST_INT64 |
| 61763 | | - && pMem->u.i<LARGEST_INT64 |
| 61764 | | - ){ |
| 61765 | | - pMem->flags |= MEM_Int; |
| 61951 | + if( pMem->u.r==ix && ix>SMALLEST_INT64 && ix<LARGEST_INT64 ){ |
| 61952 | + pMem->u.i = ix; |
| 61953 | + MemSetTypeFlag(pMem, MEM_Int); |
| 61766 | 61954 | } |
| 61767 | 61955 | } |
| 61768 | 61956 | |
| 61769 | 61957 | /* |
| 61770 | 61958 | ** Convert pMem to type integer. Invalidate any prior representations. |
| | @@ -61785,11 +61973,11 @@ |
| 61785 | 61973 | */ |
| 61786 | 61974 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem *pMem){ |
| 61787 | 61975 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 61788 | 61976 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 61789 | 61977 | |
| 61790 | | - pMem->r = sqlite3VdbeRealValue(pMem); |
| 61978 | + pMem->u.r = sqlite3VdbeRealValue(pMem); |
| 61791 | 61979 | MemSetTypeFlag(pMem, MEM_Real); |
| 61792 | 61980 | return SQLITE_OK; |
| 61793 | 61981 | } |
| 61794 | 61982 | |
| 61795 | 61983 | /* |
| | @@ -61805,11 +61993,11 @@ |
| 61805 | 61993 | assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 ); |
| 61806 | 61994 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 61807 | 61995 | if( 0==sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc) ){ |
| 61808 | 61996 | MemSetTypeFlag(pMem, MEM_Int); |
| 61809 | 61997 | }else{ |
| 61810 | | - pMem->r = sqlite3VdbeRealValue(pMem); |
| 61998 | + pMem->u.r = sqlite3VdbeRealValue(pMem); |
| 61811 | 61999 | MemSetTypeFlag(pMem, MEM_Real); |
| 61812 | 62000 | sqlite3VdbeIntegerAffinity(pMem); |
| 61813 | 62001 | } |
| 61814 | 62002 | } |
| 61815 | 62003 | assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))!=0 ); |
| | @@ -61859,24 +62047,41 @@ |
| 61859 | 62047 | break; |
| 61860 | 62048 | } |
| 61861 | 62049 | } |
| 61862 | 62050 | } |
| 61863 | 62051 | |
| 62052 | +/* |
| 62053 | +** Initialize bulk memory to be a consistent Mem object. |
| 62054 | +** |
| 62055 | +** The minimum amount of initialization feasible is performed. |
| 62056 | +*/ |
| 62057 | +SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem *pMem, sqlite3 *db, u16 flags){ |
| 62058 | + assert( (flags & ~MEM_TypeMask)==0 ); |
| 62059 | + pMem->flags = flags; |
| 62060 | + pMem->db = db; |
| 62061 | + pMem->szMalloc = 0; |
| 62062 | +} |
| 62063 | + |
| 61864 | 62064 | |
| 61865 | 62065 | /* |
| 61866 | 62066 | ** Delete any previous value and set the value stored in *pMem to NULL. |
| 62067 | +** |
| 62068 | +** This routine calls the Mem.xDel destructor to dispose of values that |
| 62069 | +** require the destructor. But it preserves the Mem.zMalloc memory allocation. |
| 62070 | +** To free all resources, use sqlite3VdbeMemRelease(), which both calls this |
| 62071 | +** routine to invoke the destructor and deallocates Mem.zMalloc. |
| 62072 | +** |
| 62073 | +** Use this routine to reset the Mem prior to insert a new value. |
| 62074 | +** |
| 62075 | +** Use sqlite3VdbeMemRelease() to complete erase the Mem prior to abandoning it. |
| 61867 | 62076 | */ |
| 61868 | 62077 | SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem *pMem){ |
| 61869 | | - if( pMem->flags & MEM_Frame ){ |
| 61870 | | - VdbeFrame *pFrame = pMem->u.pFrame; |
| 61871 | | - pFrame->pParent = pFrame->v->pDelFrame; |
| 61872 | | - pFrame->v->pDelFrame = pFrame; |
| 61873 | | - } |
| 61874 | | - if( pMem->flags & MEM_RowSet ){ |
| 61875 | | - sqlite3RowSetClear(pMem->u.pRowSet); |
| 61876 | | - } |
| 61877 | | - MemSetTypeFlag(pMem, MEM_Null); |
| 62078 | + if( VdbeMemDynamic(pMem) ){ |
| 62079 | + vdbeMemClearExternAndSetNull(pMem); |
| 62080 | + }else{ |
| 62081 | + pMem->flags = MEM_Null; |
| 62082 | + } |
| 61878 | 62083 | } |
| 61879 | 62084 | SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){ |
| 61880 | 62085 | sqlite3VdbeMemSetNull((Mem*)p); |
| 61881 | 62086 | } |
| 61882 | 62087 | |
| | @@ -61889,27 +62094,20 @@ |
| 61889 | 62094 | pMem->flags = MEM_Blob|MEM_Zero; |
| 61890 | 62095 | pMem->n = 0; |
| 61891 | 62096 | if( n<0 ) n = 0; |
| 61892 | 62097 | pMem->u.nZero = n; |
| 61893 | 62098 | pMem->enc = SQLITE_UTF8; |
| 61894 | | - |
| 61895 | | -#ifdef SQLITE_OMIT_INCRBLOB |
| 61896 | | - sqlite3VdbeMemGrow(pMem, n, 0); |
| 61897 | | - if( pMem->z ){ |
| 61898 | | - pMem->n = n; |
| 61899 | | - memset(pMem->z, 0, n); |
| 61900 | | - } |
| 61901 | | -#endif |
| 62099 | + pMem->z = 0; |
| 61902 | 62100 | } |
| 61903 | 62101 | |
| 61904 | 62102 | /* |
| 61905 | 62103 | ** The pMem is known to contain content that needs to be destroyed prior |
| 61906 | 62104 | ** to a value change. So invoke the destructor, then set the value to |
| 61907 | 62105 | ** a 64-bit integer. |
| 61908 | 62106 | */ |
| 61909 | 62107 | static SQLITE_NOINLINE void vdbeReleaseAndSetInt64(Mem *pMem, i64 val){ |
| 61910 | | - sqlite3VdbeMemReleaseExternal(pMem); |
| 62108 | + sqlite3VdbeMemSetNull(pMem); |
| 61911 | 62109 | pMem->u.i = val; |
| 61912 | 62110 | pMem->flags = MEM_Int; |
| 61913 | 62111 | } |
| 61914 | 62112 | |
| 61915 | 62113 | /* |
| | @@ -61929,15 +62127,13 @@ |
| 61929 | 62127 | /* |
| 61930 | 62128 | ** Delete any previous value and set the value stored in *pMem to val, |
| 61931 | 62129 | ** manifest type REAL. |
| 61932 | 62130 | */ |
| 61933 | 62131 | SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem *pMem, double val){ |
| 61934 | | - if( sqlite3IsNaN(val) ){ |
| 61935 | | - sqlite3VdbeMemSetNull(pMem); |
| 61936 | | - }else{ |
| 61937 | | - sqlite3VdbeMemRelease(pMem); |
| 61938 | | - pMem->r = val; |
| 62132 | + sqlite3VdbeMemSetNull(pMem); |
| 62133 | + if( !sqlite3IsNaN(val) ){ |
| 62134 | + pMem->u.r = val; |
| 61939 | 62135 | pMem->flags = MEM_Real; |
| 61940 | 62136 | } |
| 61941 | 62137 | } |
| 61942 | 62138 | #endif |
| 61943 | 62139 | |
| | @@ -61951,14 +62147,15 @@ |
| 61951 | 62147 | assert( (pMem->flags & MEM_RowSet)==0 ); |
| 61952 | 62148 | sqlite3VdbeMemRelease(pMem); |
| 61953 | 62149 | pMem->zMalloc = sqlite3DbMallocRaw(db, 64); |
| 61954 | 62150 | if( db->mallocFailed ){ |
| 61955 | 62151 | pMem->flags = MEM_Null; |
| 62152 | + pMem->szMalloc = 0; |
| 61956 | 62153 | }else{ |
| 61957 | 62154 | assert( pMem->zMalloc ); |
| 61958 | | - pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc, |
| 61959 | | - sqlite3DbMallocSize(db, pMem->zMalloc)); |
| 62155 | + pMem->szMalloc = sqlite3DbMallocSize(db, pMem->zMalloc); |
| 62156 | + pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc, pMem->szMalloc); |
| 61960 | 62157 | assert( pMem->u.pRowSet!=0 ); |
| 61961 | 62158 | pMem->flags = MEM_RowSet; |
| 61962 | 62159 | } |
| 61963 | 62160 | } |
| 61964 | 62161 | |
| | @@ -61978,11 +62175,11 @@ |
| 61978 | 62175 | return 0; |
| 61979 | 62176 | } |
| 61980 | 62177 | |
| 61981 | 62178 | #ifdef SQLITE_DEBUG |
| 61982 | 62179 | /* |
| 61983 | | -** This routine prepares a memory cell for modication by breaking |
| 62180 | +** This routine prepares a memory cell for modification by breaking |
| 61984 | 62181 | ** its link to a shallow copy and by marking any current shallow |
| 61985 | 62182 | ** copies of this cell as invalid. |
| 61986 | 62183 | ** |
| 61987 | 62184 | ** This is used for testing and debugging only - to make sure shallow |
| 61988 | 62185 | ** copies are not misused. |
| | @@ -62011,13 +62208,13 @@ |
| 62011 | 62208 | ** pFrom->z is used, then pTo->z points to the same thing as pFrom->z |
| 62012 | 62209 | ** and flags gets srcType (either MEM_Ephem or MEM_Static). |
| 62013 | 62210 | */ |
| 62014 | 62211 | SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){ |
| 62015 | 62212 | assert( (pFrom->flags & MEM_RowSet)==0 ); |
| 62016 | | - VdbeMemReleaseExtern(pTo); |
| 62213 | + assert( pTo->db==pFrom->db ); |
| 62214 | + if( VdbeMemDynamic(pTo) ) vdbeMemClearExternAndSetNull(pTo); |
| 62017 | 62215 | memcpy(pTo, pFrom, MEMCELLSIZE); |
| 62018 | | - pTo->xDel = 0; |
| 62019 | 62216 | if( (pFrom->flags&MEM_Static)==0 ){ |
| 62020 | 62217 | pTo->flags &= ~(MEM_Dyn|MEM_Static|MEM_Ephem); |
| 62021 | 62218 | assert( srcType==MEM_Ephem || srcType==MEM_Static ); |
| 62022 | 62219 | pTo->flags |= srcType; |
| 62023 | 62220 | } |
| | @@ -62028,16 +62225,15 @@ |
| 62028 | 62225 | ** freed before the copy is made. |
| 62029 | 62226 | */ |
| 62030 | 62227 | SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){ |
| 62031 | 62228 | int rc = SQLITE_OK; |
| 62032 | 62229 | |
| 62230 | + assert( pTo->db==pFrom->db ); |
| 62033 | 62231 | assert( (pFrom->flags & MEM_RowSet)==0 ); |
| 62034 | | - VdbeMemReleaseExtern(pTo); |
| 62232 | + if( VdbeMemDynamic(pTo) ) vdbeMemClearExternAndSetNull(pTo); |
| 62035 | 62233 | memcpy(pTo, pFrom, MEMCELLSIZE); |
| 62036 | 62234 | pTo->flags &= ~MEM_Dyn; |
| 62037 | | - pTo->xDel = 0; |
| 62038 | | - |
| 62039 | 62235 | if( pTo->flags&(MEM_Str|MEM_Blob) ){ |
| 62040 | 62236 | if( 0==(pFrom->flags&MEM_Static) ){ |
| 62041 | 62237 | pTo->flags |= MEM_Ephem; |
| 62042 | 62238 | rc = sqlite3VdbeMemMakeWriteable(pTo); |
| 62043 | 62239 | } |
| | @@ -62058,12 +62254,11 @@ |
| 62058 | 62254 | assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db ); |
| 62059 | 62255 | |
| 62060 | 62256 | sqlite3VdbeMemRelease(pTo); |
| 62061 | 62257 | memcpy(pTo, pFrom, sizeof(Mem)); |
| 62062 | 62258 | pFrom->flags = MEM_Null; |
| 62063 | | - pFrom->xDel = 0; |
| 62064 | | - pFrom->zMalloc = 0; |
| 62259 | + pFrom->szMalloc = 0; |
| 62065 | 62260 | } |
| 62066 | 62261 | |
| 62067 | 62262 | /* |
| 62068 | 62263 | ** Change the value of a Mem to be a string or a BLOB. |
| 62069 | 62264 | ** |
| | @@ -62106,11 +62301,12 @@ |
| 62106 | 62301 | } |
| 62107 | 62302 | flags = (enc==0?MEM_Blob:MEM_Str); |
| 62108 | 62303 | if( nByte<0 ){ |
| 62109 | 62304 | assert( enc!=0 ); |
| 62110 | 62305 | if( enc==SQLITE_UTF8 ){ |
| 62111 | | - for(nByte=0; nByte<=iLimit && z[nByte]; nByte++){} |
| 62306 | + nByte = sqlite3Strlen30(z); |
| 62307 | + if( nByte>iLimit ) nByte = iLimit+1; |
| 62112 | 62308 | }else{ |
| 62113 | 62309 | for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){} |
| 62114 | 62310 | } |
| 62115 | 62311 | flags |= MEM_Term; |
| 62116 | 62312 | } |
| | @@ -62125,18 +62321,18 @@ |
| 62125 | 62321 | nAlloc += (enc==SQLITE_UTF8?1:2); |
| 62126 | 62322 | } |
| 62127 | 62323 | if( nByte>iLimit ){ |
| 62128 | 62324 | return SQLITE_TOOBIG; |
| 62129 | 62325 | } |
| 62130 | | - if( sqlite3VdbeMemGrow(pMem, nAlloc, 0) ){ |
| 62326 | + if( sqlite3VdbeMemClearAndResize(pMem, nAlloc) ){ |
| 62131 | 62327 | return SQLITE_NOMEM; |
| 62132 | 62328 | } |
| 62133 | 62329 | memcpy(pMem->z, z, nAlloc); |
| 62134 | 62330 | }else if( xDel==SQLITE_DYNAMIC ){ |
| 62135 | 62331 | sqlite3VdbeMemRelease(pMem); |
| 62136 | 62332 | pMem->zMalloc = pMem->z = (char *)z; |
| 62137 | | - pMem->xDel = 0; |
| 62333 | + pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc); |
| 62138 | 62334 | }else{ |
| 62139 | 62335 | sqlite3VdbeMemRelease(pMem); |
| 62140 | 62336 | pMem->z = (char *)z; |
| 62141 | 62337 | pMem->xDel = xDel; |
| 62142 | 62338 | flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn); |
| | @@ -62164,12 +62360,15 @@ |
| 62164 | 62360 | ** The data or key is taken from the entry that pCur is currently pointing |
| 62165 | 62361 | ** to. offset and amt determine what portion of the data or key to retrieve. |
| 62166 | 62362 | ** key is true to get the key or false to get data. The result is written |
| 62167 | 62363 | ** into the pMem element. |
| 62168 | 62364 | ** |
| 62169 | | -** The pMem structure is assumed to be uninitialized. Any prior content |
| 62170 | | -** is overwritten without being freed. |
| 62365 | +** The pMem object must have been initialized. This routine will use |
| 62366 | +** pMem->zMalloc to hold the content from the btree, if possible. New |
| 62367 | +** pMem->zMalloc space will be allocated if necessary. The calling routine |
| 62368 | +** is responsible for making sure that the pMem object is eventually |
| 62369 | +** destroyed. |
| 62171 | 62370 | ** |
| 62172 | 62371 | ** If this routine fails for any reason (malloc returns NULL or unable |
| 62173 | 62372 | ** to read from the disk) then the pMem is left in an inconsistent state. |
| 62174 | 62373 | */ |
| 62175 | 62374 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree( |
| | @@ -62182,10 +62381,11 @@ |
| 62182 | 62381 | char *zData; /* Data from the btree layer */ |
| 62183 | 62382 | u32 available = 0; /* Number of bytes available on the local btree page */ |
| 62184 | 62383 | int rc = SQLITE_OK; /* Return code */ |
| 62185 | 62384 | |
| 62186 | 62385 | assert( sqlite3BtreeCursorIsValid(pCur) ); |
| 62386 | + assert( !VdbeMemDynamic(pMem) ); |
| 62187 | 62387 | |
| 62188 | 62388 | /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert() |
| 62189 | 62389 | ** that both the BtShared and database handle mutexes are held. */ |
| 62190 | 62390 | assert( (pMem->flags & MEM_RowSet)==0 ); |
| 62191 | 62391 | if( key ){ |
| | @@ -62194,27 +62394,29 @@ |
| 62194 | 62394 | zData = (char *)sqlite3BtreeDataFetch(pCur, &available); |
| 62195 | 62395 | } |
| 62196 | 62396 | assert( zData!=0 ); |
| 62197 | 62397 | |
| 62198 | 62398 | if( offset+amt<=available ){ |
| 62199 | | - sqlite3VdbeMemRelease(pMem); |
| 62200 | 62399 | pMem->z = &zData[offset]; |
| 62201 | 62400 | pMem->flags = MEM_Blob|MEM_Ephem; |
| 62202 | 62401 | pMem->n = (int)amt; |
| 62203 | | - }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){ |
| 62204 | | - if( key ){ |
| 62205 | | - rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z); |
| 62206 | | - }else{ |
| 62207 | | - rc = sqlite3BtreeData(pCur, offset, amt, pMem->z); |
| 62208 | | - } |
| 62209 | | - if( rc==SQLITE_OK ){ |
| 62210 | | - pMem->z[amt] = 0; |
| 62211 | | - pMem->z[amt+1] = 0; |
| 62212 | | - pMem->flags = MEM_Blob|MEM_Term; |
| 62213 | | - pMem->n = (int)amt; |
| 62214 | | - }else{ |
| 62215 | | - sqlite3VdbeMemRelease(pMem); |
| 62402 | + }else{ |
| 62403 | + pMem->flags = MEM_Null; |
| 62404 | + if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+2)) ){ |
| 62405 | + if( key ){ |
| 62406 | + rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z); |
| 62407 | + }else{ |
| 62408 | + rc = sqlite3BtreeData(pCur, offset, amt, pMem->z); |
| 62409 | + } |
| 62410 | + if( rc==SQLITE_OK ){ |
| 62411 | + pMem->z[amt] = 0; |
| 62412 | + pMem->z[amt+1] = 0; |
| 62413 | + pMem->flags = MEM_Blob|MEM_Term; |
| 62414 | + pMem->n = (int)amt; |
| 62415 | + }else{ |
| 62416 | + sqlite3VdbeMemRelease(pMem); |
| 62417 | + } |
| 62216 | 62418 | } |
| 62217 | 62419 | } |
| 62218 | 62420 | |
| 62219 | 62421 | return rc; |
| 62220 | 62422 | } |
| | @@ -62434,18 +62636,18 @@ |
| 62434 | 62636 | /* This branch happens for multiple negative signs. Ex: -(-5) */ |
| 62435 | 62637 | if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) |
| 62436 | 62638 | && pVal!=0 |
| 62437 | 62639 | ){ |
| 62438 | 62640 | sqlite3VdbeMemNumerify(pVal); |
| 62439 | | - if( pVal->u.i==SMALLEST_INT64 ){ |
| 62440 | | - pVal->flags &= ~MEM_Int; |
| 62441 | | - pVal->flags |= MEM_Real; |
| 62442 | | - pVal->r = (double)SMALLEST_INT64; |
| 62641 | + if( pVal->flags & MEM_Real ){ |
| 62642 | + pVal->u.r = -pVal->u.r; |
| 62643 | + }else if( pVal->u.i==SMALLEST_INT64 ){ |
| 62644 | + pVal->u.r = -(double)SMALLEST_INT64; |
| 62645 | + MemSetTypeFlag(pVal, MEM_Real); |
| 62443 | 62646 | }else{ |
| 62444 | 62647 | pVal->u.i = -pVal->u.i; |
| 62445 | 62648 | } |
| 62446 | | - pVal->r = -pVal->r; |
| 62447 | 62649 | sqlite3ValueApplyAffinity(pVal, affinity, enc); |
| 62448 | 62650 | } |
| 62449 | 62651 | }else if( op==TK_NULL ){ |
| 62450 | 62652 | pVal = valueNew(db, pCtx); |
| 62451 | 62653 | if( pVal==0 ) goto no_mem; |
| | @@ -62749,11 +62951,11 @@ |
| 62749 | 62951 | int i; |
| 62750 | 62952 | int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField; |
| 62751 | 62953 | Mem *aMem = pRec->aMem; |
| 62752 | 62954 | sqlite3 *db = aMem[0].db; |
| 62753 | 62955 | for(i=0; i<nCol; i++){ |
| 62754 | | - sqlite3DbFree(db, aMem[i].zMalloc); |
| 62956 | + if( aMem[i].szMalloc ) sqlite3DbFree(db, aMem[i].zMalloc); |
| 62755 | 62957 | } |
| 62756 | 62958 | sqlite3KeyInfoUnref(pRec->pKeyInfo); |
| 62757 | 62959 | sqlite3DbFree(db, pRec); |
| 62758 | 62960 | } |
| 62759 | 62961 | } |
| | @@ -62809,13 +63011,11 @@ |
| 62809 | 63011 | ** May you find forgiveness for yourself and forgive others. |
| 62810 | 63012 | ** May you share freely, never taking more than you give. |
| 62811 | 63013 | ** |
| 62812 | 63014 | ************************************************************************* |
| 62813 | 63015 | ** This file contains code used for creating, destroying, and populating |
| 62814 | | -** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.) Prior |
| 62815 | | -** to version 2.8.7, all this code was combined into the vdbe.c source file. |
| 62816 | | -** But that file was getting too big so this subroutines were split out. |
| 63016 | +** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.) |
| 62817 | 63017 | */ |
| 62818 | 63018 | |
| 62819 | 63019 | /* |
| 62820 | 63020 | ** Create a new virtual database engine. |
| 62821 | 63021 | */ |
| | @@ -63495,11 +63695,11 @@ |
| 63495 | 63695 | case P4_MEM: { |
| 63496 | 63696 | if( db->pnBytesFreed==0 ){ |
| 63497 | 63697 | sqlite3ValueFree((sqlite3_value*)p4); |
| 63498 | 63698 | }else{ |
| 63499 | 63699 | Mem *p = (Mem*)p4; |
| 63500 | | - sqlite3DbFree(db, p->zMalloc); |
| 63700 | + if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc); |
| 63501 | 63701 | sqlite3DbFree(db, p); |
| 63502 | 63702 | } |
| 63503 | 63703 | break; |
| 63504 | 63704 | } |
| 63505 | 63705 | case P4_VTAB : { |
| | @@ -63692,11 +63892,11 @@ |
| 63692 | 63892 | ** |
| 63693 | 63893 | ** If a memory allocation error has occurred prior to the calling of this |
| 63694 | 63894 | ** routine, then a pointer to a dummy VdbeOp will be returned. That opcode |
| 63695 | 63895 | ** is readable but not writable, though it is cast to a writable value. |
| 63696 | 63896 | ** The return of a dummy opcode allows the call to continue functioning |
| 63697 | | -** after a OOM fault without having to check to see if the return from |
| 63897 | +** after an OOM fault without having to check to see if the return from |
| 63698 | 63898 | ** this routine is a valid pointer. But because the dummy.opcode is 0, |
| 63699 | 63899 | ** dummy will never be written to. This is verified by code inspection and |
| 63700 | 63900 | ** by running with Valgrind. |
| 63701 | 63901 | */ |
| 63702 | 63902 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){ |
| | @@ -63873,11 +64073,11 @@ |
| 63873 | 64073 | if( pMem->flags & MEM_Str ){ |
| 63874 | 64074 | zP4 = pMem->z; |
| 63875 | 64075 | }else if( pMem->flags & MEM_Int ){ |
| 63876 | 64076 | sqlite3_snprintf(nTemp, zTemp, "%lld", pMem->u.i); |
| 63877 | 64077 | }else if( pMem->flags & MEM_Real ){ |
| 63878 | | - sqlite3_snprintf(nTemp, zTemp, "%.16g", pMem->r); |
| 64078 | + sqlite3_snprintf(nTemp, zTemp, "%.16g", pMem->u.r); |
| 63879 | 64079 | }else if( pMem->flags & MEM_Null ){ |
| 63880 | 64080 | sqlite3_snprintf(nTemp, zTemp, "NULL"); |
| 63881 | 64081 | }else{ |
| 63882 | 64082 | assert( pMem->flags & MEM_Blob ); |
| 63883 | 64083 | zP4 = "(blob)"; |
| | @@ -64023,20 +64223,20 @@ |
| 64023 | 64223 | /* |
| 64024 | 64224 | ** Release an array of N Mem elements |
| 64025 | 64225 | */ |
| 64026 | 64226 | static void releaseMemArray(Mem *p, int N){ |
| 64027 | 64227 | if( p && N ){ |
| 64028 | | - Mem *pEnd; |
| 64228 | + Mem *pEnd = &p[N]; |
| 64029 | 64229 | sqlite3 *db = p->db; |
| 64030 | 64230 | u8 malloc_failed = db->mallocFailed; |
| 64031 | 64231 | if( db->pnBytesFreed ){ |
| 64032 | | - for(pEnd=&p[N]; p<pEnd; p++){ |
| 64033 | | - sqlite3DbFree(db, p->zMalloc); |
| 64034 | | - } |
| 64232 | + do{ |
| 64233 | + if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc); |
| 64234 | + }while( (++p)<pEnd ); |
| 64035 | 64235 | return; |
| 64036 | 64236 | } |
| 64037 | | - for(pEnd=&p[N]; p<pEnd; p++){ |
| 64237 | + do{ |
| 64038 | 64238 | assert( (&p[1])==pEnd || p[0].db==p[1].db ); |
| 64039 | 64239 | assert( sqlite3VdbeCheckMemInvariants(p) ); |
| 64040 | 64240 | |
| 64041 | 64241 | /* This block is really an inlined version of sqlite3VdbeMemRelease() |
| 64042 | 64242 | ** that takes advantage of the fact that the memory cell value is |
| | @@ -64054,17 +64254,17 @@ |
| 64054 | 64254 | testcase( p->flags & MEM_Dyn ); |
| 64055 | 64255 | testcase( p->flags & MEM_Frame ); |
| 64056 | 64256 | testcase( p->flags & MEM_RowSet ); |
| 64057 | 64257 | if( p->flags&(MEM_Agg|MEM_Dyn|MEM_Frame|MEM_RowSet) ){ |
| 64058 | 64258 | sqlite3VdbeMemRelease(p); |
| 64059 | | - }else if( p->zMalloc ){ |
| 64259 | + }else if( p->szMalloc ){ |
| 64060 | 64260 | sqlite3DbFree(db, p->zMalloc); |
| 64061 | | - p->zMalloc = 0; |
| 64261 | + p->szMalloc = 0; |
| 64062 | 64262 | } |
| 64063 | 64263 | |
| 64064 | 64264 | p->flags = MEM_Undefined; |
| 64065 | | - } |
| 64265 | + }while( (++p)<pEnd ); |
| 64066 | 64266 | db->mallocFailed = malloc_failed; |
| 64067 | 64267 | } |
| 64068 | 64268 | } |
| 64069 | 64269 | |
| 64070 | 64270 | /* |
| | @@ -64223,11 +64423,11 @@ |
| 64223 | 64423 | |
| 64224 | 64424 | pMem->flags = MEM_Int; |
| 64225 | 64425 | pMem->u.i = pOp->p3; /* P3 */ |
| 64226 | 64426 | pMem++; |
| 64227 | 64427 | |
| 64228 | | - if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */ |
| 64428 | + if( sqlite3VdbeMemClearAndResize(pMem, 32) ){ /* P4 */ |
| 64229 | 64429 | assert( p->db->mallocFailed ); |
| 64230 | 64430 | return SQLITE_ERROR; |
| 64231 | 64431 | } |
| 64232 | 64432 | pMem->flags = MEM_Str|MEM_Term; |
| 64233 | 64433 | zP4 = displayP4(pOp, pMem->z, 32); |
| | @@ -64239,11 +64439,11 @@ |
| 64239 | 64439 | pMem->enc = SQLITE_UTF8; |
| 64240 | 64440 | } |
| 64241 | 64441 | pMem++; |
| 64242 | 64442 | |
| 64243 | 64443 | if( p->explain==1 ){ |
| 64244 | | - if( sqlite3VdbeMemGrow(pMem, 4, 0) ){ |
| 64444 | + if( sqlite3VdbeMemClearAndResize(pMem, 4) ){ |
| 64245 | 64445 | assert( p->db->mallocFailed ); |
| 64246 | 64446 | return SQLITE_ERROR; |
| 64247 | 64447 | } |
| 64248 | 64448 | pMem->flags = MEM_Str|MEM_Term; |
| 64249 | 64449 | pMem->n = 2; |
| | @@ -64250,11 +64450,11 @@ |
| 64250 | 64450 | sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */ |
| 64251 | 64451 | pMem->enc = SQLITE_UTF8; |
| 64252 | 64452 | pMem++; |
| 64253 | 64453 | |
| 64254 | 64454 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 64255 | | - if( sqlite3VdbeMemGrow(pMem, 500, 0) ){ |
| 64455 | + if( sqlite3VdbeMemClearAndResize(pMem, 500) ){ |
| 64256 | 64456 | assert( p->db->mallocFailed ); |
| 64257 | 64457 | return SQLITE_ERROR; |
| 64258 | 64458 | } |
| 64259 | 64459 | pMem->flags = MEM_Str|MEM_Term; |
| 64260 | 64460 | pMem->n = displayComment(pOp, zP4, pMem->z, 500); |
| | @@ -64403,17 +64603,17 @@ |
| 64403 | 64603 | } |
| 64404 | 64604 | |
| 64405 | 64605 | /* |
| 64406 | 64606 | ** Prepare a virtual machine for execution for the first time after |
| 64407 | 64607 | ** creating the virtual machine. This involves things such |
| 64408 | | -** as allocating stack space and initializing the program counter. |
| 64608 | +** as allocating registers and initializing the program counter. |
| 64409 | 64609 | ** After the VDBE has be prepped, it can be executed by one or more |
| 64410 | 64610 | ** calls to sqlite3VdbeExec(). |
| 64411 | 64611 | ** |
| 64412 | | -** This function may be called exact once on a each virtual machine. |
| 64612 | +** This function may be called exactly once on each virtual machine. |
| 64413 | 64613 | ** After this routine is called the VM has been "packaged" and is ready |
| 64414 | | -** to run. After this routine is called, futher calls to |
| 64614 | +** to run. After this routine is called, further calls to |
| 64415 | 64615 | ** sqlite3VdbeAddOp() functions are prohibited. This routine disconnects |
| 64416 | 64616 | ** the Vdbe from the Parse object that helped generate it so that the |
| 64417 | 64617 | ** the Vdbe becomes an independent entity and the Parse object can be |
| 64418 | 64618 | ** destroyed. |
| 64419 | 64619 | ** |
| | @@ -64615,15 +64815,11 @@ |
| 64615 | 64815 | sqlite3VdbeDeleteAuxData(p, -1, 0); |
| 64616 | 64816 | assert( p->pAuxData==0 ); |
| 64617 | 64817 | } |
| 64618 | 64818 | |
| 64619 | 64819 | /* |
| 64620 | | -** Clean up the VM after execution. |
| 64621 | | -** |
| 64622 | | -** This routine will automatically close any cursors, lists, and/or |
| 64623 | | -** sorters that were left open. It also deletes the values of |
| 64624 | | -** variables in the aVar[] array. |
| 64820 | +** Clean up the VM after a single run. |
| 64625 | 64821 | */ |
| 64626 | 64822 | static void Cleanup(Vdbe *p){ |
| 64627 | 64823 | sqlite3 *db = p->db; |
| 64628 | 64824 | |
| 64629 | 64825 | #ifdef SQLITE_DEBUG |
| | @@ -64787,11 +64983,11 @@ |
| 64787 | 64983 | } |
| 64788 | 64984 | } |
| 64789 | 64985 | |
| 64790 | 64986 | /* The complex case - There is a multi-file write-transaction active. |
| 64791 | 64987 | ** This requires a master journal file to ensure the transaction is |
| 64792 | | - ** committed atomicly. |
| 64988 | + ** committed atomically. |
| 64793 | 64989 | */ |
| 64794 | 64990 | #ifndef SQLITE_OMIT_DISKIO |
| 64795 | 64991 | else{ |
| 64796 | 64992 | sqlite3_vfs *pVfs = db->pVfs; |
| 64797 | 64993 | int needSync = 0; |
| | @@ -65435,11 +65631,11 @@ |
| 65435 | 65631 | ** |
| 65436 | 65632 | ** * the associated function parameter is the 32nd or later (counting |
| 65437 | 65633 | ** from left to right), or |
| 65438 | 65634 | ** |
| 65439 | 65635 | ** * the corresponding bit in argument mask is clear (where the first |
| 65440 | | -** function parameter corrsponds to bit 0 etc.). |
| 65636 | +** function parameter corresponds to bit 0 etc.). |
| 65441 | 65637 | */ |
| 65442 | 65638 | SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe *pVdbe, int iOp, int mask){ |
| 65443 | 65639 | AuxData **pp = &pVdbe->pAuxData; |
| 65444 | 65640 | while( *pp ){ |
| 65445 | 65641 | AuxData *pAux = *pp; |
| | @@ -65539,11 +65735,11 @@ |
| 65539 | 65735 | |
| 65540 | 65736 | /* |
| 65541 | 65737 | ** Something has moved cursor "p" out of place. Maybe the row it was |
| 65542 | 65738 | ** pointed to was deleted out from under it. Or maybe the btree was |
| 65543 | 65739 | ** rebalanced. Whatever the cause, try to restore "p" to the place it |
| 65544 | | -** is suppose to be pointing. If the row was deleted out from under the |
| 65740 | +** is supposed to be pointing. If the row was deleted out from under the |
| 65545 | 65741 | ** cursor, set the cursor to point to a NULL row. |
| 65546 | 65742 | */ |
| 65547 | 65743 | static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){ |
| 65548 | 65744 | int isDifferentRow, rc; |
| 65549 | 65745 | assert( p->pCursor!=0 ); |
| | @@ -65746,12 +65942,12 @@ |
| 65746 | 65942 | /* Integer and Real */ |
| 65747 | 65943 | if( serial_type<=7 && serial_type>0 ){ |
| 65748 | 65944 | u64 v; |
| 65749 | 65945 | u32 i; |
| 65750 | 65946 | if( serial_type==7 ){ |
| 65751 | | - assert( sizeof(v)==sizeof(pMem->r) ); |
| 65752 | | - memcpy(&v, &pMem->r, sizeof(v)); |
| 65947 | + assert( sizeof(v)==sizeof(pMem->u.r) ); |
| 65948 | + memcpy(&v, &pMem->u.r, sizeof(v)); |
| 65753 | 65949 | swapMixedEndianFloat(v); |
| 65754 | 65950 | }else{ |
| 65755 | 65951 | v = pMem->u.i; |
| 65756 | 65952 | } |
| 65757 | 65953 | len = i = sqlite3VdbeSerialTypeLen(serial_type); |
| | @@ -65817,14 +66013,14 @@ |
| 65817 | 66013 | static const double r1 = 1.0; |
| 65818 | 66014 | u64 t2 = t1; |
| 65819 | 66015 | swapMixedEndianFloat(t2); |
| 65820 | 66016 | assert( sizeof(r1)==sizeof(t2) && memcmp(&r1, &t2, sizeof(r1))==0 ); |
| 65821 | 66017 | #endif |
| 65822 | | - assert( sizeof(x)==8 && sizeof(pMem->r)==8 ); |
| 66018 | + assert( sizeof(x)==8 && sizeof(pMem->u.r)==8 ); |
| 65823 | 66019 | swapMixedEndianFloat(x); |
| 65824 | | - memcpy(&pMem->r, &x, sizeof(x)); |
| 65825 | | - pMem->flags = sqlite3IsNaN(pMem->r) ? MEM_Null : MEM_Real; |
| 66020 | + memcpy(&pMem->u.r, &x, sizeof(x)); |
| 66021 | + pMem->flags = sqlite3IsNaN(pMem->u.r) ? MEM_Null : MEM_Real; |
| 65826 | 66022 | } |
| 65827 | 66023 | return 8; |
| 65828 | 66024 | } |
| 65829 | 66025 | SQLITE_PRIVATE u32 sqlite3VdbeSerialGet( |
| 65830 | 66026 | const unsigned char *buf, /* Buffer to deserialize from */ |
| | @@ -65882,11 +66078,10 @@ |
| 65882 | 66078 | } |
| 65883 | 66079 | default: { |
| 65884 | 66080 | static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem }; |
| 65885 | 66081 | pMem->z = (char *)buf; |
| 65886 | 66082 | pMem->n = (serial_type-12)/2; |
| 65887 | | - pMem->xDel = 0; |
| 65888 | 66083 | pMem->flags = aFlag[serial_type&1]; |
| 65889 | 66084 | return pMem->n; |
| 65890 | 66085 | } |
| 65891 | 66086 | } |
| 65892 | 66087 | return 0; |
| | @@ -65958,21 +66153,21 @@ |
| 65958 | 66153 | p->default_rc = 0; |
| 65959 | 66154 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 65960 | 66155 | idx = getVarint32(aKey, szHdr); |
| 65961 | 66156 | d = szHdr; |
| 65962 | 66157 | u = 0; |
| 65963 | | - while( idx<szHdr && u<p->nField && d<=nKey ){ |
| 66158 | + while( idx<szHdr && d<=nKey ){ |
| 65964 | 66159 | u32 serial_type; |
| 65965 | 66160 | |
| 65966 | 66161 | idx += getVarint32(&aKey[idx], serial_type); |
| 65967 | 66162 | pMem->enc = pKeyInfo->enc; |
| 65968 | 66163 | pMem->db = pKeyInfo->db; |
| 65969 | 66164 | /* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */ |
| 65970 | | - pMem->zMalloc = 0; |
| 66165 | + pMem->szMalloc = 0; |
| 65971 | 66166 | d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem); |
| 65972 | 66167 | pMem++; |
| 65973 | | - u++; |
| 66168 | + if( (++u)>=p->nField ) break; |
| 65974 | 66169 | } |
| 65975 | 66170 | assert( u<=pKeyInfo->nField + 1 ); |
| 65976 | 66171 | p->nField = u; |
| 65977 | 66172 | } |
| 65978 | 66173 | |
| | @@ -66005,11 +66200,11 @@ |
| 66005 | 66200 | pKeyInfo = pPKey2->pKeyInfo; |
| 66006 | 66201 | if( pKeyInfo->db==0 ) return 1; |
| 66007 | 66202 | mem1.enc = pKeyInfo->enc; |
| 66008 | 66203 | mem1.db = pKeyInfo->db; |
| 66009 | 66204 | /* mem1.flags = 0; // Will be initialized by sqlite3VdbeSerialGet() */ |
| 66010 | | - VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */ |
| 66205 | + VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */ |
| 66011 | 66206 | |
| 66012 | 66207 | /* Compilers may complain that mem1.u.i is potentially uninitialized. |
| 66013 | 66208 | ** We could initialize it, as shown here, to silence those complaints. |
| 66014 | 66209 | ** But in fact, mem1.u.i will never actually be used uninitialized, and doing |
| 66015 | 66210 | ** the unnecessary initialization has a measurable negative performance |
| | @@ -66048,11 +66243,11 @@ |
| 66048 | 66243 | |
| 66049 | 66244 | /* Do the comparison |
| 66050 | 66245 | */ |
| 66051 | 66246 | rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->aColl[i]); |
| 66052 | 66247 | if( rc!=0 ){ |
| 66053 | | - assert( mem1.zMalloc==0 ); /* See comment below */ |
| 66248 | + assert( mem1.szMalloc==0 ); /* See comment below */ |
| 66054 | 66249 | if( pKeyInfo->aSortOrder[i] ){ |
| 66055 | 66250 | rc = -rc; /* Invert the result for DESC sort order. */ |
| 66056 | 66251 | } |
| 66057 | 66252 | goto debugCompareEnd; |
| 66058 | 66253 | } |
| | @@ -66061,14 +66256,14 @@ |
| 66061 | 66256 | |
| 66062 | 66257 | /* No memory allocation is ever used on mem1. Prove this using |
| 66063 | 66258 | ** the following assert(). If the assert() fails, it indicates a |
| 66064 | 66259 | ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1). |
| 66065 | 66260 | */ |
| 66066 | | - assert( mem1.zMalloc==0 ); |
| 66261 | + assert( mem1.szMalloc==0 ); |
| 66067 | 66262 | |
| 66068 | 66263 | /* rc==0 here means that one of the keys ran out of fields and |
| 66069 | | - ** all the fields up to that point were equal. Return the the default_rc |
| 66264 | + ** all the fields up to that point were equal. Return the default_rc |
| 66070 | 66265 | ** value. */ |
| 66071 | 66266 | rc = pPKey2->default_rc; |
| 66072 | 66267 | |
| 66073 | 66268 | debugCompareEnd: |
| 66074 | 66269 | if( desiredResult==0 && rc==0 ) return 1; |
| | @@ -66100,12 +66295,12 @@ |
| 66100 | 66295 | int rc; |
| 66101 | 66296 | const void *v1, *v2; |
| 66102 | 66297 | int n1, n2; |
| 66103 | 66298 | Mem c1; |
| 66104 | 66299 | Mem c2; |
| 66105 | | - memset(&c1, 0, sizeof(c1)); |
| 66106 | | - memset(&c2, 0, sizeof(c2)); |
| 66300 | + sqlite3VdbeMemInit(&c1, pMem1->db, MEM_Null); |
| 66301 | + sqlite3VdbeMemInit(&c2, pMem1->db, MEM_Null); |
| 66107 | 66302 | sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem); |
| 66108 | 66303 | sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem); |
| 66109 | 66304 | v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc); |
| 66110 | 66305 | n1 = v1==0 ? 0 : c1.n; |
| 66111 | 66306 | v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc); |
| | @@ -66115,10 +66310,22 @@ |
| 66115 | 66310 | sqlite3VdbeMemRelease(&c2); |
| 66116 | 66311 | if( (v1==0 || v2==0) && prcErr ) *prcErr = SQLITE_NOMEM; |
| 66117 | 66312 | return rc; |
| 66118 | 66313 | } |
| 66119 | 66314 | } |
| 66315 | + |
| 66316 | +/* |
| 66317 | +** Compare two blobs. Return negative, zero, or positive if the first |
| 66318 | +** is less than, equal to, or greater than the second, respectively. |
| 66319 | +** If one blob is a prefix of the other, then the shorter is the lessor. |
| 66320 | +*/ |
| 66321 | +static SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem *pB2){ |
| 66322 | + int c = memcmp(pB1->z, pB2->z, pB1->n>pB2->n ? pB2->n : pB1->n); |
| 66323 | + if( c ) return c; |
| 66324 | + return pB1->n - pB2->n; |
| 66325 | +} |
| 66326 | + |
| 66120 | 66327 | |
| 66121 | 66328 | /* |
| 66122 | 66329 | ** Compare the values contained by the two memory cells, returning |
| 66123 | 66330 | ** negative, zero or positive if pMem1 is less than, equal to, or greater |
| 66124 | 66331 | ** than pMem2. Sorting order is NULL's first, followed by numbers (integers |
| | @@ -66126,11 +66333,10 @@ |
| 66126 | 66333 | ** sequence pColl and finally blob's ordered by memcmp(). |
| 66127 | 66334 | ** |
| 66128 | 66335 | ** Two NULL values are considered equal by this function. |
| 66129 | 66336 | */ |
| 66130 | 66337 | SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){ |
| 66131 | | - int rc; |
| 66132 | 66338 | int f1, f2; |
| 66133 | 66339 | int combined_flags; |
| 66134 | 66340 | |
| 66135 | 66341 | f1 = pMem1->flags; |
| 66136 | 66342 | f2 = pMem2->flags; |
| | @@ -66154,18 +66360,18 @@ |
| 66154 | 66360 | if( pMem1->u.i < pMem2->u.i ) return -1; |
| 66155 | 66361 | if( pMem1->u.i > pMem2->u.i ) return 1; |
| 66156 | 66362 | return 0; |
| 66157 | 66363 | } |
| 66158 | 66364 | if( (f1&MEM_Real)!=0 ){ |
| 66159 | | - r1 = pMem1->r; |
| 66365 | + r1 = pMem1->u.r; |
| 66160 | 66366 | }else if( (f1&MEM_Int)!=0 ){ |
| 66161 | 66367 | r1 = (double)pMem1->u.i; |
| 66162 | 66368 | }else{ |
| 66163 | 66369 | return 1; |
| 66164 | 66370 | } |
| 66165 | 66371 | if( (f2&MEM_Real)!=0 ){ |
| 66166 | | - r2 = pMem2->r; |
| 66372 | + r2 = pMem2->u.r; |
| 66167 | 66373 | }else if( (f2&MEM_Int)!=0 ){ |
| 66168 | 66374 | r2 = (double)pMem2->u.i; |
| 66169 | 66375 | }else{ |
| 66170 | 66376 | return -1; |
| 66171 | 66377 | } |
| | @@ -66201,15 +66407,11 @@ |
| 66201 | 66407 | /* If a NULL pointer was passed as the collate function, fall through |
| 66202 | 66408 | ** to the blob case and use memcmp(). */ |
| 66203 | 66409 | } |
| 66204 | 66410 | |
| 66205 | 66411 | /* Both values must be blobs. Compare using memcmp(). */ |
| 66206 | | - rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n); |
| 66207 | | - if( rc==0 ){ |
| 66208 | | - rc = pMem1->n - pMem2->n; |
| 66209 | | - } |
| 66210 | | - return rc; |
| 66412 | + return sqlite3BlobCompare(pMem1, pMem2); |
| 66211 | 66413 | } |
| 66212 | 66414 | |
| 66213 | 66415 | |
| 66214 | 66416 | /* |
| 66215 | 66417 | ** The first argument passed to this function is a serial-type that |
| | @@ -66255,11 +66457,11 @@ |
| 66255 | 66457 | /* |
| 66256 | 66458 | ** This function compares the two table rows or index records |
| 66257 | 66459 | ** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero |
| 66258 | 66460 | ** or positive integer if key1 is less than, equal to or |
| 66259 | 66461 | ** greater than key2. The {nKey1, pKey1} key must be a blob |
| 66260 | | -** created by th OP_MakeRecord opcode of the VDBE. The pPKey2 |
| 66462 | +** created by the OP_MakeRecord opcode of the VDBE. The pPKey2 |
| 66261 | 66463 | ** key must be a parsed key such as obtained from |
| 66262 | 66464 | ** sqlite3VdbeParseRecord. |
| 66263 | 66465 | ** |
| 66264 | 66466 | ** If argument bSkip is non-zero, it is assumed that the caller has already |
| 66265 | 66467 | ** determined that the first fields of the keys are equal. |
| | @@ -66271,11 +66473,11 @@ |
| 66271 | 66473 | ** If database corruption is discovered, set pPKey2->errCode to |
| 66272 | 66474 | ** SQLITE_CORRUPT and return 0. If an OOM error is encountered, |
| 66273 | 66475 | ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the |
| 66274 | 66476 | ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db). |
| 66275 | 66477 | */ |
| 66276 | | -SQLITE_PRIVATE int sqlite3VdbeRecordCompare( |
| 66478 | +static int vdbeRecordCompareWithSkip( |
| 66277 | 66479 | int nKey1, const void *pKey1, /* Left key */ |
| 66278 | 66480 | UnpackedRecord *pPKey2, /* Right key */ |
| 66279 | 66481 | int bSkip /* If true, skip the first field */ |
| 66280 | 66482 | ){ |
| 66281 | 66483 | u32 d1; /* Offset into aKey[] of next data element */ |
| | @@ -66306,11 +66508,11 @@ |
| 66306 | 66508 | return 0; /* Corruption */ |
| 66307 | 66509 | } |
| 66308 | 66510 | i = 0; |
| 66309 | 66511 | } |
| 66310 | 66512 | |
| 66311 | | - VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */ |
| 66513 | + VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */ |
| 66312 | 66514 | assert( pPKey2->pKeyInfo->nField+pPKey2->pKeyInfo->nXField>=pPKey2->nField |
| 66313 | 66515 | || CORRUPT_DB ); |
| 66314 | 66516 | assert( pPKey2->pKeyInfo->aSortOrder!=0 ); |
| 66315 | 66517 | assert( pPKey2->pKeyInfo->nField>0 ); |
| 66316 | 66518 | assert( idx1<=szHdr1 || CORRUPT_DB ); |
| | @@ -66326,13 +66528,13 @@ |
| 66326 | 66528 | }else if( serial_type==0 ){ |
| 66327 | 66529 | rc = -1; |
| 66328 | 66530 | }else if( serial_type==7 ){ |
| 66329 | 66531 | double rhs = (double)pRhs->u.i; |
| 66330 | 66532 | sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1); |
| 66331 | | - if( mem1.r<rhs ){ |
| 66533 | + if( mem1.u.r<rhs ){ |
| 66332 | 66534 | rc = -1; |
| 66333 | | - }else if( mem1.r>rhs ){ |
| 66535 | + }else if( mem1.u.r>rhs ){ |
| 66334 | 66536 | rc = +1; |
| 66335 | 66537 | } |
| 66336 | 66538 | }else{ |
| 66337 | 66539 | i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]); |
| 66338 | 66540 | i64 rhs = pRhs->u.i; |
| | @@ -66350,15 +66552,15 @@ |
| 66350 | 66552 | if( serial_type>=12 ){ |
| 66351 | 66553 | rc = +1; |
| 66352 | 66554 | }else if( serial_type==0 ){ |
| 66353 | 66555 | rc = -1; |
| 66354 | 66556 | }else{ |
| 66355 | | - double rhs = pRhs->r; |
| 66557 | + double rhs = pRhs->u.r; |
| 66356 | 66558 | double lhs; |
| 66357 | 66559 | sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1); |
| 66358 | 66560 | if( serial_type==7 ){ |
| 66359 | | - lhs = mem1.r; |
| 66561 | + lhs = mem1.u.r; |
| 66360 | 66562 | }else{ |
| 66361 | 66563 | lhs = (double)mem1.u.i; |
| 66362 | 66564 | } |
| 66363 | 66565 | if( lhs<rhs ){ |
| 66364 | 66566 | rc = -1; |
| | @@ -66429,11 +66631,11 @@ |
| 66429 | 66631 | if( rc!=0 ){ |
| 66430 | 66632 | if( pKeyInfo->aSortOrder[i] ){ |
| 66431 | 66633 | rc = -rc; |
| 66432 | 66634 | } |
| 66433 | 66635 | assert( vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, rc) ); |
| 66434 | | - assert( mem1.zMalloc==0 ); /* See comment below */ |
| 66636 | + assert( mem1.szMalloc==0 ); /* See comment below */ |
| 66435 | 66637 | return rc; |
| 66436 | 66638 | } |
| 66437 | 66639 | |
| 66438 | 66640 | i++; |
| 66439 | 66641 | pRhs++; |
| | @@ -66442,21 +66644,28 @@ |
| 66442 | 66644 | }while( idx1<(unsigned)szHdr1 && i<pPKey2->nField && d1<=(unsigned)nKey1 ); |
| 66443 | 66645 | |
| 66444 | 66646 | /* No memory allocation is ever used on mem1. Prove this using |
| 66445 | 66647 | ** the following assert(). If the assert() fails, it indicates a |
| 66446 | 66648 | ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1). */ |
| 66447 | | - assert( mem1.zMalloc==0 ); |
| 66649 | + assert( mem1.szMalloc==0 ); |
| 66448 | 66650 | |
| 66449 | 66651 | /* rc==0 here means that one or both of the keys ran out of fields and |
| 66450 | | - ** all the fields up to that point were equal. Return the the default_rc |
| 66652 | + ** all the fields up to that point were equal. Return the default_rc |
| 66451 | 66653 | ** value. */ |
| 66452 | 66654 | assert( CORRUPT_DB |
| 66453 | 66655 | || vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, pPKey2->default_rc) |
| 66454 | 66656 | || pKeyInfo->db->mallocFailed |
| 66455 | 66657 | ); |
| 66456 | 66658 | return pPKey2->default_rc; |
| 66457 | 66659 | } |
| 66660 | +SQLITE_PRIVATE int sqlite3VdbeRecordCompare( |
| 66661 | + int nKey1, const void *pKey1, /* Left key */ |
| 66662 | + UnpackedRecord *pPKey2 /* Right key */ |
| 66663 | +){ |
| 66664 | + return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0); |
| 66665 | +} |
| 66666 | + |
| 66458 | 66667 | |
| 66459 | 66668 | /* |
| 66460 | 66669 | ** This function is an optimized version of sqlite3VdbeRecordCompare() |
| 66461 | 66670 | ** that (a) the first field of pPKey2 is an integer, and (b) the |
| 66462 | 66671 | ** size-of-header varint at the start of (pKey1/nKey1) fits in a single |
| | @@ -66465,23 +66674,20 @@ |
| 66465 | 66674 | ** To avoid concerns about buffer overreads, this routine is only used |
| 66466 | 66675 | ** on schemas where the maximum valid header size is 63 bytes or less. |
| 66467 | 66676 | */ |
| 66468 | 66677 | static int vdbeRecordCompareInt( |
| 66469 | 66678 | int nKey1, const void *pKey1, /* Left key */ |
| 66470 | | - UnpackedRecord *pPKey2, /* Right key */ |
| 66471 | | - int bSkip /* Ignored */ |
| 66679 | + UnpackedRecord *pPKey2 /* Right key */ |
| 66472 | 66680 | ){ |
| 66473 | 66681 | const u8 *aKey = &((const u8*)pKey1)[*(const u8*)pKey1 & 0x3F]; |
| 66474 | 66682 | int serial_type = ((const u8*)pKey1)[1]; |
| 66475 | 66683 | int res; |
| 66476 | 66684 | u32 y; |
| 66477 | 66685 | u64 x; |
| 66478 | 66686 | i64 v = pPKey2->aMem[0].u.i; |
| 66479 | 66687 | i64 lhs; |
| 66480 | | - UNUSED_PARAMETER(bSkip); |
| 66481 | 66688 | |
| 66482 | | - assert( bSkip==0 ); |
| 66483 | 66689 | assert( (*(u8*)pKey1)<=0x3F || CORRUPT_DB ); |
| 66484 | 66690 | switch( serial_type ){ |
| 66485 | 66691 | case 1: { /* 1-byte signed integer */ |
| 66486 | 66692 | lhs = ONE_BYTE_INT(aKey); |
| 66487 | 66693 | testcase( lhs<0 ); |
| | @@ -66527,24 +66733,24 @@ |
| 66527 | 66733 | ** statement (since the range of switch targets now starts at zero and |
| 66528 | 66734 | ** is contiguous) but does not cause any duplicate code to be generated |
| 66529 | 66735 | ** (as gcc is clever enough to combine the two like cases). Other |
| 66530 | 66736 | ** compilers might be similar. */ |
| 66531 | 66737 | case 0: case 7: |
| 66532 | | - return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0); |
| 66738 | + return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2); |
| 66533 | 66739 | |
| 66534 | 66740 | default: |
| 66535 | | - return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0); |
| 66741 | + return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2); |
| 66536 | 66742 | } |
| 66537 | 66743 | |
| 66538 | 66744 | if( v>lhs ){ |
| 66539 | 66745 | res = pPKey2->r1; |
| 66540 | 66746 | }else if( v<lhs ){ |
| 66541 | 66747 | res = pPKey2->r2; |
| 66542 | 66748 | }else if( pPKey2->nField>1 ){ |
| 66543 | 66749 | /* The first fields of the two keys are equal. Compare the trailing |
| 66544 | 66750 | ** fields. */ |
| 66545 | | - res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1); |
| 66751 | + res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 66546 | 66752 | }else{ |
| 66547 | 66753 | /* The first fields of the two keys are equal and there are no trailing |
| 66548 | 66754 | ** fields. Return pPKey2->default_rc in this case. */ |
| 66549 | 66755 | res = pPKey2->default_rc; |
| 66550 | 66756 | } |
| | @@ -66559,21 +66765,17 @@ |
| 66559 | 66765 | ** uses the collation sequence BINARY and (c) that the size-of-header varint |
| 66560 | 66766 | ** at the start of (pKey1/nKey1) fits in a single byte. |
| 66561 | 66767 | */ |
| 66562 | 66768 | static int vdbeRecordCompareString( |
| 66563 | 66769 | int nKey1, const void *pKey1, /* Left key */ |
| 66564 | | - UnpackedRecord *pPKey2, /* Right key */ |
| 66565 | | - int bSkip |
| 66770 | + UnpackedRecord *pPKey2 /* Right key */ |
| 66566 | 66771 | ){ |
| 66567 | 66772 | const u8 *aKey1 = (const u8*)pKey1; |
| 66568 | 66773 | int serial_type; |
| 66569 | 66774 | int res; |
| 66570 | | - UNUSED_PARAMETER(bSkip); |
| 66571 | 66775 | |
| 66572 | | - assert( bSkip==0 ); |
| 66573 | 66776 | getVarint32(&aKey1[1], serial_type); |
| 66574 | | - |
| 66575 | 66777 | if( serial_type<12 ){ |
| 66576 | 66778 | res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */ |
| 66577 | 66779 | }else if( !(serial_type & 0x01) ){ |
| 66578 | 66780 | res = pPKey2->r2; /* (pKey1/nKey1) is a blob */ |
| 66579 | 66781 | }else{ |
| | @@ -66591,11 +66793,11 @@ |
| 66591 | 66793 | |
| 66592 | 66794 | if( res==0 ){ |
| 66593 | 66795 | res = nStr - pPKey2->aMem[0].n; |
| 66594 | 66796 | if( res==0 ){ |
| 66595 | 66797 | if( pPKey2->nField>1 ){ |
| 66596 | | - res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1); |
| 66798 | + res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 66597 | 66799 | }else{ |
| 66598 | 66800 | res = pPKey2->default_rc; |
| 66599 | 66801 | } |
| 66600 | 66802 | }else if( res>0 ){ |
| 66601 | 66803 | res = pPKey2->r2; |
| | @@ -66673,12 +66875,10 @@ |
| 66673 | 66875 | u32 szHdr; /* Size of the header */ |
| 66674 | 66876 | u32 typeRowid; /* Serial type of the rowid */ |
| 66675 | 66877 | u32 lenRowid; /* Size of the rowid */ |
| 66676 | 66878 | Mem m, v; |
| 66677 | 66879 | |
| 66678 | | - UNUSED_PARAMETER(db); |
| 66679 | | - |
| 66680 | 66880 | /* Get the size of the index entry. Only indices entries of less |
| 66681 | 66881 | ** than 2GiB are support - anything large must be database corruption. |
| 66682 | 66882 | ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so |
| 66683 | 66883 | ** this code can safely assume that nCellKey is 32-bits |
| 66684 | 66884 | */ |
| | @@ -66686,11 +66886,11 @@ |
| 66686 | 66886 | VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey); |
| 66687 | 66887 | assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */ |
| 66688 | 66888 | assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey ); |
| 66689 | 66889 | |
| 66690 | 66890 | /* Read in the complete content of the index entry */ |
| 66691 | | - memset(&m, 0, sizeof(m)); |
| 66891 | + sqlite3VdbeMemInit(&m, db, 0); |
| 66692 | 66892 | rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m); |
| 66693 | 66893 | if( rc ){ |
| 66694 | 66894 | return rc; |
| 66695 | 66895 | } |
| 66696 | 66896 | |
| | @@ -66729,11 +66929,11 @@ |
| 66729 | 66929 | return SQLITE_OK; |
| 66730 | 66930 | |
| 66731 | 66931 | /* Jump here if database corruption is detected after m has been |
| 66732 | 66932 | ** allocated. Free the m object and return SQLITE_CORRUPT. */ |
| 66733 | 66933 | idx_rowid_corruption: |
| 66734 | | - testcase( m.zMalloc!=0 ); |
| 66934 | + testcase( m.szMalloc!=0 ); |
| 66735 | 66935 | sqlite3VdbeMemRelease(&m); |
| 66736 | 66936 | return SQLITE_CORRUPT_BKPT; |
| 66737 | 66937 | } |
| 66738 | 66938 | |
| 66739 | 66939 | /* |
| | @@ -66746,10 +66946,11 @@ |
| 66746 | 66946 | ** omits the rowid at the end. The rowid at the end of the index entry |
| 66747 | 66947 | ** is ignored as well. Hence, this routine only compares the prefixes |
| 66748 | 66948 | ** of the keys prior to the final rowid, not the entire key. |
| 66749 | 66949 | */ |
| 66750 | 66950 | SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare( |
| 66951 | + sqlite3 *db, /* Database connection */ |
| 66751 | 66952 | VdbeCursor *pC, /* The cursor to compare against */ |
| 66752 | 66953 | UnpackedRecord *pUnpacked, /* Unpacked version of key */ |
| 66753 | 66954 | int *res /* Write the comparison result here */ |
| 66754 | 66955 | ){ |
| 66755 | 66956 | i64 nCellKey = 0; |
| | @@ -66764,16 +66965,16 @@ |
| 66764 | 66965 | ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */ |
| 66765 | 66966 | if( nCellKey<=0 || nCellKey>0x7fffffff ){ |
| 66766 | 66967 | *res = 0; |
| 66767 | 66968 | return SQLITE_CORRUPT_BKPT; |
| 66768 | 66969 | } |
| 66769 | | - memset(&m, 0, sizeof(m)); |
| 66970 | + sqlite3VdbeMemInit(&m, db, 0); |
| 66770 | 66971 | rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m); |
| 66771 | 66972 | if( rc ){ |
| 66772 | 66973 | return rc; |
| 66773 | 66974 | } |
| 66774 | | - *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked, 0); |
| 66975 | + *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked); |
| 66775 | 66976 | sqlite3VdbeMemRelease(&m); |
| 66776 | 66977 | return SQLITE_OK; |
| 66777 | 66978 | } |
| 66778 | 66979 | |
| 66779 | 66980 | /* |
| | @@ -67083,13 +67284,16 @@ |
| 67083 | 67284 | |
| 67084 | 67285 | /**************************** sqlite3_result_ ******************************* |
| 67085 | 67286 | ** The following routines are used by user-defined functions to specify |
| 67086 | 67287 | ** the function result. |
| 67087 | 67288 | ** |
| 67088 | | -** The setStrOrError() funtion calls sqlite3VdbeMemSetStr() to store the |
| 67289 | +** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the |
| 67089 | 67290 | ** result as a string or blob but if the string or blob is too large, it |
| 67090 | 67291 | ** then sets the error code to SQLITE_TOOBIG |
| 67292 | +** |
| 67293 | +** The invokeValueDestructor(P,X) routine invokes destructor function X() |
| 67294 | +** on value P is not going to be used and need to be destroyed. |
| 67091 | 67295 | */ |
| 67092 | 67296 | static void setResultStrOrError( |
| 67093 | 67297 | sqlite3_context *pCtx, /* Function context */ |
| 67094 | 67298 | const char *z, /* String pointer */ |
| 67095 | 67299 | int n, /* Bytes in string, or negative */ |
| | @@ -67097,10 +67301,26 @@ |
| 67097 | 67301 | void (*xDel)(void*) /* Destructor function */ |
| 67098 | 67302 | ){ |
| 67099 | 67303 | if( sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel)==SQLITE_TOOBIG ){ |
| 67100 | 67304 | sqlite3_result_error_toobig(pCtx); |
| 67101 | 67305 | } |
| 67306 | +} |
| 67307 | +static int invokeValueDestructor( |
| 67308 | + const void *p, /* Value to destroy */ |
| 67309 | + void (*xDel)(void*), /* The destructor */ |
| 67310 | + sqlite3_context *pCtx /* Set a SQLITE_TOOBIG error if no NULL */ |
| 67311 | +){ |
| 67312 | + assert( xDel!=SQLITE_DYNAMIC ); |
| 67313 | + if( xDel==0 ){ |
| 67314 | + /* noop */ |
| 67315 | + }else if( xDel==SQLITE_TRANSIENT ){ |
| 67316 | + /* noop */ |
| 67317 | + }else{ |
| 67318 | + xDel((void*)p); |
| 67319 | + } |
| 67320 | + if( pCtx ) sqlite3_result_error_toobig(pCtx); |
| 67321 | + return SQLITE_TOOBIG; |
| 67102 | 67322 | } |
| 67103 | 67323 | SQLITE_API void sqlite3_result_blob( |
| 67104 | 67324 | sqlite3_context *pCtx, |
| 67105 | 67325 | const void *z, |
| 67106 | 67326 | int n, |
| | @@ -67107,10 +67327,24 @@ |
| 67107 | 67327 | void (*xDel)(void *) |
| 67108 | 67328 | ){ |
| 67109 | 67329 | assert( n>=0 ); |
| 67110 | 67330 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 67111 | 67331 | setResultStrOrError(pCtx, z, n, 0, xDel); |
| 67332 | +} |
| 67333 | +SQLITE_API void sqlite3_result_blob64( |
| 67334 | + sqlite3_context *pCtx, |
| 67335 | + const void *z, |
| 67336 | + sqlite3_uint64 n, |
| 67337 | + void (*xDel)(void *) |
| 67338 | +){ |
| 67339 | + assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 67340 | + assert( xDel!=SQLITE_DYNAMIC ); |
| 67341 | + if( n>0x7fffffff ){ |
| 67342 | + (void)invokeValueDestructor(z, xDel, pCtx); |
| 67343 | + }else{ |
| 67344 | + setResultStrOrError(pCtx, z, (int)n, 0, xDel); |
| 67345 | + } |
| 67112 | 67346 | } |
| 67113 | 67347 | SQLITE_API void sqlite3_result_double(sqlite3_context *pCtx, double rVal){ |
| 67114 | 67348 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 67115 | 67349 | sqlite3VdbeMemSetDouble(pCtx->pOut, rVal); |
| 67116 | 67350 | } |
| | @@ -67146,10 +67380,25 @@ |
| 67146 | 67380 | int n, |
| 67147 | 67381 | void (*xDel)(void *) |
| 67148 | 67382 | ){ |
| 67149 | 67383 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 67150 | 67384 | setResultStrOrError(pCtx, z, n, SQLITE_UTF8, xDel); |
| 67385 | +} |
| 67386 | +SQLITE_API void sqlite3_result_text64( |
| 67387 | + sqlite3_context *pCtx, |
| 67388 | + const char *z, |
| 67389 | + sqlite3_uint64 n, |
| 67390 | + void (*xDel)(void *), |
| 67391 | + unsigned char enc |
| 67392 | +){ |
| 67393 | + assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 67394 | + assert( xDel!=SQLITE_DYNAMIC ); |
| 67395 | + if( n>0x7fffffff ){ |
| 67396 | + (void)invokeValueDestructor(z, xDel, pCtx); |
| 67397 | + }else{ |
| 67398 | + setResultStrOrError(pCtx, z, (int)n, enc, xDel); |
| 67399 | + } |
| 67151 | 67400 | } |
| 67152 | 67401 | #ifndef SQLITE_OMIT_UTF16 |
| 67153 | 67402 | SQLITE_API void sqlite3_result_text16( |
| 67154 | 67403 | sqlite3_context *pCtx, |
| 67155 | 67404 | const void *z, |
| | @@ -67485,15 +67734,14 @@ |
| 67485 | 67734 | */ |
| 67486 | 67735 | static SQLITE_NOINLINE void *createAggContext(sqlite3_context *p, int nByte){ |
| 67487 | 67736 | Mem *pMem = p->pMem; |
| 67488 | 67737 | assert( (pMem->flags & MEM_Agg)==0 ); |
| 67489 | 67738 | if( nByte<=0 ){ |
| 67490 | | - sqlite3VdbeMemReleaseExternal(pMem); |
| 67491 | | - pMem->flags = MEM_Null; |
| 67739 | + sqlite3VdbeMemSetNull(pMem); |
| 67492 | 67740 | pMem->z = 0; |
| 67493 | 67741 | }else{ |
| 67494 | | - sqlite3VdbeMemGrow(pMem, nByte, 0); |
| 67742 | + sqlite3VdbeMemClearAndResize(pMem, nByte); |
| 67495 | 67743 | pMem->flags = MEM_Agg; |
| 67496 | 67744 | pMem->u.pDef = p->pFunc; |
| 67497 | 67745 | if( pMem->z ){ |
| 67498 | 67746 | memset(pMem->z, 0, nByte); |
| 67499 | 67747 | } |
| | @@ -67516,11 +67764,11 @@ |
| 67516 | 67764 | return (void*)p->pMem->z; |
| 67517 | 67765 | } |
| 67518 | 67766 | } |
| 67519 | 67767 | |
| 67520 | 67768 | /* |
| 67521 | | -** Return the auxilary data pointer, if any, for the iArg'th argument to |
| 67769 | +** Return the auxiliary data pointer, if any, for the iArg'th argument to |
| 67522 | 67770 | ** the user-function defined by pCtx. |
| 67523 | 67771 | */ |
| 67524 | 67772 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){ |
| 67525 | 67773 | AuxData *pAuxData; |
| 67526 | 67774 | |
| | @@ -67531,11 +67779,11 @@ |
| 67531 | 67779 | |
| 67532 | 67780 | return (pAuxData ? pAuxData->pAux : 0); |
| 67533 | 67781 | } |
| 67534 | 67782 | |
| 67535 | 67783 | /* |
| 67536 | | -** Set the auxilary data pointer and delete function, for the iArg'th |
| 67784 | +** Set the auxiliary data pointer and delete function, for the iArg'th |
| 67537 | 67785 | ** argument to the user-function defined by pCtx. Any previous value is |
| 67538 | 67786 | ** deleted by calling the delete function specified when it was set. |
| 67539 | 67787 | */ |
| 67540 | 67788 | SQLITE_API void sqlite3_set_auxdata( |
| 67541 | 67789 | sqlite3_context *pCtx, |
| | @@ -67577,11 +67825,11 @@ |
| 67577 | 67825 | } |
| 67578 | 67826 | } |
| 67579 | 67827 | |
| 67580 | 67828 | #ifndef SQLITE_OMIT_DEPRECATED |
| 67581 | 67829 | /* |
| 67582 | | -** Return the number of times the Step function of a aggregate has been |
| 67830 | +** Return the number of times the Step function of an aggregate has been |
| 67583 | 67831 | ** called. |
| 67584 | 67832 | ** |
| 67585 | 67833 | ** This function is deprecated. Do not use it for new code. It is |
| 67586 | 67834 | ** provide only to avoid breaking legacy code. New aggregate function |
| 67587 | 67835 | ** implementations should keep their own counts within their aggregate |
| | @@ -67626,15 +67874,26 @@ |
| 67626 | 67874 | ** __attribute__((aligned(8))) macro. */ |
| 67627 | 67875 | static const Mem nullMem |
| 67628 | 67876 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 67629 | 67877 | __attribute__((aligned(8))) |
| 67630 | 67878 | #endif |
| 67631 | | - = {0, "", (double)0, {0}, 0, MEM_Null, 0, |
| 67879 | + = { |
| 67880 | + /* .u = */ {0}, |
| 67881 | + /* .flags = */ MEM_Null, |
| 67882 | + /* .enc = */ 0, |
| 67883 | + /* .n = */ 0, |
| 67884 | + /* .z = */ 0, |
| 67885 | + /* .zMalloc = */ 0, |
| 67886 | + /* .szMalloc = */ 0, |
| 67887 | + /* .iPadding1 = */ 0, |
| 67888 | + /* .db = */ 0, |
| 67889 | + /* .xDel = */ 0, |
| 67632 | 67890 | #ifdef SQLITE_DEBUG |
| 67633 | | - 0, 0, /* pScopyFrom, pFiller */ |
| 67891 | + /* .pScopyFrom = */ 0, |
| 67892 | + /* .pFiller = */ 0, |
| 67634 | 67893 | #endif |
| 67635 | | - 0, 0 }; |
| 67894 | + }; |
| 67636 | 67895 | return &nullMem; |
| 67637 | 67896 | } |
| 67638 | 67897 | |
| 67639 | 67898 | /* |
| 67640 | 67899 | ** Check to see if column iCol of the given statement is valid. If |
| | @@ -67847,11 +68106,11 @@ |
| 67847 | 68106 | |
| 67848 | 68107 | #ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 67849 | 68108 | /* |
| 67850 | 68109 | ** Return the name of the database from which a result column derives. |
| 67851 | 68110 | ** NULL is returned if the result column is an expression or constant or |
| 67852 | | -** anything else which is not an unabiguous reference to a database column. |
| 68111 | +** anything else which is not an unambiguous reference to a database column. |
| 67853 | 68112 | */ |
| 67854 | 68113 | SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){ |
| 67855 | 68114 | return columnName( |
| 67856 | 68115 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE); |
| 67857 | 68116 | } |
| | @@ -67863,11 +68122,11 @@ |
| 67863 | 68122 | #endif /* SQLITE_OMIT_UTF16 */ |
| 67864 | 68123 | |
| 67865 | 68124 | /* |
| 67866 | 68125 | ** Return the name of the table from which a result column derives. |
| 67867 | 68126 | ** NULL is returned if the result column is an expression or constant or |
| 67868 | | -** anything else which is not an unabiguous reference to a database column. |
| 68127 | +** anything else which is not an unambiguous reference to a database column. |
| 67869 | 68128 | */ |
| 67870 | 68129 | SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){ |
| 67871 | 68130 | return columnName( |
| 67872 | 68131 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE); |
| 67873 | 68132 | } |
| | @@ -67879,11 +68138,11 @@ |
| 67879 | 68138 | #endif /* SQLITE_OMIT_UTF16 */ |
| 67880 | 68139 | |
| 67881 | 68140 | /* |
| 67882 | 68141 | ** Return the name of the table column from which a result column derives. |
| 67883 | 68142 | ** NULL is returned if the result column is an expression or constant or |
| 67884 | | -** anything else which is not an unabiguous reference to a database column. |
| 68143 | +** anything else which is not an unambiguous reference to a database column. |
| 67885 | 68144 | */ |
| 67886 | 68145 | SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){ |
| 67887 | 68146 | return columnName( |
| 67888 | 68147 | pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN); |
| 67889 | 68148 | } |
| | @@ -67995,10 +68254,24 @@ |
| 67995 | 68254 | const void *zData, |
| 67996 | 68255 | int nData, |
| 67997 | 68256 | void (*xDel)(void*) |
| 67998 | 68257 | ){ |
| 67999 | 68258 | return bindText(pStmt, i, zData, nData, xDel, 0); |
| 68259 | +} |
| 68260 | +SQLITE_API int sqlite3_bind_blob64( |
| 68261 | + sqlite3_stmt *pStmt, |
| 68262 | + int i, |
| 68263 | + const void *zData, |
| 68264 | + sqlite3_uint64 nData, |
| 68265 | + void (*xDel)(void*) |
| 68266 | +){ |
| 68267 | + assert( xDel!=SQLITE_DYNAMIC ); |
| 68268 | + if( nData>0x7fffffff ){ |
| 68269 | + return invokeValueDestructor(zData, xDel, 0); |
| 68270 | + }else{ |
| 68271 | + return bindText(pStmt, i, zData, (int)nData, xDel, 0); |
| 68272 | + } |
| 68000 | 68273 | } |
| 68001 | 68274 | SQLITE_API int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){ |
| 68002 | 68275 | int rc; |
| 68003 | 68276 | Vdbe *p = (Vdbe *)pStmt; |
| 68004 | 68277 | rc = vdbeUnbind(p, i); |
| | @@ -68036,10 +68309,26 @@ |
| 68036 | 68309 | const char *zData, |
| 68037 | 68310 | int nData, |
| 68038 | 68311 | void (*xDel)(void*) |
| 68039 | 68312 | ){ |
| 68040 | 68313 | return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8); |
| 68314 | +} |
| 68315 | +SQLITE_API int sqlite3_bind_text64( |
| 68316 | + sqlite3_stmt *pStmt, |
| 68317 | + int i, |
| 68318 | + const char *zData, |
| 68319 | + sqlite3_uint64 nData, |
| 68320 | + void (*xDel)(void*), |
| 68321 | + unsigned char enc |
| 68322 | +){ |
| 68323 | + assert( xDel!=SQLITE_DYNAMIC ); |
| 68324 | + if( nData>0x7fffffff ){ |
| 68325 | + return invokeValueDestructor(zData, xDel, 0); |
| 68326 | + }else{ |
| 68327 | + if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE; |
| 68328 | + return bindText(pStmt, i, zData, (int)nData, xDel, enc); |
| 68329 | + } |
| 68041 | 68330 | } |
| 68042 | 68331 | #ifndef SQLITE_OMIT_UTF16 |
| 68043 | 68332 | SQLITE_API int sqlite3_bind_text16( |
| 68044 | 68333 | sqlite3_stmt *pStmt, |
| 68045 | 68334 | int i, |
| | @@ -68056,11 +68345,11 @@ |
| 68056 | 68345 | case SQLITE_INTEGER: { |
| 68057 | 68346 | rc = sqlite3_bind_int64(pStmt, i, pValue->u.i); |
| 68058 | 68347 | break; |
| 68059 | 68348 | } |
| 68060 | 68349 | case SQLITE_FLOAT: { |
| 68061 | | - rc = sqlite3_bind_double(pStmt, i, pValue->r); |
| 68350 | + rc = sqlite3_bind_double(pStmt, i, pValue->u.r); |
| 68062 | 68351 | break; |
| 68063 | 68352 | } |
| 68064 | 68353 | case SQLITE_BLOB: { |
| 68065 | 68354 | if( pValue->flags & MEM_Zero ){ |
| 68066 | 68355 | rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero); |
| | @@ -68159,11 +68448,11 @@ |
| 68159 | 68448 | #ifndef SQLITE_OMIT_DEPRECATED |
| 68160 | 68449 | /* |
| 68161 | 68450 | ** Deprecated external interface. Internal/core SQLite code |
| 68162 | 68451 | ** should call sqlite3TransferBindings. |
| 68163 | 68452 | ** |
| 68164 | | -** Is is misuse to call this routine with statements from different |
| 68453 | +** It is misuse to call this routine with statements from different |
| 68165 | 68454 | ** database connections. But as this is a deprecated interface, we |
| 68166 | 68455 | ** will not bother to check for that condition. |
| 68167 | 68456 | ** |
| 68168 | 68457 | ** If the two statements contain a different number of bindings, then |
| 68169 | 68458 | ** an SQLITE_ERROR is returned. Nothing else can go wrong, so otherwise |
| | @@ -68303,11 +68592,11 @@ |
| 68303 | 68592 | ** is eventually freed. |
| 68304 | 68593 | ** |
| 68305 | 68594 | ** ALGORITHM: Scan the input string looking for host parameters in any of |
| 68306 | 68595 | ** these forms: ?, ?N, $A, @A, :A. Take care to avoid text within |
| 68307 | 68596 | ** string literals, quoted identifier names, and comments. For text forms, |
| 68308 | | -** the host parameter index is found by scanning the perpared |
| 68597 | +** the host parameter index is found by scanning the prepared |
| 68309 | 68598 | ** statement for the corresponding OP_Variable opcode. Once the host |
| 68310 | 68599 | ** parameter index is known, locate the value in p->aVar[]. Then render |
| 68311 | 68600 | ** the value as a literal in place of the host parameter name. |
| 68312 | 68601 | */ |
| 68313 | 68602 | SQLITE_PRIVATE char *sqlite3VdbeExpandSql( |
| | @@ -68366,11 +68655,11 @@ |
| 68366 | 68655 | if( pVar->flags & MEM_Null ){ |
| 68367 | 68656 | sqlite3StrAccumAppend(&out, "NULL", 4); |
| 68368 | 68657 | }else if( pVar->flags & MEM_Int ){ |
| 68369 | 68658 | sqlite3XPrintf(&out, 0, "%lld", pVar->u.i); |
| 68370 | 68659 | }else if( pVar->flags & MEM_Real ){ |
| 68371 | | - sqlite3XPrintf(&out, 0, "%!.15g", pVar->r); |
| 68660 | + sqlite3XPrintf(&out, 0, "%!.15g", pVar->u.r); |
| 68372 | 68661 | }else if( pVar->flags & MEM_Str ){ |
| 68373 | 68662 | int nOut; /* Number of bytes of the string text to include in output */ |
| 68374 | 68663 | #ifndef SQLITE_OMIT_UTF16 |
| 68375 | 68664 | u8 enc = ENC(db); |
| 68376 | 68665 | Mem utf8; |
| | @@ -68749,11 +69038,11 @@ |
| 68749 | 69038 | assert( iCur<p->nCursor ); |
| 68750 | 69039 | if( p->apCsr[iCur] ){ |
| 68751 | 69040 | sqlite3VdbeFreeCursor(p, p->apCsr[iCur]); |
| 68752 | 69041 | p->apCsr[iCur] = 0; |
| 68753 | 69042 | } |
| 68754 | | - if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){ |
| 69043 | + if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){ |
| 68755 | 69044 | p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z; |
| 68756 | 69045 | memset(pCx, 0, sizeof(VdbeCursor)); |
| 68757 | 69046 | pCx->iDb = iDb; |
| 68758 | 69047 | pCx->nField = nField; |
| 68759 | 69048 | if( isBtreeCursor ){ |
| | @@ -68782,17 +69071,17 @@ |
| 68782 | 69071 | */ |
| 68783 | 69072 | static void applyNumericAffinity(Mem *pRec, int bTryForInt){ |
| 68784 | 69073 | double rValue; |
| 68785 | 69074 | i64 iValue; |
| 68786 | 69075 | u8 enc = pRec->enc; |
| 68787 | | - if( (pRec->flags&MEM_Str)==0 ) return; |
| 69076 | + assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real))==MEM_Str ); |
| 68788 | 69077 | if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return; |
| 68789 | 69078 | if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){ |
| 68790 | 69079 | pRec->u.i = iValue; |
| 68791 | 69080 | pRec->flags |= MEM_Int; |
| 68792 | 69081 | }else{ |
| 68793 | | - pRec->r = rValue; |
| 69082 | + pRec->u.r = rValue; |
| 68794 | 69083 | pRec->flags |= MEM_Real; |
| 68795 | 69084 | if( bTryForInt ) sqlite3VdbeIntegerAffinity(pRec); |
| 68796 | 69085 | } |
| 68797 | 69086 | } |
| 68798 | 69087 | |
| | @@ -68817,28 +69106,28 @@ |
| 68817 | 69106 | static void applyAffinity( |
| 68818 | 69107 | Mem *pRec, /* The value to apply affinity to */ |
| 68819 | 69108 | char affinity, /* The affinity to be applied */ |
| 68820 | 69109 | u8 enc /* Use this text encoding */ |
| 68821 | 69110 | ){ |
| 68822 | | - if( affinity==SQLITE_AFF_TEXT ){ |
| 69111 | + if( affinity>=SQLITE_AFF_NUMERIC ){ |
| 69112 | + assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL |
| 69113 | + || affinity==SQLITE_AFF_NUMERIC ); |
| 69114 | + if( (pRec->flags & MEM_Int)==0 ){ |
| 69115 | + if( (pRec->flags & MEM_Real)==0 ){ |
| 69116 | + if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1); |
| 69117 | + }else{ |
| 69118 | + sqlite3VdbeIntegerAffinity(pRec); |
| 69119 | + } |
| 69120 | + } |
| 69121 | + }else if( affinity==SQLITE_AFF_TEXT ){ |
| 68823 | 69122 | /* Only attempt the conversion to TEXT if there is an integer or real |
| 68824 | 69123 | ** representation (blob and NULL do not get converted) but no string |
| 68825 | 69124 | ** representation. |
| 68826 | 69125 | */ |
| 68827 | 69126 | if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){ |
| 68828 | 69127 | sqlite3VdbeMemStringify(pRec, enc, 1); |
| 68829 | 69128 | } |
| 68830 | | - }else if( affinity!=SQLITE_AFF_NONE ){ |
| 68831 | | - assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL |
| 68832 | | - || affinity==SQLITE_AFF_NUMERIC ); |
| 68833 | | - if( (pRec->flags & MEM_Int)==0 ){ |
| 68834 | | - if( (pRec->flags & MEM_Real)==0 ){ |
| 68835 | | - applyNumericAffinity(pRec,1); |
| 68836 | | - }else{ |
| 68837 | | - sqlite3VdbeIntegerAffinity(pRec); |
| 68838 | | - } |
| 68839 | | - } |
| 68840 | 69129 | } |
| 68841 | 69130 | } |
| 68842 | 69131 | |
| 68843 | 69132 | /* |
| 68844 | 69133 | ** Try to convert the type of a function argument or a result column |
| | @@ -68869,17 +69158,17 @@ |
| 68869 | 69158 | } |
| 68870 | 69159 | |
| 68871 | 69160 | /* |
| 68872 | 69161 | ** pMem currently only holds a string type (or maybe a BLOB that we can |
| 68873 | 69162 | ** interpret as a string if we want to). Compute its corresponding |
| 68874 | | -** numeric type, if has one. Set the pMem->r and pMem->u.i fields |
| 69163 | +** numeric type, if has one. Set the pMem->u.r and pMem->u.i fields |
| 68875 | 69164 | ** accordingly. |
| 68876 | 69165 | */ |
| 68877 | 69166 | static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){ |
| 68878 | 69167 | assert( (pMem->flags & (MEM_Int|MEM_Real))==0 ); |
| 68879 | 69168 | assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 ); |
| 68880 | | - if( sqlite3AtoF(pMem->z, &pMem->r, pMem->n, pMem->enc)==0 ){ |
| 69169 | + if( sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc)==0 ){ |
| 68881 | 69170 | return 0; |
| 68882 | 69171 | } |
| 68883 | 69172 | if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==SQLITE_OK ){ |
| 68884 | 69173 | return MEM_Int; |
| 68885 | 69174 | } |
| | @@ -68889,11 +69178,11 @@ |
| 68889 | 69178 | /* |
| 68890 | 69179 | ** Return the numeric type for pMem, either MEM_Int or MEM_Real or both or |
| 68891 | 69180 | ** none. |
| 68892 | 69181 | ** |
| 68893 | 69182 | ** Unlike applyNumericAffinity(), this routine does not modify pMem->flags. |
| 68894 | | -** But it does set pMem->r and pMem->u.i appropriately. |
| 69183 | +** But it does set pMem->u.r and pMem->u.i appropriately. |
| 68895 | 69184 | */ |
| 68896 | 69185 | static u16 numericType(Mem *pMem){ |
| 68897 | 69186 | if( pMem->flags & (MEM_Int|MEM_Real) ){ |
| 68898 | 69187 | return pMem->flags & (MEM_Int|MEM_Real); |
| 68899 | 69188 | } |
| | @@ -68999,11 +69288,11 @@ |
| 68999 | 69288 | printf(" si:%lld", p->u.i); |
| 69000 | 69289 | }else if( p->flags & MEM_Int ){ |
| 69001 | 69290 | printf(" i:%lld", p->u.i); |
| 69002 | 69291 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 69003 | 69292 | }else if( p->flags & MEM_Real ){ |
| 69004 | | - printf(" r:%g", p->r); |
| 69293 | + printf(" r:%g", p->u.r); |
| 69005 | 69294 | #endif |
| 69006 | 69295 | }else if( p->flags & MEM_RowSet ){ |
| 69007 | 69296 | printf(" (rowset)"); |
| 69008 | 69297 | }else{ |
| 69009 | 69298 | char zBuf[200]; |
| | @@ -69269,11 +69558,11 @@ |
| 69269 | 69558 | if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){ |
| 69270 | 69559 | assert( pOp->p2>0 ); |
| 69271 | 69560 | assert( pOp->p2<=(p->nMem-p->nCursor) ); |
| 69272 | 69561 | pOut = &aMem[pOp->p2]; |
| 69273 | 69562 | memAboutToChange(p, pOut); |
| 69274 | | - VdbeMemReleaseExtern(pOut); |
| 69563 | + if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut); |
| 69275 | 69564 | pOut->flags = MEM_Int; |
| 69276 | 69565 | } |
| 69277 | 69566 | |
| 69278 | 69567 | /* Sanity checking on other operands */ |
| 69279 | 69568 | #ifdef SQLITE_DEBUG |
| | @@ -69631,11 +69920,11 @@ |
| 69631 | 69920 | ** Write that value into register P2. |
| 69632 | 69921 | */ |
| 69633 | 69922 | case OP_Real: { /* same as TK_FLOAT, out2-prerelease */ |
| 69634 | 69923 | pOut->flags = MEM_Real; |
| 69635 | 69924 | assert( !sqlite3IsNaN(*pOp->p4.pReal) ); |
| 69636 | | - pOut->r = *pOp->p4.pReal; |
| 69925 | + pOut->u.r = *pOp->p4.pReal; |
| 69637 | 69926 | break; |
| 69638 | 69927 | } |
| 69639 | 69928 | #endif |
| 69640 | 69929 | |
| 69641 | 69930 | /* Opcode: String8 * P2 * P4 * |
| | @@ -69654,13 +69943,13 @@ |
| 69654 | 69943 | #ifndef SQLITE_OMIT_UTF16 |
| 69655 | 69944 | if( encoding!=SQLITE_UTF8 ){ |
| 69656 | 69945 | rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC); |
| 69657 | 69946 | if( rc==SQLITE_TOOBIG ) goto too_big; |
| 69658 | 69947 | if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem; |
| 69659 | | - assert( pOut->zMalloc==pOut->z ); |
| 69948 | + assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z ); |
| 69660 | 69949 | assert( VdbeMemDynamic(pOut)==0 ); |
| 69661 | | - pOut->zMalloc = 0; |
| 69950 | + pOut->szMalloc = 0; |
| 69662 | 69951 | pOut->flags |= MEM_Static; |
| 69663 | 69952 | if( pOp->p4type==P4_DYNAMIC ){ |
| 69664 | 69953 | sqlite3DbFree(db, pOp->p4.z); |
| 69665 | 69954 | } |
| 69666 | 69955 | pOp->p4type = P4_DYNAMIC; |
| | @@ -69708,11 +69997,11 @@ |
| 69708 | 69997 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 69709 | 69998 | pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; |
| 69710 | 69999 | while( cnt>0 ){ |
| 69711 | 70000 | pOut++; |
| 69712 | 70001 | memAboutToChange(p, pOut); |
| 69713 | | - VdbeMemReleaseExtern(pOut); |
| 70002 | + sqlite3VdbeMemSetNull(pOut); |
| 69714 | 70003 | pOut->flags = nullFlag; |
| 69715 | 70004 | cnt--; |
| 69716 | 70005 | } |
| 69717 | 70006 | break; |
| 69718 | 70007 | } |
| | @@ -69776,11 +70065,10 @@ |
| 69776 | 70065 | ** left holding a NULL. It is an error for register ranges |
| 69777 | 70066 | ** P1..P1+P3-1 and P2..P2+P3-1 to overlap. It is an error |
| 69778 | 70067 | ** for P3 to be less than 1. |
| 69779 | 70068 | */ |
| 69780 | 70069 | case OP_Move: { |
| 69781 | | - char *zMalloc; /* Holding variable for allocated memory */ |
| 69782 | 70070 | int n; /* Number of registers left to copy */ |
| 69783 | 70071 | int p1; /* Register to copy from */ |
| 69784 | 70072 | int p2; /* Register to copy to */ |
| 69785 | 70073 | |
| 69786 | 70074 | n = pOp->p3; |
| | @@ -69794,21 +70082,16 @@ |
| 69794 | 70082 | do{ |
| 69795 | 70083 | assert( pOut<=&aMem[(p->nMem-p->nCursor)] ); |
| 69796 | 70084 | assert( pIn1<=&aMem[(p->nMem-p->nCursor)] ); |
| 69797 | 70085 | assert( memIsValid(pIn1) ); |
| 69798 | 70086 | memAboutToChange(p, pOut); |
| 69799 | | - sqlite3VdbeMemRelease(pOut); |
| 69800 | | - zMalloc = pOut->zMalloc; |
| 69801 | | - memcpy(pOut, pIn1, sizeof(Mem)); |
| 70087 | + sqlite3VdbeMemMove(pOut, pIn1); |
| 69802 | 70088 | #ifdef SQLITE_DEBUG |
| 69803 | 70089 | if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){ |
| 69804 | 70090 | pOut->pScopyFrom += p1 - pOp->p2; |
| 69805 | 70091 | } |
| 69806 | 70092 | #endif |
| 69807 | | - pIn1->flags = MEM_Undefined; |
| 69808 | | - pIn1->xDel = 0; |
| 69809 | | - pIn1->zMalloc = zMalloc; |
| 69810 | 70093 | REGISTER_TRACE(p2++, pOut); |
| 69811 | 70094 | pIn1++; |
| 69812 | 70095 | pOut++; |
| 69813 | 70096 | }while( --n ); |
| 69814 | 70097 | break; |
| | @@ -70109,11 +70392,11 @@ |
| 70109 | 70392 | MemSetTypeFlag(pOut, MEM_Int); |
| 70110 | 70393 | #else |
| 70111 | 70394 | if( sqlite3IsNaN(rB) ){ |
| 70112 | 70395 | goto arithmetic_result_is_null; |
| 70113 | 70396 | } |
| 70114 | | - pOut->r = rB; |
| 70397 | + pOut->u.r = rB; |
| 70115 | 70398 | MemSetTypeFlag(pOut, MEM_Real); |
| 70116 | 70399 | if( ((type1|type2)&MEM_Real)==0 && !bIntint ){ |
| 70117 | 70400 | sqlite3VdbeIntegerAffinity(pOut); |
| 70118 | 70401 | } |
| 70119 | 70402 | #endif |
| | @@ -70384,11 +70667,11 @@ |
| 70384 | 70667 | ** </ul> |
| 70385 | 70668 | ** |
| 70386 | 70669 | ** A NULL value is not changed by this routine. It remains NULL. |
| 70387 | 70670 | */ |
| 70388 | 70671 | case OP_Cast: { /* in1 */ |
| 70389 | | - assert( pOp->p2>=SQLITE_AFF_TEXT && pOp->p2<=SQLITE_AFF_REAL ); |
| 70672 | + assert( pOp->p2>=SQLITE_AFF_NONE && pOp->p2<=SQLITE_AFF_REAL ); |
| 70390 | 70673 | testcase( pOp->p2==SQLITE_AFF_TEXT ); |
| 70391 | 70674 | testcase( pOp->p2==SQLITE_AFF_NONE ); |
| 70392 | 70675 | testcase( pOp->p2==SQLITE_AFF_NUMERIC ); |
| 70393 | 70676 | testcase( pOp->p2==SQLITE_AFF_INTEGER ); |
| 70394 | 70677 | testcase( pOp->p2==SQLITE_AFF_REAL ); |
| | @@ -70534,19 +70817,39 @@ |
| 70534 | 70817 | break; |
| 70535 | 70818 | } |
| 70536 | 70819 | }else{ |
| 70537 | 70820 | /* Neither operand is NULL. Do a comparison. */ |
| 70538 | 70821 | affinity = pOp->p5 & SQLITE_AFF_MASK; |
| 70539 | | - if( affinity ){ |
| 70540 | | - applyAffinity(pIn1, affinity, encoding); |
| 70541 | | - applyAffinity(pIn3, affinity, encoding); |
| 70542 | | - if( db->mallocFailed ) goto no_mem; |
| 70822 | + if( affinity>=SQLITE_AFF_NUMERIC ){ |
| 70823 | + if( (pIn1->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ |
| 70824 | + applyNumericAffinity(pIn1,0); |
| 70825 | + } |
| 70826 | + if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ |
| 70827 | + applyNumericAffinity(pIn3,0); |
| 70828 | + } |
| 70829 | + }else if( affinity==SQLITE_AFF_TEXT ){ |
| 70830 | + if( (pIn1->flags & MEM_Str)==0 && (pIn1->flags & (MEM_Int|MEM_Real))!=0 ){ |
| 70831 | + testcase( pIn1->flags & MEM_Int ); |
| 70832 | + testcase( pIn1->flags & MEM_Real ); |
| 70833 | + sqlite3VdbeMemStringify(pIn1, encoding, 1); |
| 70834 | + } |
| 70835 | + if( (pIn3->flags & MEM_Str)==0 && (pIn3->flags & (MEM_Int|MEM_Real))!=0 ){ |
| 70836 | + testcase( pIn3->flags & MEM_Int ); |
| 70837 | + testcase( pIn3->flags & MEM_Real ); |
| 70838 | + sqlite3VdbeMemStringify(pIn3, encoding, 1); |
| 70839 | + } |
| 70543 | 70840 | } |
| 70544 | | - |
| 70545 | 70841 | assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 ); |
| 70546 | | - ExpandBlob(pIn1); |
| 70547 | | - ExpandBlob(pIn3); |
| 70842 | + if( pIn1->flags & MEM_Zero ){ |
| 70843 | + sqlite3VdbeMemExpandBlob(pIn1); |
| 70844 | + flags1 &= ~MEM_Zero; |
| 70845 | + } |
| 70846 | + if( pIn3->flags & MEM_Zero ){ |
| 70847 | + sqlite3VdbeMemExpandBlob(pIn3); |
| 70848 | + flags3 &= ~MEM_Zero; |
| 70849 | + } |
| 70850 | + if( db->mallocFailed ) goto no_mem; |
| 70548 | 70851 | res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl); |
| 70549 | 70852 | } |
| 70550 | 70853 | switch( pOp->opcode ){ |
| 70551 | 70854 | case OP_Eq: res = res==0; break; |
| 70552 | 70855 | case OP_Ne: res = res!=0; break; |
| | @@ -70567,12 +70870,12 @@ |
| 70567 | 70870 | if( res ){ |
| 70568 | 70871 | pc = pOp->p2-1; |
| 70569 | 70872 | } |
| 70570 | 70873 | } |
| 70571 | 70874 | /* Undo any changes made by applyAffinity() to the input registers. */ |
| 70572 | | - pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask); |
| 70573 | | - pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask); |
| 70875 | + pIn1->flags = flags1; |
| 70876 | + pIn3->flags = flags3; |
| 70574 | 70877 | break; |
| 70575 | 70878 | } |
| 70576 | 70879 | |
| 70577 | 70880 | /* Opcode: Permutation * * * P4 * |
| 70578 | 70881 | ** |
| | @@ -70736,14 +71039,14 @@ |
| 70736 | 71039 | ** NULL, then a NULL is stored in P2. |
| 70737 | 71040 | */ |
| 70738 | 71041 | case OP_Not: { /* same as TK_NOT, in1, out2 */ |
| 70739 | 71042 | pIn1 = &aMem[pOp->p1]; |
| 70740 | 71043 | pOut = &aMem[pOp->p2]; |
| 70741 | | - if( pIn1->flags & MEM_Null ){ |
| 70742 | | - sqlite3VdbeMemSetNull(pOut); |
| 70743 | | - }else{ |
| 70744 | | - sqlite3VdbeMemSetInt64(pOut, !sqlite3VdbeIntValue(pIn1)); |
| 71044 | + sqlite3VdbeMemSetNull(pOut); |
| 71045 | + if( (pIn1->flags & MEM_Null)==0 ){ |
| 71046 | + pOut->flags = MEM_Int; |
| 71047 | + pOut->u.i = !sqlite3VdbeIntValue(pIn1); |
| 70745 | 71048 | } |
| 70746 | 71049 | break; |
| 70747 | 71050 | } |
| 70748 | 71051 | |
| 70749 | 71052 | /* Opcode: BitNot P1 P2 * * * |
| | @@ -70754,14 +71057,14 @@ |
| 70754 | 71057 | ** a NULL then store a NULL in P2. |
| 70755 | 71058 | */ |
| 70756 | 71059 | case OP_BitNot: { /* same as TK_BITNOT, in1, out2 */ |
| 70757 | 71060 | pIn1 = &aMem[pOp->p1]; |
| 70758 | 71061 | pOut = &aMem[pOp->p2]; |
| 70759 | | - if( pIn1->flags & MEM_Null ){ |
| 70760 | | - sqlite3VdbeMemSetNull(pOut); |
| 70761 | | - }else{ |
| 70762 | | - sqlite3VdbeMemSetInt64(pOut, ~sqlite3VdbeIntValue(pIn1)); |
| 71062 | + sqlite3VdbeMemSetNull(pOut); |
| 71063 | + if( (pIn1->flags & MEM_Null)==0 ){ |
| 71064 | + pOut->flags = MEM_Int; |
| 71065 | + pOut->u.i = ~sqlite3VdbeIntValue(pIn1); |
| 70763 | 71066 | } |
| 70764 | 71067 | break; |
| 70765 | 71068 | } |
| 70766 | 71069 | |
| 70767 | 71070 | /* Opcode: Once P1 P2 * * * |
| | @@ -70875,11 +71178,10 @@ |
| 70875 | 71178 | case OP_Column: { |
| 70876 | 71179 | i64 payloadSize64; /* Number of bytes in the record */ |
| 70877 | 71180 | int p2; /* column number to retrieve */ |
| 70878 | 71181 | VdbeCursor *pC; /* The VDBE cursor */ |
| 70879 | 71182 | BtCursor *pCrsr; /* The BTree cursor */ |
| 70880 | | - u32 *aType; /* aType[i] holds the numeric type of the i-th column */ |
| 70881 | 71183 | u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ |
| 70882 | 71184 | int len; /* The length of the serialized data for the column */ |
| 70883 | 71185 | int i; /* Loop counter */ |
| 70884 | 71186 | Mem *pDest; /* Where to write the extracted value */ |
| 70885 | 71187 | Mem sMem; /* For storing the record being decoded */ |
| | @@ -70888,10 +71190,11 @@ |
| 70888 | 71190 | const u8 *zEndHdr; /* Pointer to first byte after the header */ |
| 70889 | 71191 | u32 offset; /* Offset into the data */ |
| 70890 | 71192 | u32 szField; /* Number of bytes in the content of a field */ |
| 70891 | 71193 | u32 avail; /* Number of bytes of available data */ |
| 70892 | 71194 | u32 t; /* A type code from the record header */ |
| 71195 | + u16 fx; /* pDest->flags value */ |
| 70893 | 71196 | Mem *pReg; /* PseudoTable input register */ |
| 70894 | 71197 | |
| 70895 | 71198 | p2 = pOp->p2; |
| 70896 | 71199 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 70897 | 71200 | pDest = &aMem[pOp->p3]; |
| | @@ -70898,12 +71201,11 @@ |
| 70898 | 71201 | memAboutToChange(p, pDest); |
| 70899 | 71202 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70900 | 71203 | pC = p->apCsr[pOp->p1]; |
| 70901 | 71204 | assert( pC!=0 ); |
| 70902 | 71205 | assert( p2<pC->nField ); |
| 70903 | | - aType = pC->aType; |
| 70904 | | - aOffset = aType + pC->nField; |
| 71206 | + aOffset = pC->aType + pC->nField; |
| 70905 | 71207 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 70906 | 71208 | assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */ |
| 70907 | 71209 | #endif |
| 70908 | 71210 | pCrsr = pC->pCursor; |
| 70909 | 71211 | assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */ |
| | @@ -70980,11 +71282,11 @@ |
| 70980 | 71282 | goto op_column_error; |
| 70981 | 71283 | } |
| 70982 | 71284 | } |
| 70983 | 71285 | |
| 70984 | 71286 | /* Make sure at least the first p2+1 entries of the header have been |
| 70985 | | - ** parsed and valid information is in aOffset[] and aType[]. |
| 71287 | + ** parsed and valid information is in aOffset[] and pC->aType[]. |
| 70986 | 71288 | */ |
| 70987 | 71289 | if( pC->nHdrParsed<=p2 ){ |
| 70988 | 71290 | /* If there is more header available for parsing in the record, try |
| 70989 | 71291 | ** to extract additional fields up through the p2+1-th field |
| 70990 | 71292 | */ |
| | @@ -71000,11 +71302,11 @@ |
| 71000 | 71302 | zData = (u8*)sMem.z; |
| 71001 | 71303 | }else{ |
| 71002 | 71304 | zData = pC->aRow; |
| 71003 | 71305 | } |
| 71004 | 71306 | |
| 71005 | | - /* Fill in aType[i] and aOffset[i] values through the p2-th field. */ |
| 71307 | + /* Fill in pC->aType[i] and aOffset[i] values through the p2-th field. */ |
| 71006 | 71308 | i = pC->nHdrParsed; |
| 71007 | 71309 | offset = aOffset[i]; |
| 71008 | 71310 | zHdr = zData + pC->iHdrOffset; |
| 71009 | 71311 | zEndHdr = zData + aOffset[0]; |
| 71010 | 71312 | assert( i<=p2 && zHdr<zEndHdr ); |
| | @@ -71013,11 +71315,11 @@ |
| 71013 | 71315 | t = zHdr[0]; |
| 71014 | 71316 | zHdr++; |
| 71015 | 71317 | }else{ |
| 71016 | 71318 | zHdr += sqlite3GetVarint32(zHdr, &t); |
| 71017 | 71319 | } |
| 71018 | | - aType[i] = t; |
| 71320 | + pC->aType[i] = t; |
| 71019 | 71321 | szField = sqlite3VdbeSerialTypeLen(t); |
| 71020 | 71322 | offset += szField; |
| 71021 | 71323 | if( offset<szField ){ /* True if offset overflows */ |
| 71022 | 71324 | zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ |
| 71023 | 71325 | break; |
| | @@ -71060,65 +71362,65 @@ |
| 71060 | 71362 | goto op_column_out; |
| 71061 | 71363 | } |
| 71062 | 71364 | } |
| 71063 | 71365 | |
| 71064 | 71366 | /* Extract the content for the p2+1-th column. Control can only |
| 71065 | | - ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are |
| 71367 | + ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are |
| 71066 | 71368 | ** all valid. |
| 71067 | 71369 | */ |
| 71068 | 71370 | assert( p2<pC->nHdrParsed ); |
| 71069 | 71371 | assert( rc==SQLITE_OK ); |
| 71070 | 71372 | assert( sqlite3VdbeCheckMemInvariants(pDest) ); |
| 71373 | + if( VdbeMemDynamic(pDest) ) sqlite3VdbeMemSetNull(pDest); |
| 71374 | + t = pC->aType[p2]; |
| 71071 | 71375 | if( pC->szRow>=aOffset[p2+1] ){ |
| 71072 | 71376 | /* This is the common case where the desired content fits on the original |
| 71073 | 71377 | ** page - where the content is not on an overflow page */ |
| 71074 | | - VdbeMemReleaseExtern(pDest); |
| 71075 | | - sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest); |
| 71378 | + sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], t, pDest); |
| 71076 | 71379 | }else{ |
| 71077 | 71380 | /* This branch happens only when content is on overflow pages */ |
| 71078 | | - t = aType[p2]; |
| 71079 | 71381 | if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0 |
| 71080 | 71382 | && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)) |
| 71081 | 71383 | || (len = sqlite3VdbeSerialTypeLen(t))==0 |
| 71082 | 71384 | ){ |
| 71083 | | - /* Content is irrelevant for the typeof() function and for |
| 71084 | | - ** the length(X) function if X is a blob. So we might as well use |
| 71085 | | - ** bogus content rather than reading content from disk. NULL works |
| 71086 | | - ** for text and blob and whatever is in the payloadSize64 variable |
| 71087 | | - ** will work for everything else. Content is also irrelevant if |
| 71088 | | - ** the content length is 0. */ |
| 71089 | | - zData = t<=13 ? (u8*)&payloadSize64 : 0; |
| 71090 | | - sMem.zMalloc = 0; |
| 71385 | + /* Content is irrelevant for |
| 71386 | + ** 1. the typeof() function, |
| 71387 | + ** 2. the length(X) function if X is a blob, and |
| 71388 | + ** 3. if the content length is zero. |
| 71389 | + ** So we might as well use bogus content rather than reading |
| 71390 | + ** content from disk. NULL will work for the value for strings |
| 71391 | + ** and blobs and whatever is in the payloadSize64 variable |
| 71392 | + ** will work for everything else. */ |
| 71393 | + sqlite3VdbeSerialGet(t<=13 ? (u8*)&payloadSize64 : 0, t, pDest); |
| 71091 | 71394 | }else{ |
| 71092 | | - memset(&sMem, 0, sizeof(sMem)); |
| 71093 | | - sqlite3VdbeMemMove(&sMem, pDest); |
| 71094 | 71395 | rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable, |
| 71095 | | - &sMem); |
| 71396 | + pDest); |
| 71096 | 71397 | if( rc!=SQLITE_OK ){ |
| 71097 | 71398 | goto op_column_error; |
| 71098 | 71399 | } |
| 71099 | | - zData = (u8*)sMem.z; |
| 71100 | | - } |
| 71101 | | - sqlite3VdbeSerialGet(zData, t, pDest); |
| 71102 | | - /* If we dynamically allocated space to hold the data (in the |
| 71103 | | - ** sqlite3VdbeMemFromBtree() call above) then transfer control of that |
| 71104 | | - ** dynamically allocated space over to the pDest structure. |
| 71105 | | - ** This prevents a memory copy. */ |
| 71106 | | - if( sMem.zMalloc ){ |
| 71107 | | - assert( sMem.z==sMem.zMalloc ); |
| 71108 | | - assert( VdbeMemDynamic(pDest)==0 ); |
| 71109 | | - assert( (pDest->flags & (MEM_Blob|MEM_Str))==0 || pDest->z==sMem.z ); |
| 71110 | | - pDest->flags &= ~(MEM_Ephem|MEM_Static); |
| 71111 | | - pDest->flags |= MEM_Term; |
| 71112 | | - pDest->z = sMem.z; |
| 71113 | | - pDest->zMalloc = sMem.zMalloc; |
| 71400 | + sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest); |
| 71401 | + pDest->flags &= ~MEM_Ephem; |
| 71114 | 71402 | } |
| 71115 | 71403 | } |
| 71116 | 71404 | pDest->enc = encoding; |
| 71117 | 71405 | |
| 71118 | 71406 | op_column_out: |
| 71119 | | - Deephemeralize(pDest); |
| 71407 | + /* If the column value is an ephemeral string, go ahead and persist |
| 71408 | + ** that string in case the cursor moves before the column value is |
| 71409 | + ** used. The following code does the equivalent of Deephemeralize() |
| 71410 | + ** but does it faster. */ |
| 71411 | + if( (pDest->flags & MEM_Ephem)!=0 && pDest->z ){ |
| 71412 | + fx = pDest->flags & (MEM_Str|MEM_Blob); |
| 71413 | + assert( fx!=0 ); |
| 71414 | + zData = (const u8*)pDest->z; |
| 71415 | + len = pDest->n; |
| 71416 | + if( sqlite3VdbeMemClearAndResize(pDest, len+2) ) goto no_mem; |
| 71417 | + memcpy(pDest->z, zData, len); |
| 71418 | + pDest->z[len] = 0; |
| 71419 | + pDest->z[len+1] = 0; |
| 71420 | + pDest->flags = fx|MEM_Term; |
| 71421 | + } |
| 71120 | 71422 | op_column_error: |
| 71121 | 71423 | UPDATE_MAX_BLOBSIZE(pDest); |
| 71122 | 71424 | REGISTER_TRACE(pOp->p3, pDest); |
| 71123 | 71425 | break; |
| 71124 | 71426 | } |
| | @@ -71189,11 +71491,11 @@ |
| 71189 | 71491 | ** ------------------------------------------------------------------------ |
| 71190 | 71492 | ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | |
| 71191 | 71493 | ** ------------------------------------------------------------------------ |
| 71192 | 71494 | ** |
| 71193 | 71495 | ** Data(0) is taken from register P1. Data(1) comes from register P1+1 |
| 71194 | | - ** and so froth. |
| 71496 | + ** and so forth. |
| 71195 | 71497 | ** |
| 71196 | 71498 | ** Each type field is a varint representing the serial type of the |
| 71197 | 71499 | ** corresponding data element (see sqlite3VdbeSerialType()). The |
| 71198 | 71500 | ** hdr-size field is also a varint which is the offset from the beginning |
| 71199 | 71501 | ** of the record to data0. |
| | @@ -71265,13 +71567,13 @@ |
| 71265 | 71567 | } |
| 71266 | 71568 | |
| 71267 | 71569 | /* Make sure the output register has a buffer large enough to store |
| 71268 | 71570 | ** the new record. The output register (pOp->p3) is not allowed to |
| 71269 | 71571 | ** be one of the input registers (because the following call to |
| 71270 | | - ** sqlite3VdbeMemGrow() could clobber the value before it is used). |
| 71572 | + ** sqlite3VdbeMemClearAndResize() could clobber the value before it is used). |
| 71271 | 71573 | */ |
| 71272 | | - if( sqlite3VdbeMemGrow(pOut, (int)nByte, 0) ){ |
| 71574 | + if( sqlite3VdbeMemClearAndResize(pOut, (int)nByte) ){ |
| 71273 | 71575 | goto no_mem; |
| 71274 | 71576 | } |
| 71275 | 71577 | zNewRecord = (u8 *)pOut->z; |
| 71276 | 71578 | |
| 71277 | 71579 | /* Write the record */ |
| | @@ -71288,11 +71590,10 @@ |
| 71288 | 71590 | assert( j==nByte ); |
| 71289 | 71591 | |
| 71290 | 71592 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 71291 | 71593 | pOut->n = (int)nByte; |
| 71292 | 71594 | pOut->flags = MEM_Blob; |
| 71293 | | - pOut->xDel = 0; |
| 71294 | 71595 | if( nZero ){ |
| 71295 | 71596 | pOut->u.nZero = nZero; |
| 71296 | 71597 | pOut->flags |= MEM_Zero; |
| 71297 | 71598 | } |
| 71298 | 71599 | pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */ |
| | @@ -72176,13 +72477,13 @@ |
| 72176 | 72477 | pC->seekOp = pOp->opcode; |
| 72177 | 72478 | #endif |
| 72178 | 72479 | if( pC->isTable ){ |
| 72179 | 72480 | /* The input value in P3 might be of any type: integer, real, string, |
| 72180 | 72481 | ** blob, or NULL. But it needs to be an integer before we can do |
| 72181 | | - ** the seek, so covert it. */ |
| 72482 | + ** the seek, so convert it. */ |
| 72182 | 72483 | pIn3 = &aMem[pOp->p3]; |
| 72183 | | - if( (pIn3->flags & (MEM_Int|MEM_Real))==0 ){ |
| 72484 | + if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ |
| 72184 | 72485 | applyNumericAffinity(pIn3, 0); |
| 72185 | 72486 | } |
| 72186 | 72487 | iKey = sqlite3VdbeIntValue(pIn3); |
| 72187 | 72488 | pC->rowidIsValid = 0; |
| 72188 | 72489 | |
| | @@ -72201,20 +72502,20 @@ |
| 72201 | 72502 | ** is 4.9 and the integer approximation 5: |
| 72202 | 72503 | ** |
| 72203 | 72504 | ** (x > 4.9) -> (x >= 5) |
| 72204 | 72505 | ** (x <= 4.9) -> (x < 5) |
| 72205 | 72506 | */ |
| 72206 | | - if( pIn3->r<(double)iKey ){ |
| 72507 | + if( pIn3->u.r<(double)iKey ){ |
| 72207 | 72508 | assert( OP_SeekGE==(OP_SeekGT-1) ); |
| 72208 | 72509 | assert( OP_SeekLT==(OP_SeekLE-1) ); |
| 72209 | 72510 | assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) ); |
| 72210 | 72511 | if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--; |
| 72211 | 72512 | } |
| 72212 | 72513 | |
| 72213 | 72514 | /* If the approximation iKey is smaller than the actual real search |
| 72214 | 72515 | ** term, substitute <= for < and > for >=. */ |
| 72215 | | - else if( pIn3->r>(double)iKey ){ |
| 72516 | + else if( pIn3->u.r>(double)iKey ){ |
| 72216 | 72517 | assert( OP_SeekLE==(OP_SeekLT+1) ); |
| 72217 | 72518 | assert( OP_SeekGT==(OP_SeekGE+1) ); |
| 72218 | 72519 | assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) ); |
| 72219 | 72520 | if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++; |
| 72220 | 72521 | } |
| | @@ -72972,11 +73273,11 @@ |
| 72972 | 73273 | assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 72973 | 73274 | if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 72974 | 73275 | goto too_big; |
| 72975 | 73276 | } |
| 72976 | 73277 | } |
| 72977 | | - if( sqlite3VdbeMemGrow(pOut, n, 0) ){ |
| 73278 | + if( sqlite3VdbeMemClearAndResize(pOut, n) ){ |
| 72978 | 73279 | goto no_mem; |
| 72979 | 73280 | } |
| 72980 | 73281 | pOut->n = n; |
| 72981 | 73282 | MemSetTypeFlag(pOut, MEM_Blob); |
| 72982 | 73283 | if( pC->isTable==0 ){ |
| | @@ -73482,11 +73783,11 @@ |
| 73482 | 73783 | r.aMem = &aMem[pOp->p3]; |
| 73483 | 73784 | #ifdef SQLITE_DEBUG |
| 73484 | 73785 | { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 73485 | 73786 | #endif |
| 73486 | 73787 | res = 0; /* Not needed. Only used to silence a warning. */ |
| 73487 | | - rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res); |
| 73788 | + rc = sqlite3VdbeIdxKeyCompare(db, pC, &r, &res); |
| 73488 | 73789 | assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) ); |
| 73489 | 73790 | if( (pOp->opcode&1)==(OP_IdxLT&1) ){ |
| 73490 | 73791 | assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT ); |
| 73491 | 73792 | res = -res; |
| 73492 | 73793 | }else{ |
| | @@ -74252,15 +74553,11 @@ |
| 74252 | 74553 | } |
| 74253 | 74554 | ctx.pFunc = pOp->p4.pFunc; |
| 74254 | 74555 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 74255 | 74556 | ctx.pMem = pMem = &aMem[pOp->p3]; |
| 74256 | 74557 | pMem->n++; |
| 74257 | | - t.flags = MEM_Null; |
| 74258 | | - t.z = 0; |
| 74259 | | - t.zMalloc = 0; |
| 74260 | | - t.xDel = 0; |
| 74261 | | - t.db = db; |
| 74558 | + sqlite3VdbeMemInit(&t, db, MEM_Null); |
| 74262 | 74559 | ctx.pOut = &t; |
| 74263 | 74560 | ctx.isError = 0; |
| 74264 | 74561 | ctx.pColl = 0; |
| 74265 | 74562 | ctx.skipFlag = 0; |
| 74266 | 74563 | if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| | @@ -76175,12 +76472,15 @@ |
| 76175 | 76472 | ** *pp is undefined in this case. |
| 76176 | 76473 | */ |
| 76177 | 76474 | static int vdbeSorterMapFile(SortSubtask *pTask, SorterFile *pFile, u8 **pp){ |
| 76178 | 76475 | int rc = SQLITE_OK; |
| 76179 | 76476 | if( pFile->iEof<=(i64)(pTask->pSorter->db->nMaxSorterMmap) ){ |
| 76180 | | - rc = sqlite3OsFetch(pFile->pFd, 0, (int)pFile->iEof, (void**)pp); |
| 76181 | | - testcase( rc!=SQLITE_OK ); |
| 76477 | + sqlite3_file *pFd = pFile->pFd; |
| 76478 | + if( pFd->pMethods->iVersion>=3 ){ |
| 76479 | + rc = sqlite3OsFetch(pFd, 0, (int)pFile->iEof, (void**)pp); |
| 76480 | + testcase( rc!=SQLITE_OK ); |
| 76481 | + } |
| 76182 | 76482 | } |
| 76183 | 76483 | return rc; |
| 76184 | 76484 | } |
| 76185 | 76485 | |
| 76186 | 76486 | /* |
| | @@ -76331,11 +76631,11 @@ |
| 76331 | 76631 | ){ |
| 76332 | 76632 | UnpackedRecord *r2 = pTask->pUnpacked; |
| 76333 | 76633 | if( pKey2 ){ |
| 76334 | 76634 | sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); |
| 76335 | 76635 | } |
| 76336 | | - return sqlite3VdbeRecordCompare(nKey1, pKey1, r2, 0); |
| 76636 | + return sqlite3VdbeRecordCompare(nKey1, pKey1, r2); |
| 76337 | 76637 | } |
| 76338 | 76638 | |
| 76339 | 76639 | /* |
| 76340 | 76640 | ** Initialize the temporary index cursor just opened as a sorter cursor. |
| 76341 | 76641 | ** |
| | @@ -76694,11 +76994,11 @@ |
| 76694 | 76994 | ** |
| 76695 | 76995 | ** Whether or not the file does end up memory mapped of course depends on |
| 76696 | 76996 | ** the specific VFS implementation. |
| 76697 | 76997 | */ |
| 76698 | 76998 | static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){ |
| 76699 | | - if( nByte<=(i64)(db->nMaxSorterMmap) ){ |
| 76999 | + if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){ |
| 76700 | 77000 | int rc = sqlite3OsTruncate(pFd, nByte); |
| 76701 | 77001 | if( rc==SQLITE_OK ){ |
| 76702 | 77002 | void *p = 0; |
| 76703 | 77003 | sqlite3OsFetch(pFd, 0, (int)nByte, &p); |
| 76704 | 77004 | sqlite3OsUnfetch(pFd, 0, p); |
| | @@ -77632,11 +77932,11 @@ |
| 77632 | 77932 | return pRet; |
| 77633 | 77933 | } |
| 77634 | 77934 | |
| 77635 | 77935 | /* |
| 77636 | 77936 | ** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK) |
| 77637 | | -** on the the PmaReader object passed as the first argument. |
| 77937 | +** on the PmaReader object passed as the first argument. |
| 77638 | 77938 | ** |
| 77639 | 77939 | ** This call will initialize the various fields of the pReadr->pIncr |
| 77640 | 77940 | ** structure and, if it is a multi-threaded IncrMerger, launch a |
| 77641 | 77941 | ** background thread to populate aFile[1]. |
| 77642 | 77942 | */ |
| | @@ -78031,11 +78331,11 @@ |
| 78031 | 78331 | SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *pCsr, Mem *pOut){ |
| 78032 | 78332 | VdbeSorter *pSorter = pCsr->pSorter; |
| 78033 | 78333 | void *pKey; int nKey; /* Sorter key to copy into pOut */ |
| 78034 | 78334 | |
| 78035 | 78335 | pKey = vdbeSorterRowkey(pSorter, &nKey); |
| 78036 | | - if( sqlite3VdbeMemGrow(pOut, nKey, 0) ){ |
| 78336 | + if( sqlite3VdbeMemClearAndResize(pOut, nKey) ){ |
| 78037 | 78337 | return SQLITE_NOMEM; |
| 78038 | 78338 | } |
| 78039 | 78339 | pOut->n = nKey; |
| 78040 | 78340 | MemSetTypeFlag(pOut, MEM_Blob); |
| 78041 | 78341 | memcpy(pOut->z, pKey, nKey); |
| | @@ -78087,11 +78387,11 @@ |
| 78087 | 78387 | *pRes = -1; |
| 78088 | 78388 | return SQLITE_OK; |
| 78089 | 78389 | } |
| 78090 | 78390 | } |
| 78091 | 78391 | |
| 78092 | | - *pRes = sqlite3VdbeRecordCompare(pVal->n, pVal->z, r2, 0); |
| 78392 | + *pRes = sqlite3VdbeRecordCompare(pVal->n, pVal->z, r2); |
| 78093 | 78393 | return SQLITE_OK; |
| 78094 | 78394 | } |
| 78095 | 78395 | |
| 78096 | 78396 | /************** End of vdbesort.c ********************************************/ |
| 78097 | 78397 | /************** Begin file journal.c *****************************************/ |
| | @@ -78378,11 +78678,11 @@ |
| 78378 | 78678 | /* Space to hold the rollback journal is allocated in increments of |
| 78379 | 78679 | ** this many bytes. |
| 78380 | 78680 | ** |
| 78381 | 78681 | ** The size chosen is a little less than a power of two. That way, |
| 78382 | 78682 | ** the FileChunk object will have a size that almost exactly fills |
| 78383 | | -** a power-of-two allocation. This mimimizes wasted space in power-of-two |
| 78683 | +** a power-of-two allocation. This minimizes wasted space in power-of-two |
| 78384 | 78684 | ** memory allocators. |
| 78385 | 78685 | */ |
| 78386 | 78686 | #define JOURNAL_CHUNKSIZE ((int)(1024-sizeof(FileChunk*))) |
| 78387 | 78687 | |
| 78388 | 78688 | /* |
| | @@ -78628,11 +78928,11 @@ |
| 78628 | 78928 | /* #include <string.h> */ |
| 78629 | 78929 | |
| 78630 | 78930 | |
| 78631 | 78931 | /* |
| 78632 | 78932 | ** Walk an expression tree. Invoke the callback once for each node |
| 78633 | | -** of the expression, while decending. (In other words, the callback |
| 78933 | +** of the expression, while descending. (In other words, the callback |
| 78634 | 78934 | ** is invoked before visiting children.) |
| 78635 | 78935 | ** |
| 78636 | 78936 | ** The return value from the callback should be one of the WRC_* |
| 78637 | 78937 | ** constants to specify how to proceed with the walk. |
| 78638 | 78938 | ** |
| | @@ -79484,13 +79784,11 @@ |
| 79484 | 79784 | ** likelihood(X,0.9375). */ |
| 79485 | 79785 | /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */ |
| 79486 | 79786 | pExpr->iTable = pDef->zName[0]=='u' ? 62 : 938; |
| 79487 | 79787 | } |
| 79488 | 79788 | } |
| 79489 | | - } |
| 79490 | 79789 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 79491 | | - if( pDef ){ |
| 79492 | 79790 | auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0); |
| 79493 | 79791 | if( auth!=SQLITE_OK ){ |
| 79494 | 79792 | if( auth==SQLITE_DENY ){ |
| 79495 | 79793 | sqlite3ErrorMsg(pParse, "not authorized to use function: %s", |
| 79496 | 79794 | pDef->zName); |
| | @@ -79497,13 +79795,13 @@ |
| 79497 | 79795 | pNC->nErr++; |
| 79498 | 79796 | } |
| 79499 | 79797 | pExpr->op = TK_NULL; |
| 79500 | 79798 | return WRC_Prune; |
| 79501 | 79799 | } |
| 79800 | +#endif |
| 79502 | 79801 | if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant); |
| 79503 | 79802 | } |
| 79504 | | -#endif |
| 79505 | 79803 | if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){ |
| 79506 | 79804 | sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId); |
| 79507 | 79805 | pNC->nErr++; |
| 79508 | 79806 | is_agg = 0; |
| 79509 | 79807 | }else if( no_such_func && pParse->db->init.busy==0 ){ |
| | @@ -79522,11 +79820,17 @@ |
| 79522 | 79820 | pExpr->op2 = 0; |
| 79523 | 79821 | while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){ |
| 79524 | 79822 | pExpr->op2++; |
| 79525 | 79823 | pNC2 = pNC2->pNext; |
| 79526 | 79824 | } |
| 79527 | | - if( pNC2 ) pNC2->ncFlags |= NC_HasAgg; |
| 79825 | + assert( pDef!=0 ); |
| 79826 | + if( pNC2 ){ |
| 79827 | + assert( SQLITE_FUNC_MINMAX==NC_MinMaxAgg ); |
| 79828 | + testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 ); |
| 79829 | + pNC2->ncFlags |= NC_HasAgg | (pDef->funcFlags & SQLITE_FUNC_MINMAX); |
| 79830 | + |
| 79831 | + } |
| 79528 | 79832 | pNC->ncFlags |= NC_AllowAgg; |
| 79529 | 79833 | } |
| 79530 | 79834 | /* FIX ME: Compute pExpr->affinity based on the expected return |
| 79531 | 79835 | ** type of the function |
| 79532 | 79836 | */ |
| | @@ -79883,11 +80187,11 @@ |
| 79883 | 80187 | } |
| 79884 | 80188 | return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType); |
| 79885 | 80189 | } |
| 79886 | 80190 | |
| 79887 | 80191 | /* |
| 79888 | | -** Resolve names in the SELECT statement p and all of its descendents. |
| 80192 | +** Resolve names in the SELECT statement p and all of its descendants. |
| 79889 | 80193 | */ |
| 79890 | 80194 | static int resolveSelectStep(Walker *pWalker, Select *p){ |
| 79891 | 80195 | NameContext *pOuterNC; /* Context that contains this SELECT */ |
| 79892 | 80196 | NameContext sNC; /* Name context of this SELECT */ |
| 79893 | 80197 | int isCompound; /* True if p is a compound select */ |
| | @@ -79987,11 +80291,12 @@ |
| 79987 | 80291 | ** expression, do not allow aggregates in any of the other expressions. |
| 79988 | 80292 | */ |
| 79989 | 80293 | assert( (p->selFlags & SF_Aggregate)==0 ); |
| 79990 | 80294 | pGroupBy = p->pGroupBy; |
| 79991 | 80295 | if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){ |
| 79992 | | - p->selFlags |= SF_Aggregate; |
| 80296 | + assert( NC_MinMaxAgg==SF_MinMaxAgg ); |
| 80297 | + p->selFlags |= SF_Aggregate | (sNC.ncFlags&NC_MinMaxAgg); |
| 79993 | 80298 | }else{ |
| 79994 | 80299 | sNC.ncFlags &= ~NC_AllowAgg; |
| 79995 | 80300 | } |
| 79996 | 80301 | |
| 79997 | 80302 | /* If a HAVING clause is present, then there must be a GROUP BY clause. |
| | @@ -80115,11 +80420,11 @@ |
| 80115 | 80420 | */ |
| 80116 | 80421 | SQLITE_PRIVATE int sqlite3ResolveExprNames( |
| 80117 | 80422 | NameContext *pNC, /* Namespace to resolve expressions in. */ |
| 80118 | 80423 | Expr *pExpr /* The expression to be analyzed. */ |
| 80119 | 80424 | ){ |
| 80120 | | - u8 savedHasAgg; |
| 80425 | + u16 savedHasAgg; |
| 80121 | 80426 | Walker w; |
| 80122 | 80427 | |
| 80123 | 80428 | if( pExpr==0 ) return 0; |
| 80124 | 80429 | #if SQLITE_MAX_EXPR_DEPTH>0 |
| 80125 | 80430 | { |
| | @@ -80128,12 +80433,12 @@ |
| 80128 | 80433 | return 1; |
| 80129 | 80434 | } |
| 80130 | 80435 | pParse->nHeight += pExpr->nHeight; |
| 80131 | 80436 | } |
| 80132 | 80437 | #endif |
| 80133 | | - savedHasAgg = pNC->ncFlags & NC_HasAgg; |
| 80134 | | - pNC->ncFlags &= ~NC_HasAgg; |
| 80438 | + savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg); |
| 80439 | + pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg); |
| 80135 | 80440 | memset(&w, 0, sizeof(w)); |
| 80136 | 80441 | w.xExprCallback = resolveExprStep; |
| 80137 | 80442 | w.xSelectCallback = resolveSelectStep; |
| 80138 | 80443 | w.pParse = pNC->pParse; |
| 80139 | 80444 | w.u.pNC = pNC; |
| | @@ -80144,13 +80449,12 @@ |
| 80144 | 80449 | if( pNC->nErr>0 || w.pParse->nErr>0 ){ |
| 80145 | 80450 | ExprSetProperty(pExpr, EP_Error); |
| 80146 | 80451 | } |
| 80147 | 80452 | if( pNC->ncFlags & NC_HasAgg ){ |
| 80148 | 80453 | ExprSetProperty(pExpr, EP_Agg); |
| 80149 | | - }else if( savedHasAgg ){ |
| 80150 | | - pNC->ncFlags |= NC_HasAgg; |
| 80151 | 80454 | } |
| 80455 | + pNC->ncFlags |= savedHasAgg; |
| 80152 | 80456 | return ExprHasProperty(pExpr, EP_Error); |
| 80153 | 80457 | } |
| 80154 | 80458 | |
| 80155 | 80459 | |
| 80156 | 80460 | /* |
| | @@ -80246,11 +80550,11 @@ |
| 80246 | 80550 | ** If pExpr is a column, a reference to a column via an 'AS' alias, |
| 80247 | 80551 | ** or a sub-select with a column as the return value, then the |
| 80248 | 80552 | ** affinity of that column is returned. Otherwise, 0x00 is returned, |
| 80249 | 80553 | ** indicating no affinity for the expression. |
| 80250 | 80554 | ** |
| 80251 | | -** i.e. the WHERE clause expresssions in the following statements all |
| 80555 | +** i.e. the WHERE clause expressions in the following statements all |
| 80252 | 80556 | ** have an affinity: |
| 80253 | 80557 | ** |
| 80254 | 80558 | ** CREATE TABLE t1(a); |
| 80255 | 80559 | ** SELECT * FROM t1 WHERE a; |
| 80256 | 80560 | ** SELECT a AS b FROM t1 WHERE b; |
| | @@ -80725,11 +81029,11 @@ |
| 80725 | 81029 | exprSetHeight(pRoot); |
| 80726 | 81030 | } |
| 80727 | 81031 | } |
| 80728 | 81032 | |
| 80729 | 81033 | /* |
| 80730 | | -** Allocate a Expr node which joins as many as two subtrees. |
| 81034 | +** Allocate an Expr node which joins as many as two subtrees. |
| 80731 | 81035 | ** |
| 80732 | 81036 | ** One or both of the subtrees can be NULL. Return a pointer to the new |
| 80733 | 81037 | ** Expr node. Or, if an OOM error occurs, set pParse->db->mallocFailed, |
| 80734 | 81038 | ** free the subtrees and return NULL. |
| 80735 | 81039 | */ |
| | @@ -80835,11 +81139,11 @@ |
| 80835 | 81139 | ** sure "nnn" is not too be to avoid a denial of service attack when |
| 80836 | 81140 | ** the SQL statement comes from an external source. |
| 80837 | 81141 | ** |
| 80838 | 81142 | ** Wildcards of the form ":aaa", "@aaa", or "$aaa" are assigned the same number |
| 80839 | 81143 | ** as the previous instance of the same wildcard. Or if this is the first |
| 80840 | | -** instance of the wildcard, the next sequenial variable number is |
| 81144 | +** instance of the wildcard, the next sequential variable number is |
| 80841 | 81145 | ** assigned. |
| 80842 | 81146 | */ |
| 80843 | 81147 | SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){ |
| 80844 | 81148 | sqlite3 *db = pParse->db; |
| 80845 | 81149 | const char *z; |
| | @@ -80970,11 +81274,11 @@ |
| 80970 | 81274 | ** Note that with flags==EXPRDUP_REDUCE, this routines works on full-size |
| 80971 | 81275 | ** (unreduced) Expr objects as they or originally constructed by the parser. |
| 80972 | 81276 | ** During expression analysis, extra information is computed and moved into |
| 80973 | 81277 | ** later parts of teh Expr object and that extra information might get chopped |
| 80974 | 81278 | ** off if the expression is reduced. Note also that it does not work to |
| 80975 | | -** make a EXPRDUP_REDUCE copy of a reduced expression. It is only legal |
| 81279 | +** make an EXPRDUP_REDUCE copy of a reduced expression. It is only legal |
| 80976 | 81280 | ** to reduce a pristine expression tree from the parser. The implementation |
| 80977 | 81281 | ** of dupedExprStructSize() contain multiple assert() statements that attempt |
| 80978 | 81282 | ** to enforce this constraint. |
| 80979 | 81283 | */ |
| 80980 | 81284 | static int dupedExprStructSize(Expr *p, int flags){ |
| | @@ -81039,11 +81343,11 @@ |
| 81039 | 81343 | /* |
| 81040 | 81344 | ** This function is similar to sqlite3ExprDup(), except that if pzBuffer |
| 81041 | 81345 | ** is not NULL then *pzBuffer is assumed to point to a buffer large enough |
| 81042 | 81346 | ** to store the copy of expression p, the copies of p->u.zToken |
| 81043 | 81347 | ** (if applicable), and the copies of the p->pLeft and p->pRight expressions, |
| 81044 | | -** if any. Before returning, *pzBuffer is set to the first byte passed the |
| 81348 | +** if any. Before returning, *pzBuffer is set to the first byte past the |
| 81045 | 81349 | ** portion of the buffer copied into by this function. |
| 81046 | 81350 | */ |
| 81047 | 81351 | static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){ |
| 81048 | 81352 | Expr *pNew = 0; /* Value to return */ |
| 81049 | 81353 | if( p ){ |
| | @@ -81765,11 +82069,11 @@ |
| 81765 | 82069 | ** |
| 81766 | 82070 | ** SELECT <column> FROM <table> |
| 81767 | 82071 | ** |
| 81768 | 82072 | ** If the RHS of the IN operator is a list or a more complex subquery, then |
| 81769 | 82073 | ** an ephemeral table might need to be generated from the RHS and then |
| 81770 | | -** pX->iTable made to point to the ephermeral table instead of an |
| 82074 | +** pX->iTable made to point to the ephemeral table instead of an |
| 81771 | 82075 | ** existing table. |
| 81772 | 82076 | ** |
| 81773 | 82077 | ** The inFlags parameter must contain exactly one of the bits |
| 81774 | 82078 | ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP. If inFlags contains |
| 81775 | 82079 | ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a |
| | @@ -81895,11 +82199,11 @@ |
| 81895 | 82199 | |
| 81896 | 82200 | /* If no preexisting index is available for the IN clause |
| 81897 | 82201 | ** and IN_INDEX_NOOP is an allowed reply |
| 81898 | 82202 | ** and the RHS of the IN operator is a list, not a subquery |
| 81899 | 82203 | ** and the RHS is not contant or has two or fewer terms, |
| 81900 | | - ** then it is not worth creating an ephermeral table to evaluate |
| 82204 | + ** then it is not worth creating an ephemeral table to evaluate |
| 81901 | 82205 | ** the IN operator so return IN_INDEX_NOOP. |
| 81902 | 82206 | */ |
| 81903 | 82207 | if( eType==0 |
| 81904 | 82208 | && (inFlags & IN_INDEX_NOOP_OK) |
| 81905 | 82209 | && !ExprHasProperty(pX, EP_xIsSelect) |
| | @@ -82656,20 +82960,13 @@ |
| 82656 | 82960 | /* |
| 82657 | 82961 | ** Generate code to move content from registers iFrom...iFrom+nReg-1 |
| 82658 | 82962 | ** over to iTo..iTo+nReg-1. Keep the column cache up-to-date. |
| 82659 | 82963 | */ |
| 82660 | 82964 | SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse *pParse, int iFrom, int iTo, int nReg){ |
| 82661 | | - int i; |
| 82662 | | - struct yColCache *p; |
| 82663 | 82965 | assert( iFrom>=iTo+nReg || iFrom+nReg<=iTo ); |
| 82664 | 82966 | sqlite3VdbeAddOp3(pParse->pVdbe, OP_Move, iFrom, iTo, nReg); |
| 82665 | | - for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 82666 | | - int x = p->iReg; |
| 82667 | | - if( x>=iFrom && x<iFrom+nReg ){ |
| 82668 | | - p->iReg += iTo-iFrom; |
| 82669 | | - } |
| 82670 | | - } |
| 82967 | + sqlite3ExprCacheRemove(pParse, iFrom, nReg); |
| 82671 | 82968 | } |
| 82672 | 82969 | |
| 82673 | 82970 | #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST) |
| 82674 | 82971 | /* |
| 82675 | 82972 | ** Return true if any register in the range iFrom..iTo (inclusive) |
| | @@ -82982,11 +83279,11 @@ |
| 82982 | 83279 | sqlite3ErrorMsg(pParse, "unknown function: %.*s()", nId, zId); |
| 82983 | 83280 | break; |
| 82984 | 83281 | } |
| 82985 | 83282 | |
| 82986 | 83283 | /* Attempt a direct implementation of the built-in COALESCE() and |
| 82987 | | - ** IFNULL() functions. This avoids unnecessary evalation of |
| 83284 | + ** IFNULL() functions. This avoids unnecessary evaluation of |
| 82988 | 83285 | ** arguments past the first non-NULL argument. |
| 82989 | 83286 | */ |
| 82990 | 83287 | if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){ |
| 82991 | 83288 | int endCoalesce = sqlite3VdbeMakeLabel(v); |
| 82992 | 83289 | assert( nFarg>=2 ); |
| | @@ -83421,11 +83718,11 @@ |
| 83421 | 83718 | sqlite3ExprCode(pParse, pExpr, target); |
| 83422 | 83719 | } |
| 83423 | 83720 | } |
| 83424 | 83721 | |
| 83425 | 83722 | /* |
| 83426 | | -** Generate code that evalutes the given expression and puts the result |
| 83723 | +** Generate code that evaluates the given expression and puts the result |
| 83427 | 83724 | ** in register target. |
| 83428 | 83725 | ** |
| 83429 | 83726 | ** Also make a copy of the expression results into another "cache" register |
| 83430 | 83727 | ** and modify the expression so that the next time it is evaluated, |
| 83431 | 83728 | ** the result is a copy of the cache register. |
| | @@ -83776,11 +84073,11 @@ |
| 83776 | 84073 | ** The above is equivalent to |
| 83777 | 84074 | ** |
| 83778 | 84075 | ** x>=y AND x<=z |
| 83779 | 84076 | ** |
| 83780 | 84077 | ** Code it as such, taking care to do the common subexpression |
| 83781 | | -** elementation of x. |
| 84078 | +** elimination of x. |
| 83782 | 84079 | */ |
| 83783 | 84080 | static void exprCodeBetween( |
| 83784 | 84081 | Parse *pParse, /* Parsing and code generating context */ |
| 83785 | 84082 | Expr *pExpr, /* The BETWEEN expression */ |
| 83786 | 84083 | int dest, /* Jump here if the jump is taken */ |
| | @@ -84513,11 +84810,11 @@ |
| 84513 | 84810 | /* |
| 84514 | 84811 | ** Deallocate a register, making available for reuse for some other |
| 84515 | 84812 | ** purpose. |
| 84516 | 84813 | ** |
| 84517 | 84814 | ** If a register is currently being used by the column cache, then |
| 84518 | | -** the dallocation is deferred until the column cache line that uses |
| 84815 | +** the deallocation is deferred until the column cache line that uses |
| 84519 | 84816 | ** the register becomes stale. |
| 84520 | 84817 | */ |
| 84521 | 84818 | SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){ |
| 84522 | 84819 | if( iReg && pParse->nTempReg<ArraySize(pParse->aTempReg) ){ |
| 84523 | 84820 | int i; |
| | @@ -84740,12 +85037,12 @@ |
| 84740 | 85037 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 84741 | 85038 | |
| 84742 | 85039 | UNUSED_PARAMETER(NotUsed); |
| 84743 | 85040 | |
| 84744 | 85041 | /* The principle used to locate the table name in the CREATE TRIGGER |
| 84745 | | - ** statement is that the table name is the first token that is immediatedly |
| 84746 | | - ** preceded by either TK_ON or TK_DOT and immediatedly followed by one |
| 85042 | + ** statement is that the table name is the first token that is immediately |
| 85043 | + ** preceded by either TK_ON or TK_DOT and immediately followed by one |
| 84747 | 85044 | ** of TK_WHEN, TK_BEGIN or TK_FOR. |
| 84748 | 85045 | */ |
| 84749 | 85046 | if( zSql ){ |
| 84750 | 85047 | do { |
| 84751 | 85048 | |
| | @@ -85432,11 +85729,11 @@ |
| 85432 | 85729 | ** version of sqlite_stat3 and is only available when compiled with |
| 85433 | 85730 | ** SQLITE_ENABLE_STAT4 and in SQLite versions 3.8.1 and later. It is |
| 85434 | 85731 | ** not possible to enable both STAT3 and STAT4 at the same time. If they |
| 85435 | 85732 | ** are both enabled, then STAT4 takes precedence. |
| 85436 | 85733 | ** |
| 85437 | | -** For most applications, sqlite_stat1 provides all the statisics required |
| 85734 | +** For most applications, sqlite_stat1 provides all the statistics required |
| 85438 | 85735 | ** for the query planner to make good choices. |
| 85439 | 85736 | ** |
| 85440 | 85737 | ** Format of sqlite_stat1: |
| 85441 | 85738 | ** |
| 85442 | 85739 | ** There is normally one row per index, with the index identified by the |
| | @@ -85783,12 +86080,13 @@ |
| 85783 | 86080 | ** WITHOUT ROWID tables, N=K+P where P is the number of columns in the |
| 85784 | 86081 | ** PRIMARY KEY of the table. The covering index that implements the |
| 85785 | 86082 | ** original WITHOUT ROWID table as N==K as a special case. |
| 85786 | 86083 | ** |
| 85787 | 86084 | ** This routine allocates the Stat4Accum object in heap memory. The return |
| 85788 | | -** value is a pointer to the the Stat4Accum object encoded as a blob (i.e. |
| 85789 | | -** the size of the blob is sizeof(void*) bytes). |
| 86085 | +** value is a pointer to the Stat4Accum object. The datatype of the |
| 86086 | +** return value is BLOB, but it is really just a pointer to the Stat4Accum |
| 86087 | +** object. |
| 85790 | 86088 | */ |
| 85791 | 86089 | static void statInit( |
| 85792 | 86090 | sqlite3_context *context, |
| 85793 | 86091 | int argc, |
| 85794 | 86092 | sqlite3_value **argv |
| | @@ -85862,12 +86160,15 @@ |
| 85862 | 86160 | p->aBest[i].iCol = i; |
| 85863 | 86161 | } |
| 85864 | 86162 | } |
| 85865 | 86163 | #endif |
| 85866 | 86164 | |
| 85867 | | - /* Return a pointer to the allocated object to the caller */ |
| 85868 | | - sqlite3_result_blob(context, p, sizeof(p), stat4Destructor); |
| 86165 | + /* Return a pointer to the allocated object to the caller. Note that |
| 86166 | + ** only the pointer (the 2nd parameter) matters. The size of the object |
| 86167 | + ** (given by the 3rd parameter) is never used and can be any positive |
| 86168 | + ** value. */ |
| 86169 | + sqlite3_result_blob(context, p, sizeof(*p), stat4Destructor); |
| 85869 | 86170 | } |
| 85870 | 86171 | static const FuncDef statInitFuncdef = { |
| 85871 | 86172 | 2+IsStat34, /* nArg */ |
| 85872 | 86173 | SQLITE_UTF8, /* funcFlags */ |
| 85873 | 86174 | 0, /* pUserData */ |
| | @@ -86189,11 +86490,11 @@ |
| 86189 | 86490 | |
| 86190 | 86491 | /* |
| 86191 | 86492 | ** Implementation of the stat_get(P,J) SQL function. This routine is |
| 86192 | 86493 | ** used to query statistical information that has been gathered into |
| 86193 | 86494 | ** the Stat4Accum object by prior calls to stat_push(). The P parameter |
| 86194 | | -** is a BLOB which is decoded into a pointer to the Stat4Accum objects. |
| 86495 | +** has type BLOB but it is really just a pointer to the Stat4Accum object. |
| 86195 | 86496 | ** The content to returned is determined by the parameter J |
| 86196 | 86497 | ** which is one of the STAT_GET_xxxx values defined above. |
| 86197 | 86498 | ** |
| 86198 | 86499 | ** If neither STAT3 nor STAT4 are enabled, then J is always |
| 86199 | 86500 | ** STAT_GET_STAT1 and is hence omitted and this routine becomes |
| | @@ -86593,11 +86894,12 @@ |
| 86593 | 86894 | sqlite3VdbeChangeP5(v, 2+IsStat34); |
| 86594 | 86895 | sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v); |
| 86595 | 86896 | |
| 86596 | 86897 | /* Add the entry to the stat1 table. */ |
| 86597 | 86898 | callStatGet(v, regStat4, STAT_GET_STAT1, regStat1); |
| 86598 | | - sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0); |
| 86899 | + assert( "BBB"[0]==SQLITE_AFF_TEXT ); |
| 86900 | + sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0); |
| 86599 | 86901 | sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid); |
| 86600 | 86902 | sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid); |
| 86601 | 86903 | sqlite3VdbeChangeP5(v, OPFLAG_APPEND); |
| 86602 | 86904 | |
| 86603 | 86905 | /* Add the entries to the stat3 or stat4 table. */ |
| | @@ -86656,11 +86958,12 @@ |
| 86656 | 86958 | if( pOnlyIdx==0 && needTableCnt ){ |
| 86657 | 86959 | VdbeComment((v, "%s", pTab->zName)); |
| 86658 | 86960 | sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1); |
| 86659 | 86961 | jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); VdbeCoverage(v); |
| 86660 | 86962 | sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname); |
| 86661 | | - sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0); |
| 86963 | + assert( "BBB"[0]==SQLITE_AFF_TEXT ); |
| 86964 | + sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0); |
| 86662 | 86965 | sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid); |
| 86663 | 86966 | sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid); |
| 86664 | 86967 | sqlite3VdbeChangeP5(v, OPFLAG_APPEND); |
| 86665 | 86968 | sqlite3VdbeJumpHere(v, jZeroRows); |
| 86666 | 86969 | } |
| | @@ -86975,11 +87278,11 @@ |
| 86975 | 87278 | tRowcnt nDLt = pFinal->anDLt[iCol]; |
| 86976 | 87279 | |
| 86977 | 87280 | /* Set nSum to the number of distinct (iCol+1) field prefixes that |
| 86978 | 87281 | ** occur in the stat4 table for this index before pFinal. Set |
| 86979 | 87282 | ** sumEq to the sum of the nEq values for column iCol for the same |
| 86980 | | - ** set (adding the value only once where there exist dupicate |
| 87283 | + ** set (adding the value only once where there exist duplicate |
| 86981 | 87284 | ** prefixes). */ |
| 86982 | 87285 | for(i=0; i<(pIdx->nSample-1); i++){ |
| 86983 | 87286 | if( aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol] ){ |
| 86984 | 87287 | sumEq += aSample[i].anEq[iCol]; |
| 86985 | 87288 | nSum++; |
| | @@ -87457,10 +87760,19 @@ |
| 87457 | 87760 | if( rc==SQLITE_OK ){ |
| 87458 | 87761 | sqlite3BtreeEnterAll(db); |
| 87459 | 87762 | rc = sqlite3Init(db, &zErrDyn); |
| 87460 | 87763 | sqlite3BtreeLeaveAll(db); |
| 87461 | 87764 | } |
| 87765 | +#ifdef SQLITE_USER_AUTHENTICATION |
| 87766 | + if( rc==SQLITE_OK ){ |
| 87767 | + u8 newAuth = 0; |
| 87768 | + rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth); |
| 87769 | + if( newAuth<db->auth.authLevel ){ |
| 87770 | + rc = SQLITE_AUTH_USER; |
| 87771 | + } |
| 87772 | + } |
| 87773 | +#endif |
| 87462 | 87774 | if( rc ){ |
| 87463 | 87775 | int iDb = db->nDb - 1; |
| 87464 | 87776 | assert( iDb>=2 ); |
| 87465 | 87777 | if( db->aDb[iDb].pBt ){ |
| 87466 | 87778 | sqlite3BtreeClose(db->aDb[iDb].pBt); |
| | @@ -87899,11 +88211,11 @@ |
| 87899 | 88211 | sqlite3 *db, |
| 87900 | 88212 | int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), |
| 87901 | 88213 | void *pArg |
| 87902 | 88214 | ){ |
| 87903 | 88215 | sqlite3_mutex_enter(db->mutex); |
| 87904 | | - db->xAuth = xAuth; |
| 88216 | + db->xAuth = (sqlite3_xauth)xAuth; |
| 87905 | 88217 | db->pAuthArg = pArg; |
| 87906 | 88218 | sqlite3ExpirePreparedStatements(db); |
| 87907 | 88219 | sqlite3_mutex_leave(db->mutex); |
| 87908 | 88220 | return SQLITE_OK; |
| 87909 | 88221 | } |
| | @@ -87934,11 +88246,15 @@ |
| 87934 | 88246 | ){ |
| 87935 | 88247 | sqlite3 *db = pParse->db; /* Database handle */ |
| 87936 | 88248 | char *zDb = db->aDb[iDb].zName; /* Name of attached database */ |
| 87937 | 88249 | int rc; /* Auth callback return code */ |
| 87938 | 88250 | |
| 87939 | | - rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext); |
| 88251 | + rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext |
| 88252 | +#ifdef SQLITE_USER_AUTHENTICATION |
| 88253 | + ,db->auth.zAuthUser |
| 88254 | +#endif |
| 88255 | + ); |
| 87940 | 88256 | if( rc==SQLITE_DENY ){ |
| 87941 | 88257 | if( db->nDb>2 || iDb!=0 ){ |
| 87942 | 88258 | sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",zDb,zTab,zCol); |
| 87943 | 88259 | }else{ |
| 87944 | 88260 | sqlite3ErrorMsg(pParse, "access to %s.%s is prohibited", zTab, zCol); |
| | @@ -88034,11 +88350,15 @@ |
| 88034 | 88350 | } |
| 88035 | 88351 | |
| 88036 | 88352 | if( db->xAuth==0 ){ |
| 88037 | 88353 | return SQLITE_OK; |
| 88038 | 88354 | } |
| 88039 | | - rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext); |
| 88355 | + rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext |
| 88356 | +#ifdef SQLITE_USER_AUTHENTICATION |
| 88357 | + ,db->auth.zAuthUser |
| 88358 | +#endif |
| 88359 | + ); |
| 88040 | 88360 | if( rc==SQLITE_DENY ){ |
| 88041 | 88361 | sqlite3ErrorMsg(pParse, "not authorized"); |
| 88042 | 88362 | pParse->rc = SQLITE_AUTH; |
| 88043 | 88363 | }else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){ |
| 88044 | 88364 | rc = SQLITE_DENY; |
| | @@ -88232,10 +88552,21 @@ |
| 88232 | 88552 | assert( !pParse->isMultiWrite |
| 88233 | 88553 | || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort)); |
| 88234 | 88554 | if( v ){ |
| 88235 | 88555 | while( sqlite3VdbeDeletePriorOpcode(v, OP_Close) ){} |
| 88236 | 88556 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 88557 | + |
| 88558 | +#if SQLITE_USER_AUTHENTICATION |
| 88559 | + if( pParse->nTableLock>0 && db->init.busy==0 ){ |
| 88560 | + sqlite3UserAuthInit(db); |
| 88561 | + if( db->auth.authLevel<UAUTH_User ){ |
| 88562 | + pParse->rc = SQLITE_AUTH_USER; |
| 88563 | + sqlite3ErrorMsg(pParse, "user not authenticated"); |
| 88564 | + return; |
| 88565 | + } |
| 88566 | + } |
| 88567 | +#endif |
| 88237 | 88568 | |
| 88238 | 88569 | /* The cookie mask contains one bit for each database file open. |
| 88239 | 88570 | ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are |
| 88240 | 88571 | ** set for each database that is used. Generate code to start a |
| 88241 | 88572 | ** transaction on each used database and to verify the schema cookie |
| | @@ -88348,10 +88679,20 @@ |
| 88348 | 88679 | sqlite3DbFree(db, zSql); |
| 88349 | 88680 | memcpy(&pParse->nVar, saveBuf, SAVE_SZ); |
| 88350 | 88681 | pParse->nested--; |
| 88351 | 88682 | } |
| 88352 | 88683 | |
| 88684 | +#if SQLITE_USER_AUTHENTICATION |
| 88685 | +/* |
| 88686 | +** Return TRUE if zTable is the name of the system table that stores the |
| 88687 | +** list of users and their access credentials. |
| 88688 | +*/ |
| 88689 | +SQLITE_PRIVATE int sqlite3UserAuthTable(const char *zTable){ |
| 88690 | + return sqlite3_stricmp(zTable, "sqlite_user")==0; |
| 88691 | +} |
| 88692 | +#endif |
| 88693 | + |
| 88353 | 88694 | /* |
| 88354 | 88695 | ** Locate the in-memory structure that describes a particular database |
| 88355 | 88696 | ** table given the name of that table and (optionally) the name of the |
| 88356 | 88697 | ** database containing the table. Return NULL if not found. |
| 88357 | 88698 | ** |
| | @@ -88366,10 +88707,17 @@ |
| 88366 | 88707 | Table *p = 0; |
| 88367 | 88708 | int i; |
| 88368 | 88709 | assert( zName!=0 ); |
| 88369 | 88710 | /* All mutexes are required for schema access. Make sure we hold them. */ |
| 88370 | 88711 | assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) ); |
| 88712 | +#if SQLITE_USER_AUTHENTICATION |
| 88713 | + /* Only the admin user is allowed to know that the sqlite_user table |
| 88714 | + ** exists */ |
| 88715 | + if( db->auth.authLevel<UAUTH_Admin && sqlite3UserAuthTable(zName)!=0 ){ |
| 88716 | + return 0; |
| 88717 | + } |
| 88718 | +#endif |
| 88371 | 88719 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 88372 | 88720 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 88373 | 88721 | if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue; |
| 88374 | 88722 | assert( sqlite3SchemaMutexHeld(db, j, 0) ); |
| 88375 | 88723 | p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName); |
| | @@ -88410,10 +88758,16 @@ |
| 88410 | 88758 | }else{ |
| 88411 | 88759 | sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName); |
| 88412 | 88760 | } |
| 88413 | 88761 | pParse->checkSchema = 1; |
| 88414 | 88762 | } |
| 88763 | +#if SQLITE_USER_AUTHENICATION |
| 88764 | + else if( pParse->db->auth.authLevel<UAUTH_User ){ |
| 88765 | + sqlite3ErrorMsg(pParse, "user not authenticated"); |
| 88766 | + p = 0; |
| 88767 | + } |
| 88768 | +#endif |
| 88415 | 88769 | return p; |
| 88416 | 88770 | } |
| 88417 | 88771 | |
| 88418 | 88772 | /* |
| 88419 | 88773 | ** Locate the table identified by *p. |
| | @@ -89220,11 +89574,11 @@ |
| 89220 | 89574 | |
| 89221 | 89575 | /* If pszEst is not NULL, store an estimate of the field size. The |
| 89222 | 89576 | ** estimate is scaled so that the size of an integer is 1. */ |
| 89223 | 89577 | if( pszEst ){ |
| 89224 | 89578 | *pszEst = 1; /* default size is approx 4 bytes */ |
| 89225 | | - if( aff<=SQLITE_AFF_NONE ){ |
| 89579 | + if( aff<SQLITE_AFF_NUMERIC ){ |
| 89226 | 89580 | if( zChar ){ |
| 89227 | 89581 | while( zChar[0] ){ |
| 89228 | 89582 | if( sqlite3Isdigit(zChar[0]) ){ |
| 89229 | 89583 | int v = 0; |
| 89230 | 89584 | sqlite3GetInt32(zChar, &v); |
| | @@ -89591,12 +89945,12 @@ |
| 89591 | 89945 | k = sqlite3Strlen30(zStmt); |
| 89592 | 89946 | identPut(zStmt, &k, p->zName); |
| 89593 | 89947 | zStmt[k++] = '('; |
| 89594 | 89948 | for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){ |
| 89595 | 89949 | static const char * const azType[] = { |
| 89596 | | - /* SQLITE_AFF_TEXT */ " TEXT", |
| 89597 | 89950 | /* SQLITE_AFF_NONE */ "", |
| 89951 | + /* SQLITE_AFF_TEXT */ " TEXT", |
| 89598 | 89952 | /* SQLITE_AFF_NUMERIC */ " NUM", |
| 89599 | 89953 | /* SQLITE_AFF_INTEGER */ " INT", |
| 89600 | 89954 | /* SQLITE_AFF_REAL */ " REAL" |
| 89601 | 89955 | }; |
| 89602 | 89956 | int len; |
| | @@ -89604,19 +89958,19 @@ |
| 89604 | 89958 | |
| 89605 | 89959 | sqlite3_snprintf(n-k, &zStmt[k], zSep); |
| 89606 | 89960 | k += sqlite3Strlen30(&zStmt[k]); |
| 89607 | 89961 | zSep = zSep2; |
| 89608 | 89962 | identPut(zStmt, &k, pCol->zName); |
| 89609 | | - assert( pCol->affinity-SQLITE_AFF_TEXT >= 0 ); |
| 89610 | | - assert( pCol->affinity-SQLITE_AFF_TEXT < ArraySize(azType) ); |
| 89611 | | - testcase( pCol->affinity==SQLITE_AFF_TEXT ); |
| 89963 | + assert( pCol->affinity-SQLITE_AFF_NONE >= 0 ); |
| 89964 | + assert( pCol->affinity-SQLITE_AFF_NONE < ArraySize(azType) ); |
| 89612 | 89965 | testcase( pCol->affinity==SQLITE_AFF_NONE ); |
| 89966 | + testcase( pCol->affinity==SQLITE_AFF_TEXT ); |
| 89613 | 89967 | testcase( pCol->affinity==SQLITE_AFF_NUMERIC ); |
| 89614 | 89968 | testcase( pCol->affinity==SQLITE_AFF_INTEGER ); |
| 89615 | 89969 | testcase( pCol->affinity==SQLITE_AFF_REAL ); |
| 89616 | 89970 | |
| 89617 | | - zType = azType[pCol->affinity - SQLITE_AFF_TEXT]; |
| 89971 | + zType = azType[pCol->affinity - SQLITE_AFF_NONE]; |
| 89618 | 89972 | len = sqlite3Strlen30(zType); |
| 89619 | 89973 | assert( pCol->affinity==SQLITE_AFF_NONE |
| 89620 | 89974 | || pCol->affinity==sqlite3AffinityType(zType, 0) ); |
| 89621 | 89975 | memcpy(&zStmt[k], zType, len); |
| 89622 | 89976 | k += len; |
| | @@ -89696,11 +90050,11 @@ |
| 89696 | 90050 | ** |
| 89697 | 90051 | ** (1) Convert the OP_CreateTable into an OP_CreateIndex. There is |
| 89698 | 90052 | ** no rowid btree for a WITHOUT ROWID. Instead, the canonical |
| 89699 | 90053 | ** data storage is a covering index btree. |
| 89700 | 90054 | ** (2) Bypass the creation of the sqlite_master table entry |
| 89701 | | -** for the PRIMARY KEY as the the primary key index is now |
| 90055 | +** for the PRIMARY KEY as the primary key index is now |
| 89702 | 90056 | ** identified by the sqlite_master table entry of the table itself. |
| 89703 | 90057 | ** (3) Set the Index.tnum of the PRIMARY KEY Index object in the |
| 89704 | 90058 | ** schema to the rootpage from the main table. |
| 89705 | 90059 | ** (4) Set all columns of the PRIMARY KEY schema object to be NOT NULL. |
| 89706 | 90060 | ** (5) Add all table columns to the PRIMARY KEY Index object |
| | @@ -89717,11 +90071,11 @@ |
| 89717 | 90071 | int i, j; |
| 89718 | 90072 | sqlite3 *db = pParse->db; |
| 89719 | 90073 | Vdbe *v = pParse->pVdbe; |
| 89720 | 90074 | |
| 89721 | 90075 | /* Convert the OP_CreateTable opcode that would normally create the |
| 89722 | | - ** root-page for the table into a OP_CreateIndex opcode. The index |
| 90076 | + ** root-page for the table into an OP_CreateIndex opcode. The index |
| 89723 | 90077 | ** created will become the PRIMARY KEY index. |
| 89724 | 90078 | */ |
| 89725 | 90079 | if( pParse->addrCrTab ){ |
| 89726 | 90080 | assert( v ); |
| 89727 | 90081 | sqlite3VdbeGetOp(v, pParse->addrCrTab)->opcode = OP_CreateIndex; |
| | @@ -90129,11 +90483,11 @@ |
| 90129 | 90483 | Table *pSelTab; /* A fake table from which we get the result set */ |
| 90130 | 90484 | Select *pSel; /* Copy of the SELECT that implements the view */ |
| 90131 | 90485 | int nErr = 0; /* Number of errors encountered */ |
| 90132 | 90486 | int n; /* Temporarily holds the number of cursors assigned */ |
| 90133 | 90487 | sqlite3 *db = pParse->db; /* Database connection for malloc errors */ |
| 90134 | | - int (*xAuth)(void*,int,const char*,const char*,const char*,const char*); |
| 90488 | + sqlite3_xauth xAuth; /* Saved xAuth pointer */ |
| 90135 | 90489 | |
| 90136 | 90490 | assert( pTable ); |
| 90137 | 90491 | |
| 90138 | 90492 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 90139 | 90493 | if( sqlite3VtabCallConnect(pParse, pTable) ){ |
| | @@ -90731,11 +91085,11 @@ |
| 90731 | 91085 | int addr2; /* Address to jump to for next iteration */ |
| 90732 | 91086 | int tnum; /* Root page of index */ |
| 90733 | 91087 | int iPartIdxLabel; /* Jump to this label to skip a row */ |
| 90734 | 91088 | Vdbe *v; /* Generate code into this virtual machine */ |
| 90735 | 91089 | KeyInfo *pKey; /* KeyInfo for index */ |
| 90736 | | - int regRecord; /* Register holding assemblied index record */ |
| 91090 | + int regRecord; /* Register holding assembled index record */ |
| 90737 | 91091 | sqlite3 *db = pParse->db; /* The database connection */ |
| 90738 | 91092 | int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema); |
| 90739 | 91093 | |
| 90740 | 91094 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 90741 | 91095 | if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0, |
| | @@ -90944,10 +91298,14 @@ |
| 90944 | 91298 | pDb = &db->aDb[iDb]; |
| 90945 | 91299 | |
| 90946 | 91300 | assert( pTab!=0 ); |
| 90947 | 91301 | assert( pParse->nErr==0 ); |
| 90948 | 91302 | if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 |
| 91303 | + && db->init.busy==0 |
| 91304 | +#if SQLITE_USER_AUTHENTICATION |
| 91305 | + && sqlite3UserAuthTable(pTab->zName)==0 |
| 91306 | +#endif |
| 90949 | 91307 | && sqlite3StrNICmp(&pTab->zName[7],"altertab_",9)!=0 ){ |
| 90950 | 91308 | sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName); |
| 90951 | 91309 | goto exit_create_index; |
| 90952 | 91310 | } |
| 90953 | 91311 | #ifndef SQLITE_OMIT_VIEW |
| | @@ -91331,11 +91689,11 @@ |
| 91331 | 91689 | |
| 91332 | 91690 | /* |
| 91333 | 91691 | ** Fill the Index.aiRowEst[] array with default information - information |
| 91334 | 91692 | ** to be used when we have not run the ANALYZE command. |
| 91335 | 91693 | ** |
| 91336 | | -** aiRowEst[0] is suppose to contain the number of elements in the index. |
| 91694 | +** aiRowEst[0] is supposed to contain the number of elements in the index. |
| 91337 | 91695 | ** Since we do not know, guess 1 million. aiRowEst[1] is an estimate of the |
| 91338 | 91696 | ** number of rows in the table that match any particular value of the |
| 91339 | 91697 | ** first column of the index. aiRowEst[2] is an estimate of the number |
| 91340 | 91698 | ** of rows that match any particular combination of the first 2 columns |
| 91341 | 91699 | ** of the index. And so forth. It must always be the case that |
| | @@ -91710,11 +92068,11 @@ |
| 91710 | 92068 | ** end of a growing FROM clause. The "p" parameter is the part of |
| 91711 | 92069 | ** the FROM clause that has already been constructed. "p" is NULL |
| 91712 | 92070 | ** if this is the first term of the FROM clause. pTable and pDatabase |
| 91713 | 92071 | ** are the name of the table and database named in the FROM clause term. |
| 91714 | 92072 | ** pDatabase is NULL if the database name qualifier is missing - the |
| 91715 | | -** usual case. If the term has a alias, then pAlias points to the |
| 92073 | +** usual case. If the term has an alias, then pAlias points to the |
| 91716 | 92074 | ** alias token. If the term is a subquery, then pSubquery is the |
| 91717 | 92075 | ** SELECT statement that the subquery encodes. The pTable and |
| 91718 | 92076 | ** pDatabase parameters are NULL for subqueries. The pOn and pUsing |
| 91719 | 92077 | ** parameters are the content of the ON and USING clauses. |
| 91720 | 92078 | ** |
| | @@ -92473,11 +92831,11 @@ |
| 92473 | 92831 | ** specified by zName and nName is not found and parameter 'create' is |
| 92474 | 92832 | ** true, then create a new entry. Otherwise return NULL. |
| 92475 | 92833 | ** |
| 92476 | 92834 | ** Each pointer stored in the sqlite3.aCollSeq hash table contains an |
| 92477 | 92835 | ** array of three CollSeq structures. The first is the collation sequence |
| 92478 | | -** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be. |
| 92836 | +** preferred for UTF-8, the second UTF-16le, and the third UTF-16be. |
| 92479 | 92837 | ** |
| 92480 | 92838 | ** Stored immediately after the three collation sequences is a copy of |
| 92481 | 92839 | ** the collation sequence name. A pointer to this string is stored in |
| 92482 | 92840 | ** each collation sequence structure. |
| 92483 | 92841 | */ |
| | @@ -92900,11 +93258,11 @@ |
| 92900 | 93258 | */ |
| 92901 | 93259 | SQLITE_PRIVATE void sqlite3MaterializeView( |
| 92902 | 93260 | Parse *pParse, /* Parsing context */ |
| 92903 | 93261 | Table *pView, /* View definition */ |
| 92904 | 93262 | Expr *pWhere, /* Optional WHERE clause to be added */ |
| 92905 | | - int iCur /* Cursor number for ephemerial table */ |
| 93263 | + int iCur /* Cursor number for ephemeral table */ |
| 92906 | 93264 | ){ |
| 92907 | 93265 | SelectDest dest; |
| 92908 | 93266 | Select *pSel; |
| 92909 | 93267 | SrcList *pFrom; |
| 92910 | 93268 | sqlite3 *db = pParse->db; |
| | @@ -93058,11 +93416,11 @@ |
| 93058 | 93416 | int iEphCur = 0; /* Ephemeral table holding all primary key values */ |
| 93059 | 93417 | int iRowSet = 0; /* Register for rowset of rows to delete */ |
| 93060 | 93418 | int addrBypass = 0; /* Address of jump over the delete logic */ |
| 93061 | 93419 | int addrLoop = 0; /* Top of the delete loop */ |
| 93062 | 93420 | int addrDelete = 0; /* Jump directly to the delete logic */ |
| 93063 | | - int addrEphOpen = 0; /* Instruction to open the Ephermeral table */ |
| 93421 | + int addrEphOpen = 0; /* Instruction to open the Ephemeral table */ |
| 93064 | 93422 | |
| 93065 | 93423 | #ifndef SQLITE_OMIT_TRIGGER |
| 93066 | 93424 | int isView; /* True if attempting to delete from a view */ |
| 93067 | 93425 | Trigger *pTrigger; /* List of table triggers, if required */ |
| 93068 | 93426 | #endif |
| | @@ -93138,11 +93496,11 @@ |
| 93138 | 93496 | } |
| 93139 | 93497 | if( pParse->nested==0 ) sqlite3VdbeCountChanges(v); |
| 93140 | 93498 | sqlite3BeginWriteOperation(pParse, 1, iDb); |
| 93141 | 93499 | |
| 93142 | 93500 | /* If we are trying to delete from a view, realize that view into |
| 93143 | | - ** a ephemeral table. |
| 93501 | + ** an ephemeral table. |
| 93144 | 93502 | */ |
| 93145 | 93503 | #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) |
| 93146 | 93504 | if( isView ){ |
| 93147 | 93505 | sqlite3MaterializeView(pParse, pTab, pWhere, iTabCur); |
| 93148 | 93506 | iDataCur = iIdxCur = iTabCur; |
| | @@ -93192,11 +93550,11 @@ |
| 93192 | 93550 | pPk = 0; |
| 93193 | 93551 | nPk = 1; |
| 93194 | 93552 | iRowSet = ++pParse->nMem; |
| 93195 | 93553 | sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet); |
| 93196 | 93554 | }else{ |
| 93197 | | - /* For a WITHOUT ROWID table, create an ephermeral table used to |
| 93555 | + /* For a WITHOUT ROWID table, create an ephemeral table used to |
| 93198 | 93556 | ** hold all primary keys for rows to be deleted. */ |
| 93199 | 93557 | pPk = sqlite3PrimaryKeyIndex(pTab); |
| 93200 | 93558 | assert( pPk!=0 ); |
| 93201 | 93559 | nPk = pPk->nKeyCol; |
| 93202 | 93560 | iPk = pParse->nMem+1; |
| | @@ -93367,11 +93725,11 @@ |
| 93367 | 93725 | sqlite3ExprDelete(db, pWhere); |
| 93368 | 93726 | sqlite3DbFree(db, aToOpen); |
| 93369 | 93727 | return; |
| 93370 | 93728 | } |
| 93371 | 93729 | /* Make sure "isView" and other macros defined above are undefined. Otherwise |
| 93372 | | -** thely may interfere with compilation of other functions in this file |
| 93730 | +** they may interfere with compilation of other functions in this file |
| 93373 | 93731 | ** (or in another file, if this file becomes part of the amalgamation). */ |
| 93374 | 93732 | #ifdef isView |
| 93375 | 93733 | #undef isView |
| 93376 | 93734 | #endif |
| 93377 | 93735 | #ifdef pTrigger |
| | @@ -93661,11 +94019,11 @@ |
| 93661 | 94019 | ** May you do good and not evil. |
| 93662 | 94020 | ** May you find forgiveness for yourself and forgive others. |
| 93663 | 94021 | ** May you share freely, never taking more than you give. |
| 93664 | 94022 | ** |
| 93665 | 94023 | ************************************************************************* |
| 93666 | | -** This file contains the C-language implementions for many of the SQL |
| 94024 | +** This file contains the C-language implementations for many of the SQL |
| 93667 | 94025 | ** functions of SQLite. (Some function, and in particular the date and |
| 93668 | 94026 | ** time functions, are implemented separately.) |
| 93669 | 94027 | */ |
| 93670 | 94028 | /* #include <stdlib.h> */ |
| 93671 | 94029 | /* #include <assert.h> */ |
| | @@ -93975,17 +94333,18 @@ |
| 93975 | 94333 | p1--; |
| 93976 | 94334 | } |
| 93977 | 94335 | for(z2=z; *z2 && p2; p2--){ |
| 93978 | 94336 | SQLITE_SKIP_UTF8(z2); |
| 93979 | 94337 | } |
| 93980 | | - sqlite3_result_text(context, (char*)z, (int)(z2-z), SQLITE_TRANSIENT); |
| 94338 | + sqlite3_result_text64(context, (char*)z, z2-z, SQLITE_TRANSIENT, |
| 94339 | + SQLITE_UTF8); |
| 93981 | 94340 | }else{ |
| 93982 | 94341 | if( p1+p2>len ){ |
| 93983 | 94342 | p2 = len-p1; |
| 93984 | 94343 | if( p2<0 ) p2 = 0; |
| 93985 | 94344 | } |
| 93986 | | - sqlite3_result_blob(context, (char*)&z[p1], (int)p2, SQLITE_TRANSIENT); |
| 94345 | + sqlite3_result_blob64(context, (char*)&z[p1], (u64)p2, SQLITE_TRANSIENT); |
| 93987 | 94346 | } |
| 93988 | 94347 | } |
| 93989 | 94348 | |
| 93990 | 94349 | /* |
| 93991 | 94350 | ** Implementation of the round() function |
| | @@ -94040,11 +94399,11 @@ |
| 94040 | 94399 | testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH]+1 ); |
| 94041 | 94400 | if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 94042 | 94401 | sqlite3_result_error_toobig(context); |
| 94043 | 94402 | z = 0; |
| 94044 | 94403 | }else{ |
| 94045 | | - z = sqlite3Malloc((int)nByte); |
| 94404 | + z = sqlite3Malloc(nByte); |
| 94046 | 94405 | if( !z ){ |
| 94047 | 94406 | sqlite3_result_error_nomem(context); |
| 94048 | 94407 | } |
| 94049 | 94408 | } |
| 94050 | 94409 | return z; |
| | @@ -94691,11 +95050,11 @@ |
| 94691 | 95050 | *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); |
| 94692 | 95051 | *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); |
| 94693 | 95052 | *zOut++ = 0x80 + (u8)(c & 0x3F); |
| 94694 | 95053 | } \ |
| 94695 | 95054 | } |
| 94696 | | - sqlite3_result_text(context, (char*)z, (int)(zOut-z), sqlite3_free); |
| 95055 | + sqlite3_result_text64(context, (char*)z, zOut-z, sqlite3_free, SQLITE_UTF8); |
| 94697 | 95056 | } |
| 94698 | 95057 | |
| 94699 | 95058 | /* |
| 94700 | 95059 | ** The hex() function. Interpret the argument as a blob. Return |
| 94701 | 95060 | ** a hexadecimal rendering as text. |
| | @@ -95141,10 +95500,11 @@ |
| 95141 | 95500 | sqlite3VdbeMemCopy(pBest, pArg); |
| 95142 | 95501 | }else{ |
| 95143 | 95502 | sqlite3SkipAccumulatorLoad(context); |
| 95144 | 95503 | } |
| 95145 | 95504 | }else{ |
| 95505 | + pBest->db = sqlite3_context_db_handle(context); |
| 95146 | 95506 | sqlite3VdbeMemCopy(pBest, pArg); |
| 95147 | 95507 | } |
| 95148 | 95508 | } |
| 95149 | 95509 | static void minMaxFinalize(sqlite3_context *context){ |
| 95150 | 95510 | sqlite3_value *pRes; |
| | @@ -95288,11 +95648,11 @@ |
| 95288 | 95648 | *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0; |
| 95289 | 95649 | return 1; |
| 95290 | 95650 | } |
| 95291 | 95651 | |
| 95292 | 95652 | /* |
| 95293 | | -** All all of the FuncDef structures in the aBuiltinFunc[] array above |
| 95653 | +** All of the FuncDef structures in the aBuiltinFunc[] array above |
| 95294 | 95654 | ** to the global function hash table. This occurs at start-time (as |
| 95295 | 95655 | ** a consequence of calling sqlite3_initialize()). |
| 95296 | 95656 | ** |
| 95297 | 95657 | ** After this routine runs |
| 95298 | 95658 | */ |
| | @@ -95312,14 +95672,16 @@ |
| 95312 | 95672 | FUNCTION(rtrim, 2, 2, 0, trimFunc ), |
| 95313 | 95673 | FUNCTION(trim, 1, 3, 0, trimFunc ), |
| 95314 | 95674 | FUNCTION(trim, 2, 3, 0, trimFunc ), |
| 95315 | 95675 | FUNCTION(min, -1, 0, 1, minmaxFunc ), |
| 95316 | 95676 | FUNCTION(min, 0, 0, 1, 0 ), |
| 95317 | | - AGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize ), |
| 95677 | + AGGREGATE2(min, 1, 0, 1, minmaxStep, minMaxFinalize, |
| 95678 | + SQLITE_FUNC_MINMAX ), |
| 95318 | 95679 | FUNCTION(max, -1, 1, 1, minmaxFunc ), |
| 95319 | 95680 | FUNCTION(max, 0, 1, 1, 0 ), |
| 95320 | | - AGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize ), |
| 95681 | + AGGREGATE2(max, 1, 1, 1, minmaxStep, minMaxFinalize, |
| 95682 | + SQLITE_FUNC_MINMAX ), |
| 95321 | 95683 | FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), |
| 95322 | 95684 | FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), |
| 95323 | 95685 | FUNCTION(instr, 2, 0, 0, instrFunc ), |
| 95324 | 95686 | FUNCTION(substr, 2, 0, 0, substrFunc ), |
| 95325 | 95687 | FUNCTION(substr, 3, 0, 0, substrFunc ), |
| | @@ -95345,10 +95707,13 @@ |
| 95345 | 95707 | VFUNCTION(randomblob, 1, 0, 0, randomBlob ), |
| 95346 | 95708 | FUNCTION(nullif, 2, 0, 1, nullifFunc ), |
| 95347 | 95709 | FUNCTION(sqlite_version, 0, 0, 0, versionFunc ), |
| 95348 | 95710 | FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), |
| 95349 | 95711 | FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ), |
| 95712 | +#if SQLITE_USER_AUTHENTICATION |
| 95713 | + FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ), |
| 95714 | +#endif |
| 95350 | 95715 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 95351 | 95716 | FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ), |
| 95352 | 95717 | FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), |
| 95353 | 95718 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 95354 | 95719 | FUNCTION(quote, 1, 0, 0, quoteFunc ), |
| | @@ -95365,12 +95730,12 @@ |
| 95365 | 95730 | FUNCTION(load_extension, 2, 0, 0, loadExt ), |
| 95366 | 95731 | #endif |
| 95367 | 95732 | AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ), |
| 95368 | 95733 | AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ), |
| 95369 | 95734 | AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ), |
| 95370 | | - /* AGGREGATE(count, 0, 0, 0, countStep, countFinalize ), */ |
| 95371 | | - {0,SQLITE_UTF8|SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0}, |
| 95735 | + AGGREGATE2(count, 0, 0, 0, countStep, countFinalize, |
| 95736 | + SQLITE_FUNC_COUNT ), |
| 95372 | 95737 | AGGREGATE(count, 1, 0, 0, countStep, countFinalize ), |
| 95373 | 95738 | AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize), |
| 95374 | 95739 | AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize), |
| 95375 | 95740 | |
| 95376 | 95741 | LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE), |
| | @@ -95573,11 +95938,11 @@ |
| 95573 | 95938 | ** foreign key definition, and the parent table does not have a |
| 95574 | 95939 | ** PRIMARY KEY, or |
| 95575 | 95940 | ** |
| 95576 | 95941 | ** 4) No parent key columns were provided explicitly as part of the |
| 95577 | 95942 | ** foreign key definition, and the PRIMARY KEY of the parent table |
| 95578 | | -** consists of a a different number of columns to the child key in |
| 95943 | +** consists of a different number of columns to the child key in |
| 95579 | 95944 | ** the child table. |
| 95580 | 95945 | ** |
| 95581 | 95946 | ** then non-zero is returned, and a "foreign key mismatch" error loaded |
| 95582 | 95947 | ** into pParse. If an OOM error occurs, non-zero is returned and the |
| 95583 | 95948 | ** pParse->db->mallocFailed flag is set. |
| | @@ -96820,17 +97185,17 @@ |
| 96820 | 97185 | ** pIdx. A column affinity string has one character for each column in |
| 96821 | 97186 | ** the table, according to the affinity of the column: |
| 96822 | 97187 | ** |
| 96823 | 97188 | ** Character Column affinity |
| 96824 | 97189 | ** ------------------------------ |
| 96825 | | -** 'a' TEXT |
| 96826 | | -** 'b' NONE |
| 96827 | | -** 'c' NUMERIC |
| 96828 | | -** 'd' INTEGER |
| 96829 | | -** 'e' REAL |
| 97190 | +** 'A' NONE |
| 97191 | +** 'B' TEXT |
| 97192 | +** 'C' NUMERIC |
| 97193 | +** 'D' INTEGER |
| 97194 | +** 'F' REAL |
| 96830 | 97195 | ** |
| 96831 | | -** An extra 'd' is appended to the end of the string to cover the |
| 97196 | +** An extra 'D' is appended to the end of the string to cover the |
| 96832 | 97197 | ** rowid that appears as the last column in every index. |
| 96833 | 97198 | ** |
| 96834 | 97199 | ** Memory for the buffer containing the column index affinity string |
| 96835 | 97200 | ** is managed along with the rest of the Index structure. It will be |
| 96836 | 97201 | ** released when sqlite3DeleteIndex() is called. |
| | @@ -96875,15 +97240,15 @@ |
| 96875 | 97240 | ** |
| 96876 | 97241 | ** A column affinity string has one character per column: |
| 96877 | 97242 | ** |
| 96878 | 97243 | ** Character Column affinity |
| 96879 | 97244 | ** ------------------------------ |
| 96880 | | -** 'a' TEXT |
| 96881 | | -** 'b' NONE |
| 96882 | | -** 'c' NUMERIC |
| 96883 | | -** 'd' INTEGER |
| 96884 | | -** 'e' REAL |
| 97245 | +** 'A' NONE |
| 97246 | +** 'B' TEXT |
| 97247 | +** 'C' NUMERIC |
| 97248 | +** 'D' INTEGER |
| 97249 | +** 'E' REAL |
| 96885 | 97250 | */ |
| 96886 | 97251 | SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){ |
| 96887 | 97252 | int i; |
| 96888 | 97253 | char *zColAff = pTab->zColAff; |
| 96889 | 97254 | if( zColAff==0 ){ |
| | @@ -97174,11 +97539,11 @@ |
| 97174 | 97539 | ** D: cleanup |
| 97175 | 97540 | ** |
| 97176 | 97541 | ** The 4th template is used if the insert statement takes its |
| 97177 | 97542 | ** values from a SELECT but the data is being inserted into a table |
| 97178 | 97543 | ** that is also read as part of the SELECT. In the third form, |
| 97179 | | -** we have to use a intermediate table to store the results of |
| 97544 | +** we have to use an intermediate table to store the results of |
| 97180 | 97545 | ** the select. The template is like this: |
| 97181 | 97546 | ** |
| 97182 | 97547 | ** X <- A |
| 97183 | 97548 | ** goto B |
| 97184 | 97549 | ** A: setup for the SELECT |
| | @@ -97339,11 +97704,11 @@ |
| 97339 | 97704 | ** sqlite_sequence table and store it in memory cell regAutoinc. |
| 97340 | 97705 | */ |
| 97341 | 97706 | regAutoinc = autoIncBegin(pParse, iDb, pTab); |
| 97342 | 97707 | |
| 97343 | 97708 | /* Allocate registers for holding the rowid of the new row, |
| 97344 | | - ** the content of the new row, and the assemblied row record. |
| 97709 | + ** the content of the new row, and the assembled row record. |
| 97345 | 97710 | */ |
| 97346 | 97711 | regRowid = regIns = pParse->nMem+1; |
| 97347 | 97712 | pParse->nMem += pTab->nCol + 1; |
| 97348 | 97713 | if( IsVirtual(pTab) ){ |
| 97349 | 97714 | regRowid++; |
| | @@ -97791,11 +98156,11 @@ |
| 97791 | 98156 | sqlite3IdListDelete(db, pColumn); |
| 97792 | 98157 | sqlite3DbFree(db, aRegIdx); |
| 97793 | 98158 | } |
| 97794 | 98159 | |
| 97795 | 98160 | /* Make sure "isView" and other macros defined above are undefined. Otherwise |
| 97796 | | -** thely may interfere with compilation of other functions in this file |
| 98161 | +** they may interfere with compilation of other functions in this file |
| 97797 | 98162 | ** (or in another file, if this file becomes part of the amalgamation). */ |
| 97798 | 98163 | #ifdef isView |
| 97799 | 98164 | #undef isView |
| 97800 | 98165 | #endif |
| 97801 | 98166 | #ifdef pTrigger |
| | @@ -97907,11 +98272,11 @@ |
| 97907 | 98272 | sqlite3 *db; /* Database connection */ |
| 97908 | 98273 | int i; /* loop counter */ |
| 97909 | 98274 | int ix; /* Index loop counter */ |
| 97910 | 98275 | int nCol; /* Number of columns */ |
| 97911 | 98276 | int onError; /* Conflict resolution strategy */ |
| 97912 | | - int j1; /* Addresss of jump instruction */ |
| 98277 | + int j1; /* Address of jump instruction */ |
| 97913 | 98278 | int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */ |
| 97914 | 98279 | int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */ |
| 97915 | 98280 | int ipkTop = 0; /* Top of the rowid change constraint check */ |
| 97916 | 98281 | int ipkBottom = 0; /* Bottom of the rowid change constraint check */ |
| 97917 | 98282 | u8 isUpdate; /* True if this is an UPDATE operation */ |
| | @@ -98311,11 +98676,11 @@ |
| 98311 | 98676 | ){ |
| 98312 | 98677 | Vdbe *v; /* Prepared statements under construction */ |
| 98313 | 98678 | Index *pIdx; /* An index being inserted or updated */ |
| 98314 | 98679 | u8 pik_flags; /* flag values passed to the btree insert */ |
| 98315 | 98680 | int regData; /* Content registers (after the rowid) */ |
| 98316 | | - int regRec; /* Register holding assemblied record for the table */ |
| 98681 | + int regRec; /* Register holding assembled record for the table */ |
| 98317 | 98682 | int i; /* Loop counter */ |
| 98318 | 98683 | u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */ |
| 98319 | 98684 | |
| 98320 | 98685 | v = sqlite3GetVdbe(pParse); |
| 98321 | 98686 | assert( v!=0 ); |
| | @@ -98436,11 +98801,11 @@ |
| 98436 | 98801 | #ifdef SQLITE_TEST |
| 98437 | 98802 | /* |
| 98438 | 98803 | ** The following global variable is incremented whenever the |
| 98439 | 98804 | ** transfer optimization is used. This is used for testing |
| 98440 | 98805 | ** purposes only - to make sure the transfer optimization really |
| 98441 | | -** is happening when it is suppose to. |
| 98806 | +** is happening when it is supposed to. |
| 98442 | 98807 | */ |
| 98443 | 98808 | SQLITE_API int sqlite3_xferopt_count; |
| 98444 | 98809 | #endif /* SQLITE_TEST */ |
| 98445 | 98810 | |
| 98446 | 98811 | |
| | @@ -98503,11 +98868,11 @@ |
| 98503 | 98868 | ** Attempt the transfer optimization on INSERTs of the form |
| 98504 | 98869 | ** |
| 98505 | 98870 | ** INSERT INTO tab1 SELECT * FROM tab2; |
| 98506 | 98871 | ** |
| 98507 | 98872 | ** The xfer optimization transfers raw records from tab2 over to tab1. |
| 98508 | | -** Columns are not decoded and reassemblied, which greatly improves |
| 98873 | +** Columns are not decoded and reassembled, which greatly improves |
| 98509 | 98874 | ** performance. Raw index records are transferred in the same way. |
| 98510 | 98875 | ** |
| 98511 | 98876 | ** The xfer optimization is only attempted if tab1 and tab2 are compatible. |
| 98512 | 98877 | ** There are lots of rules for determining compatibility - see comments |
| 98513 | 98878 | ** embedded in the code for details. |
| | @@ -98912,11 +99277,11 @@ |
| 98912 | 99277 | exec_out: |
| 98913 | 99278 | if( pStmt ) sqlite3VdbeFinalize((Vdbe *)pStmt); |
| 98914 | 99279 | sqlite3DbFree(db, azCols); |
| 98915 | 99280 | |
| 98916 | 99281 | rc = sqlite3ApiExit(db, rc); |
| 98917 | | - if( rc!=SQLITE_OK && ALWAYS(rc==sqlite3_errcode(db)) && pzErrMsg ){ |
| 99282 | + if( rc!=SQLITE_OK && pzErrMsg ){ |
| 98918 | 99283 | int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db)); |
| 98919 | 99284 | *pzErrMsg = sqlite3Malloc(nErrMsg); |
| 98920 | 99285 | if( *pzErrMsg ){ |
| 98921 | 99286 | memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg); |
| 98922 | 99287 | }else{ |
| | @@ -98981,11 +99346,11 @@ |
| 98981 | 99346 | ** routines. |
| 98982 | 99347 | ** |
| 98983 | 99348 | ** WARNING: In order to maintain backwards compatibility, add new |
| 98984 | 99349 | ** interfaces to the end of this structure only. If you insert new |
| 98985 | 99350 | ** interfaces in the middle of this structure, then older different |
| 98986 | | -** versions of SQLite will not be able to load each others' shared |
| 99351 | +** versions of SQLite will not be able to load each other's shared |
| 98987 | 99352 | ** libraries! |
| 98988 | 99353 | */ |
| 98989 | 99354 | struct sqlite3_api_routines { |
| 98990 | 99355 | void * (*aggregate_context)(sqlite3_context*,int nBytes); |
| 98991 | 99356 | int (*aggregate_count)(sqlite3_context*); |
| | @@ -99203,15 +99568,32 @@ |
| 99203 | 99568 | int (*uri_boolean)(const char*,const char*,int); |
| 99204 | 99569 | sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64); |
| 99205 | 99570 | const char *(*uri_parameter)(const char*,const char*); |
| 99206 | 99571 | char *(*vsnprintf)(int,char*,const char*,va_list); |
| 99207 | 99572 | int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*); |
| 99573 | + /* Version 3.8.7 and later */ |
| 99574 | + int (*auto_extension)(void(*)(void)); |
| 99575 | + int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64, |
| 99576 | + void(*)(void*)); |
| 99577 | + int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64, |
| 99578 | + void(*)(void*),unsigned char); |
| 99579 | + int (*cancel_auto_extension)(void(*)(void)); |
| 99580 | + int (*load_extension)(sqlite3*,const char*,const char*,char**); |
| 99581 | + void *(*malloc64)(sqlite3_uint64); |
| 99582 | + sqlite3_uint64 (*msize)(void*); |
| 99583 | + void *(*realloc64)(void*,sqlite3_uint64); |
| 99584 | + void (*reset_auto_extension)(void); |
| 99585 | + void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64, |
| 99586 | + void(*)(void*)); |
| 99587 | + void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64, |
| 99588 | + void(*)(void*), unsigned char); |
| 99589 | + int (*strglob)(const char*,const char*); |
| 99208 | 99590 | }; |
| 99209 | 99591 | |
| 99210 | 99592 | /* |
| 99211 | 99593 | ** The following macros redefine the API routines so that they are |
| 99212 | | -** redirected throught the global sqlite3_api structure. |
| 99594 | +** redirected through the global sqlite3_api structure. |
| 99213 | 99595 | ** |
| 99214 | 99596 | ** This header file is also used by the loadext.c source file |
| 99215 | 99597 | ** (part of the main SQLite library - not an extension) so that |
| 99216 | 99598 | ** it can get access to the sqlite3_api_routines structure |
| 99217 | 99599 | ** definition. But the main library does not want to redefine |
| | @@ -99420,10 +99802,23 @@ |
| 99420 | 99802 | #define sqlite3_uri_boolean sqlite3_api->uri_boolean |
| 99421 | 99803 | #define sqlite3_uri_int64 sqlite3_api->uri_int64 |
| 99422 | 99804 | #define sqlite3_uri_parameter sqlite3_api->uri_parameter |
| 99423 | 99805 | #define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf |
| 99424 | 99806 | #define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2 |
| 99807 | +/* Version 3.8.7 and later */ |
| 99808 | +#define sqlite3_auto_extension sqlite3_api->auto_extension |
| 99809 | +#define sqlite3_bind_blob64 sqlite3_api->bind_blob64 |
| 99810 | +#define sqlite3_bind_text64 sqlite3_api->bind_text64 |
| 99811 | +#define sqlite3_cancel_auto_extension sqlite3_api->cancel_auto_extension |
| 99812 | +#define sqlite3_load_extension sqlite3_api->load_extension |
| 99813 | +#define sqlite3_malloc64 sqlite3_api->malloc64 |
| 99814 | +#define sqlite3_msize sqlite3_api->msize |
| 99815 | +#define sqlite3_realloc64 sqlite3_api->realloc64 |
| 99816 | +#define sqlite3_reset_auto_extension sqlite3_api->reset_auto_extension |
| 99817 | +#define sqlite3_result_blob64 sqlite3_api->result_blob64 |
| 99818 | +#define sqlite3_result_text64 sqlite3_api->result_text64 |
| 99819 | +#define sqlite3_strglob sqlite3_api->strglob |
| 99425 | 99820 | #endif /* SQLITE_CORE */ |
| 99426 | 99821 | |
| 99427 | 99822 | #ifndef SQLITE_CORE |
| 99428 | 99823 | /* This case when the file really is being compiled as a loadable |
| 99429 | 99824 | ** extension */ |
| | @@ -99813,11 +100208,24 @@ |
| 99813 | 100208 | sqlite3_stricmp, |
| 99814 | 100209 | sqlite3_uri_boolean, |
| 99815 | 100210 | sqlite3_uri_int64, |
| 99816 | 100211 | sqlite3_uri_parameter, |
| 99817 | 100212 | sqlite3_vsnprintf, |
| 99818 | | - sqlite3_wal_checkpoint_v2 |
| 100213 | + sqlite3_wal_checkpoint_v2, |
| 100214 | + /* Version 3.8.7 and later */ |
| 100215 | + sqlite3_auto_extension, |
| 100216 | + sqlite3_bind_blob64, |
| 100217 | + sqlite3_bind_text64, |
| 100218 | + sqlite3_cancel_auto_extension, |
| 100219 | + sqlite3_load_extension, |
| 100220 | + sqlite3_malloc64, |
| 100221 | + sqlite3_msize, |
| 100222 | + sqlite3_realloc64, |
| 100223 | + sqlite3_reset_auto_extension, |
| 100224 | + sqlite3_result_blob64, |
| 100225 | + sqlite3_result_text64, |
| 100226 | + sqlite3_strglob |
| 99819 | 100227 | }; |
| 99820 | 100228 | |
| 99821 | 100229 | /* |
| 99822 | 100230 | ** Attempt to load an SQLite extension library contained in the file |
| 99823 | 100231 | ** zFile. The entry point is zProc. zProc may be 0 in which case a |
| | @@ -101580,10 +101988,16 @@ |
| 101580 | 101988 | if( db->autoCommit==0 ){ |
| 101581 | 101989 | /* Foreign key support may not be enabled or disabled while not |
| 101582 | 101990 | ** in auto-commit mode. */ |
| 101583 | 101991 | mask &= ~(SQLITE_ForeignKeys); |
| 101584 | 101992 | } |
| 101993 | +#if SQLITE_USER_AUTHENTICATION |
| 101994 | + if( db->auth.authLevel==UAUTH_User ){ |
| 101995 | + /* Do not allow non-admin users to modify the schema arbitrarily */ |
| 101996 | + mask &= ~(SQLITE_WriteSchema); |
| 101997 | + } |
| 101998 | +#endif |
| 101585 | 101999 | |
| 101586 | 102000 | if( sqlite3GetBoolean(zRight, 0) ){ |
| 101587 | 102001 | db->flags |= mask; |
| 101588 | 102002 | }else{ |
| 101589 | 102003 | db->flags &= ~mask; |
| | @@ -102897,11 +103311,11 @@ |
| 102897 | 103311 | zSql = sqlite3MPrintf(db, |
| 102898 | 103312 | "SELECT name, rootpage, sql FROM '%q'.%s ORDER BY rowid", |
| 102899 | 103313 | db->aDb[iDb].zName, zMasterName); |
| 102900 | 103314 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 102901 | 103315 | { |
| 102902 | | - int (*xAuth)(void*,int,const char*,const char*,const char*,const char*); |
| 103316 | + sqlite3_xauth xAuth; |
| 102903 | 103317 | xAuth = db->xAuth; |
| 102904 | 103318 | db->xAuth = 0; |
| 102905 | 103319 | #endif |
| 102906 | 103320 | rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0); |
| 102907 | 103321 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| | @@ -102963,10 +103377,11 @@ |
| 102963 | 103377 | SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){ |
| 102964 | 103378 | int i, rc; |
| 102965 | 103379 | int commit_internal = !(db->flags&SQLITE_InternChanges); |
| 102966 | 103380 | |
| 102967 | 103381 | assert( sqlite3_mutex_held(db->mutex) ); |
| 103382 | + assert( db->init.busy==0 ); |
| 102968 | 103383 | rc = SQLITE_OK; |
| 102969 | 103384 | db->init.busy = 1; |
| 102970 | 103385 | for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ |
| 102971 | 103386 | if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue; |
| 102972 | 103387 | rc = sqlite3InitOne(db, i, pzErrMsg); |
| | @@ -102978,12 +103393,12 @@ |
| 102978 | 103393 | /* Once all the other databases have been initialized, load the schema |
| 102979 | 103394 | ** for the TEMP database. This is loaded last, as the TEMP database |
| 102980 | 103395 | ** schema may contain references to objects in other databases. |
| 102981 | 103396 | */ |
| 102982 | 103397 | #ifndef SQLITE_OMIT_TEMPDB |
| 102983 | | - if( rc==SQLITE_OK && ALWAYS(db->nDb>1) |
| 102984 | | - && !DbHasProperty(db, 1, DB_SchemaLoaded) ){ |
| 103398 | + assert( db->nDb>1 ); |
| 103399 | + if( rc==SQLITE_OK && !DbHasProperty(db, 1, DB_SchemaLoaded) ){ |
| 102985 | 103400 | rc = sqlite3InitOne(db, 1, pzErrMsg); |
| 102986 | 103401 | if( rc ){ |
| 102987 | 103402 | sqlite3ResetOneSchema(db, 1); |
| 102988 | 103403 | } |
| 102989 | 103404 | } |
| | @@ -103944,11 +104359,11 @@ |
| 103944 | 104359 | sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, SQLITE_ECEL_DUP); |
| 103945 | 104360 | if( bSeq ){ |
| 103946 | 104361 | sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr); |
| 103947 | 104362 | } |
| 103948 | 104363 | if( nPrefixReg==0 ){ |
| 103949 | | - sqlite3VdbeAddOp3(v, OP_Move, regData, regBase+nExpr+bSeq, nData); |
| 104364 | + sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData); |
| 103950 | 104365 | } |
| 103951 | 104366 | |
| 103952 | 104367 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase+nOBSat, nBase-nOBSat, regRecord); |
| 103953 | 104368 | if( nOBSat>0 ){ |
| 103954 | 104369 | int regPrevKey; /* The first nOBSat columns of the previous row */ |
| | @@ -103980,11 +104395,11 @@ |
| 103980 | 104395 | pSort->labelBkOut = sqlite3VdbeMakeLabel(v); |
| 103981 | 104396 | pSort->regReturn = ++pParse->nMem; |
| 103982 | 104397 | sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut); |
| 103983 | 104398 | sqlite3VdbeAddOp1(v, OP_ResetSorter, pSort->iECursor); |
| 103984 | 104399 | sqlite3VdbeJumpHere(v, addrFirst); |
| 103985 | | - sqlite3VdbeAddOp3(v, OP_Move, regBase, regPrevKey, pSort->nOBSat); |
| 104400 | + sqlite3ExprCodeMove(pParse, regBase, regPrevKey, pSort->nOBSat); |
| 103986 | 104401 | sqlite3VdbeJumpHere(v, addrJmp); |
| 103987 | 104402 | } |
| 103988 | 104403 | if( pSort->sortFlags & SORTFLAG_UseSorter ){ |
| 103989 | 104404 | op = OP_SorterInsert; |
| 103990 | 104405 | }else{ |
| | @@ -104466,11 +104881,11 @@ |
| 104466 | 104881 | ** KeyInfo structure is appropriate for initializing a virtual index to |
| 104467 | 104882 | ** implement that clause. If the ExprList is the result set of a SELECT |
| 104468 | 104883 | ** then the KeyInfo structure is appropriate for initializing a virtual |
| 104469 | 104884 | ** index to implement a DISTINCT test. |
| 104470 | 104885 | ** |
| 104471 | | -** Space to hold the KeyInfo structure is obtain from malloc. The calling |
| 104886 | +** Space to hold the KeyInfo structure is obtained from malloc. The calling |
| 104472 | 104887 | ** function is responsible for seeing that this structure is eventually |
| 104473 | 104888 | ** freed. |
| 104474 | 104889 | */ |
| 104475 | 104890 | static KeyInfo *keyInfoFromExprList( |
| 104476 | 104891 | Parse *pParse, /* Parsing context */ |
| | @@ -104997,11 +105412,11 @@ |
| 104997 | 105412 | } |
| 104998 | 105413 | generateColumnTypes(pParse, pTabList, pEList); |
| 104999 | 105414 | } |
| 105000 | 105415 | |
| 105001 | 105416 | /* |
| 105002 | | -** Given a an expression list (which is really the list of expressions |
| 105417 | +** Given an expression list (which is really the list of expressions |
| 105003 | 105418 | ** that form the result set of a SELECT statement) compute appropriate |
| 105004 | 105419 | ** column names for a table that would hold the expression list. |
| 105005 | 105420 | ** |
| 105006 | 105421 | ** All column names will be unique. |
| 105007 | 105422 | ** |
| | @@ -105070,11 +105485,11 @@ |
| 105070 | 105485 | sqlite3DbFree(db, zName); |
| 105071 | 105486 | break; |
| 105072 | 105487 | } |
| 105073 | 105488 | |
| 105074 | 105489 | /* Make sure the column name is unique. If the name is not unique, |
| 105075 | | - ** append a integer to the name so that it becomes unique. |
| 105490 | + ** append an integer to the name so that it becomes unique. |
| 105076 | 105491 | */ |
| 105077 | 105492 | nName = sqlite3Strlen30(zName); |
| 105078 | 105493 | for(j=cnt=0; j<i; j++){ |
| 105079 | 105494 | if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){ |
| 105080 | 105495 | char *zNewName; |
| | @@ -106554,11 +106969,11 @@ |
| 106554 | 106969 | ** This routine attempts to rewrite queries such as the above into |
| 106555 | 106970 | ** a single flat select, like this: |
| 106556 | 106971 | ** |
| 106557 | 106972 | ** SELECT x+y AS a FROM t1 WHERE z<100 AND a>5 |
| 106558 | 106973 | ** |
| 106559 | | -** The code generated for this simpification gives the same result |
| 106974 | +** The code generated for this simplification gives the same result |
| 106560 | 106975 | ** but only has to scan the data once. And because indices might |
| 106561 | 106976 | ** exist on the table t1, a complete scan of the data might be |
| 106562 | 106977 | ** avoided. |
| 106563 | 106978 | ** |
| 106564 | 106979 | ** Flattening is only attempted if all of the following are true: |
| | @@ -106587,12 +107002,14 @@ |
| 106587 | 107002 | ** (8) The subquery does not use LIMIT or the outer query is not a join. |
| 106588 | 107003 | ** |
| 106589 | 107004 | ** (9) The subquery does not use LIMIT or the outer query does not use |
| 106590 | 107005 | ** aggregates. |
| 106591 | 107006 | ** |
| 106592 | | -** (10) The subquery does not use aggregates or the outer query does not |
| 106593 | | -** use LIMIT. |
| 107007 | +** (**) Restriction (10) was removed from the code on 2005-02-05 but we |
| 107008 | +** accidently carried the comment forward until 2014-09-15. Original |
| 107009 | +** text: "The subquery does not use aggregates or the outer query does not |
| 107010 | +** use LIMIT." |
| 106594 | 107011 | ** |
| 106595 | 107012 | ** (11) The subquery and the outer query do not both have ORDER BY clauses. |
| 106596 | 107013 | ** |
| 106597 | 107014 | ** (**) Not implemented. Subsumed into restriction (3). Was previously |
| 106598 | 107015 | ** a separate restriction deriving from ticket #350. |
| | @@ -106651,10 +107068,15 @@ |
| 106651 | 107068 | ** (23) The parent is not a recursive CTE, or the sub-query is not a |
| 106652 | 107069 | ** compound query. This restriction is because transforming the |
| 106653 | 107070 | ** parent to a compound query confuses the code that handles |
| 106654 | 107071 | ** recursive queries in multiSelect(). |
| 106655 | 107072 | ** |
| 107073 | +** (24) The subquery is not an aggregate that uses the built-in min() or |
| 107074 | +** or max() functions. (Without this restriction, a query like: |
| 107075 | +** "SELECT x FROM (SELECT max(y), x FROM t1)" would not necessarily |
| 107076 | +** return the value X for which Y was maximal.) |
| 107077 | +** |
| 106656 | 107078 | ** |
| 106657 | 107079 | ** In this routine, the "p" parameter is a pointer to the outer query. |
| 106658 | 107080 | ** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query |
| 106659 | 107081 | ** uses aggregates and subqueryIsAgg is true if the subquery uses aggregates. |
| 106660 | 107082 | ** |
| | @@ -106698,11 +107120,11 @@ |
| 106698 | 107120 | if( isAgg && subqueryIsAgg ) return 0; /* Restriction (1) */ |
| 106699 | 107121 | if( subqueryIsAgg && pSrc->nSrc>1 ) return 0; /* Restriction (2) */ |
| 106700 | 107122 | pSubSrc = pSub->pSrc; |
| 106701 | 107123 | assert( pSubSrc ); |
| 106702 | 107124 | /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants, |
| 106703 | | - ** not arbitrary expresssions, we allowed some combining of LIMIT and OFFSET |
| 107125 | + ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET |
| 106704 | 107126 | ** because they could be computed at compile-time. But when LIMIT and OFFSET |
| 106705 | 107127 | ** became arbitrary expressions, we were forced to add restrictions (13) |
| 106706 | 107128 | ** and (14). */ |
| 106707 | 107129 | if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */ |
| 106708 | 107130 | if( pSub->pOffset ) return 0; /* Restriction (14) */ |
| | @@ -106723,12 +107145,18 @@ |
| 106723 | 107145 | if( isAgg && pSub->pOrderBy ) return 0; /* Restriction (16) */ |
| 106724 | 107146 | if( pSub->pLimit && p->pWhere ) return 0; /* Restriction (19) */ |
| 106725 | 107147 | if( pSub->pLimit && (p->selFlags & SF_Distinct)!=0 ){ |
| 106726 | 107148 | return 0; /* Restriction (21) */ |
| 106727 | 107149 | } |
| 106728 | | - if( pSub->selFlags & SF_Recursive ) return 0; /* Restriction (22) */ |
| 106729 | | - if( (p->selFlags & SF_Recursive) && pSub->pPrior ) return 0; /* (23) */ |
| 107150 | + testcase( pSub->selFlags & SF_Recursive ); |
| 107151 | + testcase( pSub->selFlags & SF_MinMaxAgg ); |
| 107152 | + if( pSub->selFlags & (SF_Recursive|SF_MinMaxAgg) ){ |
| 107153 | + return 0; /* Restrictions (22) and (24) */ |
| 107154 | + } |
| 107155 | + if( (p->selFlags & SF_Recursive) && pSub->pPrior ){ |
| 107156 | + return 0; /* Restriction (23) */ |
| 107157 | + } |
| 106730 | 107158 | |
| 106731 | 107159 | /* OBSOLETE COMMENT 1: |
| 106732 | 107160 | ** Restriction 3: If the subquery is a join, make sure the subquery is |
| 106733 | 107161 | ** not used as the right operand of an outer join. Examples of why this |
| 106734 | 107162 | ** is not allowed: |
| | @@ -107084,11 +107512,11 @@ |
| 107084 | 107512 | return eRet; |
| 107085 | 107513 | } |
| 107086 | 107514 | |
| 107087 | 107515 | /* |
| 107088 | 107516 | ** The select statement passed as the first argument is an aggregate query. |
| 107089 | | -** The second argment is the associated aggregate-info object. This |
| 107517 | +** The second argument is the associated aggregate-info object. This |
| 107090 | 107518 | ** function tests if the SELECT is of the form: |
| 107091 | 107519 | ** |
| 107092 | 107520 | ** SELECT count(*) FROM <tbl> |
| 107093 | 107521 | ** |
| 107094 | 107522 | ** where table is a database table, not a sub-select or view. If the query |
| | @@ -107414,14 +107842,14 @@ |
| 107414 | 107842 | ** (2) Fill in the pTabList->a[].pTab fields in the SrcList that |
| 107415 | 107843 | ** defines FROM clause. When views appear in the FROM clause, |
| 107416 | 107844 | ** fill pTabList->a[].pSelect with a copy of the SELECT statement |
| 107417 | 107845 | ** that implements the view. A copy is made of the view's SELECT |
| 107418 | 107846 | ** statement so that we can freely modify or delete that statement |
| 107419 | | -** without worrying about messing up the presistent representation |
| 107847 | +** without worrying about messing up the persistent representation |
| 107420 | 107848 | ** of the view. |
| 107421 | 107849 | ** |
| 107422 | | -** (3) Add terms to the WHERE clause to accomodate the NATURAL keyword |
| 107850 | +** (3) Add terms to the WHERE clause to accommodate the NATURAL keyword |
| 107423 | 107851 | ** on joins and the ON and USING clause of joins. |
| 107424 | 107852 | ** |
| 107425 | 107853 | ** (4) Scan the list of columns in the result set (pEList) looking |
| 107426 | 107854 | ** for instances of the "*" operator or the TABLE.* operator. |
| 107427 | 107855 | ** If found, expand each "*" to be every column in every table |
| | @@ -108927,14 +109355,14 @@ |
| 108927 | 109355 | ** to the callback function is uses to build the result. |
| 108928 | 109356 | */ |
| 108929 | 109357 | typedef struct TabResult { |
| 108930 | 109358 | char **azResult; /* Accumulated output */ |
| 108931 | 109359 | char *zErrMsg; /* Error message text, if an error occurs */ |
| 108932 | | - int nAlloc; /* Slots allocated for azResult[] */ |
| 108933 | | - int nRow; /* Number of rows in the result */ |
| 108934 | | - int nColumn; /* Number of columns in the result */ |
| 108935 | | - int nData; /* Slots used in azResult[]. (nRow+1)*nColumn */ |
| 109360 | + u32 nAlloc; /* Slots allocated for azResult[] */ |
| 109361 | + u32 nRow; /* Number of rows in the result */ |
| 109362 | + u32 nColumn; /* Number of columns in the result */ |
| 109363 | + u32 nData; /* Slots used in azResult[]. (nRow+1)*nColumn */ |
| 108936 | 109364 | int rc; /* Return code from sqlite3_exec() */ |
| 108937 | 109365 | } TabResult; |
| 108938 | 109366 | |
| 108939 | 109367 | /* |
| 108940 | 109368 | ** This routine is called once for each row in the result table. Its job |
| | @@ -108956,11 +109384,11 @@ |
| 108956 | 109384 | need = nCol; |
| 108957 | 109385 | } |
| 108958 | 109386 | if( p->nData + need > p->nAlloc ){ |
| 108959 | 109387 | char **azNew; |
| 108960 | 109388 | p->nAlloc = p->nAlloc*2 + need; |
| 108961 | | - azNew = sqlite3_realloc( p->azResult, sizeof(char*)*p->nAlloc ); |
| 109389 | + azNew = sqlite3_realloc64( p->azResult, sizeof(char*)*p->nAlloc ); |
| 108962 | 109390 | if( azNew==0 ) goto malloc_failed; |
| 108963 | 109391 | p->azResult = azNew; |
| 108964 | 109392 | } |
| 108965 | 109393 | |
| 108966 | 109394 | /* If this is the first row, then generate an extra row containing |
| | @@ -108971,11 +109399,11 @@ |
| 108971 | 109399 | for(i=0; i<nCol; i++){ |
| 108972 | 109400 | z = sqlite3_mprintf("%s", colv[i]); |
| 108973 | 109401 | if( z==0 ) goto malloc_failed; |
| 108974 | 109402 | p->azResult[p->nData++] = z; |
| 108975 | 109403 | } |
| 108976 | | - }else if( p->nColumn!=nCol ){ |
| 109404 | + }else if( (int)p->nColumn!=nCol ){ |
| 108977 | 109405 | sqlite3_free(p->zErrMsg); |
| 108978 | 109406 | p->zErrMsg = sqlite3_mprintf( |
| 108979 | 109407 | "sqlite3_get_table() called with two or more incompatible queries" |
| 108980 | 109408 | ); |
| 108981 | 109409 | p->rc = SQLITE_ERROR; |
| | @@ -109080,11 +109508,11 @@ |
| 109080 | 109508 | |
| 109081 | 109509 | /* |
| 109082 | 109510 | ** This routine frees the space the sqlite3_get_table() malloced. |
| 109083 | 109511 | */ |
| 109084 | 109512 | SQLITE_API void sqlite3_free_table( |
| 109085 | | - char **azResult /* Result returned from from sqlite3_get_table() */ |
| 109513 | + char **azResult /* Result returned from sqlite3_get_table() */ |
| 109086 | 109514 | ){ |
| 109087 | 109515 | if( azResult ){ |
| 109088 | 109516 | int i, n; |
| 109089 | 109517 | azResult--; |
| 109090 | 109518 | assert( azResult!=0 ); |
| | @@ -109224,11 +109652,11 @@ |
| 109224 | 109652 | ** |
| 109225 | 109653 | ** CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab .... |
| 109226 | 109654 | ** ^^^^^^^^ |
| 109227 | 109655 | ** |
| 109228 | 109656 | ** To maintain backwards compatibility, ignore the database |
| 109229 | | - ** name on pTableName if we are reparsing our of SQLITE_MASTER. |
| 109657 | + ** name on pTableName if we are reparsing out of SQLITE_MASTER. |
| 109230 | 109658 | */ |
| 109231 | 109659 | if( db->init.busy && iDb!=1 ){ |
| 109232 | 109660 | sqlite3DbFree(db, pTableName->a[0].zDatabase); |
| 109233 | 109661 | pTableName->a[0].zDatabase = 0; |
| 109234 | 109662 | } |
| | @@ -110545,11 +110973,11 @@ |
| 110545 | 110973 | if( isView ){ |
| 110546 | 110974 | sqlite3AuthContextPush(pParse, &sContext, pTab->zName); |
| 110547 | 110975 | } |
| 110548 | 110976 | |
| 110549 | 110977 | /* If we are trying to update a view, realize that view into |
| 110550 | | - ** a ephemeral table. |
| 110978 | + ** an ephemeral table. |
| 110551 | 110979 | */ |
| 110552 | 110980 | #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) |
| 110553 | 110981 | if( isView ){ |
| 110554 | 110982 | sqlite3MaterializeView(pParse, pTab, pWhere, iDataCur); |
| 110555 | 110983 | } |
| | @@ -110706,11 +111134,11 @@ |
| 110706 | 111134 | sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid); |
| 110707 | 111135 | } |
| 110708 | 111136 | } |
| 110709 | 111137 | |
| 110710 | 111138 | /* Populate the array of registers beginning at regNew with the new |
| 110711 | | - ** row data. This array is used to check constaints, create the new |
| 111139 | + ** row data. This array is used to check constants, create the new |
| 110712 | 111140 | ** table and index records, and as the values for any new.* references |
| 110713 | 111141 | ** made by triggers. |
| 110714 | 111142 | ** |
| 110715 | 111143 | ** If there are one or more BEFORE triggers, then do not populate the |
| 110716 | 111144 | ** registers associated with columns that are (a) not modified by |
| | @@ -110886,11 +111314,11 @@ |
| 110886 | 111314 | sqlite3ExprListDelete(db, pChanges); |
| 110887 | 111315 | sqlite3ExprDelete(db, pWhere); |
| 110888 | 111316 | return; |
| 110889 | 111317 | } |
| 110890 | 111318 | /* Make sure "isView" and other macros defined above are undefined. Otherwise |
| 110891 | | -** thely may interfere with compilation of other functions in this file |
| 111319 | +** they may interfere with compilation of other functions in this file |
| 110892 | 111320 | ** (or in another file, if this file becomes part of the amalgamation). */ |
| 110893 | 111321 | #ifdef isView |
| 110894 | 111322 | #undef isView |
| 110895 | 111323 | #endif |
| 110896 | 111324 | #ifdef pTrigger |
| | @@ -110899,19 +111327,19 @@ |
| 110899 | 111327 | |
| 110900 | 111328 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 110901 | 111329 | /* |
| 110902 | 111330 | ** Generate code for an UPDATE of a virtual table. |
| 110903 | 111331 | ** |
| 110904 | | -** The strategy is that we create an ephemerial table that contains |
| 111332 | +** The strategy is that we create an ephemeral table that contains |
| 110905 | 111333 | ** for each row to be changed: |
| 110906 | 111334 | ** |
| 110907 | 111335 | ** (A) The original rowid of that row. |
| 110908 | 111336 | ** (B) The revised rowid for the row. (note1) |
| 110909 | 111337 | ** (C) The content of every column in the row. |
| 110910 | 111338 | ** |
| 110911 | 111339 | ** Then we loop over this ephemeral table and for each row in |
| 110912 | | -** the ephermeral table call VUpdate. |
| 111340 | +** the ephemeral table call VUpdate. |
| 110913 | 111341 | ** |
| 110914 | 111342 | ** When finished, drop the ephemeral table. |
| 110915 | 111343 | ** |
| 110916 | 111344 | ** (note1) Actually, if we know in advance that (A) is always the same |
| 110917 | 111345 | ** as (B) we only store (A), then duplicate (A) when pulling |
| | @@ -111080,11 +111508,11 @@ |
| 111080 | 111508 | ** The transient database requires temporary disk space approximately |
| 111081 | 111509 | ** equal to the size of the original database. The copy operation of |
| 111082 | 111510 | ** step (3) requires additional temporary disk space approximately equal |
| 111083 | 111511 | ** to the size of the original database for the rollback journal. |
| 111084 | 111512 | ** Hence, temporary disk space that is approximately 2x the size of the |
| 111085 | | -** orginal database is required. Every page of the database is written |
| 111513 | +** original database is required. Every page of the database is written |
| 111086 | 111514 | ** approximately 3 times: Once for step (2) and twice for step (3). |
| 111087 | 111515 | ** Two writes per page are required in step (3) because the original |
| 111088 | 111516 | ** database content must be written into the rollback journal prior to |
| 111089 | 111517 | ** overwriting the database with the vacuumed content. |
| 111090 | 111518 | ** |
| | @@ -112659,11 +113087,11 @@ |
| 112659 | 113087 | ** |
| 112660 | 113088 | ** The "solver" works by creating the N best WherePath objects of length |
| 112661 | 113089 | ** 1. Then using those as a basis to compute the N best WherePath objects |
| 112662 | 113090 | ** of length 2. And so forth until the length of WherePaths equals the |
| 112663 | 113091 | ** number of nodes in the FROM clause. The best (lowest cost) WherePath |
| 112664 | | -** at the end is the choosen query plan. |
| 113092 | +** at the end is the chosen query plan. |
| 112665 | 113093 | */ |
| 112666 | 113094 | struct WherePath { |
| 112667 | 113095 | Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */ |
| 112668 | 113096 | Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */ |
| 112669 | 113097 | LogEst nRow; /* Estimated number of rows generated by this path */ |
| | @@ -113628,11 +114056,11 @@ |
| 113628 | 114056 | if( *pisComplete && pRight->u.zToken[1] ){ |
| 113629 | 114057 | /* If the rhs of the LIKE expression is a variable, and the current |
| 113630 | 114058 | ** value of the variable means there is no need to invoke the LIKE |
| 113631 | 114059 | ** function, then no OP_Variable will be added to the program. |
| 113632 | 114060 | ** This causes problems for the sqlite3_bind_parameter_name() |
| 113633 | | - ** API. To workaround them, add a dummy OP_Variable here. |
| 114061 | + ** API. To work around them, add a dummy OP_Variable here. |
| 113634 | 114062 | */ |
| 113635 | 114063 | int r1 = sqlite3GetTempReg(pParse); |
| 113636 | 114064 | sqlite3ExprCodeTarget(pParse, pRight, r1); |
| 113637 | 114065 | sqlite3VdbeChangeP3(v, sqlite3VdbeCurrentAddr(v)-1, 0); |
| 113638 | 114066 | sqlite3ReleaseTempReg(pParse, r1); |
| | @@ -113748,11 +114176,11 @@ |
| 113748 | 114176 | ** This analysis does not consider whether or not the index exists; that |
| 113749 | 114177 | ** is decided elsewhere. This analysis only looks at whether subterms |
| 113750 | 114178 | ** appropriate for indexing exist. |
| 113751 | 114179 | ** |
| 113752 | 114180 | ** All examples A through E above satisfy case 2. But if a term |
| 113753 | | -** also statisfies case 1 (such as B) we know that the optimizer will |
| 114181 | +** also satisfies case 1 (such as B) we know that the optimizer will |
| 113754 | 114182 | ** always prefer case 1, so in that case we pretend that case 2 is not |
| 113755 | 114183 | ** satisfied. |
| 113756 | 114184 | ** |
| 113757 | 114185 | ** It might be the case that multiple tables are indexable. For example, |
| 113758 | 114186 | ** (E) above is indexable on tables P, Q, and R. |
| | @@ -113906,11 +114334,11 @@ |
| 113906 | 114334 | assert( j==1 ); |
| 113907 | 114335 | continue; |
| 113908 | 114336 | } |
| 113909 | 114337 | if( (chngToIN & getMask(&pWInfo->sMaskSet, pOrTerm->leftCursor))==0 ){ |
| 113910 | 114338 | /* This term must be of the form t1.a==t2.b where t2 is in the |
| 113911 | | - ** chngToIN set but t1 is not. This term will be either preceeded |
| 114339 | + ** chngToIN set but t1 is not. This term will be either preceded |
| 113912 | 114340 | ** or follwed by an inverted copy (t2.b==t1.a). Skip this term |
| 113913 | 114341 | ** and use its inversion. */ |
| 113914 | 114342 | testcase( pOrTerm->wtFlags & TERM_COPIED ); |
| 113915 | 114343 | testcase( pOrTerm->wtFlags & TERM_VIRTUAL ); |
| 113916 | 114344 | assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) ); |
| | @@ -114317,11 +114745,11 @@ |
| 114317 | 114745 | */ |
| 114318 | 114746 | pTerm->prereqRight |= extraRight; |
| 114319 | 114747 | } |
| 114320 | 114748 | |
| 114321 | 114749 | /* |
| 114322 | | -** This function searches pList for a entry that matches the iCol-th column |
| 114750 | +** This function searches pList for an entry that matches the iCol-th column |
| 114323 | 114751 | ** of index pIdx. |
| 114324 | 114752 | ** |
| 114325 | 114753 | ** If such an expression is found, its index in pList->a[] is returned. If |
| 114326 | 114754 | ** no expression is found, -1 is returned. |
| 114327 | 114755 | */ |
| | @@ -114840,11 +115268,11 @@ |
| 114840 | 115268 | iCol = pRec->nField - 1; |
| 114841 | 115269 | assert( pIdx->nSample>0 ); |
| 114842 | 115270 | assert( pRec->nField>0 && iCol<pIdx->nSampleCol ); |
| 114843 | 115271 | do{ |
| 114844 | 115272 | iTest = (iMin+i)/2; |
| 114845 | | - res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec, 0); |
| 115273 | + res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec); |
| 114846 | 115274 | if( res<0 ){ |
| 114847 | 115275 | iMin = iTest+1; |
| 114848 | 115276 | }else{ |
| 114849 | 115277 | i = iTest; |
| 114850 | 115278 | } |
| | @@ -114855,20 +115283,20 @@ |
| 114855 | 115283 | ** above found the right answer. This block serves no purpose other |
| 114856 | 115284 | ** than to invoke the asserts. */ |
| 114857 | 115285 | if( res==0 ){ |
| 114858 | 115286 | /* If (res==0) is true, then sample $i must be equal to pRec */ |
| 114859 | 115287 | assert( i<pIdx->nSample ); |
| 114860 | | - assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0) |
| 115288 | + assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec) |
| 114861 | 115289 | || pParse->db->mallocFailed ); |
| 114862 | 115290 | }else{ |
| 114863 | 115291 | /* Otherwise, pRec must be smaller than sample $i and larger than |
| 114864 | 115292 | ** sample ($i-1). */ |
| 114865 | 115293 | assert( i==pIdx->nSample |
| 114866 | | - || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)>0 |
| 115294 | + || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0 |
| 114867 | 115295 | || pParse->db->mallocFailed ); |
| 114868 | 115296 | assert( i==0 |
| 114869 | | - || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec, 0)<0 |
| 115297 | + || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0 |
| 114870 | 115298 | || pParse->db->mallocFailed ); |
| 114871 | 115299 | } |
| 114872 | 115300 | #endif /* ifdef SQLITE_DEBUG */ |
| 114873 | 115301 | |
| 114874 | 115302 | /* At this point, aSample[i] is the first sample that is greater than |
| | @@ -115067,11 +115495,11 @@ |
| 115067 | 115495 | ** |
| 115068 | 115496 | ** When this function is called, *pnOut is set to the sqlite3LogEst() of the |
| 115069 | 115497 | ** number of rows that the index scan is expected to visit without |
| 115070 | 115498 | ** considering the range constraints. If nEq is 0, this is the number of |
| 115071 | 115499 | ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced) |
| 115072 | | -** to account for the range contraints pLower and pUpper. |
| 115500 | +** to account for the range constraints pLower and pUpper. |
| 115073 | 115501 | ** |
| 115074 | 115502 | ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be |
| 115075 | 115503 | ** used, a single range inequality reduces the search space by a factor of 4. |
| 115076 | 115504 | ** and a pair of constraints (x>? AND x<?) reduces the expected number of |
| 115077 | 115505 | ** rows visited by a factor of 64. |
| | @@ -116344,11 +116772,11 @@ |
| 116344 | 116772 | ** Return 2 # Jump back to the Gosub |
| 116345 | 116773 | ** |
| 116346 | 116774 | ** B: <after the loop> |
| 116347 | 116775 | ** |
| 116348 | 116776 | ** Added 2014-05-26: If the table is a WITHOUT ROWID table, then |
| 116349 | | - ** use an ephermeral index instead of a RowSet to record the primary |
| 116777 | + ** use an ephemeral index instead of a RowSet to record the primary |
| 116350 | 116778 | ** keys of the rows we have already seen. |
| 116351 | 116779 | ** |
| 116352 | 116780 | */ |
| 116353 | 116781 | WhereClause *pOrWc; /* The OR-clause broken out into subterms */ |
| 116354 | 116782 | SrcList *pOrTab; /* Shortened table list or OR-clause generation */ |
| | @@ -116395,11 +116823,11 @@ |
| 116395 | 116823 | }else{ |
| 116396 | 116824 | pOrTab = pWInfo->pTabList; |
| 116397 | 116825 | } |
| 116398 | 116826 | |
| 116399 | 116827 | /* Initialize the rowset register to contain NULL. An SQL NULL is |
| 116400 | | - ** equivalent to an empty rowset. Or, create an ephermeral index |
| 116828 | + ** equivalent to an empty rowset. Or, create an ephemeral index |
| 116401 | 116829 | ** capable of holding primary keys in the case of a WITHOUT ROWID. |
| 116402 | 116830 | ** |
| 116403 | 116831 | ** Also initialize regReturn to contain the address of the instruction |
| 116404 | 116832 | ** immediately following the OP_Return at the bottom of the loop. This |
| 116405 | 116833 | ** is required in a few obscure LEFT JOIN cases where control jumps |
| | @@ -117148,18 +117576,20 @@ |
| 117148 | 117576 | ** |
| 117149 | 117577 | ** In the current implementation, the first extra WHERE clause term reduces |
| 117150 | 117578 | ** the number of output rows by a factor of 10 and each additional term |
| 117151 | 117579 | ** reduces the number of output rows by sqrt(2). |
| 117152 | 117580 | */ |
| 117153 | | -static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop){ |
| 117581 | +static void whereLoopOutputAdjust( |
| 117582 | + WhereClause *pWC, /* The WHERE clause */ |
| 117583 | + WhereLoop *pLoop, /* The loop to adjust downward */ |
| 117584 | + LogEst nRow /* Number of rows in the entire table */ |
| 117585 | +){ |
| 117154 | 117586 | WhereTerm *pTerm, *pX; |
| 117155 | 117587 | Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf); |
| 117156 | 117588 | int i, j; |
| 117589 | + int nEq = 0; /* Number of = constraints not within likely()/unlikely() */ |
| 117157 | 117590 | |
| 117158 | | - if( !OptimizationEnabled(pWC->pWInfo->pParse->db, SQLITE_AdjustOutEst) ){ |
| 117159 | | - return; |
| 117160 | | - } |
| 117161 | 117591 | for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){ |
| 117162 | 117592 | if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break; |
| 117163 | 117593 | if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue; |
| 117164 | 117594 | if( (pTerm->prereqAll & notAllowed)!=0 ) continue; |
| 117165 | 117595 | for(j=pLoop->nLTerm-1; j>=0; j--){ |
| | @@ -117167,12 +117597,24 @@ |
| 117167 | 117597 | if( pX==0 ) continue; |
| 117168 | 117598 | if( pX==pTerm ) break; |
| 117169 | 117599 | if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break; |
| 117170 | 117600 | } |
| 117171 | 117601 | if( j<0 ){ |
| 117172 | | - pLoop->nOut += (pTerm->truthProb<=0 ? pTerm->truthProb : -1); |
| 117602 | + if( pTerm->truthProb<=0 ){ |
| 117603 | + pLoop->nOut += pTerm->truthProb; |
| 117604 | + }else{ |
| 117605 | + pLoop->nOut--; |
| 117606 | + if( pTerm->eOperator&WO_EQ ) nEq++; |
| 117607 | + } |
| 117173 | 117608 | } |
| 117609 | + } |
| 117610 | + /* TUNING: If there is at least one equality constraint in the WHERE |
| 117611 | + ** clause that does not have a likelihood() explicitly assigned to it |
| 117612 | + ** then do not let the estimated number of output rows exceed half |
| 117613 | + ** the number of rows in the table. */ |
| 117614 | + if( nEq && pLoop->nOut>nRow-10 ){ |
| 117615 | + pLoop->nOut = nRow - 10; |
| 117174 | 117616 | } |
| 117175 | 117617 | } |
| 117176 | 117618 | |
| 117177 | 117619 | /* |
| 117178 | 117620 | ** Adjust the cost C by the costMult facter T. This only occurs if |
| | @@ -117215,10 +117657,11 @@ |
| 117215 | 117657 | u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */ |
| 117216 | 117658 | u32 saved_wsFlags; /* Original value of pNew->wsFlags */ |
| 117217 | 117659 | LogEst saved_nOut; /* Original value of pNew->nOut */ |
| 117218 | 117660 | int iCol; /* Index of the column in the table */ |
| 117219 | 117661 | int rc = SQLITE_OK; /* Return code */ |
| 117662 | + LogEst rSize; /* Number of rows in the table */ |
| 117220 | 117663 | LogEst rLogSize; /* Logarithm of table size */ |
| 117221 | 117664 | WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */ |
| 117222 | 117665 | |
| 117223 | 117666 | pNew = pBuilder->pNew; |
| 117224 | 117667 | if( db->mallocFailed ) return SQLITE_NOMEM; |
| | @@ -117244,11 +117687,12 @@ |
| 117244 | 117687 | saved_nLTerm = pNew->nLTerm; |
| 117245 | 117688 | saved_wsFlags = pNew->wsFlags; |
| 117246 | 117689 | saved_prereq = pNew->prereq; |
| 117247 | 117690 | saved_nOut = pNew->nOut; |
| 117248 | 117691 | pNew->rSetup = 0; |
| 117249 | | - rLogSize = estLog(pProbe->aiRowLogEst[0]); |
| 117692 | + rSize = pProbe->aiRowLogEst[0]; |
| 117693 | + rLogSize = estLog(rSize); |
| 117250 | 117694 | |
| 117251 | 117695 | /* Consider using a skip-scan if there are no WHERE clause constraints |
| 117252 | 117696 | ** available for the left-most terms of the index, and if the average |
| 117253 | 117697 | ** number of repeats in the left-most terms is at least 18. |
| 117254 | 117698 | ** |
| | @@ -117421,11 +117865,11 @@ |
| 117421 | 117865 | ApplyCostMultiplier(pNew->rRun, pProbe->pTable->costMult); |
| 117422 | 117866 | |
| 117423 | 117867 | nOutUnadjusted = pNew->nOut; |
| 117424 | 117868 | pNew->rRun += nInMul + nIn; |
| 117425 | 117869 | pNew->nOut += nInMul + nIn; |
| 117426 | | - whereLoopOutputAdjust(pBuilder->pWC, pNew); |
| 117870 | + whereLoopOutputAdjust(pBuilder->pWC, pNew, rSize); |
| 117427 | 117871 | rc = whereLoopInsert(pBuilder, pNew); |
| 117428 | 117872 | |
| 117429 | 117873 | if( pNew->wsFlags & WHERE_COLUMN_RANGE ){ |
| 117430 | 117874 | pNew->nOut = saved_nOut; |
| 117431 | 117875 | }else{ |
| | @@ -117471,10 +117915,11 @@ |
| 117471 | 117915 | if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0; |
| 117472 | 117916 | for(ii=0; ii<pOB->nExpr; ii++){ |
| 117473 | 117917 | Expr *pExpr = sqlite3ExprSkipCollate(pOB->a[ii].pExpr); |
| 117474 | 117918 | if( pExpr->op!=TK_COLUMN ) return 0; |
| 117475 | 117919 | if( pExpr->iTable==iCursor ){ |
| 117920 | + if( pExpr->iColumn<0 ) return 1; |
| 117476 | 117921 | for(jj=0; jj<pIndex->nKeyCol; jj++){ |
| 117477 | 117922 | if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1; |
| 117478 | 117923 | } |
| 117479 | 117924 | } |
| 117480 | 117925 | } |
| | @@ -117634,11 +118079,11 @@ |
| 117634 | 118079 | ** the table being indexed. */ |
| 117635 | 118080 | pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) ); |
| 117636 | 118081 | ApplyCostMultiplier(pNew->rSetup, pTab->costMult); |
| 117637 | 118082 | /* TUNING: Each index lookup yields 20 rows in the table. This |
| 117638 | 118083 | ** is more than the usual guess of 10 rows, since we have no way |
| 117639 | | - ** of knowning how selective the index will ultimately be. It would |
| 118084 | + ** of knowing how selective the index will ultimately be. It would |
| 117640 | 118085 | ** not be unreasonable to make this value much larger. */ |
| 117641 | 118086 | pNew->nOut = 43; assert( 43==sqlite3LogEst(20) ); |
| 117642 | 118087 | pNew->rRun = sqlite3LogEstAdd(rLogSize,pNew->nOut); |
| 117643 | 118088 | pNew->wsFlags = WHERE_AUTO_INDEX; |
| 117644 | 118089 | pNew->prereq = mExtra | pTerm->prereqRight; |
| | @@ -117675,11 +118120,11 @@ |
| 117675 | 118120 | /* Full table scan */ |
| 117676 | 118121 | pNew->iSortIdx = b ? iSortIdx : 0; |
| 117677 | 118122 | /* TUNING: Cost of full table scan is (N*3.0). */ |
| 117678 | 118123 | pNew->rRun = rSize + 16; |
| 117679 | 118124 | ApplyCostMultiplier(pNew->rRun, pTab->costMult); |
| 117680 | | - whereLoopOutputAdjust(pWC, pNew); |
| 118125 | + whereLoopOutputAdjust(pWC, pNew, rSize); |
| 117681 | 118126 | rc = whereLoopInsert(pBuilder, pNew); |
| 117682 | 118127 | pNew->nOut = rSize; |
| 117683 | 118128 | if( rc ) break; |
| 117684 | 118129 | }else{ |
| 117685 | 118130 | Bitmask m; |
| | @@ -117711,11 +118156,11 @@ |
| 117711 | 118156 | pNew->rRun = rSize + 1 + (15*pProbe->szIdxRow)/pTab->szTabRow; |
| 117712 | 118157 | if( m!=0 ){ |
| 117713 | 118158 | pNew->rRun = sqlite3LogEstAdd(pNew->rRun, rSize+16); |
| 117714 | 118159 | } |
| 117715 | 118160 | ApplyCostMultiplier(pNew->rRun, pTab->costMult); |
| 117716 | | - whereLoopOutputAdjust(pWC, pNew); |
| 118161 | + whereLoopOutputAdjust(pWC, pNew, rSize); |
| 117717 | 118162 | rc = whereLoopInsert(pBuilder, pNew); |
| 117718 | 118163 | pNew->nOut = rSize; |
| 117719 | 118164 | if( rc ) break; |
| 117720 | 118165 | } |
| 117721 | 118166 | } |
| | @@ -118064,11 +118509,11 @@ |
| 118064 | 118509 | ** |
| 118065 | 118510 | ** Note that processing for WHERE_GROUPBY and WHERE_DISTINCTBY is not as |
| 118066 | 118511 | ** strict. With GROUP BY and DISTINCT the only requirement is that |
| 118067 | 118512 | ** equivalent rows appear immediately adjacent to one another. GROUP BY |
| 118068 | 118513 | ** and DISTINCT do not require rows to appear in any particular order as long |
| 118069 | | -** as equivelent rows are grouped together. Thus for GROUP BY and DISTINCT |
| 118514 | +** as equivalent rows are grouped together. Thus for GROUP BY and DISTINCT |
| 118070 | 118515 | ** the pOrderBy terms can be matched in any order. With ORDER BY, the |
| 118071 | 118516 | ** pOrderBy terms must be matched in strict left-to-right order. |
| 118072 | 118517 | */ |
| 118073 | 118518 | static i8 wherePathSatisfiesOrderBy( |
| 118074 | 118519 | WhereInfo *pWInfo, /* The WHERE clause */ |
| | @@ -120841,13 +121286,13 @@ |
| 120841 | 121286 | ** |
| 120842 | 121287 | ** Outputs: |
| 120843 | 121288 | ** A pointer to a parser. This pointer is used in subsequent calls |
| 120844 | 121289 | ** to sqlite3Parser and sqlite3ParserFree. |
| 120845 | 121290 | */ |
| 120846 | | -SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(size_t)){ |
| 121291 | +SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(u64)){ |
| 120847 | 121292 | yyParser *pParser; |
| 120848 | | - pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); |
| 121293 | + pParser = (yyParser*)(*mallocProc)( (u64)sizeof(yyParser) ); |
| 120849 | 121294 | if( pParser ){ |
| 120850 | 121295 | pParser->yyidx = -1; |
| 120851 | 121296 | #ifdef YYTRACKMAXSTACKDEPTH |
| 120852 | 121297 | pParser->yyidxMax = 0; |
| 120853 | 121298 | #endif |
| | @@ -123398,11 +123843,11 @@ |
| 123398 | 123843 | ** |
| 123399 | 123844 | ** For EBCDIC, the rules are more complex but have the same |
| 123400 | 123845 | ** end result. |
| 123401 | 123846 | ** |
| 123402 | 123847 | ** Ticket #1066. the SQL standard does not allow '$' in the |
| 123403 | | -** middle of identfiers. But many SQL implementations do. |
| 123848 | +** middle of identifiers. But many SQL implementations do. |
| 123404 | 123849 | ** SQLite will allow '$' in identifiers for compatibility. |
| 123405 | 123850 | ** But the feature is undocumented. |
| 123406 | 123851 | */ |
| 123407 | 123852 | #ifdef SQLITE_ASCII |
| 123408 | 123853 | #define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0) |
| | @@ -123719,11 +124164,11 @@ |
| 123719 | 124164 | } |
| 123720 | 124165 | pParse->rc = SQLITE_OK; |
| 123721 | 124166 | pParse->zTail = zSql; |
| 123722 | 124167 | i = 0; |
| 123723 | 124168 | assert( pzErrMsg!=0 ); |
| 123724 | | - pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3Malloc); |
| 124169 | + pEngine = sqlite3ParserAlloc(sqlite3Malloc); |
| 123725 | 124170 | if( pEngine==0 ){ |
| 123726 | 124171 | db->mallocFailed = 1; |
| 123727 | 124172 | return SQLITE_NOMEM; |
| 123728 | 124173 | } |
| 123729 | 124174 | assert( pParse->pNewTable==0 ); |
| | @@ -123914,21 +124359,21 @@ |
| 123914 | 124359 | ** |
| 123915 | 124360 | ** (3) EXPLAIN The keyword EXPLAIN has been seen at the beginning of |
| 123916 | 124361 | ** a statement. |
| 123917 | 124362 | ** |
| 123918 | 124363 | ** (4) CREATE The keyword CREATE has been seen at the beginning of a |
| 123919 | | -** statement, possibly preceeded by EXPLAIN and/or followed by |
| 124364 | +** statement, possibly preceded by EXPLAIN and/or followed by |
| 123920 | 124365 | ** TEMP or TEMPORARY |
| 123921 | 124366 | ** |
| 123922 | 124367 | ** (5) TRIGGER We are in the middle of a trigger definition that must be |
| 123923 | 124368 | ** ended by a semicolon, the keyword END, and another semicolon. |
| 123924 | 124369 | ** |
| 123925 | 124370 | ** (6) SEMI We've seen the first semicolon in the ";END;" that occurs at |
| 123926 | 124371 | ** the end of a trigger definition. |
| 123927 | 124372 | ** |
| 123928 | 124373 | ** (7) END We've seen the ";END" of the ";END;" that occurs at the end |
| 123929 | | -** of a trigger difinition. |
| 124374 | +** of a trigger definition. |
| 123930 | 124375 | ** |
| 123931 | 124376 | ** Transitions between states above are determined by tokens extracted |
| 123932 | 124377 | ** from the input. The following tokens are significant: |
| 123933 | 124378 | ** |
| 123934 | 124379 | ** (0) tkSEMI A semicolon. |
| | @@ -123967,11 +124412,11 @@ |
| 123967 | 124412 | /* 6 SEMI: */ { 6, 6, 5, 5, 5, 5, 5, 7, }, |
| 123968 | 124413 | /* 7 END: */ { 1, 7, 5, 5, 5, 5, 5, 5, }, |
| 123969 | 124414 | }; |
| 123970 | 124415 | #else |
| 123971 | 124416 | /* If triggers are not supported by this compile then the statement machine |
| 123972 | | - ** used to detect the end of a statement is much simplier |
| 124417 | + ** used to detect the end of a statement is much simpler |
| 123973 | 124418 | */ |
| 123974 | 124419 | static const u8 trans[3][3] = { |
| 123975 | 124420 | /* Token: */ |
| 123976 | 124421 | /* State: ** SEMI WS OTHER */ |
| 123977 | 124422 | /* 0 INVALID: */ { 1, 0, 2, }, |
| | @@ -125202,10 +125647,14 @@ |
| 125202 | 125647 | #endif |
| 125203 | 125648 | |
| 125204 | 125649 | sqlite3Error(db, SQLITE_OK); /* Deallocates any cached error strings. */ |
| 125205 | 125650 | sqlite3ValueFree(db->pErr); |
| 125206 | 125651 | sqlite3CloseExtensions(db); |
| 125652 | +#if SQLITE_USER_AUTHENTICATION |
| 125653 | + sqlite3_free(db->auth.zAuthUser); |
| 125654 | + sqlite3_free(db->auth.zAuthPW); |
| 125655 | +#endif |
| 125207 | 125656 | |
| 125208 | 125657 | db->magic = SQLITE_MAGIC_ERROR; |
| 125209 | 125658 | |
| 125210 | 125659 | /* The temp-database schema is allocated differently from the other schema |
| 125211 | 125660 | ** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()). |
| | @@ -126783,11 +127232,10 @@ |
| 126783 | 127232 | goto opendb_out; |
| 126784 | 127233 | } |
| 126785 | 127234 | db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt); |
| 126786 | 127235 | db->aDb[1].pSchema = sqlite3SchemaGet(db, 0); |
| 126787 | 127236 | |
| 126788 | | - |
| 126789 | 127237 | /* The default safety_level for the main database is 'full'; for the temp |
| 126790 | 127238 | ** database it is 'NONE'. This matches the pager layer defaults. |
| 126791 | 127239 | */ |
| 126792 | 127240 | db->aDb[0].zName = "main"; |
| 126793 | 127241 | db->aDb[0].safety_level = 3; |
| | @@ -127070,13 +127518,13 @@ |
| 127070 | 127518 | SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){ |
| 127071 | 127519 | return db->autoCommit; |
| 127072 | 127520 | } |
| 127073 | 127521 | |
| 127074 | 127522 | /* |
| 127075 | | -** The following routines are subtitutes for constants SQLITE_CORRUPT, |
| 127523 | +** The following routines are substitutes for constants SQLITE_CORRUPT, |
| 127076 | 127524 | ** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_IOERR and possibly other error |
| 127077 | | -** constants. They server two purposes: |
| 127525 | +** constants. They serve two purposes: |
| 127078 | 127526 | ** |
| 127079 | 127527 | ** 1. Serve as a convenient place to set a breakpoint in a debugger |
| 127080 | 127528 | ** to detect when version error conditions occurs. |
| 127081 | 127529 | ** |
| 127082 | 127530 | ** 2. Invoke sqlite3_log() to provide the source code location where |
| | @@ -127386,11 +127834,11 @@ |
| 127386 | 127834 | ** as it existing before this routine was called. |
| 127387 | 127835 | ** |
| 127388 | 127836 | ** IMPORTANT: Changing the PENDING byte from 0x40000000 results in |
| 127389 | 127837 | ** an incompatible database file format. Changing the PENDING byte |
| 127390 | 127838 | ** while any database connection is open results in undefined and |
| 127391 | | - ** dileterious behavior. |
| 127839 | + ** deleterious behavior. |
| 127392 | 127840 | */ |
| 127393 | 127841 | case SQLITE_TESTCTRL_PENDING_BYTE: { |
| 127394 | 127842 | rc = PENDING_BYTE; |
| 127395 | 127843 | #ifndef SQLITE_OMIT_WSD |
| 127396 | 127844 | { |
| 127397 | 127845 | |