| | @@ -135,11 +135,11 @@ |
| 135 | 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | 137 | */ |
| 138 | 138 | #define SQLITE_VERSION "3.8.3" |
| 139 | 139 | #define SQLITE_VERSION_NUMBER 3008003 |
| 140 | | -#define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3" |
| 140 | +#define SQLITE_SOURCE_ID "2013-12-17 16:32:56 93121d3097a43997af3c0de65bd9bd7663845fa2" |
| 141 | 141 | |
| 142 | 142 | /* |
| 143 | 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | 145 | ** |
| | @@ -817,19 +817,33 @@ |
| 817 | 817 | ** to the [sqlite3_file] object associated with a particular database |
| 818 | 818 | ** connection. See the [sqlite3_file_control()] documentation for |
| 819 | 819 | ** additional information. |
| 820 | 820 | ** |
| 821 | 821 | ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] |
| 822 | | -** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by |
| 823 | | -** SQLite and sent to all VFSes in place of a call to the xSync method |
| 824 | | -** when the database connection has [PRAGMA synchronous] set to OFF.)^ |
| 825 | | -** Some specialized VFSes need this signal in order to operate correctly |
| 826 | | -** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most |
| 827 | | -** VFSes do not need this signal and should silently ignore this opcode. |
| 828 | | -** Applications should not call [sqlite3_file_control()] with this |
| 829 | | -** opcode as doing so may disrupt the operation of the specialized VFSes |
| 830 | | -** that do require it. |
| 822 | +** No longer in use. |
| 823 | +** |
| 824 | +** <li>[[SQLITE_FCNTL_SYNC]] |
| 825 | +** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and |
| 826 | +** sent to the VFS immediately before the xSync method is invoked on a |
| 827 | +** database file descriptor. Or, if the xSync method is not invoked |
| 828 | +** because the user has configured SQLite with |
| 829 | +** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place |
| 830 | +** of the xSync method. In most cases, the pointer argument passed with |
| 831 | +** this file-control is NULL. However, if the database file is being synced |
| 832 | +** as part of a multi-database commit, the argument points to a nul-terminated |
| 833 | +** string containing the transactions master-journal file name. VFSes that |
| 834 | +** do not need this signal should silently ignore this opcode. Applications |
| 835 | +** should not call [sqlite3_file_control()] with this opcode as doing so may |
| 836 | +** disrupt the operation of the specialized VFSes that do require it. |
| 837 | +** |
| 838 | +** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]] |
| 839 | +** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite |
| 840 | +** and sent to the VFS after a transaction has been committed immediately |
| 841 | +** but before the database is unlocked. VFSes that do not need this signal |
| 842 | +** should silently ignore this opcode. Applications should not call |
| 843 | +** [sqlite3_file_control()] with this opcode as doing so may disrupt the |
| 844 | +** operation of the specialized VFSes that do require it. |
| 831 | 845 | ** |
| 832 | 846 | ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] |
| 833 | 847 | ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic |
| 834 | 848 | ** retry counts and intervals for certain disk I/O operations for the |
| 835 | 849 | ** windows [VFS] in order to provide robustness in the presence of |
| | @@ -976,10 +990,12 @@ |
| 976 | 990 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 977 | 991 | #define SQLITE_FCNTL_TEMPFILENAME 16 |
| 978 | 992 | #define SQLITE_FCNTL_MMAP_SIZE 18 |
| 979 | 993 | #define SQLITE_FCNTL_TRACE 19 |
| 980 | 994 | #define SQLITE_FCNTL_HAS_MOVED 20 |
| 995 | +#define SQLITE_FCNTL_SYNC 21 |
| 996 | +#define SQLITE_FCNTL_COMMIT_PHASETWO 22 |
| 981 | 997 | |
| 982 | 998 | /* |
| 983 | 999 | ** CAPI3REF: Mutex Handle |
| 984 | 1000 | ** |
| 985 | 1001 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| | @@ -3992,19 +4008,28 @@ |
| 3992 | 4008 | ** parameter is less than -1 or greater than 127 then the behavior is |
| 3993 | 4009 | ** undefined. |
| 3994 | 4010 | ** |
| 3995 | 4011 | ** ^The fourth parameter, eTextRep, specifies what |
| 3996 | 4012 | ** [SQLITE_UTF8 | text encoding] this SQL function prefers for |
| 3997 | | -** its parameters. Every SQL function implementation must be able to work |
| 3998 | | -** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be |
| 3999 | | -** more efficient with one encoding than another. ^An application may |
| 4000 | | -** invoke sqlite3_create_function() or sqlite3_create_function16() multiple |
| 4001 | | -** times with the same function but with different values of eTextRep. |
| 4013 | +** its parameters. The application should set this parameter to |
| 4014 | +** [SQLITE_UTF16LE] if the function implementation invokes |
| 4015 | +** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the |
| 4016 | +** implementation invokes [sqlite3_value_text16be()] on an input, or |
| 4017 | +** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8] |
| 4018 | +** otherwise. ^The same SQL function may be registered multiple times using |
| 4019 | +** different preferred text encodings, with different implementations for |
| 4020 | +** each encoding. |
| 4002 | 4021 | ** ^When multiple implementations of the same function are available, SQLite |
| 4003 | 4022 | ** will pick the one that involves the least amount of data conversion. |
| 4004 | | -** If there is only a single implementation which does not care what text |
| 4005 | | -** encoding is used, then the fourth argument should be [SQLITE_ANY]. |
| 4023 | +** |
| 4024 | +** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC] |
| 4025 | +** to signal that the function will always return the same result given |
| 4026 | +** the same inputs within a single SQL statement. Most SQL functions are |
| 4027 | +** deterministic. The built-in [random()] SQL function is an example of a |
| 4028 | +** function that is not deterministic. The SQLite query planner is able to |
| 4029 | +** perform additional optimizations on deterministic functions, so use |
| 4030 | +** of the [SQLITE_DETERMINISTIC] flag is recommended where possible. |
| 4006 | 4031 | ** |
| 4007 | 4032 | ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
| 4008 | 4033 | ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
| 4009 | 4034 | ** |
| 4010 | 4035 | ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are |
| | @@ -4086,13 +4111,23 @@ |
| 4086 | 4111 | */ |
| 4087 | 4112 | #define SQLITE_UTF8 1 |
| 4088 | 4113 | #define SQLITE_UTF16LE 2 |
| 4089 | 4114 | #define SQLITE_UTF16BE 3 |
| 4090 | 4115 | #define SQLITE_UTF16 4 /* Use native byte order */ |
| 4091 | | -#define SQLITE_ANY 5 /* sqlite3_create_function only */ |
| 4116 | +#define SQLITE_ANY 5 /* Deprecated */ |
| 4092 | 4117 | #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ |
| 4093 | 4118 | |
| 4119 | +/* |
| 4120 | +** CAPI3REF: Function Flags |
| 4121 | +** |
| 4122 | +** These constants may be ORed together with the |
| 4123 | +** [SQLITE_UTF8 | preferred text encoding] as the fourth argument |
| 4124 | +** to [sqlite3_create_function()], [sqlite3_create_function16()], or |
| 4125 | +** [sqlite3_create_function_v2()]. |
| 4126 | +*/ |
| 4127 | +#define SQLITE_DETERMINISTIC 0x800 |
| 4128 | + |
| 4094 | 4129 | /* |
| 4095 | 4130 | ** CAPI3REF: Deprecated Functions |
| 4096 | 4131 | ** DEPRECATED |
| 4097 | 4132 | ** |
| 4098 | 4133 | ** These functions are [deprecated]. In order to maintain |
| | @@ -8590,10 +8625,11 @@ |
| 8590 | 8625 | typedef struct Lookaside Lookaside; |
| 8591 | 8626 | typedef struct LookasideSlot LookasideSlot; |
| 8592 | 8627 | typedef struct Module Module; |
| 8593 | 8628 | typedef struct NameContext NameContext; |
| 8594 | 8629 | typedef struct Parse Parse; |
| 8630 | +typedef struct PrintfArguments PrintfArguments; |
| 8595 | 8631 | typedef struct RowSet RowSet; |
| 8596 | 8632 | typedef struct Savepoint Savepoint; |
| 8597 | 8633 | typedef struct Select Select; |
| 8598 | 8634 | typedef struct SelectDest SelectDest; |
| 8599 | 8635 | typedef struct SrcList SrcList; |
| | @@ -9448,10 +9484,11 @@ |
| 9448 | 9484 | SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag); |
| 9449 | 9485 | #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0) |
| 9450 | 9486 | SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno); |
| 9451 | 9487 | SQLITE_PRIVATE void sqlite3PagerRef(DbPage*); |
| 9452 | 9488 | SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*); |
| 9489 | +SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*); |
| 9453 | 9490 | |
| 9454 | 9491 | /* Operations on page references. */ |
| 9455 | 9492 | SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*); |
| 9456 | 9493 | SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*); |
| 9457 | 9494 | SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int); |
| | @@ -9462,11 +9499,11 @@ |
| 9462 | 9499 | /* Functions used to manage pager transactions and savepoints. */ |
| 9463 | 9500 | SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*); |
| 9464 | 9501 | SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int); |
| 9465 | 9502 | SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int); |
| 9466 | 9503 | SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*); |
| 9467 | | -SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager); |
| 9504 | +SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster); |
| 9468 | 9505 | SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*); |
| 9469 | 9506 | SQLITE_PRIVATE int sqlite3PagerRollback(Pager*); |
| 9470 | 9507 | SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n); |
| 9471 | 9508 | SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint); |
| 9472 | 9509 | SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager); |
| | @@ -12043,14 +12080,24 @@ |
| 12043 | 12080 | SQLITE_PRIVATE int sqlite3IsNaN(double); |
| 12044 | 12081 | #else |
| 12045 | 12082 | # define sqlite3IsNaN(X) 0 |
| 12046 | 12083 | #endif |
| 12047 | 12084 | |
| 12048 | | -SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, int, const char*, va_list); |
| 12049 | | -#ifndef SQLITE_OMIT_TRACE |
| 12050 | | -SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, const char*, ...); |
| 12051 | | -#endif |
| 12085 | +/* |
| 12086 | +** An instance of the following structure holds information about SQL |
| 12087 | +** functions arguments that are the parameters to the printf() function. |
| 12088 | +*/ |
| 12089 | +struct PrintfArguments { |
| 12090 | + int nArg; /* Total number of arguments */ |
| 12091 | + int nUsed; /* Number of arguments used so far */ |
| 12092 | + sqlite3_value **apArg; /* The argument values */ |
| 12093 | +}; |
| 12094 | + |
| 12095 | +#define SQLITE_PRINTF_INTERNAL 0x01 |
| 12096 | +#define SQLITE_PRINTF_SQLFUNC 0x02 |
| 12097 | +SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list); |
| 12098 | +SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...); |
| 12052 | 12099 | SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 12053 | 12100 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
| 12054 | 12101 | SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...); |
| 12055 | 12102 | #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) |
| 12056 | 12103 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...); |
| | @@ -12436,10 +12483,11 @@ |
| 12436 | 12483 | |
| 12437 | 12484 | SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8); |
| 12438 | 12485 | SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8); |
| 12439 | 12486 | SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 12440 | 12487 | void(*)(void*)); |
| 12488 | +SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value*); |
| 12441 | 12489 | SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*); |
| 12442 | 12490 | SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *); |
| 12443 | 12491 | SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8); |
| 12444 | 12492 | SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); |
| 12445 | 12493 | SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); |
| | @@ -19894,14 +19942,31 @@ |
| 19894 | 19942 | } |
| 19895 | 19943 | |
| 19896 | 19944 | /* |
| 19897 | 19945 | ** Set the StrAccum object to an error mode. |
| 19898 | 19946 | */ |
| 19899 | | -void setStrAccumError(StrAccum *p, u8 eError){ |
| 19947 | +static void setStrAccumError(StrAccum *p, u8 eError){ |
| 19900 | 19948 | p->accError = eError; |
| 19901 | 19949 | p->nAlloc = 0; |
| 19902 | 19950 | } |
| 19951 | + |
| 19952 | +/* |
| 19953 | +** Extra argument values from a PrintfArguments object |
| 19954 | +*/ |
| 19955 | +static sqlite3_int64 getIntArg(PrintfArguments *p){ |
| 19956 | + if( p->nArg<=p->nUsed ) return 0; |
| 19957 | + return sqlite3_value_int64(p->apArg[p->nUsed++]); |
| 19958 | +} |
| 19959 | +static double getDoubleArg(PrintfArguments *p){ |
| 19960 | + if( p->nArg<=p->nUsed ) return 0.0; |
| 19961 | + return sqlite3_value_double(p->apArg[p->nUsed++]); |
| 19962 | +} |
| 19963 | +static char *getTextArg(PrintfArguments *p){ |
| 19964 | + if( p->nArg<=p->nUsed ) return 0; |
| 19965 | + return (char*)sqlite3_value_text(p->apArg[p->nUsed++]); |
| 19966 | +} |
| 19967 | + |
| 19903 | 19968 | |
| 19904 | 19969 | /* |
| 19905 | 19970 | ** On machines with a small stack size, you can redefine the |
| 19906 | 19971 | ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired. |
| 19907 | 19972 | */ |
| | @@ -19912,14 +19977,14 @@ |
| 19912 | 19977 | |
| 19913 | 19978 | /* |
| 19914 | 19979 | ** Render a string given by "fmt" into the StrAccum object. |
| 19915 | 19980 | */ |
| 19916 | 19981 | SQLITE_PRIVATE void sqlite3VXPrintf( |
| 19917 | | - StrAccum *pAccum, /* Accumulate results here */ |
| 19918 | | - int useExtended, /* Allow extended %-conversions */ |
| 19919 | | - const char *fmt, /* Format string */ |
| 19920 | | - va_list ap /* arguments */ |
| 19982 | + StrAccum *pAccum, /* Accumulate results here */ |
| 19983 | + u32 bFlags, /* SQLITE_PRINTF_* flags */ |
| 19984 | + const char *fmt, /* Format string */ |
| 19985 | + va_list ap /* arguments */ |
| 19921 | 19986 | ){ |
| 19922 | 19987 | int c; /* Next character in the format string */ |
| 19923 | 19988 | char *bufpt; /* Pointer to the conversion buffer */ |
| 19924 | 19989 | int precision; /* Precision of the current field */ |
| 19925 | 19990 | int length; /* Length of the field */ |
| | @@ -19933,10 +19998,12 @@ |
| 19933 | 19998 | etByte flag_zeropad; /* True if field width constant starts with zero */ |
| 19934 | 19999 | etByte flag_long; /* True if "l" flag is present */ |
| 19935 | 20000 | etByte flag_longlong; /* True if the "ll" flag is present */ |
| 19936 | 20001 | etByte done; /* Loop termination flag */ |
| 19937 | 20002 | etByte xtype = 0; /* Conversion paradigm */ |
| 20003 | + u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */ |
| 20004 | + u8 useIntern; /* Ok to use internal conversions (ex: %T) */ |
| 19938 | 20005 | char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ |
| 19939 | 20006 | sqlite_uint64 longvalue; /* Value for integer types */ |
| 19940 | 20007 | LONGDOUBLE_TYPE realvalue; /* Value for real types */ |
| 19941 | 20008 | const et_info *infop; /* Pointer to the appropriate info structure */ |
| 19942 | 20009 | char *zOut; /* Rendering buffer */ |
| | @@ -19947,13 +20014,22 @@ |
| 19947 | 20014 | int nsd; /* Number of significant digits returned */ |
| 19948 | 20015 | double rounder; /* Used for rounding floating point values */ |
| 19949 | 20016 | etByte flag_dp; /* True if decimal point should be shown */ |
| 19950 | 20017 | etByte flag_rtz; /* True if trailing zeros should be removed */ |
| 19951 | 20018 | #endif |
| 20019 | + PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ |
| 19952 | 20020 | char buf[etBUFSIZE]; /* Conversion buffer */ |
| 19953 | 20021 | |
| 19954 | 20022 | bufpt = 0; |
| 20023 | + if( bFlags ){ |
| 20024 | + if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ |
| 20025 | + pArgList = va_arg(ap, PrintfArguments*); |
| 20026 | + } |
| 20027 | + useIntern = bFlags & SQLITE_PRINTF_INTERNAL; |
| 20028 | + }else{ |
| 20029 | + bArgList = useIntern = 0; |
| 20030 | + } |
| 19955 | 20031 | for(; (c=(*fmt))!=0; ++fmt){ |
| 19956 | 20032 | if( c!='%' ){ |
| 19957 | 20033 | int amt; |
| 19958 | 20034 | bufpt = (char *)fmt; |
| 19959 | 20035 | amt = 1; |
| | @@ -19981,11 +20057,15 @@ |
| 19981 | 20057 | } |
| 19982 | 20058 | }while( !done && (c=(*++fmt))!=0 ); |
| 19983 | 20059 | /* Get the field width */ |
| 19984 | 20060 | width = 0; |
| 19985 | 20061 | if( c=='*' ){ |
| 19986 | | - width = va_arg(ap,int); |
| 20062 | + if( bArgList ){ |
| 20063 | + width = (int)getIntArg(pArgList); |
| 20064 | + }else{ |
| 20065 | + width = va_arg(ap,int); |
| 20066 | + } |
| 19987 | 20067 | if( width<0 ){ |
| 19988 | 20068 | flag_leftjustify = 1; |
| 19989 | 20069 | width = -width; |
| 19990 | 20070 | } |
| 19991 | 20071 | c = *++fmt; |
| | @@ -19998,11 +20078,15 @@ |
| 19998 | 20078 | /* Get the precision */ |
| 19999 | 20079 | if( c=='.' ){ |
| 20000 | 20080 | precision = 0; |
| 20001 | 20081 | c = *++fmt; |
| 20002 | 20082 | if( c=='*' ){ |
| 20003 | | - precision = va_arg(ap,int); |
| 20083 | + if( bArgList ){ |
| 20084 | + precision = (int)getIntArg(pArgList); |
| 20085 | + }else{ |
| 20086 | + precision = va_arg(ap,int); |
| 20087 | + } |
| 20004 | 20088 | if( precision<0 ) precision = -precision; |
| 20005 | 20089 | c = *++fmt; |
| 20006 | 20090 | }else{ |
| 20007 | 20091 | while( c>='0' && c<='9' ){ |
| 20008 | 20092 | precision = precision*10 + c - '0'; |
| | @@ -20029,11 +20113,11 @@ |
| 20029 | 20113 | infop = &fmtinfo[0]; |
| 20030 | 20114 | xtype = etINVALID; |
| 20031 | 20115 | for(idx=0; idx<ArraySize(fmtinfo); idx++){ |
| 20032 | 20116 | if( c==fmtinfo[idx].fmttype ){ |
| 20033 | 20117 | infop = &fmtinfo[idx]; |
| 20034 | | - if( useExtended || (infop->flags & FLAG_INTERN)==0 ){ |
| 20118 | + if( useIntern || (infop->flags & FLAG_INTERN)==0 ){ |
| 20035 | 20119 | xtype = infop->type; |
| 20036 | 20120 | }else{ |
| 20037 | 20121 | return; |
| 20038 | 20122 | } |
| 20039 | 20123 | break; |
| | @@ -20069,11 +20153,13 @@ |
| 20069 | 20153 | /* Fall through into the next case */ |
| 20070 | 20154 | case etORDINAL: |
| 20071 | 20155 | case etRADIX: |
| 20072 | 20156 | if( infop->flags & FLAG_SIGNED ){ |
| 20073 | 20157 | i64 v; |
| 20074 | | - if( flag_longlong ){ |
| 20158 | + if( bArgList ){ |
| 20159 | + v = getIntArg(pArgList); |
| 20160 | + }else if( flag_longlong ){ |
| 20075 | 20161 | v = va_arg(ap,i64); |
| 20076 | 20162 | }else if( flag_long ){ |
| 20077 | 20163 | v = va_arg(ap,long int); |
| 20078 | 20164 | }else{ |
| 20079 | 20165 | v = va_arg(ap,int); |
| | @@ -20090,11 +20176,13 @@ |
| 20090 | 20176 | if( flag_plussign ) prefix = '+'; |
| 20091 | 20177 | else if( flag_blanksign ) prefix = ' '; |
| 20092 | 20178 | else prefix = 0; |
| 20093 | 20179 | } |
| 20094 | 20180 | }else{ |
| 20095 | | - if( flag_longlong ){ |
| 20181 | + if( bArgList ){ |
| 20182 | + longvalue = (u64)getIntArg(pArgList); |
| 20183 | + }else if( flag_longlong ){ |
| 20096 | 20184 | longvalue = va_arg(ap,u64); |
| 20097 | 20185 | }else if( flag_long ){ |
| 20098 | 20186 | longvalue = va_arg(ap,unsigned long int); |
| 20099 | 20187 | }else{ |
| 20100 | 20188 | longvalue = va_arg(ap,unsigned int); |
| | @@ -20150,11 +20238,15 @@ |
| 20150 | 20238 | length = (int)(&zOut[nOut-1]-bufpt); |
| 20151 | 20239 | break; |
| 20152 | 20240 | case etFLOAT: |
| 20153 | 20241 | case etEXP: |
| 20154 | 20242 | case etGENERIC: |
| 20155 | | - realvalue = va_arg(ap,double); |
| 20243 | + if( bArgList ){ |
| 20244 | + realvalue = getDoubleArg(pArgList); |
| 20245 | + }else{ |
| 20246 | + realvalue = va_arg(ap,double); |
| 20247 | + } |
| 20156 | 20248 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 20157 | 20249 | length = 0; |
| 20158 | 20250 | #else |
| 20159 | 20251 | if( precision<0 ) precision = 6; /* Set default precision */ |
| 20160 | 20252 | if( realvalue<0.0 ){ |
| | @@ -20305,20 +20397,27 @@ |
| 20305 | 20397 | length = width; |
| 20306 | 20398 | } |
| 20307 | 20399 | #endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */ |
| 20308 | 20400 | break; |
| 20309 | 20401 | case etSIZE: |
| 20310 | | - *(va_arg(ap,int*)) = pAccum->nChar; |
| 20402 | + if( !bArgList ){ |
| 20403 | + *(va_arg(ap,int*)) = pAccum->nChar; |
| 20404 | + } |
| 20311 | 20405 | length = width = 0; |
| 20312 | 20406 | break; |
| 20313 | 20407 | case etPERCENT: |
| 20314 | 20408 | buf[0] = '%'; |
| 20315 | 20409 | bufpt = buf; |
| 20316 | 20410 | length = 1; |
| 20317 | 20411 | break; |
| 20318 | 20412 | case etCHARX: |
| 20319 | | - c = va_arg(ap,int); |
| 20413 | + if( bArgList ){ |
| 20414 | + bufpt = getTextArg(pArgList); |
| 20415 | + c = bufpt ? bufpt[0] : 0; |
| 20416 | + }else{ |
| 20417 | + c = va_arg(ap,int); |
| 20418 | + } |
| 20320 | 20419 | buf[0] = (char)c; |
| 20321 | 20420 | if( precision>=0 ){ |
| 20322 | 20421 | for(idx=1; idx<precision; idx++) buf[idx] = (char)c; |
| 20323 | 20422 | length = precision; |
| 20324 | 20423 | }else{ |
| | @@ -20326,14 +20425,18 @@ |
| 20326 | 20425 | } |
| 20327 | 20426 | bufpt = buf; |
| 20328 | 20427 | break; |
| 20329 | 20428 | case etSTRING: |
| 20330 | 20429 | case etDYNSTRING: |
| 20331 | | - bufpt = va_arg(ap,char*); |
| 20430 | + if( bArgList ){ |
| 20431 | + bufpt = getTextArg(pArgList); |
| 20432 | + }else{ |
| 20433 | + bufpt = va_arg(ap,char*); |
| 20434 | + } |
| 20332 | 20435 | if( bufpt==0 ){ |
| 20333 | 20436 | bufpt = ""; |
| 20334 | | - }else if( xtype==etDYNSTRING ){ |
| 20437 | + }else if( xtype==etDYNSTRING && !bArgList ){ |
| 20335 | 20438 | zExtra = bufpt; |
| 20336 | 20439 | } |
| 20337 | 20440 | if( precision>=0 ){ |
| 20338 | 20441 | for(length=0; length<precision && bufpt[length]; length++){} |
| 20339 | 20442 | }else{ |
| | @@ -20345,11 +20448,17 @@ |
| 20345 | 20448 | case etSQLESCAPE3: { |
| 20346 | 20449 | int i, j, k, n, isnull; |
| 20347 | 20450 | int needQuote; |
| 20348 | 20451 | char ch; |
| 20349 | 20452 | char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */ |
| 20350 | | - char *escarg = va_arg(ap,char*); |
| 20453 | + char *escarg; |
| 20454 | + |
| 20455 | + if( bArgList ){ |
| 20456 | + escarg = getTextArg(pArgList); |
| 20457 | + }else{ |
| 20458 | + escarg = va_arg(ap,char*); |
| 20459 | + } |
| 20351 | 20460 | isnull = escarg==0; |
| 20352 | 20461 | if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); |
| 20353 | 20462 | k = precision; |
| 20354 | 20463 | for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){ |
| 20355 | 20464 | if( ch==q ) n++; |
| | @@ -20380,10 +20489,11 @@ |
| 20380 | 20489 | ** if( precision>=0 && precision<length ) length = precision; */ |
| 20381 | 20490 | break; |
| 20382 | 20491 | } |
| 20383 | 20492 | case etTOKEN: { |
| 20384 | 20493 | Token *pToken = va_arg(ap, Token*); |
| 20494 | + assert( bArgList==0 ); |
| 20385 | 20495 | if( pToken && pToken->n ){ |
| 20386 | 20496 | sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n); |
| 20387 | 20497 | } |
| 20388 | 20498 | length = width = 0; |
| 20389 | 20499 | break; |
| | @@ -20390,10 +20500,11 @@ |
| 20390 | 20500 | } |
| 20391 | 20501 | case etSRCLIST: { |
| 20392 | 20502 | SrcList *pSrc = va_arg(ap, SrcList*); |
| 20393 | 20503 | int k = va_arg(ap, int); |
| 20394 | 20504 | struct SrcList_item *pItem = &pSrc->a[k]; |
| 20505 | + assert( bArgList==0 ); |
| 20395 | 20506 | assert( k>=0 && k<pSrc->nSrc ); |
| 20396 | 20507 | if( pItem->zDatabase ){ |
| 20397 | 20508 | sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase); |
| 20398 | 20509 | sqlite3StrAccumAppend(pAccum, ".", 1); |
| 20399 | 20510 | } |
| | @@ -20426,11 +20537,11 @@ |
| 20426 | 20537 | nspace = width-length; |
| 20427 | 20538 | if( nspace>0 ){ |
| 20428 | 20539 | sqlite3AppendSpace(pAccum, nspace); |
| 20429 | 20540 | } |
| 20430 | 20541 | } |
| 20431 | | - sqlite3_free(zExtra); |
| 20542 | + if( zExtra ) sqlite3_free(zExtra); |
| 20432 | 20543 | }/* End for loop over the format string */ |
| 20433 | 20544 | } /* End of function */ |
| 20434 | 20545 | |
| 20435 | 20546 | /* |
| 20436 | 20547 | ** Append N bytes of text from z to the StrAccum object. |
| | @@ -20553,11 +20664,11 @@ |
| 20553 | 20664 | StrAccum acc; |
| 20554 | 20665 | assert( db!=0 ); |
| 20555 | 20666 | sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), |
| 20556 | 20667 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 20557 | 20668 | acc.db = db; |
| 20558 | | - sqlite3VXPrintf(&acc, 1, zFormat, ap); |
| 20669 | + sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap); |
| 20559 | 20670 | z = sqlite3StrAccumFinish(&acc); |
| 20560 | 20671 | if( acc.accError==STRACCUM_NOMEM ){ |
| 20561 | 20672 | db->mallocFailed = 1; |
| 20562 | 20673 | } |
| 20563 | 20674 | return z; |
| | @@ -20709,21 +20820,19 @@ |
| 20709 | 20820 | fprintf(stdout,"%s", zBuf); |
| 20710 | 20821 | fflush(stdout); |
| 20711 | 20822 | } |
| 20712 | 20823 | #endif |
| 20713 | 20824 | |
| 20714 | | -#ifndef SQLITE_OMIT_TRACE |
| 20715 | 20825 | /* |
| 20716 | 20826 | ** variable-argument wrapper around sqlite3VXPrintf(). |
| 20717 | 20827 | */ |
| 20718 | | -SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){ |
| 20828 | +SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){ |
| 20719 | 20829 | va_list ap; |
| 20720 | 20830 | va_start(ap,zFormat); |
| 20721 | | - sqlite3VXPrintf(p, 1, zFormat, ap); |
| 20831 | + sqlite3VXPrintf(p, bFlags, zFormat, ap); |
| 20722 | 20832 | va_end(ap); |
| 20723 | 20833 | } |
| 20724 | | -#endif |
| 20725 | 20834 | |
| 20726 | 20835 | /************** End of printf.c **********************************************/ |
| 20727 | 20836 | /************** Begin file random.c ******************************************/ |
| 20728 | 20837 | /* |
| 20729 | 20838 | ** 2001 September 15 |
| | @@ -21494,22 +21603,21 @@ |
| 21494 | 21603 | ** To clear the most recent error for sqlite handle "db", sqlite3Error |
| 21495 | 21604 | ** should be called with err_code set to SQLITE_OK and zFormat set |
| 21496 | 21605 | ** to NULL. |
| 21497 | 21606 | */ |
| 21498 | 21607 | SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){ |
| 21499 | | - if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){ |
| 21500 | | - db->errCode = err_code; |
| 21501 | | - if( zFormat ){ |
| 21502 | | - char *z; |
| 21503 | | - va_list ap; |
| 21504 | | - va_start(ap, zFormat); |
| 21505 | | - z = sqlite3VMPrintf(db, zFormat, ap); |
| 21506 | | - va_end(ap); |
| 21507 | | - sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC); |
| 21508 | | - }else{ |
| 21509 | | - sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC); |
| 21510 | | - } |
| 21608 | + assert( db!=0 ); |
| 21609 | + db->errCode = err_code; |
| 21610 | + if( zFormat && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){ |
| 21611 | + char *z; |
| 21612 | + va_list ap; |
| 21613 | + va_start(ap, zFormat); |
| 21614 | + z = sqlite3VMPrintf(db, zFormat, ap); |
| 21615 | + va_end(ap); |
| 21616 | + sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC); |
| 21617 | + }else if( db->pErr ){ |
| 21618 | + sqlite3ValueSetNull(db->pErr); |
| 21511 | 21619 | } |
| 21512 | 21620 | } |
| 21513 | 21621 | |
| 21514 | 21622 | /* |
| 21515 | 21623 | ** Add an error message to pParse->zErrMsg and increment pParse->nErr. |
| | @@ -37558,10 +37666,11 @@ |
| 37558 | 37666 | ** in memory. |
| 37559 | 37667 | */ |
| 37560 | 37668 | struct PgHdr1 { |
| 37561 | 37669 | sqlite3_pcache_page page; |
| 37562 | 37670 | unsigned int iKey; /* Key value (page number) */ |
| 37671 | + u8 isPinned; /* Page in use, not on the LRU list */ |
| 37563 | 37672 | PgHdr1 *pNext; /* Next in hash table chain */ |
| 37564 | 37673 | PCache1 *pCache; /* Cache that currently owns this page */ |
| 37565 | 37674 | PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */ |
| 37566 | 37675 | PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */ |
| 37567 | 37676 | }; |
| | @@ -37886,38 +37995,36 @@ |
| 37886 | 37995 | ** This function is used internally to remove the page pPage from the |
| 37887 | 37996 | ** PGroup LRU list, if is part of it. If pPage is not part of the PGroup |
| 37888 | 37997 | ** LRU list, then this function is a no-op. |
| 37889 | 37998 | ** |
| 37890 | 37999 | ** The PGroup mutex must be held when this function is called. |
| 37891 | | -** |
| 37892 | | -** If pPage is NULL then this routine is a no-op. |
| 37893 | 38000 | */ |
| 37894 | 38001 | static void pcache1PinPage(PgHdr1 *pPage){ |
| 37895 | 38002 | PCache1 *pCache; |
| 37896 | 38003 | PGroup *pGroup; |
| 37897 | 38004 | |
| 37898 | | - if( pPage==0 ) return; |
| 38005 | + assert( pPage!=0 ); |
| 38006 | + assert( pPage->isPinned==0 ); |
| 37899 | 38007 | pCache = pPage->pCache; |
| 37900 | 38008 | pGroup = pCache->pGroup; |
| 38009 | + assert( pPage->pLruNext || pPage==pGroup->pLruTail ); |
| 38010 | + assert( pPage->pLruPrev || pPage==pGroup->pLruHead ); |
| 37901 | 38011 | assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 37902 | | - if( pPage->pLruNext || pPage==pGroup->pLruTail ){ |
| 37903 | | - if( pPage->pLruPrev ){ |
| 37904 | | - pPage->pLruPrev->pLruNext = pPage->pLruNext; |
| 37905 | | - } |
| 37906 | | - if( pPage->pLruNext ){ |
| 37907 | | - pPage->pLruNext->pLruPrev = pPage->pLruPrev; |
| 37908 | | - } |
| 37909 | | - if( pGroup->pLruHead==pPage ){ |
| 37910 | | - pGroup->pLruHead = pPage->pLruNext; |
| 37911 | | - } |
| 37912 | | - if( pGroup->pLruTail==pPage ){ |
| 37913 | | - pGroup->pLruTail = pPage->pLruPrev; |
| 37914 | | - } |
| 37915 | | - pPage->pLruNext = 0; |
| 37916 | | - pPage->pLruPrev = 0; |
| 37917 | | - pPage->pCache->nRecyclable--; |
| 37918 | | - } |
| 38012 | + if( pPage->pLruPrev ){ |
| 38013 | + pPage->pLruPrev->pLruNext = pPage->pLruNext; |
| 38014 | + }else{ |
| 38015 | + pGroup->pLruHead = pPage->pLruNext; |
| 38016 | + } |
| 38017 | + if( pPage->pLruNext ){ |
| 38018 | + pPage->pLruNext->pLruPrev = pPage->pLruPrev; |
| 38019 | + }else{ |
| 38020 | + pGroup->pLruTail = pPage->pLruPrev; |
| 38021 | + } |
| 38022 | + pPage->pLruNext = 0; |
| 38023 | + pPage->pLruPrev = 0; |
| 38024 | + pPage->isPinned = 1; |
| 38025 | + pCache->nRecyclable--; |
| 37919 | 38026 | } |
| 37920 | 38027 | |
| 37921 | 38028 | |
| 37922 | 38029 | /* |
| 37923 | 38030 | ** Remove the page supplied as an argument from the hash table |
| | @@ -37945,10 +38052,11 @@ |
| 37945 | 38052 | static void pcache1EnforceMaxPage(PGroup *pGroup){ |
| 37946 | 38053 | assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 37947 | 38054 | while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){ |
| 37948 | 38055 | PgHdr1 *p = pGroup->pLruTail; |
| 37949 | 38056 | assert( p->pCache->pGroup==pGroup ); |
| 38057 | + assert( p->isPinned==0 ); |
| 37950 | 38058 | pcache1PinPage(p); |
| 37951 | 38059 | pcache1RemoveFromHash(p); |
| 37952 | 38060 | pcache1FreePage(p); |
| 37953 | 38061 | } |
| 37954 | 38062 | } |
| | @@ -37972,11 +38080,11 @@ |
| 37972 | 38080 | PgHdr1 *pPage; |
| 37973 | 38081 | while( (pPage = *pp)!=0 ){ |
| 37974 | 38082 | if( pPage->iKey>=iLimit ){ |
| 37975 | 38083 | pCache->nPage--; |
| 37976 | 38084 | *pp = pPage->pNext; |
| 37977 | | - pcache1PinPage(pPage); |
| 38085 | + if( !pPage->isPinned ) pcache1PinPage(pPage); |
| 37978 | 38086 | pcache1FreePage(pPage); |
| 37979 | 38087 | }else{ |
| 37980 | 38088 | pp = &pPage->pNext; |
| 37981 | 38089 | TESTONLY( nPage++; ) |
| 37982 | 38090 | } |
| | @@ -38195,12 +38303,15 @@ |
| 38195 | 38303 | unsigned int h = iKey % pCache->nHash; |
| 38196 | 38304 | for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext); |
| 38197 | 38305 | } |
| 38198 | 38306 | |
| 38199 | 38307 | /* Step 2: Abort if no existing page is found and createFlag is 0 */ |
| 38200 | | - if( pPage || createFlag==0 ){ |
| 38201 | | - pcache1PinPage(pPage); |
| 38308 | + if( pPage ){ |
| 38309 | + if( !pPage->isPinned ) pcache1PinPage(pPage); |
| 38310 | + goto fetch_out; |
| 38311 | + } |
| 38312 | + if( createFlag==0 ){ |
| 38202 | 38313 | goto fetch_out; |
| 38203 | 38314 | } |
| 38204 | 38315 | |
| 38205 | 38316 | /* The pGroup local variable will normally be initialized by the |
| 38206 | 38317 | ** pcache1EnterMutex() macro above. But if SQLITE_MUTEX_OMIT is defined, |
| | @@ -38237,10 +38348,11 @@ |
| 38237 | 38348 | || pGroup->nCurrentPage>=pGroup->nMaxPage |
| 38238 | 38349 | || pcache1UnderMemoryPressure(pCache) |
| 38239 | 38350 | )){ |
| 38240 | 38351 | PCache1 *pOther; |
| 38241 | 38352 | pPage = pGroup->pLruTail; |
| 38353 | + assert( pPage->isPinned==0 ); |
| 38242 | 38354 | pcache1RemoveFromHash(pPage); |
| 38243 | 38355 | pcache1PinPage(pPage); |
| 38244 | 38356 | pOther = pPage->pCache; |
| 38245 | 38357 | |
| 38246 | 38358 | /* We want to verify that szPage and szExtra are the same for pOther |
| | @@ -38273,10 +38385,11 @@ |
| 38273 | 38385 | pPage->iKey = iKey; |
| 38274 | 38386 | pPage->pNext = pCache->apHash[h]; |
| 38275 | 38387 | pPage->pCache = pCache; |
| 38276 | 38388 | pPage->pLruPrev = 0; |
| 38277 | 38389 | pPage->pLruNext = 0; |
| 38390 | + pPage->isPinned = 1; |
| 38278 | 38391 | *(void **)pPage->page.pExtra = 0; |
| 38279 | 38392 | pCache->apHash[h] = pPage; |
| 38280 | 38393 | } |
| 38281 | 38394 | |
| 38282 | 38395 | fetch_out: |
| | @@ -38308,10 +38421,11 @@ |
| 38308 | 38421 | /* It is an error to call this function if the page is already |
| 38309 | 38422 | ** part of the PGroup LRU list. |
| 38310 | 38423 | */ |
| 38311 | 38424 | assert( pPage->pLruPrev==0 && pPage->pLruNext==0 ); |
| 38312 | 38425 | assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage ); |
| 38426 | + assert( pPage->isPinned==1 ); |
| 38313 | 38427 | |
| 38314 | 38428 | if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){ |
| 38315 | 38429 | pcache1RemoveFromHash(pPage); |
| 38316 | 38430 | pcache1FreePage(pPage); |
| 38317 | 38431 | }else{ |
| | @@ -38323,10 +38437,11 @@ |
| 38323 | 38437 | }else{ |
| 38324 | 38438 | pGroup->pLruTail = pPage; |
| 38325 | 38439 | pGroup->pLruHead = pPage; |
| 38326 | 38440 | } |
| 38327 | 38441 | pCache->nRecyclable++; |
| 38442 | + pPage->isPinned = 0; |
| 38328 | 38443 | } |
| 38329 | 38444 | |
| 38330 | 38445 | pcache1LeaveMutex(pCache->pGroup); |
| 38331 | 38446 | } |
| 38332 | 38447 | |
| | @@ -38449,10 +38564,11 @@ |
| 38449 | 38564 | while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){ |
| 38450 | 38565 | nFree += pcache1MemSize(p->page.pBuf); |
| 38451 | 38566 | #ifdef SQLITE_PCACHE_SEPARATE_HEADER |
| 38452 | 38567 | nFree += sqlite3MemSize(p); |
| 38453 | 38568 | #endif |
| 38569 | + assert( p->isPinned==0 ); |
| 38454 | 38570 | pcache1PinPage(p); |
| 38455 | 38571 | pcache1RemoveFromHash(p); |
| 38456 | 38572 | pcache1FreePage(p); |
| 38457 | 38573 | } |
| 38458 | 38574 | pcache1LeaveMutex(&pcache1.grp); |
| | @@ -38473,10 +38589,11 @@ |
| 38473 | 38589 | int *pnRecyclable /* OUT: Total number of pages available for recycling */ |
| 38474 | 38590 | ){ |
| 38475 | 38591 | PgHdr1 *p; |
| 38476 | 38592 | int nRecyclable = 0; |
| 38477 | 38593 | for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){ |
| 38594 | + assert( p->isPinned==0 ); |
| 38478 | 38595 | nRecyclable++; |
| 38479 | 38596 | } |
| 38480 | 38597 | *pnCurrent = pcache1.grp.nCurrentPage; |
| 38481 | 38598 | *pnMax = (int)pcache1.grp.nMaxPage; |
| 38482 | 38599 | *pnMin = (int)pcache1.grp.nMinPage; |
| | @@ -40159,29 +40276,26 @@ |
| 40159 | 40276 | ** PagerSavepoint.pInSavepoint. |
| 40160 | 40277 | */ |
| 40161 | 40278 | static int subjRequiresPage(PgHdr *pPg){ |
| 40162 | 40279 | Pager *pPager = pPg->pPager; |
| 40163 | 40280 | PagerSavepoint *p; |
| 40164 | | - Pgno pgno; |
| 40281 | + Pgno pgno = pPg->pgno; |
| 40165 | 40282 | int i; |
| 40166 | | - if( pPager->nSavepoint ){ |
| 40167 | | - pgno = pPg->pgno; |
| 40168 | | - for(i=0; i<pPager->nSavepoint; i++){ |
| 40169 | | - p = &pPager->aSavepoint[i]; |
| 40170 | | - if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){ |
| 40171 | | - return 1; |
| 40172 | | - } |
| 40283 | + for(i=0; i<pPager->nSavepoint; i++){ |
| 40284 | + p = &pPager->aSavepoint[i]; |
| 40285 | + if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){ |
| 40286 | + return 1; |
| 40173 | 40287 | } |
| 40174 | 40288 | } |
| 40175 | 40289 | return 0; |
| 40176 | 40290 | } |
| 40177 | 40291 | |
| 40178 | 40292 | /* |
| 40179 | 40293 | ** Return true if the page is already in the journal file. |
| 40180 | 40294 | */ |
| 40181 | | -static int pageInJournal(PgHdr *pPg){ |
| 40182 | | - return sqlite3BitvecTest(pPg->pPager->pInJournal, pPg->pgno); |
| 40295 | +static int pageInJournal(Pager *pPager, PgHdr *pPg){ |
| 40296 | + return sqlite3BitvecTest(pPager->pInJournal, pPg->pgno); |
| 40183 | 40297 | } |
| 40184 | 40298 | |
| 40185 | 40299 | /* |
| 40186 | 40300 | ** Read a 32-bit integer from the given file descriptor. Store the integer |
| 40187 | 40301 | ** that is read in *pRes. Return SQLITE_OK if everything worked, or an |
| | @@ -40384,10 +40498,11 @@ |
| 40384 | 40498 | |
| 40385 | 40499 | if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ)) |
| 40386 | 40500 | || szJ<16 |
| 40387 | 40501 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len)) |
| 40388 | 40502 | || len>=nMaster |
| 40503 | + || len==0 |
| 40389 | 40504 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum)) |
| 40390 | 40505 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8)) |
| 40391 | 40506 | || memcmp(aMagic, aJournalMagic, 8) |
| 40392 | 40507 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len)) |
| 40393 | 40508 | ){ |
| | @@ -41124,11 +41239,11 @@ |
| 41124 | 41239 | sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash); |
| 41125 | 41240 | if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){ |
| 41126 | 41241 | PgHdr *p = pager_lookup(pPager, 1); |
| 41127 | 41242 | if( p ){ |
| 41128 | 41243 | p->pageHash = 0; |
| 41129 | | - sqlite3PagerUnref(p); |
| 41244 | + sqlite3PagerUnrefNotNull(p); |
| 41130 | 41245 | } |
| 41131 | 41246 | } |
| 41132 | 41247 | #endif |
| 41133 | 41248 | |
| 41134 | 41249 | sqlite3BitvecDestroy(pPager->pInJournal); |
| | @@ -41152,10 +41267,15 @@ |
| 41152 | 41267 | ** file. So it is safe to truncate the database file to its minimum |
| 41153 | 41268 | ** required size. */ |
| 41154 | 41269 | assert( pPager->eLock==EXCLUSIVE_LOCK ); |
| 41155 | 41270 | rc = pager_truncate(pPager, pPager->dbSize); |
| 41156 | 41271 | } |
| 41272 | + |
| 41273 | + if( rc==SQLITE_OK && bCommit && isOpen(pPager->fd) ){ |
| 41274 | + rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_COMMIT_PHASETWO, 0); |
| 41275 | + if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; |
| 41276 | + } |
| 41157 | 41277 | |
| 41158 | 41278 | if( !pPager->exclusiveMode |
| 41159 | 41279 | && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0)) |
| 41160 | 41280 | ){ |
| 41161 | 41281 | rc2 = pagerUnlockDb(pPager, SHARED_LOCK); |
| | @@ -41966,11 +42086,11 @@ |
| 41966 | 42086 | testcase( rc!=SQLITE_OK ); |
| 41967 | 42087 | } |
| 41968 | 42088 | if( rc==SQLITE_OK |
| 41969 | 42089 | && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN) |
| 41970 | 42090 | ){ |
| 41971 | | - rc = sqlite3PagerSync(pPager); |
| 42091 | + rc = sqlite3PagerSync(pPager, 0); |
| 41972 | 42092 | } |
| 41973 | 42093 | if( rc==SQLITE_OK ){ |
| 41974 | 42094 | rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0); |
| 41975 | 42095 | testcase( rc!=SQLITE_OK ); |
| 41976 | 42096 | } |
| | @@ -42112,11 +42232,11 @@ |
| 42112 | 42232 | rc = readDbPage(pPg, iFrame); |
| 42113 | 42233 | } |
| 42114 | 42234 | if( rc==SQLITE_OK ){ |
| 42115 | 42235 | pPager->xReiniter(pPg); |
| 42116 | 42236 | } |
| 42117 | | - sqlite3PagerUnref(pPg); |
| 42237 | + sqlite3PagerUnrefNotNull(pPg); |
| 42118 | 42238 | } |
| 42119 | 42239 | } |
| 42120 | 42240 | |
| 42121 | 42241 | /* Normally, if a transaction is rolled back, any backup processes are |
| 42122 | 42242 | ** updated as data is copied out of the rollback journal and into the |
| | @@ -43467,11 +43587,11 @@ |
| 43467 | 43587 | /* Open the sub-journal, if it has not already been opened */ |
| 43468 | 43588 | assert( pPager->useJournal ); |
| 43469 | 43589 | assert( isOpen(pPager->jfd) || pagerUseWal(pPager) ); |
| 43470 | 43590 | assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 ); |
| 43471 | 43591 | assert( pagerUseWal(pPager) |
| 43472 | | - || pageInJournal(pPg) |
| 43592 | + || pageInJournal(pPager, pPg) |
| 43473 | 43593 | || pPg->pgno>pPager->dbOrigSize |
| 43474 | 43594 | ); |
| 43475 | 43595 | rc = openSubJournal(pPager); |
| 43476 | 43596 | |
| 43477 | 43597 | /* If the sub-journal was opened successfully (or was already open), |
| | @@ -44568,20 +44688,23 @@ |
| 44568 | 44688 | ** If the number of references to the page drop to zero, then the |
| 44569 | 44689 | ** page is added to the LRU list. When all references to all pages |
| 44570 | 44690 | ** are released, a rollback occurs and the lock on the database is |
| 44571 | 44691 | ** removed. |
| 44572 | 44692 | */ |
| 44693 | +SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){ |
| 44694 | + Pager *pPager; |
| 44695 | + assert( pPg!=0 ); |
| 44696 | + pPager = pPg->pPager; |
| 44697 | + if( pPg->flags & PGHDR_MMAP ){ |
| 44698 | + pagerReleaseMapPage(pPg); |
| 44699 | + }else{ |
| 44700 | + sqlite3PcacheRelease(pPg); |
| 44701 | + } |
| 44702 | + pagerUnlockIfUnused(pPager); |
| 44703 | +} |
| 44573 | 44704 | SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){ |
| 44574 | | - if( pPg ){ |
| 44575 | | - Pager *pPager = pPg->pPager; |
| 44576 | | - if( pPg->flags & PGHDR_MMAP ){ |
| 44577 | | - pagerReleaseMapPage(pPg); |
| 44578 | | - }else{ |
| 44579 | | - sqlite3PcacheRelease(pPg); |
| 44580 | | - } |
| 44581 | | - pagerUnlockIfUnused(pPager); |
| 44582 | | - } |
| 44705 | + if( pPg ) sqlite3PagerUnrefNotNull(pPg); |
| 44583 | 44706 | } |
| 44584 | 44707 | |
| 44585 | 44708 | /* |
| 44586 | 44709 | ** This function is called at the start of every write transaction. |
| 44587 | 44710 | ** There must already be a RESERVED or EXCLUSIVE lock on the database |
| | @@ -44765,13 +44888,13 @@ |
| 44765 | 44888 | ** one of the journals, the corresponding bit is set in the |
| 44766 | 44889 | ** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs |
| 44767 | 44890 | ** of any open savepoints as appropriate. |
| 44768 | 44891 | */ |
| 44769 | 44892 | static int pager_write(PgHdr *pPg){ |
| 44770 | | - void *pData = pPg->pData; |
| 44771 | 44893 | Pager *pPager = pPg->pPager; |
| 44772 | 44894 | int rc = SQLITE_OK; |
| 44895 | + int inJournal; |
| 44773 | 44896 | |
| 44774 | 44897 | /* This routine is not called unless a write-transaction has already |
| 44775 | 44898 | ** been started. The journal file may or may not be open at this point. |
| 44776 | 44899 | ** It is never called in the ERROR state. |
| 44777 | 44900 | */ |
| | @@ -44803,19 +44926,20 @@ |
| 44803 | 44926 | |
| 44804 | 44927 | /* Mark the page as dirty. If the page has already been written |
| 44805 | 44928 | ** to the journal then we can return right away. |
| 44806 | 44929 | */ |
| 44807 | 44930 | sqlite3PcacheMakeDirty(pPg); |
| 44808 | | - if( pageInJournal(pPg) && !subjRequiresPage(pPg) ){ |
| 44931 | + inJournal = pageInJournal(pPager, pPg); |
| 44932 | + if( inJournal && (pPager->nSavepoint==0 || !subjRequiresPage(pPg)) ){ |
| 44809 | 44933 | assert( !pagerUseWal(pPager) ); |
| 44810 | 44934 | }else{ |
| 44811 | 44935 | |
| 44812 | 44936 | /* The transaction journal now exists and we have a RESERVED or an |
| 44813 | 44937 | ** EXCLUSIVE lock on the main database file. Write the current page to |
| 44814 | 44938 | ** the transaction journal if it is not there already. |
| 44815 | 44939 | */ |
| 44816 | | - if( !pageInJournal(pPg) && !pagerUseWal(pPager) ){ |
| 44940 | + if( !inJournal && !pagerUseWal(pPager) ){ |
| 44817 | 44941 | assert( pagerUseWal(pPager)==0 ); |
| 44818 | 44942 | if( pPg->pgno<=pPager->dbOrigSize && isOpen(pPager->jfd) ){ |
| 44819 | 44943 | u32 cksum; |
| 44820 | 44944 | char *pData2; |
| 44821 | 44945 | i64 iOff = pPager->journalOff; |
| | @@ -44824,11 +44948,11 @@ |
| 44824 | 44948 | ** contains the database locks. The following assert verifies |
| 44825 | 44949 | ** that we do not. */ |
| 44826 | 44950 | assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); |
| 44827 | 44951 | |
| 44828 | 44952 | assert( pPager->journalHdr<=pPager->journalOff ); |
| 44829 | | - CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2); |
| 44953 | + CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2); |
| 44830 | 44954 | cksum = pager_cksum(pPager, (u8*)pData2); |
| 44831 | 44955 | |
| 44832 | 44956 | /* Even if an IO or diskfull error occurs while journalling the |
| 44833 | 44957 | ** page in the block above, set the need-sync flag for the page. |
| 44834 | 44958 | ** Otherwise, when the transaction is rolled back, the logic in |
| | @@ -44876,11 +45000,11 @@ |
| 44876 | 45000 | /* If the statement journal is open and the page is not in it, |
| 44877 | 45001 | ** then write the current page to the statement journal. Note that |
| 44878 | 45002 | ** the statement journal format differs from the standard journal format |
| 44879 | 45003 | ** in that it omits the checksums and the header. |
| 44880 | 45004 | */ |
| 44881 | | - if( subjRequiresPage(pPg) ){ |
| 45005 | + if( pPager->nSavepoint>0 && subjRequiresPage(pPg) ){ |
| 44882 | 45006 | rc = subjournalPage(pPg); |
| 44883 | 45007 | } |
| 44884 | 45008 | } |
| 44885 | 45009 | |
| 44886 | 45010 | /* Update the database size and return. |
| | @@ -44959,18 +45083,18 @@ |
| 44959 | 45083 | if( rc==SQLITE_OK ){ |
| 44960 | 45084 | rc = pager_write(pPage); |
| 44961 | 45085 | if( pPage->flags&PGHDR_NEED_SYNC ){ |
| 44962 | 45086 | needSync = 1; |
| 44963 | 45087 | } |
| 44964 | | - sqlite3PagerUnref(pPage); |
| 45088 | + sqlite3PagerUnrefNotNull(pPage); |
| 44965 | 45089 | } |
| 44966 | 45090 | } |
| 44967 | 45091 | }else if( (pPage = pager_lookup(pPager, pg))!=0 ){ |
| 44968 | 45092 | if( pPage->flags&PGHDR_NEED_SYNC ){ |
| 44969 | 45093 | needSync = 1; |
| 44970 | 45094 | } |
| 44971 | | - sqlite3PagerUnref(pPage); |
| 45095 | + sqlite3PagerUnrefNotNull(pPage); |
| 44972 | 45096 | } |
| 44973 | 45097 | } |
| 44974 | 45098 | |
| 44975 | 45099 | /* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages |
| 44976 | 45100 | ** starting at pg1, then it needs to be set for all of them. Because |
| | @@ -44982,11 +45106,11 @@ |
| 44982 | 45106 | assert( !MEMDB ); |
| 44983 | 45107 | for(ii=0; ii<nPage; ii++){ |
| 44984 | 45108 | PgHdr *pPage = pager_lookup(pPager, pg1+ii); |
| 44985 | 45109 | if( pPage ){ |
| 44986 | 45110 | pPage->flags |= PGHDR_NEED_SYNC; |
| 44987 | | - sqlite3PagerUnref(pPage); |
| 45111 | + sqlite3PagerUnrefNotNull(pPage); |
| 44988 | 45112 | } |
| 44989 | 45113 | } |
| 44990 | 45114 | } |
| 44991 | 45115 | |
| 44992 | 45116 | assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 ); |
| | @@ -45135,21 +45259,21 @@ |
| 45135 | 45259 | ** or pages with the Pager.noSync flag set. |
| 45136 | 45260 | ** |
| 45137 | 45261 | ** If successful, or if called on a pager for which it is a no-op, this |
| 45138 | 45262 | ** function returns SQLITE_OK. Otherwise, an IO error code is returned. |
| 45139 | 45263 | */ |
| 45140 | | -SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager){ |
| 45264 | +SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster){ |
| 45141 | 45265 | int rc = SQLITE_OK; |
| 45142 | | - if( !pPager->noSync ){ |
| 45266 | + |
| 45267 | + if( isOpen(pPager->fd) ){ |
| 45268 | + void *pArg = (void*)zMaster; |
| 45269 | + rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg); |
| 45270 | + if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; |
| 45271 | + } |
| 45272 | + if( rc==SQLITE_OK && !pPager->noSync ){ |
| 45143 | 45273 | assert( !MEMDB ); |
| 45144 | 45274 | rc = sqlite3OsSync(pPager->fd, pPager->syncFlags); |
| 45145 | | - }else if( isOpen(pPager->fd) ){ |
| 45146 | | - assert( !MEMDB ); |
| 45147 | | - rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC_OMITTED, 0); |
| 45148 | | - if( rc==SQLITE_NOTFOUND ){ |
| 45149 | | - rc = SQLITE_OK; |
| 45150 | | - } |
| 45151 | 45275 | } |
| 45152 | 45276 | return rc; |
| 45153 | 45277 | } |
| 45154 | 45278 | |
| 45155 | 45279 | /* |
| | @@ -45344,11 +45468,11 @@ |
| 45344 | 45468 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 45345 | 45469 | } |
| 45346 | 45470 | |
| 45347 | 45471 | /* Finally, sync the database file. */ |
| 45348 | 45472 | if( !noSync ){ |
| 45349 | | - rc = sqlite3PagerSync(pPager); |
| 45473 | + rc = sqlite3PagerSync(pPager, zMaster); |
| 45350 | 45474 | } |
| 45351 | 45475 | IOTRACE(("DBSYNC %p\n", pPager)) |
| 45352 | 45476 | } |
| 45353 | 45477 | } |
| 45354 | 45478 | |
| | @@ -45473,11 +45597,13 @@ |
| 45473 | 45597 | rc = pager_playback(pPager, 0); |
| 45474 | 45598 | } |
| 45475 | 45599 | |
| 45476 | 45600 | assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK ); |
| 45477 | 45601 | assert( rc==SQLITE_OK || rc==SQLITE_FULL || rc==SQLITE_CORRUPT |
| 45478 | | - || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR ); |
| 45602 | + || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR |
| 45603 | + || rc==SQLITE_CANTOPEN |
| 45604 | + ); |
| 45479 | 45605 | |
| 45480 | 45606 | /* If an error occurs during a ROLLBACK, we can no longer trust the pager |
| 45481 | 45607 | ** cache. So call pager_error() on the way out to make any error persistent. |
| 45482 | 45608 | */ |
| 45483 | 45609 | return pager_error(pPager, rc); |
| | @@ -45876,11 +46002,11 @@ |
| 45876 | 46002 | ** can be written to. The caller has already promised not to write to it. |
| 45877 | 46003 | */ |
| 45878 | 46004 | if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){ |
| 45879 | 46005 | needSyncPgno = pPg->pgno; |
| 45880 | 46006 | assert( pPager->journalMode==PAGER_JOURNALMODE_OFF || |
| 45881 | | - pageInJournal(pPg) || pPg->pgno>pPager->dbOrigSize ); |
| 46007 | + pageInJournal(pPager, pPg) || pPg->pgno>pPager->dbOrigSize ); |
| 45882 | 46008 | assert( pPg->flags&PGHDR_DIRTY ); |
| 45883 | 46009 | } |
| 45884 | 46010 | |
| 45885 | 46011 | /* If the cache contains a page with page-number pgno, remove it |
| 45886 | 46012 | ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for |
| | @@ -45910,11 +46036,11 @@ |
| 45910 | 46036 | ** as the original page since it has already been allocated. |
| 45911 | 46037 | */ |
| 45912 | 46038 | if( MEMDB ){ |
| 45913 | 46039 | assert( pPgOld ); |
| 45914 | 46040 | sqlite3PcacheMove(pPgOld, origPgno); |
| 45915 | | - sqlite3PagerUnref(pPgOld); |
| 46041 | + sqlite3PagerUnrefNotNull(pPgOld); |
| 45916 | 46042 | } |
| 45917 | 46043 | |
| 45918 | 46044 | if( needSyncPgno ){ |
| 45919 | 46045 | /* If needSyncPgno is non-zero, then the journal file needs to be |
| 45920 | 46046 | ** sync()ed before any data is written to database file page needSyncPgno. |
| | @@ -45939,11 +46065,11 @@ |
| 45939 | 46065 | } |
| 45940 | 46066 | return rc; |
| 45941 | 46067 | } |
| 45942 | 46068 | pPgHdr->flags |= PGHDR_NEED_SYNC; |
| 45943 | 46069 | sqlite3PcacheMakeDirty(pPgHdr); |
| 45944 | | - sqlite3PagerUnref(pPgHdr); |
| 46070 | + sqlite3PagerUnrefNotNull(pPgHdr); |
| 45945 | 46071 | } |
| 45946 | 46072 | |
| 45947 | 46073 | return SQLITE_OK; |
| 45948 | 46074 | } |
| 45949 | 46075 | #endif |
| | @@ -52079,14 +52205,15 @@ |
| 52079 | 52205 | */ |
| 52080 | 52206 | static void releasePage(MemPage *pPage){ |
| 52081 | 52207 | if( pPage ){ |
| 52082 | 52208 | assert( pPage->aData ); |
| 52083 | 52209 | assert( pPage->pBt ); |
| 52210 | + assert( pPage->pDbPage!=0 ); |
| 52084 | 52211 | assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); |
| 52085 | 52212 | assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData ); |
| 52086 | 52213 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 52087 | | - sqlite3PagerUnref(pPage->pDbPage); |
| 52214 | + sqlite3PagerUnrefNotNull(pPage->pDbPage); |
| 52088 | 52215 | } |
| 52089 | 52216 | } |
| 52090 | 52217 | |
| 52091 | 52218 | /* |
| 52092 | 52219 | ** During a rollback, when the pager reloads information into the cache |
| | @@ -59413,11 +59540,11 @@ |
| 59413 | 59540 | rc = backupTruncateFile(pFile, iSize); |
| 59414 | 59541 | } |
| 59415 | 59542 | |
| 59416 | 59543 | /* Sync the database file to disk. */ |
| 59417 | 59544 | if( rc==SQLITE_OK ){ |
| 59418 | | - rc = sqlite3PagerSync(pDestPager); |
| 59545 | + rc = sqlite3PagerSync(pDestPager, 0); |
| 59419 | 59546 | } |
| 59420 | 59547 | }else{ |
| 59421 | 59548 | sqlite3PagerTruncateImage(pDestPager, nDestTruncate); |
| 59422 | 59549 | rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0); |
| 59423 | 59550 | } |
| | @@ -59488,14 +59615,14 @@ |
| 59488 | 59615 | /* If a transaction is still open on the Btree, roll it back. */ |
| 59489 | 59616 | sqlite3BtreeRollback(p->pDest, SQLITE_OK); |
| 59490 | 59617 | |
| 59491 | 59618 | /* Set the error code of the destination database handle. */ |
| 59492 | 59619 | rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc; |
| 59493 | | - sqlite3Error(p->pDestDb, rc, 0); |
| 59494 | | - |
| 59495 | | - /* Exit the mutexes and free the backup context structure. */ |
| 59496 | 59620 | if( p->pDestDb ){ |
| 59621 | + sqlite3Error(p->pDestDb, rc, 0); |
| 59622 | + |
| 59623 | + /* Exit the mutexes and free the backup context structure. */ |
| 59497 | 59624 | sqlite3LeaveMutexAndCloseZombie(p->pDestDb); |
| 59498 | 59625 | } |
| 59499 | 59626 | sqlite3BtreeLeave(p->pSrc); |
| 59500 | 59627 | if( p->pDestDb ){ |
| 59501 | 59628 | /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a |
| | @@ -60117,10 +60244,13 @@ |
| 60117 | 60244 | if( pMem->flags & MEM_RowSet ){ |
| 60118 | 60245 | sqlite3RowSetClear(pMem->u.pRowSet); |
| 60119 | 60246 | } |
| 60120 | 60247 | MemSetTypeFlag(pMem, MEM_Null); |
| 60121 | 60248 | pMem->type = SQLITE_NULL; |
| 60249 | +} |
| 60250 | +SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){ |
| 60251 | + sqlite3VdbeMemSetNull((Mem*)p); |
| 60122 | 60252 | } |
| 60123 | 60253 | |
| 60124 | 60254 | /* |
| 60125 | 60255 | ** Delete any previous value and set the value to be a BLOB of length |
| 60126 | 60256 | ** n containing all zeros. |
| | @@ -63440,10 +63570,11 @@ |
| 63440 | 63570 | sqlite3 *db = p->db; |
| 63441 | 63571 | int rc = p->rc; |
| 63442 | 63572 | if( p->zErrMsg ){ |
| 63443 | 63573 | u8 mallocFailed = db->mallocFailed; |
| 63444 | 63574 | sqlite3BeginBenignMalloc(); |
| 63575 | + if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db); |
| 63445 | 63576 | sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT); |
| 63446 | 63577 | sqlite3EndBenignMalloc(); |
| 63447 | 63578 | db->mallocFailed = mallocFailed; |
| 63448 | 63579 | db->errCode = rc; |
| 63449 | 63580 | }else{ |
| | @@ -63508,12 +63639,11 @@ |
| 63508 | 63639 | }else if( p->rc && p->expired ){ |
| 63509 | 63640 | /* The expired flag was set on the VDBE before the first call |
| 63510 | 63641 | ** to sqlite3_step(). For consistency (since sqlite3_step() was |
| 63511 | 63642 | ** called), set the database error in this case as well. |
| 63512 | 63643 | */ |
| 63513 | | - sqlite3Error(db, p->rc, 0); |
| 63514 | | - sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT); |
| 63644 | + sqlite3Error(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg); |
| 63515 | 63645 | sqlite3DbFree(db, p->zErrMsg); |
| 63516 | 63646 | p->zErrMsg = 0; |
| 63517 | 63647 | } |
| 63518 | 63648 | |
| 63519 | 63649 | /* Reclaim all memory used by the VDBE |
| | @@ -64883,20 +65013,21 @@ |
| 64883 | 65013 | && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){ |
| 64884 | 65014 | sqlite3_reset(pStmt); |
| 64885 | 65015 | v->doingRerun = 1; |
| 64886 | 65016 | assert( v->expired==0 ); |
| 64887 | 65017 | } |
| 64888 | | - if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){ |
| 65018 | + if( rc2!=SQLITE_OK ){ |
| 64889 | 65019 | /* This case occurs after failing to recompile an sql statement. |
| 64890 | 65020 | ** The error message from the SQL compiler has already been loaded |
| 64891 | 65021 | ** into the database handle. This block copies the error message |
| 64892 | 65022 | ** from the database handle into the statement and sets the statement |
| 64893 | 65023 | ** program counter to 0 to ensure that when the statement is |
| 64894 | 65024 | ** finalized or reset the parser error message is available via |
| 64895 | 65025 | ** sqlite3_errmsg() and sqlite3_errcode(). |
| 64896 | 65026 | */ |
| 64897 | 65027 | const char *zErr = (const char *)sqlite3_value_text(db->pErr); |
| 65028 | + assert( zErr!=0 || db->mallocFailed ); |
| 64898 | 65029 | sqlite3DbFree(db, v->zErrMsg); |
| 64899 | 65030 | if( !db->mallocFailed ){ |
| 64900 | 65031 | v->zErrMsg = sqlite3DbStrDup(db, zErr); |
| 64901 | 65032 | v->rc = rc2; |
| 64902 | 65033 | } else { |
| | @@ -65841,13 +65972,13 @@ |
| 65841 | 65972 | assert( idx>0 && idx<=p->nVar ); |
| 65842 | 65973 | pVar = &p->aVar[idx-1]; |
| 65843 | 65974 | if( pVar->flags & MEM_Null ){ |
| 65844 | 65975 | sqlite3StrAccumAppend(&out, "NULL", 4); |
| 65845 | 65976 | }else if( pVar->flags & MEM_Int ){ |
| 65846 | | - sqlite3XPrintf(&out, "%lld", pVar->u.i); |
| 65977 | + sqlite3XPrintf(&out, 0, "%lld", pVar->u.i); |
| 65847 | 65978 | }else if( pVar->flags & MEM_Real ){ |
| 65848 | | - sqlite3XPrintf(&out, "%!.15g", pVar->r); |
| 65979 | + sqlite3XPrintf(&out, 0, "%!.15g", pVar->r); |
| 65849 | 65980 | }else if( pVar->flags & MEM_Str ){ |
| 65850 | 65981 | int nOut; /* Number of bytes of the string text to include in output */ |
| 65851 | 65982 | #ifndef SQLITE_OMIT_UTF16 |
| 65852 | 65983 | u8 enc = ENC(db); |
| 65853 | 65984 | Mem utf8; |
| | @@ -65864,33 +65995,37 @@ |
| 65864 | 65995 | if( nOut>SQLITE_TRACE_SIZE_LIMIT ){ |
| 65865 | 65996 | nOut = SQLITE_TRACE_SIZE_LIMIT; |
| 65866 | 65997 | while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; } |
| 65867 | 65998 | } |
| 65868 | 65999 | #endif |
| 65869 | | - sqlite3XPrintf(&out, "'%.*q'", nOut, pVar->z); |
| 66000 | + sqlite3XPrintf(&out, 0, "'%.*q'", nOut, pVar->z); |
| 65870 | 66001 | #ifdef SQLITE_TRACE_SIZE_LIMIT |
| 65871 | | - if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut); |
| 66002 | + if( nOut<pVar->n ){ |
| 66003 | + sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut); |
| 66004 | + } |
| 65872 | 66005 | #endif |
| 65873 | 66006 | #ifndef SQLITE_OMIT_UTF16 |
| 65874 | 66007 | if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8); |
| 65875 | 66008 | #endif |
| 65876 | 66009 | }else if( pVar->flags & MEM_Zero ){ |
| 65877 | | - sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero); |
| 66010 | + sqlite3XPrintf(&out, 0, "zeroblob(%d)", pVar->u.nZero); |
| 65878 | 66011 | }else{ |
| 65879 | 66012 | int nOut; /* Number of bytes of the blob to include in output */ |
| 65880 | 66013 | assert( pVar->flags & MEM_Blob ); |
| 65881 | 66014 | sqlite3StrAccumAppend(&out, "x'", 2); |
| 65882 | 66015 | nOut = pVar->n; |
| 65883 | 66016 | #ifdef SQLITE_TRACE_SIZE_LIMIT |
| 65884 | 66017 | if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT; |
| 65885 | 66018 | #endif |
| 65886 | 66019 | for(i=0; i<nOut; i++){ |
| 65887 | | - sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff); |
| 66020 | + sqlite3XPrintf(&out, 0, "%02x", pVar->z[i]&0xff); |
| 65888 | 66021 | } |
| 65889 | 66022 | sqlite3StrAccumAppend(&out, "'", 1); |
| 65890 | 66023 | #ifdef SQLITE_TRACE_SIZE_LIMIT |
| 65891 | | - if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut); |
| 66024 | + if( nOut<pVar->n ){ |
| 66025 | + sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut); |
| 66026 | + } |
| 65892 | 66027 | #endif |
| 65893 | 66028 | } |
| 65894 | 66029 | } |
| 65895 | 66030 | } |
| 65896 | 66031 | return sqlite3StrAccumFinish(&out); |
| | @@ -65945,11 +66080,11 @@ |
| 65945 | 66080 | int n = p->nIndent; |
| 65946 | 66081 | if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent); |
| 65947 | 66082 | sqlite3AppendSpace(&p->str, p->aIndent[n-1]); |
| 65948 | 66083 | } |
| 65949 | 66084 | va_start(ap, zFormat); |
| 65950 | | - sqlite3VXPrintf(&p->str, 1, zFormat, ap); |
| 66085 | + sqlite3VXPrintf(&p->str, SQLITE_PRINTF_INTERNAL, zFormat, ap); |
| 65951 | 66086 | va_end(ap); |
| 65952 | 66087 | } |
| 65953 | 66088 | } |
| 65954 | 66089 | |
| 65955 | 66090 | /* |
| | @@ -88246,11 +88381,10 @@ |
| 88246 | 88381 | int bestScore = 0; /* Score of best match */ |
| 88247 | 88382 | int h; /* Hash value */ |
| 88248 | 88383 | |
| 88249 | 88384 | assert( nArg>=(-2) ); |
| 88250 | 88385 | assert( nArg>=(-1) || createFlag==0 ); |
| 88251 | | - assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); |
| 88252 | 88386 | h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a); |
| 88253 | 88387 | |
| 88254 | 88388 | /* First search for a match amongst the application-defined functions. |
| 88255 | 88389 | */ |
| 88256 | 88390 | p = functionSearch(&db->aFunc, h, zName, nName); |
| | @@ -89397,10 +89531,36 @@ |
| 89397 | 89531 | }while( isText && (zHaystack[0]&0xc0)==0x80 ); |
| 89398 | 89532 | } |
| 89399 | 89533 | if( nNeedle>nHaystack ) N = 0; |
| 89400 | 89534 | sqlite3_result_int(context, N); |
| 89401 | 89535 | } |
| 89536 | + |
| 89537 | +/* |
| 89538 | +** Implementation of the printf() function. |
| 89539 | +*/ |
| 89540 | +static void printfFunc( |
| 89541 | + sqlite3_context *context, |
| 89542 | + int argc, |
| 89543 | + sqlite3_value **argv |
| 89544 | +){ |
| 89545 | + PrintfArguments x; |
| 89546 | + StrAccum str; |
| 89547 | + const char *zFormat; |
| 89548 | + int n; |
| 89549 | + |
| 89550 | + if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){ |
| 89551 | + x.nArg = argc-1; |
| 89552 | + x.nUsed = 0; |
| 89553 | + x.apArg = argv+1; |
| 89554 | + sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH); |
| 89555 | + str.db = sqlite3_context_db_handle(context); |
| 89556 | + sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x); |
| 89557 | + n = str.nChar; |
| 89558 | + sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, |
| 89559 | + SQLITE_DYNAMIC); |
| 89560 | + } |
| 89561 | +} |
| 89402 | 89562 | |
| 89403 | 89563 | /* |
| 89404 | 89564 | ** Implementation of the substr() function. |
| 89405 | 89565 | ** |
| 89406 | 89566 | ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1. |
| | @@ -90828,10 +90988,11 @@ |
| 90828 | 90988 | FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), |
| 90829 | 90989 | FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), |
| 90830 | 90990 | FUNCTION(instr, 2, 0, 0, instrFunc ), |
| 90831 | 90991 | FUNCTION(substr, 2, 0, 0, substrFunc ), |
| 90832 | 90992 | FUNCTION(substr, 3, 0, 0, substrFunc ), |
| 90993 | + FUNCTION(printf, -1, 0, 0, printfFunc ), |
| 90833 | 90994 | FUNCTION(unicode, 1, 0, 0, unicodeFunc ), |
| 90834 | 90995 | FUNCTION(char, -1, 0, 0, charFunc ), |
| 90835 | 90996 | FUNCTION(abs, 1, 0, 0, absFunc ), |
| 90836 | 90997 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 90837 | 90998 | FUNCTION(round, 1, 0, 0, roundFunc ), |
| | @@ -119433,13 +119594,11 @@ |
| 119433 | 119594 | } |
| 119434 | 119595 | sqlite3HashClear(&db->aModule); |
| 119435 | 119596 | #endif |
| 119436 | 119597 | |
| 119437 | 119598 | sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */ |
| 119438 | | - if( db->pErr ){ |
| 119439 | | - sqlite3ValueFree(db->pErr); |
| 119440 | | - } |
| 119599 | + sqlite3ValueFree(db->pErr); |
| 119441 | 119600 | sqlite3CloseExtensions(db); |
| 119442 | 119601 | |
| 119443 | 119602 | db->magic = SQLITE_MAGIC_ERROR; |
| 119444 | 119603 | |
| 119445 | 119604 | /* The temp-database schema is allocated differently from the other schema |
| | @@ -119818,10 +119977,11 @@ |
| 119818 | 119977 | void (*xFinal)(sqlite3_context*), |
| 119819 | 119978 | FuncDestructor *pDestructor |
| 119820 | 119979 | ){ |
| 119821 | 119980 | FuncDef *p; |
| 119822 | 119981 | int nName; |
| 119982 | + int extraFlags; |
| 119823 | 119983 | |
| 119824 | 119984 | assert( sqlite3_mutex_held(db->mutex) ); |
| 119825 | 119985 | if( zFunctionName==0 || |
| 119826 | 119986 | (xFunc && (xFinal || xStep)) || |
| 119827 | 119987 | (!xFunc && (xFinal && !xStep)) || |
| | @@ -119828,10 +119988,14 @@ |
| 119828 | 119988 | (!xFunc && (!xFinal && xStep)) || |
| 119829 | 119989 | (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || |
| 119830 | 119990 | (255<(nName = sqlite3Strlen30( zFunctionName))) ){ |
| 119831 | 119991 | return SQLITE_MISUSE_BKPT; |
| 119832 | 119992 | } |
| 119993 | + |
| 119994 | + assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC ); |
| 119995 | + extraFlags = enc & SQLITE_DETERMINISTIC; |
| 119996 | + enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY); |
| 119833 | 119997 | |
| 119834 | 119998 | #ifndef SQLITE_OMIT_UTF16 |
| 119835 | 119999 | /* If SQLITE_UTF16 is specified as the encoding type, transform this |
| 119836 | 120000 | ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the |
| 119837 | 120001 | ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally. |
| | @@ -119841,14 +120005,14 @@ |
| 119841 | 120005 | */ |
| 119842 | 120006 | if( enc==SQLITE_UTF16 ){ |
| 119843 | 120007 | enc = SQLITE_UTF16NATIVE; |
| 119844 | 120008 | }else if( enc==SQLITE_ANY ){ |
| 119845 | 120009 | int rc; |
| 119846 | | - rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8, |
| 120010 | + rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags, |
| 119847 | 120011 | pUserData, xFunc, xStep, xFinal, pDestructor); |
| 119848 | 120012 | if( rc==SQLITE_OK ){ |
| 119849 | | - rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE, |
| 120013 | + rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags, |
| 119850 | 120014 | pUserData, xFunc, xStep, xFinal, pDestructor); |
| 119851 | 120015 | } |
| 119852 | 120016 | if( rc!=SQLITE_OK ){ |
| 119853 | 120017 | return rc; |
| 119854 | 120018 | } |
| | @@ -119887,11 +120051,12 @@ |
| 119887 | 120051 | |
| 119888 | 120052 | if( pDestructor ){ |
| 119889 | 120053 | pDestructor->nRef++; |
| 119890 | 120054 | } |
| 119891 | 120055 | p->pDestructor = pDestructor; |
| 119892 | | - p->funcFlags &= SQLITE_FUNC_ENCMASK; |
| 120056 | + p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags; |
| 120057 | + testcase( p->funcFlags & SQLITE_DETERMINISTIC ); |
| 119893 | 120058 | p->xFunc = xFunc; |
| 119894 | 120059 | p->xStep = xStep; |
| 119895 | 120060 | p->xFinalize = xFinal; |
| 119896 | 120061 | p->pUserData = pUserData; |
| 119897 | 120062 | p->nArg = (u16)nArg; |
| | @@ -120317,10 +120482,11 @@ |
| 120317 | 120482 | } |
| 120318 | 120483 | sqlite3_mutex_enter(db->mutex); |
| 120319 | 120484 | if( db->mallocFailed ){ |
| 120320 | 120485 | z = sqlite3ErrStr(SQLITE_NOMEM); |
| 120321 | 120486 | }else{ |
| 120487 | + testcase( db->pErr==0 ); |
| 120322 | 120488 | z = (char*)sqlite3_value_text(db->pErr); |
| 120323 | 120489 | assert( !db->mallocFailed ); |
| 120324 | 120490 | if( z==0 ){ |
| 120325 | 120491 | z = sqlite3ErrStr(db->errCode); |
| 120326 | 120492 | } |
| | @@ -120358,12 +120524,11 @@ |
| 120358 | 120524 | if( db->mallocFailed ){ |
| 120359 | 120525 | z = (void *)outOfMem; |
| 120360 | 120526 | }else{ |
| 120361 | 120527 | z = sqlite3_value_text16(db->pErr); |
| 120362 | 120528 | if( z==0 ){ |
| 120363 | | - sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode), |
| 120364 | | - SQLITE_UTF8, SQLITE_STATIC); |
| 120529 | + sqlite3Error(db, db->errCode, sqlite3ErrStr(db->errCode)); |
| 120365 | 120530 | z = sqlite3_value_text16(db->pErr); |
| 120366 | 120531 | } |
| 120367 | 120532 | /* A malloc() may have failed within the call to sqlite3_value_text16() |
| 120368 | 120533 | ** above. If this is the case, then the db->mallocFailed flag needs to |
| 120369 | 120534 | ** be cleared before returning. Do this directly, instead of via |
| | @@ -121073,12 +121238,10 @@ |
| 121073 | 121238 | if( !db->mallocFailed && rc==SQLITE_OK){ |
| 121074 | 121239 | rc = sqlite3RtreeInit(db); |
| 121075 | 121240 | } |
| 121076 | 121241 | #endif |
| 121077 | 121242 | |
| 121078 | | - sqlite3Error(db, rc, 0); |
| 121079 | | - |
| 121080 | 121243 | /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking |
| 121081 | 121244 | ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking |
| 121082 | 121245 | ** mode. Doing nothing at all also makes NORMAL the default. |
| 121083 | 121246 | */ |
| 121084 | 121247 | #ifdef SQLITE_DEFAULT_LOCKING_MODE |
| 121085 | 121248 | |