sqllogictest
Check-in [9e7d09c07c]
Not logged in

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

Overview
Comment:Update to SQLite version 3.7.11-beta
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:9e7d09c07cd350fe31f839c238ed849ef754f155
User & Date: drh 2012-03-19 15:24:46
Context
2012-05-12
02:44
Update the built-in SQLite to the latest 3.7.12 beta. check-in: f003563216 user: drh tags: trunk
2012-03-19
15:24
Update to SQLite version 3.7.11-beta check-in: 9e7d09c07c user: drh tags: trunk
2012-01-11
18:07
Update the built-in SQLite to the 3.7.10 beta. check-in: 9351002d37 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/sqlite3.c.

     1      1   /******************************************************************************
     2      2   ** This file is an amalgamation of many separate C source files from SQLite
     3         -** version 3.7.10.  By combining all the individual C code files into this 
            3  +** version 3.7.11.  By combining all the individual C code files into this 
     4      4   ** single large file, the entire code can be compiled as a single translation
     5      5   ** unit.  This allows many compilers to do optimizations that would not be
     6      6   ** possible if the files were compiled separately.  Performance improvements
     7      7   ** of 5% or more are commonly seen when SQLite is compiled as a single
     8      8   ** translation unit.
     9      9   **
    10     10   ** This file is all you need to compile SQLite.  To use SQLite in other
................................................................................
   653    653   ** string contains the date and time of the check-in (UTC) and an SHA1
   654    654   ** hash of the entire source tree.
   655    655   **
   656    656   ** See also: [sqlite3_libversion()],
   657    657   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   658    658   ** [sqlite_version()] and [sqlite_source_id()].
   659    659   */
   660         -#define SQLITE_VERSION        "3.7.10"
   661         -#define SQLITE_VERSION_NUMBER 3007010
   662         -#define SQLITE_SOURCE_ID      "2012-01-11 16:16:08 9e31a275ef494ea8713a1d60a15b84157e57c3ff"
          660  +#define SQLITE_VERSION        "3.7.11"
          661  +#define SQLITE_VERSION_NUMBER 3007011
          662  +#define SQLITE_SOURCE_ID      "2012-03-19 14:57:49 bc03d99a78e90c02b69037e5f5f81537b5a3ac60"
   663    663   
   664    664   /*
   665    665   ** CAPI3REF: Run-Time Library Version Numbers
   666    666   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   667    667   **
   668    668   ** These interfaces provide the same information as the [SQLITE_VERSION],
   669    669   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
  1007   1007   #define SQLITE_IOERR_SEEK              (SQLITE_IOERR | (22<<8))
  1008   1008   #define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
  1009   1009   #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
  1010   1010   #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
  1011   1011   #define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
  1012   1012   #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
  1013   1013   #define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
         1014  +#define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
  1014   1015   
  1015   1016   /*
  1016   1017   ** CAPI3REF: Flags For File Open Operations
  1017   1018   **
  1018   1019   ** These bit values are intended for use in the
  1019   1020   ** 3rd parameter to the [sqlite3_open_v2()] interface and
  1020   1021   ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
................................................................................
  1262   1263   ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging.  This
  1263   1264   ** opcode causes the xFileControl method to write the current state of
  1264   1265   ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
  1265   1266   ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
  1266   1267   ** into an integer that the pArg argument points to. This capability
  1267   1268   ** is used during testing and only needs to be supported when SQLITE_TEST
  1268   1269   ** is defined.
  1269         -**
         1270  +** <ul>
         1271  +** <li>[[SQLITE_FCNTL_SIZE_HINT]]
  1270   1272   ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
  1271   1273   ** layer a hint of how large the database file will grow to be during the
  1272   1274   ** current transaction.  This hint is not guaranteed to be accurate but it
  1273   1275   ** is often close.  The underlying VFS might choose to preallocate database
  1274   1276   ** file space based on this hint in order to help writes to the database
  1275   1277   ** file run faster.
  1276   1278   **
         1279  +** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
  1277   1280   ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
  1278   1281   ** extends and truncates the database file in chunks of a size specified
  1279   1282   ** by the user. The fourth argument to [sqlite3_file_control()] should 
  1280   1283   ** point to an integer (type int) containing the new chunk-size to use
  1281   1284   ** for the nominated database. Allocating database file space in large
  1282   1285   ** chunks (say 1MB at a time), may reduce file-system fragmentation and
  1283   1286   ** improve performance on some systems.
  1284   1287   **
         1288  +** <li>[[SQLITE_FCNTL_FILE_POINTER]]
  1285   1289   ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
  1286   1290   ** to the [sqlite3_file] object associated with a particular database
  1287   1291   ** connection.  See the [sqlite3_file_control()] documentation for
  1288   1292   ** additional information.
  1289   1293   **
         1294  +** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
  1290   1295   ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
  1291   1296   ** SQLite and sent to all VFSes in place of a call to the xSync method
  1292   1297   ** when the database connection has [PRAGMA synchronous] set to OFF.)^
  1293   1298   ** Some specialized VFSes need this signal in order to operate correctly
  1294   1299   ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most 
  1295   1300   ** VFSes do not need this signal and should silently ignore this opcode.
  1296   1301   ** Applications should not call [sqlite3_file_control()] with this
  1297   1302   ** opcode as doing so may disrupt the operation of the specialized VFSes
  1298   1303   ** that do require it.  
  1299   1304   **
         1305  +** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
  1300   1306   ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
  1301   1307   ** retry counts and intervals for certain disk I/O operations for the
  1302   1308   ** windows [VFS] in order to provide robustness in the presence of
  1303   1309   ** anti-virus programs.  By default, the windows VFS will retry file read,
  1304   1310   ** file write, and file delete operations up to 10 times, with a delay
  1305   1311   ** of 25 milliseconds before the first retry and with the delay increasing
  1306   1312   ** by an additional 25 milliseconds with each subsequent retry.  This
................................................................................
  1309   1315   ** within the same process.  The argument is a pointer to an array of two
  1310   1316   ** integers where the first integer i the new retry count and the second
  1311   1317   ** integer is the delay.  If either integer is negative, then the setting
  1312   1318   ** is not changed but instead the prior value of that setting is written
  1313   1319   ** into the array entry, allowing the current retry settings to be
  1314   1320   ** interrogated.  The zDbName parameter is ignored.
  1315   1321   **
         1322  +** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
  1316   1323   ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
  1317   1324   ** persistent [WAL | Write AHead Log] setting.  By default, the auxiliary
  1318   1325   ** write ahead log and shared memory files used for transaction control
  1319   1326   ** are automatically deleted when the latest connection to the database
  1320   1327   ** closes.  Setting persistent WAL mode causes those files to persist after
  1321   1328   ** close.  Persisting the files is useful when other processes that do not
  1322   1329   ** have write permission on the directory containing the database file want
................................................................................
  1323   1330   ** to read the database file, as the WAL and shared memory files must exist
  1324   1331   ** in order for the database to be readable.  The fourth parameter to
  1325   1332   ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
  1326   1333   ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
  1327   1334   ** WAL mode.  If the integer is -1, then it is overwritten with the current
  1328   1335   ** WAL persistence setting.
  1329   1336   **
         1337  +** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
  1330   1338   ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
  1331   1339   ** persistent "powersafe-overwrite" or "PSOW" setting.  The PSOW setting
  1332   1340   ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
  1333   1341   ** xDeviceCharacteristics methods. The fourth parameter to
  1334   1342   ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
  1335   1343   ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
  1336   1344   ** mode.  If the integer is -1, then it is overwritten with the current
  1337   1345   ** zero-damage mode setting.
  1338   1346   **
         1347  +** <li>[[SQLITE_FCNTL_OVERWRITE]]
  1339   1348   ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
  1340   1349   ** a write transaction to indicate that, unless it is rolled back for some
  1341   1350   ** reason, the entire database file will be overwritten by the current 
  1342   1351   ** transaction. This is used by VACUUM operations.
  1343   1352   **
         1353  +** <li>[[SQLITE_FCNTL_VFSNAME]]
  1344   1354   ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
  1345   1355   ** all [VFSes] in the VFS stack.  The names are of all VFS shims and the
  1346   1356   ** final bottom-level VFS are written into memory obtained from 
  1347   1357   ** [sqlite3_malloc()] and the result is stored in the char* variable
  1348   1358   ** that the fourth parameter of [sqlite3_file_control()] points to.
  1349   1359   ** The caller is responsible for freeing the memory when done.  As with
  1350   1360   ** all file-control actions, there is no guarantee that this will actually
  1351   1361   ** do anything.  Callers should initialize the char* variable to a NULL
  1352   1362   ** pointer in case this file-control is not implemented.  This file-control
  1353   1363   ** is intended for diagnostic use only.
         1364  +**
         1365  +** <li>[[SQLITE_FCNTL_PRAGMA]]
         1366  +** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA] 
         1367  +** file control is sent to the open [sqlite3_file] object corresponding
         1368  +** to the database file to which the pragma statement refers. ^The argument
         1369  +** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
         1370  +** pointers to strings (char**) in which the second element of the array
         1371  +** is the name of the pragma and the third element is the argument to the
         1372  +** pragma or NULL if the pragma has no argument.  ^The handler for an
         1373  +** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
         1374  +** of the char** argument point to a string obtained from [sqlite3_mprintf()]
         1375  +** or the equivalent and that string will become the result of the pragma or
         1376  +** the error message if the pragma fails. ^If the
         1377  +** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal 
         1378  +** [PRAGMA] processing continues.  ^If the [SQLITE_FCNTL_PRAGMA]
         1379  +** file control returns [SQLITE_OK], then the parser assumes that the
         1380  +** VFS has handled the PRAGMA itself and the parser generates a no-op
         1381  +** prepared statement.  ^If the [SQLITE_FCNTL_PRAGMA] file control returns
         1382  +** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
         1383  +** that the VFS encountered an error while handling the [PRAGMA] and the
         1384  +** compilation of the PRAGMA fails with an error.  ^The [SQLITE_FCNTL_PRAGMA]
         1385  +** file control occurs at the beginning of pragma statement analysis and so
         1386  +** it is able to override built-in [PRAGMA] statements.
         1387  +** </ul>
  1354   1388   */
  1355   1389   #define SQLITE_FCNTL_LOCKSTATE               1
  1356   1390   #define SQLITE_GET_LOCKPROXYFILE             2
  1357   1391   #define SQLITE_SET_LOCKPROXYFILE             3
  1358   1392   #define SQLITE_LAST_ERRNO                    4
  1359   1393   #define SQLITE_FCNTL_SIZE_HINT               5
  1360   1394   #define SQLITE_FCNTL_CHUNK_SIZE              6
................................................................................
  1361   1395   #define SQLITE_FCNTL_FILE_POINTER            7
  1362   1396   #define SQLITE_FCNTL_SYNC_OMITTED            8
  1363   1397   #define SQLITE_FCNTL_WIN32_AV_RETRY          9
  1364   1398   #define SQLITE_FCNTL_PERSIST_WAL            10
  1365   1399   #define SQLITE_FCNTL_OVERWRITE              11
  1366   1400   #define SQLITE_FCNTL_VFSNAME                12
  1367   1401   #define SQLITE_FCNTL_POWERSAFE_OVERWRITE    13
         1402  +#define SQLITE_FCNTL_PRAGMA                 14
  1368   1403   
  1369   1404   /*
  1370   1405   ** CAPI3REF: Mutex Handle
  1371   1406   **
  1372   1407   ** The mutex module within SQLite defines [sqlite3_mutex] to be an
  1373   1408   ** abstract type for a mutex object.  The SQLite core never looks
  1374   1409   ** at the internal representation of an [sqlite3_mutex].  It only
................................................................................
  3178   3213   /*
  3179   3214   ** CAPI3REF: Obtain Values For URI Parameters
  3180   3215   **
  3181   3216   ** These are utility routines, useful to VFS implementations, that check
  3182   3217   ** to see if a database file was a URI that contained a specific query 
  3183   3218   ** parameter, and if so obtains the value of that query parameter.
  3184   3219   **
  3185         -** If F is the filename pointer passed into the xOpen() method of a VFS
  3186         -** implementation and P is the name of the query parameter, then
         3220  +** If F is the database filename pointer passed into the xOpen() method of 
         3221  +** a VFS implementation when the flags parameter to xOpen() has one or 
         3222  +** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
         3223  +** P is the name of the query parameter, then
  3187   3224   ** sqlite3_uri_parameter(F,P) returns the value of the P
  3188   3225   ** parameter if it exists or a NULL pointer if P does not appear as a 
  3189   3226   ** query parameter on F.  If P is a query parameter of F
  3190   3227   ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
  3191   3228   ** a pointer to an empty string.
  3192   3229   **
  3193   3230   ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
  3194   3231   ** parameter and returns true (1) or false (0) according to the value
  3195         -** of P.  The value of P is true if it is "yes" or "true" or "on" or 
  3196         -** a non-zero number and is false otherwise.  If P is not a query parameter
  3197         -** on F then sqlite3_uri_boolean(F,P,B) returns (B!=0).
         3232  +** of P.  The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
         3233  +** value of query parameter P is one of "yes", "true", or "on" in any
         3234  +** case or if the value begins with a non-zero number.  The 
         3235  +** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
         3236  +** query parameter P is one of "no", "false", or "off" in any case or
         3237  +** if the value begins with a numeric zero.  If P is not a query
         3238  +** parameter on F or if the value of P is does not match any of the
         3239  +** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
  3198   3240   **
  3199   3241   ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
  3200   3242   ** 64-bit signed integer and returns that integer, or D if P does not
  3201   3243   ** exist.  If the value of P is something other than an integer, then
  3202   3244   ** zero is returned.
  3203   3245   ** 
  3204   3246   ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
  3205   3247   ** sqlite3_uri_boolean(F,P,B) returns B.  If F is not a NULL pointer and
  3206         -** is not a pathname pointer that SQLite passed into the xOpen VFS method,
  3207         -** then the behavior of this routine is undefined and probably undesirable.
         3248  +** is not a database file pathname pointer that SQLite passed into the xOpen
         3249  +** VFS method, then the behavior of this routine is undefined and probably
         3250  +** undesirable.
  3208   3251   */
  3209   3252   SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
  3210   3253   SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
  3211   3254   SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
  3212   3255   
  3213   3256   
  3214   3257   /*
................................................................................
  5002   5045   ** ^The filename returned by this function is the output of the
  5003   5046   ** xFullPathname method of the [VFS].  ^In other words, the filename
  5004   5047   ** will be an absolute pathname, even if the filename used
  5005   5048   ** to open the database originally was a URI or relative pathname.
  5006   5049   */
  5007   5050   SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
  5008   5051   
         5052  +/*
         5053  +** CAPI3REF: Determine if a database is read-only
         5054  +**
         5055  +** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
         5056  +** of connection D is read-only, 0 if it is read/write, or -1 if N is not
         5057  +** the name of a database on connection D.
         5058  +*/
         5059  +SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
         5060  +
  5009   5061   /*
  5010   5062   ** CAPI3REF: Find the next prepared statement
  5011   5063   **
  5012   5064   ** ^This interface returns a pointer to the next [prepared statement] after
  5013   5065   ** pStmt associated with the [database connection] pDb.  ^If pStmt is NULL
  5014   5066   ** then this interface returns a pointer to the first prepared statement
  5015   5067   ** associated with the database connection pDb.  ^If no prepared statement
................................................................................
  6756   6808   ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
  6757   6809   ** handle invalid, and will not use it with any other sqlite3_pcache_methods2
  6758   6810   ** functions.
  6759   6811   **
  6760   6812   ** [[the xShrink() page cache method]]
  6761   6813   ** ^SQLite invokes the xShrink() method when it wants the page cache to
  6762   6814   ** free up as much of heap memory as possible.  The page cache implementation
  6763         -** is not obligated to free any memory, but well-behaved implementions should
         6815  +** is not obligated to free any memory, but well-behaved implementations should
  6764   6816   ** do their best.
  6765   6817   */
  6766   6818   typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;
  6767   6819   struct sqlite3_pcache_methods2 {
  6768   6820     int iVersion;
  6769   6821     void *pArg;
  6770   6822     int (*xInit)(void*);
................................................................................
  7127   7179     void *pNotifyArg                            /* Argument to pass to xNotify */
  7128   7180   );
  7129   7181   
  7130   7182   
  7131   7183   /*
  7132   7184   ** CAPI3REF: String Comparison
  7133   7185   **
  7134         -** ^The [sqlite3_strnicmp()] API allows applications and extensions to
  7135         -** compare the contents of two buffers containing UTF-8 strings in a
  7136         -** case-independent fashion, using the same definition of case independence 
  7137         -** that SQLite uses internally when comparing identifiers.
         7186  +** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
         7187  +** and extensions to compare the contents of two buffers containing UTF-8
         7188  +** strings in a case-independent fashion, using the same definition of "case
         7189  +** independence" that SQLite uses internally when comparing identifiers.
  7138   7190   */
         7191  +SQLITE_API int sqlite3_stricmp(const char *, const char *);
  7139   7192   SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
  7140   7193   
  7141   7194   /*
  7142   7195   ** CAPI3REF: Error Logging Interface
  7143   7196   **
  7144   7197   ** ^The [sqlite3_log()] interface writes a message into the error log
  7145   7198   ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
................................................................................
  8008   8061   ** A convenience macro that returns the number of elements in
  8009   8062   ** an array.
  8010   8063   */
  8011   8064   #define ArraySize(X)    ((int)(sizeof(X)/sizeof(X[0])))
  8012   8065   
  8013   8066   /*
  8014   8067   ** The following value as a destructor means to use sqlite3DbFree().
  8015         -** This is an internal extension to SQLITE_STATIC and SQLITE_TRANSIENT.
         8068  +** The sqlite3DbFree() routine requires two parameters instead of the 
         8069  +** one parameter that destructors normally want.  So we have to introduce 
         8070  +** this magic value that the code knows to handle differently.  Any 
         8071  +** pointer will work here as long as it is distinct from SQLITE_STATIC
         8072  +** and SQLITE_TRANSIENT.
  8016   8073   */
  8017         -#define SQLITE_DYNAMIC   ((sqlite3_destructor_type)sqlite3DbFree)
         8074  +#define SQLITE_DYNAMIC   ((sqlite3_destructor_type)sqlite3MallocSize)
  8018   8075   
  8019   8076   /*
  8020   8077   ** When SQLITE_OMIT_WSD is defined, it means that the target platform does
  8021   8078   ** not support Writable Static Data (WSD) such as global and static variables.
  8022   8079   ** All variables must either be on the stack or dynamically allocated from
  8023   8080   ** the heap.  When WSD is unsupported, the variable declarations scattered
  8024   8081   ** throughout the SQLite code must become constants instead.  The SQLITE_WSD
................................................................................
  8170   8227   /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
  8171   8228   ** following values.
  8172   8229   **
  8173   8230   ** NOTE:  These values must match the corresponding PAGER_ values in
  8174   8231   ** pager.h.
  8175   8232   */
  8176   8233   #define BTREE_OMIT_JOURNAL  1  /* Do not create or use a rollback journal */
  8177         -#define BTREE_NO_READLOCK   2  /* Omit readlocks on readonly files */
  8178         -#define BTREE_MEMORY        4  /* This is an in-memory DB */
  8179         -#define BTREE_SINGLE        8  /* The file contains at most 1 b-tree */
  8180         -#define BTREE_UNORDERED    16  /* Use of a hash implementation is OK */
         8234  +#define BTREE_MEMORY        2  /* This is an in-memory DB */
         8235  +#define BTREE_SINGLE        4  /* The file contains at most 1 b-tree */
         8236  +#define BTREE_UNORDERED     8  /* Use of a hash implementation is OK */
  8181   8237   
  8182   8238   SQLITE_PRIVATE int sqlite3BtreeClose(Btree*);
  8183   8239   SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int);
  8184   8240   SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int,int);
  8185   8241   SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
  8186   8242   SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
  8187   8243   SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
................................................................................
  8191   8247   SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*);
  8192   8248   SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
  8193   8249   SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
  8194   8250   SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
  8195   8251   SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
  8196   8252   SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
  8197   8253   SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
  8198         -SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*);
         8254  +SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int);
  8199   8255   SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
  8200   8256   SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
  8201   8257   SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
  8202   8258   SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
  8203   8259   SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
  8204   8260   SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
  8205   8261   SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree);
................................................................................
  8846   8902   
  8847   8903   /*
  8848   8904   ** Allowed values for the flags parameter to sqlite3PagerOpen().
  8849   8905   **
  8850   8906   ** NOTE: These values must match the corresponding BTREE_ values in btree.h.
  8851   8907   */
  8852   8908   #define PAGER_OMIT_JOURNAL  0x0001    /* Do not use a rollback journal */
  8853         -#define PAGER_NO_READLOCK   0x0002    /* Omit readlocks on readonly files */
  8854         -#define PAGER_MEMORY        0x0004    /* In-memory database */
         8909  +#define PAGER_MEMORY        0x0002    /* In-memory database */
  8855   8910   
  8856   8911   /*
  8857   8912   ** Valid values for the second argument to sqlite3PagerLockingMode().
  8858   8913   */
  8859   8914   #define PAGER_LOCKINGMODE_QUERY      -1
  8860   8915   #define PAGER_LOCKINGMODE_NORMAL      0
  8861   8916   #define PAGER_LOCKINGMODE_EXCLUSIVE   1
................................................................................
  8932   8987   SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
  8933   8988   
  8934   8989   SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int, int*, int*);
  8935   8990   SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager);
  8936   8991   SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager);
  8937   8992   SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
  8938   8993   SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager);
         8994  +#ifdef SQLITE_ENABLE_ZIPVFS
         8995  +SQLITE_PRIVATE   int sqlite3PagerWalFramesize(Pager *pPager);
         8996  +#endif
  8939   8997   
  8940   8998   /* Functions used to query pager state and configuration. */
  8941   8999   SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
  8942   9000   SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
  8943   9001   SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
  8944   9002   SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
  8945   9003   SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
................................................................................
  9004   9062   ** structure.
  9005   9063   */
  9006   9064   struct PgHdr {
  9007   9065     sqlite3_pcache_page *pPage;    /* Pcache object page handle */
  9008   9066     void *pData;                   /* Page data */
  9009   9067     void *pExtra;                  /* Extra content */
  9010   9068     PgHdr *pDirty;                 /* Transient list of dirty pages */
  9011         -  Pgno pgno;                     /* Page number for this page */
  9012   9069     Pager *pPager;                 /* The pager this page is part of */
         9070  +  Pgno pgno;                     /* Page number for this page */
  9013   9071   #ifdef SQLITE_CHECK_PAGES
  9014   9072     u32 pageHash;                  /* Hash of page content */
  9015   9073   #endif
  9016   9074     u16 flags;                     /* PGHDR flags defined below */
  9017   9075   
  9018   9076     /**********************************************************************
  9019   9077     ** Elements above are public.  All that follows is private to pcache.c
................................................................................
  9233   9291   # define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP)
  9234   9292   #else
  9235   9293   # define SQLITE_TEMPNAME_SIZE 200
  9236   9294   #endif
  9237   9295   
  9238   9296   /*
  9239   9297   ** Determine if we are dealing with Windows NT.
         9298  +**
         9299  +** We ought to be able to determine if we are compiling for win98 or winNT
         9300  +** using the _WIN32_WINNT macro as follows:
         9301  +**
         9302  +** #if defined(_WIN32_WINNT)
         9303  +** # define SQLITE_OS_WINNT 1
         9304  +** #else
         9305  +** # define SQLITE_OS_WINNT 0
         9306  +** #endif
         9307  +**
         9308  +** However, vs2005 does not set _WIN32_WINNT by default, as it ought to,
         9309  +** so the above test does not work.  We'll just assume that everything is
         9310  +** winNT unless the programmer explicitly says otherwise by setting
         9311  +** SQLITE_OS_WINNT to 0.
  9240   9312   */
  9241         -#if defined(_WIN32_WINNT)
         9313  +#if SQLITE_OS_WIN && !defined(SQLITE_OS_WINNT)
  9242   9314   # define SQLITE_OS_WINNT 1
  9243         -#else
  9244         -# define SQLITE_OS_WINNT 0
  9245   9315   #endif
  9246   9316   
  9247   9317   /*
  9248   9318   ** Determine if we are dealing with WindowsCE - which has a much
  9249   9319   ** reduced API.
  9250   9320   */
  9251   9321   #if defined(_WIN32_WCE)
................................................................................
  9635   9705   */
  9636   9706   struct FuncDefHash {
  9637   9707     FuncDef *a[23];       /* Hash table for functions */
  9638   9708   };
  9639   9709   
  9640   9710   /*
  9641   9711   ** Each database connection is an instance of the following structure.
  9642         -**
  9643         -** The sqlite.lastRowid records the last insert rowid generated by an
  9644         -** insert statement.  Inserts on views do not affect its value.  Each
  9645         -** trigger has its own context, so that lastRowid can be updated inside
  9646         -** triggers as usual.  The previous value will be restored once the trigger
  9647         -** exits.  Upon entering a before or instead of trigger, lastRowid is no
  9648         -** longer (since after version 2.8.12) reset to -1.
  9649         -**
  9650         -** The sqlite.nChange does not count changes within triggers and keeps no
  9651         -** context.  It is reset at start of sqlite3_exec.
  9652         -** The sqlite.lsChange represents the number of changes made by the last
  9653         -** insert, update, or delete statement.  It remains constant throughout the
  9654         -** length of a statement and is then updated by OP_SetCounts.  It keeps a
  9655         -** context stack just like lastRowid so that the count of changes
  9656         -** within a trigger is not seen outside the trigger.  Changes to views do not
  9657         -** affect the value of lsChange.
  9658         -** The sqlite.csChange keeps track of the number of current changes (since
  9659         -** the last statement) and is used to update sqlite_lsChange.
  9660         -**
  9661         -** The member variables sqlite.errCode, sqlite.zErrMsg and sqlite.zErrMsg16
  9662         -** store the most recent error code and, if applicable, string. The
  9663         -** internal function sqlite3Error() is used to set these variables
  9664         -** consistently.
  9665   9712   */
  9666   9713   struct sqlite3 {
  9667   9714     sqlite3_vfs *pVfs;            /* OS Interface */
  9668         -  int nDb;                      /* Number of backends currently in use */
         9715  +  struct Vdbe *pVdbe;           /* List of active virtual machines */
         9716  +  CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */
         9717  +  sqlite3_mutex *mutex;         /* Connection mutex */
  9669   9718     Db *aDb;                      /* All backends */
         9719  +  int nDb;                      /* Number of backends currently in use */
  9670   9720     int flags;                    /* Miscellaneous flags. See below */
         9721  +  i64 lastRowid;                /* ROWID of most recent insert (see above) */
  9671   9722     unsigned int openFlags;       /* Flags passed to sqlite3_vfs.xOpen() */
  9672   9723     int errCode;                  /* Most recent error code (SQLITE_*) */
  9673   9724     int errMask;                  /* & result codes with this before returning */
  9674   9725     u8 autoCommit;                /* The auto-commit flag. */
  9675   9726     u8 temp_store;                /* 1: file 2: memory 0: default */
  9676   9727     u8 mallocFailed;              /* True if we have seen a malloc failure */
  9677   9728     u8 dfltLockMode;              /* Default locking-mode for attached dbs */
  9678   9729     signed char nextAutovac;      /* Autovac setting after VACUUM if >=0 */
  9679   9730     u8 suppressErr;               /* Do not issue error messages if true */
  9680   9731     u8 vtabOnConflict;            /* Value to return for s3_vtab_on_conflict() */
         9732  +  u8 isTransactionSavepoint;    /* True if the outermost savepoint is a TS */
  9681   9733     int nextPagesize;             /* Pagesize after VACUUM if >0 */
  9682         -  int nTable;                   /* Number of tables in the database */
  9683         -  CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */
  9684         -  i64 lastRowid;                /* ROWID of most recent insert (see above) */
  9685   9734     u32 magic;                    /* Magic number for detect library misuse */
  9686   9735     int nChange;                  /* Value returned by sqlite3_changes() */
  9687   9736     int nTotalChange;             /* Value returned by sqlite3_total_changes() */
  9688         -  sqlite3_mutex *mutex;         /* Connection mutex */
  9689   9737     int aLimit[SQLITE_N_LIMIT];   /* Limits */
  9690   9738     struct sqlite3InitInfo {      /* Information used during initialization */
  9691         -    int iDb;                    /* When back is being initialized */
  9692   9739       int newTnum;                /* Rootpage of table being initialized */
         9740  +    u8 iDb;                     /* Which db file is being initialized */
  9693   9741       u8 busy;                    /* TRUE if currently initializing */
  9694   9742       u8 orphanTrigger;           /* Last statement is orphaned TEMP trigger */
  9695   9743     } init;
  9696         -  int nExtension;               /* Number of loaded extensions */
  9697         -  void **aExtension;            /* Array of shared library handles */
  9698         -  struct Vdbe *pVdbe;           /* List of active virtual machines */
  9699   9744     int activeVdbeCnt;            /* Number of VDBEs currently executing */
  9700   9745     int writeVdbeCnt;             /* Number of active VDBEs that are writing */
  9701   9746     int vdbeExecCnt;              /* Number of nested calls to VdbeExec() */
         9747  +  int nExtension;               /* Number of loaded extensions */
         9748  +  void **aExtension;            /* Array of shared library handles */
  9702   9749     void (*xTrace)(void*,const char*);        /* Trace function */
  9703   9750     void *pTraceArg;                          /* Argument to the trace function */
  9704   9751     void (*xProfile)(void*,const char*,u64);  /* Profiling function */
  9705   9752     void *pProfileArg;                        /* Argument to profile function */
  9706   9753     void *pCommitArg;                 /* Argument to xCommitCallback() */   
  9707   9754     int (*xCommitCallback)(void*);    /* Invoked at every commit. */
  9708   9755     void *pRollbackArg;               /* Argument to xRollbackCallback() */   
................................................................................
  9731   9778   #endif
  9732   9779   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
  9733   9780     int (*xProgress)(void *);     /* The progress callback */
  9734   9781     void *pProgressArg;           /* Argument to the progress callback */
  9735   9782     int nProgressOps;             /* Number of opcodes for progress callback */
  9736   9783   #endif
  9737   9784   #ifndef SQLITE_OMIT_VIRTUALTABLE
         9785  +  int nVTrans;                  /* Allocated size of aVTrans */
  9738   9786     Hash aModule;                 /* populated by sqlite3_create_module() */
  9739   9787     VtabCtx *pVtabCtx;            /* Context for active vtab connect/create */
  9740   9788     VTable **aVTrans;             /* Virtual tables with open transactions */
  9741         -  int nVTrans;                  /* Allocated size of aVTrans */
  9742   9789     VTable *pDisconnect;    /* Disconnect these in next sqlite3_prepare() */
  9743   9790   #endif
  9744   9791     FuncDefHash aFunc;            /* Hash table of connection functions */
  9745   9792     Hash aCollSeq;                /* All collating sequences */
  9746   9793     BusyHandler busyHandler;      /* Busy callback */
  9747         -  int busyTimeout;              /* Busy handler timeout, in msec */
  9748   9794     Db aDbStatic[2];              /* Static space for the 2 default backends */
  9749   9795     Savepoint *pSavepoint;        /* List of active savepoints */
         9796  +  int busyTimeout;              /* Busy handler timeout, in msec */
  9750   9797     int nSavepoint;               /* Number of non-transaction savepoints */
  9751   9798     int nStatement;               /* Number of nested statement-transactions  */
  9752         -  u8 isTransactionSavepoint;    /* True if the outermost savepoint is a TS */
  9753   9799     i64 nDeferredCons;            /* Net deferred constraints this transaction. */
  9754   9800     int *pnBytesFreed;            /* If not NULL, increment this in DbFree() */
  9755   9801   
  9756   9802   #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
  9757   9803     /* The following variables are all protected by the STATIC_MASTER 
  9758   9804     ** mutex, not by sqlite3.mutex. They are used by code in notify.c. 
  9759   9805     **
................................................................................
  9788   9834                                             /*   DELETE, or UPDATE and return */
  9789   9835                                             /*   the count using a callback. */
  9790   9836   #define SQLITE_NullCallback   0x00002000  /* Invoke the callback once if the */
  9791   9837                                             /*   result set is empty */
  9792   9838   #define SQLITE_SqlTrace       0x00004000  /* Debug print SQL as it executes */
  9793   9839   #define SQLITE_VdbeListing    0x00008000  /* Debug listings of VDBE programs */
  9794   9840   #define SQLITE_WriteSchema    0x00010000  /* OK to update SQLITE_MASTER */
  9795         -#define SQLITE_NoReadlock     0x00020000  /* Readlocks are omitted when 
  9796         -                                          ** accessing read-only databases */
         9841  +                         /*   0x00020000  Unused */
  9797   9842   #define SQLITE_IgnoreChecks   0x00040000  /* Do not enforce check constraints */
  9798   9843   #define SQLITE_ReadUncommitted 0x0080000  /* For shared-cache mode */
  9799   9844   #define SQLITE_LegacyFileFmt  0x00100000  /* Create new databases in format 1 */
  9800   9845   #define SQLITE_FullFSync      0x00200000  /* Use full fsync on the backend */
  9801   9846   #define SQLITE_CkptFullFSync  0x00400000  /* Use full fsync for checkpoint */
  9802   9847   #define SQLITE_RecoveryMode   0x00800000  /* Ignore schema errors */
  9803   9848   #define SQLITE_ReverseOrder   0x01000000  /* Reverse unordered SELECTs */
................................................................................
  9878   9923   /*
  9879   9924   ** Possible values for FuncDef.flags
  9880   9925   */
  9881   9926   #define SQLITE_FUNC_LIKE     0x01 /* Candidate for the LIKE optimization */
  9882   9927   #define SQLITE_FUNC_CASE     0x02 /* Case-sensitive LIKE-type function */
  9883   9928   #define SQLITE_FUNC_EPHEM    0x04 /* Ephemeral.  Delete with VDBE */
  9884   9929   #define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */
  9885         -#define SQLITE_FUNC_PRIVATE  0x10 /* Allowed for internal use only */
  9886   9930   #define SQLITE_FUNC_COUNT    0x20 /* Built-in count(*) aggregate */
  9887   9931   #define SQLITE_FUNC_COALESCE 0x40 /* Built-in coalesce() or ifnull() function */
  9888   9932   
  9889   9933   /*
  9890   9934   ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
  9891   9935   ** used to create the initializers for the FuncDef structures.
  9892   9936   **
................................................................................
 10161  10205   ** Allowed values for Tabe.tabFlags.
 10162  10206   */
 10163  10207   #define TF_Readonly        0x01    /* Read-only system table */
 10164  10208   #define TF_Ephemeral       0x02    /* An ephemeral table */
 10165  10209   #define TF_HasPrimaryKey   0x04    /* Table has a primary key */
 10166  10210   #define TF_Autoincrement   0x08    /* Integer primary key is autoincrement */
 10167  10211   #define TF_Virtual         0x10    /* Is a virtual table */
 10168         -#define TF_NeedMetadata    0x20    /* aCol[].zType and aCol[].pColl missing */
 10169         -
 10170  10212   
 10171  10213   
 10172  10214   /*
 10173  10215   ** Test to see whether or not a table is a virtual table.  This is
 10174  10216   ** done as a macro so that it will be optimized out when virtual
 10175  10217   ** table support is omitted from the build.
 10176  10218   */
................................................................................
 10324  10366   ** it means this is not a unique index.  Otherwise it is a unique index
 10325  10367   ** and the value of Index.onError indicate the which conflict resolution 
 10326  10368   ** algorithm to employ whenever an attempt is made to insert a non-unique
 10327  10369   ** element.
 10328  10370   */
 10329  10371   struct Index {
 10330  10372     char *zName;     /* Name of this index */
 10331         -  int nColumn;     /* Number of columns in the table used by this index */
 10332  10373     int *aiColumn;   /* Which columns are used by this index.  1st is 0 */
 10333  10374     tRowcnt *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
 10334  10375     Table *pTable;   /* The SQL table being indexed */
 10335         -  int tnum;        /* Page containing root of this index in database file */
 10336         -  u8 onError;      /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
 10337         -  u8 autoIndex;    /* True if is automatically created (ex: by UNIQUE) */
 10338         -  u8 bUnordered;   /* Use this index for == or IN queries only */
 10339  10376     char *zColAff;   /* String defining the affinity of each column */
 10340  10377     Index *pNext;    /* The next index associated with the same table */
 10341  10378     Schema *pSchema; /* Schema containing this index */
 10342  10379     u8 *aSortOrder;  /* Array of size Index.nColumn. True==DESC, False==ASC */
 10343  10380     char **azColl;   /* Array of collation sequence names for index */
        10381  +  int nColumn;     /* Number of columns in the table used by this index */
        10382  +  int tnum;        /* Page containing root of this index in database file */
        10383  +  u8 onError;      /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
        10384  +  u8 autoIndex;    /* True if is automatically created (ex: by UNIQUE) */
        10385  +  u8 bUnordered;   /* Use this index for == or IN queries only */
 10344  10386   #ifdef SQLITE_ENABLE_STAT3
 10345  10387     int nSample;             /* Number of elements in aSample[] */
 10346  10388     tRowcnt avgEq;           /* Average nEq value for key values not in aSample */
 10347  10389     IndexSample *aSample;    /* Samples of the left-most key */
 10348  10390   #endif
 10349  10391   };
 10350  10392   
................................................................................
 10395  10437   struct AggInfo {
 10396  10438     u8 directMode;          /* Direct rendering mode means take data directly
 10397  10439                             ** from source tables rather than from accumulators */
 10398  10440     u8 useSortingIdx;       /* In direct mode, reference the sorting index rather
 10399  10441                             ** than the source table */
 10400  10442     int sortingIdx;         /* Cursor number of the sorting index */
 10401  10443     int sortingIdxPTab;     /* Cursor number of pseudo-table */
 10402         -  ExprList *pGroupBy;     /* The group by clause */
 10403  10444     int nSortingColumn;     /* Number of columns in the sorting index */
        10445  +  ExprList *pGroupBy;     /* The group by clause */
 10404  10446     struct AggInfo_col {    /* For each column used in source tables */
 10405  10447       Table *pTab;             /* Source table */
 10406  10448       int iTable;              /* Cursor number of the source table */
 10407  10449       int iColumn;             /* Column number within the source table */
 10408  10450       int iSorterColumn;       /* Column number in the sorting index */
 10409  10451       int iMem;                /* Memory location that acts as accumulator */
 10410  10452       Expr *pExpr;             /* The original expression */
 10411  10453     } *aCol;
 10412  10454     int nColumn;            /* Number of used entries in aCol[] */
 10413         -  int nColumnAlloc;       /* Number of slots allocated for aCol[] */
 10414  10455     int nAccumulator;       /* Number of columns that show through to the output.
 10415  10456                             ** Additional columns are used only as parameters to
 10416  10457                             ** aggregate functions */
 10417  10458     struct AggInfo_func {   /* For each aggregate function */
 10418  10459       Expr *pExpr;             /* Expression encoding the function */
 10419  10460       FuncDef *pFunc;          /* The aggregate function implementation */
 10420  10461       int iMem;                /* Memory location that acts as accumulator */
 10421  10462       int iDistinct;           /* Ephemeral table used to enforce DISTINCT */
 10422  10463     } *aFunc;
 10423  10464     int nFunc;              /* Number of entries in aFunc[] */
 10424         -  int nFuncAlloc;         /* Number of slots allocated for aFunc[] */
 10425  10465   };
 10426  10466   
 10427  10467   /*
 10428  10468   ** The datatype ynVar is a signed integer, either 16-bit or 32-bit.
 10429  10469   ** Usually it is 16-bits.  But if SQLITE_MAX_VARIABLE_NUMBER is greater
 10430  10470   ** than 32767 we have to make it 32-bit.  16-bit is preferred because
 10431  10471   ** it uses less memory in the Expr object, which is a big memory user
................................................................................
 10614  10654   ** as the list of "expr AS ID" fields following a "SELECT" or in the
 10615  10655   ** list of "ID = expr" items in an UPDATE.  A list of expressions can
 10616  10656   ** also be used as the argument to a function, in which case the a.zName
 10617  10657   ** field is not used.
 10618  10658   */
 10619  10659   struct ExprList {
 10620  10660     int nExpr;             /* Number of expressions on the list */
 10621         -  int nAlloc;            /* Number of entries allocated below */
 10622  10661     int iECursor;          /* VDBE Cursor associated with this ExprList */
 10623         -  struct ExprList_item {
        10662  +  struct ExprList_item { /* For each expression in the list */
 10624  10663       Expr *pExpr;           /* The list of expressions */
 10625  10664       char *zName;           /* Token associated with this expression */
 10626  10665       char *zSpan;           /* Original text of the expression */
 10627  10666       u8 sortOrder;          /* 1 for DESC or 0 for ASC */
 10628  10667       u8 done;               /* A flag to indicate when processing is finished */
 10629  10668       u16 iOrderByCol;       /* For ORDER BY, column number in result set */
 10630  10669       u16 iAlias;            /* Index into Parse.aAlias[] for zName */
 10631         -  } *a;                  /* One entry for each expression */
        10670  +  } *a;                  /* Alloc a power of two greater or equal to nExpr */
 10632  10671   };
 10633  10672   
 10634  10673   /*
 10635  10674   ** An instance of this structure is used by the parser to record both
 10636  10675   ** the parse tree for an expression and the span of input text for an
 10637  10676   ** expression.
 10638  10677   */
................................................................................
 10659  10698   */
 10660  10699   struct IdList {
 10661  10700     struct IdList_item {
 10662  10701       char *zName;      /* Name of the identifier */
 10663  10702       int idx;          /* Index in some Table.aCol[] of a column named zName */
 10664  10703     } *a;
 10665  10704     int nId;         /* Number of identifiers on the list */
 10666         -  int nAlloc;      /* Number of entries allocated for a[] below */
 10667  10705   };
 10668  10706   
 10669  10707   /*
 10670  10708   ** The bitmask datatype defined below is used for various optimizations.
 10671  10709   **
 10672  10710   ** Changing this from a 64-bit to a 32-bit type limits the number of
 10673  10711   ** tables in a join to 32 instead of 64.  But it also reduces the size
................................................................................
 10903  10941   ** sequences for the ORDER BY clause.
 10904  10942   */
 10905  10943   struct Select {
 10906  10944     ExprList *pEList;      /* The fields of the result */
 10907  10945     u8 op;                 /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
 10908  10946     char affinity;         /* MakeRecord with this affinity for SRT_Set */
 10909  10947     u16 selFlags;          /* Various SF_* values */
        10948  +  int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */
        10949  +  int addrOpenEphm[3];   /* OP_OpenEphem opcodes related to this select */
        10950  +  double nSelectRow;     /* Estimated number of result rows */
 10910  10951     SrcList *pSrc;         /* The FROM clause */
 10911  10952     Expr *pWhere;          /* The WHERE clause */
 10912  10953     ExprList *pGroupBy;    /* The GROUP BY clause */
 10913  10954     Expr *pHaving;         /* The HAVING clause */
 10914  10955     ExprList *pOrderBy;    /* The ORDER BY clause */
 10915  10956     Select *pPrior;        /* Prior select in a compound select statement */
 10916  10957     Select *pNext;         /* Next select to the left in a compound */
 10917  10958     Select *pRightmost;    /* Right-most select in a compound select statement */
 10918  10959     Expr *pLimit;          /* LIMIT expression. NULL means not used. */
 10919  10960     Expr *pOffset;         /* OFFSET expression. NULL means not used. */
 10920         -  int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */
 10921         -  int addrOpenEphm[3];   /* OP_OpenEphem opcodes related to this select */
 10922         -  double nSelectRow;     /* Estimated number of result rows */
 10923  10961   };
 10924  10962   
 10925  10963   /*
 10926  10964   ** Allowed values for Select.selFlags.  The "SF" prefix stands for
 10927  10965   ** "Select Flag".
 10928  10966   */
 10929  10967   #define SF_Distinct        0x01  /* Output should be DISTINCT */
 10930  10968   #define SF_Resolved        0x02  /* Identifiers have been resolved */
 10931  10969   #define SF_Aggregate       0x04  /* Contains aggregate functions */
 10932  10970   #define SF_UsesEphemeral   0x08  /* Uses the OpenEphemeral opcode */
 10933  10971   #define SF_Expanded        0x10  /* sqlite3SelectExpand() called on this */
 10934  10972   #define SF_HasTypeInfo     0x20  /* FROM subqueries have Table metadata */
 10935  10973   #define SF_UseSorter       0x40  /* Sort using a sorter */
        10974  +#define SF_Values          0x80  /* Synthesized from VALUES clause */
 10936  10975   
 10937  10976   
 10938  10977   /*
 10939  10978   ** The results of a select can be distributed in several ways.  The
 10940  10979   ** "SRT" prefix means "SELECT Result Type".
 10941  10980   */
 10942  10981   #define SRT_Union        1  /* Store result as keys in an index */
................................................................................
 11006  11045   ** The TriggerPrg.aColmask[0] variable is set to a mask of old.* columns
 11007  11046   ** accessed (or set to 0 for triggers fired as a result of INSERT 
 11008  11047   ** statements). Similarly, the TriggerPrg.aColmask[1] variable is set to
 11009  11048   ** a mask of new.* columns used by the program.
 11010  11049   */
 11011  11050   struct TriggerPrg {
 11012  11051     Trigger *pTrigger;      /* Trigger this program was coded from */
 11013         -  int orconf;             /* Default ON CONFLICT policy */
        11052  +  TriggerPrg *pNext;      /* Next entry in Parse.pTriggerPrg list */
 11014  11053     SubProgram *pProgram;   /* Program implementing pTrigger/orconf */
        11054  +  int orconf;             /* Default ON CONFLICT policy */
 11015  11055     u32 aColmask[2];        /* Masks of old.*, new.* columns accessed */
 11016         -  TriggerPrg *pNext;      /* Next entry in Parse.pTriggerPrg list */
 11017  11056   };
 11018  11057   
 11019  11058   /*
 11020  11059   ** The yDbMask datatype for the bitmask of all attached databases.
 11021  11060   */
 11022  11061   #if SQLITE_MAX_ATTACHED>30
 11023  11062     typedef sqlite3_uint64 yDbMask;
................................................................................
 11039  11078   ** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are
 11040  11079   ** used to store the set of table-locks required by the statement being
 11041  11080   ** compiled. Function sqlite3TableLock() is used to add entries to the
 11042  11081   ** list.
 11043  11082   */
 11044  11083   struct Parse {
 11045  11084     sqlite3 *db;         /* The main database structure */
 11046         -  int rc;              /* Return code from execution */
 11047  11085     char *zErrMsg;       /* An error message */
 11048  11086     Vdbe *pVdbe;         /* An engine for executing database bytecode */
        11087  +  int rc;              /* Return code from execution */
 11049  11088     u8 colNamesSet;      /* TRUE after OP_ColumnName has been issued to pVdbe */
 11050  11089     u8 checkSchema;      /* Causes schema cookie check after an error */
 11051  11090     u8 nested;           /* Number of nested calls to the parser/code generator */
 11052  11091     u8 nTempReg;         /* Number of temporary registers in aTempReg[] */
 11053  11092     u8 nTempInUse;       /* Number of aTempReg[] currently checked out */
        11093  +  u8 nColCache;        /* Number of entries in aColCache[] */
        11094  +  u8 iColCache;        /* Next entry in aColCache[] to replace */
        11095  +  u8 isMultiWrite;     /* True if statement may modify/insert multiple rows */
        11096  +  u8 mayAbort;         /* True if statement may throw an ABORT exception */
 11054  11097     int aTempReg[8];     /* Holding area for temporary registers */
 11055  11098     int nRangeReg;       /* Size of the temporary register block */
 11056  11099     int iRangeReg;       /* First register in temporary register block */
 11057  11100     int nErr;            /* Number of errors seen */
 11058  11101     int nTab;            /* Number of previously allocated VDBE cursors */
 11059  11102     int nMem;            /* Number of memory cells used so far */
 11060  11103     int nSet;            /* Number of sets used so far */
 11061  11104     int nOnce;           /* Number of OP_Once instructions so far */
 11062  11105     int ckBase;          /* Base register of data during check constraints */
 11063  11106     int iCacheLevel;     /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
 11064  11107     int iCacheCnt;       /* Counter used to generate aColCache[].lru values */
 11065         -  u8 nColCache;        /* Number of entries in aColCache[] */
 11066         -  u8 iColCache;        /* Next entry in aColCache[] to replace */
 11067  11108     struct yColCache {
 11068  11109       int iTable;           /* Table cursor number */
 11069  11110       int iColumn;          /* Table column number */
 11070  11111       u8 tempReg;           /* iReg is a temp register that needs to be freed */
 11071  11112       int iLevel;           /* Nesting level */
 11072  11113       int iReg;             /* Reg with value of this column. 0 means none. */
 11073  11114       int lru;              /* Least recently used entry has the smallest value */
 11074  11115     } aColCache[SQLITE_N_COLCACHE];  /* One for each column cache entry */
 11075  11116     yDbMask writeMask;   /* Start a write transaction on these databases */
 11076  11117     yDbMask cookieMask;  /* Bitmask of schema verified databases */
 11077         -  u8 isMultiWrite;     /* True if statement may affect/insert multiple rows */
 11078         -  u8 mayAbort;         /* True if statement may throw an ABORT exception */
 11079  11118     int cookieGoto;      /* Address of OP_Goto to cookie verifier subroutine */
 11080  11119     int cookieValue[SQLITE_MAX_ATTACHED+2];  /* Values of cookies to verify */
        11120  +  int regRowid;        /* Register holding rowid of CREATE TABLE entry */
        11121  +  int regRoot;         /* Register holding root page number for new objects */
        11122  +  int nMaxArg;         /* Max args passed to user function by sub-program */
 11081  11123   #ifndef SQLITE_OMIT_SHARED_CACHE
 11082  11124     int nTableLock;        /* Number of locks in aTableLock */
 11083  11125     TableLock *aTableLock; /* Required table locks for shared-cache mode */
 11084  11126   #endif
 11085         -  int regRowid;        /* Register holding rowid of CREATE TABLE entry */
 11086         -  int regRoot;         /* Register holding root page number for new objects */
 11087  11127     AutoincInfo *pAinc;  /* Information about AUTOINCREMENT counters */
 11088         -  int nMaxArg;         /* Max args passed to user function by sub-program */
 11089  11128   
 11090  11129     /* Information used while coding trigger programs. */
 11091  11130     Parse *pToplevel;    /* Parse structure for main program (or NULL) */
 11092  11131     Table *pTriggerTab;  /* Table triggers are being coded for */
        11132  +  double nQueryLoop;   /* Estimated number of iterations of a query */
 11093  11133     u32 oldmask;         /* Mask of old.* columns referenced */
 11094  11134     u32 newmask;         /* Mask of new.* columns referenced */
 11095  11135     u8 eTriggerOp;       /* TK_UPDATE, TK_INSERT or TK_DELETE */
 11096  11136     u8 eOrconf;          /* Default ON CONFLICT policy for trigger steps */
 11097  11137     u8 disableTriggers;  /* True to disable triggers */
 11098         -  double nQueryLoop;   /* Estimated number of iterations of a query */
 11099  11138   
 11100  11139     /* Above is constant between recursions.  Below is reset before and after
 11101  11140     ** each recursion */
 11102  11141   
 11103         -  int nVar;            /* Number of '?' variables seen in the SQL so far */
 11104         -  int nzVar;           /* Number of available slots in azVar[] */
 11105         -  char **azVar;        /* Pointers to names of parameters */
 11106         -  Vdbe *pReprepare;    /* VM being reprepared (sqlite3Reprepare()) */
 11107         -  int nAlias;          /* Number of aliased result set columns */
 11108         -  int *aAlias;         /* Register used to hold aliased result */
 11109         -  u8 explain;          /* True if the EXPLAIN flag is found on the query */
 11110         -  Token sNameToken;    /* Token with unqualified schema object name */
 11111         -  Token sLastToken;    /* The last token parsed */
 11112         -  const char *zTail;   /* All SQL text past the last semicolon parsed */
 11113         -  Table *pNewTable;    /* A table being constructed by CREATE TABLE */
        11142  +  int nVar;                 /* Number of '?' variables seen in the SQL so far */
        11143  +  int nzVar;                /* Number of available slots in azVar[] */
        11144  +  u8 explain;               /* True if the EXPLAIN flag is found on the query */
        11145  +#ifndef SQLITE_OMIT_VIRTUALTABLE
        11146  +  u8 declareVtab;           /* True if inside sqlite3_declare_vtab() */
        11147  +  int nVtabLock;            /* Number of virtual tables to lock */
        11148  +#endif
        11149  +  int nAlias;               /* Number of aliased result set columns */
        11150  +  int nHeight;              /* Expression tree height of current sub-select */
        11151  +#ifndef SQLITE_OMIT_EXPLAIN
        11152  +  int iSelectId;            /* ID of current select for EXPLAIN output */
        11153  +  int iNextSelectId;        /* Next available select ID for EXPLAIN output */
        11154  +#endif
        11155  +  char **azVar;             /* Pointers to names of parameters */
        11156  +  Vdbe *pReprepare;         /* VM being reprepared (sqlite3Reprepare()) */
        11157  +  int *aAlias;              /* Register used to hold aliased result */
        11158  +  const char *zTail;        /* All SQL text past the last semicolon parsed */
        11159  +  Table *pNewTable;         /* A table being constructed by CREATE TABLE */
 11114  11160     Trigger *pNewTrigger;     /* Trigger under construct by a CREATE TRIGGER */
 11115  11161     const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
        11162  +  Token sNameToken;         /* Token with unqualified schema object name */
        11163  +  Token sLastToken;         /* The last token parsed */
 11116  11164   #ifndef SQLITE_OMIT_VIRTUALTABLE
 11117         -  Token sArg;                /* Complete text of a module argument */
 11118         -  u8 declareVtab;            /* True if inside sqlite3_declare_vtab() */
 11119         -  int nVtabLock;             /* Number of virtual tables to lock */
 11120         -  Table **apVtabLock;        /* Pointer to virtual tables needing locking */
        11165  +  Token sArg;               /* Complete text of a module argument */
        11166  +  Table **apVtabLock;       /* Pointer to virtual tables needing locking */
 11121  11167   #endif
 11122         -  int nHeight;            /* Expression tree height of current sub-select */
 11123         -  Table *pZombieTab;      /* List of Table objects to delete after code gen */
 11124         -  TriggerPrg *pTriggerPrg;    /* Linked list of coded triggers */
 11125         -
 11126         -#ifndef SQLITE_OMIT_EXPLAIN
 11127         -  int iSelectId;
 11128         -  int iNextSelectId;
 11129         -#endif
        11168  +  Table *pZombieTab;        /* List of Table objects to delete after code gen */
        11169  +  TriggerPrg *pTriggerPrg;  /* Linked list of coded triggers */
 11130  11170   };
 11131  11171   
        11172  +/*
        11173  +** Return true if currently inside an sqlite3_declare_vtab() call.
        11174  +*/
 11132  11175   #ifdef SQLITE_OMIT_VIRTUALTABLE
 11133  11176     #define IN_DECLARE_VTAB 0
 11134  11177   #else
 11135  11178     #define IN_DECLARE_VTAB (pParse->declareVtab)
 11136  11179   #endif
 11137  11180   
 11138  11181   /*
................................................................................
 11275  11318   
 11276  11319   /*
 11277  11320   ** A pointer to this structure is used to communicate information
 11278  11321   ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
 11279  11322   */
 11280  11323   typedef struct {
 11281  11324     sqlite3 *db;        /* The database being initialized */
 11282         -  int iDb;            /* 0 for main database.  1 for TEMP, 2.. for ATTACHed */
 11283  11325     char **pzErrMsg;    /* Error message stored here */
        11326  +  int iDb;            /* 0 for main database.  1 for TEMP, 2.. for ATTACHed */
 11284  11327     int rc;             /* Result code stored here */
 11285  11328   } InitData;
 11286  11329   
 11287  11330   /*
 11288  11331   ** Structure containing global configuration data for the SQLite library.
 11289  11332   **
 11290  11333   ** This structure also contains some state information.
................................................................................
 11418  11461   # define sqlite3Isxdigit(x)  isxdigit((unsigned char)(x))
 11419  11462   # define sqlite3Tolower(x)   tolower((unsigned char)(x))
 11420  11463   #endif
 11421  11464   
 11422  11465   /*
 11423  11466   ** Internal function prototypes
 11424  11467   */
 11425         -SQLITE_PRIVATE int sqlite3StrICmp(const char *, const char *);
        11468  +#define sqlite3StrICmp sqlite3_stricmp
 11426  11469   SQLITE_PRIVATE int sqlite3Strlen30(const char*);
 11427  11470   #define sqlite3StrNICmp sqlite3_strnicmp
 11428  11471   
 11429  11472   SQLITE_PRIVATE int sqlite3MallocInit(void);
 11430  11473   SQLITE_PRIVATE void sqlite3MallocEnd(void);
 11431  11474   SQLITE_PRIVATE void *sqlite3Malloc(int);
 11432  11475   SQLITE_PRIVATE void *sqlite3MallocZero(int);
................................................................................
 11566  11609   SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
 11567  11610   SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*);
 11568  11611   SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*);
 11569  11612   SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
 11570  11613   SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*);
 11571  11614   SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
 11572  11615                       sqlite3_vfs**,char**,char **);
        11616  +SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
 11573  11617   SQLITE_PRIVATE int sqlite3CodeOnce(Parse *);
 11574  11618   
 11575  11619   SQLITE_PRIVATE Bitvec *sqlite3BitvecCreate(u32);
 11576  11620   SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32);
 11577  11621   SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32);
 11578  11622   SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*);
 11579  11623   SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*);
................................................................................
 11601  11645   SQLITE_PRIVATE   void sqlite3AutoincrementBegin(Parse *pParse);
 11602  11646   SQLITE_PRIVATE   void sqlite3AutoincrementEnd(Parse *pParse);
 11603  11647   #else
 11604  11648   # define sqlite3AutoincrementBegin(X)
 11605  11649   # define sqlite3AutoincrementEnd(X)
 11606  11650   #endif
 11607  11651   SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
 11608         -SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*);
        11652  +SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
 11609  11653   SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
 11610  11654   SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
 11611  11655   SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
 11612  11656   SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
 11613  11657   SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
 11614  11658                                         Token*, Select*, Expr*, IdList*);
 11615  11659   SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
................................................................................
 11665  11709   SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*);
 11666  11710   SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
 11667  11711   SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
 11668  11712   SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
 11669  11713   SQLITE_PRIVATE void sqlite3PrngSaveState(void);
 11670  11714   SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
 11671  11715   SQLITE_PRIVATE void sqlite3PrngResetState(void);
 11672         -SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*);
        11716  +SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
 11673  11717   SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
 11674  11718   SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb);
 11675  11719   SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
 11676  11720   SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
 11677  11721   SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse*);
 11678  11722   SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
 11679  11723   SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
................................................................................
 11839  11883   SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64);
 11840  11884   SQLITE_PRIVATE int sqlite3AbsInt32(int);
 11841  11885   #ifdef SQLITE_ENABLE_8_3_NAMES
 11842  11886   SQLITE_PRIVATE void sqlite3FileSuffix3(const char*, char*);
 11843  11887   #else
 11844  11888   # define sqlite3FileSuffix3(X,Y)
 11845  11889   #endif
 11846         -SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z);
        11890  +SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z,int);
 11847  11891   
 11848  11892   SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
 11849  11893   SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
 11850  11894   SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, 
 11851  11895                           void(*)(void*));
 11852  11896   SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
 11853  11897   SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *);
................................................................................
 11965  12009   SQLITE_PRIVATE    void sqlite3VtabUnlock(VTable *);
 11966  12010   SQLITE_PRIVATE    void sqlite3VtabUnlockList(sqlite3*);
 11967  12011   SQLITE_PRIVATE    int sqlite3VtabSavepoint(sqlite3 *, int, int);
 11968  12012   SQLITE_PRIVATE    VTable *sqlite3GetVTable(sqlite3*, Table*);
 11969  12013   #  define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
 11970  12014   #endif
 11971  12015   SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
 11972         -SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
        12016  +SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
 11973  12017   SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
 11974  12018   SQLITE_PRIVATE void sqlite3VtabArgInit(Parse*);
 11975  12019   SQLITE_PRIVATE void sqlite3VtabArgExtend(Parse*, Token*);
 11976  12020   SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
 11977  12021   SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*);
 11978  12022   SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
 11979  12023   SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
................................................................................
 12894  12938   **
 12895  12939   ** The currently executing frame is stored in Vdbe.pFrame. Vdbe.pFrame is
 12896  12940   ** set to NULL if the currently executing frame is the main program.
 12897  12941   */
 12898  12942   typedef struct VdbeFrame VdbeFrame;
 12899  12943   struct VdbeFrame {
 12900  12944     Vdbe *v;                /* VM this frame belongs to */
 12901         -  int pc;                 /* Program Counter in parent (calling) frame */
        12945  +  VdbeFrame *pParent;     /* Parent of this frame, or NULL if parent is main */
 12902  12946     Op *aOp;                /* Program instructions for parent frame */
 12903         -  int nOp;                /* Size of aOp array */
 12904  12947     Mem *aMem;              /* Array of memory cells for parent frame */
 12905         -  int nMem;               /* Number of entries in aMem */
 12906  12948     u8 *aOnceFlag;          /* Array of OP_Once flags for parent frame */
 12907         -  int nOnceFlag;          /* Number of entries in aOnceFlag */
 12908  12949     VdbeCursor **apCsr;     /* Array of Vdbe cursors for parent frame */
        12950  +  void *token;            /* Copy of SubProgram.token */
        12951  +  i64 lastRowid;          /* Last insert rowid (sqlite3.lastRowid) */
 12909  12952     u16 nCursor;            /* Number of entries in apCsr */
 12910         -  void *token;            /* Copy of SubProgram.token */
        12953  +  int pc;                 /* Program Counter in parent (calling) frame */
        12954  +  int nOp;                /* Size of aOp array */
        12955  +  int nMem;               /* Number of entries in aMem */
        12956  +  int nOnceFlag;          /* Number of entries in aOnceFlag */
 12911  12957     int nChildMem;          /* Number of memory cells for child frame */
 12912  12958     int nChildCsr;          /* Number of cursors for child frame */
 12913         -  i64 lastRowid;          /* Last insert rowid (sqlite3.lastRowid) */
 12914  12959     int nChange;            /* Statement changes (Vdbe.nChanges)     */
 12915         -  VdbeFrame *pParent;     /* Parent of this frame, or NULL if parent is main */
 12916  12960   };
 12917  12961   
 12918  12962   #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
 12919  12963   
 12920  12964   /*
 12921  12965   ** A value for VdbeCursor.cacheValid that means the cache is always invalid.
 12922  12966   */
................................................................................
 13035  13079   ** (Mem) which are only defined there.
 13036  13080   */
 13037  13081   struct sqlite3_context {
 13038  13082     FuncDef *pFunc;       /* Pointer to function information.  MUST BE FIRST */
 13039  13083     VdbeFunc *pVdbeFunc;  /* Auxilary data, if created. */
 13040  13084     Mem s;                /* The return value is stored here */
 13041  13085     Mem *pMem;            /* Memory cell used to store aggregate context */
 13042         -  int isError;          /* Error code returned by the function. */
 13043  13086     CollSeq *pColl;       /* Collating sequence */
        13087  +  int isError;          /* Error code returned by the function. */
        13088  +  int skipFlag;         /* Skip skip accumulator loading if true */
 13044  13089   };
 13045  13090   
 13046  13091   /*
 13047  13092   ** An Explain object accumulates indented output which is helpful
 13048  13093   ** in describing recursive data structures.
 13049  13094   */
 13050  13095   struct Explain {
................................................................................
 13077  13122     Mem **apArg;            /* Arguments to currently executing user function */
 13078  13123     Mem *aColName;          /* Column names to return */
 13079  13124     Mem *pResultSet;        /* Pointer to an array of results */
 13080  13125     int nMem;               /* Number of memory locations currently allocated */
 13081  13126     int nOp;                /* Number of instructions in the program */
 13082  13127     int nOpAlloc;           /* Number of slots allocated for aOp[] */
 13083  13128     int nLabel;             /* Number of labels used */
 13084         -  int nLabelAlloc;        /* Number of slots allocated in aLabel[] */
 13085  13129     int *aLabel;            /* Space to hold the labels */
 13086  13130     u16 nResColumn;         /* Number of columns in one row of the result set */
 13087  13131     u16 nCursor;            /* Number of slots in apCsr[] */
 13088  13132     u32 magic;              /* Magic number for sanity checking */
 13089  13133     char *zErrMsg;          /* Error message written here */
 13090  13134     Vdbe *pPrev,*pNext;     /* Linked list of VDBEs with the same Vdbe.db */
 13091  13135     VdbeCursor **apCsr;     /* One element of this array for each open cursor */
................................................................................
 15144  15188   *************************************************************************
 15145  15189   **
 15146  15190   ** This file contains low-level memory allocation drivers for when
 15147  15191   ** SQLite will use the standard C-library malloc/realloc/free interface
 15148  15192   ** to obtain the memory it needs.
 15149  15193   **
 15150  15194   ** This file contains implementations of the low-level memory allocation
 15151         -** routines specified in the sqlite3_mem_methods object.
        15195  +** routines specified in the sqlite3_mem_methods object.  The content of
        15196  +** this file is only used if SQLITE_SYSTEM_MALLOC is defined.  The
        15197  +** SQLITE_SYSTEM_MALLOC macro is defined automatically if neither the
        15198  +** SQLITE_MEMDEBUG nor the SQLITE_WIN32_MALLOC macros are defined.  The
        15199  +** default configuration is to use memory allocation routines in this
        15200  +** file.
        15201  +**
        15202  +** C-preprocessor macro summary:
        15203  +**
        15204  +**    HAVE_MALLOC_USABLE_SIZE     The configure script sets this symbol if
        15205  +**                                the malloc_usable_size() interface exists
        15206  +**                                on the target platform.  Or, this symbol
        15207  +**                                can be set manually, if desired.
        15208  +**                                If an equivalent interface exists by
        15209  +**                                a different name, using a separate -D
        15210  +**                                option to rename it.
        15211  +**
        15212  +**    SQLITE_WITHOUT_ZONEMALLOC   Some older macs lack support for the zone
        15213  +**                                memory allocator.  Set this symbol to enable
        15214  +**                                building on older macs.
        15215  +**
        15216  +**    SQLITE_WITHOUT_MSIZE        Set this symbol to disable the use of
        15217  +**                                _msize() on windows systems.  This might
        15218  +**                                be necessary when compiling for Delphi,
        15219  +**                                for example.
 15152  15220   */
 15153  15221   
 15154  15222   /*
 15155  15223   ** This version of the memory allocator is the default.  It is
 15156  15224   ** used when no other memory allocator is specified using compile-time
 15157  15225   ** macros.
 15158  15226   */
 15159  15227   #ifdef SQLITE_SYSTEM_MALLOC
 15160  15228   
 15161  15229   /*
 15162         -** Windows systems have malloc_usable_size() but it is called _msize()
        15230  +** The MSVCRT has malloc_usable_size() but it is called _msize().
        15231  +** The use of _msize() is automatic, but can be disabled by compiling
        15232  +** with -DSQLITE_WITHOUT_MSIZE
 15163  15233   */
 15164         -#if !defined(HAVE_MALLOC_USABLE_SIZE) && SQLITE_OS_WIN
 15165         -# define HAVE_MALLOC_USABLE_SIZE 1
 15166         -# define malloc_usable_size _msize
        15234  +#if defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)
        15235  +# define SQLITE_MALLOCSIZE _msize
 15167  15236   #endif
 15168  15237   
 15169         -#if defined(__APPLE__)
        15238  +#if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
 15170  15239   
 15171  15240   /*
 15172         -** Use the zone allocator available on apple products
        15241  +** Use the zone allocator available on apple products unless the
        15242  +** SQLITE_WITHOUT_ZONEMALLOC symbol is defined.
 15173  15243   */
 15174  15244   #include <sys/sysctl.h>
 15175  15245   #include <malloc/malloc.h>
 15176  15246   #include <libkern/OSAtomic.h>
 15177  15247   static malloc_zone_t* _sqliteZone_;
 15178  15248   #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x))
 15179  15249   #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x));
................................................................................
 15180  15250   #define SQLITE_REALLOC(x,y) malloc_zone_realloc(_sqliteZone_, (x), (y))
 15181  15251   #define SQLITE_MALLOCSIZE(x) \
 15182  15252           (_sqliteZone_ ? _sqliteZone_->size(_sqliteZone_,x) : malloc_size(x))
 15183  15253   
 15184  15254   #else /* if not __APPLE__ */
 15185  15255   
 15186  15256   /*
 15187         -** Use standard C library malloc and free on non-Apple systems.
        15257  +** Use standard C library malloc and free on non-Apple systems.  
        15258  +** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
 15188  15259   */
 15189  15260   #define SQLITE_MALLOC(x)    malloc(x)
 15190  15261   #define SQLITE_FREE(x)      free(x)
 15191  15262   #define SQLITE_REALLOC(x,y) realloc((x),(y))
 15192  15263   
        15264  +#if (defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)) \
        15265  +      || (defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE))
        15266  +# include <malloc.h>    /* Needed for malloc_usable_size on linux */
        15267  +#endif
 15193  15268   #ifdef HAVE_MALLOC_USABLE_SIZE
 15194         -#include <malloc.h>
 15195         -#define SQLITE_MALLOCSIZE(x) malloc_usable_size(x)
        15269  +# ifndef SQLITE_MALLOCSIZE
        15270  +#  define SQLITE_MALLOCSIZE(x) malloc_usable_size(x)
        15271  +# endif
 15196  15272   #else
 15197         -#undef SQLITE_MALLOCSIZE
        15273  +# undef SQLITE_MALLOCSIZE
 15198  15274   #endif
 15199  15275   
 15200  15276   #endif /* __APPLE__ or not __APPLE__ */
 15201  15277   
 15202  15278   /*
 15203  15279   ** Like malloc(), but remember the size of the allocation
 15204  15280   ** so that we can find it later using sqlite3MemSize().
................................................................................
 15312  15388     return ROUND8(n);
 15313  15389   }
 15314  15390   
 15315  15391   /*
 15316  15392   ** Initialize this module.
 15317  15393   */
 15318  15394   static int sqlite3MemInit(void *NotUsed){
 15319         -#if defined(__APPLE__)
        15395  +#if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
 15320  15396     int cpuCount;
 15321  15397     size_t len;
 15322  15398     if( _sqliteZone_ ){
 15323  15399       return SQLITE_OK;
 15324  15400     }
 15325  15401     len = sizeof(cpuCount);
 15326  15402     /* One usually wants to use hw.acctivecpu for MT decisions, but not here */
................................................................................
 21187  21263   **
 21188  21264   ** IMPLEMENTATION-OF: R-20522-24639 The sqlite3_strnicmp() API allows
 21189  21265   ** applications and extensions to compare the contents of two buffers
 21190  21266   ** containing UTF-8 strings in a case-independent fashion, using the same
 21191  21267   ** definition of case independence that SQLite uses internally when
 21192  21268   ** comparing identifiers.
 21193  21269   */
 21194         -SQLITE_PRIVATE int sqlite3StrICmp(const char *zLeft, const char *zRight){
        21270  +SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){
 21195  21271     register unsigned char *a, *b;
 21196  21272     a = (unsigned char *)zLeft;
 21197  21273     b = (unsigned char *)zRight;
 21198  21274     while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
 21199  21275     return UpperToLower[*a] - UpperToLower[*b];
 21200  21276   }
 21201  21277   SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
................................................................................
 24938  25014   typedef struct unixFile unixFile;
 24939  25015   struct unixFile {
 24940  25016     sqlite3_io_methods const *pMethod;  /* Always the first entry */
 24941  25017     sqlite3_vfs *pVfs;                  /* The VFS that created this unixFile */
 24942  25018     unixInodeInfo *pInode;              /* Info about locks on this inode */
 24943  25019     int h;                              /* The file descriptor */
 24944  25020     unsigned char eFileLock;            /* The type of lock held on this fd */
 24945         -  unsigned char ctrlFlags;            /* Behavioral bits.  UNIXFILE_* flags */
        25021  +  unsigned short int ctrlFlags;       /* Behavioral bits.  UNIXFILE_* flags */
 24946  25022     int lastErrno;                      /* The unix errno from last I/O error */
 24947  25023     void *lockingContext;               /* Locking style specific state */
 24948  25024     UnixUnusedFd *pUnused;              /* Pre-allocated UnixUnusedFd */
 24949  25025     const char *zPath;                  /* Name of the file */
 24950  25026     unixShm *pShm;                      /* Shared memory segment information */
 24951  25027     int szChunk;                        /* Configured by FCNTL_CHUNK_SIZE */
 24952  25028   #if SQLITE_ENABLE_LOCKING_STYLE
................................................................................
 24989  25065   #else
 24990  25066   # define UNIXFILE_DIRSYNC    0x00
 24991  25067   #endif
 24992  25068   #define UNIXFILE_PSOW        0x10     /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
 24993  25069   #define UNIXFILE_DELETE      0x20     /* Delete on close */
 24994  25070   #define UNIXFILE_URI         0x40     /* Filename might have query parameters */
 24995  25071   #define UNIXFILE_NOLOCK      0x80     /* Do no file locking */
        25072  +#define UNIXFILE_CHOWN      0x100     /* File ownership was changed */
 24996  25073   
 24997  25074   /*
 24998  25075   ** Include code that is common to all os_*.c files
 24999  25076   */
 25000  25077   /************** Include os_common.h in the middle of os_unix.c ***************/
 25001  25078   /************** Begin file os_common.h ***************************************/
 25002  25079   /*
................................................................................
 25353  25430   
 25354  25431     { "mkdir",        (sqlite3_syscall_ptr)mkdir,           0 },
 25355  25432   #define osMkdir     ((int(*)(const char*,mode_t))aSyscall[18].pCurrent)
 25356  25433   
 25357  25434     { "rmdir",        (sqlite3_syscall_ptr)rmdir,           0 },
 25358  25435   #define osRmdir     ((int(*)(const char*))aSyscall[19].pCurrent)
 25359  25436   
        25437  +  { "fchown",       (sqlite3_syscall_ptr)fchown,          0 },
        25438  +#define osFchown    ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
        25439  +
        25440  +  { "umask",        (sqlite3_syscall_ptr)umask,           0 },
        25441  +#define osUmask     ((mode_t(*)(mode_t))aSyscall[21].pCurrent)
        25442  +
 25360  25443   }; /* End of the overrideable system calls */
 25361  25444   
 25362  25445   /*
 25363  25446   ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
 25364  25447   ** "unix" VFSes.  Return SQLITE_OK opon successfully updating the
 25365  25448   ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
 25366  25449   ** system call named zName.
................................................................................
 25439  25522     for(i++; i<ArraySize(aSyscall); i++){
 25440  25523       if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName;
 25441  25524     }
 25442  25525     return 0;
 25443  25526   }
 25444  25527   
 25445  25528   /*
 25446         -** Retry open() calls that fail due to EINTR
        25529  +** Invoke open().  Do so multiple times, until it either succeeds or
        25530  +** files for some reason other than EINTR.
        25531  +**
        25532  +** If the file creation mode "m" is 0 then set it to the default for
        25533  +** SQLite.  The default is SQLITE_DEFAULT_FILE_PERMISSIONS (normally
        25534  +** 0644) as modified by the system umask.  If m is not 0, then
        25535  +** make the file creation mode be exactly m ignoring the umask.
        25536  +**
        25537  +** The m parameter will be non-zero only when creating -wal, -journal,
        25538  +** and -shm files.  We want those files to have *exactly* the same
        25539  +** permissions as their original database, unadulterated by the umask.
        25540  +** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a
        25541  +** transaction crashes and leaves behind hot journals, then any
        25542  +** process that is able to write to the database will also be able to
        25543  +** recover the hot journals.
 25447  25544   */
 25448         -static int robust_open(const char *z, int f, int m){
        25545  +static int robust_open(const char *z, int f, mode_t m){
 25449  25546     int rc;
 25450         -  do{ rc = osOpen(z,f,m); }while( rc<0 && errno==EINTR );
        25547  +  mode_t m2;
        25548  +  mode_t origM = 0;
        25549  +  if( m==0 ){
        25550  +    m2 = SQLITE_DEFAULT_FILE_PERMISSIONS;
        25551  +  }else{
        25552  +    m2 = m;
        25553  +    origM = osUmask(0);
        25554  +  }
        25555  +  do{ rc = osOpen(z,f,m2); }while( rc<0 && errno==EINTR );
        25556  +  if( m ){
        25557  +    osUmask(origM);
        25558  +  }
 25451  25559     return rc;
 25452  25560   }
 25453  25561   
 25454  25562   /*
 25455  25563   ** Helper functions to obtain and relinquish the global mutex. The
 25456  25564   ** global mutex is used to protect the unixInodeInfo and
 25457  25565   ** vxworksFileId objects used by this file, all of which may be 
................................................................................
 28791  28899     pInode = pDbFd->pInode;
 28792  28900     pShmNode = pInode->pShmNode;
 28793  28901     if( pShmNode==0 ){
 28794  28902       struct stat sStat;                 /* fstat() info for database file */
 28795  28903   
 28796  28904       /* Call fstat() to figure out the permissions on the database file. If
 28797  28905       ** a new *-shm file is created, an attempt will be made to create it
 28798         -    ** with the same permissions. The actual permissions the file is created
 28799         -    ** with are subject to the current umask setting.
        28906  +    ** with the same permissions.
 28800  28907       */
 28801  28908       if( osFstat(pDbFd->h, &sStat) && pInode->bProcessLock==0 ){
 28802  28909         rc = SQLITE_IOERR_FSTAT;
 28803  28910         goto shm_open_err;
 28804  28911       }
 28805  28912   
 28806  28913   #ifdef SQLITE_SHM_DIRECTORY
................................................................................
 28836  28943         int openFlags = O_RDWR | O_CREAT;
 28837  28944         if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
 28838  28945           openFlags = O_RDONLY;
 28839  28946           pShmNode->isReadonly = 1;
 28840  28947         }
 28841  28948         pShmNode->h = robust_open(zShmFilename, openFlags, (sStat.st_mode&0777));
 28842  28949         if( pShmNode->h<0 ){
 28843         -        if( pShmNode->h<0 ){
 28844         -          rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
 28845         -          goto shm_open_err;
 28846         -        }
        28950  +        rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
        28951  +        goto shm_open_err;
        28952  +      }
        28953  +
        28954  +      /* If this process is running as root, make sure that the SHM file
        28955  +      ** is owned by the same user that owns the original database.  Otherwise,
        28956  +      ** the original owner will not be able to connect. If this process is
        28957  +      ** not root, the following fchown() will fail, but we don't care.  The
        28958  +      ** if(){..} and the UNIXFILE_CHOWN flag are purely to silence compiler
        28959  +      ** warnings.
        28960  +      */
        28961  +      if( osFchown(pShmNode->h, sStat.st_uid, sStat.st_gid)==0 ){
        28962  +        pDbFd->ctrlFlags |= UNIXFILE_CHOWN;
 28847  28963         }
 28848  28964     
 28849  28965         /* Check to see if another process is holding the dead-man switch.
 28850  28966         ** If not, truncate the file to zero length. 
 28851  28967         */
 28852  28968         rc = SQLITE_OK;
 28853  28969         if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
................................................................................
 29814  29930   /*
 29815  29931   ** This function is called by unixOpen() to determine the unix permissions
 29816  29932   ** to create new files with. If no error occurs, then SQLITE_OK is returned
 29817  29933   ** and a value suitable for passing as the third argument to open(2) is
 29818  29934   ** written to *pMode. If an IO error occurs, an SQLite error code is 
 29819  29935   ** returned and the value of *pMode is not modified.
 29820  29936   **
 29821         -** If the file being opened is a temporary file, it is always created with
 29822         -** the octal permissions 0600 (read/writable by owner only). If the file
 29823         -** is a database or master journal file, it is created with the permissions 
 29824         -** mask SQLITE_DEFAULT_FILE_PERMISSIONS.
 29825         -**
 29826         -** Finally, if the file being opened is a WAL or regular journal file, then 
        29937  +** In most cases cases, this routine sets *pMode to 0, which will become
        29938  +** an indication to robust_open() to create the file using
        29939  +** SQLITE_DEFAULT_FILE_PERMISSIONS adjusted by the umask.
        29940  +** But if the file being opened is a WAL or regular journal file, then 
 29827  29941   ** this function queries the file-system for the permissions on the 
 29828  29942   ** corresponding database file and sets *pMode to this value. Whenever 
 29829  29943   ** possible, WAL and journal files are created using the same permissions 
 29830  29944   ** as the associated database file.
 29831  29945   **
 29832  29946   ** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the
 29833  29947   ** original filename is unavailable.  But 8_3_NAMES is only used for
 29834  29948   ** FAT filesystems and permissions do not matter there, so just use
 29835  29949   ** the default permissions.
 29836  29950   */
 29837  29951   static int findCreateFileMode(
 29838  29952     const char *zPath,              /* Path of file (possibly) being created */
 29839  29953     int flags,                      /* Flags passed as 4th argument to xOpen() */
 29840         -  mode_t *pMode                   /* OUT: Permissions to open file with */
        29954  +  mode_t *pMode,                  /* OUT: Permissions to open file with */
        29955  +  uid_t *pUid,                    /* OUT: uid to set on the file */
        29956  +  gid_t *pGid                     /* OUT: gid to set on the file */
 29841  29957   ){
 29842  29958     int rc = SQLITE_OK;             /* Return Code */
 29843         -  *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS;
        29959  +  *pMode = 0;
        29960  +  *pUid = 0;
        29961  +  *pGid = 0;
 29844  29962     if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
 29845  29963       char zDb[MAX_PATHNAME+1];     /* Database file path */
 29846  29964       int nDb;                      /* Number of valid bytes in zDb */
 29847  29965       struct stat sStat;            /* Output of stat() on database file */
 29848  29966   
 29849  29967       /* zPath is a path to a WAL or journal file. The following block derives
 29850  29968       ** the path to the associated database file from zPath. This block handles
................................................................................
 29870  29988       }
 29871  29989   #endif
 29872  29990       memcpy(zDb, zPath, nDb);
 29873  29991       zDb[nDb] = '\0';
 29874  29992   
 29875  29993       if( 0==osStat(zDb, &sStat) ){
 29876  29994         *pMode = sStat.st_mode & 0777;
        29995  +      *pUid = sStat.st_uid;
        29996  +      *pGid = sStat.st_gid;
 29877  29997       }else{
 29878  29998         rc = SQLITE_IOERR_FSTAT;
 29879  29999       }
 29880  30000     }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
 29881  30001       *pMode = 0600;
 29882  30002     }
 29883  30003     return rc;
................................................................................
 30016  30136     if( isReadWrite ) openFlags |= O_RDWR;
 30017  30137     if( isCreate )    openFlags |= O_CREAT;
 30018  30138     if( isExclusive ) openFlags |= (O_EXCL|O_NOFOLLOW);
 30019  30139     openFlags |= (O_LARGEFILE|O_BINARY);
 30020  30140   
 30021  30141     if( fd<0 ){
 30022  30142       mode_t openMode;              /* Permissions to create file with */
 30023         -    rc = findCreateFileMode(zName, flags, &openMode);
        30143  +    uid_t uid;                    /* Userid for the file */
        30144  +    gid_t gid;                    /* Groupid for the file */
        30145  +    rc = findCreateFileMode(zName, flags, &openMode, &uid, &gid);
 30024  30146       if( rc!=SQLITE_OK ){
 30025  30147         assert( !p->pUnused );
 30026  30148         assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL );
 30027  30149         return rc;
 30028  30150       }
 30029  30151       fd = robust_open(zName, openFlags, openMode);
 30030  30152       OSTRACE(("OPENX   %-3d %s 0%o\n", fd, zName, openFlags));
................................................................................
 30037  30159         isReadonly = 1;
 30038  30160         fd = robust_open(zName, openFlags, openMode);
 30039  30161       }
 30040  30162       if( fd<0 ){
 30041  30163         rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
 30042  30164         goto open_finished;
 30043  30165       }
        30166  +
        30167  +    /* If this process is running as root and if creating a new rollback
        30168  +    ** journal or WAL file, set the ownership of the journal or WAL to be
        30169  +    ** the same as the original database.  If we are not running as root,
        30170  +    ** then the fchown() call will fail, but that's ok.  The "if(){}" and
        30171  +    ** the setting of the UNIXFILE_CHOWN flag are purely to silence compiler
        30172  +    ** warnings from gcc.
        30173  +    */
        30174  +    if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
        30175  +      if( osFchown(fd, uid, gid)==0 ){ p->ctrlFlags |= UNIXFILE_CHOWN; }
        30176  +    }
 30044  30177     }
 30045  30178     assert( fd>=0 );
 30046  30179     if( pOutFlags ){
 30047  30180       *pOutFlags = flags;
 30048  30181     }
 30049  30182   
 30050  30183     if( p->pUnused ){
................................................................................
 30348  30481     ** When testing, initializing zBuf[] to zero is all we do.  That means
 30349  30482     ** that we always use the same random number sequence.  This makes the
 30350  30483     ** tests repeatable.
 30351  30484     */
 30352  30485     memset(zBuf, 0, nBuf);
 30353  30486   #if !defined(SQLITE_TEST)
 30354  30487     {
 30355         -    int pid, fd;
        30488  +    int pid, fd, got;
 30356  30489       fd = robust_open("/dev/urandom", O_RDONLY, 0);
 30357  30490       if( fd<0 ){
 30358  30491         time_t t;
 30359  30492         time(&t);
 30360  30493         memcpy(zBuf, &t, sizeof(t));
 30361  30494         pid = getpid();
 30362  30495         memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
 30363  30496         assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
 30364  30497         nBuf = sizeof(t) + sizeof(pid);
 30365  30498       }else{
 30366         -      do{ nBuf = osRead(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
        30499  +      do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR );
 30367  30500         robust_close(0, fd, __LINE__);
 30368  30501       }
 30369  30502     }
 30370  30503   #endif
 30371  30504     return nBuf;
 30372  30505   }
 30373  30506   
................................................................................
 30763  30896     }else{
 30764  30897       pUnused = sqlite3_malloc(sizeof(*pUnused));
 30765  30898       if( !pUnused ){
 30766  30899         return SQLITE_NOMEM;
 30767  30900       }
 30768  30901     }
 30769  30902     if( fd<0 ){
 30770         -    fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
        30903  +    fd = robust_open(path, openFlags, 0);
 30771  30904       terrno = errno;
 30772  30905       if( fd<0 && errno==ENOENT && islockfile ){
 30773  30906         if( proxyCreateLockPath(path) == SQLITE_OK ){
 30774         -        fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
        30907  +        fd = robust_open(path, openFlags, 0);
 30775  30908         }
 30776  30909       }
 30777  30910     }
 30778  30911     if( fd<0 ){
 30779  30912       openFlags = O_RDONLY;
 30780         -    fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
        30913  +    fd = robust_open(path, openFlags, 0);
 30781  30914       terrno = errno;
 30782  30915     }
 30783  30916     if( fd<0 ){
 30784  30917       if( islockfile ){
 30785  30918         return SQLITE_BUSY;
 30786  30919       }
 30787  30920       switch (terrno) {
................................................................................
 30897  31030     /* read the conch content */
 30898  31031     readLen = osPread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0);
 30899  31032     if( readLen<PROXY_PATHINDEX ){
 30900  31033       sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen);
 30901  31034       goto end_breaklock;
 30902  31035     }
 30903  31036     /* write it out to the temporary break file */
 30904         -  fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL),
 30905         -                   SQLITE_DEFAULT_FILE_PERMISSIONS);
        31037  +  fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL), 0);
 30906  31038     if( fd<0 ){
 30907  31039       sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno);
 30908  31040       goto end_breaklock;
 30909  31041     }
 30910  31042     if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
 30911  31043       sqlite3_snprintf(sizeof(errmsg), errmsg, "write failed (%d)", errno);
 30912  31044       goto end_breaklock;
................................................................................
 31175  31307         OSTRACE(("TRANSPROXY: CLOSE  %d\n", pFile->h));
 31176  31308         if( rc==SQLITE_OK && pFile->openFlags ){
 31177  31309           int fd;
 31178  31310           if( pFile->h>=0 ){
 31179  31311             robust_close(pFile, pFile->h, __LINE__);
 31180  31312           }
 31181  31313           pFile->h = -1;
 31182         -        fd = robust_open(pCtx->dbPath, pFile->openFlags,
 31183         -                      SQLITE_DEFAULT_FILE_PERMISSIONS);
        31314  +        fd = robust_open(pCtx->dbPath, pFile->openFlags, 0);
 31184  31315           OSTRACE(("TRANSPROXY: OPEN  %d\n", fd));
 31185  31316           if( fd>=0 ){
 31186  31317             pFile->h = fd;
 31187  31318           }else{
 31188  31319             rc=SQLITE_CANTOPEN_BKPT; /* SQLITE_BUSY? proxyTakeConch called
 31189  31320              during locking */
 31190  31321           }
................................................................................
 31745  31876       UNIXVFS("unix-proxy",    proxyIoFinder ),
 31746  31877   #endif
 31747  31878     };
 31748  31879     unsigned int i;          /* Loop counter */
 31749  31880   
 31750  31881     /* Double-check that the aSyscall[] array has been constructed
 31751  31882     ** correctly.  See ticket [bb3a86e890c8e96ab] */
 31752         -  assert( ArraySize(aSyscall)==20 );
        31883  +  assert( ArraySize(aSyscall)==22 );
 31753  31884   
 31754  31885     /* Register all VFSes defined in the aVfs[] array */
 31755  31886     for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
 31756  31887       sqlite3_vfs_register(&aVfs[i], i==0);
 31757  31888     }
 31758  31889     return SQLITE_OK; 
 31759  31890   }
................................................................................
 36784  36915     PGroup *pGroup;                     /* PGroup this cache belongs to */
 36785  36916     int szPage;                         /* Size of allocated pages in bytes */
 36786  36917     int szExtra;                        /* Size of extra space in bytes */
 36787  36918     int bPurgeable;                     /* True if cache is purgeable */
 36788  36919     unsigned int nMin;                  /* Minimum number of pages reserved */
 36789  36920     unsigned int nMax;                  /* Configured "cache_size" value */
 36790  36921     unsigned int n90pct;                /* nMax*9/10 */
        36922  +  unsigned int iMaxKey;               /* Largest key seen since xTruncate() */
 36791  36923   
 36792  36924     /* Hash table of all pages. The following variables may only be accessed
 36793  36925     ** when the accessor is holding the PGroup mutex.
 36794  36926     */
 36795  36927     unsigned int nRecyclable;           /* Number of pages in the LRU list */
 36796  36928     unsigned int nPage;                 /* Total number of pages in apHash */
 36797  36929     unsigned int nHash;                 /* Number of slots in apHash[] */
 36798  36930     PgHdr1 **apHash;                    /* Hash table for fast lookup by key */
 36799         -
 36800         -  unsigned int iMaxKey;               /* Largest key seen since xTruncate() */
 36801  36931   };
 36802  36932   
 36803  36933   /*
 36804  36934   ** Each cache entry is represented by an instance of the following 
 36805  36935   ** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
 36806  36936   ** PgHdr1.pCache->szPage bytes is allocated directly before this structure 
 36807  36937   ** in memory.
................................................................................
 36837  36967     int isInit;                    /* True if initialized */
 36838  36968     int szSlot;                    /* Size of each free slot */
 36839  36969     int nSlot;                     /* The number of pcache slots */
 36840  36970     int nReserve;                  /* Try to keep nFreeSlot above this */
 36841  36971     void *pStart, *pEnd;           /* Bounds of pagecache malloc range */
 36842  36972     /* Above requires no mutex.  Use mutex below for variable that follow. */
 36843  36973     sqlite3_mutex *mutex;          /* Mutex for accessing the following: */
 36844         -  int nFreeSlot;                 /* Number of unused pcache slots */
 36845  36974     PgFreeslot *pFree;             /* Free page blocks */
        36975  +  int nFreeSlot;                 /* Number of unused pcache slots */
 36846  36976     /* The following value requires a mutex to change.  We skip the mutex on
 36847  36977     ** reading because (1) most platforms read a 32-bit integer atomically and
 36848  36978     ** (2) even if an incorrect value is read, no great harm is done since this
 36849  36979     ** is really just an optimization. */
 36850  36980     int bUnderPressure;            /* True if low on PAGECACHE memory */
 36851  36981   } pcache1_g;
 36852  36982   
................................................................................
 38219  38349   # define sqlite3WalSavepoint(y,z)
 38220  38350   # define sqlite3WalSavepointUndo(y,z)            0
 38221  38351   # define sqlite3WalFrames(u,v,w,x,y,z)           0
 38222  38352   # define sqlite3WalCheckpoint(r,s,t,u,v,w,x,y,z) 0
 38223  38353   # define sqlite3WalCallback(z)                   0
 38224  38354   # define sqlite3WalExclusiveMode(y,z)            0
 38225  38355   # define sqlite3WalHeapMemory(z)                 0
        38356  +# define sqlite3WalFramesize(z)                  0
 38226  38357   #else
 38227  38358   
 38228  38359   #define WAL_SAVEPOINT_NDATA 4
 38229  38360   
 38230  38361   /* Connection to a write-ahead log (WAL) file. 
 38231  38362   ** There is one object of this type for each pager. 
 38232  38363   */
................................................................................
 38299  38430   SQLITE_PRIVATE int sqlite3WalExclusiveMode(Wal *pWal, int op);
 38300  38431   
 38301  38432   /* Return true if the argument is non-NULL and the WAL module is using
 38302  38433   ** heap-memory for the wal-index. Otherwise, if the argument is NULL or the
 38303  38434   ** WAL module is using shared-memory, return false. 
 38304  38435   */
 38305  38436   SQLITE_PRIVATE int sqlite3WalHeapMemory(Wal *pWal);
        38437  +
        38438  +#ifdef SQLITE_ENABLE_ZIPVFS
        38439  +/* If the WAL file is not empty, return the number of bytes of content
        38440  +** stored in each frame (i.e. the db page-size when the WAL was created).
        38441  +*/
        38442  +SQLITE_PRIVATE int sqlite3WalFramesize(Wal *pWal);
        38443  +#endif
 38306  38444   
 38307  38445   #endif /* ifndef SQLITE_OMIT_WAL */
 38308  38446   #endif /* _WAL_H_ */
 38309  38447   
 38310  38448   /************** End of wal.h *************************************************/
 38311  38449   /************** Continuing where we left off in pager.c **********************/
 38312  38450   
................................................................................
 38896  39034   **   sub-codes.
 38897  39035   */
 38898  39036   struct Pager {
 38899  39037     sqlite3_vfs *pVfs;          /* OS functions to use for IO */
 38900  39038     u8 exclusiveMode;           /* Boolean. True if locking_mode==EXCLUSIVE */
 38901  39039     u8 journalMode;             /* One of the PAGER_JOURNALMODE_* values */
 38902  39040     u8 useJournal;              /* Use a rollback journal on this file */
 38903         -  u8 noReadlock;              /* Do not bother to obtain readlocks */
 38904  39041     u8 noSync;                  /* Do not sync the journal if true */
 38905  39042     u8 fullSync;                /* Do extra syncs of the journal for robustness */
 38906  39043     u8 ckptSyncFlags;           /* SYNC_NORMAL or SYNC_FULL for checkpoint */
 38907  39044     u8 walSyncFlags;            /* SYNC_NORMAL or SYNC_FULL for wal writes */
 38908  39045     u8 syncFlags;               /* SYNC_NORMAL or SYNC_FULL otherwise */
 38909  39046     u8 tempFile;                /* zFilename is a temporary file */
 38910  39047     u8 readOnly;                /* True for a read-only database */
................................................................................
 39144  39281         assert( pPager->errCode==SQLITE_OK );
 39145  39282         assert( sqlite3PcacheRefCount(pPager->pPCache)==0 || pPager->tempFile );
 39146  39283         break;
 39147  39284   
 39148  39285       case PAGER_READER:
 39149  39286         assert( pPager->errCode==SQLITE_OK );
 39150  39287         assert( p->eLock!=UNKNOWN_LOCK );
 39151         -      assert( p->eLock>=SHARED_LOCK || p->noReadlock );
        39288  +      assert( p->eLock>=SHARED_LOCK );
 39152  39289         break;
 39153  39290   
 39154  39291       case PAGER_WRITER_LOCKED:
 39155  39292         assert( p->eLock!=UNKNOWN_LOCK );
 39156  39293         assert( pPager->errCode==SQLITE_OK );
 39157  39294         if( !pagerUseWal(pPager) ){
 39158  39295           assert( p->eLock>=RESERVED_LOCK );
................................................................................
 41353  41490     /* Query the WAL sub-system for the database size. The WalDbsize()
 41354  41491     ** function returns zero if the WAL is not open (i.e. Pager.pWal==0), or
 41355  41492     ** if the database size is not available. The database size is not
 41356  41493     ** available from the WAL sub-system if the log file is empty or
 41357  41494     ** contains no valid committed transactions.
 41358  41495     */
 41359  41496     assert( pPager->eState==PAGER_OPEN );
 41360         -  assert( pPager->eLock>=SHARED_LOCK || pPager->noReadlock );
        41497  +  assert( pPager->eLock>=SHARED_LOCK );
 41361  41498     nPage = sqlite3WalDbsize(pPager->pWal);
 41362  41499   
 41363  41500     /* If the database size was not available from the WAL sub-system,
 41364  41501     ** determine it based on the size of the database file. If the size
 41365  41502     ** of the database file is not an integer multiple of the page-size,
 41366  41503     ** round down to the nearest page. Except, any file larger than 0
 41367  41504     ** bytes in size is considered to contain at least one page.
................................................................................
 41408  41545   ** a WAL on a none-empty database, this ensures there is no race condition 
 41409  41546   ** between the xAccess() below and an xDelete() being executed by some 
 41410  41547   ** other connection.
 41411  41548   */
 41412  41549   static int pagerOpenWalIfPresent(Pager *pPager){
 41413  41550     int rc = SQLITE_OK;
 41414  41551     assert( pPager->eState==PAGER_OPEN );
 41415         -  assert( pPager->eLock>=SHARED_LOCK || pPager->noReadlock );
        41552  +  assert( pPager->eLock>=SHARED_LOCK );
 41416  41553   
 41417  41554     if( !pPager->tempFile ){
 41418  41555       int isWal;                    /* True if WAL file exists */
 41419  41556       Pgno nPage;                   /* Size of the database file */
 41420  41557   
 41421  41558       rc = pagerPagecount(pPager, &nPage);
 41422  41559       if( rc ) return rc;
................................................................................
 42571  42708   **
 42572  42709   ** The nExtra parameter specifies the number of bytes of space allocated
 42573  42710   ** along with each page reference. This space is available to the user
 42574  42711   ** via the sqlite3PagerGetExtra() API.
 42575  42712   **
 42576  42713   ** The flags argument is used to specify properties that affect the
 42577  42714   ** operation of the pager. It should be passed some bitwise combination
 42578         -** of the PAGER_OMIT_JOURNAL and PAGER_NO_READLOCK flags.
        42715  +** of the PAGER_* flags.
 42579  42716   **
 42580  42717   ** The vfsFlags parameter is a bitmask to pass to the flags parameter
 42581  42718   ** of the xOpen() method of the supplied VFS when opening files. 
 42582  42719   **
 42583  42720   ** If the pager object is allocated and the specified file opened 
 42584  42721   ** successfully, SQLITE_OK is returned and *ppPager set to point to
 42585  42722   ** the new pager object. If an error occurs, *ppPager is set to NULL
................................................................................
 42602  42739     int tempFile = 0;        /* True for temp files (incl. in-memory files) */
 42603  42740     int memDb = 0;           /* True if this is an in-memory file */
 42604  42741     int readOnly = 0;        /* True if this is a read-only file */
 42605  42742     int journalFileSize;     /* Bytes to allocate for each journal fd */
 42606  42743     char *zPathname = 0;     /* Full path to database file */
 42607  42744     int nPathname = 0;       /* Number of bytes in zPathname */
 42608  42745     int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
 42609         -  int noReadlock = (flags & PAGER_NO_READLOCK)!=0;  /* True to omit read-lock */
 42610  42746     int pcacheSize = sqlite3PcacheSize();       /* Bytes to allocate for PCache */
 42611  42747     u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE;  /* Default page size */
 42612  42748     const char *zUri = 0;    /* URI args to copy */
 42613  42749     int nUri = 0;            /* Number of bytes of URI args at *zUri */
 42614  42750   
 42615  42751     /* Figure out how much space is required for each journal file-handle
 42616  42752     ** (there are two of them, the main journal and the sub-journal). This
................................................................................
 42809  42945     sqlite3PcacheOpen(szPageDflt, nExtra, !memDb,
 42810  42946                       !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
 42811  42947   
 42812  42948     PAGERTRACE(("OPEN %d %s\n", FILEHANDLEID(pPager->fd), pPager->zFilename));
 42813  42949     IOTRACE(("OPEN %p %s\n", pPager, pPager->zFilename))
 42814  42950   
 42815  42951     pPager->useJournal = (u8)useJournal;
 42816         -  pPager->noReadlock = (noReadlock && readOnly) ?1:0;
 42817  42952     /* pPager->stmtOpen = 0; */
 42818  42953     /* pPager->stmtInUse = 0; */
 42819  42954     /* pPager->nRef = 0; */
 42820  42955     /* pPager->stmtSize = 0; */
 42821  42956     /* pPager->stmtJSize = 0; */
 42822  42957     /* pPager->nPage = 0; */
 42823  42958     pPager->mxPgno = SQLITE_MAX_PAGE_COUNT;
................................................................................
 43031  43166     assert( pPager->eState==PAGER_OPEN || pPager->eState==PAGER_READER );
 43032  43167     if( NEVER(MEMDB && pPager->errCode) ){ return pPager->errCode; }
 43033  43168   
 43034  43169     if( !pagerUseWal(pPager) && pPager->eState==PAGER_OPEN ){
 43035  43170       int bHotJournal = 1;          /* True if there exists a hot journal-file */
 43036  43171   
 43037  43172       assert( !MEMDB );
 43038         -    assert( pPager->noReadlock==0 || pPager->readOnly );
 43039  43173   
 43040         -    if( pPager->noReadlock==0 ){
 43041         -      rc = pager_wait_on_lock(pPager, SHARED_LOCK);
 43042         -      if( rc!=SQLITE_OK ){
 43043         -        assert( pPager->eLock==NO_LOCK || pPager->eLock==UNKNOWN_LOCK );
 43044         -        goto failed;
 43045         -      }
        43174  +    rc = pager_wait_on_lock(pPager, SHARED_LOCK);
        43175  +    if( rc!=SQLITE_OK ){
        43176  +      assert( pPager->eLock==NO_LOCK || pPager->eLock==UNKNOWN_LOCK );
        43177  +      goto failed;
 43046  43178       }
 43047  43179   
 43048  43180       /* If a journal file exists, and there is no RESERVED lock on the
 43049  43181       ** database file, then it either needs to be played back or deleted.
 43050  43182       */
 43051  43183       if( pPager->eLock<=SHARED_LOCK ){
 43052  43184         rc = hasHotJournal(pPager, &bHotJournal);
................................................................................
 45046  45178   ** lock on the database file and use heap-memory to store the wal-index
 45047  45179   ** in. Otherwise, use the normal shared-memory.
 45048  45180   */
 45049  45181   static int pagerOpenWal(Pager *pPager){
 45050  45182     int rc = SQLITE_OK;
 45051  45183   
 45052  45184     assert( pPager->pWal==0 && pPager->tempFile==0 );
 45053         -  assert( pPager->eLock==SHARED_LOCK || pPager->eLock==EXCLUSIVE_LOCK || pPager->noReadlock);
        45185  +  assert( pPager->eLock==SHARED_LOCK || pPager->eLock==EXCLUSIVE_LOCK );
 45054  45186   
 45055  45187     /* If the pager is already in exclusive-mode, the WAL module will use 
 45056  45188     ** heap-memory for the wal-index instead of the VFS shared-memory 
 45057  45189     ** implementation. Take the exclusive lock now, before opening the WAL
 45058  45190     ** file, to make sure this is safe.
 45059  45191     */
 45060  45192     if( pPager->exclusiveMode ){
................................................................................
 45160  45292         rc = sqlite3WalClose(pPager->pWal, pPager->ckptSyncFlags,
 45161  45293                              pPager->pageSize, (u8*)pPager->pTmpSpace);
 45162  45294         pPager->pWal = 0;
 45163  45295       }
 45164  45296     }
 45165  45297     return rc;
 45166  45298   }
        45299  +
        45300  +#ifdef SQLITE_ENABLE_ZIPVFS
        45301  +/*
        45302  +** A read-lock must be held on the pager when this function is called. If
        45303  +** the pager is in WAL mode and the WAL file currently contains one or more
        45304  +** frames, return the size in bytes of the page images stored within the
        45305  +** WAL frames. Otherwise, if this is not a WAL database or the WAL file
        45306  +** is empty, return 0.
        45307  +*/
        45308  +SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){
        45309  +  assert( pPager->eState==PAGER_READER );
        45310  +  return sqlite3WalFramesize(pPager->pWal);
        45311  +}
        45312  +#endif
 45167  45313   
 45168  45314   #ifdef SQLITE_HAS_CODEC
 45169  45315   /*
 45170  45316   ** This function is called by the wal module when writing page content
 45171  45317   ** into the log file.
 45172  45318   **
 45173  45319   ** This function returns a pointer to a buffer containing the encrypted
................................................................................
 47580  47726       sz = pWal->hdr.szPage;
 47581  47727       sz = (sz&0xfe00) + ((sz&0x0001)<<16);
 47582  47728       testcase( sz<=32768 );
 47583  47729       testcase( sz>=65536 );
 47584  47730       iOffset = walFrameOffset(iRead, sz) + WAL_FRAME_HDRSIZE;
 47585  47731       *pInWal = 1;
 47586  47732       /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
 47587         -    return sqlite3OsRead(pWal->pWalFd, pOut, nOut, iOffset);
        47733  +    return sqlite3OsRead(pWal->pWalFd, pOut, (nOut>sz ? sz : nOut), iOffset);
 47588  47734     }
 47589  47735   
 47590  47736     *pInWal = 0;
 47591  47737     return SQLITE_OK;
 47592  47738   }
 47593  47739   
 47594  47740   
................................................................................
 48250  48396   ** Return true if the argument is non-NULL and the WAL module is using
 48251  48397   ** heap-memory for the wal-index. Otherwise, if the argument is NULL or the
 48252  48398   ** WAL module is using shared-memory, return false. 
 48253  48399   */
 48254  48400   SQLITE_PRIVATE int sqlite3WalHeapMemory(Wal *pWal){
 48255  48401     return (pWal && pWal->exclusiveMode==WAL_HEAPMEMORY_MODE );
 48256  48402   }
        48403  +
        48404  +#ifdef SQLITE_ENABLE_ZIPVFS
        48405  +/*
        48406  +** If the argument is not NULL, it points to a Wal object that holds a
        48407  +** read-lock. This function returns the database page-size if it is known,
        48408  +** or zero if it is not (or if pWal is NULL).
        48409  +*/
        48410  +SQLITE_PRIVATE int sqlite3WalFramesize(Wal *pWal){
        48411  +  assert( pWal==0 || pWal->readLock>=0 );
        48412  +  return (pWal ? pWal->szPage : 0);
        48413  +}
        48414  +#endif
 48257  48415   
 48258  48416   #endif /* #ifndef SQLITE_OMIT_WAL */
 48259  48417   
 48260  48418   /************** End of wal.c *************************************************/
 48261  48419   /************** Begin file btmutex.c *****************************************/
 48262  48420   /*
 48263  48421   ** 2007 August 27
................................................................................
 48559  48717     u8 max1bytePayload;  /* min(maxLocal,127) */
 48560  48718     u16 maxLocal;        /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
 48561  48719     u16 minLocal;        /* Copy of BtShared.minLocal or BtShared.minLeaf */
 48562  48720     u16 cellOffset;      /* Index in aData of first cell pointer */
 48563  48721     u16 nFree;           /* Number of free bytes on the page */
 48564  48722     u16 nCell;           /* Number of cells on this page, local and ovfl */
 48565  48723     u16 maskPage;        /* Mask for page offset */
 48566         -  struct _OvflCell {   /* Cells that will not fit on aData[] */
 48567         -    u8 *pCell;          /* Pointers to the body of the overflow cell */
 48568         -    u16 idx;            /* Insert this cell before idx-th non-overflow cell */
 48569         -  } aOvfl[5];
        48724  +  u16 aiOvfl[5];       /* Insert the i-th overflow cell before the aiOvfl-th
        48725  +                       ** non-overflow cell */
        48726  +  u8 *apOvfl[5];       /* Pointers to the body of overflow cells */
 48570  48727     BtShared *pBt;       /* Pointer to BtShared that this page is part of */
 48571  48728     u8 *aData;           /* Pointer to disk image of the page data */
 48572  48729     u8 *aDataEnd;        /* One byte past the end of usable data */
 48573  48730     u8 *aCellIdx;        /* The cell index area */
 48574  48731     DbPage *pDbPage;     /* Pager page handle */
 48575  48732     Pgno pgno;           /* Page number for this page */
 48576  48733   };
................................................................................
 48770  48927   ** found at self->pBt->mutex. 
 48771  48928   */
 48772  48929   struct BtCursor {
 48773  48930     Btree *pBtree;            /* The Btree to which this cursor belongs */
 48774  48931     BtShared *pBt;            /* The BtShared this cursor points to */
 48775  48932     BtCursor *pNext, *pPrev;  /* Forms a linked list of all cursors */
 48776  48933     struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
        48934  +#ifndef SQLITE_OMIT_INCRBLOB
        48935  +  Pgno *aOverflow;          /* Cache of overflow page locations */
        48936  +#endif
 48777  48937     Pgno pgnoRoot;            /* The root page of this tree */
 48778  48938     sqlite3_int64 cachedRowid; /* Next rowid cache.  0 means not valid */
 48779  48939     CellInfo info;            /* A parse of the cell we are pointing at */
 48780  48940     i64 nKey;        /* Size of pKey, or last integer key */
 48781  48941     void *pKey;      /* Saved key that was cursor's last known position */
 48782  48942     int skipNext;    /* Prev() is noop if negative. Next() is noop if positive */
 48783  48943     u8 wrFlag;                /* True if writable */
 48784  48944     u8 atLast;                /* Cursor pointing to the last entry */
 48785  48945     u8 validNKey;             /* True if info.nKey is valid */
 48786  48946     u8 eState;                /* One of the CURSOR_XXX constants (see below) */
 48787  48947   #ifndef SQLITE_OMIT_INCRBLOB
 48788         -  Pgno *aOverflow;          /* Cache of overflow page locations */
 48789  48948     u8 isIncrblobHandle;      /* True if this cursor is an incr. io handle */
 48790  48949   #endif
 48791  48950     i16 iPage;                            /* Index of current page in apPage */
 48792  48951     u16 aiIdx[BTCURSOR_MAX_DEPTH];        /* Current index in apPage[i] */
 48793  48952     MemPage *apPage[BTCURSOR_MAX_DEPTH];  /* Pages from root to current page */
 48794  48953   };
 48795  48954   
................................................................................
 48910  49069   ** This structure is passed around through all the sanity checking routines
 48911  49070   ** in order to keep track of some global state information.
 48912  49071   */
 48913  49072   typedef struct IntegrityCk IntegrityCk;
 48914  49073   struct IntegrityCk {
 48915  49074     BtShared *pBt;    /* The tree being checked out */
 48916  49075     Pager *pPager;    /* The associated pager.  Also accessible by pBt->pPager */
 48917         -  Pgno nPage;       /* Number of pages in the database */
 48918  49076     int *anRef;       /* Number of times each page is referenced */
        49077  +  Pgno nPage;       /* Number of pages in the database */
 48919  49078     int mxErr;        /* Stop accumulating errors when this reaches zero */
 48920  49079     int nErr;         /* Number of messages written to zErrMsg so far */
 48921  49080     int mallocFailed; /* A memory allocation error has occurred */
 48922  49081     StrAccum errMsg;  /* Accumulate the error message text here */
 48923  49082   };
 48924  49083   
 48925  49084   /*
................................................................................
 50071  50230   ** pages that do contain overflow cells.
 50072  50231   */
 50073  50232   static u8 *findOverflowCell(MemPage *pPage, int iCell){
 50074  50233     int i;
 50075  50234     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
 50076  50235     for(i=pPage->nOverflow-1; i>=0; i--){
 50077  50236       int k;
 50078         -    struct _OvflCell *pOvfl;
 50079         -    pOvfl = &pPage->aOvfl[i];
 50080         -    k = pOvfl->idx;
        50237  +    k = pPage->aiOvfl[i];
 50081  50238       if( k<=iCell ){
 50082  50239         if( k==iCell ){
 50083         -        return pOvfl->pCell;
        50240  +        return pPage->apOvfl[i];
 50084  50241         }
 50085  50242         iCell--;
 50086  50243       }
 50087  50244     }
 50088  50245     return findCell(pPage, iCell);
 50089  50246   }
 50090  50247   
................................................................................
 50890  51047   ** be exclusively in memory, or it might use a disk-based memory cache.
 50891  51048   ** Either way, the ephemeral database will be automatically deleted 
 50892  51049   ** when sqlite3BtreeClose() is called.
 50893  51050   **
 50894  51051   ** If zFilename is ":memory:" then an in-memory database is created
 50895  51052   ** that is automatically destroyed when it is closed.
 50896  51053   **
 50897         -** The "flags" parameter is a bitmask that might contain bits
 50898         -** BTREE_OMIT_JOURNAL and/or BTREE_NO_READLOCK.  The BTREE_NO_READLOCK
 50899         -** bit is also set if the SQLITE_NoReadlock flags is set in db->flags.
 50900         -** These flags are passed through into sqlite3PagerOpen() and must
 50901         -** be the same values as PAGER_OMIT_JOURNAL and PAGER_NO_READLOCK.
        51054  +** The "flags" parameter is a bitmask that might contain bits like
        51055  +** BTREE_OMIT_JOURNAL and/or BTREE_MEMORY.
 50902  51056   **
 50903  51057   ** If the database is already opened in the same database connection
 50904  51058   ** and we are in shared cache mode, then the open will fail with an
 50905  51059   ** SQLITE_CONSTRAINT error.  We cannot allow two or more BtShared
 50906  51060   ** objects in the same database connection since doing so will lead
 50907  51061   ** to problems with locking.
 50908  51062   */
................................................................................
 50941  51095   
 50942  51096     /* Only a BTREE_SINGLE database can be BTREE_UNORDERED */
 50943  51097     assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 );
 50944  51098   
 50945  51099     /* A BTREE_SINGLE database is always a temporary and/or ephemeral */
 50946  51100     assert( (flags & BTREE_SINGLE)==0 || isTempDb );
 50947  51101   
 50948         -  if( db->flags & SQLITE_NoReadlock ){
 50949         -    flags |= BTREE_NO_READLOCK;
 50950         -  }
 50951  51102     if( isMemdb ){
 50952  51103       flags |= BTREE_MEMORY;
 50953  51104     }
 50954  51105     if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){
 50955  51106       vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB;
 50956  51107     }
 50957  51108     p = sqlite3MallocZero(sizeof(Btree));
................................................................................
 51250  51401       }
 51251  51402     }
 51252  51403   
 51253  51404     /* Rollback any active transaction and free the handle structure.
 51254  51405     ** The call to sqlite3BtreeRollback() drops any table-locks held by
 51255  51406     ** this handle.
 51256  51407     */
 51257         -  sqlite3BtreeRollback(p);
        51408  +  sqlite3BtreeRollback(p, SQLITE_OK);
 51258  51409     sqlite3BtreeLeave(p);
 51259  51410   
 51260  51411     /* If there are still other outstanding references to the shared-btree
 51261  51412     ** structure, return now. The remainder of this procedure cleans 
 51262  51413     ** up the shared-btree.
 51263  51414     */
 51264  51415     assert( p->wantToLock==0 && p->locked==0 );
................................................................................
 52488  52639   ** the rollback.  The rollback may have deleted tables
 52489  52640   ** or moved root pages, so it is not sufficient to
 52490  52641   ** save the state of the cursor.  The cursor must be
 52491  52642   ** invalidated.
 52492  52643   */
 52493  52644   SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode){
 52494  52645     BtCursor *p;
        52646  +  if( pBtree==0 ) return;
 52495  52647     sqlite3BtreeEnter(pBtree);
 52496  52648     for(p=pBtree->pBt->pCursor; p; p=p->pNext){
 52497  52649       int i;
 52498  52650       sqlite3BtreeClearCursor(p);
 52499  52651       p->eState = CURSOR_FAULT;
 52500  52652       p->skipNext = errCode;
 52501  52653       for(i=0; i<=p->iPage; i++){
................................................................................
 52511  52663   ** invalided by this operation.  Any attempt to use a cursor
 52512  52664   ** that was open at the beginning of this operation will result
 52513  52665   ** in an error.
 52514  52666   **
 52515  52667   ** This will release the write lock on the database file.  If there
 52516  52668   ** are no active cursors, it also releases the read lock.
 52517  52669   */
 52518         -SQLITE_PRIVATE int sqlite3BtreeRollback(Btree *p){
        52670  +SQLITE_PRIVATE int sqlite3BtreeRollback(Btree *p, int tripCode){
 52519  52671     int rc;
 52520  52672     BtShared *pBt = p->pBt;
 52521  52673     MemPage *pPage1;
 52522  52674   
 52523  52675     sqlite3BtreeEnter(p);
 52524         -  rc = saveAllCursors(pBt, 0, 0);
 52525         -#ifndef SQLITE_OMIT_SHARED_CACHE
 52526         -  if( rc!=SQLITE_OK ){
 52527         -    /* This is a horrible situation. An IO or malloc() error occurred whilst
 52528         -    ** trying to save cursor positions. If this is an automatic rollback (as
 52529         -    ** the result of a constraint, malloc() failure or IO error) then 
 52530         -    ** the cache may be internally inconsistent (not contain valid trees) so
 52531         -    ** we cannot simply return the error to the caller. Instead, abort 
 52532         -    ** all queries that may be using any of the cursors that failed to save.
 52533         -    */
 52534         -    sqlite3BtreeTripAllCursors(p, rc);
        52676  +  if( tripCode==SQLITE_OK ){
        52677  +    rc = tripCode = saveAllCursors(pBt, 0, 0);
        52678  +  }else{
        52679  +    rc = SQLITE_OK;
 52535  52680     }
 52536         -#endif
        52681  +  if( tripCode ){
        52682  +    sqlite3BtreeTripAllCursors(p, tripCode);
        52683  +  }
 52537  52684     btreeIntegrity(p);
 52538  52685   
 52539  52686     if( p->inTrans==TRANS_WRITE ){
 52540  52687       int rc2;
 52541  52688   
 52542  52689       assert( TRANS_WRITE==pBt->inTransaction );
 52543  52690       rc2 = sqlite3PagerRollback(pBt->pPager);
................................................................................
 53395  53542     pCur->validNKey = 0;
 53396  53543     if( pNewPage->nCell<1 || pNewPage->intKey!=pCur->apPage[i]->intKey ){
 53397  53544       return SQLITE_CORRUPT_BKPT;
 53398  53545     }
 53399  53546     return SQLITE_OK;
 53400  53547   }
 53401  53548   
 53402         -#ifndef NDEBUG
        53549  +#if 0
 53403  53550   /*
 53404  53551   ** Page pParent is an internal (non-leaf) tree page. This function 
 53405  53552   ** asserts that page number iChild is the left-child if the iIdx'th
 53406  53553   ** cell in page pParent. Or, if iIdx is equal to the total number of
 53407  53554   ** cells in pParent, that page number iChild is the right-child of
 53408  53555   ** the page.
 53409  53556   */
................................................................................
 53428  53575   ** the largest cell index.
 53429  53576   */
 53430  53577   static void moveToParent(BtCursor *pCur){
 53431  53578     assert( cursorHoldsMutex(pCur) );
 53432  53579     assert( pCur->eState==CURSOR_VALID );
 53433  53580     assert( pCur->iPage>0 );
 53434  53581     assert( pCur->apPage[pCur->iPage] );
        53582  +
        53583  +  /* UPDATE: It is actually possible for the condition tested by the assert
        53584  +  ** below to be untrue if the database file is corrupt. This can occur if
        53585  +  ** one cursor has modified page pParent while a reference to it is held 
        53586  +  ** by a second cursor. Which can only happen if a single page is linked
        53587  +  ** into more than one b-tree structure in a corrupt database.  */
        53588  +#if 0
 53435  53589     assertParentIndex(
 53436  53590       pCur->apPage[pCur->iPage-1], 
 53437  53591       pCur->aiIdx[pCur->iPage-1], 
 53438  53592       pCur->apPage[pCur->iPage]->pgno
 53439  53593     );
        53594  +#endif
        53595  +  testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
        53596  +
 53440  53597     releasePage(pCur->apPage[pCur->iPage]);
 53441  53598     pCur->iPage--;
 53442  53599     pCur->info.nSize = 0;
 53443  53600     pCur->validNKey = 0;
 53444  53601   }
 53445  53602   
 53446  53603   /*
................................................................................
 53902  54059       return SQLITE_OK;
 53903  54060     }
 53904  54061     pCur->skipNext = 0;
 53905  54062   
 53906  54063     pPage = pCur->apPage[pCur->iPage];
 53907  54064     idx = ++pCur->aiIdx[pCur->iPage];
 53908  54065     assert( pPage->isInit );
 53909         -  assert( idx<=pPage->nCell );
        54066  +
        54067  +  /* If the database file is corrupt, it is possible for the value of idx 
        54068  +  ** to be invalid here. This can only occur if a second cursor modifies
        54069  +  ** the page while cursor pCur is holding a reference to it. Which can
        54070  +  ** only happen if the database is corrupt in such a way as to link the
        54071  +  ** page into more than one b-tree structure. */
        54072  +  testcase( idx>pPage->nCell );
 53910  54073   
 53911  54074     pCur->info.nSize = 0;
 53912  54075     pCur->validNKey = 0;
 53913  54076     if( idx>=pPage->nCell ){
 53914  54077       if( !pPage->leaf ){
 53915  54078         rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
 53916  54079         if( rc ) return rc;
................................................................................
 54712  54875   /*
 54713  54876   ** Insert a new cell on pPage at cell index "i".  pCell points to the
 54714  54877   ** content of the cell.
 54715  54878   **
 54716  54879   ** If the cell content will fit on the page, then put it there.  If it
 54717  54880   ** will not fit, then make a copy of the cell content into pTemp if
 54718  54881   ** pTemp is not null.  Regardless of pTemp, allocate a new entry
 54719         -** in pPage->aOvfl[] and make it point to the cell content (either
        54882  +** in pPage->apOvfl[] and make it point to the cell content (either
 54720  54883   ** in pTemp or the original pCell) and also record its index. 
 54721  54884   ** Allocating a new entry in pPage->aCell[] implies that 
 54722  54885   ** pPage->nOverflow is incremented.
 54723  54886   **
 54724  54887   ** If nSkip is non-zero, then do not copy the first nSkip bytes of the
 54725  54888   ** cell. The caller will overwrite them after this function returns. If
 54726  54889   ** nSkip is non-zero, then pCell may not point to an invalid memory location 
................................................................................
 54746  54909   
 54747  54910     int nSkip = (iChild ? 4 : 0);
 54748  54911   
 54749  54912     if( *pRC ) return;
 54750  54913   
 54751  54914     assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
 54752  54915     assert( pPage->nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=10921 );
 54753         -  assert( pPage->nOverflow<=ArraySize(pPage->aOvfl) );
        54916  +  assert( pPage->nOverflow<=ArraySize(pPage->apOvfl) );
        54917  +  assert( ArraySize(pPage->apOvfl)==ArraySize(pPage->aiOvfl) );
 54754  54918     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
 54755  54919     /* The cell should normally be sized correctly.  However, when moving a
 54756  54920     ** malformed cell from a leaf page to an interior page, if the cell size
 54757  54921     ** wanted to be less than 4 but got rounded up to 4 on the leaf, then size
 54758  54922     ** might be less than 8 (leaf-size + pointer) on the interior node.  Hence
 54759  54923     ** the term after the || in the following assert(). */
 54760  54924     assert( sz==cellSizePtr(pPage, pCell) || (sz==8 && iChild>0) );
................................................................................
 54763  54927         memcpy(pTemp+nSkip, pCell+nSkip, sz-nSkip);
 54764  54928         pCell = pTemp;
 54765  54929       }
 54766  54930       if( iChild ){
 54767  54931         put4byte(pCell, iChild);
 54768  54932       }
 54769  54933       j = pPage->nOverflow++;
 54770         -    assert( j<(int)(sizeof(pPage->aOvfl)/sizeof(pPage->aOvfl[0])) );
 54771         -    pPage->aOvfl[j].pCell = pCell;
 54772         -    pPage->aOvfl[j].idx = (u16)i;
        54934  +    assert( j<(int)(sizeof(pPage->apOvfl)/sizeof(pPage->apOvfl[0])) );
        54935  +    pPage->apOvfl[j] = pCell;
        54936  +    pPage->aiOvfl[j] = (u16)i;
 54773  54937     }else{
 54774  54938       int rc = sqlite3PagerWrite(pPage->pDbPage);
 54775  54939       if( rc!=SQLITE_OK ){
 54776  54940         *pRC = rc;
 54777  54941         return;
 54778  54942       }
 54779  54943       assert( sqlite3PagerIswriteable(pPage->pDbPage) );
................................................................................
 54913  55077     ** may be inserted. If both these operations are successful, proceed.
 54914  55078     */
 54915  55079     rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
 54916  55080   
 54917  55081     if( rc==SQLITE_OK ){
 54918  55082   
 54919  55083       u8 *pOut = &pSpace[4];
 54920         -    u8 *pCell = pPage->aOvfl[0].pCell;
        55084  +    u8 *pCell = pPage->apOvfl[0];
 54921  55085       u16 szCell = cellSizePtr(pPage, pCell);
 54922  55086       u8 *pStop;
 54923  55087   
 54924  55088       assert( sqlite3PagerIswriteable(pNew->pDbPage) );
 54925  55089       assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
 54926  55090       zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
 54927  55091       assemblePage(pNew, 1, &pCell, &szCell);
................................................................................
 55023  55187   ** on page pFrom to page pTo. If page pFrom was not a leaf page, then
 55024  55188   ** the pointer-map entries for each child page are updated so that the
 55025  55189   ** parent page stored in the pointer map is page pTo. If pFrom contained
 55026  55190   ** any cells with overflow page pointers, then the corresponding pointer
 55027  55191   ** map entries are also updated so that the parent page is page pTo.
 55028  55192   **
 55029  55193   ** If pFrom is currently carrying any overflow cells (entries in the
 55030         -** MemPage.aOvfl[] array), they are not copied to pTo. 
        55194  +** MemPage.apOvfl[] array), they are not copied to pTo. 
 55031  55195   **
 55032  55196   ** Before returning, page pTo is reinitialized using btreeInitPage().
 55033  55197   **
 55034  55198   ** The performance of this function is not critical. It is only used by 
 55035  55199   ** the balance_shallower() and balance_deeper() procedures, neither of
 55036  55200   ** which are called often under normal circumstances.
 55037  55201   */
................................................................................
 55160  55324   
 55161  55325     /* At this point pParent may have at most one overflow cell. And if
 55162  55326     ** this overflow cell is present, it must be the cell with 
 55163  55327     ** index iParentIdx. This scenario comes about when this function
 55164  55328     ** is called (indirectly) from sqlite3BtreeDelete().
 55165  55329     */
 55166  55330     assert( pParent->nOverflow==0 || pParent->nOverflow==1 );
 55167         -  assert( pParent->nOverflow==0 || pParent->aOvfl[0].idx==iParentIdx );
        55331  +  assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );
 55168  55332   
 55169  55333     if( !aOvflSpace ){
 55170  55334       return SQLITE_NOMEM;
 55171  55335     }
 55172  55336   
 55173  55337     /* Find the sibling pages to balance. Also locate the cells in pParent 
 55174  55338     ** that divide the siblings. An attempt is made to find NN siblings on 
................................................................................
 55207  55371       if( rc ){
 55208  55372         memset(apOld, 0, (i+1)*sizeof(MemPage*));
 55209  55373         goto balance_cleanup;
 55210  55374       }
 55211  55375       nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
 55212  55376       if( (i--)==0 ) break;
 55213  55377   
 55214         -    if( i+nxDiv==pParent->aOvfl[0].idx && pParent->nOverflow ){
 55215         -      apDiv[i] = pParent->aOvfl[0].pCell;
        55378  +    if( i+nxDiv==pParent->aiOvfl[0] && pParent->nOverflow ){
        55379  +      apDiv[i] = pParent->apOvfl[0];
 55216  55380         pgno = get4byte(apDiv[i]);
 55217  55381         szNew[i] = cellSizePtr(pParent, apDiv[i]);
 55218  55382         pParent->nOverflow = 0;
 55219  55383       }else{
 55220  55384         apDiv[i] = findCell(pParent, i+nxDiv-pParent->nOverflow);
 55221  55385         pgno = get4byte(apDiv[i]);
 55222  55386         szNew[i] = cellSizePtr(pParent, apDiv[i]);
................................................................................
 55649  55813       ** setting a pointer map entry is a relatively expensive operation, this
 55650  55814       ** code only sets pointer map entries for child or overflow pages that have
 55651  55815       ** actually moved between pages.  */
 55652  55816       MemPage *pNew = apNew[0];
 55653  55817       MemPage *pOld = apCopy[0];
 55654  55818       int nOverflow = pOld->nOverflow;
 55655  55819       int iNextOld = pOld->nCell + nOverflow;
 55656         -    int iOverflow = (nOverflow ? pOld->aOvfl[0].idx : -1);
        55820  +    int iOverflow = (nOverflow ? pOld->aiOvfl[0] : -1);
 55657  55821       j = 0;                             /* Current 'old' sibling page */
 55658  55822       k = 0;                             /* Current 'new' sibling page */
 55659  55823       for(i=0; i<nCell; i++){
 55660  55824         int isDivider = 0;
 55661  55825         while( i==iNextOld ){
 55662  55826           /* Cell i is the cell immediately following the last cell on old
 55663  55827           ** sibling page j. If the siblings are not leaf pages of an
 55664  55828           ** intkey b-tree, then cell i was a divider cell. */
 55665  55829           assert( j+1 < ArraySize(apCopy) );
 55666  55830           pOld = apCopy[++j];
 55667  55831           iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow;
 55668  55832           if( pOld->nOverflow ){
 55669  55833             nOverflow = pOld->nOverflow;
 55670         -          iOverflow = i + !leafData + pOld->aOvfl[0].idx;
        55834  +          iOverflow = i + !leafData + pOld->aiOvfl[0];
 55671  55835           }
 55672  55836           isDivider = !leafData;  
 55673  55837         }
 55674  55838   
 55675  55839         assert(nOverflow>0 || iOverflow<i );
 55676         -      assert(nOverflow<2 || pOld->aOvfl[0].idx==pOld->aOvfl[1].idx-1);
 55677         -      assert(nOverflow<3 || pOld->aOvfl[1].idx==pOld->aOvfl[2].idx-1);
        55840  +      assert(nOverflow<2 || pOld->aiOvfl[0]==pOld->aiOvfl[1]-1);
        55841  +      assert(nOverflow<3 || pOld->aiOvfl[1]==pOld->aiOvfl[2]-1);
 55678  55842         if( i==iOverflow ){
 55679  55843           isDivider = 1;
 55680  55844           if( (--nOverflow)>0 ){
 55681  55845             iOverflow++;
 55682  55846           }
 55683  55847         }
 55684  55848   
................................................................................
 55791  55955     assert( sqlite3PagerIswriteable(pChild->pDbPage) );
 55792  55956     assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
 55793  55957     assert( pChild->nCell==pRoot->nCell );
 55794  55958   
 55795  55959     TRACE(("BALANCE: copy root %d into %d\n", pRoot->pgno, pChild->pgno));
 55796  55960   
 55797  55961     /* Copy the overflow cells from pRoot to pChild */
 55798         -  memcpy(pChild->aOvfl, pRoot->aOvfl, pRoot->nOverflow*sizeof(pRoot->aOvfl[0]));
        55962  +  memcpy(pChild->aiOvfl, pRoot->aiOvfl,
        55963  +         pRoot->nOverflow*sizeof(pRoot->aiOvfl[0]));
        55964  +  memcpy(pChild->apOvfl, pRoot->apOvfl,
        55965  +         pRoot->nOverflow*sizeof(pRoot->apOvfl[0]));
 55799  55966     pChild->nOverflow = pRoot->nOverflow;
 55800  55967   
 55801  55968     /* Zero the contents of pRoot. Then install pChild as the right-child. */
 55802  55969     zeroPage(pRoot, pChild->aData[0] & ~PTF_LEAF);
 55803  55970     put4byte(&pRoot->aData[pRoot->hdrOffset+8], pgnoChild);
 55804  55971   
 55805  55972     *ppChild = pChild;
................................................................................
 55854  56021         int const iIdx = pCur->aiIdx[iPage-1];
 55855  56022   
 55856  56023         rc = sqlite3PagerWrite(pParent->pDbPage);
 55857  56024         if( rc==SQLITE_OK ){
 55858  56025   #ifndef SQLITE_OMIT_QUICKBALANCE
 55859  56026           if( pPage->hasData
 55860  56027            && pPage->nOverflow==1
 55861         -         && pPage->aOvfl[0].idx==pPage->nCell
        56028  +         && pPage->aiOvfl[0]==pPage->nCell
 55862  56029            && pParent->pgno!=1
 55863  56030            && pParent->nCell==iIdx
 55864  56031           ){
 55865  56032             /* Call balance_quick() to create a new sibling of pPage on which
 55866  56033             ** to store the overflow cell. balance_quick() inserts a new cell
 55867  56034             ** into pParent, which may cause pParent overflow. If this
 55868  56035             ** happens, the next interation of the do-loop will balance pParent 
................................................................................
 58031  58198       while( *pp!=p ){
 58032  58199         pp = &(*pp)->pNext;
 58033  58200       }
 58034  58201       *pp = p->pNext;
 58035  58202     }
 58036  58203   
 58037  58204     /* If a transaction is still open on the Btree, roll it back. */
 58038         -  sqlite3BtreeRollback(p->pDest);
        58205  +  sqlite3BtreeRollback(p->pDest, SQLITE_OK);
 58039  58206   
 58040  58207     /* Set the error code of the destination database handle. */
 58041  58208     rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
 58042  58209     sqlite3Error(p->pDestDb, rc, 0);
 58043  58210   
 58044  58211     /* Exit the mutexes and free the backup context structure. */
 58045  58212     if( p->pDestDb ){
................................................................................
 58275  58442       }
 58276  58443     }
 58277  58444   
 58278  58445     if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){
 58279  58446       memcpy(pMem->zMalloc, pMem->z, pMem->n);
 58280  58447     }
 58281  58448     if( pMem->flags&MEM_Dyn && pMem->xDel ){
        58449  +    assert( pMem->xDel!=SQLITE_DYNAMIC );
 58282  58450       pMem->xDel((void *)(pMem->z));
 58283  58451     }
 58284  58452   
 58285  58453     pMem->z = pMem->zMalloc;
 58286  58454     if( pMem->z==0 ){
 58287  58455       pMem->flags = MEM_Null;
 58288  58456     }else{
................................................................................
 58454  58622     assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
 58455  58623     if( p->flags&MEM_Agg ){
 58456  58624       sqlite3VdbeMemFinalize(p, p->u.pDef);
 58457  58625       assert( (p->flags & MEM_Agg)==0 );
 58458  58626       sqlite3VdbeMemRelease(p);
 58459  58627     }else if( p->flags&MEM_Dyn && p->xDel ){
 58460  58628       assert( (p->flags&MEM_RowSet)==0 );
        58629  +    assert( p->xDel!=SQLITE_DYNAMIC );
 58461  58630       p->xDel((void *)p->z);
 58462  58631       p->xDel = 0;
 58463  58632     }else if( p->flags&MEM_RowSet ){
 58464  58633       sqlite3RowSetClear(p->u.pRowSet);
 58465  58634     }else if( p->flags&MEM_Frame ){
 58466  58635       sqlite3VdbeMemSetNull(p);
 58467  58636     }
................................................................................
 58596  58765     **
 58597  58766     ** The second and third terms in the following conditional enforces
 58598  58767     ** the second condition under the assumption that addition overflow causes
 58599  58768     ** values to wrap around.  On x86 hardware, the third term is always
 58600  58769     ** true and could be omitted.  But we leave it in because other
 58601  58770     ** architectures might behave differently.
 58602  58771     */
 58603         -  if( pMem->r==(double)pMem->u.i && pMem->u.i>SMALLEST_INT64
 58604         -      && ALWAYS(pMem->u.i<LARGEST_INT64) ){
        58772  +  if( pMem->r==(double)pMem->u.i
        58773  +   && pMem->u.i>SMALLEST_INT64
        58774  +#if defined(__i486__) || defined(__x86_64__)
        58775  +   && ALWAYS(pMem->u.i<LARGEST_INT64)
        58776  +#else
        58777  +   && pMem->u.i<LARGEST_INT64
        58778  +#endif
        58779  +  ){
 58605  58780       pMem->flags |= MEM_Int;
 58606  58781     }
 58607  58782   }
 58608  58783   
 58609  58784   /*
 58610  58785   ** Convert pMem to type integer.  Invalidate any prior representations.
 58611  58786   */
................................................................................
 59571  59746   ** The VDBE knows that a P2 value is a label because labels are
 59572  59747   ** always negative and P2 values are suppose to be non-negative.
 59573  59748   ** Hence, a negative P2 value is a label that has yet to be resolved.
 59574  59749   **
 59575  59750   ** Zero is returned if a malloc() fails.
 59576  59751   */
 59577  59752   SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *p){
 59578         -  int i;
 59579         -  i = p->nLabel++;
        59753  +  int i = p->nLabel++;
 59580  59754     assert( p->magic==VDBE_MAGIC_INIT );
 59581         -  if( i>=p->nLabelAlloc ){
 59582         -    int n = p->nLabelAlloc*2 + 5;
 59583         -    p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
 59584         -                                       n*sizeof(p->aLabel[0]));
 59585         -    p->nLabelAlloc = sqlite3DbMallocSize(p->db, p->aLabel)/sizeof(p->aLabel[0]);
        59755  +  if( (i & (i-1))==0 ){
        59756  +    p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, 
        59757  +                                       (i*2+1)*sizeof(p->aLabel[0]));
 59586  59758     }
 59587  59759     if( p->aLabel ){
 59588  59760       p->aLabel[i] = -1;
 59589  59761     }
 59590  59762     return -1-i;
 59591  59763   }
 59592  59764   
................................................................................
 61336  61508     assert( cnt==db->activeVdbeCnt );
 61337  61509     assert( nWrite==db->writeVdbeCnt );
 61338  61510   }
 61339  61511   #else
 61340  61512   #define checkActiveVdbeCnt(x)
 61341  61513   #endif
 61342  61514   
 61343         -/*
 61344         -** For every Btree that in database connection db which 
 61345         -** has been modified, "trip" or invalidate each cursor in
 61346         -** that Btree might have been modified so that the cursor
 61347         -** can never be used again.  This happens when a rollback
 61348         -*** occurs.  We have to trip all the other cursors, even
 61349         -** cursor from other VMs in different database connections,
 61350         -** so that none of them try to use the data at which they
 61351         -** were pointing and which now may have been changed due
 61352         -** to the rollback.
 61353         -**
 61354         -** Remember that a rollback can delete tables complete and
 61355         -** reorder rootpages.  So it is not sufficient just to save
 61356         -** the state of the cursor.  We have to invalidate the cursor
 61357         -** so that it is never used again.
 61358         -*/
 61359         -static void invalidateCursorsOnModifiedBtrees(sqlite3 *db){
 61360         -  int i;
 61361         -  for(i=0; i<db->nDb; i++){
 61362         -    Btree *p = db->aDb[i].pBt;
 61363         -    if( p && sqlite3BtreeIsInTrans(p) ){
 61364         -      sqlite3BtreeTripAllCursors(p, SQLITE_ABORT);
 61365         -    }
 61366         -  }
 61367         -}
 61368         -
 61369  61515   /*
 61370  61516   ** If the Vdbe passed as the first argument opened a statement-transaction,
 61371  61517   ** close it now. Argument eOp must be either SAVEPOINT_ROLLBACK or
 61372  61518   ** SAVEPOINT_RELEASE. If it is SAVEPOINT_ROLLBACK, then the statement
 61373  61519   ** transaction is rolled back. If eOp is SAVEPOINT_RELEASE, then the 
 61374  61520   ** statement transaction is commtted.
 61375  61521   **
................................................................................
 61526  61672         if( !p->readOnly || mrc!=SQLITE_INTERRUPT ){
 61527  61673           if( (mrc==SQLITE_NOMEM || mrc==SQLITE_FULL) && p->usesStmtJournal ){
 61528  61674             eStatementOp = SAVEPOINT_ROLLBACK;
 61529  61675           }else{
 61530  61676             /* We are forced to roll back the active transaction. Before doing
 61531  61677             ** so, abort any other statements this handle currently has active.
 61532  61678             */
 61533         -          invalidateCursorsOnModifiedBtrees(db);
 61534         -          sqlite3RollbackAll(db);
        61679  +          sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
 61535  61680             sqlite3CloseSavepoints(db);
 61536  61681             db->autoCommit = 1;
 61537  61682           }
 61538  61683         }
 61539  61684       }
 61540  61685   
 61541  61686       /* Check for immediate foreign key violations. */
................................................................................
 61569  61714             rc = vdbeCommit(db, p);
 61570  61715           }
 61571  61716           if( rc==SQLITE_BUSY && p->readOnly ){
 61572  61717             sqlite3VdbeLeave(p);
 61573  61718             return SQLITE_BUSY;
 61574  61719           }else if( rc!=SQLITE_OK ){
 61575  61720             p->rc = rc;
 61576         -          sqlite3RollbackAll(db);
        61721  +          sqlite3RollbackAll(db, SQLITE_OK);
 61577  61722           }else{
 61578  61723             db->nDeferredCons = 0;
 61579  61724             sqlite3CommitInternalChanges(db);
 61580  61725           }
 61581  61726         }else{
 61582         -        sqlite3RollbackAll(db);
        61727  +        sqlite3RollbackAll(db, SQLITE_OK);
 61583  61728         }
 61584  61729         db->nStatement = 0;
 61585  61730       }else if( eStatementOp==0 ){
 61586  61731         if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
 61587  61732           eStatementOp = SAVEPOINT_RELEASE;
 61588  61733         }else if( p->errorAction==OE_Abort ){
 61589  61734           eStatementOp = SAVEPOINT_ROLLBACK;
 61590  61735         }else{
 61591         -        invalidateCursorsOnModifiedBtrees(db);
 61592         -        sqlite3RollbackAll(db);
        61736  +        sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
 61593  61737           sqlite3CloseSavepoints(db);
 61594  61738           db->autoCommit = 1;
 61595  61739         }
 61596  61740       }
 61597  61741     
 61598  61742       /* If eStatementOp is non-zero, then a statement transaction needs to
 61599  61743       ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
................................................................................
 61605  61749         rc = sqlite3VdbeCloseStatement(p, eStatementOp);
 61606  61750         if( rc ){
 61607  61751           if( p->rc==SQLITE_OK || p->rc==SQLITE_CONSTRAINT ){
 61608  61752             p->rc = rc;
 61609  61753             sqlite3DbFree(db, p->zErrMsg);
 61610  61754             p->zErrMsg = 0;
 61611  61755           }
 61612         -        invalidateCursorsOnModifiedBtrees(db);
 61613         -        sqlite3RollbackAll(db);
        61756  +        sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
 61614  61757           sqlite3CloseSavepoints(db);
 61615  61758           db->autoCommit = 1;
 61616  61759         }
 61617  61760       }
 61618  61761     
 61619  61762       /* If this was an INSERT, UPDATE or DELETE and no statement transaction
 61620  61763       ** has been rolled back, update the database connection change-counter. 
................................................................................
 61623  61766         if( eStatementOp!=SAVEPOINT_ROLLBACK ){
 61624  61767           sqlite3VdbeSetChanges(db, p->nChange);
 61625  61768         }else{
 61626  61769           sqlite3VdbeSetChanges(db, 0);
 61627  61770         }
 61628  61771         p->nChange = 0;
 61629  61772       }
 61630         -  
 61631         -    /* Rollback or commit any schema changes that occurred. */
 61632         -    if( p->rc!=SQLITE_OK && db->flags&SQLITE_InternChanges ){
 61633         -      sqlite3ResetInternalSchema(db, -1);
 61634         -      db->flags = (db->flags | SQLITE_InternChanges);
 61635         -    }
 61636  61773   
 61637  61774       /* Release the locks */
 61638  61775       sqlite3VdbeLeave(p);
 61639  61776     }
 61640  61777   
 61641  61778     /* We have successfully halted and closed the VM.  Record this fact. */
 61642  61779     if( p->pc>=0 ){
................................................................................
 66049  66186     break;
 66050  66187   
 66051  66188   arithmetic_result_is_null:
 66052  66189     sqlite3VdbeMemSetNull(pOut);
 66053  66190     break;
 66054  66191   }
 66055  66192   
 66056         -/* Opcode: CollSeq * * P4
        66193  +/* Opcode: CollSeq P1 * * P4
 66057  66194   **
 66058  66195   ** P4 is a pointer to a CollSeq struct. If the next call to a user function
 66059  66196   ** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
 66060  66197   ** be returned. This is used by the built-in min(), max() and nullif()
 66061  66198   ** functions.
        66199  +**
        66200  +** If P1 is not zero, then it is a register that a subsequent min() or
        66201  +** max() aggregate will set to 1 if the current row is not the minimum or
        66202  +** maximum.  The P1 register is initialized to 0 by this instruction.
 66062  66203   **
 66063  66204   ** The interface used by the implementation of the aforementioned functions
 66064  66205   ** to retrieve the collation sequence set by this opcode is not available
 66065  66206   ** publicly, only to user functions defined in func.c.
 66066  66207   */
 66067  66208   case OP_CollSeq: {
 66068  66209     assert( pOp->p4type==P4_COLLSEQ );
        66210  +  if( pOp->p1 ){
        66211  +    sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
        66212  +  }
 66069  66213     break;
 66070  66214   }
 66071  66215   
 66072  66216   /* Opcode: Function P1 P2 P3 P4 P5
 66073  66217   **
 66074  66218   ** Invoke a user function (P4 is a pointer to a Function structure that
 66075  66219   ** defines the function) with P5 arguments taken from register P2 and
................................................................................
 67417  67561         u.ar.pSavepoint = u.ar.pSavepoint->pNext
 67418  67562       ){
 67419  67563         u.ar.iSavepoint++;
 67420  67564       }
 67421  67565       if( !u.ar.pSavepoint ){
 67422  67566         sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.ar.zName);
 67423  67567         rc = SQLITE_ERROR;
 67424         -    }else if(
 67425         -        db->writeVdbeCnt>0 || (u.ar.p1==SAVEPOINT_ROLLBACK && db->activeVdbeCnt>1)
 67426         -    ){
        67568  +    }else if( db->writeVdbeCnt>0 && u.ar.p1==SAVEPOINT_RELEASE ){
 67427  67569         /* It is not possible to release (commit) a savepoint if there are
 67428         -      ** active write statements. It is not possible to rollback a savepoint
 67429         -      ** if there are any active statements at all.
        67570  +      ** active write statements.
 67430  67571         */
 67431  67572         sqlite3SetString(&p->zErrMsg, db,
 67432         -        "cannot %s savepoint - SQL statements in progress",
 67433         -        (u.ar.p1==SAVEPOINT_ROLLBACK ? "rollback": "release")
        67573  +        "cannot release savepoint - SQL statements in progress"
 67434  67574         );
 67435  67575         rc = SQLITE_BUSY;
 67436  67576       }else{
 67437  67577   
 67438  67578         /* Determine whether or not this is a transaction savepoint. If so,
 67439  67579         ** and this is a RELEASE command, then the current transaction
 67440  67580         ** is committed.
................................................................................
 67451  67591             p->rc = rc = SQLITE_BUSY;
 67452  67592             goto vdbe_return;
 67453  67593           }
 67454  67594           db->isTransactionSavepoint = 0;
 67455  67595           rc = p->rc;
 67456  67596         }else{
 67457  67597           u.ar.iSavepoint = db->nSavepoint - u.ar.iSavepoint - 1;
        67598  +        for(u.ar.ii=0; u.ar.ii<db->nDb; u.ar.ii++){
        67599  +          sqlite3BtreeTripAllCursors(db->aDb[u.ar.ii].pBt, SQLITE_ABORT);
        67600  +        }
 67458  67601           for(u.ar.ii=0; u.ar.ii<db->nDb; u.ar.ii++){
 67459  67602             rc = sqlite3BtreeSavepoint(db->aDb[u.ar.ii].pBt, u.ar.p1, u.ar.iSavepoint);
 67460  67603             if( rc!=SQLITE_OK ){
 67461  67604               goto abort_due_to_error;
 67462  67605             }
 67463  67606           }
 67464  67607           if( u.ar.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
................................................................................
 67521  67664     u.as.desiredAutoCommit = pOp->p1;
 67522  67665     u.as.iRollback = pOp->p2;
 67523  67666     u.as.turnOnAC = u.as.desiredAutoCommit && !db->autoCommit;
 67524  67667     assert( u.as.desiredAutoCommit==1 || u.as.desiredAutoCommit==0 );
 67525  67668     assert( u.as.desiredAutoCommit==1 || u.as.iRollback==0 );
 67526  67669     assert( db->activeVdbeCnt>0 );  /* At least this one VM is active */
 67527  67670   
        67671  +#if 0
 67528  67672     if( u.as.turnOnAC && u.as.iRollback && db->activeVdbeCnt>1 ){
 67529  67673       /* If this instruction implements a ROLLBACK and other VMs are
 67530  67674       ** still running, and a transaction is active, return an error indicating
 67531  67675       ** that the other VMs must complete first.
 67532  67676       */
 67533  67677       sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
 67534  67678           "SQL statements in progress");
 67535  67679       rc = SQLITE_BUSY;
 67536         -  }else if( u.as.turnOnAC && !u.as.iRollback && db->writeVdbeCnt>0 ){
        67680  +  }else
        67681  +#endif
        67682  +  if( u.as.turnOnAC && !u.as.iRollback && db->writeVdbeCnt>0 ){
 67537  67683       /* If this instruction implements a COMMIT and other VMs are writing
 67538  67684       ** return an error indicating that the other VMs must complete first.
 67539  67685       */
 67540  67686       sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
 67541  67687           "SQL statements in progress");
 67542  67688       rc = SQLITE_BUSY;
 67543  67689     }else if( u.as.desiredAutoCommit!=db->autoCommit ){
 67544  67690       if( u.as.iRollback ){
 67545  67691         assert( u.as.desiredAutoCommit==1 );
 67546         -      sqlite3RollbackAll(db);
        67692  +      sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
 67547  67693         db->autoCommit = 1;
 67548  67694       }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
 67549  67695         goto vdbe_return;
 67550  67696       }else{
 67551  67697         db->autoCommit = (u8)u.as.desiredAutoCommit;
 67552  67698         if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
 67553  67699           p->pc = pc;
................................................................................
 67595  67741   ** on the file.
 67596  67742   **
 67597  67743   ** If a write-transaction is started and the Vdbe.usesStmtJournal flag is
 67598  67744   ** true (this flag is set if the Vdbe may modify more than one row and may
 67599  67745   ** throw an ABORT exception), a statement transaction may also be opened.
 67600  67746   ** More specifically, a statement transaction is opened iff the database
 67601  67747   ** connection is currently not in autocommit mode, or if there are other
 67602         -** active statements. A statement transaction allows the affects of this
        67748  +** active statements. A statement transaction allows the changes made by this
 67603  67749   ** VDBE to be rolled back after an error without having to roll back the
 67604  67750   ** entire transaction. If no error is encountered, the statement transaction
 67605  67751   ** will automatically commit when the VDBE halts.
 67606  67752   **
 67607  67753   ** If P2 is zero, then a read-lock is obtained on the database file.
 67608  67754   */
 67609  67755   case OP_Transaction: {
................................................................................
 68605  68751           }
 68606  68752           if( u.bg.res ){
 68607  68753             u.bg.v = 1;   /* IMP: R-61914-48074 */
 68608  68754           }else{
 68609  68755             assert( sqlite3BtreeCursorIsValid(u.bg.pC->pCursor) );
 68610  68756             rc = sqlite3BtreeKeySize(u.bg.pC->pCursor, &u.bg.v);
 68611  68757             assert( rc==SQLITE_OK );   /* Cannot fail following BtreeLast() */
 68612         -          if( u.bg.v==MAX_ROWID ){
        68758  +          if( u.bg.v>=MAX_ROWID ){
 68613  68759               u.bg.pC->useRandomRowid = 1;
 68614  68760             }else{
 68615  68761               u.bg.v++;   /* IMP: R-29538-34987 */
 68616  68762             }
 68617  68763           }
 68618  68764         }
 68619  68765   
................................................................................
 69639  69785         assert( !db->mallocFailed );
 69640  69786         rc = sqlite3_exec(db, u.by.zSql, sqlite3InitCallback, &u.by.initData, 0);
 69641  69787         if( rc==SQLITE_OK ) rc = u.by.initData.rc;
 69642  69788         sqlite3DbFree(db, u.by.zSql);
 69643  69789         db->init.busy = 0;
 69644  69790       }
 69645  69791     }
        69792  +  if( rc ) sqlite3ResetInternalSchema(db, -1);
 69646  69793     if( rc==SQLITE_NOMEM ){
 69647  69794       goto no_mem;
 69648  69795     }
 69649  69796     break;
 69650  69797   }
 69651  69798   
 69652  69799   #if !defined(SQLITE_OMIT_ANALYZE)
................................................................................
 69981  70128     p->nMem = u.cc.pFrame->nChildMem;
 69982  70129     p->nCursor = (u16)u.cc.pFrame->nChildCsr;
 69983  70130     p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
 69984  70131     p->aOp = aOp = u.cc.pProgram->aOp;
 69985  70132     p->nOp = u.cc.pProgram->nOp;
 69986  70133     p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
 69987  70134     p->nOnceFlag = u.cc.pProgram->nOnce;
 69988         -  p->nOp = u.cc.pProgram->nOp;
 69989  70135     pc = -1;
 69990  70136     memset(p->aOnceFlag, 0, p->nOnceFlag);
 69991  70137   
 69992  70138     break;
 69993  70139   }
 69994  70140   
 69995  70141   /* Opcode: Param P1 P2 * * *
................................................................................
 70176  70322     u.cf.ctx.s.flags = MEM_Null;
 70177  70323     u.cf.ctx.s.z = 0;
 70178  70324     u.cf.ctx.s.zMalloc = 0;
 70179  70325     u.cf.ctx.s.xDel = 0;
 70180  70326     u.cf.ctx.s.db = db;
 70181  70327     u.cf.ctx.isError = 0;
 70182  70328     u.cf.ctx.pColl = 0;
        70329  +  u.cf.ctx.skipFlag = 0;
 70183  70330     if( u.cf.ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
 70184  70331       assert( pOp>p->aOp );
 70185  70332       assert( pOp[-1].p4type==P4_COLLSEQ );
 70186  70333       assert( pOp[-1].opcode==OP_CollSeq );
 70187  70334       u.cf.ctx.pColl = pOp[-1].p4.pColl;
 70188  70335     }
 70189  70336     (u.cf.ctx.pFunc->xStep)(&u.cf.ctx, u.cf.n, u.cf.apVal); /* IMP: R-24505-23230 */
 70190  70337     if( u.cf.ctx.isError ){
 70191  70338       sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cf.ctx.s));
 70192  70339       rc = u.cf.ctx.isError;
 70193  70340     }
        70341  +  if( u.cf.ctx.skipFlag ){
        70342  +    assert( pOp[-1].opcode==OP_CollSeq );
        70343  +    u.cf.i = pOp[-1].p1;
        70344  +    if( u.cf.i ) sqlite3VdbeMemSetInt64(&aMem[u.cf.i], 1);
        70345  +  }
 70194  70346   
 70195  70347     sqlite3VdbeMemRelease(&u.cf.ctx.s);
 70196  70348   
 70197  70349     break;
 70198  70350   }
 70199  70351   
 70200  70352   /* Opcode: AggFinal P1 P2 * P4 *
................................................................................
 71580  71732   **     aTree[] = { X, 0   0, 6    0, 3, 5, 6 }
 71581  71733   **
 71582  71734   ** In other words, each time we advance to the next sorter element, log2(N)
 71583  71735   ** key comparison operations are required, where N is the number of segments
 71584  71736   ** being merged (rounded up to the next power of 2).
 71585  71737   */
 71586  71738   struct VdbeSorter {
 71587         -  int nInMemory;                  /* Current size of pRecord list as PMA */
 71588         -  int nTree;                      /* Used size of aTree/aIter (power of 2) */
 71589         -  VdbeSorterIter *aIter;          /* Array of iterators to merge */
 71590         -  int *aTree;                     /* Current state of incremental merge */
 71591  71739     i64 iWriteOff;                  /* Current write offset within file pTemp1 */
 71592  71740     i64 iReadOff;                   /* Current read offset within file pTemp1 */
 71593         -  sqlite3_file *pTemp1;           /* PMA file 1 */
        71741  +  int nInMemory;                  /* Current size of pRecord list as PMA */
        71742  +  int nTree;                      /* Used size of aTree/aIter (power of 2) */
 71594  71743     int nPMA;                       /* Number of PMAs stored in pTemp1 */
 71595         -  SorterRecord *pRecord;          /* Head of in-memory record list */
 71596  71744     int mnPmaSize;                  /* Minimum PMA size, in bytes */
 71597  71745     int mxPmaSize;                  /* Maximum PMA size, in bytes.  0==no limit */
        71746  +  VdbeSorterIter *aIter;          /* Array of iterators to merge */
        71747  +  int *aTree;                     /* Current state of incremental merge */
        71748  +  sqlite3_file *pTemp1;           /* PMA file 1 */
        71749  +  SorterRecord *pRecord;          /* Head of in-memory record list */
 71598  71750     UnpackedRecord *pUnpacked;      /* Used to unpack keys */
 71599  71751   };
 71600  71752   
 71601  71753   /*
 71602  71754   ** The following type is an iterator for a PMA. It caches the current key in 
 71603  71755   ** variables nKey/aKey. If the iterator is at EOF, pFile==0.
 71604  71756   */
 71605  71757   struct VdbeSorterIter {
 71606  71758     i64 iReadOff;                   /* Current read offset */
 71607  71759     i64 iEof;                       /* 1 byte past EOF for this iterator */
 71608         -  sqlite3_file *pFile;            /* File iterator is reading from */
 71609  71760     int nAlloc;                     /* Bytes of space at aAlloc */
 71610         -  u8 *aAlloc;                     /* Allocated space */
 71611  71761     int nKey;                       /* Number of bytes in key */
        71762  +  sqlite3_file *pFile;            /* File iterator is reading from */
        71763  +  u8 *aAlloc;                     /* Allocated space */
 71612  71764     u8 *aKey;                       /* Pointer to current key */
 71613  71765   };
 71614  71766   
 71615  71767   /*
 71616  71768   ** A structure to store a single record. All in-memory records are connected
 71617  71769   ** together into a linked list headed at VdbeSorter.pRecord using the 
 71618  71770   ** SorterRecord.pNext pointer.
................................................................................
 75091  75243     ExprList *pNew;
 75092  75244     struct ExprList_item *pItem, *pOldItem;
 75093  75245     int i;
 75094  75246     if( p==0 ) return 0;
 75095  75247     pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
 75096  75248     if( pNew==0 ) return 0;
 75097  75249     pNew->iECursor = 0;
 75098         -  pNew->nExpr = pNew->nAlloc = p->nExpr;
 75099         -  pNew->a = pItem = sqlite3DbMallocRaw(db,  p->nExpr*sizeof(p->a[0]) );
        75250  +  pNew->nExpr = i = p->nExpr;
        75251  +  if( (flags & EXPRDUP_REDUCE)==0 ) for(i=1; i<p->nExpr; i+=i){}
        75252  +  pNew->a = pItem = sqlite3DbMallocRaw(db,  i*sizeof(p->a[0]) );
 75100  75253     if( pItem==0 ){
 75101  75254       sqlite3DbFree(db, pNew);
 75102  75255       return 0;
 75103  75256     } 
 75104  75257     pOldItem = p->a;
 75105  75258     for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
 75106  75259       Expr *pOldExpr = pOldItem->pExpr;
................................................................................
 75160  75313   }
 75161  75314   SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){
 75162  75315     IdList *pNew;
 75163  75316     int i;
 75164  75317     if( p==0 ) return 0;
 75165  75318     pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
 75166  75319     if( pNew==0 ) return 0;
 75167         -  pNew->nId = pNew->nAlloc = p->nId;
        75320  +  pNew->nId = p->nId;
 75168  75321     pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) );
 75169  75322     if( pNew->a==0 ){
 75170  75323       sqlite3DbFree(db, pNew);
 75171  75324       return 0;
 75172  75325     }
        75326  +  /* Note that because the size of the allocation for p->a[] is not
        75327  +  ** necessarily a power of two, sqlite3IdListAppend() may not be called
        75328  +  ** on the duplicate created by this function. */
 75173  75329     for(i=0; i<p->nId; i++){
 75174  75330       struct IdList_item *pNewItem = &pNew->a[i];
 75175  75331       struct IdList_item *pOldItem = &p->a[i];
 75176  75332       pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
 75177  75333       pNewItem->idx = pOldItem->idx;
 75178  75334     }
 75179  75335     return pNew;
................................................................................
 75227  75383   ){
 75228  75384     sqlite3 *db = pParse->db;
 75229  75385     if( pList==0 ){
 75230  75386       pList = sqlite3DbMallocZero(db, sizeof(ExprList) );
 75231  75387       if( pList==0 ){
 75232  75388         goto no_mem;
 75233  75389       }
 75234         -    assert( pList->nAlloc==0 );
 75235         -  }
 75236         -  if( pList->nAlloc<=pList->nExpr ){
        75390  +    pList->a = sqlite3DbMallocRaw(db, sizeof(pList->a[0]));
        75391  +    if( pList->a==0 ) goto no_mem;
        75392  +  }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
 75237  75393       struct ExprList_item *a;
 75238         -    int n = pList->nAlloc*2 + 4;
 75239         -    a = sqlite3DbRealloc(db, pList->a, n*sizeof(pList->a[0]));
        75394  +    assert( pList->nExpr>0 );
        75395  +    a = sqlite3DbRealloc(db, pList->a, pList->nExpr*2*sizeof(pList->a[0]));
 75240  75396       if( a==0 ){
 75241  75397         goto no_mem;
 75242  75398       }
 75243  75399       pList->a = a;
 75244         -    pList->nAlloc = sqlite3DbMallocSize(db, a)/sizeof(a[0]);
 75245  75400     }
 75246  75401     assert( pList->a!=0 );
 75247  75402     if( 1 ){
 75248  75403       struct ExprList_item *pItem = &pList->a[pList->nExpr++];
 75249  75404       memset(pItem, 0, sizeof(*pItem));
 75250  75405       pItem->pExpr = pExpr;
 75251  75406     }
................................................................................
 75328  75483   /*
 75329  75484   ** Delete an entire expression list.
 75330  75485   */
 75331  75486   SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
 75332  75487     int i;
 75333  75488     struct ExprList_item *pItem;
 75334  75489     if( pList==0 ) return;
 75335         -  assert( pList->a!=0 || (pList->nExpr==0 && pList->nAlloc==0) );
 75336         -  assert( pList->nExpr<=pList->nAlloc );
        75490  +  assert( pList->a!=0 || pList->nExpr==0 );
 75337  75491     for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
 75338  75492       sqlite3ExprDelete(db, pItem->pExpr);
 75339  75493       sqlite3DbFree(db, pItem->zName);
 75340  75494       sqlite3DbFree(db, pItem->zSpan);
 75341  75495     }
 75342  75496     sqlite3DbFree(db, pList->a);
 75343  75497     sqlite3DbFree(db, pList);
................................................................................
 78010  78164   */
 78011  78165   static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){
 78012  78166     int i;
 78013  78167     pInfo->aCol = sqlite3ArrayAllocate(
 78014  78168          db,
 78015  78169          pInfo->aCol,
 78016  78170          sizeof(pInfo->aCol[0]),
 78017         -       3,
 78018  78171          &pInfo->nColumn,
 78019         -       &pInfo->nColumnAlloc,
 78020  78172          &i
 78021  78173     );
 78022  78174     return i;
 78023  78175   }    
 78024  78176   
 78025  78177   /*
 78026  78178   ** Add a new element to the pAggInfo->aFunc[] array.  Return the index of
................................................................................
 78028  78180   */
 78029  78181   static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){
 78030  78182     int i;
 78031  78183     pInfo->aFunc = sqlite3ArrayAllocate(
 78032  78184          db, 
 78033  78185          pInfo->aFunc,
 78034  78186          sizeof(pInfo->aFunc[0]),
 78035         -       3,
 78036  78187          &pInfo->nFunc,
 78037         -       &pInfo->nFuncAlloc,
 78038  78188          &i
 78039  78189     );
 78040  78190     return i;
 78041  78191   }    
 78042  78192   
 78043  78193   /*
 78044  78194   ** This is the xExprCallback for a tree walker.  It is used to
................................................................................
 78807  78957   #endif
 78808  78958             "tbl_name = %Q, "
 78809  78959             "name = CASE "
 78810  78960               "WHEN type='table' THEN %Q "
 78811  78961               "WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
 78812  78962                "'sqlite_autoindex_' || %Q || substr(name,%d+18) "
 78813  78963               "ELSE name END "
 78814         -      "WHERE tbl_name=%Q AND "
        78964  +      "WHERE tbl_name=%Q COLLATE nocase AND "
 78815  78965             "(type='table' OR type='index' OR type='trigger');", 
 78816  78966         zDb, SCHEMA_TABLE(iDb), zName, zName, zName, 
 78817  78967   #ifndef SQLITE_OMIT_TRIGGER
 78818  78968         zName,
 78819  78969   #endif
 78820  78970         zName, nTabName, zTabName
 78821  78971     );
................................................................................
 80037  80187     sqlite3_stmt *pStmt = 0;      /* An SQL statement being run */
 80038  80188     char *zSql;                   /* Text of the SQL statement */
 80039  80189     Index *pPrevIdx = 0;          /* Previous index in the loop */
 80040  80190     int idx = 0;                  /* slot in pIdx->aSample[] for next sample */
 80041  80191     int eType;                    /* Datatype of a sample */
 80042  80192     IndexSample *pSample;         /* A slot in pIdx->aSample[] */
 80043  80193   
        80194  +  assert( db->lookaside.bEnabled==0 );
 80044  80195     if( !sqlite3FindTable(db, "sqlite_stat3", zDb) ){
 80045  80196       return SQLITE_OK;
 80046  80197     }
 80047  80198   
 80048  80199     zSql = sqlite3MPrintf(db, 
 80049  80200         "SELECT idx,count(*) FROM %Q.sqlite_stat3"
 80050  80201         " GROUP BY idx", zDb);
................................................................................
 80063  80214       zIndex = (char *)sqlite3_column_text(pStmt, 0);
 80064  80215       if( zIndex==0 ) continue;
 80065  80216       nSample = sqlite3_column_int(pStmt, 1);
 80066  80217       pIdx = sqlite3FindIndex(db, zIndex, zDb);
 80067  80218       if( pIdx==0 ) continue;
 80068  80219       assert( pIdx->nSample==0 );
 80069  80220       pIdx->nSample = nSample;
 80070         -    pIdx->aSample = sqlite3MallocZero( nSample*sizeof(IndexSample) );
        80221  +    pIdx->aSample = sqlite3DbMallocZero(db, nSample*sizeof(IndexSample));
 80071  80222       pIdx->avgEq = pIdx->aiRowEst[1];
 80072  80223       if( pIdx->aSample==0 ){
 80073  80224         db->mallocFailed = 1;
 80074  80225         sqlite3_finalize(pStmt);
 80075  80226         return SQLITE_NOMEM;
 80076  80227       }
 80077  80228     }
................................................................................
 80136  80287                 sqlite3_column_text(pStmt, 4)
 80137  80288              );
 80138  80289           int n = z ? sqlite3_column_bytes(pStmt, 4) : 0;
 80139  80290           pSample->nByte = n;
 80140  80291           if( n < 1){
 80141  80292             pSample->u.z = 0;
 80142  80293           }else{
 80143         -          pSample->u.z = sqlite3Malloc(n);
        80294  +          pSample->u.z = sqlite3DbMallocRaw(db, n);
 80144  80295             if( pSample->u.z==0 ){
 80145  80296               db->mallocFailed = 1;
 80146  80297               sqlite3_finalize(pStmt);
 80147  80298               return SQLITE_NOMEM;
 80148  80299             }
 80149  80300             memcpy(pSample->u.z, z, n);
 80150  80301           }
................................................................................
 80212  80363       sqlite3DbFree(db, zSql);
 80213  80364     }
 80214  80365   
 80215  80366   
 80216  80367     /* Load the statistics from the sqlite_stat3 table. */
 80217  80368   #ifdef SQLITE_ENABLE_STAT3
 80218  80369     if( rc==SQLITE_OK ){
        80370  +    int lookasideEnabled = db->lookaside.bEnabled;
        80371  +    db->lookaside.bEnabled = 0;
 80219  80372       rc = loadStat3(db, sInfo.zDatabase);
        80373  +    db->lookaside.bEnabled = lookasideEnabled;
 80220  80374     }
 80221  80375   #endif
 80222  80376   
 80223  80377     if( rc==SQLITE_NOMEM ){
 80224  80378       db->mallocFailed = 1;
 80225  80379     }
 80226  80380     return rc;
................................................................................
 82676  82830                                sqlite3Strlen30(p->zName),p);
 82677  82831       if( pOld ){
 82678  82832         assert( p==pOld );  /* Malloc must have failed inside HashInsert() */
 82679  82833         db->mallocFailed = 1;
 82680  82834         return;
 82681  82835       }
 82682  82836       pParse->pNewTable = 0;
 82683         -    db->nTable++;
 82684  82837       db->flags |= SQLITE_InternChanges;
 82685  82838   
 82686  82839   #ifndef SQLITE_OMIT_ALTERTABLE
 82687  82840       if( !p->pSelect ){
 82688  82841         const char *zName = (const char *)pParse->sNameToken.z;
 82689  82842         int nName;
 82690  82843         assert( !pSelect && pCons && pEnd );
................................................................................
 84097  84250   ** might be the same as the pArray parameter or it might be a different
 84098  84251   ** pointer if the array was resized.
 84099  84252   */
 84100  84253   SQLITE_PRIVATE void *sqlite3ArrayAllocate(
 84101  84254     sqlite3 *db,      /* Connection to notify of malloc failures */
 84102  84255     void *pArray,     /* Array of objects.  Might be reallocated */
 84103  84256     int szEntry,      /* Size of each object in the array */
 84104         -  int initSize,     /* Suggested initial allocation, in elements */
 84105  84257     int *pnEntry,     /* Number of objects currently in use */
 84106         -  int *pnAlloc,     /* Current size of the allocation, in elements */
 84107  84258     int *pIdx         /* Write the index of a new slot here */
 84108  84259   ){
 84109  84260     char *z;
 84110         -  if( *pnEntry >= *pnAlloc ){
 84111         -    void *pNew;
 84112         -    int newSize;
 84113         -    newSize = (*pnAlloc)*2 + initSize;
 84114         -    pNew = sqlite3DbRealloc(db, pArray, newSize*szEntry);
        84261  +  int n = *pnEntry;
        84262  +  if( (n & (n-1))==0 ){
        84263  +    int sz = (n==0) ? 1 : 2*n;
        84264  +    void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
 84115  84265       if( pNew==0 ){
 84116  84266         *pIdx = -1;
 84117  84267         return pArray;
 84118  84268       }
 84119         -    *pnAlloc = sqlite3DbMallocSize(db, pNew)/szEntry;
 84120  84269       pArray = pNew;
 84121  84270     }
 84122  84271     z = (char*)pArray;
 84123         -  memset(&z[*pnEntry * szEntry], 0, szEntry);
 84124         -  *pIdx = *pnEntry;
        84272  +  memset(&z[n * szEntry], 0, szEntry);
        84273  +  *pIdx = n;
 84125  84274     ++*pnEntry;
 84126  84275     return pArray;
 84127  84276   }
 84128  84277   
 84129  84278   /*
 84130  84279   ** Append a new element to the given IdList.  Create a new IdList if
 84131  84280   ** need be.
................................................................................
 84133  84282   ** A new IdList is returned, or NULL if malloc() fails.
 84134  84283   */
 84135  84284   SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pToken){
 84136  84285     int i;
 84137  84286     if( pList==0 ){
 84138  84287       pList = sqlite3DbMallocZero(db, sizeof(IdList) );
 84139  84288       if( pList==0 ) return 0;
 84140         -    pList->nAlloc = 0;
 84141  84289     }
 84142  84290     pList->a = sqlite3ArrayAllocate(
 84143  84291         db,
 84144  84292         pList->a,
 84145  84293         sizeof(pList->a[0]),
 84146         -      5,
 84147  84294         &pList->nId,
 84148         -      &pList->nAlloc,
 84149  84295         &i
 84150  84296     );
 84151  84297     if( i<0 ){
 84152  84298       sqlite3IdListDelete(db, pList);
 84153  84299       return 0;
 84154  84300     }
 84155  84301     pList->a[i].zName = sqlite3NameFromToken(db, pToken);
................................................................................
 86000  86146   
 86001  86147   /*
 86002  86148   ** Return the collating function associated with a function.
 86003  86149   */
 86004  86150   static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
 86005  86151     return context->pColl;
 86006  86152   }
        86153  +
        86154  +/*
        86155  +** Indicate that the accumulator load should be skipped on this
        86156  +** iteration of the aggregate loop.
        86157  +*/
        86158  +static void sqlite3SkipAccumulatorLoad(sqlite3_context *context){
        86159  +  context->skipFlag = 1;
        86160  +}
 86007  86161   
 86008  86162   /*
 86009  86163   ** Implementation of the non-aggregate min() and max() functions
 86010  86164   */
 86011  86165   static void minmaxFunc(
 86012  86166     sqlite3_context *context,
 86013  86167     int argc,
................................................................................
 86381  86535       ** (or -9223372036854775808) since when you do abs() of that
 86382  86536       ** number of you get the same value back again.  To do this
 86383  86537       ** in a way that is testable, mask the sign bit off of negative
 86384  86538       ** values, resulting in a positive value.  Then take the 
 86385  86539       ** 2s complement of that positive value.  The end result can
 86386  86540       ** therefore be no less than -9223372036854775807.
 86387  86541       */
 86388         -    r = -(r ^ (((sqlite3_int64)1)<<63));
        86542  +    r = -(r & LARGEST_INT64);
 86389  86543     }
 86390  86544     sqlite3_result_int64(context, r);
 86391  86545   }
 86392  86546   
 86393  86547   /*
 86394  86548   ** Implementation of randomblob(N).  Return a random blob
 86395  86549   ** that is N bytes long.
................................................................................
 87307  87461     int NotUsed, 
 87308  87462     sqlite3_value **argv
 87309  87463   ){
 87310  87464     Mem *pArg  = (Mem *)argv[0];
 87311  87465     Mem *pBest;
 87312  87466     UNUSED_PARAMETER(NotUsed);
 87313  87467   
 87314         -  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
 87315  87468     pBest = (Mem *)sqlite3_aggregate_context(context, sizeof(*pBest));
 87316  87469     if( !pBest ) return;
 87317  87470   
 87318         -  if( pBest->flags ){
        87471  +  if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
        87472  +    if( pBest->flags ) sqlite3SkipAccumulatorLoad(context);
        87473  +  }else if( pBest->flags ){
 87319  87474       int max;
 87320  87475       int cmp;
 87321  87476       CollSeq *pColl = sqlite3GetFuncCollSeq(context);
 87322  87477       /* This step function is used for both the min() and max() aggregates,
 87323  87478       ** the only difference between the two being that the sense of the
 87324  87479       ** comparison is inverted. For the max() aggregate, the
 87325  87480       ** sqlite3_user_data() function returns (void *)-1. For min() it
................................................................................
 87327  87482       ** Therefore the next statement sets variable 'max' to 1 for the max()
 87328  87483       ** aggregate, or 0 for min().
 87329  87484       */
 87330  87485       max = sqlite3_user_data(context)!=0;
 87331  87486       cmp = sqlite3MemCompare(pBest, pArg, pColl);
 87332  87487       if( (max && cmp<0) || (!max && cmp>0) ){
 87333  87488         sqlite3VdbeMemCopy(pBest, pArg);
        87489  +    }else{
        87490  +      sqlite3SkipAccumulatorLoad(context);
 87334  87491       }
 87335  87492     }else{
 87336  87493       sqlite3VdbeMemCopy(pBest, pArg);
 87337  87494     }
 87338  87495   }
 87339  87496   static void minMaxFinalize(sqlite3_context *context){
 87340  87497     sqlite3_value *pRes;
 87341  87498     pRes = (sqlite3_value *)sqlite3_aggregate_context(context, 0);
 87342  87499     if( pRes ){
 87343         -    if( ALWAYS(pRes->flags) ){
        87500  +    if( pRes->flags ){
 87344  87501         sqlite3_result_value(context, pRes);
 87345  87502       }
 87346  87503       sqlite3VdbeMemRelease(pRes);
 87347  87504     }
 87348  87505   }
 87349  87506   
 87350  87507   /*
................................................................................
 91918  92075   *************************************************************************
 91919  92076   ** This file contains code used to implement the PRAGMA command.
 91920  92077   */
 91921  92078   
 91922  92079   /*
 91923  92080   ** Interpret the given string as a safety level.  Return 0 for OFF,
 91924  92081   ** 1 for ON or NORMAL and 2 for FULL.  Return 1 for an empty or 
 91925         -** unrecognized string argument.
        92082  +** unrecognized string argument.  The FULL option is disallowed
        92083  +** if the omitFull parameter it 1.
 91926  92084   **
 91927  92085   ** Note that the values returned are one less that the values that
 91928  92086   ** should be passed into sqlite3BtreeSetSafetyLevel().  The is done
 91929  92087   ** to support legacy SQL code.  The safety level used to be boolean
 91930  92088   ** and older scripts may have used numbers 0 for OFF and 1 for ON.
 91931  92089   */
 91932         -static u8 getSafetyLevel(const char *z){
        92090  +static u8 getSafetyLevel(const char *z, int omitFull, int dflt){
 91933  92091                                /* 123456789 123456789 */
 91934  92092     static const char zText[] = "onoffalseyestruefull";
 91935  92093     static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
 91936  92094     static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
 91937  92095     static const u8 iValue[] =  {1, 0, 0, 0, 1, 1, 2};
 91938  92096     int i, n;
 91939  92097     if( sqlite3Isdigit(*z) ){
 91940  92098       return (u8)sqlite3Atoi(z);
 91941  92099     }
 91942  92100     n = sqlite3Strlen30(z);
 91943         -  for(i=0; i<ArraySize(iLength); i++){
        92101  +  for(i=0; i<ArraySize(iLength)-omitFull; i++){
 91944  92102       if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){
 91945  92103         return iValue[i];
 91946  92104       }
 91947  92105     }
 91948         -  return 1;
        92106  +  return dflt;
 91949  92107   }
 91950  92108   
 91951  92109   /*
 91952  92110   ** Interpret the given string as a boolean value.
 91953  92111   */
 91954         -SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z){
 91955         -  return getSafetyLevel(z)&1;
        92112  +SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z, int dflt){
        92113  +  return getSafetyLevel(z,1,dflt)!=0;
 91956  92114   }
 91957  92115   
 91958  92116   /* The sqlite3GetBoolean() function is used by other modules but the
 91959  92117   ** remainder of this file is specific to PRAGMA processing.  So omit
 91960  92118   ** the rest of the file if PRAGMAs are omitted from the build.
 91961  92119   */
 91962  92120   #if !defined(SQLITE_OMIT_PRAGMA)
................................................................................
 92091  92249       { "vdbe_trace",               SQLITE_VdbeTrace     },
 92092  92250   #endif
 92093  92251   #ifndef SQLITE_OMIT_CHECK
 92094  92252       { "ignore_check_constraints", SQLITE_IgnoreChecks  },
 92095  92253   #endif
 92096  92254       /* The following is VERY experimental */
 92097  92255       { "writable_schema",          SQLITE_WriteSchema|SQLITE_RecoveryMode },
 92098         -    { "omit_readlock",            SQLITE_NoReadlock    },
 92099  92256   
 92100  92257       /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
 92101  92258       ** flag if there are any active statements. */
 92102  92259       { "read_uncommitted",         SQLITE_ReadUncommitted },
 92103  92260       { "recursive_triggers",       SQLITE_RecTriggers },
 92104  92261   
 92105  92262       /* This flag may only be set if both foreign-key and trigger support
................................................................................
 92123  92280             int mask = p->mask;          /* Mask of bits to set or clear. */
 92124  92281             if( db->autoCommit==0 ){
 92125  92282               /* Foreign key support may not be enabled or disabled while not
 92126  92283               ** in auto-commit mode.  */
 92127  92284               mask &= ~(SQLITE_ForeignKeys);
 92128  92285             }
 92129  92286   
 92130         -          if( sqlite3GetBoolean(zRight) ){
        92287  +          if( sqlite3GetBoolean(zRight, 0) ){
 92131  92288               db->flags |= mask;
 92132  92289             }else{
 92133  92290               db->flags &= ~mask;
 92134  92291             }
 92135  92292   
 92136  92293             /* Many of the flag-pragmas modify the code generated by the SQL 
 92137  92294             ** compiler (eg. count_changes). So add an opcode to expire all
................................................................................
 92214  92371     int minusFlag       /* True if a '-' sign preceded <value> */
 92215  92372   ){
 92216  92373     char *zLeft = 0;       /* Nul-terminated UTF-8 string <id> */
 92217  92374     char *zRight = 0;      /* Nul-terminated UTF-8 string <value>, or NULL */
 92218  92375     const char *zDb = 0;   /* The database name */
 92219  92376     Token *pId;            /* Pointer to <id> token */
 92220  92377     int iDb;               /* Database index for <database> */
 92221         -  sqlite3 *db = pParse->db;
 92222         -  Db *pDb;
 92223         -  Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(db);
        92378  +  char *aFcntl[4];       /* Argument to SQLITE_FCNTL_PRAGMA */
        92379  +  int rc;                      /* return value form SQLITE_FCNTL_PRAGMA */
        92380  +  sqlite3 *db = pParse->db;    /* The database connection */
        92381  +  Db *pDb;                     /* The specific database being pragmaed */
        92382  +  Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(db);  /* Prepared statement */
        92383  +
 92224  92384     if( v==0 ) return;
 92225  92385     sqlite3VdbeRunOnlyOnce(v);
 92226  92386     pParse->nMem = 2;
 92227  92387   
 92228  92388     /* Interpret the [database.] part of the pragma statement. iDb is the
 92229  92389     ** index of the database this pragma is being applied to in db.aDb[]. */
 92230  92390     iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId);
................................................................................
 92247  92407     }
 92248  92408   
 92249  92409     assert( pId2 );
 92250  92410     zDb = pId2->n>0 ? pDb->zName : 0;
 92251  92411     if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
 92252  92412       goto pragma_out;
 92253  92413     }
        92414  +
        92415  +  /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
        92416  +  ** connection.  If it returns SQLITE_OK, then assume that the VFS
        92417  +  ** handled the pragma and generate a no-op prepared statement.
        92418  +  */
        92419  +  aFcntl[0] = 0;
        92420  +  aFcntl[1] = zLeft;
        92421  +  aFcntl[2] = zRight;
        92422  +  aFcntl[3] = 0;
        92423  +  rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
        92424  +  if( rc==SQLITE_OK ){
        92425  +    if( aFcntl[0] ){
        92426  +      int mem = ++pParse->nMem;
        92427  +      sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0);
        92428  +      sqlite3VdbeSetNumCols(v, 1);
        92429  +      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
        92430  +      sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
        92431  +      sqlite3_free(aFcntl[0]);
        92432  +    }
        92433  +  }else if( rc!=SQLITE_NOTFOUND ){
        92434  +    if( aFcntl[0] ){
        92435  +      sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
        92436  +      sqlite3_free(aFcntl[0]);
        92437  +    }
        92438  +    pParse->nErr++;
        92439  +    pParse->rc = rc;
        92440  +  }else
        92441  +                            
 92254  92442    
 92255  92443   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
 92256  92444     /*
 92257  92445     **  PRAGMA [database.]default_cache_size
 92258  92446     **  PRAGMA [database.]default_cache_size=N
 92259  92447     **
 92260  92448     ** The first form reports the current persistent setting for the
................................................................................
 92339  92527     ** flag setting and reports thenew value.
 92340  92528     */
 92341  92529     if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){
 92342  92530       Btree *pBt = pDb->pBt;
 92343  92531       int b = -1;
 92344  92532       assert( pBt!=0 );
 92345  92533       if( zRight ){
 92346         -      b = sqlite3GetBoolean(zRight);
        92534  +      b = sqlite3GetBoolean(zRight, 0);
 92347  92535       }
 92348  92536       if( pId2->n==0 && b>=0 ){
 92349  92537         int ii;
 92350  92538         for(ii=0; ii<db->nDb; ii++){
 92351  92539           sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
 92352  92540         }
 92353  92541       }
................................................................................
 92534  92722         db->nextAutovac = (u8)eAuto;
 92535  92723         if( ALWAYS(eAuto>=0) ){
 92536  92724           /* Call SetAutoVacuum() to set initialize the internal auto and
 92537  92725           ** incr-vacuum flags. This is required in case this connection
 92538  92726           ** creates the database file. It is important that it is created
 92539  92727           ** as an auto-vacuum capable db.
 92540  92728           */
 92541         -        int rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
        92729  +        rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
 92542  92730           if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){
 92543  92731             /* When setting the auto_vacuum mode to either "full" or 
 92544  92732             ** "incremental", write the value of meta[6] in the database
 92545  92733             ** file. Before writing to meta[6], check that meta[3] indicates
 92546  92734             ** that this really is an auto-vacuum capable database.
 92547  92735             */
 92548  92736             static const VdbeOpList setMeta6[] = {
................................................................................
 92652  92840               "temp_store_directory", SQLITE_STATIC);
 92653  92841           sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
 92654  92842           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
 92655  92843         }
 92656  92844       }else{
 92657  92845   #ifndef SQLITE_OMIT_WSD
 92658  92846         if( zRight[0] ){
 92659         -        int rc;
 92660  92847           int res;
 92661  92848           rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
 92662  92849           if( rc!=SQLITE_OK || res==0 ){
 92663  92850             sqlite3ErrorMsg(pParse, "not a writable directory");
 92664  92851             goto pragma_out;
 92665  92852           }
 92666  92853         }
................................................................................
 92744  92931       if( !zRight ){
 92745  92932         returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
 92746  92933       }else{
 92747  92934         if( !db->autoCommit ){
 92748  92935           sqlite3ErrorMsg(pParse, 
 92749  92936               "Safety level may not be changed inside a transaction");
 92750  92937         }else{
 92751         -        pDb->safety_level = getSafetyLevel(zRight)+1;
        92938  +        pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
 92752  92939         }
 92753  92940       }
 92754  92941     }else
 92755  92942   #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
 92756  92943   
 92757  92944   #ifndef SQLITE_OMIT_FLAG_PRAGMAS
 92758  92945     if( flagPragma(pParse, zLeft, zRight) ){
................................................................................
 92943  93130       }
 92944  93131     }else
 92945  93132   #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
 92946  93133   
 92947  93134   #ifndef NDEBUG
 92948  93135     if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
 92949  93136       if( zRight ){
 92950         -      if( sqlite3GetBoolean(zRight) ){
        93137  +      if( sqlite3GetBoolean(zRight, 0) ){
 92951  93138           sqlite3ParserTrace(stderr, "parser: ");
 92952  93139         }else{
 92953  93140           sqlite3ParserTrace(0, 0);
 92954  93141         }
 92955  93142       }
 92956  93143     }else
 92957  93144   #endif
 92958  93145   
 92959  93146     /* Reinstall the LIKE and GLOB functions.  The variant of LIKE
 92960  93147     ** used will be case sensitive or not depending on the RHS.
 92961  93148     */
 92962  93149     if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
 92963  93150       if( zRight ){
 92964         -      sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight));
        93151  +      sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
 92965  93152       }
 92966  93153     }else
 92967  93154   
 92968  93155   #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
 92969  93156   # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
 92970  93157   #endif
 92971  93158   
................................................................................
 94383  94570       pNew = &standin;
 94384  94571       memset(pNew, 0, sizeof(*pNew));
 94385  94572     }
 94386  94573     if( pEList==0 ){
 94387  94574       pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ALL,0));
 94388  94575     }
 94389  94576     pNew->pEList = pEList;
        94577  +  if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc));
 94390  94578     pNew->pSrc = pSrc;
 94391  94579     pNew->pWhere = pWhere;
 94392  94580     pNew->pGroupBy = pGroupBy;
 94393  94581     pNew->pHaving = pHaving;
 94394  94582     pNew->pOrderBy = pOrderBy;
 94395  94583     pNew->selFlags = isDistinct ? SF_Distinct : 0;
 94396  94584     pNew->op = TK_SELECT;
................................................................................
 95567  95755     int cnt;                    /* Index added to make the name unique */
 95568  95756     Column *aCol, *pCol;        /* For looping over result columns */
 95569  95757     int nCol;                   /* Number of columns in the result set */
 95570  95758     Expr *p;                    /* Expression for a single result column */
 95571  95759     char *zName;                /* Column name */
 95572  95760     int nName;                  /* Size of name in zName[] */
 95573  95761   
 95574         -  *pnCol = nCol = pEList->nExpr;
        95762  +  *pnCol = nCol = pEList ? pEList->nExpr : 0;
 95575  95763     aCol = *paCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
 95576  95764     if( aCol==0 ) return SQLITE_NOMEM;
 95577  95765     for(i=0, pCol=aCol; i<nCol; i++, pCol++){
 95578  95766       /* Get an appropriate name for the column
 95579  95767       */
 95580  95768       p = pEList->a[i].pExpr;
 95581  95769       assert( p->pRight==0 || ExprHasProperty(p->pRight, EP_IntValue)
................................................................................
 95921  96109     }
 95922  96110   
 95923  96111     /* Make sure all SELECTs in the statement have the same number of elements
 95924  96112     ** in their result sets.
 95925  96113     */
 95926  96114     assert( p->pEList && pPrior->pEList );
 95927  96115     if( p->pEList->nExpr!=pPrior->pEList->nExpr ){
 95928         -    sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
 95929         -      " do not have the same number of result columns", selectOpName(p->op));
        96116  +    if( p->selFlags & SF_Values ){
        96117  +      sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
        96118  +    }else{
        96119  +      sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
        96120  +        " do not have the same number of result columns", selectOpName(p->op));
        96121  +    }
 95930  96122       rc = 1;
 95931  96123       goto multi_select_end;
 95932  96124     }
 95933  96125   
 95934  96126     /* Compound SELECTs that have an ORDER BY clause are handled separately.
 95935  96127     */
 95936  96128     if( p->pOrderBy ){
................................................................................
 96538  96730         }
 96539  96731         if( j==nOrderBy ){
 96540  96732           Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
 96541  96733           if( pNew==0 ) return SQLITE_NOMEM;
 96542  96734           pNew->flags |= EP_IntValue;
 96543  96735           pNew->u.iValue = i;
 96544  96736           pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
 96545         -        pOrderBy->a[nOrderBy++].iOrderByCol = (u16)i;
        96737  +        if( pOrderBy ) pOrderBy->a[nOrderBy++].iOrderByCol = (u16)i;
 96546  96738         }
 96547  96739       }
 96548  96740     }
 96549  96741   
 96550  96742     /* Compute the comparison permutation and keyinfo that is used with
 96551  96743     ** the permutation used to determine if the next
 96552  96744     ** row of results comes from selectA or selectB.  Also add explicit
................................................................................
 97901  98093   /*
 97902  98094   ** Update the accumulator memory cells for an aggregate based on
 97903  98095   ** the current cursor position.
 97904  98096   */
 97905  98097   static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){
 97906  98098     Vdbe *v = pParse->pVdbe;
 97907  98099     int i;
        98100  +  int regHit = 0;
        98101  +  int addrHitTest = 0;
 97908  98102     struct AggInfo_func *pF;
 97909  98103     struct AggInfo_col *pC;
 97910  98104   
 97911  98105     pAggInfo->directMode = 1;
 97912  98106     sqlite3ExprCacheClear(pParse);
 97913  98107     for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
 97914  98108       int nArg;
................................................................................
 97936  98130         assert( pList!=0 );  /* pList!=0 if pF->pFunc has NEEDCOLL */
 97937  98131         for(j=0, pItem=pList->a; !pColl && j<nArg; j++, pItem++){
 97938  98132           pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
 97939  98133         }
 97940  98134         if( !pColl ){
 97941  98135           pColl = pParse->db->pDfltColl;
 97942  98136         }
 97943         -      sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
        98137  +      if( regHit==0 && pAggInfo->nAccumulator ) regHit = ++pParse->nMem;
        98138  +      sqlite3VdbeAddOp4(v, OP_CollSeq, regHit, 0, 0, (char *)pColl, P4_COLLSEQ);
 97944  98139       }
 97945  98140       sqlite3VdbeAddOp4(v, OP_AggStep, 0, regAgg, pF->iMem,
 97946  98141                         (void*)pF->pFunc, P4_FUNCDEF);
 97947  98142       sqlite3VdbeChangeP5(v, (u8)nArg);
 97948  98143       sqlite3ExprCacheAffinityChange(pParse, regAgg, nArg);
 97949  98144       sqlite3ReleaseTempRange(pParse, regAgg, nArg);
 97950  98145       if( addrNext ){
................................................................................
 97959  98154     ** to pC->iMem. But by the time the value is used, the original register
 97960  98155     ** may have been used, invalidating the underlying buffer holding the
 97961  98156     ** text or blob value. See ticket [883034dcb5].
 97962  98157     **
 97963  98158     ** Another solution would be to change the OP_SCopy used to copy cached
 97964  98159     ** values to an OP_Copy.
 97965  98160     */
        98161  +  if( regHit ){
        98162  +    addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit);
        98163  +  }
 97966  98164     sqlite3ExprCacheClear(pParse);
 97967  98165     for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
 97968  98166       sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
 97969  98167     }
 97970  98168     pAggInfo->directMode = 0;
 97971  98169     sqlite3ExprCacheClear(pParse);
        98170  +  if( addrHitTest ){
        98171  +    sqlite3VdbeJumpHere(v, addrHitTest);
        98172  +  }
 97972  98173   }
 97973  98174   
 97974  98175   /*
 97975  98176   ** Add a single OP_Explain instruction to the VDBE to explain a simple
 97976  98177   ** count(*) query ("SELECT count(*) FROM pTab").
 97977  98178   */
 97978  98179   #ifndef SQLITE_OMIT_EXPLAIN
................................................................................
 98905  99106     }
 98906  99107     sqlite3ExplainPrintf(pVdbe, "END");
 98907  99108     sqlite3ExplainPop(pVdbe);
 98908  99109   }
 98909  99110   
 98910  99111   /* End of the structure debug printing code
 98911  99112   *****************************************************************************/
 98912         -#endif /* defined(SQLITE_TEST) || defined(SQLITE_DEBUG) */
        99113  +#endif /* defined(SQLITE_ENABLE_TREE_EXPLAIN) */
 98913  99114   
 98914  99115   /************** End of select.c **********************************************/
 98915  99116   /************** Begin file table.c *******************************************/
 98916  99117   /*
 98917  99118   ** 2001 September 15
 98918  99119   **
 98919  99120   ** The author disclaims copyright to this source code.  In place of
................................................................................
101084 101285       extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);
101085 101286       int nKey;
101086 101287       char *zKey;
101087 101288       sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
101088 101289       if( nKey ) db->nextPagesize = 0;
101089 101290     }
101090 101291   #endif
       101292  +
       101293  +  rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
       101294  +  if( rc!=SQLITE_OK ) goto end_of_vacuum;
       101295  +
       101296  +  /* Begin a transaction and take an exclusive lock on the main database
       101297  +  ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
       101298  +  ** to ensure that we do not try to change the page-size on a WAL database.
       101299  +  */
       101300  +  rc = execSql(db, pzErrMsg, "BEGIN;");
       101301  +  if( rc!=SQLITE_OK ) goto end_of_vacuum;
       101302  +  rc = sqlite3BtreeBeginTrans(pMain, 2);
       101303  +  if( rc!=SQLITE_OK ) goto end_of_vacuum;
101091 101304   
101092 101305     /* Do not attempt to change the page size for a WAL database */
101093 101306     if( sqlite3PagerGetJournalMode(sqlite3BtreePager(pMain))
101094 101307                                                  ==PAGER_JOURNALMODE_WAL ){
101095 101308       db->nextPagesize = 0;
101096 101309     }
101097 101310   
................................................................................
101098 101311     if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0)
101099 101312      || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
101100 101313      || NEVER(db->mallocFailed)
101101 101314     ){
101102 101315       rc = SQLITE_NOMEM;
101103 101316       goto end_of_vacuum;
101104 101317     }
101105         -  rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
101106         -  if( rc!=SQLITE_OK ){
101107         -    goto end_of_vacuum;
101108         -  }
101109 101318   
101110 101319   #ifndef SQLITE_OMIT_AUTOVACUUM
101111 101320     sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
101112 101321                                              sqlite3BtreeGetAutoVacuum(pMain));
101113 101322   #endif
101114 101323   
101115         -  /* Begin a transaction */
101116         -  rc = execSql(db, pzErrMsg, "BEGIN EXCLUSIVE;");
101117         -  if( rc!=SQLITE_OK ) goto end_of_vacuum;
101118         -
101119 101324     /* Query the schema of the main database. Create a mirror schema
101120 101325     ** in the temporary database.
101121 101326     */
101122 101327     rc = execExecSql(db, pzErrMsg,
101123 101328         "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
101124 101329         "  FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
101125 101330         "   AND rootpage>0"
................................................................................
101532 101737   ** statement.  The module name has been parsed, but the optional list
101533 101738   ** of parameters that follow the module name are still pending.
101534 101739   */
101535 101740   SQLITE_PRIVATE void sqlite3VtabBeginParse(
101536 101741     Parse *pParse,        /* Parsing context */
101537 101742     Token *pName1,        /* Name of new table, or database name */
101538 101743     Token *pName2,        /* Name of new table or NULL */
101539         -  Token *pModuleName    /* Name of the module for the virtual table */
       101744  +  Token *pModuleName,   /* Name of the module for the virtual table */
       101745  +  int ifNotExists       /* No error if the table already exists */
101540 101746   ){
101541 101747     int iDb;              /* The database the table is being created in */
101542 101748     Table *pTable;        /* The new virtual table */
101543 101749     sqlite3 *db;          /* Database connection */
101544 101750   
101545         -  sqlite3StartTable(pParse, pName1, pName2, 0, 0, 1, 0);
       101751  +  sqlite3StartTable(pParse, pName1, pName2, 0, 0, 1, ifNotExists);
101546 101752     pTable = pParse->pNewTable;
101547 101753     if( pTable==0 ) return;
101548 101754     assert( 0==pTable->pIndex );
101549 101755   
101550 101756     db = pParse->db;
101551 101757     iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
101552 101758     assert( iDb>=0 );
................................................................................
101573 101779   
101574 101780   /*
101575 101781   ** This routine takes the module argument that has been accumulating
101576 101782   ** in pParse->zArg[] and appends it to the list of arguments on the
101577 101783   ** virtual table currently under construction in pParse->pTable.
101578 101784   */
101579 101785   static void addArgumentToVtab(Parse *pParse){
101580         -  if( pParse->sArg.z && ALWAYS(pParse->pNewTable) ){
       101786  +  if( pParse->sArg.z && pParse->pNewTable ){
101581 101787       const char *z = (const char*)pParse->sArg.z;
101582 101788       int n = pParse->sArg.n;
101583 101789       sqlite3 *db = pParse->db;
101584 101790       addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
101585 101791     }
101586 101792   }
101587 101793   
................................................................................
105425 105631         wsFlags |= WHERE_ROWID_RANGE|WHERE_COLUMN_RANGE|WHERE_ORDERBY;
105426 105632         wsFlags |= (rev ? WHERE_REVERSE : 0);
105427 105633       }
105428 105634   
105429 105635       /* If there is a DISTINCT qualifier and this index will scan rows in
105430 105636       ** order of the DISTINCT expressions, clear bDist and set the appropriate
105431 105637       ** flags in wsFlags. */
105432         -    if( isDistinctIndex(pParse, pWC, pProbe, iCur, pDistinct, nEq) ){
       105638  +    if( isDistinctIndex(pParse, pWC, pProbe, iCur, pDistinct, nEq)
       105639  +     && (wsFlags & WHERE_COLUMN_IN)==0
       105640  +    ){
105433 105641         bDist = 0;
105434 105642         wsFlags |= WHERE_ROWID_RANGE|WHERE_COLUMN_RANGE|WHERE_DISTINCT;
105435 105643       }
105436 105644   
105437 105645       /* If currently calculating the cost of using an index (not the IPK
105438 105646       ** index), determine if all required column data may be obtained without 
105439 105647       ** using the main table (i.e. if the index is a covering
................................................................................
106122 106330   ** Generate code for the start of the iLevel-th loop in the WHERE clause
106123 106331   ** implementation described by pWInfo.
106124 106332   */
106125 106333   static Bitmask codeOneLoopStart(
106126 106334     WhereInfo *pWInfo,   /* Complete information about the WHERE clause */
106127 106335     int iLevel,          /* Which level of pWInfo->a[] should be coded */
106128 106336     u16 wctrlFlags,      /* One of the WHERE_* flags defined in sqliteInt.h */
106129         -  Bitmask notReady,    /* Which tables are currently available */
106130         -  Expr *pWhere         /* Complete WHERE clause */
       106337  +  Bitmask notReady     /* Which tables are currently available */
106131 106338   ){
106132 106339     int j, k;            /* Loop counters */
106133 106340     int iCur;            /* The VDBE cursor for the table */
106134 106341     int addrNxt;         /* Where to jump to continue with the next IN case */
106135 106342     int omitTable;       /* True if we use the index only */
106136 106343     int bRev;            /* True if we need to scan in reverse order */
106137 106344     WhereLevel *pLevel;  /* The where level to be coded */
................................................................................
106662 106869       }
106663 106870       iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
106664 106871   
106665 106872       /* If the original WHERE clause is z of the form:  (x1 OR x2 OR ...) AND y
106666 106873       ** Then for every term xN, evaluate as the subexpression: xN AND z
106667 106874       ** That way, terms in y that are factored into the disjunction will
106668 106875       ** be picked up by the recursive calls to sqlite3WhereBegin() below.
       106876  +    **
       106877  +    ** Actually, each subexpression is converted to "xN AND w" where w is
       106878  +    ** the "interesting" terms of z - terms that did not originate in the
       106879  +    ** ON or USING clause of a LEFT JOIN, and terms that are usable as 
       106880  +    ** indices.
106669 106881       */
106670 106882       if( pWC->nTerm>1 ){
106671         -      pAndExpr = sqlite3ExprAlloc(pParse->db, TK_AND, 0, 0);
106672         -      pAndExpr->pRight = pWhere;
       106883  +      int iTerm;
       106884  +      for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
       106885  +        Expr *pExpr = pWC->a[iTerm].pExpr;
       106886  +        if( ExprHasProperty(pExpr, EP_FromJoin) ) continue;
       106887  +        if( pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_ORINFO) ) continue;
       106888  +        if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
       106889  +        pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
       106890  +        pAndExpr = sqlite3ExprAnd(pParse->db, pAndExpr, pExpr);
       106891  +      }
       106892  +      if( pAndExpr ){
       106893  +        pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0);
       106894  +      }
106673 106895       }
106674 106896   
106675 106897       for(ii=0; ii<pOrWc->nTerm; ii++){
106676 106898         WhereTerm *pOrTerm = &pOrWc->a[ii];
106677 106899         if( pOrTerm->leftCursor==iCur || pOrTerm->eOperator==WO_AND ){
106678 106900           WhereInfo *pSubWInfo;          /* Info for single OR-term scan */
106679 106901           Expr *pOrExpr = pOrTerm->pExpr;
................................................................................
106707 106929             if( pSubWInfo->untestedTerms ) untestedTerms = 1;
106708 106930   
106709 106931             /* Finish the loop through table entries that match term pOrTerm. */
106710 106932             sqlite3WhereEnd(pSubWInfo);
106711 106933           }
106712 106934         }
106713 106935       }
106714         -    sqlite3DbFree(pParse->db, pAndExpr);
       106936  +    if( pAndExpr ){
       106937  +      pAndExpr->pLeft = 0;
       106938  +      sqlite3ExprDelete(pParse->db, pAndExpr);
       106939  +    }
106715 106940       sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v));
106716 106941       sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrBrk);
106717 106942       sqlite3VdbeResolveLabel(v, iLoopBody);
106718 106943   
106719 106944       if( pWInfo->nLevel>1 ) sqlite3StackFree(pParse->db, pOrTab);
106720 106945       if( !untestedTerms ) disableTerm(pLevel, pTerm);
106721 106946     }else
................................................................................
107363 107588     ** loop below generates code for a single nested loop of the VM
107364 107589     ** program.
107365 107590     */
107366 107591     notReady = ~(Bitmask)0;
107367 107592     for(i=0; i<nTabList; i++){
107368 107593       pLevel = &pWInfo->a[i];
107369 107594       explainOneScan(pParse, pTabList, pLevel, i, pLevel->iFrom, wctrlFlags);
107370         -    notReady = codeOneLoopStart(pWInfo, i, wctrlFlags, notReady, pWhere);
       107595  +    notReady = codeOneLoopStart(pWInfo, i, wctrlFlags, notReady);
107371 107596       pWInfo->iContinue = pLevel->addrCont;
107372 107597     }
107373 107598   
107374 107599   #ifdef SQLITE_TEST  /* For testing and debugging use only */
107375 107600     /* Record in the query plan information about the current table
107376 107601     ** and the index used to access it (if any).  If the table itself
107377 107602     ** is not used, its name is just '{}'.  If no index is used
................................................................................
107618 107843   struct TrigEvent { int a; IdList * b; };
107619 107844   
107620 107845   /*
107621 107846   ** An instance of this structure holds the ATTACH key and the key type.
107622 107847   */
107623 107848   struct AttachKey { int type;  Token key; };
107624 107849   
       107850  +/*
       107851  +** One or more VALUES claues
       107852  +*/
       107853  +struct ValueList {
       107854  +  ExprList *pList;
       107855  +  Select *pSelect;
       107856  +};
       107857  +
107625 107858   
107626 107859     /* This is a utility routine used to set the ExprSpan.zStart and
107627 107860     ** ExprSpan.zEnd values of pOut so that the span covers the complete
107628 107861     ** range of text beginning with pStart and going to the end of pEnd.
107629 107862     */
107630 107863     static void spanSet(ExprSpan *pOut, Token *pStart, Token *pEnd){
107631 107864       pOut->zStart = pStart->z;
................................................................................
107741 107974   **    sqlite3ParserARG_FETCH     Code to extract %extra_argument from yypParser
107742 107975   **    YYNSTATE           the combined number of states.
107743 107976   **    YYNRULE            the number of rules in the grammar
107744 107977   **    YYERRORSYMBOL      is the code number of the error symbol.  If not
107745 107978   **                       defined, then do no error processing.
107746 107979   */
107747 107980   #define YYCODETYPE unsigned char
107748         -#define YYNOCODE 253
       107981  +#define YYNOCODE 251
107749 107982   #define YYACTIONTYPE unsigned short int
107750 107983   #define YYWILDCARD 67
107751 107984   #define sqlite3ParserTOKENTYPE Token
107752 107985   typedef union {
107753 107986     int yyinit;
107754 107987     sqlite3ParserTOKENTYPE yy0;
107755         -  int yy4;
107756         -  struct TrigEvent yy90;
107757         -  ExprSpan yy118;
107758         -  TriggerStep* yy203;
107759         -  u8 yy210;
107760         -  struct {int value; int mask;} yy215;
107761         -  SrcList* yy259;
107762         -  struct LimitVal yy292;
107763         -  Expr* yy314;
107764         -  ExprList* yy322;
107765         -  struct LikeOp yy342;
107766         -  IdList* yy384;
107767         -  Select* yy387;
       107988  +  struct LimitVal yy64;
       107989  +  Expr* yy122;
       107990  +  Select* yy159;
       107991  +  IdList* yy180;
       107992  +  struct {int value; int mask;} yy207;
       107993  +  u8 yy258;
       107994  +  struct LikeOp yy318;
       107995  +  TriggerStep* yy327;
       107996  +  ExprSpan yy342;
       107997  +  SrcList* yy347;
       107998  +  int yy392;
       107999  +  struct TrigEvent yy410;
       108000  +  ExprList* yy442;
       108001  +  struct ValueList yy487;
107768 108002   } YYMINORTYPE;
107769 108003   #ifndef YYSTACKDEPTH
107770 108004   #define YYSTACKDEPTH 100
107771 108005   #endif
107772 108006   #define sqlite3ParserARG_SDECL Parse *pParse;
107773 108007   #define sqlite3ParserARG_PDECL ,Parse *pParse
107774 108008   #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
107775 108009   #define sqlite3ParserARG_STORE yypParser->pParse = pParse
107776         -#define YYNSTATE 630
107777         -#define YYNRULE 329
       108010  +#define YYNSTATE 629
       108011  +#define YYNRULE 327
107778 108012   #define YYFALLBACK 1
107779 108013   #define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
107780 108014   #define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
107781 108015   #define YY_ERROR_ACTION   (YYNSTATE+YYNRULE)
107782 108016   
107783 108017   /* The yyzerominor constant is used to initialize instances of
107784 108018   ** YYMINORTYPE objects to zero. */
................................................................................
107840 108074   **                     yy_action.  Used to detect hash collisions.
107841 108075   **  yy_shift_ofst[]    For each state, the offset into yy_action for
107842 108076   **                     shifting terminals.
107843 108077   **  yy_reduce_ofst[]   For each state, the offset into yy_action for
107844 108078   **                     shifting non-terminals after a reduce.
107845 108079   **  yy_default[]       Default action for each state.
107846 108080   */
107847         -#define YY_ACTTAB_COUNT (1557)
       108081  +#define YY_ACTTAB_COUNT (1580)
107848 108082   static const YYACTIONTYPE yy_action[] = {
107849         - /*     0 */   313,  960,  186,  419,    2,  172,  627,  597,   55,   55,
107850         - /*    10 */    55,   55,   48,   53,   53,   53,   53,   52,   52,   51,
107851         - /*    20 */    51,   51,   50,  238,  302,  283,  623,  622,  516,  515,
107852         - /*    30 */   590,  584,   55,   55,   55,   55,  282,   53,   53,   53,
107853         - /*    40 */    53,   52,   52,   51,   51,   51,   50,  238,    6,   56,
107854         - /*    50 */    57,   47,  582,  581,  583,  583,   54,   54,   55,   55,
107855         - /*    60 */    55,   55,  608,   53,   53,   53,   53,   52,   52,   51,
107856         - /*    70 */    51,   51,   50,  238,  313,  597,  409,  330,  579,  579,
107857         - /*    80 */    32,   53,   53,   53,   53,   52,   52,   51,   51,   51,
107858         - /*    90 */    50,  238,  330,  217,  620,  619,  166,  411,  624,  382,
107859         - /*   100 */   379,  378,    7,  491,  590,  584,  200,  199,  198,   58,
107860         - /*   110 */   377,  300,  414,  621,  481,   66,  623,  622,  621,  580,
107861         - /*   120 */   254,  601,   94,   56,   57,   47,  582,  581,  583,  583,
107862         - /*   130 */    54,   54,   55,   55,   55,   55,  671,   53,   53,   53,
107863         - /*   140 */    53,   52,   52,   51,   51,   51,   50,  238,  313,  532,
107864         - /*   150 */   226,  506,  507,  133,  177,  139,  284,  385,  279,  384,
107865         - /*   160 */   169,  197,  342,  398,  251,  226,  253,  275,  388,  167,
107866         - /*   170 */   139,  284,  385,  279,  384,  169,  570,  236,  590,  584,
107867         - /*   180 */   672,  240,  275,  157,  620,  619,  554,  437,   51,   51,
107868         - /*   190 */    51,   50,  238,  343,  439,  553,  438,   56,   57,   47,
107869         - /*   200 */   582,  581,  583,  583,   54,   54,   55,   55,   55,   55,
107870         - /*   210 */   465,   53,   53,   53,   53,   52,   52,   51,   51,   51,
107871         - /*   220 */    50,  238,  313,  390,   52,   52,   51,   51,   51,   50,
107872         - /*   230 */   238,  391,  166,  491,  566,  382,  379,  378,  409,  440,
107873         - /*   240 */   579,  579,  252,  440,  607,   66,  377,  513,  621,   49,
107874         - /*   250 */    46,  147,  590,  584,  621,   16,  466,  189,  621,  441,
107875         - /*   260 */   442,  673,  526,  441,  340,  577,  595,   64,  194,  482,
107876         - /*   270 */   434,   56,   57,   47,  582,  581,  583,  583,   54,   54,
107877         - /*   280 */    55,   55,   55,   55,   30,   53,   53,   53,   53,   52,
107878         - /*   290 */    52,   51,   51,   51,   50,  238,  313,  593,  593,  593,
107879         - /*   300 */   387,  578,  606,  493,  259,  351,  258,  411,    1,  623,
107880         - /*   310 */   622,  496,  623,  622,   65,  240,  623,  622,  597,  443,
107881         - /*   320 */   237,  239,  414,  341,  237,  602,  590,  584,   18,  603,
107882         - /*   330 */   166,  601,   87,  382,  379,  378,   67,  623,  622,   38,
107883         - /*   340 */   623,  622,  176,  270,  377,   56,   57,   47,  582,  581,
107884         - /*   350 */   583,  583,   54,   54,   55,   55,   55,   55,  175,   53,
107885         - /*   360 */    53,   53,   53,   52,   52,   51,   51,   51,   50,  238,
107886         - /*   370 */   313,  396,  233,  411,  531,  565,  317,  620,  619,   44,
107887         - /*   380 */   620,  619,  240,  206,  620,  619,  597,  266,  414,  268,
107888         - /*   390 */   409,  597,  579,  579,  352,  184,  505,  601,   73,  533,
107889         - /*   400 */   590,  584,  466,  548,  190,  620,  619,  576,  620,  619,
107890         - /*   410 */   547,  383,  551,   35,  332,  575,  574,  600,  504,   56,
107891         - /*   420 */    57,   47,  582,  581,  583,  583,   54,   54,   55,   55,
107892         - /*   430 */    55,   55,  567,   53,   53,   53,   53,   52,   52,   51,
107893         - /*   440 */    51,   51,   50,  238,  313,  411,  561,  561,  528,  364,
107894         - /*   450 */   259,  351,  258,  183,  361,  549,  524,  374,  411,  597,
107895         - /*   460 */   414,  240,  560,  560,  409,  604,  579,  579,  328,  601,
107896         - /*   470 */    93,  623,  622,  414,  590,  584,  237,  564,  559,  559,
107897         - /*   480 */   520,  402,  601,   87,  409,  210,  579,  579,  168,  421,
107898         - /*   490 */   950,  519,  950,   56,   57,   47,  582,  581,  583,  583,
107899         - /*   500 */    54,   54,   55,   55,   55,   55,  192,   53,   53,   53,
107900         - /*   510 */    53,   52,   52,   51,   51,   51,   50,  238,  313,  600,
107901         - /*   520 */   293,  563,  511,  234,  357,  146,  475,  475,  367,  411,
107902         - /*   530 */   562,  411,  358,  542,  425,  171,  411,  215,  144,  620,
107903         - /*   540 */   619,  544,  318,  353,  414,  203,  414,  275,  590,  584,
107904         - /*   550 */   549,  414,  174,  601,   94,  601,   79,  558,  471,   61,
107905         - /*   560 */   601,   79,  421,  949,  350,  949,   34,   56,   57,   47,
107906         - /*   570 */   582,  581,  583,  583,   54,   54,   55,   55,   55,   55,
107907         - /*   580 */   535,   53,   53,   53,   53,   52,   52,   51,   51,   51,
107908         - /*   590 */    50,  238,  313,  307,  424,  394,  272,   49,   46,  147,
107909         - /*   600 */   349,  322,    4,  411,  491,  312,  321,  425,  568,  492,
107910         - /*   610 */   216,  264,  407,  575,  574,  429,   66,  549,  414,  621,
107911         - /*   620 */   540,  602,  590,  584,   13,  603,  621,  601,   72,   12,
107912         - /*   630 */   618,  617,  616,  202,  210,  621,  546,  469,  422,  319,
107913         - /*   640 */   148,   56,   57,   47,  582,  581,  583,  583,   54,   54,
107914         - /*   650 */    55,   55,   55,   55,  338,   53,   53,   53,   53,   52,
107915         - /*   660 */    52,   51,   51,   51,   50,  238,  313,  600,  600,  411,
107916         - /*   670 */    39,   21,   37,  170,  237,  875,  411,  572,  572,  201,
107917         - /*   680 */   144,  473,  538,  331,  414,  474,  143,  146,  630,  628,
107918         - /*   690 */   334,  414,  353,  601,   68,  168,  590,  584,  132,  365,
107919         - /*   700 */   601,   96,  307,  423,  530,  336,   49,   46,  147,  568,
107920         - /*   710 */   406,  216,  549,  360,  529,   56,   57,   47,  582,  581,
107921         - /*   720 */   583,  583,   54,   54,   55,   55,   55,   55,  411,   53,
107922         - /*   730 */    53,   53,   53,   52,   52,   51,   51,   51,   50,  238,
107923         - /*   740 */   313,  411,  605,  414,  484,  510,  172,  422,  597,  318,
107924         - /*   750 */   496,  485,  601,   99,  411,  142,  414,  411,  231,  411,
107925         - /*   760 */   540,  411,  359,  629,    2,  601,   97,  426,  308,  414,
107926         - /*   770 */   590,  584,  414,   20,  414,  621,  414,  621,  601,  106,
107927         - /*   780 */   503,  601,  105,  601,  108,  601,  109,  204,   28,   56,
107928         - /*   790 */    57,   47,  582,  581,  583,  583,   54,   54,   55,   55,
107929         - /*   800 */    55,   55,  411,   53,   53,   53,   53,   52,   52,   51,
107930         - /*   810 */    51,   51,   50,  238,  313,  411,  597,  414,  411,  276,
107931         - /*   820 */   214,  600,  411,  366,  213,  381,  601,  134,  274,  500,
107932         - /*   830 */   414,  167,  130,  414,  621,  411,  354,  414,  376,  601,
107933         - /*   840 */   135,  129,  601,  100,  590,  584,  601,  104,  522,  521,
107934         - /*   850 */   414,  621,  224,  273,  600,  167,  327,  282,  600,  601,
107935         - /*   860 */   103,  468,  521,   56,   57,   47,  582,  581,  583,  583,
107936         - /*   870 */    54,   54,   55,   55,   55,   55,  411,   53,   53,   53,
107937         - /*   880 */    53,   52,   52,   51,   51,   51,   50,  238,  313,  411,
107938         - /*   890 */    27,  414,  411,  375,  276,  167,  359,  544,   50,  238,
107939         - /*   900 */   601,   95,  128,  223,  414,  411,  165,  414,  411,  621,
107940         - /*   910 */   411,  621,  612,  601,  102,  372,  601,   76,  590,  584,
107941         - /*   920 */   414,  570,  236,  414,  470,  414,  167,  621,  188,  601,
107942         - /*   930 */    98,  225,  601,  138,  601,  137,  232,   56,   45,   47,
107943         - /*   940 */   582,  581,  583,  583,   54,   54,   55,   55,   55,   55,
107944         - /*   950 */   411,   53,   53,   53,   53,   52,   52,   51,   51,   51,
107945         - /*   960 */    50,  238,  313,  276,  276,  414,  411,  276,  544,  459,
107946         - /*   970 */   359,  171,  209,  479,  601,  136,  628,  334,  621,  621,
107947         - /*   980 */   125,  414,  621,  368,  411,  621,  257,  540,  589,  588,
107948         - /*   990 */   601,   75,  590,  584,  458,  446,   23,   23,  124,  414,
107949         - /*  1000 */   326,  325,  621,  427,  324,  309,  600,  288,  601,   92,
107950         - /*  1010 */   586,  585,   57,   47,  582,  581,  583,  583,   54,   54,
107951         - /*  1020 */    55,   55,   55,   55,  411,   53,   53,   53,   53,   52,
107952         - /*  1030 */    52,   51,   51,   51,   50,  238,  313,  587,  411,  414,
107953         - /*  1040 */   411,  207,  611,  476,  171,  472,  160,  123,  601,   91,
107954         - /*  1050 */   323,  261,   15,  414,  464,  414,  411,  621,  411,  354,
107955         - /*  1060 */   222,  411,  601,   74,  601,   90,  590,  584,  159,  264,
107956         - /*  1070 */   158,  414,  461,  414,  621,  600,  414,  121,  120,   25,
107957         - /*  1080 */   601,   89,  601,  101,  621,  601,   88,   47,  582,  581,
107958         - /*  1090 */   583,  583,   54,   54,   55,   55,   55,   55,  544,   53,
107959         - /*  1100 */    53,   53,   53,   52,   52,   51,   51,   51,   50,  238,
107960         - /*  1110 */    43,  405,  263,    3,  610,  264,  140,  415,  622,   24,
107961         - /*  1120 */   410,   11,  456,  594,  118,  155,  219,  452,  408,  621,
107962         - /*  1130 */   621,  621,  156,   43,  405,  621,    3,  286,  621,  113,
107963         - /*  1140 */   415,  622,  111,  445,  411,  400,  557,  403,  545,   10,
107964         - /*  1150 */   411,  408,  264,  110,  205,  436,  541,  566,  453,  414,
107965         - /*  1160 */   621,  621,   63,  621,  435,  414,  411,  621,  601,   94,
107966         - /*  1170 */   403,  621,  411,  337,  601,   86,  150,   40,   41,  534,
107967         - /*  1180 */   566,  414,  242,  264,   42,  413,  412,  414,  600,  595,
107968         - /*  1190 */   601,   85,  191,  333,  107,  451,  601,   84,  621,  539,
107969         - /*  1200 */    40,   41,  420,  230,  411,  149,  316,   42,  413,  412,
107970         - /*  1210 */   398,  127,  595,  315,  621,  399,  278,  625,  181,  414,
107971         - /*  1220 */   593,  593,  593,  592,  591,   14,  450,  411,  601,   71,
107972         - /*  1230 */   240,  621,   43,  405,  264,    3,  615,  180,  264,  415,
107973         - /*  1240 */   622,  614,  414,  593,  593,  593,  592,  591,   14,  621,
107974         - /*  1250 */   408,  601,   70,  621,  417,   33,  405,  613,    3,  411,
107975         - /*  1260 */   264,  411,  415,  622,  418,  626,  178,  509,    8,  403,
107976         - /*  1270 */   241,  416,  126,  408,  414,  621,  414,  449,  208,  566,
107977         - /*  1280 */   240,  221,  621,  601,   83,  601,   82,  599,  297,  277,
107978         - /*  1290 */   296,   30,  403,   31,  395,  264,  295,  397,  489,   40,
107979         - /*  1300 */    41,  411,  566,  220,  621,  294,   42,  413,  412,  271,
107980         - /*  1310 */   621,  595,  600,  621,   59,   60,  414,  269,  267,  623,
107981         - /*  1320 */   622,   36,   40,   41,  621,  601,   81,  598,  235,   42,
107982         - /*  1330 */   413,  412,  621,  621,  595,  265,  344,  411,  248,  556,
107983         - /*  1340 */   173,  185,  593,  593,  593,  592,  591,   14,  218,   29,
107984         - /*  1350 */   621,  543,  414,  305,  304,  303,  179,  301,  411,  566,
107985         - /*  1360 */   454,  601,   80,  289,  335,  593,  593,  593,  592,  591,
107986         - /*  1370 */    14,  411,  287,  414,  151,  392,  246,  260,  411,  196,
107987         - /*  1380 */   195,  523,  601,   69,  411,  245,  414,  526,  537,  285,
107988         - /*  1390 */   389,  595,  621,  414,  536,  601,   17,  362,  153,  414,
107989         - /*  1400 */   466,  463,  601,   78,  154,  414,  462,  152,  601,   77,
107990         - /*  1410 */   355,  255,  621,  455,  601,    9,  621,  386,  444,  517,
107991         - /*  1420 */   247,  621,  593,  593,  593,  621,  621,  244,  621,  243,
107992         - /*  1430 */   430,  518,  292,  621,  329,  621,  145,  393,  280,  513,
107993         - /*  1440 */   291,  131,  621,  514,  621,  621,  311,  621,  259,  346,
107994         - /*  1450 */   249,  621,  621,  229,  314,  621,  228,  512,  227,  240,
107995         - /*  1460 */   494,  488,  310,  164,  487,  486,  373,  480,  163,  262,
107996         - /*  1470 */   369,  371,  162,   26,  212,  478,  477,  161,  141,  363,
107997         - /*  1480 */   467,  122,  339,  187,  119,  348,  347,  117,  116,  115,
107998         - /*  1490 */   114,  112,  182,  457,  320,   22,  433,  432,  448,   19,
107999         - /*  1500 */   609,  431,  428,   62,  193,  596,  573,  298,  555,  552,
108000         - /*  1510 */   571,  404,  290,  380,  498,  510,  495,  306,  281,  499,
108001         - /*  1520 */   250,    5,  497,  460,  345,  447,  569,  550,  238,  299,
108002         - /*  1530 */   527,  525,  508,  961,  502,  501,  961,  401,  961,  211,
108003         - /*  1540 */   490,  356,  256,  961,  483,  961,  961,  961,  961,  961,
108004         - /*  1550 */   961,  961,  961,  961,  961,  961,  370,
       108083  + /*     0 */   310,  328,  574,  573,   15,  172,  187,  596,   56,   56,
       108084  + /*    10 */    56,   56,   49,   54,   54,   54,   54,   53,   53,   52,
       108085  + /*    20 */    52,   52,   51,  234,  622,  621,  626,  622,  621,  299,
       108086  + /*    30 */   589,  583,   56,   56,   56,   56,  236,   54,   54,   54,
       108087  + /*    40 */    54,   53,   53,   52,   52,   52,   51,  234,  351,   57,
       108088  + /*    50 */    58,   48,  581,  580,  582,  582,   55,   55,   56,   56,
       108089  + /*    60 */    56,   56,  570,   54,   54,   54,   54,   53,   53,   52,
       108090  + /*    70 */    52,   52,   51,  234,  310,  596,  326,  607,  233,  232,
       108091  + /*    80 */    33,   54,   54,   54,   54,   53,   53,   52,   52,   52,
       108092  + /*    90 */    51,  234,  619,  618,  326,  619,  618,  166,  605,  492,
       108093  + /*   100 */   381,  378,  377,  235,  589,  583,  554,  495,    1,   59,
       108094  + /*   110 */    19,  376,  622,  621,   53,   53,   52,   52,   52,   51,
       108095  + /*   120 */   234,  571,  571,   57,   58,   48,  581,  580,  582,  582,
       108096  + /*   130 */    55,   55,   56,   56,   56,   56,  215,   54,   54,   54,
       108097  + /*   140 */    54,   53,   53,   52,   52,   52,   51,  234,  310,  224,
       108098  + /*   150 */    50,   47,  147,  177,  139,  281,  384,  276,  383,  169,
       108099  + /*   160 */   408,  553,  578,  578,  622,  621,  272,  224,  439,  550,
       108100  + /*   170 */   552,  410,  139,  281,  384,  276,  383,  169,  589,  583,
       108101  + /*   180 */   619,  618,  280,  620,  272,  195,  413,  309,  440,  441,
       108102  + /*   190 */   567,  491,  214,  279,  560,  600,   92,   57,   58,   48,
       108103  + /*   200 */   581,  580,  582,  582,   55,   55,   56,   56,   56,   56,
       108104  + /*   210 */   559,   54,   54,   54,   54,   53,   53,   52,   52,   52,
       108105  + /*   220 */    51,  234,  310,  464,  233,  232,  558,  133,  519,   50,
       108106  + /*   230 */    47,  147,  619,  618,  565,  436,  397,  515,  514,  518,
       108107  + /*   240 */   410,  387,  438,  389,  437,  622,  621,  442,  570,  433,
       108108  + /*   250 */   203,  390,  589,  583,    6,  413,  166,  670,  250,  381,
       108109  + /*   260 */   378,  377,  525,  190,  600,   92,  594,  571,  571,  465,
       108110  + /*   270 */   376,   57,   58,   48,  581,  580,  582,  582,   55,   55,
       108111  + /*   280 */    56,   56,   56,   56,  599,   54,   54,   54,   54,   53,
       108112  + /*   290 */    53,   52,   52,   52,   51,  234,  310,  592,  592,  592,
       108113  + /*   300 */   490,  182,  247,  548,  249,  397,  273,  410,    7,  439,
       108114  + /*   310 */   398,  606,   67,  619,  618,  620,  472,  256,  347,  255,
       108115  + /*   320 */   473,  620,  413,  576,  620,   65,  589,  583,  236,  440,
       108116  + /*   330 */   336,  600,   92,   68,  364,  192,  481,  622,  621,  547,
       108117  + /*   340 */   622,  621,  560,  323,  207,   57,   58,   48,  581,  580,
       108118  + /*   350 */   582,  582,   55,   55,   56,   56,   56,   56,  559,   54,
       108119  + /*   360 */    54,   54,   54,   53,   53,   52,   52,   52,   51,  234,
       108120  + /*   370 */   310,  410,  397,  146,  558,  531,  401,  348,  599,  166,
       108121  + /*   380 */   248,  204,  381,  378,  377,  541,  413,  171,  337,  570,
       108122  + /*   390 */   622,  621,   40,  376,   38,  600,   74,  465,  548,  490,
       108123  + /*   400 */   589,  583,  532,  350,  579,  619,  618,  297,  619,  618,
       108124  + /*   410 */   480,   67,  470,   39,  620,  599,  406,  574,  573,   57,
       108125  + /*   420 */    58,   48,  581,  580,  582,  582,   55,   55,   56,   56,
       108126  + /*   430 */    56,   56,  577,   54,   54,   54,   54,   53,   53,   52,
       108127  + /*   440 */    52,   52,   51,  234,  310,  256,  347,  255,  530,   52,
       108128  + /*   450 */    52,   52,   51,  234,  345,  564,  236,  386,  619,  618,
       108129  + /*   460 */   957,  185,  418,    2,  408,  410,  578,  578,  198,  197,
       108130  + /*   470 */   196,  499,  183,  167,  589,  583,  671,  570,  505,  506,
       108131  + /*   480 */   413,  267,  601,  672,  546,  208,  602,   36,  601,  600,
       108132  + /*   490 */    91,  468,  602,   57,   58,   48,  581,  580,  582,  582,
       108133  + /*   500 */    55,   55,   56,   56,   56,   56,  202,   54,   54,   54,
       108134  + /*   510 */    54,   53,   53,   52,   52,   52,   51,  234,  310,  599,
       108135  + /*   520 */   157,  408,  527,  578,  578,  263,  490,  265,  410,  873,
       108136  + /*   530 */   410,  474,  474,  366,  373,  410,  504,  428,   67,  290,
       108137  + /*   540 */   599,  620,  352,  413,  408,  413,  578,  578,  589,  583,
       108138  + /*   550 */   413,  382,  600,   92,  600,   16,  543,   62,  503,  600,
       108139  + /*   560 */    92,  408,  346,  578,  578,  168,   45,   57,   58,   48,
       108140  + /*   570 */   581,  580,  582,  582,   55,   55,   56,   56,   56,   56,
       108141  + /*   580 */   200,   54,   54,   54,   54,   53,   53,   52,   52,   52,
       108142  + /*   590 */    51,  234,  310,  393,  395,  534,  510,  617,  616,  615,
       108143  + /*   600 */   318,  314,  172,   66,  596,  410,  338,  596,  324,  571,
       108144  + /*   610 */   571,   50,   47,  147,  599,  629,  627,  330,  539,  315,
       108145  + /*   620 */   413,   30,  589,  583,  272,  236,  199,  144,  176,  600,
       108146  + /*   630 */    73,  420,  947,  620,  947,  420,  946,  351,  946,  175,
       108147  + /*   640 */   596,   57,   58,   48,  581,  580,  582,  582,   55,   55,
       108148  + /*   650 */    56,   56,   56,   56,  410,   54,   54,   54,   54,   53,
       108149  + /*   660 */    53,   52,   52,   52,   51,  234,  310,  261,  410,  413,
       108150  + /*   670 */   269,  208,  596,  363,  410,  596,  424,  360,  600,   69,
       108151  + /*   680 */   424,  327,  620,  413,   50,   47,  147,  410,  358,  413,
       108152  + /*   690 */   575,  553,  600,   94,  483,  509,  589,  583,  600,   97,
       108153  + /*   700 */   552,  484,  413,  620,  188,  599,  551,  563,  596,  566,
       108154  + /*   710 */   334,  600,   95,  205,  201,   57,   58,   48,  581,  580,
       108155  + /*   720 */   582,  582,   55,   55,   56,   56,   56,   56,  352,   54,
       108156  + /*   730 */    54,   54,   54,   53,   53,   52,   52,   52,   51,  234,
       108157  + /*   740 */   310,  410,  261,  410,  167,   22,  356,  599,  359,  623,
       108158  + /*   750 */    50,   47,  147,  548,  357,  562,  413,  620,  413,  332,
       108159  + /*   760 */   523,  270,  410,  167,  620,  600,  104,  600,  103,  603,
       108160  + /*   770 */   589,  583,  339,  539,  304,  423,  222,  413,  174,  304,
       108161  + /*   780 */   422,  561,  567,  405,  214,  260,  600,  106,  620,   57,
       108162  + /*   790 */    58,   48,  581,  580,  582,  582,   55,   55,   56,   56,
       108163  + /*   800 */    56,   56,  410,   54,   54,   54,   54,   53,   53,   52,
       108164  + /*   810 */    52,   52,   51,  234,  310,  410,  557,  413,  410,  421,
       108165  + /*   820 */   273,   35,  512,  146,  421,   12,  600,  107,  213,  144,
       108166  + /*   830 */   413,  410,   32,  413,  410,  620,  365,  353,  358,  600,
       108167  + /*   840 */   134,   11,  600,  135,  589,  583,  413,   21,  548,  413,
       108168  + /*   850 */   316,  148,  620,  620,  170,  600,   98,  223,  600,  102,
       108169  + /*   860 */   374,  168,  167,   57,   58,   48,  581,  580,  582,  582,
       108170  + /*   870 */    55,   55,   56,   56,   56,   56,  410,   54,   54,   54,
       108171  + /*   880 */    54,   53,   53,   52,   52,   52,   51,  234,  310,  410,
       108172  + /*   890 */   273,  413,  410,  273,  212,  469,  410,  167,  628,    2,
       108173  + /*   900 */   600,  101,  545,  221,  413,  620,  130,  413,  620,  410,
       108174  + /*   910 */   539,  413,  537,  600,   93,  315,  600,  100,  589,  583,
       108175  + /*   920 */   600,   77,  425,  305,  413,  620,  254,  322,  599,  458,
       108176  + /*   930 */   320,  171,  543,  600,   96,  521,  520,   57,   58,   48,
       108177  + /*   940 */   581,  580,  582,  582,   55,   55,   56,   56,   56,   56,
       108178  + /*   950 */   410,   54,   54,   54,   54,   53,   53,   52,   52,   52,
       108179  + /*   960 */    51,  234,  310,  410,  273,  413,  410,  457,  358,   35,
       108180  + /*   970 */   426,  230,  306,  319,  600,  138,  467,  520,  413,  620,
       108181  + /*   980 */   143,  413,  410,  620,  410,  353,  529,  600,  137,  142,
       108182  + /*   990 */   600,  136,  589,  583,  604,  261,  528,  413,  229,  413,
       108183  + /*  1000 */   620,  321,  495,   28,  543,  543,  600,   76,  600,   90,
       108184  + /*  1010 */   620,   57,   46,   48,  581,  580,  582,  582,   55,   55,
       108185  + /*  1020 */    56,   56,   56,   56,  410,   54,   54,   54,   54,   53,
       108186  + /*  1030 */    53,   52,   52,   52,   51,  234,  310,  261,  451,  413,
       108187  + /*  1040 */   410,  211,  611,  285,  283,  610,  609,  502,  600,   89,
       108188  + /*  1050 */   380,  217,  620,  128,  140,  413,  220,  620,  410,  409,
       108189  + /*  1060 */   620,  620,  588,  587,  600,   75,  589,  583,  271,  620,
       108190  + /*  1070 */    51,  234,  127,  413,  620,  599,  627,  330,   27,  375,
       108191  + /*  1080 */   449,  279,  600,   88,  585,  584,   58,   48,  581,  580,
       108192  + /*  1090 */   582,  582,   55,   55,   56,   56,   56,   56,  410,   54,
       108193  + /*  1100 */    54,   54,   54,   53,   53,   52,   52,   52,   51,  234,
       108194  + /*  1110 */   310,  586,  410,  413,  410,  261,  593,  165,  399,  556,
       108195  + /*  1120 */   126,  371,  600,   87,  478,  186,  123,  413,  367,  413,
       108196  + /*  1130 */   620,  620,  410,  620,  620,  410,  600,   99,  600,   86,
       108197  + /*  1140 */   589,  583,  475,  122,  258,  171,  471,  413,  160,  121,
       108198  + /*  1150 */   413,   14,  159,  463,   25,   24,  600,   17,  448,  600,
       108199  + /*  1160 */    85,   48,  581,  580,  582,  582,   55,   55,   56,   56,
       108200  + /*  1170 */    56,   56,  158,   54,   54,   54,   54,   53,   53,   52,
       108201  + /*  1180 */    52,   52,   51,  234,   44,  404,  261,    3,  544,  261,
       108202  + /*  1190 */   540,  414,  621,  460,  119,  118,  538,  275,   10,  349,
       108203  + /*  1200 */     4,  620,  407,  620,  620,  620,  116,   44,  404,  410,
       108204  + /*  1210 */     3,  620,  620,  410,  414,  621,  456,  454,  252,  450,
       108205  + /*  1220 */   508,  402,  111,  109,  413,  407,  155,  444,  413,  447,
       108206  + /*  1230 */   435,  565,  219,  600,   84,  620,  108,  600,   83,   64,
       108207  + /*  1240 */   434,  417,  625,  150,  402,  333,  410,  237,  238,  124,
       108208  + /*  1250 */   274,   41,   42,  533,  565,  206,  189,  261,   43,  412,
       108209  + /*  1260 */   411,  413,  261,  594,  488,  620,  329,  149,  419,  268,
       108210  + /*  1270 */   600,   72,  620,  266,   41,   42,  181,  620,  410,  620,
       108211  + /*  1280 */   105,   43,  412,  411,  620,  624,  594,  614,  620,  599,
       108212  + /*  1290 */   228,  125,  313,  413,  592,  592,  592,  591,  590,   13,
       108213  + /*  1300 */   218,  410,  600,   71,  236,  244,   44,  404,  264,    3,
       108214  + /*  1310 */   312,  613,  340,  414,  621,  180,  413,  592,  592,  592,
       108215  + /*  1320 */   591,  590,   13,  620,  407,  600,   82,  410,  416,   34,
       108216  + /*  1330 */   404,  410,    3,  410,  262,  410,  414,  621,  612,  331,
       108217  + /*  1340 */   178,  415,  413,  402,    8,  236,  413,  407,  413,  620,
       108218  + /*  1350 */   413,  600,   81,  565,  257,  600,   80,  600,   70,  600,
       108219  + /*  1360 */    18,  598,  361,  462,  461,   30,  402,  294,   31,  620,
       108220  + /*  1370 */   293,  354,  251,   41,   42,  410,  565,  620,  620,  620,
       108221  + /*  1380 */    43,  412,  411,  453,  396,  594,  620,  620,  394,   61,
       108222  + /*  1390 */   413,  292,  443,  622,  621,  243,   41,   42,  620,  600,
       108223  + /*  1400 */    79,  597,  291,   43,  412,  411,   60,  620,  594,  240,
       108224  + /*  1410 */   620,  410,  231,   37,  555,  173,  592,  592,  592,  591,
       108225  + /*  1420 */   590,   13,  216,  239,  620,  184,  413,  302,  301,  300,
       108226  + /*  1430 */   179,  298,  388,  565,  452,  600,   78,  286,  620,  592,
       108227  + /*  1440 */   592,  592,  591,  590,   13,  429,   29,  413,  151,  289,
       108228  + /*  1450 */   242,  145,  392,  194,  193,  288,  600,    9,  542,  241,
       108229  + /*  1460 */   620,  525,  391,  284,  620,  594,  620,  620,  522,  536,
       108230  + /*  1470 */   620,  535,  153,  385,  465,  516,  282,  325,  154,  517,
       108231  + /*  1480 */   277,  152,  512,  511,  513,  129,  226,  308,  487,  486,
       108232  + /*  1490 */   485,  164,  372,  493,  307,  227,  592,  592,  592,  225,
       108233  + /*  1500 */   479,  163,  368,  370,  162,  476,  210,  477,   26,  259,
       108234  + /*  1510 */   161,  466,  362,  141,  132,  120,  117,  455,  156,  115,
       108235  + /*  1520 */   344,  343,  256,  342,  245,  114,  113,  446,  311,  112,
       108236  + /*  1530 */    23,  317,  432,  236,  131,  431,  110,  430,   20,  427,
       108237  + /*  1540 */   608,  595,  295,   63,  379,  287,  509,  191,  278,  403,
       108238  + /*  1550 */   572,  569,  497,  498,  496,  494,  335,  459,  445,  303,
       108239  + /*  1560 */   296,  246,  341,  355,    5,  568,  369,  507,  253,  549,
       108240  + /*  1570 */   526,  209,  400,  501,  500,  524,  234,  958,  489,  482,
108005 108241   };
108006 108242   static const YYCODETYPE yy_lookahead[] = {
108007         - /*     0 */    19,  142,  143,  144,  145,   24,    1,   26,   77,   78,
       108243  + /*     0 */    19,  169,  170,  171,   22,   24,   24,   26,   77,   78,
108008 108244    /*    10 */    79,   80,   81,   82,   83,   84,   85,   86,   87,   88,
108009         - /*    20 */    89,   90,   91,   92,   15,   98,   26,   27,    7,    8,
108010         - /*    30 */    49,   50,   77,   78,   79,   80,  109,   82,   83,   84,
108011         - /*    40 */    85,   86,   87,   88,   89,   90,   91,   92,   22,   68,
       108245  + /*    20 */    89,   90,   91,   92,   26,   27,    1,   26,   27,   15,
       108246  + /*    30 */    49,   50,   77,   78,   79,   80,  116,   82,   83,   84,
       108247  + /*    40 */    85,   86,   87,   88,   89,   90,   91,   92,  128,   68,
108012 108248    /*    50 */    69,   70,   71,   72,   73,   74,   75,   76,   77,   78,
108013         - /*    60 */    79,   80,   23,   82,   83,   84,   85,   86,   87,   88,
108014         - /*    70 */    89,   90,   91,   92,   19,   94,  112,   19,  114,  115,
       108249  + /*    60 */    79,   80,  230,   82,   83,   84,   85,   86,   87,   88,
       108250  + /*    70 */    89,   90,   91,   92,   19,   94,   19,   23,   86,   87,
108015 108251    /*    80 */    25,   82,   83,   84,   85,   86,   87,   88,   89,   90,
108016         - /*    90 */    91,   92,   19,   22,   94,   95,   96,  150,  150,   99,
108017         - /*   100 */   100,  101,   76,  150,   49,   50,  105,  106,  107,   54,
108018         - /*   110 */   110,  158,  165,  165,  161,  162,   26,   27,  165,  113,
108019         - /*   120 */    16,  174,  175,   68,   69,   70,   71,   72,   73,   74,
108020         - /*   130 */    75,   76,   77,   78,   79,   80,  118,   82,   83,   84,
108021         - /*   140 */    85,   86,   87,   88,   89,   90,   91,   92,   19,   23,
108022         - /*   150 */    92,   97,   98,   24,   96,   97,   98,   99,  100,  101,
108023         - /*   160 */   102,   25,   97,  216,   60,   92,   62,  109,  221,   25,
108024         - /*   170 */    97,   98,   99,  100,  101,  102,   86,   87,   49,   50,
108025         - /*   180 */   118,  116,  109,   25,   94,   95,   32,   97,   88,   89,
108026         - /*   190 */    90,   91,   92,  128,  104,   41,  106,   68,   69,   70,
       108252  + /*    90 */    91,   92,   94,   95,   19,   94,   95,   96,  172,  173,
       108253  + /*   100 */    99,  100,  101,  197,   49,   50,  177,  181,   22,   54,
       108254  + /*   110 */   204,  110,   26,   27,   86,   87,   88,   89,   90,   91,
       108255  + /*   120 */    92,  129,  130,   68,   69,   70,   71,   72,   73,   74,
       108256  + /*   130 */    75,   76,   77,   78,   79,   80,   22,   82,   83,   84,
       108257  + /*   140 */    85,   86,   87,   88,   89,   90,   91,   92,   19,   92,
       108258  + /*   150 */   221,  222,  223,   96,   97,   98,   99,  100,  101,  102,
       108259  + /*   160 */   112,   32,  114,  115,   26,   27,  109,   92,  150,   25,
       108260  + /*   170 */    41,  150,   97,   98,   99,  100,  101,  102,   49,   50,
       108261  + /*   180 */    94,   95,   98,  165,  109,   25,  165,  163,  170,  171,
       108262  + /*   190 */   166,  167,  168,  109,   12,  174,  175,   68,   69,   70,
108027 108263    /*   200 */    71,   72,   73,   74,   75,   76,   77,   78,   79,   80,
108028         - /*   210 */    11,   82,   83,   84,   85,   86,   87,   88,   89,   90,
108029         - /*   220 */    91,   92,   19,   19,   86,   87,   88,   89,   90,   91,
108030         - /*   230 */    92,   27,   96,  150,   66,   99,  100,  101,  112,  150,
108031         - /*   240 */   114,  115,  138,  150,  161,  162,  110,  103,  165,  222,
108032         - /*   250 */   223,  224,   49,   50,  165,   22,   57,   24,  165,  170,
108033         - /*   260 */   171,  118,   94,  170,  171,   23,   98,   25,  185,  186,
108034         - /*   270 */   243,   68,   69,   70,   71,   72,   73,   74,   75,   76,
108035         - /*   280 */    77,   78,   79,   80,  126,   82,   83,   84,   85,   86,
       108264  + /*   210 */    28,   82,   83,   84,   85,   86,   87,   88,   89,   90,
       108265  + /*   220 */    91,   92,   19,   11,   86,   87,   44,   24,   46,  221,
       108266  + /*   230 */   222,  223,   94,   95,   66,   97,  215,    7,    8,   57,
       108267  + /*   240 */   150,  220,  104,   19,  106,   26,   27,  229,  230,  241,
       108268  + /*   250 */   160,   27,   49,   50,   22,  165,   96,  118,   16,   99,
       108269  + /*   260 */   100,  101,   94,  119,  174,  175,   98,  129,  130,   57,
       108270  + /*   270 */   110,   68,   69,   70,   71,   72,   73,   74,   75,   76,
       108271  + /*   280 */    77,   78,   79,   80,  194,   82,   83,   84,   85,   86,
108036 108272    /*   290 */    87,   88,   89,   90,   91,   92,   19,  129,  130,  131,
108037         - /*   300 */    88,   23,  172,  173,  105,  106,  107,  150,   22,   26,
108038         - /*   310 */    27,  181,   26,   27,   22,  116,   26,   27,   26,  230,
108039         - /*   320 */   231,  197,  165,  230,  231,  113,   49,   50,  204,  117,
108040         - /*   330 */    96,  174,  175,   99,  100,  101,   22,   26,   27,  136,
108041         - /*   340 */    26,   27,  118,   16,  110,   68,   69,   70,   71,   72,
108042         - /*   350 */    73,   74,   75,   76,   77,   78,   79,   80,  118,   82,
       108273  + /*   300 */   150,   23,   60,   25,   62,  215,  150,  150,   76,  150,
       108274  + /*   310 */   220,  161,  162,   94,   95,  165,   30,  105,  106,  107,
       108275  + /*   320 */    34,  165,  165,   23,  165,   25,   49,   50,  116,  170,
       108276  + /*   330 */   171,  174,  175,   22,   48,  185,  186,   26,   27,  120,
       108277  + /*   340 */    26,   27,   12,  187,  160,   68,   69,   70,   71,   72,
       108278  + /*   350 */    73,   74,   75,   76,   77,   78,   79,   80,   28,   82,
108043 108279    /*   360 */    83,   84,   85,   86,   87,   88,   89,   90,   91,   92,
108044         - /*   370 */    19,  214,  215,  150,   23,   23,  155,   94,   95,   22,
108045         - /*   380 */    94,   95,  116,  160,   94,   95,   94,   60,  165,   62,
108046         - /*   390 */   112,   26,  114,  115,  128,   23,   36,  174,  175,   88,
108047         - /*   400 */    49,   50,   57,  120,   22,   94,   95,   23,   94,   95,
108048         - /*   410 */   120,   51,   25,  136,  169,  170,  171,  194,   58,   68,
       108280  + /*   370 */    19,  150,  215,   95,   44,   23,   46,  220,  194,   96,
       108281  + /*   380 */   138,  160,   99,  100,  101,   23,  165,   25,  229,  230,
       108282  + /*   390 */    26,   27,  135,  110,  137,  174,  175,   57,  120,  150,
       108283  + /*   400 */    49,   50,   88,  219,  113,   94,   95,  158,   94,   95,
       108284  + /*   410 */   161,  162,   21,  136,  165,  194,  169,  170,  171,   68,
108049 108285    /*   420 */    69,   70,   71,   72,   73,   74,   75,   76,   77,   78,
108050 108286    /*   430 */    79,   80,   23,   82,   83,   84,   85,   86,   87,   88,
108051         - /*   440 */    89,   90,   91,   92,   19,  150,   12,   12,   23,  228,
108052         - /*   450 */   105,  106,  107,   23,  233,   25,  165,   19,  150,   94,
108053         - /*   460 */   165,  116,   28,   28,  112,  174,  114,  115,  108,  174,
108054         - /*   470 */   175,   26,   27,  165,   49,   50,  231,   11,   44,   44,
108055         - /*   480 */    46,   46,  174,  175,  112,  160,  114,  115,   50,   22,
108056         - /*   490 */    23,   57,   25,   68,   69,   70,   71,   72,   73,   74,
108057         - /*   500 */    75,   76,   77,   78,   79,   80,  119,   82,   83,   84,
       108287  + /*   440 */    89,   90,   91,   92,   19,  105,  106,  107,   23,   88,
       108288  + /*   450 */    89,   90,   91,   92,   63,   23,  116,   88,   94,   95,
       108289  + /*   460 */   142,  143,  144,  145,  112,  150,  114,  115,  105,  106,
       108290  + /*   470 */   107,   23,   23,   25,   49,   50,  118,  230,   97,   98,
       108291  + /*   480 */   165,   16,  113,  118,  120,  160,  117,  136,  113,  174,
       108292  + /*   490 */   175,  100,  117,   68,   69,   70,   71,   72,   73,   74,
       108293  + /*   500 */    75,   76,   77,   78,   79,   80,  160,   82,   83,   84,
108058 108294    /*   510 */    85,   86,   87,   88,   89,   90,   91,   92,   19,  194,
108059         - /*   520 */   225,   23,   23,  215,   19,   95,  105,  106,  107,  150,
108060         - /*   530 */    23,  150,   27,   23,   67,   25,  150,  206,  207,   94,
108061         - /*   540 */    95,  166,  104,  218,  165,   22,  165,  109,   49,   50,
108062         - /*   550 */   120,  165,   25,  174,  175,  174,  175,   23,   21,  234,
108063         - /*   560 */   174,  175,   22,   23,  239,   25,   25,   68,   69,   70,
       108295  + /*   520 */    25,  112,   23,  114,  115,   60,  150,   62,  150,  138,
       108296  + /*   530 */   150,  105,  106,  107,   19,  150,   36,  161,  162,  224,
       108297  + /*   540 */   194,  165,  217,  165,  112,  165,  114,  115,   49,   50,
       108298  + /*   550 */   165,   51,  174,  175,  174,  175,  166,  232,   58,  174,
       108299  + /*   560 */   175,  112,  237,  114,  115,   50,   22,   68,   69,   70,
108064 108300    /*   570 */    71,   72,   73,   74,   75,   76,   77,   78,   79,   80,
108065         - /*   580 */   205,   82,   83,   84,   85,   86,   87,   88,   89,   90,
108066         - /*   590 */    91,   92,   19,   22,   23,  216,   23,  222,  223,  224,
108067         - /*   600 */    63,  220,   35,  150,  150,  163,  220,   67,  166,  167,
108068         - /*   610 */   168,  150,  169,  170,  171,  161,  162,   25,  165,  165,
108069         - /*   620 */   150,  113,   49,   50,   25,  117,  165,  174,  175,   35,
108070         - /*   630 */     7,    8,    9,  160,  160,  165,  120,  100,   67,  247,
108071         - /*   640 */   248,   68,   69,   70,   71,   72,   73,   74,   75,   76,
108072         - /*   650 */    77,   78,   79,   80,  193,   82,   83,   84,   85,   86,
108073         - /*   660 */    87,   88,   89,   90,   91,   92,   19,  194,  194,  150,
108074         - /*   670 */   135,   24,  137,   35,  231,  138,  150,  129,  130,  206,
108075         - /*   680 */   207,   30,   27,  213,  165,   34,  118,   95,    0,    1,
108076         - /*   690 */     2,  165,  218,  174,  175,   50,   49,   50,   22,   48,
108077         - /*   700 */   174,  175,   22,   23,   23,  244,  222,  223,  224,  166,
108078         - /*   710 */   167,  168,  120,  239,   23,   68,   69,   70,   71,   72,
108079         - /*   720 */    73,   74,   75,   76,   77,   78,   79,   80,  150,   82,
       108301  + /*   580 */   160,   82,   83,   84,   85,   86,   87,   88,   89,   90,
       108302  + /*   590 */    91,   92,   19,  215,  214,  205,   23,    7,    8,    9,
       108303  + /*   600 */   215,  155,   24,   22,   26,  150,   97,   26,  108,  129,
       108304  + /*   610 */   130,  221,  222,  223,  194,    0,    1,    2,  150,  104,
       108305  + /*   620 */   165,  126,   49,   50,  109,  116,  206,  207,  118,  174,
       108306  + /*   630 */   175,   22,   23,  165,   25,   22,   23,  128,   25,  118,
       108307  + /*   640 */    26,   68,   69,   70,   71,   72,   73,   74,   75,   76,
       108308  + /*   650 */    77,   78,   79,   80,  150,   82,   83,   84,   85,   86,
       108309  + /*   660 */    87,   88,   89,   90,   91,   92,   19,  150,  150,  165,
       108310  + /*   670 */    23,  160,   94,  227,  150,   94,   67,  231,  174,  175,
       108311  + /*   680 */    67,  213,  165,  165,  221,  222,  223,  150,  150,  165,
       108312  + /*   690 */    23,   32,  174,  175,  181,  182,   49,   50,  174,  175,
       108313  + /*   700 */    41,  188,  165,  165,   22,  194,  177,   11,   94,   23,
       108314  + /*   710 */   193,  174,  175,  160,   22,   68,   69,   70,   71,   72,
       108315  + /*   720 */    73,   74,   75,   76,   77,   78,   79,   80,  217,   82,
108080 108316    /*   730 */    83,   84,   85,   86,   87,   88,   89,   90,   91,   92,
108081         - /*   740 */    19,  150,  173,  165,  181,  182,   24,   67,   26,  104,
108082         - /*   750 */   181,  188,  174,  175,  150,   39,  165,  150,   52,  150,
108083         - /*   760 */   150,  150,  150,  144,  145,  174,  175,  249,  250,  165,
108084         - /*   770 */    49,   50,  165,   52,  165,  165,  165,  165,  174,  175,
108085         - /*   780 */    29,  174,  175,  174,  175,  174,  175,  160,   22,   68,
       108317  + /*   740 */    19,  150,  150,  150,   25,   24,   19,  194,  237,  150,
       108318  + /*   750 */   221,  222,  223,   25,   27,   23,  165,  165,  165,  242,
       108319  + /*   760 */   165,   23,  150,   25,  165,  174,  175,  174,  175,  174,
       108320  + /*   770 */    49,   50,  219,  150,   22,   23,  238,  165,   25,   22,
       108321  + /*   780 */    23,   23,  166,  167,  168,  193,  174,  175,  165,   68,
108086 108322    /*   790 */    69,   70,   71,   72,   73,   74,   75,   76,   77,   78,
108087 108323    /*   800 */    79,   80,  150,   82,   83,   84,   85,   86,   87,   88,
108088         - /*   810 */    89,   90,   91,   92,   19,  150,   94,  165,  150,  150,
108089         - /*   820 */   160,  194,  150,  213,  160,   52,  174,  175,   23,   23,
108090         - /*   830 */   165,   25,   22,  165,  165,  150,  150,  165,   52,  174,
108091         - /*   840 */   175,   22,  174,  175,   49,   50,  174,  175,  190,  191,
108092         - /*   850 */   165,  165,  240,   23,  194,   25,  187,  109,  194,  174,
108093         - /*   860 */   175,  190,  191,   68,   69,   70,   71,   72,   73,   74,
       108324  + /*   810 */    89,   90,   91,   92,   19,  150,   23,  165,  150,   67,
       108325  + /*   820 */   150,   25,  103,   95,   67,   35,  174,  175,  206,  207,
       108326  + /*   830 */   165,  150,   25,  165,  150,  165,  213,  150,  150,  174,
       108327  + /*   840 */   175,   35,  174,  175,   49,   50,  165,   52,  120,  165,
       108328  + /*   850 */   245,  246,  165,  165,   35,  174,  175,  187,  174,  175,
       108329  + /*   860 */    23,   50,   25,   68,   69,   70,   71,   72,   73,   74,
108094 108330    /*   870 */    75,   76,   77,   78,   79,   80,  150,   82,   83,   84,
108095 108331    /*   880 */    85,   86,   87,   88,   89,   90,   91,   92,   19,  150,
108096         - /*   890 */    22,  165,  150,   23,  150,   25,  150,  166,   91,   92,
108097         - /*   900 */   174,  175,   22,  217,  165,  150,  102,  165,  150,  165,
108098         - /*   910 */   150,  165,  150,  174,  175,   19,  174,  175,   49,   50,
108099         - /*   920 */   165,   86,   87,  165,   23,  165,   25,  165,   24,  174,
108100         - /*   930 */   175,  187,  174,  175,  174,  175,  205,   68,   69,   70,
       108332  + /*   890 */   150,  165,  150,  150,  160,   23,  150,   25,  144,  145,
       108333  + /*   900 */   174,  175,  120,  216,  165,  165,   22,  165,  165,  150,
       108334  + /*   910 */   150,  165,   27,  174,  175,  104,  174,  175,   49,   50,
       108335  + /*   920 */   174,  175,  247,  248,  165,  165,  238,  187,  194,   23,
       108336  + /*   930 */   187,   25,  166,  174,  175,  190,  191,   68,   69,   70,
108101 108337    /*   940 */    71,   72,   73,   74,   75,   76,   77,   78,   79,   80,
108102 108338    /*   950 */   150,   82,   83,   84,   85,   86,   87,   88,   89,   90,
108103         - /*   960 */    91,   92,   19,  150,  150,  165,  150,  150,  166,   23,
108104         - /*   970 */   150,   25,  160,   20,  174,  175,    1,    2,  165,  165,
108105         - /*   980 */   104,  165,  165,   43,  150,  165,  240,  150,   49,   50,
108106         - /*   990 */   174,  175,   49,   50,   23,   23,   25,   25,   53,  165,
108107         - /*  1000 */   187,  187,  165,   23,  187,   25,  194,  205,  174,  175,
108108         - /*  1010 */    71,   72,   69,   70,   71,   72,   73,   74,   75,   76,
       108339  + /*   960 */    91,   92,   19,  150,  150,  165,  150,   23,  150,   25,
       108340  + /*   970 */    23,  205,   25,  213,  174,  175,  190,  191,  165,  165,
       108341  + /*   980 */   118,  165,  150,  165,  150,  150,   23,  174,  175,   39,
       108342  + /*   990 */   174,  175,   49,   50,  173,  150,   23,  165,   52,  165,
       108343  + /*  1000 */   165,  187,  181,   22,  166,  166,  174,  175,  174,  175,
       108344  + /*  1010 */   165,   68,   69,   70,   71,   72,   73,   74,   75,   76,
108109 108345    /*  1020 */    77,   78,   79,   80,  150,   82,   83,   84,   85,   86,
108110         - /*  1030 */    87,   88,   89,   90,   91,   92,   19,   98,  150,  165,
108111         - /*  1040 */   150,  160,  150,   59,   25,   53,  104,   22,  174,  175,
108112         - /*  1050 */   213,  138,    5,  165,    1,  165,  150,  165,  150,  150,
108113         - /*  1060 */   240,  150,  174,  175,  174,  175,   49,   50,  118,  150,
108114         - /*  1070 */    35,  165,   27,  165,  165,  194,  165,  108,  127,   76,
108115         - /*  1080 */   174,  175,  174,  175,  165,  174,  175,   70,   71,   72,
108116         - /*  1090 */    73,   74,   75,   76,   77,   78,   79,   80,  166,   82,
       108346  + /*  1030 */    87,   88,   89,   90,   91,   92,   19,  150,  193,  165,
       108347  + /*  1040 */   150,  160,  150,  205,  205,  150,  150,   29,  174,  175,
       108348  + /*  1050 */    52,  216,  165,   22,  150,  165,  238,  165,  150,  150,
       108349  + /*  1060 */   165,  165,   49,   50,  174,  175,   49,   50,   23,  165,
       108350  + /*  1070 */    91,   92,   22,  165,  165,  194,    1,    2,   22,   52,
       108351  + /*  1080 */   193,  109,  174,  175,   71,   72,   69,   70,   71,   72,
       108352  + /*  1090 */    73,   74,   75,   76,   77,   78,   79,   80,  150,   82,
108117 108353    /*  1100 */    83,   84,   85,   86,   87,   88,   89,   90,   91,   92,
108118         - /*  1110 */    19,   20,  193,   22,  150,  150,  150,   26,   27,   76,
108119         - /*  1120 */   150,   22,    1,  150,  119,  121,  217,   20,   37,  165,
108120         - /*  1130 */   165,  165,   16,   19,   20,  165,   22,  205,  165,  119,
108121         - /*  1140 */    26,   27,  108,  128,  150,  150,  150,   56,  150,   22,
108122         - /*  1150 */   150,   37,  150,  127,  160,   23,  150,   66,  193,  165,
108123         - /*  1160 */   165,  165,   16,  165,   23,  165,  150,  165,  174,  175,
108124         - /*  1170 */    56,  165,  150,   65,  174,  175,   15,   86,   87,   88,
108125         - /*  1180 */    66,  165,  140,  150,   93,   94,   95,  165,  194,   98,
108126         - /*  1190 */   174,  175,   22,    3,  164,  193,  174,  175,  165,  150,
108127         - /*  1200 */    86,   87,    4,  180,  150,  248,  251,   93,   94,   95,
108128         - /*  1210 */   216,  180,   98,  251,  165,  221,  150,  149,    6,  165,
108129         - /*  1220 */   129,  130,  131,  132,  133,  134,  193,  150,  174,  175,
108130         - /*  1230 */   116,  165,   19,   20,  150,   22,  149,  151,  150,   26,
108131         - /*  1240 */    27,  149,  165,  129,  130,  131,  132,  133,  134,  165,
108132         - /*  1250 */    37,  174,  175,  165,  149,   19,   20,   13,   22,  150,
108133         - /*  1260 */   150,  150,   26,   27,  146,  147,  151,  150,   25,   56,
108134         - /*  1270 */   152,  159,  154,   37,  165,  165,  165,  193,  160,   66,
108135         - /*  1280 */   116,  193,  165,  174,  175,  174,  175,  194,  199,  150,
108136         - /*  1290 */   200,  126,   56,  124,  123,  150,  201,  122,  150,   86,
108137         - /*  1300 */    87,  150,   66,  193,  165,  202,   93,   94,   95,  150,
108138         - /*  1310 */   165,   98,  194,  165,  125,   22,  165,  150,  150,   26,
108139         - /*  1320 */    27,  135,   86,   87,  165,  174,  175,  203,  226,   93,
108140         - /*  1330 */    94,   95,  165,  165,   98,  150,  218,  150,  193,  157,
108141         - /*  1340 */   118,  157,  129,  130,  131,  132,  133,  134,    5,  104,
108142         - /*  1350 */   165,  211,  165,   10,   11,   12,   13,   14,  150,   66,
108143         - /*  1360 */    17,  174,  175,  210,  246,  129,  130,  131,  132,  133,
108144         - /*  1370 */   134,  150,  210,  165,   31,  121,   33,  150,  150,   86,
108145         - /*  1380 */    87,  176,  174,  175,  150,   42,  165,   94,  211,  210,
108146         - /*  1390 */   150,   98,  165,  165,  211,  174,  175,  150,   55,  165,
108147         - /*  1400 */    57,  150,  174,  175,   61,  165,  150,   64,  174,  175,
108148         - /*  1410 */   150,  150,  165,  150,  174,  175,  165,  104,  150,  184,
108149         - /*  1420 */   150,  165,  129,  130,  131,  165,  165,  150,  165,  150,
108150         - /*  1430 */   150,  176,  150,  165,   47,  165,  150,  150,  176,  103,
108151         - /*  1440 */   150,   22,  165,  178,  165,  165,  179,  165,  105,  106,
108152         - /*  1450 */   107,  165,  165,  229,  111,  165,   92,  176,  229,  116,
108153         - /*  1460 */   184,  176,  179,  156,  176,  176,   18,  157,  156,  237,
108154         - /*  1470 */    45,  157,  156,  135,  157,  157,  238,  156,   68,  157,
108155         - /*  1480 */   189,  189,  139,  219,   22,  157,   18,  192,  192,  192,
108156         - /*  1490 */   192,  189,  219,  199,  157,  242,   40,  157,  199,  242,
108157         - /*  1500 */   153,  157,   38,  245,  196,  166,  232,  198,  177,  177,
108158         - /*  1510 */   232,  227,  209,  178,  166,  182,  166,  148,  177,  177,
108159         - /*  1520 */   209,  196,  177,  199,  209,  199,  166,  208,   92,  195,
108160         - /*  1530 */   174,  174,  183,  252,  183,  183,  252,  191,  252,  235,
108161         - /*  1540 */   186,  241,  241,  252,  186,  252,  252,  252,  252,  252,
108162         - /*  1550 */   252,  252,  252,  252,  252,  252,  236,
108163         -};
108164         -#define YY_SHIFT_USE_DFLT (-74)
108165         -#define YY_SHIFT_COUNT (418)
108166         -#define YY_SHIFT_MIN   (-73)
108167         -#define YY_SHIFT_MAX   (1468)
       108354  + /*  1110 */    19,   98,  150,  165,  150,  150,  150,  102,  150,  150,
       108355  + /*  1120 */    22,   19,  174,  175,   20,   24,  104,  165,   43,  165,
       108356  + /*  1130 */   165,  165,  150,  165,  165,  150,  174,  175,  174,  175,
       108357  + /*  1140 */    49,   50,   59,   53,  138,   25,   53,  165,  104,   22,
       108358  + /*  1150 */   165,    5,  118,    1,   76,   76,  174,  175,  193,  174,
       108359  + /*  1160 */   175,   70,   71,   72,   73,   74,   75,   76,   77,   78,
       108360  + /*  1170 */    79,   80,   35,   82,   83,   84,   85,   86,   87,   88,
       108361  + /*  1180 */    89,   90,   91,   92,   19,   20,  150,   22,  150,  150,
       108362  + /*  1190 */   150,   26,   27,   27,  108,  127,  150,  150,   22,   25,
       108363  + /*  1200 */    22,  165,   37,  165,  165,  165,  119,   19,   20,  150,
       108364  + /*  1210 */    22,  165,  165,  150,   26,   27,   23,    1,   16,   20,
       108365  + /*  1220 */   150,   56,  119,  108,  165,   37,  121,  128,  165,  193,
       108366  + /*  1230 */    23,   66,  193,  174,  175,  165,  127,  174,  175,   16,
       108367  + /*  1240 */    23,  146,  147,   15,   56,   65,  150,  152,  140,  154,
       108368  + /*  1250 */   150,   86,   87,   88,   66,  160,   22,  150,   93,   94,
       108369  + /*  1260 */    95,  165,  150,   98,  150,  165,    3,  246,    4,  150,
       108370  + /*  1270 */   174,  175,  165,  150,   86,   87,    6,  165,  150,  165,
       108371  + /*  1280 */   164,   93,   94,   95,  165,  149,   98,  149,  165,  194,
       108372  + /*  1290 */   180,  180,  249,  165,  129,  130,  131,  132,  133,  134,
       108373  + /*  1300 */   193,  150,  174,  175,  116,  193,   19,   20,  150,   22,
       108374  + /*  1310 */   249,  149,  217,   26,   27,  151,  165,  129,  130,  131,
       108375  + /*  1320 */   132,  133,  134,  165,   37,  174,  175,  150,  149,   19,
       108376  + /*  1330 */    20,  150,   22,  150,  150,  150,   26,   27,   13,  244,
       108377  + /*  1340 */   151,  159,  165,   56,   25,  116,  165,   37,  165,  165,
       108378  + /*  1350 */   165,  174,  175,   66,  150,  174,  175,  174,  175,  174,
       108379  + /*  1360 */   175,  194,  150,  150,  150,  126,   56,  199,  124,  165,
       108380  + /*  1370 */   200,  150,  150,   86,   87,  150,   66,  165,  165,  165,
       108381  + /*  1380 */    93,   94,   95,  150,  122,   98,  165,  165,  123,   22,
       108382  + /*  1390 */   165,  201,  150,   26,   27,  150,   86,   87,  165,  174,
       108383  + /*  1400 */   175,  203,  202,   93,   94,   95,  125,  165,   98,  150,
       108384  + /*  1410 */   165,  150,  225,  135,  157,  118,  129,  130,  131,  132,
       108385  + /*  1420 */   133,  134,    5,  150,  165,  157,  165,   10,   11,   12,
       108386  + /*  1430 */    13,   14,  150,   66,   17,  174,  175,  210,  165,  129,
       108387  + /*  1440 */   130,  131,  132,  133,  134,  150,  104,  165,   31,  150,
       108388  + /*  1450 */    33,  150,  150,   86,   87,  150,  174,  175,  211,   42,
       108389  + /*  1460 */   165,   94,  121,  210,  165,   98,  165,  165,  176,  211,
       108390  + /*  1470 */   165,  211,   55,  104,   57,  184,  210,   47,   61,  176,
       108391  + /*  1480 */   176,   64,  103,  176,  178,   22,   92,  179,  176,  176,
       108392  + /*  1490 */   176,  156,   18,  184,  179,  228,  129,  130,  131,  228,
       108393  + /*  1500 */   157,  156,   45,  157,  156,  236,  157,  157,  135,  235,
       108394  + /*  1510 */   156,  189,  157,   68,  218,  189,   22,  199,  156,  192,
       108395  + /*  1520 */   157,   18,  105,  106,  107,  192,  192,  199,  111,  192,
       108396  + /*  1530 */   240,  157,   40,  116,  218,  157,  189,  157,  240,   38,
       108397  + /*  1540 */   153,  166,  198,  243,  178,  209,  182,  196,  177,  226,
       108398  + /*  1550 */   230,  230,  166,  177,  177,  166,  139,  199,  199,  148,
       108399  + /*  1560 */   195,  209,  209,  239,  196,  166,  234,  183,  239,  208,
       108400  + /*  1570 */   174,  233,  191,  183,  183,  174,   92,  250,  186,  186,
       108401  +};
       108402  +#define YY_SHIFT_USE_DFLT (-81)
       108403  +#define YY_SHIFT_COUNT (417)
       108404  +#define YY_SHIFT_MIN   (-80)
       108405  +#define YY_SHIFT_MAX   (1503)
108168 108406   static const short yy_shift_ofst[] = {
108169         - /*     0 */   975, 1114, 1343, 1114, 1213, 1213,   90,   90,    0,  -19,
108170         - /*    10 */  1213, 1213, 1213, 1213, 1213,  345,  445,  721, 1091, 1213,
108171         - /*    20 */  1213, 1213, 1213, 1213, 1213, 1213, 1213, 1213, 1213, 1213,
108172         - /*    30 */  1213, 1213, 1213, 1213, 1213, 1213, 1213, 1213, 1213, 1213,
108173         - /*    40 */  1213, 1213, 1213, 1213, 1213, 1213, 1213, 1236, 1213, 1213,
108174         - /*    50 */  1213, 1213, 1213, 1213, 1213, 1213, 1213, 1213, 1213, 1213,
108175         - /*    60 */  1213,  199,  445,  445,  835,  835,  365, 1164,   55,  647,
108176         - /*    70 */   573,  499,  425,  351,  277,  203,  129,  795,  795,  795,
108177         - /*    80 */   795,  795,  795,  795,  795,  795,  795,  795,  795,  795,
108178         - /*    90 */   795,  795,  795,  795,  795,  869,  795,  943, 1017, 1017,
108179         - /*   100 */   -69,  -45,  -45,  -45,  -45,  -45,   -1,   58,  138,  100,
108180         - /*   110 */   445,  445,  445,  445,  445,  445,  445,  445,  445,  445,
108181         - /*   120 */   445,  445,  445,  445,  445,  445,  537,  438,  445,  445,
108182         - /*   130 */   445,  445,  445,  365,  807, 1436,  -74,  -74,  -74, 1293,
108183         - /*   140 */    73,  434,  434,  311,  314,  290,  283,  286,  540,  467,
108184         - /*   150 */   445,  445,  445,  445,  445,  445,  445,  445,  445,  445,
108185         - /*   160 */   445,  445,  445,  445,  445,  445,  445,  445,  445,  445,
108186         - /*   170 */   445,  445,  445,  445,  445,  445,  445,  445,  445,  445,
108187         - /*   180 */   445,  445,   65,  722,  722,  722,  688,  266, 1164, 1164,
108188         - /*   190 */  1164,  -74,  -74,  -74,  136,  168,  168,  234,  360,  360,
108189         - /*   200 */   360,  430,  372,  435,  352,  278,  126,  -36,  -36,  -36,
108190         - /*   210 */   -36,  421,  651,  -36,  -36,  592,  292,  212,  623,  158,
108191         - /*   220 */   204,  204,  505,  158,  505,  144,  365,  154,  365,  154,
108192         - /*   230 */   645,  154,  204,  154,  154,  535,  548,  548,  365,  387,
108193         - /*   240 */   508,  233, 1464, 1222, 1222, 1456, 1456, 1222, 1462, 1410,
108194         - /*   250 */  1165, 1468, 1468, 1468, 1468, 1222, 1165, 1462, 1410, 1410,
108195         - /*   260 */  1222, 1448, 1338, 1425, 1222, 1222, 1448, 1222, 1448, 1222,
108196         - /*   270 */  1448, 1419, 1313, 1313, 1313, 1387, 1364, 1364, 1419, 1313,
108197         - /*   280 */  1336, 1313, 1387, 1313, 1313, 1254, 1245, 1254, 1245, 1254,
108198         - /*   290 */  1245, 1222, 1222, 1186, 1189, 1175, 1169, 1171, 1165, 1164,
108199         - /*   300 */  1243, 1244, 1244, 1212, 1212, 1212, 1212,  -74,  -74,  -74,
108200         - /*   310 */   -74,  -74,  -74,  939,  104,  680,  571,  327,    1,  980,
108201         - /*   320 */    26,  972,  971,  946,  901,  870,  830,  806,   54,   21,
108202         - /*   330 */   -73,  510,  242, 1198, 1190, 1170, 1042, 1161, 1108, 1146,
108203         - /*   340 */  1141, 1132, 1015, 1127, 1026, 1034, 1020, 1107, 1004, 1116,
108204         - /*   350 */  1121, 1005, 1099,  951, 1043, 1003,  969, 1045, 1035,  950,
108205         - /*   360 */  1053, 1047, 1025,  942,  913,  992, 1019,  945,  984,  940,
108206         - /*   370 */   876,  904,  953,  896,  748,  804,  880,  786,  868,  819,
108207         - /*   380 */   805,  810,  773,  751,  766,  706,  716,  691,  681,  568,
108208         - /*   390 */   655,  638,  676,  516,  541,  594,  599,  567,  541,  534,
108209         - /*   400 */   507,  527,  498,  523,  466,  382,  409,  384,  357,    6,
108210         - /*   410 */   240,  224,  143,   62,   18,   71,   39,    9,    5,
108211         -};
108212         -#define YY_REDUCE_USE_DFLT (-142)
108213         -#define YY_REDUCE_COUNT (312)
108214         -#define YY_REDUCE_MIN   (-141)
108215         -#define YY_REDUCE_MAX   (1369)
       108407  + /*     0 */  1075, 1188, 1417, 1188, 1287, 1287,  138,  138,    1,  -19,
       108408  + /*    10 */  1287, 1287, 1287, 1287,  340,   -2,  129,  129,  795, 1165,
       108409  + /*    20 */  1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287,
       108410  + /*    30 */  1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287,
       108411  + /*    40 */  1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1310, 1287,
       108412  + /*    50 */  1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287,
       108413  + /*    60 */  1287, 1287,  212,   -2,   -2,   -8,   -8,  614, 1229,   55,
       108414  + /*    70 */   721,  647,  573,  499,  425,  351,  277,  203,  869,  869,
       108415  + /*    80 */   869,  869,  869,  869,  869,  869,  869,  869,  869,  869,
       108416  + /*    90 */   869,  869,  869,  943,  869, 1017, 1091, 1091,  -69,  -45,
       108417  + /*   100 */   -45,  -45,  -45,  -45,   -1,   57,   28,  361,   -2,   -2,
       108418  + /*   110 */    -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,
       108419  + /*   120 */    -2,   -2,   -2,   -2,  391,  515,   -2,   -2,   -2,   -2,
       108420  + /*   130 */    -2,  509,  -80,  614,  979, 1484,  -81,  -81,  -81, 1367,
       108421  + /*   140 */    75,  182,  182,  314,  311,  364,  219,   86,  613,  609,
       108422  + /*   150 */    -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,
       108423  + /*   160 */    -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,
       108424  + /*   170 */    -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,
       108425  + /*   180 */    -2,   -2,  578,  578,  578,  615, 1229, 1229, 1229,  -81,
       108426  + /*   190 */   -81,  -81,  160,  168,  168,  283,  500,  500,  500,  278,
       108427  + /*   200 */   449,  330,  432,  409,  352,   48,   48,   48,   48,  426,
       108428  + /*   210 */   286,   48,   48,  728,  581,  369,  590,  495,  224,  224,
       108429  + /*   220 */   727,  495,  727,  719,  614,  659,  614,  659,  811,  659,
       108430  + /*   230 */   224,  257,  480,  480,  614,  144,  375,  -18, 1501, 1297,
       108431  + /*   240 */  1297, 1492, 1492, 1297, 1494, 1445, 1239, 1503, 1503, 1503,
       108432  + /*   250 */  1503, 1297, 1474, 1239, 1494, 1445, 1445, 1297, 1474, 1373,
       108433  + /*   260 */  1457, 1297, 1297, 1474, 1297, 1474, 1297, 1474, 1463, 1369,
       108434  + /*   270 */  1369, 1369, 1430, 1394, 1394, 1463, 1369, 1379, 1369, 1430,
       108435  + /*   280 */  1369, 1369, 1341, 1342, 1341, 1342, 1341, 1342, 1297, 1297,
       108436  + /*   290 */  1278, 1281, 1262, 1244, 1265, 1239, 1229, 1319, 1325, 1325,
       108437  + /*   300 */  1270, 1270, 1270, 1270,  -81,  -81,  -81,  -81,  -81,  -81,
       108438  + /*   310 */  1013,  242,  757,  752,  465,  363,  947,  232,  944,  906,
       108439  + /*   320 */   872,  837,  738,  448,  381,  230,   84,  362,  300, 1264,
       108440  + /*   330 */  1263, 1234, 1108, 1228, 1180, 1223, 1217, 1207, 1099, 1174,
       108441  + /*   340 */  1109, 1115, 1103, 1199, 1105, 1202, 1216, 1087, 1193, 1178,
       108442  + /*   350 */  1174, 1176, 1068, 1079, 1078, 1086, 1166, 1137, 1034, 1152,
       108443  + /*   360 */  1146, 1127, 1044, 1006, 1093, 1120, 1090, 1083, 1085, 1022,
       108444  + /*   370 */  1101, 1104, 1102,  972, 1015, 1098, 1027, 1056, 1050, 1045,
       108445  + /*   380 */  1031,  998, 1018,  981,  946,  950,  973,  963,  862,  885,
       108446  + /*   390 */   819,  884,  782,  796,  806,  807,  790,  796,  793,  758,
       108447  + /*   400 */   753,  732,  692,  696,  682,  686,  667,  544,  291,  521,
       108448  + /*   410 */   510,  365,  358,  139,  114,   54,   14,   25,
       108449  +};
       108450  +#define YY_REDUCE_USE_DFLT (-169)
       108451  +#define YY_REDUCE_COUNT (309)
       108452  +#define YY_REDUCE_MIN   (-168)
       108453  +#define YY_REDUCE_MAX   (1411)
108216 108454   static const short yy_reduce_ofst[] = {
108217         - /*     0 */  -141,  994, 1118,  223,  157,  -53,   93,   89,   83,  375,
108218         - /*    10 */   386,  381,  379,  308,  295,  325,  -47,   27, 1240, 1234,
108219         - /*    20 */  1228, 1221, 1208, 1187, 1151, 1111, 1109, 1077, 1054, 1022,
108220         - /*    30 */  1016, 1000,  911,  908,  906,  890,  888,  874,  834,  816,
108221         - /*    40 */   800,  760,  758,  755,  742,  739,  726,  685,  672,  668,
108222         - /*    50 */   665,  652,  611,  609,  607,  604,  591,  578,  526,  519,
108223         - /*    60 */   453,  474,  454,  461,  443,  245,  442,  473,  484,  484,
108224         - /*    70 */   484,  484,  484,  484,  484,  484,  484,  484,  484,  484,
108225         - /*    80 */   484,  484,  484,  484,  484,  484,  484,  484,  484,  484,
108226         - /*    90 */   484,  484,  484,  484,  484,  484,  484,  484,  484,  484,
108227         - /*   100 */   484,  484,  484,  484,  484,  484,  484,  130,  484,  484,
108228         - /*   110 */  1145,  909, 1110, 1088, 1084, 1033, 1002,  965,  820,  837,
108229         - /*   120 */   746,  686,  612,  817,  610,  919,  221,  563,  814,  813,
108230         - /*   130 */   744,  669,  470,  543,  484,  484,  484,  484,  484,  291,
108231         - /*   140 */   569,  671,  658,  970, 1290, 1287, 1286, 1282,  518,  518,
108232         - /*   150 */  1280, 1279, 1277, 1270, 1268, 1263, 1261, 1260, 1256, 1251,
108233         - /*   160 */  1247, 1227, 1185, 1168, 1167, 1159, 1148, 1139, 1117, 1066,
108234         - /*   170 */  1049, 1006,  998,  996,  995,  973,  970,  966,  964,  892,
108235         - /*   180 */   762,  -52,  881,  932,  802,  731,  619,  812,  664,  660,
108236         - /*   190 */   627,  392,  331,  124, 1358, 1357, 1356, 1354, 1352, 1351,
108237         - /*   200 */  1349, 1319, 1334, 1346, 1334, 1334, 1334, 1334, 1334, 1334,
108238         - /*   210 */  1334, 1320, 1304, 1334, 1334, 1319, 1360, 1325, 1369, 1326,
108239         - /*   220 */  1315, 1311, 1301, 1324, 1300, 1335, 1350, 1345, 1348, 1342,
108240         - /*   230 */  1333, 1341, 1303, 1332, 1331, 1284, 1278, 1274, 1339, 1309,
108241         - /*   240 */  1308, 1347, 1258, 1344, 1340, 1257, 1253, 1337, 1273, 1302,
108242         - /*   250 */  1299, 1298, 1297, 1296, 1295, 1328, 1294, 1264, 1292, 1291,
108243         - /*   260 */  1322, 1321, 1238, 1232, 1318, 1317, 1316, 1314, 1312, 1310,
108244         - /*   270 */  1307, 1283, 1289, 1288, 1285, 1276, 1229, 1224, 1267, 1281,
108245         - /*   280 */  1265, 1262, 1235, 1255, 1205, 1183, 1179, 1177, 1162, 1140,
108246         - /*   290 */  1153, 1184, 1182, 1102, 1124, 1103, 1095, 1090, 1089, 1093,
108247         - /*   300 */  1112, 1115, 1086, 1105, 1092, 1087, 1068,  962,  955,  957,
108248         - /*   310 */  1031, 1023, 1030,
       108455  + /*     0 */   318,   90, 1095,  221,  157,   21,  159,   18,  150,  390,
       108456  + /*    10 */   385,  378,  380,  315,  325,  249,  529,  -71,    8, 1282,
       108457  + /*    20 */  1261, 1225, 1185, 1183, 1181, 1177, 1151, 1128, 1096, 1063,
       108458  + /*    30 */  1059,  985,  982,  964,  962,  948,  908,  890,  874,  834,
       108459  + /*    40 */   832,  816,  813,  800,  759,  746,  742,  739,  726,  684,
       108460  + /*    50 */   681,  668,  665,  652,  612,  593,  591,  537,  524,  518,
       108461  + /*    60 */   504,  455,  511,  376,  517,  247, -168,   24,  420,  463,
       108462  + /*    70 */   463,  463,  463,  463,  463,  463,  463,  463,  463,  463,
       108463  + /*    80 */   463,  463,  463,  463,  463,  463,  463,  463,  463,  463,
       108464  + /*    90 */   463,  463,  463,  463,  463,  463,  463,  463,  463,  463,
       108465  + /*   100 */   463,  463,  463,  463,  463,  -74,  463,  463, 1112,  835,
       108466  + /*   110 */  1107, 1039, 1036,  965,  887,  845,  818,  760,  688,  687,
       108467  + /*   120 */   538,  743,  623,  592,  446,  513,  814,  740,  670,  156,
       108468  + /*   130 */   468,  553,  184,  616,  463,  463,  463,  463,  463,  595,
       108469  + /*   140 */   821,  786,  745,  909, 1305, 1302, 1301, 1299,  675,  675,
       108470  + /*   150 */  1295, 1273, 1259, 1245, 1242, 1233, 1222, 1221, 1214, 1213,
       108471  + /*   160 */  1212, 1204, 1184, 1158, 1123, 1119, 1114, 1100, 1070, 1047,
       108472  + /*   170 */  1046, 1040, 1038,  969,  968,  966,  909,  904,  896,  895,
       108473  + /*   180 */   892,  599,  839,  838,  766,  754,  881,  734,  346,  605,
       108474  + /*   190 */   622,  -94, 1393, 1401, 1396, 1392, 1391, 1390, 1384, 1361,
       108475  + /*   200 */  1365, 1381, 1365, 1365, 1365, 1365, 1365, 1365, 1365, 1332,
       108476  + /*   210 */  1338, 1365, 1365, 1361, 1399, 1368, 1411, 1359, 1353, 1352,
       108477  + /*   220 */  1329, 1358, 1324, 1366, 1389, 1377, 1386, 1376, 1364, 1371,
       108478  + /*   230 */  1336, 1323, 1321, 1320, 1375, 1344, 1351, 1387, 1300, 1380,
       108479  + /*   240 */  1378, 1298, 1290, 1374, 1316, 1347, 1328, 1337, 1334, 1333,
       108480  + /*   250 */  1327, 1363, 1362, 1318, 1296, 1326, 1322, 1355, 1354, 1269,
       108481  + /*   260 */  1274, 1350, 1349, 1348, 1346, 1345, 1343, 1335, 1315, 1314,
       108482  + /*   270 */  1313, 1312, 1309, 1271, 1267, 1308, 1307, 1306, 1304, 1291,
       108483  + /*   280 */  1303, 1292, 1260, 1266, 1258, 1253, 1247, 1227, 1268, 1257,
       108484  + /*   290 */  1187, 1198, 1200, 1190, 1170, 1168, 1167, 1182, 1189, 1164,
       108485  + /*   300 */  1179, 1162, 1138, 1136, 1061, 1043, 1021, 1111, 1110, 1116,
108249 108486   };
108250 108487   static const YYACTIONTYPE yy_default[] = {
108251         - /*     0 */   635,  870,  959,  959,  959,  870,  899,  899,  959,  759,
108252         - /*    10 */   959,  959,  959,  959,  868,  959,  959,  933,  959,  959,
108253         - /*    20 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  959,
108254         - /*    30 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  959,
108255         - /*    40 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  959,
108256         - /*    50 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  959,
108257         - /*    60 */   959,  959,  959,  959,  899,  899,  674,  763,  794,  959,
108258         - /*    70 */   959,  959,  959,  959,  959,  959,  959,  932,  934,  809,
108259         - /*    80 */   808,  802,  801,  912,  774,  799,  792,  785,  796,  871,
108260         - /*    90 */   864,  865,  863,  867,  872,  959,  795,  831,  848,  830,
108261         - /*   100 */   842,  847,  854,  846,  843,  833,  832,  666,  834,  835,
108262         - /*   110 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  959,
108263         - /*   120 */   959,  959,  959,  959,  959,  959,  661,  728,  959,  959,
108264         - /*   130 */   959,  959,  959,  959,  836,  837,  851,  850,  849,  959,
108265         - /*   140 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  959,
108266         - /*   150 */   959,  939,  937,  959,  883,  959,  959,  959,  959,  959,
108267         - /*   160 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  959,
108268         - /*   170 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  959,
108269         - /*   180 */   959,  641,  959,  759,  759,  759,  635,  959,  959,  959,
108270         - /*   190 */   959,  951,  763,  753,  719,  959,  959,  959,  959,  959,
108271         - /*   200 */   959,  959,  959,  959,  959,  959,  959,  804,  742,  922,
108272         - /*   210 */   924,  959,  905,  740,  663,  761,  676,  751,  643,  798,
108273         - /*   220 */   776,  776,  917,  798,  917,  700,  959,  788,  959,  788,
108274         - /*   230 */   697,  788,  776,  788,  788,  866,  959,  959,  959,  760,
108275         - /*   240 */   751,  959,  944,  767,  767,  936,  936,  767,  810,  732,
108276         - /*   250 */   798,  739,  739,  739,  739,  767,  798,  810,  732,  732,
108277         - /*   260 */   767,  658,  911,  909,  767,  767,  658,  767,  658,  767,
108278         - /*   270 */   658,  876,  730,  730,  730,  715,  880,  880,  876,  730,
108279         - /*   280 */   700,  730,  715,  730,  730,  780,  775,  780,  775,  780,
108280         - /*   290 */   775,  767,  767,  959,  793,  781,  791,  789,  798,  959,
108281         - /*   300 */   718,  651,  651,  640,  640,  640,  640,  956,  956,  951,
108282         - /*   310 */   702,  702,  684,  959,  959,  959,  959,  959,  959,  959,
108283         - /*   320 */   885,  959,  959,  959,  959,  959,  959,  959,  959,  959,
108284         - /*   330 */   959,  959,  959,  959,  636,  946,  959,  959,  943,  959,
108285         - /*   340 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  959,
108286         - /*   350 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  915,
108287         - /*   360 */   959,  959,  959,  959,  959,  959,  908,  907,  959,  959,
108288         - /*   370 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  959,
108289         - /*   380 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  959,
108290         - /*   390 */   959,  959,  959,  959,  790,  959,  782,  959,  869,  959,
108291         - /*   400 */   959,  959,  959,  959,  959,  959,  959,  959,  959,  745,
108292         - /*   410 */   819,  959,  818,  822,  817,  668,  959,  649,  959,  632,
108293         - /*   420 */   637,  955,  958,  957,  954,  953,  952,  947,  945,  942,
108294         - /*   430 */   941,  940,  938,  935,  931,  889,  887,  894,  893,  892,
108295         - /*   440 */   891,  890,  888,  886,  884,  805,  803,  800,  797,  930,
108296         - /*   450 */   882,  741,  738,  737,  657,  948,  914,  923,  921,  811,
108297         - /*   460 */   920,  919,  918,  916,  913,  900,  807,  806,  733,  874,
108298         - /*   470 */   873,  660,  904,  903,  902,  906,  910,  901,  769,  659,
108299         - /*   480 */   656,  665,  722,  721,  729,  727,  726,  725,  724,  723,
108300         - /*   490 */   720,  667,  675,  686,  714,  699,  698,  879,  881,  878,
108301         - /*   500 */   877,  707,  706,  712,  711,  710,  709,  708,  705,  704,
108302         - /*   510 */   703,  696,  695,  701,  694,  717,  716,  713,  693,  736,
108303         - /*   520 */   735,  734,  731,  692,  691,  690,  822,  689,  688,  828,
108304         - /*   530 */   827,  815,  858,  756,  755,  754,  766,  765,  778,  777,
108305         - /*   540 */   813,  812,  779,  764,  758,  757,  773,  772,  771,  770,
108306         - /*   550 */   762,  752,  784,  787,  786,  783,  860,  768,  857,  929,
108307         - /*   560 */   928,  927,  926,  925,  862,  861,  829,  826,  679,  680,
108308         - /*   570 */   898,  896,  897,  895,  682,  681,  678,  677,  859,  747,
108309         - /*   580 */   746,  855,  852,  844,  840,  856,  853,  845,  841,  839,
108310         - /*   590 */   838,  824,  823,  821,  820,  816,  825,  670,  748,  744,
108311         - /*   600 */   743,  814,  750,  749,  687,  685,  683,  664,  662,  655,
108312         - /*   610 */   653,  652,  654,  650,  648,  647,  646,  645,  644,  673,
108313         - /*   620 */   672,  671,  669,  668,  642,  639,  638,  634,  633,  631,
       108488  + /*     0 */   634,  868,  956,  956,  868,  868,  956,  956,  956,  758,
       108489  + /*    10 */   956,  956,  956,  866,  956,  956,  786,  786,  930,  956,
       108490  + /*    20 */   956,  956,  956,  956,  956,  956,  956,  956,  956,  956,
       108491  + /*    30 */   956,  956,  956,  956,  956,  956,  956,  956,  956,  956,
       108492  + /*    40 */   956,  956,  956,  956,  956,  956,  956,  956,  956,  956,
       108493  + /*    50 */   956,  956,  956,  956,  956,  956,  956,  956,  956,  956,
       108494  + /*    60 */   956,  956,  956,  956,  956,  956,  956,  673,  762,  792,
       108495  + /*    70 */   956,  956,  956,  956,  956,  956,  956,  956,  929,  931,
       108496  + /*    80 */   800,  799,  909,  773,  797,  790,  794,  869,  862,  863,
       108497  + /*    90 */   861,  865,  870,  956,  793,  829,  846,  828,  840,  845,
       108498  + /*   100 */   852,  844,  841,  831,  830,  665,  832,  833,  956,  956,
       108499  + /*   110 */   956,  956,  956,  956,  956,  956,  956,  956,  956,  956,
       108500  + /*   120 */   956,  956,  956,  956,  660,  727,  956,  956,  956,  956,
       108501  + /*   130 */   956,  956,  956,  956,  834,  835,  849,  848,  847,  956,
       108502  + /*   140 */   956,  956,  956,  956,  956,  956,  956,  956,  956,  956,
       108503  + /*   150 */   956,  936,  934,  956,  881,  956,  956,  956,  956,  956,
       108504  + /*   160 */   956,  956,  956,  956,  956,  956,  956,  956,  956,  956,
       108505  + /*   170 */   956,  956,  956,  956,  956,  956,  956,  956,  956,  956,
       108506  + /*   180 */   956,  640,  758,  758,  758,  634,  956,  956,  956,  948,
       108507  + /*   190 */   762,  752,  718,  956,  956,  956,  956,  956,  956,  956,
       108508  + /*   200 */   956,  956,  956,  956,  956,  802,  741,  919,  921,  956,
       108509  + /*   210 */   902,  739,  662,  760,  675,  750,  642,  796,  775,  775,
       108510  + /*   220 */   914,  796,  914,  699,  956,  786,  956,  786,  696,  786,
       108511  + /*   230 */   775,  864,  956,  956,  956,  759,  750,  956,  941,  766,
       108512  + /*   240 */   766,  933,  933,  766,  808,  731,  796,  738,  738,  738,
       108513  + /*   250 */   738,  766,  657,  796,  808,  731,  731,  766,  657,  908,
       108514  + /*   260 */   906,  766,  766,  657,  766,  657,  766,  657,  874,  729,
       108515  + /*   270 */   729,  729,  714,  878,  878,  874,  729,  699,  729,  714,
       108516  + /*   280 */   729,  729,  779,  774,  779,  774,  779,  774,  766,  766,
       108517  + /*   290 */   956,  791,  780,  789,  787,  796,  956,  717,  650,  650,
       108518  + /*   300 */   639,  639,  639,  639,  953,  953,  948,  701,  701,  683,
       108519  + /*   310 */   956,  956,  956,  956,  956,  956,  956,  883,  956,  956,
       108520  + /*   320 */   956,  956,  956,  956,  956,  956,  956,  956,  956,  956,
       108521  + /*   330 */   635,  943,  956,  956,  940,  956,  956,  956,  956,  801,
       108522  + /*   340 */   956,  956,  956,  956,  956,  956,  956,  956,  956,  956,
       108523  + /*   350 */   918,  956,  956,  956,  956,  956,  956,  956,  912,  956,
       108524  + /*   360 */   956,  956,  956,  956,  956,  905,  904,  956,  956,  956,
       108525  + /*   370 */   956,  956,  956,  956,  956,  956,  956,  956,  956,  956,
       108526  + /*   380 */   956,  956,  956,  956,  956,  956,  956,  956,  956,  956,
       108527  + /*   390 */   956,  956,  956,  788,  956,  781,  956,  867,  956,  956,
       108528  + /*   400 */   956,  956,  956,  956,  956,  956,  956,  956,  744,  817,
       108529  + /*   410 */   956,  816,  820,  815,  667,  956,  648,  956,  631,  636,
       108530  + /*   420 */   952,  955,  954,  951,  950,  949,  944,  942,  939,  938,
       108531  + /*   430 */   937,  935,  932,  928,  887,  885,  892,  891,  890,  889,
       108532  + /*   440 */   888,  886,  884,  882,  803,  798,  795,  927,  880,  740,
       108533  + /*   450 */   737,  736,  656,  945,  911,  920,  807,  806,  809,  917,
       108534  + /*   460 */   916,  915,  913,  910,  897,  805,  804,  732,  872,  871,
       108535  + /*   470 */   659,  901,  900,  899,  903,  907,  898,  768,  658,  655,
       108536  + /*   480 */   664,  721,  720,  728,  726,  725,  724,  723,  722,  719,
       108537  + /*   490 */   666,  674,  685,  713,  698,  697,  877,  879,  876,  875,
       108538  + /*   500 */   706,  705,  711,  710,  709,  708,  707,  704,  703,  702,
       108539  + /*   510 */   695,  694,  700,  693,  716,  715,  712,  692,  735,  734,
       108540  + /*   520 */   733,  730,  691,  690,  689,  820,  688,  687,  826,  825,
       108541  + /*   530 */   813,  856,  755,  754,  753,  765,  764,  777,  776,  811,
       108542  + /*   540 */   810,  778,  763,  757,  756,  772,  771,  770,  769,  761,
       108543  + /*   550 */   751,  783,  785,  784,  782,  858,  767,  855,  926,  925,
       108544  + /*   560 */   924,  923,  922,  860,  859,  827,  824,  678,  679,  895,
       108545  + /*   570 */   894,  896,  893,  681,  680,  677,  676,  857,  746,  745,
       108546  + /*   580 */   853,  850,  842,  838,  854,  851,  843,  839,  837,  836,
       108547  + /*   590 */   822,  821,  819,  818,  814,  823,  669,  747,  743,  742,
       108548  + /*   600 */   812,  749,  748,  686,  684,  682,  663,  661,  654,  652,
       108549  + /*   610 */   651,  653,  649,  647,  646,  645,  644,  643,  672,  671,
       108550  + /*   620 */   670,  668,  667,  641,  638,  637,  633,  632,  630,
108314 108551   };
108315 108552   
108316 108553   /* The next table maps tokens into fallback tokens.  If a construct
108317 108554   ** like the following:
108318 108555   ** 
108319 108556   **      %fallback ID X Y Z.
108320 108557   **
................................................................................
108519 108756     "init_deferred_pred_opt",  "conslist",      "tcons",         "idxlist",     
108520 108757     "defer_subclause_opt",  "orconf",        "resolvetype",   "raisetype",   
108521 108758     "ifexists",      "fullname",      "oneselect",     "multiselect_op",
108522 108759     "distinct",      "selcollist",    "from",          "where_opt",   
108523 108760     "groupby_opt",   "having_opt",    "orderby_opt",   "limit_opt",   
108524 108761     "sclp",          "as",            "seltablist",    "stl_prefix",  
108525 108762     "joinop",        "indexed_opt",   "on_opt",        "using_opt",   
108526         -  "joinop2",       "inscollist",    "sortlist",      "sortitem",    
108527         -  "nexprlist",     "setlist",       "insert_cmd",    "inscollist_opt",
108528         -  "itemlist",      "exprlist",      "likeop",        "between_op",  
108529         -  "in_op",         "case_operand",  "case_exprlist",  "case_else",   
108530         -  "uniqueflag",    "collate",       "nmnum",         "plus_opt",    
108531         -  "number",        "trigger_decl",  "trigger_cmd_list",  "trigger_time",
108532         -  "trigger_event",  "foreach_clause",  "when_clause",   "trigger_cmd", 
108533         -  "trnm",          "tridxby",       "database_kw_opt",  "key_opt",     
108534         -  "add_column_fullname",  "kwcolumn_opt",  "create_vtab",   "vtabarglist", 
108535         -  "vtabarg",       "vtabargtoken",  "lp",            "anylist",     
       108763  +  "joinop2",       "inscollist",    "sortlist",      "nexprlist",   
       108764  +  "setlist",       "insert_cmd",    "inscollist_opt",  "valuelist",   
       108765  +  "exprlist",      "likeop",        "between_op",    "in_op",       
       108766  +  "case_operand",  "case_exprlist",  "case_else",     "uniqueflag",  
       108767  +  "collate",       "nmnum",         "number",        "trigger_decl",
       108768  +  "trigger_cmd_list",  "trigger_time",  "trigger_event",  "foreach_clause",
       108769  +  "when_clause",   "trigger_cmd",   "trnm",          "tridxby",     
       108770  +  "database_kw_opt",  "key_opt",       "add_column_fullname",  "kwcolumn_opt",
       108771  +  "create_vtab",   "vtabarglist",   "vtabarg",       "vtabargtoken",
       108772  +  "lp",            "anylist",     
108536 108773   };
108537 108774   #endif /* NDEBUG */
108538 108775   
108539 108776   #ifndef NDEBUG
108540 108777   /* For tracing reduce actions, the names of all rules are required.
108541 108778   */
108542 108779   static const char *const yyRuleName[] = {
................................................................................
108689 108926    /* 146 */ "indexed_opt ::=",
108690 108927    /* 147 */ "indexed_opt ::= INDEXED BY nm",
108691 108928    /* 148 */ "indexed_opt ::= NOT INDEXED",
108692 108929    /* 149 */ "using_opt ::= USING LP inscollist RP",
108693 108930    /* 150 */ "using_opt ::=",
108694 108931    /* 151 */ "orderby_opt ::=",
108695 108932    /* 152 */ "orderby_opt ::= ORDER BY sortlist",
108696         - /* 153 */ "sortlist ::= sortlist COMMA sortitem sortorder",
108697         - /* 154 */ "sortlist ::= sortitem sortorder",
108698         - /* 155 */ "sortitem ::= expr",
108699         - /* 156 */ "sortorder ::= ASC",
108700         - /* 157 */ "sortorder ::= DESC",
108701         - /* 158 */ "sortorder ::=",
108702         - /* 159 */ "groupby_opt ::=",
108703         - /* 160 */ "groupby_opt ::= GROUP BY nexprlist",
108704         - /* 161 */ "having_opt ::=",
108705         - /* 162 */ "having_opt ::= HAVING expr",
108706         - /* 163 */ "limit_opt ::=",
108707         - /* 164 */ "limit_opt ::= LIMIT expr",
108708         - /* 165 */ "limit_opt ::= LIMIT expr OFFSET expr",
108709         - /* 166 */ "limit_opt ::= LIMIT expr COMMA expr",
108710         - /* 167 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt",
108711         - /* 168 */ "where_opt ::=",
108712         - /* 169 */ "where_opt ::= WHERE expr",
108713         - /* 170 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt",
108714         - /* 171 */ "setlist ::= setlist COMMA nm EQ expr",
108715         - /* 172 */ "setlist ::= nm EQ expr",
108716         - /* 173 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP",
108717         - /* 174 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select",
108718         - /* 175 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
108719         - /* 176 */ "insert_cmd ::= INSERT orconf",
108720         - /* 177 */ "insert_cmd ::= REPLACE",
108721         - /* 178 */ "itemlist ::= itemlist COMMA expr",
108722         - /* 179 */ "itemlist ::= expr",
108723         - /* 180 */ "inscollist_opt ::=",
108724         - /* 181 */ "inscollist_opt ::= LP inscollist RP",
108725         - /* 182 */ "inscollist ::= inscollist COMMA nm",
108726         - /* 183 */ "inscollist ::= nm",
108727         - /* 184 */ "expr ::= term",
108728         - /* 185 */ "expr ::= LP expr RP",
108729         - /* 186 */ "term ::= NULL",
108730         - /* 187 */ "expr ::= id",
108731         - /* 188 */ "expr ::= JOIN_KW",
108732         - /* 189 */ "expr ::= nm DOT nm",
108733         - /* 190 */ "expr ::= nm DOT nm DOT nm",
108734         - /* 191 */ "term ::= INTEGER|FLOAT|BLOB",
108735         - /* 192 */ "term ::= STRING",
108736         - /* 193 */ "expr ::= REGISTER",
108737         - /* 194 */ "expr ::= VARIABLE",
108738         - /* 195 */ "expr ::= expr COLLATE ids",
108739         - /* 196 */ "expr ::= CAST LP expr AS typetoken RP",
108740         - /* 197 */ "expr ::= ID LP distinct exprlist RP",
108741         - /* 198 */ "expr ::= ID LP STAR RP",
108742         - /* 199 */ "term ::= CTIME_KW",
108743         - /* 200 */ "expr ::= expr AND expr",
108744         - /* 201 */ "expr ::= expr OR expr",
108745         - /* 202 */ "expr ::= expr LT|GT|GE|LE expr",
108746         - /* 203 */ "expr ::= expr EQ|NE expr",
108747         - /* 204 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
108748         - /* 205 */ "expr ::= expr PLUS|MINUS expr",
108749         - /* 206 */ "expr ::= expr STAR|SLASH|REM expr",
108750         - /* 207 */ "expr ::= expr CONCAT expr",
108751         - /* 208 */ "likeop ::= LIKE_KW",
108752         - /* 209 */ "likeop ::= NOT LIKE_KW",
108753         - /* 210 */ "likeop ::= MATCH",
108754         - /* 211 */ "likeop ::= NOT MATCH",
108755         - /* 212 */ "expr ::= expr likeop expr",
108756         - /* 213 */ "expr ::= expr likeop expr ESCAPE expr",
108757         - /* 214 */ "expr ::= expr ISNULL|NOTNULL",
108758         - /* 215 */ "expr ::= expr NOT NULL",
108759         - /* 216 */ "expr ::= expr IS expr",
108760         - /* 217 */ "expr ::= expr IS NOT expr",
108761         - /* 218 */ "expr ::= NOT expr",
108762         - /* 219 */ "expr ::= BITNOT expr",
108763         - /* 220 */ "expr ::= MINUS expr",
108764         - /* 221 */ "expr ::= PLUS expr",
108765         - /* 222 */ "between_op ::= BETWEEN",
108766         - /* 223 */ "between_op ::= NOT BETWEEN",
108767         - /* 224 */ "expr ::= expr between_op expr AND expr",
108768         - /* 225 */ "in_op ::= IN",
108769         - /* 226 */ "in_op ::= NOT IN",
108770         - /* 227 */ "expr ::= expr in_op LP exprlist RP",
108771         - /* 228 */ "expr ::= LP select RP",
108772         - /* 229 */ "expr ::= expr in_op LP select RP",
108773         - /* 230 */ "expr ::= expr in_op nm dbnm",
108774         - /* 231 */ "expr ::= EXISTS LP select RP",
108775         - /* 232 */ "expr ::= CASE case_operand case_exprlist case_else END",
108776         - /* 233 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
108777         - /* 234 */ "case_exprlist ::= WHEN expr THEN expr",
108778         - /* 235 */ "case_else ::= ELSE expr",
108779         - /* 236 */ "case_else ::=",
108780         - /* 237 */ "case_operand ::= expr",
108781         - /* 238 */ "case_operand ::=",
108782         - /* 239 */ "exprlist ::= nexprlist",
108783         - /* 240 */ "exprlist ::=",
108784         - /* 241 */ "nexprlist ::= nexprlist COMMA expr",
108785         - /* 242 */ "nexprlist ::= expr",
108786         - /* 243 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP",
108787         - /* 244 */ "uniqueflag ::= UNIQUE",
108788         - /* 245 */ "uniqueflag ::=",
108789         - /* 246 */ "idxlist_opt ::=",
108790         - /* 247 */ "idxlist_opt ::= LP idxlist RP",
108791         - /* 248 */ "idxlist ::= idxlist COMMA nm collate sortorder",
108792         - /* 249 */ "idxlist ::= nm collate sortorder",
108793         - /* 250 */ "collate ::=",
108794         - /* 251 */ "collate ::= COLLATE ids",
108795         - /* 252 */ "cmd ::= DROP INDEX ifexists fullname",
108796         - /* 253 */ "cmd ::= VACUUM",
108797         - /* 254 */ "cmd ::= VACUUM nm",
108798         - /* 255 */ "cmd ::= PRAGMA nm dbnm",
108799         - /* 256 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
108800         - /* 257 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
108801         - /* 258 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
108802         - /* 259 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
108803         - /* 260 */ "nmnum ::= plus_num",
108804         - /* 261 */ "nmnum ::= nm",
108805         - /* 262 */ "nmnum ::= ON",
108806         - /* 263 */ "nmnum ::= DELETE",
108807         - /* 264 */ "nmnum ::= DEFAULT",
108808         - /* 265 */ "plus_num ::= plus_opt number",
       108933  + /* 153 */ "sortlist ::= sortlist COMMA expr sortorder",
       108934  + /* 154 */ "sortlist ::= expr sortorder",
       108935  + /* 155 */ "sortorder ::= ASC",
       108936  + /* 156 */ "sortorder ::= DESC",
       108937  + /* 157 */ "sortorder ::=",
       108938  + /* 158 */ "groupby_opt ::=",
       108939  + /* 159 */ "groupby_opt ::= GROUP BY nexprlist",
       108940  + /* 160 */ "having_opt ::=",
       108941  + /* 161 */ "having_opt ::= HAVING expr",
       108942  + /* 162 */ "limit_opt ::=",
       108943  + /* 163 */ "limit_opt ::= LIMIT expr",
       108944  + /* 164 */ "limit_opt ::= LIMIT expr OFFSET expr",
       108945  + /* 165 */ "limit_opt ::= LIMIT expr COMMA expr",
       108946  + /* 166 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt",
       108947  + /* 167 */ "where_opt ::=",
       108948  + /* 168 */ "where_opt ::= WHERE expr",
       108949  + /* 169 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt",
       108950  + /* 170 */ "setlist ::= setlist COMMA nm EQ expr",
       108951  + /* 171 */ "setlist ::= nm EQ expr",
       108952  + /* 172 */ "cmd ::= insert_cmd INTO fullname inscollist_opt valuelist",
       108953  + /* 173 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select",
       108954  + /* 174 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
       108955  + /* 175 */ "insert_cmd ::= INSERT orconf",
       108956  + /* 176 */ "insert_cmd ::= REPLACE",
       108957  + /* 177 */ "valuelist ::= VALUES LP nexprlist RP",
       108958  + /* 178 */ "valuelist ::= valuelist COMMA LP exprlist RP",
       108959  + /* 179 */ "inscollist_opt ::=",
       108960  + /* 180 */ "inscollist_opt ::= LP inscollist RP",
       108961  + /* 181 */ "inscollist ::= inscollist COMMA nm",
       108962  + /* 182 */ "inscollist ::= nm",
       108963  + /* 183 */ "expr ::= term",
       108964  + /* 184 */ "expr ::= LP expr RP",
       108965  + /* 185 */ "term ::= NULL",
       108966  + /* 186 */ "expr ::= id",
       108967  + /* 187 */ "expr ::= JOIN_KW",
       108968  + /* 188 */ "expr ::= nm DOT nm",
       108969  + /* 189 */ "expr ::= nm DOT nm DOT nm",
       108970  + /* 190 */ "term ::= INTEGER|FLOAT|BLOB",
       108971  + /* 191 */ "term ::= STRING",
       108972  + /* 192 */ "expr ::= REGISTER",
       108973  + /* 193 */ "expr ::= VARIABLE",
       108974  + /* 194 */ "expr ::= expr COLLATE ids",
       108975  + /* 195 */ "expr ::= CAST LP expr AS typetoken RP",
       108976  + /* 196 */ "expr ::= ID LP distinct exprlist RP",
       108977  + /* 197 */ "expr ::= ID LP STAR RP",
       108978  + /* 198 */ "term ::= CTIME_KW",
       108979  + /* 199 */ "expr ::= expr AND expr",
       108980  + /* 200 */ "expr ::= expr OR expr",
       108981  + /* 201 */ "expr ::= expr LT|GT|GE|LE expr",
       108982  + /* 202 */ "expr ::= expr EQ|NE expr",
       108983  + /* 203 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
       108984  + /* 204 */ "expr ::= expr PLUS|MINUS expr",
       108985  + /* 205 */ "expr ::= expr STAR|SLASH|REM expr",
       108986  + /* 206 */ "expr ::= expr CONCAT expr",
       108987  + /* 207 */ "likeop ::= LIKE_KW",
       108988  + /* 208 */ "likeop ::= NOT LIKE_KW",
       108989  + /* 209 */ "likeop ::= MATCH",
       108990  + /* 210 */ "likeop ::= NOT MATCH",
       108991  + /* 211 */ "expr ::= expr likeop expr",
       108992  + /* 212 */ "expr ::= expr likeop expr ESCAPE expr",
       108993  + /* 213 */ "expr ::= expr ISNULL|NOTNULL",
       108994  + /* 214 */ "expr ::= expr NOT NULL",
       108995  + /* 215 */ "expr ::= expr IS expr",
       108996  + /* 216 */ "expr ::= expr IS NOT expr",
       108997  + /* 217 */ "expr ::= NOT expr",
       108998  + /* 218 */ "expr ::= BITNOT expr",
       108999  + /* 219 */ "expr ::= MINUS expr",
       109000  + /* 220 */ "expr ::= PLUS expr",
       109001  + /* 221 */ "between_op ::= BETWEEN",
       109002  + /* 222 */ "between_op ::= NOT BETWEEN",
       109003  + /* 223 */ "expr ::= expr between_op expr AND expr",
       109004  + /* 224 */ "in_op ::= IN",
       109005  + /* 225 */ "in_op ::= NOT IN",
       109006  + /* 226 */ "expr ::= expr in_op LP exprlist RP",
       109007  + /* 227 */ "expr ::= LP select RP",
       109008  + /* 228 */ "expr ::= expr in_op LP select RP",
       109009  + /* 229 */ "expr ::= expr in_op nm dbnm",
       109010  + /* 230 */ "expr ::= EXISTS LP select RP",
       109011  + /* 231 */ "expr ::= CASE case_operand case_exprlist case_else END",
       109012  + /* 232 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
       109013  + /* 233 */ "case_exprlist ::= WHEN expr THEN expr",
       109014  + /* 234 */ "case_else ::= ELSE expr",
       109015  + /* 235 */ "case_else ::=",
       109016  + /* 236 */ "case_operand ::= expr",
       109017  + /* 237 */ "case_operand ::=",
       109018  + /* 238 */ "exprlist ::= nexprlist",
       109019  + /* 239 */ "exprlist ::=",
       109020  + /* 240 */ "nexprlist ::= nexprlist COMMA expr",
       109021  + /* 241 */ "nexprlist ::= expr",
       109022  + /* 242 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP",
       109023  + /* 243 */ "uniqueflag ::= UNIQUE",
       109024  + /* 244 */ "uniqueflag ::=",
       109025  + /* 245 */ "idxlist_opt ::=",
       109026  + /* 246 */ "idxlist_opt ::= LP idxlist RP",
       109027  + /* 247 */ "idxlist ::= idxlist COMMA nm collate sortorder",
       109028  + /* 248 */ "idxlist ::= nm collate sortorder",
       109029  + /* 249 */ "collate ::=",
       109030  + /* 250 */ "collate ::= COLLATE ids",
       109031  + /* 251 */ "cmd ::= DROP INDEX ifexists fullname",
       109032  + /* 252 */ "cmd ::= VACUUM",
       109033  + /* 253 */ "cmd ::= VACUUM nm",
       109034  + /* 254 */ "cmd ::= PRAGMA nm dbnm",
       109035  + /* 255 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
       109036  + /* 256 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
       109037  + /* 257 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
       109038  + /* 258 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
       109039  + /* 259 */ "nmnum ::= plus_num",
       109040  + /* 260 */ "nmnum ::= nm",
       109041  + /* 261 */ "nmnum ::= ON",
       109042  + /* 262 */ "nmnum ::= DELETE",
       109043  + /* 263 */ "nmnum ::= DEFAULT",
       109044  + /* 264 */ "plus_num ::= PLUS number",
       109045  + /* 265 */ "plus_num ::= number",
108809 109046    /* 266 */ "minus_num ::= MINUS number",
108810 109047    /* 267 */ "number ::= INTEGER|FLOAT",
108811         - /* 268 */ "plus_opt ::= PLUS",
108812         - /* 269 */ "plus_opt ::=",
108813         - /* 270 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
108814         - /* 271 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
108815         - /* 272 */ "trigger_time ::= BEFORE",
108816         - /* 273 */ "trigger_time ::= AFTER",
108817         - /* 274 */ "trigger_time ::= INSTEAD OF",
108818         - /* 275 */ "trigger_time ::=",
108819         - /* 276 */ "trigger_event ::= DELETE|INSERT",
108820         - /* 277 */ "trigger_event ::= UPDATE",
108821         - /* 278 */ "trigger_event ::= UPDATE OF inscollist",
108822         - /* 279 */ "foreach_clause ::=",
108823         - /* 280 */ "foreach_clause ::= FOR EACH ROW",
108824         - /* 281 */ "when_clause ::=",
108825         - /* 282 */ "when_clause ::= WHEN expr",
108826         - /* 283 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
108827         - /* 284 */ "trigger_cmd_list ::= trigger_cmd SEMI",
108828         - /* 285 */ "trnm ::= nm",
108829         - /* 286 */ "trnm ::= nm DOT nm",
108830         - /* 287 */ "tridxby ::=",
108831         - /* 288 */ "tridxby ::= INDEXED BY nm",
108832         - /* 289 */ "tridxby ::= NOT INDEXED",
108833         - /* 290 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
108834         - /* 291 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt VALUES LP itemlist RP",
108835         - /* 292 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select",
108836         - /* 293 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
108837         - /* 294 */ "trigger_cmd ::= select",
108838         - /* 295 */ "expr ::= RAISE LP IGNORE RP",
108839         - /* 296 */ "expr ::= RAISE LP raisetype COMMA nm RP",
108840         - /* 297 */ "raisetype ::= ROLLBACK",
108841         - /* 298 */ "raisetype ::= ABORT",
108842         - /* 299 */ "raisetype ::= FAIL",
108843         - /* 300 */ "cmd ::= DROP TRIGGER ifexists fullname",
108844         - /* 301 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
108845         - /* 302 */ "cmd ::= DETACH database_kw_opt expr",
108846         - /* 303 */ "key_opt ::=",
108847         - /* 304 */ "key_opt ::= KEY expr",
108848         - /* 305 */ "database_kw_opt ::= DATABASE",
108849         - /* 306 */ "database_kw_opt ::=",
108850         - /* 307 */ "cmd ::= REINDEX",
108851         - /* 308 */ "cmd ::= REINDEX nm dbnm",
108852         - /* 309 */ "cmd ::= ANALYZE",
108853         - /* 310 */ "cmd ::= ANALYZE nm dbnm",
108854         - /* 311 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
108855         - /* 312 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
108856         - /* 313 */ "add_column_fullname ::= fullname",
108857         - /* 314 */ "kwcolumn_opt ::=",
108858         - /* 315 */ "kwcolumn_opt ::= COLUMNKW",
108859         - /* 316 */ "cmd ::= create_vtab",
108860         - /* 317 */ "cmd ::= create_vtab LP vtabarglist RP",
108861         - /* 318 */ "create_vtab ::= createkw VIRTUAL TABLE nm dbnm USING nm",
108862         - /* 319 */ "vtabarglist ::= vtabarg",
108863         - /* 320 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
108864         - /* 321 */ "vtabarg ::=",
108865         - /* 322 */ "vtabarg ::= vtabarg vtabargtoken",
108866         - /* 323 */ "vtabargtoken ::= ANY",
108867         - /* 324 */ "vtabargtoken ::= lp anylist RP",
108868         - /* 325 */ "lp ::= LP",
108869         - /* 326 */ "anylist ::=",
108870         - /* 327 */ "anylist ::= anylist LP anylist RP",
108871         - /* 328 */ "anylist ::= anylist ANY",
       109048  + /* 268 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
       109049  + /* 269 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
       109050  + /* 270 */ "trigger_time ::= BEFORE",
       109051  + /* 271 */ "trigger_time ::= AFTER",
       109052  + /* 272 */ "trigger_time ::= INSTEAD OF",
       109053  + /* 273 */ "trigger_time ::=",
       109054  + /* 274 */ "trigger_event ::= DELETE|INSERT",
       109055  + /* 275 */ "trigger_event ::= UPDATE",
       109056  + /* 276 */ "trigger_event ::= UPDATE OF inscollist",
       109057  + /* 277 */ "foreach_clause ::=",
       109058  + /* 278 */ "foreach_clause ::= FOR EACH ROW",
       109059  + /* 279 */ "when_clause ::=",
       109060  + /* 280 */ "when_clause ::= WHEN expr",
       109061  + /* 281 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
       109062  + /* 282 */ "trigger_cmd_list ::= trigger_cmd SEMI",
       109063  + /* 283 */ "trnm ::= nm",
       109064  + /* 284 */ "trnm ::= nm DOT nm",
       109065  + /* 285 */ "tridxby ::=",
       109066  + /* 286 */ "tridxby ::= INDEXED BY nm",
       109067  + /* 287 */ "tridxby ::= NOT INDEXED",
       109068  + /* 288 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
       109069  + /* 289 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist",
       109070  + /* 290 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select",
       109071  + /* 291 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
       109072  + /* 292 */ "trigger_cmd ::= select",
       109073  + /* 293 */ "expr ::= RAISE LP IGNORE RP",
       109074  + /* 294 */ "expr ::= RAISE LP raisetype COMMA nm RP",
       109075  + /* 295 */ "raisetype ::= ROLLBACK",
       109076  + /* 296 */ "raisetype ::= ABORT",
       109077  + /* 297 */ "raisetype ::= FAIL",
       109078  + /* 298 */ "cmd ::= DROP TRIGGER ifexists fullname",
       109079  + /* 299 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
       109080  + /* 300 */ "cmd ::= DETACH database_kw_opt expr",
       109081  + /* 301 */ "key_opt ::=",
       109082  + /* 302 */ "key_opt ::= KEY expr",
       109083  + /* 303 */ "database_kw_opt ::= DATABASE",
       109084  + /* 304 */ "database_kw_opt ::=",
       109085  + /* 305 */ "cmd ::= REINDEX",
       109086  + /* 306 */ "cmd ::= REINDEX nm dbnm",
       109087  + /* 307 */ "cmd ::= ANALYZE",
       109088  + /* 308 */ "cmd ::= ANALYZE nm dbnm",
       109089  + /* 309 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
       109090  + /* 310 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
       109091  + /* 311 */ "add_column_fullname ::= fullname",
       109092  + /* 312 */ "kwcolumn_opt ::=",
       109093  + /* 313 */ "kwcolumn_opt ::= COLUMNKW",
       109094  + /* 314 */ "cmd ::= create_vtab",
       109095  + /* 315 */ "cmd ::= create_vtab LP vtabarglist RP",
       109096  + /* 316 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
       109097  + /* 317 */ "vtabarglist ::= vtabarg",
       109098  + /* 318 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
       109099  + /* 319 */ "vtabarg ::=",
       109100  + /* 320 */ "vtabarg ::= vtabarg vtabargtoken",
       109101  + /* 321 */ "vtabargtoken ::= ANY",
       109102  + /* 322 */ "vtabargtoken ::= lp anylist RP",
       109103  + /* 323 */ "lp ::= LP",
       109104  + /* 324 */ "anylist ::=",
       109105  + /* 325 */ "anylist ::= anylist LP anylist RP",
       109106  + /* 326 */ "anylist ::= anylist ANY",
108872 109107   };
108873 109108   #endif /* NDEBUG */
108874 109109   
108875 109110   
108876 109111   #if YYSTACKDEPTH<=0
108877 109112   /*
108878 109113   ** Try to increase the size of the parser stack.
................................................................................
108946 109181       ** Note: during a reduce, the only symbols destroyed are those
108947 109182       ** which appear on the RHS of the rule, but which are not used
108948 109183       ** inside the C code.
108949 109184       */
108950 109185       case 160: /* select */
108951 109186       case 194: /* oneselect */
108952 109187   {
108953         -sqlite3SelectDelete(pParse->db, (yypminor->yy387));
       109188  +sqlite3SelectDelete(pParse->db, (yypminor->yy159));
108954 109189   }
108955 109190         break;
108956 109191       case 174: /* term */
108957 109192       case 175: /* expr */
108958 109193   {
108959         -sqlite3ExprDelete(pParse->db, (yypminor->yy118).pExpr);
       109194  +sqlite3ExprDelete(pParse->db, (yypminor->yy342).pExpr);
108960 109195   }
108961 109196         break;
108962 109197       case 179: /* idxlist_opt */
108963 109198       case 187: /* idxlist */
108964 109199       case 197: /* selcollist */
108965 109200       case 200: /* groupby_opt */
108966 109201       case 202: /* orderby_opt */
108967 109202       case 204: /* sclp */
108968 109203       case 214: /* sortlist */
108969         -    case 216: /* nexprlist */
108970         -    case 217: /* setlist */
108971         -    case 220: /* itemlist */
108972         -    case 221: /* exprlist */
108973         -    case 226: /* case_exprlist */
       109204  +    case 215: /* nexprlist */
       109205  +    case 216: /* setlist */
       109206  +    case 220: /* exprlist */
       109207  +    case 225: /* case_exprlist */
108974 109208   {
108975         -sqlite3ExprListDelete(pParse->db, (yypminor->yy322));
       109209  +sqlite3ExprListDelete(pParse->db, (yypminor->yy442));
108976 109210   }
108977 109211         break;
108978 109212       case 193: /* fullname */
108979 109213       case 198: /* from */
108980 109214       case 206: /* seltablist */
108981 109215       case 207: /* stl_prefix */
108982 109216   {
108983         -sqlite3SrcListDelete(pParse->db, (yypminor->yy259));
       109217  +sqlite3SrcListDelete(pParse->db, (yypminor->yy347));
108984 109218   }
108985 109219         break;
108986 109220       case 199: /* where_opt */
108987 109221       case 201: /* having_opt */
108988 109222       case 210: /* on_opt */
108989         -    case 215: /* sortitem */
108990         -    case 225: /* case_operand */
108991         -    case 227: /* case_else */
108992         -    case 238: /* when_clause */
108993         -    case 243: /* key_opt */
       109223  +    case 224: /* case_operand */
       109224  +    case 226: /* case_else */
       109225  +    case 236: /* when_clause */
       109226  +    case 241: /* key_opt */
108994 109227   {
108995         -sqlite3ExprDelete(pParse->db, (yypminor->yy314));
       109228  +sqlite3ExprDelete(pParse->db, (yypminor->yy122));
108996 109229   }
108997 109230         break;
108998 109231       case 211: /* using_opt */
108999 109232       case 213: /* inscollist */
109000         -    case 219: /* inscollist_opt */
       109233  +    case 218: /* inscollist_opt */
109001 109234   {
109002         -sqlite3IdListDelete(pParse->db, (yypminor->yy384));
       109235  +sqlite3IdListDelete(pParse->db, (yypminor->yy180));
109003 109236   }
109004 109237         break;
109005         -    case 234: /* trigger_cmd_list */
109006         -    case 239: /* trigger_cmd */
       109238  +    case 219: /* valuelist */
109007 109239   {
109008         -sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy203));
       109240  +
       109241  +  sqlite3ExprListDelete(pParse->db, (yypminor->yy487).pList);
       109242  +  sqlite3SelectDelete(pParse->db, (yypminor->yy487).pSelect);
       109243  +
109009 109244   }
109010 109245         break;
109011         -    case 236: /* trigger_event */
       109246  +    case 232: /* trigger_cmd_list */
       109247  +    case 237: /* trigger_cmd */
109012 109248   {
109013         -sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
       109249  +sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy327));
       109250  +}
       109251  +      break;
       109252  +    case 234: /* trigger_event */
       109253  +{
       109254  +sqlite3IdListDelete(pParse->db, (yypminor->yy410).b);
109014 109255   }
109015 109256         break;
109016 109257       default:  break;   /* If no destructor action specified: do nothing */
109017 109258     }
109018 109259   }
109019 109260   
109020 109261   /*
................................................................................
109406 109647     { 209, 2 },
109407 109648     { 211, 4 },
109408 109649     { 211, 0 },
109409 109650     { 202, 0 },
109410 109651     { 202, 3 },
109411 109652     { 214, 4 },
109412 109653     { 214, 2 },
109413         -  { 215, 1 },
109414 109654     { 177, 1 },
109415 109655     { 177, 1 },
109416 109656     { 177, 0 },
109417 109657     { 200, 0 },
109418 109658     { 200, 3 },
109419 109659     { 201, 0 },
109420 109660     { 201, 2 },
................................................................................
109422 109662     { 203, 2 },
109423 109663     { 203, 4 },
109424 109664     { 203, 4 },
109425 109665     { 147, 5 },
109426 109666     { 199, 0 },
109427 109667     { 199, 2 },
109428 109668     { 147, 7 },
109429         -  { 217, 5 },
109430         -  { 217, 3 },
109431         -  { 147, 8 },
       109669  +  { 216, 5 },
       109670  +  { 216, 3 },
       109671  +  { 147, 5 },
109432 109672     { 147, 5 },
109433 109673     { 147, 6 },
109434         -  { 218, 2 },
109435         -  { 218, 1 },
109436         -  { 220, 3 },
109437         -  { 220, 1 },
109438         -  { 219, 0 },
109439         -  { 219, 3 },
       109674  +  { 217, 2 },
       109675  +  { 217, 1 },
       109676  +  { 219, 4 },
       109677  +  { 219, 5 },
       109678  +  { 218, 0 },
       109679  +  { 218, 3 },
109440 109680     { 213, 3 },
109441 109681     { 213, 1 },
109442 109682     { 175, 1 },
109443 109683     { 175, 3 },
109444 109684     { 174, 1 },
109445 109685     { 175, 1 },
109446 109686     { 175, 1 },
................................................................................
109459 109699     { 175, 3 },
109460 109700     { 175, 3 },
109461 109701     { 175, 3 },
109462 109702     { 175, 3 },
109463 109703     { 175, 3 },
109464 109704     { 175, 3 },
109465 109705     { 175, 3 },
109466         -  { 222, 1 },
109467         -  { 222, 2 },
109468         -  { 222, 1 },
109469         -  { 222, 2 },
       109706  +  { 221, 1 },
       109707  +  { 221, 2 },
       109708  +  { 221, 1 },
       109709  +  { 221, 2 },
109470 109710     { 175, 3 },
109471 109711     { 175, 5 },
109472 109712     { 175, 2 },
109473 109713     { 175, 3 },
109474 109714     { 175, 3 },
109475 109715     { 175, 4 },
109476 109716     { 175, 2 },
109477 109717     { 175, 2 },
109478 109718     { 175, 2 },
109479 109719     { 175, 2 },
       109720  +  { 222, 1 },
       109721  +  { 222, 2 },
       109722  +  { 175, 5 },
109480 109723     { 223, 1 },
109481 109724     { 223, 2 },
109482         -  { 175, 5 },
109483         -  { 224, 1 },
109484         -  { 224, 2 },
109485 109725     { 175, 5 },
109486 109726     { 175, 3 },
109487 109727     { 175, 5 },
109488 109728     { 175, 4 },
109489 109729     { 175, 4 },
109490 109730     { 175, 5 },
109491         -  { 226, 5 },
109492         -  { 226, 4 },
109493         -  { 227, 2 },
109494         -  { 227, 0 },
109495         -  { 225, 1 },
109496         -  { 225, 0 },
109497         -  { 221, 1 },
109498         -  { 221, 0 },
109499         -  { 216, 3 },
109500         -  { 216, 1 },
       109731  +  { 225, 5 },
       109732  +  { 225, 4 },
       109733  +  { 226, 2 },
       109734  +  { 226, 0 },
       109735  +  { 224, 1 },
       109736  +  { 224, 0 },
       109737  +  { 220, 1 },
       109738  +  { 220, 0 },
       109739  +  { 215, 3 },
       109740  +  { 215, 1 },
109501 109741     { 147, 11 },
109502         -  { 228, 1 },
109503         -  { 228, 0 },
       109742  +  { 227, 1 },
       109743  +  { 227, 0 },
109504 109744     { 179, 0 },
109505 109745     { 179, 3 },
109506 109746     { 187, 5 },
109507 109747     { 187, 3 },
109508         -  { 229, 0 },
109509         -  { 229, 2 },
       109748  +  { 228, 0 },
       109749  +  { 228, 2 },
109510 109750     { 147, 4 },
109511 109751     { 147, 1 },
109512 109752     { 147, 2 },
109513 109753     { 147, 3 },
109514 109754     { 147, 5 },
109515 109755     { 147, 6 },
109516 109756     { 147, 5 },
109517 109757     { 147, 6 },
109518         -  { 230, 1 },
109519         -  { 230, 1 },
109520         -  { 230, 1 },
109521         -  { 230, 1 },
109522         -  { 230, 1 },
       109758  +  { 229, 1 },
       109759  +  { 229, 1 },
       109760  +  { 229, 1 },
       109761  +  { 229, 1 },
       109762  +  { 229, 1 },
109523 109763     { 170, 2 },
       109764  +  { 170, 1 },
109524 109765     { 171, 2 },
109525         -  { 232, 1 },
109526         -  { 231, 1 },
109527         -  { 231, 0 },
       109766  +  { 230, 1 },
109528 109767     { 147, 5 },
109529         -  { 233, 11 },
109530         -  { 235, 1 },
109531         -  { 235, 1 },
109532         -  { 235, 2 },
       109768  +  { 231, 11 },
       109769  +  { 233, 1 },
       109770  +  { 233, 1 },
       109771  +  { 233, 2 },
       109772  +  { 233, 0 },
       109773  +  { 234, 1 },
       109774  +  { 234, 1 },
       109775  +  { 234, 3 },
109533 109776     { 235, 0 },
109534         -  { 236, 1 },
109535         -  { 236, 1 },
109536         -  { 236, 3 },
109537         -  { 237, 0 },
109538         -  { 237, 3 },
109539         -  { 238, 0 },
109540         -  { 238, 2 },
109541         -  { 234, 3 },
109542         -  { 234, 2 },
109543         -  { 240, 1 },
109544         -  { 240, 3 },
109545         -  { 241, 0 },
109546         -  { 241, 3 },
109547         -  { 241, 2 },
109548         -  { 239, 7 },
109549         -  { 239, 8 },
109550         -  { 239, 5 },
109551         -  { 239, 5 },
109552         -  { 239, 1 },
       109777  +  { 235, 3 },
       109778  +  { 236, 0 },
       109779  +  { 236, 2 },
       109780  +  { 232, 3 },
       109781  +  { 232, 2 },
       109782  +  { 238, 1 },
       109783  +  { 238, 3 },
       109784  +  { 239, 0 },
       109785  +  { 239, 3 },
       109786  +  { 239, 2 },
       109787  +  { 237, 7 },
       109788  +  { 237, 5 },
       109789  +  { 237, 5 },
       109790  +  { 237, 5 },
       109791  +  { 237, 1 },
109553 109792     { 175, 4 },
109554 109793     { 175, 6 },
109555 109794     { 191, 1 },
109556 109795     { 191, 1 },
109557 109796     { 191, 1 },
109558 109797     { 147, 4 },
109559 109798     { 147, 6 },
109560 109799     { 147, 3 },
109561         -  { 243, 0 },
109562         -  { 243, 2 },
109563         -  { 242, 1 },
109564         -  { 242, 0 },
       109800  +  { 241, 0 },
       109801  +  { 241, 2 },
       109802  +  { 240, 1 },
       109803  +  { 240, 0 },
109565 109804     { 147, 1 },
109566 109805     { 147, 3 },
109567 109806     { 147, 1 },
109568 109807     { 147, 3 },
109569 109808     { 147, 6 },
109570 109809     { 147, 6 },
109571         -  { 244, 1 },
109572         -  { 245, 0 },
109573         -  { 245, 1 },
       109810  +  { 242, 1 },
       109811  +  { 243, 0 },
       109812  +  { 243, 1 },
109574 109813     { 147, 1 },
109575 109814     { 147, 4 },
109576         -  { 246, 7 },
       109815  +  { 244, 8 },
       109816  +  { 245, 1 },
       109817  +  { 245, 3 },
       109818  +  { 246, 0 },
       109819  +  { 246, 2 },
109577 109820     { 247, 1 },
109578 109821     { 247, 3 },
109579         -  { 248, 0 },
109580         -  { 248, 2 },
109581         -  { 249, 1 },
109582         -  { 249, 3 },
109583         -  { 250, 1 },
109584         -  { 251, 0 },
109585         -  { 251, 4 },
109586         -  { 251, 2 },
       109822  +  { 248, 1 },
       109823  +  { 249, 0 },
       109824  +  { 249, 4 },
       109825  +  { 249, 2 },
109587 109826   };
109588 109827   
109589 109828   static void yy_accept(yyParser*);  /* Forward Declaration */
109590 109829   
109591 109830   /*
109592 109831   ** Perform a reduce action and the shift that must immediately
109593 109832   ** follow the reduce.
................................................................................
109647 109886         case 7: /* explain ::= EXPLAIN QUERY PLAN */
109648 109887   { sqlite3BeginParse(pParse, 2); }
109649 109888           break;
109650 109889         case 8: /* cmdx ::= cmd */
109651 109890   { sqlite3FinishCoding(pParse); }
109652 109891           break;
109653 109892         case 9: /* cmd ::= BEGIN transtype trans_opt */
109654         -{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy4);}
       109893  +{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy392);}
109655 109894           break;
109656 109895         case 13: /* transtype ::= */
109657         -{yygotominor.yy4 = TK_DEFERRED;}
       109896  +{yygotominor.yy392 = TK_DEFERRED;}
109658 109897           break;
109659 109898         case 14: /* transtype ::= DEFERRED */
109660 109899         case 15: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==15);
109661 109900         case 16: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==16);
109662 109901         case 115: /* multiselect_op ::= UNION */ yytestcase(yyruleno==115);
109663 109902         case 117: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==117);
109664         -{yygotominor.yy4 = yymsp[0].major;}
       109903  +{yygotominor.yy392 = yymsp[0].major;}
109665 109904           break;
109666 109905         case 17: /* cmd ::= COMMIT trans_opt */
109667 109906         case 18: /* cmd ::= END trans_opt */ yytestcase(yyruleno==18);
109668 109907   {sqlite3CommitTransaction(pParse);}
109669 109908           break;
109670 109909         case 19: /* cmd ::= ROLLBACK trans_opt */
109671 109910   {sqlite3RollbackTransaction(pParse);}
................................................................................
109683 109922         case 24: /* cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
109684 109923   {
109685 109924     sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
109686 109925   }
109687 109926           break;
109688 109927         case 26: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
109689 109928   {
109690         -   sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy4,0,0,yymsp[-2].minor.yy4);
       109929  +   sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy392,0,0,yymsp[-2].minor.yy392);
109691 109930   }
109692 109931           break;
109693 109932         case 27: /* createkw ::= CREATE */
109694 109933   {
109695 109934     pParse->db->lookaside.bEnabled = 0;
109696 109935     yygotominor.yy0 = yymsp[0].minor.yy0;
109697 109936   }
................................................................................
109702 109941         case 83: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==83);
109703 109942         case 85: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==85);
109704 109943         case 87: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ yytestcase(yyruleno==87);
109705 109944         case 98: /* defer_subclause_opt ::= */ yytestcase(yyruleno==98);
109706 109945         case 109: /* ifexists ::= */ yytestcase(yyruleno==109);
109707 109946         case 120: /* distinct ::= ALL */ yytestcase(yyruleno==120);
109708 109947         case 121: /* distinct ::= */ yytestcase(yyruleno==121);
109709         -      case 222: /* between_op ::= BETWEEN */ yytestcase(yyruleno==222);
109710         -      case 225: /* in_op ::= IN */ yytestcase(yyruleno==225);
109711         -{yygotominor.yy4 = 0;}
       109948  +      case 221: /* between_op ::= BETWEEN */ yytestcase(yyruleno==221);
       109949  +      case 224: /* in_op ::= IN */ yytestcase(yyruleno==224);
       109950  +{yygotominor.yy392 = 0;}
109712 109951           break;
109713 109952         case 29: /* ifnotexists ::= IF NOT EXISTS */
109714 109953         case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30);
109715 109954         case 71: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==71);
109716 109955         case 86: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==86);
109717 109956         case 108: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==108);
109718 109957         case 119: /* distinct ::= DISTINCT */ yytestcase(yyruleno==119);
109719         -      case 223: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==223);
109720         -      case 226: /* in_op ::= NOT IN */ yytestcase(yyruleno==226);
109721         -{yygotominor.yy4 = 1;}
       109958  +      case 222: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==222);
       109959  +      case 225: /* in_op ::= NOT IN */ yytestcase(yyruleno==225);
       109960  +{yygotominor.yy392 = 1;}
109722 109961           break;
109723 109962         case 32: /* create_table_args ::= LP columnlist conslist_opt RP */
109724 109963   {
109725 109964     sqlite3EndTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0);
109726 109965   }
109727 109966           break;
109728 109967         case 33: /* create_table_args ::= AS select */
109729 109968   {
109730         -  sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy387);
109731         -  sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
       109969  +  sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy159);
       109970  +  sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
109732 109971   }
109733 109972           break;
109734 109973         case 36: /* column ::= columnid type carglist */
109735 109974   {
109736 109975     yygotominor.yy0.z = yymsp[-2].minor.yy0.z;
109737 109976     yygotominor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-2].minor.yy0.z) + pParse->sLastToken.n;
109738 109977   }
................................................................................
109751 109990         case 43: /* nm ::= JOIN_KW */ yytestcase(yyruleno==43);
109752 109991         case 46: /* typetoken ::= typename */ yytestcase(yyruleno==46);
109753 109992         case 49: /* typename ::= ids */ yytestcase(yyruleno==49);
109754 109993         case 127: /* as ::= AS nm */ yytestcase(yyruleno==127);
109755 109994         case 128: /* as ::= ids */ yytestcase(yyruleno==128);
109756 109995         case 138: /* dbnm ::= DOT nm */ yytestcase(yyruleno==138);
109757 109996         case 147: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==147);
109758         -      case 251: /* collate ::= COLLATE ids */ yytestcase(yyruleno==251);
109759         -      case 260: /* nmnum ::= plus_num */ yytestcase(yyruleno==260);
109760         -      case 261: /* nmnum ::= nm */ yytestcase(yyruleno==261);
109761         -      case 262: /* nmnum ::= ON */ yytestcase(yyruleno==262);
109762         -      case 263: /* nmnum ::= DELETE */ yytestcase(yyruleno==263);
109763         -      case 264: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==264);
109764         -      case 265: /* plus_num ::= plus_opt number */ yytestcase(yyruleno==265);
       109997  +      case 250: /* collate ::= COLLATE ids */ yytestcase(yyruleno==250);
       109998  +      case 259: /* nmnum ::= plus_num */ yytestcase(yyruleno==259);
       109999  +      case 260: /* nmnum ::= nm */ yytestcase(yyruleno==260);
       110000  +      case 261: /* nmnum ::= ON */ yytestcase(yyruleno==261);
       110001  +      case 262: /* nmnum ::= DELETE */ yytestcase(yyruleno==262);
       110002  +      case 263: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==263);
       110003  +      case 264: /* plus_num ::= PLUS number */ yytestcase(yyruleno==264);
       110004  +      case 265: /* plus_num ::= number */ yytestcase(yyruleno==265);
109765 110005         case 266: /* minus_num ::= MINUS number */ yytestcase(yyruleno==266);
109766 110006         case 267: /* number ::= INTEGER|FLOAT */ yytestcase(yyruleno==267);
109767         -      case 285: /* trnm ::= nm */ yytestcase(yyruleno==285);
       110007  +      case 283: /* trnm ::= nm */ yytestcase(yyruleno==283);
109768 110008   {yygotominor.yy0 = yymsp[0].minor.yy0;}
109769 110009           break;
109770 110010         case 45: /* type ::= typetoken */
109771 110011   {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
109772 110012           break;
109773 110013         case 47: /* typetoken ::= typename LP signed RP */
109774 110014   {
................................................................................
109783 110023   }
109784 110024           break;
109785 110025         case 50: /* typename ::= typename ids */
109786 110026   {yygotominor.yy0.z=yymsp[-1].minor.yy0.z; yygotominor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
109787 110027           break;
109788 110028         case 57: /* ccons ::= DEFAULT term */
109789 110029         case 59: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==59);
109790         -{sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy118);}
       110030  +{sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy342);}
109791 110031           break;
109792 110032         case 58: /* ccons ::= DEFAULT LP expr RP */
109793         -{sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy118);}
       110033  +{sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy342);}
109794 110034           break;
109795 110035         case 60: /* ccons ::= DEFAULT MINUS term */
109796 110036   {
109797 110037     ExprSpan v;
109798         -  v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy118.pExpr, 0, 0);
       110038  +  v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy342.pExpr, 0, 0);
109799 110039     v.zStart = yymsp[-1].minor.yy0.z;
109800         -  v.zEnd = yymsp[0].minor.yy118.zEnd;
       110040  +  v.zEnd = yymsp[0].minor.yy342.zEnd;
109801 110041     sqlite3AddDefaultValue(pParse,&v);
109802 110042   }
109803 110043           break;
109804 110044         case 61: /* ccons ::= DEFAULT id */
109805 110045   {
109806 110046     ExprSpan v;
109807 110047     spanExpr(&v, pParse, TK_STRING, &yymsp[0].minor.yy0);
109808 110048     sqlite3AddDefaultValue(pParse,&v);
109809 110049   }
109810 110050           break;
109811 110051         case 63: /* ccons ::= NOT NULL onconf */
109812         -{sqlite3AddNotNull(pParse, yymsp[0].minor.yy4);}
       110052  +{sqlite3AddNotNull(pParse, yymsp[0].minor.yy392);}
109813 110053           break;
109814 110054         case 64: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
109815         -{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy4,yymsp[0].minor.yy4,yymsp[-2].minor.yy4);}
       110055  +{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy392,yymsp[0].minor.yy392,yymsp[-2].minor.yy392);}
109816 110056           break;
109817 110057         case 65: /* ccons ::= UNIQUE onconf */
109818         -{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy4,0,0,0,0);}
       110058  +{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy392,0,0,0,0);}
109819 110059           break;
109820 110060         case 66: /* ccons ::= CHECK LP expr RP */
109821         -{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy118.pExpr);}
       110061  +{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy342.pExpr);}
109822 110062           break;
109823 110063         case 67: /* ccons ::= REFERENCES nm idxlist_opt refargs */
109824         -{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy322,yymsp[0].minor.yy4);}
       110064  +{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy442,yymsp[0].minor.yy392);}
109825 110065           break;
109826 110066         case 68: /* ccons ::= defer_subclause */
109827         -{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy4);}
       110067  +{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy392);}
109828 110068           break;
109829 110069         case 69: /* ccons ::= COLLATE ids */
109830 110070   {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
109831 110071           break;
109832 110072         case 72: /* refargs ::= */
109833         -{ yygotominor.yy4 = OE_None*0x0101; /* EV: R-19803-45884 */}
       110073  +{ yygotominor.yy392 = OE_None*0x0101; /* EV: R-19803-45884 */}
109834 110074           break;
109835 110075         case 73: /* refargs ::= refargs refarg */
109836         -{ yygotominor.yy4 = (yymsp[-1].minor.yy4 & ~yymsp[0].minor.yy215.mask) | yymsp[0].minor.yy215.value; }
       110076  +{ yygotominor.yy392 = (yymsp[-1].minor.yy392 & ~yymsp[0].minor.yy207.mask) | yymsp[0].minor.yy207.value; }
109837 110077           break;
109838 110078         case 74: /* refarg ::= MATCH nm */
109839 110079         case 75: /* refarg ::= ON INSERT refact */ yytestcase(yyruleno==75);
109840         -{ yygotominor.yy215.value = 0;     yygotominor.yy215.mask = 0x000000; }
       110080  +{ yygotominor.yy207.value = 0;     yygotominor.yy207.mask = 0x000000; }
109841 110081           break;
109842 110082         case 76: /* refarg ::= ON DELETE refact */
109843         -{ yygotominor.yy215.value = yymsp[0].minor.yy4;     yygotominor.yy215.mask = 0x0000ff; }
       110083  +{ yygotominor.yy207.value = yymsp[0].minor.yy392;     yygotominor.yy207.mask = 0x0000ff; }
109844 110084           break;
109845 110085         case 77: /* refarg ::= ON UPDATE refact */
109846         -{ yygotominor.yy215.value = yymsp[0].minor.yy4<<8;  yygotominor.yy215.mask = 0x00ff00; }
       110086  +{ yygotominor.yy207.value = yymsp[0].minor.yy392<<8;  yygotominor.yy207.mask = 0x00ff00; }
109847 110087           break;
109848 110088         case 78: /* refact ::= SET NULL */
109849         -{ yygotominor.yy4 = OE_SetNull;  /* EV: R-33326-45252 */}
       110089  +{ yygotominor.yy392 = OE_SetNull;  /* EV: R-33326-45252 */}
109850 110090           break;
109851 110091         case 79: /* refact ::= SET DEFAULT */
109852         -{ yygotominor.yy4 = OE_SetDflt;  /* EV: R-33326-45252 */}
       110092  +{ yygotominor.yy392 = OE_SetDflt;  /* EV: R-33326-45252 */}
109853 110093           break;
109854 110094         case 80: /* refact ::= CASCADE */
109855         -{ yygotominor.yy4 = OE_Cascade;  /* EV: R-33326-45252 */}
       110095  +{ yygotominor.yy392 = OE_Cascade;  /* EV: R-33326-45252 */}
109856 110096           break;
109857 110097         case 81: /* refact ::= RESTRICT */
109858         -{ yygotominor.yy4 = OE_Restrict; /* EV: R-33326-45252 */}
       110098  +{ yygotominor.yy392 = OE_Restrict; /* EV: R-33326-45252 */}
109859 110099           break;
109860 110100         case 82: /* refact ::= NO ACTION */
109861         -{ yygotominor.yy4 = OE_None;     /* EV: R-33326-45252 */}
       110101  +{ yygotominor.yy392 = OE_None;     /* EV: R-33326-45252 */}
109862 110102           break;
109863 110103         case 84: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
109864 110104         case 99: /* defer_subclause_opt ::= defer_subclause */ yytestcase(yyruleno==99);
109865 110105         case 101: /* onconf ::= ON CONFLICT resolvetype */ yytestcase(yyruleno==101);
109866 110106         case 104: /* resolvetype ::= raisetype */ yytestcase(yyruleno==104);
109867         -{yygotominor.yy4 = yymsp[0].minor.yy4;}
       110107  +{yygotominor.yy392 = yymsp[0].minor.yy392;}
109868 110108           break;
109869 110109         case 88: /* conslist_opt ::= */
109870 110110   {yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;}
109871 110111           break;
109872 110112         case 89: /* conslist_opt ::= COMMA conslist */
109873 110113   {yygotominor.yy0 = yymsp[-1].minor.yy0;}
109874 110114           break;
109875 110115         case 94: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
109876         -{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy322,yymsp[0].minor.yy4,yymsp[-2].minor.yy4,0);}
       110116  +{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy442,yymsp[0].minor.yy392,yymsp[-2].minor.yy392,0);}
109877 110117           break;
109878 110118         case 95: /* tcons ::= UNIQUE LP idxlist RP onconf */
109879         -{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy322,yymsp[0].minor.yy4,0,0,0,0);}
       110119  +{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy442,yymsp[0].minor.yy392,0,0,0,0);}
109880 110120           break;
109881 110121         case 96: /* tcons ::= CHECK LP expr RP onconf */
109882         -{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy118.pExpr);}
       110122  +{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy342.pExpr);}
109883 110123           break;
109884 110124         case 97: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
109885 110125   {
109886         -    sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy322, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy4);
109887         -    sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy4);
       110126  +    sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy442, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy442, yymsp[-1].minor.yy392);
       110127  +    sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy392);
109888 110128   }
109889 110129           break;
109890 110130         case 100: /* onconf ::= */
109891         -{yygotominor.yy4 = OE_Default;}
       110131  +{yygotominor.yy392 = OE_Default;}
109892 110132           break;
109893 110133         case 102: /* orconf ::= */
109894         -{yygotominor.yy210 = OE_Default;}
       110134  +{yygotominor.yy258 = OE_Default;}
109895 110135           break;
109896 110136         case 103: /* orconf ::= OR resolvetype */
109897         -{yygotominor.yy210 = (u8)yymsp[0].minor.yy4;}
       110137  +{yygotominor.yy258 = (u8)yymsp[0].minor.yy392;}
109898 110138           break;
109899 110139         case 105: /* resolvetype ::= IGNORE */
109900         -{yygotominor.yy4 = OE_Ignore;}
       110140  +{yygotominor.yy392 = OE_Ignore;}
109901 110141           break;
109902 110142         case 106: /* resolvetype ::= REPLACE */
109903         -{yygotominor.yy4 = OE_Replace;}
       110143  +{yygotominor.yy392 = OE_Replace;}
109904 110144           break;
109905 110145         case 107: /* cmd ::= DROP TABLE ifexists fullname */
109906 110146   {
109907         -  sqlite3DropTable(pParse, yymsp[0].minor.yy259, 0, yymsp[-1].minor.yy4);
       110147  +  sqlite3DropTable(pParse, yymsp[0].minor.yy347, 0, yymsp[-1].minor.yy392);
109908 110148   }
109909 110149           break;
109910 110150         case 110: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */
109911 110151   {
109912         -  sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy387, yymsp[-6].minor.yy4, yymsp[-4].minor.yy4);
       110152  +  sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy159, yymsp[-6].minor.yy392, yymsp[-4].minor.yy392);
109913 110153   }
109914 110154           break;
109915 110155         case 111: /* cmd ::= DROP VIEW ifexists fullname */
109916 110156   {
109917         -  sqlite3DropTable(pParse, yymsp[0].minor.yy259, 1, yymsp[-1].minor.yy4);
       110157  +  sqlite3DropTable(pParse, yymsp[0].minor.yy347, 1, yymsp[-1].minor.yy392);
109918 110158   }
109919 110159           break;
109920 110160         case 112: /* cmd ::= select */
109921 110161   {
109922 110162     SelectDest dest = {SRT_Output, 0, 0, 0, 0};
109923         -  sqlite3Select(pParse, yymsp[0].minor.yy387, &dest);
       110163  +  sqlite3Select(pParse, yymsp[0].minor.yy159, &dest);
109924 110164     sqlite3ExplainBegin(pParse->pVdbe);
109925         -  sqlite3ExplainSelect(pParse->pVdbe, yymsp[0].minor.yy387);
       110165  +  sqlite3ExplainSelect(pParse->pVdbe, yymsp[0].minor.yy159);
109926 110166     sqlite3ExplainFinish(pParse->pVdbe);
109927         -  sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
       110167  +  sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
109928 110168   }
109929 110169           break;
109930 110170         case 113: /* select ::= oneselect */
109931         -{yygotominor.yy387 = yymsp[0].minor.yy387;}
       110171  +{yygotominor.yy159 = yymsp[0].minor.yy159;}
109932 110172           break;
109933 110173         case 114: /* select ::= select multiselect_op oneselect */
109934 110174   {
109935         -  if( yymsp[0].minor.yy387 ){
109936         -    yymsp[0].minor.yy387->op = (u8)yymsp[-1].minor.yy4;
109937         -    yymsp[0].minor.yy387->pPrior = yymsp[-2].minor.yy387;
       110175  +  if( yymsp[0].minor.yy159 ){
       110176  +    yymsp[0].minor.yy159->op = (u8)yymsp[-1].minor.yy392;
       110177  +    yymsp[0].minor.yy159->pPrior = yymsp[-2].minor.yy159;
109938 110178     }else{
109939         -    sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy387);
       110179  +    sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy159);
109940 110180     }
109941         -  yygotominor.yy387 = yymsp[0].minor.yy387;
       110181  +  yygotominor.yy159 = yymsp[0].minor.yy159;
109942 110182   }
109943 110183           break;
109944 110184         case 116: /* multiselect_op ::= UNION ALL */
109945         -{yygotominor.yy4 = TK_ALL;}
       110185  +{yygotominor.yy392 = TK_ALL;}
109946 110186           break;
109947 110187         case 118: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
109948 110188   {
109949         -  yygotominor.yy387 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy322,yymsp[-5].minor.yy259,yymsp[-4].minor.yy314,yymsp[-3].minor.yy322,yymsp[-2].minor.yy314,yymsp[-1].minor.yy322,yymsp[-7].minor.yy4,yymsp[0].minor.yy292.pLimit,yymsp[0].minor.yy292.pOffset);
       110189  +  yygotominor.yy159 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy442,yymsp[-5].minor.yy347,yymsp[-4].minor.yy122,yymsp[-3].minor.yy442,yymsp[-2].minor.yy122,yymsp[-1].minor.yy442,yymsp[-7].minor.yy392,yymsp[0].minor.yy64.pLimit,yymsp[0].minor.yy64.pOffset);
109950 110190   }
109951 110191           break;
109952 110192         case 122: /* sclp ::= selcollist COMMA */
109953         -      case 247: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==247);
109954         -{yygotominor.yy322 = yymsp[-1].minor.yy322;}
       110193  +      case 246: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==246);
       110194  +{yygotominor.yy442 = yymsp[-1].minor.yy442;}
109955 110195           break;
109956 110196         case 123: /* sclp ::= */
109957 110197         case 151: /* orderby_opt ::= */ yytestcase(yyruleno==151);
109958         -      case 159: /* groupby_opt ::= */ yytestcase(yyruleno==159);
109959         -      case 240: /* exprlist ::= */ yytestcase(yyruleno==240);
109960         -      case 246: /* idxlist_opt ::= */ yytestcase(yyruleno==246);
109961         -{yygotominor.yy322 = 0;}
       110198  +      case 158: /* groupby_opt ::= */ yytestcase(yyruleno==158);
       110199  +      case 239: /* exprlist ::= */ yytestcase(yyruleno==239);
       110200  +      case 245: /* idxlist_opt ::= */ yytestcase(yyruleno==245);
       110201  +{yygotominor.yy442 = 0;}
109962 110202           break;
109963 110203         case 124: /* selcollist ::= sclp expr as */
109964 110204   {
109965         -   yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy322, yymsp[-1].minor.yy118.pExpr);
109966         -   if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[0].minor.yy0, 1);
109967         -   sqlite3ExprListSetSpan(pParse,yygotominor.yy322,&yymsp[-1].minor.yy118);
       110205  +   yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy442, yymsp[-1].minor.yy342.pExpr);
       110206  +   if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[0].minor.yy0, 1);
       110207  +   sqlite3ExprListSetSpan(pParse,yygotominor.yy442,&yymsp[-1].minor.yy342);
109968 110208   }
109969 110209           break;
109970 110210         case 125: /* selcollist ::= sclp STAR */
109971 110211   {
109972 110212     Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
109973         -  yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy322, p);
       110213  +  yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy442, p);
109974 110214   }
109975 110215           break;
109976 110216         case 126: /* selcollist ::= sclp nm DOT STAR */
109977 110217   {
109978 110218     Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &yymsp[0].minor.yy0);
109979 110219     Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
109980 110220     Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
109981         -  yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, pDot);
       110221  +  yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy442, pDot);
109982 110222   }
109983 110223           break;
109984 110224         case 129: /* as ::= */
109985 110225   {yygotominor.yy0.n = 0;}
109986 110226           break;
109987 110227         case 130: /* from ::= */
109988         -{yygotominor.yy259 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy259));}
       110228  +{yygotominor.yy347 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy347));}
109989 110229           break;
109990 110230         case 131: /* from ::= FROM seltablist */
109991 110231   {
109992         -  yygotominor.yy259 = yymsp[0].minor.yy259;
109993         -  sqlite3SrcListShiftJoinType(yygotominor.yy259);
       110232  +  yygotominor.yy347 = yymsp[0].minor.yy347;
       110233  +  sqlite3SrcListShiftJoinType(yygotominor.yy347);
109994 110234   }
109995 110235           break;
109996 110236         case 132: /* stl_prefix ::= seltablist joinop */
109997 110237   {
109998         -   yygotominor.yy259 = yymsp[-1].minor.yy259;
109999         -   if( ALWAYS(yygotominor.yy259 && yygotominor.yy259->nSrc>0) ) yygotominor.yy259->a[yygotominor.yy259->nSrc-1].jointype = (u8)yymsp[0].minor.yy4;
       110238  +   yygotominor.yy347 = yymsp[-1].minor.yy347;
       110239  +   if( ALWAYS(yygotominor.yy347 && yygotominor.yy347->nSrc>0) ) yygotominor.yy347->a[yygotominor.yy347->nSrc-1].jointype = (u8)yymsp[0].minor.yy392;
110000 110240   }
110001 110241           break;
110002 110242         case 133: /* stl_prefix ::= */
110003         -{yygotominor.yy259 = 0;}
       110243  +{yygotominor.yy347 = 0;}
110004 110244           break;
110005 110245         case 134: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
110006 110246   {
110007         -  yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
110008         -  sqlite3SrcListIndexedBy(pParse, yygotominor.yy259, &yymsp[-2].minor.yy0);
       110247  +  yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
       110248  +  sqlite3SrcListIndexedBy(pParse, yygotominor.yy347, &yymsp[-2].minor.yy0);
110009 110249   }
110010 110250           break;
110011 110251         case 135: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
110012 110252   {
110013         -    yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy387,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
       110253  +    yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy159,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
110014 110254     }
110015 110255           break;
110016 110256         case 136: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
110017 110257   {
110018         -    if( yymsp[-6].minor.yy259==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy314==0 && yymsp[0].minor.yy384==0 ){
110019         -      yygotominor.yy259 = yymsp[-4].minor.yy259;
       110258  +    if( yymsp[-6].minor.yy347==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy122==0 && yymsp[0].minor.yy180==0 ){
       110259  +      yygotominor.yy347 = yymsp[-4].minor.yy347;
110020 110260       }else{
110021 110261         Select *pSubquery;
110022         -      sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy259);
110023         -      pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy259,0,0,0,0,0,0,0);
110024         -      yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
       110262  +      sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy347);
       110263  +      pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy347,0,0,0,0,0,0,0);
       110264  +      yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
110025 110265       }
110026 110266     }
110027 110267           break;
110028 110268         case 137: /* dbnm ::= */
110029 110269         case 146: /* indexed_opt ::= */ yytestcase(yyruleno==146);
110030 110270   {yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
110031 110271           break;
110032 110272         case 139: /* fullname ::= nm dbnm */
110033         -{yygotominor.yy259 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
       110273  +{yygotominor.yy347 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
110034 110274           break;
110035 110275         case 140: /* joinop ::= COMMA|JOIN */
110036         -{ yygotominor.yy4 = JT_INNER; }
       110276  +{ yygotominor.yy392 = JT_INNER; }
110037 110277           break;
110038 110278         case 141: /* joinop ::= JOIN_KW JOIN */
110039         -{ yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
       110279  +{ yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
110040 110280           break;
110041 110281         case 142: /* joinop ::= JOIN_KW nm JOIN */
110042         -{ yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
       110282  +{ yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
110043 110283           break;
110044 110284         case 143: /* joinop ::= JOIN_KW nm nm JOIN */
110045         -{ yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
       110285  +{ yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
110046 110286           break;
110047 110287         case 144: /* on_opt ::= ON expr */
110048         -      case 155: /* sortitem ::= expr */ yytestcase(yyruleno==155);
110049         -      case 162: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==162);
110050         -      case 169: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==169);
110051         -      case 235: /* case_else ::= ELSE expr */ yytestcase(yyruleno==235);
110052         -      case 237: /* case_operand ::= expr */ yytestcase(yyruleno==237);
110053         -{yygotominor.yy314 = yymsp[0].minor.yy118.pExpr;}
       110288  +      case 161: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==161);
       110289  +      case 168: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==168);
       110290  +      case 234: /* case_else ::= ELSE expr */ yytestcase(yyruleno==234);
       110291  +      case 236: /* case_operand ::= expr */ yytestcase(yyruleno==236);
       110292  +{yygotominor.yy122 = yymsp[0].minor.yy342.pExpr;}
110054 110293           break;
110055 110294         case 145: /* on_opt ::= */
110056         -      case 161: /* having_opt ::= */ yytestcase(yyruleno==161);
110057         -      case 168: /* where_opt ::= */ yytestcase(yyruleno==168);
110058         -      case 236: /* case_else ::= */ yytestcase(yyruleno==236);
110059         -      case 238: /* case_operand ::= */ yytestcase(yyruleno==238);
110060         -{yygotominor.yy314 = 0;}
       110295  +      case 160: /* having_opt ::= */ yytestcase(yyruleno==160);
       110296  +      case 167: /* where_opt ::= */ yytestcase(yyruleno==167);
       110297  +      case 235: /* case_else ::= */ yytestcase(yyruleno==235);
       110298  +      case 237: /* case_operand ::= */ yytestcase(yyruleno==237);
       110299  +{yygotominor.yy122 = 0;}
110061 110300           break;
110062 110301         case 148: /* indexed_opt ::= NOT INDEXED */
110063 110302   {yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
110064 110303           break;
110065 110304         case 149: /* using_opt ::= USING LP inscollist RP */
110066         -      case 181: /* inscollist_opt ::= LP inscollist RP */ yytestcase(yyruleno==181);
110067         -{yygotominor.yy384 = yymsp[-1].minor.yy384;}
       110305  +      case 180: /* inscollist_opt ::= LP inscollist RP */ yytestcase(yyruleno==180);
       110306  +{yygotominor.yy180 = yymsp[-1].minor.yy180;}
110068 110307           break;
110069 110308         case 150: /* using_opt ::= */
110070         -      case 180: /* inscollist_opt ::= */ yytestcase(yyruleno==180);
110071         -{yygotominor.yy384 = 0;}
       110309  +      case 179: /* inscollist_opt ::= */ yytestcase(yyruleno==179);
       110310  +{yygotominor.yy180 = 0;}
110072 110311           break;
110073 110312         case 152: /* orderby_opt ::= ORDER BY sortlist */
110074         -      case 160: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==160);
110075         -      case 239: /* exprlist ::= nexprlist */ yytestcase(yyruleno==239);
110076         -{yygotominor.yy322 = yymsp[0].minor.yy322;}
110077         -        break;
110078         -      case 153: /* sortlist ::= sortlist COMMA sortitem sortorder */
110079         -{
110080         -  yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322,yymsp[-1].minor.yy314);
110081         -  if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
110082         -}
110083         -        break;
110084         -      case 154: /* sortlist ::= sortitem sortorder */
110085         -{
110086         -  yygotominor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy314);
110087         -  if( yygotominor.yy322 && ALWAYS(yygotominor.yy322->a) ) yygotominor.yy322->a[0].sortOrder = (u8)yymsp[0].minor.yy4;
110088         -}
110089         -        break;
110090         -      case 156: /* sortorder ::= ASC */
110091         -      case 158: /* sortorder ::= */ yytestcase(yyruleno==158);
110092         -{yygotominor.yy4 = SQLITE_SO_ASC;}
110093         -        break;
110094         -      case 157: /* sortorder ::= DESC */
110095         -{yygotominor.yy4 = SQLITE_SO_DESC;}
110096         -        break;
110097         -      case 163: /* limit_opt ::= */
110098         -{yygotominor.yy292.pLimit = 0; yygotominor.yy292.pOffset = 0;}
110099         -        break;
110100         -      case 164: /* limit_opt ::= LIMIT expr */
110101         -{yygotominor.yy292.pLimit = yymsp[0].minor.yy118.pExpr; yygotominor.yy292.pOffset = 0;}
110102         -        break;
110103         -      case 165: /* limit_opt ::= LIMIT expr OFFSET expr */
110104         -{yygotominor.yy292.pLimit = yymsp[-2].minor.yy118.pExpr; yygotominor.yy292.pOffset = yymsp[0].minor.yy118.pExpr;}
110105         -        break;
110106         -      case 166: /* limit_opt ::= LIMIT expr COMMA expr */
110107         -{yygotominor.yy292.pOffset = yymsp[-2].minor.yy118.pExpr; yygotominor.yy292.pLimit = yymsp[0].minor.yy118.pExpr;}
110108         -        break;
110109         -      case 167: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
110110         -{
110111         -  sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy259, &yymsp[-1].minor.yy0);
110112         -  sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy259,yymsp[0].minor.yy314);
110113         -}
110114         -        break;
110115         -      case 170: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
110116         -{
110117         -  sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy259, &yymsp[-3].minor.yy0);
110118         -  sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy322,"set list"); 
110119         -  sqlite3Update(pParse,yymsp[-4].minor.yy259,yymsp[-1].minor.yy322,yymsp[0].minor.yy314,yymsp[-5].minor.yy210);
110120         -}
110121         -        break;
110122         -      case 171: /* setlist ::= setlist COMMA nm EQ expr */
110123         -{
110124         -  yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[0].minor.yy118.pExpr);
110125         -  sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
110126         -}
110127         -        break;
110128         -      case 172: /* setlist ::= nm EQ expr */
110129         -{
110130         -  yygotominor.yy322 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy118.pExpr);
110131         -  sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
110132         -}
110133         -        break;
110134         -      case 173: /* cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP */
110135         -{sqlite3Insert(pParse, yymsp[-5].minor.yy259, yymsp[-1].minor.yy322, 0, yymsp[-4].minor.yy384, yymsp[-7].minor.yy210);}
110136         -        break;
110137         -      case 174: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
110138         -{sqlite3Insert(pParse, yymsp[-2].minor.yy259, 0, yymsp[0].minor.yy387, yymsp[-1].minor.yy384, yymsp[-4].minor.yy210);}
110139         -        break;
110140         -      case 175: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
110141         -{sqlite3Insert(pParse, yymsp[-3].minor.yy259, 0, 0, yymsp[-2].minor.yy384, yymsp[-5].minor.yy210);}
110142         -        break;
110143         -      case 176: /* insert_cmd ::= INSERT orconf */
110144         -{yygotominor.yy210 = yymsp[0].minor.yy210;}
110145         -        break;
110146         -      case 177: /* insert_cmd ::= REPLACE */
110147         -{yygotominor.yy210 = OE_Replace;}
110148         -        break;
110149         -      case 178: /* itemlist ::= itemlist COMMA expr */
110150         -      case 241: /* nexprlist ::= nexprlist COMMA expr */ yytestcase(yyruleno==241);
110151         -{yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy118.pExpr);}
110152         -        break;
110153         -      case 179: /* itemlist ::= expr */
110154         -      case 242: /* nexprlist ::= expr */ yytestcase(yyruleno==242);
110155         -{yygotominor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy118.pExpr);}
110156         -        break;
110157         -      case 182: /* inscollist ::= inscollist COMMA nm */
110158         -{yygotominor.yy384 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy384,&yymsp[0].minor.yy0);}
110159         -        break;
110160         -      case 183: /* inscollist ::= nm */
110161         -{yygotominor.yy384 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
110162         -        break;
110163         -      case 184: /* expr ::= term */
110164         -{yygotominor.yy118 = yymsp[0].minor.yy118;}
110165         -        break;
110166         -      case 185: /* expr ::= LP expr RP */
110167         -{yygotominor.yy118.pExpr = yymsp[-1].minor.yy118.pExpr; spanSet(&yygotominor.yy118,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
110168         -        break;
110169         -      case 186: /* term ::= NULL */
110170         -      case 191: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==191);
110171         -      case 192: /* term ::= STRING */ yytestcase(yyruleno==192);
110172         -{spanExpr(&yygotominor.yy118, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
110173         -        break;
110174         -      case 187: /* expr ::= id */
110175         -      case 188: /* expr ::= JOIN_KW */ yytestcase(yyruleno==188);
110176         -{spanExpr(&yygotominor.yy118, pParse, TK_ID, &yymsp[0].minor.yy0);}
110177         -        break;
110178         -      case 189: /* expr ::= nm DOT nm */
       110313  +      case 159: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==159);
       110314  +      case 238: /* exprlist ::= nexprlist */ yytestcase(yyruleno==238);
       110315  +{yygotominor.yy442 = yymsp[0].minor.yy442;}
       110316  +        break;
       110317  +      case 153: /* sortlist ::= sortlist COMMA expr sortorder */
       110318  +{
       110319  +  yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy442,yymsp[-1].minor.yy342.pExpr);
       110320  +  if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
       110321  +}
       110322  +        break;
       110323  +      case 154: /* sortlist ::= expr sortorder */
       110324  +{
       110325  +  yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy342.pExpr);
       110326  +  if( yygotominor.yy442 && ALWAYS(yygotominor.yy442->a) ) yygotominor.yy442->a[0].sortOrder = (u8)yymsp[0].minor.yy392;
       110327  +}
       110328  +        break;
       110329  +      case 155: /* sortorder ::= ASC */
       110330  +      case 157: /* sortorder ::= */ yytestcase(yyruleno==157);
       110331  +{yygotominor.yy392 = SQLITE_SO_ASC;}
       110332  +        break;
       110333  +      case 156: /* sortorder ::= DESC */
       110334  +{yygotominor.yy392 = SQLITE_SO_DESC;}
       110335  +        break;
       110336  +      case 162: /* limit_opt ::= */
       110337  +{yygotominor.yy64.pLimit = 0; yygotominor.yy64.pOffset = 0;}
       110338  +        break;
       110339  +      case 163: /* limit_opt ::= LIMIT expr */
       110340  +{yygotominor.yy64.pLimit = yymsp[0].minor.yy342.pExpr; yygotominor.yy64.pOffset = 0;}
       110341  +        break;
       110342  +      case 164: /* limit_opt ::= LIMIT expr OFFSET expr */
       110343  +{yygotominor.yy64.pLimit = yymsp[-2].minor.yy342.pExpr; yygotominor.yy64.pOffset = yymsp[0].minor.yy342.pExpr;}
       110344  +        break;
       110345  +      case 165: /* limit_opt ::= LIMIT expr COMMA expr */
       110346  +{yygotominor.yy64.pOffset = yymsp[-2].minor.yy342.pExpr; yygotominor.yy64.pLimit = yymsp[0].minor.yy342.pExpr;}
       110347  +        break;
       110348  +      case 166: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
       110349  +{
       110350  +  sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy347, &yymsp[-1].minor.yy0);
       110351  +  sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy347,yymsp[0].minor.yy122);
       110352  +}
       110353  +        break;
       110354  +      case 169: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
       110355  +{
       110356  +  sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy347, &yymsp[-3].minor.yy0);
       110357  +  sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy442,"set list"); 
       110358  +  sqlite3Update(pParse,yymsp[-4].minor.yy347,yymsp[-1].minor.yy442,yymsp[0].minor.yy122,yymsp[-5].minor.yy258);
       110359  +}
       110360  +        break;
       110361  +      case 170: /* setlist ::= setlist COMMA nm EQ expr */
       110362  +{
       110363  +  yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy442, yymsp[0].minor.yy342.pExpr);
       110364  +  sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1);
       110365  +}
       110366  +        break;
       110367  +      case 171: /* setlist ::= nm EQ expr */
       110368  +{
       110369  +  yygotominor.yy442 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy342.pExpr);
       110370  +  sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1);
       110371  +}
       110372  +        break;
       110373  +      case 172: /* cmd ::= insert_cmd INTO fullname inscollist_opt valuelist */
       110374  +{sqlite3Insert(pParse, yymsp[-2].minor.yy347, yymsp[0].minor.yy487.pList, yymsp[0].minor.yy487.pSelect, yymsp[-1].minor.yy180, yymsp[-4].minor.yy258);}
       110375  +        break;
       110376  +      case 173: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
       110377  +{sqlite3Insert(pParse, yymsp[-2].minor.yy347, 0, yymsp[0].minor.yy159, yymsp[-1].minor.yy180, yymsp[-4].minor.yy258);}
       110378  +        break;
       110379  +      case 174: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
       110380  +{sqlite3Insert(pParse, yymsp[-3].minor.yy347, 0, 0, yymsp[-2].minor.yy180, yymsp[-5].minor.yy258);}
       110381  +        break;
       110382  +      case 175: /* insert_cmd ::= INSERT orconf */
       110383  +{yygotominor.yy258 = yymsp[0].minor.yy258;}
       110384  +        break;
       110385  +      case 176: /* insert_cmd ::= REPLACE */
       110386  +{yygotominor.yy258 = OE_Replace;}
       110387  +        break;
       110388  +      case 177: /* valuelist ::= VALUES LP nexprlist RP */
       110389  +{
       110390  +  yygotominor.yy487.pList = yymsp[-1].minor.yy442;
       110391  +  yygotominor.yy487.pSelect = 0;
       110392  +}
       110393  +        break;
       110394  +      case 178: /* valuelist ::= valuelist COMMA LP exprlist RP */
       110395  +{
       110396  +  Select *pRight = sqlite3SelectNew(pParse, yymsp[-1].minor.yy442, 0, 0, 0, 0, 0, 0, 0, 0);
       110397  +  if( yymsp[-4].minor.yy487.pList ){
       110398  +    yymsp[-4].minor.yy487.pSelect = sqlite3SelectNew(pParse, yymsp[-4].minor.yy487.pList, 0, 0, 0, 0, 0, 0, 0, 0);
       110399  +    yymsp[-4].minor.yy487.pList = 0;
       110400  +  }
       110401  +  yygotominor.yy487.pList = 0;
       110402  +  if( yymsp[-4].minor.yy487.pSelect==0 || pRight==0 ){
       110403  +    sqlite3SelectDelete(pParse->db, pRight);
       110404  +    sqlite3SelectDelete(pParse->db, yymsp[-4].minor.yy487.pSelect);
       110405  +    yygotominor.yy487.pSelect = 0;
       110406  +  }else{
       110407  +    pRight->op = TK_ALL;
       110408  +    pRight->pPrior = yymsp[-4].minor.yy487.pSelect;
       110409  +    pRight->selFlags |= SF_Values;
       110410  +    pRight->pPrior->selFlags |= SF_Values;
       110411  +    yygotominor.yy487.pSelect = pRight;
       110412  +  }
       110413  +}
       110414  +        break;
       110415  +      case 181: /* inscollist ::= inscollist COMMA nm */
       110416  +{yygotominor.yy180 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy180,&yymsp[0].minor.yy0);}
       110417  +        break;
       110418  +      case 182: /* inscollist ::= nm */
       110419  +{yygotominor.yy180 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
       110420  +        break;
       110421  +      case 183: /* expr ::= term */
       110422  +{yygotominor.yy342 = yymsp[0].minor.yy342;}
       110423  +        break;
       110424  +      case 184: /* expr ::= LP expr RP */
       110425  +{yygotominor.yy342.pExpr = yymsp[-1].minor.yy342.pExpr; spanSet(&yygotominor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
       110426  +        break;
       110427  +      case 185: /* term ::= NULL */
       110428  +      case 190: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==190);
       110429  +      case 191: /* term ::= STRING */ yytestcase(yyruleno==191);
       110430  +{spanExpr(&yygotominor.yy342, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
       110431  +        break;
       110432  +      case 186: /* expr ::= id */
       110433  +      case 187: /* expr ::= JOIN_KW */ yytestcase(yyruleno==187);
       110434  +{spanExpr(&yygotominor.yy342, pParse, TK_ID, &yymsp[0].minor.yy0);}
       110435  +        break;
       110436  +      case 188: /* expr ::= nm DOT nm */
110179 110437   {
110180 110438     Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
110181 110439     Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
110182         -  yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
110183         -  spanSet(&yygotominor.yy118,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
       110440  +  yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
       110441  +  spanSet(&yygotominor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
110184 110442   }
110185 110443           break;
110186         -      case 190: /* expr ::= nm DOT nm DOT nm */
       110444  +      case 189: /* expr ::= nm DOT nm DOT nm */
110187 110445   {
110188 110446     Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
110189 110447     Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
110190 110448     Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
110191 110449     Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
110192         -  yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
110193         -  spanSet(&yygotominor.yy118,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
       110450  +  yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
       110451  +  spanSet(&yygotominor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
110194 110452   }
110195 110453           break;
110196         -      case 193: /* expr ::= REGISTER */
       110454  +      case 192: /* expr ::= REGISTER */
110197 110455   {
110198 110456     /* When doing a nested parse, one can include terms in an expression
110199 110457     ** that look like this:   #1 #2 ...  These terms refer to registers
110200 110458     ** in the virtual machine.  #N is the N-th register. */
110201 110459     if( pParse->nested==0 ){
110202 110460       sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &yymsp[0].minor.yy0);
110203         -    yygotominor.yy118.pExpr = 0;
110204         -  }else{
110205         -    yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &yymsp[0].minor.yy0);
110206         -    if( yygotominor.yy118.pExpr ) sqlite3GetInt32(&yymsp[0].minor.yy0.z[1], &yygotominor.yy118.pExpr->iTable);
110207         -  }
110208         -  spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
110209         -}
110210         -        break;
110211         -      case 194: /* expr ::= VARIABLE */
110212         -{
110213         -  spanExpr(&yygotominor.yy118, pParse, TK_VARIABLE, &yymsp[0].minor.yy0);
110214         -  sqlite3ExprAssignVarNumber(pParse, yygotominor.yy118.pExpr);
110215         -  spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
110216         -}
110217         -        break;
110218         -      case 195: /* expr ::= expr COLLATE ids */
110219         -{
110220         -  yygotominor.yy118.pExpr = sqlite3ExprSetCollByToken(pParse, yymsp[-2].minor.yy118.pExpr, &yymsp[0].minor.yy0);
110221         -  yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
110222         -  yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
110223         -}
110224         -        break;
110225         -      case 196: /* expr ::= CAST LP expr AS typetoken RP */
110226         -{
110227         -  yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy118.pExpr, 0, &yymsp[-1].minor.yy0);
110228         -  spanSet(&yygotominor.yy118,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
110229         -}
110230         -        break;
110231         -      case 197: /* expr ::= ID LP distinct exprlist RP */
110232         -{
110233         -  if( yymsp[-1].minor.yy322 && yymsp[-1].minor.yy322->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
       110461  +    yygotominor.yy342.pExpr = 0;
       110462  +  }else{
       110463  +    yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &yymsp[0].minor.yy0);
       110464  +    if( yygotominor.yy342.pExpr ) sqlite3GetInt32(&yymsp[0].minor.yy0.z[1], &yygotominor.yy342.pExpr->iTable);
       110465  +  }
       110466  +  spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
       110467  +}
       110468  +        break;
       110469  +      case 193: /* expr ::= VARIABLE */
       110470  +{
       110471  +  spanExpr(&yygotominor.yy342, pParse, TK_VARIABLE, &yymsp[0].minor.yy0);
       110472  +  sqlite3ExprAssignVarNumber(pParse, yygotominor.yy342.pExpr);
       110473  +  spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
       110474  +}
       110475  +        break;
       110476  +      case 194: /* expr ::= expr COLLATE ids */
       110477  +{
       110478  +  yygotominor.yy342.pExpr = sqlite3ExprSetCollByToken(pParse, yymsp[-2].minor.yy342.pExpr, &yymsp[0].minor.yy0);
       110479  +  yygotominor.yy342.zStart = yymsp[-2].minor.yy342.zStart;
       110480  +  yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
       110481  +}
       110482  +        break;
       110483  +      case 195: /* expr ::= CAST LP expr AS typetoken RP */
       110484  +{
       110485  +  yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy342.pExpr, 0, &yymsp[-1].minor.yy0);
       110486  +  spanSet(&yygotominor.yy342,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
       110487  +}
       110488  +        break;
       110489  +      case 196: /* expr ::= ID LP distinct exprlist RP */
       110490  +{
       110491  +  if( yymsp[-1].minor.yy442 && yymsp[-1].minor.yy442->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
110234 110492       sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
110235 110493     }
110236         -  yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
110237         -  spanSet(&yygotominor.yy118,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
110238         -  if( yymsp[-2].minor.yy4 && yygotominor.yy118.pExpr ){
110239         -    yygotominor.yy118.pExpr->flags |= EP_Distinct;
       110494  +  yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy442, &yymsp[-4].minor.yy0);
       110495  +  spanSet(&yygotominor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
       110496  +  if( yymsp[-2].minor.yy392 && yygotominor.yy342.pExpr ){
       110497  +    yygotominor.yy342.pExpr->flags |= EP_Distinct;
110240 110498     }
110241 110499   }
110242 110500           break;
110243         -      case 198: /* expr ::= ID LP STAR RP */
       110501  +      case 197: /* expr ::= ID LP STAR RP */
110244 110502   {
110245         -  yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
110246         -  spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
       110503  +  yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
       110504  +  spanSet(&yygotominor.yy342,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
110247 110505   }
110248 110506           break;
110249         -      case 199: /* term ::= CTIME_KW */
       110507  +      case 198: /* term ::= CTIME_KW */
110250 110508   {
110251 110509     /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
110252 110510     ** treated as functions that return constants */
110253         -  yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
110254         -  if( yygotominor.yy118.pExpr ){
110255         -    yygotominor.yy118.pExpr->op = TK_CONST_FUNC;  
110256         -  }
110257         -  spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
110258         -}
110259         -        break;
110260         -      case 200: /* expr ::= expr AND expr */
110261         -      case 201: /* expr ::= expr OR expr */ yytestcase(yyruleno==201);
110262         -      case 202: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==202);
110263         -      case 203: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==203);
110264         -      case 204: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==204);
110265         -      case 205: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==205);
110266         -      case 206: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==206);
110267         -      case 207: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==207);
110268         -{spanBinaryExpr(&yygotominor.yy118,pParse,yymsp[-1].major,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy118);}
110269         -        break;
110270         -      case 208: /* likeop ::= LIKE_KW */
110271         -      case 210: /* likeop ::= MATCH */ yytestcase(yyruleno==210);
110272         -{yygotominor.yy342.eOperator = yymsp[0].minor.yy0; yygotominor.yy342.not = 0;}
110273         -        break;
110274         -      case 209: /* likeop ::= NOT LIKE_KW */
110275         -      case 211: /* likeop ::= NOT MATCH */ yytestcase(yyruleno==211);
110276         -{yygotominor.yy342.eOperator = yymsp[0].minor.yy0; yygotominor.yy342.not = 1;}
110277         -        break;
110278         -      case 212: /* expr ::= expr likeop expr */
       110511  +  yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
       110512  +  if( yygotominor.yy342.pExpr ){
       110513  +    yygotominor.yy342.pExpr->op = TK_CONST_FUNC;  
       110514  +  }
       110515  +  spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
       110516  +}
       110517  +        break;
       110518  +      case 199: /* expr ::= expr AND expr */
       110519  +      case 200: /* expr ::= expr OR expr */ yytestcase(yyruleno==200);
       110520  +      case 201: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==201);
       110521  +      case 202: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==202);
       110522  +      case 203: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==203);
       110523  +      case 204: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==204);
       110524  +      case 205: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==205);
       110525  +      case 206: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==206);
       110526  +{spanBinaryExpr(&yygotominor.yy342,pParse,yymsp[-1].major,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy342);}
       110527  +        break;
       110528  +      case 207: /* likeop ::= LIKE_KW */
       110529  +      case 209: /* likeop ::= MATCH */ yytestcase(yyruleno==209);
       110530  +{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.not = 0;}
       110531  +        break;
       110532  +      case 208: /* likeop ::= NOT LIKE_KW */
       110533  +      case 210: /* likeop ::= NOT MATCH */ yytestcase(yyruleno==210);
       110534  +{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.not = 1;}
       110535  +        break;
       110536  +      case 211: /* expr ::= expr likeop expr */
110279 110537   {
110280 110538     ExprList *pList;
110281         -  pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy118.pExpr);
110282         -  pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy118.pExpr);
110283         -  yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy342.eOperator);
110284         -  if( yymsp[-1].minor.yy342.not ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
110285         -  yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
110286         -  yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
110287         -  if( yygotominor.yy118.pExpr ) yygotominor.yy118.pExpr->flags |= EP_InfixFunc;
       110539  +  pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy342.pExpr);
       110540  +  pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy342.pExpr);
       110541  +  yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy318.eOperator);
       110542  +  if( yymsp[-1].minor.yy318.not ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
       110543  +  yygotominor.yy342.zStart = yymsp[-2].minor.yy342.zStart;
       110544  +  yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd;
       110545  +  if( yygotominor.yy342.pExpr ) yygotominor.yy342.pExpr->flags |= EP_InfixFunc;
110288 110546   }
110289 110547           break;
110290         -      case 213: /* expr ::= expr likeop expr ESCAPE expr */
       110548  +      case 212: /* expr ::= expr likeop expr ESCAPE expr */
110291 110549   {
110292 110550     ExprList *pList;
110293         -  pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
110294         -  pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy118.pExpr);
110295         -  pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy118.pExpr);
110296         -  yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy342.eOperator);
110297         -  if( yymsp[-3].minor.yy342.not ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
110298         -  yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
110299         -  yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
110300         -  if( yygotominor.yy118.pExpr ) yygotominor.yy118.pExpr->flags |= EP_InfixFunc;
110301         -}
110302         -        break;
110303         -      case 214: /* expr ::= expr ISNULL|NOTNULL */
110304         -{spanUnaryPostfix(&yygotominor.yy118,pParse,yymsp[0].major,&yymsp[-1].minor.yy118,&yymsp[0].minor.yy0);}
110305         -        break;
110306         -      case 215: /* expr ::= expr NOT NULL */
110307         -{spanUnaryPostfix(&yygotominor.yy118,pParse,TK_NOTNULL,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy0);}
110308         -        break;
110309         -      case 216: /* expr ::= expr IS expr */
110310         -{
110311         -  spanBinaryExpr(&yygotominor.yy118,pParse,TK_IS,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy118);
110312         -  binaryToUnaryIfNull(pParse, yymsp[0].minor.yy118.pExpr, yygotominor.yy118.pExpr, TK_ISNULL);
110313         -}
110314         -        break;
110315         -      case 217: /* expr ::= expr IS NOT expr */
110316         -{
110317         -  spanBinaryExpr(&yygotominor.yy118,pParse,TK_ISNOT,&yymsp[-3].minor.yy118,&yymsp[0].minor.yy118);
110318         -  binaryToUnaryIfNull(pParse, yymsp[0].minor.yy118.pExpr, yygotominor.yy118.pExpr, TK_NOTNULL);
110319         -}
110320         -        break;
110321         -      case 218: /* expr ::= NOT expr */
110322         -      case 219: /* expr ::= BITNOT expr */ yytestcase(yyruleno==219);
110323         -{spanUnaryPrefix(&yygotominor.yy118,pParse,yymsp[-1].major,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
110324         -        break;
110325         -      case 220: /* expr ::= MINUS expr */
110326         -{spanUnaryPrefix(&yygotominor.yy118,pParse,TK_UMINUS,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
110327         -        break;
110328         -      case 221: /* expr ::= PLUS expr */
110329         -{spanUnaryPrefix(&yygotominor.yy118,pParse,TK_UPLUS,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
110330         -        break;
110331         -      case 224: /* expr ::= expr between_op expr AND expr */
110332         -{
110333         -  ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
110334         -  pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy118.pExpr);
110335         -  yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy118.pExpr, 0, 0);
110336         -  if( yygotominor.yy118.pExpr ){
110337         -    yygotominor.yy118.pExpr->x.pList = pList;
       110551  +  pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr);
       110552  +  pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy342.pExpr);
       110553  +  pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy342.pExpr);
       110554  +  yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy318.eOperator);
       110555  +  if( yymsp[-3].minor.yy318.not ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
       110556  +  yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart;
       110557  +  yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd;
       110558  +  if( yygotominor.yy342.pExpr ) yygotominor.yy342.pExpr->flags |= EP_InfixFunc;
       110559  +}
       110560  +        break;
       110561  +      case 213: /* expr ::= expr ISNULL|NOTNULL */
       110562  +{spanUnaryPostfix(&yygotominor.yy342,pParse,yymsp[0].major,&yymsp[-1].minor.yy342,&yymsp[0].minor.yy0);}
       110563  +        break;
       110564  +      case 214: /* expr ::= expr NOT NULL */
       110565  +{spanUnaryPostfix(&yygotominor.yy342,pParse,TK_NOTNULL,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy0);}
       110566  +        break;
       110567  +      case 215: /* expr ::= expr IS expr */
       110568  +{
       110569  +  spanBinaryExpr(&yygotominor.yy342,pParse,TK_IS,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy342);
       110570  +  binaryToUnaryIfNull(pParse, yymsp[0].minor.yy342.pExpr, yygotominor.yy342.pExpr, TK_ISNULL);
       110571  +}
       110572  +        break;
       110573  +      case 216: /* expr ::= expr IS NOT expr */
       110574  +{
       110575  +  spanBinaryExpr(&yygotominor.yy342,pParse,TK_ISNOT,&yymsp[-3].minor.yy342,&yymsp[0].minor.yy342);
       110576  +  binaryToUnaryIfNull(pParse, yymsp[0].minor.yy342.pExpr, yygotominor.yy342.pExpr, TK_NOTNULL);
       110577  +}
       110578  +        break;
       110579  +      case 217: /* expr ::= NOT expr */
       110580  +      case 218: /* expr ::= BITNOT expr */ yytestcase(yyruleno==218);
       110581  +{spanUnaryPrefix(&yygotominor.yy342,pParse,yymsp[-1].major,&yymsp[0].minor.yy342,&yymsp[-1].minor.yy0);}
       110582  +        break;
       110583  +      case 219: /* expr ::= MINUS expr */
       110584  +{spanUnaryPrefix(&yygotominor.yy342,pParse,TK_UMINUS,&yymsp[0].minor.yy342,&yymsp[-1].minor.yy0);}
       110585  +        break;
       110586  +      case 220: /* expr ::= PLUS expr */
       110587  +{spanUnaryPrefix(&yygotominor.yy342,pParse,TK_UPLUS,&yymsp[0].minor.yy342,&yymsp[-1].minor.yy0);}
       110588  +        break;
       110589  +      case 223: /* expr ::= expr between_op expr AND expr */
       110590  +{
       110591  +  ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr);
       110592  +  pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy342.pExpr);
       110593  +  yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy342.pExpr, 0, 0);
       110594  +  if( yygotominor.yy342.pExpr ){
       110595  +    yygotominor.yy342.pExpr->x.pList = pList;
110338 110596     }else{
110339 110597       sqlite3ExprListDelete(pParse->db, pList);
110340 110598     } 
110341         -  if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
110342         -  yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
110343         -  yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
       110599  +  if( yymsp[-3].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
       110600  +  yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart;
       110601  +  yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd;
110344 110602   }
110345 110603           break;
110346         -      case 227: /* expr ::= expr in_op LP exprlist RP */
       110604  +      case 226: /* expr ::= expr in_op LP exprlist RP */
110347 110605   {
110348         -    if( yymsp[-1].minor.yy322==0 ){
       110606  +    if( yymsp[-1].minor.yy442==0 ){
110349 110607         /* Expressions of the form
110350 110608         **
110351 110609         **      expr1 IN ()
110352 110610         **      expr1 NOT IN ()
110353 110611         **
110354 110612         ** simplify to constants 0 (false) and 1 (true), respectively,
110355 110613         ** regardless of the value of expr1.
110356 110614         */
110357         -      yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[yymsp[-3].minor.yy4]);
110358         -      sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy118.pExpr);
110359         -    }else{
110360         -      yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy118.pExpr, 0, 0);
110361         -      if( yygotominor.yy118.pExpr ){
110362         -        yygotominor.yy118.pExpr->x.pList = yymsp[-1].minor.yy322;
110363         -        sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
110364         -      }else{
110365         -        sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322);
110366         -      }
110367         -      if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
110368         -    }
110369         -    yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
110370         -    yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
110371         -  }
110372         -        break;
110373         -      case 228: /* expr ::= LP select RP */
110374         -{
110375         -    yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
110376         -    if( yygotominor.yy118.pExpr ){
110377         -      yygotominor.yy118.pExpr->x.pSelect = yymsp[-1].minor.yy387;
110378         -      ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
110379         -      sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
110380         -    }else{
110381         -      sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
110382         -    }
110383         -    yygotominor.yy118.zStart = yymsp[-2].minor.yy0.z;
110384         -    yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
110385         -  }
110386         -        break;
110387         -      case 229: /* expr ::= expr in_op LP select RP */
110388         -{
110389         -    yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy118.pExpr, 0, 0);
110390         -    if( yygotominor.yy118.pExpr ){
110391         -      yygotominor.yy118.pExpr->x.pSelect = yymsp[-1].minor.yy387;
110392         -      ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
110393         -      sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
110394         -    }else{
110395         -      sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
110396         -    }
110397         -    if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
110398         -    yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
110399         -    yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
110400         -  }
110401         -        break;
110402         -      case 230: /* expr ::= expr in_op nm dbnm */
       110615  +      yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[yymsp[-3].minor.yy392]);
       110616  +      sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy342.pExpr);
       110617  +    }else{
       110618  +      yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0);
       110619  +      if( yygotominor.yy342.pExpr ){
       110620  +        yygotominor.yy342.pExpr->x.pList = yymsp[-1].minor.yy442;
       110621  +        sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
       110622  +      }else{
       110623  +        sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy442);
       110624  +      }
       110625  +      if( yymsp[-3].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
       110626  +    }
       110627  +    yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart;
       110628  +    yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
       110629  +  }
       110630  +        break;
       110631  +      case 227: /* expr ::= LP select RP */
       110632  +{
       110633  +    yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
       110634  +    if( yygotominor.yy342.pExpr ){
       110635  +      yygotominor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
       110636  +      ExprSetProperty(yygotominor.yy342.pExpr, EP_xIsSelect);
       110637  +      sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
       110638  +    }else{
       110639  +      sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
       110640  +    }
       110641  +    yygotominor.yy342.zStart = yymsp[-2].minor.yy0.z;
       110642  +    yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
       110643  +  }
       110644  +        break;
       110645  +      case 228: /* expr ::= expr in_op LP select RP */
       110646  +{
       110647  +    yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0);
       110648  +    if( yygotominor.yy342.pExpr ){
       110649  +      yygotominor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
       110650  +      ExprSetProperty(yygotominor.yy342.pExpr, EP_xIsSelect);
       110651  +      sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
       110652  +    }else{
       110653  +      sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
       110654  +    }
       110655  +    if( yymsp[-3].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
       110656  +    yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart;
       110657  +    yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
       110658  +  }
       110659  +        break;
       110660  +      case 229: /* expr ::= expr in_op nm dbnm */
110403 110661   {
110404 110662       SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
110405         -    yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy118.pExpr, 0, 0);
110406         -    if( yygotominor.yy118.pExpr ){
110407         -      yygotominor.yy118.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
110408         -      ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
110409         -      sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
       110663  +    yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy342.pExpr, 0, 0);
       110664  +    if( yygotominor.yy342.pExpr ){
       110665  +      yygotominor.yy342.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
       110666  +      ExprSetProperty(yygotominor.yy342.pExpr, EP_xIsSelect);
       110667  +      sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
110410 110668       }else{
110411 110669         sqlite3SrcListDelete(pParse->db, pSrc);
110412 110670       }
110413         -    if( yymsp[-2].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
110414         -    yygotominor.yy118.zStart = yymsp[-3].minor.yy118.zStart;
110415         -    yygotominor.yy118.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
       110671  +    if( yymsp[-2].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
       110672  +    yygotominor.yy342.zStart = yymsp[-3].minor.yy342.zStart;
       110673  +    yygotominor.yy342.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
110416 110674     }
110417 110675           break;
110418         -      case 231: /* expr ::= EXISTS LP select RP */
       110676  +      case 230: /* expr ::= EXISTS LP select RP */
110419 110677   {
110420         -    Expr *p = yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
       110678  +    Expr *p = yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
110421 110679       if( p ){
110422         -      p->x.pSelect = yymsp[-1].minor.yy387;
       110680  +      p->x.pSelect = yymsp[-1].minor.yy159;
110423 110681         ExprSetProperty(p, EP_xIsSelect);
110424 110682         sqlite3ExprSetHeight(pParse, p);
110425 110683       }else{
110426         -      sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
110427         -    }
110428         -    yygotominor.yy118.zStart = yymsp[-3].minor.yy0.z;
110429         -    yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
110430         -  }
110431         -        break;
110432         -      case 232: /* expr ::= CASE case_operand case_exprlist case_else END */
110433         -{
110434         -  yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy314, yymsp[-1].minor.yy314, 0);
110435         -  if( yygotominor.yy118.pExpr ){
110436         -    yygotominor.yy118.pExpr->x.pList = yymsp[-2].minor.yy322;
110437         -    sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
110438         -  }else{
110439         -    sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
110440         -  }
110441         -  yygotominor.yy118.zStart = yymsp[-4].minor.yy0.z;
110442         -  yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
110443         -}
110444         -        break;
110445         -      case 233: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
110446         -{
110447         -  yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy118.pExpr);
110448         -  yygotominor.yy322 = sqlite3ExprListAppend(pParse,yygotominor.yy322, yymsp[0].minor.yy118.pExpr);
110449         -}
110450         -        break;
110451         -      case 234: /* case_exprlist ::= WHEN expr THEN expr */
110452         -{
110453         -  yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
110454         -  yygotominor.yy322 = sqlite3ExprListAppend(pParse,yygotominor.yy322, yymsp[0].minor.yy118.pExpr);
110455         -}
110456         -        break;
110457         -      case 243: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */
       110684  +      sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
       110685  +    }
       110686  +    yygotominor.yy342.zStart = yymsp[-3].minor.yy0.z;
       110687  +    yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
       110688  +  }
       110689  +        break;
       110690  +      case 231: /* expr ::= CASE case_operand case_exprlist case_else END */
       110691  +{
       110692  +  yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy122, yymsp[-1].minor.yy122, 0);
       110693  +  if( yygotominor.yy342.pExpr ){
       110694  +    yygotominor.yy342.pExpr->x.pList = yymsp[-2].minor.yy442;
       110695  +    sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
       110696  +  }else{
       110697  +    sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy442);
       110698  +  }
       110699  +  yygotominor.yy342.zStart = yymsp[-4].minor.yy0.z;
       110700  +  yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
       110701  +}
       110702  +        break;
       110703  +      case 232: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
       110704  +{
       110705  +  yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, yymsp[-2].minor.yy342.pExpr);
       110706  +  yygotominor.yy442 = sqlite3ExprListAppend(pParse,yygotominor.yy442, yymsp[0].minor.yy342.pExpr);
       110707  +}
       110708  +        break;
       110709  +      case 233: /* case_exprlist ::= WHEN expr THEN expr */
       110710  +{
       110711  +  yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr);
       110712  +  yygotominor.yy442 = sqlite3ExprListAppend(pParse,yygotominor.yy442, yymsp[0].minor.yy342.pExpr);
       110713  +}
       110714  +        break;
       110715  +      case 240: /* nexprlist ::= nexprlist COMMA expr */
       110716  +{yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy442,yymsp[0].minor.yy342.pExpr);}
       110717  +        break;
       110718  +      case 241: /* nexprlist ::= expr */
       110719  +{yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy342.pExpr);}
       110720  +        break;
       110721  +      case 242: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */
110458 110722   {
110459 110723     sqlite3CreateIndex(pParse, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0, 
110460         -                     sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy322, yymsp[-9].minor.yy4,
110461         -                      &yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy4);
       110724  +                     sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy442, yymsp[-9].minor.yy392,
       110725  +                      &yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy392);
110462 110726   }
110463 110727           break;
110464         -      case 244: /* uniqueflag ::= UNIQUE */
110465         -      case 298: /* raisetype ::= ABORT */ yytestcase(yyruleno==298);
110466         -{yygotominor.yy4 = OE_Abort;}
       110728  +      case 243: /* uniqueflag ::= UNIQUE */
       110729  +      case 296: /* raisetype ::= ABORT */ yytestcase(yyruleno==296);
       110730  +{yygotominor.yy392 = OE_Abort;}
110467 110731           break;
110468         -      case 245: /* uniqueflag ::= */
110469         -{yygotominor.yy4 = OE_None;}
       110732  +      case 244: /* uniqueflag ::= */
       110733  +{yygotominor.yy392 = OE_None;}
110470 110734           break;
110471         -      case 248: /* idxlist ::= idxlist COMMA nm collate sortorder */
       110735  +      case 247: /* idxlist ::= idxlist COMMA nm collate sortorder */
110472 110736   {
110473 110737     Expr *p = 0;
110474 110738     if( yymsp[-1].minor.yy0.n>0 ){
110475 110739       p = sqlite3Expr(pParse->db, TK_COLUMN, 0);
110476 110740       sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0);
110477 110741     }
110478         -  yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, p);
110479         -  sqlite3ExprListSetName(pParse,yygotominor.yy322,&yymsp[-2].minor.yy0,1);
110480         -  sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
110481         -  if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
       110742  +  yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, p);
       110743  +  sqlite3ExprListSetName(pParse,yygotominor.yy442,&yymsp[-2].minor.yy0,1);
       110744  +  sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index");
       110745  +  if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
110482 110746   }
110483 110747           break;
110484         -      case 249: /* idxlist ::= nm collate sortorder */
       110748  +      case 248: /* idxlist ::= nm collate sortorder */
110485 110749   {
110486 110750     Expr *p = 0;
110487 110751     if( yymsp[-1].minor.yy0.n>0 ){
110488 110752       p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
110489 110753       sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0);
110490 110754     }
110491         -  yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, p);
110492         -  sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
110493         -  sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
110494         -  if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
       110755  +  yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, p);
       110756  +  sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1);
       110757  +  sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index");
       110758  +  if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
110495 110759   }
110496 110760           break;
110497         -      case 250: /* collate ::= */
       110761  +      case 249: /* collate ::= */
110498 110762   {yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
110499 110763           break;
110500         -      case 252: /* cmd ::= DROP INDEX ifexists fullname */
110501         -{sqlite3DropIndex(pParse, yymsp[0].minor.yy259, yymsp[-1].minor.yy4);}
       110764  +      case 251: /* cmd ::= DROP INDEX ifexists fullname */
       110765  +{sqlite3DropIndex(pParse, yymsp[0].minor.yy347, yymsp[-1].minor.yy392);}
110502 110766           break;
110503         -      case 253: /* cmd ::= VACUUM */
110504         -      case 254: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==254);
       110767  +      case 252: /* cmd ::= VACUUM */
       110768  +      case 253: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==253);
110505 110769   {sqlite3Vacuum(pParse);}
110506 110770           break;
110507         -      case 255: /* cmd ::= PRAGMA nm dbnm */
       110771  +      case 254: /* cmd ::= PRAGMA nm dbnm */
110508 110772   {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
110509 110773           break;
110510         -      case 256: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
       110774  +      case 255: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
110511 110775   {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
110512 110776           break;
110513         -      case 257: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
       110777  +      case 256: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
110514 110778   {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
110515 110779           break;
110516         -      case 258: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
       110780  +      case 257: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
110517 110781   {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
110518 110782           break;
110519         -      case 259: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
       110783  +      case 258: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
110520 110784   {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
110521 110785           break;
110522         -      case 270: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
       110786  +      case 268: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
110523 110787   {
110524 110788     Token all;
110525 110789     all.z = yymsp[-3].minor.yy0.z;
110526 110790     all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
110527         -  sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy203, &all);
       110791  +  sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy327, &all);
110528 110792   }
110529 110793           break;
110530         -      case 271: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
       110794  +      case 269: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
110531 110795   {
110532         -  sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy4, yymsp[-4].minor.yy90.a, yymsp[-4].minor.yy90.b, yymsp[-2].minor.yy259, yymsp[0].minor.yy314, yymsp[-10].minor.yy4, yymsp[-8].minor.yy4);
       110796  +  sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy392, yymsp[-4].minor.yy410.a, yymsp[-4].minor.yy410.b, yymsp[-2].minor.yy347, yymsp[0].minor.yy122, yymsp[-10].minor.yy392, yymsp[-8].minor.yy392);
110533 110797     yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
110534 110798   }
110535 110799           break;
110536         -      case 272: /* trigger_time ::= BEFORE */
110537         -      case 275: /* trigger_time ::= */ yytestcase(yyruleno==275);
110538         -{ yygotominor.yy4 = TK_BEFORE; }
110539         -        break;
110540         -      case 273: /* trigger_time ::= AFTER */
110541         -{ yygotominor.yy4 = TK_AFTER;  }
110542         -        break;
110543         -      case 274: /* trigger_time ::= INSTEAD OF */
110544         -{ yygotominor.yy4 = TK_INSTEAD;}
110545         -        break;
110546         -      case 276: /* trigger_event ::= DELETE|INSERT */
110547         -      case 277: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==277);
110548         -{yygotominor.yy90.a = yymsp[0].major; yygotominor.yy90.b = 0;}
110549         -        break;
110550         -      case 278: /* trigger_event ::= UPDATE OF inscollist */
110551         -{yygotominor.yy90.a = TK_UPDATE; yygotominor.yy90.b = yymsp[0].minor.yy384;}
110552         -        break;
110553         -      case 281: /* when_clause ::= */
110554         -      case 303: /* key_opt ::= */ yytestcase(yyruleno==303);
110555         -{ yygotominor.yy314 = 0; }
110556         -        break;
110557         -      case 282: /* when_clause ::= WHEN expr */
110558         -      case 304: /* key_opt ::= KEY expr */ yytestcase(yyruleno==304);
110559         -{ yygotominor.yy314 = yymsp[0].minor.yy118.pExpr; }
110560         -        break;
110561         -      case 283: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
110562         -{
110563         -  assert( yymsp[-2].minor.yy203!=0 );
110564         -  yymsp[-2].minor.yy203->pLast->pNext = yymsp[-1].minor.yy203;
110565         -  yymsp[-2].minor.yy203->pLast = yymsp[-1].minor.yy203;
110566         -  yygotominor.yy203 = yymsp[-2].minor.yy203;
110567         -}
110568         -        break;
110569         -      case 284: /* trigger_cmd_list ::= trigger_cmd SEMI */
       110800  +      case 270: /* trigger_time ::= BEFORE */
       110801  +      case 273: /* trigger_time ::= */ yytestcase(yyruleno==273);
       110802  +{ yygotominor.yy392 = TK_BEFORE; }
       110803  +        break;
       110804  +      case 271: /* trigger_time ::= AFTER */
       110805  +{ yygotominor.yy392 = TK_AFTER;  }
       110806  +        break;
       110807  +      case 272: /* trigger_time ::= INSTEAD OF */
       110808  +{ yygotominor.yy392 = TK_INSTEAD;}
       110809  +        break;
       110810  +      case 274: /* trigger_event ::= DELETE|INSERT */
       110811  +      case 275: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==275);
       110812  +{yygotominor.yy410.a = yymsp[0].major; yygotominor.yy410.b = 0;}
       110813  +        break;
       110814  +      case 276: /* trigger_event ::= UPDATE OF inscollist */
       110815  +{yygotominor.yy410.a = TK_UPDATE; yygotominor.yy410.b = yymsp[0].minor.yy180;}
       110816  +        break;
       110817  +      case 279: /* when_clause ::= */
       110818  +      case 301: /* key_opt ::= */ yytestcase(yyruleno==301);
       110819  +{ yygotominor.yy122 = 0; }
       110820  +        break;
       110821  +      case 280: /* when_clause ::= WHEN expr */
       110822  +      case 302: /* key_opt ::= KEY expr */ yytestcase(yyruleno==302);
       110823  +{ yygotominor.yy122 = yymsp[0].minor.yy342.pExpr; }
       110824  +        break;
       110825  +      case 281: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
       110826  +{
       110827  +  assert( yymsp[-2].minor.yy327!=0 );
       110828  +  yymsp[-2].minor.yy327->pLast->pNext = yymsp[-1].minor.yy327;
       110829  +  yymsp[-2].minor.yy327->pLast = yymsp[-1].minor.yy327;
       110830  +  yygotominor.yy327 = yymsp[-2].minor.yy327;
       110831  +}
       110832  +        break;
       110833  +      case 282: /* trigger_cmd_list ::= trigger_cmd SEMI */
110570 110834   { 
110571         -  assert( yymsp[-1].minor.yy203!=0 );
110572         -  yymsp[-1].minor.yy203->pLast = yymsp[-1].minor.yy203;
110573         -  yygotominor.yy203 = yymsp[-1].minor.yy203;
       110835  +  assert( yymsp[-1].minor.yy327!=0 );
       110836  +  yymsp[-1].minor.yy327->pLast = yymsp[-1].minor.yy327;
       110837  +  yygotominor.yy327 = yymsp[-1].minor.yy327;
110574 110838   }
110575 110839           break;
110576         -      case 286: /* trnm ::= nm DOT nm */
       110840  +      case 284: /* trnm ::= nm DOT nm */
110577 110841   {
110578 110842     yygotominor.yy0 = yymsp[0].minor.yy0;
110579 110843     sqlite3ErrorMsg(pParse, 
110580 110844           "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
110581 110845           "statements within triggers");
110582 110846   }
110583 110847           break;
110584         -      case 288: /* tridxby ::= INDEXED BY nm */
       110848  +      case 286: /* tridxby ::= INDEXED BY nm */
110585 110849   {
110586 110850     sqlite3ErrorMsg(pParse,
110587 110851           "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
110588 110852           "within triggers");
110589 110853   }
110590 110854           break;
110591         -      case 289: /* tridxby ::= NOT INDEXED */
       110855  +      case 287: /* tridxby ::= NOT INDEXED */
110592 110856   {
110593 110857     sqlite3ErrorMsg(pParse,
110594 110858           "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
110595 110859           "within triggers");
110596 110860   }
110597 110861           break;
110598         -      case 290: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
110599         -{ yygotominor.yy203 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy322, yymsp[0].minor.yy314, yymsp[-5].minor.yy210); }
110600         -        break;
110601         -      case 291: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt VALUES LP itemlist RP */
110602         -{yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy384, yymsp[-1].minor.yy322, 0, yymsp[-7].minor.yy210);}
110603         -        break;
110604         -      case 292: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */
110605         -{yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy384, 0, yymsp[0].minor.yy387, yymsp[-4].minor.yy210);}
110606         -        break;
110607         -      case 293: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
110608         -{yygotominor.yy203 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy314);}
110609         -        break;
110610         -      case 294: /* trigger_cmd ::= select */
110611         -{yygotominor.yy203 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy387); }
110612         -        break;
110613         -      case 295: /* expr ::= RAISE LP IGNORE RP */
       110862  +      case 288: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
       110863  +{ yygotominor.yy327 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy442, yymsp[0].minor.yy122, yymsp[-5].minor.yy258); }
       110864  +        break;
       110865  +      case 289: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist */
       110866  +{yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, yymsp[0].minor.yy487.pList, yymsp[0].minor.yy487.pSelect, yymsp[-4].minor.yy258);}
       110867  +        break;
       110868  +      case 290: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */
       110869  +{yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, 0, yymsp[0].minor.yy159, yymsp[-4].minor.yy258);}
       110870  +        break;
       110871  +      case 291: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
       110872  +{yygotominor.yy327 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy122);}
       110873  +        break;
       110874  +      case 292: /* trigger_cmd ::= select */
       110875  +{yygotominor.yy327 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy159); }
       110876  +        break;
       110877  +      case 293: /* expr ::= RAISE LP IGNORE RP */
       110878  +{
       110879  +  yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0); 
       110880  +  if( yygotominor.yy342.pExpr ){
       110881  +    yygotominor.yy342.pExpr->affinity = OE_Ignore;
       110882  +  }
       110883  +  yygotominor.yy342.zStart = yymsp[-3].minor.yy0.z;
       110884  +  yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
       110885  +}
       110886  +        break;
       110887  +      case 294: /* expr ::= RAISE LP raisetype COMMA nm RP */
       110888  +{
       110889  +  yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0); 
       110890  +  if( yygotominor.yy342.pExpr ) {
       110891  +    yygotominor.yy342.pExpr->affinity = (char)yymsp[-3].minor.yy392;
       110892  +  }
       110893  +  yygotominor.yy342.zStart = yymsp[-5].minor.yy0.z;
       110894  +  yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
       110895  +}
       110896  +        break;
       110897  +      case 295: /* raisetype ::= ROLLBACK */
       110898  +{yygotominor.yy392 = OE_Rollback;}
       110899  +        break;
       110900  +      case 297: /* raisetype ::= FAIL */
       110901  +{yygotominor.yy392 = OE_Fail;}
       110902  +        break;
       110903  +      case 298: /* cmd ::= DROP TRIGGER ifexists fullname */
110614 110904   {
110615         -  yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0); 
110616         -  if( yygotominor.yy118.pExpr ){
110617         -    yygotominor.yy118.pExpr->affinity = OE_Ignore;
110618         -  }
110619         -  yygotominor.yy118.zStart = yymsp[-3].minor.yy0.z;
110620         -  yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
       110905  +  sqlite3DropTrigger(pParse,yymsp[0].minor.yy347,yymsp[-1].minor.yy392);
110621 110906   }
110622 110907           break;
110623         -      case 296: /* expr ::= RAISE LP raisetype COMMA nm RP */
       110908  +      case 299: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
110624 110909   {
110625         -  yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0); 
110626         -  if( yygotominor.yy118.pExpr ) {
110627         -    yygotominor.yy118.pExpr->affinity = (char)yymsp[-3].minor.yy4;
110628         -  }
110629         -  yygotominor.yy118.zStart = yymsp[-5].minor.yy0.z;
110630         -  yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
       110910  +  sqlite3Attach(pParse, yymsp[-3].minor.yy342.pExpr, yymsp[-1].minor.yy342.pExpr, yymsp[0].minor.yy122);
110631 110911   }
110632 110912           break;
110633         -      case 297: /* raisetype ::= ROLLBACK */
110634         -{yygotominor.yy4 = OE_Rollback;}
110635         -        break;
110636         -      case 299: /* raisetype ::= FAIL */
110637         -{yygotominor.yy4 = OE_Fail;}
110638         -        break;
110639         -      case 300: /* cmd ::= DROP TRIGGER ifexists fullname */
       110913  +      case 300: /* cmd ::= DETACH database_kw_opt expr */
110640 110914   {
110641         -  sqlite3DropTrigger(pParse,yymsp[0].minor.yy259,yymsp[-1].minor.yy4);
       110915  +  sqlite3Detach(pParse, yymsp[0].minor.yy342.pExpr);
110642 110916   }
110643 110917           break;
110644         -      case 301: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
110645         -{
110646         -  sqlite3Attach(pParse, yymsp[-3].minor.yy118.pExpr, yymsp[-1].minor.yy118.pExpr, yymsp[0].minor.yy314);
110647         -}
110648         -        break;
110649         -      case 302: /* cmd ::= DETACH database_kw_opt expr */
110650         -{
110651         -  sqlite3Detach(pParse, yymsp[0].minor.yy118.pExpr);
110652         -}
110653         -        break;
110654         -      case 307: /* cmd ::= REINDEX */
       110918  +      case 305: /* cmd ::= REINDEX */
110655 110919   {sqlite3Reindex(pParse, 0, 0);}
110656 110920           break;
110657         -      case 308: /* cmd ::= REINDEX nm dbnm */
       110921  +      case 306: /* cmd ::= REINDEX nm dbnm */
110658 110922   {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
110659 110923           break;
110660         -      case 309: /* cmd ::= ANALYZE */
       110924  +      case 307: /* cmd ::= ANALYZE */
110661 110925   {sqlite3Analyze(pParse, 0, 0);}
110662 110926           break;
110663         -      case 310: /* cmd ::= ANALYZE nm dbnm */
       110927  +      case 308: /* cmd ::= ANALYZE nm dbnm */
110664 110928   {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
110665 110929           break;
110666         -      case 311: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
       110930  +      case 309: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
110667 110931   {
110668         -  sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy259,&yymsp[0].minor.yy0);
       110932  +  sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy347,&yymsp[0].minor.yy0);
110669 110933   }
110670 110934           break;
110671         -      case 312: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
       110935  +      case 310: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
110672 110936   {
110673 110937     sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
110674 110938   }
110675 110939           break;
110676         -      case 313: /* add_column_fullname ::= fullname */
       110940  +      case 311: /* add_column_fullname ::= fullname */
110677 110941   {
110678 110942     pParse->db->lookaside.bEnabled = 0;
110679         -  sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy259);
       110943  +  sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy347);
110680 110944   }
110681 110945           break;
110682         -      case 316: /* cmd ::= create_vtab */
       110946  +      case 314: /* cmd ::= create_vtab */
110683 110947   {sqlite3VtabFinishParse(pParse,0);}
110684 110948           break;
110685         -      case 317: /* cmd ::= create_vtab LP vtabarglist RP */
       110949  +      case 315: /* cmd ::= create_vtab LP vtabarglist RP */
110686 110950   {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
110687 110951           break;
110688         -      case 318: /* create_vtab ::= createkw VIRTUAL TABLE nm dbnm USING nm */
       110952  +      case 316: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
110689 110953   {
110690         -    sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
       110954  +    sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy392);
110691 110955   }
110692 110956           break;
110693         -      case 321: /* vtabarg ::= */
       110957  +      case 319: /* vtabarg ::= */
110694 110958   {sqlite3VtabArgInit(pParse);}
110695 110959           break;
110696         -      case 323: /* vtabargtoken ::= ANY */
110697         -      case 324: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==324);
110698         -      case 325: /* lp ::= LP */ yytestcase(yyruleno==325);
       110960  +      case 321: /* vtabargtoken ::= ANY */
       110961  +      case 322: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==322);
       110962  +      case 323: /* lp ::= LP */ yytestcase(yyruleno==323);
110699 110963   {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
110700 110964           break;
110701 110965         default:
110702 110966         /* (0) input ::= cmdlist */ yytestcase(yyruleno==0);
110703 110967         /* (1) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==1);
110704 110968         /* (2) cmdlist ::= ecmd */ yytestcase(yyruleno==2);
110705 110969         /* (3) ecmd ::= SEMI */ yytestcase(yyruleno==3);
................................................................................
110720 110984         /* (55) carg ::= CONSTRAINT nm ccons */ yytestcase(yyruleno==55);
110721 110985         /* (56) carg ::= ccons */ yytestcase(yyruleno==56);
110722 110986         /* (62) ccons ::= NULL onconf */ yytestcase(yyruleno==62);
110723 110987         /* (90) conslist ::= conslist COMMA tcons */ yytestcase(yyruleno==90);
110724 110988         /* (91) conslist ::= conslist tcons */ yytestcase(yyruleno==91);
110725 110989         /* (92) conslist ::= tcons */ yytestcase(yyruleno==92);
110726 110990         /* (93) tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==93);
110727         -      /* (268) plus_opt ::= PLUS */ yytestcase(yyruleno==268);
110728         -      /* (269) plus_opt ::= */ yytestcase(yyruleno==269);
110729         -      /* (279) foreach_clause ::= */ yytestcase(yyruleno==279);
110730         -      /* (280) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==280);
110731         -      /* (287) tridxby ::= */ yytestcase(yyruleno==287);
110732         -      /* (305) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==305);
110733         -      /* (306) database_kw_opt ::= */ yytestcase(yyruleno==306);
110734         -      /* (314) kwcolumn_opt ::= */ yytestcase(yyruleno==314);
110735         -      /* (315) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==315);
110736         -      /* (319) vtabarglist ::= vtabarg */ yytestcase(yyruleno==319);
110737         -      /* (320) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==320);
110738         -      /* (322) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==322);
110739         -      /* (326) anylist ::= */ yytestcase(yyruleno==326);
110740         -      /* (327) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==327);
110741         -      /* (328) anylist ::= anylist ANY */ yytestcase(yyruleno==328);
       110991  +      /* (277) foreach_clause ::= */ yytestcase(yyruleno==277);
       110992  +      /* (278) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==278);
       110993  +      /* (285) tridxby ::= */ yytestcase(yyruleno==285);
       110994  +      /* (303) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==303);
       110995  +      /* (304) database_kw_opt ::= */ yytestcase(yyruleno==304);
       110996  +      /* (312) kwcolumn_opt ::= */ yytestcase(yyruleno==312);
       110997  +      /* (313) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==313);
       110998  +      /* (317) vtabarglist ::= vtabarg */ yytestcase(yyruleno==317);
       110999  +      /* (318) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==318);
       111000  +      /* (320) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==320);
       111001  +      /* (324) anylist ::= */ yytestcase(yyruleno==324);
       111002  +      /* (325) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==325);
       111003  +      /* (326) anylist ::= anylist ANY */ yytestcase(yyruleno==326);
110742 111004           break;
110743 111005     };
110744 111006     yygoto = yyRuleInfo[yyruleno].lhs;
110745 111007     yysize = yyRuleInfo[yyruleno].nrhs;
110746 111008     yypParser->yyidx -= yysize;
110747 111009     yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
110748 111010     if( yyact < YYNSTATE ){
................................................................................
113019 113281       sqlite3_free(db->lookaside.pStart);
113020 113282     }
113021 113283     sqlite3_free(db);
113022 113284     return SQLITE_OK;
113023 113285   }
113024 113286   
113025 113287   /*
113026         -** Rollback all database files.
       113288  +** Rollback all database files.  If tripCode is not SQLITE_OK, then
       113289  +** any open cursors are invalidated ("tripped" - as in "tripping a circuit
       113290  +** breaker") and made to return tripCode if there are any further
       113291  +** attempts to use that cursor.
113027 113292   */
113028         -SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db){
       113293  +SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){
113029 113294     int i;
113030 113295     int inTrans = 0;
113031 113296     assert( sqlite3_mutex_held(db->mutex) );
113032 113297     sqlite3BeginBenignMalloc();
113033 113298     for(i=0; i<db->nDb; i++){
113034         -    if( db->aDb[i].pBt ){
113035         -      if( sqlite3BtreeIsInTrans(db->aDb[i].pBt) ){
       113299  +    Btree *p = db->aDb[i].pBt;
       113300  +    if( p ){
       113301  +      if( sqlite3BtreeIsInTrans(p) ){
113036 113302           inTrans = 1;
113037 113303         }
113038         -      sqlite3BtreeRollback(db->aDb[i].pBt);
       113304  +      sqlite3BtreeRollback(p, tripCode);
113039 113305         db->aDb[i].inTrans = 0;
113040 113306       }
113041 113307     }
113042 113308     sqlite3VtabRollback(db);
113043 113309     sqlite3EndBenignMalloc();
113044 113310   
113045 113311     if( db->flags&SQLITE_InternChanges ){
................................................................................
113086 113352       /* SQLITE_MISUSE      */ "library routine called out of sequence",
113087 113353       /* SQLITE_NOLFS       */ "large file support is disabled",
113088 113354       /* SQLITE_AUTH        */ "authorization denied",
113089 113355       /* SQLITE_FORMAT      */ "auxiliary database format error",
113090 113356       /* SQLITE_RANGE       */ "bind or column index out of range",
113091 113357       /* SQLITE_NOTADB      */ "file is encrypted or is not a database",
113092 113358     };
113093         -  rc &= 0xff;
113094         -  if( ALWAYS(rc>=0) && rc<(int)(sizeof(aMsg)/sizeof(aMsg[0])) && aMsg[rc]!=0 ){
113095         -    return aMsg[rc];
113096         -  }else{
113097         -    return "unknown error";
       113359  +  const char *zErr = "unknown error";
       113360  +  switch( rc ){
       113361  +    case SQLITE_ABORT_ROLLBACK: {
       113362  +      zErr = "abort due to ROLLBACK";
       113363  +      break;
       113364  +    }
       113365  +    default: {
       113366  +      rc &= 0xff;
       113367  +      if( ALWAYS(rc>=0) && rc<ArraySize(aMsg) && aMsg[rc]!=0 ){
       113368  +        zErr = aMsg[rc];
       113369  +      }
       113370  +      break;
       113371  +    }
113098 113372     }
       113373  +  return zErr;
113099 113374   }
113100 113375   
113101 113376   /*
113102 113377   ** This routine implements a busy callback that sleeps and tries
113103 113378   ** again until a timeout value is reached.  The timeout value is
113104 113379   ** an integer number of milliseconds passed in as the first
113105 113380   ** argument.
................................................................................
113469 113744     db->xProfile = xProfile;
113470 113745     db->pProfileArg = pArg;
113471 113746     sqlite3_mutex_leave(db->mutex);
113472 113747     return pOld;
113473 113748   }
113474 113749   #endif /* SQLITE_OMIT_TRACE */
113475 113750   
113476         -/*** EXPERIMENTAL ***
113477         -**
113478         -** Register a function to be invoked when a transaction comments.
       113751  +/*
       113752  +** Register a function to be invoked when a transaction commits.
113479 113753   ** If the invoked function returns non-zero, then the commit becomes a
113480 113754   ** rollback.
113481 113755   */
113482 113756   SQLITE_API void *sqlite3_commit_hook(
113483 113757     sqlite3 *db,              /* Attach the hook to this database */
113484 113758     int (*xCallback)(void*),  /* Function to invoke on each commit */
113485 113759     void *pArg                /* Argument to the function */
................................................................................
114862 115136   }
114863 115137   
114864 115138   /*
114865 115139   ** Invoke the xFileControl method on a particular database.
114866 115140   */
114867 115141   SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
114868 115142     int rc = SQLITE_ERROR;
114869         -  int iDb;
       115143  +  Btree *pBtree;
       115144  +
114870 115145     sqlite3_mutex_enter(db->mutex);
114871         -  if( zDbName==0 ){
114872         -    iDb = 0;
114873         -  }else{
114874         -    for(iDb=0; iDb<db->nDb; iDb++){
114875         -      if( strcmp(db->aDb[iDb].zName, zDbName)==0 ) break;
114876         -    }
114877         -  }
114878         -  if( iDb<db->nDb ){
114879         -    Btree *pBtree = db->aDb[iDb].pBt;
114880         -    if( pBtree ){
114881         -      Pager *pPager;
114882         -      sqlite3_file *fd;
114883         -      sqlite3BtreeEnter(pBtree);
114884         -      pPager = sqlite3BtreePager(pBtree);
114885         -      assert( pPager!=0 );
114886         -      fd = sqlite3PagerFile(pPager);
114887         -      assert( fd!=0 );
114888         -      if( op==SQLITE_FCNTL_FILE_POINTER ){
114889         -        *(sqlite3_file**)pArg = fd;
114890         -        rc = SQLITE_OK;
114891         -      }else if( fd->pMethods ){
114892         -        rc = sqlite3OsFileControl(fd, op, pArg);
114893         -      }else{
114894         -        rc = SQLITE_NOTFOUND;
114895         -      }
114896         -      sqlite3BtreeLeave(pBtree);
114897         -    }
       115146  +  pBtree = sqlite3DbNameToBtree(db, zDbName);
       115147  +  if( pBtree ){
       115148  +    Pager *pPager;
       115149  +    sqlite3_file *fd;
       115150  +    sqlite3BtreeEnter(pBtree);
       115151  +    pPager = sqlite3BtreePager(pBtree);
       115152  +    assert( pPager!=0 );
       115153  +    fd = sqlite3PagerFile(pPager);
       115154  +    assert( fd!=0 );
       115155  +    if( op==SQLITE_FCNTL_FILE_POINTER ){
       115156  +      *(sqlite3_file**)pArg = fd;
       115157  +      rc = SQLITE_OK;
       115158  +    }else if( fd->pMethods ){
       115159  +      rc = sqlite3OsFileControl(fd, op, pArg);
       115160  +    }else{
       115161  +      rc = SQLITE_NOTFOUND;
       115162  +    }
       115163  +    sqlite3BtreeLeave(pBtree);
114898 115164     }
114899 115165     sqlite3_mutex_leave(db->mutex);
114900 115166     return rc;   
114901 115167   }
114902 115168   
114903 115169   /*
114904 115170   ** Interface to the testing logic.
................................................................................
115165 115431   }
115166 115432   
115167 115433   /*
115168 115434   ** Return a boolean value for a query parameter.
115169 115435   */
115170 115436   SQLITE_API int sqlite3_uri_boolean(const char *zFilename, const char *zParam, int bDflt){
115171 115437     const char *z = sqlite3_uri_parameter(zFilename, zParam);
115172         -  return z ? sqlite3GetBoolean(z) : (bDflt!=0);
       115438  +  bDflt = bDflt!=0;
       115439  +  return z ? sqlite3GetBoolean(z, bDflt) : bDflt;
115173 115440   }
115174 115441   
115175 115442   /*
115176 115443   ** Return a 64-bit integer value for a query parameter.
115177 115444   */
115178 115445   SQLITE_API sqlite3_int64 sqlite3_uri_int64(
115179 115446     const char *zFilename,    /* Filename as passed to xOpen */
................................................................................
115183 115450     const char *z = sqlite3_uri_parameter(zFilename, zParam);
115184 115451     sqlite3_int64 v;
115185 115452     if( z && sqlite3Atoi64(z, &v, sqlite3Strlen30(z), SQLITE_UTF8)==SQLITE_OK ){
115186 115453       bDflt = v;
115187 115454     }
115188 115455     return bDflt;
115189 115456   }
       115457  +
       115458  +/*
       115459  +** Return the Btree pointer identified by zDbName.  Return NULL if not found.
       115460  +*/
       115461  +SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
       115462  +  int i;
       115463  +  for(i=0; i<db->nDb; i++){
       115464  +    if( db->aDb[i].pBt
       115465  +     && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0)
       115466  +    ){
       115467  +      return db->aDb[i].pBt;
       115468  +    }
       115469  +  }
       115470  +  return 0;
       115471  +}
115190 115472   
115191 115473   /*
115192 115474   ** Return the filename of the database associated with a database
115193 115475   ** connection.
115194 115476   */
115195 115477   SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
115196         -  int i;
115197         -  for(i=0; i<db->nDb; i++){
115198         -    if( db->aDb[i].pBt && sqlite3StrICmp(zDbName, db->aDb[i].zName)==0 ){
115199         -      return sqlite3BtreeGetFilename(db->aDb[i].pBt);
115200         -    }
115201         -  }
115202         -  return 0;
       115478  +  Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
       115479  +  return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
       115480  +}
       115481  +
       115482  +/*
       115483  +** Return 1 if database is read-only or 0 if read/write.  Return -1 if
       115484  +** no such database exists.
       115485  +*/
       115486  +SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
       115487  +  Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
       115488  +  return pBt ? sqlite3PagerIsreadonly(sqlite3BtreePager(pBt)) : -1;
115203 115489   }
115204 115490   
115205 115491   /************** End of main.c ************************************************/
115206 115492   /************** Begin file notify.c ******************************************/
115207 115493   /*
115208 115494   ** 2009 March 3
115209 115495   **
................................................................................
115821 116107   ** index when a document is deleted or updated.  For deletions, we
115822 116108   ** write an empty doclist (varint(docid) varint(POS_END)), for updates
115823 116109   ** we simply write the new doclist.  Segment merges overwrite older
115824 116110   ** data for a particular docid with newer data, so deletes or updates
115825 116111   ** will eventually overtake the earlier data and knock it out.  The
115826 116112   ** query logic likewise merges doclists so that newer data knocks out
115827 116113   ** older data.
115828         -**
115829         -** TODO(shess) Provide a VACUUM type operation to clear out all
115830         -** deletions and duplications.  This would basically be a forced merge
115831         -** into a single segment.
115832 116114   */
115833 116115   
115834 116116   /************** Include fts3Int.h in the middle of fts3.c ********************/
115835 116117   /************** Begin file fts3Int.h *****************************************/
115836 116118   /*
115837 116119   ** 2009 Nov 12
115838 116120   **
................................................................................
115920 116202   typedef struct sqlite3_tokenizer_module sqlite3_tokenizer_module;
115921 116203   typedef struct sqlite3_tokenizer sqlite3_tokenizer;
115922 116204   typedef struct sqlite3_tokenizer_cursor sqlite3_tokenizer_cursor;
115923 116205   
115924 116206   struct sqlite3_tokenizer_module {
115925 116207   
115926 116208     /*
115927         -  ** Structure version. Should always be set to 0.
       116209  +  ** Structure version. Should always be set to 0 or 1.
115928 116210     */
115929 116211     int iVersion;
115930 116212   
115931 116213     /*
115932 116214     ** Create a new tokenizer. The values in the argv[] array are the
115933 116215     ** arguments passed to the "tokenizer" clause of the CREATE VIRTUAL
115934 116216     ** TABLE statement that created the fts3 table. For example, if
................................................................................
116001 116283     int (*xNext)(
116002 116284       sqlite3_tokenizer_cursor *pCursor,   /* Tokenizer cursor */
116003 116285       const char **ppToken, int *pnBytes,  /* OUT: Normalized text for token */
116004 116286       int *piStartOffset,  /* OUT: Byte offset of token in input buffer */
116005 116287       int *piEndOffset,    /* OUT: Byte offset of end of token in input buffer */
116006 116288       int *piPosition      /* OUT: Number of tokens returned before this one */
116007 116289     );
       116290  +
       116291  +  /***********************************************************************
       116292  +  ** Methods below this point are only available if iVersion>=1.
       116293  +  */
       116294  +
       116295  +  /* 
       116296  +  ** Configure the language id of a tokenizer cursor.
       116297  +  */
       116298  +  int (*xLanguageid)(sqlite3_tokenizer_cursor *pCsr, int iLangid);
116008 116299   };
116009 116300   
116010 116301   struct sqlite3_tokenizer {
116011 116302     const sqlite3_tokenizer_module *pModule;  /* The module for this tokenizer */
116012 116303     /* Tokenizer implementations will typically add additional fields */
116013 116304   };
116014 116305   
................................................................................
116292 116583     sqlite3 *db;                    /* The database connection */
116293 116584     const char *zDb;                /* logical database name */
116294 116585     const char *zName;              /* virtual table name */
116295 116586     int nColumn;                    /* number of named columns in virtual table */
116296 116587     char **azColumn;                /* column names.  malloced */
116297 116588     sqlite3_tokenizer *pTokenizer;  /* tokenizer for inserts and queries */
116298 116589     char *zContentTbl;              /* content=xxx option, or NULL */
       116590  +  char *zLanguageid;              /* languageid=xxx option, or NULL */
116299 116591   
116300 116592     /* Precompiled statements used by the implementation. Each of these 
116301 116593     ** statements is run and reset within a single virtual table API call. 
116302 116594     */
116303         -  sqlite3_stmt *aStmt[27];
       116595  +  sqlite3_stmt *aStmt[28];
116304 116596   
116305 116597     char *zReadExprlist;
116306 116598     char *zWriteExprlist;
116307 116599   
116308 116600     int nNodeSize;                  /* Soft limit for node size */
116309 116601     u8 bHasStat;                    /* True if %_stat table exists */
116310 116602     u8 bHasDocsize;                 /* True if %_docsize table exists */
................................................................................
116311 116603     u8 bDescIdx;                    /* True if doclists are in reverse order */
116312 116604     int nPgsz;                      /* Page size for host database */
116313 116605     char *zSegmentsTbl;             /* Name of %_segments table */
116314 116606     sqlite3_blob *pSegments;        /* Blob handle open on %_segments table */
116315 116607   
116316 116608     /* TODO: Fix the first paragraph of this comment.
116317 116609     **
116318         -  ** The following hash table is used to buffer pending index updates during
116319         -  ** transactions. Variable nPendingData estimates the memory size of the 
116320         -  ** pending data, including hash table overhead, but not malloc overhead. 
116321         -  ** When nPendingData exceeds nMaxPendingData, the buffer is flushed 
116322         -  ** automatically. Variable iPrevDocid is the docid of the most recently
116323         -  ** inserted record.
       116610  +  ** The following array of hash tables is used to buffer pending index 
       116611  +  ** updates during transactions. Variable nPendingData estimates the memory 
       116612  +  ** size of the pending data, including hash table overhead, not including
       116613  +  ** malloc overhead.  When nPendingData exceeds nMaxPendingData, the buffer 
       116614  +  ** is flushed automatically. Variable iPrevDocid is the docid of the most 
       116615  +  ** recently inserted record.
116324 116616     **
116325 116617     ** A single FTS4 table may have multiple full-text indexes. For each index
116326 116618     ** there is an entry in the aIndex[] array. Index 0 is an index of all the
116327 116619     ** terms that appear in the document set. Each subsequent index in aIndex[]
116328 116620     ** is an index of prefixes of a specific length.
116329 116621     */
116330 116622     int nIndex;                     /* Size of aIndex[] */
................................................................................
116331 116623     struct Fts3Index {
116332 116624       int nPrefix;                  /* Prefix length (0 for main terms index) */
116333 116625       Fts3Hash hPending;            /* Pending terms table for this index */
116334 116626     } *aIndex;
116335 116627     int nMaxPendingData;            /* Max pending data before flush to disk */
116336 116628     int nPendingData;               /* Current bytes of pending data */
116337 116629     sqlite_int64 iPrevDocid;        /* Docid of most recently inserted document */
       116630  +  int iPrevLangid;                /* Langid of recently inserted document */
116338 116631   
116339 116632   #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
116340 116633     /* State variables used for validating that the transaction control
116341 116634     ** methods of the virtual table are called at appropriate times.  These
116342         -  ** values do not contribution to the FTS computation; they are used for
116343         -  ** verifying the SQLite core.
       116635  +  ** values do not contribute to FTS functionality; they are used for
       116636  +  ** verifying the operation of the SQLite core.
116344 116637     */
116345 116638     int inTransaction;     /* True after xBegin but before xCommit/xRollback */
116346 116639     int mxSavepoint;       /* Largest valid xSavepoint integer */
116347 116640   #endif
116348 116641   };
116349 116642   
116350 116643   /*
................................................................................
116355 116648   struct Fts3Cursor {
116356 116649     sqlite3_vtab_cursor base;       /* Base class used by SQLite core */
116357 116650     i16 eSearch;                    /* Search strategy (see below) */
116358 116651     u8 isEof;                       /* True if at End Of Results */
116359 116652     u8 isRequireSeek;               /* True if must seek pStmt to %_content row */
116360 116653     sqlite3_stmt *pStmt;            /* Prepared statement in use by the cursor */
116361 116654     Fts3Expr *pExpr;                /* Parsed MATCH query string */
       116655  +  int iLangid;                    /* Language being queried for */
116362 116656     int nPhrase;                    /* Number of matchable phrases in query */
116363 116657     Fts3DeferredToken *pDeferred;   /* Deferred search tokens, if any */
116364 116658     sqlite3_int64 iPrevId;          /* Previous id read from aDoclist */
116365 116659     char *pNextId;                  /* Pointer into the body of aDoclist */
116366 116660     char *aDoclist;                 /* List of docids for full-text queries */
116367 116661     int nDoclist;                   /* Size of buffer at aDoclist */
116368 116662     u8 bDesc;                       /* True to sort in descending order */
................................................................................
116501 116795   
116502 116796   
116503 116797   /* fts3_write.c */
116504 116798   SQLITE_PRIVATE int sqlite3Fts3UpdateMethod(sqlite3_vtab*,int,sqlite3_value**,sqlite3_int64*);
116505 116799   SQLITE_PRIVATE int sqlite3Fts3PendingTermsFlush(Fts3Table *);
116506 116800   SQLITE_PRIVATE void sqlite3Fts3PendingTermsClear(Fts3Table *);
116507 116801   SQLITE_PRIVATE int sqlite3Fts3Optimize(Fts3Table *);
116508         -SQLITE_PRIVATE int sqlite3Fts3SegReaderNew(int, sqlite3_int64,
       116802  +SQLITE_PRIVATE int sqlite3Fts3SegReaderNew(int, int, sqlite3_int64,
116509 116803     sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**);
116510 116804   SQLITE_PRIVATE int sqlite3Fts3SegReaderPending(
116511 116805     Fts3Table*,int,const char*,int,int,Fts3SegReader**);
116512 116806   SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *);
116513         -SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, sqlite3_stmt **);
       116807  +SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, int, sqlite3_stmt **);
116514 116808   SQLITE_PRIVATE int sqlite3Fts3ReadLock(Fts3Table *);
116515 116809   SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);
116516 116810   
116517 116811   SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
116518 116812   SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);
116519 116813   
116520 116814   SQLITE_PRIVATE void sqlite3Fts3FreeDeferredTokens(Fts3Cursor *);
................................................................................
116527 116821   #define FTS3_SEGCURSOR_PENDING        -1
116528 116822   #define FTS3_SEGCURSOR_ALL            -2
116529 116823   
116530 116824   SQLITE_PRIVATE int sqlite3Fts3SegReaderStart(Fts3Table*, Fts3MultiSegReader*, Fts3SegFilter*);
116531 116825   SQLITE_PRIVATE int sqlite3Fts3SegReaderStep(Fts3Table *, Fts3MultiSegReader *);
116532 116826   SQLITE_PRIVATE void sqlite3Fts3SegReaderFinish(Fts3MultiSegReader *);
116533 116827   
116534         -SQLITE_PRIVATE int sqlite3Fts3SegReaderCursor(
116535         -    Fts3Table *, int, int, const char *, int, int, int, Fts3MultiSegReader *);
       116828  +SQLITE_PRIVATE int sqlite3Fts3SegReaderCursor(Fts3Table *, 
       116829  +    int, int, int, const char *, int, int, int, Fts3MultiSegReader *);
116536 116830   
116537 116831   /* Flags allowed as part of the 4th argument to SegmentReaderIterate() */
116538 116832   #define FTS3_SEGMENT_REQUIRE_POS   0x00000001
116539 116833   #define FTS3_SEGMENT_IGNORE_EMPTY  0x00000002
116540 116834   #define FTS3_SEGMENT_COLUMN_FILTER 0x00000004
116541 116835   #define FTS3_SEGMENT_PREFIX        0x00000008
116542 116836   #define FTS3_SEGMENT_SCAN          0x00000010
................................................................................
116595 116889   SQLITE_PRIVATE void sqlite3Fts3Offsets(sqlite3_context*, Fts3Cursor*);
116596 116890   SQLITE_PRIVATE void sqlite3Fts3Snippet(sqlite3_context *, Fts3Cursor *, const char *,
116597 116891     const char *, const char *, int, int
116598 116892   );
116599 116893   SQLITE_PRIVATE void sqlite3Fts3Matchinfo(sqlite3_context *, Fts3Cursor *, const char *);
116600 116894   
116601 116895   /* fts3_expr.c */
116602         -SQLITE_PRIVATE int sqlite3Fts3ExprParse(sqlite3_tokenizer *, 
       116896  +SQLITE_PRIVATE int sqlite3Fts3ExprParse(sqlite3_tokenizer *, int,
116603 116897     char **, int, int, int, const char *, int, Fts3Expr **
116604 116898   );
116605 116899   SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
116606 116900   #ifdef SQLITE_TEST
116607 116901   SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
116608 116902   SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
116609 116903   #endif
       116904  +
       116905  +SQLITE_PRIVATE int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int,
       116906  +  sqlite3_tokenizer_cursor **
       116907  +);
116610 116908   
116611 116909   /* fts3_aux.c */
116612 116910   SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db);
116613 116911   
116614 116912   SQLITE_PRIVATE void sqlite3Fts3EvalPhraseCleanup(Fts3Phrase *);
116615 116913   
116616 116914   SQLITE_PRIVATE int sqlite3Fts3MsrIncrStart(
................................................................................
116798 117096     for(i=0; i<SizeofArray(p->aStmt); i++){
116799 117097       sqlite3_finalize(p->aStmt[i]);
116800 117098     }
116801 117099     sqlite3_free(p->zSegmentsTbl);
116802 117100     sqlite3_free(p->zReadExprlist);
116803 117101     sqlite3_free(p->zWriteExprlist);
116804 117102     sqlite3_free(p->zContentTbl);
       117103  +  sqlite3_free(p->zLanguageid);
116805 117104   
116806 117105     /* Invoke the tokenizer destructor to free the tokenizer. */
116807 117106     p->pTokenizer->pModule->xDestroy(p->pTokenizer);
116808 117107   
116809 117108     sqlite3_free(p);
116810 117109     return SQLITE_OK;
116811 117110   }
................................................................................
116874 117173   */
116875 117174   static void fts3DeclareVtab(int *pRc, Fts3Table *p){
116876 117175     if( *pRc==SQLITE_OK ){
116877 117176       int i;                        /* Iterator variable */
116878 117177       int rc;                       /* Return code */
116879 117178       char *zSql;                   /* SQL statement passed to declare_vtab() */
116880 117179       char *zCols;                  /* List of user defined columns */
       117180  +    const char *zLanguageid;
116881 117181   
       117182  +    zLanguageid = (p->zLanguageid ? p->zLanguageid : "__langid");
116882 117183       sqlite3_vtab_config(p->db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
116883 117184   
116884 117185       /* Create a list of user columns for the virtual table */
116885 117186       zCols = sqlite3_mprintf("%Q, ", p->azColumn[0]);
116886 117187       for(i=1; zCols && i<p->nColumn; i++){
116887 117188         zCols = sqlite3_mprintf("%z%Q, ", zCols, p->azColumn[i]);
116888 117189       }
116889 117190   
116890 117191       /* Create the whole "CREATE TABLE" statement to pass to SQLite */
116891 117192       zSql = sqlite3_mprintf(
116892         -        "CREATE TABLE x(%s %Q HIDDEN, docid HIDDEN)", zCols, p->zName
       117193  +        "CREATE TABLE x(%s %Q HIDDEN, docid HIDDEN, %Q HIDDEN)", 
       117194  +        zCols, p->zName, zLanguageid
116893 117195       );
116894 117196       if( !zCols || !zSql ){
116895 117197         rc = SQLITE_NOMEM;
116896 117198       }else{
116897 117199         rc = sqlite3_declare_vtab(p->db, zSql);
116898 117200       }
116899 117201   
................................................................................
116914 117216   */
116915 117217   static int fts3CreateTables(Fts3Table *p){
116916 117218     int rc = SQLITE_OK;             /* Return code */
116917 117219     int i;                          /* Iterator variable */
116918 117220     sqlite3 *db = p->db;            /* The database connection */
116919 117221   
116920 117222     if( p->zContentTbl==0 ){
       117223  +    const char *zLanguageid = p->zLanguageid;
116921 117224       char *zContentCols;           /* Columns of %_content table */
116922 117225   
116923 117226       /* Create a list of user columns for the content table */
116924 117227       zContentCols = sqlite3_mprintf("docid INTEGER PRIMARY KEY");
116925 117228       for(i=0; zContentCols && i<p->nColumn; i++){
116926 117229         char *z = p->azColumn[i];
116927 117230         zContentCols = sqlite3_mprintf("%z, 'c%d%q'", zContentCols, i, z);
116928 117231       }
       117232  +    if( zLanguageid && zContentCols ){
       117233  +      zContentCols = sqlite3_mprintf("%z, langid", zContentCols, zLanguageid);
       117234  +    }
116929 117235       if( zContentCols==0 ) rc = SQLITE_NOMEM;
116930 117236     
116931 117237       /* Create the content table */
116932 117238       fts3DbExec(&rc, db, 
116933 117239          "CREATE TABLE %Q.'%q_content'(%s)",
116934 117240          p->zDb, p->zName, zContentCols
116935 117241       );
................................................................................
117066 117372   ** The pointer returned points to memory obtained from sqlite3_malloc(). It
117067 117373   ** is the callers responsibility to call sqlite3_free() to release this
117068 117374   ** memory.
117069 117375   */
117070 117376   static char *fts3QuoteId(char const *zInput){
117071 117377     int nRet;
117072 117378     char *zRet;
117073         -  nRet = 2 + strlen(zInput)*2 + 1;
       117379  +  nRet = 2 + (int)strlen(zInput)*2 + 1;
117074 117380     zRet = sqlite3_malloc(nRet);
117075 117381     if( zRet ){
117076 117382       int i;
117077 117383       char *z = zRet;
117078 117384       *(z++) = '"';
117079 117385       for(i=0; zInput[i]; i++){
117080 117386         if( zInput[i]=='"' ) *(z++) = '"';
................................................................................
117121 117427       }else{
117122 117428         zFree = zFunction = fts3QuoteId(zFunc);
117123 117429       }
117124 117430       fts3Appendf(pRc, &zRet, "docid");
117125 117431       for(i=0; i<p->nColumn; i++){
117126 117432         fts3Appendf(pRc, &zRet, ",%s(x.'c%d%q')", zFunction, i, p->azColumn[i]);
117127 117433       }
       117434  +    if( p->zLanguageid ){
       117435  +      fts3Appendf(pRc, &zRet, ", x.%Q", "langid");
       117436  +    }
117128 117437       sqlite3_free(zFree);
117129 117438     }else{
117130 117439       fts3Appendf(pRc, &zRet, "rowid");
117131 117440       for(i=0; i<p->nColumn; i++){
117132 117441         fts3Appendf(pRc, &zRet, ", x.'%q'", p->azColumn[i]);
117133 117442       }
       117443  +    if( p->zLanguageid ){
       117444  +      fts3Appendf(pRc, &zRet, ", x.%Q", p->zLanguageid);
       117445  +    }
117134 117446     }
117135         -  fts3Appendf(pRc, &zRet, "FROM '%q'.'%q%s' AS x", 
       117447  +  fts3Appendf(pRc, &zRet, " FROM '%q'.'%q%s' AS x", 
117136 117448         p->zDb,
117137 117449         (p->zContentTbl ? p->zContentTbl : p->zName),
117138 117450         (p->zContentTbl ? "" : "_content")
117139 117451     );
117140 117452     return zRet;
117141 117453   }
117142 117454   
................................................................................
117171 117483     }else{
117172 117484       zFree = zFunction = fts3QuoteId(zFunc);
117173 117485     }
117174 117486     fts3Appendf(pRc, &zRet, "?");
117175 117487     for(i=0; i<p->nColumn; i++){
117176 117488       fts3Appendf(pRc, &zRet, ",%s(?)", zFunction);
117177 117489     }
       117490  +  if( p->zLanguageid ){
       117491  +    fts3Appendf(pRc, &zRet, ", ?");
       117492  +  }
117178 117493     sqlite3_free(zFree);
117179 117494     return zRet;
117180 117495   }
117181 117496   
117182 117497   /*
117183 117498   ** This function interprets the string at (*pp) as a non-negative integer
117184 117499   ** value. It reads the integer and sets *pnOut to the value read, then 
................................................................................
117313 117628   
117314 117629       /* Loop through the returned columns. Set nStr to the number of bytes of
117315 117630       ** space required to store a copy of each column name, including the
117316 117631       ** nul-terminator byte.  */
117317 117632       nCol = sqlite3_column_count(pStmt);
117318 117633       for(i=0; i<nCol; i++){
117319 117634         const char *zCol = sqlite3_column_name(pStmt, i);
117320         -      nStr += strlen(zCol) + 1;
       117635  +      nStr += (int)strlen(zCol) + 1;
117321 117636       }
117322 117637   
117323 117638       /* Allocate and populate the array to return. */
117324 117639       azCol = (const char **)sqlite3_malloc(sizeof(char *) * nCol + nStr);
117325 117640       if( azCol==0 ){
117326 117641         rc = SQLITE_NOMEM;
117327 117642       }else{
117328 117643         char *p = (char *)&azCol[nCol];
117329 117644         for(i=0; i<nCol; i++){
117330 117645           const char *zCol = sqlite3_column_name(pStmt, i);
117331         -        int n = strlen(zCol)+1;
       117646  +        int n = (int)strlen(zCol)+1;
117332 117647           memcpy(p, zCol, n);
117333 117648           azCol[i] = p;
117334 117649           p += n;
117335 117650         }
117336 117651       }
117337 117652       sqlite3_finalize(pStmt);
117338 117653   
................................................................................
117386 117701     /* The results of parsing supported FTS4 key=value options: */
117387 117702     int bNoDocsize = 0;             /* True to omit %_docsize table */
117388 117703     int bDescIdx = 0;               /* True to store descending indexes */
117389 117704     char *zPrefix = 0;              /* Prefix parameter value (or NULL) */
117390 117705     char *zCompress = 0;            /* compress=? parameter (or NULL) */
117391 117706     char *zUncompress = 0;          /* uncompress=? parameter (or NULL) */
117392 117707     char *zContent = 0;             /* content=? parameter (or NULL) */
       117708  +  char *zLanguageid = 0;          /* languageid=? parameter (or NULL) */
117393 117709   
117394 117710     assert( strlen(argv[0])==4 );
117395 117711     assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
117396 117712          || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
117397 117713     );
117398 117714   
117399 117715     nDb = (int)strlen(argv[1]) + 1;
................................................................................
117435 117751           int nOpt;
117436 117752         } aFts4Opt[] = {
117437 117753           { "matchinfo",   9 },     /* 0 -> MATCHINFO */
117438 117754           { "prefix",      6 },     /* 1 -> PREFIX */
117439 117755           { "compress",    8 },     /* 2 -> COMPRESS */
117440 117756           { "uncompress", 10 },     /* 3 -> UNCOMPRESS */
117441 117757           { "order",       5 },     /* 4 -> ORDER */
117442         -        { "content",     7 }      /* 5 -> CONTENT */
       117758  +        { "content",     7 },     /* 5 -> CONTENT */
       117759  +        { "languageid", 10 }      /* 6 -> LANGUAGEID */
117443 117760         };
117444 117761   
117445 117762         int iOpt;
117446 117763         if( !zVal ){
117447 117764           rc = SQLITE_NOMEM;
117448 117765         }else{
117449 117766           for(iOpt=0; iOpt<SizeofArray(aFts4Opt); iOpt++){
................................................................................
117489 117806                 ){
117490 117807                   *pzErr = sqlite3_mprintf("unrecognized order: %s", zVal);
117491 117808                   rc = SQLITE_ERROR;
117492 117809                 }
117493 117810                 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
117494 117811                 break;
117495 117812   
117496         -            default:              /* CONTENT */
117497         -              assert( iOpt==5 );
117498         -              sqlite3_free(zUncompress);
       117813  +            case 5:              /* CONTENT */
       117814  +              sqlite3_free(zContent);
117499 117815                 zContent = zVal;
117500 117816                 zVal = 0;
117501 117817                 break;
       117818  +
       117819  +            case 6:              /* LANGUAGEID */
       117820  +              assert( iOpt==6 );
       117821  +              sqlite3_free(zLanguageid);
       117822  +              zLanguageid = zVal;
       117823  +              zVal = 0;
       117824  +              break;
117502 117825             }
117503 117826           }
117504 117827           sqlite3_free(zVal);
117505 117828         }
117506 117829       }
117507 117830   
117508 117831       /* Otherwise, the argument is a column name. */
................................................................................
117524 117847       sqlite3_free(zUncompress); 
117525 117848       zCompress = 0;
117526 117849       zUncompress = 0;
117527 117850       if( nCol==0 ){
117528 117851         sqlite3_free((void*)aCol); 
117529 117852         aCol = 0;
117530 117853         rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString);
       117854  +
       117855  +      /* If a languageid= option was specified, remove the language id
       117856  +      ** column from the aCol[] array. */ 
       117857  +      if( rc==SQLITE_OK && zLanguageid ){
       117858  +        int j;
       117859  +        for(j=0; j<nCol; j++){
       117860  +          if( sqlite3_stricmp(zLanguageid, aCol[j])==0 ){
       117861  +            int k;
       117862  +            for(k=j; k<nCol; k++) aCol[k] = aCol[k+1];
       117863  +            nCol--;
       117864  +            break;
       117865  +          }
       117866  +        }
       117867  +      }
117531 117868       }
117532         -    assert( rc!=SQLITE_OK || nCol>0 );
117533 117869     }
117534 117870     if( rc!=SQLITE_OK ) goto fts3_init_out;
117535 117871   
117536 117872     if( nCol==0 ){
117537 117873       assert( nString==0 );
117538 117874       aCol[0] = "content";
117539 117875       nString = 8;
................................................................................
117572 117908     p->azColumn = (char **)&p[1];
117573 117909     p->pTokenizer = pTokenizer;
117574 117910     p->nMaxPendingData = FTS3_MAX_PENDING_DATA;
117575 117911     p->bHasDocsize = (isFts4 && bNoDocsize==0);
117576 117912     p->bHasStat = isFts4;
117577 117913     p->bDescIdx = bDescIdx;
117578 117914     p->zContentTbl = zContent;
       117915  +  p->zLanguageid = zLanguageid;
117579 117916     zContent = 0;
       117917  +  zLanguageid = 0;
117580 117918     TESTONLY( p->inTransaction = -1 );
117581 117919     TESTONLY( p->mxSavepoint = -1 );
117582 117920   
117583 117921     p->aIndex = (struct Fts3Index *)&p->azColumn[nCol];
117584 117922     memcpy(p->aIndex, aIndex, sizeof(struct Fts3Index) * nIndex);
117585 117923     p->nIndex = nIndex;
117586 117924     for(i=0; i<nIndex; i++){
................................................................................
117635 117973   
117636 117974   fts3_init_out:
117637 117975     sqlite3_free(zPrefix);
117638 117976     sqlite3_free(aIndex);
117639 117977     sqlite3_free(zCompress);
117640 117978     sqlite3_free(zUncompress);
117641 117979     sqlite3_free(zContent);
       117980  +  sqlite3_free(zLanguageid);
117642 117981     sqlite3_free((void *)aCol);
117643 117982     if( rc!=SQLITE_OK ){
117644 117983       if( p ){
117645 117984         fts3DisconnectMethod((sqlite3_vtab *)p);
117646 117985       }else if( pTokenizer ){
117647 117986         pTokenizer->pModule->xDestroy(pTokenizer);
117648 117987       }
................................................................................
117686 118025   **   2. Full-text search using a MATCH operator on a non-docid column.
117687 118026   **   3. Linear scan of %_content table.
117688 118027   */
117689 118028   static int fts3BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
117690 118029     Fts3Table *p = (Fts3Table *)pVTab;
117691 118030     int i;                          /* Iterator variable */
117692 118031     int iCons = -1;                 /* Index of constraint to use */
       118032  +  int iLangidCons = -1;           /* Index of langid=x constraint, if present */
117693 118033   
117694 118034     /* By default use a full table scan. This is an expensive option,
117695 118035     ** so search through the constraints to see if a more efficient 
117696 118036     ** strategy is possible.
117697 118037     */
117698 118038     pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
117699 118039     pInfo->estimatedCost = 500000;
117700 118040     for(i=0; i<pInfo->nConstraint; i++){
117701 118041       struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i];
117702 118042       if( pCons->usable==0 ) continue;
117703 118043   
117704 118044       /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */
117705         -    if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ 
       118045  +    if( iCons<0 
       118046  +     && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ 
117706 118047        && (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1 )
117707 118048       ){
117708 118049         pInfo->idxNum = FTS3_DOCID_SEARCH;
117709 118050         pInfo->estimatedCost = 1.0;
117710 118051         iCons = i;
117711 118052       }
117712 118053   
................................................................................
117721 118062       */
117722 118063       if( pCons->op==SQLITE_INDEX_CONSTRAINT_MATCH 
117723 118064        && pCons->iColumn>=0 && pCons->iColumn<=p->nColumn
117724 118065       ){
117725 118066         pInfo->idxNum = FTS3_FULLTEXT_SEARCH + pCons->iColumn;
117726 118067         pInfo->estimatedCost = 2.0;
117727 118068         iCons = i;
117728         -      break;
       118069  +    }
       118070  +
       118071  +    /* Equality constraint on the langid column */
       118072  +    if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ 
       118073  +     && pCons->iColumn==p->nColumn + 2
       118074  +    ){
       118075  +      iLangidCons = i;
117729 118076       }
117730 118077     }
117731 118078   
117732 118079     if( iCons>=0 ){
117733 118080       pInfo->aConstraintUsage[iCons].argvIndex = 1;
117734 118081       pInfo->aConstraintUsage[iCons].omit = 1;
117735 118082     } 
       118083  +  if( iLangidCons>=0 ){
       118084  +    pInfo->aConstraintUsage[iLangidCons].argvIndex = 2;
       118085  +  } 
117736 118086   
117737 118087     /* Regardless of the strategy selected, FTS can deliver rows in rowid (or
117738 118088     ** docid) order. Both ascending and descending are possible. 
117739 118089     */
117740 118090     if( pInfo->nOrderBy==1 ){
117741 118091       struct sqlite3_index_orderby *pOrder = &pInfo->aOrderBy[0];
117742 118092       if( pOrder->iColumn<0 || pOrder->iColumn==p->nColumn+1 ){
................................................................................
118612 118962         fts3PutDeltaVarint3(&p, bDescDoclist, &iPrev, &bFirstOut, i2);
118613 118963         fts3PoslistCopy(&p, &p2);
118614 118964         fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2);
118615 118965       }
118616 118966     }
118617 118967   
118618 118968     *paOut = aOut;
118619         -  *pnOut = (p-aOut);
       118969  +  *pnOut = (int)(p-aOut);
118620 118970     assert( *pnOut<=n1+n2+FTS3_VARINT_MAX-1 );
118621 118971     return SQLITE_OK;
118622 118972   }
118623 118973   
118624 118974   /*
118625 118975   ** This function does a "phrase" merge of two doclists. In a phrase merge,
118626 118976   ** the output contains a copy of each position from the right-hand input
................................................................................
118676 119026         fts3GetDeltaVarint3(&p1, pEnd1, bDescDoclist, &i1);
118677 119027       }else{
118678 119028         fts3PoslistCopy(0, &p2);
118679 119029         fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2);
118680 119030       }
118681 119031     }
118682 119032   
118683         -  *pnRight = p - aOut;
       119033  +  *pnRight = (int)(p - aOut);
118684 119034   }
118685 119035   
118686 119036   /*
118687 119037   ** Argument pList points to a position list nList bytes in size. This
118688 119038   ** function checks to see if the position list contains any entries for
118689 119039   ** a token in position 0 (of any column). If so, it writes argument iDelta
118690 119040   ** to the output buffer pOut, followed by a position list consisting only
................................................................................
118878 119228   ** 8th argument.
118879 119229   **
118880 119230   ** This function returns SQLITE_OK if successful, or an SQLite error code
118881 119231   ** otherwise.
118882 119232   */
118883 119233   static int fts3SegReaderCursor(
118884 119234     Fts3Table *p,                   /* FTS3 table handle */
       119235  +  int iLangid,                    /* Language id */
118885 119236     int iIndex,                     /* Index to search (from 0 to p->nIndex-1) */
118886 119237     int iLevel,                     /* Level of segments to scan */
118887 119238     const char *zTerm,              /* Term to query for */
118888 119239     int nTerm,                      /* Size of zTerm in bytes */
118889 119240     int isPrefix,                   /* True for a prefix search */
118890 119241     int isScan,                     /* True to scan from zTerm to EOF */
118891 119242     Fts3MultiSegReader *pCsr        /* Cursor object to populate */
................................................................................
118906 119257       if( rc==SQLITE_OK && pSeg ){
118907 119258         rc = fts3SegReaderCursorAppend(pCsr, pSeg);
118908 119259       }
118909 119260     }
118910 119261   
118911 119262     if( iLevel!=FTS3_SEGCURSOR_PENDING ){
118912 119263       if( rc==SQLITE_OK ){
118913         -      rc = sqlite3Fts3AllSegdirs(p, iIndex, iLevel, &pStmt);
       119264  +      rc = sqlite3Fts3AllSegdirs(p, iLangid, iIndex, iLevel, &pStmt);
118914 119265       }
118915 119266   
118916 119267       while( rc==SQLITE_OK && SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){
118917 119268         Fts3SegReader *pSeg = 0;
118918 119269   
118919 119270         /* Read the values returned by the SELECT into local variables. */
118920 119271         sqlite3_int64 iStartBlock = sqlite3_column_int64(pStmt, 1);
................................................................................
118929 119280           sqlite3_int64 *pi = (isPrefix ? &iLeavesEndBlock : 0);
118930 119281           rc = fts3SelectLeaf(p, zTerm, nTerm, zRoot, nRoot, &iStartBlock, pi);
118931 119282           if( rc!=SQLITE_OK ) goto finished;
118932 119283           if( isPrefix==0 && isScan==0 ) iLeavesEndBlock = iStartBlock;
118933 119284         }
118934 119285    
118935 119286         rc = sqlite3Fts3SegReaderNew(pCsr->nSegment+1, 
118936         -          iStartBlock, iLeavesEndBlock, iEndBlock, zRoot, nRoot, &pSeg
       119287  +          (isPrefix==0 && isScan==0),
       119288  +          iStartBlock, iLeavesEndBlock, 
       119289  +          iEndBlock, zRoot, nRoot, &pSeg
118937 119290         );
118938 119291         if( rc!=SQLITE_OK ) goto finished;
118939 119292         rc = fts3SegReaderCursorAppend(pCsr, pSeg);
118940 119293       }
118941 119294     }
118942 119295   
118943 119296    finished:
................................................................................
118949 119302   
118950 119303   /*
118951 119304   ** Set up a cursor object for iterating through a full-text index or a 
118952 119305   ** single level therein.
118953 119306   */
118954 119307   SQLITE_PRIVATE int sqlite3Fts3SegReaderCursor(
118955 119308     Fts3Table *p,                   /* FTS3 table handle */
       119309  +  int iLangid,
118956 119310     int iIndex,                     /* Index to search (from 0 to p->nIndex-1) */
118957 119311     int iLevel,                     /* Level of segments to scan */
118958 119312     const char *zTerm,              /* Term to query for */
118959 119313     int nTerm,                      /* Size of zTerm in bytes */
118960 119314     int isPrefix,                   /* True for a prefix search */
118961 119315     int isScan,                     /* True to scan from zTerm to EOF */
118962 119316     Fts3MultiSegReader *pCsr       /* Cursor object to populate */
................................................................................
118973 119327     /* "isScan" is only set to true by the ft4aux module, an ordinary
118974 119328     ** full-text tables. */
118975 119329     assert( isScan==0 || p->aIndex==0 );
118976 119330   
118977 119331     memset(pCsr, 0, sizeof(Fts3MultiSegReader));
118978 119332   
118979 119333     return fts3SegReaderCursor(
118980         -      p, iIndex, iLevel, zTerm, nTerm, isPrefix, isScan, pCsr
       119334  +      p, iLangid, iIndex, iLevel, zTerm, nTerm, isPrefix, isScan, pCsr
118981 119335     );
118982 119336   }
118983 119337   
118984 119338   /*
118985 119339   ** In addition to its current configuration, have the Fts3MultiSegReader
118986 119340   ** passed as the 4th argument also scan the doclist for term zTerm/nTerm.
118987 119341   **
118988 119342   ** SQLITE_OK is returned if no error occurs, otherwise an SQLite error code.
118989 119343   */
118990 119344   static int fts3SegReaderCursorAddZero(
118991 119345     Fts3Table *p,                   /* FTS virtual table handle */
       119346  +  int iLangid,
118992 119347     const char *zTerm,              /* Term to scan doclist of */
118993 119348     int nTerm,                      /* Number of bytes in zTerm */
118994 119349     Fts3MultiSegReader *pCsr        /* Fts3MultiSegReader to modify */
118995 119350   ){
118996         -  return fts3SegReaderCursor(p, 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0,pCsr);
       119351  +  return fts3SegReaderCursor(p, 
       119352  +      iLangid, 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0,pCsr
       119353  +  );
118997 119354   }
118998 119355   
118999 119356   /*
119000 119357   ** Open an Fts3MultiSegReader to scan the doclist for term zTerm/nTerm. Or,
119001 119358   ** if isPrefix is true, to scan the doclist for all terms for which 
119002 119359   ** zTerm/nTerm is a prefix. If successful, return SQLITE_OK and write
119003 119360   ** a pointer to the new Fts3MultiSegReader to *ppSegcsr. Otherwise, return
................................................................................
119025 119382       int bFound = 0;               /* True once an index has been found */
119026 119383       Fts3Table *p = (Fts3Table *)pCsr->base.pVtab;
119027 119384   
119028 119385       if( isPrefix ){
119029 119386         for(i=1; bFound==0 && i<p->nIndex; i++){
119030 119387           if( p->aIndex[i].nPrefix==nTerm ){
119031 119388             bFound = 1;
119032         -          rc = sqlite3Fts3SegReaderCursor(
119033         -              p, i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0, pSegcsr);
       119389  +          rc = sqlite3Fts3SegReaderCursor(p, pCsr->iLangid, 
       119390  +              i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 0, 0, pSegcsr
       119391  +          );
119034 119392             pSegcsr->bLookup = 1;
119035 119393           }
119036 119394         }
119037 119395   
119038 119396         for(i=1; bFound==0 && i<p->nIndex; i++){
119039 119397           if( p->aIndex[i].nPrefix==nTerm+1 ){
119040 119398             bFound = 1;
119041         -          rc = sqlite3Fts3SegReaderCursor(
119042         -              p, i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 1, 0, pSegcsr
       119399  +          rc = sqlite3Fts3SegReaderCursor(p, pCsr->iLangid, 
       119400  +              i, FTS3_SEGCURSOR_ALL, zTerm, nTerm, 1, 0, pSegcsr
119043 119401             );
119044 119402             if( rc==SQLITE_OK ){
119045         -            rc = fts3SegReaderCursorAddZero(p, zTerm, nTerm, pSegcsr);
       119403  +            rc = fts3SegReaderCursorAddZero(
       119404  +                p, pCsr->iLangid, zTerm, nTerm, pSegcsr
       119405  +            );
119046 119406             }
119047 119407           }
119048 119408         }
119049 119409       }
119050 119410   
119051 119411       if( bFound==0 ){
119052         -      rc = sqlite3Fts3SegReaderCursor(
119053         -          p, 0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, isPrefix, 0, pSegcsr
       119412  +      rc = sqlite3Fts3SegReaderCursor(p, pCsr->iLangid, 
       119413  +          0, FTS3_SEGCURSOR_ALL, zTerm, nTerm, isPrefix, 0, pSegcsr
119054 119414         );
119055 119415         pSegcsr->bLookup = !isPrefix;
119056 119416       }
119057 119417     }
119058 119418   
119059 119419     *ppSegcsr = pSegcsr;
119060 119420     return rc;
................................................................................
119201 119561     Fts3Table *p = (Fts3Table *)pCursor->pVtab;
119202 119562     Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
119203 119563   
119204 119564     UNUSED_PARAMETER(idxStr);
119205 119565     UNUSED_PARAMETER(nVal);
119206 119566   
119207 119567     assert( idxNum>=0 && idxNum<=(FTS3_FULLTEXT_SEARCH+p->nColumn) );
119208         -  assert( nVal==0 || nVal==1 );
       119568  +  assert( nVal==0 || nVal==1 || nVal==2 );
119209 119569     assert( (nVal==0)==(idxNum==FTS3_FULLSCAN_SEARCH) );
119210 119570     assert( p->pSegments==0 );
119211 119571   
119212 119572     /* In case the cursor has been used before, clear it now. */
119213 119573     sqlite3_finalize(pCsr->pStmt);
119214 119574     sqlite3_free(pCsr->aDoclist);
119215 119575     sqlite3Fts3ExprFree(pCsr->pExpr);
................................................................................
119226 119586       int iCol = idxNum-FTS3_FULLTEXT_SEARCH;
119227 119587       const char *zQuery = (const char *)sqlite3_value_text(apVal[0]);
119228 119588   
119229 119589       if( zQuery==0 && sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
119230 119590         return SQLITE_NOMEM;
119231 119591       }
119232 119592   
119233         -    rc = sqlite3Fts3ExprParse(p->pTokenizer, p->azColumn, p->bHasStat, 
119234         -        p->nColumn, iCol, zQuery, -1, &pCsr->pExpr
       119593  +    pCsr->iLangid = 0;
       119594  +    if( nVal==2 ) pCsr->iLangid = sqlite3_value_int(apVal[1]);
       119595  +
       119596  +    rc = sqlite3Fts3ExprParse(p->pTokenizer, pCsr->iLangid,
       119597  +        p->azColumn, p->bHasStat, p->nColumn, iCol, zQuery, -1, &pCsr->pExpr
119235 119598       );
119236 119599       if( rc!=SQLITE_OK ){
119237 119600         if( rc==SQLITE_ERROR ){
119238 119601           static const char *zErr = "malformed MATCH expression: [%s]";
119239 119602           p->base.zErrMsg = sqlite3_mprintf(zErr, zQuery);
119240 119603         }
119241 119604         return rc;
................................................................................
119298 119661     *pRowid = pCsr->iPrevId;
119299 119662     return SQLITE_OK;
119300 119663   }
119301 119664   
119302 119665   /* 
119303 119666   ** This is the xColumn method, called by SQLite to request a value from
119304 119667   ** the row that the supplied cursor currently points to.
       119668  +**
       119669  +** If:
       119670  +**
       119671  +**   (iCol <  p->nColumn)   -> The value of the iCol'th user column.
       119672  +**   (iCol == p->nColumn)   -> Magic column with the same name as the table.
       119673  +**   (iCol == p->nColumn+1) -> Docid column
       119674  +**   (iCol == p->nColumn+2) -> Langid column
119305 119675   */
119306 119676   static int fts3ColumnMethod(
119307 119677     sqlite3_vtab_cursor *pCursor,   /* Cursor to retrieve value from */
119308         -  sqlite3_context *pContext,      /* Context for sqlite3_result_xxx() calls */
       119678  +  sqlite3_context *pCtx,          /* Context for sqlite3_result_xxx() calls */
119309 119679     int iCol                        /* Index of column to read value from */
119310 119680   ){
119311 119681     int rc = SQLITE_OK;             /* Return Code */
119312 119682     Fts3Cursor *pCsr = (Fts3Cursor *) pCursor;
119313 119683     Fts3Table *p = (Fts3Table *)pCursor->pVtab;
119314 119684   
119315 119685     /* The column value supplied by SQLite must be in range. */
119316         -  assert( iCol>=0 && iCol<=p->nColumn+1 );
       119686  +  assert( iCol>=0 && iCol<=p->nColumn+2 );
119317 119687   
119318 119688     if( iCol==p->nColumn+1 ){
119319 119689       /* This call is a request for the "docid" column. Since "docid" is an 
119320 119690       ** alias for "rowid", use the xRowid() method to obtain the value.
119321 119691       */
119322         -    sqlite3_result_int64(pContext, pCsr->iPrevId);
       119692  +    sqlite3_result_int64(pCtx, pCsr->iPrevId);
119323 119693     }else if( iCol==p->nColumn ){
119324 119694       /* The extra column whose name is the same as the table.
119325         -    ** Return a blob which is a pointer to the cursor.
119326         -    */
119327         -    sqlite3_result_blob(pContext, &pCsr, sizeof(pCsr), SQLITE_TRANSIENT);
       119695  +    ** Return a blob which is a pointer to the cursor.  */
       119696  +    sqlite3_result_blob(pCtx, &pCsr, sizeof(pCsr), SQLITE_TRANSIENT);
       119697  +  }else if( iCol==p->nColumn+2 && pCsr->pExpr ){
       119698  +    sqlite3_result_int64(pCtx, pCsr->iLangid);
119328 119699     }else{
       119700  +    /* The requested column is either a user column (one that contains 
       119701  +    ** indexed data), or the language-id column.  */
119329 119702       rc = fts3CursorSeek(0, pCsr);
119330         -    if( rc==SQLITE_OK && sqlite3_data_count(pCsr->pStmt)>(iCol+1) ){
119331         -      sqlite3_result_value(pContext, sqlite3_column_value(pCsr->pStmt, iCol+1));
       119703  +
       119704  +    if( rc==SQLITE_OK ){
       119705  +      if( iCol==p->nColumn+2 ){
       119706  +        int iLangid = 0;
       119707  +        if( p->zLanguageid ){
       119708  +          iLangid = sqlite3_column_int(pCsr->pStmt, p->nColumn+1);
       119709  +        }
       119710  +        sqlite3_result_int(pCtx, iLangid);
       119711  +      }else if( sqlite3_data_count(pCsr->pStmt)>(iCol+1) ){
       119712  +        sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
       119713  +      }
119332 119714       }
119333 119715     }
119334 119716   
119335 119717     assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
119336 119718     return rc;
119337 119719   }
119338 119720   
................................................................................
120025 120407           char *p1 = aPoslist;
120026 120408           char *p2 = aOut;
120027 120409   
120028 120410           assert( iPrev>=0 );
120029 120411           fts3PoslistPhraseMerge(&aOut, iToken-iPrev, 0, 1, &p1, &p2);
120030 120412           sqlite3_free(aPoslist);
120031 120413           aPoslist = pList;
120032         -        nPoslist = aOut - aPoslist;
       120414  +        nPoslist = (int)(aOut - aPoslist);
120033 120415           if( nPoslist==0 ){
120034 120416             sqlite3_free(aPoslist);
120035 120417             pPhrase->doclist.pList = 0;
120036 120418             pPhrase->doclist.nList = 0;
120037 120419             return SQLITE_OK;
120038 120420           }
120039 120421         }
................................................................................
120069 120451           sqlite3_free(aPoslist);
120070 120452           return SQLITE_NOMEM;
120071 120453         }
120072 120454         
120073 120455         pPhrase->doclist.pList = aOut;
120074 120456         if( fts3PoslistPhraseMerge(&aOut, nDistance, 0, 1, &p1, &p2) ){
120075 120457           pPhrase->doclist.bFreeList = 1;
120076         -        pPhrase->doclist.nList = (aOut - pPhrase->doclist.pList);
       120458  +        pPhrase->doclist.nList = (int)(aOut - pPhrase->doclist.pList);
120077 120459         }else{
120078 120460           sqlite3_free(aOut);
120079 120461           pPhrase->doclist.pList = 0;
120080 120462           pPhrase->doclist.nList = 0;
120081 120463         }
120082 120464         sqlite3_free(aPoslist);
120083 120465       }
................................................................................
120165 120547         iDocid += (iMul * iDelta);
120166 120548         pNext = pDocid;
120167 120549         fts3PoslistCopy(0, &pDocid);
120168 120550         while( pDocid<pEnd && *pDocid==0 ) pDocid++;
120169 120551         iMul = (bDescIdx ? -1 : 1);
120170 120552       }
120171 120553   
120172         -    *pnList = pEnd - pNext;
       120554  +    *pnList = (int)(pEnd - pNext);
120173 120555       *ppIter = pNext;
120174 120556       *piDocid = iDocid;
120175 120557     }else{
120176 120558       int iMul = (bDescIdx ? -1 : 1);
120177 120559       sqlite3_int64 iDelta;
120178 120560       fts3GetReverseVarint(&p, aDoclist, &iDelta);
120179 120561       *piDocid -= (iMul * iDelta);
120180 120562   
120181 120563       if( p==aDoclist ){
120182 120564         *pbEof = 1;
120183 120565       }else{
120184 120566         char *pSave = p;
120185 120567         fts3ReversePoslist(aDoclist, &p);
120186         -      *pnList = (pSave - p);
       120568  +      *pnList = (int)(pSave - p);
120187 120569       }
120188 120570       *ppIter = p;
120189 120571     }
120190 120572   }
120191 120573   
120192 120574   /*
120193 120575   ** Attempt to move the phrase iterator to point to the next matching docid. 
................................................................................
120239 120621         if( pTab->bDescIdx==0 || pDL->pNextDocid==0 ){
120240 120622           pDL->iDocid += iDelta;
120241 120623         }else{
120242 120624           pDL->iDocid -= iDelta;
120243 120625         }
120244 120626         pDL->pList = pIter;
120245 120627         fts3PoslistCopy(0, &pIter);
120246         -      pDL->nList = (pIter - pDL->pList);
       120628  +      pDL->nList = (int)(pIter - pDL->pList);
120247 120629   
120248 120630         /* pIter now points just past the 0x00 that terminates the position-
120249 120631         ** list for document pDL->iDocid. However, if this position-list was
120250 120632         ** edited in place by fts3EvalNearTrim(), then pIter may not actually
120251 120633         ** point to the start of the next docid value. The following line deals
120252 120634         ** with this case by advancing pIter past the zero-padding added by
120253 120635         ** fts3EvalNearTrim().  */
................................................................................
120597 120979         rc = SQLITE_NOMEM;
120598 120980       }else{
120599 120981         int ii;
120600 120982         Fts3TokenAndCost *pTC = aTC;
120601 120983         Fts3Expr **ppOr = apOr;
120602 120984   
120603 120985         fts3EvalTokenCosts(pCsr, 0, pCsr->pExpr, &pTC, &ppOr, &rc);
120604         -      nToken = pTC-aTC;
120605         -      nOr = ppOr-apOr;
       120986  +      nToken = (int)(pTC-aTC);
       120987  +      nOr = (int)(ppOr-apOr);
120606 120988   
120607 120989         if( rc==SQLITE_OK ){
120608 120990           rc = fts3EvalSelectDeferred(pCsr, 0, aTC, nToken);
120609 120991           for(ii=0; rc==SQLITE_OK && ii<nOr; ii++){
120610 120992             rc = fts3EvalSelectDeferred(pCsr, apOr[ii], aTC, nToken);
120611 120993           }
120612 120994         }
................................................................................
120670 121052     assert( pPhrase->doclist.pList );
120671 121053   
120672 121054     p2 = pOut = pPhrase->doclist.pList;
120673 121055     res = fts3PoslistNearMerge(
120674 121056       &pOut, aTmp, nParam1, nParam2, paPoslist, &p2
120675 121057     );
120676 121058     if( res ){
120677         -    nNew = (pOut - pPhrase->doclist.pList) - 1;
       121059  +    nNew = (int)(pOut - pPhrase->doclist.pList) - 1;
120678 121060       assert( pPhrase->doclist.pList[nNew]=='\0' );
120679 121061       assert( nNew<=pPhrase->doclist.nList && nNew>0 );
120680 121062       memset(&pPhrase->doclist.pList[nNew], 0, pPhrase->doclist.nList - nNew);
120681 121063       pPhrase->doclist.nList = nNew;
120682 121064       *paPoslist = pPhrase->doclist.pList;
120683 121065       *pnToken = pPhrase->nToken;
120684 121066     }
................................................................................
121503 121885       *pzErr = sqlite3_mprintf(
121504 121886           "wrong number of arguments to fts4aux constructor"
121505 121887       );
121506 121888       return SQLITE_ERROR;
121507 121889     }
121508 121890   
121509 121891     zDb = argv[1]; 
121510         -  nDb = strlen(zDb);
       121892  +  nDb = (int)strlen(zDb);
121511 121893     zFts3 = argv[3];
121512         -  nFts3 = strlen(zFts3);
       121894  +  nFts3 = (int)strlen(zFts3);
121513 121895   
121514 121896     rc = sqlite3_declare_vtab(db, FTS3_TERMS_SCHEMA);
121515 121897     if( rc!=SQLITE_OK ) return rc;
121516 121898   
121517 121899     nByte = sizeof(Fts3auxTable) + sizeof(Fts3Table) + nDb + nFts3 + 2;
121518 121900     p = (Fts3auxTable *)sqlite3_malloc(nByte);
121519 121901     if( !p ) return SQLITE_NOMEM;
................................................................................
121800 122182     if( idxNum&FTS4AUX_LE_CONSTRAINT ){
121801 122183       int iIdx = (idxNum&FTS4AUX_GE_CONSTRAINT) ? 1 : 0;
121802 122184       pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iIdx]));
121803 122185       pCsr->nStop = sqlite3_value_bytes(apVal[iIdx]);
121804 122186       if( pCsr->zStop==0 ) return SQLITE_NOMEM;
121805 122187     }
121806 122188   
121807         -  rc = sqlite3Fts3SegReaderCursor(pFts3, 0, FTS3_SEGCURSOR_ALL,
       122189  +  rc = sqlite3Fts3SegReaderCursor(pFts3, 0, 0, FTS3_SEGCURSOR_ALL,
121808 122190         pCsr->filter.zTerm, pCsr->filter.nTerm, 0, isScan, &pCsr->csr
121809 122191     );
121810 122192     if( rc==SQLITE_OK ){
121811 122193       rc = sqlite3Fts3SegReaderStart(pFts3, &pCsr->csr, &pCsr->filter);
121812 122194     }
121813 122195   
121814 122196     if( rc==SQLITE_OK ) rc = fts3auxNextMethod(pCursor);
................................................................................
121992 122374   **   FTSQUERY_PHRASE with a unary "-" attached to it. i.e. "mysql" in the
121993 122375   **   FTS3 query "sqlite -mysql". Otherwise, ParseContext.isNot is set to
121994 122376   **   zero.
121995 122377   */
121996 122378   typedef struct ParseContext ParseContext;
121997 122379   struct ParseContext {
121998 122380     sqlite3_tokenizer *pTokenizer;      /* Tokenizer module */
       122381  +  int iLangid;                        /* Language id used with tokenizer */
121999 122382     const char **azCol;                 /* Array of column names for fts3 table */
122000 122383     int bFts4;                          /* True to allow FTS4-only syntax */
122001 122384     int nCol;                           /* Number of entries in azCol[] */
122002 122385     int iDefaultCol;                    /* Default column to query */
122003 122386     int isNot;                          /* True if getNextNode() sees a unary - */
122004 122387     sqlite3_context *pCtx;              /* Write error message here */
122005 122388     int nNest;                          /* Number of nested brackets */
................................................................................
122027 122410   */
122028 122411   static void *fts3MallocZero(int nByte){
122029 122412     void *pRet = sqlite3_malloc(nByte);
122030 122413     if( pRet ) memset(pRet, 0, nByte);
122031 122414     return pRet;
122032 122415   }
122033 122416   
       122417  +SQLITE_PRIVATE int sqlite3Fts3OpenTokenizer(
       122418  +  sqlite3_tokenizer *pTokenizer,
       122419  +  int iLangid,
       122420  +  const char *z,
       122421  +  int n,
       122422  +  sqlite3_tokenizer_cursor **ppCsr
       122423  +){
       122424  +  sqlite3_tokenizer_module const *pModule = pTokenizer->pModule;
       122425  +  sqlite3_tokenizer_cursor *pCsr = 0;
       122426  +  int rc;
       122427  +
       122428  +  rc = pModule->xOpen(pTokenizer, z, n, &pCsr);
       122429  +  assert( rc==SQLITE_OK || pCsr==0 );
       122430  +  if( rc==SQLITE_OK ){
       122431  +    pCsr->pTokenizer = pTokenizer;
       122432  +    if( pModule->iVersion>=1 ){
       122433  +      rc = pModule->xLanguageid(pCsr, iLangid);
       122434  +      if( rc!=SQLITE_OK ){
       122435  +        pModule->xClose(pCsr);
       122436  +        pCsr = 0;
       122437  +      }
       122438  +    }
       122439  +  }
       122440  +  *ppCsr = pCsr;
       122441  +  return rc;
       122442  +}
       122443  +
122034 122444   
122035 122445   /*
122036 122446   ** Extract the next token from buffer z (length n) using the tokenizer
122037 122447   ** and other information (column names etc.) in pParse. Create an Fts3Expr
122038 122448   ** structure of type FTSQUERY_PHRASE containing a phrase consisting of this
122039 122449   ** single token and set *ppExpr to point to it. If the end of the buffer is
122040 122450   ** reached before a token is found, set *ppExpr to zero. It is the
................................................................................
122054 122464     sqlite3_tokenizer *pTokenizer = pParse->pTokenizer;
122055 122465     sqlite3_tokenizer_module const *pModule = pTokenizer->pModule;
122056 122466     int rc;
122057 122467     sqlite3_tokenizer_cursor *pCursor;
122058 122468     Fts3Expr *pRet = 0;
122059 122469     int nConsumed = 0;
122060 122470   
122061         -  rc = pModule->xOpen(pTokenizer, z, n, &pCursor);
       122471  +  rc = sqlite3Fts3OpenTokenizer(pTokenizer, pParse->iLangid, z, n, &pCursor);
122062 122472     if( rc==SQLITE_OK ){
122063 122473       const char *zToken;
122064 122474       int nToken, iStart, iEnd, iPosition;
122065 122475       int nByte;                               /* total space to allocate */
122066 122476   
122067         -    pCursor->pTokenizer = pTokenizer;
122068 122477       rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
122069         -
122070 122478       if( rc==SQLITE_OK ){
122071 122479         nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
122072 122480         pRet = (Fts3Expr *)fts3MallocZero(nByte);
122073 122481         if( !pRet ){
122074 122482           rc = SQLITE_NOMEM;
122075 122483         }else{
122076 122484           pRet->eType = FTSQUERY_PHRASE;
................................................................................
122168 122576     **
122169 122577     **   Buffer zTemp: Contains copies of all tokens.
122170 122578     **
122171 122579     ** The second pass, in the block that begins "if( rc==SQLITE_DONE )" below,
122172 122580     ** appends buffer zTemp to buffer p, and fills in the Fts3Expr and Fts3Phrase
122173 122581     ** structures.
122174 122582     */
122175         -  rc = pModule->xOpen(pTokenizer, zInput, nInput, &pCursor);
       122583  +  rc = sqlite3Fts3OpenTokenizer(
       122584  +      pTokenizer, pParse->iLangid, zInput, nInput, &pCursor);
122176 122585     if( rc==SQLITE_OK ){
122177 122586       int ii;
122178         -    pCursor->pTokenizer = pTokenizer;
122179 122587       for(ii=0; rc==SQLITE_OK; ii++){
122180 122588         const char *zByte;
122181 122589         int nByte, iBegin, iEnd, iPos;
122182 122590         rc = pModule->xNext(pCursor, &zByte, &nByte, &iBegin, &iEnd, &iPos);
122183 122591         if( rc==SQLITE_OK ){
122184 122592           Fts3PhraseToken *pToken;
122185 122593   
................................................................................
122645 123053   ** that appears on the left-hand-side of the MATCH operator (the default
122646 123054   ** column to match against for tokens for which a column name is not explicitly
122647 123055   ** specified as part of the query string), or -1 if tokens may by default
122648 123056   ** match any table column.
122649 123057   */
122650 123058   SQLITE_PRIVATE int sqlite3Fts3ExprParse(
122651 123059     sqlite3_tokenizer *pTokenizer,      /* Tokenizer module */
       123060  +  int iLangid,                        /* Language id for tokenizer */
122652 123061     char **azCol,                       /* Array of column names for fts3 table */
122653 123062     int bFts4,                          /* True to allow FTS4-only syntax */
122654 123063     int nCol,                           /* Number of entries in azCol[] */
122655 123064     int iDefaultCol,                    /* Default column to query */
122656 123065     const char *z, int n,               /* Text of MATCH query */
122657 123066     Fts3Expr **ppExpr                   /* OUT: Parsed query structure */
122658 123067   ){
122659 123068     int nParsed;
122660 123069     int rc;
122661 123070     ParseContext sParse;
       123071  +
       123072  +  memset(&sParse, 0, sizeof(ParseContext));
122662 123073     sParse.pTokenizer = pTokenizer;
       123074  +  sParse.iLangid = iLangid;
122663 123075     sParse.azCol = (const char **)azCol;
122664 123076     sParse.nCol = nCol;
122665 123077     sParse.iDefaultCol = iDefaultCol;
122666         -  sParse.nNest = 0;
122667 123078     sParse.bFts4 = bFts4;
122668 123079     if( z==0 ){
122669 123080       *ppExpr = 0;
122670 123081       return SQLITE_OK;
122671 123082     }
122672 123083     if( n<0 ){
122673 123084       n = (int)strlen(z);
................................................................................
122850 123261       goto exprtest_out;
122851 123262     }
122852 123263     for(ii=0; ii<nCol; ii++){
122853 123264       azCol[ii] = (char *)sqlite3_value_text(argv[ii+2]);
122854 123265     }
122855 123266   
122856 123267     rc = sqlite3Fts3ExprParse(
122857         -      pTokenizer, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr
       123268  +      pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr
122858 123269     );
122859 123270     if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM ){
122860 123271       sqlite3_result_error(context, "Error parsing expression", -1);
122861 123272     }else if( rc==SQLITE_NOMEM || !(zBuf = exprToString(pExpr, 0)) ){
122862 123273       sqlite3_result_error_nomem(context);
122863 123274     }else{
122864 123275       sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
................................................................................
123899 124310   static const sqlite3_tokenizer_module porterTokenizerModule = {
123900 124311     0,
123901 124312     porterCreate,
123902 124313     porterDestroy,
123903 124314     porterOpen,
123904 124315     porterClose,
123905 124316     porterNext,
       124317  +  0
123906 124318   };
123907 124319   
123908 124320   /*
123909 124321   ** Allocate a new porter tokenizer.  Return a pointer to the new
123910 124322   ** tokenizer in *ppModule
123911 124323   */
123912 124324   SQLITE_PRIVATE void sqlite3Fts3PorterTokenizerModule(
................................................................................
124204 124616     Tcl_IncrRefCount(pRet);
124205 124617   
124206 124618     if( SQLITE_OK!=p->xCreate(zArg ? 1 : 0, &zArg, &pTokenizer) ){
124207 124619       zErr = "error in xCreate()";
124208 124620       goto finish;
124209 124621     }
124210 124622     pTokenizer->pModule = p;
124211         -  if( SQLITE_OK!=p->xOpen(pTokenizer, zInput, nInput, &pCsr) ){
       124623  +  if( sqlite3Fts3OpenTokenizer(pTokenizer, 0, zInput, nInput, &pCsr) ){
124212 124624       zErr = "error in xOpen()";
124213 124625       goto finish;
124214 124626     }
124215         -  pCsr->pTokenizer = pTokenizer;
124216 124627   
124217 124628     while( SQLITE_OK==p->xNext(pCsr, &zToken, &nToken, &iStart, &iEnd, &iPos) ){
124218 124629       Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(iPos));
124219 124630       Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zToken, nToken));
124220 124631       zToken = &zInput[iStart];
124221 124632       nToken = iEnd-iStart;
124222 124633       Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zToken, nToken));
................................................................................
124624 125035   static const sqlite3_tokenizer_module simpleTokenizerModule = {
124625 125036     0,
124626 125037     simpleCreate,
124627 125038     simpleDestroy,
124628 125039     simpleOpen,
124629 125040     simpleClose,
124630 125041     simpleNext,
       125042  +  0,
124631 125043   };
124632 125044   
124633 125045   /*
124634 125046   ** Allocate a new simple tokenizer.  Return a pointer to the new
124635 125047   ** tokenizer in *ppModule
124636 125048   */
124637 125049   SQLITE_PRIVATE void sqlite3Fts3SimpleTokenizerModule(
................................................................................
124751 125163   **
124752 125164   **   fts3SegReaderNext()
124753 125165   **   fts3SegReaderFirstDocid()
124754 125166   **   fts3SegReaderNextDocid()
124755 125167   */
124756 125168   struct Fts3SegReader {
124757 125169     int iIdx;                       /* Index within level, or 0x7FFFFFFF for PT */
       125170  +  int bLookup;                    /* True for a lookup only */
124758 125171   
124759 125172     sqlite3_int64 iStartBlock;      /* Rowid of first leaf block to traverse */
124760 125173     sqlite3_int64 iLeafEndBlock;    /* Rowid of final leaf block to traverse */
124761 125174     sqlite3_int64 iEndBlock;        /* Rowid of final block in segment (or 0) */
124762 125175     sqlite3_int64 iCurrentBlock;    /* Current leaf block (or 0) */
124763 125176   
124764 125177     char *aNode;                    /* Pointer to node data (or NULL) */
................................................................................
124872 125285   #define SQL_REPLACE_DOCTOTAL          23
124873 125286   
124874 125287   #define SQL_SELECT_ALL_PREFIX_LEVEL   24
124875 125288   #define SQL_DELETE_ALL_TERMS_SEGDIR   25
124876 125289   
124877 125290   #define SQL_DELETE_SEGDIR_RANGE       26
124878 125291   
       125292  +#define SQL_SELECT_ALL_LANGID         27
       125293  +
124879 125294   /*
124880 125295   ** This function is used to obtain an SQLite prepared statement handle
124881 125296   ** for the statement identified by the second argument. If successful,
124882 125297   ** *pp is set to the requested statement handle and SQLITE_OK returned.
124883 125298   ** Otherwise, an SQLite error code is returned and *pp is set to 0.
124884 125299   **
124885 125300   ** If argument apVal is not NULL, then it must point to an array with
................................................................................
124925 125340   /* 21 */  "SELECT size FROM %Q.'%q_docsize' WHERE docid=?",
124926 125341   /* 22 */  "SELECT value FROM %Q.'%q_stat' WHERE id=0",
124927 125342   /* 23 */  "REPLACE INTO %Q.'%q_stat' VALUES(0,?)",
124928 125343   /* 24 */  "",
124929 125344   /* 25 */  "",
124930 125345   
124931 125346   /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?",
       125347  +/* 27 */ "SELECT DISTINCT level / (1024 * ?) FROM %Q.'%q_segdir'",
124932 125348   
124933 125349     };
124934 125350     int rc = SQLITE_OK;
124935 125351     sqlite3_stmt *pStmt;
124936 125352   
124937 125353     assert( SizeofArray(azSql)==SizeofArray(p->aStmt) );
124938 125354     assert( eStmt<SizeofArray(azSql) && eStmt>=0 );
................................................................................
125070 125486       }
125071 125487     }else{
125072 125488       rc = SQLITE_OK;
125073 125489     }
125074 125490   
125075 125491     return rc;
125076 125492   }
       125493  +
       125494  +/*
       125495  +** FTS maintains a separate indexes for each language-id (a 32-bit integer).
       125496  +** Within each language id, a separate index is maintained to store the
       125497  +** document terms, and each configured prefix size (configured the FTS 
       125498  +** "prefix=" option). And each index consists of multiple levels ("relative
       125499  +** levels").
       125500  +**
       125501  +** All three of these values (the language id, the specific index and the
       125502  +** level within the index) are encoded in 64-bit integer values stored
       125503  +** in the %_segdir table on disk. This function is used to convert three
       125504  +** separate component values into the single 64-bit integer value that
       125505  +** can be used to query the %_segdir table.
       125506  +**
       125507  +** Specifically, each language-id/index combination is allocated 1024 
       125508  +** 64-bit integer level values ("absolute levels"). The main terms index
       125509  +** for language-id 0 is allocate values 0-1023. The first prefix index
       125510  +** (if any) for language-id 0 is allocated values 1024-2047. And so on.
       125511  +** Language 1 indexes are allocated immediately following language 0.
       125512  +**
       125513  +** So, for a system with nPrefix prefix indexes configured, the block of
       125514  +** absolute levels that corresponds to language-id iLangid and index 
       125515  +** iIndex starts at absolute level ((iLangid * (nPrefix+1) + iIndex) * 1024).
       125516  +*/
       125517  +static sqlite3_int64 getAbsoluteLevel(
       125518  +  Fts3Table *p, 
       125519  +  int iLangid, 
       125520  +  int iIndex, 
       125521  +  int iLevel
       125522  +){
       125523  +  sqlite3_int64 iBase;            /* First absolute level for iLangid/iIndex */
       125524  +  assert( iLangid>=0 );
       125525  +  assert( p->nIndex>0 );
       125526  +  assert( iIndex>=0 && iIndex<p->nIndex );
       125527  +
       125528  +  iBase = ((sqlite3_int64)iLangid * p->nIndex + iIndex) * FTS3_SEGDIR_MAXLEVEL;
       125529  +  return iBase + iLevel;
       125530  +}
       125531  +
125077 125532   
125078 125533   /*
125079 125534   ** Set *ppStmt to a statement handle that may be used to iterate through
125080 125535   ** all rows in the %_segdir table, from oldest to newest. If successful,
125081 125536   ** return SQLITE_OK. If an error occurs while preparing the statement, 
125082 125537   ** return an SQLite error code.
125083 125538   **
................................................................................
125090 125545   **   1: start_block
125091 125546   **   2: leaves_end_block
125092 125547   **   3: end_block
125093 125548   **   4: root
125094 125549   */
125095 125550   SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(
125096 125551     Fts3Table *p,                   /* FTS3 table */
       125552  +  int iLangid,                    /* Language being queried */
125097 125553     int iIndex,                     /* Index for p->aIndex[] */
125098         -  int iLevel,                     /* Level to select */
       125554  +  int iLevel,                     /* Level to select (relative level) */
125099 125555     sqlite3_stmt **ppStmt           /* OUT: Compiled statement */
125100 125556   ){
125101 125557     int rc;
125102 125558     sqlite3_stmt *pStmt = 0;
125103 125559   
125104 125560     assert( iLevel==FTS3_SEGCURSOR_ALL || iLevel>=0 );
125105 125561     assert( iLevel<FTS3_SEGDIR_MAXLEVEL );
125106 125562     assert( iIndex>=0 && iIndex<p->nIndex );
125107 125563   
125108 125564     if( iLevel<0 ){
125109 125565       /* "SELECT * FROM %_segdir WHERE level BETWEEN ? AND ? ORDER BY ..." */
125110 125566       rc = fts3SqlStmt(p, SQL_SELECT_LEVEL_RANGE, &pStmt, 0);
125111 125567       if( rc==SQLITE_OK ){ 
125112         -      sqlite3_bind_int(pStmt, 1, iIndex*FTS3_SEGDIR_MAXLEVEL);
125113         -      sqlite3_bind_int(pStmt, 2, (iIndex+1)*FTS3_SEGDIR_MAXLEVEL-1);
       125568  +      sqlite3_bind_int64(pStmt, 1, getAbsoluteLevel(p, iLangid, iIndex, 0));
       125569  +      sqlite3_bind_int64(pStmt, 2, 
       125570  +          getAbsoluteLevel(p, iLangid, iIndex, FTS3_SEGDIR_MAXLEVEL-1)
       125571  +      );
125114 125572       }
125115 125573     }else{
125116 125574       /* "SELECT * FROM %_segdir WHERE level = ? ORDER BY ..." */
125117 125575       rc = fts3SqlStmt(p, SQL_SELECT_LEVEL, &pStmt, 0);
125118 125576       if( rc==SQLITE_OK ){ 
125119         -      sqlite3_bind_int(pStmt, 1, iLevel+iIndex*FTS3_SEGDIR_MAXLEVEL);
       125577  +      sqlite3_bind_int64(pStmt, 1, getAbsoluteLevel(p, iLangid, iIndex,iLevel));
125120 125578       }
125121 125579     }
125122 125580     *ppStmt = pStmt;
125123 125581     return rc;
125124 125582   }
125125 125583   
125126 125584   
................................................................................
125278 125736   ** pending-terms hash-table. The docid used is that currently stored in
125279 125737   ** p->iPrevDocid, and the column is specified by argument iCol.
125280 125738   **
125281 125739   ** If successful, SQLITE_OK is returned. Otherwise, an SQLite error code.
125282 125740   */
125283 125741   static int fts3PendingTermsAdd(
125284 125742     Fts3Table *p,                   /* Table into which text will be inserted */
       125743  +  int iLangid,                    /* Language id to use */
125285 125744     const char *zText,              /* Text of document to be inserted */
125286 125745     int iCol,                       /* Column into which text is being inserted */
125287 125746     u32 *pnWord                     /* OUT: Number of tokens inserted */
125288 125747   ){
125289 125748     int rc;
125290 125749     int iStart;
125291 125750     int iEnd;
................................................................................
125307 125766     ** zText==0. In this case, add zero token entries to the hash table and 
125308 125767     ** return early. */
125309 125768     if( zText==0 ){
125310 125769       *pnWord = 0;
125311 125770       return SQLITE_OK;
125312 125771     }
125313 125772   
125314         -  rc = pModule->xOpen(pTokenizer, zText, -1, &pCsr);
       125773  +  rc = sqlite3Fts3OpenTokenizer(pTokenizer, iLangid, zText, -1, &pCsr);
125315 125774     if( rc!=SQLITE_OK ){
125316 125775       return rc;
125317 125776     }
125318         -  pCsr->pTokenizer = pTokenizer;
125319 125777   
125320 125778     xNext = pModule->xNext;
125321 125779     while( SQLITE_OK==rc
125322 125780         && SQLITE_OK==(rc = xNext(pCsr, &zToken, &nToken, &iStart, &iEnd, &iPos))
125323 125781     ){
125324 125782       int i;
125325 125783       if( iPos>=nWord ) nWord = iPos+1;
................................................................................
125354 125812   }
125355 125813   
125356 125814   /* 
125357 125815   ** Calling this function indicates that subsequent calls to 
125358 125816   ** fts3PendingTermsAdd() are to add term/position-list pairs for the
125359 125817   ** contents of the document with docid iDocid.
125360 125818   */
125361         -static int fts3PendingTermsDocid(Fts3Table *p, sqlite_int64 iDocid){
       125819  +static int fts3PendingTermsDocid(
       125820  +  Fts3Table *p,                   /* Full-text table handle */
       125821  +  int iLangid,                    /* Language id of row being written */
       125822  +  sqlite_int64 iDocid             /* Docid of row being written */
       125823  +){
       125824  +  assert( iLangid>=0 );
       125825  +
125362 125826     /* TODO(shess) Explore whether partially flushing the buffer on
125363 125827     ** forced-flush would provide better performance.  I suspect that if
125364 125828     ** we ordered the doclists by size and flushed the largest until the
125365 125829     ** buffer was half empty, that would let the less frequent terms
125366 125830     ** generate longer doclists.
125367 125831     */
125368         -  if( iDocid<=p->iPrevDocid || p->nPendingData>p->nMaxPendingData ){
       125832  +  if( iDocid<=p->iPrevDocid 
       125833  +   || p->iPrevLangid!=iLangid
       125834  +   || p->nPendingData>p->nMaxPendingData 
       125835  +  ){
125369 125836       int rc = sqlite3Fts3PendingTermsFlush(p);
125370 125837       if( rc!=SQLITE_OK ) return rc;
125371 125838     }
125372 125839     p->iPrevDocid = iDocid;
       125840  +  p->iPrevLangid = iLangid;
125373 125841     return SQLITE_OK;
125374 125842   }
125375 125843   
125376 125844   /*
125377 125845   ** Discard the contents of the pending-terms hash tables. 
125378 125846   */
125379 125847   SQLITE_PRIVATE void sqlite3Fts3PendingTermsClear(Fts3Table *p){
................................................................................
125394 125862   ** This function is called by the xUpdate() method as part of an INSERT
125395 125863   ** operation. It adds entries for each term in the new record to the
125396 125864   ** pendingTerms hash table.
125397 125865   **
125398 125866   ** Argument apVal is the same as the similarly named argument passed to
125399 125867   ** fts3InsertData(). Parameter iDocid is the docid of the new row.
125400 125868   */
125401         -static int fts3InsertTerms(Fts3Table *p, sqlite3_value **apVal, u32 *aSz){
       125869  +static int fts3InsertTerms(
       125870  +  Fts3Table *p, 
       125871  +  int iLangid, 
       125872  +  sqlite3_value **apVal, 
       125873  +  u32 *aSz
       125874  +){
125402 125875     int i;                          /* Iterator variable */
125403 125876     for(i=2; i<p->nColumn+2; i++){
125404 125877       const char *zText = (const char *)sqlite3_value_text(apVal[i]);
125405         -    int rc = fts3PendingTermsAdd(p, zText, i-2, &aSz[i-2]);
       125878  +    int rc = fts3PendingTermsAdd(p, iLangid, zText, i-2, &aSz[i-2]);
125406 125879       if( rc!=SQLITE_OK ){
125407 125880         return rc;
125408 125881       }
125409 125882       aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]);
125410 125883     }
125411 125884     return SQLITE_OK;
125412 125885   }
................................................................................
125419 125892   **   apVal[0]                Not used for INSERT.
125420 125893   **   apVal[1]                rowid
125421 125894   **   apVal[2]                Left-most user-defined column
125422 125895   **   ...
125423 125896   **   apVal[p->nColumn+1]     Right-most user-defined column
125424 125897   **   apVal[p->nColumn+2]     Hidden column with same name as table
125425 125898   **   apVal[p->nColumn+3]     Hidden "docid" column (alias for rowid)
       125899  +**   apVal[p->nColumn+4]     Hidden languageid column
125426 125900   */
125427 125901   static int fts3InsertData(
125428 125902     Fts3Table *p,                   /* Full-text table */
125429 125903     sqlite3_value **apVal,          /* Array of values to insert */
125430 125904     sqlite3_int64 *piDocid          /* OUT: Docid for row just inserted */
125431 125905   ){
125432 125906     int rc;                         /* Return code */
................................................................................
125449 125923     **
125450 125924     **   INSERT INTO %_content VALUES(?, ?, ?, ...)
125451 125925     **
125452 125926     ** The statement features N '?' variables, where N is the number of user
125453 125927     ** defined columns in the FTS3 table, plus one for the docid field.
125454 125928     */
125455 125929     rc = fts3SqlStmt(p, SQL_CONTENT_INSERT, &pContentInsert, &apVal[1]);
125456         -  if( rc!=SQLITE_OK ){
125457         -    return rc;
       125930  +  if( rc==SQLITE_OK && p->zLanguageid ){
       125931  +    rc = sqlite3_bind_int(
       125932  +        pContentInsert, p->nColumn+2, 
       125933  +        sqlite3_value_int(apVal[p->nColumn+4])
       125934  +    );
125458 125935     }
       125936  +  if( rc!=SQLITE_OK ) return rc;
125459 125937   
125460 125938     /* There is a quirk here. The users INSERT statement may have specified
125461 125939     ** a value for the "rowid" field, for the "docid" field, or for both.
125462 125940     ** Which is a problem, since "rowid" and "docid" are aliases for the
125463 125941     ** same value. For example:
125464 125942     **
125465 125943     **   INSERT INTO fts3tbl(rowid, docid) VALUES(1, 2);
................................................................................
125510 125988       fts3SqlExec(&rc, p, SQL_DELETE_ALL_DOCSIZE, 0);
125511 125989     }
125512 125990     if( p->bHasStat ){
125513 125991       fts3SqlExec(&rc, p, SQL_DELETE_ALL_STAT, 0);
125514 125992     }
125515 125993     return rc;
125516 125994   }
       125995  +
       125996  +/*
       125997  +**
       125998  +*/
       125999  +static int langidFromSelect(Fts3Table *p, sqlite3_stmt *pSelect){
       126000  +  int iLangid = 0;
       126001  +  if( p->zLanguageid ) iLangid = sqlite3_column_int(pSelect, p->nColumn+1);
       126002  +  return iLangid;
       126003  +}
125517 126004   
125518 126005   /*
125519 126006   ** The first element in the apVal[] array is assumed to contain the docid
125520 126007   ** (an integer) of a row about to be deleted. Remove all terms from the
125521 126008   ** full-text index.
125522 126009   */
125523 126010   static void fts3DeleteTerms( 
................................................................................
125530 126017     sqlite3_stmt *pSelect;
125531 126018   
125532 126019     if( *pRC ) return;
125533 126020     rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, &pRowid);
125534 126021     if( rc==SQLITE_OK ){
125535 126022       if( SQLITE_ROW==sqlite3_step(pSelect) ){
125536 126023         int i;
125537         -      for(i=1; i<=p->nColumn; i++){
       126024  +      int iLangid = langidFromSelect(p, pSelect);
       126025  +      rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pSelect, 0));
       126026  +      for(i=1; rc==SQLITE_OK && i<=p->nColumn; i++){
125538 126027           const char *zText = (const char *)sqlite3_column_text(pSelect, i);
125539         -        rc = fts3PendingTermsAdd(p, zText, -1, &aSz[i-1]);
125540         -        if( rc!=SQLITE_OK ){
125541         -          sqlite3_reset(pSelect);
125542         -          *pRC = rc;
125543         -          return;
125544         -        }
       126028  +        rc = fts3PendingTermsAdd(p, iLangid, zText, -1, &aSz[i-1]);
125545 126029           aSz[p->nColumn] += sqlite3_column_bytes(pSelect, i);
       126030  +      }
       126031  +      if( rc!=SQLITE_OK ){
       126032  +        sqlite3_reset(pSelect);
       126033  +        *pRC = rc;
       126034  +        return;
125546 126035         }
125547 126036       }
125548 126037       rc = sqlite3_reset(pSelect);
125549 126038     }else{
125550 126039       sqlite3_reset(pSelect);
125551 126040     }
125552 126041     *pRC = rc;
125553 126042   }
125554 126043   
125555 126044   /*
125556 126045   ** Forward declaration to account for the circular dependency between
125557 126046   ** functions fts3SegmentMerge() and fts3AllocateSegdirIdx().
125558 126047   */
125559         -static int fts3SegmentMerge(Fts3Table *, int, int);
       126048  +static int fts3SegmentMerge(Fts3Table *, int, int, int);
125560 126049   
125561 126050   /* 
125562 126051   ** This function allocates a new level iLevel index in the segdir table.
125563 126052   ** Usually, indexes are allocated within a level sequentially starting
125564 126053   ** with 0, so the allocated index is one greater than the value returned
125565 126054   ** by:
125566 126055   **
................................................................................
125571 126060   ** allocated index is 0.
125572 126061   **
125573 126062   ** If successful, *piIdx is set to the allocated index slot and SQLITE_OK
125574 126063   ** returned. Otherwise, an SQLite error code is returned.
125575 126064   */
125576 126065   static int fts3AllocateSegdirIdx(
125577 126066     Fts3Table *p, 
       126067  +  int iLangid,                    /* Language id */
125578 126068     int iIndex,                     /* Index for p->aIndex */
125579 126069     int iLevel, 
125580 126070     int *piIdx
125581 126071   ){
125582 126072     int rc;                         /* Return Code */
125583 126073     sqlite3_stmt *pNextIdx;         /* Query for next idx at level iLevel */
125584 126074     int iNext = 0;                  /* Result of query pNextIdx */
125585 126075   
       126076  +  assert( iLangid>=0 );
       126077  +  assert( p->nIndex>=1 );
       126078  +
125586 126079     /* Set variable iNext to the next available segdir index at level iLevel. */
125587 126080     rc = fts3SqlStmt(p, SQL_NEXT_SEGMENT_INDEX, &pNextIdx, 0);
125588 126081     if( rc==SQLITE_OK ){
125589         -    sqlite3_bind_int(pNextIdx, 1, iIndex*FTS3_SEGDIR_MAXLEVEL + iLevel);
       126082  +    sqlite3_bind_int64(
       126083  +        pNextIdx, 1, getAbsoluteLevel(p, iLangid, iIndex, iLevel)
       126084  +    );
125590 126085       if( SQLITE_ROW==sqlite3_step(pNextIdx) ){
125591 126086         iNext = sqlite3_column_int(pNextIdx, 0);
125592 126087       }
125593 126088       rc = sqlite3_reset(pNextIdx);
125594 126089     }
125595 126090   
125596 126091     if( rc==SQLITE_OK ){
125597 126092       /* If iNext is FTS3_MERGE_COUNT, indicating that level iLevel is already
125598 126093       ** full, merge all segments in level iLevel into a single iLevel+1
125599 126094       ** segment and allocate (newly freed) index 0 at level iLevel. Otherwise,
125600 126095       ** if iNext is less than FTS3_MERGE_COUNT, allocate index iNext.
125601 126096       */
125602 126097       if( iNext>=FTS3_MERGE_COUNT ){
125603         -      rc = fts3SegmentMerge(p, iIndex, iLevel);
       126098  +      rc = fts3SegmentMerge(p, iLangid, iIndex, iLevel);
125604 126099         *piIdx = 0;
125605 126100       }else{
125606 126101         *piIdx = iNext;
125607 126102       }
125608 126103     }
125609 126104   
125610 126105     return rc;
................................................................................
125728 126223     while( pReader->pBlob && rc==SQLITE_OK 
125729 126224        &&  (pFrom - pReader->aNode + nByte)>pReader->nPopulate
125730 126225     ){
125731 126226       rc = fts3SegReaderIncrRead(pReader);
125732 126227     }
125733 126228     return rc;
125734 126229   }
       126230  +
       126231  +/*
       126232  +** Set an Fts3SegReader cursor to point at EOF.
       126233  +*/
       126234  +static void fts3SegReaderSetEof(Fts3SegReader *pSeg){
       126235  +  if( !fts3SegReaderIsRootOnly(pSeg) ){
       126236  +    sqlite3_free(pSeg->aNode);
       126237  +    sqlite3_blob_close(pSeg->pBlob);
       126238  +    pSeg->pBlob = 0;
       126239  +  }
       126240  +  pSeg->aNode = 0;
       126241  +}
125735 126242   
125736 126243   /*
125737 126244   ** Move the iterator passed as the first argument to the next term in the
125738 126245   ** segment. If successful, SQLITE_OK is returned. If there is no next term,
125739 126246   ** SQLITE_DONE. Otherwise, an SQLite error code.
125740 126247   */
125741 126248   static int fts3SegReaderNext(
................................................................................
125768 126275           pReader->aNode = pReader->aDoclist = pList->aData;
125769 126276           pReader->ppNextElem++;
125770 126277           assert( pReader->aNode );
125771 126278         }
125772 126279         return SQLITE_OK;
125773 126280       }
125774 126281   
125775         -    if( !fts3SegReaderIsRootOnly(pReader) ){
125776         -      sqlite3_free(pReader->aNode);
125777         -      sqlite3_blob_close(pReader->pBlob);
125778         -      pReader->pBlob = 0;
125779         -    }
125780         -    pReader->aNode = 0;
       126282  +    fts3SegReaderSetEof(pReader);
125781 126283   
125782 126284       /* If iCurrentBlock>=iLeafEndBlock, this is an EOF condition. All leaf 
125783 126285       ** blocks have already been traversed.  */
125784 126286       assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock );
125785 126287       if( pReader->iCurrentBlock>=pReader->iLeafEndBlock ){
125786 126288         return SQLITE_OK;
125787 126289       }
................................................................................
126020 126522   }
126021 126523   
126022 126524   /*
126023 126525   ** Allocate a new SegReader object.
126024 126526   */
126025 126527   SQLITE_PRIVATE int sqlite3Fts3SegReaderNew(
126026 126528     int iAge,                       /* Segment "age". */
       126529  +  int bLookup,                    /* True for a lookup only */
126027 126530     sqlite3_int64 iStartLeaf,       /* First leaf to traverse */
126028 126531     sqlite3_int64 iEndLeaf,         /* Final leaf to traverse */
126029 126532     sqlite3_int64 iEndBlock,        /* Final block of segment */
126030 126533     const char *zRoot,              /* Buffer containing root node */
126031 126534     int nRoot,                      /* Size of buffer containing root node */
126032 126535     Fts3SegReader **ppReader        /* OUT: Allocated Fts3SegReader */
126033 126536   ){
................................................................................
126041 126544   
126042 126545     pReader = (Fts3SegReader *)sqlite3_malloc(sizeof(Fts3SegReader) + nExtra);
126043 126546     if( !pReader ){
126044 126547       return SQLITE_NOMEM;
126045 126548     }
126046 126549     memset(pReader, 0, sizeof(Fts3SegReader));
126047 126550     pReader->iIdx = iAge;
       126551  +  pReader->bLookup = bLookup;
126048 126552     pReader->iStartBlock = iStartLeaf;
126049 126553     pReader->iLeafEndBlock = iEndLeaf;
126050 126554     pReader->iEndBlock = iEndBlock;
126051 126555   
126052 126556     if( nExtra ){
126053 126557       /* The entire segment is stored in the root node. */
126054 126558       pReader->aNode = (char *)&pReader[1];
................................................................................
126338 126842   }
126339 126843   
126340 126844   /* 
126341 126845   ** Insert a record into the %_segdir table.
126342 126846   */
126343 126847   static int fts3WriteSegdir(
126344 126848     Fts3Table *p,                   /* Virtual table handle */
126345         -  int iLevel,                     /* Value for "level" field */
       126849  +  sqlite3_int64 iLevel,           /* Value for "level" field (absolute level) */
126346 126850     int iIdx,                       /* Value for "idx" field */
126347 126851     sqlite3_int64 iStartBlock,      /* Value for "start_block" field */
126348 126852     sqlite3_int64 iLeafEndBlock,    /* Value for "leaves_end_block" field */
126349 126853     sqlite3_int64 iEndBlock,        /* Value for "end_block" field */
126350 126854     char *zRoot,                    /* Blob value for "root" field */
126351 126855     int nRoot                       /* Number of bytes in buffer zRoot */
126352 126856   ){
126353 126857     sqlite3_stmt *pStmt;
126354 126858     int rc = fts3SqlStmt(p, SQL_INSERT_SEGDIR, &pStmt, 0);
126355 126859     if( rc==SQLITE_OK ){
126356         -    sqlite3_bind_int(pStmt, 1, iLevel);
       126860  +    sqlite3_bind_int64(pStmt, 1, iLevel);
126357 126861       sqlite3_bind_int(pStmt, 2, iIdx);
126358 126862       sqlite3_bind_int64(pStmt, 3, iStartBlock);
126359 126863       sqlite3_bind_int64(pStmt, 4, iLeafEndBlock);
126360 126864       sqlite3_bind_int64(pStmt, 5, iEndBlock);
126361 126865       sqlite3_bind_blob(pStmt, 6, zRoot, nRoot, SQLITE_STATIC);
126362 126866       sqlite3_step(pStmt);
126363 126867       rc = sqlite3_reset(pStmt);
................................................................................
126732 127236   ** database. This function must be called after all terms have been added
126733 127237   ** to the segment using fts3SegWriterAdd(). If successful, SQLITE_OK is
126734 127238   ** returned. Otherwise, an SQLite error code.
126735 127239   */
126736 127240   static int fts3SegWriterFlush(
126737 127241     Fts3Table *p,                   /* Virtual table handle */
126738 127242     SegmentWriter *pWriter,         /* SegmentWriter to flush to the db */
126739         -  int iLevel,                     /* Value for 'level' column of %_segdir */
       127243  +  sqlite3_int64 iLevel,           /* Value for 'level' column of %_segdir */
126740 127244     int iIdx                        /* Value for 'idx' column of %_segdir */
126741 127245   ){
126742 127246     int rc;                         /* Return code */
126743 127247     if( pWriter->pTree ){
126744 127248       sqlite3_int64 iLast = 0;      /* Largest block id written to database */
126745 127249       sqlite3_int64 iLastLeaf;      /* Largest leaf block id written to db */
126746 127250       char *zRoot = NULL;           /* Pointer to buffer containing root node */
................................................................................
126810 127314   ** Set *pnMax to the largest segment level in the database for the index
126811 127315   ** iIndex.
126812 127316   **
126813 127317   ** Segment levels are stored in the 'level' column of the %_segdir table.
126814 127318   **
126815 127319   ** Return SQLITE_OK if successful, or an SQLite error code if not.
126816 127320   */
126817         -static int fts3SegmentMaxLevel(Fts3Table *p, int iIndex, int *pnMax){
       127321  +static int fts3SegmentMaxLevel(
       127322  +  Fts3Table *p, 
       127323  +  int iLangid,
       127324  +  int iIndex, 
       127325  +  sqlite3_int64 *pnMax
       127326  +){
126818 127327     sqlite3_stmt *pStmt;
126819 127328     int rc;
126820 127329     assert( iIndex>=0 && iIndex<p->nIndex );
126821 127330   
126822 127331     /* Set pStmt to the compiled version of:
126823 127332     **
126824 127333     **   SELECT max(level) FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?
126825 127334     **
126826 127335     ** (1024 is actually the value of macro FTS3_SEGDIR_PREFIXLEVEL_STR).
126827 127336     */
126828 127337     rc = fts3SqlStmt(p, SQL_SELECT_SEGDIR_MAX_LEVEL, &pStmt, 0);
126829 127338     if( rc!=SQLITE_OK ) return rc;
126830         -  sqlite3_bind_int(pStmt, 1, iIndex*FTS3_SEGDIR_MAXLEVEL);
126831         -  sqlite3_bind_int(pStmt, 2, (iIndex+1)*FTS3_SEGDIR_MAXLEVEL - 1);
       127339  +  sqlite3_bind_int64(pStmt, 1, getAbsoluteLevel(p, iLangid, iIndex, 0));
       127340  +  sqlite3_bind_int64(pStmt, 2, 
       127341  +      getAbsoluteLevel(p, iLangid, iIndex, FTS3_SEGDIR_MAXLEVEL-1)
       127342  +  );
126832 127343     if( SQLITE_ROW==sqlite3_step(pStmt) ){
126833         -    *pnMax = sqlite3_column_int(pStmt, 0);
       127344  +    *pnMax = sqlite3_column_int64(pStmt, 0);
126834 127345     }
126835 127346     return sqlite3_reset(pStmt);
126836 127347   }
126837 127348   
126838 127349   /*
126839 127350   ** This function is used after merging multiple segments into a single large
126840 127351   ** segment to delete the old, now redundant, segment b-trees. Specifically,
................................................................................
126847 127358   **   2) deletes all %_segdir entries with level iLevel, or all %_segdir
126848 127359   **      entries regardless of level if (iLevel<0).
126849 127360   **
126850 127361   ** SQLITE_OK is returned if successful, otherwise an SQLite error code.
126851 127362   */
126852 127363   static int fts3DeleteSegdir(
126853 127364     Fts3Table *p,                   /* Virtual table handle */
       127365  +  int iLangid,                    /* Language id */
126854 127366     int iIndex,                     /* Index for p->aIndex */
126855 127367     int iLevel,                     /* Level of %_segdir entries to delete */
126856 127368     Fts3SegReader **apSegment,      /* Array of SegReader objects */
126857 127369     int nReader                     /* Size of array apSegment */
126858 127370   ){
126859 127371     int rc;                         /* Return Code */
126860 127372     int i;                          /* Iterator variable */
................................................................................
126874 127386       return rc;
126875 127387     }
126876 127388   
126877 127389     assert( iLevel>=0 || iLevel==FTS3_SEGCURSOR_ALL );
126878 127390     if( iLevel==FTS3_SEGCURSOR_ALL ){
126879 127391       rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_RANGE, &pDelete, 0);
126880 127392       if( rc==SQLITE_OK ){
126881         -      sqlite3_bind_int(pDelete, 1, iIndex*FTS3_SEGDIR_MAXLEVEL);
126882         -      sqlite3_bind_int(pDelete, 2, (iIndex+1) * FTS3_SEGDIR_MAXLEVEL - 1);
       127393  +      sqlite3_bind_int64(pDelete, 1, getAbsoluteLevel(p, iLangid, iIndex, 0));
       127394  +      sqlite3_bind_int64(pDelete, 2, 
       127395  +          getAbsoluteLevel(p, iLangid, iIndex, FTS3_SEGDIR_MAXLEVEL-1)
       127396  +      );
126883 127397       }
126884 127398     }else{
126885 127399       rc = fts3SqlStmt(p, SQL_DELETE_SEGDIR_LEVEL, &pDelete, 0);
126886 127400       if( rc==SQLITE_OK ){
126887         -      sqlite3_bind_int(pDelete, 1, iIndex*FTS3_SEGDIR_MAXLEVEL + iLevel);
       127401  +      sqlite3_bind_int64(
       127402  +          pDelete, 1, getAbsoluteLevel(p, iLangid, iIndex, iLevel)
       127403  +      );
126888 127404       }
126889 127405     }
126890 127406   
126891 127407     if( rc==SQLITE_OK ){
126892 127408       sqlite3_step(pDelete);
126893 127409       rc = sqlite3_reset(pDelete);
126894 127410     }
................................................................................
127043 127559     /* If the Fts3SegFilter defines a specific term (or term prefix) to search 
127044 127560     ** for, then advance each segment iterator until it points to a term of
127045 127561     ** equal or greater value than the specified term. This prevents many
127046 127562     ** unnecessary merge/sort operations for the case where single segment
127047 127563     ** b-tree leaf nodes contain more than one term.
127048 127564     */
127049 127565     for(i=0; pCsr->bRestart==0 && i<pCsr->nSegment; i++){
       127566  +    int res = 0;
127050 127567       Fts3SegReader *pSeg = pCsr->apSegment[i];
127051 127568       do {
127052 127569         int rc = fts3SegReaderNext(p, pSeg, 0);
127053 127570         if( rc!=SQLITE_OK ) return rc;
127054         -    }while( zTerm && fts3SegReaderTermCmp(pSeg, zTerm, nTerm)<0 );
       127571  +    }while( zTerm && (res = fts3SegReaderTermCmp(pSeg, zTerm, nTerm))<0 );
       127572  +
       127573  +    if( pSeg->bLookup && res!=0 ){
       127574  +      fts3SegReaderSetEof(pSeg);
       127575  +    }
127055 127576     }
127056 127577     fts3SegReaderSort(pCsr->apSegment, nSeg, nSeg, fts3SegReaderCmp);
127057 127578   
127058 127579     return SQLITE_OK;
127059 127580   }
127060 127581   
127061 127582   SQLITE_PRIVATE int sqlite3Fts3SegReaderStart(
................................................................................
127168 127689       int nMerge;
127169 127690       int i;
127170 127691     
127171 127692       /* Advance the first pCsr->nAdvance entries in the apSegment[] array
127172 127693       ** forward. Then sort the list in order of current term again.  
127173 127694       */
127174 127695       for(i=0; i<pCsr->nAdvance; i++){
127175         -      rc = fts3SegReaderNext(p, apSegment[i], 0);
       127696  +      Fts3SegReader *pSeg = apSegment[i];
       127697  +      if( pSeg->bLookup ){
       127698  +        fts3SegReaderSetEof(pSeg);
       127699  +      }else{
       127700  +        rc = fts3SegReaderNext(p, pSeg, 0);
       127701  +      }
127176 127702         if( rc!=SQLITE_OK ) return rc;
127177 127703       }
127178 127704       fts3SegReaderSort(apSegment, nSegment, pCsr->nAdvance, fts3SegReaderCmp);
127179 127705       pCsr->nAdvance = 0;
127180 127706   
127181 127707       /* If all the seg-readers are at EOF, we're finished. return SQLITE_OK. */
127182 127708       assert( rc==SQLITE_OK );
................................................................................
127339 127865   ** currently present in the database.
127340 127866   **
127341 127867   ** If this function is called with iLevel<0, but there is only one
127342 127868   ** segment in the database, SQLITE_DONE is returned immediately. 
127343 127869   ** Otherwise, if successful, SQLITE_OK is returned. If an error occurs, 
127344 127870   ** an SQLite error code is returned.
127345 127871   */
127346         -static int fts3SegmentMerge(Fts3Table *p, int iIndex, int iLevel){
       127872  +static int fts3SegmentMerge(
       127873  +  Fts3Table *p, 
       127874  +  int iLangid,                    /* Language id to merge */
       127875  +  int iIndex,                     /* Index in p->aIndex[] to merge */
       127876  +  int iLevel                      /* Level to merge */
       127877  +){
127347 127878     int rc;                         /* Return code */
127348 127879     int iIdx = 0;                   /* Index of new segment */
127349         -  int iNewLevel = 0;              /* Level/index to create new segment at */
       127880  +  sqlite3_int64 iNewLevel = 0;    /* Level/index to create new segment at */
127350 127881     SegmentWriter *pWriter = 0;     /* Used to write the new, merged, segment */
127351 127882     Fts3SegFilter filter;           /* Segment term filter condition */
127352         -  Fts3MultiSegReader csr;        /* Cursor to iterate through level(s) */
       127883  +  Fts3MultiSegReader csr;         /* Cursor to iterate through level(s) */
127353 127884     int bIgnoreEmpty = 0;           /* True to ignore empty segments */
127354 127885   
127355 127886     assert( iLevel==FTS3_SEGCURSOR_ALL
127356 127887          || iLevel==FTS3_SEGCURSOR_PENDING
127357 127888          || iLevel>=0
127358 127889     );
127359 127890     assert( iLevel<FTS3_SEGDIR_MAXLEVEL );
127360 127891     assert( iIndex>=0 && iIndex<p->nIndex );
127361 127892   
127362         -  rc = sqlite3Fts3SegReaderCursor(p, iIndex, iLevel, 0, 0, 1, 0, &csr);
       127893  +  rc = sqlite3Fts3SegReaderCursor(p, iLangid, iIndex, iLevel, 0, 0, 1, 0, &csr);
127363 127894     if( rc!=SQLITE_OK || csr.nSegment==0 ) goto finished;
127364 127895   
127365 127896     if( iLevel==FTS3_SEGCURSOR_ALL ){
127366 127897       /* This call is to merge all segments in the database to a single
127367 127898       ** segment. The level of the new segment is equal to the the numerically 
127368 127899       ** greatest segment level currently present in the database for this
127369 127900       ** index. The idx of the new segment is always 0.  */
127370 127901       if( csr.nSegment==1 ){
127371 127902         rc = SQLITE_DONE;
127372 127903         goto finished;
127373 127904       }
127374         -    rc = fts3SegmentMaxLevel(p, iIndex, &iNewLevel);
       127905  +    rc = fts3SegmentMaxLevel(p, iLangid, iIndex, &iNewLevel);
127375 127906       bIgnoreEmpty = 1;
127376 127907   
127377 127908     }else if( iLevel==FTS3_SEGCURSOR_PENDING ){
127378         -    iNewLevel = iIndex * FTS3_SEGDIR_MAXLEVEL; 
127379         -    rc = fts3AllocateSegdirIdx(p, iIndex, 0, &iIdx);
       127909  +    iNewLevel = getAbsoluteLevel(p, iLangid, iIndex, 0);
       127910  +    rc = fts3AllocateSegdirIdx(p, iLangid, iIndex, 0, &iIdx);
127380 127911     }else{
127381 127912       /* This call is to merge all segments at level iLevel. find the next
127382 127913       ** available segment index at level iLevel+1. The call to
127383 127914       ** fts3AllocateSegdirIdx() will merge the segments at level iLevel+1 to 
127384 127915       ** a single iLevel+2 segment if necessary.  */
127385         -    rc = fts3AllocateSegdirIdx(p, iIndex, iLevel+1, &iIdx);
127386         -    iNewLevel = iIndex * FTS3_SEGDIR_MAXLEVEL + iLevel+1;
       127916  +    rc = fts3AllocateSegdirIdx(p, iLangid, iIndex, iLevel+1, &iIdx);
       127917  +    iNewLevel = getAbsoluteLevel(p, iLangid, iIndex, iLevel+1);
127387 127918     }
127388 127919     if( rc!=SQLITE_OK ) goto finished;
127389 127920     assert( csr.nSegment>0 );
127390         -  assert( iNewLevel>=(iIndex*FTS3_SEGDIR_MAXLEVEL) );
127391         -  assert( iNewLevel<((iIndex+1)*FTS3_SEGDIR_MAXLEVEL) );
       127921  +  assert( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
       127922  +  assert( iNewLevel<getAbsoluteLevel(p, iLangid, iIndex,FTS3_SEGDIR_MAXLEVEL) );
127392 127923   
127393 127924     memset(&filter, 0, sizeof(Fts3SegFilter));
127394 127925     filter.flags = FTS3_SEGMENT_REQUIRE_POS;
127395 127926     filter.flags |= (bIgnoreEmpty ? FTS3_SEGMENT_IGNORE_EMPTY : 0);
127396 127927   
127397 127928     rc = sqlite3Fts3SegReaderStart(p, &csr, &filter);
127398 127929     while( SQLITE_OK==rc ){
................................................................................
127401 127932       rc = fts3SegWriterAdd(p, &pWriter, 1, 
127402 127933           csr.zTerm, csr.nTerm, csr.aDoclist, csr.nDoclist);
127403 127934     }
127404 127935     if( rc!=SQLITE_OK ) goto finished;
127405 127936     assert( pWriter );
127406 127937   
127407 127938     if( iLevel!=FTS3_SEGCURSOR_PENDING ){
127408         -    rc = fts3DeleteSegdir(p, iIndex, iLevel, csr.apSegment, csr.nSegment);
       127939  +    rc = fts3DeleteSegdir(
       127940  +        p, iLangid, iIndex, iLevel, csr.apSegment, csr.nSegment
       127941  +    );
127409 127942       if( rc!=SQLITE_OK ) goto finished;
127410 127943     }
127411 127944     rc = fts3SegWriterFlush(p, pWriter, iNewLevel, iIdx);
127412 127945   
127413 127946    finished:
127414 127947     fts3SegWriterFree(pWriter);
127415 127948     sqlite3Fts3SegReaderFinish(&csr);
................................................................................
127420 127953   /* 
127421 127954   ** Flush the contents of pendingTerms to level 0 segments.
127422 127955   */
127423 127956   SQLITE_PRIVATE int sqlite3Fts3PendingTermsFlush(Fts3Table *p){
127424 127957     int rc = SQLITE_OK;
127425 127958     int i;
127426 127959     for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
127427         -    rc = fts3SegmentMerge(p, i, FTS3_SEGCURSOR_PENDING);
       127960  +    rc = fts3SegmentMerge(p, p->iPrevLangid, i, FTS3_SEGCURSOR_PENDING);
127428 127961       if( rc==SQLITE_DONE ) rc = SQLITE_OK;
127429 127962     }
127430 127963     sqlite3Fts3PendingTermsClear(p);
127431 127964     return rc;
127432 127965   }
127433 127966   
127434 127967   /*
................................................................................
127575 128108     }
127576 128109     sqlite3_bind_blob(pStmt, 1, pBlob, nBlob, SQLITE_STATIC);
127577 128110     sqlite3_step(pStmt);
127578 128111     *pRC = sqlite3_reset(pStmt);
127579 128112     sqlite3_free(a);
127580 128113   }
127581 128114   
       128115  +/*
       128116  +** Merge the entire database so that there is one segment for each 
       128117  +** iIndex/iLangid combination.
       128118  +*/
127582 128119   static int fts3DoOptimize(Fts3Table *p, int bReturnDone){
127583         -  int i;
127584 128120     int bSeenDone = 0;
127585         -  int rc = SQLITE_OK;
127586         -  for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
127587         -    rc = fts3SegmentMerge(p, i, FTS3_SEGCURSOR_ALL);
127588         -    if( rc==SQLITE_DONE ){
127589         -      bSeenDone = 1;
127590         -      rc = SQLITE_OK;
       128121  +  int rc;
       128122  +  sqlite3_stmt *pAllLangid = 0;
       128123  +
       128124  +  rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
       128125  +  if( rc==SQLITE_OK ){
       128126  +    int rc2;
       128127  +    sqlite3_bind_int(pAllLangid, 1, p->nIndex);
       128128  +    while( sqlite3_step(pAllLangid)==SQLITE_ROW ){
       128129  +      int i;
       128130  +      int iLangid = sqlite3_column_int(pAllLangid, 0);
       128131  +      for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
       128132  +        rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL);
       128133  +        if( rc==SQLITE_DONE ){
       128134  +          bSeenDone = 1;
       128135  +          rc = SQLITE_OK;
       128136  +        }
       128137  +      }
127591 128138       }
       128139  +    rc2 = sqlite3_reset(pAllLangid);
       128140  +    if( rc==SQLITE_OK ) rc = rc2;
127592 128141     }
       128142  +
127593 128143     sqlite3Fts3SegmentsClose(p);
127594 128144     sqlite3Fts3PendingTermsClear(p);
127595 128145   
127596 128146     return (rc==SQLITE_OK && bReturnDone && bSeenDone) ? SQLITE_DONE : rc;
127597 128147   }
127598 128148   
127599 128149   /*
................................................................................
127636 128186           aSzIns = &aSz[p->nColumn+1];
127637 128187           aSzDel = &aSzIns[p->nColumn+1];
127638 128188         }
127639 128189       }
127640 128190   
127641 128191       while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
127642 128192         int iCol;
127643         -      rc = fts3PendingTermsDocid(p, sqlite3_column_int64(pStmt, 0));
       128193  +      int iLangid = langidFromSelect(p, pStmt);
       128194  +      rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pStmt, 0));
127644 128195         aSz[p->nColumn] = 0;
127645 128196         for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
127646 128197           const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1);
127647         -        rc = fts3PendingTermsAdd(p, z, iCol, &aSz[iCol]);
       128198  +        rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]);
127648 128199           aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1);
127649 128200         }
127650 128201         if( p->bHasDocsize ){
127651 128202           fts3InsertDocsize(&rc, p, aSz);
127652 128203         }
127653 128204         if( rc!=SQLITE_OK ){
127654 128205           sqlite3_finalize(pStmt);
................................................................................
127759 128310       assert( pCsr->isRequireSeek==0 );
127760 128311       iDocid = sqlite3_column_int64(pCsr->pStmt, 0);
127761 128312     
127762 128313       for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){
127763 128314         const char *zText = (const char *)sqlite3_column_text(pCsr->pStmt, i+1);
127764 128315         sqlite3_tokenizer_cursor *pTC = 0;
127765 128316     
127766         -      rc = pModule->xOpen(pT, zText, -1, &pTC);
       128317  +      rc = sqlite3Fts3OpenTokenizer(pT, pCsr->iLangid, zText, -1, &pTC);
127767 128318         while( rc==SQLITE_OK ){
127768 128319           char const *zToken;       /* Buffer containing token */
127769 128320           int nToken;               /* Number of bytes in token */
127770 128321           int iDum1, iDum2;         /* Dummy variables */
127771 128322           int iPos;                 /* Position of token in zText */
127772 128323     
127773         -        pTC->pTokenizer = pT;
127774 128324           rc = pModule->xNext(pTC, &zToken, &nToken, &iDum1, &iDum2, &iPos);
127775 128325           for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
127776 128326             Fts3PhraseToken *pPT = pDef->pToken;
127777 128327             if( (pDef->iCol>=p->nColumn || pDef->iCol==i)
127778 128328              && (pPT->bFirst==0 || iPos==0)
127779 128329              && (pPT->n==nToken || (pPT->isPrefix && pPT->n<nToken))
127780 128330              && (0==memcmp(zToken, pPT->z, pPT->n))
................................................................................
127866 128416       if( isEmpty ){
127867 128417         /* Deleting this row means the whole table is empty. In this case
127868 128418         ** delete the contents of all three tables and throw away any
127869 128419         ** data in the pendingTerms hash table.  */
127870 128420         rc = fts3DeleteAll(p, 1);
127871 128421         *pnDoc = *pnDoc - 1;
127872 128422       }else{
127873         -      sqlite3_int64 iRemove = sqlite3_value_int64(pRowid);
127874         -      rc = fts3PendingTermsDocid(p, iRemove);
127875 128423         fts3DeleteTerms(&rc, p, pRowid, aSzDel);
127876 128424         if( p->zContentTbl==0 ){
127877 128425           fts3SqlExec(&rc, p, SQL_DELETE_CONTENT, &pRowid);
127878 128426           if( sqlite3_changes(p->db) ) *pnDoc = *pnDoc - 1;
127879 128427         }else{
127880 128428           *pnDoc = *pnDoc - 1;
127881 128429         }
................................................................................
127886 128434     }
127887 128435   
127888 128436     return rc;
127889 128437   }
127890 128438   
127891 128439   /*
127892 128440   ** This function does the work for the xUpdate method of FTS3 virtual
127893         -** tables.
       128441  +** tables. The schema of the virtual table being:
       128442  +**
       128443  +**     CREATE TABLE <table name>( 
       128444  +**       <user COLUMns>,
       128445  +**       <table name> HIDDEN, 
       128446  +**       docid HIDDEN, 
       128447  +**       <langid> HIDDEN
       128448  +**     );
       128449  +**
       128450  +** 
127894 128451   */
127895 128452   SQLITE_PRIVATE int sqlite3Fts3UpdateMethod(
127896 128453     sqlite3_vtab *pVtab,            /* FTS3 vtab object */
127897 128454     int nArg,                       /* Size of argument array */
127898 128455     sqlite3_value **apVal,          /* Array of arguments */
127899 128456     sqlite_int64 *pRowid            /* OUT: The affected (or effected) rowid */
127900 128457   ){
................................................................................
127903 128460     int isRemove = 0;               /* True for an UPDATE or DELETE */
127904 128461     u32 *aSzIns = 0;                /* Sizes of inserted documents */
127905 128462     u32 *aSzDel;                    /* Sizes of deleted documents */
127906 128463     int nChng = 0;                  /* Net change in number of documents */
127907 128464     int bInsertDone = 0;
127908 128465   
127909 128466     assert( p->pSegments==0 );
       128467  +  assert( 
       128468  +      nArg==1                     /* DELETE operations */
       128469  +   || nArg==(2 + p->nColumn + 3)  /* INSERT or UPDATE operations */
       128470  +  );
127910 128471   
127911 128472     /* Check for a "special" INSERT operation. One of the form:
127912 128473     **
127913 128474     **   INSERT INTO xyz(xyz) VALUES('command');
127914 128475     */
127915 128476     if( nArg>1 
127916 128477      && sqlite3_value_type(apVal[0])==SQLITE_NULL 
127917 128478      && sqlite3_value_type(apVal[p->nColumn+2])!=SQLITE_NULL 
127918 128479     ){
127919 128480       rc = fts3SpecialInsert(p, apVal[p->nColumn+2]);
127920 128481       goto update_out;
127921 128482     }
       128483  +
       128484  +  if( nArg>1 && sqlite3_value_int(apVal[2 + p->nColumn + 2])<0 ){
       128485  +    rc = SQLITE_CONSTRAINT;
       128486  +    goto update_out;
       128487  +  }
127922 128488   
127923 128489     /* Allocate space to hold the change in document sizes */
127924 128490     aSzIns = sqlite3_malloc( sizeof(aSzIns[0])*(p->nColumn+1)*2 );
127925 128491     if( aSzIns==0 ){
127926 128492       rc = SQLITE_NOMEM;
127927 128493       goto update_out;
127928 128494     }
................................................................................
127983 128549       assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER );
127984 128550       rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel);
127985 128551       isRemove = 1;
127986 128552     }
127987 128553     
127988 128554     /* If this is an INSERT or UPDATE operation, insert the new record. */
127989 128555     if( nArg>1 && rc==SQLITE_OK ){
       128556  +    int iLangid = sqlite3_value_int(apVal[2 + p->nColumn + 2]);
127990 128557       if( bInsertDone==0 ){
127991 128558         rc = fts3InsertData(p, apVal, pRowid);
127992 128559         if( rc==SQLITE_CONSTRAINT && p->zContentTbl==0 ){
127993 128560           rc = FTS_CORRUPT_VTAB;
127994 128561         }
127995 128562       }
127996 128563       if( rc==SQLITE_OK && (!isRemove || *pRowid!=p->iPrevDocid ) ){
127997         -      rc = fts3PendingTermsDocid(p, *pRowid);
       128564  +      rc = fts3PendingTermsDocid(p, iLangid, *pRowid);
127998 128565       }
127999 128566       if( rc==SQLITE_OK ){
128000 128567         assert( p->iPrevDocid==*pRowid );
128001         -      rc = fts3InsertTerms(p, apVal, aSzIns);
       128568  +      rc = fts3InsertTerms(p, iLangid, apVal, aSzIns);
128002 128569       }
128003 128570       if( p->bHasDocsize ){
128004 128571         fts3InsertDocsize(&rc, p, aSzIns);
128005 128572       }
128006 128573       nChng++;
128007 128574     }
128008 128575   
................................................................................
128571 129138   ** This is done as part of extracting the snippet text, not when selecting
128572 129139   ** the snippet. Snippet selection is done based on doclists only, so there
128573 129140   ** is no way for fts3BestSnippet() to know whether or not the document 
128574 129141   ** actually contains terms that follow the final highlighted term. 
128575 129142   */
128576 129143   static int fts3SnippetShift(
128577 129144     Fts3Table *pTab,                /* FTS3 table snippet comes from */
       129145  +  int iLangid,                    /* Language id to use in tokenizing */
128578 129146     int nSnippet,                   /* Number of tokens desired for snippet */
128579 129147     const char *zDoc,               /* Document text to extract snippet from */
128580 129148     int nDoc,                       /* Size of buffer zDoc in bytes */
128581 129149     int *piPos,                     /* IN/OUT: First token of snippet */
128582 129150     u64 *pHlmask                    /* IN/OUT: Mask of tokens to highlight */
128583 129151   ){
128584 129152     u64 hlmask = *pHlmask;          /* Local copy of initial highlight-mask */
................................................................................
128606 129174         sqlite3_tokenizer_module *pMod;
128607 129175         sqlite3_tokenizer_cursor *pC;
128608 129176         pMod = (sqlite3_tokenizer_module *)pTab->pTokenizer->pModule;
128609 129177   
128610 129178         /* Open a cursor on zDoc/nDoc. Check if there are (nSnippet+nDesired)
128611 129179         ** or more tokens in zDoc/nDoc.
128612 129180         */
128613         -      rc = pMod->xOpen(pTab->pTokenizer, zDoc, nDoc, &pC);
       129181  +      rc = sqlite3Fts3OpenTokenizer(pTab->pTokenizer, iLangid, zDoc, nDoc, &pC);
128614 129182         if( rc!=SQLITE_OK ){
128615 129183           return rc;
128616 129184         }
128617         -      pC->pTokenizer = pTab->pTokenizer;
128618 129185         while( rc==SQLITE_OK && iCurrent<(nSnippet+nDesired) ){
128619 129186           const char *ZDUMMY; int DUMMY1, DUMMY2, DUMMY3;
128620 129187           rc = pMod->xNext(pC, &ZDUMMY, &DUMMY1, &DUMMY2, &DUMMY3, &iCurrent);
128621 129188         }
128622 129189         pMod->xClose(pC);
128623 129190         if( rc!=SQLITE_OK && rc!=SQLITE_DONE ){ return rc; }
128624 129191   
................................................................................
128670 129237       }
128671 129238       return SQLITE_OK;
128672 129239     }
128673 129240     nDoc = sqlite3_column_bytes(pCsr->pStmt, iCol);
128674 129241   
128675 129242     /* Open a token cursor on the document. */
128676 129243     pMod = (sqlite3_tokenizer_module *)pTab->pTokenizer->pModule;
128677         -  rc = pMod->xOpen(pTab->pTokenizer, zDoc, nDoc, &pC);
       129244  +  rc = sqlite3Fts3OpenTokenizer(pTab->pTokenizer, pCsr->iLangid, zDoc,nDoc,&pC);
128678 129245     if( rc!=SQLITE_OK ){
128679 129246       return rc;
128680 129247     }
128681         -  pC->pTokenizer = pTab->pTokenizer;
128682 129248   
128683 129249     while( rc==SQLITE_OK ){
128684 129250       int iBegin;                   /* Offset in zDoc of start of token */
128685 129251       int iFin;                     /* Offset in zDoc of end of token */
128686 129252       int isHighlight;              /* True for highlighted terms */
128687 129253   
128688 129254       rc = pMod->xNext(pC, &ZDUMMY, &DUMMY1, &iBegin, &iFin, &iCurrent);
................................................................................
128696 129262         }
128697 129263         break;
128698 129264       }
128699 129265       if( iCurrent<iPos ){ continue; }
128700 129266   
128701 129267       if( !isShiftDone ){
128702 129268         int n = nDoc - iBegin;
128703         -      rc = fts3SnippetShift(pTab, nSnippet, &zDoc[iBegin], n, &iPos, &hlmask);
       129269  +      rc = fts3SnippetShift(
       129270  +          pTab, pCsr->iLangid, nSnippet, &zDoc[iBegin], n, &iPos, &hlmask
       129271  +      );
128704 129272         isShiftDone = 1;
128705 129273   
128706 129274         /* Now that the shift has been done, check if the initial "..." are
128707 129275         ** required. They are required if (a) this is not the first fragment,
128708 129276         ** or (b) this fragment does not begin at position 0 of its column. 
128709 129277         */
128710 129278         if( rc==SQLITE_OK && (iPos>0 || iFragment>0) ){
................................................................................
129429 129997           continue;
129430 129998         }
129431 129999         rc = SQLITE_NOMEM;
129432 130000         goto offsets_out;
129433 130001       }
129434 130002   
129435 130003       /* Initialize a tokenizer iterator to iterate through column iCol. */
129436         -    rc = pMod->xOpen(pTab->pTokenizer, zDoc, nDoc, &pC);
       130004  +    rc = sqlite3Fts3OpenTokenizer(pTab->pTokenizer, pCsr->iLangid,
       130005  +        zDoc, nDoc, &pC
       130006  +    );
129437 130007       if( rc!=SQLITE_OK ) goto offsets_out;
129438         -    pC->pTokenizer = pTab->pTokenizer;
129439 130008   
129440 130009       rc = pMod->xNext(pC, &ZDUMMY, &NDUMMY, &iStart, &iEnd, &iCurrent);
129441 130010       while( rc==SQLITE_OK ){
129442 130011         int i;                      /* Used to loop through terms */
129443 130012         int iMinPos = 0x7FFFFFFF;   /* Position of next token */
129444 130013         TermOffset *pTerm = 0;      /* TermOffset associated with next token */
129445 130014   
................................................................................
132596 133165       *pzErr = sqlite3_mprintf("%s", aErrMsg[iErr]);
132597 133166       return SQLITE_ERROR;
132598 133167     }
132599 133168   
132600 133169     sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
132601 133170   
132602 133171     /* Allocate the sqlite3_vtab structure */
132603         -  nDb = strlen(argv[1]);
132604         -  nName = strlen(argv[2]);
       133172  +  nDb = (int)strlen(argv[1]);
       133173  +  nName = (int)strlen(argv[2]);
132605 133174     pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2);
132606 133175     if( !pRtree ){
132607 133176       return SQLITE_NOMEM;
132608 133177     }
132609 133178     memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
132610 133179     pRtree->nBusy = 1;
132611 133180     pRtree->base.pModule = &rtreeModule;
................................................................................
132692 133261       char zCell[512];
132693 133262       int nCell = 0;
132694 133263       RtreeCell cell;
132695 133264       int jj;
132696 133265   
132697 133266       nodeGetCell(&tree, &node, ii, &cell);
132698 133267       sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
132699         -    nCell = strlen(zCell);
       133268  +    nCell = (int)strlen(zCell);
132700 133269       for(jj=0; jj<tree.nDim*2; jj++){
132701 133270         sqlite3_snprintf(512-nCell,&zCell[nCell]," %f",(double)cell.aCoord[jj].f);
132702         -      nCell = strlen(zCell);
       133271  +      nCell = (int)strlen(zCell);
132703 133272       }
132704 133273   
132705 133274       if( zText ){
132706 133275         char *zTextNew = sqlite3_mprintf("%s {%s}", zText, zCell);
132707 133276         sqlite3_free(zText);
132708 133277         zText = zTextNew;
132709 133278       }else{

Changes to src/sqlite3.h.

   103    103   ** string contains the date and time of the check-in (UTC) and an SHA1
   104    104   ** hash of the entire source tree.
   105    105   **
   106    106   ** See also: [sqlite3_libversion()],
   107    107   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   108    108   ** [sqlite_version()] and [sqlite_source_id()].
   109    109   */
   110         -#define SQLITE_VERSION        "3.7.10"
   111         -#define SQLITE_VERSION_NUMBER 3007010
   112         -#define SQLITE_SOURCE_ID      "2012-01-11 16:16:08 9e31a275ef494ea8713a1d60a15b84157e57c3ff"
          110  +#define SQLITE_VERSION        "3.7.11"
          111  +#define SQLITE_VERSION_NUMBER 3007011
          112  +#define SQLITE_SOURCE_ID      "2012-03-19 14:57:49 bc03d99a78e90c02b69037e5f5f81537b5a3ac60"
   113    113   
   114    114   /*
   115    115   ** CAPI3REF: Run-Time Library Version Numbers
   116    116   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   117    117   **
   118    118   ** These interfaces provide the same information as the [SQLITE_VERSION],
   119    119   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
   457    457   #define SQLITE_IOERR_SEEK              (SQLITE_IOERR | (22<<8))
   458    458   #define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
   459    459   #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
   460    460   #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
   461    461   #define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
   462    462   #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
   463    463   #define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
          464  +#define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
   464    465   
   465    466   /*
   466    467   ** CAPI3REF: Flags For File Open Operations
   467    468   **
   468    469   ** These bit values are intended for use in the
   469    470   ** 3rd parameter to the [sqlite3_open_v2()] interface and
   470    471   ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
................................................................................
   712    713   ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging.  This
   713    714   ** opcode causes the xFileControl method to write the current state of
   714    715   ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
   715    716   ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
   716    717   ** into an integer that the pArg argument points to. This capability
   717    718   ** is used during testing and only needs to be supported when SQLITE_TEST
   718    719   ** is defined.
   719         -**
          720  +** <ul>
          721  +** <li>[[SQLITE_FCNTL_SIZE_HINT]]
   720    722   ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
   721    723   ** layer a hint of how large the database file will grow to be during the
   722    724   ** current transaction.  This hint is not guaranteed to be accurate but it
   723    725   ** is often close.  The underlying VFS might choose to preallocate database
   724    726   ** file space based on this hint in order to help writes to the database
   725    727   ** file run faster.
   726    728   **
          729  +** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
   727    730   ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
   728    731   ** extends and truncates the database file in chunks of a size specified
   729    732   ** by the user. The fourth argument to [sqlite3_file_control()] should 
   730    733   ** point to an integer (type int) containing the new chunk-size to use
   731    734   ** for the nominated database. Allocating database file space in large
   732    735   ** chunks (say 1MB at a time), may reduce file-system fragmentation and
   733    736   ** improve performance on some systems.
   734    737   **
          738  +** <li>[[SQLITE_FCNTL_FILE_POINTER]]
   735    739   ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
   736    740   ** to the [sqlite3_file] object associated with a particular database
   737    741   ** connection.  See the [sqlite3_file_control()] documentation for
   738    742   ** additional information.
   739    743   **
          744  +** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
   740    745   ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
   741    746   ** SQLite and sent to all VFSes in place of a call to the xSync method
   742    747   ** when the database connection has [PRAGMA synchronous] set to OFF.)^
   743    748   ** Some specialized VFSes need this signal in order to operate correctly
   744    749   ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most 
   745    750   ** VFSes do not need this signal and should silently ignore this opcode.
   746    751   ** Applications should not call [sqlite3_file_control()] with this
   747    752   ** opcode as doing so may disrupt the operation of the specialized VFSes
   748    753   ** that do require it.  
   749    754   **
          755  +** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
   750    756   ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
   751    757   ** retry counts and intervals for certain disk I/O operations for the
   752    758   ** windows [VFS] in order to provide robustness in the presence of
   753    759   ** anti-virus programs.  By default, the windows VFS will retry file read,
   754    760   ** file write, and file delete operations up to 10 times, with a delay
   755    761   ** of 25 milliseconds before the first retry and with the delay increasing
   756    762   ** by an additional 25 milliseconds with each subsequent retry.  This
................................................................................
   759    765   ** within the same process.  The argument is a pointer to an array of two
   760    766   ** integers where the first integer i the new retry count and the second
   761    767   ** integer is the delay.  If either integer is negative, then the setting
   762    768   ** is not changed but instead the prior value of that setting is written
   763    769   ** into the array entry, allowing the current retry settings to be
   764    770   ** interrogated.  The zDbName parameter is ignored.
   765    771   **
          772  +** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
   766    773   ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
   767    774   ** persistent [WAL | Write AHead Log] setting.  By default, the auxiliary
   768    775   ** write ahead log and shared memory files used for transaction control
   769    776   ** are automatically deleted when the latest connection to the database
   770    777   ** closes.  Setting persistent WAL mode causes those files to persist after
   771    778   ** close.  Persisting the files is useful when other processes that do not
   772    779   ** have write permission on the directory containing the database file want
................................................................................
   773    780   ** to read the database file, as the WAL and shared memory files must exist
   774    781   ** in order for the database to be readable.  The fourth parameter to
   775    782   ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
   776    783   ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
   777    784   ** WAL mode.  If the integer is -1, then it is overwritten with the current
   778    785   ** WAL persistence setting.
   779    786   **
          787  +** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
   780    788   ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
   781    789   ** persistent "powersafe-overwrite" or "PSOW" setting.  The PSOW setting
   782    790   ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
   783    791   ** xDeviceCharacteristics methods. The fourth parameter to
   784    792   ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
   785    793   ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
   786    794   ** mode.  If the integer is -1, then it is overwritten with the current
   787    795   ** zero-damage mode setting.
   788    796   **
          797  +** <li>[[SQLITE_FCNTL_OVERWRITE]]
   789    798   ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
   790    799   ** a write transaction to indicate that, unless it is rolled back for some
   791    800   ** reason, the entire database file will be overwritten by the current 
   792    801   ** transaction. This is used by VACUUM operations.
   793    802   **
          803  +** <li>[[SQLITE_FCNTL_VFSNAME]]
   794    804   ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
   795    805   ** all [VFSes] in the VFS stack.  The names are of all VFS shims and the
   796    806   ** final bottom-level VFS are written into memory obtained from 
   797    807   ** [sqlite3_malloc()] and the result is stored in the char* variable
   798    808   ** that the fourth parameter of [sqlite3_file_control()] points to.
   799    809   ** The caller is responsible for freeing the memory when done.  As with
   800    810   ** all file-control actions, there is no guarantee that this will actually
   801    811   ** do anything.  Callers should initialize the char* variable to a NULL
   802    812   ** pointer in case this file-control is not implemented.  This file-control
   803    813   ** is intended for diagnostic use only.
          814  +**
          815  +** <li>[[SQLITE_FCNTL_PRAGMA]]
          816  +** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA] 
          817  +** file control is sent to the open [sqlite3_file] object corresponding
          818  +** to the database file to which the pragma statement refers. ^The argument
          819  +** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
          820  +** pointers to strings (char**) in which the second element of the array
          821  +** is the name of the pragma and the third element is the argument to the
          822  +** pragma or NULL if the pragma has no argument.  ^The handler for an
          823  +** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
          824  +** of the char** argument point to a string obtained from [sqlite3_mprintf()]
          825  +** or the equivalent and that string will become the result of the pragma or
          826  +** the error message if the pragma fails. ^If the
          827  +** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal 
          828  +** [PRAGMA] processing continues.  ^If the [SQLITE_FCNTL_PRAGMA]
          829  +** file control returns [SQLITE_OK], then the parser assumes that the
          830  +** VFS has handled the PRAGMA itself and the parser generates a no-op
          831  +** prepared statement.  ^If the [SQLITE_FCNTL_PRAGMA] file control returns
          832  +** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
          833  +** that the VFS encountered an error while handling the [PRAGMA] and the
          834  +** compilation of the PRAGMA fails with an error.  ^The [S