| | @@ -385,23 +385,29 @@ |
| 385 | 385 | /* |
| 386 | 386 | ** Exactly one of the following macros must be defined in order to |
| 387 | 387 | ** specify which memory allocation subsystem to use. |
| 388 | 388 | ** |
| 389 | 389 | ** SQLITE_SYSTEM_MALLOC // Use normal system malloc() |
| 390 | +** SQLITE_WIN32_MALLOC // Use Win32 native heap API |
| 390 | 391 | ** SQLITE_MEMDEBUG // Debugging version of system malloc() |
| 392 | +** |
| 393 | +** On Windows, if the SQLITE_WIN32_MALLOC_VALIDATE macro is defined and the |
| 394 | +** assert() macro is enabled, each call into the Win32 native heap subsystem |
| 395 | +** will cause HeapValidate to be called. If heap validation should fail, an |
| 396 | +** assertion will be triggered. |
| 391 | 397 | ** |
| 392 | 398 | ** (Historical note: There used to be several other options, but we've |
| 393 | 399 | ** pared it down to just these two.) |
| 394 | 400 | ** |
| 395 | 401 | ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as |
| 396 | 402 | ** the default. |
| 397 | 403 | */ |
| 398 | | -#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)>1 |
| 404 | +#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_WIN32_MALLOC)+defined(SQLITE_MEMDEBUG)>1 |
| 399 | 405 | # error "At most one of the following compile-time configuration options\ |
| 400 | | - is allows: SQLITE_SYSTEM_MALLOC, SQLITE_MEMDEBUG" |
| 406 | + is allows: SQLITE_SYSTEM_MALLOC, SQLITE_WIN32_MALLOC, SQLITE_MEMDEBUG" |
| 401 | 407 | #endif |
| 402 | | -#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)==0 |
| 408 | +#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_WIN32_MALLOC)+defined(SQLITE_MEMDEBUG)==0 |
| 403 | 409 | # define SQLITE_SYSTEM_MALLOC 1 |
| 404 | 410 | #endif |
| 405 | 411 | |
| 406 | 412 | /* |
| 407 | 413 | ** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the |
| | @@ -650,11 +656,11 @@ |
| 650 | 656 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | 657 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | 658 | */ |
| 653 | 659 | #define SQLITE_VERSION "3.7.8" |
| 654 | 660 | #define SQLITE_VERSION_NUMBER 3007008 |
| 655 | | -#define SQLITE_SOURCE_ID "2011-08-16 02:07:04 9650d7962804d61f56cac944ff9bb2c7bc111957" |
| 661 | +#define SQLITE_SOURCE_ID "2011-09-04 01:27:00 6b657ae75035eb10b0ad640998d3c9eadfdffa6e" |
| 656 | 662 | |
| 657 | 663 | /* |
| 658 | 664 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | 665 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | 666 | ** |
| | @@ -1751,20 +1757,14 @@ |
| 1751 | 1757 | ** also used during testing of SQLite in order to specify an alternative |
| 1752 | 1758 | ** memory allocator that simulates memory out-of-memory conditions in |
| 1753 | 1759 | ** order to verify that SQLite recovers gracefully from such |
| 1754 | 1760 | ** conditions. |
| 1755 | 1761 | ** |
| 1756 | | -** The xMalloc and xFree methods must work like the |
| 1757 | | -** malloc() and free() functions from the standard C library. |
| 1758 | | -** The xRealloc method must work like realloc() from the standard C library |
| 1759 | | -** with the exception that if the second argument to xRealloc is zero, |
| 1760 | | -** xRealloc must be a no-op - it must not perform any allocation or |
| 1761 | | -** deallocation. ^SQLite guarantees that the second argument to |
| 1762 | +** The xMalloc, xRealloc, and xFree methods must work like the |
| 1763 | +** malloc(), realloc() and free() functions from the standard C library. |
| 1764 | +** ^SQLite guarantees that the second argument to |
| 1762 | 1765 | ** xRealloc is always a value returned by a prior call to xRoundup. |
| 1763 | | -** And so in cases where xRoundup always returns a positive number, |
| 1764 | | -** xRealloc can perform exactly as the standard library realloc() and |
| 1765 | | -** still be in compliance with this specification. |
| 1766 | 1766 | ** |
| 1767 | 1767 | ** xSize should return the allocated size of a memory allocation |
| 1768 | 1768 | ** previously obtained from xMalloc or xRealloc. The allocated size |
| 1769 | 1769 | ** is always at least as big as the requested size but may be larger. |
| 1770 | 1770 | ** |
| | @@ -3397,11 +3397,11 @@ |
| 3397 | 3397 | ** a schema change, on the first [sqlite3_step()] call following any change |
| 3398 | 3398 | ** to the [sqlite3_bind_text | bindings] of that [parameter]. |
| 3399 | 3399 | ** ^The specific value of WHERE-clause [parameter] might influence the |
| 3400 | 3400 | ** choice of query plan if the parameter is the left-hand side of a [LIKE] |
| 3401 | 3401 | ** or [GLOB] operator or if the parameter is compared to an indexed column |
| 3402 | | -** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled. |
| 3402 | +** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled. |
| 3403 | 3403 | ** the |
| 3404 | 3404 | ** </li> |
| 3405 | 3405 | ** </ol> |
| 3406 | 3406 | */ |
| 3407 | 3407 | SQLITE_API int sqlite3_prepare( |
| | @@ -7711,22 +7711,10 @@ |
| 7711 | 7711 | ** is 0x00000000ffffffff. But because of quirks of some compilers, we |
| 7712 | 7712 | ** have to specify the value in the less intuitive manner shown: |
| 7713 | 7713 | */ |
| 7714 | 7714 | #define SQLITE_MAX_U32 ((((u64)1)<<32)-1) |
| 7715 | 7715 | |
| 7716 | | -/* |
| 7717 | | -** The datatype used to store estimates of the number of rows in a |
| 7718 | | -** table or index. This is an unsigned integer type. For 99.9% of |
| 7719 | | -** the world, a 32-bit integer is sufficient. But a 64-bit integer |
| 7720 | | -** can be used at compile-time if desired. |
| 7721 | | -*/ |
| 7722 | | -#ifdef SQLITE_64BIT_STATS |
| 7723 | | - typedef u64 tRowcnt; /* 64-bit only if requested at compile-time */ |
| 7724 | | -#else |
| 7725 | | - typedef u32 tRowcnt; /* 32-bit is the default */ |
| 7726 | | -#endif |
| 7727 | | - |
| 7728 | 7716 | /* |
| 7729 | 7717 | ** Macros to determine whether the machine is big or little endian, |
| 7730 | 7718 | ** evaluated at runtime. |
| 7731 | 7719 | */ |
| 7732 | 7720 | #ifdef SQLITE_AMALGAMATION |
| | @@ -8188,10 +8176,11 @@ |
| 8188 | 8176 | ** or VDBE. The VDBE implements an abstract machine that runs a |
| 8189 | 8177 | ** simple program to access and modify the underlying database. |
| 8190 | 8178 | */ |
| 8191 | 8179 | #ifndef _SQLITE_VDBE_H_ |
| 8192 | 8180 | #define _SQLITE_VDBE_H_ |
| 8181 | +/* #include <stdio.h> */ |
| 8193 | 8182 | |
| 8194 | 8183 | /* |
| 8195 | 8184 | ** A single VDBE is an opaque structure named "Vdbe". Only routines |
| 8196 | 8185 | ** in the source file sqliteVdbe.c are allowed to see the insides |
| 8197 | 8186 | ** of this structure. |
| | @@ -8231,10 +8220,11 @@ |
| 8231 | 8220 | Mem *pMem; /* Used when p4type is P4_MEM */ |
| 8232 | 8221 | VTable *pVtab; /* Used when p4type is P4_VTAB */ |
| 8233 | 8222 | KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */ |
| 8234 | 8223 | int *ai; /* Used when p4type is P4_INTARRAY */ |
| 8235 | 8224 | SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */ |
| 8225 | + int (*xAdvance)(BtCursor *, int *); |
| 8236 | 8226 | } p4; |
| 8237 | 8227 | #ifdef SQLITE_DEBUG |
| 8238 | 8228 | char *zComment; /* Comment to improve readability */ |
| 8239 | 8229 | #endif |
| 8240 | 8230 | #ifdef VDBE_PROFILE |
| | @@ -8286,10 +8276,11 @@ |
| 8286 | 8276 | #define P4_REAL (-12) /* P4 is a 64-bit floating point value */ |
| 8287 | 8277 | #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */ |
| 8288 | 8278 | #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */ |
| 8289 | 8279 | #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */ |
| 8290 | 8280 | #define P4_SUBPROGRAM (-18) /* P4 is a pointer to a SubProgram structure */ |
| 8281 | +#define P4_ADVANCE (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */ |
| 8291 | 8282 | |
| 8292 | 8283 | /* When adding a P4 argument using P4_KEYINFO, a copy of the KeyInfo structure |
| 8293 | 8284 | ** is made. That copy is freed when the Vdbe is finalized. But if the |
| 8294 | 8285 | ** argument is P4_KEYINFO_HANDOFF, the passed in pointer is used. It still |
| 8295 | 8286 | ** gets freed when the Vdbe is finalized so it still should be obtained |
| | @@ -8401,88 +8392,90 @@ |
| 8401 | 8392 | #define OP_VerifyCookie 37 |
| 8402 | 8393 | #define OP_OpenRead 38 |
| 8403 | 8394 | #define OP_OpenWrite 39 |
| 8404 | 8395 | #define OP_OpenAutoindex 40 |
| 8405 | 8396 | #define OP_OpenEphemeral 41 |
| 8406 | | -#define OP_OpenPseudo 42 |
| 8407 | | -#define OP_Close 43 |
| 8408 | | -#define OP_SeekLt 44 |
| 8409 | | -#define OP_SeekLe 45 |
| 8410 | | -#define OP_SeekGe 46 |
| 8411 | | -#define OP_SeekGt 47 |
| 8412 | | -#define OP_Seek 48 |
| 8413 | | -#define OP_NotFound 49 |
| 8414 | | -#define OP_Found 50 |
| 8415 | | -#define OP_IsUnique 51 |
| 8416 | | -#define OP_NotExists 52 |
| 8417 | | -#define OP_Sequence 53 |
| 8418 | | -#define OP_NewRowid 54 |
| 8419 | | -#define OP_Insert 55 |
| 8420 | | -#define OP_InsertInt 56 |
| 8421 | | -#define OP_Delete 57 |
| 8422 | | -#define OP_ResetCount 58 |
| 8423 | | -#define OP_RowKey 59 |
| 8424 | | -#define OP_RowData 60 |
| 8425 | | -#define OP_Rowid 61 |
| 8426 | | -#define OP_NullRow 62 |
| 8427 | | -#define OP_Last 63 |
| 8428 | | -#define OP_Sort 64 |
| 8429 | | -#define OP_Rewind 65 |
| 8430 | | -#define OP_Prev 66 |
| 8431 | | -#define OP_Next 67 |
| 8432 | | -#define OP_IdxInsert 70 |
| 8433 | | -#define OP_IdxDelete 71 |
| 8434 | | -#define OP_IdxRowid 72 |
| 8435 | | -#define OP_IdxLT 81 |
| 8436 | | -#define OP_IdxGE 92 |
| 8437 | | -#define OP_Destroy 95 |
| 8438 | | -#define OP_Clear 96 |
| 8439 | | -#define OP_CreateIndex 97 |
| 8440 | | -#define OP_CreateTable 98 |
| 8441 | | -#define OP_ParseSchema 99 |
| 8442 | | -#define OP_LoadAnalysis 100 |
| 8443 | | -#define OP_DropTable 101 |
| 8444 | | -#define OP_DropIndex 102 |
| 8445 | | -#define OP_DropTrigger 103 |
| 8446 | | -#define OP_IntegrityCk 104 |
| 8447 | | -#define OP_RowSetAdd 105 |
| 8448 | | -#define OP_RowSetRead 106 |
| 8449 | | -#define OP_RowSetTest 107 |
| 8450 | | -#define OP_Program 108 |
| 8451 | | -#define OP_Param 109 |
| 8452 | | -#define OP_FkCounter 110 |
| 8453 | | -#define OP_FkIfZero 111 |
| 8454 | | -#define OP_MemMax 112 |
| 8455 | | -#define OP_IfPos 113 |
| 8456 | | -#define OP_IfNeg 114 |
| 8457 | | -#define OP_IfZero 115 |
| 8458 | | -#define OP_AggStep 116 |
| 8459 | | -#define OP_AggFinal 117 |
| 8460 | | -#define OP_Checkpoint 118 |
| 8461 | | -#define OP_JournalMode 119 |
| 8462 | | -#define OP_Vacuum 120 |
| 8463 | | -#define OP_IncrVacuum 121 |
| 8464 | | -#define OP_Expire 122 |
| 8465 | | -#define OP_TableLock 123 |
| 8466 | | -#define OP_VBegin 124 |
| 8467 | | -#define OP_VCreate 125 |
| 8468 | | -#define OP_VDestroy 126 |
| 8469 | | -#define OP_VOpen 127 |
| 8470 | | -#define OP_VFilter 128 |
| 8471 | | -#define OP_VColumn 129 |
| 8472 | | -#define OP_VNext 131 |
| 8473 | | -#define OP_VRename 132 |
| 8474 | | -#define OP_VUpdate 133 |
| 8475 | | -#define OP_Pagecount 134 |
| 8476 | | -#define OP_MaxPgcnt 135 |
| 8477 | | -#define OP_Trace 136 |
| 8478 | | -#define OP_Noop 137 |
| 8479 | | -#define OP_Explain 138 |
| 8480 | | - |
| 8481 | | -/* The following opcode values are never used */ |
| 8482 | | -#define OP_NotUsed_139 139 |
| 8483 | | -#define OP_NotUsed_140 140 |
| 8397 | +#define OP_SorterOpen 42 |
| 8398 | +#define OP_OpenPseudo 43 |
| 8399 | +#define OP_Close 44 |
| 8400 | +#define OP_SeekLt 45 |
| 8401 | +#define OP_SeekLe 46 |
| 8402 | +#define OP_SeekGe 47 |
| 8403 | +#define OP_SeekGt 48 |
| 8404 | +#define OP_Seek 49 |
| 8405 | +#define OP_NotFound 50 |
| 8406 | +#define OP_Found 51 |
| 8407 | +#define OP_IsUnique 52 |
| 8408 | +#define OP_NotExists 53 |
| 8409 | +#define OP_Sequence 54 |
| 8410 | +#define OP_NewRowid 55 |
| 8411 | +#define OP_Insert 56 |
| 8412 | +#define OP_InsertInt 57 |
| 8413 | +#define OP_Delete 58 |
| 8414 | +#define OP_ResetCount 59 |
| 8415 | +#define OP_SorterCompare 60 |
| 8416 | +#define OP_SorterData 61 |
| 8417 | +#define OP_RowKey 62 |
| 8418 | +#define OP_RowData 63 |
| 8419 | +#define OP_Rowid 64 |
| 8420 | +#define OP_NullRow 65 |
| 8421 | +#define OP_Last 66 |
| 8422 | +#define OP_SorterSort 67 |
| 8423 | +#define OP_Sort 70 |
| 8424 | +#define OP_Rewind 71 |
| 8425 | +#define OP_SorterNext 72 |
| 8426 | +#define OP_Prev 81 |
| 8427 | +#define OP_Next 92 |
| 8428 | +#define OP_SorterInsert 95 |
| 8429 | +#define OP_IdxInsert 96 |
| 8430 | +#define OP_IdxDelete 97 |
| 8431 | +#define OP_IdxRowid 98 |
| 8432 | +#define OP_IdxLT 99 |
| 8433 | +#define OP_IdxGE 100 |
| 8434 | +#define OP_Destroy 101 |
| 8435 | +#define OP_Clear 102 |
| 8436 | +#define OP_CreateIndex 103 |
| 8437 | +#define OP_CreateTable 104 |
| 8438 | +#define OP_ParseSchema 105 |
| 8439 | +#define OP_LoadAnalysis 106 |
| 8440 | +#define OP_DropTable 107 |
| 8441 | +#define OP_DropIndex 108 |
| 8442 | +#define OP_DropTrigger 109 |
| 8443 | +#define OP_IntegrityCk 110 |
| 8444 | +#define OP_RowSetAdd 111 |
| 8445 | +#define OP_RowSetRead 112 |
| 8446 | +#define OP_RowSetTest 113 |
| 8447 | +#define OP_Program 114 |
| 8448 | +#define OP_Param 115 |
| 8449 | +#define OP_FkCounter 116 |
| 8450 | +#define OP_FkIfZero 117 |
| 8451 | +#define OP_MemMax 118 |
| 8452 | +#define OP_IfPos 119 |
| 8453 | +#define OP_IfNeg 120 |
| 8454 | +#define OP_IfZero 121 |
| 8455 | +#define OP_AggStep 122 |
| 8456 | +#define OP_AggFinal 123 |
| 8457 | +#define OP_Checkpoint 124 |
| 8458 | +#define OP_JournalMode 125 |
| 8459 | +#define OP_Vacuum 126 |
| 8460 | +#define OP_IncrVacuum 127 |
| 8461 | +#define OP_Expire 128 |
| 8462 | +#define OP_TableLock 129 |
| 8463 | +#define OP_VBegin 131 |
| 8464 | +#define OP_VCreate 132 |
| 8465 | +#define OP_VDestroy 133 |
| 8466 | +#define OP_VOpen 134 |
| 8467 | +#define OP_VFilter 135 |
| 8468 | +#define OP_VColumn 136 |
| 8469 | +#define OP_VNext 137 |
| 8470 | +#define OP_VRename 138 |
| 8471 | +#define OP_VUpdate 139 |
| 8472 | +#define OP_Pagecount 140 |
| 8473 | +#define OP_MaxPgcnt 146 |
| 8474 | +#define OP_Trace 147 |
| 8475 | +#define OP_Noop 148 |
| 8476 | +#define OP_Explain 149 |
| 8484 | 8477 | |
| 8485 | 8478 | |
| 8486 | 8479 | /* Properties such as "out2" or "jump" that are specified in |
| 8487 | 8480 | ** comments following the "case" for each opcode in the vdbe.c |
| 8488 | 8481 | ** are encoded into bitvectors as follows: |
| | @@ -8498,24 +8491,24 @@ |
| 8498 | 8491 | /* 0 */ 0x00, 0x01, 0x05, 0x04, 0x04, 0x10, 0x00, 0x02,\ |
| 8499 | 8492 | /* 8 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x24, 0x24,\ |
| 8500 | 8493 | /* 16 */ 0x00, 0x00, 0x00, 0x24, 0x04, 0x05, 0x04, 0x00,\ |
| 8501 | 8494 | /* 24 */ 0x00, 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02,\ |
| 8502 | 8495 | /* 32 */ 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00,\ |
| 8503 | | -/* 40 */ 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11,\ |
| 8504 | | -/* 48 */ 0x08, 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00,\ |
| 8505 | | -/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,\ |
| 8506 | | -/* 64 */ 0x01, 0x01, 0x01, 0x01, 0x4c, 0x4c, 0x08, 0x00,\ |
| 8507 | | -/* 72 */ 0x02, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\ |
| 8496 | +/* 40 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11,\ |
| 8497 | +/* 48 */ 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x02, 0x02,\ |
| 8498 | +/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 8499 | +/* 64 */ 0x02, 0x00, 0x01, 0x01, 0x4c, 0x4c, 0x01, 0x01,\ |
| 8500 | +/* 72 */ 0x01, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\ |
| 8508 | 8501 | /* 80 */ 0x15, 0x01, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\ |
| 8509 | | -/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x01, 0x24, 0x02, 0x02,\ |
| 8510 | | -/* 96 */ 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 8511 | | -/* 104 */ 0x00, 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01,\ |
| 8512 | | -/* 112 */ 0x08, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02,\ |
| 8513 | | -/* 120 */ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 8514 | | -/* 128 */ 0x01, 0x00, 0x02, 0x01, 0x00, 0x00, 0x02, 0x02,\ |
| 8515 | | -/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,\ |
| 8516 | | -/* 144 */ 0x04, 0x04,} |
| 8502 | +/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x01, 0x24, 0x02, 0x08,\ |
| 8503 | +/* 96 */ 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00, 0x02,\ |
| 8504 | +/* 104 */ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,\ |
| 8505 | +/* 112 */ 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08, 0x05,\ |
| 8506 | +/* 120 */ 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,\ |
| 8507 | +/* 128 */ 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01,\ |
| 8508 | +/* 136 */ 0x00, 0x01, 0x00, 0x00, 0x02, 0x04, 0x04, 0x04,\ |
| 8509 | +/* 144 */ 0x04, 0x04, 0x02, 0x00, 0x00, 0x00,} |
| 8517 | 8510 | |
| 8518 | 8511 | /************** End of opcodes.h *********************************************/ |
| 8519 | 8512 | /************** Continuing where we left off in vdbe.h ***********************/ |
| 8520 | 8513 | |
| 8521 | 8514 | /* |
| | @@ -8529,13 +8522,13 @@ |
| 8529 | 8522 | SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int); |
| 8530 | 8523 | SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int); |
| 8531 | 8524 | SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int); |
| 8532 | 8525 | SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp); |
| 8533 | 8526 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*); |
| 8534 | | -SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1); |
| 8535 | | -SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2); |
| 8536 | | -SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3); |
| 8527 | +SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1); |
| 8528 | +SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 8529 | +SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 8537 | 8530 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| 8538 | 8531 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 8539 | 8532 | SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N); |
| 8540 | 8533 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 8541 | 8534 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| | @@ -8653,10 +8646,11 @@ |
| 8653 | 8646 | ** NOTE: These values must match the corresponding BTREE_ values in btree.h. |
| 8654 | 8647 | */ |
| 8655 | 8648 | #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */ |
| 8656 | 8649 | #define PAGER_NO_READLOCK 0x0002 /* Omit readlocks on readonly files */ |
| 8657 | 8650 | #define PAGER_MEMORY 0x0004 /* In-memory database */ |
| 8651 | +#define PAGER_SORTER 0x0020 /* Accumulator in external merge sort */ |
| 8658 | 8652 | |
| 8659 | 8653 | /* |
| 8660 | 8654 | ** Valid values for the second argument to sqlite3PagerLockingMode(). |
| 8661 | 8655 | */ |
| 8662 | 8656 | #define PAGER_LOCKINGMODE_QUERY -1 |
| | @@ -9924,11 +9918,11 @@ |
| 9924 | 9918 | int iPKey; /* If not negative, use aCol[iPKey] as the primary key */ |
| 9925 | 9919 | int nCol; /* Number of columns in this table */ |
| 9926 | 9920 | Column *aCol; /* Information about each column */ |
| 9927 | 9921 | Index *pIndex; /* List of SQL indexes on this table. */ |
| 9928 | 9922 | int tnum; /* Root BTree node for this table (see note above) */ |
| 9929 | | - tRowcnt nRowEst; /* Estimated rows in table - from sqlite_stat1 table */ |
| 9923 | + unsigned nRowEst; /* Estimated rows in table - from sqlite_stat1 table */ |
| 9930 | 9924 | Select *pSelect; /* NULL for tables. Points to definition if a view. */ |
| 9931 | 9925 | u16 nRef; /* Number of pointers to this Table */ |
| 9932 | 9926 | u8 tabFlags; /* Mask of TF_* values */ |
| 9933 | 9927 | u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ |
| 9934 | 9928 | FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| | @@ -10123,43 +10117,35 @@ |
| 10123 | 10117 | */ |
| 10124 | 10118 | struct Index { |
| 10125 | 10119 | char *zName; /* Name of this index */ |
| 10126 | 10120 | int nColumn; /* Number of columns in the table used by this index */ |
| 10127 | 10121 | int *aiColumn; /* Which columns are used by this index. 1st is 0 */ |
| 10128 | | - tRowcnt *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */ |
| 10122 | + unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */ |
| 10129 | 10123 | Table *pTable; /* The SQL table being indexed */ |
| 10130 | 10124 | int tnum; /* Page containing root of this index in database file */ |
| 10131 | 10125 | u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ |
| 10132 | 10126 | u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */ |
| 10133 | 10127 | u8 bUnordered; /* Use this index for == or IN queries only */ |
| 10134 | | - u8 nSample; /* Number of elements in aSample[] */ |
| 10135 | 10128 | char *zColAff; /* String defining the affinity of each column */ |
| 10136 | 10129 | Index *pNext; /* The next index associated with the same table */ |
| 10137 | 10130 | Schema *pSchema; /* Schema containing this index */ |
| 10138 | 10131 | u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */ |
| 10139 | 10132 | char **azColl; /* Array of collation sequence names for index */ |
| 10140 | | -#ifdef SQLITE_ENABLE_STAT3 |
| 10141 | | - tRowcnt avgEq; /* Average nEq value for key values not in aSample */ |
| 10142 | | - IndexSample *aSample; /* Samples of the left-most key */ |
| 10143 | | -#endif |
| 10133 | + IndexSample *aSample; /* Array of SQLITE_INDEX_SAMPLES samples */ |
| 10144 | 10134 | }; |
| 10145 | 10135 | |
| 10146 | 10136 | /* |
| 10147 | 10137 | ** Each sample stored in the sqlite_stat2 table is represented in memory |
| 10148 | 10138 | ** using a structure of this type. |
| 10149 | 10139 | */ |
| 10150 | 10140 | struct IndexSample { |
| 10151 | 10141 | union { |
| 10152 | 10142 | char *z; /* Value if eType is SQLITE_TEXT or SQLITE_BLOB */ |
| 10153 | | - double r; /* Value if eType is SQLITE_FLOAT */ |
| 10154 | | - i64 i; /* Value if eType is SQLITE_INTEGER */ |
| 10143 | + double r; /* Value if eType is SQLITE_FLOAT or SQLITE_INTEGER */ |
| 10155 | 10144 | } u; |
| 10156 | 10145 | u8 eType; /* SQLITE_NULL, SQLITE_INTEGER ... etc. */ |
| 10157 | | - u16 nByte; /* Size in byte of text or blob. */ |
| 10158 | | - tRowcnt nEq; /* Est. number of rows where the key equals this sample */ |
| 10159 | | - tRowcnt nLt; /* Est. number of rows where key is less than this sample */ |
| 10160 | | - tRowcnt nDLt; /* Est. number of distinct keys less than this sample */ |
| 10146 | + u8 nByte; /* Size in byte of text or blob. */ |
| 10161 | 10147 | }; |
| 10162 | 10148 | |
| 10163 | 10149 | /* |
| 10164 | 10150 | ** Each token coming out of the lexer is an instance of |
| 10165 | 10151 | ** this structure. Tokens are also used as part of an expression. |
| | @@ -10190,10 +10176,11 @@ |
| 10190 | 10176 | u8 directMode; /* Direct rendering mode means take data directly |
| 10191 | 10177 | ** from source tables rather than from accumulators */ |
| 10192 | 10178 | u8 useSortingIdx; /* In direct mode, reference the sorting index rather |
| 10193 | 10179 | ** than the source table */ |
| 10194 | 10180 | int sortingIdx; /* Cursor number of the sorting index */ |
| 10181 | + int sortingIdxPTab; /* Cursor number of pseudo-table */ |
| 10195 | 10182 | ExprList *pGroupBy; /* The group by clause */ |
| 10196 | 10183 | int nSortingColumn; /* Number of columns in the sorting index */ |
| 10197 | 10184 | struct AggInfo_col { /* For each column used in source tables */ |
| 10198 | 10185 | Table *pTab; /* Source table */ |
| 10199 | 10186 | int iTable; /* Cursor number of the source table */ |
| | @@ -10722,10 +10709,11 @@ |
| 10722 | 10709 | #define SF_Resolved 0x0002 /* Identifiers have been resolved */ |
| 10723 | 10710 | #define SF_Aggregate 0x0004 /* Contains aggregate functions */ |
| 10724 | 10711 | #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */ |
| 10725 | 10712 | #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */ |
| 10726 | 10713 | #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ |
| 10714 | +#define SF_UseSorter 0x0040 /* Sort using a sorter */ |
| 10727 | 10715 | |
| 10728 | 10716 | |
| 10729 | 10717 | /* |
| 10730 | 10718 | ** The results of a select can be distributed in several ways. The |
| 10731 | 10719 | ** "SRT" prefix means "SELECT Result Type". |
| | @@ -11361,11 +11349,10 @@ |
| 11361 | 11349 | #else |
| 11362 | 11350 | # define sqlite3ViewGetColumnNames(A,B) 0 |
| 11363 | 11351 | #endif |
| 11364 | 11352 | |
| 11365 | 11353 | SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int); |
| 11366 | | -SQLITE_PRIVATE void sqlite3CodeDropTable(Parse*, Table*, int, int); |
| 11367 | 11354 | SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*); |
| 11368 | 11355 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 11369 | 11356 | SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse); |
| 11370 | 11357 | SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse); |
| 11371 | 11358 | #else |
| | @@ -11618,11 +11605,11 @@ |
| 11618 | 11605 | SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 11619 | 11606 | void(*)(void*)); |
| 11620 | 11607 | SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*); |
| 11621 | 11608 | SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *); |
| 11622 | 11609 | SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8); |
| 11623 | | -#ifdef SQLITE_ENABLE_STAT3 |
| 11610 | +#ifdef SQLITE_ENABLE_STAT2 |
| 11624 | 11611 | SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *, u8, char *, int, int *); |
| 11625 | 11612 | #endif |
| 11626 | 11613 | SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); |
| 11627 | 11614 | SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); |
| 11628 | 11615 | #ifndef SQLITE_AMALGAMATION |
| | @@ -12245,13 +12232,10 @@ |
| 12245 | 12232 | "ENABLE_RTREE", |
| 12246 | 12233 | #endif |
| 12247 | 12234 | #ifdef SQLITE_ENABLE_STAT2 |
| 12248 | 12235 | "ENABLE_STAT2", |
| 12249 | 12236 | #endif |
| 12250 | | -#ifdef SQLITE_ENABLE_STAT3 |
| 12251 | | - "ENABLE_STAT3", |
| 12252 | | -#endif |
| 12253 | 12237 | #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY |
| 12254 | 12238 | "ENABLE_UNLOCK_NOTIFY", |
| 12255 | 12239 | #endif |
| 12256 | 12240 | #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
| 12257 | 12241 | "ENABLE_UPDATE_DELETE_LIMIT", |
| | @@ -12275,10 +12259,13 @@ |
| 12275 | 12259 | "INT64_TYPE", |
| 12276 | 12260 | #endif |
| 12277 | 12261 | #ifdef SQLITE_LOCK_TRACE |
| 12278 | 12262 | "LOCK_TRACE", |
| 12279 | 12263 | #endif |
| 12264 | +#ifdef SQLITE_MAX_SCHEMA_RETRY |
| 12265 | + "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY), |
| 12266 | +#endif |
| 12280 | 12267 | #ifdef SQLITE_MEMDEBUG |
| 12281 | 12268 | "MEMDEBUG", |
| 12282 | 12269 | #endif |
| 12283 | 12270 | #ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT |
| 12284 | 12271 | "MIXED_ENDIAN_64BIT_FLOAT", |
| | @@ -12387,10 +12374,13 @@ |
| 12387 | 12374 | #ifdef SQLITE_OMIT_LOOKASIDE |
| 12388 | 12375 | "OMIT_LOOKASIDE", |
| 12389 | 12376 | #endif |
| 12390 | 12377 | #ifdef SQLITE_OMIT_MEMORYDB |
| 12391 | 12378 | "OMIT_MEMORYDB", |
| 12379 | +#endif |
| 12380 | +#ifdef SQLITE_OMIT_MERGE_SORT |
| 12381 | + "OMIT_MERGE_SORT", |
| 12392 | 12382 | #endif |
| 12393 | 12383 | #ifdef SQLITE_OMIT_OR_OPTIMIZATION |
| 12394 | 12384 | "OMIT_OR_OPTIMIZATION", |
| 12395 | 12385 | #endif |
| 12396 | 12386 | #ifdef SQLITE_OMIT_PAGER_PRAGMAS |
| | @@ -12453,10 +12443,13 @@ |
| 12453 | 12443 | #ifdef SQLITE_OMIT_WSD |
| 12454 | 12444 | "OMIT_WSD", |
| 12455 | 12445 | #endif |
| 12456 | 12446 | #ifdef SQLITE_OMIT_XFER_OPT |
| 12457 | 12447 | "OMIT_XFER_OPT", |
| 12448 | +#endif |
| 12449 | +#ifdef SQLITE_PAGECACHE_BLOCKALLOC |
| 12450 | + "PAGECACHE_BLOCKALLOC", |
| 12458 | 12451 | #endif |
| 12459 | 12452 | #ifdef SQLITE_PERFORMANCE_TRACE |
| 12460 | 12453 | "PERFORMANCE_TRACE", |
| 12461 | 12454 | #endif |
| 12462 | 12455 | #ifdef SQLITE_PROXY_DEBUG |
| | @@ -12574,10 +12567,13 @@ |
| 12574 | 12567 | /* |
| 12575 | 12568 | ** Boolean values |
| 12576 | 12569 | */ |
| 12577 | 12570 | typedef unsigned char Bool; |
| 12578 | 12571 | |
| 12572 | +/* Opaque type used by code in vdbesort.c */ |
| 12573 | +typedef struct VdbeSorter VdbeSorter; |
| 12574 | + |
| 12579 | 12575 | /* |
| 12580 | 12576 | ** A cursor is a pointer into a single BTree within a database file. |
| 12581 | 12577 | ** The cursor can seek to a BTree entry with a particular key, or |
| 12582 | 12578 | ** loop over all entries of the Btree. You can also insert new BTree |
| 12583 | 12579 | ** entries or retrieve the key or data from the entry that the cursor |
| | @@ -12600,15 +12596,17 @@ |
| 12600 | 12596 | Bool nullRow; /* True if pointing to a row with no data */ |
| 12601 | 12597 | Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ |
| 12602 | 12598 | Bool isTable; /* True if a table requiring integer keys */ |
| 12603 | 12599 | Bool isIndex; /* True if an index containing keys only - no data */ |
| 12604 | 12600 | Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */ |
| 12601 | + Bool isSorter; /* True if a new-style sorter */ |
| 12605 | 12602 | sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */ |
| 12606 | 12603 | const sqlite3_module *pModule; /* Module for cursor pVtabCursor */ |
| 12607 | 12604 | i64 seqCount; /* Sequence counter */ |
| 12608 | 12605 | i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ |
| 12609 | 12606 | i64 lastRowid; /* Last rowid from a Next or NextIdx operation */ |
| 12607 | + VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */ |
| 12610 | 12608 | |
| 12611 | 12609 | /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or |
| 12612 | 12610 | ** OP_IsUnique opcode on this cursor. */ |
| 12613 | 12611 | int seekResult; |
| 12614 | 12612 | |
| | @@ -12924,17 +12922,38 @@ |
| 12924 | 12922 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); |
| 12925 | 12923 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); |
| 12926 | 12924 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*); |
| 12927 | 12925 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); |
| 12928 | 12926 | SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p); |
| 12927 | +#define MemReleaseExt(X) \ |
| 12928 | + if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \ |
| 12929 | + sqlite3VdbeMemReleaseExternal(X); |
| 12929 | 12930 | SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); |
| 12930 | 12931 | SQLITE_PRIVATE const char *sqlite3OpcodeName(int); |
| 12931 | 12932 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); |
| 12932 | 12933 | SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int); |
| 12933 | 12934 | SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); |
| 12934 | 12935 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *); |
| 12935 | 12936 | SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem); |
| 12937 | + |
| 12938 | +#ifdef SQLITE_OMIT_MERGE_SORT |
| 12939 | +# define sqlite3VdbeSorterInit(Y,Z) SQLITE_OK |
| 12940 | +# define sqlite3VdbeSorterWrite(X,Y,Z) SQLITE_OK |
| 12941 | +# define sqlite3VdbeSorterClose(Y,Z) |
| 12942 | +# define sqlite3VdbeSorterRowkey(Y,Z) SQLITE_OK |
| 12943 | +# define sqlite3VdbeSorterRewind(X,Y,Z) SQLITE_OK |
| 12944 | +# define sqlite3VdbeSorterNext(X,Y,Z) SQLITE_OK |
| 12945 | +# define sqlite3VdbeSorterCompare(X,Y,Z) SQLITE_OK |
| 12946 | +#else |
| 12947 | +SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *); |
| 12948 | +SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *); |
| 12949 | +SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(VdbeCursor *, Mem *); |
| 12950 | +SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *, VdbeCursor *, int *); |
| 12951 | +SQLITE_PRIVATE int sqlite3VdbeSorterRewind(sqlite3 *, VdbeCursor *, int *); |
| 12952 | +SQLITE_PRIVATE int sqlite3VdbeSorterWrite(sqlite3 *, VdbeCursor *, Mem *); |
| 12953 | +SQLITE_PRIVATE int sqlite3VdbeSorterCompare(VdbeCursor *, Mem *, int *); |
| 12954 | +#endif |
| 12936 | 12955 | |
| 12937 | 12956 | #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0 |
| 12938 | 12957 | SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*); |
| 12939 | 12958 | SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*); |
| 12940 | 12959 | #else |
| | @@ -13225,10 +13244,12 @@ |
| 13225 | 13244 | ** Astronomical Algorithms, 2nd Edition, 1998 |
| 13226 | 13245 | ** ISBM 0-943396-61-1 |
| 13227 | 13246 | ** Willmann-Bell, Inc |
| 13228 | 13247 | ** Richmond, Virginia (USA) |
| 13229 | 13248 | */ |
| 13249 | +/* #include <stdlib.h> */ |
| 13250 | +/* #include <assert.h> */ |
| 13230 | 13251 | #include <time.h> |
| 13231 | 13252 | |
| 13232 | 13253 | #ifndef SQLITE_OMIT_DATETIME_FUNCS |
| 13233 | 13254 | |
| 13234 | 13255 | |
| | @@ -14978,10 +14999,11 @@ |
| 14978 | 14999 | extern void backtrace_symbols_fd(void*const*,int,int); |
| 14979 | 15000 | #else |
| 14980 | 15001 | # define backtrace(A,B) 1 |
| 14981 | 15002 | # define backtrace_symbols_fd(A,B,C) |
| 14982 | 15003 | #endif |
| 15004 | +/* #include <stdio.h> */ |
| 14983 | 15005 | |
| 14984 | 15006 | /* |
| 14985 | 15007 | ** Each memory allocation looks like this: |
| 14986 | 15008 | ** |
| 14987 | 15009 | ** ------------------------------------------------------------------------ |
| | @@ -18081,10 +18103,11 @@ |
| 18081 | 18103 | ** |
| 18082 | 18104 | ************************************************************************* |
| 18083 | 18105 | ** |
| 18084 | 18106 | ** Memory allocation functions used throughout sqlite. |
| 18085 | 18107 | */ |
| 18108 | +/* #include <stdarg.h> */ |
| 18086 | 18109 | |
| 18087 | 18110 | /* |
| 18088 | 18111 | ** Attempt to release up to n bytes of non-essential memory currently |
| 18089 | 18112 | ** held by SQLite. An example of non-essential memory is memory used to |
| 18090 | 18113 | ** cache database pages that are not currently in use. |
| | @@ -20058,10 +20081,11 @@ |
| 20058 | 20081 | ** BOM or Byte Order Mark: |
| 20059 | 20082 | ** 0xff 0xfe little-endian utf-16 follows |
| 20060 | 20083 | ** 0xfe 0xff big-endian utf-16 follows |
| 20061 | 20084 | ** |
| 20062 | 20085 | */ |
| 20086 | +/* #include <assert.h> */ |
| 20063 | 20087 | |
| 20064 | 20088 | #ifndef SQLITE_AMALGAMATION |
| 20065 | 20089 | /* |
| 20066 | 20090 | ** The following constant value is used by the SQLITE_BIGENDIAN and |
| 20067 | 20091 | ** SQLITE_LITTLEENDIAN macros. |
| | @@ -20486,11 +20510,11 @@ |
| 20486 | 20510 | ** no longer required. |
| 20487 | 20511 | ** |
| 20488 | 20512 | ** If a malloc failure occurs, NULL is returned and the db.mallocFailed |
| 20489 | 20513 | ** flag set. |
| 20490 | 20514 | */ |
| 20491 | | -#ifdef SQLITE_ENABLE_STAT3 |
| 20515 | +#ifdef SQLITE_ENABLE_STAT2 |
| 20492 | 20516 | SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *db, u8 enc, char *z, int n, int *pnOut){ |
| 20493 | 20517 | Mem m; |
| 20494 | 20518 | memset(&m, 0, sizeof(m)); |
| 20495 | 20519 | m.db = db; |
| 20496 | 20520 | sqlite3VdbeMemSetStr(&m, z, n, SQLITE_UTF8, SQLITE_STATIC); |
| | @@ -20600,10 +20624,11 @@ |
| 20600 | 20624 | ** |
| 20601 | 20625 | ** This file contains functions for allocating memory, comparing |
| 20602 | 20626 | ** strings, and stuff like that. |
| 20603 | 20627 | ** |
| 20604 | 20628 | */ |
| 20629 | +/* #include <stdarg.h> */ |
| 20605 | 20630 | #ifdef SQLITE_HAVE_ISNAN |
| 20606 | 20631 | # include <math.h> |
| 20607 | 20632 | #endif |
| 20608 | 20633 | |
| 20609 | 20634 | /* |
| | @@ -21778,10 +21803,11 @@ |
| 21778 | 21803 | ** |
| 21779 | 21804 | ************************************************************************* |
| 21780 | 21805 | ** This is the implementation of generic hash-tables |
| 21781 | 21806 | ** used in SQLite. |
| 21782 | 21807 | */ |
| 21808 | +/* #include <assert.h> */ |
| 21783 | 21809 | |
| 21784 | 21810 | /* Turn bulk memory into a hash table object by initializing the |
| 21785 | 21811 | ** fields of the Hash structure. |
| 21786 | 21812 | ** |
| 21787 | 21813 | ** "pNew" is a pointer to the hash table that is to be initialized. |
| | @@ -22088,50 +22114,50 @@ |
| 22088 | 22114 | /* 37 */ "VerifyCookie", |
| 22089 | 22115 | /* 38 */ "OpenRead", |
| 22090 | 22116 | /* 39 */ "OpenWrite", |
| 22091 | 22117 | /* 40 */ "OpenAutoindex", |
| 22092 | 22118 | /* 41 */ "OpenEphemeral", |
| 22093 | | - /* 42 */ "OpenPseudo", |
| 22094 | | - /* 43 */ "Close", |
| 22095 | | - /* 44 */ "SeekLt", |
| 22096 | | - /* 45 */ "SeekLe", |
| 22097 | | - /* 46 */ "SeekGe", |
| 22098 | | - /* 47 */ "SeekGt", |
| 22099 | | - /* 48 */ "Seek", |
| 22100 | | - /* 49 */ "NotFound", |
| 22101 | | - /* 50 */ "Found", |
| 22102 | | - /* 51 */ "IsUnique", |
| 22103 | | - /* 52 */ "NotExists", |
| 22104 | | - /* 53 */ "Sequence", |
| 22105 | | - /* 54 */ "NewRowid", |
| 22106 | | - /* 55 */ "Insert", |
| 22107 | | - /* 56 */ "InsertInt", |
| 22108 | | - /* 57 */ "Delete", |
| 22109 | | - /* 58 */ "ResetCount", |
| 22110 | | - /* 59 */ "RowKey", |
| 22111 | | - /* 60 */ "RowData", |
| 22112 | | - /* 61 */ "Rowid", |
| 22113 | | - /* 62 */ "NullRow", |
| 22114 | | - /* 63 */ "Last", |
| 22115 | | - /* 64 */ "Sort", |
| 22116 | | - /* 65 */ "Rewind", |
| 22117 | | - /* 66 */ "Prev", |
| 22118 | | - /* 67 */ "Next", |
| 22119 | + /* 42 */ "SorterOpen", |
| 22120 | + /* 43 */ "OpenPseudo", |
| 22121 | + /* 44 */ "Close", |
| 22122 | + /* 45 */ "SeekLt", |
| 22123 | + /* 46 */ "SeekLe", |
| 22124 | + /* 47 */ "SeekGe", |
| 22125 | + /* 48 */ "SeekGt", |
| 22126 | + /* 49 */ "Seek", |
| 22127 | + /* 50 */ "NotFound", |
| 22128 | + /* 51 */ "Found", |
| 22129 | + /* 52 */ "IsUnique", |
| 22130 | + /* 53 */ "NotExists", |
| 22131 | + /* 54 */ "Sequence", |
| 22132 | + /* 55 */ "NewRowid", |
| 22133 | + /* 56 */ "Insert", |
| 22134 | + /* 57 */ "InsertInt", |
| 22135 | + /* 58 */ "Delete", |
| 22136 | + /* 59 */ "ResetCount", |
| 22137 | + /* 60 */ "SorterCompare", |
| 22138 | + /* 61 */ "SorterData", |
| 22139 | + /* 62 */ "RowKey", |
| 22140 | + /* 63 */ "RowData", |
| 22141 | + /* 64 */ "Rowid", |
| 22142 | + /* 65 */ "NullRow", |
| 22143 | + /* 66 */ "Last", |
| 22144 | + /* 67 */ "SorterSort", |
| 22119 | 22145 | /* 68 */ "Or", |
| 22120 | 22146 | /* 69 */ "And", |
| 22121 | | - /* 70 */ "IdxInsert", |
| 22122 | | - /* 71 */ "IdxDelete", |
| 22123 | | - /* 72 */ "IdxRowid", |
| 22147 | + /* 70 */ "Sort", |
| 22148 | + /* 71 */ "Rewind", |
| 22149 | + /* 72 */ "SorterNext", |
| 22124 | 22150 | /* 73 */ "IsNull", |
| 22125 | 22151 | /* 74 */ "NotNull", |
| 22126 | 22152 | /* 75 */ "Ne", |
| 22127 | 22153 | /* 76 */ "Eq", |
| 22128 | 22154 | /* 77 */ "Gt", |
| 22129 | 22155 | /* 78 */ "Le", |
| 22130 | 22156 | /* 79 */ "Lt", |
| 22131 | 22157 | /* 80 */ "Ge", |
| 22132 | | - /* 81 */ "IdxLT", |
| 22158 | + /* 81 */ "Prev", |
| 22133 | 22159 | /* 82 */ "BitAnd", |
| 22134 | 22160 | /* 83 */ "BitOr", |
| 22135 | 22161 | /* 84 */ "ShiftLeft", |
| 22136 | 22162 | /* 85 */ "ShiftRight", |
| 22137 | 22163 | /* 86 */ "Add", |
| | @@ -22138,64 +22164,68 @@ |
| 22138 | 22164 | /* 87 */ "Subtract", |
| 22139 | 22165 | /* 88 */ "Multiply", |
| 22140 | 22166 | /* 89 */ "Divide", |
| 22141 | 22167 | /* 90 */ "Remainder", |
| 22142 | 22168 | /* 91 */ "Concat", |
| 22143 | | - /* 92 */ "IdxGE", |
| 22169 | + /* 92 */ "Next", |
| 22144 | 22170 | /* 93 */ "BitNot", |
| 22145 | 22171 | /* 94 */ "String8", |
| 22146 | | - /* 95 */ "Destroy", |
| 22147 | | - /* 96 */ "Clear", |
| 22148 | | - /* 97 */ "CreateIndex", |
| 22149 | | - /* 98 */ "CreateTable", |
| 22150 | | - /* 99 */ "ParseSchema", |
| 22151 | | - /* 100 */ "LoadAnalysis", |
| 22152 | | - /* 101 */ "DropTable", |
| 22153 | | - /* 102 */ "DropIndex", |
| 22154 | | - /* 103 */ "DropTrigger", |
| 22155 | | - /* 104 */ "IntegrityCk", |
| 22156 | | - /* 105 */ "RowSetAdd", |
| 22157 | | - /* 106 */ "RowSetRead", |
| 22158 | | - /* 107 */ "RowSetTest", |
| 22159 | | - /* 108 */ "Program", |
| 22160 | | - /* 109 */ "Param", |
| 22161 | | - /* 110 */ "FkCounter", |
| 22162 | | - /* 111 */ "FkIfZero", |
| 22163 | | - /* 112 */ "MemMax", |
| 22164 | | - /* 113 */ "IfPos", |
| 22165 | | - /* 114 */ "IfNeg", |
| 22166 | | - /* 115 */ "IfZero", |
| 22167 | | - /* 116 */ "AggStep", |
| 22168 | | - /* 117 */ "AggFinal", |
| 22169 | | - /* 118 */ "Checkpoint", |
| 22170 | | - /* 119 */ "JournalMode", |
| 22171 | | - /* 120 */ "Vacuum", |
| 22172 | | - /* 121 */ "IncrVacuum", |
| 22173 | | - /* 122 */ "Expire", |
| 22174 | | - /* 123 */ "TableLock", |
| 22175 | | - /* 124 */ "VBegin", |
| 22176 | | - /* 125 */ "VCreate", |
| 22177 | | - /* 126 */ "VDestroy", |
| 22178 | | - /* 127 */ "VOpen", |
| 22179 | | - /* 128 */ "VFilter", |
| 22180 | | - /* 129 */ "VColumn", |
| 22172 | + /* 95 */ "SorterInsert", |
| 22173 | + /* 96 */ "IdxInsert", |
| 22174 | + /* 97 */ "IdxDelete", |
| 22175 | + /* 98 */ "IdxRowid", |
| 22176 | + /* 99 */ "IdxLT", |
| 22177 | + /* 100 */ "IdxGE", |
| 22178 | + /* 101 */ "Destroy", |
| 22179 | + /* 102 */ "Clear", |
| 22180 | + /* 103 */ "CreateIndex", |
| 22181 | + /* 104 */ "CreateTable", |
| 22182 | + /* 105 */ "ParseSchema", |
| 22183 | + /* 106 */ "LoadAnalysis", |
| 22184 | + /* 107 */ "DropTable", |
| 22185 | + /* 108 */ "DropIndex", |
| 22186 | + /* 109 */ "DropTrigger", |
| 22187 | + /* 110 */ "IntegrityCk", |
| 22188 | + /* 111 */ "RowSetAdd", |
| 22189 | + /* 112 */ "RowSetRead", |
| 22190 | + /* 113 */ "RowSetTest", |
| 22191 | + /* 114 */ "Program", |
| 22192 | + /* 115 */ "Param", |
| 22193 | + /* 116 */ "FkCounter", |
| 22194 | + /* 117 */ "FkIfZero", |
| 22195 | + /* 118 */ "MemMax", |
| 22196 | + /* 119 */ "IfPos", |
| 22197 | + /* 120 */ "IfNeg", |
| 22198 | + /* 121 */ "IfZero", |
| 22199 | + /* 122 */ "AggStep", |
| 22200 | + /* 123 */ "AggFinal", |
| 22201 | + /* 124 */ "Checkpoint", |
| 22202 | + /* 125 */ "JournalMode", |
| 22203 | + /* 126 */ "Vacuum", |
| 22204 | + /* 127 */ "IncrVacuum", |
| 22205 | + /* 128 */ "Expire", |
| 22206 | + /* 129 */ "TableLock", |
| 22181 | 22207 | /* 130 */ "Real", |
| 22182 | | - /* 131 */ "VNext", |
| 22183 | | - /* 132 */ "VRename", |
| 22184 | | - /* 133 */ "VUpdate", |
| 22185 | | - /* 134 */ "Pagecount", |
| 22186 | | - /* 135 */ "MaxPgcnt", |
| 22187 | | - /* 136 */ "Trace", |
| 22188 | | - /* 137 */ "Noop", |
| 22189 | | - /* 138 */ "Explain", |
| 22190 | | - /* 139 */ "NotUsed_139", |
| 22191 | | - /* 140 */ "NotUsed_140", |
| 22208 | + /* 131 */ "VBegin", |
| 22209 | + /* 132 */ "VCreate", |
| 22210 | + /* 133 */ "VDestroy", |
| 22211 | + /* 134 */ "VOpen", |
| 22212 | + /* 135 */ "VFilter", |
| 22213 | + /* 136 */ "VColumn", |
| 22214 | + /* 137 */ "VNext", |
| 22215 | + /* 138 */ "VRename", |
| 22216 | + /* 139 */ "VUpdate", |
| 22217 | + /* 140 */ "Pagecount", |
| 22192 | 22218 | /* 141 */ "ToText", |
| 22193 | 22219 | /* 142 */ "ToBlob", |
| 22194 | 22220 | /* 143 */ "ToNumeric", |
| 22195 | 22221 | /* 144 */ "ToInt", |
| 22196 | 22222 | /* 145 */ "ToReal", |
| 22223 | + /* 146 */ "MaxPgcnt", |
| 22224 | + /* 147 */ "Trace", |
| 22225 | + /* 148 */ "Noop", |
| 22226 | + /* 149 */ "Explain", |
| 22197 | 22227 | }; |
| 22198 | 22228 | return azName[i]; |
| 22199 | 22229 | } |
| 22200 | 22230 | #endif |
| 22201 | 22231 | |
| | @@ -22286,11 +22316,11 @@ |
| 22286 | 22316 | */ |
| 22287 | 22317 | #ifdef MEMORY_DEBUG |
| 22288 | 22318 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 22289 | 22319 | #endif |
| 22290 | 22320 | |
| 22291 | | -#ifdef SQLITE_DEBUG |
| 22321 | +#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 22292 | 22322 | # ifndef SQLITE_DEBUG_OS_TRACE |
| 22293 | 22323 | # define SQLITE_DEBUG_OS_TRACE 0 |
| 22294 | 22324 | # endif |
| 22295 | 22325 | int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; |
| 22296 | 22326 | # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X |
| | @@ -24450,10 +24480,11 @@ |
| 24450 | 24480 | */ |
| 24451 | 24481 | #include <sys/types.h> |
| 24452 | 24482 | #include <sys/stat.h> |
| 24453 | 24483 | #include <fcntl.h> |
| 24454 | 24484 | #include <unistd.h> |
| 24485 | +/* #include <time.h> */ |
| 24455 | 24486 | #include <sys/time.h> |
| 24456 | 24487 | #include <errno.h> |
| 24457 | 24488 | #ifndef SQLITE_OMIT_WAL |
| 24458 | 24489 | #include <sys/mman.h> |
| 24459 | 24490 | #endif |
| | @@ -24485,10 +24516,11 @@ |
| 24485 | 24516 | /* |
| 24486 | 24517 | ** If we are to be thread-safe, include the pthreads header and define |
| 24487 | 24518 | ** the SQLITE_UNIX_THREADS macro. |
| 24488 | 24519 | */ |
| 24489 | 24520 | #if SQLITE_THREADSAFE |
| 24521 | +/* # include <pthread.h> */ |
| 24490 | 24522 | # define SQLITE_UNIX_THREADS 1 |
| 24491 | 24523 | #endif |
| 24492 | 24524 | |
| 24493 | 24525 | /* |
| 24494 | 24526 | ** Default permissions when creating a new file |
| | @@ -24584,11 +24616,15 @@ |
| 24584 | 24616 | ** Allowed values for the unixFile.ctrlFlags bitmask: |
| 24585 | 24617 | */ |
| 24586 | 24618 | #define UNIXFILE_EXCL 0x01 /* Connections from one process only */ |
| 24587 | 24619 | #define UNIXFILE_RDONLY 0x02 /* Connection is read only */ |
| 24588 | 24620 | #define UNIXFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */ |
| 24589 | | -#define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */ |
| 24621 | +#ifndef SQLITE_DISABLE_DIRSYNC |
| 24622 | +# define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */ |
| 24623 | +#else |
| 24624 | +# define UNIXFILE_DIRSYNC 0x00 |
| 24625 | +#endif |
| 24590 | 24626 | |
| 24591 | 24627 | /* |
| 24592 | 24628 | ** Include code that is common to all os_*.c files |
| 24593 | 24629 | */ |
| 24594 | 24630 | /************** Include os_common.h in the middle of os_unix.c ***************/ |
| | @@ -24622,11 +24658,11 @@ |
| 24622 | 24658 | */ |
| 24623 | 24659 | #ifdef MEMORY_DEBUG |
| 24624 | 24660 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 24625 | 24661 | #endif |
| 24626 | 24662 | |
| 24627 | | -#ifdef SQLITE_DEBUG |
| 24663 | +#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 24628 | 24664 | # ifndef SQLITE_DEBUG_OS_TRACE |
| 24629 | 24665 | # define SQLITE_DEBUG_OS_TRACE 0 |
| 24630 | 24666 | # endif |
| 24631 | 24667 | int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; |
| 24632 | 24668 | # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X |
| | @@ -27061,15 +27097,16 @@ |
| 27061 | 27097 | */ |
| 27062 | 27098 | static int afpCheckReservedLock(sqlite3_file *id, int *pResOut){ |
| 27063 | 27099 | int rc = SQLITE_OK; |
| 27064 | 27100 | int reserved = 0; |
| 27065 | 27101 | unixFile *pFile = (unixFile*)id; |
| 27102 | + afpLockingContext *context; |
| 27066 | 27103 | |
| 27067 | 27104 | SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); |
| 27068 | 27105 | |
| 27069 | 27106 | assert( pFile ); |
| 27070 | | - afpLockingContext *context = (afpLockingContext *) pFile->lockingContext; |
| 27107 | + context = (afpLockingContext *) pFile->lockingContext; |
| 27071 | 27108 | if( context->reserved ){ |
| 27072 | 27109 | *pResOut = 1; |
| 27073 | 27110 | return SQLITE_OK; |
| 27074 | 27111 | } |
| 27075 | 27112 | unixEnterMutex(); /* Because pFile->pInode is shared across threads */ |
| | @@ -27205,11 +27242,11 @@ |
| 27205 | 27242 | |
| 27206 | 27243 | /* If control gets to this point, then actually go ahead and make |
| 27207 | 27244 | ** operating system calls for the specified lock. |
| 27208 | 27245 | */ |
| 27209 | 27246 | if( eFileLock==SHARED_LOCK ){ |
| 27210 | | - int lrc1, lrc2, lrc1Errno; |
| 27247 | + int lrc1, lrc2, lrc1Errno = 0; |
| 27211 | 27248 | long lk, mask; |
| 27212 | 27249 | |
| 27213 | 27250 | assert( pInode->nShared==0 ); |
| 27214 | 27251 | assert( pInode->eFileLock==0 ); |
| 27215 | 27252 | |
| | @@ -27579,21 +27616,23 @@ |
| 27579 | 27616 | #if defined(USE_PREAD) |
| 27580 | 27617 | do{ got = osPwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); |
| 27581 | 27618 | #elif defined(USE_PREAD64) |
| 27582 | 27619 | do{ got = osPwrite64(id->h, pBuf, cnt, offset);}while( got<0 && errno==EINTR); |
| 27583 | 27620 | #else |
| 27584 | | - newOffset = lseek(id->h, offset, SEEK_SET); |
| 27585 | | - SimulateIOError( newOffset-- ); |
| 27586 | | - if( newOffset!=offset ){ |
| 27587 | | - if( newOffset == -1 ){ |
| 27588 | | - ((unixFile*)id)->lastErrno = errno; |
| 27589 | | - }else{ |
| 27590 | | - ((unixFile*)id)->lastErrno = 0; |
| 27591 | | - } |
| 27592 | | - return -1; |
| 27593 | | - } |
| 27594 | | - do{ got = osWrite(id->h, pBuf, cnt); }while( got<0 && errno==EINTR ); |
| 27621 | + do{ |
| 27622 | + newOffset = lseek(id->h, offset, SEEK_SET); |
| 27623 | + SimulateIOError( newOffset-- ); |
| 27624 | + if( newOffset!=offset ){ |
| 27625 | + if( newOffset == -1 ){ |
| 27626 | + ((unixFile*)id)->lastErrno = errno; |
| 27627 | + }else{ |
| 27628 | + ((unixFile*)id)->lastErrno = 0; |
| 27629 | + } |
| 27630 | + return -1; |
| 27631 | + } |
| 27632 | + got = osWrite(id->h, pBuf, cnt); |
| 27633 | + }while( got<0 && errno==EINTR ); |
| 27595 | 27634 | #endif |
| 27596 | 27635 | TIMER_END; |
| 27597 | 27636 | if( got<0 ){ |
| 27598 | 27637 | ((unixFile*)id)->lastErrno = errno; |
| 27599 | 27638 | } |
| | @@ -27679,15 +27718,15 @@ |
| 27679 | 27718 | SQLITE_API int sqlite3_fullsync_count = 0; |
| 27680 | 27719 | #endif |
| 27681 | 27720 | |
| 27682 | 27721 | /* |
| 27683 | 27722 | ** We do not trust systems to provide a working fdatasync(). Some do. |
| 27684 | | -** Others do no. To be safe, we will stick with the (slower) fsync(). |
| 27685 | | -** If you know that your system does support fdatasync() correctly, |
| 27723 | +** Others do no. To be safe, we will stick with the (slightly slower) |
| 27724 | +** fsync(). If you know that your system does support fdatasync() correctly, |
| 27686 | 27725 | ** then simply compile with -Dfdatasync=fdatasync |
| 27687 | 27726 | */ |
| 27688 | | -#if !defined(fdatasync) && !defined(__linux__) |
| 27727 | +#if !defined(fdatasync) |
| 27689 | 27728 | # define fdatasync fsync |
| 27690 | 27729 | #endif |
| 27691 | 27730 | |
| 27692 | 27731 | /* |
| 27693 | 27732 | ** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not |
| | @@ -27888,10 +27927,12 @@ |
| 27888 | 27927 | HAVE_FULLFSYNC, isFullsync)); |
| 27889 | 27928 | rc = osOpenDirectory(pFile->zPath, &dirfd); |
| 27890 | 27929 | if( rc==SQLITE_OK && dirfd>=0 ){ |
| 27891 | 27930 | full_fsync(dirfd, 0, 0); |
| 27892 | 27931 | robust_close(pFile, dirfd, __LINE__); |
| 27932 | + }else if( rc==SQLITE_CANTOPEN ){ |
| 27933 | + rc = SQLITE_OK; |
| 27893 | 27934 | } |
| 27894 | 27935 | pFile->ctrlFlags &= ~UNIXFILE_DIRSYNC; |
| 27895 | 27936 | } |
| 27896 | 27937 | return rc; |
| 27897 | 27938 | } |
| | @@ -27971,30 +28012,22 @@ |
| 27971 | 28012 | static int proxyFileControl(sqlite3_file*,int,void*); |
| 27972 | 28013 | #endif |
| 27973 | 28014 | |
| 27974 | 28015 | /* |
| 27975 | 28016 | ** This function is called to handle the SQLITE_FCNTL_SIZE_HINT |
| 27976 | | -** file-control operation. |
| 27977 | | -** |
| 27978 | | -** If the user has configured a chunk-size for this file, it could be |
| 27979 | | -** that the file needs to be extended at this point. Otherwise, the |
| 27980 | | -** SQLITE_FCNTL_SIZE_HINT operation is a no-op for Unix. |
| 28017 | +** file-control operation. Enlarge the database to nBytes in size |
| 28018 | +** (rounded up to the next chunk-size). If the database is already |
| 28019 | +** nBytes or larger, this routine is a no-op. |
| 27981 | 28020 | */ |
| 27982 | 28021 | static int fcntlSizeHint(unixFile *pFile, i64 nByte){ |
| 27983 | | - { /* preserve indentation of removed "if" */ |
| 28022 | + if( pFile->szChunk>0 ){ |
| 27984 | 28023 | i64 nSize; /* Required file size */ |
| 27985 | | - i64 szChunk; /* Chunk size */ |
| 27986 | 28024 | struct stat buf; /* Used to hold return values of fstat() */ |
| 27987 | 28025 | |
| 27988 | 28026 | if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT; |
| 27989 | 28027 | |
| 27990 | | - szChunk = pFile->szChunk; |
| 27991 | | - if( szChunk==0 ){ |
| 27992 | | - nSize = nByte; |
| 27993 | | - }else{ |
| 27994 | | - nSize = ((nByte+szChunk-1) / szChunk) * szChunk; |
| 27995 | | - } |
| 28028 | + nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk; |
| 27996 | 28029 | if( nSize>(i64)buf.st_size ){ |
| 27997 | 28030 | |
| 27998 | 28031 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 27999 | 28032 | /* The code below is handling the return value of osFallocate() |
| 28000 | 28033 | ** correctly. posix_fallocate() is defined to "returns zero on success, |
| | @@ -28048,11 +28081,15 @@ |
| 28048 | 28081 | case SQLITE_FCNTL_CHUNK_SIZE: { |
| 28049 | 28082 | pFile->szChunk = *(int *)pArg; |
| 28050 | 28083 | return SQLITE_OK; |
| 28051 | 28084 | } |
| 28052 | 28085 | case SQLITE_FCNTL_SIZE_HINT: { |
| 28053 | | - return fcntlSizeHint(pFile, *(i64 *)pArg); |
| 28086 | + int rc; |
| 28087 | + SimulateIOErrorBenign(1); |
| 28088 | + rc = fcntlSizeHint(pFile, *(i64 *)pArg); |
| 28089 | + SimulateIOErrorBenign(0); |
| 28090 | + return rc; |
| 28054 | 28091 | } |
| 28055 | 28092 | case SQLITE_FCNTL_PERSIST_WAL: { |
| 28056 | 28093 | int bPersist = *(int*)pArg; |
| 28057 | 28094 | if( bPersist<0 ){ |
| 28058 | 28095 | *(int*)pArg = (pFile->ctrlFlags & UNIXFILE_PERSIST_WAL)!=0; |
| | @@ -28175,15 +28212,13 @@ |
| 28175 | 28212 | */ |
| 28176 | 28213 | struct unixShm { |
| 28177 | 28214 | unixShmNode *pShmNode; /* The underlying unixShmNode object */ |
| 28178 | 28215 | unixShm *pNext; /* Next unixShm with the same unixShmNode */ |
| 28179 | 28216 | u8 hasMutex; /* True if holding the unixShmNode mutex */ |
| 28217 | + u8 id; /* Id of this connection within its unixShmNode */ |
| 28180 | 28218 | u16 sharedMask; /* Mask of shared locks held */ |
| 28181 | 28219 | u16 exclMask; /* Mask of exclusive locks held */ |
| 28182 | | -#ifdef SQLITE_DEBUG |
| 28183 | | - u8 id; /* Id of this connection within its unixShmNode */ |
| 28184 | | -#endif |
| 28185 | 28220 | }; |
| 28186 | 28221 | |
| 28187 | 28222 | /* |
| 28188 | 28223 | ** Constants used for locking |
| 28189 | 28224 | */ |
| | @@ -29485,10 +29520,13 @@ |
| 29485 | 29520 | int isReadonly = (flags & SQLITE_OPEN_READONLY); |
| 29486 | 29521 | int isReadWrite = (flags & SQLITE_OPEN_READWRITE); |
| 29487 | 29522 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 29488 | 29523 | int isAutoProxy = (flags & SQLITE_OPEN_AUTOPROXY); |
| 29489 | 29524 | #endif |
| 29525 | +#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE |
| 29526 | + struct statfs fsInfo; |
| 29527 | +#endif |
| 29490 | 29528 | |
| 29491 | 29529 | /* If creating a master or main-file journal, this function will open |
| 29492 | 29530 | ** a file-descriptor on the directory too. The first time unixSync() |
| 29493 | 29531 | ** is called the directory file descriptor will be fsync()ed and close()d. |
| 29494 | 29532 | */ |
| | @@ -29617,11 +29655,10 @@ |
| 29617 | 29655 | |
| 29618 | 29656 | noLock = eType!=SQLITE_OPEN_MAIN_DB; |
| 29619 | 29657 | |
| 29620 | 29658 | |
| 29621 | 29659 | #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE |
| 29622 | | - struct statfs fsInfo; |
| 29623 | 29660 | if( fstatfs(fd, &fsInfo) == -1 ){ |
| 29624 | 29661 | ((unixFile*)pFile)->lastErrno = errno; |
| 29625 | 29662 | robust_close(p, fd, __LINE__); |
| 29626 | 29663 | return SQLITE_IOERR_ACCESS; |
| 29627 | 29664 | } |
| | @@ -29641,11 +29678,10 @@ |
| 29641 | 29678 | /* SQLITE_FORCE_PROXY_LOCKING==1 means force always use proxy, 0 means |
| 29642 | 29679 | ** never use proxy, NULL means use proxy for non-local files only. */ |
| 29643 | 29680 | if( envforce!=NULL ){ |
| 29644 | 29681 | useProxy = atoi(envforce)>0; |
| 29645 | 29682 | }else{ |
| 29646 | | - struct statfs fsInfo; |
| 29647 | 29683 | if( statfs(zPath, &fsInfo) == -1 ){ |
| 29648 | 29684 | /* In theory, the close(fd) call is sub-optimal. If the file opened |
| 29649 | 29685 | ** with fd is a database file, and there are other connections open |
| 29650 | 29686 | ** on that file that are currently holding advisory locks on it, |
| 29651 | 29687 | ** then the call to close() will cancel those locks. In practice, |
| | @@ -29715,10 +29751,12 @@ |
| 29715 | 29751 | #endif |
| 29716 | 29752 | { |
| 29717 | 29753 | rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath); |
| 29718 | 29754 | } |
| 29719 | 29755 | robust_close(0, fd, __LINE__); |
| 29756 | + }else if( rc==SQLITE_CANTOPEN ){ |
| 29757 | + rc = SQLITE_OK; |
| 29720 | 29758 | } |
| 29721 | 29759 | } |
| 29722 | 29760 | #endif |
| 29723 | 29761 | return rc; |
| 29724 | 29762 | } |
| | @@ -30380,10 +30418,12 @@ |
| 30380 | 30418 | *pError = err; |
| 30381 | 30419 | } |
| 30382 | 30420 | return SQLITE_IOERR; |
| 30383 | 30421 | } |
| 30384 | 30422 | } |
| 30423 | +#else |
| 30424 | + UNUSED_PARAMETER(pError); |
| 30385 | 30425 | #endif |
| 30386 | 30426 | #ifdef SQLITE_TEST |
| 30387 | 30427 | /* simulate multiple hosts by creating unique hostid file paths */ |
| 30388 | 30428 | if( sqlite3_hostid_num != 0){ |
| 30389 | 30429 | pHostID[0] = (char)(pHostID[0] + (char)(sqlite3_hostid_num & 0xFF)); |
| | @@ -30472,10 +30512,11 @@ |
| 30472 | 30512 | unixFile *conchFile = pCtx->conchFile; |
| 30473 | 30513 | int rc = SQLITE_OK; |
| 30474 | 30514 | int nTries = 0; |
| 30475 | 30515 | struct timespec conchModTime; |
| 30476 | 30516 | |
| 30517 | + memset(&conchModTime, 0, sizeof(conchModTime)); |
| 30477 | 30518 | do { |
| 30478 | 30519 | rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, lockType); |
| 30479 | 30520 | nTries ++; |
| 30480 | 30521 | if( rc==SQLITE_BUSY ){ |
| 30481 | 30522 | /* If the lock failed (busy): |
| | @@ -30703,15 +30744,16 @@ |
| 30703 | 30744 | conchFile->pMethod->xUnlock((sqlite3_file*)conchFile, SHARED_LOCK); |
| 30704 | 30745 | |
| 30705 | 30746 | end_takeconch: |
| 30706 | 30747 | OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h)); |
| 30707 | 30748 | if( rc==SQLITE_OK && pFile->openFlags ){ |
| 30749 | + int fd; |
| 30708 | 30750 | if( pFile->h>=0 ){ |
| 30709 | 30751 | robust_close(pFile, pFile->h, __LINE__); |
| 30710 | 30752 | } |
| 30711 | 30753 | pFile->h = -1; |
| 30712 | | - int fd = robust_open(pCtx->dbPath, pFile->openFlags, |
| 30754 | + fd = robust_open(pCtx->dbPath, pFile->openFlags, |
| 30713 | 30755 | SQLITE_DEFAULT_FILE_PERMISSIONS); |
| 30714 | 30756 | OSTRACE(("TRANSPROXY: OPEN %d\n", fd)); |
| 30715 | 30757 | if( fd>=0 ){ |
| 30716 | 30758 | pFile->h = fd; |
| 30717 | 30759 | }else{ |
| | @@ -31393,11 +31435,11 @@ |
| 31393 | 31435 | */ |
| 31394 | 31436 | #ifdef MEMORY_DEBUG |
| 31395 | 31437 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 31396 | 31438 | #endif |
| 31397 | 31439 | |
| 31398 | | -#ifdef SQLITE_DEBUG |
| 31440 | +#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 31399 | 31441 | # ifndef SQLITE_DEBUG_OS_TRACE |
| 31400 | 31442 | # define SQLITE_DEBUG_OS_TRACE 0 |
| 31401 | 31443 | # endif |
| 31402 | 31444 | int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; |
| 31403 | 31445 | # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X |
| | @@ -31629,10 +31671,80 @@ |
| 31629 | 31671 | winceLock local; /* Locks obtained by this instance of winFile */ |
| 31630 | 31672 | winceLock *shared; /* Global shared lock memory for the file */ |
| 31631 | 31673 | #endif |
| 31632 | 31674 | }; |
| 31633 | 31675 | |
| 31676 | +/* |
| 31677 | + * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the |
| 31678 | + * various Win32 API heap functions instead of our own. |
| 31679 | + */ |
| 31680 | +#ifdef SQLITE_WIN32_MALLOC |
| 31681 | +/* |
| 31682 | + * The initial size of the Win32-specific heap. This value may be zero. |
| 31683 | + */ |
| 31684 | +#ifndef SQLITE_WIN32_HEAP_INIT_SIZE |
| 31685 | +# define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_DEFAULT_CACHE_SIZE) * \ |
| 31686 | + (SQLITE_DEFAULT_PAGE_SIZE) + 4194304) |
| 31687 | +#endif |
| 31688 | + |
| 31689 | +/* |
| 31690 | + * The maximum size of the Win32-specific heap. This value may be zero. |
| 31691 | + */ |
| 31692 | +#ifndef SQLITE_WIN32_HEAP_MAX_SIZE |
| 31693 | +# define SQLITE_WIN32_HEAP_MAX_SIZE (0) |
| 31694 | +#endif |
| 31695 | + |
| 31696 | +/* |
| 31697 | + * The extra flags to use in calls to the Win32 heap APIs. This value may be |
| 31698 | + * zero for the default behavior. |
| 31699 | + */ |
| 31700 | +#ifndef SQLITE_WIN32_HEAP_FLAGS |
| 31701 | +# define SQLITE_WIN32_HEAP_FLAGS (0) |
| 31702 | +#endif |
| 31703 | + |
| 31704 | +/* |
| 31705 | +** The winMemData structure stores information required by the Win32-specific |
| 31706 | +** sqlite3_mem_methods implementation. |
| 31707 | +*/ |
| 31708 | +typedef struct winMemData winMemData; |
| 31709 | +struct winMemData { |
| 31710 | +#ifndef NDEBUG |
| 31711 | + u32 magic; /* Magic number to detect structure corruption. */ |
| 31712 | +#endif |
| 31713 | + HANDLE hHeap; /* The handle to our heap. */ |
| 31714 | + BOOL bOwned; /* Do we own the heap (i.e. destroy it on shutdown)? */ |
| 31715 | +}; |
| 31716 | + |
| 31717 | +#ifndef NDEBUG |
| 31718 | +#define WINMEM_MAGIC 0x42b2830b |
| 31719 | +#endif |
| 31720 | + |
| 31721 | +static struct winMemData win_mem_data = { |
| 31722 | +#ifndef NDEBUG |
| 31723 | + WINMEM_MAGIC, |
| 31724 | +#endif |
| 31725 | + NULL, FALSE |
| 31726 | +}; |
| 31727 | + |
| 31728 | +#ifndef NDEBUG |
| 31729 | +#define winMemAssertMagic() assert( win_mem_data.magic==WINMEM_MAGIC ) |
| 31730 | +#else |
| 31731 | +#define winMemAssertMagic() |
| 31732 | +#endif |
| 31733 | + |
| 31734 | +#define winMemGetHeap() win_mem_data.hHeap |
| 31735 | + |
| 31736 | +static void *winMemMalloc(int nBytes); |
| 31737 | +static void winMemFree(void *pPrior); |
| 31738 | +static void *winMemRealloc(void *pPrior, int nBytes); |
| 31739 | +static int winMemSize(void *p); |
| 31740 | +static int winMemRoundup(int n); |
| 31741 | +static int winMemInit(void *pAppData); |
| 31742 | +static void winMemShutdown(void *pAppData); |
| 31743 | + |
| 31744 | +SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetWin32(void); |
| 31745 | +#endif /* SQLITE_WIN32_MALLOC */ |
| 31634 | 31746 | |
| 31635 | 31747 | /* |
| 31636 | 31748 | ** Forward prototypes. |
| 31637 | 31749 | */ |
| 31638 | 31750 | static int getSectorSize( |
| | @@ -31681,10 +31793,192 @@ |
| 31681 | 31793 | } |
| 31682 | 31794 | return sqlite3_os_type==2; |
| 31683 | 31795 | } |
| 31684 | 31796 | #endif /* SQLITE_OS_WINCE */ |
| 31685 | 31797 | |
| 31798 | +#ifdef SQLITE_WIN32_MALLOC |
| 31799 | +/* |
| 31800 | +** Allocate nBytes of memory. |
| 31801 | +*/ |
| 31802 | +static void *winMemMalloc(int nBytes){ |
| 31803 | + HANDLE hHeap; |
| 31804 | + void *p; |
| 31805 | + |
| 31806 | + winMemAssertMagic(); |
| 31807 | + hHeap = winMemGetHeap(); |
| 31808 | + assert( hHeap!=0 ); |
| 31809 | + assert( hHeap!=INVALID_HANDLE_VALUE ); |
| 31810 | +#ifdef SQLITE_WIN32_MALLOC_VALIDATE |
| 31811 | + assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); |
| 31812 | +#endif |
| 31813 | + assert( nBytes>=0 ); |
| 31814 | + p = HeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes); |
| 31815 | + if( !p ){ |
| 31816 | + sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p", |
| 31817 | + nBytes, GetLastError(), (void*)hHeap); |
| 31818 | + } |
| 31819 | + return p; |
| 31820 | +} |
| 31821 | + |
| 31822 | +/* |
| 31823 | +** Free memory. |
| 31824 | +*/ |
| 31825 | +static void winMemFree(void *pPrior){ |
| 31826 | + HANDLE hHeap; |
| 31827 | + |
| 31828 | + winMemAssertMagic(); |
| 31829 | + hHeap = winMemGetHeap(); |
| 31830 | + assert( hHeap!=0 ); |
| 31831 | + assert( hHeap!=INVALID_HANDLE_VALUE ); |
| 31832 | +#ifdef SQLITE_WIN32_MALLOC_VALIDATE |
| 31833 | + assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); |
| 31834 | +#endif |
| 31835 | + if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */ |
| 31836 | + if( !HeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){ |
| 31837 | + sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p", |
| 31838 | + pPrior, GetLastError(), (void*)hHeap); |
| 31839 | + } |
| 31840 | +} |
| 31841 | + |
| 31842 | +/* |
| 31843 | +** Change the size of an existing memory allocation |
| 31844 | +*/ |
| 31845 | +static void *winMemRealloc(void *pPrior, int nBytes){ |
| 31846 | + HANDLE hHeap; |
| 31847 | + void *p; |
| 31848 | + |
| 31849 | + winMemAssertMagic(); |
| 31850 | + hHeap = winMemGetHeap(); |
| 31851 | + assert( hHeap!=0 ); |
| 31852 | + assert( hHeap!=INVALID_HANDLE_VALUE ); |
| 31853 | +#ifdef SQLITE_WIN32_MALLOC_VALIDATE |
| 31854 | + assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); |
| 31855 | +#endif |
| 31856 | + assert( nBytes>=0 ); |
| 31857 | + if( !pPrior ){ |
| 31858 | + p = HeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes); |
| 31859 | + }else{ |
| 31860 | + p = HeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes); |
| 31861 | + } |
| 31862 | + if( !p ){ |
| 31863 | + sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%d), heap=%p", |
| 31864 | + pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, GetLastError(), |
| 31865 | + (void*)hHeap); |
| 31866 | + } |
| 31867 | + return p; |
| 31868 | +} |
| 31869 | + |
| 31870 | +/* |
| 31871 | +** Return the size of an outstanding allocation, in bytes. |
| 31872 | +*/ |
| 31873 | +static int winMemSize(void *p){ |
| 31874 | + HANDLE hHeap; |
| 31875 | + SIZE_T n; |
| 31876 | + |
| 31877 | + winMemAssertMagic(); |
| 31878 | + hHeap = winMemGetHeap(); |
| 31879 | + assert( hHeap!=0 ); |
| 31880 | + assert( hHeap!=INVALID_HANDLE_VALUE ); |
| 31881 | +#ifdef SQLITE_WIN32_MALLOC_VALIDATE |
| 31882 | + assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); |
| 31883 | +#endif |
| 31884 | + if( !p ) return 0; |
| 31885 | + n = HeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p); |
| 31886 | + if( n==(SIZE_T)-1 ){ |
| 31887 | + sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p", |
| 31888 | + p, GetLastError(), (void*)hHeap); |
| 31889 | + return 0; |
| 31890 | + } |
| 31891 | + return (int)n; |
| 31892 | +} |
| 31893 | + |
| 31894 | +/* |
| 31895 | +** Round up a request size to the next valid allocation size. |
| 31896 | +*/ |
| 31897 | +static int winMemRoundup(int n){ |
| 31898 | + return n; |
| 31899 | +} |
| 31900 | + |
| 31901 | +/* |
| 31902 | +** Initialize this module. |
| 31903 | +*/ |
| 31904 | +static int winMemInit(void *pAppData){ |
| 31905 | + winMemData *pWinMemData = (winMemData *)pAppData; |
| 31906 | + |
| 31907 | + if( !pWinMemData ) return SQLITE_ERROR; |
| 31908 | + assert( pWinMemData->magic==WINMEM_MAGIC ); |
| 31909 | + if( !pWinMemData->hHeap ){ |
| 31910 | + pWinMemData->hHeap = HeapCreate(SQLITE_WIN32_HEAP_FLAGS, |
| 31911 | + SQLITE_WIN32_HEAP_INIT_SIZE, |
| 31912 | + SQLITE_WIN32_HEAP_MAX_SIZE); |
| 31913 | + if( !pWinMemData->hHeap ){ |
| 31914 | + sqlite3_log(SQLITE_NOMEM, |
| 31915 | + "failed to HeapCreate (%d), flags=%u, initSize=%u, maxSize=%u", |
| 31916 | + GetLastError(), SQLITE_WIN32_HEAP_FLAGS, SQLITE_WIN32_HEAP_INIT_SIZE, |
| 31917 | + SQLITE_WIN32_HEAP_MAX_SIZE); |
| 31918 | + return SQLITE_NOMEM; |
| 31919 | + } |
| 31920 | + pWinMemData->bOwned = TRUE; |
| 31921 | + } |
| 31922 | + assert( pWinMemData->hHeap!=0 ); |
| 31923 | + assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); |
| 31924 | +#ifdef SQLITE_WIN32_MALLOC_VALIDATE |
| 31925 | + assert( HeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); |
| 31926 | +#endif |
| 31927 | + return SQLITE_OK; |
| 31928 | +} |
| 31929 | + |
| 31930 | +/* |
| 31931 | +** Deinitialize this module. |
| 31932 | +*/ |
| 31933 | +static void winMemShutdown(void *pAppData){ |
| 31934 | + winMemData *pWinMemData = (winMemData *)pAppData; |
| 31935 | + |
| 31936 | + if( !pWinMemData ) return; |
| 31937 | + if( pWinMemData->hHeap ){ |
| 31938 | + assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); |
| 31939 | +#ifdef SQLITE_WIN32_MALLOC_VALIDATE |
| 31940 | + assert( HeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); |
| 31941 | +#endif |
| 31942 | + if( pWinMemData->bOwned ){ |
| 31943 | + if( !HeapDestroy(pWinMemData->hHeap) ){ |
| 31944 | + sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p", |
| 31945 | + GetLastError(), (void*)pWinMemData->hHeap); |
| 31946 | + } |
| 31947 | + pWinMemData->bOwned = FALSE; |
| 31948 | + } |
| 31949 | + pWinMemData->hHeap = NULL; |
| 31950 | + } |
| 31951 | +} |
| 31952 | + |
| 31953 | +/* |
| 31954 | +** Populate the low-level memory allocation function pointers in |
| 31955 | +** sqlite3GlobalConfig.m with pointers to the routines in this file. The |
| 31956 | +** arguments specify the block of memory to manage. |
| 31957 | +** |
| 31958 | +** This routine is only called by sqlite3_config(), and therefore |
| 31959 | +** is not required to be threadsafe (it is not). |
| 31960 | +*/ |
| 31961 | +SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetWin32(void){ |
| 31962 | + static const sqlite3_mem_methods winMemMethods = { |
| 31963 | + winMemMalloc, |
| 31964 | + winMemFree, |
| 31965 | + winMemRealloc, |
| 31966 | + winMemSize, |
| 31967 | + winMemRoundup, |
| 31968 | + winMemInit, |
| 31969 | + winMemShutdown, |
| 31970 | + &win_mem_data |
| 31971 | + }; |
| 31972 | + return &winMemMethods; |
| 31973 | +} |
| 31974 | + |
| 31975 | +SQLITE_PRIVATE void sqlite3MemSetDefault(void){ |
| 31976 | + sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetWin32()); |
| 31977 | +} |
| 31978 | +#endif /* SQLITE_WIN32_MALLOC */ |
| 31979 | + |
| 31686 | 31980 | /* |
| 31687 | 31981 | ** Convert a UTF-8 string to microsoft unicode (UTF-16?). |
| 31688 | 31982 | ** |
| 31689 | 31983 | ** Space to hold the returned string is obtained from malloc. |
| 31690 | 31984 | */ |
| | @@ -31969,10 +32263,11 @@ |
| 31969 | 32263 | */ |
| 31970 | 32264 | /* |
| 31971 | 32265 | ** WindowsCE does not have a localtime() function. So create a |
| 31972 | 32266 | ** substitute. |
| 31973 | 32267 | */ |
| 32268 | +/* #include <time.h> */ |
| 31974 | 32269 | struct tm *__cdecl localtime(const time_t *t) |
| 31975 | 32270 | { |
| 31976 | 32271 | static struct tm y; |
| 31977 | 32272 | FILETIME uTm, lTm; |
| 31978 | 32273 | SYSTEMTIME pTm; |
| | @@ -32473,11 +32768,11 @@ |
| 32473 | 32768 | /* If the user has configured a chunk-size for this file, truncate the |
| 32474 | 32769 | ** file so that it consists of an integer number of chunks (i.e. the |
| 32475 | 32770 | ** actual file size after the operation may be larger than the requested |
| 32476 | 32771 | ** size). |
| 32477 | 32772 | */ |
| 32478 | | - if( pFile->szChunk ){ |
| 32773 | + if( pFile->szChunk>0 ){ |
| 32479 | 32774 | nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; |
| 32480 | 32775 | } |
| 32481 | 32776 | |
| 32482 | 32777 | /* SetEndOfFile() returns non-zero when successful, or zero when it fails. */ |
| 32483 | 32778 | if( seekWinFile(pFile, nByte) ){ |
| | @@ -32860,14 +33155,23 @@ |
| 32860 | 33155 | case SQLITE_FCNTL_CHUNK_SIZE: { |
| 32861 | 33156 | pFile->szChunk = *(int *)pArg; |
| 32862 | 33157 | return SQLITE_OK; |
| 32863 | 33158 | } |
| 32864 | 33159 | case SQLITE_FCNTL_SIZE_HINT: { |
| 32865 | | - sqlite3_int64 sz = *(sqlite3_int64*)pArg; |
| 32866 | | - SimulateIOErrorBenign(1); |
| 32867 | | - winTruncate(id, sz); |
| 32868 | | - SimulateIOErrorBenign(0); |
| 33160 | + if( pFile->szChunk>0 ){ |
| 33161 | + sqlite3_int64 oldSz; |
| 33162 | + int rc = winFileSize(id, &oldSz); |
| 33163 | + if( rc==SQLITE_OK ){ |
| 33164 | + sqlite3_int64 newSz = *(sqlite3_int64*)pArg; |
| 33165 | + if( newSz>oldSz ){ |
| 33166 | + SimulateIOErrorBenign(1); |
| 33167 | + rc = winTruncate(id, newSz); |
| 33168 | + SimulateIOErrorBenign(0); |
| 33169 | + } |
| 33170 | + } |
| 33171 | + return rc; |
| 33172 | + } |
| 32869 | 33173 | return SQLITE_OK; |
| 32870 | 33174 | } |
| 32871 | 33175 | case SQLITE_FCNTL_PERSIST_WAL: { |
| 32872 | 33176 | int bPersist = *(int*)pArg; |
| 32873 | 33177 | if( bPersist<0 ){ |
| | @@ -35473,10 +35777,13 @@ |
| 35473 | 35777 | typedef struct PCache1 PCache1; |
| 35474 | 35778 | typedef struct PgHdr1 PgHdr1; |
| 35475 | 35779 | typedef struct PgFreeslot PgFreeslot; |
| 35476 | 35780 | typedef struct PGroup PGroup; |
| 35477 | 35781 | |
| 35782 | +typedef struct PGroupBlock PGroupBlock; |
| 35783 | +typedef struct PGroupBlockList PGroupBlockList; |
| 35784 | + |
| 35478 | 35785 | /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set |
| 35479 | 35786 | ** of one or more PCaches that are able to recycle each others unpinned |
| 35480 | 35787 | ** pages when they are under memory pressure. A PGroup is an instance of |
| 35481 | 35788 | ** the following object. |
| 35482 | 35789 | ** |
| | @@ -35502,12 +35809,70 @@ |
| 35502 | 35809 | int nMaxPage; /* Sum of nMax for purgeable caches */ |
| 35503 | 35810 | int nMinPage; /* Sum of nMin for purgeable caches */ |
| 35504 | 35811 | int mxPinned; /* nMaxpage + 10 - nMinPage */ |
| 35505 | 35812 | int nCurrentPage; /* Number of purgeable pages allocated */ |
| 35506 | 35813 | PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */ |
| 35814 | +#ifdef SQLITE_PAGECACHE_BLOCKALLOC |
| 35815 | + int isBusy; /* Do not run ReleaseMemory() if true */ |
| 35816 | + PGroupBlockList *pBlockList; /* List of block-lists for this group */ |
| 35817 | +#endif |
| 35507 | 35818 | }; |
| 35508 | 35819 | |
| 35820 | +/* |
| 35821 | +** If SQLITE_PAGECACHE_BLOCKALLOC is defined when the library is built, |
| 35822 | +** each PGroup structure has a linked list of the the following starting |
| 35823 | +** at PGroup.pBlockList. There is one entry for each distinct page-size |
| 35824 | +** currently used by members of the PGroup (i.e. 1024 bytes, 4096 bytes |
| 35825 | +** etc.). Variable PGroupBlockList.nByte is set to the actual allocation |
| 35826 | +** size requested by each pcache, which is the database page-size plus |
| 35827 | +** the various header structures used by the pcache, pager and btree layers. |
| 35828 | +** Usually around (pgsz+200) bytes. |
| 35829 | +** |
| 35830 | +** This size (pgsz+200) bytes is not allocated efficiently by some |
| 35831 | +** implementations of malloc. In particular, some implementations are only |
| 35832 | +** able to allocate blocks of memory chunks of 2^N bytes, where N is some |
| 35833 | +** integer value. Since the page-size is a power of 2, this means we |
| 35834 | +** end up wasting (pgsz-200) bytes in each allocation. |
| 35835 | +** |
| 35836 | +** If SQLITE_PAGECACHE_BLOCKALLOC is defined, the (pgsz+200) byte blocks |
| 35837 | +** are not allocated directly. Instead, blocks of roughly M*(pgsz+200) bytes |
| 35838 | +** are requested from malloc allocator. After a block is returned, |
| 35839 | +** sqlite3MallocSize() is used to determine how many (pgsz+200) byte |
| 35840 | +** allocations can fit in the space returned by malloc(). This value may |
| 35841 | +** be more than M. |
| 35842 | +** |
| 35843 | +** The blocks are stored in a doubly-linked list. Variable PGroupBlock.nEntry |
| 35844 | +** contains the number of allocations that will fit in the aData[] space. |
| 35845 | +** nEntry is limited to the number of bits in bitmask mUsed. If a slot |
| 35846 | +** within aData is in use, the corresponding bit in mUsed is set. Thus |
| 35847 | +** when (mUsed+1==(1 << nEntry)) the block is completely full. |
| 35848 | +** |
| 35849 | +** Each time a slot within a block is freed, the block is moved to the start |
| 35850 | +** of the linked-list. And if a block becomes completely full, then it is |
| 35851 | +** moved to the end of the list. As a result, when searching for a free |
| 35852 | +** slot, only the first block in the list need be examined. If it is full, |
| 35853 | +** then it is guaranteed that all blocks are full. |
| 35854 | +*/ |
| 35855 | +struct PGroupBlockList { |
| 35856 | + int nByte; /* Size of each allocation in bytes */ |
| 35857 | + PGroupBlock *pFirst; /* First PGroupBlock in list */ |
| 35858 | + PGroupBlock *pLast; /* Last PGroupBlock in list */ |
| 35859 | + PGroupBlockList *pNext; /* Next block-list attached to group */ |
| 35860 | +}; |
| 35861 | + |
| 35862 | +struct PGroupBlock { |
| 35863 | + Bitmask mUsed; /* Mask of used slots */ |
| 35864 | + int nEntry; /* Maximum number of allocations in aData[] */ |
| 35865 | + u8 *aData; /* Pointer to data block */ |
| 35866 | + PGroupBlock *pNext; /* Next PGroupBlock in list */ |
| 35867 | + PGroupBlock *pPrev; /* Previous PGroupBlock in list */ |
| 35868 | + PGroupBlockList *pList; /* Owner list */ |
| 35869 | +}; |
| 35870 | + |
| 35871 | +/* Minimum value for PGroupBlock.nEntry */ |
| 35872 | +#define PAGECACHE_BLOCKALLOC_MINENTRY 15 |
| 35873 | + |
| 35509 | 35874 | /* Each page cache is an instance of the following object. Every |
| 35510 | 35875 | ** open database file (including each in-memory database and each |
| 35511 | 35876 | ** temporary or transient database) has a single page cache which |
| 35512 | 35877 | ** is an instance of this object. |
| 35513 | 35878 | ** |
| | @@ -35606,10 +35971,21 @@ |
| 35606 | 35971 | ** |
| 35607 | 35972 | ** assert( PGHDR1_TO_PAGE(PAGE_TO_PGHDR1(pCache, X))==X ); |
| 35608 | 35973 | */ |
| 35609 | 35974 | #define PGHDR1_TO_PAGE(p) (void*)(((char*)p) - p->pCache->szPage) |
| 35610 | 35975 | #define PAGE_TO_PGHDR1(c, p) (PgHdr1*)(((char*)p) + c->szPage) |
| 35976 | + |
| 35977 | +/* |
| 35978 | +** Blocks used by the SQLITE_PAGECACHE_BLOCKALLOC blocks to store/retrieve |
| 35979 | +** a PGroupBlock pointer based on a pointer to a page buffer. |
| 35980 | +*/ |
| 35981 | +#define PAGE_SET_BLOCKPTR(pCache, pPg, pBlock) \ |
| 35982 | + ( *(PGroupBlock **)&(((u8*)pPg)[sizeof(PgHdr1) + pCache->szPage]) = pBlock ) |
| 35983 | + |
| 35984 | +#define PAGE_GET_BLOCKPTR(pCache, pPg) \ |
| 35985 | + ( *(PGroupBlock **)&(((u8*)pPg)[sizeof(PgHdr1) + pCache->szPage]) ) |
| 35986 | + |
| 35611 | 35987 | |
| 35612 | 35988 | /* |
| 35613 | 35989 | ** Macros to enter and leave the PCache LRU mutex. |
| 35614 | 35990 | */ |
| 35615 | 35991 | #define pcache1EnterMutex(X) sqlite3_mutex_enter((X)->mutex) |
| | @@ -35732,25 +36108,159 @@ |
| 35732 | 36108 | return iSize; |
| 35733 | 36109 | } |
| 35734 | 36110 | } |
| 35735 | 36111 | #endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */ |
| 35736 | 36112 | |
| 36113 | +#ifdef SQLITE_PAGECACHE_BLOCKALLOC |
| 36114 | +/* |
| 36115 | +** The block pBlock belongs to list pList but is not currently linked in. |
| 36116 | +** Insert it into the start of the list. |
| 36117 | +*/ |
| 36118 | +static void addBlockToList(PGroupBlockList *pList, PGroupBlock *pBlock){ |
| 36119 | + pBlock->pPrev = 0; |
| 36120 | + pBlock->pNext = pList->pFirst; |
| 36121 | + pList->pFirst = pBlock; |
| 36122 | + if( pBlock->pNext ){ |
| 36123 | + pBlock->pNext->pPrev = pBlock; |
| 36124 | + }else{ |
| 36125 | + assert( pList->pLast==0 ); |
| 36126 | + pList->pLast = pBlock; |
| 36127 | + } |
| 36128 | +} |
| 36129 | + |
| 36130 | +/* |
| 36131 | +** If there are no blocks in the list headed by pList, remove pList |
| 36132 | +** from the pGroup->pBlockList list and free it with sqlite3_free(). |
| 36133 | +*/ |
| 36134 | +static void freeListIfEmpty(PGroup *pGroup, PGroupBlockList *pList){ |
| 36135 | + assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 36136 | + if( pList->pFirst==0 ){ |
| 36137 | + PGroupBlockList **pp; |
| 36138 | + for(pp=&pGroup->pBlockList; *pp!=pList; pp=&(*pp)->pNext); |
| 36139 | + *pp = (*pp)->pNext; |
| 36140 | + sqlite3_free(pList); |
| 36141 | + } |
| 36142 | +} |
| 36143 | +#endif /* SQLITE_PAGECACHE_BLOCKALLOC */ |
| 36144 | + |
| 35737 | 36145 | /* |
| 35738 | 36146 | ** Allocate a new page object initially associated with cache pCache. |
| 35739 | 36147 | */ |
| 35740 | 36148 | static PgHdr1 *pcache1AllocPage(PCache1 *pCache){ |
| 35741 | 36149 | int nByte = sizeof(PgHdr1) + pCache->szPage; |
| 35742 | | - void *pPg = pcache1Alloc(nByte); |
| 36150 | + void *pPg = 0; |
| 35743 | 36151 | PgHdr1 *p; |
| 36152 | + |
| 36153 | +#ifdef SQLITE_PAGECACHE_BLOCKALLOC |
| 36154 | + PGroup *pGroup = pCache->pGroup; |
| 36155 | + PGroupBlockList *pList; |
| 36156 | + PGroupBlock *pBlock; |
| 36157 | + int i; |
| 36158 | + |
| 36159 | + nByte += sizeof(PGroupBlockList *); |
| 36160 | + nByte = ROUND8(nByte); |
| 36161 | + |
| 36162 | + for(pList=pGroup->pBlockList; pList; pList=pList->pNext){ |
| 36163 | + if( pList->nByte==nByte ) break; |
| 36164 | + } |
| 36165 | + if( pList==0 ){ |
| 36166 | + PGroupBlockList *pNew; |
| 36167 | + assert( pGroup->isBusy==0 ); |
| 36168 | + assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 36169 | + pGroup->isBusy = 1; /* Disable sqlite3PcacheReleaseMemory() */ |
| 36170 | + pNew = (PGroupBlockList *)sqlite3MallocZero(sizeof(PGroupBlockList)); |
| 36171 | + pGroup->isBusy = 0; /* Reenable sqlite3PcacheReleaseMemory() */ |
| 36172 | + if( pNew==0 ){ |
| 36173 | + /* malloc() failure. Return early. */ |
| 36174 | + return 0; |
| 36175 | + } |
| 36176 | +#ifdef SQLITE_DEBUG |
| 36177 | + for(pList=pGroup->pBlockList; pList; pList=pList->pNext){ |
| 36178 | + assert( pList->nByte!=nByte ); |
| 36179 | + } |
| 36180 | +#endif |
| 36181 | + pNew->nByte = nByte; |
| 36182 | + pNew->pNext = pGroup->pBlockList; |
| 36183 | + pGroup->pBlockList = pNew; |
| 36184 | + pList = pNew; |
| 36185 | + } |
| 36186 | + |
| 36187 | + pBlock = pList->pFirst; |
| 36188 | + if( pBlock==0 || pBlock->mUsed==(((Bitmask)1<<pBlock->nEntry)-1) ){ |
| 36189 | + int sz; |
| 36190 | + |
| 36191 | + /* Allocate a new block. Try to allocate enough space for the PGroupBlock |
| 36192 | + ** structure and MINENTRY allocations of nByte bytes each. If the |
| 36193 | + ** allocator returns more memory than requested, then more than MINENTRY |
| 36194 | + ** allocations may fit in it. */ |
| 36195 | + assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 36196 | + pcache1LeaveMutex(pCache->pGroup); |
| 36197 | + sz = sizeof(PGroupBlock) + PAGECACHE_BLOCKALLOC_MINENTRY * nByte; |
| 36198 | + pBlock = (PGroupBlock *)sqlite3Malloc(sz); |
| 36199 | + pcache1EnterMutex(pCache->pGroup); |
| 36200 | + |
| 36201 | + if( !pBlock ){ |
| 36202 | + freeListIfEmpty(pGroup, pList); |
| 36203 | + return 0; |
| 36204 | + } |
| 36205 | + pBlock->nEntry = (sqlite3MallocSize(pBlock) - sizeof(PGroupBlock)) / nByte; |
| 36206 | + if( pBlock->nEntry>=BMS ){ |
| 36207 | + pBlock->nEntry = BMS-1; |
| 36208 | + } |
| 36209 | + pBlock->pList = pList; |
| 36210 | + pBlock->mUsed = 0; |
| 36211 | + pBlock->aData = (u8 *)&pBlock[1]; |
| 36212 | + addBlockToList(pList, pBlock); |
| 36213 | + |
| 36214 | + sz = sqlite3MallocSize(pBlock); |
| 36215 | + sqlite3_mutex_enter(pcache1.mutex); |
| 36216 | + sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz); |
| 36217 | + sqlite3_mutex_leave(pcache1.mutex); |
| 36218 | + } |
| 36219 | + |
| 36220 | + for(i=0; pPg==0 && ALWAYS(i<pBlock->nEntry); i++){ |
| 36221 | + if( 0==(pBlock->mUsed & ((Bitmask)1<<i)) ){ |
| 36222 | + pBlock->mUsed |= ((Bitmask)1<<i); |
| 36223 | + pPg = (void *)&pBlock->aData[pList->nByte * i]; |
| 36224 | + } |
| 36225 | + } |
| 36226 | + assert( pPg ); |
| 36227 | + PAGE_SET_BLOCKPTR(pCache, pPg, pBlock); |
| 36228 | + |
| 36229 | + /* If the block is now full, shift it to the end of the list */ |
| 36230 | + if( pBlock->mUsed==(((Bitmask)1<<pBlock->nEntry)-1) && pList->pLast!=pBlock ){ |
| 36231 | + assert( pList->pFirst==pBlock ); |
| 36232 | + assert( pBlock->pPrev==0 ); |
| 36233 | + assert( pList->pLast->pNext==0 ); |
| 36234 | + pList->pFirst = pBlock->pNext; |
| 36235 | + pList->pFirst->pPrev = 0; |
| 36236 | + pBlock->pPrev = pList->pLast; |
| 36237 | + pBlock->pNext = 0; |
| 36238 | + pList->pLast->pNext = pBlock; |
| 36239 | + pList->pLast = pBlock; |
| 36240 | + } |
| 36241 | + p = PAGE_TO_PGHDR1(pCache, pPg); |
| 36242 | + if( pCache->bPurgeable ){ |
| 36243 | + pCache->pGroup->nCurrentPage++; |
| 36244 | + } |
| 36245 | +#else |
| 36246 | + /* The group mutex must be released before pcache1Alloc() is called. This |
| 36247 | + ** is because it may call sqlite3_release_memory(), which assumes that |
| 36248 | + ** this mutex is not held. */ |
| 36249 | + assert( sqlite3_mutex_held(pCache->pGroup->mutex) ); |
| 36250 | + pcache1LeaveMutex(pCache->pGroup); |
| 36251 | + pPg = pcache1Alloc(nByte); |
| 36252 | + pcache1EnterMutex(pCache->pGroup); |
| 35744 | 36253 | if( pPg ){ |
| 35745 | 36254 | p = PAGE_TO_PGHDR1(pCache, pPg); |
| 35746 | 36255 | if( pCache->bPurgeable ){ |
| 35747 | 36256 | pCache->pGroup->nCurrentPage++; |
| 35748 | 36257 | } |
| 35749 | 36258 | }else{ |
| 35750 | 36259 | p = 0; |
| 35751 | 36260 | } |
| 36261 | +#endif |
| 35752 | 36262 | return p; |
| 35753 | 36263 | } |
| 35754 | 36264 | |
| 35755 | 36265 | /* |
| 35756 | 36266 | ** Free a page object allocated by pcache1AllocPage(). |
| | @@ -35760,14 +36270,56 @@ |
| 35760 | 36270 | ** with a NULL pointer, so we mark the NULL test with ALWAYS(). |
| 35761 | 36271 | */ |
| 35762 | 36272 | static void pcache1FreePage(PgHdr1 *p){ |
| 35763 | 36273 | if( ALWAYS(p) ){ |
| 35764 | 36274 | PCache1 *pCache = p->pCache; |
| 36275 | + void *pPg = PGHDR1_TO_PAGE(p); |
| 36276 | + |
| 36277 | +#ifdef SQLITE_PAGECACHE_BLOCKALLOC |
| 36278 | + PGroupBlock *pBlock = PAGE_GET_BLOCKPTR(pCache, pPg); |
| 36279 | + PGroupBlockList *pList = pBlock->pList; |
| 36280 | + int i = ((u8 *)pPg - pBlock->aData) / pList->nByte; |
| 36281 | + |
| 36282 | + assert( pPg==(void *)&pBlock->aData[i*pList->nByte] ); |
| 36283 | + assert( pBlock->mUsed & ((Bitmask)1<<i) ); |
| 36284 | + pBlock->mUsed &= ~((Bitmask)1<<i); |
| 36285 | + |
| 36286 | + /* Remove the block from the list. If it is completely empty, free it. |
| 36287 | + ** Or if it is not completely empty, re-insert it at the start of the |
| 36288 | + ** list. */ |
| 36289 | + if( pList->pFirst==pBlock ){ |
| 36290 | + pList->pFirst = pBlock->pNext; |
| 36291 | + if( pList->pFirst ) pList->pFirst->pPrev = 0; |
| 36292 | + }else{ |
| 36293 | + pBlock->pPrev->pNext = pBlock->pNext; |
| 36294 | + } |
| 36295 | + if( pList->pLast==pBlock ){ |
| 36296 | + pList->pLast = pBlock->pPrev; |
| 36297 | + if( pList->pLast ) pList->pLast->pNext = 0; |
| 36298 | + }else{ |
| 36299 | + pBlock->pNext->pPrev = pBlock->pPrev; |
| 36300 | + } |
| 36301 | + |
| 36302 | + if( pBlock->mUsed==0 ){ |
| 36303 | + PGroup *pGroup = p->pCache->pGroup; |
| 36304 | + |
| 36305 | + int sz = sqlite3MallocSize(pBlock); |
| 36306 | + sqlite3_mutex_enter(pcache1.mutex); |
| 36307 | + sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -sz); |
| 36308 | + sqlite3_mutex_leave(pcache1.mutex); |
| 36309 | + freeListIfEmpty(pGroup, pList); |
| 36310 | + sqlite3_free(pBlock); |
| 36311 | + }else{ |
| 36312 | + addBlockToList(pList, pBlock); |
| 36313 | + } |
| 36314 | +#else |
| 36315 | + assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) ); |
| 36316 | + pcache1Free(pPg); |
| 36317 | +#endif |
| 35765 | 36318 | if( pCache->bPurgeable ){ |
| 35766 | 36319 | pCache->pGroup->nCurrentPage--; |
| 35767 | 36320 | } |
| 35768 | | - pcache1Free(PGHDR1_TO_PAGE(p)); |
| 35769 | 36321 | } |
| 35770 | 36322 | } |
| 35771 | 36323 | |
| 35772 | 36324 | /* |
| 35773 | 36325 | ** Malloc function used by SQLite to obtain space from the buffer configured |
| | @@ -36201,13 +36753,11 @@ |
| 36201 | 36753 | /* Step 5. If a usable page buffer has still not been found, |
| 36202 | 36754 | ** attempt to allocate a new one. |
| 36203 | 36755 | */ |
| 36204 | 36756 | if( !pPage ){ |
| 36205 | 36757 | if( createFlag==1 ) sqlite3BeginBenignMalloc(); |
| 36206 | | - pcache1LeaveMutex(pGroup); |
| 36207 | 36758 | pPage = pcache1AllocPage(pCache); |
| 36208 | | - pcache1EnterMutex(pGroup); |
| 36209 | 36759 | if( createFlag==1 ) sqlite3EndBenignMalloc(); |
| 36210 | 36760 | } |
| 36211 | 36761 | |
| 36212 | 36762 | if( pPage ){ |
| 36213 | 36763 | unsigned int h = iKey % pCache->nHash; |
| | @@ -36373,10 +36923,13 @@ |
| 36373 | 36923 | ** been released, the function returns. The return value is the total number |
| 36374 | 36924 | ** of bytes of memory released. |
| 36375 | 36925 | */ |
| 36376 | 36926 | SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){ |
| 36377 | 36927 | int nFree = 0; |
| 36928 | +#ifdef SQLITE_PAGECACHE_BLOCKALLOC |
| 36929 | + if( pcache1.grp.isBusy ) return 0; |
| 36930 | +#endif |
| 36378 | 36931 | assert( sqlite3_mutex_notheld(pcache1.grp.mutex) ); |
| 36379 | 36932 | assert( sqlite3_mutex_notheld(pcache1.mutex) ); |
| 36380 | 36933 | if( pcache1.pStart==0 ){ |
| 36381 | 36934 | PgHdr1 *p; |
| 36382 | 36935 | pcache1EnterMutex(&pcache1.grp); |
| | @@ -37585,10 +38138,11 @@ |
| 37585 | 38138 | u8 ckptSyncFlags; /* SYNC_NORMAL or SYNC_FULL for checkpoint */ |
| 37586 | 38139 | u8 syncFlags; /* SYNC_NORMAL or SYNC_FULL otherwise */ |
| 37587 | 38140 | u8 tempFile; /* zFilename is a temporary file */ |
| 37588 | 38141 | u8 readOnly; /* True for a read-only database */ |
| 37589 | 38142 | u8 memDb; /* True to inhibit all file I/O */ |
| 38143 | + u8 hasSeenStress; /* pagerStress() called one or more times */ |
| 37590 | 38144 | |
| 37591 | 38145 | /************************************************************************** |
| 37592 | 38146 | ** The following block contains those class members that change during |
| 37593 | 38147 | ** routine opertion. Class members not in this block are either fixed |
| 37594 | 38148 | ** when the pager is first created or else only change when there is a |
| | @@ -40704,10 +41258,11 @@ |
| 40704 | 41258 | ** to the caller. |
| 40705 | 41259 | */ |
| 40706 | 41260 | SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager){ |
| 40707 | 41261 | u8 *pTmp = (u8 *)pPager->pTmpSpace; |
| 40708 | 41262 | |
| 41263 | + assert( assert_pager_state(pPager) ); |
| 40709 | 41264 | disable_simulated_io_errors(); |
| 40710 | 41265 | sqlite3BeginBenignMalloc(); |
| 40711 | 41266 | /* pPager->errCode = 0; */ |
| 40712 | 41267 | pPager->exclusiveMode = 0; |
| 40713 | 41268 | #ifndef SQLITE_OMIT_WAL |
| | @@ -41138,10 +41693,11 @@ |
| 41138 | 41693 | ** is impossible for sqlite3PCacheFetch() to be called with createFlag==1 |
| 41139 | 41694 | ** while in the error state, hence it is impossible for this routine to |
| 41140 | 41695 | ** be called in the error state. Nevertheless, we include a NEVER() |
| 41141 | 41696 | ** test for the error state as a safeguard against future changes. |
| 41142 | 41697 | */ |
| 41698 | + pPager->hasSeenStress = 1; |
| 41143 | 41699 | if( NEVER(pPager->errCode) ) return SQLITE_OK; |
| 41144 | 41700 | if( pPager->doNotSpill ) return SQLITE_OK; |
| 41145 | 41701 | if( pPager->doNotSyncSpill && (pPg->flags & PGHDR_NEED_SYNC)!=0 ){ |
| 41146 | 41702 | return SQLITE_OK; |
| 41147 | 41703 | } |
| | @@ -50430,15 +50986,16 @@ |
| 50430 | 50986 | for(i=0; i<nCell; i++){ |
| 50431 | 50987 | u8 *pCell = findCell(pPage, i); |
| 50432 | 50988 | if( eType==PTRMAP_OVERFLOW1 ){ |
| 50433 | 50989 | CellInfo info; |
| 50434 | 50990 | btreeParseCellPtr(pPage, pCell, &info); |
| 50435 | | - if( info.iOverflow ){ |
| 50436 | | - if( iFrom==get4byte(&pCell[info.iOverflow]) ){ |
| 50437 | | - put4byte(&pCell[info.iOverflow], iTo); |
| 50438 | | - break; |
| 50439 | | - } |
| 50991 | + if( info.iOverflow |
| 50992 | + && pCell+info.iOverflow+3<=pPage->aData+pPage->maskPage |
| 50993 | + && iFrom==get4byte(&pCell[info.iOverflow]) |
| 50994 | + ){ |
| 50995 | + put4byte(&pCell[info.iOverflow], iTo); |
| 50996 | + break; |
| 50440 | 50997 | } |
| 50441 | 50998 | }else{ |
| 50442 | 50999 | if( get4byte(pCell)==iFrom ){ |
| 50443 | 51000 | put4byte(pCell, iTo); |
| 50444 | 51001 | break; |
| | @@ -51155,11 +51712,12 @@ |
| 51155 | 51712 | |
| 51156 | 51713 | if( NEVER(wrFlag && pBt->readOnly) ){ |
| 51157 | 51714 | return SQLITE_READONLY; |
| 51158 | 51715 | } |
| 51159 | 51716 | if( iTable==1 && btreePagecount(pBt)==0 ){ |
| 51160 | | - return SQLITE_EMPTY; |
| 51717 | + assert( wrFlag==0 ); |
| 51718 | + iTable = 0; |
| 51161 | 51719 | } |
| 51162 | 51720 | |
| 51163 | 51721 | /* Now that no other errors can occur, finish filling in the BtCursor |
| 51164 | 51722 | ** variables and link the cursor into the BtShared list. */ |
| 51165 | 51723 | pCur->pgnoRoot = (Pgno)iTable; |
| | @@ -51909,10 +52467,13 @@ |
| 51909 | 52467 | int i; |
| 51910 | 52468 | for(i=1; i<=pCur->iPage; i++){ |
| 51911 | 52469 | releasePage(pCur->apPage[i]); |
| 51912 | 52470 | } |
| 51913 | 52471 | pCur->iPage = 0; |
| 52472 | + }else if( pCur->pgnoRoot==0 ){ |
| 52473 | + pCur->eState = CURSOR_INVALID; |
| 52474 | + return SQLITE_OK; |
| 51914 | 52475 | }else{ |
| 51915 | 52476 | rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0]); |
| 51916 | 52477 | if( rc!=SQLITE_OK ){ |
| 51917 | 52478 | pCur->eState = CURSOR_INVALID; |
| 51918 | 52479 | return rc; |
| | @@ -52018,11 +52579,11 @@ |
| 52018 | 52579 | assert( cursorHoldsMutex(pCur) ); |
| 52019 | 52580 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 52020 | 52581 | rc = moveToRoot(pCur); |
| 52021 | 52582 | if( rc==SQLITE_OK ){ |
| 52022 | 52583 | if( pCur->eState==CURSOR_INVALID ){ |
| 52023 | | - assert( pCur->apPage[pCur->iPage]->nCell==0 ); |
| 52584 | + assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 ); |
| 52024 | 52585 | *pRes = 1; |
| 52025 | 52586 | }else{ |
| 52026 | 52587 | assert( pCur->apPage[pCur->iPage]->nCell>0 ); |
| 52027 | 52588 | *pRes = 0; |
| 52028 | 52589 | rc = moveToLeftmost(pCur); |
| | @@ -52057,11 +52618,11 @@ |
| 52057 | 52618 | } |
| 52058 | 52619 | |
| 52059 | 52620 | rc = moveToRoot(pCur); |
| 52060 | 52621 | if( rc==SQLITE_OK ){ |
| 52061 | 52622 | if( CURSOR_INVALID==pCur->eState ){ |
| 52062 | | - assert( pCur->apPage[pCur->iPage]->nCell==0 ); |
| 52623 | + assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 ); |
| 52063 | 52624 | *pRes = 1; |
| 52064 | 52625 | }else{ |
| 52065 | 52626 | assert( pCur->eState==CURSOR_VALID ); |
| 52066 | 52627 | *pRes = 0; |
| 52067 | 52628 | rc = moveToRightmost(pCur); |
| | @@ -52130,16 +52691,16 @@ |
| 52130 | 52691 | |
| 52131 | 52692 | rc = moveToRoot(pCur); |
| 52132 | 52693 | if( rc ){ |
| 52133 | 52694 | return rc; |
| 52134 | 52695 | } |
| 52135 | | - assert( pCur->apPage[pCur->iPage] ); |
| 52136 | | - assert( pCur->apPage[pCur->iPage]->isInit ); |
| 52137 | | - assert( pCur->apPage[pCur->iPage]->nCell>0 || pCur->eState==CURSOR_INVALID ); |
| 52696 | + assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage] ); |
| 52697 | + assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->isInit ); |
| 52698 | + assert( pCur->eState==CURSOR_INVALID || pCur->apPage[pCur->iPage]->nCell>0 ); |
| 52138 | 52699 | if( pCur->eState==CURSOR_INVALID ){ |
| 52139 | 52700 | *pRes = -1; |
| 52140 | | - assert( pCur->apPage[pCur->iPage]->nCell==0 ); |
| 52701 | + assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 ); |
| 52141 | 52702 | return SQLITE_OK; |
| 52142 | 52703 | } |
| 52143 | 52704 | assert( pCur->apPage[0]->intKey || pIdxKey ); |
| 52144 | 52705 | for(;;){ |
| 52145 | 52706 | int lwr, upr, idx; |
| | @@ -52862,10 +53423,13 @@ |
| 52862 | 53423 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 52863 | 53424 | btreeParseCellPtr(pPage, pCell, &info); |
| 52864 | 53425 | if( info.iOverflow==0 ){ |
| 52865 | 53426 | return SQLITE_OK; /* No overflow pages. Return without doing anything */ |
| 52866 | 53427 | } |
| 53428 | + if( pCell+info.iOverflow+3 > pPage->aData+pPage->maskPage ){ |
| 53429 | + return SQLITE_CORRUPT; /* Cell extends past end of page */ |
| 53430 | + } |
| 52867 | 53431 | ovflPgno = get4byte(&pCell[info.iOverflow]); |
| 52868 | 53432 | assert( pBt->usableSize > 4 ); |
| 52869 | 53433 | ovflPageSize = pBt->usableSize - 4; |
| 52870 | 53434 | nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize; |
| 52871 | 53435 | assert( ovflPgno==0 || nOvfl>0 ); |
| | @@ -55045,10 +55609,15 @@ |
| 55045 | 55609 | ** corruption) an SQLite error code is returned. |
| 55046 | 55610 | */ |
| 55047 | 55611 | SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *pCur, i64 *pnEntry){ |
| 55048 | 55612 | i64 nEntry = 0; /* Value to return in *pnEntry */ |
| 55049 | 55613 | int rc; /* Return code */ |
| 55614 | + |
| 55615 | + if( pCur->pgnoRoot==0 ){ |
| 55616 | + *pnEntry = 0; |
| 55617 | + return SQLITE_OK; |
| 55618 | + } |
| 55050 | 55619 | rc = moveToRoot(pCur); |
| 55051 | 55620 | |
| 55052 | 55621 | /* Unless an error occurs, the following loop runs one iteration for each |
| 55053 | 55622 | ** page in the B-Tree structure (not including overflow pages). |
| 55054 | 55623 | */ |
| | @@ -55829,11 +56398,10 @@ |
| 55829 | 56398 | */ |
| 55830 | 56399 | SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBtree, int iVersion){ |
| 55831 | 56400 | BtShared *pBt = pBtree->pBt; |
| 55832 | 56401 | int rc; /* Return code */ |
| 55833 | 56402 | |
| 55834 | | - assert( pBtree->inTrans==TRANS_NONE ); |
| 55835 | 56403 | assert( iVersion==1 || iVersion==2 ); |
| 55836 | 56404 | |
| 55837 | 56405 | /* If setting the version fields to 1, do not automatically open the |
| 55838 | 56406 | ** WAL connection, even if the version fields are currently set to 2. |
| 55839 | 56407 | */ |
| | @@ -56268,106 +56836,110 @@ |
| 56268 | 56836 | /* Update the schema version field in the destination database. This |
| 56269 | 56837 | ** is to make sure that the schema-version really does change in |
| 56270 | 56838 | ** the case where the source and destination databases have the |
| 56271 | 56839 | ** same schema version. |
| 56272 | 56840 | */ |
| 56273 | | - if( rc==SQLITE_DONE |
| 56274 | | - && (rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1))==SQLITE_OK |
| 56275 | | - ){ |
| 56276 | | - int nDestTruncate; |
| 56277 | | - |
| 56278 | | - if( p->pDestDb ){ |
| 56279 | | - sqlite3ResetInternalSchema(p->pDestDb, -1); |
| 56280 | | - } |
| 56281 | | - |
| 56282 | | - /* Set nDestTruncate to the final number of pages in the destination |
| 56283 | | - ** database. The complication here is that the destination page |
| 56284 | | - ** size may be different to the source page size. |
| 56285 | | - ** |
| 56286 | | - ** If the source page size is smaller than the destination page size, |
| 56287 | | - ** round up. In this case the call to sqlite3OsTruncate() below will |
| 56288 | | - ** fix the size of the file. However it is important to call |
| 56289 | | - ** sqlite3PagerTruncateImage() here so that any pages in the |
| 56290 | | - ** destination file that lie beyond the nDestTruncate page mark are |
| 56291 | | - ** journalled by PagerCommitPhaseOne() before they are destroyed |
| 56292 | | - ** by the file truncation. |
| 56293 | | - */ |
| 56294 | | - assert( pgszSrc==sqlite3BtreeGetPageSize(p->pSrc) ); |
| 56295 | | - assert( pgszDest==sqlite3BtreeGetPageSize(p->pDest) ); |
| 56296 | | - if( pgszSrc<pgszDest ){ |
| 56297 | | - int ratio = pgszDest/pgszSrc; |
| 56298 | | - nDestTruncate = (nSrcPage+ratio-1)/ratio; |
| 56299 | | - if( nDestTruncate==(int)PENDING_BYTE_PAGE(p->pDest->pBt) ){ |
| 56300 | | - nDestTruncate--; |
| 56301 | | - } |
| 56302 | | - }else{ |
| 56303 | | - nDestTruncate = nSrcPage * (pgszSrc/pgszDest); |
| 56304 | | - } |
| 56305 | | - sqlite3PagerTruncateImage(pDestPager, nDestTruncate); |
| 56306 | | - |
| 56307 | | - if( pgszSrc<pgszDest ){ |
| 56308 | | - /* If the source page-size is smaller than the destination page-size, |
| 56309 | | - ** two extra things may need to happen: |
| 56310 | | - ** |
| 56311 | | - ** * The destination may need to be truncated, and |
| 56312 | | - ** |
| 56313 | | - ** * Data stored on the pages immediately following the |
| 56314 | | - ** pending-byte page in the source database may need to be |
| 56315 | | - ** copied into the destination database. |
| 56316 | | - */ |
| 56317 | | - const i64 iSize = (i64)pgszSrc * (i64)nSrcPage; |
| 56318 | | - sqlite3_file * const pFile = sqlite3PagerFile(pDestPager); |
| 56319 | | - i64 iOff; |
| 56320 | | - i64 iEnd; |
| 56321 | | - |
| 56322 | | - assert( pFile ); |
| 56323 | | - assert( (i64)nDestTruncate*(i64)pgszDest >= iSize || ( |
| 56324 | | - nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1) |
| 56325 | | - && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest |
| 56326 | | - )); |
| 56327 | | - |
| 56328 | | - /* This call ensures that all data required to recreate the original |
| 56329 | | - ** database has been stored in the journal for pDestPager and the |
| 56330 | | - ** journal synced to disk. So at this point we may safely modify |
| 56331 | | - ** the database file in any way, knowing that if a power failure |
| 56332 | | - ** occurs, the original database will be reconstructed from the |
| 56333 | | - ** journal file. */ |
| 56334 | | - rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1); |
| 56335 | | - |
| 56336 | | - /* Write the extra pages and truncate the database file as required. */ |
| 56337 | | - iEnd = MIN(PENDING_BYTE + pgszDest, iSize); |
| 56338 | | - for( |
| 56339 | | - iOff=PENDING_BYTE+pgszSrc; |
| 56340 | | - rc==SQLITE_OK && iOff<iEnd; |
| 56341 | | - iOff+=pgszSrc |
| 56342 | | - ){ |
| 56343 | | - PgHdr *pSrcPg = 0; |
| 56344 | | - const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1); |
| 56345 | | - rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg); |
| 56346 | | - if( rc==SQLITE_OK ){ |
| 56347 | | - u8 *zData = sqlite3PagerGetData(pSrcPg); |
| 56348 | | - rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff); |
| 56349 | | - } |
| 56350 | | - sqlite3PagerUnref(pSrcPg); |
| 56351 | | - } |
| 56352 | | - if( rc==SQLITE_OK ){ |
| 56353 | | - rc = backupTruncateFile(pFile, iSize); |
| 56354 | | - } |
| 56355 | | - |
| 56356 | | - /* Sync the database file to disk. */ |
| 56357 | | - if( rc==SQLITE_OK ){ |
| 56358 | | - rc = sqlite3PagerSync(pDestPager); |
| 56359 | | - } |
| 56360 | | - }else{ |
| 56361 | | - rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0); |
| 56362 | | - } |
| 56363 | | - |
| 56364 | | - /* Finish committing the transaction to the destination database. */ |
| 56365 | | - if( SQLITE_OK==rc |
| 56366 | | - && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0)) |
| 56367 | | - ){ |
| 56368 | | - rc = SQLITE_DONE; |
| 56841 | + if( rc==SQLITE_DONE ){ |
| 56842 | + rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1); |
| 56843 | + if( rc==SQLITE_OK ){ |
| 56844 | + if( p->pDestDb ){ |
| 56845 | + sqlite3ResetInternalSchema(p->pDestDb, -1); |
| 56846 | + } |
| 56847 | + if( destMode==PAGER_JOURNALMODE_WAL ){ |
| 56848 | + rc = sqlite3BtreeSetVersion(p->pDest, 2); |
| 56849 | + } |
| 56850 | + } |
| 56851 | + if( rc==SQLITE_OK ){ |
| 56852 | + int nDestTruncate; |
| 56853 | + /* Set nDestTruncate to the final number of pages in the destination |
| 56854 | + ** database. The complication here is that the destination page |
| 56855 | + ** size may be different to the source page size. |
| 56856 | + ** |
| 56857 | + ** If the source page size is smaller than the destination page size, |
| 56858 | + ** round up. In this case the call to sqlite3OsTruncate() below will |
| 56859 | + ** fix the size of the file. However it is important to call |
| 56860 | + ** sqlite3PagerTruncateImage() here so that any pages in the |
| 56861 | + ** destination file that lie beyond the nDestTruncate page mark are |
| 56862 | + ** journalled by PagerCommitPhaseOne() before they are destroyed |
| 56863 | + ** by the file truncation. |
| 56864 | + */ |
| 56865 | + assert( pgszSrc==sqlite3BtreeGetPageSize(p->pSrc) ); |
| 56866 | + assert( pgszDest==sqlite3BtreeGetPageSize(p->pDest) ); |
| 56867 | + if( pgszSrc<pgszDest ){ |
| 56868 | + int ratio = pgszDest/pgszSrc; |
| 56869 | + nDestTruncate = (nSrcPage+ratio-1)/ratio; |
| 56870 | + if( nDestTruncate==(int)PENDING_BYTE_PAGE(p->pDest->pBt) ){ |
| 56871 | + nDestTruncate--; |
| 56872 | + } |
| 56873 | + }else{ |
| 56874 | + nDestTruncate = nSrcPage * (pgszSrc/pgszDest); |
| 56875 | + } |
| 56876 | + sqlite3PagerTruncateImage(pDestPager, nDestTruncate); |
| 56877 | + |
| 56878 | + if( pgszSrc<pgszDest ){ |
| 56879 | + /* If the source page-size is smaller than the destination page-size, |
| 56880 | + ** two extra things may need to happen: |
| 56881 | + ** |
| 56882 | + ** * The destination may need to be truncated, and |
| 56883 | + ** |
| 56884 | + ** * Data stored on the pages immediately following the |
| 56885 | + ** pending-byte page in the source database may need to be |
| 56886 | + ** copied into the destination database. |
| 56887 | + */ |
| 56888 | + const i64 iSize = (i64)pgszSrc * (i64)nSrcPage; |
| 56889 | + sqlite3_file * const pFile = sqlite3PagerFile(pDestPager); |
| 56890 | + i64 iOff; |
| 56891 | + i64 iEnd; |
| 56892 | + |
| 56893 | + assert( pFile ); |
| 56894 | + assert( (i64)nDestTruncate*(i64)pgszDest >= iSize || ( |
| 56895 | + nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1) |
| 56896 | + && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest |
| 56897 | + )); |
| 56898 | + |
| 56899 | + /* This call ensures that all data required to recreate the original |
| 56900 | + ** database has been stored in the journal for pDestPager and the |
| 56901 | + ** journal synced to disk. So at this point we may safely modify |
| 56902 | + ** the database file in any way, knowing that if a power failure |
| 56903 | + ** occurs, the original database will be reconstructed from the |
| 56904 | + ** journal file. */ |
| 56905 | + rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1); |
| 56906 | + |
| 56907 | + /* Write the extra pages and truncate the database file as required */ |
| 56908 | + iEnd = MIN(PENDING_BYTE + pgszDest, iSize); |
| 56909 | + for( |
| 56910 | + iOff=PENDING_BYTE+pgszSrc; |
| 56911 | + rc==SQLITE_OK && iOff<iEnd; |
| 56912 | + iOff+=pgszSrc |
| 56913 | + ){ |
| 56914 | + PgHdr *pSrcPg = 0; |
| 56915 | + const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1); |
| 56916 | + rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg); |
| 56917 | + if( rc==SQLITE_OK ){ |
| 56918 | + u8 *zData = sqlite3PagerGetData(pSrcPg); |
| 56919 | + rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff); |
| 56920 | + } |
| 56921 | + sqlite3PagerUnref(pSrcPg); |
| 56922 | + } |
| 56923 | + if( rc==SQLITE_OK ){ |
| 56924 | + rc = backupTruncateFile(pFile, iSize); |
| 56925 | + } |
| 56926 | + |
| 56927 | + /* Sync the database file to disk. */ |
| 56928 | + if( rc==SQLITE_OK ){ |
| 56929 | + rc = sqlite3PagerSync(pDestPager); |
| 56930 | + } |
| 56931 | + }else{ |
| 56932 | + rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0); |
| 56933 | + } |
| 56934 | + |
| 56935 | + /* Finish committing the transaction to the destination database. */ |
| 56936 | + if( SQLITE_OK==rc |
| 56937 | + && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0)) |
| 56938 | + ){ |
| 56939 | + rc = SQLITE_DONE; |
| 56940 | + } |
| 56369 | 56941 | } |
| 56370 | 56942 | } |
| 56371 | 56943 | |
| 56372 | 56944 | /* If bCloseTrans is true, then this function opened a read transaction |
| 56373 | 56945 | ** on the source database. Close the read transaction here. There is |
| | @@ -56831,38 +57403,32 @@ |
| 56831 | 57403 | ** invoking an external callback, free it now. Calling this function |
| 56832 | 57404 | ** does not free any Mem.zMalloc buffer. |
| 56833 | 57405 | */ |
| 56834 | 57406 | SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p){ |
| 56835 | 57407 | assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) ); |
| 56836 | | - testcase( p->flags & MEM_Agg ); |
| 56837 | | - testcase( p->flags & MEM_Dyn ); |
| 56838 | | - testcase( p->flags & MEM_RowSet ); |
| 56839 | | - testcase( p->flags & MEM_Frame ); |
| 56840 | | - if( p->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame) ){ |
| 56841 | | - if( p->flags&MEM_Agg ){ |
| 56842 | | - sqlite3VdbeMemFinalize(p, p->u.pDef); |
| 56843 | | - assert( (p->flags & MEM_Agg)==0 ); |
| 56844 | | - sqlite3VdbeMemRelease(p); |
| 56845 | | - }else if( p->flags&MEM_Dyn && p->xDel ){ |
| 56846 | | - assert( (p->flags&MEM_RowSet)==0 ); |
| 56847 | | - p->xDel((void *)p->z); |
| 56848 | | - p->xDel = 0; |
| 56849 | | - }else if( p->flags&MEM_RowSet ){ |
| 56850 | | - sqlite3RowSetClear(p->u.pRowSet); |
| 56851 | | - }else if( p->flags&MEM_Frame ){ |
| 56852 | | - sqlite3VdbeMemSetNull(p); |
| 56853 | | - } |
| 57408 | + if( p->flags&MEM_Agg ){ |
| 57409 | + sqlite3VdbeMemFinalize(p, p->u.pDef); |
| 57410 | + assert( (p->flags & MEM_Agg)==0 ); |
| 57411 | + sqlite3VdbeMemRelease(p); |
| 57412 | + }else if( p->flags&MEM_Dyn && p->xDel ){ |
| 57413 | + assert( (p->flags&MEM_RowSet)==0 ); |
| 57414 | + p->xDel((void *)p->z); |
| 57415 | + p->xDel = 0; |
| 57416 | + }else if( p->flags&MEM_RowSet ){ |
| 57417 | + sqlite3RowSetClear(p->u.pRowSet); |
| 57418 | + }else if( p->flags&MEM_Frame ){ |
| 57419 | + sqlite3VdbeMemSetNull(p); |
| 56854 | 57420 | } |
| 56855 | 57421 | } |
| 56856 | 57422 | |
| 56857 | 57423 | /* |
| 56858 | 57424 | ** Release any memory held by the Mem. This may leave the Mem in an |
| 56859 | 57425 | ** inconsistent state, for example with (Mem.z==0) and |
| 56860 | 57426 | ** (Mem.type==SQLITE_TEXT). |
| 56861 | 57427 | */ |
| 56862 | 57428 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){ |
| 56863 | | - sqlite3VdbeMemReleaseExternal(p); |
| 57429 | + MemReleaseExt(p); |
| 56864 | 57430 | sqlite3DbFree(p->db, p->zMalloc); |
| 56865 | 57431 | p->z = 0; |
| 56866 | 57432 | p->zMalloc = 0; |
| 56867 | 57433 | p->xDel = 0; |
| 56868 | 57434 | } |
| | @@ -57180,11 +57746,11 @@ |
| 57180 | 57746 | ** pFrom->z is used, then pTo->z points to the same thing as pFrom->z |
| 57181 | 57747 | ** and flags gets srcType (either MEM_Ephem or MEM_Static). |
| 57182 | 57748 | */ |
| 57183 | 57749 | SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){ |
| 57184 | 57750 | assert( (pFrom->flags & MEM_RowSet)==0 ); |
| 57185 | | - sqlite3VdbeMemReleaseExternal(pTo); |
| 57751 | + MemReleaseExt(pTo); |
| 57186 | 57752 | memcpy(pTo, pFrom, MEMCELLSIZE); |
| 57187 | 57753 | pTo->xDel = 0; |
| 57188 | 57754 | if( (pFrom->flags&MEM_Static)==0 ){ |
| 57189 | 57755 | pTo->flags &= ~(MEM_Dyn|MEM_Static|MEM_Ephem); |
| 57190 | 57756 | assert( srcType==MEM_Ephem || srcType==MEM_Static ); |
| | @@ -57198,11 +57764,11 @@ |
| 57198 | 57764 | */ |
| 57199 | 57765 | SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){ |
| 57200 | 57766 | int rc = SQLITE_OK; |
| 57201 | 57767 | |
| 57202 | 57768 | assert( (pFrom->flags & MEM_RowSet)==0 ); |
| 57203 | | - sqlite3VdbeMemReleaseExternal(pTo); |
| 57769 | + MemReleaseExt(pTo); |
| 57204 | 57770 | memcpy(pTo, pFrom, MEMCELLSIZE); |
| 57205 | 57771 | pTo->flags &= ~MEM_Dyn; |
| 57206 | 57772 | |
| 57207 | 57773 | if( pTo->flags&(MEM_Str|MEM_Blob) ){ |
| 57208 | 57774 | if( 0==(pFrom->flags&MEM_Static) ){ |
| | @@ -57592,15 +58158,15 @@ |
| 57592 | 58158 | *ppVal = 0; |
| 57593 | 58159 | return SQLITE_OK; |
| 57594 | 58160 | } |
| 57595 | 58161 | op = pExpr->op; |
| 57596 | 58162 | |
| 57597 | | - /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT3. |
| 58163 | + /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT2. |
| 57598 | 58164 | ** The ifdef here is to enable us to achieve 100% branch test coverage even |
| 57599 | | - ** when SQLITE_ENABLE_STAT3 is omitted. |
| 58165 | + ** when SQLITE_ENABLE_STAT2 is omitted. |
| 57600 | 58166 | */ |
| 57601 | | -#ifdef SQLITE_ENABLE_STAT3 |
| 58167 | +#ifdef SQLITE_ENABLE_STAT2 |
| 57602 | 58168 | if( op==TK_REGISTER ) op = pExpr->op2; |
| 57603 | 58169 | #else |
| 57604 | 58170 | if( NEVER(op==TK_REGISTER) ) op = pExpr->op2; |
| 57605 | 58171 | #endif |
| 57606 | 58172 | |
| | @@ -58153,10 +58719,16 @@ |
| 58153 | 58719 | assert( p->nOp - i >= 3 ); |
| 58154 | 58720 | assert( pOp[-1].opcode==OP_Integer ); |
| 58155 | 58721 | n = pOp[-1].p1; |
| 58156 | 58722 | if( n>nMaxArgs ) nMaxArgs = n; |
| 58157 | 58723 | #endif |
| 58724 | + }else if( opcode==OP_Next || opcode==OP_SorterNext ){ |
| 58725 | + pOp->p4.xAdvance = sqlite3BtreeNext; |
| 58726 | + pOp->p4type = P4_ADVANCE; |
| 58727 | + }else if( opcode==OP_Prev ){ |
| 58728 | + pOp->p4.xAdvance = sqlite3BtreePrevious; |
| 58729 | + pOp->p4type = P4_ADVANCE; |
| 58158 | 58730 | } |
| 58159 | 58731 | |
| 58160 | 58732 | if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){ |
| 58161 | 58733 | assert( -1-pOp->p2<p->nLabel ); |
| 58162 | 58734 | pOp->p2 = aLabel[-1-pOp->p2]; |
| | @@ -58244,37 +58816,34 @@ |
| 58244 | 58816 | ** Change the value of the P1 operand for a specific instruction. |
| 58245 | 58817 | ** This routine is useful when a large program is loaded from a |
| 58246 | 58818 | ** static array using sqlite3VdbeAddOpList but we want to make a |
| 58247 | 58819 | ** few minor changes to the program. |
| 58248 | 58820 | */ |
| 58249 | | -SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, int addr, int val){ |
| 58821 | +SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, u32 addr, int val){ |
| 58250 | 58822 | assert( p!=0 ); |
| 58251 | | - assert( addr>=0 ); |
| 58252 | | - if( p->nOp>addr ){ |
| 58823 | + if( ((u32)p->nOp)>addr ){ |
| 58253 | 58824 | p->aOp[addr].p1 = val; |
| 58254 | 58825 | } |
| 58255 | 58826 | } |
| 58256 | 58827 | |
| 58257 | 58828 | /* |
| 58258 | 58829 | ** Change the value of the P2 operand for a specific instruction. |
| 58259 | 58830 | ** This routine is useful for setting a jump destination. |
| 58260 | 58831 | */ |
| 58261 | | -SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){ |
| 58832 | +SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, u32 addr, int val){ |
| 58262 | 58833 | assert( p!=0 ); |
| 58263 | | - assert( addr>=0 ); |
| 58264 | | - if( p->nOp>addr ){ |
| 58834 | + if( ((u32)p->nOp)>addr ){ |
| 58265 | 58835 | p->aOp[addr].p2 = val; |
| 58266 | 58836 | } |
| 58267 | 58837 | } |
| 58268 | 58838 | |
| 58269 | 58839 | /* |
| 58270 | 58840 | ** Change the value of the P3 operand for a specific instruction. |
| 58271 | 58841 | */ |
| 58272 | | -SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, int addr, int val){ |
| 58842 | +SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){ |
| 58273 | 58843 | assert( p!=0 ); |
| 58274 | | - assert( addr>=0 ); |
| 58275 | | - if( p->nOp>addr ){ |
| 58844 | + if( ((u32)p->nOp)>addr ){ |
| 58276 | 58845 | p->aOp[addr].p3 = val; |
| 58277 | 58846 | } |
| 58278 | 58847 | } |
| 58279 | 58848 | |
| 58280 | 58849 | /* |
| | @@ -58292,12 +58861,12 @@ |
| 58292 | 58861 | /* |
| 58293 | 58862 | ** Change the P2 operand of instruction addr so that it points to |
| 58294 | 58863 | ** the address of the next instruction to be coded. |
| 58295 | 58864 | */ |
| 58296 | 58865 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){ |
| 58297 | | - assert( addr>=0 || p->db->mallocFailed ); |
| 58298 | | - if( addr>=0 ) sqlite3VdbeChangeP2(p, addr, p->nOp); |
| 58866 | + assert( addr>=0 ); |
| 58867 | + sqlite3VdbeChangeP2(p, addr, p->nOp); |
| 58299 | 58868 | } |
| 58300 | 58869 | |
| 58301 | 58870 | |
| 58302 | 58871 | /* |
| 58303 | 58872 | ** If the input FuncDef structure is ephemeral, then free it. If |
| | @@ -58661,10 +59230,14 @@ |
| 58661 | 59230 | break; |
| 58662 | 59231 | } |
| 58663 | 59232 | case P4_SUBPROGRAM: { |
| 58664 | 59233 | sqlite3_snprintf(nTemp, zTemp, "program"); |
| 58665 | 59234 | break; |
| 59235 | + } |
| 59236 | + case P4_ADVANCE: { |
| 59237 | + zTemp[0] = 0; |
| 59238 | + break; |
| 58666 | 59239 | } |
| 58667 | 59240 | default: { |
| 58668 | 59241 | zP4 = pOp->p4.z; |
| 58669 | 59242 | if( zP4==0 ){ |
| 58670 | 59243 | zP4 = zTemp; |
| | @@ -59285,10 +59858,11 @@ |
| 59285 | 59858 | */ |
| 59286 | 59859 | SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){ |
| 59287 | 59860 | if( pCx==0 ){ |
| 59288 | 59861 | return; |
| 59289 | 59862 | } |
| 59863 | + sqlite3VdbeSorterClose(p->db, pCx); |
| 59290 | 59864 | if( pCx->pBt ){ |
| 59291 | 59865 | sqlite3BtreeClose(pCx->pBt); |
| 59292 | 59866 | /* The pCx->pCursor will be close automatically, if it exists, by |
| 59293 | 59867 | ** the call above. */ |
| 59294 | 59868 | }else if( pCx->pCursor ){ |
| | @@ -62585,10 +63159,17 @@ |
| 62585 | 63159 | ** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*) |
| 62586 | 63160 | ** P if required. |
| 62587 | 63161 | */ |
| 62588 | 63162 | #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0) |
| 62589 | 63163 | |
| 63164 | +/* Return true if the cursor was opened using the OP_OpenSorter opcode. */ |
| 63165 | +#ifdef SQLITE_OMIT_MERGE_SORT |
| 63166 | +# define isSorter(x) 0 |
| 63167 | +#else |
| 63168 | +# define isSorter(x) ((x)->pSorter!=0) |
| 63169 | +#endif |
| 63170 | + |
| 62590 | 63171 | /* |
| 62591 | 63172 | ** Argument pMem points at a register that will be passed to a |
| 62592 | 63173 | ** user-defined function or returned to the user as the result of a query. |
| 62593 | 63174 | ** This routine sets the pMem->type variable used by the sqlite3_value_*() |
| 62594 | 63175 | ** routines. |
| | @@ -63179,10 +63760,11 @@ |
| 63179 | 63760 | u8 *zEndHdr; /* Pointer to first byte after the header */ |
| 63180 | 63761 | u32 offset; /* Offset into the data */ |
| 63181 | 63762 | u32 szField; /* Number of bytes in the content of a field */ |
| 63182 | 63763 | int szHdr; /* Size of the header size field at start of record */ |
| 63183 | 63764 | int avail; /* Number of bytes of available data */ |
| 63765 | + u32 t; /* A type code from the record header */ |
| 63184 | 63766 | Mem *pReg; /* PseudoTable input register */ |
| 63185 | 63767 | } am; |
| 63186 | 63768 | struct OP_Affinity_stack_vars { |
| 63187 | 63769 | const char *zAffinity; /* The affinity to be applied */ |
| 63188 | 63770 | char cAff; /* A single character of affinity */ |
| | @@ -63250,55 +63832,58 @@ |
| 63250 | 63832 | Db *pDb; |
| 63251 | 63833 | } aw; |
| 63252 | 63834 | struct OP_OpenEphemeral_stack_vars { |
| 63253 | 63835 | VdbeCursor *pCx; |
| 63254 | 63836 | } ax; |
| 63255 | | - struct OP_OpenPseudo_stack_vars { |
| 63837 | + struct OP_SorterOpen_stack_vars { |
| 63256 | 63838 | VdbeCursor *pCx; |
| 63257 | 63839 | } ay; |
| 63840 | + struct OP_OpenPseudo_stack_vars { |
| 63841 | + VdbeCursor *pCx; |
| 63842 | + } az; |
| 63258 | 63843 | struct OP_SeekGt_stack_vars { |
| 63259 | 63844 | int res; |
| 63260 | 63845 | int oc; |
| 63261 | 63846 | VdbeCursor *pC; |
| 63262 | 63847 | UnpackedRecord r; |
| 63263 | 63848 | int nField; |
| 63264 | 63849 | i64 iKey; /* The rowid we are to seek to */ |
| 63265 | | - } az; |
| 63850 | + } ba; |
| 63266 | 63851 | struct OP_Seek_stack_vars { |
| 63267 | 63852 | VdbeCursor *pC; |
| 63268 | | - } ba; |
| 63853 | + } bb; |
| 63269 | 63854 | struct OP_Found_stack_vars { |
| 63270 | 63855 | int alreadyExists; |
| 63271 | 63856 | VdbeCursor *pC; |
| 63272 | 63857 | int res; |
| 63273 | 63858 | UnpackedRecord *pIdxKey; |
| 63274 | 63859 | UnpackedRecord r; |
| 63275 | 63860 | char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*3 + 7]; |
| 63276 | | - } bb; |
| 63861 | + } bc; |
| 63277 | 63862 | struct OP_IsUnique_stack_vars { |
| 63278 | 63863 | u16 ii; |
| 63279 | 63864 | VdbeCursor *pCx; |
| 63280 | 63865 | BtCursor *pCrsr; |
| 63281 | 63866 | u16 nField; |
| 63282 | 63867 | Mem *aMx; |
| 63283 | 63868 | UnpackedRecord r; /* B-Tree index search key */ |
| 63284 | 63869 | i64 R; /* Rowid stored in register P3 */ |
| 63285 | | - } bc; |
| 63870 | + } bd; |
| 63286 | 63871 | struct OP_NotExists_stack_vars { |
| 63287 | 63872 | VdbeCursor *pC; |
| 63288 | 63873 | BtCursor *pCrsr; |
| 63289 | 63874 | int res; |
| 63290 | 63875 | u64 iKey; |
| 63291 | | - } bd; |
| 63876 | + } be; |
| 63292 | 63877 | struct OP_NewRowid_stack_vars { |
| 63293 | 63878 | i64 v; /* The new rowid */ |
| 63294 | 63879 | VdbeCursor *pC; /* Cursor of table to get the new rowid */ |
| 63295 | 63880 | int res; /* Result of an sqlite3BtreeLast() */ |
| 63296 | 63881 | int cnt; /* Counter to limit the number of searches */ |
| 63297 | 63882 | Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ |
| 63298 | 63883 | VdbeFrame *pFrame; /* Root frame of VDBE */ |
| 63299 | | - } be; |
| 63884 | + } bf; |
| 63300 | 63885 | struct OP_InsertInt_stack_vars { |
| 63301 | 63886 | Mem *pData; /* MEM cell holding data for the record to be inserted */ |
| 63302 | 63887 | Mem *pKey; /* MEM cell holding key for the record */ |
| 63303 | 63888 | i64 iKey; /* The integer ROWID or key for the record to be inserted */ |
| 63304 | 63889 | VdbeCursor *pC; /* Cursor to table into which insert is written */ |
| | @@ -63305,155 +63890,161 @@ |
| 63305 | 63890 | int nZero; /* Number of zero-bytes to append */ |
| 63306 | 63891 | int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */ |
| 63307 | 63892 | const char *zDb; /* database name - used by the update hook */ |
| 63308 | 63893 | const char *zTbl; /* Table name - used by the opdate hook */ |
| 63309 | 63894 | int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */ |
| 63310 | | - } bf; |
| 63895 | + } bg; |
| 63311 | 63896 | struct OP_Delete_stack_vars { |
| 63312 | 63897 | i64 iKey; |
| 63313 | 63898 | VdbeCursor *pC; |
| 63314 | | - } bg; |
| 63899 | + } bh; |
| 63900 | + struct OP_SorterCompare_stack_vars { |
| 63901 | + VdbeCursor *pC; |
| 63902 | + int res; |
| 63903 | + } bi; |
| 63904 | + struct OP_SorterData_stack_vars { |
| 63905 | + VdbeCursor *pC; |
| 63906 | + } bj; |
| 63315 | 63907 | struct OP_RowData_stack_vars { |
| 63316 | 63908 | VdbeCursor *pC; |
| 63317 | 63909 | BtCursor *pCrsr; |
| 63318 | 63910 | u32 n; |
| 63319 | 63911 | i64 n64; |
| 63320 | | - } bh; |
| 63912 | + } bk; |
| 63321 | 63913 | struct OP_Rowid_stack_vars { |
| 63322 | 63914 | VdbeCursor *pC; |
| 63323 | 63915 | i64 v; |
| 63324 | 63916 | sqlite3_vtab *pVtab; |
| 63325 | 63917 | const sqlite3_module *pModule; |
| 63326 | | - } bi; |
| 63918 | + } bl; |
| 63327 | 63919 | struct OP_NullRow_stack_vars { |
| 63328 | 63920 | VdbeCursor *pC; |
| 63329 | | - } bj; |
| 63921 | + } bm; |
| 63330 | 63922 | struct OP_Last_stack_vars { |
| 63331 | 63923 | VdbeCursor *pC; |
| 63332 | 63924 | BtCursor *pCrsr; |
| 63333 | 63925 | int res; |
| 63334 | | - } bk; |
| 63926 | + } bn; |
| 63335 | 63927 | struct OP_Rewind_stack_vars { |
| 63336 | 63928 | VdbeCursor *pC; |
| 63337 | 63929 | BtCursor *pCrsr; |
| 63338 | 63930 | int res; |
| 63339 | | - } bl; |
| 63931 | + } bo; |
| 63340 | 63932 | struct OP_Next_stack_vars { |
| 63341 | 63933 | VdbeCursor *pC; |
| 63342 | | - BtCursor *pCrsr; |
| 63343 | 63934 | int res; |
| 63344 | | - } bm; |
| 63935 | + } bp; |
| 63345 | 63936 | struct OP_IdxInsert_stack_vars { |
| 63346 | 63937 | VdbeCursor *pC; |
| 63347 | 63938 | BtCursor *pCrsr; |
| 63348 | 63939 | int nKey; |
| 63349 | 63940 | const char *zKey; |
| 63350 | | - } bn; |
| 63941 | + } bq; |
| 63351 | 63942 | struct OP_IdxDelete_stack_vars { |
| 63352 | 63943 | VdbeCursor *pC; |
| 63353 | 63944 | BtCursor *pCrsr; |
| 63354 | 63945 | int res; |
| 63355 | 63946 | UnpackedRecord r; |
| 63356 | | - } bo; |
| 63947 | + } br; |
| 63357 | 63948 | struct OP_IdxRowid_stack_vars { |
| 63358 | 63949 | BtCursor *pCrsr; |
| 63359 | 63950 | VdbeCursor *pC; |
| 63360 | 63951 | i64 rowid; |
| 63361 | | - } bp; |
| 63952 | + } bs; |
| 63362 | 63953 | struct OP_IdxGE_stack_vars { |
| 63363 | 63954 | VdbeCursor *pC; |
| 63364 | 63955 | int res; |
| 63365 | 63956 | UnpackedRecord r; |
| 63366 | | - } bq; |
| 63957 | + } bt; |
| 63367 | 63958 | struct OP_Destroy_stack_vars { |
| 63368 | 63959 | int iMoved; |
| 63369 | 63960 | int iCnt; |
| 63370 | 63961 | Vdbe *pVdbe; |
| 63371 | 63962 | int iDb; |
| 63372 | | - } br; |
| 63963 | + } bu; |
| 63373 | 63964 | struct OP_Clear_stack_vars { |
| 63374 | 63965 | int nChange; |
| 63375 | | - } bs; |
| 63966 | + } bv; |
| 63376 | 63967 | struct OP_CreateTable_stack_vars { |
| 63377 | 63968 | int pgno; |
| 63378 | 63969 | int flags; |
| 63379 | 63970 | Db *pDb; |
| 63380 | | - } bt; |
| 63971 | + } bw; |
| 63381 | 63972 | struct OP_ParseSchema_stack_vars { |
| 63382 | 63973 | int iDb; |
| 63383 | 63974 | const char *zMaster; |
| 63384 | 63975 | char *zSql; |
| 63385 | 63976 | InitData initData; |
| 63386 | | - } bu; |
| 63977 | + } bx; |
| 63387 | 63978 | struct OP_IntegrityCk_stack_vars { |
| 63388 | 63979 | int nRoot; /* Number of tables to check. (Number of root pages.) */ |
| 63389 | 63980 | int *aRoot; /* Array of rootpage numbers for tables to be checked */ |
| 63390 | 63981 | int j; /* Loop counter */ |
| 63391 | 63982 | int nErr; /* Number of errors reported */ |
| 63392 | 63983 | char *z; /* Text of the error report */ |
| 63393 | 63984 | Mem *pnErr; /* Register keeping track of errors remaining */ |
| 63394 | | - } bv; |
| 63985 | + } by; |
| 63395 | 63986 | struct OP_RowSetRead_stack_vars { |
| 63396 | 63987 | i64 val; |
| 63397 | | - } bw; |
| 63988 | + } bz; |
| 63398 | 63989 | struct OP_RowSetTest_stack_vars { |
| 63399 | 63990 | int iSet; |
| 63400 | 63991 | int exists; |
| 63401 | | - } bx; |
| 63992 | + } ca; |
| 63402 | 63993 | struct OP_Program_stack_vars { |
| 63403 | 63994 | int nMem; /* Number of memory registers for sub-program */ |
| 63404 | 63995 | int nByte; /* Bytes of runtime space required for sub-program */ |
| 63405 | 63996 | Mem *pRt; /* Register to allocate runtime space */ |
| 63406 | 63997 | Mem *pMem; /* Used to iterate through memory cells */ |
| 63407 | 63998 | Mem *pEnd; /* Last memory cell in new array */ |
| 63408 | 63999 | VdbeFrame *pFrame; /* New vdbe frame to execute in */ |
| 63409 | 64000 | SubProgram *pProgram; /* Sub-program to execute */ |
| 63410 | 64001 | void *t; /* Token identifying trigger */ |
| 63411 | | - } by; |
| 64002 | + } cb; |
| 63412 | 64003 | struct OP_Param_stack_vars { |
| 63413 | 64004 | VdbeFrame *pFrame; |
| 63414 | 64005 | Mem *pIn; |
| 63415 | | - } bz; |
| 64006 | + } cc; |
| 63416 | 64007 | struct OP_MemMax_stack_vars { |
| 63417 | 64008 | Mem *pIn1; |
| 63418 | 64009 | VdbeFrame *pFrame; |
| 63419 | | - } ca; |
| 64010 | + } cd; |
| 63420 | 64011 | struct OP_AggStep_stack_vars { |
| 63421 | 64012 | int n; |
| 63422 | 64013 | int i; |
| 63423 | 64014 | Mem *pMem; |
| 63424 | 64015 | Mem *pRec; |
| 63425 | 64016 | sqlite3_context ctx; |
| 63426 | 64017 | sqlite3_value **apVal; |
| 63427 | | - } cb; |
| 64018 | + } ce; |
| 63428 | 64019 | struct OP_AggFinal_stack_vars { |
| 63429 | 64020 | Mem *pMem; |
| 63430 | | - } cc; |
| 64021 | + } cf; |
| 63431 | 64022 | struct OP_Checkpoint_stack_vars { |
| 63432 | 64023 | int i; /* Loop counter */ |
| 63433 | 64024 | int aRes[3]; /* Results */ |
| 63434 | 64025 | Mem *pMem; /* Write results here */ |
| 63435 | | - } cd; |
| 64026 | + } cg; |
| 63436 | 64027 | struct OP_JournalMode_stack_vars { |
| 63437 | 64028 | Btree *pBt; /* Btree to change journal mode of */ |
| 63438 | 64029 | Pager *pPager; /* Pager associated with pBt */ |
| 63439 | 64030 | int eNew; /* New journal mode */ |
| 63440 | 64031 | int eOld; /* The old journal mode */ |
| 63441 | 64032 | const char *zFilename; /* Name of database file for pPager */ |
| 63442 | | - } ce; |
| 64033 | + } ch; |
| 63443 | 64034 | struct OP_IncrVacuum_stack_vars { |
| 63444 | 64035 | Btree *pBt; |
| 63445 | | - } cf; |
| 64036 | + } ci; |
| 63446 | 64037 | struct OP_VBegin_stack_vars { |
| 63447 | 64038 | VTable *pVTab; |
| 63448 | | - } cg; |
| 64039 | + } cj; |
| 63449 | 64040 | struct OP_VOpen_stack_vars { |
| 63450 | 64041 | VdbeCursor *pCur; |
| 63451 | 64042 | sqlite3_vtab_cursor *pVtabCursor; |
| 63452 | 64043 | sqlite3_vtab *pVtab; |
| 63453 | 64044 | sqlite3_module *pModule; |
| 63454 | | - } ch; |
| 64045 | + } ck; |
| 63455 | 64046 | struct OP_VFilter_stack_vars { |
| 63456 | 64047 | int nArg; |
| 63457 | 64048 | int iQuery; |
| 63458 | 64049 | const sqlite3_module *pModule; |
| 63459 | 64050 | Mem *pQuery; |
| | @@ -63462,40 +64053,40 @@ |
| 63462 | 64053 | sqlite3_vtab *pVtab; |
| 63463 | 64054 | VdbeCursor *pCur; |
| 63464 | 64055 | int res; |
| 63465 | 64056 | int i; |
| 63466 | 64057 | Mem **apArg; |
| 63467 | | - } ci; |
| 64058 | + } cl; |
| 63468 | 64059 | struct OP_VColumn_stack_vars { |
| 63469 | 64060 | sqlite3_vtab *pVtab; |
| 63470 | 64061 | const sqlite3_module *pModule; |
| 63471 | 64062 | Mem *pDest; |
| 63472 | 64063 | sqlite3_context sContext; |
| 63473 | | - } cj; |
| 64064 | + } cm; |
| 63474 | 64065 | struct OP_VNext_stack_vars { |
| 63475 | 64066 | sqlite3_vtab *pVtab; |
| 63476 | 64067 | const sqlite3_module *pModule; |
| 63477 | 64068 | int res; |
| 63478 | 64069 | VdbeCursor *pCur; |
| 63479 | | - } ck; |
| 64070 | + } cn; |
| 63480 | 64071 | struct OP_VRename_stack_vars { |
| 63481 | 64072 | sqlite3_vtab *pVtab; |
| 63482 | 64073 | Mem *pName; |
| 63483 | | - } cl; |
| 64074 | + } co; |
| 63484 | 64075 | struct OP_VUpdate_stack_vars { |
| 63485 | 64076 | sqlite3_vtab *pVtab; |
| 63486 | 64077 | sqlite3_module *pModule; |
| 63487 | 64078 | int nArg; |
| 63488 | 64079 | int i; |
| 63489 | 64080 | sqlite_int64 rowid; |
| 63490 | 64081 | Mem **apArg; |
| 63491 | 64082 | Mem *pX; |
| 63492 | | - } cm; |
| 64083 | + } cp; |
| 63493 | 64084 | struct OP_Trace_stack_vars { |
| 63494 | 64085 | char *zTrace; |
| 63495 | 64086 | char *z; |
| 63496 | | - } cn; |
| 64087 | + } cq; |
| 63497 | 64088 | } u; |
| 63498 | 64089 | /* End automatically generated code |
| 63499 | 64090 | ********************************************************************/ |
| 63500 | 64091 | |
| 63501 | 64092 | assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| | @@ -63591,11 +64182,11 @@ |
| 63591 | 64182 | if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){ |
| 63592 | 64183 | assert( pOp->p2>0 ); |
| 63593 | 64184 | assert( pOp->p2<=p->nMem ); |
| 63594 | 64185 | pOut = &aMem[pOp->p2]; |
| 63595 | 64186 | memAboutToChange(p, pOut); |
| 63596 | | - sqlite3VdbeMemReleaseExternal(pOut); |
| 64187 | + MemReleaseExt(pOut); |
| 63597 | 64188 | pOut->flags = MEM_Int; |
| 63598 | 64189 | } |
| 63599 | 64190 | |
| 63600 | 64191 | /* Sanity checking on other operands */ |
| 63601 | 64192 | #ifdef SQLITE_DEBUG |
| | @@ -65061,10 +65652,11 @@ |
| 65061 | 65652 | u8 *zEndHdr; /* Pointer to first byte after the header */ |
| 65062 | 65653 | u32 offset; /* Offset into the data */ |
| 65063 | 65654 | u32 szField; /* Number of bytes in the content of a field */ |
| 65064 | 65655 | int szHdr; /* Size of the header size field at start of record */ |
| 65065 | 65656 | int avail; /* Number of bytes of available data */ |
| 65657 | + u32 t; /* A type code from the record header */ |
| 65066 | 65658 | Mem *pReg; /* PseudoTable input register */ |
| 65067 | 65659 | #endif /* local variables moved into u.am */ |
| 65068 | 65660 | |
| 65069 | 65661 | |
| 65070 | 65662 | u.am.p1 = pOp->p1; |
| | @@ -65073,11 +65665,10 @@ |
| 65073 | 65665 | memset(&u.am.sMem, 0, sizeof(u.am.sMem)); |
| 65074 | 65666 | assert( u.am.p1<p->nCursor ); |
| 65075 | 65667 | assert( pOp->p3>0 && pOp->p3<=p->nMem ); |
| 65076 | 65668 | u.am.pDest = &aMem[pOp->p3]; |
| 65077 | 65669 | memAboutToChange(p, u.am.pDest); |
| 65078 | | - MemSetTypeFlag(u.am.pDest, MEM_Null); |
| 65079 | 65670 | u.am.zRec = 0; |
| 65080 | 65671 | |
| 65081 | 65672 | /* This block sets the variable u.am.payloadSize to be the total number of |
| 65082 | 65673 | ** bytes in the record. |
| 65083 | 65674 | ** |
| | @@ -65117,11 +65708,11 @@ |
| 65117 | 65708 | }else{ |
| 65118 | 65709 | assert( sqlite3BtreeCursorIsValid(u.am.pCrsr) ); |
| 65119 | 65710 | rc = sqlite3BtreeDataSize(u.am.pCrsr, &u.am.payloadSize); |
| 65120 | 65711 | assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 65121 | 65712 | } |
| 65122 | | - }else if( u.am.pC->pseudoTableReg>0 ){ |
| 65713 | + }else if( ALWAYS(u.am.pC->pseudoTableReg>0) ){ |
| 65123 | 65714 | u.am.pReg = &aMem[u.am.pC->pseudoTableReg]; |
| 65124 | 65715 | assert( u.am.pReg->flags & MEM_Blob ); |
| 65125 | 65716 | assert( memIsValid(u.am.pReg) ); |
| 65126 | 65717 | u.am.payloadSize = u.am.pReg->n; |
| 65127 | 65718 | u.am.zRec = u.am.pReg->z; |
| | @@ -65130,13 +65721,14 @@ |
| 65130 | 65721 | }else{ |
| 65131 | 65722 | /* Consider the row to be NULL */ |
| 65132 | 65723 | u.am.payloadSize = 0; |
| 65133 | 65724 | } |
| 65134 | 65725 | |
| 65135 | | - /* If u.am.payloadSize is 0, then just store a NULL */ |
| 65726 | + /* If u.am.payloadSize is 0, then just store a NULL. This can happen because of |
| 65727 | + ** nullRow or because of a corrupt database. */ |
| 65136 | 65728 | if( u.am.payloadSize==0 ){ |
| 65137 | | - assert( u.am.pDest->flags&MEM_Null ); |
| 65729 | + MemSetTypeFlag(u.am.pDest, MEM_Null); |
| 65138 | 65730 | goto op_column_out; |
| 65139 | 65731 | } |
| 65140 | 65732 | assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 ); |
| 65141 | 65733 | if( u.am.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 65142 | 65734 | goto too_big; |
| | @@ -65239,12 +65831,18 @@ |
| 65239 | 65831 | ** of the record to the start of the data for the u.am.i-th column |
| 65240 | 65832 | */ |
| 65241 | 65833 | for(u.am.i=0; u.am.i<u.am.nField; u.am.i++){ |
| 65242 | 65834 | if( u.am.zIdx<u.am.zEndHdr ){ |
| 65243 | 65835 | u.am.aOffset[u.am.i] = u.am.offset; |
| 65244 | | - u.am.zIdx += getVarint32(u.am.zIdx, u.am.aType[u.am.i]); |
| 65245 | | - u.am.szField = sqlite3VdbeSerialTypeLen(u.am.aType[u.am.i]); |
| 65836 | + if( u.am.zIdx[0]<0x80 ){ |
| 65837 | + u.am.t = u.am.zIdx[0]; |
| 65838 | + u.am.zIdx++; |
| 65839 | + }else{ |
| 65840 | + u.am.zIdx += sqlite3GetVarint32(u.am.zIdx, &u.am.t); |
| 65841 | + } |
| 65842 | + u.am.aType[u.am.i] = u.am.t; |
| 65843 | + u.am.szField = sqlite3VdbeSerialTypeLen(u.am.t); |
| 65246 | 65844 | u.am.offset += u.am.szField; |
| 65247 | 65845 | if( u.am.offset<u.am.szField ){ /* True if u.am.offset overflows */ |
| 65248 | 65846 | u.am.zIdx = &u.am.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ |
| 65249 | 65847 | break; |
| 65250 | 65848 | } |
| | @@ -65281,11 +65879,11 @@ |
| 65281 | 65879 | ** a pointer to a Mem object. |
| 65282 | 65880 | */ |
| 65283 | 65881 | if( u.am.aOffset[u.am.p2] ){ |
| 65284 | 65882 | assert( rc==SQLITE_OK ); |
| 65285 | 65883 | if( u.am.zRec ){ |
| 65286 | | - sqlite3VdbeMemReleaseExternal(u.am.pDest); |
| 65884 | + MemReleaseExt(u.am.pDest); |
| 65287 | 65885 | sqlite3VdbeSerialGet((u8 *)&u.am.zRec[u.am.aOffset[u.am.p2]], u.am.aType[u.am.p2], u.am.pDest); |
| 65288 | 65886 | }else{ |
| 65289 | 65887 | u.am.len = sqlite3VdbeSerialTypeLen(u.am.aType[u.am.p2]); |
| 65290 | 65888 | sqlite3VdbeMemMove(&u.am.sMem, u.am.pDest); |
| 65291 | 65889 | rc = sqlite3VdbeMemFromBtree(u.am.pCrsr, u.am.aOffset[u.am.p2], u.am.len, u.am.pC->isIndex, &u.am.sMem); |
| | @@ -65298,11 +65896,11 @@ |
| 65298 | 65896 | u.am.pDest->enc = encoding; |
| 65299 | 65897 | }else{ |
| 65300 | 65898 | if( pOp->p4type==P4_MEM ){ |
| 65301 | 65899 | sqlite3VdbeMemShallowCopy(u.am.pDest, pOp->p4.pMem, MEM_Static); |
| 65302 | 65900 | }else{ |
| 65303 | | - assert( u.am.pDest->flags&MEM_Null ); |
| 65901 | + MemSetTypeFlag(u.am.pDest, MEM_Null); |
| 65304 | 65902 | } |
| 65305 | 65903 | } |
| 65306 | 65904 | |
| 65307 | 65905 | /* If we dynamically allocated space to hold the data (in the |
| 65308 | 65906 | ** sqlite3VdbeMemFromBtree() call above) then transfer control of that |
| | @@ -65500,11 +66098,11 @@ |
| 65500 | 66098 | i64 nEntry; |
| 65501 | 66099 | BtCursor *pCrsr; |
| 65502 | 66100 | #endif /* local variables moved into u.ap */ |
| 65503 | 66101 | |
| 65504 | 66102 | u.ap.pCrsr = p->apCsr[pOp->p1]->pCursor; |
| 65505 | | - if( u.ap.pCrsr ){ |
| 66103 | + if( ALWAYS(u.ap.pCrsr) ){ |
| 65506 | 66104 | rc = sqlite3BtreeCount(u.ap.pCrsr, &u.ap.nEntry); |
| 65507 | 66105 | }else{ |
| 65508 | 66106 | u.ap.nEntry = 0; |
| 65509 | 66107 | } |
| 65510 | 66108 | pOut->u.i = u.ap.nEntry; |
| | @@ -66076,19 +66674,13 @@ |
| 66076 | 66674 | u.aw.pCur->nullRow = 1; |
| 66077 | 66675 | u.aw.pCur->isOrdered = 1; |
| 66078 | 66676 | rc = sqlite3BtreeCursor(u.aw.pX, u.aw.p2, u.aw.wrFlag, u.aw.pKeyInfo, u.aw.pCur->pCursor); |
| 66079 | 66677 | u.aw.pCur->pKeyInfo = u.aw.pKeyInfo; |
| 66080 | 66678 | |
| 66081 | | - /* Since it performs no memory allocation or IO, the only values that |
| 66082 | | - ** sqlite3BtreeCursor() may return are SQLITE_EMPTY and SQLITE_OK. |
| 66083 | | - ** SQLITE_EMPTY is only returned when attempting to open the table |
| 66084 | | - ** rooted at page 1 of a zero-byte database. */ |
| 66085 | | - assert( rc==SQLITE_EMPTY || rc==SQLITE_OK ); |
| 66086 | | - if( rc==SQLITE_EMPTY ){ |
| 66087 | | - u.aw.pCur->pCursor = 0; |
| 66088 | | - rc = SQLITE_OK; |
| 66089 | | - } |
| 66679 | + /* Since it performs no memory allocation or IO, the only value that |
| 66680 | + ** sqlite3BtreeCursor() may return is SQLITE_OK. */ |
| 66681 | + assert( rc==SQLITE_OK ); |
| 66090 | 66682 | |
| 66091 | 66683 | /* Set the VdbeCursor.isTable and isIndex variables. Previous versions of |
| 66092 | 66684 | ** SQLite used to check if the root-page flags were sane at this point |
| 66093 | 66685 | ** and report database corruption if they were not, but this check has |
| 66094 | 66686 | ** since moved into the btree layer. */ |
| | @@ -66095,11 +66687,11 @@ |
| 66095 | 66687 | u.aw.pCur->isTable = pOp->p4type!=P4_KEYINFO; |
| 66096 | 66688 | u.aw.pCur->isIndex = !u.aw.pCur->isTable; |
| 66097 | 66689 | break; |
| 66098 | 66690 | } |
| 66099 | 66691 | |
| 66100 | | -/* Opcode: OpenEphemeral P1 P2 * P4 * |
| 66692 | +/* Opcode: OpenEphemeral P1 P2 * P4 P5 |
| 66101 | 66693 | ** |
| 66102 | 66694 | ** Open a new cursor P1 to a transient table. |
| 66103 | 66695 | ** The cursor is always opened read/write even if |
| 66104 | 66696 | ** the main database is read-only. The ephemeral |
| 66105 | 66697 | ** table is deleted automatically when the cursor is closed. |
| | @@ -66112,10 +66704,15 @@ |
| 66112 | 66704 | ** This opcode was once called OpenTemp. But that created |
| 66113 | 66705 | ** confusion because the term "temp table", might refer either |
| 66114 | 66706 | ** to a TEMP table at the SQL level, or to a table opened by |
| 66115 | 66707 | ** this opcode. Then this opcode was call OpenVirtual. But |
| 66116 | 66708 | ** that created confusion with the whole virtual-table idea. |
| 66709 | +** |
| 66710 | +** The P5 parameter can be a mask of the BTREE_* flags defined |
| 66711 | +** in btree.h. These flags control aspects of the operation of |
| 66712 | +** the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are |
| 66713 | +** added automatically. |
| 66117 | 66714 | */ |
| 66118 | 66715 | /* Opcode: OpenAutoindex P1 P2 * P4 * |
| 66119 | 66716 | ** |
| 66120 | 66717 | ** This opcode works the same as OP_OpenEphemeral. It has a |
| 66121 | 66718 |