| | @@ -657,11 +657,11 @@ |
| 657 | 657 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 658 | 658 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 659 | 659 | */ |
| 660 | 660 | #define SQLITE_VERSION "3.7.10" |
| 661 | 661 | #define SQLITE_VERSION_NUMBER 3007010 |
| 662 | | -#define SQLITE_SOURCE_ID "2011-12-23 13:32:07 1f24ae716df6232de768e245ea990049deee3c22" |
| 662 | +#define SQLITE_SOURCE_ID "2012-01-05 12:38:02 1378f905d37544701776d38987fe7a312b255983" |
| 663 | 663 | |
| 664 | 664 | /* |
| 665 | 665 | ** CAPI3REF: Run-Time Library Version Numbers |
| 666 | 666 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 667 | 667 | ** |
| | @@ -725,11 +725,11 @@ |
| 725 | 725 | |
| 726 | 726 | /* |
| 727 | 727 | ** CAPI3REF: Test To See If The Library Is Threadsafe |
| 728 | 728 | ** |
| 729 | 729 | ** ^The sqlite3_threadsafe() function returns zero if and only if |
| 730 | | -** SQLite was compiled mutexing code omitted due to the |
| 730 | +** SQLite was compiled with mutexing code omitted due to the |
| 731 | 731 | ** [SQLITE_THREADSAFE] compile-time option being set to 0. |
| 732 | 732 | ** |
| 733 | 733 | ** SQLite can be compiled with or without mutexes. When |
| 734 | 734 | ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes |
| 735 | 735 | ** are enabled and SQLite is threadsafe. When the |
| | @@ -919,11 +919,11 @@ |
| 919 | 919 | ** CAPI3REF: Result Codes |
| 920 | 920 | ** KEYWORDS: SQLITE_OK {error code} {error codes} |
| 921 | 921 | ** KEYWORDS: {result code} {result codes} |
| 922 | 922 | ** |
| 923 | 923 | ** Many SQLite functions return an integer result code from the set shown |
| 924 | | -** here in order to indicates success or failure. |
| 924 | +** here in order to indicate success or failure. |
| 925 | 925 | ** |
| 926 | 926 | ** New error codes may be added in future versions of SQLite. |
| 927 | 927 | ** |
| 928 | 928 | ** See also: [SQLITE_IOERR_READ | extended result codes], |
| 929 | 929 | ** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. |
| | @@ -1058,17 +1058,14 @@ |
| 1058 | 1058 | ** that when data is appended to a file, the data is appended |
| 1059 | 1059 | ** first then the size of the file is extended, never the other |
| 1060 | 1060 | ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that |
| 1061 | 1061 | ** information is written to disk in the same order as calls |
| 1062 | 1062 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 1063 | | -** after reboot following a crash or power loss, the value of |
| 1064 | | -** each byte in a file is a value that was actually written |
| 1065 | | -** into that byte at some point. In other words, a crash will |
| 1066 | | -** not cause unwritten bytes of the file to change nor introduce |
| 1067 | | -** randomness into a file nor zero out parts of the file, and any byte of |
| 1068 | | -** a file that are never written will not change values due to |
| 1069 | | -** writes to nearby bytes. |
| 1063 | +** after reboot following a crash or power loss, the only bytes in a |
| 1064 | +** file that were written at the application level might have changed |
| 1065 | +** and that adjacent bytes, even bytes within the same sector are |
| 1066 | +** guaranteed to be unchanged. |
| 1070 | 1067 | */ |
| 1071 | 1068 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| 1072 | 1069 | #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
| 1073 | 1070 | #define SQLITE_IOCAP_ATOMIC1K 0x00000004 |
| 1074 | 1071 | #define SQLITE_IOCAP_ATOMIC2K 0x00000008 |
| | @@ -1300,16 +1297,16 @@ |
| 1300 | 1297 | ** opcode as doing so may disrupt the operation of the specialized VFSes |
| 1301 | 1298 | ** that do require it. |
| 1302 | 1299 | ** |
| 1303 | 1300 | ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic |
| 1304 | 1301 | ** retry counts and intervals for certain disk I/O operations for the |
| 1305 | | -** windows [VFS] in order to work to provide robustness against |
| 1302 | +** windows [VFS] in order to provide robustness in the presence of |
| 1306 | 1303 | ** anti-virus programs. By default, the windows VFS will retry file read, |
| 1307 | 1304 | ** file write, and file delete operations up to 10 times, with a delay |
| 1308 | 1305 | ** of 25 milliseconds before the first retry and with the delay increasing |
| 1309 | 1306 | ** by an additional 25 milliseconds with each subsequent retry. This |
| 1310 | | -** opcode allows those to values (10 retries and 25 milliseconds of delay) |
| 1307 | +** opcode allows these two values (10 retries and 25 milliseconds of delay) |
| 1311 | 1308 | ** to be adjusted. The values are changed for all database connections |
| 1312 | 1309 | ** within the same process. The argument is a pointer to an array of two |
| 1313 | 1310 | ** integers where the first integer i the new retry count and the second |
| 1314 | 1311 | ** integer is the delay. If either integer is negative, then the setting |
| 1315 | 1312 | ** is not changed but instead the prior value of that setting is written |
| | @@ -1420,11 +1417,11 @@ |
| 1420 | 1417 | ** ^SQLite guarantees that the zFilename parameter to xOpen |
| 1421 | 1418 | ** is either a NULL pointer or string obtained |
| 1422 | 1419 | ** from xFullPathname() with an optional suffix added. |
| 1423 | 1420 | ** ^If a suffix is added to the zFilename parameter, it will |
| 1424 | 1421 | ** consist of a single "-" character followed by no more than |
| 1425 | | -** 10 alphanumeric and/or "-" characters. |
| 1422 | +** 11 alphanumeric and/or "-" characters. |
| 1426 | 1423 | ** ^SQLite further guarantees that |
| 1427 | 1424 | ** the string will be valid and unchanged until xClose() is |
| 1428 | 1425 | ** called. Because of the previous sentence, |
| 1429 | 1426 | ** the [sqlite3_file] can safely store a pointer to the |
| 1430 | 1427 | ** filename if it needs to remember the filename for some reason. |
| | @@ -2571,11 +2568,11 @@ |
| 2571 | 2568 | ** These routines all implement some additional formatting |
| 2572 | 2569 | ** options that are useful for constructing SQL statements. |
| 2573 | 2570 | ** All of the usual printf() formatting options apply. In addition, there |
| 2574 | 2571 | ** is are "%q", "%Q", and "%z" options. |
| 2575 | 2572 | ** |
| 2576 | | -** ^(The %q option works like %s in that it substitutes a null-terminated |
| 2573 | +** ^(The %q option works like %s in that it substitutes a nul-terminated |
| 2577 | 2574 | ** string from the argument list. But %q also doubles every '\'' character. |
| 2578 | 2575 | ** %q is designed for use inside a string literal.)^ By doubling each '\'' |
| 2579 | 2576 | ** character it escapes that character and allows it to be inserted into |
| 2580 | 2577 | ** the string. |
| 2581 | 2578 | ** |
| | @@ -4091,11 +4088,11 @@ |
| 4091 | 4088 | ** of the string. ^For clarity: the values returned by |
| 4092 | 4089 | ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of |
| 4093 | 4090 | ** bytes in the string, not the number of characters. |
| 4094 | 4091 | ** |
| 4095 | 4092 | ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), |
| 4096 | | -** even empty strings, are always zero terminated. ^The return |
| 4093 | +** even empty strings, are always zero-terminated. ^The return |
| 4097 | 4094 | ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. |
| 4098 | 4095 | ** |
| 4099 | 4096 | ** ^The object returned by [sqlite3_column_value()] is an |
| 4100 | 4097 | ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object |
| 4101 | 4098 | ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()]. |
| | @@ -5171,11 +5168,11 @@ |
| 5171 | 5168 | SQLITE_API int sqlite3_release_memory(int); |
| 5172 | 5169 | |
| 5173 | 5170 | /* |
| 5174 | 5171 | ** CAPI3REF: Free Memory Used By A Database Connection |
| 5175 | 5172 | ** |
| 5176 | | -** ^The sqlite3_db_shrink(D) interface attempts to free as much heap |
| 5173 | +** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap |
| 5177 | 5174 | ** memory as possible from database connection D. Unlike the |
| 5178 | 5175 | ** [sqlite3_release_memory()] interface, this interface is effect even |
| 5179 | 5176 | ** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is |
| 5180 | 5177 | ** omitted. |
| 5181 | 5178 | ** |
| | @@ -5954,19 +5951,19 @@ |
| 5954 | 5951 | ** is selected automatically at compile-time. ^(The following |
| 5955 | 5952 | ** implementations are available in the SQLite core: |
| 5956 | 5953 | ** |
| 5957 | 5954 | ** <ul> |
| 5958 | 5955 | ** <li> SQLITE_MUTEX_OS2 |
| 5959 | | -** <li> SQLITE_MUTEX_PTHREAD |
| 5956 | +** <li> SQLITE_MUTEX_PTHREADS |
| 5960 | 5957 | ** <li> SQLITE_MUTEX_W32 |
| 5961 | 5958 | ** <li> SQLITE_MUTEX_NOOP |
| 5962 | 5959 | ** </ul>)^ |
| 5963 | 5960 | ** |
| 5964 | 5961 | ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines |
| 5965 | 5962 | ** that does no real locking and is appropriate for use in |
| 5966 | 5963 | ** a single-threaded application. ^The SQLITE_MUTEX_OS2, |
| 5967 | | -** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations |
| 5964 | +** SQLITE_MUTEX_PTHREADS, and SQLITE_MUTEX_W32 implementations |
| 5968 | 5965 | ** are appropriate for use on OS/2, Unix, and Windows. |
| 5969 | 5966 | ** |
| 5970 | 5967 | ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor |
| 5971 | 5968 | ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex |
| 5972 | 5969 | ** implementation is included with the library. In this case the |
| | @@ -6152,11 +6149,11 @@ |
| 6152 | 6149 | ** defined and if NDEBUG is not defined. |
| 6153 | 6150 | ** |
| 6154 | 6151 | ** ^These routines should return true if the mutex in their argument |
| 6155 | 6152 | ** is held or not held, respectively, by the calling thread. |
| 6156 | 6153 | ** |
| 6157 | | -** ^The implementation is not required to provided versions of these |
| 6154 | +** ^The implementation is not required to provide versions of these |
| 6158 | 6155 | ** routines that actually work. If the implementation does not provide working |
| 6159 | 6156 | ** versions of these routines, it should at least provide stubs that always |
| 6160 | 6157 | ** return true so that one does not get spurious assertion failures. |
| 6161 | 6158 | ** |
| 6162 | 6159 | ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then |
| | @@ -6634,11 +6631,11 @@ |
| 6634 | 6631 | ** |
| 6635 | 6632 | ** [[the xInit() page cache method]] |
| 6636 | 6633 | ** ^(The xInit() method is called once for each effective |
| 6637 | 6634 | ** call to [sqlite3_initialize()])^ |
| 6638 | 6635 | ** (usually only once during the lifetime of the process). ^(The xInit() |
| 6639 | | -** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ |
| 6636 | +** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^ |
| 6640 | 6637 | ** The intent of the xInit() method is to set up global data structures |
| 6641 | 6638 | ** required by the custom page cache implementation. |
| 6642 | 6639 | ** ^(If the xInit() method is NULL, then the |
| 6643 | 6640 | ** built-in default page cache is used instead of the application defined |
| 6644 | 6641 | ** page cache.)^ |
| | @@ -6660,11 +6657,11 @@ |
| 6660 | 6657 | ** |
| 6661 | 6658 | ** [[the xCreate() page cache methods]] |
| 6662 | 6659 | ** ^SQLite invokes the xCreate() method to construct a new cache instance. |
| 6663 | 6660 | ** SQLite will typically create one cache instance for each open database file, |
| 6664 | 6661 | ** though this is not guaranteed. ^The |
| 6665 | | -** parameter parameter, szPage, is the size in bytes of the pages that must |
| 6662 | +** first parameter, szPage, is the size in bytes of the pages that must |
| 6666 | 6663 | ** be allocated by the cache. ^szPage will always a power of two. ^The |
| 6667 | 6664 | ** second parameter szExtra is a number of bytes of extra storage |
| 6668 | 6665 | ** associated with each page cache entry. ^The szExtra parameter will |
| 6669 | 6666 | ** a number less than 250. SQLite will use the |
| 6670 | 6667 | ** extra szExtra bytes on each page to store metadata about the underlying |
| | @@ -6755,11 +6752,11 @@ |
| 6755 | 6752 | ** |
| 6756 | 6753 | ** [[the xDestroy() page cache method]] |
| 6757 | 6754 | ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). |
| 6758 | 6755 | ** All resources associated with the specified cache should be freed. ^After |
| 6759 | 6756 | ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] |
| 6760 | | -** handle invalid, and will not use it with any other sqlite3_pcache_methods |
| 6757 | +** handle invalid, and will not use it with any other sqlite3_pcache_methods2 |
| 6761 | 6758 | ** functions. |
| 6762 | 6759 | ** |
| 6763 | 6760 | ** [[the xShrink() page cache method]] |
| 6764 | 6761 | ** ^SQLite invokes the xShrink() method when it wants the page cache to |
| 6765 | 6762 | ** free up as much of heap memory as possible. The page cache implementation |
| | @@ -9266,11 +9263,11 @@ |
| 9266 | 9263 | |
| 9267 | 9264 | /* |
| 9268 | 9265 | ** The default size of a disk sector |
| 9269 | 9266 | */ |
| 9270 | 9267 | #ifndef SQLITE_DEFAULT_SECTOR_SIZE |
| 9271 | | -# define SQLITE_DEFAULT_SECTOR_SIZE 512 |
| 9268 | +# define SQLITE_DEFAULT_SECTOR_SIZE 4096 |
| 9272 | 9269 | #endif |
| 9273 | 9270 | |
| 9274 | 9271 | /* |
| 9275 | 9272 | ** Temporary files are named starting with this prefix followed by 16 random |
| 9276 | 9273 | ** alphanumeric characters, and no file extension. They are stored in the |
| | @@ -13190,11 +13187,11 @@ |
| 13190 | 13187 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); |
| 13191 | 13188 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); |
| 13192 | 13189 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*); |
| 13193 | 13190 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); |
| 13194 | 13191 | SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p); |
| 13195 | | -#define MemReleaseExt(X) \ |
| 13192 | +#define VdbeMemRelease(X) \ |
| 13196 | 13193 | if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \ |
| 13197 | 13194 | sqlite3VdbeMemReleaseExternal(X); |
| 13198 | 13195 | SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); |
| 13199 | 13196 | SQLITE_PRIVATE const char *sqlite3OpcodeName(int); |
| 13200 | 13197 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); |
| | @@ -13229,11 +13226,11 @@ |
| 13229 | 13226 | # define sqlite3VdbeEnter(X) |
| 13230 | 13227 | # define sqlite3VdbeLeave(X) |
| 13231 | 13228 | #endif |
| 13232 | 13229 | |
| 13233 | 13230 | #ifdef SQLITE_DEBUG |
| 13234 | | -SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*); |
| 13231 | +SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*); |
| 13235 | 13232 | #endif |
| 13236 | 13233 | |
| 13237 | 13234 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 13238 | 13235 | SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int); |
| 13239 | 13236 | #else |
| | @@ -14762,11 +14759,11 @@ |
| 14762 | 14759 | int flags, |
| 14763 | 14760 | int *pFlagsOut |
| 14764 | 14761 | ){ |
| 14765 | 14762 | int rc; |
| 14766 | 14763 | DO_OS_MALLOC_TEST(0); |
| 14767 | | - /* 0x87f3f is a mask of SQLITE_OPEN_ flags that are valid to be passed |
| 14764 | + /* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed |
| 14768 | 14765 | ** down into the VFS layer. Some SQLITE_OPEN_ flags (for example, |
| 14769 | 14766 | ** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before |
| 14770 | 14767 | ** reaching the VFS. */ |
| 14771 | 14768 | rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x87f7f, pFlagsOut); |
| 14772 | 14769 | assert( rc==SQLITE_OK || pFile->pMethods==0 ); |
| | @@ -17316,11 +17313,11 @@ |
| 17316 | 17313 | SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex *p){ |
| 17317 | 17314 | return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); |
| 17318 | 17315 | } |
| 17319 | 17316 | #endif |
| 17320 | 17317 | |
| 17321 | | -#endif /* SQLITE_MUTEX_OMIT */ |
| 17318 | +#endif /* !defined(SQLITE_MUTEX_OMIT) */ |
| 17322 | 17319 | |
| 17323 | 17320 | /************** End of mutex.c ***********************************************/ |
| 17324 | 17321 | /************** Begin file mutex_noop.c **************************************/ |
| 17325 | 17322 | /* |
| 17326 | 17323 | ** 2008 October 07 |
| | @@ -17523,12 +17520,12 @@ |
| 17523 | 17520 | */ |
| 17524 | 17521 | #ifdef SQLITE_MUTEX_NOOP |
| 17525 | 17522 | SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){ |
| 17526 | 17523 | return sqlite3NoopMutex(); |
| 17527 | 17524 | } |
| 17528 | | -#endif /* SQLITE_MUTEX_NOOP */ |
| 17529 | | -#endif /* SQLITE_MUTEX_OMIT */ |
| 17525 | +#endif /* defined(SQLITE_MUTEX_NOOP) */ |
| 17526 | +#endif /* !defined(SQLITE_MUTEX_OMIT) */ |
| 17530 | 17527 | |
| 17531 | 17528 | /************** End of mutex_noop.c ******************************************/ |
| 17532 | 17529 | /************** Begin file mutex_os2.c ***************************************/ |
| 17533 | 17530 | /* |
| 17534 | 17531 | ** 2007 August 28 |
| | @@ -18153,11 +18150,11 @@ |
| 18153 | 18150 | }; |
| 18154 | 18151 | |
| 18155 | 18152 | return &sMutex; |
| 18156 | 18153 | } |
| 18157 | 18154 | |
| 18158 | | -#endif /* SQLITE_MUTEX_PTHREAD */ |
| 18155 | +#endif /* SQLITE_MUTEX_PTHREADS */ |
| 18159 | 18156 | |
| 18160 | 18157 | /************** End of mutex_unix.c ******************************************/ |
| 18161 | 18158 | /************** Begin file mutex_w32.c ***************************************/ |
| 18162 | 18159 | /* |
| 18163 | 18160 | ** 2007 August 14 |
| | @@ -22116,26 +22113,31 @@ |
| 22116 | 22113 | ** characters of the original suffix. |
| 22117 | 22114 | ** |
| 22118 | 22115 | ** If SQLITE_ENABLE_8_3_NAMES is set to 2 at compile-time, then always |
| 22119 | 22116 | ** do the suffix shortening regardless of URI parameter. |
| 22120 | 22117 | ** |
| 22118 | +** Assume that zBaseFilename contains two \000 terminator bytes (so that |
| 22119 | +** it can be harmlessly passed into sqlite3_uri_parameter()) and copy both |
| 22120 | +** zero terminator bytes into the end of the revised name. |
| 22121 | +** |
| 22121 | 22122 | ** Examples: |
| 22122 | 22123 | ** |
| 22123 | 22124 | ** test.db-journal => test.nal |
| 22124 | 22125 | ** test.db-wal => test.wal |
| 22125 | 22126 | ** test.db-shm => test.shm |
| 22126 | 22127 | ** test.db-mj7f3319fa => test.9fa |
| 22127 | 22128 | */ |
| 22128 | 22129 | SQLITE_PRIVATE void sqlite3FileSuffix3(const char *zBaseFilename, char *z){ |
| 22130 | + assert( zBaseFilename[strlen(zBaseFilename)+1]==0 ); |
| 22129 | 22131 | #if SQLITE_ENABLE_8_3_NAMES<2 |
| 22130 | | - if( sqlite3_uri_boolean(zBaseFilename, "8_3_names") ) |
| 22132 | + if( sqlite3_uri_boolean(zBaseFilename, "8_3_names", 0) ) |
| 22131 | 22133 | #endif |
| 22132 | 22134 | { |
| 22133 | 22135 | int i, sz; |
| 22134 | 22136 | sz = sqlite3Strlen30(z); |
| 22135 | 22137 | for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){} |
| 22136 | | - if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 4); |
| 22138 | + if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 5); |
| 22137 | 22139 | } |
| 22138 | 22140 | } |
| 22139 | 22141 | #endif |
| 22140 | 22142 | |
| 22141 | 22143 | /************** End of util.c ************************************************/ |
| | @@ -24836,13 +24838,10 @@ |
| 24836 | 24838 | #include <sys/time.h> |
| 24837 | 24839 | #include <errno.h> |
| 24838 | 24840 | #ifndef SQLITE_OMIT_WAL |
| 24839 | 24841 | #include <sys/mman.h> |
| 24840 | 24842 | #endif |
| 24841 | | -#ifndef MISSING_STATVFS |
| 24842 | | -#include <sys/statvfs.h> |
| 24843 | | -#endif |
| 24844 | 24843 | |
| 24845 | 24844 | |
| 24846 | 24845 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 24847 | 24846 | # include <sys/ioctl.h> |
| 24848 | 24847 | # if OS_VXWORKS |
| | @@ -24929,11 +24928,10 @@ |
| 24929 | 24928 | sqlite3_vfs *pVfs; /* The VFS that created this unixFile */ |
| 24930 | 24929 | unixInodeInfo *pInode; /* Info about locks on this inode */ |
| 24931 | 24930 | int h; /* The file descriptor */ |
| 24932 | 24931 | unsigned char eFileLock; /* The type of lock held on this fd */ |
| 24933 | 24932 | unsigned char ctrlFlags; /* Behavioral bits. UNIXFILE_* flags */ |
| 24934 | | - unsigned char szSector; /* Sectorsize/512 */ |
| 24935 | 24933 | int lastErrno; /* The unix errno from last I/O error */ |
| 24936 | 24934 | void *lockingContext; /* Locking style specific state */ |
| 24937 | 24935 | UnixUnusedFd *pUnused; /* Pre-allocated UnixUnusedFd */ |
| 24938 | 24936 | const char *zPath; /* Name of the file */ |
| 24939 | 24937 | unixShm *pShm; /* Shared memory segment information */ |
| | @@ -25342,18 +25340,10 @@ |
| 25342 | 25340 | #define osMkdir ((int(*)(const char*,mode_t))aSyscall[18].pCurrent) |
| 25343 | 25341 | |
| 25344 | 25342 | { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 }, |
| 25345 | 25343 | #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent) |
| 25346 | 25344 | |
| 25347 | | -#if defined(MISSING_STATVFS) |
| 25348 | | - { "statvfs", (sqlite3_syscall_ptr)0, 0 }, |
| 25349 | | -#define osStatvfs ((int(*)(const char*,void*))aSyscall[20].pCurrent) |
| 25350 | | -#else |
| 25351 | | - { "statvfs", (sqlite3_syscall_ptr)statvfs, 0 }, |
| 25352 | | -#define osStatvfs ((int(*)(const char*,struct statvfs*))aSyscall[20].pCurrent) |
| 25353 | | -#endif |
| 25354 | | - |
| 25355 | 25345 | }; /* End of the overrideable system calls */ |
| 25356 | 25346 | |
| 25357 | 25347 | /* |
| 25358 | 25348 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| 25359 | 25349 | ** "unix" VFSes. Return SQLITE_OK opon successfully updating the |
| | @@ -28504,13 +28494,10 @@ |
| 28504 | 28494 | case SQLITE_SET_LOCKPROXYFILE: |
| 28505 | 28495 | case SQLITE_GET_LOCKPROXYFILE: { |
| 28506 | 28496 | return proxyFileControl(id,op,pArg); |
| 28507 | 28497 | } |
| 28508 | 28498 | #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */ |
| 28509 | | - case SQLITE_FCNTL_SYNC_OMITTED: { |
| 28510 | | - return SQLITE_OK; /* A no-op */ |
| 28511 | | - } |
| 28512 | 28499 | } |
| 28513 | 28500 | return SQLITE_NOTFOUND; |
| 28514 | 28501 | } |
| 28515 | 28502 | |
| 28516 | 28503 | /* |
| | @@ -28522,27 +28509,12 @@ |
| 28522 | 28509 | ** if two files are created in the same file-system directory (i.e. |
| 28523 | 28510 | ** a database and its journal file) that the sector size will be the |
| 28524 | 28511 | ** same for both. |
| 28525 | 28512 | */ |
| 28526 | 28513 | static int unixSectorSize(sqlite3_file *pFile){ |
| 28527 | | - unixFile *p = (unixFile*)pFile; |
| 28528 | | - if( p->szSector==0 ){ |
| 28529 | | -#ifdef MISSING_STATVFS |
| 28530 | | - p->szSector = SQLITE_DEFAULT_SECTOR_SIZE/512; |
| 28531 | | -#else |
| 28532 | | - struct statvfs x; |
| 28533 | | - int sz; |
| 28534 | | - memset(&x, 0, sizeof(x)); |
| 28535 | | - osStatvfs(p->zPath, &x); |
| 28536 | | - sz = (int)x.f_frsize; |
| 28537 | | - if( sz<512 || sz>65536 || (sz&(sz-1))!=0 ){ |
| 28538 | | - sz = SQLITE_DEFAULT_SECTOR_SIZE; |
| 28539 | | - } |
| 28540 | | - p->szSector = sz/512; |
| 28541 | | -#endif |
| 28542 | | - } |
| 28543 | | - return p->szSector*512; |
| 28514 | + (void)pFile; |
| 28515 | + return SQLITE_DEFAULT_SECTOR_SIZE; |
| 28544 | 28516 | } |
| 28545 | 28517 | |
| 28546 | 28518 | /* |
| 28547 | 28519 | ** Return the device characteristics for the file. |
| 28548 | 28520 | ** |
| | @@ -28815,13 +28787,13 @@ |
| 28815 | 28787 | rc = SQLITE_IOERR_FSTAT; |
| 28816 | 28788 | goto shm_open_err; |
| 28817 | 28789 | } |
| 28818 | 28790 | |
| 28819 | 28791 | #ifdef SQLITE_SHM_DIRECTORY |
| 28820 | | - nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 30; |
| 28792 | + nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31; |
| 28821 | 28793 | #else |
| 28822 | | - nShmFilename = 5 + (int)strlen(pDbFd->zPath); |
| 28794 | + nShmFilename = 6 + (int)strlen(pDbFd->zPath); |
| 28823 | 28795 | #endif |
| 28824 | 28796 | pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename ); |
| 28825 | 28797 | if( pShmNode==0 ){ |
| 28826 | 28798 | rc = SQLITE_NOMEM; |
| 28827 | 28799 | goto shm_open_err; |
| | @@ -31755,11 +31727,11 @@ |
| 31755 | 31727 | }; |
| 31756 | 31728 | unsigned int i; /* Loop counter */ |
| 31757 | 31729 | |
| 31758 | 31730 | /* Double-check that the aSyscall[] array has been constructed |
| 31759 | 31731 | ** correctly. See ticket [bb3a86e890c8e96ab] */ |
| 31760 | | - assert( ArraySize(aSyscall)==21 ); |
| 31732 | + assert( ArraySize(aSyscall)==20 ); |
| 31761 | 31733 | |
| 31762 | 31734 | /* Register all VFSes defined in the aVfs[] array */ |
| 31763 | 31735 | for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ |
| 31764 | 31736 | sqlite3_vfs_register(&aVfs[i], i==0); |
| 31765 | 31737 | } |
| | @@ -32049,11 +32021,10 @@ |
| 32049 | 32021 | HANDLE h; /* Handle for accessing the file */ |
| 32050 | 32022 | u8 locktype; /* Type of lock currently held on this file */ |
| 32051 | 32023 | short sharedLockByte; /* Randomly chosen byte used as a shared lock */ |
| 32052 | 32024 | u8 ctrlFlags; /* Flags. See WINFILE_* below */ |
| 32053 | 32025 | DWORD lastErrno; /* The Windows errno from the last I/O error */ |
| 32054 | | - DWORD sectorSize; /* Sector size of the device file is on */ |
| 32055 | 32026 | winShm *pShm; /* Instance of shared memory on this file */ |
| 32056 | 32027 | const char *zPath; /* Full pathname of this file */ |
| 32057 | 32028 | int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */ |
| 32058 | 32029 | #if SQLITE_OS_WINCE |
| 32059 | 32030 | LPWSTR zDeleteOnClose; /* Name of file to delete when closing */ |
| | @@ -32139,18 +32110,10 @@ |
| 32139 | 32110 | static void winMemShutdown(void *pAppData); |
| 32140 | 32111 | |
| 32141 | 32112 | SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetWin32(void); |
| 32142 | 32113 | #endif /* SQLITE_WIN32_MALLOC */ |
| 32143 | 32114 | |
| 32144 | | -/* |
| 32145 | | -** Forward prototypes. |
| 32146 | | -*/ |
| 32147 | | -static int getSectorSize( |
| 32148 | | - sqlite3_vfs *pVfs, |
| 32149 | | - const char *zRelative /* UTF-8 file name */ |
| 32150 | | -); |
| 32151 | | - |
| 32152 | 32115 | /* |
| 32153 | 32116 | ** The following variable is (normally) set once and never changes |
| 32154 | 32117 | ** thereafter. It records whether the operating system is Win9x |
| 32155 | 32118 | ** or WinNT. |
| 32156 | 32119 | ** |
| | @@ -34181,13 +34144,10 @@ |
| 34181 | 34144 | } |
| 34182 | 34145 | case SQLITE_FCNTL_VFSNAME: { |
| 34183 | 34146 | *(char**)pArg = sqlite3_mprintf("win32"); |
| 34184 | 34147 | return SQLITE_OK; |
| 34185 | 34148 | } |
| 34186 | | - case SQLITE_FCNTL_SYNC_OMITTED: { |
| 34187 | | - return SQLITE_OK; |
| 34188 | | - } |
| 34189 | 34149 | case SQLITE_FCNTL_WIN32_AV_RETRY: { |
| 34190 | 34150 | int *a = (int*)pArg; |
| 34191 | 34151 | if( a[0]>0 ){ |
| 34192 | 34152 | win32IoerrRetry = a[0]; |
| 34193 | 34153 | }else{ |
| | @@ -34213,12 +34173,12 @@ |
| 34213 | 34173 | ** if two files are created in the same file-system directory (i.e. |
| 34214 | 34174 | ** a database and its journal file) that the sector size will be the |
| 34215 | 34175 | ** same for both. |
| 34216 | 34176 | */ |
| 34217 | 34177 | static int winSectorSize(sqlite3_file *id){ |
| 34218 | | - assert( id!=0 ); |
| 34219 | | - return (int)(((winFile*)id)->sectorSize); |
| 34178 | + (void)id; |
| 34179 | + return SQLITE_DEFAULT_SECTOR_SIZE; |
| 34220 | 34180 | } |
| 34221 | 34181 | |
| 34222 | 34182 | /* |
| 34223 | 34183 | ** Return a vector of device characteristics. |
| 34224 | 34184 | */ |
| | @@ -34463,11 +34423,11 @@ |
| 34463 | 34423 | */ |
| 34464 | 34424 | p = sqlite3_malloc( sizeof(*p) ); |
| 34465 | 34425 | if( p==0 ) return SQLITE_IOERR_NOMEM; |
| 34466 | 34426 | memset(p, 0, sizeof(*p)); |
| 34467 | 34427 | nName = sqlite3Strlen30(pDbFd->zPath); |
| 34468 | | - pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 15 ); |
| 34428 | + pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 16 ); |
| 34469 | 34429 | if( pNew==0 ){ |
| 34470 | 34430 | sqlite3_free(p); |
| 34471 | 34431 | return SQLITE_IOERR_NOMEM; |
| 34472 | 34432 | } |
| 34473 | 34433 | memset(pNew, 0, sizeof(*pNew)); |
| | @@ -35191,11 +35151,10 @@ |
| 35191 | 35151 | pFile->pShm = 0; |
| 35192 | 35152 | pFile->zPath = zName; |
| 35193 | 35153 | if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){ |
| 35194 | 35154 | pFile->ctrlFlags |= WINFILE_PSOW; |
| 35195 | 35155 | } |
| 35196 | | - pFile->sectorSize = getSectorSize(pVfs, zUtf8Name); |
| 35197 | 35156 | |
| 35198 | 35157 | #if SQLITE_OS_WINCE |
| 35199 | 35158 | if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB |
| 35200 | 35159 | && !winceCreateLock(zName, pFile) |
| 35201 | 35160 | ){ |
| | @@ -35436,85 +35395,10 @@ |
| 35436 | 35395 | return SQLITE_IOERR_NOMEM; |
| 35437 | 35396 | } |
| 35438 | 35397 | #endif |
| 35439 | 35398 | } |
| 35440 | 35399 | |
| 35441 | | -/* |
| 35442 | | -** Get the sector size of the device used to store |
| 35443 | | -** file. |
| 35444 | | -*/ |
| 35445 | | -static int getSectorSize( |
| 35446 | | - sqlite3_vfs *pVfs, |
| 35447 | | - const char *zRelative /* UTF-8 file name */ |
| 35448 | | -){ |
| 35449 | | - DWORD bytesPerSector = SQLITE_DEFAULT_SECTOR_SIZE; |
| 35450 | | - /* GetDiskFreeSpace is not supported under WINCE */ |
| 35451 | | -#if SQLITE_OS_WINCE |
| 35452 | | - UNUSED_PARAMETER(pVfs); |
| 35453 | | - UNUSED_PARAMETER(zRelative); |
| 35454 | | -#else |
| 35455 | | - char zFullpath[MAX_PATH+1]; |
| 35456 | | - int rc; |
| 35457 | | - DWORD dwRet = 0; |
| 35458 | | - DWORD dwDummy; |
| 35459 | | - |
| 35460 | | - /* |
| 35461 | | - ** We need to get the full path name of the file |
| 35462 | | - ** to get the drive letter to look up the sector |
| 35463 | | - ** size. |
| 35464 | | - */ |
| 35465 | | - SimulateIOErrorBenign(1); |
| 35466 | | - sqlite3BeginBenignMalloc(); |
| 35467 | | - rc = winFullPathname(pVfs, zRelative, MAX_PATH, zFullpath); |
| 35468 | | - sqlite3EndBenignMalloc(); |
| 35469 | | - SimulateIOErrorBenign(0); |
| 35470 | | - if( rc == SQLITE_OK ) |
| 35471 | | - { |
| 35472 | | - void *zConverted; |
| 35473 | | - sqlite3BeginBenignMalloc(); |
| 35474 | | - zConverted = convertUtf8Filename(zFullpath); |
| 35475 | | - sqlite3EndBenignMalloc(); |
| 35476 | | - if( zConverted ){ |
| 35477 | | - if( isNT() ){ |
| 35478 | | - /* trim path to just drive reference */ |
| 35479 | | - LPWSTR p = zConverted; |
| 35480 | | - for(;*p;p++){ |
| 35481 | | - if( *p == '\\' ){ |
| 35482 | | - *p = '\0'; |
| 35483 | | - break; |
| 35484 | | - } |
| 35485 | | - } |
| 35486 | | - dwRet = osGetDiskFreeSpaceW((LPCWSTR)zConverted, |
| 35487 | | - &dwDummy, |
| 35488 | | - &bytesPerSector, |
| 35489 | | - &dwDummy, |
| 35490 | | - &dwDummy); |
| 35491 | | - }else{ |
| 35492 | | - /* trim path to just drive reference */ |
| 35493 | | - char *p = (char *)zConverted; |
| 35494 | | - for(;*p;p++){ |
| 35495 | | - if( *p == '\\' ){ |
| 35496 | | - *p = '\0'; |
| 35497 | | - break; |
| 35498 | | - } |
| 35499 | | - } |
| 35500 | | - dwRet = osGetDiskFreeSpaceA((char*)zConverted, |
| 35501 | | - &dwDummy, |
| 35502 | | - &bytesPerSector, |
| 35503 | | - &dwDummy, |
| 35504 | | - &dwDummy); |
| 35505 | | - } |
| 35506 | | - sqlite3_free(zConverted); |
| 35507 | | - } |
| 35508 | | - if( !dwRet ){ |
| 35509 | | - bytesPerSector = SQLITE_DEFAULT_SECTOR_SIZE; |
| 35510 | | - } |
| 35511 | | - } |
| 35512 | | -#endif |
| 35513 | | - return (int) bytesPerSector; |
| 35514 | | -} |
| 35515 | | - |
| 35516 | 35400 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 35517 | 35401 | /* |
| 35518 | 35402 | ** Interfaces for opening a shared library, finding entry points |
| 35519 | 35403 | ** within the shared library, and closing the shared library. |
| 35520 | 35404 | */ |
| | @@ -36381,11 +36265,11 @@ |
| 36381 | 36265 | */ |
| 36382 | 36266 | static int numberOfCachePages(PCache *p){ |
| 36383 | 36267 | if( p->szCache>=0 ){ |
| 36384 | 36268 | return p->szCache; |
| 36385 | 36269 | }else{ |
| 36386 | | - return (-1024*p->szCache)/(p->szPage+p->szExtra); |
| 36270 | + return (int)((-1024*(i64)p->szCache)/(p->szPage+p->szExtra)); |
| 36387 | 36271 | } |
| 36388 | 36272 | } |
| 36389 | 36273 | |
| 36390 | 36274 | /* |
| 36391 | 36275 | ** Try to obtain a page from the cache. |
| | @@ -36845,14 +36729,14 @@ |
| 36845 | 36729 | ** PGroup which is the pcache1.grp global variable and its mutex is |
| 36846 | 36730 | ** SQLITE_MUTEX_STATIC_LRU. |
| 36847 | 36731 | */ |
| 36848 | 36732 | struct PGroup { |
| 36849 | 36733 | sqlite3_mutex *mutex; /* MUTEX_STATIC_LRU or NULL */ |
| 36850 | | - int nMaxPage; /* Sum of nMax for purgeable caches */ |
| 36851 | | - int nMinPage; /* Sum of nMin for purgeable caches */ |
| 36852 | | - int mxPinned; /* nMaxpage + 10 - nMinPage */ |
| 36853 | | - int nCurrentPage; /* Number of purgeable pages allocated */ |
| 36734 | + unsigned int nMaxPage; /* Sum of nMax for purgeable caches */ |
| 36735 | + unsigned int nMinPage; /* Sum of nMin for purgeable caches */ |
| 36736 | + unsigned int mxPinned; /* nMaxpage + 10 - nMinPage */ |
| 36737 | + unsigned int nCurrentPage; /* Number of purgeable pages allocated */ |
| 36854 | 36738 | PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */ |
| 36855 | 36739 | }; |
| 36856 | 36740 | |
| 36857 | 36741 | /* Each page cache is an instance of the following object. Every |
| 36858 | 36742 | ** open database file (including each in-memory database and each |
| | @@ -37511,11 +37395,11 @@ |
| 37511 | 37395 | static sqlite3_pcache_page *pcache1Fetch( |
| 37512 | 37396 | sqlite3_pcache *p, |
| 37513 | 37397 | unsigned int iKey, |
| 37514 | 37398 | int createFlag |
| 37515 | 37399 | ){ |
| 37516 | | - int nPinned; |
| 37400 | + unsigned int nPinned; |
| 37517 | 37401 | PCache1 *pCache = (PCache1 *)p; |
| 37518 | 37402 | PGroup *pGroup; |
| 37519 | 37403 | PgHdr1 *pPage = 0; |
| 37520 | 37404 | |
| 37521 | 37405 | assert( pCache->bPurgeable || createFlag!=1 ); |
| | @@ -37546,17 +37430,17 @@ |
| 37546 | 37430 | #ifdef SQLITE_MUTEX_OMIT |
| 37547 | 37431 | pGroup = pCache->pGroup; |
| 37548 | 37432 | #endif |
| 37549 | 37433 | |
| 37550 | 37434 | /* Step 3: Abort if createFlag is 1 but the cache is nearly full */ |
| 37435 | + assert( pCache->nPage >= pCache->nRecyclable ); |
| 37551 | 37436 | nPinned = pCache->nPage - pCache->nRecyclable; |
| 37552 | | - assert( nPinned>=0 ); |
| 37553 | 37437 | assert( pGroup->mxPinned == pGroup->nMaxPage + 10 - pGroup->nMinPage ); |
| 37554 | 37438 | assert( pCache->n90pct == pCache->nMax*9/10 ); |
| 37555 | 37439 | if( createFlag==1 && ( |
| 37556 | 37440 | nPinned>=pGroup->mxPinned |
| 37557 | | - || nPinned>=(int)pCache->n90pct |
| 37441 | + || nPinned>=pCache->n90pct |
| 37558 | 37442 | || pcache1UnderMemoryPressure(pCache) |
| 37559 | 37443 | )){ |
| 37560 | 37444 | goto fetch_out; |
| 37561 | 37445 | } |
| 37562 | 37446 | |
| | @@ -37725,11 +37609,13 @@ |
| 37725 | 37609 | PCache1 *pCache = (PCache1 *)p; |
| 37726 | 37610 | PGroup *pGroup = pCache->pGroup; |
| 37727 | 37611 | assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) ); |
| 37728 | 37612 | pcache1EnterMutex(pGroup); |
| 37729 | 37613 | pcache1TruncateUnsafe(pCache, 0); |
| 37614 | + assert( pGroup->nMaxPage >= pCache->nMax ); |
| 37730 | 37615 | pGroup->nMaxPage -= pCache->nMax; |
| 37616 | + assert( pGroup->nMinPage >= pCache->nMin ); |
| 37731 | 37617 | pGroup->nMinPage -= pCache->nMin; |
| 37732 | 37618 | pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage; |
| 37733 | 37619 | pcache1EnforceMaxPage(pGroup); |
| 37734 | 37620 | pcache1LeaveMutex(pGroup); |
| 37735 | 37621 | sqlite3_free(pCache->apHash); |
| | @@ -37807,12 +37693,12 @@ |
| 37807 | 37693 | int nRecyclable = 0; |
| 37808 | 37694 | for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){ |
| 37809 | 37695 | nRecyclable++; |
| 37810 | 37696 | } |
| 37811 | 37697 | *pnCurrent = pcache1.grp.nCurrentPage; |
| 37812 | | - *pnMax = pcache1.grp.nMaxPage; |
| 37813 | | - *pnMin = pcache1.grp.nMinPage; |
| 37698 | + *pnMax = (int)pcache1.grp.nMaxPage; |
| 37699 | + *pnMin = (int)pcache1.grp.nMinPage; |
| 37814 | 37700 | *pnRecyclable = nRecyclable; |
| 37815 | 37701 | } |
| 37816 | 37702 | #endif |
| 37817 | 37703 | |
| 37818 | 37704 | /************** End of pcache1.c *********************************************/ |
| | @@ -38282,10 +38168,16 @@ |
| 38282 | 38168 | |
| 38283 | 38169 | #ifndef _WAL_H_ |
| 38284 | 38170 | #define _WAL_H_ |
| 38285 | 38171 | |
| 38286 | 38172 | |
| 38173 | +/* Additional values that can be added to the sync_flags argument of |
| 38174 | +** sqlite3WalFrames(): |
| 38175 | +*/ |
| 38176 | +#define WAL_SYNC_TRANSACTIONS 0x20 /* Sync at the end of each transaction */ |
| 38177 | +#define SQLITE_SYNC_MASK 0x13 /* Mask off the SQLITE_SYNC_* values */ |
| 38178 | + |
| 38287 | 38179 | #ifdef SQLITE_OMIT_WAL |
| 38288 | 38180 | # define sqlite3WalOpen(x,y,z) 0 |
| 38289 | 38181 | # define sqlite3WalLimit(x,y) |
| 38290 | 38182 | # define sqlite3WalClose(w,x,y,z) 0 |
| 38291 | 38183 | # define sqlite3WalBeginReadTransaction(y,z) 0 |
| | @@ -38350,16 +38242,10 @@ |
| 38350 | 38242 | SQLITE_PRIVATE int sqlite3WalSavepointUndo(Wal *pWal, u32 *aWalData); |
| 38351 | 38243 | |
| 38352 | 38244 | /* Write a frame or frames to the log. */ |
| 38353 | 38245 | SQLITE_PRIVATE int sqlite3WalFrames(Wal *pWal, int, PgHdr *, Pgno, int, int); |
| 38354 | 38246 | |
| 38355 | | -/* Additional values that can be added to the sync_flags argument of |
| 38356 | | -** sqlite3WalFrames(): |
| 38357 | | -*/ |
| 38358 | | -#define WAL_SYNC_TRANSACTIONS 0x20 /* Sync at the end of each transaction */ |
| 38359 | | -#define SQLITE_SYNC_MASK 0x13 /* Mask off the SQLITE_SYNC_* values */ |
| 38360 | | - |
| 38361 | 38247 | /* Copy pages from the log to the database file */ |
| 38362 | 38248 | SQLITE_PRIVATE int sqlite3WalCheckpoint( |
| 38363 | 38249 | Wal *pWal, /* Write-ahead log connection */ |
| 38364 | 38250 | int eMode, /* One of PASSIVE, FULL and RESTART */ |
| 38365 | 38251 | int (*xBusy)(void*), /* Function to call when busy */ |
| | @@ -42400,11 +42286,13 @@ |
| 42400 | 42286 | ** file size will be. |
| 42401 | 42287 | */ |
| 42402 | 42288 | assert( rc!=SQLITE_OK || isOpen(pPager->fd) ); |
| 42403 | 42289 | if( rc==SQLITE_OK && pPager->dbSize>pPager->dbHintSize ){ |
| 42404 | 42290 | sqlite3_int64 szFile = pPager->pageSize * (sqlite3_int64)pPager->dbSize; |
| 42291 | + sqlite3BeginBenignMalloc(); |
| 42405 | 42292 | sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &szFile); |
| 42293 | + sqlite3EndBenignMalloc(); |
| 42406 | 42294 | pPager->dbHintSize = pPager->dbSize; |
| 42407 | 42295 | } |
| 42408 | 42296 | |
| 42409 | 42297 | while( rc==SQLITE_OK && pList ){ |
| 42410 | 42298 | Pgno pgno = pList->pgno; |
| | @@ -42741,11 +42629,12 @@ |
| 42741 | 42629 | z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1]; |
| 42742 | 42630 | while( *z ){ |
| 42743 | 42631 | z += sqlite3Strlen30(z)+1; |
| 42744 | 42632 | z += sqlite3Strlen30(z)+1; |
| 42745 | 42633 | } |
| 42746 | | - nUri = &z[1] - zUri; |
| 42634 | + nUri = (int)(&z[1] - zUri); |
| 42635 | + assert( nUri>=0 ); |
| 42747 | 42636 | if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){ |
| 42748 | 42637 | /* This branch is taken when the journal path required by |
| 42749 | 42638 | ** the database being opened will be more than pVfs->mxPathname |
| 42750 | 42639 | ** bytes in length. This means the database cannot be opened, |
| 42751 | 42640 | ** as it will not be possible to open the journal file or even |
| | @@ -42775,13 +42664,13 @@ |
| 42775 | 42664 | ROUND8(sizeof(*pPager)) + /* Pager structure */ |
| 42776 | 42665 | ROUND8(pcacheSize) + /* PCache object */ |
| 42777 | 42666 | ROUND8(pVfs->szOsFile) + /* The main db file */ |
| 42778 | 42667 | journalFileSize * 2 + /* The two journal files */ |
| 42779 | 42668 | nPathname + 1 + nUri + /* zFilename */ |
| 42780 | | - nPathname + 8 + 1 /* zJournal */ |
| 42669 | + nPathname + 8 + 2 /* zJournal */ |
| 42781 | 42670 | #ifndef SQLITE_OMIT_WAL |
| 42782 | | - + nPathname + 4 + 1 /* zWal */ |
| 42671 | + + nPathname + 4 + 2 /* zWal */ |
| 42783 | 42672 | #endif |
| 42784 | 42673 | ); |
| 42785 | 42674 | assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) ); |
| 42786 | 42675 | if( !pPtr ){ |
| 42787 | 42676 | sqlite3_free(zPathname); |
| | @@ -42800,16 +42689,16 @@ |
| 42800 | 42689 | assert( nPathname>0 ); |
| 42801 | 42690 | pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri); |
| 42802 | 42691 | memcpy(pPager->zFilename, zPathname, nPathname); |
| 42803 | 42692 | memcpy(&pPager->zFilename[nPathname+1], zUri, nUri); |
| 42804 | 42693 | memcpy(pPager->zJournal, zPathname, nPathname); |
| 42805 | | - memcpy(&pPager->zJournal[nPathname], "-journal", 8); |
| 42694 | + memcpy(&pPager->zJournal[nPathname], "-journal\000", 8+1); |
| 42806 | 42695 | sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal); |
| 42807 | 42696 | #ifndef SQLITE_OMIT_WAL |
| 42808 | 42697 | pPager->zWal = &pPager->zJournal[nPathname+8+1]; |
| 42809 | 42698 | memcpy(pPager->zWal, zPathname, nPathname); |
| 42810 | | - memcpy(&pPager->zWal[nPathname], "-wal", 4); |
| 42699 | + memcpy(&pPager->zWal[nPathname], "-wal\000", 4+1); |
| 42811 | 42700 | sqlite3FileSuffix3(pPager->zFilename, pPager->zWal); |
| 42812 | 42701 | #endif |
| 42813 | 42702 | sqlite3_free(zPathname); |
| 42814 | 42703 | } |
| 42815 | 42704 | pPager->pVfs = pVfs; |
| | @@ -44064,11 +43953,14 @@ |
| 44064 | 43953 | if( !pPager->noSync ){ |
| 44065 | 43954 | assert( !MEMDB ); |
| 44066 | 43955 | rc = sqlite3OsSync(pPager->fd, pPager->syncFlags); |
| 44067 | 43956 | }else if( isOpen(pPager->fd) ){ |
| 44068 | 43957 | assert( !MEMDB ); |
| 44069 | | - sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC_OMITTED, (void *)&rc); |
| 43958 | + rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC_OMITTED, 0); |
| 43959 | + if( rc==SQLITE_NOTFOUND ){ |
| 43960 | + rc = SQLITE_OK; |
| 43961 | + } |
| 44070 | 43962 | } |
| 44071 | 43963 | return rc; |
| 44072 | 43964 | } |
| 44073 | 43965 | |
| 44074 | 43966 | /* |
| | @@ -48125,11 +48017,11 @@ |
| 48125 | 48017 | iFrame = pWal->hdr.mxFrame; |
| 48126 | 48018 | for(p=pList; p && rc==SQLITE_OK; p=p->pDirty){ |
| 48127 | 48019 | iFrame++; |
| 48128 | 48020 | rc = walIndexAppend(pWal, iFrame, p->pgno); |
| 48129 | 48021 | } |
| 48130 | | - while( nExtra>0 && rc==SQLITE_OK ){ |
| 48022 | + while( rc==SQLITE_OK && nExtra>0 ){ |
| 48131 | 48023 | iFrame++; |
| 48132 | 48024 | nExtra--; |
| 48133 | 48025 | rc = walIndexAppend(pWal, iFrame, pLast->pgno); |
| 48134 | 48026 | } |
| 48135 | 48027 | |
| | @@ -48726,11 +48618,11 @@ |
| 48726 | 48618 | #define TRANS_WRITE 2 |
| 48727 | 48619 | |
| 48728 | 48620 | /* |
| 48729 | 48621 | ** An instance of this object represents a single database file. |
| 48730 | 48622 | ** |
| 48731 | | -** A single database file can be in use as the same time by two |
| 48623 | +** A single database file can be in use at the same time by two |
| 48732 | 48624 | ** or more database connections. When two or more connections are |
| 48733 | 48625 | ** sharing the same database file, each connection has it own |
| 48734 | 48626 | ** private Btree object for the file and each of those Btrees points |
| 48735 | 48627 | ** to this one BtShared object. BtShared.nRef is the number of |
| 48736 | 48628 | ** connections currently sharing this database file. |
| | @@ -48832,11 +48724,11 @@ |
| 48832 | 48724 | ** b-tree within a database file. |
| 48833 | 48725 | ** |
| 48834 | 48726 | ** The entry is identified by its MemPage and the index in |
| 48835 | 48727 | ** MemPage.aCell[] of the entry. |
| 48836 | 48728 | ** |
| 48837 | | -** A single database file can shared by two more database connections, |
| 48729 | +** A single database file can be shared by two more database connections, |
| 48838 | 48730 | ** but cursors cannot be shared. Each cursor is associated with a |
| 48839 | 48731 | ** particular database connection identified BtCursor.pBtree.db. |
| 48840 | 48732 | ** |
| 48841 | 48733 | ** Fields in this structure are accessed under the BtShared.mutex |
| 48842 | 48734 | ** found at self->pBt->mutex. |
| | @@ -48993,11 +48885,11 @@ |
| 48993 | 48885 | int mallocFailed; /* A memory allocation error has occurred */ |
| 48994 | 48886 | StrAccum errMsg; /* Accumulate the error message text here */ |
| 48995 | 48887 | }; |
| 48996 | 48888 | |
| 48997 | 48889 | /* |
| 48998 | | -** Read or write a two- and four-byte big-endian integer values. |
| 48890 | +** Routines to read or write a two- and four-byte big-endian integer values. |
| 48999 | 48891 | */ |
| 49000 | 48892 | #define get2byte(x) ((x)[0]<<8 | (x)[1]) |
| 49001 | 48893 | #define put2byte(p,v) ((p)[0] = (u8)((v)>>8), (p)[1] = (u8)(v)) |
| 49002 | 48894 | #define get4byte sqlite3Get4byte |
| 49003 | 48895 | #define put4byte sqlite3Put4byte |
| | @@ -55478,12 +55370,18 @@ |
| 55478 | 55370 | } |
| 55479 | 55371 | |
| 55480 | 55372 | /* Either we found one or more cells (cntnew[0])>0) or pPage is |
| 55481 | 55373 | ** a virtual root page. A virtual root page is when the real root |
| 55482 | 55374 | ** page is page 1 and we are the only child of that page. |
| 55375 | + ** |
| 55376 | + ** UPDATE: The assert() below is not necessarily true if the database |
| 55377 | + ** file is corrupt. The corruption will be detected and reported later |
| 55378 | + ** in this procedure so there is no need to act upon it now. |
| 55483 | 55379 | */ |
| 55380 | +#if 0 |
| 55484 | 55381 | assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) ); |
| 55382 | +#endif |
| 55485 | 55383 | |
| 55486 | 55384 | TRACE(("BALANCE: old: %d %d %d ", |
| 55487 | 55385 | apOld[0]->pgno, |
| 55488 | 55386 | nOld>=2 ? apOld[1]->pgno : 0, |
| 55489 | 55387 | nOld>=3 ? apOld[2]->pgno : 0 |
| | @@ -58194,11 +58092,13 @@ |
| 58194 | 58092 | |
| 58195 | 58093 | assert( sqlite3BtreeIsInTrans(pTo) ); |
| 58196 | 58094 | pFd = sqlite3PagerFile(sqlite3BtreePager(pTo)); |
| 58197 | 58095 | if( pFd->pMethods ){ |
| 58198 | 58096 | i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom); |
| 58097 | + sqlite3BeginBenignMalloc(); |
| 58199 | 58098 | sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte); |
| 58099 | + sqlite3EndBenignMalloc(); |
| 58200 | 58100 | } |
| 58201 | 58101 | |
| 58202 | 58102 | /* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set |
| 58203 | 58103 | ** to 0. This is used by the implementations of sqlite3_backup_step() |
| 58204 | 58104 | ** and sqlite3_backup_finish() to detect that they are being called |
| | @@ -58525,11 +58425,11 @@ |
| 58525 | 58425 | ** Release any memory held by the Mem. This may leave the Mem in an |
| 58526 | 58426 | ** inconsistent state, for example with (Mem.z==0) and |
| 58527 | 58427 | ** (Mem.type==SQLITE_TEXT). |
| 58528 | 58428 | */ |
| 58529 | 58429 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){ |
| 58530 | | - MemReleaseExt(p); |
| 58430 | + VdbeMemRelease(p); |
| 58531 | 58431 | sqlite3DbFree(p->db, p->zMalloc); |
| 58532 | 58432 | p->z = 0; |
| 58533 | 58433 | p->zMalloc = 0; |
| 58534 | 58434 | p->xDel = 0; |
| 58535 | 58435 | } |
| | @@ -58821,11 +58721,11 @@ |
| 58821 | 58721 | ** copies of this cell as invalid. |
| 58822 | 58722 | ** |
| 58823 | 58723 | ** This is used for testing and debugging only - to make sure shallow |
| 58824 | 58724 | ** copies are not misused. |
| 58825 | 58725 | */ |
| 58826 | | -SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe *pVdbe, Mem *pMem){ |
| 58726 | +SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){ |
| 58827 | 58727 | int i; |
| 58828 | 58728 | Mem *pX; |
| 58829 | 58729 | for(i=1, pX=&pVdbe->aMem[1]; i<=pVdbe->nMem; i++, pX++){ |
| 58830 | 58730 | if( pX->pScopyFrom==pMem ){ |
| 58831 | 58731 | pX->flags |= MEM_Invalid; |
| | @@ -58847,11 +58747,11 @@ |
| 58847 | 58747 | ** pFrom->z is used, then pTo->z points to the same thing as pFrom->z |
| 58848 | 58748 | ** and flags gets srcType (either MEM_Ephem or MEM_Static). |
| 58849 | 58749 | */ |
| 58850 | 58750 | SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){ |
| 58851 | 58751 | assert( (pFrom->flags & MEM_RowSet)==0 ); |
| 58852 | | - MemReleaseExt(pTo); |
| 58752 | + VdbeMemRelease(pTo); |
| 58853 | 58753 | memcpy(pTo, pFrom, MEMCELLSIZE); |
| 58854 | 58754 | pTo->xDel = 0; |
| 58855 | 58755 | if( (pFrom->flags&MEM_Static)==0 ){ |
| 58856 | 58756 | pTo->flags &= ~(MEM_Dyn|MEM_Static|MEM_Ephem); |
| 58857 | 58757 | assert( srcType==MEM_Ephem || srcType==MEM_Static ); |
| | @@ -58865,11 +58765,11 @@ |
| 58865 | 58765 | */ |
| 58866 | 58766 | SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){ |
| 58867 | 58767 | int rc = SQLITE_OK; |
| 58868 | 58768 | |
| 58869 | 58769 | assert( (pFrom->flags & MEM_RowSet)==0 ); |
| 58870 | | - MemReleaseExt(pTo); |
| 58770 | + VdbeMemRelease(pTo); |
| 58871 | 58771 | memcpy(pTo, pFrom, MEMCELLSIZE); |
| 58872 | 58772 | pTo->flags &= ~MEM_Dyn; |
| 58873 | 58773 | |
| 58874 | 58774 | if( pTo->flags&(MEM_Str|MEM_Blob) ){ |
| 58875 | 58775 | if( 0==(pFrom->flags&MEM_Static) ){ |
| | @@ -59202,11 +59102,11 @@ |
| 59202 | 59102 | assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 ); |
| 59203 | 59103 | if( sqlite3VdbeMemMakeWriteable(pVal)!=SQLITE_OK ){ |
| 59204 | 59104 | return 0; |
| 59205 | 59105 | } |
| 59206 | 59106 | } |
| 59207 | | - sqlite3VdbeMemNulTerminate(pVal); /* IMP: R-59893-45467 */ |
| 59107 | + sqlite3VdbeMemNulTerminate(pVal); /* IMP: R-31275-44060 */ |
| 59208 | 59108 | }else{ |
| 59209 | 59109 | assert( (pVal->flags&MEM_Blob)==0 ); |
| 59210 | 59110 | sqlite3VdbeMemStringify(pVal, enc); |
| 59211 | 59111 | assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) ); |
| 59212 | 59112 | } |
| | @@ -59583,11 +59483,12 @@ |
| 59583 | 59483 | return addr; |
| 59584 | 59484 | } |
| 59585 | 59485 | |
| 59586 | 59486 | /* |
| 59587 | 59487 | ** Add an OP_ParseSchema opcode. This routine is broken out from |
| 59588 | | -** sqlite3VdbeAddOp4() since it needs to also local all btrees. |
| 59488 | +** sqlite3VdbeAddOp4() since it needs to also needs to mark all btrees |
| 59489 | +** as having been used. |
| 59589 | 59490 | ** |
| 59590 | 59491 | ** The zWhere string must have been obtained from sqlite3_malloc(). |
| 59591 | 59492 | ** This routine will take ownership of the allocated memory. |
| 59592 | 59493 | */ |
| 59593 | 59494 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere){ |
| | @@ -60350,12 +60251,13 @@ |
| 60350 | 60251 | |
| 60351 | 60252 | /* |
| 60352 | 60253 | ** Declare to the Vdbe that the BTree object at db->aDb[i] is used. |
| 60353 | 60254 | ** |
| 60354 | 60255 | ** The prepared statements need to know in advance the complete set of |
| 60355 | | -** attached databases that they will be using. A mask of these databases |
| 60356 | | -** is maintained in p->btreeMask and is used for locking and other purposes. |
| 60256 | +** attached databases that will be use. A mask of these databases |
| 60257 | +** is maintained in p->btreeMask. The p->lockMask value is the subset of |
| 60258 | +** p->btreeMask of databases that will require a lock. |
| 60357 | 60259 | */ |
| 60358 | 60260 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){ |
| 60359 | 60261 | assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 ); |
| 60360 | 60262 | assert( i<(int)sizeof(p->btreeMask)*8 ); |
| 60361 | 60263 | p->btreeMask |= ((yDbMask)1)<<i; |
| | @@ -60874,10 +60776,11 @@ |
| 60874 | 60776 | nVar = pParse->nVar; |
| 60875 | 60777 | nMem = pParse->nMem; |
| 60876 | 60778 | nCursor = pParse->nTab; |
| 60877 | 60779 | nArg = pParse->nMaxArg; |
| 60878 | 60780 | nOnce = pParse->nOnce; |
| 60781 | + if( nOnce==0 ) nOnce = 1; /* Ensure at least one byte in p->aOnceFlag[] */ |
| 60879 | 60782 | |
| 60880 | 60783 | /* For each cursor required, also allocate a memory cell. Memory |
| 60881 | 60784 | ** cells (nMem+1-nCursor)..nMem, inclusive, will never be used by |
| 60882 | 60785 | ** the vdbe program. Instead they are used to allocate space for |
| 60883 | 60786 | ** VdbeCursor/BtCursor structures. The blob of memory associated with |
| | @@ -61225,11 +61128,11 @@ |
| 61225 | 61128 | int retryCount = 0; |
| 61226 | 61129 | int nMainFile; |
| 61227 | 61130 | |
| 61228 | 61131 | /* Select a master journal file name */ |
| 61229 | 61132 | nMainFile = sqlite3Strlen30(zMainFile); |
| 61230 | | - zMaster = sqlite3MPrintf(db, "%s-mjXXXXXX9XX", zMainFile); |
| 61133 | + zMaster = sqlite3MPrintf(db, "%s-mjXXXXXX9XXz", zMainFile); |
| 61231 | 61134 | if( zMaster==0 ) return SQLITE_NOMEM; |
| 61232 | 61135 | do { |
| 61233 | 61136 | u32 iRandom; |
| 61234 | 61137 | if( retryCount ){ |
| 61235 | 61138 | if( retryCount>100 ){ |
| | @@ -63013,11 +62916,11 @@ |
| 63013 | 62916 | ** since any application that receives an SQLITE_MISUSE is broken by |
| 63014 | 62917 | ** definition. |
| 63015 | 62918 | ** |
| 63016 | 62919 | ** Nevertheless, some published applications that were originally written |
| 63017 | 62920 | ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE |
| 63018 | | - ** returns, and the so were broken by the automatic-reset change. As a |
| 62921 | + ** returns, and those were broken by the automatic-reset change. As a |
| 63019 | 62922 | ** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the |
| 63020 | 62923 | ** legacy behavior of returning SQLITE_MISUSE for cases where the |
| 63021 | 62924 | ** previous sqlite3_step() returned something other than a SQLITE_LOCKED |
| 63022 | 62925 | ** or SQLITE_BUSY error. |
| 63023 | 62926 | */ |
| | @@ -63359,17 +63262,17 @@ |
| 63359 | 63262 | pOut = &pVm->pResultSet[i]; |
| 63360 | 63263 | }else{ |
| 63361 | 63264 | /* If the value passed as the second argument is out of range, return |
| 63362 | 63265 | ** a pointer to the following static Mem object which contains the |
| 63363 | 63266 | ** value SQL NULL. Even though the Mem structure contains an element |
| 63364 | | - ** of type i64, on certain architecture (x86) with certain compiler |
| 63267 | + ** of type i64, on certain architectures (x86) with certain compiler |
| 63365 | 63268 | ** switches (-Os), gcc may align this Mem object on a 4-byte boundary |
| 63366 | 63269 | ** instead of an 8-byte one. This all works fine, except that when |
| 63367 | 63270 | ** running with SQLITE_DEBUG defined the SQLite code sometimes assert()s |
| 63368 | 63271 | ** that a Mem structure is located on an 8-byte boundary. To prevent |
| 63369 | | - ** this assert() from failing, when building with SQLITE_DEBUG defined |
| 63370 | | - ** using gcc, force nullMem to be 8-byte aligned using the magical |
| 63272 | + ** these assert()s from failing, when building with SQLITE_DEBUG defined |
| 63273 | + ** using gcc, we force nullMem to be 8-byte aligned using the magical |
| 63371 | 63274 | ** __attribute__((aligned(8))) macro. */ |
| 63372 | 63275 | static const Mem nullMem |
| 63373 | 63276 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 63374 | 63277 | __attribute__((aligned(8))) |
| 63375 | 63278 | #endif |
| | @@ -64298,11 +64201,11 @@ |
| 64298 | 64201 | ** Invoke this macro on memory cells just prior to changing the |
| 64299 | 64202 | ** value of the cell. This macro verifies that shallow copies are |
| 64300 | 64203 | ** not misused. |
| 64301 | 64204 | */ |
| 64302 | 64205 | #ifdef SQLITE_DEBUG |
| 64303 | | -# define memAboutToChange(P,M) sqlite3VdbeMemPrepareToChange(P,M) |
| 64206 | +# define memAboutToChange(P,M) sqlite3VdbeMemAboutToChange(P,M) |
| 64304 | 64207 | #else |
| 64305 | 64208 | # define memAboutToChange(P,M) |
| 64306 | 64209 | #endif |
| 64307 | 64210 | |
| 64308 | 64211 | /* |
| | @@ -64316,12 +64219,12 @@ |
| 64316 | 64219 | SQLITE_API int sqlite3_search_count = 0; |
| 64317 | 64220 | #endif |
| 64318 | 64221 | |
| 64319 | 64222 | /* |
| 64320 | 64223 | ** When this global variable is positive, it gets decremented once before |
| 64321 | | -** each instruction in the VDBE. When reaches zero, the u1.isInterrupted |
| 64322 | | -** field of the sqlite3 structure is set in order to simulate and interrupt. |
| 64224 | +** each instruction in the VDBE. When it reaches zero, the u1.isInterrupted |
| 64225 | +** field of the sqlite3 structure is set in order to simulate an interrupt. |
| 64323 | 64226 | ** |
| 64324 | 64227 | ** This facility is used for testing purposes only. It does not function |
| 64325 | 64228 | ** in an ordinary build. |
| 64326 | 64229 | */ |
| 64327 | 64230 | #ifdef SQLITE_TEST |
| | @@ -64442,11 +64345,11 @@ |
| 64442 | 64345 | */ |
| 64443 | 64346 | static VdbeCursor *allocateCursor( |
| 64444 | 64347 | Vdbe *p, /* The virtual machine */ |
| 64445 | 64348 | int iCur, /* Index of the new VdbeCursor */ |
| 64446 | 64349 | int nField, /* Number of fields in the table or index */ |
| 64447 | | - int iDb, /* When database the cursor belongs to, or -1 */ |
| 64350 | + int iDb, /* Database the cursor belongs to, or -1 */ |
| 64448 | 64351 | int isBtreeCursor /* True for B-Tree. False for pseudo-table or vtab */ |
| 64449 | 64352 | ){ |
| 64450 | 64353 | /* Find the memory cell that will be used to store the blob of memory |
| 64451 | 64354 | ** required for this VdbeCursor structure. It is convenient to use a |
| 64452 | 64355 | ** vdbe memory cell to manage the memory allocation required for a |
| | @@ -64813,11 +64716,11 @@ |
| 64813 | 64716 | ** sqlite3_interrupt() routine has been called. If it has been, then |
| 64814 | 64717 | ** processing of the VDBE program is interrupted. |
| 64815 | 64718 | ** |
| 64816 | 64719 | ** This macro added to every instruction that does a jump in order to |
| 64817 | 64720 | ** implement a loop. This test used to be on every single instruction, |
| 64818 | | -** but that meant we more testing that we needed. By only testing the |
| 64721 | +** but that meant we more testing than we needed. By only testing the |
| 64819 | 64722 | ** flag on jump instructions, we get a (small) speed improvement. |
| 64820 | 64723 | */ |
| 64821 | 64724 | #define CHECK_FOR_INTERRUPT \ |
| 64822 | 64725 | if( db->u1.isInterrupted ) goto abort_due_to_interrupt; |
| 64823 | 64726 | |
| | @@ -65430,11 +65333,11 @@ |
| 65430 | 65333 | if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){ |
| 65431 | 65334 | assert( pOp->p2>0 ); |
| 65432 | 65335 | assert( pOp->p2<=p->nMem ); |
| 65433 | 65336 | pOut = &aMem[pOp->p2]; |
| 65434 | 65337 | memAboutToChange(p, pOut); |
| 65435 | | - MemReleaseExt(pOut); |
| 65338 | + VdbeMemRelease(pOut); |
| 65436 | 65339 | pOut->flags = MEM_Int; |
| 65437 | 65340 | } |
| 65438 | 65341 | |
| 65439 | 65342 | /* Sanity checking on other operands */ |
| 65440 | 65343 | #ifdef SQLITE_DEBUG |
| | @@ -65738,11 +65641,11 @@ |
| 65738 | 65641 | assert( pOp->p3<=p->nMem ); |
| 65739 | 65642 | pOut->flags = MEM_Null; |
| 65740 | 65643 | while( u.ab.cnt>0 ){ |
| 65741 | 65644 | pOut++; |
| 65742 | 65645 | memAboutToChange(p, pOut); |
| 65743 | | - MemReleaseExt(pOut); |
| 65646 | + VdbeMemRelease(pOut); |
| 65744 | 65647 | pOut->flags = MEM_Null; |
| 65745 | 65648 | u.ab.cnt--; |
| 65746 | 65649 | } |
| 65747 | 65650 | break; |
| 65748 | 65651 | } |
| | @@ -65919,11 +65822,11 @@ |
| 65919 | 65822 | /* Invalidate all ephemeral cursor row caches */ |
| 65920 | 65823 | p->cacheCtr = (p->cacheCtr + 2)|1; |
| 65921 | 65824 | |
| 65922 | 65825 | /* Make sure the results of the current row are \000 terminated |
| 65923 | 65826 | ** and have an assigned type. The results are de-ephemeralized as |
| 65924 | | - ** as side effect. |
| 65827 | + ** a side effect. |
| 65925 | 65828 | */ |
| 65926 | 65829 | u.ae.pMem = p->pResultSet = &aMem[pOp->p1]; |
| 65927 | 65830 | for(u.ae.i=0; u.ae.i<pOp->p2; u.ae.i++){ |
| 65928 | 65831 | assert( memIsValid(&u.ae.pMem[u.ae.i]) ); |
| 65929 | 65832 | Deephemeralize(&u.ae.pMem[u.ae.i]); |
| | @@ -67160,11 +67063,11 @@ |
| 67160 | 67063 | ** a pointer to a Mem object. |
| 67161 | 67064 | */ |
| 67162 | 67065 | if( u.an.aOffset[u.an.p2] ){ |
| 67163 | 67066 | assert( rc==SQLITE_OK ); |
| 67164 | 67067 | if( u.an.zRec ){ |
| 67165 | | - MemReleaseExt(u.an.pDest); |
| 67068 | + VdbeMemRelease(u.an.pDest); |
| 67166 | 67069 | sqlite3VdbeSerialGet((u8 *)&u.an.zRec[u.an.aOffset[u.an.p2]], u.an.aType[u.an.p2], u.an.pDest); |
| 67167 | 67070 | }else{ |
| 67168 | 67071 | u.an.len = sqlite3VdbeSerialTypeLen(u.an.aType[u.an.p2]); |
| 67169 | 67072 | sqlite3VdbeMemMove(&u.an.sMem, u.an.pDest); |
| 67170 | 67073 | rc = sqlite3VdbeMemFromBtree(u.an.pCrsr, u.an.aOffset[u.an.p2], u.an.len, u.an.pC->isIndex, &u.an.sMem); |
| | @@ -83758,11 +83661,11 @@ |
| 83758 | 83661 | ** Allocate the index structure. |
| 83759 | 83662 | */ |
| 83760 | 83663 | nName = sqlite3Strlen30(zName); |
| 83761 | 83664 | nCol = pList->nExpr; |
| 83762 | 83665 | pIndex = sqlite3DbMallocZero(db, |
| 83763 | | - sizeof(Index) + /* Index structure */ |
| 83666 | + ROUND8(sizeof(Index)) + /* Index structure */ |
| 83764 | 83667 | ROUND8(sizeof(tRowcnt)*(nCol+1)) + /* Index.aiRowEst */ |
| 83765 | 83668 | sizeof(char *)*nCol + /* Index.azColl */ |
| 83766 | 83669 | sizeof(int)*nCol + /* Index.aiColumn */ |
| 83767 | 83670 | sizeof(u8)*nCol + /* Index.aSortOrder */ |
| 83768 | 83671 | nName + 1 + /* Index.zName */ |
| | @@ -83769,11 +83672,12 @@ |
| 83769 | 83672 | nExtra /* Collation sequence names */ |
| 83770 | 83673 | ); |
| 83771 | 83674 | if( db->mallocFailed ){ |
| 83772 | 83675 | goto exit_create_index; |
| 83773 | 83676 | } |
| 83774 | | - pIndex->aiRowEst = (tRowcnt*)(&pIndex[1]); |
| 83677 | + zExtra = (char*)pIndex; |
| 83678 | + pIndex->aiRowEst = (tRowcnt*)&zExtra[ROUND8(sizeof(Index))]; |
| 83775 | 83679 | pIndex->azColl = (char**) |
| 83776 | 83680 | ((char*)pIndex->aiRowEst + ROUND8(sizeof(tRowcnt)*nCol+1)); |
| 83777 | 83681 | assert( EIGHT_BYTE_ALIGNMENT(pIndex->aiRowEst) ); |
| 83778 | 83682 | assert( EIGHT_BYTE_ALIGNMENT(pIndex->azColl) ); |
| 83779 | 83683 | pIndex->aiColumn = (int *)(&pIndex->azColl[nCol]); |
| | @@ -89966,11 +89870,11 @@ |
| 89966 | 89870 | ** any ABORT Back out changes from the current command |
| 89967 | 89871 | ** only (do not do a complete rollback) then |
| 89968 | 89872 | ** cause sqlite3_exec() to return immediately |
| 89969 | 89873 | ** with SQLITE_CONSTRAINT. |
| 89970 | 89874 | ** |
| 89971 | | -** any FAIL Sqlite_exec() returns immediately with a |
| 89875 | +** any FAIL Sqlite3_exec() returns immediately with a |
| 89972 | 89876 | ** return code of SQLITE_CONSTRAINT. The |
| 89973 | 89877 | ** transaction is not rolled back and any |
| 89974 | 89878 | ** prior changes are retained. |
| 89975 | 89879 | ** |
| 89976 | 89880 | ** any IGNORE The record number and data is popped from |
| | @@ -111450,11 +111354,11 @@ |
| 111450 | 111354 | *tokenType = TK_SPACE; |
| 111451 | 111355 | return i; |
| 111452 | 111356 | } |
| 111453 | 111357 | case '-': { |
| 111454 | 111358 | if( z[1]=='-' ){ |
| 111455 | | - /* IMP: R-15891-05542 -- syntax diagram for comments */ |
| 111359 | + /* IMP: R-50417-27976 -- syntax diagram for comments */ |
| 111456 | 111360 | for(i=2; (c=z[i])!=0 && c!='\n'; i++){} |
| 111457 | 111361 | *tokenType = TK_SPACE; /* IMP: R-22934-25134 */ |
| 111458 | 111362 | return i; |
| 111459 | 111363 | } |
| 111460 | 111364 | *tokenType = TK_MINUS; |
| | @@ -111483,11 +111387,11 @@ |
| 111483 | 111387 | case '/': { |
| 111484 | 111388 | if( z[1]!='*' || z[2]==0 ){ |
| 111485 | 111389 | *tokenType = TK_SLASH; |
| 111486 | 111390 | return 1; |
| 111487 | 111391 | } |
| 111488 | | - /* IMP: R-15891-05542 -- syntax diagram for comments */ |
| 111392 | + /* IMP: R-50417-27976 -- syntax diagram for comments */ |
| 111489 | 111393 | for(i=3, c=z[2]; (c!='*' || z[i]!='/') && (c=z[i])!=0; i++){} |
| 111490 | 111394 | if( c ) i++; |
| 111491 | 111395 | *tokenType = TK_SPACE; /* IMP: R-22934-25134 */ |
| 111492 | 111396 | return i; |
| 111493 | 111397 | } |
| | @@ -112277,12 +112181,12 @@ |
| 112277 | 112181 | /* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function |
| 112278 | 112182 | ** returns an integer equal to SQLITE_VERSION_NUMBER. |
| 112279 | 112183 | */ |
| 112280 | 112184 | SQLITE_API int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; } |
| 112281 | 112185 | |
| 112282 | | -/* IMPLEMENTATION-OF: R-54823-41343 The sqlite3_threadsafe() function returns |
| 112283 | | -** zero if and only if SQLite was compiled mutexing code omitted due to |
| 112186 | +/* IMPLEMENTATION-OF: R-20790-14025 The sqlite3_threadsafe() function returns |
| 112187 | +** zero if and only if SQLite was compiled with mutexing code omitted due to |
| 112284 | 112188 | ** the SQLITE_THREADSAFE compile-time option being set to 0. |
| 112285 | 112189 | */ |
| 112286 | 112190 | SQLITE_API int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; } |
| 112287 | 112191 | |
| 112288 | 112192 | #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE) |
| | @@ -112768,19 +112672,21 @@ |
| 112768 | 112672 | ** Free up as much memory as we can from the given database |
| 112769 | 112673 | ** connection. |
| 112770 | 112674 | */ |
| 112771 | 112675 | SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){ |
| 112772 | 112676 | int i; |
| 112677 | + sqlite3_mutex_enter(db->mutex); |
| 112773 | 112678 | sqlite3BtreeEnterAll(db); |
| 112774 | 112679 | for(i=0; i<db->nDb; i++){ |
| 112775 | 112680 | Btree *pBt = db->aDb[i].pBt; |
| 112776 | 112681 | if( pBt ){ |
| 112777 | 112682 | Pager *pPager = sqlite3BtreePager(pBt); |
| 112778 | 112683 | sqlite3PagerShrink(pPager); |
| 112779 | 112684 | } |
| 112780 | 112685 | } |
| 112781 | 112686 | sqlite3BtreeLeaveAll(db); |
| 112687 | + sqlite3_mutex_leave(db->mutex); |
| 112782 | 112688 | return SQLITE_OK; |
| 112783 | 112689 | } |
| 112784 | 112690 | |
| 112785 | 112691 | /* |
| 112786 | 112692 | ** Configuration settings for an individual database connection |
| 112787 | 112693 | |