1diff -Npur sqlite-amalgamation-3320200/CMakeLists.txt linux-amalgamation/CMakeLists.txt 2--- sqlite-amalgamation-3320200/CMakeLists.txt 1970-01-01 08:00:00.000000000 +0800 3+++ linux-amalgamation/CMakeLists.txt 2020-06-16 09:21:51.768154641 +0800 4@@ -0,0 +1,6 @@ 5+cmake_minimum_required(VERSION 3.14) 6+project (Sqlite[C]) 7+add_library(sqlite3 SHARED sqlite3.c) 8+set_target_properties(sqlite3 PROPERTIES PUBLIC_HEADER "sqlite3.h;sqlite3ext.h") 9+include(GNUInstallDirs) 10+install(TARGETS sqlite3 PUBLIC_HEADER) 11diff -Npur sqlite-amalgamation-3320200/sqlite3.c linux-amalgamation/sqlite3.c 12--- sqlite-amalgamation-3320200/sqlite3.c 2020-06-04 22:01:17.000000000 +0800 13+++ linux-amalgamation/sqlite3.c 2020-06-15 14:18:34.330175000 +0800 14@@ -1164,7 +1164,7 @@ extern "C" { 15 */ 16 #define SQLITE_VERSION "3.32.2" 17 #define SQLITE_VERSION_NUMBER 3032002 18-#define SQLITE_SOURCE_ID "2020-06-04 12:58:43 ec02243ea6ce33b090870ae55ab8aa2534b54d216d45c4aa2fdbb00e86861e8c" 19+#define SQLITE_SOURCE_ID "2020-06-04 12:58:43 ec02243ea6ce33b090870ae55ab8aa2534b54d216d45c4aa2fdbb00e8686alt1" 20 21 /* 22 ** CAPI3REF: Run-Time Library Version Numbers 23@@ -14521,7 +14521,12 @@ typedef INT16_TYPE LogEst; 24 */ 25 #if defined(SQLITE_ENABLE_SELECTTRACE) 26 # define SELECTTRACE_ENABLED 1 27+# define SELECTTRACE(K,P,S,X) \ 28+ if(sqlite3SelectTrace&(K)) \ 29+ sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\ 30+ sqlite3DebugPrintf X 31 #else 32+# define SELECTTRACE(K,P,S,X) 33 # define SELECTTRACE_ENABLED 0 34 #endif 35 36@@ -17880,9 +17885,24 @@ struct AggInfo { 37 int iDistinct; /* Ephemeral table used to enforce DISTINCT */ 38 } *aFunc; 39 int nFunc; /* Number of entries in aFunc[] */ 40+#ifdef SQLITE_DEBUG 41+ u32 iAggMagic; /* Sanity checking constant */ 42+#endif 43 }; 44 45 /* 46+** Allowed values for AggInfo.iAggMagic 47+*/ 48+#define SQLITE_AGGMAGIC_VALID 0x05cadade 49+ 50+/* 51+** True if the AggInfo object is valid. Used inside of assert() only. 52+*/ 53+#ifdef SQLITE_DEBUG 54+# define AggInfoValid(P) ((P)->iAggMagic==SQLITE_AGGMAGIC_VALID) 55+#endif 56+ 57+/* 58 ** The datatype ynVar is a signed integer, either 16-bit or 32-bit. 59 ** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater 60 ** than 32767 we have to make it 32-bit. 16-bit is preferred because 61@@ -19903,10 +19923,11 @@ SQLITE_PRIVATE const unsigned char sqlit 62 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[]; 63 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config; 64 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions; 65+SQLITE_PRIVATE u32 sqlite3SelectTrace; 66 #ifndef SQLITE_OMIT_WSD 67 SQLITE_PRIVATE int sqlite3PendingByte; 68 #endif 69-#endif 70+#endif /* !defined(SQLITE_AMALGAMATION) */ 71 #ifdef VDBE_PROFILE 72 SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt; 73 #endif 74@@ -20616,6 +20637,11 @@ SQLITE_PRIVATE sqlite3_uint64 sqlite3NPr 75 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000; 76 #endif 77 78+/* 79+** Flags for select tracing and the ".selecttrace" macro of the CLI 80+*/ 81+/**/ u32 sqlite3SelectTrace = 0; 82+ 83 /* #include "opcodes.h" */ 84 /* 85 ** Properties of opcodes. The OPFLG_INITIALIZER macro is 86@@ -99243,6 +99269,14 @@ static int resolveSelectStep(Walker *pWa 87 return WRC_Abort; 88 } 89 } 90+ }else if( p->pWin && ALWAYS( (p->selFlags & SF_WinRewrite)==0 ) ){ 91+ sqlite3WindowRewrite(pParse, p); 92+#if SELECTTRACE_ENABLED 93+ if( (sqlite3SelectTrace & 0x108)!=0 ){ 94+ SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n")); 95+ sqlite3TreeViewSelect(0, p, 0); 96+ } 97+#endif 98 } 99 #endif 100 101@@ -103297,6 +103331,7 @@ expr_code_doover: 102 AggInfo *pAggInfo = pExpr->pAggInfo; 103 struct AggInfo_col *pCol; 104 assert( pAggInfo!=0 ); 105+ assert( AggInfoValid(pAggInfo) ); 106 assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn ); 107 pCol = &pAggInfo->aCol[pExpr->iAgg]; 108 if( !pAggInfo->directMode ){ 109@@ -103605,6 +103640,7 @@ expr_code_doover: 110 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 111 sqlite3ErrorMsg(pParse, "misuse of aggregate: %s()", pExpr->u.zToken); 112 }else{ 113+ assert( AggInfoValid(pInfo) ); 114 return pInfo->aFunc[pExpr->iAgg].iMem; 115 } 116 break; 117@@ -105142,13 +105178,7 @@ struct SrcCount { 118 ** Count the number of references to columns. 119 */ 120 static int exprSrcCount(Walker *pWalker, Expr *pExpr){ 121- /* There was once a NEVER() on the second term on the grounds that 122- ** sqlite3FunctionUsesThisSrc() was always called before 123- ** sqlite3ExprAnalyzeAggregates() and so the TK_COLUMNs have not yet 124- ** been converted into TK_AGG_COLUMN. But this is no longer true due 125- ** to window functions - sqlite3WindowRewrite() may now indirectly call 126- ** FunctionUsesThisSrc() when creating a new sub-select. */ 127- if( pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN ){ 128+ if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){ 129 int i; 130 struct SrcCount *p = pWalker->u.pSrcCount; 131 SrcList *pSrc = p->pSrc; 132@@ -128851,20 +128881,6 @@ SQLITE_API int sqlite3_prepare16_v3( 133 /* #include "sqliteInt.h" */ 134 135 /* 136-** Trace output macros 137-*/ 138-#if SELECTTRACE_ENABLED 139-/***/ int sqlite3SelectTrace = 0; 140-# define SELECTTRACE(K,P,S,X) \ 141- if(sqlite3SelectTrace&(K)) \ 142- sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\ 143- sqlite3DebugPrintf X 144-#else 145-# define SELECTTRACE(K,P,S,X) 146-#endif 147- 148- 149-/* 150 ** An instance of the following object is used to record information about 151 ** how to process the DISTINCT keyword, to simplify passing that information 152 ** into the selectInnerLoop() routine. 153@@ -133262,11 +133278,14 @@ static int pushDownWhereTerms( 154 ){ 155 Expr *pNew; 156 int nChng = 0; 157+ Select *pSel; 158 if( pWhere==0 ) return 0; 159 if( pSubq->selFlags & SF_Recursive ) return 0; /* restriction (2) */ 160 161 #ifndef SQLITE_OMIT_WINDOWFUNC 162- if( pSubq->pWin ) return 0; /* restriction (6) */ 163+ for(pSel=pSubq; pSel; pSel=pSel->pPrior){ 164+ if( pSel->pWin ) return 0; /* restriction (6) */ 165+ } 166 #endif 167 168 #ifdef SQLITE_DEBUG 169@@ -134602,6 +134621,9 @@ SQLITE_PRIVATE int sqlite3Select( 170 } 171 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1; 172 memset(&sAggInfo, 0, sizeof(sAggInfo)); 173+#ifdef SQLITE_DEBUG 174+ sAggInfo.iAggMagic = SQLITE_AGGMAGIC_VALID; 175+#endif 176 #if SELECTTRACE_ENABLED 177 SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain)); 178 if( sqlite3SelectTrace & 0x100 ){ 179@@ -134640,19 +134662,6 @@ SQLITE_PRIVATE int sqlite3Select( 180 generateColumnNames(pParse, p); 181 } 182 183-#ifndef SQLITE_OMIT_WINDOWFUNC 184- rc = sqlite3WindowRewrite(pParse, p); 185- if( rc ){ 186- assert( db->mallocFailed || pParse->nErr>0 ); 187- goto select_end; 188- } 189-#if SELECTTRACE_ENABLED 190- if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){ 191- SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n")); 192- sqlite3TreeViewSelect(0, p, 0); 193- } 194-#endif 195-#endif /* SQLITE_OMIT_WINDOWFUNC */ 196 pTabList = p->pSrc; 197 isAgg = (p->selFlags & SF_Aggregate)!=0; 198 memset(&sSort, 0, sizeof(sSort)); 199@@ -134980,7 +134989,7 @@ SQLITE_PRIVATE int sqlite3Select( 200 if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct 201 && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0 202 #ifndef SQLITE_OMIT_WINDOWFUNC 203- && p->pWin==0 204+ && ALWAYS(p->pWin==0) 205 #endif 206 ){ 207 p->selFlags &= ~SF_Distinct; 208@@ -135627,6 +135636,14 @@ SQLITE_PRIVATE int sqlite3Select( 209 select_end: 210 sqlite3ExprListDelete(db, pMinMaxOrderBy); 211 sqlite3DbFree(db, sAggInfo.aCol); 212+#ifdef SQLITE_DEBUG 213+ for(i=0; i<sAggInfo.nFunc; i++){ 214+ assert( sAggInfo.aFunc[i].pExpr!=0 ); 215+ assert( sAggInfo.aFunc[i].pExpr->pAggInfo==&sAggInfo ); 216+ sAggInfo.aFunc[i].pExpr->pAggInfo = 0; 217+ } 218+ sAggInfo.iAggMagic = 0; 219+#endif 220 sqlite3DbFree(db, sAggInfo.aFunc); 221 #if SELECTTRACE_ENABLED 222 SELECTTRACE(0x1,pParse,p,("end processing\n")); 223@@ -151305,7 +151322,7 @@ static int sqlite3WindowExtraAggFuncDept 224 */ 225 SQLITE_PRIVATE int sqlite3WindowRewrite(Parse *pParse, Select *p){ 226 int rc = SQLITE_OK; 227- if( p->pWin && p->pPrior==0 && (p->selFlags & SF_WinRewrite)==0 ){ 228+ if( ALWAYS(p->pWin && (p->selFlags & SF_WinRewrite)==0) ){ 229 Vdbe *v = sqlite3GetVdbe(pParse); 230 sqlite3 *db = pParse->db; 231 Select *pSub = 0; /* The subquery */ 232@@ -229607,7 +229624,7 @@ SQLITE_API int sqlite3_stmt_init( 233 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ 234 235 /************** End of stmt.c ************************************************/ 236-#if __LINE__!=229610 237+#if __LINE__!=229627 238 #undef SQLITE_SOURCE_ID 239 #define SQLITE_SOURCE_ID "2020-06-04 12:58:43 ec02243ea6ce33b090870ae55ab8aa2534b54d216d45c4aa2fdbb00e8686alt2" 240 #endif 241diff -Npur sqlite-amalgamation-3320200/sqlite3.h linux-amalgamation/sqlite3.h 242--- sqlite-amalgamation-3320200/sqlite3.h 2020-06-04 22:01:17.000000000 +0800 243+++ linux-amalgamation/sqlite3.h 2020-06-15 14:18:32.674154000 +0800 244@@ -125,7 +125,7 @@ extern "C" { 245 */ 246 #define SQLITE_VERSION "3.32.2" 247 #define SQLITE_VERSION_NUMBER 3032002 248-#define SQLITE_SOURCE_ID "2020-06-04 12:58:43 ec02243ea6ce33b090870ae55ab8aa2534b54d216d45c4aa2fdbb00e86861e8c" 249+#define SQLITE_SOURCE_ID "2020-06-04 12:58:43 ec02243ea6ce33b090870ae55ab8aa2534b54d216d45c4aa2fdbb00e8686alt1" 250 251 /* 252 ** CAPI3REF: Run-Time Library Version Numbers 253