| | @@ -325,11 +325,11 @@ |
| 325 | 325 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 326 | 326 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 327 | 327 | */ |
| 328 | 328 | #define SQLITE_VERSION "3.8.11" |
| 329 | 329 | #define SQLITE_VERSION_NUMBER 3008011 |
| 330 | | -#define SQLITE_SOURCE_ID "2015-07-08 16:22:42 5348ffc3fda5168c1e9e14aa88b0c6aedbda7c94" |
| 330 | +#define SQLITE_SOURCE_ID "2015-07-23 20:44:49 017c5019e1ce042025d4f327e50ec50af49f9fa4" |
| 331 | 331 | |
| 332 | 332 | /* |
| 333 | 333 | ** CAPI3REF: Run-Time Library Version Numbers |
| 334 | 334 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 335 | 335 | ** |
| | @@ -1179,13 +1179,13 @@ |
| 1179 | 1179 | ** |
| 1180 | 1180 | ** <li>[[SQLITE_FCNTL_ZIPVFS]] |
| 1181 | 1181 | ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other |
| 1182 | 1182 | ** VFS should return SQLITE_NOTFOUND for this opcode. |
| 1183 | 1183 | ** |
| 1184 | | -** <li>[[SQLITE_FCNTL_OTA]] |
| 1185 | | -** The [SQLITE_FCNTL_OTA] opcode is implemented by the special VFS used by |
| 1186 | | -** the OTA extension only. All other VFS should return SQLITE_NOTFOUND for |
| 1184 | +** <li>[[SQLITE_FCNTL_RBU]] |
| 1185 | +** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by |
| 1186 | +** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for |
| 1187 | 1187 | ** this opcode. |
| 1188 | 1188 | ** </ul> |
| 1189 | 1189 | */ |
| 1190 | 1190 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 1191 | 1191 | #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2 |
| | @@ -1209,11 +1209,11 @@ |
| 1209 | 1209 | #define SQLITE_FCNTL_SYNC 21 |
| 1210 | 1210 | #define SQLITE_FCNTL_COMMIT_PHASETWO 22 |
| 1211 | 1211 | #define SQLITE_FCNTL_WIN32_SET_HANDLE 23 |
| 1212 | 1212 | #define SQLITE_FCNTL_WAL_BLOCK 24 |
| 1213 | 1213 | #define SQLITE_FCNTL_ZIPVFS 25 |
| 1214 | | -#define SQLITE_FCNTL_OTA 26 |
| 1214 | +#define SQLITE_FCNTL_RBU 26 |
| 1215 | 1215 | |
| 1216 | 1216 | /* deprecated names */ |
| 1217 | 1217 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 1218 | 1218 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 1219 | 1219 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| | @@ -8361,11 +8361,11 @@ |
| 8361 | 8361 | |
| 8362 | 8362 | /* |
| 8363 | 8363 | ** Make sure that the compiler intrinsics we desire are enabled when |
| 8364 | 8364 | ** compiling with an appropriate version of MSVC. |
| 8365 | 8365 | */ |
| 8366 | | -#if defined(_MSC_VER) && _MSC_VER>=1300 |
| 8366 | +#if defined(_MSC_VER) && _MSC_VER>=1300 && !defined(_WIN32_WCE) |
| 8367 | 8367 | # include <intrin.h> |
| 8368 | 8368 | # pragma intrinsic(_byteswap_ushort) |
| 8369 | 8369 | # pragma intrinsic(_byteswap_ulong) |
| 8370 | 8370 | #endif |
| 8371 | 8371 | |
| | @@ -9189,11 +9189,13 @@ |
| 9189 | 9189 | #endif |
| 9190 | 9190 | #ifndef SQLITE_MAX_MMAP_SIZE |
| 9191 | 9191 | # if defined(__linux__) \ |
| 9192 | 9192 | || defined(_WIN32) \ |
| 9193 | 9193 | || (defined(__APPLE__) && defined(__MACH__)) \ |
| 9194 | | - || defined(__sun) |
| 9194 | + || defined(__sun) \ |
| 9195 | + || defined(__FreeBSD__) \ |
| 9196 | + || defined(__DragonFly__) |
| 9195 | 9197 | # define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */ |
| 9196 | 9198 | # else |
| 9197 | 9199 | # define SQLITE_MAX_MMAP_SIZE 0 |
| 9198 | 9200 | # endif |
| 9199 | 9201 | # define SQLITE_MAX_MMAP_SIZE_xc 1 /* exclude from ctime.c */ |
| | @@ -13883,10 +13885,11 @@ |
| 13883 | 13885 | ** |
| 13884 | 13886 | ************************************************************************* |
| 13885 | 13887 | ** |
| 13886 | 13888 | ** This file contains definitions of global variables and constants. |
| 13887 | 13889 | */ |
| 13890 | +/* #include "sqliteInt.h" */ |
| 13888 | 13891 | |
| 13889 | 13892 | /* An array to map all upper-case characters into their corresponding |
| 13890 | 13893 | ** lower-case character. |
| 13891 | 13894 | ** |
| 13892 | 13895 | ** SQLite only considers US-ASCII (or EBCDIC) characters. We do not |
| | @@ -14122,10 +14125,11 @@ |
| 14122 | 14125 | */ |
| 14123 | 14126 | #ifndef SQLITE_OMIT_WSD |
| 14124 | 14127 | SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000; |
| 14125 | 14128 | #endif |
| 14126 | 14129 | |
| 14130 | +/* #include "opcodes.h" */ |
| 14127 | 14131 | /* |
| 14128 | 14132 | ** Properties of opcodes. The OPFLG_INITIALIZER macro is |
| 14129 | 14133 | ** created by mkopcodeh.awk during compilation. Data is obtained |
| 14130 | 14134 | ** from the comments following the "case OP_xxxx:" statements in |
| 14131 | 14135 | ** the vdbe.c file. |
| | @@ -14150,10 +14154,11 @@ |
| 14150 | 14154 | ** SQLite was built with. |
| 14151 | 14155 | */ |
| 14152 | 14156 | |
| 14153 | 14157 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 14154 | 14158 | |
| 14159 | +/* #include "sqliteInt.h" */ |
| 14155 | 14160 | |
| 14156 | 14161 | /* |
| 14157 | 14162 | ** An array of names of all compile-time options. This array should |
| 14158 | 14163 | ** be sorted A-Z. |
| 14159 | 14164 | ** |
| | @@ -14579,10 +14584,11 @@ |
| 14579 | 14584 | ************************************************************************* |
| 14580 | 14585 | ** |
| 14581 | 14586 | ** This module implements the sqlite3_status() interface and related |
| 14582 | 14587 | ** functionality. |
| 14583 | 14588 | */ |
| 14589 | +/* #include "sqliteInt.h" */ |
| 14584 | 14590 | /************** Include vdbeInt.h in the middle of status.c ******************/ |
| 14585 | 14591 | /************** Begin file vdbeInt.h *****************************************/ |
| 14586 | 14592 | /* |
| 14587 | 14593 | ** 2003 September 6 |
| 14588 | 14594 | ** |
| | @@ -15462,10 +15468,11 @@ |
| 15462 | 15468 | ** Astronomical Algorithms, 2nd Edition, 1998 |
| 15463 | 15469 | ** ISBM 0-943396-61-1 |
| 15464 | 15470 | ** Willmann-Bell, Inc |
| 15465 | 15471 | ** Richmond, Virginia (USA) |
| 15466 | 15472 | */ |
| 15473 | +/* #include "sqliteInt.h" */ |
| 15467 | 15474 | /* #include <stdlib.h> */ |
| 15468 | 15475 | /* #include <assert.h> */ |
| 15469 | 15476 | #include <time.h> |
| 15470 | 15477 | |
| 15471 | 15478 | #ifndef SQLITE_OMIT_DATETIME_FUNCS |
| | @@ -15773,11 +15780,11 @@ |
| 15773 | 15780 | Z = (int)((p->iJD + 43200000)/86400000); |
| 15774 | 15781 | A = (int)((Z - 1867216.25)/36524.25); |
| 15775 | 15782 | A = Z + 1 + A - (A/4); |
| 15776 | 15783 | B = A + 1524; |
| 15777 | 15784 | C = (int)((B - 122.1)/365.25); |
| 15778 | | - D = (36525*C)/100; |
| 15785 | + D = (36525*(C&32767))/100; |
| 15779 | 15786 | E = (int)((B-D)/30.6001); |
| 15780 | 15787 | X1 = (int)(30.6001*E); |
| 15781 | 15788 | p->D = B - D - X1; |
| 15782 | 15789 | p->M = E<14 ? E-1 : E-13; |
| 15783 | 15790 | p->Y = p->M>2 ? C - 4716 : C - 4715; |
| | @@ -16574,10 +16581,11 @@ |
| 16574 | 16581 | ** |
| 16575 | 16582 | ** This file contains OS interface code that is common to all |
| 16576 | 16583 | ** architectures. |
| 16577 | 16584 | */ |
| 16578 | 16585 | #define _SQLITE_OS_C_ 1 |
| 16586 | +/* #include "sqliteInt.h" */ |
| 16579 | 16587 | #undef _SQLITE_OS_C_ |
| 16580 | 16588 | |
| 16581 | 16589 | /* |
| 16582 | 16590 | ** The default SQLite sqlite3_vfs implementations do not allocate |
| 16583 | 16591 | ** memory (actually, os_unix.c allocates a small amount of memory |
| | @@ -16980,10 +16988,11 @@ |
| 16980 | 16988 | ** is completely recoverable simply by not carrying out the resize. The |
| 16981 | 16989 | ** hash table will continue to function normally. So a malloc failure |
| 16982 | 16990 | ** during a hash table resize is a benign fault. |
| 16983 | 16991 | */ |
| 16984 | 16992 | |
| 16993 | +/* #include "sqliteInt.h" */ |
| 16985 | 16994 | |
| 16986 | 16995 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 16987 | 16996 | |
| 16988 | 16997 | /* |
| 16989 | 16998 | ** Global variables. |
| | @@ -17061,10 +17070,11 @@ |
| 17061 | 17070 | ** SQLITE_ZERO_MALLOC is defined. The allocation drivers implemented |
| 17062 | 17071 | ** here always fail. SQLite will not operate with these drivers. These |
| 17063 | 17072 | ** are merely placeholders. Real drivers must be substituted using |
| 17064 | 17073 | ** sqlite3_config() before SQLite will operate. |
| 17065 | 17074 | */ |
| 17075 | +/* #include "sqliteInt.h" */ |
| 17066 | 17076 | |
| 17067 | 17077 | /* |
| 17068 | 17078 | ** This version of the memory allocator is the default. It is |
| 17069 | 17079 | ** used when no other memory allocator is specified using compile-time |
| 17070 | 17080 | ** macros. |
| | @@ -17147,10 +17157,11 @@ |
| 17147 | 17157 | ** SQLITE_WITHOUT_MSIZE Set this symbol to disable the use of |
| 17148 | 17158 | ** _msize() on windows systems. This might |
| 17149 | 17159 | ** be necessary when compiling for Delphi, |
| 17150 | 17160 | ** for example. |
| 17151 | 17161 | */ |
| 17162 | +/* #include "sqliteInt.h" */ |
| 17152 | 17163 | |
| 17153 | 17164 | /* |
| 17154 | 17165 | ** This version of the memory allocator is the default. It is |
| 17155 | 17166 | ** used when no other memory allocator is specified using compile-time |
| 17156 | 17167 | ** macros. |
| | @@ -17422,10 +17433,11 @@ |
| 17422 | 17433 | ** leaks and memory usage errors. |
| 17423 | 17434 | ** |
| 17424 | 17435 | ** This file contains implementations of the low-level memory allocation |
| 17425 | 17436 | ** routines specified in the sqlite3_mem_methods object. |
| 17426 | 17437 | */ |
| 17438 | +/* #include "sqliteInt.h" */ |
| 17427 | 17439 | |
| 17428 | 17440 | /* |
| 17429 | 17441 | ** This version of the memory allocator is used only if the |
| 17430 | 17442 | ** SQLITE_MEMDEBUG macro is defined |
| 17431 | 17443 | */ |
| | @@ -17956,10 +17968,11 @@ |
| 17956 | 17968 | ** be changed. |
| 17957 | 17969 | ** |
| 17958 | 17970 | ** This version of the memory allocation subsystem is included |
| 17959 | 17971 | ** in the build only if SQLITE_ENABLE_MEMSYS3 is defined. |
| 17960 | 17972 | */ |
| 17973 | +/* #include "sqliteInt.h" */ |
| 17961 | 17974 | |
| 17962 | 17975 | /* |
| 17963 | 17976 | ** This version of the memory allocator is only built into the library |
| 17964 | 17977 | ** SQLITE_ENABLE_MEMSYS3 is defined. Defining this symbol does not |
| 17965 | 17978 | ** mean that the library will use a memory-pool by default, just that |
| | @@ -18670,10 +18683,11 @@ |
| 18670 | 18683 | ** N >= M*(1 + log2(n)/2) - n + 1 |
| 18671 | 18684 | ** |
| 18672 | 18685 | ** The sqlite3_status() logic tracks the maximum values of n and M so |
| 18673 | 18686 | ** that an application can, at any time, verify this constraint. |
| 18674 | 18687 | */ |
| 18688 | +/* #include "sqliteInt.h" */ |
| 18675 | 18689 | |
| 18676 | 18690 | /* |
| 18677 | 18691 | ** This version of the memory allocator is used only when |
| 18678 | 18692 | ** SQLITE_ENABLE_MEMSYS5 is defined. |
| 18679 | 18693 | */ |
| | @@ -19213,10 +19227,11 @@ |
| 19213 | 19227 | ************************************************************************* |
| 19214 | 19228 | ** This file contains the C functions that implement mutexes. |
| 19215 | 19229 | ** |
| 19216 | 19230 | ** This file contains code that is common across all mutex implementations. |
| 19217 | 19231 | */ |
| 19232 | +/* #include "sqliteInt.h" */ |
| 19218 | 19233 | |
| 19219 | 19234 | #if defined(SQLITE_DEBUG) && !defined(SQLITE_MUTEX_OMIT) |
| 19220 | 19235 | /* |
| 19221 | 19236 | ** For debugging purposes, record when the mutex subsystem is initialized |
| 19222 | 19237 | ** and uninitialized so that we can assert() if there is an attempt to |
| | @@ -19386,10 +19401,11 @@ |
| 19386 | 19401 | ** |
| 19387 | 19402 | ** If compiled with SQLITE_DEBUG, then additional logic is inserted |
| 19388 | 19403 | ** that does error checking on mutexes to make sure they are being |
| 19389 | 19404 | ** called correctly. |
| 19390 | 19405 | */ |
| 19406 | +/* #include "sqliteInt.h" */ |
| 19391 | 19407 | |
| 19392 | 19408 | #ifndef SQLITE_MUTEX_OMIT |
| 19393 | 19409 | |
| 19394 | 19410 | #ifndef SQLITE_DEBUG |
| 19395 | 19411 | /* |
| | @@ -19589,10 +19605,11 @@ |
| 19589 | 19605 | ** May you share freely, never taking more than you give. |
| 19590 | 19606 | ** |
| 19591 | 19607 | ************************************************************************* |
| 19592 | 19608 | ** This file contains the C functions that implement mutexes for pthreads |
| 19593 | 19609 | */ |
| 19610 | +/* #include "sqliteInt.h" */ |
| 19594 | 19611 | |
| 19595 | 19612 | /* |
| 19596 | 19613 | ** The code in this file is only used if we are compiling threadsafe |
| 19597 | 19614 | ** under unix with pthreads. |
| 19598 | 19615 | ** |
| | @@ -19963,10 +19980,11 @@ |
| 19963 | 19980 | ** May you share freely, never taking more than you give. |
| 19964 | 19981 | ** |
| 19965 | 19982 | ************************************************************************* |
| 19966 | 19983 | ** This file contains the C functions that implement mutexes for Win32. |
| 19967 | 19984 | */ |
| 19985 | +/* #include "sqliteInt.h" */ |
| 19968 | 19986 | |
| 19969 | 19987 | #if SQLITE_OS_WIN |
| 19970 | 19988 | /* |
| 19971 | 19989 | ** Include code that is common to all os_*.c files |
| 19972 | 19990 | */ |
| | @@ -20638,10 +20656,11 @@ |
| 20638 | 20656 | ** |
| 20639 | 20657 | ************************************************************************* |
| 20640 | 20658 | ** |
| 20641 | 20659 | ** Memory allocation functions used throughout sqlite. |
| 20642 | 20660 | */ |
| 20661 | +/* #include "sqliteInt.h" */ |
| 20643 | 20662 | /* #include <stdarg.h> */ |
| 20644 | 20663 | |
| 20645 | 20664 | /* |
| 20646 | 20665 | ** Attempt to release up to n bytes of non-essential memory currently |
| 20647 | 20666 | ** held by SQLite. An example of non-essential memory is memory used to |
| | @@ -21449,10 +21468,11 @@ |
| 21449 | 21468 | ** This file contains code for a set of "printf"-like routines. These |
| 21450 | 21469 | ** routines format strings much like the printf() from the standard C |
| 21451 | 21470 | ** library, though the implementation here has enhancements to support |
| 21452 | 21471 | ** SQLite. |
| 21453 | 21472 | */ |
| 21473 | +/* #include "sqliteInt.h" */ |
| 21454 | 21474 | |
| 21455 | 21475 | /* |
| 21456 | 21476 | ** Conversion types fall into various categories as defined by the |
| 21457 | 21477 | ** following enumeration. |
| 21458 | 21478 | */ |
| | @@ -22451,10 +22471,15 @@ |
| 22451 | 22471 | ** stack space on small-stack systems when logging is disabled. |
| 22452 | 22472 | ** |
| 22453 | 22473 | ** sqlite3_log() must render into a static buffer. It cannot dynamically |
| 22454 | 22474 | ** allocate memory because it might be called while the memory allocator |
| 22455 | 22475 | ** mutex is held. |
| 22476 | +** |
| 22477 | +** sqlite3VXPrintf() might ask for *temporary* memory allocations for |
| 22478 | +** certain format characters (%q) or for very large precisions or widths. |
| 22479 | +** Care must be taken that any sqlite3_log() calls that occur while the |
| 22480 | +** memory mutex is held do not use these mechanisms. |
| 22456 | 22481 | */ |
| 22457 | 22482 | static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){ |
| 22458 | 22483 | StrAccum acc; /* String accumulator */ |
| 22459 | 22484 | char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */ |
| 22460 | 22485 | |
| | @@ -22526,10 +22551,11 @@ |
| 22526 | 22551 | ** analysis. |
| 22527 | 22552 | ** |
| 22528 | 22553 | ** The interfaces in this file is only available when compiling |
| 22529 | 22554 | ** with SQLITE_DEBUG. |
| 22530 | 22555 | */ |
| 22556 | +/* #include "sqliteInt.h" */ |
| 22531 | 22557 | #ifdef SQLITE_DEBUG |
| 22532 | 22558 | |
| 22533 | 22559 | /* |
| 22534 | 22560 | ** Add a new subitem to the tree. The moreToFollow flag indicates that this |
| 22535 | 22561 | ** is not the last item in the tree. |
| | @@ -22957,10 +22983,11 @@ |
| 22957 | 22983 | ** generator (PRNG) for SQLite. |
| 22958 | 22984 | ** |
| 22959 | 22985 | ** Random numbers are used by some of the database backends in order |
| 22960 | 22986 | ** to generate random integer keys for tables or random filenames. |
| 22961 | 22987 | */ |
| 22988 | +/* #include "sqliteInt.h" */ |
| 22962 | 22989 | |
| 22963 | 22990 | |
| 22964 | 22991 | /* All threads share a single random number generator. |
| 22965 | 22992 | ** This structure is the current state of the generator. |
| 22966 | 22993 | */ |
| | @@ -23103,11 +23130,13 @@ |
| 23103 | 23130 | ** single threaded systems. Nothing in SQLite requires multiple threads. |
| 23104 | 23131 | ** This interface exists so that applications that want to take advantage |
| 23105 | 23132 | ** of multiple cores can do so, while also allowing applications to stay |
| 23106 | 23133 | ** single-threaded if desired. |
| 23107 | 23134 | */ |
| 23135 | +/* #include "sqliteInt.h" */ |
| 23108 | 23136 | #if SQLITE_OS_WIN |
| 23137 | +/* # include "os_win.h" */ |
| 23109 | 23138 | #endif |
| 23110 | 23139 | |
| 23111 | 23140 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 23112 | 23141 | |
| 23113 | 23142 | /********************************* Unix Pthreads ****************************/ |
| | @@ -23377,11 +23406,13 @@ |
| 23377 | 23406 | ** BOM or Byte Order Mark: |
| 23378 | 23407 | ** 0xff 0xfe little-endian utf-16 follows |
| 23379 | 23408 | ** 0xfe 0xff big-endian utf-16 follows |
| 23380 | 23409 | ** |
| 23381 | 23410 | */ |
| 23411 | +/* #include "sqliteInt.h" */ |
| 23382 | 23412 | /* #include <assert.h> */ |
| 23413 | +/* #include "vdbeInt.h" */ |
| 23383 | 23414 | |
| 23384 | 23415 | #ifndef SQLITE_AMALGAMATION |
| 23385 | 23416 | /* |
| 23386 | 23417 | ** The following constant value is used by the SQLITE_BIGENDIAN and |
| 23387 | 23418 | ** SQLITE_LITTLEENDIAN macros. |
| | @@ -23890,10 +23921,11 @@ |
| 23890 | 23921 | ** |
| 23891 | 23922 | ** This file contains functions for allocating memory, comparing |
| 23892 | 23923 | ** strings, and stuff like that. |
| 23893 | 23924 | ** |
| 23894 | 23925 | */ |
| 23926 | +/* #include "sqliteInt.h" */ |
| 23895 | 23927 | /* #include <stdarg.h> */ |
| 23896 | 23928 | #if HAVE_ISNAN || SQLITE_HAVE_ISNAN |
| 23897 | 23929 | # include <math.h> |
| 23898 | 23930 | #endif |
| 23899 | 23931 | |
| | @@ -25286,10 +25318,11 @@ |
| 25286 | 25318 | ** |
| 25287 | 25319 | ************************************************************************* |
| 25288 | 25320 | ** This is the implementation of generic hash-tables |
| 25289 | 25321 | ** used in SQLite. |
| 25290 | 25322 | */ |
| 25323 | +/* #include "sqliteInt.h" */ |
| 25291 | 25324 | /* #include <assert.h> */ |
| 25292 | 25325 | |
| 25293 | 25326 | /* Turn bulk memory into a hash table object by initializing the |
| 25294 | 25327 | ** fields of the Hash structure. |
| 25295 | 25328 | ** |
| | @@ -25763,10 +25796,11 @@ |
| 25763 | 25796 | ** * sqlite3_vfs method implementations. |
| 25764 | 25797 | ** * Locking primitives for the proxy uber-locking-method. (MacOSX only) |
| 25765 | 25798 | ** * Definitions of sqlite3_vfs objects for all locking methods |
| 25766 | 25799 | ** plus implementations of sqlite3_os_init() and sqlite3_os_end(). |
| 25767 | 25800 | */ |
| 25801 | +/* #include "sqliteInt.h" */ |
| 25768 | 25802 | #if SQLITE_OS_UNIX /* This file is used on unix only */ |
| 25769 | 25803 | |
| 25770 | 25804 | /* |
| 25771 | 25805 | ** There are various methods for file locking used for concurrency |
| 25772 | 25806 | ** control: |
| | @@ -33497,10 +33531,11 @@ |
| 33497 | 33531 | ** |
| 33498 | 33532 | ****************************************************************************** |
| 33499 | 33533 | ** |
| 33500 | 33534 | ** This file contains code that is specific to Windows. |
| 33501 | 33535 | */ |
| 33536 | +/* #include "sqliteInt.h" */ |
| 33502 | 33537 | #if SQLITE_OS_WIN /* This file is used for Windows only */ |
| 33503 | 33538 | |
| 33504 | 33539 | /* |
| 33505 | 33540 | ** Include code that is common to all os_*.c files |
| 33506 | 33541 | */ |
| | @@ -33705,10 +33740,11 @@ |
| 33705 | 33740 | /************** Continuing where we left off in os_win.c *********************/ |
| 33706 | 33741 | |
| 33707 | 33742 | /* |
| 33708 | 33743 | ** Include the header file for the Windows VFS. |
| 33709 | 33744 | */ |
| 33745 | +/* #include "os_win.h" */ |
| 33710 | 33746 | |
| 33711 | 33747 | /* |
| 33712 | 33748 | ** Compiling and using WAL mode requires several APIs that are only |
| 33713 | 33749 | ** available in Windows platforms based on the NT kernel. |
| 33714 | 33750 | */ |
| | @@ -39358,10 +39394,11 @@ |
| 39358 | 39394 | ** sometimes grow into tens of thousands or larger. The size of the |
| 39359 | 39395 | ** Bitvec object is the number of pages in the database file at the |
| 39360 | 39396 | ** start of a transaction, and is thus usually less than a few thousand, |
| 39361 | 39397 | ** but can be as large as 2 billion for a really big database. |
| 39362 | 39398 | */ |
| 39399 | +/* #include "sqliteInt.h" */ |
| 39363 | 39400 | |
| 39364 | 39401 | /* Size of the Bitvec structure in bytes. */ |
| 39365 | 39402 | #define BITVEC_SZ 512 |
| 39366 | 39403 | |
| 39367 | 39404 | /* Round the union size down to the nearest pointer boundary, since that's how |
| | @@ -39747,10 +39784,11 @@ |
| 39747 | 39784 | ** May you share freely, never taking more than you give. |
| 39748 | 39785 | ** |
| 39749 | 39786 | ************************************************************************* |
| 39750 | 39787 | ** This file implements that page cache. |
| 39751 | 39788 | */ |
| 39789 | +/* #include "sqliteInt.h" */ |
| 39752 | 39790 | |
| 39753 | 39791 | /* |
| 39754 | 39792 | ** A complete page cache is an instance of this structure. |
| 39755 | 39793 | */ |
| 39756 | 39794 | struct PCache { |
| | @@ -40488,10 +40526,11 @@ |
| 40488 | 40526 | ** |
| 40489 | 40527 | ** Earlier versions of SQLite used only methods (1) and (2). But experiments |
| 40490 | 40528 | ** show that method (3) with N==100 provides about a 5% performance boost for |
| 40491 | 40529 | ** common workloads. |
| 40492 | 40530 | */ |
| 40531 | +/* #include "sqliteInt.h" */ |
| 40493 | 40532 | |
| 40494 | 40533 | typedef struct PCache1 PCache1; |
| 40495 | 40534 | typedef struct PgHdr1 PgHdr1; |
| 40496 | 40535 | typedef struct PgFreeslot PgFreeslot; |
| 40497 | 40536 | typedef struct PGroup PGroup; |
| | @@ -40598,10 +40637,11 @@ |
| 40598 | 40637 | ** fixed at sqlite3_initialize() time and do not require mutex protection. |
| 40599 | 40638 | ** The nFreeSlot and pFree values do require mutex protection. |
| 40600 | 40639 | */ |
| 40601 | 40640 | int isInit; /* True if initialized */ |
| 40602 | 40641 | int separateCache; /* Use a new PGroup for each PCache */ |
| 40642 | + int nInitPage; /* Initial bulk allocation size */ |
| 40603 | 40643 | int szSlot; /* Size of each free slot */ |
| 40604 | 40644 | int nSlot; /* The number of pcache slots */ |
| 40605 | 40645 | int nReserve; /* Try to keep nFreeSlot above this */ |
| 40606 | 40646 | void *pStart, *pEnd; /* Bounds of global page cache memory */ |
| 40607 | 40647 | /* Above requires no mutex. Use mutex below for variable that follow. */ |
| | @@ -40665,10 +40705,47 @@ |
| 40665 | 40705 | pBuf = (void*)&((char*)pBuf)[sz]; |
| 40666 | 40706 | } |
| 40667 | 40707 | pcache1.pEnd = pBuf; |
| 40668 | 40708 | } |
| 40669 | 40709 | } |
| 40710 | + |
| 40711 | +/* |
| 40712 | +** Try to initialize the pCache->pFree and pCache->pBulk fields. Return |
| 40713 | +** true if pCache->pFree ends up containing one or more free pages. |
| 40714 | +*/ |
| 40715 | +static int pcache1InitBulk(PCache1 *pCache){ |
| 40716 | + i64 szBulk; |
| 40717 | + char *zBulk; |
| 40718 | + if( pcache1.nInitPage==0 ) return 0; |
| 40719 | + /* Do not bother with a bulk allocation if the cache size very small */ |
| 40720 | + if( pCache->nMax<3 ) return 0; |
| 40721 | + sqlite3BeginBenignMalloc(); |
| 40722 | + if( pcache1.nInitPage>0 ){ |
| 40723 | + szBulk = pCache->szAlloc * (i64)pcache1.nInitPage; |
| 40724 | + }else{ |
| 40725 | + szBulk = -1024 * (i64)pcache1.nInitPage; |
| 40726 | + } |
| 40727 | + if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){ |
| 40728 | + szBulk = pCache->szAlloc*pCache->nMax; |
| 40729 | + } |
| 40730 | + zBulk = pCache->pBulk = sqlite3Malloc( szBulk ); |
| 40731 | + sqlite3EndBenignMalloc(); |
| 40732 | + if( zBulk ){ |
| 40733 | + int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc; |
| 40734 | + int i; |
| 40735 | + for(i=0; i<nBulk; i++){ |
| 40736 | + PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage]; |
| 40737 | + pX->page.pBuf = zBulk; |
| 40738 | + pX->page.pExtra = &pX[1]; |
| 40739 | + pX->isBulkLocal = 1; |
| 40740 | + pX->pNext = pCache->pFree; |
| 40741 | + pCache->pFree = pX; |
| 40742 | + zBulk += pCache->szAlloc; |
| 40743 | + } |
| 40744 | + } |
| 40745 | + return pCache->pFree!=0; |
| 40746 | +} |
| 40670 | 40747 | |
| 40671 | 40748 | /* |
| 40672 | 40749 | ** Malloc function used within this file to allocate space from the buffer |
| 40673 | 40750 | ** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no |
| 40674 | 40751 | ** such buffer exists or there is no space left in it, this function falls |
| | @@ -40766,11 +40843,11 @@ |
| 40766 | 40843 | static PgHdr1 *pcache1AllocPage(PCache1 *pCache){ |
| 40767 | 40844 | PgHdr1 *p = 0; |
| 40768 | 40845 | void *pPg; |
| 40769 | 40846 | |
| 40770 | 40847 | assert( sqlite3_mutex_held(pCache->pGroup->mutex) ); |
| 40771 | | - if( pCache->pFree ){ |
| 40848 | + if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){ |
| 40772 | 40849 | p = pCache->pFree; |
| 40773 | 40850 | pCache->pFree = p->pNext; |
| 40774 | 40851 | p->pNext = 0; |
| 40775 | 40852 | }else{ |
| 40776 | 40853 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| | @@ -40970,18 +41047,23 @@ |
| 40970 | 41047 | |
| 40971 | 41048 | /* |
| 40972 | 41049 | ** If there are currently more than nMaxPage pages allocated, try |
| 40973 | 41050 | ** to recycle pages to reduce the number allocated to nMaxPage. |
| 40974 | 41051 | */ |
| 40975 | | -static void pcache1EnforceMaxPage(PGroup *pGroup){ |
| 41052 | +static void pcache1EnforceMaxPage(PCache1 *pCache){ |
| 41053 | + PGroup *pGroup = pCache->pGroup; |
| 40976 | 41054 | assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 40977 | 41055 | while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){ |
| 40978 | 41056 | PgHdr1 *p = pGroup->pLruTail; |
| 40979 | 41057 | assert( p->pCache->pGroup==pGroup ); |
| 40980 | 41058 | assert( p->isPinned==0 ); |
| 40981 | 41059 | pcache1PinPage(p); |
| 40982 | 41060 | pcache1RemoveFromHash(p, 1); |
| 41061 | + } |
| 41062 | + if( pCache->nPage==0 && pCache->pBulk ){ |
| 41063 | + sqlite3_free(pCache->pBulk); |
| 41064 | + pCache->pBulk = pCache->pFree = 0; |
| 40983 | 41065 | } |
| 40984 | 41066 | } |
| 40985 | 41067 | |
| 40986 | 41068 | /* |
| 40987 | 41069 | ** Discard all pages from cache pCache with a page number (key value) |
| | @@ -41054,10 +41136,18 @@ |
| 41054 | 41136 | if( sqlite3GlobalConfig.bCoreMutex ){ |
| 41055 | 41137 | pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU); |
| 41056 | 41138 | pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM); |
| 41057 | 41139 | } |
| 41058 | 41140 | #endif |
| 41141 | + if( pcache1.separateCache |
| 41142 | + && sqlite3GlobalConfig.nPage!=0 |
| 41143 | + && sqlite3GlobalConfig.pPage==0 |
| 41144 | + ){ |
| 41145 | + pcache1.nInitPage = sqlite3GlobalConfig.nPage; |
| 41146 | + }else{ |
| 41147 | + pcache1.nInitPage = 0; |
| 41148 | + } |
| 41059 | 41149 | pcache1.grp.mxPinned = 10; |
| 41060 | 41150 | pcache1.isInit = 1; |
| 41061 | 41151 | return SQLITE_OK; |
| 41062 | 41152 | } |
| 41063 | 41153 | |
| | @@ -41108,40 +41198,10 @@ |
| 41108 | 41198 | pCache->nMin = 10; |
| 41109 | 41199 | pGroup->nMinPage += pCache->nMin; |
| 41110 | 41200 | pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage; |
| 41111 | 41201 | } |
| 41112 | 41202 | pcache1LeaveMutex(pGroup); |
| 41113 | | - /* Try to initialize the local bulk pagecache line allocation if using |
| 41114 | | - ** separate caches and if nPage!=0 */ |
| 41115 | | - if( pcache1.separateCache |
| 41116 | | - && sqlite3GlobalConfig.nPage!=0 |
| 41117 | | - && sqlite3GlobalConfig.pPage==0 |
| 41118 | | - ){ |
| 41119 | | - int szBulk; |
| 41120 | | - char *zBulk; |
| 41121 | | - sqlite3BeginBenignMalloc(); |
| 41122 | | - if( sqlite3GlobalConfig.nPage>0 ){ |
| 41123 | | - szBulk = pCache->szAlloc * sqlite3GlobalConfig.nPage; |
| 41124 | | - }else{ |
| 41125 | | - szBulk = -1024*sqlite3GlobalConfig.nPage; |
| 41126 | | - } |
| 41127 | | - zBulk = pCache->pBulk = sqlite3Malloc( szBulk ); |
| 41128 | | - sqlite3EndBenignMalloc(); |
| 41129 | | - if( zBulk ){ |
| 41130 | | - int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc; |
| 41131 | | - int i; |
| 41132 | | - for(i=0; i<nBulk; i++){ |
| 41133 | | - PgHdr1 *pX = (PgHdr1*)&zBulk[szPage]; |
| 41134 | | - pX->page.pBuf = zBulk; |
| 41135 | | - pX->page.pExtra = &pX[1]; |
| 41136 | | - pX->isBulkLocal = 1; |
| 41137 | | - pX->pNext = pCache->pFree; |
| 41138 | | - pCache->pFree = pX; |
| 41139 | | - zBulk += pCache->szAlloc; |
| 41140 | | - } |
| 41141 | | - } |
| 41142 | | - } |
| 41143 | 41203 | if( pCache->nHash==0 ){ |
| 41144 | 41204 | pcache1Destroy((sqlite3_pcache*)pCache); |
| 41145 | 41205 | pCache = 0; |
| 41146 | 41206 | } |
| 41147 | 41207 | } |
| | @@ -41160,11 +41220,11 @@ |
| 41160 | 41220 | pcache1EnterMutex(pGroup); |
| 41161 | 41221 | pGroup->nMaxPage += (nMax - pCache->nMax); |
| 41162 | 41222 | pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage; |
| 41163 | 41223 | pCache->nMax = nMax; |
| 41164 | 41224 | pCache->n90pct = pCache->nMax*9/10; |
| 41165 | | - pcache1EnforceMaxPage(pGroup); |
| 41225 | + pcache1EnforceMaxPage(pCache); |
| 41166 | 41226 | pcache1LeaveMutex(pGroup); |
| 41167 | 41227 | } |
| 41168 | 41228 | } |
| 41169 | 41229 | |
| 41170 | 41230 | /* |
| | @@ -41178,11 +41238,11 @@ |
| 41178 | 41238 | PGroup *pGroup = pCache->pGroup; |
| 41179 | 41239 | int savedMaxPage; |
| 41180 | 41240 | pcache1EnterMutex(pGroup); |
| 41181 | 41241 | savedMaxPage = pGroup->nMaxPage; |
| 41182 | 41242 | pGroup->nMaxPage = 0; |
| 41183 | | - pcache1EnforceMaxPage(pGroup); |
| 41243 | + pcache1EnforceMaxPage(pCache); |
| 41184 | 41244 | pGroup->nMaxPage = savedMaxPage; |
| 41185 | 41245 | pcache1LeaveMutex(pGroup); |
| 41186 | 41246 | } |
| 41187 | 41247 | } |
| 41188 | 41248 | |
| | @@ -41515,11 +41575,11 @@ |
| 41515 | 41575 | assert( pGroup->nMaxPage >= pCache->nMax ); |
| 41516 | 41576 | pGroup->nMaxPage -= pCache->nMax; |
| 41517 | 41577 | assert( pGroup->nMinPage >= pCache->nMin ); |
| 41518 | 41578 | pGroup->nMinPage -= pCache->nMin; |
| 41519 | 41579 | pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage; |
| 41520 | | - pcache1EnforceMaxPage(pGroup); |
| 41580 | + pcache1EnforceMaxPage(pCache); |
| 41521 | 41581 | pcache1LeaveMutex(pGroup); |
| 41522 | 41582 | sqlite3_free(pCache->pBulk); |
| 41523 | 41583 | sqlite3_free(pCache->apHash); |
| 41524 | 41584 | sqlite3_free(pCache); |
| 41525 | 41585 | } |
| | @@ -41679,10 +41739,11 @@ |
| 41679 | 41739 | ** primitives are constant time. The cost of DESTROY is O(N). |
| 41680 | 41740 | ** |
| 41681 | 41741 | ** There is an added cost of O(N) when switching between TEST and |
| 41682 | 41742 | ** SMALLEST primitives. |
| 41683 | 41743 | */ |
| 41744 | +/* #include "sqliteInt.h" */ |
| 41684 | 41745 | |
| 41685 | 41746 | |
| 41686 | 41747 | /* |
| 41687 | 41748 | ** Target size for allocation chunks. |
| 41688 | 41749 | */ |
| | @@ -42148,10 +42209,11 @@ |
| 42148 | 42209 | ** locking to prevent two processes from writing the same database |
| 42149 | 42210 | ** file simultaneously, or one process from reading the database while |
| 42150 | 42211 | ** another is writing. |
| 42151 | 42212 | */ |
| 42152 | 42213 | #ifndef SQLITE_OMIT_DISKIO |
| 42214 | +/* #include "sqliteInt.h" */ |
| 42153 | 42215 | /************** Include wal.h in the middle of pager.c ***********************/ |
| 42154 | 42216 | /************** Begin file wal.h *********************************************/ |
| 42155 | 42217 | /* |
| 42156 | 42218 | ** 2010 February 1 |
| 42157 | 42219 | ** |
| | @@ -42169,10 +42231,11 @@ |
| 42169 | 42231 | */ |
| 42170 | 42232 | |
| 42171 | 42233 | #ifndef _WAL_H_ |
| 42172 | 42234 | #define _WAL_H_ |
| 42173 | 42235 | |
| 42236 | +/* #include "sqliteInt.h" */ |
| 42174 | 42237 | |
| 42175 | 42238 | /* Additional values that can be added to the sync_flags argument of |
| 42176 | 42239 | ** sqlite3WalFrames(): |
| 42177 | 42240 | */ |
| 42178 | 42241 | #define WAL_SYNC_TRANSACTIONS 0x20 /* Sync at the end of each transaction */ |
| | @@ -49783,10 +49846,11 @@ |
| 49783 | 49846 | ** that correspond to frames greater than the new K value are removed |
| 49784 | 49847 | ** from the hash table at this point. |
| 49785 | 49848 | */ |
| 49786 | 49849 | #ifndef SQLITE_OMIT_WAL |
| 49787 | 49850 | |
| 49851 | +/* #include "wal.h" */ |
| 49788 | 49852 | |
| 49789 | 49853 | /* |
| 49790 | 49854 | ** Trace output macros |
| 49791 | 49855 | */ |
| 49792 | 49856 | #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) |
| | @@ -50188,13 +50252,13 @@ |
| 50188 | 50252 | |
| 50189 | 50253 | assert( pWal->writeLock ); |
| 50190 | 50254 | pWal->hdr.isInit = 1; |
| 50191 | 50255 | pWal->hdr.iVersion = WALINDEX_MAX_VERSION; |
| 50192 | 50256 | walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum); |
| 50193 | | - memcpy((void *)&aHdr[1], (void *)&pWal->hdr, sizeof(WalIndexHdr)); |
| 50257 | + memcpy((void*)&aHdr[1], (const void*)&pWal->hdr, sizeof(WalIndexHdr)); |
| 50194 | 50258 | walShmBarrier(pWal); |
| 50195 | | - memcpy((void *)&aHdr[0], (void *)&pWal->hdr, sizeof(WalIndexHdr)); |
| 50259 | + memcpy((void*)&aHdr[0], (const void*)&pWal->hdr, sizeof(WalIndexHdr)); |
| 50196 | 50260 | } |
| 50197 | 50261 | |
| 50198 | 50262 | /* |
| 50199 | 50263 | ** This function encodes a single frame header and writes it to a buffer |
| 50200 | 50264 | ** supplied by the caller. A frame-header is made up of a series of |
| | @@ -50492,17 +50556,17 @@ |
| 50492 | 50556 | #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT |
| 50493 | 50557 | /* Verify that the every entry in the mapping region is still reachable |
| 50494 | 50558 | ** via the hash table even after the cleanup. |
| 50495 | 50559 | */ |
| 50496 | 50560 | if( iLimit ){ |
| 50497 | | - int i; /* Loop counter */ |
| 50561 | + int j; /* Loop counter */ |
| 50498 | 50562 | int iKey; /* Hash key */ |
| 50499 | | - for(i=1; i<=iLimit; i++){ |
| 50500 | | - for(iKey=walHash(aPgno[i]); aHash[iKey]; iKey=walNextHash(iKey)){ |
| 50501 | | - if( aHash[iKey]==i ) break; |
| 50563 | + for(j=1; j<=iLimit; j++){ |
| 50564 | + for(iKey=walHash(aPgno[j]); aHash[iKey]; iKey=walNextHash(iKey)){ |
| 50565 | + if( aHash[iKey]==j ) break; |
| 50502 | 50566 | } |
| 50503 | | - assert( aHash[iKey]==i ); |
| 50567 | + assert( aHash[iKey]==j ); |
| 50504 | 50568 | } |
| 50505 | 50569 | } |
| 50506 | 50570 | #endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */ |
| 50507 | 50571 | } |
| 50508 | 50572 | |
| | @@ -51000,11 +51064,11 @@ |
| 51000 | 51064 | |
| 51001 | 51065 | const int nList = *pnList; /* Size of input list */ |
| 51002 | 51066 | int nMerge = 0; /* Number of elements in list aMerge */ |
| 51003 | 51067 | ht_slot *aMerge = 0; /* List to be merged */ |
| 51004 | 51068 | int iList; /* Index into input list */ |
| 51005 | | - int iSub = 0; /* Index into aSub array */ |
| 51069 | + u32 iSub = 0; /* Index into aSub array */ |
| 51006 | 51070 | struct Sublist aSub[13]; /* Array of sub-lists */ |
| 51007 | 51071 | |
| 51008 | 51072 | memset(aSub, 0, sizeof(aSub)); |
| 51009 | 51073 | assert( nList<=HASHTABLE_NPAGE && nList>0 ); |
| 51010 | 51074 | assert( HASHTABLE_NPAGE==(1<<(ArraySize(aSub)-1)) ); |
| | @@ -51011,11 +51075,13 @@ |
| 51011 | 51075 | |
| 51012 | 51076 | for(iList=0; iList<nList; iList++){ |
| 51013 | 51077 | nMerge = 1; |
| 51014 | 51078 | aMerge = &aList[iList]; |
| 51015 | 51079 | for(iSub=0; iList & (1<<iSub); iSub++){ |
| 51016 | | - struct Sublist *p = &aSub[iSub]; |
| 51080 | + struct Sublist *p; |
| 51081 | + assert( iSub<ArraySize(aSub) ); |
| 51082 | + p = &aSub[iSub]; |
| 51017 | 51083 | assert( p->aList && p->nList<=(1<<iSub) ); |
| 51018 | 51084 | assert( p->aList==&aList[iList&~((2<<iSub)-1)] ); |
| 51019 | 51085 | walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer); |
| 51020 | 51086 | } |
| 51021 | 51087 | aSub[iSub].aList = aMerge; |
| | @@ -51022,11 +51088,13 @@ |
| 51022 | 51088 | aSub[iSub].nList = nMerge; |
| 51023 | 51089 | } |
| 51024 | 51090 | |
| 51025 | 51091 | for(iSub++; iSub<ArraySize(aSub); iSub++){ |
| 51026 | 51092 | if( nList & (1<<iSub) ){ |
| 51027 | | - struct Sublist *p = &aSub[iSub]; |
| 51093 | + struct Sublist *p; |
| 51094 | + assert( iSub<ArraySize(aSub) ); |
| 51095 | + p = &aSub[iSub]; |
| 51028 | 51096 | assert( p->nList<=(1<<iSub) ); |
| 51029 | 51097 | assert( p->aList==&aList[nList&~((2<<iSub)-1)] ); |
| 51030 | 51098 | walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer); |
| 51031 | 51099 | } |
| 51032 | 51100 | } |
| | @@ -52933,10 +53001,11 @@ |
| 52933 | 53001 | ** SIZE DESCRIPTION |
| 52934 | 53002 | ** 4 Page number of next trunk page |
| 52935 | 53003 | ** 4 Number of leaf pointers on this page |
| 52936 | 53004 | ** * zero or more pages numbers of leaves |
| 52937 | 53005 | */ |
| 53006 | +/* #include "sqliteInt.h" */ |
| 52938 | 53007 | |
| 52939 | 53008 | |
| 52940 | 53009 | /* The following value is the maximum cell size assuming a maximum page |
| 52941 | 53010 | ** size give above. |
| 52942 | 53011 | */ |
| | @@ -53730,10 +53799,11 @@ |
| 53730 | 53799 | ************************************************************************* |
| 53731 | 53800 | ** This file implements an external (disk-based) database using BTrees. |
| 53732 | 53801 | ** See the header comment on "btreeInt.h" for additional information. |
| 53733 | 53802 | ** Including a description of file format and an overview of operation. |
| 53734 | 53803 | */ |
| 53804 | +/* #include "btreeInt.h" */ |
| 53735 | 53805 | |
| 53736 | 53806 | /* |
| 53737 | 53807 | ** The header string that appears at the beginning of every |
| 53738 | 53808 | ** SQLite database. |
| 53739 | 53809 | */ |
| | @@ -62675,11 +62745,11 @@ |
| 62675 | 62745 | u32 *heap = 0; /* Min-heap used for checking cell coverage */ |
| 62676 | 62746 | u32 x, prev = 0; /* Next and previous entry on the min-heap */ |
| 62677 | 62747 | const char *saved_zPfx = pCheck->zPfx; |
| 62678 | 62748 | int saved_v1 = pCheck->v1; |
| 62679 | 62749 | int saved_v2 = pCheck->v2; |
| 62680 | | - u8 savedIsInit; |
| 62750 | + u8 savedIsInit = 0; |
| 62681 | 62751 | |
| 62682 | 62752 | /* Check that the page exists |
| 62683 | 62753 | */ |
| 62684 | 62754 | pBt = pCheck->pBt; |
| 62685 | 62755 | usableSize = pBt->usableSize; |
| | @@ -63311,10 +63381,12 @@ |
| 63311 | 63381 | ** |
| 63312 | 63382 | ************************************************************************* |
| 63313 | 63383 | ** This file contains the implementation of the sqlite3_backup_XXX() |
| 63314 | 63384 | ** API functions and the related features. |
| 63315 | 63385 | */ |
| 63386 | +/* #include "sqliteInt.h" */ |
| 63387 | +/* #include "btreeInt.h" */ |
| 63316 | 63388 | |
| 63317 | 63389 | /* |
| 63318 | 63390 | ** Structure allocated for each backup operation. |
| 63319 | 63391 | */ |
| 63320 | 63392 | struct sqlite3_backup { |
| | @@ -64109,10 +64181,12 @@ |
| 64109 | 64181 | ** This file contains code use to manipulate "Mem" structure. A "Mem" |
| 64110 | 64182 | ** stores a single value in the VDBE. Mem is an opaque structure visible |
| 64111 | 64183 | ** only within the VDBE. Interface routines refer to a Mem using the |
| 64112 | 64184 | ** name sqlite_value |
| 64113 | 64185 | */ |
| 64186 | +/* #include "sqliteInt.h" */ |
| 64187 | +/* #include "vdbeInt.h" */ |
| 64114 | 64188 | |
| 64115 | 64189 | #ifdef SQLITE_DEBUG |
| 64116 | 64190 | /* |
| 64117 | 64191 | ** Check invariants on a Mem object. |
| 64118 | 64192 | ** |
| | @@ -65826,10 +65900,12 @@ |
| 65826 | 65900 | ** |
| 65827 | 65901 | ************************************************************************* |
| 65828 | 65902 | ** This file contains code used for creating, destroying, and populating |
| 65829 | 65903 | ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.) |
| 65830 | 65904 | */ |
| 65905 | +/* #include "sqliteInt.h" */ |
| 65906 | +/* #include "vdbeInt.h" */ |
| 65831 | 65907 | |
| 65832 | 65908 | /* |
| 65833 | 65909 | ** Create a new virtual database engine. |
| 65834 | 65910 | */ |
| 65835 | 65911 | SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse *pParse){ |
| | @@ -70074,10 +70150,12 @@ |
| 70074 | 70150 | ************************************************************************* |
| 70075 | 70151 | ** |
| 70076 | 70152 | ** This file contains code use to implement APIs that are part of the |
| 70077 | 70153 | ** VDBE. |
| 70078 | 70154 | */ |
| 70155 | +/* #include "sqliteInt.h" */ |
| 70156 | +/* #include "vdbeInt.h" */ |
| 70079 | 70157 | |
| 70080 | 70158 | #ifndef SQLITE_OMIT_DEPRECATED |
| 70081 | 70159 | /* |
| 70082 | 70160 | ** Return TRUE (non-zero) of the statement supplied as an argument needs |
| 70083 | 70161 | ** to be recompiled. A statement needs to be recompiled whenever the |
| | @@ -70112,10 +70190,35 @@ |
| 70112 | 70190 | }else{ |
| 70113 | 70191 | return vdbeSafety(p); |
| 70114 | 70192 | } |
| 70115 | 70193 | } |
| 70116 | 70194 | |
| 70195 | +#ifndef SQLITE_OMIT_TRACE |
| 70196 | +/* |
| 70197 | +** Invoke the profile callback. This routine is only called if we already |
| 70198 | +** know that the profile callback is defined and needs to be invoked. |
| 70199 | +*/ |
| 70200 | +static SQLITE_NOINLINE void invokeProfileCallback(sqlite3 *db, Vdbe *p){ |
| 70201 | + sqlite3_int64 iNow; |
| 70202 | + assert( p->startTime>0 ); |
| 70203 | + assert( db->xProfile!=0 ); |
| 70204 | + assert( db->init.busy==0 ); |
| 70205 | + assert( p->zSql!=0 ); |
| 70206 | + sqlite3OsCurrentTimeInt64(db->pVfs, &iNow); |
| 70207 | + db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000); |
| 70208 | + p->startTime = 0; |
| 70209 | +} |
| 70210 | +/* |
| 70211 | +** The checkProfileCallback(DB,P) macro checks to see if a profile callback |
| 70212 | +** is needed, and it invokes the callback if it is needed. |
| 70213 | +*/ |
| 70214 | +# define checkProfileCallback(DB,P) \ |
| 70215 | + if( ((P)->startTime)>0 ){ invokeProfileCallback(DB,P); } |
| 70216 | +#else |
| 70217 | +# define checkProfileCallback(DB,P) /*no-op*/ |
| 70218 | +#endif |
| 70219 | + |
| 70117 | 70220 | /* |
| 70118 | 70221 | ** The following routine destroys a virtual machine that is created by |
| 70119 | 70222 | ** the sqlite3_compile() routine. The integer returned is an SQLITE_ |
| 70120 | 70223 | ** success/failure code that describes the result of executing the virtual |
| 70121 | 70224 | ** machine. |
| | @@ -70132,10 +70235,11 @@ |
| 70132 | 70235 | }else{ |
| 70133 | 70236 | Vdbe *v = (Vdbe*)pStmt; |
| 70134 | 70237 | sqlite3 *db = v->db; |
| 70135 | 70238 | if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT; |
| 70136 | 70239 | sqlite3_mutex_enter(db->mutex); |
| 70240 | + checkProfileCallback(db, v); |
| 70137 | 70241 | rc = sqlite3VdbeFinalize(v); |
| 70138 | 70242 | rc = sqlite3ApiExit(db, rc); |
| 70139 | 70243 | sqlite3LeaveMutexAndCloseZombie(db); |
| 70140 | 70244 | } |
| 70141 | 70245 | return rc; |
| | @@ -70153,16 +70257,18 @@ |
| 70153 | 70257 | int rc; |
| 70154 | 70258 | if( pStmt==0 ){ |
| 70155 | 70259 | rc = SQLITE_OK; |
| 70156 | 70260 | }else{ |
| 70157 | 70261 | Vdbe *v = (Vdbe*)pStmt; |
| 70158 | | - sqlite3_mutex_enter(v->db->mutex); |
| 70262 | + sqlite3 *db = v->db; |
| 70263 | + sqlite3_mutex_enter(db->mutex); |
| 70264 | + checkProfileCallback(db, v); |
| 70159 | 70265 | rc = sqlite3VdbeReset(v); |
| 70160 | 70266 | sqlite3VdbeRewind(v); |
| 70161 | | - assert( (rc & (v->db->errMask))==rc ); |
| 70162 | | - rc = sqlite3ApiExit(v->db, rc); |
| 70163 | | - sqlite3_mutex_leave(v->db->mutex); |
| 70267 | + assert( (rc & (db->errMask))==rc ); |
| 70268 | + rc = sqlite3ApiExit(db, rc); |
| 70269 | + sqlite3_mutex_leave(db->mutex); |
| 70164 | 70270 | } |
| 70165 | 70271 | return rc; |
| 70166 | 70272 | } |
| 70167 | 70273 | |
| 70168 | 70274 | /* |
| | @@ -70508,10 +70614,11 @@ |
| 70508 | 70614 | } |
| 70509 | 70615 | } |
| 70510 | 70616 | #endif |
| 70511 | 70617 | return rc; |
| 70512 | 70618 | } |
| 70619 | + |
| 70513 | 70620 | |
| 70514 | 70621 | /* |
| 70515 | 70622 | ** Execute the statement pStmt, either until a row of data is ready, the |
| 70516 | 70623 | ** statement is completely executed or an error occurs. |
| 70517 | 70624 | ** |
| | @@ -70577,12 +70684,14 @@ |
| 70577 | 70684 | assert( db->nVdbeWrite>0 || db->autoCommit==0 |
| 70578 | 70685 | || (db->nDeferredCons==0 && db->nDeferredImmCons==0) |
| 70579 | 70686 | ); |
| 70580 | 70687 | |
| 70581 | 70688 | #ifndef SQLITE_OMIT_TRACE |
| 70582 | | - if( db->xProfile && !db->init.busy ){ |
| 70689 | + if( db->xProfile && !db->init.busy && p->zSql ){ |
| 70583 | 70690 | sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime); |
| 70691 | + }else{ |
| 70692 | + assert( p->startTime==0 ); |
| 70584 | 70693 | } |
| 70585 | 70694 | #endif |
| 70586 | 70695 | |
| 70587 | 70696 | db->nVdbeActive++; |
| 70588 | 70697 | if( p->readOnly==0 ) db->nVdbeWrite++; |
| | @@ -70602,17 +70711,12 @@ |
| 70602 | 70711 | rc = sqlite3VdbeExec(p); |
| 70603 | 70712 | db->nVdbeExec--; |
| 70604 | 70713 | } |
| 70605 | 70714 | |
| 70606 | 70715 | #ifndef SQLITE_OMIT_TRACE |
| 70607 | | - /* Invoke the profile callback if there is one |
| 70608 | | - */ |
| 70609 | | - if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){ |
| 70610 | | - sqlite3_int64 iNow; |
| 70611 | | - sqlite3OsCurrentTimeInt64(db->pVfs, &iNow); |
| 70612 | | - db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000); |
| 70613 | | - } |
| 70716 | + /* If the statement completed successfully, invoke the profile callback */ |
| 70717 | + if( rc!=SQLITE_ROW ) checkProfileCallback(db, p); |
| 70614 | 70718 | #endif |
| 70615 | 70719 | |
| 70616 | 70720 | if( rc==SQLITE_DONE ){ |
| 70617 | 70721 | assert( p->rc==SQLITE_OK ); |
| 70618 | 70722 | p->rc = doWalCallbacks(db); |
| | @@ -71685,10 +71789,12 @@ |
| 71685 | 71789 | ** This file contains code used to insert the values of host parameters |
| 71686 | 71790 | ** (aka "wildcards") into the SQL text output by sqlite3_trace(). |
| 71687 | 71791 | ** |
| 71688 | 71792 | ** The Vdbe parse-tree explainer is also found here. |
| 71689 | 71793 | */ |
| 71794 | +/* #include "sqliteInt.h" */ |
| 71795 | +/* #include "vdbeInt.h" */ |
| 71690 | 71796 | |
| 71691 | 71797 | #ifndef SQLITE_OMIT_TRACE |
| 71692 | 71798 | |
| 71693 | 71799 | /* |
| 71694 | 71800 | ** zSql is a zero-terminated string of UTF-8 SQL text. Return the number of |
| | @@ -71877,10 +71983,12 @@ |
| 71877 | 71983 | ** documentation, headers files, or other derived files. The formatting |
| 71878 | 71984 | ** of the code in this file is, therefore, important. See other comments |
| 71879 | 71985 | ** in this file for details. If in doubt, do not deviate from existing |
| 71880 | 71986 | ** commenting and indentation practices when changing or adding code. |
| 71881 | 71987 | */ |
| 71988 | +/* #include "sqliteInt.h" */ |
| 71989 | +/* #include "vdbeInt.h" */ |
| 71882 | 71990 | |
| 71883 | 71991 | /* |
| 71884 | 71992 | ** Invoke this macro on memory cells just prior to changing the |
| 71885 | 71993 | ** value of the cell. This macro verifies that shallow copies are |
| 71886 | 71994 | ** not misused. A shallow copy of a string or blob just copies a |
| | @@ -78635,10 +78743,12 @@ |
| 78635 | 78743 | ************************************************************************* |
| 78636 | 78744 | ** |
| 78637 | 78745 | ** This file contains code used to implement incremental BLOB I/O. |
| 78638 | 78746 | */ |
| 78639 | 78747 | |
| 78748 | +/* #include "sqliteInt.h" */ |
| 78749 | +/* #include "vdbeInt.h" */ |
| 78640 | 78750 | |
| 78641 | 78751 | #ifndef SQLITE_OMIT_INCRBLOB |
| 78642 | 78752 | |
| 78643 | 78753 | /* |
| 78644 | 78754 | ** Valid sqlite3_blob* handles point to Incrblob structures. |
| | @@ -79233,10 +79343,12 @@ |
| 79233 | 79343 | ** than one background thread may be created. Specifically, there may be |
| 79234 | 79344 | ** one background thread for each temporary file on disk, and one background |
| 79235 | 79345 | ** thread to merge the output of each of the others to a single PMA for |
| 79236 | 79346 | ** the main thread to read from. |
| 79237 | 79347 | */ |
| 79348 | +/* #include "sqliteInt.h" */ |
| 79349 | +/* #include "vdbeInt.h" */ |
| 79238 | 79350 | |
| 79239 | 79351 | /* |
| 79240 | 79352 | ** If SQLITE_DEBUG_SORTER_THREADS is defined, this module outputs various |
| 79241 | 79353 | ** messages to stderr that may be helpful in understanding the performance |
| 79242 | 79354 | ** characteristics of the sorter in multi-threaded mode. |
| | @@ -81849,10 +81961,11 @@ |
| 81849 | 81961 | ** 1) The in-memory representation grows too large for the allocated |
| 81850 | 81962 | ** buffer, or |
| 81851 | 81963 | ** 2) The sqlite3JournalCreate() function is called. |
| 81852 | 81964 | */ |
| 81853 | 81965 | #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 81966 | +/* #include "sqliteInt.h" */ |
| 81854 | 81967 | |
| 81855 | 81968 | |
| 81856 | 81969 | /* |
| 81857 | 81970 | ** A JournalFile object is a subclass of sqlite3_file used by |
| 81858 | 81971 | ** as an open file handle for journal files. |
| | @@ -82096,10 +82209,11 @@ |
| 82096 | 82209 | ** |
| 82097 | 82210 | ** This file contains code use to implement an in-memory rollback journal. |
| 82098 | 82211 | ** The in-memory rollback journal is used to journal transactions for |
| 82099 | 82212 | ** ":memory:" databases and when the journal_mode=MEMORY pragma is used. |
| 82100 | 82213 | */ |
| 82214 | +/* #include "sqliteInt.h" */ |
| 82101 | 82215 | |
| 82102 | 82216 | /* Forward references to internal structures */ |
| 82103 | 82217 | typedef struct MemJournal MemJournal; |
| 82104 | 82218 | typedef struct FilePoint FilePoint; |
| 82105 | 82219 | typedef struct FileChunk FileChunk; |
| | @@ -82351,10 +82465,11 @@ |
| 82351 | 82465 | ** |
| 82352 | 82466 | ************************************************************************* |
| 82353 | 82467 | ** This file contains routines used for walking the parser tree for |
| 82354 | 82468 | ** an SQL statement. |
| 82355 | 82469 | */ |
| 82470 | +/* #include "sqliteInt.h" */ |
| 82356 | 82471 | /* #include <stdlib.h> */ |
| 82357 | 82472 | /* #include <string.h> */ |
| 82358 | 82473 | |
| 82359 | 82474 | |
| 82360 | 82475 | /* |
| | @@ -82509,10 +82624,11 @@ |
| 82509 | 82624 | ** |
| 82510 | 82625 | ** This file contains routines used for walking the parser tree and |
| 82511 | 82626 | ** resolve all identifiers by associating them with a particular |
| 82512 | 82627 | ** table and column. |
| 82513 | 82628 | */ |
| 82629 | +/* #include "sqliteInt.h" */ |
| 82514 | 82630 | /* #include <stdlib.h> */ |
| 82515 | 82631 | /* #include <string.h> */ |
| 82516 | 82632 | |
| 82517 | 82633 | /* |
| 82518 | 82634 | ** Walk the expression tree pExpr and increase the aggregate function |
| | @@ -84021,10 +84137,11 @@ |
| 84021 | 84137 | ** |
| 84022 | 84138 | ************************************************************************* |
| 84023 | 84139 | ** This file contains routines used for analyzing expressions and |
| 84024 | 84140 | ** for generating VDBE code that evaluates expressions in SQLite. |
| 84025 | 84141 | */ |
| 84142 | +/* #include "sqliteInt.h" */ |
| 84026 | 84143 | |
| 84027 | 84144 | /* |
| 84028 | 84145 | ** Return the 'affinity' of the expression pExpr if any. |
| 84029 | 84146 | ** |
| 84030 | 84147 | ** If pExpr is a column, a reference to a column via an 'AS' alias, |
| | @@ -88183,10 +88300,11 @@ |
| 88183 | 88300 | ** |
| 88184 | 88301 | ************************************************************************* |
| 88185 | 88302 | ** This file contains C code routines that used to generate VDBE code |
| 88186 | 88303 | ** that implements the ALTER TABLE command. |
| 88187 | 88304 | */ |
| 88305 | +/* #include "sqliteInt.h" */ |
| 88188 | 88306 | |
| 88189 | 88307 | /* |
| 88190 | 88308 | ** The code in this file only exists if we are not omitting the |
| 88191 | 88309 | ** ALTER TABLE logic from the build. |
| 88192 | 88310 | */ |
| | @@ -89145,10 +89263,11 @@ |
| 89145 | 89263 | ** sqlite_stat4.sample. The nEq, nLt, and nDLt entries of sqlite_stat3 |
| 89146 | 89264 | ** all contain just a single integer which is the same as the first |
| 89147 | 89265 | ** integer in the equivalent columns in sqlite_stat4. |
| 89148 | 89266 | */ |
| 89149 | 89267 | #ifndef SQLITE_OMIT_ANALYZE |
| 89268 | +/* #include "sqliteInt.h" */ |
| 89150 | 89269 | |
| 89151 | 89270 | #if defined(SQLITE_ENABLE_STAT4) |
| 89152 | 89271 | # define IsStat4 1 |
| 89153 | 89272 | # define IsStat3 0 |
| 89154 | 89273 | #elif defined(SQLITE_ENABLE_STAT3) |
| | @@ -90910,10 +91029,11 @@ |
| 90910 | 91029 | ** May you share freely, never taking more than you give. |
| 90911 | 91030 | ** |
| 90912 | 91031 | ************************************************************************* |
| 90913 | 91032 | ** This file contains code used to implement the ATTACH and DETACH commands. |
| 90914 | 91033 | */ |
| 91034 | +/* #include "sqliteInt.h" */ |
| 90915 | 91035 | |
| 90916 | 91036 | #ifndef SQLITE_OMIT_ATTACH |
| 90917 | 91037 | /* |
| 90918 | 91038 | ** Resolve an expression that was part of an ATTACH or DETACH statement. This |
| 90919 | 91039 | ** is slightly different from resolving a normal SQL expression, because simple |
| | @@ -91499,10 +91619,11 @@ |
| 91499 | 91619 | ** This file contains code used to implement the sqlite3_set_authorizer() |
| 91500 | 91620 | ** API. This facility is an optional feature of the library. Embedded |
| 91501 | 91621 | ** systems that do not need this facility may omit it by recompiling |
| 91502 | 91622 | ** the library with -DSQLITE_OMIT_AUTHORIZATION=1 |
| 91503 | 91623 | */ |
| 91624 | +/* #include "sqliteInt.h" */ |
| 91504 | 91625 | |
| 91505 | 91626 | /* |
| 91506 | 91627 | ** All of the code in this file may be omitted by defining a single |
| 91507 | 91628 | ** macro. |
| 91508 | 91629 | */ |
| | @@ -91769,10 +91890,11 @@ |
| 91769 | 91890 | ** creating ID lists |
| 91770 | 91891 | ** BEGIN TRANSACTION |
| 91771 | 91892 | ** COMMIT |
| 91772 | 91893 | ** ROLLBACK |
| 91773 | 91894 | */ |
| 91895 | +/* #include "sqliteInt.h" */ |
| 91774 | 91896 | |
| 91775 | 91897 | /* |
| 91776 | 91898 | ** This routine is called when a new SQL statement is beginning to |
| 91777 | 91899 | ** be parsed. Initialize the pParse structure as needed. |
| 91778 | 91900 | */ |
| | @@ -96089,10 +96211,11 @@ |
| 96089 | 96211 | ** |
| 96090 | 96212 | ** This file contains functions used to access the internal hash tables |
| 96091 | 96213 | ** of user defined functions and collation sequences. |
| 96092 | 96214 | */ |
| 96093 | 96215 | |
| 96216 | +/* #include "sqliteInt.h" */ |
| 96094 | 96217 | |
| 96095 | 96218 | /* |
| 96096 | 96219 | ** Invoke the 'collation needed' callback to request a collation sequence |
| 96097 | 96220 | ** in the encoding enc of name zName, length nName. |
| 96098 | 96221 | */ |
| | @@ -96566,10 +96689,11 @@ |
| 96566 | 96689 | ** |
| 96567 | 96690 | ************************************************************************* |
| 96568 | 96691 | ** This file contains C code routines that are called by the parser |
| 96569 | 96692 | ** in order to generate code for DELETE FROM statements. |
| 96570 | 96693 | */ |
| 96694 | +/* #include "sqliteInt.h" */ |
| 96571 | 96695 | |
| 96572 | 96696 | /* |
| 96573 | 96697 | ** While a SrcList can in general represent multiple tables and subqueries |
| 96574 | 96698 | ** (as in the FROM clause of a SELECT statement) in this case it contains |
| 96575 | 96699 | ** the name of a single table, as one might find in an INSERT, DELETE, |
| | @@ -97408,12 +97532,14 @@ |
| 97408 | 97532 | ************************************************************************* |
| 97409 | 97533 | ** This file contains the C-language implementations for many of the SQL |
| 97410 | 97534 | ** functions of SQLite. (Some function, and in particular the date and |
| 97411 | 97535 | ** time functions, are implemented separately.) |
| 97412 | 97536 | */ |
| 97537 | +/* #include "sqliteInt.h" */ |
| 97413 | 97538 | /* #include <stdlib.h> */ |
| 97414 | 97539 | /* #include <assert.h> */ |
| 97540 | +/* #include "vdbeInt.h" */ |
| 97415 | 97541 | |
| 97416 | 97542 | /* |
| 97417 | 97543 | ** Return the collating function associated with a function. |
| 97418 | 97544 | */ |
| 97419 | 97545 | static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){ |
| | @@ -99205,10 +99331,11 @@ |
| 99205 | 99331 | ** |
| 99206 | 99332 | ************************************************************************* |
| 99207 | 99333 | ** This file contains code used by the compiler to add foreign key |
| 99208 | 99334 | ** support to compiled SQL statements. |
| 99209 | 99335 | */ |
| 99336 | +/* #include "sqliteInt.h" */ |
| 99210 | 99337 | |
| 99211 | 99338 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 99212 | 99339 | #ifndef SQLITE_OMIT_TRIGGER |
| 99213 | 99340 | |
| 99214 | 99341 | /* |
| | @@ -100609,10 +100736,11 @@ |
| 100609 | 100736 | ** |
| 100610 | 100737 | ************************************************************************* |
| 100611 | 100738 | ** This file contains C code routines that are called by the parser |
| 100612 | 100739 | ** to handle INSERT statements in SQLite. |
| 100613 | 100740 | */ |
| 100741 | +/* #include "sqliteInt.h" */ |
| 100614 | 100742 | |
| 100615 | 100743 | /* |
| 100616 | 100744 | ** Generate code that will |
| 100617 | 100745 | ** |
| 100618 | 100746 | ** (1) acquire a lock for table pTab then |
| | @@ -102671,10 +102799,11 @@ |
| 102671 | 102799 | ** implement the programmer interface to the library. Routines in |
| 102672 | 102800 | ** other files are for internal use by SQLite and should not be |
| 102673 | 102801 | ** accessed by users of the library. |
| 102674 | 102802 | */ |
| 102675 | 102803 | |
| 102804 | +/* #include "sqliteInt.h" */ |
| 102676 | 102805 | |
| 102677 | 102806 | /* |
| 102678 | 102807 | ** Execute SQL code. Return one of the SQLITE_ success/failure |
| 102679 | 102808 | ** codes. Also write an error message into memory obtained from |
| 102680 | 102809 | ** malloc() and make *pzErrMsg point to that message. |
| | @@ -102839,10 +102968,11 @@ |
| 102839 | 102968 | ** as extensions by SQLite should #include this file instead of |
| 102840 | 102969 | ** sqlite3.h. |
| 102841 | 102970 | */ |
| 102842 | 102971 | #ifndef _SQLITE3EXT_H_ |
| 102843 | 102972 | #define _SQLITE3EXT_H_ |
| 102973 | +/* #include "sqlite3.h" */ |
| 102844 | 102974 | |
| 102845 | 102975 | typedef struct sqlite3_api_routines sqlite3_api_routines; |
| 102846 | 102976 | |
| 102847 | 102977 | /* |
| 102848 | 102978 | ** The following structure holds pointers to all of the SQLite API |
| | @@ -103345,10 +103475,11 @@ |
| 103345 | 103475 | |
| 103346 | 103476 | #endif /* _SQLITE3EXT_H_ */ |
| 103347 | 103477 | |
| 103348 | 103478 | /************** End of sqlite3ext.h ******************************************/ |
| 103349 | 103479 | /************** Continuing where we left off in loadext.c ********************/ |
| 103480 | +/* #include "sqliteInt.h" */ |
| 103350 | 103481 | /* #include <string.h> */ |
| 103351 | 103482 | |
| 103352 | 103483 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 103353 | 103484 | |
| 103354 | 103485 | /* |
| | @@ -104114,10 +104245,11 @@ |
| 104114 | 104245 | ** May you share freely, never taking more than you give. |
| 104115 | 104246 | ** |
| 104116 | 104247 | ************************************************************************* |
| 104117 | 104248 | ** This file contains code used to implement the PRAGMA command. |
| 104118 | 104249 | */ |
| 104250 | +/* #include "sqliteInt.h" */ |
| 104119 | 104251 | |
| 104120 | 104252 | #if !defined(SQLITE_ENABLE_LOCKING_STYLE) |
| 104121 | 104253 | # if defined(__APPLE__) |
| 104122 | 104254 | # define SQLITE_ENABLE_LOCKING_STYLE 1 |
| 104123 | 104255 | # else |
| | @@ -104220,11 +104352,11 @@ |
| 104220 | 104352 | /* ePragFlag: */ 0, |
| 104221 | 104353 | /* iArg: */ 0 }, |
| 104222 | 104354 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 104223 | 104355 | { /* zName: */ "cache_size", |
| 104224 | 104356 | /* ePragTyp: */ PragTyp_CACHE_SIZE, |
| 104225 | | - /* ePragFlag: */ PragFlag_NeedSchema, |
| 104357 | + /* ePragFlag: */ 0, |
| 104226 | 104358 | /* iArg: */ 0 }, |
| 104227 | 104359 | #endif |
| 104228 | 104360 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 104229 | 104361 | { /* zName: */ "cache_spill", |
| 104230 | 104362 | /* ePragTyp: */ PragTyp_FLAG, |
| | @@ -105290,10 +105422,11 @@ |
| 105290 | 105422 | ** of memory. |
| 105291 | 105423 | */ |
| 105292 | 105424 | case PragTyp_CACHE_SIZE: { |
| 105293 | 105425 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 105294 | 105426 | if( !zRight ){ |
| 105427 | + if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 105295 | 105428 | returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); |
| 105296 | 105429 | }else{ |
| 105297 | 105430 | int size = sqlite3Atoi(zRight); |
| 105298 | 105431 | pDb->pSchema->cache_size = size; |
| 105299 | 105432 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
| | @@ -106565,10 +106698,11 @@ |
| 106565 | 106698 | ************************************************************************* |
| 106566 | 106699 | ** This file contains the implementation of the sqlite3_prepare() |
| 106567 | 106700 | ** interface, and routines that contribute to loading the database schema |
| 106568 | 106701 | ** from disk. |
| 106569 | 106702 | */ |
| 106703 | +/* #include "sqliteInt.h" */ |
| 106570 | 106704 | |
| 106571 | 106705 | /* |
| 106572 | 106706 | ** Fill the InitData structure with an error message that indicates |
| 106573 | 106707 | ** that the database is corrupt. |
| 106574 | 106708 | */ |
| | @@ -107459,10 +107593,11 @@ |
| 107459 | 107593 | ** |
| 107460 | 107594 | ************************************************************************* |
| 107461 | 107595 | ** This file contains C code routines that are called by the parser |
| 107462 | 107596 | ** to handle SELECT statements in SQLite. |
| 107463 | 107597 | */ |
| 107598 | +/* #include "sqliteInt.h" */ |
| 107464 | 107599 | |
| 107465 | 107600 | /* |
| 107466 | 107601 | ** Trace output macros |
| 107467 | 107602 | */ |
| 107468 | 107603 | #if SELECTTRACE_ENABLED |
| | @@ -108528,11 +108663,10 @@ |
| 108528 | 108663 | } |
| 108529 | 108664 | } |
| 108530 | 108665 | return pInfo; |
| 108531 | 108666 | } |
| 108532 | 108667 | |
| 108533 | | -#ifndef SQLITE_OMIT_COMPOUND_SELECT |
| 108534 | 108668 | /* |
| 108535 | 108669 | ** Name of the connection operator, used for error messages. |
| 108536 | 108670 | */ |
| 108537 | 108671 | static const char *selectOpName(int id){ |
| 108538 | 108672 | char *z; |
| | @@ -108542,11 +108676,10 @@ |
| 108542 | 108676 | case TK_EXCEPT: z = "EXCEPT"; break; |
| 108543 | 108677 | default: z = "UNION"; break; |
| 108544 | 108678 | } |
| 108545 | 108679 | return z; |
| 108546 | 108680 | } |
| 108547 | | -#endif /* SQLITE_OMIT_COMPOUND_SELECT */ |
| 108548 | 108681 | |
| 108549 | 108682 | #ifndef SQLITE_OMIT_EXPLAIN |
| 108550 | 108683 | /* |
| 108551 | 108684 | ** Unless an "EXPLAIN QUERY PLAN" command is being processed, this function |
| 108552 | 108685 | ** is a no-op. Otherwise, it adds a single row of output to the EQP result, |
| | @@ -109545,23 +109678,10 @@ |
| 109545 | 109678 | Parse *pParse, /* Parsing context */ |
| 109546 | 109679 | Select *p, /* The right-most of SELECTs to be coded */ |
| 109547 | 109680 | SelectDest *pDest /* What to do with query results */ |
| 109548 | 109681 | ); |
| 109549 | 109682 | |
| 109550 | | -/* |
| 109551 | | -** Error message for when two or more terms of a compound select have different |
| 109552 | | -** size result sets. |
| 109553 | | -*/ |
| 109554 | | -SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p){ |
| 109555 | | - if( p->selFlags & SF_Values ){ |
| 109556 | | - sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms"); |
| 109557 | | - }else{ |
| 109558 | | - sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s" |
| 109559 | | - " do not have the same number of result columns", selectOpName(p->op)); |
| 109560 | | - } |
| 109561 | | -} |
| 109562 | | - |
| 109563 | 109683 | /* |
| 109564 | 109684 | ** Handle the special case of a compound-select that originates from a |
| 109565 | 109685 | ** VALUES clause. By handling this as a special case, we avoid deep |
| 109566 | 109686 | ** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT |
| 109567 | 109687 | ** on a VALUES clause. |
| | @@ -109983,10 +110103,23 @@ |
| 109983 | 110103 | pDest->nSdst = dest.nSdst; |
| 109984 | 110104 | sqlite3SelectDelete(db, pDelete); |
| 109985 | 110105 | return rc; |
| 109986 | 110106 | } |
| 109987 | 110107 | #endif /* SQLITE_OMIT_COMPOUND_SELECT */ |
| 110108 | + |
| 110109 | +/* |
| 110110 | +** Error message for when two or more terms of a compound select have different |
| 110111 | +** size result sets. |
| 110112 | +*/ |
| 110113 | +SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p){ |
| 110114 | + if( p->selFlags & SF_Values ){ |
| 110115 | + sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms"); |
| 110116 | + }else{ |
| 110117 | + sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s" |
| 110118 | + " do not have the same number of result columns", selectOpName(p->op)); |
| 110119 | + } |
| 110120 | +} |
| 109988 | 110121 | |
| 109989 | 110122 | /* |
| 109990 | 110123 | ** Code an output subroutine for a coroutine implementation of a |
| 109991 | 110124 | ** SELECT statment. |
| 109992 | 110125 | ** |
| | @@ -113077,10 +113210,11 @@ |
| 113077 | 113210 | ** interface routine of sqlite3_exec(). |
| 113078 | 113211 | ** |
| 113079 | 113212 | ** These routines are in a separate files so that they will not be linked |
| 113080 | 113213 | ** if they are not used. |
| 113081 | 113214 | */ |
| 113215 | +/* #include "sqliteInt.h" */ |
| 113082 | 113216 | /* #include <stdlib.h> */ |
| 113083 | 113217 | /* #include <string.h> */ |
| 113084 | 113218 | |
| 113085 | 113219 | #ifndef SQLITE_OMIT_GET_TABLE |
| 113086 | 113220 | |
| | @@ -113273,10 +113407,11 @@ |
| 113273 | 113407 | ** May you share freely, never taking more than you give. |
| 113274 | 113408 | ** |
| 113275 | 113409 | ************************************************************************* |
| 113276 | 113410 | ** This file contains the implementation for TRIGGERs |
| 113277 | 113411 | */ |
| 113412 | +/* #include "sqliteInt.h" */ |
| 113278 | 113413 | |
| 113279 | 113414 | #ifndef SQLITE_OMIT_TRIGGER |
| 113280 | 113415 | /* |
| 113281 | 113416 | ** Delete a linked list of TriggerStep structures. |
| 113282 | 113417 | */ |
| | @@ -114396,10 +114531,11 @@ |
| 114396 | 114531 | ** |
| 114397 | 114532 | ************************************************************************* |
| 114398 | 114533 | ** This file contains C code routines that are called by the parser |
| 114399 | 114534 | ** to handle UPDATE statements. |
| 114400 | 114535 | */ |
| 114536 | +/* #include "sqliteInt.h" */ |
| 114401 | 114537 | |
| 114402 | 114538 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 114403 | 114539 | /* Forward declaration */ |
| 114404 | 114540 | static void updateVirtualTable( |
| 114405 | 114541 | Parse *pParse, /* The parsing context */ |
| | @@ -115172,10 +115308,12 @@ |
| 115172 | 115308 | ** This file contains code used to implement the VACUUM command. |
| 115173 | 115309 | ** |
| 115174 | 115310 | ** Most of the code in this file may be omitted by defining the |
| 115175 | 115311 | ** SQLITE_OMIT_VACUUM macro. |
| 115176 | 115312 | */ |
| 115313 | +/* #include "sqliteInt.h" */ |
| 115314 | +/* #include "vdbeInt.h" */ |
| 115177 | 115315 | |
| 115178 | 115316 | #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH) |
| 115179 | 115317 | /* |
| 115180 | 115318 | ** Finalize a prepared statement. If there was an error, store the |
| 115181 | 115319 | ** text of the error message in *pzErrMsg. Return the result code. |
| | @@ -115544,10 +115682,11 @@ |
| 115544 | 115682 | ** |
| 115545 | 115683 | ************************************************************************* |
| 115546 | 115684 | ** This file contains code used to help implement virtual tables. |
| 115547 | 115685 | */ |
| 115548 | 115686 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 115687 | +/* #include "sqliteInt.h" */ |
| 115549 | 115688 | |
| 115550 | 115689 | /* |
| 115551 | 115690 | ** Before a virtual table xCreate() or xConnect() method is invoked, the |
| 115552 | 115691 | ** sqlite3.pVtabCtx member variable is set to point to an instance of |
| 115553 | 115692 | ** this struct allocated on the stack. It is used by the implementation of |
| | @@ -116702,10 +116841,11 @@ |
| 116702 | 116841 | ** This file was split off from where.c on 2015-06-06 in order to reduce the |
| 116703 | 116842 | ** size of where.c and make it easier to edit. This file contains the routines |
| 116704 | 116843 | ** that actually generate the bulk of the WHERE loop code. The original where.c |
| 116705 | 116844 | ** file retains the code that does query planning and analysis. |
| 116706 | 116845 | */ |
| 116846 | +/* #include "sqliteInt.h" */ |
| 116707 | 116847 | /************** Include whereInt.h in the middle of wherecode.c **************/ |
| 116708 | 116848 | /************** Begin file whereInt.h ****************************************/ |
| 116709 | 116849 | /* |
| 116710 | 116850 | ** 2013-11-12 |
| 116711 | 116851 | ** |
| | @@ -118513,11 +118653,15 @@ |
| 118513 | 118653 | |
| 118514 | 118654 | /* Read the PK into an array of temp registers. */ |
| 118515 | 118655 | r = sqlite3GetTempRange(pParse, nPk); |
| 118516 | 118656 | for(iPk=0; iPk<nPk; iPk++){ |
| 118517 | 118657 | int iCol = pPk->aiColumn[iPk]; |
| 118518 | | - sqlite3ExprCodeGetColumn(pParse, pTab, iCol, iCur, r+iPk, 0); |
| 118658 | + int rx; |
| 118659 | + rx = sqlite3ExprCodeGetColumn(pParse, pTab, iCol, iCur,r+iPk,0); |
| 118660 | + if( rx!=r+iPk ){ |
| 118661 | + sqlite3VdbeAddOp2(v, OP_SCopy, rx, r+iPk); |
| 118662 | + } |
| 118519 | 118663 | } |
| 118520 | 118664 | |
| 118521 | 118665 | /* Check if the temp table already contains this key. If so, |
| 118522 | 118666 | ** the row has already been included in the result set and |
| 118523 | 118667 | ** can be ignored (by jumping past the Gosub below). Otherwise, |
| | @@ -118737,10 +118881,12 @@ |
| 118737 | 118881 | ** |
| 118738 | 118882 | ** This file was originally part of where.c but was split out to improve |
| 118739 | 118883 | ** readability and editabiliity. This file contains utility routines for |
| 118740 | 118884 | ** analyzing Expr objects in the WHERE clause. |
| 118741 | 118885 | */ |
| 118886 | +/* #include "sqliteInt.h" */ |
| 118887 | +/* #include "whereInt.h" */ |
| 118742 | 118888 | |
| 118743 | 118889 | /* Forward declarations */ |
| 118744 | 118890 | static void exprAnalyze(SrcList*, WhereClause*, int); |
| 118745 | 118891 | |
| 118746 | 118892 | /* |
| | @@ -119987,10 +120133,12 @@ |
| 119987 | 120133 | ** generating the code that loops through a table looking for applicable |
| 119988 | 120134 | ** rows. Indices are selected and used to speed the search when doing |
| 119989 | 120135 | ** so is applicable. Because this module is responsible for selecting |
| 119990 | 120136 | ** indices, you might also think of this module as the "query optimizer". |
| 119991 | 120137 | */ |
| 120138 | +/* #include "sqliteInt.h" */ |
| 120139 | +/* #include "whereInt.h" */ |
| 119992 | 120140 | |
| 119993 | 120141 | /* Forward declaration of methods */ |
| 119994 | 120142 | static int whereLoopResize(sqlite3*, WhereLoop*, int); |
| 119995 | 120143 | |
| 119996 | 120144 | /* Test variable that can be set to enable WHERE tracing */ |
| | @@ -124486,10 +124634,11 @@ |
| 124486 | 124634 | */ |
| 124487 | 124635 | /* First off, code is included that follows the "include" declaration |
| 124488 | 124636 | ** in the input grammar file. */ |
| 124489 | 124637 | /* #include <stdio.h> */ |
| 124490 | 124638 | |
| 124639 | +/* #include "sqliteInt.h" */ |
| 124491 | 124640 | |
| 124492 | 124641 | /* |
| 124493 | 124642 | ** Disable all error recovery processing in the parser push-down |
| 124494 | 124643 | ** automaton. |
| 124495 | 124644 | */ |
| | @@ -128071,10 +128220,11 @@ |
| 128071 | 128220 | ** |
| 128072 | 128221 | ** This file contains C code that splits an SQL input string up into |
| 128073 | 128222 | ** individual tokens and sends those tokens one-by-one over to the |
| 128074 | 128223 | ** parser for analysis. |
| 128075 | 128224 | */ |
| 128225 | +/* #include "sqliteInt.h" */ |
| 128076 | 128226 | /* #include <stdlib.h> */ |
| 128077 | 128227 | |
| 128078 | 128228 | /* |
| 128079 | 128229 | ** The charMap() macro maps alphabetic characters into their |
| 128080 | 128230 | ** lower-case ASCII equivalent. On ASCII machines, this is just |
| | @@ -128880,10 +129030,11 @@ |
| 128880 | 129030 | ** This file contains C code that implements the sqlite3_complete() API. |
| 128881 | 129031 | ** This code used to be part of the tokenizer.c source file. But by |
| 128882 | 129032 | ** separating it out, the code will be automatically omitted from |
| 128883 | 129033 | ** static links that do not use it. |
| 128884 | 129034 | */ |
| 129035 | +/* #include "sqliteInt.h" */ |
| 128885 | 129036 | #ifndef SQLITE_OMIT_COMPLETE |
| 128886 | 129037 | |
| 128887 | 129038 | /* |
| 128888 | 129039 | ** This is defined in tokenize.c. We just have to import the definition. |
| 128889 | 129040 | */ |
| | @@ -129170,10 +129321,11 @@ |
| 129170 | 129321 | ** Main file for the SQLite library. The routines in this file |
| 129171 | 129322 | ** implement the programmer interface to the library. Routines in |
| 129172 | 129323 | ** other files are for internal use by SQLite and should not be |
| 129173 | 129324 | ** accessed by users of the library. |
| 129174 | 129325 | */ |
| 129326 | +/* #include "sqliteInt.h" */ |
| 129175 | 129327 | |
| 129176 | 129328 | #ifdef SQLITE_ENABLE_FTS3 |
| 129177 | 129329 | /************** Include fts3.h in the middle of main.c ***********************/ |
| 129178 | 129330 | /************** Begin file fts3.h ********************************************/ |
| 129179 | 129331 | /* |
| | @@ -129189,10 +129341,11 @@ |
| 129189 | 129341 | ****************************************************************************** |
| 129190 | 129342 | ** |
| 129191 | 129343 | ** This header file is used by programs that want to link against the |
| 129192 | 129344 | ** FTS3 library. All it does is declare the sqlite3Fts3Init() interface. |
| 129193 | 129345 | */ |
| 129346 | +/* #include "sqlite3.h" */ |
| 129194 | 129347 | |
| 129195 | 129348 | #if 0 |
| 129196 | 129349 | extern "C" { |
| 129197 | 129350 | #endif /* __cplusplus */ |
| 129198 | 129351 | |
| | @@ -129221,10 +129374,11 @@ |
| 129221 | 129374 | ****************************************************************************** |
| 129222 | 129375 | ** |
| 129223 | 129376 | ** This header file is used by programs that want to link against the |
| 129224 | 129377 | ** RTREE library. All it does is declare the sqlite3RtreeInit() interface. |
| 129225 | 129378 | */ |
| 129379 | +/* #include "sqlite3.h" */ |
| 129226 | 129380 | |
| 129227 | 129381 | #if 0 |
| 129228 | 129382 | extern "C" { |
| 129229 | 129383 | #endif /* __cplusplus */ |
| 129230 | 129384 | |
| | @@ -129253,10 +129407,11 @@ |
| 129253 | 129407 | ****************************************************************************** |
| 129254 | 129408 | ** |
| 129255 | 129409 | ** This header file is used by programs that want to link against the |
| 129256 | 129410 | ** ICU extension. All it does is declare the sqlite3IcuInit() interface. |
| 129257 | 129411 | */ |
| 129412 | +/* #include "sqlite3.h" */ |
| 129258 | 129413 | |
| 129259 | 129414 | #if 0 |
| 129260 | 129415 | extern "C" { |
| 129261 | 129416 | #endif /* __cplusplus */ |
| 129262 | 129417 | |
| | @@ -129885,10 +130040,11 @@ |
| 129885 | 130040 | ** space for the lookaside memory is obtained from sqlite3_malloc(). |
| 129886 | 130041 | ** If pStart is not NULL then it is sz*cnt bytes of memory to use for |
| 129887 | 130042 | ** the lookaside memory. |
| 129888 | 130043 | */ |
| 129889 | 130044 | static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ |
| 130045 | +#ifndef SQLITE_OMIT_LOOKASIDE |
| 129890 | 130046 | void *pStart; |
| 129891 | 130047 | if( db->lookaside.nOut ){ |
| 129892 | 130048 | return SQLITE_BUSY; |
| 129893 | 130049 | } |
| 129894 | 130050 | /* Free any existing lookaside buffer for this handle before |
| | @@ -129935,10 +130091,11 @@ |
| 129935 | 130091 | db->lookaside.pStart = db; |
| 129936 | 130092 | db->lookaside.pEnd = db; |
| 129937 | 130093 | db->lookaside.bEnabled = 0; |
| 129938 | 130094 | db->lookaside.bMalloced = 0; |
| 129939 | 130095 | } |
| 130096 | +#endif /* SQLITE_OMIT_LOOKASIDE */ |
| 129940 | 130097 | return SQLITE_OK; |
| 129941 | 130098 | } |
| 129942 | 130099 | |
| 129943 | 130100 | /* |
| 129944 | 130101 | ** Return the mutex associated with a database connection. |
| | @@ -133045,10 +133202,12 @@ |
| 133045 | 133202 | ************************************************************************* |
| 133046 | 133203 | ** |
| 133047 | 133204 | ** This file contains the implementation of the sqlite3_unlock_notify() |
| 133048 | 133205 | ** API method and its associated functionality. |
| 133049 | 133206 | */ |
| 133207 | +/* #include "sqliteInt.h" */ |
| 133208 | +/* #include "btreeInt.h" */ |
| 133050 | 133209 | |
| 133051 | 133210 | /* Omit this entire file if SQLITE_ENABLE_UNLOCK_NOTIFY is not defined. */ |
| 133052 | 133211 | #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY |
| 133053 | 133212 | |
| 133054 | 133213 | /* |
| | @@ -133688,13 +133847,15 @@ |
| 133688 | 133847 | |
| 133689 | 133848 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 133690 | 133849 | |
| 133691 | 133850 | /* If not building as part of the core, include sqlite3ext.h. */ |
| 133692 | 133851 | #ifndef SQLITE_CORE |
| 133852 | +/* # include "sqlite3ext.h" */ |
| 133693 | 133853 | SQLITE_EXTENSION_INIT3 |
| 133694 | 133854 | #endif |
| 133695 | 133855 | |
| 133856 | +/* #include "sqlite3.h" */ |
| 133696 | 133857 | /************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/ |
| 133697 | 133858 | /************** Begin file fts3_tokenizer.h **********************************/ |
| 133698 | 133859 | /* |
| 133699 | 133860 | ** 2006 July 10 |
| 133700 | 133861 | ** |
| | @@ -133719,10 +133880,11 @@ |
| 133719 | 133880 | |
| 133720 | 133881 | /* TODO(shess) Only used for SQLITE_OK and SQLITE_DONE at this time. |
| 133721 | 133882 | ** If tokenizers are to be allowed to call sqlite3_*() functions, then |
| 133722 | 133883 | ** we will need a way to register the API consistently. |
| 133723 | 133884 | */ |
| 133885 | +/* #include "sqlite3.h" */ |
| 133724 | 133886 | |
| 133725 | 133887 | /* |
| 133726 | 133888 | ** Structures used by the tokenizer interface. When a new tokenizer |
| 133727 | 133889 | ** implementation is registered, the caller provides a pointer to |
| 133728 | 133890 | ** an sqlite3_tokenizer_module containing pointers to the callback |
| | @@ -134559,11 +134721,13 @@ |
| 134559 | 134721 | /* #include <stddef.h> */ |
| 134560 | 134722 | /* #include <stdio.h> */ |
| 134561 | 134723 | /* #include <string.h> */ |
| 134562 | 134724 | /* #include <stdarg.h> */ |
| 134563 | 134725 | |
| 134726 | +/* #include "fts3.h" */ |
| 134564 | 134727 | #ifndef SQLITE_CORE |
| 134728 | +/* # include "sqlite3ext.h" */ |
| 134565 | 134729 | SQLITE_EXTENSION_INIT1 |
| 134566 | 134730 | #endif |
| 134567 | 134731 | |
| 134568 | 134732 | static int fts3EvalNext(Fts3Cursor *pCsr); |
| 134569 | 134733 | static int fts3EvalStart(Fts3Cursor *pCsr); |
| | @@ -138606,10 +138770,11 @@ |
| 138606 | 138770 | if( p==0 ){ |
| 138607 | 138771 | p = aDoclist; |
| 138608 | 138772 | p += sqlite3Fts3GetVarint(p, piDocid); |
| 138609 | 138773 | }else{ |
| 138610 | 138774 | fts3PoslistCopy(0, &p); |
| 138775 | + while( p<&aDoclist[nDoclist] && *p==0 ) p++; |
| 138611 | 138776 | if( p>=&aDoclist[nDoclist] ){ |
| 138612 | 138777 | *pbEof = 1; |
| 138613 | 138778 | }else{ |
| 138614 | 138779 | sqlite3_int64 iVar; |
| 138615 | 138780 | p += sqlite3Fts3GetVarint(p, &iVar); |
| | @@ -140012,14 +140177,14 @@ |
| 140012 | 140177 | pIter = pPhrase->doclist.pList; |
| 140013 | 140178 | if( iDocid!=pCsr->iPrevId || pExpr->bEof ){ |
| 140014 | 140179 | int rc = SQLITE_OK; |
| 140015 | 140180 | int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */ |
| 140016 | 140181 | int bOr = 0; |
| 140017 | | - u8 bEof = 0; |
| 140018 | 140182 | u8 bTreeEof = 0; |
| 140019 | 140183 | Fts3Expr *p; /* Used to iterate from pExpr to root */ |
| 140020 | 140184 | Fts3Expr *pNear; /* Most senior NEAR ancestor (or pExpr) */ |
| 140185 | + int bMatch; |
| 140021 | 140186 | |
| 140022 | 140187 | /* Check if this phrase descends from an OR expression node. If not, |
| 140023 | 140188 | ** return NULL. Otherwise, the entry that corresponds to docid |
| 140024 | 140189 | ** pCsr->iPrevId may lie earlier in the doclist buffer. Or, if the |
| 140025 | 140190 | ** tree that the node is part of has been marked as EOF, but the node |
| | @@ -140049,35 +140214,51 @@ |
| 140049 | 140214 | fts3EvalNextRow(pCsr, pNear, &rc); |
| 140050 | 140215 | } |
| 140051 | 140216 | } |
| 140052 | 140217 | if( rc!=SQLITE_OK ) return rc; |
| 140053 | 140218 | |
| 140054 | | - pIter = pPhrase->pOrPoslist; |
| 140055 | | - iDocid = pPhrase->iOrDocid; |
| 140056 | | - if( pCsr->bDesc==bDescDoclist ){ |
| 140057 | | - bEof = !pPhrase->doclist.nAll || |
| 140058 | | - (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll)); |
| 140059 | | - while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ |
| 140060 | | - sqlite3Fts3DoclistNext( |
| 140061 | | - bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, |
| 140062 | | - &pIter, &iDocid, &bEof |
| 140063 | | - ); |
| 140064 | | - } |
| 140065 | | - }else{ |
| 140066 | | - bEof = !pPhrase->doclist.nAll || (pIter && pIter<=pPhrase->doclist.aAll); |
| 140067 | | - while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){ |
| 140068 | | - int dummy; |
| 140069 | | - sqlite3Fts3DoclistPrev( |
| 140070 | | - bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, |
| 140071 | | - &pIter, &iDocid, &dummy, &bEof |
| 140072 | | - ); |
| 140073 | | - } |
| 140074 | | - } |
| 140075 | | - pPhrase->pOrPoslist = pIter; |
| 140076 | | - pPhrase->iOrDocid = iDocid; |
| 140077 | | - |
| 140078 | | - if( bEof || iDocid!=pCsr->iPrevId ) pIter = 0; |
| 140219 | + bMatch = 1; |
| 140220 | + for(p=pNear; p; p=p->pLeft){ |
| 140221 | + u8 bEof = 0; |
| 140222 | + Fts3Expr *pTest = p; |
| 140223 | + Fts3Phrase *pPh; |
| 140224 | + assert( pTest->eType==FTSQUERY_NEAR || pTest->eType==FTSQUERY_PHRASE ); |
| 140225 | + if( pTest->eType==FTSQUERY_NEAR ) pTest = pTest->pRight; |
| 140226 | + assert( pTest->eType==FTSQUERY_PHRASE ); |
| 140227 | + pPh = pTest->pPhrase; |
| 140228 | + |
| 140229 | + pIter = pPh->pOrPoslist; |
| 140230 | + iDocid = pPh->iOrDocid; |
| 140231 | + if( pCsr->bDesc==bDescDoclist ){ |
| 140232 | + bEof = !pPh->doclist.nAll || |
| 140233 | + (pIter >= (pPh->doclist.aAll + pPh->doclist.nAll)); |
| 140234 | + while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ |
| 140235 | + sqlite3Fts3DoclistNext( |
| 140236 | + bDescDoclist, pPh->doclist.aAll, pPh->doclist.nAll, |
| 140237 | + &pIter, &iDocid, &bEof |
| 140238 | + ); |
| 140239 | + } |
| 140240 | + }else{ |
| 140241 | + bEof = !pPh->doclist.nAll || (pIter && pIter<=pPh->doclist.aAll); |
| 140242 | + while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){ |
| 140243 | + int dummy; |
| 140244 | + sqlite3Fts3DoclistPrev( |
| 140245 | + bDescDoclist, pPh->doclist.aAll, pPh->doclist.nAll, |
| 140246 | + &pIter, &iDocid, &dummy, &bEof |
| 140247 | + ); |
| 140248 | + } |
| 140249 | + } |
| 140250 | + pPh->pOrPoslist = pIter; |
| 140251 | + pPh->iOrDocid = iDocid; |
| 140252 | + if( bEof || iDocid!=pCsr->iPrevId ) bMatch = 0; |
| 140253 | + } |
| 140254 | + |
| 140255 | + if( bMatch ){ |
| 140256 | + pIter = pPhrase->pOrPoslist; |
| 140257 | + }else{ |
| 140258 | + pIter = 0; |
| 140259 | + } |
| 140079 | 140260 | } |
| 140080 | 140261 | if( pIter==0 ) return SQLITE_OK; |
| 140081 | 140262 | |
| 140082 | 140263 | if( *pIter==0x01 ){ |
| 140083 | 140264 | pIter++; |
| | @@ -140161,10 +140342,11 @@ |
| 140161 | 140342 | ** May you share freely, never taking more than you give. |
| 140162 | 140343 | ** |
| 140163 | 140344 | ****************************************************************************** |
| 140164 | 140345 | ** |
| 140165 | 140346 | */ |
| 140347 | +/* #include "fts3Int.h" */ |
| 140166 | 140348 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 140167 | 140349 | |
| 140168 | 140350 | /* #include <string.h> */ |
| 140169 | 140351 | /* #include <assert.h> */ |
| 140170 | 140352 | |
| | @@ -140717,10 +140899,11 @@ |
| 140717 | 140899 | ** This module contains code that implements a parser for fts3 query strings |
| 140718 | 140900 | ** (the right-hand argument to the MATCH operator). Because the supported |
| 140719 | 140901 | ** syntax is relatively simple, the whole tokenizer/parser system is |
| 140720 | 140902 | ** hand-coded. |
| 140721 | 140903 | */ |
| 140904 | +/* #include "fts3Int.h" */ |
| 140722 | 140905 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 140723 | 140906 | |
| 140724 | 140907 | /* |
| 140725 | 140908 | ** By default, this module parses the legacy syntax that has been |
| 140726 | 140909 | ** traditionally used by fts3. Or, if SQLITE_ENABLE_FTS3_PARENTHESIS |
| | @@ -142010,16 +142193,18 @@ |
| 142010 | 142193 | ** (in which case SQLITE_CORE is not defined), or |
| 142011 | 142194 | ** |
| 142012 | 142195 | ** * The FTS3 module is being built into the core of |
| 142013 | 142196 | ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined). |
| 142014 | 142197 | */ |
| 142198 | +/* #include "fts3Int.h" */ |
| 142015 | 142199 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 142016 | 142200 | |
| 142017 | 142201 | /* #include <assert.h> */ |
| 142018 | 142202 | /* #include <stdlib.h> */ |
| 142019 | 142203 | /* #include <string.h> */ |
| 142020 | 142204 | |
| 142205 | +/* #include "fts3_hash.h" */ |
| 142021 | 142206 | |
| 142022 | 142207 | /* |
| 142023 | 142208 | ** Malloc and Free functions |
| 142024 | 142209 | */ |
| 142025 | 142210 | static void *fts3HashMalloc(int n){ |
| | @@ -142393,17 +142578,19 @@ |
| 142393 | 142578 | ** (in which case SQLITE_CORE is not defined), or |
| 142394 | 142579 | ** |
| 142395 | 142580 | ** * The FTS3 module is being built into the core of |
| 142396 | 142581 | ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined). |
| 142397 | 142582 | */ |
| 142583 | +/* #include "fts3Int.h" */ |
| 142398 | 142584 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 142399 | 142585 | |
| 142400 | 142586 | /* #include <assert.h> */ |
| 142401 | 142587 | /* #include <stdlib.h> */ |
| 142402 | 142588 | /* #include <stdio.h> */ |
| 142403 | 142589 | /* #include <string.h> */ |
| 142404 | 142590 | |
| 142591 | +/* #include "fts3_tokenizer.h" */ |
| 142405 | 142592 | |
| 142406 | 142593 | /* |
| 142407 | 142594 | ** Class derived from sqlite3_tokenizer |
| 142408 | 142595 | */ |
| 142409 | 142596 | typedef struct porter_tokenizer { |
| | @@ -143057,10 +143244,11 @@ |
| 143057 | 143244 | ** (in which case SQLITE_CORE is not defined), or |
| 143058 | 143245 | ** |
| 143059 | 143246 | ** * The FTS3 module is being built into the core of |
| 143060 | 143247 | ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined). |
| 143061 | 143248 | */ |
| 143249 | +/* #include "fts3Int.h" */ |
| 143062 | 143250 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 143063 | 143251 | |
| 143064 | 143252 | /* #include <assert.h> */ |
| 143065 | 143253 | /* #include <string.h> */ |
| 143066 | 143254 | |
| | @@ -143552,17 +143740,19 @@ |
| 143552 | 143740 | ** (in which case SQLITE_CORE is not defined), or |
| 143553 | 143741 | ** |
| 143554 | 143742 | ** * The FTS3 module is being built into the core of |
| 143555 | 143743 | ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined). |
| 143556 | 143744 | */ |
| 143745 | +/* #include "fts3Int.h" */ |
| 143557 | 143746 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 143558 | 143747 | |
| 143559 | 143748 | /* #include <assert.h> */ |
| 143560 | 143749 | /* #include <stdlib.h> */ |
| 143561 | 143750 | /* #include <stdio.h> */ |
| 143562 | 143751 | /* #include <string.h> */ |
| 143563 | 143752 | |
| 143753 | +/* #include "fts3_tokenizer.h" */ |
| 143564 | 143754 | |
| 143565 | 143755 | typedef struct simple_tokenizer { |
| 143566 | 143756 | sqlite3_tokenizer base; |
| 143567 | 143757 | char delim[128]; /* flag ASCII delimiters */ |
| 143568 | 143758 | } simple_tokenizer; |
| | @@ -143803,10 +143993,11 @@ |
| 143803 | 143993 | ** end: Byte offset of the byte immediately following the end of the |
| 143804 | 143994 | ** token within the input string. |
| 143805 | 143995 | ** pos: Token offset of token within input. |
| 143806 | 143996 | ** |
| 143807 | 143997 | */ |
| 143998 | +/* #include "fts3Int.h" */ |
| 143808 | 143999 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 143809 | 144000 | |
| 143810 | 144001 | /* #include <string.h> */ |
| 143811 | 144002 | /* #include <assert.h> */ |
| 143812 | 144003 | |
| | @@ -144238,10 +144429,11 @@ |
| 144238 | 144429 | ** tables. It also contains code to merge FTS3 b-tree segments. Some |
| 144239 | 144430 | ** of the sub-routines used to merge segments are also used by the query |
| 144240 | 144431 | ** code in fts3.c. |
| 144241 | 144432 | */ |
| 144242 | 144433 | |
| 144434 | +/* #include "fts3Int.h" */ |
| 144243 | 144435 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 144244 | 144436 | |
| 144245 | 144437 | /* #include <string.h> */ |
| 144246 | 144438 | /* #include <assert.h> */ |
| 144247 | 144439 | /* #include <stdlib.h> */ |
| | @@ -149898,10 +150090,11 @@ |
| 149898 | 150090 | ** May you share freely, never taking more than you give. |
| 149899 | 150091 | ** |
| 149900 | 150092 | ****************************************************************************** |
| 149901 | 150093 | */ |
| 149902 | 150094 | |
| 150095 | +/* #include "fts3Int.h" */ |
| 149903 | 150096 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 149904 | 150097 | |
| 149905 | 150098 | /* #include <string.h> */ |
| 149906 | 150099 | /* #include <assert.h> */ |
| 149907 | 150100 | |
| | @@ -151610,17 +151803,19 @@ |
| 151610 | 151803 | ** Implementation of the "unicode" full-text-search tokenizer. |
| 151611 | 151804 | */ |
| 151612 | 151805 | |
| 151613 | 151806 | #ifndef SQLITE_DISABLE_FTS3_UNICODE |
| 151614 | 151807 | |
| 151808 | +/* #include "fts3Int.h" */ |
| 151615 | 151809 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 151616 | 151810 | |
| 151617 | 151811 | /* #include <assert.h> */ |
| 151618 | 151812 | /* #include <stdlib.h> */ |
| 151619 | 151813 | /* #include <stdio.h> */ |
| 151620 | 151814 | /* #include <string.h> */ |
| 151621 | 151815 | |
| 151816 | +/* #include "fts3_tokenizer.h" */ |
| 151622 | 151817 | |
| 151623 | 151818 | /* |
| 151624 | 151819 | ** The following two macros - READ_UTF8 and WRITE_UTF8 - have been copied |
| 151625 | 151820 | ** from the sqlite3 source file utf.c. If this file is compiled as part |
| 151626 | 151821 | ** of the amalgamation, they are not required. |
| | @@ -152412,12 +152607,14 @@ |
| 152412 | 152607 | */ |
| 152413 | 152608 | |
| 152414 | 152609 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE) |
| 152415 | 152610 | |
| 152416 | 152611 | #ifndef SQLITE_CORE |
| 152612 | +/* #include "sqlite3ext.h" */ |
| 152417 | 152613 | SQLITE_EXTENSION_INIT1 |
| 152418 | 152614 | #else |
| 152615 | +/* #include "sqlite3.h" */ |
| 152419 | 152616 | #endif |
| 152420 | 152617 | |
| 152421 | 152618 | /* #include <string.h> */ |
| 152422 | 152619 | /* #include <assert.h> */ |
| 152423 | 152620 | /* #include <stdio.h> */ |
| | @@ -155909,12 +156106,14 @@ |
| 155909 | 156106 | #include <unicode/ucol.h> |
| 155910 | 156107 | |
| 155911 | 156108 | /* #include <assert.h> */ |
| 155912 | 156109 | |
| 155913 | 156110 | #ifndef SQLITE_CORE |
| 156111 | +/* #include "sqlite3ext.h" */ |
| 155914 | 156112 | SQLITE_EXTENSION_INIT1 |
| 155915 | 156113 | #else |
| 156114 | +/* #include "sqlite3.h" */ |
| 155916 | 156115 | #endif |
| 155917 | 156116 | |
| 155918 | 156117 | /* |
| 155919 | 156118 | ** Maximum length (in bytes) of the pattern in a LIKE or GLOB |
| 155920 | 156119 | ** operator. |
| | @@ -156386,15 +156585,17 @@ |
| 156386 | 156585 | ** May you share freely, never taking more than you give. |
| 156387 | 156586 | ** |
| 156388 | 156587 | ************************************************************************* |
| 156389 | 156588 | ** This file implements a tokenizer for fts3 based on the ICU library. |
| 156390 | 156589 | */ |
| 156590 | +/* #include "fts3Int.h" */ |
| 156391 | 156591 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 156392 | 156592 | #ifdef SQLITE_ENABLE_ICU |
| 156393 | 156593 | |
| 156394 | 156594 | /* #include <assert.h> */ |
| 156395 | 156595 | /* #include <string.h> */ |
| 156596 | +/* #include "fts3_tokenizer.h" */ |
| 156396 | 156597 | |
| 156397 | 156598 | #include <unicode/ubrk.h> |
| 156398 | 156599 | /* #include <unicode/ucol.h> */ |
| 156399 | 156600 | /* #include <unicode/ustring.h> */ |
| 156400 | 156601 | #include <unicode/utf16.h> |
| | @@ -156635,11 +156836,11 @@ |
| 156635 | 156836 | |
| 156636 | 156837 | #endif /* defined(SQLITE_ENABLE_ICU) */ |
| 156637 | 156838 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ |
| 156638 | 156839 | |
| 156639 | 156840 | /************** End of fts3_icu.c ********************************************/ |
| 156640 | | -/************** Begin file sqlite3ota.c **************************************/ |
| 156841 | +/************** Begin file sqlite3rbu.c **************************************/ |
| 156641 | 156842 | /* |
| 156642 | 156843 | ** 2014 August 30 |
| 156643 | 156844 | ** |
| 156644 | 156845 | ** The author disclaims copyright to this source code. In place of |
| 156645 | 156846 | ** a legal notice, here is a blessing: |
| | @@ -156651,15 +156852,15 @@ |
| 156651 | 156852 | ************************************************************************* |
| 156652 | 156853 | ** |
| 156653 | 156854 | ** |
| 156654 | 156855 | ** OVERVIEW |
| 156655 | 156856 | ** |
| 156656 | | -** The OTA extension requires that the OTA update be packaged as an |
| 156857 | +** The RBU extension requires that the RBU update be packaged as an |
| 156657 | 156858 | ** SQLite database. The tables it expects to find are described in |
| 156658 | | -** sqlite3ota.h. Essentially, for each table xyz in the target database |
| 156859 | +** sqlite3rbu.h. Essentially, for each table xyz in the target database |
| 156659 | 156860 | ** that the user wishes to write to, a corresponding data_xyz table is |
| 156660 | | -** created in the OTA database and populated with one row for each row to |
| 156861 | +** created in the RBU database and populated with one row for each row to |
| 156661 | 156862 | ** update, insert or delete from the target table. |
| 156662 | 156863 | ** |
| 156663 | 156864 | ** The update proceeds in three stages: |
| 156664 | 156865 | ** |
| 156665 | 156866 | ** 1) The database is updated. The modified database pages are written |
| | @@ -156667,70 +156868,71 @@ |
| 156667 | 156868 | ** that it is named "<database>-oal" instead of "<database>-wal". |
| 156668 | 156869 | ** Because regular SQLite clients do not look for file named |
| 156669 | 156870 | ** "<database>-oal", they go on using the original database in |
| 156670 | 156871 | ** rollback mode while the *-oal file is being generated. |
| 156671 | 156872 | ** |
| 156672 | | -** During this stage OTA does not update the database by writing |
| 156873 | +** During this stage RBU does not update the database by writing |
| 156673 | 156874 | ** directly to the target tables. Instead it creates "imposter" |
| 156674 | 156875 | ** tables using the SQLITE_TESTCTRL_IMPOSTER interface that it uses |
| 156675 | 156876 | ** to update each b-tree individually. All updates required by each |
| 156676 | 156877 | ** b-tree are completed before moving on to the next, and all |
| 156677 | 156878 | ** updates are done in sorted key order. |
| 156678 | 156879 | ** |
| 156679 | 156880 | ** 2) The "<database>-oal" file is moved to the equivalent "<database>-wal" |
| 156680 | | -** location using a call to rename(2). Before doing this the OTA |
| 156881 | +** location using a call to rename(2). Before doing this the RBU |
| 156681 | 156882 | ** module takes an EXCLUSIVE lock on the database file, ensuring |
| 156682 | 156883 | ** that there are no other active readers. |
| 156683 | 156884 | ** |
| 156684 | 156885 | ** Once the EXCLUSIVE lock is released, any other database readers |
| 156685 | 156886 | ** detect the new *-wal file and read the database in wal mode. At |
| 156686 | 156887 | ** this point they see the new version of the database - including |
| 156687 | | -** the updates made as part of the OTA update. |
| 156888 | +** the updates made as part of the RBU update. |
| 156688 | 156889 | ** |
| 156689 | 156890 | ** 3) The new *-wal file is checkpointed. This proceeds in the same way |
| 156690 | 156891 | ** as a regular database checkpoint, except that a single frame is |
| 156691 | | -** checkpointed each time sqlite3ota_step() is called. If the OTA |
| 156892 | +** checkpointed each time sqlite3rbu_step() is called. If the RBU |
| 156692 | 156893 | ** handle is closed before the entire *-wal file is checkpointed, |
| 156693 | | -** the checkpoint progress is saved in the OTA database and the |
| 156694 | | -** checkpoint can be resumed by another OTA client at some point in |
| 156894 | +** the checkpoint progress is saved in the RBU database and the |
| 156895 | +** checkpoint can be resumed by another RBU client at some point in |
| 156695 | 156896 | ** the future. |
| 156696 | 156897 | ** |
| 156697 | 156898 | ** POTENTIAL PROBLEMS |
| 156698 | 156899 | ** |
| 156699 | | -** The rename() call might not be portable. And OTA is not currently |
| 156900 | +** The rename() call might not be portable. And RBU is not currently |
| 156700 | 156901 | ** syncing the directory after renaming the file. |
| 156701 | 156902 | ** |
| 156702 | 156903 | ** When state is saved, any commit to the *-oal file and the commit to |
| 156703 | | -** the OTA update database are not atomic. So if the power fails at the |
| 156904 | +** the RBU update database are not atomic. So if the power fails at the |
| 156704 | 156905 | ** wrong moment they might get out of sync. As the main database will be |
| 156705 | | -** committed before the OTA update database this will likely either just |
| 156906 | +** committed before the RBU update database this will likely either just |
| 156706 | 156907 | ** pass unnoticed, or result in SQLITE_CONSTRAINT errors (due to UNIQUE |
| 156707 | 156908 | ** constraint violations). |
| 156708 | 156909 | ** |
| 156709 | | -** If some client does modify the target database mid OTA update, or some |
| 156710 | | -** other error occurs, the OTA extension will keep throwing errors. It's |
| 156910 | +** If some client does modify the target database mid RBU update, or some |
| 156911 | +** other error occurs, the RBU extension will keep throwing errors. It's |
| 156711 | 156912 | ** not really clear how to get out of this state. The system could just |
| 156712 | | -** by delete the OTA update database and *-oal file and have the device |
| 156913 | +** by delete the RBU update database and *-oal file and have the device |
| 156713 | 156914 | ** download the update again and start over. |
| 156714 | 156915 | ** |
| 156715 | 156916 | ** At present, for an UPDATE, both the new.* and old.* records are |
| 156716 | | -** collected in the ota_xyz table. And for both UPDATEs and DELETEs all |
| 156917 | +** collected in the rbu_xyz table. And for both UPDATEs and DELETEs all |
| 156717 | 156918 | ** fields are collected. This means we're probably writing a lot more |
| 156718 | | -** data to disk when saving the state of an ongoing update to the OTA |
| 156919 | +** data to disk when saving the state of an ongoing update to the RBU |
| 156719 | 156920 | ** update database than is strictly necessary. |
| 156720 | 156921 | ** |
| 156721 | 156922 | */ |
| 156722 | 156923 | |
| 156723 | 156924 | /* #include <assert.h> */ |
| 156724 | 156925 | /* #include <string.h> */ |
| 156725 | 156926 | /* #include <stdio.h> */ |
| 156726 | 156927 | /* #include <unistd.h> */ |
| 156727 | 156928 | |
| 156929 | +/* #include "sqlite3.h" */ |
| 156728 | 156930 | |
| 156729 | | -#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA) |
| 156730 | | -/************** Include sqlite3ota.h in the middle of sqlite3ota.c ***********/ |
| 156731 | | -/************** Begin file sqlite3ota.h **************************************/ |
| 156931 | +#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) |
| 156932 | +/************** Include sqlite3rbu.h in the middle of sqlite3rbu.c ***********/ |
| 156933 | +/************** Begin file sqlite3rbu.h **************************************/ |
| 156732 | 156934 | /* |
| 156733 | 156935 | ** 2014 August 30 |
| 156734 | 156936 | ** |
| 156735 | 156937 | ** The author disclaims copyright to this source code. In place of |
| 156736 | 156938 | ** a legal notice, here is a blessing: |
| | @@ -156739,11 +156941,11 @@ |
| 156739 | 156941 | ** May you find forgiveness for yourself and forgive others. |
| 156740 | 156942 | ** May you share freely, never taking more than you give. |
| 156741 | 156943 | ** |
| 156742 | 156944 | ************************************************************************* |
| 156743 | 156945 | ** |
| 156744 | | -** This file contains the public interface for the OTA extension. |
| 156946 | +** This file contains the public interface for the RBU extension. |
| 156745 | 156947 | */ |
| 156746 | 156948 | |
| 156747 | 156949 | /* |
| 156748 | 156950 | ** SUMMARY |
| 156749 | 156951 | ** |
| | @@ -156776,18 +156978,18 @@ |
| 156776 | 156978 | ** mobile device that is frequently rebooted. Even after the writer process |
| 156777 | 156979 | ** has committed one or more sub-transactions, other database clients continue |
| 156778 | 156980 | ** to read from the original database snapshot. In other words, partially |
| 156779 | 156981 | ** applied transactions are not visible to other clients. |
| 156780 | 156982 | ** |
| 156781 | | -** "OTA" stands for "Over The Air" update. As in a large database update |
| 156983 | +** "RBU" stands for "Over The Air" update. As in a large database update |
| 156782 | 156984 | ** transmitted via a wireless network to a mobile device. A transaction |
| 156783 | | -** applied using this extension is hence refered to as an "OTA update". |
| 156985 | +** applied using this extension is hence refered to as an "RBU update". |
| 156784 | 156986 | ** |
| 156785 | 156987 | ** |
| 156786 | 156988 | ** LIMITATIONS |
| 156787 | 156989 | ** |
| 156788 | | -** An "OTA update" transaction is subject to the following limitations: |
| 156990 | +** An "RBU update" transaction is subject to the following limitations: |
| 156789 | 156991 | ** |
| 156790 | 156992 | ** * The transaction must consist of INSERT, UPDATE and DELETE operations |
| 156791 | 156993 | ** only. |
| 156792 | 156994 | ** |
| 156793 | 156995 | ** * INSERT statements may not use any default values. |
| | @@ -156808,430 +157010,430 @@ |
| 156808 | 157010 | ** * No constraint handling mode except for "OR ROLLBACK" is supported. |
| 156809 | 157011 | ** |
| 156810 | 157012 | ** |
| 156811 | 157013 | ** PREPARATION |
| 156812 | 157014 | ** |
| 156813 | | -** An "OTA update" is stored as a separate SQLite database. A database |
| 156814 | | -** containing an OTA update is an "OTA database". For each table in the |
| 156815 | | -** target database to be updated, the OTA database should contain a table |
| 157015 | +** An "RBU update" is stored as a separate SQLite database. A database |
| 157016 | +** containing an RBU update is an "RBU database". For each table in the |
| 157017 | +** target database to be updated, the RBU database should contain a table |
| 156816 | 157018 | ** named "data_<target name>" containing the same set of columns as the |
| 156817 | | -** target table, and one more - "ota_control". The data_% table should |
| 157019 | +** target table, and one more - "rbu_control". The data_% table should |
| 156818 | 157020 | ** have no PRIMARY KEY or UNIQUE constraints, but each column should have |
| 156819 | 157021 | ** the same type as the corresponding column in the target database. |
| 156820 | | -** The "ota_control" column should have no type at all. For example, if |
| 157022 | +** The "rbu_control" column should have no type at all. For example, if |
| 156821 | 157023 | ** the target database contains: |
| 156822 | 157024 | ** |
| 156823 | 157025 | ** CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c UNIQUE); |
| 156824 | 157026 | ** |
| 156825 | | -** Then the OTA database should contain: |
| 157027 | +** Then the RBU database should contain: |
| 156826 | 157028 | ** |
| 156827 | | -** CREATE TABLE data_t1(a INTEGER, b TEXT, c, ota_control); |
| 157029 | +** CREATE TABLE data_t1(a INTEGER, b TEXT, c, rbu_control); |
| 156828 | 157030 | ** |
| 156829 | 157031 | ** The order of the columns in the data_% table does not matter. |
| 156830 | 157032 | ** |
| 156831 | 157033 | ** If the target database table is a virtual table or a table that has no |
| 156832 | 157034 | ** PRIMARY KEY declaration, the data_% table must also contain a column |
| 156833 | | -** named "ota_rowid". This column is mapped to the tables implicit primary |
| 157035 | +** named "rbu_rowid". This column is mapped to the tables implicit primary |
| 156834 | 157036 | ** key column - "rowid". Virtual tables for which the "rowid" column does |
| 156835 | | -** not function like a primary key value cannot be updated using OTA. For |
| 157037 | +** not function like a primary key value cannot be updated using RBU. For |
| 156836 | 157038 | ** example, if the target db contains either of the following: |
| 156837 | 157039 | ** |
| 156838 | 157040 | ** CREATE VIRTUAL TABLE x1 USING fts3(a, b); |
| 156839 | 157041 | ** CREATE TABLE x1(a, b) |
| 156840 | 157042 | ** |
| 156841 | | -** then the OTA database should contain: |
| 157043 | +** then the RBU database should contain: |
| 156842 | 157044 | ** |
| 156843 | | -** CREATE TABLE data_x1(a, b, ota_rowid, ota_control); |
| 157045 | +** CREATE TABLE data_x1(a, b, rbu_rowid, rbu_control); |
| 156844 | 157046 | ** |
| 156845 | 157047 | ** All non-hidden columns (i.e. all columns matched by "SELECT *") of the |
| 156846 | 157048 | ** target table must be present in the input table. For virtual tables, |
| 156847 | | -** hidden columns are optional - they are updated by OTA if present in |
| 157049 | +** hidden columns are optional - they are updated by RBU if present in |
| 156848 | 157050 | ** the input table, or not otherwise. For example, to write to an fts4 |
| 156849 | 157051 | ** table with a hidden languageid column such as: |
| 156850 | 157052 | ** |
| 156851 | 157053 | ** CREATE VIRTUAL TABLE ft1 USING fts4(a, b, languageid='langid'); |
| 156852 | 157054 | ** |
| 156853 | 157055 | ** Either of the following input table schemas may be used: |
| 156854 | 157056 | ** |
| 156855 | | -** CREATE TABLE data_ft1(a, b, langid, ota_rowid, ota_control); |
| 156856 | | -** CREATE TABLE data_ft1(a, b, ota_rowid, ota_control); |
| 157057 | +** CREATE TABLE data_ft1(a, b, langid, rbu_rowid, rbu_control); |
| 157058 | +** CREATE TABLE data_ft1(a, b, rbu_rowid, rbu_control); |
| 156857 | 157059 | ** |
| 156858 | | -** For each row to INSERT into the target database as part of the OTA |
| 157060 | +** For each row to INSERT into the target database as part of the RBU |
| 156859 | 157061 | ** update, the corresponding data_% table should contain a single record |
| 156860 | | -** with the "ota_control" column set to contain integer value 0. The |
| 157062 | +** with the "rbu_control" column set to contain integer value 0. The |
| 156861 | 157063 | ** other columns should be set to the values that make up the new record |
| 156862 | 157064 | ** to insert. |
| 156863 | 157065 | ** |
| 156864 | 157066 | ** If the target database table has an INTEGER PRIMARY KEY, it is not |
| 156865 | 157067 | ** possible to insert a NULL value into the IPK column. Attempting to |
| 156866 | 157068 | ** do so results in an SQLITE_MISMATCH error. |
| 156867 | 157069 | ** |
| 156868 | | -** For each row to DELETE from the target database as part of the OTA |
| 157070 | +** For each row to DELETE from the target database as part of the RBU |
| 156869 | 157071 | ** update, the corresponding data_% table should contain a single record |
| 156870 | | -** with the "ota_control" column set to contain integer value 1. The |
| 157072 | +** with the "rbu_control" column set to contain integer value 1. The |
| 156871 | 157073 | ** real primary key values of the row to delete should be stored in the |
| 156872 | 157074 | ** corresponding columns of the data_% table. The values stored in the |
| 156873 | 157075 | ** other columns are not used. |
| 156874 | 157076 | ** |
| 156875 | | -** For each row to UPDATE from the target database as part of the OTA |
| 157077 | +** For each row to UPDATE from the target database as part of the RBU |
| 156876 | 157078 | ** update, the corresponding data_% table should contain a single record |
| 156877 | | -** with the "ota_control" column set to contain a value of type text. |
| 157079 | +** with the "rbu_control" column set to contain a value of type text. |
| 156878 | 157080 | ** The real primary key values identifying the row to update should be |
| 156879 | 157081 | ** stored in the corresponding columns of the data_% table row, as should |
| 156880 | 157082 | ** the new values of all columns being update. The text value in the |
| 156881 | | -** "ota_control" column must contain the same number of characters as |
| 157083 | +** "rbu_control" column must contain the same number of characters as |
| 156882 | 157084 | ** there are columns in the target database table, and must consist entirely |
| 156883 | 157085 | ** of 'x' and '.' characters (or in some special cases 'd' - see below). For |
| 156884 | 157086 | ** each column that is being updated, the corresponding character is set to |
| 156885 | 157087 | ** 'x'. For those that remain as they are, the corresponding character of the |
| 156886 | | -** ota_control value should be set to '.'. For example, given the tables |
| 157088 | +** rbu_control value should be set to '.'. For example, given the tables |
| 156887 | 157089 | ** above, the update statement: |
| 156888 | 157090 | ** |
| 156889 | 157091 | ** UPDATE t1 SET c = 'usa' WHERE a = 4; |
| 156890 | 157092 | ** |
| 156891 | 157093 | ** is represented by the data_t1 row created by: |
| 156892 | 157094 | ** |
| 156893 | | -** INSERT INTO data_t1(a, b, c, ota_control) VALUES(4, NULL, 'usa', '..x'); |
| 157095 | +** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..x'); |
| 156894 | 157096 | ** |
| 156895 | | -** Instead of an 'x' character, characters of the ota_control value specified |
| 157097 | +** Instead of an 'x' character, characters of the rbu_control value specified |
| 156896 | 157098 | ** for UPDATEs may also be set to 'd'. In this case, instead of updating the |
| 156897 | 157099 | ** target table with the value stored in the corresponding data_% column, the |
| 156898 | | -** user-defined SQL function "ota_delta()" is invoked and the result stored in |
| 156899 | | -** the target table column. ota_delta() is invoked with two arguments - the |
| 157100 | +** user-defined SQL function "rbu_delta()" is invoked and the result stored in |
| 157101 | +** the target table column. rbu_delta() is invoked with two arguments - the |
| 156900 | 157102 | ** original value currently stored in the target table column and the |
| 156901 | 157103 | ** value specified in the data_xxx table. |
| 156902 | 157104 | ** |
| 156903 | 157105 | ** For example, this row: |
| 156904 | 157106 | ** |
| 156905 | | -** INSERT INTO data_t1(a, b, c, ota_control) VALUES(4, NULL, 'usa', '..d'); |
| 157107 | +** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..d'); |
| 156906 | 157108 | ** |
| 156907 | 157109 | ** is similar to an UPDATE statement such as: |
| 156908 | 157110 | ** |
| 156909 | | -** UPDATE t1 SET c = ota_delta(c, 'usa') WHERE a = 4; |
| 157111 | +** UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4; |
| 156910 | 157112 | ** |
| 156911 | 157113 | ** If the target database table is a virtual table or a table with no PRIMARY |
| 156912 | | -** KEY, the ota_control value should not include a character corresponding |
| 156913 | | -** to the ota_rowid value. For example, this: |
| 157114 | +** KEY, the rbu_control value should not include a character corresponding |
| 157115 | +** to the rbu_rowid value. For example, this: |
| 156914 | 157116 | ** |
| 156915 | | -** INSERT INTO data_ft1(a, b, ota_rowid, ota_control) |
| 157117 | +** INSERT INTO data_ft1(a, b, rbu_rowid, rbu_control) |
| 156916 | 157118 | ** VALUES(NULL, 'usa', 12, '.x'); |
| 156917 | 157119 | ** |
| 156918 | 157120 | ** causes a result similar to: |
| 156919 | 157121 | ** |
| 156920 | 157122 | ** UPDATE ft1 SET b = 'usa' WHERE rowid = 12; |
| 156921 | 157123 | ** |
| 156922 | 157124 | ** The data_xxx tables themselves should have no PRIMARY KEY declarations. |
| 156923 | | -** However, OTA is more efficient if reading the rows in from each data_xxx |
| 157125 | +** However, RBU is more efficient if reading the rows in from each data_xxx |
| 156924 | 157126 | ** table in "rowid" order is roughly the same as reading them sorted by |
| 156925 | 157127 | ** the PRIMARY KEY of the corresponding target database table. In other |
| 156926 | 157128 | ** words, rows should be sorted using the destination table PRIMARY KEY |
| 156927 | 157129 | ** fields before they are inserted into the data_xxx tables. |
| 156928 | 157130 | ** |
| 156929 | 157131 | ** USAGE |
| 156930 | 157132 | ** |
| 156931 | | -** The API declared below allows an application to apply an OTA update |
| 157133 | +** The API declared below allows an application to apply an RBU update |
| 156932 | 157134 | ** stored on disk to an existing target database. Essentially, the |
| 156933 | 157135 | ** application: |
| 156934 | 157136 | ** |
| 156935 | | -** 1) Opens an OTA handle using the sqlite3ota_open() function. |
| 157137 | +** 1) Opens an RBU handle using the sqlite3rbu_open() function. |
| 156936 | 157138 | ** |
| 156937 | 157139 | ** 2) Registers any required virtual table modules with the database |
| 156938 | | -** handle returned by sqlite3ota_db(). Also, if required, register |
| 156939 | | -** the ota_delta() implementation. |
| 157140 | +** handle returned by sqlite3rbu_db(). Also, if required, register |
| 157141 | +** the rbu_delta() implementation. |
| 156940 | 157142 | ** |
| 156941 | | -** 3) Calls the sqlite3ota_step() function one or more times on |
| 156942 | | -** the new handle. Each call to sqlite3ota_step() performs a single |
| 157143 | +** 3) Calls the sqlite3rbu_step() function one or more times on |
| 157144 | +** the new handle. Each call to sqlite3rbu_step() performs a single |
| 156943 | 157145 | ** b-tree operation, so thousands of calls may be required to apply |
| 156944 | 157146 | ** a complete update. |
| 156945 | 157147 | ** |
| 156946 | | -** 4) Calls sqlite3ota_close() to close the OTA update handle. If |
| 156947 | | -** sqlite3ota_step() has been called enough times to completely |
| 156948 | | -** apply the update to the target database, then the OTA database |
| 156949 | | -** is marked as fully applied. Otherwise, the state of the OTA |
| 156950 | | -** update application is saved in the OTA database for later |
| 157148 | +** 4) Calls sqlite3rbu_close() to close the RBU update handle. If |
| 157149 | +** sqlite3rbu_step() has been called enough times to completely |
| 157150 | +** apply the update to the target database, then the RBU database |
| 157151 | +** is marked as fully applied. Otherwise, the state of the RBU |
| 157152 | +** update application is saved in the RBU database for later |
| 156951 | 157153 | ** resumption. |
| 156952 | 157154 | ** |
| 156953 | 157155 | ** See comments below for more detail on APIs. |
| 156954 | 157156 | ** |
| 156955 | 157157 | ** If an update is only partially applied to the target database by the |
| 156956 | | -** time sqlite3ota_close() is called, various state information is saved |
| 156957 | | -** within the OTA database. This allows subsequent processes to automatically |
| 156958 | | -** resume the OTA update from where it left off. |
| 157158 | +** time sqlite3rbu_close() is called, various state information is saved |
| 157159 | +** within the RBU database. This allows subsequent processes to automatically |
| 157160 | +** resume the RBU update from where it left off. |
| 156959 | 157161 | ** |
| 156960 | | -** To remove all OTA extension state information, returning an OTA database |
| 157162 | +** To remove all RBU extension state information, returning an RBU database |
| 156961 | 157163 | ** to its original contents, it is sufficient to drop all tables that begin |
| 156962 | | -** with the prefix "ota_" |
| 157164 | +** with the prefix "rbu_" |
| 156963 | 157165 | ** |
| 156964 | 157166 | ** DATABASE LOCKING |
| 156965 | 157167 | ** |
| 156966 | | -** An OTA update may not be applied to a database in WAL mode. Attempting |
| 157168 | +** An RBU update may not be applied to a database in WAL mode. Attempting |
| 156967 | 157169 | ** to do so is an error (SQLITE_ERROR). |
| 156968 | 157170 | ** |
| 156969 | | -** While an OTA handle is open, a SHARED lock may be held on the target |
| 157171 | +** While an RBU handle is open, a SHARED lock may be held on the target |
| 156970 | 157172 | ** database file. This means it is possible for other clients to read the |
| 156971 | 157173 | ** database, but not to write it. |
| 156972 | 157174 | ** |
| 156973 | | -** If an OTA update is started and then suspended before it is completed, |
| 157175 | +** If an RBU update is started and then suspended before it is completed, |
| 156974 | 157176 | ** then an external client writes to the database, then attempting to resume |
| 156975 | | -** the suspended OTA update is also an error (SQLITE_BUSY). |
| 157177 | +** the suspended RBU update is also an error (SQLITE_BUSY). |
| 156976 | 157178 | */ |
| 156977 | 157179 | |
| 156978 | | -#ifndef _SQLITE3OTA_H |
| 156979 | | -#define _SQLITE3OTA_H |
| 157180 | +#ifndef _SQLITE3RBU_H |
| 157181 | +#define _SQLITE3RBU_H |
| 156980 | 157182 | |
| 157183 | +/* #include "sqlite3.h" ** Required for error code definitions ** */ |
| 156981 | 157184 | |
| 156982 | | -typedef struct sqlite3ota sqlite3ota; |
| 157185 | +typedef struct sqlite3rbu sqlite3rbu; |
| 156983 | 157186 | |
| 156984 | 157187 | /* |
| 156985 | | -** Open an OTA handle. |
| 157188 | +** Open an RBU handle. |
| 156986 | 157189 | ** |
| 156987 | | -** Argument zTarget is the path to the target database. Argument zOta is |
| 156988 | | -** the path to the OTA database. Each call to this function must be matched |
| 156989 | | -** by a call to sqlite3ota_close(). When opening the databases, OTA passes |
| 157190 | +** Argument zTarget is the path to the target database. Argument zRbu is |
| 157191 | +** the path to the RBU database. Each call to this function must be matched |
| 157192 | +** by a call to sqlite3rbu_close(). When opening the databases, RBU passes |
| 156990 | 157193 | ** the SQLITE_CONFIG_URI flag to sqlite3_open_v2(). So if either zTarget |
| 156991 | | -** or zOta begin with "file:", it will be interpreted as an SQLite |
| 157194 | +** or zRbu begin with "file:", it will be interpreted as an SQLite |
| 156992 | 157195 | ** database URI, not a regular file name. |
| 156993 | 157196 | ** |
| 156994 | | -** If the zState argument is passed a NULL value, the OTA extension stores |
| 157197 | +** If the zState argument is passed a NULL value, the RBU extension stores |
| 156995 | 157198 | ** the current state of the update (how many rows have been updated, which |
| 156996 | | -** indexes are yet to be updated etc.) within the OTA database itself. This |
| 156997 | | -** can be convenient, as it means that the OTA application does not need to |
| 157199 | +** indexes are yet to be updated etc.) within the RBU database itself. This |
| 157200 | +** can be convenient, as it means that the RBU application does not need to |
| 156998 | 157201 | ** organize removing a separate state file after the update is concluded. |
| 156999 | 157202 | ** Or, if zState is non-NULL, it must be a path to a database file in which |
| 157000 | | -** the OTA extension can store the state of the update. |
| 157203 | +** the RBU extension can store the state of the update. |
| 157001 | 157204 | ** |
| 157002 | | -** When resuming an OTA update, the zState argument must be passed the same |
| 157003 | | -** value as when the OTA update was started. |
| 157205 | +** When resuming an RBU update, the zState argument must be passed the same |
| 157206 | +** value as when the RBU update was started. |
| 157004 | 157207 | ** |
| 157005 | | -** Once the OTA update is finished, the OTA extension does not |
| 157208 | +** Once the RBU update is finished, the RBU extension does not |
| 157006 | 157209 | ** automatically remove any zState database file, even if it created it. |
| 157007 | 157210 | ** |
| 157008 | | -** By default, OTA uses the default VFS to access the files on disk. To |
| 157211 | +** By default, RBU uses the default VFS to access the files on disk. To |
| 157009 | 157212 | ** use a VFS other than the default, an SQLite "file:" URI containing a |
| 157010 | 157213 | ** "vfs=..." option may be passed as the zTarget option. |
| 157011 | 157214 | ** |
| 157012 | | -** IMPORTANT NOTE FOR ZIPVFS USERS: The OTA extension works with all of |
| 157215 | +** IMPORTANT NOTE FOR ZIPVFS USERS: The RBU extension works with all of |
| 157013 | 157216 | ** SQLite's built-in VFSs, including the multiplexor VFS. However it does |
| 157014 | 157217 | ** not work out of the box with zipvfs. Refer to the comment describing |
| 157015 | | -** the zipvfs_create_vfs() API below for details on using OTA with zipvfs. |
| 157218 | +** the zipvfs_create_vfs() API below for details on using RBU with zipvfs. |
| 157016 | 157219 | */ |
| 157017 | | -SQLITE_API sqlite3ota *SQLITE_STDCALL sqlite3ota_open( |
| 157220 | +SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open( |
| 157018 | 157221 | const char *zTarget, |
| 157019 | | - const char *zOta, |
| 157222 | + const char *zRbu, |
| 157020 | 157223 | const char *zState |
| 157021 | 157224 | ); |
| 157022 | 157225 | |
| 157023 | 157226 | /* |
| 157024 | | -** Internally, each OTA connection uses a separate SQLite database |
| 157025 | | -** connection to access the target and ota update databases. This |
| 157227 | +** Internally, each RBU connection uses a separate SQLite database |
| 157228 | +** connection to access the target and rbu update databases. This |
| 157026 | 157229 | ** API allows the application direct access to these database handles. |
| 157027 | 157230 | ** |
| 157028 | | -** The first argument passed to this function must be a valid, open, OTA |
| 157231 | +** The first argument passed to this function must be a valid, open, RBU |
| 157029 | 157232 | ** handle. The second argument should be passed zero to access the target |
| 157030 | | -** database handle, or non-zero to access the ota update database handle. |
| 157233 | +** database handle, or non-zero to access the rbu update database handle. |
| 157031 | 157234 | ** Accessing the underlying database handles may be useful in the |
| 157032 | 157235 | ** following scenarios: |
| 157033 | 157236 | ** |
| 157034 | 157237 | ** * If any target tables are virtual tables, it may be necessary to |
| 157035 | 157238 | ** call sqlite3_create_module() on the target database handle to |
| 157036 | 157239 | ** register the required virtual table implementations. |
| 157037 | 157240 | ** |
| 157038 | | -** * If the data_xxx tables in the OTA source database are virtual |
| 157241 | +** * If the data_xxx tables in the RBU source database are virtual |
| 157039 | 157242 | ** tables, the application may need to call sqlite3_create_module() on |
| 157040 | | -** the ota update db handle to any required virtual table |
| 157243 | +** the rbu update db handle to any required virtual table |
| 157041 | 157244 | ** implementations. |
| 157042 | 157245 | ** |
| 157043 | | -** * If the application uses the "ota_delta()" feature described above, |
| 157246 | +** * If the application uses the "rbu_delta()" feature described above, |
| 157044 | 157247 | ** it must use sqlite3_create_function() or similar to register the |
| 157045 | | -** ota_delta() implementation with the target database handle. |
| 157248 | +** rbu_delta() implementation with the target database handle. |
| 157046 | 157249 | ** |
| 157047 | | -** If an error has occurred, either while opening or stepping the OTA object, |
| 157250 | +** If an error has occurred, either while opening or stepping the RBU object, |
| 157048 | 157251 | ** this function may return NULL. The error code and message may be collected |
| 157049 | | -** when sqlite3ota_close() is called. |
| 157252 | +** when sqlite3rbu_close() is called. |
| 157050 | 157253 | */ |
| 157051 | | -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3ota_db(sqlite3ota*, int bOta); |
| 157254 | +SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu*, int bRbu); |
| 157052 | 157255 | |
| 157053 | 157256 | /* |
| 157054 | | -** Do some work towards applying the OTA update to the target db. |
| 157257 | +** Do some work towards applying the RBU update to the target db. |
| 157055 | 157258 | ** |
| 157056 | 157259 | ** Return SQLITE_DONE if the update has been completely applied, or |
| 157057 | 157260 | ** SQLITE_OK if no error occurs but there remains work to do to apply |
| 157058 | | -** the OTA update. If an error does occur, some other error code is |
| 157261 | +** the RBU update. If an error does occur, some other error code is |
| 157059 | 157262 | ** returned. |
| 157060 | 157263 | ** |
| 157061 | | -** Once a call to sqlite3ota_step() has returned a value other than |
| 157062 | | -** SQLITE_OK, all subsequent calls on the same OTA handle are no-ops |
| 157264 | +** Once a call to sqlite3rbu_step() has returned a value other than |
| 157265 | +** SQLITE_OK, all subsequent calls on the same RBU handle are no-ops |
| 157063 | 157266 | ** that immediately return the same value. |
| 157064 | 157267 | */ |
| 157065 | | -SQLITE_API int SQLITE_STDCALL sqlite3ota_step(sqlite3ota *pOta); |
| 157268 | +SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *pRbu); |
| 157066 | 157269 | |
| 157067 | 157270 | /* |
| 157068 | | -** Close an OTA handle. |
| 157271 | +** Close an RBU handle. |
| 157069 | 157272 | ** |
| 157070 | | -** If the OTA update has been completely applied, mark the OTA database |
| 157273 | +** If the RBU update has been completely applied, mark the RBU database |
| 157071 | 157274 | ** as fully applied. Otherwise, assuming no error has occurred, save the |
| 157072 | | -** current state of the OTA update appliation to the OTA database. |
| 157275 | +** current state of the RBU update appliation to the RBU database. |
| 157073 | 157276 | ** |
| 157074 | | -** If an error has already occurred as part of an sqlite3ota_step() |
| 157075 | | -** or sqlite3ota_open() call, or if one occurs within this function, an |
| 157277 | +** If an error has already occurred as part of an sqlite3rbu_step() |
| 157278 | +** or sqlite3rbu_open() call, or if one occurs within this function, an |
| 157076 | 157279 | ** SQLite error code is returned. Additionally, *pzErrmsg may be set to |
| 157077 | 157280 | ** point to a buffer containing a utf-8 formatted English language error |
| 157078 | 157281 | ** message. It is the responsibility of the caller to eventually free any |
| 157079 | 157282 | ** such buffer using sqlite3_free(). |
| 157080 | 157283 | ** |
| 157081 | 157284 | ** Otherwise, if no error occurs, this function returns SQLITE_OK if the |
| 157082 | 157285 | ** update has been partially applied, or SQLITE_DONE if it has been |
| 157083 | 157286 | ** completely applied. |
| 157084 | 157287 | */ |
| 157085 | | -SQLITE_API int SQLITE_STDCALL sqlite3ota_close(sqlite3ota *pOta, char **pzErrmsg); |
| 157288 | +SQLITE_API int SQLITE_STDCALL sqlite3rbu_close(sqlite3rbu *pRbu, char **pzErrmsg); |
| 157086 | 157289 | |
| 157087 | 157290 | /* |
| 157088 | 157291 | ** Return the total number of key-value operations (inserts, deletes or |
| 157089 | 157292 | ** updates) that have been performed on the target database since the |
| 157090 | | -** current OTA update was started. |
| 157293 | +** current RBU update was started. |
| 157091 | 157294 | */ |
| 157092 | | -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3ota_progress(sqlite3ota *pOta); |
| 157295 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3rbu_progress(sqlite3rbu *pRbu); |
| 157093 | 157296 | |
| 157094 | 157297 | /* |
| 157095 | | -** Create an OTA VFS named zName that accesses the underlying file-system |
| 157298 | +** Create an RBU VFS named zName that accesses the underlying file-system |
| 157096 | 157299 | ** via existing VFS zParent. Or, if the zParent parameter is passed NULL, |
| 157097 | | -** then the new OTA VFS uses the default system VFS to access the file-system. |
| 157300 | +** then the new RBU VFS uses the default system VFS to access the file-system. |
| 157098 | 157301 | ** The new object is registered as a non-default VFS with SQLite before |
| 157099 | 157302 | ** returning. |
| 157100 | 157303 | ** |
| 157101 | | -** Part of the OTA implementation uses a custom VFS object. Usually, this |
| 157102 | | -** object is created and deleted automatically by OTA. |
| 157304 | +** Part of the RBU implementation uses a custom VFS object. Usually, this |
| 157305 | +** object is created and deleted automatically by RBU. |
| 157103 | 157306 | ** |
| 157104 | 157307 | ** The exception is for applications that also use zipvfs. In this case, |
| 157105 | | -** the custom VFS must be explicitly created by the user before the OTA |
| 157106 | | -** handle is opened. The OTA VFS should be installed so that the zipvfs |
| 157107 | | -** VFS uses the OTA VFS, which in turn uses any other VFS layers in use |
| 157308 | +** the custom VFS must be explicitly created by the user before the RBU |
| 157309 | +** handle is opened. The RBU VFS should be installed so that the zipvfs |
| 157310 | +** VFS uses the RBU VFS, which in turn uses any other VFS layers in use |
| 157108 | 157311 | ** (for example multiplexor) to access the file-system. For example, |
| 157109 | | -** to assemble an OTA enabled VFS stack that uses both zipvfs and |
| 157312 | +** to assemble an RBU enabled VFS stack that uses both zipvfs and |
| 157110 | 157313 | ** multiplexor (error checking omitted): |
| 157111 | 157314 | ** |
| 157112 | 157315 | ** // Create a VFS named "multiplex" (not the default). |
| 157113 | 157316 | ** sqlite3_multiplex_initialize(0, 0); |
| 157114 | 157317 | ** |
| 157115 | | -** // Create an ota VFS named "ota" that uses multiplexor. If the |
| 157116 | | -** // second argument were replaced with NULL, the "ota" VFS would |
| 157318 | +** // Create an rbu VFS named "rbu" that uses multiplexor. If the |
| 157319 | +** // second argument were replaced with NULL, the "rbu" VFS would |
| 157117 | 157320 | ** // access the file-system via the system default VFS, bypassing the |
| 157118 | 157321 | ** // multiplexor. |
| 157119 | | -** sqlite3ota_create_vfs("ota", "multiplex"); |
| 157322 | +** sqlite3rbu_create_vfs("rbu", "multiplex"); |
| 157120 | 157323 | ** |
| 157121 | | -** // Create a zipvfs VFS named "zipvfs" that uses ota. |
| 157122 | | -** zipvfs_create_vfs_v3("zipvfs", "ota", 0, xCompressorAlgorithmDetector); |
| 157324 | +** // Create a zipvfs VFS named "zipvfs" that uses rbu. |
| 157325 | +** zipvfs_create_vfs_v3("zipvfs", "rbu", 0, xCompressorAlgorithmDetector); |
| 157123 | 157326 | ** |
| 157124 | 157327 | ** // Make zipvfs the default VFS. |
| 157125 | 157328 | ** sqlite3_vfs_register(sqlite3_vfs_find("zipvfs"), 1); |
| 157126 | 157329 | ** |
| 157127 | | -** Because the default VFS created above includes a OTA functionality, it |
| 157128 | | -** may be used by OTA clients. Attempting to use OTA with a zipvfs VFS stack |
| 157129 | | -** that does not include the OTA layer results in an error. |
| 157330 | +** Because the default VFS created above includes a RBU functionality, it |
| 157331 | +** may be used by RBU clients. Attempting to use RBU with a zipvfs VFS stack |
| 157332 | +** that does not include the RBU layer results in an error. |
| 157130 | 157333 | ** |
| 157131 | | -** The overhead of adding the "ota" VFS to the system is negligible for |
| 157132 | | -** non-OTA users. There is no harm in an application accessing the |
| 157133 | | -** file-system via "ota" all the time, even if it only uses OTA functionality |
| 157334 | +** The overhead of adding the "rbu" VFS to the system is negligible for |
| 157335 | +** non-RBU users. There is no harm in an application accessing the |
| 157336 | +** file-system via "rbu" all the time, even if it only uses RBU functionality |
| 157134 | 157337 | ** occasionally. |
| 157135 | 157338 | */ |
| 157136 | | -SQLITE_API int SQLITE_STDCALL sqlite3ota_create_vfs(const char *zName, const char *zParent); |
| 157339 | +SQLITE_API int SQLITE_STDCALL sqlite3rbu_create_vfs(const char *zName, const char *zParent); |
| 157137 | 157340 | |
| 157138 | 157341 | /* |
| 157139 | | -** Deregister and destroy an OTA vfs created by an earlier call to |
| 157140 | | -** sqlite3ota_create_vfs(). |
| 157342 | +** Deregister and destroy an RBU vfs created by an earlier call to |
| 157343 | +** sqlite3rbu_create_vfs(). |
| 157141 | 157344 | ** |
| 157142 | 157345 | ** VFS objects are not reference counted. If a VFS object is destroyed |
| 157143 | 157346 | ** before all database handles that use it have been closed, the results |
| 157144 | 157347 | ** are undefined. |
| 157145 | 157348 | */ |
| 157146 | | -SQLITE_API void SQLITE_STDCALL sqlite3ota_destroy_vfs(const char *zName); |
| 157349 | +SQLITE_API void SQLITE_STDCALL sqlite3rbu_destroy_vfs(const char *zName); |
| 157147 | 157350 | |
| 157148 | | -#endif /* _SQLITE3OTA_H */ |
| 157351 | +#endif /* _SQLITE3RBU_H */ |
| 157149 | 157352 | |
| 157150 | | - |
| 157151 | | -/************** End of sqlite3ota.h ******************************************/ |
| 157152 | | -/************** Continuing where we left off in sqlite3ota.c *****************/ |
| 157353 | +/************** End of sqlite3rbu.h ******************************************/ |
| 157354 | +/************** Continuing where we left off in sqlite3rbu.c *****************/ |
| 157153 | 157355 | |
| 157154 | 157356 | /* Maximum number of prepared UPDATE statements held by this module */ |
| 157155 | | -#define SQLITE_OTA_UPDATE_CACHESIZE 16 |
| 157357 | +#define SQLITE_RBU_UPDATE_CACHESIZE 16 |
| 157156 | 157358 | |
| 157157 | 157359 | /* |
| 157158 | 157360 | ** Swap two objects of type TYPE. |
| 157159 | 157361 | */ |
| 157160 | 157362 | #if !defined(SQLITE_AMALGAMATION) |
| 157161 | 157363 | # define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} |
| 157162 | 157364 | #endif |
| 157163 | 157365 | |
| 157164 | 157366 | /* |
| 157165 | | -** The ota_state table is used to save the state of a partially applied |
| 157367 | +** The rbu_state table is used to save the state of a partially applied |
| 157166 | 157368 | ** update so that it can be resumed later. The table consists of integer |
| 157167 | 157369 | ** keys mapped to values as follows: |
| 157168 | 157370 | ** |
| 157169 | | -** OTA_STATE_STAGE: |
| 157371 | +** RBU_STATE_STAGE: |
| 157170 | 157372 | ** May be set to integer values 1, 2, 4 or 5. As follows: |
| 157171 | | -** 1: the *-ota file is currently under construction. |
| 157172 | | -** 2: the *-ota file has been constructed, but not yet moved |
| 157373 | +** 1: the *-rbu file is currently under construction. |
| 157374 | +** 2: the *-rbu file has been constructed, but not yet moved |
| 157173 | 157375 | ** to the *-wal path. |
| 157174 | 157376 | ** 4: the checkpoint is underway. |
| 157175 | | -** 5: the ota update has been checkpointed. |
| 157377 | +** 5: the rbu update has been checkpointed. |
| 157176 | 157378 | ** |
| 157177 | | -** OTA_STATE_TBL: |
| 157379 | +** RBU_STATE_TBL: |
| 157178 | 157380 | ** Only valid if STAGE==1. The target database name of the table |
| 157179 | 157381 | ** currently being written. |
| 157180 | 157382 | ** |
| 157181 | | -** OTA_STATE_IDX: |
| 157383 | +** RBU_STATE_IDX: |
| 157182 | 157384 | ** Only valid if STAGE==1. The target database name of the index |
| 157183 | 157385 | ** currently being written, or NULL if the main table is currently being |
| 157184 | 157386 | ** updated. |
| 157185 | 157387 | ** |
| 157186 | | -** OTA_STATE_ROW: |
| 157388 | +** RBU_STATE_ROW: |
| 157187 | 157389 | ** Only valid if STAGE==1. Number of rows already processed for the current |
| 157188 | 157390 | ** table/index. |
| 157189 | 157391 | ** |
| 157190 | | -** OTA_STATE_PROGRESS: |
| 157191 | | -** Total number of sqlite3ota_step() calls made so far as part of this |
| 157192 | | -** ota update. |
| 157392 | +** RBU_STATE_PROGRESS: |
| 157393 | +** Trbul number of sqlite3rbu_step() calls made so far as part of this |
| 157394 | +** rbu update. |
| 157193 | 157395 | ** |
| 157194 | | -** OTA_STATE_CKPT: |
| 157396 | +** RBU_STATE_CKPT: |
| 157195 | 157397 | ** Valid if STAGE==4. The 64-bit checksum associated with the wal-index |
| 157196 | 157398 | ** header created by recovering the *-wal file. This is used to detect |
| 157197 | 157399 | ** cases when another client appends frames to the *-wal file in the |
| 157198 | 157400 | ** middle of an incremental checkpoint (an incremental checkpoint cannot |
| 157199 | 157401 | ** be continued if this happens). |
| 157200 | 157402 | ** |
| 157201 | | -** OTA_STATE_COOKIE: |
| 157403 | +** RBU_STATE_COOKIE: |
| 157202 | 157404 | ** Valid if STAGE==1. The current change-counter cookie value in the |
| 157203 | 157405 | ** target db file. |
| 157204 | 157406 | ** |
| 157205 | | -** OTA_STATE_OALSZ: |
| 157407 | +** RBU_STATE_OALSZ: |
| 157206 | 157408 | ** Valid if STAGE==1. The size in bytes of the *-oal file. |
| 157207 | 157409 | */ |
| 157208 | | -#define OTA_STATE_STAGE 1 |
| 157209 | | -#define OTA_STATE_TBL 2 |
| 157210 | | -#define OTA_STATE_IDX 3 |
| 157211 | | -#define OTA_STATE_ROW 4 |
| 157212 | | -#define OTA_STATE_PROGRESS 5 |
| 157213 | | -#define OTA_STATE_CKPT 6 |
| 157214 | | -#define OTA_STATE_COOKIE 7 |
| 157215 | | -#define OTA_STATE_OALSZ 8 |
| 157216 | | - |
| 157217 | | -#define OTA_STAGE_OAL 1 |
| 157218 | | -#define OTA_STAGE_MOVE 2 |
| 157219 | | -#define OTA_STAGE_CAPTURE 3 |
| 157220 | | -#define OTA_STAGE_CKPT 4 |
| 157221 | | -#define OTA_STAGE_DONE 5 |
| 157222 | | - |
| 157223 | | - |
| 157224 | | -#define OTA_CREATE_STATE \ |
| 157225 | | - "CREATE TABLE IF NOT EXISTS %s.ota_state(k INTEGER PRIMARY KEY, v)" |
| 157226 | | - |
| 157227 | | -typedef struct OtaFrame OtaFrame; |
| 157228 | | -typedef struct OtaObjIter OtaObjIter; |
| 157229 | | -typedef struct OtaState OtaState; |
| 157230 | | -typedef struct ota_vfs ota_vfs; |
| 157231 | | -typedef struct ota_file ota_file; |
| 157232 | | -typedef struct OtaUpdateStmt OtaUpdateStmt; |
| 157410 | +#define RBU_STATE_STAGE 1 |
| 157411 | +#define RBU_STATE_TBL 2 |
| 157412 | +#define RBU_STATE_IDX 3 |
| 157413 | +#define RBU_STATE_ROW 4 |
| 157414 | +#define RBU_STATE_PROGRESS 5 |
| 157415 | +#define RBU_STATE_CKPT 6 |
| 157416 | +#define RBU_STATE_COOKIE 7 |
| 157417 | +#define RBU_STATE_OALSZ 8 |
| 157418 | + |
| 157419 | +#define RBU_STAGE_OAL 1 |
| 157420 | +#define RBU_STAGE_MOVE 2 |
| 157421 | +#define RBU_STAGE_CAPTURE 3 |
| 157422 | +#define RBU_STAGE_CKPT 4 |
| 157423 | +#define RBU_STAGE_DONE 5 |
| 157424 | + |
| 157425 | + |
| 157426 | +#define RBU_CREATE_STATE \ |
| 157427 | + "CREATE TABLE IF NOT EXISTS %s.rbu_state(k INTEGER PRIMARY KEY, v)" |
| 157428 | + |
| 157429 | +typedef struct RbuFrame RbuFrame; |
| 157430 | +typedef struct RbuObjIter RbuObjIter; |
| 157431 | +typedef struct RbuState RbuState; |
| 157432 | +typedef struct rbu_vfs rbu_vfs; |
| 157433 | +typedef struct rbu_file rbu_file; |
| 157434 | +typedef struct RbuUpdateStmt RbuUpdateStmt; |
| 157233 | 157435 | |
| 157234 | 157436 | #if !defined(SQLITE_AMALGAMATION) |
| 157235 | 157437 | typedef unsigned int u32; |
| 157236 | 157438 | typedef unsigned char u8; |
| 157237 | 157439 | typedef sqlite3_int64 i64; |
| | @@ -157245,13 +157447,13 @@ |
| 157245 | 157447 | #define WAL_LOCK_WRITE 0 |
| 157246 | 157448 | #define WAL_LOCK_CKPT 1 |
| 157247 | 157449 | #define WAL_LOCK_READ0 3 |
| 157248 | 157450 | |
| 157249 | 157451 | /* |
| 157250 | | -** A structure to store values read from the ota_state table in memory. |
| 157452 | +** A structure to store values read from the rbu_state table in memory. |
| 157251 | 157453 | */ |
| 157252 | | -struct OtaState { |
| 157454 | +struct RbuState { |
| 157253 | 157455 | int eStage; |
| 157254 | 157456 | char *zTbl; |
| 157255 | 157457 | char *zIdx; |
| 157256 | 157458 | i64 iWalCksum; |
| 157257 | 157459 | int nRow; |
| | @@ -157258,14 +157460,14 @@ |
| 157258 | 157460 | i64 nProgress; |
| 157259 | 157461 | u32 iCookie; |
| 157260 | 157462 | i64 iOalSz; |
| 157261 | 157463 | }; |
| 157262 | 157464 | |
| 157263 | | -struct OtaUpdateStmt { |
| 157465 | +struct RbuUpdateStmt { |
| 157264 | 157466 | char *zMask; /* Copy of update mask used with pUpdate */ |
| 157265 | 157467 | sqlite3_stmt *pUpdate; /* Last update statement (or NULL) */ |
| 157266 | | - OtaUpdateStmt *pNext; |
| 157468 | + RbuUpdateStmt *pNext; |
| 157267 | 157469 | }; |
| 157268 | 157470 | |
| 157269 | 157471 | /* |
| 157270 | 157472 | ** An iterator of this type is used to iterate through all objects in |
| 157271 | 157473 | ** the target database that require updating. For each such table, the |
| | @@ -157280,131 +157482,131 @@ |
| 157280 | 157482 | ** it points to an array of flags nTblCol elements in size. The flag is |
| 157281 | 157483 | ** set for each column that is either a part of the PK or a part of an |
| 157282 | 157484 | ** index. Or clear otherwise. |
| 157283 | 157485 | ** |
| 157284 | 157486 | */ |
| 157285 | | -struct OtaObjIter { |
| 157487 | +struct RbuObjIter { |
| 157286 | 157488 | sqlite3_stmt *pTblIter; /* Iterate through tables */ |
| 157287 | 157489 | sqlite3_stmt *pIdxIter; /* Index iterator */ |
| 157288 | 157490 | int nTblCol; /* Size of azTblCol[] array */ |
| 157289 | 157491 | char **azTblCol; /* Array of unquoted target column names */ |
| 157290 | 157492 | char **azTblType; /* Array of target column types */ |
| 157291 | 157493 | int *aiSrcOrder; /* src table col -> target table col */ |
| 157292 | 157494 | u8 *abTblPk; /* Array of flags, set on target PK columns */ |
| 157293 | 157495 | u8 *abNotNull; /* Array of flags, set on NOT NULL columns */ |
| 157294 | 157496 | u8 *abIndexed; /* Array of flags, set on indexed & PK cols */ |
| 157295 | | - int eType; /* Table type - an OTA_PK_XXX value */ |
| 157497 | + int eType; /* Table type - an RBU_PK_XXX value */ |
| 157296 | 157498 | |
| 157297 | 157499 | /* Output variables. zTbl==0 implies EOF. */ |
| 157298 | 157500 | int bCleanup; /* True in "cleanup" state */ |
| 157299 | 157501 | const char *zTbl; /* Name of target db table */ |
| 157300 | 157502 | const char *zIdx; /* Name of target db index (or null) */ |
| 157301 | 157503 | int iTnum; /* Root page of current object */ |
| 157302 | 157504 | int iPkTnum; /* If eType==EXTERNAL, root of PK index */ |
| 157303 | 157505 | int bUnique; /* Current index is unique */ |
| 157304 | 157506 | |
| 157305 | | - /* Statements created by otaObjIterPrepareAll() */ |
| 157507 | + /* Statements created by rbuObjIterPrepareAll() */ |
| 157306 | 157508 | int nCol; /* Number of columns in current object */ |
| 157307 | 157509 | sqlite3_stmt *pSelect; /* Source data */ |
| 157308 | 157510 | sqlite3_stmt *pInsert; /* Statement for INSERT operations */ |
| 157309 | 157511 | sqlite3_stmt *pDelete; /* Statement for DELETE ops */ |
| 157310 | | - sqlite3_stmt *pTmpInsert; /* Insert into ota_tmp_$zTbl */ |
| 157512 | + sqlite3_stmt *pTmpInsert; /* Insert into rbu_tmp_$zTbl */ |
| 157311 | 157513 | |
| 157312 | 157514 | /* Last UPDATE used (for PK b-tree updates only), or NULL. */ |
| 157313 | | - OtaUpdateStmt *pOtaUpdate; |
| 157515 | + RbuUpdateStmt *pRbuUpdate; |
| 157314 | 157516 | }; |
| 157315 | 157517 | |
| 157316 | 157518 | /* |
| 157317 | | -** Values for OtaObjIter.eType |
| 157519 | +** Values for RbuObjIter.eType |
| 157318 | 157520 | ** |
| 157319 | 157521 | ** 0: Table does not exist (error) |
| 157320 | 157522 | ** 1: Table has an implicit rowid. |
| 157321 | 157523 | ** 2: Table has an explicit IPK column. |
| 157322 | 157524 | ** 3: Table has an external PK index. |
| 157323 | 157525 | ** 4: Table is WITHOUT ROWID. |
| 157324 | 157526 | ** 5: Table is a virtual table. |
| 157325 | 157527 | */ |
| 157326 | | -#define OTA_PK_NOTABLE 0 |
| 157327 | | -#define OTA_PK_NONE 1 |
| 157328 | | -#define OTA_PK_IPK 2 |
| 157329 | | -#define OTA_PK_EXTERNAL 3 |
| 157330 | | -#define OTA_PK_WITHOUT_ROWID 4 |
| 157331 | | -#define OTA_PK_VTAB 5 |
| 157528 | +#define RBU_PK_NOTABLE 0 |
| 157529 | +#define RBU_PK_NONE 1 |
| 157530 | +#define RBU_PK_IPK 2 |
| 157531 | +#define RBU_PK_EXTERNAL 3 |
| 157532 | +#define RBU_PK_WITHOUT_ROWID 4 |
| 157533 | +#define RBU_PK_VTAB 5 |
| 157332 | 157534 | |
| 157333 | 157535 | |
| 157334 | 157536 | /* |
| 157335 | | -** Within the OTA_STAGE_OAL stage, each call to sqlite3ota_step() performs |
| 157537 | +** Within the RBU_STAGE_OAL stage, each call to sqlite3rbu_step() performs |
| 157336 | 157538 | ** one of the following operations. |
| 157337 | 157539 | */ |
| 157338 | | -#define OTA_INSERT 1 /* Insert on a main table b-tree */ |
| 157339 | | -#define OTA_DELETE 2 /* Delete a row from a main table b-tree */ |
| 157340 | | -#define OTA_IDX_DELETE 3 /* Delete a row from an aux. index b-tree */ |
| 157341 | | -#define OTA_IDX_INSERT 4 /* Insert on an aux. index b-tree */ |
| 157342 | | -#define OTA_UPDATE 5 /* Update a row in a main table b-tree */ |
| 157540 | +#define RBU_INSERT 1 /* Insert on a main table b-tree */ |
| 157541 | +#define RBU_DELETE 2 /* Delete a row from a main table b-tree */ |
| 157542 | +#define RBU_IDX_DELETE 3 /* Delete a row from an aux. index b-tree */ |
| 157543 | +#define RBU_IDX_INSERT 4 /* Insert on an aux. index b-tree */ |
| 157544 | +#define RBU_UPDATE 5 /* Update a row in a main table b-tree */ |
| 157343 | 157545 | |
| 157344 | 157546 | |
| 157345 | 157547 | /* |
| 157346 | 157548 | ** A single step of an incremental checkpoint - frame iWalFrame of the wal |
| 157347 | 157549 | ** file should be copied to page iDbPage of the database file. |
| 157348 | 157550 | */ |
| 157349 | | -struct OtaFrame { |
| 157551 | +struct RbuFrame { |
| 157350 | 157552 | u32 iDbPage; |
| 157351 | 157553 | u32 iWalFrame; |
| 157352 | 157554 | }; |
| 157353 | 157555 | |
| 157354 | 157556 | /* |
| 157355 | | -** OTA handle. |
| 157557 | +** RBU handle. |
| 157356 | 157558 | */ |
| 157357 | | -struct sqlite3ota { |
| 157358 | | - int eStage; /* Value of OTA_STATE_STAGE field */ |
| 157559 | +struct sqlite3rbu { |
| 157560 | + int eStage; /* Value of RBU_STATE_STAGE field */ |
| 157359 | 157561 | sqlite3 *dbMain; /* target database handle */ |
| 157360 | | - sqlite3 *dbOta; /* ota database handle */ |
| 157562 | + sqlite3 *dbRbu; /* rbu database handle */ |
| 157361 | 157563 | char *zTarget; /* Path to target db */ |
| 157362 | | - char *zOta; /* Path to ota db */ |
| 157363 | | - char *zState; /* Path to state db (or NULL if zOta) */ |
| 157564 | + char *zRbu; /* Path to rbu db */ |
| 157565 | + char *zState; /* Path to state db (or NULL if zRbu) */ |
| 157364 | 157566 | char zStateDb[5]; /* Db name for state ("stat" or "main") */ |
| 157365 | | - int rc; /* Value returned by last ota_step() call */ |
| 157567 | + int rc; /* Value returned by last rbu_step() call */ |
| 157366 | 157568 | char *zErrmsg; /* Error message if rc!=SQLITE_OK */ |
| 157367 | 157569 | int nStep; /* Rows processed for current object */ |
| 157368 | 157570 | int nProgress; /* Rows processed for all objects */ |
| 157369 | | - OtaObjIter objiter; /* Iterator for skipping through tbl/idx */ |
| 157370 | | - const char *zVfsName; /* Name of automatically created ota vfs */ |
| 157371 | | - ota_file *pTargetFd; /* File handle open on target db */ |
| 157571 | + RbuObjIter objiter; /* Iterator for skipping through tbl/idx */ |
| 157572 | + const char *zVfsName; /* Name of automatically created rbu vfs */ |
| 157573 | + rbu_file *pTargetFd; /* File handle open on target db */ |
| 157372 | 157574 | i64 iOalSz; |
| 157373 | 157575 | |
| 157374 | 157576 | /* The following state variables are used as part of the incremental |
| 157375 | | - ** checkpoint stage (eStage==OTA_STAGE_CKPT). See comments surrounding |
| 157376 | | - ** function otaSetupCheckpoint() for details. */ |
| 157577 | + ** checkpoint stage (eStage==RBU_STAGE_CKPT). See comments surrounding |
| 157578 | + ** function rbuSetupCheckpoint() for details. */ |
| 157377 | 157579 | u32 iMaxFrame; /* Largest iWalFrame value in aFrame[] */ |
| 157378 | 157580 | u32 mLock; |
| 157379 | 157581 | int nFrame; /* Entries in aFrame[] array */ |
| 157380 | 157582 | int nFrameAlloc; /* Allocated size of aFrame[] array */ |
| 157381 | | - OtaFrame *aFrame; |
| 157583 | + RbuFrame *aFrame; |
| 157382 | 157584 | int pgsz; |
| 157383 | 157585 | u8 *aBuf; |
| 157384 | 157586 | i64 iWalCksum; |
| 157385 | 157587 | }; |
| 157386 | 157588 | |
| 157387 | 157589 | /* |
| 157388 | | -** An ota VFS is implemented using an instance of this structure. |
| 157590 | +** An rbu VFS is implemented using an instance of this structure. |
| 157389 | 157591 | */ |
| 157390 | | -struct ota_vfs { |
| 157391 | | - sqlite3_vfs base; /* ota VFS shim methods */ |
| 157592 | +struct rbu_vfs { |
| 157593 | + sqlite3_vfs base; /* rbu VFS shim methods */ |
| 157392 | 157594 | sqlite3_vfs *pRealVfs; /* Underlying VFS */ |
| 157393 | 157595 | sqlite3_mutex *mutex; /* Mutex to protect pMain */ |
| 157394 | | - ota_file *pMain; /* Linked list of main db files */ |
| 157596 | + rbu_file *pMain; /* Linked list of main db files */ |
| 157395 | 157597 | }; |
| 157396 | 157598 | |
| 157397 | 157599 | /* |
| 157398 | | -** Each file opened by an ota VFS is represented by an instance of |
| 157600 | +** Each file opened by an rbu VFS is represented by an instance of |
| 157399 | 157601 | ** the following structure. |
| 157400 | 157602 | */ |
| 157401 | | -struct ota_file { |
| 157603 | +struct rbu_file { |
| 157402 | 157604 | sqlite3_file base; /* sqlite3_file methods */ |
| 157403 | 157605 | sqlite3_file *pReal; /* Underlying file handle */ |
| 157404 | | - ota_vfs *pOtaVfs; /* Pointer to the ota_vfs object */ |
| 157405 | | - sqlite3ota *pOta; /* Pointer to ota object (ota target only) */ |
| 157606 | + rbu_vfs *pRbuVfs; /* Pointer to the rbu_vfs object */ |
| 157607 | + sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */ |
| 157406 | 157608 | |
| 157407 | 157609 | int openFlags; /* Flags this file was opened with */ |
| 157408 | 157610 | u32 iCookie; /* Cookie value for main db files */ |
| 157409 | 157611 | u8 iWriteVer; /* "write-version" value for main db files */ |
| 157410 | 157612 | |
| | @@ -157411,12 +157613,12 @@ |
| 157411 | 157613 | int nShm; /* Number of entries in apShm[] array */ |
| 157412 | 157614 | char **apShm; /* Array of mmap'd *-shm regions */ |
| 157413 | 157615 | char *zDel; /* Delete this when closing file */ |
| 157414 | 157616 | |
| 157415 | 157617 | const char *zWal; /* Wal filename for this main db file */ |
| 157416 | | - ota_file *pWalFd; /* Wal file descriptor for this main db */ |
| 157417 | | - ota_file *pMainNext; /* Next MAIN_DB file */ |
| 157618 | + rbu_file *pWalFd; /* Wal file descriptor for this main db */ |
| 157619 | + rbu_file *pMainNext; /* Next MAIN_DB file */ |
| 157418 | 157620 | }; |
| 157419 | 157621 | |
| 157420 | 157622 | |
| 157421 | 157623 | /* |
| 157422 | 157624 | ** Prepare the SQL statement in buffer zSql against database handle db. |
| | @@ -157490,14 +157692,14 @@ |
| 157490 | 157692 | } |
| 157491 | 157693 | return rc; |
| 157492 | 157694 | } |
| 157493 | 157695 | |
| 157494 | 157696 | /* |
| 157495 | | -** Free the OtaObjIter.azTblCol[] and OtaObjIter.abTblPk[] arrays allocated |
| 157496 | | -** by an earlier call to otaObjIterCacheTableInfo(). |
| 157697 | +** Free the RbuObjIter.azTblCol[] and RbuObjIter.abTblPk[] arrays allocated |
| 157698 | +** by an earlier call to rbuObjIterCacheTableInfo(). |
| 157497 | 157699 | */ |
| 157498 | | -static void otaObjIterFreeCols(OtaObjIter *pIter){ |
| 157700 | +static void rbuObjIterFreeCols(RbuObjIter *pIter){ |
| 157499 | 157701 | int i; |
| 157500 | 157702 | for(i=0; i<pIter->nTblCol; i++){ |
| 157501 | 157703 | sqlite3_free(pIter->azTblCol[i]); |
| 157502 | 157704 | sqlite3_free(pIter->azTblType[i]); |
| 157503 | 157705 | } |
| | @@ -157513,72 +157715,72 @@ |
| 157513 | 157715 | |
| 157514 | 157716 | /* |
| 157515 | 157717 | ** Finalize all statements and free all allocations that are specific to |
| 157516 | 157718 | ** the current object (table/index pair). |
| 157517 | 157719 | */ |
| 157518 | | -static void otaObjIterClearStatements(OtaObjIter *pIter){ |
| 157519 | | - OtaUpdateStmt *pUp; |
| 157720 | +static void rbuObjIterClearStatements(RbuObjIter *pIter){ |
| 157721 | + RbuUpdateStmt *pUp; |
| 157520 | 157722 | |
| 157521 | 157723 | sqlite3_finalize(pIter->pSelect); |
| 157522 | 157724 | sqlite3_finalize(pIter->pInsert); |
| 157523 | 157725 | sqlite3_finalize(pIter->pDelete); |
| 157524 | 157726 | sqlite3_finalize(pIter->pTmpInsert); |
| 157525 | | - pUp = pIter->pOtaUpdate; |
| 157727 | + pUp = pIter->pRbuUpdate; |
| 157526 | 157728 | while( pUp ){ |
| 157527 | | - OtaUpdateStmt *pTmp = pUp->pNext; |
| 157729 | + RbuUpdateStmt *pTmp = pUp->pNext; |
| 157528 | 157730 | sqlite3_finalize(pUp->pUpdate); |
| 157529 | 157731 | sqlite3_free(pUp); |
| 157530 | 157732 | pUp = pTmp; |
| 157531 | 157733 | } |
| 157532 | 157734 | |
| 157533 | 157735 | pIter->pSelect = 0; |
| 157534 | 157736 | pIter->pInsert = 0; |
| 157535 | 157737 | pIter->pDelete = 0; |
| 157536 | | - pIter->pOtaUpdate = 0; |
| 157738 | + pIter->pRbuUpdate = 0; |
| 157537 | 157739 | pIter->pTmpInsert = 0; |
| 157538 | 157740 | pIter->nCol = 0; |
| 157539 | 157741 | } |
| 157540 | 157742 | |
| 157541 | 157743 | /* |
| 157542 | 157744 | ** Clean up any resources allocated as part of the iterator object passed |
| 157543 | 157745 | ** as the only argument. |
| 157544 | 157746 | */ |
| 157545 | | -static void otaObjIterFinalize(OtaObjIter *pIter){ |
| 157546 | | - otaObjIterClearStatements(pIter); |
| 157747 | +static void rbuObjIterFinalize(RbuObjIter *pIter){ |
| 157748 | + rbuObjIterClearStatements(pIter); |
| 157547 | 157749 | sqlite3_finalize(pIter->pTblIter); |
| 157548 | 157750 | sqlite3_finalize(pIter->pIdxIter); |
| 157549 | | - otaObjIterFreeCols(pIter); |
| 157550 | | - memset(pIter, 0, sizeof(OtaObjIter)); |
| 157751 | + rbuObjIterFreeCols(pIter); |
| 157752 | + memset(pIter, 0, sizeof(RbuObjIter)); |
| 157551 | 157753 | } |
| 157552 | 157754 | |
| 157553 | 157755 | /* |
| 157554 | 157756 | ** Advance the iterator to the next position. |
| 157555 | 157757 | ** |
| 157556 | 157758 | ** If no error occurs, SQLITE_OK is returned and the iterator is left |
| 157557 | 157759 | ** pointing to the next entry. Otherwise, an error code and message is |
| 157558 | | -** left in the OTA handle passed as the first argument. A copy of the |
| 157760 | +** left in the RBU handle passed as the first argument. A copy of the |
| 157559 | 157761 | ** error code is returned. |
| 157560 | 157762 | */ |
| 157561 | | -static int otaObjIterNext(sqlite3ota *p, OtaObjIter *pIter){ |
| 157763 | +static int rbuObjIterNext(sqlite3rbu *p, RbuObjIter *pIter){ |
| 157562 | 157764 | int rc = p->rc; |
| 157563 | 157765 | if( rc==SQLITE_OK ){ |
| 157564 | 157766 | |
| 157565 | 157767 | /* Free any SQLite statements used while processing the previous object */ |
| 157566 | | - otaObjIterClearStatements(pIter); |
| 157768 | + rbuObjIterClearStatements(pIter); |
| 157567 | 157769 | if( pIter->zIdx==0 ){ |
| 157568 | 157770 | rc = sqlite3_exec(p->dbMain, |
| 157569 | | - "DROP TRIGGER IF EXISTS temp.ota_insert_tr;" |
| 157570 | | - "DROP TRIGGER IF EXISTS temp.ota_update1_tr;" |
| 157571 | | - "DROP TRIGGER IF EXISTS temp.ota_update2_tr;" |
| 157572 | | - "DROP TRIGGER IF EXISTS temp.ota_delete_tr;" |
| 157771 | + "DROP TRIGGER IF EXISTS temp.rbu_insert_tr;" |
| 157772 | + "DROP TRIGGER IF EXISTS temp.rbu_update1_tr;" |
| 157773 | + "DROP TRIGGER IF EXISTS temp.rbu_update2_tr;" |
| 157774 | + "DROP TRIGGER IF EXISTS temp.rbu_delete_tr;" |
| 157573 | 157775 | , 0, 0, &p->zErrmsg |
| 157574 | 157776 | ); |
| 157575 | 157777 | } |
| 157576 | 157778 | |
| 157577 | 157779 | if( rc==SQLITE_OK ){ |
| 157578 | 157780 | if( pIter->bCleanup ){ |
| 157579 | | - otaObjIterFreeCols(pIter); |
| 157781 | + rbuObjIterFreeCols(pIter); |
| 157580 | 157782 | pIter->bCleanup = 0; |
| 157581 | 157783 | rc = sqlite3_step(pIter->pTblIter); |
| 157582 | 157784 | if( rc!=SQLITE_ROW ){ |
| 157583 | 157785 | rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg); |
| 157584 | 157786 | pIter->zTbl = 0; |
| | @@ -157607,11 +157809,11 @@ |
| 157607 | 157809 | } |
| 157608 | 157810 | } |
| 157609 | 157811 | } |
| 157610 | 157812 | |
| 157611 | 157813 | if( rc!=SQLITE_OK ){ |
| 157612 | | - otaObjIterFinalize(pIter); |
| 157814 | + rbuObjIterFinalize(pIter); |
| 157613 | 157815 | p->rc = rc; |
| 157614 | 157816 | } |
| 157615 | 157817 | return rc; |
| 157616 | 157818 | } |
| 157617 | 157819 | |
| | @@ -157618,18 +157820,18 @@ |
| 157618 | 157820 | /* |
| 157619 | 157821 | ** Initialize the iterator structure passed as the second argument. |
| 157620 | 157822 | ** |
| 157621 | 157823 | ** If no error occurs, SQLITE_OK is returned and the iterator is left |
| 157622 | 157824 | ** pointing to the first entry. Otherwise, an error code and message is |
| 157623 | | -** left in the OTA handle passed as the first argument. A copy of the |
| 157825 | +** left in the RBU handle passed as the first argument. A copy of the |
| 157624 | 157826 | ** error code is returned. |
| 157625 | 157827 | */ |
| 157626 | | -static int otaObjIterFirst(sqlite3ota *p, OtaObjIter *pIter){ |
| 157828 | +static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){ |
| 157627 | 157829 | int rc; |
| 157628 | | - memset(pIter, 0, sizeof(OtaObjIter)); |
| 157830 | + memset(pIter, 0, sizeof(RbuObjIter)); |
| 157629 | 157831 | |
| 157630 | | - rc = prepareAndCollectError(p->dbOta, &pIter->pTblIter, &p->zErrmsg, |
| 157832 | + rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg, |
| 157631 | 157833 | "SELECT substr(name, 6) FROM sqlite_master " |
| 157632 | 157834 | "WHERE type='table' AND name LIKE 'data_%'" |
| 157633 | 157835 | ); |
| 157634 | 157836 | |
| 157635 | 157837 | if( rc==SQLITE_OK ){ |
| | @@ -157640,23 +157842,23 @@ |
| 157640 | 157842 | ); |
| 157641 | 157843 | } |
| 157642 | 157844 | |
| 157643 | 157845 | pIter->bCleanup = 1; |
| 157644 | 157846 | p->rc = rc; |
| 157645 | | - return otaObjIterNext(p, pIter); |
| 157847 | + return rbuObjIterNext(p, pIter); |
| 157646 | 157848 | } |
| 157647 | 157849 | |
| 157648 | 157850 | /* |
| 157649 | 157851 | ** This is a wrapper around "sqlite3_mprintf(zFmt, ...)". If an OOM occurs, |
| 157650 | | -** an error code is stored in the OTA handle passed as the first argument. |
| 157852 | +** an error code is stored in the RBU handle passed as the first argument. |
| 157651 | 157853 | ** |
| 157652 | 157854 | ** If an error has already occurred (p->rc is already set to something other |
| 157653 | 157855 | ** than SQLITE_OK), then this function returns NULL without modifying the |
| 157654 | 157856 | ** stored error code. In this case it still calls sqlite3_free() on any |
| 157655 | 157857 | ** printf() parameters associated with %z conversions. |
| 157656 | 157858 | */ |
| 157657 | | -static char *otaMPrintf(sqlite3ota *p, const char *zFmt, ...){ |
| 157859 | +static char *rbuMPrintf(sqlite3rbu *p, const char *zFmt, ...){ |
| 157658 | 157860 | char *zSql = 0; |
| 157659 | 157861 | va_list ap; |
| 157660 | 157862 | va_start(ap, zFmt); |
| 157661 | 157863 | zSql = sqlite3_vmprintf(zFmt, ap); |
| 157662 | 157864 | if( p->rc==SQLITE_OK ){ |
| | @@ -157671,17 +157873,17 @@ |
| 157671 | 157873 | |
| 157672 | 157874 | /* |
| 157673 | 157875 | ** Argument zFmt is a sqlite3_mprintf() style format string. The trailing |
| 157674 | 157876 | ** arguments are the usual subsitution values. This function performs |
| 157675 | 157877 | ** the printf() style substitutions and executes the result as an SQL |
| 157676 | | -** statement on the OTA handles database. |
| 157878 | +** statement on the RBU handles database. |
| 157677 | 157879 | ** |
| 157678 | 157880 | ** If an error occurs, an error code and error message is stored in the |
| 157679 | | -** OTA handle. If an error has already occurred when this function is |
| 157881 | +** RBU handle. If an error has already occurred when this function is |
| 157680 | 157882 | ** called, it is a no-op. |
| 157681 | 157883 | */ |
| 157682 | | -static int otaMPrintfExec(sqlite3ota *p, sqlite3 *db, const char *zFmt, ...){ |
| 157884 | +static int rbuMPrintfExec(sqlite3rbu *p, sqlite3 *db, const char *zFmt, ...){ |
| 157683 | 157885 | va_list ap; |
| 157684 | 157886 | va_start(ap, zFmt); |
| 157685 | 157887 | char *zSql = sqlite3_vmprintf(zFmt, ap); |
| 157686 | 157888 | if( p->rc==SQLITE_OK ){ |
| 157687 | 157889 | if( zSql==0 ){ |
| | @@ -157698,16 +157900,16 @@ |
| 157698 | 157900 | /* |
| 157699 | 157901 | ** Attempt to allocate and return a pointer to a zeroed block of nByte |
| 157700 | 157902 | ** bytes. |
| 157701 | 157903 | ** |
| 157702 | 157904 | ** If an error (i.e. an OOM condition) occurs, return NULL and leave an |
| 157703 | | -** error code in the ota handle passed as the first argument. Or, if an |
| 157905 | +** error code in the rbu handle passed as the first argument. Or, if an |
| 157704 | 157906 | ** error has already occurred when this function is called, return NULL |
| 157705 | 157907 | ** immediately without attempting the allocation or modifying the stored |
| 157706 | 157908 | ** error code. |
| 157707 | 157909 | */ |
| 157708 | | -static void *otaMalloc(sqlite3ota *p, int nByte){ |
| 157910 | +static void *rbuMalloc(sqlite3rbu *p, int nByte){ |
| 157709 | 157911 | void *pRet = 0; |
| 157710 | 157912 | if( p->rc==SQLITE_OK ){ |
| 157711 | 157913 | assert( nByte>0 ); |
| 157712 | 157914 | pRet = sqlite3_malloc(nByte); |
| 157713 | 157915 | if( pRet==0 ){ |
| | @@ -157721,17 +157923,17 @@ |
| 157721 | 157923 | |
| 157722 | 157924 | |
| 157723 | 157925 | /* |
| 157724 | 157926 | ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that |
| 157725 | 157927 | ** there is room for at least nCol elements. If an OOM occurs, store an |
| 157726 | | -** error code in the OTA handle passed as the first argument. |
| 157928 | +** error code in the RBU handle passed as the first argument. |
| 157727 | 157929 | */ |
| 157728 | | -static void otaAllocateIterArrays(sqlite3ota *p, OtaObjIter *pIter, int nCol){ |
| 157930 | +static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){ |
| 157729 | 157931 | int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol; |
| 157730 | 157932 | char **azNew; |
| 157731 | 157933 | |
| 157732 | | - azNew = (char**)otaMalloc(p, nByte); |
| 157934 | + azNew = (char**)rbuMalloc(p, nByte); |
| 157733 | 157935 | if( azNew ){ |
| 157734 | 157936 | pIter->azTblCol = azNew; |
| 157735 | 157937 | pIter->azTblType = &azNew[nCol]; |
| 157736 | 157938 | pIter->aiSrcOrder = (int*)&pIter->azTblType[nCol]; |
| 157737 | 157939 | pIter->abTblPk = (u8*)&pIter->aiSrcOrder[nCol]; |
| | @@ -157748,11 +157950,11 @@ |
| 157748 | 157950 | ** |
| 157749 | 157951 | ** If an OOM condition is encountered when attempting to allocate memory, |
| 157750 | 157952 | ** output variable (*pRc) is set to SQLITE_NOMEM before returning. Otherwise, |
| 157751 | 157953 | ** if the allocation succeeds, (*pRc) is left unchanged. |
| 157752 | 157954 | */ |
| 157753 | | -static char *otaStrndup(const char *zStr, int *pRc){ |
| 157955 | +static char *rbuStrndup(const char *zStr, int *pRc){ |
| 157754 | 157956 | char *zRet = 0; |
| 157755 | 157957 | |
| 157756 | 157958 | assert( *pRc==SQLITE_OK ); |
| 157757 | 157959 | if( zStr ){ |
| 157758 | 157960 | int nCopy = strlen(zStr) + 1; |
| | @@ -157769,14 +157971,14 @@ |
| 157769 | 157971 | |
| 157770 | 157972 | /* |
| 157771 | 157973 | ** Finalize the statement passed as the second argument. |
| 157772 | 157974 | ** |
| 157773 | 157975 | ** If the sqlite3_finalize() call indicates that an error occurs, and the |
| 157774 | | -** ota handle error code is not already set, set the error code and error |
| 157976 | +** rbu handle error code is not already set, set the error code and error |
| 157775 | 157977 | ** message accordingly. |
| 157776 | 157978 | */ |
| 157777 | | -static void otaFinalize(sqlite3ota *p, sqlite3_stmt *pStmt){ |
| 157979 | +static void rbuFinalize(sqlite3rbu *p, sqlite3_stmt *pStmt){ |
| 157778 | 157980 | sqlite3 *db = sqlite3_db_handle(pStmt); |
| 157779 | 157981 | int rc = sqlite3_finalize(pStmt); |
| 157780 | 157982 | if( p->rc==SQLITE_OK && rc!=SQLITE_OK ){ |
| 157781 | 157983 | p->rc = rc; |
| 157782 | 157984 | p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db)); |
| | @@ -157787,16 +157989,16 @@ |
| 157787 | 157989 | ** |
| 157788 | 157990 | ** peType is of type (int*), a pointer to an output parameter of type |
| 157789 | 157991 | ** (int). This call sets the output parameter as follows, depending |
| 157790 | 157992 | ** on the type of the table specified by parameters dbName and zTbl. |
| 157791 | 157993 | ** |
| 157792 | | -** OTA_PK_NOTABLE: No such table. |
| 157793 | | -** OTA_PK_NONE: Table has an implicit rowid. |
| 157794 | | -** OTA_PK_IPK: Table has an explicit IPK column. |
| 157795 | | -** OTA_PK_EXTERNAL: Table has an external PK index. |
| 157796 | | -** OTA_PK_WITHOUT_ROWID: Table is WITHOUT ROWID. |
| 157797 | | -** OTA_PK_VTAB: Table is a virtual table. |
| 157994 | +** RBU_PK_NOTABLE: No such table. |
| 157995 | +** RBU_PK_NONE: Table has an implicit rowid. |
| 157996 | +** RBU_PK_IPK: Table has an explicit IPK column. |
| 157997 | +** RBU_PK_EXTERNAL: Table has an external PK index. |
| 157998 | +** RBU_PK_WITHOUT_ROWID: Table is WITHOUT ROWID. |
| 157999 | +** RBU_PK_VTAB: Table is a virtual table. |
| 157798 | 158000 | ** |
| 157799 | 158001 | ** Argument *piPk is also of type (int*), and also points to an output |
| 157800 | 158002 | ** parameter. Unless the table has an external primary key index |
| 157801 | 158003 | ** (i.e. unless *peType is set to 3), then *piPk is set to zero. Or, |
| 157802 | 158004 | ** if the table does have an external primary key index, then *piPk |
| | @@ -157804,28 +158006,28 @@ |
| 157804 | 158006 | ** returning. |
| 157805 | 158007 | ** |
| 157806 | 158008 | ** ALGORITHM: |
| 157807 | 158009 | ** |
| 157808 | 158010 | ** if( no entry exists in sqlite_master ){ |
| 157809 | | -** return OTA_PK_NOTABLE |
| 158011 | +** return RBU_PK_NOTABLE |
| 157810 | 158012 | ** }else if( sql for the entry starts with "CREATE VIRTUAL" ){ |
| 157811 | | -** return OTA_PK_VTAB |
| 158013 | +** return RBU_PK_VTAB |
| 157812 | 158014 | ** }else if( "PRAGMA index_list()" for the table contains a "pk" index ){ |
| 157813 | 158015 | ** if( the index that is the pk exists in sqlite_master ){ |
| 157814 | 158016 | ** *piPK = rootpage of that index. |
| 157815 | | -** return OTA_PK_EXTERNAL |
| 158017 | +** return RBU_PK_EXTERNAL |
| 157816 | 158018 | ** }else{ |
| 157817 | | -** return OTA_PK_WITHOUT_ROWID |
| 158019 | +** return RBU_PK_WITHOUT_ROWID |
| 157818 | 158020 | ** } |
| 157819 | 158021 | ** }else if( "PRAGMA table_info()" lists one or more "pk" columns ){ |
| 157820 | | -** return OTA_PK_IPK |
| 158022 | +** return RBU_PK_IPK |
| 157821 | 158023 | ** }else{ |
| 157822 | | -** return OTA_PK_NONE |
| 158024 | +** return RBU_PK_NONE |
| 157823 | 158025 | ** } |
| 157824 | 158026 | */ |
| 157825 | | -static void otaTableType( |
| 157826 | | - sqlite3ota *p, |
| 158027 | +static void rbuTableType( |
| 158028 | + sqlite3rbu *p, |
| 157827 | 158029 | const char *zTab, |
| 157828 | 158030 | int *peType, |
| 157829 | 158031 | int *piTnum, |
| 157830 | 158032 | int *piPk |
| 157831 | 158033 | ){ |
| | @@ -157835,11 +158037,11 @@ |
| 157835 | 158037 | ** 2) SELECT count(*) FROM sqlite_master where name=%Q |
| 157836 | 158038 | ** 3) PRAGMA table_info = ? |
| 157837 | 158039 | */ |
| 157838 | 158040 | sqlite3_stmt *aStmt[4] = {0, 0, 0, 0}; |
| 157839 | 158041 | |
| 157840 | | - *peType = OTA_PK_NOTABLE; |
| 158042 | + *peType = RBU_PK_NOTABLE; |
| 157841 | 158043 | *piPk = 0; |
| 157842 | 158044 | |
| 157843 | 158045 | assert( p->rc==SQLITE_OK ); |
| 157844 | 158046 | p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg, |
| 157845 | 158047 | sqlite3_mprintf( |
| | @@ -157847,22 +158049,22 @@ |
| 157847 | 158049 | " FROM sqlite_master" |
| 157848 | 158050 | " WHERE name=%Q", zTab |
| 157849 | 158051 | )); |
| 157850 | 158052 | if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){ |
| 157851 | 158053 | /* Either an error, or no such table. */ |
| 157852 | | - goto otaTableType_end; |
| 158054 | + goto rbuTableType_end; |
| 157853 | 158055 | } |
| 157854 | 158056 | if( sqlite3_column_int(aStmt[0], 0) ){ |
| 157855 | | - *peType = OTA_PK_VTAB; /* virtual table */ |
| 157856 | | - goto otaTableType_end; |
| 158057 | + *peType = RBU_PK_VTAB; /* virtual table */ |
| 158058 | + goto rbuTableType_end; |
| 157857 | 158059 | } |
| 157858 | 158060 | *piTnum = sqlite3_column_int(aStmt[0], 1); |
| 157859 | 158061 | |
| 157860 | 158062 | p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[1], &p->zErrmsg, |
| 157861 | 158063 | sqlite3_mprintf("PRAGMA index_list=%Q",zTab) |
| 157862 | 158064 | ); |
| 157863 | | - if( p->rc ) goto otaTableType_end; |
| 158065 | + if( p->rc ) goto rbuTableType_end; |
| 157864 | 158066 | while( sqlite3_step(aStmt[1])==SQLITE_ROW ){ |
| 157865 | 158067 | const u8 *zOrig = sqlite3_column_text(aStmt[1], 3); |
| 157866 | 158068 | const u8 *zIdx = sqlite3_column_text(aStmt[1], 1); |
| 157867 | 158069 | if( zOrig && zIdx && zOrig[0]=='p' ){ |
| 157868 | 158070 | p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[2], &p->zErrmsg, |
| | @@ -157870,45 +158072,45 @@ |
| 157870 | 158072 | "SELECT rootpage FROM sqlite_master WHERE name = %Q", zIdx |
| 157871 | 158073 | )); |
| 157872 | 158074 | if( p->rc==SQLITE_OK ){ |
| 157873 | 158075 | if( sqlite3_step(aStmt[2])==SQLITE_ROW ){ |
| 157874 | 158076 | *piPk = sqlite3_column_int(aStmt[2], 0); |
| 157875 | | - *peType = OTA_PK_EXTERNAL; |
| 158077 | + *peType = RBU_PK_EXTERNAL; |
| 157876 | 158078 | }else{ |
| 157877 | | - *peType = OTA_PK_WITHOUT_ROWID; |
| 158079 | + *peType = RBU_PK_WITHOUT_ROWID; |
| 157878 | 158080 | } |
| 157879 | 158081 | } |
| 157880 | | - goto otaTableType_end; |
| 158082 | + goto rbuTableType_end; |
| 157881 | 158083 | } |
| 157882 | 158084 | } |
| 157883 | 158085 | |
| 157884 | 158086 | p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[3], &p->zErrmsg, |
| 157885 | 158087 | sqlite3_mprintf("PRAGMA table_info=%Q",zTab) |
| 157886 | 158088 | ); |
| 157887 | 158089 | if( p->rc==SQLITE_OK ){ |
| 157888 | 158090 | while( sqlite3_step(aStmt[3])==SQLITE_ROW ){ |
| 157889 | 158091 | if( sqlite3_column_int(aStmt[3],5)>0 ){ |
| 157890 | | - *peType = OTA_PK_IPK; /* explicit IPK column */ |
| 157891 | | - goto otaTableType_end; |
| 158092 | + *peType = RBU_PK_IPK; /* explicit IPK column */ |
| 158093 | + goto rbuTableType_end; |
| 157892 | 158094 | } |
| 157893 | 158095 | } |
| 157894 | | - *peType = OTA_PK_NONE; |
| 158096 | + *peType = RBU_PK_NONE; |
| 157895 | 158097 | } |
| 157896 | 158098 | |
| 157897 | | -otaTableType_end: { |
| 158099 | +rbuTableType_end: { |
| 157898 | 158100 | int i; |
| 157899 | 158101 | for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){ |
| 157900 | | - otaFinalize(p, aStmt[i]); |
| 158102 | + rbuFinalize(p, aStmt[i]); |
| 157901 | 158103 | } |
| 157902 | 158104 | } |
| 157903 | 158105 | } |
| 157904 | 158106 | |
| 157905 | 158107 | /* |
| 157906 | | -** This is a helper function for otaObjIterCacheTableInfo(). It populates |
| 158108 | +** This is a helper function for rbuObjIterCacheTableInfo(). It populates |
| 157907 | 158109 | ** the pIter->abIndexed[] array. |
| 157908 | 158110 | */ |
| 157909 | | -static void otaObjIterCacheIndexedCols(sqlite3ota *p, OtaObjIter *pIter){ |
| 158111 | +static void rbuObjIterCacheIndexedCols(sqlite3rbu *p, RbuObjIter *pIter){ |
| 157910 | 158112 | sqlite3_stmt *pList = 0; |
| 157911 | 158113 | int bIndex = 0; |
| 157912 | 158114 | |
| 157913 | 158115 | if( p->rc==SQLITE_OK ){ |
| 157914 | 158116 | memcpy(pIter->abIndexed, pIter->abTblPk, sizeof(u8)*pIter->nTblCol); |
| | @@ -157926,15 +158128,15 @@ |
| 157926 | 158128 | ); |
| 157927 | 158129 | while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){ |
| 157928 | 158130 | int iCid = sqlite3_column_int(pXInfo, 1); |
| 157929 | 158131 | if( iCid>=0 ) pIter->abIndexed[iCid] = 1; |
| 157930 | 158132 | } |
| 157931 | | - otaFinalize(p, pXInfo); |
| 158133 | + rbuFinalize(p, pXInfo); |
| 157932 | 158134 | bIndex = 1; |
| 157933 | 158135 | } |
| 157934 | 158136 | |
| 157935 | | - otaFinalize(p, pList); |
| 158137 | + rbuFinalize(p, pList); |
| 157936 | 158138 | if( bIndex==0 ) pIter->abIndexed = 0; |
| 157937 | 158139 | } |
| 157938 | 158140 | |
| 157939 | 158141 | |
| 157940 | 158142 | /* |
| | @@ -157942,67 +158144,67 @@ |
| 157942 | 158144 | ** pIter->abTblPk[], pIter->nTblCol and pIter->bRowid variables according to |
| 157943 | 158145 | ** the table (not index) that the iterator currently points to. |
| 157944 | 158146 | ** |
| 157945 | 158147 | ** Return SQLITE_OK if successful, or an SQLite error code otherwise. If |
| 157946 | 158148 | ** an error does occur, an error code and error message are also left in |
| 157947 | | -** the OTA handle. |
| 158149 | +** the RBU handle. |
| 157948 | 158150 | */ |
| 157949 | | -static int otaObjIterCacheTableInfo(sqlite3ota *p, OtaObjIter *pIter){ |
| 158151 | +static int rbuObjIterCacheTableInfo(sqlite3rbu *p, RbuObjIter *pIter){ |
| 157950 | 158152 | if( pIter->azTblCol==0 ){ |
| 157951 | 158153 | sqlite3_stmt *pStmt = 0; |
| 157952 | 158154 | int nCol = 0; |
| 157953 | 158155 | int i; /* for() loop iterator variable */ |
| 157954 | | - int bOtaRowid = 0; /* If input table has column "ota_rowid" */ |
| 158156 | + int bRbuRowid = 0; /* If input table has column "rbu_rowid" */ |
| 157955 | 158157 | int iOrder = 0; |
| 157956 | 158158 | int iTnum = 0; |
| 157957 | 158159 | |
| 157958 | 158160 | /* Figure out the type of table this step will deal with. */ |
| 157959 | 158161 | assert( pIter->eType==0 ); |
| 157960 | | - otaTableType(p, pIter->zTbl, &pIter->eType, &iTnum, &pIter->iPkTnum); |
| 157961 | | - if( p->rc==SQLITE_OK && pIter->eType==OTA_PK_NOTABLE ){ |
| 158162 | + rbuTableType(p, pIter->zTbl, &pIter->eType, &iTnum, &pIter->iPkTnum); |
| 158163 | + if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_NOTABLE ){ |
| 157962 | 158164 | p->rc = SQLITE_ERROR; |
| 157963 | 158165 | p->zErrmsg = sqlite3_mprintf("no such table: %s", pIter->zTbl); |
| 157964 | 158166 | } |
| 157965 | 158167 | if( p->rc ) return p->rc; |
| 157966 | 158168 | if( pIter->zIdx==0 ) pIter->iTnum = iTnum; |
| 157967 | 158169 | |
| 157968 | | - assert( pIter->eType==OTA_PK_NONE || pIter->eType==OTA_PK_IPK |
| 157969 | | - || pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_WITHOUT_ROWID |
| 157970 | | - || pIter->eType==OTA_PK_VTAB |
| 158170 | + assert( pIter->eType==RBU_PK_NONE || pIter->eType==RBU_PK_IPK |
| 158171 | + || pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_WITHOUT_ROWID |
| 158172 | + || pIter->eType==RBU_PK_VTAB |
| 157971 | 158173 | ); |
| 157972 | 158174 | |
| 157973 | 158175 | /* Populate the azTblCol[] and nTblCol variables based on the columns |
| 157974 | 158176 | ** of the input table. Ignore any input table columns that begin with |
| 157975 | | - ** "ota_". */ |
| 157976 | | - p->rc = prepareFreeAndCollectError(p->dbOta, &pStmt, &p->zErrmsg, |
| 158177 | + ** "rbu_". */ |
| 158178 | + p->rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg, |
| 157977 | 158179 | sqlite3_mprintf("SELECT * FROM 'data_%q'", pIter->zTbl) |
| 157978 | 158180 | ); |
| 157979 | 158181 | if( p->rc==SQLITE_OK ){ |
| 157980 | 158182 | nCol = sqlite3_column_count(pStmt); |
| 157981 | | - otaAllocateIterArrays(p, pIter, nCol); |
| 158183 | + rbuAllocateIterArrays(p, pIter, nCol); |
| 157982 | 158184 | } |
| 157983 | 158185 | for(i=0; p->rc==SQLITE_OK && i<nCol; i++){ |
| 157984 | 158186 | const char *zName = (const char*)sqlite3_column_name(pStmt, i); |
| 157985 | | - if( sqlite3_strnicmp("ota_", zName, 4) ){ |
| 157986 | | - char *zCopy = otaStrndup(zName, &p->rc); |
| 158187 | + if( sqlite3_strnicmp("rbu_", zName, 4) ){ |
| 158188 | + char *zCopy = rbuStrndup(zName, &p->rc); |
| 157987 | 158189 | pIter->aiSrcOrder[pIter->nTblCol] = pIter->nTblCol; |
| 157988 | 158190 | pIter->azTblCol[pIter->nTblCol++] = zCopy; |
| 157989 | 158191 | } |
| 157990 | | - else if( 0==sqlite3_stricmp("ota_rowid", zName) ){ |
| 157991 | | - bOtaRowid = 1; |
| 158192 | + else if( 0==sqlite3_stricmp("rbu_rowid", zName) ){ |
| 158193 | + bRbuRowid = 1; |
| 157992 | 158194 | } |
| 157993 | 158195 | } |
| 157994 | 158196 | sqlite3_finalize(pStmt); |
| 157995 | 158197 | pStmt = 0; |
| 157996 | 158198 | |
| 157997 | 158199 | if( p->rc==SQLITE_OK |
| 157998 | | - && bOtaRowid!=(pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE) |
| 158200 | + && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) |
| 157999 | 158201 | ){ |
| 158000 | 158202 | p->rc = SQLITE_ERROR; |
| 158001 | 158203 | p->zErrmsg = sqlite3_mprintf( |
| 158002 | | - "table data_%q %s ota_rowid column", pIter->zTbl, |
| 158003 | | - (bOtaRowid ? "may not have" : "requires") |
| 158204 | + "table data_%q %s rbu_rowid column", pIter->zTbl, |
| 158205 | + (bRbuRowid ? "may not have" : "requires") |
| 158004 | 158206 | ); |
| 158005 | 158207 | } |
| 158006 | 158208 | |
| 158007 | 158209 | /* Check that all non-HIDDEN columns in the destination table are also |
| 158008 | 158210 | ** present in the input table. Populate the abTblPk[], azTblType[] and |
| | @@ -158031,20 +158233,20 @@ |
| 158031 | 158233 | if( i!=iOrder ){ |
| 158032 | 158234 | SWAP(int, pIter->aiSrcOrder[i], pIter->aiSrcOrder[iOrder]); |
| 158033 | 158235 | SWAP(char*, pIter->azTblCol[i], pIter->azTblCol[iOrder]); |
| 158034 | 158236 | } |
| 158035 | 158237 | |
| 158036 | | - pIter->azTblType[iOrder] = otaStrndup(zType, &p->rc); |
| 158238 | + pIter->azTblType[iOrder] = rbuStrndup(zType, &p->rc); |
| 158037 | 158239 | pIter->abTblPk[iOrder] = (iPk!=0); |
| 158038 | 158240 | pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0); |
| 158039 | 158241 | iOrder++; |
| 158040 | 158242 | } |
| 158041 | 158243 | } |
| 158042 | 158244 | |
| 158043 | | - otaFinalize(p, pStmt); |
| 158044 | | - otaObjIterCacheIndexedCols(p, pIter); |
| 158045 | | - assert( pIter->eType!=OTA_PK_VTAB || pIter->abIndexed==0 ); |
| 158245 | + rbuFinalize(p, pStmt); |
| 158246 | + rbuObjIterCacheIndexedCols(p, pIter); |
| 158247 | + assert( pIter->eType!=RBU_PK_VTAB || pIter->abIndexed==0 ); |
| 158046 | 158248 | } |
| 158047 | 158249 | |
| 158048 | 158250 | return p->rc; |
| 158049 | 158251 | } |
| 158050 | 158252 | |
| | @@ -158051,29 +158253,29 @@ |
| 158051 | 158253 | /* |
| 158052 | 158254 | ** This function constructs and returns a pointer to a nul-terminated |
| 158053 | 158255 | ** string containing some SQL clause or list based on one or more of the |
| 158054 | 158256 | ** column names currently stored in the pIter->azTblCol[] array. |
| 158055 | 158257 | */ |
| 158056 | | -static char *otaObjIterGetCollist( |
| 158057 | | - sqlite3ota *p, /* OTA object */ |
| 158058 | | - OtaObjIter *pIter /* Object iterator for column names */ |
| 158258 | +static char *rbuObjIterGetCollist( |
| 158259 | + sqlite3rbu *p, /* RBU object */ |
| 158260 | + RbuObjIter *pIter /* Object iterator for column names */ |
| 158059 | 158261 | ){ |
| 158060 | 158262 | char *zList = 0; |
| 158061 | 158263 | const char *zSep = ""; |
| 158062 | 158264 | int i; |
| 158063 | 158265 | for(i=0; i<pIter->nTblCol; i++){ |
| 158064 | 158266 | const char *z = pIter->azTblCol[i]; |
| 158065 | | - zList = otaMPrintf(p, "%z%s\"%w\"", zList, zSep, z); |
| 158267 | + zList = rbuMPrintf(p, "%z%s\"%w\"", zList, zSep, z); |
| 158066 | 158268 | zSep = ", "; |
| 158067 | 158269 | } |
| 158068 | 158270 | return zList; |
| 158069 | 158271 | } |
| 158070 | 158272 | |
| 158071 | 158273 | /* |
| 158072 | 158274 | ** This function is used to create a SELECT list (the list of SQL |
| 158073 | 158275 | ** expressions that follows a SELECT keyword) for a SELECT statement |
| 158074 | | -** used to read from an data_xxx or ota_tmp_xxx table while updating the |
| 158276 | +** used to read from an data_xxx or rbu_tmp_xxx table while updating the |
| 158075 | 158277 | ** index object currently indicated by the iterator object passed as the |
| 158076 | 158278 | ** second argument. A "PRAGMA index_xinfo = <idxname>" statement is used |
| 158077 | 158279 | ** to obtain the required information. |
| 158078 | 158280 | ** |
| 158079 | 158281 | ** If the index is of the following form: |
| | @@ -158090,17 +158292,17 @@ |
| 158090 | 158292 | ** |
| 158091 | 158293 | ** pzImposterCols: ... |
| 158092 | 158294 | ** pzImposterPk: ... |
| 158093 | 158295 | ** pzWhere: ... |
| 158094 | 158296 | */ |
| 158095 | | -static char *otaObjIterGetIndexCols( |
| 158096 | | - sqlite3ota *p, /* OTA object */ |
| 158097 | | - OtaObjIter *pIter, /* Object iterator for column names */ |
| 158297 | +static char *rbuObjIterGetIndexCols( |
| 158298 | + sqlite3rbu *p, /* RBU object */ |
| 158299 | + RbuObjIter *pIter, /* Object iterator for column names */ |
| 158098 | 158300 | char **pzImposterCols, /* OUT: Columns for imposter table */ |
| 158099 | 158301 | char **pzImposterPk, /* OUT: Imposter PK clause */ |
| 158100 | 158302 | char **pzWhere, /* OUT: WHERE clause */ |
| 158101 | | - int *pnBind /* OUT: Total number of columns */ |
| 158303 | + int *pnBind /* OUT: Trbul number of columns */ |
| 158102 | 158304 | ){ |
| 158103 | 158305 | int rc = p->rc; /* Error code */ |
| 158104 | 158306 | int rc2; /* sqlite3_finalize() return code */ |
| 158105 | 158307 | char *zRet = 0; /* String to return */ |
| 158106 | 158308 | char *zImpCols = 0; /* String to return via *pzImposterCols */ |
| | @@ -158125,18 +158327,18 @@ |
| 158125 | 158327 | const char *zCol; |
| 158126 | 158328 | const char *zType; |
| 158127 | 158329 | |
| 158128 | 158330 | if( iCid<0 ){ |
| 158129 | 158331 | /* An integer primary key. If the table has an explicit IPK, use |
| 158130 | | - ** its name. Otherwise, use "ota_rowid". */ |
| 158131 | | - if( pIter->eType==OTA_PK_IPK ){ |
| 158332 | + ** its name. Otherwise, use "rbu_rowid". */ |
| 158333 | + if( pIter->eType==RBU_PK_IPK ){ |
| 158132 | 158334 | int i; |
| 158133 | 158335 | for(i=0; pIter->abTblPk[i]==0; i++); |
| 158134 | 158336 | assert( i<pIter->nTblCol ); |
| 158135 | 158337 | zCol = pIter->azTblCol[i]; |
| 158136 | 158338 | }else{ |
| 158137 | | - zCol = "ota_rowid"; |
| 158339 | + zCol = "rbu_rowid"; |
| 158138 | 158340 | } |
| 158139 | 158341 | zType = "INTEGER"; |
| 158140 | 158342 | }else{ |
| 158141 | 158343 | zCol = pIter->azTblCol[iCid]; |
| 158142 | 158344 | zType = pIter->azTblType[iCid]; |
| | @@ -158143,19 +158345,19 @@ |
| 158143 | 158345 | } |
| 158144 | 158346 | |
| 158145 | 158347 | zRet = sqlite3_mprintf("%z%s\"%w\" COLLATE %Q", zRet, zCom, zCol, zCollate); |
| 158146 | 158348 | if( pIter->bUnique==0 || sqlite3_column_int(pXInfo, 5) ){ |
| 158147 | 158349 | const char *zOrder = (bDesc ? " DESC" : ""); |
| 158148 | | - zImpPK = sqlite3_mprintf("%z%s\"ota_imp_%d%w\"%s", |
| 158350 | + zImpPK = sqlite3_mprintf("%z%s\"rbu_imp_%d%w\"%s", |
| 158149 | 158351 | zImpPK, zCom, nBind, zCol, zOrder |
| 158150 | 158352 | ); |
| 158151 | 158353 | } |
| 158152 | | - zImpCols = sqlite3_mprintf("%z%s\"ota_imp_%d%w\" %s COLLATE %Q", |
| 158354 | + zImpCols = sqlite3_mprintf("%z%s\"rbu_imp_%d%w\" %s COLLATE %Q", |
| 158153 | 158355 | zImpCols, zCom, nBind, zCol, zType, zCollate |
| 158154 | 158356 | ); |
| 158155 | 158357 | zWhere = sqlite3_mprintf( |
| 158156 | | - "%z%s\"ota_imp_%d%w\" IS ?", zWhere, zAnd, nBind, zCol |
| 158358 | + "%z%s\"rbu_imp_%d%w\" IS ?", zWhere, zAnd, nBind, zCol |
| 158157 | 158359 | ); |
| 158158 | 158360 | if( zRet==0 || zImpPK==0 || zImpCols==0 || zWhere==0 ) rc = SQLITE_NOMEM; |
| 158159 | 158361 | zCom = ", "; |
| 158160 | 158362 | zAnd = " AND "; |
| 158161 | 158363 | nBind++; |
| | @@ -158189,16 +158391,16 @@ |
| 158189 | 158391 | ** |
| 158190 | 158392 | ** "old.a, old.b, old.b" |
| 158191 | 158393 | ** |
| 158192 | 158394 | ** With the column names escaped. |
| 158193 | 158395 | ** |
| 158194 | | -** For tables with implicit rowids - OTA_PK_EXTERNAL and OTA_PK_NONE, append |
| 158396 | +** For tables with implicit rowids - RBU_PK_EXTERNAL and RBU_PK_NONE, append |
| 158195 | 158397 | ** the text ", old._rowid_" to the returned value. |
| 158196 | 158398 | */ |
| 158197 | | -static char *otaObjIterGetOldlist( |
| 158198 | | - sqlite3ota *p, |
| 158199 | | - OtaObjIter *pIter, |
| 158399 | +static char *rbuObjIterGetOldlist( |
| 158400 | + sqlite3rbu *p, |
| 158401 | + RbuObjIter *pIter, |
| 158200 | 158402 | const char *zObj |
| 158201 | 158403 | ){ |
| 158202 | 158404 | char *zList = 0; |
| 158203 | 158405 | if( p->rc==SQLITE_OK && pIter->abIndexed ){ |
| 158204 | 158406 | const char *zS = ""; |
| | @@ -158216,12 +158418,12 @@ |
| 158216 | 158418 | break; |
| 158217 | 158419 | } |
| 158218 | 158420 | } |
| 158219 | 158421 | |
| 158220 | 158422 | /* For a table with implicit rowids, append "old._rowid_" to the list. */ |
| 158221 | | - if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){ |
| 158222 | | - zList = otaMPrintf(p, "%z, %s._rowid_", zList, zObj); |
| 158423 | + if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ |
| 158424 | + zList = rbuMPrintf(p, "%z, %s._rowid_", zList, zObj); |
| 158223 | 158425 | } |
| 158224 | 158426 | } |
| 158225 | 158427 | return zList; |
| 158226 | 158428 | } |
| 158227 | 158429 | |
| | @@ -158233,37 +158435,37 @@ |
| 158233 | 158435 | ** |
| 158234 | 158436 | ** Return the string: |
| 158235 | 158437 | ** |
| 158236 | 158438 | ** "b = ?1 AND c = ?2" |
| 158237 | 158439 | */ |
| 158238 | | -static char *otaObjIterGetWhere( |
| 158239 | | - sqlite3ota *p, |
| 158240 | | - OtaObjIter *pIter |
| 158440 | +static char *rbuObjIterGetWhere( |
| 158441 | + sqlite3rbu *p, |
| 158442 | + RbuObjIter *pIter |
| 158241 | 158443 | ){ |
| 158242 | 158444 | char *zList = 0; |
| 158243 | | - if( pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE ){ |
| 158244 | | - zList = otaMPrintf(p, "_rowid_ = ?%d", pIter->nTblCol+1); |
| 158245 | | - }else if( pIter->eType==OTA_PK_EXTERNAL ){ |
| 158445 | + if( pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE ){ |
| 158446 | + zList = rbuMPrintf(p, "_rowid_ = ?%d", pIter->nTblCol+1); |
| 158447 | + }else if( pIter->eType==RBU_PK_EXTERNAL ){ |
| 158246 | 158448 | const char *zSep = ""; |
| 158247 | 158449 | int i; |
| 158248 | 158450 | for(i=0; i<pIter->nTblCol; i++){ |
| 158249 | 158451 | if( pIter->abTblPk[i] ){ |
| 158250 | | - zList = otaMPrintf(p, "%z%sc%d=?%d", zList, zSep, i, i+1); |
| 158452 | + zList = rbuMPrintf(p, "%z%sc%d=?%d", zList, zSep, i, i+1); |
| 158251 | 158453 | zSep = " AND "; |
| 158252 | 158454 | } |
| 158253 | 158455 | } |
| 158254 | | - zList = otaMPrintf(p, |
| 158255 | | - "_rowid_ = (SELECT id FROM ota_imposter2 WHERE %z)", zList |
| 158456 | + zList = rbuMPrintf(p, |
| 158457 | + "_rowid_ = (SELECT id FROM rbu_imposter2 WHERE %z)", zList |
| 158256 | 158458 | ); |
| 158257 | 158459 | |
| 158258 | 158460 | }else{ |
| 158259 | 158461 | const char *zSep = ""; |
| 158260 | 158462 | int i; |
| 158261 | 158463 | for(i=0; i<pIter->nTblCol; i++){ |
| 158262 | 158464 | if( pIter->abTblPk[i] ){ |
| 158263 | 158465 | const char *zCol = pIter->azTblCol[i]; |
| 158264 | | - zList = otaMPrintf(p, "%z%s\"%w\"=?%d", zList, zSep, zCol, i+1); |
| 158466 | + zList = rbuMPrintf(p, "%z%s\"%w\"=?%d", zList, zSep, zCol, i+1); |
| 158265 | 158467 | zSep = " AND "; |
| 158266 | 158468 | } |
| 158267 | 158469 | } |
| 158268 | 158470 | } |
| 158269 | 158471 | return zList; |
| | @@ -158270,60 +158472,60 @@ |
| 158270 | 158472 | } |
| 158271 | 158473 | |
| 158272 | 158474 | /* |
| 158273 | 158475 | ** The SELECT statement iterating through the keys for the current object |
| 158274 | 158476 | ** (p->objiter.pSelect) currently points to a valid row. However, there |
| 158275 | | -** is something wrong with the ota_control value in the ota_control value |
| 158477 | +** is something wrong with the rbu_control value in the rbu_control value |
| 158276 | 158478 | ** stored in the (p->nCol+1)'th column. Set the error code and error message |
| 158277 | | -** of the OTA handle to something reflecting this. |
| 158479 | +** of the RBU handle to something reflecting this. |
| 158278 | 158480 | */ |
| 158279 | | -static void otaBadControlError(sqlite3ota *p){ |
| 158481 | +static void rbuBadControlError(sqlite3rbu *p){ |
| 158280 | 158482 | p->rc = SQLITE_ERROR; |
| 158281 | | - p->zErrmsg = sqlite3_mprintf("invalid ota_control value"); |
| 158483 | + p->zErrmsg = sqlite3_mprintf("invalid rbu_control value"); |
| 158282 | 158484 | } |
| 158283 | 158485 | |
| 158284 | 158486 | |
| 158285 | 158487 | /* |
| 158286 | 158488 | ** Return a nul-terminated string containing the comma separated list of |
| 158287 | 158489 | ** assignments that should be included following the "SET" keyword of |
| 158288 | 158490 | ** an UPDATE statement used to update the table object that the iterator |
| 158289 | | -** passed as the second argument currently points to if the ota_control |
| 158491 | +** passed as the second argument currently points to if the rbu_control |
| 158290 | 158492 | ** column of the data_xxx table entry is set to zMask. |
| 158291 | 158493 | ** |
| 158292 | 158494 | ** The memory for the returned string is obtained from sqlite3_malloc(). |
| 158293 | 158495 | ** It is the responsibility of the caller to eventually free it using |
| 158294 | 158496 | ** sqlite3_free(). |
| 158295 | 158497 | ** |
| 158296 | 158498 | ** If an OOM error is encountered when allocating space for the new |
| 158297 | | -** string, an error code is left in the ota handle passed as the first |
| 158499 | +** string, an error code is left in the rbu handle passed as the first |
| 158298 | 158500 | ** argument and NULL is returned. Or, if an error has already occurred |
| 158299 | 158501 | ** when this function is called, NULL is returned immediately, without |
| 158300 | 158502 | ** attempting the allocation or modifying the stored error code. |
| 158301 | 158503 | */ |
| 158302 | | -static char *otaObjIterGetSetlist( |
| 158303 | | - sqlite3ota *p, |
| 158304 | | - OtaObjIter *pIter, |
| 158504 | +static char *rbuObjIterGetSetlist( |
| 158505 | + sqlite3rbu *p, |
| 158506 | + RbuObjIter *pIter, |
| 158305 | 158507 | const char *zMask |
| 158306 | 158508 | ){ |
| 158307 | 158509 | char *zList = 0; |
| 158308 | 158510 | if( p->rc==SQLITE_OK ){ |
| 158309 | 158511 | int i; |
| 158310 | 158512 | |
| 158311 | 158513 | if( strlen(zMask)!=pIter->nTblCol ){ |
| 158312 | | - otaBadControlError(p); |
| 158514 | + rbuBadControlError(p); |
| 158313 | 158515 | }else{ |
| 158314 | 158516 | const char *zSep = ""; |
| 158315 | 158517 | for(i=0; i<pIter->nTblCol; i++){ |
| 158316 | 158518 | char c = zMask[pIter->aiSrcOrder[i]]; |
| 158317 | 158519 | if( c=='x' ){ |
| 158318 | | - zList = otaMPrintf(p, "%z%s\"%w\"=?%d", |
| 158520 | + zList = rbuMPrintf(p, "%z%s\"%w\"=?%d", |
| 158319 | 158521 | zList, zSep, pIter->azTblCol[i], i+1 |
| 158320 | 158522 | ); |
| 158321 | 158523 | zSep = ", "; |
| 158322 | 158524 | } |
| 158323 | 158525 | if( c=='d' ){ |
| 158324 | | - zList = otaMPrintf(p, "%z%s\"%w\"=ota_delta(\"%w\", ?%d)", |
| 158526 | + zList = rbuMPrintf(p, "%z%s\"%w\"=rbu_delta(\"%w\", ?%d)", |
| 158325 | 158527 | zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1 |
| 158326 | 158528 | ); |
| 158327 | 158529 | zSep = ", "; |
| 158328 | 158530 | } |
| 158329 | 158531 | } |
| | @@ -158340,20 +158542,20 @@ |
| 158340 | 158542 | ** The memory for the returned string is obtained from sqlite3_malloc(). |
| 158341 | 158543 | ** It is the responsibility of the caller to eventually free it using |
| 158342 | 158544 | ** sqlite3_free(). |
| 158343 | 158545 | ** |
| 158344 | 158546 | ** If an OOM error is encountered when allocating space for the new |
| 158345 | | -** string, an error code is left in the ota handle passed as the first |
| 158547 | +** string, an error code is left in the rbu handle passed as the first |
| 158346 | 158548 | ** argument and NULL is returned. Or, if an error has already occurred |
| 158347 | 158549 | ** when this function is called, NULL is returned immediately, without |
| 158348 | 158550 | ** attempting the allocation or modifying the stored error code. |
| 158349 | 158551 | */ |
| 158350 | | -static char *otaObjIterGetBindlist(sqlite3ota *p, int nBind){ |
| 158552 | +static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){ |
| 158351 | 158553 | char *zRet = 0; |
| 158352 | 158554 | int nByte = nBind*2 + 1; |
| 158353 | 158555 | |
| 158354 | | - zRet = (char*)otaMalloc(p, nByte); |
| 158556 | + zRet = (char*)rbuMalloc(p, nByte); |
| 158355 | 158557 | if( zRet ){ |
| 158356 | 158558 | int i; |
| 158357 | 158559 | for(i=0; i<nBind; i++){ |
| 158358 | 158560 | zRet[i*2] = '?'; |
| 158359 | 158561 | zRet[i*2+1] = (i+1==nBind) ? '\0' : ','; |
| | @@ -158362,21 +158564,21 @@ |
| 158362 | 158564 | return zRet; |
| 158363 | 158565 | } |
| 158364 | 158566 | |
| 158365 | 158567 | /* |
| 158366 | 158568 | ** The iterator currently points to a table (not index) of type |
| 158367 | | -** OTA_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY |
| 158569 | +** RBU_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY |
| 158368 | 158570 | ** declaration for the corresponding imposter table. For example, |
| 158369 | 158571 | ** if the iterator points to a table created as: |
| 158370 | 158572 | ** |
| 158371 | 158573 | ** CREATE TABLE t1(a, b, c, PRIMARY KEY(b, a DESC)) WITHOUT ROWID |
| 158372 | 158574 | ** |
| 158373 | 158575 | ** this function returns: |
| 158374 | 158576 | ** |
| 158375 | 158577 | ** PRIMARY KEY("b", "a" DESC) |
| 158376 | 158578 | */ |
| 158377 | | -static char *otaWithoutRowidPK(sqlite3ota *p, OtaObjIter *pIter){ |
| 158579 | +static char *rbuWithoutRowidPK(sqlite3rbu *p, RbuObjIter *pIter){ |
| 158378 | 158580 | char *z = 0; |
| 158379 | 158581 | assert( pIter->zIdx==0 ); |
| 158380 | 158582 | if( p->rc==SQLITE_OK ){ |
| 158381 | 158583 | const char *zSep = "PRIMARY KEY("; |
| 158382 | 158584 | sqlite3_stmt *pXList = 0; /* PRAGMA index_list = (pIter->zTbl) */ |
| | @@ -158395,23 +158597,23 @@ |
| 158395 | 158597 | ); |
| 158396 | 158598 | } |
| 158397 | 158599 | break; |
| 158398 | 158600 | } |
| 158399 | 158601 | } |
| 158400 | | - otaFinalize(p, pXList); |
| 158602 | + rbuFinalize(p, pXList); |
| 158401 | 158603 | |
| 158402 | 158604 | while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){ |
| 158403 | 158605 | if( sqlite3_column_int(pXInfo, 5) ){ |
| 158404 | 158606 | /* int iCid = sqlite3_column_int(pXInfo, 0); */ |
| 158405 | 158607 | const char *zCol = (const char*)sqlite3_column_text(pXInfo, 2); |
| 158406 | 158608 | const char *zDesc = sqlite3_column_int(pXInfo, 3) ? " DESC" : ""; |
| 158407 | | - z = otaMPrintf(p, "%z%s\"%w\"%s", z, zSep, zCol, zDesc); |
| 158609 | + z = rbuMPrintf(p, "%z%s\"%w\"%s", z, zSep, zCol, zDesc); |
| 158408 | 158610 | zSep = ", "; |
| 158409 | 158611 | } |
| 158410 | 158612 | } |
| 158411 | | - z = otaMPrintf(p, "%z)", z); |
| 158412 | | - otaFinalize(p, pXInfo); |
| 158613 | + z = rbuMPrintf(p, "%z)", z); |
| 158614 | + rbuFinalize(p, pXInfo); |
| 158413 | 158615 | } |
| 158414 | 158616 | return z; |
| 158415 | 158617 | } |
| 158416 | 158618 | |
| 158417 | 158619 | /* |
| | @@ -158420,23 +158622,23 @@ |
| 158420 | 158622 | ** iterator passed as the second argument does not currently point to |
| 158421 | 158623 | ** a table (not index) with an external primary key, this function is a |
| 158422 | 158624 | ** no-op. |
| 158423 | 158625 | ** |
| 158424 | 158626 | ** Assuming the iterator does point to a table with an external PK, this |
| 158425 | | -** function creates a WITHOUT ROWID imposter table named "ota_imposter2" |
| 158627 | +** function creates a WITHOUT ROWID imposter table named "rbu_imposter2" |
| 158426 | 158628 | ** used to access that PK index. For example, if the target table is |
| 158427 | 158629 | ** declared as follows: |
| 158428 | 158630 | ** |
| 158429 | 158631 | ** CREATE TABLE t1(a, b TEXT, c REAL, PRIMARY KEY(b, c)); |
| 158430 | 158632 | ** |
| 158431 | 158633 | ** then the imposter table schema is: |
| 158432 | 158634 | ** |
| 158433 | | -** CREATE TABLE ota_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID; |
| 158635 | +** CREATE TABLE rbu_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID; |
| 158434 | 158636 | ** |
| 158435 | 158637 | */ |
| 158436 | | -static void otaCreateImposterTable2(sqlite3ota *p, OtaObjIter *pIter){ |
| 158437 | | - if( p->rc==SQLITE_OK && pIter->eType==OTA_PK_EXTERNAL ){ |
| 158638 | +static void rbuCreateImposterTable2(sqlite3rbu *p, RbuObjIter *pIter){ |
| 158639 | + if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_EXTERNAL ){ |
| 158438 | 158640 | int tnum = pIter->iPkTnum; /* Root page of PK index */ |
| 158439 | 158641 | sqlite3_stmt *pQuery = 0; /* SELECT name ... WHERE rootpage = $tnum */ |
| 158440 | 158642 | const char *zIdx = 0; /* Name of PK index */ |
| 158441 | 158643 | sqlite3_stmt *pXInfo = 0; /* PRAGMA main.index_xinfo = $zIdx */ |
| 158442 | 158644 | const char *zComma = ""; |
| | @@ -158458,31 +158660,31 @@ |
| 158458 | 158660 | if( zIdx ){ |
| 158459 | 158661 | p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg, |
| 158460 | 158662 | sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx) |
| 158461 | 158663 | ); |
| 158462 | 158664 | } |
| 158463 | | - otaFinalize(p, pQuery); |
| 158665 | + rbuFinalize(p, pQuery); |
| 158464 | 158666 | |
| 158465 | 158667 | while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){ |
| 158466 | 158668 | int bKey = sqlite3_column_int(pXInfo, 5); |
| 158467 | 158669 | if( bKey ){ |
| 158468 | 158670 | int iCid = sqlite3_column_int(pXInfo, 1); |
| 158469 | 158671 | int bDesc = sqlite3_column_int(pXInfo, 3); |
| 158470 | 158672 | const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4); |
| 158471 | | - zCols = otaMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma, |
| 158673 | + zCols = rbuMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma, |
| 158472 | 158674 | iCid, pIter->azTblType[iCid], zCollate |
| 158473 | 158675 | ); |
| 158474 | | - zPk = otaMPrintf(p, "%z%sc%d%s", zPk, zComma, iCid, bDesc?" DESC":""); |
| 158676 | + zPk = rbuMPrintf(p, "%z%sc%d%s", zPk, zComma, iCid, bDesc?" DESC":""); |
| 158475 | 158677 | zComma = ", "; |
| 158476 | 158678 | } |
| 158477 | 158679 | } |
| 158478 | | - zCols = otaMPrintf(p, "%z, id INTEGER", zCols); |
| 158479 | | - otaFinalize(p, pXInfo); |
| 158680 | + zCols = rbuMPrintf(p, "%z, id INTEGER", zCols); |
| 158681 | + rbuFinalize(p, pXInfo); |
| 158480 | 158682 | |
| 158481 | 158683 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1, tnum); |
| 158482 | | - otaMPrintfExec(p, p->dbMain, |
| 158483 | | - "CREATE TABLE ota_imposter2(%z, PRIMARY KEY(%z)) WITHOUT ROWID", |
| 158684 | + rbuMPrintfExec(p, p->dbMain, |
| 158685 | + "CREATE TABLE rbu_imposter2(%z, PRIMARY KEY(%z)) WITHOUT ROWID", |
| 158484 | 158686 | zCols, zPk |
| 158485 | 158687 | ); |
| 158486 | 158688 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0); |
| 158487 | 158689 | } |
| 158488 | 158690 | } |
| | @@ -158489,28 +158691,28 @@ |
| 158489 | 158691 | |
| 158490 | 158692 | /* |
| 158491 | 158693 | ** If an error has already occurred when this function is called, it |
| 158492 | 158694 | ** immediately returns zero (without doing any work). Or, if an error |
| 158493 | 158695 | ** occurs during the execution of this function, it sets the error code |
| 158494 | | -** in the sqlite3ota object indicated by the first argument and returns |
| 158696 | +** in the sqlite3rbu object indicated by the first argument and returns |
| 158495 | 158697 | ** zero. |
| 158496 | 158698 | ** |
| 158497 | 158699 | ** The iterator passed as the second argument is guaranteed to point to |
| 158498 | 158700 | ** a table (not an index) when this function is called. This function |
| 158499 | 158701 | ** attempts to create any imposter table required to write to the main |
| 158500 | 158702 | ** table b-tree of the table before returning. Non-zero is returned if |
| 158501 | 158703 | ** an imposter table are created, or zero otherwise. |
| 158502 | 158704 | ** |
| 158503 | | -** An imposter table is required in all cases except OTA_PK_VTAB. Only |
| 158705 | +** An imposter table is required in all cases except RBU_PK_VTAB. Only |
| 158504 | 158706 | ** virtual tables are written to directly. The imposter table has the |
| 158505 | 158707 | ** same schema as the actual target table (less any UNIQUE constraints). |
| 158506 | 158708 | ** More precisely, the "same schema" means the same columns, types, |
| 158507 | 158709 | ** collation sequences. For tables that do not have an external PRIMARY |
| 158508 | 158710 | ** KEY, it also means the same PRIMARY KEY declaration. |
| 158509 | 158711 | */ |
| 158510 | | -static void otaCreateImposterTable(sqlite3ota *p, OtaObjIter *pIter){ |
| 158511 | | - if( p->rc==SQLITE_OK && pIter->eType!=OTA_PK_VTAB ){ |
| 158712 | +static void rbuCreateImposterTable(sqlite3rbu *p, RbuObjIter *pIter){ |
| 158713 | + if( p->rc==SQLITE_OK && pIter->eType!=RBU_PK_VTAB ){ |
| 158512 | 158714 | int tnum = pIter->iTnum; |
| 158513 | 158715 | const char *zComma = ""; |
| 158514 | 158716 | char *zSql = 0; |
| 158515 | 158717 | int iCol; |
| 158516 | 158718 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1); |
| | @@ -158522,73 +158724,73 @@ |
| 158522 | 158724 | |
| 158523 | 158725 | p->rc = sqlite3_table_column_metadata( |
| 158524 | 158726 | p->dbMain, "main", pIter->zTbl, zCol, 0, &zColl, 0, 0, 0 |
| 158525 | 158727 | ); |
| 158526 | 158728 | |
| 158527 | | - if( pIter->eType==OTA_PK_IPK && pIter->abTblPk[iCol] ){ |
| 158729 | + if( pIter->eType==RBU_PK_IPK && pIter->abTblPk[iCol] ){ |
| 158528 | 158730 | /* If the target table column is an "INTEGER PRIMARY KEY", add |
| 158529 | 158731 | ** "PRIMARY KEY" to the imposter table column declaration. */ |
| 158530 | 158732 | zPk = "PRIMARY KEY "; |
| 158531 | 158733 | } |
| 158532 | | - zSql = otaMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s", |
| 158734 | + zSql = rbuMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s", |
| 158533 | 158735 | zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl, |
| 158534 | 158736 | (pIter->abNotNull[iCol] ? " NOT NULL" : "") |
| 158535 | 158737 | ); |
| 158536 | 158738 | zComma = ", "; |
| 158537 | 158739 | } |
| 158538 | 158740 | |
| 158539 | | - if( pIter->eType==OTA_PK_WITHOUT_ROWID ){ |
| 158540 | | - char *zPk = otaWithoutRowidPK(p, pIter); |
| 158741 | + if( pIter->eType==RBU_PK_WITHOUT_ROWID ){ |
| 158742 | + char *zPk = rbuWithoutRowidPK(p, pIter); |
| 158541 | 158743 | if( zPk ){ |
| 158542 | | - zSql = otaMPrintf(p, "%z, %z", zSql, zPk); |
| 158744 | + zSql = rbuMPrintf(p, "%z, %z", zSql, zPk); |
| 158543 | 158745 | } |
| 158544 | 158746 | } |
| 158545 | 158747 | |
| 158546 | 158748 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1, tnum); |
| 158547 | | - otaMPrintfExec(p, p->dbMain, "CREATE TABLE \"ota_imp_%w\"(%z)%s", |
| 158749 | + rbuMPrintfExec(p, p->dbMain, "CREATE TABLE \"rbu_imp_%w\"(%z)%s", |
| 158548 | 158750 | pIter->zTbl, zSql, |
| 158549 | | - (pIter->eType==OTA_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "") |
| 158751 | + (pIter->eType==RBU_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "") |
| 158550 | 158752 | ); |
| 158551 | 158753 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0); |
| 158552 | 158754 | } |
| 158553 | 158755 | } |
| 158554 | 158756 | |
| 158555 | 158757 | /* |
| 158556 | | -** Prepare a statement used to insert rows into the "ota_tmp_xxx" table. |
| 158758 | +** Prepare a statement used to insert rows into the "rbu_tmp_xxx" table. |
| 158557 | 158759 | ** Specifically a statement of the form: |
| 158558 | 158760 | ** |
| 158559 | | -** INSERT INTO ota_tmp_xxx VALUES(?, ?, ? ...); |
| 158761 | +** INSERT INTO rbu_tmp_xxx VALUES(?, ?, ? ...); |
| 158560 | 158762 | ** |
| 158561 | 158763 | ** The number of bound variables is equal to the number of columns in |
| 158562 | | -** the target table, plus one (for the ota_control column), plus one more |
| 158563 | | -** (for the ota_rowid column) if the target table is an implicit IPK or |
| 158764 | +** the target table, plus one (for the rbu_control column), plus one more |
| 158765 | +** (for the rbu_rowid column) if the target table is an implicit IPK or |
| 158564 | 158766 | ** virtual table. |
| 158565 | 158767 | */ |
| 158566 | | -static void otaObjIterPrepareTmpInsert( |
| 158567 | | - sqlite3ota *p, |
| 158568 | | - OtaObjIter *pIter, |
| 158768 | +static void rbuObjIterPrepareTmpInsert( |
| 158769 | + sqlite3rbu *p, |
| 158770 | + RbuObjIter *pIter, |
| 158569 | 158771 | const char *zCollist, |
| 158570 | | - const char *zOtaRowid |
| 158772 | + const char *zRbuRowid |
| 158571 | 158773 | ){ |
| 158572 | | - int bOtaRowid = (pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE); |
| 158573 | | - char *zBind = otaObjIterGetBindlist(p, pIter->nTblCol + 1 + bOtaRowid); |
| 158774 | + int bRbuRowid = (pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE); |
| 158775 | + char *zBind = rbuObjIterGetBindlist(p, pIter->nTblCol + 1 + bRbuRowid); |
| 158574 | 158776 | if( zBind ){ |
| 158575 | 158777 | assert( pIter->pTmpInsert==0 ); |
| 158576 | 158778 | p->rc = prepareFreeAndCollectError( |
| 158577 | | - p->dbOta, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf( |
| 158578 | | - "INSERT INTO %s.'ota_tmp_%q'(ota_control,%s%s) VALUES(%z)", |
| 158579 | | - p->zStateDb, pIter->zTbl, zCollist, zOtaRowid, zBind |
| 158779 | + p->dbRbu, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf( |
| 158780 | + "INSERT INTO %s.'rbu_tmp_%q'(rbu_control,%s%s) VALUES(%z)", |
| 158781 | + p->zStateDb, pIter->zTbl, zCollist, zRbuRowid, zBind |
| 158580 | 158782 | )); |
| 158581 | 158783 | } |
| 158582 | 158784 | } |
| 158583 | 158785 | |
| 158584 | | -static void otaTmpInsertFunc( |
| 158786 | +static void rbuTmpInsertFunc( |
| 158585 | 158787 | sqlite3_context *pCtx, |
| 158586 | 158788 | int nVal, |
| 158587 | 158789 | sqlite3_value **apVal |
| 158588 | 158790 | ){ |
| 158589 | | - sqlite3ota *p = sqlite3_user_data(pCtx); |
| 158791 | + sqlite3rbu *p = sqlite3_user_data(pCtx); |
| 158590 | 158792 | int rc = SQLITE_OK; |
| 158591 | 158793 | int i; |
| 158592 | 158794 | |
| 158593 | 158795 | for(i=0; rc==SQLITE_OK && i<nVal; i++){ |
| 158594 | 158796 | rc = sqlite3_bind_value(p->objiter.pTmpInsert, i+1, apVal[i]); |
| | @@ -158606,17 +158808,17 @@ |
| 158606 | 158808 | /* |
| 158607 | 158809 | ** Ensure that the SQLite statement handles required to update the |
| 158608 | 158810 | ** target database object currently indicated by the iterator passed |
| 158609 | 158811 | ** as the second argument are available. |
| 158610 | 158812 | */ |
| 158611 | | -static int otaObjIterPrepareAll( |
| 158612 | | - sqlite3ota *p, |
| 158613 | | - OtaObjIter *pIter, |
| 158813 | +static int rbuObjIterPrepareAll( |
| 158814 | + sqlite3rbu *p, |
| 158815 | + RbuObjIter *pIter, |
| 158614 | 158816 | int nOffset /* Add "LIMIT -1 OFFSET $nOffset" to SELECT */ |
| 158615 | 158817 | ){ |
| 158616 | 158818 | assert( pIter->bCleanup==0 ); |
| 158617 | | - if( pIter->pSelect==0 && otaObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){ |
| 158819 | + if( pIter->pSelect==0 && rbuObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){ |
| 158618 | 158820 | const int tnum = pIter->iTnum; |
| 158619 | 158821 | char *zCollist = 0; /* List of indexed columns */ |
| 158620 | 158822 | char **pz = &p->zErrmsg; |
| 158621 | 158823 | const char *zIdx = pIter->zIdx; |
| 158622 | 158824 | char *zLimit = 0; |
| | @@ -158632,104 +158834,104 @@ |
| 158632 | 158834 | char *zImposterPK = 0; /* Primary key declaration for imposter */ |
| 158633 | 158835 | char *zWhere = 0; /* WHERE clause on PK columns */ |
| 158634 | 158836 | char *zBind = 0; |
| 158635 | 158837 | int nBind = 0; |
| 158636 | 158838 | |
| 158637 | | - assert( pIter->eType!=OTA_PK_VTAB ); |
| 158638 | | - zCollist = otaObjIterGetIndexCols( |
| 158839 | + assert( pIter->eType!=RBU_PK_VTAB ); |
| 158840 | + zCollist = rbuObjIterGetIndexCols( |
| 158639 | 158841 | p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind |
| 158640 | 158842 | ); |
| 158641 | | - zBind = otaObjIterGetBindlist(p, nBind); |
| 158843 | + zBind = rbuObjIterGetBindlist(p, nBind); |
| 158642 | 158844 | |
| 158643 | 158845 | /* Create the imposter table used to write to this index. */ |
| 158644 | 158846 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1); |
| 158645 | 158847 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum); |
| 158646 | | - otaMPrintfExec(p, p->dbMain, |
| 158647 | | - "CREATE TABLE \"ota_imp_%w\"( %s, PRIMARY KEY( %s ) ) WITHOUT ROWID", |
| 158848 | + rbuMPrintfExec(p, p->dbMain, |
| 158849 | + "CREATE TABLE \"rbu_imp_%w\"( %s, PRIMARY KEY( %s ) ) WITHOUT ROWID", |
| 158648 | 158850 | zTbl, zImposterCols, zImposterPK |
| 158649 | 158851 | ); |
| 158650 | 158852 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0); |
| 158651 | 158853 | |
| 158652 | 158854 | /* Create the statement to insert index entries */ |
| 158653 | 158855 | pIter->nCol = nBind; |
| 158654 | 158856 | if( p->rc==SQLITE_OK ){ |
| 158655 | 158857 | p->rc = prepareFreeAndCollectError( |
| 158656 | 158858 | p->dbMain, &pIter->pInsert, &p->zErrmsg, |
| 158657 | | - sqlite3_mprintf("INSERT INTO \"ota_imp_%w\" VALUES(%s)", zTbl, zBind) |
| 158859 | + sqlite3_mprintf("INSERT INTO \"rbu_imp_%w\" VALUES(%s)", zTbl, zBind) |
| 158658 | 158860 | ); |
| 158659 | 158861 | } |
| 158660 | 158862 | |
| 158661 | 158863 | /* And to delete index entries */ |
| 158662 | 158864 | if( p->rc==SQLITE_OK ){ |
| 158663 | 158865 | p->rc = prepareFreeAndCollectError( |
| 158664 | 158866 | p->dbMain, &pIter->pDelete, &p->zErrmsg, |
| 158665 | | - sqlite3_mprintf("DELETE FROM \"ota_imp_%w\" WHERE %s", zTbl, zWhere) |
| 158867 | + sqlite3_mprintf("DELETE FROM \"rbu_imp_%w\" WHERE %s", zTbl, zWhere) |
| 158666 | 158868 | ); |
| 158667 | 158869 | } |
| 158668 | 158870 | |
| 158669 | 158871 | /* Create the SELECT statement to read keys in sorted order */ |
| 158670 | 158872 | if( p->rc==SQLITE_OK ){ |
| 158671 | 158873 | char *zSql; |
| 158672 | | - if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){ |
| 158874 | + if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ |
| 158673 | 158875 | zSql = sqlite3_mprintf( |
| 158674 | | - "SELECT %s, ota_control FROM %s.'ota_tmp_%q' ORDER BY %s%s", |
| 158876 | + "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s", |
| 158675 | 158877 | zCollist, p->zStateDb, pIter->zTbl, |
| 158676 | 158878 | zCollist, zLimit |
| 158677 | 158879 | ); |
| 158678 | 158880 | }else{ |
| 158679 | 158881 | zSql = sqlite3_mprintf( |
| 158680 | | - "SELECT %s, ota_control FROM 'data_%q' " |
| 158681 | | - "WHERE typeof(ota_control)='integer' AND ota_control!=1 " |
| 158882 | + "SELECT %s, rbu_control FROM 'data_%q' " |
| 158883 | + "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 " |
| 158682 | 158884 | "UNION ALL " |
| 158683 | | - "SELECT %s, ota_control FROM %s.'ota_tmp_%q' " |
| 158885 | + "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' " |
| 158684 | 158886 | "ORDER BY %s%s", |
| 158685 | 158887 | zCollist, pIter->zTbl, |
| 158686 | 158888 | zCollist, p->zStateDb, pIter->zTbl, |
| 158687 | 158889 | zCollist, zLimit |
| 158688 | 158890 | ); |
| 158689 | 158891 | } |
| 158690 | | - p->rc = prepareFreeAndCollectError(p->dbOta, &pIter->pSelect, pz, zSql); |
| 158892 | + p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql); |
| 158691 | 158893 | } |
| 158692 | 158894 | |
| 158693 | 158895 | sqlite3_free(zImposterCols); |
| 158694 | 158896 | sqlite3_free(zImposterPK); |
| 158695 | 158897 | sqlite3_free(zWhere); |
| 158696 | 158898 | sqlite3_free(zBind); |
| 158697 | 158899 | }else{ |
| 158698 | | - int bOtaRowid = (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE); |
| 158900 | + int bRbuRowid = (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE); |
| 158699 | 158901 | const char *zTbl = pIter->zTbl; /* Table this step applies to */ |
| 158700 | 158902 | const char *zWrite; /* Imposter table name */ |
| 158701 | 158903 | |
| 158702 | | - char *zBindings = otaObjIterGetBindlist(p, pIter->nTblCol + bOtaRowid); |
| 158703 | | - char *zWhere = otaObjIterGetWhere(p, pIter); |
| 158704 | | - char *zOldlist = otaObjIterGetOldlist(p, pIter, "old"); |
| 158705 | | - char *zNewlist = otaObjIterGetOldlist(p, pIter, "new"); |
| 158904 | + char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid); |
| 158905 | + char *zWhere = rbuObjIterGetWhere(p, pIter); |
| 158906 | + char *zOldlist = rbuObjIterGetOldlist(p, pIter, "old"); |
| 158907 | + char *zNewlist = rbuObjIterGetOldlist(p, pIter, "new"); |
| 158706 | 158908 | |
| 158707 | | - zCollist = otaObjIterGetCollist(p, pIter); |
| 158909 | + zCollist = rbuObjIterGetCollist(p, pIter); |
| 158708 | 158910 | pIter->nCol = pIter->nTblCol; |
| 158709 | 158911 | |
| 158710 | 158912 | /* Create the SELECT statement to read keys from data_xxx */ |
| 158711 | 158913 | if( p->rc==SQLITE_OK ){ |
| 158712 | | - p->rc = prepareFreeAndCollectError(p->dbOta, &pIter->pSelect, pz, |
| 158914 | + p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, |
| 158713 | 158915 | sqlite3_mprintf( |
| 158714 | | - "SELECT %s, ota_control%s FROM 'data_%q'%s", |
| 158715 | | - zCollist, (bOtaRowid ? ", ota_rowid" : ""), zTbl, zLimit |
| 158916 | + "SELECT %s, rbu_control%s FROM 'data_%q'%s", |
| 158917 | + zCollist, (bRbuRowid ? ", rbu_rowid" : ""), zTbl, zLimit |
| 158716 | 158918 | ) |
| 158717 | 158919 | ); |
| 158718 | 158920 | } |
| 158719 | 158921 | |
| 158720 | 158922 | /* Create the imposter table or tables (if required). */ |
| 158721 | | - otaCreateImposterTable(p, pIter); |
| 158722 | | - otaCreateImposterTable2(p, pIter); |
| 158723 | | - zWrite = (pIter->eType==OTA_PK_VTAB ? "" : "ota_imp_"); |
| 158923 | + rbuCreateImposterTable(p, pIter); |
| 158924 | + rbuCreateImposterTable2(p, pIter); |
| 158925 | + zWrite = (pIter->eType==RBU_PK_VTAB ? "" : "rbu_imp_"); |
| 158724 | 158926 | |
| 158725 | 158927 | /* Create the INSERT statement to write to the target PK b-tree */ |
| 158726 | 158928 | if( p->rc==SQLITE_OK ){ |
| 158727 | 158929 | p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pInsert, pz, |
| 158728 | 158930 | sqlite3_mprintf( |
| 158729 | 158931 | "INSERT INTO \"%s%w\"(%s%s) VALUES(%s)", |
| 158730 | | - zWrite, zTbl, zCollist, (bOtaRowid ? ", _rowid_" : ""), zBindings |
| 158932 | + zWrite, zTbl, zCollist, (bRbuRowid ? ", _rowid_" : ""), zBindings |
| 158731 | 158933 | ) |
| 158732 | 158934 | ); |
| 158733 | 158935 | } |
| 158734 | 158936 | |
| 158735 | 158937 | /* Create the DELETE statement to write to the target PK b-tree */ |
| | @@ -158740,55 +158942,55 @@ |
| 158740 | 158942 | ) |
| 158741 | 158943 | ); |
| 158742 | 158944 | } |
| 158743 | 158945 | |
| 158744 | 158946 | if( pIter->abIndexed ){ |
| 158745 | | - const char *zOtaRowid = ""; |
| 158746 | | - if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){ |
| 158747 | | - zOtaRowid = ", ota_rowid"; |
| 158947 | + const char *zRbuRowid = ""; |
| 158948 | + if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ |
| 158949 | + zRbuRowid = ", rbu_rowid"; |
| 158748 | 158950 | } |
| 158749 | 158951 | |
| 158750 | | - /* Create the ota_tmp_xxx table and the triggers to populate it. */ |
| 158751 | | - otaMPrintfExec(p, p->dbOta, |
| 158752 | | - "CREATE TABLE IF NOT EXISTS %s.'ota_tmp_%q' AS " |
| 158952 | + /* Create the rbu_tmp_xxx table and the triggers to populate it. */ |
| 158953 | + rbuMPrintfExec(p, p->dbRbu, |
| 158954 | + "CREATE TABLE IF NOT EXISTS %s.'rbu_tmp_%q' AS " |
| 158753 | 158955 | "SELECT *%s FROM 'data_%q' WHERE 0;" |
| 158754 | 158956 | , p->zStateDb |
| 158755 | | - , zTbl, (pIter->eType==OTA_PK_EXTERNAL ? ", 0 AS ota_rowid" : "") |
| 158957 | + , zTbl, (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "") |
| 158756 | 158958 | , zTbl |
| 158757 | 158959 | ); |
| 158758 | 158960 | |
| 158759 | | - otaMPrintfExec(p, p->dbMain, |
| 158760 | | - "CREATE TEMP TRIGGER ota_delete_tr BEFORE DELETE ON \"%s%w\" " |
| 158961 | + rbuMPrintfExec(p, p->dbMain, |
| 158962 | + "CREATE TEMP TRIGGER rbu_delete_tr BEFORE DELETE ON \"%s%w\" " |
| 158761 | 158963 | "BEGIN " |
| 158762 | | - " SELECT ota_tmp_insert(2, %s);" |
| 158964 | + " SELECT rbu_tmp_insert(2, %s);" |
| 158763 | 158965 | "END;" |
| 158764 | 158966 | |
| 158765 | | - "CREATE TEMP TRIGGER ota_update1_tr BEFORE UPDATE ON \"%s%w\" " |
| 158967 | + "CREATE TEMP TRIGGER rbu_update1_tr BEFORE UPDATE ON \"%s%w\" " |
| 158766 | 158968 | "BEGIN " |
| 158767 | | - " SELECT ota_tmp_insert(2, %s);" |
| 158969 | + " SELECT rbu_tmp_insert(2, %s);" |
| 158768 | 158970 | "END;" |
| 158769 | 158971 | |
| 158770 | | - "CREATE TEMP TRIGGER ota_update2_tr AFTER UPDATE ON \"%s%w\" " |
| 158972 | + "CREATE TEMP TRIGGER rbu_update2_tr AFTER UPDATE ON \"%s%w\" " |
| 158771 | 158973 | "BEGIN " |
| 158772 | | - " SELECT ota_tmp_insert(3, %s);" |
| 158974 | + " SELECT rbu_tmp_insert(3, %s);" |
| 158773 | 158975 | "END;", |
| 158774 | 158976 | zWrite, zTbl, zOldlist, |
| 158775 | 158977 | zWrite, zTbl, zOldlist, |
| 158776 | 158978 | zWrite, zTbl, zNewlist |
| 158777 | 158979 | ); |
| 158778 | 158980 | |
| 158779 | | - if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){ |
| 158780 | | - otaMPrintfExec(p, p->dbMain, |
| 158781 | | - "CREATE TEMP TRIGGER ota_insert_tr AFTER INSERT ON \"%s%w\" " |
| 158981 | + if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ |
| 158982 | + rbuMPrintfExec(p, p->dbMain, |
| 158983 | + "CREATE TEMP TRIGGER rbu_insert_tr AFTER INSERT ON \"%s%w\" " |
| 158782 | 158984 | "BEGIN " |
| 158783 | | - " SELECT ota_tmp_insert(0, %s);" |
| 158985 | + " SELECT rbu_tmp_insert(0, %s);" |
| 158784 | 158986 | "END;", |
| 158785 | 158987 | zWrite, zTbl, zNewlist |
| 158786 | 158988 | ); |
| 158787 | 158989 | } |
| 158788 | 158990 | |
| 158789 | | - otaObjIterPrepareTmpInsert(p, pIter, zCollist, zOtaRowid); |
| 158991 | + rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid); |
| 158790 | 158992 | } |
| 158791 | 158993 | |
| 158792 | 158994 | sqlite3_free(zWhere); |
| 158793 | 158995 | sqlite3_free(zOldlist); |
| 158794 | 158996 | sqlite3_free(zNewlist); |
| | @@ -158803,68 +159005,68 @@ |
| 158803 | 159005 | |
| 158804 | 159006 | /* |
| 158805 | 159007 | ** Set output variable *ppStmt to point to an UPDATE statement that may |
| 158806 | 159008 | ** be used to update the imposter table for the main table b-tree of the |
| 158807 | 159009 | ** table object that pIter currently points to, assuming that the |
| 158808 | | -** ota_control column of the data_xyz table contains zMask. |
| 159010 | +** rbu_control column of the data_xyz table contains zMask. |
| 158809 | 159011 | ** |
| 158810 | 159012 | ** If the zMask string does not specify any columns to update, then this |
| 158811 | 159013 | ** is not an error. Output variable *ppStmt is set to NULL in this case. |
| 158812 | 159014 | */ |
| 158813 | | -static int otaGetUpdateStmt( |
| 158814 | | - sqlite3ota *p, /* OTA handle */ |
| 158815 | | - OtaObjIter *pIter, /* Object iterator */ |
| 158816 | | - const char *zMask, /* ota_control value ('x.x.') */ |
| 159015 | +static int rbuGetUpdateStmt( |
| 159016 | + sqlite3rbu *p, /* RBU handle */ |
| 159017 | + RbuObjIter *pIter, /* Object iterator */ |
| 159018 | + const char *zMask, /* rbu_control value ('x.x.') */ |
| 158817 | 159019 | sqlite3_stmt **ppStmt /* OUT: UPDATE statement handle */ |
| 158818 | 159020 | ){ |
| 158819 | | - OtaUpdateStmt **pp; |
| 158820 | | - OtaUpdateStmt *pUp = 0; |
| 159021 | + RbuUpdateStmt **pp; |
| 159022 | + RbuUpdateStmt *pUp = 0; |
| 158821 | 159023 | int nUp = 0; |
| 158822 | 159024 | |
| 158823 | 159025 | /* In case an error occurs */ |
| 158824 | 159026 | *ppStmt = 0; |
| 158825 | 159027 | |
| 158826 | 159028 | /* Search for an existing statement. If one is found, shift it to the front |
| 158827 | 159029 | ** of the LRU queue and return immediately. Otherwise, leave nUp pointing |
| 158828 | 159030 | ** to the number of statements currently in the cache and pUp to the |
| 158829 | 159031 | ** last object in the list. */ |
| 158830 | | - for(pp=&pIter->pOtaUpdate; *pp; pp=&((*pp)->pNext)){ |
| 159032 | + for(pp=&pIter->pRbuUpdate; *pp; pp=&((*pp)->pNext)){ |
| 158831 | 159033 | pUp = *pp; |
| 158832 | 159034 | if( strcmp(pUp->zMask, zMask)==0 ){ |
| 158833 | 159035 | *pp = pUp->pNext; |
| 158834 | | - pUp->pNext = pIter->pOtaUpdate; |
| 158835 | | - pIter->pOtaUpdate = pUp; |
| 159036 | + pUp->pNext = pIter->pRbuUpdate; |
| 159037 | + pIter->pRbuUpdate = pUp; |
| 158836 | 159038 | *ppStmt = pUp->pUpdate; |
| 158837 | 159039 | return SQLITE_OK; |
| 158838 | 159040 | } |
| 158839 | 159041 | nUp++; |
| 158840 | 159042 | } |
| 158841 | 159043 | assert( pUp==0 || pUp->pNext==0 ); |
| 158842 | 159044 | |
| 158843 | | - if( nUp>=SQLITE_OTA_UPDATE_CACHESIZE ){ |
| 158844 | | - for(pp=&pIter->pOtaUpdate; *pp!=pUp; pp=&((*pp)->pNext)); |
| 159045 | + if( nUp>=SQLITE_RBU_UPDATE_CACHESIZE ){ |
| 159046 | + for(pp=&pIter->pRbuUpdate; *pp!=pUp; pp=&((*pp)->pNext)); |
| 158845 | 159047 | *pp = 0; |
| 158846 | 159048 | sqlite3_finalize(pUp->pUpdate); |
| 158847 | 159049 | pUp->pUpdate = 0; |
| 158848 | 159050 | }else{ |
| 158849 | | - pUp = (OtaUpdateStmt*)otaMalloc(p, sizeof(OtaUpdateStmt)+pIter->nTblCol+1); |
| 159051 | + pUp = (RbuUpdateStmt*)rbuMalloc(p, sizeof(RbuUpdateStmt)+pIter->nTblCol+1); |
| 158850 | 159052 | } |
| 158851 | 159053 | |
| 158852 | 159054 | if( pUp ){ |
| 158853 | | - char *zWhere = otaObjIterGetWhere(p, pIter); |
| 158854 | | - char *zSet = otaObjIterGetSetlist(p, pIter, zMask); |
| 159055 | + char *zWhere = rbuObjIterGetWhere(p, pIter); |
| 159056 | + char *zSet = rbuObjIterGetSetlist(p, pIter, zMask); |
| 158855 | 159057 | char *zUpdate = 0; |
| 158856 | 159058 | |
| 158857 | 159059 | pUp->zMask = (char*)&pUp[1]; |
| 158858 | 159060 | memcpy(pUp->zMask, zMask, pIter->nTblCol); |
| 158859 | | - pUp->pNext = pIter->pOtaUpdate; |
| 158860 | | - pIter->pOtaUpdate = pUp; |
| 159061 | + pUp->pNext = pIter->pRbuUpdate; |
| 159062 | + pIter->pRbuUpdate = pUp; |
| 158861 | 159063 | |
| 158862 | 159064 | if( zSet ){ |
| 158863 | 159065 | const char *zPrefix = ""; |
| 158864 | 159066 | |
| 158865 | | - if( pIter->eType!=OTA_PK_VTAB ) zPrefix = "ota_imp_"; |
| 159067 | + if( pIter->eType!=RBU_PK_VTAB ) zPrefix = "rbu_imp_"; |
| 158866 | 159068 | zUpdate = sqlite3_mprintf("UPDATE \"%s%w\" SET %s WHERE %s", |
| 158867 | 159069 | zPrefix, pIter->zTbl, zSet, zWhere |
| 158868 | 159070 | ); |
| 158869 | 159071 | p->rc = prepareFreeAndCollectError( |
| 158870 | 159072 | p->dbMain, &pUp->pUpdate, &p->zErrmsg, zUpdate |
| | @@ -158876,11 +159078,11 @@ |
| 158876 | 159078 | } |
| 158877 | 159079 | |
| 158878 | 159080 | return p->rc; |
| 158879 | 159081 | } |
| 158880 | 159082 | |
| 158881 | | -static sqlite3 *otaOpenDbhandle(sqlite3ota *p, const char *zName){ |
| 159083 | +static sqlite3 *rbuOpenDbhandle(sqlite3rbu *p, const char *zName){ |
| 158882 | 159084 | sqlite3 *db = 0; |
| 158883 | 159085 | if( p->rc==SQLITE_OK ){ |
| 158884 | 159086 | const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI; |
| 158885 | 159087 | p->rc = sqlite3_open_v2(zName, &db, flags, p->zVfsName); |
| 158886 | 159088 | if( p->rc ){ |
| | @@ -158891,51 +159093,51 @@ |
| 158891 | 159093 | } |
| 158892 | 159094 | return db; |
| 158893 | 159095 | } |
| 158894 | 159096 | |
| 158895 | 159097 | /* |
| 158896 | | -** Open the database handle and attach the OTA database as "ota". If an |
| 158897 | | -** error occurs, leave an error code and message in the OTA handle. |
| 159098 | +** Open the database handle and attach the RBU database as "rbu". If an |
| 159099 | +** error occurs, leave an error code and message in the RBU handle. |
| 158898 | 159100 | */ |
| 158899 | | -static void otaOpenDatabase(sqlite3ota *p){ |
| 159101 | +static void rbuOpenDatabase(sqlite3rbu *p){ |
| 158900 | 159102 | assert( p->rc==SQLITE_OK ); |
| 158901 | | - assert( p->dbMain==0 && p->dbOta==0 ); |
| 159103 | + assert( p->dbMain==0 && p->dbRbu==0 ); |
| 158902 | 159104 | |
| 158903 | 159105 | p->eStage = 0; |
| 158904 | | - p->dbMain = otaOpenDbhandle(p, p->zTarget); |
| 158905 | | - p->dbOta = otaOpenDbhandle(p, p->zOta); |
| 159106 | + p->dbMain = rbuOpenDbhandle(p, p->zTarget); |
| 159107 | + p->dbRbu = rbuOpenDbhandle(p, p->zRbu); |
| 158906 | 159108 | |
| 158907 | | - /* If using separate OTA and state databases, attach the state database to |
| 158908 | | - ** the OTA db handle now. */ |
| 159109 | + /* If using separate RBU and state databases, attach the state database to |
| 159110 | + ** the RBU db handle now. */ |
| 158909 | 159111 | if( p->zState ){ |
| 158910 | | - otaMPrintfExec(p, p->dbOta, "ATTACH %Q AS stat", p->zState); |
| 159112 | + rbuMPrintfExec(p, p->dbRbu, "ATTACH %Q AS stat", p->zState); |
| 158911 | 159113 | memcpy(p->zStateDb, "stat", 4); |
| 158912 | 159114 | }else{ |
| 158913 | 159115 | memcpy(p->zStateDb, "main", 4); |
| 158914 | 159116 | } |
| 158915 | 159117 | |
| 158916 | 159118 | if( p->rc==SQLITE_OK ){ |
| 158917 | 159119 | p->rc = sqlite3_create_function(p->dbMain, |
| 158918 | | - "ota_tmp_insert", -1, SQLITE_UTF8, (void*)p, otaTmpInsertFunc, 0, 0 |
| 159120 | + "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0 |
| 158919 | 159121 | ); |
| 158920 | 159122 | } |
| 158921 | 159123 | |
| 158922 | 159124 | if( p->rc==SQLITE_OK ){ |
| 158923 | | - p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_OTA, (void*)p); |
| 159125 | + p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p); |
| 158924 | 159126 | } |
| 158925 | | - otaMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master"); |
| 159127 | + rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master"); |
| 158926 | 159128 | |
| 158927 | | - /* Mark the database file just opened as an OTA target database. If |
| 158928 | | - ** this call returns SQLITE_NOTFOUND, then the OTA vfs is not in use. |
| 159129 | + /* Mark the database file just opened as an RBU target database. If |
| 159130 | + ** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use. |
| 158929 | 159131 | ** This is an error. */ |
| 158930 | 159132 | if( p->rc==SQLITE_OK ){ |
| 158931 | | - p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_OTA, (void*)p); |
| 159133 | + p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p); |
| 158932 | 159134 | } |
| 158933 | 159135 | |
| 158934 | 159136 | if( p->rc==SQLITE_NOTFOUND ){ |
| 158935 | 159137 | p->rc = SQLITE_ERROR; |
| 158936 | | - p->zErrmsg = sqlite3_mprintf("ota vfs not found"); |
| 159138 | + p->zErrmsg = sqlite3_mprintf("rbu vfs not found"); |
| 158937 | 159139 | } |
| 158938 | 159140 | } |
| 158939 | 159141 | |
| 158940 | 159142 | /* |
| 158941 | 159143 | ** This routine is a copy of the sqlite3FileSuffix3() routine from the core. |
| | @@ -158955,11 +159157,11 @@ |
| 158955 | 159157 | ** test.db-journal => test.nal |
| 158956 | 159158 | ** test.db-wal => test.wal |
| 158957 | 159159 | ** test.db-shm => test.shm |
| 158958 | 159160 | ** test.db-mj7f3319fa => test.9fa |
| 158959 | 159161 | */ |
| 158960 | | -static void otaFileSuffix3(const char *zBase, char *z){ |
| 159162 | +static void rbuFileSuffix3(const char *zBase, char *z){ |
| 158961 | 159163 | #ifdef SQLITE_ENABLE_8_3_NAMES |
| 158962 | 159164 | #if SQLITE_ENABLE_8_3_NAMES<2 |
| 158963 | 159165 | if( sqlite3_uri_boolean(zBase, "8_3_names", 0) ) |
| 158964 | 159166 | #endif |
| 158965 | 159167 | { |
| | @@ -158976,11 +159178,11 @@ |
| 158976 | 159178 | ** as a 64-bit integer. |
| 158977 | 159179 | ** |
| 158978 | 159180 | ** The checksum is store in the first page of xShmMap memory as an 8-byte |
| 158979 | 159181 | ** blob starting at byte offset 40. |
| 158980 | 159182 | */ |
| 158981 | | -static i64 otaShmChecksum(sqlite3ota *p){ |
| 159183 | +static i64 rbuShmChecksum(sqlite3rbu *p){ |
| 158982 | 159184 | i64 iRet = 0; |
| 158983 | 159185 | if( p->rc==SQLITE_OK ){ |
| 158984 | 159186 | sqlite3_file *pDb = p->pTargetFd->pReal; |
| 158985 | 159187 | u32 volatile *ptr; |
| 158986 | 159188 | p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, (void volatile**)&ptr); |
| | @@ -158993,23 +159195,23 @@ |
| 158993 | 159195 | |
| 158994 | 159196 | /* |
| 158995 | 159197 | ** This function is called as part of initializing or reinitializing an |
| 158996 | 159198 | ** incremental checkpoint. |
| 158997 | 159199 | ** |
| 158998 | | -** It populates the sqlite3ota.aFrame[] array with the set of |
| 159200 | +** It populates the sqlite3rbu.aFrame[] array with the set of |
| 158999 | 159201 | ** (wal frame -> db page) copy operations required to checkpoint the |
| 159000 | 159202 | ** current wal file, and obtains the set of shm locks required to safely |
| 159001 | 159203 | ** perform the copy operations directly on the file-system. |
| 159002 | 159204 | ** |
| 159003 | 159205 | ** If argument pState is not NULL, then the incremental checkpoint is |
| 159004 | 159206 | ** being resumed. In this case, if the checksum of the wal-index-header |
| 159005 | | -** following recovery is not the same as the checksum saved in the OtaState |
| 159006 | | -** object, then the ota handle is set to DONE state. This occurs if some |
| 159207 | +** following recovery is not the same as the checksum saved in the RbuState |
| 159208 | +** object, then the rbu handle is set to DONE state. This occurs if some |
| 159007 | 159209 | ** other client appends a transaction to the wal file in the middle of |
| 159008 | 159210 | ** an incremental checkpoint. |
| 159009 | 159211 | */ |
| 159010 | | -static void otaSetupCheckpoint(sqlite3ota *p, OtaState *pState){ |
| 159212 | +static void rbuSetupCheckpoint(sqlite3rbu *p, RbuState *pState){ |
| 159011 | 159213 | |
| 159012 | 159214 | /* If pState is NULL, then the wal file may not have been opened and |
| 159013 | 159215 | ** recovered. Running a read-statement here to ensure that doing so |
| 159014 | 159216 | ** does not interfere with the "capture" process below. */ |
| 159015 | 159217 | if( pState==0 ){ |
| | @@ -159018,20 +159220,20 @@ |
| 159018 | 159220 | p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_master", 0, 0, 0); |
| 159019 | 159221 | } |
| 159020 | 159222 | } |
| 159021 | 159223 | |
| 159022 | 159224 | /* Assuming no error has occurred, run a "restart" checkpoint with the |
| 159023 | | - ** sqlite3ota.eStage variable set to CAPTURE. This turns on the following |
| 159024 | | - ** special behaviour in the ota VFS: |
| 159225 | + ** sqlite3rbu.eStage variable set to CAPTURE. This turns on the following |
| 159226 | + ** special behaviour in the rbu VFS: |
| 159025 | 159227 | ** |
| 159026 | 159228 | ** * If the exclusive shm WRITER or READ0 lock cannot be obtained, |
| 159027 | 159229 | ** the checkpoint fails with SQLITE_BUSY (normally SQLite would |
| 159028 | 159230 | ** proceed with running a passive checkpoint instead of failing). |
| 159029 | 159231 | ** |
| 159030 | 159232 | ** * Attempts to read from the *-wal file or write to the database file |
| 159031 | 159233 | ** do not perform any IO. Instead, the frame/page combinations that |
| 159032 | | - ** would be read/written are recorded in the sqlite3ota.aFrame[] |
| 159234 | + ** would be read/written are recorded in the sqlite3rbu.aFrame[] |
| 159033 | 159235 | ** array. |
| 159034 | 159236 | ** |
| 159035 | 159237 | ** * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER, |
| 159036 | 159238 | ** READ0 and CHECKPOINT locks taken as part of the checkpoint are |
| 159037 | 159239 | ** no-ops. These locks will not be released until the connection |
| | @@ -159047,76 +159249,76 @@ |
| 159047 | 159249 | ** data from the wal file into the database file according to the |
| 159048 | 159250 | ** contents of aFrame[]. |
| 159049 | 159251 | */ |
| 159050 | 159252 | if( p->rc==SQLITE_OK ){ |
| 159051 | 159253 | int rc2; |
| 159052 | | - p->eStage = OTA_STAGE_CAPTURE; |
| 159254 | + p->eStage = RBU_STAGE_CAPTURE; |
| 159053 | 159255 | rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0); |
| 159054 | 159256 | if( rc2!=SQLITE_INTERNAL ) p->rc = rc2; |
| 159055 | 159257 | } |
| 159056 | 159258 | |
| 159057 | 159259 | if( p->rc==SQLITE_OK ){ |
| 159058 | | - p->eStage = OTA_STAGE_CKPT; |
| 159260 | + p->eStage = RBU_STAGE_CKPT; |
| 159059 | 159261 | p->nStep = (pState ? pState->nRow : 0); |
| 159060 | | - p->aBuf = otaMalloc(p, p->pgsz); |
| 159061 | | - p->iWalCksum = otaShmChecksum(p); |
| 159262 | + p->aBuf = rbuMalloc(p, p->pgsz); |
| 159263 | + p->iWalCksum = rbuShmChecksum(p); |
| 159062 | 159264 | } |
| 159063 | 159265 | |
| 159064 | 159266 | if( p->rc==SQLITE_OK && pState && pState->iWalCksum!=p->iWalCksum ){ |
| 159065 | 159267 | p->rc = SQLITE_DONE; |
| 159066 | | - p->eStage = OTA_STAGE_DONE; |
| 159268 | + p->eStage = RBU_STAGE_DONE; |
| 159067 | 159269 | } |
| 159068 | 159270 | } |
| 159069 | 159271 | |
| 159070 | 159272 | /* |
| 159071 | 159273 | ** Called when iAmt bytes are read from offset iOff of the wal file while |
| 159072 | | -** the ota object is in capture mode. Record the frame number of the frame |
| 159274 | +** the rbu object is in capture mode. Record the frame number of the frame |
| 159073 | 159275 | ** being read in the aFrame[] array. |
| 159074 | 159276 | */ |
| 159075 | | -static int otaCaptureWalRead(sqlite3ota *pOta, i64 iOff, int iAmt){ |
| 159277 | +static int rbuCaptureWalRead(sqlite3rbu *pRbu, i64 iOff, int iAmt){ |
| 159076 | 159278 | const u32 mReq = (1<<WAL_LOCK_WRITE)|(1<<WAL_LOCK_CKPT)|(1<<WAL_LOCK_READ0); |
| 159077 | 159279 | u32 iFrame; |
| 159078 | 159280 | |
| 159079 | | - if( pOta->mLock!=mReq ){ |
| 159080 | | - pOta->rc = SQLITE_BUSY; |
| 159281 | + if( pRbu->mLock!=mReq ){ |
| 159282 | + pRbu->rc = SQLITE_BUSY; |
| 159081 | 159283 | return SQLITE_INTERNAL; |
| 159082 | 159284 | } |
| 159083 | 159285 | |
| 159084 | | - pOta->pgsz = iAmt; |
| 159085 | | - if( pOta->nFrame==pOta->nFrameAlloc ){ |
| 159086 | | - int nNew = (pOta->nFrameAlloc ? pOta->nFrameAlloc : 64) * 2; |
| 159087 | | - OtaFrame *aNew; |
| 159088 | | - aNew = (OtaFrame*)sqlite3_realloc(pOta->aFrame, nNew * sizeof(OtaFrame)); |
| 159286 | + pRbu->pgsz = iAmt; |
| 159287 | + if( pRbu->nFrame==pRbu->nFrameAlloc ){ |
| 159288 | + int nNew = (pRbu->nFrameAlloc ? pRbu->nFrameAlloc : 64) * 2; |
| 159289 | + RbuFrame *aNew; |
| 159290 | + aNew = (RbuFrame*)sqlite3_realloc(pRbu->aFrame, nNew * sizeof(RbuFrame)); |
| 159089 | 159291 | if( aNew==0 ) return SQLITE_NOMEM; |
| 159090 | | - pOta->aFrame = aNew; |
| 159091 | | - pOta->nFrameAlloc = nNew; |
| 159292 | + pRbu->aFrame = aNew; |
| 159293 | + pRbu->nFrameAlloc = nNew; |
| 159092 | 159294 | } |
| 159093 | 159295 | |
| 159094 | 159296 | iFrame = (u32)((iOff-32) / (i64)(iAmt+24)) + 1; |
| 159095 | | - if( pOta->iMaxFrame<iFrame ) pOta->iMaxFrame = iFrame; |
| 159096 | | - pOta->aFrame[pOta->nFrame].iWalFrame = iFrame; |
| 159097 | | - pOta->aFrame[pOta->nFrame].iDbPage = 0; |
| 159098 | | - pOta->nFrame++; |
| 159297 | + if( pRbu->iMaxFrame<iFrame ) pRbu->iMaxFrame = iFrame; |
| 159298 | + pRbu->aFrame[pRbu->nFrame].iWalFrame = iFrame; |
| 159299 | + pRbu->aFrame[pRbu->nFrame].iDbPage = 0; |
| 159300 | + pRbu->nFrame++; |
| 159099 | 159301 | return SQLITE_OK; |
| 159100 | 159302 | } |
| 159101 | 159303 | |
| 159102 | 159304 | /* |
| 159103 | 159305 | ** Called when a page of data is written to offset iOff of the database |
| 159104 | | -** file while the ota handle is in capture mode. Record the page number |
| 159306 | +** file while the rbu handle is in capture mode. Record the page number |
| 159105 | 159307 | ** of the page being written in the aFrame[] array. |
| 159106 | 159308 | */ |
| 159107 | | -static int otaCaptureDbWrite(sqlite3ota *pOta, i64 iOff){ |
| 159108 | | - pOta->aFrame[pOta->nFrame-1].iDbPage = (u32)(iOff / pOta->pgsz) + 1; |
| 159309 | +static int rbuCaptureDbWrite(sqlite3rbu *pRbu, i64 iOff){ |
| 159310 | + pRbu->aFrame[pRbu->nFrame-1].iDbPage = (u32)(iOff / pRbu->pgsz) + 1; |
| 159109 | 159311 | return SQLITE_OK; |
| 159110 | 159312 | } |
| 159111 | 159313 | |
| 159112 | 159314 | /* |
| 159113 | 159315 | ** This is called as part of an incremental checkpoint operation. Copy |
| 159114 | 159316 | ** a single frame of data from the wal file into the database file, as |
| 159115 | | -** indicated by the OtaFrame object. |
| 159317 | +** indicated by the RbuFrame object. |
| 159116 | 159318 | */ |
| 159117 | | -static void otaCheckpointFrame(sqlite3ota *p, OtaFrame *pFrame){ |
| 159319 | +static void rbuCheckpointFrame(sqlite3rbu *p, RbuFrame *pFrame){ |
| 159118 | 159320 | sqlite3_file *pWal = p->pTargetFd->pWalFd->pReal; |
| 159119 | 159321 | sqlite3_file *pDb = p->pTargetFd->pReal; |
| 159120 | 159322 | i64 iOff; |
| 159121 | 159323 | |
| 159122 | 159324 | assert( p->rc==SQLITE_OK ); |
| | @@ -159130,33 +159332,33 @@ |
| 159130 | 159332 | |
| 159131 | 159333 | |
| 159132 | 159334 | /* |
| 159133 | 159335 | ** Take an EXCLUSIVE lock on the database file. |
| 159134 | 159336 | */ |
| 159135 | | -static void otaLockDatabase(sqlite3ota *p){ |
| 159337 | +static void rbuLockDatabase(sqlite3rbu *p){ |
| 159136 | 159338 | sqlite3_file *pReal = p->pTargetFd->pReal; |
| 159137 | 159339 | assert( p->rc==SQLITE_OK ); |
| 159138 | 159340 | p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_SHARED); |
| 159139 | 159341 | if( p->rc==SQLITE_OK ){ |
| 159140 | 159342 | p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_EXCLUSIVE); |
| 159141 | 159343 | } |
| 159142 | 159344 | } |
| 159143 | 159345 | |
| 159144 | 159346 | /* |
| 159145 | | -** The OTA handle is currently in OTA_STAGE_OAL state, with a SHARED lock |
| 159347 | +** The RBU handle is currently in RBU_STAGE_OAL state, with a SHARED lock |
| 159146 | 159348 | ** on the database file. This proc moves the *-oal file to the *-wal path, |
| 159147 | 159349 | ** then reopens the database file (this time in vanilla, non-oal, WAL mode). |
| 159148 | | -** If an error occurs, leave an error code and error message in the ota |
| 159350 | +** If an error occurs, leave an error code and error message in the rbu |
| 159149 | 159351 | ** handle. |
| 159150 | 159352 | */ |
| 159151 | | -static void otaMoveOalFile(sqlite3ota *p){ |
| 159353 | +static void rbuMoveOalFile(sqlite3rbu *p){ |
| 159152 | 159354 | const char *zBase = sqlite3_db_filename(p->dbMain, "main"); |
| 159153 | 159355 | |
| 159154 | 159356 | char *zWal = sqlite3_mprintf("%s-wal", zBase); |
| 159155 | 159357 | char *zOal = sqlite3_mprintf("%s-oal", zBase); |
| 159156 | 159358 | |
| 159157 | | - assert( p->eStage==OTA_STAGE_MOVE ); |
| 159359 | + assert( p->eStage==RBU_STAGE_MOVE ); |
| 159158 | 159360 | assert( p->rc==SQLITE_OK && p->zErrmsg==0 ); |
| 159159 | 159361 | if( zWal==0 || zOal==0 ){ |
| 159160 | 159362 | p->rc = SQLITE_NOMEM; |
| 159161 | 159363 | }else{ |
| 159162 | 159364 | /* Move the *-oal file to *-wal. At this point connection p->db is |
| | @@ -159164,25 +159366,25 @@ |
| 159164 | 159366 | ** in WAL mode). So no other connection may be writing the db. |
| 159165 | 159367 | ** |
| 159166 | 159368 | ** In order to ensure that there are no database readers, an EXCLUSIVE |
| 159167 | 159369 | ** lock is obtained here before the *-oal is moved to *-wal. |
| 159168 | 159370 | */ |
| 159169 | | - otaLockDatabase(p); |
| 159371 | + rbuLockDatabase(p); |
| 159170 | 159372 | if( p->rc==SQLITE_OK ){ |
| 159171 | | - otaFileSuffix3(zBase, zWal); |
| 159172 | | - otaFileSuffix3(zBase, zOal); |
| 159373 | + rbuFileSuffix3(zBase, zWal); |
| 159374 | + rbuFileSuffix3(zBase, zOal); |
| 159173 | 159375 | |
| 159174 | 159376 | /* Re-open the databases. */ |
| 159175 | | - otaObjIterFinalize(&p->objiter); |
| 159377 | + rbuObjIterFinalize(&p->objiter); |
| 159176 | 159378 | sqlite3_close(p->dbMain); |
| 159177 | | - sqlite3_close(p->dbOta); |
| 159379 | + sqlite3_close(p->dbRbu); |
| 159178 | 159380 | p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK; |
| 159179 | 159381 | if( p->rc==SQLITE_OK ){ |
| 159180 | 159382 | p->dbMain = 0; |
| 159181 | | - p->dbOta = 0; |
| 159182 | | - otaOpenDatabase(p); |
| 159183 | | - otaSetupCheckpoint(p, 0); |
| 159383 | + p->dbRbu = 0; |
| 159384 | + rbuOpenDatabase(p); |
| 159385 | + rbuSetupCheckpoint(p, 0); |
| 159184 | 159386 | } |
| 159185 | 159387 | } |
| 159186 | 159388 | } |
| 159187 | 159389 | |
| 159188 | 159390 | sqlite3_free(zWal); |
| | @@ -159193,36 +159395,36 @@ |
| 159193 | 159395 | ** The SELECT statement iterating through the keys for the current object |
| 159194 | 159396 | ** (p->objiter.pSelect) currently points to a valid row. This function |
| 159195 | 159397 | ** determines the type of operation requested by this row and returns |
| 159196 | 159398 | ** one of the following values to indicate the result: |
| 159197 | 159399 | ** |
| 159198 | | -** * OTA_INSERT |
| 159199 | | -** * OTA_DELETE |
| 159200 | | -** * OTA_IDX_DELETE |
| 159201 | | -** * OTA_UPDATE |
| 159400 | +** * RBU_INSERT |
| 159401 | +** * RBU_DELETE |
| 159402 | +** * RBU_IDX_DELETE |
| 159403 | +** * RBU_UPDATE |
| 159202 | 159404 | ** |
| 159203 | | -** If OTA_UPDATE is returned, then output variable *pzMask is set to |
| 159405 | +** If RBU_UPDATE is returned, then output variable *pzMask is set to |
| 159204 | 159406 | ** point to the text value indicating the columns to update. |
| 159205 | 159407 | ** |
| 159206 | | -** If the ota_control field contains an invalid value, an error code and |
| 159207 | | -** message are left in the OTA handle and zero returned. |
| 159408 | +** If the rbu_control field contains an invalid value, an error code and |
| 159409 | +** message are left in the RBU handle and zero returned. |
| 159208 | 159410 | */ |
| 159209 | | -static int otaStepType(sqlite3ota *p, const char **pzMask){ |
| 159210 | | - int iCol = p->objiter.nCol; /* Index of ota_control column */ |
| 159411 | +static int rbuStepType(sqlite3rbu *p, const char **pzMask){ |
| 159412 | + int iCol = p->objiter.nCol; /* Index of rbu_control column */ |
| 159211 | 159413 | int res = 0; /* Return value */ |
| 159212 | 159414 | |
| 159213 | 159415 | switch( sqlite3_column_type(p->objiter.pSelect, iCol) ){ |
| 159214 | 159416 | case SQLITE_INTEGER: { |
| 159215 | 159417 | int iVal = sqlite3_column_int(p->objiter.pSelect, iCol); |
| 159216 | 159418 | if( iVal==0 ){ |
| 159217 | | - res = OTA_INSERT; |
| 159419 | + res = RBU_INSERT; |
| 159218 | 159420 | }else if( iVal==1 ){ |
| 159219 | | - res = OTA_DELETE; |
| 159421 | + res = RBU_DELETE; |
| 159220 | 159422 | }else if( iVal==2 ){ |
| 159221 | | - res = OTA_IDX_DELETE; |
| 159423 | + res = RBU_IDX_DELETE; |
| 159222 | 159424 | }else if( iVal==3 ){ |
| 159223 | | - res = OTA_IDX_INSERT; |
| 159425 | + res = RBU_IDX_INSERT; |
| 159224 | 159426 | } |
| 159225 | 159427 | break; |
| 159226 | 159428 | } |
| 159227 | 159429 | |
| 159228 | 159430 | case SQLITE_TEXT: { |
| | @@ -159230,21 +159432,21 @@ |
| 159230 | 159432 | if( z==0 ){ |
| 159231 | 159433 | p->rc = SQLITE_NOMEM; |
| 159232 | 159434 | }else{ |
| 159233 | 159435 | *pzMask = (const char*)z; |
| 159234 | 159436 | } |
| 159235 | | - res = OTA_UPDATE; |
| 159437 | + res = RBU_UPDATE; |
| 159236 | 159438 | |
| 159237 | 159439 | break; |
| 159238 | 159440 | } |
| 159239 | 159441 | |
| 159240 | 159442 | default: |
| 159241 | 159443 | break; |
| 159242 | 159444 | } |
| 159243 | 159445 | |
| 159244 | 159446 | if( res==0 ){ |
| 159245 | | - otaBadControlError(p); |
| 159447 | + rbuBadControlError(p); |
| 159246 | 159448 | } |
| 159247 | 159449 | return res; |
| 159248 | 159450 | } |
| 159249 | 159451 | |
| 159250 | 159452 | #ifdef SQLITE_DEBUG |
| | @@ -159258,82 +159460,82 @@ |
| 159258 | 159460 | #else |
| 159259 | 159461 | # define assertColumnName(x,y,z) |
| 159260 | 159462 | #endif |
| 159261 | 159463 | |
| 159262 | 159464 | /* |
| 159263 | | -** This function does the work for an sqlite3ota_step() call. |
| 159465 | +** This function does the work for an sqlite3rbu_step() call. |
| 159264 | 159466 | ** |
| 159265 | 159467 | ** The object-iterator (p->objiter) currently points to a valid object, |
| 159266 | 159468 | ** and the input cursor (p->objiter.pSelect) currently points to a valid |
| 159267 | 159469 | ** input row. Perform whatever processing is required and return. |
| 159268 | 159470 | ** |
| 159269 | 159471 | ** If no error occurs, SQLITE_OK is returned. Otherwise, an error code |
| 159270 | | -** and message is left in the OTA handle and a copy of the error code |
| 159472 | +** and message is left in the RBU handle and a copy of the error code |
| 159271 | 159473 | ** returned. |
| 159272 | 159474 | */ |
| 159273 | | -static int otaStep(sqlite3ota *p){ |
| 159274 | | - OtaObjIter *pIter = &p->objiter; |
| 159475 | +static int rbuStep(sqlite3rbu *p){ |
| 159476 | + RbuObjIter *pIter = &p->objiter; |
| 159275 | 159477 | const char *zMask = 0; |
| 159276 | 159478 | int i; |
| 159277 | | - int eType = otaStepType(p, &zMask); |
| 159479 | + int eType = rbuStepType(p, &zMask); |
| 159278 | 159480 | |
| 159279 | 159481 | if( eType ){ |
| 159280 | | - assert( eType!=OTA_UPDATE || pIter->zIdx==0 ); |
| 159482 | + assert( eType!=RBU_UPDATE || pIter->zIdx==0 ); |
| 159281 | 159483 | |
| 159282 | | - if( pIter->zIdx==0 && eType==OTA_IDX_DELETE ){ |
| 159283 | | - otaBadControlError(p); |
| 159484 | + if( pIter->zIdx==0 && eType==RBU_IDX_DELETE ){ |
| 159485 | + rbuBadControlError(p); |
| 159284 | 159486 | } |
| 159285 | 159487 | else if( |
| 159286 | | - eType==OTA_INSERT |
| 159287 | | - || eType==OTA_DELETE |
| 159288 | | - || eType==OTA_IDX_DELETE |
| 159289 | | - || eType==OTA_IDX_INSERT |
| 159488 | + eType==RBU_INSERT |
| 159489 | + || eType==RBU_DELETE |
| 159490 | + || eType==RBU_IDX_DELETE |
| 159491 | + || eType==RBU_IDX_INSERT |
| 159290 | 159492 | ){ |
| 159291 | 159493 | sqlite3_value *pVal; |
| 159292 | 159494 | sqlite3_stmt *pWriter; |
| 159293 | 159495 | |
| 159294 | | - assert( eType!=OTA_UPDATE ); |
| 159295 | | - assert( eType!=OTA_DELETE || pIter->zIdx==0 ); |
| 159496 | + assert( eType!=RBU_UPDATE ); |
| 159497 | + assert( eType!=RBU_DELETE || pIter->zIdx==0 ); |
| 159296 | 159498 | |
| 159297 | | - if( eType==OTA_IDX_DELETE || eType==OTA_DELETE ){ |
| 159499 | + if( eType==RBU_IDX_DELETE || eType==RBU_DELETE ){ |
| 159298 | 159500 | pWriter = pIter->pDelete; |
| 159299 | 159501 | }else{ |
| 159300 | 159502 | pWriter = pIter->pInsert; |
| 159301 | 159503 | } |
| 159302 | 159504 | |
| 159303 | 159505 | for(i=0; i<pIter->nCol; i++){ |
| 159304 | 159506 | /* If this is an INSERT into a table b-tree and the table has an |
| 159305 | 159507 | ** explicit INTEGER PRIMARY KEY, check that this is not an attempt |
| 159306 | 159508 | ** to write a NULL into the IPK column. That is not permitted. */ |
| 159307 | | - if( eType==OTA_INSERT |
| 159308 | | - && pIter->zIdx==0 && pIter->eType==OTA_PK_IPK && pIter->abTblPk[i] |
| 159509 | + if( eType==RBU_INSERT |
| 159510 | + && pIter->zIdx==0 && pIter->eType==RBU_PK_IPK && pIter->abTblPk[i] |
| 159309 | 159511 | && sqlite3_column_type(pIter->pSelect, i)==SQLITE_NULL |
| 159310 | 159512 | ){ |
| 159311 | 159513 | p->rc = SQLITE_MISMATCH; |
| 159312 | 159514 | p->zErrmsg = sqlite3_mprintf("datatype mismatch"); |
| 159313 | 159515 | goto step_out; |
| 159314 | 159516 | } |
| 159315 | 159517 | |
| 159316 | | - if( eType==OTA_DELETE && pIter->abTblPk[i]==0 ){ |
| 159518 | + if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){ |
| 159317 | 159519 | continue; |
| 159318 | 159520 | } |
| 159319 | 159521 | |
| 159320 | 159522 | pVal = sqlite3_column_value(pIter->pSelect, i); |
| 159321 | 159523 | p->rc = sqlite3_bind_value(pWriter, i+1, pVal); |
| 159322 | 159524 | if( p->rc ) goto step_out; |
| 159323 | 159525 | } |
| 159324 | 159526 | if( pIter->zIdx==0 |
| 159325 | | - && (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE) |
| 159527 | + && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) |
| 159326 | 159528 | ){ |
| 159327 | 159529 | /* For a virtual table, or a table with no primary key, the |
| 159328 | 159530 | ** SELECT statement is: |
| 159329 | 159531 | ** |
| 159330 | | - ** SELECT <cols>, ota_control, ota_rowid FROM .... |
| 159532 | + ** SELECT <cols>, rbu_control, rbu_rowid FROM .... |
| 159331 | 159533 | ** |
| 159332 | 159534 | ** Hence column_value(pIter->nCol+1). |
| 159333 | 159535 | */ |
| 159334 | | - assertColumnName(pIter->pSelect, pIter->nCol+1, "ota_rowid"); |
| 159536 | + assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid"); |
| 159335 | 159537 | pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1); |
| 159336 | 159538 | p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal); |
| 159337 | 159539 | } |
| 159338 | 159540 | if( p->rc==SQLITE_OK ){ |
| 159339 | 159541 | sqlite3_step(pWriter); |
| | @@ -159340,25 +159542,25 @@ |
| 159340 | 159542 | p->rc = resetAndCollectError(pWriter, &p->zErrmsg); |
| 159341 | 159543 | } |
| 159342 | 159544 | }else{ |
| 159343 | 159545 | sqlite3_value *pVal; |
| 159344 | 159546 | sqlite3_stmt *pUpdate = 0; |
| 159345 | | - assert( eType==OTA_UPDATE ); |
| 159346 | | - otaGetUpdateStmt(p, pIter, zMask, &pUpdate); |
| 159547 | + assert( eType==RBU_UPDATE ); |
| 159548 | + rbuGetUpdateStmt(p, pIter, zMask, &pUpdate); |
| 159347 | 159549 | if( pUpdate ){ |
| 159348 | 159550 | for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){ |
| 159349 | 159551 | char c = zMask[pIter->aiSrcOrder[i]]; |
| 159350 | 159552 | pVal = sqlite3_column_value(pIter->pSelect, i); |
| 159351 | 159553 | if( pIter->abTblPk[i] || c=='x' || c=='d' ){ |
| 159352 | 159554 | p->rc = sqlite3_bind_value(pUpdate, i+1, pVal); |
| 159353 | 159555 | } |
| 159354 | 159556 | } |
| 159355 | 159557 | if( p->rc==SQLITE_OK |
| 159356 | | - && (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE) |
| 159558 | + && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) |
| 159357 | 159559 | ){ |
| 159358 | | - /* Bind the ota_rowid value to column _rowid_ */ |
| 159359 | | - assertColumnName(pIter->pSelect, pIter->nCol+1, "ota_rowid"); |
| 159560 | + /* Bind the rbu_rowid value to column _rowid_ */ |
| 159561 | + assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid"); |
| 159360 | 159562 | pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1); |
| 159361 | 159563 | p->rc = sqlite3_bind_value(pUpdate, pIter->nCol+1, pVal); |
| 159362 | 159564 | } |
| 159363 | 159565 | if( p->rc==SQLITE_OK ){ |
| 159364 | 159566 | sqlite3_step(pUpdate); |
| | @@ -159373,11 +159575,11 @@ |
| 159373 | 159575 | } |
| 159374 | 159576 | |
| 159375 | 159577 | /* |
| 159376 | 159578 | ** Increment the schema cookie of the main database opened by p->dbMain. |
| 159377 | 159579 | */ |
| 159378 | | -static void otaIncrSchemaCookie(sqlite3ota *p){ |
| 159580 | +static void rbuIncrSchemaCookie(sqlite3rbu *p){ |
| 159379 | 159581 | if( p->rc==SQLITE_OK ){ |
| 159380 | 159582 | int iCookie = 1000000; |
| 159381 | 159583 | sqlite3_stmt *pStmt; |
| 159382 | 159584 | |
| 159383 | 159585 | p->rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg, |
| | @@ -159390,49 +159592,49 @@ |
| 159390 | 159592 | ** statement reads is page 1, which is guaranteed to be in the cache. |
| 159391 | 159593 | ** And no memory allocations are required. */ |
| 159392 | 159594 | if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 159393 | 159595 | iCookie = sqlite3_column_int(pStmt, 0); |
| 159394 | 159596 | } |
| 159395 | | - otaFinalize(p, pStmt); |
| 159597 | + rbuFinalize(p, pStmt); |
| 159396 | 159598 | } |
| 159397 | 159599 | if( p->rc==SQLITE_OK ){ |
| 159398 | | - otaMPrintfExec(p, p->dbMain, "PRAGMA schema_version = %d", iCookie+1); |
| 159600 | + rbuMPrintfExec(p, p->dbMain, "PRAGMA schema_version = %d", iCookie+1); |
| 159399 | 159601 | } |
| 159400 | 159602 | } |
| 159401 | 159603 | } |
| 159402 | 159604 | |
| 159403 | 159605 | /* |
| 159404 | | -** Update the contents of the ota_state table within the ota database. The |
| 159405 | | -** value stored in the OTA_STATE_STAGE column is eStage. All other values |
| 159406 | | -** are determined by inspecting the ota handle passed as the first argument. |
| 159606 | +** Update the contents of the rbu_state table within the rbu database. The |
| 159607 | +** value stored in the RBU_STATE_STAGE column is eStage. All other values |
| 159608 | +** are determined by inspecting the rbu handle passed as the first argument. |
| 159407 | 159609 | */ |
| 159408 | | -static void otaSaveState(sqlite3ota *p, int eStage){ |
| 159610 | +static void rbuSaveState(sqlite3rbu *p, int eStage){ |
| 159409 | 159611 | if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){ |
| 159410 | 159612 | sqlite3_stmt *pInsert = 0; |
| 159411 | 159613 | int rc; |
| 159412 | 159614 | |
| 159413 | 159615 | assert( p->zErrmsg==0 ); |
| 159414 | | - rc = prepareFreeAndCollectError(p->dbOta, &pInsert, &p->zErrmsg, |
| 159616 | + rc = prepareFreeAndCollectError(p->dbRbu, &pInsert, &p->zErrmsg, |
| 159415 | 159617 | sqlite3_mprintf( |
| 159416 | | - "INSERT OR REPLACE INTO %s.ota_state(k, v) VALUES " |
| 159618 | + "INSERT OR REPLACE INTO %s.rbu_state(k, v) VALUES " |
| 159417 | 159619 | "(%d, %d), " |
| 159418 | 159620 | "(%d, %Q), " |
| 159419 | 159621 | "(%d, %Q), " |
| 159420 | 159622 | "(%d, %d), " |
| 159421 | 159623 | "(%d, %d), " |
| 159422 | 159624 | "(%d, %lld), " |
| 159423 | 159625 | "(%d, %lld), " |
| 159424 | 159626 | "(%d, %lld) ", |
| 159425 | 159627 | p->zStateDb, |
| 159426 | | - OTA_STATE_STAGE, eStage, |
| 159427 | | - OTA_STATE_TBL, p->objiter.zTbl, |
| 159428 | | - OTA_STATE_IDX, p->objiter.zIdx, |
| 159429 | | - OTA_STATE_ROW, p->nStep, |
| 159430 | | - OTA_STATE_PROGRESS, p->nProgress, |
| 159431 | | - OTA_STATE_CKPT, p->iWalCksum, |
| 159432 | | - OTA_STATE_COOKIE, (i64)p->pTargetFd->iCookie, |
| 159433 | | - OTA_STATE_OALSZ, p->iOalSz |
| 159628 | + RBU_STATE_STAGE, eStage, |
| 159629 | + RBU_STATE_TBL, p->objiter.zTbl, |
| 159630 | + RBU_STATE_IDX, p->objiter.zIdx, |
| 159631 | + RBU_STATE_ROW, p->nStep, |
| 159632 | + RBU_STATE_PROGRESS, p->nProgress, |
| 159633 | + RBU_STATE_CKPT, p->iWalCksum, |
| 159634 | + RBU_STATE_COOKIE, (i64)p->pTargetFd->iCookie, |
| 159635 | + RBU_STATE_OALSZ, p->iOalSz |
| 159434 | 159636 | ) |
| 159435 | 159637 | ); |
| 159436 | 159638 | assert( pInsert==0 || rc==SQLITE_OK ); |
| 159437 | 159639 | |
| 159438 | 159640 | if( rc==SQLITE_OK ){ |
| | @@ -159443,71 +159645,71 @@ |
| 159443 | 159645 | } |
| 159444 | 159646 | } |
| 159445 | 159647 | |
| 159446 | 159648 | |
| 159447 | 159649 | /* |
| 159448 | | -** Step the OTA object. |
| 159650 | +** Step the RBU object. |
| 159449 | 159651 | */ |
| 159450 | | -SQLITE_API int SQLITE_STDCALL sqlite3ota_step(sqlite3ota *p){ |
| 159652 | +SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *p){ |
| 159451 | 159653 | if( p ){ |
| 159452 | 159654 | switch( p->eStage ){ |
| 159453 | | - case OTA_STAGE_OAL: { |
| 159454 | | - OtaObjIter *pIter = &p->objiter; |
| 159655 | + case RBU_STAGE_OAL: { |
| 159656 | + RbuObjIter *pIter = &p->objiter; |
| 159455 | 159657 | while( p->rc==SQLITE_OK && pIter->zTbl ){ |
| 159456 | 159658 | |
| 159457 | 159659 | if( pIter->bCleanup ){ |
| 159458 | | - /* Clean up the ota_tmp_xxx table for the previous table. It |
| 159660 | + /* Clean up the rbu_tmp_xxx table for the previous table. It |
| 159459 | 159661 | ** cannot be dropped as there are currently active SQL statements. |
| 159460 | 159662 | ** But the contents can be deleted. */ |
| 159461 | 159663 | if( pIter->abIndexed ){ |
| 159462 | | - otaMPrintfExec(p, p->dbOta, |
| 159463 | | - "DELETE FROM %s.'ota_tmp_%q'", p->zStateDb, pIter->zTbl |
| 159664 | + rbuMPrintfExec(p, p->dbRbu, |
| 159665 | + "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zTbl |
| 159464 | 159666 | ); |
| 159465 | 159667 | } |
| 159466 | 159668 | }else{ |
| 159467 | | - otaObjIterPrepareAll(p, pIter, 0); |
| 159669 | + rbuObjIterPrepareAll(p, pIter, 0); |
| 159468 | 159670 | |
| 159469 | 159671 | /* Advance to the next row to process. */ |
| 159470 | 159672 | if( p->rc==SQLITE_OK ){ |
| 159471 | 159673 | int rc = sqlite3_step(pIter->pSelect); |
| 159472 | 159674 | if( rc==SQLITE_ROW ){ |
| 159473 | 159675 | p->nProgress++; |
| 159474 | 159676 | p->nStep++; |
| 159475 | | - return otaStep(p); |
| 159677 | + return rbuStep(p); |
| 159476 | 159678 | } |
| 159477 | 159679 | p->rc = sqlite3_reset(pIter->pSelect); |
| 159478 | 159680 | p->nStep = 0; |
| 159479 | 159681 | } |
| 159480 | 159682 | } |
| 159481 | 159683 | |
| 159482 | | - otaObjIterNext(p, pIter); |
| 159684 | + rbuObjIterNext(p, pIter); |
| 159483 | 159685 | } |
| 159484 | 159686 | |
| 159485 | 159687 | if( p->rc==SQLITE_OK ){ |
| 159486 | 159688 | assert( pIter->zTbl==0 ); |
| 159487 | | - otaSaveState(p, OTA_STAGE_MOVE); |
| 159488 | | - otaIncrSchemaCookie(p); |
| 159689 | + rbuSaveState(p, RBU_STAGE_MOVE); |
| 159690 | + rbuIncrSchemaCookie(p); |
| 159489 | 159691 | if( p->rc==SQLITE_OK ){ |
| 159490 | 159692 | p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg); |
| 159491 | 159693 | } |
| 159492 | 159694 | if( p->rc==SQLITE_OK ){ |
| 159493 | | - p->rc = sqlite3_exec(p->dbOta, "COMMIT", 0, 0, &p->zErrmsg); |
| 159494 | | - } |
| 159495 | | - p->eStage = OTA_STAGE_MOVE; |
| 159496 | | - } |
| 159497 | | - break; |
| 159498 | | - } |
| 159499 | | - |
| 159500 | | - case OTA_STAGE_MOVE: { |
| 159695 | + p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg); |
| 159696 | + } |
| 159697 | + p->eStage = RBU_STAGE_MOVE; |
| 159698 | + } |
| 159699 | + break; |
| 159700 | + } |
| 159701 | + |
| 159702 | + case RBU_STAGE_MOVE: { |
| 159501 | 159703 | if( p->rc==SQLITE_OK ){ |
| 159502 | | - otaMoveOalFile(p); |
| 159704 | + rbuMoveOalFile(p); |
| 159503 | 159705 | p->nProgress++; |
| 159504 | 159706 | } |
| 159505 | 159707 | break; |
| 159506 | 159708 | } |
| 159507 | 159709 | |
| 159508 | | - case OTA_STAGE_CKPT: { |
| 159710 | + case RBU_STAGE_CKPT: { |
| 159509 | 159711 | if( p->rc==SQLITE_OK ){ |
| 159510 | 159712 | if( p->nStep>=p->nFrame ){ |
| 159511 | 159713 | sqlite3_file *pDb = p->pTargetFd->pReal; |
| 159512 | 159714 | |
| 159513 | 159715 | /* Sync the db file */ |
| | @@ -159521,16 +159723,16 @@ |
| 159521 | 159723 | ((u32 volatile*)ptr)[24] = p->iMaxFrame; |
| 159522 | 159724 | } |
| 159523 | 159725 | } |
| 159524 | 159726 | |
| 159525 | 159727 | if( p->rc==SQLITE_OK ){ |
| 159526 | | - p->eStage = OTA_STAGE_DONE; |
| 159728 | + p->eStage = RBU_STAGE_DONE; |
| 159527 | 159729 | p->rc = SQLITE_DONE; |
| 159528 | 159730 | } |
| 159529 | 159731 | }else{ |
| 159530 | | - OtaFrame *pFrame = &p->aFrame[p->nStep]; |
| 159531 | | - otaCheckpointFrame(p, pFrame); |
| 159732 | + RbuFrame *pFrame = &p->aFrame[p->nStep]; |
| 159733 | + rbuCheckpointFrame(p, pFrame); |
| 159532 | 159734 | p->nStep++; |
| 159533 | 159735 | } |
| 159534 | 159736 | p->nProgress++; |
| 159535 | 159737 | } |
| 159536 | 159738 | break; |
| | @@ -159544,78 +159746,78 @@ |
| 159544 | 159746 | return SQLITE_NOMEM; |
| 159545 | 159747 | } |
| 159546 | 159748 | } |
| 159547 | 159749 | |
| 159548 | 159750 | /* |
| 159549 | | -** Free an OtaState object allocated by otaLoadState(). |
| 159751 | +** Free an RbuState object allocated by rbuLoadState(). |
| 159550 | 159752 | */ |
| 159551 | | -static void otaFreeState(OtaState *p){ |
| 159753 | +static void rbuFreeState(RbuState *p){ |
| 159552 | 159754 | if( p ){ |
| 159553 | 159755 | sqlite3_free(p->zTbl); |
| 159554 | 159756 | sqlite3_free(p->zIdx); |
| 159555 | 159757 | sqlite3_free(p); |
| 159556 | 159758 | } |
| 159557 | 159759 | } |
| 159558 | 159760 | |
| 159559 | 159761 | /* |
| 159560 | | -** Allocate an OtaState object and load the contents of the ota_state |
| 159762 | +** Allocate an RbuState object and load the contents of the rbu_state |
| 159561 | 159763 | ** table into it. Return a pointer to the new object. It is the |
| 159562 | 159764 | ** responsibility of the caller to eventually free the object using |
| 159563 | 159765 | ** sqlite3_free(). |
| 159564 | 159766 | ** |
| 159565 | | -** If an error occurs, leave an error code and message in the ota handle |
| 159767 | +** If an error occurs, leave an error code and message in the rbu handle |
| 159566 | 159768 | ** and return NULL. |
| 159567 | 159769 | */ |
| 159568 | | -static OtaState *otaLoadState(sqlite3ota *p){ |
| 159569 | | - OtaState *pRet = 0; |
| 159770 | +static RbuState *rbuLoadState(sqlite3rbu *p){ |
| 159771 | + RbuState *pRet = 0; |
| 159570 | 159772 | sqlite3_stmt *pStmt = 0; |
| 159571 | 159773 | int rc; |
| 159572 | 159774 | int rc2; |
| 159573 | 159775 | |
| 159574 | | - pRet = (OtaState*)otaMalloc(p, sizeof(OtaState)); |
| 159776 | + pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState)); |
| 159575 | 159777 | if( pRet==0 ) return 0; |
| 159576 | 159778 | |
| 159577 | | - rc = prepareFreeAndCollectError(p->dbOta, &pStmt, &p->zErrmsg, |
| 159578 | | - sqlite3_mprintf("SELECT k, v FROM %s.ota_state", p->zStateDb) |
| 159779 | + rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg, |
| 159780 | + sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb) |
| 159579 | 159781 | ); |
| 159580 | 159782 | while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 159581 | 159783 | switch( sqlite3_column_int(pStmt, 0) ){ |
| 159582 | | - case OTA_STATE_STAGE: |
| 159784 | + case RBU_STATE_STAGE: |
| 159583 | 159785 | pRet->eStage = sqlite3_column_int(pStmt, 1); |
| 159584 | | - if( pRet->eStage!=OTA_STAGE_OAL |
| 159585 | | - && pRet->eStage!=OTA_STAGE_MOVE |
| 159586 | | - && pRet->eStage!=OTA_STAGE_CKPT |
| 159786 | + if( pRet->eStage!=RBU_STAGE_OAL |
| 159787 | + && pRet->eStage!=RBU_STAGE_MOVE |
| 159788 | + && pRet->eStage!=RBU_STAGE_CKPT |
| 159587 | 159789 | ){ |
| 159588 | 159790 | p->rc = SQLITE_CORRUPT; |
| 159589 | 159791 | } |
| 159590 | 159792 | break; |
| 159591 | 159793 | |
| 159592 | | - case OTA_STATE_TBL: |
| 159593 | | - pRet->zTbl = otaStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); |
| 159794 | + case RBU_STATE_TBL: |
| 159795 | + pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); |
| 159594 | 159796 | break; |
| 159595 | 159797 | |
| 159596 | | - case OTA_STATE_IDX: |
| 159597 | | - pRet->zIdx = otaStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); |
| 159798 | + case RBU_STATE_IDX: |
| 159799 | + pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); |
| 159598 | 159800 | break; |
| 159599 | 159801 | |
| 159600 | | - case OTA_STATE_ROW: |
| 159802 | + case RBU_STATE_ROW: |
| 159601 | 159803 | pRet->nRow = sqlite3_column_int(pStmt, 1); |
| 159602 | 159804 | break; |
| 159603 | 159805 | |
| 159604 | | - case OTA_STATE_PROGRESS: |
| 159806 | + case RBU_STATE_PROGRESS: |
| 159605 | 159807 | pRet->nProgress = sqlite3_column_int64(pStmt, 1); |
| 159606 | 159808 | break; |
| 159607 | 159809 | |
| 159608 | | - case OTA_STATE_CKPT: |
| 159810 | + case RBU_STATE_CKPT: |
| 159609 | 159811 | pRet->iWalCksum = sqlite3_column_int64(pStmt, 1); |
| 159610 | 159812 | break; |
| 159611 | 159813 | |
| 159612 | | - case OTA_STATE_COOKIE: |
| 159814 | + case RBU_STATE_COOKIE: |
| 159613 | 159815 | pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1); |
| 159614 | 159816 | break; |
| 159615 | 159817 | |
| 159616 | | - case OTA_STATE_OALSZ: |
| 159818 | + case RBU_STATE_OALSZ: |
| 159617 | 159819 | pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1); |
| 159618 | 159820 | break; |
| 159619 | 159821 | |
| 159620 | 159822 | default: |
| 159621 | 159823 | rc = SQLITE_CORRUPT; |
| | @@ -159632,142 +159834,142 @@ |
| 159632 | 159834 | /* |
| 159633 | 159835 | ** Compare strings z1 and z2, returning 0 if they are identical, or non-zero |
| 159634 | 159836 | ** otherwise. Either or both argument may be NULL. Two NULL values are |
| 159635 | 159837 | ** considered equal, and NULL is considered distinct from all other values. |
| 159636 | 159838 | */ |
| 159637 | | -static int otaStrCompare(const char *z1, const char *z2){ |
| 159839 | +static int rbuStrCompare(const char *z1, const char *z2){ |
| 159638 | 159840 | if( z1==0 && z2==0 ) return 0; |
| 159639 | 159841 | if( z1==0 || z2==0 ) return 1; |
| 159640 | 159842 | return (sqlite3_stricmp(z1, z2)!=0); |
| 159641 | 159843 | } |
| 159642 | 159844 | |
| 159643 | 159845 | /* |
| 159644 | | -** This function is called as part of sqlite3ota_open() when initializing |
| 159645 | | -** an ota handle in OAL stage. If the ota update has not started (i.e. |
| 159646 | | -** the ota_state table was empty) it is a no-op. Otherwise, it arranges |
| 159647 | | -** things so that the next call to sqlite3ota_step() continues on from |
| 159648 | | -** where the previous ota handle left off. |
| 159846 | +** This function is called as part of sqlite3rbu_open() when initializing |
| 159847 | +** an rbu handle in OAL stage. If the rbu update has not started (i.e. |
| 159848 | +** the rbu_state table was empty) it is a no-op. Otherwise, it arranges |
| 159849 | +** things so that the next call to sqlite3rbu_step() continues on from |
| 159850 | +** where the previous rbu handle left off. |
| 159649 | 159851 | ** |
| 159650 | 159852 | ** If an error occurs, an error code and error message are left in the |
| 159651 | | -** ota handle passed as the first argument. |
| 159853 | +** rbu handle passed as the first argument. |
| 159652 | 159854 | */ |
| 159653 | | -static void otaSetupOal(sqlite3ota *p, OtaState *pState){ |
| 159855 | +static void rbuSetupOal(sqlite3rbu *p, RbuState *pState){ |
| 159654 | 159856 | assert( p->rc==SQLITE_OK ); |
| 159655 | 159857 | if( pState->zTbl ){ |
| 159656 | | - OtaObjIter *pIter = &p->objiter; |
| 159858 | + RbuObjIter *pIter = &p->objiter; |
| 159657 | 159859 | int rc = SQLITE_OK; |
| 159658 | 159860 | |
| 159659 | 159861 | while( rc==SQLITE_OK && pIter->zTbl && (pIter->bCleanup |
| 159660 | | - || otaStrCompare(pIter->zIdx, pState->zIdx) |
| 159661 | | - || otaStrCompare(pIter->zTbl, pState->zTbl) |
| 159862 | + || rbuStrCompare(pIter->zIdx, pState->zIdx) |
| 159863 | + || rbuStrCompare(pIter->zTbl, pState->zTbl) |
| 159662 | 159864 | )){ |
| 159663 | | - rc = otaObjIterNext(p, pIter); |
| 159865 | + rc = rbuObjIterNext(p, pIter); |
| 159664 | 159866 | } |
| 159665 | 159867 | |
| 159666 | 159868 | if( rc==SQLITE_OK && !pIter->zTbl ){ |
| 159667 | 159869 | rc = SQLITE_ERROR; |
| 159668 | | - p->zErrmsg = sqlite3_mprintf("ota_state mismatch error"); |
| 159870 | + p->zErrmsg = sqlite3_mprintf("rbu_state mismatch error"); |
| 159669 | 159871 | } |
| 159670 | 159872 | |
| 159671 | 159873 | if( rc==SQLITE_OK ){ |
| 159672 | 159874 | p->nStep = pState->nRow; |
| 159673 | | - rc = otaObjIterPrepareAll(p, &p->objiter, p->nStep); |
| 159875 | + rc = rbuObjIterPrepareAll(p, &p->objiter, p->nStep); |
| 159674 | 159876 | } |
| 159675 | 159877 | |
| 159676 | 159878 | p->rc = rc; |
| 159677 | 159879 | } |
| 159678 | 159880 | } |
| 159679 | 159881 | |
| 159680 | 159882 | /* |
| 159681 | 159883 | ** If there is a "*-oal" file in the file-system corresponding to the |
| 159682 | 159884 | ** target database in the file-system, delete it. If an error occurs, |
| 159683 | | -** leave an error code and error message in the ota handle. |
| 159885 | +** leave an error code and error message in the rbu handle. |
| 159684 | 159886 | */ |
| 159685 | | -static void otaDeleteOalFile(sqlite3ota *p){ |
| 159887 | +static void rbuDeleteOalFile(sqlite3rbu *p){ |
| 159686 | 159888 | char *zOal = sqlite3_mprintf("%s-oal", p->zTarget); |
| 159687 | 159889 | assert( p->rc==SQLITE_OK && p->zErrmsg==0 ); |
| 159688 | 159890 | unlink(zOal); |
| 159689 | 159891 | sqlite3_free(zOal); |
| 159690 | 159892 | } |
| 159691 | 159893 | |
| 159692 | 159894 | /* |
| 159693 | | -** Allocate a private ota VFS for the ota handle passed as the only |
| 159694 | | -** argument. This VFS will be used unless the call to sqlite3ota_open() |
| 159895 | +** Allocate a private rbu VFS for the rbu handle passed as the only |
| 159896 | +** argument. This VFS will be used unless the call to sqlite3rbu_open() |
| 159695 | 159897 | ** specified a URI with a vfs=? option in place of a target database |
| 159696 | 159898 | ** file name. |
| 159697 | 159899 | */ |
| 159698 | | -static void otaCreateVfs(sqlite3ota *p){ |
| 159900 | +static void rbuCreateVfs(sqlite3rbu *p){ |
| 159699 | 159901 | int rnd; |
| 159700 | 159902 | char zRnd[64]; |
| 159701 | 159903 | |
| 159702 | 159904 | assert( p->rc==SQLITE_OK ); |
| 159703 | 159905 | sqlite3_randomness(sizeof(int), (void*)&rnd); |
| 159704 | | - sprintf(zRnd, "ota_vfs_%d", rnd); |
| 159705 | | - p->rc = sqlite3ota_create_vfs(zRnd, 0); |
| 159906 | + sprintf(zRnd, "rbu_vfs_%d", rnd); |
| 159907 | + p->rc = sqlite3rbu_create_vfs(zRnd, 0); |
| 159706 | 159908 | if( p->rc==SQLITE_OK ){ |
| 159707 | 159909 | sqlite3_vfs *pVfs = sqlite3_vfs_find(zRnd); |
| 159708 | 159910 | assert( pVfs ); |
| 159709 | 159911 | p->zVfsName = pVfs->zName; |
| 159710 | 159912 | } |
| 159711 | 159913 | } |
| 159712 | 159914 | |
| 159713 | 159915 | /* |
| 159714 | | -** Destroy the private VFS created for the ota handle passed as the only |
| 159715 | | -** argument by an earlier call to otaCreateVfs(). |
| 159916 | +** Destroy the private VFS created for the rbu handle passed as the only |
| 159917 | +** argument by an earlier call to rbuCreateVfs(). |
| 159716 | 159918 | */ |
| 159717 | | -static void otaDeleteVfs(sqlite3ota *p){ |
| 159919 | +static void rbuDeleteVfs(sqlite3rbu *p){ |
| 159718 | 159920 | if( p->zVfsName ){ |
| 159719 | | - sqlite3ota_destroy_vfs(p->zVfsName); |
| 159921 | + sqlite3rbu_destroy_vfs(p->zVfsName); |
| 159720 | 159922 | p->zVfsName = 0; |
| 159721 | 159923 | } |
| 159722 | 159924 | } |
| 159723 | 159925 | |
| 159724 | 159926 | /* |
| 159725 | | -** Open and return a new OTA handle. |
| 159927 | +** Open and return a new RBU handle. |
| 159726 | 159928 | */ |
| 159727 | | -SQLITE_API sqlite3ota *SQLITE_STDCALL sqlite3ota_open( |
| 159929 | +SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open( |
| 159728 | 159930 | const char *zTarget, |
| 159729 | | - const char *zOta, |
| 159931 | + const char *zRbu, |
| 159730 | 159932 | const char *zState |
| 159731 | 159933 | ){ |
| 159732 | | - sqlite3ota *p; |
| 159934 | + sqlite3rbu *p; |
| 159733 | 159935 | int nTarget = strlen(zTarget); |
| 159734 | | - int nOta = strlen(zOta); |
| 159936 | + int nRbu = strlen(zRbu); |
| 159735 | 159937 | int nState = zState ? strlen(zState) : 0; |
| 159736 | 159938 | |
| 159737 | | - p = (sqlite3ota*)sqlite3_malloc(sizeof(sqlite3ota)+nTarget+1+nOta+1+nState+1); |
| 159939 | + p = (sqlite3rbu*)sqlite3_malloc(sizeof(sqlite3rbu)+nTarget+1+nRbu+1+nState+1); |
| 159738 | 159940 | if( p ){ |
| 159739 | | - OtaState *pState = 0; |
| 159941 | + RbuState *pState = 0; |
| 159740 | 159942 | |
| 159741 | 159943 | /* Create the custom VFS. */ |
| 159742 | | - memset(p, 0, sizeof(sqlite3ota)); |
| 159743 | | - otaCreateVfs(p); |
| 159944 | + memset(p, 0, sizeof(sqlite3rbu)); |
| 159945 | + rbuCreateVfs(p); |
| 159744 | 159946 | |
| 159745 | 159947 | /* Open the target database */ |
| 159746 | 159948 | if( p->rc==SQLITE_OK ){ |
| 159747 | 159949 | p->zTarget = (char*)&p[1]; |
| 159748 | 159950 | memcpy(p->zTarget, zTarget, nTarget+1); |
| 159749 | | - p->zOta = &p->zTarget[nTarget+1]; |
| 159750 | | - memcpy(p->zOta, zOta, nOta+1); |
| 159951 | + p->zRbu = &p->zTarget[nTarget+1]; |
| 159952 | + memcpy(p->zRbu, zRbu, nRbu+1); |
| 159751 | 159953 | if( zState ){ |
| 159752 | | - p->zState = &p->zOta[nOta+1]; |
| 159954 | + p->zState = &p->zRbu[nRbu+1]; |
| 159753 | 159955 | memcpy(p->zState, zState, nState+1); |
| 159754 | 159956 | } |
| 159755 | | - otaOpenDatabase(p); |
| 159957 | + rbuOpenDatabase(p); |
| 159756 | 159958 | } |
| 159757 | 159959 | |
| 159758 | | - /* If it has not already been created, create the ota_state table */ |
| 159759 | | - otaMPrintfExec(p, p->dbOta, OTA_CREATE_STATE, p->zStateDb); |
| 159960 | + /* If it has not already been created, create the rbu_state table */ |
| 159961 | + rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb); |
| 159760 | 159962 | |
| 159761 | 159963 | if( p->rc==SQLITE_OK ){ |
| 159762 | | - pState = otaLoadState(p); |
| 159964 | + pState = rbuLoadState(p); |
| 159763 | 159965 | assert( pState || p->rc!=SQLITE_OK ); |
| 159764 | 159966 | if( p->rc==SQLITE_OK ){ |
| 159765 | 159967 | |
| 159766 | 159968 | if( pState->eStage==0 ){ |
| 159767 | | - otaDeleteOalFile(p); |
| 159768 | | - p->eStage = OTA_STAGE_OAL; |
| 159969 | + rbuDeleteOalFile(p); |
| 159970 | + p->eStage = RBU_STAGE_OAL; |
| 159769 | 159971 | }else{ |
| 159770 | 159972 | p->eStage = pState->eStage; |
| 159771 | 159973 | } |
| 159772 | 159974 | p->nProgress = pState->nProgress; |
| 159773 | 159975 | p->iOalSz = pState->iOalSz; |
| | @@ -159774,97 +159976,97 @@ |
| 159774 | 159976 | } |
| 159775 | 159977 | } |
| 159776 | 159978 | assert( p->rc!=SQLITE_OK || p->eStage!=0 ); |
| 159777 | 159979 | |
| 159778 | 159980 | if( p->rc==SQLITE_OK && p->pTargetFd->pWalFd ){ |
| 159779 | | - if( p->eStage==OTA_STAGE_OAL ){ |
| 159981 | + if( p->eStage==RBU_STAGE_OAL ){ |
| 159780 | 159982 | p->rc = SQLITE_ERROR; |
| 159781 | 159983 | p->zErrmsg = sqlite3_mprintf("cannot update wal mode database"); |
| 159782 | | - }else if( p->eStage==OTA_STAGE_MOVE ){ |
| 159783 | | - p->eStage = OTA_STAGE_CKPT; |
| 159984 | + }else if( p->eStage==RBU_STAGE_MOVE ){ |
| 159985 | + p->eStage = RBU_STAGE_CKPT; |
| 159784 | 159986 | p->nStep = 0; |
| 159785 | 159987 | } |
| 159786 | 159988 | } |
| 159787 | 159989 | |
| 159788 | 159990 | if( p->rc==SQLITE_OK |
| 159789 | | - && (p->eStage==OTA_STAGE_OAL || p->eStage==OTA_STAGE_MOVE) |
| 159991 | + && (p->eStage==RBU_STAGE_OAL || p->eStage==RBU_STAGE_MOVE) |
| 159790 | 159992 | && pState->eStage!=0 && p->pTargetFd->iCookie!=pState->iCookie |
| 159791 | 159993 | ){ |
| 159792 | 159994 | /* At this point (pTargetFd->iCookie) contains the value of the |
| 159793 | 159995 | ** change-counter cookie (the thing that gets incremented when a |
| 159794 | 159996 | ** transaction is committed in rollback mode) currently stored on |
| 159795 | 159997 | ** page 1 of the database file. */ |
| 159796 | 159998 | p->rc = SQLITE_BUSY; |
| 159797 | | - p->zErrmsg = sqlite3_mprintf("database modified during ota update"); |
| 159999 | + p->zErrmsg = sqlite3_mprintf("database modified during rbu update"); |
| 159798 | 160000 | } |
| 159799 | 160001 | |
| 159800 | 160002 | if( p->rc==SQLITE_OK ){ |
| 159801 | | - if( p->eStage==OTA_STAGE_OAL ){ |
| 160003 | + if( p->eStage==RBU_STAGE_OAL ){ |
| 159802 | 160004 | |
| 159803 | 160005 | /* Open transactions both databases. The *-oal file is opened or |
| 159804 | 160006 | ** created at this point. */ |
| 159805 | 160007 | p->rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg); |
| 159806 | 160008 | if( p->rc==SQLITE_OK ){ |
| 159807 | | - p->rc = sqlite3_exec(p->dbOta, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg); |
| 160009 | + p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg); |
| 159808 | 160010 | } |
| 159809 | 160011 | |
| 159810 | 160012 | /* Point the object iterator at the first object */ |
| 159811 | 160013 | if( p->rc==SQLITE_OK ){ |
| 159812 | | - p->rc = otaObjIterFirst(p, &p->objiter); |
| 160014 | + p->rc = rbuObjIterFirst(p, &p->objiter); |
| 159813 | 160015 | } |
| 159814 | 160016 | |
| 159815 | | - /* If the OTA database contains no data_xxx tables, declare the OTA |
| 160017 | + /* If the RBU database contains no data_xxx tables, declare the RBU |
| 159816 | 160018 | ** update finished. */ |
| 159817 | 160019 | if( p->rc==SQLITE_OK && p->objiter.zTbl==0 ){ |
| 159818 | 160020 | p->rc = SQLITE_DONE; |
| 159819 | 160021 | } |
| 159820 | 160022 | |
| 159821 | 160023 | if( p->rc==SQLITE_OK ){ |
| 159822 | | - otaSetupOal(p, pState); |
| 160024 | + rbuSetupOal(p, pState); |
| 159823 | 160025 | } |
| 159824 | 160026 | |
| 159825 | | - }else if( p->eStage==OTA_STAGE_MOVE ){ |
| 160027 | + }else if( p->eStage==RBU_STAGE_MOVE ){ |
| 159826 | 160028 | /* no-op */ |
| 159827 | | - }else if( p->eStage==OTA_STAGE_CKPT ){ |
| 159828 | | - otaSetupCheckpoint(p, pState); |
| 159829 | | - }else if( p->eStage==OTA_STAGE_DONE ){ |
| 160029 | + }else if( p->eStage==RBU_STAGE_CKPT ){ |
| 160030 | + rbuSetupCheckpoint(p, pState); |
| 160031 | + }else if( p->eStage==RBU_STAGE_DONE ){ |
| 159830 | 160032 | p->rc = SQLITE_DONE; |
| 159831 | 160033 | }else{ |
| 159832 | 160034 | p->rc = SQLITE_CORRUPT; |
| 159833 | 160035 | } |
| 159834 | 160036 | } |
| 159835 | 160037 | |
| 159836 | | - otaFreeState(pState); |
| 160038 | + rbuFreeState(pState); |
| 159837 | 160039 | } |
| 159838 | 160040 | |
| 159839 | 160041 | return p; |
| 159840 | 160042 | } |
| 159841 | 160043 | |
| 159842 | 160044 | |
| 159843 | 160045 | /* |
| 159844 | | -** Return the database handle used by pOta. |
| 160046 | +** Return the database handle used by pRbu. |
| 159845 | 160047 | */ |
| 159846 | | -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3ota_db(sqlite3ota *pOta, int bOta){ |
| 160048 | +SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){ |
| 159847 | 160049 | sqlite3 *db = 0; |
| 159848 | | - if( pOta ){ |
| 159849 | | - db = (bOta ? pOta->dbOta : pOta->dbMain); |
| 160050 | + if( pRbu ){ |
| 160051 | + db = (bRbu ? pRbu->dbRbu : pRbu->dbMain); |
| 159850 | 160052 | } |
| 159851 | 160053 | return db; |
| 159852 | 160054 | } |
| 159853 | 160055 | |
| 159854 | 160056 | |
| 159855 | 160057 | /* |
| 159856 | | -** If the error code currently stored in the OTA handle is SQLITE_CONSTRAINT, |
| 160058 | +** If the error code currently stored in the RBU handle is SQLITE_CONSTRAINT, |
| 159857 | 160059 | ** then edit any error message string so as to remove all occurrences of |
| 159858 | | -** the pattern "ota_imp_[0-9]*". |
| 160060 | +** the pattern "rbu_imp_[0-9]*". |
| 159859 | 160061 | */ |
| 159860 | | -static void otaEditErrmsg(sqlite3ota *p){ |
| 160062 | +static void rbuEditErrmsg(sqlite3rbu *p){ |
| 159861 | 160063 | if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){ |
| 159862 | 160064 | int i; |
| 159863 | 160065 | int nErrmsg = strlen(p->zErrmsg); |
| 159864 | 160066 | for(i=0; i<(nErrmsg-8); i++){ |
| 159865 | | - if( memcmp(&p->zErrmsg[i], "ota_imp_", 8)==0 ){ |
| 160067 | + if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){ |
| 159866 | 160068 | int nDel = 8; |
| 159867 | 160069 | while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++; |
| 159868 | 160070 | memmove(&p->zErrmsg[i], &p->zErrmsg[i+nDel], nErrmsg + 1 - i - nDel); |
| 159869 | 160071 | nErrmsg -= nDel; |
| 159870 | 160072 | } |
| | @@ -159871,38 +160073,38 @@ |
| 159871 | 160073 | } |
| 159872 | 160074 | } |
| 159873 | 160075 | } |
| 159874 | 160076 | |
| 159875 | 160077 | /* |
| 159876 | | -** Close the OTA handle. |
| 160078 | +** Close the RBU handle. |
| 159877 | 160079 | */ |
| 159878 | | -SQLITE_API int SQLITE_STDCALL sqlite3ota_close(sqlite3ota *p, char **pzErrmsg){ |
| 160080 | +SQLITE_API int SQLITE_STDCALL sqlite3rbu_close(sqlite3rbu *p, char **pzErrmsg){ |
| 159879 | 160081 | int rc; |
| 159880 | 160082 | if( p ){ |
| 159881 | 160083 | |
| 159882 | 160084 | /* Commit the transaction to the *-oal file. */ |
| 159883 | | - if( p->rc==SQLITE_OK && p->eStage==OTA_STAGE_OAL ){ |
| 160085 | + if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){ |
| 159884 | 160086 | p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg); |
| 159885 | 160087 | } |
| 159886 | 160088 | |
| 159887 | | - otaSaveState(p, p->eStage); |
| 160089 | + rbuSaveState(p, p->eStage); |
| 159888 | 160090 | |
| 159889 | | - if( p->rc==SQLITE_OK && p->eStage==OTA_STAGE_OAL ){ |
| 159890 | | - p->rc = sqlite3_exec(p->dbOta, "COMMIT", 0, 0, &p->zErrmsg); |
| 160091 | + if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){ |
| 160092 | + p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg); |
| 159891 | 160093 | } |
| 159892 | 160094 | |
| 159893 | 160095 | /* Close any open statement handles. */ |
| 159894 | | - otaObjIterFinalize(&p->objiter); |
| 160096 | + rbuObjIterFinalize(&p->objiter); |
| 159895 | 160097 | |
| 159896 | 160098 | /* Close the open database handle and VFS object. */ |
| 159897 | 160099 | sqlite3_close(p->dbMain); |
| 159898 | | - sqlite3_close(p->dbOta); |
| 159899 | | - otaDeleteVfs(p); |
| 160100 | + sqlite3_close(p->dbRbu); |
| 160101 | + rbuDeleteVfs(p); |
| 159900 | 160102 | sqlite3_free(p->aBuf); |
| 159901 | 160103 | sqlite3_free(p->aFrame); |
| 159902 | 160104 | |
| 159903 | | - otaEditErrmsg(p); |
| 160105 | + rbuEditErrmsg(p); |
| 159904 | 160106 | rc = p->rc; |
| 159905 | 160107 | *pzErrmsg = p->zErrmsg; |
| 159906 | 160108 | sqlite3_free(p); |
| 159907 | 160109 | }else{ |
| 159908 | 160110 | rc = SQLITE_NOMEM; |
| | @@ -159912,65 +160114,65 @@ |
| 159912 | 160114 | } |
| 159913 | 160115 | |
| 159914 | 160116 | /* |
| 159915 | 160117 | ** Return the total number of key-value operations (inserts, deletes or |
| 159916 | 160118 | ** updates) that have been performed on the target database since the |
| 159917 | | -** current OTA update was started. |
| 160119 | +** current RBU update was started. |
| 159918 | 160120 | */ |
| 159919 | | -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3ota_progress(sqlite3ota *pOta){ |
| 159920 | | - return pOta->nProgress; |
| 160121 | +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3rbu_progress(sqlite3rbu *pRbu){ |
| 160122 | + return pRbu->nProgress; |
| 159921 | 160123 | } |
| 159922 | 160124 | |
| 159923 | 160125 | /************************************************************************** |
| 159924 | | -** Beginning of OTA VFS shim methods. The VFS shim modifies the behaviour |
| 160126 | +** Beginning of RBU VFS shim methods. The VFS shim modifies the behaviour |
| 159925 | 160127 | ** of a standard VFS in the following ways: |
| 159926 | 160128 | ** |
| 159927 | 160129 | ** 1. Whenever the first page of a main database file is read or |
| 159928 | 160130 | ** written, the value of the change-counter cookie is stored in |
| 159929 | | -** ota_file.iCookie. Similarly, the value of the "write-version" |
| 159930 | | -** database header field is stored in ota_file.iWriteVer. This ensures |
| 160131 | +** rbu_file.iCookie. Similarly, the value of the "write-version" |
| 160132 | +** database header field is stored in rbu_file.iWriteVer. This ensures |
| 159931 | 160133 | ** that the values are always trustworthy within an open transaction. |
| 159932 | 160134 | ** |
| 159933 | | -** 2. Whenever an SQLITE_OPEN_WAL file is opened, the (ota_file.pWalFd) |
| 160135 | +** 2. Whenever an SQLITE_OPEN_WAL file is opened, the (rbu_file.pWalFd) |
| 159934 | 160136 | ** member variable of the associated database file descriptor is set |
| 159935 | 160137 | ** to point to the new file. A mutex protected linked list of all main |
| 159936 | | -** db fds opened using a particular OTA VFS is maintained at |
| 159937 | | -** ota_vfs.pMain to facilitate this. |
| 160138 | +** db fds opened using a particular RBU VFS is maintained at |
| 160139 | +** rbu_vfs.pMain to facilitate this. |
| 159938 | 160140 | ** |
| 159939 | | -** 3. Using a new file-control "SQLITE_FCNTL_OTA", a main db ota_file |
| 159940 | | -** object can be marked as the target database of an OTA update. This |
| 160141 | +** 3. Using a new file-control "SQLITE_FCNTL_RBU", a main db rbu_file |
| 160142 | +** object can be marked as the target database of an RBU update. This |
| 159941 | 160143 | ** turns on the following extra special behaviour: |
| 159942 | 160144 | ** |
| 159943 | 160145 | ** 3a. If xAccess() is called to check if there exists a *-wal file |
| 159944 | | -** associated with an OTA target database currently in OTA_STAGE_OAL |
| 160146 | +** associated with an RBU target database currently in RBU_STAGE_OAL |
| 159945 | 160147 | ** stage (preparing the *-oal file), the following special handling |
| 159946 | 160148 | ** applies: |
| 159947 | 160149 | ** |
| 159948 | | -** * if the *-wal file does exist, return SQLITE_CANTOPEN. An OTA |
| 160150 | +** * if the *-wal file does exist, return SQLITE_CANTOPEN. An RBU |
| 159949 | 160151 | ** target database may not be in wal mode already. |
| 159950 | 160152 | ** |
| 159951 | 160153 | ** * if the *-wal file does not exist, set the output parameter to |
| 159952 | 160154 | ** non-zero (to tell SQLite that it does exist) anyway. |
| 159953 | 160155 | ** |
| 159954 | 160156 | ** Then, when xOpen() is called to open the *-wal file associated with |
| 159955 | | -** the OTA target in OTA_STAGE_OAL stage, instead of opening the *-wal |
| 159956 | | -** file, the ota vfs opens the corresponding *-oal file instead. |
| 160157 | +** the RBU target in RBU_STAGE_OAL stage, instead of opening the *-wal |
| 160158 | +** file, the rbu vfs opens the corresponding *-oal file instead. |
| 159957 | 160159 | ** |
| 159958 | 160160 | ** 3b. The *-shm pages returned by xShmMap() for a target db file in |
| 159959 | | -** OTA_STAGE_OAL mode are actually stored in heap memory. This is to |
| 160161 | +** RBU_STAGE_OAL mode are actually stored in heap memory. This is to |
| 159960 | 160162 | ** avoid creating a *-shm file on disk. Additionally, xShmLock() calls |
| 159961 | | -** are no-ops on target database files in OTA_STAGE_OAL mode. This is |
| 160163 | +** are no-ops on target database files in RBU_STAGE_OAL mode. This is |
| 159962 | 160164 | ** because assert() statements in some VFS implementations fail if |
| 159963 | 160165 | ** xShmLock() is called before xShmMap(). |
| 159964 | 160166 | ** |
| 159965 | 160167 | ** 3c. If an EXCLUSIVE lock is attempted on a target database file in any |
| 159966 | | -** mode except OTA_STAGE_DONE (all work completed and checkpointed), it |
| 159967 | | -** fails with an SQLITE_BUSY error. This is to stop OTA connections |
| 160168 | +** mode except RBU_STAGE_DONE (all work completed and checkpointed), it |
| 160169 | +** fails with an SQLITE_BUSY error. This is to stop RBU connections |
| 159968 | 160170 | ** from automatically checkpointing a *-wal (or *-oal) file from within |
| 159969 | 160171 | ** sqlite3_close(). |
| 159970 | 160172 | ** |
| 159971 | | -** 3d. In OTA_STAGE_CAPTURE mode, all xRead() calls on the wal file, and |
| 160173 | +** 3d. In RBU_STAGE_CAPTURE mode, all xRead() calls on the wal file, and |
| 159972 | 160174 | ** all xWrite() calls on the target database file perform no IO. |
| 159973 | 160175 | ** Instead the frame and page numbers that would be read and written |
| 159974 | 160176 | ** are recorded. Additionally, successful attempts to obtain exclusive |
| 159975 | 160177 | ** xShmLock() WRITER, CHECKPOINTER and READ0 locks on the target |
| 159976 | 160178 | ** database file are recorded. xShmLock() calls to unlock the same |
| | @@ -159977,28 +160179,28 @@ |
| 159977 | 160179 | ** locks are no-ops (so that once obtained, these locks are never |
| 159978 | 160180 | ** relinquished). Finally, calls to xSync() on the target database |
| 159979 | 160181 | ** file fail with SQLITE_INTERNAL errors. |
| 159980 | 160182 | */ |
| 159981 | 160183 | |
| 159982 | | -static void otaUnlockShm(ota_file *p){ |
| 159983 | | - if( p->pOta ){ |
| 160184 | +static void rbuUnlockShm(rbu_file *p){ |
| 160185 | + if( p->pRbu ){ |
| 159984 | 160186 | int (*xShmLock)(sqlite3_file*,int,int,int) = p->pReal->pMethods->xShmLock; |
| 159985 | 160187 | int i; |
| 159986 | 160188 | for(i=0; i<SQLITE_SHM_NLOCK;i++){ |
| 159987 | | - if( (1<<i) & p->pOta->mLock ){ |
| 160189 | + if( (1<<i) & p->pRbu->mLock ){ |
| 159988 | 160190 | xShmLock(p->pReal, i, 1, SQLITE_SHM_UNLOCK|SQLITE_SHM_EXCLUSIVE); |
| 159989 | 160191 | } |
| 159990 | 160192 | } |
| 159991 | | - p->pOta->mLock = 0; |
| 160193 | + p->pRbu->mLock = 0; |
| 159992 | 160194 | } |
| 159993 | 160195 | } |
| 159994 | 160196 | |
| 159995 | 160197 | /* |
| 159996 | | -** Close an ota file. |
| 160198 | +** Close an rbu file. |
| 159997 | 160199 | */ |
| 159998 | | -static int otaVfsClose(sqlite3_file *pFile){ |
| 159999 | | - ota_file *p = (ota_file*)pFile; |
| 160200 | +static int rbuVfsClose(sqlite3_file *pFile){ |
| 160201 | + rbu_file *p = (rbu_file*)pFile; |
| 160000 | 160202 | int rc; |
| 160001 | 160203 | int i; |
| 160002 | 160204 | |
| 160003 | 160205 | /* Free the contents of the apShm[] array. And the array itself. */ |
| 160004 | 160206 | for(i=0; i<p->nShm; i++){ |
| | @@ -160007,16 +160209,16 @@ |
| 160007 | 160209 | sqlite3_free(p->apShm); |
| 160008 | 160210 | p->apShm = 0; |
| 160009 | 160211 | sqlite3_free(p->zDel); |
| 160010 | 160212 | |
| 160011 | 160213 | if( p->openFlags & SQLITE_OPEN_MAIN_DB ){ |
| 160012 | | - ota_file **pp; |
| 160013 | | - sqlite3_mutex_enter(p->pOtaVfs->mutex); |
| 160014 | | - for(pp=&p->pOtaVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext)); |
| 160214 | + rbu_file **pp; |
| 160215 | + sqlite3_mutex_enter(p->pRbuVfs->mutex); |
| 160216 | + for(pp=&p->pRbuVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext)); |
| 160015 | 160217 | *pp = p->pMainNext; |
| 160016 | | - sqlite3_mutex_leave(p->pOtaVfs->mutex); |
| 160017 | | - otaUnlockShm(p); |
| 160218 | + sqlite3_mutex_leave(p->pRbuVfs->mutex); |
| 160219 | + rbuUnlockShm(p); |
| 160018 | 160220 | p->pReal->pMethods->xShmUnmap(p->pReal, 0); |
| 160019 | 160221 | } |
| 160020 | 160222 | |
| 160021 | 160223 | /* Close the underlying file handle */ |
| 160022 | 160224 | rc = p->pReal->pMethods->xClose(p->pReal); |
| | @@ -160026,37 +160228,37 @@ |
| 160026 | 160228 | |
| 160027 | 160229 | /* |
| 160028 | 160230 | ** Read and return an unsigned 32-bit big-endian integer from the buffer |
| 160029 | 160231 | ** passed as the only argument. |
| 160030 | 160232 | */ |
| 160031 | | -static u32 otaGetU32(u8 *aBuf){ |
| 160233 | +static u32 rbuGetU32(u8 *aBuf){ |
| 160032 | 160234 | return ((u32)aBuf[0] << 24) |
| 160033 | 160235 | + ((u32)aBuf[1] << 16) |
| 160034 | 160236 | + ((u32)aBuf[2] << 8) |
| 160035 | 160237 | + ((u32)aBuf[3]); |
| 160036 | 160238 | } |
| 160037 | 160239 | |
| 160038 | 160240 | /* |
| 160039 | | -** Read data from an otaVfs-file. |
| 160241 | +** Read data from an rbuVfs-file. |
| 160040 | 160242 | */ |
| 160041 | | -static int otaVfsRead( |
| 160243 | +static int rbuVfsRead( |
| 160042 | 160244 | sqlite3_file *pFile, |
| 160043 | 160245 | void *zBuf, |
| 160044 | 160246 | int iAmt, |
| 160045 | 160247 | sqlite_int64 iOfst |
| 160046 | 160248 | ){ |
| 160047 | | - ota_file *p = (ota_file*)pFile; |
| 160048 | | - sqlite3ota *pOta = p->pOta; |
| 160249 | + rbu_file *p = (rbu_file*)pFile; |
| 160250 | + sqlite3rbu *pRbu = p->pRbu; |
| 160049 | 160251 | int rc; |
| 160050 | 160252 | |
| 160051 | | - if( pOta && pOta->eStage==OTA_STAGE_CAPTURE ){ |
| 160253 | + if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){ |
| 160052 | 160254 | assert( p->openFlags & SQLITE_OPEN_WAL ); |
| 160053 | | - rc = otaCaptureWalRead(p->pOta, iOfst, iAmt); |
| 160255 | + rc = rbuCaptureWalRead(p->pRbu, iOfst, iAmt); |
| 160054 | 160256 | }else{ |
| 160055 | | - if( pOta && pOta->eStage==OTA_STAGE_OAL |
| 160257 | + if( pRbu && pRbu->eStage==RBU_STAGE_OAL |
| 160056 | 160258 | && (p->openFlags & SQLITE_OPEN_WAL) |
| 160057 | | - && iOfst>=pOta->iOalSz |
| 160259 | + && iOfst>=pRbu->iOalSz |
| 160058 | 160260 | ){ |
| 160059 | 160261 | rc = SQLITE_OK; |
| 160060 | 160262 | memset(zBuf, 0, iAmt); |
| 160061 | 160263 | }else{ |
| 160062 | 160264 | rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst); |
| | @@ -160063,92 +160265,92 @@ |
| 160063 | 160265 | } |
| 160064 | 160266 | if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){ |
| 160065 | 160267 | /* These look like magic numbers. But they are stable, as they are part |
| 160066 | 160268 | ** of the definition of the SQLite file format, which may not change. */ |
| 160067 | 160269 | u8 *pBuf = (u8*)zBuf; |
| 160068 | | - p->iCookie = otaGetU32(&pBuf[24]); |
| 160270 | + p->iCookie = rbuGetU32(&pBuf[24]); |
| 160069 | 160271 | p->iWriteVer = pBuf[19]; |
| 160070 | 160272 | } |
| 160071 | 160273 | } |
| 160072 | 160274 | return rc; |
| 160073 | 160275 | } |
| 160074 | 160276 | |
| 160075 | 160277 | /* |
| 160076 | | -** Write data to an otaVfs-file. |
| 160278 | +** Write data to an rbuVfs-file. |
| 160077 | 160279 | */ |
| 160078 | | -static int otaVfsWrite( |
| 160280 | +static int rbuVfsWrite( |
| 160079 | 160281 | sqlite3_file *pFile, |
| 160080 | 160282 | const void *zBuf, |
| 160081 | 160283 | int iAmt, |
| 160082 | 160284 | sqlite_int64 iOfst |
| 160083 | 160285 | ){ |
| 160084 | | - ota_file *p = (ota_file*)pFile; |
| 160085 | | - sqlite3ota *pOta = p->pOta; |
| 160286 | + rbu_file *p = (rbu_file*)pFile; |
| 160287 | + sqlite3rbu *pRbu = p->pRbu; |
| 160086 | 160288 | int rc; |
| 160087 | 160289 | |
| 160088 | | - if( pOta && pOta->eStage==OTA_STAGE_CAPTURE ){ |
| 160290 | + if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){ |
| 160089 | 160291 | assert( p->openFlags & SQLITE_OPEN_MAIN_DB ); |
| 160090 | | - rc = otaCaptureDbWrite(p->pOta, iOfst); |
| 160292 | + rc = rbuCaptureDbWrite(p->pRbu, iOfst); |
| 160091 | 160293 | }else{ |
| 160092 | | - if( pOta && pOta->eStage==OTA_STAGE_OAL |
| 160294 | + if( pRbu && pRbu->eStage==RBU_STAGE_OAL |
| 160093 | 160295 | && (p->openFlags & SQLITE_OPEN_WAL) |
| 160094 | | - && iOfst>=pOta->iOalSz |
| 160296 | + && iOfst>=pRbu->iOalSz |
| 160095 | 160297 | ){ |
| 160096 | | - pOta->iOalSz = iAmt + iOfst; |
| 160298 | + pRbu->iOalSz = iAmt + iOfst; |
| 160097 | 160299 | } |
| 160098 | 160300 | rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst); |
| 160099 | 160301 | if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){ |
| 160100 | 160302 | /* These look like magic numbers. But they are stable, as they are part |
| 160101 | 160303 | ** of the definition of the SQLite file format, which may not change. */ |
| 160102 | 160304 | u8 *pBuf = (u8*)zBuf; |
| 160103 | | - p->iCookie = otaGetU32(&pBuf[24]); |
| 160305 | + p->iCookie = rbuGetU32(&pBuf[24]); |
| 160104 | 160306 | p->iWriteVer = pBuf[19]; |
| 160105 | 160307 | } |
| 160106 | 160308 | } |
| 160107 | 160309 | return rc; |
| 160108 | 160310 | } |
| 160109 | 160311 | |
| 160110 | 160312 | /* |
| 160111 | | -** Truncate an otaVfs-file. |
| 160313 | +** Truncate an rbuVfs-file. |
| 160112 | 160314 | */ |
| 160113 | | -static int otaVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){ |
| 160114 | | - ota_file *p = (ota_file*)pFile; |
| 160315 | +static int rbuVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){ |
| 160316 | + rbu_file *p = (rbu_file*)pFile; |
| 160115 | 160317 | return p->pReal->pMethods->xTruncate(p->pReal, size); |
| 160116 | 160318 | } |
| 160117 | 160319 | |
| 160118 | 160320 | /* |
| 160119 | | -** Sync an otaVfs-file. |
| 160321 | +** Sync an rbuVfs-file. |
| 160120 | 160322 | */ |
| 160121 | | -static int otaVfsSync(sqlite3_file *pFile, int flags){ |
| 160122 | | - ota_file *p = (ota_file *)pFile; |
| 160123 | | - if( p->pOta && p->pOta->eStage==OTA_STAGE_CAPTURE ){ |
| 160323 | +static int rbuVfsSync(sqlite3_file *pFile, int flags){ |
| 160324 | + rbu_file *p = (rbu_file *)pFile; |
| 160325 | + if( p->pRbu && p->pRbu->eStage==RBU_STAGE_CAPTURE ){ |
| 160124 | 160326 | if( p->openFlags & SQLITE_OPEN_MAIN_DB ){ |
| 160125 | 160327 | return SQLITE_INTERNAL; |
| 160126 | 160328 | } |
| 160127 | 160329 | return SQLITE_OK; |
| 160128 | 160330 | } |
| 160129 | 160331 | return p->pReal->pMethods->xSync(p->pReal, flags); |
| 160130 | 160332 | } |
| 160131 | 160333 | |
| 160132 | 160334 | /* |
| 160133 | | -** Return the current file-size of an otaVfs-file. |
| 160335 | +** Return the current file-size of an rbuVfs-file. |
| 160134 | 160336 | */ |
| 160135 | | -static int otaVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ |
| 160136 | | - ota_file *p = (ota_file *)pFile; |
| 160337 | +static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ |
| 160338 | + rbu_file *p = (rbu_file *)pFile; |
| 160137 | 160339 | return p->pReal->pMethods->xFileSize(p->pReal, pSize); |
| 160138 | 160340 | } |
| 160139 | 160341 | |
| 160140 | 160342 | /* |
| 160141 | | -** Lock an otaVfs-file. |
| 160343 | +** Lock an rbuVfs-file. |
| 160142 | 160344 | */ |
| 160143 | | -static int otaVfsLock(sqlite3_file *pFile, int eLock){ |
| 160144 | | - ota_file *p = (ota_file*)pFile; |
| 160145 | | - sqlite3ota *pOta = p->pOta; |
| 160345 | +static int rbuVfsLock(sqlite3_file *pFile, int eLock){ |
| 160346 | + rbu_file *p = (rbu_file*)pFile; |
| 160347 | + sqlite3rbu *pRbu = p->pRbu; |
| 160146 | 160348 | int rc = SQLITE_OK; |
| 160147 | 160349 | |
| 160148 | 160350 | assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) ); |
| 160149 | | - if( pOta && eLock==SQLITE_LOCK_EXCLUSIVE && pOta->eStage!=OTA_STAGE_DONE ){ |
| 160351 | + if( pRbu && eLock==SQLITE_LOCK_EXCLUSIVE && pRbu->eStage!=RBU_STAGE_DONE ){ |
| 160150 | 160352 | /* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this |
| 160151 | 160353 | ** prevents it from checkpointing the database from sqlite3_close(). */ |
| 160152 | 160354 | rc = SQLITE_BUSY; |
| 160153 | 160355 | }else{ |
| 160154 | 160356 | rc = p->pReal->pMethods->xLock(p->pReal, eLock); |
| | @@ -160156,122 +160358,122 @@ |
| 160156 | 160358 | |
| 160157 | 160359 | return rc; |
| 160158 | 160360 | } |
| 160159 | 160361 | |
| 160160 | 160362 | /* |
| 160161 | | -** Unlock an otaVfs-file. |
| 160363 | +** Unlock an rbuVfs-file. |
| 160162 | 160364 | */ |
| 160163 | | -static int otaVfsUnlock(sqlite3_file *pFile, int eLock){ |
| 160164 | | - ota_file *p = (ota_file *)pFile; |
| 160365 | +static int rbuVfsUnlock(sqlite3_file *pFile, int eLock){ |
| 160366 | + rbu_file *p = (rbu_file *)pFile; |
| 160165 | 160367 | return p->pReal->pMethods->xUnlock(p->pReal, eLock); |
| 160166 | 160368 | } |
| 160167 | 160369 | |
| 160168 | 160370 | /* |
| 160169 | | -** Check if another file-handle holds a RESERVED lock on an otaVfs-file. |
| 160371 | +** Check if another file-handle holds a RESERVED lock on an rbuVfs-file. |
| 160170 | 160372 | */ |
| 160171 | | -static int otaVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){ |
| 160172 | | - ota_file *p = (ota_file *)pFile; |
| 160373 | +static int rbuVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){ |
| 160374 | + rbu_file *p = (rbu_file *)pFile; |
| 160173 | 160375 | return p->pReal->pMethods->xCheckReservedLock(p->pReal, pResOut); |
| 160174 | 160376 | } |
| 160175 | 160377 | |
| 160176 | 160378 | /* |
| 160177 | | -** File control method. For custom operations on an otaVfs-file. |
| 160379 | +** File control method. For custom operations on an rbuVfs-file. |
| 160178 | 160380 | */ |
| 160179 | | -static int otaVfsFileControl(sqlite3_file *pFile, int op, void *pArg){ |
| 160180 | | - ota_file *p = (ota_file *)pFile; |
| 160381 | +static int rbuVfsFileControl(sqlite3_file *pFile, int op, void *pArg){ |
| 160382 | + rbu_file *p = (rbu_file *)pFile; |
| 160181 | 160383 | int (*xControl)(sqlite3_file*,int,void*) = p->pReal->pMethods->xFileControl; |
| 160182 | 160384 | int rc; |
| 160183 | 160385 | |
| 160184 | 160386 | assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) |
| 160185 | 160387 | || p->openFlags & (SQLITE_OPEN_TRANSIENT_DB|SQLITE_OPEN_TEMP_JOURNAL) |
| 160186 | 160388 | ); |
| 160187 | | - if( op==SQLITE_FCNTL_OTA ){ |
| 160188 | | - sqlite3ota *pOta = (sqlite3ota*)pArg; |
| 160389 | + if( op==SQLITE_FCNTL_RBU ){ |
| 160390 | + sqlite3rbu *pRbu = (sqlite3rbu*)pArg; |
| 160189 | 160391 | |
| 160190 | | - /* First try to find another OTA vfs lower down in the vfs stack. If |
| 160392 | + /* First try to find another RBU vfs lower down in the vfs stack. If |
| 160191 | 160393 | ** one is found, this vfs will operate in pass-through mode. The lower |
| 160192 | | - ** level vfs will do the special OTA handling. */ |
| 160394 | + ** level vfs will do the special RBU handling. */ |
| 160193 | 160395 | rc = xControl(p->pReal, op, pArg); |
| 160194 | 160396 | |
| 160195 | 160397 | if( rc==SQLITE_NOTFOUND ){ |
| 160196 | 160398 | /* Now search for a zipvfs instance lower down in the VFS stack. If |
| 160197 | 160399 | ** one is found, this is an error. */ |
| 160198 | 160400 | void *dummy = 0; |
| 160199 | 160401 | rc = xControl(p->pReal, SQLITE_FCNTL_ZIPVFS, &dummy); |
| 160200 | 160402 | if( rc==SQLITE_OK ){ |
| 160201 | 160403 | rc = SQLITE_ERROR; |
| 160202 | | - pOta->zErrmsg = sqlite3_mprintf("ota/zipvfs setup error"); |
| 160404 | + pRbu->zErrmsg = sqlite3_mprintf("rbu/zipvfs setup error"); |
| 160203 | 160405 | }else if( rc==SQLITE_NOTFOUND ){ |
| 160204 | | - pOta->pTargetFd = p; |
| 160205 | | - p->pOta = pOta; |
| 160206 | | - if( p->pWalFd ) p->pWalFd->pOta = pOta; |
| 160406 | + pRbu->pTargetFd = p; |
| 160407 | + p->pRbu = pRbu; |
| 160408 | + if( p->pWalFd ) p->pWalFd->pRbu = pRbu; |
| 160207 | 160409 | rc = SQLITE_OK; |
| 160208 | 160410 | } |
| 160209 | 160411 | } |
| 160210 | 160412 | return rc; |
| 160211 | 160413 | } |
| 160212 | 160414 | |
| 160213 | 160415 | rc = xControl(p->pReal, op, pArg); |
| 160214 | 160416 | if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){ |
| 160215 | | - ota_vfs *pOtaVfs = p->pOtaVfs; |
| 160417 | + rbu_vfs *pRbuVfs = p->pRbuVfs; |
| 160216 | 160418 | char *zIn = *(char**)pArg; |
| 160217 | | - char *zOut = sqlite3_mprintf("ota(%s)/%z", pOtaVfs->base.zName, zIn); |
| 160419 | + char *zOut = sqlite3_mprintf("rbu(%s)/%z", pRbuVfs->base.zName, zIn); |
| 160218 | 160420 | *(char**)pArg = zOut; |
| 160219 | 160421 | if( zOut==0 ) rc = SQLITE_NOMEM; |
| 160220 | 160422 | } |
| 160221 | 160423 | |
| 160222 | 160424 | return rc; |
| 160223 | 160425 | } |
| 160224 | 160426 | |
| 160225 | 160427 | /* |
| 160226 | | -** Return the sector-size in bytes for an otaVfs-file. |
| 160428 | +** Return the sector-size in bytes for an rbuVfs-file. |
| 160227 | 160429 | */ |
| 160228 | | -static int otaVfsSectorSize(sqlite3_file *pFile){ |
| 160229 | | - ota_file *p = (ota_file *)pFile; |
| 160430 | +static int rbuVfsSectorSize(sqlite3_file *pFile){ |
| 160431 | + rbu_file *p = (rbu_file *)pFile; |
| 160230 | 160432 | return p->pReal->pMethods->xSectorSize(p->pReal); |
| 160231 | 160433 | } |
| 160232 | 160434 | |
| 160233 | 160435 | /* |
| 160234 | | -** Return the device characteristic flags supported by an otaVfs-file. |
| 160436 | +** Return the device characteristic flags supported by an rbuVfs-file. |
| 160235 | 160437 | */ |
| 160236 | | -static int otaVfsDeviceCharacteristics(sqlite3_file *pFile){ |
| 160237 | | - ota_file *p = (ota_file *)pFile; |
| 160438 | +static int rbuVfsDeviceCharacteristics(sqlite3_file *pFile){ |
| 160439 | + rbu_file *p = (rbu_file *)pFile; |
| 160238 | 160440 | return p->pReal->pMethods->xDeviceCharacteristics(p->pReal); |
| 160239 | 160441 | } |
| 160240 | 160442 | |
| 160241 | 160443 | /* |
| 160242 | 160444 | ** Take or release a shared-memory lock. |
| 160243 | 160445 | */ |
| 160244 | | -static int otaVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){ |
| 160245 | | - ota_file *p = (ota_file*)pFile; |
| 160246 | | - sqlite3ota *pOta = p->pOta; |
| 160446 | +static int rbuVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){ |
| 160447 | + rbu_file *p = (rbu_file*)pFile; |
| 160448 | + sqlite3rbu *pRbu = p->pRbu; |
| 160247 | 160449 | int rc = SQLITE_OK; |
| 160248 | 160450 | |
| 160249 | 160451 | #ifdef SQLITE_AMALGAMATION |
| 160250 | 160452 | assert( WAL_CKPT_LOCK==1 ); |
| 160251 | 160453 | #endif |
| 160252 | 160454 | |
| 160253 | 160455 | assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) ); |
| 160254 | | - if( pOta && (pOta->eStage==OTA_STAGE_OAL || pOta->eStage==OTA_STAGE_MOVE) ){ |
| 160456 | + if( pRbu && (pRbu->eStage==RBU_STAGE_OAL || pRbu->eStage==RBU_STAGE_MOVE) ){ |
| 160255 | 160457 | /* Magic number 1 is the WAL_CKPT_LOCK lock. Preventing SQLite from |
| 160256 | 160458 | ** taking this lock also prevents any checkpoints from occurring. |
| 160257 | 160459 | ** todo: really, it's not clear why this might occur, as |
| 160258 | 160460 | ** wal_autocheckpoint ought to be turned off. */ |
| 160259 | 160461 | if( ofst==WAL_LOCK_CKPT && n==1 ) rc = SQLITE_BUSY; |
| 160260 | 160462 | }else{ |
| 160261 | 160463 | int bCapture = 0; |
| 160262 | 160464 | if( n==1 && (flags & SQLITE_SHM_EXCLUSIVE) |
| 160263 | | - && pOta && pOta->eStage==OTA_STAGE_CAPTURE |
| 160465 | + && pRbu && pRbu->eStage==RBU_STAGE_CAPTURE |
| 160264 | 160466 | && (ofst==WAL_LOCK_WRITE || ofst==WAL_LOCK_CKPT || ofst==WAL_LOCK_READ0) |
| 160265 | 160467 | ){ |
| 160266 | 160468 | bCapture = 1; |
| 160267 | 160469 | } |
| 160268 | 160470 | |
| 160269 | 160471 | if( bCapture==0 || 0==(flags & SQLITE_SHM_UNLOCK) ){ |
| 160270 | 160472 | rc = p->pReal->pMethods->xShmLock(p->pReal, ofst, n, flags); |
| 160271 | 160473 | if( bCapture && rc==SQLITE_OK ){ |
| 160272 | | - pOta->mLock |= (1 << ofst); |
| 160474 | + pRbu->mLock |= (1 << ofst); |
| 160273 | 160475 | } |
| 160274 | 160476 | } |
| 160275 | 160477 | } |
| 160276 | 160478 | |
| 160277 | 160479 | return rc; |
| | @@ -160278,26 +160480,26 @@ |
| 160278 | 160480 | } |
| 160279 | 160481 | |
| 160280 | 160482 | /* |
| 160281 | 160483 | ** Obtain a pointer to a mapping of a single 32KiB page of the *-shm file. |
| 160282 | 160484 | */ |
| 160283 | | -static int otaVfsShmMap( |
| 160485 | +static int rbuVfsShmMap( |
| 160284 | 160486 | sqlite3_file *pFile, |
| 160285 | 160487 | int iRegion, |
| 160286 | 160488 | int szRegion, |
| 160287 | 160489 | int isWrite, |
| 160288 | 160490 | void volatile **pp |
| 160289 | 160491 | ){ |
| 160290 | | - ota_file *p = (ota_file*)pFile; |
| 160492 | + rbu_file *p = (rbu_file*)pFile; |
| 160291 | 160493 | int rc = SQLITE_OK; |
| 160292 | | - int eStage = (p->pOta ? p->pOta->eStage : 0); |
| 160494 | + int eStage = (p->pRbu ? p->pRbu->eStage : 0); |
| 160293 | 160495 | |
| 160294 | | - /* If not in OTA_STAGE_OAL, allow this call to pass through. Or, if this |
| 160295 | | - ** ota is in the OTA_STAGE_OAL state, use heap memory for *-shm space |
| 160496 | + /* If not in RBU_STAGE_OAL, allow this call to pass through. Or, if this |
| 160497 | + ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space |
| 160296 | 160498 | ** instead of a file on disk. */ |
| 160297 | 160499 | assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) ); |
| 160298 | | - if( eStage==OTA_STAGE_OAL || eStage==OTA_STAGE_MOVE ){ |
| 160500 | + if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){ |
| 160299 | 160501 | if( iRegion<=p->nShm ){ |
| 160300 | 160502 | int nByte = (iRegion+1) * sizeof(char*); |
| 160301 | 160503 | char **apNew = (char**)sqlite3_realloc(p->apShm, nByte); |
| 160302 | 160504 | if( apNew==0 ){ |
| 160303 | 160505 | rc = SQLITE_NOMEM; |
| | @@ -160332,29 +160534,29 @@ |
| 160332 | 160534 | } |
| 160333 | 160535 | |
| 160334 | 160536 | /* |
| 160335 | 160537 | ** Memory barrier. |
| 160336 | 160538 | */ |
| 160337 | | -static void otaVfsShmBarrier(sqlite3_file *pFile){ |
| 160338 | | - ota_file *p = (ota_file *)pFile; |
| 160539 | +static void rbuVfsShmBarrier(sqlite3_file *pFile){ |
| 160540 | + rbu_file *p = (rbu_file *)pFile; |
| 160339 | 160541 | p->pReal->pMethods->xShmBarrier(p->pReal); |
| 160340 | 160542 | } |
| 160341 | 160543 | |
| 160342 | 160544 | /* |
| 160343 | 160545 | ** The xShmUnmap method. |
| 160344 | 160546 | */ |
| 160345 | | -static int otaVfsShmUnmap(sqlite3_file *pFile, int delFlag){ |
| 160346 | | - ota_file *p = (ota_file*)pFile; |
| 160547 | +static int rbuVfsShmUnmap(sqlite3_file *pFile, int delFlag){ |
| 160548 | + rbu_file *p = (rbu_file*)pFile; |
| 160347 | 160549 | int rc = SQLITE_OK; |
| 160348 | | - int eStage = (p->pOta ? p->pOta->eStage : 0); |
| 160550 | + int eStage = (p->pRbu ? p->pRbu->eStage : 0); |
| 160349 | 160551 | |
| 160350 | 160552 | assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) ); |
| 160351 | | - if( eStage==OTA_STAGE_OAL || eStage==OTA_STAGE_MOVE ){ |
| 160553 | + if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){ |
| 160352 | 160554 | /* no-op */ |
| 160353 | 160555 | }else{ |
| 160354 | 160556 | /* Release the checkpointer and writer locks */ |
| 160355 | | - otaUnlockShm(p); |
| 160557 | + rbuUnlockShm(p); |
| 160356 | 160558 | rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag); |
| 160357 | 160559 | } |
| 160358 | 160560 | return rc; |
| 160359 | 160561 | } |
| 160360 | 160562 | |
| | @@ -160362,56 +160564,56 @@ |
| 160362 | 160564 | ** Given that zWal points to a buffer containing a wal file name passed to |
| 160363 | 160565 | ** either the xOpen() or xAccess() VFS method, return a pointer to the |
| 160364 | 160566 | ** file-handle opened by the same database connection on the corresponding |
| 160365 | 160567 | ** database file. |
| 160366 | 160568 | */ |
| 160367 | | -static ota_file *otaFindMaindb(ota_vfs *pOtaVfs, const char *zWal){ |
| 160368 | | - ota_file *pDb; |
| 160369 | | - sqlite3_mutex_enter(pOtaVfs->mutex); |
| 160370 | | - for(pDb=pOtaVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext); |
| 160371 | | - sqlite3_mutex_leave(pOtaVfs->mutex); |
| 160569 | +static rbu_file *rbuFindMaindb(rbu_vfs *pRbuVfs, const char *zWal){ |
| 160570 | + rbu_file *pDb; |
| 160571 | + sqlite3_mutex_enter(pRbuVfs->mutex); |
| 160572 | + for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext); |
| 160573 | + sqlite3_mutex_leave(pRbuVfs->mutex); |
| 160372 | 160574 | return pDb; |
| 160373 | 160575 | } |
| 160374 | 160576 | |
| 160375 | 160577 | /* |
| 160376 | | -** Open an ota file handle. |
| 160578 | +** Open an rbu file handle. |
| 160377 | 160579 | */ |
| 160378 | | -static int otaVfsOpen( |
| 160580 | +static int rbuVfsOpen( |
| 160379 | 160581 | sqlite3_vfs *pVfs, |
| 160380 | 160582 | const char *zName, |
| 160381 | 160583 | sqlite3_file *pFile, |
| 160382 | 160584 | int flags, |
| 160383 | 160585 | int *pOutFlags |
| 160384 | 160586 | ){ |
| 160385 | | - static sqlite3_io_methods otavfs_io_methods = { |
| 160587 | + static sqlite3_io_methods rbuvfs_io_methods = { |
| 160386 | 160588 | 2, /* iVersion */ |
| 160387 | | - otaVfsClose, /* xClose */ |
| 160388 | | - otaVfsRead, /* xRead */ |
| 160389 | | - otaVfsWrite, /* xWrite */ |
| 160390 | | - otaVfsTruncate, /* xTruncate */ |
| 160391 | | - otaVfsSync, /* xSync */ |
| 160392 | | - otaVfsFileSize, /* xFileSize */ |
| 160393 | | - otaVfsLock, /* xLock */ |
| 160394 | | - otaVfsUnlock, /* xUnlock */ |
| 160395 | | - otaVfsCheckReservedLock, /* xCheckReservedLock */ |
| 160396 | | - otaVfsFileControl, /* xFileControl */ |
| 160397 | | - otaVfsSectorSize, /* xSectorSize */ |
| 160398 | | - otaVfsDeviceCharacteristics, /* xDeviceCharacteristics */ |
| 160399 | | - otaVfsShmMap, /* xShmMap */ |
| 160400 | | - otaVfsShmLock, /* xShmLock */ |
| 160401 | | - otaVfsShmBarrier, /* xShmBarrier */ |
| 160402 | | - otaVfsShmUnmap /* xShmUnmap */ |
| 160589 | + rbuVfsClose, /* xClose */ |
| 160590 | + rbuVfsRead, /* xRead */ |
| 160591 | + rbuVfsWrite, /* xWrite */ |
| 160592 | + rbuVfsTruncate, /* xTruncate */ |
| 160593 | + rbuVfsSync, /* xSync */ |
| 160594 | + rbuVfsFileSize, /* xFileSize */ |
| 160595 | + rbuVfsLock, /* xLock */ |
| 160596 | + rbuVfsUnlock, /* xUnlock */ |
| 160597 | + rbuVfsCheckReservedLock, /* xCheckReservedLock */ |
| 160598 | + rbuVfsFileControl, /* xFileControl */ |
| 160599 | + rbuVfsSectorSize, /* xSectorSize */ |
| 160600 | + rbuVfsDeviceCharacteristics, /* xDeviceCharacteristics */ |
| 160601 | + rbuVfsShmMap, /* xShmMap */ |
| 160602 | + rbuVfsShmLock, /* xShmLock */ |
| 160603 | + rbuVfsShmBarrier, /* xShmBarrier */ |
| 160604 | + rbuVfsShmUnmap /* xShmUnmap */ |
| 160403 | 160605 | }; |
| 160404 | | - ota_vfs *pOtaVfs = (ota_vfs*)pVfs; |
| 160405 | | - sqlite3_vfs *pRealVfs = pOtaVfs->pRealVfs; |
| 160406 | | - ota_file *pFd = (ota_file *)pFile; |
| 160606 | + rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs; |
| 160607 | + sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs; |
| 160608 | + rbu_file *pFd = (rbu_file *)pFile; |
| 160407 | 160609 | int rc = SQLITE_OK; |
| 160408 | 160610 | const char *zOpen = zName; |
| 160409 | 160611 | |
| 160410 | | - memset(pFd, 0, sizeof(ota_file)); |
| 160612 | + memset(pFd, 0, sizeof(rbu_file)); |
| 160411 | 160613 | pFd->pReal = (sqlite3_file*)&pFd[1]; |
| 160412 | | - pFd->pOtaVfs = pOtaVfs; |
| 160614 | + pFd->pRbuVfs = pRbuVfs; |
| 160413 | 160615 | pFd->openFlags = flags; |
| 160414 | 160616 | if( zName ){ |
| 160415 | 160617 | if( flags & SQLITE_OPEN_MAIN_DB ){ |
| 160416 | 160618 | /* A main database has just been opened. The following block sets |
| 160417 | 160619 | ** (pFd->zWal) to point to a buffer owned by SQLite that contains |
| | @@ -160435,13 +160637,13 @@ |
| 160435 | 160637 | } |
| 160436 | 160638 | z += (n + 8 + 1); |
| 160437 | 160639 | pFd->zWal = z; |
| 160438 | 160640 | } |
| 160439 | 160641 | else if( flags & SQLITE_OPEN_WAL ){ |
| 160440 | | - ota_file *pDb = otaFindMaindb(pOtaVfs, zName); |
| 160642 | + rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName); |
| 160441 | 160643 | if( pDb ){ |
| 160442 | | - if( pDb->pOta && pDb->pOta->eStage==OTA_STAGE_OAL ){ |
| 160644 | + if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){ |
| 160443 | 160645 | /* This call is to open a *-wal file. Intead, open the *-oal. This |
| 160444 | 160646 | ** code ensures that the string passed to xOpen() is terminated by a |
| 160445 | 160647 | ** pair of '\0' bytes in case the VFS attempts to extract a URI |
| 160446 | 160648 | ** parameter from it. */ |
| 160447 | 160649 | int nCopy = strlen(zName); |
| | @@ -160453,11 +160655,11 @@ |
| 160453 | 160655 | zCopy[nCopy+1] = '\0'; |
| 160454 | 160656 | zOpen = (const char*)(pFd->zDel = zCopy); |
| 160455 | 160657 | }else{ |
| 160456 | 160658 | rc = SQLITE_NOMEM; |
| 160457 | 160659 | } |
| 160458 | | - pFd->pOta = pDb->pOta; |
| 160660 | + pFd->pRbu = pDb->pRbu; |
| 160459 | 160661 | } |
| 160460 | 160662 | pDb->pWalFd = pFd; |
| 160461 | 160663 | } |
| 160462 | 160664 | } |
| 160463 | 160665 | } |
| | @@ -160467,16 +160669,16 @@ |
| 160467 | 160669 | } |
| 160468 | 160670 | if( pFd->pReal->pMethods ){ |
| 160469 | 160671 | /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods |
| 160470 | 160672 | ** pointer and, if the file is a main database file, link it into the |
| 160471 | 160673 | ** mutex protected linked list of all such files. */ |
| 160472 | | - pFile->pMethods = &otavfs_io_methods; |
| 160674 | + pFile->pMethods = &rbuvfs_io_methods; |
| 160473 | 160675 | if( flags & SQLITE_OPEN_MAIN_DB ){ |
| 160474 | | - sqlite3_mutex_enter(pOtaVfs->mutex); |
| 160475 | | - pFd->pMainNext = pOtaVfs->pMain; |
| 160476 | | - pOtaVfs->pMain = pFd; |
| 160477 | | - sqlite3_mutex_leave(pOtaVfs->mutex); |
| 160676 | + sqlite3_mutex_enter(pRbuVfs->mutex); |
| 160677 | + pFd->pMainNext = pRbuVfs->pMain; |
| 160678 | + pRbuVfs->pMain = pFd; |
| 160679 | + sqlite3_mutex_leave(pRbuVfs->mutex); |
| 160478 | 160680 | } |
| 160479 | 160681 | }else{ |
| 160480 | 160682 | sqlite3_free(pFd->zDel); |
| 160481 | 160683 | } |
| 160482 | 160684 | |
| | @@ -160484,48 +160686,48 @@ |
| 160484 | 160686 | } |
| 160485 | 160687 | |
| 160486 | 160688 | /* |
| 160487 | 160689 | ** Delete the file located at zPath. |
| 160488 | 160690 | */ |
| 160489 | | -static int otaVfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ |
| 160490 | | - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; |
| 160691 | +static int rbuVfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ |
| 160692 | + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; |
| 160491 | 160693 | return pRealVfs->xDelete(pRealVfs, zPath, dirSync); |
| 160492 | 160694 | } |
| 160493 | 160695 | |
| 160494 | 160696 | /* |
| 160495 | 160697 | ** Test for access permissions. Return true if the requested permission |
| 160496 | 160698 | ** is available, or false otherwise. |
| 160497 | 160699 | */ |
| 160498 | | -static int otaVfsAccess( |
| 160700 | +static int rbuVfsAccess( |
| 160499 | 160701 | sqlite3_vfs *pVfs, |
| 160500 | 160702 | const char *zPath, |
| 160501 | 160703 | int flags, |
| 160502 | 160704 | int *pResOut |
| 160503 | 160705 | ){ |
| 160504 | | - ota_vfs *pOtaVfs = (ota_vfs*)pVfs; |
| 160505 | | - sqlite3_vfs *pRealVfs = pOtaVfs->pRealVfs; |
| 160706 | + rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs; |
| 160707 | + sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs; |
| 160506 | 160708 | int rc; |
| 160507 | 160709 | |
| 160508 | 160710 | rc = pRealVfs->xAccess(pRealVfs, zPath, flags, pResOut); |
| 160509 | 160711 | |
| 160510 | | - /* If this call is to check if a *-wal file associated with an OTA target |
| 160511 | | - ** database connection exists, and the OTA update is in OTA_STAGE_OAL, |
| 160712 | + /* If this call is to check if a *-wal file associated with an RBU target |
| 160713 | + ** database connection exists, and the RBU update is in RBU_STAGE_OAL, |
| 160512 | 160714 | ** the following special handling is activated: |
| 160513 | 160715 | ** |
| 160514 | 160716 | ** a) if the *-wal file does exist, return SQLITE_CANTOPEN. This |
| 160515 | | - ** ensures that the OTA extension never tries to update a database |
| 160717 | + ** ensures that the RBU extension never tries to update a database |
| 160516 | 160718 | ** in wal mode, even if the first page of the database file has |
| 160517 | 160719 | ** been damaged. |
| 160518 | 160720 | ** |
| 160519 | 160721 | ** b) if the *-wal file does not exist, claim that it does anyway, |
| 160520 | 160722 | ** causing SQLite to call xOpen() to open it. This call will also |
| 160521 | | - ** be intercepted (see the otaVfsOpen() function) and the *-oal |
| 160723 | + ** be intercepted (see the rbuVfsOpen() function) and the *-oal |
| 160522 | 160724 | ** file opened instead. |
| 160523 | 160725 | */ |
| 160524 | 160726 | if( rc==SQLITE_OK && flags==SQLITE_ACCESS_EXISTS ){ |
| 160525 | | - ota_file *pDb = otaFindMaindb(pOtaVfs, zPath); |
| 160526 | | - if( pDb && pDb->pOta && pDb->pOta->eStage==OTA_STAGE_OAL ){ |
| 160727 | + rbu_file *pDb = rbuFindMaindb(pRbuVfs, zPath); |
| 160728 | + if( pDb && pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){ |
| 160527 | 160729 | if( *pResOut ){ |
| 160528 | 160730 | rc = SQLITE_CANTOPEN; |
| 160529 | 160731 | }else{ |
| 160530 | 160732 | *pResOut = 1; |
| 160531 | 160733 | } |
| | @@ -160538,151 +160740,151 @@ |
| 160538 | 160740 | /* |
| 160539 | 160741 | ** Populate buffer zOut with the full canonical pathname corresponding |
| 160540 | 160742 | ** to the pathname in zPath. zOut is guaranteed to point to a buffer |
| 160541 | 160743 | ** of at least (DEVSYM_MAX_PATHNAME+1) bytes. |
| 160542 | 160744 | */ |
| 160543 | | -static int otaVfsFullPathname( |
| 160745 | +static int rbuVfsFullPathname( |
| 160544 | 160746 | sqlite3_vfs *pVfs, |
| 160545 | 160747 | const char *zPath, |
| 160546 | 160748 | int nOut, |
| 160547 | 160749 | char *zOut |
| 160548 | 160750 | ){ |
| 160549 | | - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; |
| 160751 | + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; |
| 160550 | 160752 | return pRealVfs->xFullPathname(pRealVfs, zPath, nOut, zOut); |
| 160551 | 160753 | } |
| 160552 | 160754 | |
| 160553 | 160755 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 160554 | 160756 | /* |
| 160555 | 160757 | ** Open the dynamic library located at zPath and return a handle. |
| 160556 | 160758 | */ |
| 160557 | | -static void *otaVfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){ |
| 160558 | | - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; |
| 160759 | +static void *rbuVfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){ |
| 160760 | + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; |
| 160559 | 160761 | return pRealVfs->xDlOpen(pRealVfs, zPath); |
| 160560 | 160762 | } |
| 160561 | 160763 | |
| 160562 | 160764 | /* |
| 160563 | 160765 | ** Populate the buffer zErrMsg (size nByte bytes) with a human readable |
| 160564 | 160766 | ** utf-8 string describing the most recent error encountered associated |
| 160565 | 160767 | ** with dynamic libraries. |
| 160566 | 160768 | */ |
| 160567 | | -static void otaVfsDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){ |
| 160568 | | - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; |
| 160769 | +static void rbuVfsDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){ |
| 160770 | + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; |
| 160569 | 160771 | pRealVfs->xDlError(pRealVfs, nByte, zErrMsg); |
| 160570 | 160772 | } |
| 160571 | 160773 | |
| 160572 | 160774 | /* |
| 160573 | 160775 | ** Return a pointer to the symbol zSymbol in the dynamic library pHandle. |
| 160574 | 160776 | */ |
| 160575 | | -static void (*otaVfsDlSym( |
| 160777 | +static void (*rbuVfsDlSym( |
| 160576 | 160778 | sqlite3_vfs *pVfs, |
| 160577 | 160779 | void *pArg, |
| 160578 | 160780 | const char *zSym |
| 160579 | 160781 | ))(void){ |
| 160580 | | - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; |
| 160782 | + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; |
| 160581 | 160783 | return pRealVfs->xDlSym(pRealVfs, pArg, zSym); |
| 160582 | 160784 | } |
| 160583 | 160785 | |
| 160584 | 160786 | /* |
| 160585 | 160787 | ** Close the dynamic library handle pHandle. |
| 160586 | 160788 | */ |
| 160587 | | -static void otaVfsDlClose(sqlite3_vfs *pVfs, void *pHandle){ |
| 160588 | | - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; |
| 160789 | +static void rbuVfsDlClose(sqlite3_vfs *pVfs, void *pHandle){ |
| 160790 | + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; |
| 160589 | 160791 | return pRealVfs->xDlClose(pRealVfs, pHandle); |
| 160590 | 160792 | } |
| 160591 | 160793 | #endif /* SQLITE_OMIT_LOAD_EXTENSION */ |
| 160592 | 160794 | |
| 160593 | 160795 | /* |
| 160594 | 160796 | ** Populate the buffer pointed to by zBufOut with nByte bytes of |
| 160595 | 160797 | ** random data. |
| 160596 | 160798 | */ |
| 160597 | | -static int otaVfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ |
| 160598 | | - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; |
| 160799 | +static int rbuVfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ |
| 160800 | + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; |
| 160599 | 160801 | return pRealVfs->xRandomness(pRealVfs, nByte, zBufOut); |
| 160600 | 160802 | } |
| 160601 | 160803 | |
| 160602 | 160804 | /* |
| 160603 | 160805 | ** Sleep for nMicro microseconds. Return the number of microseconds |
| 160604 | 160806 | ** actually slept. |
| 160605 | 160807 | */ |
| 160606 | | -static int otaVfsSleep(sqlite3_vfs *pVfs, int nMicro){ |
| 160607 | | - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; |
| 160808 | +static int rbuVfsSleep(sqlite3_vfs *pVfs, int nMicro){ |
| 160809 | + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; |
| 160608 | 160810 | return pRealVfs->xSleep(pRealVfs, nMicro); |
| 160609 | 160811 | } |
| 160610 | 160812 | |
| 160611 | 160813 | /* |
| 160612 | 160814 | ** Return the current time as a Julian Day number in *pTimeOut. |
| 160613 | 160815 | */ |
| 160614 | | -static int otaVfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ |
| 160615 | | - sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs; |
| 160816 | +static int rbuVfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ |
| 160817 | + sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs; |
| 160616 | 160818 | return pRealVfs->xCurrentTime(pRealVfs, pTimeOut); |
| 160617 | 160819 | } |
| 160618 | 160820 | |
| 160619 | 160821 | /* |
| 160620 | 160822 | ** No-op. |
| 160621 | 160823 | */ |
| 160622 | | -static int otaVfsGetLastError(sqlite3_vfs *pVfs, int a, char *b){ |
| 160824 | +static int rbuVfsGetLastError(sqlite3_vfs *pVfs, int a, char *b){ |
| 160623 | 160825 | return 0; |
| 160624 | 160826 | } |
| 160625 | 160827 | |
| 160626 | 160828 | /* |
| 160627 | | -** Deregister and destroy an OTA vfs created by an earlier call to |
| 160628 | | -** sqlite3ota_create_vfs(). |
| 160829 | +** Deregister and destroy an RBU vfs created by an earlier call to |
| 160830 | +** sqlite3rbu_create_vfs(). |
| 160629 | 160831 | */ |
| 160630 | | -SQLITE_API void SQLITE_STDCALL sqlite3ota_destroy_vfs(const char *zName){ |
| 160832 | +SQLITE_API void SQLITE_STDCALL sqlite3rbu_destroy_vfs(const char *zName){ |
| 160631 | 160833 | sqlite3_vfs *pVfs = sqlite3_vfs_find(zName); |
| 160632 | | - if( pVfs && pVfs->xOpen==otaVfsOpen ){ |
| 160633 | | - sqlite3_mutex_free(((ota_vfs*)pVfs)->mutex); |
| 160834 | + if( pVfs && pVfs->xOpen==rbuVfsOpen ){ |
| 160835 | + sqlite3_mutex_free(((rbu_vfs*)pVfs)->mutex); |
| 160634 | 160836 | sqlite3_vfs_unregister(pVfs); |
| 160635 | 160837 | sqlite3_free(pVfs); |
| 160636 | 160838 | } |
| 160637 | 160839 | } |
| 160638 | 160840 | |
| 160639 | 160841 | /* |
| 160640 | | -** Create an OTA VFS named zName that accesses the underlying file-system |
| 160842 | +** Create an RBU VFS named zName that accesses the underlying file-system |
| 160641 | 160843 | ** via existing VFS zParent. The new object is registered as a non-default |
| 160642 | 160844 | ** VFS with SQLite before returning. |
| 160643 | 160845 | */ |
| 160644 | | -SQLITE_API int SQLITE_STDCALL sqlite3ota_create_vfs(const char *zName, const char *zParent){ |
| 160846 | +SQLITE_API int SQLITE_STDCALL sqlite3rbu_create_vfs(const char *zName, const char *zParent){ |
| 160645 | 160847 | |
| 160646 | 160848 | /* Template for VFS */ |
| 160647 | 160849 | static sqlite3_vfs vfs_template = { |
| 160648 | 160850 | 1, /* iVersion */ |
| 160649 | 160851 | 0, /* szOsFile */ |
| 160650 | 160852 | 0, /* mxPathname */ |
| 160651 | 160853 | 0, /* pNext */ |
| 160652 | 160854 | 0, /* zName */ |
| 160653 | 160855 | 0, /* pAppData */ |
| 160654 | | - otaVfsOpen, /* xOpen */ |
| 160655 | | - otaVfsDelete, /* xDelete */ |
| 160656 | | - otaVfsAccess, /* xAccess */ |
| 160657 | | - otaVfsFullPathname, /* xFullPathname */ |
| 160856 | + rbuVfsOpen, /* xOpen */ |
| 160857 | + rbuVfsDelete, /* xDelete */ |
| 160858 | + rbuVfsAccess, /* xAccess */ |
| 160859 | + rbuVfsFullPathname, /* xFullPathname */ |
| 160658 | 160860 | |
| 160659 | 160861 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 160660 | | - otaVfsDlOpen, /* xDlOpen */ |
| 160661 | | - otaVfsDlError, /* xDlError */ |
| 160662 | | - otaVfsDlSym, /* xDlSym */ |
| 160663 | | - otaVfsDlClose, /* xDlClose */ |
| 160862 | + rbuVfsDlOpen, /* xDlOpen */ |
| 160863 | + rbuVfsDlError, /* xDlError */ |
| 160864 | + rbuVfsDlSym, /* xDlSym */ |
| 160865 | + rbuVfsDlClose, /* xDlClose */ |
| 160664 | 160866 | #else |
| 160665 | 160867 | 0, 0, 0, 0, |
| 160666 | 160868 | #endif |
| 160667 | 160869 | |
| 160668 | | - otaVfsRandomness, /* xRandomness */ |
| 160669 | | - otaVfsSleep, /* xSleep */ |
| 160670 | | - otaVfsCurrentTime, /* xCurrentTime */ |
| 160671 | | - otaVfsGetLastError, /* xGetLastError */ |
| 160870 | + rbuVfsRandomness, /* xRandomness */ |
| 160871 | + rbuVfsSleep, /* xSleep */ |
| 160872 | + rbuVfsCurrentTime, /* xCurrentTime */ |
| 160873 | + rbuVfsGetLastError, /* xGetLastError */ |
| 160672 | 160874 | 0, /* xCurrentTimeInt64 (version 2) */ |
| 160673 | 160875 | 0, 0, 0 /* Unimplemented version 3 methods */ |
| 160674 | 160876 | }; |
| 160675 | 160877 | |
| 160676 | | - ota_vfs *pNew = 0; /* Newly allocated VFS */ |
| 160878 | + rbu_vfs *pNew = 0; /* Newly allocated VFS */ |
| 160677 | 160879 | int nName; |
| 160678 | 160880 | int rc = SQLITE_OK; |
| 160679 | 160881 | |
| 160680 | 160882 | int nByte; |
| 160681 | 160883 | nName = strlen(zName); |
| 160682 | | - nByte = sizeof(ota_vfs) + nName + 1; |
| 160683 | | - pNew = (ota_vfs*)sqlite3_malloc(nByte); |
| 160884 | + nByte = sizeof(rbu_vfs) + nName + 1; |
| 160885 | + pNew = (rbu_vfs*)sqlite3_malloc(nByte); |
| 160684 | 160886 | if( pNew==0 ){ |
| 160685 | 160887 | rc = SQLITE_NOMEM; |
| 160686 | 160888 | }else{ |
| 160687 | 160889 | sqlite3_vfs *pParent; /* Parent VFS */ |
| 160688 | 160890 | memset(pNew, 0, nByte); |
| | @@ -160691,11 +160893,11 @@ |
| 160691 | 160893 | rc = SQLITE_NOTFOUND; |
| 160692 | 160894 | }else{ |
| 160693 | 160895 | char *zSpace; |
| 160694 | 160896 | memcpy(&pNew->base, &vfs_template, sizeof(sqlite3_vfs)); |
| 160695 | 160897 | pNew->base.mxPathname = pParent->mxPathname; |
| 160696 | | - pNew->base.szOsFile = sizeof(ota_file) + pParent->szOsFile; |
| 160898 | + pNew->base.szOsFile = sizeof(rbu_file) + pParent->szOsFile; |
| 160697 | 160899 | pNew->pRealVfs = pParent; |
| 160698 | 160900 | pNew->base.zName = (const char*)(zSpace = (char*)&pNew[1]); |
| 160699 | 160901 | memcpy(zSpace, zName, nName); |
| 160700 | 160902 | |
| 160701 | 160903 | /* Allocate the mutex and register the new VFS (not as the default) */ |
| | @@ -160717,13 +160919,13 @@ |
| 160717 | 160919 | } |
| 160718 | 160920 | |
| 160719 | 160921 | |
| 160720 | 160922 | /**************************************************************************/ |
| 160721 | 160923 | |
| 160722 | | -#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA) */ |
| 160924 | +#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) */ |
| 160723 | 160925 | |
| 160724 | | -/************** End of sqlite3ota.c ******************************************/ |
| 160926 | +/************** End of sqlite3rbu.c ******************************************/ |
| 160725 | 160927 | /************** Begin file dbstat.c ******************************************/ |
| 160726 | 160928 | /* |
| 160727 | 160929 | ** 2010 July 12 |
| 160728 | 160930 | ** |
| 160729 | 160931 | ** The author disclaims copyright to this source code. In place of |
| | @@ -160741,10 +160943,11 @@ |
| 160741 | 160943 | ** information from an SQLite database in order to implement the |
| 160742 | 160944 | ** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script |
| 160743 | 160945 | ** for an example implementation. |
| 160744 | 160946 | */ |
| 160745 | 160947 | |
| 160948 | +/* #include "sqliteInt.h" ** Requires access to internal data structures ** */ |
| 160746 | 160949 | #if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \ |
| 160747 | 160950 | && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 160748 | 160951 | |
| 160749 | 160952 | /* |
| 160750 | 160953 | ** Page paths: |
| 160751 | 160954 | |