System.Data.SQLite
Check-in [d4447158f6]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Update SQLite core library to the latest trunk code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d4447158f660df8d74ed5ee0308eca8c1b29c54f
User & Date: mistachkin 2015-07-24 00:17:45
Context
2015-07-24
00:59
Enhance the test suite infrastructure to permit a non-default .NET Framework version to be used for a particular 'build year'. check-in: 13498a4979 user: mistachkin tags: trunk
00:32
Preliminary updates to the download page. check-in: 7dbf8439b5 user: mistachkin tags: preRelease
00:17
Update SQLite core library to the latest trunk code. check-in: d4447158f6 user: mistachkin tags: trunk
2015-07-23
04:40
In the batch build tool, attempt to make sure the target solution/project file matches up with the .NET Framework used. check-in: 49d0228259 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to SQLite.Interop/src/core/sqlite3.c.

   323    323   **
   324    324   ** See also: [sqlite3_libversion()],
   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-21 19:22:35 01c8b9ccfa0f336dfead7c004de3de571753f707"
          330  +#define SQLITE_SOURCE_ID      "2015-07-24 00:02:15 119883a21bdcab66c15d1e80f3da20addda328ad"
   331    331   
   332    332   /*
   333    333   ** CAPI3REF: Run-Time Library Version Numbers
   334    334   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   335    335   **
   336    336   ** These interfaces provide the same information as the [SQLITE_VERSION],
   337    337   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
  1177   1177   ** circumstances in order to fix a problem with priority inversion.
  1178   1178   ** Applications should <em>not</em> use this file-control.
  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
  1192   1192   #define SQLITE_FCNTL_SET_LOCKPROXYFILE       3
  1193   1193   #define SQLITE_FCNTL_LAST_ERRNO              4
................................................................................
  1207   1207   #define SQLITE_FCNTL_TRACE                  19
  1208   1208   #define SQLITE_FCNTL_HAS_MOVED              20
  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
  1220   1220   
  1221   1221   
................................................................................
118651 118651                 int nPk = pPk->nKeyCol;
118652 118652                 int iPk;
118653 118653   
118654 118654                 /* Read the PK into an array of temp registers. */
118655 118655                 r = sqlite3GetTempRange(pParse, nPk);
118656 118656                 for(iPk=0; iPk<nPk; iPk++){
118657 118657                   int iCol = pPk->aiColumn[iPk];
118658         -                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  +                }
118659 118663                 }
118660 118664   
118661 118665                 /* Check if the temp table already contains this key. If so,
118662 118666                 ** the row has already been included in the result set and
118663 118667                 ** can be ignored (by jumping past the Gosub below). Otherwise,
118664 118668                 ** insert the key into the temp table and proceed with processing
118665 118669                 ** the row.
................................................................................
130034 130038   ** The sz parameter is the number of bytes in each lookaside slot.
130035 130039   ** The cnt parameter is the number of slots.  If pStart is NULL the
130036 130040   ** space for the lookaside memory is obtained from sqlite3_malloc().
130037 130041   ** If pStart is not NULL then it is sz*cnt bytes of memory to use for
130038 130042   ** the lookaside memory.
130039 130043   */
130040 130044   static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
       130045  +#ifndef SQLITE_OMIT_LOOKASIDE
130041 130046     void *pStart;
130042 130047     if( db->lookaside.nOut ){
130043 130048       return SQLITE_BUSY;
130044 130049     }
130045 130050     /* Free any existing lookaside buffer for this handle before
130046 130051     ** allocating a new one so we don't have to have space for 
130047 130052     ** both at the same time.
................................................................................
130084 130089       db->lookaside.bMalloced = pBuf==0 ?1:0;
130085 130090     }else{
130086 130091       db->lookaside.pStart = db;
130087 130092       db->lookaside.pEnd = db;
130088 130093       db->lookaside.bEnabled = 0;
130089 130094       db->lookaside.bMalloced = 0;
130090 130095     }
       130096  +#endif /* SQLITE_OMIT_LOOKASIDE */
130091 130097     return SQLITE_OK;
130092 130098   }
130093 130099   
130094 130100   /*
130095 130101   ** Return the mutex associated with a database connection.
130096 130102   */
130097 130103   SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3 *db){
................................................................................
156828 156834     *ppModule = &icuTokenizerModule;
156829 156835   }
156830 156836   
156831 156837   #endif /* defined(SQLITE_ENABLE_ICU) */
156832 156838   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
156833 156839   
156834 156840   /************** End of fts3_icu.c ********************************************/
156835         -/************** Begin file sqlite3ota.c **************************************/
       156841  +/************** Begin file sqlite3rbu.c **************************************/
156836 156842   /*
156837 156843   ** 2014 August 30
156838 156844   **
156839 156845   ** The author disclaims copyright to this source code.  In place of
156840 156846   ** a legal notice, here is a blessing:
156841 156847   **
156842 156848   **    May you do good and not evil.
................................................................................
156844 156850   **    May you share freely, never taking more than you give.
156845 156851   **
156846 156852   *************************************************************************
156847 156853   **
156848 156854   **
156849 156855   ** OVERVIEW 
156850 156856   **
156851         -**  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
156852 156858   **  SQLite database. The tables it expects to find are described in
156853         -**  sqlite3ota.h.  Essentially, for each table xyz in the target database
       156859  +**  sqlite3rbu.h.  Essentially, for each table xyz in the target database
156854 156860   **  that the user wishes to write to, a corresponding data_xyz table is
156855         -**  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
156856 156862   **  update, insert or delete from the target table.
156857 156863   ** 
156858 156864   **  The update proceeds in three stages:
156859 156865   ** 
156860 156866   **  1) The database is updated. The modified database pages are written
156861 156867   **     to a *-oal file. A *-oal file is just like a *-wal file, except
156862 156868   **     that it is named "<database>-oal" instead of "<database>-wal".
156863 156869   **     Because regular SQLite clients do not look for file named
156864 156870   **     "<database>-oal", they go on using the original database in
156865 156871   **     rollback mode while the *-oal file is being generated.
156866 156872   ** 
156867         -**     During this stage OTA does not update the database by writing
       156873  +**     During this stage RBU does not update the database by writing
156868 156874   **     directly to the target tables. Instead it creates "imposter"
156869 156875   **     tables using the SQLITE_TESTCTRL_IMPOSTER interface that it uses
156870 156876   **     to update each b-tree individually. All updates required by each
156871 156877   **     b-tree are completed before moving on to the next, and all
156872 156878   **     updates are done in sorted key order.
156873 156879   ** 
156874 156880   **  2) The "<database>-oal" file is moved to the equivalent "<database>-wal"
156875         -**     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
156876 156882   **     module takes an EXCLUSIVE lock on the database file, ensuring
156877 156883   **     that there are no other active readers.
156878 156884   ** 
156879 156885   **     Once the EXCLUSIVE lock is released, any other database readers
156880 156886   **     detect the new *-wal file and read the database in wal mode. At
156881 156887   **     this point they see the new version of the database - including
156882         -**     the updates made as part of the OTA update.
       156888  +**     the updates made as part of the RBU update.
156883 156889   ** 
156884 156890   **  3) The new *-wal file is checkpointed. This proceeds in the same way 
156885 156891   **     as a regular database checkpoint, except that a single frame is
156886         -**     checkpointed each time sqlite3ota_step() is called. If the OTA
       156892  +**     checkpointed each time sqlite3rbu_step() is called. If the RBU
156887 156893   **     handle is closed before the entire *-wal file is checkpointed,
156888         -**     the checkpoint progress is saved in the OTA database and the
156889         -**     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
156890 156896   **     the future.
156891 156897   **
156892 156898   ** POTENTIAL PROBLEMS
156893 156899   ** 
156894         -**  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
156895 156901   **  syncing the directory after renaming the file.
156896 156902   **
156897 156903   **  When state is saved, any commit to the *-oal file and the commit to
156898         -**  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
156899 156905   **  wrong moment they might get out of sync. As the main database will be
156900         -**  committed before the OTA update database this will likely either just
       156906  +**  committed before the RBU update database this will likely either just
156901 156907   **  pass unnoticed, or result in SQLITE_CONSTRAINT errors (due to UNIQUE
156902 156908   **  constraint violations).
156903 156909   **
156904         -**  If some client does modify the target database mid OTA update, or some
156905         -**  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
156906 156912   **  not really clear how to get out of this state. The system could just
156907         -**  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
156908 156914   **  download the update again and start over.
156909 156915   **
156910 156916   **  At present, for an UPDATE, both the new.* and old.* records are
156911         -**  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
156912 156918   **  fields are collected.  This means we're probably writing a lot more
156913         -**  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
156914 156920   **  update database than is strictly necessary.
156915 156921   ** 
156916 156922   */
156917 156923   
156918 156924   /* #include <assert.h> */
156919 156925   /* #include <string.h> */
156920 156926   /* #include <stdio.h> */
156921 156927   /* #include <unistd.h> */
156922 156928   
156923 156929   /* #include "sqlite3.h" */
156924 156930   
156925         -#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA)
156926         -/************** Include sqlite3ota.h in the middle of sqlite3ota.c ***********/
156927         -/************** 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 **************************************/
156928 156934   /*
156929 156935   ** 2014 August 30
156930 156936   **
156931 156937   ** The author disclaims copyright to this source code.  In place of
156932 156938   ** a legal notice, here is a blessing:
156933 156939   **
156934 156940   **    May you do good and not evil.
156935 156941   **    May you find forgiveness for yourself and forgive others.
156936 156942   **    May you share freely, never taking more than you give.
156937 156943   **
156938 156944   *************************************************************************
156939 156945   **
156940         -** This file contains the public interface for the OTA extension. 
       156946  +** This file contains the public interface for the RBU extension. 
156941 156947   */
156942 156948   
156943 156949   /*
156944 156950   ** SUMMARY
156945 156951   **
156946 156952   ** Writing a transaction containing a large number of operations on 
156947 156953   ** b-tree indexes that are collectively larger than the available cache
................................................................................
156970 156976   ** guarantee that a single update process will run for long enough to apply 
156971 156977   ** the entire update, for example because the update is being applied on a 
156972 156978   ** mobile device that is frequently rebooted. Even after the writer process 
156973 156979   ** has committed one or more sub-transactions, other database clients continue
156974 156980   ** to read from the original database snapshot. In other words, partially 
156975 156981   ** applied transactions are not visible to other clients. 
156976 156982   **
156977         -** "OTA" stands for "Over The Air" update. As in a large database update
       156983  +** "RBU" stands for "Resumable Bulk Update". As in a large database update
156978 156984   ** transmitted via a wireless network to a mobile device. A transaction
156979         -** 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".
156980 156986   **
156981 156987   **
156982 156988   ** LIMITATIONS
156983 156989   **
156984         -** An "OTA update" transaction is subject to the following limitations:
       156990  +** An "RBU update" transaction is subject to the following limitations:
156985 156991   **
156986 156992   **   * The transaction must consist of INSERT, UPDATE and DELETE operations
156987 156993   **     only.
156988 156994   **
156989 156995   **   * INSERT statements may not use any default values.
156990 156996   **
156991 156997   **   * UPDATE and DELETE statements must identify their target rows by 
................................................................................
157002 157008   **   * CHECK constraints are not enforced.
157003 157009   **
157004 157010   **   * No constraint handling mode except for "OR ROLLBACK" is supported.
157005 157011   **
157006 157012   **
157007 157013   ** PREPARATION
157008 157014   **
157009         -** An "OTA update" is stored as a separate SQLite database. A database
157010         -** containing an OTA update is an "OTA database". For each table in the 
157011         -** 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
157012 157018   ** named "data_<target name>" containing the same set of columns as the
157013         -** target table, and one more - "ota_control". The data_% table should 
       157019  +** target table, and one more - "rbu_control". The data_% table should 
157014 157020   ** have no PRIMARY KEY or UNIQUE constraints, but each column should have
157015 157021   ** the same type as the corresponding column in the target database.
157016         -** 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
157017 157023   ** the target database contains:
157018 157024   **
157019 157025   **   CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c UNIQUE);
157020 157026   **
157021         -** Then the OTA database should contain:
       157027  +** Then the RBU database should contain:
157022 157028   **
157023         -**   CREATE TABLE data_t1(a INTEGER, b TEXT, c, ota_control);
       157029  +**   CREATE TABLE data_t1(a INTEGER, b TEXT, c, rbu_control);
157024 157030   **
157025 157031   ** The order of the columns in the data_% table does not matter.
157026 157032   **
157027 157033   ** If the target database table is a virtual table or a table that has no
157028 157034   ** PRIMARY KEY declaration, the data_% table must also contain a column 
157029         -** 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 
157030 157036   ** key column - "rowid". Virtual tables for which the "rowid" column does 
157031         -** 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 
157032 157038   ** example, if the target db contains either of the following:
157033 157039   **
157034 157040   **   CREATE VIRTUAL TABLE x1 USING fts3(a, b);
157035 157041   **   CREATE TABLE x1(a, b)
157036 157042   **
157037         -** then the OTA database should contain:
       157043  +** then the RBU database should contain:
157038 157044   **
157039         -**   CREATE TABLE data_x1(a, b, ota_rowid, ota_control);
       157045  +**   CREATE TABLE data_x1(a, b, rbu_rowid, rbu_control);
157040 157046   **
157041 157047   ** All non-hidden columns (i.e. all columns matched by "SELECT *") of the
157042 157048   ** target table must be present in the input table. For virtual tables,
157043         -** 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
157044 157050   ** the input table, or not otherwise. For example, to write to an fts4
157045 157051   ** table with a hidden languageid column such as:
157046 157052   **
157047 157053   **   CREATE VIRTUAL TABLE ft1 USING fts4(a, b, languageid='langid');
157048 157054   **
157049 157055   ** Either of the following input table schemas may be used:
157050 157056   **
157051         -**   CREATE TABLE data_ft1(a, b, langid, ota_rowid, ota_control);
157052         -**   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);
157053 157059   **
157054         -** 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 
157055 157061   ** update, the corresponding data_% table should contain a single record
157056         -** 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
157057 157063   ** other columns should be set to the values that make up the new record 
157058 157064   ** to insert. 
157059 157065   **
157060 157066   ** If the target database table has an INTEGER PRIMARY KEY, it is not 
157061 157067   ** possible to insert a NULL value into the IPK column. Attempting to 
157062 157068   ** do so results in an SQLITE_MISMATCH error.
157063 157069   **
157064         -** 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 
157065 157071   ** update, the corresponding data_% table should contain a single record
157066         -** 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
157067 157073   ** real primary key values of the row to delete should be stored in the
157068 157074   ** corresponding columns of the data_% table. The values stored in the
157069 157075   ** other columns are not used.
157070 157076   **
157071         -** 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 
157072 157078   ** update, the corresponding data_% table should contain a single record
157073         -** 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.
157074 157080   ** The real primary key values identifying the row to update should be 
157075 157081   ** stored in the corresponding columns of the data_% table row, as should
157076 157082   ** the new values of all columns being update. The text value in the 
157077         -** "ota_control" column must contain the same number of characters as
       157083  +** "rbu_control" column must contain the same number of characters as
157078 157084   ** there are columns in the target database table, and must consist entirely
157079 157085   ** of 'x' and '.' characters (or in some special cases 'd' - see below). For 
157080 157086   ** each column that is being updated, the corresponding character is set to
157081 157087   ** 'x'. For those that remain as they are, the corresponding character of the
157082         -** 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 
157083 157089   ** above, the update statement:
157084 157090   **
157085 157091   **   UPDATE t1 SET c = 'usa' WHERE a = 4;
157086 157092   **
157087 157093   ** is represented by the data_t1 row created by:
157088 157094   **
157089         -**   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');
157090 157096   **
157091         -** 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
157092 157098   ** for UPDATEs may also be set to 'd'. In this case, instead of updating the
157093 157099   ** target table with the value stored in the corresponding data_% column, the
157094         -** user-defined SQL function "ota_delta()" is invoked and the result stored in
157095         -** 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
157096 157102   ** original value currently stored in the target table column and the 
157097 157103   ** value specified in the data_xxx table.
157098 157104   **
157099 157105   ** For example, this row:
157100 157106   **
157101         -**   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');
157102 157108   **
157103 157109   ** is similar to an UPDATE statement such as: 
157104 157110   **
157105         -**   UPDATE t1 SET c = ota_delta(c, 'usa') WHERE a = 4;
       157111  +**   UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4;
157106 157112   **
157107 157113   ** If the target database table is a virtual table or a table with no PRIMARY
157108         -** KEY, the ota_control value should not include a character corresponding 
157109         -** 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:
157110 157116   **
157111         -**   INSERT INTO data_ft1(a, b, ota_rowid, ota_control) 
       157117  +**   INSERT INTO data_ft1(a, b, rbu_rowid, rbu_control) 
157112 157118   **       VALUES(NULL, 'usa', 12, '.x');
157113 157119   **
157114 157120   ** causes a result similar to:
157115 157121   **
157116 157122   **   UPDATE ft1 SET b = 'usa' WHERE rowid = 12;
157117 157123   **
157118 157124   ** The data_xxx tables themselves should have no PRIMARY KEY declarations.
157119         -** 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
157120 157126   ** table in "rowid" order is roughly the same as reading them sorted by
157121 157127   ** the PRIMARY KEY of the corresponding target database table. In other 
157122 157128   ** words, rows should be sorted using the destination table PRIMARY KEY 
157123 157129   ** fields before they are inserted into the data_xxx tables.
157124 157130   **
157125 157131   ** USAGE
157126 157132   **
157127         -** 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 
157128 157134   ** stored on disk to an existing target database. Essentially, the 
157129 157135   ** application:
157130 157136   **
157131         -**     1) Opens an OTA handle using the sqlite3ota_open() function.
       157137  +**     1) Opens an RBU handle using the sqlite3rbu_open() function.
157132 157138   **
157133 157139   **     2) Registers any required virtual table modules with the database
157134         -**        handle returned by sqlite3ota_db(). Also, if required, register
157135         -**        the ota_delta() implementation.
       157140  +**        handle returned by sqlite3rbu_db(). Also, if required, register
       157141  +**        the rbu_delta() implementation.
157136 157142   **
157137         -**     3) Calls the sqlite3ota_step() function one or more times on
157138         -**        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
157139 157145   **        b-tree operation, so thousands of calls may be required to apply 
157140 157146   **        a complete update.
157141 157147   **
157142         -**     4) Calls sqlite3ota_close() to close the OTA update handle. If
157143         -**        sqlite3ota_step() has been called enough times to completely
157144         -**        apply the update to the target database, then the OTA database
157145         -**        is marked as fully applied. Otherwise, the state of the OTA 
157146         -**        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 
157147 157153   **        resumption.
157148 157154   **
157149 157155   ** See comments below for more detail on APIs.
157150 157156   **
157151 157157   ** If an update is only partially applied to the target database by the
157152         -** time sqlite3ota_close() is called, various state information is saved 
157153         -** within the OTA database. This allows subsequent processes to automatically
157154         -** 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.
157155 157161   **
157156         -** To remove all OTA extension state information, returning an OTA database 
       157162  +** To remove all RBU extension state information, returning an RBU database 
157157 157163   ** to its original contents, it is sufficient to drop all tables that begin
157158         -** with the prefix "ota_"
       157164  +** with the prefix "rbu_"
157159 157165   **
157160 157166   ** DATABASE LOCKING
157161 157167   **
157162         -** 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
157163 157169   ** to do so is an error (SQLITE_ERROR).
157164 157170   **
157165         -** 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
157166 157172   ** database file. This means it is possible for other clients to read the
157167 157173   ** database, but not to write it.
157168 157174   **
157169         -** 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,
157170 157176   ** then an external client writes to the database, then attempting to resume
157171         -** the suspended OTA update is also an error (SQLITE_BUSY).
       157177  +** the suspended RBU update is also an error (SQLITE_BUSY).
157172 157178   */
157173 157179   
157174         -#ifndef _SQLITE3OTA_H
157175         -#define _SQLITE3OTA_H
       157180  +#ifndef _SQLITE3RBU_H
       157181  +#define _SQLITE3RBU_H
157176 157182   
157177 157183   /* #include "sqlite3.h"              ** Required for error code definitions ** */
157178 157184   
157179         -typedef struct sqlite3ota sqlite3ota;
       157185  +typedef struct sqlite3rbu sqlite3rbu;
157180 157186   
157181 157187   /*
157182         -** Open an OTA handle.
       157188  +** Open an RBU handle.
157183 157189   **
157184         -** Argument zTarget is the path to the target database. Argument zOta is
157185         -** the path to the OTA database. Each call to this function must be matched
157186         -** 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
157187 157193   ** the SQLITE_CONFIG_URI flag to sqlite3_open_v2(). So if either zTarget
157188         -** 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 
157189 157195   ** database URI, not a regular file name.
157190 157196   **
157191         -** 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 
157192 157198   ** the current state of the update (how many rows have been updated, which 
157193         -** indexes are yet to be updated etc.) within the OTA database itself. This
157194         -** 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
157195 157201   ** organize removing a separate state file after the update is concluded. 
157196 157202   ** Or, if zState is non-NULL, it must be a path to a database file in which 
157197         -** the OTA extension can store the state of the update.
       157203  +** the RBU extension can store the state of the update.
157198 157204   **
157199         -** When resuming an OTA update, the zState argument must be passed the same
157200         -** 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.
157201 157207   **
157202         -** Once the OTA update is finished, the OTA extension does not 
       157208  +** Once the RBU update is finished, the RBU extension does not 
157203 157209   ** automatically remove any zState database file, even if it created it.
157204 157210   **
157205         -** 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
157206 157212   ** use a VFS other than the default, an SQLite "file:" URI containing a
157207 157213   ** "vfs=..." option may be passed as the zTarget option.
157208 157214   **
157209         -** 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
157210 157216   ** SQLite's built-in VFSs, including the multiplexor VFS. However it does
157211 157217   ** not work out of the box with zipvfs. Refer to the comment describing
157212         -** 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.
157213 157219   */
157214         -SQLITE_API sqlite3ota *SQLITE_STDCALL sqlite3ota_open(
       157220  +SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
157215 157221     const char *zTarget, 
157216         -  const char *zOta,
       157222  +  const char *zRbu,
157217 157223     const char *zState
157218 157224   );
157219 157225   
157220 157226   /*
157221         -** Internally, each OTA connection uses a separate SQLite database 
157222         -** 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
157223 157229   ** API allows the application direct access to these database handles.
157224 157230   **
157225         -** 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
157226 157232   ** handle. The second argument should be passed zero to access the target
157227         -** 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.
157228 157234   ** Accessing the underlying database handles may be useful in the
157229 157235   ** following scenarios:
157230 157236   **
157231 157237   **   * If any target tables are virtual tables, it may be necessary to
157232 157238   **     call sqlite3_create_module() on the target database handle to 
157233 157239   **     register the required virtual table implementations.
157234 157240   **
157235         -**   * 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 
157236 157242   **     tables, the application may need to call sqlite3_create_module() on
157237         -**     the ota update db handle to any required virtual table
       157243  +**     the rbu update db handle to any required virtual table
157238 157244   **     implementations.
157239 157245   **
157240         -**   * If the application uses the "ota_delta()" feature described above,
       157246  +**   * If the application uses the "rbu_delta()" feature described above,
157241 157247   **     it must use sqlite3_create_function() or similar to register the
157242         -**     ota_delta() implementation with the target database handle.
       157248  +**     rbu_delta() implementation with the target database handle.
157243 157249   **
157244         -** 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,
157245 157251   ** this function may return NULL. The error code and message may be collected
157246         -** when sqlite3ota_close() is called.
       157252  +** when sqlite3rbu_close() is called.
157247 157253   */
157248         -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3ota_db(sqlite3ota*, int bOta);
       157254  +SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu*, int bRbu);
157249 157255   
157250 157256   /*
157251         -** 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. 
157252 157258   **
157253 157259   ** Return SQLITE_DONE if the update has been completely applied, or 
157254 157260   ** SQLITE_OK if no error occurs but there remains work to do to apply
157255         -** 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 
157256 157262   ** returned. 
157257 157263   **
157258         -** Once a call to sqlite3ota_step() has returned a value other than
157259         -** 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
157260 157266   ** that immediately return the same value.
157261 157267   */
157262         -SQLITE_API int SQLITE_STDCALL sqlite3ota_step(sqlite3ota *pOta);
       157268  +SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *pRbu);
157263 157269   
157264 157270   /*
157265         -** Close an OTA handle. 
       157271  +** Close an RBU handle. 
157266 157272   **
157267         -** 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
157268 157274   ** as fully applied. Otherwise, assuming no error has occurred, save the
157269         -** current state of the OTA update appliation to the OTA database.
       157275  +** current state of the RBU update appliation to the RBU database.
157270 157276   **
157271         -** If an error has already occurred as part of an sqlite3ota_step()
157272         -** 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
157273 157279   ** SQLite error code is returned. Additionally, *pzErrmsg may be set to
157274 157280   ** point to a buffer containing a utf-8 formatted English language error
157275 157281   ** message. It is the responsibility of the caller to eventually free any 
157276 157282   ** such buffer using sqlite3_free().
157277 157283   **
157278 157284   ** Otherwise, if no error occurs, this function returns SQLITE_OK if the
157279 157285   ** update has been partially applied, or SQLITE_DONE if it has been 
157280 157286   ** completely applied.
157281 157287   */
157282         -SQLITE_API int SQLITE_STDCALL sqlite3ota_close(sqlite3ota *pOta, char **pzErrmsg);
       157288  +SQLITE_API int SQLITE_STDCALL sqlite3rbu_close(sqlite3rbu *pRbu, char **pzErrmsg);
157283 157289   
157284 157290   /*
157285 157291   ** Return the total number of key-value operations (inserts, deletes or 
157286 157292   ** updates) that have been performed on the target database since the
157287         -** current OTA update was started.
       157293  +** current RBU update was started.
157288 157294   */
157289         -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3ota_progress(sqlite3ota *pOta);
       157295  +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3rbu_progress(sqlite3rbu *pRbu);
157290 157296   
157291 157297   /*
157292         -** 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
157293 157299   ** via existing VFS zParent. Or, if the zParent parameter is passed NULL, 
157294         -** 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.
157295 157301   ** The new object is registered as a non-default VFS with SQLite before 
157296 157302   ** returning.
157297 157303   **
157298         -** Part of the OTA implementation uses a custom VFS object. Usually, this
157299         -** 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. 
157300 157306   **
157301 157307   ** The exception is for applications that also use zipvfs. In this case,
157302         -** the custom VFS must be explicitly created by the user before the OTA
157303         -** handle is opened. The OTA VFS should be installed so that the zipvfs
157304         -** 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 
157305 157311   ** (for example multiplexor) to access the file-system. For example,
157306         -** 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 
157307 157313   ** multiplexor (error checking omitted):
157308 157314   **
157309 157315   **     // Create a VFS named "multiplex" (not the default).
157310 157316   **     sqlite3_multiplex_initialize(0, 0);
157311 157317   **
157312         -**     // Create an ota VFS named "ota" that uses multiplexor. If the
157313         -**     // 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
157314 157320   **     // access the file-system via the system default VFS, bypassing the
157315 157321   **     // multiplexor.
157316         -**     sqlite3ota_create_vfs("ota", "multiplex");
       157322  +**     sqlite3rbu_create_vfs("rbu", "multiplex");
157317 157323   **
157318         -**     // Create a zipvfs VFS named "zipvfs" that uses ota.
157319         -**     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);
157320 157326   **
157321 157327   **     // Make zipvfs the default VFS.
157322 157328   **     sqlite3_vfs_register(sqlite3_vfs_find("zipvfs"), 1);
157323 157329   **
157324         -** Because the default VFS created above includes a OTA functionality, it
157325         -** may be used by OTA clients. Attempting to use OTA with a zipvfs VFS stack
157326         -** 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.
157327 157333   **
157328         -** The overhead of adding the "ota" VFS to the system is negligible for 
157329         -** non-OTA users. There is no harm in an application accessing the 
157330         -** 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 
157331 157337   ** occasionally.
157332 157338   */
157333         -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);
157334 157340   
157335 157341   /*
157336         -** Deregister and destroy an OTA vfs created by an earlier call to
157337         -** sqlite3ota_create_vfs().
       157342  +** Deregister and destroy an RBU vfs created by an earlier call to
       157343  +** sqlite3rbu_create_vfs().
157338 157344   **
157339 157345   ** VFS objects are not reference counted. If a VFS object is destroyed
157340 157346   ** before all database handles that use it have been closed, the results
157341 157347   ** are undefined.
157342 157348   */
157343         -SQLITE_API void SQLITE_STDCALL sqlite3ota_destroy_vfs(const char *zName);
       157349  +SQLITE_API void SQLITE_STDCALL sqlite3rbu_destroy_vfs(const char *zName);
157344 157350   
157345         -#endif /* _SQLITE3OTA_H */
       157351  +#endif /* _SQLITE3RBU_H */
157346 157352   
157347         -/************** End of sqlite3ota.h ******************************************/
157348         -/************** Continuing where we left off in sqlite3ota.c *****************/
       157353  +/************** End of sqlite3rbu.h ******************************************/
       157354  +/************** Continuing where we left off in sqlite3rbu.c *****************/
157349 157355   
157350 157356   /* Maximum number of prepared UPDATE statements held by this module */
157351         -#define SQLITE_OTA_UPDATE_CACHESIZE 16
       157357  +#define SQLITE_RBU_UPDATE_CACHESIZE 16
157352 157358   
157353 157359   /*
157354 157360   ** Swap two objects of type TYPE.
157355 157361   */
157356 157362   #if !defined(SQLITE_AMALGAMATION)
157357 157363   # define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
157358 157364   #endif
157359 157365   
157360 157366   /*
157361         -** 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
157362 157368   ** update so that it can be resumed later. The table consists of integer
157363 157369   ** keys mapped to values as follows:
157364 157370   **
157365         -** OTA_STATE_STAGE:
       157371  +** RBU_STATE_STAGE:
157366 157372   **   May be set to integer values 1, 2, 4 or 5. As follows:
157367         -**       1: the *-ota file is currently under construction.
157368         -**       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 
157369 157375   **          to the *-wal path.
157370 157376   **       4: the checkpoint is underway.
157371         -**       5: the ota update has been checkpointed.
       157377  +**       5: the rbu update has been checkpointed.
157372 157378   **
157373         -** OTA_STATE_TBL:
       157379  +** RBU_STATE_TBL:
157374 157380   **   Only valid if STAGE==1. The target database name of the table 
157375 157381   **   currently being written.
157376 157382   **
157377         -** OTA_STATE_IDX:
       157383  +** RBU_STATE_IDX:
157378 157384   **   Only valid if STAGE==1. The target database name of the index 
157379 157385   **   currently being written, or NULL if the main table is currently being
157380 157386   **   updated.
157381 157387   **
157382         -** OTA_STATE_ROW:
       157388  +** RBU_STATE_ROW:
157383 157389   **   Only valid if STAGE==1. Number of rows already processed for the current
157384 157390   **   table/index.
157385 157391   **
157386         -** OTA_STATE_PROGRESS:
157387         -**   Total number of sqlite3ota_step() calls made so far as part of this
157388         -**   ota update.
       157392  +** RBU_STATE_PROGRESS:
       157393  +**   Trbul number of sqlite3rbu_step() calls made so far as part of this
       157394  +**   rbu update.
157389 157395   **
157390         -** OTA_STATE_CKPT:
       157396  +** RBU_STATE_CKPT:
157391 157397   **   Valid if STAGE==4. The 64-bit checksum associated with the wal-index
157392 157398   **   header created by recovering the *-wal file. This is used to detect
157393 157399   **   cases when another client appends frames to the *-wal file in the
157394 157400   **   middle of an incremental checkpoint (an incremental checkpoint cannot
157395 157401   **   be continued if this happens).
157396 157402   **
157397         -** OTA_STATE_COOKIE:
       157403  +** RBU_STATE_COOKIE:
157398 157404   **   Valid if STAGE==1. The current change-counter cookie value in the 
157399 157405   **   target db file.
157400 157406   **
157401         -** OTA_STATE_OALSZ:
       157407  +** RBU_STATE_OALSZ:
157402 157408   **   Valid if STAGE==1. The size in bytes of the *-oal file.
157403 157409   */
157404         -#define OTA_STATE_STAGE       1
157405         -#define OTA_STATE_TBL         2
157406         -#define OTA_STATE_IDX         3
157407         -#define OTA_STATE_ROW         4
157408         -#define OTA_STATE_PROGRESS    5
157409         -#define OTA_STATE_CKPT        6
157410         -#define OTA_STATE_COOKIE      7
157411         -#define OTA_STATE_OALSZ       8
157412         -
157413         -#define OTA_STAGE_OAL         1
157414         -#define OTA_STAGE_MOVE        2
157415         -#define OTA_STAGE_CAPTURE     3
157416         -#define OTA_STAGE_CKPT        4
157417         -#define OTA_STAGE_DONE        5
157418         -
157419         -
157420         -#define OTA_CREATE_STATE \
157421         -  "CREATE TABLE IF NOT EXISTS %s.ota_state(k INTEGER PRIMARY KEY, v)"
157422         -
157423         -typedef struct OtaFrame OtaFrame;
157424         -typedef struct OtaObjIter OtaObjIter;
157425         -typedef struct OtaState OtaState;
157426         -typedef struct ota_vfs ota_vfs;
157427         -typedef struct ota_file ota_file;
157428         -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;
157429 157435   
157430 157436   #if !defined(SQLITE_AMALGAMATION)
157431 157437   typedef unsigned int u32;
157432 157438   typedef unsigned char u8;
157433 157439   typedef sqlite3_int64 i64;
157434 157440   #endif
157435 157441   
................................................................................
157439 157445   ** format.
157440 157446   */
157441 157447   #define WAL_LOCK_WRITE  0
157442 157448   #define WAL_LOCK_CKPT   1
157443 157449   #define WAL_LOCK_READ0  3
157444 157450   
157445 157451   /*
157446         -** 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.
157447 157453   */
157448         -struct OtaState {
       157454  +struct RbuState {
157449 157455     int eStage;
157450 157456     char *zTbl;
157451 157457     char *zIdx;
157452 157458     i64 iWalCksum;
157453 157459     int nRow;
157454 157460     i64 nProgress;
157455 157461     u32 iCookie;
157456 157462     i64 iOalSz;
157457 157463   };
157458 157464   
157459         -struct OtaUpdateStmt {
       157465  +struct RbuUpdateStmt {
157460 157466     char *zMask;                    /* Copy of update mask used with pUpdate */
157461 157467     sqlite3_stmt *pUpdate;          /* Last update statement (or NULL) */
157462         -  OtaUpdateStmt *pNext;
       157468  +  RbuUpdateStmt *pNext;
157463 157469   };
157464 157470   
157465 157471   /*
157466 157472   ** An iterator of this type is used to iterate through all objects in
157467 157473   ** the target database that require updating. For each such table, the
157468 157474   ** iterator visits, in order:
157469 157475   **
................................................................................
157474 157480   ** abIndexed:
157475 157481   **   If the table has no indexes on it, abIndexed is set to NULL. Otherwise,
157476 157482   **   it points to an array of flags nTblCol elements in size. The flag is
157477 157483   **   set for each column that is either a part of the PK or a part of an
157478 157484   **   index. Or clear otherwise.
157479 157485   **   
157480 157486   */
157481         -struct OtaObjIter {
       157487  +struct RbuObjIter {
157482 157488     sqlite3_stmt *pTblIter;         /* Iterate through tables */
157483 157489     sqlite3_stmt *pIdxIter;         /* Index iterator */
157484 157490     int nTblCol;                    /* Size of azTblCol[] array */
157485 157491     char **azTblCol;                /* Array of unquoted target column names */
157486 157492     char **azTblType;               /* Array of target column types */
157487 157493     int *aiSrcOrder;                /* src table col -> target table col */
157488 157494     u8 *abTblPk;                    /* Array of flags, set on target PK columns */
157489 157495     u8 *abNotNull;                  /* Array of flags, set on NOT NULL columns */
157490 157496     u8 *abIndexed;                  /* Array of flags, set on indexed & PK cols */
157491         -  int eType;                      /* Table type - an OTA_PK_XXX value */
       157497  +  int eType;                      /* Table type - an RBU_PK_XXX value */
157492 157498   
157493 157499     /* Output variables. zTbl==0 implies EOF. */
157494 157500     int bCleanup;                   /* True in "cleanup" state */
157495 157501     const char *zTbl;               /* Name of target db table */
157496 157502     const char *zIdx;               /* Name of target db index (or null) */
157497 157503     int iTnum;                      /* Root page of current object */
157498 157504     int iPkTnum;                    /* If eType==EXTERNAL, root of PK index */
157499 157505     int bUnique;                    /* Current index is unique */
157500 157506   
157501         -  /* Statements created by otaObjIterPrepareAll() */
       157507  +  /* Statements created by rbuObjIterPrepareAll() */
157502 157508     int nCol;                       /* Number of columns in current object */
157503 157509     sqlite3_stmt *pSelect;          /* Source data */
157504 157510     sqlite3_stmt *pInsert;          /* Statement for INSERT operations */
157505 157511     sqlite3_stmt *pDelete;          /* Statement for DELETE ops */
157506         -  sqlite3_stmt *pTmpInsert;       /* Insert into ota_tmp_$zTbl */
       157512  +  sqlite3_stmt *pTmpInsert;       /* Insert into rbu_tmp_$zTbl */
157507 157513   
157508 157514     /* Last UPDATE used (for PK b-tree updates only), or NULL. */
157509         -  OtaUpdateStmt *pOtaUpdate;
       157515  +  RbuUpdateStmt *pRbuUpdate;
157510 157516   };
157511 157517   
157512 157518   /*
157513         -** Values for OtaObjIter.eType
       157519  +** Values for RbuObjIter.eType
157514 157520   **
157515 157521   **     0: Table does not exist (error)
157516 157522   **     1: Table has an implicit rowid.
157517 157523   **     2: Table has an explicit IPK column.
157518 157524   **     3: Table has an external PK index.
157519 157525   **     4: Table is WITHOUT ROWID.
157520 157526   **     5: Table is a virtual table.
157521 157527   */
157522         -#define OTA_PK_NOTABLE        0
157523         -#define OTA_PK_NONE           1
157524         -#define OTA_PK_IPK            2
157525         -#define OTA_PK_EXTERNAL       3
157526         -#define OTA_PK_WITHOUT_ROWID  4
157527         -#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
157528 157534   
157529 157535   
157530 157536   /*
157531         -** 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
157532 157538   ** one of the following operations.
157533 157539   */
157534         -#define OTA_INSERT     1          /* Insert on a main table b-tree */
157535         -#define OTA_DELETE     2          /* Delete a row from a main table b-tree */
157536         -#define OTA_IDX_DELETE 3          /* Delete a row from an aux. index b-tree */
157537         -#define OTA_IDX_INSERT 4          /* Insert on an aux. index b-tree */
157538         -#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 */
157539 157545   
157540 157546   
157541 157547   /*
157542 157548   ** A single step of an incremental checkpoint - frame iWalFrame of the wal
157543 157549   ** file should be copied to page iDbPage of the database file.
157544 157550   */
157545         -struct OtaFrame {
       157551  +struct RbuFrame {
157546 157552     u32 iDbPage;
157547 157553     u32 iWalFrame;
157548 157554   };
157549 157555   
157550 157556   /*
157551         -** OTA handle.
       157557  +** RBU handle.
157552 157558   */
157553         -struct sqlite3ota {
157554         -  int eStage;                     /* Value of OTA_STATE_STAGE field */
       157559  +struct sqlite3rbu {
       157560  +  int eStage;                     /* Value of RBU_STATE_STAGE field */
157555 157561     sqlite3 *dbMain;                /* target database handle */
157556         -  sqlite3 *dbOta;                 /* ota database handle */
       157562  +  sqlite3 *dbRbu;                 /* rbu database handle */
157557 157563     char *zTarget;                  /* Path to target db */
157558         -  char *zOta;                     /* Path to ota db */
157559         -  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) */
157560 157566     char zStateDb[5];               /* Db name for state ("stat" or "main") */
157561         -  int rc;                         /* Value returned by last ota_step() call */
       157567  +  int rc;                         /* Value returned by last rbu_step() call */
157562 157568     char *zErrmsg;                  /* Error message if rc!=SQLITE_OK */
157563 157569     int nStep;                      /* Rows processed for current object */
157564 157570     int nProgress;                  /* Rows processed for all objects */
157565         -  OtaObjIter objiter;             /* Iterator for skipping through tbl/idx */
157566         -  const char *zVfsName;           /* Name of automatically created ota vfs */
157567         -  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 */
157568 157574     i64 iOalSz;
157569 157575   
157570 157576     /* The following state variables are used as part of the incremental
157571         -  ** checkpoint stage (eStage==OTA_STAGE_CKPT). See comments surrounding
157572         -  ** function otaSetupCheckpoint() for details.  */
       157577  +  ** checkpoint stage (eStage==RBU_STAGE_CKPT). See comments surrounding
       157578  +  ** function rbuSetupCheckpoint() for details.  */
157573 157579     u32 iMaxFrame;                  /* Largest iWalFrame value in aFrame[] */
157574 157580     u32 mLock;
157575 157581     int nFrame;                     /* Entries in aFrame[] array */
157576 157582     int nFrameAlloc;                /* Allocated size of aFrame[] array */
157577         -  OtaFrame *aFrame;
       157583  +  RbuFrame *aFrame;
157578 157584     int pgsz;
157579 157585     u8 *aBuf;
157580 157586     i64 iWalCksum;
157581 157587   };
157582 157588   
157583 157589   /*
157584         -** An ota VFS is implemented using an instance of this structure.
       157590  +** An rbu VFS is implemented using an instance of this structure.
157585 157591   */
157586         -struct ota_vfs {
157587         -  sqlite3_vfs base;               /* ota VFS shim methods */
       157592  +struct rbu_vfs {
       157593  +  sqlite3_vfs base;               /* rbu VFS shim methods */
157588 157594     sqlite3_vfs *pRealVfs;          /* Underlying VFS */
157589 157595     sqlite3_mutex *mutex;           /* Mutex to protect pMain */
157590         -  ota_file *pMain;                /* Linked list of main db files */
       157596  +  rbu_file *pMain;                /* Linked list of main db files */
157591 157597   };
157592 157598   
157593 157599   /*
157594         -** 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
157595 157601   ** the following structure.
157596 157602   */
157597         -struct ota_file {
       157603  +struct rbu_file {
157598 157604     sqlite3_file base;              /* sqlite3_file methods */
157599 157605     sqlite3_file *pReal;            /* Underlying file handle */
157600         -  ota_vfs *pOtaVfs;               /* Pointer to the ota_vfs object */
157601         -  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) */
157602 157608   
157603 157609     int openFlags;                  /* Flags this file was opened with */
157604 157610     u32 iCookie;                    /* Cookie value for main db files */
157605 157611     u8 iWriteVer;                   /* "write-version" value for main db files */
157606 157612   
157607 157613     int nShm;                       /* Number of entries in apShm[] array */
157608 157614     char **apShm;                   /* Array of mmap'd *-shm regions */
157609 157615     char *zDel;                     /* Delete this when closing file */
157610 157616   
157611 157617     const char *zWal;               /* Wal filename for this main db file */
157612         -  ota_file *pWalFd;               /* Wal file descriptor for this main db */
157613         -  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 */
157614 157620   };
157615 157621   
157616 157622   
157617 157623   /*
157618 157624   ** Prepare the SQL statement in buffer zSql against database handle db.
157619 157625   ** If successful, set *ppStmt to point to the new statement and return
157620 157626   ** SQLITE_OK. 
................................................................................
157684 157690       rc = prepareAndCollectError(db, ppStmt, pzErrmsg, zSql);
157685 157691       sqlite3_free(zSql);
157686 157692     }
157687 157693     return rc;
157688 157694   }
157689 157695   
157690 157696   /*
157691         -** Free the OtaObjIter.azTblCol[] and OtaObjIter.abTblPk[] arrays allocated
157692         -** by an earlier call to otaObjIterCacheTableInfo().
       157697  +** Free the RbuObjIter.azTblCol[] and RbuObjIter.abTblPk[] arrays allocated
       157698  +** by an earlier call to rbuObjIterCacheTableInfo().
157693 157699   */
157694         -static void otaObjIterFreeCols(OtaObjIter *pIter){
       157700  +static void rbuObjIterFreeCols(RbuObjIter *pIter){
157695 157701     int i;
157696 157702     for(i=0; i<pIter->nTblCol; i++){
157697 157703       sqlite3_free(pIter->azTblCol[i]);
157698 157704       sqlite3_free(pIter->azTblType[i]);
157699 157705     }
157700 157706     sqlite3_free(pIter->azTblCol);
157701 157707     pIter->azTblCol = 0;
................................................................................
157707 157713     pIter->eType = 0;               /* Invalid value */
157708 157714   }
157709 157715   
157710 157716   /*
157711 157717   ** Finalize all statements and free all allocations that are specific to
157712 157718   ** the current object (table/index pair).
157713 157719   */
157714         -static void otaObjIterClearStatements(OtaObjIter *pIter){
157715         -  OtaUpdateStmt *pUp;
       157720  +static void rbuObjIterClearStatements(RbuObjIter *pIter){
       157721  +  RbuUpdateStmt *pUp;
157716 157722   
157717 157723     sqlite3_finalize(pIter->pSelect);
157718 157724     sqlite3_finalize(pIter->pInsert);
157719 157725     sqlite3_finalize(pIter->pDelete);
157720 157726     sqlite3_finalize(pIter->pTmpInsert);
157721         -  pUp = pIter->pOtaUpdate;
       157727  +  pUp = pIter->pRbuUpdate;
157722 157728     while( pUp ){
157723         -    OtaUpdateStmt *pTmp = pUp->pNext;
       157729  +    RbuUpdateStmt *pTmp = pUp->pNext;
157724 157730       sqlite3_finalize(pUp->pUpdate);
157725 157731       sqlite3_free(pUp);
157726 157732       pUp = pTmp;
157727 157733     }
157728 157734     
157729 157735     pIter->pSelect = 0;
157730 157736     pIter->pInsert = 0;
157731 157737     pIter->pDelete = 0;
157732         -  pIter->pOtaUpdate = 0;
       157738  +  pIter->pRbuUpdate = 0;
157733 157739     pIter->pTmpInsert = 0;
157734 157740     pIter->nCol = 0;
157735 157741   }
157736 157742   
157737 157743   /*
157738 157744   ** Clean up any resources allocated as part of the iterator object passed
157739 157745   ** as the only argument.
157740 157746   */
157741         -static void otaObjIterFinalize(OtaObjIter *pIter){
157742         -  otaObjIterClearStatements(pIter);
       157747  +static void rbuObjIterFinalize(RbuObjIter *pIter){
       157748  +  rbuObjIterClearStatements(pIter);
157743 157749     sqlite3_finalize(pIter->pTblIter);
157744 157750     sqlite3_finalize(pIter->pIdxIter);
157745         -  otaObjIterFreeCols(pIter);
157746         -  memset(pIter, 0, sizeof(OtaObjIter));
       157751  +  rbuObjIterFreeCols(pIter);
       157752  +  memset(pIter, 0, sizeof(RbuObjIter));
157747 157753   }
157748 157754   
157749 157755   /*
157750 157756   ** Advance the iterator to the next position.
157751 157757   **
157752 157758   ** If no error occurs, SQLITE_OK is returned and the iterator is left 
157753 157759   ** pointing to the next entry. Otherwise, an error code and message is 
157754         -** 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 
157755 157761   ** error code is returned.
157756 157762   */
157757         -static int otaObjIterNext(sqlite3ota *p, OtaObjIter *pIter){
       157763  +static int rbuObjIterNext(sqlite3rbu *p, RbuObjIter *pIter){
157758 157764     int rc = p->rc;
157759 157765     if( rc==SQLITE_OK ){
157760 157766   
157761 157767       /* Free any SQLite statements used while processing the previous object */ 
157762         -    otaObjIterClearStatements(pIter);
       157768  +    rbuObjIterClearStatements(pIter);
157763 157769       if( pIter->zIdx==0 ){
157764 157770         rc = sqlite3_exec(p->dbMain,
157765         -          "DROP TRIGGER IF EXISTS temp.ota_insert_tr;"
157766         -          "DROP TRIGGER IF EXISTS temp.ota_update1_tr;"
157767         -          "DROP TRIGGER IF EXISTS temp.ota_update2_tr;"
157768         -          "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;"
157769 157775             , 0, 0, &p->zErrmsg
157770 157776         );
157771 157777       }
157772 157778   
157773 157779       if( rc==SQLITE_OK ){
157774 157780         if( pIter->bCleanup ){
157775         -        otaObjIterFreeCols(pIter);
       157781  +        rbuObjIterFreeCols(pIter);
157776 157782           pIter->bCleanup = 0;
157777 157783           rc = sqlite3_step(pIter->pTblIter);
157778 157784           if( rc!=SQLITE_ROW ){
157779 157785             rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
157780 157786             pIter->zTbl = 0;
157781 157787           }else{
157782 157788             pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
................................................................................
157801 157807             }
157802 157808           }
157803 157809         }
157804 157810       }
157805 157811     }
157806 157812   
157807 157813     if( rc!=SQLITE_OK ){
157808         -    otaObjIterFinalize(pIter);
       157814  +    rbuObjIterFinalize(pIter);
157809 157815       p->rc = rc;
157810 157816     }
157811 157817     return rc;
157812 157818   }
157813 157819   
157814 157820   /*
157815 157821   ** Initialize the iterator structure passed as the second argument.
157816 157822   **
157817 157823   ** If no error occurs, SQLITE_OK is returned and the iterator is left 
157818 157824   ** pointing to the first entry. Otherwise, an error code and message is 
157819         -** 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 
157820 157826   ** error code is returned.
157821 157827   */
157822         -static int otaObjIterFirst(sqlite3ota *p, OtaObjIter *pIter){
       157828  +static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
157823 157829     int rc;
157824         -  memset(pIter, 0, sizeof(OtaObjIter));
       157830  +  memset(pIter, 0, sizeof(RbuObjIter));
157825 157831   
157826         -  rc = prepareAndCollectError(p->dbOta, &pIter->pTblIter, &p->zErrmsg, 
       157832  +  rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg, 
157827 157833         "SELECT substr(name, 6) FROM sqlite_master "
157828 157834         "WHERE type='table' AND name LIKE 'data_%'"
157829 157835     );
157830 157836   
157831 157837     if( rc==SQLITE_OK ){
157832 157838       rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
157833 157839           "SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
................................................................................
157834 157840           "  FROM main.sqlite_master "
157835 157841           "  WHERE type='index' AND tbl_name = ?"
157836 157842       );
157837 157843     }
157838 157844   
157839 157845     pIter->bCleanup = 1;
157840 157846     p->rc = rc;
157841         -  return otaObjIterNext(p, pIter);
       157847  +  return rbuObjIterNext(p, pIter);
157842 157848   }
157843 157849   
157844 157850   /*
157845 157851   ** This is a wrapper around "sqlite3_mprintf(zFmt, ...)". If an OOM occurs,
157846         -** 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.
157847 157853   **
157848 157854   ** If an error has already occurred (p->rc is already set to something other
157849 157855   ** than SQLITE_OK), then this function returns NULL without modifying the
157850 157856   ** stored error code. In this case it still calls sqlite3_free() on any 
157851 157857   ** printf() parameters associated with %z conversions.
157852 157858   */
157853         -static char *otaMPrintf(sqlite3ota *p, const char *zFmt, ...){
       157859  +static char *rbuMPrintf(sqlite3rbu *p, const char *zFmt, ...){
157854 157860     char *zSql = 0;
157855 157861     va_list ap;
157856 157862     va_start(ap, zFmt);
157857 157863     zSql = sqlite3_vmprintf(zFmt, ap);
157858 157864     if( p->rc==SQLITE_OK ){
157859 157865       if( zSql==0 ) p->rc = SQLITE_NOMEM;
157860 157866     }else{
................................................................................
157865 157871     return zSql;
157866 157872   }
157867 157873   
157868 157874   /*
157869 157875   ** Argument zFmt is a sqlite3_mprintf() style format string. The trailing
157870 157876   ** arguments are the usual subsitution values. This function performs
157871 157877   ** the printf() style substitutions and executes the result as an SQL
157872         -** statement on the OTA handles database.
       157878  +** statement on the RBU handles database.
157873 157879   **
157874 157880   ** If an error occurs, an error code and error message is stored in the
157875         -** 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
157876 157882   ** called, it is a no-op.
157877 157883   */
157878         -static int otaMPrintfExec(sqlite3ota *p, sqlite3 *db, const char *zFmt, ...){
       157884  +static int rbuMPrintfExec(sqlite3rbu *p, sqlite3 *db, const char *zFmt, ...){
157879 157885     va_list ap;
157880 157886     va_start(ap, zFmt);
157881 157887     char *zSql = sqlite3_vmprintf(zFmt, ap);
157882 157888     if( p->rc==SQLITE_OK ){
157883 157889       if( zSql==0 ){
157884 157890         p->rc = SQLITE_NOMEM;
157885 157891       }else{
................................................................................
157892 157898   }
157893 157899   
157894 157900   /*
157895 157901   ** Attempt to allocate and return a pointer to a zeroed block of nByte 
157896 157902   ** bytes. 
157897 157903   **
157898 157904   ** If an error (i.e. an OOM condition) occurs, return NULL and leave an 
157899         -** 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 
157900 157906   ** error has already occurred when this function is called, return NULL 
157901 157907   ** immediately without attempting the allocation or modifying the stored
157902 157908   ** error code.
157903 157909   */
157904         -static void *otaMalloc(sqlite3ota *p, int nByte){
       157910  +static void *rbuMalloc(sqlite3rbu *p, int nByte){
157905 157911     void *pRet = 0;
157906 157912     if( p->rc==SQLITE_OK ){
157907 157913       assert( nByte>0 );
157908 157914       pRet = sqlite3_malloc(nByte);
157909 157915       if( pRet==0 ){
157910 157916         p->rc = SQLITE_NOMEM;
157911 157917       }else{
................................................................................
157915 157921     return pRet;
157916 157922   }
157917 157923   
157918 157924   
157919 157925   /*
157920 157926   ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
157921 157927   ** there is room for at least nCol elements. If an OOM occurs, store an
157922         -** error code in the OTA handle passed as the first argument.
       157928  +** error code in the RBU handle passed as the first argument.
157923 157929   */
157924         -static void otaAllocateIterArrays(sqlite3ota *p, OtaObjIter *pIter, int nCol){
       157930  +static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
157925 157931     int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
157926 157932     char **azNew;
157927 157933   
157928         -  azNew = (char**)otaMalloc(p, nByte);
       157934  +  azNew = (char**)rbuMalloc(p, nByte);
157929 157935     if( azNew ){
157930 157936       pIter->azTblCol = azNew;
157931 157937       pIter->azTblType = &azNew[nCol];
157932 157938       pIter->aiSrcOrder = (int*)&pIter->azTblType[nCol];
157933 157939       pIter->abTblPk = (u8*)&pIter->aiSrcOrder[nCol];
157934 157940       pIter->abNotNull = (u8*)&pIter->abTblPk[nCol];
157935 157941       pIter->abIndexed = (u8*)&pIter->abNotNull[nCol];
................................................................................
157942 157948   ** It is the responsibility of the caller to eventually free this memory
157943 157949   ** using sqlite3_free().
157944 157950   **
157945 157951   ** If an OOM condition is encountered when attempting to allocate memory,
157946 157952   ** output variable (*pRc) is set to SQLITE_NOMEM before returning. Otherwise,
157947 157953   ** if the allocation succeeds, (*pRc) is left unchanged.
157948 157954   */
157949         -static char *otaStrndup(const char *zStr, int *pRc){
       157955  +static char *rbuStrndup(const char *zStr, int *pRc){
157950 157956     char *zRet = 0;
157951 157957   
157952 157958     assert( *pRc==SQLITE_OK );
157953 157959     if( zStr ){
157954 157960       int nCopy = strlen(zStr) + 1;
157955 157961       zRet = (char*)sqlite3_malloc(nCopy);
157956 157962       if( zRet ){
................................................................................
157963 157969     return zRet;
157964 157970   }
157965 157971   
157966 157972   /*
157967 157973   ** Finalize the statement passed as the second argument.
157968 157974   **
157969 157975   ** If the sqlite3_finalize() call indicates that an error occurs, and the
157970         -** 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
157971 157977   ** message accordingly.
157972 157978   */
157973         -static void otaFinalize(sqlite3ota *p, sqlite3_stmt *pStmt){
       157979  +static void rbuFinalize(sqlite3rbu *p, sqlite3_stmt *pStmt){
157974 157980     sqlite3 *db = sqlite3_db_handle(pStmt);
157975 157981     int rc = sqlite3_finalize(pStmt);
157976 157982     if( p->rc==SQLITE_OK && rc!=SQLITE_OK ){
157977 157983       p->rc = rc;
157978 157984       p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
157979 157985     }
157980 157986   }
................................................................................
157981 157987   
157982 157988   /* Determine the type of a table.
157983 157989   **
157984 157990   **   peType is of type (int*), a pointer to an output parameter of type
157985 157991   **   (int). This call sets the output parameter as follows, depending
157986 157992   **   on the type of the table specified by parameters dbName and zTbl.
157987 157993   **
157988         -**     OTA_PK_NOTABLE:       No such table.
157989         -**     OTA_PK_NONE:          Table has an implicit rowid.
157990         -**     OTA_PK_IPK:           Table has an explicit IPK column.
157991         -**     OTA_PK_EXTERNAL:      Table has an external PK index.
157992         -**     OTA_PK_WITHOUT_ROWID: Table is WITHOUT ROWID.
157993         -**     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.
157994 158000   **
157995 158001   **   Argument *piPk is also of type (int*), and also points to an output
157996 158002   **   parameter. Unless the table has an external primary key index 
157997 158003   **   (i.e. unless *peType is set to 3), then *piPk is set to zero. Or,
157998 158004   **   if the table does have an external primary key index, then *piPk
157999 158005   **   is set to the root page number of the primary key index before
158000 158006   **   returning.
158001 158007   **
158002 158008   ** ALGORITHM:
158003 158009   **
158004 158010   **   if( no entry exists in sqlite_master ){
158005         -**     return OTA_PK_NOTABLE
       158011  +**     return RBU_PK_NOTABLE
158006 158012   **   }else if( sql for the entry starts with "CREATE VIRTUAL" ){
158007         -**     return OTA_PK_VTAB
       158013  +**     return RBU_PK_VTAB
158008 158014   **   }else if( "PRAGMA index_list()" for the table contains a "pk" index ){
158009 158015   **     if( the index that is the pk exists in sqlite_master ){
158010 158016   **       *piPK = rootpage of that index.
158011         -**       return OTA_PK_EXTERNAL
       158017  +**       return RBU_PK_EXTERNAL
158012 158018   **     }else{
158013         -**       return OTA_PK_WITHOUT_ROWID
       158019  +**       return RBU_PK_WITHOUT_ROWID
158014 158020   **     }
158015 158021   **   }else if( "PRAGMA table_info()" lists one or more "pk" columns ){
158016         -**     return OTA_PK_IPK
       158022  +**     return RBU_PK_IPK
158017 158023   **   }else{
158018         -**     return OTA_PK_NONE
       158024  +**     return RBU_PK_NONE
158019 158025   **   }
158020 158026   */
158021         -static void otaTableType(
158022         -  sqlite3ota *p,
       158027  +static void rbuTableType(
       158028  +  sqlite3rbu *p,
158023 158029     const char *zTab,
158024 158030     int *peType,
158025 158031     int *piTnum,
158026 158032     int *piPk
158027 158033   ){
158028 158034     /*
158029 158035     ** 0) SELECT count(*) FROM sqlite_master where name=%Q AND IsVirtual(%Q)
158030 158036     ** 1) PRAGMA index_list = ?
158031 158037     ** 2) SELECT count(*) FROM sqlite_master where name=%Q 
158032 158038     ** 3) PRAGMA table_info = ?
158033 158039     */
158034 158040     sqlite3_stmt *aStmt[4] = {0, 0, 0, 0};
158035 158041   
158036         -  *peType = OTA_PK_NOTABLE;
       158042  +  *peType = RBU_PK_NOTABLE;
158037 158043     *piPk = 0;
158038 158044   
158039 158045     assert( p->rc==SQLITE_OK );
158040 158046     p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg, 
158041 158047       sqlite3_mprintf(
158042 158048             "SELECT (sql LIKE 'create virtual%%'), rootpage"
158043 158049             "  FROM sqlite_master"
158044 158050             " WHERE name=%Q", zTab
158045 158051     ));
158046 158052     if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
158047 158053       /* Either an error, or no such table. */
158048         -    goto otaTableType_end;
       158054  +    goto rbuTableType_end;
158049 158055     }
158050 158056     if( sqlite3_column_int(aStmt[0], 0) ){
158051         -    *peType = OTA_PK_VTAB;                     /* virtual table */
158052         -    goto otaTableType_end;
       158057  +    *peType = RBU_PK_VTAB;                     /* virtual table */
       158058  +    goto rbuTableType_end;
158053 158059     }
158054 158060     *piTnum = sqlite3_column_int(aStmt[0], 1);
158055 158061   
158056 158062     p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[1], &p->zErrmsg, 
158057 158063       sqlite3_mprintf("PRAGMA index_list=%Q",zTab)
158058 158064     );
158059         -  if( p->rc ) goto otaTableType_end;
       158065  +  if( p->rc ) goto rbuTableType_end;
158060 158066     while( sqlite3_step(aStmt[1])==SQLITE_ROW ){
158061 158067       const u8 *zOrig = sqlite3_column_text(aStmt[1], 3);
158062 158068       const u8 *zIdx = sqlite3_column_text(aStmt[1], 1);
158063 158069       if( zOrig && zIdx && zOrig[0]=='p' ){
158064 158070         p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[2], &p->zErrmsg, 
158065 158071             sqlite3_mprintf(
158066 158072               "SELECT rootpage FROM sqlite_master WHERE name = %Q", zIdx
158067 158073         ));
158068 158074         if( p->rc==SQLITE_OK ){
158069 158075           if( sqlite3_step(aStmt[2])==SQLITE_ROW ){
158070 158076             *piPk = sqlite3_column_int(aStmt[2], 0);
158071         -          *peType = OTA_PK_EXTERNAL;
       158077  +          *peType = RBU_PK_EXTERNAL;
158072 158078           }else{
158073         -          *peType = OTA_PK_WITHOUT_ROWID;
       158079  +          *peType = RBU_PK_WITHOUT_ROWID;
158074 158080           }
158075 158081         }
158076         -      goto otaTableType_end;
       158082  +      goto rbuTableType_end;
158077 158083       }
158078 158084     }
158079 158085   
158080 158086     p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[3], &p->zErrmsg, 
158081 158087       sqlite3_mprintf("PRAGMA table_info=%Q",zTab)
158082 158088     );
158083 158089     if( p->rc==SQLITE_OK ){
158084 158090       while( sqlite3_step(aStmt[3])==SQLITE_ROW ){
158085 158091         if( sqlite3_column_int(aStmt[3],5)>0 ){
158086         -        *peType = OTA_PK_IPK;                /* explicit IPK column */
158087         -        goto otaTableType_end;
       158092  +        *peType = RBU_PK_IPK;                /* explicit IPK column */
       158093  +        goto rbuTableType_end;
158088 158094         }
158089 158095       }
158090         -    *peType = OTA_PK_NONE;
       158096  +    *peType = RBU_PK_NONE;
158091 158097     }
158092 158098   
158093         -otaTableType_end: {
       158099  +rbuTableType_end: {
158094 158100       int i;
158095 158101       for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){
158096         -      otaFinalize(p, aStmt[i]);
       158102  +      rbuFinalize(p, aStmt[i]);
158097 158103       }
158098 158104     }
158099 158105   }
158100 158106   
158101 158107   /*
158102         -** This is a helper function for otaObjIterCacheTableInfo(). It populates
       158108  +** This is a helper function for rbuObjIterCacheTableInfo(). It populates
158103 158109   ** the pIter->abIndexed[] array.
158104 158110   */
158105         -static void otaObjIterCacheIndexedCols(sqlite3ota *p, OtaObjIter *pIter){
       158111  +static void rbuObjIterCacheIndexedCols(sqlite3rbu *p, RbuObjIter *pIter){
158106 158112     sqlite3_stmt *pList = 0;
158107 158113     int bIndex = 0;
158108 158114   
158109 158115     if( p->rc==SQLITE_OK ){
158110 158116       memcpy(pIter->abIndexed, pIter->abTblPk, sizeof(u8)*pIter->nTblCol);
158111 158117       p->rc = prepareFreeAndCollectError(p->dbMain, &pList, &p->zErrmsg,
158112 158118           sqlite3_mprintf("PRAGMA main.index_list = %Q", pIter->zTbl)
................................................................................
158120 158126       p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
158121 158127           sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
158122 158128       );
158123 158129       while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
158124 158130         int iCid = sqlite3_column_int(pXInfo, 1);
158125 158131         if( iCid>=0 ) pIter->abIndexed[iCid] = 1;
158126 158132       }
158127         -    otaFinalize(p, pXInfo);
       158133  +    rbuFinalize(p, pXInfo);
158128 158134       bIndex = 1;
158129 158135     }
158130 158136   
158131         -  otaFinalize(p, pList);
       158137  +  rbuFinalize(p, pList);
158132 158138     if( bIndex==0 ) pIter->abIndexed = 0;
158133 158139   }
158134 158140   
158135 158141   
158136 158142   /*
158137 158143   ** If they are not already populated, populate the pIter->azTblCol[],
158138 158144   ** pIter->abTblPk[], pIter->nTblCol and pIter->bRowid variables according to
158139 158145   ** the table (not index) that the iterator currently points to.
158140 158146   **
158141 158147   ** Return SQLITE_OK if successful, or an SQLite error code otherwise. If
158142 158148   ** an error does occur, an error code and error message are also left in 
158143         -** the OTA handle.
       158149  +** the RBU handle.
158144 158150   */
158145         -static int otaObjIterCacheTableInfo(sqlite3ota *p, OtaObjIter *pIter){
       158151  +static int rbuObjIterCacheTableInfo(sqlite3rbu *p, RbuObjIter *pIter){
158146 158152     if( pIter->azTblCol==0 ){
158147 158153       sqlite3_stmt *pStmt = 0;
158148 158154       int nCol = 0;
158149 158155       int i;                        /* for() loop iterator variable */
158150         -    int bOtaRowid = 0;            /* If input table has column "ota_rowid" */
       158156  +    int bRbuRowid = 0;            /* If input table has column "rbu_rowid" */
158151 158157       int iOrder = 0;
158152 158158       int iTnum = 0;
158153 158159   
158154 158160       /* Figure out the type of table this step will deal with. */
158155 158161       assert( pIter->eType==0 );
158156         -    otaTableType(p, pIter->zTbl, &pIter->eType, &iTnum, &pIter->iPkTnum);
158157         -    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 ){
158158 158164         p->rc = SQLITE_ERROR;
158159 158165         p->zErrmsg = sqlite3_mprintf("no such table: %s", pIter->zTbl);
158160 158166       }
158161 158167       if( p->rc ) return p->rc;
158162 158168       if( pIter->zIdx==0 ) pIter->iTnum = iTnum;
158163 158169   
158164         -    assert( pIter->eType==OTA_PK_NONE || pIter->eType==OTA_PK_IPK 
158165         -         || pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_WITHOUT_ROWID
158166         -         || 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
158167 158173       );
158168 158174   
158169 158175       /* Populate the azTblCol[] and nTblCol variables based on the columns
158170 158176       ** of the input table. Ignore any input table columns that begin with
158171         -    ** "ota_".  */
158172         -    p->rc = prepareFreeAndCollectError(p->dbOta, &pStmt, &p->zErrmsg, 
       158177  +    ** "rbu_".  */
       158178  +    p->rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg, 
158173 158179           sqlite3_mprintf("SELECT * FROM 'data_%q'", pIter->zTbl)
158174 158180       );
158175 158181       if( p->rc==SQLITE_OK ){
158176 158182         nCol = sqlite3_column_count(pStmt);
158177         -      otaAllocateIterArrays(p, pIter, nCol);
       158183  +      rbuAllocateIterArrays(p, pIter, nCol);
158178 158184       }
158179 158185       for(i=0; p->rc==SQLITE_OK && i<nCol; i++){
158180 158186         const char *zName = (const char*)sqlite3_column_name(pStmt, i);
158181         -      if( sqlite3_strnicmp("ota_", zName, 4) ){
158182         -        char *zCopy = otaStrndup(zName, &p->rc);
       158187  +      if( sqlite3_strnicmp("rbu_", zName, 4) ){
       158188  +        char *zCopy = rbuStrndup(zName, &p->rc);
158183 158189           pIter->aiSrcOrder[pIter->nTblCol] = pIter->nTblCol;
158184 158190           pIter->azTblCol[pIter->nTblCol++] = zCopy;
158185 158191         }
158186         -      else if( 0==sqlite3_stricmp("ota_rowid", zName) ){
158187         -        bOtaRowid = 1;
       158192  +      else if( 0==sqlite3_stricmp("rbu_rowid", zName) ){
       158193  +        bRbuRowid = 1;
158188 158194         }
158189 158195       }
158190 158196       sqlite3_finalize(pStmt);
158191 158197       pStmt = 0;
158192 158198   
158193 158199       if( p->rc==SQLITE_OK
158194         -     && bOtaRowid!=(pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE)
       158200  +     && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
158195 158201       ){
158196 158202         p->rc = SQLITE_ERROR;
158197 158203         p->zErrmsg = sqlite3_mprintf(
158198         -          "table data_%q %s ota_rowid column", pIter->zTbl,
158199         -          (bOtaRowid ? "may not have" : "requires")
       158204  +          "table data_%q %s rbu_rowid column", pIter->zTbl,
       158205  +          (bRbuRowid ? "may not have" : "requires")
158200 158206         );
158201 158207       }
158202 158208   
158203 158209       /* Check that all non-HIDDEN columns in the destination table are also
158204 158210       ** present in the input table. Populate the abTblPk[], azTblType[] and
158205 158211       ** aiTblOrder[] arrays at the same time.  */
158206 158212       if( p->rc==SQLITE_OK ){
................................................................................
158225 158231           const char *zType = (const char*)sqlite3_column_text(pStmt, 2);
158226 158232   
158227 158233           if( i!=iOrder ){
158228 158234             SWAP(int, pIter->aiSrcOrder[i], pIter->aiSrcOrder[iOrder]);
158229 158235             SWAP(char*, pIter->azTblCol[i], pIter->azTblCol[iOrder]);
158230 158236           }
158231 158237   
158232         -        pIter->azTblType[iOrder] = otaStrndup(zType, &p->rc);
       158238  +        pIter->azTblType[iOrder] = rbuStrndup(zType, &p->rc);
158233 158239           pIter->abTblPk[iOrder] = (iPk!=0);
158234 158240           pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0);
158235 158241           iOrder++;
158236 158242         }
158237 158243       }
158238 158244   
158239         -    otaFinalize(p, pStmt);
158240         -    otaObjIterCacheIndexedCols(p, pIter);
158241         -    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 );
158242 158248     }
158243 158249   
158244 158250     return p->rc;
158245 158251   }
158246 158252   
158247 158253   /*
158248 158254   ** This function constructs and returns a pointer to a nul-terminated 
158249 158255   ** string containing some SQL clause or list based on one or more of the 
158250 158256   ** column names currently stored in the pIter->azTblCol[] array.
158251 158257   */
158252         -static char *otaObjIterGetCollist(
158253         -  sqlite3ota *p,                  /* OTA object */
158254         -  OtaObjIter *pIter               /* Object iterator for column names */
       158258  +static char *rbuObjIterGetCollist(
       158259  +  sqlite3rbu *p,                  /* RBU object */
       158260  +  RbuObjIter *pIter               /* Object iterator for column names */
158255 158261   ){
158256 158262     char *zList = 0;
158257 158263     const char *zSep = "";
158258 158264     int i;
158259 158265     for(i=0; i<pIter->nTblCol; i++){
158260 158266       const char *z = pIter->azTblCol[i];
158261         -    zList = otaMPrintf(p, "%z%s\"%w\"", zList, zSep, z);
       158267  +    zList = rbuMPrintf(p, "%z%s\"%w\"", zList, zSep, z);
158262 158268       zSep = ", ";
158263 158269     }
158264 158270     return zList;
158265 158271   }
158266 158272   
158267 158273   /*
158268 158274   ** This function is used to create a SELECT list (the list of SQL 
158269 158275   ** expressions that follows a SELECT keyword) for a SELECT statement 
158270         -** 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 
158271 158277   ** index object currently indicated by the iterator object passed as the 
158272 158278   ** second argument. A "PRAGMA index_xinfo = <idxname>" statement is used 
158273 158279   ** to obtain the required information.
158274 158280   **
158275 158281   ** If the index is of the following form:
158276 158282   **
158277 158283   **   CREATE INDEX i1 ON t1(c, b COLLATE nocase);
................................................................................
158284 158290   ** As well as the returned string, three other malloc'd strings are 
158285 158291   ** returned via output parameters. As follows:
158286 158292   **
158287 158293   **   pzImposterCols: ...
158288 158294   **   pzImposterPk: ...
158289 158295   **   pzWhere: ...
158290 158296   */
158291         -static char *otaObjIterGetIndexCols(
158292         -  sqlite3ota *p,                  /* OTA object */
158293         -  OtaObjIter *pIter,              /* Object iterator for column names */
       158297  +static char *rbuObjIterGetIndexCols(
       158298  +  sqlite3rbu *p,                  /* RBU object */
       158299  +  RbuObjIter *pIter,              /* Object iterator for column names */
158294 158300     char **pzImposterCols,          /* OUT: Columns for imposter table */
158295 158301     char **pzImposterPk,            /* OUT: Imposter PK clause */
158296 158302     char **pzWhere,                 /* OUT: WHERE clause */
158297         -  int *pnBind                     /* OUT: Total number of columns */
       158303  +  int *pnBind                     /* OUT: Trbul number of columns */
158298 158304   ){
158299 158305     int rc = p->rc;                 /* Error code */
158300 158306     int rc2;                        /* sqlite3_finalize() return code */
158301 158307     char *zRet = 0;                 /* String to return */
158302 158308     char *zImpCols = 0;             /* String to return via *pzImposterCols */
158303 158309     char *zImpPK = 0;               /* String to return via *pzImposterPK */
158304 158310     char *zWhere = 0;               /* String to return via *pzWhere */
................................................................................
158319 158325       int bDesc = sqlite3_column_int(pXInfo, 3);
158320 158326       const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4);
158321 158327       const char *zCol;
158322 158328       const char *zType;
158323 158329   
158324 158330       if( iCid<0 ){
158325 158331         /* An integer primary key. If the table has an explicit IPK, use
158326         -      ** its name. Otherwise, use "ota_rowid".  */
158327         -      if( pIter->eType==OTA_PK_IPK ){
       158332  +      ** its name. Otherwise, use "rbu_rowid".  */
       158333  +      if( pIter->eType==RBU_PK_IPK ){
158328 158334           int i;
158329 158335           for(i=0; pIter->abTblPk[i]==0; i++);
158330 158336           assert( i<pIter->nTblCol );
158331 158337           zCol = pIter->azTblCol[i];
158332 158338         }else{
158333         -        zCol = "ota_rowid";
       158339  +        zCol = "rbu_rowid";
158334 158340         }
158335 158341         zType = "INTEGER";
158336 158342       }else{
158337 158343         zCol = pIter->azTblCol[iCid];
158338 158344         zType = pIter->azTblType[iCid];
158339 158345       }
158340 158346   
158341 158347       zRet = sqlite3_mprintf("%z%s\"%w\" COLLATE %Q", zRet, zCom, zCol, zCollate);
158342 158348       if( pIter->bUnique==0 || sqlite3_column_int(pXInfo, 5) ){
158343 158349         const char *zOrder = (bDesc ? " DESC" : "");
158344         -      zImpPK = sqlite3_mprintf("%z%s\"ota_imp_%d%w\"%s", 
       158350  +      zImpPK = sqlite3_mprintf("%z%s\"rbu_imp_%d%w\"%s", 
158345 158351             zImpPK, zCom, nBind, zCol, zOrder
158346 158352         );
158347 158353       }
158348         -    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", 
158349 158355           zImpCols, zCom, nBind, zCol, zType, zCollate
158350 158356       );
158351 158357       zWhere = sqlite3_mprintf(
158352         -        "%z%s\"ota_imp_%d%w\" IS ?", zWhere, zAnd, nBind, zCol
       158358  +        "%z%s\"rbu_imp_%d%w\" IS ?", zWhere, zAnd, nBind, zCol
158353 158359       );
158354 158360       if( zRet==0 || zImpPK==0 || zImpCols==0 || zWhere==0 ) rc = SQLITE_NOMEM;
158355 158361       zCom = ", ";
158356 158362       zAnd = " AND ";
158357 158363       nBind++;
158358 158364     }
158359 158365   
................................................................................
158383 158389   ** Assuming the current table columns are "a", "b" and "c", and the zObj
158384 158390   ** paramter is passed "old", return a string of the form:
158385 158391   **
158386 158392   **     "old.a, old.b, old.b"
158387 158393   **
158388 158394   ** With the column names escaped.
158389 158395   **
158390         -** 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
158391 158397   ** the text ", old._rowid_" to the returned value.
158392 158398   */
158393         -static char *otaObjIterGetOldlist(
158394         -  sqlite3ota *p, 
158395         -  OtaObjIter *pIter,
       158399  +static char *rbuObjIterGetOldlist(
       158400  +  sqlite3rbu *p, 
       158401  +  RbuObjIter *pIter,
158396 158402     const char *zObj
158397 158403   ){
158398 158404     char *zList = 0;
158399 158405     if( p->rc==SQLITE_OK && pIter->abIndexed ){
158400 158406       const char *zS = "";
158401 158407       int i;
158402 158408       for(i=0; i<pIter->nTblCol; i++){
................................................................................
158410 158416         if( zList==0 ){
158411 158417           p->rc = SQLITE_NOMEM;
158412 158418           break;
158413 158419         }
158414 158420       }
158415 158421   
158416 158422       /* For a table with implicit rowids, append "old._rowid_" to the list. */
158417         -    if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){
158418         -      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);
158419 158425       }
158420 158426     }
158421 158427     return zList;
158422 158428   }
158423 158429   
158424 158430   /*
158425 158431   ** Return an expression that can be used in a WHERE clause to match the
................................................................................
158427 158433   **
158428 158434   **   CREATE TABLE t1(a, b, c, PRIMARY KEY(b, c));
158429 158435   **
158430 158436   ** Return the string:
158431 158437   **
158432 158438   **   "b = ?1 AND c = ?2"
158433 158439   */
158434         -static char *otaObjIterGetWhere(
158435         -  sqlite3ota *p, 
158436         -  OtaObjIter *pIter
       158440  +static char *rbuObjIterGetWhere(
       158441  +  sqlite3rbu *p, 
       158442  +  RbuObjIter *pIter
158437 158443   ){
158438 158444     char *zList = 0;
158439         -  if( pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE ){
158440         -    zList = otaMPrintf(p, "_rowid_ = ?%d", pIter->nTblCol+1);
158441         -  }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 ){
158442 158448       const char *zSep = "";
158443 158449       int i;
158444 158450       for(i=0; i<pIter->nTblCol; i++){
158445 158451         if( pIter->abTblPk[i] ){
158446         -        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);
158447 158453           zSep = " AND ";
158448 158454         }
158449 158455       }
158450         -    zList = otaMPrintf(p, 
158451         -        "_rowid_ = (SELECT id FROM ota_imposter2 WHERE %z)", zList
       158456  +    zList = rbuMPrintf(p, 
       158457  +        "_rowid_ = (SELECT id FROM rbu_imposter2 WHERE %z)", zList
158452 158458       );
158453 158459   
158454 158460     }else{
158455 158461       const char *zSep = "";
158456 158462       int i;
158457 158463       for(i=0; i<pIter->nTblCol; i++){
158458 158464         if( pIter->abTblPk[i] ){
158459 158465           const char *zCol = pIter->azTblCol[i];
158460         -        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);
158461 158467           zSep = " AND ";
158462 158468         }
158463 158469       }
158464 158470     }
158465 158471     return zList;
158466 158472   }
158467 158473   
158468 158474   /*
158469 158475   ** The SELECT statement iterating through the keys for the current object
158470 158476   ** (p->objiter.pSelect) currently points to a valid row. However, there
158471         -** 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
158472 158478   ** stored in the (p->nCol+1)'th column. Set the error code and error message
158473         -** of the OTA handle to something reflecting this.
       158479  +** of the RBU handle to something reflecting this.
158474 158480   */
158475         -static void otaBadControlError(sqlite3ota *p){
       158481  +static void rbuBadControlError(sqlite3rbu *p){
158476 158482     p->rc = SQLITE_ERROR;
158477         -  p->zErrmsg = sqlite3_mprintf("invalid ota_control value");
       158483  +  p->zErrmsg = sqlite3_mprintf("invalid rbu_control value");
158478 158484   }
158479 158485   
158480 158486   
158481 158487   /*
158482 158488   ** Return a nul-terminated string containing the comma separated list of
158483 158489   ** assignments that should be included following the "SET" keyword of
158484 158490   ** an UPDATE statement used to update the table object that the iterator
158485         -** 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
158486 158492   ** column of the data_xxx table entry is set to zMask.
158487 158493   **
158488 158494   ** The memory for the returned string is obtained from sqlite3_malloc().
158489 158495   ** It is the responsibility of the caller to eventually free it using
158490 158496   ** sqlite3_free(). 
158491 158497   **
158492 158498   ** If an OOM error is encountered when allocating space for the new
158493         -** 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
158494 158500   ** argument and NULL is returned. Or, if an error has already occurred
158495 158501   ** when this function is called, NULL is returned immediately, without
158496 158502   ** attempting the allocation or modifying the stored error code.
158497 158503   */
158498         -static char *otaObjIterGetSetlist(
158499         -  sqlite3ota *p,
158500         -  OtaObjIter *pIter,
       158504  +static char *rbuObjIterGetSetlist(
       158505  +  sqlite3rbu *p,
       158506  +  RbuObjIter *pIter,
158501 158507     const char *zMask
158502 158508   ){
158503 158509     char *zList = 0;
158504 158510     if( p->rc==SQLITE_OK ){
158505 158511       int i;
158506 158512   
158507 158513       if( strlen(zMask)!=pIter->nTblCol ){
158508         -      otaBadControlError(p);
       158514  +      rbuBadControlError(p);
158509 158515       }else{
158510 158516         const char *zSep = "";
158511 158517         for(i=0; i<pIter->nTblCol; i++){
158512 158518           char c = zMask[pIter->aiSrcOrder[i]];
158513 158519           if( c=='x' ){
158514         -          zList = otaMPrintf(p, "%z%s\"%w\"=?%d", 
       158520  +          zList = rbuMPrintf(p, "%z%s\"%w\"=?%d", 
158515 158521                 zList, zSep, pIter->azTblCol[i], i+1
158516 158522             );
158517 158523             zSep = ", ";
158518 158524           }
158519 158525           if( c=='d' ){
158520         -          zList = otaMPrintf(p, "%z%s\"%w\"=ota_delta(\"%w\", ?%d)", 
       158526  +          zList = rbuMPrintf(p, "%z%s\"%w\"=rbu_delta(\"%w\", ?%d)", 
158521 158527                 zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
158522 158528             );
158523 158529             zSep = ", ";
158524 158530           }
158525 158531         }
158526 158532       }
158527 158533     }
................................................................................
158534 158540   ** a buffer containing the string "?,?,?".
158535 158541   **
158536 158542   ** The memory for the returned string is obtained from sqlite3_malloc().
158537 158543   ** It is the responsibility of the caller to eventually free it using
158538 158544   ** sqlite3_free(). 
158539 158545   **
158540 158546   ** If an OOM error is encountered when allocating space for the new
158541         -** 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
158542 158548   ** argument and NULL is returned. Or, if an error has already occurred
158543 158549   ** when this function is called, NULL is returned immediately, without
158544 158550   ** attempting the allocation or modifying the stored error code.
158545 158551   */
158546         -static char *otaObjIterGetBindlist(sqlite3ota *p, int nBind){
       158552  +static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){
158547 158553     char *zRet = 0;
158548 158554     int nByte = nBind*2 + 1;
158549 158555   
158550         -  zRet = (char*)otaMalloc(p, nByte);
       158556  +  zRet = (char*)rbuMalloc(p, nByte);
158551 158557     if( zRet ){
158552 158558       int i;
158553 158559       for(i=0; i<nBind; i++){
158554 158560         zRet[i*2] = '?';
158555 158561         zRet[i*2+1] = (i+1==nBind) ? '\0' : ',';
158556 158562       }
158557 158563     }
158558 158564     return zRet;
158559 158565   }
158560 158566   
158561 158567   /*
158562 158568   ** The iterator currently points to a table (not index) of type 
158563         -** OTA_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY 
       158569  +** RBU_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY 
158564 158570   ** declaration for the corresponding imposter table. For example,
158565 158571   ** if the iterator points to a table created as:
158566 158572   **
158567 158573   **   CREATE TABLE t1(a, b, c, PRIMARY KEY(b, a DESC)) WITHOUT ROWID
158568 158574   **
158569 158575   ** this function returns:
158570 158576   **
158571 158577   **   PRIMARY KEY("b", "a" DESC)
158572 158578   */
158573         -static char *otaWithoutRowidPK(sqlite3ota *p, OtaObjIter *pIter){
       158579  +static char *rbuWithoutRowidPK(sqlite3rbu *p, RbuObjIter *pIter){
158574 158580     char *z = 0;
158575 158581     assert( pIter->zIdx==0 );
158576 158582     if( p->rc==SQLITE_OK ){
158577 158583       const char *zSep = "PRIMARY KEY(";
158578 158584       sqlite3_stmt *pXList = 0;     /* PRAGMA index_list = (pIter->zTbl) */
158579 158585       sqlite3_stmt *pXInfo = 0;     /* PRAGMA index_xinfo = <pk-index> */
158580 158586      
................................................................................
158589 158595             p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
158590 158596                 sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
158591 158597             );
158592 158598           }
158593 158599           break;
158594 158600         }
158595 158601       }
158596         -    otaFinalize(p, pXList);
       158602  +    rbuFinalize(p, pXList);
158597 158603   
158598 158604       while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
158599 158605         if( sqlite3_column_int(pXInfo, 5) ){
158600 158606           /* int iCid = sqlite3_column_int(pXInfo, 0); */
158601 158607           const char *zCol = (const char*)sqlite3_column_text(pXInfo, 2);
158602 158608           const char *zDesc = sqlite3_column_int(pXInfo, 3) ? " DESC" : "";
158603         -        z = otaMPrintf(p, "%z%s\"%w\"%s", z, zSep, zCol, zDesc);
       158609  +        z = rbuMPrintf(p, "%z%s\"%w\"%s", z, zSep, zCol, zDesc);
158604 158610           zSep = ", ";
158605 158611         }
158606 158612       }
158607         -    z = otaMPrintf(p, "%z)", z);
158608         -    otaFinalize(p, pXInfo);
       158613  +    z = rbuMPrintf(p, "%z)", z);
       158614  +    rbuFinalize(p, pXInfo);
158609 158615     }
158610 158616     return z;
158611 158617   }
158612 158618   
158613 158619   /*
158614 158620   ** This function creates the second imposter table used when writing to
158615 158621   ** a table b-tree where the table has an external primary key. If the
158616 158622   ** iterator passed as the second argument does not currently point to
158617 158623   ** a table (not index) with an external primary key, this function is a
158618 158624   ** no-op. 
158619 158625   **
158620 158626   ** Assuming the iterator does point to a table with an external PK, this
158621         -** function creates a WITHOUT ROWID imposter table named "ota_imposter2"
       158627  +** function creates a WITHOUT ROWID imposter table named "rbu_imposter2"
158622 158628   ** used to access that PK index. For example, if the target table is
158623 158629   ** declared as follows:
158624 158630   **
158625 158631   **   CREATE TABLE t1(a, b TEXT, c REAL, PRIMARY KEY(b, c));
158626 158632   **
158627 158633   ** then the imposter table schema is:
158628 158634   **
158629         -**   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;
158630 158636   **
158631 158637   */
158632         -static void otaCreateImposterTable2(sqlite3ota *p, OtaObjIter *pIter){
158633         -  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 ){
158634 158640       int tnum = pIter->iPkTnum;    /* Root page of PK index */
158635 158641       sqlite3_stmt *pQuery = 0;     /* SELECT name ... WHERE rootpage = $tnum */
158636 158642       const char *zIdx = 0;         /* Name of PK index */
158637 158643       sqlite3_stmt *pXInfo = 0;     /* PRAGMA main.index_xinfo = $zIdx */
158638 158644       const char *zComma = "";
158639 158645       char *zCols = 0;              /* Used to build up list of table cols */
158640 158646       char *zPk = 0;                /* Used to build up table PK declaration */
................................................................................
158652 158658         }
158653 158659       }
158654 158660       if( zIdx ){
158655 158661         p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
158656 158662             sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
158657 158663         );
158658 158664       }
158659         -    otaFinalize(p, pQuery);
       158665  +    rbuFinalize(p, pQuery);
158660 158666   
158661 158667       while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
158662 158668         int bKey = sqlite3_column_int(pXInfo, 5);
158663 158669         if( bKey ){
158664 158670           int iCid = sqlite3_column_int(pXInfo, 1);
158665 158671           int bDesc = sqlite3_column_int(pXInfo, 3);
158666 158672           const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4);
158667         -        zCols = otaMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma, 
       158673  +        zCols = rbuMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma, 
158668 158674               iCid, pIter->azTblType[iCid], zCollate
158669 158675           );
158670         -        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":"");
158671 158677           zComma = ", ";
158672 158678         }
158673 158679       }
158674         -    zCols = otaMPrintf(p, "%z, id INTEGER", zCols);
158675         -    otaFinalize(p, pXInfo);
       158680  +    zCols = rbuMPrintf(p, "%z, id INTEGER", zCols);
       158681  +    rbuFinalize(p, pXInfo);
158676 158682   
158677 158683       sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1, tnum);
158678         -    otaMPrintfExec(p, p->dbMain,
158679         -        "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", 
158680 158686           zCols, zPk
158681 158687       );
158682 158688       sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
158683 158689     }
158684 158690   }
158685 158691   
158686 158692   /*
158687 158693   ** If an error has already occurred when this function is called, it 
158688 158694   ** immediately returns zero (without doing any work). Or, if an error
158689 158695   ** occurs during the execution of this function, it sets the error code
158690         -** in the sqlite3ota object indicated by the first argument and returns
       158696  +** in the sqlite3rbu object indicated by the first argument and returns
158691 158697   ** zero.
158692 158698   **
158693 158699   ** The iterator passed as the second argument is guaranteed to point to
158694 158700   ** a table (not an index) when this function is called. This function
158695 158701   ** attempts to create any imposter table required to write to the main
158696 158702   ** table b-tree of the table before returning. Non-zero is returned if
158697 158703   ** an imposter table are created, or zero otherwise.
158698 158704   **
158699         -** 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
158700 158706   ** virtual tables are written to directly. The imposter table has the 
158701 158707   ** same schema as the actual target table (less any UNIQUE constraints). 
158702 158708   ** More precisely, the "same schema" means the same columns, types, 
158703 158709   ** collation sequences. For tables that do not have an external PRIMARY
158704 158710   ** KEY, it also means the same PRIMARY KEY declaration.
158705 158711   */
158706         -static void otaCreateImposterTable(sqlite3ota *p, OtaObjIter *pIter){
158707         -  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 ){
158708 158714       int tnum = pIter->iTnum;
158709 158715       const char *zComma = "";
158710 158716       char *zSql = 0;
158711 158717       int iCol;
158712 158718       sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
158713 158719   
158714 158720       for(iCol=0; p->rc==SQLITE_OK && iCol<pIter->nTblCol; iCol++){
................................................................................
158716 158722         const char *zCol = pIter->azTblCol[iCol];
158717 158723         const char *zColl = 0;
158718 158724   
158719 158725         p->rc = sqlite3_table_column_metadata(
158720 158726             p->dbMain, "main", pIter->zTbl, zCol, 0, &zColl, 0, 0, 0
158721 158727         );
158722 158728   
158723         -      if( pIter->eType==OTA_PK_IPK && pIter->abTblPk[iCol] ){
       158729  +      if( pIter->eType==RBU_PK_IPK && pIter->abTblPk[iCol] ){
158724 158730           /* If the target table column is an "INTEGER PRIMARY KEY", add
158725 158731           ** "PRIMARY KEY" to the imposter table column declaration. */
158726 158732           zPk = "PRIMARY KEY ";
158727 158733         }
158728         -      zSql = otaMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s", 
       158734  +      zSql = rbuMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s", 
158729 158735             zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl,
158730 158736             (pIter->abNotNull[iCol] ? " NOT NULL" : "")
158731 158737         );
158732 158738         zComma = ", ";
158733 158739       }
158734 158740   
158735         -    if( pIter->eType==OTA_PK_WITHOUT_ROWID ){
158736         -      char *zPk = otaWithoutRowidPK(p, pIter);
       158741  +    if( pIter->eType==RBU_PK_WITHOUT_ROWID ){
       158742  +      char *zPk = rbuWithoutRowidPK(p, pIter);
158737 158743         if( zPk ){
158738         -        zSql = otaMPrintf(p, "%z, %z", zSql, zPk);
       158744  +        zSql = rbuMPrintf(p, "%z, %z", zSql, zPk);
158739 158745         }
158740 158746       }
158741 158747   
158742 158748       sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1, tnum);
158743         -    otaMPrintfExec(p, p->dbMain, "CREATE TABLE \"ota_imp_%w\"(%z)%s", 
       158749  +    rbuMPrintfExec(p, p->dbMain, "CREATE TABLE \"rbu_imp_%w\"(%z)%s", 
158744 158750           pIter->zTbl, zSql, 
158745         -        (pIter->eType==OTA_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "")
       158751  +        (pIter->eType==RBU_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "")
158746 158752       );
158747 158753       sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
158748 158754     }
158749 158755   }
158750 158756   
158751 158757   /*
158752         -** 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.
158753 158759   ** Specifically a statement of the form:
158754 158760   **
158755         -**     INSERT INTO ota_tmp_xxx VALUES(?, ?, ? ...);
       158761  +**     INSERT INTO rbu_tmp_xxx VALUES(?, ?, ? ...);
158756 158762   **
158757 158763   ** The number of bound variables is equal to the number of columns in
158758         -** the target table, plus one (for the ota_control column), plus one more 
158759         -** (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 
158760 158766   ** virtual table.
158761 158767   */
158762         -static void otaObjIterPrepareTmpInsert(
158763         -  sqlite3ota *p, 
158764         -  OtaObjIter *pIter,
       158768  +static void rbuObjIterPrepareTmpInsert(
       158769  +  sqlite3rbu *p, 
       158770  +  RbuObjIter *pIter,
158765 158771     const char *zCollist,
158766         -  const char *zOtaRowid
       158772  +  const char *zRbuRowid
158767 158773   ){
158768         -  int bOtaRowid = (pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE);
158769         -  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);
158770 158776     if( zBind ){
158771 158777       assert( pIter->pTmpInsert==0 );
158772 158778       p->rc = prepareFreeAndCollectError(
158773         -        p->dbOta, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf(
158774         -          "INSERT INTO %s.'ota_tmp_%q'(ota_control,%s%s) VALUES(%z)", 
158775         -          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
158776 158782       ));
158777 158783     }
158778 158784   }
158779 158785   
158780         -static void otaTmpInsertFunc(
       158786  +static void rbuTmpInsertFunc(
158781 158787     sqlite3_context *pCtx, 
158782 158788     int nVal,
158783 158789     sqlite3_value **apVal
158784 158790   ){
158785         -  sqlite3ota *p = sqlite3_user_data(pCtx);
       158791  +  sqlite3rbu *p = sqlite3_user_data(pCtx);
158786 158792     int rc = SQLITE_OK;
158787 158793     int i;
158788 158794   
158789 158795     for(i=0; rc==SQLITE_OK && i<nVal; i++){
158790 158796       rc = sqlite3_bind_value(p->objiter.pTmpInsert, i+1, apVal[i]);
158791 158797     }
158792 158798     if( rc==SQLITE_OK ){
................................................................................
158800 158806   }
158801 158807   
158802 158808   /*
158803 158809   ** Ensure that the SQLite statement handles required to update the 
158804 158810   ** target database object currently indicated by the iterator passed 
158805 158811   ** as the second argument are available.
158806 158812   */
158807         -static int otaObjIterPrepareAll(
158808         -  sqlite3ota *p, 
158809         -  OtaObjIter *pIter,
       158813  +static int rbuObjIterPrepareAll(
       158814  +  sqlite3rbu *p, 
       158815  +  RbuObjIter *pIter,
158810 158816     int nOffset                     /* Add "LIMIT -1 OFFSET $nOffset" to SELECT */
158811 158817   ){
158812 158818     assert( pIter->bCleanup==0 );
158813         -  if( pIter->pSelect==0 && otaObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){
       158819  +  if( pIter->pSelect==0 && rbuObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){
158814 158820       const int tnum = pIter->iTnum;
158815 158821       char *zCollist = 0;           /* List of indexed columns */
158816 158822       char **pz = &p->zErrmsg;
158817 158823       const char *zIdx = pIter->zIdx;
158818 158824       char *zLimit = 0;
158819 158825   
158820 158826       if( nOffset ){
................................................................................
158826 158832         const char *zTbl = pIter->zTbl;
158827 158833         char *zImposterCols = 0;    /* Columns for imposter table */
158828 158834         char *zImposterPK = 0;      /* Primary key declaration for imposter */
158829 158835         char *zWhere = 0;           /* WHERE clause on PK columns */
158830 158836         char *zBind = 0;
158831 158837         int nBind = 0;
158832 158838   
158833         -      assert( pIter->eType!=OTA_PK_VTAB );
158834         -      zCollist = otaObjIterGetIndexCols(
       158839  +      assert( pIter->eType!=RBU_PK_VTAB );
       158840  +      zCollist = rbuObjIterGetIndexCols(
158835 158841             p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
158836 158842         );
158837         -      zBind = otaObjIterGetBindlist(p, nBind);
       158843  +      zBind = rbuObjIterGetBindlist(p, nBind);
158838 158844   
158839 158845         /* Create the imposter table used to write to this index. */
158840 158846         sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
158841 158847         sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum);
158842         -      otaMPrintfExec(p, p->dbMain,
158843         -          "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",
158844 158850             zTbl, zImposterCols, zImposterPK
158845 158851         );
158846 158852         sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
158847 158853   
158848 158854         /* Create the statement to insert index entries */
158849 158855         pIter->nCol = nBind;
158850 158856         if( p->rc==SQLITE_OK ){
158851 158857           p->rc = prepareFreeAndCollectError(
158852 158858               p->dbMain, &pIter->pInsert, &p->zErrmsg,
158853         -          sqlite3_mprintf("INSERT INTO \"ota_imp_%w\" VALUES(%s)", zTbl, zBind)
       158859  +          sqlite3_mprintf("INSERT INTO \"rbu_imp_%w\" VALUES(%s)", zTbl, zBind)
158854 158860           );
158855 158861         }
158856 158862   
158857 158863         /* And to delete index entries */
158858 158864         if( p->rc==SQLITE_OK ){
158859 158865           p->rc = prepareFreeAndCollectError(
158860 158866               p->dbMain, &pIter->pDelete, &p->zErrmsg,
158861         -          sqlite3_mprintf("DELETE FROM \"ota_imp_%w\" WHERE %s", zTbl, zWhere)
       158867  +          sqlite3_mprintf("DELETE FROM \"rbu_imp_%w\" WHERE %s", zTbl, zWhere)
158862 158868           );
158863 158869         }
158864 158870   
158865 158871         /* Create the SELECT statement to read keys in sorted order */
158866 158872         if( p->rc==SQLITE_OK ){
158867 158873           char *zSql;
158868         -        if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){
       158874  +        if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
158869 158875             zSql = sqlite3_mprintf(
158870         -              "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",
158871 158877                 zCollist, p->zStateDb, pIter->zTbl,
158872 158878                 zCollist, zLimit
158873 158879             );
158874 158880           }else{
158875 158881             zSql = sqlite3_mprintf(
158876         -              "SELECT %s, ota_control FROM 'data_%q' "
158877         -              "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 "
158878 158884                 "UNION ALL "
158879         -              "SELECT %s, ota_control FROM %s.'ota_tmp_%q' "
       158885  +              "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
158880 158886                 "ORDER BY %s%s",
158881 158887                 zCollist, pIter->zTbl, 
158882 158888                 zCollist, p->zStateDb, pIter->zTbl, 
158883 158889                 zCollist, zLimit
158884 158890             );
158885 158891           }
158886         -        p->rc = prepareFreeAndCollectError(p->dbOta, &pIter->pSelect, pz, zSql);
       158892  +        p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
158887 158893         }
158888 158894   
158889 158895         sqlite3_free(zImposterCols);
158890 158896         sqlite3_free(zImposterPK);
158891 158897         sqlite3_free(zWhere);
158892 158898         sqlite3_free(zBind);
158893 158899       }else{
158894         -      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);
158895 158901         const char *zTbl = pIter->zTbl;       /* Table this step applies to */
158896 158902         const char *zWrite;                   /* Imposter table name */
158897 158903   
158898         -      char *zBindings = otaObjIterGetBindlist(p, pIter->nTblCol + bOtaRowid);
158899         -      char *zWhere = otaObjIterGetWhere(p, pIter);
158900         -      char *zOldlist = otaObjIterGetOldlist(p, pIter, "old");
158901         -      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");
158902 158908   
158903         -      zCollist = otaObjIterGetCollist(p, pIter);
       158909  +      zCollist = rbuObjIterGetCollist(p, pIter);
158904 158910         pIter->nCol = pIter->nTblCol;
158905 158911   
158906 158912         /* Create the SELECT statement to read keys from data_xxx */
158907 158913         if( p->rc==SQLITE_OK ){
158908         -        p->rc = prepareFreeAndCollectError(p->dbOta, &pIter->pSelect, pz,
       158914  +        p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
158909 158915               sqlite3_mprintf(
158910         -              "SELECT %s, ota_control%s FROM 'data_%q'%s", 
158911         -              zCollist, (bOtaRowid ? ", ota_rowid" : ""), zTbl, zLimit
       158916  +              "SELECT %s, rbu_control%s FROM 'data_%q'%s", 
       158917  +              zCollist, (bRbuRowid ? ", rbu_rowid" : ""), zTbl, zLimit
158912 158918               )
158913 158919           );
158914 158920         }
158915 158921   
158916 158922         /* Create the imposter table or tables (if required). */
158917         -      otaCreateImposterTable(p, pIter);
158918         -      otaCreateImposterTable2(p, pIter);
158919         -      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_");
158920 158926   
158921 158927         /* Create the INSERT statement to write to the target PK b-tree */
158922 158928         if( p->rc==SQLITE_OK ){
158923 158929           p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pInsert, pz,
158924 158930               sqlite3_mprintf(
158925 158931                 "INSERT INTO \"%s%w\"(%s%s) VALUES(%s)", 
158926         -              zWrite, zTbl, zCollist, (bOtaRowid ? ", _rowid_" : ""), zBindings
       158932  +              zWrite, zTbl, zCollist, (bRbuRowid ? ", _rowid_" : ""), zBindings
158927 158933               )
158928 158934           );
158929 158935         }
158930 158936   
158931 158937         /* Create the DELETE statement to write to the target PK b-tree */
158932 158938         if( p->rc==SQLITE_OK ){
158933 158939           p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pDelete, pz,
................................................................................
158934 158940               sqlite3_mprintf(
158935 158941                 "DELETE FROM \"%s%w\" WHERE %s", zWrite, zTbl, zWhere
158936 158942               )
158937 158943           );
158938 158944         }
158939 158945   
158940 158946         if( pIter->abIndexed ){
158941         -        const char *zOtaRowid = "";
158942         -        if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){
158943         -          zOtaRowid = ", ota_rowid";
       158947  +        const char *zRbuRowid = "";
       158948  +        if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
       158949  +          zRbuRowid = ", rbu_rowid";
158944 158950           }
158945 158951   
158946         -        /* Create the ota_tmp_xxx table and the triggers to populate it. */
158947         -        otaMPrintfExec(p, p->dbOta,
158948         -            "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 "
158949 158955               "SELECT *%s FROM 'data_%q' WHERE 0;"
158950 158956               , p->zStateDb
158951         -            , zTbl, (pIter->eType==OTA_PK_EXTERNAL ? ", 0 AS ota_rowid" : "")
       158957  +            , zTbl, (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
158952 158958               , zTbl
158953 158959           );
158954 158960   
158955         -        otaMPrintfExec(p, p->dbMain,
158956         -            "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\" "
158957 158963               "BEGIN "
158958         -            "  SELECT ota_tmp_insert(2, %s);"
       158964  +            "  SELECT rbu_tmp_insert(2, %s);"
158959 158965               "END;"
158960 158966   
158961         -            "CREATE TEMP TRIGGER ota_update1_tr BEFORE UPDATE ON \"%s%w\" "
       158967  +            "CREATE TEMP TRIGGER rbu_update1_tr BEFORE UPDATE ON \"%s%w\" "
158962 158968               "BEGIN "
158963         -            "  SELECT ota_tmp_insert(2, %s);"
       158969  +            "  SELECT rbu_tmp_insert(2, %s);"
158964 158970               "END;"
158965 158971   
158966         -            "CREATE TEMP TRIGGER ota_update2_tr AFTER UPDATE ON \"%s%w\" "
       158972  +            "CREATE TEMP TRIGGER rbu_update2_tr AFTER UPDATE ON \"%s%w\" "
158967 158973               "BEGIN "
158968         -            "  SELECT ota_tmp_insert(3, %s);"
       158974  +            "  SELECT rbu_tmp_insert(3, %s);"
158969 158975               "END;",
158970 158976               zWrite, zTbl, zOldlist,
158971 158977               zWrite, zTbl, zOldlist,
158972 158978               zWrite, zTbl, zNewlist
158973 158979           );
158974 158980   
158975         -        if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){
158976         -          otaMPrintfExec(p, p->dbMain,
158977         -              "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\" "
158978 158984                 "BEGIN "
158979         -              "  SELECT ota_tmp_insert(0, %s);"
       158985  +              "  SELECT rbu_tmp_insert(0, %s);"
158980 158986                 "END;",
158981 158987                 zWrite, zTbl, zNewlist
158982 158988             );
158983 158989           }
158984 158990   
158985         -        otaObjIterPrepareTmpInsert(p, pIter, zCollist, zOtaRowid);
       158991  +        rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
158986 158992         }
158987 158993   
158988 158994         sqlite3_free(zWhere);
158989 158995         sqlite3_free(zOldlist);
158990 158996         sqlite3_free(zNewlist);
158991 158997         sqlite3_free(zBindings);
158992 158998       }
................................................................................
158997 159003     return p->rc;
158998 159004   }
158999 159005   
159000 159006   /*
159001 159007   ** Set output variable *ppStmt to point to an UPDATE statement that may
159002 159008   ** be used to update the imposter table for the main table b-tree of the
159003 159009   ** table object that pIter currently points to, assuming that the 
159004         -** ota_control column of the data_xyz table contains zMask.
       159010  +** rbu_control column of the data_xyz table contains zMask.
159005 159011   ** 
159006 159012   ** If the zMask string does not specify any columns to update, then this
159007 159013   ** is not an error. Output variable *ppStmt is set to NULL in this case.
159008 159014   */
159009         -static int otaGetUpdateStmt(
159010         -  sqlite3ota *p,                  /* OTA handle */
159011         -  OtaObjIter *pIter,              /* Object iterator */
159012         -  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.') */
159013 159019     sqlite3_stmt **ppStmt           /* OUT: UPDATE statement handle */
159014 159020   ){
159015         -  OtaUpdateStmt **pp;
159016         -  OtaUpdateStmt *pUp = 0;
       159021  +  RbuUpdateStmt **pp;
       159022  +  RbuUpdateStmt *pUp = 0;
159017 159023     int nUp = 0;
159018 159024   
159019 159025     /* In case an error occurs */
159020 159026     *ppStmt = 0;
159021 159027   
159022 159028     /* Search for an existing statement. If one is found, shift it to the front
159023 159029     ** of the LRU queue and return immediately. Otherwise, leave nUp pointing
159024 159030     ** to the number of statements currently in the cache and pUp to the
159025 159031     ** last object in the list.  */
159026         -  for(pp=&pIter->pOtaUpdate; *pp; pp=&((*pp)->pNext)){
       159032  +  for(pp=&pIter->pRbuUpdate; *pp; pp=&((*pp)->pNext)){
159027 159033       pUp = *pp;
159028 159034       if( strcmp(pUp->zMask, zMask)==0 ){
159029 159035         *pp = pUp->pNext;
159030         -      pUp->pNext = pIter->pOtaUpdate;
159031         -      pIter->pOtaUpdate = pUp;
       159036  +      pUp->pNext = pIter->pRbuUpdate;
       159037  +      pIter->pRbuUpdate = pUp;
159032 159038         *ppStmt = pUp->pUpdate; 
159033 159039         return SQLITE_OK;
159034 159040       }
159035 159041       nUp++;
159036 159042     }
159037 159043     assert( pUp==0 || pUp->pNext==0 );
159038 159044   
159039         -  if( nUp>=SQLITE_OTA_UPDATE_CACHESIZE ){
159040         -    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));
159041 159047       *pp = 0;
159042 159048       sqlite3_finalize(pUp->pUpdate);
159043 159049       pUp->pUpdate = 0;
159044 159050     }else{
159045         -    pUp = (OtaUpdateStmt*)otaMalloc(p, sizeof(OtaUpdateStmt)+pIter->nTblCol+1);
       159051  +    pUp = (RbuUpdateStmt*)rbuMalloc(p, sizeof(RbuUpdateStmt)+pIter->nTblCol+1);
159046 159052     }
159047 159053   
159048 159054     if( pUp ){
159049         -    char *zWhere = otaObjIterGetWhere(p, pIter);
159050         -    char *zSet = otaObjIterGetSetlist(p, pIter, zMask);
       159055  +    char *zWhere = rbuObjIterGetWhere(p, pIter);
       159056  +    char *zSet = rbuObjIterGetSetlist(p, pIter, zMask);
159051 159057       char *zUpdate = 0;
159052 159058   
159053 159059       pUp->zMask = (char*)&pUp[1];
159054 159060       memcpy(pUp->zMask, zMask, pIter->nTblCol);
159055         -    pUp->pNext = pIter->pOtaUpdate;
159056         -    pIter->pOtaUpdate = pUp;
       159061  +    pUp->pNext = pIter->pRbuUpdate;
       159062  +    pIter->pRbuUpdate = pUp;
159057 159063   
159058 159064       if( zSet ){
159059 159065         const char *zPrefix = "";
159060 159066   
159061         -      if( pIter->eType!=OTA_PK_VTAB ) zPrefix = "ota_imp_";
       159067  +      if( pIter->eType!=RBU_PK_VTAB ) zPrefix = "rbu_imp_";
159062 159068         zUpdate = sqlite3_mprintf("UPDATE \"%s%w\" SET %s WHERE %s", 
159063 159069             zPrefix, pIter->zTbl, zSet, zWhere
159064 159070         );
159065 159071         p->rc = prepareFreeAndCollectError(
159066 159072             p->dbMain, &pUp->pUpdate, &p->zErrmsg, zUpdate
159067 159073         );
159068 159074         *ppStmt = pUp->pUpdate;
................................................................................
159070 159076       sqlite3_free(zWhere);
159071 159077       sqlite3_free(zSet);
159072 159078     }
159073 159079   
159074 159080     return p->rc;
159075 159081   }
159076 159082   
159077         -static sqlite3 *otaOpenDbhandle(sqlite3ota *p, const char *zName){
       159083  +static sqlite3 *rbuOpenDbhandle(sqlite3rbu *p, const char *zName){
159078 159084     sqlite3 *db = 0;
159079 159085     if( p->rc==SQLITE_OK ){
159080 159086       const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI;
159081 159087       p->rc = sqlite3_open_v2(zName, &db, flags, p->zVfsName);
159082 159088       if( p->rc ){
159083 159089         p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
159084 159090         sqlite3_close(db);
................................................................................
159085 159091         db = 0;
159086 159092       }
159087 159093     }
159088 159094     return db;
159089 159095   }
159090 159096   
159091 159097   /*
159092         -** Open the database handle and attach the OTA database as "ota". If an
159093         -** 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.
159094 159100   */
159095         -static void otaOpenDatabase(sqlite3ota *p){
       159101  +static void rbuOpenDatabase(sqlite3rbu *p){
159096 159102     assert( p->rc==SQLITE_OK );
159097         -  assert( p->dbMain==0 && p->dbOta==0 );
       159103  +  assert( p->dbMain==0 && p->dbRbu==0 );
159098 159104   
159099 159105     p->eStage = 0;
159100         -  p->dbMain = otaOpenDbhandle(p, p->zTarget);
159101         -  p->dbOta = otaOpenDbhandle(p, p->zOta);
       159106  +  p->dbMain = rbuOpenDbhandle(p, p->zTarget);
       159107  +  p->dbRbu = rbuOpenDbhandle(p, p->zRbu);
159102 159108   
159103         -  /* If using separate OTA and state databases, attach the state database to
159104         -  ** the OTA db handle now.  */
       159109  +  /* If using separate RBU and state databases, attach the state database to
       159110  +  ** the RBU db handle now.  */
159105 159111     if( p->zState ){
159106         -    otaMPrintfExec(p, p->dbOta, "ATTACH %Q AS stat", p->zState);
       159112  +    rbuMPrintfExec(p, p->dbRbu, "ATTACH %Q AS stat", p->zState);
159107 159113       memcpy(p->zStateDb, "stat", 4);
159108 159114     }else{
159109 159115       memcpy(p->zStateDb, "main", 4);
159110 159116     }
159111 159117   
159112 159118     if( p->rc==SQLITE_OK ){
159113 159119       p->rc = sqlite3_create_function(p->dbMain, 
159114         -        "ota_tmp_insert", -1, SQLITE_UTF8, (void*)p, otaTmpInsertFunc, 0, 0
       159120  +        "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
159115 159121       );
159116 159122     }
159117 159123   
159118 159124     if( p->rc==SQLITE_OK ){
159119         -    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);
159120 159126     }
159121         -  otaMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master");
       159127  +  rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master");
159122 159128   
159123         -  /* Mark the database file just opened as an OTA target database. If 
159124         -  ** 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.
159125 159131     ** This is an error.  */
159126 159132     if( p->rc==SQLITE_OK ){
159127         -    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);
159128 159134     }
159129 159135   
159130 159136     if( p->rc==SQLITE_NOTFOUND ){
159131 159137       p->rc = SQLITE_ERROR;
159132         -    p->zErrmsg = sqlite3_mprintf("ota vfs not found");
       159138  +    p->zErrmsg = sqlite3_mprintf("rbu vfs not found");
159133 159139     }
159134 159140   }
159135 159141   
159136 159142   /*
159137 159143   ** This routine is a copy of the sqlite3FileSuffix3() routine from the core.
159138 159144   ** It is a no-op unless SQLITE_ENABLE_8_3_NAMES is defined.
159139 159145   **
................................................................................
159149 159155   ** Examples:
159150 159156   **
159151 159157   **     test.db-journal    =>   test.nal
159152 159158   **     test.db-wal        =>   test.wal
159153 159159   **     test.db-shm        =>   test.shm
159154 159160   **     test.db-mj7f3319fa =>   test.9fa
159155 159161   */
159156         -static void otaFileSuffix3(const char *zBase, char *z){
       159162  +static void rbuFileSuffix3(const char *zBase, char *z){
159157 159163   #ifdef SQLITE_ENABLE_8_3_NAMES
159158 159164   #if SQLITE_ENABLE_8_3_NAMES<2
159159 159165     if( sqlite3_uri_boolean(zBase, "8_3_names", 0) )
159160 159166   #endif
159161 159167     {
159162 159168       int i, sz;
159163 159169       sz = sqlite3Strlen30(z);
................................................................................
159170 159176   /*
159171 159177   ** Return the current wal-index header checksum for the target database 
159172 159178   ** as a 64-bit integer.
159173 159179   **
159174 159180   ** The checksum is store in the first page of xShmMap memory as an 8-byte 
159175 159181   ** blob starting at byte offset 40.
159176 159182   */
159177         -static i64 otaShmChecksum(sqlite3ota *p){
       159183  +static i64 rbuShmChecksum(sqlite3rbu *p){
159178 159184     i64 iRet = 0;
159179 159185     if( p->rc==SQLITE_OK ){
159180 159186       sqlite3_file *pDb = p->pTargetFd->pReal;
159181 159187       u32 volatile *ptr;
159182 159188       p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, (void volatile**)&ptr);
159183 159189       if( p->rc==SQLITE_OK ){
159184 159190         iRet = ((i64)ptr[10] << 32) + ptr[11];
................................................................................
159187 159193     return iRet;
159188 159194   }
159189 159195   
159190 159196   /*
159191 159197   ** This function is called as part of initializing or reinitializing an
159192 159198   ** incremental checkpoint. 
159193 159199   **
159194         -** It populates the sqlite3ota.aFrame[] array with the set of 
       159200  +** It populates the sqlite3rbu.aFrame[] array with the set of 
159195 159201   ** (wal frame -> db page) copy operations required to checkpoint the 
159196 159202   ** current wal file, and obtains the set of shm locks required to safely 
159197 159203   ** perform the copy operations directly on the file-system.
159198 159204   **
159199 159205   ** If argument pState is not NULL, then the incremental checkpoint is
159200 159206   ** being resumed. In this case, if the checksum of the wal-index-header
159201         -** following recovery is not the same as the checksum saved in the OtaState
159202         -** 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
159203 159209   ** other client appends a transaction to the wal file in the middle of
159204 159210   ** an incremental checkpoint.
159205 159211   */
159206         -static void otaSetupCheckpoint(sqlite3ota *p, OtaState *pState){
       159212  +static void rbuSetupCheckpoint(sqlite3rbu *p, RbuState *pState){
159207 159213   
159208 159214     /* If pState is NULL, then the wal file may not have been opened and
159209 159215     ** recovered. Running a read-statement here to ensure that doing so
159210 159216     ** does not interfere with the "capture" process below.  */
159211 159217     if( pState==0 ){
159212 159218       p->eStage = 0;
159213 159219       if( p->rc==SQLITE_OK ){
159214 159220         p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_master", 0, 0, 0);
159215 159221       }
159216 159222     }
159217 159223   
159218 159224     /* Assuming no error has occurred, run a "restart" checkpoint with the
159219         -  ** sqlite3ota.eStage variable set to CAPTURE. This turns on the following
159220         -  ** 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:
159221 159227     **
159222 159228     **   * If the exclusive shm WRITER or READ0 lock cannot be obtained,
159223 159229     **     the checkpoint fails with SQLITE_BUSY (normally SQLite would
159224 159230     **     proceed with running a passive checkpoint instead of failing).
159225 159231     **
159226 159232     **   * Attempts to read from the *-wal file or write to the database file
159227 159233     **     do not perform any IO. Instead, the frame/page combinations that
159228         -  **     would be read/written are recorded in the sqlite3ota.aFrame[]
       159234  +  **     would be read/written are recorded in the sqlite3rbu.aFrame[]
159229 159235     **     array.
159230 159236     **
159231 159237     **   * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER, 
159232 159238     **     READ0 and CHECKPOINT locks taken as part of the checkpoint are
159233 159239     **     no-ops. These locks will not be released until the connection
159234 159240     **     is closed.
159235 159241     **
................................................................................
159241 159247     ** array populated with a set of (frame -> page) mappings. Because the 
159242 159248     ** WRITER, CHECKPOINT and READ0 locks are still held, it is safe to copy 
159243 159249     ** data from the wal file into the database file according to the 
159244 159250     ** contents of aFrame[].
159245 159251     */
159246 159252     if( p->rc==SQLITE_OK ){
159247 159253       int rc2;
159248         -    p->eStage = OTA_STAGE_CAPTURE;
       159254  +    p->eStage = RBU_STAGE_CAPTURE;
159249 159255       rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
159250 159256       if( rc2!=SQLITE_INTERNAL ) p->rc = rc2;
159251 159257     }
159252 159258   
159253 159259     if( p->rc==SQLITE_OK ){
159254         -    p->eStage = OTA_STAGE_CKPT;
       159260  +    p->eStage = RBU_STAGE_CKPT;
159255 159261       p->nStep = (pState ? pState->nRow : 0);
159256         -    p->aBuf = otaMalloc(p, p->pgsz);
159257         -    p->iWalCksum = otaShmChecksum(p);
       159262  +    p->aBuf = rbuMalloc(p, p->pgsz);
       159263  +    p->iWalCksum = rbuShmChecksum(p);
159258 159264     }
159259 159265   
159260 159266     if( p->rc==SQLITE_OK && pState && pState->iWalCksum!=p->iWalCksum ){
159261 159267       p->rc = SQLITE_DONE;
159262         -    p->eStage = OTA_STAGE_DONE;
       159268  +    p->eStage = RBU_STAGE_DONE;
159263 159269     }
159264 159270   }
159265 159271   
159266 159272   /*
159267 159273   ** Called when iAmt bytes are read from offset iOff of the wal file while
159268         -** 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
159269 159275   ** being read in the aFrame[] array.
159270 159276   */
159271         -static int otaCaptureWalRead(sqlite3ota *pOta, i64 iOff, int iAmt){
       159277  +static int rbuCaptureWalRead(sqlite3rbu *pRbu, i64 iOff, int iAmt){
159272 159278     const u32 mReq = (1<<WAL_LOCK_WRITE)|(1<<WAL_LOCK_CKPT)|(1<<WAL_LOCK_READ0);
159273 159279     u32 iFrame;
159274 159280   
159275         -  if( pOta->mLock!=mReq ){
159276         -    pOta->rc = SQLITE_BUSY;
       159281  +  if( pRbu->mLock!=mReq ){
       159282  +    pRbu->rc = SQLITE_BUSY;
159277 159283       return SQLITE_INTERNAL;
159278 159284     }
159279 159285   
159280         -  pOta->pgsz = iAmt;
159281         -  if( pOta->nFrame==pOta->nFrameAlloc ){
159282         -    int nNew = (pOta->nFrameAlloc ? pOta->nFrameAlloc : 64) * 2;
159283         -    OtaFrame *aNew;
159284         -    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));
159285 159291       if( aNew==0 ) return SQLITE_NOMEM;
159286         -    pOta->aFrame = aNew;
159287         -    pOta->nFrameAlloc = nNew;
       159292  +    pRbu->aFrame = aNew;
       159293  +    pRbu->nFrameAlloc = nNew;
159288 159294     }
159289 159295   
159290 159296     iFrame = (u32)((iOff-32) / (i64)(iAmt+24)) + 1;
159291         -  if( pOta->iMaxFrame<iFrame ) pOta->iMaxFrame = iFrame;
159292         -  pOta->aFrame[pOta->nFrame].iWalFrame = iFrame;
159293         -  pOta->aFrame[pOta->nFrame].iDbPage = 0;
159294         -  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++;
159295 159301     return SQLITE_OK;
159296 159302   }
159297 159303   
159298 159304   /*
159299 159305   ** Called when a page of data is written to offset iOff of the database
159300         -** 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 
159301 159307   ** of the page being written in the aFrame[] array.
159302 159308   */
159303         -static int otaCaptureDbWrite(sqlite3ota *pOta, i64 iOff){
159304         -  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;
159305 159311     return SQLITE_OK;
159306 159312   }
159307 159313   
159308 159314   /*
159309 159315   ** This is called as part of an incremental checkpoint operation. Copy
159310 159316   ** a single frame of data from the wal file into the database file, as
159311         -** indicated by the OtaFrame object.
       159317  +** indicated by the RbuFrame object.
159312 159318   */
159313         -static void otaCheckpointFrame(sqlite3ota *p, OtaFrame *pFrame){
       159319  +static void rbuCheckpointFrame(sqlite3rbu *p, RbuFrame *pFrame){
159314 159320     sqlite3_file *pWal = p->pTargetFd->pWalFd->pReal;
159315 159321     sqlite3_file *pDb = p->pTargetFd->pReal;
159316 159322     i64 iOff;
159317 159323   
159318 159324     assert( p->rc==SQLITE_OK );
159319 159325     iOff = (i64)(pFrame->iWalFrame-1) * (p->pgsz + 24) + 32 + 24;
159320 159326     p->rc = pWal->pMethods->xRead(pWal, p->aBuf, p->pgsz, iOff);
................................................................................
159324 159330     p->rc = pDb->pMethods->xWrite(pDb, p->aBuf, p->pgsz, iOff);
159325 159331   }
159326 159332   
159327 159333   
159328 159334   /*
159329 159335   ** Take an EXCLUSIVE lock on the database file.
159330 159336   */
159331         -static void otaLockDatabase(sqlite3ota *p){
       159337  +static void rbuLockDatabase(sqlite3rbu *p){
159332 159338     sqlite3_file *pReal = p->pTargetFd->pReal;
159333 159339     assert( p->rc==SQLITE_OK );
159334 159340     p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_SHARED);
159335 159341     if( p->rc==SQLITE_OK ){
159336 159342       p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_EXCLUSIVE);
159337 159343     }
159338 159344   }
159339 159345   
159340 159346   /*
159341         -** 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
159342 159348   ** on the database file. This proc moves the *-oal file to the *-wal path,
159343 159349   ** then reopens the database file (this time in vanilla, non-oal, WAL mode).
159344         -** 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 
159345 159351   ** handle.
159346 159352   */
159347         -static void otaMoveOalFile(sqlite3ota *p){
       159353  +static void rbuMoveOalFile(sqlite3rbu *p){
159348 159354     const char *zBase = sqlite3_db_filename(p->dbMain, "main");
159349 159355   
159350 159356     char *zWal = sqlite3_mprintf("%s-wal", zBase);
159351 159357     char *zOal = sqlite3_mprintf("%s-oal", zBase);
159352 159358   
159353         -  assert( p->eStage==OTA_STAGE_MOVE );
       159359  +  assert( p->eStage==RBU_STAGE_MOVE );
159354 159360     assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
159355 159361     if( zWal==0 || zOal==0 ){
159356 159362       p->rc = SQLITE_NOMEM;
159357 159363     }else{
159358 159364       /* Move the *-oal file to *-wal. At this point connection p->db is
159359 159365       ** holding a SHARED lock on the target database file (because it is
159360 159366       ** in WAL mode). So no other connection may be writing the db. 
159361 159367       **
159362 159368       ** In order to ensure that there are no database readers, an EXCLUSIVE
159363 159369       ** lock is obtained here before the *-oal is moved to *-wal.
159364 159370       */
159365         -    otaLockDatabase(p);
       159371  +    rbuLockDatabase(p);
159366 159372       if( p->rc==SQLITE_OK ){
159367         -      otaFileSuffix3(zBase, zWal);
159368         -      otaFileSuffix3(zBase, zOal);
       159373  +      rbuFileSuffix3(zBase, zWal);
       159374  +      rbuFileSuffix3(zBase, zOal);
159369 159375   
159370 159376         /* Re-open the databases. */
159371         -      otaObjIterFinalize(&p->objiter);
       159377  +      rbuObjIterFinalize(&p->objiter);
159372 159378         sqlite3_close(p->dbMain);
159373         -      sqlite3_close(p->dbOta);
       159379  +      sqlite3_close(p->dbRbu);
159374 159380         p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK;
159375 159381         if( p->rc==SQLITE_OK ){
159376 159382           p->dbMain = 0;
159377         -        p->dbOta = 0;
159378         -        otaOpenDatabase(p);
159379         -        otaSetupCheckpoint(p, 0);
       159383  +        p->dbRbu = 0;
       159384  +        rbuOpenDatabase(p);
       159385  +        rbuSetupCheckpoint(p, 0);
159380 159386         }
159381 159387       }
159382 159388     }
159383 159389   
159384 159390     sqlite3_free(zWal);
159385 159391     sqlite3_free(zOal);
159386 159392   }
................................................................................
159387 159393   
159388 159394   /*
159389 159395   ** The SELECT statement iterating through the keys for the current object
159390 159396   ** (p->objiter.pSelect) currently points to a valid row. This function
159391 159397   ** determines the type of operation requested by this row and returns
159392 159398   ** one of the following values to indicate the result:
159393 159399   **
159394         -**     * OTA_INSERT
159395         -**     * OTA_DELETE
159396         -**     * OTA_IDX_DELETE
159397         -**     * OTA_UPDATE
       159400  +**     * RBU_INSERT
       159401  +**     * RBU_DELETE
       159402  +**     * RBU_IDX_DELETE
       159403  +**     * RBU_UPDATE
159398 159404   **
159399         -** 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
159400 159406   ** point to the text value indicating the columns to update.
159401 159407   **
159402         -** If the ota_control field contains an invalid value, an error code and
159403         -** 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.
159404 159410   */
159405         -static int otaStepType(sqlite3ota *p, const char **pzMask){
159406         -  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 */
159407 159413     int res = 0;                    /* Return value */
159408 159414   
159409 159415     switch( sqlite3_column_type(p->objiter.pSelect, iCol) ){
159410 159416       case SQLITE_INTEGER: {
159411 159417         int iVal = sqlite3_column_int(p->objiter.pSelect, iCol);
159412 159418         if( iVal==0 ){
159413         -        res = OTA_INSERT;
       159419  +        res = RBU_INSERT;
159414 159420         }else if( iVal==1 ){
159415         -        res = OTA_DELETE;
       159421  +        res = RBU_DELETE;
159416 159422         }else if( iVal==2 ){
159417         -        res = OTA_IDX_DELETE;
       159423  +        res = RBU_IDX_DELETE;
159418 159424         }else if( iVal==3 ){
159419         -        res = OTA_IDX_INSERT;
       159425  +        res = RBU_IDX_INSERT;
159420 159426         }
159421 159427         break;
159422 159428       }
159423 159429   
159424 159430       case SQLITE_TEXT: {
159425 159431         const unsigned char *z = sqlite3_column_text(p->objiter.pSelect, iCol);
159426 159432         if( z==0 ){
159427 159433           p->rc = SQLITE_NOMEM;
159428 159434         }else{
159429 159435           *pzMask = (const char*)z;
159430 159436         }
159431         -      res = OTA_UPDATE;
       159437  +      res = RBU_UPDATE;
159432 159438   
159433 159439         break;
159434 159440       }
159435 159441   
159436 159442       default:
159437 159443         break;
159438 159444     }
159439 159445   
159440 159446     if( res==0 ){
159441         -    otaBadControlError(p);
       159447  +    rbuBadControlError(p);
159442 159448     }
159443 159449     return res;
159444 159450   }
159445 159451   
159446 159452   #ifdef SQLITE_DEBUG
159447 159453   /*
159448 159454   ** Assert that column iCol of statement pStmt is named zName.
................................................................................
159452 159458     assert( 0==sqlite3_stricmp(zName, zCol) );
159453 159459   }
159454 159460   #else
159455 159461   # define assertColumnName(x,y,z)
159456 159462   #endif
159457 159463   
159458 159464   /*
159459         -** This function does the work for an sqlite3ota_step() call.
       159465  +** This function does the work for an sqlite3rbu_step() call.
159460 159466   **
159461 159467   ** The object-iterator (p->objiter) currently points to a valid object,
159462 159468   ** and the input cursor (p->objiter.pSelect) currently points to a valid
159463 159469   ** input row. Perform whatever processing is required and return.
159464 159470   **
159465 159471   ** If no  error occurs, SQLITE_OK is returned. Otherwise, an error code
159466         -** 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
159467 159473   ** returned.
159468 159474   */
159469         -static int otaStep(sqlite3ota *p){
159470         -  OtaObjIter *pIter = &p->objiter;
       159475  +static int rbuStep(sqlite3rbu *p){
       159476  +  RbuObjIter *pIter = &p->objiter;
159471 159477     const char *zMask = 0;
159472 159478     int i;
159473         -  int eType = otaStepType(p, &zMask);
       159479  +  int eType = rbuStepType(p, &zMask);
159474 159480   
159475 159481     if( eType ){
159476         -    assert( eType!=OTA_UPDATE || pIter->zIdx==0 );
       159482  +    assert( eType!=RBU_UPDATE || pIter->zIdx==0 );
159477 159483   
159478         -    if( pIter->zIdx==0 && eType==OTA_IDX_DELETE ){
159479         -      otaBadControlError(p);
       159484  +    if( pIter->zIdx==0 && eType==RBU_IDX_DELETE ){
       159485  +      rbuBadControlError(p);
159480 159486       }
159481 159487       else if( 
159482         -        eType==OTA_INSERT 
159483         -     || eType==OTA_DELETE
159484         -     || eType==OTA_IDX_DELETE 
159485         -     || eType==OTA_IDX_INSERT
       159488  +        eType==RBU_INSERT 
       159489  +     || eType==RBU_DELETE
       159490  +     || eType==RBU_IDX_DELETE 
       159491  +     || eType==RBU_IDX_INSERT
159486 159492       ){
159487 159493         sqlite3_value *pVal;
159488 159494         sqlite3_stmt *pWriter;
159489 159495   
159490         -      assert( eType!=OTA_UPDATE );
159491         -      assert( eType!=OTA_DELETE || pIter->zIdx==0 );
       159496  +      assert( eType!=RBU_UPDATE );
       159497  +      assert( eType!=RBU_DELETE || pIter->zIdx==0 );
159492 159498   
159493         -      if( eType==OTA_IDX_DELETE || eType==OTA_DELETE ){
       159499  +      if( eType==RBU_IDX_DELETE || eType==RBU_DELETE ){
159494 159500           pWriter = pIter->pDelete;
159495 159501         }else{
159496 159502           pWriter = pIter->pInsert;
159497 159503         }
159498 159504   
159499 159505         for(i=0; i<pIter->nCol; i++){
159500 159506           /* If this is an INSERT into a table b-tree and the table has an
159501 159507           ** explicit INTEGER PRIMARY KEY, check that this is not an attempt
159502 159508           ** to write a NULL into the IPK column. That is not permitted.  */
159503         -        if( eType==OTA_INSERT 
159504         -         && 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] 
159505 159511            && sqlite3_column_type(pIter->pSelect, i)==SQLITE_NULL
159506 159512           ){
159507 159513             p->rc = SQLITE_MISMATCH;
159508 159514             p->zErrmsg = sqlite3_mprintf("datatype mismatch");
159509 159515             goto step_out;
159510 159516           }
159511 159517   
159512         -        if( eType==OTA_DELETE && pIter->abTblPk[i]==0 ){
       159518  +        if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){
159513 159519             continue;
159514 159520           }
159515 159521   
159516 159522           pVal = sqlite3_column_value(pIter->pSelect, i);
159517 159523           p->rc = sqlite3_bind_value(pWriter, i+1, pVal);
159518 159524           if( p->rc ) goto step_out;
159519 159525         }
159520 159526         if( pIter->zIdx==0
159521         -       && (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE) 
       159527  +       && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) 
159522 159528         ){
159523 159529           /* For a virtual table, or a table with no primary key, the 
159524 159530           ** SELECT statement is:
159525 159531           **
159526         -        **   SELECT <cols>, ota_control, ota_rowid FROM ....
       159532  +        **   SELECT <cols>, rbu_control, rbu_rowid FROM ....
159527 159533           **
159528 159534           ** Hence column_value(pIter->nCol+1).
159529 159535           */
159530         -        assertColumnName(pIter->pSelect, pIter->nCol+1, "ota_rowid");
       159536  +        assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
159531 159537           pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
159532 159538           p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
159533 159539         }
159534 159540         if( p->rc==SQLITE_OK ){
159535 159541           sqlite3_step(pWriter);
159536 159542           p->rc = resetAndCollectError(pWriter, &p->zErrmsg);
159537 159543         }
159538 159544       }else{
159539 159545         sqlite3_value *pVal;
159540 159546         sqlite3_stmt *pUpdate = 0;
159541         -      assert( eType==OTA_UPDATE );
159542         -      otaGetUpdateStmt(p, pIter, zMask, &pUpdate);
       159547  +      assert( eType==RBU_UPDATE );
       159548  +      rbuGetUpdateStmt(p, pIter, zMask, &pUpdate);
159543 159549         if( pUpdate ){
159544 159550           for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
159545 159551             char c = zMask[pIter->aiSrcOrder[i]];
159546 159552             pVal = sqlite3_column_value(pIter->pSelect, i);
159547 159553             if( pIter->abTblPk[i] || c=='x' || c=='d' ){
159548 159554               p->rc = sqlite3_bind_value(pUpdate, i+1, pVal);
159549 159555             }
159550 159556           }
159551 159557           if( p->rc==SQLITE_OK 
159552         -         && (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE) 
       159558  +         && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) 
159553 159559           ){
159554         -          /* Bind the ota_rowid value to column _rowid_ */
159555         -          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");
159556 159562             pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
159557 159563             p->rc = sqlite3_bind_value(pUpdate, pIter->nCol+1, pVal);
159558 159564           }
159559 159565           if( p->rc==SQLITE_OK ){
159560 159566             sqlite3_step(pUpdate);
159561 159567             p->rc = resetAndCollectError(pUpdate, &p->zErrmsg);
159562 159568           }
................................................................................
159567 159573    step_out:
159568 159574     return p->rc;
159569 159575   }
159570 159576   
159571 159577   /*
159572 159578   ** Increment the schema cookie of the main database opened by p->dbMain.
159573 159579   */
159574         -static void otaIncrSchemaCookie(sqlite3ota *p){
       159580  +static void rbuIncrSchemaCookie(sqlite3rbu *p){
159575 159581     if( p->rc==SQLITE_OK ){
159576 159582       int iCookie = 1000000;
159577 159583       sqlite3_stmt *pStmt;
159578 159584   
159579 159585       p->rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg, 
159580 159586           "PRAGMA schema_version"
159581 159587       );
................................................................................
159584 159590         ** is already a transaction open, so the prepared statement cannot
159585 159591         ** throw an SQLITE_SCHEMA exception. The only database page the
159586 159592         ** statement reads is page 1, which is guaranteed to be in the cache.
159587 159593         ** And no memory allocations are required.  */
159588 159594         if( SQLITE_ROW==sqlite3_step(pStmt) ){
159589 159595           iCookie = sqlite3_column_int(pStmt, 0);
159590 159596         }
159591         -      otaFinalize(p, pStmt);
       159597  +      rbuFinalize(p, pStmt);
159592 159598       }
159593 159599       if( p->rc==SQLITE_OK ){
159594         -      otaMPrintfExec(p, p->dbMain, "PRAGMA schema_version = %d", iCookie+1);
       159600  +      rbuMPrintfExec(p, p->dbMain, "PRAGMA schema_version = %d", iCookie+1);
159595 159601       }
159596 159602     }
159597 159603   }
159598 159604   
159599 159605   /*
159600         -** Update the contents of the ota_state table within the ota database. The
159601         -** value stored in the OTA_STATE_STAGE column is eStage. All other values
159602         -** 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.
159603 159609   */
159604         -static void otaSaveState(sqlite3ota *p, int eStage){
       159610  +static void rbuSaveState(sqlite3rbu *p, int eStage){
159605 159611     if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){
159606 159612       sqlite3_stmt *pInsert = 0;
159607 159613       int rc;
159608 159614   
159609 159615       assert( p->zErrmsg==0 );
159610         -    rc = prepareFreeAndCollectError(p->dbOta, &pInsert, &p->zErrmsg, 
       159616  +    rc = prepareFreeAndCollectError(p->dbRbu, &pInsert, &p->zErrmsg, 
159611 159617           sqlite3_mprintf(
159612         -          "INSERT OR REPLACE INTO %s.ota_state(k, v) VALUES "
       159618  +          "INSERT OR REPLACE INTO %s.rbu_state(k, v) VALUES "
159613 159619             "(%d, %d), "
159614 159620             "(%d, %Q), "
159615 159621             "(%d, %Q), "
159616 159622             "(%d, %d), "
159617 159623             "(%d, %d), "
159618 159624             "(%d, %lld), "
159619 159625             "(%d, %lld), "
159620 159626             "(%d, %lld) ",
159621 159627             p->zStateDb,
159622         -          OTA_STATE_STAGE, eStage,
159623         -          OTA_STATE_TBL, p->objiter.zTbl, 
159624         -          OTA_STATE_IDX, p->objiter.zIdx, 
159625         -          OTA_STATE_ROW, p->nStep, 
159626         -          OTA_STATE_PROGRESS, p->nProgress,
159627         -          OTA_STATE_CKPT, p->iWalCksum,
159628         -          OTA_STATE_COOKIE, (i64)p->pTargetFd->iCookie,
159629         -          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
159630 159636         )
159631 159637       );
159632 159638       assert( pInsert==0 || rc==SQLITE_OK );
159633 159639   
159634 159640       if( rc==SQLITE_OK ){
159635 159641         sqlite3_step(pInsert);
159636 159642         rc = sqlite3_finalize(pInsert);
................................................................................
159637 159643       }
159638 159644       if( rc!=SQLITE_OK ) p->rc = rc;
159639 159645     }
159640 159646   }
159641 159647   
159642 159648   
159643 159649   /*
159644         -** Step the OTA object.
       159650  +** Step the RBU object.
159645 159651   */
159646         -SQLITE_API int SQLITE_STDCALL sqlite3ota_step(sqlite3ota *p){
       159652  +SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *p){
159647 159653     if( p ){
159648 159654       switch( p->eStage ){
159649         -      case OTA_STAGE_OAL: {
159650         -        OtaObjIter *pIter = &p->objiter;
       159655  +      case RBU_STAGE_OAL: {
       159656  +        RbuObjIter *pIter = &p->objiter;
159651 159657           while( p->rc==SQLITE_OK && pIter->zTbl ){
159652 159658   
159653 159659             if( pIter->bCleanup ){
159654         -            /* 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 
159655 159661               ** cannot be dropped as there are currently active SQL statements.
159656 159662               ** But the contents can be deleted.  */
159657 159663               if( pIter->abIndexed ){
159658         -              otaMPrintfExec(p, p->dbOta, 
159659         -                  "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
159660 159666                 );
159661 159667               }
159662 159668             }else{
159663         -            otaObjIterPrepareAll(p, pIter, 0);
       159669  +            rbuObjIterPrepareAll(p, pIter, 0);
159664 159670   
159665 159671               /* Advance to the next row to process. */
159666 159672               if( p->rc==SQLITE_OK ){
159667 159673                 int rc = sqlite3_step(pIter->pSelect);
159668 159674                 if( rc==SQLITE_ROW ){
159669 159675                   p->nProgress++;
159670 159676                   p->nStep++;
159671         -                return otaStep(p);
       159677  +                return rbuStep(p);
159672 159678                 }
159673 159679                 p->rc = sqlite3_reset(pIter->pSelect);
159674 159680                 p->nStep = 0;
159675 159681               }
159676 159682             }
159677 159683   
159678         -          otaObjIterNext(p, pIter);
       159684  +          rbuObjIterNext(p, pIter);
159679 159685           }
159680 159686   
159681 159687           if( p->rc==SQLITE_OK ){
159682 159688             assert( pIter->zTbl==0 );
159683         -          otaSaveState(p, OTA_STAGE_MOVE);
159684         -          otaIncrSchemaCookie(p);
       159689  +          rbuSaveState(p, RBU_STAGE_MOVE);
       159690  +          rbuIncrSchemaCookie(p);
159685 159691             if( p->rc==SQLITE_OK ){
159686 159692               p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
159687 159693             }
159688 159694             if( p->rc==SQLITE_OK ){
159689         -            p->rc = sqlite3_exec(p->dbOta, "COMMIT", 0, 0, &p->zErrmsg);
       159695  +            p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
159690 159696             }
159691         -          p->eStage = OTA_STAGE_MOVE;
       159697  +          p->eStage = RBU_STAGE_MOVE;
159692 159698           }
159693 159699           break;
159694 159700         }
159695 159701   
159696         -      case OTA_STAGE_MOVE: {
       159702  +      case RBU_STAGE_MOVE: {
159697 159703           if( p->rc==SQLITE_OK ){
159698         -          otaMoveOalFile(p);
       159704  +          rbuMoveOalFile(p);
159699 159705             p->nProgress++;
159700 159706           }
159701 159707           break;
159702 159708         }
159703 159709   
159704         -      case OTA_STAGE_CKPT: {
       159710  +      case RBU_STAGE_CKPT: {
159705 159711           if( p->rc==SQLITE_OK ){
159706 159712             if( p->nStep>=p->nFrame ){
159707 159713               sqlite3_file *pDb = p->pTargetFd->pReal;
159708 159714     
159709 159715               /* Sync the db file */
159710 159716               p->rc = pDb->pMethods->xSync(pDb, SQLITE_SYNC_NORMAL);
159711 159717     
................................................................................
159715 159721                 p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, &ptr);
159716 159722                 if( p->rc==SQLITE_OK ){
159717 159723                   ((u32 volatile*)ptr)[24] = p->iMaxFrame;
159718 159724                 }
159719 159725               }
159720 159726     
159721 159727               if( p->rc==SQLITE_OK ){
159722         -              p->eStage = OTA_STAGE_DONE;
       159728  +              p->eStage = RBU_STAGE_DONE;
159723 159729                 p->rc = SQLITE_DONE;
159724 159730               }
159725 159731             }else{
159726         -            OtaFrame *pFrame = &p->aFrame[p->nStep];
159727         -            otaCheckpointFrame(p, pFrame);
       159732  +            RbuFrame *pFrame = &p->aFrame[p->nStep];
       159733  +            rbuCheckpointFrame(p, pFrame);
159728 159734               p->nStep++;
159729 159735             }
159730 159736             p->nProgress++;
159731 159737           }
159732 159738           break;
159733 159739         }
159734 159740   
................................................................................
159738 159744       return p->rc;
159739 159745     }else{
159740 159746       return SQLITE_NOMEM;
159741 159747     }
159742 159748   }
159743 159749   
159744 159750   /*
159745         -** Free an OtaState object allocated by otaLoadState().
       159751  +** Free an RbuState object allocated by rbuLoadState().
159746 159752   */
159747         -static void otaFreeState(OtaState *p){
       159753  +static void rbuFreeState(RbuState *p){
159748 159754     if( p ){
159749 159755       sqlite3_free(p->zTbl);
159750 159756       sqlite3_free(p->zIdx);
159751 159757       sqlite3_free(p);
159752 159758     }
159753 159759   }
159754 159760   
159755 159761   /*
159756         -** 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 
159757 159763   ** table into it. Return a pointer to the new object. It is the 
159758 159764   ** responsibility of the caller to eventually free the object using
159759 159765   ** sqlite3_free().
159760 159766   **
159761         -** 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
159762 159768   ** and return NULL.
159763 159769   */
159764         -static OtaState *otaLoadState(sqlite3ota *p){
159765         -  OtaState *pRet = 0;
       159770  +static RbuState *rbuLoadState(sqlite3rbu *p){
       159771  +  RbuState *pRet = 0;
159766 159772     sqlite3_stmt *pStmt = 0;
159767 159773     int rc;
159768 159774     int rc2;
159769 159775   
159770         -  pRet = (OtaState*)otaMalloc(p, sizeof(OtaState));
       159776  +  pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState));
159771 159777     if( pRet==0 ) return 0;
159772 159778   
159773         -  rc = prepareFreeAndCollectError(p->dbOta, &pStmt, &p->zErrmsg, 
159774         -      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)
159775 159781     );
159776 159782     while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
159777 159783       switch( sqlite3_column_int(pStmt, 0) ){
159778         -      case OTA_STATE_STAGE:
       159784  +      case RBU_STATE_STAGE:
159779 159785           pRet->eStage = sqlite3_column_int(pStmt, 1);
159780         -        if( pRet->eStage!=OTA_STAGE_OAL
159781         -         && pRet->eStage!=OTA_STAGE_MOVE
159782         -         && pRet->eStage!=OTA_STAGE_CKPT
       159786  +        if( pRet->eStage!=RBU_STAGE_OAL
       159787  +         && pRet->eStage!=RBU_STAGE_MOVE
       159788  +         && pRet->eStage!=RBU_STAGE_CKPT
159783 159789           ){
159784 159790             p->rc = SQLITE_CORRUPT;
159785 159791           }
159786 159792           break;
159787 159793   
159788         -      case OTA_STATE_TBL:
159789         -        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);
159790 159796           break;
159791 159797   
159792         -      case OTA_STATE_IDX:
159793         -        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);
159794 159800           break;
159795 159801   
159796         -      case OTA_STATE_ROW:
       159802  +      case RBU_STATE_ROW:
159797 159803           pRet->nRow = sqlite3_column_int(pStmt, 1);
159798 159804           break;
159799 159805   
159800         -      case OTA_STATE_PROGRESS:
       159806  +      case RBU_STATE_PROGRESS:
159801 159807           pRet->nProgress = sqlite3_column_int64(pStmt, 1);
159802 159808           break;
159803 159809   
159804         -      case OTA_STATE_CKPT:
       159810  +      case RBU_STATE_CKPT:
159805 159811           pRet->iWalCksum = sqlite3_column_int64(pStmt, 1);
159806 159812           break;
159807 159813   
159808         -      case OTA_STATE_COOKIE:
       159814  +      case RBU_STATE_COOKIE:
159809 159815           pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
159810 159816           break;
159811 159817   
159812         -      case OTA_STATE_OALSZ:
       159818  +      case RBU_STATE_OALSZ:
159813 159819           pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
159814 159820           break;
159815 159821   
159816 159822         default:
159817 159823           rc = SQLITE_CORRUPT;
159818 159824           break;
159819 159825       }
................................................................................
159826 159832   }
159827 159833   
159828 159834   /*
159829 159835   ** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
159830 159836   ** otherwise. Either or both argument may be NULL. Two NULL values are
159831 159837   ** considered equal, and NULL is considered distinct from all other values.
159832 159838   */
159833         -static int otaStrCompare(const char *z1, const char *z2){
       159839  +static int rbuStrCompare(const char *z1, const char *z2){
159834 159840     if( z1==0 && z2==0 ) return 0;
159835 159841     if( z1==0 || z2==0 ) return 1;
159836 159842     return (sqlite3_stricmp(z1, z2)!=0);
159837 159843   }
159838 159844   
159839 159845   /*
159840         -** This function is called as part of sqlite3ota_open() when initializing
159841         -** an ota handle in OAL stage. If the ota update has not started (i.e.
159842         -** the ota_state table was empty) it is a no-op. Otherwise, it arranges
159843         -** things so that the next call to sqlite3ota_step() continues on from
159844         -** 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.
159845 159851   **
159846 159852   ** If an error occurs, an error code and error message are left in the
159847         -** ota handle passed as the first argument.
       159853  +** rbu handle passed as the first argument.
159848 159854   */
159849         -static void otaSetupOal(sqlite3ota *p, OtaState *pState){
       159855  +static void rbuSetupOal(sqlite3rbu *p, RbuState *pState){
159850 159856     assert( p->rc==SQLITE_OK );
159851 159857     if( pState->zTbl ){
159852         -    OtaObjIter *pIter = &p->objiter;
       159858  +    RbuObjIter *pIter = &p->objiter;
159853 159859       int rc = SQLITE_OK;
159854 159860   
159855 159861       while( rc==SQLITE_OK && pIter->zTbl && (pIter->bCleanup 
159856         -       || otaStrCompare(pIter->zIdx, pState->zIdx)
159857         -       || otaStrCompare(pIter->zTbl, pState->zTbl) 
       159862  +       || rbuStrCompare(pIter->zIdx, pState->zIdx)
       159863  +       || rbuStrCompare(pIter->zTbl, pState->zTbl) 
159858 159864       )){
159859         -      rc = otaObjIterNext(p, pIter);
       159865  +      rc = rbuObjIterNext(p, pIter);
159860 159866       }
159861 159867   
159862 159868       if( rc==SQLITE_OK && !pIter->zTbl ){
159863 159869         rc = SQLITE_ERROR;
159864         -      p->zErrmsg = sqlite3_mprintf("ota_state mismatch error");
       159870  +      p->zErrmsg = sqlite3_mprintf("rbu_state mismatch error");
159865 159871       }
159866 159872   
159867 159873       if( rc==SQLITE_OK ){
159868 159874         p->nStep = pState->nRow;
159869         -      rc = otaObjIterPrepareAll(p, &p->objiter, p->nStep);
       159875  +      rc = rbuObjIterPrepareAll(p, &p->objiter, p->nStep);
159870 159876       }
159871 159877   
159872 159878       p->rc = rc;
159873 159879     }
159874 159880   }
159875 159881   
159876 159882   /*
159877 159883   ** If there is a "*-oal" file in the file-system corresponding to the
159878 159884   ** target database in the file-system, delete it. If an error occurs,
159879         -** leave an error code and error message in the ota handle.
       159885  +** leave an error code and error message in the rbu handle.
159880 159886   */
159881         -static void otaDeleteOalFile(sqlite3ota *p){
       159887  +static void rbuDeleteOalFile(sqlite3rbu *p){
159882 159888     char *zOal = sqlite3_mprintf("%s-oal", p->zTarget);
159883 159889     assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
159884 159890     unlink(zOal);
159885 159891     sqlite3_free(zOal);
159886 159892   }
159887 159893   
159888 159894   /*
159889         -** Allocate a private ota VFS for the ota handle passed as the only
159890         -** 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()
159891 159897   ** specified a URI with a vfs=? option in place of a target database
159892 159898   ** file name.
159893 159899   */
159894         -static void otaCreateVfs(sqlite3ota *p){
       159900  +static void rbuCreateVfs(sqlite3rbu *p){
159895 159901     int rnd;
159896 159902     char zRnd[64];
159897 159903   
159898 159904     assert( p->rc==SQLITE_OK );
159899 159905     sqlite3_randomness(sizeof(int), (void*)&rnd);
159900         -  sprintf(zRnd, "ota_vfs_%d", rnd);
159901         -  p->rc = sqlite3ota_create_vfs(zRnd, 0);
       159906  +  sprintf(zRnd, "rbu_vfs_%d", rnd);
       159907  +  p->rc = sqlite3rbu_create_vfs(zRnd, 0);
159902 159908     if( p->rc==SQLITE_OK ){
159903 159909       sqlite3_vfs *pVfs = sqlite3_vfs_find(zRnd);
159904 159910       assert( pVfs );
159905 159911       p->zVfsName = pVfs->zName;
159906 159912     }
159907 159913   }
159908 159914   
159909 159915   /*
159910         -** Destroy the private VFS created for the ota handle passed as the only
159911         -** 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().
159912 159918   */
159913         -static void otaDeleteVfs(sqlite3ota *p){
       159919  +static void rbuDeleteVfs(sqlite3rbu *p){
159914 159920     if( p->zVfsName ){
159915         -    sqlite3ota_destroy_vfs(p->zVfsName);
       159921  +    sqlite3rbu_destroy_vfs(p->zVfsName);
159916 159922       p->zVfsName = 0;
159917 159923     }
159918 159924   }
159919 159925   
159920 159926   /*
159921         -** Open and return a new OTA handle. 
       159927  +** Open and return a new RBU handle. 
159922 159928   */
159923         -SQLITE_API sqlite3ota *SQLITE_STDCALL sqlite3ota_open(
       159929  +SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
159924 159930     const char *zTarget, 
159925         -  const char *zOta,
       159931  +  const char *zRbu,
159926 159932     const char *zState
159927 159933   ){
159928         -  sqlite3ota *p;
       159934  +  sqlite3rbu *p;
159929 159935     int nTarget = strlen(zTarget);
159930         -  int nOta = strlen(zOta);
       159936  +  int nRbu = strlen(zRbu);
159931 159937     int nState = zState ? strlen(zState) : 0;
159932 159938   
159933         -  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);
159934 159940     if( p ){
159935         -    OtaState *pState = 0;
       159941  +    RbuState *pState = 0;
159936 159942   
159937 159943       /* Create the custom VFS. */
159938         -    memset(p, 0, sizeof(sqlite3ota));
159939         -    otaCreateVfs(p);
       159944  +    memset(p, 0, sizeof(sqlite3rbu));
       159945  +    rbuCreateVfs(p);
159940 159946   
159941 159947       /* Open the target database */
159942 159948       if( p->rc==SQLITE_OK ){
159943 159949         p->zTarget = (char*)&p[1];
159944 159950         memcpy(p->zTarget, zTarget, nTarget+1);
159945         -      p->zOta = &p->zTarget[nTarget+1];
159946         -      memcpy(p->zOta, zOta, nOta+1);
       159951  +      p->zRbu = &p->zTarget[nTarget+1];
       159952  +      memcpy(p->zRbu, zRbu, nRbu+1);
159947 159953         if( zState ){
159948         -        p->zState = &p->zOta[nOta+1];
       159954  +        p->zState = &p->zRbu[nRbu+1];
159949 159955           memcpy(p->zState, zState, nState+1);
159950 159956         }
159951         -      otaOpenDatabase(p);
       159957  +      rbuOpenDatabase(p);
159952 159958       }
159953 159959   
159954         -    /* If it has not already been created, create the ota_state table */
159955         -    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);
159956 159962   
159957 159963       if( p->rc==SQLITE_OK ){
159958         -      pState = otaLoadState(p);
       159964  +      pState = rbuLoadState(p);
159959 159965         assert( pState || p->rc!=SQLITE_OK );
159960 159966         if( p->rc==SQLITE_OK ){
159961 159967   
159962 159968           if( pState->eStage==0 ){ 
159963         -          otaDeleteOalFile(p);
159964         -          p->eStage = OTA_STAGE_OAL;
       159969  +          rbuDeleteOalFile(p);
       159970  +          p->eStage = RBU_STAGE_OAL;
159965 159971           }else{
159966 159972             p->eStage = pState->eStage;
159967 159973           }
159968 159974           p->nProgress = pState->nProgress;
159969 159975           p->iOalSz = pState->iOalSz;
159970 159976         }
159971 159977       }
159972 159978       assert( p->rc!=SQLITE_OK || p->eStage!=0 );
159973 159979   
159974 159980       if( p->rc==SQLITE_OK && p->pTargetFd->pWalFd ){
159975         -      if( p->eStage==OTA_STAGE_OAL ){
       159981  +      if( p->eStage==RBU_STAGE_OAL ){
159976 159982           p->rc = SQLITE_ERROR;
159977 159983           p->zErrmsg = sqlite3_mprintf("cannot update wal mode database");
159978         -      }else if( p->eStage==OTA_STAGE_MOVE ){
159979         -        p->eStage = OTA_STAGE_CKPT;
       159984  +      }else if( p->eStage==RBU_STAGE_MOVE ){
       159985  +        p->eStage = RBU_STAGE_CKPT;
159980 159986           p->nStep = 0;
159981 159987         }
159982 159988       }
159983 159989   
159984 159990       if( p->rc==SQLITE_OK
159985         -     && (p->eStage==OTA_STAGE_OAL || p->eStage==OTA_STAGE_MOVE)
       159991  +     && (p->eStage==RBU_STAGE_OAL || p->eStage==RBU_STAGE_MOVE)
159986 159992        && pState->eStage!=0 && p->pTargetFd->iCookie!=pState->iCookie
159987 159993       ){   
159988 159994         /* At this point (pTargetFd->iCookie) contains the value of the
159989 159995         ** change-counter cookie (the thing that gets incremented when a 
159990 159996         ** transaction is committed in rollback mode) currently stored on 
159991 159997         ** page 1 of the database file. */
159992 159998         p->rc = SQLITE_BUSY;
159993         -      p->zErrmsg = sqlite3_mprintf("database modified during ota update");
       159999  +      p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
159994 160000       }
159995 160001   
159996 160002       if( p->rc==SQLITE_OK ){
159997         -      if( p->eStage==OTA_STAGE_OAL ){
       160003  +      if( p->eStage==RBU_STAGE_OAL ){
159998 160004   
159999 160005           /* Open transactions both databases. The *-oal file is opened or
160000 160006           ** created at this point. */
160001 160007           p->rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
160002 160008           if( p->rc==SQLITE_OK ){
160003         -          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);
160004 160010           }
160005 160011     
160006 160012           /* Point the object iterator at the first object */
160007 160013           if( p->rc==SQLITE_OK ){
160008         -          p->rc = otaObjIterFirst(p, &p->objiter);
       160014  +          p->rc = rbuObjIterFirst(p, &p->objiter);
160009 160015           }
160010 160016   
160011         -        /* 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
160012 160018           ** update finished.  */
160013 160019           if( p->rc==SQLITE_OK && p->objiter.zTbl==0 ){
160014 160020             p->rc = SQLITE_DONE;
160015 160021           }
160016 160022   
160017 160023           if( p->rc==SQLITE_OK ){
160018         -          otaSetupOal(p, pState);
       160024  +          rbuSetupOal(p, pState);
160019 160025           }
160020 160026   
160021         -      }else if( p->eStage==OTA_STAGE_MOVE ){
       160027  +      }else if( p->eStage==RBU_STAGE_MOVE ){
160022 160028           /* no-op */
160023         -      }else if( p->eStage==OTA_STAGE_CKPT ){
160024         -        otaSetupCheckpoint(p, pState);
160025         -      }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 ){
160026 160032           p->rc = SQLITE_DONE;
160027 160033         }else{
160028 160034           p->rc = SQLITE_CORRUPT;
160029 160035         }
160030 160036       }
160031 160037   
160032         -    otaFreeState(pState);
       160038  +    rbuFreeState(pState);
160033 160039     }
160034 160040   
160035 160041     return p;
160036 160042   }
160037 160043   
160038 160044   
160039 160045   /*
160040         -** Return the database handle used by pOta.
       160046  +** Return the database handle used by pRbu.
160041 160047   */
160042         -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3ota_db(sqlite3ota *pOta, int bOta){
       160048  +SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){
160043 160049     sqlite3 *db = 0;
160044         -  if( pOta ){
160045         -    db = (bOta ? pOta->dbOta : pOta->dbMain);
       160050  +  if( pRbu ){
       160051  +    db = (bRbu ? pRbu->dbRbu : pRbu->dbMain);
160046 160052     }
160047 160053     return db;
160048 160054   }
160049 160055   
160050 160056   
160051 160057   /*
160052         -** 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,
160053 160059   ** then edit any error message string so as to remove all occurrences of
160054         -** the pattern "ota_imp_[0-9]*".
       160060  +** the pattern "rbu_imp_[0-9]*".
160055 160061   */
160056         -static void otaEditErrmsg(sqlite3ota *p){
       160062  +static void rbuEditErrmsg(sqlite3rbu *p){
160057 160063     if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){
160058 160064       int i;
160059 160065       int nErrmsg = strlen(p->zErrmsg);
160060 160066       for(i=0; i<(nErrmsg-8); i++){
160061         -      if( memcmp(&p->zErrmsg[i], "ota_imp_", 8)==0 ){
       160067  +      if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
160062 160068           int nDel = 8;
160063 160069           while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
160064 160070           memmove(&p->zErrmsg[i], &p->zErrmsg[i+nDel], nErrmsg + 1 - i - nDel);
160065 160071           nErrmsg -= nDel;
160066 160072         }
160067 160073       }
160068 160074     }
160069 160075   }
160070 160076   
160071 160077   /*
160072         -** Close the OTA handle.
       160078  +** Close the RBU handle.
160073 160079   */
160074         -SQLITE_API int SQLITE_STDCALL sqlite3ota_close(sqlite3ota *p, char **pzErrmsg){
       160080  +SQLITE_API int SQLITE_STDCALL sqlite3rbu_close(sqlite3rbu *p, char **pzErrmsg){
160075 160081     int rc;
160076 160082     if( p ){
160077 160083   
160078 160084       /* Commit the transaction to the *-oal file. */
160079         -    if( p->rc==SQLITE_OK && p->eStage==OTA_STAGE_OAL ){
       160085  +    if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){
160080 160086         p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
160081 160087       }
160082 160088   
160083         -    otaSaveState(p, p->eStage);
       160089  +    rbuSaveState(p, p->eStage);
160084 160090   
160085         -    if( p->rc==SQLITE_OK && p->eStage==OTA_STAGE_OAL ){
160086         -      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);
160087 160093       }
160088 160094   
160089 160095       /* Close any open statement handles. */
160090         -    otaObjIterFinalize(&p->objiter);
       160096  +    rbuObjIterFinalize(&p->objiter);
160091 160097   
160092 160098       /* Close the open database handle and VFS object. */
160093 160099       sqlite3_close(p->dbMain);
160094         -    sqlite3_close(p->dbOta);
160095         -    otaDeleteVfs(p);
       160100  +    sqlite3_close(p->dbRbu);
       160101  +    rbuDeleteVfs(p);
160096 160102       sqlite3_free(p->aBuf);
160097 160103       sqlite3_free(p->aFrame);
160098 160104   
160099         -    otaEditErrmsg(p);
       160105  +    rbuEditErrmsg(p);
160100 160106       rc = p->rc;
160101 160107       *pzErrmsg = p->zErrmsg;
160102 160108       sqlite3_free(p);
160103 160109     }else{
160104 160110       rc = SQLITE_NOMEM;
160105 160111       *pzErrmsg = 0;
160106 160112     }
160107 160113     return rc;
160108 160114   }
160109 160115   
160110 160116   /*
160111 160117   ** Return the total number of key-value operations (inserts, deletes or 
160112 160118   ** updates) that have been performed on the target database since the
160113         -** current OTA update was started.
       160119  +** current RBU update was started.
160114 160120   */
160115         -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3ota_progress(sqlite3ota *pOta){
160116         -  return pOta->nProgress;
       160121  +SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3rbu_progress(sqlite3rbu *pRbu){
       160122  +  return pRbu->nProgress;
160117 160123   }
160118 160124   
160119 160125   /**************************************************************************
160120         -** 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
160121 160127   ** of a standard VFS in the following ways:
160122 160128   **
160123 160129   ** 1. Whenever the first page of a main database file is read or 
160124 160130   **    written, the value of the change-counter cookie is stored in
160125         -**    ota_file.iCookie. Similarly, the value of the "write-version"
160126         -**    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
160127 160133   **    that the values are always trustworthy within an open transaction.
160128 160134   **
160129         -** 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)
160130 160136   **    member variable of the associated database file descriptor is set
160131 160137   **    to point to the new file. A mutex protected linked list of all main 
160132         -**    db fds opened using a particular OTA VFS is maintained at 
160133         -**    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.
160134 160140   **
160135         -** 3. Using a new file-control "SQLITE_FCNTL_OTA", a main db ota_file 
160136         -**    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
160137 160143   **    turns on the following extra special behaviour:
160138 160144   **
160139 160145   ** 3a. If xAccess() is called to check if there exists a *-wal file 
160140         -**     associated with an OTA target database currently in OTA_STAGE_OAL
       160146  +**     associated with an RBU target database currently in RBU_STAGE_OAL
160141 160147   **     stage (preparing the *-oal file), the following special handling
160142 160148   **     applies:
160143 160149   **
160144         -**      * if the *-wal file does exist, return SQLITE_CANTOPEN. An OTA
       160150  +**      * if the *-wal file does exist, return SQLITE_CANTOPEN. An RBU
160145 160151   **        target database may not be in wal mode already.
160146 160152   **
160147 160153   **      * if the *-wal file does not exist, set the output parameter to
160148 160154   **        non-zero (to tell SQLite that it does exist) anyway.
160149 160155   **
160150 160156   **     Then, when xOpen() is called to open the *-wal file associated with
160151         -**     the OTA target in OTA_STAGE_OAL stage, instead of opening the *-wal
160152         -**     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. 
160153 160159   **
160154 160160   ** 3b. The *-shm pages returned by xShmMap() for a target db file in
160155         -**     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
160156 160162   **     avoid creating a *-shm file on disk. Additionally, xShmLock() calls
160157         -**     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
160158 160164   **     because assert() statements in some VFS implementations fail if 
160159 160165   **     xShmLock() is called before xShmMap().
160160 160166   **
160161 160167   ** 3c. If an EXCLUSIVE lock is attempted on a target database file in any
160162         -**     mode except OTA_STAGE_DONE (all work completed and checkpointed), it 
160163         -**     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
160164 160170   **     from automatically checkpointing a *-wal (or *-oal) file from within
160165 160171   **     sqlite3_close().
160166 160172   **
160167         -** 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
160168 160174   **     all xWrite() calls on the target database file perform no IO. 
160169 160175   **     Instead the frame and page numbers that would be read and written
160170 160176   **     are recorded. Additionally, successful attempts to obtain exclusive
160171 160177   **     xShmLock() WRITER, CHECKPOINTER and READ0 locks on the target 
160172 160178   **     database file are recorded. xShmLock() calls to unlock the same
160173 160179   **     locks are no-ops (so that once obtained, these locks are never
160174 160180   **     relinquished). Finally, calls to xSync() on the target database
160175 160181   **     file fail with SQLITE_INTERNAL errors.
160176 160182   */
160177 160183   
160178         -static void otaUnlockShm(ota_file *p){
160179         -  if( p->pOta ){
       160184  +static void rbuUnlockShm(rbu_file *p){
       160185  +  if( p->pRbu ){
160180 160186       int (*xShmLock)(sqlite3_file*,int,int,int) = p->pReal->pMethods->xShmLock;
160181 160187       int i;
160182 160188       for(i=0; i<SQLITE_SHM_NLOCK;i++){
160183         -      if( (1<<i) & p->pOta->mLock ){
       160189  +      if( (1<<i) & p->pRbu->mLock ){
160184 160190           xShmLock(p->pReal, i, 1, SQLITE_SHM_UNLOCK|SQLITE_SHM_EXCLUSIVE);
160185 160191         }
160186 160192       }
160187         -    p->pOta->mLock = 0;
       160193  +    p->pRbu->mLock = 0;
160188 160194     }
160189 160195   }
160190 160196   
160191 160197   /*
160192         -** Close an ota file.
       160198  +** Close an rbu file.
160193 160199   */
160194         -static int otaVfsClose(sqlite3_file *pFile){
160195         -  ota_file *p = (ota_file*)pFile;
       160200  +static int rbuVfsClose(sqlite3_file *pFile){
       160201  +  rbu_file *p = (rbu_file*)pFile;
160196 160202     int rc;
160197 160203     int i;
160198 160204   
160199 160205     /* Free the contents of the apShm[] array. And the array itself. */
160200 160206     for(i=0; i<p->nShm; i++){
160201 160207       sqlite3_free(p->apShm[i]);
160202 160208     }
160203 160209     sqlite3_free(p->apShm);
160204 160210     p->apShm = 0;
160205 160211     sqlite3_free(p->zDel);
160206 160212   
160207 160213     if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
160208         -    ota_file **pp;
160209         -    sqlite3_mutex_enter(p->pOtaVfs->mutex);
160210         -    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));
160211 160217       *pp = p->pMainNext;
160212         -    sqlite3_mutex_leave(p->pOtaVfs->mutex);
160213         -    otaUnlockShm(p);
       160218  +    sqlite3_mutex_leave(p->pRbuVfs->mutex);
       160219  +    rbuUnlockShm(p);
160214 160220       p->pReal->pMethods->xShmUnmap(p->pReal, 0);
160215 160221     }
160216 160222   
160217 160223     /* Close the underlying file handle */
160218 160224     rc = p->pReal->pMethods->xClose(p->pReal);
160219 160225     return rc;
160220 160226   }
160221 160227   
160222 160228   
160223 160229   /*
160224 160230   ** Read and return an unsigned 32-bit big-endian integer from the buffer 
160225 160231   ** passed as the only argument.
160226 160232   */
160227         -static u32 otaGetU32(u8 *aBuf){
       160233  +static u32 rbuGetU32(u8 *aBuf){
160228 160234     return ((u32)aBuf[0] << 24)
160229 160235          + ((u32)aBuf[1] << 16)
160230 160236          + ((u32)aBuf[2] <<  8)
160231 160237          + ((u32)aBuf[3]);
160232 160238   }
160233 160239   
160234 160240   /*
160235         -** Read data from an otaVfs-file.
       160241  +** Read data from an rbuVfs-file.
160236 160242   */
160237         -static int otaVfsRead(
       160243  +static int rbuVfsRead(
160238 160244     sqlite3_file *pFile, 
160239 160245     void *zBuf, 
160240 160246     int iAmt, 
160241 160247     sqlite_int64 iOfst
160242 160248   ){
160243         -  ota_file *p = (ota_file*)pFile;
160244         -  sqlite3ota *pOta = p->pOta;
       160249  +  rbu_file *p = (rbu_file*)pFile;
       160250  +  sqlite3rbu *pRbu = p->pRbu;
160245 160251     int rc;
160246 160252   
160247         -  if( pOta && pOta->eStage==OTA_STAGE_CAPTURE ){
       160253  +  if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){
160248 160254       assert( p->openFlags & SQLITE_OPEN_WAL );
160249         -    rc = otaCaptureWalRead(p->pOta, iOfst, iAmt);
       160255  +    rc = rbuCaptureWalRead(p->pRbu, iOfst, iAmt);
160250 160256     }else{
160251         -    if( pOta && pOta->eStage==OTA_STAGE_OAL 
       160257  +    if( pRbu && pRbu->eStage==RBU_STAGE_OAL 
160252 160258        && (p->openFlags & SQLITE_OPEN_WAL) 
160253         -     && iOfst>=pOta->iOalSz 
       160259  +     && iOfst>=pRbu->iOalSz 
160254 160260       ){
160255 160261         rc = SQLITE_OK;
160256 160262         memset(zBuf, 0, iAmt);
160257 160263       }else{
160258 160264         rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
160259 160265       }
160260 160266       if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
160261 160267         /* These look like magic numbers. But they are stable, as they are part
160262 160268          ** of the definition of the SQLite file format, which may not change. */
160263 160269         u8 *pBuf = (u8*)zBuf;
160264         -      p->iCookie = otaGetU32(&pBuf[24]);
       160270  +      p->iCookie = rbuGetU32(&pBuf[24]);
160265 160271         p->iWriteVer = pBuf[19];
160266 160272       }
160267 160273     }
160268 160274     return rc;
160269 160275   }
160270 160276   
160271 160277   /*
160272         -** Write data to an otaVfs-file.
       160278  +** Write data to an rbuVfs-file.
160273 160279   */
160274         -static int otaVfsWrite(
       160280  +static int rbuVfsWrite(
160275 160281     sqlite3_file *pFile, 
160276 160282     const void *zBuf, 
160277 160283     int iAmt, 
160278 160284     sqlite_int64 iOfst
160279 160285   ){
160280         -  ota_file *p = (ota_file*)pFile;
160281         -  sqlite3ota *pOta = p->pOta;
       160286  +  rbu_file *p = (rbu_file*)pFile;
       160287  +  sqlite3rbu *pRbu = p->pRbu;
160282 160288     int rc;
160283 160289   
160284         -  if( pOta && pOta->eStage==OTA_STAGE_CAPTURE ){
       160290  +  if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){
160285 160291       assert( p->openFlags & SQLITE_OPEN_MAIN_DB );
160286         -    rc = otaCaptureDbWrite(p->pOta, iOfst);
       160292  +    rc = rbuCaptureDbWrite(p->pRbu, iOfst);
160287 160293     }else{
160288         -    if( pOta && pOta->eStage==OTA_STAGE_OAL 
       160294  +    if( pRbu && pRbu->eStage==RBU_STAGE_OAL 
160289 160295        && (p->openFlags & SQLITE_OPEN_WAL) 
160290         -     && iOfst>=pOta->iOalSz
       160296  +     && iOfst>=pRbu->iOalSz
160291 160297       ){
160292         -      pOta->iOalSz = iAmt + iOfst;
       160298  +      pRbu->iOalSz = iAmt + iOfst;
160293 160299       }
160294 160300       rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst);
160295 160301       if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
160296 160302         /* These look like magic numbers. But they are stable, as they are part
160297 160303         ** of the definition of the SQLite file format, which may not change. */
160298 160304         u8 *pBuf = (u8*)zBuf;
160299         -      p->iCookie = otaGetU32(&pBuf[24]);
       160305  +      p->iCookie = rbuGetU32(&pBuf[24]);
160300 160306         p->iWriteVer = pBuf[19];
160301 160307       }
160302 160308     }
160303 160309     return rc;
160304 160310   }
160305 160311   
160306 160312   /*
160307         -** Truncate an otaVfs-file.
       160313  +** Truncate an rbuVfs-file.
160308 160314   */
160309         -static int otaVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
160310         -  ota_file *p = (ota_file*)pFile;
       160315  +static int rbuVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
       160316  +  rbu_file *p = (rbu_file*)pFile;
160311 160317     return p->pReal->pMethods->xTruncate(p->pReal, size);
160312 160318   }
160313 160319   
160314 160320   /*
160315         -** Sync an otaVfs-file.
       160321  +** Sync an rbuVfs-file.
160316 160322   */
160317         -static int otaVfsSync(sqlite3_file *pFile, int flags){
160318         -  ota_file *p = (ota_file *)pFile;
160319         -  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 ){
160320 160326       if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
160321 160327         return SQLITE_INTERNAL;
160322 160328       }
160323 160329       return SQLITE_OK;
160324 160330     }
160325 160331     return p->pReal->pMethods->xSync(p->pReal, flags);
160326 160332   }
160327 160333   
160328 160334   /*
160329         -** Return the current file-size of an otaVfs-file.
       160335  +** Return the current file-size of an rbuVfs-file.
160330 160336   */
160331         -static int otaVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
160332         -  ota_file *p = (ota_file *)pFile;
       160337  +static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
       160338  +  rbu_file *p = (rbu_file *)pFile;
160333 160339     return p->pReal->pMethods->xFileSize(p->pReal, pSize);
160334 160340   }
160335 160341   
160336 160342   /*
160337         -** Lock an otaVfs-file.
       160343  +** Lock an rbuVfs-file.
160338 160344   */
160339         -static int otaVfsLock(sqlite3_file *pFile, int eLock){
160340         -  ota_file *p = (ota_file*)pFile;
160341         -  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;
160342 160348     int rc = SQLITE_OK;
160343 160349   
160344 160350     assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160345         -  if( pOta && eLock==SQLITE_LOCK_EXCLUSIVE && pOta->eStage!=OTA_STAGE_DONE ){
       160351  +  if( pRbu && eLock==SQLITE_LOCK_EXCLUSIVE && pRbu->eStage!=RBU_STAGE_DONE ){
160346 160352       /* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this 
160347 160353       ** prevents it from checkpointing the database from sqlite3_close(). */
160348 160354       rc = SQLITE_BUSY;
160349 160355     }else{
160350 160356       rc = p->pReal->pMethods->xLock(p->pReal, eLock);
160351 160357     }
160352 160358   
160353 160359     return rc;
160354 160360   }
160355 160361   
160356 160362   /*
160357         -** Unlock an otaVfs-file.
       160363  +** Unlock an rbuVfs-file.
160358 160364   */
160359         -static int otaVfsUnlock(sqlite3_file *pFile, int eLock){
160360         -  ota_file *p = (ota_file *)pFile;
       160365  +static int rbuVfsUnlock(sqlite3_file *pFile, int eLock){
       160366  +  rbu_file *p = (rbu_file *)pFile;
160361 160367     return p->pReal->pMethods->xUnlock(p->pReal, eLock);
160362 160368   }
160363 160369   
160364 160370   /*
160365         -** 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.
160366 160372   */
160367         -static int otaVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
160368         -  ota_file *p = (ota_file *)pFile;
       160373  +static int rbuVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
       160374  +  rbu_file *p = (rbu_file *)pFile;
160369 160375     return p->pReal->pMethods->xCheckReservedLock(p->pReal, pResOut);
160370 160376   }
160371 160377   
160372 160378   /*
160373         -** File control method. For custom operations on an otaVfs-file.
       160379  +** File control method. For custom operations on an rbuVfs-file.
160374 160380   */
160375         -static int otaVfsFileControl(sqlite3_file *pFile, int op, void *pArg){
160376         -  ota_file *p = (ota_file *)pFile;
       160381  +static int rbuVfsFileControl(sqlite3_file *pFile, int op, void *pArg){
       160382  +  rbu_file *p = (rbu_file *)pFile;
160377 160383     int (*xControl)(sqlite3_file*,int,void*) = p->pReal->pMethods->xFileControl;
160378 160384     int rc;
160379 160385   
160380 160386     assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB)
160381 160387          || p->openFlags & (SQLITE_OPEN_TRANSIENT_DB|SQLITE_OPEN_TEMP_JOURNAL)
160382 160388     );
160383         -  if( op==SQLITE_FCNTL_OTA ){
160384         -    sqlite3ota *pOta = (sqlite3ota*)pArg;
       160389  +  if( op==SQLITE_FCNTL_RBU ){
       160390  +    sqlite3rbu *pRbu = (sqlite3rbu*)pArg;
160385 160391   
160386         -    /* 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
160387 160393       ** one is found, this vfs will operate in pass-through mode. The lower
160388         -    ** level vfs will do the special OTA handling.  */
       160394  +    ** level vfs will do the special RBU handling.  */
160389 160395       rc = xControl(p->pReal, op, pArg);
160390 160396   
160391 160397       if( rc==SQLITE_NOTFOUND ){
160392 160398         /* Now search for a zipvfs instance lower down in the VFS stack. If
160393 160399         ** one is found, this is an error.  */
160394 160400         void *dummy = 0;
160395 160401         rc = xControl(p->pReal, SQLITE_FCNTL_ZIPVFS, &dummy);
160396 160402         if( rc==SQLITE_OK ){
160397 160403           rc = SQLITE_ERROR;
160398         -        pOta->zErrmsg = sqlite3_mprintf("ota/zipvfs setup error");
       160404  +        pRbu->zErrmsg = sqlite3_mprintf("rbu/zipvfs setup error");
160399 160405         }else if( rc==SQLITE_NOTFOUND ){
160400         -        pOta->pTargetFd = p;
160401         -        p->pOta = pOta;
160402         -        if( p->pWalFd ) p->pWalFd->pOta = pOta;
       160406  +        pRbu->pTargetFd = p;
       160407  +        p->pRbu = pRbu;
       160408  +        if( p->pWalFd ) p->pWalFd->pRbu = pRbu;
160403 160409           rc = SQLITE_OK;
160404 160410         }
160405 160411       }
160406 160412       return rc;
160407 160413     }
160408 160414   
160409 160415     rc = xControl(p->pReal, op, pArg);
160410 160416     if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
160411         -    ota_vfs *pOtaVfs = p->pOtaVfs;
       160417  +    rbu_vfs *pRbuVfs = p->pRbuVfs;
160412 160418       char *zIn = *(char**)pArg;
160413         -    char *zOut = sqlite3_mprintf("ota(%s)/%z", pOtaVfs->base.zName, zIn);
       160419  +    char *zOut = sqlite3_mprintf("rbu(%s)/%z", pRbuVfs->base.zName, zIn);
160414 160420       *(char**)pArg = zOut;
160415 160421       if( zOut==0 ) rc = SQLITE_NOMEM;
160416 160422     }
160417 160423   
160418 160424     return rc;
160419 160425   }
160420 160426   
160421 160427   /*
160422         -** Return the sector-size in bytes for an otaVfs-file.
       160428  +** Return the sector-size in bytes for an rbuVfs-file.
160423 160429   */
160424         -static int otaVfsSectorSize(sqlite3_file *pFile){
160425         -  ota_file *p = (ota_file *)pFile;
       160430  +static int rbuVfsSectorSize(sqlite3_file *pFile){
       160431  +  rbu_file *p = (rbu_file *)pFile;
160426 160432     return p->pReal->pMethods->xSectorSize(p->pReal);
160427 160433   }
160428 160434   
160429 160435   /*
160430         -** Return the device characteristic flags supported by an otaVfs-file.
       160436  +** Return the device characteristic flags supported by an rbuVfs-file.
160431 160437   */
160432         -static int otaVfsDeviceCharacteristics(sqlite3_file *pFile){
160433         -  ota_file *p = (ota_file *)pFile;
       160438  +static int rbuVfsDeviceCharacteristics(sqlite3_file *pFile){
       160439  +  rbu_file *p = (rbu_file *)pFile;
160434 160440     return p->pReal->pMethods->xDeviceCharacteristics(p->pReal);
160435 160441   }
160436 160442   
160437 160443   /*
160438 160444   ** Take or release a shared-memory lock.
160439 160445   */
160440         -static int otaVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
160441         -  ota_file *p = (ota_file*)pFile;
160442         -  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;
160443 160449     int rc = SQLITE_OK;
160444 160450   
160445 160451   #ifdef SQLITE_AMALGAMATION
160446 160452       assert( WAL_CKPT_LOCK==1 );
160447 160453   #endif
160448 160454   
160449 160455     assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160450         -  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) ){
160451 160457       /* Magic number 1 is the WAL_CKPT_LOCK lock. Preventing SQLite from
160452 160458       ** taking this lock also prevents any checkpoints from occurring. 
160453 160459       ** todo: really, it's not clear why this might occur, as 
160454 160460       ** wal_autocheckpoint ought to be turned off.  */
160455 160461       if( ofst==WAL_LOCK_CKPT && n==1 ) rc = SQLITE_BUSY;
160456 160462     }else{
160457 160463       int bCapture = 0;
160458 160464       if( n==1 && (flags & SQLITE_SHM_EXCLUSIVE)
160459         -     && pOta && pOta->eStage==OTA_STAGE_CAPTURE
       160465  +     && pRbu && pRbu->eStage==RBU_STAGE_CAPTURE
160460 160466        && (ofst==WAL_LOCK_WRITE || ofst==WAL_LOCK_CKPT || ofst==WAL_LOCK_READ0)
160461 160467       ){
160462 160468         bCapture = 1;
160463 160469       }
160464 160470   
160465 160471       if( bCapture==0 || 0==(flags & SQLITE_SHM_UNLOCK) ){
160466 160472         rc = p->pReal->pMethods->xShmLock(p->pReal, ofst, n, flags);
160467 160473         if( bCapture && rc==SQLITE_OK ){
160468         -        pOta->mLock |= (1 << ofst);
       160474  +        pRbu->mLock |= (1 << ofst);
160469 160475         }
160470 160476       }
160471 160477     }
160472 160478   
160473 160479     return rc;
160474 160480   }
160475 160481   
160476 160482   /*
160477 160483   ** Obtain a pointer to a mapping of a single 32KiB page of the *-shm file.
160478 160484   */
160479         -static int otaVfsShmMap(
       160485  +static int rbuVfsShmMap(
160480 160486     sqlite3_file *pFile, 
160481 160487     int iRegion, 
160482 160488     int szRegion, 
160483 160489     int isWrite, 
160484 160490     void volatile **pp
160485 160491   ){
160486         -  ota_file *p = (ota_file*)pFile;
       160492  +  rbu_file *p = (rbu_file*)pFile;
160487 160493     int rc = SQLITE_OK;
160488         -  int eStage = (p->pOta ? p->pOta->eStage : 0);
       160494  +  int eStage = (p->pRbu ? p->pRbu->eStage : 0);
160489 160495   
160490         -  /* If not in OTA_STAGE_OAL, allow this call to pass through. Or, if this
160491         -  ** 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 
160492 160498     ** instead of a file on disk.  */
160493 160499     assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160494         -  if( eStage==OTA_STAGE_OAL || eStage==OTA_STAGE_MOVE ){
       160500  +  if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
160495 160501       if( iRegion<=p->nShm ){
160496 160502         int nByte = (iRegion+1) * sizeof(char*);
160497 160503         char **apNew = (char**)sqlite3_realloc(p->apShm, nByte);
160498 160504         if( apNew==0 ){
160499 160505           rc = SQLITE_NOMEM;
160500 160506         }else{
160501 160507           memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm));
................................................................................
160526 160532   
160527 160533     return rc;
160528 160534   }
160529 160535   
160530 160536   /*
160531 160537   ** Memory barrier.
160532 160538   */
160533         -static void otaVfsShmBarrier(sqlite3_file *pFile){
160534         -  ota_file *p = (ota_file *)pFile;
       160539  +static void rbuVfsShmBarrier(sqlite3_file *pFile){
       160540  +  rbu_file *p = (rbu_file *)pFile;
160535 160541     p->pReal->pMethods->xShmBarrier(p->pReal);
160536 160542   }
160537 160543   
160538 160544   /*
160539 160545   ** The xShmUnmap method.
160540 160546   */
160541         -static int otaVfsShmUnmap(sqlite3_file *pFile, int delFlag){
160542         -  ota_file *p = (ota_file*)pFile;
       160547  +static int rbuVfsShmUnmap(sqlite3_file *pFile, int delFlag){
       160548  +  rbu_file *p = (rbu_file*)pFile;
160543 160549     int rc = SQLITE_OK;
160544         -  int eStage = (p->pOta ? p->pOta->eStage : 0);
       160550  +  int eStage = (p->pRbu ? p->pRbu->eStage : 0);
160545 160551   
160546 160552     assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160547         -  if( eStage==OTA_STAGE_OAL || eStage==OTA_STAGE_MOVE ){
       160553  +  if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
160548 160554       /* no-op */
160549 160555     }else{
160550 160556       /* Release the checkpointer and writer locks */
160551         -    otaUnlockShm(p);
       160557  +    rbuUnlockShm(p);
160552 160558       rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag);
160553 160559     }
160554 160560     return rc;
160555 160561   }
160556 160562   
160557 160563   /*
160558 160564   ** Given that zWal points to a buffer containing a wal file name passed to 
160559 160565   ** either the xOpen() or xAccess() VFS method, return a pointer to the
160560 160566   ** file-handle opened by the same database connection on the corresponding
160561 160567   ** database file.
160562 160568   */
160563         -static ota_file *otaFindMaindb(ota_vfs *pOtaVfs, const char *zWal){
160564         -  ota_file *pDb;
160565         -  sqlite3_mutex_enter(pOtaVfs->mutex);
160566         -  for(pDb=pOtaVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext);
160567         -  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);
160568 160574     return pDb;
160569 160575   }
160570 160576   
160571 160577   /*
160572         -** Open an ota file handle.
       160578  +** Open an rbu file handle.
160573 160579   */
160574         -static int otaVfsOpen(
       160580  +static int rbuVfsOpen(
160575 160581     sqlite3_vfs *pVfs,
160576 160582     const char *zName,
160577 160583     sqlite3_file *pFile,
160578 160584     int flags,
160579 160585     int *pOutFlags
160580 160586   ){
160581         -  static sqlite3_io_methods otavfs_io_methods = {
       160587  +  static sqlite3_io_methods rbuvfs_io_methods = {
160582 160588       2,                            /* iVersion */
160583         -    otaVfsClose,                  /* xClose */
160584         -    otaVfsRead,                   /* xRead */
160585         -    otaVfsWrite,                  /* xWrite */
160586         -    otaVfsTruncate,               /* xTruncate */
160587         -    otaVfsSync,                   /* xSync */
160588         -    otaVfsFileSize,               /* xFileSize */
160589         -    otaVfsLock,                   /* xLock */
160590         -    otaVfsUnlock,                 /* xUnlock */
160591         -    otaVfsCheckReservedLock,      /* xCheckReservedLock */
160592         -    otaVfsFileControl,            /* xFileControl */
160593         -    otaVfsSectorSize,             /* xSectorSize */
160594         -    otaVfsDeviceCharacteristics,  /* xDeviceCharacteristics */
160595         -    otaVfsShmMap,                 /* xShmMap */
160596         -    otaVfsShmLock,                /* xShmLock */
160597         -    otaVfsShmBarrier,             /* xShmBarrier */
160598         -    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 */
160599 160605     };
160600         -  ota_vfs *pOtaVfs = (ota_vfs*)pVfs;
160601         -  sqlite3_vfs *pRealVfs = pOtaVfs->pRealVfs;
160602         -  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;
160603 160609     int rc = SQLITE_OK;
160604 160610     const char *zOpen = zName;
160605 160611   
160606         -  memset(pFd, 0, sizeof(ota_file));
       160612  +  memset(pFd, 0, sizeof(rbu_file));
160607 160613     pFd->pReal = (sqlite3_file*)&pFd[1];
160608         -  pFd->pOtaVfs = pOtaVfs;
       160614  +  pFd->pRbuVfs = pRbuVfs;
160609 160615     pFd->openFlags = flags;
160610 160616     if( zName ){
160611 160617       if( flags & SQLITE_OPEN_MAIN_DB ){
160612 160618         /* A main database has just been opened. The following block sets
160613 160619         ** (pFd->zWal) to point to a buffer owned by SQLite that contains
160614 160620         ** the name of the *-wal file this db connection will use. SQLite
160615 160621         ** happens to pass a pointer to this buffer when using xAccess()
................................................................................
160629 160635         }else{
160630 160636           while( *z==0 ) z++;
160631 160637         }
160632 160638         z += (n + 8 + 1);
160633 160639         pFd->zWal = z;
160634 160640       }
160635 160641       else if( flags & SQLITE_OPEN_WAL ){
160636         -      ota_file *pDb = otaFindMaindb(pOtaVfs, zName);
       160642  +      rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName);
160637 160643         if( pDb ){
160638         -        if( pDb->pOta && pDb->pOta->eStage==OTA_STAGE_OAL ){
       160644  +        if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
160639 160645             /* This call is to open a *-wal file. Intead, open the *-oal. This
160640 160646             ** code ensures that the string passed to xOpen() is terminated by a
160641 160647             ** pair of '\0' bytes in case the VFS attempts to extract a URI 
160642 160648             ** parameter from it.  */
160643 160649             int nCopy = strlen(zName);
160644 160650             char *zCopy = sqlite3_malloc(nCopy+2);
160645 160651             if( zCopy ){
................................................................................
160647 160653               zCopy[nCopy-3] = 'o';
160648 160654               zCopy[nCopy] = '\0';
160649 160655               zCopy[nCopy+1] = '\0';
160650 160656               zOpen = (const char*)(pFd->zDel = zCopy);
160651 160657             }else{
160652 160658               rc = SQLITE_NOMEM;
160653 160659             }
160654         -          pFd->pOta = pDb->pOta;
       160660  +          pFd->pRbu = pDb->pRbu;
160655 160661           }
160656 160662           pDb->pWalFd = pFd;
160657 160663         }
160658 160664       }
160659 160665     }
160660 160666   
160661 160667     if( rc==SQLITE_OK ){
160662 160668       rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, flags, pOutFlags);
160663 160669     }
160664 160670     if( pFd->pReal->pMethods ){
160665 160671       /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
160666 160672       ** pointer and, if the file is a main database file, link it into the
160667 160673       ** mutex protected linked list of all such files.  */
160668         -    pFile->pMethods = &otavfs_io_methods;
       160674  +    pFile->pMethods = &rbuvfs_io_methods;
160669 160675       if( flags & SQLITE_OPEN_MAIN_DB ){
160670         -      sqlite3_mutex_enter(pOtaVfs->mutex);
160671         -      pFd->pMainNext = pOtaVfs->pMain;
160672         -      pOtaVfs->pMain = pFd;
160673         -      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);
160674 160680       }
160675 160681     }else{
160676 160682       sqlite3_free(pFd->zDel);
160677 160683     }
160678 160684   
160679 160685     return rc;
160680 160686   }
160681 160687   
160682 160688   /*
160683 160689   ** Delete the file located at zPath.
160684 160690   */
160685         -static int otaVfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
160686         -  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;
160687 160693     return pRealVfs->xDelete(pRealVfs, zPath, dirSync);
160688 160694   }
160689 160695   
160690 160696   /*
160691 160697   ** Test for access permissions. Return true if the requested permission
160692 160698   ** is available, or false otherwise.
160693 160699   */
160694         -static int otaVfsAccess(
       160700  +static int rbuVfsAccess(
160695 160701     sqlite3_vfs *pVfs, 
160696 160702     const char *zPath, 
160697 160703     int flags, 
160698 160704     int *pResOut
160699 160705   ){
160700         -  ota_vfs *pOtaVfs = (ota_vfs*)pVfs;
160701         -  sqlite3_vfs *pRealVfs = pOtaVfs->pRealVfs;
       160706  +  rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
       160707  +  sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
160702 160708     int rc;
160703 160709   
160704 160710     rc = pRealVfs->xAccess(pRealVfs, zPath, flags, pResOut);
160705 160711   
160706         -  /* If this call is to check if a *-wal file associated with an OTA target
160707         -  ** 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,
160708 160714     ** the following special handling is activated:
160709 160715     **
160710 160716     **   a) if the *-wal file does exist, return SQLITE_CANTOPEN. This
160711         -  **      ensures that the OTA extension never tries to update a database
       160717  +  **      ensures that the RBU extension never tries to update a database
160712 160718     **      in wal mode, even if the first page of the database file has
160713 160719     **      been damaged. 
160714 160720     **
160715 160721     **   b) if the *-wal file does not exist, claim that it does anyway,
160716 160722     **      causing SQLite to call xOpen() to open it. This call will also
160717         -  **      be intercepted (see the otaVfsOpen() function) and the *-oal
       160723  +  **      be intercepted (see the rbuVfsOpen() function) and the *-oal
160718 160724     **      file opened instead.
160719 160725     */
160720 160726     if( rc==SQLITE_OK && flags==SQLITE_ACCESS_EXISTS ){
160721         -    ota_file *pDb = otaFindMaindb(pOtaVfs, zPath);
160722         -    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 ){
160723 160729         if( *pResOut ){
160724 160730           rc = SQLITE_CANTOPEN;
160725 160731         }else{
160726 160732           *pResOut = 1;
160727 160733         }
160728 160734       }
160729 160735     }
................................................................................
160732 160738   }
160733 160739   
160734 160740   /*
160735 160741   ** Populate buffer zOut with the full canonical pathname corresponding
160736 160742   ** to the pathname in zPath. zOut is guaranteed to point to a buffer
160737 160743   ** of at least (DEVSYM_MAX_PATHNAME+1) bytes.
160738 160744   */
160739         -static int otaVfsFullPathname(
       160745  +static int rbuVfsFullPathname(
160740 160746     sqlite3_vfs *pVfs, 
160741 160747     const char *zPath, 
160742 160748     int nOut, 
160743 160749     char *zOut
160744 160750   ){
160745         -  sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
       160751  +  sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160746 160752     return pRealVfs->xFullPathname(pRealVfs, zPath, nOut, zOut);
160747 160753   }
160748 160754   
160749 160755   #ifndef SQLITE_OMIT_LOAD_EXTENSION
160750 160756   /*
160751 160757   ** Open the dynamic library located at zPath and return a handle.
160752 160758   */
160753         -static void *otaVfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
160754         -  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;
160755 160761     return pRealVfs->xDlOpen(pRealVfs, zPath);
160756 160762   }
160757 160763   
160758 160764   /*
160759 160765   ** Populate the buffer zErrMsg (size nByte bytes) with a human readable
160760 160766   ** utf-8 string describing the most recent error encountered associated 
160761 160767   ** with dynamic libraries.
160762 160768   */
160763         -static void otaVfsDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
160764         -  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;
160765 160771     pRealVfs->xDlError(pRealVfs, nByte, zErrMsg);
160766 160772   }
160767 160773   
160768 160774   /*
160769 160775   ** Return a pointer to the symbol zSymbol in the dynamic library pHandle.
160770 160776   */
160771         -static void (*otaVfsDlSym(
       160777  +static void (*rbuVfsDlSym(
160772 160778     sqlite3_vfs *pVfs, 
160773 160779     void *pArg, 
160774 160780     const char *zSym
160775 160781   ))(void){
160776         -  sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
       160782  +  sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160777 160783     return pRealVfs->xDlSym(pRealVfs, pArg, zSym);
160778 160784   }
160779 160785   
160780 160786   /*
160781 160787   ** Close the dynamic library handle pHandle.
160782 160788   */
160783         -static void otaVfsDlClose(sqlite3_vfs *pVfs, void *pHandle){
160784         -  sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
       160789  +static void rbuVfsDlClose(sqlite3_vfs *pVfs, void *pHandle){
       160790  +  sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160785 160791     return pRealVfs->xDlClose(pRealVfs, pHandle);
160786 160792   }
160787 160793   #endif /* SQLITE_OMIT_LOAD_EXTENSION */
160788 160794   
160789 160795   /*
160790 160796   ** Populate the buffer pointed to by zBufOut with nByte bytes of 
160791 160797   ** random data.
160792 160798   */
160793         -static int otaVfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
160794         -  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;
160795 160801     return pRealVfs->xRandomness(pRealVfs, nByte, zBufOut);
160796 160802   }
160797 160803   
160798 160804   /*
160799 160805   ** Sleep for nMicro microseconds. Return the number of microseconds 
160800 160806   ** actually slept.
160801 160807   */
160802         -static int otaVfsSleep(sqlite3_vfs *pVfs, int nMicro){
160803         -  sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
       160808  +static int rbuVfsSleep(sqlite3_vfs *pVfs, int nMicro){
       160809  +  sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160804 160810     return pRealVfs->xSleep(pRealVfs, nMicro);
160805 160811   }
160806 160812   
160807 160813   /*
160808 160814   ** Return the current time as a Julian Day number in *pTimeOut.
160809 160815   */
160810         -static int otaVfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
160811         -  sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
       160816  +static int rbuVfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
       160817  +  sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160812 160818     return pRealVfs->xCurrentTime(pRealVfs, pTimeOut);
160813 160819   }
160814 160820   
160815 160821   /*
160816 160822   ** No-op.
160817 160823   */
160818         -static int otaVfsGetLastError(sqlite3_vfs *pVfs, int a, char *b){
       160824  +static int rbuVfsGetLastError(sqlite3_vfs *pVfs, int a, char *b){
160819 160825     return 0;
160820 160826   }
160821 160827   
160822 160828   /*
160823         -** Deregister and destroy an OTA vfs created by an earlier call to
160824         -** sqlite3ota_create_vfs().
       160829  +** Deregister and destroy an RBU vfs created by an earlier call to
       160830  +** sqlite3rbu_create_vfs().
160825 160831   */
160826         -SQLITE_API void SQLITE_STDCALL sqlite3ota_destroy_vfs(const char *zName){
       160832  +SQLITE_API void SQLITE_STDCALL sqlite3rbu_destroy_vfs(const char *zName){
160827 160833     sqlite3_vfs *pVfs = sqlite3_vfs_find(zName);
160828         -  if( pVfs && pVfs->xOpen==otaVfsOpen ){
160829         -    sqlite3_mutex_free(((ota_vfs*)pVfs)->mutex);
       160834  +  if( pVfs && pVfs->xOpen==rbuVfsOpen ){
       160835  +    sqlite3_mutex_free(((rbu_vfs*)pVfs)->mutex);
160830 160836       sqlite3_vfs_unregister(pVfs);
160831 160837       sqlite3_free(pVfs);
160832 160838     }
160833 160839   }
160834 160840   
160835 160841   /*
160836         -** 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
160837 160843   ** via existing VFS zParent. The new object is registered as a non-default
160838 160844   ** VFS with SQLite before returning.
160839 160845   */
160840         -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){
160841 160847   
160842 160848     /* Template for VFS */
160843 160849     static sqlite3_vfs vfs_template = {
160844 160850       1,                            /* iVersion */
160845 160851       0,                            /* szOsFile */
160846 160852       0,                            /* mxPathname */
160847 160853       0,                            /* pNext */
160848 160854       0,                            /* zName */
160849 160855       0,                            /* pAppData */
160850         -    otaVfsOpen,                   /* xOpen */
160851         -    otaVfsDelete,                 /* xDelete */
160852         -    otaVfsAccess,                 /* xAccess */
160853         -    otaVfsFullPathname,           /* xFullPathname */
       160856  +    rbuVfsOpen,                   /* xOpen */
       160857  +    rbuVfsDelete,                 /* xDelete */
       160858  +    rbuVfsAccess,                 /* xAccess */
       160859  +    rbuVfsFullPathname,           /* xFullPathname */
160854 160860   
160855 160861   #ifndef SQLITE_OMIT_LOAD_EXTENSION
160856         -    otaVfsDlOpen,                 /* xDlOpen */
160857         -    otaVfsDlError,                /* xDlError */
160858         -    otaVfsDlSym,                  /* xDlSym */
160859         -    otaVfsDlClose,                /* xDlClose */
       160862  +    rbuVfsDlOpen,                 /* xDlOpen */
       160863  +    rbuVfsDlError,                /* xDlError */
       160864  +    rbuVfsDlSym,                  /* xDlSym */
       160865  +    rbuVfsDlClose,                /* xDlClose */
160860 160866   #else
160861 160867       0, 0, 0, 0,
160862 160868   #endif
160863 160869   
160864         -    otaVfsRandomness,             /* xRandomness */
160865         -    otaVfsSleep,                  /* xSleep */
160866         -    otaVfsCurrentTime,            /* xCurrentTime */
160867         -    otaVfsGetLastError,           /* xGetLastError */
       160870  +    rbuVfsRandomness,             /* xRandomness */
       160871  +    rbuVfsSleep,                  /* xSleep */
       160872  +    rbuVfsCurrentTime,            /* xCurrentTime */
       160873  +    rbuVfsGetLastError,           /* xGetLastError */
160868 160874       0,                            /* xCurrentTimeInt64 (version 2) */
160869 160875       0, 0, 0                       /* Unimplemented version 3 methods */
160870 160876     };
160871 160877   
160872         -  ota_vfs *pNew = 0;              /* Newly allocated VFS */
       160878  +  rbu_vfs *pNew = 0;              /* Newly allocated VFS */
160873 160879     int nName;
160874 160880     int rc = SQLITE_OK;
160875 160881   
160876 160882     int nByte;
160877 160883     nName = strlen(zName);
160878         -  nByte = sizeof(ota_vfs) + nName + 1;
160879         -  pNew = (ota_vfs*)sqlite3_malloc(nByte);
       160884  +  nByte = sizeof(rbu_vfs) + nName + 1;
       160885  +  pNew = (rbu_vfs*)sqlite3_malloc(nByte);
160880 160886     if( pNew==0 ){
160881 160887       rc = SQLITE_NOMEM;
160882 160888     }else{
160883 160889       sqlite3_vfs *pParent;           /* Parent VFS */
160884 160890       memset(pNew, 0, nByte);
160885 160891       pParent = sqlite3_vfs_find(zParent);
160886 160892       if( pParent==0 ){
160887 160893         rc = SQLITE_NOTFOUND;
160888 160894       }else{
160889 160895         char *zSpace;
160890 160896         memcpy(&pNew->base, &vfs_template, sizeof(sqlite3_vfs));
160891 160897         pNew->base.mxPathname = pParent->mxPathname;
160892         -      pNew->base.szOsFile = sizeof(ota_file) + pParent->szOsFile;
       160898  +      pNew->base.szOsFile = sizeof(rbu_file) + pParent->szOsFile;
160893 160899         pNew->pRealVfs = pParent;
160894 160900         pNew->base.zName = (const char*)(zSpace = (char*)&pNew[1]);
160895 160901         memcpy(zSpace, zName, nName);
160896 160902   
160897 160903         /* Allocate the mutex and register the new VFS (not as the default) */
160898 160904         pNew->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_RECURSIVE);
160899 160905         if( pNew->mutex==0 ){
................................................................................
160911 160917   
160912 160918     return rc;
160913 160919   }
160914 160920   
160915 160921   
160916 160922   /**************************************************************************/
160917 160923   
160918         -#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA) */
       160924  +#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) */
160919 160925   
160920         -/************** End of sqlite3ota.c ******************************************/
       160926  +/************** End of sqlite3rbu.c ******************************************/
160921 160927   /************** Begin file dbstat.c ******************************************/
160922 160928   /*
160923 160929   ** 2010 July 12
160924 160930   **
160925 160931   ** The author disclaims copyright to this source code.  In place of
160926 160932   ** a legal notice, here is a blessing:
160927 160933   **

Changes to SQLite.Interop/src/core/sqlite3.h.

   109    109   **
   110    110   ** See also: [sqlite3_libversion()],
   111    111   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   112    112   ** [sqlite_version()] and [sqlite_source_id()].
   113    113   */
   114    114   #define SQLITE_VERSION        "3.8.11"
   115    115   #define SQLITE_VERSION_NUMBER 3008011
   116         -#define SQLITE_SOURCE_ID      "2015-07-21 19:22:35 01c8b9ccfa0f336dfead7c004de3de571753f707"
          116  +#define SQLITE_SOURCE_ID      "2015-07-24 00:02:15 119883a21bdcab66c15d1e80f3da20addda328ad"
   117    117   
   118    118   /*
   119    119   ** CAPI3REF: Run-Time Library Version Numbers
   120    120   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   121    121   **
   122    122   ** These interfaces provide the same information as the [SQLITE_VERSION],
   123    123   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
   963    963   ** circumstances in order to fix a problem with priority inversion.
   964    964   ** Applications should <em>not</em> use this file-control.
   965    965   **
   966    966   ** <li>[[SQLITE_FCNTL_ZIPVFS]]
   967    967   ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
   968    968   ** VFS should return SQLITE_NOTFOUND for this opcode.
   969    969   **
   970         -** <li>[[SQLITE_FCNTL_OTA]]
   971         -** The [SQLITE_FCNTL_OTA] opcode is implemented by the special VFS used by
   972         -** the OTA extension only.  All other VFS should return SQLITE_NOTFOUND for
          970  +** <li>[[SQLITE_FCNTL_RBU]]
          971  +** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
          972  +** the RBU extension only.  All other VFS should return SQLITE_NOTFOUND for
   973    973   ** this opcode.  
   974    974   ** </ul>
   975    975   */
   976    976   #define SQLITE_FCNTL_LOCKSTATE               1
   977    977   #define SQLITE_FCNTL_GET_LOCKPROXYFILE       2
   978    978   #define SQLITE_FCNTL_SET_LOCKPROXYFILE       3
   979    979   #define SQLITE_FCNTL_LAST_ERRNO              4
................................................................................
   993    993   #define SQLITE_FCNTL_TRACE                  19
   994    994   #define SQLITE_FCNTL_HAS_MOVED              20
   995    995   #define SQLITE_FCNTL_SYNC                   21
   996    996   #define SQLITE_FCNTL_COMMIT_PHASETWO        22
   997    997   #define SQLITE_FCNTL_WIN32_SET_HANDLE       23
   998    998   #define SQLITE_FCNTL_WAL_BLOCK              24
   999    999   #define SQLITE_FCNTL_ZIPVFS                 25
  1000         -#define SQLITE_FCNTL_OTA                    26
         1000  +#define SQLITE_FCNTL_RBU                    26
  1001   1001   
  1002   1002   /* deprecated names */
  1003   1003   #define SQLITE_GET_LOCKPROXYFILE      SQLITE_FCNTL_GET_LOCKPROXYFILE
  1004   1004   #define SQLITE_SET_LOCKPROXYFILE      SQLITE_FCNTL_SET_LOCKPROXYFILE
  1005   1005   #define SQLITE_LAST_ERRNO             SQLITE_FCNTL_LAST_ERRNO
  1006   1006   
  1007   1007