Fossil SCM
Update the built-in SQLite to an early alpha for 3.32.0, for testing.
Commit
d239550e9e00a9f894a296c9b539f29b52d1650e999baa466c15624a2c5baeff
Parent
13919ef8fcddd93…
2 files changed
+609
-729
+57
-49
+609
-729
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | -** version 3.31.1. By combining all the individual C code files into this | |
| 3 | +** version 3.32.0. By combining all the individual C code files into this | |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| @@ -378,13 +378,10 @@ | ||
| 378 | 378 | "FTS5_ENABLE_TEST_MI", |
| 379 | 379 | #endif |
| 380 | 380 | #if SQLITE_FTS5_NO_WITHOUT_ROWID |
| 381 | 381 | "FTS5_NO_WITHOUT_ROWID", |
| 382 | 382 | #endif |
| 383 | -#if SQLITE_HAS_CODEC | |
| 384 | - "HAS_CODEC", | |
| 385 | -#endif | |
| 386 | 383 | #if HAVE_ISNAN || SQLITE_HAVE_ISNAN |
| 387 | 384 | "HAVE_ISNAN", |
| 388 | 385 | #endif |
| 389 | 386 | #if SQLITE_HOMEGROWN_RECURSIVE_MUTEX |
| 390 | 387 | "HOMEGROWN_RECURSIVE_MUTEX", |
| @@ -1163,13 +1160,13 @@ | ||
| 1163 | 1160 | ** |
| 1164 | 1161 | ** See also: [sqlite3_libversion()], |
| 1165 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1166 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1167 | 1164 | */ |
| 1168 | -#define SQLITE_VERSION "3.31.1" | |
| 1169 | -#define SQLITE_VERSION_NUMBER 3031001 | |
| 1170 | -#define SQLITE_SOURCE_ID "2020-01-28 15:02:23 04885763c4cd00cbca26d048f2b19316bfc93e8edebeceaa171ebfc6c563d53e" | |
| 1165 | +#define SQLITE_VERSION "3.32.0" | |
| 1166 | +#define SQLITE_VERSION_NUMBER 3032000 | |
| 1167 | +#define SQLITE_SOURCE_ID "2020-02-27 16:21:39 951b39ca74c9bd933139e099d5555283278db475f410f202c162e5d1e6aef933" | |
| 1171 | 1168 | |
| 1172 | 1169 | /* |
| 1173 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1174 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1175 | 1172 | ** |
| @@ -4657,10 +4654,63 @@ | ||
| 4657 | 4654 | */ |
| 4658 | 4655 | SQLITE_API const char *sqlite3_filename_database(const char*); |
| 4659 | 4656 | SQLITE_API const char *sqlite3_filename_journal(const char*); |
| 4660 | 4657 | SQLITE_API const char *sqlite3_filename_wal(const char*); |
| 4661 | 4658 | |
| 4659 | +/* | |
| 4660 | +** CAPI3REF: Create and Destroy VFS Filenames | |
| 4661 | +** | |
| 4662 | +** These interfces are provided for use by [VFS shim] implementations and | |
| 4663 | +** are not useful outside of that context. | |
| 4664 | +** | |
| 4665 | +** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of | |
| 4666 | +** database filename D with corresponding journal file J and WAL file W and | |
| 4667 | +** with N URI parameters key/values pairs in the array P. The result from | |
| 4668 | +** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that | |
| 4669 | +** is safe to pass to routines like: | |
| 4670 | +** <ul> | |
| 4671 | +** <li> [sqlite3_uri_parameter()], | |
| 4672 | +** <li> [sqlite3_uri_boolean()], | |
| 4673 | +** <li> [sqlite3_uri_int64()], | |
| 4674 | +** <li> [sqlite3_uri_key()], | |
| 4675 | +** <li> [sqlite3_filename_database()], | |
| 4676 | +** <li> [sqlite3_filename_journal()], or | |
| 4677 | +** <li> [sqlite3_filename_wal()]. | |
| 4678 | +** </ul> | |
| 4679 | +** If a memory allocation error occurs, sqlite3_create_filename() might | |
| 4680 | +** return a NULL pointer. The memory obtained from sqlite3_create_filename(X) | |
| 4681 | +** must be released by a corresponding call to sqlite3_free_filename(Y). | |
| 4682 | +** | |
| 4683 | +** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array | |
| 4684 | +** of 2*N pointers to strings. Each pair of pointers in this array corresponds | |
| 4685 | +** to a key and value for a query parameter. The P parameter may be a NULL | |
| 4686 | +** pointer if N is zero. None of the 2*N pointers in the P array may be | |
| 4687 | +** NULL pointers and key pointers should not be empty strings. | |
| 4688 | +** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may | |
| 4689 | +** be NULL pointers, though they can be empty strings. | |
| 4690 | +** | |
| 4691 | +** The sqlite3_free_filename(Y) routine releases a memory allocation | |
| 4692 | +** previously obtained from sqlite3_create_filename(). Invoking | |
| 4693 | +** sqlite3_free_filename(Y) is a NULL pointer is a harmless no-op. | |
| 4694 | +** | |
| 4695 | +** If the Y parameter to sqlite3_free_filename(Y) is anything other | |
| 4696 | +** than a NULL pointer or a pointer previously acquired from | |
| 4697 | +** sqlite3_create_filename(), then bad things such as heap | |
| 4698 | +** corruption or segfaults may occur. The value Y should be | |
| 4699 | +** used again after sqlite3_free_filename(Y) has been called. This means | |
| 4700 | +** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y, | |
| 4701 | +** then the corresponding [sqlite3_module.xClose() method should also be | |
| 4702 | +** invoked prior to calling sqlite3_free_filename(Y). | |
| 4703 | +*/ | |
| 4704 | +SQLITE_API char *sqlite3_create_filename( | |
| 4705 | + const char *zDatabase, | |
| 4706 | + const char *zJournal, | |
| 4707 | + const char *zWal, | |
| 4708 | + int nParam, | |
| 4709 | + const char **azParam | |
| 4710 | +); | |
| 4711 | +SQLITE_API void sqlite3_free_filename(char*); | |
| 4662 | 4712 | |
| 4663 | 4713 | /* |
| 4664 | 4714 | ** CAPI3REF: Error Codes And Messages |
| 4665 | 4715 | ** METHOD: sqlite3 |
| 4666 | 4716 | ** |
| @@ -5239,11 +5289,11 @@ | ||
| 5239 | 5289 | ** occurrences have the same index as the first occurrence. |
| 5240 | 5290 | ** ^The index for named parameters can be looked up using the |
| 5241 | 5291 | ** [sqlite3_bind_parameter_index()] API if desired. ^The index |
| 5242 | 5292 | ** for "?NNN" parameters is the value of NNN. |
| 5243 | 5293 | ** ^The NNN value must be between 1 and the [sqlite3_limit()] |
| 5244 | -** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). | |
| 5294 | +** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766). | |
| 5245 | 5295 | ** |
| 5246 | 5296 | ** ^The third argument is the value to bind to the parameter. |
| 5247 | 5297 | ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
| 5248 | 5298 | ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter |
| 5249 | 5299 | ** is ignored and the end result is the same as sqlite3_bind_null(). |
| @@ -6857,55 +6907,10 @@ | ||
| 6857 | 6907 | sqlite3*, |
| 6858 | 6908 | void*, |
| 6859 | 6909 | void(*)(void*,sqlite3*,int eTextRep,const void*) |
| 6860 | 6910 | ); |
| 6861 | 6911 | |
| 6862 | -#ifdef SQLITE_HAS_CODEC | |
| 6863 | -/* | |
| 6864 | -** Specify the key for an encrypted database. This routine should be | |
| 6865 | -** called right after sqlite3_open(). | |
| 6866 | -** | |
| 6867 | -** The code to implement this API is not available in the public release | |
| 6868 | -** of SQLite. | |
| 6869 | -*/ | |
| 6870 | -SQLITE_API int sqlite3_key( | |
| 6871 | - sqlite3 *db, /* Database to be rekeyed */ | |
| 6872 | - const void *pKey, int nKey /* The key */ | |
| 6873 | -); | |
| 6874 | -SQLITE_API int sqlite3_key_v2( | |
| 6875 | - sqlite3 *db, /* Database to be rekeyed */ | |
| 6876 | - const char *zDbName, /* Name of the database */ | |
| 6877 | - const void *pKey, int nKey /* The key */ | |
| 6878 | -); | |
| 6879 | - | |
| 6880 | -/* | |
| 6881 | -** Change the key on an open database. If the current database is not | |
| 6882 | -** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the | |
| 6883 | -** database is decrypted. | |
| 6884 | -** | |
| 6885 | -** The code to implement this API is not available in the public release | |
| 6886 | -** of SQLite. | |
| 6887 | -*/ | |
| 6888 | -SQLITE_API int sqlite3_rekey( | |
| 6889 | - sqlite3 *db, /* Database to be rekeyed */ | |
| 6890 | - const void *pKey, int nKey /* The new key */ | |
| 6891 | -); | |
| 6892 | -SQLITE_API int sqlite3_rekey_v2( | |
| 6893 | - sqlite3 *db, /* Database to be rekeyed */ | |
| 6894 | - const char *zDbName, /* Name of the database */ | |
| 6895 | - const void *pKey, int nKey /* The new key */ | |
| 6896 | -); | |
| 6897 | - | |
| 6898 | -/* | |
| 6899 | -** Specify the activation key for a SEE database. Unless | |
| 6900 | -** activated, none of the SEE routines will work. | |
| 6901 | -*/ | |
| 6902 | -SQLITE_API void sqlite3_activate_see( | |
| 6903 | - const char *zPassPhrase /* Activation phrase */ | |
| 6904 | -); | |
| 6905 | -#endif | |
| 6906 | - | |
| 6907 | 6912 | #ifdef SQLITE_ENABLE_CEROD |
| 6908 | 6913 | /* |
| 6909 | 6914 | ** Specify the activation key for a CEROD database. Unless |
| 6910 | 6915 | ** activated, none of the CEROD routines will work. |
| 6911 | 6916 | */ |
| @@ -13270,13 +13275,16 @@ | ||
| 13270 | 13275 | #endif |
| 13271 | 13276 | |
| 13272 | 13277 | |
| 13273 | 13278 | /* |
| 13274 | 13279 | ** The maximum value of a ?nnn wildcard that the parser will accept. |
| 13280 | +** If the value exceeds 32767 then extra space is required for the Expr | |
| 13281 | +** structure. But otherwise, we believe that the number can be as large | |
| 13282 | +** as a signed 32-bit integer can hold. | |
| 13275 | 13283 | */ |
| 13276 | 13284 | #ifndef SQLITE_MAX_VARIABLE_NUMBER |
| 13277 | -# define SQLITE_MAX_VARIABLE_NUMBER 999 | |
| 13285 | +# define SQLITE_MAX_VARIABLE_NUMBER 32766 | |
| 13278 | 13286 | #endif |
| 13279 | 13287 | |
| 13280 | 13288 | /* Maximum page size. The upper bound on this value is 65536. This a limit |
| 13281 | 13289 | ** imposed by the use of 16-bit offsets within each page. |
| 13282 | 13290 | ** |
| @@ -15253,12 +15261,12 @@ | ||
| 15253 | 15261 | #define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */ |
| 15254 | 15262 | #define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */ |
| 15255 | 15263 | #define OP_IncrVacuum 60 /* jump */ |
| 15256 | 15264 | #define OP_VNext 61 /* jump */ |
| 15257 | 15265 | #define OP_Init 62 /* jump, synopsis: Start at P2 */ |
| 15258 | -#define OP_PureFunc 63 /* synopsis: r[P3]=func(r[P2@P5]) */ | |
| 15259 | -#define OP_Function 64 /* synopsis: r[P3]=func(r[P2@P5]) */ | |
| 15266 | +#define OP_PureFunc 63 /* synopsis: r[P3]=func(r[P2@NP]) */ | |
| 15267 | +#define OP_Function 64 /* synopsis: r[P3]=func(r[P2@NP]) */ | |
| 15260 | 15268 | #define OP_Return 65 |
| 15261 | 15269 | #define OP_EndCoroutine 66 |
| 15262 | 15270 | #define OP_HaltIfNull 67 /* synopsis: if r[P3]=null halt */ |
| 15263 | 15271 | #define OP_Halt 68 |
| 15264 | 15272 | #define OP_Integer 69 /* synopsis: r[P2]=P1 */ |
| @@ -15320,12 +15328,12 @@ | ||
| 15320 | 15328 | #define OP_SorterData 125 /* synopsis: r[P2]=data */ |
| 15321 | 15329 | #define OP_RowData 126 /* synopsis: r[P2]=data */ |
| 15322 | 15330 | #define OP_Rowid 127 /* synopsis: r[P2]=rowid */ |
| 15323 | 15331 | #define OP_NullRow 128 |
| 15324 | 15332 | #define OP_SeekEnd 129 |
| 15325 | -#define OP_SorterInsert 130 /* synopsis: key=r[P2] */ | |
| 15326 | -#define OP_IdxInsert 131 /* synopsis: key=r[P2] */ | |
| 15333 | +#define OP_IdxInsert 130 /* synopsis: key=r[P2] */ | |
| 15334 | +#define OP_SorterInsert 131 /* synopsis: key=r[P2] */ | |
| 15327 | 15335 | #define OP_IdxDelete 132 /* synopsis: key=r[P2@P3] */ |
| 15328 | 15336 | #define OP_DeferredSeek 133 /* synopsis: Move P3 to P1.rowid if needed */ |
| 15329 | 15337 | #define OP_IdxRowid 134 /* synopsis: r[P2]=rowid */ |
| 15330 | 15338 | #define OP_FinishSeek 135 |
| 15331 | 15339 | #define OP_Destroy 136 |
| @@ -15475,10 +15483,11 @@ | ||
| 15475 | 15483 | SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1); |
| 15476 | 15484 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2); |
| 15477 | 15485 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3); |
| 15478 | 15486 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5); |
| 15479 | 15487 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 15488 | +SQLITE_PRIVATE void sqlite3VdbeJumpHereOrPopInst(Vdbe*, int addr); | |
| 15480 | 15489 | SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 15481 | 15490 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 15482 | 15491 | #ifdef SQLITE_DEBUG |
| 15483 | 15492 | SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask, int); |
| 15484 | 15493 | #else |
| @@ -15770,13 +15779,10 @@ | ||
| 15770 | 15779 | SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); |
| 15771 | 15780 | |
| 15772 | 15781 | /* Functions used to configure a Pager object. */ |
| 15773 | 15782 | SQLITE_PRIVATE void sqlite3PagerSetBusyHandler(Pager*, int(*)(void *), void *); |
| 15774 | 15783 | SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); |
| 15775 | -#ifdef SQLITE_HAS_CODEC | |
| 15776 | -SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager*,Pager*); | |
| 15777 | -#endif | |
| 15778 | 15784 | SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int); |
| 15779 | 15785 | SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int); |
| 15780 | 15786 | SQLITE_PRIVATE int sqlite3PagerSetSpillsize(Pager*, int); |
| 15781 | 15787 | SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64); |
| 15782 | 15788 | SQLITE_PRIVATE void sqlite3PagerShrink(Pager*); |
| @@ -15866,14 +15872,10 @@ | ||
| 15866 | 15872 | /* Functions used to truncate the database file. */ |
| 15867 | 15873 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno); |
| 15868 | 15874 | |
| 15869 | 15875 | SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16); |
| 15870 | 15876 | |
| 15871 | -#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL) | |
| 15872 | -SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *); | |
| 15873 | -#endif | |
| 15874 | - | |
| 15875 | 15877 | /* Functions to support testing and debugging. */ |
| 15876 | 15878 | #if !defined(NDEBUG) || defined(SQLITE_TEST) |
| 15877 | 15879 | SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*); |
| 15878 | 15880 | SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*); |
| 15879 | 15881 | #endif |
| @@ -17426,12 +17428,15 @@ | ||
| 17426 | 17428 | ** done as a macro so that it will be optimized out when virtual |
| 17427 | 17429 | ** table support is omitted from the build. |
| 17428 | 17430 | */ |
| 17429 | 17431 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 17430 | 17432 | # define IsVirtual(X) ((X)->nModuleArg) |
| 17433 | +# define ExprIsVtab(X) \ | |
| 17434 | + ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->nModuleArg) | |
| 17431 | 17435 | #else |
| 17432 | 17436 | # define IsVirtual(X) 0 |
| 17437 | +# define ExprIsVtab(X) 0 | |
| 17433 | 17438 | #endif |
| 17434 | 17439 | |
| 17435 | 17440 | /* |
| 17436 | 17441 | ** Macros to determine if a column is hidden. IsOrdinaryHiddenColumn() |
| 17437 | 17442 | ** only works for non-virtual tables (ordinary tables and views) and is |
| @@ -17785,14 +17790,14 @@ | ||
| 17785 | 17790 | ** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater |
| 17786 | 17791 | ** than 32767 we have to make it 32-bit. 16-bit is preferred because |
| 17787 | 17792 | ** it uses less memory in the Expr object, which is a big memory user |
| 17788 | 17793 | ** in systems with lots of prepared statements. And few applications |
| 17789 | 17794 | ** need more than about 10 or 20 variables. But some extreme users want |
| 17790 | -** to have prepared statements with over 32767 variables, and for them | |
| 17795 | +** to have prepared statements with over 32766 variables, and for them | |
| 17791 | 17796 | ** the option is available (at compile-time). |
| 17792 | 17797 | */ |
| 17793 | -#if SQLITE_MAX_VARIABLE_NUMBER<=32767 | |
| 17798 | +#if SQLITE_MAX_VARIABLE_NUMBER<32767 | |
| 17794 | 17799 | typedef i16 ynVar; |
| 17795 | 17800 | #else |
| 17796 | 17801 | typedef int ynVar; |
| 17797 | 17802 | #endif |
| 17798 | 17803 | |
| @@ -19107,17 +19112,20 @@ | ||
| 19107 | 19112 | #define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__) |
| 19108 | 19113 | #define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__) |
| 19109 | 19114 | #ifdef SQLITE_DEBUG |
| 19110 | 19115 | SQLITE_PRIVATE int sqlite3NomemError(int); |
| 19111 | 19116 | SQLITE_PRIVATE int sqlite3IoerrnomemError(int); |
| 19112 | -SQLITE_PRIVATE int sqlite3CorruptPgnoError(int,Pgno); | |
| 19113 | 19117 | # define SQLITE_NOMEM_BKPT sqlite3NomemError(__LINE__) |
| 19114 | 19118 | # define SQLITE_IOERR_NOMEM_BKPT sqlite3IoerrnomemError(__LINE__) |
| 19115 | -# define SQLITE_CORRUPT_PGNO(P) sqlite3CorruptPgnoError(__LINE__,(P)) | |
| 19116 | 19119 | #else |
| 19117 | 19120 | # define SQLITE_NOMEM_BKPT SQLITE_NOMEM |
| 19118 | 19121 | # define SQLITE_IOERR_NOMEM_BKPT SQLITE_IOERR_NOMEM |
| 19122 | +#endif | |
| 19123 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_CORRUPT_PGNO) | |
| 19124 | +SQLITE_PRIVATE int sqlite3CorruptPgnoError(int,Pgno); | |
| 19125 | +# define SQLITE_CORRUPT_PGNO(P) sqlite3CorruptPgnoError(__LINE__,(P)) | |
| 19126 | +#else | |
| 19119 | 19127 | # define SQLITE_CORRUPT_PGNO(P) sqlite3CorruptError(__LINE__) |
| 19120 | 19128 | #endif |
| 19121 | 19129 | |
| 19122 | 19130 | /* |
| 19123 | 19131 | ** FTS3 and FTS4 both require virtual table support |
| @@ -19383,15 +19391,11 @@ | ||
| 19383 | 19391 | SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| 19384 | 19392 | SQLITE_PRIVATE void sqlite3AddGenerated(Parse*,Expr*,Token*); |
| 19385 | 19393 | SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*); |
| 19386 | 19394 | SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, |
| 19387 | 19395 | sqlite3_vfs**,char**,char **); |
| 19388 | -#ifdef SQLITE_HAS_CODEC | |
| 19389 | -SQLITE_PRIVATE int sqlite3CodecQueryParameters(sqlite3*,const char*,const char*); | |
| 19390 | -#else | |
| 19391 | -# define sqlite3CodecQueryParameters(A,B,C) 0 | |
| 19392 | -#endif | |
| 19396 | +#define sqlite3CodecQueryParameters(A,B,C) 0 | |
| 19393 | 19397 | SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*); |
| 19394 | 19398 | |
| 19395 | 19399 | #ifdef SQLITE_UNTESTABLE |
| 19396 | 19400 | # define sqlite3FaultSim(X) SQLITE_OK |
| 19397 | 19401 | #else |
| @@ -19699,10 +19703,12 @@ | ||
| 19699 | 19703 | ** macros handle the common case without a procedure call, but then call |
| 19700 | 19704 | ** the procedure for larger varints. |
| 19701 | 19705 | */ |
| 19702 | 19706 | #define getVarint32(A,B) \ |
| 19703 | 19707 | (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B))) |
| 19708 | +#define getVarint32NR(A,B) \ | |
| 19709 | + B=(u32)*(A);if(B>=0x80)sqlite3GetVarint32((A),(u32*)&(B)) | |
| 19704 | 19710 | #define putVarint32(A,B) \ |
| 19705 | 19711 | (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\ |
| 19706 | 19712 | sqlite3PutVarint((A),(B))) |
| 19707 | 19713 | #define getVarint sqlite3GetVarint |
| 19708 | 19714 | #define putVarint sqlite3PutVarint |
| @@ -20322,20 +20328,13 @@ | ||
| 20322 | 20328 | ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options. |
| 20323 | 20329 | ** |
| 20324 | 20330 | ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally |
| 20325 | 20331 | ** disabled. The default value may be changed by compiling with the |
| 20326 | 20332 | ** SQLITE_USE_URI symbol defined. |
| 20327 | -** | |
| 20328 | -** URI filenames are enabled by default if SQLITE_HAS_CODEC is | |
| 20329 | -** enabled. | |
| 20330 | 20333 | */ |
| 20331 | 20334 | #ifndef SQLITE_USE_URI |
| 20332 | -# ifdef SQLITE_HAS_CODEC | |
| 20333 | -# define SQLITE_USE_URI 1 | |
| 20334 | -# else | |
| 20335 | -# define SQLITE_USE_URI 0 | |
| 20336 | -# endif | |
| 20335 | +# define SQLITE_USE_URI 0 | |
| 20337 | 20336 | #endif |
| 20338 | 20337 | |
| 20339 | 20338 | /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the |
| 20340 | 20339 | ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if |
| 20341 | 20340 | ** that compile-time option is omitted. |
| @@ -21062,10 +21061,11 @@ | ||
| 21062 | 21061 | SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); |
| 21063 | 21062 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); |
| 21064 | 21063 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); |
| 21065 | 21064 | SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8); |
| 21066 | 21065 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*); |
| 21066 | +SQLITE_PRIVATE int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*); | |
| 21067 | 21067 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); |
| 21068 | 21068 | SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); |
| 21069 | 21069 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 21070 | 21070 | SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*); |
| 21071 | 21071 | #endif |
| @@ -25712,10 +25712,11 @@ | ||
| 25712 | 25712 | |
| 25713 | 25713 | #ifdef SQLITE_DEBUG |
| 25714 | 25714 | GLOBAL(int, mutexIsInit) = 1; |
| 25715 | 25715 | #endif |
| 25716 | 25716 | |
| 25717 | + sqlite3MemoryBarrier(); | |
| 25717 | 25718 | return rc; |
| 25718 | 25719 | } |
| 25719 | 25720 | |
| 25720 | 25721 | /* |
| 25721 | 25722 | ** Shutdown the mutex system. This call frees resources allocated by |
| @@ -30544,30 +30545,10 @@ | ||
| 30544 | 30545 | *zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); \ |
| 30545 | 30546 | *zOut++ = (u8)(c&0x00FF); \ |
| 30546 | 30547 | } \ |
| 30547 | 30548 | } |
| 30548 | 30549 | |
| 30549 | -#define READ_UTF16LE(zIn, TERM, c){ \ | |
| 30550 | - c = (*zIn++); \ | |
| 30551 | - c += ((*zIn++)<<8); \ | |
| 30552 | - if( c>=0xD800 && c<0xE000 && TERM ){ \ | |
| 30553 | - int c2 = (*zIn++); \ | |
| 30554 | - c2 += ((*zIn++)<<8); \ | |
| 30555 | - c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); \ | |
| 30556 | - } \ | |
| 30557 | -} | |
| 30558 | - | |
| 30559 | -#define READ_UTF16BE(zIn, TERM, c){ \ | |
| 30560 | - c = ((*zIn++)<<8); \ | |
| 30561 | - c += (*zIn++); \ | |
| 30562 | - if( c>=0xD800 && c<0xE000 && TERM ){ \ | |
| 30563 | - int c2 = ((*zIn++)<<8); \ | |
| 30564 | - c2 += (*zIn++); \ | |
| 30565 | - c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); \ | |
| 30566 | - } \ | |
| 30567 | -} | |
| 30568 | - | |
| 30569 | 30550 | /* |
| 30570 | 30551 | ** Translate a single UTF-8 character. Return the unicode value. |
| 30571 | 30552 | ** |
| 30572 | 30553 | ** During translation, assume that the byte that zTerm points |
| 30573 | 30554 | ** is a 0x00. |
| @@ -30740,17 +30721,47 @@ | ||
| 30740 | 30721 | }else{ |
| 30741 | 30722 | assert( desiredEnc==SQLITE_UTF8 ); |
| 30742 | 30723 | if( pMem->enc==SQLITE_UTF16LE ){ |
| 30743 | 30724 | /* UTF-16 Little-endian -> UTF-8 */ |
| 30744 | 30725 | while( zIn<zTerm ){ |
| 30745 | - READ_UTF16LE(zIn, zIn<zTerm, c); | |
| 30726 | + c = *(zIn++); | |
| 30727 | + c += (*(zIn++))<<8; | |
| 30728 | + if( c>=0xd800 && c<0xe000 ){ | |
| 30729 | + if( c>=0xdc00 || zIn>=zTerm ){ | |
| 30730 | + c = 0xfffd; | |
| 30731 | + }else{ | |
| 30732 | + int c2 = *(zIn++); | |
| 30733 | + c2 += (*(zIn++))<<8; | |
| 30734 | + if( c2<0xdc00 || c2>=0xe000 ){ | |
| 30735 | + zIn -= 2; | |
| 30736 | + c = 0xfffd; | |
| 30737 | + }else{ | |
| 30738 | + c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; | |
| 30739 | + } | |
| 30740 | + } | |
| 30741 | + } | |
| 30746 | 30742 | WRITE_UTF8(z, c); |
| 30747 | 30743 | } |
| 30748 | 30744 | }else{ |
| 30749 | 30745 | /* UTF-16 Big-endian -> UTF-8 */ |
| 30750 | 30746 | while( zIn<zTerm ){ |
| 30751 | - READ_UTF16BE(zIn, zIn<zTerm, c); | |
| 30747 | + c = (*(zIn++))<<8; | |
| 30748 | + c += *(zIn++); | |
| 30749 | + if( c>=0xd800 && c<0xe000 ){ | |
| 30750 | + if( c>=0xdc00 || zIn>=zTerm ){ | |
| 30751 | + c = 0xfffd; | |
| 30752 | + }else{ | |
| 30753 | + int c2 = (*(zIn++))<<8; | |
| 30754 | + c2 += *(zIn++); | |
| 30755 | + if( c2<0xdc00 || c2>=0xe000 ){ | |
| 30756 | + zIn -= 2; | |
| 30757 | + c = 0xfffd; | |
| 30758 | + }else{ | |
| 30759 | + c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; | |
| 30760 | + } | |
| 30761 | + } | |
| 30762 | + } | |
| 30752 | 30763 | WRITE_UTF8(z, c); |
| 30753 | 30764 | } |
| 30754 | 30765 | } |
| 30755 | 30766 | pMem->n = (int)(z - zOut); |
| 30756 | 30767 | } |
| @@ -30905,22 +30916,19 @@ | ||
| 30905 | 30916 | SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *zIn, int nChar){ |
| 30906 | 30917 | int c; |
| 30907 | 30918 | unsigned char const *z = zIn; |
| 30908 | 30919 | int n = 0; |
| 30909 | 30920 | |
| 30910 | - if( SQLITE_UTF16NATIVE==SQLITE_UTF16BE ){ | |
| 30911 | - while( n<nChar ){ | |
| 30912 | - READ_UTF16BE(z, 1, c); | |
| 30913 | - n++; | |
| 30914 | - } | |
| 30915 | - }else{ | |
| 30916 | - while( n<nChar ){ | |
| 30917 | - READ_UTF16LE(z, 1, c); | |
| 30918 | - n++; | |
| 30919 | - } | |
| 30920 | - } | |
| 30921 | - return (int)(z-(unsigned char const *)zIn); | |
| 30921 | + if( SQLITE_UTF16NATIVE==SQLITE_UTF16LE ) z++; | |
| 30922 | + while( n<nChar ){ | |
| 30923 | + c = z[0]; | |
| 30924 | + z += 2; | |
| 30925 | + if( c>=0xd8 && c<0xdc && z[0]>=0xdc && z[0]<0xe0 ) z += 2; | |
| 30926 | + n++; | |
| 30927 | + } | |
| 30928 | + return (int)(z-(unsigned char const *)zIn) | |
| 30929 | + - (SQLITE_UTF16NATIVE==SQLITE_UTF16LE); | |
| 30922 | 30930 | } |
| 30923 | 30931 | |
| 30924 | 30932 | #if defined(SQLITE_TEST) |
| 30925 | 30933 | /* |
| 30926 | 30934 | ** This routine is called from the TCL test function "translate_selftest". |
| @@ -30944,34 +30952,10 @@ | ||
| 30944 | 30952 | c = sqlite3Utf8Read((const u8**)&z); |
| 30945 | 30953 | t = i; |
| 30946 | 30954 | if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD; |
| 30947 | 30955 | if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD; |
| 30948 | 30956 | assert( c==t ); |
| 30949 | - assert( (z-zBuf)==n ); | |
| 30950 | - } | |
| 30951 | - for(i=0; i<0x00110000; i++){ | |
| 30952 | - if( i>=0xD800 && i<0xE000 ) continue; | |
| 30953 | - z = zBuf; | |
| 30954 | - WRITE_UTF16LE(z, i); | |
| 30955 | - n = (int)(z-zBuf); | |
| 30956 | - assert( n>0 && n<=4 ); | |
| 30957 | - z[0] = 0; | |
| 30958 | - z = zBuf; | |
| 30959 | - READ_UTF16LE(z, 1, c); | |
| 30960 | - assert( c==i ); | |
| 30961 | - assert( (z-zBuf)==n ); | |
| 30962 | - } | |
| 30963 | - for(i=0; i<0x00110000; i++){ | |
| 30964 | - if( i>=0xD800 && i<0xE000 ) continue; | |
| 30965 | - z = zBuf; | |
| 30966 | - WRITE_UTF16BE(z, i); | |
| 30967 | - n = (int)(z-zBuf); | |
| 30968 | - assert( n>0 && n<=4 ); | |
| 30969 | - z[0] = 0; | |
| 30970 | - z = zBuf; | |
| 30971 | - READ_UTF16BE(z, 1, c); | |
| 30972 | - assert( c==i ); | |
| 30973 | 30957 | assert( (z-zBuf)==n ); |
| 30974 | 30958 | } |
| 30975 | 30959 | } |
| 30976 | 30960 | #endif /* SQLITE_TEST */ |
| 30977 | 30961 | #endif /* SQLITE_OMIT_UTF16 */ |
| @@ -32234,11 +32218,11 @@ | ||
| 32234 | 32218 | h += 9*(1&~(h>>4)); |
| 32235 | 32219 | #endif |
| 32236 | 32220 | return (u8)(h & 0xf); |
| 32237 | 32221 | } |
| 32238 | 32222 | |
| 32239 | -#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) | |
| 32223 | +#if !defined(SQLITE_OMIT_BLOB_LITERAL) | |
| 32240 | 32224 | /* |
| 32241 | 32225 | ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary |
| 32242 | 32226 | ** value. Return a pointer to its binary value. Space to hold the |
| 32243 | 32227 | ** binary value has been obtained from malloc and must be freed by |
| 32244 | 32228 | ** the calling routine. |
| @@ -32255,11 +32239,11 @@ | ||
| 32255 | 32239 | } |
| 32256 | 32240 | zBlob[i/2] = 0; |
| 32257 | 32241 | } |
| 32258 | 32242 | return zBlob; |
| 32259 | 32243 | } |
| 32260 | -#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC */ | |
| 32244 | +#endif /* !SQLITE_OMIT_BLOB_LITERAL */ | |
| 32261 | 32245 | |
| 32262 | 32246 | /* |
| 32263 | 32247 | ** Log an error that is an API call on a connection pointer that should |
| 32264 | 32248 | ** not have been used. The "type" of connection pointer is given as the |
| 32265 | 32249 | ** argument. The zType is a word like "NULL" or "closed" or "invalid". |
| @@ -32966,12 +32950,12 @@ | ||
| 32966 | 32950 | /* 58 */ "ElseNotEq" OpHelp(""), |
| 32967 | 32951 | /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 32968 | 32952 | /* 60 */ "IncrVacuum" OpHelp(""), |
| 32969 | 32953 | /* 61 */ "VNext" OpHelp(""), |
| 32970 | 32954 | /* 62 */ "Init" OpHelp("Start at P2"), |
| 32971 | - /* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@P5])"), | |
| 32972 | - /* 64 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), | |
| 32955 | + /* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"), | |
| 32956 | + /* 64 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"), | |
| 32973 | 32957 | /* 65 */ "Return" OpHelp(""), |
| 32974 | 32958 | /* 66 */ "EndCoroutine" OpHelp(""), |
| 32975 | 32959 | /* 67 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 32976 | 32960 | /* 68 */ "Halt" OpHelp(""), |
| 32977 | 32961 | /* 69 */ "Integer" OpHelp("r[P2]=P1"), |
| @@ -33033,12 +33017,12 @@ | ||
| 33033 | 33017 | /* 125 */ "SorterData" OpHelp("r[P2]=data"), |
| 33034 | 33018 | /* 126 */ "RowData" OpHelp("r[P2]=data"), |
| 33035 | 33019 | /* 127 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 33036 | 33020 | /* 128 */ "NullRow" OpHelp(""), |
| 33037 | 33021 | /* 129 */ "SeekEnd" OpHelp(""), |
| 33038 | - /* 130 */ "SorterInsert" OpHelp("key=r[P2]"), | |
| 33039 | - /* 131 */ "IdxInsert" OpHelp("key=r[P2]"), | |
| 33022 | + /* 130 */ "IdxInsert" OpHelp("key=r[P2]"), | |
| 33023 | + /* 131 */ "SorterInsert" OpHelp("key=r[P2]"), | |
| 33040 | 33024 | /* 132 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 33041 | 33025 | /* 133 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 33042 | 33026 | /* 134 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 33043 | 33027 | /* 135 */ "FinishSeek" OpHelp(""), |
| 33044 | 33028 | /* 136 */ "Destroy" OpHelp(""), |
| @@ -33975,11 +33959,11 @@ | ||
| 33975 | 33959 | if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break; |
| 33976 | 33960 | osClose(fd); |
| 33977 | 33961 | sqlite3_log(SQLITE_WARNING, |
| 33978 | 33962 | "attempt to open \"%s\" as file descriptor %d", z, fd); |
| 33979 | 33963 | fd = -1; |
| 33980 | - if( osOpen("/dev/null", f, m)<0 ) break; | |
| 33964 | + if( osOpen("/dev/null", O_RDONLY, m)<0 ) break; | |
| 33981 | 33965 | } |
| 33982 | 33966 | if( fd>=0 ){ |
| 33983 | 33967 | if( m!=0 ){ |
| 33984 | 33968 | struct stat statbuf; |
| 33985 | 33969 | if( osFstat(fd, &statbuf)==0 |
| @@ -51799,24 +51783,10 @@ | ||
| 51799 | 51783 | ** Pager.eLock may only be set to UNKNOWN_LOCK when the pager is in |
| 51800 | 51784 | ** PAGER_OPEN state. |
| 51801 | 51785 | */ |
| 51802 | 51786 | #define UNKNOWN_LOCK (EXCLUSIVE_LOCK+1) |
| 51803 | 51787 | |
| 51804 | -/* | |
| 51805 | -** A macro used for invoking the codec if there is one | |
| 51806 | -*/ | |
| 51807 | -#ifdef SQLITE_HAS_CODEC | |
| 51808 | -# define CODEC1(P,D,N,X,E) \ | |
| 51809 | - if( P->xCodec && P->xCodec(P->pCodec,D,N,X)==0 ){ E; } | |
| 51810 | -# define CODEC2(P,D,N,X,E,O) \ | |
| 51811 | - if( P->xCodec==0 ){ O=(char*)D; }else \ | |
| 51812 | - if( (O=(char*)(P->xCodec(P->pCodec,D,N,X)))==0 ){ E; } | |
| 51813 | -#else | |
| 51814 | -# define CODEC1(P,D,N,X,E) /* NO-OP */ | |
| 51815 | -# define CODEC2(P,D,N,X,E,O) O=(char*)D | |
| 51816 | -#endif | |
| 51817 | - | |
| 51818 | 51788 | /* |
| 51819 | 51789 | ** The maximum allowed sector size. 64KiB. If the xSectorsize() method |
| 51820 | 51790 | ** returns a value larger than this, then MAX_SECTOR_SIZE is used instead. |
| 51821 | 51791 | ** This could conceivably cause corruption following a power failure on |
| 51822 | 51792 | ** such a system. This is currently an undocumented limit. |
| @@ -52098,16 +52068,10 @@ | ||
| 52098 | 52068 | #ifdef SQLITE_TEST |
| 52099 | 52069 | int nRead; /* Database pages read */ |
| 52100 | 52070 | #endif |
| 52101 | 52071 | void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */ |
| 52102 | 52072 | int (*xGet)(Pager*,Pgno,DbPage**,int); /* Routine to fetch a patch */ |
| 52103 | -#ifdef SQLITE_HAS_CODEC | |
| 52104 | - void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */ | |
| 52105 | - void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */ | |
| 52106 | - void (*xCodecFree)(void*); /* Destructor for the codec */ | |
| 52107 | - void *pCodec; /* First argument to xCodec... methods */ | |
| 52108 | -#endif | |
| 52109 | 52073 | char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */ |
| 52110 | 52074 | PCache *pPCache; /* Pointer to page cache object */ |
| 52111 | 52075 | #ifndef SQLITE_OMIT_WAL |
| 52112 | 52076 | Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */ |
| 52113 | 52077 | char *zWal; /* File name for write-ahead log */ |
| @@ -52230,13 +52194,10 @@ | ||
| 52230 | 52194 | ** * the desired page is not currently in the wal file. |
| 52231 | 52195 | */ |
| 52232 | 52196 | SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){ |
| 52233 | 52197 | if( pPager->fd->pMethods==0 ) return 0; |
| 52234 | 52198 | if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0; |
| 52235 | -#ifdef SQLITE_HAS_CODEC | |
| 52236 | - if( pPager->xCodec!=0 ) return 0; | |
| 52237 | -#endif | |
| 52238 | 52199 | #ifndef SQLITE_OMIT_WAL |
| 52239 | 52200 | if( pPager->pWal ){ |
| 52240 | 52201 | u32 iRead = 0; |
| 52241 | 52202 | int rc; |
| 52242 | 52203 | rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead); |
| @@ -52466,15 +52427,11 @@ | ||
| 52466 | 52427 | */ |
| 52467 | 52428 | static void setGetterMethod(Pager *pPager){ |
| 52468 | 52429 | if( pPager->errCode ){ |
| 52469 | 52430 | pPager->xGet = getPageError; |
| 52470 | 52431 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 52471 | - }else if( USEFETCH(pPager) | |
| 52472 | -#ifdef SQLITE_HAS_CODEC | |
| 52473 | - && pPager->xCodec==0 | |
| 52474 | -#endif | |
| 52475 | - ){ | |
| 52432 | + }else if( USEFETCH(pPager) ){ | |
| 52476 | 52433 | pPager->xGet = getPageMMap; |
| 52477 | 52434 | #endif /* SQLITE_MAX_MMAP_SIZE>0 */ |
| 52478 | 52435 | }else{ |
| 52479 | 52436 | pPager->xGet = getPageNormal; |
| 52480 | 52437 | } |
| @@ -53618,39 +53575,10 @@ | ||
| 53618 | 53575 | i -= 200; |
| 53619 | 53576 | } |
| 53620 | 53577 | return cksum; |
| 53621 | 53578 | } |
| 53622 | 53579 | |
| 53623 | -/* | |
| 53624 | -** Report the current page size and number of reserved bytes back | |
| 53625 | -** to the codec. | |
| 53626 | -*/ | |
| 53627 | -#ifdef SQLITE_HAS_CODEC | |
| 53628 | -static void pagerReportSize(Pager *pPager){ | |
| 53629 | - if( pPager->xCodecSizeChng ){ | |
| 53630 | - pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize, | |
| 53631 | - (int)pPager->nReserve); | |
| 53632 | - } | |
| 53633 | -} | |
| 53634 | -#else | |
| 53635 | -# define pagerReportSize(X) /* No-op if we do not support a codec */ | |
| 53636 | -#endif | |
| 53637 | - | |
| 53638 | -#ifdef SQLITE_HAS_CODEC | |
| 53639 | -/* | |
| 53640 | -** Make sure the number of reserved bits is the same in the destination | |
| 53641 | -** pager as it is in the source. This comes up when a VACUUM changes the | |
| 53642 | -** number of reserved bits to the "optimal" amount. | |
| 53643 | -*/ | |
| 53644 | -SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager *pDest, Pager *pSrc){ | |
| 53645 | - if( pDest->nReserve!=pSrc->nReserve ){ | |
| 53646 | - pDest->nReserve = pSrc->nReserve; | |
| 53647 | - pagerReportSize(pDest); | |
| 53648 | - } | |
| 53649 | -} | |
| 53650 | -#endif | |
| 53651 | - | |
| 53652 | 53580 | /* |
| 53653 | 53581 | ** Read a single page from either the journal file (if isMainJrnl==1) or |
| 53654 | 53582 | ** from the sub-journal (if isMainJrnl==0) and playback that page. |
| 53655 | 53583 | ** The page begins at offset *pOffset into the file. The *pOffset |
| 53656 | 53584 | ** value is increased to the start of the next page in the journal. |
| @@ -53698,15 +53626,10 @@ | ||
| 53698 | 53626 | Pgno pgno; /* The page number of a page in journal */ |
| 53699 | 53627 | u32 cksum; /* Checksum used for sanity checking */ |
| 53700 | 53628 | char *aData; /* Temporary storage for the page */ |
| 53701 | 53629 | sqlite3_file *jfd; /* The file descriptor for the journal file */ |
| 53702 | 53630 | int isSynced; /* True if journal page is synced */ |
| 53703 | -#ifdef SQLITE_HAS_CODEC | |
| 53704 | - /* The jrnlEnc flag is true if Journal pages should be passed through | |
| 53705 | - ** the codec. It is false for pure in-memory journals. */ | |
| 53706 | - const int jrnlEnc = (isMainJrnl || pPager->subjInMemory==0); | |
| 53707 | -#endif | |
| 53708 | 53631 | |
| 53709 | 53632 | assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */ |
| 53710 | 53633 | assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */ |
| 53711 | 53634 | assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */ |
| 53712 | 53635 | assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */ |
| @@ -53765,11 +53688,10 @@ | ||
| 53765 | 53688 | |
| 53766 | 53689 | /* When playing back page 1, restore the nReserve setting |
| 53767 | 53690 | */ |
| 53768 | 53691 | if( pgno==1 && pPager->nReserve!=((u8*)aData)[20] ){ |
| 53769 | 53692 | pPager->nReserve = ((u8*)aData)[20]; |
| 53770 | - pagerReportSize(pPager); | |
| 53771 | 53693 | } |
| 53772 | 53694 | |
| 53773 | 53695 | /* If the pager is in CACHEMOD state, then there must be a copy of this |
| 53774 | 53696 | ** page in the pager cache. In this case just update the pager cache, |
| 53775 | 53697 | ** not the database file. The page is left marked dirty in this case. |
| @@ -53833,30 +53755,16 @@ | ||
| 53833 | 53755 | ** This is usually safe even for an encrypted database - as the data |
| 53834 | 53756 | ** was encrypted before it was written to the journal file. The exception |
| 53835 | 53757 | ** is if the data was just read from an in-memory sub-journal. In that |
| 53836 | 53758 | ** case it must be encrypted here before it is copied into the database |
| 53837 | 53759 | ** file. */ |
| 53838 | -#ifdef SQLITE_HAS_CODEC | |
| 53839 | - if( !jrnlEnc ){ | |
| 53840 | - CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData); | |
| 53841 | - rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst); | |
| 53842 | - CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT); | |
| 53843 | - }else | |
| 53844 | -#endif | |
| 53845 | 53760 | rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst); |
| 53846 | 53761 | |
| 53847 | 53762 | if( pgno>pPager->dbFileSize ){ |
| 53848 | 53763 | pPager->dbFileSize = pgno; |
| 53849 | 53764 | } |
| 53850 | 53765 | if( pPager->pBackup ){ |
| 53851 | -#ifdef SQLITE_HAS_CODEC | |
| 53852 | - if( jrnlEnc ){ | |
| 53853 | - CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT); | |
| 53854 | - sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData); | |
| 53855 | - CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT,aData); | |
| 53856 | - }else | |
| 53857 | -#endif | |
| 53858 | 53766 | sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData); |
| 53859 | 53767 | } |
| 53860 | 53768 | }else if( !isMainJrnl && pPg==0 ){ |
| 53861 | 53769 | /* If this is a rollback of a savepoint and data was not written to |
| 53862 | 53770 | ** the database and the page is not in-memory, there is a potential |
| @@ -53903,15 +53811,10 @@ | ||
| 53903 | 53811 | /* If this was page 1, then restore the value of Pager.dbFileVers. |
| 53904 | 53812 | ** Do this before any decoding. */ |
| 53905 | 53813 | if( pgno==1 ){ |
| 53906 | 53814 | memcpy(&pPager->dbFileVers, &((u8*)pData)[24],sizeof(pPager->dbFileVers)); |
| 53907 | 53815 | } |
| 53908 | - | |
| 53909 | - /* Decode the page just read from disk */ | |
| 53910 | -#if SQLITE_HAS_CODEC | |
| 53911 | - if( jrnlEnc ){ CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT); } | |
| 53912 | -#endif | |
| 53913 | 53816 | sqlite3PcacheRelease(pPg); |
| 53914 | 53817 | } |
| 53915 | 53818 | return rc; |
| 53916 | 53819 | } |
| 53917 | 53820 | |
| @@ -54467,12 +54370,10 @@ | ||
| 54467 | 54370 | }else{ |
| 54468 | 54371 | u8 *dbFileVers = &((u8*)pPg->pData)[24]; |
| 54469 | 54372 | memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers)); |
| 54470 | 54373 | } |
| 54471 | 54374 | } |
| 54472 | - CODEC1(pPager, pPg->pData, pPg->pgno, 3, rc = SQLITE_NOMEM_BKPT); | |
| 54473 | - | |
| 54474 | 54375 | PAGER_INCR(sqlite3_pager_readdb_count); |
| 54475 | 54376 | PAGER_INCR(pPager->nRead); |
| 54476 | 54377 | IOTRACE(("PGIN %p %d\n", pPager, pPg->pgno)); |
| 54477 | 54378 | PAGERTRACE(("FETCH %d page %d hash(%08x)\n", |
| 54478 | 54379 | PAGERID(pPager), pPg->pgno, pager_pagehash(pPg))); |
| @@ -55212,11 +55113,10 @@ | ||
| 55212 | 55113 | *pPageSize = pPager->pageSize; |
| 55213 | 55114 | if( rc==SQLITE_OK ){ |
| 55214 | 55115 | if( nReserve<0 ) nReserve = pPager->nReserve; |
| 55215 | 55116 | assert( nReserve>=0 && nReserve<1000 ); |
| 55216 | 55117 | pPager->nReserve = (i16)nReserve; |
| 55217 | - pagerReportSize(pPager); | |
| 55218 | 55118 | pagerFixMaplimit(pPager); |
| 55219 | 55119 | } |
| 55220 | 55120 | return rc; |
| 55221 | 55121 | } |
| 55222 | 55122 | |
| @@ -55608,15 +55508,10 @@ | ||
| 55608 | 55508 | IOTRACE(("CLOSE %p\n", pPager)) |
| 55609 | 55509 | sqlite3OsClose(pPager->jfd); |
| 55610 | 55510 | sqlite3OsClose(pPager->fd); |
| 55611 | 55511 | sqlite3PageFree(pTmp); |
| 55612 | 55512 | sqlite3PcacheClose(pPager->pPCache); |
| 55613 | - | |
| 55614 | -#ifdef SQLITE_HAS_CODEC | |
| 55615 | - if( pPager->xCodecFree ) pPager->xCodecFree(pPager->pCodec); | |
| 55616 | -#endif | |
| 55617 | - | |
| 55618 | 55513 | assert( !pPager->aSavepoint && !pPager->pInJournal ); |
| 55619 | 55514 | assert( !isOpen(pPager->jfd) && !isOpen(pPager->sjfd) ); |
| 55620 | 55515 | |
| 55621 | 55516 | sqlite3_free(pPager); |
| 55622 | 55517 | return SQLITE_OK; |
| @@ -55863,12 +55758,11 @@ | ||
| 55863 | 55758 | char *pData; /* Data to write */ |
| 55864 | 55759 | |
| 55865 | 55760 | assert( (pList->flags&PGHDR_NEED_SYNC)==0 ); |
| 55866 | 55761 | if( pList->pgno==1 ) pager_write_changecounter(pList); |
| 55867 | 55762 | |
| 55868 | - /* Encode the database */ | |
| 55869 | - CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM_BKPT, pData); | |
| 55763 | + pData = pList->pData; | |
| 55870 | 55764 | |
| 55871 | 55765 | /* Write out the page data. */ |
| 55872 | 55766 | rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset); |
| 55873 | 55767 | |
| 55874 | 55768 | /* If page 1 was just written, update Pager.dbFileVers to match |
| @@ -55953,16 +55847,10 @@ | ||
| 55953 | 55847 | ** write the journal record into the file. */ |
| 55954 | 55848 | if( rc==SQLITE_OK ){ |
| 55955 | 55849 | void *pData = pPg->pData; |
| 55956 | 55850 | i64 offset = (i64)pPager->nSubRec*(4+pPager->pageSize); |
| 55957 | 55851 | char *pData2; |
| 55958 | - | |
| 55959 | -#if SQLITE_HAS_CODEC | |
| 55960 | - if( !pPager->subjInMemory ){ | |
| 55961 | - CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2); | |
| 55962 | - }else | |
| 55963 | -#endif | |
| 55964 | 55852 | pData2 = pData; |
| 55965 | 55853 | PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno)); |
| 55966 | 55854 | rc = write32bits(pPager->sjfd, offset, pPg->pgno); |
| 55967 | 55855 | if( rc==SQLITE_OK ){ |
| 55968 | 55856 | rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4); |
| @@ -56259,10 +56147,15 @@ | ||
| 56259 | 56147 | ** - \0 |
| 56260 | 56148 | ** - Journal Path |
| 56261 | 56149 | ** - \0 |
| 56262 | 56150 | ** - WAL Path (zWALName) |
| 56263 | 56151 | ** - \0 |
| 56152 | + ** | |
| 56153 | + ** The sqlite3_create_filename() interface and the databaseFilename() utility | |
| 56154 | + ** that is used by sqlite3_filename_database() and kin also depend on the | |
| 56155 | + ** specific formatting and order of the various filenames, so if the format | |
| 56156 | + ** changes here, be sure to change it there as well. | |
| 56264 | 56157 | */ |
| 56265 | 56158 | pPtr = (u8 *)sqlite3MallocZero( |
| 56266 | 56159 | ROUND8(sizeof(*pPager)) + /* Pager structure */ |
| 56267 | 56160 | ROUND8(pcacheSize) + /* PCache object */ |
| 56268 | 56161 | ROUND8(pVfs->szOsFile) + /* The main db file */ |
| @@ -57040,13 +56933,10 @@ | ||
| 57040 | 56933 | const int bMmapOk = (pgno>1 |
| 57041 | 56934 | && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY)) |
| 57042 | 56935 | ); |
| 57043 | 56936 | |
| 57044 | 56937 | assert( USEFETCH(pPager) ); |
| 57045 | -#ifdef SQLITE_HAS_CODEC | |
| 57046 | - assert( pPager->xCodec==0 ); | |
| 57047 | -#endif | |
| 57048 | 56938 | |
| 57049 | 56939 | /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here |
| 57050 | 56940 | ** allows the compiler optimizer to reuse the results of the "pgno>1" |
| 57051 | 56941 | ** test in the previous statement, and avoid testing pgno==0 in the |
| 57052 | 56942 | ** common case where pgno is large. */ |
| @@ -57371,11 +57261,11 @@ | ||
| 57371 | 57261 | ** contains the database locks. The following assert verifies |
| 57372 | 57262 | ** that we do not. */ |
| 57373 | 57263 | assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); |
| 57374 | 57264 | |
| 57375 | 57265 | assert( pPager->journalHdr<=pPager->journalOff ); |
| 57376 | - CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2); | |
| 57266 | + pData2 = pPg->pData; | |
| 57377 | 57267 | cksum = pager_cksum(pPager, (u8*)pData2); |
| 57378 | 57268 | |
| 57379 | 57269 | /* Even if an IO or diskfull error occurs while journalling the |
| 57380 | 57270 | ** page in the block above, set the need-sync flag for the page. |
| 57381 | 57271 | ** Otherwise, when the transaction is rolled back, the logic in |
| @@ -57736,11 +57626,11 @@ | ||
| 57736 | 57626 | |
| 57737 | 57627 | /* If running in direct mode, write the contents of page 1 to the file. */ |
| 57738 | 57628 | if( DIRECT_MODE ){ |
| 57739 | 57629 | const void *zBuf; |
| 57740 | 57630 | assert( pPager->dbFileSize>0 ); |
| 57741 | - CODEC2(pPager, pPgHdr->pData, 1, 6, rc=SQLITE_NOMEM_BKPT, zBuf); | |
| 57631 | + zBuf = pPgHdr->pData; | |
| 57742 | 57632 | if( rc==SQLITE_OK ){ |
| 57743 | 57633 | rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0); |
| 57744 | 57634 | pPager->aStat[PAGER_STAT_WRITE]++; |
| 57745 | 57635 | } |
| 57746 | 57636 | if( rc==SQLITE_OK ){ |
| @@ -58446,11 +58336,11 @@ | ||
| 58446 | 58336 | ** |
| 58447 | 58337 | ** The return value to this routine is always safe to use with |
| 58448 | 58338 | ** sqlite3_uri_parameter() and sqlite3_filename_database() and friends. |
| 58449 | 58339 | */ |
| 58450 | 58340 | SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager *pPager, int nullIfMemDb){ |
| 58451 | - static const char zFake[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; | |
| 58341 | + static const char zFake[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; | |
| 58452 | 58342 | return (nullIfMemDb && pPager->memDb) ? &zFake[4] : pPager->zFilename; |
| 58453 | 58343 | } |
| 58454 | 58344 | |
| 58455 | 58345 | /* |
| 58456 | 58346 | ** Return the VFS structure for the pager. |
| @@ -58495,58 +58385,10 @@ | ||
| 58495 | 58385 | */ |
| 58496 | 58386 | SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager *pPager){ |
| 58497 | 58387 | return pPager->zJournal; |
| 58498 | 58388 | } |
| 58499 | 58389 | |
| 58500 | -#ifdef SQLITE_HAS_CODEC | |
| 58501 | -/* | |
| 58502 | -** Set or retrieve the codec for this pager | |
| 58503 | -*/ | |
| 58504 | -SQLITE_PRIVATE void sqlite3PagerSetCodec( | |
| 58505 | - Pager *pPager, | |
| 58506 | - void *(*xCodec)(void*,void*,Pgno,int), | |
| 58507 | - void (*xCodecSizeChng)(void*,int,int), | |
| 58508 | - void (*xCodecFree)(void*), | |
| 58509 | - void *pCodec | |
| 58510 | -){ | |
| 58511 | - if( pPager->xCodecFree ){ | |
| 58512 | - pPager->xCodecFree(pPager->pCodec); | |
| 58513 | - }else{ | |
| 58514 | - pager_reset(pPager); | |
| 58515 | - } | |
| 58516 | - pPager->xCodec = pPager->memDb ? 0 : xCodec; | |
| 58517 | - pPager->xCodecSizeChng = xCodecSizeChng; | |
| 58518 | - pPager->xCodecFree = xCodecFree; | |
| 58519 | - pPager->pCodec = pCodec; | |
| 58520 | - setGetterMethod(pPager); | |
| 58521 | - pagerReportSize(pPager); | |
| 58522 | -} | |
| 58523 | -SQLITE_PRIVATE void *sqlite3PagerGetCodec(Pager *pPager){ | |
| 58524 | - return pPager->pCodec; | |
| 58525 | -} | |
| 58526 | - | |
| 58527 | -/* | |
| 58528 | -** This function is called by the wal module when writing page content | |
| 58529 | -** into the log file. | |
| 58530 | -** | |
| 58531 | -** This function returns a pointer to a buffer containing the encrypted | |
| 58532 | -** page content. If a malloc fails, this function may return NULL. | |
| 58533 | -*/ | |
| 58534 | -SQLITE_PRIVATE void *sqlite3PagerCodec(PgHdr *pPg){ | |
| 58535 | - void *aData = 0; | |
| 58536 | - CODEC2(pPg->pPager, pPg->pData, pPg->pgno, 6, return 0, aData); | |
| 58537 | - return aData; | |
| 58538 | -} | |
| 58539 | - | |
| 58540 | -/* | |
| 58541 | -** Return the current pager state | |
| 58542 | -*/ | |
| 58543 | -SQLITE_PRIVATE int sqlite3PagerState(Pager *pPager){ | |
| 58544 | - return pPager->eState; | |
| 58545 | -} | |
| 58546 | -#endif /* SQLITE_HAS_CODEC */ | |
| 58547 | - | |
| 58548 | 58390 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 58549 | 58391 | /* |
| 58550 | 58392 | ** Move the page pPg to location pgno in the file. |
| 58551 | 58393 | ** |
| 58552 | 58394 | ** There must be no references to the page previously located at |
| @@ -62453,15 +62295,11 @@ | ||
| 62453 | 62295 | sqlite3_int64 iOffset /* Byte offset at which to write */ |
| 62454 | 62296 | ){ |
| 62455 | 62297 | int rc; /* Result code from subfunctions */ |
| 62456 | 62298 | void *pData; /* Data actually written */ |
| 62457 | 62299 | u8 aFrame[WAL_FRAME_HDRSIZE]; /* Buffer to assemble frame-header in */ |
| 62458 | -#if defined(SQLITE_HAS_CODEC) | |
| 62459 | - if( (pData = sqlite3PagerCodec(pPage))==0 ) return SQLITE_NOMEM_BKPT; | |
| 62460 | -#else | |
| 62461 | 62300 | pData = pPage->pData; |
| 62462 | -#endif | |
| 62463 | 62301 | walEncodeFrame(p->pWal, pPage->pgno, nTruncate, pData, aFrame); |
| 62464 | 62302 | rc = walWriteToLog(p, aFrame, sizeof(aFrame), iOffset); |
| 62465 | 62303 | if( rc ) return rc; |
| 62466 | 62304 | /* Write the page data */ |
| 62467 | 62305 | rc = walWriteToLog(p, pData, p->szPage, iOffset+sizeof(aFrame)); |
| @@ -62640,15 +62478,11 @@ | ||
| 62640 | 62478 | i64 iOff = walFrameOffset(iWrite, szPage) + WAL_FRAME_HDRSIZE; |
| 62641 | 62479 | void *pData; |
| 62642 | 62480 | if( pWal->iReCksum==0 || iWrite<pWal->iReCksum ){ |
| 62643 | 62481 | pWal->iReCksum = iWrite; |
| 62644 | 62482 | } |
| 62645 | -#if defined(SQLITE_HAS_CODEC) | |
| 62646 | - if( (pData = sqlite3PagerCodec(p))==0 ) return SQLITE_NOMEM; | |
| 62647 | -#else | |
| 62648 | 62483 | pData = p->pData; |
| 62649 | -#endif | |
| 62650 | 62484 | rc = sqlite3OsWrite(pWal->pWalFd, pData, szPage, iOff); |
| 62651 | 62485 | if( rc ) return rc; |
| 62652 | 62486 | p->flags &= ~PGHDR_WAL_APPEND; |
| 62653 | 62487 | continue; |
| 62654 | 62488 | } |
| @@ -63502,13 +63336,10 @@ | ||
| 63502 | 63336 | u8 incrVacuum; /* True if incr-vacuum is enabled */ |
| 63503 | 63337 | u8 bDoTruncate; /* True to truncate db on commit */ |
| 63504 | 63338 | #endif |
| 63505 | 63339 | u8 inTransaction; /* Transaction state */ |
| 63506 | 63340 | u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */ |
| 63507 | -#ifdef SQLITE_HAS_CODEC | |
| 63508 | - u8 optimalReserve; /* Desired amount of reserved space per page */ | |
| 63509 | -#endif | |
| 63510 | 63341 | u16 btsFlags; /* Boolean parameters. See BTS_* macros below */ |
| 63511 | 63342 | u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */ |
| 63512 | 63343 | u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */ |
| 63513 | 63344 | u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */ |
| 63514 | 63345 | u16 minLeaf; /* Minimum local payload in a LEAFDATA table */ |
| @@ -65543,11 +65374,11 @@ | ||
| 65543 | 65374 | u8 *pEnd = &data[cellOffset + nCell*2]; |
| 65544 | 65375 | u8 *pAddr; |
| 65545 | 65376 | int sz2 = 0; |
| 65546 | 65377 | int sz = get2byte(&data[iFree+2]); |
| 65547 | 65378 | int top = get2byte(&data[hdr+5]); |
| 65548 | - if( NEVER(top>=iFree) ){ | |
| 65379 | + if( top>=iFree ){ | |
| 65549 | 65380 | return SQLITE_CORRUPT_PAGE(pPage); |
| 65550 | 65381 | } |
| 65551 | 65382 | if( iFree2 ){ |
| 65552 | 65383 | if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65553 | 65384 | sz2 = get2byte(&data[iFree2+2]); |
| @@ -65874,11 +65705,11 @@ | ||
| 65874 | 65705 | if( iStart<=x ){ |
| 65875 | 65706 | /* The new freeblock is at the beginning of the cell content area, |
| 65876 | 65707 | ** so just extend the cell content area rather than create another |
| 65877 | 65708 | ** freelist entry */ |
| 65878 | 65709 | if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65879 | - if( NEVER(iPtr!=hdr+1) ) return SQLITE_CORRUPT_PAGE(pPage); | |
| 65710 | + if( iPtr!=hdr+1 ) return SQLITE_CORRUPT_PAGE(pPage); | |
| 65880 | 65711 | put2byte(&data[hdr+1], iFreeBlk); |
| 65881 | 65712 | put2byte(&data[hdr+5], iEnd); |
| 65882 | 65713 | }else{ |
| 65883 | 65714 | /* Insert the new freeblock into the freelist */ |
| 65884 | 65715 | put2byte(&data[iPtr], iStart); |
| @@ -66953,13 +66784,10 @@ | ||
| 66953 | 66784 | SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){ |
| 66954 | 66785 | int rc = SQLITE_OK; |
| 66955 | 66786 | BtShared *pBt = p->pBt; |
| 66956 | 66787 | assert( nReserve>=-1 && nReserve<=255 ); |
| 66957 | 66788 | sqlite3BtreeEnter(p); |
| 66958 | -#if SQLITE_HAS_CODEC | |
| 66959 | - if( nReserve>pBt->optimalReserve ) pBt->optimalReserve = (u8)nReserve; | |
| 66960 | -#endif | |
| 66961 | 66789 | if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){ |
| 66962 | 66790 | sqlite3BtreeLeave(p); |
| 66963 | 66791 | return SQLITE_READONLY; |
| 66964 | 66792 | } |
| 66965 | 66793 | if( nReserve<0 ){ |
| @@ -67016,13 +66844,10 @@ | ||
| 67016 | 66844 | */ |
| 67017 | 66845 | SQLITE_PRIVATE int sqlite3BtreeGetOptimalReserve(Btree *p){ |
| 67018 | 66846 | int n; |
| 67019 | 66847 | sqlite3BtreeEnter(p); |
| 67020 | 66848 | n = sqlite3BtreeGetReserveNoMutex(p); |
| 67021 | -#ifdef SQLITE_HAS_CODEC | |
| 67022 | - if( n<p->pBt->optimalReserve ) n = p->pBt->optimalReserve; | |
| 67023 | -#endif | |
| 67024 | 66849 | sqlite3BtreeLeave(p); |
| 67025 | 66850 | return n; |
| 67026 | 66851 | } |
| 67027 | 66852 | |
| 67028 | 66853 | |
| @@ -74855,17 +74680,10 @@ | ||
| 74855 | 74680 | Pager * const pDestPager = sqlite3BtreePager(p->pDest); |
| 74856 | 74681 | const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc); |
| 74857 | 74682 | int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest); |
| 74858 | 74683 | const int nCopy = MIN(nSrcPgsz, nDestPgsz); |
| 74859 | 74684 | const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz; |
| 74860 | -#ifdef SQLITE_HAS_CODEC | |
| 74861 | - /* Use BtreeGetReserveNoMutex() for the source b-tree, as although it is | |
| 74862 | - ** guaranteed that the shared-mutex is held by this thread, handle | |
| 74863 | - ** p->pSrc may not actually be the owner. */ | |
| 74864 | - int nSrcReserve = sqlite3BtreeGetReserveNoMutex(p->pSrc); | |
| 74865 | - int nDestReserve = sqlite3BtreeGetOptimalReserve(p->pDest); | |
| 74866 | -#endif | |
| 74867 | 74685 | int rc = SQLITE_OK; |
| 74868 | 74686 | i64 iOff; |
| 74869 | 74687 | |
| 74870 | 74688 | assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 ); |
| 74871 | 74689 | assert( p->bDestLocked ); |
| @@ -74878,30 +74696,10 @@ | ||
| 74878 | 74696 | */ |
| 74879 | 74697 | if( nSrcPgsz!=nDestPgsz && sqlite3PagerIsMemdb(pDestPager) ){ |
| 74880 | 74698 | rc = SQLITE_READONLY; |
| 74881 | 74699 | } |
| 74882 | 74700 | |
| 74883 | -#ifdef SQLITE_HAS_CODEC | |
| 74884 | - /* Backup is not possible if the page size of the destination is changing | |
| 74885 | - ** and a codec is in use. | |
| 74886 | - */ | |
| 74887 | - if( nSrcPgsz!=nDestPgsz && sqlite3PagerGetCodec(pDestPager)!=0 ){ | |
| 74888 | - rc = SQLITE_READONLY; | |
| 74889 | - } | |
| 74890 | - | |
| 74891 | - /* Backup is not possible if the number of bytes of reserve space differ | |
| 74892 | - ** between source and destination. If there is a difference, try to | |
| 74893 | - ** fix the destination to agree with the source. If that is not possible, | |
| 74894 | - ** then the backup cannot proceed. | |
| 74895 | - */ | |
| 74896 | - if( nSrcReserve!=nDestReserve ){ | |
| 74897 | - u32 newPgsz = nSrcPgsz; | |
| 74898 | - rc = sqlite3PagerSetPagesize(pDestPager, &newPgsz, nSrcReserve); | |
| 74899 | - if( rc==SQLITE_OK && newPgsz!=(u32)nSrcPgsz ) rc = SQLITE_READONLY; | |
| 74900 | - } | |
| 74901 | -#endif | |
| 74902 | - | |
| 74903 | 74701 | /* This loop runs once for each destination page spanned by the source |
| 74904 | 74702 | ** page. For each iteration, variable iOff is set to the byte offset |
| 74905 | 74703 | ** of the destination page. |
| 74906 | 74704 | */ |
| 74907 | 74705 | for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){ |
| @@ -75393,14 +75191,10 @@ | ||
| 75393 | 75191 | b.pSrcDb = pFrom->db; |
| 75394 | 75192 | b.pSrc = pFrom; |
| 75395 | 75193 | b.pDest = pTo; |
| 75396 | 75194 | b.iNext = 1; |
| 75397 | 75195 | |
| 75398 | -#ifdef SQLITE_HAS_CODEC | |
| 75399 | - sqlite3PagerAlignReserve(sqlite3BtreePager(pTo), sqlite3BtreePager(pFrom)); | |
| 75400 | -#endif | |
| 75401 | - | |
| 75402 | 75196 | /* 0x7FFFFFFF is the hard limit for the number of pages in a database |
| 75403 | 75197 | ** file. By passing this as the number of pages to copy to |
| 75404 | 75198 | ** sqlite3_backup_step(), we can guarantee that the copy finishes |
| 75405 | 75199 | ** within a single call (unless an error occurs). The assert() statement |
| 75406 | 75200 | ** checks this assumption - (p->rc) should be set to either SQLITE_DONE |
| @@ -76594,11 +76388,11 @@ | ||
| 76594 | 76388 | ** destroyed. |
| 76595 | 76389 | ** |
| 76596 | 76390 | ** If this routine fails for any reason (malloc returns NULL or unable |
| 76597 | 76391 | ** to read from the disk) then the pMem is left in an inconsistent state. |
| 76598 | 76392 | */ |
| 76599 | -static SQLITE_NOINLINE int vdbeMemFromBtreeResize( | |
| 76393 | +SQLITE_PRIVATE int sqlite3VdbeMemFromBtree( | |
| 76600 | 76394 | BtCursor *pCur, /* Cursor pointing at record to retrieve. */ |
| 76601 | 76395 | u32 offset, /* Offset from the start of data to return bytes from. */ |
| 76602 | 76396 | u32 amt, /* Number of bytes to return. */ |
| 76603 | 76397 | Mem *pMem /* OUT: Return data in this Mem structure. */ |
| 76604 | 76398 | ){ |
| @@ -76617,35 +76411,32 @@ | ||
| 76617 | 76411 | sqlite3VdbeMemRelease(pMem); |
| 76618 | 76412 | } |
| 76619 | 76413 | } |
| 76620 | 76414 | return rc; |
| 76621 | 76415 | } |
| 76622 | -SQLITE_PRIVATE int sqlite3VdbeMemFromBtree( | |
| 76416 | +SQLITE_PRIVATE int sqlite3VdbeMemFromBtreeZeroOffset( | |
| 76623 | 76417 | BtCursor *pCur, /* Cursor pointing at record to retrieve. */ |
| 76624 | - u32 offset, /* Offset from the start of data to return bytes from. */ | |
| 76625 | 76418 | u32 amt, /* Number of bytes to return. */ |
| 76626 | 76419 | Mem *pMem /* OUT: Return data in this Mem structure. */ |
| 76627 | 76420 | ){ |
| 76628 | - char *zData; /* Data from the btree layer */ | |
| 76629 | 76421 | u32 available = 0; /* Number of bytes available on the local btree page */ |
| 76630 | 76422 | int rc = SQLITE_OK; /* Return code */ |
| 76631 | 76423 | |
| 76632 | 76424 | assert( sqlite3BtreeCursorIsValid(pCur) ); |
| 76633 | 76425 | assert( !VdbeMemDynamic(pMem) ); |
| 76634 | 76426 | |
| 76635 | 76427 | /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert() |
| 76636 | 76428 | ** that both the BtShared and database handle mutexes are held. */ |
| 76637 | 76429 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| 76638 | - zData = (char *)sqlite3BtreePayloadFetch(pCur, &available); | |
| 76639 | - assert( zData!=0 ); | |
| 76430 | + pMem->z = (char *)sqlite3BtreePayloadFetch(pCur, &available); | |
| 76431 | + assert( pMem->z!=0 ); | |
| 76640 | 76432 | |
| 76641 | - if( offset+amt<=available ){ | |
| 76642 | - pMem->z = &zData[offset]; | |
| 76433 | + if( amt<=available ){ | |
| 76643 | 76434 | pMem->flags = MEM_Blob|MEM_Ephem; |
| 76644 | 76435 | pMem->n = (int)amt; |
| 76645 | 76436 | }else{ |
| 76646 | - rc = vdbeMemFromBtreeResize(pCur, offset, amt, pMem); | |
| 76437 | + rc = sqlite3VdbeMemFromBtree(pCur, 0, amt, pMem); | |
| 76647 | 76438 | } |
| 76648 | 76439 | |
| 76649 | 76440 | return rc; |
| 76650 | 76441 | } |
| 76651 | 76442 | |
| @@ -78397,10 +78188,38 @@ | ||
| 78397 | 78188 | */ |
| 78398 | 78189 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){ |
| 78399 | 78190 | sqlite3VdbeChangeP2(p, addr, p->nOp); |
| 78400 | 78191 | } |
| 78401 | 78192 | |
| 78193 | +/* | |
| 78194 | +** Change the P2 operand of the jump instruction at addr so that | |
| 78195 | +** the jump lands on the next opcode. Or if the jump instruction was | |
| 78196 | +** the previous opcode (and is thus a no-op) then simply back up | |
| 78197 | +** the next instruction counter by one slot so that the jump is | |
| 78198 | +** overwritten by the next inserted opcode. | |
| 78199 | +** | |
| 78200 | +** This routine is an optimization of sqlite3VdbeJumpHere() that | |
| 78201 | +** strives to omit useless byte-code like this: | |
| 78202 | +** | |
| 78203 | +** 7 Once 0 8 0 | |
| 78204 | +** 8 ... | |
| 78205 | +*/ | |
| 78206 | +SQLITE_PRIVATE void sqlite3VdbeJumpHereOrPopInst(Vdbe *p, int addr){ | |
| 78207 | + if( addr==p->nOp-1 ){ | |
| 78208 | + assert( p->aOp[addr].opcode==OP_Once | |
| 78209 | + || p->aOp[addr].opcode==OP_If | |
| 78210 | + || p->aOp[addr].opcode==OP_FkIfZero ); | |
| 78211 | + assert( p->aOp[addr].p4type==0 ); | |
| 78212 | +#ifdef SQLITE_VDBE_COVERAGE | |
| 78213 | + sqlite3VdbeGetOp(p,-1)->iSrcLine = 0; /* Erase VdbeCoverage() macros */ | |
| 78214 | +#endif | |
| 78215 | + p->nOp--; | |
| 78216 | + }else{ | |
| 78217 | + sqlite3VdbeChangeP2(p, addr, p->nOp); | |
| 78218 | + } | |
| 78219 | +} | |
| 78220 | + | |
| 78402 | 78221 | |
| 78403 | 78222 | /* |
| 78404 | 78223 | ** If the input FuncDef structure is ephemeral, then free it. If |
| 78405 | 78224 | ** the FuncDef is not ephermal, then do nothing. |
| 78406 | 78225 | */ |
| @@ -78777,12 +78596,15 @@ | ||
| 78777 | 78596 | int nTemp /* Space available in zTemp[] */ |
| 78778 | 78597 | ){ |
| 78779 | 78598 | const char *zOpName; |
| 78780 | 78599 | const char *zSynopsis; |
| 78781 | 78600 | int nOpName; |
| 78782 | - int ii, jj; | |
| 78601 | + int ii; | |
| 78783 | 78602 | char zAlt[50]; |
| 78603 | + StrAccum x; | |
| 78604 | + sqlite3StrAccumInit(&x, 0, zTemp, nTemp, 0); | |
| 78605 | + | |
| 78784 | 78606 | zOpName = sqlite3OpcodeName(pOp->opcode); |
| 78785 | 78607 | nOpName = sqlite3Strlen30(zOpName); |
| 78786 | 78608 | if( zOpName[nOpName+1] ){ |
| 78787 | 78609 | int seenCom = 0; |
| 78788 | 78610 | char c; |
| @@ -78793,55 +78615,64 @@ | ||
| 78793 | 78615 | }else{ |
| 78794 | 78616 | sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3); |
| 78795 | 78617 | } |
| 78796 | 78618 | zSynopsis = zAlt; |
| 78797 | 78619 | } |
| 78798 | - for(ii=jj=0; jj<nTemp-1 && (c = zSynopsis[ii])!=0; ii++){ | |
| 78620 | + for(ii=0; (c = zSynopsis[ii])!=0; ii++){ | |
| 78799 | 78621 | if( c=='P' ){ |
| 78800 | 78622 | c = zSynopsis[++ii]; |
| 78801 | 78623 | if( c=='4' ){ |
| 78802 | - sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", zP4); | |
| 78624 | + sqlite3_str_appendall(&x, zP4); | |
| 78803 | 78625 | }else if( c=='X' ){ |
| 78804 | - sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", pOp->zComment); | |
| 78626 | + sqlite3_str_appendall(&x, pOp->zComment); | |
| 78805 | 78627 | seenCom = 1; |
| 78806 | 78628 | }else{ |
| 78807 | 78629 | int v1 = translateP(c, pOp); |
| 78808 | 78630 | int v2; |
| 78809 | - sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1); | |
| 78810 | 78631 | if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){ |
| 78811 | 78632 | ii += 3; |
| 78812 | - jj += sqlite3Strlen30(zTemp+jj); | |
| 78813 | 78633 | v2 = translateP(zSynopsis[ii], pOp); |
| 78814 | 78634 | if( strncmp(zSynopsis+ii+1,"+1",2)==0 ){ |
| 78815 | 78635 | ii += 2; |
| 78816 | 78636 | v2++; |
| 78817 | 78637 | } |
| 78818 | - if( v2>1 ){ | |
| 78819 | - sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1); | |
| 78820 | - } | |
| 78821 | - }else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){ | |
| 78822 | - ii += 4; | |
| 78823 | - } | |
| 78824 | - } | |
| 78825 | - jj += sqlite3Strlen30(zTemp+jj); | |
| 78826 | - }else{ | |
| 78827 | - zTemp[jj++] = c; | |
| 78828 | - } | |
| 78829 | - } | |
| 78830 | - if( !seenCom && jj<nTemp-5 && pOp->zComment ){ | |
| 78831 | - sqlite3_snprintf(nTemp-jj, zTemp+jj, "; %s", pOp->zComment); | |
| 78832 | - jj += sqlite3Strlen30(zTemp+jj); | |
| 78833 | - } | |
| 78834 | - if( jj<nTemp ) zTemp[jj] = 0; | |
| 78638 | + if( v2<2 ){ | |
| 78639 | + sqlite3_str_appendf(&x, "%d", v1); | |
| 78640 | + }else{ | |
| 78641 | + sqlite3_str_appendf(&x, "%d..%d", v1, v1+v2-1); | |
| 78642 | + } | |
| 78643 | + }else if( strncmp(zSynopsis+ii+1, "@NP", 3)==0 ){ | |
| 78644 | + sqlite3_context *pCtx = pOp->p4.pCtx; | |
| 78645 | + if( pOp->p4type!=P4_FUNCCTX || pCtx->argc==1 ){ | |
| 78646 | + sqlite3_str_appendf(&x, "%d", v1); | |
| 78647 | + }else if( pCtx->argc>1 ){ | |
| 78648 | + sqlite3_str_appendf(&x, "%d..%d", v1, v1+pCtx->argc-1); | |
| 78649 | + }else{ | |
| 78650 | + assert( x.nChar>2 ); | |
| 78651 | + x.nChar -= 2; | |
| 78652 | + ii++; | |
| 78653 | + } | |
| 78654 | + ii += 3; | |
| 78655 | + }else{ | |
| 78656 | + sqlite3_str_appendf(&x, "%d", v1); | |
| 78657 | + if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){ | |
| 78658 | + ii += 4; | |
| 78659 | + } | |
| 78660 | + } | |
| 78661 | + } | |
| 78662 | + }else{ | |
| 78663 | + sqlite3_str_appendchar(&x, 1, c); | |
| 78664 | + } | |
| 78665 | + } | |
| 78666 | + if( !seenCom && pOp->zComment ){ | |
| 78667 | + sqlite3_str_appendf(&x, "; %s", pOp->zComment); | |
| 78668 | + } | |
| 78835 | 78669 | }else if( pOp->zComment ){ |
| 78836 | - sqlite3_snprintf(nTemp, zTemp, "%s", pOp->zComment); | |
| 78837 | - jj = sqlite3Strlen30(zTemp); | |
| 78838 | - }else{ | |
| 78839 | - zTemp[0] = 0; | |
| 78840 | - jj = 0; | |
| 78670 | + sqlite3_str_appendall(&x, pOp->zComment); | |
| 78841 | 78671 | } |
| 78842 | - return jj; | |
| 78672 | + sqlite3StrAccumFinish(&x); | |
| 78673 | + return x.nChar; | |
| 78843 | 78674 | } |
| 78844 | 78675 | #endif /* SQLITE_DEBUG */ |
| 78845 | 78676 | |
| 78846 | 78677 | #if VDBE_DISPLAY_P4 && defined(SQLITE_ENABLE_CURSOR_HINTS) |
| 78847 | 78678 | /* |
| @@ -80832,11 +80663,11 @@ | ||
| 80832 | 80663 | SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, int *piCol){ |
| 80833 | 80664 | VdbeCursor *p = *pp; |
| 80834 | 80665 | assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO ); |
| 80835 | 80666 | if( p->deferredMoveto ){ |
| 80836 | 80667 | int iMap; |
| 80837 | - if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){ | |
| 80668 | + if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){ | |
| 80838 | 80669 | *pp = p->pAltCursor; |
| 80839 | 80670 | *piCol = iMap - 1; |
| 80840 | 80671 | return SQLITE_OK; |
| 80841 | 80672 | } |
| 80842 | 80673 | return sqlite3VdbeFinishMoveto(p); |
| @@ -81835,11 +81666,11 @@ | ||
| 81835 | 81666 | } |
| 81836 | 81667 | } |
| 81837 | 81668 | |
| 81838 | 81669 | /* RHS is a string */ |
| 81839 | 81670 | else if( pRhs->flags & MEM_Str ){ |
| 81840 | - getVarint32(&aKey1[idx1], serial_type); | |
| 81671 | + getVarint32NR(&aKey1[idx1], serial_type); | |
| 81841 | 81672 | testcase( serial_type==12 ); |
| 81842 | 81673 | if( serial_type<12 ){ |
| 81843 | 81674 | rc = -1; |
| 81844 | 81675 | }else if( !(serial_type & 0x01) ){ |
| 81845 | 81676 | rc = +1; |
| @@ -81869,11 +81700,11 @@ | ||
| 81869 | 81700 | } |
| 81870 | 81701 | |
| 81871 | 81702 | /* RHS is a blob */ |
| 81872 | 81703 | else if( pRhs->flags & MEM_Blob ){ |
| 81873 | 81704 | assert( (pRhs->flags & MEM_Zero)==0 || pRhs->n==0 ); |
| 81874 | - getVarint32(&aKey1[idx1], serial_type); | |
| 81705 | + getVarint32NR(&aKey1[idx1], serial_type); | |
| 81875 | 81706 | testcase( serial_type==12 ); |
| 81876 | 81707 | if( serial_type<12 || (serial_type & 0x01) ){ |
| 81877 | 81708 | rc = -1; |
| 81878 | 81709 | }else{ |
| 81879 | 81710 | int nStr = (serial_type - 12) / 2; |
| @@ -82058,11 +81889,14 @@ | ||
| 82058 | 81889 | int serial_type; |
| 82059 | 81890 | int res; |
| 82060 | 81891 | |
| 82061 | 81892 | assert( pPKey2->aMem[0].flags & MEM_Str ); |
| 82062 | 81893 | vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); |
| 82063 | - getVarint32(&aKey1[1], serial_type); | |
| 81894 | + serial_type = (u8)(aKey1[1]); | |
| 81895 | + if( serial_type >= 0x80 ){ | |
| 81896 | + sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type); | |
| 81897 | + } | |
| 82064 | 81898 | if( serial_type<12 ){ |
| 82065 | 81899 | res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */ |
| 82066 | 81900 | }else if( !(serial_type & 0x01) ){ |
| 82067 | 81901 | res = pPKey2->r2; /* (pKey1/nKey1) is a blob */ |
| 82068 | 81902 | }else{ |
| @@ -82179,17 +82013,17 @@ | ||
| 82179 | 82013 | nCellKey = sqlite3BtreePayloadSize(pCur); |
| 82180 | 82014 | assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey ); |
| 82181 | 82015 | |
| 82182 | 82016 | /* Read in the complete content of the index entry */ |
| 82183 | 82017 | sqlite3VdbeMemInit(&m, db, 0); |
| 82184 | - rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, &m); | |
| 82018 | + rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m); | |
| 82185 | 82019 | if( rc ){ |
| 82186 | 82020 | return rc; |
| 82187 | 82021 | } |
| 82188 | 82022 | |
| 82189 | 82023 | /* The index entry must begin with a header size */ |
| 82190 | - (void)getVarint32((u8*)m.z, szHdr); | |
| 82024 | + getVarint32NR((u8*)m.z, szHdr); | |
| 82191 | 82025 | testcase( szHdr==3 ); |
| 82192 | 82026 | testcase( szHdr==m.n ); |
| 82193 | 82027 | testcase( szHdr>0x7fffffff ); |
| 82194 | 82028 | assert( m.n>=0 ); |
| 82195 | 82029 | if( unlikely(szHdr<3 || szHdr>(unsigned)m.n) ){ |
| @@ -82196,11 +82030,11 @@ | ||
| 82196 | 82030 | goto idx_rowid_corruption; |
| 82197 | 82031 | } |
| 82198 | 82032 | |
| 82199 | 82033 | /* The last field of the index should be an integer - the ROWID. |
| 82200 | 82034 | ** Verify that the last entry really is an integer. */ |
| 82201 | - (void)getVarint32((u8*)&m.z[szHdr-1], typeRowid); | |
| 82035 | + getVarint32NR((u8*)&m.z[szHdr-1], typeRowid); | |
| 82202 | 82036 | testcase( typeRowid==1 ); |
| 82203 | 82037 | testcase( typeRowid==2 ); |
| 82204 | 82038 | testcase( typeRowid==3 ); |
| 82205 | 82039 | testcase( typeRowid==4 ); |
| 82206 | 82040 | testcase( typeRowid==5 ); |
| @@ -82261,11 +82095,11 @@ | ||
| 82261 | 82095 | if( nCellKey<=0 || nCellKey>0x7fffffff ){ |
| 82262 | 82096 | *res = 0; |
| 82263 | 82097 | return SQLITE_CORRUPT_BKPT; |
| 82264 | 82098 | } |
| 82265 | 82099 | sqlite3VdbeMemInit(&m, db, 0); |
| 82266 | - rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, &m); | |
| 82100 | + rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m); | |
| 82267 | 82101 | if( rc ){ |
| 82268 | 82102 | return rc; |
| 82269 | 82103 | } |
| 82270 | 82104 | *res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, pUnpacked, 0); |
| 82271 | 82105 | sqlite3VdbeMemRelease(&m); |
| @@ -86927,11 +86761,11 @@ | ||
| 86927 | 86761 | affinity = pOp->p5 & SQLITE_AFF_MASK; |
| 86928 | 86762 | if( affinity>=SQLITE_AFF_NUMERIC ){ |
| 86929 | 86763 | if( (flags1 | flags3)&MEM_Str ){ |
| 86930 | 86764 | if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){ |
| 86931 | 86765 | applyNumericAffinity(pIn1,0); |
| 86932 | - testcase( flags3!=pIn3->flags ); | |
| 86766 | + assert( flags3==pIn3->flags ); | |
| 86933 | 86767 | flags3 = pIn3->flags; |
| 86934 | 86768 | } |
| 86935 | 86769 | if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){ |
| 86936 | 86770 | applyNumericAffinity(pIn3,0); |
| 86937 | 86771 | } |
| @@ -86950,11 +86784,11 @@ | ||
| 86950 | 86784 | testcase( pIn1->flags & MEM_Real ); |
| 86951 | 86785 | testcase( pIn1->flags & MEM_IntReal ); |
| 86952 | 86786 | sqlite3VdbeMemStringify(pIn1, encoding, 1); |
| 86953 | 86787 | testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) ); |
| 86954 | 86788 | flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask); |
| 86955 | - if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str; | |
| 86789 | + if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str; | |
| 86956 | 86790 | } |
| 86957 | 86791 | if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){ |
| 86958 | 86792 | testcase( pIn3->flags & MEM_Int ); |
| 86959 | 86793 | testcase( pIn3->flags & MEM_Real ); |
| 86960 | 86794 | testcase( pIn3->flags & MEM_IntReal ); |
| @@ -87565,11 +87399,11 @@ | ||
| 87565 | 87399 | */ |
| 87566 | 87400 | if( pC->iHdrOffset<aOffset[0] ){ |
| 87567 | 87401 | /* Make sure zData points to enough of the record to cover the header. */ |
| 87568 | 87402 | if( pC->aRow==0 ){ |
| 87569 | 87403 | memset(&sMem, 0, sizeof(sMem)); |
| 87570 | - rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, 0, aOffset[0], &sMem); | |
| 87404 | + rc = sqlite3VdbeMemFromBtreeZeroOffset(pC->uc.pCursor,aOffset[0],&sMem); | |
| 87571 | 87405 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 87572 | 87406 | zData = (u8*)sMem.z; |
| 87573 | 87407 | }else{ |
| 87574 | 87408 | zData = pC->aRow; |
| 87575 | 87409 | } |
| @@ -90061,11 +89895,11 @@ | ||
| 90061 | 89895 | n = sqlite3BtreePayloadSize(pCrsr); |
| 90062 | 89896 | if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 90063 | 89897 | goto too_big; |
| 90064 | 89898 | } |
| 90065 | 89899 | testcase( n==0 ); |
| 90066 | - rc = sqlite3VdbeMemFromBtree(pCrsr, 0, n, pOut); | |
| 89900 | + rc = sqlite3VdbeMemFromBtreeZeroOffset(pCrsr, n, pOut); | |
| 90067 | 89901 | if( rc ) goto abort_due_to_error; |
| 90068 | 89902 | if( !pOp->p3 ) Deephemeralize(pOut); |
| 90069 | 89903 | UPDATE_MAX_BLOBSIZE(pOut); |
| 90070 | 89904 | REGISTER_TRACE(pOp->p2, pOut); |
| 90071 | 89905 | break; |
| @@ -90439,48 +90273,61 @@ | ||
| 90439 | 90273 | ** to P2. |
| 90440 | 90274 | ** |
| 90441 | 90275 | ** This instruction only works for indices. The equivalent instruction |
| 90442 | 90276 | ** for tables is OP_Insert. |
| 90443 | 90277 | */ |
| 90444 | -/* Opcode: SorterInsert P1 P2 * * * | |
| 90445 | -** Synopsis: key=r[P2] | |
| 90446 | -** | |
| 90447 | -** Register P2 holds an SQL index key made using the | |
| 90448 | -** MakeRecord instructions. This opcode writes that key | |
| 90449 | -** into the sorter P1. Data for the entry is nil. | |
| 90450 | -*/ | |
| 90451 | -case OP_SorterInsert: /* in2 */ | |
| 90452 | 90278 | case OP_IdxInsert: { /* in2 */ |
| 90453 | 90279 | VdbeCursor *pC; |
| 90454 | 90280 | BtreePayload x; |
| 90455 | 90281 | |
| 90456 | 90282 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 90457 | 90283 | pC = p->apCsr[pOp->p1]; |
| 90458 | 90284 | sqlite3VdbeIncrWriteCounter(p, pC); |
| 90459 | 90285 | assert( pC!=0 ); |
| 90460 | - assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) ); | |
| 90286 | + assert( !isSorter(pC) ); | |
| 90461 | 90287 | pIn2 = &aMem[pOp->p2]; |
| 90462 | 90288 | assert( pIn2->flags & MEM_Blob ); |
| 90463 | 90289 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 90464 | - assert( pC->eCurType==CURTYPE_BTREE || pOp->opcode==OP_SorterInsert ); | |
| 90290 | + assert( pC->eCurType==CURTYPE_BTREE ); | |
| 90291 | + assert( pC->isTable==0 ); | |
| 90292 | + rc = ExpandBlob(pIn2); | |
| 90293 | + if( rc ) goto abort_due_to_error; | |
| 90294 | + x.nKey = pIn2->n; | |
| 90295 | + x.pKey = pIn2->z; | |
| 90296 | + x.aMem = aMem + pOp->p3; | |
| 90297 | + x.nMem = (u16)pOp->p4.i; | |
| 90298 | + rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, | |
| 90299 | + (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)), | |
| 90300 | + ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) | |
| 90301 | + ); | |
| 90302 | + assert( pC->deferredMoveto==0 ); | |
| 90303 | + pC->cacheStatus = CACHE_STALE; | |
| 90304 | + if( rc) goto abort_due_to_error; | |
| 90305 | + break; | |
| 90306 | +} | |
| 90307 | + | |
| 90308 | +/* Opcode: SorterInsert P1 P2 * * * | |
| 90309 | +** Synopsis: key=r[P2] | |
| 90310 | +** | |
| 90311 | +** Register P2 holds an SQL index key made using the | |
| 90312 | +** MakeRecord instructions. This opcode writes that key | |
| 90313 | +** into the sorter P1. Data for the entry is nil. | |
| 90314 | +*/ | |
| 90315 | +case OP_SorterInsert: { /* in2 */ | |
| 90316 | + VdbeCursor *pC; | |
| 90317 | + | |
| 90318 | + assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | |
| 90319 | + pC = p->apCsr[pOp->p1]; | |
| 90320 | + sqlite3VdbeIncrWriteCounter(p, pC); | |
| 90321 | + assert( pC!=0 ); | |
| 90322 | + assert( isSorter(pC) ); | |
| 90323 | + pIn2 = &aMem[pOp->p2]; | |
| 90324 | + assert( pIn2->flags & MEM_Blob ); | |
| 90465 | 90325 | assert( pC->isTable==0 ); |
| 90466 | 90326 | rc = ExpandBlob(pIn2); |
| 90467 | 90327 | if( rc ) goto abort_due_to_error; |
| 90468 | - if( pOp->opcode==OP_SorterInsert ){ | |
| 90469 | - rc = sqlite3VdbeSorterWrite(pC, pIn2); | |
| 90470 | - }else{ | |
| 90471 | - x.nKey = pIn2->n; | |
| 90472 | - x.pKey = pIn2->z; | |
| 90473 | - x.aMem = aMem + pOp->p3; | |
| 90474 | - x.nMem = (u16)pOp->p4.i; | |
| 90475 | - rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, | |
| 90476 | - (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)), | |
| 90477 | - ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) | |
| 90478 | - ); | |
| 90479 | - assert( pC->deferredMoveto==0 ); | |
| 90480 | - pC->cacheStatus = CACHE_STALE; | |
| 90481 | - } | |
| 90328 | + rc = sqlite3VdbeSorterWrite(pC, pIn2); | |
| 90482 | 90329 | if( rc) goto abort_due_to_error; |
| 90483 | 90330 | break; |
| 90484 | 90331 | } |
| 90485 | 90332 | |
| 90486 | 90333 | /* Opcode: IdxDelete P1 P2 P3 * * |
| @@ -92426,11 +92273,11 @@ | ||
| 92426 | 92273 | break; |
| 92427 | 92274 | } |
| 92428 | 92275 | #endif |
| 92429 | 92276 | |
| 92430 | 92277 | /* Opcode: Function P1 P2 P3 P4 * |
| 92431 | -** Synopsis: r[P3]=func(r[P2@P5]) | |
| 92278 | +** Synopsis: r[P3]=func(r[P2@NP]) | |
| 92432 | 92279 | ** |
| 92433 | 92280 | ** Invoke a user function (P4 is a pointer to an sqlite3_context object that |
| 92434 | 92281 | ** contains a pointer to the function to be run) with arguments taken |
| 92435 | 92282 | ** from register P2 and successors. The number of arguments is in |
| 92436 | 92283 | ** the sqlite3_context object that P4 points to. |
| @@ -92445,11 +92292,11 @@ | ||
| 92445 | 92292 | ** invocation of this opcode. |
| 92446 | 92293 | ** |
| 92447 | 92294 | ** See also: AggStep, AggFinal, PureFunc |
| 92448 | 92295 | */ |
| 92449 | 92296 | /* Opcode: PureFunc P1 P2 P3 P4 * |
| 92450 | -** Synopsis: r[P3]=func(r[P2@P5]) | |
| 92297 | +** Synopsis: r[P3]=func(r[P2@NP]) | |
| 92451 | 92298 | ** |
| 92452 | 92299 | ** Invoke a user function (P4 is a pointer to an sqlite3_context object that |
| 92453 | 92300 | ** contains a pointer to the function to be run) with arguments taken |
| 92454 | 92301 | ** from register P2 and successors. The number of arguments is in |
| 92455 | 92302 | ** the sqlite3_context object that P4 points to. |
| @@ -94172,12 +94019,12 @@ | ||
| 94172 | 94019 | |
| 94173 | 94020 | int n1; |
| 94174 | 94021 | int n2; |
| 94175 | 94022 | int res; |
| 94176 | 94023 | |
| 94177 | - getVarint32(&p1[1], n1); | |
| 94178 | - getVarint32(&p2[1], n2); | |
| 94024 | + getVarint32NR(&p1[1], n1); | |
| 94025 | + getVarint32NR(&p2[1], n2); | |
| 94179 | 94026 | res = memcmp(v1, v2, (MIN(n1, n2) - 13)/2); |
| 94180 | 94027 | if( res==0 ){ |
| 94181 | 94028 | res = n1 - n2; |
| 94182 | 94029 | } |
| 94183 | 94030 | |
| @@ -95130,11 +94977,11 @@ | ||
| 95130 | 94977 | int nPMA; /* Bytes of PMA space required */ |
| 95131 | 94978 | int t; /* serial type of first record field */ |
| 95132 | 94979 | |
| 95133 | 94980 | assert( pCsr->eCurType==CURTYPE_SORTER ); |
| 95134 | 94981 | pSorter = pCsr->uc.pSorter; |
| 95135 | - getVarint32((const u8*)&pVal->z[1], t); | |
| 94982 | + getVarint32NR((const u8*)&pVal->z[1], t); | |
| 95136 | 94983 | if( t>0 && t<10 && t!=7 ){ |
| 95137 | 94984 | pSorter->typeMask &= SORTER_TYPE_INTEGER; |
| 95138 | 94985 | }else if( t>10 && (t & 0x01) ){ |
| 95139 | 94986 | pSorter->typeMask &= SORTER_TYPE_TEXT; |
| 95140 | 94987 | }else{ |
| @@ -97814,11 +97661,11 @@ | ||
| 97814 | 97661 | case TK_ISNOT: { |
| 97815 | 97662 | Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight); |
| 97816 | 97663 | assert( !ExprHasProperty(pExpr, EP_Reduced) ); |
| 97817 | 97664 | /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE", |
| 97818 | 97665 | ** and "x IS NOT FALSE". */ |
| 97819 | - if( pRight->op==TK_ID ){ | |
| 97666 | + if( pRight && pRight->op==TK_ID ){ | |
| 97820 | 97667 | int rc = resolveExprStep(pWalker, pRight); |
| 97821 | 97668 | if( rc==WRC_Abort ) return WRC_Abort; |
| 97822 | 97669 | if( pRight->op==TK_TRUEFALSE ){ |
| 97823 | 97670 | pExpr->op2 = pExpr->op; |
| 97824 | 97671 | pExpr->op = TK_TRUTH; |
| @@ -102304,10 +102151,20 @@ | ||
| 102304 | 102151 | } |
| 102305 | 102152 | } |
| 102306 | 102153 | } |
| 102307 | 102154 | return iResult; |
| 102308 | 102155 | } |
| 102156 | + | |
| 102157 | +/* | |
| 102158 | +** If the last opcode is a OP_Copy, then set the do-not-merge flag (p5) | |
| 102159 | +** so that a subsequent copy will not be merged into this one. | |
| 102160 | +*/ | |
| 102161 | +static void setDoNotMergeFlagOnCopy(Vdbe *v){ | |
| 102162 | + if( sqlite3VdbeGetOp(v, -1)->opcode==OP_Copy ){ | |
| 102163 | + sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */ | |
| 102164 | + } | |
| 102165 | +} | |
| 102309 | 102166 | |
| 102310 | 102167 | /* |
| 102311 | 102168 | ** Generate code to implement special SQL functions that are implemented |
| 102312 | 102169 | ** in-line rather than by using the usual callbacks. |
| 102313 | 102170 | */ |
| @@ -102336,13 +102193,11 @@ | ||
| 102336 | 102193 | for(i=1; i<nFarg; i++){ |
| 102337 | 102194 | sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce); |
| 102338 | 102195 | VdbeCoverage(v); |
| 102339 | 102196 | sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target); |
| 102340 | 102197 | } |
| 102341 | - if( sqlite3VdbeGetOp(v, -1)->opcode==OP_Copy ){ | |
| 102342 | - sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */ | |
| 102343 | - } | |
| 102198 | + setDoNotMergeFlagOnCopy(v); | |
| 102344 | 102199 | sqlite3VdbeResolveLabel(v, endCoalesce); |
| 102345 | 102200 | break; |
| 102346 | 102201 | } |
| 102347 | 102202 | |
| 102348 | 102203 | default: { |
| @@ -103109,10 +102964,11 @@ | ||
| 103109 | 102964 | sqlite3ExprCode(pParse, pEList->a[nExpr-1].pExpr, target); |
| 103110 | 102965 | }else{ |
| 103111 | 102966 | sqlite3VdbeAddOp2(v, OP_Null, 0, target); |
| 103112 | 102967 | } |
| 103113 | 102968 | sqlite3ExprDelete(db, pDel); |
| 102969 | + setDoNotMergeFlagOnCopy(v); | |
| 103114 | 102970 | sqlite3VdbeResolveLabel(v, endLabel); |
| 103115 | 102971 | break; |
| 103116 | 102972 | } |
| 103117 | 102973 | #ifndef SQLITE_OMIT_TRIGGER |
| 103118 | 102974 | case TK_RAISE: { |
| @@ -104131,23 +103987,29 @@ | ||
| 104131 | 103987 | case TK_EQ: |
| 104132 | 103988 | case TK_NE: |
| 104133 | 103989 | case TK_LT: |
| 104134 | 103990 | case TK_LE: |
| 104135 | 103991 | case TK_GT: |
| 104136 | - case TK_GE: | |
| 103992 | + case TK_GE: { | |
| 103993 | + Expr *pLeft = pExpr->pLeft; | |
| 103994 | + Expr *pRight = pExpr->pRight; | |
| 104137 | 103995 | testcase( pExpr->op==TK_EQ ); |
| 104138 | 103996 | testcase( pExpr->op==TK_NE ); |
| 104139 | 103997 | testcase( pExpr->op==TK_LT ); |
| 104140 | 103998 | testcase( pExpr->op==TK_LE ); |
| 104141 | 103999 | testcase( pExpr->op==TK_GT ); |
| 104142 | 104000 | testcase( pExpr->op==TK_GE ); |
| 104143 | - if( (pExpr->pLeft->op==TK_COLUMN && IsVirtual(pExpr->pLeft->y.pTab)) | |
| 104144 | - || (pExpr->pRight->op==TK_COLUMN && IsVirtual(pExpr->pRight->y.pTab)) | |
| 104001 | + /* The y.pTab=0 assignment in wherecode.c always happens after the | |
| 104002 | + ** impliesNotNullRow() test */ | |
| 104003 | + if( (pLeft->op==TK_COLUMN && ALWAYS(pLeft->y.pTab!=0) | |
| 104004 | + && IsVirtual(pLeft->y.pTab)) | |
| 104005 | + || (pRight->op==TK_COLUMN && ALWAYS(pRight->y.pTab!=0) | |
| 104006 | + && IsVirtual(pRight->y.pTab)) | |
| 104145 | 104007 | ){ |
| 104146 | - return WRC_Prune; | |
| 104008 | + return WRC_Prune; | |
| 104147 | 104009 | } |
| 104148 | - | |
| 104010 | + } | |
| 104149 | 104011 | default: |
| 104150 | 104012 | return WRC_Continue; |
| 104151 | 104013 | } |
| 104152 | 104014 | } |
| 104153 | 104015 | |
| @@ -108386,47 +108248,11 @@ | ||
| 108386 | 108248 | } |
| 108387 | 108249 | pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1; |
| 108388 | 108250 | if( rc==SQLITE_OK && pNew->zDbSName==0 ){ |
| 108389 | 108251 | rc = SQLITE_NOMEM_BKPT; |
| 108390 | 108252 | } |
| 108391 | - | |
| 108392 | - | |
| 108393 | -#ifdef SQLITE_HAS_CODEC | |
| 108394 | - if( rc==SQLITE_OK ){ | |
| 108395 | - extern int sqlite3CodecAttach(sqlite3*, int, const void*, int); | |
| 108396 | - extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*); | |
| 108397 | - int nKey; | |
| 108398 | - char *zKey; | |
| 108399 | - int t = sqlite3_value_type(argv[2]); | |
| 108400 | - switch( t ){ | |
| 108401 | - case SQLITE_INTEGER: | |
| 108402 | - case SQLITE_FLOAT: | |
| 108403 | - zErrDyn = sqlite3DbStrDup(db, "Invalid key value"); | |
| 108404 | - rc = SQLITE_ERROR; | |
| 108405 | - break; | |
| 108406 | - | |
| 108407 | - case SQLITE_TEXT: | |
| 108408 | - case SQLITE_BLOB: | |
| 108409 | - nKey = sqlite3_value_bytes(argv[2]); | |
| 108410 | - zKey = (char *)sqlite3_value_blob(argv[2]); | |
| 108411 | - rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey); | |
| 108412 | - break; | |
| 108413 | - | |
| 108414 | - case SQLITE_NULL: | |
| 108415 | - /* No key specified. Use the key from URI filename, or if none, | |
| 108416 | - ** use the key from the main database. */ | |
| 108417 | - if( sqlite3CodecQueryParameters(db, zName, zPath)==0 ){ | |
| 108418 | - sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey); | |
| 108419 | - if( nKey || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){ | |
| 108420 | - rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey); | |
| 108421 | - } | |
| 108422 | - } | |
| 108423 | - break; | |
| 108424 | - } | |
| 108425 | - } | |
| 108426 | -#endif | |
| 108427 | - sqlite3_free( zPath ); | |
| 108253 | + sqlite3_free_filename( zPath ); | |
| 108428 | 108254 | |
| 108429 | 108255 | /* If the file was opened successfully, read the schema for the new database. |
| 108430 | 108256 | ** If this fails, or if opening the file failed, then close the file and |
| 108431 | 108257 | ** remove the entry from the db->aDb[] array. i.e. put everything back the |
| 108432 | 108258 | ** way we found it. |
| @@ -115207,11 +115033,13 @@ | ||
| 115207 | 115033 | testcase( IsVirtual(pTab) ); |
| 115208 | 115034 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, OPFLAG_FORDELETE, |
| 115209 | 115035 | iTabCur, aToOpen, &iDataCur, &iIdxCur); |
| 115210 | 115036 | assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur ); |
| 115211 | 115037 | assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 ); |
| 115212 | - if( eOnePass==ONEPASS_MULTI ) sqlite3VdbeJumpHere(v, iAddrOnce); | |
| 115038 | + if( eOnePass==ONEPASS_MULTI ){ | |
| 115039 | + sqlite3VdbeJumpHereOrPopInst(v, iAddrOnce); | |
| 115040 | + } | |
| 115213 | 115041 | } |
| 115214 | 115042 | |
| 115215 | 115043 | /* Set up a loop over the rowids/primary-keys that were found in the |
| 115216 | 115044 | ** where-clause loop above. |
| 115217 | 115045 | */ |
| @@ -118337,11 +118165,11 @@ | ||
| 118337 | 118165 | } |
| 118338 | 118166 | |
| 118339 | 118167 | /* Clean up the WHERE clause constructed above. */ |
| 118340 | 118168 | sqlite3ExprDelete(db, pWhere); |
| 118341 | 118169 | if( iFkIfZero ){ |
| 118342 | - sqlite3VdbeJumpHere(v, iFkIfZero); | |
| 118170 | + sqlite3VdbeJumpHereOrPopInst(v, iFkIfZero); | |
| 118343 | 118171 | } |
| 118344 | 118172 | } |
| 118345 | 118173 | |
| 118346 | 118174 | /* |
| 118347 | 118175 | ** This function returns a linked list of FKey objects (connected by |
| @@ -120798,10 +120626,14 @@ | ||
| 120798 | 120626 | && !sqlite3ExprReferencesUpdatedColumn(pExpr, aiChng, pkChng) |
| 120799 | 120627 | ){ |
| 120800 | 120628 | /* The check constraints do not reference any of the columns being |
| 120801 | 120629 | ** updated so there is no point it verifying the check constraint */ |
| 120802 | 120630 | continue; |
| 120631 | + } | |
| 120632 | + if( bAffinityDone==0 ){ | |
| 120633 | + sqlite3TableAffinity(v, pTab, regNewData+1); | |
| 120634 | + bAffinityDone = 1; | |
| 120803 | 120635 | } |
| 120804 | 120636 | allOk = sqlite3VdbeMakeLabel(pParse); |
| 120805 | 120637 | sqlite3VdbeVerifyAbortable(v, onError); |
| 120806 | 120638 | sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL); |
| 120807 | 120639 | if( onError==OE_Ignore ){ |
| @@ -121915,18 +121747,17 @@ | ||
| 121915 | 121747 | addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid); |
| 121916 | 121748 | }else{ |
| 121917 | 121749 | addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); |
| 121918 | 121750 | assert( (pDest->tabFlags & TF_Autoincrement)==0 ); |
| 121919 | 121751 | } |
| 121920 | - sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); | |
| 121921 | 121752 | if( db->mDbFlags & DBFLAG_Vacuum ){ |
| 121922 | 121753 | sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest); |
| 121923 | - insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID| | |
| 121924 | - OPFLAG_APPEND|OPFLAG_USESEEKRESULT; | |
| 121754 | + insFlags = OPFLAG_APPEND|OPFLAG_USESEEKRESULT; | |
| 121925 | 121755 | }else{ |
| 121926 | 121756 | insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND; |
| 121927 | 121757 | } |
| 121758 | + sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); | |
| 121928 | 121759 | sqlite3VdbeAddOp4(v, OP_Insert, iDest, regData, regRowid, |
| 121929 | 121760 | (char*)pDest, P4_TABLE); |
| 121930 | 121761 | sqlite3VdbeChangeP5(v, insFlags); |
| 121931 | 121762 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v); |
| 121932 | 121763 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| @@ -121947,11 +121778,10 @@ | ||
| 121947 | 121778 | sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest); |
| 121948 | 121779 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 121949 | 121780 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 121950 | 121781 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 121951 | 121782 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 121952 | - sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); | |
| 121953 | 121783 | if( db->mDbFlags & DBFLAG_Vacuum ){ |
| 121954 | 121784 | /* This INSERT command is part of a VACUUM operation, which guarantees |
| 121955 | 121785 | ** that the destination table is empty. If all indexed columns use |
| 121956 | 121786 | ** collation sequence BINARY, then it can also be assumed that the |
| 121957 | 121787 | ** index will be populated by inserting keys in strictly sorted |
| @@ -121971,14 +121801,14 @@ | ||
| 121971 | 121801 | } |
| 121972 | 121802 | if( i==pSrcIdx->nColumn ){ |
| 121973 | 121803 | idxInsFlags = OPFLAG_USESEEKRESULT; |
| 121974 | 121804 | sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest); |
| 121975 | 121805 | } |
| 121976 | - } | |
| 121977 | - if( !HasRowid(pSrc) && pDestIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){ | |
| 121806 | + }else if( !HasRowid(pSrc) && pDestIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){ | |
| 121978 | 121807 | idxInsFlags |= OPFLAG_NCHANGE; |
| 121979 | 121808 | } |
| 121809 | + sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); | |
| 121980 | 121810 | sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData); |
| 121981 | 121811 | sqlite3VdbeChangeP5(v, idxInsFlags|OPFLAG_APPEND); |
| 121982 | 121812 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v); |
| 121983 | 121813 | sqlite3VdbeJumpHere(v, addr1); |
| 121984 | 121814 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| @@ -122495,10 +122325,14 @@ | ||
| 122495 | 122325 | sqlite3_int64 (*hard_heap_limit64)(sqlite3_int64); |
| 122496 | 122326 | const char *(*uri_key)(const char*,int); |
| 122497 | 122327 | const char *(*filename_database)(const char*); |
| 122498 | 122328 | const char *(*filename_journal)(const char*); |
| 122499 | 122329 | const char *(*filename_wal)(const char*); |
| 122330 | + /* Version 3.32.0 and later */ | |
| 122331 | + char *(*create_filename)(const char*,const char*,const char*, | |
| 122332 | + int,const char**); | |
| 122333 | + void (*free_filename)(char*); | |
| 122500 | 122334 | }; |
| 122501 | 122335 | |
| 122502 | 122336 | /* |
| 122503 | 122337 | ** This is the function signature used for all extension entry points. It |
| 122504 | 122338 | ** is also defined in the file "loadext.c". |
| @@ -122795,10 +122629,13 @@ | ||
| 122795 | 122629 | #define sqlite3_hard_heap_limit64 sqlite3_api->hard_heap_limit64 |
| 122796 | 122630 | #define sqlite3_uri_key sqlite3_api->uri_key |
| 122797 | 122631 | #define sqlite3_filename_database sqlite3_api->filename_database |
| 122798 | 122632 | #define sqlite3_filename_journal sqlite3_api->filename_journal |
| 122799 | 122633 | #define sqlite3_filename_wal sqlite3_api->filename_wal |
| 122634 | +/* Version 3.32.0 and later */ | |
| 122635 | +#define sqlite3_create_filename sqlite3_api->create_filename | |
| 122636 | +#define sqlite3_free_filename sqlite3_api->free_filename | |
| 122800 | 122637 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 122801 | 122638 | |
| 122802 | 122639 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 122803 | 122640 | /* This case when the file really is being compiled as a loadable |
| 122804 | 122641 | ** extension */ |
| @@ -123273,10 +123110,13 @@ | ||
| 123273 | 123110 | sqlite3_hard_heap_limit64, |
| 123274 | 123111 | sqlite3_uri_key, |
| 123275 | 123112 | sqlite3_filename_database, |
| 123276 | 123113 | sqlite3_filename_journal, |
| 123277 | 123114 | sqlite3_filename_wal, |
| 123115 | + /* Version 3.32.0 and later */ | |
| 123116 | + sqlite3_create_filename, | |
| 123117 | + sqlite3_free_filename, | |
| 123278 | 123118 | }; |
| 123279 | 123119 | |
| 123280 | 123120 | /* |
| 123281 | 123121 | ** Attempt to load an SQLite extension library contained in the file |
| 123282 | 123122 | ** zFile. The entry point is zProc. zProc may be 0 in which case a |
| @@ -123679,55 +123519,54 @@ | ||
| 123679 | 123519 | ** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit |
| 123680 | 123520 | ** that script and rerun it. |
| 123681 | 123521 | */ |
| 123682 | 123522 | |
| 123683 | 123523 | /* The various pragma types */ |
| 123684 | -#define PragTyp_HEADER_VALUE 0 | |
| 123685 | -#define PragTyp_AUTO_VACUUM 1 | |
| 123686 | -#define PragTyp_FLAG 2 | |
| 123687 | -#define PragTyp_BUSY_TIMEOUT 3 | |
| 123688 | -#define PragTyp_CACHE_SIZE 4 | |
| 123689 | -#define PragTyp_CACHE_SPILL 5 | |
| 123690 | -#define PragTyp_CASE_SENSITIVE_LIKE 6 | |
| 123691 | -#define PragTyp_COLLATION_LIST 7 | |
| 123692 | -#define PragTyp_COMPILE_OPTIONS 8 | |
| 123693 | -#define PragTyp_DATA_STORE_DIRECTORY 9 | |
| 123694 | -#define PragTyp_DATABASE_LIST 10 | |
| 123695 | -#define PragTyp_DEFAULT_CACHE_SIZE 11 | |
| 123696 | -#define PragTyp_ENCODING 12 | |
| 123697 | -#define PragTyp_FOREIGN_KEY_CHECK 13 | |
| 123698 | -#define PragTyp_FOREIGN_KEY_LIST 14 | |
| 123699 | -#define PragTyp_FUNCTION_LIST 15 | |
| 123700 | -#define PragTyp_HARD_HEAP_LIMIT 16 | |
| 123701 | -#define PragTyp_INCREMENTAL_VACUUM 17 | |
| 123702 | -#define PragTyp_INDEX_INFO 18 | |
| 123703 | -#define PragTyp_INDEX_LIST 19 | |
| 123704 | -#define PragTyp_INTEGRITY_CHECK 20 | |
| 123705 | -#define PragTyp_JOURNAL_MODE 21 | |
| 123706 | -#define PragTyp_JOURNAL_SIZE_LIMIT 22 | |
| 123707 | -#define PragTyp_LOCK_PROXY_FILE 23 | |
| 123708 | -#define PragTyp_LOCKING_MODE 24 | |
| 123709 | -#define PragTyp_PAGE_COUNT 25 | |
| 123710 | -#define PragTyp_MMAP_SIZE 26 | |
| 123711 | -#define PragTyp_MODULE_LIST 27 | |
| 123712 | -#define PragTyp_OPTIMIZE 28 | |
| 123713 | -#define PragTyp_PAGE_SIZE 29 | |
| 123714 | -#define PragTyp_PRAGMA_LIST 30 | |
| 123715 | -#define PragTyp_SECURE_DELETE 31 | |
| 123716 | -#define PragTyp_SHRINK_MEMORY 32 | |
| 123717 | -#define PragTyp_SOFT_HEAP_LIMIT 33 | |
| 123718 | -#define PragTyp_SYNCHRONOUS 34 | |
| 123719 | -#define PragTyp_TABLE_INFO 35 | |
| 123720 | -#define PragTyp_TEMP_STORE 36 | |
| 123721 | -#define PragTyp_TEMP_STORE_DIRECTORY 37 | |
| 123722 | -#define PragTyp_THREADS 38 | |
| 123723 | -#define PragTyp_WAL_AUTOCHECKPOINT 39 | |
| 123724 | -#define PragTyp_WAL_CHECKPOINT 40 | |
| 123725 | -#define PragTyp_ACTIVATE_EXTENSIONS 41 | |
| 123726 | -#define PragTyp_KEY 42 | |
| 123727 | -#define PragTyp_LOCK_STATUS 43 | |
| 123728 | -#define PragTyp_STATS 44 | |
| 123524 | +#define PragTyp_ACTIVATE_EXTENSIONS 0 | |
| 123525 | +#define PragTyp_HEADER_VALUE 1 | |
| 123526 | +#define PragTyp_AUTO_VACUUM 2 | |
| 123527 | +#define PragTyp_FLAG 3 | |
| 123528 | +#define PragTyp_BUSY_TIMEOUT 4 | |
| 123529 | +#define PragTyp_CACHE_SIZE 5 | |
| 123530 | +#define PragTyp_CACHE_SPILL 6 | |
| 123531 | +#define PragTyp_CASE_SENSITIVE_LIKE 7 | |
| 123532 | +#define PragTyp_COLLATION_LIST 8 | |
| 123533 | +#define PragTyp_COMPILE_OPTIONS 9 | |
| 123534 | +#define PragTyp_DATA_STORE_DIRECTORY 10 | |
| 123535 | +#define PragTyp_DATABASE_LIST 11 | |
| 123536 | +#define PragTyp_DEFAULT_CACHE_SIZE 12 | |
| 123537 | +#define PragTyp_ENCODING 13 | |
| 123538 | +#define PragTyp_FOREIGN_KEY_CHECK 14 | |
| 123539 | +#define PragTyp_FOREIGN_KEY_LIST 15 | |
| 123540 | +#define PragTyp_FUNCTION_LIST 16 | |
| 123541 | +#define PragTyp_HARD_HEAP_LIMIT 17 | |
| 123542 | +#define PragTyp_INCREMENTAL_VACUUM 18 | |
| 123543 | +#define PragTyp_INDEX_INFO 19 | |
| 123544 | +#define PragTyp_INDEX_LIST 20 | |
| 123545 | +#define PragTyp_INTEGRITY_CHECK 21 | |
| 123546 | +#define PragTyp_JOURNAL_MODE 22 | |
| 123547 | +#define PragTyp_JOURNAL_SIZE_LIMIT 23 | |
| 123548 | +#define PragTyp_LOCK_PROXY_FILE 24 | |
| 123549 | +#define PragTyp_LOCKING_MODE 25 | |
| 123550 | +#define PragTyp_PAGE_COUNT 26 | |
| 123551 | +#define PragTyp_MMAP_SIZE 27 | |
| 123552 | +#define PragTyp_MODULE_LIST 28 | |
| 123553 | +#define PragTyp_OPTIMIZE 29 | |
| 123554 | +#define PragTyp_PAGE_SIZE 30 | |
| 123555 | +#define PragTyp_PRAGMA_LIST 31 | |
| 123556 | +#define PragTyp_SECURE_DELETE 32 | |
| 123557 | +#define PragTyp_SHRINK_MEMORY 33 | |
| 123558 | +#define PragTyp_SOFT_HEAP_LIMIT 34 | |
| 123559 | +#define PragTyp_SYNCHRONOUS 35 | |
| 123560 | +#define PragTyp_TABLE_INFO 36 | |
| 123561 | +#define PragTyp_TEMP_STORE 37 | |
| 123562 | +#define PragTyp_TEMP_STORE_DIRECTORY 38 | |
| 123563 | +#define PragTyp_THREADS 39 | |
| 123564 | +#define PragTyp_WAL_AUTOCHECKPOINT 40 | |
| 123565 | +#define PragTyp_WAL_CHECKPOINT 41 | |
| 123566 | +#define PragTyp_LOCK_STATUS 42 | |
| 123567 | +#define PragTyp_STATS 43 | |
| 123729 | 123568 | |
| 123730 | 123569 | /* Property flags associated with various pragma. */ |
| 123731 | 123570 | #define PragFlg_NeedSchema 0x01 /* Force schema load before running */ |
| 123732 | 123571 | #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */ |
| 123733 | 123572 | #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */ |
| @@ -123807,11 +123646,11 @@ | ||
| 123807 | 123646 | u8 iPragCName; /* Start of column names in pragCName[] */ |
| 123808 | 123647 | u8 nPragCName; /* Num of col names. 0 means use pragma name */ |
| 123809 | 123648 | u64 iArg; /* Extra argument */ |
| 123810 | 123649 | } PragmaName; |
| 123811 | 123650 | static const PragmaName aPragmaName[] = { |
| 123812 | -#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) | |
| 123651 | +#if defined(SQLITE_ENABLE_CEROD) | |
| 123813 | 123652 | {/* zName: */ "activate_extensions", |
| 123814 | 123653 | /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS, |
| 123815 | 123654 | /* ePragFlg: */ 0, |
| 123816 | 123655 | /* ColNames: */ 0, 0, |
| 123817 | 123656 | /* iArg: */ 0 }, |
| @@ -124003,22 +123842,10 @@ | ||
| 124003 | 123842 | {/* zName: */ "hard_heap_limit", |
| 124004 | 123843 | /* ePragTyp: */ PragTyp_HARD_HEAP_LIMIT, |
| 124005 | 123844 | /* ePragFlg: */ PragFlg_Result0, |
| 124006 | 123845 | /* ColNames: */ 0, 0, |
| 124007 | 123846 | /* iArg: */ 0 }, |
| 124008 | -#if defined(SQLITE_HAS_CODEC) | |
| 124009 | - {/* zName: */ "hexkey", | |
| 124010 | - /* ePragTyp: */ PragTyp_KEY, | |
| 124011 | - /* ePragFlg: */ 0, | |
| 124012 | - /* ColNames: */ 0, 0, | |
| 124013 | - /* iArg: */ 2 }, | |
| 124014 | - {/* zName: */ "hexrekey", | |
| 124015 | - /* ePragTyp: */ PragTyp_KEY, | |
| 124016 | - /* ePragFlg: */ 0, | |
| 124017 | - /* ColNames: */ 0, 0, | |
| 124018 | - /* iArg: */ 3 }, | |
| 124019 | -#endif | |
| 124020 | 123847 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 124021 | 123848 | #if !defined(SQLITE_OMIT_CHECK) |
| 124022 | 123849 | {/* zName: */ "ignore_check_constraints", |
| 124023 | 123850 | /* ePragTyp: */ PragTyp_FLAG, |
| 124024 | 123851 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| @@ -124064,17 +123891,10 @@ | ||
| 124064 | 123891 | /* ColNames: */ 0, 0, |
| 124065 | 123892 | /* iArg: */ 0 }, |
| 124066 | 123893 | {/* zName: */ "journal_size_limit", |
| 124067 | 123894 | /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT, |
| 124068 | 123895 | /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq, |
| 124069 | - /* ColNames: */ 0, 0, | |
| 124070 | - /* iArg: */ 0 }, | |
| 124071 | -#endif | |
| 124072 | -#if defined(SQLITE_HAS_CODEC) | |
| 124073 | - {/* zName: */ "key", | |
| 124074 | - /* ePragTyp: */ PragTyp_KEY, | |
| 124075 | - /* ePragFlg: */ 0, | |
| 124076 | 123896 | /* ColNames: */ 0, 0, |
| 124077 | 123897 | /* iArg: */ 0 }, |
| 124078 | 123898 | #endif |
| 124079 | 123899 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 124080 | 123900 | {/* zName: */ "legacy_alter_table", |
| @@ -124181,19 +124001,10 @@ | ||
| 124181 | 124001 | {/* zName: */ "recursive_triggers", |
| 124182 | 124002 | /* ePragTyp: */ PragTyp_FLAG, |
| 124183 | 124003 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 124184 | 124004 | /* ColNames: */ 0, 0, |
| 124185 | 124005 | /* iArg: */ SQLITE_RecTriggers }, |
| 124186 | -#endif | |
| 124187 | -#if defined(SQLITE_HAS_CODEC) | |
| 124188 | - {/* zName: */ "rekey", | |
| 124189 | - /* ePragTyp: */ PragTyp_KEY, | |
| 124190 | - /* ePragFlg: */ 0, | |
| 124191 | - /* ColNames: */ 0, 0, | |
| 124192 | - /* iArg: */ 1 }, | |
| 124193 | -#endif | |
| 124194 | -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) | |
| 124195 | 124006 | {/* zName: */ "reverse_unordered_selects", |
| 124196 | 124007 | /* ePragTyp: */ PragTyp_FLAG, |
| 124197 | 124008 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 124198 | 124009 | /* ColNames: */ 0, 0, |
| 124199 | 124010 | /* iArg: */ SQLITE_ReverseOrder }, |
| @@ -124274,22 +124085,10 @@ | ||
| 124274 | 124085 | /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY, |
| 124275 | 124086 | /* ePragFlg: */ PragFlg_NoColumns1, |
| 124276 | 124087 | /* ColNames: */ 0, 0, |
| 124277 | 124088 | /* iArg: */ 0 }, |
| 124278 | 124089 | #endif |
| 124279 | -#if defined(SQLITE_HAS_CODEC) | |
| 124280 | - {/* zName: */ "textkey", | |
| 124281 | - /* ePragTyp: */ PragTyp_KEY, | |
| 124282 | - /* ePragFlg: */ 0, | |
| 124283 | - /* ColNames: */ 0, 0, | |
| 124284 | - /* iArg: */ 4 }, | |
| 124285 | - {/* zName: */ "textrekey", | |
| 124286 | - /* ePragTyp: */ PragTyp_KEY, | |
| 124287 | - /* ePragFlg: */ 0, | |
| 124288 | - /* ColNames: */ 0, 0, | |
| 124289 | - /* iArg: */ 5 }, | |
| 124290 | -#endif | |
| 124291 | 124090 | {/* zName: */ "threads", |
| 124292 | 124091 | /* ePragTyp: */ PragTyp_THREADS, |
| 124293 | 124092 | /* ePragFlg: */ PragFlg_Result0, |
| 124294 | 124093 | /* ColNames: */ 0, 0, |
| 124295 | 124094 | /* iArg: */ 0 }, |
| @@ -124354,11 +124153,11 @@ | ||
| 124354 | 124153 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 124355 | 124154 | /* ColNames: */ 0, 0, |
| 124356 | 124155 | /* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError }, |
| 124357 | 124156 | #endif |
| 124358 | 124157 | }; |
| 124359 | -/* Number of pragmas: 66 on by default, 82 total. */ | |
| 124158 | +/* Number of pragmas: 66 on by default, 76 total. */ | |
| 124360 | 124159 | |
| 124361 | 124160 | /************** End of pragma.h **********************************************/ |
| 124362 | 124161 | /************** Continuing where we left off in pragma.c *********************/ |
| 124363 | 124162 | |
| 124364 | 124163 | /* |
| @@ -126544,63 +126343,15 @@ | ||
| 126544 | 126343 | } |
| 126545 | 126344 | break; |
| 126546 | 126345 | } |
| 126547 | 126346 | #endif |
| 126548 | 126347 | |
| 126549 | -#ifdef SQLITE_HAS_CODEC | |
| 126550 | - /* Pragma iArg | |
| 126551 | - ** ---------- ------ | |
| 126552 | - ** key 0 | |
| 126553 | - ** rekey 1 | |
| 126554 | - ** hexkey 2 | |
| 126555 | - ** hexrekey 3 | |
| 126556 | - ** textkey 4 | |
| 126557 | - ** textrekey 5 | |
| 126558 | - */ | |
| 126559 | - case PragTyp_KEY: { | |
| 126560 | - if( zRight ){ | |
| 126561 | - char zBuf[40]; | |
| 126562 | - const char *zKey = zRight; | |
| 126563 | - int n; | |
| 126564 | - if( pPragma->iArg==2 || pPragma->iArg==3 ){ | |
| 126565 | - u8 iByte; | |
| 126566 | - int i; | |
| 126567 | - for(i=0, iByte=0; i<sizeof(zBuf)*2 && sqlite3Isxdigit(zRight[i]); i++){ | |
| 126568 | - iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]); | |
| 126569 | - if( (i&1)!=0 ) zBuf[i/2] = iByte; | |
| 126570 | - } | |
| 126571 | - zKey = zBuf; | |
| 126572 | - n = i/2; | |
| 126573 | - }else{ | |
| 126574 | - n = pPragma->iArg<4 ? sqlite3Strlen30(zRight) : -1; | |
| 126575 | - } | |
| 126576 | - if( (pPragma->iArg & 1)==0 ){ | |
| 126577 | - rc = sqlite3_key_v2(db, zDb, zKey, n); | |
| 126578 | - }else{ | |
| 126579 | - rc = sqlite3_rekey_v2(db, zDb, zKey, n); | |
| 126580 | - } | |
| 126581 | - if( rc==SQLITE_OK && n!=0 ){ | |
| 126582 | - sqlite3VdbeSetNumCols(v, 1); | |
| 126583 | - sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "ok", SQLITE_STATIC); | |
| 126584 | - returnSingleText(v, "ok"); | |
| 126585 | - } | |
| 126586 | - } | |
| 126587 | - break; | |
| 126588 | - } | |
| 126589 | -#endif | |
| 126590 | -#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) | |
| 126348 | +#if defined(SQLITE_ENABLE_CEROD) | |
| 126591 | 126349 | case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){ |
| 126592 | -#ifdef SQLITE_HAS_CODEC | |
| 126593 | - if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){ | |
| 126594 | - sqlite3_activate_see(&zRight[4]); | |
| 126595 | - } | |
| 126596 | -#endif | |
| 126597 | -#ifdef SQLITE_ENABLE_CEROD | |
| 126598 | 126350 | if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){ |
| 126599 | 126351 | sqlite3_activate_cerod(&zRight[6]); |
| 126600 | 126352 | } |
| 126601 | -#endif | |
| 126602 | 126353 | } |
| 126603 | 126354 | break; |
| 126604 | 126355 | #endif |
| 126605 | 126356 | |
| 126606 | 126357 | } /* End of the PRAGMA switch */ |
| @@ -130671,10 +130422,11 @@ | ||
| 130671 | 130422 | p->pLimit = pLimit; |
| 130672 | 130423 | |
| 130673 | 130424 | /* Generate code to take the intersection of the two temporary |
| 130674 | 130425 | ** tables. |
| 130675 | 130426 | */ |
| 130427 | + if( rc ) break; | |
| 130676 | 130428 | assert( p->pEList ); |
| 130677 | 130429 | iBreak = sqlite3VdbeMakeLabel(pParse); |
| 130678 | 130430 | iCont = sqlite3VdbeMakeLabel(pParse); |
| 130679 | 130431 | computeLimitRegisters(pParse, p, iBreak); |
| 130680 | 130432 | sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v); |
| @@ -132031,13 +131783,12 @@ | ||
| 132031 | 131783 | ){ |
| 132032 | 131784 | int i; |
| 132033 | 131785 | assert( pColumn->op==TK_COLUMN ); |
| 132034 | 131786 | assert( sqlite3ExprIsConstant(pValue) ); |
| 132035 | 131787 | |
| 132036 | - if( !ExprHasProperty(pValue, EP_FixedCol) && sqlite3ExprAffinity(pValue)!=0 ){ | |
| 132037 | - return; | |
| 132038 | - } | |
| 131788 | + if( ExprHasProperty(pColumn, EP_FixedCol) ) return; | |
| 131789 | + if( sqlite3ExprAffinity(pValue)!=0 ) return; | |
| 132039 | 131790 | if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){ |
| 132040 | 131791 | return; |
| 132041 | 131792 | } |
| 132042 | 131793 | |
| 132043 | 131794 | /* 2018-10-25 ticket [cf5ed20f] |
| @@ -132056,13 +131807,10 @@ | ||
| 132056 | 131807 | pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr, |
| 132057 | 131808 | pConst->nConst*2*sizeof(Expr*)); |
| 132058 | 131809 | if( pConst->apExpr==0 ){ |
| 132059 | 131810 | pConst->nConst = 0; |
| 132060 | 131811 | }else{ |
| 132061 | - if( ExprHasProperty(pValue, EP_FixedCol) ){ | |
| 132062 | - pValue = pValue->pLeft; | |
| 132063 | - } | |
| 132064 | 131812 | pConst->apExpr[pConst->nConst*2-2] = pColumn; |
| 132065 | 131813 | pConst->apExpr[pConst->nConst*2-1] = pValue; |
| 132066 | 131814 | } |
| 132067 | 131815 | } |
| 132068 | 131816 | |
| @@ -132334,11 +132082,11 @@ | ||
| 132334 | 132082 | static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){ |
| 132335 | 132083 | int eRet = WHERE_ORDERBY_NORMAL; /* Return value */ |
| 132336 | 132084 | ExprList *pEList = pFunc->x.pList; /* Arguments to agg function */ |
| 132337 | 132085 | const char *zFunc; /* Name of aggregate function pFunc */ |
| 132338 | 132086 | ExprList *pOrderBy; |
| 132339 | - u8 sortFlags; | |
| 132087 | + u8 sortFlags = 0; | |
| 132340 | 132088 | |
| 132341 | 132089 | assert( *ppMinMax==0 ); |
| 132342 | 132090 | assert( pFunc->op==TK_AGG_FUNCTION ); |
| 132343 | 132091 | assert( !IsWindowFunc(pFunc) ); |
| 132344 | 132092 | if( pEList==0 || pEList->nExpr!=1 || ExprHasProperty(pFunc, EP_WinFunc) ){ |
| @@ -132345,11 +132093,13 @@ | ||
| 132345 | 132093 | return eRet; |
| 132346 | 132094 | } |
| 132347 | 132095 | zFunc = pFunc->u.zToken; |
| 132348 | 132096 | if( sqlite3StrICmp(zFunc, "min")==0 ){ |
| 132349 | 132097 | eRet = WHERE_ORDERBY_MIN; |
| 132350 | - sortFlags = KEYINFO_ORDER_BIGNULL; | |
| 132098 | + if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){ | |
| 132099 | + sortFlags = KEYINFO_ORDER_BIGNULL; | |
| 132100 | + } | |
| 132351 | 132101 | }else if( sqlite3StrICmp(zFunc, "max")==0 ){ |
| 132352 | 132102 | eRet = WHERE_ORDERBY_MAX; |
| 132353 | 132103 | sortFlags = KEYINFO_ORDER_DESC; |
| 132354 | 132104 | }else{ |
| 132355 | 132105 | return eRet; |
| @@ -133013,11 +132763,11 @@ | ||
| 133013 | 132763 | pExpr = pRight; |
| 133014 | 132764 | } |
| 133015 | 132765 | pNew = sqlite3ExprListAppend(pParse, pNew, pExpr); |
| 133016 | 132766 | sqlite3TokenInit(&sColname, zColname); |
| 133017 | 132767 | sqlite3ExprListSetName(pParse, pNew, &sColname, 0); |
| 133018 | - if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){ | |
| 132768 | + if( pNew && (p->selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){ | |
| 133019 | 132769 | struct ExprList_item *pX = &pNew->a[pNew->nExpr-1]; |
| 133020 | 132770 | sqlite3DbFree(db, pX->zEName); |
| 133021 | 132771 | if( pSub ){ |
| 133022 | 132772 | pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName); |
| 133023 | 132773 | testcase( pX->zEName==0 ); |
| @@ -133358,11 +133108,11 @@ | ||
| 133358 | 133108 | sqlite3ExprCode(pParse, pC->pExpr, pC->iMem); |
| 133359 | 133109 | } |
| 133360 | 133110 | |
| 133361 | 133111 | pAggInfo->directMode = 0; |
| 133362 | 133112 | if( addrHitTest ){ |
| 133363 | - sqlite3VdbeJumpHere(v, addrHitTest); | |
| 133113 | + sqlite3VdbeJumpHereOrPopInst(v, addrHitTest); | |
| 133364 | 133114 | } |
| 133365 | 133115 | } |
| 133366 | 133116 | |
| 133367 | 133117 | /* |
| 133368 | 133118 | ** Add a single OP_Explain instruction to the VDBE to explain a simple |
| @@ -136671,11 +136421,13 @@ | ||
| 136671 | 136421 | if( eOnePass==ONEPASS_MULTI && (nIdx-(aiCurOnePass[1]>=0))>0 ){ |
| 136672 | 136422 | addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); |
| 136673 | 136423 | } |
| 136674 | 136424 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur, |
| 136675 | 136425 | aToOpen, 0, 0); |
| 136676 | - if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce); | |
| 136426 | + if( addrOnce ){ | |
| 136427 | + sqlite3VdbeJumpHereOrPopInst(v, addrOnce); | |
| 136428 | + } | |
| 136677 | 136429 | } |
| 136678 | 136430 | |
| 136679 | 136431 | /* Top of the update loop */ |
| 136680 | 136432 | if( eOnePass!=ONEPASS_OFF ){ |
| 136681 | 136433 | if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){ |
| @@ -137626,21 +137378,10 @@ | ||
| 137626 | 137378 | } |
| 137627 | 137379 | db->mDbFlags |= DBFLAG_VacuumInto; |
| 137628 | 137380 | } |
| 137629 | 137381 | nRes = sqlite3BtreeGetOptimalReserve(pMain); |
| 137630 | 137382 | |
| 137631 | - /* A VACUUM cannot change the pagesize of an encrypted database. */ | |
| 137632 | -#ifdef SQLITE_HAS_CODEC | |
| 137633 | - if( db->nextPagesize ){ | |
| 137634 | - extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*); | |
| 137635 | - int nKey; | |
| 137636 | - char *zKey; | |
| 137637 | - sqlite3CodecGetKey(db, iDb, (void**)&zKey, &nKey); | |
| 137638 | - if( nKey ) db->nextPagesize = 0; | |
| 137639 | - } | |
| 137640 | -#endif | |
| 137641 | - | |
| 137642 | 137383 | sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size); |
| 137643 | 137384 | sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0)); |
| 137644 | 137385 | sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF|PAGER_CACHESPILL); |
| 137645 | 137386 | |
| 137646 | 137387 | /* Begin a transaction and take an exclusive lock on the main database |
| @@ -139443,10 +139184,16 @@ | ||
| 139443 | 139184 | #define TERM_LIKEOPT 0x0100 /* Virtual terms from the LIKE optimization */ |
| 139444 | 139185 | #define TERM_LIKECOND 0x0200 /* Conditionally this LIKE operator term */ |
| 139445 | 139186 | #define TERM_LIKE 0x0400 /* The original LIKE operator */ |
| 139446 | 139187 | #define TERM_IS 0x0800 /* Term.pExpr is an IS operator */ |
| 139447 | 139188 | #define TERM_VARSELECT 0x1000 /* Term.pExpr contains a correlated sub-query */ |
| 139189 | +#define TERM_HEURTRUTH 0x2000 /* Heuristic truthProb used */ | |
| 139190 | +#ifdef SQLITE_ENABLE_STAT4 | |
| 139191 | +# define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */ | |
| 139192 | +#else | |
| 139193 | +# define TERM_HIGHTRUTH 0 /* Only used with STAT4 */ | |
| 139194 | +#endif | |
| 139448 | 139195 | |
| 139449 | 139196 | /* |
| 139450 | 139197 | ** An instance of the WhereScan object is used as an iterator for locating |
| 139451 | 139198 | ** terms in the WHERE clause that are useful to the query planner. |
| 139452 | 139199 | */ |
| @@ -139557,17 +139304,20 @@ | ||
| 139557 | 139304 | WhereOrSet *pOrSet; /* Record best loops here, if not NULL */ |
| 139558 | 139305 | #ifdef SQLITE_ENABLE_STAT4 |
| 139559 | 139306 | UnpackedRecord *pRec; /* Probe for stat4 (if required) */ |
| 139560 | 139307 | int nRecValid; /* Number of valid fields currently in pRec */ |
| 139561 | 139308 | #endif |
| 139562 | - unsigned int bldFlags; /* SQLITE_BLDF_* flags */ | |
| 139309 | + unsigned char bldFlags1; /* First set of SQLITE_BLDF_* flags */ | |
| 139310 | + unsigned char bldFlags2; /* Second set of SQLITE_BLDF_* flags */ | |
| 139563 | 139311 | unsigned int iPlanLimit; /* Search limiter */ |
| 139564 | 139312 | }; |
| 139565 | 139313 | |
| 139566 | 139314 | /* Allowed values for WhereLoopBuider.bldFlags */ |
| 139567 | -#define SQLITE_BLDF_INDEXED 0x0001 /* An index is used */ | |
| 139568 | -#define SQLITE_BLDF_UNIQUE 0x0002 /* All keys of a UNIQUE index used */ | |
| 139315 | +#define SQLITE_BLDF1_INDEXED 0x0001 /* An index is used */ | |
| 139316 | +#define SQLITE_BLDF1_UNIQUE 0x0002 /* All keys of a UNIQUE index used */ | |
| 139317 | + | |
| 139318 | +#define SQLITE_BLDF2_2NDPASS 0x0004 /* Second builder pass needed */ | |
| 139569 | 139319 | |
| 139570 | 139320 | /* The WhereLoopBuilder.iPlanLimit is used to limit the number of |
| 139571 | 139321 | ** index+constraint combinations the query planner will consider for a |
| 139572 | 139322 | ** particular query. If this parameter is unlimited, then certain |
| 139573 | 139323 | ** pathological queries can spend excess time in the sqlite3WhereBegin() |
| @@ -141177,11 +140927,13 @@ | ||
| 141177 | 140927 | if( pCompare ){ |
| 141178 | 140928 | pCompare->pLeft = pTerm->pExpr->pLeft; |
| 141179 | 140929 | pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0); |
| 141180 | 140930 | if( pRight ){ |
| 141181 | 140931 | pRight->iTable = iReg+j+2; |
| 141182 | - sqlite3ExprIfFalse(pParse, pCompare, pLevel->addrCont, 0); | |
| 140932 | + sqlite3ExprIfFalse( | |
| 140933 | + pParse, pCompare, pLevel->addrCont, SQLITE_JUMPIFNULL | |
| 140934 | + ); | |
| 141183 | 140935 | } |
| 141184 | 140936 | pCompare->pLeft = 0; |
| 141185 | 140937 | sqlite3ExprDelete(db, pCompare); |
| 141186 | 140938 | } |
| 141187 | 140939 | } |
| @@ -142591,11 +142343,12 @@ | ||
| 142591 | 142343 | ** |
| 142592 | 142344 | ** vtab_column MATCH expression |
| 142593 | 142345 | ** MATCH(expression,vtab_column) |
| 142594 | 142346 | */ |
| 142595 | 142347 | pCol = pList->a[1].pExpr; |
| 142596 | - if( pCol->op==TK_COLUMN && IsVirtual(pCol->y.pTab) ){ | |
| 142348 | + testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 ); | |
| 142349 | + if( ExprIsVtab(pCol) ){ | |
| 142597 | 142350 | for(i=0; i<ArraySize(aOp); i++){ |
| 142598 | 142351 | if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){ |
| 142599 | 142352 | *peOp2 = aOp[i].eOp2; |
| 142600 | 142353 | *ppRight = pList->a[0].pExpr; |
| 142601 | 142354 | *ppLeft = pCol; |
| @@ -142613,11 +142366,12 @@ | ||
| 142613 | 142366 | ** Historically, xFindFunction expected to see lower-case function |
| 142614 | 142367 | ** names. But for this use case, xFindFunction is expected to deal |
| 142615 | 142368 | ** with function names in an arbitrary case. |
| 142616 | 142369 | */ |
| 142617 | 142370 | pCol = pList->a[0].pExpr; |
| 142618 | - if( pCol->op==TK_COLUMN && IsVirtual(pCol->y.pTab) ){ | |
| 142371 | + testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 ); | |
| 142372 | + if( ExprIsVtab(pCol) ){ | |
| 142619 | 142373 | sqlite3_vtab *pVtab; |
| 142620 | 142374 | sqlite3_module *pMod; |
| 142621 | 142375 | void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**); |
| 142622 | 142376 | void *pNotUsed; |
| 142623 | 142377 | pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab; |
| @@ -142636,14 +142390,16 @@ | ||
| 142636 | 142390 | } |
| 142637 | 142391 | }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){ |
| 142638 | 142392 | int res = 0; |
| 142639 | 142393 | Expr *pLeft = pExpr->pLeft; |
| 142640 | 142394 | Expr *pRight = pExpr->pRight; |
| 142641 | - if( pLeft->op==TK_COLUMN && IsVirtual(pLeft->y.pTab) ){ | |
| 142395 | + testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 ); | |
| 142396 | + if( ExprIsVtab(pLeft) ){ | |
| 142642 | 142397 | res++; |
| 142643 | 142398 | } |
| 142644 | - if( pRight && pRight->op==TK_COLUMN && IsVirtual(pRight->y.pTab) ){ | |
| 142399 | + testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 ); | |
| 142400 | + if( pRight && ExprIsVtab(pRight) ){ | |
| 142645 | 142401 | res++; |
| 142646 | 142402 | SWAP(Expr*, pLeft, pRight); |
| 142647 | 142403 | } |
| 142648 | 142404 | *ppLeft = pLeft; |
| 142649 | 142405 | *ppRight = pRight; |
| @@ -146123,20 +145879,25 @@ | ||
| 146123 | 145879 | pLoop->nOut += pTerm->truthProb; |
| 146124 | 145880 | }else{ |
| 146125 | 145881 | /* In the absence of explicit truth probabilities, use heuristics to |
| 146126 | 145882 | ** guess a reasonable truth probability. */ |
| 146127 | 145883 | pLoop->nOut--; |
| 146128 | - if( pTerm->eOperator&(WO_EQ|WO_IS) ){ | |
| 145884 | + if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 | |
| 145885 | + && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */ | |
| 145886 | + ){ | |
| 146129 | 145887 | Expr *pRight = pTerm->pExpr->pRight; |
| 146130 | 145888 | int k = 0; |
| 146131 | 145889 | testcase( pTerm->pExpr->op==TK_IS ); |
| 146132 | 145890 | if( sqlite3ExprIsInteger(pRight, &k) && k>=(-1) && k<=1 ){ |
| 146133 | 145891 | k = 10; |
| 146134 | 145892 | }else{ |
| 146135 | 145893 | k = 20; |
| 146136 | 145894 | } |
| 146137 | - if( iReduce<k ) iReduce = k; | |
| 145895 | + if( iReduce<k ){ | |
| 145896 | + pTerm->wtFlags |= TERM_HEURTRUTH; | |
| 145897 | + iReduce = k; | |
| 145898 | + } | |
| 146138 | 145899 | } |
| 146139 | 145900 | } |
| 146140 | 145901 | } |
| 146141 | 145902 | } |
| 146142 | 145903 | if( pLoop->nOut > nRow-iReduce ) pLoop->nOut = nRow - iReduce; |
| @@ -146314,13 +146075,13 @@ | ||
| 146314 | 146075 | ){ |
| 146315 | 146076 | continue; |
| 146316 | 146077 | } |
| 146317 | 146078 | |
| 146318 | 146079 | if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){ |
| 146319 | - pBuilder->bldFlags |= SQLITE_BLDF_UNIQUE; | |
| 146080 | + pBuilder->bldFlags1 |= SQLITE_BLDF1_UNIQUE; | |
| 146320 | 146081 | }else{ |
| 146321 | - pBuilder->bldFlags |= SQLITE_BLDF_INDEXED; | |
| 146082 | + pBuilder->bldFlags1 |= SQLITE_BLDF1_INDEXED; | |
| 146322 | 146083 | } |
| 146323 | 146084 | pNew->wsFlags = saved_wsFlags; |
| 146324 | 146085 | pNew->u.btree.nEq = saved_nEq; |
| 146325 | 146086 | pNew->u.btree.nBtm = saved_nBtm; |
| 146326 | 146087 | pNew->u.btree.nTop = saved_nTop; |
| @@ -146481,10 +146242,31 @@ | ||
| 146481 | 146242 | } |
| 146482 | 146243 | if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; |
| 146483 | 146244 | if( rc!=SQLITE_OK ) break; /* Jump out of the pTerm loop */ |
| 146484 | 146245 | if( nOut ){ |
| 146485 | 146246 | pNew->nOut = sqlite3LogEst(nOut); |
| 146247 | + if( nEq==1 | |
| 146248 | + /* TUNING: Mark terms as "low selectivity" if they seem likely | |
| 146249 | + ** to be true for half or more of the rows in the table. | |
| 146250 | + ** See tag-202002240-1 */ | |
| 146251 | + && pNew->nOut+10 > pProbe->aiRowLogEst[0] | |
| 146252 | + ){ | |
| 146253 | +#if WHERETRACE_ENABLED /* 0x01 */ | |
| 146254 | + if( sqlite3WhereTrace & 0x01 ){ | |
| 146255 | + sqlite3DebugPrintf( | |
| 146256 | + "STAT4 determines term has low selectivity:\n"); | |
| 146257 | + sqlite3WhereTermPrint(pTerm, 999); | |
| 146258 | + } | |
| 146259 | +#endif | |
| 146260 | + pTerm->wtFlags |= TERM_HIGHTRUTH; | |
| 146261 | + if( pTerm->wtFlags & TERM_HEURTRUTH ){ | |
| 146262 | + /* If the term has previously been used with an assumption of | |
| 146263 | + ** higher selectivity, then set the flag to rerun the | |
| 146264 | + ** loop computations. */ | |
| 146265 | + pBuilder->bldFlags2 |= SQLITE_BLDF2_2NDPASS; | |
| 146266 | + } | |
| 146267 | + } | |
| 146486 | 146268 | if( pNew->nOut>saved_nOut ) pNew->nOut = saved_nOut; |
| 146487 | 146269 | pNew->nOut -= nIn; |
| 146488 | 146270 | } |
| 146489 | 146271 | } |
| 146490 | 146272 | if( nOut==0 ) |
| @@ -146557,10 +146339,11 @@ | ||
| 146557 | 146339 | assert( 42==sqlite3LogEst(18) ); |
| 146558 | 146340 | if( saved_nEq==saved_nSkip |
| 146559 | 146341 | && saved_nEq+1<pProbe->nKeyCol |
| 146560 | 146342 | && saved_nEq==pNew->nLTerm |
| 146561 | 146343 | && pProbe->noSkipScan==0 |
| 146344 | + && pProbe->hasStat1!=0 | |
| 146562 | 146345 | && OptimizationEnabled(db, SQLITE_SkipScan) |
| 146563 | 146346 | && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */ |
| 146564 | 146347 | && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK |
| 146565 | 146348 | ){ |
| 146566 | 146349 | LogEst nIter; |
| @@ -146904,13 +146687,13 @@ | ||
| 146904 | 146687 | pNew->nOut = rSize; |
| 146905 | 146688 | if( rc ) break; |
| 146906 | 146689 | } |
| 146907 | 146690 | } |
| 146908 | 146691 | |
| 146909 | - pBuilder->bldFlags = 0; | |
| 146692 | + pBuilder->bldFlags1 = 0; | |
| 146910 | 146693 | rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0); |
| 146911 | - if( pBuilder->bldFlags==SQLITE_BLDF_INDEXED ){ | |
| 146694 | + if( pBuilder->bldFlags1==SQLITE_BLDF1_INDEXED ){ | |
| 146912 | 146695 | /* If a non-unique index is used, or if a prefix of the key for |
| 146913 | 146696 | ** unique index is used (making the index functionally non-unique) |
| 146914 | 146697 | ** then the sqlite_stat1 data becomes important for scoring the |
| 146915 | 146698 | ** plan */ |
| 146916 | 146699 | pTab->tabFlags |= TF_StatsUsed; |
| @@ -147577,12 +147360,15 @@ | ||
| 147577 | 147360 | assert( wctrlFlags & WHERE_ORDERBY_LIMIT ); |
| 147578 | 147361 | for(j=0; j<pLoop->nLTerm && pTerm!=pLoop->aLTerm[j]; j++){} |
| 147579 | 147362 | if( j>=pLoop->nLTerm ) continue; |
| 147580 | 147363 | } |
| 147581 | 147364 | if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 && pOBExpr->iColumn>=0 ){ |
| 147582 | - if( sqlite3ExprCollSeqMatch(pWInfo->pParse, | |
| 147583 | - pOrderBy->a[i].pExpr, pTerm->pExpr)==0 ){ | |
| 147365 | + Parse *pParse = pWInfo->pParse; | |
| 147366 | + CollSeq *pColl1 = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[i].pExpr); | |
| 147367 | + CollSeq *pColl2 = sqlite3ExprCompareCollSeq(pParse, pTerm->pExpr); | |
| 147368 | + assert( pColl1 ); | |
| 147369 | + if( pColl2==0 || sqlite3StrICmp(pColl1->zName, pColl2->zName) ){ | |
| 147584 | 147370 | continue; |
| 147585 | 147371 | } |
| 147586 | 147372 | testcase( pTerm->pExpr->op==TK_IS ); |
| 147587 | 147373 | } |
| 147588 | 147374 | obSat |= MASKBIT(i); |
| @@ -148358,10 +148144,32 @@ | ||
| 148358 | 148144 | w.xSelectCallback = sqlite3SelectWalkFail; |
| 148359 | 148145 | sqlite3WalkExpr(&w, p); |
| 148360 | 148146 | return w.eCode; |
| 148361 | 148147 | } |
| 148362 | 148148 | |
| 148149 | + | |
| 148150 | +#ifdef WHERETRACE_ENABLED | |
| 148151 | +/* | |
| 148152 | +** Display all WhereLoops in pWInfo | |
| 148153 | +*/ | |
| 148154 | +static void showAllWhereLoops(WhereInfo *pWInfo, WhereClause *pWC){ | |
| 148155 | + if( sqlite3WhereTrace ){ /* Display all of the WhereLoop objects */ | |
| 148156 | + WhereLoop *p; | |
| 148157 | + int i; | |
| 148158 | + static const char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz" | |
| 148159 | + "ABCDEFGHIJKLMNOPQRSTUVWYXZ"; | |
| 148160 | + for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){ | |
| 148161 | + p->cId = zLabel[i%(sizeof(zLabel)-1)]; | |
| 148162 | + sqlite3WhereLoopPrint(p, pWC); | |
| 148163 | + } | |
| 148164 | + } | |
| 148165 | +} | |
| 148166 | +# define WHERETRACE_ALL_LOOPS(W,C) showAllWhereLoops(W,C) | |
| 148167 | +#else | |
| 148168 | +# define WHERETRACE_ALL_LOOPS(W,C) | |
| 148169 | +#endif | |
| 148170 | + | |
| 148363 | 148171 | /* |
| 148364 | 148172 | ** Generate the beginning of the loop used for WHERE clause processing. |
| 148365 | 148173 | ** The return value is a pointer to an opaque structure that contains |
| 148366 | 148174 | ** information needed to terminate the loop. Later, the calling routine |
| 148367 | 148175 | ** should invoke sqlite3WhereEnd() with the return value of this function |
| @@ -148659,23 +148467,32 @@ | ||
| 148659 | 148467 | #endif |
| 148660 | 148468 | |
| 148661 | 148469 | if( nTabList!=1 || whereShortCut(&sWLB)==0 ){ |
| 148662 | 148470 | rc = whereLoopAddAll(&sWLB); |
| 148663 | 148471 | if( rc ) goto whereBeginError; |
| 148664 | - | |
| 148665 | -#ifdef WHERETRACE_ENABLED | |
| 148666 | - if( sqlite3WhereTrace ){ /* Display all of the WhereLoop objects */ | |
| 148667 | - WhereLoop *p; | |
| 148668 | - int i; | |
| 148669 | - static const char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz" | |
| 148670 | - "ABCDEFGHIJKLMNOPQRSTUVWYXZ"; | |
| 148671 | - for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){ | |
| 148672 | - p->cId = zLabel[i%(sizeof(zLabel)-1)]; | |
| 148673 | - sqlite3WhereLoopPrint(p, sWLB.pWC); | |
| 148674 | - } | |
| 148472 | + | |
| 148473 | +#ifdef SQLITE_ENABLE_STAT4 | |
| 148474 | + /* If one or more WhereTerm.truthProb values were used in estimating | |
| 148475 | + ** loop parameters, but then those truthProb values were subsequently | |
| 148476 | + ** changed based on STAT4 information while computing subsequent loops, | |
| 148477 | + ** then we need to rerun the whole loop building process so that all | |
| 148478 | + ** loops will be built using the revised truthProb values. */ | |
| 148479 | + if( sWLB.bldFlags2 & SQLITE_BLDF2_2NDPASS ){ | |
| 148480 | + WHERETRACE_ALL_LOOPS(pWInfo, sWLB.pWC); | |
| 148481 | + WHERETRACE(0xffff, | |
| 148482 | + ("**** Redo all loop computations due to" | |
| 148483 | + " TERM_HIGHTRUTH changes ****\n")); | |
| 148484 | + while( pWInfo->pLoops ){ | |
| 148485 | + WhereLoop *p = pWInfo->pLoops; | |
| 148486 | + pWInfo->pLoops = p->pNextLoop; | |
| 148487 | + whereLoopDelete(db, p); | |
| 148488 | + } | |
| 148489 | + rc = whereLoopAddAll(&sWLB); | |
| 148490 | + if( rc ) goto whereBeginError; | |
| 148675 | 148491 | } |
| 148676 | 148492 | #endif |
| 148493 | + WHERETRACE_ALL_LOOPS(pWInfo, sWLB.pWC); | |
| 148677 | 148494 | |
| 148678 | 148495 | wherePathSolver(pWInfo, 0); |
| 148679 | 148496 | if( db->mallocFailed ) goto whereBeginError; |
| 148680 | 148497 | if( pWInfo->pOrderBy ){ |
| 148681 | 148498 | wherePathSolver(pWInfo, pWInfo->nRowOut+1); |
| @@ -156496,10 +156313,16 @@ | ||
| 156496 | 156313 | ** simplify to constants 0 (false) and 1 (true), respectively, |
| 156497 | 156314 | ** regardless of the value of expr1. |
| 156498 | 156315 | */ |
| 156499 | 156316 | sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy202); |
| 156500 | 156317 | yymsp[-4].minor.yy202 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy192 ? "1" : "0"); |
| 156318 | + }else if( 0 && yymsp[-1].minor.yy242->nExpr==1 && sqlite3ExprIsConstant(yymsp[-1].minor.yy242->a[0].pExpr) ){ | |
| 156319 | + Expr *pRHS = yymsp[-1].minor.yy242->a[0].pExpr; | |
| 156320 | + yymsp[-1].minor.yy242->a[0].pExpr = 0; | |
| 156321 | + sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy242); | |
| 156322 | + yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_EQ, yymsp[-4].minor.yy202, pRHS); | |
| 156323 | + if( yymsp[-3].minor.yy192 ) yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy202, 0); | |
| 156501 | 156324 | }else{ |
| 156502 | 156325 | yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy202, 0); |
| 156503 | 156326 | if( yymsp[-4].minor.yy202 ){ |
| 156504 | 156327 | yymsp[-4].minor.yy202->x.pList = yymsp[-1].minor.yy242; |
| 156505 | 156328 | sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy202); |
| @@ -157767,16 +157590,21 @@ | ||
| 157767 | 157590 | const char *zKW; |
| 157768 | 157591 | if( n>=2 ){ |
| 157769 | 157592 | i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n) % 127; |
| 157770 | 157593 | for(i=((int)aKWHash[i])-1; i>=0; i=((int)aKWNext[i])-1){ |
| 157771 | 157594 | if( aKWLen[i]!=n ) continue; |
| 157772 | - j = 0; | |
| 157773 | 157595 | zKW = &zKWText[aKWOffset[i]]; |
| 157774 | 157596 | #ifdef SQLITE_ASCII |
| 157597 | + if( (z[0]&~0x20)!=zKW[0] ) continue; | |
| 157598 | + if( (z[1]&~0x20)!=zKW[1] ) continue; | |
| 157599 | + j = 2; | |
| 157775 | 157600 | while( j<n && (z[j]&~0x20)==zKW[j] ){ j++; } |
| 157776 | 157601 | #endif |
| 157777 | 157602 | #ifdef SQLITE_EBCDIC |
| 157603 | + if( toupper(z[0])!=zKW[0] ) continue; | |
| 157604 | + if( toupper(z[1])!=zKW[1] ) continue; | |
| 157605 | + j = 2; | |
| 157778 | 157606 | while( j<n && toupper(z[j])==zKW[j] ){ j++; } |
| 157779 | 157607 | #endif |
| 157780 | 157608 | if( j<n ) continue; |
| 157781 | 157609 | testcase( i==0 ); /* REINDEX */ |
| 157782 | 157610 | testcase( i==1 ); /* INDEXED */ |
| @@ -159218,11 +159046,14 @@ | ||
| 159218 | 159046 | /* If SQLite is already completely initialized, then this call |
| 159219 | 159047 | ** to sqlite3_initialize() should be a no-op. But the initialization |
| 159220 | 159048 | ** must be complete. So isInit must not be set until the very end |
| 159221 | 159049 | ** of this routine. |
| 159222 | 159050 | */ |
| 159223 | - if( sqlite3GlobalConfig.isInit ) return SQLITE_OK; | |
| 159051 | + if( sqlite3GlobalConfig.isInit ){ | |
| 159052 | + sqlite3MemoryBarrier(); | |
| 159053 | + return SQLITE_OK; | |
| 159054 | + } | |
| 159224 | 159055 | |
| 159225 | 159056 | /* Make sure the mutex subsystem is initialized. If unable to |
| 159226 | 159057 | ** initialize the mutex subsystem, return early with the error. |
| 159227 | 159058 | ** If the system is so sick that we are unable to allocate a mutex, |
| 159228 | 159059 | ** there is not much SQLite is going to be able to do. |
| @@ -161807,13 +161638,15 @@ | ||
| 161807 | 161638 | ** *pFlags may be updated before returning if the URI filename contains |
| 161808 | 161639 | ** "cache=xxx" or "mode=xxx" query parameters. |
| 161809 | 161640 | ** |
| 161810 | 161641 | ** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to |
| 161811 | 161642 | ** the VFS that should be used to open the database file. *pzFile is set to |
| 161812 | -** point to a buffer containing the name of the file to open. It is the | |
| 161813 | -** responsibility of the caller to eventually call sqlite3_free() to release | |
| 161814 | -** this buffer. | |
| 161643 | +** point to a buffer containing the name of the file to open. The value | |
| 161644 | +** stored in *pzFile is a database name acceptable to sqlite3_uri_parameter() | |
| 161645 | +** and is in the same format as names created using sqlite3_create_filename(). | |
| 161646 | +** The caller must invoke sqlite3_free_filename() (not sqlite3_free()!) on | |
| 161647 | +** the value returned in *pzFile to avoid a memory leak. | |
| 161815 | 161648 | ** |
| 161816 | 161649 | ** If an error occurs, then an SQLite error code is returned and *pzErrMsg |
| 161817 | 161650 | ** may be set to point to a buffer containing an English language error |
| 161818 | 161651 | ** message. It is the responsibility of the caller to eventually release |
| 161819 | 161652 | ** this buffer by calling sqlite3_free(). |
| @@ -161841,19 +161674,22 @@ | ||
| 161841 | 161674 | ){ |
| 161842 | 161675 | char *zOpt; |
| 161843 | 161676 | int eState; /* Parser state when parsing URI */ |
| 161844 | 161677 | int iIn; /* Input character index */ |
| 161845 | 161678 | int iOut = 0; /* Output character index */ |
| 161846 | - u64 nByte = nUri+2; /* Bytes of space to allocate */ | |
| 161679 | + u64 nByte = nUri+8; /* Bytes of space to allocate */ | |
| 161847 | 161680 | |
| 161848 | 161681 | /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen |
| 161849 | 161682 | ** method that there may be extra parameters following the file-name. */ |
| 161850 | 161683 | flags |= SQLITE_OPEN_URI; |
| 161851 | 161684 | |
| 161852 | 161685 | for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&'); |
| 161853 | 161686 | zFile = sqlite3_malloc64(nByte); |
| 161854 | 161687 | if( !zFile ) return SQLITE_NOMEM_BKPT; |
| 161688 | + | |
| 161689 | + memset(zFile, 0, 4); /* 4-byte of 0x00 is the start of DB name marker */ | |
| 161690 | + zFile += 4; | |
| 161855 | 161691 | |
| 161856 | 161692 | iIn = 5; |
| 161857 | 161693 | #ifdef SQLITE_ALLOW_URI_AUTHORITY |
| 161858 | 161694 | if( strncmp(zUri+5, "///", 3)==0 ){ |
| 161859 | 161695 | iIn = 7; |
| @@ -161940,12 +161776,11 @@ | ||
| 161940 | 161776 | eState = 1; |
| 161941 | 161777 | } |
| 161942 | 161778 | zFile[iOut++] = c; |
| 161943 | 161779 | } |
| 161944 | 161780 | if( eState==1 ) zFile[iOut++] = '\0'; |
| 161945 | - zFile[iOut++] = '\0'; | |
| 161946 | - zFile[iOut++] = '\0'; | |
| 161781 | + memset(zFile+iOut, 0, 4); /* end-of-options + empty journal filenames */ | |
| 161947 | 161782 | |
| 161948 | 161783 | /* Check if there were any options specified that should be interpreted |
| 161949 | 161784 | ** here. Options that are interpreted here include "vfs" and those that |
| 161950 | 161785 | ** correspond to flags that may be passed to the sqlite3_open_v2() |
| 161951 | 161786 | ** method. */ |
| @@ -162021,17 +161856,18 @@ | ||
| 162021 | 161856 | |
| 162022 | 161857 | zOpt = &zVal[nVal+1]; |
| 162023 | 161858 | } |
| 162024 | 161859 | |
| 162025 | 161860 | }else{ |
| 162026 | - zFile = sqlite3_malloc64(nUri+2); | |
| 161861 | + zFile = sqlite3_malloc64(nUri+8); | |
| 162027 | 161862 | if( !zFile ) return SQLITE_NOMEM_BKPT; |
| 161863 | + memset(zFile, 0, 4); | |
| 161864 | + zFile += 4; | |
| 162028 | 161865 | if( nUri ){ |
| 162029 | 161866 | memcpy(zFile, zUri, nUri); |
| 162030 | 161867 | } |
| 162031 | - zFile[nUri] = '\0'; | |
| 162032 | - zFile[nUri+1] = '\0'; | |
| 161868 | + memset(zFile+nUri, 0, 4); | |
| 162033 | 161869 | flags &= ~SQLITE_OPEN_URI; |
| 162034 | 161870 | } |
| 162035 | 161871 | |
| 162036 | 161872 | *ppVfs = sqlite3_vfs_find(zVfs); |
| 162037 | 161873 | if( *ppVfs==0 ){ |
| @@ -162038,51 +161874,33 @@ | ||
| 162038 | 161874 | *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs); |
| 162039 | 161875 | rc = SQLITE_ERROR; |
| 162040 | 161876 | } |
| 162041 | 161877 | parse_uri_out: |
| 162042 | 161878 | if( rc!=SQLITE_OK ){ |
| 162043 | - sqlite3_free(zFile); | |
| 161879 | + sqlite3_free_filename(zFile); | |
| 162044 | 161880 | zFile = 0; |
| 162045 | 161881 | } |
| 162046 | 161882 | *pFlags = flags; |
| 162047 | 161883 | *pzFile = zFile; |
| 162048 | 161884 | return rc; |
| 162049 | 161885 | } |
| 162050 | 161886 | |
| 162051 | -#if defined(SQLITE_HAS_CODEC) | |
| 162052 | 161887 | /* |
| 162053 | -** Process URI filename query parameters relevant to the SQLite Encryption | |
| 162054 | -** Extension. Return true if any of the relevant query parameters are | |
| 162055 | -** seen and return false if not. | |
| 161888 | +** This routine does the core work of extracting URI parameters from a | |
| 161889 | +** database filename for the sqlite3_uri_parameter() interface. | |
| 162056 | 161890 | */ |
| 162057 | -SQLITE_PRIVATE int sqlite3CodecQueryParameters( | |
| 162058 | - sqlite3 *db, /* Database connection */ | |
| 162059 | - const char *zDb, /* Which schema is being created/attached */ | |
| 162060 | - const char *zUri /* URI filename */ | |
| 162061 | -){ | |
| 162062 | - const char *zKey; | |
| 162063 | - if( (zKey = sqlite3_uri_parameter(zUri, "hexkey"))!=0 && zKey[0] ){ | |
| 162064 | - u8 iByte; | |
| 162065 | - int i; | |
| 162066 | - char zDecoded[40]; | |
| 162067 | - for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){ | |
| 162068 | - iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]); | |
| 162069 | - if( (i&1)!=0 ) zDecoded[i/2] = iByte; | |
| 162070 | - } | |
| 162071 | - sqlite3_key_v2(db, zDb, zDecoded, i/2); | |
| 162072 | - return 1; | |
| 162073 | - }else if( (zKey = sqlite3_uri_parameter(zUri, "key"))!=0 ){ | |
| 162074 | - sqlite3_key_v2(db, zDb, zKey, sqlite3Strlen30(zKey)); | |
| 162075 | - return 1; | |
| 162076 | - }else if( (zKey = sqlite3_uri_parameter(zUri, "textkey"))!=0 ){ | |
| 162077 | - sqlite3_key_v2(db, zDb, zKey, -1); | |
| 162078 | - return 1; | |
| 162079 | - }else{ | |
| 162080 | - return 0; | |
| 162081 | - } | |
| 162082 | -} | |
| 162083 | -#endif | |
| 161891 | +static const char *uriParameter(const char *zFilename, const char *zParam){ | |
| 161892 | + zFilename += sqlite3Strlen30(zFilename) + 1; | |
| 161893 | + while( zFilename[0] ){ | |
| 161894 | + int x = strcmp(zFilename, zParam); | |
| 161895 | + zFilename += sqlite3Strlen30(zFilename) + 1; | |
| 161896 | + if( x==0 ) return zFilename; | |
| 161897 | + zFilename += sqlite3Strlen30(zFilename) + 1; | |
| 161898 | + } | |
| 161899 | + return 0; | |
| 161900 | +} | |
| 161901 | + | |
| 162084 | 161902 | |
| 162085 | 161903 | |
| 162086 | 161904 | /* |
| 162087 | 161905 | ** This routine does the work of opening a database on behalf of |
| 162088 | 161906 | ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename" |
| @@ -162463,14 +162281,11 @@ | ||
| 162463 | 162281 | /* Opening a db handle. Fourth parameter is passed 0. */ |
| 162464 | 162282 | void *pArg = sqlite3GlobalConfig.pSqllogArg; |
| 162465 | 162283 | sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0); |
| 162466 | 162284 | } |
| 162467 | 162285 | #endif |
| 162468 | -#if defined(SQLITE_HAS_CODEC) | |
| 162469 | - if( rc==SQLITE_OK ) sqlite3CodecQueryParameters(db, 0, zOpen); | |
| 162470 | -#endif | |
| 162471 | - sqlite3_free(zOpen); | |
| 162286 | + sqlite3_free_filename(zOpen); | |
| 162472 | 162287 | return rc & 0xff; |
| 162473 | 162288 | } |
| 162474 | 162289 | |
| 162475 | 162290 | |
| 162476 | 162291 | /* |
| @@ -162693,17 +162508,19 @@ | ||
| 162693 | 162508 | } |
| 162694 | 162509 | SQLITE_PRIVATE int sqlite3CantopenError(int lineno){ |
| 162695 | 162510 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 162696 | 162511 | return sqlite3ReportError(SQLITE_CANTOPEN, lineno, "cannot open file"); |
| 162697 | 162512 | } |
| 162698 | -#ifdef SQLITE_DEBUG | |
| 162513 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_CORRUPT_PGNO) | |
| 162699 | 162514 | SQLITE_PRIVATE int sqlite3CorruptPgnoError(int lineno, Pgno pgno){ |
| 162700 | 162515 | char zMsg[100]; |
| 162701 | 162516 | sqlite3_snprintf(sizeof(zMsg), zMsg, "database corruption page %d", pgno); |
| 162702 | 162517 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 162703 | 162518 | return sqlite3ReportError(SQLITE_CORRUPT, lineno, zMsg); |
| 162704 | 162519 | } |
| 162520 | +#endif | |
| 162521 | +#ifdef SQLITE_DEBUG | |
| 162705 | 162522 | SQLITE_PRIVATE int sqlite3NomemError(int lineno){ |
| 162706 | 162523 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 162707 | 162524 | return sqlite3ReportError(SQLITE_NOMEM, lineno, "OOM"); |
| 162708 | 162525 | } |
| 162709 | 162526 | SQLITE_PRIVATE int sqlite3IoerrnomemError(int lineno){ |
| @@ -163314,10 +163131,72 @@ | ||
| 163314 | 163131 | while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){ |
| 163315 | 163132 | zName--; |
| 163316 | 163133 | } |
| 163317 | 163134 | return zName; |
| 163318 | 163135 | } |
| 163136 | + | |
| 163137 | +/* | |
| 163138 | +** Append text z[] to the end of p[]. Return a pointer to the first | |
| 163139 | +** character after then zero terminator on the new text in p[]. | |
| 163140 | +*/ | |
| 163141 | +static char *appendText(char *p, const char *z){ | |
| 163142 | + size_t n = strlen(z); | |
| 163143 | + memcpy(p, z, n+1); | |
| 163144 | + return p+n+1; | |
| 163145 | +} | |
| 163146 | + | |
| 163147 | +/* | |
| 163148 | +** Allocate memory to hold names for a database, journal file, WAL file, | |
| 163149 | +** and query parameters. The pointer returned is valid for use by | |
| 163150 | +** sqlite3_filename_database() and sqlite3_uri_parameter() and related | |
| 163151 | +** functions. | |
| 163152 | +** | |
| 163153 | +** Memory layout must be compatible with that generated by the pager | |
| 163154 | +** and expected by sqlite3_uri_parameter() and databaseName(). | |
| 163155 | +*/ | |
| 163156 | +SQLITE_API char *sqlite3_create_filename( | |
| 163157 | + const char *zDatabase, | |
| 163158 | + const char *zJournal, | |
| 163159 | + const char *zWal, | |
| 163160 | + int nParam, | |
| 163161 | + const char **azParam | |
| 163162 | +){ | |
| 163163 | + sqlite3_int64 nByte; | |
| 163164 | + int i; | |
| 163165 | + char *pResult, *p; | |
| 163166 | + nByte = strlen(zDatabase) + strlen(zJournal) + strlen(zWal) + 10; | |
| 163167 | + for(i=0; i<nParam*2; i++){ | |
| 163168 | + nByte += strlen(azParam[i])+1; | |
| 163169 | + } | |
| 163170 | + pResult = p = sqlite3_malloc64( nByte ); | |
| 163171 | + if( p==0 ) return 0; | |
| 163172 | + memset(p, 0, 4); | |
| 163173 | + p += 4; | |
| 163174 | + p = appendText(p, zDatabase); | |
| 163175 | + for(i=0; i<nParam*2; i++){ | |
| 163176 | + p = appendText(p, azParam[i]); | |
| 163177 | + } | |
| 163178 | + *(p++) = 0; | |
| 163179 | + p = appendText(p, zJournal); | |
| 163180 | + p = appendText(p, zWal); | |
| 163181 | + *(p++) = 0; | |
| 163182 | + *(p++) = 0; | |
| 163183 | + assert( (sqlite3_int64)(p - pResult)==nByte ); | |
| 163184 | + return pResult + 4; | |
| 163185 | +} | |
| 163186 | + | |
| 163187 | +/* | |
| 163188 | +** Free memory obtained from sqlite3_create_filename(). It is a severe | |
| 163189 | +** error to call this routine with any parameter other than a pointer | |
| 163190 | +** previously obtained from sqlite3_create_filename() or a NULL pointer. | |
| 163191 | +*/ | |
| 163192 | +SQLITE_API void sqlite3_free_filename(char *p){ | |
| 163193 | + if( p==0 ) return; | |
| 163194 | + p = (char*)databaseName(p); | |
| 163195 | + sqlite3_free(p - 4); | |
| 163196 | +} | |
| 163197 | + | |
| 163319 | 163198 | |
| 163320 | 163199 | /* |
| 163321 | 163200 | ** This is a utility routine, useful to VFS implementations, that checks |
| 163322 | 163201 | ** to see if a database file was a URI that contained a specific query |
| 163323 | 163202 | ** parameter, and if so obtains the value of the query parameter. |
| @@ -163329,18 +163208,11 @@ | ||
| 163329 | 163208 | ** returns a NULL pointer. |
| 163330 | 163209 | */ |
| 163331 | 163210 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){ |
| 163332 | 163211 | if( zFilename==0 || zParam==0 ) return 0; |
| 163333 | 163212 | zFilename = databaseName(zFilename); |
| 163334 | - zFilename += sqlite3Strlen30(zFilename) + 1; | |
| 163335 | - while( zFilename[0] ){ | |
| 163336 | - int x = strcmp(zFilename, zParam); | |
| 163337 | - zFilename += sqlite3Strlen30(zFilename) + 1; | |
| 163338 | - if( x==0 ) return zFilename; | |
| 163339 | - zFilename += sqlite3Strlen30(zFilename) + 1; | |
| 163340 | - } | |
| 163341 | - return 0; | |
| 163213 | + return uriParameter(zFilename, zParam); | |
| 163342 | 163214 | } |
| 163343 | 163215 | |
| 163344 | 163216 | /* |
| 163345 | 163217 | ** Return a pointer to the name of Nth query parameter of the filename. |
| 163346 | 163218 | */ |
| @@ -163390,11 +163262,10 @@ | ||
| 163390 | 163262 | ** an error that we cannot easily detect but that will likely cause memory |
| 163391 | 163263 | ** corruption. |
| 163392 | 163264 | */ |
| 163393 | 163265 | SQLITE_API const char *sqlite3_filename_database(const char *zFilename){ |
| 163394 | 163266 | return databaseName(zFilename); |
| 163395 | - return sqlite3_uri_parameter(zFilename - 3, "\003"); | |
| 163396 | 163267 | } |
| 163397 | 163268 | SQLITE_API const char *sqlite3_filename_journal(const char *zFilename){ |
| 163398 | 163269 | zFilename = databaseName(zFilename); |
| 163399 | 163270 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 163400 | 163271 | while( zFilename[0] ){ |
| @@ -174985,11 +174856,11 @@ | ||
| 174985 | 174856 | int nByte = sqlite3_value_bytes(apVal[0]); |
| 174986 | 174857 | pCsr->zInput = sqlite3_malloc64(nByte+1); |
| 174987 | 174858 | if( pCsr->zInput==0 ){ |
| 174988 | 174859 | rc = SQLITE_NOMEM; |
| 174989 | 174860 | }else{ |
| 174990 | - memcpy(pCsr->zInput, zByte, nByte); | |
| 174861 | + if( nByte>0 ) memcpy(pCsr->zInput, zByte, nByte); | |
| 174991 | 174862 | pCsr->zInput[nByte] = 0; |
| 174992 | 174863 | rc = pTab->pMod->xOpen(pTab->pTok, pCsr->zInput, nByte, &pCsr->pCsr); |
| 174993 | 174864 | if( rc==SQLITE_OK ){ |
| 174994 | 174865 | pCsr->pCsr->pTokenizer = pTab->pTok; |
| 174995 | 174866 | } |
| @@ -177595,11 +177466,11 @@ | ||
| 177595 | 177466 | sqlite3_stmt *pStmt; |
| 177596 | 177467 | int rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR_MAX_LEVEL, &pStmt, 0); |
| 177597 | 177468 | if( rc!=SQLITE_OK ) return rc; |
| 177598 | 177469 | sqlite3_bind_int64(pStmt, 1, iAbsLevel+1); |
| 177599 | 177470 | sqlite3_bind_int64(pStmt, 2, |
| 177600 | - ((iAbsLevel/FTS3_SEGDIR_MAXLEVEL)+1) * FTS3_SEGDIR_MAXLEVEL | |
| 177471 | + (((u64)iAbsLevel/FTS3_SEGDIR_MAXLEVEL)+1) * FTS3_SEGDIR_MAXLEVEL | |
| 177601 | 177472 | ); |
| 177602 | 177473 | |
| 177603 | 177474 | *pbMax = 0; |
| 177604 | 177475 | if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 177605 | 177476 | *pbMax = sqlite3_column_type(pStmt, 0)==SQLITE_NULL; |
| @@ -223667,11 +223538,11 @@ | ||
| 223667 | 223538 | int nArg, /* Number of args */ |
| 223668 | 223539 | sqlite3_value **apUnused /* Function arguments */ |
| 223669 | 223540 | ){ |
| 223670 | 223541 | assert( nArg==0 ); |
| 223671 | 223542 | UNUSED_PARAM2(nArg, apUnused); |
| 223672 | - sqlite3_result_text(pCtx, "fts5: 2020-01-28 15:02:23 04885763c4cd00cbca26d048f2b19316bfc93e8edebeceaa171ebfc6c563d53e", -1, SQLITE_TRANSIENT); | |
| 223543 | + sqlite3_result_text(pCtx, "fts5: 2020-02-27 11:32:14 bfb09371d452d5d4dacab2ec476880bc729952f44ac0e5de90ea7ba203243c8c", -1, SQLITE_TRANSIENT); | |
| 223673 | 223544 | } |
| 223674 | 223545 | |
| 223675 | 223546 | /* |
| 223676 | 223547 | ** Return true if zName is the extension on one of the shadow tables used |
| 223677 | 223548 | ** by this module. |
| @@ -227410,10 +227281,11 @@ | ||
| 227410 | 227281 | char *zFts5Tbl; /* Name of fts5 table */ |
| 227411 | 227282 | char *zFts5Db; /* Db containing fts5 table */ |
| 227412 | 227283 | sqlite3 *db; /* Database handle */ |
| 227413 | 227284 | Fts5Global *pGlobal; /* FTS5 global object for this database */ |
| 227414 | 227285 | int eType; /* FTS5_VOCAB_COL, ROW or INSTANCE */ |
| 227286 | + unsigned bBusy; /* True if busy */ | |
| 227415 | 227287 | }; |
| 227416 | 227288 | |
| 227417 | 227289 | struct Fts5VocabCursor { |
| 227418 | 227290 | sqlite3_vtab_cursor base; |
| 227419 | 227291 | sqlite3_stmt *pStmt; /* Statement holding lock on pIndex */ |
| @@ -227692,10 +227564,16 @@ | ||
| 227692 | 227564 | Fts5VocabCursor *pCsr = 0; |
| 227693 | 227565 | int rc = SQLITE_OK; |
| 227694 | 227566 | sqlite3_stmt *pStmt = 0; |
| 227695 | 227567 | char *zSql = 0; |
| 227696 | 227568 | |
| 227569 | + if( pTab->bBusy ){ | |
| 227570 | + pVTab->zErrMsg = sqlite3_mprintf( | |
| 227571 | + "recursive definition for %s.%s", pTab->zFts5Db, pTab->zFts5Tbl | |
| 227572 | + ); | |
| 227573 | + return SQLITE_ERROR; | |
| 227574 | + } | |
| 227697 | 227575 | zSql = sqlite3Fts5Mprintf(&rc, |
| 227698 | 227576 | "SELECT t.%Q FROM %Q.%Q AS t WHERE t.%Q MATCH '*id'", |
| 227699 | 227577 | pTab->zFts5Tbl, pTab->zFts5Db, pTab->zFts5Tbl, pTab->zFts5Tbl |
| 227700 | 227578 | ); |
| 227701 | 227579 | if( zSql ){ |
| @@ -227703,14 +227581,16 @@ | ||
| 227703 | 227581 | } |
| 227704 | 227582 | sqlite3_free(zSql); |
| 227705 | 227583 | assert( rc==SQLITE_OK || pStmt==0 ); |
| 227706 | 227584 | if( rc==SQLITE_ERROR ) rc = SQLITE_OK; |
| 227707 | 227585 | |
| 227586 | + pTab->bBusy = 1; | |
| 227708 | 227587 | if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 227709 | 227588 | i64 iId = sqlite3_column_int64(pStmt, 0); |
| 227710 | 227589 | pFts5 = sqlite3Fts5TableFromCsrid(pTab->pGlobal, iId); |
| 227711 | 227590 | } |
| 227591 | + pTab->bBusy = 0; | |
| 227712 | 227592 | |
| 227713 | 227593 | if( rc==SQLITE_OK ){ |
| 227714 | 227594 | if( pFts5==0 ){ |
| 227715 | 227595 | rc = sqlite3_finalize(pStmt); |
| 227716 | 227596 | pStmt = 0; |
| @@ -228440,12 +228320,12 @@ | ||
| 228440 | 228320 | } |
| 228441 | 228321 | #endif /* SQLITE_CORE */ |
| 228442 | 228322 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 228443 | 228323 | |
| 228444 | 228324 | /************** End of stmt.c ************************************************/ |
| 228445 | -#if __LINE__!=228445 | |
| 228325 | +#if __LINE__!=228325 | |
| 228446 | 228326 | #undef SQLITE_SOURCE_ID |
| 228447 | -#define SQLITE_SOURCE_ID "2020-01-28 15:02:23 04885763c4cd00cbca26d048f2b19316bfc93e8edebeceaa171ebfc6c563alt2" | |
| 228327 | +#define SQLITE_SOURCE_ID "2020-02-27 16:21:39 951b39ca74c9bd933139e099d5555283278db475f410f202c162e5d1e6aealt2" | |
| 228448 | 228328 | #endif |
| 228449 | 228329 | /* Return the source-id for this library */ |
| 228450 | 228330 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 228451 | 228331 | /************************** End of sqlite3.c ******************************/ |
| 228452 | 228332 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.31.1. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -378,13 +378,10 @@ | |
| 378 | "FTS5_ENABLE_TEST_MI", |
| 379 | #endif |
| 380 | #if SQLITE_FTS5_NO_WITHOUT_ROWID |
| 381 | "FTS5_NO_WITHOUT_ROWID", |
| 382 | #endif |
| 383 | #if SQLITE_HAS_CODEC |
| 384 | "HAS_CODEC", |
| 385 | #endif |
| 386 | #if HAVE_ISNAN || SQLITE_HAVE_ISNAN |
| 387 | "HAVE_ISNAN", |
| 388 | #endif |
| 389 | #if SQLITE_HOMEGROWN_RECURSIVE_MUTEX |
| 390 | "HOMEGROWN_RECURSIVE_MUTEX", |
| @@ -1163,13 +1160,13 @@ | |
| 1163 | ** |
| 1164 | ** See also: [sqlite3_libversion()], |
| 1165 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1166 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1167 | */ |
| 1168 | #define SQLITE_VERSION "3.31.1" |
| 1169 | #define SQLITE_VERSION_NUMBER 3031001 |
| 1170 | #define SQLITE_SOURCE_ID "2020-01-28 15:02:23 04885763c4cd00cbca26d048f2b19316bfc93e8edebeceaa171ebfc6c563d53e" |
| 1171 | |
| 1172 | /* |
| 1173 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1174 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1175 | ** |
| @@ -4657,10 +4654,63 @@ | |
| 4657 | */ |
| 4658 | SQLITE_API const char *sqlite3_filename_database(const char*); |
| 4659 | SQLITE_API const char *sqlite3_filename_journal(const char*); |
| 4660 | SQLITE_API const char *sqlite3_filename_wal(const char*); |
| 4661 | |
| 4662 | |
| 4663 | /* |
| 4664 | ** CAPI3REF: Error Codes And Messages |
| 4665 | ** METHOD: sqlite3 |
| 4666 | ** |
| @@ -5239,11 +5289,11 @@ | |
| 5239 | ** occurrences have the same index as the first occurrence. |
| 5240 | ** ^The index for named parameters can be looked up using the |
| 5241 | ** [sqlite3_bind_parameter_index()] API if desired. ^The index |
| 5242 | ** for "?NNN" parameters is the value of NNN. |
| 5243 | ** ^The NNN value must be between 1 and the [sqlite3_limit()] |
| 5244 | ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). |
| 5245 | ** |
| 5246 | ** ^The third argument is the value to bind to the parameter. |
| 5247 | ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
| 5248 | ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter |
| 5249 | ** is ignored and the end result is the same as sqlite3_bind_null(). |
| @@ -6857,55 +6907,10 @@ | |
| 6857 | sqlite3*, |
| 6858 | void*, |
| 6859 | void(*)(void*,sqlite3*,int eTextRep,const void*) |
| 6860 | ); |
| 6861 | |
| 6862 | #ifdef SQLITE_HAS_CODEC |
| 6863 | /* |
| 6864 | ** Specify the key for an encrypted database. This routine should be |
| 6865 | ** called right after sqlite3_open(). |
| 6866 | ** |
| 6867 | ** The code to implement this API is not available in the public release |
| 6868 | ** of SQLite. |
| 6869 | */ |
| 6870 | SQLITE_API int sqlite3_key( |
| 6871 | sqlite3 *db, /* Database to be rekeyed */ |
| 6872 | const void *pKey, int nKey /* The key */ |
| 6873 | ); |
| 6874 | SQLITE_API int sqlite3_key_v2( |
| 6875 | sqlite3 *db, /* Database to be rekeyed */ |
| 6876 | const char *zDbName, /* Name of the database */ |
| 6877 | const void *pKey, int nKey /* The key */ |
| 6878 | ); |
| 6879 | |
| 6880 | /* |
| 6881 | ** Change the key on an open database. If the current database is not |
| 6882 | ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the |
| 6883 | ** database is decrypted. |
| 6884 | ** |
| 6885 | ** The code to implement this API is not available in the public release |
| 6886 | ** of SQLite. |
| 6887 | */ |
| 6888 | SQLITE_API int sqlite3_rekey( |
| 6889 | sqlite3 *db, /* Database to be rekeyed */ |
| 6890 | const void *pKey, int nKey /* The new key */ |
| 6891 | ); |
| 6892 | SQLITE_API int sqlite3_rekey_v2( |
| 6893 | sqlite3 *db, /* Database to be rekeyed */ |
| 6894 | const char *zDbName, /* Name of the database */ |
| 6895 | const void *pKey, int nKey /* The new key */ |
| 6896 | ); |
| 6897 | |
| 6898 | /* |
| 6899 | ** Specify the activation key for a SEE database. Unless |
| 6900 | ** activated, none of the SEE routines will work. |
| 6901 | */ |
| 6902 | SQLITE_API void sqlite3_activate_see( |
| 6903 | const char *zPassPhrase /* Activation phrase */ |
| 6904 | ); |
| 6905 | #endif |
| 6906 | |
| 6907 | #ifdef SQLITE_ENABLE_CEROD |
| 6908 | /* |
| 6909 | ** Specify the activation key for a CEROD database. Unless |
| 6910 | ** activated, none of the CEROD routines will work. |
| 6911 | */ |
| @@ -13270,13 +13275,16 @@ | |
| 13270 | #endif |
| 13271 | |
| 13272 | |
| 13273 | /* |
| 13274 | ** The maximum value of a ?nnn wildcard that the parser will accept. |
| 13275 | */ |
| 13276 | #ifndef SQLITE_MAX_VARIABLE_NUMBER |
| 13277 | # define SQLITE_MAX_VARIABLE_NUMBER 999 |
| 13278 | #endif |
| 13279 | |
| 13280 | /* Maximum page size. The upper bound on this value is 65536. This a limit |
| 13281 | ** imposed by the use of 16-bit offsets within each page. |
| 13282 | ** |
| @@ -15253,12 +15261,12 @@ | |
| 15253 | #define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */ |
| 15254 | #define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */ |
| 15255 | #define OP_IncrVacuum 60 /* jump */ |
| 15256 | #define OP_VNext 61 /* jump */ |
| 15257 | #define OP_Init 62 /* jump, synopsis: Start at P2 */ |
| 15258 | #define OP_PureFunc 63 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 15259 | #define OP_Function 64 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 15260 | #define OP_Return 65 |
| 15261 | #define OP_EndCoroutine 66 |
| 15262 | #define OP_HaltIfNull 67 /* synopsis: if r[P3]=null halt */ |
| 15263 | #define OP_Halt 68 |
| 15264 | #define OP_Integer 69 /* synopsis: r[P2]=P1 */ |
| @@ -15320,12 +15328,12 @@ | |
| 15320 | #define OP_SorterData 125 /* synopsis: r[P2]=data */ |
| 15321 | #define OP_RowData 126 /* synopsis: r[P2]=data */ |
| 15322 | #define OP_Rowid 127 /* synopsis: r[P2]=rowid */ |
| 15323 | #define OP_NullRow 128 |
| 15324 | #define OP_SeekEnd 129 |
| 15325 | #define OP_SorterInsert 130 /* synopsis: key=r[P2] */ |
| 15326 | #define OP_IdxInsert 131 /* synopsis: key=r[P2] */ |
| 15327 | #define OP_IdxDelete 132 /* synopsis: key=r[P2@P3] */ |
| 15328 | #define OP_DeferredSeek 133 /* synopsis: Move P3 to P1.rowid if needed */ |
| 15329 | #define OP_IdxRowid 134 /* synopsis: r[P2]=rowid */ |
| 15330 | #define OP_FinishSeek 135 |
| 15331 | #define OP_Destroy 136 |
| @@ -15475,10 +15483,11 @@ | |
| 15475 | SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1); |
| 15476 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2); |
| 15477 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3); |
| 15478 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5); |
| 15479 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 15480 | SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 15481 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 15482 | #ifdef SQLITE_DEBUG |
| 15483 | SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask, int); |
| 15484 | #else |
| @@ -15770,13 +15779,10 @@ | |
| 15770 | SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); |
| 15771 | |
| 15772 | /* Functions used to configure a Pager object. */ |
| 15773 | SQLITE_PRIVATE void sqlite3PagerSetBusyHandler(Pager*, int(*)(void *), void *); |
| 15774 | SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); |
| 15775 | #ifdef SQLITE_HAS_CODEC |
| 15776 | SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager*,Pager*); |
| 15777 | #endif |
| 15778 | SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int); |
| 15779 | SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int); |
| 15780 | SQLITE_PRIVATE int sqlite3PagerSetSpillsize(Pager*, int); |
| 15781 | SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64); |
| 15782 | SQLITE_PRIVATE void sqlite3PagerShrink(Pager*); |
| @@ -15866,14 +15872,10 @@ | |
| 15866 | /* Functions used to truncate the database file. */ |
| 15867 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno); |
| 15868 | |
| 15869 | SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16); |
| 15870 | |
| 15871 | #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL) |
| 15872 | SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *); |
| 15873 | #endif |
| 15874 | |
| 15875 | /* Functions to support testing and debugging. */ |
| 15876 | #if !defined(NDEBUG) || defined(SQLITE_TEST) |
| 15877 | SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*); |
| 15878 | SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*); |
| 15879 | #endif |
| @@ -17426,12 +17428,15 @@ | |
| 17426 | ** done as a macro so that it will be optimized out when virtual |
| 17427 | ** table support is omitted from the build. |
| 17428 | */ |
| 17429 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 17430 | # define IsVirtual(X) ((X)->nModuleArg) |
| 17431 | #else |
| 17432 | # define IsVirtual(X) 0 |
| 17433 | #endif |
| 17434 | |
| 17435 | /* |
| 17436 | ** Macros to determine if a column is hidden. IsOrdinaryHiddenColumn() |
| 17437 | ** only works for non-virtual tables (ordinary tables and views) and is |
| @@ -17785,14 +17790,14 @@ | |
| 17785 | ** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater |
| 17786 | ** than 32767 we have to make it 32-bit. 16-bit is preferred because |
| 17787 | ** it uses less memory in the Expr object, which is a big memory user |
| 17788 | ** in systems with lots of prepared statements. And few applications |
| 17789 | ** need more than about 10 or 20 variables. But some extreme users want |
| 17790 | ** to have prepared statements with over 32767 variables, and for them |
| 17791 | ** the option is available (at compile-time). |
| 17792 | */ |
| 17793 | #if SQLITE_MAX_VARIABLE_NUMBER<=32767 |
| 17794 | typedef i16 ynVar; |
| 17795 | #else |
| 17796 | typedef int ynVar; |
| 17797 | #endif |
| 17798 | |
| @@ -19107,17 +19112,20 @@ | |
| 19107 | #define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__) |
| 19108 | #define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__) |
| 19109 | #ifdef SQLITE_DEBUG |
| 19110 | SQLITE_PRIVATE int sqlite3NomemError(int); |
| 19111 | SQLITE_PRIVATE int sqlite3IoerrnomemError(int); |
| 19112 | SQLITE_PRIVATE int sqlite3CorruptPgnoError(int,Pgno); |
| 19113 | # define SQLITE_NOMEM_BKPT sqlite3NomemError(__LINE__) |
| 19114 | # define SQLITE_IOERR_NOMEM_BKPT sqlite3IoerrnomemError(__LINE__) |
| 19115 | # define SQLITE_CORRUPT_PGNO(P) sqlite3CorruptPgnoError(__LINE__,(P)) |
| 19116 | #else |
| 19117 | # define SQLITE_NOMEM_BKPT SQLITE_NOMEM |
| 19118 | # define SQLITE_IOERR_NOMEM_BKPT SQLITE_IOERR_NOMEM |
| 19119 | # define SQLITE_CORRUPT_PGNO(P) sqlite3CorruptError(__LINE__) |
| 19120 | #endif |
| 19121 | |
| 19122 | /* |
| 19123 | ** FTS3 and FTS4 both require virtual table support |
| @@ -19383,15 +19391,11 @@ | |
| 19383 | SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| 19384 | SQLITE_PRIVATE void sqlite3AddGenerated(Parse*,Expr*,Token*); |
| 19385 | SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*); |
| 19386 | SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, |
| 19387 | sqlite3_vfs**,char**,char **); |
| 19388 | #ifdef SQLITE_HAS_CODEC |
| 19389 | SQLITE_PRIVATE int sqlite3CodecQueryParameters(sqlite3*,const char*,const char*); |
| 19390 | #else |
| 19391 | # define sqlite3CodecQueryParameters(A,B,C) 0 |
| 19392 | #endif |
| 19393 | SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*); |
| 19394 | |
| 19395 | #ifdef SQLITE_UNTESTABLE |
| 19396 | # define sqlite3FaultSim(X) SQLITE_OK |
| 19397 | #else |
| @@ -19699,10 +19703,12 @@ | |
| 19699 | ** macros handle the common case without a procedure call, but then call |
| 19700 | ** the procedure for larger varints. |
| 19701 | */ |
| 19702 | #define getVarint32(A,B) \ |
| 19703 | (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B))) |
| 19704 | #define putVarint32(A,B) \ |
| 19705 | (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\ |
| 19706 | sqlite3PutVarint((A),(B))) |
| 19707 | #define getVarint sqlite3GetVarint |
| 19708 | #define putVarint sqlite3PutVarint |
| @@ -20322,20 +20328,13 @@ | |
| 20322 | ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options. |
| 20323 | ** |
| 20324 | ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally |
| 20325 | ** disabled. The default value may be changed by compiling with the |
| 20326 | ** SQLITE_USE_URI symbol defined. |
| 20327 | ** |
| 20328 | ** URI filenames are enabled by default if SQLITE_HAS_CODEC is |
| 20329 | ** enabled. |
| 20330 | */ |
| 20331 | #ifndef SQLITE_USE_URI |
| 20332 | # ifdef SQLITE_HAS_CODEC |
| 20333 | # define SQLITE_USE_URI 1 |
| 20334 | # else |
| 20335 | # define SQLITE_USE_URI 0 |
| 20336 | # endif |
| 20337 | #endif |
| 20338 | |
| 20339 | /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the |
| 20340 | ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if |
| 20341 | ** that compile-time option is omitted. |
| @@ -21062,10 +21061,11 @@ | |
| 21062 | SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); |
| 21063 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); |
| 21064 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); |
| 21065 | SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8); |
| 21066 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*); |
| 21067 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); |
| 21068 | SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); |
| 21069 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 21070 | SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*); |
| 21071 | #endif |
| @@ -25712,10 +25712,11 @@ | |
| 25712 | |
| 25713 | #ifdef SQLITE_DEBUG |
| 25714 | GLOBAL(int, mutexIsInit) = 1; |
| 25715 | #endif |
| 25716 | |
| 25717 | return rc; |
| 25718 | } |
| 25719 | |
| 25720 | /* |
| 25721 | ** Shutdown the mutex system. This call frees resources allocated by |
| @@ -30544,30 +30545,10 @@ | |
| 30544 | *zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); \ |
| 30545 | *zOut++ = (u8)(c&0x00FF); \ |
| 30546 | } \ |
| 30547 | } |
| 30548 | |
| 30549 | #define READ_UTF16LE(zIn, TERM, c){ \ |
| 30550 | c = (*zIn++); \ |
| 30551 | c += ((*zIn++)<<8); \ |
| 30552 | if( c>=0xD800 && c<0xE000 && TERM ){ \ |
| 30553 | int c2 = (*zIn++); \ |
| 30554 | c2 += ((*zIn++)<<8); \ |
| 30555 | c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); \ |
| 30556 | } \ |
| 30557 | } |
| 30558 | |
| 30559 | #define READ_UTF16BE(zIn, TERM, c){ \ |
| 30560 | c = ((*zIn++)<<8); \ |
| 30561 | c += (*zIn++); \ |
| 30562 | if( c>=0xD800 && c<0xE000 && TERM ){ \ |
| 30563 | int c2 = ((*zIn++)<<8); \ |
| 30564 | c2 += (*zIn++); \ |
| 30565 | c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); \ |
| 30566 | } \ |
| 30567 | } |
| 30568 | |
| 30569 | /* |
| 30570 | ** Translate a single UTF-8 character. Return the unicode value. |
| 30571 | ** |
| 30572 | ** During translation, assume that the byte that zTerm points |
| 30573 | ** is a 0x00. |
| @@ -30740,17 +30721,47 @@ | |
| 30740 | }else{ |
| 30741 | assert( desiredEnc==SQLITE_UTF8 ); |
| 30742 | if( pMem->enc==SQLITE_UTF16LE ){ |
| 30743 | /* UTF-16 Little-endian -> UTF-8 */ |
| 30744 | while( zIn<zTerm ){ |
| 30745 | READ_UTF16LE(zIn, zIn<zTerm, c); |
| 30746 | WRITE_UTF8(z, c); |
| 30747 | } |
| 30748 | }else{ |
| 30749 | /* UTF-16 Big-endian -> UTF-8 */ |
| 30750 | while( zIn<zTerm ){ |
| 30751 | READ_UTF16BE(zIn, zIn<zTerm, c); |
| 30752 | WRITE_UTF8(z, c); |
| 30753 | } |
| 30754 | } |
| 30755 | pMem->n = (int)(z - zOut); |
| 30756 | } |
| @@ -30905,22 +30916,19 @@ | |
| 30905 | SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *zIn, int nChar){ |
| 30906 | int c; |
| 30907 | unsigned char const *z = zIn; |
| 30908 | int n = 0; |
| 30909 | |
| 30910 | if( SQLITE_UTF16NATIVE==SQLITE_UTF16BE ){ |
| 30911 | while( n<nChar ){ |
| 30912 | READ_UTF16BE(z, 1, c); |
| 30913 | n++; |
| 30914 | } |
| 30915 | }else{ |
| 30916 | while( n<nChar ){ |
| 30917 | READ_UTF16LE(z, 1, c); |
| 30918 | n++; |
| 30919 | } |
| 30920 | } |
| 30921 | return (int)(z-(unsigned char const *)zIn); |
| 30922 | } |
| 30923 | |
| 30924 | #if defined(SQLITE_TEST) |
| 30925 | /* |
| 30926 | ** This routine is called from the TCL test function "translate_selftest". |
| @@ -30944,34 +30952,10 @@ | |
| 30944 | c = sqlite3Utf8Read((const u8**)&z); |
| 30945 | t = i; |
| 30946 | if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD; |
| 30947 | if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD; |
| 30948 | assert( c==t ); |
| 30949 | assert( (z-zBuf)==n ); |
| 30950 | } |
| 30951 | for(i=0; i<0x00110000; i++){ |
| 30952 | if( i>=0xD800 && i<0xE000 ) continue; |
| 30953 | z = zBuf; |
| 30954 | WRITE_UTF16LE(z, i); |
| 30955 | n = (int)(z-zBuf); |
| 30956 | assert( n>0 && n<=4 ); |
| 30957 | z[0] = 0; |
| 30958 | z = zBuf; |
| 30959 | READ_UTF16LE(z, 1, c); |
| 30960 | assert( c==i ); |
| 30961 | assert( (z-zBuf)==n ); |
| 30962 | } |
| 30963 | for(i=0; i<0x00110000; i++){ |
| 30964 | if( i>=0xD800 && i<0xE000 ) continue; |
| 30965 | z = zBuf; |
| 30966 | WRITE_UTF16BE(z, i); |
| 30967 | n = (int)(z-zBuf); |
| 30968 | assert( n>0 && n<=4 ); |
| 30969 | z[0] = 0; |
| 30970 | z = zBuf; |
| 30971 | READ_UTF16BE(z, 1, c); |
| 30972 | assert( c==i ); |
| 30973 | assert( (z-zBuf)==n ); |
| 30974 | } |
| 30975 | } |
| 30976 | #endif /* SQLITE_TEST */ |
| 30977 | #endif /* SQLITE_OMIT_UTF16 */ |
| @@ -32234,11 +32218,11 @@ | |
| 32234 | h += 9*(1&~(h>>4)); |
| 32235 | #endif |
| 32236 | return (u8)(h & 0xf); |
| 32237 | } |
| 32238 | |
| 32239 | #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) |
| 32240 | /* |
| 32241 | ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary |
| 32242 | ** value. Return a pointer to its binary value. Space to hold the |
| 32243 | ** binary value has been obtained from malloc and must be freed by |
| 32244 | ** the calling routine. |
| @@ -32255,11 +32239,11 @@ | |
| 32255 | } |
| 32256 | zBlob[i/2] = 0; |
| 32257 | } |
| 32258 | return zBlob; |
| 32259 | } |
| 32260 | #endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC */ |
| 32261 | |
| 32262 | /* |
| 32263 | ** Log an error that is an API call on a connection pointer that should |
| 32264 | ** not have been used. The "type" of connection pointer is given as the |
| 32265 | ** argument. The zType is a word like "NULL" or "closed" or "invalid". |
| @@ -32966,12 +32950,12 @@ | |
| 32966 | /* 58 */ "ElseNotEq" OpHelp(""), |
| 32967 | /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 32968 | /* 60 */ "IncrVacuum" OpHelp(""), |
| 32969 | /* 61 */ "VNext" OpHelp(""), |
| 32970 | /* 62 */ "Init" OpHelp("Start at P2"), |
| 32971 | /* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@P5])"), |
| 32972 | /* 64 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), |
| 32973 | /* 65 */ "Return" OpHelp(""), |
| 32974 | /* 66 */ "EndCoroutine" OpHelp(""), |
| 32975 | /* 67 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 32976 | /* 68 */ "Halt" OpHelp(""), |
| 32977 | /* 69 */ "Integer" OpHelp("r[P2]=P1"), |
| @@ -33033,12 +33017,12 @@ | |
| 33033 | /* 125 */ "SorterData" OpHelp("r[P2]=data"), |
| 33034 | /* 126 */ "RowData" OpHelp("r[P2]=data"), |
| 33035 | /* 127 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 33036 | /* 128 */ "NullRow" OpHelp(""), |
| 33037 | /* 129 */ "SeekEnd" OpHelp(""), |
| 33038 | /* 130 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 33039 | /* 131 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 33040 | /* 132 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 33041 | /* 133 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 33042 | /* 134 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 33043 | /* 135 */ "FinishSeek" OpHelp(""), |
| 33044 | /* 136 */ "Destroy" OpHelp(""), |
| @@ -33975,11 +33959,11 @@ | |
| 33975 | if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break; |
| 33976 | osClose(fd); |
| 33977 | sqlite3_log(SQLITE_WARNING, |
| 33978 | "attempt to open \"%s\" as file descriptor %d", z, fd); |
| 33979 | fd = -1; |
| 33980 | if( osOpen("/dev/null", f, m)<0 ) break; |
| 33981 | } |
| 33982 | if( fd>=0 ){ |
| 33983 | if( m!=0 ){ |
| 33984 | struct stat statbuf; |
| 33985 | if( osFstat(fd, &statbuf)==0 |
| @@ -51799,24 +51783,10 @@ | |
| 51799 | ** Pager.eLock may only be set to UNKNOWN_LOCK when the pager is in |
| 51800 | ** PAGER_OPEN state. |
| 51801 | */ |
| 51802 | #define UNKNOWN_LOCK (EXCLUSIVE_LOCK+1) |
| 51803 | |
| 51804 | /* |
| 51805 | ** A macro used for invoking the codec if there is one |
| 51806 | */ |
| 51807 | #ifdef SQLITE_HAS_CODEC |
| 51808 | # define CODEC1(P,D,N,X,E) \ |
| 51809 | if( P->xCodec && P->xCodec(P->pCodec,D,N,X)==0 ){ E; } |
| 51810 | # define CODEC2(P,D,N,X,E,O) \ |
| 51811 | if( P->xCodec==0 ){ O=(char*)D; }else \ |
| 51812 | if( (O=(char*)(P->xCodec(P->pCodec,D,N,X)))==0 ){ E; } |
| 51813 | #else |
| 51814 | # define CODEC1(P,D,N,X,E) /* NO-OP */ |
| 51815 | # define CODEC2(P,D,N,X,E,O) O=(char*)D |
| 51816 | #endif |
| 51817 | |
| 51818 | /* |
| 51819 | ** The maximum allowed sector size. 64KiB. If the xSectorsize() method |
| 51820 | ** returns a value larger than this, then MAX_SECTOR_SIZE is used instead. |
| 51821 | ** This could conceivably cause corruption following a power failure on |
| 51822 | ** such a system. This is currently an undocumented limit. |
| @@ -52098,16 +52068,10 @@ | |
| 52098 | #ifdef SQLITE_TEST |
| 52099 | int nRead; /* Database pages read */ |
| 52100 | #endif |
| 52101 | void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */ |
| 52102 | int (*xGet)(Pager*,Pgno,DbPage**,int); /* Routine to fetch a patch */ |
| 52103 | #ifdef SQLITE_HAS_CODEC |
| 52104 | void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */ |
| 52105 | void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */ |
| 52106 | void (*xCodecFree)(void*); /* Destructor for the codec */ |
| 52107 | void *pCodec; /* First argument to xCodec... methods */ |
| 52108 | #endif |
| 52109 | char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */ |
| 52110 | PCache *pPCache; /* Pointer to page cache object */ |
| 52111 | #ifndef SQLITE_OMIT_WAL |
| 52112 | Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */ |
| 52113 | char *zWal; /* File name for write-ahead log */ |
| @@ -52230,13 +52194,10 @@ | |
| 52230 | ** * the desired page is not currently in the wal file. |
| 52231 | */ |
| 52232 | SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){ |
| 52233 | if( pPager->fd->pMethods==0 ) return 0; |
| 52234 | if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0; |
| 52235 | #ifdef SQLITE_HAS_CODEC |
| 52236 | if( pPager->xCodec!=0 ) return 0; |
| 52237 | #endif |
| 52238 | #ifndef SQLITE_OMIT_WAL |
| 52239 | if( pPager->pWal ){ |
| 52240 | u32 iRead = 0; |
| 52241 | int rc; |
| 52242 | rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead); |
| @@ -52466,15 +52427,11 @@ | |
| 52466 | */ |
| 52467 | static void setGetterMethod(Pager *pPager){ |
| 52468 | if( pPager->errCode ){ |
| 52469 | pPager->xGet = getPageError; |
| 52470 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 52471 | }else if( USEFETCH(pPager) |
| 52472 | #ifdef SQLITE_HAS_CODEC |
| 52473 | && pPager->xCodec==0 |
| 52474 | #endif |
| 52475 | ){ |
| 52476 | pPager->xGet = getPageMMap; |
| 52477 | #endif /* SQLITE_MAX_MMAP_SIZE>0 */ |
| 52478 | }else{ |
| 52479 | pPager->xGet = getPageNormal; |
| 52480 | } |
| @@ -53618,39 +53575,10 @@ | |
| 53618 | i -= 200; |
| 53619 | } |
| 53620 | return cksum; |
| 53621 | } |
| 53622 | |
| 53623 | /* |
| 53624 | ** Report the current page size and number of reserved bytes back |
| 53625 | ** to the codec. |
| 53626 | */ |
| 53627 | #ifdef SQLITE_HAS_CODEC |
| 53628 | static void pagerReportSize(Pager *pPager){ |
| 53629 | if( pPager->xCodecSizeChng ){ |
| 53630 | pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize, |
| 53631 | (int)pPager->nReserve); |
| 53632 | } |
| 53633 | } |
| 53634 | #else |
| 53635 | # define pagerReportSize(X) /* No-op if we do not support a codec */ |
| 53636 | #endif |
| 53637 | |
| 53638 | #ifdef SQLITE_HAS_CODEC |
| 53639 | /* |
| 53640 | ** Make sure the number of reserved bits is the same in the destination |
| 53641 | ** pager as it is in the source. This comes up when a VACUUM changes the |
| 53642 | ** number of reserved bits to the "optimal" amount. |
| 53643 | */ |
| 53644 | SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager *pDest, Pager *pSrc){ |
| 53645 | if( pDest->nReserve!=pSrc->nReserve ){ |
| 53646 | pDest->nReserve = pSrc->nReserve; |
| 53647 | pagerReportSize(pDest); |
| 53648 | } |
| 53649 | } |
| 53650 | #endif |
| 53651 | |
| 53652 | /* |
| 53653 | ** Read a single page from either the journal file (if isMainJrnl==1) or |
| 53654 | ** from the sub-journal (if isMainJrnl==0) and playback that page. |
| 53655 | ** The page begins at offset *pOffset into the file. The *pOffset |
| 53656 | ** value is increased to the start of the next page in the journal. |
| @@ -53698,15 +53626,10 @@ | |
| 53698 | Pgno pgno; /* The page number of a page in journal */ |
| 53699 | u32 cksum; /* Checksum used for sanity checking */ |
| 53700 | char *aData; /* Temporary storage for the page */ |
| 53701 | sqlite3_file *jfd; /* The file descriptor for the journal file */ |
| 53702 | int isSynced; /* True if journal page is synced */ |
| 53703 | #ifdef SQLITE_HAS_CODEC |
| 53704 | /* The jrnlEnc flag is true if Journal pages should be passed through |
| 53705 | ** the codec. It is false for pure in-memory journals. */ |
| 53706 | const int jrnlEnc = (isMainJrnl || pPager->subjInMemory==0); |
| 53707 | #endif |
| 53708 | |
| 53709 | assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */ |
| 53710 | assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */ |
| 53711 | assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */ |
| 53712 | assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */ |
| @@ -53765,11 +53688,10 @@ | |
| 53765 | |
| 53766 | /* When playing back page 1, restore the nReserve setting |
| 53767 | */ |
| 53768 | if( pgno==1 && pPager->nReserve!=((u8*)aData)[20] ){ |
| 53769 | pPager->nReserve = ((u8*)aData)[20]; |
| 53770 | pagerReportSize(pPager); |
| 53771 | } |
| 53772 | |
| 53773 | /* If the pager is in CACHEMOD state, then there must be a copy of this |
| 53774 | ** page in the pager cache. In this case just update the pager cache, |
| 53775 | ** not the database file. The page is left marked dirty in this case. |
| @@ -53833,30 +53755,16 @@ | |
| 53833 | ** This is usually safe even for an encrypted database - as the data |
| 53834 | ** was encrypted before it was written to the journal file. The exception |
| 53835 | ** is if the data was just read from an in-memory sub-journal. In that |
| 53836 | ** case it must be encrypted here before it is copied into the database |
| 53837 | ** file. */ |
| 53838 | #ifdef SQLITE_HAS_CODEC |
| 53839 | if( !jrnlEnc ){ |
| 53840 | CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData); |
| 53841 | rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst); |
| 53842 | CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT); |
| 53843 | }else |
| 53844 | #endif |
| 53845 | rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst); |
| 53846 | |
| 53847 | if( pgno>pPager->dbFileSize ){ |
| 53848 | pPager->dbFileSize = pgno; |
| 53849 | } |
| 53850 | if( pPager->pBackup ){ |
| 53851 | #ifdef SQLITE_HAS_CODEC |
| 53852 | if( jrnlEnc ){ |
| 53853 | CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT); |
| 53854 | sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData); |
| 53855 | CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT,aData); |
| 53856 | }else |
| 53857 | #endif |
| 53858 | sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData); |
| 53859 | } |
| 53860 | }else if( !isMainJrnl && pPg==0 ){ |
| 53861 | /* If this is a rollback of a savepoint and data was not written to |
| 53862 | ** the database and the page is not in-memory, there is a potential |
| @@ -53903,15 +53811,10 @@ | |
| 53903 | /* If this was page 1, then restore the value of Pager.dbFileVers. |
| 53904 | ** Do this before any decoding. */ |
| 53905 | if( pgno==1 ){ |
| 53906 | memcpy(&pPager->dbFileVers, &((u8*)pData)[24],sizeof(pPager->dbFileVers)); |
| 53907 | } |
| 53908 | |
| 53909 | /* Decode the page just read from disk */ |
| 53910 | #if SQLITE_HAS_CODEC |
| 53911 | if( jrnlEnc ){ CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT); } |
| 53912 | #endif |
| 53913 | sqlite3PcacheRelease(pPg); |
| 53914 | } |
| 53915 | return rc; |
| 53916 | } |
| 53917 | |
| @@ -54467,12 +54370,10 @@ | |
| 54467 | }else{ |
| 54468 | u8 *dbFileVers = &((u8*)pPg->pData)[24]; |
| 54469 | memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers)); |
| 54470 | } |
| 54471 | } |
| 54472 | CODEC1(pPager, pPg->pData, pPg->pgno, 3, rc = SQLITE_NOMEM_BKPT); |
| 54473 | |
| 54474 | PAGER_INCR(sqlite3_pager_readdb_count); |
| 54475 | PAGER_INCR(pPager->nRead); |
| 54476 | IOTRACE(("PGIN %p %d\n", pPager, pPg->pgno)); |
| 54477 | PAGERTRACE(("FETCH %d page %d hash(%08x)\n", |
| 54478 | PAGERID(pPager), pPg->pgno, pager_pagehash(pPg))); |
| @@ -55212,11 +55113,10 @@ | |
| 55212 | *pPageSize = pPager->pageSize; |
| 55213 | if( rc==SQLITE_OK ){ |
| 55214 | if( nReserve<0 ) nReserve = pPager->nReserve; |
| 55215 | assert( nReserve>=0 && nReserve<1000 ); |
| 55216 | pPager->nReserve = (i16)nReserve; |
| 55217 | pagerReportSize(pPager); |
| 55218 | pagerFixMaplimit(pPager); |
| 55219 | } |
| 55220 | return rc; |
| 55221 | } |
| 55222 | |
| @@ -55608,15 +55508,10 @@ | |
| 55608 | IOTRACE(("CLOSE %p\n", pPager)) |
| 55609 | sqlite3OsClose(pPager->jfd); |
| 55610 | sqlite3OsClose(pPager->fd); |
| 55611 | sqlite3PageFree(pTmp); |
| 55612 | sqlite3PcacheClose(pPager->pPCache); |
| 55613 | |
| 55614 | #ifdef SQLITE_HAS_CODEC |
| 55615 | if( pPager->xCodecFree ) pPager->xCodecFree(pPager->pCodec); |
| 55616 | #endif |
| 55617 | |
| 55618 | assert( !pPager->aSavepoint && !pPager->pInJournal ); |
| 55619 | assert( !isOpen(pPager->jfd) && !isOpen(pPager->sjfd) ); |
| 55620 | |
| 55621 | sqlite3_free(pPager); |
| 55622 | return SQLITE_OK; |
| @@ -55863,12 +55758,11 @@ | |
| 55863 | char *pData; /* Data to write */ |
| 55864 | |
| 55865 | assert( (pList->flags&PGHDR_NEED_SYNC)==0 ); |
| 55866 | if( pList->pgno==1 ) pager_write_changecounter(pList); |
| 55867 | |
| 55868 | /* Encode the database */ |
| 55869 | CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM_BKPT, pData); |
| 55870 | |
| 55871 | /* Write out the page data. */ |
| 55872 | rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset); |
| 55873 | |
| 55874 | /* If page 1 was just written, update Pager.dbFileVers to match |
| @@ -55953,16 +55847,10 @@ | |
| 55953 | ** write the journal record into the file. */ |
| 55954 | if( rc==SQLITE_OK ){ |
| 55955 | void *pData = pPg->pData; |
| 55956 | i64 offset = (i64)pPager->nSubRec*(4+pPager->pageSize); |
| 55957 | char *pData2; |
| 55958 | |
| 55959 | #if SQLITE_HAS_CODEC |
| 55960 | if( !pPager->subjInMemory ){ |
| 55961 | CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2); |
| 55962 | }else |
| 55963 | #endif |
| 55964 | pData2 = pData; |
| 55965 | PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno)); |
| 55966 | rc = write32bits(pPager->sjfd, offset, pPg->pgno); |
| 55967 | if( rc==SQLITE_OK ){ |
| 55968 | rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4); |
| @@ -56259,10 +56147,15 @@ | |
| 56259 | ** - \0 |
| 56260 | ** - Journal Path |
| 56261 | ** - \0 |
| 56262 | ** - WAL Path (zWALName) |
| 56263 | ** - \0 |
| 56264 | */ |
| 56265 | pPtr = (u8 *)sqlite3MallocZero( |
| 56266 | ROUND8(sizeof(*pPager)) + /* Pager structure */ |
| 56267 | ROUND8(pcacheSize) + /* PCache object */ |
| 56268 | ROUND8(pVfs->szOsFile) + /* The main db file */ |
| @@ -57040,13 +56933,10 @@ | |
| 57040 | const int bMmapOk = (pgno>1 |
| 57041 | && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY)) |
| 57042 | ); |
| 57043 | |
| 57044 | assert( USEFETCH(pPager) ); |
| 57045 | #ifdef SQLITE_HAS_CODEC |
| 57046 | assert( pPager->xCodec==0 ); |
| 57047 | #endif |
| 57048 | |
| 57049 | /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here |
| 57050 | ** allows the compiler optimizer to reuse the results of the "pgno>1" |
| 57051 | ** test in the previous statement, and avoid testing pgno==0 in the |
| 57052 | ** common case where pgno is large. */ |
| @@ -57371,11 +57261,11 @@ | |
| 57371 | ** contains the database locks. The following assert verifies |
| 57372 | ** that we do not. */ |
| 57373 | assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); |
| 57374 | |
| 57375 | assert( pPager->journalHdr<=pPager->journalOff ); |
| 57376 | CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2); |
| 57377 | cksum = pager_cksum(pPager, (u8*)pData2); |
| 57378 | |
| 57379 | /* Even if an IO or diskfull error occurs while journalling the |
| 57380 | ** page in the block above, set the need-sync flag for the page. |
| 57381 | ** Otherwise, when the transaction is rolled back, the logic in |
| @@ -57736,11 +57626,11 @@ | |
| 57736 | |
| 57737 | /* If running in direct mode, write the contents of page 1 to the file. */ |
| 57738 | if( DIRECT_MODE ){ |
| 57739 | const void *zBuf; |
| 57740 | assert( pPager->dbFileSize>0 ); |
| 57741 | CODEC2(pPager, pPgHdr->pData, 1, 6, rc=SQLITE_NOMEM_BKPT, zBuf); |
| 57742 | if( rc==SQLITE_OK ){ |
| 57743 | rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0); |
| 57744 | pPager->aStat[PAGER_STAT_WRITE]++; |
| 57745 | } |
| 57746 | if( rc==SQLITE_OK ){ |
| @@ -58446,11 +58336,11 @@ | |
| 58446 | ** |
| 58447 | ** The return value to this routine is always safe to use with |
| 58448 | ** sqlite3_uri_parameter() and sqlite3_filename_database() and friends. |
| 58449 | */ |
| 58450 | SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager *pPager, int nullIfMemDb){ |
| 58451 | static const char zFake[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| 58452 | return (nullIfMemDb && pPager->memDb) ? &zFake[4] : pPager->zFilename; |
| 58453 | } |
| 58454 | |
| 58455 | /* |
| 58456 | ** Return the VFS structure for the pager. |
| @@ -58495,58 +58385,10 @@ | |
| 58495 | */ |
| 58496 | SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager *pPager){ |
| 58497 | return pPager->zJournal; |
| 58498 | } |
| 58499 | |
| 58500 | #ifdef SQLITE_HAS_CODEC |
| 58501 | /* |
| 58502 | ** Set or retrieve the codec for this pager |
| 58503 | */ |
| 58504 | SQLITE_PRIVATE void sqlite3PagerSetCodec( |
| 58505 | Pager *pPager, |
| 58506 | void *(*xCodec)(void*,void*,Pgno,int), |
| 58507 | void (*xCodecSizeChng)(void*,int,int), |
| 58508 | void (*xCodecFree)(void*), |
| 58509 | void *pCodec |
| 58510 | ){ |
| 58511 | if( pPager->xCodecFree ){ |
| 58512 | pPager->xCodecFree(pPager->pCodec); |
| 58513 | }else{ |
| 58514 | pager_reset(pPager); |
| 58515 | } |
| 58516 | pPager->xCodec = pPager->memDb ? 0 : xCodec; |
| 58517 | pPager->xCodecSizeChng = xCodecSizeChng; |
| 58518 | pPager->xCodecFree = xCodecFree; |
| 58519 | pPager->pCodec = pCodec; |
| 58520 | setGetterMethod(pPager); |
| 58521 | pagerReportSize(pPager); |
| 58522 | } |
| 58523 | SQLITE_PRIVATE void *sqlite3PagerGetCodec(Pager *pPager){ |
| 58524 | return pPager->pCodec; |
| 58525 | } |
| 58526 | |
| 58527 | /* |
| 58528 | ** This function is called by the wal module when writing page content |
| 58529 | ** into the log file. |
| 58530 | ** |
| 58531 | ** This function returns a pointer to a buffer containing the encrypted |
| 58532 | ** page content. If a malloc fails, this function may return NULL. |
| 58533 | */ |
| 58534 | SQLITE_PRIVATE void *sqlite3PagerCodec(PgHdr *pPg){ |
| 58535 | void *aData = 0; |
| 58536 | CODEC2(pPg->pPager, pPg->pData, pPg->pgno, 6, return 0, aData); |
| 58537 | return aData; |
| 58538 | } |
| 58539 | |
| 58540 | /* |
| 58541 | ** Return the current pager state |
| 58542 | */ |
| 58543 | SQLITE_PRIVATE int sqlite3PagerState(Pager *pPager){ |
| 58544 | return pPager->eState; |
| 58545 | } |
| 58546 | #endif /* SQLITE_HAS_CODEC */ |
| 58547 | |
| 58548 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 58549 | /* |
| 58550 | ** Move the page pPg to location pgno in the file. |
| 58551 | ** |
| 58552 | ** There must be no references to the page previously located at |
| @@ -62453,15 +62295,11 @@ | |
| 62453 | sqlite3_int64 iOffset /* Byte offset at which to write */ |
| 62454 | ){ |
| 62455 | int rc; /* Result code from subfunctions */ |
| 62456 | void *pData; /* Data actually written */ |
| 62457 | u8 aFrame[WAL_FRAME_HDRSIZE]; /* Buffer to assemble frame-header in */ |
| 62458 | #if defined(SQLITE_HAS_CODEC) |
| 62459 | if( (pData = sqlite3PagerCodec(pPage))==0 ) return SQLITE_NOMEM_BKPT; |
| 62460 | #else |
| 62461 | pData = pPage->pData; |
| 62462 | #endif |
| 62463 | walEncodeFrame(p->pWal, pPage->pgno, nTruncate, pData, aFrame); |
| 62464 | rc = walWriteToLog(p, aFrame, sizeof(aFrame), iOffset); |
| 62465 | if( rc ) return rc; |
| 62466 | /* Write the page data */ |
| 62467 | rc = walWriteToLog(p, pData, p->szPage, iOffset+sizeof(aFrame)); |
| @@ -62640,15 +62478,11 @@ | |
| 62640 | i64 iOff = walFrameOffset(iWrite, szPage) + WAL_FRAME_HDRSIZE; |
| 62641 | void *pData; |
| 62642 | if( pWal->iReCksum==0 || iWrite<pWal->iReCksum ){ |
| 62643 | pWal->iReCksum = iWrite; |
| 62644 | } |
| 62645 | #if defined(SQLITE_HAS_CODEC) |
| 62646 | if( (pData = sqlite3PagerCodec(p))==0 ) return SQLITE_NOMEM; |
| 62647 | #else |
| 62648 | pData = p->pData; |
| 62649 | #endif |
| 62650 | rc = sqlite3OsWrite(pWal->pWalFd, pData, szPage, iOff); |
| 62651 | if( rc ) return rc; |
| 62652 | p->flags &= ~PGHDR_WAL_APPEND; |
| 62653 | continue; |
| 62654 | } |
| @@ -63502,13 +63336,10 @@ | |
| 63502 | u8 incrVacuum; /* True if incr-vacuum is enabled */ |
| 63503 | u8 bDoTruncate; /* True to truncate db on commit */ |
| 63504 | #endif |
| 63505 | u8 inTransaction; /* Transaction state */ |
| 63506 | u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */ |
| 63507 | #ifdef SQLITE_HAS_CODEC |
| 63508 | u8 optimalReserve; /* Desired amount of reserved space per page */ |
| 63509 | #endif |
| 63510 | u16 btsFlags; /* Boolean parameters. See BTS_* macros below */ |
| 63511 | u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */ |
| 63512 | u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */ |
| 63513 | u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */ |
| 63514 | u16 minLeaf; /* Minimum local payload in a LEAFDATA table */ |
| @@ -65543,11 +65374,11 @@ | |
| 65543 | u8 *pEnd = &data[cellOffset + nCell*2]; |
| 65544 | u8 *pAddr; |
| 65545 | int sz2 = 0; |
| 65546 | int sz = get2byte(&data[iFree+2]); |
| 65547 | int top = get2byte(&data[hdr+5]); |
| 65548 | if( NEVER(top>=iFree) ){ |
| 65549 | return SQLITE_CORRUPT_PAGE(pPage); |
| 65550 | } |
| 65551 | if( iFree2 ){ |
| 65552 | if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65553 | sz2 = get2byte(&data[iFree2+2]); |
| @@ -65874,11 +65705,11 @@ | |
| 65874 | if( iStart<=x ){ |
| 65875 | /* The new freeblock is at the beginning of the cell content area, |
| 65876 | ** so just extend the cell content area rather than create another |
| 65877 | ** freelist entry */ |
| 65878 | if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65879 | if( NEVER(iPtr!=hdr+1) ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65880 | put2byte(&data[hdr+1], iFreeBlk); |
| 65881 | put2byte(&data[hdr+5], iEnd); |
| 65882 | }else{ |
| 65883 | /* Insert the new freeblock into the freelist */ |
| 65884 | put2byte(&data[iPtr], iStart); |
| @@ -66953,13 +66784,10 @@ | |
| 66953 | SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){ |
| 66954 | int rc = SQLITE_OK; |
| 66955 | BtShared *pBt = p->pBt; |
| 66956 | assert( nReserve>=-1 && nReserve<=255 ); |
| 66957 | sqlite3BtreeEnter(p); |
| 66958 | #if SQLITE_HAS_CODEC |
| 66959 | if( nReserve>pBt->optimalReserve ) pBt->optimalReserve = (u8)nReserve; |
| 66960 | #endif |
| 66961 | if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){ |
| 66962 | sqlite3BtreeLeave(p); |
| 66963 | return SQLITE_READONLY; |
| 66964 | } |
| 66965 | if( nReserve<0 ){ |
| @@ -67016,13 +66844,10 @@ | |
| 67016 | */ |
| 67017 | SQLITE_PRIVATE int sqlite3BtreeGetOptimalReserve(Btree *p){ |
| 67018 | int n; |
| 67019 | sqlite3BtreeEnter(p); |
| 67020 | n = sqlite3BtreeGetReserveNoMutex(p); |
| 67021 | #ifdef SQLITE_HAS_CODEC |
| 67022 | if( n<p->pBt->optimalReserve ) n = p->pBt->optimalReserve; |
| 67023 | #endif |
| 67024 | sqlite3BtreeLeave(p); |
| 67025 | return n; |
| 67026 | } |
| 67027 | |
| 67028 | |
| @@ -74855,17 +74680,10 @@ | |
| 74855 | Pager * const pDestPager = sqlite3BtreePager(p->pDest); |
| 74856 | const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc); |
| 74857 | int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest); |
| 74858 | const int nCopy = MIN(nSrcPgsz, nDestPgsz); |
| 74859 | const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz; |
| 74860 | #ifdef SQLITE_HAS_CODEC |
| 74861 | /* Use BtreeGetReserveNoMutex() for the source b-tree, as although it is |
| 74862 | ** guaranteed that the shared-mutex is held by this thread, handle |
| 74863 | ** p->pSrc may not actually be the owner. */ |
| 74864 | int nSrcReserve = sqlite3BtreeGetReserveNoMutex(p->pSrc); |
| 74865 | int nDestReserve = sqlite3BtreeGetOptimalReserve(p->pDest); |
| 74866 | #endif |
| 74867 | int rc = SQLITE_OK; |
| 74868 | i64 iOff; |
| 74869 | |
| 74870 | assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 ); |
| 74871 | assert( p->bDestLocked ); |
| @@ -74878,30 +74696,10 @@ | |
| 74878 | */ |
| 74879 | if( nSrcPgsz!=nDestPgsz && sqlite3PagerIsMemdb(pDestPager) ){ |
| 74880 | rc = SQLITE_READONLY; |
| 74881 | } |
| 74882 | |
| 74883 | #ifdef SQLITE_HAS_CODEC |
| 74884 | /* Backup is not possible if the page size of the destination is changing |
| 74885 | ** and a codec is in use. |
| 74886 | */ |
| 74887 | if( nSrcPgsz!=nDestPgsz && sqlite3PagerGetCodec(pDestPager)!=0 ){ |
| 74888 | rc = SQLITE_READONLY; |
| 74889 | } |
| 74890 | |
| 74891 | /* Backup is not possible if the number of bytes of reserve space differ |
| 74892 | ** between source and destination. If there is a difference, try to |
| 74893 | ** fix the destination to agree with the source. If that is not possible, |
| 74894 | ** then the backup cannot proceed. |
| 74895 | */ |
| 74896 | if( nSrcReserve!=nDestReserve ){ |
| 74897 | u32 newPgsz = nSrcPgsz; |
| 74898 | rc = sqlite3PagerSetPagesize(pDestPager, &newPgsz, nSrcReserve); |
| 74899 | if( rc==SQLITE_OK && newPgsz!=(u32)nSrcPgsz ) rc = SQLITE_READONLY; |
| 74900 | } |
| 74901 | #endif |
| 74902 | |
| 74903 | /* This loop runs once for each destination page spanned by the source |
| 74904 | ** page. For each iteration, variable iOff is set to the byte offset |
| 74905 | ** of the destination page. |
| 74906 | */ |
| 74907 | for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){ |
| @@ -75393,14 +75191,10 @@ | |
| 75393 | b.pSrcDb = pFrom->db; |
| 75394 | b.pSrc = pFrom; |
| 75395 | b.pDest = pTo; |
| 75396 | b.iNext = 1; |
| 75397 | |
| 75398 | #ifdef SQLITE_HAS_CODEC |
| 75399 | sqlite3PagerAlignReserve(sqlite3BtreePager(pTo), sqlite3BtreePager(pFrom)); |
| 75400 | #endif |
| 75401 | |
| 75402 | /* 0x7FFFFFFF is the hard limit for the number of pages in a database |
| 75403 | ** file. By passing this as the number of pages to copy to |
| 75404 | ** sqlite3_backup_step(), we can guarantee that the copy finishes |
| 75405 | ** within a single call (unless an error occurs). The assert() statement |
| 75406 | ** checks this assumption - (p->rc) should be set to either SQLITE_DONE |
| @@ -76594,11 +76388,11 @@ | |
| 76594 | ** destroyed. |
| 76595 | ** |
| 76596 | ** If this routine fails for any reason (malloc returns NULL or unable |
| 76597 | ** to read from the disk) then the pMem is left in an inconsistent state. |
| 76598 | */ |
| 76599 | static SQLITE_NOINLINE int vdbeMemFromBtreeResize( |
| 76600 | BtCursor *pCur, /* Cursor pointing at record to retrieve. */ |
| 76601 | u32 offset, /* Offset from the start of data to return bytes from. */ |
| 76602 | u32 amt, /* Number of bytes to return. */ |
| 76603 | Mem *pMem /* OUT: Return data in this Mem structure. */ |
| 76604 | ){ |
| @@ -76617,35 +76411,32 @@ | |
| 76617 | sqlite3VdbeMemRelease(pMem); |
| 76618 | } |
| 76619 | } |
| 76620 | return rc; |
| 76621 | } |
| 76622 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree( |
| 76623 | BtCursor *pCur, /* Cursor pointing at record to retrieve. */ |
| 76624 | u32 offset, /* Offset from the start of data to return bytes from. */ |
| 76625 | u32 amt, /* Number of bytes to return. */ |
| 76626 | Mem *pMem /* OUT: Return data in this Mem structure. */ |
| 76627 | ){ |
| 76628 | char *zData; /* Data from the btree layer */ |
| 76629 | u32 available = 0; /* Number of bytes available on the local btree page */ |
| 76630 | int rc = SQLITE_OK; /* Return code */ |
| 76631 | |
| 76632 | assert( sqlite3BtreeCursorIsValid(pCur) ); |
| 76633 | assert( !VdbeMemDynamic(pMem) ); |
| 76634 | |
| 76635 | /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert() |
| 76636 | ** that both the BtShared and database handle mutexes are held. */ |
| 76637 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| 76638 | zData = (char *)sqlite3BtreePayloadFetch(pCur, &available); |
| 76639 | assert( zData!=0 ); |
| 76640 | |
| 76641 | if( offset+amt<=available ){ |
| 76642 | pMem->z = &zData[offset]; |
| 76643 | pMem->flags = MEM_Blob|MEM_Ephem; |
| 76644 | pMem->n = (int)amt; |
| 76645 | }else{ |
| 76646 | rc = vdbeMemFromBtreeResize(pCur, offset, amt, pMem); |
| 76647 | } |
| 76648 | |
| 76649 | return rc; |
| 76650 | } |
| 76651 | |
| @@ -78397,10 +78188,38 @@ | |
| 78397 | */ |
| 78398 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){ |
| 78399 | sqlite3VdbeChangeP2(p, addr, p->nOp); |
| 78400 | } |
| 78401 | |
| 78402 | |
| 78403 | /* |
| 78404 | ** If the input FuncDef structure is ephemeral, then free it. If |
| 78405 | ** the FuncDef is not ephermal, then do nothing. |
| 78406 | */ |
| @@ -78777,12 +78596,15 @@ | |
| 78777 | int nTemp /* Space available in zTemp[] */ |
| 78778 | ){ |
| 78779 | const char *zOpName; |
| 78780 | const char *zSynopsis; |
| 78781 | int nOpName; |
| 78782 | int ii, jj; |
| 78783 | char zAlt[50]; |
| 78784 | zOpName = sqlite3OpcodeName(pOp->opcode); |
| 78785 | nOpName = sqlite3Strlen30(zOpName); |
| 78786 | if( zOpName[nOpName+1] ){ |
| 78787 | int seenCom = 0; |
| 78788 | char c; |
| @@ -78793,55 +78615,64 @@ | |
| 78793 | }else{ |
| 78794 | sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3); |
| 78795 | } |
| 78796 | zSynopsis = zAlt; |
| 78797 | } |
| 78798 | for(ii=jj=0; jj<nTemp-1 && (c = zSynopsis[ii])!=0; ii++){ |
| 78799 | if( c=='P' ){ |
| 78800 | c = zSynopsis[++ii]; |
| 78801 | if( c=='4' ){ |
| 78802 | sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", zP4); |
| 78803 | }else if( c=='X' ){ |
| 78804 | sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", pOp->zComment); |
| 78805 | seenCom = 1; |
| 78806 | }else{ |
| 78807 | int v1 = translateP(c, pOp); |
| 78808 | int v2; |
| 78809 | sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1); |
| 78810 | if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){ |
| 78811 | ii += 3; |
| 78812 | jj += sqlite3Strlen30(zTemp+jj); |
| 78813 | v2 = translateP(zSynopsis[ii], pOp); |
| 78814 | if( strncmp(zSynopsis+ii+1,"+1",2)==0 ){ |
| 78815 | ii += 2; |
| 78816 | v2++; |
| 78817 | } |
| 78818 | if( v2>1 ){ |
| 78819 | sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1); |
| 78820 | } |
| 78821 | }else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){ |
| 78822 | ii += 4; |
| 78823 | } |
| 78824 | } |
| 78825 | jj += sqlite3Strlen30(zTemp+jj); |
| 78826 | }else{ |
| 78827 | zTemp[jj++] = c; |
| 78828 | } |
| 78829 | } |
| 78830 | if( !seenCom && jj<nTemp-5 && pOp->zComment ){ |
| 78831 | sqlite3_snprintf(nTemp-jj, zTemp+jj, "; %s", pOp->zComment); |
| 78832 | jj += sqlite3Strlen30(zTemp+jj); |
| 78833 | } |
| 78834 | if( jj<nTemp ) zTemp[jj] = 0; |
| 78835 | }else if( pOp->zComment ){ |
| 78836 | sqlite3_snprintf(nTemp, zTemp, "%s", pOp->zComment); |
| 78837 | jj = sqlite3Strlen30(zTemp); |
| 78838 | }else{ |
| 78839 | zTemp[0] = 0; |
| 78840 | jj = 0; |
| 78841 | } |
| 78842 | return jj; |
| 78843 | } |
| 78844 | #endif /* SQLITE_DEBUG */ |
| 78845 | |
| 78846 | #if VDBE_DISPLAY_P4 && defined(SQLITE_ENABLE_CURSOR_HINTS) |
| 78847 | /* |
| @@ -80832,11 +80663,11 @@ | |
| 80832 | SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, int *piCol){ |
| 80833 | VdbeCursor *p = *pp; |
| 80834 | assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO ); |
| 80835 | if( p->deferredMoveto ){ |
| 80836 | int iMap; |
| 80837 | if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){ |
| 80838 | *pp = p->pAltCursor; |
| 80839 | *piCol = iMap - 1; |
| 80840 | return SQLITE_OK; |
| 80841 | } |
| 80842 | return sqlite3VdbeFinishMoveto(p); |
| @@ -81835,11 +81666,11 @@ | |
| 81835 | } |
| 81836 | } |
| 81837 | |
| 81838 | /* RHS is a string */ |
| 81839 | else if( pRhs->flags & MEM_Str ){ |
| 81840 | getVarint32(&aKey1[idx1], serial_type); |
| 81841 | testcase( serial_type==12 ); |
| 81842 | if( serial_type<12 ){ |
| 81843 | rc = -1; |
| 81844 | }else if( !(serial_type & 0x01) ){ |
| 81845 | rc = +1; |
| @@ -81869,11 +81700,11 @@ | |
| 81869 | } |
| 81870 | |
| 81871 | /* RHS is a blob */ |
| 81872 | else if( pRhs->flags & MEM_Blob ){ |
| 81873 | assert( (pRhs->flags & MEM_Zero)==0 || pRhs->n==0 ); |
| 81874 | getVarint32(&aKey1[idx1], serial_type); |
| 81875 | testcase( serial_type==12 ); |
| 81876 | if( serial_type<12 || (serial_type & 0x01) ){ |
| 81877 | rc = -1; |
| 81878 | }else{ |
| 81879 | int nStr = (serial_type - 12) / 2; |
| @@ -82058,11 +81889,14 @@ | |
| 82058 | int serial_type; |
| 82059 | int res; |
| 82060 | |
| 82061 | assert( pPKey2->aMem[0].flags & MEM_Str ); |
| 82062 | vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); |
| 82063 | getVarint32(&aKey1[1], serial_type); |
| 82064 | if( serial_type<12 ){ |
| 82065 | res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */ |
| 82066 | }else if( !(serial_type & 0x01) ){ |
| 82067 | res = pPKey2->r2; /* (pKey1/nKey1) is a blob */ |
| 82068 | }else{ |
| @@ -82179,17 +82013,17 @@ | |
| 82179 | nCellKey = sqlite3BtreePayloadSize(pCur); |
| 82180 | assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey ); |
| 82181 | |
| 82182 | /* Read in the complete content of the index entry */ |
| 82183 | sqlite3VdbeMemInit(&m, db, 0); |
| 82184 | rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, &m); |
| 82185 | if( rc ){ |
| 82186 | return rc; |
| 82187 | } |
| 82188 | |
| 82189 | /* The index entry must begin with a header size */ |
| 82190 | (void)getVarint32((u8*)m.z, szHdr); |
| 82191 | testcase( szHdr==3 ); |
| 82192 | testcase( szHdr==m.n ); |
| 82193 | testcase( szHdr>0x7fffffff ); |
| 82194 | assert( m.n>=0 ); |
| 82195 | if( unlikely(szHdr<3 || szHdr>(unsigned)m.n) ){ |
| @@ -82196,11 +82030,11 @@ | |
| 82196 | goto idx_rowid_corruption; |
| 82197 | } |
| 82198 | |
| 82199 | /* The last field of the index should be an integer - the ROWID. |
| 82200 | ** Verify that the last entry really is an integer. */ |
| 82201 | (void)getVarint32((u8*)&m.z[szHdr-1], typeRowid); |
| 82202 | testcase( typeRowid==1 ); |
| 82203 | testcase( typeRowid==2 ); |
| 82204 | testcase( typeRowid==3 ); |
| 82205 | testcase( typeRowid==4 ); |
| 82206 | testcase( typeRowid==5 ); |
| @@ -82261,11 +82095,11 @@ | |
| 82261 | if( nCellKey<=0 || nCellKey>0x7fffffff ){ |
| 82262 | *res = 0; |
| 82263 | return SQLITE_CORRUPT_BKPT; |
| 82264 | } |
| 82265 | sqlite3VdbeMemInit(&m, db, 0); |
| 82266 | rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, &m); |
| 82267 | if( rc ){ |
| 82268 | return rc; |
| 82269 | } |
| 82270 | *res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, pUnpacked, 0); |
| 82271 | sqlite3VdbeMemRelease(&m); |
| @@ -86927,11 +86761,11 @@ | |
| 86927 | affinity = pOp->p5 & SQLITE_AFF_MASK; |
| 86928 | if( affinity>=SQLITE_AFF_NUMERIC ){ |
| 86929 | if( (flags1 | flags3)&MEM_Str ){ |
| 86930 | if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){ |
| 86931 | applyNumericAffinity(pIn1,0); |
| 86932 | testcase( flags3!=pIn3->flags ); |
| 86933 | flags3 = pIn3->flags; |
| 86934 | } |
| 86935 | if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){ |
| 86936 | applyNumericAffinity(pIn3,0); |
| 86937 | } |
| @@ -86950,11 +86784,11 @@ | |
| 86950 | testcase( pIn1->flags & MEM_Real ); |
| 86951 | testcase( pIn1->flags & MEM_IntReal ); |
| 86952 | sqlite3VdbeMemStringify(pIn1, encoding, 1); |
| 86953 | testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) ); |
| 86954 | flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask); |
| 86955 | if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str; |
| 86956 | } |
| 86957 | if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){ |
| 86958 | testcase( pIn3->flags & MEM_Int ); |
| 86959 | testcase( pIn3->flags & MEM_Real ); |
| 86960 | testcase( pIn3->flags & MEM_IntReal ); |
| @@ -87565,11 +87399,11 @@ | |
| 87565 | */ |
| 87566 | if( pC->iHdrOffset<aOffset[0] ){ |
| 87567 | /* Make sure zData points to enough of the record to cover the header. */ |
| 87568 | if( pC->aRow==0 ){ |
| 87569 | memset(&sMem, 0, sizeof(sMem)); |
| 87570 | rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, 0, aOffset[0], &sMem); |
| 87571 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 87572 | zData = (u8*)sMem.z; |
| 87573 | }else{ |
| 87574 | zData = pC->aRow; |
| 87575 | } |
| @@ -90061,11 +89895,11 @@ | |
| 90061 | n = sqlite3BtreePayloadSize(pCrsr); |
| 90062 | if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 90063 | goto too_big; |
| 90064 | } |
| 90065 | testcase( n==0 ); |
| 90066 | rc = sqlite3VdbeMemFromBtree(pCrsr, 0, n, pOut); |
| 90067 | if( rc ) goto abort_due_to_error; |
| 90068 | if( !pOp->p3 ) Deephemeralize(pOut); |
| 90069 | UPDATE_MAX_BLOBSIZE(pOut); |
| 90070 | REGISTER_TRACE(pOp->p2, pOut); |
| 90071 | break; |
| @@ -90439,48 +90273,61 @@ | |
| 90439 | ** to P2. |
| 90440 | ** |
| 90441 | ** This instruction only works for indices. The equivalent instruction |
| 90442 | ** for tables is OP_Insert. |
| 90443 | */ |
| 90444 | /* Opcode: SorterInsert P1 P2 * * * |
| 90445 | ** Synopsis: key=r[P2] |
| 90446 | ** |
| 90447 | ** Register P2 holds an SQL index key made using the |
| 90448 | ** MakeRecord instructions. This opcode writes that key |
| 90449 | ** into the sorter P1. Data for the entry is nil. |
| 90450 | */ |
| 90451 | case OP_SorterInsert: /* in2 */ |
| 90452 | case OP_IdxInsert: { /* in2 */ |
| 90453 | VdbeCursor *pC; |
| 90454 | BtreePayload x; |
| 90455 | |
| 90456 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 90457 | pC = p->apCsr[pOp->p1]; |
| 90458 | sqlite3VdbeIncrWriteCounter(p, pC); |
| 90459 | assert( pC!=0 ); |
| 90460 | assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) ); |
| 90461 | pIn2 = &aMem[pOp->p2]; |
| 90462 | assert( pIn2->flags & MEM_Blob ); |
| 90463 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 90464 | assert( pC->eCurType==CURTYPE_BTREE || pOp->opcode==OP_SorterInsert ); |
| 90465 | assert( pC->isTable==0 ); |
| 90466 | rc = ExpandBlob(pIn2); |
| 90467 | if( rc ) goto abort_due_to_error; |
| 90468 | if( pOp->opcode==OP_SorterInsert ){ |
| 90469 | rc = sqlite3VdbeSorterWrite(pC, pIn2); |
| 90470 | }else{ |
| 90471 | x.nKey = pIn2->n; |
| 90472 | x.pKey = pIn2->z; |
| 90473 | x.aMem = aMem + pOp->p3; |
| 90474 | x.nMem = (u16)pOp->p4.i; |
| 90475 | rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, |
| 90476 | (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)), |
| 90477 | ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) |
| 90478 | ); |
| 90479 | assert( pC->deferredMoveto==0 ); |
| 90480 | pC->cacheStatus = CACHE_STALE; |
| 90481 | } |
| 90482 | if( rc) goto abort_due_to_error; |
| 90483 | break; |
| 90484 | } |
| 90485 | |
| 90486 | /* Opcode: IdxDelete P1 P2 P3 * * |
| @@ -92426,11 +92273,11 @@ | |
| 92426 | break; |
| 92427 | } |
| 92428 | #endif |
| 92429 | |
| 92430 | /* Opcode: Function P1 P2 P3 P4 * |
| 92431 | ** Synopsis: r[P3]=func(r[P2@P5]) |
| 92432 | ** |
| 92433 | ** Invoke a user function (P4 is a pointer to an sqlite3_context object that |
| 92434 | ** contains a pointer to the function to be run) with arguments taken |
| 92435 | ** from register P2 and successors. The number of arguments is in |
| 92436 | ** the sqlite3_context object that P4 points to. |
| @@ -92445,11 +92292,11 @@ | |
| 92445 | ** invocation of this opcode. |
| 92446 | ** |
| 92447 | ** See also: AggStep, AggFinal, PureFunc |
| 92448 | */ |
| 92449 | /* Opcode: PureFunc P1 P2 P3 P4 * |
| 92450 | ** Synopsis: r[P3]=func(r[P2@P5]) |
| 92451 | ** |
| 92452 | ** Invoke a user function (P4 is a pointer to an sqlite3_context object that |
| 92453 | ** contains a pointer to the function to be run) with arguments taken |
| 92454 | ** from register P2 and successors. The number of arguments is in |
| 92455 | ** the sqlite3_context object that P4 points to. |
| @@ -94172,12 +94019,12 @@ | |
| 94172 | |
| 94173 | int n1; |
| 94174 | int n2; |
| 94175 | int res; |
| 94176 | |
| 94177 | getVarint32(&p1[1], n1); |
| 94178 | getVarint32(&p2[1], n2); |
| 94179 | res = memcmp(v1, v2, (MIN(n1, n2) - 13)/2); |
| 94180 | if( res==0 ){ |
| 94181 | res = n1 - n2; |
| 94182 | } |
| 94183 | |
| @@ -95130,11 +94977,11 @@ | |
| 95130 | int nPMA; /* Bytes of PMA space required */ |
| 95131 | int t; /* serial type of first record field */ |
| 95132 | |
| 95133 | assert( pCsr->eCurType==CURTYPE_SORTER ); |
| 95134 | pSorter = pCsr->uc.pSorter; |
| 95135 | getVarint32((const u8*)&pVal->z[1], t); |
| 95136 | if( t>0 && t<10 && t!=7 ){ |
| 95137 | pSorter->typeMask &= SORTER_TYPE_INTEGER; |
| 95138 | }else if( t>10 && (t & 0x01) ){ |
| 95139 | pSorter->typeMask &= SORTER_TYPE_TEXT; |
| 95140 | }else{ |
| @@ -97814,11 +97661,11 @@ | |
| 97814 | case TK_ISNOT: { |
| 97815 | Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight); |
| 97816 | assert( !ExprHasProperty(pExpr, EP_Reduced) ); |
| 97817 | /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE", |
| 97818 | ** and "x IS NOT FALSE". */ |
| 97819 | if( pRight->op==TK_ID ){ |
| 97820 | int rc = resolveExprStep(pWalker, pRight); |
| 97821 | if( rc==WRC_Abort ) return WRC_Abort; |
| 97822 | if( pRight->op==TK_TRUEFALSE ){ |
| 97823 | pExpr->op2 = pExpr->op; |
| 97824 | pExpr->op = TK_TRUTH; |
| @@ -102304,10 +102151,20 @@ | |
| 102304 | } |
| 102305 | } |
| 102306 | } |
| 102307 | return iResult; |
| 102308 | } |
| 102309 | |
| 102310 | /* |
| 102311 | ** Generate code to implement special SQL functions that are implemented |
| 102312 | ** in-line rather than by using the usual callbacks. |
| 102313 | */ |
| @@ -102336,13 +102193,11 @@ | |
| 102336 | for(i=1; i<nFarg; i++){ |
| 102337 | sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce); |
| 102338 | VdbeCoverage(v); |
| 102339 | sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target); |
| 102340 | } |
| 102341 | if( sqlite3VdbeGetOp(v, -1)->opcode==OP_Copy ){ |
| 102342 | sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */ |
| 102343 | } |
| 102344 | sqlite3VdbeResolveLabel(v, endCoalesce); |
| 102345 | break; |
| 102346 | } |
| 102347 | |
| 102348 | default: { |
| @@ -103109,10 +102964,11 @@ | |
| 103109 | sqlite3ExprCode(pParse, pEList->a[nExpr-1].pExpr, target); |
| 103110 | }else{ |
| 103111 | sqlite3VdbeAddOp2(v, OP_Null, 0, target); |
| 103112 | } |
| 103113 | sqlite3ExprDelete(db, pDel); |
| 103114 | sqlite3VdbeResolveLabel(v, endLabel); |
| 103115 | break; |
| 103116 | } |
| 103117 | #ifndef SQLITE_OMIT_TRIGGER |
| 103118 | case TK_RAISE: { |
| @@ -104131,23 +103987,29 @@ | |
| 104131 | case TK_EQ: |
| 104132 | case TK_NE: |
| 104133 | case TK_LT: |
| 104134 | case TK_LE: |
| 104135 | case TK_GT: |
| 104136 | case TK_GE: |
| 104137 | testcase( pExpr->op==TK_EQ ); |
| 104138 | testcase( pExpr->op==TK_NE ); |
| 104139 | testcase( pExpr->op==TK_LT ); |
| 104140 | testcase( pExpr->op==TK_LE ); |
| 104141 | testcase( pExpr->op==TK_GT ); |
| 104142 | testcase( pExpr->op==TK_GE ); |
| 104143 | if( (pExpr->pLeft->op==TK_COLUMN && IsVirtual(pExpr->pLeft->y.pTab)) |
| 104144 | || (pExpr->pRight->op==TK_COLUMN && IsVirtual(pExpr->pRight->y.pTab)) |
| 104145 | ){ |
| 104146 | return WRC_Prune; |
| 104147 | } |
| 104148 | |
| 104149 | default: |
| 104150 | return WRC_Continue; |
| 104151 | } |
| 104152 | } |
| 104153 | |
| @@ -108386,47 +108248,11 @@ | |
| 108386 | } |
| 108387 | pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1; |
| 108388 | if( rc==SQLITE_OK && pNew->zDbSName==0 ){ |
| 108389 | rc = SQLITE_NOMEM_BKPT; |
| 108390 | } |
| 108391 | |
| 108392 | |
| 108393 | #ifdef SQLITE_HAS_CODEC |
| 108394 | if( rc==SQLITE_OK ){ |
| 108395 | extern int sqlite3CodecAttach(sqlite3*, int, const void*, int); |
| 108396 | extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*); |
| 108397 | int nKey; |
| 108398 | char *zKey; |
| 108399 | int t = sqlite3_value_type(argv[2]); |
| 108400 | switch( t ){ |
| 108401 | case SQLITE_INTEGER: |
| 108402 | case SQLITE_FLOAT: |
| 108403 | zErrDyn = sqlite3DbStrDup(db, "Invalid key value"); |
| 108404 | rc = SQLITE_ERROR; |
| 108405 | break; |
| 108406 | |
| 108407 | case SQLITE_TEXT: |
| 108408 | case SQLITE_BLOB: |
| 108409 | nKey = sqlite3_value_bytes(argv[2]); |
| 108410 | zKey = (char *)sqlite3_value_blob(argv[2]); |
| 108411 | rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey); |
| 108412 | break; |
| 108413 | |
| 108414 | case SQLITE_NULL: |
| 108415 | /* No key specified. Use the key from URI filename, or if none, |
| 108416 | ** use the key from the main database. */ |
| 108417 | if( sqlite3CodecQueryParameters(db, zName, zPath)==0 ){ |
| 108418 | sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey); |
| 108419 | if( nKey || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){ |
| 108420 | rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey); |
| 108421 | } |
| 108422 | } |
| 108423 | break; |
| 108424 | } |
| 108425 | } |
| 108426 | #endif |
| 108427 | sqlite3_free( zPath ); |
| 108428 | |
| 108429 | /* If the file was opened successfully, read the schema for the new database. |
| 108430 | ** If this fails, or if opening the file failed, then close the file and |
| 108431 | ** remove the entry from the db->aDb[] array. i.e. put everything back the |
| 108432 | ** way we found it. |
| @@ -115207,11 +115033,13 @@ | |
| 115207 | testcase( IsVirtual(pTab) ); |
| 115208 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, OPFLAG_FORDELETE, |
| 115209 | iTabCur, aToOpen, &iDataCur, &iIdxCur); |
| 115210 | assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur ); |
| 115211 | assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 ); |
| 115212 | if( eOnePass==ONEPASS_MULTI ) sqlite3VdbeJumpHere(v, iAddrOnce); |
| 115213 | } |
| 115214 | |
| 115215 | /* Set up a loop over the rowids/primary-keys that were found in the |
| 115216 | ** where-clause loop above. |
| 115217 | */ |
| @@ -118337,11 +118165,11 @@ | |
| 118337 | } |
| 118338 | |
| 118339 | /* Clean up the WHERE clause constructed above. */ |
| 118340 | sqlite3ExprDelete(db, pWhere); |
| 118341 | if( iFkIfZero ){ |
| 118342 | sqlite3VdbeJumpHere(v, iFkIfZero); |
| 118343 | } |
| 118344 | } |
| 118345 | |
| 118346 | /* |
| 118347 | ** This function returns a linked list of FKey objects (connected by |
| @@ -120798,10 +120626,14 @@ | |
| 120798 | && !sqlite3ExprReferencesUpdatedColumn(pExpr, aiChng, pkChng) |
| 120799 | ){ |
| 120800 | /* The check constraints do not reference any of the columns being |
| 120801 | ** updated so there is no point it verifying the check constraint */ |
| 120802 | continue; |
| 120803 | } |
| 120804 | allOk = sqlite3VdbeMakeLabel(pParse); |
| 120805 | sqlite3VdbeVerifyAbortable(v, onError); |
| 120806 | sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL); |
| 120807 | if( onError==OE_Ignore ){ |
| @@ -121915,18 +121747,17 @@ | |
| 121915 | addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid); |
| 121916 | }else{ |
| 121917 | addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); |
| 121918 | assert( (pDest->tabFlags & TF_Autoincrement)==0 ); |
| 121919 | } |
| 121920 | sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); |
| 121921 | if( db->mDbFlags & DBFLAG_Vacuum ){ |
| 121922 | sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest); |
| 121923 | insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID| |
| 121924 | OPFLAG_APPEND|OPFLAG_USESEEKRESULT; |
| 121925 | }else{ |
| 121926 | insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND; |
| 121927 | } |
| 121928 | sqlite3VdbeAddOp4(v, OP_Insert, iDest, regData, regRowid, |
| 121929 | (char*)pDest, P4_TABLE); |
| 121930 | sqlite3VdbeChangeP5(v, insFlags); |
| 121931 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v); |
| 121932 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| @@ -121947,11 +121778,10 @@ | |
| 121947 | sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest); |
| 121948 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 121949 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 121950 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 121951 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 121952 | sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); |
| 121953 | if( db->mDbFlags & DBFLAG_Vacuum ){ |
| 121954 | /* This INSERT command is part of a VACUUM operation, which guarantees |
| 121955 | ** that the destination table is empty. If all indexed columns use |
| 121956 | ** collation sequence BINARY, then it can also be assumed that the |
| 121957 | ** index will be populated by inserting keys in strictly sorted |
| @@ -121971,14 +121801,14 @@ | |
| 121971 | } |
| 121972 | if( i==pSrcIdx->nColumn ){ |
| 121973 | idxInsFlags = OPFLAG_USESEEKRESULT; |
| 121974 | sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest); |
| 121975 | } |
| 121976 | } |
| 121977 | if( !HasRowid(pSrc) && pDestIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){ |
| 121978 | idxInsFlags |= OPFLAG_NCHANGE; |
| 121979 | } |
| 121980 | sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData); |
| 121981 | sqlite3VdbeChangeP5(v, idxInsFlags|OPFLAG_APPEND); |
| 121982 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v); |
| 121983 | sqlite3VdbeJumpHere(v, addr1); |
| 121984 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| @@ -122495,10 +122325,14 @@ | |
| 122495 | sqlite3_int64 (*hard_heap_limit64)(sqlite3_int64); |
| 122496 | const char *(*uri_key)(const char*,int); |
| 122497 | const char *(*filename_database)(const char*); |
| 122498 | const char *(*filename_journal)(const char*); |
| 122499 | const char *(*filename_wal)(const char*); |
| 122500 | }; |
| 122501 | |
| 122502 | /* |
| 122503 | ** This is the function signature used for all extension entry points. It |
| 122504 | ** is also defined in the file "loadext.c". |
| @@ -122795,10 +122629,13 @@ | |
| 122795 | #define sqlite3_hard_heap_limit64 sqlite3_api->hard_heap_limit64 |
| 122796 | #define sqlite3_uri_key sqlite3_api->uri_key |
| 122797 | #define sqlite3_filename_database sqlite3_api->filename_database |
| 122798 | #define sqlite3_filename_journal sqlite3_api->filename_journal |
| 122799 | #define sqlite3_filename_wal sqlite3_api->filename_wal |
| 122800 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 122801 | |
| 122802 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 122803 | /* This case when the file really is being compiled as a loadable |
| 122804 | ** extension */ |
| @@ -123273,10 +123110,13 @@ | |
| 123273 | sqlite3_hard_heap_limit64, |
| 123274 | sqlite3_uri_key, |
| 123275 | sqlite3_filename_database, |
| 123276 | sqlite3_filename_journal, |
| 123277 | sqlite3_filename_wal, |
| 123278 | }; |
| 123279 | |
| 123280 | /* |
| 123281 | ** Attempt to load an SQLite extension library contained in the file |
| 123282 | ** zFile. The entry point is zProc. zProc may be 0 in which case a |
| @@ -123679,55 +123519,54 @@ | |
| 123679 | ** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit |
| 123680 | ** that script and rerun it. |
| 123681 | */ |
| 123682 | |
| 123683 | /* The various pragma types */ |
| 123684 | #define PragTyp_HEADER_VALUE 0 |
| 123685 | #define PragTyp_AUTO_VACUUM 1 |
| 123686 | #define PragTyp_FLAG 2 |
| 123687 | #define PragTyp_BUSY_TIMEOUT 3 |
| 123688 | #define PragTyp_CACHE_SIZE 4 |
| 123689 | #define PragTyp_CACHE_SPILL 5 |
| 123690 | #define PragTyp_CASE_SENSITIVE_LIKE 6 |
| 123691 | #define PragTyp_COLLATION_LIST 7 |
| 123692 | #define PragTyp_COMPILE_OPTIONS 8 |
| 123693 | #define PragTyp_DATA_STORE_DIRECTORY 9 |
| 123694 | #define PragTyp_DATABASE_LIST 10 |
| 123695 | #define PragTyp_DEFAULT_CACHE_SIZE 11 |
| 123696 | #define PragTyp_ENCODING 12 |
| 123697 | #define PragTyp_FOREIGN_KEY_CHECK 13 |
| 123698 | #define PragTyp_FOREIGN_KEY_LIST 14 |
| 123699 | #define PragTyp_FUNCTION_LIST 15 |
| 123700 | #define PragTyp_HARD_HEAP_LIMIT 16 |
| 123701 | #define PragTyp_INCREMENTAL_VACUUM 17 |
| 123702 | #define PragTyp_INDEX_INFO 18 |
| 123703 | #define PragTyp_INDEX_LIST 19 |
| 123704 | #define PragTyp_INTEGRITY_CHECK 20 |
| 123705 | #define PragTyp_JOURNAL_MODE 21 |
| 123706 | #define PragTyp_JOURNAL_SIZE_LIMIT 22 |
| 123707 | #define PragTyp_LOCK_PROXY_FILE 23 |
| 123708 | #define PragTyp_LOCKING_MODE 24 |
| 123709 | #define PragTyp_PAGE_COUNT 25 |
| 123710 | #define PragTyp_MMAP_SIZE 26 |
| 123711 | #define PragTyp_MODULE_LIST 27 |
| 123712 | #define PragTyp_OPTIMIZE 28 |
| 123713 | #define PragTyp_PAGE_SIZE 29 |
| 123714 | #define PragTyp_PRAGMA_LIST 30 |
| 123715 | #define PragTyp_SECURE_DELETE 31 |
| 123716 | #define PragTyp_SHRINK_MEMORY 32 |
| 123717 | #define PragTyp_SOFT_HEAP_LIMIT 33 |
| 123718 | #define PragTyp_SYNCHRONOUS 34 |
| 123719 | #define PragTyp_TABLE_INFO 35 |
| 123720 | #define PragTyp_TEMP_STORE 36 |
| 123721 | #define PragTyp_TEMP_STORE_DIRECTORY 37 |
| 123722 | #define PragTyp_THREADS 38 |
| 123723 | #define PragTyp_WAL_AUTOCHECKPOINT 39 |
| 123724 | #define PragTyp_WAL_CHECKPOINT 40 |
| 123725 | #define PragTyp_ACTIVATE_EXTENSIONS 41 |
| 123726 | #define PragTyp_KEY 42 |
| 123727 | #define PragTyp_LOCK_STATUS 43 |
| 123728 | #define PragTyp_STATS 44 |
| 123729 | |
| 123730 | /* Property flags associated with various pragma. */ |
| 123731 | #define PragFlg_NeedSchema 0x01 /* Force schema load before running */ |
| 123732 | #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */ |
| 123733 | #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */ |
| @@ -123807,11 +123646,11 @@ | |
| 123807 | u8 iPragCName; /* Start of column names in pragCName[] */ |
| 123808 | u8 nPragCName; /* Num of col names. 0 means use pragma name */ |
| 123809 | u64 iArg; /* Extra argument */ |
| 123810 | } PragmaName; |
| 123811 | static const PragmaName aPragmaName[] = { |
| 123812 | #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) |
| 123813 | {/* zName: */ "activate_extensions", |
| 123814 | /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS, |
| 123815 | /* ePragFlg: */ 0, |
| 123816 | /* ColNames: */ 0, 0, |
| 123817 | /* iArg: */ 0 }, |
| @@ -124003,22 +123842,10 @@ | |
| 124003 | {/* zName: */ "hard_heap_limit", |
| 124004 | /* ePragTyp: */ PragTyp_HARD_HEAP_LIMIT, |
| 124005 | /* ePragFlg: */ PragFlg_Result0, |
| 124006 | /* ColNames: */ 0, 0, |
| 124007 | /* iArg: */ 0 }, |
| 124008 | #if defined(SQLITE_HAS_CODEC) |
| 124009 | {/* zName: */ "hexkey", |
| 124010 | /* ePragTyp: */ PragTyp_KEY, |
| 124011 | /* ePragFlg: */ 0, |
| 124012 | /* ColNames: */ 0, 0, |
| 124013 | /* iArg: */ 2 }, |
| 124014 | {/* zName: */ "hexrekey", |
| 124015 | /* ePragTyp: */ PragTyp_KEY, |
| 124016 | /* ePragFlg: */ 0, |
| 124017 | /* ColNames: */ 0, 0, |
| 124018 | /* iArg: */ 3 }, |
| 124019 | #endif |
| 124020 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 124021 | #if !defined(SQLITE_OMIT_CHECK) |
| 124022 | {/* zName: */ "ignore_check_constraints", |
| 124023 | /* ePragTyp: */ PragTyp_FLAG, |
| 124024 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| @@ -124064,17 +123891,10 @@ | |
| 124064 | /* ColNames: */ 0, 0, |
| 124065 | /* iArg: */ 0 }, |
| 124066 | {/* zName: */ "journal_size_limit", |
| 124067 | /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT, |
| 124068 | /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq, |
| 124069 | /* ColNames: */ 0, 0, |
| 124070 | /* iArg: */ 0 }, |
| 124071 | #endif |
| 124072 | #if defined(SQLITE_HAS_CODEC) |
| 124073 | {/* zName: */ "key", |
| 124074 | /* ePragTyp: */ PragTyp_KEY, |
| 124075 | /* ePragFlg: */ 0, |
| 124076 | /* ColNames: */ 0, 0, |
| 124077 | /* iArg: */ 0 }, |
| 124078 | #endif |
| 124079 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 124080 | {/* zName: */ "legacy_alter_table", |
| @@ -124181,19 +124001,10 @@ | |
| 124181 | {/* zName: */ "recursive_triggers", |
| 124182 | /* ePragTyp: */ PragTyp_FLAG, |
| 124183 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 124184 | /* ColNames: */ 0, 0, |
| 124185 | /* iArg: */ SQLITE_RecTriggers }, |
| 124186 | #endif |
| 124187 | #if defined(SQLITE_HAS_CODEC) |
| 124188 | {/* zName: */ "rekey", |
| 124189 | /* ePragTyp: */ PragTyp_KEY, |
| 124190 | /* ePragFlg: */ 0, |
| 124191 | /* ColNames: */ 0, 0, |
| 124192 | /* iArg: */ 1 }, |
| 124193 | #endif |
| 124194 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 124195 | {/* zName: */ "reverse_unordered_selects", |
| 124196 | /* ePragTyp: */ PragTyp_FLAG, |
| 124197 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 124198 | /* ColNames: */ 0, 0, |
| 124199 | /* iArg: */ SQLITE_ReverseOrder }, |
| @@ -124274,22 +124085,10 @@ | |
| 124274 | /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY, |
| 124275 | /* ePragFlg: */ PragFlg_NoColumns1, |
| 124276 | /* ColNames: */ 0, 0, |
| 124277 | /* iArg: */ 0 }, |
| 124278 | #endif |
| 124279 | #if defined(SQLITE_HAS_CODEC) |
| 124280 | {/* zName: */ "textkey", |
| 124281 | /* ePragTyp: */ PragTyp_KEY, |
| 124282 | /* ePragFlg: */ 0, |
| 124283 | /* ColNames: */ 0, 0, |
| 124284 | /* iArg: */ 4 }, |
| 124285 | {/* zName: */ "textrekey", |
| 124286 | /* ePragTyp: */ PragTyp_KEY, |
| 124287 | /* ePragFlg: */ 0, |
| 124288 | /* ColNames: */ 0, 0, |
| 124289 | /* iArg: */ 5 }, |
| 124290 | #endif |
| 124291 | {/* zName: */ "threads", |
| 124292 | /* ePragTyp: */ PragTyp_THREADS, |
| 124293 | /* ePragFlg: */ PragFlg_Result0, |
| 124294 | /* ColNames: */ 0, 0, |
| 124295 | /* iArg: */ 0 }, |
| @@ -124354,11 +124153,11 @@ | |
| 124354 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 124355 | /* ColNames: */ 0, 0, |
| 124356 | /* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError }, |
| 124357 | #endif |
| 124358 | }; |
| 124359 | /* Number of pragmas: 66 on by default, 82 total. */ |
| 124360 | |
| 124361 | /************** End of pragma.h **********************************************/ |
| 124362 | /************** Continuing where we left off in pragma.c *********************/ |
| 124363 | |
| 124364 | /* |
| @@ -126544,63 +126343,15 @@ | |
| 126544 | } |
| 126545 | break; |
| 126546 | } |
| 126547 | #endif |
| 126548 | |
| 126549 | #ifdef SQLITE_HAS_CODEC |
| 126550 | /* Pragma iArg |
| 126551 | ** ---------- ------ |
| 126552 | ** key 0 |
| 126553 | ** rekey 1 |
| 126554 | ** hexkey 2 |
| 126555 | ** hexrekey 3 |
| 126556 | ** textkey 4 |
| 126557 | ** textrekey 5 |
| 126558 | */ |
| 126559 | case PragTyp_KEY: { |
| 126560 | if( zRight ){ |
| 126561 | char zBuf[40]; |
| 126562 | const char *zKey = zRight; |
| 126563 | int n; |
| 126564 | if( pPragma->iArg==2 || pPragma->iArg==3 ){ |
| 126565 | u8 iByte; |
| 126566 | int i; |
| 126567 | for(i=0, iByte=0; i<sizeof(zBuf)*2 && sqlite3Isxdigit(zRight[i]); i++){ |
| 126568 | iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]); |
| 126569 | if( (i&1)!=0 ) zBuf[i/2] = iByte; |
| 126570 | } |
| 126571 | zKey = zBuf; |
| 126572 | n = i/2; |
| 126573 | }else{ |
| 126574 | n = pPragma->iArg<4 ? sqlite3Strlen30(zRight) : -1; |
| 126575 | } |
| 126576 | if( (pPragma->iArg & 1)==0 ){ |
| 126577 | rc = sqlite3_key_v2(db, zDb, zKey, n); |
| 126578 | }else{ |
| 126579 | rc = sqlite3_rekey_v2(db, zDb, zKey, n); |
| 126580 | } |
| 126581 | if( rc==SQLITE_OK && n!=0 ){ |
| 126582 | sqlite3VdbeSetNumCols(v, 1); |
| 126583 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "ok", SQLITE_STATIC); |
| 126584 | returnSingleText(v, "ok"); |
| 126585 | } |
| 126586 | } |
| 126587 | break; |
| 126588 | } |
| 126589 | #endif |
| 126590 | #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) |
| 126591 | case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){ |
| 126592 | #ifdef SQLITE_HAS_CODEC |
| 126593 | if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){ |
| 126594 | sqlite3_activate_see(&zRight[4]); |
| 126595 | } |
| 126596 | #endif |
| 126597 | #ifdef SQLITE_ENABLE_CEROD |
| 126598 | if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){ |
| 126599 | sqlite3_activate_cerod(&zRight[6]); |
| 126600 | } |
| 126601 | #endif |
| 126602 | } |
| 126603 | break; |
| 126604 | #endif |
| 126605 | |
| 126606 | } /* End of the PRAGMA switch */ |
| @@ -130671,10 +130422,11 @@ | |
| 130671 | p->pLimit = pLimit; |
| 130672 | |
| 130673 | /* Generate code to take the intersection of the two temporary |
| 130674 | ** tables. |
| 130675 | */ |
| 130676 | assert( p->pEList ); |
| 130677 | iBreak = sqlite3VdbeMakeLabel(pParse); |
| 130678 | iCont = sqlite3VdbeMakeLabel(pParse); |
| 130679 | computeLimitRegisters(pParse, p, iBreak); |
| 130680 | sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v); |
| @@ -132031,13 +131783,12 @@ | |
| 132031 | ){ |
| 132032 | int i; |
| 132033 | assert( pColumn->op==TK_COLUMN ); |
| 132034 | assert( sqlite3ExprIsConstant(pValue) ); |
| 132035 | |
| 132036 | if( !ExprHasProperty(pValue, EP_FixedCol) && sqlite3ExprAffinity(pValue)!=0 ){ |
| 132037 | return; |
| 132038 | } |
| 132039 | if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){ |
| 132040 | return; |
| 132041 | } |
| 132042 | |
| 132043 | /* 2018-10-25 ticket [cf5ed20f] |
| @@ -132056,13 +131807,10 @@ | |
| 132056 | pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr, |
| 132057 | pConst->nConst*2*sizeof(Expr*)); |
| 132058 | if( pConst->apExpr==0 ){ |
| 132059 | pConst->nConst = 0; |
| 132060 | }else{ |
| 132061 | if( ExprHasProperty(pValue, EP_FixedCol) ){ |
| 132062 | pValue = pValue->pLeft; |
| 132063 | } |
| 132064 | pConst->apExpr[pConst->nConst*2-2] = pColumn; |
| 132065 | pConst->apExpr[pConst->nConst*2-1] = pValue; |
| 132066 | } |
| 132067 | } |
| 132068 | |
| @@ -132334,11 +132082,11 @@ | |
| 132334 | static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){ |
| 132335 | int eRet = WHERE_ORDERBY_NORMAL; /* Return value */ |
| 132336 | ExprList *pEList = pFunc->x.pList; /* Arguments to agg function */ |
| 132337 | const char *zFunc; /* Name of aggregate function pFunc */ |
| 132338 | ExprList *pOrderBy; |
| 132339 | u8 sortFlags; |
| 132340 | |
| 132341 | assert( *ppMinMax==0 ); |
| 132342 | assert( pFunc->op==TK_AGG_FUNCTION ); |
| 132343 | assert( !IsWindowFunc(pFunc) ); |
| 132344 | if( pEList==0 || pEList->nExpr!=1 || ExprHasProperty(pFunc, EP_WinFunc) ){ |
| @@ -132345,11 +132093,13 @@ | |
| 132345 | return eRet; |
| 132346 | } |
| 132347 | zFunc = pFunc->u.zToken; |
| 132348 | if( sqlite3StrICmp(zFunc, "min")==0 ){ |
| 132349 | eRet = WHERE_ORDERBY_MIN; |
| 132350 | sortFlags = KEYINFO_ORDER_BIGNULL; |
| 132351 | }else if( sqlite3StrICmp(zFunc, "max")==0 ){ |
| 132352 | eRet = WHERE_ORDERBY_MAX; |
| 132353 | sortFlags = KEYINFO_ORDER_DESC; |
| 132354 | }else{ |
| 132355 | return eRet; |
| @@ -133013,11 +132763,11 @@ | |
| 133013 | pExpr = pRight; |
| 133014 | } |
| 133015 | pNew = sqlite3ExprListAppend(pParse, pNew, pExpr); |
| 133016 | sqlite3TokenInit(&sColname, zColname); |
| 133017 | sqlite3ExprListSetName(pParse, pNew, &sColname, 0); |
| 133018 | if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){ |
| 133019 | struct ExprList_item *pX = &pNew->a[pNew->nExpr-1]; |
| 133020 | sqlite3DbFree(db, pX->zEName); |
| 133021 | if( pSub ){ |
| 133022 | pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName); |
| 133023 | testcase( pX->zEName==0 ); |
| @@ -133358,11 +133108,11 @@ | |
| 133358 | sqlite3ExprCode(pParse, pC->pExpr, pC->iMem); |
| 133359 | } |
| 133360 | |
| 133361 | pAggInfo->directMode = 0; |
| 133362 | if( addrHitTest ){ |
| 133363 | sqlite3VdbeJumpHere(v, addrHitTest); |
| 133364 | } |
| 133365 | } |
| 133366 | |
| 133367 | /* |
| 133368 | ** Add a single OP_Explain instruction to the VDBE to explain a simple |
| @@ -136671,11 +136421,13 @@ | |
| 136671 | if( eOnePass==ONEPASS_MULTI && (nIdx-(aiCurOnePass[1]>=0))>0 ){ |
| 136672 | addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); |
| 136673 | } |
| 136674 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur, |
| 136675 | aToOpen, 0, 0); |
| 136676 | if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce); |
| 136677 | } |
| 136678 | |
| 136679 | /* Top of the update loop */ |
| 136680 | if( eOnePass!=ONEPASS_OFF ){ |
| 136681 | if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){ |
| @@ -137626,21 +137378,10 @@ | |
| 137626 | } |
| 137627 | db->mDbFlags |= DBFLAG_VacuumInto; |
| 137628 | } |
| 137629 | nRes = sqlite3BtreeGetOptimalReserve(pMain); |
| 137630 | |
| 137631 | /* A VACUUM cannot change the pagesize of an encrypted database. */ |
| 137632 | #ifdef SQLITE_HAS_CODEC |
| 137633 | if( db->nextPagesize ){ |
| 137634 | extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*); |
| 137635 | int nKey; |
| 137636 | char *zKey; |
| 137637 | sqlite3CodecGetKey(db, iDb, (void**)&zKey, &nKey); |
| 137638 | if( nKey ) db->nextPagesize = 0; |
| 137639 | } |
| 137640 | #endif |
| 137641 | |
| 137642 | sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size); |
| 137643 | sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0)); |
| 137644 | sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF|PAGER_CACHESPILL); |
| 137645 | |
| 137646 | /* Begin a transaction and take an exclusive lock on the main database |
| @@ -139443,10 +139184,16 @@ | |
| 139443 | #define TERM_LIKEOPT 0x0100 /* Virtual terms from the LIKE optimization */ |
| 139444 | #define TERM_LIKECOND 0x0200 /* Conditionally this LIKE operator term */ |
| 139445 | #define TERM_LIKE 0x0400 /* The original LIKE operator */ |
| 139446 | #define TERM_IS 0x0800 /* Term.pExpr is an IS operator */ |
| 139447 | #define TERM_VARSELECT 0x1000 /* Term.pExpr contains a correlated sub-query */ |
| 139448 | |
| 139449 | /* |
| 139450 | ** An instance of the WhereScan object is used as an iterator for locating |
| 139451 | ** terms in the WHERE clause that are useful to the query planner. |
| 139452 | */ |
| @@ -139557,17 +139304,20 @@ | |
| 139557 | WhereOrSet *pOrSet; /* Record best loops here, if not NULL */ |
| 139558 | #ifdef SQLITE_ENABLE_STAT4 |
| 139559 | UnpackedRecord *pRec; /* Probe for stat4 (if required) */ |
| 139560 | int nRecValid; /* Number of valid fields currently in pRec */ |
| 139561 | #endif |
| 139562 | unsigned int bldFlags; /* SQLITE_BLDF_* flags */ |
| 139563 | unsigned int iPlanLimit; /* Search limiter */ |
| 139564 | }; |
| 139565 | |
| 139566 | /* Allowed values for WhereLoopBuider.bldFlags */ |
| 139567 | #define SQLITE_BLDF_INDEXED 0x0001 /* An index is used */ |
| 139568 | #define SQLITE_BLDF_UNIQUE 0x0002 /* All keys of a UNIQUE index used */ |
| 139569 | |
| 139570 | /* The WhereLoopBuilder.iPlanLimit is used to limit the number of |
| 139571 | ** index+constraint combinations the query planner will consider for a |
| 139572 | ** particular query. If this parameter is unlimited, then certain |
| 139573 | ** pathological queries can spend excess time in the sqlite3WhereBegin() |
| @@ -141177,11 +140927,13 @@ | |
| 141177 | if( pCompare ){ |
| 141178 | pCompare->pLeft = pTerm->pExpr->pLeft; |
| 141179 | pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0); |
| 141180 | if( pRight ){ |
| 141181 | pRight->iTable = iReg+j+2; |
| 141182 | sqlite3ExprIfFalse(pParse, pCompare, pLevel->addrCont, 0); |
| 141183 | } |
| 141184 | pCompare->pLeft = 0; |
| 141185 | sqlite3ExprDelete(db, pCompare); |
| 141186 | } |
| 141187 | } |
| @@ -142591,11 +142343,12 @@ | |
| 142591 | ** |
| 142592 | ** vtab_column MATCH expression |
| 142593 | ** MATCH(expression,vtab_column) |
| 142594 | */ |
| 142595 | pCol = pList->a[1].pExpr; |
| 142596 | if( pCol->op==TK_COLUMN && IsVirtual(pCol->y.pTab) ){ |
| 142597 | for(i=0; i<ArraySize(aOp); i++){ |
| 142598 | if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){ |
| 142599 | *peOp2 = aOp[i].eOp2; |
| 142600 | *ppRight = pList->a[0].pExpr; |
| 142601 | *ppLeft = pCol; |
| @@ -142613,11 +142366,12 @@ | |
| 142613 | ** Historically, xFindFunction expected to see lower-case function |
| 142614 | ** names. But for this use case, xFindFunction is expected to deal |
| 142615 | ** with function names in an arbitrary case. |
| 142616 | */ |
| 142617 | pCol = pList->a[0].pExpr; |
| 142618 | if( pCol->op==TK_COLUMN && IsVirtual(pCol->y.pTab) ){ |
| 142619 | sqlite3_vtab *pVtab; |
| 142620 | sqlite3_module *pMod; |
| 142621 | void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**); |
| 142622 | void *pNotUsed; |
| 142623 | pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab; |
| @@ -142636,14 +142390,16 @@ | |
| 142636 | } |
| 142637 | }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){ |
| 142638 | int res = 0; |
| 142639 | Expr *pLeft = pExpr->pLeft; |
| 142640 | Expr *pRight = pExpr->pRight; |
| 142641 | if( pLeft->op==TK_COLUMN && IsVirtual(pLeft->y.pTab) ){ |
| 142642 | res++; |
| 142643 | } |
| 142644 | if( pRight && pRight->op==TK_COLUMN && IsVirtual(pRight->y.pTab) ){ |
| 142645 | res++; |
| 142646 | SWAP(Expr*, pLeft, pRight); |
| 142647 | } |
| 142648 | *ppLeft = pLeft; |
| 142649 | *ppRight = pRight; |
| @@ -146123,20 +145879,25 @@ | |
| 146123 | pLoop->nOut += pTerm->truthProb; |
| 146124 | }else{ |
| 146125 | /* In the absence of explicit truth probabilities, use heuristics to |
| 146126 | ** guess a reasonable truth probability. */ |
| 146127 | pLoop->nOut--; |
| 146128 | if( pTerm->eOperator&(WO_EQ|WO_IS) ){ |
| 146129 | Expr *pRight = pTerm->pExpr->pRight; |
| 146130 | int k = 0; |
| 146131 | testcase( pTerm->pExpr->op==TK_IS ); |
| 146132 | if( sqlite3ExprIsInteger(pRight, &k) && k>=(-1) && k<=1 ){ |
| 146133 | k = 10; |
| 146134 | }else{ |
| 146135 | k = 20; |
| 146136 | } |
| 146137 | if( iReduce<k ) iReduce = k; |
| 146138 | } |
| 146139 | } |
| 146140 | } |
| 146141 | } |
| 146142 | if( pLoop->nOut > nRow-iReduce ) pLoop->nOut = nRow - iReduce; |
| @@ -146314,13 +146075,13 @@ | |
| 146314 | ){ |
| 146315 | continue; |
| 146316 | } |
| 146317 | |
| 146318 | if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){ |
| 146319 | pBuilder->bldFlags |= SQLITE_BLDF_UNIQUE; |
| 146320 | }else{ |
| 146321 | pBuilder->bldFlags |= SQLITE_BLDF_INDEXED; |
| 146322 | } |
| 146323 | pNew->wsFlags = saved_wsFlags; |
| 146324 | pNew->u.btree.nEq = saved_nEq; |
| 146325 | pNew->u.btree.nBtm = saved_nBtm; |
| 146326 | pNew->u.btree.nTop = saved_nTop; |
| @@ -146481,10 +146242,31 @@ | |
| 146481 | } |
| 146482 | if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; |
| 146483 | if( rc!=SQLITE_OK ) break; /* Jump out of the pTerm loop */ |
| 146484 | if( nOut ){ |
| 146485 | pNew->nOut = sqlite3LogEst(nOut); |
| 146486 | if( pNew->nOut>saved_nOut ) pNew->nOut = saved_nOut; |
| 146487 | pNew->nOut -= nIn; |
| 146488 | } |
| 146489 | } |
| 146490 | if( nOut==0 ) |
| @@ -146557,10 +146339,11 @@ | |
| 146557 | assert( 42==sqlite3LogEst(18) ); |
| 146558 | if( saved_nEq==saved_nSkip |
| 146559 | && saved_nEq+1<pProbe->nKeyCol |
| 146560 | && saved_nEq==pNew->nLTerm |
| 146561 | && pProbe->noSkipScan==0 |
| 146562 | && OptimizationEnabled(db, SQLITE_SkipScan) |
| 146563 | && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */ |
| 146564 | && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK |
| 146565 | ){ |
| 146566 | LogEst nIter; |
| @@ -146904,13 +146687,13 @@ | |
| 146904 | pNew->nOut = rSize; |
| 146905 | if( rc ) break; |
| 146906 | } |
| 146907 | } |
| 146908 | |
| 146909 | pBuilder->bldFlags = 0; |
| 146910 | rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0); |
| 146911 | if( pBuilder->bldFlags==SQLITE_BLDF_INDEXED ){ |
| 146912 | /* If a non-unique index is used, or if a prefix of the key for |
| 146913 | ** unique index is used (making the index functionally non-unique) |
| 146914 | ** then the sqlite_stat1 data becomes important for scoring the |
| 146915 | ** plan */ |
| 146916 | pTab->tabFlags |= TF_StatsUsed; |
| @@ -147577,12 +147360,15 @@ | |
| 147577 | assert( wctrlFlags & WHERE_ORDERBY_LIMIT ); |
| 147578 | for(j=0; j<pLoop->nLTerm && pTerm!=pLoop->aLTerm[j]; j++){} |
| 147579 | if( j>=pLoop->nLTerm ) continue; |
| 147580 | } |
| 147581 | if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 && pOBExpr->iColumn>=0 ){ |
| 147582 | if( sqlite3ExprCollSeqMatch(pWInfo->pParse, |
| 147583 | pOrderBy->a[i].pExpr, pTerm->pExpr)==0 ){ |
| 147584 | continue; |
| 147585 | } |
| 147586 | testcase( pTerm->pExpr->op==TK_IS ); |
| 147587 | } |
| 147588 | obSat |= MASKBIT(i); |
| @@ -148358,10 +148144,32 @@ | |
| 148358 | w.xSelectCallback = sqlite3SelectWalkFail; |
| 148359 | sqlite3WalkExpr(&w, p); |
| 148360 | return w.eCode; |
| 148361 | } |
| 148362 | |
| 148363 | /* |
| 148364 | ** Generate the beginning of the loop used for WHERE clause processing. |
| 148365 | ** The return value is a pointer to an opaque structure that contains |
| 148366 | ** information needed to terminate the loop. Later, the calling routine |
| 148367 | ** should invoke sqlite3WhereEnd() with the return value of this function |
| @@ -148659,23 +148467,32 @@ | |
| 148659 | #endif |
| 148660 | |
| 148661 | if( nTabList!=1 || whereShortCut(&sWLB)==0 ){ |
| 148662 | rc = whereLoopAddAll(&sWLB); |
| 148663 | if( rc ) goto whereBeginError; |
| 148664 | |
| 148665 | #ifdef WHERETRACE_ENABLED |
| 148666 | if( sqlite3WhereTrace ){ /* Display all of the WhereLoop objects */ |
| 148667 | WhereLoop *p; |
| 148668 | int i; |
| 148669 | static const char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz" |
| 148670 | "ABCDEFGHIJKLMNOPQRSTUVWYXZ"; |
| 148671 | for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){ |
| 148672 | p->cId = zLabel[i%(sizeof(zLabel)-1)]; |
| 148673 | sqlite3WhereLoopPrint(p, sWLB.pWC); |
| 148674 | } |
| 148675 | } |
| 148676 | #endif |
| 148677 | |
| 148678 | wherePathSolver(pWInfo, 0); |
| 148679 | if( db->mallocFailed ) goto whereBeginError; |
| 148680 | if( pWInfo->pOrderBy ){ |
| 148681 | wherePathSolver(pWInfo, pWInfo->nRowOut+1); |
| @@ -156496,10 +156313,16 @@ | |
| 156496 | ** simplify to constants 0 (false) and 1 (true), respectively, |
| 156497 | ** regardless of the value of expr1. |
| 156498 | */ |
| 156499 | sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy202); |
| 156500 | yymsp[-4].minor.yy202 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy192 ? "1" : "0"); |
| 156501 | }else{ |
| 156502 | yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy202, 0); |
| 156503 | if( yymsp[-4].minor.yy202 ){ |
| 156504 | yymsp[-4].minor.yy202->x.pList = yymsp[-1].minor.yy242; |
| 156505 | sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy202); |
| @@ -157767,16 +157590,21 @@ | |
| 157767 | const char *zKW; |
| 157768 | if( n>=2 ){ |
| 157769 | i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n) % 127; |
| 157770 | for(i=((int)aKWHash[i])-1; i>=0; i=((int)aKWNext[i])-1){ |
| 157771 | if( aKWLen[i]!=n ) continue; |
| 157772 | j = 0; |
| 157773 | zKW = &zKWText[aKWOffset[i]]; |
| 157774 | #ifdef SQLITE_ASCII |
| 157775 | while( j<n && (z[j]&~0x20)==zKW[j] ){ j++; } |
| 157776 | #endif |
| 157777 | #ifdef SQLITE_EBCDIC |
| 157778 | while( j<n && toupper(z[j])==zKW[j] ){ j++; } |
| 157779 | #endif |
| 157780 | if( j<n ) continue; |
| 157781 | testcase( i==0 ); /* REINDEX */ |
| 157782 | testcase( i==1 ); /* INDEXED */ |
| @@ -159218,11 +159046,14 @@ | |
| 159218 | /* If SQLite is already completely initialized, then this call |
| 159219 | ** to sqlite3_initialize() should be a no-op. But the initialization |
| 159220 | ** must be complete. So isInit must not be set until the very end |
| 159221 | ** of this routine. |
| 159222 | */ |
| 159223 | if( sqlite3GlobalConfig.isInit ) return SQLITE_OK; |
| 159224 | |
| 159225 | /* Make sure the mutex subsystem is initialized. If unable to |
| 159226 | ** initialize the mutex subsystem, return early with the error. |
| 159227 | ** If the system is so sick that we are unable to allocate a mutex, |
| 159228 | ** there is not much SQLite is going to be able to do. |
| @@ -161807,13 +161638,15 @@ | |
| 161807 | ** *pFlags may be updated before returning if the URI filename contains |
| 161808 | ** "cache=xxx" or "mode=xxx" query parameters. |
| 161809 | ** |
| 161810 | ** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to |
| 161811 | ** the VFS that should be used to open the database file. *pzFile is set to |
| 161812 | ** point to a buffer containing the name of the file to open. It is the |
| 161813 | ** responsibility of the caller to eventually call sqlite3_free() to release |
| 161814 | ** this buffer. |
| 161815 | ** |
| 161816 | ** If an error occurs, then an SQLite error code is returned and *pzErrMsg |
| 161817 | ** may be set to point to a buffer containing an English language error |
| 161818 | ** message. It is the responsibility of the caller to eventually release |
| 161819 | ** this buffer by calling sqlite3_free(). |
| @@ -161841,19 +161674,22 @@ | |
| 161841 | ){ |
| 161842 | char *zOpt; |
| 161843 | int eState; /* Parser state when parsing URI */ |
| 161844 | int iIn; /* Input character index */ |
| 161845 | int iOut = 0; /* Output character index */ |
| 161846 | u64 nByte = nUri+2; /* Bytes of space to allocate */ |
| 161847 | |
| 161848 | /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen |
| 161849 | ** method that there may be extra parameters following the file-name. */ |
| 161850 | flags |= SQLITE_OPEN_URI; |
| 161851 | |
| 161852 | for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&'); |
| 161853 | zFile = sqlite3_malloc64(nByte); |
| 161854 | if( !zFile ) return SQLITE_NOMEM_BKPT; |
| 161855 | |
| 161856 | iIn = 5; |
| 161857 | #ifdef SQLITE_ALLOW_URI_AUTHORITY |
| 161858 | if( strncmp(zUri+5, "///", 3)==0 ){ |
| 161859 | iIn = 7; |
| @@ -161940,12 +161776,11 @@ | |
| 161940 | eState = 1; |
| 161941 | } |
| 161942 | zFile[iOut++] = c; |
| 161943 | } |
| 161944 | if( eState==1 ) zFile[iOut++] = '\0'; |
| 161945 | zFile[iOut++] = '\0'; |
| 161946 | zFile[iOut++] = '\0'; |
| 161947 | |
| 161948 | /* Check if there were any options specified that should be interpreted |
| 161949 | ** here. Options that are interpreted here include "vfs" and those that |
| 161950 | ** correspond to flags that may be passed to the sqlite3_open_v2() |
| 161951 | ** method. */ |
| @@ -162021,17 +161856,18 @@ | |
| 162021 | |
| 162022 | zOpt = &zVal[nVal+1]; |
| 162023 | } |
| 162024 | |
| 162025 | }else{ |
| 162026 | zFile = sqlite3_malloc64(nUri+2); |
| 162027 | if( !zFile ) return SQLITE_NOMEM_BKPT; |
| 162028 | if( nUri ){ |
| 162029 | memcpy(zFile, zUri, nUri); |
| 162030 | } |
| 162031 | zFile[nUri] = '\0'; |
| 162032 | zFile[nUri+1] = '\0'; |
| 162033 | flags &= ~SQLITE_OPEN_URI; |
| 162034 | } |
| 162035 | |
| 162036 | *ppVfs = sqlite3_vfs_find(zVfs); |
| 162037 | if( *ppVfs==0 ){ |
| @@ -162038,51 +161874,33 @@ | |
| 162038 | *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs); |
| 162039 | rc = SQLITE_ERROR; |
| 162040 | } |
| 162041 | parse_uri_out: |
| 162042 | if( rc!=SQLITE_OK ){ |
| 162043 | sqlite3_free(zFile); |
| 162044 | zFile = 0; |
| 162045 | } |
| 162046 | *pFlags = flags; |
| 162047 | *pzFile = zFile; |
| 162048 | return rc; |
| 162049 | } |
| 162050 | |
| 162051 | #if defined(SQLITE_HAS_CODEC) |
| 162052 | /* |
| 162053 | ** Process URI filename query parameters relevant to the SQLite Encryption |
| 162054 | ** Extension. Return true if any of the relevant query parameters are |
| 162055 | ** seen and return false if not. |
| 162056 | */ |
| 162057 | SQLITE_PRIVATE int sqlite3CodecQueryParameters( |
| 162058 | sqlite3 *db, /* Database connection */ |
| 162059 | const char *zDb, /* Which schema is being created/attached */ |
| 162060 | const char *zUri /* URI filename */ |
| 162061 | ){ |
| 162062 | const char *zKey; |
| 162063 | if( (zKey = sqlite3_uri_parameter(zUri, "hexkey"))!=0 && zKey[0] ){ |
| 162064 | u8 iByte; |
| 162065 | int i; |
| 162066 | char zDecoded[40]; |
| 162067 | for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){ |
| 162068 | iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]); |
| 162069 | if( (i&1)!=0 ) zDecoded[i/2] = iByte; |
| 162070 | } |
| 162071 | sqlite3_key_v2(db, zDb, zDecoded, i/2); |
| 162072 | return 1; |
| 162073 | }else if( (zKey = sqlite3_uri_parameter(zUri, "key"))!=0 ){ |
| 162074 | sqlite3_key_v2(db, zDb, zKey, sqlite3Strlen30(zKey)); |
| 162075 | return 1; |
| 162076 | }else if( (zKey = sqlite3_uri_parameter(zUri, "textkey"))!=0 ){ |
| 162077 | sqlite3_key_v2(db, zDb, zKey, -1); |
| 162078 | return 1; |
| 162079 | }else{ |
| 162080 | return 0; |
| 162081 | } |
| 162082 | } |
| 162083 | #endif |
| 162084 | |
| 162085 | |
| 162086 | /* |
| 162087 | ** This routine does the work of opening a database on behalf of |
| 162088 | ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename" |
| @@ -162463,14 +162281,11 @@ | |
| 162463 | /* Opening a db handle. Fourth parameter is passed 0. */ |
| 162464 | void *pArg = sqlite3GlobalConfig.pSqllogArg; |
| 162465 | sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0); |
| 162466 | } |
| 162467 | #endif |
| 162468 | #if defined(SQLITE_HAS_CODEC) |
| 162469 | if( rc==SQLITE_OK ) sqlite3CodecQueryParameters(db, 0, zOpen); |
| 162470 | #endif |
| 162471 | sqlite3_free(zOpen); |
| 162472 | return rc & 0xff; |
| 162473 | } |
| 162474 | |
| 162475 | |
| 162476 | /* |
| @@ -162693,17 +162508,19 @@ | |
| 162693 | } |
| 162694 | SQLITE_PRIVATE int sqlite3CantopenError(int lineno){ |
| 162695 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 162696 | return sqlite3ReportError(SQLITE_CANTOPEN, lineno, "cannot open file"); |
| 162697 | } |
| 162698 | #ifdef SQLITE_DEBUG |
| 162699 | SQLITE_PRIVATE int sqlite3CorruptPgnoError(int lineno, Pgno pgno){ |
| 162700 | char zMsg[100]; |
| 162701 | sqlite3_snprintf(sizeof(zMsg), zMsg, "database corruption page %d", pgno); |
| 162702 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 162703 | return sqlite3ReportError(SQLITE_CORRUPT, lineno, zMsg); |
| 162704 | } |
| 162705 | SQLITE_PRIVATE int sqlite3NomemError(int lineno){ |
| 162706 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 162707 | return sqlite3ReportError(SQLITE_NOMEM, lineno, "OOM"); |
| 162708 | } |
| 162709 | SQLITE_PRIVATE int sqlite3IoerrnomemError(int lineno){ |
| @@ -163314,10 +163131,72 @@ | |
| 163314 | while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){ |
| 163315 | zName--; |
| 163316 | } |
| 163317 | return zName; |
| 163318 | } |
| 163319 | |
| 163320 | /* |
| 163321 | ** This is a utility routine, useful to VFS implementations, that checks |
| 163322 | ** to see if a database file was a URI that contained a specific query |
| 163323 | ** parameter, and if so obtains the value of the query parameter. |
| @@ -163329,18 +163208,11 @@ | |
| 163329 | ** returns a NULL pointer. |
| 163330 | */ |
| 163331 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){ |
| 163332 | if( zFilename==0 || zParam==0 ) return 0; |
| 163333 | zFilename = databaseName(zFilename); |
| 163334 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 163335 | while( zFilename[0] ){ |
| 163336 | int x = strcmp(zFilename, zParam); |
| 163337 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 163338 | if( x==0 ) return zFilename; |
| 163339 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 163340 | } |
| 163341 | return 0; |
| 163342 | } |
| 163343 | |
| 163344 | /* |
| 163345 | ** Return a pointer to the name of Nth query parameter of the filename. |
| 163346 | */ |
| @@ -163390,11 +163262,10 @@ | |
| 163390 | ** an error that we cannot easily detect but that will likely cause memory |
| 163391 | ** corruption. |
| 163392 | */ |
| 163393 | SQLITE_API const char *sqlite3_filename_database(const char *zFilename){ |
| 163394 | return databaseName(zFilename); |
| 163395 | return sqlite3_uri_parameter(zFilename - 3, "\003"); |
| 163396 | } |
| 163397 | SQLITE_API const char *sqlite3_filename_journal(const char *zFilename){ |
| 163398 | zFilename = databaseName(zFilename); |
| 163399 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 163400 | while( zFilename[0] ){ |
| @@ -174985,11 +174856,11 @@ | |
| 174985 | int nByte = sqlite3_value_bytes(apVal[0]); |
| 174986 | pCsr->zInput = sqlite3_malloc64(nByte+1); |
| 174987 | if( pCsr->zInput==0 ){ |
| 174988 | rc = SQLITE_NOMEM; |
| 174989 | }else{ |
| 174990 | memcpy(pCsr->zInput, zByte, nByte); |
| 174991 | pCsr->zInput[nByte] = 0; |
| 174992 | rc = pTab->pMod->xOpen(pTab->pTok, pCsr->zInput, nByte, &pCsr->pCsr); |
| 174993 | if( rc==SQLITE_OK ){ |
| 174994 | pCsr->pCsr->pTokenizer = pTab->pTok; |
| 174995 | } |
| @@ -177595,11 +177466,11 @@ | |
| 177595 | sqlite3_stmt *pStmt; |
| 177596 | int rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR_MAX_LEVEL, &pStmt, 0); |
| 177597 | if( rc!=SQLITE_OK ) return rc; |
| 177598 | sqlite3_bind_int64(pStmt, 1, iAbsLevel+1); |
| 177599 | sqlite3_bind_int64(pStmt, 2, |
| 177600 | ((iAbsLevel/FTS3_SEGDIR_MAXLEVEL)+1) * FTS3_SEGDIR_MAXLEVEL |
| 177601 | ); |
| 177602 | |
| 177603 | *pbMax = 0; |
| 177604 | if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 177605 | *pbMax = sqlite3_column_type(pStmt, 0)==SQLITE_NULL; |
| @@ -223667,11 +223538,11 @@ | |
| 223667 | int nArg, /* Number of args */ |
| 223668 | sqlite3_value **apUnused /* Function arguments */ |
| 223669 | ){ |
| 223670 | assert( nArg==0 ); |
| 223671 | UNUSED_PARAM2(nArg, apUnused); |
| 223672 | sqlite3_result_text(pCtx, "fts5: 2020-01-28 15:02:23 04885763c4cd00cbca26d048f2b19316bfc93e8edebeceaa171ebfc6c563d53e", -1, SQLITE_TRANSIENT); |
| 223673 | } |
| 223674 | |
| 223675 | /* |
| 223676 | ** Return true if zName is the extension on one of the shadow tables used |
| 223677 | ** by this module. |
| @@ -227410,10 +227281,11 @@ | |
| 227410 | char *zFts5Tbl; /* Name of fts5 table */ |
| 227411 | char *zFts5Db; /* Db containing fts5 table */ |
| 227412 | sqlite3 *db; /* Database handle */ |
| 227413 | Fts5Global *pGlobal; /* FTS5 global object for this database */ |
| 227414 | int eType; /* FTS5_VOCAB_COL, ROW or INSTANCE */ |
| 227415 | }; |
| 227416 | |
| 227417 | struct Fts5VocabCursor { |
| 227418 | sqlite3_vtab_cursor base; |
| 227419 | sqlite3_stmt *pStmt; /* Statement holding lock on pIndex */ |
| @@ -227692,10 +227564,16 @@ | |
| 227692 | Fts5VocabCursor *pCsr = 0; |
| 227693 | int rc = SQLITE_OK; |
| 227694 | sqlite3_stmt *pStmt = 0; |
| 227695 | char *zSql = 0; |
| 227696 | |
| 227697 | zSql = sqlite3Fts5Mprintf(&rc, |
| 227698 | "SELECT t.%Q FROM %Q.%Q AS t WHERE t.%Q MATCH '*id'", |
| 227699 | pTab->zFts5Tbl, pTab->zFts5Db, pTab->zFts5Tbl, pTab->zFts5Tbl |
| 227700 | ); |
| 227701 | if( zSql ){ |
| @@ -227703,14 +227581,16 @@ | |
| 227703 | } |
| 227704 | sqlite3_free(zSql); |
| 227705 | assert( rc==SQLITE_OK || pStmt==0 ); |
| 227706 | if( rc==SQLITE_ERROR ) rc = SQLITE_OK; |
| 227707 | |
| 227708 | if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 227709 | i64 iId = sqlite3_column_int64(pStmt, 0); |
| 227710 | pFts5 = sqlite3Fts5TableFromCsrid(pTab->pGlobal, iId); |
| 227711 | } |
| 227712 | |
| 227713 | if( rc==SQLITE_OK ){ |
| 227714 | if( pFts5==0 ){ |
| 227715 | rc = sqlite3_finalize(pStmt); |
| 227716 | pStmt = 0; |
| @@ -228440,12 +228320,12 @@ | |
| 228440 | } |
| 228441 | #endif /* SQLITE_CORE */ |
| 228442 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 228443 | |
| 228444 | /************** End of stmt.c ************************************************/ |
| 228445 | #if __LINE__!=228445 |
| 228446 | #undef SQLITE_SOURCE_ID |
| 228447 | #define SQLITE_SOURCE_ID "2020-01-28 15:02:23 04885763c4cd00cbca26d048f2b19316bfc93e8edebeceaa171ebfc6c563alt2" |
| 228448 | #endif |
| 228449 | /* Return the source-id for this library */ |
| 228450 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 228451 | /************************** End of sqlite3.c ******************************/ |
| 228452 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.32.0. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -378,13 +378,10 @@ | |
| 378 | "FTS5_ENABLE_TEST_MI", |
| 379 | #endif |
| 380 | #if SQLITE_FTS5_NO_WITHOUT_ROWID |
| 381 | "FTS5_NO_WITHOUT_ROWID", |
| 382 | #endif |
| 383 | #if HAVE_ISNAN || SQLITE_HAVE_ISNAN |
| 384 | "HAVE_ISNAN", |
| 385 | #endif |
| 386 | #if SQLITE_HOMEGROWN_RECURSIVE_MUTEX |
| 387 | "HOMEGROWN_RECURSIVE_MUTEX", |
| @@ -1163,13 +1160,13 @@ | |
| 1160 | ** |
| 1161 | ** See also: [sqlite3_libversion()], |
| 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | */ |
| 1165 | #define SQLITE_VERSION "3.32.0" |
| 1166 | #define SQLITE_VERSION_NUMBER 3032000 |
| 1167 | #define SQLITE_SOURCE_ID "2020-02-27 16:21:39 951b39ca74c9bd933139e099d5555283278db475f410f202c162e5d1e6aef933" |
| 1168 | |
| 1169 | /* |
| 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | ** |
| @@ -4657,10 +4654,63 @@ | |
| 4654 | */ |
| 4655 | SQLITE_API const char *sqlite3_filename_database(const char*); |
| 4656 | SQLITE_API const char *sqlite3_filename_journal(const char*); |
| 4657 | SQLITE_API const char *sqlite3_filename_wal(const char*); |
| 4658 | |
| 4659 | /* |
| 4660 | ** CAPI3REF: Create and Destroy VFS Filenames |
| 4661 | ** |
| 4662 | ** These interfces are provided for use by [VFS shim] implementations and |
| 4663 | ** are not useful outside of that context. |
| 4664 | ** |
| 4665 | ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of |
| 4666 | ** database filename D with corresponding journal file J and WAL file W and |
| 4667 | ** with N URI parameters key/values pairs in the array P. The result from |
| 4668 | ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that |
| 4669 | ** is safe to pass to routines like: |
| 4670 | ** <ul> |
| 4671 | ** <li> [sqlite3_uri_parameter()], |
| 4672 | ** <li> [sqlite3_uri_boolean()], |
| 4673 | ** <li> [sqlite3_uri_int64()], |
| 4674 | ** <li> [sqlite3_uri_key()], |
| 4675 | ** <li> [sqlite3_filename_database()], |
| 4676 | ** <li> [sqlite3_filename_journal()], or |
| 4677 | ** <li> [sqlite3_filename_wal()]. |
| 4678 | ** </ul> |
| 4679 | ** If a memory allocation error occurs, sqlite3_create_filename() might |
| 4680 | ** return a NULL pointer. The memory obtained from sqlite3_create_filename(X) |
| 4681 | ** must be released by a corresponding call to sqlite3_free_filename(Y). |
| 4682 | ** |
| 4683 | ** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array |
| 4684 | ** of 2*N pointers to strings. Each pair of pointers in this array corresponds |
| 4685 | ** to a key and value for a query parameter. The P parameter may be a NULL |
| 4686 | ** pointer if N is zero. None of the 2*N pointers in the P array may be |
| 4687 | ** NULL pointers and key pointers should not be empty strings. |
| 4688 | ** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may |
| 4689 | ** be NULL pointers, though they can be empty strings. |
| 4690 | ** |
| 4691 | ** The sqlite3_free_filename(Y) routine releases a memory allocation |
| 4692 | ** previously obtained from sqlite3_create_filename(). Invoking |
| 4693 | ** sqlite3_free_filename(Y) is a NULL pointer is a harmless no-op. |
| 4694 | ** |
| 4695 | ** If the Y parameter to sqlite3_free_filename(Y) is anything other |
| 4696 | ** than a NULL pointer or a pointer previously acquired from |
| 4697 | ** sqlite3_create_filename(), then bad things such as heap |
| 4698 | ** corruption or segfaults may occur. The value Y should be |
| 4699 | ** used again after sqlite3_free_filename(Y) has been called. This means |
| 4700 | ** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y, |
| 4701 | ** then the corresponding [sqlite3_module.xClose() method should also be |
| 4702 | ** invoked prior to calling sqlite3_free_filename(Y). |
| 4703 | */ |
| 4704 | SQLITE_API char *sqlite3_create_filename( |
| 4705 | const char *zDatabase, |
| 4706 | const char *zJournal, |
| 4707 | const char *zWal, |
| 4708 | int nParam, |
| 4709 | const char **azParam |
| 4710 | ); |
| 4711 | SQLITE_API void sqlite3_free_filename(char*); |
| 4712 | |
| 4713 | /* |
| 4714 | ** CAPI3REF: Error Codes And Messages |
| 4715 | ** METHOD: sqlite3 |
| 4716 | ** |
| @@ -5239,11 +5289,11 @@ | |
| 5289 | ** occurrences have the same index as the first occurrence. |
| 5290 | ** ^The index for named parameters can be looked up using the |
| 5291 | ** [sqlite3_bind_parameter_index()] API if desired. ^The index |
| 5292 | ** for "?NNN" parameters is the value of NNN. |
| 5293 | ** ^The NNN value must be between 1 and the [sqlite3_limit()] |
| 5294 | ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766). |
| 5295 | ** |
| 5296 | ** ^The third argument is the value to bind to the parameter. |
| 5297 | ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
| 5298 | ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter |
| 5299 | ** is ignored and the end result is the same as sqlite3_bind_null(). |
| @@ -6857,55 +6907,10 @@ | |
| 6907 | sqlite3*, |
| 6908 | void*, |
| 6909 | void(*)(void*,sqlite3*,int eTextRep,const void*) |
| 6910 | ); |
| 6911 | |
| 6912 | #ifdef SQLITE_ENABLE_CEROD |
| 6913 | /* |
| 6914 | ** Specify the activation key for a CEROD database. Unless |
| 6915 | ** activated, none of the CEROD routines will work. |
| 6916 | */ |
| @@ -13270,13 +13275,16 @@ | |
| 13275 | #endif |
| 13276 | |
| 13277 | |
| 13278 | /* |
| 13279 | ** The maximum value of a ?nnn wildcard that the parser will accept. |
| 13280 | ** If the value exceeds 32767 then extra space is required for the Expr |
| 13281 | ** structure. But otherwise, we believe that the number can be as large |
| 13282 | ** as a signed 32-bit integer can hold. |
| 13283 | */ |
| 13284 | #ifndef SQLITE_MAX_VARIABLE_NUMBER |
| 13285 | # define SQLITE_MAX_VARIABLE_NUMBER 32766 |
| 13286 | #endif |
| 13287 | |
| 13288 | /* Maximum page size. The upper bound on this value is 65536. This a limit |
| 13289 | ** imposed by the use of 16-bit offsets within each page. |
| 13290 | ** |
| @@ -15253,12 +15261,12 @@ | |
| 15261 | #define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */ |
| 15262 | #define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */ |
| 15263 | #define OP_IncrVacuum 60 /* jump */ |
| 15264 | #define OP_VNext 61 /* jump */ |
| 15265 | #define OP_Init 62 /* jump, synopsis: Start at P2 */ |
| 15266 | #define OP_PureFunc 63 /* synopsis: r[P3]=func(r[P2@NP]) */ |
| 15267 | #define OP_Function 64 /* synopsis: r[P3]=func(r[P2@NP]) */ |
| 15268 | #define OP_Return 65 |
| 15269 | #define OP_EndCoroutine 66 |
| 15270 | #define OP_HaltIfNull 67 /* synopsis: if r[P3]=null halt */ |
| 15271 | #define OP_Halt 68 |
| 15272 | #define OP_Integer 69 /* synopsis: r[P2]=P1 */ |
| @@ -15320,12 +15328,12 @@ | |
| 15328 | #define OP_SorterData 125 /* synopsis: r[P2]=data */ |
| 15329 | #define OP_RowData 126 /* synopsis: r[P2]=data */ |
| 15330 | #define OP_Rowid 127 /* synopsis: r[P2]=rowid */ |
| 15331 | #define OP_NullRow 128 |
| 15332 | #define OP_SeekEnd 129 |
| 15333 | #define OP_IdxInsert 130 /* synopsis: key=r[P2] */ |
| 15334 | #define OP_SorterInsert 131 /* synopsis: key=r[P2] */ |
| 15335 | #define OP_IdxDelete 132 /* synopsis: key=r[P2@P3] */ |
| 15336 | #define OP_DeferredSeek 133 /* synopsis: Move P3 to P1.rowid if needed */ |
| 15337 | #define OP_IdxRowid 134 /* synopsis: r[P2]=rowid */ |
| 15338 | #define OP_FinishSeek 135 |
| 15339 | #define OP_Destroy 136 |
| @@ -15475,10 +15483,11 @@ | |
| 15483 | SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1); |
| 15484 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2); |
| 15485 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3); |
| 15486 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5); |
| 15487 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 15488 | SQLITE_PRIVATE void sqlite3VdbeJumpHereOrPopInst(Vdbe*, int addr); |
| 15489 | SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 15490 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 15491 | #ifdef SQLITE_DEBUG |
| 15492 | SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask, int); |
| 15493 | #else |
| @@ -15770,13 +15779,10 @@ | |
| 15779 | SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); |
| 15780 | |
| 15781 | /* Functions used to configure a Pager object. */ |
| 15782 | SQLITE_PRIVATE void sqlite3PagerSetBusyHandler(Pager*, int(*)(void *), void *); |
| 15783 | SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); |
| 15784 | SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int); |
| 15785 | SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int); |
| 15786 | SQLITE_PRIVATE int sqlite3PagerSetSpillsize(Pager*, int); |
| 15787 | SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64); |
| 15788 | SQLITE_PRIVATE void sqlite3PagerShrink(Pager*); |
| @@ -15866,14 +15872,10 @@ | |
| 15872 | /* Functions used to truncate the database file. */ |
| 15873 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno); |
| 15874 | |
| 15875 | SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16); |
| 15876 | |
| 15877 | /* Functions to support testing and debugging. */ |
| 15878 | #if !defined(NDEBUG) || defined(SQLITE_TEST) |
| 15879 | SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*); |
| 15880 | SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*); |
| 15881 | #endif |
| @@ -17426,12 +17428,15 @@ | |
| 17428 | ** done as a macro so that it will be optimized out when virtual |
| 17429 | ** table support is omitted from the build. |
| 17430 | */ |
| 17431 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 17432 | # define IsVirtual(X) ((X)->nModuleArg) |
| 17433 | # define ExprIsVtab(X) \ |
| 17434 | ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->nModuleArg) |
| 17435 | #else |
| 17436 | # define IsVirtual(X) 0 |
| 17437 | # define ExprIsVtab(X) 0 |
| 17438 | #endif |
| 17439 | |
| 17440 | /* |
| 17441 | ** Macros to determine if a column is hidden. IsOrdinaryHiddenColumn() |
| 17442 | ** only works for non-virtual tables (ordinary tables and views) and is |
| @@ -17785,14 +17790,14 @@ | |
| 17790 | ** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater |
| 17791 | ** than 32767 we have to make it 32-bit. 16-bit is preferred because |
| 17792 | ** it uses less memory in the Expr object, which is a big memory user |
| 17793 | ** in systems with lots of prepared statements. And few applications |
| 17794 | ** need more than about 10 or 20 variables. But some extreme users want |
| 17795 | ** to have prepared statements with over 32766 variables, and for them |
| 17796 | ** the option is available (at compile-time). |
| 17797 | */ |
| 17798 | #if SQLITE_MAX_VARIABLE_NUMBER<32767 |
| 17799 | typedef i16 ynVar; |
| 17800 | #else |
| 17801 | typedef int ynVar; |
| 17802 | #endif |
| 17803 | |
| @@ -19107,17 +19112,20 @@ | |
| 19112 | #define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__) |
| 19113 | #define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__) |
| 19114 | #ifdef SQLITE_DEBUG |
| 19115 | SQLITE_PRIVATE int sqlite3NomemError(int); |
| 19116 | SQLITE_PRIVATE int sqlite3IoerrnomemError(int); |
| 19117 | # define SQLITE_NOMEM_BKPT sqlite3NomemError(__LINE__) |
| 19118 | # define SQLITE_IOERR_NOMEM_BKPT sqlite3IoerrnomemError(__LINE__) |
| 19119 | #else |
| 19120 | # define SQLITE_NOMEM_BKPT SQLITE_NOMEM |
| 19121 | # define SQLITE_IOERR_NOMEM_BKPT SQLITE_IOERR_NOMEM |
| 19122 | #endif |
| 19123 | #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_CORRUPT_PGNO) |
| 19124 | SQLITE_PRIVATE int sqlite3CorruptPgnoError(int,Pgno); |
| 19125 | # define SQLITE_CORRUPT_PGNO(P) sqlite3CorruptPgnoError(__LINE__,(P)) |
| 19126 | #else |
| 19127 | # define SQLITE_CORRUPT_PGNO(P) sqlite3CorruptError(__LINE__) |
| 19128 | #endif |
| 19129 | |
| 19130 | /* |
| 19131 | ** FTS3 and FTS4 both require virtual table support |
| @@ -19383,15 +19391,11 @@ | |
| 19391 | SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| 19392 | SQLITE_PRIVATE void sqlite3AddGenerated(Parse*,Expr*,Token*); |
| 19393 | SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*); |
| 19394 | SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, |
| 19395 | sqlite3_vfs**,char**,char **); |
| 19396 | #define sqlite3CodecQueryParameters(A,B,C) 0 |
| 19397 | SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*); |
| 19398 | |
| 19399 | #ifdef SQLITE_UNTESTABLE |
| 19400 | # define sqlite3FaultSim(X) SQLITE_OK |
| 19401 | #else |
| @@ -19699,10 +19703,12 @@ | |
| 19703 | ** macros handle the common case without a procedure call, but then call |
| 19704 | ** the procedure for larger varints. |
| 19705 | */ |
| 19706 | #define getVarint32(A,B) \ |
| 19707 | (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B))) |
| 19708 | #define getVarint32NR(A,B) \ |
| 19709 | B=(u32)*(A);if(B>=0x80)sqlite3GetVarint32((A),(u32*)&(B)) |
| 19710 | #define putVarint32(A,B) \ |
| 19711 | (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\ |
| 19712 | sqlite3PutVarint((A),(B))) |
| 19713 | #define getVarint sqlite3GetVarint |
| 19714 | #define putVarint sqlite3PutVarint |
| @@ -20322,20 +20328,13 @@ | |
| 20328 | ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options. |
| 20329 | ** |
| 20330 | ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally |
| 20331 | ** disabled. The default value may be changed by compiling with the |
| 20332 | ** SQLITE_USE_URI symbol defined. |
| 20333 | */ |
| 20334 | #ifndef SQLITE_USE_URI |
| 20335 | # define SQLITE_USE_URI 0 |
| 20336 | #endif |
| 20337 | |
| 20338 | /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the |
| 20339 | ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if |
| 20340 | ** that compile-time option is omitted. |
| @@ -21062,10 +21061,11 @@ | |
| 21061 | SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); |
| 21062 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); |
| 21063 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); |
| 21064 | SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8); |
| 21065 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*); |
| 21066 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*); |
| 21067 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); |
| 21068 | SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); |
| 21069 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 21070 | SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*); |
| 21071 | #endif |
| @@ -25712,10 +25712,11 @@ | |
| 25712 | |
| 25713 | #ifdef SQLITE_DEBUG |
| 25714 | GLOBAL(int, mutexIsInit) = 1; |
| 25715 | #endif |
| 25716 | |
| 25717 | sqlite3MemoryBarrier(); |
| 25718 | return rc; |
| 25719 | } |
| 25720 | |
| 25721 | /* |
| 25722 | ** Shutdown the mutex system. This call frees resources allocated by |
| @@ -30544,30 +30545,10 @@ | |
| 30545 | *zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); \ |
| 30546 | *zOut++ = (u8)(c&0x00FF); \ |
| 30547 | } \ |
| 30548 | } |
| 30549 | |
| 30550 | /* |
| 30551 | ** Translate a single UTF-8 character. Return the unicode value. |
| 30552 | ** |
| 30553 | ** During translation, assume that the byte that zTerm points |
| 30554 | ** is a 0x00. |
| @@ -30740,17 +30721,47 @@ | |
| 30721 | }else{ |
| 30722 | assert( desiredEnc==SQLITE_UTF8 ); |
| 30723 | if( pMem->enc==SQLITE_UTF16LE ){ |
| 30724 | /* UTF-16 Little-endian -> UTF-8 */ |
| 30725 | while( zIn<zTerm ){ |
| 30726 | c = *(zIn++); |
| 30727 | c += (*(zIn++))<<8; |
| 30728 | if( c>=0xd800 && c<0xe000 ){ |
| 30729 | if( c>=0xdc00 || zIn>=zTerm ){ |
| 30730 | c = 0xfffd; |
| 30731 | }else{ |
| 30732 | int c2 = *(zIn++); |
| 30733 | c2 += (*(zIn++))<<8; |
| 30734 | if( c2<0xdc00 || c2>=0xe000 ){ |
| 30735 | zIn -= 2; |
| 30736 | c = 0xfffd; |
| 30737 | }else{ |
| 30738 | c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; |
| 30739 | } |
| 30740 | } |
| 30741 | } |
| 30742 | WRITE_UTF8(z, c); |
| 30743 | } |
| 30744 | }else{ |
| 30745 | /* UTF-16 Big-endian -> UTF-8 */ |
| 30746 | while( zIn<zTerm ){ |
| 30747 | c = (*(zIn++))<<8; |
| 30748 | c += *(zIn++); |
| 30749 | if( c>=0xd800 && c<0xe000 ){ |
| 30750 | if( c>=0xdc00 || zIn>=zTerm ){ |
| 30751 | c = 0xfffd; |
| 30752 | }else{ |
| 30753 | int c2 = (*(zIn++))<<8; |
| 30754 | c2 += *(zIn++); |
| 30755 | if( c2<0xdc00 || c2>=0xe000 ){ |
| 30756 | zIn -= 2; |
| 30757 | c = 0xfffd; |
| 30758 | }else{ |
| 30759 | c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; |
| 30760 | } |
| 30761 | } |
| 30762 | } |
| 30763 | WRITE_UTF8(z, c); |
| 30764 | } |
| 30765 | } |
| 30766 | pMem->n = (int)(z - zOut); |
| 30767 | } |
| @@ -30905,22 +30916,19 @@ | |
| 30916 | SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *zIn, int nChar){ |
| 30917 | int c; |
| 30918 | unsigned char const *z = zIn; |
| 30919 | int n = 0; |
| 30920 | |
| 30921 | if( SQLITE_UTF16NATIVE==SQLITE_UTF16LE ) z++; |
| 30922 | while( n<nChar ){ |
| 30923 | c = z[0]; |
| 30924 | z += 2; |
| 30925 | if( c>=0xd8 && c<0xdc && z[0]>=0xdc && z[0]<0xe0 ) z += 2; |
| 30926 | n++; |
| 30927 | } |
| 30928 | return (int)(z-(unsigned char const *)zIn) |
| 30929 | - (SQLITE_UTF16NATIVE==SQLITE_UTF16LE); |
| 30930 | } |
| 30931 | |
| 30932 | #if defined(SQLITE_TEST) |
| 30933 | /* |
| 30934 | ** This routine is called from the TCL test function "translate_selftest". |
| @@ -30944,34 +30952,10 @@ | |
| 30952 | c = sqlite3Utf8Read((const u8**)&z); |
| 30953 | t = i; |
| 30954 | if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD; |
| 30955 | if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD; |
| 30956 | assert( c==t ); |
| 30957 | assert( (z-zBuf)==n ); |
| 30958 | } |
| 30959 | } |
| 30960 | #endif /* SQLITE_TEST */ |
| 30961 | #endif /* SQLITE_OMIT_UTF16 */ |
| @@ -32234,11 +32218,11 @@ | |
| 32218 | h += 9*(1&~(h>>4)); |
| 32219 | #endif |
| 32220 | return (u8)(h & 0xf); |
| 32221 | } |
| 32222 | |
| 32223 | #if !defined(SQLITE_OMIT_BLOB_LITERAL) |
| 32224 | /* |
| 32225 | ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary |
| 32226 | ** value. Return a pointer to its binary value. Space to hold the |
| 32227 | ** binary value has been obtained from malloc and must be freed by |
| 32228 | ** the calling routine. |
| @@ -32255,11 +32239,11 @@ | |
| 32239 | } |
| 32240 | zBlob[i/2] = 0; |
| 32241 | } |
| 32242 | return zBlob; |
| 32243 | } |
| 32244 | #endif /* !SQLITE_OMIT_BLOB_LITERAL */ |
| 32245 | |
| 32246 | /* |
| 32247 | ** Log an error that is an API call on a connection pointer that should |
| 32248 | ** not have been used. The "type" of connection pointer is given as the |
| 32249 | ** argument. The zType is a word like "NULL" or "closed" or "invalid". |
| @@ -32966,12 +32950,12 @@ | |
| 32950 | /* 58 */ "ElseNotEq" OpHelp(""), |
| 32951 | /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 32952 | /* 60 */ "IncrVacuum" OpHelp(""), |
| 32953 | /* 61 */ "VNext" OpHelp(""), |
| 32954 | /* 62 */ "Init" OpHelp("Start at P2"), |
| 32955 | /* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"), |
| 32956 | /* 64 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"), |
| 32957 | /* 65 */ "Return" OpHelp(""), |
| 32958 | /* 66 */ "EndCoroutine" OpHelp(""), |
| 32959 | /* 67 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 32960 | /* 68 */ "Halt" OpHelp(""), |
| 32961 | /* 69 */ "Integer" OpHelp("r[P2]=P1"), |
| @@ -33033,12 +33017,12 @@ | |
| 33017 | /* 125 */ "SorterData" OpHelp("r[P2]=data"), |
| 33018 | /* 126 */ "RowData" OpHelp("r[P2]=data"), |
| 33019 | /* 127 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 33020 | /* 128 */ "NullRow" OpHelp(""), |
| 33021 | /* 129 */ "SeekEnd" OpHelp(""), |
| 33022 | /* 130 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 33023 | /* 131 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 33024 | /* 132 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 33025 | /* 133 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 33026 | /* 134 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 33027 | /* 135 */ "FinishSeek" OpHelp(""), |
| 33028 | /* 136 */ "Destroy" OpHelp(""), |
| @@ -33975,11 +33959,11 @@ | |
| 33959 | if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break; |
| 33960 | osClose(fd); |
| 33961 | sqlite3_log(SQLITE_WARNING, |
| 33962 | "attempt to open \"%s\" as file descriptor %d", z, fd); |
| 33963 | fd = -1; |
| 33964 | if( osOpen("/dev/null", O_RDONLY, m)<0 ) break; |
| 33965 | } |
| 33966 | if( fd>=0 ){ |
| 33967 | if( m!=0 ){ |
| 33968 | struct stat statbuf; |
| 33969 | if( osFstat(fd, &statbuf)==0 |
| @@ -51799,24 +51783,10 @@ | |
| 51783 | ** Pager.eLock may only be set to UNKNOWN_LOCK when the pager is in |
| 51784 | ** PAGER_OPEN state. |
| 51785 | */ |
| 51786 | #define UNKNOWN_LOCK (EXCLUSIVE_LOCK+1) |
| 51787 | |
| 51788 | /* |
| 51789 | ** The maximum allowed sector size. 64KiB. If the xSectorsize() method |
| 51790 | ** returns a value larger than this, then MAX_SECTOR_SIZE is used instead. |
| 51791 | ** This could conceivably cause corruption following a power failure on |
| 51792 | ** such a system. This is currently an undocumented limit. |
| @@ -52098,16 +52068,10 @@ | |
| 52068 | #ifdef SQLITE_TEST |
| 52069 | int nRead; /* Database pages read */ |
| 52070 | #endif |
| 52071 | void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */ |
| 52072 | int (*xGet)(Pager*,Pgno,DbPage**,int); /* Routine to fetch a patch */ |
| 52073 | char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */ |
| 52074 | PCache *pPCache; /* Pointer to page cache object */ |
| 52075 | #ifndef SQLITE_OMIT_WAL |
| 52076 | Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */ |
| 52077 | char *zWal; /* File name for write-ahead log */ |
| @@ -52230,13 +52194,10 @@ | |
| 52194 | ** * the desired page is not currently in the wal file. |
| 52195 | */ |
| 52196 | SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){ |
| 52197 | if( pPager->fd->pMethods==0 ) return 0; |
| 52198 | if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0; |
| 52199 | #ifndef SQLITE_OMIT_WAL |
| 52200 | if( pPager->pWal ){ |
| 52201 | u32 iRead = 0; |
| 52202 | int rc; |
| 52203 | rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead); |
| @@ -52466,15 +52427,11 @@ | |
| 52427 | */ |
| 52428 | static void setGetterMethod(Pager *pPager){ |
| 52429 | if( pPager->errCode ){ |
| 52430 | pPager->xGet = getPageError; |
| 52431 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 52432 | }else if( USEFETCH(pPager) ){ |
| 52433 | pPager->xGet = getPageMMap; |
| 52434 | #endif /* SQLITE_MAX_MMAP_SIZE>0 */ |
| 52435 | }else{ |
| 52436 | pPager->xGet = getPageNormal; |
| 52437 | } |
| @@ -53618,39 +53575,10 @@ | |
| 53575 | i -= 200; |
| 53576 | } |
| 53577 | return cksum; |
| 53578 | } |
| 53579 | |
| 53580 | /* |
| 53581 | ** Read a single page from either the journal file (if isMainJrnl==1) or |
| 53582 | ** from the sub-journal (if isMainJrnl==0) and playback that page. |
| 53583 | ** The page begins at offset *pOffset into the file. The *pOffset |
| 53584 | ** value is increased to the start of the next page in the journal. |
| @@ -53698,15 +53626,10 @@ | |
| 53626 | Pgno pgno; /* The page number of a page in journal */ |
| 53627 | u32 cksum; /* Checksum used for sanity checking */ |
| 53628 | char *aData; /* Temporary storage for the page */ |
| 53629 | sqlite3_file *jfd; /* The file descriptor for the journal file */ |
| 53630 | int isSynced; /* True if journal page is synced */ |
| 53631 | |
| 53632 | assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */ |
| 53633 | assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */ |
| 53634 | assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */ |
| 53635 | assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */ |
| @@ -53765,11 +53688,10 @@ | |
| 53688 | |
| 53689 | /* When playing back page 1, restore the nReserve setting |
| 53690 | */ |
| 53691 | if( pgno==1 && pPager->nReserve!=((u8*)aData)[20] ){ |
| 53692 | pPager->nReserve = ((u8*)aData)[20]; |
| 53693 | } |
| 53694 | |
| 53695 | /* If the pager is in CACHEMOD state, then there must be a copy of this |
| 53696 | ** page in the pager cache. In this case just update the pager cache, |
| 53697 | ** not the database file. The page is left marked dirty in this case. |
| @@ -53833,30 +53755,16 @@ | |
| 53755 | ** This is usually safe even for an encrypted database - as the data |
| 53756 | ** was encrypted before it was written to the journal file. The exception |
| 53757 | ** is if the data was just read from an in-memory sub-journal. In that |
| 53758 | ** case it must be encrypted here before it is copied into the database |
| 53759 | ** file. */ |
| 53760 | rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst); |
| 53761 | |
| 53762 | if( pgno>pPager->dbFileSize ){ |
| 53763 | pPager->dbFileSize = pgno; |
| 53764 | } |
| 53765 | if( pPager->pBackup ){ |
| 53766 | sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData); |
| 53767 | } |
| 53768 | }else if( !isMainJrnl && pPg==0 ){ |
| 53769 | /* If this is a rollback of a savepoint and data was not written to |
| 53770 | ** the database and the page is not in-memory, there is a potential |
| @@ -53903,15 +53811,10 @@ | |
| 53811 | /* If this was page 1, then restore the value of Pager.dbFileVers. |
| 53812 | ** Do this before any decoding. */ |
| 53813 | if( pgno==1 ){ |
| 53814 | memcpy(&pPager->dbFileVers, &((u8*)pData)[24],sizeof(pPager->dbFileVers)); |
| 53815 | } |
| 53816 | sqlite3PcacheRelease(pPg); |
| 53817 | } |
| 53818 | return rc; |
| 53819 | } |
| 53820 | |
| @@ -54467,12 +54370,10 @@ | |
| 54370 | }else{ |
| 54371 | u8 *dbFileVers = &((u8*)pPg->pData)[24]; |
| 54372 | memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers)); |
| 54373 | } |
| 54374 | } |
| 54375 | PAGER_INCR(sqlite3_pager_readdb_count); |
| 54376 | PAGER_INCR(pPager->nRead); |
| 54377 | IOTRACE(("PGIN %p %d\n", pPager, pPg->pgno)); |
| 54378 | PAGERTRACE(("FETCH %d page %d hash(%08x)\n", |
| 54379 | PAGERID(pPager), pPg->pgno, pager_pagehash(pPg))); |
| @@ -55212,11 +55113,10 @@ | |
| 55113 | *pPageSize = pPager->pageSize; |
| 55114 | if( rc==SQLITE_OK ){ |
| 55115 | if( nReserve<0 ) nReserve = pPager->nReserve; |
| 55116 | assert( nReserve>=0 && nReserve<1000 ); |
| 55117 | pPager->nReserve = (i16)nReserve; |
| 55118 | pagerFixMaplimit(pPager); |
| 55119 | } |
| 55120 | return rc; |
| 55121 | } |
| 55122 | |
| @@ -55608,15 +55508,10 @@ | |
| 55508 | IOTRACE(("CLOSE %p\n", pPager)) |
| 55509 | sqlite3OsClose(pPager->jfd); |
| 55510 | sqlite3OsClose(pPager->fd); |
| 55511 | sqlite3PageFree(pTmp); |
| 55512 | sqlite3PcacheClose(pPager->pPCache); |
| 55513 | assert( !pPager->aSavepoint && !pPager->pInJournal ); |
| 55514 | assert( !isOpen(pPager->jfd) && !isOpen(pPager->sjfd) ); |
| 55515 | |
| 55516 | sqlite3_free(pPager); |
| 55517 | return SQLITE_OK; |
| @@ -55863,12 +55758,11 @@ | |
| 55758 | char *pData; /* Data to write */ |
| 55759 | |
| 55760 | assert( (pList->flags&PGHDR_NEED_SYNC)==0 ); |
| 55761 | if( pList->pgno==1 ) pager_write_changecounter(pList); |
| 55762 | |
| 55763 | pData = pList->pData; |
| 55764 | |
| 55765 | /* Write out the page data. */ |
| 55766 | rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset); |
| 55767 | |
| 55768 | /* If page 1 was just written, update Pager.dbFileVers to match |
| @@ -55953,16 +55847,10 @@ | |
| 55847 | ** write the journal record into the file. */ |
| 55848 | if( rc==SQLITE_OK ){ |
| 55849 | void *pData = pPg->pData; |
| 55850 | i64 offset = (i64)pPager->nSubRec*(4+pPager->pageSize); |
| 55851 | char *pData2; |
| 55852 | pData2 = pData; |
| 55853 | PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno)); |
| 55854 | rc = write32bits(pPager->sjfd, offset, pPg->pgno); |
| 55855 | if( rc==SQLITE_OK ){ |
| 55856 | rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4); |
| @@ -56259,10 +56147,15 @@ | |
| 56147 | ** - \0 |
| 56148 | ** - Journal Path |
| 56149 | ** - \0 |
| 56150 | ** - WAL Path (zWALName) |
| 56151 | ** - \0 |
| 56152 | ** |
| 56153 | ** The sqlite3_create_filename() interface and the databaseFilename() utility |
| 56154 | ** that is used by sqlite3_filename_database() and kin also depend on the |
| 56155 | ** specific formatting and order of the various filenames, so if the format |
| 56156 | ** changes here, be sure to change it there as well. |
| 56157 | */ |
| 56158 | pPtr = (u8 *)sqlite3MallocZero( |
| 56159 | ROUND8(sizeof(*pPager)) + /* Pager structure */ |
| 56160 | ROUND8(pcacheSize) + /* PCache object */ |
| 56161 | ROUND8(pVfs->szOsFile) + /* The main db file */ |
| @@ -57040,13 +56933,10 @@ | |
| 56933 | const int bMmapOk = (pgno>1 |
| 56934 | && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY)) |
| 56935 | ); |
| 56936 | |
| 56937 | assert( USEFETCH(pPager) ); |
| 56938 | |
| 56939 | /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here |
| 56940 | ** allows the compiler optimizer to reuse the results of the "pgno>1" |
| 56941 | ** test in the previous statement, and avoid testing pgno==0 in the |
| 56942 | ** common case where pgno is large. */ |
| @@ -57371,11 +57261,11 @@ | |
| 57261 | ** contains the database locks. The following assert verifies |
| 57262 | ** that we do not. */ |
| 57263 | assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); |
| 57264 | |
| 57265 | assert( pPager->journalHdr<=pPager->journalOff ); |
| 57266 | pData2 = pPg->pData; |
| 57267 | cksum = pager_cksum(pPager, (u8*)pData2); |
| 57268 | |
| 57269 | /* Even if an IO or diskfull error occurs while journalling the |
| 57270 | ** page in the block above, set the need-sync flag for the page. |
| 57271 | ** Otherwise, when the transaction is rolled back, the logic in |
| @@ -57736,11 +57626,11 @@ | |
| 57626 | |
| 57627 | /* If running in direct mode, write the contents of page 1 to the file. */ |
| 57628 | if( DIRECT_MODE ){ |
| 57629 | const void *zBuf; |
| 57630 | assert( pPager->dbFileSize>0 ); |
| 57631 | zBuf = pPgHdr->pData; |
| 57632 | if( rc==SQLITE_OK ){ |
| 57633 | rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0); |
| 57634 | pPager->aStat[PAGER_STAT_WRITE]++; |
| 57635 | } |
| 57636 | if( rc==SQLITE_OK ){ |
| @@ -58446,11 +58336,11 @@ | |
| 58336 | ** |
| 58337 | ** The return value to this routine is always safe to use with |
| 58338 | ** sqlite3_uri_parameter() and sqlite3_filename_database() and friends. |
| 58339 | */ |
| 58340 | SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager *pPager, int nullIfMemDb){ |
| 58341 | static const char zFake[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 58342 | return (nullIfMemDb && pPager->memDb) ? &zFake[4] : pPager->zFilename; |
| 58343 | } |
| 58344 | |
| 58345 | /* |
| 58346 | ** Return the VFS structure for the pager. |
| @@ -58495,58 +58385,10 @@ | |
| 58385 | */ |
| 58386 | SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager *pPager){ |
| 58387 | return pPager->zJournal; |
| 58388 | } |
| 58389 | |
| 58390 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 58391 | /* |
| 58392 | ** Move the page pPg to location pgno in the file. |
| 58393 | ** |
| 58394 | ** There must be no references to the page previously located at |
| @@ -62453,15 +62295,11 @@ | |
| 62295 | sqlite3_int64 iOffset /* Byte offset at which to write */ |
| 62296 | ){ |
| 62297 | int rc; /* Result code from subfunctions */ |
| 62298 | void *pData; /* Data actually written */ |
| 62299 | u8 aFrame[WAL_FRAME_HDRSIZE]; /* Buffer to assemble frame-header in */ |
| 62300 | pData = pPage->pData; |
| 62301 | walEncodeFrame(p->pWal, pPage->pgno, nTruncate, pData, aFrame); |
| 62302 | rc = walWriteToLog(p, aFrame, sizeof(aFrame), iOffset); |
| 62303 | if( rc ) return rc; |
| 62304 | /* Write the page data */ |
| 62305 | rc = walWriteToLog(p, pData, p->szPage, iOffset+sizeof(aFrame)); |
| @@ -62640,15 +62478,11 @@ | |
| 62478 | i64 iOff = walFrameOffset(iWrite, szPage) + WAL_FRAME_HDRSIZE; |
| 62479 | void *pData; |
| 62480 | if( pWal->iReCksum==0 || iWrite<pWal->iReCksum ){ |
| 62481 | pWal->iReCksum = iWrite; |
| 62482 | } |
| 62483 | pData = p->pData; |
| 62484 | rc = sqlite3OsWrite(pWal->pWalFd, pData, szPage, iOff); |
| 62485 | if( rc ) return rc; |
| 62486 | p->flags &= ~PGHDR_WAL_APPEND; |
| 62487 | continue; |
| 62488 | } |
| @@ -63502,13 +63336,10 @@ | |
| 63336 | u8 incrVacuum; /* True if incr-vacuum is enabled */ |
| 63337 | u8 bDoTruncate; /* True to truncate db on commit */ |
| 63338 | #endif |
| 63339 | u8 inTransaction; /* Transaction state */ |
| 63340 | u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */ |
| 63341 | u16 btsFlags; /* Boolean parameters. See BTS_* macros below */ |
| 63342 | u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */ |
| 63343 | u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */ |
| 63344 | u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */ |
| 63345 | u16 minLeaf; /* Minimum local payload in a LEAFDATA table */ |
| @@ -65543,11 +65374,11 @@ | |
| 65374 | u8 *pEnd = &data[cellOffset + nCell*2]; |
| 65375 | u8 *pAddr; |
| 65376 | int sz2 = 0; |
| 65377 | int sz = get2byte(&data[iFree+2]); |
| 65378 | int top = get2byte(&data[hdr+5]); |
| 65379 | if( top>=iFree ){ |
| 65380 | return SQLITE_CORRUPT_PAGE(pPage); |
| 65381 | } |
| 65382 | if( iFree2 ){ |
| 65383 | if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65384 | sz2 = get2byte(&data[iFree2+2]); |
| @@ -65874,11 +65705,11 @@ | |
| 65705 | if( iStart<=x ){ |
| 65706 | /* The new freeblock is at the beginning of the cell content area, |
| 65707 | ** so just extend the cell content area rather than create another |
| 65708 | ** freelist entry */ |
| 65709 | if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65710 | if( iPtr!=hdr+1 ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65711 | put2byte(&data[hdr+1], iFreeBlk); |
| 65712 | put2byte(&data[hdr+5], iEnd); |
| 65713 | }else{ |
| 65714 | /* Insert the new freeblock into the freelist */ |
| 65715 | put2byte(&data[iPtr], iStart); |
| @@ -66953,13 +66784,10 @@ | |
| 66784 | SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){ |
| 66785 | int rc = SQLITE_OK; |
| 66786 | BtShared *pBt = p->pBt; |
| 66787 | assert( nReserve>=-1 && nReserve<=255 ); |
| 66788 | sqlite3BtreeEnter(p); |
| 66789 | if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){ |
| 66790 | sqlite3BtreeLeave(p); |
| 66791 | return SQLITE_READONLY; |
| 66792 | } |
| 66793 | if( nReserve<0 ){ |
| @@ -67016,13 +66844,10 @@ | |
| 66844 | */ |
| 66845 | SQLITE_PRIVATE int sqlite3BtreeGetOptimalReserve(Btree *p){ |
| 66846 | int n; |
| 66847 | sqlite3BtreeEnter(p); |
| 66848 | n = sqlite3BtreeGetReserveNoMutex(p); |
| 66849 | sqlite3BtreeLeave(p); |
| 66850 | return n; |
| 66851 | } |
| 66852 | |
| 66853 | |
| @@ -74855,17 +74680,10 @@ | |
| 74680 | Pager * const pDestPager = sqlite3BtreePager(p->pDest); |
| 74681 | const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc); |
| 74682 | int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest); |
| 74683 | const int nCopy = MIN(nSrcPgsz, nDestPgsz); |
| 74684 | const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz; |
| 74685 | int rc = SQLITE_OK; |
| 74686 | i64 iOff; |
| 74687 | |
| 74688 | assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 ); |
| 74689 | assert( p->bDestLocked ); |
| @@ -74878,30 +74696,10 @@ | |
| 74696 | */ |
| 74697 | if( nSrcPgsz!=nDestPgsz && sqlite3PagerIsMemdb(pDestPager) ){ |
| 74698 | rc = SQLITE_READONLY; |
| 74699 | } |
| 74700 | |
| 74701 | /* This loop runs once for each destination page spanned by the source |
| 74702 | ** page. For each iteration, variable iOff is set to the byte offset |
| 74703 | ** of the destination page. |
| 74704 | */ |
| 74705 | for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){ |
| @@ -75393,14 +75191,10 @@ | |
| 75191 | b.pSrcDb = pFrom->db; |
| 75192 | b.pSrc = pFrom; |
| 75193 | b.pDest = pTo; |
| 75194 | b.iNext = 1; |
| 75195 | |
| 75196 | /* 0x7FFFFFFF is the hard limit for the number of pages in a database |
| 75197 | ** file. By passing this as the number of pages to copy to |
| 75198 | ** sqlite3_backup_step(), we can guarantee that the copy finishes |
| 75199 | ** within a single call (unless an error occurs). The assert() statement |
| 75200 | ** checks this assumption - (p->rc) should be set to either SQLITE_DONE |
| @@ -76594,11 +76388,11 @@ | |
| 76388 | ** destroyed. |
| 76389 | ** |
| 76390 | ** If this routine fails for any reason (malloc returns NULL or unable |
| 76391 | ** to read from the disk) then the pMem is left in an inconsistent state. |
| 76392 | */ |
| 76393 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree( |
| 76394 | BtCursor *pCur, /* Cursor pointing at record to retrieve. */ |
| 76395 | u32 offset, /* Offset from the start of data to return bytes from. */ |
| 76396 | u32 amt, /* Number of bytes to return. */ |
| 76397 | Mem *pMem /* OUT: Return data in this Mem structure. */ |
| 76398 | ){ |
| @@ -76617,35 +76411,32 @@ | |
| 76411 | sqlite3VdbeMemRelease(pMem); |
| 76412 | } |
| 76413 | } |
| 76414 | return rc; |
| 76415 | } |
| 76416 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtreeZeroOffset( |
| 76417 | BtCursor *pCur, /* Cursor pointing at record to retrieve. */ |
| 76418 | u32 amt, /* Number of bytes to return. */ |
| 76419 | Mem *pMem /* OUT: Return data in this Mem structure. */ |
| 76420 | ){ |
| 76421 | u32 available = 0; /* Number of bytes available on the local btree page */ |
| 76422 | int rc = SQLITE_OK; /* Return code */ |
| 76423 | |
| 76424 | assert( sqlite3BtreeCursorIsValid(pCur) ); |
| 76425 | assert( !VdbeMemDynamic(pMem) ); |
| 76426 | |
| 76427 | /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert() |
| 76428 | ** that both the BtShared and database handle mutexes are held. */ |
| 76429 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| 76430 | pMem->z = (char *)sqlite3BtreePayloadFetch(pCur, &available); |
| 76431 | assert( pMem->z!=0 ); |
| 76432 | |
| 76433 | if( amt<=available ){ |
| 76434 | pMem->flags = MEM_Blob|MEM_Ephem; |
| 76435 | pMem->n = (int)amt; |
| 76436 | }else{ |
| 76437 | rc = sqlite3VdbeMemFromBtree(pCur, 0, amt, pMem); |
| 76438 | } |
| 76439 | |
| 76440 | return rc; |
| 76441 | } |
| 76442 | |
| @@ -78397,10 +78188,38 @@ | |
| 78188 | */ |
| 78189 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){ |
| 78190 | sqlite3VdbeChangeP2(p, addr, p->nOp); |
| 78191 | } |
| 78192 | |
| 78193 | /* |
| 78194 | ** Change the P2 operand of the jump instruction at addr so that |
| 78195 | ** the jump lands on the next opcode. Or if the jump instruction was |
| 78196 | ** the previous opcode (and is thus a no-op) then simply back up |
| 78197 | ** the next instruction counter by one slot so that the jump is |
| 78198 | ** overwritten by the next inserted opcode. |
| 78199 | ** |
| 78200 | ** This routine is an optimization of sqlite3VdbeJumpHere() that |
| 78201 | ** strives to omit useless byte-code like this: |
| 78202 | ** |
| 78203 | ** 7 Once 0 8 0 |
| 78204 | ** 8 ... |
| 78205 | */ |
| 78206 | SQLITE_PRIVATE void sqlite3VdbeJumpHereOrPopInst(Vdbe *p, int addr){ |
| 78207 | if( addr==p->nOp-1 ){ |
| 78208 | assert( p->aOp[addr].opcode==OP_Once |
| 78209 | || p->aOp[addr].opcode==OP_If |
| 78210 | || p->aOp[addr].opcode==OP_FkIfZero ); |
| 78211 | assert( p->aOp[addr].p4type==0 ); |
| 78212 | #ifdef SQLITE_VDBE_COVERAGE |
| 78213 | sqlite3VdbeGetOp(p,-1)->iSrcLine = 0; /* Erase VdbeCoverage() macros */ |
| 78214 | #endif |
| 78215 | p->nOp--; |
| 78216 | }else{ |
| 78217 | sqlite3VdbeChangeP2(p, addr, p->nOp); |
| 78218 | } |
| 78219 | } |
| 78220 | |
| 78221 | |
| 78222 | /* |
| 78223 | ** If the input FuncDef structure is ephemeral, then free it. If |
| 78224 | ** the FuncDef is not ephermal, then do nothing. |
| 78225 | */ |
| @@ -78777,12 +78596,15 @@ | |
| 78596 | int nTemp /* Space available in zTemp[] */ |
| 78597 | ){ |
| 78598 | const char *zOpName; |
| 78599 | const char *zSynopsis; |
| 78600 | int nOpName; |
| 78601 | int ii; |
| 78602 | char zAlt[50]; |
| 78603 | StrAccum x; |
| 78604 | sqlite3StrAccumInit(&x, 0, zTemp, nTemp, 0); |
| 78605 | |
| 78606 | zOpName = sqlite3OpcodeName(pOp->opcode); |
| 78607 | nOpName = sqlite3Strlen30(zOpName); |
| 78608 | if( zOpName[nOpName+1] ){ |
| 78609 | int seenCom = 0; |
| 78610 | char c; |
| @@ -78793,55 +78615,64 @@ | |
| 78615 | }else{ |
| 78616 | sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3); |
| 78617 | } |
| 78618 | zSynopsis = zAlt; |
| 78619 | } |
| 78620 | for(ii=0; (c = zSynopsis[ii])!=0; ii++){ |
| 78621 | if( c=='P' ){ |
| 78622 | c = zSynopsis[++ii]; |
| 78623 | if( c=='4' ){ |
| 78624 | sqlite3_str_appendall(&x, zP4); |
| 78625 | }else if( c=='X' ){ |
| 78626 | sqlite3_str_appendall(&x, pOp->zComment); |
| 78627 | seenCom = 1; |
| 78628 | }else{ |
| 78629 | int v1 = translateP(c, pOp); |
| 78630 | int v2; |
| 78631 | if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){ |
| 78632 | ii += 3; |
| 78633 | v2 = translateP(zSynopsis[ii], pOp); |
| 78634 | if( strncmp(zSynopsis+ii+1,"+1",2)==0 ){ |
| 78635 | ii += 2; |
| 78636 | v2++; |
| 78637 | } |
| 78638 | if( v2<2 ){ |
| 78639 | sqlite3_str_appendf(&x, "%d", v1); |
| 78640 | }else{ |
| 78641 | sqlite3_str_appendf(&x, "%d..%d", v1, v1+v2-1); |
| 78642 | } |
| 78643 | }else if( strncmp(zSynopsis+ii+1, "@NP", 3)==0 ){ |
| 78644 | sqlite3_context *pCtx = pOp->p4.pCtx; |
| 78645 | if( pOp->p4type!=P4_FUNCCTX || pCtx->argc==1 ){ |
| 78646 | sqlite3_str_appendf(&x, "%d", v1); |
| 78647 | }else if( pCtx->argc>1 ){ |
| 78648 | sqlite3_str_appendf(&x, "%d..%d", v1, v1+pCtx->argc-1); |
| 78649 | }else{ |
| 78650 | assert( x.nChar>2 ); |
| 78651 | x.nChar -= 2; |
| 78652 | ii++; |
| 78653 | } |
| 78654 | ii += 3; |
| 78655 | }else{ |
| 78656 | sqlite3_str_appendf(&x, "%d", v1); |
| 78657 | if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){ |
| 78658 | ii += 4; |
| 78659 | } |
| 78660 | } |
| 78661 | } |
| 78662 | }else{ |
| 78663 | sqlite3_str_appendchar(&x, 1, c); |
| 78664 | } |
| 78665 | } |
| 78666 | if( !seenCom && pOp->zComment ){ |
| 78667 | sqlite3_str_appendf(&x, "; %s", pOp->zComment); |
| 78668 | } |
| 78669 | }else if( pOp->zComment ){ |
| 78670 | sqlite3_str_appendall(&x, pOp->zComment); |
| 78671 | } |
| 78672 | sqlite3StrAccumFinish(&x); |
| 78673 | return x.nChar; |
| 78674 | } |
| 78675 | #endif /* SQLITE_DEBUG */ |
| 78676 | |
| 78677 | #if VDBE_DISPLAY_P4 && defined(SQLITE_ENABLE_CURSOR_HINTS) |
| 78678 | /* |
| @@ -80832,11 +80663,11 @@ | |
| 80663 | SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, int *piCol){ |
| 80664 | VdbeCursor *p = *pp; |
| 80665 | assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO ); |
| 80666 | if( p->deferredMoveto ){ |
| 80667 | int iMap; |
| 80668 | if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){ |
| 80669 | *pp = p->pAltCursor; |
| 80670 | *piCol = iMap - 1; |
| 80671 | return SQLITE_OK; |
| 80672 | } |
| 80673 | return sqlite3VdbeFinishMoveto(p); |
| @@ -81835,11 +81666,11 @@ | |
| 81666 | } |
| 81667 | } |
| 81668 | |
| 81669 | /* RHS is a string */ |
| 81670 | else if( pRhs->flags & MEM_Str ){ |
| 81671 | getVarint32NR(&aKey1[idx1], serial_type); |
| 81672 | testcase( serial_type==12 ); |
| 81673 | if( serial_type<12 ){ |
| 81674 | rc = -1; |
| 81675 | }else if( !(serial_type & 0x01) ){ |
| 81676 | rc = +1; |
| @@ -81869,11 +81700,11 @@ | |
| 81700 | } |
| 81701 | |
| 81702 | /* RHS is a blob */ |
| 81703 | else if( pRhs->flags & MEM_Blob ){ |
| 81704 | assert( (pRhs->flags & MEM_Zero)==0 || pRhs->n==0 ); |
| 81705 | getVarint32NR(&aKey1[idx1], serial_type); |
| 81706 | testcase( serial_type==12 ); |
| 81707 | if( serial_type<12 || (serial_type & 0x01) ){ |
| 81708 | rc = -1; |
| 81709 | }else{ |
| 81710 | int nStr = (serial_type - 12) / 2; |
| @@ -82058,11 +81889,14 @@ | |
| 81889 | int serial_type; |
| 81890 | int res; |
| 81891 | |
| 81892 | assert( pPKey2->aMem[0].flags & MEM_Str ); |
| 81893 | vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); |
| 81894 | serial_type = (u8)(aKey1[1]); |
| 81895 | if( serial_type >= 0x80 ){ |
| 81896 | sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type); |
| 81897 | } |
| 81898 | if( serial_type<12 ){ |
| 81899 | res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */ |
| 81900 | }else if( !(serial_type & 0x01) ){ |
| 81901 | res = pPKey2->r2; /* (pKey1/nKey1) is a blob */ |
| 81902 | }else{ |
| @@ -82179,17 +82013,17 @@ | |
| 82013 | nCellKey = sqlite3BtreePayloadSize(pCur); |
| 82014 | assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey ); |
| 82015 | |
| 82016 | /* Read in the complete content of the index entry */ |
| 82017 | sqlite3VdbeMemInit(&m, db, 0); |
| 82018 | rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m); |
| 82019 | if( rc ){ |
| 82020 | return rc; |
| 82021 | } |
| 82022 | |
| 82023 | /* The index entry must begin with a header size */ |
| 82024 | getVarint32NR((u8*)m.z, szHdr); |
| 82025 | testcase( szHdr==3 ); |
| 82026 | testcase( szHdr==m.n ); |
| 82027 | testcase( szHdr>0x7fffffff ); |
| 82028 | assert( m.n>=0 ); |
| 82029 | if( unlikely(szHdr<3 || szHdr>(unsigned)m.n) ){ |
| @@ -82196,11 +82030,11 @@ | |
| 82030 | goto idx_rowid_corruption; |
| 82031 | } |
| 82032 | |
| 82033 | /* The last field of the index should be an integer - the ROWID. |
| 82034 | ** Verify that the last entry really is an integer. */ |
| 82035 | getVarint32NR((u8*)&m.z[szHdr-1], typeRowid); |
| 82036 | testcase( typeRowid==1 ); |
| 82037 | testcase( typeRowid==2 ); |
| 82038 | testcase( typeRowid==3 ); |
| 82039 | testcase( typeRowid==4 ); |
| 82040 | testcase( typeRowid==5 ); |
| @@ -82261,11 +82095,11 @@ | |
| 82095 | if( nCellKey<=0 || nCellKey>0x7fffffff ){ |
| 82096 | *res = 0; |
| 82097 | return SQLITE_CORRUPT_BKPT; |
| 82098 | } |
| 82099 | sqlite3VdbeMemInit(&m, db, 0); |
| 82100 | rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m); |
| 82101 | if( rc ){ |
| 82102 | return rc; |
| 82103 | } |
| 82104 | *res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, pUnpacked, 0); |
| 82105 | sqlite3VdbeMemRelease(&m); |
| @@ -86927,11 +86761,11 @@ | |
| 86761 | affinity = pOp->p5 & SQLITE_AFF_MASK; |
| 86762 | if( affinity>=SQLITE_AFF_NUMERIC ){ |
| 86763 | if( (flags1 | flags3)&MEM_Str ){ |
| 86764 | if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){ |
| 86765 | applyNumericAffinity(pIn1,0); |
| 86766 | assert( flags3==pIn3->flags ); |
| 86767 | flags3 = pIn3->flags; |
| 86768 | } |
| 86769 | if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){ |
| 86770 | applyNumericAffinity(pIn3,0); |
| 86771 | } |
| @@ -86950,11 +86784,11 @@ | |
| 86784 | testcase( pIn1->flags & MEM_Real ); |
| 86785 | testcase( pIn1->flags & MEM_IntReal ); |
| 86786 | sqlite3VdbeMemStringify(pIn1, encoding, 1); |
| 86787 | testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) ); |
| 86788 | flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask); |
| 86789 | if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str; |
| 86790 | } |
| 86791 | if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){ |
| 86792 | testcase( pIn3->flags & MEM_Int ); |
| 86793 | testcase( pIn3->flags & MEM_Real ); |
| 86794 | testcase( pIn3->flags & MEM_IntReal ); |
| @@ -87565,11 +87399,11 @@ | |
| 87399 | */ |
| 87400 | if( pC->iHdrOffset<aOffset[0] ){ |
| 87401 | /* Make sure zData points to enough of the record to cover the header. */ |
| 87402 | if( pC->aRow==0 ){ |
| 87403 | memset(&sMem, 0, sizeof(sMem)); |
| 87404 | rc = sqlite3VdbeMemFromBtreeZeroOffset(pC->uc.pCursor,aOffset[0],&sMem); |
| 87405 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 87406 | zData = (u8*)sMem.z; |
| 87407 | }else{ |
| 87408 | zData = pC->aRow; |
| 87409 | } |
| @@ -90061,11 +89895,11 @@ | |
| 89895 | n = sqlite3BtreePayloadSize(pCrsr); |
| 89896 | if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 89897 | goto too_big; |
| 89898 | } |
| 89899 | testcase( n==0 ); |
| 89900 | rc = sqlite3VdbeMemFromBtreeZeroOffset(pCrsr, n, pOut); |
| 89901 | if( rc ) goto abort_due_to_error; |
| 89902 | if( !pOp->p3 ) Deephemeralize(pOut); |
| 89903 | UPDATE_MAX_BLOBSIZE(pOut); |
| 89904 | REGISTER_TRACE(pOp->p2, pOut); |
| 89905 | break; |
| @@ -90439,48 +90273,61 @@ | |
| 90273 | ** to P2. |
| 90274 | ** |
| 90275 | ** This instruction only works for indices. The equivalent instruction |
| 90276 | ** for tables is OP_Insert. |
| 90277 | */ |
| 90278 | case OP_IdxInsert: { /* in2 */ |
| 90279 | VdbeCursor *pC; |
| 90280 | BtreePayload x; |
| 90281 | |
| 90282 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 90283 | pC = p->apCsr[pOp->p1]; |
| 90284 | sqlite3VdbeIncrWriteCounter(p, pC); |
| 90285 | assert( pC!=0 ); |
| 90286 | assert( !isSorter(pC) ); |
| 90287 | pIn2 = &aMem[pOp->p2]; |
| 90288 | assert( pIn2->flags & MEM_Blob ); |
| 90289 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 90290 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 90291 | assert( pC->isTable==0 ); |
| 90292 | rc = ExpandBlob(pIn2); |
| 90293 | if( rc ) goto abort_due_to_error; |
| 90294 | x.nKey = pIn2->n; |
| 90295 | x.pKey = pIn2->z; |
| 90296 | x.aMem = aMem + pOp->p3; |
| 90297 | x.nMem = (u16)pOp->p4.i; |
| 90298 | rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, |
| 90299 | (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)), |
| 90300 | ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) |
| 90301 | ); |
| 90302 | assert( pC->deferredMoveto==0 ); |
| 90303 | pC->cacheStatus = CACHE_STALE; |
| 90304 | if( rc) goto abort_due_to_error; |
| 90305 | break; |
| 90306 | } |
| 90307 | |
| 90308 | /* Opcode: SorterInsert P1 P2 * * * |
| 90309 | ** Synopsis: key=r[P2] |
| 90310 | ** |
| 90311 | ** Register P2 holds an SQL index key made using the |
| 90312 | ** MakeRecord instructions. This opcode writes that key |
| 90313 | ** into the sorter P1. Data for the entry is nil. |
| 90314 | */ |
| 90315 | case OP_SorterInsert: { /* in2 */ |
| 90316 | VdbeCursor *pC; |
| 90317 | |
| 90318 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 90319 | pC = p->apCsr[pOp->p1]; |
| 90320 | sqlite3VdbeIncrWriteCounter(p, pC); |
| 90321 | assert( pC!=0 ); |
| 90322 | assert( isSorter(pC) ); |
| 90323 | pIn2 = &aMem[pOp->p2]; |
| 90324 | assert( pIn2->flags & MEM_Blob ); |
| 90325 | assert( pC->isTable==0 ); |
| 90326 | rc = ExpandBlob(pIn2); |
| 90327 | if( rc ) goto abort_due_to_error; |
| 90328 | rc = sqlite3VdbeSorterWrite(pC, pIn2); |
| 90329 | if( rc) goto abort_due_to_error; |
| 90330 | break; |
| 90331 | } |
| 90332 | |
| 90333 | /* Opcode: IdxDelete P1 P2 P3 * * |
| @@ -92426,11 +92273,11 @@ | |
| 92273 | break; |
| 92274 | } |
| 92275 | #endif |
| 92276 | |
| 92277 | /* Opcode: Function P1 P2 P3 P4 * |
| 92278 | ** Synopsis: r[P3]=func(r[P2@NP]) |
| 92279 | ** |
| 92280 | ** Invoke a user function (P4 is a pointer to an sqlite3_context object that |
| 92281 | ** contains a pointer to the function to be run) with arguments taken |
| 92282 | ** from register P2 and successors. The number of arguments is in |
| 92283 | ** the sqlite3_context object that P4 points to. |
| @@ -92445,11 +92292,11 @@ | |
| 92292 | ** invocation of this opcode. |
| 92293 | ** |
| 92294 | ** See also: AggStep, AggFinal, PureFunc |
| 92295 | */ |
| 92296 | /* Opcode: PureFunc P1 P2 P3 P4 * |
| 92297 | ** Synopsis: r[P3]=func(r[P2@NP]) |
| 92298 | ** |
| 92299 | ** Invoke a user function (P4 is a pointer to an sqlite3_context object that |
| 92300 | ** contains a pointer to the function to be run) with arguments taken |
| 92301 | ** from register P2 and successors. The number of arguments is in |
| 92302 | ** the sqlite3_context object that P4 points to. |
| @@ -94172,12 +94019,12 @@ | |
| 94019 | |
| 94020 | int n1; |
| 94021 | int n2; |
| 94022 | int res; |
| 94023 | |
| 94024 | getVarint32NR(&p1[1], n1); |
| 94025 | getVarint32NR(&p2[1], n2); |
| 94026 | res = memcmp(v1, v2, (MIN(n1, n2) - 13)/2); |
| 94027 | if( res==0 ){ |
| 94028 | res = n1 - n2; |
| 94029 | } |
| 94030 | |
| @@ -95130,11 +94977,11 @@ | |
| 94977 | int nPMA; /* Bytes of PMA space required */ |
| 94978 | int t; /* serial type of first record field */ |
| 94979 | |
| 94980 | assert( pCsr->eCurType==CURTYPE_SORTER ); |
| 94981 | pSorter = pCsr->uc.pSorter; |
| 94982 | getVarint32NR((const u8*)&pVal->z[1], t); |
| 94983 | if( t>0 && t<10 && t!=7 ){ |
| 94984 | pSorter->typeMask &= SORTER_TYPE_INTEGER; |
| 94985 | }else if( t>10 && (t & 0x01) ){ |
| 94986 | pSorter->typeMask &= SORTER_TYPE_TEXT; |
| 94987 | }else{ |
| @@ -97814,11 +97661,11 @@ | |
| 97661 | case TK_ISNOT: { |
| 97662 | Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight); |
| 97663 | assert( !ExprHasProperty(pExpr, EP_Reduced) ); |
| 97664 | /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE", |
| 97665 | ** and "x IS NOT FALSE". */ |
| 97666 | if( pRight && pRight->op==TK_ID ){ |
| 97667 | int rc = resolveExprStep(pWalker, pRight); |
| 97668 | if( rc==WRC_Abort ) return WRC_Abort; |
| 97669 | if( pRight->op==TK_TRUEFALSE ){ |
| 97670 | pExpr->op2 = pExpr->op; |
| 97671 | pExpr->op = TK_TRUTH; |
| @@ -102304,10 +102151,20 @@ | |
| 102151 | } |
| 102152 | } |
| 102153 | } |
| 102154 | return iResult; |
| 102155 | } |
| 102156 | |
| 102157 | /* |
| 102158 | ** If the last opcode is a OP_Copy, then set the do-not-merge flag (p5) |
| 102159 | ** so that a subsequent copy will not be merged into this one. |
| 102160 | */ |
| 102161 | static void setDoNotMergeFlagOnCopy(Vdbe *v){ |
| 102162 | if( sqlite3VdbeGetOp(v, -1)->opcode==OP_Copy ){ |
| 102163 | sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */ |
| 102164 | } |
| 102165 | } |
| 102166 | |
| 102167 | /* |
| 102168 | ** Generate code to implement special SQL functions that are implemented |
| 102169 | ** in-line rather than by using the usual callbacks. |
| 102170 | */ |
| @@ -102336,13 +102193,11 @@ | |
| 102193 | for(i=1; i<nFarg; i++){ |
| 102194 | sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce); |
| 102195 | VdbeCoverage(v); |
| 102196 | sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target); |
| 102197 | } |
| 102198 | setDoNotMergeFlagOnCopy(v); |
| 102199 | sqlite3VdbeResolveLabel(v, endCoalesce); |
| 102200 | break; |
| 102201 | } |
| 102202 | |
| 102203 | default: { |
| @@ -103109,10 +102964,11 @@ | |
| 102964 | sqlite3ExprCode(pParse, pEList->a[nExpr-1].pExpr, target); |
| 102965 | }else{ |
| 102966 | sqlite3VdbeAddOp2(v, OP_Null, 0, target); |
| 102967 | } |
| 102968 | sqlite3ExprDelete(db, pDel); |
| 102969 | setDoNotMergeFlagOnCopy(v); |
| 102970 | sqlite3VdbeResolveLabel(v, endLabel); |
| 102971 | break; |
| 102972 | } |
| 102973 | #ifndef SQLITE_OMIT_TRIGGER |
| 102974 | case TK_RAISE: { |
| @@ -104131,23 +103987,29 @@ | |
| 103987 | case TK_EQ: |
| 103988 | case TK_NE: |
| 103989 | case TK_LT: |
| 103990 | case TK_LE: |
| 103991 | case TK_GT: |
| 103992 | case TK_GE: { |
| 103993 | Expr *pLeft = pExpr->pLeft; |
| 103994 | Expr *pRight = pExpr->pRight; |
| 103995 | testcase( pExpr->op==TK_EQ ); |
| 103996 | testcase( pExpr->op==TK_NE ); |
| 103997 | testcase( pExpr->op==TK_LT ); |
| 103998 | testcase( pExpr->op==TK_LE ); |
| 103999 | testcase( pExpr->op==TK_GT ); |
| 104000 | testcase( pExpr->op==TK_GE ); |
| 104001 | /* The y.pTab=0 assignment in wherecode.c always happens after the |
| 104002 | ** impliesNotNullRow() test */ |
| 104003 | if( (pLeft->op==TK_COLUMN && ALWAYS(pLeft->y.pTab!=0) |
| 104004 | && IsVirtual(pLeft->y.pTab)) |
| 104005 | || (pRight->op==TK_COLUMN && ALWAYS(pRight->y.pTab!=0) |
| 104006 | && IsVirtual(pRight->y.pTab)) |
| 104007 | ){ |
| 104008 | return WRC_Prune; |
| 104009 | } |
| 104010 | } |
| 104011 | default: |
| 104012 | return WRC_Continue; |
| 104013 | } |
| 104014 | } |
| 104015 | |
| @@ -108386,47 +108248,11 @@ | |
| 108248 | } |
| 108249 | pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1; |
| 108250 | if( rc==SQLITE_OK && pNew->zDbSName==0 ){ |
| 108251 | rc = SQLITE_NOMEM_BKPT; |
| 108252 | } |
| 108253 | sqlite3_free_filename( zPath ); |
| 108254 | |
| 108255 | /* If the file was opened successfully, read the schema for the new database. |
| 108256 | ** If this fails, or if opening the file failed, then close the file and |
| 108257 | ** remove the entry from the db->aDb[] array. i.e. put everything back the |
| 108258 | ** way we found it. |
| @@ -115207,11 +115033,13 @@ | |
| 115033 | testcase( IsVirtual(pTab) ); |
| 115034 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, OPFLAG_FORDELETE, |
| 115035 | iTabCur, aToOpen, &iDataCur, &iIdxCur); |
| 115036 | assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur ); |
| 115037 | assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 ); |
| 115038 | if( eOnePass==ONEPASS_MULTI ){ |
| 115039 | sqlite3VdbeJumpHereOrPopInst(v, iAddrOnce); |
| 115040 | } |
| 115041 | } |
| 115042 | |
| 115043 | /* Set up a loop over the rowids/primary-keys that were found in the |
| 115044 | ** where-clause loop above. |
| 115045 | */ |
| @@ -118337,11 +118165,11 @@ | |
| 118165 | } |
| 118166 | |
| 118167 | /* Clean up the WHERE clause constructed above. */ |
| 118168 | sqlite3ExprDelete(db, pWhere); |
| 118169 | if( iFkIfZero ){ |
| 118170 | sqlite3VdbeJumpHereOrPopInst(v, iFkIfZero); |
| 118171 | } |
| 118172 | } |
| 118173 | |
| 118174 | /* |
| 118175 | ** This function returns a linked list of FKey objects (connected by |
| @@ -120798,10 +120626,14 @@ | |
| 120626 | && !sqlite3ExprReferencesUpdatedColumn(pExpr, aiChng, pkChng) |
| 120627 | ){ |
| 120628 | /* The check constraints do not reference any of the columns being |
| 120629 | ** updated so there is no point it verifying the check constraint */ |
| 120630 | continue; |
| 120631 | } |
| 120632 | if( bAffinityDone==0 ){ |
| 120633 | sqlite3TableAffinity(v, pTab, regNewData+1); |
| 120634 | bAffinityDone = 1; |
| 120635 | } |
| 120636 | allOk = sqlite3VdbeMakeLabel(pParse); |
| 120637 | sqlite3VdbeVerifyAbortable(v, onError); |
| 120638 | sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL); |
| 120639 | if( onError==OE_Ignore ){ |
| @@ -121915,18 +121747,17 @@ | |
| 121747 | addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid); |
| 121748 | }else{ |
| 121749 | addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); |
| 121750 | assert( (pDest->tabFlags & TF_Autoincrement)==0 ); |
| 121751 | } |
| 121752 | if( db->mDbFlags & DBFLAG_Vacuum ){ |
| 121753 | sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest); |
| 121754 | insFlags = OPFLAG_APPEND|OPFLAG_USESEEKRESULT; |
| 121755 | }else{ |
| 121756 | insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND; |
| 121757 | } |
| 121758 | sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); |
| 121759 | sqlite3VdbeAddOp4(v, OP_Insert, iDest, regData, regRowid, |
| 121760 | (char*)pDest, P4_TABLE); |
| 121761 | sqlite3VdbeChangeP5(v, insFlags); |
| 121762 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v); |
| 121763 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| @@ -121947,11 +121778,10 @@ | |
| 121778 | sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest); |
| 121779 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 121780 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 121781 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 121782 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 121783 | if( db->mDbFlags & DBFLAG_Vacuum ){ |
| 121784 | /* This INSERT command is part of a VACUUM operation, which guarantees |
| 121785 | ** that the destination table is empty. If all indexed columns use |
| 121786 | ** collation sequence BINARY, then it can also be assumed that the |
| 121787 | ** index will be populated by inserting keys in strictly sorted |
| @@ -121971,14 +121801,14 @@ | |
| 121801 | } |
| 121802 | if( i==pSrcIdx->nColumn ){ |
| 121803 | idxInsFlags = OPFLAG_USESEEKRESULT; |
| 121804 | sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest); |
| 121805 | } |
| 121806 | }else if( !HasRowid(pSrc) && pDestIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){ |
| 121807 | idxInsFlags |= OPFLAG_NCHANGE; |
| 121808 | } |
| 121809 | sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); |
| 121810 | sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData); |
| 121811 | sqlite3VdbeChangeP5(v, idxInsFlags|OPFLAG_APPEND); |
| 121812 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v); |
| 121813 | sqlite3VdbeJumpHere(v, addr1); |
| 121814 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| @@ -122495,10 +122325,14 @@ | |
| 122325 | sqlite3_int64 (*hard_heap_limit64)(sqlite3_int64); |
| 122326 | const char *(*uri_key)(const char*,int); |
| 122327 | const char *(*filename_database)(const char*); |
| 122328 | const char *(*filename_journal)(const char*); |
| 122329 | const char *(*filename_wal)(const char*); |
| 122330 | /* Version 3.32.0 and later */ |
| 122331 | char *(*create_filename)(const char*,const char*,const char*, |
| 122332 | int,const char**); |
| 122333 | void (*free_filename)(char*); |
| 122334 | }; |
| 122335 | |
| 122336 | /* |
| 122337 | ** This is the function signature used for all extension entry points. It |
| 122338 | ** is also defined in the file "loadext.c". |
| @@ -122795,10 +122629,13 @@ | |
| 122629 | #define sqlite3_hard_heap_limit64 sqlite3_api->hard_heap_limit64 |
| 122630 | #define sqlite3_uri_key sqlite3_api->uri_key |
| 122631 | #define sqlite3_filename_database sqlite3_api->filename_database |
| 122632 | #define sqlite3_filename_journal sqlite3_api->filename_journal |
| 122633 | #define sqlite3_filename_wal sqlite3_api->filename_wal |
| 122634 | /* Version 3.32.0 and later */ |
| 122635 | #define sqlite3_create_filename sqlite3_api->create_filename |
| 122636 | #define sqlite3_free_filename sqlite3_api->free_filename |
| 122637 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 122638 | |
| 122639 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 122640 | /* This case when the file really is being compiled as a loadable |
| 122641 | ** extension */ |
| @@ -123273,10 +123110,13 @@ | |
| 123110 | sqlite3_hard_heap_limit64, |
| 123111 | sqlite3_uri_key, |
| 123112 | sqlite3_filename_database, |
| 123113 | sqlite3_filename_journal, |
| 123114 | sqlite3_filename_wal, |
| 123115 | /* Version 3.32.0 and later */ |
| 123116 | sqlite3_create_filename, |
| 123117 | sqlite3_free_filename, |
| 123118 | }; |
| 123119 | |
| 123120 | /* |
| 123121 | ** Attempt to load an SQLite extension library contained in the file |
| 123122 | ** zFile. The entry point is zProc. zProc may be 0 in which case a |
| @@ -123679,55 +123519,54 @@ | |
| 123519 | ** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit |
| 123520 | ** that script and rerun it. |
| 123521 | */ |
| 123522 | |
| 123523 | /* The various pragma types */ |
| 123524 | #define PragTyp_ACTIVATE_EXTENSIONS 0 |
| 123525 | #define PragTyp_HEADER_VALUE 1 |
| 123526 | #define PragTyp_AUTO_VACUUM 2 |
| 123527 | #define PragTyp_FLAG 3 |
| 123528 | #define PragTyp_BUSY_TIMEOUT 4 |
| 123529 | #define PragTyp_CACHE_SIZE 5 |
| 123530 | #define PragTyp_CACHE_SPILL 6 |
| 123531 | #define PragTyp_CASE_SENSITIVE_LIKE 7 |
| 123532 | #define PragTyp_COLLATION_LIST 8 |
| 123533 | #define PragTyp_COMPILE_OPTIONS 9 |
| 123534 | #define PragTyp_DATA_STORE_DIRECTORY 10 |
| 123535 | #define PragTyp_DATABASE_LIST 11 |
| 123536 | #define PragTyp_DEFAULT_CACHE_SIZE 12 |
| 123537 | #define PragTyp_ENCODING 13 |
| 123538 | #define PragTyp_FOREIGN_KEY_CHECK 14 |
| 123539 | #define PragTyp_FOREIGN_KEY_LIST 15 |
| 123540 | #define PragTyp_FUNCTION_LIST 16 |
| 123541 | #define PragTyp_HARD_HEAP_LIMIT 17 |
| 123542 | #define PragTyp_INCREMENTAL_VACUUM 18 |
| 123543 | #define PragTyp_INDEX_INFO 19 |
| 123544 | #define PragTyp_INDEX_LIST 20 |
| 123545 | #define PragTyp_INTEGRITY_CHECK 21 |
| 123546 | #define PragTyp_JOURNAL_MODE 22 |
| 123547 | #define PragTyp_JOURNAL_SIZE_LIMIT 23 |
| 123548 | #define PragTyp_LOCK_PROXY_FILE 24 |
| 123549 | #define PragTyp_LOCKING_MODE 25 |
| 123550 | #define PragTyp_PAGE_COUNT 26 |
| 123551 | #define PragTyp_MMAP_SIZE 27 |
| 123552 | #define PragTyp_MODULE_LIST 28 |
| 123553 | #define PragTyp_OPTIMIZE 29 |
| 123554 | #define PragTyp_PAGE_SIZE 30 |
| 123555 | #define PragTyp_PRAGMA_LIST 31 |
| 123556 | #define PragTyp_SECURE_DELETE 32 |
| 123557 | #define PragTyp_SHRINK_MEMORY 33 |
| 123558 | #define PragTyp_SOFT_HEAP_LIMIT 34 |
| 123559 | #define PragTyp_SYNCHRONOUS 35 |
| 123560 | #define PragTyp_TABLE_INFO 36 |
| 123561 | #define PragTyp_TEMP_STORE 37 |
| 123562 | #define PragTyp_TEMP_STORE_DIRECTORY 38 |
| 123563 | #define PragTyp_THREADS 39 |
| 123564 | #define PragTyp_WAL_AUTOCHECKPOINT 40 |
| 123565 | #define PragTyp_WAL_CHECKPOINT 41 |
| 123566 | #define PragTyp_LOCK_STATUS 42 |
| 123567 | #define PragTyp_STATS 43 |
| 123568 | |
| 123569 | /* Property flags associated with various pragma. */ |
| 123570 | #define PragFlg_NeedSchema 0x01 /* Force schema load before running */ |
| 123571 | #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */ |
| 123572 | #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */ |
| @@ -123807,11 +123646,11 @@ | |
| 123646 | u8 iPragCName; /* Start of column names in pragCName[] */ |
| 123647 | u8 nPragCName; /* Num of col names. 0 means use pragma name */ |
| 123648 | u64 iArg; /* Extra argument */ |
| 123649 | } PragmaName; |
| 123650 | static const PragmaName aPragmaName[] = { |
| 123651 | #if defined(SQLITE_ENABLE_CEROD) |
| 123652 | {/* zName: */ "activate_extensions", |
| 123653 | /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS, |
| 123654 | /* ePragFlg: */ 0, |
| 123655 | /* ColNames: */ 0, 0, |
| 123656 | /* iArg: */ 0 }, |
| @@ -124003,22 +123842,10 @@ | |
| 123842 | {/* zName: */ "hard_heap_limit", |
| 123843 | /* ePragTyp: */ PragTyp_HARD_HEAP_LIMIT, |
| 123844 | /* ePragFlg: */ PragFlg_Result0, |
| 123845 | /* ColNames: */ 0, 0, |
| 123846 | /* iArg: */ 0 }, |
| 123847 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 123848 | #if !defined(SQLITE_OMIT_CHECK) |
| 123849 | {/* zName: */ "ignore_check_constraints", |
| 123850 | /* ePragTyp: */ PragTyp_FLAG, |
| 123851 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| @@ -124064,17 +123891,10 @@ | |
| 123891 | /* ColNames: */ 0, 0, |
| 123892 | /* iArg: */ 0 }, |
| 123893 | {/* zName: */ "journal_size_limit", |
| 123894 | /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT, |
| 123895 | /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq, |
| 123896 | /* ColNames: */ 0, 0, |
| 123897 | /* iArg: */ 0 }, |
| 123898 | #endif |
| 123899 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 123900 | {/* zName: */ "legacy_alter_table", |
| @@ -124181,19 +124001,10 @@ | |
| 124001 | {/* zName: */ "recursive_triggers", |
| 124002 | /* ePragTyp: */ PragTyp_FLAG, |
| 124003 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 124004 | /* ColNames: */ 0, 0, |
| 124005 | /* iArg: */ SQLITE_RecTriggers }, |
| 124006 | {/* zName: */ "reverse_unordered_selects", |
| 124007 | /* ePragTyp: */ PragTyp_FLAG, |
| 124008 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 124009 | /* ColNames: */ 0, 0, |
| 124010 | /* iArg: */ SQLITE_ReverseOrder }, |
| @@ -124274,22 +124085,10 @@ | |
| 124085 | /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY, |
| 124086 | /* ePragFlg: */ PragFlg_NoColumns1, |
| 124087 | /* ColNames: */ 0, 0, |
| 124088 | /* iArg: */ 0 }, |
| 124089 | #endif |
| 124090 | {/* zName: */ "threads", |
| 124091 | /* ePragTyp: */ PragTyp_THREADS, |
| 124092 | /* ePragFlg: */ PragFlg_Result0, |
| 124093 | /* ColNames: */ 0, 0, |
| 124094 | /* iArg: */ 0 }, |
| @@ -124354,11 +124153,11 @@ | |
| 124153 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 124154 | /* ColNames: */ 0, 0, |
| 124155 | /* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError }, |
| 124156 | #endif |
| 124157 | }; |
| 124158 | /* Number of pragmas: 66 on by default, 76 total. */ |
| 124159 | |
| 124160 | /************** End of pragma.h **********************************************/ |
| 124161 | /************** Continuing where we left off in pragma.c *********************/ |
| 124162 | |
| 124163 | /* |
| @@ -126544,63 +126343,15 @@ | |
| 126343 | } |
| 126344 | break; |
| 126345 | } |
| 126346 | #endif |
| 126347 | |
| 126348 | #if defined(SQLITE_ENABLE_CEROD) |
| 126349 | case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){ |
| 126350 | if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){ |
| 126351 | sqlite3_activate_cerod(&zRight[6]); |
| 126352 | } |
| 126353 | } |
| 126354 | break; |
| 126355 | #endif |
| 126356 | |
| 126357 | } /* End of the PRAGMA switch */ |
| @@ -130671,10 +130422,11 @@ | |
| 130422 | p->pLimit = pLimit; |
| 130423 | |
| 130424 | /* Generate code to take the intersection of the two temporary |
| 130425 | ** tables. |
| 130426 | */ |
| 130427 | if( rc ) break; |
| 130428 | assert( p->pEList ); |
| 130429 | iBreak = sqlite3VdbeMakeLabel(pParse); |
| 130430 | iCont = sqlite3VdbeMakeLabel(pParse); |
| 130431 | computeLimitRegisters(pParse, p, iBreak); |
| 130432 | sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v); |
| @@ -132031,13 +131783,12 @@ | |
| 131783 | ){ |
| 131784 | int i; |
| 131785 | assert( pColumn->op==TK_COLUMN ); |
| 131786 | assert( sqlite3ExprIsConstant(pValue) ); |
| 131787 | |
| 131788 | if( ExprHasProperty(pColumn, EP_FixedCol) ) return; |
| 131789 | if( sqlite3ExprAffinity(pValue)!=0 ) return; |
| 131790 | if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){ |
| 131791 | return; |
| 131792 | } |
| 131793 | |
| 131794 | /* 2018-10-25 ticket [cf5ed20f] |
| @@ -132056,13 +131807,10 @@ | |
| 131807 | pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr, |
| 131808 | pConst->nConst*2*sizeof(Expr*)); |
| 131809 | if( pConst->apExpr==0 ){ |
| 131810 | pConst->nConst = 0; |
| 131811 | }else{ |
| 131812 | pConst->apExpr[pConst->nConst*2-2] = pColumn; |
| 131813 | pConst->apExpr[pConst->nConst*2-1] = pValue; |
| 131814 | } |
| 131815 | } |
| 131816 | |
| @@ -132334,11 +132082,11 @@ | |
| 132082 | static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){ |
| 132083 | int eRet = WHERE_ORDERBY_NORMAL; /* Return value */ |
| 132084 | ExprList *pEList = pFunc->x.pList; /* Arguments to agg function */ |
| 132085 | const char *zFunc; /* Name of aggregate function pFunc */ |
| 132086 | ExprList *pOrderBy; |
| 132087 | u8 sortFlags = 0; |
| 132088 | |
| 132089 | assert( *ppMinMax==0 ); |
| 132090 | assert( pFunc->op==TK_AGG_FUNCTION ); |
| 132091 | assert( !IsWindowFunc(pFunc) ); |
| 132092 | if( pEList==0 || pEList->nExpr!=1 || ExprHasProperty(pFunc, EP_WinFunc) ){ |
| @@ -132345,11 +132093,13 @@ | |
| 132093 | return eRet; |
| 132094 | } |
| 132095 | zFunc = pFunc->u.zToken; |
| 132096 | if( sqlite3StrICmp(zFunc, "min")==0 ){ |
| 132097 | eRet = WHERE_ORDERBY_MIN; |
| 132098 | if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){ |
| 132099 | sortFlags = KEYINFO_ORDER_BIGNULL; |
| 132100 | } |
| 132101 | }else if( sqlite3StrICmp(zFunc, "max")==0 ){ |
| 132102 | eRet = WHERE_ORDERBY_MAX; |
| 132103 | sortFlags = KEYINFO_ORDER_DESC; |
| 132104 | }else{ |
| 132105 | return eRet; |
| @@ -133013,11 +132763,11 @@ | |
| 132763 | pExpr = pRight; |
| 132764 | } |
| 132765 | pNew = sqlite3ExprListAppend(pParse, pNew, pExpr); |
| 132766 | sqlite3TokenInit(&sColname, zColname); |
| 132767 | sqlite3ExprListSetName(pParse, pNew, &sColname, 0); |
| 132768 | if( pNew && (p->selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){ |
| 132769 | struct ExprList_item *pX = &pNew->a[pNew->nExpr-1]; |
| 132770 | sqlite3DbFree(db, pX->zEName); |
| 132771 | if( pSub ){ |
| 132772 | pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName); |
| 132773 | testcase( pX->zEName==0 ); |
| @@ -133358,11 +133108,11 @@ | |
| 133108 | sqlite3ExprCode(pParse, pC->pExpr, pC->iMem); |
| 133109 | } |
| 133110 | |
| 133111 | pAggInfo->directMode = 0; |
| 133112 | if( addrHitTest ){ |
| 133113 | sqlite3VdbeJumpHereOrPopInst(v, addrHitTest); |
| 133114 | } |
| 133115 | } |
| 133116 | |
| 133117 | /* |
| 133118 | ** Add a single OP_Explain instruction to the VDBE to explain a simple |
| @@ -136671,11 +136421,13 @@ | |
| 136421 | if( eOnePass==ONEPASS_MULTI && (nIdx-(aiCurOnePass[1]>=0))>0 ){ |
| 136422 | addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); |
| 136423 | } |
| 136424 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur, |
| 136425 | aToOpen, 0, 0); |
| 136426 | if( addrOnce ){ |
| 136427 | sqlite3VdbeJumpHereOrPopInst(v, addrOnce); |
| 136428 | } |
| 136429 | } |
| 136430 | |
| 136431 | /* Top of the update loop */ |
| 136432 | if( eOnePass!=ONEPASS_OFF ){ |
| 136433 | if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){ |
| @@ -137626,21 +137378,10 @@ | |
| 137378 | } |
| 137379 | db->mDbFlags |= DBFLAG_VacuumInto; |
| 137380 | } |
| 137381 | nRes = sqlite3BtreeGetOptimalReserve(pMain); |
| 137382 | |
| 137383 | sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size); |
| 137384 | sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0)); |
| 137385 | sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF|PAGER_CACHESPILL); |
| 137386 | |
| 137387 | /* Begin a transaction and take an exclusive lock on the main database |
| @@ -139443,10 +139184,16 @@ | |
| 139184 | #define TERM_LIKEOPT 0x0100 /* Virtual terms from the LIKE optimization */ |
| 139185 | #define TERM_LIKECOND 0x0200 /* Conditionally this LIKE operator term */ |
| 139186 | #define TERM_LIKE 0x0400 /* The original LIKE operator */ |
| 139187 | #define TERM_IS 0x0800 /* Term.pExpr is an IS operator */ |
| 139188 | #define TERM_VARSELECT 0x1000 /* Term.pExpr contains a correlated sub-query */ |
| 139189 | #define TERM_HEURTRUTH 0x2000 /* Heuristic truthProb used */ |
| 139190 | #ifdef SQLITE_ENABLE_STAT4 |
| 139191 | # define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */ |
| 139192 | #else |
| 139193 | # define TERM_HIGHTRUTH 0 /* Only used with STAT4 */ |
| 139194 | #endif |
| 139195 | |
| 139196 | /* |
| 139197 | ** An instance of the WhereScan object is used as an iterator for locating |
| 139198 | ** terms in the WHERE clause that are useful to the query planner. |
| 139199 | */ |
| @@ -139557,17 +139304,20 @@ | |
| 139304 | WhereOrSet *pOrSet; /* Record best loops here, if not NULL */ |
| 139305 | #ifdef SQLITE_ENABLE_STAT4 |
| 139306 | UnpackedRecord *pRec; /* Probe for stat4 (if required) */ |
| 139307 | int nRecValid; /* Number of valid fields currently in pRec */ |
| 139308 | #endif |
| 139309 | unsigned char bldFlags1; /* First set of SQLITE_BLDF_* flags */ |
| 139310 | unsigned char bldFlags2; /* Second set of SQLITE_BLDF_* flags */ |
| 139311 | unsigned int iPlanLimit; /* Search limiter */ |
| 139312 | }; |
| 139313 | |
| 139314 | /* Allowed values for WhereLoopBuider.bldFlags */ |
| 139315 | #define SQLITE_BLDF1_INDEXED 0x0001 /* An index is used */ |
| 139316 | #define SQLITE_BLDF1_UNIQUE 0x0002 /* All keys of a UNIQUE index used */ |
| 139317 | |
| 139318 | #define SQLITE_BLDF2_2NDPASS 0x0004 /* Second builder pass needed */ |
| 139319 | |
| 139320 | /* The WhereLoopBuilder.iPlanLimit is used to limit the number of |
| 139321 | ** index+constraint combinations the query planner will consider for a |
| 139322 | ** particular query. If this parameter is unlimited, then certain |
| 139323 | ** pathological queries can spend excess time in the sqlite3WhereBegin() |
| @@ -141177,11 +140927,13 @@ | |
| 140927 | if( pCompare ){ |
| 140928 | pCompare->pLeft = pTerm->pExpr->pLeft; |
| 140929 | pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0); |
| 140930 | if( pRight ){ |
| 140931 | pRight->iTable = iReg+j+2; |
| 140932 | sqlite3ExprIfFalse( |
| 140933 | pParse, pCompare, pLevel->addrCont, SQLITE_JUMPIFNULL |
| 140934 | ); |
| 140935 | } |
| 140936 | pCompare->pLeft = 0; |
| 140937 | sqlite3ExprDelete(db, pCompare); |
| 140938 | } |
| 140939 | } |
| @@ -142591,11 +142343,12 @@ | |
| 142343 | ** |
| 142344 | ** vtab_column MATCH expression |
| 142345 | ** MATCH(expression,vtab_column) |
| 142346 | */ |
| 142347 | pCol = pList->a[1].pExpr; |
| 142348 | testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 ); |
| 142349 | if( ExprIsVtab(pCol) ){ |
| 142350 | for(i=0; i<ArraySize(aOp); i++){ |
| 142351 | if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){ |
| 142352 | *peOp2 = aOp[i].eOp2; |
| 142353 | *ppRight = pList->a[0].pExpr; |
| 142354 | *ppLeft = pCol; |
| @@ -142613,11 +142366,12 @@ | |
| 142366 | ** Historically, xFindFunction expected to see lower-case function |
| 142367 | ** names. But for this use case, xFindFunction is expected to deal |
| 142368 | ** with function names in an arbitrary case. |
| 142369 | */ |
| 142370 | pCol = pList->a[0].pExpr; |
| 142371 | testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 ); |
| 142372 | if( ExprIsVtab(pCol) ){ |
| 142373 | sqlite3_vtab *pVtab; |
| 142374 | sqlite3_module *pMod; |
| 142375 | void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**); |
| 142376 | void *pNotUsed; |
| 142377 | pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab; |
| @@ -142636,14 +142390,16 @@ | |
| 142390 | } |
| 142391 | }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){ |
| 142392 | int res = 0; |
| 142393 | Expr *pLeft = pExpr->pLeft; |
| 142394 | Expr *pRight = pExpr->pRight; |
| 142395 | testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 ); |
| 142396 | if( ExprIsVtab(pLeft) ){ |
| 142397 | res++; |
| 142398 | } |
| 142399 | testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 ); |
| 142400 | if( pRight && ExprIsVtab(pRight) ){ |
| 142401 | res++; |
| 142402 | SWAP(Expr*, pLeft, pRight); |
| 142403 | } |
| 142404 | *ppLeft = pLeft; |
| 142405 | *ppRight = pRight; |
| @@ -146123,20 +145879,25 @@ | |
| 145879 | pLoop->nOut += pTerm->truthProb; |
| 145880 | }else{ |
| 145881 | /* In the absence of explicit truth probabilities, use heuristics to |
| 145882 | ** guess a reasonable truth probability. */ |
| 145883 | pLoop->nOut--; |
| 145884 | if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 |
| 145885 | && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */ |
| 145886 | ){ |
| 145887 | Expr *pRight = pTerm->pExpr->pRight; |
| 145888 | int k = 0; |
| 145889 | testcase( pTerm->pExpr->op==TK_IS ); |
| 145890 | if( sqlite3ExprIsInteger(pRight, &k) && k>=(-1) && k<=1 ){ |
| 145891 | k = 10; |
| 145892 | }else{ |
| 145893 | k = 20; |
| 145894 | } |
| 145895 | if( iReduce<k ){ |
| 145896 | pTerm->wtFlags |= TERM_HEURTRUTH; |
| 145897 | iReduce = k; |
| 145898 | } |
| 145899 | } |
| 145900 | } |
| 145901 | } |
| 145902 | } |
| 145903 | if( pLoop->nOut > nRow-iReduce ) pLoop->nOut = nRow - iReduce; |
| @@ -146314,13 +146075,13 @@ | |
| 146075 | ){ |
| 146076 | continue; |
| 146077 | } |
| 146078 | |
| 146079 | if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){ |
| 146080 | pBuilder->bldFlags1 |= SQLITE_BLDF1_UNIQUE; |
| 146081 | }else{ |
| 146082 | pBuilder->bldFlags1 |= SQLITE_BLDF1_INDEXED; |
| 146083 | } |
| 146084 | pNew->wsFlags = saved_wsFlags; |
| 146085 | pNew->u.btree.nEq = saved_nEq; |
| 146086 | pNew->u.btree.nBtm = saved_nBtm; |
| 146087 | pNew->u.btree.nTop = saved_nTop; |
| @@ -146481,10 +146242,31 @@ | |
| 146242 | } |
| 146243 | if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; |
| 146244 | if( rc!=SQLITE_OK ) break; /* Jump out of the pTerm loop */ |
| 146245 | if( nOut ){ |
| 146246 | pNew->nOut = sqlite3LogEst(nOut); |
| 146247 | if( nEq==1 |
| 146248 | /* TUNING: Mark terms as "low selectivity" if they seem likely |
| 146249 | ** to be true for half or more of the rows in the table. |
| 146250 | ** See tag-202002240-1 */ |
| 146251 | && pNew->nOut+10 > pProbe->aiRowLogEst[0] |
| 146252 | ){ |
| 146253 | #if WHERETRACE_ENABLED /* 0x01 */ |
| 146254 | if( sqlite3WhereTrace & 0x01 ){ |
| 146255 | sqlite3DebugPrintf( |
| 146256 | "STAT4 determines term has low selectivity:\n"); |
| 146257 | sqlite3WhereTermPrint(pTerm, 999); |
| 146258 | } |
| 146259 | #endif |
| 146260 | pTerm->wtFlags |= TERM_HIGHTRUTH; |
| 146261 | if( pTerm->wtFlags & TERM_HEURTRUTH ){ |
| 146262 | /* If the term has previously been used with an assumption of |
| 146263 | ** higher selectivity, then set the flag to rerun the |
| 146264 | ** loop computations. */ |
| 146265 | pBuilder->bldFlags2 |= SQLITE_BLDF2_2NDPASS; |
| 146266 | } |
| 146267 | } |
| 146268 | if( pNew->nOut>saved_nOut ) pNew->nOut = saved_nOut; |
| 146269 | pNew->nOut -= nIn; |
| 146270 | } |
| 146271 | } |
| 146272 | if( nOut==0 ) |
| @@ -146557,10 +146339,11 @@ | |
| 146339 | assert( 42==sqlite3LogEst(18) ); |
| 146340 | if( saved_nEq==saved_nSkip |
| 146341 | && saved_nEq+1<pProbe->nKeyCol |
| 146342 | && saved_nEq==pNew->nLTerm |
| 146343 | && pProbe->noSkipScan==0 |
| 146344 | && pProbe->hasStat1!=0 |
| 146345 | && OptimizationEnabled(db, SQLITE_SkipScan) |
| 146346 | && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */ |
| 146347 | && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK |
| 146348 | ){ |
| 146349 | LogEst nIter; |
| @@ -146904,13 +146687,13 @@ | |
| 146687 | pNew->nOut = rSize; |
| 146688 | if( rc ) break; |
| 146689 | } |
| 146690 | } |
| 146691 | |
| 146692 | pBuilder->bldFlags1 = 0; |
| 146693 | rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0); |
| 146694 | if( pBuilder->bldFlags1==SQLITE_BLDF1_INDEXED ){ |
| 146695 | /* If a non-unique index is used, or if a prefix of the key for |
| 146696 | ** unique index is used (making the index functionally non-unique) |
| 146697 | ** then the sqlite_stat1 data becomes important for scoring the |
| 146698 | ** plan */ |
| 146699 | pTab->tabFlags |= TF_StatsUsed; |
| @@ -147577,12 +147360,15 @@ | |
| 147360 | assert( wctrlFlags & WHERE_ORDERBY_LIMIT ); |
| 147361 | for(j=0; j<pLoop->nLTerm && pTerm!=pLoop->aLTerm[j]; j++){} |
| 147362 | if( j>=pLoop->nLTerm ) continue; |
| 147363 | } |
| 147364 | if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 && pOBExpr->iColumn>=0 ){ |
| 147365 | Parse *pParse = pWInfo->pParse; |
| 147366 | CollSeq *pColl1 = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[i].pExpr); |
| 147367 | CollSeq *pColl2 = sqlite3ExprCompareCollSeq(pParse, pTerm->pExpr); |
| 147368 | assert( pColl1 ); |
| 147369 | if( pColl2==0 || sqlite3StrICmp(pColl1->zName, pColl2->zName) ){ |
| 147370 | continue; |
| 147371 | } |
| 147372 | testcase( pTerm->pExpr->op==TK_IS ); |
| 147373 | } |
| 147374 | obSat |= MASKBIT(i); |
| @@ -148358,10 +148144,32 @@ | |
| 148144 | w.xSelectCallback = sqlite3SelectWalkFail; |
| 148145 | sqlite3WalkExpr(&w, p); |
| 148146 | return w.eCode; |
| 148147 | } |
| 148148 | |
| 148149 | |
| 148150 | #ifdef WHERETRACE_ENABLED |
| 148151 | /* |
| 148152 | ** Display all WhereLoops in pWInfo |
| 148153 | */ |
| 148154 | static void showAllWhereLoops(WhereInfo *pWInfo, WhereClause *pWC){ |
| 148155 | if( sqlite3WhereTrace ){ /* Display all of the WhereLoop objects */ |
| 148156 | WhereLoop *p; |
| 148157 | int i; |
| 148158 | static const char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz" |
| 148159 | "ABCDEFGHIJKLMNOPQRSTUVWYXZ"; |
| 148160 | for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){ |
| 148161 | p->cId = zLabel[i%(sizeof(zLabel)-1)]; |
| 148162 | sqlite3WhereLoopPrint(p, pWC); |
| 148163 | } |
| 148164 | } |
| 148165 | } |
| 148166 | # define WHERETRACE_ALL_LOOPS(W,C) showAllWhereLoops(W,C) |
| 148167 | #else |
| 148168 | # define WHERETRACE_ALL_LOOPS(W,C) |
| 148169 | #endif |
| 148170 | |
| 148171 | /* |
| 148172 | ** Generate the beginning of the loop used for WHERE clause processing. |
| 148173 | ** The return value is a pointer to an opaque structure that contains |
| 148174 | ** information needed to terminate the loop. Later, the calling routine |
| 148175 | ** should invoke sqlite3WhereEnd() with the return value of this function |
| @@ -148659,23 +148467,32 @@ | |
| 148467 | #endif |
| 148468 | |
| 148469 | if( nTabList!=1 || whereShortCut(&sWLB)==0 ){ |
| 148470 | rc = whereLoopAddAll(&sWLB); |
| 148471 | if( rc ) goto whereBeginError; |
| 148472 | |
| 148473 | #ifdef SQLITE_ENABLE_STAT4 |
| 148474 | /* If one or more WhereTerm.truthProb values were used in estimating |
| 148475 | ** loop parameters, but then those truthProb values were subsequently |
| 148476 | ** changed based on STAT4 information while computing subsequent loops, |
| 148477 | ** then we need to rerun the whole loop building process so that all |
| 148478 | ** loops will be built using the revised truthProb values. */ |
| 148479 | if( sWLB.bldFlags2 & SQLITE_BLDF2_2NDPASS ){ |
| 148480 | WHERETRACE_ALL_LOOPS(pWInfo, sWLB.pWC); |
| 148481 | WHERETRACE(0xffff, |
| 148482 | ("**** Redo all loop computations due to" |
| 148483 | " TERM_HIGHTRUTH changes ****\n")); |
| 148484 | while( pWInfo->pLoops ){ |
| 148485 | WhereLoop *p = pWInfo->pLoops; |
| 148486 | pWInfo->pLoops = p->pNextLoop; |
| 148487 | whereLoopDelete(db, p); |
| 148488 | } |
| 148489 | rc = whereLoopAddAll(&sWLB); |
| 148490 | if( rc ) goto whereBeginError; |
| 148491 | } |
| 148492 | #endif |
| 148493 | WHERETRACE_ALL_LOOPS(pWInfo, sWLB.pWC); |
| 148494 | |
| 148495 | wherePathSolver(pWInfo, 0); |
| 148496 | if( db->mallocFailed ) goto whereBeginError; |
| 148497 | if( pWInfo->pOrderBy ){ |
| 148498 | wherePathSolver(pWInfo, pWInfo->nRowOut+1); |
| @@ -156496,10 +156313,16 @@ | |
| 156313 | ** simplify to constants 0 (false) and 1 (true), respectively, |
| 156314 | ** regardless of the value of expr1. |
| 156315 | */ |
| 156316 | sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy202); |
| 156317 | yymsp[-4].minor.yy202 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy192 ? "1" : "0"); |
| 156318 | }else if( 0 && yymsp[-1].minor.yy242->nExpr==1 && sqlite3ExprIsConstant(yymsp[-1].minor.yy242->a[0].pExpr) ){ |
| 156319 | Expr *pRHS = yymsp[-1].minor.yy242->a[0].pExpr; |
| 156320 | yymsp[-1].minor.yy242->a[0].pExpr = 0; |
| 156321 | sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy242); |
| 156322 | yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_EQ, yymsp[-4].minor.yy202, pRHS); |
| 156323 | if( yymsp[-3].minor.yy192 ) yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy202, 0); |
| 156324 | }else{ |
| 156325 | yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy202, 0); |
| 156326 | if( yymsp[-4].minor.yy202 ){ |
| 156327 | yymsp[-4].minor.yy202->x.pList = yymsp[-1].minor.yy242; |
| 156328 | sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy202); |
| @@ -157767,16 +157590,21 @@ | |
| 157590 | const char *zKW; |
| 157591 | if( n>=2 ){ |
| 157592 | i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n) % 127; |
| 157593 | for(i=((int)aKWHash[i])-1; i>=0; i=((int)aKWNext[i])-1){ |
| 157594 | if( aKWLen[i]!=n ) continue; |
| 157595 | zKW = &zKWText[aKWOffset[i]]; |
| 157596 | #ifdef SQLITE_ASCII |
| 157597 | if( (z[0]&~0x20)!=zKW[0] ) continue; |
| 157598 | if( (z[1]&~0x20)!=zKW[1] ) continue; |
| 157599 | j = 2; |
| 157600 | while( j<n && (z[j]&~0x20)==zKW[j] ){ j++; } |
| 157601 | #endif |
| 157602 | #ifdef SQLITE_EBCDIC |
| 157603 | if( toupper(z[0])!=zKW[0] ) continue; |
| 157604 | if( toupper(z[1])!=zKW[1] ) continue; |
| 157605 | j = 2; |
| 157606 | while( j<n && toupper(z[j])==zKW[j] ){ j++; } |
| 157607 | #endif |
| 157608 | if( j<n ) continue; |
| 157609 | testcase( i==0 ); /* REINDEX */ |
| 157610 | testcase( i==1 ); /* INDEXED */ |
| @@ -159218,11 +159046,14 @@ | |
| 159046 | /* If SQLite is already completely initialized, then this call |
| 159047 | ** to sqlite3_initialize() should be a no-op. But the initialization |
| 159048 | ** must be complete. So isInit must not be set until the very end |
| 159049 | ** of this routine. |
| 159050 | */ |
| 159051 | if( sqlite3GlobalConfig.isInit ){ |
| 159052 | sqlite3MemoryBarrier(); |
| 159053 | return SQLITE_OK; |
| 159054 | } |
| 159055 | |
| 159056 | /* Make sure the mutex subsystem is initialized. If unable to |
| 159057 | ** initialize the mutex subsystem, return early with the error. |
| 159058 | ** If the system is so sick that we are unable to allocate a mutex, |
| 159059 | ** there is not much SQLite is going to be able to do. |
| @@ -161807,13 +161638,15 @@ | |
| 161638 | ** *pFlags may be updated before returning if the URI filename contains |
| 161639 | ** "cache=xxx" or "mode=xxx" query parameters. |
| 161640 | ** |
| 161641 | ** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to |
| 161642 | ** the VFS that should be used to open the database file. *pzFile is set to |
| 161643 | ** point to a buffer containing the name of the file to open. The value |
| 161644 | ** stored in *pzFile is a database name acceptable to sqlite3_uri_parameter() |
| 161645 | ** and is in the same format as names created using sqlite3_create_filename(). |
| 161646 | ** The caller must invoke sqlite3_free_filename() (not sqlite3_free()!) on |
| 161647 | ** the value returned in *pzFile to avoid a memory leak. |
| 161648 | ** |
| 161649 | ** If an error occurs, then an SQLite error code is returned and *pzErrMsg |
| 161650 | ** may be set to point to a buffer containing an English language error |
| 161651 | ** message. It is the responsibility of the caller to eventually release |
| 161652 | ** this buffer by calling sqlite3_free(). |
| @@ -161841,19 +161674,22 @@ | |
| 161674 | ){ |
| 161675 | char *zOpt; |
| 161676 | int eState; /* Parser state when parsing URI */ |
| 161677 | int iIn; /* Input character index */ |
| 161678 | int iOut = 0; /* Output character index */ |
| 161679 | u64 nByte = nUri+8; /* Bytes of space to allocate */ |
| 161680 | |
| 161681 | /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen |
| 161682 | ** method that there may be extra parameters following the file-name. */ |
| 161683 | flags |= SQLITE_OPEN_URI; |
| 161684 | |
| 161685 | for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&'); |
| 161686 | zFile = sqlite3_malloc64(nByte); |
| 161687 | if( !zFile ) return SQLITE_NOMEM_BKPT; |
| 161688 | |
| 161689 | memset(zFile, 0, 4); /* 4-byte of 0x00 is the start of DB name marker */ |
| 161690 | zFile += 4; |
| 161691 | |
| 161692 | iIn = 5; |
| 161693 | #ifdef SQLITE_ALLOW_URI_AUTHORITY |
| 161694 | if( strncmp(zUri+5, "///", 3)==0 ){ |
| 161695 | iIn = 7; |
| @@ -161940,12 +161776,11 @@ | |
| 161776 | eState = 1; |
| 161777 | } |
| 161778 | zFile[iOut++] = c; |
| 161779 | } |
| 161780 | if( eState==1 ) zFile[iOut++] = '\0'; |
| 161781 | memset(zFile+iOut, 0, 4); /* end-of-options + empty journal filenames */ |
| 161782 | |
| 161783 | /* Check if there were any options specified that should be interpreted |
| 161784 | ** here. Options that are interpreted here include "vfs" and those that |
| 161785 | ** correspond to flags that may be passed to the sqlite3_open_v2() |
| 161786 | ** method. */ |
| @@ -162021,17 +161856,18 @@ | |
| 161856 | |
| 161857 | zOpt = &zVal[nVal+1]; |
| 161858 | } |
| 161859 | |
| 161860 | }else{ |
| 161861 | zFile = sqlite3_malloc64(nUri+8); |
| 161862 | if( !zFile ) return SQLITE_NOMEM_BKPT; |
| 161863 | memset(zFile, 0, 4); |
| 161864 | zFile += 4; |
| 161865 | if( nUri ){ |
| 161866 | memcpy(zFile, zUri, nUri); |
| 161867 | } |
| 161868 | memset(zFile+nUri, 0, 4); |
| 161869 | flags &= ~SQLITE_OPEN_URI; |
| 161870 | } |
| 161871 | |
| 161872 | *ppVfs = sqlite3_vfs_find(zVfs); |
| 161873 | if( *ppVfs==0 ){ |
| @@ -162038,51 +161874,33 @@ | |
| 161874 | *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs); |
| 161875 | rc = SQLITE_ERROR; |
| 161876 | } |
| 161877 | parse_uri_out: |
| 161878 | if( rc!=SQLITE_OK ){ |
| 161879 | sqlite3_free_filename(zFile); |
| 161880 | zFile = 0; |
| 161881 | } |
| 161882 | *pFlags = flags; |
| 161883 | *pzFile = zFile; |
| 161884 | return rc; |
| 161885 | } |
| 161886 | |
| 161887 | /* |
| 161888 | ** This routine does the core work of extracting URI parameters from a |
| 161889 | ** database filename for the sqlite3_uri_parameter() interface. |
| 161890 | */ |
| 161891 | static const char *uriParameter(const char *zFilename, const char *zParam){ |
| 161892 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 161893 | while( zFilename[0] ){ |
| 161894 | int x = strcmp(zFilename, zParam); |
| 161895 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 161896 | if( x==0 ) return zFilename; |
| 161897 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 161898 | } |
| 161899 | return 0; |
| 161900 | } |
| 161901 | |
| 161902 | |
| 161903 | |
| 161904 | /* |
| 161905 | ** This routine does the work of opening a database on behalf of |
| 161906 | ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename" |
| @@ -162463,14 +162281,11 @@ | |
| 162281 | /* Opening a db handle. Fourth parameter is passed 0. */ |
| 162282 | void *pArg = sqlite3GlobalConfig.pSqllogArg; |
| 162283 | sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0); |
| 162284 | } |
| 162285 | #endif |
| 162286 | sqlite3_free_filename(zOpen); |
| 162287 | return rc & 0xff; |
| 162288 | } |
| 162289 | |
| 162290 | |
| 162291 | /* |
| @@ -162693,17 +162508,19 @@ | |
| 162508 | } |
| 162509 | SQLITE_PRIVATE int sqlite3CantopenError(int lineno){ |
| 162510 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 162511 | return sqlite3ReportError(SQLITE_CANTOPEN, lineno, "cannot open file"); |
| 162512 | } |
| 162513 | #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_CORRUPT_PGNO) |
| 162514 | SQLITE_PRIVATE int sqlite3CorruptPgnoError(int lineno, Pgno pgno){ |
| 162515 | char zMsg[100]; |
| 162516 | sqlite3_snprintf(sizeof(zMsg), zMsg, "database corruption page %d", pgno); |
| 162517 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 162518 | return sqlite3ReportError(SQLITE_CORRUPT, lineno, zMsg); |
| 162519 | } |
| 162520 | #endif |
| 162521 | #ifdef SQLITE_DEBUG |
| 162522 | SQLITE_PRIVATE int sqlite3NomemError(int lineno){ |
| 162523 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 162524 | return sqlite3ReportError(SQLITE_NOMEM, lineno, "OOM"); |
| 162525 | } |
| 162526 | SQLITE_PRIVATE int sqlite3IoerrnomemError(int lineno){ |
| @@ -163314,10 +163131,72 @@ | |
| 163131 | while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){ |
| 163132 | zName--; |
| 163133 | } |
| 163134 | return zName; |
| 163135 | } |
| 163136 | |
| 163137 | /* |
| 163138 | ** Append text z[] to the end of p[]. Return a pointer to the first |
| 163139 | ** character after then zero terminator on the new text in p[]. |
| 163140 | */ |
| 163141 | static char *appendText(char *p, const char *z){ |
| 163142 | size_t n = strlen(z); |
| 163143 | memcpy(p, z, n+1); |
| 163144 | return p+n+1; |
| 163145 | } |
| 163146 | |
| 163147 | /* |
| 163148 | ** Allocate memory to hold names for a database, journal file, WAL file, |
| 163149 | ** and query parameters. The pointer returned is valid for use by |
| 163150 | ** sqlite3_filename_database() and sqlite3_uri_parameter() and related |
| 163151 | ** functions. |
| 163152 | ** |
| 163153 | ** Memory layout must be compatible with that generated by the pager |
| 163154 | ** and expected by sqlite3_uri_parameter() and databaseName(). |
| 163155 | */ |
| 163156 | SQLITE_API char *sqlite3_create_filename( |
| 163157 | const char *zDatabase, |
| 163158 | const char *zJournal, |
| 163159 | const char *zWal, |
| 163160 | int nParam, |
| 163161 | const char **azParam |
| 163162 | ){ |
| 163163 | sqlite3_int64 nByte; |
| 163164 | int i; |
| 163165 | char *pResult, *p; |
| 163166 | nByte = strlen(zDatabase) + strlen(zJournal) + strlen(zWal) + 10; |
| 163167 | for(i=0; i<nParam*2; i++){ |
| 163168 | nByte += strlen(azParam[i])+1; |
| 163169 | } |
| 163170 | pResult = p = sqlite3_malloc64( nByte ); |
| 163171 | if( p==0 ) return 0; |
| 163172 | memset(p, 0, 4); |
| 163173 | p += 4; |
| 163174 | p = appendText(p, zDatabase); |
| 163175 | for(i=0; i<nParam*2; i++){ |
| 163176 | p = appendText(p, azParam[i]); |
| 163177 | } |
| 163178 | *(p++) = 0; |
| 163179 | p = appendText(p, zJournal); |
| 163180 | p = appendText(p, zWal); |
| 163181 | *(p++) = 0; |
| 163182 | *(p++) = 0; |
| 163183 | assert( (sqlite3_int64)(p - pResult)==nByte ); |
| 163184 | return pResult + 4; |
| 163185 | } |
| 163186 | |
| 163187 | /* |
| 163188 | ** Free memory obtained from sqlite3_create_filename(). It is a severe |
| 163189 | ** error to call this routine with any parameter other than a pointer |
| 163190 | ** previously obtained from sqlite3_create_filename() or a NULL pointer. |
| 163191 | */ |
| 163192 | SQLITE_API void sqlite3_free_filename(char *p){ |
| 163193 | if( p==0 ) return; |
| 163194 | p = (char*)databaseName(p); |
| 163195 | sqlite3_free(p - 4); |
| 163196 | } |
| 163197 | |
| 163198 | |
| 163199 | /* |
| 163200 | ** This is a utility routine, useful to VFS implementations, that checks |
| 163201 | ** to see if a database file was a URI that contained a specific query |
| 163202 | ** parameter, and if so obtains the value of the query parameter. |
| @@ -163329,18 +163208,11 @@ | |
| 163208 | ** returns a NULL pointer. |
| 163209 | */ |
| 163210 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){ |
| 163211 | if( zFilename==0 || zParam==0 ) return 0; |
| 163212 | zFilename = databaseName(zFilename); |
| 163213 | return uriParameter(zFilename, zParam); |
| 163214 | } |
| 163215 | |
| 163216 | /* |
| 163217 | ** Return a pointer to the name of Nth query parameter of the filename. |
| 163218 | */ |
| @@ -163390,11 +163262,10 @@ | |
| 163262 | ** an error that we cannot easily detect but that will likely cause memory |
| 163263 | ** corruption. |
| 163264 | */ |
| 163265 | SQLITE_API const char *sqlite3_filename_database(const char *zFilename){ |
| 163266 | return databaseName(zFilename); |
| 163267 | } |
| 163268 | SQLITE_API const char *sqlite3_filename_journal(const char *zFilename){ |
| 163269 | zFilename = databaseName(zFilename); |
| 163270 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 163271 | while( zFilename[0] ){ |
| @@ -174985,11 +174856,11 @@ | |
| 174856 | int nByte = sqlite3_value_bytes(apVal[0]); |
| 174857 | pCsr->zInput = sqlite3_malloc64(nByte+1); |
| 174858 | if( pCsr->zInput==0 ){ |
| 174859 | rc = SQLITE_NOMEM; |
| 174860 | }else{ |
| 174861 | if( nByte>0 ) memcpy(pCsr->zInput, zByte, nByte); |
| 174862 | pCsr->zInput[nByte] = 0; |
| 174863 | rc = pTab->pMod->xOpen(pTab->pTok, pCsr->zInput, nByte, &pCsr->pCsr); |
| 174864 | if( rc==SQLITE_OK ){ |
| 174865 | pCsr->pCsr->pTokenizer = pTab->pTok; |
| 174866 | } |
| @@ -177595,11 +177466,11 @@ | |
| 177466 | sqlite3_stmt *pStmt; |
| 177467 | int rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR_MAX_LEVEL, &pStmt, 0); |
| 177468 | if( rc!=SQLITE_OK ) return rc; |
| 177469 | sqlite3_bind_int64(pStmt, 1, iAbsLevel+1); |
| 177470 | sqlite3_bind_int64(pStmt, 2, |
| 177471 | (((u64)iAbsLevel/FTS3_SEGDIR_MAXLEVEL)+1) * FTS3_SEGDIR_MAXLEVEL |
| 177472 | ); |
| 177473 | |
| 177474 | *pbMax = 0; |
| 177475 | if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 177476 | *pbMax = sqlite3_column_type(pStmt, 0)==SQLITE_NULL; |
| @@ -223667,11 +223538,11 @@ | |
| 223538 | int nArg, /* Number of args */ |
| 223539 | sqlite3_value **apUnused /* Function arguments */ |
| 223540 | ){ |
| 223541 | assert( nArg==0 ); |
| 223542 | UNUSED_PARAM2(nArg, apUnused); |
| 223543 | sqlite3_result_text(pCtx, "fts5: 2020-02-27 11:32:14 bfb09371d452d5d4dacab2ec476880bc729952f44ac0e5de90ea7ba203243c8c", -1, SQLITE_TRANSIENT); |
| 223544 | } |
| 223545 | |
| 223546 | /* |
| 223547 | ** Return true if zName is the extension on one of the shadow tables used |
| 223548 | ** by this module. |
| @@ -227410,10 +227281,11 @@ | |
| 227281 | char *zFts5Tbl; /* Name of fts5 table */ |
| 227282 | char *zFts5Db; /* Db containing fts5 table */ |
| 227283 | sqlite3 *db; /* Database handle */ |
| 227284 | Fts5Global *pGlobal; /* FTS5 global object for this database */ |
| 227285 | int eType; /* FTS5_VOCAB_COL, ROW or INSTANCE */ |
| 227286 | unsigned bBusy; /* True if busy */ |
| 227287 | }; |
| 227288 | |
| 227289 | struct Fts5VocabCursor { |
| 227290 | sqlite3_vtab_cursor base; |
| 227291 | sqlite3_stmt *pStmt; /* Statement holding lock on pIndex */ |
| @@ -227692,10 +227564,16 @@ | |
| 227564 | Fts5VocabCursor *pCsr = 0; |
| 227565 | int rc = SQLITE_OK; |
| 227566 | sqlite3_stmt *pStmt = 0; |
| 227567 | char *zSql = 0; |
| 227568 | |
| 227569 | if( pTab->bBusy ){ |
| 227570 | pVTab->zErrMsg = sqlite3_mprintf( |
| 227571 | "recursive definition for %s.%s", pTab->zFts5Db, pTab->zFts5Tbl |
| 227572 | ); |
| 227573 | return SQLITE_ERROR; |
| 227574 | } |
| 227575 | zSql = sqlite3Fts5Mprintf(&rc, |
| 227576 | "SELECT t.%Q FROM %Q.%Q AS t WHERE t.%Q MATCH '*id'", |
| 227577 | pTab->zFts5Tbl, pTab->zFts5Db, pTab->zFts5Tbl, pTab->zFts5Tbl |
| 227578 | ); |
| 227579 | if( zSql ){ |
| @@ -227703,14 +227581,16 @@ | |
| 227581 | } |
| 227582 | sqlite3_free(zSql); |
| 227583 | assert( rc==SQLITE_OK || pStmt==0 ); |
| 227584 | if( rc==SQLITE_ERROR ) rc = SQLITE_OK; |
| 227585 | |
| 227586 | pTab->bBusy = 1; |
| 227587 | if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 227588 | i64 iId = sqlite3_column_int64(pStmt, 0); |
| 227589 | pFts5 = sqlite3Fts5TableFromCsrid(pTab->pGlobal, iId); |
| 227590 | } |
| 227591 | pTab->bBusy = 0; |
| 227592 | |
| 227593 | if( rc==SQLITE_OK ){ |
| 227594 | if( pFts5==0 ){ |
| 227595 | rc = sqlite3_finalize(pStmt); |
| 227596 | pStmt = 0; |
| @@ -228440,12 +228320,12 @@ | |
| 228320 | } |
| 228321 | #endif /* SQLITE_CORE */ |
| 228322 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 228323 | |
| 228324 | /************** End of stmt.c ************************************************/ |
| 228325 | #if __LINE__!=228325 |
| 228326 | #undef SQLITE_SOURCE_ID |
| 228327 | #define SQLITE_SOURCE_ID "2020-02-27 16:21:39 951b39ca74c9bd933139e099d5555283278db475f410f202c162e5d1e6aealt2" |
| 228328 | #endif |
| 228329 | /* Return the source-id for this library */ |
| 228330 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 228331 | /************************** End of sqlite3.c ******************************/ |
| 228332 |
+57
-49
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -121,13 +121,13 @@ | ||
| 121 | 121 | ** |
| 122 | 122 | ** See also: [sqlite3_libversion()], |
| 123 | 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | 125 | */ |
| 126 | -#define SQLITE_VERSION "3.31.1" | |
| 127 | -#define SQLITE_VERSION_NUMBER 3031001 | |
| 128 | -#define SQLITE_SOURCE_ID "2020-01-28 15:02:23 04885763c4cd00cbca26d048f2b19316bfc93e8edebeceaa171ebfc6c563d53e" | |
| 126 | +#define SQLITE_VERSION "3.32.0" | |
| 127 | +#define SQLITE_VERSION_NUMBER 3032000 | |
| 128 | +#define SQLITE_SOURCE_ID "2020-02-27 16:21:39 951b39ca74c9bd933139e099d5555283278db475f410f202c162e5d1e6aef933" | |
| 129 | 129 | |
| 130 | 130 | /* |
| 131 | 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | 133 | ** |
| @@ -3615,10 +3615,63 @@ | ||
| 3615 | 3615 | */ |
| 3616 | 3616 | SQLITE_API const char *sqlite3_filename_database(const char*); |
| 3617 | 3617 | SQLITE_API const char *sqlite3_filename_journal(const char*); |
| 3618 | 3618 | SQLITE_API const char *sqlite3_filename_wal(const char*); |
| 3619 | 3619 | |
| 3620 | +/* | |
| 3621 | +** CAPI3REF: Create and Destroy VFS Filenames | |
| 3622 | +** | |
| 3623 | +** These interfces are provided for use by [VFS shim] implementations and | |
| 3624 | +** are not useful outside of that context. | |
| 3625 | +** | |
| 3626 | +** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of | |
| 3627 | +** database filename D with corresponding journal file J and WAL file W and | |
| 3628 | +** with N URI parameters key/values pairs in the array P. The result from | |
| 3629 | +** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that | |
| 3630 | +** is safe to pass to routines like: | |
| 3631 | +** <ul> | |
| 3632 | +** <li> [sqlite3_uri_parameter()], | |
| 3633 | +** <li> [sqlite3_uri_boolean()], | |
| 3634 | +** <li> [sqlite3_uri_int64()], | |
| 3635 | +** <li> [sqlite3_uri_key()], | |
| 3636 | +** <li> [sqlite3_filename_database()], | |
| 3637 | +** <li> [sqlite3_filename_journal()], or | |
| 3638 | +** <li> [sqlite3_filename_wal()]. | |
| 3639 | +** </ul> | |
| 3640 | +** If a memory allocation error occurs, sqlite3_create_filename() might | |
| 3641 | +** return a NULL pointer. The memory obtained from sqlite3_create_filename(X) | |
| 3642 | +** must be released by a corresponding call to sqlite3_free_filename(Y). | |
| 3643 | +** | |
| 3644 | +** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array | |
| 3645 | +** of 2*N pointers to strings. Each pair of pointers in this array corresponds | |
| 3646 | +** to a key and value for a query parameter. The P parameter may be a NULL | |
| 3647 | +** pointer if N is zero. None of the 2*N pointers in the P array may be | |
| 3648 | +** NULL pointers and key pointers should not be empty strings. | |
| 3649 | +** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may | |
| 3650 | +** be NULL pointers, though they can be empty strings. | |
| 3651 | +** | |
| 3652 | +** The sqlite3_free_filename(Y) routine releases a memory allocation | |
| 3653 | +** previously obtained from sqlite3_create_filename(). Invoking | |
| 3654 | +** sqlite3_free_filename(Y) is a NULL pointer is a harmless no-op. | |
| 3655 | +** | |
| 3656 | +** If the Y parameter to sqlite3_free_filename(Y) is anything other | |
| 3657 | +** than a NULL pointer or a pointer previously acquired from | |
| 3658 | +** sqlite3_create_filename(), then bad things such as heap | |
| 3659 | +** corruption or segfaults may occur. The value Y should be | |
| 3660 | +** used again after sqlite3_free_filename(Y) has been called. This means | |
| 3661 | +** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y, | |
| 3662 | +** then the corresponding [sqlite3_module.xClose() method should also be | |
| 3663 | +** invoked prior to calling sqlite3_free_filename(Y). | |
| 3664 | +*/ | |
| 3665 | +SQLITE_API char *sqlite3_create_filename( | |
| 3666 | + const char *zDatabase, | |
| 3667 | + const char *zJournal, | |
| 3668 | + const char *zWal, | |
| 3669 | + int nParam, | |
| 3670 | + const char **azParam | |
| 3671 | +); | |
| 3672 | +SQLITE_API void sqlite3_free_filename(char*); | |
| 3620 | 3673 | |
| 3621 | 3674 | /* |
| 3622 | 3675 | ** CAPI3REF: Error Codes And Messages |
| 3623 | 3676 | ** METHOD: sqlite3 |
| 3624 | 3677 | ** |
| @@ -4197,11 +4250,11 @@ | ||
| 4197 | 4250 | ** occurrences have the same index as the first occurrence. |
| 4198 | 4251 | ** ^The index for named parameters can be looked up using the |
| 4199 | 4252 | ** [sqlite3_bind_parameter_index()] API if desired. ^The index |
| 4200 | 4253 | ** for "?NNN" parameters is the value of NNN. |
| 4201 | 4254 | ** ^The NNN value must be between 1 and the [sqlite3_limit()] |
| 4202 | -** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). | |
| 4255 | +** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766). | |
| 4203 | 4256 | ** |
| 4204 | 4257 | ** ^The third argument is the value to bind to the parameter. |
| 4205 | 4258 | ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
| 4206 | 4259 | ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter |
| 4207 | 4260 | ** is ignored and the end result is the same as sqlite3_bind_null(). |
| @@ -5815,55 +5868,10 @@ | ||
| 5815 | 5868 | sqlite3*, |
| 5816 | 5869 | void*, |
| 5817 | 5870 | void(*)(void*,sqlite3*,int eTextRep,const void*) |
| 5818 | 5871 | ); |
| 5819 | 5872 | |
| 5820 | -#ifdef SQLITE_HAS_CODEC | |
| 5821 | -/* | |
| 5822 | -** Specify the key for an encrypted database. This routine should be | |
| 5823 | -** called right after sqlite3_open(). | |
| 5824 | -** | |
| 5825 | -** The code to implement this API is not available in the public release | |
| 5826 | -** of SQLite. | |
| 5827 | -*/ | |
| 5828 | -SQLITE_API int sqlite3_key( | |
| 5829 | - sqlite3 *db, /* Database to be rekeyed */ | |
| 5830 | - const void *pKey, int nKey /* The key */ | |
| 5831 | -); | |
| 5832 | -SQLITE_API int sqlite3_key_v2( | |
| 5833 | - sqlite3 *db, /* Database to be rekeyed */ | |
| 5834 | - const char *zDbName, /* Name of the database */ | |
| 5835 | - const void *pKey, int nKey /* The key */ | |
| 5836 | -); | |
| 5837 | - | |
| 5838 | -/* | |
| 5839 | -** Change the key on an open database. If the current database is not | |
| 5840 | -** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the | |
| 5841 | -** database is decrypted. | |
| 5842 | -** | |
| 5843 | -** The code to implement this API is not available in the public release | |
| 5844 | -** of SQLite. | |
| 5845 | -*/ | |
| 5846 | -SQLITE_API int sqlite3_rekey( | |
| 5847 | - sqlite3 *db, /* Database to be rekeyed */ | |
| 5848 | - const void *pKey, int nKey /* The new key */ | |
| 5849 | -); | |
| 5850 | -SQLITE_API int sqlite3_rekey_v2( | |
| 5851 | - sqlite3 *db, /* Database to be rekeyed */ | |
| 5852 | - const char *zDbName, /* Name of the database */ | |
| 5853 | - const void *pKey, int nKey /* The new key */ | |
| 5854 | -); | |
| 5855 | - | |
| 5856 | -/* | |
| 5857 | -** Specify the activation key for a SEE database. Unless | |
| 5858 | -** activated, none of the SEE routines will work. | |
| 5859 | -*/ | |
| 5860 | -SQLITE_API void sqlite3_activate_see( | |
| 5861 | - const char *zPassPhrase /* Activation phrase */ | |
| 5862 | -); | |
| 5863 | -#endif | |
| 5864 | - | |
| 5865 | 5873 | #ifdef SQLITE_ENABLE_CEROD |
| 5866 | 5874 | /* |
| 5867 | 5875 | ** Specify the activation key for a CEROD database. Unless |
| 5868 | 5876 | ** activated, none of the CEROD routines will work. |
| 5869 | 5877 | */ |
| 5870 | 5878 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -121,13 +121,13 @@ | |
| 121 | ** |
| 122 | ** See also: [sqlite3_libversion()], |
| 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | */ |
| 126 | #define SQLITE_VERSION "3.31.1" |
| 127 | #define SQLITE_VERSION_NUMBER 3031001 |
| 128 | #define SQLITE_SOURCE_ID "2020-01-28 15:02:23 04885763c4cd00cbca26d048f2b19316bfc93e8edebeceaa171ebfc6c563d53e" |
| 129 | |
| 130 | /* |
| 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | ** |
| @@ -3615,10 +3615,63 @@ | |
| 3615 | */ |
| 3616 | SQLITE_API const char *sqlite3_filename_database(const char*); |
| 3617 | SQLITE_API const char *sqlite3_filename_journal(const char*); |
| 3618 | SQLITE_API const char *sqlite3_filename_wal(const char*); |
| 3619 | |
| 3620 | |
| 3621 | /* |
| 3622 | ** CAPI3REF: Error Codes And Messages |
| 3623 | ** METHOD: sqlite3 |
| 3624 | ** |
| @@ -4197,11 +4250,11 @@ | |
| 4197 | ** occurrences have the same index as the first occurrence. |
| 4198 | ** ^The index for named parameters can be looked up using the |
| 4199 | ** [sqlite3_bind_parameter_index()] API if desired. ^The index |
| 4200 | ** for "?NNN" parameters is the value of NNN. |
| 4201 | ** ^The NNN value must be between 1 and the [sqlite3_limit()] |
| 4202 | ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). |
| 4203 | ** |
| 4204 | ** ^The third argument is the value to bind to the parameter. |
| 4205 | ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
| 4206 | ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter |
| 4207 | ** is ignored and the end result is the same as sqlite3_bind_null(). |
| @@ -5815,55 +5868,10 @@ | |
| 5815 | sqlite3*, |
| 5816 | void*, |
| 5817 | void(*)(void*,sqlite3*,int eTextRep,const void*) |
| 5818 | ); |
| 5819 | |
| 5820 | #ifdef SQLITE_HAS_CODEC |
| 5821 | /* |
| 5822 | ** Specify the key for an encrypted database. This routine should be |
| 5823 | ** called right after sqlite3_open(). |
| 5824 | ** |
| 5825 | ** The code to implement this API is not available in the public release |
| 5826 | ** of SQLite. |
| 5827 | */ |
| 5828 | SQLITE_API int sqlite3_key( |
| 5829 | sqlite3 *db, /* Database to be rekeyed */ |
| 5830 | const void *pKey, int nKey /* The key */ |
| 5831 | ); |
| 5832 | SQLITE_API int sqlite3_key_v2( |
| 5833 | sqlite3 *db, /* Database to be rekeyed */ |
| 5834 | const char *zDbName, /* Name of the database */ |
| 5835 | const void *pKey, int nKey /* The key */ |
| 5836 | ); |
| 5837 | |
| 5838 | /* |
| 5839 | ** Change the key on an open database. If the current database is not |
| 5840 | ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the |
| 5841 | ** database is decrypted. |
| 5842 | ** |
| 5843 | ** The code to implement this API is not available in the public release |
| 5844 | ** of SQLite. |
| 5845 | */ |
| 5846 | SQLITE_API int sqlite3_rekey( |
| 5847 | sqlite3 *db, /* Database to be rekeyed */ |
| 5848 | const void *pKey, int nKey /* The new key */ |
| 5849 | ); |
| 5850 | SQLITE_API int sqlite3_rekey_v2( |
| 5851 | sqlite3 *db, /* Database to be rekeyed */ |
| 5852 | const char *zDbName, /* Name of the database */ |
| 5853 | const void *pKey, int nKey /* The new key */ |
| 5854 | ); |
| 5855 | |
| 5856 | /* |
| 5857 | ** Specify the activation key for a SEE database. Unless |
| 5858 | ** activated, none of the SEE routines will work. |
| 5859 | */ |
| 5860 | SQLITE_API void sqlite3_activate_see( |
| 5861 | const char *zPassPhrase /* Activation phrase */ |
| 5862 | ); |
| 5863 | #endif |
| 5864 | |
| 5865 | #ifdef SQLITE_ENABLE_CEROD |
| 5866 | /* |
| 5867 | ** Specify the activation key for a CEROD database. Unless |
| 5868 | ** activated, none of the CEROD routines will work. |
| 5869 | */ |
| 5870 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -121,13 +121,13 @@ | |
| 121 | ** |
| 122 | ** See also: [sqlite3_libversion()], |
| 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | */ |
| 126 | #define SQLITE_VERSION "3.32.0" |
| 127 | #define SQLITE_VERSION_NUMBER 3032000 |
| 128 | #define SQLITE_SOURCE_ID "2020-02-27 16:21:39 951b39ca74c9bd933139e099d5555283278db475f410f202c162e5d1e6aef933" |
| 129 | |
| 130 | /* |
| 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | ** |
| @@ -3615,10 +3615,63 @@ | |
| 3615 | */ |
| 3616 | SQLITE_API const char *sqlite3_filename_database(const char*); |
| 3617 | SQLITE_API const char *sqlite3_filename_journal(const char*); |
| 3618 | SQLITE_API const char *sqlite3_filename_wal(const char*); |
| 3619 | |
| 3620 | /* |
| 3621 | ** CAPI3REF: Create and Destroy VFS Filenames |
| 3622 | ** |
| 3623 | ** These interfces are provided for use by [VFS shim] implementations and |
| 3624 | ** are not useful outside of that context. |
| 3625 | ** |
| 3626 | ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of |
| 3627 | ** database filename D with corresponding journal file J and WAL file W and |
| 3628 | ** with N URI parameters key/values pairs in the array P. The result from |
| 3629 | ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that |
| 3630 | ** is safe to pass to routines like: |
| 3631 | ** <ul> |
| 3632 | ** <li> [sqlite3_uri_parameter()], |
| 3633 | ** <li> [sqlite3_uri_boolean()], |
| 3634 | ** <li> [sqlite3_uri_int64()], |
| 3635 | ** <li> [sqlite3_uri_key()], |
| 3636 | ** <li> [sqlite3_filename_database()], |
| 3637 | ** <li> [sqlite3_filename_journal()], or |
| 3638 | ** <li> [sqlite3_filename_wal()]. |
| 3639 | ** </ul> |
| 3640 | ** If a memory allocation error occurs, sqlite3_create_filename() might |
| 3641 | ** return a NULL pointer. The memory obtained from sqlite3_create_filename(X) |
| 3642 | ** must be released by a corresponding call to sqlite3_free_filename(Y). |
| 3643 | ** |
| 3644 | ** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array |
| 3645 | ** of 2*N pointers to strings. Each pair of pointers in this array corresponds |
| 3646 | ** to a key and value for a query parameter. The P parameter may be a NULL |
| 3647 | ** pointer if N is zero. None of the 2*N pointers in the P array may be |
| 3648 | ** NULL pointers and key pointers should not be empty strings. |
| 3649 | ** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may |
| 3650 | ** be NULL pointers, though they can be empty strings. |
| 3651 | ** |
| 3652 | ** The sqlite3_free_filename(Y) routine releases a memory allocation |
| 3653 | ** previously obtained from sqlite3_create_filename(). Invoking |
| 3654 | ** sqlite3_free_filename(Y) is a NULL pointer is a harmless no-op. |
| 3655 | ** |
| 3656 | ** If the Y parameter to sqlite3_free_filename(Y) is anything other |
| 3657 | ** than a NULL pointer or a pointer previously acquired from |
| 3658 | ** sqlite3_create_filename(), then bad things such as heap |
| 3659 | ** corruption or segfaults may occur. The value Y should be |
| 3660 | ** used again after sqlite3_free_filename(Y) has been called. This means |
| 3661 | ** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y, |
| 3662 | ** then the corresponding [sqlite3_module.xClose() method should also be |
| 3663 | ** invoked prior to calling sqlite3_free_filename(Y). |
| 3664 | */ |
| 3665 | SQLITE_API char *sqlite3_create_filename( |
| 3666 | const char *zDatabase, |
| 3667 | const char *zJournal, |
| 3668 | const char *zWal, |
| 3669 | int nParam, |
| 3670 | const char **azParam |
| 3671 | ); |
| 3672 | SQLITE_API void sqlite3_free_filename(char*); |
| 3673 | |
| 3674 | /* |
| 3675 | ** CAPI3REF: Error Codes And Messages |
| 3676 | ** METHOD: sqlite3 |
| 3677 | ** |
| @@ -4197,11 +4250,11 @@ | |
| 4250 | ** occurrences have the same index as the first occurrence. |
| 4251 | ** ^The index for named parameters can be looked up using the |
| 4252 | ** [sqlite3_bind_parameter_index()] API if desired. ^The index |
| 4253 | ** for "?NNN" parameters is the value of NNN. |
| 4254 | ** ^The NNN value must be between 1 and the [sqlite3_limit()] |
| 4255 | ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766). |
| 4256 | ** |
| 4257 | ** ^The third argument is the value to bind to the parameter. |
| 4258 | ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
| 4259 | ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter |
| 4260 | ** is ignored and the end result is the same as sqlite3_bind_null(). |
| @@ -5815,55 +5868,10 @@ | |
| 5868 | sqlite3*, |
| 5869 | void*, |
| 5870 | void(*)(void*,sqlite3*,int eTextRep,const void*) |
| 5871 | ); |
| 5872 | |
| 5873 | #ifdef SQLITE_ENABLE_CEROD |
| 5874 | /* |
| 5875 | ** Specify the activation key for a CEROD database. Unless |
| 5876 | ** activated, none of the CEROD routines will work. |
| 5877 | */ |
| 5878 |