| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.22.0. By combining all the individual C code files into this |
| 3 | +** version 3.23.0. 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. |
| | @@ -1145,13 +1145,13 @@ |
| 1145 | 1145 | ** |
| 1146 | 1146 | ** See also: [sqlite3_libversion()], |
| 1147 | 1147 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1148 | 1148 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1149 | 1149 | */ |
| 1150 | | -#define SQLITE_VERSION "3.22.0" |
| 1151 | | -#define SQLITE_VERSION_NUMBER 3022000 |
| 1152 | | -#define SQLITE_SOURCE_ID "2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2171d" |
| 1150 | +#define SQLITE_VERSION "3.23.0" |
| 1151 | +#define SQLITE_VERSION_NUMBER 3023000 |
| 1152 | +#define SQLITE_SOURCE_ID "2018-03-17 16:26:36 442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec477034540" |
| 1153 | 1153 | |
| 1154 | 1154 | /* |
| 1155 | 1155 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1156 | 1156 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1157 | 1157 | ** |
| | @@ -3518,20 +3518,20 @@ |
| 3518 | 3518 | /* |
| 3519 | 3519 | ** CAPI3REF: Formatted String Printing Functions |
| 3520 | 3520 | ** |
| 3521 | 3521 | ** These routines are work-alikes of the "printf()" family of functions |
| 3522 | 3522 | ** from the standard C library. |
| 3523 | | -** These routines understand most of the common K&R formatting options, |
| 3524 | | -** plus some additional non-standard formats, detailed below. |
| 3525 | | -** Note that some of the more obscure formatting options from recent |
| 3526 | | -** C-library standards are omitted from this implementation. |
| 3523 | +** These routines understand most of the common formatting options from |
| 3524 | +** the standard library printf() |
| 3525 | +** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]). |
| 3526 | +** See the [built-in printf()] documentation for details. |
| 3527 | 3527 | ** |
| 3528 | 3528 | ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their |
| 3529 | | -** results into memory obtained from [sqlite3_malloc()]. |
| 3529 | +** results into memory obtained from [sqlite3_malloc64()]. |
| 3530 | 3530 | ** The strings returned by these two routines should be |
| 3531 | 3531 | ** released by [sqlite3_free()]. ^Both routines return a |
| 3532 | | -** NULL pointer if [sqlite3_malloc()] is unable to allocate enough |
| 3532 | +** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough |
| 3533 | 3533 | ** memory to hold the resulting string. |
| 3534 | 3534 | ** |
| 3535 | 3535 | ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from |
| 3536 | 3536 | ** the standard C library. The result is written into the |
| 3537 | 3537 | ** buffer supplied as the second parameter whose size is given by |
| | @@ -3551,75 +3551,11 @@ |
| 3551 | 3551 | ** the zero terminator. So the longest string that can be completely |
| 3552 | 3552 | ** written will be n-1 characters. |
| 3553 | 3553 | ** |
| 3554 | 3554 | ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). |
| 3555 | 3555 | ** |
| 3556 | | -** These routines all implement some additional formatting |
| 3557 | | -** options that are useful for constructing SQL statements. |
| 3558 | | -** All of the usual printf() formatting options apply. In addition, there |
| 3559 | | -** is are "%q", "%Q", "%w" and "%z" options. |
| 3560 | | -** |
| 3561 | | -** ^(The %q option works like %s in that it substitutes a nul-terminated |
| 3562 | | -** string from the argument list. But %q also doubles every '\'' character. |
| 3563 | | -** %q is designed for use inside a string literal.)^ By doubling each '\'' |
| 3564 | | -** character it escapes that character and allows it to be inserted into |
| 3565 | | -** the string. |
| 3566 | | -** |
| 3567 | | -** For example, assume the string variable zText contains text as follows: |
| 3568 | | -** |
| 3569 | | -** <blockquote><pre> |
| 3570 | | -** char *zText = "It's a happy day!"; |
| 3571 | | -** </pre></blockquote> |
| 3572 | | -** |
| 3573 | | -** One can use this text in an SQL statement as follows: |
| 3574 | | -** |
| 3575 | | -** <blockquote><pre> |
| 3576 | | -** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText); |
| 3577 | | -** sqlite3_exec(db, zSQL, 0, 0, 0); |
| 3578 | | -** sqlite3_free(zSQL); |
| 3579 | | -** </pre></blockquote> |
| 3580 | | -** |
| 3581 | | -** Because the %q format string is used, the '\'' character in zText |
| 3582 | | -** is escaped and the SQL generated is as follows: |
| 3583 | | -** |
| 3584 | | -** <blockquote><pre> |
| 3585 | | -** INSERT INTO table1 VALUES('It''s a happy day!') |
| 3586 | | -** </pre></blockquote> |
| 3587 | | -** |
| 3588 | | -** This is correct. Had we used %s instead of %q, the generated SQL |
| 3589 | | -** would have looked like this: |
| 3590 | | -** |
| 3591 | | -** <blockquote><pre> |
| 3592 | | -** INSERT INTO table1 VALUES('It's a happy day!'); |
| 3593 | | -** </pre></blockquote> |
| 3594 | | -** |
| 3595 | | -** This second example is an SQL syntax error. As a general rule you should |
| 3596 | | -** always use %q instead of %s when inserting text into a string literal. |
| 3597 | | -** |
| 3598 | | -** ^(The %Q option works like %q except it also adds single quotes around |
| 3599 | | -** the outside of the total string. Additionally, if the parameter in the |
| 3600 | | -** argument list is a NULL pointer, %Q substitutes the text "NULL" (without |
| 3601 | | -** single quotes).)^ So, for example, one could say: |
| 3602 | | -** |
| 3603 | | -** <blockquote><pre> |
| 3604 | | -** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText); |
| 3605 | | -** sqlite3_exec(db, zSQL, 0, 0, 0); |
| 3606 | | -** sqlite3_free(zSQL); |
| 3607 | | -** </pre></blockquote> |
| 3608 | | -** |
| 3609 | | -** The code above will render a correct SQL statement in the zSQL |
| 3610 | | -** variable even if the zText variable is a NULL pointer. |
| 3611 | | -** |
| 3612 | | -** ^(The "%w" formatting option is like "%q" except that it expects to |
| 3613 | | -** be contained within double-quotes instead of single quotes, and it |
| 3614 | | -** escapes the double-quote character instead of the single-quote |
| 3615 | | -** character.)^ The "%w" formatting option is intended for safely inserting |
| 3616 | | -** table and column names into a constructed SQL statement. |
| 3617 | | -** |
| 3618 | | -** ^(The "%z" formatting option works like "%s" but with the |
| 3619 | | -** addition that after the string has been read and copied into |
| 3620 | | -** the result, [sqlite3_free()] is called on the input string.)^ |
| 3556 | +** See also: [built-in printf()], [printf() SQL function] |
| 3621 | 3557 | */ |
| 3622 | 3558 | SQLITE_API char *sqlite3_mprintf(const char*,...); |
| 3623 | 3559 | SQLITE_API char *sqlite3_vmprintf(const char*, va_list); |
| 3624 | 3560 | SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); |
| 3625 | 3561 | SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); |
| | @@ -4681,17 +4617,17 @@ |
| 4681 | 4617 | ** ^The specific value of WHERE-clause [parameter] might influence the |
| 4682 | 4618 | ** choice of query plan if the parameter is the left-hand side of a [LIKE] |
| 4683 | 4619 | ** or [GLOB] operator or if the parameter is compared to an indexed column |
| 4684 | 4620 | ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled. |
| 4685 | 4621 | ** </li> |
| 4622 | +** </ol> |
| 4686 | 4623 | ** |
| 4687 | 4624 | ** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having |
| 4688 | 4625 | ** the extra prepFlags parameter, which is a bit array consisting of zero or |
| 4689 | 4626 | ** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The |
| 4690 | 4627 | ** sqlite3_prepare_v2() interface works exactly the same as |
| 4691 | 4628 | ** sqlite3_prepare_v3() with a zero prepFlags parameter. |
| 4692 | | -** </ol> |
| 4693 | 4629 | */ |
| 4694 | 4630 | SQLITE_API int sqlite3_prepare( |
| 4695 | 4631 | sqlite3 *db, /* Database handle */ |
| 4696 | 4632 | const char *zSql, /* SQL statement, UTF-8 encoded */ |
| 4697 | 4633 | int nByte, /* Maximum length of zSql in bytes. */ |
| | @@ -8315,10 +8251,19 @@ |
| 8315 | 8251 | ** transaction rollback or database recovery operations are not included. |
| 8316 | 8252 | ** If an IO or other error occurs while writing a page to disk, the effect |
| 8317 | 8253 | ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The |
| 8318 | 8254 | ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0. |
| 8319 | 8255 | ** </dd> |
| 8256 | +** |
| 8257 | +** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt> |
| 8258 | +** <dd>This parameter returns the number of dirty cache entries that have |
| 8259 | +** been written to disk in the middle of a transaction due to the page |
| 8260 | +** cache overflowing. Transactions are more efficient if they are written |
| 8261 | +** to disk all at once. When pages spill mid-transaction, that introduces |
| 8262 | +** additional overhead. This parameter can be used help identify |
| 8263 | +** inefficiencies that can be resolve by increasing the cache size. |
| 8264 | +** </dd> |
| 8320 | 8265 | ** |
| 8321 | 8266 | ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt> |
| 8322 | 8267 | ** <dd>This parameter returns zero for the current value if and only if |
| 8323 | 8268 | ** all foreign key constraints (deferred or immediate) have been |
| 8324 | 8269 | ** resolved.)^ ^The highwater mark is always 0. |
| | @@ -8335,11 +8280,12 @@ |
| 8335 | 8280 | #define SQLITE_DBSTATUS_CACHE_HIT 7 |
| 8336 | 8281 | #define SQLITE_DBSTATUS_CACHE_MISS 8 |
| 8337 | 8282 | #define SQLITE_DBSTATUS_CACHE_WRITE 9 |
| 8338 | 8283 | #define SQLITE_DBSTATUS_DEFERRED_FKS 10 |
| 8339 | 8284 | #define SQLITE_DBSTATUS_CACHE_USED_SHARED 11 |
| 8340 | | -#define SQLITE_DBSTATUS_MAX 11 /* Largest defined DBSTATUS */ |
| 8285 | +#define SQLITE_DBSTATUS_CACHE_SPILL 12 |
| 8286 | +#define SQLITE_DBSTATUS_MAX 12 /* Largest defined DBSTATUS */ |
| 8341 | 8287 | |
| 8342 | 8288 | |
| 8343 | 8289 | /* |
| 8344 | 8290 | ** CAPI3REF: Prepared Statement Status |
| 8345 | 8291 | ** METHOD: sqlite3_stmt |
| | @@ -9815,10 +9761,132 @@ |
| 9815 | 9761 | ** |
| 9816 | 9762 | ** SQLITE_OK is returned if successful, or an SQLite error code otherwise. |
| 9817 | 9763 | */ |
| 9818 | 9764 | SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); |
| 9819 | 9765 | |
| 9766 | +/* |
| 9767 | +** CAPI3REF: Serialize a database |
| 9768 | +** |
| 9769 | +** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory |
| 9770 | +** that is a serialization of the S database on [database connection] D. |
| 9771 | +** If P is not a NULL pointer, then the size of the database in bytes |
| 9772 | +** is written into *P. |
| 9773 | +** |
| 9774 | +** For an ordinary on-disk database file, the serialization is just a |
| 9775 | +** copy of the disk file. For an in-memory database or a "TEMP" database, |
| 9776 | +** the serialization is the same sequence of bytes which would be written |
| 9777 | +** to disk if that database where backed up to disk. |
| 9778 | +** |
| 9779 | +** The usual case is that sqlite3_serialize() copies the serialization of |
| 9780 | +** the database into memory obtained from [sqlite3_malloc64()] and returns |
| 9781 | +** a pointer to that memory. The caller is responsible for freeing the |
| 9782 | +** returned value to avoid a memory leak. However, if the F argument |
| 9783 | +** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations |
| 9784 | +** are made, and the sqlite3_serialize() function will return a pointer |
| 9785 | +** to the contiguous memory representation of the database that SQLite |
| 9786 | +** is currently using for that database, or NULL if the no such contiguous |
| 9787 | +** memory representation of the database exists. A contiguous memory |
| 9788 | +** representation of the database will usually only exist if there has |
| 9789 | +** been a prior call to [sqlite3_deserialize(D,S,...)] with the same |
| 9790 | +** values of D and S. |
| 9791 | +** The size of the database is written into *P even if the |
| 9792 | +** SQLITE_SERIALIZE_NOCOPY bit is set but no contigious copy |
| 9793 | +** of the database exists. |
| 9794 | +** |
| 9795 | +** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the |
| 9796 | +** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory |
| 9797 | +** allocation error occurs. |
| 9798 | +** |
| 9799 | +** This interface is only available if SQLite is compiled with the |
| 9800 | +** [SQLITE_ENABLE_DESERIALIZE] option. |
| 9801 | +*/ |
| 9802 | +SQLITE_API unsigned char *sqlite3_serialize( |
| 9803 | + sqlite3 *db, /* The database connection */ |
| 9804 | + const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */ |
| 9805 | + sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */ |
| 9806 | + unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */ |
| 9807 | +); |
| 9808 | + |
| 9809 | +/* |
| 9810 | +** CAPI3REF: Flags for sqlite3_serialize |
| 9811 | +** |
| 9812 | +** Zero or more of the following constants can be OR-ed together for |
| 9813 | +** the F argument to [sqlite3_serialize(D,S,P,F)]. |
| 9814 | +** |
| 9815 | +** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return |
| 9816 | +** a pointer to contiguous in-memory database that it is currently using, |
| 9817 | +** without making a copy of the database. If SQLite is not currently using |
| 9818 | +** a contiguous in-memory database, then this option causes |
| 9819 | +** [sqlite3_serialize()] to return a NULL pointer. SQLite will only be |
| 9820 | +** using a contiguous in-memory database if it has been initialized by a |
| 9821 | +** prior call to [sqlite3_deserialize()]. |
| 9822 | +*/ |
| 9823 | +#define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */ |
| 9824 | + |
| 9825 | +/* |
| 9826 | +** CAPI3REF: Deserialize a database |
| 9827 | +** |
| 9828 | +** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the |
| 9829 | +** [database connection] D to disconnection from database S and then |
| 9830 | +** reopen S as an in-memory database based on the serialization contained |
| 9831 | +** in P. The serialized database P is N bytes in size. M is the size of |
| 9832 | +** the buffer P, which might be larger than N. If M is larger than N, and |
| 9833 | +** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is |
| 9834 | +** permitted to add content to the in-memory database as long as the total |
| 9835 | +** size does not exceed M bytes. |
| 9836 | +** |
| 9837 | +** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will |
| 9838 | +** invoke sqlite3_free() on the serialization buffer when the database |
| 9839 | +** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then |
| 9840 | +** SQLite will try to increase the buffer size using sqlite3_realloc64() |
| 9841 | +** if writes on the database cause it to grow larger than M bytes. |
| 9842 | +** |
| 9843 | +** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the |
| 9844 | +** database is currently in a read transaction or is involved in a backup |
| 9845 | +** operation. |
| 9846 | +** |
| 9847 | +** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the |
| 9848 | +** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then |
| 9849 | +** [sqlite3_free()] is invoked on argument P prior to returning. |
| 9850 | +** |
| 9851 | +** This interface is only available if SQLite is compiled with the |
| 9852 | +** [SQLITE_ENABLE_DESERIALIZE] option. |
| 9853 | +*/ |
| 9854 | +SQLITE_API int sqlite3_deserialize( |
| 9855 | + sqlite3 *db, /* The database connection */ |
| 9856 | + const char *zSchema, /* Which DB to reopen with the deserialization */ |
| 9857 | + unsigned char *pData, /* The serialized database content */ |
| 9858 | + sqlite3_int64 szDb, /* Number bytes in the deserialization */ |
| 9859 | + sqlite3_int64 szBuf, /* Total size of buffer pData[] */ |
| 9860 | + unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ |
| 9861 | +); |
| 9862 | + |
| 9863 | +/* |
| 9864 | +** CAPI3REF: Flags for sqlite3_deserialize() |
| 9865 | +** |
| 9866 | +** The following are allowed values for 6th argument (the F argument) to |
| 9867 | +** the [sqlite3_deserialize(D,S,P,N,M,F)] interface. |
| 9868 | +** |
| 9869 | +** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization |
| 9870 | +** in the P argument is held in memory obtained from [sqlite3_malloc64()] |
| 9871 | +** and that SQLite should take ownership of this memory and automatically |
| 9872 | +** free it when it has finished using it. Without this flag, the caller |
| 9873 | +** is resposible for freeing any dynamically allocated memory. |
| 9874 | +** |
| 9875 | +** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to |
| 9876 | +** grow the size of the database using calls to [sqlite3_realloc64()]. This |
| 9877 | +** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used. |
| 9878 | +** Without this flag, the deserialized database cannot increase in size beyond |
| 9879 | +** the number of bytes specified by the M parameter. |
| 9880 | +** |
| 9881 | +** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database |
| 9882 | +** should be treated as read-only. |
| 9883 | +*/ |
| 9884 | +#define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */ |
| 9885 | +#define SQLITE_DESERIALIZE_RESIZEABLE 2 /* Resize using sqlite3_realloc64() */ |
| 9886 | +#define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */ |
| 9887 | + |
| 9820 | 9888 | /* |
| 9821 | 9889 | ** Undo the hack that converts floating point types to integer for |
| 9822 | 9890 | ** builds on processors without floating point support. |
| 9823 | 9891 | */ |
| 9824 | 9892 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| | @@ -9962,20 +10030,27 @@ |
| 9962 | 10030 | #endif |
| 9963 | 10031 | |
| 9964 | 10032 | |
| 9965 | 10033 | /* |
| 9966 | 10034 | ** CAPI3REF: Session Object Handle |
| 10035 | +** |
| 10036 | +** An instance of this object is a [session] that can be used to |
| 10037 | +** record changes to a database. |
| 9967 | 10038 | */ |
| 9968 | 10039 | typedef struct sqlite3_session sqlite3_session; |
| 9969 | 10040 | |
| 9970 | 10041 | /* |
| 9971 | 10042 | ** CAPI3REF: Changeset Iterator Handle |
| 10043 | +** |
| 10044 | +** An instance of this object acts as a cursor for iterating |
| 10045 | +** over the elements of a [changeset] or [patchset]. |
| 9972 | 10046 | */ |
| 9973 | 10047 | typedef struct sqlite3_changeset_iter sqlite3_changeset_iter; |
| 9974 | 10048 | |
| 9975 | 10049 | /* |
| 9976 | 10050 | ** CAPI3REF: Create A New Session Object |
| 10051 | +** CONSTRUCTOR: sqlite3_session |
| 9977 | 10052 | ** |
| 9978 | 10053 | ** Create a new session object attached to database handle db. If successful, |
| 9979 | 10054 | ** a pointer to the new object is written to *ppSession and SQLITE_OK is |
| 9980 | 10055 | ** returned. If an error occurs, *ppSession is set to NULL and an SQLite |
| 9981 | 10056 | ** error code (e.g. SQLITE_NOMEM) is returned. |
| | @@ -10008,10 +10083,11 @@ |
| 10008 | 10083 | sqlite3_session **ppSession /* OUT: New session object */ |
| 10009 | 10084 | ); |
| 10010 | 10085 | |
| 10011 | 10086 | /* |
| 10012 | 10087 | ** CAPI3REF: Delete A Session Object |
| 10088 | +** DESTRUCTOR: sqlite3_session |
| 10013 | 10089 | ** |
| 10014 | 10090 | ** Delete a session object previously allocated using |
| 10015 | 10091 | ** [sqlite3session_create()]. Once a session object has been deleted, the |
| 10016 | 10092 | ** results of attempting to use pSession with any other session module |
| 10017 | 10093 | ** function are undefined. |
| | @@ -10023,10 +10099,11 @@ |
| 10023 | 10099 | SQLITE_API void sqlite3session_delete(sqlite3_session *pSession); |
| 10024 | 10100 | |
| 10025 | 10101 | |
| 10026 | 10102 | /* |
| 10027 | 10103 | ** CAPI3REF: Enable Or Disable A Session Object |
| 10104 | +** METHOD: sqlite3_session |
| 10028 | 10105 | ** |
| 10029 | 10106 | ** Enable or disable the recording of changes by a session object. When |
| 10030 | 10107 | ** enabled, a session object records changes made to the database. When |
| 10031 | 10108 | ** disabled - it does not. A newly created session object is enabled. |
| 10032 | 10109 | ** Refer to the documentation for [sqlite3session_changeset()] for further |
| | @@ -10042,10 +10119,11 @@ |
| 10042 | 10119 | */ |
| 10043 | 10120 | SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable); |
| 10044 | 10121 | |
| 10045 | 10122 | /* |
| 10046 | 10123 | ** CAPI3REF: Set Or Clear the Indirect Change Flag |
| 10124 | +** METHOD: sqlite3_session |
| 10047 | 10125 | ** |
| 10048 | 10126 | ** Each change recorded by a session object is marked as either direct or |
| 10049 | 10127 | ** indirect. A change is marked as indirect if either: |
| 10050 | 10128 | ** |
| 10051 | 10129 | ** <ul> |
| | @@ -10071,10 +10149,11 @@ |
| 10071 | 10149 | */ |
| 10072 | 10150 | SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect); |
| 10073 | 10151 | |
| 10074 | 10152 | /* |
| 10075 | 10153 | ** CAPI3REF: Attach A Table To A Session Object |
| 10154 | +** METHOD: sqlite3_session |
| 10076 | 10155 | ** |
| 10077 | 10156 | ** If argument zTab is not NULL, then it is the name of a table to attach |
| 10078 | 10157 | ** to the session object passed as the first argument. All subsequent changes |
| 10079 | 10158 | ** made to the table while the session object is enabled will be recorded. See |
| 10080 | 10159 | ** documentation for [sqlite3session_changeset()] for further details. |
| | @@ -10133,10 +10212,11 @@ |
| 10133 | 10212 | const char *zTab /* Table name */ |
| 10134 | 10213 | ); |
| 10135 | 10214 | |
| 10136 | 10215 | /* |
| 10137 | 10216 | ** CAPI3REF: Set a table filter on a Session Object. |
| 10217 | +** METHOD: sqlite3_session |
| 10138 | 10218 | ** |
| 10139 | 10219 | ** The second argument (xFilter) is the "filter callback". For changes to rows |
| 10140 | 10220 | ** in tables that are not attached to the Session object, the filter is called |
| 10141 | 10221 | ** to determine whether changes to the table's rows should be tracked or not. |
| 10142 | 10222 | ** If xFilter returns 0, changes is not tracked. Note that once a table is |
| | @@ -10151,10 +10231,11 @@ |
| 10151 | 10231 | void *pCtx /* First argument passed to xFilter */ |
| 10152 | 10232 | ); |
| 10153 | 10233 | |
| 10154 | 10234 | /* |
| 10155 | 10235 | ** CAPI3REF: Generate A Changeset From A Session Object |
| 10236 | +** METHOD: sqlite3_session |
| 10156 | 10237 | ** |
| 10157 | 10238 | ** Obtain a changeset containing changes to the tables attached to the |
| 10158 | 10239 | ** session object passed as the first argument. If successful, |
| 10159 | 10240 | ** set *ppChangeset to point to a buffer containing the changeset |
| 10160 | 10241 | ** and *pnChangeset to the size of the changeset in bytes before returning |
| | @@ -10260,11 +10341,12 @@ |
| 10260 | 10341 | int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */ |
| 10261 | 10342 | void **ppChangeset /* OUT: Buffer containing changeset */ |
| 10262 | 10343 | ); |
| 10263 | 10344 | |
| 10264 | 10345 | /* |
| 10265 | | -** CAPI3REF: Load The Difference Between Tables Into A Session |
| 10346 | +** CAPI3REF: Load The Difference Between Tables Into A Session |
| 10347 | +** METHOD: sqlite3_session |
| 10266 | 10348 | ** |
| 10267 | 10349 | ** If it is not already attached to the session object passed as the first |
| 10268 | 10350 | ** argument, this function attaches table zTbl in the same manner as the |
| 10269 | 10351 | ** [sqlite3session_attach()] function. If zTbl does not exist, or if it |
| 10270 | 10352 | ** does not have a primary key, this function is a no-op (but does not return |
| | @@ -10325,10 +10407,11 @@ |
| 10325 | 10407 | ); |
| 10326 | 10408 | |
| 10327 | 10409 | |
| 10328 | 10410 | /* |
| 10329 | 10411 | ** CAPI3REF: Generate A Patchset From A Session Object |
| 10412 | +** METHOD: sqlite3_session |
| 10330 | 10413 | ** |
| 10331 | 10414 | ** The differences between a patchset and a changeset are that: |
| 10332 | 10415 | ** |
| 10333 | 10416 | ** <ul> |
| 10334 | 10417 | ** <li> DELETE records consist of the primary key fields only. The |
| | @@ -10376,10 +10459,11 @@ |
| 10376 | 10459 | */ |
| 10377 | 10460 | SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession); |
| 10378 | 10461 | |
| 10379 | 10462 | /* |
| 10380 | 10463 | ** CAPI3REF: Create An Iterator To Traverse A Changeset |
| 10464 | +** CONSTRUCTOR: sqlite3_changeset_iter |
| 10381 | 10465 | ** |
| 10382 | 10466 | ** Create an iterator used to iterate through the contents of a changeset. |
| 10383 | 10467 | ** If successful, *pp is set to point to the iterator handle and SQLITE_OK |
| 10384 | 10468 | ** is returned. Otherwise, if an error occurs, *pp is set to zero and an |
| 10385 | 10469 | ** SQLite error code is returned. |
| | @@ -10416,10 +10500,11 @@ |
| 10416 | 10500 | ); |
| 10417 | 10501 | |
| 10418 | 10502 | |
| 10419 | 10503 | /* |
| 10420 | 10504 | ** CAPI3REF: Advance A Changeset Iterator |
| 10505 | +** METHOD: sqlite3_changeset_iter |
| 10421 | 10506 | ** |
| 10422 | 10507 | ** This function may only be used with iterators created by function |
| 10423 | 10508 | ** [sqlite3changeset_start()]. If it is called on an iterator passed to |
| 10424 | 10509 | ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE |
| 10425 | 10510 | ** is returned and the call has no effect. |
| | @@ -10440,10 +10525,11 @@ |
| 10440 | 10525 | */ |
| 10441 | 10526 | SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter); |
| 10442 | 10527 | |
| 10443 | 10528 | /* |
| 10444 | 10529 | ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator |
| 10530 | +** METHOD: sqlite3_changeset_iter |
| 10445 | 10531 | ** |
| 10446 | 10532 | ** The pIter argument passed to this function may either be an iterator |
| 10447 | 10533 | ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator |
| 10448 | 10534 | ** created by [sqlite3changeset_start()]. In the latter case, the most recent |
| 10449 | 10535 | ** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this |
| | @@ -10474,10 +10560,11 @@ |
| 10474 | 10560 | int *pbIndirect /* OUT: True for an 'indirect' change */ |
| 10475 | 10561 | ); |
| 10476 | 10562 | |
| 10477 | 10563 | /* |
| 10478 | 10564 | ** CAPI3REF: Obtain The Primary Key Definition Of A Table |
| 10565 | +** METHOD: sqlite3_changeset_iter |
| 10479 | 10566 | ** |
| 10480 | 10567 | ** For each modified table, a changeset includes the following: |
| 10481 | 10568 | ** |
| 10482 | 10569 | ** <ul> |
| 10483 | 10570 | ** <li> The number of columns in the table, and |
| | @@ -10505,10 +10592,11 @@ |
| 10505 | 10592 | int *pnCol /* OUT: Number of entries in output array */ |
| 10506 | 10593 | ); |
| 10507 | 10594 | |
| 10508 | 10595 | /* |
| 10509 | 10596 | ** CAPI3REF: Obtain old.* Values From A Changeset Iterator |
| 10597 | +** METHOD: sqlite3_changeset_iter |
| 10510 | 10598 | ** |
| 10511 | 10599 | ** The pIter argument passed to this function may either be an iterator |
| 10512 | 10600 | ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator |
| 10513 | 10601 | ** created by [sqlite3changeset_start()]. In the latter case, the most recent |
| 10514 | 10602 | ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW. |
| | @@ -10535,10 +10623,11 @@ |
| 10535 | 10623 | sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */ |
| 10536 | 10624 | ); |
| 10537 | 10625 | |
| 10538 | 10626 | /* |
| 10539 | 10627 | ** CAPI3REF: Obtain new.* Values From A Changeset Iterator |
| 10628 | +** METHOD: sqlite3_changeset_iter |
| 10540 | 10629 | ** |
| 10541 | 10630 | ** The pIter argument passed to this function may either be an iterator |
| 10542 | 10631 | ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator |
| 10543 | 10632 | ** created by [sqlite3changeset_start()]. In the latter case, the most recent |
| 10544 | 10633 | ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW. |
| | @@ -10568,10 +10657,11 @@ |
| 10568 | 10657 | sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */ |
| 10569 | 10658 | ); |
| 10570 | 10659 | |
| 10571 | 10660 | /* |
| 10572 | 10661 | ** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator |
| 10662 | +** METHOD: sqlite3_changeset_iter |
| 10573 | 10663 | ** |
| 10574 | 10664 | ** This function should only be used with iterator objects passed to a |
| 10575 | 10665 | ** conflict-handler callback by [sqlite3changeset_apply()] with either |
| 10576 | 10666 | ** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function |
| 10577 | 10667 | ** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue |
| | @@ -10595,10 +10685,11 @@ |
| 10595 | 10685 | sqlite3_value **ppValue /* OUT: Value from conflicting row */ |
| 10596 | 10686 | ); |
| 10597 | 10687 | |
| 10598 | 10688 | /* |
| 10599 | 10689 | ** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations |
| 10690 | +** METHOD: sqlite3_changeset_iter |
| 10600 | 10691 | ** |
| 10601 | 10692 | ** This function may only be called with an iterator passed to an |
| 10602 | 10693 | ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case |
| 10603 | 10694 | ** it sets the output variable to the total number of known foreign key |
| 10604 | 10695 | ** violations in the destination database and returns SQLITE_OK. |
| | @@ -10611,10 +10702,11 @@ |
| 10611 | 10702 | ); |
| 10612 | 10703 | |
| 10613 | 10704 | |
| 10614 | 10705 | /* |
| 10615 | 10706 | ** CAPI3REF: Finalize A Changeset Iterator |
| 10707 | +** METHOD: sqlite3_changeset_iter |
| 10616 | 10708 | ** |
| 10617 | 10709 | ** This function is used to finalize an iterator allocated with |
| 10618 | 10710 | ** [sqlite3changeset_start()]. |
| 10619 | 10711 | ** |
| 10620 | 10712 | ** This function should only be called on iterators created using the |
| | @@ -10627,18 +10719,20 @@ |
| 10627 | 10719 | ** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an |
| 10628 | 10720 | ** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding |
| 10629 | 10721 | ** to that error is returned by this function. Otherwise, SQLITE_OK is |
| 10630 | 10722 | ** returned. This is to allow the following pattern (pseudo-code): |
| 10631 | 10723 | ** |
| 10724 | +** <pre> |
| 10632 | 10725 | ** sqlite3changeset_start(); |
| 10633 | 10726 | ** while( SQLITE_ROW==sqlite3changeset_next() ){ |
| 10634 | 10727 | ** // Do something with change. |
| 10635 | 10728 | ** } |
| 10636 | 10729 | ** rc = sqlite3changeset_finalize(); |
| 10637 | 10730 | ** if( rc!=SQLITE_OK ){ |
| 10638 | 10731 | ** // An error has occurred |
| 10639 | 10732 | ** } |
| 10733 | +** </pre> |
| 10640 | 10734 | */ |
| 10641 | 10735 | SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter); |
| 10642 | 10736 | |
| 10643 | 10737 | /* |
| 10644 | 10738 | ** CAPI3REF: Invert A Changeset |
| | @@ -10682,10 +10776,11 @@ |
| 10682 | 10776 | ** |
| 10683 | 10777 | ** This function combines the two input changesets using an |
| 10684 | 10778 | ** sqlite3_changegroup object. Calling it produces similar results as the |
| 10685 | 10779 | ** following code fragment: |
| 10686 | 10780 | ** |
| 10781 | +** <pre> |
| 10687 | 10782 | ** sqlite3_changegroup *pGrp; |
| 10688 | 10783 | ** rc = sqlite3_changegroup_new(&pGrp); |
| 10689 | 10784 | ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA); |
| 10690 | 10785 | ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB); |
| 10691 | 10786 | ** if( rc==SQLITE_OK ){ |
| | @@ -10692,10 +10787,11 @@ |
| 10692 | 10787 | ** rc = sqlite3changegroup_output(pGrp, pnOut, ppOut); |
| 10693 | 10788 | ** }else{ |
| 10694 | 10789 | ** *ppOut = 0; |
| 10695 | 10790 | ** *pnOut = 0; |
| 10696 | 10791 | ** } |
| 10792 | +** </pre> |
| 10697 | 10793 | ** |
| 10698 | 10794 | ** Refer to the sqlite3_changegroup documentation below for details. |
| 10699 | 10795 | */ |
| 10700 | 10796 | SQLITE_API int sqlite3changeset_concat( |
| 10701 | 10797 | int nA, /* Number of bytes in buffer pA */ |
| | @@ -10707,15 +10803,19 @@ |
| 10707 | 10803 | ); |
| 10708 | 10804 | |
| 10709 | 10805 | |
| 10710 | 10806 | /* |
| 10711 | 10807 | ** CAPI3REF: Changegroup Handle |
| 10808 | +** |
| 10809 | +** A changegroup is an object used to combine two or more |
| 10810 | +** [changesets] or [patchsets] |
| 10712 | 10811 | */ |
| 10713 | 10812 | typedef struct sqlite3_changegroup sqlite3_changegroup; |
| 10714 | 10813 | |
| 10715 | 10814 | /* |
| 10716 | 10815 | ** CAPI3REF: Create A New Changegroup Object |
| 10816 | +** CONSTRUCTOR: sqlite3_changegroup |
| 10717 | 10817 | ** |
| 10718 | 10818 | ** An sqlite3_changegroup object is used to combine two or more changesets |
| 10719 | 10819 | ** (or patchsets) into a single changeset (or patchset). A single changegroup |
| 10720 | 10820 | ** object may combine changesets or patchsets, but not both. The output is |
| 10721 | 10821 | ** always in the same format as the input. |
| | @@ -10749,10 +10849,11 @@ |
| 10749 | 10849 | */ |
| 10750 | 10850 | SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp); |
| 10751 | 10851 | |
| 10752 | 10852 | /* |
| 10753 | 10853 | ** CAPI3REF: Add A Changeset To A Changegroup |
| 10854 | +** METHOD: sqlite3_changegroup |
| 10754 | 10855 | ** |
| 10755 | 10856 | ** Add all changes within the changeset (or patchset) in buffer pData (size |
| 10756 | 10857 | ** nData bytes) to the changegroup. |
| 10757 | 10858 | ** |
| 10758 | 10859 | ** If the buffer contains a patchset, then all prior calls to this function |
| | @@ -10826,10 +10927,11 @@ |
| 10826 | 10927 | */ |
| 10827 | 10928 | SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData); |
| 10828 | 10929 | |
| 10829 | 10930 | /* |
| 10830 | 10931 | ** CAPI3REF: Obtain A Composite Changeset From A Changegroup |
| 10932 | +** METHOD: sqlite3_changegroup |
| 10831 | 10933 | ** |
| 10832 | 10934 | ** Obtain a buffer containing a changeset (or patchset) representing the |
| 10833 | 10935 | ** current contents of the changegroup. If the inputs to the changegroup |
| 10834 | 10936 | ** were themselves changesets, the output is a changeset. Or, if the |
| 10835 | 10937 | ** inputs were patchsets, the output is also a patchset. |
| | @@ -10856,10 +10958,11 @@ |
| 10856 | 10958 | void **ppData /* OUT: Pointer to output buffer */ |
| 10857 | 10959 | ); |
| 10858 | 10960 | |
| 10859 | 10961 | /* |
| 10860 | 10962 | ** CAPI3REF: Delete A Changegroup Object |
| 10963 | +** DESTRUCTOR: sqlite3_changegroup |
| 10861 | 10964 | */ |
| 10862 | 10965 | SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); |
| 10863 | 10966 | |
| 10864 | 10967 | /* |
| 10865 | 10968 | ** CAPI3REF: Apply A Changeset To A Database |
| | @@ -12671,27 +12774,29 @@ |
| 12671 | 12774 | #define TK_THEN 138 |
| 12672 | 12775 | #define TK_ELSE 139 |
| 12673 | 12776 | #define TK_INDEX 140 |
| 12674 | 12777 | #define TK_ALTER 141 |
| 12675 | 12778 | #define TK_ADD 142 |
| 12676 | | -#define TK_ISNOT 143 |
| 12677 | | -#define TK_FUNCTION 144 |
| 12678 | | -#define TK_COLUMN 145 |
| 12679 | | -#define TK_AGG_FUNCTION 146 |
| 12680 | | -#define TK_AGG_COLUMN 147 |
| 12681 | | -#define TK_UMINUS 148 |
| 12682 | | -#define TK_UPLUS 149 |
| 12683 | | -#define TK_REGISTER 150 |
| 12684 | | -#define TK_VECTOR 151 |
| 12685 | | -#define TK_SELECT_COLUMN 152 |
| 12686 | | -#define TK_IF_NULL_ROW 153 |
| 12687 | | -#define TK_ASTERISK 154 |
| 12688 | | -#define TK_SPAN 155 |
| 12689 | | -#define TK_END_OF_FILE 156 |
| 12690 | | -#define TK_UNCLOSED_STRING 157 |
| 12691 | | -#define TK_SPACE 158 |
| 12692 | | -#define TK_ILLEGAL 159 |
| 12779 | +#define TK_TRUEFALSE 143 |
| 12780 | +#define TK_ISNOT 144 |
| 12781 | +#define TK_FUNCTION 145 |
| 12782 | +#define TK_COLUMN 146 |
| 12783 | +#define TK_AGG_FUNCTION 147 |
| 12784 | +#define TK_AGG_COLUMN 148 |
| 12785 | +#define TK_UMINUS 149 |
| 12786 | +#define TK_UPLUS 150 |
| 12787 | +#define TK_TRUTH 151 |
| 12788 | +#define TK_REGISTER 152 |
| 12789 | +#define TK_VECTOR 153 |
| 12790 | +#define TK_SELECT_COLUMN 154 |
| 12791 | +#define TK_IF_NULL_ROW 155 |
| 12792 | +#define TK_ASTERISK 156 |
| 12793 | +#define TK_SPAN 157 |
| 12794 | +#define TK_END_OF_FILE 158 |
| 12795 | +#define TK_UNCLOSED_STRING 159 |
| 12796 | +#define TK_SPACE 160 |
| 12797 | +#define TK_ILLEGAL 161 |
| 12693 | 12798 | |
| 12694 | 12799 | /* The token codes above must all fit in 8 bits */ |
| 12695 | 12800 | #define TKFLG_MASK 0xff |
| 12696 | 12801 | |
| 12697 | 12802 | /* Flags that can be added to a token code when it is not |
| | @@ -13933,84 +14038,85 @@ |
| 13933 | 14038 | #define OP_Divide 91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ |
| 13934 | 14039 | #define OP_Remainder 92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ |
| 13935 | 14040 | #define OP_Concat 93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ |
| 13936 | 14041 | #define OP_Compare 94 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 13937 | 14042 | #define OP_BitNot 95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */ |
| 13938 | | -#define OP_Offset 96 /* synopsis: r[P3] = sqlite_offset(P1) */ |
| 14043 | +#define OP_IsTrue 96 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */ |
| 13939 | 14044 | #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */ |
| 13940 | | -#define OP_Column 98 /* synopsis: r[P3]=PX */ |
| 13941 | | -#define OP_Affinity 99 /* synopsis: affinity(r[P1@P2]) */ |
| 13942 | | -#define OP_MakeRecord 100 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 13943 | | -#define OP_Count 101 /* synopsis: r[P2]=count() */ |
| 13944 | | -#define OP_ReadCookie 102 |
| 13945 | | -#define OP_SetCookie 103 |
| 13946 | | -#define OP_ReopenIdx 104 /* synopsis: root=P2 iDb=P3 */ |
| 13947 | | -#define OP_OpenRead 105 /* synopsis: root=P2 iDb=P3 */ |
| 13948 | | -#define OP_OpenWrite 106 /* synopsis: root=P2 iDb=P3 */ |
| 13949 | | -#define OP_OpenDup 107 |
| 13950 | | -#define OP_OpenAutoindex 108 /* synopsis: nColumn=P2 */ |
| 13951 | | -#define OP_OpenEphemeral 109 /* synopsis: nColumn=P2 */ |
| 13952 | | -#define OP_SorterOpen 110 |
| 13953 | | -#define OP_SequenceTest 111 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 13954 | | -#define OP_OpenPseudo 112 /* synopsis: P3 columns in r[P2] */ |
| 13955 | | -#define OP_Close 113 |
| 13956 | | -#define OP_ColumnsUsed 114 |
| 13957 | | -#define OP_Sequence 115 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 13958 | | -#define OP_NewRowid 116 /* synopsis: r[P2]=rowid */ |
| 13959 | | -#define OP_Insert 117 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 13960 | | -#define OP_InsertInt 118 /* synopsis: intkey=P3 data=r[P2] */ |
| 13961 | | -#define OP_Delete 119 |
| 13962 | | -#define OP_ResetCount 120 |
| 13963 | | -#define OP_SorterCompare 121 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 13964 | | -#define OP_SorterData 122 /* synopsis: r[P2]=data */ |
| 13965 | | -#define OP_RowData 123 /* synopsis: r[P2]=data */ |
| 13966 | | -#define OP_Rowid 124 /* synopsis: r[P2]=rowid */ |
| 13967 | | -#define OP_NullRow 125 |
| 13968 | | -#define OP_SeekEnd 126 |
| 13969 | | -#define OP_SorterInsert 127 /* synopsis: key=r[P2] */ |
| 13970 | | -#define OP_IdxInsert 128 /* synopsis: key=r[P2] */ |
| 13971 | | -#define OP_IdxDelete 129 /* synopsis: key=r[P2@P3] */ |
| 13972 | | -#define OP_DeferredSeek 130 /* synopsis: Move P3 to P1.rowid if needed */ |
| 13973 | | -#define OP_IdxRowid 131 /* synopsis: r[P2]=rowid */ |
| 14045 | +#define OP_Offset 98 /* synopsis: r[P3] = sqlite_offset(P1) */ |
| 14046 | +#define OP_Column 99 /* synopsis: r[P3]=PX */ |
| 14047 | +#define OP_Affinity 100 /* synopsis: affinity(r[P1@P2]) */ |
| 14048 | +#define OP_MakeRecord 101 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 14049 | +#define OP_Count 102 /* synopsis: r[P2]=count() */ |
| 14050 | +#define OP_ReadCookie 103 |
| 14051 | +#define OP_SetCookie 104 |
| 14052 | +#define OP_ReopenIdx 105 /* synopsis: root=P2 iDb=P3 */ |
| 14053 | +#define OP_OpenRead 106 /* synopsis: root=P2 iDb=P3 */ |
| 14054 | +#define OP_OpenWrite 107 /* synopsis: root=P2 iDb=P3 */ |
| 14055 | +#define OP_OpenDup 108 |
| 14056 | +#define OP_OpenAutoindex 109 /* synopsis: nColumn=P2 */ |
| 14057 | +#define OP_OpenEphemeral 110 /* synopsis: nColumn=P2 */ |
| 14058 | +#define OP_SorterOpen 111 |
| 14059 | +#define OP_SequenceTest 112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 14060 | +#define OP_OpenPseudo 113 /* synopsis: P3 columns in r[P2] */ |
| 14061 | +#define OP_Close 114 |
| 14062 | +#define OP_ColumnsUsed 115 |
| 14063 | +#define OP_Sequence 116 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 14064 | +#define OP_NewRowid 117 /* synopsis: r[P2]=rowid */ |
| 14065 | +#define OP_Insert 118 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 14066 | +#define OP_InsertInt 119 /* synopsis: intkey=P3 data=r[P2] */ |
| 14067 | +#define OP_Delete 120 |
| 14068 | +#define OP_ResetCount 121 |
| 14069 | +#define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 14070 | +#define OP_SorterData 123 /* synopsis: r[P2]=data */ |
| 14071 | +#define OP_RowData 124 /* synopsis: r[P2]=data */ |
| 14072 | +#define OP_Rowid 125 /* synopsis: r[P2]=rowid */ |
| 14073 | +#define OP_NullRow 126 |
| 14074 | +#define OP_SeekEnd 127 |
| 14075 | +#define OP_SorterInsert 128 /* synopsis: key=r[P2] */ |
| 14076 | +#define OP_IdxInsert 129 /* synopsis: key=r[P2] */ |
| 14077 | +#define OP_IdxDelete 130 /* synopsis: key=r[P2@P3] */ |
| 14078 | +#define OP_DeferredSeek 131 /* synopsis: Move P3 to P1.rowid if needed */ |
| 13974 | 14079 | #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ |
| 13975 | | -#define OP_Destroy 133 |
| 13976 | | -#define OP_Clear 134 |
| 13977 | | -#define OP_ResetSorter 135 |
| 13978 | | -#define OP_CreateBtree 136 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ |
| 13979 | | -#define OP_SqlExec 137 |
| 13980 | | -#define OP_ParseSchema 138 |
| 13981 | | -#define OP_LoadAnalysis 139 |
| 13982 | | -#define OP_DropTable 140 |
| 13983 | | -#define OP_DropIndex 141 |
| 13984 | | -#define OP_DropTrigger 142 |
| 13985 | | -#define OP_IntegrityCk 143 |
| 13986 | | -#define OP_RowSetAdd 144 /* synopsis: rowset(P1)=r[P2] */ |
| 13987 | | -#define OP_Param 145 |
| 13988 | | -#define OP_FkCounter 146 /* synopsis: fkctr[P1]+=P2 */ |
| 13989 | | -#define OP_MemMax 147 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 13990 | | -#define OP_OffsetLimit 148 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 13991 | | -#define OP_AggStep0 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 13992 | | -#define OP_AggStep 150 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 13993 | | -#define OP_AggFinal 151 /* synopsis: accum=r[P1] N=P2 */ |
| 13994 | | -#define OP_Expire 152 |
| 13995 | | -#define OP_TableLock 153 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 13996 | | -#define OP_VBegin 154 |
| 13997 | | -#define OP_VCreate 155 |
| 13998 | | -#define OP_VDestroy 156 |
| 13999 | | -#define OP_VOpen 157 |
| 14000 | | -#define OP_VColumn 158 /* synopsis: r[P3]=vcolumn(P2) */ |
| 14001 | | -#define OP_VRename 159 |
| 14002 | | -#define OP_Pagecount 160 |
| 14003 | | -#define OP_MaxPgcnt 161 |
| 14004 | | -#define OP_PureFunc0 162 |
| 14005 | | -#define OP_Function0 163 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 14006 | | -#define OP_PureFunc 164 |
| 14007 | | -#define OP_Function 165 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 14008 | | -#define OP_Trace 166 |
| 14009 | | -#define OP_CursorHint 167 |
| 14010 | | -#define OP_Noop 168 |
| 14011 | | -#define OP_Explain 169 |
| 14080 | +#define OP_IdxRowid 133 /* synopsis: r[P2]=rowid */ |
| 14081 | +#define OP_Destroy 134 |
| 14082 | +#define OP_Clear 135 |
| 14083 | +#define OP_ResetSorter 136 |
| 14084 | +#define OP_CreateBtree 137 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ |
| 14085 | +#define OP_SqlExec 138 |
| 14086 | +#define OP_ParseSchema 139 |
| 14087 | +#define OP_LoadAnalysis 140 |
| 14088 | +#define OP_DropTable 141 |
| 14089 | +#define OP_DropIndex 142 |
| 14090 | +#define OP_DropTrigger 143 |
| 14091 | +#define OP_IntegrityCk 144 |
| 14092 | +#define OP_RowSetAdd 145 /* synopsis: rowset(P1)=r[P2] */ |
| 14093 | +#define OP_Param 146 |
| 14094 | +#define OP_FkCounter 147 /* synopsis: fkctr[P1]+=P2 */ |
| 14095 | +#define OP_MemMax 148 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 14096 | +#define OP_OffsetLimit 149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 14097 | +#define OP_AggStep0 150 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 14098 | +#define OP_AggStep 151 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 14099 | +#define OP_AggFinal 152 /* synopsis: accum=r[P1] N=P2 */ |
| 14100 | +#define OP_Expire 153 |
| 14101 | +#define OP_TableLock 154 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 14102 | +#define OP_VBegin 155 |
| 14103 | +#define OP_VCreate 156 |
| 14104 | +#define OP_VDestroy 157 |
| 14105 | +#define OP_VOpen 158 |
| 14106 | +#define OP_VColumn 159 /* synopsis: r[P3]=vcolumn(P2) */ |
| 14107 | +#define OP_VRename 160 |
| 14108 | +#define OP_Pagecount 161 |
| 14109 | +#define OP_MaxPgcnt 162 |
| 14110 | +#define OP_PureFunc0 163 |
| 14111 | +#define OP_Function0 164 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 14112 | +#define OP_PureFunc 165 |
| 14113 | +#define OP_Function 166 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 14114 | +#define OP_Trace 167 |
| 14115 | +#define OP_CursorHint 168 |
| 14116 | +#define OP_Noop 169 |
| 14117 | +#define OP_Explain 170 |
| 14012 | 14118 | |
| 14013 | 14119 | /* Properties such as "out2" or "jump" that are specified in |
| 14014 | 14120 | ** comments following the "case" for each opcode in the vdbe.c |
| 14015 | 14121 | ** are encoded into bitvectors as follows: |
| 14016 | 14122 | */ |
| | @@ -14031,20 +14137,20 @@ |
| 14031 | 14137 | /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x02,\ |
| 14032 | 14138 | /* 64 */ 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00,\ |
| 14033 | 14139 | /* 72 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 14034 | 14140 | /* 80 */ 0x02, 0x02, 0x02, 0x00, 0x26, 0x26, 0x26, 0x26,\ |
| 14035 | 14141 | /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\ |
| 14036 | | -/* 96 */ 0x20, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 14142 | +/* 96 */ 0x12, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10,\ |
| 14037 | 14143 | /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 14038 | | -/* 112 */ 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\ |
| 14039 | | -/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04,\ |
| 14040 | | -/* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\ |
| 14041 | | -/* 136 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 14042 | | -/* 144 */ 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00,\ |
| 14144 | +/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 14145 | +/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,\ |
| 14146 | +/* 128 */ 0x04, 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00,\ |
| 14147 | +/* 136 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 14148 | +/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\ |
| 14043 | 14149 | /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 14044 | | -/* 160 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 14045 | | -/* 168 */ 0x00, 0x00,} |
| 14150 | +/* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 14151 | +/* 168 */ 0x00, 0x00, 0x00,} |
| 14046 | 14152 | |
| 14047 | 14153 | /* The sqlite3P2Values() routine is able to run faster if it knows |
| 14048 | 14154 | ** the value of the largest JUMP opcode. The smaller the maximum |
| 14049 | 14155 | ** JUMP opcode the better, so the mkopcodeh.tcl script that |
| 14050 | 14156 | ** generated this include file strives to group all JUMP opcodes |
| | @@ -15246,12 +15352,13 @@ |
| 15246 | 15352 | int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */ |
| 15247 | 15353 | struct sqlite3InitInfo { /* Information used during initialization */ |
| 15248 | 15354 | int newTnum; /* Rootpage of table being initialized */ |
| 15249 | 15355 | u8 iDb; /* Which db file is being initialized */ |
| 15250 | 15356 | u8 busy; /* TRUE if currently initializing */ |
| 15251 | | - u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */ |
| 15252 | | - u8 imposterTable; /* Building an imposter table */ |
| 15357 | + unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */ |
| 15358 | + unsigned imposterTable : 1; /* Building an imposter table */ |
| 15359 | + unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */ |
| 15253 | 15360 | } init; |
| 15254 | 15361 | int nVdbeActive; /* Number of VDBEs currently running */ |
| 15255 | 15362 | int nVdbeRead; /* Number of active VDBEs that read or write */ |
| 15256 | 15363 | int nVdbeWrite; /* Number of active VDBEs that read and write */ |
| 15257 | 15364 | int nVdbeExec; /* Number of nested calls to VdbeExec() */ |
| | @@ -15635,10 +15742,11 @@ |
| 15635 | 15742 | /* Allowed values for Column.colFlags: |
| 15636 | 15743 | */ |
| 15637 | 15744 | #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */ |
| 15638 | 15745 | #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */ |
| 15639 | 15746 | #define COLFLAG_HASTYPE 0x0004 /* Type name follows column name */ |
| 15747 | +#define COLFLAG_UNIQUE 0x0008 /* Column def contains "UNIQUE" or "PK" */ |
| 15640 | 15748 | |
| 15641 | 15749 | /* |
| 15642 | 15750 | ** A "Collating Sequence" is defined by an instance of the following |
| 15643 | 15751 | ** structure. Conceptually, a collating sequence consists of a name and |
| 15644 | 15752 | ** a comparison routine that defines the order of that sequence. |
| | @@ -17719,10 +17827,12 @@ |
| 17719 | 17827 | SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 17720 | 17828 | SQLITE_PRIVATE void sqlite3EndTransaction(Parse*,int); |
| 17721 | 17829 | SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*); |
| 17722 | 17830 | SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *); |
| 17723 | 17831 | SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*); |
| 17832 | +SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*); |
| 17833 | +SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*); |
| 17724 | 17834 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); |
| 17725 | 17835 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); |
| 17726 | 17836 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); |
| 17727 | 17837 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); |
| 17728 | 17838 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); |
| | @@ -17900,10 +18010,14 @@ |
| 17900 | 18010 | SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
| 17901 | 18011 | |
| 17902 | 18012 | #if defined(SQLITE_NEED_ERR_NAME) |
| 17903 | 18013 | SQLITE_PRIVATE const char *sqlite3ErrName(int); |
| 17904 | 18014 | #endif |
| 18015 | + |
| 18016 | +#ifdef SQLITE_ENABLE_DESERIALIZE |
| 18017 | +SQLITE_PRIVATE int sqlite3MemdbInit(void); |
| 18018 | +#endif |
| 17905 | 18019 | |
| 17906 | 18020 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 17907 | 18021 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| 17908 | 18022 | SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); |
| 17909 | 18023 | SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); |
| | @@ -17949,10 +18063,13 @@ |
| 17949 | 18063 | SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions; |
| 17950 | 18064 | #ifndef SQLITE_OMIT_WSD |
| 17951 | 18065 | SQLITE_PRIVATE int sqlite3PendingByte; |
| 17952 | 18066 | #endif |
| 17953 | 18067 | #endif |
| 18068 | +#ifdef VDBE_PROFILE |
| 18069 | +SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt; |
| 18070 | +#endif |
| 17954 | 18071 | SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int); |
| 17955 | 18072 | SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*); |
| 17956 | 18073 | SQLITE_PRIVATE void sqlite3AlterFunctions(void); |
| 17957 | 18074 | SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); |
| 17958 | 18075 | SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *); |
| | @@ -18572,10 +18689,17 @@ |
| 18572 | 18689 | SQLITE_PRIVATE const Token sqlite3IntTokens[] = { |
| 18573 | 18690 | { "0", 1 }, |
| 18574 | 18691 | { "1", 1 } |
| 18575 | 18692 | }; |
| 18576 | 18693 | |
| 18694 | +#ifdef VDBE_PROFILE |
| 18695 | +/* |
| 18696 | +** The following performance counter can be used in place of |
| 18697 | +** sqlite3Hwtime() for profiling. This is a no-op on standard builds. |
| 18698 | +*/ |
| 18699 | +SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt = 0; |
| 18700 | +#endif |
| 18577 | 18701 | |
| 18578 | 18702 | /* |
| 18579 | 18703 | ** The value of the "pending" byte must be 0x40000000 (1 byte past the |
| 18580 | 18704 | ** 1-gibabyte boundary) in a compatible database. SQLite never uses |
| 18581 | 18705 | ** the database page that contains the pending byte. It never attempts |
| | @@ -18855,12 +18979,10 @@ |
| 18855 | 18979 | ** representations of the value stored in the Mem struct. |
| 18856 | 18980 | ** |
| 18857 | 18981 | ** If the MEM_Null flag is set, then the value is an SQL NULL value. |
| 18858 | 18982 | ** For a pointer type created using sqlite3_bind_pointer() or |
| 18859 | 18983 | ** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set. |
| 18860 | | -** If both MEM_Null and MEM_Zero are set, that means that the value is |
| 18861 | | -** an unchanging column value from VColumn. |
| 18862 | 18984 | ** |
| 18863 | 18985 | ** If the MEM_Str flag is set then Mem.z points at a string representation. |
| 18864 | 18986 | ** Usually this is encoded in the same unicode encoding as the main |
| 18865 | 18987 | ** database (see below for exceptions). If the MEM_Term flag is also |
| 18866 | 18988 | ** set, then the string is nul terminated. The MEM_Int and MEM_Real |
| | @@ -18950,11 +19072,10 @@ |
| 18950 | 19072 | Mem *pMem; /* Memory cell used to store aggregate context */ |
| 18951 | 19073 | Vdbe *pVdbe; /* The VM that owns this context */ |
| 18952 | 19074 | int iOp; /* Instruction number of OP_Function */ |
| 18953 | 19075 | int isError; /* Error code returned by the function. */ |
| 18954 | 19076 | u8 skipFlag; /* Skip accumulator loading if true */ |
| 18955 | | - u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */ |
| 18956 | 19077 | u8 argc; /* Number of arguments */ |
| 18957 | 19078 | sqlite3_value *argv[1]; /* Argument set */ |
| 18958 | 19079 | }; |
| 18959 | 19080 | |
| 18960 | 19081 | /* A bitfield type for use inside of structures. Always follow with :N where |
| | @@ -19120,10 +19241,11 @@ |
| 19120 | 19241 | SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*); |
| 19121 | 19242 | SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8); |
| 19122 | 19243 | SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*); |
| 19123 | 19244 | SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*); |
| 19124 | 19245 | SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*); |
| 19246 | +SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull); |
| 19125 | 19247 | SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); |
| 19126 | 19248 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); |
| 19127 | 19249 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); |
| 19128 | 19250 | SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8); |
| 19129 | 19251 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*); |
| | @@ -19513,10 +19635,13 @@ |
| 19513 | 19635 | /* |
| 19514 | 19636 | ** Set *pCurrent to the total cache hits or misses encountered by all |
| 19515 | 19637 | ** pagers the database handle is connected to. *pHighwater is always set |
| 19516 | 19638 | ** to zero. |
| 19517 | 19639 | */ |
| 19640 | + case SQLITE_DBSTATUS_CACHE_SPILL: |
| 19641 | + op = SQLITE_DBSTATUS_CACHE_WRITE+1; |
| 19642 | + /* Fall through into the next case */ |
| 19518 | 19643 | case SQLITE_DBSTATUS_CACHE_HIT: |
| 19519 | 19644 | case SQLITE_DBSTATUS_CACHE_MISS: |
| 19520 | 19645 | case SQLITE_DBSTATUS_CACHE_WRITE:{ |
| 19521 | 19646 | int i; |
| 19522 | 19647 | int nRet = 0; |
| | @@ -24106,15 +24231,16 @@ |
| 24106 | 24231 | volatile pthread_t owner; /* Thread that is within this mutex */ |
| 24107 | 24232 | int trace; /* True to trace changes */ |
| 24108 | 24233 | #endif |
| 24109 | 24234 | }; |
| 24110 | 24235 | #if SQLITE_MUTEX_NREF |
| 24111 | | -#define SQLITE3_MUTEX_INITIALIZER {PTHREAD_MUTEX_INITIALIZER,0,0,(pthread_t)0,0} |
| 24236 | +# define SQLITE3_MUTEX_INITIALIZER(id) \ |
| 24237 | + {PTHREAD_MUTEX_INITIALIZER,id,0,(pthread_t)0,0} |
| 24112 | 24238 | #elif defined(SQLITE_ENABLE_API_ARMOR) |
| 24113 | | -#define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0 } |
| 24239 | +# define SQLITE3_MUTEX_INITIALIZER(id) { PTHREAD_MUTEX_INITIALIZER, id } |
| 24114 | 24240 | #else |
| 24115 | | -#define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER } |
| 24241 | +#define SQLITE3_MUTEX_INITIALIZER(id) { PTHREAD_MUTEX_INITIALIZER } |
| 24116 | 24242 | #endif |
| 24117 | 24243 | |
| 24118 | 24244 | /* |
| 24119 | 24245 | ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are |
| 24120 | 24246 | ** intended for use only inside assert() statements. On some platforms, |
| | @@ -24207,22 +24333,22 @@ |
| 24207 | 24333 | ** mutex types, the same mutex is returned on every call that has |
| 24208 | 24334 | ** the same type number. |
| 24209 | 24335 | */ |
| 24210 | 24336 | static sqlite3_mutex *pthreadMutexAlloc(int iType){ |
| 24211 | 24337 | static sqlite3_mutex staticMutexes[] = { |
| 24212 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24213 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24214 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24215 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24216 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24217 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24218 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24219 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24220 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24221 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24222 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24223 | | - SQLITE3_MUTEX_INITIALIZER |
| 24338 | + SQLITE3_MUTEX_INITIALIZER(2), |
| 24339 | + SQLITE3_MUTEX_INITIALIZER(3), |
| 24340 | + SQLITE3_MUTEX_INITIALIZER(4), |
| 24341 | + SQLITE3_MUTEX_INITIALIZER(5), |
| 24342 | + SQLITE3_MUTEX_INITIALIZER(6), |
| 24343 | + SQLITE3_MUTEX_INITIALIZER(7), |
| 24344 | + SQLITE3_MUTEX_INITIALIZER(8), |
| 24345 | + SQLITE3_MUTEX_INITIALIZER(9), |
| 24346 | + SQLITE3_MUTEX_INITIALIZER(10), |
| 24347 | + SQLITE3_MUTEX_INITIALIZER(11), |
| 24348 | + SQLITE3_MUTEX_INITIALIZER(12), |
| 24349 | + SQLITE3_MUTEX_INITIALIZER(13) |
| 24224 | 24350 | }; |
| 24225 | 24351 | sqlite3_mutex *p; |
| 24226 | 24352 | switch( iType ){ |
| 24227 | 24353 | case SQLITE_MUTEX_RECURSIVE: { |
| 24228 | 24354 | p = sqlite3MallocZero( sizeof(*p) ); |
| | @@ -24237,17 +24363,23 @@ |
| 24237 | 24363 | pthread_mutexattr_init(&recursiveAttr); |
| 24238 | 24364 | pthread_mutexattr_settype(&recursiveAttr, PTHREAD_MUTEX_RECURSIVE); |
| 24239 | 24365 | pthread_mutex_init(&p->mutex, &recursiveAttr); |
| 24240 | 24366 | pthread_mutexattr_destroy(&recursiveAttr); |
| 24241 | 24367 | #endif |
| 24368 | +#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR) |
| 24369 | + p->id = SQLITE_MUTEX_RECURSIVE; |
| 24370 | +#endif |
| 24242 | 24371 | } |
| 24243 | 24372 | break; |
| 24244 | 24373 | } |
| 24245 | 24374 | case SQLITE_MUTEX_FAST: { |
| 24246 | 24375 | p = sqlite3MallocZero( sizeof(*p) ); |
| 24247 | 24376 | if( p ){ |
| 24248 | 24377 | pthread_mutex_init(&p->mutex, 0); |
| 24378 | +#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR) |
| 24379 | + p->id = SQLITE_MUTEX_FAST; |
| 24380 | +#endif |
| 24249 | 24381 | } |
| 24250 | 24382 | break; |
| 24251 | 24383 | } |
| 24252 | 24384 | default: { |
| 24253 | 24385 | #ifdef SQLITE_ENABLE_API_ARMOR |
| | @@ -24259,11 +24391,11 @@ |
| 24259 | 24391 | p = &staticMutexes[iType-2]; |
| 24260 | 24392 | break; |
| 24261 | 24393 | } |
| 24262 | 24394 | } |
| 24263 | 24395 | #if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR) |
| 24264 | | - if( p ) p->id = iType; |
| 24396 | + assert( p==0 || p->id==iType ); |
| 24265 | 24397 | #endif |
| 24266 | 24398 | return p; |
| 24267 | 24399 | } |
| 24268 | 24400 | |
| 24269 | 24401 | |
| | @@ -24776,11 +24908,11 @@ |
| 24776 | 24908 | CRITICAL_SECTION mutex; /* Mutex controlling the lock */ |
| 24777 | 24909 | int id; /* Mutex type */ |
| 24778 | 24910 | #ifdef SQLITE_DEBUG |
| 24779 | 24911 | volatile int nRef; /* Number of enterances */ |
| 24780 | 24912 | volatile DWORD owner; /* Thread holding this mutex */ |
| 24781 | | - volatile int trace; /* True to trace changes */ |
| 24913 | + volatile LONG trace; /* True to trace changes */ |
| 24782 | 24914 | #endif |
| 24783 | 24915 | }; |
| 24784 | 24916 | |
| 24785 | 24917 | /* |
| 24786 | 24918 | ** These are the initializer values used when declaring a "static" mutex |
| | @@ -24788,14 +24920,14 @@ |
| 24788 | 24920 | ** on the Win32 platform. |
| 24789 | 24921 | */ |
| 24790 | 24922 | #define SQLITE_W32_MUTEX_INITIALIZER { 0 } |
| 24791 | 24923 | |
| 24792 | 24924 | #ifdef SQLITE_DEBUG |
| 24793 | | -#define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0, \ |
| 24925 | +#define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id, \ |
| 24794 | 24926 | 0L, (DWORD)0, 0 } |
| 24795 | 24927 | #else |
| 24796 | | -#define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0 } |
| 24928 | +#define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id } |
| 24797 | 24929 | #endif |
| 24798 | 24930 | |
| 24799 | 24931 | #ifdef SQLITE_DEBUG |
| 24800 | 24932 | /* |
| 24801 | 24933 | ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are |
| | @@ -24834,22 +24966,22 @@ |
| 24834 | 24966 | |
| 24835 | 24967 | /* |
| 24836 | 24968 | ** Initialize and deinitialize the mutex subsystem. |
| 24837 | 24969 | */ |
| 24838 | 24970 | static sqlite3_mutex winMutex_staticMutexes[] = { |
| 24839 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24840 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24841 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24842 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24843 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24844 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24845 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24846 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24847 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24848 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24849 | | - SQLITE3_MUTEX_INITIALIZER, |
| 24850 | | - SQLITE3_MUTEX_INITIALIZER |
| 24971 | + SQLITE3_MUTEX_INITIALIZER(2), |
| 24972 | + SQLITE3_MUTEX_INITIALIZER(3), |
| 24973 | + SQLITE3_MUTEX_INITIALIZER(4), |
| 24974 | + SQLITE3_MUTEX_INITIALIZER(5), |
| 24975 | + SQLITE3_MUTEX_INITIALIZER(6), |
| 24976 | + SQLITE3_MUTEX_INITIALIZER(7), |
| 24977 | + SQLITE3_MUTEX_INITIALIZER(8), |
| 24978 | + SQLITE3_MUTEX_INITIALIZER(9), |
| 24979 | + SQLITE3_MUTEX_INITIALIZER(10), |
| 24980 | + SQLITE3_MUTEX_INITIALIZER(11), |
| 24981 | + SQLITE3_MUTEX_INITIALIZER(12), |
| 24982 | + SQLITE3_MUTEX_INITIALIZER(13) |
| 24851 | 24983 | }; |
| 24852 | 24984 | |
| 24853 | 24985 | static int winMutex_isInit = 0; |
| 24854 | 24986 | static int winMutex_isNt = -1; /* <0 means "need to query" */ |
| 24855 | 24987 | |
| | @@ -24975,19 +25107,19 @@ |
| 24975 | 25107 | (void)SQLITE_MISUSE_BKPT; |
| 24976 | 25108 | return 0; |
| 24977 | 25109 | } |
| 24978 | 25110 | #endif |
| 24979 | 25111 | p = &winMutex_staticMutexes[iType-2]; |
| 24980 | | - p->id = iType; |
| 24981 | 25112 | #ifdef SQLITE_DEBUG |
| 24982 | 25113 | #ifdef SQLITE_WIN32_MUTEX_TRACE_STATIC |
| 24983 | | - p->trace = 1; |
| 25114 | + InterlockedCompareExchange(&p->trace, 1, 0); |
| 24984 | 25115 | #endif |
| 24985 | 25116 | #endif |
| 24986 | 25117 | break; |
| 24987 | 25118 | } |
| 24988 | 25119 | } |
| 25120 | + assert( p==0 || p->id==iType ); |
| 24989 | 25121 | return p; |
| 24990 | 25122 | } |
| 24991 | 25123 | |
| 24992 | 25124 | |
| 24993 | 25125 | /* |
| | @@ -26062,10 +26194,15 @@ |
| 26062 | 26194 | etByte flag_rtz; /* True if trailing zeros should be removed */ |
| 26063 | 26195 | #endif |
| 26064 | 26196 | PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ |
| 26065 | 26197 | char buf[etBUFSIZE]; /* Conversion buffer */ |
| 26066 | 26198 | |
| 26199 | + /* pAccum never starts out with an empty buffer that was obtained from |
| 26200 | + ** malloc(). This precondition is required by the mprintf("%z...") |
| 26201 | + ** optimization. */ |
| 26202 | + assert( pAccum->nChar>0 || (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 ); |
| 26203 | + |
| 26067 | 26204 | bufpt = 0; |
| 26068 | 26205 | if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){ |
| 26069 | 26206 | pArgList = va_arg(ap, PrintfArguments*); |
| 26070 | 26207 | bArgList = 1; |
| 26071 | 26208 | }else{ |
| | @@ -26480,26 +26617,56 @@ |
| 26480 | 26617 | length = 1; |
| 26481 | 26618 | break; |
| 26482 | 26619 | case etCHARX: |
| 26483 | 26620 | if( bArgList ){ |
| 26484 | 26621 | bufpt = getTextArg(pArgList); |
| 26485 | | - c = bufpt ? bufpt[0] : 0; |
| 26622 | + length = 1; |
| 26623 | + if( bufpt ){ |
| 26624 | + buf[0] = c = *(bufpt++); |
| 26625 | + if( (c&0xc0)==0xc0 ){ |
| 26626 | + while( length<4 && (bufpt[0]&0xc0)==0x80 ){ |
| 26627 | + buf[length++] = *(bufpt++); |
| 26628 | + } |
| 26629 | + } |
| 26630 | + }else{ |
| 26631 | + buf[0] = 0; |
| 26632 | + } |
| 26486 | 26633 | }else{ |
| 26487 | | - c = va_arg(ap,int); |
| 26634 | + unsigned int ch = va_arg(ap,unsigned int); |
| 26635 | + if( ch<0x00080 ){ |
| 26636 | + buf[0] = ch & 0xff; |
| 26637 | + length = 1; |
| 26638 | + }else if( ch<0x00800 ){ |
| 26639 | + buf[0] = 0xc0 + (u8)((ch>>6)&0x1f); |
| 26640 | + buf[1] = 0x80 + (u8)(ch & 0x3f); |
| 26641 | + length = 2; |
| 26642 | + }else if( ch<0x10000 ){ |
| 26643 | + buf[0] = 0xe0 + (u8)((ch>>12)&0x0f); |
| 26644 | + buf[1] = 0x80 + (u8)((ch>>6) & 0x3f); |
| 26645 | + buf[2] = 0x80 + (u8)(ch & 0x3f); |
| 26646 | + length = 3; |
| 26647 | + }else{ |
| 26648 | + buf[0] = 0xf0 + (u8)((ch>>18) & 0x07); |
| 26649 | + buf[1] = 0x80 + (u8)((ch>>12) & 0x3f); |
| 26650 | + buf[2] = 0x80 + (u8)((ch>>6) & 0x3f); |
| 26651 | + buf[3] = 0x80 + (u8)(ch & 0x3f); |
| 26652 | + length = 4; |
| 26653 | + } |
| 26488 | 26654 | } |
| 26489 | 26655 | if( precision>1 ){ |
| 26490 | 26656 | width -= precision-1; |
| 26491 | 26657 | if( width>1 && !flag_leftjustify ){ |
| 26492 | 26658 | sqlite3AppendChar(pAccum, width-1, ' '); |
| 26493 | 26659 | width = 0; |
| 26494 | 26660 | } |
| 26495 | | - sqlite3AppendChar(pAccum, precision-1, c); |
| 26661 | + while( precision-- > 1 ){ |
| 26662 | + sqlite3StrAccumAppend(pAccum, buf, length); |
| 26663 | + } |
| 26496 | 26664 | } |
| 26497 | | - length = 1; |
| 26498 | | - buf[0] = c; |
| 26499 | 26665 | bufpt = buf; |
| 26500 | | - break; |
| 26666 | + flag_altform2 = 1; |
| 26667 | + goto adjust_width_for_utf8; |
| 26501 | 26668 | case etSTRING: |
| 26502 | 26669 | case etDYNSTRING: |
| 26503 | 26670 | if( bArgList ){ |
| 26504 | 26671 | bufpt = getTextArg(pArgList); |
| 26505 | 26672 | xtype = etSTRING; |
| | @@ -26507,21 +26674,49 @@ |
| 26507 | 26674 | bufpt = va_arg(ap,char*); |
| 26508 | 26675 | } |
| 26509 | 26676 | if( bufpt==0 ){ |
| 26510 | 26677 | bufpt = ""; |
| 26511 | 26678 | }else if( xtype==etDYNSTRING ){ |
| 26679 | + if( pAccum->nChar==0 && pAccum->mxAlloc && width==0 && precision<0 ){ |
| 26680 | + /* Special optimization for sqlite3_mprintf("%z..."): |
| 26681 | + ** Extend an existing memory allocation rather than creating |
| 26682 | + ** a new one. */ |
| 26683 | + assert( (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 ); |
| 26684 | + pAccum->zText = bufpt; |
| 26685 | + pAccum->nAlloc = sqlite3DbMallocSize(pAccum->db, bufpt); |
| 26686 | + pAccum->nChar = 0x7fffffff & (int)strlen(bufpt); |
| 26687 | + pAccum->printfFlags |= SQLITE_PRINTF_MALLOCED; |
| 26688 | + length = 0; |
| 26689 | + break; |
| 26690 | + } |
| 26512 | 26691 | zExtra = bufpt; |
| 26513 | 26692 | } |
| 26514 | 26693 | if( precision>=0 ){ |
| 26515 | | - for(length=0; length<precision && bufpt[length]; length++){} |
| 26694 | + if( flag_altform2 ){ |
| 26695 | + /* Set length to the number of bytes needed in order to display |
| 26696 | + ** precision characters */ |
| 26697 | + unsigned char *z = (unsigned char*)bufpt; |
| 26698 | + while( precision-- > 0 && z[0] ){ |
| 26699 | + SQLITE_SKIP_UTF8(z); |
| 26700 | + } |
| 26701 | + length = (int)(z - (unsigned char*)bufpt); |
| 26702 | + }else{ |
| 26703 | + for(length=0; length<precision && bufpt[length]; length++){} |
| 26704 | + } |
| 26516 | 26705 | }else{ |
| 26517 | 26706 | length = 0x7fffffff & (int)strlen(bufpt); |
| 26518 | 26707 | } |
| 26708 | + adjust_width_for_utf8: |
| 26709 | + if( flag_altform2 && width>0 ){ |
| 26710 | + /* Adjust width to account for extra bytes in UTF-8 characters */ |
| 26711 | + int ii = length - 1; |
| 26712 | + while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++; |
| 26713 | + } |
| 26519 | 26714 | break; |
| 26520 | | - case etSQLESCAPE: /* Escape ' characters */ |
| 26521 | | - case etSQLESCAPE2: /* Escape ' and enclose in '...' */ |
| 26522 | | - case etSQLESCAPE3: { /* Escape " characters */ |
| 26715 | + case etSQLESCAPE: /* %q: Escape ' characters */ |
| 26716 | + case etSQLESCAPE2: /* %Q: Escape ' and enclose in '...' */ |
| 26717 | + case etSQLESCAPE3: { /* %w: Escape " characters */ |
| 26523 | 26718 | int i, j, k, n, isnull; |
| 26524 | 26719 | int needQuote; |
| 26525 | 26720 | char ch; |
| 26526 | 26721 | char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */ |
| 26527 | 26722 | char *escarg; |
| | @@ -26531,13 +26726,21 @@ |
| 26531 | 26726 | }else{ |
| 26532 | 26727 | escarg = va_arg(ap,char*); |
| 26533 | 26728 | } |
| 26534 | 26729 | isnull = escarg==0; |
| 26535 | 26730 | if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); |
| 26731 | + /* For %q, %Q, and %w, the precision is the number of byte (or |
| 26732 | + ** characters if the ! flags is present) to use from the input. |
| 26733 | + ** Because of the extra quoting characters inserted, the number |
| 26734 | + ** of output characters may be larger than the precision. |
| 26735 | + */ |
| 26536 | 26736 | k = precision; |
| 26537 | 26737 | for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){ |
| 26538 | 26738 | if( ch==q ) n++; |
| 26739 | + if( flag_altform2 && (ch&0xc0)==0xc0 ){ |
| 26740 | + while( (escarg[i+1]&0xc0)==0x80 ){ i++; } |
| 26741 | + } |
| 26539 | 26742 | } |
| 26540 | 26743 | needQuote = !isnull && xtype==etSQLESCAPE2; |
| 26541 | 26744 | n += i + 3; |
| 26542 | 26745 | if( n>etBUFSIZE ){ |
| 26543 | 26746 | bufpt = zExtra = sqlite3Malloc( n ); |
| | @@ -26556,14 +26759,11 @@ |
| 26556 | 26759 | if( ch==q ) bufpt[j++] = ch; |
| 26557 | 26760 | } |
| 26558 | 26761 | if( needQuote ) bufpt[j++] = q; |
| 26559 | 26762 | bufpt[j] = 0; |
| 26560 | 26763 | length = j; |
| 26561 | | - /* The precision in %q and %Q means how many input characters to |
| 26562 | | - ** consume, not the length of the output... |
| 26563 | | - ** if( precision>=0 && precision<length ) length = precision; */ |
| 26564 | | - break; |
| 26764 | + goto adjust_width_for_utf8; |
| 26565 | 26765 | } |
| 26566 | 26766 | case etTOKEN: { |
| 26567 | 26767 | Token *pToken; |
| 26568 | 26768 | if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; |
| 26569 | 26769 | pToken = va_arg(ap, Token*); |
| | @@ -26598,11 +26798,14 @@ |
| 26598 | 26798 | } |
| 26599 | 26799 | }/* End switch over the format type */ |
| 26600 | 26800 | /* |
| 26601 | 26801 | ** The text of the conversion is pointed to by "bufpt" and is |
| 26602 | 26802 | ** "length" characters long. The field width is "width". Do |
| 26603 | | - ** the output. |
| 26803 | + ** the output. Both length and width are in bytes, not characters, |
| 26804 | + ** at this point. If the "!" flag was present on string conversions |
| 26805 | + ** indicating that width and precision should be expressed in characters, |
| 26806 | + ** then the values have been translated prior to reaching this point. |
| 26604 | 26807 | */ |
| 26605 | 26808 | width -= length; |
| 26606 | 26809 | if( width>0 ){ |
| 26607 | 26810 | if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); |
| 26608 | 26811 | sqlite3StrAccumAppend(pAccum, bufpt, length); |
| | @@ -27267,10 +27470,15 @@ |
| 27267 | 27470 | break; |
| 27268 | 27471 | } |
| 27269 | 27472 | case TK_NULL: { |
| 27270 | 27473 | sqlite3TreeViewLine(pView,"NULL"); |
| 27271 | 27474 | break; |
| 27475 | + } |
| 27476 | + case TK_TRUEFALSE: { |
| 27477 | + sqlite3TreeViewLine(pView, |
| 27478 | + sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE"); |
| 27479 | + break; |
| 27272 | 27480 | } |
| 27273 | 27481 | #ifndef SQLITE_OMIT_BLOB_LITERAL |
| 27274 | 27482 | case TK_BLOB: { |
| 27275 | 27483 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 27276 | 27484 | break; |
| | @@ -27323,10 +27531,23 @@ |
| 27323 | 27531 | case TK_UPLUS: zUniOp = "UPLUS"; break; |
| 27324 | 27532 | case TK_BITNOT: zUniOp = "BITNOT"; break; |
| 27325 | 27533 | case TK_NOT: zUniOp = "NOT"; break; |
| 27326 | 27534 | case TK_ISNULL: zUniOp = "ISNULL"; break; |
| 27327 | 27535 | case TK_NOTNULL: zUniOp = "NOTNULL"; break; |
| 27536 | + |
| 27537 | + case TK_TRUTH: { |
| 27538 | + int x; |
| 27539 | + const char *azOp[] = { |
| 27540 | + "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE" |
| 27541 | + }; |
| 27542 | + assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT ); |
| 27543 | + assert( pExpr->pRight ); |
| 27544 | + assert( pExpr->pRight->op==TK_TRUEFALSE ); |
| 27545 | + x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight); |
| 27546 | + zUniOp = azOp[x]; |
| 27547 | + break; |
| 27548 | + } |
| 27328 | 27549 | |
| 27329 | 27550 | case TK_SPAN: { |
| 27330 | 27551 | sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken); |
| 27331 | 27552 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 27332 | 27553 | break; |
| | @@ -29061,11 +29282,11 @@ |
| 29061 | 29282 | ** routine does *not* accept hexadecimal notation. |
| 29062 | 29283 | ** |
| 29063 | 29284 | ** Returns: |
| 29064 | 29285 | ** |
| 29065 | 29286 | ** 0 Successful transformation. Fits in a 64-bit signed integer. |
| 29066 | | -** 1 Excess text after the integer value |
| 29287 | +** 1 Excess non-space text after the integer value |
| 29067 | 29288 | ** 2 Integer too large for a 64-bit signed integer or is malformed |
| 29068 | 29289 | ** 3 Special case of 9223372036854775808 |
| 29069 | 29290 | ** |
| 29070 | 29291 | ** length is the number of bytes in the string (bytes, not characters). |
| 29071 | 29292 | ** The string is not necessarily zero-terminated. The encoding is |
| | @@ -29104,51 +29325,61 @@ |
| 29104 | 29325 | zStart = zNum; |
| 29105 | 29326 | while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */ |
| 29106 | 29327 | for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){ |
| 29107 | 29328 | u = u*10 + c - '0'; |
| 29108 | 29329 | } |
| 29330 | + testcase( i==18*incr ); |
| 29331 | + testcase( i==19*incr ); |
| 29332 | + testcase( i==20*incr ); |
| 29109 | 29333 | if( u>LARGEST_INT64 ){ |
| 29334 | + /* This test and assignment is needed only to suppress UB warnings |
| 29335 | + ** from clang and -fsanitize=undefined. This test and assignment make |
| 29336 | + ** the code a little larger and slower, and no harm comes from omitting |
| 29337 | + ** them, but we must appaise the undefined-behavior pharisees. */ |
| 29110 | 29338 | *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64; |
| 29111 | 29339 | }else if( neg ){ |
| 29112 | 29340 | *pNum = -(i64)u; |
| 29113 | 29341 | }else{ |
| 29114 | 29342 | *pNum = (i64)u; |
| 29115 | 29343 | } |
| 29116 | | - testcase( i==18 ); |
| 29117 | | - testcase( i==19 ); |
| 29118 | | - testcase( i==20 ); |
| 29119 | | - if( &zNum[i]<zEnd /* Extra bytes at the end */ |
| 29120 | | - || (i==0 && zStart==zNum) /* No digits */ |
| 29344 | + rc = 0; |
| 29345 | + if( (i==0 && zStart==zNum) /* No digits */ |
| 29121 | 29346 | || nonNum /* UTF16 with high-order bytes non-zero */ |
| 29122 | 29347 | ){ |
| 29123 | 29348 | rc = 1; |
| 29124 | | - }else{ |
| 29125 | | - rc = 0; |
| 29126 | | - } |
| 29127 | | - if( i>19*incr ){ /* Too many digits */ |
| 29128 | | - /* zNum is empty or contains non-numeric text or is longer |
| 29129 | | - ** than 19 digits (thus guaranteeing that it is too large) */ |
| 29130 | | - return 2; |
| 29131 | | - }else if( i<19*incr ){ |
| 29349 | + }else if( &zNum[i]<zEnd ){ /* Extra bytes at the end */ |
| 29350 | + int jj = i; |
| 29351 | + do{ |
| 29352 | + if( !sqlite3Isspace(zNum[jj]) ){ |
| 29353 | + rc = 1; /* Extra non-space text after the integer */ |
| 29354 | + break; |
| 29355 | + } |
| 29356 | + jj += incr; |
| 29357 | + }while( &zNum[jj]<zEnd ); |
| 29358 | + } |
| 29359 | + if( i<19*incr ){ |
| 29132 | 29360 | /* Less than 19 digits, so we know that it fits in 64 bits */ |
| 29133 | 29361 | assert( u<=LARGEST_INT64 ); |
| 29134 | 29362 | return rc; |
| 29135 | 29363 | }else{ |
| 29136 | 29364 | /* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */ |
| 29137 | | - c = compare2pow63(zNum, incr); |
| 29365 | + c = i>19*incr ? 1 : compare2pow63(zNum, incr); |
| 29138 | 29366 | if( c<0 ){ |
| 29139 | 29367 | /* zNum is less than 9223372036854775808 so it fits */ |
| 29140 | 29368 | assert( u<=LARGEST_INT64 ); |
| 29141 | 29369 | return rc; |
| 29142 | | - }else if( c>0 ){ |
| 29143 | | - /* zNum is greater than 9223372036854775808 so it overflows */ |
| 29144 | | - return 2; |
| 29145 | 29370 | }else{ |
| 29146 | | - /* zNum is exactly 9223372036854775808. Fits if negative. The |
| 29147 | | - ** special case 2 overflow if positive */ |
| 29148 | | - assert( u-1==LARGEST_INT64 ); |
| 29149 | | - return neg ? rc : 3; |
| 29371 | + *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64; |
| 29372 | + if( c>0 ){ |
| 29373 | + /* zNum is greater than 9223372036854775808 so it overflows */ |
| 29374 | + return 2; |
| 29375 | + }else{ |
| 29376 | + /* zNum is exactly 9223372036854775808. Fits if negative. The |
| 29377 | + ** special case 2 overflow if positive */ |
| 29378 | + assert( u-1==LARGEST_INT64 ); |
| 29379 | + return neg ? rc : 3; |
| 29380 | + } |
| 29150 | 29381 | } |
| 29151 | 29382 | } |
| 29152 | 29383 | } |
| 29153 | 29384 | |
| 29154 | 29385 | /* |
| | @@ -30461,84 +30692,85 @@ |
| 30461 | 30692 | /* 91 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), |
| 30462 | 30693 | /* 92 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), |
| 30463 | 30694 | /* 93 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), |
| 30464 | 30695 | /* 94 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), |
| 30465 | 30696 | /* 95 */ "BitNot" OpHelp("r[P1]= ~r[P1]"), |
| 30466 | | - /* 96 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), |
| 30697 | + /* 96 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"), |
| 30467 | 30698 | /* 97 */ "String8" OpHelp("r[P2]='P4'"), |
| 30468 | | - /* 98 */ "Column" OpHelp("r[P3]=PX"), |
| 30469 | | - /* 99 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 30470 | | - /* 100 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 30471 | | - /* 101 */ "Count" OpHelp("r[P2]=count()"), |
| 30472 | | - /* 102 */ "ReadCookie" OpHelp(""), |
| 30473 | | - /* 103 */ "SetCookie" OpHelp(""), |
| 30474 | | - /* 104 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 30475 | | - /* 105 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 30476 | | - /* 106 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 30477 | | - /* 107 */ "OpenDup" OpHelp(""), |
| 30478 | | - /* 108 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 30479 | | - /* 109 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 30480 | | - /* 110 */ "SorterOpen" OpHelp(""), |
| 30481 | | - /* 111 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 30482 | | - /* 112 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 30483 | | - /* 113 */ "Close" OpHelp(""), |
| 30484 | | - /* 114 */ "ColumnsUsed" OpHelp(""), |
| 30485 | | - /* 115 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 30486 | | - /* 116 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 30487 | | - /* 117 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 30488 | | - /* 118 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), |
| 30489 | | - /* 119 */ "Delete" OpHelp(""), |
| 30490 | | - /* 120 */ "ResetCount" OpHelp(""), |
| 30491 | | - /* 121 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 30492 | | - /* 122 */ "SorterData" OpHelp("r[P2]=data"), |
| 30493 | | - /* 123 */ "RowData" OpHelp("r[P2]=data"), |
| 30494 | | - /* 124 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 30495 | | - /* 125 */ "NullRow" OpHelp(""), |
| 30496 | | - /* 126 */ "SeekEnd" OpHelp(""), |
| 30497 | | - /* 127 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 30498 | | - /* 128 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 30499 | | - /* 129 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 30500 | | - /* 130 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 30501 | | - /* 131 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 30699 | + /* 98 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), |
| 30700 | + /* 99 */ "Column" OpHelp("r[P3]=PX"), |
| 30701 | + /* 100 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 30702 | + /* 101 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 30703 | + /* 102 */ "Count" OpHelp("r[P2]=count()"), |
| 30704 | + /* 103 */ "ReadCookie" OpHelp(""), |
| 30705 | + /* 104 */ "SetCookie" OpHelp(""), |
| 30706 | + /* 105 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 30707 | + /* 106 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 30708 | + /* 107 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 30709 | + /* 108 */ "OpenDup" OpHelp(""), |
| 30710 | + /* 109 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 30711 | + /* 110 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 30712 | + /* 111 */ "SorterOpen" OpHelp(""), |
| 30713 | + /* 112 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 30714 | + /* 113 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 30715 | + /* 114 */ "Close" OpHelp(""), |
| 30716 | + /* 115 */ "ColumnsUsed" OpHelp(""), |
| 30717 | + /* 116 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 30718 | + /* 117 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 30719 | + /* 118 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 30720 | + /* 119 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), |
| 30721 | + /* 120 */ "Delete" OpHelp(""), |
| 30722 | + /* 121 */ "ResetCount" OpHelp(""), |
| 30723 | + /* 122 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 30724 | + /* 123 */ "SorterData" OpHelp("r[P2]=data"), |
| 30725 | + /* 124 */ "RowData" OpHelp("r[P2]=data"), |
| 30726 | + /* 125 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 30727 | + /* 126 */ "NullRow" OpHelp(""), |
| 30728 | + /* 127 */ "SeekEnd" OpHelp(""), |
| 30729 | + /* 128 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 30730 | + /* 129 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 30731 | + /* 130 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 30732 | + /* 131 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 30502 | 30733 | /* 132 */ "Real" OpHelp("r[P2]=P4"), |
| 30503 | | - /* 133 */ "Destroy" OpHelp(""), |
| 30504 | | - /* 134 */ "Clear" OpHelp(""), |
| 30505 | | - /* 135 */ "ResetSorter" OpHelp(""), |
| 30506 | | - /* 136 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), |
| 30507 | | - /* 137 */ "SqlExec" OpHelp(""), |
| 30508 | | - /* 138 */ "ParseSchema" OpHelp(""), |
| 30509 | | - /* 139 */ "LoadAnalysis" OpHelp(""), |
| 30510 | | - /* 140 */ "DropTable" OpHelp(""), |
| 30511 | | - /* 141 */ "DropIndex" OpHelp(""), |
| 30512 | | - /* 142 */ "DropTrigger" OpHelp(""), |
| 30513 | | - /* 143 */ "IntegrityCk" OpHelp(""), |
| 30514 | | - /* 144 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 30515 | | - /* 145 */ "Param" OpHelp(""), |
| 30516 | | - /* 146 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 30517 | | - /* 147 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 30518 | | - /* 148 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 30519 | | - /* 149 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 30520 | | - /* 150 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 30521 | | - /* 151 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 30522 | | - /* 152 */ "Expire" OpHelp(""), |
| 30523 | | - /* 153 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 30524 | | - /* 154 */ "VBegin" OpHelp(""), |
| 30525 | | - /* 155 */ "VCreate" OpHelp(""), |
| 30526 | | - /* 156 */ "VDestroy" OpHelp(""), |
| 30527 | | - /* 157 */ "VOpen" OpHelp(""), |
| 30528 | | - /* 158 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 30529 | | - /* 159 */ "VRename" OpHelp(""), |
| 30530 | | - /* 160 */ "Pagecount" OpHelp(""), |
| 30531 | | - /* 161 */ "MaxPgcnt" OpHelp(""), |
| 30532 | | - /* 162 */ "PureFunc0" OpHelp(""), |
| 30533 | | - /* 163 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"), |
| 30534 | | - /* 164 */ "PureFunc" OpHelp(""), |
| 30535 | | - /* 165 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), |
| 30536 | | - /* 166 */ "Trace" OpHelp(""), |
| 30537 | | - /* 167 */ "CursorHint" OpHelp(""), |
| 30538 | | - /* 168 */ "Noop" OpHelp(""), |
| 30539 | | - /* 169 */ "Explain" OpHelp(""), |
| 30734 | + /* 133 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 30735 | + /* 134 */ "Destroy" OpHelp(""), |
| 30736 | + /* 135 */ "Clear" OpHelp(""), |
| 30737 | + /* 136 */ "ResetSorter" OpHelp(""), |
| 30738 | + /* 137 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), |
| 30739 | + /* 138 */ "SqlExec" OpHelp(""), |
| 30740 | + /* 139 */ "ParseSchema" OpHelp(""), |
| 30741 | + /* 140 */ "LoadAnalysis" OpHelp(""), |
| 30742 | + /* 141 */ "DropTable" OpHelp(""), |
| 30743 | + /* 142 */ "DropIndex" OpHelp(""), |
| 30744 | + /* 143 */ "DropTrigger" OpHelp(""), |
| 30745 | + /* 144 */ "IntegrityCk" OpHelp(""), |
| 30746 | + /* 145 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 30747 | + /* 146 */ "Param" OpHelp(""), |
| 30748 | + /* 147 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 30749 | + /* 148 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 30750 | + /* 149 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 30751 | + /* 150 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 30752 | + /* 151 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 30753 | + /* 152 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 30754 | + /* 153 */ "Expire" OpHelp(""), |
| 30755 | + /* 154 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 30756 | + /* 155 */ "VBegin" OpHelp(""), |
| 30757 | + /* 156 */ "VCreate" OpHelp(""), |
| 30758 | + /* 157 */ "VDestroy" OpHelp(""), |
| 30759 | + /* 158 */ "VOpen" OpHelp(""), |
| 30760 | + /* 159 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 30761 | + /* 160 */ "VRename" OpHelp(""), |
| 30762 | + /* 161 */ "Pagecount" OpHelp(""), |
| 30763 | + /* 162 */ "MaxPgcnt" OpHelp(""), |
| 30764 | + /* 163 */ "PureFunc0" OpHelp(""), |
| 30765 | + /* 164 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"), |
| 30766 | + /* 165 */ "PureFunc" OpHelp(""), |
| 30767 | + /* 166 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), |
| 30768 | + /* 167 */ "Trace" OpHelp(""), |
| 30769 | + /* 168 */ "CursorHint" OpHelp(""), |
| 30770 | + /* 169 */ "Noop" OpHelp(""), |
| 30771 | + /* 170 */ "Explain" OpHelp(""), |
| 30540 | 30772 | }; |
| 30541 | 30773 | return azName[i]; |
| 30542 | 30774 | } |
| 30543 | 30775 | #endif |
| 30544 | 30776 | |
| | @@ -31210,11 +31442,15 @@ |
| 31210 | 31442 | #else |
| 31211 | 31443 | { "fchown", (sqlite3_syscall_ptr)0, 0 }, |
| 31212 | 31444 | #endif |
| 31213 | 31445 | #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent) |
| 31214 | 31446 | |
| 31447 | +#if defined(HAVE_FCHOWN) |
| 31215 | 31448 | { "geteuid", (sqlite3_syscall_ptr)geteuid, 0 }, |
| 31449 | +#else |
| 31450 | + { "geteuid", (sqlite3_syscall_ptr)0, 0 }, |
| 31451 | +#endif |
| 31216 | 31452 | #define osGeteuid ((uid_t(*)(void))aSyscall[21].pCurrent) |
| 31217 | 31453 | |
| 31218 | 31454 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 31219 | 31455 | { "mmap", (sqlite3_syscall_ptr)mmap, 0 }, |
| 31220 | 31456 | #else |
| | @@ -31438,19 +31674,20 @@ |
| 31438 | 31674 | ** |
| 31439 | 31675 | ** unixEnterMutex() |
| 31440 | 31676 | ** assert( unixMutexHeld() ); |
| 31441 | 31677 | ** unixEnterLeave() |
| 31442 | 31678 | */ |
| 31679 | +static sqlite3_mutex *unixBigLock = 0; |
| 31443 | 31680 | static void unixEnterMutex(void){ |
| 31444 | | - sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); |
| 31681 | + sqlite3_mutex_enter(unixBigLock); |
| 31445 | 31682 | } |
| 31446 | 31683 | static void unixLeaveMutex(void){ |
| 31447 | | - sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); |
| 31684 | + sqlite3_mutex_leave(unixBigLock); |
| 31448 | 31685 | } |
| 31449 | 31686 | #ifdef SQLITE_DEBUG |
| 31450 | 31687 | static int unixMutexHeld(void) { |
| 31451 | | - return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); |
| 31688 | + return sqlite3_mutex_held(unixBigLock); |
| 31452 | 31689 | } |
| 31453 | 31690 | #endif |
| 31454 | 31691 | |
| 31455 | 31692 | |
| 31456 | 31693 | #ifdef SQLITE_HAVE_OS_TRACE |
| | @@ -34917,16 +35154,14 @@ |
| 34917 | 35154 | /* Locks are within range */ |
| 34918 | 35155 | assert( n>=1 && n<=SQLITE_SHM_NLOCK ); |
| 34919 | 35156 | |
| 34920 | 35157 | if( pShmNode->h>=0 ){ |
| 34921 | 35158 | /* Initialize the locking parameters */ |
| 34922 | | - memset(&f, 0, sizeof(f)); |
| 34923 | 35159 | f.l_type = lockType; |
| 34924 | 35160 | f.l_whence = SEEK_SET; |
| 34925 | 35161 | f.l_start = ofst; |
| 34926 | 35162 | f.l_len = n; |
| 34927 | | - |
| 34928 | 35163 | rc = osFcntl(pShmNode->h, F_SETLK, &f); |
| 34929 | 35164 | rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY; |
| 34930 | 35165 | } |
| 34931 | 35166 | |
| 34932 | 35167 | /* Update the global lock state and do debug tracing */ |
| | @@ -36588,11 +36823,10 @@ |
| 36588 | 36823 | */ |
| 36589 | 36824 | if( randomnessPid!=osGetpid(0) ){ |
| 36590 | 36825 | randomnessPid = osGetpid(0); |
| 36591 | 36826 | sqlite3_randomness(0,0); |
| 36592 | 36827 | } |
| 36593 | | - |
| 36594 | 36828 | memset(p, 0, sizeof(unixFile)); |
| 36595 | 36829 | |
| 36596 | 36830 | if( eType==SQLITE_OPEN_MAIN_DB ){ |
| 36597 | 36831 | UnixUnusedFd *pUnused; |
| 36598 | 36832 | pUnused = findReusableFd(zName, flags); |
| | @@ -38463,10 +38697,11 @@ |
| 38463 | 38697 | |
| 38464 | 38698 | /* Register all VFSes defined in the aVfs[] array */ |
| 38465 | 38699 | for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ |
| 38466 | 38700 | sqlite3_vfs_register(&aVfs[i], i==0); |
| 38467 | 38701 | } |
| 38702 | + unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1); |
| 38468 | 38703 | return SQLITE_OK; |
| 38469 | 38704 | } |
| 38470 | 38705 | |
| 38471 | 38706 | /* |
| 38472 | 38707 | ** Shutdown the operating system interface. |
| | @@ -38474,10 +38709,11 @@ |
| 38474 | 38709 | ** Some operating systems might need to do some cleanup in this routine, |
| 38475 | 38710 | ** to release dynamically allocated objects. But not on unix. |
| 38476 | 38711 | ** This routine is a no-op for unix. |
| 38477 | 38712 | */ |
| 38478 | 38713 | SQLITE_API int sqlite3_os_end(void){ |
| 38714 | + unixBigLock = 0; |
| 38479 | 38715 | return SQLITE_OK; |
| 38480 | 38716 | } |
| 38481 | 38717 | |
| 38482 | 38718 | #endif /* SQLITE_OS_UNIX */ |
| 38483 | 38719 | |
| | @@ -42312,19 +42548,20 @@ |
| 42312 | 42548 | ** |
| 42313 | 42549 | ** winShmEnterMutex() |
| 42314 | 42550 | ** assert( winShmMutexHeld() ); |
| 42315 | 42551 | ** winShmLeaveMutex() |
| 42316 | 42552 | */ |
| 42553 | +static sqlite3_mutex *winBigLock = 0; |
| 42317 | 42554 | static void winShmEnterMutex(void){ |
| 42318 | | - sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); |
| 42555 | + sqlite3_mutex_enter(winBigLock); |
| 42319 | 42556 | } |
| 42320 | 42557 | static void winShmLeaveMutex(void){ |
| 42321 | | - sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); |
| 42558 | + sqlite3_mutex_leave(winBigLock); |
| 42322 | 42559 | } |
| 42323 | 42560 | #ifndef NDEBUG |
| 42324 | 42561 | static int winShmMutexHeld(void) { |
| 42325 | | - return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); |
| 42562 | + return sqlite3_mutex_held(winBigLock); |
| 42326 | 42563 | } |
| 42327 | 42564 | #endif |
| 42328 | 42565 | |
| 42329 | 42566 | /* |
| 42330 | 42567 | ** Object used to represent a single file opened and mmapped to provide |
| | @@ -44742,10 +44979,14 @@ |
| 44742 | 44979 | sqlite3_vfs_register(&winNolockVfs, 0); |
| 44743 | 44980 | |
| 44744 | 44981 | #if defined(SQLITE_WIN32_HAS_WIDE) |
| 44745 | 44982 | sqlite3_vfs_register(&winLongPathNolockVfs, 0); |
| 44746 | 44983 | #endif |
| 44984 | + |
| 44985 | +#ifndef SQLITE_OMIT_WAL |
| 44986 | + winBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1); |
| 44987 | +#endif |
| 44747 | 44988 | |
| 44748 | 44989 | return SQLITE_OK; |
| 44749 | 44990 | } |
| 44750 | 44991 | |
| 44751 | 44992 | SQLITE_API int sqlite3_os_end(void){ |
| | @@ -44753,16 +44994,613 @@ |
| 44753 | 44994 | if( sleepObj!=NULL ){ |
| 44754 | 44995 | osCloseHandle(sleepObj); |
| 44755 | 44996 | sleepObj = NULL; |
| 44756 | 44997 | } |
| 44757 | 44998 | #endif |
| 44999 | + |
| 45000 | +#ifndef SQLITE_OMIT_WAL |
| 45001 | + winBigLock = 0; |
| 45002 | +#endif |
| 45003 | + |
| 44758 | 45004 | return SQLITE_OK; |
| 44759 | 45005 | } |
| 44760 | 45006 | |
| 44761 | 45007 | #endif /* SQLITE_OS_WIN */ |
| 44762 | 45008 | |
| 44763 | 45009 | /************** End of os_win.c **********************************************/ |
| 45010 | +/************** Begin file memdb.c *******************************************/ |
| 45011 | +/* |
| 45012 | +** 2016-09-07 |
| 45013 | +** |
| 45014 | +** The author disclaims copyright to this source code. In place of |
| 45015 | +** a legal notice, here is a blessing: |
| 45016 | +** |
| 45017 | +** May you do good and not evil. |
| 45018 | +** May you find forgiveness for yourself and forgive others. |
| 45019 | +** May you share freely, never taking more than you give. |
| 45020 | +** |
| 45021 | +****************************************************************************** |
| 45022 | +** |
| 45023 | +** This file implements in-memory VFS. A database is held as a contiguous |
| 45024 | +** block of memory. |
| 45025 | +** |
| 45026 | +** This file also implements interface sqlite3_serialize() and |
| 45027 | +** sqlite3_deserialize(). |
| 45028 | +*/ |
| 45029 | +#ifdef SQLITE_ENABLE_DESERIALIZE |
| 45030 | +/* #include "sqliteInt.h" */ |
| 45031 | + |
| 45032 | +/* |
| 45033 | +** Forward declaration of objects used by this utility |
| 45034 | +*/ |
| 45035 | +typedef struct sqlite3_vfs MemVfs; |
| 45036 | +typedef struct MemFile MemFile; |
| 45037 | + |
| 45038 | +/* Access to a lower-level VFS that (might) implement dynamic loading, |
| 45039 | +** access to randomness, etc. |
| 45040 | +*/ |
| 45041 | +#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData)) |
| 45042 | + |
| 45043 | +/* An open file */ |
| 45044 | +struct MemFile { |
| 45045 | + sqlite3_file base; /* IO methods */ |
| 45046 | + sqlite3_int64 sz; /* Size of the file */ |
| 45047 | + sqlite3_int64 szMax; /* Space allocated to aData */ |
| 45048 | + unsigned char *aData; /* content of the file */ |
| 45049 | + int nMmap; /* Number of memory mapped pages */ |
| 45050 | + unsigned mFlags; /* Flags */ |
| 45051 | + int eLock; /* Most recent lock against this file */ |
| 45052 | +}; |
| 45053 | + |
| 45054 | +/* |
| 45055 | +** Methods for MemFile |
| 45056 | +*/ |
| 45057 | +static int memdbClose(sqlite3_file*); |
| 45058 | +static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); |
| 45059 | +static int memdbWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst); |
| 45060 | +static int memdbTruncate(sqlite3_file*, sqlite3_int64 size); |
| 45061 | +static int memdbSync(sqlite3_file*, int flags); |
| 45062 | +static int memdbFileSize(sqlite3_file*, sqlite3_int64 *pSize); |
| 45063 | +static int memdbLock(sqlite3_file*, int); |
| 45064 | +/* static int memdbCheckReservedLock(sqlite3_file*, int *pResOut);// not used */ |
| 45065 | +static int memdbFileControl(sqlite3_file*, int op, void *pArg); |
| 45066 | +/* static int memdbSectorSize(sqlite3_file*); // not used */ |
| 45067 | +static int memdbDeviceCharacteristics(sqlite3_file*); |
| 45068 | +static int memdbFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp); |
| 45069 | +static int memdbUnfetch(sqlite3_file*, sqlite3_int64 iOfst, void *p); |
| 45070 | + |
| 45071 | +/* |
| 45072 | +** Methods for MemVfs |
| 45073 | +*/ |
| 45074 | +static int memdbOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *); |
| 45075 | +/* static int memdbDelete(sqlite3_vfs*, const char *zName, int syncDir); */ |
| 45076 | +static int memdbAccess(sqlite3_vfs*, const char *zName, int flags, int *); |
| 45077 | +static int memdbFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut); |
| 45078 | +static void *memdbDlOpen(sqlite3_vfs*, const char *zFilename); |
| 45079 | +static void memdbDlError(sqlite3_vfs*, int nByte, char *zErrMsg); |
| 45080 | +static void (*memdbDlSym(sqlite3_vfs *pVfs, void *p, const char*zSym))(void); |
| 45081 | +static void memdbDlClose(sqlite3_vfs*, void*); |
| 45082 | +static int memdbRandomness(sqlite3_vfs*, int nByte, char *zOut); |
| 45083 | +static int memdbSleep(sqlite3_vfs*, int microseconds); |
| 45084 | +/* static int memdbCurrentTime(sqlite3_vfs*, double*); */ |
| 45085 | +static int memdbGetLastError(sqlite3_vfs*, int, char *); |
| 45086 | +static int memdbCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*); |
| 45087 | + |
| 45088 | +static sqlite3_vfs memdb_vfs = { |
| 45089 | + 2, /* iVersion */ |
| 45090 | + 0, /* szOsFile (set when registered) */ |
| 45091 | + 1024, /* mxPathname */ |
| 45092 | + 0, /* pNext */ |
| 45093 | + "memdb", /* zName */ |
| 45094 | + 0, /* pAppData (set when registered) */ |
| 45095 | + memdbOpen, /* xOpen */ |
| 45096 | + 0, /* memdbDelete, */ /* xDelete */ |
| 45097 | + memdbAccess, /* xAccess */ |
| 45098 | + memdbFullPathname, /* xFullPathname */ |
| 45099 | + memdbDlOpen, /* xDlOpen */ |
| 45100 | + memdbDlError, /* xDlError */ |
| 45101 | + memdbDlSym, /* xDlSym */ |
| 45102 | + memdbDlClose, /* xDlClose */ |
| 45103 | + memdbRandomness, /* xRandomness */ |
| 45104 | + memdbSleep, /* xSleep */ |
| 45105 | + 0, /* memdbCurrentTime, */ /* xCurrentTime */ |
| 45106 | + memdbGetLastError, /* xGetLastError */ |
| 45107 | + memdbCurrentTimeInt64 /* xCurrentTimeInt64 */ |
| 45108 | +}; |
| 45109 | + |
| 45110 | +static const sqlite3_io_methods memdb_io_methods = { |
| 45111 | + 3, /* iVersion */ |
| 45112 | + memdbClose, /* xClose */ |
| 45113 | + memdbRead, /* xRead */ |
| 45114 | + memdbWrite, /* xWrite */ |
| 45115 | + memdbTruncate, /* xTruncate */ |
| 45116 | + memdbSync, /* xSync */ |
| 45117 | + memdbFileSize, /* xFileSize */ |
| 45118 | + memdbLock, /* xLock */ |
| 45119 | + memdbLock, /* xUnlock - same as xLock in this case */ |
| 45120 | + 0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */ |
| 45121 | + memdbFileControl, /* xFileControl */ |
| 45122 | + 0, /* memdbSectorSize,*/ /* xSectorSize */ |
| 45123 | + memdbDeviceCharacteristics, /* xDeviceCharacteristics */ |
| 45124 | + 0, /* xShmMap */ |
| 45125 | + 0, /* xShmLock */ |
| 45126 | + 0, /* xShmBarrier */ |
| 45127 | + 0, /* xShmUnmap */ |
| 45128 | + memdbFetch, /* xFetch */ |
| 45129 | + memdbUnfetch /* xUnfetch */ |
| 45130 | +}; |
| 45131 | + |
| 45132 | + |
| 45133 | + |
| 45134 | +/* |
| 45135 | +** Close an memdb-file. |
| 45136 | +** |
| 45137 | +** The pData pointer is owned by the application, so there is nothing |
| 45138 | +** to free. |
| 45139 | +*/ |
| 45140 | +static int memdbClose(sqlite3_file *pFile){ |
| 45141 | + MemFile *p = (MemFile *)pFile; |
| 45142 | + if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ) sqlite3_free(p->aData); |
| 45143 | + return SQLITE_OK; |
| 45144 | +} |
| 45145 | + |
| 45146 | +/* |
| 45147 | +** Read data from an memdb-file. |
| 45148 | +*/ |
| 45149 | +static int memdbRead( |
| 45150 | + sqlite3_file *pFile, |
| 45151 | + void *zBuf, |
| 45152 | + int iAmt, |
| 45153 | + sqlite_int64 iOfst |
| 45154 | +){ |
| 45155 | + MemFile *p = (MemFile *)pFile; |
| 45156 | + if( iOfst+iAmt>p->sz ){ |
| 45157 | + memset(zBuf, 0, iAmt); |
| 45158 | + if( iOfst<p->sz ) memcpy(zBuf, p->aData+iOfst, p->sz - iOfst); |
| 45159 | + return SQLITE_IOERR_SHORT_READ; |
| 45160 | + } |
| 45161 | + memcpy(zBuf, p->aData+iOfst, iAmt); |
| 45162 | + return SQLITE_OK; |
| 45163 | +} |
| 45164 | + |
| 45165 | +/* |
| 45166 | +** Try to enlarge the memory allocation to hold at least sz bytes |
| 45167 | +*/ |
| 45168 | +static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){ |
| 45169 | + unsigned char *pNew; |
| 45170 | + if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){ |
| 45171 | + return SQLITE_FULL; |
| 45172 | + } |
| 45173 | + pNew = sqlite3_realloc64(p->aData, newSz); |
| 45174 | + if( pNew==0 ) return SQLITE_NOMEM; |
| 45175 | + p->aData = pNew; |
| 45176 | + p->szMax = newSz; |
| 45177 | + return SQLITE_OK; |
| 45178 | +} |
| 45179 | + |
| 45180 | +/* |
| 45181 | +** Write data to an memdb-file. |
| 45182 | +*/ |
| 45183 | +static int memdbWrite( |
| 45184 | + sqlite3_file *pFile, |
| 45185 | + const void *z, |
| 45186 | + int iAmt, |
| 45187 | + sqlite_int64 iOfst |
| 45188 | +){ |
| 45189 | + MemFile *p = (MemFile *)pFile; |
| 45190 | + if( iOfst+iAmt>p->sz ){ |
| 45191 | + int rc; |
| 45192 | + if( iOfst+iAmt>p->szMax |
| 45193 | + && (rc = memdbEnlarge(p, (iOfst+iAmt)*2))!=SQLITE_OK |
| 45194 | + ){ |
| 45195 | + return rc; |
| 45196 | + } |
| 45197 | + if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz); |
| 45198 | + p->sz = iOfst+iAmt; |
| 45199 | + } |
| 45200 | + memcpy(p->aData+iOfst, z, iAmt); |
| 45201 | + return SQLITE_OK; |
| 45202 | +} |
| 45203 | + |
| 45204 | +/* |
| 45205 | +** Truncate an memdb-file. |
| 45206 | +** |
| 45207 | +** In rollback mode (which is always the case for memdb, as it does not |
| 45208 | +** support WAL mode) the truncate() method is only used to reduce |
| 45209 | +** the size of a file, never to increase the size. |
| 45210 | +*/ |
| 45211 | +static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){ |
| 45212 | + MemFile *p = (MemFile *)pFile; |
| 45213 | + if( NEVER(size>p->sz) ) return SQLITE_FULL; |
| 45214 | + p->sz = size; |
| 45215 | + return SQLITE_OK; |
| 45216 | +} |
| 45217 | + |
| 45218 | +/* |
| 45219 | +** Sync an memdb-file. |
| 45220 | +*/ |
| 45221 | +static int memdbSync(sqlite3_file *pFile, int flags){ |
| 45222 | + return SQLITE_OK; |
| 45223 | +} |
| 45224 | + |
| 45225 | +/* |
| 45226 | +** Return the current file-size of an memdb-file. |
| 45227 | +*/ |
| 45228 | +static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ |
| 45229 | + MemFile *p = (MemFile *)pFile; |
| 45230 | + *pSize = p->sz; |
| 45231 | + return SQLITE_OK; |
| 45232 | +} |
| 45233 | + |
| 45234 | +/* |
| 45235 | +** Lock an memdb-file. |
| 45236 | +*/ |
| 45237 | +static int memdbLock(sqlite3_file *pFile, int eLock){ |
| 45238 | + MemFile *p = (MemFile *)pFile; |
| 45239 | + p->eLock = eLock; |
| 45240 | + return SQLITE_OK; |
| 45241 | +} |
| 45242 | + |
| 45243 | +#if 0 /* Never used because memdbAccess() always returns false */ |
| 45244 | +/* |
| 45245 | +** Check if another file-handle holds a RESERVED lock on an memdb-file. |
| 45246 | +*/ |
| 45247 | +static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){ |
| 45248 | + *pResOut = 0; |
| 45249 | + return SQLITE_OK; |
| 45250 | +} |
| 45251 | +#endif |
| 45252 | + |
| 45253 | +/* |
| 45254 | +** File control method. For custom operations on an memdb-file. |
| 45255 | +*/ |
| 45256 | +static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){ |
| 45257 | + MemFile *p = (MemFile *)pFile; |
| 45258 | + int rc = SQLITE_NOTFOUND; |
| 45259 | + if( op==SQLITE_FCNTL_VFSNAME ){ |
| 45260 | + *(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz); |
| 45261 | + rc = SQLITE_OK; |
| 45262 | + } |
| 45263 | + return rc; |
| 45264 | +} |
| 45265 | + |
| 45266 | +#if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */ |
| 45267 | +/* |
| 45268 | +** Return the sector-size in bytes for an memdb-file. |
| 45269 | +*/ |
| 45270 | +static int memdbSectorSize(sqlite3_file *pFile){ |
| 45271 | + return 1024; |
| 45272 | +} |
| 45273 | +#endif |
| 45274 | + |
| 45275 | +/* |
| 45276 | +** Return the device characteristic flags supported by an memdb-file. |
| 45277 | +*/ |
| 45278 | +static int memdbDeviceCharacteristics(sqlite3_file *pFile){ |
| 45279 | + return SQLITE_IOCAP_ATOMIC | |
| 45280 | + SQLITE_IOCAP_POWERSAFE_OVERWRITE | |
| 45281 | + SQLITE_IOCAP_SAFE_APPEND | |
| 45282 | + SQLITE_IOCAP_SEQUENTIAL; |
| 45283 | +} |
| 45284 | + |
| 45285 | +/* Fetch a page of a memory-mapped file */ |
| 45286 | +static int memdbFetch( |
| 45287 | + sqlite3_file *pFile, |
| 45288 | + sqlite3_int64 iOfst, |
| 45289 | + int iAmt, |
| 45290 | + void **pp |
| 45291 | +){ |
| 45292 | + MemFile *p = (MemFile *)pFile; |
| 45293 | + p->nMmap++; |
| 45294 | + *pp = (void*)(p->aData + iOfst); |
| 45295 | + return SQLITE_OK; |
| 45296 | +} |
| 45297 | + |
| 45298 | +/* Release a memory-mapped page */ |
| 45299 | +static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){ |
| 45300 | + MemFile *p = (MemFile *)pFile; |
| 45301 | + p->nMmap--; |
| 45302 | + return SQLITE_OK; |
| 45303 | +} |
| 45304 | + |
| 45305 | +/* |
| 45306 | +** Open an mem file handle. |
| 45307 | +*/ |
| 45308 | +static int memdbOpen( |
| 45309 | + sqlite3_vfs *pVfs, |
| 45310 | + const char *zName, |
| 45311 | + sqlite3_file *pFile, |
| 45312 | + int flags, |
| 45313 | + int *pOutFlags |
| 45314 | +){ |
| 45315 | + MemFile *p = (MemFile*)pFile; |
| 45316 | + if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){ |
| 45317 | + return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFile, flags, pOutFlags); |
| 45318 | + } |
| 45319 | + memset(p, 0, sizeof(*p)); |
| 45320 | + p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; |
| 45321 | + assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */ |
| 45322 | + *pOutFlags = flags | SQLITE_OPEN_MEMORY; |
| 45323 | + p->base.pMethods = &memdb_io_methods; |
| 45324 | + return SQLITE_OK; |
| 45325 | +} |
| 45326 | + |
| 45327 | +#if 0 /* Only used to delete rollback journals, master journals, and WAL |
| 45328 | + ** files, none of which exist in memdb. So this routine is never used */ |
| 45329 | +/* |
| 45330 | +** Delete the file located at zPath. If the dirSync argument is true, |
| 45331 | +** ensure the file-system modifications are synced to disk before |
| 45332 | +** returning. |
| 45333 | +*/ |
| 45334 | +static int memdbDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ |
| 45335 | + return SQLITE_IOERR_DELETE; |
| 45336 | +} |
| 45337 | +#endif |
| 45338 | + |
| 45339 | +/* |
| 45340 | +** Test for access permissions. Return true if the requested permission |
| 45341 | +** is available, or false otherwise. |
| 45342 | +** |
| 45343 | +** With memdb, no files ever exist on disk. So always return false. |
| 45344 | +*/ |
| 45345 | +static int memdbAccess( |
| 45346 | + sqlite3_vfs *pVfs, |
| 45347 | + const char *zPath, |
| 45348 | + int flags, |
| 45349 | + int *pResOut |
| 45350 | +){ |
| 45351 | + *pResOut = 0; |
| 45352 | + return SQLITE_OK; |
| 45353 | +} |
| 45354 | + |
| 45355 | +/* |
| 45356 | +** Populate buffer zOut with the full canonical pathname corresponding |
| 45357 | +** to the pathname in zPath. zOut is guaranteed to point to a buffer |
| 45358 | +** of at least (INST_MAX_PATHNAME+1) bytes. |
| 45359 | +*/ |
| 45360 | +static int memdbFullPathname( |
| 45361 | + sqlite3_vfs *pVfs, |
| 45362 | + const char *zPath, |
| 45363 | + int nOut, |
| 45364 | + char *zOut |
| 45365 | +){ |
| 45366 | + sqlite3_snprintf(nOut, zOut, "%s", zPath); |
| 45367 | + return SQLITE_OK; |
| 45368 | +} |
| 45369 | + |
| 45370 | +/* |
| 45371 | +** Open the dynamic library located at zPath and return a handle. |
| 45372 | +*/ |
| 45373 | +static void *memdbDlOpen(sqlite3_vfs *pVfs, const char *zPath){ |
| 45374 | + return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath); |
| 45375 | +} |
| 45376 | + |
| 45377 | +/* |
| 45378 | +** Populate the buffer zErrMsg (size nByte bytes) with a human readable |
| 45379 | +** utf-8 string describing the most recent error encountered associated |
| 45380 | +** with dynamic libraries. |
| 45381 | +*/ |
| 45382 | +static void memdbDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){ |
| 45383 | + ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg); |
| 45384 | +} |
| 45385 | + |
| 45386 | +/* |
| 45387 | +** Return a pointer to the symbol zSymbol in the dynamic library pHandle. |
| 45388 | +*/ |
| 45389 | +static void (*memdbDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){ |
| 45390 | + return ORIGVFS(pVfs)->xDlSym(ORIGVFS(pVfs), p, zSym); |
| 45391 | +} |
| 45392 | + |
| 45393 | +/* |
| 45394 | +** Close the dynamic library handle pHandle. |
| 45395 | +*/ |
| 45396 | +static void memdbDlClose(sqlite3_vfs *pVfs, void *pHandle){ |
| 45397 | + ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle); |
| 45398 | +} |
| 45399 | + |
| 45400 | +/* |
| 45401 | +** Populate the buffer pointed to by zBufOut with nByte bytes of |
| 45402 | +** random data. |
| 45403 | +*/ |
| 45404 | +static int memdbRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ |
| 45405 | + return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut); |
| 45406 | +} |
| 45407 | + |
| 45408 | +/* |
| 45409 | +** Sleep for nMicro microseconds. Return the number of microseconds |
| 45410 | +** actually slept. |
| 45411 | +*/ |
| 45412 | +static int memdbSleep(sqlite3_vfs *pVfs, int nMicro){ |
| 45413 | + return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro); |
| 45414 | +} |
| 45415 | + |
| 45416 | +#if 0 /* Never used. Modern cores only call xCurrentTimeInt64() */ |
| 45417 | +/* |
| 45418 | +** Return the current time as a Julian Day number in *pTimeOut. |
| 45419 | +*/ |
| 45420 | +static int memdbCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ |
| 45421 | + return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut); |
| 45422 | +} |
| 45423 | +#endif |
| 45424 | + |
| 45425 | +static int memdbGetLastError(sqlite3_vfs *pVfs, int a, char *b){ |
| 45426 | + return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b); |
| 45427 | +} |
| 45428 | +static int memdbCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){ |
| 45429 | + return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p); |
| 45430 | +} |
| 45431 | + |
| 45432 | +/* |
| 45433 | +** Translate a database connection pointer and schema name into a |
| 45434 | +** MemFile pointer. |
| 45435 | +*/ |
| 45436 | +static MemFile *memdbFromDbSchema(sqlite3 *db, const char *zSchema){ |
| 45437 | + MemFile *p = 0; |
| 45438 | + int rc = sqlite3_file_control(db, zSchema, SQLITE_FCNTL_FILE_POINTER, &p); |
| 45439 | + if( rc ) return 0; |
| 45440 | + if( p->base.pMethods!=&memdb_io_methods ) return 0; |
| 45441 | + return p; |
| 45442 | +} |
| 45443 | + |
| 45444 | +/* |
| 45445 | +** Return the serialization of a database |
| 45446 | +*/ |
| 45447 | +SQLITE_API unsigned char *sqlite3_serialize( |
| 45448 | + sqlite3 *db, /* The database connection */ |
| 45449 | + const char *zSchema, /* Which database within the connection */ |
| 45450 | + sqlite3_int64 *piSize, /* Write size here, if not NULL */ |
| 45451 | + unsigned int mFlags /* Maybe SQLITE_SERIALIZE_NOCOPY */ |
| 45452 | +){ |
| 45453 | + MemFile *p; |
| 45454 | + int iDb; |
| 45455 | + Btree *pBt; |
| 45456 | + sqlite3_int64 sz; |
| 45457 | + int szPage = 0; |
| 45458 | + sqlite3_stmt *pStmt = 0; |
| 45459 | + unsigned char *pOut; |
| 45460 | + char *zSql; |
| 45461 | + int rc; |
| 45462 | + |
| 45463 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 45464 | + if( !sqlite3SafetyCheckOk(db) ){ |
| 45465 | + (void)SQLITE_MISUSE_BKPT; |
| 45466 | + return 0; |
| 45467 | + } |
| 45468 | +#endif |
| 45469 | + |
| 45470 | + if( zSchema==0 ) zSchema = db->aDb[0].zDbSName; |
| 45471 | + p = memdbFromDbSchema(db, zSchema); |
| 45472 | + iDb = sqlite3FindDbName(db, zSchema); |
| 45473 | + if( piSize ) *piSize = -1; |
| 45474 | + if( iDb<0 ) return 0; |
| 45475 | + if( p ){ |
| 45476 | + if( piSize ) *piSize = p->sz; |
| 45477 | + if( mFlags & SQLITE_SERIALIZE_NOCOPY ){ |
| 45478 | + pOut = p->aData; |
| 45479 | + }else{ |
| 45480 | + pOut = sqlite3_malloc64( p->sz ); |
| 45481 | + if( pOut ) memcpy(pOut, p->aData, p->sz); |
| 45482 | + } |
| 45483 | + return pOut; |
| 45484 | + } |
| 45485 | + pBt = db->aDb[iDb].pBt; |
| 45486 | + if( pBt==0 ) return 0; |
| 45487 | + szPage = sqlite3BtreeGetPageSize(pBt); |
| 45488 | + zSql = sqlite3_mprintf("PRAGMA \"%w\".page_count", zSchema); |
| 45489 | + rc = zSql ? sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) : SQLITE_NOMEM; |
| 45490 | + sqlite3_free(zSql); |
| 45491 | + if( rc ) return 0; |
| 45492 | + rc = sqlite3_step(pStmt); |
| 45493 | + if( rc!=SQLITE_ROW ){ |
| 45494 | + pOut = 0; |
| 45495 | + }else{ |
| 45496 | + sz = sqlite3_column_int64(pStmt, 0)*szPage; |
| 45497 | + if( piSize ) *piSize = sz; |
| 45498 | + if( mFlags & SQLITE_SERIALIZE_NOCOPY ){ |
| 45499 | + pOut = 0; |
| 45500 | + }else{ |
| 45501 | + pOut = sqlite3_malloc64( sz ); |
| 45502 | + if( pOut ){ |
| 45503 | + int nPage = sqlite3_column_int(pStmt, 0); |
| 45504 | + Pager *pPager = sqlite3BtreePager(pBt); |
| 45505 | + int pgno; |
| 45506 | + for(pgno=1; pgno<=nPage; pgno++){ |
| 45507 | + DbPage *pPage = 0; |
| 45508 | + unsigned char *pTo = pOut + szPage*(sqlite3_int64)(pgno-1); |
| 45509 | + rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pPage, 0); |
| 45510 | + if( rc==SQLITE_OK ){ |
| 45511 | + memcpy(pTo, sqlite3PagerGetData(pPage), szPage); |
| 45512 | + }else{ |
| 45513 | + memset(pTo, 0, szPage); |
| 45514 | + } |
| 45515 | + sqlite3PagerUnref(pPage); |
| 45516 | + } |
| 45517 | + } |
| 45518 | + } |
| 45519 | + } |
| 45520 | + sqlite3_finalize(pStmt); |
| 45521 | + return pOut; |
| 45522 | +} |
| 45523 | + |
| 45524 | +/* Convert zSchema to a MemDB and initialize its content. |
| 45525 | +*/ |
| 45526 | +SQLITE_API int sqlite3_deserialize( |
| 45527 | + sqlite3 *db, /* The database connection */ |
| 45528 | + const char *zSchema, /* Which DB to reopen with the deserialization */ |
| 45529 | + unsigned char *pData, /* The serialized database content */ |
| 45530 | + sqlite3_int64 szDb, /* Number bytes in the deserialization */ |
| 45531 | + sqlite3_int64 szBuf, /* Total size of buffer pData[] */ |
| 45532 | + unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ |
| 45533 | +){ |
| 45534 | + MemFile *p; |
| 45535 | + char *zSql; |
| 45536 | + sqlite3_stmt *pStmt = 0; |
| 45537 | + int rc; |
| 45538 | + int iDb; |
| 45539 | + |
| 45540 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 45541 | + if( !sqlite3SafetyCheckOk(db) ){ |
| 45542 | + return SQLITE_MISUSE_BKPT; |
| 45543 | + } |
| 45544 | + if( szDb<0 ) return SQLITE_MISUSE_BKPT; |
| 45545 | + if( szBuf<0 ) return SQLITE_MISUSE_BKPT; |
| 45546 | +#endif |
| 45547 | + |
| 45548 | + sqlite3_mutex_enter(db->mutex); |
| 45549 | + if( zSchema==0 ) zSchema = db->aDb[0].zDbSName; |
| 45550 | + iDb = sqlite3FindDbName(db, zSchema); |
| 45551 | + if( iDb<0 ){ |
| 45552 | + rc = SQLITE_ERROR; |
| 45553 | + goto end_deserialize; |
| 45554 | + } |
| 45555 | + zSql = sqlite3_mprintf("ATTACH x AS %Q", zSchema); |
| 45556 | + rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); |
| 45557 | + sqlite3_free(zSql); |
| 45558 | + if( rc ) goto end_deserialize; |
| 45559 | + db->init.iDb = (u8)iDb; |
| 45560 | + db->init.reopenMemdb = 1; |
| 45561 | + rc = sqlite3_step(pStmt); |
| 45562 | + db->init.reopenMemdb = 0; |
| 45563 | + if( rc!=SQLITE_DONE ){ |
| 45564 | + rc = SQLITE_ERROR; |
| 45565 | + goto end_deserialize; |
| 45566 | + } |
| 45567 | + p = memdbFromDbSchema(db, zSchema); |
| 45568 | + if( p==0 ){ |
| 45569 | + rc = SQLITE_ERROR; |
| 45570 | + }else{ |
| 45571 | + p->aData = pData; |
| 45572 | + p->sz = szDb; |
| 45573 | + p->szMax = szBuf; |
| 45574 | + p->mFlags = mFlags; |
| 45575 | + rc = SQLITE_OK; |
| 45576 | + } |
| 45577 | + |
| 45578 | +end_deserialize: |
| 45579 | + sqlite3_finalize(pStmt); |
| 45580 | + sqlite3_mutex_leave(db->mutex); |
| 45581 | + return rc; |
| 45582 | +} |
| 45583 | + |
| 45584 | +/* |
| 45585 | +** This routine is called when the extension is loaded. |
| 45586 | +** Register the new VFS. |
| 45587 | +*/ |
| 45588 | +SQLITE_PRIVATE int sqlite3MemdbInit(void){ |
| 45589 | + sqlite3_vfs *pLower = sqlite3_vfs_find(0); |
| 45590 | + int sz = pLower->szOsFile; |
| 45591 | + memdb_vfs.pAppData = pLower; |
| 45592 | + /* In all known configurations of SQLite, the size of a default |
| 45593 | + ** sqlite3_file is greater than the size of a memdb sqlite3_file. |
| 45594 | + ** Should that ever change, remove the following NEVER() */ |
| 45595 | + if( NEVER(sz<sizeof(MemFile)) ) sz = sizeof(MemFile); |
| 45596 | + memdb_vfs.szOsFile = sz; |
| 45597 | + return sqlite3_vfs_register(&memdb_vfs, 0); |
| 45598 | +} |
| 45599 | +#endif /* SQLITE_ENABLE_DESERIALIZE */ |
| 45600 | + |
| 45601 | +/************** End of memdb.c ***********************************************/ |
| 44764 | 45602 | /************** Begin file bitvec.c ******************************************/ |
| 44765 | 45603 | /* |
| 44766 | 45604 | ** 2008 February 16 |
| 44767 | 45605 | ** |
| 44768 | 45606 | ** The author disclaims copyright to this source code. In place of |
| | @@ -45607,11 +46445,11 @@ |
| 45607 | 46445 | int rc; |
| 45608 | 46446 | #ifdef SQLITE_LOG_CACHE_SPILL |
| 45609 | 46447 | sqlite3_log(SQLITE_FULL, |
| 45610 | 46448 | "spill page %d making room for %d - cache used: %d/%d", |
| 45611 | 46449 | pPg->pgno, pgno, |
| 45612 | | - sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache), |
| 46450 | + sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache), |
| 45613 | 46451 | numberOfCachePages(pCache)); |
| 45614 | 46452 | #endif |
| 45615 | 46453 | pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno)); |
| 45616 | 46454 | rc = pCache->xStress(pCache->pStress, pPg); |
| 45617 | 46455 | pcacheDump(pCache); |
| | @@ -48663,11 +49501,11 @@ |
| 48663 | 49501 | i64 journalSizeLimit; /* Size limit for persistent journal files */ |
| 48664 | 49502 | char *zFilename; /* Name of the database file */ |
| 48665 | 49503 | char *zJournal; /* Name of the journal file */ |
| 48666 | 49504 | int (*xBusyHandler)(void*); /* Function to call when busy */ |
| 48667 | 49505 | void *pBusyHandlerArg; /* Context argument for xBusyHandler */ |
| 48668 | | - int aStat[3]; /* Total cache hits, misses and writes */ |
| 49506 | + int aStat[4]; /* Total cache hits, misses, writes, spills */ |
| 48669 | 49507 | #ifdef SQLITE_TEST |
| 48670 | 49508 | int nRead; /* Database pages read */ |
| 48671 | 49509 | #endif |
| 48672 | 49510 | void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */ |
| 48673 | 49511 | int (*xGet)(Pager*,Pgno,DbPage**,int); /* Routine to fetch a patch */ |
| | @@ -48691,10 +49529,11 @@ |
| 48691 | 49529 | ** or CACHE_WRITE to sqlite3_db_status(). |
| 48692 | 49530 | */ |
| 48693 | 49531 | #define PAGER_STAT_HIT 0 |
| 48694 | 49532 | #define PAGER_STAT_MISS 1 |
| 48695 | 49533 | #define PAGER_STAT_WRITE 2 |
| 49534 | +#define PAGER_STAT_SPILL 3 |
| 48696 | 49535 | |
| 48697 | 49536 | /* |
| 48698 | 49537 | ** The following global variables hold counters used for |
| 48699 | 49538 | ** testing purposes only. These variables do not exist in |
| 48700 | 49539 | ** a non-testing build. These variables are not thread-safe. |
| | @@ -49177,11 +50016,11 @@ |
| 49177 | 50016 | #else |
| 49178 | 50017 | UNUSED_PARAMETER(pPager); |
| 49179 | 50018 | #endif |
| 49180 | 50019 | |
| 49181 | 50020 | #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 49182 | | - if( dc&SQLITE_IOCAP_BATCH_ATOMIC ){ |
| 50021 | + if( pPager->dbSize>0 && (dc&SQLITE_IOCAP_BATCH_ATOMIC) ){ |
| 49183 | 50022 | return -1; |
| 49184 | 50023 | } |
| 49185 | 50024 | #endif |
| 49186 | 50025 | |
| 49187 | 50026 | #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| | @@ -52066,10 +52905,34 @@ |
| 52066 | 52905 | pNext = p->pDirty; |
| 52067 | 52906 | sqlite3_free(p); |
| 52068 | 52907 | } |
| 52069 | 52908 | } |
| 52070 | 52909 | |
| 52910 | +/* Verify that the database file has not be deleted or renamed out from |
| 52911 | +** under the pager. Return SQLITE_OK if the database is still where it ought |
| 52912 | +** to be on disk. Return non-zero (SQLITE_READONLY_DBMOVED or some other error |
| 52913 | +** code from sqlite3OsAccess()) if the database has gone missing. |
| 52914 | +*/ |
| 52915 | +static int databaseIsUnmoved(Pager *pPager){ |
| 52916 | + int bHasMoved = 0; |
| 52917 | + int rc; |
| 52918 | + |
| 52919 | + if( pPager->tempFile ) return SQLITE_OK; |
| 52920 | + if( pPager->dbSize==0 ) return SQLITE_OK; |
| 52921 | + assert( pPager->zFilename && pPager->zFilename[0] ); |
| 52922 | + rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved); |
| 52923 | + if( rc==SQLITE_NOTFOUND ){ |
| 52924 | + /* If the HAS_MOVED file-control is unimplemented, assume that the file |
| 52925 | + ** has not been moved. That is the historical behavior of SQLite: prior to |
| 52926 | + ** version 3.8.3, it never checked */ |
| 52927 | + rc = SQLITE_OK; |
| 52928 | + }else if( rc==SQLITE_OK && bHasMoved ){ |
| 52929 | + rc = SQLITE_READONLY_DBMOVED; |
| 52930 | + } |
| 52931 | + return rc; |
| 52932 | +} |
| 52933 | + |
| 52071 | 52934 | |
| 52072 | 52935 | /* |
| 52073 | 52936 | ** Shutdown the page cache. Free all memory and close all files. |
| 52074 | 52937 | ** |
| 52075 | 52938 | ** If a transaction was in progress when this routine is called, that |
| | @@ -52082,25 +52945,30 @@ |
| 52082 | 52945 | ** is made to roll it back. If an error occurs during the rollback |
| 52083 | 52946 | ** a hot journal may be left in the filesystem but no error is returned |
| 52084 | 52947 | ** to the caller. |
| 52085 | 52948 | */ |
| 52086 | 52949 | SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3 *db){ |
| 52087 | | - u8 *pTmp = (u8 *)pPager->pTmpSpace; |
| 52088 | | - |
| 52950 | + u8 *pTmp = (u8*)pPager->pTmpSpace; |
| 52089 | 52951 | assert( db || pagerUseWal(pPager)==0 ); |
| 52090 | 52952 | assert( assert_pager_state(pPager) ); |
| 52091 | 52953 | disable_simulated_io_errors(); |
| 52092 | 52954 | sqlite3BeginBenignMalloc(); |
| 52093 | 52955 | pagerFreeMapHdrs(pPager); |
| 52094 | 52956 | /* pPager->errCode = 0; */ |
| 52095 | 52957 | pPager->exclusiveMode = 0; |
| 52096 | 52958 | #ifndef SQLITE_OMIT_WAL |
| 52097 | | - assert( db || pPager->pWal==0 ); |
| 52098 | | - sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags, pPager->pageSize, |
| 52099 | | - (db && (db->flags & SQLITE_NoCkptOnClose) ? 0 : pTmp) |
| 52100 | | - ); |
| 52101 | | - pPager->pWal = 0; |
| 52959 | + { |
| 52960 | + u8 *a = 0; |
| 52961 | + assert( db || pPager->pWal==0 ); |
| 52962 | + if( db && 0==(db->flags & SQLITE_NoCkptOnClose) |
| 52963 | + && SQLITE_OK==databaseIsUnmoved(pPager) |
| 52964 | + ){ |
| 52965 | + a = pTmp; |
| 52966 | + } |
| 52967 | + sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags, pPager->pageSize,a); |
| 52968 | + pPager->pWal = 0; |
| 52969 | + } |
| 52102 | 52970 | #endif |
| 52103 | 52971 | pager_reset(pPager); |
| 52104 | 52972 | if( MEMDB ){ |
| 52105 | 52973 | pager_unlock(pPager); |
| 52106 | 52974 | }else{ |
| | @@ -52553,10 +53421,11 @@ |
| 52553 | 53421 | || (pPg->flags & PGHDR_NEED_SYNC)!=0) |
| 52554 | 53422 | ){ |
| 52555 | 53423 | return SQLITE_OK; |
| 52556 | 53424 | } |
| 52557 | 53425 | |
| 53426 | + pPager->aStat[PAGER_STAT_SPILL]++; |
| 52558 | 53427 | pPg->pDirty = 0; |
| 52559 | 53428 | if( pagerUseWal(pPager) ){ |
| 52560 | 53429 | /* Write a single frame for this page to the log. */ |
| 52561 | 53430 | rc = subjournalPageIfRequired(pPg); |
| 52562 | 53431 | if( rc==SQLITE_OK ){ |
| | @@ -52658,10 +53527,15 @@ |
| 52658 | 53527 | u8 *pPtr; |
| 52659 | 53528 | Pager *pPager = 0; /* Pager object to allocate and return */ |
| 52660 | 53529 | int rc = SQLITE_OK; /* Return code */ |
| 52661 | 53530 | int tempFile = 0; /* True for temp files (incl. in-memory files) */ |
| 52662 | 53531 | int memDb = 0; /* True if this is an in-memory file */ |
| 53532 | +#ifdef SQLITE_ENABLE_DESERIALIZE |
| 53533 | + int memJM = 0; /* Memory journal mode */ |
| 53534 | +#else |
| 53535 | +# define memJM 0 |
| 53536 | +#endif |
| 52663 | 53537 | int readOnly = 0; /* True if this is a read-only file */ |
| 52664 | 53538 | int journalFileSize; /* Bytes to allocate for each journal fd */ |
| 52665 | 53539 | char *zPathname = 0; /* Full path to database file */ |
| 52666 | 53540 | int nPathname = 0; /* Number of bytes in zPathname */ |
| 52667 | 53541 | int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */ |
| | @@ -52785,11 +53659,14 @@ |
| 52785 | 53659 | */ |
| 52786 | 53660 | if( zFilename && zFilename[0] ){ |
| 52787 | 53661 | int fout = 0; /* VFS flags returned by xOpen() */ |
| 52788 | 53662 | rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout); |
| 52789 | 53663 | assert( !memDb ); |
| 52790 | | - readOnly = (fout&SQLITE_OPEN_READONLY); |
| 53664 | +#ifdef SQLITE_ENABLE_DESERIALIZE |
| 53665 | + memJM = (fout&SQLITE_OPEN_MEMORY)!=0; |
| 53666 | +#endif |
| 53667 | + readOnly = (fout&SQLITE_OPEN_READONLY)!=0; |
| 52791 | 53668 | |
| 52792 | 53669 | /* If the file was successfully opened for read/write access, |
| 52793 | 53670 | ** choose a default page size in case we have to create the |
| 52794 | 53671 | ** database file. The default page size is the maximum of: |
| 52795 | 53672 | ** |
| | @@ -52916,11 +53793,11 @@ |
| 52916 | 53793 | pPager->journalSizeLimit = SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT; |
| 52917 | 53794 | assert( isOpen(pPager->fd) || tempFile ); |
| 52918 | 53795 | setSectorSize(pPager); |
| 52919 | 53796 | if( !useJournal ){ |
| 52920 | 53797 | pPager->journalMode = PAGER_JOURNALMODE_OFF; |
| 52921 | | - }else if( memDb ){ |
| 53798 | + }else if( memDb || memJM ){ |
| 52922 | 53799 | pPager->journalMode = PAGER_JOURNALMODE_MEMORY; |
| 52923 | 53800 | } |
| 52924 | 53801 | /* pPager->xBusyHandler = 0; */ |
| 52925 | 53802 | /* pPager->pBusyHandlerArg = 0; */ |
| 52926 | 53803 | pPager->xReiniter = xReinit; |
| | @@ -52931,34 +53808,10 @@ |
| 52931 | 53808 | *ppPager = pPager; |
| 52932 | 53809 | return SQLITE_OK; |
| 52933 | 53810 | } |
| 52934 | 53811 | |
| 52935 | 53812 | |
| 52936 | | -/* Verify that the database file has not be deleted or renamed out from |
| 52937 | | -** under the pager. Return SQLITE_OK if the database is still were it ought |
| 52938 | | -** to be on disk. Return non-zero (SQLITE_READONLY_DBMOVED or some other error |
| 52939 | | -** code from sqlite3OsAccess()) if the database has gone missing. |
| 52940 | | -*/ |
| 52941 | | -static int databaseIsUnmoved(Pager *pPager){ |
| 52942 | | - int bHasMoved = 0; |
| 52943 | | - int rc; |
| 52944 | | - |
| 52945 | | - if( pPager->tempFile ) return SQLITE_OK; |
| 52946 | | - if( pPager->dbSize==0 ) return SQLITE_OK; |
| 52947 | | - assert( pPager->zFilename && pPager->zFilename[0] ); |
| 52948 | | - rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved); |
| 52949 | | - if( rc==SQLITE_NOTFOUND ){ |
| 52950 | | - /* If the HAS_MOVED file-control is unimplemented, assume that the file |
| 52951 | | - ** has not been moved. That is the historical behavior of SQLite: prior to |
| 52952 | | - ** version 3.8.3, it never checked */ |
| 52953 | | - rc = SQLITE_OK; |
| 52954 | | - }else if( rc==SQLITE_OK && bHasMoved ){ |
| 52955 | | - rc = SQLITE_READONLY_DBMOVED; |
| 52956 | | - } |
| 52957 | | - return rc; |
| 52958 | | -} |
| 52959 | | - |
| 52960 | 53813 | |
| 52961 | 53814 | /* |
| 52962 | 53815 | ** This function is called after transitioning from PAGER_UNLOCK to |
| 52963 | 53816 | ** PAGER_SHARED state. It tests if there is a hot journal present in |
| 52964 | 53817 | ** the file-system for the given pager. A hot journal is one that |
| | @@ -54463,12 +55316,13 @@ |
| 54463 | 55316 | } |
| 54464 | 55317 | rc = pager_write_pagelist(pPager,sqlite3PcacheDirtyList(pPager->pPCache)); |
| 54465 | 55318 | if( bBatch ){ |
| 54466 | 55319 | if( rc==SQLITE_OK ){ |
| 54467 | 55320 | rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, 0); |
| 54468 | | - }else{ |
| 54469 | | - sqlite3OsFileControl(fd, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 0); |
| 55321 | + } |
| 55322 | + if( rc!=SQLITE_OK ){ |
| 55323 | + sqlite3OsFileControlHint(fd, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 0); |
| 54470 | 55324 | } |
| 54471 | 55325 | } |
| 54472 | 55326 | |
| 54473 | 55327 | if( rc!=SQLITE_OK ){ |
| 54474 | 55328 | assert( rc!=SQLITE_IOERR_BLOCKED ); |
| | @@ -54688,30 +55542,37 @@ |
| 54688 | 55542 | return a; |
| 54689 | 55543 | } |
| 54690 | 55544 | #endif |
| 54691 | 55545 | |
| 54692 | 55546 | /* |
| 54693 | | -** Parameter eStat must be either SQLITE_DBSTATUS_CACHE_HIT or |
| 54694 | | -** SQLITE_DBSTATUS_CACHE_MISS. Before returning, *pnVal is incremented by the |
| 55547 | +** Parameter eStat must be one of SQLITE_DBSTATUS_CACHE_HIT, _MISS, _WRITE, |
| 55548 | +** or _WRITE+1. The SQLITE_DBSTATUS_CACHE_WRITE+1 case is a translation |
| 55549 | +** of SQLITE_DBSTATUS_CACHE_SPILL. The _SPILL case is not contiguous because |
| 55550 | +** it was added later. |
| 55551 | +** |
| 55552 | +** Before returning, *pnVal is incremented by the |
| 54695 | 55553 | ** current cache hit or miss count, according to the value of eStat. If the |
| 54696 | 55554 | ** reset parameter is non-zero, the cache hit or miss count is zeroed before |
| 54697 | 55555 | ** returning. |
| 54698 | 55556 | */ |
| 54699 | 55557 | SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *pPager, int eStat, int reset, int *pnVal){ |
| 54700 | 55558 | |
| 54701 | 55559 | assert( eStat==SQLITE_DBSTATUS_CACHE_HIT |
| 54702 | 55560 | || eStat==SQLITE_DBSTATUS_CACHE_MISS |
| 54703 | 55561 | || eStat==SQLITE_DBSTATUS_CACHE_WRITE |
| 55562 | + || eStat==SQLITE_DBSTATUS_CACHE_WRITE+1 |
| 54704 | 55563 | ); |
| 54705 | 55564 | |
| 54706 | 55565 | assert( SQLITE_DBSTATUS_CACHE_HIT+1==SQLITE_DBSTATUS_CACHE_MISS ); |
| 54707 | 55566 | assert( SQLITE_DBSTATUS_CACHE_HIT+2==SQLITE_DBSTATUS_CACHE_WRITE ); |
| 54708 | | - assert( PAGER_STAT_HIT==0 && PAGER_STAT_MISS==1 && PAGER_STAT_WRITE==2 ); |
| 55567 | + assert( PAGER_STAT_HIT==0 && PAGER_STAT_MISS==1 |
| 55568 | + && PAGER_STAT_WRITE==2 && PAGER_STAT_SPILL==3 ); |
| 54709 | 55569 | |
| 54710 | | - *pnVal += pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT]; |
| 55570 | + eStat -= SQLITE_DBSTATUS_CACHE_HIT; |
| 55571 | + *pnVal += pPager->aStat[eStat]; |
| 54711 | 55572 | if( reset ){ |
| 54712 | | - pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT] = 0; |
| 55573 | + pPager->aStat[eStat] = 0; |
| 54713 | 55574 | } |
| 54714 | 55575 | } |
| 54715 | 55576 | |
| 54716 | 55577 | /* |
| 54717 | 55578 | ** Return true if this is an in-memory or temp-file backed pager. |
| | @@ -56153,11 +57014,15 @@ |
| 56153 | 57014 | ** |
| 56154 | 57015 | ** If this call is successful, *ppPage is set to point to the wal-index |
| 56155 | 57016 | ** page and SQLITE_OK is returned. If an error (an OOM or VFS error) occurs, |
| 56156 | 57017 | ** then an SQLite error code is returned and *ppPage is set to 0. |
| 56157 | 57018 | */ |
| 56158 | | -static int walIndexPage(Wal *pWal, int iPage, volatile u32 **ppPage){ |
| 57019 | +static SQLITE_NOINLINE int walIndexPageRealloc( |
| 57020 | + Wal *pWal, /* The WAL context */ |
| 57021 | + int iPage, /* The page we seek */ |
| 57022 | + volatile u32 **ppPage /* Write the page pointer here */ |
| 57023 | +){ |
| 56159 | 57024 | int rc = SQLITE_OK; |
| 56160 | 57025 | |
| 56161 | 57026 | /* Enlarge the pWal->apWiData[] array if required */ |
| 56162 | 57027 | if( pWal->nWiData<=iPage ){ |
| 56163 | 57028 | int nByte = sizeof(u32*)*(iPage+1); |
| | @@ -56172,32 +57037,41 @@ |
| 56172 | 57037 | pWal->apWiData = apNew; |
| 56173 | 57038 | pWal->nWiData = iPage+1; |
| 56174 | 57039 | } |
| 56175 | 57040 | |
| 56176 | 57041 | /* Request a pointer to the required page from the VFS */ |
| 56177 | | - if( pWal->apWiData[iPage]==0 ){ |
| 56178 | | - if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ){ |
| 56179 | | - pWal->apWiData[iPage] = (u32 volatile *)sqlite3MallocZero(WALINDEX_PGSZ); |
| 56180 | | - if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT; |
| 56181 | | - }else{ |
| 56182 | | - rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ, |
| 56183 | | - pWal->writeLock, (void volatile **)&pWal->apWiData[iPage] |
| 56184 | | - ); |
| 56185 | | - assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 ); |
| 56186 | | - testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK ); |
| 56187 | | - if( (rc&0xff)==SQLITE_READONLY ){ |
| 56188 | | - pWal->readOnly |= WAL_SHM_RDONLY; |
| 56189 | | - if( rc==SQLITE_READONLY ){ |
| 56190 | | - rc = SQLITE_OK; |
| 56191 | | - } |
| 57042 | + assert( pWal->apWiData[iPage]==0 ); |
| 57043 | + if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ){ |
| 57044 | + pWal->apWiData[iPage] = (u32 volatile *)sqlite3MallocZero(WALINDEX_PGSZ); |
| 57045 | + if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT; |
| 57046 | + }else{ |
| 57047 | + rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ, |
| 57048 | + pWal->writeLock, (void volatile **)&pWal->apWiData[iPage] |
| 57049 | + ); |
| 57050 | + assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 ); |
| 57051 | + testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK ); |
| 57052 | + if( (rc&0xff)==SQLITE_READONLY ){ |
| 57053 | + pWal->readOnly |= WAL_SHM_RDONLY; |
| 57054 | + if( rc==SQLITE_READONLY ){ |
| 57055 | + rc = SQLITE_OK; |
| 56192 | 57056 | } |
| 56193 | 57057 | } |
| 56194 | 57058 | } |
| 56195 | 57059 | |
| 56196 | 57060 | *ppPage = pWal->apWiData[iPage]; |
| 56197 | 57061 | assert( iPage==0 || *ppPage || rc!=SQLITE_OK ); |
| 56198 | 57062 | return rc; |
| 57063 | +} |
| 57064 | +static int walIndexPage( |
| 57065 | + Wal *pWal, /* The WAL context */ |
| 57066 | + int iPage, /* The page we seek */ |
| 57067 | + volatile u32 **ppPage /* Write the page pointer here */ |
| 57068 | +){ |
| 57069 | + if( pWal->nWiData<=iPage || (*ppPage = pWal->apWiData[iPage])==0 ){ |
| 57070 | + return walIndexPageRealloc(pWal, iPage, ppPage); |
| 57071 | + } |
| 57072 | + return SQLITE_OK; |
| 56199 | 57073 | } |
| 56200 | 57074 | |
| 56201 | 57075 | /* |
| 56202 | 57076 | ** Return a pointer to the WalCkptInfo structure in the wal-index. |
| 56203 | 57077 | */ |
| | @@ -57171,21 +58045,22 @@ |
| 57171 | 58045 | sqlite3_free(p); |
| 57172 | 58046 | } |
| 57173 | 58047 | |
| 57174 | 58048 | /* |
| 57175 | 58049 | ** Construct a WalInterator object that can be used to loop over all |
| 57176 | | -** pages in the WAL in ascending order. The caller must hold the checkpoint |
| 57177 | | -** lock. |
| 58050 | +** pages in the WAL following frame nBackfill in ascending order. Frames |
| 58051 | +** nBackfill or earlier may be included - excluding them is an optimization |
| 58052 | +** only. The caller must hold the checkpoint lock. |
| 57178 | 58053 | ** |
| 57179 | 58054 | ** On success, make *pp point to the newly allocated WalInterator object |
| 57180 | 58055 | ** return SQLITE_OK. Otherwise, return an error code. If this routine |
| 57181 | 58056 | ** returns an error, the value of *pp is undefined. |
| 57182 | 58057 | ** |
| 57183 | 58058 | ** The calling routine should invoke walIteratorFree() to destroy the |
| 57184 | 58059 | ** WalIterator object when it has finished with it. |
| 57185 | 58060 | */ |
| 57186 | | -static int walIteratorInit(Wal *pWal, WalIterator **pp){ |
| 58061 | +static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){ |
| 57187 | 58062 | WalIterator *p; /* Return value */ |
| 57188 | 58063 | int nSegment; /* Number of segments to merge */ |
| 57189 | 58064 | u32 iLast; /* Last frame in log */ |
| 57190 | 58065 | int nByte; /* Number of bytes to allocate */ |
| 57191 | 58066 | int i; /* Iterator variable */ |
| | @@ -57218,11 +58093,11 @@ |
| 57218 | 58093 | ); |
| 57219 | 58094 | if( !aTmp ){ |
| 57220 | 58095 | rc = SQLITE_NOMEM_BKPT; |
| 57221 | 58096 | } |
| 57222 | 58097 | |
| 57223 | | - for(i=0; rc==SQLITE_OK && i<nSegment; i++){ |
| 58098 | + for(i=walFramePage(nBackfill+1); rc==SQLITE_OK && i<nSegment; i++){ |
| 57224 | 58099 | volatile ht_slot *aHash; |
| 57225 | 58100 | u32 iZero; |
| 57226 | 58101 | volatile u32 *aPgno; |
| 57227 | 58102 | |
| 57228 | 58103 | rc = walHashGet(pWal, i, &aHash, &aPgno, &iZero); |
| | @@ -57252,10 +58127,11 @@ |
| 57252 | 58127 | } |
| 57253 | 58128 | sqlite3_free(aTmp); |
| 57254 | 58129 | |
| 57255 | 58130 | if( rc!=SQLITE_OK ){ |
| 57256 | 58131 | walIteratorFree(p); |
| 58132 | + p = 0; |
| 57257 | 58133 | } |
| 57258 | 58134 | *pp = p; |
| 57259 | 58135 | return rc; |
| 57260 | 58136 | } |
| 57261 | 58137 | |
| | @@ -57374,17 +58250,10 @@ |
| 57374 | 58250 | testcase( szPage<=32768 ); |
| 57375 | 58251 | testcase( szPage>=65536 ); |
| 57376 | 58252 | pInfo = walCkptInfo(pWal); |
| 57377 | 58253 | if( pInfo->nBackfill<pWal->hdr.mxFrame ){ |
| 57378 | 58254 | |
| 57379 | | - /* Allocate the iterator */ |
| 57380 | | - rc = walIteratorInit(pWal, &pIter); |
| 57381 | | - if( rc!=SQLITE_OK ){ |
| 57382 | | - return rc; |
| 57383 | | - } |
| 57384 | | - assert( pIter ); |
| 57385 | | - |
| 57386 | 58255 | /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked |
| 57387 | 58256 | ** in the SQLITE_CHECKPOINT_PASSIVE mode. */ |
| 57388 | 58257 | assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); |
| 57389 | 58258 | |
| 57390 | 58259 | /* Compute in mxSafeFrame the index of the last frame of the WAL that is |
| | @@ -57417,11 +58286,17 @@ |
| 57417 | 58286 | goto walcheckpoint_out; |
| 57418 | 58287 | } |
| 57419 | 58288 | } |
| 57420 | 58289 | } |
| 57421 | 58290 | |
| 57422 | | - if( pInfo->nBackfill<mxSafeFrame |
| 58291 | + /* Allocate the iterator */ |
| 58292 | + if( pInfo->nBackfill<mxSafeFrame ){ |
| 58293 | + rc = walIteratorInit(pWal, pInfo->nBackfill, &pIter); |
| 58294 | + assert( rc==SQLITE_OK || pIter==0 ); |
| 58295 | + } |
| 58296 | + |
| 58297 | + if( pIter |
| 57423 | 58298 | && (rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(0),1))==SQLITE_OK |
| 57424 | 58299 | ){ |
| 57425 | 58300 | i64 nSize; /* Current size of database file */ |
| 57426 | 58301 | u32 nBackfill = pInfo->nBackfill; |
| 57427 | 58302 | |
| | @@ -58467,11 +59342,11 @@ |
| 58467 | 59342 | ** (iFrame<=iLast): |
| 58468 | 59343 | ** This condition filters out entries that were added to the hash |
| 58469 | 59344 | ** table after the current read-transaction had started. |
| 58470 | 59345 | */ |
| 58471 | 59346 | iMinHash = walFramePage(pWal->minFrame); |
| 58472 | | - for(iHash=walFramePage(iLast); iHash>=iMinHash && iRead==0; iHash--){ |
| 59347 | + for(iHash=walFramePage(iLast); iHash>=iMinHash; iHash--){ |
| 58473 | 59348 | volatile ht_slot *aHash; /* Pointer to hash table */ |
| 58474 | 59349 | volatile u32 *aPgno; /* Pointer to array of page numbers */ |
| 58475 | 59350 | u32 iZero; /* Frame number corresponding to aPgno[0] */ |
| 58476 | 59351 | int iKey; /* Hash slot index */ |
| 58477 | 59352 | int nCollide; /* Number of hash collisions remaining */ |
| | @@ -58490,10 +59365,11 @@ |
| 58490 | 59365 | } |
| 58491 | 59366 | if( (nCollide--)==0 ){ |
| 58492 | 59367 | return SQLITE_CORRUPT_BKPT; |
| 58493 | 59368 | } |
| 58494 | 59369 | } |
| 59370 | + if( iRead ) break; |
| 58495 | 59371 | } |
| 58496 | 59372 | |
| 58497 | 59373 | #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT |
| 58498 | 59374 | /* If expensive assert() statements are available, do a linear search |
| 58499 | 59375 | ** of the wal-index file content. Make sure the results agree with the |
| | @@ -59904,24 +60780,24 @@ |
| 59904 | 60780 | struct BtCursor { |
| 59905 | 60781 | u8 eState; /* One of the CURSOR_XXX constants (see below) */ |
| 59906 | 60782 | u8 curFlags; /* zero or more BTCF_* flags defined below */ |
| 59907 | 60783 | u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */ |
| 59908 | 60784 | u8 hints; /* As configured by CursorSetHints() */ |
| 59909 | | - int nOvflAlloc; /* Allocated size of aOverflow[] array */ |
| 59910 | | - Btree *pBtree; /* The Btree to which this cursor belongs */ |
| 59911 | | - BtShared *pBt; /* The BtShared this cursor points to */ |
| 59912 | | - BtCursor *pNext; /* Forms a linked list of all cursors */ |
| 59913 | | - Pgno *aOverflow; /* Cache of overflow page locations */ |
| 59914 | | - CellInfo info; /* A parse of the cell we are pointing at */ |
| 59915 | | - i64 nKey; /* Size of pKey, or last integer key */ |
| 59916 | | - void *pKey; /* Saved key that was cursor last known position */ |
| 59917 | | - Pgno pgnoRoot; /* The root page of this tree */ |
| 59918 | 60785 | int skipNext; /* Prev() is noop if negative. Next() is noop if positive. |
| 59919 | 60786 | ** Error code if eState==CURSOR_FAULT */ |
| 60787 | + Btree *pBtree; /* The Btree to which this cursor belongs */ |
| 60788 | + Pgno *aOverflow; /* Cache of overflow page locations */ |
| 60789 | + void *pKey; /* Saved key that was cursor last known position */ |
| 59920 | 60790 | /* All fields above are zeroed when the cursor is allocated. See |
| 59921 | 60791 | ** sqlite3BtreeCursorZero(). Fields that follow must be manually |
| 59922 | 60792 | ** initialized. */ |
| 60793 | +#define BTCURSOR_FIRST_UNINIT pBt /* Name of first uninitialized field */ |
| 60794 | + BtShared *pBt; /* The BtShared this cursor points to */ |
| 60795 | + BtCursor *pNext; /* Forms a linked list of all cursors */ |
| 60796 | + CellInfo info; /* A parse of the cell we are pointing at */ |
| 60797 | + i64 nKey; /* Size of pKey, or last integer key */ |
| 60798 | + Pgno pgnoRoot; /* The root page of this tree */ |
| 59923 | 60799 | i8 iPage; /* Index of current page in apPage */ |
| 59924 | 60800 | u8 curIntKey; /* Value of apPage[0]->intKey */ |
| 59925 | 60801 | u16 ix; /* Current index for apPage[iPage] */ |
| 59926 | 60802 | u16 aiIdx[BTCURSOR_MAX_DEPTH-1]; /* Current index in apPage[i] */ |
| 59927 | 60803 | struct KeyInfo *pKeyInfo; /* Arg passed to comparison function */ |
| | @@ -59967,12 +60843,12 @@ |
| 59967 | 60843 | ** on a different connection that shares the BtShared cache with this |
| 59968 | 60844 | ** cursor. The error has left the cache in an inconsistent state. |
| 59969 | 60845 | ** Do nothing else with this cursor. Any attempt to use the cursor |
| 59970 | 60846 | ** should return the error code stored in BtCursor.skipNext |
| 59971 | 60847 | */ |
| 59972 | | -#define CURSOR_INVALID 0 |
| 59973 | | -#define CURSOR_VALID 1 |
| 60848 | +#define CURSOR_VALID 0 |
| 60849 | +#define CURSOR_INVALID 1 |
| 59974 | 60850 | #define CURSOR_SKIPNEXT 2 |
| 59975 | 60851 | #define CURSOR_REQUIRESEEK 3 |
| 59976 | 60852 | #define CURSOR_FAULT 4 |
| 59977 | 60853 | |
| 59978 | 60854 | /* |
| | @@ -64746,11 +65622,11 @@ |
| 64746 | 65622 | ** to zero. But it turns out that the apPage[] and aiIdx[] arrays |
| 64747 | 65623 | ** do not need to be zeroed and they are large, so we can save a lot |
| 64748 | 65624 | ** of run-time by skipping the initialization of those elements. |
| 64749 | 65625 | */ |
| 64750 | 65626 | SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor *p){ |
| 64751 | | - memset(p, 0, offsetof(BtCursor, iPage)); |
| 65627 | + memset(p, 0, offsetof(BtCursor, BTCURSOR_FIRST_UNINIT)); |
| 64752 | 65628 | } |
| 64753 | 65629 | |
| 64754 | 65630 | /* |
| 64755 | 65631 | ** Close a cursor. The read lock on the database file is released |
| 64756 | 65632 | ** when the last cursor is closed. |
| | @@ -64789,15 +65665,23 @@ |
| 64789 | 65665 | ** |
| 64790 | 65666 | ** BtCursor.info is a cache of the information in the current cell. |
| 64791 | 65667 | ** Using this cache reduces the number of calls to btreeParseCell(). |
| 64792 | 65668 | */ |
| 64793 | 65669 | #ifndef NDEBUG |
| 65670 | + static int cellInfoEqual(CellInfo *a, CellInfo *b){ |
| 65671 | + if( a->nKey!=b->nKey ) return 0; |
| 65672 | + if( a->pPayload!=b->pPayload ) return 0; |
| 65673 | + if( a->nPayload!=b->nPayload ) return 0; |
| 65674 | + if( a->nLocal!=b->nLocal ) return 0; |
| 65675 | + if( a->nSize!=b->nSize ) return 0; |
| 65676 | + return 1; |
| 65677 | + } |
| 64794 | 65678 | static void assertCellInfo(BtCursor *pCur){ |
| 64795 | 65679 | CellInfo info; |
| 64796 | 65680 | memset(&info, 0, sizeof(info)); |
| 64797 | 65681 | btreeParseCell(pCur->pPage, pCur->ix, &info); |
| 64798 | | - assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 ); |
| 65682 | + assert( CORRUPT_DB || cellInfoEqual(&info, &pCur->info) ); |
| 64799 | 65683 | } |
| 64800 | 65684 | #else |
| 64801 | 65685 | #define assertCellInfo(x) |
| 64802 | 65686 | #endif |
| 64803 | 65687 | static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){ |
| | @@ -65069,18 +65953,19 @@ |
| 65069 | 65953 | ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array |
| 65070 | 65954 | ** means "not yet known" (the cache is lazily populated). |
| 65071 | 65955 | */ |
| 65072 | 65956 | if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){ |
| 65073 | 65957 | int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize; |
| 65074 | | - if( nOvfl>pCur->nOvflAlloc ){ |
| 65958 | + if( pCur->aOverflow==0 |
| 65959 | + || nOvfl*(int)sizeof(Pgno) > sqlite3MallocSize(pCur->aOverflow) |
| 65960 | + ){ |
| 65075 | 65961 | Pgno *aNew = (Pgno*)sqlite3Realloc( |
| 65076 | 65962 | pCur->aOverflow, nOvfl*2*sizeof(Pgno) |
| 65077 | 65963 | ); |
| 65078 | 65964 | if( aNew==0 ){ |
| 65079 | 65965 | return SQLITE_NOMEM_BKPT; |
| 65080 | 65966 | }else{ |
| 65081 | | - pCur->nOvflAlloc = nOvfl*2; |
| 65082 | 65967 | pCur->aOverflow = aNew; |
| 65083 | 65968 | } |
| 65084 | 65969 | } |
| 65085 | 65970 | memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno)); |
| 65086 | 65971 | pCur->curFlags |= BTCF_ValidOvfl; |
| | @@ -66590,13 +67475,12 @@ |
| 66590 | 67475 | *pRC = freePage2(pPage->pBt, pPage, pPage->pgno); |
| 66591 | 67476 | } |
| 66592 | 67477 | } |
| 66593 | 67478 | |
| 66594 | 67479 | /* |
| 66595 | | -** Free any overflow pages associated with the given Cell. Write the |
| 66596 | | -** local Cell size (the number of bytes on the original page, omitting |
| 66597 | | -** overflow) into *pnSize. |
| 67480 | +** Free any overflow pages associated with the given Cell. Store |
| 67481 | +** size information about the cell in pInfo. |
| 66598 | 67482 | */ |
| 66599 | 67483 | static int clearCell( |
| 66600 | 67484 | MemPage *pPage, /* The page that contains the Cell */ |
| 66601 | 67485 | unsigned char *pCell, /* First byte of the Cell */ |
| 66602 | 67486 | CellInfo *pInfo /* Size information about the cell */ |
| | @@ -67796,11 +68680,11 @@ |
| 67796 | 68680 | rc = SQLITE_CORRUPT_BKPT; |
| 67797 | 68681 | goto balance_cleanup; |
| 67798 | 68682 | } |
| 67799 | 68683 | |
| 67800 | 68684 | /* Load b.apCell[] with pointers to all cells in pOld. If pOld |
| 67801 | | - ** constains overflow cells, include them in the b.apCell[] array |
| 68685 | + ** contains overflow cells, include them in the b.apCell[] array |
| 67802 | 68686 | ** in the correct spot. |
| 67803 | 68687 | ** |
| 67804 | 68688 | ** Note that when there are multiple overflow cells, it is always the |
| 67805 | 68689 | ** case that they are sequential and adjacent. This invariant arises |
| 67806 | 68690 | ** because multiple overflows can only occurs when inserting divider |
| | @@ -71281,10 +72165,55 @@ |
| 71281 | 72165 | } |
| 71282 | 72166 | return 1; |
| 71283 | 72167 | } |
| 71284 | 72168 | #endif |
| 71285 | 72169 | |
| 72170 | +#ifdef SQLITE_DEBUG |
| 72171 | +/* |
| 72172 | +** Check that string value of pMem agrees with its integer or real value. |
| 72173 | +** |
| 72174 | +** A single int or real value always converts to the same strings. But |
| 72175 | +** many different strings can be converted into the same int or real. |
| 72176 | +** If a table contains a numeric value and an index is based on the |
| 72177 | +** corresponding string value, then it is important that the string be |
| 72178 | +** derived from the numeric value, not the other way around, to ensure |
| 72179 | +** that the index and table are consistent. See ticket |
| 72180 | +** https://www.sqlite.org/src/info/343634942dd54ab (2018-01-31) for |
| 72181 | +** an example. |
| 72182 | +** |
| 72183 | +** This routine looks at pMem to verify that if it has both a numeric |
| 72184 | +** representation and a string representation then the string rep has |
| 72185 | +** been derived from the numeric and not the other way around. It returns |
| 72186 | +** true if everything is ok and false if there is a problem. |
| 72187 | +** |
| 72188 | +** This routine is for use inside of assert() statements only. |
| 72189 | +*/ |
| 72190 | +SQLITE_PRIVATE int sqlite3VdbeMemConsistentDualRep(Mem *p){ |
| 72191 | + char zBuf[100]; |
| 72192 | + char *z; |
| 72193 | + int i, j, incr; |
| 72194 | + if( (p->flags & MEM_Str)==0 ) return 1; |
| 72195 | + if( (p->flags & (MEM_Int|MEM_Real))==0 ) return 1; |
| 72196 | + if( p->flags & MEM_Int ){ |
| 72197 | + sqlite3_snprintf(sizeof(zBuf),zBuf,"%lld",p->u.i); |
| 72198 | + }else{ |
| 72199 | + sqlite3_snprintf(sizeof(zBuf),zBuf,"%!.15g",p->u.r); |
| 72200 | + } |
| 72201 | + z = p->z; |
| 72202 | + i = j = 0; |
| 72203 | + incr = 1; |
| 72204 | + if( p->enc!=SQLITE_UTF8 ){ |
| 72205 | + incr = 2; |
| 72206 | + if( p->enc==SQLITE_UTF16BE ) z++; |
| 72207 | + } |
| 72208 | + while( zBuf[j] ){ |
| 72209 | + if( zBuf[j++]!=z[i] ) return 0; |
| 72210 | + i += incr; |
| 72211 | + } |
| 72212 | + return 1; |
| 72213 | +} |
| 72214 | +#endif /* SQLITE_DEBUG */ |
| 71286 | 72215 | |
| 71287 | 72216 | /* |
| 71288 | 72217 | ** If pMem is an object with a valid string representation, this routine |
| 71289 | 72218 | ** ensures the internal encoding for the string representation is |
| 71290 | 72219 | ** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE. |
| | @@ -71714,10 +72643,20 @@ |
| 71714 | 72643 | }else{ |
| 71715 | 72644 | /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ |
| 71716 | 72645 | return (double)0; |
| 71717 | 72646 | } |
| 71718 | 72647 | } |
| 72648 | + |
| 72649 | +/* |
| 72650 | +** Return 1 if pMem represents true, and return 0 if pMem represents false. |
| 72651 | +** Return the value ifNull if pMem is NULL. |
| 72652 | +*/ |
| 72653 | +SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem *pMem, int ifNull){ |
| 72654 | + if( pMem->flags & MEM_Int ) return pMem->u.i!=0; |
| 72655 | + if( pMem->flags & MEM_Null ) return ifNull; |
| 72656 | + return sqlite3VdbeRealValue(pMem)!=0.0; |
| 72657 | +} |
| 71719 | 72658 | |
| 71720 | 72659 | /* |
| 71721 | 72660 | ** The MEM structure is already a MEM_Real. Try to also make it a |
| 71722 | 72661 | ** MEM_Int if we can. |
| 71723 | 72662 | */ |
| | @@ -71769,10 +72708,22 @@ |
| 71769 | 72708 | |
| 71770 | 72709 | pMem->u.r = sqlite3VdbeRealValue(pMem); |
| 71771 | 72710 | MemSetTypeFlag(pMem, MEM_Real); |
| 71772 | 72711 | return SQLITE_OK; |
| 71773 | 72712 | } |
| 72713 | + |
| 72714 | +/* Compare a floating point value to an integer. Return true if the two |
| 72715 | +** values are the same within the precision of the floating point value. |
| 72716 | +** |
| 72717 | +** For some versions of GCC on 32-bit machines, if you do the more obvious |
| 72718 | +** comparison of "r1==(double)i" you sometimes get an answer of false even |
| 72719 | +** though the r1 and (double)i values are bit-for-bit the same. |
| 72720 | +*/ |
| 72721 | +static int sqlite3RealSameAsInt(double r1, sqlite3_int64 i){ |
| 72722 | + double r2 = (double)i; |
| 72723 | + return memcmp(&r1, &r2, sizeof(r1))==0; |
| 72724 | +} |
| 71774 | 72725 | |
| 71775 | 72726 | /* |
| 71776 | 72727 | ** Convert pMem so that it has types MEM_Real or MEM_Int or both. |
| 71777 | 72728 | ** Invalidate any prior representations. |
| 71778 | 72729 | ** |
| | @@ -71789,11 +72740,11 @@ |
| 71789 | 72740 | if( rc==0 ){ |
| 71790 | 72741 | MemSetTypeFlag(pMem, MEM_Int); |
| 71791 | 72742 | }else{ |
| 71792 | 72743 | i64 i = pMem->u.i; |
| 71793 | 72744 | sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc); |
| 71794 | | - if( rc==1 && pMem->u.r==(double)i ){ |
| 72745 | + if( rc==1 && sqlite3RealSameAsInt(pMem->u.r, i) ){ |
| 71795 | 72746 | pMem->u.i = i; |
| 71796 | 72747 | MemSetTypeFlag(pMem, MEM_Int); |
| 71797 | 72748 | }else{ |
| 71798 | 72749 | MemSetTypeFlag(pMem, MEM_Real); |
| 71799 | 72750 | } |
| | @@ -72272,10 +73223,11 @@ |
| 72272 | 73223 | assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) ); |
| 72273 | 73224 | } |
| 72274 | 73225 | assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0 |
| 72275 | 73226 | || pVal->db->mallocFailed ); |
| 72276 | 73227 | if( pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) ){ |
| 73228 | + assert( sqlite3VdbeMemConsistentDualRep(pVal) ); |
| 72277 | 73229 | return pVal->z; |
| 72278 | 73230 | }else{ |
| 72279 | 73231 | return 0; |
| 72280 | 73232 | } |
| 72281 | 73233 | } |
| | @@ -72294,10 +73246,11 @@ |
| 72294 | 73246 | if( !pVal ) return 0; |
| 72295 | 73247 | assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) ); |
| 72296 | 73248 | assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) ); |
| 72297 | 73249 | assert( (pVal->flags & MEM_RowSet)==0 ); |
| 72298 | 73250 | if( (pVal->flags&(MEM_Str|MEM_Term))==(MEM_Str|MEM_Term) && pVal->enc==enc ){ |
| 73251 | + assert( sqlite3VdbeMemConsistentDualRep(pVal) ); |
| 72299 | 73252 | return pVal->z; |
| 72300 | 73253 | } |
| 72301 | 73254 | if( pVal->flags&MEM_Null ){ |
| 72302 | 73255 | return 0; |
| 72303 | 73256 | } |
| | @@ -78075,18 +79028,16 @@ |
| 78075 | 79028 | sqlite3VdbeMemSetDouble(pCtx->pOut, rVal); |
| 78076 | 79029 | } |
| 78077 | 79030 | SQLITE_API void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){ |
| 78078 | 79031 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 78079 | 79032 | pCtx->isError = SQLITE_ERROR; |
| 78080 | | - pCtx->fErrorOrAux = 1; |
| 78081 | 79033 | sqlite3VdbeMemSetStr(pCtx->pOut, z, n, SQLITE_UTF8, SQLITE_TRANSIENT); |
| 78082 | 79034 | } |
| 78083 | 79035 | #ifndef SQLITE_OMIT_UTF16 |
| 78084 | 79036 | SQLITE_API void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){ |
| 78085 | 79037 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 78086 | 79038 | pCtx->isError = SQLITE_ERROR; |
| 78087 | | - pCtx->fErrorOrAux = 1; |
| 78088 | 79039 | sqlite3VdbeMemSetStr(pCtx->pOut, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT); |
| 78089 | 79040 | } |
| 78090 | 79041 | #endif |
| 78091 | 79042 | SQLITE_API void sqlite3_result_int(sqlite3_context *pCtx, int iVal){ |
| 78092 | 79043 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| | @@ -78188,12 +79139,11 @@ |
| 78188 | 79139 | } |
| 78189 | 79140 | sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n); |
| 78190 | 79141 | return SQLITE_OK; |
| 78191 | 79142 | } |
| 78192 | 79143 | SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ |
| 78193 | | - pCtx->isError = errCode; |
| 78194 | | - pCtx->fErrorOrAux = 1; |
| 79144 | + pCtx->isError = errCode ? errCode : -1; |
| 78195 | 79145 | #ifdef SQLITE_DEBUG |
| 78196 | 79146 | if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode; |
| 78197 | 79147 | #endif |
| 78198 | 79148 | if( pCtx->pOut->flags & MEM_Null ){ |
| 78199 | 79149 | sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1, |
| | @@ -78203,21 +79153,19 @@ |
| 78203 | 79153 | |
| 78204 | 79154 | /* Force an SQLITE_TOOBIG error. */ |
| 78205 | 79155 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){ |
| 78206 | 79156 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 78207 | 79157 | pCtx->isError = SQLITE_TOOBIG; |
| 78208 | | - pCtx->fErrorOrAux = 1; |
| 78209 | 79158 | sqlite3VdbeMemSetStr(pCtx->pOut, "string or blob too big", -1, |
| 78210 | 79159 | SQLITE_UTF8, SQLITE_STATIC); |
| 78211 | 79160 | } |
| 78212 | 79161 | |
| 78213 | 79162 | /* An SQLITE_NOMEM error. */ |
| 78214 | 79163 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context *pCtx){ |
| 78215 | 79164 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 78216 | 79165 | sqlite3VdbeMemSetNull(pCtx->pOut); |
| 78217 | 79166 | pCtx->isError = SQLITE_NOMEM_BKPT; |
| 78218 | | - pCtx->fErrorOrAux = 1; |
| 78219 | 79167 | sqlite3OomFault(pCtx->pOut->db); |
| 78220 | 79168 | } |
| 78221 | 79169 | |
| 78222 | 79170 | /* |
| 78223 | 79171 | ** This function is called after a transaction has been committed. It |
| | @@ -78620,14 +79568,11 @@ |
| 78620 | 79568 | if( !pAuxData ) goto failed; |
| 78621 | 79569 | pAuxData->iAuxOp = pCtx->iOp; |
| 78622 | 79570 | pAuxData->iAuxArg = iArg; |
| 78623 | 79571 | pAuxData->pNextAux = pVdbe->pAuxData; |
| 78624 | 79572 | pVdbe->pAuxData = pAuxData; |
| 78625 | | - if( pCtx->fErrorOrAux==0 ){ |
| 78626 | | - pCtx->isError = 0; |
| 78627 | | - pCtx->fErrorOrAux = 1; |
| 78628 | | - } |
| 79573 | + if( pCtx->isError==0 ) pCtx->isError = -1; |
| 78629 | 79574 | }else if( pAuxData->xDeleteAux ){ |
| 78630 | 79575 | pAuxData->xDeleteAux(pAuxData->pAux); |
| 78631 | 79576 | } |
| 78632 | 79577 | |
| 78633 | 79578 | pAuxData->pAux = pAux; |
| | @@ -79379,11 +80324,13 @@ |
| 79379 | 80324 | */ |
| 79380 | 80325 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ |
| 79381 | 80326 | Vdbe *pVdbe = (Vdbe*)pStmt; |
| 79382 | 80327 | u32 v; |
| 79383 | 80328 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 79384 | | - if( !pStmt ){ |
| 80329 | + if( !pStmt |
| 80330 | + || (op!=SQLITE_STMTSTATUS_MEMUSED && (op<0||op>=ArraySize(pVdbe->aCounter))) |
| 80331 | + ){ |
| 79385 | 80332 | (void)SQLITE_MISUSE_BKPT; |
| 79386 | 80333 | return 0; |
| 79387 | 80334 | } |
| 79388 | 80335 | #endif |
| 79389 | 80336 | if( op==SQLITE_STMTSTATUS_MEMUSED ){ |
| | @@ -80153,10 +81100,15 @@ |
| 80153 | 81100 | }else{ |
| 80154 | 81101 | pRec->u.r = rValue; |
| 80155 | 81102 | pRec->flags |= MEM_Real; |
| 80156 | 81103 | if( bTryForInt ) sqlite3VdbeIntegerAffinity(pRec); |
| 80157 | 81104 | } |
| 81105 | + /* TEXT->NUMERIC is many->one. Hence, it is important to invalidate the |
| 81106 | + ** string representation after computing a numeric equivalent, because the |
| 81107 | + ** string representation might not be the canonical representation for the |
| 81108 | + ** numeric value. Ticket [343634942dd54ab57b7024] 2018-01-31. */ |
| 81109 | + pRec->flags &= ~MEM_Str; |
| 80158 | 81110 | } |
| 80159 | 81111 | |
| 80160 | 81112 | /* |
| 80161 | 81113 | ** Processing is determine by the affinity parameter: |
| 80162 | 81114 | ** |
| | @@ -80621,11 +81573,11 @@ |
| 80621 | 81573 | ** jumps to abort_due_to_error. */ |
| 80622 | 81574 | assert( rc==SQLITE_OK ); |
| 80623 | 81575 | |
| 80624 | 81576 | assert( pOp>=aOp && pOp<&aOp[p->nOp]); |
| 80625 | 81577 | #ifdef VDBE_PROFILE |
| 80626 | | - start = sqlite3Hwtime(); |
| 81578 | + start = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime(); |
| 80627 | 81579 | #endif |
| 80628 | 81580 | nVmStep++; |
| 80629 | 81581 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 80630 | 81582 | if( p->anExec ) p->anExec[(int)(pOp-aOp)]++; |
| 80631 | 81583 | #endif |
| | @@ -82145,22 +83097,12 @@ |
| 82145 | 83097 | case OP_And: /* same as TK_AND, in1, in2, out3 */ |
| 82146 | 83098 | case OP_Or: { /* same as TK_OR, in1, in2, out3 */ |
| 82147 | 83099 | int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 82148 | 83100 | int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 82149 | 83101 | |
| 82150 | | - pIn1 = &aMem[pOp->p1]; |
| 82151 | | - if( pIn1->flags & MEM_Null ){ |
| 82152 | | - v1 = 2; |
| 82153 | | - }else{ |
| 82154 | | - v1 = sqlite3VdbeIntValue(pIn1)!=0; |
| 82155 | | - } |
| 82156 | | - pIn2 = &aMem[pOp->p2]; |
| 82157 | | - if( pIn2->flags & MEM_Null ){ |
| 82158 | | - v2 = 2; |
| 82159 | | - }else{ |
| 82160 | | - v2 = sqlite3VdbeIntValue(pIn2)!=0; |
| 82161 | | - } |
| 83102 | + v1 = sqlite3VdbeBooleanValue(&aMem[pOp->p1], 2); |
| 83103 | + v2 = sqlite3VdbeBooleanValue(&aMem[pOp->p2], 2); |
| 82162 | 83104 | if( pOp->opcode==OP_And ){ |
| 82163 | 83105 | static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 }; |
| 82164 | 83106 | v1 = and_logic[v1*3+v2]; |
| 82165 | 83107 | }else{ |
| 82166 | 83108 | static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 }; |
| | @@ -82173,10 +83115,39 @@ |
| 82173 | 83115 | pOut->u.i = v1; |
| 82174 | 83116 | MemSetTypeFlag(pOut, MEM_Int); |
| 82175 | 83117 | } |
| 82176 | 83118 | break; |
| 82177 | 83119 | } |
| 83120 | + |
| 83121 | +/* Opcode: IsTrue P1 P2 P3 P4 * |
| 83122 | +** Synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 |
| 83123 | +** |
| 83124 | +** This opcode implements the IS TRUE, IS FALSE, IS NOT TRUE, and |
| 83125 | +** IS NOT FALSE operators. |
| 83126 | +** |
| 83127 | +** Interpret the value in register P1 as a boolean value. Store that |
| 83128 | +** boolean (a 0 or 1) in register P2. Or if the value in register P1 is |
| 83129 | +** NULL, then the P3 is stored in register P2. Invert the answer if P4 |
| 83130 | +** is 1. |
| 83131 | +** |
| 83132 | +** The logic is summarized like this: |
| 83133 | +** |
| 83134 | +** <ul> |
| 83135 | +** <li> If P3==0 and P4==0 then r[P2] := r[P1] IS TRUE |
| 83136 | +** <li> If P3==1 and P4==1 then r[P2] := r[P1] IS FALSE |
| 83137 | +** <li> If P3==0 and P4==1 then r[P2] := r[P1] IS NOT TRUE |
| 83138 | +** <li> If P3==1 and P4==0 then r[P2] := r[P1] IS NOT FALSE |
| 83139 | +** </ul> |
| 83140 | +*/ |
| 83141 | +case OP_IsTrue: { /* in1, out2 */ |
| 83142 | + assert( pOp->p4type==P4_INT32 ); |
| 83143 | + assert( pOp->p4.i==0 || pOp->p4.i==1 ); |
| 83144 | + assert( pOp->p3==0 || pOp->p3==1 ); |
| 83145 | + sqlite3VdbeMemSetInt64(&aMem[pOp->p2], |
| 83146 | + sqlite3VdbeBooleanValue(&aMem[pOp->p1], pOp->p3) ^ pOp->p4.i); |
| 83147 | + break; |
| 83148 | +} |
| 82178 | 83149 | |
| 82179 | 83150 | /* Opcode: Not P1 P2 * * * |
| 82180 | 83151 | ** Synopsis: r[P2]= !r[P1] |
| 82181 | 83152 | ** |
| 82182 | 83153 | ** Interpret the value in register P1 as a boolean value. Store the |
| | @@ -82184,14 +83155,14 @@ |
| 82184 | 83155 | ** NULL, then a NULL is stored in P2. |
| 82185 | 83156 | */ |
| 82186 | 83157 | case OP_Not: { /* same as TK_NOT, in1, out2 */ |
| 82187 | 83158 | pIn1 = &aMem[pOp->p1]; |
| 82188 | 83159 | pOut = &aMem[pOp->p2]; |
| 82189 | | - sqlite3VdbeMemSetNull(pOut); |
| 82190 | 83160 | if( (pIn1->flags & MEM_Null)==0 ){ |
| 82191 | | - pOut->flags = MEM_Int; |
| 82192 | | - pOut->u.i = !sqlite3VdbeIntValue(pIn1); |
| 83161 | + sqlite3VdbeMemSetInt64(pOut, !sqlite3VdbeBooleanValue(pIn1,0)); |
| 83162 | + }else{ |
| 83163 | + sqlite3VdbeMemSetNull(pOut); |
| 82193 | 83164 | } |
| 82194 | 83165 | break; |
| 82195 | 83166 | } |
| 82196 | 83167 | |
| 82197 | 83168 | /* Opcode: BitNot P1 P2 * * * |
| | @@ -82254,34 +83225,29 @@ |
| 82254 | 83225 | ** |
| 82255 | 83226 | ** Jump to P2 if the value in register P1 is true. The value |
| 82256 | 83227 | ** is considered true if it is numeric and non-zero. If the value |
| 82257 | 83228 | ** in P1 is NULL then take the jump if and only if P3 is non-zero. |
| 82258 | 83229 | */ |
| 83230 | +case OP_If: { /* jump, in1 */ |
| 83231 | + int c; |
| 83232 | + c = sqlite3VdbeBooleanValue(&aMem[pOp->p1], pOp->p3); |
| 83233 | + VdbeBranchTaken(c!=0, 2); |
| 83234 | + if( c ) goto jump_to_p2; |
| 83235 | + break; |
| 83236 | +} |
| 83237 | + |
| 82259 | 83238 | /* Opcode: IfNot P1 P2 P3 * * |
| 82260 | 83239 | ** |
| 82261 | 83240 | ** Jump to P2 if the value in register P1 is False. The value |
| 82262 | 83241 | ** is considered false if it has a numeric value of zero. If the value |
| 82263 | 83242 | ** in P1 is NULL then take the jump if and only if P3 is non-zero. |
| 82264 | 83243 | */ |
| 82265 | | -case OP_If: /* jump, in1 */ |
| 82266 | 83244 | case OP_IfNot: { /* jump, in1 */ |
| 82267 | 83245 | int c; |
| 82268 | | - pIn1 = &aMem[pOp->p1]; |
| 82269 | | - if( pIn1->flags & MEM_Null ){ |
| 82270 | | - c = pOp->p3; |
| 82271 | | - }else{ |
| 82272 | | -#ifdef SQLITE_OMIT_FLOATING_POINT |
| 82273 | | - c = sqlite3VdbeIntValue(pIn1)!=0; |
| 82274 | | -#else |
| 82275 | | - c = sqlite3VdbeRealValue(pIn1)!=0.0; |
| 82276 | | -#endif |
| 82277 | | - if( pOp->opcode==OP_IfNot ) c = !c; |
| 82278 | | - } |
| 83246 | + c = !sqlite3VdbeBooleanValue(&aMem[pOp->p1], !pOp->p3); |
| 82279 | 83247 | VdbeBranchTaken(c!=0, 2); |
| 82280 | | - if( c ){ |
| 82281 | | - goto jump_to_p2; |
| 82282 | | - } |
| 83248 | + if( c ) goto jump_to_p2; |
| 82283 | 83249 | break; |
| 82284 | 83250 | } |
| 82285 | 83251 | |
| 82286 | 83252 | /* Opcode: IsNull P1 P2 * * * |
| 82287 | 83253 | ** Synopsis: if r[P1]==NULL goto P2 |
| | @@ -82338,11 +83304,11 @@ |
| 82338 | 83304 | ** pointing. |
| 82339 | 83305 | ** |
| 82340 | 83306 | ** P2 is the column number for the argument to the sqlite_offset() function. |
| 82341 | 83307 | ** This opcode does not use P2 itself, but the P2 value is used by the |
| 82342 | 83308 | ** code generator. The P1, P2, and P3 operands to this opcode are the |
| 82343 | | -** as as for OP_Column. |
| 83309 | +** same as for OP_Column. |
| 82344 | 83310 | ** |
| 82345 | 83311 | ** This opcode is only available if SQLite is compiled with the |
| 82346 | 83312 | ** -DSQLITE_ENABLE_OFFSET_SQL_FUNC option. |
| 82347 | 83313 | */ |
| 82348 | 83314 | case OP_Offset: { /* out3 */ |
| | @@ -84246,10 +85212,14 @@ |
| 84246 | 85212 | v = 0; |
| 84247 | 85213 | res = 0; |
| 84248 | 85214 | pOut = out2Prerelease(p, pOp); |
| 84249 | 85215 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 84250 | 85216 | pC = p->apCsr[pOp->p1]; |
| 85217 | + if( !pC->isTable ){ |
| 85218 | + rc = SQLITE_CORRUPT_BKPT; |
| 85219 | + goto abort_due_to_error; |
| 85220 | + } |
| 84251 | 85221 | assert( pC!=0 ); |
| 84252 | 85222 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 84253 | 85223 | assert( pC->uc.pCursor!=0 ); |
| 84254 | 85224 | { |
| 84255 | 85225 | /* The next rowid or record number (different terms for the same |
| | @@ -86182,16 +87152,21 @@ |
| 86182 | 87152 | assert( pOp->p4type==P4_FUNCDEF ); |
| 86183 | 87153 | n = pOp->p5; |
| 86184 | 87154 | assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 86185 | 87155 | assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) ); |
| 86186 | 87156 | assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n ); |
| 86187 | | - pCtx = sqlite3DbMallocRawNN(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*)); |
| 87157 | + pCtx = sqlite3DbMallocRawNN(db, n*sizeof(sqlite3_value*) + |
| 87158 | + (sizeof(pCtx[0]) + sizeof(Mem) - sizeof(sqlite3_value*))); |
| 86188 | 87159 | if( pCtx==0 ) goto no_mem; |
| 86189 | 87160 | pCtx->pMem = 0; |
| 87161 | + pCtx->pOut = (Mem*)&(pCtx->argv[n]); |
| 87162 | + sqlite3VdbeMemInit(pCtx->pOut, db, MEM_Null); |
| 86190 | 87163 | pCtx->pFunc = pOp->p4.pFunc; |
| 86191 | 87164 | pCtx->iOp = (int)(pOp - aOp); |
| 86192 | 87165 | pCtx->pVdbe = p; |
| 87166 | + pCtx->skipFlag = 0; |
| 87167 | + pCtx->isError = 0; |
| 86193 | 87168 | pCtx->argc = n; |
| 86194 | 87169 | pOp->p4type = P4_FUNCCTX; |
| 86195 | 87170 | pOp->p4.pCtx = pCtx; |
| 86196 | 87171 | pOp->opcode = OP_AggStep; |
| 86197 | 87172 | /* Fall through into OP_AggStep */ |
| | @@ -86198,11 +87173,10 @@ |
| 86198 | 87173 | } |
| 86199 | 87174 | case OP_AggStep: { |
| 86200 | 87175 | int i; |
| 86201 | 87176 | sqlite3_context *pCtx; |
| 86202 | 87177 | Mem *pMem; |
| 86203 | | - Mem t; |
| 86204 | 87178 | |
| 86205 | 87179 | assert( pOp->p4type==P4_FUNCCTX ); |
| 86206 | 87180 | pCtx = pOp->p4.pCtx; |
| 86207 | 87181 | pMem = &aMem[pOp->p3]; |
| 86208 | 87182 | |
| | @@ -86221,30 +87195,32 @@ |
| 86221 | 87195 | REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]); |
| 86222 | 87196 | } |
| 86223 | 87197 | #endif |
| 86224 | 87198 | |
| 86225 | 87199 | pMem->n++; |
| 86226 | | - sqlite3VdbeMemInit(&t, db, MEM_Null); |
| 86227 | | - pCtx->pOut = &t; |
| 86228 | | - pCtx->fErrorOrAux = 0; |
| 86229 | | - pCtx->skipFlag = 0; |
| 87200 | + assert( pCtx->pOut->flags==MEM_Null ); |
| 87201 | + assert( pCtx->isError==0 ); |
| 87202 | + assert( pCtx->skipFlag==0 ); |
| 86230 | 87203 | (pCtx->pFunc->xSFunc)(pCtx,pCtx->argc,pCtx->argv); /* IMP: R-24505-23230 */ |
| 86231 | | - if( pCtx->fErrorOrAux ){ |
| 86232 | | - if( pCtx->isError ){ |
| 86233 | | - sqlite3VdbeError(p, "%s", sqlite3_value_text(&t)); |
| 87204 | + if( pCtx->isError ){ |
| 87205 | + if( pCtx->isError>0 ){ |
| 87206 | + sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut)); |
| 86234 | 87207 | rc = pCtx->isError; |
| 86235 | 87208 | } |
| 86236 | | - sqlite3VdbeMemRelease(&t); |
| 87209 | + if( pCtx->skipFlag ){ |
| 87210 | + assert( pOp[-1].opcode==OP_CollSeq ); |
| 87211 | + i = pOp[-1].p1; |
| 87212 | + if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1); |
| 87213 | + pCtx->skipFlag = 0; |
| 87214 | + } |
| 87215 | + sqlite3VdbeMemRelease(pCtx->pOut); |
| 87216 | + pCtx->pOut->flags = MEM_Null; |
| 87217 | + pCtx->isError = 0; |
| 86237 | 87218 | if( rc ) goto abort_due_to_error; |
| 86238 | | - }else{ |
| 86239 | | - assert( t.flags==MEM_Null ); |
| 86240 | | - } |
| 86241 | | - if( pCtx->skipFlag ){ |
| 86242 | | - assert( pOp[-1].opcode==OP_CollSeq ); |
| 86243 | | - i = pOp[-1].p1; |
| 86244 | | - if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1); |
| 86245 | | - } |
| 87219 | + } |
| 87220 | + assert( pCtx->pOut->flags==MEM_Null ); |
| 87221 | + assert( pCtx->skipFlag==0 ); |
| 86246 | 87222 | break; |
| 86247 | 87223 | } |
| 86248 | 87224 | |
| 86249 | 87225 | /* Opcode: AggFinal P1 P2 * P4 * |
| 86250 | 87226 | ** Synopsis: accum=r[P1] N=P2 |
| | @@ -86727,11 +87703,12 @@ |
| 86727 | 87703 | }else{ |
| 86728 | 87704 | MemSetTypeFlag(pDest, MEM_Null); |
| 86729 | 87705 | } |
| 86730 | 87706 | rc = pModule->xColumn(pCur->uc.pVCur, &sContext, pOp->p2); |
| 86731 | 87707 | sqlite3VtabImportErrmsg(p, pVtab); |
| 86732 | | - if( sContext.isError ){ |
| 87708 | + if( sContext.isError>0 ){ |
| 87709 | + sqlite3VdbeError(p, "%s", sqlite3_value_text(pDest)); |
| 86733 | 87710 | rc = sContext.isError; |
| 86734 | 87711 | } |
| 86735 | 87712 | sqlite3VdbeChangeEncoding(pDest, encoding); |
| 86736 | 87713 | REGISTER_TRACE(pOp->p3, pDest); |
| 86737 | 87714 | UPDATE_MAX_BLOBSIZE(pDest); |
| | @@ -86992,10 +87969,11 @@ |
| 86992 | 87969 | if( pCtx==0 ) goto no_mem; |
| 86993 | 87970 | pCtx->pOut = 0; |
| 86994 | 87971 | pCtx->pFunc = pOp->p4.pFunc; |
| 86995 | 87972 | pCtx->iOp = (int)(pOp - aOp); |
| 86996 | 87973 | pCtx->pVdbe = p; |
| 87974 | + pCtx->isError = 0; |
| 86997 | 87975 | pCtx->argc = n; |
| 86998 | 87976 | pOp->p4type = P4_FUNCCTX; |
| 86999 | 87977 | pOp->p4.pCtx = pCtx; |
| 87000 | 87978 | assert( OP_PureFunc == OP_PureFunc0+2 ); |
| 87001 | 87979 | assert( OP_Function == OP_Function0+2 ); |
| | @@ -87026,20 +88004,21 @@ |
| 87026 | 88004 | assert( memIsValid(pCtx->argv[i]) ); |
| 87027 | 88005 | REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]); |
| 87028 | 88006 | } |
| 87029 | 88007 | #endif |
| 87030 | 88008 | MemSetTypeFlag(pOut, MEM_Null); |
| 87031 | | - pCtx->fErrorOrAux = 0; |
| 88009 | + assert( pCtx->isError==0 ); |
| 87032 | 88010 | (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */ |
| 87033 | 88011 | |
| 87034 | 88012 | /* If the function returned an error, throw an exception */ |
| 87035 | | - if( pCtx->fErrorOrAux ){ |
| 87036 | | - if( pCtx->isError ){ |
| 88013 | + if( pCtx->isError ){ |
| 88014 | + if( pCtx->isError>0 ){ |
| 87037 | 88015 | sqlite3VdbeError(p, "%s", sqlite3_value_text(pOut)); |
| 87038 | 88016 | rc = pCtx->isError; |
| 87039 | 88017 | } |
| 87040 | 88018 | sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1); |
| 88019 | + pCtx->isError = 0; |
| 87041 | 88020 | if( rc ) goto abort_due_to_error; |
| 87042 | 88021 | } |
| 87043 | 88022 | |
| 87044 | 88023 | /* Copy the result of the function into register P3 */ |
| 87045 | 88024 | if( pOut->flags & (MEM_Str|MEM_Blob) ){ |
| | @@ -87077,12 +88056,14 @@ |
| 87077 | 88056 | ** If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT |
| 87078 | 88057 | ** error is encountered. |
| 87079 | 88058 | */ |
| 87080 | 88059 | case OP_Trace: |
| 87081 | 88060 | case OP_Init: { /* jump */ |
| 88061 | + int i; |
| 88062 | +#ifndef SQLITE_OMIT_TRACE |
| 87082 | 88063 | char *zTrace; |
| 87083 | | - int i; |
| 88064 | +#endif |
| 87084 | 88065 | |
| 87085 | 88066 | /* If the P4 argument is not NULL, then it must be an SQL comment string. |
| 87086 | 88067 | ** The "--" string is broken up to prevent false-positives with srcck1.c. |
| 87087 | 88068 | ** |
| 87088 | 88069 | ** This assert() provides evidence for: |
| | @@ -87195,11 +88176,11 @@ |
| 87195 | 88176 | *****************************************************************************/ |
| 87196 | 88177 | } |
| 87197 | 88178 | |
| 87198 | 88179 | #ifdef VDBE_PROFILE |
| 87199 | 88180 | { |
| 87200 | | - u64 endTime = sqlite3Hwtime(); |
| 88181 | + u64 endTime = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime(); |
| 87201 | 88182 | if( endTime>start ) pOrigOp->cycles += endTime - start; |
| 87202 | 88183 | pOrigOp->cnt++; |
| 87203 | 88184 | } |
| 87204 | 88185 | #endif |
| 87205 | 88186 | |
| | @@ -91582,14 +92563,20 @@ |
| 91582 | 92563 | ** pExpr. |
| 91583 | 92564 | ** |
| 91584 | 92565 | ** Because no reference was made to outer contexts, the pNC->nRef |
| 91585 | 92566 | ** fields are not changed in any context. |
| 91586 | 92567 | */ |
| 91587 | | - if( cnt==0 && zTab==0 && ExprHasProperty(pExpr,EP_DblQuoted) ){ |
| 91588 | | - pExpr->op = TK_STRING; |
| 91589 | | - pExpr->pTab = 0; |
| 91590 | | - return WRC_Prune; |
| 92568 | + if( cnt==0 && zTab==0 ){ |
| 92569 | + assert( pExpr->op==TK_ID ); |
| 92570 | + if( ExprHasProperty(pExpr,EP_DblQuoted) ){ |
| 92571 | + pExpr->op = TK_STRING; |
| 92572 | + pExpr->pTab = 0; |
| 92573 | + return WRC_Prune; |
| 92574 | + } |
| 92575 | + if( sqlite3ExprIdToTrueFalse(pExpr) ){ |
| 92576 | + return WRC_Prune; |
| 92577 | + } |
| 91591 | 92578 | } |
| 91592 | 92579 | |
| 91593 | 92580 | /* |
| 91594 | 92581 | ** cnt==0 means there was not match. cnt>1 means there were two or |
| 91595 | 92582 | ** more matches. Either way, we have an error. |
| | @@ -91934,19 +92921,34 @@ |
| 91934 | 92921 | } |
| 91935 | 92922 | case TK_VARIABLE: { |
| 91936 | 92923 | notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr); |
| 91937 | 92924 | break; |
| 91938 | 92925 | } |
| 92926 | + case TK_IS: |
| 92927 | + case TK_ISNOT: { |
| 92928 | + Expr *pRight; |
| 92929 | + assert( !ExprHasProperty(pExpr, EP_Reduced) ); |
| 92930 | + /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE", |
| 92931 | + ** and "x IS NOT FALSE". */ |
| 92932 | + if( (pRight = pExpr->pRight)->op==TK_ID ){ |
| 92933 | + int rc = resolveExprStep(pWalker, pRight); |
| 92934 | + if( rc==WRC_Abort ) return WRC_Abort; |
| 92935 | + if( pRight->op==TK_TRUEFALSE ){ |
| 92936 | + pExpr->op2 = pExpr->op; |
| 92937 | + pExpr->op = TK_TRUTH; |
| 92938 | + return WRC_Continue; |
| 92939 | + } |
| 92940 | + } |
| 92941 | + /* Fall thru */ |
| 92942 | + } |
| 91939 | 92943 | case TK_BETWEEN: |
| 91940 | 92944 | case TK_EQ: |
| 91941 | 92945 | case TK_NE: |
| 91942 | 92946 | case TK_LT: |
| 91943 | 92947 | case TK_LE: |
| 91944 | 92948 | case TK_GT: |
| 91945 | | - case TK_GE: |
| 91946 | | - case TK_IS: |
| 91947 | | - case TK_ISNOT: { |
| 92949 | + case TK_GE: { |
| 91948 | 92950 | int nLeft, nRight; |
| 91949 | 92951 | if( pParse->db->mallocFailed ) break; |
| 91950 | 92952 | assert( pExpr->pLeft!=0 ); |
| 91951 | 92953 | nLeft = sqlite3ExprVectorSize(pExpr->pLeft); |
| 91952 | 92954 | if( pExpr->op==TK_BETWEEN ){ |
| | @@ -94416,10 +95418,38 @@ |
| 94416 | 95418 | SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker *pWalker, Select *NotUsed){ |
| 94417 | 95419 | UNUSED_PARAMETER(NotUsed); |
| 94418 | 95420 | pWalker->eCode = 0; |
| 94419 | 95421 | return WRC_Abort; |
| 94420 | 95422 | } |
| 95423 | + |
| 95424 | +/* |
| 95425 | +** If the input expression is an ID with the name "true" or "false" |
| 95426 | +** then convert it into an TK_TRUEFALSE term. Return non-zero if |
| 95427 | +** the conversion happened, and zero if the expression is unaltered. |
| 95428 | +*/ |
| 95429 | +SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){ |
| 95430 | + assert( pExpr->op==TK_ID || pExpr->op==TK_STRING ); |
| 95431 | + if( sqlite3StrICmp(pExpr->u.zToken, "true")==0 |
| 95432 | + || sqlite3StrICmp(pExpr->u.zToken, "false")==0 |
| 95433 | + ){ |
| 95434 | + pExpr->op = TK_TRUEFALSE; |
| 95435 | + return 1; |
| 95436 | + } |
| 95437 | + return 0; |
| 95438 | +} |
| 95439 | + |
| 95440 | +/* |
| 95441 | +** The argument must be a TK_TRUEFALSE Expr node. Return 1 if it is TRUE |
| 95442 | +** and 0 if it is FALSE. |
| 95443 | +*/ |
| 95444 | +SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){ |
| 95445 | + assert( pExpr->op==TK_TRUEFALSE ); |
| 95446 | + assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0 |
| 95447 | + || sqlite3StrICmp(pExpr->u.zToken,"false")==0 ); |
| 95448 | + return pExpr->u.zToken[4]==0; |
| 95449 | +} |
| 95450 | + |
| 94421 | 95451 | |
| 94422 | 95452 | /* |
| 94423 | 95453 | ** These routines are Walker callbacks used to check expressions to |
| 94424 | 95454 | ** see if they are "constant" for some definition of constant. The |
| 94425 | 95455 | ** Walker.eCode value determines the type of "constant" we are looking |
| | @@ -94464,10 +95494,16 @@ |
| 94464 | 95494 | }else{ |
| 94465 | 95495 | pWalker->eCode = 0; |
| 94466 | 95496 | return WRC_Abort; |
| 94467 | 95497 | } |
| 94468 | 95498 | case TK_ID: |
| 95499 | + /* Convert "true" or "false" in a DEFAULT clause into the |
| 95500 | + ** appropriate TK_TRUEFALSE operator */ |
| 95501 | + if( sqlite3ExprIdToTrueFalse(pExpr) ){ |
| 95502 | + return WRC_Prune; |
| 95503 | + } |
| 95504 | + /* Fall thru */ |
| 94469 | 95505 | case TK_COLUMN: |
| 94470 | 95506 | case TK_AGG_FUNCTION: |
| 94471 | 95507 | case TK_AGG_COLUMN: |
| 94472 | 95508 | testcase( pExpr->op==TK_ID ); |
| 94473 | 95509 | testcase( pExpr->op==TK_COLUMN ); |
| | @@ -96227,10 +97263,14 @@ |
| 96227 | 97263 | pExpr->op2); |
| 96228 | 97264 | } |
| 96229 | 97265 | case TK_INTEGER: { |
| 96230 | 97266 | codeInteger(pParse, pExpr, 0, target); |
| 96231 | 97267 | return target; |
| 97268 | + } |
| 97269 | + case TK_TRUEFALSE: { |
| 97270 | + sqlite3VdbeAddOp2(v, OP_Integer, sqlite3ExprTruthValue(pExpr), target); |
| 97271 | + return target; |
| 96232 | 97272 | } |
| 96233 | 97273 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 96234 | 97274 | case TK_FLOAT: { |
| 96235 | 97275 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 96236 | 97276 | codeReal(v, pExpr->u.zToken, 0, target); |
| | @@ -96382,10 +97422,22 @@ |
| 96382 | 97422 | assert( TK_NOT==OP_Not ); testcase( op==TK_NOT ); |
| 96383 | 97423 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 96384 | 97424 | testcase( regFree1==0 ); |
| 96385 | 97425 | sqlite3VdbeAddOp2(v, op, r1, inReg); |
| 96386 | 97426 | break; |
| 97427 | + } |
| 97428 | + case TK_TRUTH: { |
| 97429 | + int isTrue; /* IS TRUE or IS NOT TRUE */ |
| 97430 | + int bNormal; /* IS TRUE or IS FALSE */ |
| 97431 | + r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 97432 | + testcase( regFree1==0 ); |
| 97433 | + isTrue = sqlite3ExprTruthValue(pExpr->pRight); |
| 97434 | + bNormal = pExpr->op2==TK_IS; |
| 97435 | + testcase( isTrue && bNormal); |
| 97436 | + testcase( !isTrue && bNormal); |
| 97437 | + sqlite3VdbeAddOp4Int(v, OP_IsTrue, r1, inReg, !isTrue, isTrue ^ bNormal); |
| 97438 | + break; |
| 96387 | 97439 | } |
| 96388 | 97440 | case TK_ISNULL: |
| 96389 | 97441 | case TK_NOTNULL: { |
| 96390 | 97442 | int addr; |
| 96391 | 97443 | assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL ); |
| | @@ -97157,10 +98209,27 @@ |
| 97157 | 98209 | } |
| 97158 | 98210 | case TK_NOT: { |
| 97159 | 98211 | testcase( jumpIfNull==0 ); |
| 97160 | 98212 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 97161 | 98213 | break; |
| 98214 | + } |
| 98215 | + case TK_TRUTH: { |
| 98216 | + int isNot; /* IS NOT TRUE or IS NOT FALSE */ |
| 98217 | + int isTrue; /* IS TRUE or IS NOT TRUE */ |
| 98218 | + testcase( jumpIfNull==0 ); |
| 98219 | + isNot = pExpr->op2==TK_ISNOT; |
| 98220 | + isTrue = sqlite3ExprTruthValue(pExpr->pRight); |
| 98221 | + testcase( isTrue && isNot ); |
| 98222 | + testcase( !isTrue && isNot ); |
| 98223 | + if( isTrue ^ isNot ){ |
| 98224 | + sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, |
| 98225 | + isNot ? SQLITE_JUMPIFNULL : 0); |
| 98226 | + }else{ |
| 98227 | + sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, |
| 98228 | + isNot ? SQLITE_JUMPIFNULL : 0); |
| 98229 | + } |
| 98230 | + break; |
| 97162 | 98231 | } |
| 97163 | 98232 | case TK_IS: |
| 97164 | 98233 | case TK_ISNOT: |
| 97165 | 98234 | testcase( op==TK_IS ); |
| 97166 | 98235 | testcase( op==TK_ISNOT ); |
| | @@ -97311,10 +98380,30 @@ |
| 97311 | 98380 | } |
| 97312 | 98381 | case TK_NOT: { |
| 97313 | 98382 | testcase( jumpIfNull==0 ); |
| 97314 | 98383 | sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 97315 | 98384 | break; |
| 98385 | + } |
| 98386 | + case TK_TRUTH: { |
| 98387 | + int isNot; /* IS NOT TRUE or IS NOT FALSE */ |
| 98388 | + int isTrue; /* IS TRUE or IS NOT TRUE */ |
| 98389 | + testcase( jumpIfNull==0 ); |
| 98390 | + isNot = pExpr->op2==TK_ISNOT; |
| 98391 | + isTrue = sqlite3ExprTruthValue(pExpr->pRight); |
| 98392 | + testcase( isTrue && isNot ); |
| 98393 | + testcase( !isTrue && isNot ); |
| 98394 | + if( isTrue ^ isNot ){ |
| 98395 | + /* IS TRUE and IS NOT FALSE */ |
| 98396 | + sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, |
| 98397 | + isNot ? 0 : SQLITE_JUMPIFNULL); |
| 98398 | + |
| 98399 | + }else{ |
| 98400 | + /* IS FALSE and IS NOT TRUE */ |
| 98401 | + sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, |
| 98402 | + isNot ? 0 : SQLITE_JUMPIFNULL); |
| 98403 | + } |
| 98404 | + break; |
| 97316 | 98405 | } |
| 97317 | 98406 | case TK_IS: |
| 97318 | 98407 | case TK_ISNOT: |
| 97319 | 98408 | testcase( pExpr->op==TK_IS ); |
| 97320 | 98409 | testcase( pExpr->op==TK_ISNOT ); |
| | @@ -100822,10 +101911,14 @@ |
| 100822 | 101911 | ** |
| 100823 | 101912 | ** SELECT sqlite_attach(x, y, z) |
| 100824 | 101913 | ** |
| 100825 | 101914 | ** If the optional "KEY z" syntax is omitted, an SQL NULL is passed as the |
| 100826 | 101915 | ** third argument. |
| 101916 | +** |
| 101917 | +** If the db->init.reopenMemdb flags is set, then instead of attaching a |
| 101918 | +** new database, close the database on db->init.iDb and reopen it as an |
| 101919 | +** empty MemDB. |
| 100827 | 101920 | */ |
| 100828 | 101921 | static void attachFunc( |
| 100829 | 101922 | sqlite3_context *context, |
| 100830 | 101923 | int NotUsed, |
| 100831 | 101924 | sqlite3_value **argv |
| | @@ -100842,69 +101935,89 @@ |
| 100842 | 101935 | Db *pNew; /* Db object for the newly attached database */ |
| 100843 | 101936 | char *zErrDyn = 0; |
| 100844 | 101937 | sqlite3_vfs *pVfs; |
| 100845 | 101938 | |
| 100846 | 101939 | UNUSED_PARAMETER(NotUsed); |
| 100847 | | - |
| 100848 | 101940 | zFile = (const char *)sqlite3_value_text(argv[0]); |
| 100849 | 101941 | zName = (const char *)sqlite3_value_text(argv[1]); |
| 100850 | 101942 | if( zFile==0 ) zFile = ""; |
| 100851 | 101943 | if( zName==0 ) zName = ""; |
| 100852 | 101944 | |
| 100853 | | - /* Check for the following errors: |
| 100854 | | - ** |
| 100855 | | - ** * Too many attached databases, |
| 100856 | | - ** * Transaction currently open |
| 100857 | | - ** * Specified database name already being used. |
| 100858 | | - */ |
| 100859 | | - if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){ |
| 100860 | | - zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d", |
| 100861 | | - db->aLimit[SQLITE_LIMIT_ATTACHED] |
| 100862 | | - ); |
| 100863 | | - goto attach_error; |
| 100864 | | - } |
| 100865 | | - for(i=0; i<db->nDb; i++){ |
| 100866 | | - char *z = db->aDb[i].zDbSName; |
| 100867 | | - assert( z && zName ); |
| 100868 | | - if( sqlite3StrICmp(z, zName)==0 ){ |
| 100869 | | - zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName); |
| 100870 | | - goto attach_error; |
| 100871 | | - } |
| 100872 | | - } |
| 100873 | | - |
| 100874 | | - /* Allocate the new entry in the db->aDb[] array and initialize the schema |
| 100875 | | - ** hash tables. |
| 100876 | | - */ |
| 100877 | | - if( db->aDb==db->aDbStatic ){ |
| 100878 | | - aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 ); |
| 100879 | | - if( aNew==0 ) return; |
| 100880 | | - memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2); |
| 100881 | | - }else{ |
| 100882 | | - aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); |
| 100883 | | - if( aNew==0 ) return; |
| 100884 | | - } |
| 100885 | | - db->aDb = aNew; |
| 100886 | | - pNew = &db->aDb[db->nDb]; |
| 100887 | | - memset(pNew, 0, sizeof(*pNew)); |
| 100888 | | - |
| 100889 | | - /* Open the database file. If the btree is successfully opened, use |
| 100890 | | - ** it to obtain the database schema. At this point the schema may |
| 100891 | | - ** or may not be initialized. |
| 100892 | | - */ |
| 100893 | | - flags = db->openFlags; |
| 100894 | | - rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr); |
| 100895 | | - if( rc!=SQLITE_OK ){ |
| 100896 | | - if( rc==SQLITE_NOMEM ) sqlite3OomFault(db); |
| 100897 | | - sqlite3_result_error(context, zErr, -1); |
| 100898 | | - sqlite3_free(zErr); |
| 100899 | | - return; |
| 100900 | | - } |
| 100901 | | - assert( pVfs ); |
| 100902 | | - flags |= SQLITE_OPEN_MAIN_DB; |
| 100903 | | - rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags); |
| 100904 | | - sqlite3_free( zPath ); |
| 100905 | | - db->nDb++; |
| 101945 | +#ifdef SQLITE_ENABLE_DESERIALIZE |
| 101946 | +# define REOPEN_AS_MEMDB(db) (db->init.reopenMemdb) |
| 101947 | +#else |
| 101948 | +# define REOPEN_AS_MEMDB(db) (0) |
| 101949 | +#endif |
| 101950 | + |
| 101951 | + if( REOPEN_AS_MEMDB(db) ){ |
| 101952 | + /* This is not a real ATTACH. Instead, this routine is being called |
| 101953 | + ** from sqlite3_deserialize() to close database db->init.iDb and |
| 101954 | + ** reopen it as a MemDB */ |
| 101955 | + pVfs = sqlite3_vfs_find("memdb"); |
| 101956 | + if( pVfs==0 ) return; |
| 101957 | + pNew = &db->aDb[db->init.iDb]; |
| 101958 | + if( pNew->pBt ) sqlite3BtreeClose(pNew->pBt); |
| 101959 | + pNew->pBt = 0; |
| 101960 | + pNew->pSchema = 0; |
| 101961 | + rc = sqlite3BtreeOpen(pVfs, "x", db, &pNew->pBt, 0, SQLITE_OPEN_MAIN_DB); |
| 101962 | + }else{ |
| 101963 | + /* This is a real ATTACH |
| 101964 | + ** |
| 101965 | + ** Check for the following errors: |
| 101966 | + ** |
| 101967 | + ** * Too many attached databases, |
| 101968 | + ** * Transaction currently open |
| 101969 | + ** * Specified database name already being used. |
| 101970 | + */ |
| 101971 | + if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){ |
| 101972 | + zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d", |
| 101973 | + db->aLimit[SQLITE_LIMIT_ATTACHED] |
| 101974 | + ); |
| 101975 | + goto attach_error; |
| 101976 | + } |
| 101977 | + for(i=0; i<db->nDb; i++){ |
| 101978 | + char *z = db->aDb[i].zDbSName; |
| 101979 | + assert( z && zName ); |
| 101980 | + if( sqlite3StrICmp(z, zName)==0 ){ |
| 101981 | + zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName); |
| 101982 | + goto attach_error; |
| 101983 | + } |
| 101984 | + } |
| 101985 | + |
| 101986 | + /* Allocate the new entry in the db->aDb[] array and initialize the schema |
| 101987 | + ** hash tables. |
| 101988 | + */ |
| 101989 | + if( db->aDb==db->aDbStatic ){ |
| 101990 | + aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 ); |
| 101991 | + if( aNew==0 ) return; |
| 101992 | + memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2); |
| 101993 | + }else{ |
| 101994 | + aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); |
| 101995 | + if( aNew==0 ) return; |
| 101996 | + } |
| 101997 | + db->aDb = aNew; |
| 101998 | + pNew = &db->aDb[db->nDb]; |
| 101999 | + memset(pNew, 0, sizeof(*pNew)); |
| 102000 | + |
| 102001 | + /* Open the database file. If the btree is successfully opened, use |
| 102002 | + ** it to obtain the database schema. At this point the schema may |
| 102003 | + ** or may not be initialized. |
| 102004 | + */ |
| 102005 | + flags = db->openFlags; |
| 102006 | + rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr); |
| 102007 | + if( rc!=SQLITE_OK ){ |
| 102008 | + if( rc==SQLITE_NOMEM ) sqlite3OomFault(db); |
| 102009 | + sqlite3_result_error(context, zErr, -1); |
| 102010 | + sqlite3_free(zErr); |
| 102011 | + return; |
| 102012 | + } |
| 102013 | + assert( pVfs ); |
| 102014 | + flags |= SQLITE_OPEN_MAIN_DB; |
| 102015 | + rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags); |
| 102016 | + sqlite3_free( zPath ); |
| 102017 | + db->nDb++; |
| 102018 | + } |
| 100906 | 102019 | db->skipBtreeMutex = 0; |
| 100907 | 102020 | if( rc==SQLITE_CONSTRAINT ){ |
| 100908 | 102021 | rc = SQLITE_ERROR; |
| 100909 | 102022 | zErrDyn = sqlite3MPrintf(db, "database is already attached"); |
| 100910 | 102023 | }else if( rc==SQLITE_OK ){ |
| | @@ -100927,11 +102040,11 @@ |
| 100927 | 102040 | PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK)); |
| 100928 | 102041 | #endif |
| 100929 | 102042 | sqlite3BtreeLeave(pNew->pBt); |
| 100930 | 102043 | } |
| 100931 | 102044 | pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1; |
| 100932 | | - pNew->zDbSName = sqlite3DbStrDup(db, zName); |
| 102045 | + if( !REOPEN_AS_MEMDB(db) ) pNew->zDbSName = sqlite3DbStrDup(db, zName); |
| 100933 | 102046 | if( rc==SQLITE_OK && pNew->zDbSName==0 ){ |
| 100934 | 102047 | rc = SQLITE_NOMEM_BKPT; |
| 100935 | 102048 | } |
| 100936 | 102049 | |
| 100937 | 102050 | |
| | @@ -100967,17 +102080,19 @@ |
| 100967 | 102080 | } |
| 100968 | 102081 | #endif |
| 100969 | 102082 | |
| 100970 | 102083 | /* If the file was opened successfully, read the schema for the new database. |
| 100971 | 102084 | ** If this fails, or if opening the file failed, then close the file and |
| 100972 | | - ** remove the entry from the db->aDb[] array. i.e. put everything back the way |
| 100973 | | - ** we found it. |
| 102085 | + ** remove the entry from the db->aDb[] array. i.e. put everything back the |
| 102086 | + ** way we found it. |
| 100974 | 102087 | */ |
| 100975 | 102088 | if( rc==SQLITE_OK ){ |
| 100976 | 102089 | sqlite3BtreeEnterAll(db); |
| 102090 | + db->init.iDb = 0; |
| 100977 | 102091 | rc = sqlite3Init(db, &zErrDyn); |
| 100978 | 102092 | sqlite3BtreeLeaveAll(db); |
| 102093 | + assert( zErrDyn==0 || rc!=SQLITE_OK ); |
| 100979 | 102094 | } |
| 100980 | 102095 | #ifdef SQLITE_USER_AUTHENTICATION |
| 100981 | 102096 | if( rc==SQLITE_OK ){ |
| 100982 | 102097 | u8 newAuth = 0; |
| 100983 | 102098 | rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth); |
| | @@ -100985,25 +102100,27 @@ |
| 100985 | 102100 | rc = SQLITE_AUTH_USER; |
| 100986 | 102101 | } |
| 100987 | 102102 | } |
| 100988 | 102103 | #endif |
| 100989 | 102104 | if( rc ){ |
| 100990 | | - int iDb = db->nDb - 1; |
| 100991 | | - assert( iDb>=2 ); |
| 100992 | | - if( db->aDb[iDb].pBt ){ |
| 100993 | | - sqlite3BtreeClose(db->aDb[iDb].pBt); |
| 100994 | | - db->aDb[iDb].pBt = 0; |
| 100995 | | - db->aDb[iDb].pSchema = 0; |
| 100996 | | - } |
| 100997 | | - sqlite3ResetAllSchemasOfConnection(db); |
| 100998 | | - db->nDb = iDb; |
| 100999 | | - if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ |
| 101000 | | - sqlite3OomFault(db); |
| 101001 | | - sqlite3DbFree(db, zErrDyn); |
| 101002 | | - zErrDyn = sqlite3MPrintf(db, "out of memory"); |
| 101003 | | - }else if( zErrDyn==0 ){ |
| 101004 | | - zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile); |
| 102105 | + if( !REOPEN_AS_MEMDB(db) ){ |
| 102106 | + int iDb = db->nDb - 1; |
| 102107 | + assert( iDb>=2 ); |
| 102108 | + if( db->aDb[iDb].pBt ){ |
| 102109 | + sqlite3BtreeClose(db->aDb[iDb].pBt); |
| 102110 | + db->aDb[iDb].pBt = 0; |
| 102111 | + db->aDb[iDb].pSchema = 0; |
| 102112 | + } |
| 102113 | + sqlite3ResetAllSchemasOfConnection(db); |
| 102114 | + db->nDb = iDb; |
| 102115 | + if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ |
| 102116 | + sqlite3OomFault(db); |
| 102117 | + sqlite3DbFree(db, zErrDyn); |
| 102118 | + zErrDyn = sqlite3MPrintf(db, "out of memory"); |
| 102119 | + }else if( zErrDyn==0 ){ |
| 102120 | + zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile); |
| 102121 | + } |
| 101005 | 102122 | } |
| 101006 | 102123 | goto attach_error; |
| 101007 | 102124 | } |
| 101008 | 102125 | |
| 101009 | 102126 | return; |
| | @@ -101270,10 +102387,18 @@ |
| 101270 | 102387 | if( sqlite3FixExprList(pFix, pSelect->pOrderBy) ){ |
| 101271 | 102388 | return 1; |
| 101272 | 102389 | } |
| 101273 | 102390 | if( sqlite3FixExpr(pFix, pSelect->pLimit) ){ |
| 101274 | 102391 | return 1; |
| 102392 | + } |
| 102393 | + if( pSelect->pWith ){ |
| 102394 | + int i; |
| 102395 | + for(i=0; i<pSelect->pWith->nCte; i++){ |
| 102396 | + if( sqlite3FixSelect(pFix, pSelect->pWith->a[i].pSelect) ){ |
| 102397 | + return 1; |
| 102398 | + } |
| 102399 | + } |
| 101275 | 102400 | } |
| 101276 | 102401 | pSelect = pSelect->pPrior; |
| 101277 | 102402 | } |
| 101278 | 102403 | return 0; |
| 101279 | 102404 | } |
| | @@ -102734,14 +103859,28 @@ |
| 102734 | 103859 | ** been seen on a column. This routine sets the notNull flag on |
| 102735 | 103860 | ** the column currently under construction. |
| 102736 | 103861 | */ |
| 102737 | 103862 | SQLITE_PRIVATE void sqlite3AddNotNull(Parse *pParse, int onError){ |
| 102738 | 103863 | Table *p; |
| 103864 | + Column *pCol; |
| 102739 | 103865 | p = pParse->pNewTable; |
| 102740 | 103866 | if( p==0 || NEVER(p->nCol<1) ) return; |
| 102741 | | - p->aCol[p->nCol-1].notNull = (u8)onError; |
| 103867 | + pCol = &p->aCol[p->nCol-1]; |
| 103868 | + pCol->notNull = (u8)onError; |
| 102742 | 103869 | p->tabFlags |= TF_HasNotNull; |
| 103870 | + |
| 103871 | + /* Set the uniqNotNull flag on any UNIQUE or PK indexes already created |
| 103872 | + ** on this column. */ |
| 103873 | + if( pCol->colFlags & COLFLAG_UNIQUE ){ |
| 103874 | + Index *pIdx; |
| 103875 | + for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 103876 | + assert( pIdx->nKeyCol==1 && pIdx->onError!=OE_None ); |
| 103877 | + if( pIdx->aiColumn[0]==p->nCol-1 ){ |
| 103878 | + pIdx->uniqNotNull = 1; |
| 103879 | + } |
| 103880 | + } |
| 103881 | + } |
| 102743 | 103882 | } |
| 102744 | 103883 | |
| 102745 | 103884 | /* |
| 102746 | 103885 | ** Scan the column type name zType (length nType) and return the |
| 102747 | 103886 | ** associated affinity type. |
| | @@ -103472,12 +104611,10 @@ |
| 103472 | 104611 | } |
| 103473 | 104612 | assert( !db->mallocFailed ); |
| 103474 | 104613 | p = pParse->pNewTable; |
| 103475 | 104614 | if( p==0 ) return; |
| 103476 | 104615 | |
| 103477 | | - assert( !db->init.busy || !pSelect ); |
| 103478 | | - |
| 103479 | 104616 | /* If the db->init.busy is 1 it means we are reading the SQL off the |
| 103480 | 104617 | ** "sqlite_master" or "sqlite_temp_master" table on the disk. |
| 103481 | 104618 | ** So do not write to the disk again. Extract the root page number |
| 103482 | 104619 | ** for the table from the db->init.newTnum field. (The page number |
| 103483 | 104620 | ** should have been put there by the sqliteOpenCb routine.) |
| | @@ -103484,10 +104621,14 @@ |
| 103484 | 104621 | ** |
| 103485 | 104622 | ** If the root page number is 1, that means this is the sqlite_master |
| 103486 | 104623 | ** table itself. So mark it read-only. |
| 103487 | 104624 | */ |
| 103488 | 104625 | if( db->init.busy ){ |
| 104626 | + if( pSelect ){ |
| 104627 | + sqlite3ErrorMsg(pParse, ""); |
| 104628 | + return; |
| 104629 | + } |
| 103489 | 104630 | p->tnum = db->init.newTnum; |
| 103490 | 104631 | if( p->tnum==1 ) p->tabFlags |= TF_Readonly; |
| 103491 | 104632 | } |
| 103492 | 104633 | |
| 103493 | 104634 | /* Special processing for WITHOUT ROWID Tables */ |
| | @@ -104701,11 +105842,13 @@ |
| 104701 | 105842 | ** key out of the last column added to the table under construction. |
| 104702 | 105843 | ** So create a fake list to simulate this. |
| 104703 | 105844 | */ |
| 104704 | 105845 | if( pList==0 ){ |
| 104705 | 105846 | Token prevCol; |
| 104706 | | - sqlite3TokenInit(&prevCol, pTab->aCol[pTab->nCol-1].zName); |
| 105847 | + Column *pCol = &pTab->aCol[pTab->nCol-1]; |
| 105848 | + pCol->colFlags |= COLFLAG_UNIQUE; |
| 105849 | + sqlite3TokenInit(&prevCol, pCol->zName); |
| 104707 | 105850 | pList = sqlite3ExprListAppend(pParse, 0, |
| 104708 | 105851 | sqlite3ExprAlloc(db, TK_ID, &prevCol, 0)); |
| 104709 | 105852 | if( pList==0 ) goto exit_create_index; |
| 104710 | 105853 | assert( pList->nExpr==1 ); |
| 104711 | 105854 | sqlite3ExprListSetSortOrder(pList, sortOrder); |
| | @@ -107546,10 +108689,12 @@ |
| 107546 | 108689 | /* |
| 107547 | 108690 | ** Indicate that the accumulator load should be skipped on this |
| 107548 | 108691 | ** iteration of the aggregate loop. |
| 107549 | 108692 | */ |
| 107550 | 108693 | static void sqlite3SkipAccumulatorLoad(sqlite3_context *context){ |
| 108694 | + assert( context->isError<=0 ); |
| 108695 | + context->isError = -1; |
| 107551 | 108696 | context->skipFlag = 1; |
| 107552 | 108697 | } |
| 107553 | 108698 | |
| 107554 | 108699 | /* |
| 107555 | 108700 | ** Implementation of the non-aggregate min() and max() functions |
| | @@ -107612,12 +108757,10 @@ |
| 107612 | 108757 | static void lengthFunc( |
| 107613 | 108758 | sqlite3_context *context, |
| 107614 | 108759 | int argc, |
| 107615 | 108760 | sqlite3_value **argv |
| 107616 | 108761 | ){ |
| 107617 | | - int len; |
| 107618 | | - |
| 107619 | 108762 | assert( argc==1 ); |
| 107620 | 108763 | UNUSED_PARAMETER(argc); |
| 107621 | 108764 | switch( sqlite3_value_type(argv[0]) ){ |
| 107622 | 108765 | case SQLITE_BLOB: |
| 107623 | 108766 | case SQLITE_INTEGER: |
| | @@ -107625,17 +108768,21 @@ |
| 107625 | 108768 | sqlite3_result_int(context, sqlite3_value_bytes(argv[0])); |
| 107626 | 108769 | break; |
| 107627 | 108770 | } |
| 107628 | 108771 | case SQLITE_TEXT: { |
| 107629 | 108772 | const unsigned char *z = sqlite3_value_text(argv[0]); |
| 108773 | + const unsigned char *z0; |
| 108774 | + unsigned char c; |
| 107630 | 108775 | if( z==0 ) return; |
| 107631 | | - len = 0; |
| 107632 | | - while( *z ){ |
| 107633 | | - len++; |
| 107634 | | - SQLITE_SKIP_UTF8(z); |
| 108776 | + z0 = z; |
| 108777 | + while( (c = *z)!=0 ){ |
| 108778 | + z++; |
| 108779 | + if( c>=0xc0 ){ |
| 108780 | + while( (*z & 0xc0)==0x80 ){ z++; z0++; } |
| 108781 | + } |
| 107635 | 108782 | } |
| 107636 | | - sqlite3_result_int(context, len); |
| 108783 | + sqlite3_result_int(context, (int)(z-z0)); |
| 107637 | 108784 | break; |
| 107638 | 108785 | } |
| 107639 | 108786 | default: { |
| 107640 | 108787 | sqlite3_result_null(context); |
| 107641 | 108788 | break; |
| | @@ -108706,10 +109853,12 @@ |
| 108706 | 109853 | int nPattern; /* Size of zPattern */ |
| 108707 | 109854 | int nRep; /* Size of zRep */ |
| 108708 | 109855 | i64 nOut; /* Maximum size of zOut */ |
| 108709 | 109856 | int loopLimit; /* Last zStr[] that might match zPattern[] */ |
| 108710 | 109857 | int i, j; /* Loop counters */ |
| 109858 | + unsigned cntExpand; /* Number zOut expansions */ |
| 109859 | + sqlite3 *db = sqlite3_context_db_handle(context); |
| 108711 | 109860 | |
| 108712 | 109861 | assert( argc==3 ); |
| 108713 | 109862 | UNUSED_PARAMETER(argc); |
| 108714 | 109863 | zStr = sqlite3_value_text(argv[0]); |
| 108715 | 109864 | if( zStr==0 ) return; |
| | @@ -108737,37 +109886,44 @@ |
| 108737 | 109886 | zOut = contextMalloc(context, (i64)nOut); |
| 108738 | 109887 | if( zOut==0 ){ |
| 108739 | 109888 | return; |
| 108740 | 109889 | } |
| 108741 | 109890 | loopLimit = nStr - nPattern; |
| 109891 | + cntExpand = 0; |
| 108742 | 109892 | for(i=j=0; i<=loopLimit; i++){ |
| 108743 | 109893 | if( zStr[i]!=zPattern[0] || memcmp(&zStr[i], zPattern, nPattern) ){ |
| 108744 | 109894 | zOut[j++] = zStr[i]; |
| 108745 | 109895 | }else{ |
| 108746 | | - u8 *zOld; |
| 108747 | | - sqlite3 *db = sqlite3_context_db_handle(context); |
| 108748 | | - nOut += nRep - nPattern; |
| 108749 | | - testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] ); |
| 108750 | | - testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] ); |
| 108751 | | - if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 108752 | | - sqlite3_result_error_toobig(context); |
| 108753 | | - sqlite3_free(zOut); |
| 108754 | | - return; |
| 108755 | | - } |
| 108756 | | - zOld = zOut; |
| 108757 | | - zOut = sqlite3_realloc64(zOut, (int)nOut); |
| 108758 | | - if( zOut==0 ){ |
| 108759 | | - sqlite3_result_error_nomem(context); |
| 108760 | | - sqlite3_free(zOld); |
| 108761 | | - return; |
| 109896 | + if( nRep>nPattern ){ |
| 109897 | + nOut += nRep - nPattern; |
| 109898 | + testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] ); |
| 109899 | + testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] ); |
| 109900 | + if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 109901 | + sqlite3_result_error_toobig(context); |
| 109902 | + sqlite3_free(zOut); |
| 109903 | + return; |
| 109904 | + } |
| 109905 | + cntExpand++; |
| 109906 | + if( (cntExpand&(cntExpand-1))==0 ){ |
| 109907 | + /* Grow the size of the output buffer only on substitutions |
| 109908 | + ** whose index is a power of two: 1, 2, 4, 8, 16, 32, ... */ |
| 109909 | + u8 *zOld; |
| 109910 | + zOld = zOut; |
| 109911 | + zOut = sqlite3_realloc64(zOut, (int)nOut + (nOut - nStr - 1)); |
| 109912 | + if( zOut==0 ){ |
| 109913 | + sqlite3_result_error_nomem(context); |
| 109914 | + sqlite3_free(zOld); |
| 109915 | + return; |
| 109916 | + } |
| 109917 | + } |
| 108762 | 109918 | } |
| 108763 | 109919 | memcpy(&zOut[j], zRep, nRep); |
| 108764 | 109920 | j += nRep; |
| 108765 | 109921 | i += nPattern-1; |
| 108766 | 109922 | } |
| 108767 | 109923 | } |
| 108768 | | - assert( j+nStr-i+1==nOut ); |
| 109924 | + assert( j+nStr-i+1<=nOut ); |
| 108769 | 109925 | memcpy(&zOut[j], &zStr[i], nStr-i); |
| 108770 | 109926 | j += nStr - i; |
| 108771 | 109927 | assert( j<=nOut ); |
| 108772 | 109928 | zOut[j] = 0; |
| 108773 | 109929 | sqlite3_result_text(context, (char*)zOut, j, sqlite3_free); |
| | @@ -113826,12 +114982,12 @@ |
| 113826 | 114982 | #define sqlite3_bind_pointer sqlite3_api->bind_pointer |
| 113827 | 114983 | #define sqlite3_result_pointer sqlite3_api->result_pointer |
| 113828 | 114984 | #define sqlite3_value_pointer sqlite3_api->value_pointer |
| 113829 | 114985 | /* Version 3.22.0 and later */ |
| 113830 | 114986 | #define sqlite3_vtab_nochange sqlite3_api->vtab_nochange |
| 113831 | | -#define sqlite3_value_nochange sqltie3_api->value_nochange |
| 113832 | | -#define sqlite3_vtab_collation sqltie3_api->vtab_collation |
| 114987 | +#define sqlite3_value_nochange sqlite3_api->value_nochange |
| 114988 | +#define sqlite3_vtab_collation sqlite3_api->vtab_collation |
| 113833 | 114989 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 113834 | 114990 | |
| 113835 | 114991 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 113836 | 114992 | /* This case when the file really is being compiled as a loadable |
| 113837 | 114993 | ** extension */ |
| | @@ -117811,11 +118967,11 @@ |
| 117811 | 118967 | sqlite3 *db = pData->db; |
| 117812 | 118968 | if( !db->mallocFailed && (db->flags & SQLITE_WriteSchema)==0 ){ |
| 117813 | 118969 | char *z; |
| 117814 | 118970 | if( zObj==0 ) zObj = "?"; |
| 117815 | 118971 | z = sqlite3MPrintf(db, "malformed database schema (%s)", zObj); |
| 117816 | | - if( zExtra ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra); |
| 118972 | + if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra); |
| 117817 | 118973 | sqlite3DbFree(db, *pData->pzErrMsg); |
| 117818 | 118974 | *pData->pzErrMsg = z; |
| 117819 | 118975 | } |
| 117820 | 118976 | pData->rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_CORRUPT_BKPT; |
| 117821 | 118977 | } |
| | @@ -119950,16 +121106,19 @@ |
| 119950 | 121106 | addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v); |
| 119951 | 121107 | codeOffset(v, p->iOffset, addrContinue); |
| 119952 | 121108 | iSortTab = iTab; |
| 119953 | 121109 | bSeq = 1; |
| 119954 | 121110 | } |
| 119955 | | - for(i=0, iCol=nKey+bSeq; i<nSortData; i++){ |
| 121111 | + for(i=0, iCol=nKey+bSeq-1; i<nSortData; i++){ |
| 121112 | + if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++; |
| 121113 | + } |
| 121114 | + for(i=nSortData-1; i>=0; i--){ |
| 119956 | 121115 | int iRead; |
| 119957 | 121116 | if( aOutEx[i].u.x.iOrderByCol ){ |
| 119958 | 121117 | iRead = aOutEx[i].u.x.iOrderByCol-1; |
| 119959 | 121118 | }else{ |
| 119960 | | - iRead = iCol++; |
| 121119 | + iRead = iCol--; |
| 119961 | 121120 | } |
| 119962 | 121121 | sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i); |
| 119963 | 121122 | VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan)); |
| 119964 | 121123 | } |
| 119965 | 121124 | switch( eDest ){ |
| | @@ -127022,12 +128181,12 @@ |
| 127022 | 128181 | rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); |
| 127023 | 128182 | if( rc!=SQLITE_OK ) return rc; |
| 127024 | 128183 | while( SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){ |
| 127025 | 128184 | const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0); |
| 127026 | 128185 | assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 ); |
| 127027 | | - if( zSubSql ){ |
| 127028 | | - assert( zSubSql[0]!='S' ); |
| 128186 | + assert( sqlite3_strnicmp(zSubSql,"SELECT",6)!=0 || CORRUPT_DB ); |
| 128187 | + if( zSubSql && zSubSql[0]!='S' ){ |
| 127029 | 128188 | rc = execSql(db, pzErrMsg, zSubSql); |
| 127030 | 128189 | if( rc!=SQLITE_OK ) break; |
| 127031 | 128190 | } |
| 127032 | 128191 | } |
| 127033 | 128192 | assert( rc!=SQLITE_ROW ); |
| | @@ -130561,11 +131720,19 @@ |
| 130561 | 131720 | assert( pX!=0 ); |
| 130562 | 131721 | testcase( pStart->leftCursor!=iCur ); /* transitive constraints */ |
| 130563 | 131722 | if( sqlite3ExprIsVector(pX->pRight) ){ |
| 130564 | 131723 | r1 = rTemp = sqlite3GetTempReg(pParse); |
| 130565 | 131724 | codeExprOrVector(pParse, pX->pRight, r1, 1); |
| 130566 | | - op = aMoveOp[(pX->op - TK_GT) | 0x0001]; |
| 131725 | + testcase( pX->op==TK_GT ); |
| 131726 | + testcase( pX->op==TK_GE ); |
| 131727 | + testcase( pX->op==TK_LT ); |
| 131728 | + testcase( pX->op==TK_LE ); |
| 131729 | + op = aMoveOp[((pX->op - TK_GT - 1) & 0x3) | 0x1]; |
| 131730 | + assert( pX->op!=TK_GT || op==OP_SeekGE ); |
| 131731 | + assert( pX->op!=TK_GE || op==OP_SeekGE ); |
| 131732 | + assert( pX->op!=TK_LT || op==OP_SeekLE ); |
| 131733 | + assert( pX->op!=TK_LE || op==OP_SeekLE ); |
| 130567 | 131734 | }else{ |
| 130568 | 131735 | r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp); |
| 130569 | 131736 | disableTerm(pLevel, pStart); |
| 130570 | 131737 | op = aMoveOp[(pX->op - TK_GT)]; |
| 130571 | 131738 | } |
| | @@ -131336,10 +132503,16 @@ |
| 131336 | 132503 | assert( (pTerm->prereqRight & pLevel->notReady)!=0 ); |
| 131337 | 132504 | pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.leftColumn, notReady, |
| 131338 | 132505 | WO_EQ|WO_IN|WO_IS, 0); |
| 131339 | 132506 | if( pAlt==0 ) continue; |
| 131340 | 132507 | if( pAlt->wtFlags & (TERM_CODED) ) continue; |
| 132508 | + if( (pAlt->eOperator & WO_IN) |
| 132509 | + && (pAlt->pExpr->flags & EP_xIsSelect) |
| 132510 | + && (pAlt->pExpr->x.pSelect->pEList->nExpr>1) |
| 132511 | + ){ |
| 132512 | + continue; |
| 132513 | + } |
| 131341 | 132514 | testcase( pAlt->eOperator & WO_EQ ); |
| 131342 | 132515 | testcase( pAlt->eOperator & WO_IS ); |
| 131343 | 132516 | testcase( pAlt->eOperator & WO_IN ); |
| 131344 | 132517 | VdbeModuleComment((v, "begin transitive constraint")); |
| 131345 | 132518 | sEAlt = *pAlt->pExpr; |
| | @@ -132250,10 +133423,13 @@ |
| 132250 | 133423 | if( ALWAYS(pSrc!=0) ){ |
| 132251 | 133424 | int i; |
| 132252 | 133425 | for(i=0; i<pSrc->nSrc; i++){ |
| 132253 | 133426 | mask |= exprSelectUsage(pMaskSet, pSrc->a[i].pSelect); |
| 132254 | 133427 | mask |= sqlite3WhereExprUsage(pMaskSet, pSrc->a[i].pOn); |
| 133428 | + if( pSrc->a[i].fg.isTabFunc ){ |
| 133429 | + mask |= sqlite3WhereExprListUsage(pMaskSet, pSrc->a[i].u1.pFuncArg); |
| 133430 | + } |
| 132255 | 133431 | } |
| 132256 | 133432 | } |
| 132257 | 133433 | pS = pS->pPrior; |
| 132258 | 133434 | } |
| 132259 | 133435 | return mask; |
| | @@ -132662,11 +133838,11 @@ |
| 132662 | 133838 | transferJoinMarkings(pNew, pExpr); |
| 132663 | 133839 | idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC); |
| 132664 | 133840 | exprAnalyze(pSrc, pWC, idxNew); |
| 132665 | 133841 | } |
| 132666 | 133842 | pTerm = &pWC->a[idxTerm]; |
| 132667 | | - pTerm->wtFlags = TERM_CODED|TERM_VIRTUAL; /* Disable the original */ |
| 133843 | + pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */ |
| 132668 | 133844 | pTerm->eOperator = 0; |
| 132669 | 133845 | } |
| 132670 | 133846 | |
| 132671 | 133847 | /* If there is a vector IN term - e.g. "(a, b) IN (SELECT ...)" - create |
| 132672 | 133848 | ** a virtual term for each vector component. The expression object |
| | @@ -135387,14 +136563,16 @@ |
| 135387 | 136563 | pNew->wsFlags |= WHERE_COLUMN_EQ; |
| 135388 | 136564 | assert( saved_nEq==pNew->u.btree.nEq ); |
| 135389 | 136565 | if( iCol==XN_ROWID |
| 135390 | 136566 | || (iCol>=0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1) |
| 135391 | 136567 | ){ |
| 135392 | | - if( iCol>=0 && pProbe->uniqNotNull==0 ){ |
| 135393 | | - pNew->wsFlags |= WHERE_UNQ_WANTED; |
| 135394 | | - }else{ |
| 136568 | + if( iCol==XN_ROWID || pProbe->uniqNotNull |
| 136569 | + || (pProbe->nKeyCol==1 && pProbe->onError && eOp==WO_EQ) |
| 136570 | + ){ |
| 135395 | 136571 | pNew->wsFlags |= WHERE_ONEROW; |
| 136572 | + }else{ |
| 136573 | + pNew->wsFlags |= WHERE_UNQ_WANTED; |
| 135396 | 136574 | } |
| 135397 | 136575 | } |
| 135398 | 136576 | }else if( eOp & WO_ISNULL ){ |
| 135399 | 136577 | pNew->wsFlags |= WHERE_COLUMN_NULL; |
| 135400 | 136578 | }else if( eOp & (WO_GT|WO_GE) ){ |
| | @@ -137537,10 +138715,11 @@ |
| 137537 | 138715 | ** FROM ... WHERE random()>0; -- eval random() once per row |
| 137538 | 138716 | ** FROM ... WHERE (SELECT random())>0; -- eval random() once overall |
| 137539 | 138717 | */ |
| 137540 | 138718 | for(ii=0; ii<sWLB.pWC->nTerm; ii++){ |
| 137541 | 138719 | WhereTerm *pT = &sWLB.pWC->a[ii]; |
| 138720 | + if( pT->wtFlags & TERM_VIRTUAL ) continue; |
| 137542 | 138721 | if( pT->prereqAll==0 && (nTabList==0 || exprIsDeterministic(pT->pExpr)) ){ |
| 137543 | 138722 | sqlite3ExprIfFalse(pParse, pT->pExpr, pWInfo->iBreak, SQLITE_JUMPIFNULL); |
| 137544 | 138723 | pT->wtFlags |= TERM_CODED; |
| 137545 | 138724 | } |
| 137546 | 138725 | } |
| | @@ -139995,11 +141174,12 @@ |
| 139995 | 141174 | #if defined(YYCOVERAGE) |
| 139996 | 141175 | yycoverage[stateno][iLookAhead] = 1; |
| 139997 | 141176 | #endif |
| 139998 | 141177 | do{ |
| 139999 | 141178 | i = yy_shift_ofst[stateno]; |
| 140000 | | - assert( i>=0 && i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) ); |
| 141179 | + assert( i>=0 ); |
| 141180 | + assert( i+YYNTOKEN<=(int)sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) ); |
| 140001 | 141181 | assert( iLookAhead!=YYNOCODE ); |
| 140002 | 141182 | assert( iLookAhead < YYNTOKEN ); |
| 140003 | 141183 | i += iLookAhead; |
| 140004 | 141184 | if( yy_lookahead[i]!=iLookAhead ){ |
| 140005 | 141185 | #ifdef YYFALLBACK |
| | @@ -140709,10 +141889,14 @@ |
| 140709 | 141889 | } |
| 140710 | 141890 | break; |
| 140711 | 141891 | case 34: /* ccons ::= DEFAULT scanpt ID|INDEXED */ |
| 140712 | 141892 | { |
| 140713 | 141893 | Expr *p = tokenExpr(pParse, TK_STRING, yymsp[0].minor.yy0); |
| 141894 | + if( p ){ |
| 141895 | + sqlite3ExprIdToTrueFalse(p); |
| 141896 | + testcase( p->op==TK_TRUEFALSE && sqlite3ExprTruthValue(p) ); |
| 141897 | + } |
| 140714 | 141898 | sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n); |
| 140715 | 141899 | } |
| 140716 | 141900 | break; |
| 140717 | 141901 | case 35: /* ccons ::= NOT NULL onconf */ |
| 140718 | 141902 | {sqlite3AddNotNull(pParse, yymsp[0].minor.yy4);} |
| | @@ -143602,10 +144786,15 @@ |
| 143602 | 144786 | } |
| 143603 | 144787 | if( rc==SQLITE_OK ){ |
| 143604 | 144788 | sqlite3GlobalConfig.isPCacheInit = 1; |
| 143605 | 144789 | rc = sqlite3OsInit(); |
| 143606 | 144790 | } |
| 144791 | +#ifdef SQLITE_ENABLE_DESERIALIZE |
| 144792 | + if( rc==SQLITE_OK ){ |
| 144793 | + rc = sqlite3MemdbInit(); |
| 144794 | + } |
| 144795 | +#endif |
| 143607 | 144796 | if( rc==SQLITE_OK ){ |
| 143608 | 144797 | sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, |
| 143609 | 144798 | sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage); |
| 143610 | 144799 | sqlite3GlobalConfig.isInit = 1; |
| 143611 | 144800 | #ifdef SQLITE_EXTRA_INIT |
| | @@ -143634,11 +144823,11 @@ |
| 143634 | 144823 | ** reason. So we run it once during initialization. |
| 143635 | 144824 | */ |
| 143636 | 144825 | #ifndef NDEBUG |
| 143637 | 144826 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 143638 | 144827 | /* This section of code's only "output" is via assert() statements. */ |
| 143639 | | - if ( rc==SQLITE_OK ){ |
| 144828 | + if( rc==SQLITE_OK ){ |
| 143640 | 144829 | u64 x = (((u64)1)<<63)-1; |
| 143641 | 144830 | double y; |
| 143642 | 144831 | assert(sizeof(x)==8); |
| 143643 | 144832 | assert(sizeof(x)==sizeof(y)); |
| 143644 | 144833 | memcpy(&y, &x, 8); |
| | @@ -144801,16 +145990,26 @@ |
| 144801 | 145990 | #endif |
| 144802 | 145991 | /* SQLITE_AUTH */ "authorization denied", |
| 144803 | 145992 | /* SQLITE_FORMAT */ 0, |
| 144804 | 145993 | /* SQLITE_RANGE */ "column index out of range", |
| 144805 | 145994 | /* SQLITE_NOTADB */ "file is not a database", |
| 145995 | + /* SQLITE_NOTICE */ "notification message", |
| 145996 | + /* SQLITE_WARNING */ "warning message", |
| 144806 | 145997 | }; |
| 144807 | 145998 | const char *zErr = "unknown error"; |
| 144808 | 145999 | switch( rc ){ |
| 144809 | 146000 | case SQLITE_ABORT_ROLLBACK: { |
| 144810 | 146001 | zErr = "abort due to ROLLBACK"; |
| 144811 | 146002 | break; |
| 146003 | + } |
| 146004 | + case SQLITE_ROW: { |
| 146005 | + zErr = "another row available"; |
| 146006 | + break; |
| 146007 | + } |
| 146008 | + case SQLITE_DONE: { |
| 146009 | + zErr = "no more rows available"; |
| 146010 | + break; |
| 144812 | 146011 | } |
| 144813 | 146012 | default: { |
| 144814 | 146013 | rc &= 0xff; |
| 144815 | 146014 | if( ALWAYS(rc>=0) && rc<ArraySize(aMsg) && aMsg[rc]!=0 ){ |
| 144816 | 146015 | zErr = aMsg[rc]; |
| | @@ -160794,10 +161993,11 @@ |
| 160794 | 161993 | if( rc==SQLITE_OK ){ |
| 160795 | 161994 | sqlite3_bind_int64(pStmt, 1, iBlock); |
| 160796 | 161995 | sqlite3_bind_blob(pStmt, 2, z, n, SQLITE_STATIC); |
| 160797 | 161996 | sqlite3_step(pStmt); |
| 160798 | 161997 | rc = sqlite3_reset(pStmt); |
| 161998 | + sqlite3_bind_null(pStmt, 2); |
| 160799 | 161999 | } |
| 160800 | 162000 | return rc; |
| 160801 | 162001 | } |
| 160802 | 162002 | |
| 160803 | 162003 | /* |
| | @@ -160850,10 +162050,11 @@ |
| 160850 | 162050 | sqlite3_bind_text(pStmt, 5, zEnd, -1, sqlite3_free); |
| 160851 | 162051 | } |
| 160852 | 162052 | sqlite3_bind_blob(pStmt, 6, zRoot, nRoot, SQLITE_STATIC); |
| 160853 | 162053 | sqlite3_step(pStmt); |
| 160854 | 162054 | rc = sqlite3_reset(pStmt); |
| 162055 | + sqlite3_bind_null(pStmt, 6); |
| 160855 | 162056 | } |
| 160856 | 162057 | return rc; |
| 160857 | 162058 | } |
| 160858 | 162059 | |
| 160859 | 162060 | /* |
| | @@ -162329,10 +163530,11 @@ |
| 162329 | 163530 | } |
| 162330 | 163531 | sqlite3_bind_int(pStmt, 1, FTS_STAT_DOCTOTAL); |
| 162331 | 163532 | sqlite3_bind_blob(pStmt, 2, pBlob, nBlob, SQLITE_STATIC); |
| 162332 | 163533 | sqlite3_step(pStmt); |
| 162333 | 163534 | *pRC = sqlite3_reset(pStmt); |
| 163535 | + sqlite3_bind_null(pStmt, 2); |
| 162334 | 163536 | sqlite3_free(a); |
| 162335 | 163537 | } |
| 162336 | 163538 | |
| 162337 | 163539 | /* |
| 162338 | 163540 | ** Merge the entire database so that there is one segment for each |
| | @@ -163517,10 +164719,11 @@ |
| 163517 | 164719 | sqlite3_bind_blob(pChomp, 2, root.a, root.n, SQLITE_STATIC); |
| 163518 | 164720 | sqlite3_bind_int64(pChomp, 3, iAbsLevel); |
| 163519 | 164721 | sqlite3_bind_int(pChomp, 4, iIdx); |
| 163520 | 164722 | sqlite3_step(pChomp); |
| 163521 | 164723 | rc = sqlite3_reset(pChomp); |
| 164724 | + sqlite3_bind_null(pChomp, 2); |
| 163522 | 164725 | } |
| 163523 | 164726 | } |
| 163524 | 164727 | |
| 163525 | 164728 | sqlite3_free(root.a); |
| 163526 | 164729 | sqlite3_free(block.a); |
| | @@ -163596,10 +164799,11 @@ |
| 163596 | 164799 | if( rc==SQLITE_OK ){ |
| 163597 | 164800 | sqlite3_bind_int(pReplace, 1, FTS_STAT_INCRMERGEHINT); |
| 163598 | 164801 | sqlite3_bind_blob(pReplace, 2, pHint->a, pHint->n, SQLITE_STATIC); |
| 163599 | 164802 | sqlite3_step(pReplace); |
| 163600 | 164803 | rc = sqlite3_reset(pReplace); |
| 164804 | + sqlite3_bind_null(pReplace, 2); |
| 163601 | 164805 | } |
| 163602 | 164806 | |
| 163603 | 164807 | return rc; |
| 163604 | 164808 | } |
| 163605 | 164809 | |
| | @@ -164410,11 +165614,10 @@ |
| 164410 | 165614 | sqlite3_value **apVal, /* Array of arguments */ |
| 164411 | 165615 | sqlite_int64 *pRowid /* OUT: The affected (or effected) rowid */ |
| 164412 | 165616 | ){ |
| 164413 | 165617 | Fts3Table *p = (Fts3Table *)pVtab; |
| 164414 | 165618 | int rc = SQLITE_OK; /* Return Code */ |
| 164415 | | - int isRemove = 0; /* True for an UPDATE or DELETE */ |
| 164416 | 165619 | u32 *aSzIns = 0; /* Sizes of inserted documents */ |
| 164417 | 165620 | u32 *aSzDel = 0; /* Sizes of deleted documents */ |
| 164418 | 165621 | int nChng = 0; /* Net change in number of documents */ |
| 164419 | 165622 | int bInsertDone = 0; |
| 164420 | 165623 | |
| | @@ -164508,11 +165711,10 @@ |
| 164508 | 165711 | |
| 164509 | 165712 | /* If this is a DELETE or UPDATE operation, remove the old record. */ |
| 164510 | 165713 | if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){ |
| 164511 | 165714 | assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER ); |
| 164512 | 165715 | rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel); |
| 164513 | | - isRemove = 1; |
| 164514 | 165716 | } |
| 164515 | 165717 | |
| 164516 | 165718 | /* If this is an INSERT or UPDATE operation, insert the new record. */ |
| 164517 | 165719 | if( nArg>1 && rc==SQLITE_OK ){ |
| 164518 | 165720 | int iLangid = sqlite3_value_int(apVal[2 + p->nColumn + 2]); |
| | @@ -164520,11 +165722,11 @@ |
| 164520 | 165722 | rc = fts3InsertData(p, apVal, pRowid); |
| 164521 | 165723 | if( rc==SQLITE_CONSTRAINT && p->zContentTbl==0 ){ |
| 164522 | 165724 | rc = FTS_CORRUPT_VTAB; |
| 164523 | 165725 | } |
| 164524 | 165726 | } |
| 164525 | | - if( rc==SQLITE_OK && (!isRemove || *pRowid!=p->iPrevDocid ) ){ |
| 165727 | + if( rc==SQLITE_OK ){ |
| 164526 | 165728 | rc = fts3PendingTermsDocid(p, 0, iLangid, *pRowid); |
| 164527 | 165729 | } |
| 164528 | 165730 | if( rc==SQLITE_OK ){ |
| 164529 | 165731 | assert( p->iPrevDocid==*pRowid ); |
| 164530 | 165732 | rc = fts3InsertTerms(p, iLangid, apVal, aSzIns); |
| | @@ -167828,10 +169030,11 @@ |
| 167828 | 169030 | } |
| 167829 | 169031 | sqlite3_bind_blob(p, 2, pNode->zData, pRtree->iNodeSize, SQLITE_STATIC); |
| 167830 | 169032 | sqlite3_step(p); |
| 167831 | 169033 | pNode->isDirty = 0; |
| 167832 | 169034 | rc = sqlite3_reset(p); |
| 169035 | + sqlite3_bind_null(p, 2); |
| 167833 | 169036 | if( pNode->iNode==0 && rc==SQLITE_OK ){ |
| 167834 | 169037 | pNode->iNode = sqlite3_last_insert_rowid(pRtree->db); |
| 167835 | 169038 | nodeHashInsert(pRtree, pNode); |
| 167836 | 169039 | } |
| 167837 | 169040 | } |
| | @@ -179823,11 +181026,11 @@ |
| 179823 | 181026 | SessionTable *pTab /* Table that change applies to */ |
| 179824 | 181027 | ){ |
| 179825 | 181028 | int iHash; |
| 179826 | 181029 | int bNull = 0; |
| 179827 | 181030 | int rc = SQLITE_OK; |
| 179828 | | - SessionStat1Ctx stat1; |
| 181031 | + SessionStat1Ctx stat1 = {0}; |
| 179829 | 181032 | |
| 179830 | 181033 | if( pSession->rc ) return; |
| 179831 | 181034 | |
| 179832 | 181035 | /* Load table details if required */ |
| 179833 | 181036 | if( sessionInitTable(pSession, pTab) ) return; |
| | @@ -181428,30 +182631,37 @@ |
| 181428 | 182631 | for(i=0; i<nCol && rc==SQLITE_OK; i++){ |
| 181429 | 182632 | int eType = 0; /* Type of value (SQLITE_NULL, TEXT etc.) */ |
| 181430 | 182633 | if( abPK && abPK[i]==0 ) continue; |
| 181431 | 182634 | rc = sessionInputBuffer(pIn, 9); |
| 181432 | 182635 | if( rc==SQLITE_OK ){ |
| 181433 | | - eType = pIn->aData[pIn->iNext++]; |
| 181434 | | - } |
| 181435 | | - |
| 181436 | | - assert( apOut[i]==0 ); |
| 181437 | | - if( eType ){ |
| 181438 | | - apOut[i] = sqlite3ValueNew(0); |
| 181439 | | - if( !apOut[i] ) rc = SQLITE_NOMEM; |
| 182636 | + if( pIn->iNext>=pIn->nData ){ |
| 182637 | + rc = SQLITE_CORRUPT_BKPT; |
| 182638 | + }else{ |
| 182639 | + eType = pIn->aData[pIn->iNext++]; |
| 182640 | + assert( apOut[i]==0 ); |
| 182641 | + if( eType ){ |
| 182642 | + apOut[i] = sqlite3ValueNew(0); |
| 182643 | + if( !apOut[i] ) rc = SQLITE_NOMEM; |
| 182644 | + } |
| 182645 | + } |
| 181440 | 182646 | } |
| 181441 | 182647 | |
| 181442 | 182648 | if( rc==SQLITE_OK ){ |
| 181443 | 182649 | u8 *aVal = &pIn->aData[pIn->iNext]; |
| 181444 | 182650 | if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){ |
| 181445 | 182651 | int nByte; |
| 181446 | 182652 | pIn->iNext += sessionVarintGet(aVal, &nByte); |
| 181447 | 182653 | rc = sessionInputBuffer(pIn, nByte); |
| 181448 | 182654 | if( rc==SQLITE_OK ){ |
| 181449 | | - u8 enc = (eType==SQLITE_TEXT ? SQLITE_UTF8 : 0); |
| 181450 | | - rc = sessionValueSetStr(apOut[i],&pIn->aData[pIn->iNext],nByte,enc); |
| 182655 | + if( nByte<0 || nByte>pIn->nData-pIn->iNext ){ |
| 182656 | + rc = SQLITE_CORRUPT_BKPT; |
| 182657 | + }else{ |
| 182658 | + u8 enc = (eType==SQLITE_TEXT ? SQLITE_UTF8 : 0); |
| 182659 | + rc = sessionValueSetStr(apOut[i],&pIn->aData[pIn->iNext],nByte,enc); |
| 182660 | + pIn->iNext += nByte; |
| 182661 | + } |
| 181451 | 182662 | } |
| 181452 | | - pIn->iNext += nByte; |
| 181453 | 182663 | } |
| 181454 | 182664 | if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){ |
| 181455 | 182665 | sqlite3_int64 v = sessionGetI64(aVal); |
| 181456 | 182666 | if( eType==SQLITE_INTEGER ){ |
| 181457 | 182667 | sqlite3VdbeMemSetInt64(apOut[i], v); |
| | @@ -181487,12 +182697,23 @@ |
| 181487 | 182697 | int nRead = 0; |
| 181488 | 182698 | |
| 181489 | 182699 | rc = sessionInputBuffer(pIn, 9); |
| 181490 | 182700 | if( rc==SQLITE_OK ){ |
| 181491 | 182701 | nRead += sessionVarintGet(&pIn->aData[pIn->iNext + nRead], &nCol); |
| 181492 | | - rc = sessionInputBuffer(pIn, nRead+nCol+100); |
| 181493 | | - nRead += nCol; |
| 182702 | + /* The hard upper limit for the number of columns in an SQLite |
| 182703 | + ** database table is, according to sqliteLimit.h, 32676. So |
| 182704 | + ** consider any table-header that purports to have more than 65536 |
| 182705 | + ** columns to be corrupt. This is convenient because otherwise, |
| 182706 | + ** if the (nCol>65536) condition below were omitted, a sufficiently |
| 182707 | + ** large value for nCol may cause nRead to wrap around and become |
| 182708 | + ** negative. Leading to a crash. */ |
| 182709 | + if( nCol<0 || nCol>65536 ){ |
| 182710 | + rc = SQLITE_CORRUPT_BKPT; |
| 182711 | + }else{ |
| 182712 | + rc = sessionInputBuffer(pIn, nRead+nCol+100); |
| 182713 | + nRead += nCol; |
| 182714 | + } |
| 181494 | 182715 | } |
| 181495 | 182716 | |
| 181496 | 182717 | while( rc==SQLITE_OK ){ |
| 181497 | 182718 | while( (pIn->iNext + nRead)<pIn->nData && pIn->aData[pIn->iNext + nRead] ){ |
| 181498 | 182719 | nRead++; |
| | @@ -181565,15 +182786,19 @@ |
| 181565 | 182786 | rc = sessionChangesetBufferTblhdr(&p->in, &nCopy); |
| 181566 | 182787 | if( rc==SQLITE_OK ){ |
| 181567 | 182788 | int nByte; |
| 181568 | 182789 | int nVarint; |
| 181569 | 182790 | nVarint = sessionVarintGet(&p->in.aData[p->in.iNext], &p->nCol); |
| 181570 | | - nCopy -= nVarint; |
| 181571 | | - p->in.iNext += nVarint; |
| 181572 | | - nByte = p->nCol * sizeof(sqlite3_value*) * 2 + nCopy; |
| 181573 | | - p->tblhdr.nBuf = 0; |
| 181574 | | - sessionBufferGrow(&p->tblhdr, nByte, &rc); |
| 182791 | + if( p->nCol>0 ){ |
| 182792 | + nCopy -= nVarint; |
| 182793 | + p->in.iNext += nVarint; |
| 182794 | + nByte = p->nCol * sizeof(sqlite3_value*) * 2 + nCopy; |
| 182795 | + p->tblhdr.nBuf = 0; |
| 182796 | + sessionBufferGrow(&p->tblhdr, nByte, &rc); |
| 182797 | + }else{ |
| 182798 | + rc = SQLITE_CORRUPT_BKPT; |
| 182799 | + } |
| 181575 | 182800 | } |
| 181576 | 182801 | |
| 181577 | 182802 | if( rc==SQLITE_OK ){ |
| 181578 | 182803 | int iPK = sizeof(sqlite3_value*)*p->nCol*2; |
| 181579 | 182804 | memset(p->tblhdr.aBuf, 0, iPK); |
| | @@ -181646,10 +182871,17 @@ |
| 181646 | 182871 | if( (p->rc = sessionInputBuffer(&p->in, 2)) ) return p->rc; |
| 181647 | 182872 | p->in.iCurrent = p->in.iNext; |
| 181648 | 182873 | if( p->in.iNext>=p->in.nData ) return SQLITE_DONE; |
| 181649 | 182874 | op = p->in.aData[p->in.iNext++]; |
| 181650 | 182875 | } |
| 182876 | + |
| 182877 | + if( p->zTab==0 ){ |
| 182878 | + /* The first record in the changeset is not a table header. Must be a |
| 182879 | + ** corrupt changeset. */ |
| 182880 | + assert( p->in.iNext==1 ); |
| 182881 | + return (p->rc = SQLITE_CORRUPT_BKPT); |
| 182882 | + } |
| 181651 | 182883 | |
| 181652 | 182884 | p->op = op; |
| 181653 | 182885 | p->bIndirect = p->in.aData[p->in.iNext++]; |
| 181654 | 182886 | if( p->op!=SQLITE_UPDATE && p->op!=SQLITE_DELETE && p->op!=SQLITE_INSERT ){ |
| 181655 | 182887 | return (p->rc = SQLITE_CORRUPT_BKPT); |
| | @@ -181689,13 +182921,13 @@ |
| 181689 | 182921 | ** modified fields are present in the new.* record. The old.* record |
| 181690 | 182922 | ** is currently completely empty. This block shifts the PK fields from |
| 181691 | 182923 | ** new.* to old.*, to accommodate the code that reads these arrays. */ |
| 181692 | 182924 | for(i=0; i<p->nCol; i++){ |
| 181693 | 182925 | assert( p->apValue[i]==0 ); |
| 181694 | | - assert( p->abPK[i]==0 || p->apValue[i+p->nCol] ); |
| 181695 | 182926 | if( p->abPK[i] ){ |
| 181696 | 182927 | p->apValue[i] = p->apValue[i+p->nCol]; |
| 182928 | + if( p->apValue[i]==0 ) return (p->rc = SQLITE_CORRUPT_BKPT); |
| 181697 | 182929 | p->apValue[i+p->nCol] = 0; |
| 181698 | 182930 | } |
| 181699 | 182931 | } |
| 181700 | 182932 | } |
| 181701 | 182933 | } |
| | @@ -182416,11 +183648,17 @@ |
| 182416 | 183648 | |
| 182417 | 183649 | for(i=0; rc==SQLITE_OK && i<nCol; i++){ |
| 182418 | 183650 | if( !abPK || abPK[i] ){ |
| 182419 | 183651 | sqlite3_value *pVal; |
| 182420 | 183652 | (void)xValue(pIter, i, &pVal); |
| 182421 | | - rc = sessionBindValue(pStmt, i+1, pVal); |
| 183653 | + if( pVal==0 ){ |
| 183654 | + /* The value in the changeset was "undefined". This indicates a |
| 183655 | + ** corrupt changeset blob. */ |
| 183656 | + rc = SQLITE_CORRUPT_BKPT; |
| 183657 | + }else{ |
| 183658 | + rc = sessionBindValue(pStmt, i+1, pVal); |
| 183659 | + } |
| 182422 | 183660 | } |
| 182423 | 183661 | } |
| 182424 | 183662 | return rc; |
| 182425 | 183663 | } |
| 182426 | 183664 | |
| | @@ -188053,11 +189291,12 @@ |
| 188053 | 189291 | #if defined(fts5YYCOVERAGE) |
| 188054 | 189292 | fts5yycoverage[stateno][iLookAhead] = 1; |
| 188055 | 189293 | #endif |
| 188056 | 189294 | do{ |
| 188057 | 189295 | i = fts5yy_shift_ofst[stateno]; |
| 188058 | | - assert( i>=0 && i+fts5YYNFTS5TOKEN<=sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0]) ); |
| 189296 | + assert( i>=0 ); |
| 189297 | + assert( i+fts5YYNFTS5TOKEN<=(int)sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0]) ); |
| 188059 | 189298 | assert( iLookAhead!=fts5YYNOCODE ); |
| 188060 | 189299 | assert( iLookAhead < fts5YYNFTS5TOKEN ); |
| 188061 | 189300 | i += iLookAhead; |
| 188062 | 189301 | if( fts5yy_lookahead[i]!=iLookAhead ){ |
| 188063 | 189302 | #ifdef fts5YYFALLBACK |
| | @@ -192495,11 +193734,11 @@ |
| 192495 | 193734 | if( sCtx.pPhrase==0 ){ |
| 192496 | 193735 | /* This happens when parsing a token or quoted phrase that contains |
| 192497 | 193736 | ** no token characters at all. (e.g ... MATCH '""'). */ |
| 192498 | 193737 | sCtx.pPhrase = sqlite3Fts5MallocZero(&pParse->rc, sizeof(Fts5ExprPhrase)); |
| 192499 | 193738 | }else if( sCtx.pPhrase->nTerm ){ |
| 192500 | | - sCtx.pPhrase->aTerm[sCtx.pPhrase->nTerm-1].bPrefix = bPrefix; |
| 193739 | + sCtx.pPhrase->aTerm[sCtx.pPhrase->nTerm-1].bPrefix = (u8)bPrefix; |
| 192501 | 193740 | } |
| 192502 | 193741 | pParse->apPhrase[pParse->nPhrase-1] = sCtx.pPhrase; |
| 192503 | 193742 | } |
| 192504 | 193743 | |
| 192505 | 193744 | return sCtx.pPhrase; |
| | @@ -194958,10 +196197,11 @@ |
| 194958 | 196197 | |
| 194959 | 196198 | sqlite3_bind_int64(p->pWriter, 1, iRowid); |
| 194960 | 196199 | sqlite3_bind_blob(p->pWriter, 2, pData, nData, SQLITE_STATIC); |
| 194961 | 196200 | sqlite3_step(p->pWriter); |
| 194962 | 196201 | p->rc = sqlite3_reset(p->pWriter); |
| 196202 | + sqlite3_bind_null(p->pWriter, 2); |
| 194963 | 196203 | } |
| 194964 | 196204 | |
| 194965 | 196205 | /* |
| 194966 | 196206 | ** Execute the following SQL: |
| 194967 | 196207 | ** |
| | @@ -196586,10 +197826,11 @@ |
| 196586 | 197826 | i64 val = sqlite3_column_int(pIdxSelect, 0); |
| 196587 | 197827 | iPg = (int)(val>>1); |
| 196588 | 197828 | bDlidx = (val & 0x0001); |
| 196589 | 197829 | } |
| 196590 | 197830 | p->rc = sqlite3_reset(pIdxSelect); |
| 197831 | + sqlite3_bind_null(pIdxSelect, 2); |
| 196591 | 197832 | |
| 196592 | 197833 | if( iPg<pSeg->pgnoFirst ){ |
| 196593 | 197834 | iPg = pSeg->pgnoFirst; |
| 196594 | 197835 | bDlidx = 0; |
| 196595 | 197836 | } |
| | @@ -197798,10 +199039,11 @@ |
| 197798 | 199039 | u8 aBlob[2] = {0xff, 0xff}; |
| 197799 | 199040 | sqlite3_bind_int(pIdxSelect, 1, iSegid); |
| 197800 | 199041 | sqlite3_bind_blob(pIdxSelect, 2, aBlob, 2, SQLITE_STATIC); |
| 197801 | 199042 | assert( sqlite3_step(pIdxSelect)!=SQLITE_ROW ); |
| 197802 | 199043 | p->rc = sqlite3_reset(pIdxSelect); |
| 199044 | + sqlite3_bind_null(pIdxSelect, 2); |
| 197803 | 199045 | } |
| 197804 | 199046 | } |
| 197805 | 199047 | #endif |
| 197806 | 199048 | } |
| 197807 | 199049 | } |
| | @@ -197924,10 +199166,11 @@ |
| 197924 | 199166 | /* sqlite3_bind_int(p->pIdxWriter, 1, pWriter->iSegid); */ |
| 197925 | 199167 | sqlite3_bind_blob(p->pIdxWriter, 2, z, pWriter->btterm.n, SQLITE_STATIC); |
| 197926 | 199168 | sqlite3_bind_int64(p->pIdxWriter, 3, bFlag + ((i64)pWriter->iBtPage<<1)); |
| 197927 | 199169 | sqlite3_step(p->pIdxWriter); |
| 197928 | 199170 | p->rc = sqlite3_reset(p->pIdxWriter); |
| 199171 | + sqlite3_bind_null(p->pIdxWriter, 2); |
| 197929 | 199172 | } |
| 197930 | 199173 | pWriter->iBtPage = 0; |
| 197931 | 199174 | } |
| 197932 | 199175 | |
| 197933 | 199176 | /* |
| | @@ -203331,11 +204574,11 @@ |
| 203331 | 204574 | int nArg, /* Number of args */ |
| 203332 | 204575 | sqlite3_value **apUnused /* Function arguments */ |
| 203333 | 204576 | ){ |
| 203334 | 204577 | assert( nArg==0 ); |
| 203335 | 204578 | UNUSED_PARAM2(nArg, apUnused); |
| 203336 | | - sqlite3_result_text(pCtx, "fts5: 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2171d", -1, SQLITE_TRANSIENT); |
| 204579 | + sqlite3_result_text(pCtx, "fts5: 2018-03-16 20:23:01 d75e67654aa9620b9617786553a002f54e8c6dcbbcc58948a06bd98a0916d75a", -1, SQLITE_TRANSIENT); |
| 203337 | 204580 | } |
| 203338 | 204581 | |
| 203339 | 204582 | static int fts5Init(sqlite3 *db){ |
| 203340 | 204583 | static const sqlite3_module fts5Mod = { |
| 203341 | 204584 | /* iVersion */ 2, |
| | @@ -203907,10 +205150,11 @@ |
| 203907 | 205150 | if( rc==SQLITE_OK ){ |
| 203908 | 205151 | sqlite3_bind_int64(pReplace, 1, iRowid); |
| 203909 | 205152 | sqlite3_bind_blob(pReplace, 2, pBuf->p, pBuf->n, SQLITE_STATIC); |
| 203910 | 205153 | sqlite3_step(pReplace); |
| 203911 | 205154 | rc = sqlite3_reset(pReplace); |
| 205155 | + sqlite3_bind_null(pReplace, 2); |
| 203912 | 205156 | } |
| 203913 | 205157 | } |
| 203914 | 205158 | return rc; |
| 203915 | 205159 | } |
| 203916 | 205160 | |
| | @@ -204567,10 +205811,11 @@ |
| 204567 | 205811 | }else{ |
| 204568 | 205812 | sqlite3_bind_int(pReplace, 2, iVal); |
| 204569 | 205813 | } |
| 204570 | 205814 | sqlite3_step(pReplace); |
| 204571 | 205815 | rc = sqlite3_reset(pReplace); |
| 205816 | + sqlite3_bind_null(pReplace, 1); |
| 204572 | 205817 | } |
| 204573 | 205818 | if( rc==SQLITE_OK && pVal ){ |
| 204574 | 205819 | int iNew = p->pConfig->iCookie + 1; |
| 204575 | 205820 | rc = sqlite3Fts5IndexSetCookie(p->pIndex, iNew); |
| 204576 | 205821 | if( rc==SQLITE_OK ){ |
| | @@ -207599,12 +208844,12 @@ |
| 207599 | 208844 | } |
| 207600 | 208845 | #endif /* SQLITE_CORE */ |
| 207601 | 208846 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 207602 | 208847 | |
| 207603 | 208848 | /************** End of stmt.c ************************************************/ |
| 207604 | | -#if __LINE__!=207604 |
| 208849 | +#if __LINE__!=208849 |
| 207605 | 208850 | #undef SQLITE_SOURCE_ID |
| 207606 | | -#define SQLITE_SOURCE_ID "2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2alt2" |
| 208851 | +#define SQLITE_SOURCE_ID "2018-03-17 16:26:36 442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec47703alt2" |
| 207607 | 208852 | #endif |
| 207608 | 208853 | /* Return the source-id for this library */ |
| 207609 | 208854 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 207610 | 208855 | /************************** End of sqlite3.c ******************************/ |
| 207611 | 208856 | |