| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.37.0" |
| 456 | 456 | #define SQLITE_VERSION_NUMBER 3037000 |
| 457 | | -#define SQLITE_SOURCE_ID "2021-09-22 14:43:35 d678ecca02698753d1b33e072566112e94ea36d0d3a8f4a24d2b09d131968d88" |
| 457 | +#define SQLITE_SOURCE_ID "2021-10-04 11:10:15 8b24c177061c38361588f419eda9b7943b72a0c6b2855b6f39272451b8a1b813" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -13303,10 +13303,17 @@ |
| 13303 | 13303 | */ |
| 13304 | 13304 | #ifdef SQLITE_OMIT_EXPLAIN |
| 13305 | 13305 | # undef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 13306 | 13306 | #endif |
| 13307 | 13307 | |
| 13308 | +/* |
| 13309 | +** SQLITE_OMIT_VIRTUALTABLE implies SQLITE_OMIT_ALTERTABLE |
| 13310 | +*/ |
| 13311 | +#if defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_ALTERTABLE) |
| 13312 | +# define SQLITE_OMIT_ALTERTABLE |
| 13313 | +#endif |
| 13314 | + |
| 13308 | 13315 | /* |
| 13309 | 13316 | ** Return true (non-zero) if the input is an integer that is too large |
| 13310 | 13317 | ** to fit in 32-bits. This macro is used inside of various testcase() |
| 13311 | 13318 | ** macros to verify that we have tested SQLite for large-file support. |
| 13312 | 13319 | */ |
| | @@ -16403,11 +16410,11 @@ |
| 16403 | 16410 | u8 iDb; /* Which db file is being initialized */ |
| 16404 | 16411 | u8 busy; /* TRUE if currently initializing */ |
| 16405 | 16412 | unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */ |
| 16406 | 16413 | unsigned imposterTable : 1; /* Building an imposter table */ |
| 16407 | 16414 | unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */ |
| 16408 | | - char **azInit; /* "type", "name", and "tbl_name" columns */ |
| 16415 | + const char **azInit; /* "type", "name", and "tbl_name" columns */ |
| 16409 | 16416 | } init; |
| 16410 | 16417 | int nVdbeActive; /* Number of VDBEs currently running */ |
| 16411 | 16418 | int nVdbeRead; /* Number of active VDBEs that read or write */ |
| 16412 | 16419 | int nVdbeWrite; /* Number of active VDBEs that read and write */ |
| 16413 | 16420 | int nVdbeExec; /* Number of nested calls to VdbeExec() */ |
| | @@ -18967,11 +18974,11 @@ |
| 18967 | 18974 | SQLITE_PRIVATE void sqlite3WindowUnlinkFromSelect(Window*); |
| 18968 | 18975 | SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p); |
| 18969 | 18976 | SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*, u8); |
| 18970 | 18977 | SQLITE_PRIVATE void sqlite3WindowAttach(Parse*, Expr*, Window*); |
| 18971 | 18978 | SQLITE_PRIVATE void sqlite3WindowLink(Select *pSel, Window *pWin); |
| 18972 | | -SQLITE_PRIVATE int sqlite3WindowCompare(Parse*, Window*, Window*, int); |
| 18979 | +SQLITE_PRIVATE int sqlite3WindowCompare(const Parse*, const Window*, const Window*, int); |
| 18973 | 18980 | SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Select*); |
| 18974 | 18981 | SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int); |
| 18975 | 18982 | SQLITE_PRIVATE int sqlite3WindowRewrite(Parse*, Select*); |
| 18976 | 18983 | SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*); |
| 18977 | 18984 | SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p); |
| | @@ -19099,12 +19106,12 @@ |
| 19099 | 19106 | SQLITE_PRIVATE void *sqlite3Realloc(void*, u64); |
| 19100 | 19107 | SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64); |
| 19101 | 19108 | SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64); |
| 19102 | 19109 | SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*); |
| 19103 | 19110 | SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*); |
| 19104 | | -SQLITE_PRIVATE int sqlite3MallocSize(void*); |
| 19105 | | -SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*); |
| 19111 | +SQLITE_PRIVATE int sqlite3MallocSize(const void*); |
| 19112 | +SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, const void*); |
| 19106 | 19113 | SQLITE_PRIVATE void *sqlite3PageMalloc(int); |
| 19107 | 19114 | SQLITE_PRIVATE void sqlite3PageFree(void*); |
| 19108 | 19115 | SQLITE_PRIVATE void sqlite3MemSetDefault(void); |
| 19109 | 19116 | #ifndef SQLITE_UNTESTABLE |
| 19110 | 19117 | SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void)); |
| | @@ -19236,21 +19243,21 @@ |
| 19236 | 19243 | SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*); |
| 19237 | 19244 | SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*); |
| 19238 | 19245 | SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*); |
| 19239 | 19246 | SQLITE_PRIVATE Expr *sqlite3ExprAnd(Parse*,Expr*, Expr*); |
| 19240 | 19247 | SQLITE_PRIVATE Expr *sqlite3ExprSimplifiedAndOr(Expr*); |
| 19241 | | -SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int); |
| 19242 | | -SQLITE_PRIVATE void sqlite3ExprFunctionUsable(Parse*,Expr*,FuncDef*); |
| 19248 | +SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, const Token*, int); |
| 19249 | +SQLITE_PRIVATE void sqlite3ExprFunctionUsable(Parse*,const Expr*,const FuncDef*); |
| 19243 | 19250 | SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32); |
| 19244 | 19251 | SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*); |
| 19245 | 19252 | SQLITE_PRIVATE void sqlite3ExprDeferredDelete(Parse*, Expr*); |
| 19246 | 19253 | SQLITE_PRIVATE void sqlite3ExprUnmapAndDelete(Parse*, Expr*); |
| 19247 | 19254 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); |
| 19248 | 19255 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*); |
| 19249 | 19256 | SQLITE_PRIVATE Select *sqlite3ExprListToValues(Parse*, int, ExprList*); |
| 19250 | 19257 | SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int,int); |
| 19251 | | -SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); |
| 19258 | +SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,const Token*,int); |
| 19252 | 19259 | SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*); |
| 19253 | 19260 | SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*); |
| 19254 | 19261 | SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*); |
| 19255 | 19262 | SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index*); |
| 19256 | 19263 | SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**); |
| | @@ -19429,15 +19436,15 @@ |
| 19429 | 19436 | SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*); |
| 19430 | 19437 | SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); |
| 19431 | 19438 | SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); |
| 19432 | 19439 | SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*,Expr*); |
| 19433 | 19440 | SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int, sqlite3_value*); |
| 19434 | | -SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*); |
| 19435 | | -SQLITE_PRIVATE int sqlite3ExprCompare(Parse*,Expr*, Expr*, int); |
| 19436 | | -SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int); |
| 19437 | | -SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int); |
| 19438 | | -SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse*,Expr*, Expr*, int); |
| 19441 | +SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, const Token*); |
| 19442 | +SQLITE_PRIVATE int sqlite3ExprCompare(const Parse*,const Expr*,const Expr*, int); |
| 19443 | +SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*,Expr*,int); |
| 19444 | +SQLITE_PRIVATE int sqlite3ExprListCompare(const ExprList*,const ExprList*, int); |
| 19445 | +SQLITE_PRIVATE int sqlite3ExprImpliesExpr(const Parse*,const Expr*,const Expr*, int); |
| 19439 | 19446 | SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int); |
| 19440 | 19447 | SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*); |
| 19441 | 19448 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); |
| 19442 | 19449 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 19443 | 19450 | SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); |
| | @@ -19464,11 +19471,11 @@ |
| 19464 | 19471 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); |
| 19465 | 19472 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); |
| 19466 | 19473 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 19467 | 19474 | SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*); |
| 19468 | 19475 | #endif |
| 19469 | | -SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*); |
| 19476 | +SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*); |
| 19470 | 19477 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| 19471 | 19478 | SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); |
| 19472 | 19479 | SQLITE_PRIVATE int sqlite3IsRowid(const char*); |
| 19473 | 19480 | SQLITE_PRIVATE void sqlite3GenerateRowDelete( |
| 19474 | 19481 | Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int); |
| | @@ -19489,15 +19496,15 @@ |
| 19489 | 19496 | SQLITE_PRIVATE void sqlite3MultiWrite(Parse*); |
| 19490 | 19497 | SQLITE_PRIVATE void sqlite3MayAbort(Parse*); |
| 19491 | 19498 | SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8); |
| 19492 | 19499 | SQLITE_PRIVATE void sqlite3UniqueConstraint(Parse*, int, Index*); |
| 19493 | 19500 | SQLITE_PRIVATE void sqlite3RowidConstraint(Parse*, int, Table*); |
| 19494 | | -SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*,int); |
| 19495 | | -SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int); |
| 19496 | | -SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); |
| 19497 | | -SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*); |
| 19498 | | -SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*,int); |
| 19501 | +SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,const Expr*,int); |
| 19502 | +SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,const ExprList*,int); |
| 19503 | +SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,const SrcList*,int); |
| 19504 | +SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,const IdList*); |
| 19505 | +SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,const Select*,int); |
| 19499 | 19506 | SQLITE_PRIVATE FuncDef *sqlite3FunctionSearch(int,const char*); |
| 19500 | 19507 | SQLITE_PRIVATE void sqlite3InsertBuiltinFuncs(FuncDef*,int); |
| 19501 | 19508 | SQLITE_PRIVATE FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8); |
| 19502 | 19509 | SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(void); |
| 19503 | 19510 | SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void); |
| | @@ -19631,11 +19638,11 @@ |
| 19631 | 19638 | |
| 19632 | 19639 | SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3*, Index*); |
| 19633 | 19640 | SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int); |
| 19634 | 19641 | SQLITE_PRIVATE char sqlite3CompareAffinity(const Expr *pExpr, char aff2); |
| 19635 | 19642 | SQLITE_PRIVATE int sqlite3IndexAffinityOk(const Expr *pExpr, char idx_affinity); |
| 19636 | | -SQLITE_PRIVATE char sqlite3TableColumnAffinity(Table*,int); |
| 19643 | +SQLITE_PRIVATE char sqlite3TableColumnAffinity(const Table*,int); |
| 19637 | 19644 | SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr); |
| 19638 | 19645 | SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8); |
| 19639 | 19646 | SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*); |
| 19640 | 19647 | SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...); |
| 19641 | 19648 | SQLITE_PRIVATE void sqlite3Error(sqlite3*,int); |
| | @@ -19660,12 +19667,12 @@ |
| 19660 | 19667 | SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); |
| 19661 | 19668 | SQLITE_PRIVATE void sqlite3SetTextEncoding(sqlite3 *db, u8); |
| 19662 | 19669 | SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr); |
| 19663 | 19670 | SQLITE_PRIVATE CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr); |
| 19664 | 19671 | SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse*,const Expr*,const Expr*); |
| 19665 | | -SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int); |
| 19666 | | -SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*); |
| 19672 | +SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(const Parse *pParse, Expr*, const Token*, int); |
| 19673 | +SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(const Parse*,Expr*,const char*); |
| 19667 | 19674 | SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*); |
| 19668 | 19675 | SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr*); |
| 19669 | 19676 | SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *); |
| 19670 | 19677 | SQLITE_PRIVATE int sqlite3WritableSchema(sqlite3*); |
| 19671 | 19678 | SQLITE_PRIVATE int sqlite3CheckObjectName(Parse*, const char*,const char*,const char*); |
| | @@ -19692,11 +19699,11 @@ |
| 19692 | 19699 | #endif |
| 19693 | 19700 | SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *); |
| 19694 | 19701 | #ifndef SQLITE_OMIT_UTF16 |
| 19695 | 19702 | SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8); |
| 19696 | 19703 | #endif |
| 19697 | | -SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); |
| 19704 | +SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, const Expr *, u8, u8, sqlite3_value **); |
| 19698 | 19705 | SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); |
| 19699 | 19706 | #ifndef SQLITE_AMALGAMATION |
| 19700 | 19707 | SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[]; |
| 19701 | 19708 | SQLITE_PRIVATE const char sqlite3StrBINARY[]; |
| 19702 | 19709 | SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[]; |
| | @@ -19744,13 +19751,13 @@ |
| 19744 | 19751 | SQLITE_PRIVATE int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*); |
| 19745 | 19752 | SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*); |
| 19746 | 19753 | SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int); |
| 19747 | 19754 | SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *); |
| 19748 | 19755 | SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *, SrcList *); |
| 19749 | | -SQLITE_PRIVATE void sqlite3AlterDropColumn(Parse*, SrcList*, Token*); |
| 19750 | | -SQLITE_PRIVATE void *sqlite3RenameTokenMap(Parse*, void*, Token*); |
| 19751 | | -SQLITE_PRIVATE void sqlite3RenameTokenRemap(Parse*, void *pTo, void *pFrom); |
| 19756 | +SQLITE_PRIVATE void sqlite3AlterDropColumn(Parse*, SrcList*, const Token*); |
| 19757 | +SQLITE_PRIVATE const void *sqlite3RenameTokenMap(Parse*, const void*, const Token*); |
| 19758 | +SQLITE_PRIVATE void sqlite3RenameTokenRemap(Parse*, const void *pTo, const void *pFrom); |
| 19752 | 19759 | SQLITE_PRIVATE void sqlite3RenameExprUnmap(Parse*, Expr*); |
| 19753 | 19760 | SQLITE_PRIVATE void sqlite3RenameExprlistUnmap(Parse*, ExprList*); |
| 19754 | 19761 | SQLITE_PRIVATE CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); |
| 19755 | 19762 | SQLITE_PRIVATE char sqlite3AffinityType(const char*, Column*); |
| 19756 | 19763 | SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*); |
| | @@ -19790,10 +19797,12 @@ |
| 19790 | 19797 | SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); |
| 19791 | 19798 | SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); |
| 19792 | 19799 | |
| 19793 | 19800 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int); |
| 19794 | 19801 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 19802 | +SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8); |
| 19803 | +SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*); |
| 19795 | 19804 | SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); |
| 19796 | 19805 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); |
| 19797 | 19806 | |
| 19798 | 19807 | SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *); |
| 19799 | 19808 | SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *); |
| | @@ -20021,11 +20030,11 @@ |
| 20021 | 20030 | SQLITE_PRIVATE int sqlite3JournalIsInMemory(sqlite3_file *p); |
| 20022 | 20031 | SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *); |
| 20023 | 20032 | |
| 20024 | 20033 | SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p); |
| 20025 | 20034 | #if SQLITE_MAX_EXPR_DEPTH>0 |
| 20026 | | -SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *); |
| 20035 | +SQLITE_PRIVATE int sqlite3SelectExprHeight(const Select *); |
| 20027 | 20036 | SQLITE_PRIVATE int sqlite3ExprCheckHeight(Parse*, int); |
| 20028 | 20037 | #else |
| 20029 | 20038 | #define sqlite3SelectExprHeight(x) 0 |
| 20030 | 20039 | #define sqlite3ExprCheckHeight(x,y) |
| 20031 | 20040 | #endif |
| | @@ -20118,12 +20127,12 @@ |
| 20118 | 20127 | #endif |
| 20119 | 20128 | #if defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST) |
| 20120 | 20129 | SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3*); |
| 20121 | 20130 | #endif |
| 20122 | 20131 | |
| 20123 | | -SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr); |
| 20124 | | -SQLITE_PRIVATE int sqlite3ExprIsVector(Expr *pExpr); |
| 20132 | +SQLITE_PRIVATE int sqlite3ExprVectorSize(const Expr *pExpr); |
| 20133 | +SQLITE_PRIVATE int sqlite3ExprIsVector(const Expr *pExpr); |
| 20125 | 20134 | SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr*, int); |
| 20126 | 20135 | SQLITE_PRIVATE Expr *sqlite3ExprForVectorField(Parse*,Expr*,int,int); |
| 20127 | 20136 | SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse*, Expr*); |
| 20128 | 20137 | |
| 20129 | 20138 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| | @@ -23548,135 +23557,104 @@ |
| 23548 | 23557 | sqlite3_context *context, |
| 23549 | 23558 | int argc, |
| 23550 | 23559 | sqlite3_value **argv |
| 23551 | 23560 | ){ |
| 23552 | 23561 | DateTime x; |
| 23553 | | - u64 n; |
| 23554 | 23562 | size_t i,j; |
| 23555 | | - char *z; |
| 23556 | 23563 | sqlite3 *db; |
| 23557 | 23564 | const char *zFmt; |
| 23558 | | - char zBuf[100]; |
| 23565 | + sqlite3_str sRes; |
| 23566 | + |
| 23567 | + |
| 23559 | 23568 | if( argc==0 ) return; |
| 23560 | 23569 | zFmt = (const char*)sqlite3_value_text(argv[0]); |
| 23561 | 23570 | if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return; |
| 23562 | 23571 | db = sqlite3_context_db_handle(context); |
| 23563 | | - for(i=0, n=1; zFmt[i]; i++, n++){ |
| 23564 | | - if( zFmt[i]=='%' ){ |
| 23565 | | - switch( zFmt[i+1] ){ |
| 23566 | | - case 'd': |
| 23567 | | - case 'H': |
| 23568 | | - case 'm': |
| 23569 | | - case 'M': |
| 23570 | | - case 'S': |
| 23571 | | - case 'W': |
| 23572 | | - n++; |
| 23573 | | - /* fall thru */ |
| 23574 | | - case 'w': |
| 23575 | | - case '%': |
| 23576 | | - break; |
| 23577 | | - case 'f': |
| 23578 | | - n += 8; |
| 23579 | | - break; |
| 23580 | | - case 'j': |
| 23581 | | - n += 3; |
| 23582 | | - break; |
| 23583 | | - case 'Y': |
| 23584 | | - n += 8; |
| 23585 | | - break; |
| 23586 | | - case 's': |
| 23587 | | - case 'J': |
| 23588 | | - n += 50; |
| 23589 | | - break; |
| 23590 | | - default: |
| 23591 | | - return; /* ERROR. return a NULL */ |
| 23592 | | - } |
| 23593 | | - i++; |
| 23594 | | - } |
| 23595 | | - } |
| 23596 | | - testcase( n==sizeof(zBuf)-1 ); |
| 23597 | | - testcase( n==sizeof(zBuf) ); |
| 23598 | | - testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH]+1 ); |
| 23599 | | - testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ); |
| 23600 | | - if( n<sizeof(zBuf) ){ |
| 23601 | | - z = zBuf; |
| 23602 | | - }else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 23603 | | - sqlite3_result_error_toobig(context); |
| 23604 | | - return; |
| 23605 | | - }else{ |
| 23606 | | - z = sqlite3DbMallocRawNN(db, (int)n); |
| 23607 | | - if( z==0 ){ |
| 23608 | | - sqlite3_result_error_nomem(context); |
| 23609 | | - return; |
| 23610 | | - } |
| 23611 | | - } |
| 23572 | + sqlite3StrAccumInit(&sRes, 0, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 23573 | + |
| 23612 | 23574 | computeJD(&x); |
| 23613 | 23575 | computeYMD_HMS(&x); |
| 23614 | 23576 | for(i=j=0; zFmt[i]; i++){ |
| 23615 | | - if( zFmt[i]!='%' ){ |
| 23616 | | - z[j++] = zFmt[i]; |
| 23617 | | - }else{ |
| 23618 | | - i++; |
| 23619 | | - switch( zFmt[i] ){ |
| 23620 | | - case 'd': sqlite3_snprintf(3, &z[j],"%02d",x.D); j+=2; break; |
| 23621 | | - case 'f': { |
| 23622 | | - double s = x.s; |
| 23623 | | - if( s>59.999 ) s = 59.999; |
| 23624 | | - sqlite3_snprintf(7, &z[j],"%06.3f", s); |
| 23625 | | - j += sqlite3Strlen30(&z[j]); |
| 23626 | | - break; |
| 23627 | | - } |
| 23628 | | - case 'H': sqlite3_snprintf(3, &z[j],"%02d",x.h); j+=2; break; |
| 23629 | | - case 'W': /* Fall thru */ |
| 23630 | | - case 'j': { |
| 23631 | | - int nDay; /* Number of days since 1st day of year */ |
| 23632 | | - DateTime y = x; |
| 23633 | | - y.validJD = 0; |
| 23634 | | - y.M = 1; |
| 23635 | | - y.D = 1; |
| 23636 | | - computeJD(&y); |
| 23637 | | - nDay = (int)((x.iJD-y.iJD+43200000)/86400000); |
| 23638 | | - if( zFmt[i]=='W' ){ |
| 23639 | | - int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */ |
| 23640 | | - wd = (int)(((x.iJD+43200000)/86400000)%7); |
| 23641 | | - sqlite3_snprintf(3, &z[j],"%02d",(nDay+7-wd)/7); |
| 23642 | | - j += 2; |
| 23643 | | - }else{ |
| 23644 | | - sqlite3_snprintf(4, &z[j],"%03d",nDay+1); |
| 23645 | | - j += 3; |
| 23646 | | - } |
| 23647 | | - break; |
| 23648 | | - } |
| 23649 | | - case 'J': { |
| 23650 | | - sqlite3_snprintf(20, &z[j],"%.16g",x.iJD/86400000.0); |
| 23651 | | - j+=sqlite3Strlen30(&z[j]); |
| 23652 | | - break; |
| 23653 | | - } |
| 23654 | | - case 'm': sqlite3_snprintf(3, &z[j],"%02d",x.M); j+=2; break; |
| 23655 | | - case 'M': sqlite3_snprintf(3, &z[j],"%02d",x.m); j+=2; break; |
| 23656 | | - case 's': { |
| 23657 | | - i64 iS = (i64)(x.iJD/1000 - 21086676*(i64)10000); |
| 23658 | | - sqlite3Int64ToText(iS, &z[j]); |
| 23659 | | - j += sqlite3Strlen30(&z[j]); |
| 23660 | | - break; |
| 23661 | | - } |
| 23662 | | - case 'S': sqlite3_snprintf(3,&z[j],"%02d",(int)x.s); j+=2; break; |
| 23663 | | - case 'w': { |
| 23664 | | - z[j++] = (char)(((x.iJD+129600000)/86400000) % 7) + '0'; |
| 23665 | | - break; |
| 23666 | | - } |
| 23667 | | - case 'Y': { |
| 23668 | | - sqlite3_snprintf(5,&z[j],"%04d",x.Y); j+=sqlite3Strlen30(&z[j]); |
| 23669 | | - break; |
| 23670 | | - } |
| 23671 | | - default: z[j++] = '%'; break; |
| 23672 | | - } |
| 23673 | | - } |
| 23674 | | - } |
| 23675 | | - z[j] = 0; |
| 23676 | | - sqlite3_result_text(context, z, -1, |
| 23677 | | - z==zBuf ? SQLITE_TRANSIENT : SQLITE_DYNAMIC); |
| 23577 | + if( zFmt[i]!='%' ) continue; |
| 23578 | + if( j<i ) sqlite3_str_append(&sRes, zFmt+j, i-j); |
| 23579 | + i++; |
| 23580 | + j = i + 1; |
| 23581 | + switch( zFmt[i] ){ |
| 23582 | + case 'd': { |
| 23583 | + sqlite3_str_appendf(&sRes, "%02d", x.D); |
| 23584 | + break; |
| 23585 | + } |
| 23586 | + case 'f': { |
| 23587 | + double s = x.s; |
| 23588 | + if( s>59.999 ) s = 59.999; |
| 23589 | + sqlite3_str_appendf(&sRes, "%06.3f", s); |
| 23590 | + break; |
| 23591 | + } |
| 23592 | + case 'H': { |
| 23593 | + sqlite3_str_appendf(&sRes, "%02d", x.h); |
| 23594 | + break; |
| 23595 | + } |
| 23596 | + case 'W': /* Fall thru */ |
| 23597 | + case 'j': { |
| 23598 | + int nDay; /* Number of days since 1st day of year */ |
| 23599 | + DateTime y = x; |
| 23600 | + y.validJD = 0; |
| 23601 | + y.M = 1; |
| 23602 | + y.D = 1; |
| 23603 | + computeJD(&y); |
| 23604 | + nDay = (int)((x.iJD-y.iJD+43200000)/86400000); |
| 23605 | + if( zFmt[i]=='W' ){ |
| 23606 | + int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */ |
| 23607 | + wd = (int)(((x.iJD+43200000)/86400000)%7); |
| 23608 | + sqlite3_str_appendf(&sRes,"%02d",(nDay+7-wd)/7); |
| 23609 | + }else{ |
| 23610 | + sqlite3_str_appendf(&sRes,"%03d",nDay+1); |
| 23611 | + } |
| 23612 | + break; |
| 23613 | + } |
| 23614 | + case 'J': { |
| 23615 | + sqlite3_str_appendf(&sRes,"%.16g",x.iJD/86400000.0); |
| 23616 | + break; |
| 23617 | + } |
| 23618 | + case 'm': { |
| 23619 | + sqlite3_str_appendf(&sRes,"%02d",x.M); |
| 23620 | + break; |
| 23621 | + } |
| 23622 | + case 'M': { |
| 23623 | + sqlite3_str_appendf(&sRes,"%02d",x.m); |
| 23624 | + break; |
| 23625 | + } |
| 23626 | + case 's': { |
| 23627 | + i64 iS = (i64)(x.iJD/1000 - 21086676*(i64)10000); |
| 23628 | + sqlite3_str_appendf(&sRes,"%lld",iS); |
| 23629 | + break; |
| 23630 | + } |
| 23631 | + case 'S': { |
| 23632 | + sqlite3_str_appendf(&sRes,"%02d",(int)x.s); |
| 23633 | + break; |
| 23634 | + } |
| 23635 | + case 'w': { |
| 23636 | + sqlite3_str_appendchar(&sRes, 1, |
| 23637 | + (char)(((x.iJD+129600000)/86400000) % 7) + '0'); |
| 23638 | + break; |
| 23639 | + } |
| 23640 | + case 'Y': { |
| 23641 | + sqlite3_str_appendf(&sRes,"%04d",x.Y); |
| 23642 | + break; |
| 23643 | + } |
| 23644 | + case '%': { |
| 23645 | + sqlite3_str_appendchar(&sRes, 1, '%'); |
| 23646 | + break; |
| 23647 | + } |
| 23648 | + default: { |
| 23649 | + sqlite3_str_reset(&sRes); |
| 23650 | + return; |
| 23651 | + } |
| 23652 | + } |
| 23653 | + } |
| 23654 | + if( j<i ) sqlite3_str_append(&sRes, zFmt+j, i-j); |
| 23655 | + sqlite3ResultStrAccum(context, &sRes); |
| 23678 | 23656 | } |
| 23679 | 23657 | |
| 23680 | 23658 | /* |
| 23681 | 23659 | ** current_time() |
| 23682 | 23660 | ** |
| | @@ -23953,10 +23931,11 @@ |
| 23953 | 23931 | SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id){ |
| 23954 | 23932 | int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize; |
| 23955 | 23933 | return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE); |
| 23956 | 23934 | } |
| 23957 | 23935 | SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id){ |
| 23936 | + if( NEVER(id->pMethods==0) ) return 0; |
| 23958 | 23937 | return id->pMethods->xDeviceCharacteristics(id); |
| 23959 | 23938 | } |
| 23960 | 23939 | #ifndef SQLITE_OMIT_WAL |
| 23961 | 23940 | SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int offset, int n, int flags){ |
| 23962 | 23941 | return id->pMethods->xShmLock(id, offset, n, flags); |
| | @@ -28270,11 +28249,11 @@ |
| 28270 | 28249 | |
| 28271 | 28250 | /* |
| 28272 | 28251 | ** TRUE if p is a lookaside memory allocation from db |
| 28273 | 28252 | */ |
| 28274 | 28253 | #ifndef SQLITE_OMIT_LOOKASIDE |
| 28275 | | -static int isLookaside(sqlite3 *db, void *p){ |
| 28254 | +static int isLookaside(sqlite3 *db, const void *p){ |
| 28276 | 28255 | return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd); |
| 28277 | 28256 | } |
| 28278 | 28257 | #else |
| 28279 | 28258 | #define isLookaside(A,B) 0 |
| 28280 | 28259 | #endif |
| | @@ -28281,22 +28260,22 @@ |
| 28281 | 28260 | |
| 28282 | 28261 | /* |
| 28283 | 28262 | ** Return the size of a memory allocation previously obtained from |
| 28284 | 28263 | ** sqlite3Malloc() or sqlite3_malloc(). |
| 28285 | 28264 | */ |
| 28286 | | -SQLITE_PRIVATE int sqlite3MallocSize(void *p){ |
| 28265 | +SQLITE_PRIVATE int sqlite3MallocSize(const void *p){ |
| 28287 | 28266 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 28288 | | - return sqlite3GlobalConfig.m.xSize(p); |
| 28267 | + return sqlite3GlobalConfig.m.xSize((void*)p); |
| 28289 | 28268 | } |
| 28290 | | -static int lookasideMallocSize(sqlite3 *db, void *p){ |
| 28269 | +static int lookasideMallocSize(sqlite3 *db, const void *p){ |
| 28291 | 28270 | #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 28292 | 28271 | return p<db->lookaside.pMiddle ? db->lookaside.szTrue : LOOKASIDE_SMALL; |
| 28293 | 28272 | #else |
| 28294 | 28273 | return db->lookaside.szTrue; |
| 28295 | 28274 | #endif |
| 28296 | 28275 | } |
| 28297 | | -SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){ |
| 28276 | +SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, const void *p){ |
| 28298 | 28277 | assert( p!=0 ); |
| 28299 | 28278 | #ifdef SQLITE_DEBUG |
| 28300 | 28279 | if( db==0 || !isLookaside(db,p) ){ |
| 28301 | 28280 | if( db==0 ){ |
| 28302 | 28281 | assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); |
| | @@ -28319,11 +28298,11 @@ |
| 28319 | 28298 | assert( sqlite3_mutex_held(db->mutex) ); |
| 28320 | 28299 | return db->lookaside.szTrue; |
| 28321 | 28300 | } |
| 28322 | 28301 | } |
| 28323 | 28302 | } |
| 28324 | | - return sqlite3GlobalConfig.m.xSize(p); |
| 28303 | + return sqlite3GlobalConfig.m.xSize((void*)p); |
| 28325 | 28304 | } |
| 28326 | 28305 | SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){ |
| 28327 | 28306 | assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); |
| 28328 | 28307 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 28329 | 28308 | return p ? sqlite3GlobalConfig.m.xSize(p) : 0; |
| | @@ -28929,11 +28908,11 @@ |
| 28929 | 28908 | #endif /* SQLITE_OMIT_FLOATING_POINT */ |
| 28930 | 28909 | |
| 28931 | 28910 | /* |
| 28932 | 28911 | ** Set the StrAccum object to an error mode. |
| 28933 | 28912 | */ |
| 28934 | | -static void setStrAccumError(StrAccum *p, u8 eError){ |
| 28913 | +SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum *p, u8 eError){ |
| 28935 | 28914 | assert( eError==SQLITE_NOMEM || eError==SQLITE_TOOBIG ); |
| 28936 | 28915 | p->accError = eError; |
| 28937 | 28916 | if( p->mxAlloc ) sqlite3_str_reset(p); |
| 28938 | 28917 | if( eError==SQLITE_TOOBIG ) sqlite3ErrorToParser(p->db, eError); |
| 28939 | 28918 | } |
| | @@ -28965,16 +28944,16 @@ |
| 28965 | 28944 | */ |
| 28966 | 28945 | static char *printfTempBuf(sqlite3_str *pAccum, sqlite3_int64 n){ |
| 28967 | 28946 | char *z; |
| 28968 | 28947 | if( pAccum->accError ) return 0; |
| 28969 | 28948 | if( n>pAccum->nAlloc && n>pAccum->mxAlloc ){ |
| 28970 | | - setStrAccumError(pAccum, SQLITE_TOOBIG); |
| 28949 | + sqlite3StrAccumSetError(pAccum, SQLITE_TOOBIG); |
| 28971 | 28950 | return 0; |
| 28972 | 28951 | } |
| 28973 | 28952 | z = sqlite3DbMallocRaw(pAccum->db, n); |
| 28974 | 28953 | if( z==0 ){ |
| 28975 | | - setStrAccumError(pAccum, SQLITE_NOMEM); |
| 28954 | + sqlite3StrAccumSetError(pAccum, SQLITE_NOMEM); |
| 28976 | 28955 | } |
| 28977 | 28956 | return z; |
| 28978 | 28957 | } |
| 28979 | 28958 | |
| 28980 | 28959 | /* |
| | @@ -29709,11 +29688,11 @@ |
| 29709 | 29688 | testcase(p->accError==SQLITE_TOOBIG); |
| 29710 | 29689 | testcase(p->accError==SQLITE_NOMEM); |
| 29711 | 29690 | return 0; |
| 29712 | 29691 | } |
| 29713 | 29692 | if( p->mxAlloc==0 ){ |
| 29714 | | - setStrAccumError(p, SQLITE_TOOBIG); |
| 29693 | + sqlite3StrAccumSetError(p, SQLITE_TOOBIG); |
| 29715 | 29694 | return p->nAlloc - p->nChar - 1; |
| 29716 | 29695 | }else{ |
| 29717 | 29696 | char *zOld = isMalloced(p) ? p->zText : 0; |
| 29718 | 29697 | i64 szNew = p->nChar; |
| 29719 | 29698 | szNew += (sqlite3_int64)N + 1; |
| | @@ -29722,11 +29701,11 @@ |
| 29722 | 29701 | ** to avoid having to call this routine too often */ |
| 29723 | 29702 | szNew += p->nChar; |
| 29724 | 29703 | } |
| 29725 | 29704 | if( szNew > p->mxAlloc ){ |
| 29726 | 29705 | sqlite3_str_reset(p); |
| 29727 | | - setStrAccumError(p, SQLITE_TOOBIG); |
| 29706 | + sqlite3StrAccumSetError(p, SQLITE_TOOBIG); |
| 29728 | 29707 | return 0; |
| 29729 | 29708 | }else{ |
| 29730 | 29709 | p->nAlloc = (int)szNew; |
| 29731 | 29710 | } |
| 29732 | 29711 | if( p->db ){ |
| | @@ -29740,11 +29719,11 @@ |
| 29740 | 29719 | p->zText = zNew; |
| 29741 | 29720 | p->nAlloc = sqlite3DbMallocSize(p->db, zNew); |
| 29742 | 29721 | p->printfFlags |= SQLITE_PRINTF_MALLOCED; |
| 29743 | 29722 | }else{ |
| 29744 | 29723 | sqlite3_str_reset(p); |
| 29745 | | - setStrAccumError(p, SQLITE_NOMEM); |
| 29724 | + sqlite3StrAccumSetError(p, SQLITE_NOMEM); |
| 29746 | 29725 | return 0; |
| 29747 | 29726 | } |
| 29748 | 29727 | } |
| 29749 | 29728 | return N; |
| 29750 | 29729 | } |
| | @@ -29813,11 +29792,11 @@ |
| 29813 | 29792 | zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); |
| 29814 | 29793 | if( zText ){ |
| 29815 | 29794 | memcpy(zText, p->zText, p->nChar+1); |
| 29816 | 29795 | p->printfFlags |= SQLITE_PRINTF_MALLOCED; |
| 29817 | 29796 | }else{ |
| 29818 | | - setStrAccumError(p, SQLITE_NOMEM); |
| 29797 | + sqlite3StrAccumSetError(p, SQLITE_NOMEM); |
| 29819 | 29798 | } |
| 29820 | 29799 | p->zText = zText; |
| 29821 | 29800 | return zText; |
| 29822 | 29801 | } |
| 29823 | 29802 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){ |
| | @@ -29827,10 +29806,26 @@ |
| 29827 | 29806 | return strAccumFinishRealloc(p); |
| 29828 | 29807 | } |
| 29829 | 29808 | } |
| 29830 | 29809 | return p->zText; |
| 29831 | 29810 | } |
| 29811 | + |
| 29812 | +/* |
| 29813 | +** Use the content of the StrAccum passed as the second argument |
| 29814 | +** as the result of an SQL function. |
| 29815 | +*/ |
| 29816 | +SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context *pCtx, StrAccum *p){ |
| 29817 | + if( p->accError ){ |
| 29818 | + sqlite3_result_error_code(pCtx, p->accError); |
| 29819 | + sqlite3_str_reset(p); |
| 29820 | + }else if( isMalloced(p) ){ |
| 29821 | + sqlite3_result_text(pCtx, p->zText, p->nChar, SQLITE_DYNAMIC); |
| 29822 | + }else{ |
| 29823 | + sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC); |
| 29824 | + sqlite3_str_reset(p); |
| 29825 | + } |
| 29826 | +} |
| 29832 | 29827 | |
| 29833 | 29828 | /* |
| 29834 | 29829 | ** This singleton is an sqlite3_str object that is returned if |
| 29835 | 29830 | ** sqlite3_malloc() fails to provide space for a real one. This |
| 29836 | 29831 | ** sqlite3_str object accepts no new text and always returns |
| | @@ -57339,10 +57334,11 @@ |
| 57339 | 57334 | #endif |
| 57340 | 57335 | }else{ |
| 57341 | 57336 | pPager->zWal = 0; |
| 57342 | 57337 | } |
| 57343 | 57338 | #endif |
| 57339 | + (void)pPtr; /* Suppress warning about unused pPtr value */ |
| 57344 | 57340 | |
| 57345 | 57341 | if( nPathname ) sqlite3DbFree(0, zPathname); |
| 57346 | 57342 | pPager->pVfs = pVfs; |
| 57347 | 57343 | pPager->vfsFlags = vfsFlags; |
| 57348 | 57344 | |
| | @@ -70866,13 +70862,11 @@ |
| 70866 | 70862 | if( rc==SQLITE_OK ){ |
| 70867 | 70863 | getCellInfo(pCur); |
| 70868 | 70864 | if( pCur->info.nKey==intKey ){ |
| 70869 | 70865 | return SQLITE_OK; |
| 70870 | 70866 | } |
| 70871 | | - }else if( rc==SQLITE_DONE ){ |
| 70872 | | - rc = SQLITE_OK; |
| 70873 | | - }else{ |
| 70867 | + }else if( rc!=SQLITE_DONE ){ |
| 70874 | 70868 | return rc; |
| 70875 | 70869 | } |
| 70876 | 70870 | } |
| 70877 | 70871 | } |
| 70878 | 70872 | } |
| | @@ -74541,11 +74535,11 @@ |
| 74541 | 74535 | nIn = pSrc->pBt->usableSize - 4; |
| 74542 | 74536 | } |
| 74543 | 74537 | } |
| 74544 | 74538 | }while( rc==SQLITE_OK && nOut>0 ); |
| 74545 | 74539 | |
| 74546 | | - if( rc==SQLITE_OK && nRem>0 ){ |
| 74540 | + if( rc==SQLITE_OK && nRem>0 && ALWAYS(pPgnoOut) ){ |
| 74547 | 74541 | Pgno pgnoNew; |
| 74548 | 74542 | MemPage *pNew = 0; |
| 74549 | 74543 | rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0); |
| 74550 | 74544 | put4byte(pPgnoOut, pgnoNew); |
| 74551 | 74545 | if( ISAUTOVACUUM && pPageOut ){ |
| | @@ -78403,11 +78397,11 @@ |
| 78403 | 78397 | ** NULL and an SQLite error code returned. |
| 78404 | 78398 | */ |
| 78405 | 78399 | #ifdef SQLITE_ENABLE_STAT4 |
| 78406 | 78400 | static int valueFromFunction( |
| 78407 | 78401 | sqlite3 *db, /* The database connection */ |
| 78408 | | - Expr *p, /* The expression to evaluate */ |
| 78402 | + const Expr *p, /* The expression to evaluate */ |
| 78409 | 78403 | u8 enc, /* Encoding to use */ |
| 78410 | 78404 | u8 aff, /* Affinity to use */ |
| 78411 | 78405 | sqlite3_value **ppVal, /* Write the new value here */ |
| 78412 | 78406 | struct ValueNewStat4Ctx *pCtx /* Second argument for valueNew() */ |
| 78413 | 78407 | ){ |
| | @@ -78497,11 +78491,11 @@ |
| 78497 | 78491 | ** NULL, it is assumed that the caller will free any allocated object |
| 78498 | 78492 | ** in all cases. |
| 78499 | 78493 | */ |
| 78500 | 78494 | static int valueFromExpr( |
| 78501 | 78495 | sqlite3 *db, /* The database connection */ |
| 78502 | | - Expr *pExpr, /* The expression to evaluate */ |
| 78496 | + const Expr *pExpr, /* The expression to evaluate */ |
| 78503 | 78497 | u8 enc, /* Encoding to use */ |
| 78504 | 78498 | u8 affinity, /* Affinity to use */ |
| 78505 | 78499 | sqlite3_value **ppVal, /* Write the new value here */ |
| 78506 | 78500 | struct ValueNewStat4Ctx *pCtx /* Second argument for valueNew() */ |
| 78507 | 78501 | ){ |
| | @@ -78652,11 +78646,11 @@ |
| 78652 | 78646 | ** the value by passing it to sqlite3ValueFree() later on. If the expression |
| 78653 | 78647 | ** cannot be converted to a value, then *ppVal is set to NULL. |
| 78654 | 78648 | */ |
| 78655 | 78649 | SQLITE_PRIVATE int sqlite3ValueFromExpr( |
| 78656 | 78650 | sqlite3 *db, /* The database connection */ |
| 78657 | | - Expr *pExpr, /* The expression to evaluate */ |
| 78651 | + const Expr *pExpr, /* The expression to evaluate */ |
| 78658 | 78652 | u8 enc, /* Encoding to use */ |
| 78659 | 78653 | u8 affinity, /* Affinity to use */ |
| 78660 | 78654 | sqlite3_value **ppVal /* Write the new value here */ |
| 78661 | 78655 | ){ |
| 78662 | 78656 | return pExpr ? valueFromExpr(db, pExpr, enc, affinity, ppVal, 0) : 0; |
| | @@ -86316,15 +86310,13 @@ |
| 86316 | 86310 | Mem *pVar; /* Value of a host parameter */ |
| 86317 | 86311 | StrAccum out; /* Accumulate the output here */ |
| 86318 | 86312 | #ifndef SQLITE_OMIT_UTF16 |
| 86319 | 86313 | Mem utf8; /* Used to convert UTF16 into UTF8 for display */ |
| 86320 | 86314 | #endif |
| 86321 | | - char zBase[100]; /* Initial working space */ |
| 86322 | 86315 | |
| 86323 | 86316 | db = p->db; |
| 86324 | | - sqlite3StrAccumInit(&out, 0, zBase, sizeof(zBase), |
| 86325 | | - db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 86317 | + sqlite3StrAccumInit(&out, 0, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 86326 | 86318 | if( db->nVdbeExec>1 ){ |
| 86327 | 86319 | while( *zRawSql ){ |
| 86328 | 86320 | const char *zStart = zRawSql; |
| 86329 | 86321 | while( *(zRawSql++)!='\n' && *zRawSql ); |
| 86330 | 86322 | sqlite3_str_append(&out, "-- ", 3); |
| | @@ -94164,11 +94156,10 @@ |
| 94164 | 94156 | assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int ); |
| 94165 | 94157 | nArg = (int)pArgc->u.i; |
| 94166 | 94158 | iQuery = (int)pQuery->u.i; |
| 94167 | 94159 | |
| 94168 | 94160 | /* Invoke the xFilter method */ |
| 94169 | | - res = 0; |
| 94170 | 94161 | apArg = p->apArg; |
| 94171 | 94162 | for(i = 0; i<nArg; i++){ |
| 94172 | 94163 | apArg[i] = &pArgc[i+1]; |
| 94173 | 94164 | } |
| 94174 | 94165 | rc = pModule->xFilter(pVCur, iQuery, pOp->p4.z, nArg, apArg); |
| | @@ -94254,11 +94245,10 @@ |
| 94254 | 94245 | sqlite3_vtab *pVtab; |
| 94255 | 94246 | const sqlite3_module *pModule; |
| 94256 | 94247 | int res; |
| 94257 | 94248 | VdbeCursor *pCur; |
| 94258 | 94249 | |
| 94259 | | - res = 0; |
| 94260 | 94250 | pCur = p->apCsr[pOp->p1]; |
| 94261 | 94251 | assert( pCur->eCurType==CURTYPE_VTAB ); |
| 94262 | 94252 | if( pCur->nullRow ){ |
| 94263 | 94253 | break; |
| 94264 | 94254 | } |
| | @@ -100392,13 +100382,15 @@ |
| 100392 | 100382 | int nRef = pNC->nRef; |
| 100393 | 100383 | testcase( pNC->ncFlags & NC_IsCheck ); |
| 100394 | 100384 | testcase( pNC->ncFlags & NC_PartIdx ); |
| 100395 | 100385 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 100396 | 100386 | testcase( pNC->ncFlags & NC_GenCol ); |
| 100397 | | - sqlite3ResolveNotValid(pParse, pNC, "subqueries", |
| 100398 | | - NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr); |
| 100399 | | - sqlite3WalkSelect(pWalker, pExpr->x.pSelect); |
| 100387 | + if( pNC->ncFlags & NC_SelfRef ){ |
| 100388 | + notValidImpl(pParse, pNC, "subqueries", pExpr); |
| 100389 | + }else{ |
| 100390 | + sqlite3WalkSelect(pWalker, pExpr->x.pSelect); |
| 100391 | + } |
| 100400 | 100392 | assert( pNC->nRef>=nRef ); |
| 100401 | 100393 | if( nRef!=pNC->nRef ){ |
| 100402 | 100394 | ExprSetProperty(pExpr, EP_VarSelect); |
| 100403 | 100395 | pNC->ncFlags |= NC_VarSelect; |
| 100404 | 100396 | } |
| | @@ -101322,11 +101314,11 @@ |
| 101322 | 101314 | static int exprCodeVector(Parse *pParse, Expr *p, int *piToFree); |
| 101323 | 101315 | |
| 101324 | 101316 | /* |
| 101325 | 101317 | ** Return the affinity character for a single column of a table. |
| 101326 | 101318 | */ |
| 101327 | | -SQLITE_PRIVATE char sqlite3TableColumnAffinity(Table *pTab, int iCol){ |
| 101319 | +SQLITE_PRIVATE char sqlite3TableColumnAffinity(const Table *pTab, int iCol){ |
| 101328 | 101320 | assert( iCol<pTab->nCol ); |
| 101329 | 101321 | return iCol>=0 ? pTab->aCol[iCol].affinity : SQLITE_AFF_INTEGER; |
| 101330 | 101322 | } |
| 101331 | 101323 | |
| 101332 | 101324 | /* |
| | @@ -101393,11 +101385,11 @@ |
| 101393 | 101385 | ** |
| 101394 | 101386 | ** If a memory allocation error occurs, that fact is recorded in pParse->db |
| 101395 | 101387 | ** and the pExpr parameter is returned unchanged. |
| 101396 | 101388 | */ |
| 101397 | 101389 | SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken( |
| 101398 | | - Parse *pParse, /* Parsing context */ |
| 101390 | + const Parse *pParse, /* Parsing context */ |
| 101399 | 101391 | Expr *pExpr, /* Add the "COLLATE" clause to this expression */ |
| 101400 | 101392 | const Token *pCollName, /* Name of collating sequence */ |
| 101401 | 101393 | int dequote /* True to dequote pCollName */ |
| 101402 | 101394 | ){ |
| 101403 | 101395 | if( pCollName->n>0 ){ |
| | @@ -101408,11 +101400,15 @@ |
| 101408 | 101400 | pExpr = pNew; |
| 101409 | 101401 | } |
| 101410 | 101402 | } |
| 101411 | 101403 | return pExpr; |
| 101412 | 101404 | } |
| 101413 | | -SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr, const char *zC){ |
| 101405 | +SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString( |
| 101406 | + const Parse *pParse, /* Parsing context */ |
| 101407 | + Expr *pExpr, /* Add the "COLLATE" clause to this expression */ |
| 101408 | + const char *zC /* The collating sequence name */ |
| 101409 | +){ |
| 101414 | 101410 | Token s; |
| 101415 | 101411 | assert( zC!=0 ); |
| 101416 | 101412 | sqlite3TokenInit(&s, (char*)zC); |
| 101417 | 101413 | return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0); |
| 101418 | 101414 | } |
| | @@ -101710,21 +101706,21 @@ |
| 101710 | 101706 | ** columns of result. Every TK_VECTOR node is an vector because the |
| 101711 | 101707 | ** parser will not generate a TK_VECTOR with fewer than two entries. |
| 101712 | 101708 | ** But a TK_SELECT might be either a vector or a scalar. It is only |
| 101713 | 101709 | ** considered a vector if it has two or more result columns. |
| 101714 | 101710 | */ |
| 101715 | | -SQLITE_PRIVATE int sqlite3ExprIsVector(Expr *pExpr){ |
| 101711 | +SQLITE_PRIVATE int sqlite3ExprIsVector(const Expr *pExpr){ |
| 101716 | 101712 | return sqlite3ExprVectorSize(pExpr)>1; |
| 101717 | 101713 | } |
| 101718 | 101714 | |
| 101719 | 101715 | /* |
| 101720 | 101716 | ** If the expression passed as the only argument is of type TK_VECTOR |
| 101721 | 101717 | ** return the number of expressions in the vector. Or, if the expression |
| 101722 | 101718 | ** is a sub-select, return the number of columns in the sub-select. For |
| 101723 | 101719 | ** any other type of expression, return 1. |
| 101724 | 101720 | */ |
| 101725 | | -SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr){ |
| 101721 | +SQLITE_PRIVATE int sqlite3ExprVectorSize(const Expr *pExpr){ |
| 101726 | 101722 | u8 op = pExpr->op; |
| 101727 | 101723 | if( op==TK_REGISTER ) op = pExpr->op2; |
| 101728 | 101724 | if( op==TK_VECTOR ){ |
| 101729 | 101725 | return pExpr->x.pList->nExpr; |
| 101730 | 101726 | }else if( op==TK_SELECT ){ |
| | @@ -101813,13 +101809,20 @@ |
| 101813 | 101809 | pRet->iTable = nField; |
| 101814 | 101810 | pRet->iColumn = iField; |
| 101815 | 101811 | pRet->pLeft = pVector; |
| 101816 | 101812 | } |
| 101817 | 101813 | }else{ |
| 101818 | | - if( pVector->op==TK_VECTOR ) pVector = pVector->x.pList->a[iField].pExpr; |
| 101814 | + if( pVector->op==TK_VECTOR ){ |
| 101815 | + Expr **ppVector = &pVector->x.pList->a[iField].pExpr; |
| 101816 | + pVector = *ppVector; |
| 101817 | + if( IN_RENAME_OBJECT ){ |
| 101818 | + /* This must be a vector UPDATE inside a trigger */ |
| 101819 | + *ppVector = 0; |
| 101820 | + return pVector; |
| 101821 | + } |
| 101822 | + } |
| 101819 | 101823 | pRet = sqlite3ExprDup(pParse->db, pVector, 0); |
| 101820 | | - sqlite3RenameTokenRemap(pParse, pRet, pVector); |
| 101821 | 101824 | } |
| 101822 | 101825 | return pRet; |
| 101823 | 101826 | } |
| 101824 | 101827 | |
| 101825 | 101828 | /* |
| | @@ -102008,27 +102011,27 @@ |
| 102008 | 102011 | ** |
| 102009 | 102012 | ** If this maximum height is greater than the current value pointed |
| 102010 | 102013 | ** to by pnHeight, the second parameter, then set *pnHeight to that |
| 102011 | 102014 | ** value. |
| 102012 | 102015 | */ |
| 102013 | | -static void heightOfExpr(Expr *p, int *pnHeight){ |
| 102016 | +static void heightOfExpr(const Expr *p, int *pnHeight){ |
| 102014 | 102017 | if( p ){ |
| 102015 | 102018 | if( p->nHeight>*pnHeight ){ |
| 102016 | 102019 | *pnHeight = p->nHeight; |
| 102017 | 102020 | } |
| 102018 | 102021 | } |
| 102019 | 102022 | } |
| 102020 | | -static void heightOfExprList(ExprList *p, int *pnHeight){ |
| 102023 | +static void heightOfExprList(const ExprList *p, int *pnHeight){ |
| 102021 | 102024 | if( p ){ |
| 102022 | 102025 | int i; |
| 102023 | 102026 | for(i=0; i<p->nExpr; i++){ |
| 102024 | 102027 | heightOfExpr(p->a[i].pExpr, pnHeight); |
| 102025 | 102028 | } |
| 102026 | 102029 | } |
| 102027 | 102030 | } |
| 102028 | | -static void heightOfSelect(Select *pSelect, int *pnHeight){ |
| 102029 | | - Select *p; |
| 102031 | +static void heightOfSelect(const Select *pSelect, int *pnHeight){ |
| 102032 | + const Select *p; |
| 102030 | 102033 | for(p=pSelect; p; p=p->pPrior){ |
| 102031 | 102034 | heightOfExpr(p->pWhere, pnHeight); |
| 102032 | 102035 | heightOfExpr(p->pHaving, pnHeight); |
| 102033 | 102036 | heightOfExpr(p->pLimit, pnHeight); |
| 102034 | 102037 | heightOfExprList(p->pEList, pnHeight); |
| | @@ -102076,11 +102079,11 @@ |
| 102076 | 102079 | |
| 102077 | 102080 | /* |
| 102078 | 102081 | ** Return the maximum height of any expression tree referenced |
| 102079 | 102082 | ** by the select statement passed as an argument. |
| 102080 | 102083 | */ |
| 102081 | | -SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *p){ |
| 102084 | +SQLITE_PRIVATE int sqlite3SelectExprHeight(const Select *p){ |
| 102082 | 102085 | int nHeight = 0; |
| 102083 | 102086 | heightOfSelect(p, &nHeight); |
| 102084 | 102087 | return nHeight; |
| 102085 | 102088 | } |
| 102086 | 102089 | #else /* ABOVE: Height enforcement enabled. BELOW: Height enforcement off */ |
| | @@ -102329,11 +102332,11 @@ |
| 102329 | 102332 | ** arguments. |
| 102330 | 102333 | */ |
| 102331 | 102334 | SQLITE_PRIVATE Expr *sqlite3ExprFunction( |
| 102332 | 102335 | Parse *pParse, /* Parsing context */ |
| 102333 | 102336 | ExprList *pList, /* Argument list */ |
| 102334 | | - Token *pToken, /* Name of the function */ |
| 102337 | + const Token *pToken, /* Name of the function */ |
| 102335 | 102338 | int eDistinct /* SF_Distinct or SF_ALL or 0 */ |
| 102336 | 102339 | ){ |
| 102337 | 102340 | Expr *pNew; |
| 102338 | 102341 | sqlite3 *db = pParse->db; |
| 102339 | 102342 | assert( pToken ); |
| | @@ -102367,12 +102370,12 @@ |
| 102367 | 102370 | ** |
| 102368 | 102371 | ** If the function is not usable, create an error. |
| 102369 | 102372 | */ |
| 102370 | 102373 | SQLITE_PRIVATE void sqlite3ExprFunctionUsable( |
| 102371 | 102374 | Parse *pParse, /* Parsing and code generating context */ |
| 102372 | | - Expr *pExpr, /* The function invocation */ |
| 102373 | | - FuncDef *pDef /* The function being invoked */ |
| 102375 | + const Expr *pExpr, /* The function invocation */ |
| 102376 | + const FuncDef *pDef /* The function being invoked */ |
| 102374 | 102377 | ){ |
| 102375 | 102378 | assert( !IN_RENAME_OBJECT ); |
| 102376 | 102379 | assert( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 ); |
| 102377 | 102380 | if( ExprHasProperty(pExpr, EP_FromDDL) ){ |
| 102378 | 102381 | if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0 |
| | @@ -102548,11 +102551,11 @@ |
| 102548 | 102551 | /* |
| 102549 | 102552 | ** Return the number of bytes allocated for the expression structure |
| 102550 | 102553 | ** passed as the first argument. This is always one of EXPR_FULLSIZE, |
| 102551 | 102554 | ** EXPR_REDUCEDSIZE or EXPR_TOKENONLYSIZE. |
| 102552 | 102555 | */ |
| 102553 | | -static int exprStructSize(Expr *p){ |
| 102556 | +static int exprStructSize(const Expr *p){ |
| 102554 | 102557 | if( ExprHasProperty(p, EP_TokenOnly) ) return EXPR_TOKENONLYSIZE; |
| 102555 | 102558 | if( ExprHasProperty(p, EP_Reduced) ) return EXPR_REDUCEDSIZE; |
| 102556 | 102559 | return EXPR_FULLSIZE; |
| 102557 | 102560 | } |
| 102558 | 102561 | |
| | @@ -102588,11 +102591,11 @@ |
| 102588 | 102591 | ** make an EXPRDUP_REDUCE copy of a reduced expression. It is only legal |
| 102589 | 102592 | ** to reduce a pristine expression tree from the parser. The implementation |
| 102590 | 102593 | ** of dupedExprStructSize() contain multiple assert() statements that attempt |
| 102591 | 102594 | ** to enforce this constraint. |
| 102592 | 102595 | */ |
| 102593 | | -static int dupedExprStructSize(Expr *p, int flags){ |
| 102596 | +static int dupedExprStructSize(const Expr *p, int flags){ |
| 102594 | 102597 | int nSize; |
| 102595 | 102598 | assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */ |
| 102596 | 102599 | assert( EXPR_FULLSIZE<=0xfff ); |
| 102597 | 102600 | assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 ); |
| 102598 | 102601 | if( 0==flags || p->op==TK_SELECT_COLUMN |
| | @@ -102619,11 +102622,11 @@ |
| 102619 | 102622 | /* |
| 102620 | 102623 | ** This function returns the space in bytes required to store the copy |
| 102621 | 102624 | ** of the Expr structure and a copy of the Expr.u.zToken string (if that |
| 102622 | 102625 | ** string is defined.) |
| 102623 | 102626 | */ |
| 102624 | | -static int dupedExprNodeSize(Expr *p, int flags){ |
| 102627 | +static int dupedExprNodeSize(const Expr *p, int flags){ |
| 102625 | 102628 | int nByte = dupedExprStructSize(p, flags) & 0xfff; |
| 102626 | 102629 | if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){ |
| 102627 | 102630 | nByte += sqlite3Strlen30NN(p->u.zToken)+1; |
| 102628 | 102631 | } |
| 102629 | 102632 | return ROUND8(nByte); |
| | @@ -102640,11 +102643,11 @@ |
| 102640 | 102643 | ** If the EXPRDUP_REDUCE flag is set, then the return value includes |
| 102641 | 102644 | ** space to duplicate all Expr nodes in the tree formed by Expr.pLeft |
| 102642 | 102645 | ** and Expr.pRight variables (but not for any structures pointed to or |
| 102643 | 102646 | ** descended from the Expr.x.pList or Expr.x.pSelect variables). |
| 102644 | 102647 | */ |
| 102645 | | -static int dupedExprSize(Expr *p, int flags){ |
| 102648 | +static int dupedExprSize(const Expr *p, int flags){ |
| 102646 | 102649 | int nByte = 0; |
| 102647 | 102650 | if( p ){ |
| 102648 | 102651 | nByte = dupedExprNodeSize(p, flags); |
| 102649 | 102652 | if( flags&EXPRDUP_REDUCE ){ |
| 102650 | 102653 | nByte += dupedExprSize(p->pLeft, flags) + dupedExprSize(p->pRight, flags); |
| | @@ -102659,11 +102662,11 @@ |
| 102659 | 102662 | ** to store the copy of expression p, the copies of p->u.zToken |
| 102660 | 102663 | ** (if applicable), and the copies of the p->pLeft and p->pRight expressions, |
| 102661 | 102664 | ** if any. Before returning, *pzBuffer is set to the first byte past the |
| 102662 | 102665 | ** portion of the buffer copied into by this function. |
| 102663 | 102666 | */ |
| 102664 | | -static Expr *exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer){ |
| 102667 | +static Expr *exprDup(sqlite3 *db, const Expr *p, int dupFlags, u8 **pzBuffer){ |
| 102665 | 102668 | Expr *pNew; /* Value to return */ |
| 102666 | 102669 | u8 *zAlloc; /* Memory space from which to build Expr object */ |
| 102667 | 102670 | u32 staticFlag; /* EP_Static if space not obtained from malloc */ |
| 102668 | 102671 | |
| 102669 | 102672 | assert( db!=0 ); |
| | @@ -102840,17 +102843,18 @@ |
| 102840 | 102843 | ** The flags parameter contains a combination of the EXPRDUP_XXX flags. |
| 102841 | 102844 | ** If the EXPRDUP_REDUCE flag is set, then the structure returned is a |
| 102842 | 102845 | ** truncated version of the usual Expr structure that will be stored as |
| 102843 | 102846 | ** part of the in-memory representation of the database schema. |
| 102844 | 102847 | */ |
| 102845 | | -SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){ |
| 102848 | +SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, const Expr *p, int flags){ |
| 102846 | 102849 | assert( flags==0 || flags==EXPRDUP_REDUCE ); |
| 102847 | 102850 | return p ? exprDup(db, p, flags, 0) : 0; |
| 102848 | 102851 | } |
| 102849 | | -SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){ |
| 102852 | +SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, const ExprList *p, int flags){ |
| 102850 | 102853 | ExprList *pNew; |
| 102851 | | - struct ExprList_item *pItem, *pOldItem; |
| 102854 | + struct ExprList_item *pItem; |
| 102855 | + const struct ExprList_item *pOldItem; |
| 102852 | 102856 | int i; |
| 102853 | 102857 | Expr *pPriorSelectColOld = 0; |
| 102854 | 102858 | Expr *pPriorSelectColNew = 0; |
| 102855 | 102859 | assert( db!=0 ); |
| 102856 | 102860 | if( p==0 ) return 0; |
| | @@ -102898,11 +102902,11 @@ |
| 102898 | 102902 | ** sqlite3SelectDup(), can be called. sqlite3SelectDup() is sometimes |
| 102899 | 102903 | ** called with a NULL argument. |
| 102900 | 102904 | */ |
| 102901 | 102905 | #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) \ |
| 102902 | 102906 | || !defined(SQLITE_OMIT_SUBQUERY) |
| 102903 | | -SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){ |
| 102907 | +SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3 *db, const SrcList *p, int flags){ |
| 102904 | 102908 | SrcList *pNew; |
| 102905 | 102909 | int i; |
| 102906 | 102910 | int nByte; |
| 102907 | 102911 | assert( db!=0 ); |
| 102908 | 102912 | if( p==0 ) return 0; |
| | @@ -102910,11 +102914,11 @@ |
| 102910 | 102914 | pNew = sqlite3DbMallocRawNN(db, nByte ); |
| 102911 | 102915 | if( pNew==0 ) return 0; |
| 102912 | 102916 | pNew->nSrc = pNew->nAlloc = p->nSrc; |
| 102913 | 102917 | for(i=0; i<p->nSrc; i++){ |
| 102914 | 102918 | SrcItem *pNewItem = &pNew->a[i]; |
| 102915 | | - SrcItem *pOldItem = &p->a[i]; |
| 102919 | + const SrcItem *pOldItem = &p->a[i]; |
| 102916 | 102920 | Table *pTab; |
| 102917 | 102921 | pNewItem->pSchema = pOldItem->pSchema; |
| 102918 | 102922 | pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase); |
| 102919 | 102923 | pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); |
| 102920 | 102924 | pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias); |
| | @@ -102942,11 +102946,11 @@ |
| 102942 | 102946 | pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing); |
| 102943 | 102947 | pNewItem->colUsed = pOldItem->colUsed; |
| 102944 | 102948 | } |
| 102945 | 102949 | return pNew; |
| 102946 | 102950 | } |
| 102947 | | -SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){ |
| 102951 | +SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, const IdList *p){ |
| 102948 | 102952 | IdList *pNew; |
| 102949 | 102953 | int i; |
| 102950 | 102954 | assert( db!=0 ); |
| 102951 | 102955 | if( p==0 ) return 0; |
| 102952 | 102956 | pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) ); |
| | @@ -102966,15 +102970,15 @@ |
| 102966 | 102970 | pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); |
| 102967 | 102971 | pNewItem->idx = pOldItem->idx; |
| 102968 | 102972 | } |
| 102969 | 102973 | return pNew; |
| 102970 | 102974 | } |
| 102971 | | -SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *pDup, int flags){ |
| 102975 | +SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, const Select *pDup, int flags){ |
| 102972 | 102976 | Select *pRet = 0; |
| 102973 | 102977 | Select *pNext = 0; |
| 102974 | 102978 | Select **pp = &pRet; |
| 102975 | | - Select *p; |
| 102979 | + const Select *p; |
| 102976 | 102980 | |
| 102977 | 102981 | assert( db!=0 ); |
| 102978 | 102982 | for(p=pDup; p; p=p->pPrior){ |
| 102979 | 102983 | Select *pNew = sqlite3DbMallocRawNN(db, sizeof(*p) ); |
| 102980 | 102984 | if( pNew==0 ) break; |
| | @@ -103211,11 +103215,11 @@ |
| 103211 | 103215 | ** is set. |
| 103212 | 103216 | */ |
| 103213 | 103217 | SQLITE_PRIVATE void sqlite3ExprListSetName( |
| 103214 | 103218 | Parse *pParse, /* Parsing context */ |
| 103215 | 103219 | ExprList *pList, /* List to which to add the span. */ |
| 103216 | | - Token *pName, /* Name to be added */ |
| 103220 | + const Token *pName, /* Name to be added */ |
| 103217 | 103221 | int dequote /* True to cause the name to be dequoted */ |
| 103218 | 103222 | ){ |
| 103219 | 103223 | assert( pList!=0 || pParse->db->mallocFailed!=0 ); |
| 103220 | 103224 | assert( pParse->eParseMode!=PARSE_MODE_UNMAP || dequote==0 ); |
| 103221 | 103225 | if( pList ){ |
| | @@ -103229,11 +103233,11 @@ |
| 103229 | 103233 | /* If dequote==0, then pName->z does not point to part of a DDL |
| 103230 | 103234 | ** statement handled by the parser. And so no token need be added |
| 103231 | 103235 | ** to the token-map. */ |
| 103232 | 103236 | sqlite3Dequote(pItem->zEName); |
| 103233 | 103237 | if( IN_RENAME_OBJECT ){ |
| 103234 | | - sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName); |
| 103238 | + sqlite3RenameTokenMap(pParse, (const void*)pItem->zEName, pName); |
| 103235 | 103239 | } |
| 103236 | 103240 | } |
| 103237 | 103241 | } |
| 103238 | 103242 | } |
| 103239 | 103243 | |
| | @@ -103657,11 +103661,11 @@ |
| 103657 | 103661 | ** If the expression p codes a constant integer that is small enough |
| 103658 | 103662 | ** to fit in a 32-bit integer, return 1 and put the value of the integer |
| 103659 | 103663 | ** in *pValue. If the expression is not an integer or if it is too big |
| 103660 | 103664 | ** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged. |
| 103661 | 103665 | */ |
| 103662 | | -SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr *p, int *pValue){ |
| 103666 | +SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr *p, int *pValue){ |
| 103663 | 103667 | int rc = 0; |
| 103664 | 103668 | if( NEVER(p==0) ) return 0; /* Used to only happen following on OOM */ |
| 103665 | 103669 | |
| 103666 | 103670 | /* If an expression is an integer literal that fits in a signed 32-bit |
| 103667 | 103671 | ** integer, then the EP_IntValue flag will have already been set */ |
| | @@ -103790,11 +103794,11 @@ |
| 103790 | 103794 | ** a pointer to the SELECT statement. If pX is not a SELECT statement, |
| 103791 | 103795 | ** or if the SELECT statement needs to be manifested into a transient |
| 103792 | 103796 | ** table, then return NULL. |
| 103793 | 103797 | */ |
| 103794 | 103798 | #ifndef SQLITE_OMIT_SUBQUERY |
| 103795 | | -static Select *isCandidateForInOpt(Expr *pX){ |
| 103799 | +static Select *isCandidateForInOpt(const Expr *pX){ |
| 103796 | 103800 | Select *p; |
| 103797 | 103801 | SrcList *pSrc; |
| 103798 | 103802 | ExprList *pEList; |
| 103799 | 103803 | Table *pTab; |
| 103800 | 103804 | int i; |
| | @@ -104168,11 +104172,11 @@ |
| 104168 | 104172 | ** the affinities to be used for each column of the comparison. |
| 104169 | 104173 | ** |
| 104170 | 104174 | ** It is the responsibility of the caller to ensure that the returned |
| 104171 | 104175 | ** string is eventually freed using sqlite3DbFree(). |
| 104172 | 104176 | */ |
| 104173 | | -static char *exprINAffinity(Parse *pParse, Expr *pExpr){ |
| 104177 | +static char *exprINAffinity(Parse *pParse, const Expr *pExpr){ |
| 104174 | 104178 | Expr *pLeft = pExpr->pLeft; |
| 104175 | 104179 | int nVal = sqlite3ExprVectorSize(pLeft); |
| 104176 | 104180 | Select *pSelect = (pExpr->flags & EP_xIsSelect) ? pExpr->x.pSelect : 0; |
| 104177 | 104181 | char *zRet; |
| 104178 | 104182 | |
| | @@ -106087,11 +106091,11 @@ |
| 106087 | 106091 | assert( pParse->pVdbe!=0 || pParse->db->mallocFailed ); |
| 106088 | 106092 | if( pParse->pVdbe==0 ) return; |
| 106089 | 106093 | inReg = sqlite3ExprCodeTarget(pParse, pExpr, target); |
| 106090 | 106094 | if( inReg!=target ){ |
| 106091 | 106095 | u8 op; |
| 106092 | | - if( ExprHasProperty(pExpr,EP_Subquery) ){ |
| 106096 | + if( ALWAYS(pExpr) && ExprHasProperty(pExpr,EP_Subquery) ){ |
| 106093 | 106097 | op = OP_Copy; |
| 106094 | 106098 | }else{ |
| 106095 | 106099 | op = OP_SCopy; |
| 106096 | 106100 | } |
| 106097 | 106101 | sqlite3VdbeAddOp2(pParse->pVdbe, op, inReg, target); |
| | @@ -106625,11 +106629,15 @@ |
| 106625 | 106629 | ** Additionally, if pExpr is a simple SQL value and the value is the |
| 106626 | 106630 | ** same as that currently bound to variable pVar, non-zero is returned. |
| 106627 | 106631 | ** Otherwise, if the values are not the same or if pExpr is not a simple |
| 106628 | 106632 | ** SQL value, zero is returned. |
| 106629 | 106633 | */ |
| 106630 | | -static int exprCompareVariable(Parse *pParse, Expr *pVar, Expr *pExpr){ |
| 106634 | +static int exprCompareVariable( |
| 106635 | + const Parse *pParse, |
| 106636 | + const Expr *pVar, |
| 106637 | + const Expr *pExpr |
| 106638 | +){ |
| 106631 | 106639 | int res = 0; |
| 106632 | 106640 | int iVar; |
| 106633 | 106641 | sqlite3_value *pL, *pR = 0; |
| 106634 | 106642 | |
| 106635 | 106643 | sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, SQLITE_AFF_BLOB, &pR); |
| | @@ -106677,11 +106685,16 @@ |
| 106677 | 106685 | ** pParse->pVdbe->expmask bitmask is updated for each variable referenced. |
| 106678 | 106686 | ** If pParse is NULL (the normal case) then any TK_VARIABLE term in |
| 106679 | 106687 | ** Argument pParse should normally be NULL. If it is not NULL and pA or |
| 106680 | 106688 | ** pB causes a return value of 2. |
| 106681 | 106689 | */ |
| 106682 | | -SQLITE_PRIVATE int sqlite3ExprCompare(Parse *pParse, Expr *pA, Expr *pB, int iTab){ |
| 106690 | +SQLITE_PRIVATE int sqlite3ExprCompare( |
| 106691 | + const Parse *pParse, |
| 106692 | + const Expr *pA, |
| 106693 | + const Expr *pB, |
| 106694 | + int iTab |
| 106695 | +){ |
| 106683 | 106696 | u32 combinedFlags; |
| 106684 | 106697 | if( pA==0 || pB==0 ){ |
| 106685 | 106698 | return pB==pA ? 0 : 2; |
| 106686 | 106699 | } |
| 106687 | 106700 | if( pParse && pA->op==TK_VARIABLE && exprCompareVariable(pParse, pA, pB) ){ |
| | @@ -106761,11 +106774,11 @@ |
| 106761 | 106774 | ** a malfunction will result. |
| 106762 | 106775 | ** |
| 106763 | 106776 | ** Two NULL pointers are considered to be the same. But a NULL pointer |
| 106764 | 106777 | ** always differs from a non-NULL pointer. |
| 106765 | 106778 | */ |
| 106766 | | -SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList *pA, ExprList *pB, int iTab){ |
| 106779 | +SQLITE_PRIVATE int sqlite3ExprListCompare(const ExprList *pA, const ExprList *pB, int iTab){ |
| 106767 | 106780 | int i; |
| 106768 | 106781 | if( pA==0 && pB==0 ) return 0; |
| 106769 | 106782 | if( pA==0 || pB==0 ) return 1; |
| 106770 | 106783 | if( pA->nExpr!=pB->nExpr ) return 1; |
| 106771 | 106784 | for(i=0; i<pA->nExpr; i++){ |
| | @@ -106780,11 +106793,11 @@ |
| 106780 | 106793 | |
| 106781 | 106794 | /* |
| 106782 | 106795 | ** Like sqlite3ExprCompare() except COLLATE operators at the top-level |
| 106783 | 106796 | ** are ignored. |
| 106784 | 106797 | */ |
| 106785 | | -SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr *pA, Expr *pB, int iTab){ |
| 106798 | +SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr *pA,Expr *pB, int iTab){ |
| 106786 | 106799 | return sqlite3ExprCompare(0, |
| 106787 | 106800 | sqlite3ExprSkipCollateAndLikely(pA), |
| 106788 | 106801 | sqlite3ExprSkipCollateAndLikely(pB), |
| 106789 | 106802 | iTab); |
| 106790 | 106803 | } |
| | @@ -106794,13 +106807,13 @@ |
| 106794 | 106807 | ** |
| 106795 | 106808 | ** Or if seenNot is true, return non-zero if Expr p can only be |
| 106796 | 106809 | ** non-NULL if pNN is not NULL |
| 106797 | 106810 | */ |
| 106798 | 106811 | static int exprImpliesNotNull( |
| 106799 | | - Parse *pParse, /* Parsing context */ |
| 106800 | | - Expr *p, /* The expression to be checked */ |
| 106801 | | - Expr *pNN, /* The expression that is NOT NULL */ |
| 106812 | + const Parse *pParse,/* Parsing context */ |
| 106813 | + const Expr *p, /* The expression to be checked */ |
| 106814 | + const Expr *pNN, /* The expression that is NOT NULL */ |
| 106802 | 106815 | int iTab, /* Table being evaluated */ |
| 106803 | 106816 | int seenNot /* Return true only if p can be any non-NULL value */ |
| 106804 | 106817 | ){ |
| 106805 | 106818 | assert( p ); |
| 106806 | 106819 | assert( pNN ); |
| | @@ -106889,11 +106902,16 @@ |
| 106889 | 106902 | ** |
| 106890 | 106903 | ** When in doubt, return false. Returning true might give a performance |
| 106891 | 106904 | ** improvement. Returning false might cause a performance reduction, but |
| 106892 | 106905 | ** it will always give the correct answer and is hence always safe. |
| 106893 | 106906 | */ |
| 106894 | | -SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse *pParse, Expr *pE1, Expr *pE2, int iTab){ |
| 106907 | +SQLITE_PRIVATE int sqlite3ExprImpliesExpr( |
| 106908 | + const Parse *pParse, |
| 106909 | + const Expr *pE1, |
| 106910 | + const Expr *pE2, |
| 106911 | + int iTab |
| 106912 | +){ |
| 106895 | 106913 | if( sqlite3ExprCompare(pParse, pE1, pE2, iTab)==0 ){ |
| 106896 | 106914 | return 1; |
| 106897 | 106915 | } |
| 106898 | 106916 | if( pE2->op==TK_OR |
| 106899 | 106917 | && (sqlite3ExprImpliesExpr(pParse, pE1, pE2->pLeft, iTab) |
| | @@ -108220,11 +108238,11 @@ |
| 108220 | 108238 | ** After the parse finishes, renameTokenFind() routine can be used |
| 108221 | 108239 | ** to look up the actual token value that created some element in |
| 108222 | 108240 | ** the parse tree. |
| 108223 | 108241 | */ |
| 108224 | 108242 | struct RenameToken { |
| 108225 | | - void *p; /* Parse tree element created by token t */ |
| 108243 | + const void *p; /* Parse tree element created by token t */ |
| 108226 | 108244 | Token t; /* The token that created parse tree element p */ |
| 108227 | 108245 | RenameToken *pNext; /* Next is a list of all RenameToken objects */ |
| 108228 | 108246 | }; |
| 108229 | 108247 | |
| 108230 | 108248 | /* |
| | @@ -108262,13 +108280,13 @@ |
| 108262 | 108280 | ** if( x==y ) ... |
| 108263 | 108281 | ** |
| 108264 | 108282 | ** Technically, as x no longer points into a valid object or to the byte |
| 108265 | 108283 | ** following a valid object, it may not be used in comparison operations. |
| 108266 | 108284 | */ |
| 108267 | | -static void renameTokenCheckAll(Parse *pParse, void *pPtr){ |
| 108285 | +static void renameTokenCheckAll(Parse *pParse, const void *pPtr){ |
| 108268 | 108286 | if( pParse->nErr==0 && pParse->db->mallocFailed==0 ){ |
| 108269 | | - RenameToken *p; |
| 108287 | + const RenameToken *p; |
| 108270 | 108288 | u8 i = 0; |
| 108271 | 108289 | for(p=pParse->pRename; p; p=p->pNext){ |
| 108272 | 108290 | if( p->p ){ |
| 108273 | 108291 | assert( p->p!=pPtr ); |
| 108274 | 108292 | i += *(u8*)(p->p); |
| | @@ -108290,11 +108308,15 @@ |
| 108290 | 108308 | ** |
| 108291 | 108309 | ** The pPtr argument is returned so that this routine can be used |
| 108292 | 108310 | ** with tail recursion in tokenExpr() routine, for a small performance |
| 108293 | 108311 | ** improvement. |
| 108294 | 108312 | */ |
| 108295 | | -SQLITE_PRIVATE void *sqlite3RenameTokenMap(Parse *pParse, void *pPtr, Token *pToken){ |
| 108313 | +SQLITE_PRIVATE const void *sqlite3RenameTokenMap( |
| 108314 | + Parse *pParse, |
| 108315 | + const void *pPtr, |
| 108316 | + const Token *pToken |
| 108317 | +){ |
| 108296 | 108318 | RenameToken *pNew; |
| 108297 | 108319 | assert( pPtr || pParse->db->mallocFailed ); |
| 108298 | 108320 | renameTokenCheckAll(pParse, pPtr); |
| 108299 | 108321 | if( ALWAYS(pParse->eParseMode!=PARSE_MODE_UNMAP) ){ |
| 108300 | 108322 | pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken)); |
| | @@ -108312,11 +108334,11 @@ |
| 108312 | 108334 | /* |
| 108313 | 108335 | ** It is assumed that there is already a RenameToken object associated |
| 108314 | 108336 | ** with parse tree element pFrom. This function remaps the associated token |
| 108315 | 108337 | ** to parse tree element pTo. |
| 108316 | 108338 | */ |
| 108317 | | -SQLITE_PRIVATE void sqlite3RenameTokenRemap(Parse *pParse, void *pTo, void *pFrom){ |
| 108339 | +SQLITE_PRIVATE void sqlite3RenameTokenRemap(Parse *pParse, const void *pTo, const void *pFrom){ |
| 108318 | 108340 | RenameToken *p; |
| 108319 | 108341 | renameTokenCheckAll(pParse, pTo); |
| 108320 | 108342 | for(p=pParse->pRename; p; p=p->pNext){ |
| 108321 | 108343 | if( p->p==pFrom ){ |
| 108322 | 108344 | p->p = pTo; |
| | @@ -108328,11 +108350,12 @@ |
| 108328 | 108350 | /* |
| 108329 | 108351 | ** Walker callback used by sqlite3RenameExprUnmap(). |
| 108330 | 108352 | */ |
| 108331 | 108353 | static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){ |
| 108332 | 108354 | Parse *pParse = pWalker->pParse; |
| 108333 | | - sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr); |
| 108355 | + sqlite3RenameTokenRemap(pParse, 0, (const void*)pExpr); |
| 108356 | + sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab); |
| 108334 | 108357 | return WRC_Continue; |
| 108335 | 108358 | } |
| 108336 | 108359 | |
| 108337 | 108360 | /* |
| 108338 | 108361 | ** Iterate through the Select objects that are part of WITH clauses attached |
| | @@ -108358,10 +108381,11 @@ |
| 108358 | 108381 | Select *p = pWith->a[i].pSelect; |
| 108359 | 108382 | NameContext sNC; |
| 108360 | 108383 | memset(&sNC, 0, sizeof(sNC)); |
| 108361 | 108384 | sNC.pParse = pParse; |
| 108362 | 108385 | if( pCopy ) sqlite3SelectPrep(sNC.pParse, p, &sNC); |
| 108386 | + if( sNC.pParse->db->mallocFailed ) return; |
| 108363 | 108387 | sqlite3WalkSelect(pWalker, p); |
| 108364 | 108388 | sqlite3RenameExprlistUnmap(pParse, pWith->a[i].pCols); |
| 108365 | 108389 | } |
| 108366 | 108390 | if( pCopy && pParse->pWith==pCopy ){ |
| 108367 | 108391 | pParse->pWith = pCopy->pOuter; |
| | @@ -108372,16 +108396,16 @@ |
| 108372 | 108396 | /* |
| 108373 | 108397 | ** Unmap all tokens in the IdList object passed as the second argument. |
| 108374 | 108398 | */ |
| 108375 | 108399 | static void unmapColumnIdlistNames( |
| 108376 | 108400 | Parse *pParse, |
| 108377 | | - IdList *pIdList |
| 108401 | + const IdList *pIdList |
| 108378 | 108402 | ){ |
| 108379 | 108403 | if( pIdList ){ |
| 108380 | 108404 | int ii; |
| 108381 | 108405 | for(ii=0; ii<pIdList->nId; ii++){ |
| 108382 | | - sqlite3RenameTokenRemap(pParse, 0, (void*)pIdList->a[ii].zName); |
| 108406 | + sqlite3RenameTokenRemap(pParse, 0, (const void*)pIdList->a[ii].zName); |
| 108383 | 108407 | } |
| 108384 | 108408 | } |
| 108385 | 108409 | } |
| 108386 | 108410 | |
| 108387 | 108411 | /* |
| | @@ -108389,13 +108413,11 @@ |
| 108389 | 108413 | */ |
| 108390 | 108414 | static int renameUnmapSelectCb(Walker *pWalker, Select *p){ |
| 108391 | 108415 | Parse *pParse = pWalker->pParse; |
| 108392 | 108416 | int i; |
| 108393 | 108417 | if( pParse->nErr ) return WRC_Abort; |
| 108394 | | - if( p->selFlags & (SF_View|SF_CopyCte) ){ |
| 108395 | | - testcase( p->selFlags & SF_View ); |
| 108396 | | - testcase( p->selFlags & SF_CopyCte ); |
| 108418 | + if( NEVER(p->selFlags & (SF_View|SF_CopyCte)) ){ |
| 108397 | 108419 | return WRC_Prune; |
| 108398 | 108420 | } |
| 108399 | 108421 | if( ALWAYS(p->pEList) ){ |
| 108400 | 108422 | ExprList *pList = p->pEList; |
| 108401 | 108423 | for(i=0; i<pList->nExpr; i++){ |
| | @@ -108406,11 +108428,11 @@ |
| 108406 | 108428 | } |
| 108407 | 108429 | if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */ |
| 108408 | 108430 | SrcList *pSrc = p->pSrc; |
| 108409 | 108431 | for(i=0; i<pSrc->nSrc; i++){ |
| 108410 | 108432 | sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName); |
| 108411 | | - if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort; |
| 108433 | + sqlite3WalkExpr(pWalker, pSrc->a[i].pOn); |
| 108412 | 108434 | unmapColumnIdlistNames(pParse, pSrc->a[i].pUsing); |
| 108413 | 108435 | } |
| 108414 | 108436 | } |
| 108415 | 108437 | |
| 108416 | 108438 | renameWalkWith(pWalker, p); |
| | @@ -108474,11 +108496,11 @@ |
| 108474 | 108496 | ** the list maintained by the RenameCtx object. |
| 108475 | 108497 | */ |
| 108476 | 108498 | static RenameToken *renameTokenFind( |
| 108477 | 108499 | Parse *pParse, |
| 108478 | 108500 | struct RenameCtx *pCtx, |
| 108479 | | - void *pPtr |
| 108501 | + const void *pPtr |
| 108480 | 108502 | ){ |
| 108481 | 108503 | RenameToken **pp; |
| 108482 | 108504 | if( NEVER(pPtr==0) ){ |
| 108483 | 108505 | return 0; |
| 108484 | 108506 | } |
| | @@ -108593,22 +108615,22 @@ |
| 108593 | 108615 | ** to the RenameCtx pCtx. |
| 108594 | 108616 | */ |
| 108595 | 108617 | static void renameColumnElistNames( |
| 108596 | 108618 | Parse *pParse, |
| 108597 | 108619 | RenameCtx *pCtx, |
| 108598 | | - ExprList *pEList, |
| 108620 | + const ExprList *pEList, |
| 108599 | 108621 | const char *zOld |
| 108600 | 108622 | ){ |
| 108601 | 108623 | if( pEList ){ |
| 108602 | 108624 | int i; |
| 108603 | 108625 | for(i=0; i<pEList->nExpr; i++){ |
| 108604 | | - char *zName = pEList->a[i].zEName; |
| 108626 | + const char *zName = pEList->a[i].zEName; |
| 108605 | 108627 | if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) |
| 108606 | 108628 | && ALWAYS(zName!=0) |
| 108607 | 108629 | && 0==sqlite3_stricmp(zName, zOld) |
| 108608 | 108630 | ){ |
| 108609 | | - renameTokenFind(pParse, pCtx, (void*)zName); |
| 108631 | + renameTokenFind(pParse, pCtx, (const void*)zName); |
| 108610 | 108632 | } |
| 108611 | 108633 | } |
| 108612 | 108634 | } |
| 108613 | 108635 | } |
| 108614 | 108636 | |
| | @@ -108618,19 +108640,19 @@ |
| 108618 | 108640 | ** from Parse object pParse and add it to the RenameCtx pCtx. |
| 108619 | 108641 | */ |
| 108620 | 108642 | static void renameColumnIdlistNames( |
| 108621 | 108643 | Parse *pParse, |
| 108622 | 108644 | RenameCtx *pCtx, |
| 108623 | | - IdList *pIdList, |
| 108645 | + const IdList *pIdList, |
| 108624 | 108646 | const char *zOld |
| 108625 | 108647 | ){ |
| 108626 | 108648 | if( pIdList ){ |
| 108627 | 108649 | int i; |
| 108628 | 108650 | for(i=0; i<pIdList->nId; i++){ |
| 108629 | | - char *zName = pIdList->a[i].zName; |
| 108651 | + const char *zName = pIdList->a[i].zName; |
| 108630 | 108652 | if( 0==sqlite3_stricmp(zName, zOld) ){ |
| 108631 | | - renameTokenFind(pParse, pCtx, (void*)zName); |
| 108653 | + renameTokenFind(pParse, pCtx, (const void*)zName); |
| 108632 | 108654 | } |
| 108633 | 108655 | } |
| 108634 | 108656 | } |
| 108635 | 108657 | } |
| 108636 | 108658 | |
| | @@ -109326,11 +109348,11 @@ |
| 109326 | 109348 | return; |
| 109327 | 109349 | } |
| 109328 | 109350 | |
| 109329 | 109351 | static int renameQuotefixExprCb(Walker *pWalker, Expr *pExpr){ |
| 109330 | 109352 | if( pExpr->op==TK_STRING && (pExpr->flags & EP_DblQuoted) ){ |
| 109331 | | - renameTokenFind(pWalker->pParse, pWalker->u.pRename, (void*)pExpr); |
| 109353 | + renameTokenFind(pWalker->pParse, pWalker->u.pRename, (const void*)pExpr); |
| 109332 | 109354 | } |
| 109333 | 109355 | return WRC_Continue; |
| 109334 | 109356 | } |
| 109335 | 109357 | |
| 109336 | 109358 | /* |
| | @@ -109596,11 +109618,11 @@ |
| 109596 | 109618 | ** ALTER TABLE pSrc DROP COLUMN pName |
| 109597 | 109619 | ** |
| 109598 | 109620 | ** statement. Argument pSrc contains the possibly qualified name of the |
| 109599 | 109621 | ** table being edited, and token pName the name of the column to drop. |
| 109600 | 109622 | */ |
| 109601 | | -SQLITE_PRIVATE void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, Token *pName){ |
| 109623 | +SQLITE_PRIVATE void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, const Token *pName){ |
| 109602 | 109624 | sqlite3 *db = pParse->db; /* Database handle */ |
| 109603 | 109625 | Table *pTab; /* Table to modify */ |
| 109604 | 109626 | int iDb; /* Index of db containing pTab in aDb[] */ |
| 109605 | 109627 | const char *zDb; /* Database containing pTab ("main" etc.) */ |
| 109606 | 109628 | char *zCol = 0; /* Name of column to drop */ |
| | @@ -110181,11 +110203,10 @@ |
| 110181 | 110203 | n += sizeof(tRowcnt)*nColUp /* StatAccum.anLt */ |
| 110182 | 110204 | + sizeof(StatSample)*(nCol+mxSample) /* StatAccum.aBest[], a[] */ |
| 110183 | 110205 | + sizeof(tRowcnt)*3*nColUp*(nCol+mxSample); |
| 110184 | 110206 | } |
| 110185 | 110207 | #endif |
| 110186 | | - db = sqlite3_context_db_handle(context); |
| 110187 | 110208 | p = sqlite3DbMallocZero(db, n); |
| 110188 | 110209 | if( p==0 ){ |
| 110189 | 110210 | sqlite3_result_error_nomem(context); |
| 110190 | 110211 | return; |
| 110191 | 110212 | } |
| | @@ -110600,32 +110621,23 @@ |
| 110600 | 110621 | ** If D is the count of distinct values and K is the total number of |
| 110601 | 110622 | ** rows, then each estimate is computed as: |
| 110602 | 110623 | ** |
| 110603 | 110624 | ** I = (K+D-1)/D |
| 110604 | 110625 | */ |
| 110605 | | - char *z; |
| 110606 | | - int i; |
| 110607 | | - |
| 110608 | | - char *zRet = sqlite3MallocZero( (p->nKeyCol+1)*25 ); |
| 110609 | | - if( zRet==0 ){ |
| 110610 | | - sqlite3_result_error_nomem(context); |
| 110611 | | - return; |
| 110612 | | - } |
| 110613 | | - |
| 110614 | | - sqlite3_snprintf(24, zRet, "%llu", |
| 110615 | | - p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow); |
| 110616 | | - z = zRet + sqlite3Strlen30(zRet); |
| 110626 | + sqlite3_str sStat; /* Text of the constructed "stat" line */ |
| 110627 | + int i; /* Loop counter */ |
| 110628 | + |
| 110629 | + sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100); |
| 110630 | + sqlite3_str_appendf(&sStat, "%llu", |
| 110631 | + p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow); |
| 110617 | 110632 | for(i=0; i<p->nKeyCol; i++){ |
| 110618 | 110633 | u64 nDistinct = p->current.anDLt[i] + 1; |
| 110619 | 110634 | u64 iVal = (p->nRow + nDistinct - 1) / nDistinct; |
| 110620 | | - sqlite3_snprintf(24, z, " %llu", iVal); |
| 110621 | | - z += sqlite3Strlen30(z); |
| 110635 | + sqlite3_str_appendf(&sStat, " %llu", iVal); |
| 110622 | 110636 | assert( p->current.anEq[i] ); |
| 110623 | 110637 | } |
| 110624 | | - assert( z[0]=='\0' && z>zRet ); |
| 110625 | | - |
| 110626 | | - sqlite3_result_text(context, zRet, -1, sqlite3_free); |
| 110638 | + sqlite3ResultStrAccum(context, &sStat); |
| 110627 | 110639 | } |
| 110628 | 110640 | #ifdef SQLITE_ENABLE_STAT4 |
| 110629 | 110641 | else if( eCall==STAT_GET_ROWID ){ |
| 110630 | 110642 | if( p->iGet<0 ){ |
| 110631 | 110643 | samplePushPrevious(p, 0); |
| | @@ -110640,10 +110652,12 @@ |
| 110640 | 110652 | SQLITE_TRANSIENT); |
| 110641 | 110653 | } |
| 110642 | 110654 | } |
| 110643 | 110655 | }else{ |
| 110644 | 110656 | tRowcnt *aCnt = 0; |
| 110657 | + sqlite3_str sStat; |
| 110658 | + int i; |
| 110645 | 110659 | |
| 110646 | 110660 | assert( p->iGet<p->nSample ); |
| 110647 | 110661 | switch( eCall ){ |
| 110648 | 110662 | case STAT_GET_NEQ: aCnt = p->a[p->iGet].anEq; break; |
| 110649 | 110663 | case STAT_GET_NLT: aCnt = p->a[p->iGet].anLt; break; |
| | @@ -110651,27 +110665,16 @@ |
| 110651 | 110665 | aCnt = p->a[p->iGet].anDLt; |
| 110652 | 110666 | p->iGet++; |
| 110653 | 110667 | break; |
| 110654 | 110668 | } |
| 110655 | 110669 | } |
| 110656 | | - |
| 110657 | | - { |
| 110658 | | - char *zRet = sqlite3MallocZero(p->nCol * 25); |
| 110659 | | - if( zRet==0 ){ |
| 110660 | | - sqlite3_result_error_nomem(context); |
| 110661 | | - }else{ |
| 110662 | | - int i; |
| 110663 | | - char *z = zRet; |
| 110664 | | - for(i=0; i<p->nCol; i++){ |
| 110665 | | - sqlite3_snprintf(24, z, "%llu ", (u64)aCnt[i]); |
| 110666 | | - z += sqlite3Strlen30(z); |
| 110667 | | - } |
| 110668 | | - assert( z[0]=='\0' && z>zRet ); |
| 110669 | | - z[-1] = '\0'; |
| 110670 | | - sqlite3_result_text(context, zRet, -1, sqlite3_free); |
| 110671 | | - } |
| 110672 | | - } |
| 110670 | + sqlite3StrAccumInit(&sStat, 0, 0, 0, p->nCol*100); |
| 110671 | + for(i=0; i<p->nCol; i++){ |
| 110672 | + sqlite3_str_appendf(&sStat, "%llu ", (u64)aCnt[i]); |
| 110673 | + } |
| 110674 | + if( sStat.nChar ) sStat.nChar--; |
| 110675 | + sqlite3ResultStrAccum(context, &sStat); |
| 110673 | 110676 | } |
| 110674 | 110677 | #endif /* SQLITE_ENABLE_STAT4 */ |
| 110675 | 110678 | #ifndef SQLITE_DEBUG |
| 110676 | 110679 | UNUSED_PARAMETER( argc ); |
| 110677 | 110680 | #endif |
| | @@ -111588,13 +111591,16 @@ |
| 111588 | 111591 | ** Load content from the sqlite_stat4 table into |
| 111589 | 111592 | ** the Index.aSample[] arrays of all indices. |
| 111590 | 111593 | */ |
| 111591 | 111594 | static int loadStat4(sqlite3 *db, const char *zDb){ |
| 111592 | 111595 | int rc = SQLITE_OK; /* Result codes from subroutines */ |
| 111596 | + const Table *pStat4; |
| 111593 | 111597 | |
| 111594 | 111598 | assert( db->lookaside.bDisable ); |
| 111595 | | - if( sqlite3FindTable(db, "sqlite_stat4", zDb) ){ |
| 111599 | + if( (pStat4 = sqlite3FindTable(db, "sqlite_stat4", zDb))!=0 |
| 111600 | + && IsOrdinaryTable(pStat4) |
| 111601 | + ){ |
| 111596 | 111602 | rc = loadStatTbl(db, |
| 111597 | 111603 | "SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx", |
| 111598 | 111604 | "SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4", |
| 111599 | 111605 | zDb |
| 111600 | 111606 | ); |
| | @@ -111627,10 +111633,11 @@ |
| 111627 | 111633 | analysisInfo sInfo; |
| 111628 | 111634 | HashElem *i; |
| 111629 | 111635 | char *zSql; |
| 111630 | 111636 | int rc = SQLITE_OK; |
| 111631 | 111637 | Schema *pSchema = db->aDb[iDb].pSchema; |
| 111638 | + const Table *pStat1; |
| 111632 | 111639 | |
| 111633 | 111640 | assert( iDb>=0 && iDb<db->nDb ); |
| 111634 | 111641 | assert( db->aDb[iDb].pBt!=0 ); |
| 111635 | 111642 | |
| 111636 | 111643 | /* Clear any prior statistics */ |
| | @@ -111649,11 +111656,13 @@ |
| 111649 | 111656 | } |
| 111650 | 111657 | |
| 111651 | 111658 | /* Load new statistics out of the sqlite_stat1 table */ |
| 111652 | 111659 | sInfo.db = db; |
| 111653 | 111660 | sInfo.zDatabase = db->aDb[iDb].zDbSName; |
| 111654 | | - if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){ |
| 111661 | + if( (pStat1 = sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)) |
| 111662 | + && IsOrdinaryTable(pStat1) |
| 111663 | + ){ |
| 111655 | 111664 | zSql = sqlite3MPrintf(db, |
| 111656 | 111665 | "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase); |
| 111657 | 111666 | if( zSql==0 ){ |
| 111658 | 111667 | rc = SQLITE_NOMEM_BKPT; |
| 111659 | 111668 | }else{ |
| | @@ -113453,14 +113462,14 @@ |
| 113453 | 113462 | ** |
| 113454 | 113463 | ** Tokens are often just pointers into the original SQL text and so |
| 113455 | 113464 | ** are not \000 terminated and are not persistent. The returned string |
| 113456 | 113465 | ** is \000 terminated and is persistent. |
| 113457 | 113466 | */ |
| 113458 | | -SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3 *db, Token *pName){ |
| 113467 | +SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3 *db, const Token *pName){ |
| 113459 | 113468 | char *zName; |
| 113460 | 113469 | if( pName ){ |
| 113461 | | - zName = sqlite3DbStrNDup(db, (char*)pName->z, pName->n); |
| 113470 | + zName = sqlite3DbStrNDup(db, (const char*)pName->z, pName->n); |
| 113462 | 113471 | sqlite3Dequote(zName); |
| 113463 | 113472 | }else{ |
| 113464 | 113473 | zName = 0; |
| 113465 | 113474 | } |
| 113466 | 113475 | return zName; |
| | @@ -116947,11 +116956,11 @@ |
| 116947 | 116956 | if( pTab ){ |
| 116948 | 116957 | /* Ensure all REPLACE indexes on pTab are at the end of the pIndex list. |
| 116949 | 116958 | ** The list was already ordered when this routine was entered, so at this |
| 116950 | 116959 | ** point at most a single index (the newly added index) will be out of |
| 116951 | 116960 | ** order. So we have to reorder at most one index. */ |
| 116952 | | - Index **ppFrom = &pTab->pIndex; |
| 116961 | + Index **ppFrom; |
| 116953 | 116962 | Index *pThis; |
| 116954 | 116963 | for(ppFrom=&pTab->pIndex; (pThis = *ppFrom)!=0; ppFrom=&pThis->pNext){ |
| 116955 | 116964 | Index *pNext; |
| 116956 | 116965 | if( pThis->onError!=OE_Replace ) continue; |
| 116957 | 116966 | while( (pNext = pThis->pNext)!=0 && pNext->onError!=OE_Replace ){ |
| | @@ -121358,101 +121367,167 @@ |
| 121358 | 121367 | minMaxValueFinalize(context, 0); |
| 121359 | 121368 | } |
| 121360 | 121369 | |
| 121361 | 121370 | /* |
| 121362 | 121371 | ** group_concat(EXPR, ?SEPARATOR?) |
| 121372 | +** |
| 121373 | +** The SEPARATOR goes before the EXPR string. This is tragic. The |
| 121374 | +** groupConcatInverse() implementation would have been easier if the |
| 121375 | +** SEPARATOR were appended after EXPR. And the order is undocumented, |
| 121376 | +** so we could change it, in theory. But the old behavior has been |
| 121377 | +** around for so long that we dare not, for fear of breaking something. |
| 121363 | 121378 | */ |
| 121379 | +typedef struct { |
| 121380 | + StrAccum str; /* The accumulated concatenation */ |
| 121381 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 121382 | + int nAccum; /* Number of strings presently concatenated */ |
| 121383 | + int nFirstSepLength; /* Used to detect separator length change */ |
| 121384 | + /* If pnSepLengths!=0, refs an array of inter-string separator lengths, |
| 121385 | + ** stored as actually incorporated into presently accumulated result. |
| 121386 | + ** (Hence, its slots in use number nAccum-1 between method calls.) |
| 121387 | + ** If pnSepLengths==0, nFirstSepLength is the length used throughout. |
| 121388 | + */ |
| 121389 | + int *pnSepLengths; |
| 121390 | +#endif |
| 121391 | +} GroupConcatCtx; |
| 121392 | + |
| 121364 | 121393 | static void groupConcatStep( |
| 121365 | 121394 | sqlite3_context *context, |
| 121366 | 121395 | int argc, |
| 121367 | 121396 | sqlite3_value **argv |
| 121368 | 121397 | ){ |
| 121369 | 121398 | const char *zVal; |
| 121370 | | - StrAccum *pAccum; |
| 121399 | + GroupConcatCtx *pGCC; |
| 121371 | 121400 | const char *zSep; |
| 121372 | 121401 | int nVal, nSep; |
| 121373 | 121402 | assert( argc==1 || argc==2 ); |
| 121374 | 121403 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 121375 | | - pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum)); |
| 121376 | | - |
| 121377 | | - if( pAccum ){ |
| 121404 | + pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC)); |
| 121405 | + if( pGCC ){ |
| 121378 | 121406 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 121379 | | - int firstTerm = pAccum->mxAlloc==0; |
| 121380 | | - pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH]; |
| 121381 | | - if( !firstTerm ){ |
| 121382 | | - if( argc==2 ){ |
| 121383 | | - zSep = (char*)sqlite3_value_text(argv[1]); |
| 121384 | | - nSep = sqlite3_value_bytes(argv[1]); |
| 121385 | | - }else{ |
| 121386 | | - zSep = ","; |
| 121387 | | - nSep = 1; |
| 121388 | | - } |
| 121389 | | - if( zSep ) sqlite3_str_append(pAccum, zSep, nSep); |
| 121390 | | - } |
| 121407 | + int firstTerm = pGCC->str.mxAlloc==0; |
| 121408 | + pGCC->str.mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH]; |
| 121409 | + if( argc==1 ){ |
| 121410 | + if( !firstTerm ){ |
| 121411 | + sqlite3_str_appendchar(&pGCC->str, 1, ','); |
| 121412 | + } |
| 121413 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 121414 | + else{ |
| 121415 | + pGCC->nFirstSepLength = 1; |
| 121416 | + } |
| 121417 | +#endif |
| 121418 | + }else if( !firstTerm ){ |
| 121419 | + zSep = (char*)sqlite3_value_text(argv[1]); |
| 121420 | + nSep = sqlite3_value_bytes(argv[1]); |
| 121421 | + if( zSep ){ |
| 121422 | + sqlite3_str_append(&pGCC->str, zSep, nSep); |
| 121423 | + } |
| 121424 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 121425 | + else{ |
| 121426 | + nSep = 0; |
| 121427 | + } |
| 121428 | + if( nSep != pGCC->nFirstSepLength || pGCC->pnSepLengths != 0 ){ |
| 121429 | + int *pnsl = pGCC->pnSepLengths; |
| 121430 | + if( pnsl == 0 ){ |
| 121431 | + /* First separator length variation seen, start tracking them. */ |
| 121432 | + pnsl = (int*)sqlite3_malloc64((pGCC->nAccum+1) * sizeof(int)); |
| 121433 | + if( pnsl!=0 ){ |
| 121434 | + int i = 0, nA = pGCC->nAccum-1; |
| 121435 | + while( i<nA ) pnsl[i++] = pGCC->nFirstSepLength; |
| 121436 | + } |
| 121437 | + }else{ |
| 121438 | + pnsl = (int*)sqlite3_realloc64(pnsl, pGCC->nAccum * sizeof(int)); |
| 121439 | + } |
| 121440 | + if( pnsl!=0 ){ |
| 121441 | + if( ALWAYS(pGCC->nAccum>0) ){ |
| 121442 | + pnsl[pGCC->nAccum-1] = nSep; |
| 121443 | + } |
| 121444 | + pGCC->pnSepLengths = pnsl; |
| 121445 | + }else{ |
| 121446 | + sqlite3StrAccumSetError(&pGCC->str, SQLITE_NOMEM); |
| 121447 | + } |
| 121448 | + } |
| 121449 | +#endif |
| 121450 | + } |
| 121451 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 121452 | + else{ |
| 121453 | + pGCC->nFirstSepLength = sqlite3_value_bytes(argv[1]); |
| 121454 | + } |
| 121455 | + pGCC->nAccum += 1; |
| 121456 | +#endif |
| 121391 | 121457 | zVal = (char*)sqlite3_value_text(argv[0]); |
| 121392 | 121458 | nVal = sqlite3_value_bytes(argv[0]); |
| 121393 | | - if( zVal ) sqlite3_str_append(pAccum, zVal, nVal); |
| 121459 | + if( zVal ) sqlite3_str_append(&pGCC->str, zVal, nVal); |
| 121394 | 121460 | } |
| 121395 | 121461 | } |
| 121462 | + |
| 121396 | 121463 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 121397 | 121464 | static void groupConcatInverse( |
| 121398 | 121465 | sqlite3_context *context, |
| 121399 | 121466 | int argc, |
| 121400 | 121467 | sqlite3_value **argv |
| 121401 | 121468 | ){ |
| 121402 | | - int n; |
| 121403 | | - StrAccum *pAccum; |
| 121469 | + GroupConcatCtx *pGCC; |
| 121404 | 121470 | assert( argc==1 || argc==2 ); |
| 121471 | + (void)argc; /* Suppress unused parameter warning */ |
| 121405 | 121472 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 121406 | | - pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum)); |
| 121407 | | - /* pAccum is always non-NULL since groupConcatStep() will have always |
| 121473 | + pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC)); |
| 121474 | + /* pGCC is always non-NULL since groupConcatStep() will have always |
| 121408 | 121475 | ** run frist to initialize it */ |
| 121409 | | - if( ALWAYS(pAccum) ){ |
| 121410 | | - n = sqlite3_value_bytes(argv[0]); |
| 121411 | | - if( argc==2 ){ |
| 121412 | | - n += sqlite3_value_bytes(argv[1]); |
| 121413 | | - }else{ |
| 121414 | | - n++; |
| 121415 | | - } |
| 121416 | | - if( n>=(int)pAccum->nChar ){ |
| 121417 | | - pAccum->nChar = 0; |
| 121418 | | - }else{ |
| 121419 | | - pAccum->nChar -= n; |
| 121420 | | - memmove(pAccum->zText, &pAccum->zText[n], pAccum->nChar); |
| 121421 | | - } |
| 121422 | | - if( pAccum->nChar==0 ) pAccum->mxAlloc = 0; |
| 121476 | + if( ALWAYS(pGCC) ){ |
| 121477 | + int nVS = sqlite3_value_bytes(argv[0]); |
| 121478 | + pGCC->nAccum -= 1; |
| 121479 | + if( pGCC->pnSepLengths!=0 ){ |
| 121480 | + assert(pGCC->nAccum >= 0); |
| 121481 | + if( pGCC->nAccum>0 ){ |
| 121482 | + nVS += *pGCC->pnSepLengths; |
| 121483 | + memmove(pGCC->pnSepLengths, pGCC->pnSepLengths+1, |
| 121484 | + (pGCC->nAccum-1)*sizeof(int)); |
| 121485 | + } |
| 121486 | + }else{ |
| 121487 | + /* If removing single accumulated string, harmlessly over-do. */ |
| 121488 | + nVS += pGCC->nFirstSepLength; |
| 121489 | + } |
| 121490 | + if( nVS>=(int)pGCC->str.nChar ){ |
| 121491 | + pGCC->str.nChar = 0; |
| 121492 | + }else{ |
| 121493 | + pGCC->str.nChar -= nVS; |
| 121494 | + memmove(pGCC->str.zText, &pGCC->str.zText[nVS], pGCC->str.nChar); |
| 121495 | + } |
| 121496 | + if( pGCC->str.nChar==0 ){ |
| 121497 | + pGCC->str.mxAlloc = 0; |
| 121498 | + sqlite3_free(pGCC->pnSepLengths); |
| 121499 | + pGCC->pnSepLengths = 0; |
| 121500 | + } |
| 121423 | 121501 | } |
| 121424 | 121502 | } |
| 121425 | 121503 | #else |
| 121426 | 121504 | # define groupConcatInverse 0 |
| 121427 | 121505 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 121428 | 121506 | static void groupConcatFinalize(sqlite3_context *context){ |
| 121429 | | - StrAccum *pAccum; |
| 121430 | | - pAccum = sqlite3_aggregate_context(context, 0); |
| 121431 | | - if( pAccum ){ |
| 121432 | | - if( pAccum->accError==SQLITE_TOOBIG ){ |
| 121433 | | - sqlite3_result_error_toobig(context); |
| 121434 | | - }else if( pAccum->accError==SQLITE_NOMEM ){ |
| 121435 | | - sqlite3_result_error_nomem(context); |
| 121436 | | - }else{ |
| 121437 | | - sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1, |
| 121438 | | - sqlite3_free); |
| 121439 | | - } |
| 121507 | + GroupConcatCtx *pGCC |
| 121508 | + = (GroupConcatCtx*)sqlite3_aggregate_context(context, 0); |
| 121509 | + if( pGCC ){ |
| 121510 | + sqlite3ResultStrAccum(context, &pGCC->str); |
| 121511 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 121512 | + sqlite3_free(pGCC->pnSepLengths); |
| 121513 | +#endif |
| 121440 | 121514 | } |
| 121441 | 121515 | } |
| 121442 | 121516 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 121443 | 121517 | static void groupConcatValue(sqlite3_context *context){ |
| 121444 | | - sqlite3_str *pAccum; |
| 121445 | | - pAccum = (sqlite3_str*)sqlite3_aggregate_context(context, 0); |
| 121446 | | - if( pAccum ){ |
| 121518 | + GroupConcatCtx *pGCC |
| 121519 | + = (GroupConcatCtx*)sqlite3_aggregate_context(context, 0); |
| 121520 | + if( pGCC ){ |
| 121521 | + StrAccum *pAccum = &pGCC->str; |
| 121447 | 121522 | if( pAccum->accError==SQLITE_TOOBIG ){ |
| 121448 | 121523 | sqlite3_result_error_toobig(context); |
| 121449 | 121524 | }else if( pAccum->accError==SQLITE_NOMEM ){ |
| 121450 | 121525 | sqlite3_result_error_nomem(context); |
| 121451 | 121526 | }else{ |
| 121452 | 121527 | const char *zText = sqlite3_str_value(pAccum); |
| 121453 | | - sqlite3_result_text(context, zText, -1, SQLITE_TRANSIENT); |
| 121528 | + sqlite3_result_text(context, zText, pAccum->nChar, SQLITE_TRANSIENT); |
| 121454 | 121529 | } |
| 121455 | 121530 | } |
| 121456 | 121531 | } |
| 121457 | 121532 | #else |
| 121458 | 121533 | # define groupConcatValue 0 |
| | @@ -131668,11 +131743,11 @@ |
| 131668 | 131743 | if( sqlite3Config.bExtraSchemaChecks ){ |
| 131669 | 131744 | corruptSchema(pData, argv, "invalid rootpage"); |
| 131670 | 131745 | } |
| 131671 | 131746 | } |
| 131672 | 131747 | db->init.orphanTrigger = 0; |
| 131673 | | - db->init.azInit = argv; |
| 131748 | + db->init.azInit = (const char**)argv; |
| 131674 | 131749 | pStmt = 0; |
| 131675 | 131750 | TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, 0); |
| 131676 | 131751 | rc = db->errCode; |
| 131677 | 131752 | assert( (rc&0xFF)==(rcp&0xFF) ); |
| 131678 | 131753 | db->init.iDb = saved_iDb; |
| | @@ -131687,10 +131762,11 @@ |
| 131687 | 131762 | }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){ |
| 131688 | 131763 | corruptSchema(pData, argv, sqlite3_errmsg(db)); |
| 131689 | 131764 | } |
| 131690 | 131765 | } |
| 131691 | 131766 | } |
| 131767 | + db->init.azInit = sqlite3StdType; /* Any array of string ptrs will do */ |
| 131692 | 131768 | sqlite3_finalize(pStmt); |
| 131693 | 131769 | }else if( argv[1]==0 || (argv[4]!=0 && argv[4][0]!=0) ){ |
| 131694 | 131770 | corruptSchema(pData, argv, 0); |
| 131695 | 131771 | }else{ |
| 131696 | 131772 | /* If the SQL column is blank it means this is an index that |
| | @@ -134990,11 +135066,11 @@ |
| 134990 | 135066 | SelectDest *pDest /* What to do with query results */ |
| 134991 | 135067 | ){ |
| 134992 | 135068 | SrcList *pSrc = p->pSrc; /* The FROM clause of the recursive query */ |
| 134993 | 135069 | int nCol = p->pEList->nExpr; /* Number of columns in the recursive table */ |
| 134994 | 135070 | Vdbe *v = pParse->pVdbe; /* The prepared statement under construction */ |
| 134995 | | - Select *pSetup = p->pPrior; /* The setup query */ |
| 135071 | + Select *pSetup; /* The setup query */ |
| 134996 | 135072 | Select *pFirstRec; /* Left-most recursive term */ |
| 134997 | 135073 | int addrTop; /* Top of the loop */ |
| 134998 | 135074 | int addrCont, addrBreak; /* CONTINUE and BREAK addresses */ |
| 134999 | 135075 | int iCurrent = 0; /* The Current table */ |
| 135000 | 135076 | int regCurrent; /* Register holding Current table */ |
| | @@ -135074,11 +135150,10 @@ |
| 135074 | 135150 | ** functions. Mark the recursive elements as UNION ALL even if they |
| 135075 | 135151 | ** are really UNION because the distinctness will be enforced by the |
| 135076 | 135152 | ** iDistinct table. pFirstRec is left pointing to the left-most |
| 135077 | 135153 | ** recursive term of the CTE. |
| 135078 | 135154 | */ |
| 135079 | | - pFirstRec = p; |
| 135080 | 135155 | for(pFirstRec=p; ALWAYS(pFirstRec!=0); pFirstRec=pFirstRec->pPrior){ |
| 135081 | 135156 | if( pFirstRec->selFlags & SF_Aggregate ){ |
| 135082 | 135157 | sqlite3ErrorMsg(pParse, "recursive aggregate queries not supported"); |
| 135083 | 135158 | goto end_of_recursive_query; |
| 135084 | 135159 | } |
| | @@ -138055,13 +138130,13 @@ |
| 138055 | 138130 | ){ |
| 138056 | 138131 | sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited", |
| 138057 | 138132 | pTab->zName); |
| 138058 | 138133 | } |
| 138059 | 138134 | pFrom->pSelect = sqlite3SelectDup(db, pTab->u.view.pSelect, 0); |
| 138060 | | - }else |
| 138135 | + } |
| 138061 | 138136 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 138062 | | - if( ALWAYS(IsVirtual(pTab)) |
| 138137 | + else if( ALWAYS(IsVirtual(pTab)) |
| 138063 | 138138 | && pFrom->fg.fromDDL |
| 138064 | 138139 | && ALWAYS(pTab->u.vtab.p!=0) |
| 138065 | 138140 | && pTab->u.vtab.p->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0) |
| 138066 | 138141 | ){ |
| 138067 | 138142 | sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"", |
| | @@ -144520,10 +144595,11 @@ |
| 144520 | 144595 | VtabCtx *pCtx; |
| 144521 | 144596 | int rc = SQLITE_OK; |
| 144522 | 144597 | Table *pTab; |
| 144523 | 144598 | char *zErr = 0; |
| 144524 | 144599 | Parse sParse; |
| 144600 | + int initBusy; |
| 144525 | 144601 | |
| 144526 | 144602 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 144527 | 144603 | if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){ |
| 144528 | 144604 | return SQLITE_MISUSE_BKPT; |
| 144529 | 144605 | } |
| | @@ -144539,10 +144615,16 @@ |
| 144539 | 144615 | assert( IsVirtual(pTab) ); |
| 144540 | 144616 | |
| 144541 | 144617 | memset(&sParse, 0, sizeof(sParse)); |
| 144542 | 144618 | sParse.eParseMode = PARSE_MODE_DECLARE_VTAB; |
| 144543 | 144619 | sParse.db = db; |
| 144620 | + /* We should never be able to reach this point while loading the |
| 144621 | + ** schema. Nevertheless, defend against that (turn off db->init.busy) |
| 144622 | + ** in case a bug arises. */ |
| 144623 | + assert( db->init.busy==0 ); |
| 144624 | + initBusy = db->init.busy; |
| 144625 | + db->init.busy = 0; |
| 144544 | 144626 | sParse.nQueryLoop = 1; |
| 144545 | 144627 | if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable, &zErr) |
| 144546 | 144628 | && sParse.pNewTable |
| 144547 | 144629 | && !db->mallocFailed |
| 144548 | 144630 | && IsOrdinaryTable(sParse.pNewTable) |
| | @@ -144585,10 +144667,11 @@ |
| 144585 | 144667 | if( sParse.pVdbe ){ |
| 144586 | 144668 | sqlite3VdbeFinalize(sParse.pVdbe); |
| 144587 | 144669 | } |
| 144588 | 144670 | sqlite3DeleteTable(db, sParse.pNewTable); |
| 144589 | 144671 | sqlite3ParserReset(&sParse); |
| 144672 | + db->init.busy = initBusy; |
| 144590 | 144673 | |
| 144591 | 144674 | assert( (rc&0xff)==rc ); |
| 144592 | 144675 | rc = sqlite3ApiExit(db, rc); |
| 144593 | 144676 | sqlite3_mutex_leave(db->mutex); |
| 144594 | 144677 | return rc; |
| | @@ -154396,10 +154479,11 @@ |
| 154396 | 154479 | WhereLoop *pLoop; |
| 154397 | 154480 | int iCur; |
| 154398 | 154481 | int j; |
| 154399 | 154482 | Table *pTab; |
| 154400 | 154483 | Index *pIdx; |
| 154484 | + WhereScan scan; |
| 154401 | 154485 | |
| 154402 | 154486 | pWInfo = pBuilder->pWInfo; |
| 154403 | 154487 | if( pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE ) return 0; |
| 154404 | 154488 | assert( pWInfo->pTabList->nSrc>=1 ); |
| 154405 | 154489 | pItem = pWInfo->pTabList->a; |
| | @@ -154409,13 +154493,14 @@ |
| 154409 | 154493 | iCur = pItem->iCursor; |
| 154410 | 154494 | pWC = &pWInfo->sWC; |
| 154411 | 154495 | pLoop = pBuilder->pNew; |
| 154412 | 154496 | pLoop->wsFlags = 0; |
| 154413 | 154497 | pLoop->nSkip = 0; |
| 154414 | | - pTerm = sqlite3WhereFindTerm(pWC, iCur, -1, 0, WO_EQ|WO_IS, 0); |
| 154498 | + pTerm = whereScanInit(&scan, pWC, iCur, -1, WO_EQ|WO_IS, 0); |
| 154415 | 154499 | if( pTerm ){ |
| 154416 | 154500 | testcase( pTerm->eOperator & WO_IS ); |
| 154501 | + assert( pTerm->prereqRight==0 ); |
| 154417 | 154502 | pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW; |
| 154418 | 154503 | pLoop->aLTerm[0] = pTerm; |
| 154419 | 154504 | pLoop->nLTerm = 1; |
| 154420 | 154505 | pLoop->u.btree.nEq = 1; |
| 154421 | 154506 | /* TUNING: Cost of a rowid lookup is 10 */ |
| | @@ -154428,11 +154513,12 @@ |
| 154428 | 154513 | || pIdx->pPartIdxWhere!=0 |
| 154429 | 154514 | || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace) |
| 154430 | 154515 | ) continue; |
| 154431 | 154516 | opMask = pIdx->uniqNotNull ? (WO_EQ|WO_IS) : WO_EQ; |
| 154432 | 154517 | for(j=0; j<pIdx->nKeyCol; j++){ |
| 154433 | | - pTerm = sqlite3WhereFindTerm(pWC, iCur, j, 0, opMask, pIdx); |
| 154518 | + pTerm = whereScanInit(&scan, pWC, iCur, j, opMask, pIdx); |
| 154519 | + while( pTerm && pTerm->prereqRight ) pTerm = whereScanNext(&scan); |
| 154434 | 154520 | if( pTerm==0 ) break; |
| 154435 | 154521 | testcase( pTerm->eOperator & WO_IS ); |
| 154436 | 154522 | pLoop->aLTerm[j] = pTerm; |
| 154437 | 154523 | } |
| 154438 | 154524 | if( j!=pIdx->nKeyCol ) continue; |
| | @@ -154457,12 +154543,18 @@ |
| 154457 | 154543 | pWInfo->nRowOut = 1; |
| 154458 | 154544 | if( pWInfo->pOrderBy ) pWInfo->nOBSat = pWInfo->pOrderBy->nExpr; |
| 154459 | 154545 | if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){ |
| 154460 | 154546 | pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE; |
| 154461 | 154547 | } |
| 154548 | + if( scan.iEquiv>1 ) pLoop->wsFlags |= WHERE_TRANSCONS; |
| 154462 | 154549 | #ifdef SQLITE_DEBUG |
| 154463 | 154550 | pLoop->cId = '0'; |
| 154551 | +#endif |
| 154552 | +#ifdef WHERETRACE_ENABLED |
| 154553 | + if( sqlite3WhereTrace ){ |
| 154554 | + sqlite3DebugPrintf("whereShortCut() used to compute solution\n"); |
| 154555 | + } |
| 154464 | 154556 | #endif |
| 154465 | 154557 | return 1; |
| 154466 | 154558 | } |
| 154467 | 154559 | return 0; |
| 154468 | 154560 | } |
| | @@ -156839,11 +156931,16 @@ |
| 156839 | 156931 | /* |
| 156840 | 156932 | ** Return 0 if the two window objects are identical, 1 if they are |
| 156841 | 156933 | ** different, or 2 if it cannot be determined if the objects are identical |
| 156842 | 156934 | ** or not. Identical window objects can be processed in a single scan. |
| 156843 | 156935 | */ |
| 156844 | | -SQLITE_PRIVATE int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2, int bFilter){ |
| 156936 | +SQLITE_PRIVATE int sqlite3WindowCompare( |
| 156937 | + const Parse *pParse, |
| 156938 | + const Window *p1, |
| 156939 | + const Window *p2, |
| 156940 | + int bFilter |
| 156941 | +){ |
| 156845 | 156942 | int res; |
| 156846 | 156943 | if( NEVER(p1==0) || NEVER(p2==0) ) return 1; |
| 156847 | 156944 | if( p1->eFrmType!=p2->eFrmType ) return 1; |
| 156848 | 156945 | if( p1->eStart!=p2->eStart ) return 1; |
| 156849 | 156946 | if( p1->eEnd!=p2->eEnd ) return 1; |
| | @@ -168909,10 +169006,11 @@ |
| 168909 | 169006 | db->aLimit[SQLITE_LIMIT_WORKER_THREADS] = SQLITE_DEFAULT_WORKER_THREADS; |
| 168910 | 169007 | db->autoCommit = 1; |
| 168911 | 169008 | db->nextAutovac = -1; |
| 168912 | 169009 | db->szMmap = sqlite3GlobalConfig.szMmap; |
| 168913 | 169010 | db->nextPagesize = 0; |
| 169011 | + db->init.azInit = sqlite3StdType; /* Any array of string ptrs will do */ |
| 168914 | 169012 | #ifdef SQLITE_ENABLE_SORTER_MMAP |
| 168915 | 169013 | /* Beginning with version 3.37.0, using the VFS xFetch() API to memory-map |
| 168916 | 169014 | ** the temporary files used to do external sorts (see code in vdbesort.c) |
| 168917 | 169015 | ** is disabled. It can still be used either by defining |
| 168918 | 169016 | ** SQLITE_ENABLE_SORTER_MMAP at compile time or by using the |
| | @@ -170190,13 +170288,15 @@ |
| 170190 | 170288 | ** passing free() a pointer that was not obtained from malloc() - it is |
| 170191 | 170289 | ** an error that we cannot easily detect but that will likely cause memory |
| 170192 | 170290 | ** corruption. |
| 170193 | 170291 | */ |
| 170194 | 170292 | SQLITE_API const char *sqlite3_filename_database(const char *zFilename){ |
| 170293 | + if( zFilename==0 ) return 0; |
| 170195 | 170294 | return databaseName(zFilename); |
| 170196 | 170295 | } |
| 170197 | 170296 | SQLITE_API const char *sqlite3_filename_journal(const char *zFilename){ |
| 170297 | + if( zFilename==0 ) return 0; |
| 170198 | 170298 | zFilename = databaseName(zFilename); |
| 170199 | 170299 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 170200 | 170300 | while( zFilename[0] ){ |
| 170201 | 170301 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 170202 | 170302 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| | @@ -170206,11 +170306,11 @@ |
| 170206 | 170306 | SQLITE_API const char *sqlite3_filename_wal(const char *zFilename){ |
| 170207 | 170307 | #ifdef SQLITE_OMIT_WAL |
| 170208 | 170308 | return 0; |
| 170209 | 170309 | #else |
| 170210 | 170310 | zFilename = sqlite3_filename_journal(zFilename); |
| 170211 | | - zFilename += sqlite3Strlen30(zFilename) + 1; |
| 170311 | + if( zFilename ) zFilename += sqlite3Strlen30(zFilename) + 1; |
| 170212 | 170312 | return zFilename; |
| 170213 | 170313 | #endif |
| 170214 | 170314 | } |
| 170215 | 170315 | |
| 170216 | 170316 | /* |
| | @@ -190887,11 +190987,11 @@ |
| 190887 | 190987 | } |
| 190888 | 190988 | if( pNode->u.zJContent[0]=='-' ){ i = -i; } |
| 190889 | 190989 | sqlite3_result_int64(pCtx, i); |
| 190890 | 190990 | int_done: |
| 190891 | 190991 | break; |
| 190892 | | - int_as_real: i=0; /* no break */ deliberate_fall_through |
| 190992 | + int_as_real: ; /* no break */ deliberate_fall_through |
| 190893 | 190993 | } |
| 190894 | 190994 | case JSON_REAL: { |
| 190895 | 190995 | double r; |
| 190896 | 190996 | #ifdef SQLITE_AMALGAMATION |
| 190897 | 190997 | const char *z = pNode->u.zJContent; |
| | @@ -195462,10 +195562,14 @@ |
| 195462 | 195562 | ){ |
| 195463 | 195563 | int (*xSetMapping)(Rtree *, sqlite3_int64, sqlite3_int64); |
| 195464 | 195564 | xSetMapping = ((iHeight==0)?rowidWrite:parentWrite); |
| 195465 | 195565 | if( iHeight>0 ){ |
| 195466 | 195566 | RtreeNode *pChild = nodeHashLookup(pRtree, iRowid); |
| 195567 | + RtreeNode *p; |
| 195568 | + for(p=pNode; p; p=p->pParent){ |
| 195569 | + if( p==pChild ) return SQLITE_CORRUPT_VTAB; |
| 195570 | + } |
| 195467 | 195571 | if( pChild ){ |
| 195468 | 195572 | nodeRelease(pRtree, pChild->pParent); |
| 195469 | 195573 | nodeReference(pNode); |
| 195470 | 195574 | pChild->pParent = pNode; |
| 195471 | 195575 | } |
| | @@ -206052,10 +206156,19 @@ |
| 206052 | 206156 | |
| 206053 | 206157 | /* #include "sqliteInt.h" ** Requires access to internal data structures ** */ |
| 206054 | 206158 | #if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \ |
| 206055 | 206159 | && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 206056 | 206160 | |
| 206161 | +/* |
| 206162 | +** The pager and btree modules arrange objects in memory so that there are |
| 206163 | +** always approximately 200 bytes of addressable memory following each page |
| 206164 | +** buffer. This way small buffer overreads caused by corrupt database pages |
| 206165 | +** do not cause undefined behaviour. This module pads each page buffer |
| 206166 | +** by the following number of bytes for the same purpose. |
| 206167 | +*/ |
| 206168 | +#define DBSTAT_PAGE_PADDING_BYTES 256 |
| 206169 | + |
| 206057 | 206170 | /* |
| 206058 | 206171 | ** Page paths: |
| 206059 | 206172 | ** |
| 206060 | 206173 | ** The value of the 'path' column describes the path taken from the |
| 206061 | 206174 | ** root-node of the b-tree structure to each page. The value of the |
| | @@ -206119,13 +206232,12 @@ |
| 206119 | 206232 | }; |
| 206120 | 206233 | |
| 206121 | 206234 | /* Size information for a single btree page */ |
| 206122 | 206235 | struct StatPage { |
| 206123 | 206236 | u32 iPgno; /* Page number */ |
| 206124 | | - DbPage *pPg; /* Page content */ |
| 206237 | + u8 *aPg; /* Page buffer from sqlite3_malloc() */ |
| 206125 | 206238 | int iCell; /* Current cell */ |
| 206126 | | - |
| 206127 | 206239 | char *zPath; /* Path to this page */ |
| 206128 | 206240 | |
| 206129 | 206241 | /* Variables populated by statDecodePage(): */ |
| 206130 | 206242 | u8 flags; /* Copy of flags byte */ |
| 206131 | 206243 | int nCell; /* Number of cells on page */ |
| | @@ -206333,22 +206445,29 @@ |
| 206333 | 206445 | p->nCell = 0; |
| 206334 | 206446 | p->aCell = 0; |
| 206335 | 206447 | } |
| 206336 | 206448 | |
| 206337 | 206449 | static void statClearPage(StatPage *p){ |
| 206450 | + u8 *aPg = p->aPg; |
| 206338 | 206451 | statClearCells(p); |
| 206339 | | - sqlite3PagerUnref(p->pPg); |
| 206340 | 206452 | sqlite3_free(p->zPath); |
| 206341 | 206453 | memset(p, 0, sizeof(StatPage)); |
| 206454 | + p->aPg = aPg; |
| 206342 | 206455 | } |
| 206343 | 206456 | |
| 206344 | 206457 | static void statResetCsr(StatCursor *pCsr){ |
| 206345 | 206458 | int i; |
| 206346 | | - sqlite3_reset(pCsr->pStmt); |
| 206459 | + /* In some circumstances, specifically if an OOM has occurred, the call |
| 206460 | + ** to sqlite3_reset() may cause the pager to be reset (emptied). It is |
| 206461 | + ** important that statClearPage() is called to free any page refs before |
| 206462 | + ** this happens. dbsqlfuzz 9ed3e4e3816219d3509d711636c38542bf3f40b1. */ |
| 206347 | 206463 | for(i=0; i<ArraySize(pCsr->aPage); i++){ |
| 206348 | 206464 | statClearPage(&pCsr->aPage[i]); |
| 206465 | + sqlite3_free(pCsr->aPage[i].aPg); |
| 206466 | + pCsr->aPage[i].aPg = 0; |
| 206349 | 206467 | } |
| 206468 | + sqlite3_reset(pCsr->pStmt); |
| 206350 | 206469 | pCsr->iPage = 0; |
| 206351 | 206470 | sqlite3_free(pCsr->zPath); |
| 206352 | 206471 | pCsr->zPath = 0; |
| 206353 | 206472 | pCsr->isEof = 0; |
| 206354 | 206473 | } |
| | @@ -206409,11 +206528,11 @@ |
| 206409 | 206528 | int iOff; |
| 206410 | 206529 | int nHdr; |
| 206411 | 206530 | int isLeaf; |
| 206412 | 206531 | int szPage; |
| 206413 | 206532 | |
| 206414 | | - u8 *aData = sqlite3PagerGetData(p->pPg); |
| 206533 | + u8 *aData = p->aPg; |
| 206415 | 206534 | u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0]; |
| 206416 | 206535 | |
| 206417 | 206536 | p->flags = aHdr[0]; |
| 206418 | 206537 | if( p->flags==0x0A || p->flags==0x0D ){ |
| 206419 | 206538 | isLeaf = 1; |
| | @@ -206480,11 +206599,11 @@ |
| 206480 | 206599 | assert( nPayload>=(u32)nLocal ); |
| 206481 | 206600 | assert( nLocal<=(nUsable-35) ); |
| 206482 | 206601 | if( nPayload>(u32)nLocal ){ |
| 206483 | 206602 | int j; |
| 206484 | 206603 | int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4); |
| 206485 | | - if( iOff+nLocal>nUsable || nPayload>0x7fffffff ){ |
| 206604 | + if( iOff+nLocal+4>nUsable || nPayload>0x7fffffff ){ |
| 206486 | 206605 | goto statPageIsCorrupt; |
| 206487 | 206606 | } |
| 206488 | 206607 | pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4); |
| 206489 | 206608 | pCell->nOvfl = nOvfl; |
| 206490 | 206609 | pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl); |
| | @@ -206538,10 +206657,42 @@ |
| 206538 | 206657 | /* Not ZIPVFS: The default page size and offset */ |
| 206539 | 206658 | pCsr->szPage += sqlite3BtreeGetPageSize(pBt); |
| 206540 | 206659 | pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1); |
| 206541 | 206660 | } |
| 206542 | 206661 | } |
| 206662 | + |
| 206663 | +/* |
| 206664 | +** Load a copy of the page data for page iPg into the buffer belonging |
| 206665 | +** to page object pPg. Allocate the buffer if necessary. Return SQLITE_OK |
| 206666 | +** if successful, or an SQLite error code otherwise. |
| 206667 | +*/ |
| 206668 | +static int statGetPage( |
| 206669 | + Btree *pBt, /* Load page from this b-tree */ |
| 206670 | + u32 iPg, /* Page number to load */ |
| 206671 | + StatPage *pPg /* Load page into this object */ |
| 206672 | +){ |
| 206673 | + int pgsz = sqlite3BtreeGetPageSize(pBt); |
| 206674 | + DbPage *pDbPage = 0; |
| 206675 | + int rc; |
| 206676 | + |
| 206677 | + if( pPg->aPg==0 ){ |
| 206678 | + pPg->aPg = (u8*)sqlite3_malloc(pgsz + DBSTAT_PAGE_PADDING_BYTES); |
| 206679 | + if( pPg->aPg==0 ){ |
| 206680 | + return SQLITE_NOMEM_BKPT; |
| 206681 | + } |
| 206682 | + memset(&pPg->aPg[pgsz], 0, DBSTAT_PAGE_PADDING_BYTES); |
| 206683 | + } |
| 206684 | + |
| 206685 | + rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPg, &pDbPage, 0); |
| 206686 | + if( rc==SQLITE_OK ){ |
| 206687 | + const u8 *a = sqlite3PagerGetData(pDbPage); |
| 206688 | + memcpy(pPg->aPg, a, pgsz); |
| 206689 | + sqlite3PagerUnref(pDbPage); |
| 206690 | + } |
| 206691 | + |
| 206692 | + return rc; |
| 206693 | +} |
| 206543 | 206694 | |
| 206544 | 206695 | /* |
| 206545 | 206696 | ** Move a DBSTAT cursor to the next entry. Normally, the next |
| 206546 | 206697 | ** entry will be the next page, but in aggregated mode (pCsr->isAgg!=0), |
| 206547 | 206698 | ** the next entry is the next btree. |
| | @@ -206557,11 +206708,11 @@ |
| 206557 | 206708 | |
| 206558 | 206709 | sqlite3_free(pCsr->zPath); |
| 206559 | 206710 | pCsr->zPath = 0; |
| 206560 | 206711 | |
| 206561 | 206712 | statNextRestart: |
| 206562 | | - if( pCsr->aPage[0].pPg==0 ){ |
| 206713 | + if( pCsr->iPage<0 ){ |
| 206563 | 206714 | /* Start measuring space on the next btree */ |
| 206564 | 206715 | statResetCounts(pCsr); |
| 206565 | 206716 | rc = sqlite3_step(pCsr->pStmt); |
| 206566 | 206717 | if( rc==SQLITE_ROW ){ |
| 206567 | 206718 | int nPage; |
| | @@ -206569,11 +206720,11 @@ |
| 206569 | 206720 | sqlite3PagerPagecount(pPager, &nPage); |
| 206570 | 206721 | if( nPage==0 ){ |
| 206571 | 206722 | pCsr->isEof = 1; |
| 206572 | 206723 | return sqlite3_reset(pCsr->pStmt); |
| 206573 | 206724 | } |
| 206574 | | - rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg, 0); |
| 206725 | + rc = statGetPage(pBt, iRoot, &pCsr->aPage[0]); |
| 206575 | 206726 | pCsr->aPage[0].iPgno = iRoot; |
| 206576 | 206727 | pCsr->aPage[0].iCell = 0; |
| 206577 | 206728 | if( !pCsr->isAgg ){ |
| 206578 | 206729 | pCsr->aPage[0].zPath = z = sqlite3_mprintf("/"); |
| 206579 | 206730 | if( z==0 ) rc = SQLITE_NOMEM_BKPT; |
| | @@ -206620,13 +206771,12 @@ |
| 206620 | 206771 | p->iCell++; |
| 206621 | 206772 | } |
| 206622 | 206773 | |
| 206623 | 206774 | if( !p->iRightChildPg || p->iCell>p->nCell ){ |
| 206624 | 206775 | statClearPage(p); |
| 206625 | | - if( pCsr->iPage>0 ){ |
| 206626 | | - pCsr->iPage--; |
| 206627 | | - }else if( pCsr->isAgg ){ |
| 206776 | + pCsr->iPage--; |
| 206777 | + if( pCsr->isAgg && pCsr->iPage<0 ){ |
| 206628 | 206778 | /* label-statNext-done: When computing aggregate space usage over |
| 206629 | 206779 | ** an entire btree, this is the exit point from this function */ |
| 206630 | 206780 | return SQLITE_OK; |
| 206631 | 206781 | } |
| 206632 | 206782 | goto statNextRestart; /* Tail recursion */ |
| | @@ -206641,11 +206791,11 @@ |
| 206641 | 206791 | if( p->iCell==p->nCell ){ |
| 206642 | 206792 | p[1].iPgno = p->iRightChildPg; |
| 206643 | 206793 | }else{ |
| 206644 | 206794 | p[1].iPgno = p->aCell[p->iCell].iChildPg; |
| 206645 | 206795 | } |
| 206646 | | - rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg, 0); |
| 206796 | + rc = statGetPage(pBt, p[1].iPgno, &p[1]); |
| 206647 | 206797 | pCsr->nPage++; |
| 206648 | 206798 | p[1].iCell = 0; |
| 206649 | 206799 | if( !pCsr->isAgg ){ |
| 206650 | 206800 | p[1].zPath = z = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell); |
| 206651 | 206801 | if( z==0 ) rc = SQLITE_NOMEM_BKPT; |
| | @@ -206771,10 +206921,11 @@ |
| 206771 | 206921 | rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0); |
| 206772 | 206922 | sqlite3_free(zSql); |
| 206773 | 206923 | } |
| 206774 | 206924 | |
| 206775 | 206925 | if( rc==SQLITE_OK ){ |
| 206926 | + pCsr->iPage = -1; |
| 206776 | 206927 | rc = statNext(pCursor); |
| 206777 | 206928 | } |
| 206778 | 206929 | return rc; |
| 206779 | 206930 | } |
| 206780 | 206931 | |
| | @@ -222410,10 +222561,11 @@ |
| 222410 | 222561 | } |
| 222411 | 222562 | |
| 222412 | 222563 | assert( (pRet==0)==(p->rc!=SQLITE_OK) ); |
| 222413 | 222564 | return pRet; |
| 222414 | 222565 | } |
| 222566 | + |
| 222415 | 222567 | |
| 222416 | 222568 | /* |
| 222417 | 222569 | ** Release a reference to data record returned by an earlier call to |
| 222418 | 222570 | ** fts5DataRead(). |
| 222419 | 222571 | */ |
| | @@ -223869,11 +224021,11 @@ |
| 223869 | 224021 | int pgnoLast = 0; |
| 223870 | 224022 | |
| 223871 | 224023 | if( pDlidx ){ |
| 223872 | 224024 | int iSegid = pIter->pSeg->iSegid; |
| 223873 | 224025 | pgnoLast = fts5DlidxIterPgno(pDlidx); |
| 223874 | | - pLast = fts5DataRead(p, FTS5_SEGMENT_ROWID(iSegid, pgnoLast)); |
| 224026 | + pLast = fts5LeafRead(p, FTS5_SEGMENT_ROWID(iSegid, pgnoLast)); |
| 223875 | 224027 | }else{ |
| 223876 | 224028 | Fts5Data *pLeaf = pIter->pLeaf; /* Current leaf data */ |
| 223877 | 224029 | |
| 223878 | 224030 | /* Currently, Fts5SegIter.iLeafOffset points to the first byte of |
| 223879 | 224031 | ** position-list content for the current rowid. Back it up so that it |
| | @@ -223896,11 +224048,11 @@ |
| 223896 | 224048 | |
| 223897 | 224049 | /* The last rowid in the doclist may not be on the current page. Search |
| 223898 | 224050 | ** forward to find the page containing the last rowid. */ |
| 223899 | 224051 | for(pgno=pIter->iLeafPgno+1; !p->rc && pgno<=pSeg->pgnoLast; pgno++){ |
| 223900 | 224052 | i64 iAbs = FTS5_SEGMENT_ROWID(pSeg->iSegid, pgno); |
| 223901 | | - Fts5Data *pNew = fts5DataRead(p, iAbs); |
| 224053 | + Fts5Data *pNew = fts5LeafRead(p, iAbs); |
| 223902 | 224054 | if( pNew ){ |
| 223903 | 224055 | int iRowid, bTermless; |
| 223904 | 224056 | iRowid = fts5LeafFirstRowidOff(pNew); |
| 223905 | 224057 | bTermless = fts5LeafIsTermless(pNew); |
| 223906 | 224058 | if( iRowid ){ |
| | @@ -223927,19 +224079,22 @@ |
| 223927 | 224079 | int iOff; |
| 223928 | 224080 | fts5DataRelease(pIter->pLeaf); |
| 223929 | 224081 | pIter->pLeaf = pLast; |
| 223930 | 224082 | pIter->iLeafPgno = pgnoLast; |
| 223931 | 224083 | iOff = fts5LeafFirstRowidOff(pLast); |
| 224084 | + if( iOff>pLast->szLeaf ){ |
| 224085 | + p->rc = FTS5_CORRUPT; |
| 224086 | + return; |
| 224087 | + } |
| 223932 | 224088 | iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid); |
| 223933 | 224089 | pIter->iLeafOffset = iOff; |
| 223934 | 224090 | |
| 223935 | 224091 | if( fts5LeafIsTermless(pLast) ){ |
| 223936 | 224092 | pIter->iEndofDoclist = pLast->nn+1; |
| 223937 | 224093 | }else{ |
| 223938 | 224094 | pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast); |
| 223939 | 224095 | } |
| 223940 | | - |
| 223941 | 224096 | } |
| 223942 | 224097 | |
| 223943 | 224098 | fts5SegIterReverseInitPage(p, pIter); |
| 223944 | 224099 | } |
| 223945 | 224100 | |
| | @@ -231295,11 +231450,11 @@ |
| 231295 | 231450 | int nArg, /* Number of args */ |
| 231296 | 231451 | sqlite3_value **apUnused /* Function arguments */ |
| 231297 | 231452 | ){ |
| 231298 | 231453 | assert( nArg==0 ); |
| 231299 | 231454 | UNUSED_PARAM2(nArg, apUnused); |
| 231300 | | - sqlite3_result_text(pCtx, "fts5: 2021-09-22 14:43:35 d678ecca02698753d1b33e072566112e94ea36d0d3a8f4a24d2b09d131968d88", -1, SQLITE_TRANSIENT); |
| 231455 | + sqlite3_result_text(pCtx, "fts5: 2021-10-04 11:10:15 8b24c177061c38361588f419eda9b7943b72a0c6b2855b6f39272451b8a1b813", -1, SQLITE_TRANSIENT); |
| 231301 | 231456 | } |
| 231302 | 231457 | |
| 231303 | 231458 | /* |
| 231304 | 231459 | ** Return true if zName is the extension on one of the shadow tables used |
| 231305 | 231460 | ** by this module. |
| 231306 | 231461 | |