| | @@ -656,11 +656,11 @@ |
| 656 | 656 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 657 | 657 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 658 | 658 | */ |
| 659 | 659 | #define SQLITE_VERSION "3.7.9" |
| 660 | 660 | #define SQLITE_VERSION_NUMBER 3007009 |
| 661 | | -#define SQLITE_SOURCE_ID "2011-10-11 20:41:54 b94a80a832777f0e639f6a81fcfe169bf970a8c0" |
| 661 | +#define SQLITE_SOURCE_ID "2011-10-15 00:16:30 39408702a989f907261c298bf0947f3e68bd10fe" |
| 662 | 662 | |
| 663 | 663 | /* |
| 664 | 664 | ** CAPI3REF: Run-Time Library Version Numbers |
| 665 | 665 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 666 | 666 | ** |
| | @@ -3351,11 +3351,12 @@ |
| 3351 | 3351 | ** zSql string ends at either the first '\000' or '\u0000' character or |
| 3352 | 3352 | ** the nByte-th byte, whichever comes first. If the caller knows |
| 3353 | 3353 | ** that the supplied string is nul-terminated, then there is a small |
| 3354 | 3354 | ** performance advantage to be gained by passing an nByte parameter that |
| 3355 | 3355 | ** is equal to the number of bytes in the input string <i>including</i> |
| 3356 | | -** the nul-terminator bytes. |
| 3356 | +** the nul-terminator bytes as this saves SQLite from having to |
| 3357 | +** make a copy of the input string. |
| 3357 | 3358 | ** |
| 3358 | 3359 | ** ^If pzTail is not NULL then *pzTail is made to point to the first byte |
| 3359 | 3360 | ** past the end of the first SQL statement in zSql. These routines only |
| 3360 | 3361 | ** compile the first statement in zSql, so *pzTail is left pointing to |
| 3361 | 3362 | ** what remains uncompiled. |
| | @@ -3572,10 +3573,17 @@ |
| 3572 | 3573 | ** ^(In those routines that have a fourth argument, its value is the |
| 3573 | 3574 | ** number of bytes in the parameter. To be clear: the value is the |
| 3574 | 3575 | ** number of <u>bytes</u> in the value, not the number of characters.)^ |
| 3575 | 3576 | ** ^If the fourth parameter is negative, the length of the string is |
| 3576 | 3577 | ** the number of bytes up to the first zero terminator. |
| 3578 | +** If a non-negative fourth parameter is provided to sqlite3_bind_text() |
| 3579 | +** or sqlite3_bind_text16() then that parameter must be the byte offset |
| 3580 | +** where the NUL terminator would occur assuming the string were NUL |
| 3581 | +** terminated. If any NUL characters occur at byte offsets less than |
| 3582 | +** the value of the fourth parameter then the resulting string value will |
| 3583 | +** contain embedded NULs. The result of expressions involving strings |
| 3584 | +** with embedded NULs is undefined. |
| 3577 | 3585 | ** |
| 3578 | 3586 | ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and |
| 3579 | 3587 | ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or |
| 3580 | 3588 | ** string after SQLite has finished with it. ^The destructor is called |
| 3581 | 3589 | ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(), |
| | @@ -4590,11 +4598,16 @@ |
| 4590 | 4598 | ** is negative, then SQLite takes result text from the 2nd parameter |
| 4591 | 4599 | ** through the first zero character. |
| 4592 | 4600 | ** ^If the 3rd parameter to the sqlite3_result_text* interfaces |
| 4593 | 4601 | ** is non-negative, then as many bytes (not characters) of the text |
| 4594 | 4602 | ** pointed to by the 2nd parameter are taken as the application-defined |
| 4595 | | -** function result. |
| 4603 | +** function result. If the 3rd parameter is non-negative, then it |
| 4604 | +** must be the byte offset into the string where the NUL terminator would |
| 4605 | +** appear if the string where NUL terminated. If any NUL characters occur |
| 4606 | +** in the string at a byte offset that is less than the value of the 3rd |
| 4607 | +** parameter, then the resulting string will contain embedded NULs and the |
| 4608 | +** result of expressions operating on strings with embedded NULs is undefined. |
| 4596 | 4609 | ** ^If the 4th parameter to the sqlite3_result_text* interfaces |
| 4597 | 4610 | ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that |
| 4598 | 4611 | ** function as the destructor on the text or BLOB result when it has |
| 4599 | 4612 | ** finished using that result. |
| 4600 | 4613 | ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to |
| | @@ -9315,18 +9328,21 @@ |
| 9315 | 9328 | /* |
| 9316 | 9329 | ** If this is a no-op implementation, implement everything as macros. |
| 9317 | 9330 | */ |
| 9318 | 9331 | #define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8) |
| 9319 | 9332 | #define sqlite3_mutex_free(X) |
| 9320 | | -#define sqlite3_mutex_enter(X) |
| 9333 | +#define sqlite3_mutex_enter(X) |
| 9321 | 9334 | #define sqlite3_mutex_try(X) SQLITE_OK |
| 9322 | | -#define sqlite3_mutex_leave(X) |
| 9335 | +#define sqlite3_mutex_leave(X) |
| 9323 | 9336 | #define sqlite3_mutex_held(X) ((void)(X),1) |
| 9324 | 9337 | #define sqlite3_mutex_notheld(X) ((void)(X),1) |
| 9325 | 9338 | #define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8) |
| 9326 | 9339 | #define sqlite3MutexInit() SQLITE_OK |
| 9327 | 9340 | #define sqlite3MutexEnd() |
| 9341 | +#define MUTEX_LOGIC(X) |
| 9342 | +#else |
| 9343 | +#define MUTEX_LOGIC(X) X |
| 9328 | 9344 | #endif /* defined(SQLITE_MUTEX_OMIT) */ |
| 9329 | 9345 | |
| 9330 | 9346 | /************** End of mutex.h ***********************************************/ |
| 9331 | 9347 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 9332 | 9348 | |
| | @@ -11754,19 +11770,21 @@ |
| 11754 | 11770 | # define sqlite3VtabInSync(db) 0 |
| 11755 | 11771 | # define sqlite3VtabLock(X) |
| 11756 | 11772 | # define sqlite3VtabUnlock(X) |
| 11757 | 11773 | # define sqlite3VtabUnlockList(X) |
| 11758 | 11774 | # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK |
| 11775 | +# define sqlite3GetVTable(X,Y) ((VTable*)0) |
| 11759 | 11776 | #else |
| 11760 | 11777 | SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*); |
| 11761 | 11778 | SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **); |
| 11762 | 11779 | SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db); |
| 11763 | 11780 | SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db); |
| 11764 | 11781 | SQLITE_PRIVATE void sqlite3VtabLock(VTable *); |
| 11765 | 11782 | SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *); |
| 11766 | 11783 | SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*); |
| 11767 | 11784 | SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int); |
| 11785 | +SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*); |
| 11768 | 11786 | # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) |
| 11769 | 11787 | #endif |
| 11770 | 11788 | SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*); |
| 11771 | 11789 | SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*); |
| 11772 | 11790 | SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*); |
| | @@ -11782,11 +11800,10 @@ |
| 11782 | 11800 | SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *); |
| 11783 | 11801 | SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*); |
| 11784 | 11802 | SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*); |
| 11785 | 11803 | SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *); |
| 11786 | 11804 | SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*); |
| 11787 | | -SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*); |
| 11788 | 11805 | SQLITE_PRIVATE const char *sqlite3JournalModename(int); |
| 11789 | 11806 | SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3*, int, int, int*, int*); |
| 11790 | 11807 | SQLITE_PRIVATE int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int); |
| 11791 | 11808 | |
| 11792 | 11809 | /* Declarations for functions in fkey.c. All of these are replaced by |
| | @@ -13558,16 +13575,22 @@ |
| 13558 | 13575 | } |
| 13559 | 13576 | return 0; |
| 13560 | 13577 | } |
| 13561 | 13578 | |
| 13562 | 13579 | /* |
| 13563 | | -** Set the time to the current time reported by the VFS |
| 13580 | +** Set the time to the current time reported by the VFS. |
| 13581 | +** |
| 13582 | +** Return the number of errors. |
| 13564 | 13583 | */ |
| 13565 | | -static void setDateTimeToCurrent(sqlite3_context *context, DateTime *p){ |
| 13584 | +static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){ |
| 13566 | 13585 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 13567 | | - sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD); |
| 13568 | | - p->validJD = 1; |
| 13586 | + if( sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD)==SQLITE_OK ){ |
| 13587 | + p->validJD = 1; |
| 13588 | + return 0; |
| 13589 | + }else{ |
| 13590 | + return 1; |
| 13591 | + } |
| 13569 | 13592 | } |
| 13570 | 13593 | |
| 13571 | 13594 | /* |
| 13572 | 13595 | ** Attempt to parse the given string into a Julian Day Number. Return |
| 13573 | 13596 | ** the number of errors. |
| | @@ -13593,12 +13616,11 @@ |
| 13593 | 13616 | if( parseYyyyMmDd(zDate,p)==0 ){ |
| 13594 | 13617 | return 0; |
| 13595 | 13618 | }else if( parseHhMmSs(zDate, p)==0 ){ |
| 13596 | 13619 | return 0; |
| 13597 | 13620 | }else if( sqlite3StrICmp(zDate,"now")==0){ |
| 13598 | | - setDateTimeToCurrent(context, p); |
| 13599 | | - return 0; |
| 13621 | + return setDateTimeToCurrent(context, p); |
| 13600 | 13622 | }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){ |
| 13601 | 13623 | p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5); |
| 13602 | 13624 | p->validJD = 1; |
| 13603 | 13625 | return 0; |
| 13604 | 13626 | } |
| | @@ -14021,12 +14043,13 @@ |
| 14021 | 14043 | int i; |
| 14022 | 14044 | const unsigned char *z; |
| 14023 | 14045 | int eType; |
| 14024 | 14046 | memset(p, 0, sizeof(*p)); |
| 14025 | 14047 | if( argc==0 ){ |
| 14026 | | - setDateTimeToCurrent(context, p); |
| 14027 | | - }else if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT |
| 14048 | + return setDateTimeToCurrent(context, p); |
| 14049 | + } |
| 14050 | + if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT |
| 14028 | 14051 | || eType==SQLITE_INTEGER ){ |
| 14029 | 14052 | p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5); |
| 14030 | 14053 | p->validJD = 1; |
| 14031 | 14054 | }else{ |
| 14032 | 14055 | z = sqlite3_value_text(argv[0]); |
| | @@ -14334,35 +14357,32 @@ |
| 14334 | 14357 | ){ |
| 14335 | 14358 | time_t t; |
| 14336 | 14359 | char *zFormat = (char *)sqlite3_user_data(context); |
| 14337 | 14360 | sqlite3 *db; |
| 14338 | 14361 | sqlite3_int64 iT; |
| 14362 | + struct tm *pTm; |
| 14363 | + struct tm sNow; |
| 14339 | 14364 | char zBuf[20]; |
| 14340 | 14365 | |
| 14341 | 14366 | UNUSED_PARAMETER(argc); |
| 14342 | 14367 | UNUSED_PARAMETER(argv); |
| 14343 | 14368 | |
| 14344 | 14369 | db = sqlite3_context_db_handle(context); |
| 14345 | | - sqlite3OsCurrentTimeInt64(db->pVfs, &iT); |
| 14370 | + if( sqlite3OsCurrentTimeInt64(db->pVfs, &iT) ) return; |
| 14346 | 14371 | t = iT/1000 - 10000*(sqlite3_int64)21086676; |
| 14347 | 14372 | #ifdef HAVE_GMTIME_R |
| 14348 | | - { |
| 14349 | | - struct tm sNow; |
| 14350 | | - gmtime_r(&t, &sNow); |
| 14373 | + pTm = gmtime_r(&t, &sNow); |
| 14374 | +#else |
| 14375 | + sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 14376 | + pTm = gmtime(&t); |
| 14377 | + if( pTm ) memcpy(&sNow, pTm, sizeof(sNow)); |
| 14378 | + sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 14379 | +#endif |
| 14380 | + if( pTm ){ |
| 14351 | 14381 | strftime(zBuf, 20, zFormat, &sNow); |
| 14352 | | - } |
| 14353 | | -#else |
| 14354 | | - { |
| 14355 | | - struct tm *pTm; |
| 14356 | | - sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 14357 | | - pTm = gmtime(&t); |
| 14358 | | - strftime(zBuf, 20, zFormat, pTm); |
| 14359 | | - sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 14360 | | - } |
| 14361 | | -#endif |
| 14362 | | - |
| 14363 | | - sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); |
| 14382 | + sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); |
| 14383 | + } |
| 14364 | 14384 | } |
| 14365 | 14385 | #endif |
| 14366 | 14386 | |
| 14367 | 14387 | /* |
| 14368 | 14388 | ** This function registered all of the above C functions as SQL |
| | @@ -14693,16 +14713,16 @@ |
| 14693 | 14713 | ** Register a VFS with the system. It is harmless to register the same |
| 14694 | 14714 | ** VFS multiple times. The new VFS becomes the default if makeDflt is |
| 14695 | 14715 | ** true. |
| 14696 | 14716 | */ |
| 14697 | 14717 | SQLITE_API int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){ |
| 14698 | | - sqlite3_mutex *mutex = 0; |
| 14718 | + MUTEX_LOGIC(sqlite3_mutex *mutex;) |
| 14699 | 14719 | #ifndef SQLITE_OMIT_AUTOINIT |
| 14700 | 14720 | int rc = sqlite3_initialize(); |
| 14701 | 14721 | if( rc ) return rc; |
| 14702 | 14722 | #endif |
| 14703 | | - mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 14723 | + MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 14704 | 14724 | sqlite3_mutex_enter(mutex); |
| 14705 | 14725 | vfsUnlink(pVfs); |
| 14706 | 14726 | if( makeDflt || vfsList==0 ){ |
| 14707 | 14727 | pVfs->pNext = vfsList; |
| 14708 | 14728 | vfsList = pVfs; |
| | @@ -18946,52 +18966,14 @@ |
| 18946 | 18966 | ** an historical reference. Most of the "enhancements" have been backed |
| 18947 | 18967 | ** out so that the functionality is now the same as standard printf(). |
| 18948 | 18968 | ** |
| 18949 | 18969 | ************************************************************************** |
| 18950 | 18970 | ** |
| 18951 | | -** The following modules is an enhanced replacement for the "printf" subroutines |
| 18952 | | -** found in the standard C library. The following enhancements are |
| 18953 | | -** supported: |
| 18954 | | -** |
| 18955 | | -** + Additional functions. The standard set of "printf" functions |
| 18956 | | -** includes printf, fprintf, sprintf, vprintf, vfprintf, and |
| 18957 | | -** vsprintf. This module adds the following: |
| 18958 | | -** |
| 18959 | | -** * snprintf -- Works like sprintf, but has an extra argument |
| 18960 | | -** which is the size of the buffer written to. |
| 18961 | | -** |
| 18962 | | -** * mprintf -- Similar to sprintf. Writes output to memory |
| 18963 | | -** obtained from malloc. |
| 18964 | | -** |
| 18965 | | -** * xprintf -- Calls a function to dispose of output. |
| 18966 | | -** |
| 18967 | | -** * nprintf -- No output, but returns the number of characters |
| 18968 | | -** that would have been output by printf. |
| 18969 | | -** |
| 18970 | | -** * A v- version (ex: vsnprintf) of every function is also |
| 18971 | | -** supplied. |
| 18972 | | -** |
| 18973 | | -** + A few extensions to the formatting notation are supported: |
| 18974 | | -** |
| 18975 | | -** * The "=" flag (similar to "-") causes the output to be |
| 18976 | | -** be centered in the appropriately sized field. |
| 18977 | | -** |
| 18978 | | -** * The %b field outputs an integer in binary notation. |
| 18979 | | -** |
| 18980 | | -** * The %c field now accepts a precision. The character output |
| 18981 | | -** is repeated by the number of times the precision specifies. |
| 18982 | | -** |
| 18983 | | -** * The %' field works like %c, but takes as its character the |
| 18984 | | -** next character of the format string, instead of the next |
| 18985 | | -** argument. For example, printf("%.78'-") prints 78 minus |
| 18986 | | -** signs, the same as printf("%.78c",'-'). |
| 18987 | | -** |
| 18988 | | -** + When compiled using GCC on a SPARC, this version of printf is |
| 18989 | | -** faster than the library printf for SUN OS 4.1. |
| 18990 | | -** |
| 18991 | | -** + All functions are fully reentrant. |
| 18992 | | -** |
| 18971 | +** This file contains code for a set of "printf"-like routines. These |
| 18972 | +** routines format strings much like the printf() from the standard C |
| 18973 | +** library, though the implementation here has enhancements to support |
| 18974 | +** SQLlite. |
| 18993 | 18975 | */ |
| 18994 | 18976 | |
| 18995 | 18977 | /* |
| 18996 | 18978 | ** Conversion types fall into various categories as defined by the |
| 18997 | 18979 | ** following enumeration. |
| | @@ -19125,43 +19107,19 @@ |
| 19125 | 19107 | } |
| 19126 | 19108 | } |
| 19127 | 19109 | |
| 19128 | 19110 | /* |
| 19129 | 19111 | ** On machines with a small stack size, you can redefine the |
| 19130 | | -** SQLITE_PRINT_BUF_SIZE to be less than 350. |
| 19112 | +** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired. |
| 19131 | 19113 | */ |
| 19132 | 19114 | #ifndef SQLITE_PRINT_BUF_SIZE |
| 19133 | 19115 | # define SQLITE_PRINT_BUF_SIZE 70 |
| 19134 | 19116 | #endif |
| 19135 | 19117 | #define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */ |
| 19136 | 19118 | |
| 19137 | 19119 | /* |
| 19138 | | -** The root program. All variations call this core. |
| 19139 | | -** |
| 19140 | | -** INPUTS: |
| 19141 | | -** func This is a pointer to a function taking three arguments |
| 19142 | | -** 1. A pointer to anything. Same as the "arg" parameter. |
| 19143 | | -** 2. A pointer to the list of characters to be output |
| 19144 | | -** (Note, this list is NOT null terminated.) |
| 19145 | | -** 3. An integer number of characters to be output. |
| 19146 | | -** (Note: This number might be zero.) |
| 19147 | | -** |
| 19148 | | -** arg This is the pointer to anything which will be passed as the |
| 19149 | | -** first argument to "func". Use it for whatever you like. |
| 19150 | | -** |
| 19151 | | -** fmt This is the format string, as in the usual print. |
| 19152 | | -** |
| 19153 | | -** ap This is a pointer to a list of arguments. Same as in |
| 19154 | | -** vfprint. |
| 19155 | | -** |
| 19156 | | -** OUTPUTS: |
| 19157 | | -** The return value is the total number of characters sent to |
| 19158 | | -** the function "func". Returns -1 on a error. |
| 19159 | | -** |
| 19160 | | -** Note that the order in which automatic variables are declared below |
| 19161 | | -** seems to make a big difference in determining how fast this beast |
| 19162 | | -** will run. |
| 19120 | +** Render a string given by "fmt" into the StrAccum object. |
| 19163 | 19121 | */ |
| 19164 | 19122 | SQLITE_PRIVATE void sqlite3VXPrintf( |
| 19165 | 19123 | StrAccum *pAccum, /* Accumulate results here */ |
| 19166 | 19124 | int useExtended, /* Allow extended %-conversions */ |
| 19167 | 19125 | const char *fmt, /* Format string */ |
| | @@ -19180,28 +19138,27 @@ |
| 19180 | 19138 | etByte flag_altform2; /* True if "!" flag is present */ |
| 19181 | 19139 | etByte flag_zeropad; /* True if field width constant starts with zero */ |
| 19182 | 19140 | etByte flag_long; /* True if "l" flag is present */ |
| 19183 | 19141 | etByte flag_longlong; /* True if the "ll" flag is present */ |
| 19184 | 19142 | etByte done; /* Loop termination flag */ |
| 19143 | + etByte xtype = 0; /* Conversion paradigm */ |
| 19144 | + char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ |
| 19185 | 19145 | sqlite_uint64 longvalue; /* Value for integer types */ |
| 19186 | 19146 | LONGDOUBLE_TYPE realvalue; /* Value for real types */ |
| 19187 | 19147 | const et_info *infop; /* Pointer to the appropriate info structure */ |
| 19188 | | - char buf[etBUFSIZE]; /* Conversion buffer */ |
| 19189 | 19148 | char *zOut; /* Rendering buffer */ |
| 19190 | 19149 | int nOut; /* Size of the rendering buffer */ |
| 19191 | | - char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ |
| 19192 | | - etByte xtype = 0; /* Conversion paradigm */ |
| 19193 | | - char *zExtra; /* Extra memory used for etTCLESCAPE conversions */ |
| 19150 | + char *zExtra; /* Malloced memory used by some conversion */ |
| 19194 | 19151 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 19195 | 19152 | int exp, e2; /* exponent of real numbers */ |
| 19153 | + int nsd; /* Number of significant digits returned */ |
| 19196 | 19154 | double rounder; /* Used for rounding floating point values */ |
| 19197 | 19155 | etByte flag_dp; /* True if decimal point should be shown */ |
| 19198 | 19156 | etByte flag_rtz; /* True if trailing zeros should be removed */ |
| 19199 | | - int nsd; /* Number of significant digits returned */ |
| 19200 | 19157 | #endif |
| 19158 | + char buf[etBUFSIZE]; /* Conversion buffer */ |
| 19201 | 19159 | |
| 19202 | | - length = 0; |
| 19203 | 19160 | bufpt = 0; |
| 19204 | 19161 | for(; (c=(*fmt))!=0; ++fmt){ |
| 19205 | 19162 | if( c!='%' ){ |
| 19206 | 19163 | int amt; |
| 19207 | 19164 | bufpt = (char *)fmt; |
| | @@ -19692,10 +19649,11 @@ |
| 19692 | 19649 | if( p->tooBig | p->mallocFailed ){ |
| 19693 | 19650 | testcase(p->tooBig); |
| 19694 | 19651 | testcase(p->mallocFailed); |
| 19695 | 19652 | return; |
| 19696 | 19653 | } |
| 19654 | + assert( p->zText!=0 || p->nChar==0 ); |
| 19697 | 19655 | if( N<0 ){ |
| 19698 | 19656 | N = sqlite3Strlen30(z); |
| 19699 | 19657 | } |
| 19700 | 19658 | if( N==0 || NEVER(z==0) ){ |
| 19701 | 19659 | return; |
| | @@ -19723,19 +19681,20 @@ |
| 19723 | 19681 | zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc); |
| 19724 | 19682 | }else{ |
| 19725 | 19683 | zNew = sqlite3_realloc(zOld, p->nAlloc); |
| 19726 | 19684 | } |
| 19727 | 19685 | if( zNew ){ |
| 19728 | | - if( zOld==0 ) memcpy(zNew, p->zText, p->nChar); |
| 19686 | + if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 19729 | 19687 | p->zText = zNew; |
| 19730 | 19688 | }else{ |
| 19731 | 19689 | p->mallocFailed = 1; |
| 19732 | 19690 | sqlite3StrAccumReset(p); |
| 19733 | 19691 | return; |
| 19734 | 19692 | } |
| 19735 | 19693 | } |
| 19736 | 19694 | } |
| 19695 | + assert( p->zText ); |
| 19737 | 19696 | memcpy(&p->zText[p->nChar], z, N); |
| 19738 | 19697 | p->nChar += N; |
| 19739 | 19698 | } |
| 19740 | 19699 | |
| 19741 | 19700 | /* |
| | @@ -25172,11 +25131,11 @@ |
| 25172 | 25131 | return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); |
| 25173 | 25132 | } |
| 25174 | 25133 | #endif |
| 25175 | 25134 | |
| 25176 | 25135 | |
| 25177 | | -#ifdef SQLITE_DEBUG |
| 25136 | +#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| 25178 | 25137 | /* |
| 25179 | 25138 | ** Helper function for printing out trace information from debugging |
| 25180 | 25139 | ** binaries. This returns the string represetation of the supplied |
| 25181 | 25140 | ** integer lock-type. |
| 25182 | 25141 | */ |
| | @@ -26007,18 +25966,18 @@ |
| 26007 | 25966 | ** locking a random byte from a range, concurrent SHARED locks may exist |
| 26008 | 25967 | ** even if the locking primitive used is always a write-lock. |
| 26009 | 25968 | */ |
| 26010 | 25969 | int rc = SQLITE_OK; |
| 26011 | 25970 | unixFile *pFile = (unixFile*)id; |
| 26012 | | - unixInodeInfo *pInode = pFile->pInode; |
| 25971 | + unixInodeInfo *pInode; |
| 26013 | 25972 | struct flock lock; |
| 26014 | 25973 | int tErrno = 0; |
| 26015 | 25974 | |
| 26016 | 25975 | assert( pFile ); |
| 26017 | 25976 | OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h, |
| 26018 | 25977 | azFileLock(eFileLock), azFileLock(pFile->eFileLock), |
| 26019 | | - azFileLock(pInode->eFileLock), pInode->nShared , getpid())); |
| 25978 | + azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared , getpid())); |
| 26020 | 25979 | |
| 26021 | 25980 | /* If there is already a lock of this type or more restrictive on the |
| 26022 | 25981 | ** unixFile, do nothing. Don't use the end_lock: exit path, as |
| 26023 | 25982 | ** unixEnterMutex() hasn't been called yet. |
| 26024 | 25983 | */ |
| | @@ -26218,11 +26177,10 @@ |
| 26218 | 26177 | static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ |
| 26219 | 26178 | unixFile *pFile = (unixFile*)id; |
| 26220 | 26179 | unixInodeInfo *pInode; |
| 26221 | 26180 | struct flock lock; |
| 26222 | 26181 | int rc = SQLITE_OK; |
| 26223 | | - int h; |
| 26224 | 26182 | |
| 26225 | 26183 | assert( pFile ); |
| 26226 | 26184 | OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock, |
| 26227 | 26185 | pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, |
| 26228 | 26186 | getpid())); |
| | @@ -26230,18 +26188,14 @@ |
| 26230 | 26188 | assert( eFileLock<=SHARED_LOCK ); |
| 26231 | 26189 | if( pFile->eFileLock<=eFileLock ){ |
| 26232 | 26190 | return SQLITE_OK; |
| 26233 | 26191 | } |
| 26234 | 26192 | unixEnterMutex(); |
| 26235 | | - h = pFile->h; |
| 26236 | 26193 | pInode = pFile->pInode; |
| 26237 | 26194 | assert( pInode->nShared!=0 ); |
| 26238 | 26195 | if( pFile->eFileLock>SHARED_LOCK ){ |
| 26239 | 26196 | assert( pInode->eFileLock==pFile->eFileLock ); |
| 26240 | | - SimulateIOErrorBenign(1); |
| 26241 | | - SimulateIOError( h=(-1) ) |
| 26242 | | - SimulateIOErrorBenign(0); |
| 26243 | 26197 | |
| 26244 | 26198 | #ifndef NDEBUG |
| 26245 | 26199 | /* When reducing a lock such that other processes can start |
| 26246 | 26200 | ** reading the database file again, make sure that the |
| 26247 | 26201 | ** transaction counter was updated if any part of the database |
| | @@ -26248,15 +26202,10 @@ |
| 26248 | 26202 | ** file changed. If the transaction counter is not updated, |
| 26249 | 26203 | ** other connections to the same file might not realize that |
| 26250 | 26204 | ** the file has changed and hence might not know to flush their |
| 26251 | 26205 | ** cache. The use of a stale cache can lead to database corruption. |
| 26252 | 26206 | */ |
| 26253 | | -#if 0 |
| 26254 | | - assert( pFile->inNormalWrite==0 |
| 26255 | | - || pFile->dbUpdate==0 |
| 26256 | | - || pFile->transCntrChng==1 ); |
| 26257 | | -#endif |
| 26258 | 26207 | pFile->inNormalWrite = 0; |
| 26259 | 26208 | #endif |
| 26260 | 26209 | |
| 26261 | 26210 | /* downgrading to a shared lock on NFS involves clearing the write lock |
| 26262 | 26211 | ** before establishing the readlock - to avoid a race condition we downgrade |
| | @@ -26354,13 +26303,10 @@ |
| 26354 | 26303 | pInode->nShared--; |
| 26355 | 26304 | if( pInode->nShared==0 ){ |
| 26356 | 26305 | lock.l_type = F_UNLCK; |
| 26357 | 26306 | lock.l_whence = SEEK_SET; |
| 26358 | 26307 | lock.l_start = lock.l_len = 0L; |
| 26359 | | - SimulateIOErrorBenign(1); |
| 26360 | | - SimulateIOError( h=(-1) ) |
| 26361 | | - SimulateIOErrorBenign(0); |
| 26362 | 26308 | if( unixFileLock(pFile, &lock)==0 ){ |
| 26363 | 26309 | pInode->eFileLock = NO_LOCK; |
| 26364 | 26310 | }else{ |
| 26365 | 26311 | rc = SQLITE_IOERR_UNLOCK; |
| 26366 | 26312 | pFile->lastErrno = errno; |
| | @@ -29191,10 +29137,13 @@ |
| 29191 | 29137 | assert( zFilename==0 || zFilename[0]=='/' |
| 29192 | 29138 | || pVfs->pAppData==(void*)&autolockIoFinder ); |
| 29193 | 29139 | #else |
| 29194 | 29140 | assert( zFilename==0 || zFilename[0]=='/' ); |
| 29195 | 29141 | #endif |
| 29142 | + |
| 29143 | + /* No locking occurs in temporary files */ |
| 29144 | + assert( zFilename!=0 || noLock ); |
| 29196 | 29145 | |
| 29197 | 29146 | OSTRACE(("OPEN %-3d %s\n", h, zFilename)); |
| 29198 | 29147 | pNew->h = h; |
| 29199 | 29148 | pNew->zPath = zFilename; |
| 29200 | 29149 | if( memcmp(pVfs->zName,"unix-excl",10)==0 ){ |
| | @@ -29293,10 +29242,11 @@ |
| 29293 | 29242 | /* Dotfile locking uses the file path so it needs to be included in |
| 29294 | 29243 | ** the dotlockLockingContext |
| 29295 | 29244 | */ |
| 29296 | 29245 | char *zLockFile; |
| 29297 | 29246 | int nFilename; |
| 29247 | + assert( zFilename!=0 ); |
| 29298 | 29248 | nFilename = (int)strlen(zFilename) + 6; |
| 29299 | 29249 | zLockFile = (char *)sqlite3_malloc(nFilename); |
| 29300 | 29250 | if( zLockFile==0 ){ |
| 29301 | 29251 | rc = SQLITE_NOMEM; |
| 29302 | 29252 | }else{ |
| | @@ -30072,14 +30022,16 @@ |
| 30072 | 30022 | ** the current time and date as a Julian Day number times 86_400_000. In |
| 30073 | 30023 | ** other words, write into *piNow the number of milliseconds since the Julian |
| 30074 | 30024 | ** epoch of noon in Greenwich on November 24, 4714 B.C according to the |
| 30075 | 30025 | ** proleptic Gregorian calendar. |
| 30076 | 30026 | ** |
| 30077 | | -** On success, return 0. Return 1 if the time and date cannot be found. |
| 30027 | +** On success, return SQLITE_OK. Return SQLITE_ERROR if the time and date |
| 30028 | +** cannot be found. |
| 30078 | 30029 | */ |
| 30079 | 30030 | static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){ |
| 30080 | 30031 | static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000; |
| 30032 | + int rc = SQLITE_OK; |
| 30081 | 30033 | #if defined(NO_GETTOD) |
| 30082 | 30034 | time_t t; |
| 30083 | 30035 | time(&t); |
| 30084 | 30036 | *piNow = ((sqlite3_int64)t)*1000 + unixEpoch; |
| 30085 | 30037 | #elif OS_VXWORKS |
| | @@ -30086,34 +30038,38 @@ |
| 30086 | 30038 | struct timespec sNow; |
| 30087 | 30039 | clock_gettime(CLOCK_REALTIME, &sNow); |
| 30088 | 30040 | *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000; |
| 30089 | 30041 | #else |
| 30090 | 30042 | struct timeval sNow; |
| 30091 | | - gettimeofday(&sNow, 0); |
| 30092 | | - *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000; |
| 30043 | + if( gettimeofday(&sNow, 0)==0 ){ |
| 30044 | + *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000; |
| 30045 | + }else{ |
| 30046 | + rc = SQLITE_ERROR; |
| 30047 | + } |
| 30093 | 30048 | #endif |
| 30094 | 30049 | |
| 30095 | 30050 | #ifdef SQLITE_TEST |
| 30096 | 30051 | if( sqlite3_current_time ){ |
| 30097 | 30052 | *piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch; |
| 30098 | 30053 | } |
| 30099 | 30054 | #endif |
| 30100 | 30055 | UNUSED_PARAMETER(NotUsed); |
| 30101 | | - return 0; |
| 30056 | + return rc; |
| 30102 | 30057 | } |
| 30103 | 30058 | |
| 30104 | 30059 | /* |
| 30105 | 30060 | ** Find the current time (in Universal Coordinated Time). Write the |
| 30106 | 30061 | ** current time and date as a Julian Day number into *prNow and |
| 30107 | 30062 | ** return 0. Return 1 if the time and date cannot be found. |
| 30108 | 30063 | */ |
| 30109 | 30064 | static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){ |
| 30110 | | - sqlite3_int64 i; |
| 30065 | + sqlite3_int64 i = 0; |
| 30066 | + int rc; |
| 30111 | 30067 | UNUSED_PARAMETER(NotUsed); |
| 30112 | | - unixCurrentTimeInt64(0, &i); |
| 30068 | + rc = unixCurrentTimeInt64(0, &i); |
| 30113 | 30069 | *prNow = i/86400000.0; |
| 30114 | | - return 0; |
| 30070 | + return rc; |
| 30115 | 30071 | } |
| 30116 | 30072 | |
| 30117 | 30073 | /* |
| 30118 | 30074 | ** We added the xGetLastError() method with the intention of providing |
| 30119 | 30075 | ** better low-level error messages when operating-system problems come up |
| | @@ -34612,11 +34568,11 @@ |
| 34612 | 34568 | } |
| 34613 | 34569 | static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){ |
| 34614 | 34570 | UNUSED_PARAMETER(pVfs); |
| 34615 | 34571 | getLastErrorMsg(nBuf, zBufOut); |
| 34616 | 34572 | } |
| 34617 | | -void (*winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(void){ |
| 34573 | +static void (*winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(void){ |
| 34618 | 34574 | UNUSED_PARAMETER(pVfs); |
| 34619 | 34575 | #if SQLITE_OS_WINCE |
| 34620 | 34576 | /* The GetProcAddressA() routine is only available on wince. */ |
| 34621 | 34577 | return (void(*)(void))GetProcAddressA((HANDLE)pHandle, zSymbol); |
| 34622 | 34578 | #else |
| | @@ -34623,11 +34579,11 @@ |
| 34623 | 34579 | /* All other windows platforms expect GetProcAddress() to take |
| 34624 | 34580 | ** an Ansi string regardless of the _UNICODE setting */ |
| 34625 | 34581 | return (void(*)(void))GetProcAddress((HANDLE)pHandle, zSymbol); |
| 34626 | 34582 | #endif |
| 34627 | 34583 | } |
| 34628 | | -void winDlClose(sqlite3_vfs *pVfs, void *pHandle){ |
| 34584 | +static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){ |
| 34629 | 34585 | UNUSED_PARAMETER(pVfs); |
| 34630 | 34586 | FreeLibrary((HANDLE)pHandle); |
| 34631 | 34587 | } |
| 34632 | 34588 | #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */ |
| 34633 | 34589 | #define winDlOpen 0 |
| | @@ -34697,11 +34653,12 @@ |
| 34697 | 34653 | ** the current time and date as a Julian Day number times 86_400_000. In |
| 34698 | 34654 | ** other words, write into *piNow the number of milliseconds since the Julian |
| 34699 | 34655 | ** epoch of noon in Greenwich on November 24, 4714 B.C according to the |
| 34700 | 34656 | ** proleptic Gregorian calendar. |
| 34701 | 34657 | ** |
| 34702 | | -** On success, return 0. Return 1 if the time and date cannot be found. |
| 34658 | +** On success, return SQLITE_OK. Return SQLITE_ERROR if the time and date |
| 34659 | +** cannot be found. |
| 34703 | 34660 | */ |
| 34704 | 34661 | static int winCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *piNow){ |
| 34705 | 34662 | /* FILETIME structure is a 64-bit value representing the number of |
| 34706 | 34663 | 100-nanosecond intervals since January 1, 1601 (= JD 2305813.5). |
| 34707 | 34664 | */ |
| | @@ -34717,11 +34674,11 @@ |
| 34717 | 34674 | #if SQLITE_OS_WINCE |
| 34718 | 34675 | SYSTEMTIME time; |
| 34719 | 34676 | GetSystemTime(&time); |
| 34720 | 34677 | /* if SystemTimeToFileTime() fails, it returns zero. */ |
| 34721 | 34678 | if (!SystemTimeToFileTime(&time,&ft)){ |
| 34722 | | - return 1; |
| 34679 | + return SQLITE_ERROR; |
| 34723 | 34680 | } |
| 34724 | 34681 | #else |
| 34725 | 34682 | GetSystemTimeAsFileTime( &ft ); |
| 34726 | 34683 | #endif |
| 34727 | 34684 | |
| | @@ -34733,19 +34690,19 @@ |
| 34733 | 34690 | if( sqlite3_current_time ){ |
| 34734 | 34691 | *piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch; |
| 34735 | 34692 | } |
| 34736 | 34693 | #endif |
| 34737 | 34694 | UNUSED_PARAMETER(pVfs); |
| 34738 | | - return 0; |
| 34695 | + return SQLITE_OK; |
| 34739 | 34696 | } |
| 34740 | 34697 | |
| 34741 | 34698 | /* |
| 34742 | 34699 | ** Find the current time (in Universal Coordinated Time). Write the |
| 34743 | 34700 | ** current time and date as a Julian Day number into *prNow and |
| 34744 | 34701 | ** return 0. Return 1 if the time and date cannot be found. |
| 34745 | 34702 | */ |
| 34746 | | -int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){ |
| 34703 | +static int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){ |
| 34747 | 34704 | int rc; |
| 34748 | 34705 | sqlite3_int64 i; |
| 34749 | 34706 | rc = winCurrentTimeInt64(pVfs, &i); |
| 34750 | 34707 | if( !rc ){ |
| 34751 | 34708 | *prNow = i/86400000.0; |
| | @@ -40068,11 +40025,10 @@ |
| 40068 | 40025 | needPagerReset = 0; |
| 40069 | 40026 | } |
| 40070 | 40027 | rc = pager_playback_one_page(pPager,&pPager->journalOff,0,1,0); |
| 40071 | 40028 | if( rc!=SQLITE_OK ){ |
| 40072 | 40029 | if( rc==SQLITE_DONE ){ |
| 40073 | | - rc = SQLITE_OK; |
| 40074 | 40030 | pPager->journalOff = szJ; |
| 40075 | 40031 | break; |
| 40076 | 40032 | }else if( rc==SQLITE_IOERR_SHORT_READ ){ |
| 40077 | 40033 | /* If the journal has been truncated, simply stop reading and |
| 40078 | 40034 | ** processing the journal. This might happen if the journal was |
| | @@ -40330,10 +40286,11 @@ |
| 40330 | 40286 | #if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES) |
| 40331 | 40287 | PgHdr *p; /* For looping over pages */ |
| 40332 | 40288 | #endif |
| 40333 | 40289 | |
| 40334 | 40290 | assert( pPager->pWal ); |
| 40291 | + assert( pList ); |
| 40335 | 40292 | #ifdef SQLITE_DEBUG |
| 40336 | 40293 | /* Verify that the page list is in accending order */ |
| 40337 | 40294 | for(p=pList; p && p->pDirty; p=p->pDirty){ |
| 40338 | 40295 | assert( p->pgno < p->pDirty->pgno ); |
| 40339 | 40296 | } |
| | @@ -46566,11 +46523,11 @@ |
| 46566 | 46523 | */ |
| 46567 | 46524 | if( iRead ){ |
| 46568 | 46525 | int sz; |
| 46569 | 46526 | i64 iOffset; |
| 46570 | 46527 | sz = pWal->hdr.szPage; |
| 46571 | | - sz = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16); |
| 46528 | + sz = (sz&0xfe00) + ((sz&0x0001)<<16); |
| 46572 | 46529 | testcase( sz<=32768 ); |
| 46573 | 46530 | testcase( sz>=65536 ); |
| 46574 | 46531 | iOffset = walFrameOffset(iRead, sz) + WAL_FRAME_HDRSIZE; |
| 46575 | 46532 | *pInWal = 1; |
| 46576 | 46533 | /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */ |
| | @@ -49879,21 +49836,23 @@ |
| 49879 | 49836 | */ |
| 49880 | 49837 | if( isMemdb==0 && isTempDb==0 ){ |
| 49881 | 49838 | if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){ |
| 49882 | 49839 | int nFullPathname = pVfs->mxPathname+1; |
| 49883 | 49840 | char *zFullPathname = sqlite3Malloc(nFullPathname); |
| 49884 | | - sqlite3_mutex *mutexShared; |
| 49841 | + MUTEX_LOGIC( sqlite3_mutex *mutexShared; ) |
| 49885 | 49842 | p->sharable = 1; |
| 49886 | 49843 | if( !zFullPathname ){ |
| 49887 | 49844 | sqlite3_free(p); |
| 49888 | 49845 | return SQLITE_NOMEM; |
| 49889 | 49846 | } |
| 49890 | 49847 | sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname); |
| 49848 | +#if SQLITE_THREADSAFE |
| 49891 | 49849 | mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN); |
| 49892 | 49850 | sqlite3_mutex_enter(mutexOpen); |
| 49893 | 49851 | mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 49894 | 49852 | sqlite3_mutex_enter(mutexShared); |
| 49853 | +#endif |
| 49895 | 49854 | for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){ |
| 49896 | 49855 | assert( pBt->nRef>0 ); |
| 49897 | 49856 | if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager)) |
| 49898 | 49857 | && sqlite3PagerVfs(pBt->pPager)==pVfs ){ |
| 49899 | 49858 | int iDb; |
| | @@ -49995,13 +49954,13 @@ |
| 49995 | 49954 | |
| 49996 | 49955 | #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO) |
| 49997 | 49956 | /* Add the new BtShared object to the linked list sharable BtShareds. |
| 49998 | 49957 | */ |
| 49999 | 49958 | if( p->sharable ){ |
| 50000 | | - sqlite3_mutex *mutexShared; |
| 49959 | + MUTEX_LOGIC( sqlite3_mutex *mutexShared; ) |
| 50001 | 49960 | pBt->nRef = 1; |
| 50002 | | - mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 49961 | + MUTEX_LOGIC( mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);) |
| 50003 | 49962 | if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){ |
| 50004 | 49963 | pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST); |
| 50005 | 49964 | if( pBt->mutex==0 ){ |
| 50006 | 49965 | rc = SQLITE_NOMEM; |
| 50007 | 49966 | db->mallocFailed = 0; |
| | @@ -50079,16 +50038,16 @@ |
| 50079 | 50038 | ** true if the BtShared.nRef counter reaches zero and return |
| 50080 | 50039 | ** false if it is still positive. |
| 50081 | 50040 | */ |
| 50082 | 50041 | static int removeFromSharingList(BtShared *pBt){ |
| 50083 | 50042 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 50084 | | - sqlite3_mutex *pMaster; |
| 50043 | + MUTEX_LOGIC( sqlite3_mutex *pMaster; ) |
| 50085 | 50044 | BtShared *pList; |
| 50086 | 50045 | int removed = 0; |
| 50087 | 50046 | |
| 50088 | 50047 | assert( sqlite3_mutex_notheld(pBt->mutex) ); |
| 50089 | | - pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 50048 | + MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 50090 | 50049 | sqlite3_mutex_enter(pMaster); |
| 50091 | 50050 | pBt->nRef--; |
| 50092 | 50051 | if( pBt->nRef<=0 ){ |
| 50093 | 50052 | if( GLOBAL(BtShared*,sqlite3SharedCacheList)==pBt ){ |
| 50094 | 50053 | GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt->pNext; |
| | @@ -52698,11 +52657,10 @@ |
| 52698 | 52657 | } |
| 52699 | 52658 | } |
| 52700 | 52659 | if( c==0 ){ |
| 52701 | 52660 | if( pPage->intKey && !pPage->leaf ){ |
| 52702 | 52661 | lwr = idx; |
| 52703 | | - upr = lwr - 1; |
| 52704 | 52662 | break; |
| 52705 | 52663 | }else{ |
| 52706 | 52664 | *pRes = 0; |
| 52707 | 52665 | rc = SQLITE_OK; |
| 52708 | 52666 | goto moveto_finish; |
| | @@ -52716,11 +52674,11 @@ |
| 52716 | 52674 | if( lwr>upr ){ |
| 52717 | 52675 | break; |
| 52718 | 52676 | } |
| 52719 | 52677 | pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2); |
| 52720 | 52678 | } |
| 52721 | | - assert( lwr==upr+1 ); |
| 52679 | + assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) ); |
| 52722 | 52680 | assert( pPage->isInit ); |
| 52723 | 52681 | if( pPage->leaf ){ |
| 52724 | 52682 | chldPg = 0; |
| 52725 | 52683 | }else if( lwr>=pPage->nCell ){ |
| 52726 | 52684 | chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]); |
| | @@ -52981,10 +52939,12 @@ |
| 52981 | 52939 | } |
| 52982 | 52940 | if( rc ){ |
| 52983 | 52941 | pTrunk = 0; |
| 52984 | 52942 | goto end_allocate_page; |
| 52985 | 52943 | } |
| 52944 | + assert( pTrunk!=0 ); |
| 52945 | + assert( pTrunk->aData!=0 ); |
| 52986 | 52946 | |
| 52987 | 52947 | k = get4byte(&pTrunk->aData[4]); /* # of leaves on this trunk page */ |
| 52988 | 52948 | if( k==0 && !searchList ){ |
| 52989 | 52949 | /* The trunk has no leaves and the list is not being searched. |
| 52990 | 52950 | ** So extract the trunk page itself and use it as the newly |
| | @@ -54108,17 +54068,19 @@ |
| 54108 | 54068 | ** This is safe because dropping a cell only overwrites the first |
| 54109 | 54069 | ** four bytes of it, and this function does not need the first |
| 54110 | 54070 | ** four bytes of the divider cell. So the pointer is safe to use |
| 54111 | 54071 | ** later on. |
| 54112 | 54072 | ** |
| 54113 | | - ** Unless SQLite is compiled in secure-delete mode. In this case, |
| 54073 | + ** But not if we are in secure-delete mode. In secure-delete mode, |
| 54114 | 54074 | ** the dropCell() routine will overwrite the entire cell with zeroes. |
| 54115 | 54075 | ** In this case, temporarily copy the cell into the aOvflSpace[] |
| 54116 | 54076 | ** buffer. It will be copied out again as soon as the aSpace[] buffer |
| 54117 | 54077 | ** is allocated. */ |
| 54118 | 54078 | if( pBt->secureDelete ){ |
| 54119 | | - int iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData); |
| 54079 | + int iOff; |
| 54080 | + |
| 54081 | + iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData); |
| 54120 | 54082 | if( (iOff+szNew[i])>(int)pBt->usableSize ){ |
| 54121 | 54083 | rc = SQLITE_CORRUPT_BKPT; |
| 54122 | 54084 | memset(apOld, 0, (i+1)*sizeof(MemPage*)); |
| 54123 | 54085 | goto balance_cleanup; |
| 54124 | 54086 | }else{ |
| | @@ -54534,10 +54496,11 @@ |
| 54534 | 54496 | int isDivider = 0; |
| 54535 | 54497 | while( i==iNextOld ){ |
| 54536 | 54498 | /* Cell i is the cell immediately following the last cell on old |
| 54537 | 54499 | ** sibling page j. If the siblings are not leaf pages of an |
| 54538 | 54500 | ** intkey b-tree, then cell i was a divider cell. */ |
| 54501 | + assert( j+1 < ArraySize(apCopy) ); |
| 54539 | 54502 | pOld = apCopy[++j]; |
| 54540 | 54503 | iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow; |
| 54541 | 54504 | if( pOld->nOverflow ){ |
| 54542 | 54505 | nOverflow = pOld->nOverflow; |
| 54543 | 54506 | iOverflow = i + !leafData + pOld->aOvfl[0].idx; |
| | @@ -56876,18 +56839,18 @@ |
| 56876 | 56839 | /* |
| 56877 | 56840 | ** Release all resources associated with an sqlite3_backup* handle. |
| 56878 | 56841 | */ |
| 56879 | 56842 | SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p){ |
| 56880 | 56843 | sqlite3_backup **pp; /* Ptr to head of pagers backup list */ |
| 56881 | | - sqlite3_mutex *mutex; /* Mutex to protect source database */ |
| 56844 | + MUTEX_LOGIC( sqlite3_mutex *mutex; ) /* Mutex to protect source database */ |
| 56882 | 56845 | int rc; /* Value to return */ |
| 56883 | 56846 | |
| 56884 | 56847 | /* Enter the mutexes */ |
| 56885 | 56848 | if( p==0 ) return SQLITE_OK; |
| 56886 | 56849 | sqlite3_mutex_enter(p->pSrcDb->mutex); |
| 56887 | 56850 | sqlite3BtreeEnter(p->pSrc); |
| 56888 | | - mutex = p->pSrcDb->mutex; |
| 56851 | + MUTEX_LOGIC( mutex = p->pSrcDb->mutex; ) |
| 56889 | 56852 | if( p->pDestDb ){ |
| 56890 | 56853 | sqlite3_mutex_enter(p->pDestDb->mutex); |
| 56891 | 56854 | } |
| 56892 | 56855 | |
| 56893 | 56856 | /* Detach this backup from the source pager. */ |
| | @@ -58983,34 +58946,33 @@ |
| 58983 | 58946 | ** Change the comment on the the most recently coded instruction. Or |
| 58984 | 58947 | ** insert a No-op and add the comment to that new instruction. This |
| 58985 | 58948 | ** makes the code easier to read during debugging. None of this happens |
| 58986 | 58949 | ** in a production build. |
| 58987 | 58950 | */ |
| 58988 | | -SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){ |
| 58989 | | - va_list ap; |
| 58990 | | - if( !p ) return; |
| 58951 | +static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){ |
| 58991 | 58952 | assert( p->nOp>0 || p->aOp==0 ); |
| 58992 | 58953 | assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed ); |
| 58993 | 58954 | if( p->nOp ){ |
| 58994 | | - char **pz = &p->aOp[p->nOp-1].zComment; |
| 58955 | + assert( p->aOp ); |
| 58956 | + sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment); |
| 58957 | + p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap); |
| 58958 | + } |
| 58959 | +} |
| 58960 | +SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){ |
| 58961 | + va_list ap; |
| 58962 | + if( p ){ |
| 58995 | 58963 | va_start(ap, zFormat); |
| 58996 | | - sqlite3DbFree(p->db, *pz); |
| 58997 | | - *pz = sqlite3VMPrintf(p->db, zFormat, ap); |
| 58964 | + vdbeVComment(p, zFormat, ap); |
| 58998 | 58965 | va_end(ap); |
| 58999 | 58966 | } |
| 59000 | 58967 | } |
| 59001 | 58968 | SQLITE_PRIVATE void sqlite3VdbeNoopComment(Vdbe *p, const char *zFormat, ...){ |
| 59002 | 58969 | va_list ap; |
| 59003 | | - if( !p ) return; |
| 59004 | | - sqlite3VdbeAddOp0(p, OP_Noop); |
| 59005 | | - assert( p->nOp>0 || p->aOp==0 ); |
| 59006 | | - assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed ); |
| 59007 | | - if( p->nOp ){ |
| 59008 | | - char **pz = &p->aOp[p->nOp-1].zComment; |
| 58970 | + if( p ){ |
| 58971 | + sqlite3VdbeAddOp0(p, OP_Noop); |
| 59009 | 58972 | va_start(ap, zFormat); |
| 59010 | | - sqlite3DbFree(p->db, *pz); |
| 59011 | | - *pz = sqlite3VMPrintf(p->db, zFormat, ap); |
| 58973 | + vdbeVComment(p, zFormat, ap); |
| 59012 | 58974 | va_end(ap); |
| 59013 | 58975 | } |
| 59014 | 58976 | } |
| 59015 | 58977 | #endif /* NDEBUG */ |
| 59016 | 58978 | |
| | @@ -61266,11 +61228,11 @@ |
| 61266 | 61228 | ** than 2GiB are support - anything large must be database corruption. |
| 61267 | 61229 | ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so |
| 61268 | 61230 | ** this code can safely assume that nCellKey is 32-bits |
| 61269 | 61231 | */ |
| 61270 | 61232 | assert( sqlite3BtreeCursorIsValid(pCur) ); |
| 61271 | | - rc = sqlite3BtreeKeySize(pCur, &nCellKey); |
| 61233 | + VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey); |
| 61272 | 61234 | assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */ |
| 61273 | 61235 | assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey ); |
| 61274 | 61236 | |
| 61275 | 61237 | /* Read in the complete content of the index entry */ |
| 61276 | 61238 | memset(&m, 0, sizeof(m)); |
| | @@ -61341,11 +61303,11 @@ |
| 61341 | 61303 | int rc; |
| 61342 | 61304 | BtCursor *pCur = pC->pCursor; |
| 61343 | 61305 | Mem m; |
| 61344 | 61306 | |
| 61345 | 61307 | assert( sqlite3BtreeCursorIsValid(pCur) ); |
| 61346 | | - rc = sqlite3BtreeKeySize(pCur, &nCellKey); |
| 61308 | + VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey); |
| 61347 | 61309 | assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */ |
| 61348 | 61310 | /* nCellKey will always be between 0 and 0xffffffff because of the say |
| 61349 | 61311 | ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */ |
| 61350 | 61312 | if( nCellKey<=0 || nCellKey>0x7fffffff ){ |
| 61351 | 61313 | *res = 0; |
| | @@ -65617,20 +65579,20 @@ |
| 65617 | 65579 | }else if( u.am.pC->cacheStatus==p->cacheCtr ){ |
| 65618 | 65580 | u.am.payloadSize = u.am.pC->payloadSize; |
| 65619 | 65581 | u.am.zRec = (char*)u.am.pC->aRow; |
| 65620 | 65582 | }else if( u.am.pC->isIndex ){ |
| 65621 | 65583 | assert( sqlite3BtreeCursorIsValid(u.am.pCrsr) ); |
| 65622 | | - rc = sqlite3BtreeKeySize(u.am.pCrsr, &u.am.payloadSize64); |
| 65584 | + VVA_ONLY(rc =) sqlite3BtreeKeySize(u.am.pCrsr, &u.am.payloadSize64); |
| 65623 | 65585 | assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 65624 | 65586 | /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the |
| 65625 | 65587 | ** payload size, so it is impossible for u.am.payloadSize64 to be |
| 65626 | 65588 | ** larger than 32 bits. */ |
| 65627 | 65589 | assert( (u.am.payloadSize64 & SQLITE_MAX_U32)==(u64)u.am.payloadSize64 ); |
| 65628 | 65590 | u.am.payloadSize = (u32)u.am.payloadSize64; |
| 65629 | 65591 | }else{ |
| 65630 | 65592 | assert( sqlite3BtreeCursorIsValid(u.am.pCrsr) ); |
| 65631 | | - rc = sqlite3BtreeDataSize(u.am.pCrsr, &u.am.payloadSize); |
| 65593 | + VVA_ONLY(rc =) sqlite3BtreeDataSize(u.am.pCrsr, &u.am.payloadSize); |
| 65632 | 65594 | assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 65633 | 65595 | } |
| 65634 | 65596 | }else if( ALWAYS(u.am.pC->pseudoTableReg>0) ){ |
| 65635 | 65597 | u.am.pReg = &aMem[u.am.pC->pseudoTableReg]; |
| 65636 | 65598 | assert( u.am.pReg->flags & MEM_Blob ); |
| | @@ -67678,18 +67640,18 @@ |
| 67678 | 67640 | rc = sqlite3VdbeCursorMoveto(u.bk.pC); |
| 67679 | 67641 | if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; |
| 67680 | 67642 | |
| 67681 | 67643 | if( u.bk.pC->isIndex ){ |
| 67682 | 67644 | assert( !u.bk.pC->isTable ); |
| 67683 | | - rc = sqlite3BtreeKeySize(u.bk.pCrsr, &u.bk.n64); |
| 67645 | + VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bk.pCrsr, &u.bk.n64); |
| 67684 | 67646 | assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 67685 | 67647 | if( u.bk.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 67686 | 67648 | goto too_big; |
| 67687 | 67649 | } |
| 67688 | 67650 | u.bk.n = (u32)u.bk.n64; |
| 67689 | 67651 | }else{ |
| 67690 | | - rc = sqlite3BtreeDataSize(u.bk.pCrsr, &u.bk.n); |
| 67652 | + VVA_ONLY(rc =) sqlite3BtreeDataSize(u.bk.pCrsr, &u.bk.n); |
| 67691 | 67653 | assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 67692 | 67654 | if( u.bk.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 67693 | 67655 | goto too_big; |
| 67694 | 67656 | } |
| 67695 | 67657 | } |
| | @@ -73322,11 +73284,12 @@ |
| 73322 | 73284 | pNew->flags |= EP_IntValue; |
| 73323 | 73285 | pNew->u.iValue = iValue; |
| 73324 | 73286 | }else{ |
| 73325 | 73287 | int c; |
| 73326 | 73288 | pNew->u.zToken = (char*)&pNew[1]; |
| 73327 | | - memcpy(pNew->u.zToken, pToken->z, pToken->n); |
| 73289 | + assert( pToken->z!=0 || pToken->n==0 ); |
| 73290 | + if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n); |
| 73328 | 73291 | pNew->u.zToken[pToken->n] = 0; |
| 73329 | 73292 | if( dequote && nExtra>=3 |
| 73330 | 73293 | && ((c = pToken->z[0])=='\'' || c=='"' || c=='[' || c=='`') ){ |
| 73331 | 73294 | sqlite3Dequote(pNew->u.zToken); |
| 73332 | 73295 | if( c=='"' ) pNew->flags |= EP_DblQuoted; |
| | @@ -74361,15 +74324,23 @@ |
| 74361 | 74324 | ** ephemeral table. |
| 74362 | 74325 | */ |
| 74363 | 74326 | p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0); |
| 74364 | 74327 | if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){ |
| 74365 | 74328 | sqlite3 *db = pParse->db; /* Database connection */ |
| 74366 | | - Expr *pExpr = p->pEList->a[0].pExpr; /* Expression <column> */ |
| 74367 | | - int iCol = pExpr->iColumn; /* Index of column <column> */ |
| 74368 | 74329 | Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */ |
| 74369 | | - Table *pTab = p->pSrc->a[0].pTab; /* Table <table>. */ |
| 74330 | + Table *pTab; /* Table <table>. */ |
| 74331 | + Expr *pExpr; /* Expression <column> */ |
| 74332 | + int iCol; /* Index of column <column> */ |
| 74370 | 74333 | int iDb; /* Database idx for pTab */ |
| 74334 | + |
| 74335 | + assert( p ); /* Because of isCandidateForInOpt(p) */ |
| 74336 | + assert( p->pEList!=0 ); /* Because of isCandidateForInOpt(p) */ |
| 74337 | + assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */ |
| 74338 | + assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */ |
| 74339 | + pTab = p->pSrc->a[0].pTab; |
| 74340 | + pExpr = p->pEList->a[0].pExpr; |
| 74341 | + iCol = pExpr->iColumn; |
| 74371 | 74342 | |
| 74372 | 74343 | /* Code an OP_VerifyCookie and OP_TableLock for <table>. */ |
| 74373 | 74344 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 74374 | 74345 | sqlite3CodeVerifySchema(pParse, iDb); |
| 74375 | 74346 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| | @@ -76372,11 +76343,11 @@ |
| 76372 | 76343 | if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){ |
| 76373 | 76344 | return 2; |
| 76374 | 76345 | } |
| 76375 | 76346 | }else if( pA->op!=TK_COLUMN && pA->u.zToken ){ |
| 76376 | 76347 | if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2; |
| 76377 | | - if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ){ |
| 76348 | + if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ |
| 76378 | 76349 | return 2; |
| 76379 | 76350 | } |
| 76380 | 76351 | } |
| 76381 | 76352 | if( (pA->flags & EP_ExpCollate)!=(pB->flags & EP_ExpCollate) ) return 1; |
| 76382 | 76353 | if( (pA->flags & EP_ExpCollate)!=0 && pA->pColl!=pB->pColl ) return 2; |
| | @@ -81778,17 +81749,19 @@ |
| 81778 | 81749 | */ |
| 81779 | 81750 | static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){ |
| 81780 | 81751 | Table *pTab = pIndex->pTable; /* The table that is indexed */ |
| 81781 | 81752 | int iTab = pParse->nTab++; /* Btree cursor used for pTab */ |
| 81782 | 81753 | int iIdx = pParse->nTab++; /* Btree cursor used for pIndex */ |
| 81783 | | - int iSorter = iTab; /* Cursor opened by OpenSorter (if in use) */ |
| 81754 | + int iSorter; /* Cursor opened by OpenSorter (if in use) */ |
| 81784 | 81755 | int addr1; /* Address of top of loop */ |
| 81785 | 81756 | int addr2; /* Address to jump to for next iteration */ |
| 81786 | 81757 | int tnum; /* Root page of index */ |
| 81787 | 81758 | Vdbe *v; /* Generate code into this virtual machine */ |
| 81788 | 81759 | KeyInfo *pKey; /* KeyInfo for index */ |
| 81760 | +#ifdef SQLITE_OMIT_MERGE_SORT |
| 81789 | 81761 | int regIdxKey; /* Registers containing the index key */ |
| 81762 | +#endif |
| 81790 | 81763 | int regRecord; /* Register holding assemblied index record */ |
| 81791 | 81764 | sqlite3 *db = pParse->db; /* The database connection */ |
| 81792 | 81765 | int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema); |
| 81793 | 81766 | |
| 81794 | 81767 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| | @@ -81818,21 +81791,22 @@ |
| 81818 | 81791 | |
| 81819 | 81792 | #ifndef SQLITE_OMIT_MERGE_SORT |
| 81820 | 81793 | /* Open the sorter cursor if we are to use one. */ |
| 81821 | 81794 | iSorter = pParse->nTab++; |
| 81822 | 81795 | sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)pKey, P4_KEYINFO); |
| 81796 | +#else |
| 81797 | + iSorter = iTab; |
| 81823 | 81798 | #endif |
| 81824 | 81799 | |
| 81825 | 81800 | /* Open the table. Loop through all rows of the table, inserting index |
| 81826 | 81801 | ** records into the sorter. */ |
| 81827 | 81802 | sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead); |
| 81828 | 81803 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); |
| 81829 | | - addr2 = addr1 + 1; |
| 81830 | 81804 | regRecord = sqlite3GetTempReg(pParse); |
| 81831 | | - regIdxKey = sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1); |
| 81832 | 81805 | |
| 81833 | 81806 | #ifndef SQLITE_OMIT_MERGE_SORT |
| 81807 | + sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1); |
| 81834 | 81808 | sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord); |
| 81835 | 81809 | sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); |
| 81836 | 81810 | sqlite3VdbeJumpHere(v, addr1); |
| 81837 | 81811 | addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); |
| 81838 | 81812 | if( pIndex->onError!=OE_None ){ |
| | @@ -81848,10 +81822,12 @@ |
| 81848 | 81822 | } |
| 81849 | 81823 | sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord); |
| 81850 | 81824 | sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1); |
| 81851 | 81825 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 81852 | 81826 | #else |
| 81827 | + regIdxKey = sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1); |
| 81828 | + addr2 = addr1 + 1; |
| 81853 | 81829 | if( pIndex->onError!=OE_None ){ |
| 81854 | 81830 | const int regRowid = regIdxKey + pIndex->nColumn; |
| 81855 | 81831 | const int j2 = sqlite3VdbeCurrentAddr(v) + 2; |
| 81856 | 81832 | void * const pRegKey = SQLITE_INT_TO_PTR(regIdxKey); |
| 81857 | 81833 | |
| | @@ -81945,10 +81921,11 @@ |
| 81945 | 81921 | ** before looking up the table. |
| 81946 | 81922 | */ |
| 81947 | 81923 | assert( pName1 && pName2 ); |
| 81948 | 81924 | iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName); |
| 81949 | 81925 | if( iDb<0 ) goto exit_create_index; |
| 81926 | + assert( pName && pName->z ); |
| 81950 | 81927 | |
| 81951 | 81928 | #ifndef SQLITE_OMIT_TEMPDB |
| 81952 | 81929 | /* If the index name was unqualified, check if the the table |
| 81953 | 81930 | ** is a temp table. If so, set the database to 1. Do not do this |
| 81954 | 81931 | ** if initialising a database schema. |
| | @@ -81972,10 +81949,11 @@ |
| 81972 | 81949 | pTblName->a[0].zDatabase); |
| 81973 | 81950 | if( !pTab || db->mallocFailed ) goto exit_create_index; |
| 81974 | 81951 | assert( db->aDb[iDb].pSchema==pTab->pSchema ); |
| 81975 | 81952 | }else{ |
| 81976 | 81953 | assert( pName==0 ); |
| 81954 | + assert( pStart==0 ); |
| 81977 | 81955 | pTab = pParse->pNewTable; |
| 81978 | 81956 | if( !pTab ) goto exit_create_index; |
| 81979 | 81957 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 81980 | 81958 | } |
| 81981 | 81959 | pDb = &db->aDb[iDb]; |
| | @@ -82014,10 +81992,11 @@ |
| 82014 | 81992 | ** own name. |
| 82015 | 81993 | */ |
| 82016 | 81994 | if( pName ){ |
| 82017 | 81995 | zName = sqlite3NameFromToken(db, pName); |
| 82018 | 81996 | if( zName==0 ) goto exit_create_index; |
| 81997 | + assert( pName->z!=0 ); |
| 82019 | 81998 | if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ |
| 82020 | 81999 | goto exit_create_index; |
| 82021 | 82000 | } |
| 82022 | 82001 | if( !db->init.busy ){ |
| 82023 | 82002 | if( sqlite3FindTable(db, zName, 0)!=0 ){ |
| | @@ -82869,17 +82848,14 @@ |
| 82869 | 82848 | |
| 82870 | 82849 | /* |
| 82871 | 82850 | ** Commit a transaction |
| 82872 | 82851 | */ |
| 82873 | 82852 | SQLITE_PRIVATE void sqlite3CommitTransaction(Parse *pParse){ |
| 82874 | | - sqlite3 *db; |
| 82875 | 82853 | Vdbe *v; |
| 82876 | 82854 | |
| 82877 | 82855 | assert( pParse!=0 ); |
| 82878 | | - db = pParse->db; |
| 82879 | | - assert( db!=0 ); |
| 82880 | | -/* if( db->aDb[0].pBt==0 ) return; */ |
| 82856 | + assert( pParse->db!=0 ); |
| 82881 | 82857 | if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "COMMIT", 0, 0) ){ |
| 82882 | 82858 | return; |
| 82883 | 82859 | } |
| 82884 | 82860 | v = sqlite3GetVdbe(pParse); |
| 82885 | 82861 | if( v ){ |
| | @@ -82889,17 +82865,14 @@ |
| 82889 | 82865 | |
| 82890 | 82866 | /* |
| 82891 | 82867 | ** Rollback a transaction |
| 82892 | 82868 | */ |
| 82893 | 82869 | SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse *pParse){ |
| 82894 | | - sqlite3 *db; |
| 82895 | 82870 | Vdbe *v; |
| 82896 | 82871 | |
| 82897 | 82872 | assert( pParse!=0 ); |
| 82898 | | - db = pParse->db; |
| 82899 | | - assert( db!=0 ); |
| 82900 | | -/* if( db->aDb[0].pBt==0 ) return; */ |
| 82873 | + assert( pParse->db!=0 ); |
| 82901 | 82874 | if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "ROLLBACK", 0, 0) ){ |
| 82902 | 82875 | return; |
| 82903 | 82876 | } |
| 82904 | 82877 | v = sqlite3GetVdbe(pParse); |
| 82905 | 82878 | if( v ){ |
| | @@ -84701,20 +84674,19 @@ |
| 84701 | 84674 | /* Verify that the call to _bytes() does not invalidate the _text() pointer */ |
| 84702 | 84675 | assert( z2==(char*)sqlite3_value_text(argv[0]) ); |
| 84703 | 84676 | if( z2 ){ |
| 84704 | 84677 | z1 = contextMalloc(context, ((i64)n)+1); |
| 84705 | 84678 | if( z1 ){ |
| 84706 | | - memcpy(z1, z2, n+1); |
| 84707 | | - for(i=0; z1[i]; i++){ |
| 84708 | | - z1[i] = (char)sqlite3Toupper(z1[i]); |
| 84679 | + for(i=0; i<n; i++){ |
| 84680 | + z1[i] = (char)sqlite3Toupper(z2[i]); |
| 84709 | 84681 | } |
| 84710 | | - sqlite3_result_text(context, z1, -1, sqlite3_free); |
| 84682 | + sqlite3_result_text(context, z1, n, sqlite3_free); |
| 84711 | 84683 | } |
| 84712 | 84684 | } |
| 84713 | 84685 | } |
| 84714 | 84686 | static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ |
| 84715 | | - u8 *z1; |
| 84687 | + char *z1; |
| 84716 | 84688 | const char *z2; |
| 84717 | 84689 | int i, n; |
| 84718 | 84690 | UNUSED_PARAMETER(argc); |
| 84719 | 84691 | z2 = (char*)sqlite3_value_text(argv[0]); |
| 84720 | 84692 | n = sqlite3_value_bytes(argv[0]); |
| | @@ -84721,15 +84693,14 @@ |
| 84721 | 84693 | /* Verify that the call to _bytes() does not invalidate the _text() pointer */ |
| 84722 | 84694 | assert( z2==(char*)sqlite3_value_text(argv[0]) ); |
| 84723 | 84695 | if( z2 ){ |
| 84724 | 84696 | z1 = contextMalloc(context, ((i64)n)+1); |
| 84725 | 84697 | if( z1 ){ |
| 84726 | | - memcpy(z1, z2, n+1); |
| 84727 | | - for(i=0; z1[i]; i++){ |
| 84728 | | - z1[i] = sqlite3Tolower(z1[i]); |
| 84698 | + for(i=0; i<n; i++){ |
| 84699 | + z1[i] = sqlite3Tolower(z2[i]); |
| 84729 | 84700 | } |
| 84730 | | - sqlite3_result_text(context, (char *)z1, -1, sqlite3_free); |
| 84701 | + sqlite3_result_text(context, z1, n, sqlite3_free); |
| 84731 | 84702 | } |
| 84732 | 84703 | } |
| 84733 | 84704 | } |
| 84734 | 84705 | |
| 84735 | 84706 | |
| | @@ -87102,10 +87073,11 @@ |
| 87102 | 87073 | sqlite3SelectDelete(db, pSelect); |
| 87103 | 87074 | if( db->mallocFailed==1 ){ |
| 87104 | 87075 | fkTriggerDelete(db, pTrigger); |
| 87105 | 87076 | return 0; |
| 87106 | 87077 | } |
| 87078 | + assert( pStep!=0 ); |
| 87107 | 87079 | |
| 87108 | 87080 | switch( action ){ |
| 87109 | 87081 | case OE_Restrict: |
| 87110 | 87082 | pStep->op = TK_SELECT; |
| 87111 | 87083 | break; |
| | @@ -90025,11 +89997,11 @@ |
| 90025 | 89997 | sqlite3_vfs *pVfs = db->pVfs; |
| 90026 | 89998 | void *handle; |
| 90027 | 89999 | int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); |
| 90028 | 90000 | char *zErrmsg = 0; |
| 90029 | 90001 | void **aHandle; |
| 90030 | | - const int nMsg = 300; |
| 90002 | + int nMsg = 300 + sqlite3Strlen30(zFile); |
| 90031 | 90003 | |
| 90032 | 90004 | if( pzErrMsg ) *pzErrMsg = 0; |
| 90033 | 90005 | |
| 90034 | 90006 | /* Ticket #1863. To avoid a creating security problems for older |
| 90035 | 90007 | ** applications that relink against newer versions of SQLite, the |
| | @@ -90062,10 +90034,11 @@ |
| 90062 | 90034 | } |
| 90063 | 90035 | xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*)) |
| 90064 | 90036 | sqlite3OsDlSym(pVfs, handle, zProc); |
| 90065 | 90037 | if( xInit==0 ){ |
| 90066 | 90038 | if( pzErrMsg ){ |
| 90039 | + nMsg += sqlite3Strlen30(zProc); |
| 90067 | 90040 | *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg); |
| 90068 | 90041 | if( zErrmsg ){ |
| 90069 | 90042 | sqlite3_snprintf(nMsg, zErrmsg, |
| 90070 | 90043 | "no entry point [%s] in shared library [%s]", zProc,zFile); |
| 90071 | 90044 | sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); |
| | @@ -90747,11 +90720,11 @@ |
| 90747 | 90720 | ){ |
| 90748 | 90721 | int iReg; |
| 90749 | 90722 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 90750 | 90723 | sqlite3CodeVerifySchema(pParse, iDb); |
| 90751 | 90724 | iReg = ++pParse->nMem; |
| 90752 | | - if( zLeft[0]=='p' ){ |
| 90725 | + if( sqlite3Tolower(zLeft[0])=='p' ){ |
| 90753 | 90726 | sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg); |
| 90754 | 90727 | }else{ |
| 90755 | 90728 | sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, sqlite3Atoi(zRight)); |
| 90756 | 90729 | } |
| 90757 | 90730 | sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1); |
| | @@ -91360,11 +91333,11 @@ |
| 91360 | 91333 | { OP_IfNeg, 1, 0, 0}, /* 1 */ |
| 91361 | 91334 | { OP_String8, 0, 3, 0}, /* 2 */ |
| 91362 | 91335 | { OP_ResultRow, 3, 1, 0}, |
| 91363 | 91336 | }; |
| 91364 | 91337 | |
| 91365 | | - int isQuick = (zLeft[0]=='q'); |
| 91338 | + int isQuick = (sqlite3Tolower(zLeft[0])=='q'); |
| 91366 | 91339 | |
| 91367 | 91340 | /* Initialize the VDBE program */ |
| 91368 | 91341 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 91369 | 91342 | pParse->nMem = 6; |
| 91370 | 91343 | sqlite3VdbeSetNumCols(v, 1); |
| | @@ -93942,11 +93915,14 @@ |
| 93942 | 93915 | /* If the column contains an "AS <name>" phrase, use <name> as the name */ |
| 93943 | 93916 | zName = sqlite3DbStrDup(db, zName); |
| 93944 | 93917 | }else{ |
| 93945 | 93918 | Expr *pColExpr = p; /* The expression that is the result column name */ |
| 93946 | 93919 | Table *pTab; /* Table associated with this expression */ |
| 93947 | | - while( pColExpr->op==TK_DOT ) pColExpr = pColExpr->pRight; |
| 93920 | + while( pColExpr->op==TK_DOT ){ |
| 93921 | + pColExpr = pColExpr->pRight; |
| 93922 | + assert( pColExpr!=0 ); |
| 93923 | + } |
| 93948 | 93924 | if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){ |
| 93949 | 93925 | /* For columns use the column name name */ |
| 93950 | 93926 | int iCol = pColExpr->iColumn; |
| 93951 | 93927 | pTab = pColExpr->pTab; |
| 93952 | 93928 | if( iCol<0 ) iCol = pTab->iPKey; |
| | @@ -98940,10 +98916,11 @@ |
| 98940 | 98916 | break; |
| 98941 | 98917 | } |
| 98942 | 98918 | } |
| 98943 | 98919 | } |
| 98944 | 98920 | for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ |
| 98921 | + assert( aRegIdx ); |
| 98945 | 98922 | if( openAll || aRegIdx[i]>0 ){ |
| 98946 | 98923 | KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx); |
| 98947 | 98924 | sqlite3VdbeAddOp4(v, OP_OpenWrite, iCur+i+1, pIdx->tnum, iDb, |
| 98948 | 98925 | (char*)pKey, P4_KEYINFO_HANDOFF); |
| 98949 | 98926 | assert( pParse->nTab>iCur+i+1 ); |
| | @@ -99113,10 +99090,11 @@ |
| 99113 | 99090 | sqlite3VdbeAddOp2(v, OP_Goto, 0, addr); |
| 99114 | 99091 | sqlite3VdbeJumpHere(v, addr); |
| 99115 | 99092 | |
| 99116 | 99093 | /* Close all tables */ |
| 99117 | 99094 | for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ |
| 99095 | + assert( aRegIdx ); |
| 99118 | 99096 | if( openAll || aRegIdx[i]>0 ){ |
| 99119 | 99097 | sqlite3VdbeAddOp2(v, OP_Close, iCur+i+1, 0); |
| 99120 | 99098 | } |
| 99121 | 99099 | } |
| 99122 | 99100 | sqlite3VdbeAddOp2(v, OP_Close, iCur, 0); |
| | @@ -103144,11 +103122,10 @@ |
| 103144 | 103122 | assert( roundUp==0 || roundUp==1 ); |
| 103145 | 103123 | assert( pIdx->nSample>0 ); |
| 103146 | 103124 | if( pVal==0 ) return SQLITE_ERROR; |
| 103147 | 103125 | n = pIdx->aiRowEst[0]; |
| 103148 | 103126 | aSample = pIdx->aSample; |
| 103149 | | - i = 0; |
| 103150 | 103127 | eType = sqlite3_value_type(pVal); |
| 103151 | 103128 | |
| 103152 | 103129 | if( eType==SQLITE_INTEGER ){ |
| 103153 | 103130 | v = sqlite3_value_int64(pVal); |
| 103154 | 103131 | r = (i64)v; |
| | @@ -105564,11 +105541,12 @@ |
| 105564 | 105541 | assert( bestJ>=0 ); |
| 105565 | 105542 | assert( notReady & getMask(pMaskSet, pTabList->a[bestJ].iCursor) ); |
| 105566 | 105543 | WHERETRACE(("*** Optimizer selects table %d for loop %d" |
| 105567 | 105544 | " with cost=%g and nRow=%g\n", |
| 105568 | 105545 | bestJ, pLevel-pWInfo->a, bestPlan.rCost, bestPlan.plan.nRow)); |
| 105569 | | - if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){ |
| 105546 | + /* The ALWAYS() that follows was added to hush up clang scan-build */ |
| 105547 | + if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 && ALWAYS(ppOrderBy) ){ |
| 105570 | 105548 | *ppOrderBy = 0; |
| 105571 | 105549 | } |
| 105572 | 105550 | if( (bestPlan.plan.wsFlags & WHERE_DISTINCT)!=0 ){ |
| 105573 | 105551 | assert( pWInfo->eDistinct==0 ); |
| 105574 | 105552 | pWInfo->eDistinct = WHERE_DISTINCT_ORDERED; |
| | @@ -109180,11 +109158,13 @@ |
| 109180 | 109158 | sqlite3ParserTOKENTYPE yyminor /* The value for the token */ |
| 109181 | 109159 | sqlite3ParserARG_PDECL /* Optional %extra_argument parameter */ |
| 109182 | 109160 | ){ |
| 109183 | 109161 | YYMINORTYPE yyminorunion; |
| 109184 | 109162 | int yyact; /* The parser action. */ |
| 109163 | +#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) |
| 109185 | 109164 | int yyendofinput; /* True if we are at the end of input */ |
| 109165 | +#endif |
| 109186 | 109166 | #ifdef YYERRORSYMBOL |
| 109187 | 109167 | int yyerrorhit = 0; /* True if yymajor has invoked an error */ |
| 109188 | 109168 | #endif |
| 109189 | 109169 | yyParser *yypParser; /* The parser */ |
| 109190 | 109170 | |
| | @@ -109203,11 +109183,13 @@ |
| 109203 | 109183 | yypParser->yyerrcnt = -1; |
| 109204 | 109184 | yypParser->yystack[0].stateno = 0; |
| 109205 | 109185 | yypParser->yystack[0].major = 0; |
| 109206 | 109186 | } |
| 109207 | 109187 | yyminorunion.yy0 = yyminor; |
| 109188 | +#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) |
| 109208 | 109189 | yyendofinput = (yymajor==0); |
| 109190 | +#endif |
| 109209 | 109191 | sqlite3ParserARG_STORE; |
| 109210 | 109192 | |
| 109211 | 109193 | #ifndef NDEBUG |
| 109212 | 109194 | if( yyTraceFILE ){ |
| 109213 | 109195 | fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); |
| | @@ -109215,11 +109197,10 @@ |
| 109215 | 109197 | #endif |
| 109216 | 109198 | |
| 109217 | 109199 | do{ |
| 109218 | 109200 | yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); |
| 109219 | 109201 | if( yyact<YYNSTATE ){ |
| 109220 | | - assert( !yyendofinput ); /* Impossible to shift the $ token */ |
| 109221 | 109202 | yy_shift(yypParser,yyact,yymajor,&yyminorunion); |
| 109222 | 109203 | yypParser->yyerrcnt--; |
| 109223 | 109204 | yymajor = YYNOCODE; |
| 109224 | 109205 | }else if( yyact < YYNSTATE + YYNRULE ){ |
| 109225 | 109206 | yy_reduce(yypParser,yyact-YYNSTATE); |
| | @@ -110607,11 +110588,11 @@ |
| 110607 | 110588 | ** |
| 110608 | 110589 | ** * Recursive calls to this routine from thread X return immediately |
| 110609 | 110590 | ** without blocking. |
| 110610 | 110591 | */ |
| 110611 | 110592 | SQLITE_API int sqlite3_initialize(void){ |
| 110612 | | - sqlite3_mutex *pMaster; /* The main static mutex */ |
| 110593 | + MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ |
| 110613 | 110594 | int rc; /* Result code */ |
| 110614 | 110595 | |
| 110615 | 110596 | #ifdef SQLITE_OMIT_WSD |
| 110616 | 110597 | rc = sqlite3_wsd_init(4096, 24); |
| 110617 | 110598 | if( rc!=SQLITE_OK ){ |
| | @@ -110641,11 +110622,11 @@ |
| 110641 | 110622 | ** This operation is protected by the STATIC_MASTER mutex. Note that |
| 110642 | 110623 | ** MutexAlloc() is called for a static mutex prior to initializing the |
| 110643 | 110624 | ** malloc subsystem - this implies that the allocation of a static |
| 110644 | 110625 | ** mutex must not require support from the malloc subsystem. |
| 110645 | 110626 | */ |
| 110646 | | - pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 110627 | + MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 110647 | 110628 | sqlite3_mutex_enter(pMaster); |
| 110648 | 110629 | sqlite3GlobalConfig.isMutexInit = 1; |
| 110649 | 110630 | if( !sqlite3GlobalConfig.isMallocInit ){ |
| 110650 | 110631 | rc = sqlite3MallocInit(); |
| 110651 | 110632 | } |
| | @@ -111715,17 +111696,17 @@ |
| 111715 | 111696 | sqlite3 *db, |
| 111716 | 111697 | const char *zName, |
| 111717 | 111698 | int nArg |
| 111718 | 111699 | ){ |
| 111719 | 111700 | int nName = sqlite3Strlen30(zName); |
| 111720 | | - int rc; |
| 111701 | + int rc = SQLITE_OK; |
| 111721 | 111702 | sqlite3_mutex_enter(db->mutex); |
| 111722 | 111703 | if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){ |
| 111723 | | - sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8, |
| 111724 | | - 0, sqlite3InvalidFunction, 0, 0, 0); |
| 111704 | + rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8, |
| 111705 | + 0, sqlite3InvalidFunction, 0, 0, 0); |
| 111725 | 111706 | } |
| 111726 | | - rc = sqlite3ApiExit(db, SQLITE_OK); |
| 111707 | + rc = sqlite3ApiExit(db, rc); |
| 111727 | 111708 | sqlite3_mutex_leave(db->mutex); |
| 111728 | 111709 | return rc; |
| 111729 | 111710 | } |
| 111730 | 111711 | |
| 111731 | 111712 | #ifndef SQLITE_OMIT_TRACE |
| | @@ -112783,10 +112764,11 @@ |
| 112783 | 112764 | if( db ){ |
| 112784 | 112765 | assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 ); |
| 112785 | 112766 | sqlite3_mutex_leave(db->mutex); |
| 112786 | 112767 | } |
| 112787 | 112768 | rc = sqlite3_errcode(db); |
| 112769 | + assert( db!=0 || rc==SQLITE_NOMEM ); |
| 112788 | 112770 | if( rc==SQLITE_NOMEM ){ |
| 112789 | 112771 | sqlite3_close(db); |
| 112790 | 112772 | db = 0; |
| 112791 | 112773 | }else if( rc!=SQLITE_OK ){ |
| 112792 | 112774 | db->magic = SQLITE_MAGIC_SICK; |
| | @@ -114511,10 +114493,17 @@ |
| 114511 | 114493 | #else |
| 114512 | 114494 | # define TESTONLY(X) |
| 114513 | 114495 | #endif |
| 114514 | 114496 | |
| 114515 | 114497 | #endif /* SQLITE_AMALGAMATION */ |
| 114498 | + |
| 114499 | +#ifdef SQLITE_DEBUG |
| 114500 | +SQLITE_PRIVATE int sqlite3Fts3Corrupt(void); |
| 114501 | +# define FTS_CORRUPT_VTAB sqlite3Fts3Corrupt() |
| 114502 | +#else |
| 114503 | +# define FTS_CORRUPT_VTAB SQLITE_CORRUPT_VTAB |
| 114504 | +#endif |
| 114516 | 114505 | |
| 114517 | 114506 | typedef struct Fts3Table Fts3Table; |
| 114518 | 114507 | typedef struct Fts3Cursor Fts3Cursor; |
| 114519 | 114508 | typedef struct Fts3Expr Fts3Expr; |
| 114520 | 114509 | typedef struct Fts3Phrase Fts3Phrase; |
| | @@ -115012,11 +115001,11 @@ |
| 115012 | 115001 | char **pp, |
| 115013 | 115002 | char *pStart, |
| 115014 | 115003 | sqlite3_int64 *pVal |
| 115015 | 115004 | ){ |
| 115016 | 115005 | sqlite3_int64 iVal; |
| 115017 | | - char *p = *pp; |
| 115006 | + char *p; |
| 115018 | 115007 | |
| 115019 | 115008 | /* Pointer p now points at the first byte past the varint we are |
| 115020 | 115009 | ** interested in. So, unless the doclist is corrupt, the 0x80 bit is |
| 115021 | 115010 | ** clear on character p[-1]. */ |
| 115022 | 115011 | for(p = (*pp)-2; p>=pStart && *p&0x80; p--); |
| | @@ -115413,11 +115402,11 @@ |
| 115413 | 115402 | ** the output value undefined. Otherwise SQLITE_OK is returned. |
| 115414 | 115403 | ** |
| 115415 | 115404 | ** This function is used when parsing the "prefix=" FTS4 parameter. |
| 115416 | 115405 | */ |
| 115417 | 115406 | static int fts3GobbleInt(const char **pp, int *pnOut){ |
| 115418 | | - const char *p = *pp; /* Iterator pointer */ |
| 115407 | + const char *p; /* Iterator pointer */ |
| 115419 | 115408 | int nInt = 0; /* Output value */ |
| 115420 | 115409 | |
| 115421 | 115410 | for(p=*pp; p[0]>='0' && p[0]<='9'; p++){ |
| 115422 | 115411 | nInt = nInt * 10 + (p[0] - '0'); |
| 115423 | 115412 | } |
| | @@ -115912,11 +115901,11 @@ |
| 115912 | 115901 | if( rc==SQLITE_OK ){ |
| 115913 | 115902 | /* If no row was found and no error has occured, then the %_content |
| 115914 | 115903 | ** table is missing a row that is present in the full-text index. |
| 115915 | 115904 | ** The data structures are corrupt. |
| 115916 | 115905 | */ |
| 115917 | | - rc = SQLITE_CORRUPT_VTAB; |
| 115906 | + rc = FTS_CORRUPT_VTAB; |
| 115918 | 115907 | } |
| 115919 | 115908 | pCsr->isEof = 1; |
| 115920 | 115909 | if( pContext ){ |
| 115921 | 115910 | sqlite3_result_error_code(pContext, rc); |
| 115922 | 115911 | } |
| | @@ -115972,11 +115961,11 @@ |
| 115972 | 115961 | ** nNode bytes of content (see sqlite3Fts3ReadBlock() for details). |
| 115973 | 115962 | */ |
| 115974 | 115963 | zCsr += sqlite3Fts3GetVarint(zCsr, &iChild); |
| 115975 | 115964 | zCsr += sqlite3Fts3GetVarint(zCsr, &iChild); |
| 115976 | 115965 | if( zCsr>zEnd ){ |
| 115977 | | - return SQLITE_CORRUPT_VTAB; |
| 115966 | + return FTS_CORRUPT_VTAB; |
| 115978 | 115967 | } |
| 115979 | 115968 | |
| 115980 | 115969 | while( zCsr<zEnd && (piFirst || piLast) ){ |
| 115981 | 115970 | int cmp; /* memcmp() result */ |
| 115982 | 115971 | int nSuffix; /* Size of term suffix */ |
| | @@ -115990,11 +115979,11 @@ |
| 115990 | 115979 | } |
| 115991 | 115980 | isFirstTerm = 0; |
| 115992 | 115981 | zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix); |
| 115993 | 115982 | |
| 115994 | 115983 | if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){ |
| 115995 | | - rc = SQLITE_CORRUPT_VTAB; |
| 115984 | + rc = FTS_CORRUPT_VTAB; |
| 115996 | 115985 | goto finish_scan; |
| 115997 | 115986 | } |
| 115998 | 115987 | if( nPrefix+nSuffix>nAlloc ){ |
| 115999 | 115988 | char *zNew; |
| 116000 | 115989 | nAlloc = (nPrefix+nSuffix) * 2; |
| | @@ -116003,10 +115992,11 @@ |
| 116003 | 115992 | rc = SQLITE_NOMEM; |
| 116004 | 115993 | goto finish_scan; |
| 116005 | 115994 | } |
| 116006 | 115995 | zBuffer = zNew; |
| 116007 | 115996 | } |
| 115997 | + assert( zBuffer ); |
| 116008 | 115998 | memcpy(&zBuffer[nPrefix], zCsr, nSuffix); |
| 116009 | 115999 | nBuffer = nPrefix + nSuffix; |
| 116010 | 116000 | zCsr += nSuffix; |
| 116011 | 116001 | |
| 116012 | 116002 | /* Compare the term we are searching for with the term just loaded from |
| | @@ -117439,11 +117429,11 @@ |
| 117439 | 117429 | ** moves *ppPoslist so that it instead points to the first byte of the |
| 117440 | 117430 | ** same position list. |
| 117441 | 117431 | */ |
| 117442 | 117432 | static void fts3ReversePoslist(char *pStart, char **ppPoslist){ |
| 117443 | 117433 | char *p = &(*ppPoslist)[-2]; |
| 117444 | | - char c; |
| 117434 | + char c = 0; |
| 117445 | 117435 | |
| 117446 | 117436 | while( p>pStart && (c=*p--)==0 ); |
| 117447 | 117437 | while( p>pStart && (*p & 0x80) | c ){ |
| 117448 | 117438 | c = *p--; |
| 117449 | 117439 | } |
| | @@ -118433,11 +118423,11 @@ |
| 118433 | 118423 | while( a<pEnd ){ |
| 118434 | 118424 | a += sqlite3Fts3GetVarint(a, &nByte); |
| 118435 | 118425 | } |
| 118436 | 118426 | if( nDoc==0 || nByte==0 ){ |
| 118437 | 118427 | sqlite3_reset(pStmt); |
| 118438 | | - return SQLITE_CORRUPT_VTAB; |
| 118428 | + return FTS_CORRUPT_VTAB; |
| 118439 | 118429 | } |
| 118440 | 118430 | |
| 118441 | 118431 | pCsr->nDoc = nDoc; |
| 118442 | 118432 | pCsr->nRowAvg = (int)(((nByte / nDoc) + p->nPgsz) / p->nPgsz); |
| 118443 | 118433 | assert( pCsr->nRowAvg>0 ); |
| | @@ -118909,12 +118899,15 @@ |
| 118909 | 118899 | } |
| 118910 | 118900 | |
| 118911 | 118901 | aPoslist = pExpr->pRight->pPhrase->doclist.pList; |
| 118912 | 118902 | nToken = pExpr->pRight->pPhrase->nToken; |
| 118913 | 118903 | for(p=pExpr->pLeft; p && res; p=p->pLeft){ |
| 118914 | | - int nNear = p->pParent->nNear; |
| 118915 | | - Fts3Phrase *pPhrase = ( |
| 118904 | + int nNear; |
| 118905 | + Fts3Phrase *pPhrase; |
| 118906 | + assert( p->pParent && p->pParent->pLeft==p ); |
| 118907 | + nNear = p->pParent->nNear; |
| 118908 | + pPhrase = ( |
| 118916 | 118909 | p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase |
| 118917 | 118910 | ); |
| 118918 | 118911 | res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase); |
| 118919 | 118912 | } |
| 118920 | 118913 | } |
| | @@ -119400,10 +119393,19 @@ |
| 119400 | 119393 | pPhrase->aToken[i].pSegcsr = 0; |
| 119401 | 119394 | } |
| 119402 | 119395 | } |
| 119403 | 119396 | } |
| 119404 | 119397 | |
| 119398 | +/* |
| 119399 | +** Return SQLITE_CORRUPT_VTAB. |
| 119400 | +*/ |
| 119401 | +#ifdef SQLITE_DEBUG |
| 119402 | +SQLITE_PRIVATE int sqlite3Fts3Corrupt(){ |
| 119403 | + return SQLITE_CORRUPT_VTAB; |
| 119404 | +} |
| 119405 | +#endif |
| 119406 | + |
| 119405 | 119407 | #if !SQLITE_CORE |
| 119406 | 119408 | /* |
| 119407 | 119409 | ** Initialize API pointer table, if required. |
| 119408 | 119410 | */ |
| 119409 | 119411 | SQLITE_API int sqlite3_extension_init( |
| | @@ -120197,12 +120199,16 @@ |
| 120197 | 120199 | p->pPhrase = (Fts3Phrase *)&p[1]; |
| 120198 | 120200 | p->pPhrase->iColumn = pParse->iDefaultCol; |
| 120199 | 120201 | p->pPhrase->nToken = nToken; |
| 120200 | 120202 | |
| 120201 | 120203 | zBuf = (char *)&p->pPhrase->aToken[nToken]; |
| 120202 | | - memcpy(zBuf, zTemp, nTemp); |
| 120203 | | - sqlite3_free(zTemp); |
| 120204 | + if( zTemp ){ |
| 120205 | + memcpy(zBuf, zTemp, nTemp); |
| 120206 | + sqlite3_free(zTemp); |
| 120207 | + }else{ |
| 120208 | + assert( nTemp==0 ); |
| 120209 | + } |
| 120204 | 120210 | |
| 120205 | 120211 | for(jj=0; jj<p->pPhrase->nToken; jj++){ |
| 120206 | 120212 | p->pPhrase->aToken[jj].z = zBuf; |
| 120207 | 120213 | zBuf += p->pPhrase->aToken[jj].n; |
| 120208 | 120214 | } |
| | @@ -122957,11 +122963,11 @@ |
| 122957 | 122963 | sqlite3_bind_int64(pStmt, 1, iDocid); |
| 122958 | 122964 | } |
| 122959 | 122965 | rc = sqlite3_step(pStmt); |
| 122960 | 122966 | if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){ |
| 122961 | 122967 | rc = sqlite3_reset(pStmt); |
| 122962 | | - if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT_VTAB; |
| 122968 | + if( rc==SQLITE_OK ) rc = FTS_CORRUPT_VTAB; |
| 122963 | 122969 | pStmt = 0; |
| 122964 | 122970 | }else{ |
| 122965 | 122971 | rc = SQLITE_OK; |
| 122966 | 122972 | } |
| 122967 | 122973 | } |
| | @@ -123761,11 +123767,11 @@ |
| 123761 | 123767 | pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix); |
| 123762 | 123768 | pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix); |
| 123763 | 123769 | if( nPrefix<0 || nSuffix<=0 |
| 123764 | 123770 | || &pNext[nSuffix]>&pReader->aNode[pReader->nNode] |
| 123765 | 123771 | ){ |
| 123766 | | - return SQLITE_CORRUPT_VTAB; |
| 123772 | + return FTS_CORRUPT_VTAB; |
| 123767 | 123773 | } |
| 123768 | 123774 | |
| 123769 | 123775 | if( nPrefix+nSuffix>pReader->nTermAlloc ){ |
| 123770 | 123776 | int nNew = (nPrefix+nSuffix)*2; |
| 123771 | 123777 | char *zNew = sqlite3_realloc(pReader->zTerm, nNew); |
| | @@ -123791,11 +123797,11 @@ |
| 123791 | 123797 | ** of these statements is untrue, then the data structure is corrupt. |
| 123792 | 123798 | */ |
| 123793 | 123799 | if( &pReader->aDoclist[pReader->nDoclist]>&pReader->aNode[pReader->nNode] |
| 123794 | 123800 | || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1]) |
| 123795 | 123801 | ){ |
| 123796 | | - return SQLITE_CORRUPT_VTAB; |
| 123802 | + return FTS_CORRUPT_VTAB; |
| 123797 | 123803 | } |
| 123798 | 123804 | return SQLITE_OK; |
| 123799 | 123805 | } |
| 123800 | 123806 | |
| 123801 | 123807 | /* |
| | @@ -125745,11 +125751,10 @@ |
| 125745 | 125751 | sqlite_int64 *pRowid /* OUT: The affected (or effected) rowid */ |
| 125746 | 125752 | ){ |
| 125747 | 125753 | Fts3Table *p = (Fts3Table *)pVtab; |
| 125748 | 125754 | int rc = SQLITE_OK; /* Return Code */ |
| 125749 | 125755 | int isRemove = 0; /* True for an UPDATE or DELETE */ |
| 125750 | | - sqlite3_int64 iRemove = 0; /* Rowid removed by UPDATE or DELETE */ |
| 125751 | 125756 | u32 *aSzIns = 0; /* Sizes of inserted documents */ |
| 125752 | 125757 | u32 *aSzDel; /* Sizes of deleted documents */ |
| 125753 | 125758 | int nChng = 0; /* Net change in number of documents */ |
| 125754 | 125759 | int bInsertDone = 0; |
| 125755 | 125760 | |
| | @@ -125828,23 +125833,23 @@ |
| 125828 | 125833 | /* If this is a DELETE or UPDATE operation, remove the old record. */ |
| 125829 | 125834 | if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){ |
| 125830 | 125835 | assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER ); |
| 125831 | 125836 | rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel); |
| 125832 | 125837 | isRemove = 1; |
| 125833 | | - iRemove = sqlite3_value_int64(apVal[0]); |
| 125834 | 125838 | } |
| 125835 | 125839 | |
| 125836 | 125840 | /* If this is an INSERT or UPDATE operation, insert the new record. */ |
| 125837 | 125841 | if( nArg>1 && rc==SQLITE_OK ){ |
| 125838 | 125842 | if( bInsertDone==0 ){ |
| 125839 | 125843 | rc = fts3InsertData(p, apVal, pRowid); |
| 125840 | | - if( rc==SQLITE_CONSTRAINT ) rc = SQLITE_CORRUPT_VTAB; |
| 125844 | + if( rc==SQLITE_CONSTRAINT ) rc = FTS_CORRUPT_VTAB; |
| 125841 | 125845 | } |
| 125842 | | - if( rc==SQLITE_OK && (!isRemove || *pRowid!=iRemove) ){ |
| 125846 | + if( rc==SQLITE_OK && (!isRemove || *pRowid!=p->iPrevDocid ) ){ |
| 125843 | 125847 | rc = fts3PendingTermsDocid(p, *pRowid); |
| 125844 | 125848 | } |
| 125845 | 125849 | if( rc==SQLITE_OK ){ |
| 125850 | + assert( p->iPrevDocid==*pRowid ); |
| 125846 | 125851 | rc = fts3InsertTerms(p, apVal, aSzIns); |
| 125847 | 125852 | } |
| 125848 | 125853 | if( p->bHasDocsize ){ |
| 125849 | 125854 | fts3InsertDocsize(&rc, p, aSzIns); |
| 125850 | 125855 | } |
| | @@ -126734,11 +126739,11 @@ |
| 126734 | 126739 | pStmt = *ppStmt; |
| 126735 | 126740 | assert( sqlite3_data_count(pStmt)==1 ); |
| 126736 | 126741 | |
| 126737 | 126742 | a = sqlite3_column_blob(pStmt, 0); |
| 126738 | 126743 | a += sqlite3Fts3GetVarint(a, &nDoc); |
| 126739 | | - if( nDoc==0 ) return SQLITE_CORRUPT_VTAB; |
| 126744 | + if( nDoc==0 ) return FTS_CORRUPT_VTAB; |
| 126740 | 126745 | *pnDoc = (u32)nDoc; |
| 126741 | 126746 | |
| 126742 | 126747 | if( paLen ) *paLen = a; |
| 126743 | 126748 | return SQLITE_OK; |
| 126744 | 126749 | } |
| | @@ -127313,11 +127318,11 @@ |
| 127313 | 127318 | sqlite3_snprintf(sizeof(aBuffer), aBuffer, |
| 127314 | 127319 | "%d %d %d %d ", iCol, pTerm-sCtx.aTerm, iStart, iEnd-iStart |
| 127315 | 127320 | ); |
| 127316 | 127321 | rc = fts3StringAppend(&res, aBuffer, -1); |
| 127317 | 127322 | }else if( rc==SQLITE_DONE ){ |
| 127318 | | - rc = SQLITE_CORRUPT_VTAB; |
| 127323 | + rc = FTS_CORRUPT_VTAB; |
| 127319 | 127324 | } |
| 127320 | 127325 | } |
| 127321 | 127326 | } |
| 127322 | 127327 | if( rc==SQLITE_DONE ){ |
| 127323 | 127328 | rc = SQLITE_OK; |
| | @@ -128654,11 +128659,12 @@ |
| 128654 | 128659 | pCsr->nConstraint = argc; |
| 128655 | 128660 | if( !pCsr->aConstraint ){ |
| 128656 | 128661 | rc = SQLITE_NOMEM; |
| 128657 | 128662 | }else{ |
| 128658 | 128663 | memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc); |
| 128659 | | - assert( (idxStr==0 && argc==0) || (int)strlen(idxStr)==argc*2 ); |
| 128664 | + assert( (idxStr==0 && argc==0) |
| 128665 | + || (idxStr && (int)strlen(idxStr)==argc*2) ); |
| 128660 | 128666 | for(ii=0; ii<argc; ii++){ |
| 128661 | 128667 | RtreeConstraint *p = &pCsr->aConstraint[ii]; |
| 128662 | 128668 | p->op = idxStr[ii*2]; |
| 128663 | 128669 | p->iCoord = idxStr[ii*2+1]-'a'; |
| 128664 | 128670 | if( p->op==RTREE_MATCH ){ |
| | @@ -128955,11 +128961,14 @@ |
| 128955 | 128961 | int iCell; |
| 128956 | 128962 | sqlite3_int64 iBest = 0; |
| 128957 | 128963 | |
| 128958 | 128964 | float fMinGrowth = 0.0; |
| 128959 | 128965 | float fMinArea = 0.0; |
| 128966 | +#if VARIANT_RSTARTREE_CHOOSESUBTREE |
| 128960 | 128967 | float fMinOverlap = 0.0; |
| 128968 | + float overlap; |
| 128969 | +#endif |
| 128961 | 128970 | |
| 128962 | 128971 | int nCell = NCELL(pNode); |
| 128963 | 128972 | RtreeCell cell; |
| 128964 | 128973 | RtreeNode *pChild; |
| 128965 | 128974 | |
| | @@ -128987,33 +128996,34 @@ |
| 128987 | 128996 | */ |
| 128988 | 128997 | for(iCell=0; iCell<nCell; iCell++){ |
| 128989 | 128998 | int bBest = 0; |
| 128990 | 128999 | float growth; |
| 128991 | 129000 | float area; |
| 128992 | | - float overlap = 0.0; |
| 128993 | 129001 | nodeGetCell(pRtree, pNode, iCell, &cell); |
| 128994 | 129002 | growth = cellGrowth(pRtree, &cell, pCell); |
| 128995 | 129003 | area = cellArea(pRtree, &cell); |
| 128996 | 129004 | |
| 128997 | 129005 | #if VARIANT_RSTARTREE_CHOOSESUBTREE |
| 128998 | 129006 | if( ii==(pRtree->iDepth-1) ){ |
| 128999 | 129007 | overlap = cellOverlapEnlargement(pRtree,&cell,pCell,aCell,nCell,iCell); |
| 129008 | + }else{ |
| 129009 | + overlap = 0.0; |
| 129000 | 129010 | } |
| 129001 | 129011 | if( (iCell==0) |
| 129002 | 129012 | || (overlap<fMinOverlap) |
| 129003 | 129013 | || (overlap==fMinOverlap && growth<fMinGrowth) |
| 129004 | 129014 | || (overlap==fMinOverlap && growth==fMinGrowth && area<fMinArea) |
| 129005 | 129015 | ){ |
| 129006 | 129016 | bBest = 1; |
| 129017 | + fMinOverlap = overlap; |
| 129007 | 129018 | } |
| 129008 | 129019 | #else |
| 129009 | 129020 | if( iCell==0||growth<fMinGrowth||(growth==fMinGrowth && area<fMinArea) ){ |
| 129010 | 129021 | bBest = 1; |
| 129011 | 129022 | } |
| 129012 | 129023 | #endif |
| 129013 | 129024 | if( bBest ){ |
| 129014 | | - fMinOverlap = overlap; |
| 129015 | 129025 | fMinGrowth = growth; |
| 129016 | 129026 | fMinArea = area; |
| 129017 | 129027 | iBest = cell.iRowid; |
| 129018 | 129028 | } |
| 129019 | 129029 | } |
| 129020 | 129030 | |